Skip to content

Commit

Permalink
rework the keytable handling. items in the static data result in it h…
Browse files Browse the repository at this point in the history
…aving different padding/alignment in the library base, to what the public base exposes its elements at.
  • Loading branch information
Kalamatee committed Jan 19, 2020
1 parent 84610d2 commit 37ef165
Show file tree
Hide file tree
Showing 9 changed files with 315 additions and 273 deletions.
151 changes: 69 additions & 82 deletions arch/all-hosted/hidd/x11/disk_startup.c
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
/*
Copyright 1995-2016, The AROS Development Team. All rights reserved.
Copyright 1995-2020, The AROS Development Team. All rights reserved.
$Id$
Desc: Disk-resident part of X11 display driver
Lang: english
*/

#include <aros/debug.h>
#include <dos/dosextens.h>
#include <oop/oop.h>
#include <workbench/startup.h>
#include <workbench/workbench.h>
#include <proto/dos.h>

#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/graphics.h>
#include <proto/oop.h>
#include <proto/icon.h>
#include <proto/x11gfx.h>

#include <dos/dosextens.h>
#include <oop/oop.h>
#include <workbench/startup.h>
#include <workbench/workbench.h>

#include <stdlib.h>

Expand Down Expand Up @@ -81,134 +84,114 @@ int __nocommandline = 1;

static ULONG LoadKeyCode2RawKeyTable(STRPTR filename)
{
struct X11Base *X11Base;
struct Library *X11ClBase;
ULONG displays;
BPTR fh;

X11Base = (struct X11Base *)OpenLibrary(X11_LIBNAME, X11_VERSION);
if (!X11Base) {
D(bug("[X11] No X11 driver in the system\n"));
D(bug("[X11:DiskStart] %s()\n", __func__));

X11ClBase = (struct Library *)OpenLibrary(X11_LIBNAME, X11_VERSION);
if (!X11ClBase) {
D(bug("[X11:DiskStart] No X11 driver in the system\n"));
return 0;
}

displays = X11Base->library.lib_OpenCnt - 1;
D(
bug("[X11:DiskStart] %s: X11ClBase @ 0x%p\n", __func__, X11ClBase);
)
displays = X11ClBase->lib_OpenCnt - 1;

if ((fh = Open(filename, MODE_OLDFILE)))
{
D(bug("[X11] X keymap file handle: %p\n", fh));

if ((256 == Read(fh, X11Base->keycode2rawkey, 256)))
{
D(bug("LoadKeyCode2RawKeyTable: keycode2rawkey.table successfully loaded!\n"));
X11Base->havetable = TRUE;
}
Close(fh);
}

CloseLibrary(&X11Base->library);
UBYTE keycode2rawkey[256];

return displays;
}
D(bug("[X11:DiskStart] %s: X key table file handle: %p\n", __func__, fh));
D(bug("[X11:DiskStart] %s: X key table name : %s\n", __func__, filename));

#if 0
/* This function uses library open count as displays count */
static ULONG AddDisplays(ULONG num, ULONG old)
{
struct X11Base *X11Base;
ULONG i, err;
if ((256 == Read(fh, keycode2rawkey, 256)))
{
x11kdb_LoadkeyTable(keycode2rawkey);
D(bug("[X11:DiskStart] %s: table loaded\n", __func__));
}
Close(fh);
}

D(bug("[X11] Making %u displays\n", num));
D(bug("[X11] Current displays count: %u\n", old));
CloseLibrary(X11ClBase);

/* Add displays if needed, open the library once more for every display */
for (i = old; i < num; i++)
{
/* This increments counter */
X11Base = (struct X11Base *)OpenLibrary(X11_LIBNAME, X11_VERSION);
if (!X11Base)
{
D(bug("[X11] Failed to open X11 library!\n"));
break;
}

err = AddDisplayDriverA(X11Base->gfxclass, NULL, NULL);

/* If driver setup failed, decrement counter back and abort */
if (!err)
{
D(bug("[X11] Failed to add display object\n"));

CloseLibrary(X11Base);
break;
}
}

return i;
return displays;
}
#endif

