Implemented support for executing commands on Host OS, through emulib

This commit is contained in:
Dimitris Panokostas 2020-06-26 00:02:48 +02:00
parent 22372fd4e3
commit fb0bfdb78c
2 changed files with 152 additions and 118 deletions

View file

@ -22,8 +22,8 @@
#define GETBDM(x) (((x) - (((x) / 10000) * 10000)) / 100)
#define GETBDD(x) ((x) % 100)
#define AMIBERRYVERSION _T("Amiberry v3.2 beta (2020-06-25)")
#define AMIBERRYDATE MAKEBD(2020, 6, 25)
#define AMIBERRYVERSION _T("Amiberry v3.2 beta (2020-06-26)")
#define AMIBERRYDATE MAKEBD(2020, 6, 26)
extern std::string get_version_string();

View file

@ -28,7 +28,7 @@
/*
* Returns UAE Version
*/
static uae_u32 emulib_GetVersion (void)
static uae_u32 emulib_GetVersion(void)
{
return version;
}
@ -36,13 +36,13 @@ static uae_u32 emulib_GetVersion (void)
/*
* Resets your amiga
*/
static uae_u32 emulib_HardReset (void)
static uae_u32 emulib_HardReset(void)
{
uae_reset(1, 1);
return 0;
}
static uae_u32 emulib_Reset (void)
static uae_u32 emulib_Reset(void)
{
uae_reset(0, 0);
return 0;
@ -51,7 +51,7 @@ static uae_u32 emulib_Reset (void)
/*
* Enables SOUND
*/
static uae_u32 emulib_EnableSound (uae_u32 val)
static uae_u32 emulib_EnableSound(uae_u32 val)
{
if (!sound_available || currprefs.produce_sound == 2)
return 0;
@ -63,7 +63,7 @@ static uae_u32 emulib_EnableSound (uae_u32 val)
/*
* Enables FAKE JOYSTICK
*/
static uae_u32 emulib_EnableJoystick (uae_u32 val)
static uae_u32 emulib_EnableJoystick(uae_u32 val)
{
currprefs.jports[0].id = val & 255;
currprefs.jports[1].id = (val >> 8) & 255;
@ -73,53 +73,50 @@ static uae_u32 emulib_EnableJoystick (uae_u32 val)
/*
* Sets the framerate
*/
static uae_u32 emulib_SetFrameRate (uae_u32 val)
static uae_u32 emulib_SetFrameRate(uae_u32 val)
{
if (val == 0)
return 0;
else if (val > 20)
if (val > 20)
return 0;
else {
currprefs.gfx_framerate = val;
return 1;
}
currprefs.gfx_framerate = val;
return 1;
}
/*
* Changes keyboard language settings
*/
static uae_u32 emulib_ChangeLanguage (uae_u32 which)
static uae_u32 emulib_ChangeLanguage(uae_u32 which)
{
if (which > 6)
return 0;
else {
switch (which) {
case 0:
currprefs.keyboard_lang = KBD_LANG_US;
break;
case 1:
currprefs.keyboard_lang = KBD_LANG_DK;
break;
case 2:
currprefs.keyboard_lang = KBD_LANG_DE;
break;
case 3:
currprefs.keyboard_lang = KBD_LANG_SE;
break;
case 4:
currprefs.keyboard_lang = KBD_LANG_FR;
break;
case 5:
currprefs.keyboard_lang = KBD_LANG_IT;
break;
case 6:
currprefs.keyboard_lang = KBD_LANG_ES;
break;
default:
break;
}
return 1;
switch (which)
{
case 0:
currprefs.keyboard_lang = KBD_LANG_US;
break;
case 1:
currprefs.keyboard_lang = KBD_LANG_DK;
break;
case 2:
currprefs.keyboard_lang = KBD_LANG_DE;
break;
case 3:
currprefs.keyboard_lang = KBD_LANG_SE;
break;
case 4:
currprefs.keyboard_lang = KBD_LANG_FR;
break;
case 5:
currprefs.keyboard_lang = KBD_LANG_IT;
break;
case 6:
currprefs.keyboard_lang = KBD_LANG_ES;
break;
default:
break;
}
return 1;
}
/* The following ones don't work as we never realloc the arrays... */
@ -127,14 +124,15 @@ static uae_u32 emulib_ChangeLanguage (uae_u32 which)
* Changes chip memory size
* (reboots)
*/
static uae_u32 REGPARAM2 emulib_ChgCMemSize(TrapContext *ctx, uae_u32 memsize)
static uae_u32 REGPARAM2 emulib_ChgCMemSize(TrapContext* ctx, uae_u32 memsize)
{
if (memsize != 0x80000 && memsize != 0x100000 &&
memsize != 0x200000) {
memsize = 0x200000;
write_log (_T("Unsupported chipmem size!\n"));
memsize != 0x200000)
{
memsize = 0x200000;
write_log(_T("Unsupported chipmem size!\n"));
}
trap_set_dreg(ctx, 0, 0);
trap_set_dreg(ctx, 0, 0);
changed_prefs.chipmem_size = memsize;
uae_reset(1, 1);
@ -145,17 +143,18 @@ static uae_u32 REGPARAM2 emulib_ChgCMemSize(TrapContext *ctx, uae_u32 memsize)
* Changes slow memory size
* (reboots)
*/
static uae_u32 REGPARAM2 emulib_ChgSMemSize(TrapContext *ctx, uae_u32 memsize)
static uae_u32 REGPARAM2 emulib_ChgSMemSize(TrapContext* ctx, uae_u32 memsize)
{
if (memsize != 0x80000 && memsize != 0x100000 &&
memsize != 0x180000 && memsize != 0x1C0000) {
memsize = 0;
write_log (_T("Unsupported bogomem size!\n"));
memsize != 0x180000 && memsize != 0x1C0000)
{
memsize = 0;
write_log(_T("Unsupported bogomem size!\n"));
}
trap_set_dreg(ctx, 0, 0);
changed_prefs.bogomem_size = memsize;
uae_reset (1, 1);
uae_reset(1, 1);
return 1;
}
@ -163,26 +162,27 @@ static uae_u32 REGPARAM2 emulib_ChgSMemSize(TrapContext *ctx, uae_u32 memsize)
* Changes fast memory size
* (reboots)
*/
static uae_u32 REGPARAM2 emulib_ChgFMemSize(TrapContext *ctx, uae_u32 memsize)
static uae_u32 REGPARAM2 emulib_ChgFMemSize(TrapContext* ctx, uae_u32 memsize)
{
if (memsize != 0x100000 && memsize != 0x200000 &&
memsize != 0x400000 && memsize != 0x800000) {
memsize = 0;
write_log (_T("Unsupported fastmem size!\n"));
memsize != 0x400000 && memsize != 0x800000)
{
memsize = 0;
write_log(_T("Unsupported fastmem size!\n"));
}
trap_set_dreg(ctx, 0, 0);
changed_prefs.fastmem[0].size = memsize;
uae_reset (1, 1);
uae_reset(1, 1);
return 0;
}
/*
* Inserts a disk
*/
static uae_u32 emulib_InsertDisk(TrapContext *ctx, uaecptr name, uae_u32 drive)
static uae_u32 emulib_InsertDisk(TrapContext* ctx, uaecptr name, uae_u32 drive)
{
char real_name[256];
TCHAR *s;
TCHAR* s;
if (drive > 3)
return 0;
@ -190,9 +190,9 @@ static uae_u32 emulib_InsertDisk(TrapContext *ctx, uaecptr name, uae_u32 drive)
if (trap_get_string(ctx, real_name, name, sizeof real_name) >= sizeof real_name)
return 0; /* ENAMETOOLONG */
s = au (real_name);
_tcscpy (changed_prefs.floppyslots[drive].df, s);
xfree (s);
s = au(real_name);
_tcscpy(changed_prefs.floppyslots[drive].df, s);
xfree(s);
return 1;
}
@ -202,14 +202,14 @@ static uae_u32 emulib_InsertDisk(TrapContext *ctx, uaecptr name, uae_u32 drive)
*/
static uae_u32 emulib_ExitEmu(void)
{
uae_quit ();
uae_quit();
return 1;
}
/*
* Gets UAE Configuration
*/
static uae_u32 emulib_GetUaeConfig(TrapContext *ctx, uaecptr place)
static uae_u32 emulib_GetUaeConfig(TrapContext* ctx, uaecptr place)
{
trap_put_long(ctx, place, version);
trap_put_long(ctx, place + 4, chipmem_bank.allocated_size);
@ -219,11 +219,11 @@ static uae_u32 emulib_GetUaeConfig(TrapContext *ctx, uaecptr place)
trap_put_long(ctx, place + 20, currprefs.produce_sound);
trap_put_long(ctx, place + 24, currprefs.jports[0].id | (currprefs.jports[1].id << 8));
trap_put_long(ctx, place + 28, currprefs.keyboard_lang);
if (disk_empty (0))
if (disk_empty(0))
trap_put_byte(ctx, place + 32, 0);
else
trap_put_byte(ctx, place + 32, 1);
if (disk_empty (1))
if (disk_empty(1))
trap_put_byte(ctx, place + 33, 0);
else
trap_put_byte(ctx, place + 33, 1);
@ -236,10 +236,11 @@ static uae_u32 emulib_GetUaeConfig(TrapContext *ctx, uaecptr place)
else
trap_put_byte(ctx, place + 35, 1);
for (int i = 0; i < 4; i++) {
char *s = ua (currprefs.floppyslots[i].df);
for (int i = 0; i < 4; i++)
{
char* s = ua(currprefs.floppyslots[i].df);
trap_put_string(ctx, s, place + 36 + i * 256, 256);
xfree (s);
xfree(s);
}
return 1;
}
@ -257,12 +258,12 @@ static uae_u32 emulib_SetUaeConfig(uaecptr place)
/*
* Gets the name of the disk in the given drive
*/
static uae_u32 emulib_GetDisk(TrapContext *ctx, uae_u32 drive, uaecptr name)
static uae_u32 emulib_GetDisk(TrapContext* ctx, uae_u32 drive, uaecptr name)
{
if (drive > 3)
return 0;
char *n = ua(currprefs.floppyslots[drive].df);
char* n = ua(currprefs.floppyslots[drive].df);
trap_put_string(ctx, (uae_u8*)n, name, 256);
xfree(n);
return 1;
@ -288,7 +289,7 @@ static uae_u32 emulib_Debug(void)
#define CALL_NATIVE_FUNC( d1,d2,d3,d4,d5,d6,d7,a1,a2,a3,a4,a5,a6 ) if(native_func) native_func( d1,d2,d3,d4,d5,d6,d7,a1,a2,a3,a4,a5,a6 )
/* A0 - Contains a ptr to the native .obj data. This ptr is Amiga-based. */
/* We simply find the first function in this .obj data, and execute it. */
static uae_u32 REGPARAM2 emulib_ExecuteNativeCode (void)
static uae_u32 REGPARAM2 emulib_ExecuteNativeCode(void)
{
#if 0
uaecptr object_AAM = m68k_areg (regs, 0);
@ -321,15 +322,15 @@ static uae_u32 REGPARAM2 emulib_ExecuteNativeCode (void)
return 0;
}
static uae_u32 emulib_Minimize (void)
static uae_u32 emulib_Minimize(void)
{
return 0; // OSDEP_minimize_uae();
}
static int native_dos_op(TrapContext *ctx, uae_u32 mode, uae_u32 p1, uae_u32 p2, uae_u32 p3)
static int native_dos_op(TrapContext* ctx, uae_u32 mode, uae_u32 p1, uae_u32 p2, uae_u32 p3)
{
TCHAR tmp[MAX_DPATH];
char *s;
char* s;
int v;
if (mode)
@ -340,67 +341,100 @@ static int native_dos_op(TrapContext *ctx, uae_u32 mode, uae_u32 p1, uae_u32 p2,
v = get_native_path(ctx, p1, tmp);
if (v)
return v;
s = ua (tmp);
s = ua(tmp);
trap_put_string(ctx, (uae_u8*)s, p2, p3);
xfree (s);
xfree(s);
return 0;
}
static uae_u32 uaelib_demux_common(TrapContext *ctx, uae_u32 ARG0, uae_u32 ARG1, uae_u32 ARG2, uae_u32 ARG3, uae_u32 ARG4, uae_u32 ARG5)
// Execute a command on the Host OS
static uae_u32 emulib_ExecuteOnHost(TrapContext* ctx, uaecptr name)
{
switch (ARG0) {
case 0: return emulib_GetVersion();
case 1: return emulib_GetUaeConfig(ctx, ARG1);
case 2: return emulib_SetUaeConfig(ARG1);
case 3: return emulib_HardReset();
case 4: return emulib_Reset();
case 5: return emulib_InsertDisk(ctx, ARG1, ARG2);
case 6: return emulib_EnableSound(ARG1);
case 7: return emulib_EnableJoystick(ARG1);
case 8: return emulib_SetFrameRate(ARG1);
case 9: return emulib_ChgCMemSize(ctx, ARG1);
case 10: return emulib_ChgSMemSize(ctx, ARG1);
case 11: return emulib_ChgFMemSize(ctx, ARG1);
case 12: return emulib_ChangeLanguage(ARG1);
/* The next call brings bad luck */
case 13: return emulib_ExitEmu();
case 14: return emulib_GetDisk(ctx, ARG1, ARG2);
case 15: return emulib_Debug();
char real_name[MAX_DPATH];
TCHAR* s;
case 68: return emulib_Minimize();
case 69: return emulib_ExecuteNativeCode();
if (trap_get_string(ctx, real_name, name, sizeof real_name) >= sizeof real_name)
return 0; /* ENAMETOOLONG */
case 70: return 0; /* RESERVED. Something uses this.. */
system(real_name);
return 1;
}
case 80:
static uae_u32 uaelib_demux_common(TrapContext* ctx, uae_u32 ARG0, uae_u32 ARG1, uae_u32 ARG2, uae_u32 ARG3,
uae_u32 ARG4, uae_u32 ARG5)
{
switch (ARG0)
{
case 0: return emulib_GetVersion();
case 1: return emulib_GetUaeConfig(ctx, ARG1);
case 2: return emulib_SetUaeConfig(ARG1);
case 3: return emulib_HardReset();
case 4: return emulib_Reset();
case 5: return emulib_InsertDisk(ctx, ARG1, ARG2);
case 6: return emulib_EnableSound(ARG1);
case 7: return emulib_EnableJoystick(ARG1);
case 8: return emulib_SetFrameRate(ARG1);
case 9: return emulib_ChgCMemSize(ctx, ARG1);
case 10: return emulib_ChgSMemSize(ctx, ARG1);
case 11: return emulib_ChgFMemSize(ctx, ARG1);
case 12: return emulib_ChangeLanguage(ARG1);
/* The next call brings bad luck */
case 13: return emulib_ExitEmu();
case 14: return emulib_GetDisk(ctx, ARG1, ARG2);
case 15: return emulib_Debug();
case 68: return emulib_Minimize();
case 69: return emulib_ExecuteNativeCode();
case 70: return 0; /* RESERVED. Something uses this.. */
case 80:
return 0xffffffff;
case 81: return cfgfile_uaelib(ctx, ARG1, ARG2, ARG3, ARG4);
case 82: return cfgfile_uaelib_modify(ctx, ARG1, ARG2, ARG3, ARG4, ARG5);
case 83: return 0;
case 85: return native_dos_op(ctx, ARG1, ARG2, ARG3, ARG4);
case 86:
if (valid_address(ARG1, 1)) {
case 81: return cfgfile_uaelib(ctx, ARG1, ARG2, ARG3, ARG4);
case 82: return cfgfile_uaelib_modify(ctx, ARG1, ARG2, ARG3, ARG4, ARG5);
case 83: currprefs.mmkeyboard = ARG1 ? 1 : 0; return currprefs.mmkeyboard;
#ifdef DEBUGGER
case 84: return mmu_init(ARG1, ARG2, ARG3);
#endif
case 85: return native_dos_op(ctx, ARG1, ARG2, ARG3, ARG4);
case 86:
if (valid_address(ARG1, 1))
{
uae_char tmp[MAX_DPATH];
trap_get_string(ctx, tmp, ARG1, sizeof tmp);
TCHAR *s = au(tmp);
TCHAR* s = au(tmp);
write_log(_T("DBG: %s\n"), s);
xfree(s);
return 1;
}
return 0;
case 87:
case 87:
{
uae_u32 d0, d1;
d0 = emulib_target_getcpurate(ARG1, &d1);
trap_set_dreg(ctx, 1, d1);
return d0;
}
case 88: return emulib_ExecuteOnHost(ctx, ARG1);
}
return 0;
}
static uae_u32 REGPARAM2 uaelib_demux2 (TrapContext *ctx)
uae_u32 uaeboard_demux(uae_u32* board)
{
uae_u32 arg0, arg1, arg2, arg3, arg4, arg5;
arg0 = do_get_mem_word((uae_u16*)&board[0]);
arg1 = do_get_mem_long(&board[2]);
arg2 = do_get_mem_long(&board[3]);
arg3 = do_get_mem_long(&board[4]);
arg4 = do_get_mem_long(&board[5]);
arg5 = do_get_mem_long(&board[6]);
return uaelib_demux_common(NULL, arg0, arg1, arg2, arg3, arg4, arg5);
}
static uae_u32 REGPARAM2 uaelib_demux2(TrapContext* ctx)
{
#define ARG0 (trap_get_long(ctx, trap_get_areg(ctx, 7) + 4))
#define ARG1 (trap_get_long(ctx, trap_get_areg(ctx, 7) + 8))
@ -416,26 +450,26 @@ static uae_u32 REGPARAM2 uaelib_demux2 (TrapContext *ctx)
return uaelib_demux_common(ctx, ARG0, ARG1, ARG2, ARG3, ARG4, ARG5);
}
static uae_u32 REGPARAM2 uaelib_demux (TrapContext *ctx)
static uae_u32 REGPARAM2 uaelib_demux(TrapContext* ctx)
{
uae_u32 v;
v = uaelib_demux2 (ctx);
v = uaelib_demux2(ctx);
return v;
}
/*
* Installs the UAE LIBRARY
*/
void emulib_install (void)
void emulib_install(void)
{
uaecptr a;
if (!uae_boot_rom_type && !currprefs.uaeboard)
return;
a = here ();
currprefs.mmkeyboard = 0;
org (rtarea_base + 0xFF60);
calltrap (deftrapres (uaelib_demux, 0, _T("uaelib_demux")));
dw (RTS);
org (a);
a = here();
currprefs.mmkeyboard = false;
org(rtarea_base + 0xFF60);
calltrap(deftrapres(uaelib_demux, 0, _T("uaelib_demux")));
dw(RTS);
org(a);
}