int main(void)
{
BPTR olddir = BNULL;
STRPTR myname;
struct DiskObject *icon;
struct RDArgs *rdargs = NULL;
BPTR olddir = BNULL;
ULONG old_displays;
STRPTR myname;
int res = RETURN_OK;
struct Node *x11entry;

struct MyArgs args =
{
1,
DEF_KEYMAP
1,
DEF_KEYMAP
};

struct StackSwapStruct sss;
struct StackSwapArgs ssa;
UBYTE *stack;

D(bug("[X11:DiskStart] %s()\n", __func__));

if ((x11entry = FindName(&SysBase->LibList, X11_LIBNAME)))
{
D(bug("[X11:DiskStart] %s: X11gfx has already loaded @ 0x%p\n", __func__, x11entry));
return res;
}

stack = AllocMem(STACK_SIZE, MEMF_ANY);
if (stack == NULL)
return RETURN_FAIL;

if (WBenchMsg)
{
olddir = CurrentDir(WBenchMsg->sm_ArgList[0].wa_Lock);
myname = WBenchMsg->sm_ArgList[0].wa_Name;
myname = WBenchMsg->sm_ArgList[0].wa_Name;
}
else
{
struct Process *me = (struct Process *)FindTask(NULL);
struct Process *me = (struct Process *)FindTask(NULL);

if (me->pr_CLI)
{
if (me->pr_CLI)
{
struct CommandLineInterface *cli = BADDR(me->pr_CLI);

myname = AROS_BSTR_ADDR(cli->cli_CommandName);
} else
myname = me->pr_Task.tc_Node.ln_Name;
myname = AROS_BSTR_ADDR(cli->cli_CommandName);
} else
myname = me->pr_Task.tc_Node.ln_Name;
}
D(bug("[X11] Command name: %s\n", myname));
D(bug("[X11:DiskStart] %s: Command name: %s\n", __func__, myname));

icon = GetDiskObject(myname);
D(bug("[X11] Icon 0x%p\n", icon));

if (icon)
{
STRPTR str;

str = FindToolType(icon->do_ToolTypes, "DISPLAYS");
if (str)
args.displays = atoi(str);

str = FindToolType(icon->do_ToolTypes, "KEYMAP");
if (str)
args.keymap = str;
D(bug("[X11:DiskStart] %s: Icon 0x%p\n", __func__, icon));

str = FindToolType(icon->do_ToolTypes, "DISPLAYS");
if (str)
args.displays = atoi(str);

str = FindToolType(icon->do_ToolTypes, "KEYMAP");
if (str)
args.keymap = str;
}

if (!WBenchMsg) {
rdargs = ReadArgs(ARGS_TEMPLATE, (IPTR *)&args, NULL);
D(bug("[X11] RDArgs 0x%p\n", rdargs));
D(bug("[X11:DiskStart] %s: RDArgs 0x%p\n", __func__, rdargs));
}

D(bug("[X11] Keymap: %s\n", args.keymap));
D(bug("[X11:DiskStart] %s: Keymap: %s\n", __func__, args.keymap));

/* Call LoadKeyCode2RawKeyTable() with a new stack: it initialises
x11gfx.hidd, and some X servers need a larger than normal stack */
Expand All @@ -220,6 +203,8 @@ int main(void)

old_displays = NewStackSwap(&sss, LoadKeyCode2RawKeyTable, &ssa);

D(bug("[X11:DiskStart] %s: cleaning up\n", __func__));

/*
* TODO: In order for this to work X11 driver needs to be fixed
* in the following way:
Expand Down Expand Up @@ -247,5 +232,7 @@ int main(void)
CurrentDir(olddir);
FreeMem(stack, STACK_SIZE);

D(bug("[X11:DiskStart] %s: exiting\n", __func__));

return res;
}
15 changes: 9 additions & 6 deletions arch/all-hosted/hidd/x11/mmakefile.src
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ include $(SRCDIR)/config/aros.cfg
DISK_FILES := disk_startup
DISK_EXEDIR := $(AROS_DEVS)/Monitors

#MM- hidd-x11gfx-yes : kernel-x11gfx
#MM devs-monitors-x11 : iconset-$(AROS_TARGET_ICONSET)-x11
#MM- hidd-x11gfx-yes : hosted-X11
#MM- hosted-X11 : hosted-X11-x11gfx hosted-X11-monitor
#MM- hosted-X11-quick : hosted-X11-x11gfx-quick hosted-X11-monitor-quick

%build_prog mmake=devs-monitors-x11 \
#MM hosted-X11-monitor : iconset-$(AROS_TARGET_ICONSET)-x11

%build_prog mmake=hosted-X11-monitor \
progname=X11 targetdir=$(DISK_EXEDIR) \
files=$(DISK_FILES)

Expand Down Expand Up @@ -50,10 +53,10 @@ FILES := \
x11gfx_fullscreen \
x11gfx_bitmapclass

#MM kernel-x11gfx : x11keymaptable devs-monitors-x11
#MM kernel-x11gfx-kobj : x11keymaptable devs-monitors-x11
#MM hosted-X11-x11gfx : x11keymaptable hosted-X11-monitor
#MM hosted-X11-x11gfx-kobj : x11keymaptable hosted-X11-monitor

%build_module mmake=kernel-x11gfx \
%build_module mmake=hosted-X11-x11gfx \
modname=x11gfx modtype=hidd version=$(AROS_TARGET_PLATFORM) \
files=$(FILES) uselibs="hiddstubs"

Expand Down
20 changes: 12 additions & 8 deletions arch/all-hosted/hidd/x11/startup.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright © 1995-2016, The AROS Development Team. All rights reserved.
Copyright © 1995-2020, The AROS Development Team. All rights reserved.
$Id$
*/

Expand Down Expand Up @@ -52,10 +52,14 @@ static int X11_Startup(LIBBASETYPEPTR LIBBASE)
int res = FALSE;
ULONG err;

D(bug("[X11] X11_Startup()\n"));
D(
bug("[X11] %s()\n", __func__);
bug("[X11] %s: X11Base @ 0x%p\n", __func__, LIBBASE);
bug("[X11] %s: xsd @ 0x%p\n", __func__, &LIBBASE->xsd);
)

GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 41);
D(bug("[X11_Startup] GfxBase 0x%p\n", GfxBase));
D(bug("[X11] GfxBase 0x%p\n", GfxBase));
if (!GfxBase)
return FALSE;

Expand All @@ -82,18 +86,18 @@ static int X11_Startup(LIBBASETYPEPTR LIBBASE)

err = AddDisplayDriverA(LIBBASE->xsd.gfxclass, NULL, NULL);

D(bug("[X11_Startup] AddDisplayDriver() result: %u\n", err));
D(bug("[X11] AddDisplayDriver() result: %u\n", err));
if (!err)
{
LIBBASE->library.lib_OpenCnt = 1;
res = TRUE;
}
else
{
if (kbdriver)
HW_RemoveDriver(kbd, kbdriver);
if (msdriver)
HW_RemoveDriver(ms, msdriver);
if (kbdriver)
HW_RemoveDriver(kbd, kbdriver);
if (msdriver)
HW_RemoveDriver(ms, msdriver);
}

CloseLibrary(&GfxBase->LibNode);
Expand Down

0 comments on commit 37ef165

Please sign in to comment.