]> git.unchartedbackwaters.co.uk Git - francis/winuae.git/commitdiff
imported winuaesrc1400b1_.zip
authorToni Wilen <twilen@winuae.net>
Sat, 9 Sep 2006 19:38:49 +0000 (22:38 +0300)
committerToni Wilen <twilen@winuae.net>
Mon, 22 Feb 2010 19:29:31 +0000 (21:29 +0200)
116 files changed:
akiko.c
ar.c
arcadia.c
audio.c
autoconf.c
blitter.c
blkdev.c
bsdsocket.c
catweasel.c
cdrom.c
cdtv.c
cfgfile.c
cia.c
compemu_fpp.c
compemu_optimizer_x86.c
compemu_raw_x86.c
compemu_support.c
custom.c
debug.c
disk.c
dms/pfile.c
drawing.c
driveclick.c
enforcer.c
ersatz.c
expansion.c
filesys.c
fpp.c
fsdb.c
gayle.c
genblitter.c
gencomp.c
gencpu.c
genlinetoscr.c [new file with mode: 0755]
gfxlib.c
gfxutil.c
hardfile.c
identify.c
include/akiko.h
include/ar.h
include/autoconf.h
include/blitter.h
include/bsdsocket.h
include/cia.h
include/commpipe.h
include/compemu.h
include/cpu_prefetch.h
include/custom.h
include/drawing.h
include/events.h
include/identify.h
include/memory.h
include/native2amiga.h
include/newcpu.h
include/options.h
include/savestate.h
include/serial.h
include/sysdeps.h
include/traps.h [new file with mode: 0755]
include/uaeexe.h
include/xwin.h
inputdevice.c
keybuf.c
main.c
memory.c
moduleripper.c
native2amiga.c
newcpu.c
od-win32/ahidsound.c
od-win32/ahidsound.h
od-win32/avioutput.c
od-win32/blkdev_win32_ioctl.c
od-win32/bsdsock.c
od-win32/config.h [deleted file]
od-win32/dinput.c
od-win32/direct3d.c
od-win32/driveclick_win32.c
od-win32/dxwrap.c
od-win32/fsdb_win32.c
od-win32/genlinetoscr_msvc/genlinetoscr_msvc.vcproj [new file with mode: 0755]
od-win32/hardfile_win32.c
od-win32/keyboard_win32.c
od-win32/machdep/m68k.h
od-win32/midi.c
od-win32/mman.c
od-win32/opengl.c
od-win32/osdep/exectasks.h [deleted file]
od-win32/parser.c
od-win32/picasso96_win.c
od-win32/picasso96_win.h
od-win32/posixemu.c
od-win32/resources/winuae.rc
od-win32/screenshot.c
od-win32/serial_win32.c
od-win32/sounddep/sound.c
od-win32/sounddep/sound.h
od-win32/srcrelease.bat
od-win32/stackmagic_amd64.asm [deleted file]
od-win32/sys/mman.h
od-win32/sysconfig.h
od-win32/threaddep/thread.h
od-win32/win32.c
od-win32/win32.h
od-win32/win32_scale2x.c
od-win32/win32gfx.c
od-win32/win32gui.c
od-win32/winuae_msvc/winuae_msvc.vcproj
readcpu.c
savestate.c
scsi-none.c
scsiemul.c
traps.c [new file with mode: 0755]
uaeexe.c
uaeipc.c
uaelib.c
zfile.c

diff --git a/akiko.c b/akiko.c
index f7e3b6bd49858d328d4a9acb5f856d1872fc3dbc..bd26082925cebaf44387dc0da7decea289da7e1b 100755 (executable)
--- a/akiko.c
+++ b/akiko.c
@@ -14,9 +14,7 @@
 #include "sysconfig.h"
 #include "sysdeps.h"
 
-#include "config.h"
 #include "options.h"
-#include "uae.h"
 #include "memory.h"
 #include "events.h"
 #include "savestate.h"
@@ -945,7 +943,6 @@ void AKIKO_hsync_handler (void)
            gui_cd_led (1);
        cdrom_run_read ();
        framecounter = 1000000 / (74 * 75 * cdrom_speed);
-       framecounter = 1000000 / (74 * 75 * cdrom_speed);
        cdrom_status1 |= CDSTATUS_FRAME;
     }
     akiko_internal ();
@@ -1007,11 +1004,11 @@ static void *akiko_thread (void *null)
     return 0;
 }
 
-static uae_u8 akiko_get_long (uae_u32 v, int offset)
+STATIC_INLINE uae_u8 akiko_get_long (uae_u32 v, int offset)
 {
     return v >> ((3 - offset) * 8);
 }
-static void akiko_put_long (uae_u32 *p,        int offset, int v)
+STATIC_INLINE void akiko_put_long (uae_u32 *p, int offset, int v)
 {
     *p &= ~(0xff << ((3 - offset) * 8));
     *p |= v << ((3 - offset) * 8);
@@ -1110,12 +1107,12 @@ uae_u32 akiko_bget2 (uaecptr addr, int msg)
     return v;
 }
 
-uae_u32 akiko_bget (uaecptr addr)
+uae_u32 REGPARAM2 akiko_bget (uaecptr addr)
 {
     return akiko_bget2 (addr, 1);
 }
 
-uae_u32 akiko_wget (uaecptr addr)
+uae_u32 REGPARAM2 akiko_wget (uaecptr addr)
 {
     uae_u16 v;
     addr &= 0xffff;
@@ -1126,7 +1123,7 @@ uae_u32 akiko_wget (uaecptr addr)
     return v;
 }
 
-uae_u32 akiko_lget (uaecptr addr)
+uae_u32 REGPARAM2 akiko_lget (uaecptr addr)
 {
     uae_u32 v;
 
@@ -1232,12 +1229,12 @@ void akiko_bput2 (uaecptr addr, uae_u32 v, int msg)
     uae_sem_post (&akiko_sem);
 }
 
-void akiko_bput (uaecptr addr, uae_u32 v)
+void REGPARAM2 akiko_bput (uaecptr addr, uae_u32 v)
 {
     akiko_bput2 (addr, v, 1);
 }
 
-void akiko_wput (uaecptr addr, uae_u32 v)
+void REGPARAM2 akiko_wput (uaecptr addr, uae_u32 v)
 {
     addr &= 0xfff;
     if((addr < 0x30 && AKIKO_DEBUG_IO))
@@ -1246,7 +1243,7 @@ void akiko_wput (uaecptr addr, uae_u32 v)
     akiko_bput2 (addr + 0, v >> 8, 0);
 }
 
-void akiko_lput (uaecptr addr, uae_u32 v)
+void REGPARAM2 akiko_lput (uaecptr addr, uae_u32 v)
 {
     addr &= 0xffff;
     if(addr < 0x30 && AKIKO_DEBUG_IO)
@@ -1351,6 +1348,8 @@ int akiko_init (void)
     return 1;
 }
 
+#ifdef SAVESTATE
+
 uae_u8 *save_akiko(int *len)
 {
     uae_u8 *dstbak, *dst;
@@ -1472,6 +1471,7 @@ void restore_akiko_finish(void)
        sys_command_cd_play (DF_IOCTL, unitnum, last_play_pos, last_play_end, 0);
 }
 
+#endif
 
 void akiko_entergui (void)
 {
diff --git a/ar.c b/ar.c
index 453826ba8d7dcf793bf2db4ef851d08249cf8dfb..bedd29af7b020dda848fb50bdc38df45987dd22f 100755 (executable)
--- a/ar.c
+++ b/ar.c
 #include "sysconfig.h"
 #include "sysdeps.h"
 
-#include "config.h"
 #include "options.h"
 #include "uae.h"
 #include "memory.h"
@@ -273,7 +272,7 @@ static int REGPARAM2 hrtmem_check (uaecptr addr, uae_u32 size)
     return (addr + size) <= hrtmem_size;
 }
 
-static uae_u8 REGPARAM2 *hrtmem_xlate (uaecptr addr)
+static uae_u8 *REGPARAM2 hrtmem_xlate (uaecptr addr)
 {
     addr -= hrtmem_start & hrtmem_mask;
     addr &= hrtmem_mask;
@@ -319,14 +318,14 @@ uaecptr wait_for_pc = 0;    /* The program counter that we wait for. */
 /* returns true if the Program counter is currently in the AR rom. */
 int is_ar_pc_in_rom()
 {
-    uaecptr pc = m68k_getpc() & 0xFFFFFF;
+    uaecptr pc = m68k_getpc(&regs) & 0xFFFFFF;
     return pc >= arrom_start && pc < arrom_start+arrom_size;
 }
 
 /* returns true if the Program counter is currently in the AR RAM. */
 int is_ar_pc_in_ram()
 {
-    uaecptr pc = m68k_getpc() & 0xFFFFFF;
+    uaecptr pc = m68k_getpc(&regs) & 0xFFFFFF;
     return pc >= arram_start && pc < arram_start+arram_size;
 }
 
@@ -359,15 +358,15 @@ STATIC_INLINE int ar3a (uaecptr addr, uae_u8 b, int writing)
                    ar_wait_pop = 0;
                    /* We get (SP+2) here, as the first word on the stack is the status register. */
                    /* We want the following long, which is the return program counter. */
-                   wait_for_pc = longget(m68k_areg(regs,7)+2); /* Get (SP+2) */
-                   set_special (SPCFLAG_ACTION_REPLAY);
+                   wait_for_pc = longget(m68k_areg(&regs,7)+2); /* Get (SP+2) */
+                   set_special (&regs, SPCFLAG_ACTION_REPLAY);
 
-                   pc = m68k_getpc();
+                   pc = m68k_getpc(&regs);
 /*                 write_log_debug("Action Replay marked as ACTION_REPLAY_WAIT_PC, PC=%p\n",pc);*/
                }
                else
                {
-                   uaecptr pc = m68k_getpc();
+                   uaecptr pc = m68k_getpc(&regs);
 /*                 write_log_debug("Action Replay marked as IDLE, PC=%p\n",pc);*/
                    action_replay_flag = ACTION_REPLAY_IDLE;
                }
@@ -414,7 +413,7 @@ STATIC_INLINE int ar3a (uaecptr addr, uae_u8 b, int writing)
        } else {
            write_log("AR: exit with armode(%d)\n", armode);
        }
-       set_special (SPCFLAG_ACTION_REPLAY);
+       set_special (&regs, SPCFLAG_ACTION_REPLAY);
        action_replay_flag = ACTION_REPLAY_HIDE;
     } else if (addr == 6) {
        copytoamiga (regs.vbr + 0x7c, artemp, 4);
@@ -475,23 +474,23 @@ void REGPARAM2 chipmem_wput_actionreplay23 (uaecptr addr, uae_u32 w)
 }
 
 
-static uae_u32 arram_lget (uaecptr) REGPARAM;
-static uae_u32 arram_wget (uaecptr) REGPARAM;
-static uae_u32 arram_bget (uaecptr) REGPARAM;
-static void  arram_lput (uaecptr, uae_u32) REGPARAM;
-static void  arram_wput (uaecptr, uae_u32) REGPARAM;
-static void  arram_bput (uaecptr, uae_u32) REGPARAM;
-static int  arram_check (uaecptr addr, uae_u32 size) REGPARAM;
-static uae_u8 *arram_xlate (uaecptr addr) REGPARAM;
-
-static uae_u32 arrom_lget (uaecptr) REGPARAM;
-static uae_u32 arrom_wget (uaecptr) REGPARAM;
-static uae_u32 arrom_bget (uaecptr) REGPARAM;
-static void arrom_lput (uaecptr, uae_u32) REGPARAM;
-static void arrom_wput (uaecptr, uae_u32) REGPARAM;
-static void arrom_bput (uaecptr, uae_u32) REGPARAM;
-static int  arrom_check (uaecptr addr, uae_u32 size) REGPARAM;
-static uae_u8 *arrom_xlate (uaecptr addr) REGPARAM;
+static uae_u32 REGPARAM3 arram_lget (uaecptr) REGPARAM;
+static uae_u32 REGPARAM3 arram_wget (uaecptr) REGPARAM;
+static uae_u32 REGPARAM3 arram_bget (uaecptr) REGPARAM;
+static void  REGPARAM3 arram_lput (uaecptr, uae_u32) REGPARAM;
+static void  REGPARAM3 arram_wput (uaecptr, uae_u32) REGPARAM;
+static void  REGPARAM3 arram_bput (uaecptr, uae_u32) REGPARAM;
+static int  REGPARAM3 arram_check (uaecptr addr, uae_u32 size) REGPARAM;
+static uae_u8 *REGPARAM3 arram_xlate (uaecptr addr) REGPARAM;
+
+static uae_u32 REGPARAM3 arrom_lget (uaecptr) REGPARAM;
+static uae_u32 REGPARAM3 arrom_wget (uaecptr) REGPARAM;
+static uae_u32 REGPARAM3 arrom_bget (uaecptr) REGPARAM;
+static void REGPARAM3 arrom_lput (uaecptr, uae_u32) REGPARAM;
+static void REGPARAM3 arrom_wput (uaecptr, uae_u32) REGPARAM;
+static void REGPARAM3 arrom_bput (uaecptr, uae_u32) REGPARAM;
+static int  REGPARAM3 arrom_check (uaecptr addr, uae_u32 size) REGPARAM;
+static uae_u8 *REGPARAM3 arrom_xlate (uaecptr addr) REGPARAM;
 static void action_replay_unmap_banks(void);
 
 static uae_u32 action_replay_calculate_checksum(void);
@@ -508,19 +507,19 @@ static uae_u32 REGPARAM2 arram_lget (uaecptr addr)
     addr &= arram_mask;
     m = (uae_u32 *)(armemory_ram + addr);
     if (strncmp("T8", (char*)m, 2) == 0)
-       write_log_debug("Reading T8 from addr %08.08x PC=%p\n", addr, m68k_getpc());
+       write_log_debug("Reading T8 from addr %08.08x PC=%p\n", addr, m68k_getpc(&regs));
     if (strncmp("LAME", (char*)m, 4) == 0)
-       write_log_debug("Reading LAME from addr %08.08x PC=%p\n", addr, m68k_getpc());
+       write_log_debug("Reading LAME from addr %08.08x PC=%p\n", addr, m68k_getpc(&regs));
     if (strncmp("RES1", (char*)m, 4) == 0)
-       write_log_debug("Reading RES1 from addr %08.08x PC=%p\n", addr, m68k_getpc());
+       write_log_debug("Reading RES1 from addr %08.08x PC=%p\n", addr, m68k_getpc(&regs));
     if (strncmp("ARON", (char*)m, 4) == 0)
-       write_log_debug("Reading ARON from addr %08.08x PC=%p\n", addr, m68k_getpc());
+       write_log_debug("Reading ARON from addr %08.08x PC=%p\n", addr, m68k_getpc(&regs));
     if (strncmp("KILL", (char*)m, 4) == 0)
-       write_log_debug("Reading KILL from addr %08.08x PC=%p\n", addr, m68k_getpc());
+       write_log_debug("Reading KILL from addr %08.08x PC=%p\n", addr, m68k_getpc(&regs));
     if (strncmp("BRON", (char*)m, 4) == 0)
-       write_log_debug("Reading BRON from addr %08.08x PC=%p\n", addr, m68k_getpc());
+       write_log_debug("Reading BRON from addr %08.08x PC=%p\n", addr, m68k_getpc(&regs));
     if (strncmp("PRIN", (char*)m, 4) == 0)
-       write_log_debug("Reading PRIN from addr %08.08x PC=%p\n", addr, m68k_getpc());
+       write_log_debug("Reading PRIN from addr %08.08x PC=%p\n", addr, m68k_getpc(&regs));
     return do_get_mem_long (m);
 }
 
@@ -554,19 +553,19 @@ void REGPARAM2 arram_lput (uaecptr addr, uae_u32 l)
     addr &= arram_mask;
     m = (uae_u32 *)(armemory_ram + addr);
     if (strncmp("T8", (char*)m, 2) == 0)
-       write_log_debug("Writing T8 to addr %08.08x PC=%p\n", addr, m68k_getpc());
+       write_log_debug("Writing T8 to addr %08.08x PC=%p\n", addr, m68k_getpc(&regs));
     if (strncmp("LAME", (char*)m, 4) == 0)
-       write_log_debug("Writing LAME to addr %08.08x PC=%p\n", addr, m68k_getpc());
+       write_log_debug("Writing LAME to addr %08.08x PC=%p\n", addr, m68k_getpc(&regs));
     if (strncmp("RES1", (char*)m, 4) == 0)
-       write_log_debug("Writing RES1 to addr %08.08x PC=%p\n", addr, m68k_getpc());
+       write_log_debug("Writing RES1 to addr %08.08x PC=%p\n", addr, m68k_getpc(&regs));
     if (strncmp("ARON", (char*)m, 4) == 0)
-       write_log_debug("Writing ARON to addr %08.08x PC=%p\n", addr, m68k_getpc());
+       write_log_debug("Writing ARON to addr %08.08x PC=%p\n", addr, m68k_getpc(&regs));
     if (strncmp("KILL", (char*)m, 4) == 0)
-       write_log_debug("Writing KILL to addr %08.08x PC=%p\n", addr, m68k_getpc());
+       write_log_debug("Writing KILL to addr %08.08x PC=%p\n", addr, m68k_getpc(&regs));
     if (strncmp("BRON", (char*)m, 4) == 0)
-       write_log_debug("Writing BRON to addr %08.08x PC=%p\n", addr, m68k_getpc());
+       write_log_debug("Writing BRON to addr %08.08x PC=%p\n", addr, m68k_getpc(&regs));
     if (strncmp("PRIN", (char*)m, 4) == 0)
-       write_log_debug("Writing PRIN to addr %08.08x PC=%p\n", addr, m68k_getpc());
+       write_log_debug("Writing PRIN to addr %08.08x PC=%p\n", addr, m68k_getpc(&regs));
     do_put_mem_long (m, l);
 }
 
@@ -597,7 +596,7 @@ static int REGPARAM2 arram_check (uaecptr addr, uae_u32 size)
     return (addr + size) <= arram_size;
 }
 
-static uae_u8 REGPARAM2 *arram_xlate (uaecptr addr)
+static uae_u8 *REGPARAM2 arram_xlate (uaecptr addr)
 {
     addr -= arram_start;
     addr &= arram_mask;
@@ -675,7 +674,7 @@ static int REGPARAM2 arrom_check (uaecptr addr, uae_u32 size)
     return (addr + size) <= arrom_size;
 }
 
-static uae_u8 REGPARAM2 *arrom_xlate (uaecptr addr)
+static uae_u8 *REGPARAM2 arrom_xlate (uaecptr addr)
 {
     addr -= arrom_start;
     addr &= arrom_mask;
@@ -737,7 +736,7 @@ static void action_replay_go (void)
     hide_cart (0);
     memcpy (armemory_ram + 0xf000, ar_custom, 2 * 256);
     action_replay_flag = ACTION_REPLAY_ACTIVE;
-    set_special (SPCFLAG_ACTION_REPLAY);
+    set_special (&regs, SPCFLAG_ACTION_REPLAY);
     copyfromamiga (artemp, regs.vbr + 0x7c, 4);
     copytoamiga (regs.vbr+0x7c, armemory_rom + 0x7c, 4);
     Interrupt (7);
@@ -793,7 +792,7 @@ static void hrtmon_go (void)
     triggered_once = 1;
     cartridge_enter();
     hrtmon_flag = ACTION_REPLAY_ACTIVE;
-    set_special (SPCFLAG_ACTION_REPLAY);
+    set_special (&regs, SPCFLAG_ACTION_REPLAY);
     memcpy (hrtmon_custom, ar_custom, 2 * 256);
     for (i = 0; i < 16; i++) {
        if (hrtmon_ciaa)
@@ -805,7 +804,7 @@ static void hrtmon_go (void)
         old = get_long((uaecptr)(regs.vbr + 0x8));
        put_word (hrtmem_start + 0xc0000, 4);
        put_long ((uaecptr)(regs.vbr + 8), get_long (hrtmem_start + 8));
-       Exception (2, 0);
+       Exception (2, &regs, 0);
        put_long ((uaecptr)(regs.vbr + 8), old);
     } else {
         old = get_long((uaecptr)(regs.vbr + 0x7c));
@@ -838,9 +837,9 @@ void action_replay_enter(void)
        return;
     triggered_once = 1;
     if (armodel == 1) {
-       write_log("AR1: Enter PC:%p\n", m68k_getpc());
+       write_log("AR1: Enter PC:%p\n", m68k_getpc(&regs));
        action_replay_go1 (7);
-       unset_special (SPCFLAG_ACTION_REPLAY);
+       unset_special (&regs, SPCFLAG_ACTION_REPLAY);
        return;
     }
     if (action_replay_flag == ACTION_REPLAY_DORESET) {
@@ -892,7 +891,7 @@ void action_replay_reset(void)
 {
     if (hrtmemory) {
        if (savestate_state == STATE_RESTORE) {
-           if (m68k_getpc() >= hrtmem_start && m68k_getpc() <= hrtmem_start + hrtmem_size)
+           if (m68k_getpc(&regs) >= hrtmem_start && m68k_getpc(&regs) <= hrtmem_start + hrtmem_size)
                hrtmon_map_banks();
            else
                hrtmon_unmap_banks();
@@ -902,7 +901,7 @@ void action_replay_reset(void)
            return;
 
        if (savestate_state == STATE_RESTORE) {
-           if (m68k_getpc() >= arrom_start && m68k_getpc() <= arrom_start + arrom_size) {
+           if (m68k_getpc(&regs) >= arrom_start && m68k_getpc(&regs) <= arrom_start + arrom_size) {
                action_replay_flag = ACTION_REPLAY_ACTIVE;
                hide_cart (0);
            } else {
@@ -932,10 +931,10 @@ void action_replay_ciaread(void)
        return;
     if (armode < 2) /* If there are no active breakpoints*/
        return;
-    if (m68k_getpc() >= 0x200)
+    if (m68k_getpc(&regs) >= 0x200)
        return;
     action_replay_flag = ACTION_REPLAY_ACTIVATE;
-    set_special (SPCFLAG_ACTION_REPLAY);
+    set_special (&regs, SPCFLAG_ACTION_REPLAY);
 }
 
 int action_replay_freeze(void)
@@ -945,13 +944,13 @@ int action_replay_freeze(void)
            action_replay_chipwrite();
        } else {
            action_replay_flag = ACTION_REPLAY_ACTIVATE;
-           set_special (SPCFLAG_ACTION_REPLAY);
+           set_special (&regs, SPCFLAG_ACTION_REPLAY);
            armode = ARMODE_FREEZE;
        }
        return 1;
     } else {
        hrtmon_flag = ACTION_REPLAY_ACTIVATE;
-       set_special (SPCFLAG_ACTION_REPLAY);
+       set_special (&regs, SPCFLAG_ACTION_REPLAY);
        return 1;
     }
     return 0;
@@ -961,7 +960,7 @@ void action_replay_chipwrite(void)
 {
     if (armodel == 2 || armodel == 3) {
        action_replay_flag = ACTION_REPLAY_DORESET;
-       set_special (SPCFLAG_ACTION_REPLAY);
+       set_special (&regs, SPCFLAG_ACTION_REPLAY);
     } else if (armodel == 1) {
        /* copy 0x60 addr info to level 7 */
        /* This is to emulate the 0x60 interrupt. */
@@ -970,7 +969,7 @@ void action_replay_chipwrite(void)
        ar_wait_pop = 1; /* Wait for stack to pop. */
 
        action_replay_flag = ACTION_REPLAY_ACTIVATE;
-       set_special (SPCFLAG_ACTION_REPLAY);
+       set_special (&regs, SPCFLAG_ACTION_REPLAY);
     }
 }
 
@@ -987,7 +986,7 @@ void hrtmon_hide(void)
        return;
     hrtmon_flag = ACTION_REPLAY_IDLE;
     cartridge_exit();
-    unset_special (SPCFLAG_ACTION_REPLAY);
+    unset_special (&regs, SPCFLAG_ACTION_REPLAY);
     //write_log ("HRTMON: Exit\n");
 }
 
@@ -1332,7 +1331,7 @@ int action_replay_unload(int in_memory_reset)
                }
        }
 
-       unset_special(SPCFLAG_ACTION_REPLAY); /* This shouldn't be necessary here, but just in case. */
+       unset_special(&regs, SPCFLAG_ACTION_REPLAY); /* This shouldn't be necessary here, but just in case. */
        action_replay_flag = ACTION_REPLAY_INACTIVE;
        hrtmon_flag = ACTION_REPLAY_INACTIVE;
        action_replay_unsetbanks();
index 5ac08b0a0b7659ddefd5c2a2137a78e38e3deab7..fbb66490cbf8fd7dc07643d4011e84c22eb2e216 100755 (executable)
--- a/arcadia.c
+++ b/arcadia.c
@@ -10,7 +10,6 @@
 #include "sysconfig.h"
 #include "sysdeps.h"
 
-#include "config.h"
 #include "options.h"
 #include "uae.h"
 #include "memory.h"
diff --git a/audio.c b/audio.c
index fa2c708d55e1b9c222b8c6743b77ab9d35fa3721..c490ecfe1a0fab50df4fdc03a515e7b8d1e6e4e0 100755 (executable)
--- a/audio.c
+++ b/audio.c
@@ -15,7 +15,6 @@
 #include "sysconfig.h"
 #include "sysdeps.h"
 
-#include "config.h"
 #include "options.h"
 #include "memory.h"
 #include "custom.h"
 #ifdef AVIOUTPUT
 #include "avioutput.h"
 #endif
+#ifdef AHI
+#include "traps.h"
+#include "ahidsound.h"
+#endif
 
 #include <math.h>
 
@@ -961,7 +964,7 @@ static void setirq (int nr, int debug)
 {
 #ifdef DEBUG_AUDIO
     if (debugchannel (nr))
-       write_log ("SETIRQ %d %08.8X (%d)\n", nr, m68k_getpc(), debug);
+       write_log ("SETIRQ %d %08.8X (%d)\n", nr, M68K_GETPC, debug);
 #endif
     INTREQ (0x8000 | (0x80 << nr));
 }
@@ -1082,7 +1085,7 @@ static void audio_handler (int nr, int timed)
            if (currprefs.produce_sound == 0)
                cdp->per = PERIOD_MAX;
 
-           if (!cdp->dmaen && isirq (nr) && ((cdp->per <= 30 ) || (evtime == 0 || evtime == MAX_EV || evtime == cdp->per))) {
+           if (!cdp->dmaen && isirq (nr) && (evtime == 0 || evtime == MAX_EV || evtime == cdp->per)) {
                zerostate (cdp);
                return;
            }
@@ -1445,7 +1448,7 @@ void audio_hsync (int dmaaction)
 #ifdef DEBUG_AUDIO
            if (debugchannel (nr))
                write_log ("AUD%dDMA %d->%d (%d) LEN=%d/%d %08.8X\n", nr, cdp->dmaen, chan_ena,
-                   cdp->state, cdp->wlen, cdp->len, m68k_getpc());
+                   cdp->state, cdp->wlen, cdp->len, M68K_GETPC);
 #endif
            cdp->dmaen = chan_ena;
            if (cdp->dmaen)
@@ -1468,7 +1471,7 @@ void AUDxDAT (int nr, uae_u16 v)
 #ifdef DEBUG_AUDIO
     if (debugchannel (nr))
        write_log ("AUD%dDAT: %04.4X STATE=%d IRQ=%d %08.8X\n", nr,
-           v, cdp->state, isirq(nr) ? 1 : 0, m68k_getpc());
+           v, cdp->state, isirq(nr) ? 1 : 0, M68K_GETPC);
 #endif
     update_audio ();
     cdp->dat2 = v;
@@ -1488,7 +1491,7 @@ void AUDxLCH (int nr, uae_u16 v)
     audio_channel[nr].lc = (audio_channel[nr].lc & 0xffff) | ((uae_u32)v << 16);
 #ifdef DEBUG_AUDIO
     if (debugchannel (nr))
-       write_log ("AUD%dLCH: %04.4X %08.8X\n", nr, v, m68k_getpc());
+       write_log ("AUD%dLCH: %04.4X %08.8X\n", nr, v, M68K_GETPC);
 #endif
 }
 
@@ -1498,7 +1501,7 @@ void AUDxLCL (int nr, uae_u16 v)
     audio_channel[nr].lc = (audio_channel[nr].lc & ~0xffff) | (v & 0xFFFE);
 #ifdef DEBUG_AUDIO
     if (debugchannel (nr))
-       write_log ("AUD%dLCL: %04.4X %08.8X\n", nr, v, m68k_getpc());
+       write_log ("AUD%dLCL: %04.4X %08.8X\n", nr, v, M68K_GETPC);
 #endif
 }
 
@@ -1524,7 +1527,7 @@ void AUDxPER (int nr, uae_u16 v)
     audio_channel[nr].per = per;
 #ifdef DEBUG_AUDIO
     if (debugchannel (nr))
-       write_log ("AUD%dPER: %d %08.8X\n", nr, v, m68k_getpc());
+       write_log ("AUD%dPER: %d %08.8X\n", nr, v, M68K_GETPC);
 #endif
 }
 
@@ -1534,7 +1537,7 @@ void AUDxLEN (int nr, uae_u16 v)
     audio_channel[nr].len = v;
 #ifdef DEBUG_AUDIO
     if (debugchannel (nr))
-       write_log ("AUD%dLEN: %d %08.8X\n", nr, v, m68k_getpc());
+       write_log ("AUD%dLEN: %d %08.8X\n", nr, v, M68K_GETPC);
 #endif
 }
 
@@ -1548,7 +1551,7 @@ void AUDxVOL (int nr, uae_u16 v)
 #endif
 #ifdef DEBUG_AUDIO
     if (debugchannel (nr))
-       write_log ("AUD%dVOL: %d %08.8X\n", nr, v2, m68k_getpc());
+       write_log ("AUD%dVOL: %d %08.8X\n", nr, v2, M68K_GETPC);
 #endif
 }
 
@@ -1567,7 +1570,7 @@ void audio_update_irq (uae_u16 v)
        if ((1 << i) & DEBUG_CHANNEL_MASK) {
            uae_u16 mask = 0x80 << i;
            if ((v2 & mask) != (v3 & mask))
-               write_log("AUD%dINTREQ %d->%d %08.8X\n", i, !!(v3 & mask), !!(v2 & mask), m68k_getpc());
+               write_log("AUD%dINTREQ %d->%d %08.8X\n", i, !!(v3 & mask), !!(v2 & mask), M68K_GETPC);
        }
     }
 #endif
@@ -1584,7 +1587,7 @@ void audio_update_adkmasks (void)
     {
        static int prevcon = -1;
        if ((prevcon & 0xff) != (adkcon & 0xff)) {
-           write_log("ADKCON=%02.2x %08.8X\n", adkcon & 0xff, m68k_getpc());
+           write_log("ADKCON=%02.2x %08.8X\n", adkcon & 0xff, M68K_GETPC);
            prevcon = adkcon;
        }
     }
index 4ea59b1e4da84d176bdb6be7a11fe21768e8f36a..9d43904d6fd26980ae6ab18f3a873869ba58a155 100755 (executable)
@@ -10,7 +10,6 @@
 #include "sysconfig.h"
 #include "sysdeps.h"
 
-#include "config.h"
 #include "options.h"
 #include "uae.h"
 #include "memory.h"
 #include "events.h"
 #include "newcpu.h"
 #include "autoconf.h"
-#include "osdep/exectasks.h"
-
-/* We'll need a lot of these. */
-#define MAX_TRAPS 4096
-static TrapFunction traps[MAX_TRAPS];
-static int trapmode[MAX_TRAPS];
-static const char *trapstr[MAX_TRAPS];
-static uaecptr trapoldfunc[MAX_TRAPS];
-
-static int max_trap;
-int lasttrap;
-
-//#define sm_log write_log
-#define sm_log
-
-#ifdef CAN_DO_STACK_MAGIC
-
-/* Stack management */
-
-/* The mechanism for doing m68k calls from native code is as follows:
- *
- * m68k code executes, stack is main
- * calltrap to execute_fn_on_extra_stack. new stack is allocated
- * do_stack_magic is called for the first time
- * current context is saved with setjmp [0]
- *  transfer_control is done
- *   native code executes on new stack
- *   native code calls call_m68k
- *   setjmp saves current context [1]
- *  longjmp back to execute_fn_on_extra_stack [0]
- * pointer to new stack is saved on m68k stack. m68k return address set
- * to RTAREA_BASE + 0xFF00. m68k PC set to called function
- * m68k function executes, stack is main
- * m68k function returns to RTAREA_BASE + 0xFF00
- * calltrap to m68k_mode_return
- * do_stack_magic is called again
- * current context is saved again with setjmp [0]
- *  this time, transfer_control is _not_ done, instead a longjmp[1]
- *  to the previously saved context
- *   native code executes again on temp stack
- *   native function returns to stack_stub
- *  longjmp[0] back to old context
- * back again!
- *
- * A bearded man enters the room, carrying a bowl of spaghetti.
- */
-
-/* This _shouldn't_ crash with a stack size of 4096, but it does...
- * might be a bug */
-#ifndef EXTRA_STACK_SIZE
-#define EXTRA_STACK_SIZE 32768
-#endif
-#ifdef _WIN32
-#define WIN32_EXTRA_STACKS 30
-static void *win32_freestack[WIN32_EXTRA_STACKS]; //EXTRA_STACK_SIZE
-#endif
-
-struct extra_stack
-{
-    jmp_buf stackswap_env;
-    jmp_buf m68kcall_env;
-    uaecptr m68kcall_addr;
-    void *stack[EXTRA_STACK_SIZE - 2*sizeof(jmp_buf) - sizeof(uaecptr)];
-};
-
-
-static struct extra_stack *get_extra_stack (void)
-{
-    struct extra_stack *s;
-
-#ifdef _WIN32
-    {
-       extern uae_u8 *win32_stackbase;
-       int i;
-       for (i = 0;i < WIN32_EXTRA_STACKS; i++) { //0 to MAX_SELECT_THREADS
-           if(!win32_freestack[i])
-               break; //get a free block
-       }
-       if (i == WIN32_EXTRA_STACKS) {
-           gui_message("run out of extra stacks. this shouldn't happen.");
-           i = 0;
-       }
-       s = (struct extra_stack*)(win32_stackbase + (i * EXTRA_STACK_SIZE));
-       win32_freestack[i] = s;
-    }
-#else
-    s = xmalloc (sizeof (struct extra_stack));
-#endif
-    return s;
-}
-
-static void free_extra_stack (struct extra_stack *s)
-{
-#ifdef _WIN32
-    int i;
-    for (i = 0; i < WIN32_EXTRA_STACKS; i++) {//0 to MAX_SELECT_THREADS
-       if(win32_freestack[i] == s)
-           break; //got a free block
-    }
-    win32_freestack[i] = 0;
-#else
-    free (s);
-#endif
-}
-
-static void stack_stub (struct extra_stack *s, TrapFunction f, uae_u32 *retval)
-{
-    sm_log("in stack_stub: %p %p %p %x\n", s, f, retval, (int)*retval);
-    *retval = f ();
-    sm_log("returning from stack_stub\n");
-    longjmp (s->stackswap_env, 1);
-}
-
-static struct extra_stack *current_extra_stack = NULL;
-
-static void do_stack_magic (TrapFunction f, struct extra_stack *s, int has_retval)
-{
-    switch (setjmp (s->stackswap_env)) {
-     case 0:
-       /* Returning directly */
-       current_extra_stack = s;
-       if (has_retval == -1) {
-           sm_log("finishing m68k mode return\n");
-           longjmp (s->m68kcall_env, 1);
-       }
-       sm_log("calling native function\n");
-       transfer_control (s, EXTRA_STACK_SIZE, stack_stub, f, has_retval);
-       /* not reached */
-       abort ();
-
-     case 1:
-       sm_log("native function complete\n");
-       /* Returning normally. */
-       if (stack_has_retval (s, EXTRA_STACK_SIZE))
-           m68k_dreg (regs, 0) = get_retval_from_stack (s, EXTRA_STACK_SIZE);
-       free_extra_stack (s);
-       break;
-
-     case 2: {
-       /* Returning to do a m68k call. We're now back on the main stack. */
-       uaecptr a7 = m68k_areg (regs, 7) -= (sizeof (void *) + 7) & ~3;
-       /* Save stack to restore */
-       *((void **)get_real_address (a7 + 4)) = s;
-       /* Save special return address: this address contains a
-        * calltrap that will longjmp to the right stack. */
-       put_long (m68k_areg (regs, 7), RTAREA_BASE + 0xFF00);
-       m68k_setpc (s->m68kcall_addr);
-       fill_prefetch_slow ();
-       sm_log("native function calls m68k\n");
-       break;
-     }
-    }
-    current_extra_stack = 0;
-}
-
-static uae_u32 execute_fn_on_extra_stack (TrapFunction f, int has_retval)
-{
-    struct extra_stack *s = get_extra_stack ();
-    do_stack_magic (f, s, has_retval);
-    return 0;
-}
-
-static uae_u32 m68k_mode_return (void)
-{
-    uaecptr a7 = m68k_areg (regs, 7);
-    struct extra_stack *s = *(struct extra_stack **)get_real_address (a7);
-    m68k_areg (regs, 7) += (sizeof (void *) + 3) & ~3;
-    sm_log("doing m68k mode return\n");
-    do_stack_magic (NULL, s, -1);
-    return 0;
-}
-
-static uae_u32 call_m68k (uaecptr addr, int saveregs)
-{
-    volatile uae_u32 retval = 0;
-    volatile int do_save = saveregs;
-
-    sm_log("\nDoing call_m68k (addr=%08x, savereg=%d) extra_stack=%p\n",
-                 addr,saveregs,current_extra_stack);
-
-    if (current_extra_stack != NULL)
-    {
-       volatile struct regstruct saved_regs;
-       struct extra_stack *s = current_extra_stack;
-
-       if (do_save)
-           saved_regs = regs;
-
-       s->m68kcall_addr = addr;
-
-       switch (setjmp (s->m68kcall_env)) {
-        case 0:
-           /*write_log ("doing call\n");*/
-           /* Returning directly: now switch to main stack and do the call */
-           longjmp (s->stackswap_env, 2);
-        case 1:
-           /*write_log ("returning from call\n");*/
-           retval = m68k_dreg (regs, 0);
-           if (do_save)
-               regs = saved_regs;
-           /* Returning after the call. */
-           break;
-       }
-    } else
-       abort ();
-
-    return retval;
-}
-
-uae_u32 CallLib (uaecptr base, uae_s16 offset)
-{
-    int i;
-    uaecptr olda6 = m68k_areg (regs, 6);
-    uae_u32 retval;
-#if 0
-    for (i = 0; i < n_libpatches; i++) {
-       if (libpatches[i].libbase == base && libpatches[i].functions[-offset/6] != NULL)
-           return (*libpatches[i].functions[-offset/6])();
-    }
-#endif
-    m68k_areg (regs, 6) = base;
-    retval = call_m68k (base + offset, 1);
-    m68k_areg (regs, 6) = olda6;
-    return retval;
-}
-
-#else
-
-/*
- * Stubs for when building without stack magic
- */
-static uae_u32 m68k_mode_return (void)
-{
-    return 0;
-}
-
-uae_u32 CallLib (uaecptr base, uae_s16 offset)
-{
-    /* Shouldn't be necessary */
-    write_log ("WARNING: Calling 68k code from UAE is not supported in this version.\n");
-    return 0;
-}
-
-#endif
+#include "traps.h"
 
 /* Commonly used autoconfig strings */
 
 uaecptr EXPANSION_explibname, EXPANSION_doslibname, EXPANSION_uaeversion;
-uaecptr EXPANSION_uaedevname, EXPANSION_explibbase = 0, EXPANSION_haveV36;
+uaecptr EXPANSION_uaedevname, EXPANSION_explibbase = 0;
 uaecptr EXPANSION_bootcode, EXPANSION_nullfunc;
-uaecptr EXPANSION_cddevice;
 
 /* ROM tag area memory access */
 
 uae_u8 *rtarea;
 
-static uae_u32 rtarea_lget (uaecptr) REGPARAM;
-static uae_u32 rtarea_wget (uaecptr) REGPARAM;
-static uae_u32 rtarea_bget (uaecptr) REGPARAM;
-static void rtarea_lput (uaecptr, uae_u32) REGPARAM;
-static void rtarea_wput (uaecptr, uae_u32) REGPARAM;
-static void rtarea_bput (uaecptr, uae_u32) REGPARAM;
-static uae_u8 *rtarea_xlate (uaecptr) REGPARAM;
+static uae_u32 REGPARAM3 rtarea_lget (uaecptr) REGPARAM;
+static uae_u32 REGPARAM3 rtarea_wget (uaecptr) REGPARAM;
+static uae_u32 REGPARAM3 rtarea_bget (uaecptr) REGPARAM;
+static void REGPARAM3 rtarea_lput (uaecptr, uae_u32) REGPARAM;
+static void REGPARAM3 rtarea_wput (uaecptr, uae_u32) REGPARAM;
+static void REGPARAM3 rtarea_bput (uaecptr, uae_u32) REGPARAM;
+static uae_u8 *REGPARAM3 rtarea_xlate (uaecptr) REGPARAM;
 
 addrbank rtarea_bank = {
     rtarea_lget, rtarea_wget, rtarea_bget,
@@ -288,7 +43,7 @@ addrbank rtarea_bank = {
     rtarea_xlate, default_check, NULL, "UAE Boot ROM"
 };
 
-uae_u8 REGPARAM2 *rtarea_xlate (uaecptr addr)
+uae_u8 *REGPARAM2 rtarea_xlate (uaecptr addr)
 {
     addr &= 0xFFFF;
     return rtarea + addr;
@@ -342,82 +97,6 @@ void REGPARAM2 rtarea_bput (uaecptr addr, uae_u32 value)
 #endif
 }
 
-static const int trace_traps = 1;
-
-void REGPARAM2 call_calltrap (int func)
-{
-    uae_u32 retval = 0;
-    int has_retval = (trapmode[func] & TRAPFLAG_NO_RETVAL) == 0;
-    int implicit_rts = (trapmode[func] & TRAPFLAG_DORET) != 0;
-
-    if (trapstr[func] && *trapstr[func] != 0 && trace_traps)
-       write_log ("TRAP: %s\n", trapstr[func]);
-
-    /* For monitoring only? */
-    if (traps[func] == NULL) {
-       m68k_setpc (trapoldfunc[func]);
-       fill_prefetch_slow ();
-       return;
-    }
-
-    if (func < max_trap) {
-#ifdef CAN_DO_STACK_MAGIC
-       if (trapmode[func] & TRAPFLAG_EXTRA_STACK) {
-           execute_fn_on_extra_stack(traps[func], has_retval);
-           return;
-       }
-#endif
-       retval = (*traps[func])();
-    } else
-       write_log ("illegal emulator trap\n");
-
-    if (has_retval)
-       m68k_dreg (regs, 0) = retval;
-    if (implicit_rts) {
-       m68k_do_rts ();
-       fill_prefetch_slow ();
-    }
-}
-
-#ifdef CAN_DO_STACK_MAGIC
-/* @$%& compiler bugs */
-static volatile int four = 4;
-
-uaecptr libemu_InstallFunctionFlags (TrapFunction f, uaecptr libbase, int offset,
-     int flags, const char *tracename)
-{
-    int i;
-    uaecptr retval;
-    uaecptr execbase = get_long (four);
-    int trnum;
-    uaecptr addr = here ();
-    calltrap (trnum = deftrap2 (f, flags, tracename));
-    dw (RTS);
-
-    m68k_areg (regs, 1) = libbase;
-    m68k_areg (regs, 0) = offset;
-    m68k_dreg (regs, 0) = addr;
-    retval = CallLib (execbase, -420);
-
-    trapoldfunc[trnum] = retval;
-#if 0
-    for (i = 0; i < n_libpatches; i++) {
-       if (libpatches[i].libbase == libbase)
-           break;
-    }
-    if (i == n_libpatches) {
-       int j;
-       libpatches[i].libbase = libbase;
-       for (j = 0; j < 300; j++)
-           libpatches[i].functions[j] = NULL;
-       n_libpatches++;
-    }
-    libpatches[i].functions[-offset/6] = f;
-#endif
-    return retval;
-}
-#endif
-
 /* some quick & dirty code to fill in the rt area and save me a lot of
  * scratch paper
  */
@@ -453,7 +132,7 @@ void dl (uae_u32 data)
  * backward.  store pointer at current address
  */
 
-uae_u32 ds (char *str)
+uae_u32 ds (const char *str)
 {
     int len = strlen (str) + 1;
 
@@ -478,39 +157,25 @@ uae_u32 here (void)
     return addr (rt_addr);
 }
 
-int deftrap2 (TrapFunction func, int mode, const char *str)
-{
-    int num = max_trap++;
-    traps[num] = func;
-    trapstr[num] = str;
-    trapmode[num] = mode;
-    return num;
-}
-
-int deftrap (TrapFunction func)
-{
-    return deftrap2 (func, 0, "");
-}
-
 void align (int b)
 {
     rt_addr = (rt_addr + b - 1) & ~(b - 1);
 }
 
-static uae_u32 nullfunc (void)
+static uae_u32 REGPARAM2 nullfunc (TrapContext *context)
 {
     write_log ("Null function called\n");
     return 0;
 }
 
-static uae_u32 getchipmemsize (void)
+static uae_u32 REGPARAM2 getchipmemsize (TrapContext *context)
 {
     return allocated_chipmem;
 }
 
-static uae_u32 uae_puts (void)
+static uae_u32 REGPARAM2 uae_puts (TrapContext *context)
 {
-    puts (get_real_address (m68k_areg (regs, 0)));
+    puts ((char *)get_real_address (m68k_areg (&context->regs, 0)));
     return 0;
 }
 
@@ -531,7 +196,8 @@ void rtarea_init (void)
 
     rt_straddr = 0xFF00 - 2;
     rt_addr = 0;
-    max_trap = 0;
+
+    init_traps ();
 
     rtarea_init_mem ();
 
@@ -543,16 +209,15 @@ void rtarea_init (void)
     EXPANSION_uaedevname = ds ("uae.device");
 
     deftrap (NULL); /* Generic emulator trap */
-    lasttrap = 0;
 
     EXPANSION_nullfunc = here ();
     calltrap (deftrap (nullfunc));
     dw (RTS);
 
     a = here();
-    /* Standard "return from 68k mode" trap */
+    /* Dummy trap - removing this breaks the filesys emulation. */
     org (RTAREA_BASE + 0xFF00);
-    calltrap (deftrap2 (m68k_mode_return, TRAPFLAG_NO_RETVAL, ""));
+    calltrap (deftrap2 (nullfunc, TRAPFLAG_NO_RETVAL, ""));
 
     org (RTAREA_BASE + 0xFF80);
     calltrap (deftrap2 (getchipmemsize, TRAPFLAG_DORET, ""));
@@ -566,6 +231,8 @@ void rtarea_init (void)
 #ifdef FILESYS
     filesys_install_code ();
 #endif
+
+    init_extended_traps();
 }
 
 volatile int uae_int_requested = 0;
index 166ccef08e77078e91c2ac9fc274b414a6f8e01b..380b7d3d160950c6f1d47b9b8a5dc6149d83596b 100755 (executable)
--- a/blitter.c
+++ b/blitter.c
@@ -15,7 +15,6 @@
 #include "sysconfig.h"
 #include "sysdeps.h"
 
-#include "config.h"
 #include "options.h"
 #include "uae.h"
 #include "memory.h"
@@ -29,7 +28,6 @@
 /* we must not change ce-mode while blitter is running.. */
 static int blitter_cycle_exact;
 
-uae_u16 oldvblts;
 uae_u16 bltcon0,bltcon1;
 uae_u32 bltapt,bltbpt,bltcpt,bltdpt;
 
@@ -53,7 +51,6 @@ struct bltinfo blt_info;
 
 static uae_u8 blit_filltable[256][4][2];
 uae_u32 blit_masktable[BLITTER_MAX_WORDS];
-static uae_u16 blit_trashtable[BLITTER_MAX_WORDS];
 enum blitter_states bltstate;
 
 static int blit_cyclecounter, blit_maxcyclecounter, blit_slowdown;
@@ -67,7 +64,7 @@ static long blit_firstline_cycles;
 static long blit_first_cycle;
 static int blit_last_cycle, blit_dmacount, blit_dmacount2;
 static int blit_linecycles, blit_extracycles, blit_nod;
-static int *blit_diag;
+static const int *blit_diag;
 
 static uae_u16 ddat1, ddat2;
 static int ddat1use, ddat2use;
@@ -127,7 +124,7 @@ BLTNASTY=0 makes things even more interesting..
 
 /* -1 = idle cycle and allocate bus */
 
-static int blit_cycle_diagram[][10] =
+static const int blit_cycle_diagram[][10] =
 {
     { 0, 2, 0,0 },             /* 0 */
     { 0, 2, 0,4 },             /* 1 */
@@ -149,7 +146,7 @@ static int blit_cycle_diagram[][10] =
 
 /* 5 = fill mode idle cycle ("real" idle cycle) */
 
-static int blit_cycle_diagram_fill[][10] =
+static const int blit_cycle_diagram_fill[][10] =
 {
     { 0, 3, 0,5,0 },           /* 0 */
     { 0, 3, 3,5,4 },           /* 1 */
@@ -185,12 +182,12 @@ static int blit_cycle_diagram_fill[][10] =
 
 */
 
-static int blit_cycle_diagram_line[] =
+static const int blit_cycle_diagram_line[] =
 {
     0, 4, 0,3,0,4, 0,0,0,0,0,0,0,0,0,0  /* guessed */
 };
 
-static int blit_cycle_diagram_finald[] =
+static const int blit_cycle_diagram_finald[] =
     { 0, 2, 0,4 };
 
 void build_blitfilltable(void)
@@ -271,7 +268,7 @@ static void blitter_done (void)
     blitter_done_notify ();
     INTREQ(0x8040);
     eventtab[ev_blitter].active = 0;
-    unset_special (SPCFLAG_BLTNASTY);
+    unset_special (&regs, SPCFLAG_BLTNASTY);
 #ifdef BLITTER_DEBUG
     write_log ("vpos=%d, cycles %d, missed %d, total %d\n",
        vpos, blit_cyclecounter, blit_misscyclecounter, blit_cyclecounter + blit_misscyclecounter);
@@ -932,7 +929,8 @@ static void blit_bltset (int con)
 
     if (blitline) {
        if (blt_info.hblitsize != 2)
-           write_log ("weird hblitsize in linemode: %d vsize=%d PC%=%x\n", blt_info.hblitsize, blt_info.vblitsize, m68k_getpc());
+           write_log ("weird hblitsize in linemode: %d vsize=%d PC%=%x\n",
+               blt_info.hblitsize, blt_info.vblitsize, m68k_getpc(&regs));
        blit_diag = blit_cycle_diagram_line;
     } else {
        if (con & 2) {
@@ -943,7 +941,8 @@ static void blit_bltset (int con)
                * negative effects. */
                static int warn = 1;
                if (warn)
-                   write_log ("warning: weird fill mode (further messages suppressed) PC=%x\n", m68k_getpc());
+                   write_log ("warning: weird fill mode (further messages suppressed) PC=%x\n",
+                       m68k_getpc(&regs));
                warn = 0;
                blitife = 0;
            }
@@ -951,7 +950,8 @@ static void blit_bltset (int con)
        if (blitfill && !blitdesc) {
            static int warn = 1;
            if (warn)
-               write_log ("warning: blitter fill without desc (further messages suppressed) PC=%x\n", m68k_getpc());
+               write_log ("warning: blitter fill without desc (further messages suppressed) PC=%x\n",
+                   m68k_getpc(&regs));
            warn = 0;
        }
        blit_diag = blitfill ? blit_cycle_diagram_fill[blit_ch] : blit_cycle_diagram[blit_ch];
@@ -1047,9 +1047,9 @@ void do_blitter (int hpos)
 #endif
     blit_slowdown = 0;
 
-    unset_special (SPCFLAG_BLTNASTY);
+    unset_special (&regs, SPCFLAG_BLTNASTY);
     if (dmaen(DMA_BLITPRI))
-       set_special (SPCFLAG_BLTNASTY);
+       set_special (&regs, SPCFLAG_BLTNASTY);
 
     if (blt_info.vblitsize == 0 || (blitline && blt_info.hblitsize != 2)) {
        blitter_done ();
@@ -1094,9 +1094,9 @@ void maybe_blit (int hpos, int hack)
 #ifndef BLITTER_DEBUG
        warned = 1;
 #endif
-       if (m68k_getpc() < 0xe0000 || m68k_getpc() >= 0x10000000)
+       if (m68k_getpc(&regs) < 0xe0000 || m68k_getpc(&regs) >= 0x10000000)
            write_log ("warning: Program does not wait for blitter %p vpos=%d tc=%d\n",
-               m68k_getpc(), vpos, blit_cyclecounter);
+               m68k_getpc(&regs), vpos, blit_cyclecounter);
     }
 
     if (blitter_cycle_exact) {
@@ -1161,6 +1161,8 @@ void blitter_slowdown (int ddfstrt, int ddfstop, int totalcycles, int freecycles
     blit_misscyclecounter += slow;
 }
 
+#ifdef SAVESTATE
+
 uae_u8 *restore_blitter (uae_u8 *src)
 {
     uae_u32 flags = restore_u32();
@@ -1202,3 +1204,5 @@ uae_u8 *save_blitter (int *len, uae_u8 *dstptr)
     return dstbak;
 
 }
+
+#endif /* SAVESTATE */
index 9a50f76bb61363a899a5f8c7dd2c442ae01172bf..c258d08e8125518d8865705f1c79d198ac7d9549 100755 (executable)
--- a/blkdev.c
+++ b/blkdev.c
 #include "options.h"
 #include "memory.h"
 
-#include "config.h"
-
 #include "blkdev.h"
 #include "scsidev.h"
 
 static struct device_functions *device_func[2];
-static int ioctl;
+static int have_ioctl;
 
 #ifdef WIN32
 
@@ -49,7 +47,7 @@ static void install_driver (int flags)
 
 int sys_command_open (int mode, int unitnum)
 {
-    if (mode == DF_SCSI || !ioctl)
+    if (mode == DF_SCSI || !have_ioctl)
        return device_func[DF_SCSI]->opendev (unitnum);
     else
        return device_func[DF_IOCTL]->opendev (unitnum);
@@ -57,7 +55,7 @@ int sys_command_open (int mode, int unitnum)
 
 void sys_command_close (int mode, int unitnum)
 {
-    if (mode == DF_SCSI || !ioctl)
+    if (mode == DF_SCSI || !have_ioctl)
        device_func[DF_SCSI]->closedev (unitnum);
     else
        device_func[DF_IOCTL]->closedev (unitnum);
@@ -73,11 +71,11 @@ int device_func_init (int flags)
        return initialized;
     install_driver (flags);
     if (device_func[DF_IOCTL])
-       ioctl = 1;
+       have_ioctl = 1;
     else
-       ioctl = 0;
+       have_ioctl = 0;
     support_scsi = device_func[DF_SCSI]->openbus (oflags) ? 1 : 0;
-    if (ioctl)
+    if (have_ioctl)
        support_ioctl = device_func[DF_IOCTL]->openbus (1 << INQ_ROMD) ? 1 : 0;
     initialized = 1;
     write_log ("support_scsi = %d support_ioctl = %d\n", support_scsi, support_ioctl);
@@ -96,7 +94,7 @@ static int audiostatus (int unitnum)
 /* pause/unpause CD audio */
 void sys_command_cd_pause (int mode, int unitnum, int paused)
 {
-    if (mode == DF_SCSI || !ioctl) {
+    if (mode == DF_SCSI || !have_ioctl) {
        int as = audiostatus (unitnum);
        if ((paused && as == 0x11) && (!paused && as == 0x12)) {
            uae_u8 cmd[10] = {0x4b,0,0,0,0,0,0,0,paused?0:1,0};
@@ -110,7 +108,7 @@ void sys_command_cd_pause (int mode, int unitnum, int paused)
 /* stop CD audio */
 void sys_command_cd_stop (int mode, int unitnum)
 {
-    if (mode == DF_SCSI || !ioctl) {
+    if (mode == DF_SCSI || !have_ioctl) {
        int as = audiostatus (unitnum);
        if (as == 0x11) {
            uae_u8 cmd[6] = {0x4e,0,0,0,0,0};
@@ -124,7 +122,7 @@ void sys_command_cd_stop (int mode, int unitnum)
 /* play CD audio */
 int sys_command_cd_play (int mode, int unitnum,uae_u32 startmsf, uae_u32 endmsf, int scan)
 {
-    if (mode == DF_SCSI || !ioctl) {
+    if (mode == DF_SCSI || !have_ioctl) {
        uae_u8 cmd[12] = {0,0,0,0,0,0,0,0,0,0,0,0};
 #if 0
        if (scan) {
@@ -154,7 +152,7 @@ int sys_command_cd_play (int mode, int unitnum,uae_u32 startmsf, uae_u32 endmsf,
 /* read qcode */
 uae_u8 *sys_command_cd_qcode (int mode, int unitnum)
 {
-    if (mode == DF_SCSI || !ioctl) {
+    if (mode == DF_SCSI || !have_ioctl) {
        uae_u8 cmd[10] = {0x42,2,0x40,1,0,0,0,DEVICE_SCSI_BUFSIZE>>8,DEVICE_SCSI_BUFSIZE&0xff,0};
        return  device_func[DF_SCSI]->exec_in (unitnum, cmd, sizeof (cmd), 0);
     }
@@ -164,7 +162,7 @@ uae_u8 *sys_command_cd_qcode (int mode, int unitnum)
 /* read table of contents */
 uae_u8 *sys_command_cd_toc (int mode, int unitnum)
 {
-    if (mode == DF_SCSI || !ioctl) {
+    if (mode == DF_SCSI || !have_ioctl) {
        uae_u8 cmd [10] = { 0x43,0,2,0,0,0,1,DEVICE_SCSI_BUFSIZE>>8,DEVICE_SCSI_BUFSIZE&0xFF,0};
        return device_func[DF_SCSI]->exec_in (unitnum, cmd, sizeof(cmd), 0);
     }
@@ -174,7 +172,7 @@ uae_u8 *sys_command_cd_toc (int mode, int unitnum)
 /* read one cd sector */
 uae_u8 *sys_command_cd_read (int mode, int unitnum, int offset)
 {
-    if (mode == DF_SCSI || !ioctl) {
+    if (mode == DF_SCSI || !have_ioctl) {
        uae_u8 cmd[12] = { 0xbe, 0, 0, 0, 0, 0, 0, 0, 1, 0x10, 0, 0 };
        cmd[3] = (uae_u8)(offset >> 16);
        cmd[4] = (uae_u8)(offset >> 8);
@@ -187,7 +185,7 @@ uae_u8 *sys_command_cd_read (int mode, int unitnum, int offset)
 /* read block */
 uae_u8 *sys_command_read (int mode, int unitnum, int offset)
 {
-    if (mode == DF_SCSI || !ioctl) {
+    if (mode == DF_SCSI || !have_ioctl) {
        uae_u8 cmd[10] = { 0x28, 0, 0, 0, 0, 0, 0, 0, 1, 0 };
        cmd[2] = (uae_u8)(offset >> 24);
        cmd[3] = (uae_u8)(offset >> 16);
@@ -201,7 +199,7 @@ uae_u8 *sys_command_read (int mode, int unitnum, int offset)
 /* write block */
 int sys_command_write (int mode, int unitnum, int offset)
 {
-    if (mode == DF_SCSI || !ioctl) {
+    if (mode == DF_SCSI || !have_ioctl) {
        uae_u8 cmd[10] = { 0x2a, 0, 0, 0, 0, 0, 0, 0, 1, 0 };
        cmd[2] = (uae_u8)(offset >> 24);
        cmd[3] = (uae_u8)(offset >> 16);
@@ -216,7 +214,7 @@ int sys_command_write (int mode, int unitnum, int offset)
 
 struct device_info *sys_command_info (int mode, int unitnum, struct device_info *di)
 {
-    if (mode == DF_SCSI || !ioctl)
+    if (mode == DF_SCSI || !have_ioctl)
        return device_func[DF_SCSI]->info (unitnum, di);
     else
        return device_func[DF_IOCTL]->info (unitnum, di);
@@ -224,7 +222,7 @@ struct device_info *sys_command_info (int mode, int unitnum, struct device_info
 
 struct device_scsi_info *sys_command_scsi_info (int mode, int unitnum, struct device_scsi_info *dsi)
 {
-    if (mode == DF_SCSI || !ioctl)
+    if (mode == DF_SCSI || !have_ioctl)
        return device_func[DF_SCSI]->scsiinfo (unitnum, dsi);
     else
        return device_func[DF_IOCTL]->scsiinfo (unitnum, dsi);
index 85740237f839327477262b290dc5b5249b7b26dc..67e8fe82029e57cf0814c561bb68ac65184508f1 100755 (executable)
 #include <assert.h>
 #include <stddef.h>
 
-#include "config.h"
 #include "options.h"
 #include "memory.h"
 #include "custom.h"
 #include "newcpu.h"
 #include "autoconf.h"
+#include "traps.h"
 #include "bsdsocket.h"
-#include "osdep/exectasks.h"
 
 #ifdef BSDSOCKET
 
@@ -38,7 +37,7 @@ uae_u32 sockpoolflags[SOCKPOOLSIZE];
 long curruniqid = 65536;
 
 /* Memory-related helper functions */
-static void memcpyha (uae_u32 dst, char *src, int size)
+STATIC_INLINE void memcpyha (uae_u32 dst, const char *src, int size)
 {
     while (size--)
        put_byte (dst++, *src++);
@@ -58,7 +57,7 @@ char *strcpyah (char *dst, uae_u32 src)
     return res;
 }
 
-uae_u32 strcpyha (uae_u32 dst, char *src)
+uae_u32 strcpyha (uae_u32 dst, const char *src)
 {
     uae_u32 res = dst;
 
@@ -69,7 +68,7 @@ uae_u32 strcpyha (uae_u32 dst, char *src)
     return res;
 }
 
-uae_u32 strncpyha (uae_u32 dst, char *src, int size)
+uae_u32 strncpyha (uae_u32 dst, const char *src, int size)
 {
     uae_u32 res = dst;
     while (size--) {
@@ -80,7 +79,7 @@ uae_u32 strncpyha (uae_u32 dst, char *src, int size)
     return res;
 }
 
-uae_u32 addstr (uae_u32 * dst, char *src)
+uae_u32 addstr (uae_u32 * dst, const char *src)
 {
     uae_u32 res = *dst;
     int len;
@@ -93,7 +92,7 @@ uae_u32 addstr (uae_u32 * dst, char *src)
     return res;
 }
 
-uae_u32 addmem (uae_u32 * dst, char *src, int len)
+uae_u32 addmem (uae_u32 * dst, const char *src, int len)
 {
     uae_u32 res = *dst;
 
@@ -107,25 +106,25 @@ uae_u32 addmem (uae_u32 * dst, char *src, int len)
 }
 
 /* Get current task */
-static uae_u32 gettask (void)
+static uae_u32 gettask (TrapContext *context)
 {
-    uae_u32 currtask, a1 = m68k_areg (regs, 1);
+    uae_u32 currtask, a1 = m68k_areg (&context->regs, 1);
 
-    m68k_areg (regs, 1) = 0;
-    currtask = CallLib (get_long (4), -0x126); /* FindTask */
+    m68k_areg (&context->regs, 1) = 0;
+    currtask = CallLib (context, get_long (4), -0x126); /* FindTask */
 
-    m68k_areg (regs, 1) = a1;
+    m68k_areg (&context->regs, 1) = a1;
 
     TRACE (("[%s] ", get_real_address (get_long (currtask + 10))));
     return currtask;
 }
 
 /* errno/herrno setting */
-void seterrno (SB, int sb_errno)
+void bsdsocklib_seterrno (SB, int sb_errno)
 {
     sb->sb_errno = sb_errno;
     if (sb->sb_errno >= 1001 && sb->sb_errno <= 1005)
-       setherrno(sb,sb->sb_errno-1000);
+       bsdsocklib_setherrno(sb,sb->sb_errno-1000);
     if (sb->errnoptr) {
        switch (sb->errnosize) {
         case 1:
@@ -140,7 +139,7 @@ void seterrno (SB, int sb_errno)
     }
 }
 
-void setherrno (SB, int sb_herrno)
+void bsdsocklib_setherrno (SB, int sb_herrno)
 {
     sb->sb_herrno = sb_herrno;
 
@@ -211,7 +210,7 @@ int getsd (SB, SOCKET_TYPE s)
                return i + 1;
                }
     /* descriptor table full. */
-    seterrno (sb, 24); /* EMFILE */
+    bsdsocklib_seterrno (sb, 24); /* EMFILE */
 
     return -1;
 }
@@ -220,7 +219,7 @@ SOCKET_TYPE getsock (SB, int sd)
 {
     if ((unsigned int) (sd - 1) >= (unsigned int) sb->dtablesize) {
        TRACE (("Invalid Socket Descriptor (%d)\n", sd));
-       seterrno (sb, 38); /* ENOTSOCK */
+       bsdsocklib_seterrno (sb, 38); /* ENOTSOCK */
 
        return -1;
     }
@@ -272,7 +271,7 @@ void addtosigqueue (SB, int events)
     INTREQ (0xA000);
 }
 
-static uae_u32 bsdsock_int_handler (void)
+static uae_u32 REGPARAM2 bsdsock_int_handler (TrapContext *context)
 {
     SB;
 
@@ -281,10 +280,10 @@ static uae_u32 bsdsock_int_handler (void)
 
        for (sb = sbsigqueue; sb; sb = sb->nextsig) {
            if (sb->dosignal == 1) {
-               struct regstruct sbved_regs = regs;
-               m68k_areg (regs, 1) = sb->ownertask;
-               m68k_dreg (regs, 0) = sb->sigstosend;
-               CallLib (get_long (4), -0x144); /* Signal() */
+               struct regstruct sbved_regs = context->regs;
+               m68k_areg (&context->regs, 1) = sb->ownertask;
+               m68k_dreg (&context->regs, 0) = sb->sigstosend;
+               CallLib (context, get_long (4), -0x144); /* Signal() */
 
                regs = sbved_regs;
 
@@ -299,56 +298,56 @@ static uae_u32 bsdsock_int_handler (void)
     return 0;
 }
 
-void waitsig (SB)
+void waitsig (TrapContext *context, SB)
 {
     long sigs;
-    m68k_dreg (regs, 0) = (((uae_u32) 1) << sb->signal) | sb->eintrsigs;
-    if ((sigs = CallLib (get_long (4), -0x13e)) & sb->eintrsigs) {
+    m68k_dreg (&context->regs, 0) = (((uae_u32) 1) << sb->signal) | sb->eintrsigs;
+    if ((sigs = CallLib (context, get_long (4), -0x13e)) & sb->eintrsigs) {
        sockabort (sb); 
-       seterrno (sb, 4); /* EINTR */
+       bsdsocklib_seterrno (sb, 4); /* EINTR */
 
        // Set signal
-       m68k_dreg (regs, 0) = sigs;
-       m68k_dreg (regs, 1) = sb->eintrsigs;
-       sigs = CallLib (get_long (4), -0x132); /* SetSignal() */
+       m68k_dreg (&context->regs, 0) = sigs;
+       m68k_dreg (&context->regs, 1) = sb->eintrsigs;
+       sigs = CallLib (context, get_long (4), -0x132); /* SetSignal() */
 
        sb->eintr = 1;
     } else
        sb->eintr = 0;
 }
 
-void cancelsig (SB)
+void cancelsig (TrapContext *context, SB)
 {
     locksigqueue ();
     if (sb->dosignal)
        sb->dosignal = 2;
     unlocksigqueue ();
 
-    m68k_dreg (regs, 0) = 0;
-    m68k_dreg (regs, 1) = ((uae_u32) 1) << sb->signal;
-    CallLib (get_long (4), -0x132); /* SetSignal() */
+    m68k_dreg (&context->regs, 0) = 0;
+    m68k_dreg (&context->regs, 1) = ((uae_u32) 1) << sb->signal;
+    CallLib (context, get_long (4), -0x132); /* SetSignal() */
 
 }
 
 /* Allocate and initialize per-task state structure */
-static struct socketbase *alloc_socketbase (void)
+static struct socketbase *alloc_socketbase (TrapContext *context)
 {
     SB;
     int i;
 
     if ((sb = calloc (sizeof (struct socketbase), 1)) != NULL) {
-       sb->ownertask = gettask ();
+       sb->ownertask = gettask (context);
 
-       m68k_dreg (regs, 0) = -1;
-       sb->signal = CallLib (get_long (4), -0x14A); /* AllocSignal */
+       m68k_dreg (&context->regs, 0) = -1;
+       sb->signal = CallLib (context, get_long (4), -0x14A); /* AllocSignal */
 
        if (sb->signal == -1) {
            write_log ("bsdsocket: ERROR: Couldn't allocate signal for task 0x%lx.\n", sb->ownertask);
            free (sb);
            return NULL;
        }
-       m68k_dreg (regs, 0) = SCRATCHBUFSIZE;
-       m68k_dreg (regs, 1) = 0;
+       m68k_dreg (&context->regs, 0) = SCRATCHBUFSIZE;
+       m68k_dreg (&context->regs, 1) = 0;
 
        sb->dtablesize = DEFAULT_DTABLE_SIZE;
        /* @@@ check malloc() result */
@@ -360,52 +359,52 @@ static struct socketbase *alloc_socketbase (void)
 
        sb->eintrsigs = 0x1000; /* SIGBREAKF_CTRL_C */
 
-       if (!host_sbinit (sb)) {
+       if (!host_sbinit (context, sb)) {
            /* @@@ free everything   */
        }
+
+       locksigqueue();
+
        if (socketbases)
            sb->next = socketbases;
        socketbases = sb;
 
+       unlocksigqueue();
+
        return sb;
     }
     return NULL;
 }
 
-struct socketbase *get_socketbase (void)
+STATIC_INLINE struct socketbase *get_socketbase (TrapContext *context)
 {
-    int i;
-    uae_u32 p[sizeof(void*) / 4];
-
-    for (i = 0; i < (sizeof p) / 4; i++)
-       p[i] = get_long (m68k_areg (regs, 6) + offsetof (struct UAEBSDBase, sb) + i * 4);
-    return *((struct socketbase**)p);
+    return get_pointer (m68k_areg (&context->regs, 6) + offsetof (struct UAEBSDBase, sb));
 }
 
-static void free_socketbase (void)
+static void free_socketbase (TrapContext *context)
 {
     struct socketbase *sb, *nsb;
 
-    if ((sb = get_socketbase ()) != NULL) {
-       m68k_dreg (regs, 0) = sb->signal;
-       CallLib (get_long (4), -0x150); /* FreeSignal */
+    if ((sb = get_socketbase (context)) != NULL) {
+       m68k_dreg (&context->regs, 0) = sb->signal;
+       CallLib (context, get_long (4), -0x150); /* FreeSignal */
 
        if (sb->hostent) {
-           m68k_areg (regs, 1) = sb->hostent;
-           m68k_dreg (regs, 0) = sb->hostentsize;
-           CallLib (get_long (4), -0xD2); /* FreeMem */
+           m68k_areg (&context->regs, 1) = sb->hostent;
+           m68k_dreg (&context->regs, 0) = sb->hostentsize;
+           CallLib (context, get_long (4), -0xD2); /* FreeMem */
 
        }
        if (sb->protoent) {
-           m68k_areg (regs, 1) = sb->protoent;
-           m68k_dreg (regs, 0) = sb->protoentsize;
-           CallLib (get_long (4), -0xD2); /* FreeMem */
+           m68k_areg (&context->regs, 1) = sb->protoent;
+           m68k_dreg (&context->regs, 0) = sb->protoentsize;
+           CallLib (context, get_long (4), -0xD2); /* FreeMem */
 
        }
        if (sb->servent) {
-           m68k_areg (regs, 1) = sb->servent;
-           m68k_dreg (regs, 0) = sb->serventsize;
-           CallLib (get_long (4), -0xD2); /* FreeMem */
+           m68k_areg (&context->regs, 1) = sb->servent;
+           m68k_dreg (&context->regs, 0) = sb->serventsize;
+           CallLib (context, get_long (4), -0xD2); /* FreeMem */
 
        }
        host_sbcleanup (sb);
@@ -443,7 +442,7 @@ static void free_socketbase (void)
     }
 }
 
-static uae_u32 bsdsocklib_Expunge (void)
+static uae_u32 REGPARAM2 bsdsocklib_Expunge (TrapContext *context)
 {
     TRACE (("Expunge() -> [ignored]\n"));
     return 0;
@@ -451,56 +450,47 @@ static uae_u32 bsdsocklib_Expunge (void)
 
 static uae_u32 functable, datatable, inittable;
 
-#define SOCKETBASE get_socketbase()
-
-static uae_u32 bsdsocklib_Open (void)
+static uae_u32 REGPARAM2 bsdsocklib_Open (TrapContext *context)
 {
     uae_u32 result = 0;
-    int opencount, i;
+    int opencount;
     SB;
-    uae_u32 p[sizeof (void*) / 4];
-
-    locksigqueue ();
 
     TRACE (("OpenLibrary() -> "));
 
-    if ((sb = alloc_socketbase ()) != NULL) {
+    if ((sb = alloc_socketbase (context)) != NULL) {
        put_word (SockLibBase + 32, opencount = get_word (SockLibBase + 32) + 1);
 
-       m68k_areg (regs, 0) = functable;
-       m68k_areg (regs, 1) = datatable;
-       m68k_areg (regs, 2) = 0;
-       m68k_dreg (regs, 0) = sizeof (struct UAEBSDBase);
-       m68k_dreg (regs, 1) = 0;
-       result = CallLib (get_long (4), -0x54); /* MakeLibrary */
+       m68k_areg (&context->regs, 0) = functable;
+       m68k_areg (&context->regs, 1) = datatable;
+       m68k_areg (&context->regs, 2) = 0;
+       m68k_dreg (&context->regs, 0) = sizeof (struct UAEBSDBase);
+       m68k_dreg (&context->regs, 1) = 0;
+       result = CallLib (context, get_long (4), -0x54); /* MakeLibrary */
 
-       *((struct socketbase**)p) = sb;
-       for (i = 0; i < (sizeof p) / 4; i++)
-           put_long(result + offsetof (struct UAEBSDBase, sb) + i * 4, p[i]);
+       put_pointer (result + offsetof (struct UAEBSDBase, sb), sb);
 
        TRACE (("%0lx [%d]\n", result, opencount));
     } else
        TRACE (("failed (out of memory)\n"));
 
-    unlocksigqueue ();
-
     return result;
 }
 
-static uae_u32 bsdsocklib_Close (void)
+static uae_u32 REGPARAM2 bsdsocklib_Close (TrapContext *context)
 {
     int opencount;
 
-    uae_u32 base = m68k_areg (regs, 6);
+    uae_u32 base = m68k_areg (&context->regs, 6);
     uae_u32 negsize = get_word (base + 16);
 
-    free_socketbase ();
+    free_socketbase (context);
 
     put_word (SockLibBase + 32, opencount = get_word (SockLibBase + 32) - 1);
 
-    m68k_areg (regs, 1) = base - negsize;
-    m68k_dreg (regs, 0) = negsize + get_word (base + 18);
-    CallLib (get_long (4), -0xD2); /* FreeMem */
+    m68k_areg (&context->regs, 1) = base - negsize;
+    m68k_dreg (&context->regs, 0) = negsize + get_word (base + 18);
+    CallLib (context, get_long (4), -0xD2); /* FreeMem */
 
     TRACE (("CloseLibrary() -> [%d]\n", opencount));
 
@@ -508,150 +498,187 @@ static uae_u32 bsdsocklib_Close (void)
 }
 
 /* socket(domain, type, protocol)(d0/d1/d2) */
-static uae_u32 bsdsocklib_socket (void)
+static uae_u32 REGPARAM2 bsdsocklib_socket (TrapContext *context)
 {
-    return host_socket (SOCKETBASE, m68k_dreg (regs, 0), m68k_dreg (regs, 1),
-       m68k_dreg (regs, 2));
+    struct socketbase *sb = get_socketbase (context);
+    return host_socket (sb, m68k_dreg (&context->regs, 0), m68k_dreg (&context->regs, 1),
+       m68k_dreg (&context->regs, 2));
 }
 
 /* bind(s, name, namelen)(d0/a0/d1) */
-static uae_u32 bsdsocklib_bind (void)
+static uae_u32 REGPARAM2 bsdsocklib_bind (TrapContext *context)
 {
-    return host_bind (SOCKETBASE, m68k_dreg (regs, 0), m68k_areg (regs, 0),
-       m68k_dreg (regs, 1));
+    struct socketbase *sb = get_socketbase (context);
+    return host_bind (sb, m68k_dreg (&context->regs, 0), m68k_areg (&context->regs, 0),
+                     m68k_dreg (&context->regs, 1));
 }
 
 /* listen(s, backlog)(d0/d1) */
-static uae_u32 bsdsocklib_listen (void)
+static uae_u32 REGPARAM2 bsdsocklib_listen (TrapContext *context)
 {
-    return host_listen (SOCKETBASE, m68k_dreg (regs, 0), m68k_dreg (regs, 1));
+    struct socketbase *sb = get_socketbase (context);
+    return host_listen (sb, m68k_dreg (&context->regs, 0), m68k_dreg (&context->regs, 1));
 }
 
 /* accept(s, addr, addrlen)(d0/a0/a1) */
-static uae_u32 bsdsocklib_accept (void)
+static uae_u32 REGPARAM2 bsdsocklib_accept (TrapContext *context)
 {
-    SB = get_socketbase ();
-    host_accept (sb, m68k_dreg (regs, 0), m68k_areg (regs, 0), m68k_areg (regs, 1));
+    struct socketbase *sb = get_socketbase (context);
+    host_accept (context, sb, m68k_dreg (&context->regs, 0), m68k_areg (&context->regs, 0), m68k_areg (&context->regs, 1));
     return sb->resultval;
 }
 
 /* connect(s, name, namelen)(d0/a0/d1) */
-static uae_u32 bsdsocklib_connect (void)
+static uae_u32 REGPARAM2 bsdsocklib_connect (TrapContext *context)
 {
-    SB = get_socketbase ();
-    host_connect (sb, m68k_dreg (regs, 0), m68k_areg (regs, 0), m68k_dreg (regs, 1));
+    struct socketbase *sb = get_socketbase (context);
+    host_connect (context, sb, m68k_dreg (&context->regs, 0), m68k_areg (&context->regs, 0), m68k_dreg (&context->regs, 1));
     return sb->sb_errno ? -1 : 0;
 }
 
 /* sendto(s, msg, len, flags, to, tolen)(d0/a0/d1/d2/a1/d3) */
-static uae_u32 bsdsocklib_sendto (void)
+static uae_u32 REGPARAM2 bsdsocklib_sendto (TrapContext *context)
 {
-    SB = get_socketbase ();
-    host_sendto (sb, m68k_dreg (regs, 0), m68k_areg (regs, 0), m68k_dreg (regs, 1),
-       m68k_dreg (regs, 2), m68k_areg (regs, 1), m68k_dreg (regs, 3));
+    struct socketbase *sb = get_socketbase (context);
+    host_sendto (context, sb, m68k_dreg (&context->regs, 0), m68k_areg (&context->regs, 0), m68k_dreg (&context->regs, 1),
+                m68k_dreg (&context->regs, 2), m68k_areg (&context->regs, 1), m68k_dreg (&context->regs, 3));
     return sb->resultval;
 }
 
 /* send(s, msg, len, flags)(d0/a0/d1/d2) */
-static uae_u32 bsdsocklib_send (void)
+static uae_u32 REGPARAM2 bsdsocklib_send (TrapContext *context)
 {
-    SB = get_socketbase ();
-    host_sendto (sb, m68k_dreg (regs, 0), m68k_areg (regs, 0), m68k_dreg (regs, 1),
-       m68k_dreg (regs, 2), 0, 0);
+    struct socketbase *sb = get_socketbase (context);
+    host_sendto (context, sb, m68k_dreg (&context->regs, 0), m68k_areg (&context->regs, 0), m68k_dreg (&context->regs, 1),
+                m68k_dreg (&context->regs, 2), 0, 0);
     return sb->resultval;
 }
 
 /* recvfrom(s, buf, len, flags, from, fromlen)(d0/a0/d1/d2/a1/a2) */
-static uae_u32 bsdsocklib_recvfrom (void)
+static uae_u32 REGPARAM2 bsdsocklib_recvfrom (TrapContext *context)
 {
-    SB = get_socketbase ();
-    host_recvfrom (sb, m68k_dreg (regs, 0), m68k_areg (regs, 0), m68k_dreg (regs, 1),
-       m68k_dreg (regs, 2), m68k_areg (regs, 1), m68k_areg (regs, 2));
+    struct socketbase *sb = get_socketbase (context);
+    host_recvfrom (context, sb, m68k_dreg (&context->regs, 0), m68k_areg (&context->regs, 0), m68k_dreg (&context->regs, 1),
+                  m68k_dreg (&context->regs, 2), m68k_areg (&context->regs, 1), m68k_areg (&context->regs, 2));
     return sb->resultval;
 }
 
 /* recv(s, buf, len, flags)(d0/a0/d1/d2) */
-static uae_u32 bsdsocklib_recv (void)
+static uae_u32 REGPARAM2 bsdsocklib_recv (TrapContext *context)
 {
-    SB = get_socketbase ();
-    host_recvfrom (sb, m68k_dreg (regs, 0), m68k_areg (regs, 0), m68k_dreg (regs, 1),
-       m68k_dreg (regs, 2), 0, 0);
+    struct socketbase *sb = get_socketbase (context);
+    host_recvfrom (context, sb, m68k_dreg (&context->regs, 0), m68k_areg (&context->regs, 0), m68k_dreg (&context->regs, 1),
+                  m68k_dreg (&context->regs, 2), 0, 0);
     return sb->resultval;
 }
 
 /* shutdown(s, how)(d0/d1) */
-static uae_u32 bsdsocklib_shutdown (void)
+static uae_u32 REGPARAM2 bsdsocklib_shutdown (TrapContext *context)
 {
-    return host_shutdown (SOCKETBASE, m68k_dreg (regs, 0), m68k_dreg (regs, 1));
+    struct socketbase *sb = get_socketbase (context);
+    return host_shutdown (sb, m68k_dreg (&context->regs, 0), m68k_dreg (&context->regs, 1));
 }
 
 /* setsockopt(s, level, optname, optval, optlen)(d0/d1/d2/a0/d3) */
-static uae_u32 bsdsocklib_setsockopt (void)
+static uae_u32 REGPARAM2 bsdsocklib_setsockopt (TrapContext *context)
 {
-    SB = get_socketbase ();
-    host_setsockopt (sb, m68k_dreg (regs, 0), m68k_dreg (regs, 1), m68k_dreg (regs, 2),
-       m68k_areg (regs, 0), m68k_dreg (regs, 3));
+    struct socketbase *sb = get_socketbase (context);
+    host_setsockopt (sb, m68k_dreg (&context->regs, 0), m68k_dreg (&context->regs, 1), m68k_dreg (&context->regs, 2),
+                    m68k_areg (&context->regs, 0), m68k_dreg (&context->regs, 3));
     return sb->resultval;
 }
 
 /* getsockopt(s, level, optname, optval, optlen)(d0/d1/d2/a0/a1) */
-static uae_u32 bsdsocklib_getsockopt (void)
+static uae_u32 REGPARAM2 bsdsocklib_getsockopt (TrapContext *context)
 {
-    return host_getsockopt (SOCKETBASE, m68k_dreg (regs, 0), m68k_dreg (regs, 1), m68k_dreg (regs, 2),
-       m68k_areg (regs, 0), m68k_areg (regs, 1));
+    struct socketbase *sb = get_socketbase (context);
+    return host_getsockopt (sb, m68k_dreg (&context->regs, 0), m68k_dreg (&context->regs, 1), m68k_dreg (&context->regs, 2),
+                           m68k_areg (&context->regs, 0), m68k_areg (&context->regs, 1));
 }
 
 /* getsockname(s, hostname, namelen)(d0/a0/a1) */
-static uae_u32 bsdsocklib_getsockname (void)
+static uae_u32 REGPARAM2 bsdsocklib_getsockname (TrapContext *context)
 {
-    return host_getsockname (SOCKETBASE, m68k_dreg (regs, 0), m68k_areg (regs, 0), m68k_areg (regs, 1));
+    struct socketbase *sb = get_socketbase (context);
+    return host_getsockname (sb, m68k_dreg (&context->regs, 0), m68k_areg (&context->regs, 0), m68k_areg (&context->regs, 1));
 }
 
 /* getpeername(s, hostname, namelen)(d0/a0/a1) */
-static uae_u32 bsdsocklib_getpeername (void)
+static uae_u32 REGPARAM2 bsdsocklib_getpeername (TrapContext *context)
 {
-    return host_getpeername (SOCKETBASE, m68k_dreg (regs, 0), m68k_areg (regs, 0), m68k_areg (regs, 1));
+    struct socketbase *sb = get_socketbase (context);
+    return host_getpeername (sb, m68k_dreg (&context->regs, 0), m68k_areg (&context->regs, 0), m68k_areg (&context->regs, 1));
 }
 
 /* *------ generic system calls related to sockets */
 /* IoctlSocket(d, request, argp)(d0/d1/a0) */
-static uae_u32 bsdsocklib_IoctlSocket (void)
+static uae_u32 REGPARAM2 bsdsocklib_IoctlSocket (TrapContext *context)
 {
-    return host_IoctlSocket (SOCKETBASE, m68k_dreg (regs, 0), m68k_dreg (regs, 1), m68k_areg (regs, 0));
+    struct socketbase *sb = get_socketbase (context);
+    return host_IoctlSocket (context, sb, m68k_dreg (&context->regs, 0), m68k_dreg (&context->regs, 1), m68k_areg (&context->regs, 0));
 }
 
 /* *------ AmiTCP/IP specific stuff */
 /* CloseSocket(d)(d0) */
-static uae_u32 bsdsocklib_CloseSocket (void)
+static uae_u32 REGPARAM2 bsdsocklib_CloseSocket (TrapContext *context)
 {
-    return host_CloseSocket (SOCKETBASE, m68k_dreg (regs, 0));
+    struct socketbase *sb = get_socketbase (context);
+    return host_CloseSocket (context, sb, m68k_dreg (&context->regs, 0));
 }
 
 /* WaitSelect(nfds, readfds, writefds, execptfds, timeout, maskp)(d0/a0/a1/a2/a3/d1) */
-static uae_u32 bsdsocklib_WaitSelect (void)
+static uae_u32 REGPARAM2 bsdsocklib_WaitSelect (TrapContext *context)
 {
-    SB = get_socketbase ();
-    host_WaitSelect (sb, m68k_dreg (regs, 0), m68k_areg (regs, 0), m68k_areg (regs, 1),
-       m68k_areg (regs, 2), m68k_areg (regs, 3), m68k_dreg (regs, 1));
+    struct socketbase *sb = get_socketbase (context);
+    host_WaitSelect (context, sb, m68k_dreg (&context->regs, 0), m68k_areg (&context->regs, 0), m68k_areg (&context->regs, 1),
+                    m68k_areg (&context->regs, 2), m68k_areg (&context->regs, 3), m68k_dreg (&context->regs, 1));
     return sb->resultval;
 }
 
 /* SetSocketSignals(SIGINTR, SIGIO, SIGURG)(d0/d1/d2) */
-static uae_u32 bsdsocklib_SetSocketSignals (void)
+static uae_u32 REGPARAM2 bsdsocklib_SetSocketSignals (TrapContext *context)
 {
-    SB = get_socketbase ();
+    struct socketbase *sb = get_socketbase (context);
 
-    TRACE (("SetSocketSignals(0x%08lx,0x%08lx,0x%08lx) -> ", m68k_dreg (regs, 0), m68k_dreg (regs, 1), m68k_dreg (regs, 2)));
-    sb->eintrsigs = m68k_dreg (regs, 0);
-    sb->eventsigs = m68k_dreg (regs, 1);
+    TRACE (("SetSocketSignals(0x%08lx,0x%08lx,0x%08lx) -> ", m68k_dreg (&context->regs, 0), m68k_dreg (&context->regs, 1), m68k_dreg (&context->regs, 2)));
+    sb->eintrsigs = m68k_dreg (&context->regs, 0);
+    sb->eventsigs = m68k_dreg (&context->regs, 1);
 
     return 0;
 }
 
 /* SetDTableSize(size)(d0) */
-static uae_u32 bsdsocklib_SetDTableSize (void)
+static uae_u32 bsdsocklib_SetDTableSize (SB, int newSize)
 {
-    write_log ("bsdsocket: UNSUPPORTED: SetDTableSize()\n");
+    int *newdtable;
+    int *newftable;
+    int i;
+
+    if (newSize < sb->dtablesize) {
+       /* I don't support lowering the size */
+       return 0;
+    }
+
+    newdtable = (int *)malloc(newSize * sizeof(*sb->dtable));
+    newftable = (int *)malloc(newSize * sizeof(*sb->ftable));
+
+    if (newdtable == NULL || newftable == NULL) {
+       sb->resultval = -1;
+       bsdsocklib_seterrno(sb, ENOMEM);
+       return -1;
+    }
+
+    memcpy(newdtable, sb->dtable, sb->dtablesize * sizeof(*sb->dtable));
+    memcpy(newftable, sb->ftable, sb->dtablesize * sizeof(*sb->ftable));
+    for (i = sb->dtablesize + 1; i < newSize; i++)
+       newdtable[i] = -1;
+
+    sb->dtablesize = newSize;
+    free(sb->dtable);
+    free(sb->ftable);
+    sb->dtable = newdtable;
+    sb->ftable = newftable;
+    sb->resultval = 0;
     return 0;
 }
 
@@ -667,17 +694,17 @@ static int sockpoolindex (long id)
 }
 
 /* ObtainSocket(id, domain, type, protocol)(d0/d1/d2/d3) */
-static uae_u32 bsdsocklib_ObtainSocket (void)
+static uae_u32 REGPARAM2 bsdsocklib_ObtainSocket (TrapContext *context)
 {
-    SB = SOCKETBASE;
+    struct socketbase *sb = get_socketbase (context);
     int sd;
     long id;
     SOCKET_TYPE s;
     int i;
 
-    id = m68k_dreg (regs, 0);
+    id = m68k_dreg (&context->regs, 0);
 
-    TRACE (("ObtainSocket(%d,%d,%d,%d) -> ", id, m68k_dreg (regs, 1), m68k_dreg (regs, 2), m68k_dreg (regs, 3)));
+    TRACE (("ObtainSocket(%d,%d,%d,%d) -> ", id, m68k_dreg (&context->regs, 1), m68k_dreg (&context->regs, 2), m68k_dreg (&context->regs, 3)));
 
     i = sockpoolindex (id);
 
@@ -689,27 +716,29 @@ static uae_u32 bsdsocklib_ObtainSocket (void)
 
     sd = getsd (sb, s);
 
-    sb->ftable[sd - 1] = sockpoolflags[i];
-
     TRACE (("%d\n", sd));
 
-    sockpoolids[i] = UNIQUE_ID;
+    if (sd != -1) {
+       sb->ftable[sd - 1] = sockpoolflags[i];
+        sockpoolids[i] = UNIQUE_ID;
+        return sd - 1;
+    }
 
-    return sd-1;
+    return -1;
 }
 
 /* ReleaseSocket(fd, id)(d0/d1) */
-static uae_u32 bsdsocklib_ReleaseSocket (void)
+static uae_u32 REGPARAM2 bsdsocklib_ReleaseSocket (TrapContext *context)
 {
-    SB = SOCKETBASE;
+    struct socketbase *sb = get_socketbase (context);
     int sd;
     long id;
     SOCKET_TYPE s;
     int i;
     uae_u32 flags;
 
-    sd = m68k_dreg (regs, 0);
-    id = m68k_dreg (regs, 1);
+    sd = m68k_dreg (&context->regs, 0);
+    id = m68k_dreg (&context->regs, 1);
 
     sd++;
     TRACE (("ReleaseSocket(%d,%d) -> ", sd, id));
@@ -762,25 +791,25 @@ static uae_u32 bsdsocklib_ReleaseSocket (void)
 }
 
 /* ReleaseCopyOfSocket(fd, id)(d0/d1) */
-static uae_u32 bsdsocklib_ReleaseCopyOfSocket (void)
+static uae_u32 REGPARAM2 bsdsocklib_ReleaseCopyOfSocket (TrapContext *context)
 {
     write_log ("bsdsocket: UNSUPPORTED: ReleaseCopyOfSocket()\n");
     return 0;
 }
 
 /* Errno()() */
-static uae_u32 bsdsocklib_Errno (void)
+static uae_u32 REGPARAM2 bsdsocklib_Errno (TrapContext *context)
 {
-    SB = get_socketbase ();
+    struct socketbase *sb = get_socketbase (context);
     TRACE (("Errno() -> %d\n", sb->sb_errno));
     return sb->sb_errno;
 }
 
 /* SetErrnoPtr(errno_p, size)(a0/d0) */
-static uae_u32 bsdsocklib_SetErrnoPtr (void)
+static uae_u32 REGPARAM2 bsdsocklib_SetErrnoPtr (TrapContext *context)
 {
-    SB = get_socketbase ();
-    uae_u32 errnoptr = m68k_areg (regs, 0), size = m68k_dreg (regs, 0);
+    struct socketbase *sb = get_socketbase (context);
+    uae_u32 errnoptr = m68k_areg (&context->regs, 0), size = m68k_dreg (&context->regs, 0);
 
     TRACE (("SetErrnoPtr(0x%lx,%d) -> ", errnoptr, size));
 
@@ -790,116 +819,118 @@ static uae_u32 bsdsocklib_SetErrnoPtr (void)
        TRACE (("OK\n"));
        return 0;
     }
-    seterrno (sb, 22); /* EINVAL */
+    bsdsocklib_seterrno (sb, 22); /* EINVAL */
 
     return -1;
 }
 
 /* *------ inet library calls related to inet address manipulation */
 /* Inet_NtoA(in)(d0) */
-static uae_u32 bsdsocklib_Inet_NtoA (void)
+static uae_u32 REGPARAM2 bsdsocklib_Inet_NtoA (TrapContext *context)
 {
-    return host_Inet_NtoA (SOCKETBASE, m68k_dreg (regs, 0));
+    struct socketbase *sb = get_socketbase (context);
+    return host_Inet_NtoA (context, sb, m68k_dreg (&context->regs, 0));
 }
 
 /* inet_addr(cp)(a0) */
-static uae_u32 bsdsocklib_inet_addr (void)
+static uae_u32 REGPARAM2 bsdsocklib_inet_addr (TrapContext *context)
 {
-    return host_inet_addr (m68k_areg (regs, 0));
+    return host_inet_addr (m68k_areg (&context->regs, 0));
 }
 
 /* Inet_LnaOf(in)(d0) */
-static uae_u32 bsdsocklib_Inet_LnaOf (void)
+static uae_u32 REGPARAM2 bsdsocklib_Inet_LnaOf (TrapContext *context)
 {
     write_log ("bsdsocket: UNSUPPORTED: Inet_LnaOf()\n");
     return 0;
 }
 
 /* Inet_NetOf(in)(d0) */
-static uae_u32 bsdsocklib_Inet_NetOf (void)
+static uae_u32 REGPARAM2 bsdsocklib_Inet_NetOf (TrapContext *context)
 {
     write_log ("bsdsocket: UNSUPPORTED: Inet_NetOf()\n");
     return 0;
 }
 
 /* Inet_MakeAddr(net, host)(d0/d1) */
-static uae_u32 bsdsocklib_Inet_MakeAddr (void)
+static uae_u32 REGPARAM2 bsdsocklib_Inet_MakeAddr (TrapContext *context)
 {
     write_log ("bsdsocket: UNSUPPORTED: Inet_MakeAddr()\n");
     return 0;
 }
 
 /* inet_network(cp)(a0) */
-static uae_u32 bsdsocklib_inet_network (void)
+static uae_u32 REGPARAM2 bsdsocklib_inet_network (TrapContext *context)
 {
-    return host_inet_addr (m68k_areg (regs, 0));
+    return host_inet_addr (m68k_areg (&context->regs, 0));
 }
 
 /* *------ gethostbyname etc */
 /* gethostbyname(name)(a0) */
-static uae_u32 bsdsocklib_gethostbyname (void)
+static uae_u32 REGPARAM2 bsdsocklib_gethostbyname (TrapContext *context)
 {
-    SB = get_socketbase ();
-    host_gethostbynameaddr (sb, m68k_areg (regs, 0), 0, -1);
-    return sb->sb_errno ? 0 : sb->hostent;
+    struct socketbase *sb = get_socketbase (context);
+    host_gethostbynameaddr (context, sb, m68k_areg (&context->regs, 0), 0, -1);
+    return sb->sb_herrno ? 0 : sb->hostent;
 }
 
 /* gethostbyaddr(addr, len, type)(a0/d0/d1) */
-static uae_u32 bsdsocklib_gethostbyaddr (void)
+static uae_u32 REGPARAM2 bsdsocklib_gethostbyaddr (TrapContext *context)
 {
-    SB = get_socketbase ();
-    host_gethostbynameaddr (sb, m68k_areg (regs, 0), m68k_dreg (regs, 0), m68k_dreg (regs, 1));
-    return sb->sb_errno ? 0 : sb->hostent;
+    struct socketbase *sb = get_socketbase (context);
+    host_gethostbynameaddr (context, sb, m68k_areg (&context->regs, 0), m68k_dreg (&context->regs, 0), m68k_dreg (&context->regs, 1));
+    return sb->sb_herrno ? 0 : sb->hostent;
 }
 
 /* getnetbyname(name)(a0) */
-static uae_u32 bsdsocklib_getnetbyname (void)
+static uae_u32 REGPARAM2 bsdsocklib_getnetbyname (TrapContext *context)
 {
     write_log ("bsdsocket: UNSUPPORTED: getnetbyname()\n");
     return 0;
 }
 
 /* getnetbyaddr(net, type)(d0/d1) */
-static uae_u32 bsdsocklib_getnetbyaddr (void)
+static uae_u32 REGPARAM2 bsdsocklib_getnetbyaddr (TrapContext *context)
 {
     write_log ("bsdsocket: UNSUPPORTED: getnetbyaddr()\n");
     return 0;
 }
 
 /* getservbyname(name, proto)(a0/a1) */
-static uae_u32 bsdsocklib_getservbyname (void)
+static uae_u32 REGPARAM2 bsdsocklib_getservbyname (TrapContext *context)
 {
-    SB = get_socketbase ();
-    host_getservbynameport (sb, m68k_areg (regs, 0), m68k_areg (regs, 1), 0);
+    struct socketbase *sb = get_socketbase (context);
+    host_getservbynameport (context, sb, m68k_areg (&context->regs, 0), m68k_areg (&context->regs, 1), 0);
     return sb->sb_errno ? 0 : sb->servent;
 }
 
 /* getservbyport(port, proto)(d0/a0) */
-static uae_u32 bsdsocklib_getservbyport (void)
+static uae_u32 REGPARAM2 bsdsocklib_getservbyport (TrapContext *context)
 {
-    SB = get_socketbase ();
-    host_getservbynameport (sb, m68k_dreg (regs, 0), m68k_areg (regs, 0), 1);
+    struct socketbase *sb = get_socketbase (context);
+    host_getservbynameport (context, sb, m68k_dreg (&context->regs, 0), m68k_areg (&context->regs, 0), 1);
     return sb->sb_errno ? 0 : sb->servent;
 }
 
 /* getprotobyname(name)(a0) */
-static uae_u32 bsdsocklib_getprotobyname (void)
+static uae_u32 REGPARAM2 bsdsocklib_getprotobyname (TrapContext *context)
 {
-    SB = get_socketbase ();
-    host_getprotobyname (sb, m68k_areg (regs, 0));
+    struct socketbase *sb = get_socketbase (context);
+    host_getprotobyname (context, sb, m68k_areg (&context->regs, 0));
     return sb->sb_errno ? 0 : sb->protoent;
 }
 
-/* getprotobynumber(proto)(d0) */
-static uae_u32 bsdsocklib_getprotobynumber (void)
+/* getprotobynumber(proto)(d0)  */
+static uae_u32 REGPARAM2 bsdsocklib_getprotobynumber (TrapContext *context)
 {
-    write_log ("bsdsocket: UNSUPPORTED: getprotobynumber()\n");
-    return 0;
+    struct socketbase *sb = get_socketbase (context);
+    host_getprotobynumber (context, sb, m68k_dreg (&context->regs, 0));
+    return sb->sb_errno ? 0 : sb->protoent;
 }
 
 /* *------ syslog functions */
 /* Syslog(level, format, ap)(d0/a0/a1) */
-static uae_u32 bsdsocklib_vsyslog (void)
+static uae_u32 REGPARAM2 bsdsocklib_vsyslog (TrapContext *context)
 {
     write_log ("bsdsocket: UNSUPPORTED: vsyslog()\n");
     return 0;
@@ -907,35 +938,36 @@ static uae_u32 bsdsocklib_vsyslog (void)
 
 /* *------ AmiTCP/IP 1.1 extensions */
 /* Dup2Socket(fd1, fd2)(d0/d1) */
-static uae_u32 bsdsocklib_Dup2Socket (void)
+static uae_u32 REGPARAM2 bsdsocklib_Dup2Socket (TrapContext *context)
 {
-    return host_dup2socket (SOCKETBASE, m68k_dreg (regs, 0), m68k_dreg (regs, 1));
+    struct socketbase *sb = get_socketbase (context);
+    return host_dup2socket (sb, m68k_dreg (&context->regs, 0), m68k_dreg (&context->regs, 1));
 }
 
-static uae_u32 bsdsocklib_sendmsg (void)
+static uae_u32 REGPARAM2 bsdsocklib_sendmsg (TrapContext *context)
 {
     write_log ("bsdsocket: UNSUPPORTED: sendmsg()\n");
     return 0;
 }
 
-static uae_u32 bsdsocklib_recvmsg (void)
+static uae_u32 REGPARAM2 bsdsocklib_recvmsg (TrapContext *context)
 {
     write_log ("bsdsocket: UNSUPPORTED: recvmsg()\n");
     return 0;
 }
 
-static uae_u32 bsdsocklib_gethostname (void)
+static uae_u32 REGPARAM2 bsdsocklib_gethostname (TrapContext *context)
 {
-    return host_gethostname (m68k_areg (regs, 0), m68k_dreg (regs, 0));
+    return host_gethostname (m68k_areg (&context->regs, 0), m68k_dreg (&context->regs, 0));
 }
 
-static uae_u32 bsdsocklib_gethostid (void)
+static uae_u32 REGPARAM2 bsdsocklib_gethostid (TrapContext *context)
 {
-    write_log ("bsdsocket: WARNING: Process '%s' calls deprecated function gethostid() - returning 127.0.0.1\n", get_real_address (get_long (gettask () + 10)));
+    write_log ("bsdsocket: WARNING: Process '%s' calls deprecated function gethostid() - returning 127.0.0.1\n", get_real_address (get_long (gettask (context) + 10)));
     return 0x7f000001;
 }
 
-char *errortexts[] =
+const char *errortexts[] =
 {"No error", "Operation not permitted", "No such file or directory",
  "No such process", "Interrupted system call", "Input/output error", "Device not configured",
  "Argument list too long", "Exec format error", "Bad file descriptor", "No child processes",
@@ -965,7 +997,7 @@ uae_u32 errnotextptrs[sizeof (errortexts) / sizeof (*errortexts)];
 uae_u32 number_sys_error = sizeof (errortexts) / sizeof (*errortexts);
 
 
-char *herrortexts[] =
+const char *herrortexts[] =
  {"No error", "Unknown host", "Host name lookup failure", "Unknown server error",
  "No address associated with name"};
 
@@ -1040,10 +1072,10 @@ static void tagcopy (uae_u32 currtag, uae_u32 currval, uae_u32 tagptr, uae_u32 *
     }
 }
 
-static uae_u32 bsdsocklib_SocketBaseTagList (void)
+static uae_u32 REGPARAM2 bsdsocklib_SocketBaseTagList (TrapContext *context)
 {
-    SB = SOCKETBASE;
-    uae_u32 tagptr = m68k_areg (regs, 0);
+    struct socketbase *sb = get_socketbase (context);
+    uae_u32 tagptr = m68k_areg (&context->regs, 0);
     uae_u32 tagsprocessed = 1;
     uae_u32 currtag;
     uae_u32 currval;
@@ -1099,6 +1131,14 @@ static uae_u32 bsdsocklib_SocketBaseTagList (void)
                    TRACE (("SBTC_HERRNO),%d", currval));
                    tagcopy (currtag, currval, tagptr, &sb->sb_herrno);
                    break;
+                case SBTC_DTABLESIZE:
+                   TRACE (("SBTC_DTABLESIZE),0x%lx", currval));
+                   if (currtag & 1) {
+                       bsdsocklib_SetDTableSize(sb, currval);
+                   } else {
+                       put_long(tagptr + 4, sb->dtablesize);
+                   }
+                   break;
                 case SBTC_ERRNOSTRPTR:
                    if (currtag & 1) {
                        TRACE (("ERRNOSTRPTR),invalid"));
@@ -1185,12 +1225,13 @@ static uae_u32 bsdsocklib_SocketBaseTagList (void)
     return tagsprocessed;
 }
 
-static uae_u32 bsdsocklib_GetSocketEvents (void)
+static uae_u32 REGPARAM2 bsdsocklib_GetSocketEvents (TrapContext *context)
 {
-    SB = SOCKETBASE;
+#ifdef _WIN32
+    struct socketbase *sb = get_socketbase (context);
     int i;
     int flags;
-    uae_u32 ptr = m68k_areg (regs, 0);
+    uae_u32 ptr = m68k_areg (&context->regs, 0);
 
     TRACE (("GetSocketEvents(0x%x) -> ", ptr));
 
@@ -1202,30 +1243,28 @@ static uae_u32 bsdsocklib_GetSocketEvents (void)
            flags = sb->ftable[sb->eventindex] & SET_ALL;
            if (flags) {
                sb->ftable[sb->eventindex] &= ~SET_ALL;
-               put_long (m68k_areg (regs, 0), flags >> 8);
+               put_long (m68k_areg (&context->regs, 0), flags >> 8);
                TRACE (("%d (0x%x)\n", sb->eventindex + 1, flags >> 8));
                return sb->eventindex; // xxx
            }
        }
     }
-
+#endif
     TRACE (("-1\n"));
     return -1;
 }
 
-static uae_u32 bsdsocklib_getdtablesize (void)
+static uae_u32 REGPARAM2 bsdsocklib_getdtablesize (TrapContext *context)
 {
-    return get_socketbase ()->dtablesize;
+    return get_socketbase (context)->dtablesize;
 }
 
-static uae_u32 bsdsocklib_null (void)
+static uae_u32 REGPARAM2 bsdsocklib_null (TrapContext *context)
 {
     return 0;
 }
 
-extern uae_u32 sockfuncvecs[];
-
-static uae_u32 bsdsocklib_init (void)
+static uae_u32 REGPARAM2 bsdsocklib_init (TrapContext *context)
 {
     uae_u32 tmp1;
     int i;
@@ -1234,19 +1273,19 @@ static uae_u32 bsdsocklib_init (void)
     if (SockLibBase)
        bsdlib_reset ();
 
-    m68k_areg (regs, 0) = functable;
-    m68k_areg (regs, 1) = datatable;
-    m68k_areg (regs, 2) = 0;
-    m68k_dreg (regs, 0) = sizeof (struct UAEBSDBase);
-    m68k_dreg (regs, 1) = 0;
-    tmp1 = CallLib (m68k_areg (regs, 6), -0x54); /* MakeLibrary */
+    m68k_areg (&context->regs, 0) = functable;
+    m68k_areg (&context->regs, 1) = datatable;
+    m68k_areg (&context->regs, 2) = 0;
+    m68k_dreg (&context->regs, 0) = LIBRARY_SIZEOF;
+    m68k_dreg (&context->regs, 1) = 0;
+    tmp1 = CallLib (context, m68k_areg (&context->regs, 6), -0x54); /* MakeLibrary */
 
     if (!tmp1) {
        write_log ("bsdoscket: FATAL: Cannot create bsdsocket.library!\n");
        return 0;
     }
-    m68k_areg (regs, 1) = tmp1;
-    CallLib (m68k_areg (regs, 6), -0x18c); /* AddLibrary */
+    m68k_areg (&context->regs, 1) = tmp1;
+    CallLib (context, m68k_areg (&context->regs, 6), -0x18c); /* AddLibrary */
     SockLibBase = tmp1;
 
     /* Install error strings in Amiga memory */
@@ -1259,9 +1298,9 @@ static uae_u32 bsdsocklib_init (void)
 
     tmp1 += strlen(strErr)+1;
 
-    m68k_dreg (regs, 0) = tmp1;
-    m68k_dreg (regs, 1) = 0;
-    tmp1 = CallLib (get_long (4), -0xC6); /* AllocMem */
+    m68k_dreg (&context->regs, 0) = tmp1;
+    m68k_dreg (&context->regs, 1) = 0;
+    tmp1 = CallLib (context, get_long (4), -0xC6); /* AllocMem */
 
     if (!tmp1) {
        write_log ("bsdsocket: FATAL: Ran out of memory while creating bsdsocket.library!\n");
@@ -1277,12 +1316,12 @@ static uae_u32 bsdsocklib_init (void)
 
     /* @@@ someone please implement a proper interrupt handler setup here :) */
     tmp1 = here ();
-    calltrap (deftrap2 (bsdsock_int_handler, TRAPFLAG_EXTRA_STACK | TRAPFLAG_NO_RETVAL, ""));
+    calltrap (deftrap2 (bsdsock_int_handler, TRAPFLAG_EXTRA_STACK | TRAPFLAG_NO_RETVAL, "bsdsock_int_handler"));
     dw (0x4ef9);
-    dl (get_long (regs.vbr + 0x78));
-    put_long (regs.vbr + 0x78, tmp1);
+    dl (get_long (context->regs.vbr + 0x78));
+    put_long (context->regs.vbr + 0x78, tmp1);
 
-    m68k_dreg (regs, 0) = 1;
+    m68k_dreg (&context->regs, 0) = 1;
     return 0;
 }
 
@@ -1317,13 +1356,13 @@ void bsdlib_reset (void)
     host_sbreset ();
 }
 
-uae_u32 (*sockfuncs[])(void) = {
+static const TrapHandler sockfuncs[] = {
     bsdsocklib_init, bsdsocklib_Open, bsdsocklib_Close, bsdsocklib_Expunge,
     bsdsocklib_socket, bsdsocklib_bind, bsdsocklib_listen, bsdsocklib_accept,
     bsdsocklib_connect, bsdsocklib_sendto, bsdsocklib_send, bsdsocklib_recvfrom, bsdsocklib_recv,
     bsdsocklib_shutdown, bsdsocklib_setsockopt, bsdsocklib_getsockopt, bsdsocklib_getsockname,
     bsdsocklib_getpeername, bsdsocklib_IoctlSocket, bsdsocklib_CloseSocket, bsdsocklib_WaitSelect,
-    bsdsocklib_SetSocketSignals, bsdsocklib_SetDTableSize, bsdsocklib_ObtainSocket, bsdsocklib_ReleaseSocket,
+    bsdsocklib_SetSocketSignals, bsdsocklib_getdtablesize, bsdsocklib_ObtainSocket, bsdsocklib_ReleaseSocket,
     bsdsocklib_ReleaseCopyOfSocket, bsdsocklib_Errno, bsdsocklib_SetErrnoPtr, bsdsocklib_Inet_NtoA,
     bsdsocklib_inet_addr, bsdsocklib_Inet_LnaOf, bsdsocklib_Inet_NetOf, bsdsocklib_Inet_MakeAddr,
     bsdsocklib_inet_network, bsdsocklib_gethostbyname, bsdsocklib_gethostbyaddr, bsdsocklib_getnetbyname,
@@ -1333,7 +1372,23 @@ uae_u32 (*sockfuncs[])(void) = {
     bsdsocklib_GetSocketEvents
 };
 
-uae_u32 sockfuncvecs[sizeof (sockfuncs) / sizeof (*sockfuncs)];
+static const char * const funcnames[] = {
+    "bsdsocklib_init", "bsdsocklib_Open", "bsdsocklib_Close", "bsdsocklib_Expunge",
+    "bsdsocklib_socket", "bsdsocklib_bind", "bsdsocklib_listen", "bsdsocklib_accept",
+    "bsdsocklib_connect", "bsdsocklib_sendto", "bsdsocklib_send", "bsdsocklib_recvfrom", "bsdsocklib_recv",
+    "bsdsocklib_shutdown", "bsdsocklib_setsockopt", "bsdsocklib_getsockopt", "bsdsocklib_getsockname",
+    "bsdsocklib_getpeername", "bsdsocklib_IoctlSocket", "bsdsocklib_CloseSocket", "bsdsocklib_WaitSelect",
+    "bsdsocklib_SetSocketSignals", "bsdsocklib_getdtablesize", "bsdsocklib_ObtainSocket", "bsdsocklib_ReleaseSocket",
+    "bsdsocklib_ReleaseCopyOfSocket", "bsdsocklib_Errno", "bsdsocklib_SetErrnoPtr", "bsdsocklib_Inet_NtoA",
+    "bsdsocklib_inet_addr", "bsdsocklib_Inet_LnaOf", "bsdsocklib_Inet_NetOf", "bsdsocklib_Inet_MakeAddr",
+    "bsdsocklib_inet_network", "bsdsocklib_gethostbyname", "bsdsocklib_gethostbyaddr", "bsdsocklib_getnetbyname",
+    "bsdsocklib_getnetbyaddr", "bsdsocklib_getservbyname", "bsdsocklib_getservbyport", "bsdsocklib_getprotobyname",
+    "bsdsocklib_getprotobynumber", "bsdsocklib_vsyslog", "bsdsocklib_Dup2Socket", "bsdsocklib_sendmsg",
+    "bsdsocklib_recvmsg", "bsdsocklib_gethostname", "bsdsocklib_gethostid", "bsdsocklib_SocketBaseTagList",
+    "bsdsocklib_GetSocketEvents"
+};
+
+static uae_u32 sockfuncvecs[sizeof (sockfuncs) / sizeof (*sockfuncs)];
 
 void bsdlib_install (void)
 {
@@ -1369,7 +1424,7 @@ void bsdlib_install (void)
 
     for (i = 0; i < (int) (sizeof (sockfuncs) / sizeof (sockfuncs[0])); i++) {
        sockfuncvecs[i] = here ();
-       calltrap (deftrap2 (sockfuncs[i], TRAPFLAG_EXTRA_STACK, ""));
+       calltrap (deftrap2 (sockfuncs[i], TRAPFLAG_EXTRA_STACK, funcnames[i]));
        dw (RTS);
     }
 
index 727e48538d21dd68e3f0614b7634aa53d3d3ed50..1ca291b090c144de9ed864cb203c6bf49d403a00 100755 (executable)
@@ -4,7 +4,6 @@
 
 #ifdef CATWEASEL
 
-#include "config.h"
 #include "options.h"
 #include "memory.h"
 #include "ioport.h"
diff --git a/cdrom.c b/cdrom.c
index f171b3c322623c942c225187abeec9dfeed469c7..a19fcdee7dd6f692d5ee9d35a8abb5cef19b3931 100755 (executable)
--- a/cdrom.c
+++ b/cdrom.c
@@ -1,8 +1,6 @@
 #include "sysconfig.h"
 #include "sysdeps.h"
 
-#include "config.h"
-
 /* CDROM MODE 1 EDC/ECC code (from Reed-Solomon library by Heiko Eissfeldt) */
 
 /*****************************************************************/
@@ -25,7 +23,7 @@
 /*                                                               */
 /*****************************************************************/
 
-static uae_u32 EDC_crctable[256] =
+static const uae_u32 EDC_crctable[256] =
 {
  0x00000000L, 0x90910101L, 0x91210201L, 0x01B00300L,
  0x92410401L, 0x02D00500L, 0x03600600L, 0x93F10701L,
diff --git a/cdtv.c b/cdtv.c
index 72f4cfecb58ce7439df6aef3285b850c2bce8a79..2ed259c933d0458bf07d3c6f4b443d1186b0f616 100755 (executable)
--- a/cdtv.c
+++ b/cdtv.c
@@ -12,7 +12,6 @@
 #include "sysconfig.h"
 #include "sysdeps.h"
 
-#include "config.h"
 #include "options.h"
 #include "uae.h"
 #include "memory.h"
 #include "debug.h"
 #include "cdtv.h"
 
-static uae_u32 dmac_lget (uaecptr) REGPARAM;
-static uae_u32 dmac_wget (uaecptr) REGPARAM;
-static uae_u32 dmac_bget (uaecptr) REGPARAM;
-static void dmac_lput (uaecptr, uae_u32) REGPARAM;
-static void dmac_wput (uaecptr, uae_u32) REGPARAM;
-static void dmac_bput (uaecptr, uae_u32) REGPARAM;
+static uae_u32 REGPARAM3 dmac_lget (uaecptr) REGPARAM;
+static uae_u32 REGPARAM3 dmac_wget (uaecptr) REGPARAM;
+static uae_u32 REGPARAM3 dmac_bget (uaecptr) REGPARAM;
+static void REGPARAM3 dmac_lput (uaecptr, uae_u32) REGPARAM;
+static void REGPARAM3 dmac_wput (uaecptr, uae_u32) REGPARAM;
+static void REGPARAM3 dmac_bput (uaecptr, uae_u32) REGPARAM;
 
 static uae_u8 dmacmemory[0x100];
 static uae_u8 wd[0x1f];
@@ -96,7 +95,7 @@ uae_u32 REGPARAM2 dmac_lget (uaecptr addr)
     v = (dmac_bget2 (addr) << 24) | (dmac_bget2 (addr + 1) << 16) |
        (dmac_bget2 (addr + 2) << 8) | (dmac_bget2 (addr + 3));
 #ifdef CDTV_DEBUG
-    write_log ("dmac_lget %08.8X=%08.8X PC=%08.8X\n", addr, v, m68k_getpc());
+    write_log ("dmac_lget %08.8X=%08.8X PC=%08.8X\n", addr, v, M68K_GETPC);
 #endif
     return v;
 }
@@ -109,7 +108,7 @@ uae_u32 REGPARAM2 dmac_wget (uaecptr addr)
 #endif
     v = (dmac_bget2 (addr) << 8) | dmac_bget2 (addr + 1);
 #ifdef CDTV_DEBUG
-    write_log ("dmac_wget %08.8X=%04.4X PC=%08.8X\n", addr, v, m68k_getpc());
+    write_log ("dmac_wget %08.8X=%04.4X PC=%08.8X\n", addr, v, M68K_GETPC);
 #endif
     return v;
 }
@@ -122,7 +121,7 @@ uae_u32 REGPARAM2 dmac_bget (uaecptr addr)
 #endif
     v = dmac_bget2 (addr);
 #ifdef CDTV_DEBUG
-    write_log ("dmac_bget %08.8X=%02.2X PC=%08.8X\n", addr, v, m68k_getpc());
+    write_log ("dmac_bget %08.8X=%02.2X PC=%08.8X\n", addr, v, M68K_GETPC);
 #endif
     return v;
 }
@@ -186,7 +185,7 @@ static void REGPARAM2 dmac_lput (uaecptr addr, uae_u32 l)
     special_mem |= S_WRITE;
 #endif
 #ifdef CDTV_DEBUG
-    write_log ("dmac_lput %08.8X=%08.8X PC=%08.8X\n", addr, l, m68k_getpc());
+    write_log ("dmac_lput %08.8X=%08.8X PC=%08.8X\n", addr, l, M68K_GETPC);
 #endif
     dmac_bput2 (addr, l >> 24);
     dmac_bput2 (addr + 1, l >> 16);
@@ -200,7 +199,7 @@ static void REGPARAM2 dmac_wput (uaecptr addr, uae_u32 w)
     special_mem |= S_WRITE;
 #endif
 #ifdef CDTV_DEBUG
-    write_log ("dmac_wput %04.4X=%04.4X PC=%08.8X\n", addr, w & 65535, m68k_getpc());
+    write_log ("dmac_wput %04.4X=%04.4X PC=%08.8X\n", addr, w & 65535, M68K_GETPC);
 #endif
     dmac_bput2 (addr, w >> 8);
     dmac_bput2 (addr + 1, w);
@@ -212,7 +211,7 @@ static void REGPARAM2 dmac_bput (uaecptr addr, uae_u32 b)
     special_mem |= S_WRITE;
 #endif
 #ifdef CDTV_DEBUG
-    write_log ("dmac_bput %08.8X=%02.2X PC=%08.8X\n", addr, b & 255, m68k_getpc());
+    write_log ("dmac_bput %08.8X=%02.2X PC=%08.8X\n", addr, b & 255, M68K_GETPC);
 #endif
     dmac_bput2 (addr, b);
 }
index 387c219603456238023bf6648c79d2aa8f5657f6..74e7ae72bfcf8856034d29bae85b0ed3a16a1767 100755 (executable)
--- a/cfgfile.c
+++ b/cfgfile.c
@@ -12,9 +12,7 @@
 
 #include <ctype.h>
 
-#include "config.h"
 #include "options.h"
-#include "threaddep/thread.h"
 #include "uae.h"
 #include "autoconf.h"
 #include "events.h"
@@ -39,7 +37,7 @@ struct cfg_lines
     const char *config_label, *config_help;
 };
 
-static struct cfg_lines opttable[] =
+static const struct cfg_lines opttable[] =
 {
     {"help", "Prints this help" },
     {"config_description", "" },
@@ -2230,7 +2228,7 @@ uae_u32 cfgfile_modify (uae_u32 index, char *parms, uae_u32 size, char *out, uae
                    break;
                }
            }
-           set_special (SPCFLAG_BRK);
+           set_special (&regs, SPCFLAG_BRK);
            i++;
        }
     }
diff --git a/cia.c b/cia.c
index b2efa5c01584ac8cd87f3f128f9f79f23b8f3c30..87834da13f4dd7804ef8b94bc767922f216b3873 100755 (executable)
--- a/cia.c
+++ b/cia.c
@@ -12,9 +12,7 @@
 #include "sysdeps.h"
 #include <assert.h>
 
-#include "config.h"
 #include "options.h"
-#include "threaddep/thread.h"
 #include "events.h"
 #include "memory.h"
 #include "custom.h"
@@ -1015,12 +1013,12 @@ void dumpcia (void)
 
 /* CIA memory access */
 
-static uae_u32 cia_lget (uaecptr) REGPARAM;
-static uae_u32 cia_wget (uaecptr) REGPARAM;
-static uae_u32 cia_bget (uaecptr) REGPARAM;
-static void cia_lput (uaecptr, uae_u32) REGPARAM;
-static void cia_wput (uaecptr, uae_u32) REGPARAM;
-static void cia_bput (uaecptr, uae_u32) REGPARAM;
+static uae_u32 REGPARAM3 cia_lget (uaecptr) REGPARAM;
+static uae_u32 REGPARAM3 cia_wget (uaecptr) REGPARAM;
+static uae_u32 REGPARAM3 cia_bget (uaecptr) REGPARAM;
+static void REGPARAM3 cia_lput (uaecptr, uae_u32) REGPARAM;
+static void REGPARAM3 cia_wput (uaecptr, uae_u32) REGPARAM;
+static void REGPARAM3 cia_bput (uaecptr, uae_u32) REGPARAM;
 
 addrbank cia_bank = {
     cia_lget, cia_wget, cia_bget,
@@ -1029,19 +1027,9 @@ addrbank cia_bank = {
 };
 
 
-#ifdef CD32
-extern uae_u32 akiko_lget (uaecptr addr);
-extern uae_u32 akiko_wget (uaecptr addr);
-extern uae_u32 akiko_bget (uaecptr addr);
-extern void akiko_bput (uaecptr addr, uae_u32 value);
-extern void akiko_wput (uaecptr addr, uae_u32 value);
-extern void akiko_lput (uaecptr addr, uae_u32 value);
-#endif
-
 /* e-clock is 10 CPU cycles, 6 cycles low, 4 high
  * data transfer happens during 4 high cycles
  */
-
 #define ECLOCK_DATA_CYCLE 4
 
 static void cia_wait_pre (void)
@@ -1095,7 +1083,7 @@ uae_u32 REGPARAM2 cia_bget (uaecptr addr)
        if (currprefs.cpu_level == 0 && currprefs.cpu_compatible)
            v = (addr & 1) ? regs.irc : regs.irc >> 8;
        if (warned > 0) {
-           write_log ("cia_bget: unknown CIA address %x PC=%x\n", addr, m68k_getpc());
+           write_log ("cia_bget: unknown CIA address %x PC=%x\n", addr, m68k_getpc(&regs));
            warned--;
        }
        break;
@@ -1133,7 +1121,7 @@ uae_u32 REGPARAM2 cia_wget (uaecptr addr)
        if (currprefs.cpu_level == 0 && currprefs.cpu_compatible)
            v = regs.irc;
        if (warned > 0) {
-           write_log ("cia_wget: unknown CIA address %x PC=%x\n", addr, m68k_getpc());
+           write_log ("cia_wget: unknown CIA address %x PC=%x\n", addr, m68k_getpc(&regs));
            warned--;
        }
        break;
@@ -1270,12 +1258,12 @@ static uae_u8 cdtv_battram_read (int addr)
 
 /* battclock memory access */
 
-static uae_u32 clock_lget (uaecptr) REGPARAM;
-static uae_u32 clock_wget (uaecptr) REGPARAM;
-static uae_u32 clock_bget (uaecptr) REGPARAM;
-static void clock_lput (uaecptr, uae_u32) REGPARAM;
-static void clock_wput (uaecptr, uae_u32) REGPARAM;
-static void clock_bput (uaecptr, uae_u32) REGPARAM;
+static uae_u32 REGPARAM3 clock_lget (uaecptr) REGPARAM;
+static uae_u32 REGPARAM3 clock_wget (uaecptr) REGPARAM;
+static uae_u32 REGPARAM3 clock_bget (uaecptr) REGPARAM;
+static void REGPARAM3 clock_lput (uaecptr, uae_u32) REGPARAM;
+static void REGPARAM3 clock_wput (uaecptr, uae_u32) REGPARAM;
+static void REGPARAM3 clock_bput (uaecptr, uae_u32) REGPARAM;
 
 addrbank clock_bank = {
     clock_lget, clock_wget, clock_bget,
@@ -1357,6 +1345,8 @@ void REGPARAM2 clock_bput (uaecptr addr, uae_u32 value)
     }
 }
 
+#ifdef SAVESTATE
+
 /* CIA-A and CIA-B save/restore code */
 
 uae_u8 *restore_cia (int num, uae_u8 *src)
@@ -1501,3 +1491,5 @@ uae_u8 *save_cia (int num, int *len, uae_u8 *dstptr)
     *len = dst - dstbak;
     return dstbak;
 }
+
+#endif /* SAVESTATE */
\ No newline at end of file
index 195905e8cb88df19136b3f2d7a4e10996ceb23f0..b14855bd97aa23c3f61579e46c7f6fad9d9d506a 100755 (executable)
@@ -13,7 +13,6 @@
 #include "sysconfig.h"
 #include "sysdeps.h"
 
-#include "config.h"
 #include "options.h"
 #include "memory.h"
 #include "custom.h"
@@ -26,7 +25,7 @@
 uae_u32 temp_fp[] = {0,0,0};  /* To convert between FP and <EA> */
 
 /* 128 words, indexed through the low byte of the 68k fpu control word */
-static uae_u16 x86_fpucw[]={
+static const uae_u16 x86_fpucw[]={
     0x137f, 0x137f, 0x137f, 0x137f, 0x137f, 0x137f, 0x137f, 0x137f, /* E-RN */
     0x1f7f, 0x1f7f, 0x1f7f, 0x1f7f, 0x1f7f, 0x1f7f, 0x1f7f, 0x1f7f, /* E-RZ */
     0x177f, 0x177f, 0x177f, 0x177f, 0x177f, 0x177f, 0x177f, 0x177f, /* E-RD */
@@ -47,8 +46,8 @@ static uae_u16 x86_fpucw[]={
     0x177f, 0x177f, 0x177f, 0x177f, 0x177f, 0x177f, 0x177f, 0x177f, /* ?-RD */
     0x1b7f, 0x1b7f, 0x1b7f, 0x1b7f, 0x1b7f, 0x1b7f, 0x1b7f, 0x1b7f  /* ?-RU */
 };
-static int sz1[8] = { 4, 4, 12, 12, 2, 8, 1, 0 };
-static int sz2[8] = { 4, 4, 12, 12, 2, 8, 2, 0 };
+static const int sz1[8] = { 4, 4, 12, 12, 2, 8, 1, 0 };
+static const int sz2[8] = { 4, 4, 12, 12, 2, 8, 2, 0 };
 
 /* return the required floating point precision or -1 for failure, 0=E, 1=S, 2=D */
 STATIC_INLINE int comp_fp_get (uae_u32 opcode, uae_u16 extra, int treg)
@@ -458,11 +457,9 @@ void comp_fscc_opp (uae_u32 opcode, uae_u16 extra)
     }
 
 #if DEBUG_FPP
-    printf ("fscc_opp at %08lx\n", m68k_getpc ());
-    fflush (stdout);
+    write_log ("JIT: fscc_opp at %08lx\n", M68K_GETPC);
 #endif
 
-
     if (extra&0x20) {  /* only cc from 00 to 1f are defined */
        FAIL(1);
        return;
@@ -507,8 +504,8 @@ void comp_fscc_opp (uae_u32 opcode, uae_u16 extra)
     else {
        abort();
        if (!comp_fp_adr (opcode)) {
-           m68k_setpc (m68k_getpc () - 4);
-           op_illg (opcode);
+           m68k_setpc (&regs, m68k_getpc (&regs) - 4);
+           op_illg (opcode, &regs);
        }
        else
            put_byte (ad, cc ? 0xff : 0x00);
@@ -682,12 +679,11 @@ void comp_fsave_opp (uae_u32 opcode)
     }
 
 #if DEBUG_FPP
-    printf ("fsave_opp at %08lx\n", m68k_getpc ());
-    fflush (stdout);
+    write_log ("JIT: fsave_opp at %08lx\n", M68K_GETPC);
 #endif
     if (!comp_fp_adr (opcode)) {
-       m68k_setpc (m68k_getpc () - 2);
-       op_illg (opcode);
+       m68k_setpc (&regs, m68k_getpc (&regs) - 2);
+       op_illg (opcode, &regs);
        return;
     }
 
@@ -722,9 +718,9 @@ void comp_fsave_opp (uae_u32 opcode)
        }
     }
     if ((opcode & 0x38) == 0x18)
-       m68k_areg (regs, opcode & 7) = ad;
+       m68k_areg (&regs, opcode & 7) = ad;
     if ((opcode & 0x38) == 0x20)
-       m68k_areg (regs, opcode & 7) = ad;
+       m68k_areg (&regs, opcode & 7) = ad;
 }
 
 void comp_frestore_opp (uae_u32 opcode)
@@ -742,12 +738,11 @@ void comp_frestore_opp (uae_u32 opcode)
     }
 
 #if DEBUG_FPP
-    printf ("frestore_opp at %08lx\n", m68k_getpc ());
-    fflush (stdout);
+    write_log ("frestore_opp at %08lx\n", M68K_GETPC);
 #endif
     if (!comp_fp_adr (opcode)) {
-       m68k_setpc (m68k_getpc () - 2);
-       op_illg (opcode);
+       m68k_setpc (&regs, m68k_getpc (&regs) - 2);
+       op_illg (opcode, &regs);
        return;
     }
     if (currprefs.cpu_level >= 4) {
@@ -802,9 +797,9 @@ void comp_frestore_opp (uae_u32 opcode)
        }
     }
     if ((opcode & 0x38) == 0x18)
-       m68k_areg (regs, opcode & 7) = ad;
+       m68k_areg (&regs, opcode & 7) = ad;
     if ((opcode & 0x38) == 0x20)
-       m68k_areg (regs, opcode & 7) = ad;
+       m68k_areg (&regs, opcode & 7) = ad;
 }
 
 extern uae_u32 xhex_pi, xhex_exp_1, xhex_l2_e, xhex_ln_2, xhex_ln_10;
index cc40eed2d53d30786bf64b4dcb3aed38a87fac7b..f84fdc62f564a5f9876ca14d3a18c12c4230fb89 100755 (executable)
 #undef LENDFUNC
 
 #define LOWFUNC(flags,mem,nargs,func,args) \
-  static __inline__ void do_##func args
+  STATIC_INLINE void do_##func args
 
 #define LENDFUNC(flags,mem,nargs,func,args) \
-  static __inline__ void func args \
+  STATIC_INLINE void func args \
   { \
   if (LDECISION) { \
     lopt_op##nargs##args do_##func, mem, flags); \
@@ -116,17 +116,17 @@ typedef struct lopt_inst_rec {
 static lopt_inst linst[MAXLOPTINST];
 static int lopt_index=0;
 
-static __inline__ int argsize(int type)
+STATIC_INLINE int argsize(int type)
 {
     return type&SIZEMASK;
 }
 
-static __inline__ int reads_mem(int i) {
+STATIC_INLINE int reads_mem(int i) {
     return linst[i].mem & READ;
 }
 
 
-static __inline__ int access_reg(int i, int r, int mode)
+STATIC_INLINE int access_reg(int i, int r, int mode)
 {
     int k;
     for (k=0;k<linst[i].nargs;k++)
@@ -137,40 +137,40 @@ static __inline__ int access_reg(int i, int r, int mode)
     return 0;
 }
 
-static __inline__ int writes_reg(int i, int r)
+STATIC_INLINE_ int writes_reg(int i, int r)
 {
     return access_reg(i,r,WRITE);
 }
 
-static __inline__ int reads_reg(int i, int r)
+STATIC_INLINE int reads_reg(int i, int r)
 {
     return access_reg(i,r,READ);
 }
 
-static __inline__ int uses_reg(int i, int r)
+STATIC_INLINE int uses_reg(int i, int r)
 {
     return access_reg(i,r,RMW);
 }
 
 
-static __inline__ int writes_mem(int i) {
+STATIC_INLINE int writes_mem(int i) {
     return linst[i].mem & WRITE;
 }
 
-static __inline__ int uses_mem(int i)
+STATIC_INLINE int uses_mem(int i)
 {
     return linst[i].mem & RMW;
 }
 
-static __inline__ int reads_flags(int i) {
+STATIC_INLINE int reads_flags(int i) {
     return linst[i].flags & READ;
 }
 
-static __inline__ int writes_flags(int i) {
+STATIC_INLINE int writes_flags(int i) {
     return linst[i].flags & WRITE;
 }
 
-static __inline__ int uses_flags(int i)
+STATIC_INLINE int uses_flags(int i)
 {
     return linst[i].flags & RMW;
 }
@@ -180,7 +180,7 @@ static void do_raw_fflags_save(void);
 
 
 /* Whether i depends on j */
-static __inline__ int depends_on(int i, int j)
+STATIC_INLINE int depends_on(int i, int j)
 {
     int n;
 
@@ -233,7 +233,7 @@ static __inline__ int depends_on(int i, int j)
 
 static void do_raw_mov_l_rm(W4 d, MEMR s);
 
-static __inline__ void low_peephole(void)
+STATIC_INLINE void low_peephole(void)
 {
     int i;
 
@@ -298,14 +298,14 @@ static void lopt_emit_all(void)
     inemit=0;
 }
 
-static __inline__ void low_advance(void)
+STATIC_INLINE void low_advance(void)
 {
   lopt_index++;
   if (lopt_index==MAXLOPTINST)
     lopt_emit_all();
 }
 
-static __inline__ void lopt_store_op0(void* lfuncptr, uae_u32 lmem,
+STATIC_INLINE void lopt_store_op0(void* lfuncptr, uae_u32 lmem,
                                      uae_u32 lflags)
 {
   linst[lopt_index].func=lfuncptr;
@@ -315,7 +315,7 @@ static __inline__ void lopt_store_op0(void* lfuncptr, uae_u32 lmem,
   low_advance();
 }
 
-static __inline__ void lopt_store_op1(uae_u8 t1, uae_u32 a1,
+STATIC_INLINE void lopt_store_op1(uae_u8 t1, uae_u32 a1,
                                      void* lfuncptr, uae_u32 lmem,
                                      uae_u32 lflags)
 {
@@ -328,7 +328,7 @@ static __inline__ void lopt_store_op1(uae_u8 t1, uae_u32 a1,
   low_advance();
 }
 
-static __inline__ void lopt_store_op2(uae_u8 t1, uae_u32 a1,
+STATIC_INLINE void lopt_store_op2(uae_u8 t1, uae_u32 a1,
                                      uae_u8 t2, uae_u32 a2,
                                      void* lfuncptr, uae_u32 lmem,
                                      uae_u32 lflags)
@@ -344,7 +344,7 @@ static __inline__ void lopt_store_op2(uae_u8 t1, uae_u32 a1,
   low_advance();
 }
 
-static __inline__ void lopt_store_op3(uae_u8 t1, uae_u32 a1,
+STATIC_INLINE void lopt_store_op3(uae_u8 t1, uae_u32 a1,
                                      uae_u8 t2, uae_u32 a2,
                                      uae_u8 t3, uae_u32 a3,
                                      void* lfuncptr, uae_u32 lmem,
@@ -363,7 +363,7 @@ static __inline__ void lopt_store_op3(uae_u8 t1, uae_u32 a1,
   low_advance();
 }
 
-static __inline__ void lopt_store_op4(uae_u8 t1, uae_u32 a1,
+STATIC_INLINE void lopt_store_op4(uae_u8 t1, uae_u32 a1,
                                      uae_u8 t2, uae_u32 a2,
                                      uae_u8 t3, uae_u32 a3,
                                      uae_u8 t4, uae_u32 a4,
@@ -385,7 +385,7 @@ static __inline__ void lopt_store_op4(uae_u8 t1, uae_u32 a1,
   low_advance();
 }
 
-static __inline__ void lopt_store_op5(uae_u8 t1, uae_u32 a1,
+STATIC_INLINE void lopt_store_op5(uae_u8 t1, uae_u32 a1,
                                      uae_u8 t2, uae_u32 a2,
                                      uae_u8 t3, uae_u32 a3,
                                      uae_u8 t4, uae_u32 a4,
@@ -410,12 +410,12 @@ static __inline__ void lopt_store_op5(uae_u8 t1, uae_u32 a1,
   low_advance();
 }
 
-static __inline__ void empty_low_optimizer(void)
+STATIC_INLINE void empty_low_optimizer(void)
 {
   lopt_emit_all();
 }
 
 #else
-static __inline__ void lopt_emit_all(void) {}
-static __inline__ void empty_low_optimizer(void) {}
+#define lopt_emit_all()
+#define empty_low_optimizer()
 #endif
index 68c46ab04c1f0c02f37859de1e57e28f66f42f63..e1a5a6b9e2b1074e3ce76dfc89d917e664fac294 100755 (executable)
 #define EBX 3
 
 /* The register in which subroutines return an integer return value */
-#define REG_RESULT 0
+#define REG_RESULT EAX
 
 /* The registers subroutines take their first and second argument in */
-#define REG_PAR1 0
-#define REG_PAR2 2
+#ifdef _WIN32
+/* MSVC __fastcall registers are ECX and EDX */
+#define REG_PAR1 ECX
+#define REG_PAR2 EDX
+#else
+#define REG_PAR1 EAX
+#define REG_PAR2 EDX
+#endif
 
 /* Three registers that are not used for any of the above */
 #define REG_NOPAR1 6
@@ -85,17 +91,17 @@ uae_u8 need_to_preserve[]={1,1,1,1,0,1,1,1};
 
 #include "compemu_optimizer_x86.c"
 
-static uae_u16 swap16(uae_u16 x)
+STATIC_INLINE uae_u16 swap16(uae_u16 x)
 {
     return ((x&0xff00)>>8)|((x&0x00ff)<<8);
 }
 
-static uae_u32 swap32(uae_u32 x)
+STATIC_INLINE uae_u32 swap32(uae_u32 x)
 {
     return ((x&0xff00)<<8)|((x&0x00ff)<<24)|((x&0xff0000)>>8)|((x&0xff000000)>>24);
 }
 
-static __inline__ int isbyte(uae_s32 x)
+STATIC_INLINE int isbyte(uae_s32 x)
 {
     return (x>=-128 && x<=127);
 }
@@ -575,7 +581,7 @@ LOWFUNC(NONE,NONE,2,raw_imul_64_32,(RW4 d, RW4 s))
 {
 #ifdef JIT_DEBUG
     if (d!=MUL_NREG1 || s!=MUL_NREG2) {
-       printf("Bad register in IMUL: d=%d, s=%d\n",d,s);
+       write_log("JIT: Bad register in IMUL: d=%d, s=%d\n",d,s);
        abort();
     }
 #endif
@@ -588,7 +594,7 @@ LOWFUNC(NONE,NONE,2,raw_mul_64_32,(RW4 d, RW4 s))
 {
 #ifdef JIT_DEBUG
     if (d!=MUL_NREG1 || s!=MUL_NREG2) {
-       printf("Bad register in MUL: d=%d, s=%d\n",d,s);
+       write_log("JIT: Bad register in MUL: d=%d, s=%d\n",d,s);
        abort();
     }
 #endif
@@ -1397,21 +1403,21 @@ LENDFUNC(WRITE,READ,0,raw_popfl,(void))
  * Unoptimizable stuff --- jump                                          *
  *************************************************************************/
 
-static __inline__ void raw_call_r(R4 r)
+STATIC_INLINE void raw_call_r(R4 r)
 {
     lopt_emit_all();
     emit_byte(0xff);
     emit_byte(0xd0+r);
 }
 
-static __inline__ void raw_jmp_r(R4 r)
+STATIC_INLINE void raw_jmp_r(R4 r)
 {
     lopt_emit_all();
     emit_byte(0xff);
     emit_byte(0xe0+r);
 }
 
-static __inline__ void raw_jmp_m_indexed(uae_u32 base, uae_u32 r, uae_u32 m)
+STATIC_INLINE void raw_jmp_m_indexed(uae_u32 base, uae_u32 r, uae_u32 m)
 {
     int sib;
 
@@ -1429,7 +1435,7 @@ static __inline__ void raw_jmp_m_indexed(uae_u32 base, uae_u32 r, uae_u32 m)
     emit_long(base);
 }
 
-static __inline__ void raw_jmp_m(uae_u32 base)
+STATIC_INLINE void raw_jmp_m(uae_u32 base)
 {
     lopt_emit_all();
     emit_byte(0xff);
@@ -1437,21 +1443,21 @@ static __inline__ void raw_jmp_m(uae_u32 base)
     emit_long(base);
 }
 
-static __inline__ void raw_call(uae_u32 t)
+STATIC_INLINE void raw_call(uae_u32 t)
 {
     lopt_emit_all();
     emit_byte(0xe8);
     emit_long(t-(uae_u32)target-4);
 }
 
-static __inline__ void raw_jmp(uae_u32 t)
+STATIC_INLINE void raw_jmp(uae_u32 t)
 {
     lopt_emit_all();
     emit_byte(0xe9);
     emit_long(t-(uae_u32)target-4);
 }
 
-static __inline__ void raw_jl(uae_u32 t)
+STATIC_INLINE void raw_jl(uae_u32 t)
 {
     lopt_emit_all();
     emit_byte(0x0f);
@@ -1459,7 +1465,7 @@ static __inline__ void raw_jl(uae_u32 t)
     emit_long(t-(uae_u32)target-4);
 }
 
-static __inline__ void raw_jz(uae_u32 t)
+STATIC_INLINE void raw_jz(uae_u32 t)
 {
     lopt_emit_all();
     emit_byte(0x0f);
@@ -1467,7 +1473,7 @@ static __inline__ void raw_jz(uae_u32 t)
     emit_long(t-(uae_u32)target-4);
 }
 
-static __inline__ void raw_jnz(uae_u32 t)
+STATIC_INLINE void raw_jnz(uae_u32 t)
 {
     lopt_emit_all();
     emit_byte(0x0f);
@@ -1475,51 +1481,51 @@ static __inline__ void raw_jnz(uae_u32 t)
     emit_long(t-(uae_u32)target-4);
 }
 
-static __inline__ void raw_jnz_l_oponly(void)
+STATIC_INLINE void raw_jnz_l_oponly(void)
 {
     lopt_emit_all();
     emit_byte(0x0f);
     emit_byte(0x85);
 }
 
-static __inline__ void raw_jcc_l_oponly(int cc)
+STATIC_INLINE void raw_jcc_l_oponly(int cc)
 {
     lopt_emit_all();
     emit_byte(0x0f);
     emit_byte(0x80+cc);
 }
 
-static __inline__ void raw_jnz_b_oponly(void)
+STATIC_INLINE void raw_jnz_b_oponly(void)
 {
     lopt_emit_all();
     emit_byte(0x75);
 }
 
-static __inline__ void raw_jz_b_oponly(void)
+STATIC_INLINE void raw_jz_b_oponly(void)
 {
     lopt_emit_all();
     emit_byte(0x74);
 }
 
-static __inline__ void raw_jmp_l_oponly(void)
+STATIC_INLINE void raw_jmp_l_oponly(void)
 {
     lopt_emit_all();
     emit_byte(0xe9);
 }
 
-static __inline__ void raw_jmp_b_oponly(void)
+STATIC_INLINE void raw_jmp_b_oponly(void)
 {
     lopt_emit_all();
     emit_byte(0xeb);
 }
 
-static __inline__ void raw_ret(void)
+STATIC_INLINE void raw_ret(void)
 {
     lopt_emit_all();
     emit_byte(0xc3);
 }
 
-static __inline__ void raw_nop(void)
+STATIC_INLINE void raw_nop(void)
 {
     lopt_emit_all();
     emit_byte(0x90);
@@ -1533,7 +1539,7 @@ static __inline__ void raw_nop(void)
 
 #define FLAG_NREG1 0  /* Set to -1 if any register will do */
 
-static __inline__ void raw_flags_to_reg(int r)
+STATIC_INLINE void raw_flags_to_reg(int r)
 {
   raw_lahf(0);  /* Most flags in AH */
   //raw_setcc(r,0); /* V flag in AL */
@@ -1555,7 +1561,7 @@ static __inline__ void raw_flags_to_reg(int r)
 }
 
 #define FLAG_NREG2 0  /* Set to -1 if any register will do */
-static __inline__ void raw_reg_to_flags(int r)
+STATIC_INLINE void raw_reg_to_flags(int r)
 {
   raw_cmp_b_ri(r,-127); /* set V */
   raw_sahf(0);
@@ -1563,7 +1569,7 @@ static __inline__ void raw_reg_to_flags(int r)
 
 /* Apparently, there are enough instructions between flag store and
    flag reload to avoid the partial memory stall */
-static __inline__ void raw_load_flagreg(uae_u32 target, uae_u32 r)
+STATIC_INLINE void raw_load_flagreg(uae_u32 target, uae_u32 r)
 {
 #if 1
     raw_mov_l_rm(target,(uae_u32)live.state[r].mem);
@@ -1573,12 +1579,10 @@ static __inline__ void raw_load_flagreg(uae_u32 target, uae_u32 r)
 #endif
 }
 
-/* FLAGX is byte sized, and we *do* write it at that size */
-static __inline__ void raw_load_flagx(uae_u32 target, uae_u32 r)
+/* FLAGX is word-sized */
+STATIC_INLINE void raw_load_flagx(uae_u32 target, uae_u32 r)
 {
-    if (live.nat[target].canbyte)
-       raw_mov_b_rm(target,(uae_u32)live.state[r].mem);
-    else if (live.nat[target].canword)
+    if (live.nat[target].canword)
        raw_mov_w_rm(target,(uae_u32)live.state[r].mem);
     else
        raw_mov_l_rm(target,(uae_u32)live.state[r].mem);
@@ -1586,7 +1590,7 @@ static __inline__ void raw_load_flagx(uae_u32 target, uae_u32 r)
 
 #define NATIVE_FLAG_Z 0x40
 #define NATIVE_CC_EQ  4
-static __inline__ void raw_flags_set_zero(int f, int r, int t)
+STATIC_INLINE void raw_flags_set_zero(int f, int r, int t)
 {
     // FIXME: this is really suboptimal
     raw_pushfl();
@@ -1601,7 +1605,7 @@ static __inline__ void raw_flags_set_zero(int f, int r, int t)
     raw_popfl();
 }
 
-static __inline__ void raw_inc_sp(int off)
+STATIC_INLINE void raw_inc_sp(int off)
 {
     raw_add_l_ri(4,off);
 }
@@ -1745,7 +1749,7 @@ int EvalException ( LPEXCEPTION_POINTERS blah, int n_except )
     if (r!=-1) {
        void* pr=NULL;
 #ifdef JIT_DEBUG
-       write_log("register was %d, direction was %d, size was %d\n",r,dir,size);
+       write_log("JIT: register was %d, direction was %d, size was %d\n",r,dir,size);
 #endif
 
        switch(r) {
@@ -1791,7 +1795,7 @@ int EvalException ( LPEXCEPTION_POINTERS blah, int n_except )
 #ifdef JIT_DEBUG
                if ((addr>=0x10000000 && addr<0x40000000) ||
                    (addr>=0x50000000)) {
-                   write_log("Suspicious address 0x%x in SEGV handler.\n",addr);
+                       write_log("JIT: Suspicious address 0x%x in SEGV handler.\n",addr);
                }
 #endif
                if (dir==SIG_READ) {
@@ -1811,7 +1815,7 @@ int EvalException ( LPEXCEPTION_POINTERS blah, int n_except )
                    }
                }
 #ifdef JIT_DEBUG
-               write_log("Handled one access!\n");
+               write_log("JIT: Handled one access!\n");
 #endif
                fflush(stdout);
                segvcount++;
@@ -1827,7 +1831,7 @@ int EvalException ( LPEXCEPTION_POINTERS blah, int n_except )
 #ifdef JIT_DEBUG
                if ((addr>=0x10000000 && addr<0x40000000) ||
                    (addr>=0x50000000)) {
-                   write_log("Suspicious address 0x%x in SEGV handler.\n",addr);
+                   write_log("JIT: Suspicious address 0x%x in SEGV handler.\n",addr);
                }
 #endif
 
@@ -1838,8 +1842,8 @@ int EvalException ( LPEXCEPTION_POINTERS blah, int n_except )
                emit_long((uae_u32)veccode-(uae_u32)target-4);
 #ifdef JIT_DEBUG
 
-               write_log("Create jump to %p\n",veccode);
-               write_log("Handled one access!\n");
+               write_log("JIT: Create jump to %p\n",veccode);
+               write_log("JIT: Handled one access!\n");
 #endif
                segvcount++;
 
@@ -1875,7 +1879,7 @@ int EvalException ( LPEXCEPTION_POINTERS blah, int n_except )
                    (uae_u8*)bi->direct_handler<=i &&
                    (uae_u8*)bi->nexthandler>i) {
 #ifdef JIT_DEBUG
-                   write_log("deleted trigger (%p<%p<%p) %p\n",
+                   write_log("JIT: deleted trigger (%p<%p<%p) %p\n",
                        bi->handler,
                        i,
                        bi->nexthandler,
@@ -1883,7 +1887,7 @@ int EvalException ( LPEXCEPTION_POINTERS blah, int n_except )
 #endif
                    invalidate_block(bi);
                    raise_in_cl_list(bi);
-                   set_special(0);
+                   set_special(&regs, 0);
                    return EXCEPTION_CONTINUE_EXECUTION;
                }
                bi=bi->next;
@@ -1896,7 +1900,7 @@ int EvalException ( LPEXCEPTION_POINTERS blah, int n_except )
                    (uae_u8*)bi->direct_handler<=i &&
                    (uae_u8*)bi->nexthandler>i) {
 #ifdef JIT_DEBUG
-                   write_log("deleted trigger (%p<%p<%p) %p\n",
+                   write_log("JIT: deleted trigger (%p<%p<%p) %p\n",
                        bi->handler,
                        i,
                        bi->nexthandler,
@@ -1904,13 +1908,13 @@ int EvalException ( LPEXCEPTION_POINTERS blah, int n_except )
 #endif
                    invalidate_block(bi);
                    raise_in_cl_list(bi);
-                   set_special(0);
+                   set_special(&regs, 0);
                    return EXCEPTION_CONTINUE_EXECUTION;
                }
                bi=bi->next;
            }
 #ifdef JIT_DEBUG
-           write_log("Huh? Could not find trigger!\n");
+           write_log("JIT: Huh? Could not find trigger!\n");
 #endif
            return EXCEPTION_CONTINUE_EXECUTION;
        }
@@ -1942,11 +1946,11 @@ static void vec(int x, struct sigcontext sc)
     int len=0;
     int j;
 
-    write_log("fault address is %08x at %08x\n",sc.cr2,sc.eip);
+    write_log("JIT: fault address is %08x at %08x\n",sc.cr2,sc.eip);
     if (!canbang)
-       write_log("Not happy! Canbang is 0 in SIGSEGV handler!\n");
+       write_log("JIT: Not happy! Canbang is 0 in SIGSEGV handler!\n");
     if (in_handler)
-       write_log("Argh --- Am already in a handler. Shouldn't happen!\n");
+       write_log("JIT: Argh --- Am already in a handler. Shouldn't happen!\n");
 
     if (canbang && i>=compiled_code && i<=current_compile_p) {
        if (*i==0x66) {
@@ -2021,7 +2025,7 @@ static void vec(int x, struct sigcontext sc)
 
     if (r!=-1) {
        void* pr=NULL;
-       write_log("register was %d, direction was %d, size was %d\n",r,dir,size);
+       write_log("JIT: register was %d, direction was %d, size was %d\n",r,dir,size);
 
        switch(r) {
         case 0: pr=&(sc.eax); break;
@@ -2048,7 +2052,7 @@ static void vec(int x, struct sigcontext sc)
 
            if ((addr>=0x10000000 && addr<0x40000000) ||
                (addr>=0x50000000)) {
-               write_log("Suspicious address in %x SEGV handler.\n",addr);
+               write_log("JIT: Suspicious address in %x SEGV handler.\n",addr);
            }
            if (dir==SIG_READ) {
                switch(size) {
@@ -2066,7 +2070,7 @@ static void vec(int x, struct sigcontext sc)
                 default: abort();
                }
            }
-           write_log("Handled one access!\n");
+           write_log("JIT: Handled one access!\n");
            fflush(stdout);
            segvcount++;
            sc.eip+=len;
@@ -2080,7 +2084,7 @@ static void vec(int x, struct sigcontext sc)
 
                if ((addr>=0x10000000 && addr<0x40000000) ||
                    (addr>=0x50000000)) {
-                   write_log("Suspicious address 0x%x in SEGV handler.\n",addr);
+                   write_log("JIT: Suspicious address 0x%x in SEGV handler.\n",addr);
                }
 
                target=(uae_u8*)sc.eip;
@@ -2088,10 +2092,9 @@ static void vec(int x, struct sigcontext sc)
                    vecbuf[i]=target[i];
                emit_byte(0xe9);
                emit_long((uae_u32)veccode-(uae_u32)target-4);
-               write_log("Create jump to %p\n",veccode);
+               write_log("JIT: Create jump to %p\n",veccode);
 
-               write_log("Handled one access!\n");
-               fflush(stdout);
+               write_log("JIT: Handled one access!\n");
                segvcount++;
 
                target=veccode;
@@ -2125,14 +2128,14 @@ static void vec(int x, struct sigcontext sc)
                if (bi->handler &&
                    (uae_u8*)bi->direct_handler<=i &&
                    (uae_u8*)bi->nexthandler>i) {
-                   write_log("deleted trigger (%p<%p<%p) %p\n",
+                   write_log("JIT: deleted trigger (%p<%p<%p) %p\n",
                              bi->handler,
                              i,
                              bi->nexthandler,
                              bi->pc_p);
                    invalidate_block(bi);
                    raise_in_cl_list(bi);
-                   set_special(0);
+                   set_special(&regs, 0);
                    return;
                }
                bi=bi->next;
@@ -2144,25 +2147,25 @@ static void vec(int x, struct sigcontext sc)
                if (bi->handler &&
                    (uae_u8*)bi->direct_handler<=i &&
                    (uae_u8*)bi->nexthandler>i) {
-                   write_log("deleted trigger (%p<%p<%p) %p\n",
+                   write_log("JIT: deleted trigger (%p<%p<%p) %p\n",
                              bi->handler,
                              i,
                              bi->nexthandler,
                              bi->pc_p);
                    invalidate_block(bi);
                    raise_in_cl_list(bi);
-                   set_special(0);
+                   set_special(&regs, 0);
                    return;
                }
                bi=bi->next;
            }
-           write_log("Huh? Could not find trigger!\n");
+           write_log("JIT: Huh? Could not find trigger!\n");
            return;
        }
     }
-    write_log("Can't handle access!\n");
+    write_log("JIT: Can't handle access!\n");
     for (j=0;j<10;j++) {
-       write_log("instruction byte %2d is %02x\n",j,i[j]);
+       write_log("JIT: instruction byte %2d is %02x\n",j,i[j]);
     }
 #if 0
     write_log("Please send the above info (starting at \"fault address\") to\n"
@@ -2290,7 +2293,7 @@ static void cpuid(uae_u32 op, uae_u32 *eax, uae_u32 *ebx, uae_u32 *ecx, uae_u32
   raw_ret();
   set_target(tmp);
 
-  ((cpuop_func*)cpuid_space)(0);
+  ((compop_func*)cpuid_space)(0);
   if (eax != NULL) *eax = s_eax;
   if (ebx != NULL) *ebx = s_ebx;
   if (ecx != NULL) *ecx = s_ecx;
@@ -2560,7 +2563,7 @@ static void raw_init_cpu(void)
  *************************************************************************/
 
 
-static __inline__ void raw_fp_init(void)
+STATIC_INLINE void raw_fp_init(void)
 {
     int i;
 
@@ -2569,7 +2572,7 @@ static __inline__ void raw_fp_init(void)
     live.tos=-1;  /* Stack is empty */
 }
 
-static __inline__ void raw_fp_cleanup_drop(void)
+STATIC_INLINE void raw_fp_cleanup_drop(void)
 {
 #if 0
     /* using FINIT instead of popping all the entries.
@@ -2595,7 +2598,7 @@ static __inline__ void raw_fp_cleanup_drop(void)
     raw_fp_init();
 }
 
-static __inline__ void make_tos(int r)
+STATIC_INLINE void make_tos(int r)
 {
     int p,q;
 
@@ -2621,12 +2624,12 @@ static __inline__ void make_tos(int r)
     live.spos[q]=p;
 }
 
-static __inline__ int stackpos(int r)
+STATIC_INLINE int stackpos(int r)
 {
     if (live.spos[r]<0)
        abort();
     if (live.tos<live.spos[r]) {
-       printf("Looking for spos for fnreg %d\n",r);
+       write_log("JIT: Looking for spos for fnreg %d\n",r);
        abort();
     }
     return live.tos-live.spos[r];
@@ -2636,7 +2639,7 @@ static __inline__ int stackpos(int r)
    an argument, because I would expect all arguments to be on the stack already, won't they?
    Thus, usereg(s) is always useless and also for every FRW d it's too late here now. PeterK
 */
-static __inline__ void usereg(int r)
+STATIC_INLINE void usereg(int r)
 {
 
     if (live.spos[r]<0) {
@@ -2647,7 +2650,7 @@ static __inline__ void usereg(int r)
 
 /* This is called with one FP value in a reg *above* tos,
    which it will pop off the stack if necessary */
-static __inline__ void tos_make(int r)
+STATIC_INLINE void tos_make(int r)
 {
     if (live.spos[r]<0) {
        live.tos++;
@@ -3950,7 +3953,7 @@ LOWFUNC(NONE,NONE,1,raw_ftst_r,(FR r))
 }
 LENDFUNC(NONE,NONE,1,raw_ftst_r,(FR r))
 
-static __inline__ void raw_fflags_into_flags(int r)
+STATIC_INLINE void raw_fflags_into_flags(int r)
 {
     int p;
 
index 357392edf313452f96c6dc12e1eee52ccb999bc7..3a8f8faa8f32c85ba2c8eff6ff7188122fce43e2 100755 (executable)
@@ -5,7 +5,6 @@
 #define USE_MATCHSTATE 0
 #include "sysconfig.h"
 #include "sysdeps.h"
-#include "config.h"
 #include "options.h"
 #include "events.h"
 #include "include/memory.h"
 // %%% BRIAN KING WAS HERE %%%
 extern int canbang;
 #include <sys/mman.h>
-#include <limits.h>    /* for PAGESIZE */
 
-cpuop_func *compfunctbl[65536];
-cpuop_func *nfcompfunctbl[65536];
+compop_func *compfunctbl[65536];
+compop_func *nfcompfunctbl[65536];
 #ifdef NOFLAGS_SUPPORT
-cpuop_func *nfcpufunctbl[65536];
+compop_func *nfcpufunctbl[65536];
 #endif
 uae_u8* comp_pc_p;
 
@@ -85,21 +83,21 @@ op_properties prop[65536];
 
 #ifdef NOFLAGS_SUPPORT
 /* 68040 */
-extern struct cputbl op_smalltbl_0_nf[];
+extern const struct comptbl op_smalltbl_0_nf[];
 #endif
-extern struct cputbl op_smalltbl_0_comp_nf[];
-extern struct cputbl op_smalltbl_0_comp_ff[];
+extern const struct comptbl op_smalltbl_0_comp_nf[];
+extern const struct comptbl op_smalltbl_0_comp_ff[];
 #ifdef NOFLAGS_SUPPORT
 /* 68020 + 68881 */
-extern struct cputbl op_smalltbl_1_nf[];
+extern const struct cputbl op_smalltbl_1_nf[];
 /* 68020 */
-extern struct cputbl op_smalltbl_2_nf[];
+extern const struct cputbl op_smalltbl_2_nf[];
 /* 68010 */
-extern struct cputbl op_smalltbl_3_nf[];
+extern const struct cputbl op_smalltbl_3_nf[];
 /* 68000 */
-extern struct cputbl op_smalltbl_4_nf[];
+extern const struct cputbl op_smalltbl_4_nf[];
 /* 68000 slow but compatible.  */
-extern struct cputbl op_smalltbl_5_nf[];
+extern const struct cputbl op_smalltbl_5_nf[];
 #endif
 
 static void flush_icache_hard(int n);
@@ -159,12 +157,12 @@ uae_u32 needflags=0;
 */
 
 
-static __inline__ blockinfo* get_blockinfo(uae_u32 cl)
+STATIC_INLINE blockinfo* get_blockinfo(uae_u32 cl)
 {
     return cache_tags[cl+1].bi;
 }
 
-static __inline__ blockinfo* get_blockinfo_addr(void* addr)
+STATIC_INLINE blockinfo* get_blockinfo_addr(void* addr)
 {
     blockinfo*  bi=get_blockinfo(cacheline(addr));
 
@@ -181,7 +179,7 @@ static __inline__ blockinfo* get_blockinfo_addr(void* addr)
  * All sorts of list related functions for all of the lists        *
  *******************************************************************/
 
-static __inline__ void remove_from_cl_list(blockinfo* bi)
+STATIC_INLINE void remove_from_cl_list(blockinfo* bi)
 {
     uae_u32 cl=cacheline(bi->pc_p);
 
@@ -195,7 +193,7 @@ static __inline__ void remove_from_cl_list(blockinfo* bi)
        cache_tags[cl].handler=popall_execute_normal;
 }
 
-static __inline__ void remove_from_list(blockinfo* bi)
+STATIC_INLINE void remove_from_list(blockinfo* bi)
 {
     if (bi->prev_p)
        *(bi->prev_p)=bi->next;
@@ -203,13 +201,13 @@ static __inline__ void remove_from_list(blockinfo* bi)
        bi->next->prev_p=bi->prev_p;
 }
 
-static __inline__ void remove_from_lists(blockinfo* bi)
+STATIC_INLINE void remove_from_lists(blockinfo* bi)
 {
     remove_from_list(bi);
     remove_from_cl_list(bi);
 }
 
-static __inline__ void add_to_cl_list(blockinfo* bi)
+STATIC_INLINE void add_to_cl_list(blockinfo* bi)
 {
     uae_u32 cl=cacheline(bi->pc_p);
 
@@ -223,13 +221,13 @@ static __inline__ void add_to_cl_list(blockinfo* bi)
     cache_tags[cl].handler=bi->handler_to_use;
 }
 
-static __inline__ void raise_in_cl_list(blockinfo* bi)
+STATIC_INLINE void raise_in_cl_list(blockinfo* bi)
 {
     remove_from_cl_list(bi);
     add_to_cl_list(bi);
 }
 
-static __inline__ void add_to_active(blockinfo* bi)
+STATIC_INLINE void add_to_active(blockinfo* bi)
 {
     if (active)
        active->prev_p=&(bi->next);
@@ -239,7 +237,7 @@ static __inline__ void add_to_active(blockinfo* bi)
     bi->prev_p=&active;
 }
 
-static __inline__ void add_to_dormant(blockinfo* bi)
+STATIC_INLINE void add_to_dormant(blockinfo* bi)
 {
     if (dormant)
        dormant->prev_p=&(bi->next);
@@ -249,7 +247,7 @@ static __inline__ void add_to_dormant(blockinfo* bi)
     bi->prev_p=&dormant;
 }
 
-static __inline__ void remove_dep(dependency* d)
+STATIC_INLINE void remove_dep(dependency* d)
 {
     if (d->prev_p)
        *(d->prev_p)=d->next;
@@ -261,13 +259,13 @@ static __inline__ void remove_dep(dependency* d)
 
 /* This block's code is about to be thrown away, so it no longer
    depends on anything else */
-static __inline__ void remove_deps(blockinfo* bi)
+STATIC_INLINE void remove_deps(blockinfo* bi)
 {
     remove_dep(&(bi->dep[0]));
     remove_dep(&(bi->dep[1]));
 }
 
-static __inline__ void adjust_jmpdep(dependency* d, void* a)
+STATIC_INLINE void adjust_jmpdep(dependency* d, void* a)
 {
     *(d->jmp_off)=(uae_u32)a-((uae_u32)d->jmp_off+4);
 }
@@ -276,16 +274,16 @@ static __inline__ void adjust_jmpdep(dependency* d, void* a)
  * Soft flush handling support functions                            *
  ********************************************************************/
 
-static __inline__ void set_dhtu(blockinfo* bi, void* dh)
+STATIC_INLINE void set_dhtu(blockinfo* bi, void* dh)
 {
-    //printf("bi is %p\n",bi);
+    //write_log("JIT: bi is %p\n",bi);
     if (dh!=bi->direct_handler_to_use) {
        dependency* x=bi->deplist;
-       //printf("bi->deplist=%p\n",bi->deplist);
+       //write_log("JIT: bi->deplist=%p\n",bi->deplist);
        while (x) {
-           //printf("x is %p\n",x);
-           //printf("x->next is %p\n",x->next);
-           //printf("x->prev_p is %p\n",x->prev_p);
+           //write_log("JIT: x is %p\n",x);
+           //write_log("JIT: x->next is %p\n",x->next);
+           //write_log("JIT: x->prev_p is %p\n",x->prev_p);
 
            if (x->jmp_off) {
                adjust_jmpdep(x,dh);
@@ -296,7 +294,7 @@ static __inline__ void set_dhtu(blockinfo* bi, void* dh)
     }
 }
 
-static __inline__ void invalidate_block(blockinfo* bi)
+STATIC_INLINE void invalidate_block(blockinfo* bi)
 {
     int i;
 
@@ -315,12 +313,12 @@ static __inline__ void invalidate_block(blockinfo* bi)
     remove_deps(bi);
 }
 
-static __inline__ void create_jmpdep(blockinfo* bi, int i, uae_u32* jmpaddr, uae_u32 target)
+STATIC_INLINE void create_jmpdep(blockinfo* bi, int i, uae_u32* jmpaddr, uae_u32 target)
 {
     blockinfo*  tbi=get_blockinfo_addr((void*)target);
 
     Dif(!tbi) {
-       printf("Could not create jmpdep!\n");
+       write_log("JIT: Could not create jmpdep!\n");
        abort();
     }
     bi->dep[i].jmp_off=jmpaddr;
@@ -332,7 +330,7 @@ static __inline__ void create_jmpdep(blockinfo* bi, int i, uae_u32* jmpaddr, uae
     tbi->deplist=&(bi->dep[i]);
 }
 
-static __inline__ void big_to_small_state(bigstate* b, smallstate* s)
+STATIC_INLINE void big_to_small_state(bigstate* b, smallstate* s)
 {
     int i;
     int count=0;
@@ -349,13 +347,13 @@ static __inline__ void big_to_small_state(bigstate* b, smallstate* s)
            count++;
        }
     }
-    printf("count=%d\n",count);
+    write_log("JIT: count=%d\n",count);
     for (i=0;i<N_REGS;i++) {  // FIXME --- don't do dirty yet
        s->nat[i].dirtysize=0;
     }
 }
 
-static __inline__ void attached_state(blockinfo* bi)
+STATIC_INLINE void attached_state(blockinfo* bi)
 {
     bi->havestate=1;
     if (bi->direct_handler_to_use==bi->direct_handler)
@@ -364,7 +362,7 @@ static __inline__ void attached_state(blockinfo* bi)
     bi->status=BI_TARGETTED;
 }
 
-static __inline__ blockinfo* get_blockinfo_addr_new(void* addr, int setstate)
+STATIC_INLINE blockinfo* get_blockinfo_addr_new(void* addr, int setstate)
 {
     blockinfo*  bi=get_blockinfo_addr(addr);
     int i;
@@ -389,7 +387,7 @@ static __inline__ blockinfo* get_blockinfo_addr_new(void* addr, int setstate)
        }
     }
     if (!bi) {
-       write_log ("Looking for blockinfo, can't find free one\n");
+       write_log ("JIT: Looking for blockinfo, can't find free one\n");
        abort();
     }
 
@@ -405,7 +403,7 @@ static __inline__ blockinfo* get_blockinfo_addr_new(void* addr, int setstate)
 
 static void prepare_block(blockinfo* bi);
 
-static __inline__ void alloc_blockinfos(void)
+STATIC_INLINE void alloc_blockinfos(void)
 {
     int i;
     blockinfo* bi;
@@ -476,22 +474,22 @@ void check_prefs_changed_comp (void)
     if (!currprefs.compforcesettings && !have_done_picasso) {
        int stop=0;
        if (currprefs.comptrustbyte!=0 && currprefs.comptrustbyte!=3)
-           stop = 1, write_log("<JIT compiler> : comptrustbyte is not 'direct' or 'afterpic'\n");
+           stop = 1, write_log("JIT: comptrustbyte is not 'direct' or 'afterpic'\n");
        if (currprefs.comptrustword!=0 && currprefs.comptrustword!=3)
-           stop = 1, write_log("<JIT compiler> : comptrustword is not 'direct' or 'afterpic'\n");
+           stop = 1, write_log("JIT: comptrustword is not 'direct' or 'afterpic'\n");
        if (currprefs.comptrustlong!=0 && currprefs.comptrustlong!=3)
-           stop = 1, write_log("<JIT compiler> : comptrustlong is not 'direct' or 'afterpic'\n");
+           stop = 1, write_log("JIT: comptrustlong is not 'direct' or 'afterpic'\n");
        if (currprefs.comptrustnaddr!=0 && currprefs.comptrustnaddr!=3)
-           stop = 1, write_log("<JIT compiler> : comptrustnaddr is not 'direct' or 'afterpic'\n");
+           stop = 1, write_log("JIT: comptrustnaddr is not 'direct' or 'afterpic'\n");
        if (currprefs.compnf!=1)
-           stop = 1, write_log("<JIT compiler> : compnf is not 'yes'\n");
+           stop = 1, write_log("JIT: compnf is not 'yes'\n");
        if (currprefs.cachesize<1024)
-           stop = 1, write_log("<JIT compiler> : cachesize is less than 1024\n");
+           stop = 1, write_log("JIT: cachesize is less than 1024\n");
        if (currprefs.comp_hardflush)
-           stop = 1, write_log("<JIT compiler> : comp_flushmode is 'hard'\n");
+           stop = 1, write_log("JIT: comp_flushmode is 'hard'\n");
        if (!canbang)
-           stop = 1, write_log("<JIT compiler> : Cannot use most direct memory access,\n"
-                               "                 and unable to recover from failed guess!\n");
+           stop = 1, write_log("JIT: Cannot use most direct memory access,\n"
+                               "     and unable to recover from failed guess!\n");
 #if 0
        if (stop) {
            gui_message("JIT: Configuration problems were detected!\n"
@@ -512,6 +510,7 @@ void check_prefs_changed_comp (void)
  ********************************************************************/
 
 #include "compemu_optimizer.c"
+#include "compemu_optimizer_x86.c"
 
 /********************************************************************
  * Functions to emit data into memory, and other general support    *
@@ -523,24 +522,24 @@ static  void emit_init(void)
 {
 }
 
-static __inline__ void emit_byte(uae_u8 x)
+STATIC_INLINE void emit_byte(uae_u8 x)
 {
     *target++=x;
 }
 
-static __inline__ void emit_word(uae_u16 x)
+STATIC_INLINE void emit_word(uae_u16 x)
 {
     *((uae_u16*)target)=x;
     target+=2;
 }
 
-static __inline__ void emit_long(uae_u32 x)
+STATIC_INLINE void emit_long(uae_u32 x)
 {
     *((uae_u32*)target)=x;
     target+=4;
 }
 
-static __inline__ uae_u32 reverse32(uae_u32 oldv)
+STATIC_INLINE uae_u32 reverse32(uae_u32 oldv)
 {
     return ((oldv>>24)&0xff) | ((oldv>>8)&0xff00) |
        ((oldv<<8)&0xff0000) | ((oldv<<24)&0xff000000);
@@ -553,12 +552,12 @@ void set_target(uae_u8* t)
     target=t;
 }
 
-static __inline__ uae_u8* get_target_noopt(void)
+STATIC_INLINE uae_u8* get_target_noopt(void)
 {
     return target;
 }
 
-__inline__ uae_u8* get_target(void)
+STATIC_INLINE uae_u8* get_target(void)
 {
     lopt_emit_all();
     return get_target_noopt();
@@ -583,7 +582,7 @@ static void make_flags_live_internal(void)
     if (live.flags_in_flags==VALID)
        return;
     Dif (live.flags_on_stack==TRASH) {
-       printf("Want flags, got something on stack, but it is TRASH\n");
+       write_log("JIT: Want flags, got something on stack, but it is TRASH\n");
        abort();
     }
     if (live.flags_on_stack==VALID) {
@@ -595,7 +594,7 @@ static void make_flags_live_internal(void)
        live.flags_in_flags=VALID;
        return;
     }
-    printf("Huh? live.flags_in_flags=%d, live.flags_on_stack=%d, but need to make live\n",
+    write_log("JIT: Huh? live.flags_in_flags=%d, live.flags_on_stack=%d, but need to make live\n",
           live.flags_in_flags,live.flags_on_stack);
     abort();
 }
@@ -619,7 +618,7 @@ static void flags_to_stack(void)
     live.flags_on_stack=VALID;
 }
 
-static __inline__ void clobber_flags(void)
+STATIC_INLINE void clobber_flags(void)
 {
     if (live.flags_in_flags==VALID && live.flags_on_stack!=VALID)
        flags_to_stack();
@@ -627,7 +626,7 @@ static __inline__ void clobber_flags(void)
 }
 
 /* Prepare for leaving the compiled stuff */
-static __inline__ void flush_flags(void)
+STATIC_INLINE void flush_flags(void)
 {
     flags_to_stack();
     return;
@@ -647,7 +646,7 @@ static uae_s8 nstate[N_REGS];
 #define L_NEEDED -2
 #define L_UNNEEDED -3
 
-static __inline__ void log_startblock(void)
+STATIC_INLINE void log_startblock(void)
 {
     int i;
     for (i=0;i<VREGS;i++)
@@ -656,13 +655,13 @@ static __inline__ void log_startblock(void)
        nstate[i]=L_UNKNOWN;
 }
 
-static __inline__ void log_isused(int n)
+STATIC_INLINE void log_isused(int n)
 {
     if (nstate[n]==L_UNKNOWN)
        nstate[n]=L_UNAVAIL;
 }
 
-static __inline__ void log_isreg(int n, int r)
+STATIC_INLINE void log_isreg(int n, int r)
 {
     if (nstate[n]==L_UNKNOWN)
        nstate[n]=r;
@@ -670,7 +669,7 @@ static __inline__ void log_isreg(int n, int r)
        vstate[r]=L_NEEDED;
 }
 
-static __inline__ void log_clobberreg(int r)
+STATIC_INLINE void log_clobberreg(int r)
 {
     if (vstate[r]==L_UNKNOWN)
        vstate[r]=L_UNNEEDED;
@@ -678,7 +677,7 @@ static __inline__ void log_clobberreg(int r)
 
 /* This ends all possibility of clever register allocation */
 
-static __inline__ void log_flush(void)
+STATIC_INLINE void log_flush(void)
 {
     int i;
     for (i=0;i<VREGS;i++)
@@ -689,7 +688,7 @@ static __inline__ void log_flush(void)
            nstate[i]=L_UNAVAIL;
 }
 
-static __inline__ void log_dump(void)
+STATIC_INLINE void log_dump(void)
 {
     int i;
 
@@ -713,7 +712,7 @@ static __inline__ void log_dump(void)
  * register status handling. EMIT TIME!                             *
  ********************************************************************/
 
-static __inline__ void set_status(int r, int status)
+STATIC_INLINE void set_status(int r, int status)
 {
     if (status==ISCONST)
        log_clobberreg(r);
@@ -721,12 +720,12 @@ static __inline__ void set_status(int r, int status)
 }
 
 
-static __inline__ int isinreg(int r)
+STATIC_INLINE int isinreg(int r)
 {
     return live.state[r].status==CLEAN || live.state[r].status==DIRTY;
 }
 
-static __inline__ void adjust_nreg(int r, uae_u32 val)
+STATIC_INLINE void adjust_nreg(int r, uae_u32 val)
 {
     if (!val)
        return;
@@ -741,7 +740,7 @@ static  void tomem(int r)
        if (live.state[r].val &&
            live.nat[rr].nholds==1 &&
            !live.nat[rr].locked) {
-           // printf("RemovingA offset %x from reg %d (%d) at %p\n",
+           // write_log("JIT: RemovingA offset %x from reg %d (%d) at %p\n",
            //   live.state[r].val,r,rr,target);
            adjust_nreg(rr,live.state[r].val);
            live.state[r].val=0;
@@ -762,7 +761,7 @@ static  void tomem(int r)
     }
 }
 
-static __inline__ int isconst(int r)
+STATIC_INLINE int isconst(int r)
 {
     return live.state[r].status==ISCONST;
 }
@@ -772,12 +771,12 @@ int is_const(int r)
     return isconst(r);
 }
 
-static __inline__ void writeback_const(int r)
+STATIC_INLINE void writeback_const(int r)
 {
     if (!isconst(r))
        return;
     Dif (live.state[r].needflush==NF_HANDLER) {
-       write_log ("Trying to write back constant NF_HANDLER!\n");
+       write_log ("JIT: Trying to write back constant NF_HANDLER!\n");
        abort();
     }
 
@@ -786,7 +785,7 @@ static __inline__ void writeback_const(int r)
     set_status(r,INMEM);
 }
 
-static __inline__ void tomem_c(int r)
+STATIC_INLINE void tomem_c(int r)
 {
     if (isconst(r)) {
        writeback_const(r);
@@ -806,7 +805,7 @@ static  void evict(int r)
 
     Dif (live.nat[rr].locked &&
        live.nat[rr].nholds==1) {
-       write_log ("register %d in nreg %d is locked!\n",r,live.state[r].realreg);
+       write_log ("JIT: register %d in nreg %d is locked!\n",r,live.state[r].realreg);
        abort();
     }
 
@@ -821,7 +820,7 @@ static  void evict(int r)
     set_status(r,INMEM);
 }
 
-static __inline__ void free_nreg(int r)
+STATIC_INLINE void free_nreg(int r)
 {
     int i=live.nat[r].nholds;
 
@@ -833,13 +832,13 @@ static __inline__ void free_nreg(int r)
        evict(vr);
     }
     Dif (live.nat[r].nholds!=0) {
-       printf("Failed to free nreg %d, nholds is %d\n",r,live.nat[r].nholds);
+       write_log("JIT: Failed to free nreg %d, nholds is %d\n",r,live.nat[r].nholds);
        abort();
     }
 }
 
 /* Use with care! */
-static __inline__ void isclean(int r)
+STATIC_INLINE void isclean(int r)
 {
     if (!isinreg(r))
        return;
@@ -849,20 +848,20 @@ static __inline__ void isclean(int r)
     set_status(r,CLEAN);
 }
 
-static __inline__ void disassociate(int r)
+STATIC_INLINE void disassociate(int r)
 {
     isclean(r);
     evict(r);
 }
 
-static __inline__ void set_const(int r, uae_u32 val)
+STATIC_INLINE void set_const(int r, uae_u32 val)
 {
     disassociate(r);
     live.state[r].val=val;
     set_status(r,ISCONST);
 }
 
-static __inline__ uae_u32 get_offset(int r)
+STATIC_INLINE uae_u32 get_offset(int r)
 {
     return live.state[r].val;
 }
@@ -1034,7 +1033,7 @@ static void mov_nregs(int d, int s)
 }
 
 
-static __inline__ void make_exclusive(int r, int size, int spec)
+STATIC_INLINE void make_exclusive(int r, int size, int spec)
 {
     reg_status oldstate;
     int rr=live.state[r].realreg;
@@ -1063,7 +1062,7 @@ static __inline__ void make_exclusive(int r, int size, int spec)
            }
        }
        Dif (live.nat[rr].nholds!=1) {
-           printf("natreg %d holds %d vregs, %d not exclusive\n",
+           write_log("JIT: natreg %d holds %d vregs, %d not exclusive\n",
                   rr,live.nat[rr].nholds,r);
            abort();
        }
@@ -1105,12 +1104,12 @@ static __inline__ void make_exclusive(int r, int size, int spec)
     unlock(rr);
 }
 
-static __inline__ void add_offset(int r, uae_u32 off)
+STATIC_INLINE void add_offset(int r, uae_u32 off)
 {
     live.state[r].val+=off;
 }
 
-static __inline__ void remove_offset(int r, int spec)
+STATIC_INLINE void remove_offset(int r, int spec)
 {
     int rr;
 
@@ -1125,7 +1124,7 @@ static __inline__ void remove_offset(int r, int spec)
        alloc_reg_hinted(r,4,0,spec);
 
     Dif (live.state[r].validsize!=4) {
-       printf("Validsize=%d in remove_offset\n",live.state[r].validsize);
+       write_log("JIT: Validsize=%d in remove_offset\n",live.state[r].validsize);
        abort();
     }
     make_exclusive(r,0,-1);
@@ -1136,7 +1135,7 @@ static __inline__ void remove_offset(int r, int spec)
     rr=live.state[r].realreg;
 
     if (live.nat[rr].nholds==1) {
-       //printf("RemovingB offset %x from reg %d (%d) at %p\n",
+       //write_log("JIT: RemovingB offset %x from reg %d (%d) at %p\n",
        //       live.state[r].val,r,rr,target);
        adjust_nreg(rr,live.state[r].val);
        live.state[r].dirtysize=4;
@@ -1144,7 +1143,7 @@ static __inline__ void remove_offset(int r, int spec)
        set_status(r,DIRTY);
        return;
     }
-    printf("Failed in remove_offset\n");
+    write_log("JIT: Failed in remove_offset\n");
     abort();
 }
 
@@ -1156,13 +1155,13 @@ STATIC_INLINE void remove_all_offsets(void)
        remove_offset(i,-1);
 }
 
-static __inline__ int readreg_general(int r, int size, int spec, int can_offset)
+STATIC_INLINE int readreg_general(int r, int size, int spec, int can_offset)
 {
     int n;
     int answer=-1;
 
     if (live.state[r].status==UNDEF) {
-      printf("WARNING: Unexpected read of undefined register %d\n",r);
+       write_log("JIT: WARNING: Unexpected read of undefined register %d\n",r);
     }
     if (!can_offset)
        remove_offset(r,spec);
@@ -1222,7 +1221,7 @@ static int readreg_offset(int r, int size)
 }
 
 
-static __inline__ int writereg_general(int r, int size, int spec)
+STATIC_INLINE int writereg_general(int r, int size, int spec)
 {
     int n;
     int answer=-1;
@@ -1285,7 +1284,7 @@ static __inline__ int writereg_general(int r, int size, int spec)
     }
     else {
        Dif (live.state[r].val) {
-           printf("Problem with val\n");
+           write_log("JIT: Problem with val\n");
            abort();
        }
     }
@@ -1303,19 +1302,19 @@ static int writereg_specific(int r, int size, int spec)
     return writereg_general(r,size,spec);
 }
 
-static __inline__ int rmw_general(int r, int wsize, int rsize, int spec)
+STATIC_INLINE int rmw_general(int r, int wsize, int rsize, int spec)
 {
     int n;
     int answer=-1;
 
     if (live.state[r].status==UNDEF) {
-      printf("WARNING: Unexpected read of undefined register %d\n",r);
+       write_log("JIT: WARNING: Unexpected read of undefined register %d\n",r);
     }
     remove_offset(r,spec);
     make_exclusive(r,0,spec);
 
     Dif (wsize<rsize) {
-       printf("Cannot handle wsize<rsize in rmw_general()\n");
+       write_log("JIT: Cannot handle wsize<rsize in rmw_general()\n");
        abort();
     }
     if (isinreg(r) && live.state[r].validsize>=rsize) {
@@ -1363,7 +1362,7 @@ static __inline__ int rmw_general(int r, int wsize, int rsize, int spec)
     live.nat[answer].touched=touchcnt++;
 
     Dif (live.state[r].val) {
-       printf("Problem with val(rmw)\n");
+       write_log("JIT: Problem with val(rmw)\n");
        abort();
     }
     return answer;
@@ -1420,7 +1419,7 @@ static  void f_tomem_drop(int r)
 }
 
 
-static __inline__ int f_isinreg(int r)
+STATIC_INLINE int f_isinreg(int r)
 {
     return live.fate[r].status==CLEAN || live.fate[r].status==DIRTY;
 }
@@ -1439,7 +1438,7 @@ static void f_evict(int r)
 
     Dif (live.fat[rr].locked &&
        live.fat[rr].nholds==1) {
-       write_log ("FPU register %d in nreg %d is locked!\n",r,live.fate[r].realreg);
+       write_log ("JIT: FPU register %d in nreg %d is locked!\n",r,live.fate[r].realreg);
        abort();
     }
 
@@ -1454,7 +1453,7 @@ static void f_evict(int r)
     live.fate[r].realreg=-1;
 }
 
-static __inline__ void f_free_nreg(int r)
+STATIC_INLINE void f_free_nreg(int r)
 {
     int i=live.fat[r].nholds;
 
@@ -1466,21 +1465,21 @@ static __inline__ void f_free_nreg(int r)
        f_evict(vr);
     }
     Dif (live.fat[r].nholds!=0) {
-       printf("Failed to free nreg %d, nholds is %d\n",r,live.fat[r].nholds);
+       write_log("JIT: Failed to free nreg %d, nholds is %d\n",r,live.fat[r].nholds);
        abort();
     }
 }
 
 
 /* Use with care! */
-static __inline__ void f_isclean(int r)
+STATIC_INLINE void f_isclean(int r)
 {
     if (!f_isinreg(r))
        return;
     live.fate[r].status=CLEAN;
 }
 
-static __inline__ void f_disassociate(int r)
+STATIC_INLINE void f_disassociate(int r)
 {
     f_isclean(r);
     f_evict(r);
@@ -1552,7 +1551,7 @@ static  void f_setlock(int r)
     live.fat[r].locked++;
 }
 
-static __inline__ int f_readreg(int r)
+STATIC_INLINE int f_readreg(int r)
 {
     int n;
     int answer=-1;
@@ -1571,7 +1570,7 @@ static __inline__ int f_readreg(int r)
     return answer;
 }
 
-static __inline__ void f_make_exclusive(int r, int clobber)
+STATIC_INLINE void f_make_exclusive(int r, int clobber)
 {
     freg_status oldstate;
     int rr=live.fate[r].realreg;
@@ -1599,13 +1598,13 @@ static __inline__ void f_make_exclusive(int r, int clobber)
            }
        }
        Dif (live.fat[rr].nholds!=1) {
-           printf("realreg %d holds %d (",rr,live.fat[rr].nholds);
+           write_log("JIT: realreg %d holds %d (",rr,live.fat[rr].nholds);
            for (i=0;i<live.fat[rr].nholds;i++) {
-               printf(" %d(%d,%d)",live.fat[rr].holds[i],
+               write_log("JIT: %d(%d,%d)",live.fat[rr].holds[i],
                       live.fate[live.fat[rr].holds[i]].realreg,
                       live.fate[live.fat[rr].holds[i]].realind);
            }
-           printf("\n");
+           write_log("\n");
            abort();
        }
        return;
@@ -1629,7 +1628,7 @@ static __inline__ void f_make_exclusive(int r, int clobber)
 }
 
 
-static __inline__ int f_writereg(int r)
+STATIC_INLINE int f_writereg(int r)
 {
     int n;
     int answer=-1;
@@ -1716,23 +1715,37 @@ MIDFUNC(0,dont_care_flags,(void))
 MENDFUNC(0,dont_care_flags,(void))
 
 
+/*
+ * Copy m68k C flag into m68k X flag
+ *
+ * FIXME: This needs to be moved into the machdep
+ * part of the source because it depends on what bit
+ * is used to hold X.
+ */
 MIDFUNC(0,duplicate_carry,(void))
 {
     evict(FLAGX);
     make_flags_live_internal();
-    COMPCALL(setcc_m)((uae_u32)live.state[FLAGX].mem,2);
+    COMPCALL(setcc_m)((uae_u32)live.state[FLAGX].mem + 1,2);
 }
 MENDFUNC(0,duplicate_carry,(void))
 
+/*
+ * Set host C flag from m68k X flag.
+ *
+ * FIXME: This needs to be moved into the machdep
+ * part of the source because it depends on what bit
+ * is used to hold X.
+ */
 MIDFUNC(0,restore_carry,(void))
 {
     if (!have_rat_stall) { /* Not a P6 core, i.e. no partial stalls */
-       bt_l_ri_noclobber(FLAGX,0);
+       bt_l_ri_noclobber(FLAGX, 8);
     }
     else {  /* Avoid the stall the above creates.
               This is slow on non-P6, though.
            */
-       COMPCALL(rol_b_ri(FLAGX,8));
+       COMPCALL(rol_w_ri(FLAGX, 8));
        isclean(FLAGX);
        /* Why is the above faster than the below? */
        //raw_rol_b_mi((uae_u32)live.state[FLAGX].mem,8);
@@ -1949,7 +1962,7 @@ MIDFUNC(2,rol_l_rr,(RW4 d, R1 r))
     r=readreg_specific(r,1,SHIFTCOUNT_NREG);
     d=rmw(d,4,4);
     Dif (r!=1) {
-       write_log ("Illegal register %d in raw_rol_b\n",r);
+       write_log ("JIT: Illegal register %d in raw_rol_b\n",r);
        abort();
     }
     raw_rol_l_rr(d,r) ;
@@ -1969,7 +1982,7 @@ MIDFUNC(2,rol_w_rr,(RW2 d, R1 r))
     r=readreg_specific(r,1,SHIFTCOUNT_NREG);
     d=rmw(d,2,2);
     Dif (r!=1) {
-       write_log ("Illegal register %d in raw_rol_b\n",r);
+       write_log ("JIT: Illegal register %d in raw_rol_b\n",r);
        abort();
     }
     raw_rol_w_rr(d,r) ;
@@ -1990,7 +2003,7 @@ MIDFUNC(2,rol_b_rr,(RW1 d, R1 r))
     r=readreg_specific(r,1,SHIFTCOUNT_NREG);
     d=rmw(d,1,1);
     Dif (r!=1) {
-       write_log ("Illegal register %d in raw_rol_b\n",r);
+       write_log ("JIT: Illegal register %d in raw_rol_b\n",r);
        abort();
     }
     raw_rol_b_rr(d,r) ;
@@ -2010,7 +2023,7 @@ MIDFUNC(2,shll_l_rr,(RW4 d, R1 r))
     r=readreg_specific(r,1,SHIFTCOUNT_NREG);
     d=rmw(d,4,4);
     Dif (r!=1) {
-       write_log ("Illegal register %d in raw_rol_b\n",r);
+       write_log ("JIT: Illegal register %d in raw_rol_b\n",r);
        abort();
     }
     raw_shll_l_rr(d,r) ;
@@ -2030,7 +2043,7 @@ MIDFUNC(2,shll_w_rr,(RW2 d, R1 r))
     r=readreg_specific(r,1,SHIFTCOUNT_NREG);
     d=rmw(d,2,2);
     Dif (r!=1) {
-       write_log ("Illegal register %d in raw_shll_b\n",r);
+       write_log ("JIT: Illegal register %d in raw_shll_b\n",r);
        abort();
     }
     raw_shll_w_rr(d,r) ;
@@ -2051,7 +2064,7 @@ MIDFUNC(2,shll_b_rr,(RW1 d, R1 r))
     r=readreg_specific(r,1,SHIFTCOUNT_NREG);
     d=rmw(d,1,1);
     Dif (r!=1) {
-       write_log ("Illegal register %d in raw_shll_b\n",r);
+       write_log ("JIT: Illegal register %d in raw_shll_b\n",r);
        abort();
     }
     raw_shll_b_rr(d,r) ;
@@ -2150,7 +2163,7 @@ MIDFUNC(2,shrl_l_rr,(RW4 d, R1 r))
     r=readreg_specific(r,1,SHIFTCOUNT_NREG);
     d=rmw(d,4,4);
     Dif (r!=1) {
-       write_log ("Illegal register %d in raw_rol_b\n",r);
+       write_log ("JIT: Illegal register %d in raw_rol_b\n",r);
        abort();
     }
     raw_shrl_l_rr(d,r) ;
@@ -2170,7 +2183,7 @@ MIDFUNC(2,shrl_w_rr,(RW2 d, R1 r))
     r=readreg_specific(r,1,SHIFTCOUNT_NREG);
     d=rmw(d,2,2);
     Dif (r!=1) {
-       write_log ("Illegal register %d in raw_shrl_b\n",r);
+       write_log ("JIT: Illegal register %d in raw_shrl_b\n",r);
        abort();
     }
     raw_shrl_w_rr(d,r) ;
@@ -2191,7 +2204,7 @@ MIDFUNC(2,shrl_b_rr,(RW1 d, R1 r))
     r=readreg_specific(r,1,SHIFTCOUNT_NREG);
     d=rmw(d,1,1);
     Dif (r!=1) {
-       write_log ("Illegal register %d in raw_shrl_b\n",r);
+       write_log ("JIT: Illegal register %d in raw_shrl_b\n",r);
        abort();
     }
     raw_shrl_b_rr(d,r) ;
@@ -2317,7 +2330,7 @@ MIDFUNC(2,shra_l_rr,(RW4 d, R1 r))
     r=readreg_specific(r,1,SHIFTCOUNT_NREG);
     d=rmw(d,4,4);
     Dif (r!=1) {
-       write_log ("Illegal register %d in raw_rol_b\n",r);
+       write_log ("JIT: Illegal register %d in raw_rol_b\n",r);
        abort();
     }
     raw_shra_l_rr(d,r) ;
@@ -2337,7 +2350,7 @@ MIDFUNC(2,shra_w_rr,(RW2 d, R1 r))
     r=readreg_specific(r,1,SHIFTCOUNT_NREG);
     d=rmw(d,2,2);
     Dif (r!=1) {
-       write_log ("Illegal register %d in raw_shra_b\n",r);
+       write_log ("JIT: Illegal register %d in raw_shra_b\n",r);
        abort();
     }
     raw_shra_w_rr(d,r) ;
@@ -2358,7 +2371,7 @@ MIDFUNC(2,shra_b_rr,(RW1 d, R1 r))
     r=readreg_specific(r,1,SHIFTCOUNT_NREG);
     d=rmw(d,1,1);
     Dif (r!=1) {
-       write_log ("Illegal register %d in raw_shra_b\n",r);
+       write_log ("JIT: Illegal register %d in raw_shra_b\n",r);
        abort();
     }
     raw_shra_b_rr(d,r) ;
@@ -2406,8 +2419,8 @@ MIDFUNC(1,setzflg_l,(RW4 r))
        }
        else {
                Dif (live.flags_in_flags!=VALID) {
-                       write_log("setzflg() wanted flags in native flags, they are %d\n",
-                                         live.flags_in_flags);
+                       write_log("JIT: setzflg() wanted flags in native flags, they are %d\n",
+                           live.flags_in_flags);
                        abort();
                }
                r=readreg(r,4);
@@ -3057,7 +3070,7 @@ MIDFUNC(3,mov_b_bRr,(R4 d, R1 s, IMM offset))
 }
 MENDFUNC(3,mov_b_bRr,(R4 d, R1 s, IMM offset))
 
-MIDFUNC(1,bswap_32,(RW4 r))
+MIDFUNC(1,gen_bswap_32,(RW4 r))
 {
     int reg=r;
 
@@ -3072,9 +3085,9 @@ MIDFUNC(1,bswap_32,(RW4 r))
     raw_bswap_32(r);
     unlock(r);
 }
-MENDFUNC(1,bswap_32,(RW4 r))
+MENDFUNC(1,gen_bswap_32,(RW4 r))
 
-MIDFUNC(1,bswap_16,(RW2 r))
+MIDFUNC(1,gen_bswap_16,(RW2 r))
 {
     if (isconst(r)) {
        uae_u32 oldv=live.state[r].val;
@@ -3089,7 +3102,7 @@ MIDFUNC(1,bswap_16,(RW2 r))
     raw_bswap_16(r);
     unlock(r);
 }
-MENDFUNC(1,bswap_16,(RW2 r))
+MENDFUNC(1,gen_bswap_16,(RW2 r))
 
 
 
@@ -3119,7 +3132,7 @@ MIDFUNC(2,mov_l_rr,(W4 d, R4 s))
     live.nat[s].nholds++;
     log_clobberreg(d);
 
-    /* printf("Added %d to nreg %d(%d), now holds %d regs\n",
+    /* write_log("JIT: Added %d to nreg %d(%d), now holds %d regs\n",
        d,s,live.state[d].realind,live.nat[s].nholds); */
     unlock(s);
 #else
@@ -4408,7 +4421,7 @@ uae_u32 get_const(int r)
     if (!reg_alloc_run)
 #endif
        Dif (!isconst(r)) {
-           printf("Register %d should be constant, but isn't\n",r);
+           write_log("JIT: Register %d should be constant, but isn't\n",r);
            abort();
        }
     return live.state[r].val;
@@ -4463,11 +4476,11 @@ void init_comp(void)
     live.state[PC_P].needflush=NF_TOMEM;
     set_const(PC_P,(uae_u32)comp_pc_p);
 
-    live.state[FLAGX].mem=&(regflags.x);
+    live.state[FLAGX].mem=&(regs.ccrflags.x);
     live.state[FLAGX].needflush=NF_TOMEM;
     set_status(FLAGX,INMEM);
 
-    live.state[FLAGTMP].mem=&(regflags.cznv);
+    live.state[FLAGTMP].mem=&(regs.ccrflags.cznv);
     live.state[FLAGTMP].needflush=NF_TOMEM;
     set_status(FLAGTMP,INMEM);
 
@@ -4525,7 +4538,7 @@ static void vinton(int i, uae_s8* vton, int depth)
     int rr;
 
     Dif (vton[i]==-1) {
-       printf("Asked to load register %d, but nowhere to go\n",i);
+       write_log("JIT: Asked to load register %d, but nowhere to go\n",i);
        abort();
     }
     n=vton[i];
@@ -4544,7 +4557,7 @@ static void vinton(int i, uae_s8* vton, int depth)
 #if USE_MATCHSTATE
 /* This is going to be, amongst other things, a more elaborate version of
    flush() */
-static __inline__ void match_states(smallstate* s)
+STATIC_INLINE void match_states(smallstate* s)
 {
     uae_s8 vton[VREGS];
     uae_s8 ndone[N_REGS];
@@ -4609,7 +4622,7 @@ static __inline__ void match_states(smallstate* s)
         case UNDEF:
            break;
         default:
-           printf("Weird status: %d\n",live.state[i].status);
+           write_log("JIT: Weird status: %d\n",live.state[i].status);
            abort();
        }
     }
@@ -4620,12 +4633,12 @@ static __inline__ void match_states(smallstate* s)
            int n=live.state[i].realreg;
 
            if (live.nat[n].nholds!=1) {
-               printf("Register %d isn't alone in nreg %d\n",
+               write_log("JIT: Register %d isn't alone in nreg %d\n",
                       i,n);
                abort();
            }
            if (vton[i]==-1) {
-               printf("Register %d is still in register, shouldn't be\n",
+               write_log("JIT: Register %d is still in register, shouldn't be\n",
                       i);
                abort();
            }
@@ -4644,7 +4657,7 @@ static __inline__ void match_states(smallstate* s)
        int n=vton[i];
        if (n==-1) {
            Dif (isinreg(i)) {
-               printf("Register %d unexpectedly in nreg %d\n",
+               write_log("JIT: Register %d unexpectedly in nreg %d\n",
                       i,live.state[i].realreg);
                abort();
            }
@@ -4658,7 +4671,7 @@ static __inline__ void match_states(smallstate* s)
                break;
             case INMEM:
                Dif (live.nat[n].nholds) {
-                   printf("natreg %d holds %d vregs, should be empty\n",
+                   write_log("JIT: natreg %d holds %d vregs, should be empty\n",
                           n,live.nat[n].nholds);
                }
                raw_mov_l_rm(n,(uae_u32)live.state[i].mem);
@@ -4675,7 +4688,7 @@ static __inline__ void match_states(smallstate* s)
                break;
             case ISCONST:
                if (i!=PC_P) {
-                   printf("Got constant in matchstate for reg %d. Bad!\n",i);
+                   write_log("JIT: Got constant in matchstate for reg %d. Bad!\n",i);
                    abort();
                }
                break;
@@ -4719,7 +4732,7 @@ static __inline__ void match_states(smallstate* s)
     }
 }
 #else
-static __inline__ void match_states(smallstate* s)
+STATIC_INLINE void match_states(smallstate* s)
 {
     flush(1);
 }
@@ -4760,7 +4773,7 @@ void flush(int save_regs)
                 default: break;
                }
                Dif (live.state[i].val && i!=PC_P) {
-                   printf("Register %d still has val %x\n",
+                   write_log("JIT: Register %d still has val %x\n",
                           i,live.state[i].val);
                }
            }
@@ -4774,7 +4787,7 @@ void flush(int save_regs)
        raw_fp_cleanup_drop();
     }
     if (needflags) {
-       printf("Warning! flush with needflags=1!\n");
+       write_log("JIT: Warning! flush with needflags=1!\n");
     }
 
     lopt_emit_all();
@@ -4822,7 +4835,7 @@ void freescratch(void)
     int i;
     for (i=0;i<N_REGS;i++)
        if (live.nat[i].locked && i!=4)
-           printf("Warning! %d is locked\n",i);
+           write_log("JIT: Warning! %d is locked\n",i);
 
     for (i=0;i<VREGS;i++)
        if (live.state[i].needflush==NF_SCRATCH) {
@@ -4849,7 +4862,7 @@ static void align_target(uae_u32 a)
 }
 
 extern uae_u8* kickmemory;
-static __inline__ int isinrom(uae_u32 addr)
+STATIC_INLINE int isinrom(uae_u32 addr)
 {
     return (addr>=(uae_u32)kickmemory &&
            addr<(uae_u32)kickmemory+8*65536);
@@ -4953,8 +4966,8 @@ static void writemem_real(int address, int source, int offset, int size, int tmp
            f=source;
        switch(size) {
         case 1: mov_b_bRr(address,source,NATMEM_OFFSETX); break;
-        case 2: mov_w_rr(f,source); bswap_16(f); mov_w_bRr(address,f,NATMEM_OFFSETX); break;
-        case 4: mov_l_rr(f,source); bswap_32(f); mov_l_bRr(address,f,NATMEM_OFFSETX); break;
+        case 2: mov_w_rr(f,source); gen_bswap_16(f); mov_w_bRr(address,f,NATMEM_OFFSETX); break;
+        case 4: mov_l_rr(f,source); gen_bswap_32(f); mov_l_bRr(address,f,NATMEM_OFFSETX); break;
        }
        forget_about(tmp);
        forget_about(f);
@@ -4970,23 +4983,23 @@ static void writemem_real(int address, int source, int offset, int size, int tmp
         if (size > 1) {
            add_l(f,address); /* f now holds the final address */
            switch (size) {
-               case 2: bswap_16(source); mov_w_Rr(f,source,0);
-                       bswap_16(source); return;
-               case 4: bswap_32(source); mov_l_Rr(f,source,0);
-                       bswap_32(source); return;
+               case 2: gen_bswap_16(source); mov_w_Rr(f,source,0);
+                       gen_bswap_16(source); return;
+               case 4: gen_bswap_32(source); mov_l_Rr(f,source,0);
+                       gen_bswap_32(source); return;
            }
        }
     }
     switch (size) { /* f now holds the offset */
        case 1: mov_b_mrr_indexed(address,f,source); break;
-       case 2: bswap_16(source); mov_w_mrr_indexed(address,f,source);
-               bswap_16(source); break;           /* base, index, source */
-       case 4: bswap_32(source); mov_l_mrr_indexed(address,f,source);
-               bswap_32(source); break;
+       case 2: gen_bswap_16(source); mov_w_mrr_indexed(address,f,source);
+               gen_bswap_16(source); break;       /* base, index, source */
+       case 4: gen_bswap_32(source); mov_l_mrr_indexed(address,f,source);
+               gen_bswap_32(source); break;
     }
 }
 
-static __inline__ void writemem(int address, int source, int offset, int size, int tmp)
+STATIC_INLINE void writemem(int address, int source, int offset, int size, int tmp)
 {
     int f=tmp;
 
@@ -5017,7 +5030,7 @@ void writebyte(int address, int source, int tmp)
        writemem_real(address,source,20,1,tmp,0);
 }
 
-static __inline__ void writeword_general(int address, int source, int tmp,
+STATIC_INLINE void writeword_general(int address, int source, int tmp,
                                         int clobber)
 {
     int  distrust;
@@ -5045,7 +5058,7 @@ void writeword(int address, int source, int tmp)
     writeword_general(address,source,tmp,0);
 }
 
-static __inline__ void writelong_general(int address, int source, int tmp,
+STATIC_INLINE void writelong_general(int address, int source, int tmp,
                                         int clobber)
 {
     int  distrust;
@@ -5090,8 +5103,8 @@ static void readmem_real(int address, int dest, int offset, int size, int tmp)
     if (canbang) {  /* Woohoo! go directly at the memory! */
        switch(size) {
         case 1: mov_b_brR(dest,address,NATMEM_OFFSETX); break;
-        case 2: mov_w_brR(dest,address,NATMEM_OFFSETX); bswap_16(dest); break;
-        case 4: mov_l_brR(dest,address,NATMEM_OFFSETX); bswap_32(dest); break;
+        case 2: mov_w_brR(dest,address,NATMEM_OFFSETX); gen_bswap_16(dest); break;
+        case 4: mov_l_brR(dest,address,NATMEM_OFFSETX); gen_bswap_32(dest); break;
        }
        forget_about(tmp);
        return;
@@ -5105,15 +5118,15 @@ static void readmem_real(int address, int dest, int offset, int size, int tmp)
 
     switch(size) {
      case 1: mov_b_rrm_indexed(dest,address,f); break;
-     case 2: mov_w_rrm_indexed(dest,address,f); bswap_16(dest); break;
-     case 4: mov_l_rrm_indexed(dest,address,f); bswap_32(dest); break;
+     case 2: mov_w_rrm_indexed(dest,address,f); gen_bswap_16(dest); break;
+     case 4: mov_l_rrm_indexed(dest,address,f); gen_bswap_32(dest); break;
     }
     forget_about(tmp);
 }
 
 
 
-static __inline__ void readmem(int address, int dest, int offset, int size, int tmp)
+STATIC_INLINE void readmem(int address, int dest, int offset, int size, int tmp)
 {
     int f=tmp;
 
@@ -5181,12 +5194,12 @@ void readlong(int address, int dest, int tmp)
 
 
 /* This one might appear a bit odd... */
-static __inline__ void get_n_addr_old(int address, int dest, int tmp)
+STATIC_INLINE void get_n_addr_old(int address, int dest, int tmp)
 {
     readmem(address,dest,24,4,tmp);
 }
 
-static __inline__ void get_n_addr_real(int address, int dest, int tmp)
+STATIC_INLINE void get_n_addr_real(int address, int dest, int tmp)
 {
     int f=tmp;
     if (address!=dest)
@@ -5309,7 +5322,7 @@ void calc_disp_ea_020(int base, uae_u32 dp, int target, int tmp)
     forget_about(tmp);
 }
 
-static __inline__ unsigned int cft_map (unsigned int f)
+STATIC_INLINE unsigned int cft_map (unsigned int f)
 {
     return ((f >> 8) & 255) | ((f & 255) << 8);
 }
@@ -5358,8 +5371,6 @@ void alloc_cache(void)
     }
 }
 
-extern unsigned long op_illg_1 (uae_u32 opcode) REGPARAM;
-
 static void calc_checksum(blockinfo* bi, uae_u32* c1, uae_u32* c2)
 {
     uae_u32 k1=0;
@@ -5405,11 +5416,11 @@ static void show_checksum(blockinfo* bi)
     }
     else {
        while (len>0) {
-           printf("%08x ",*pos);
+           write_log("%08x ",*pos);
            pos++;
            len-=4;
        }
-       printf(" bla\n");
+       write_log(" bla\n");
     }
 }
 
@@ -5495,7 +5506,7 @@ static void check_checksum(void)
        bi->handler_to_use=bi->handler;
        set_dhtu(bi,bi->direct_handler);
 
-       /*      printf("reactivate %p/%p (%x %x/%x %x)\n",bi,bi->pc_p,
+       /*      write_log("JIT: reactivate %p/%p (%x %x/%x %x)\n",bi,bi->pc_p,
                c1,c2,bi->c1,bi->c2);*/
        remove_from_list(bi);
        add_to_active(bi);
@@ -5504,7 +5515,7 @@ static void check_checksum(void)
     else {
        /* This block actually changed. We need to invalidate it,
           and set it up to be recompiled */
-       /* printf("discard %p/%p (%x %x/%x %x)\n",bi,bi->pc_p,
+       /* write_log("JIT: discard %p/%p (%x %x/%x %x)\n",bi,bi->pc_p,
           c1,c2,bi->c1,bi->c2); */
        invalidate_block(bi);
        raise_in_cl_list(bi);
@@ -5513,7 +5524,7 @@ static void check_checksum(void)
 }
 
 
-static __inline__ void create_popalls(void)
+STATIC_INLINE void create_popalls(void)
 {
   int i,r;
 
@@ -5597,7 +5608,7 @@ static __inline__ void create_popalls(void)
   raw_jmp_m_indexed((uae_u32)cache_tags,r,4);
 }
 
-static __inline__ void reset_lists(void)
+STATIC_INLINE void reset_lists(void)
 {
     int i;
 
@@ -5648,11 +5659,11 @@ void build_comp(void)
     int i;
     int jumpcount=0;
     unsigned long opcode;
-    struct cputbl* tbl=op_smalltbl_0_comp_ff;
-    struct cputbl* nftbl=op_smalltbl_0_comp_nf;
+    const struct comptbl* tbl=op_smalltbl_0_comp_ff;
+    const struct comptbl* nftbl=op_smalltbl_0_comp_nf;
     int count;
 #ifdef NOFLAGS_SUPPORT
-    struct cputbl *nfctbl = (currprefs.cpu_level >= 4 ? op_smalltbl_0_nf
+    struct comptbl *nfctbl = (currprefs.cpu_level >= 4 ? op_smalltbl_0_nf
                             : currprefs.cpu_level == 3 ? op_smalltbl_1_nf
                             : currprefs.cpu_level == 2 ? op_smalltbl_2_nf
                             : currprefs.cpu_level == 1 ? op_smalltbl_3_nf
@@ -5669,7 +5680,7 @@ void build_comp(void)
     write_log ("JIT: Building Compiler function table\n");
     for (opcode = 0; opcode < 65536; opcode++) {
 #ifdef NOFLAGS_SUPPORT
-       nfcpufunctbl[opcode] = op_illg_1;
+       nfcpufunctbl[opcode] = op_illg;
 #endif
        compfunctbl[opcode] = NULL;
        nfcompfunctbl[opcode] = NULL;
@@ -5702,10 +5713,10 @@ void build_comp(void)
 #endif
 
     for (opcode = 0; opcode < 65536; opcode++) {
-       cpuop_func *f;
-       cpuop_func *nff;
+       compop_func *f;
+       compop_func *nff;
 #ifdef NOFLAGS_SUPPORT
-       cpuop_func *nfcf;
+       compop_func *nfcf;
 #endif
        int isjmp,isaddx,iscjmp;
 
@@ -5727,7 +5738,7 @@ void build_comp(void)
            compfunctbl[opcode] = f;
            nfcompfunctbl[opcode] = nff;
 #ifdef NOFLAGS_SUPPORT
-           Dif (nfcf == op_illg_1)
+           Dif (nfcf == op_illg)
                abort();
            nfcpufunctbl[opcode] = nfcf;
 #endif
@@ -5751,7 +5762,7 @@ void build_comp(void)
        if (compfunctbl[opcode])
            count++;
     }
-    write_log ("Supposedly %d compileable opcodes!\n",count);
+    write_log ("JIT: Supposedly %d compileable opcodes!\n",count);
 
     /* Initialise state */
     alloc_cache();
@@ -5785,7 +5796,7 @@ static void flush_icache_hard(int n)
 
     hard_flush_count++;
 #if 0
-    printf("Flush Icache_hard(%d/%x/%p), %u instruction bytes\n",
+    write_log("JIT: Flush Icache_hard(%d/%x/%p), %u instruction bytes\n",
           n,regs.pc,regs.pc_p,current_compile_p-compiled_code);
 #endif
     bi=active;
@@ -5805,7 +5816,7 @@ static void flush_icache_hard(int n)
     if (!compiled_code)
        return;
     current_compile_p=compiled_code;
-    set_special(0); /* To get out of compiled code */
+    set_special(&regs, 0); /* To get out of compiled code */
 }
 
 
@@ -5895,7 +5906,7 @@ void compile_block(cpu_history* pc_hist, int blocklen, int totcycles)
            Dif (bi!=bi2) {
                /* I don't think it can happen anymore. Shouldn't, in
                   any case. So let's make sure... */
-               printf("WOOOWOO count=%d, ol=%d %p %p\n",
+               write_log("JIT: WOOOWOO count=%d, ol=%d %p %p\n",
                       bi->count,bi->optlevel,bi->handler_to_use,
                       cache_tags[cl].handler);
                abort();
@@ -5988,7 +5999,7 @@ void compile_block(cpu_history* pc_hist, int blocklen, int totcycles)
            for (i=0;i<blocklen &&
                     get_target_noopt()<max_compile_start;i++) {
                cpuop_func **cputbl;
-               cpuop_func **comptbl;
+               compop_func **comptbl;
                uae_u16 opcode;
 
                opcode=cft_map((uae_u16)*pc_hist[i].location);
@@ -6036,7 +6047,9 @@ void compile_block(cpu_history* pc_hist, int blocklen, int totcycles)
                        was_comp=0;
                    }
                    raw_mov_l_ri(REG_PAR1,(uae_u32)opcode);
+                   raw_mov_l_ri(REG_PAR2,(uae_u32)&regs);
 #if USE_NORMAL_CALLING_CONVENTION
+                   raw_push_l_r(REG_PAR2);
                    raw_push_l_r(REG_PAR1);
 #endif
                    raw_mov_l_mi((uae_u32)&regs.pc_p,
@@ -6044,7 +6057,7 @@ void compile_block(cpu_history* pc_hist, int blocklen, int totcycles)
                    raw_call((uae_u32)cputbl[opcode]);
                    //raw_add_l_mi((uae_u32)&oink,1); // FIXME
 #if USE_NORMAL_CALLING_CONVENTION
-                   raw_inc_sp(4);
+                   raw_inc_sp(8);
 #endif
                    /*if (needed_flags)
                        raw_mov_l_mi((uae_u32)&foink3,(uae_u32)opcode+65536);
index f4e14a5c5ab5597cc0bc8c68d1037fcaa172862d..16ccd6dd0d22e241a0fb46936efcee4b3108fb3e 100755 (executable)
--- a/custom.c
+++ b/custom.c
@@ -23,9 +23,7 @@
 #include <ctype.h>
 #include <assert.h>
 
-#include "config.h"
 #include "options.h"
-#include "threaddep/thread.h"
 #include "uae.h"
 #include "gensound.h"
 #include "sounddep/sound.h"
 #include "serial.h"
 #include "osemu.h"
 #include "autoconf.h"
+#include "traps.h"
 #include "gui.h"
 #include "picasso96.h"
 #include "drawing.h"
 #include "savestate.h"
 #include "ar.h"
+#ifdef AVIOUTPUT
 #include "avioutput.h"
+#endif
 #include "debug.h"
 #include "akiko.h"
 #if defined(ENFORCER)
@@ -143,7 +144,7 @@ static uae_u32 sprclx[16], clxmask[16];
  * Hardware registers of all sorts.
  */
 
-static int custom_wput_1 (int, uaecptr, uae_u32, int) REGPARAM;
+static int REGPARAM3 custom_wput_1 (int, uaecptr, uae_u32, int) REGPARAM;
 
 static uae_u16 cregs[256];
 
@@ -157,7 +158,7 @@ int maxhpos = MAXHPOS_PAL;
 int maxvpos = MAXVPOS_PAL;
 int minfirstline = VBLANK_ENDLINE_PAL;
 int vblank_hz = VBLANK_HZ_PAL, fake_vblank_hz, vblank_skip;
-unsigned long syncbase;
+frame_time_t syncbase;
 static int fmode;
 unsigned int beamcon0, new_beamcon0;
 uae_u16 vtotal = MAXVPOS_PAL, htotal = MAXHPOS_PAL;
@@ -583,15 +584,15 @@ static int fetchstart, fetchstart_shift, fetchstart_mask;
 static int fm_maxplane, fm_maxplane_shift;
 
 /* The corresponding values, by fetchmode and display resolution.  */
-static int fetchunits[] = { 8,8,8,0, 16,8,8,0, 32,16,8,0 };
-static int fetchstarts[] = { 3,2,1,0, 4,3,2,0, 5,4,3,0 };
-static int fm_maxplanes[] = { 3,2,1,0, 3,3,2,0, 3,3,3,0 };
+static const int fetchunits[] = { 8,8,8,0, 16,8,8,0, 32,16,8,0 };
+static const int fetchstarts[] = { 3,2,1,0, 4,3,2,0, 5,4,3,0 };
+static const int fm_maxplanes[] = { 3,2,1,0, 3,3,2,0, 3,3,3,0 };
 
 static int cycle_diagram_table[3][3][9][32];
 static int cycle_diagram_free_cycles[3][3][9];
 static int cycle_diagram_total_cycles[3][3][9];
 static int *curr_diagram;
-static int cycle_sequences[3 * 8] = { 2,1,2,1,2,1,2,1, 4,2,3,1,4,2,3,1, 8,4,6,2,7,3,5,1 };
+static const int cycle_sequences[3 * 8] = { 2,1,2,1,2,1,2,1, 4,2,3,1,4,2,3,1, 8,4,6,2,7,3,5,1 };
 
 static void debug_cycle_diagram(void)
 {
@@ -621,7 +622,7 @@ static void create_cycle_diagram_table(void)
 {
     int fm, res, cycle, planes, rplanes, v;
     int fetch_start, max_planes, freecycles;
-    int *cycle_sequence;
+    const int *cycle_sequence;
 
     for (fm = 0; fm <= 2; fm++) {
        for (res = 0; res <= 2; res++) {
@@ -1589,8 +1590,6 @@ static void record_color_change (int hpos, int regno, unsigned long value)
        return;
     }
 #endif
-    if (regno < 0)
-       write_log("%d\n", regno);
     curr_color_changes[next_color_change].linepos = hpos;
     curr_color_changes[next_color_change].regno = regno;
     curr_color_changes[next_color_change++].value = value;
@@ -2127,7 +2126,6 @@ static void reset_decisions (void)
     curr_drawinfo[next_lineno].first_sprite_entry = next_sprite_entry;
     next_sprite_forced = 1;
 
-    /* memset(sprite_last_drawn_at, 0, sizeof sprite_last_drawn_at); */
     last_sprite_point = 0;
     fetch_state = fetch_not_started;
     passed_plfstop = 0;
@@ -2154,8 +2152,6 @@ static void reset_decisions (void)
     thisline_decision.bplcon3 = bplcon3;
     thisline_decision.bplcon4 = bplcon4;
 #endif
-
-
 }
 
 static int isvsync (void)
@@ -2202,7 +2198,7 @@ static void dumpsync (void)
     if (cnt < 0)
        return;
     cnt--;
-    write_log ("BEAMCON0 = %04.4X VTOTAL=%04.4X HTOTAL=%04.4X\n", new_beamcon0, vtotal, htotal);
+    write_log ("BEAMCON0=%04.4X VTOTAL=%04.4X HTOTAL=%04.4X\n", new_beamcon0, vtotal, htotal);
     write_log ("HSSTOP=%04.4X HBSTRT=%04.4X HBSTOP=%04.4X\n", hsstop, hbstrt, hbstop);
     write_log ("VSSTOP=%04.4X VBSTRT=%04.4X VBSTOP=%04.4X\n", vsstop, vbstrt, vbstop);
     write_log ("HSSTRT=%04.4X VSSTRT=%04.4X HCENTER=%04.4X\n", hsstrt, vsstrt, hcenter);
@@ -2349,18 +2345,18 @@ void init_custom (void)
 
 static int timehack_alive = 0;
 
-static uae_u32 timehack_helper (void)
+static uae_u32 REGPARAM2 timehack_helper (TrapContext *context)
 {
 #ifdef HAVE_GETTIMEOFDAY
     struct timeval tv;
-    if (m68k_dreg (regs, 0) == 0)
+    if (m68k_dreg (&context->regs, 0) == 0)
        return timehack_alive;
 
     timehack_alive = 10;
 
     gettimeofday (&tv, NULL);
-    put_long (m68k_areg (regs, 0), tv.tv_sec - (((365 * 8 + 2) * 24) * 60 * 60));
-    put_long (m68k_areg (regs, 0) + 4, tv.tv_usec);
+    put_long (m68k_areg (&context->regs, 0), tv.tv_sec - (((365 * 8 + 2) * 24) * 60 * 60));
+    put_long (m68k_areg (&context->regs, 0) + 4, tv.tv_usec);
     return 0;
 #else
     return 2;
@@ -2386,10 +2382,6 @@ STATIC_INLINE uae_u16 DMACONR (void)
     decide_blitter (current_hpos ());
     v = dmacon | (bltstate == BLT_done ? 0 : 0x4000)
            | (blt_info.blitzero ? 0x2000 : 0);
-#if 0
-    if (!dmaen (DMA_BLITTER))
-       v &= ~0x4000;
-#endif
     return v;
 }
 STATIC_INLINE uae_u16 INTENAR (void)
@@ -2405,11 +2397,11 @@ STATIC_INLINE uae_u16 ADKCONR (void)
     return adkcon;
 }
 
-STATIC_INLINE GETVPOS(void)
+STATIC_INLINE int GETVPOS(void)
 {
     return vpos_lpen > 0 ? vpos_lpen : (((bplcon0 & 2) && !currprefs.genlock) ? vpos_previous : vpos);
 }
-STATIC_INLINE GETHPOS(void)
+STATIC_INLINE int GETHPOS(void)
 {
     return vpos_lpen > 0 ? hpos_lpen : (((bplcon0 & 2) && !currprefs.genlock) ? hpos_previous : current_hpos ());
 }
@@ -2471,7 +2463,7 @@ static void COPJMP (int num)
     if (was_active)
        events_schedule ();
 
-    unset_special (SPCFLAG_COPPER);
+    unset_special (&regs, SPCFLAG_COPPER);
     cop_state.ignore_next = 0;
     if (!oldstrobe)
        cop_state.state_prev = cop_state.state;
@@ -2483,7 +2475,7 @@ static void COPJMP (int num)
 
     if (dmaen (DMA_COPPER)) {
        copper_enabled_thisline = 1;
-       set_special (SPCFLAG_COPPER);
+       set_special (&regs, SPCFLAG_COPPER);
     } else if (oldstrobe > 0 && oldstrobe != num && cop_state.state_prev == COP_wait) {
        /* dma disabled, copper idle and accessing both COPxJMPs -> copper stops! */
        cop_state.state = COP_stop;
@@ -2521,7 +2513,7 @@ static void DMACON (int hpos, uae_u16 v)
            compute_spcflag_copper ();
        } else if (!newcop) {
            copper_enabled_thisline = 0;
-           unset_special (SPCFLAG_COPPER);
+           unset_special (&regs, SPCFLAG_COPPER);
        }
     }
     if ((dmacon & DMA_BLITPRI) > (oldcon & DMA_BLITPRI) && bltstate != BLT_done) {
@@ -2530,13 +2522,13 @@ static void DMACON (int hpos, uae_u16 v)
            count = 1;
            write_log ("warning: program is doing blitpri hacks.\n");
        }
-       set_special (SPCFLAG_BLTNASTY);
+       set_special (&regs, SPCFLAG_BLTNASTY);
        decide_blitter (hpos);
     }
     if (dmaen (DMA_BLITTER) && bltstate == BLT_init)
        bltstate = BLT_work;
     if ((dmacon & (DMA_BLITPRI | DMA_BLITTER | DMA_MASTER)) != (DMA_BLITPRI | DMA_BLITTER | DMA_MASTER)) {
-       unset_special (SPCFLAG_BLTNASTY);
+       unset_special (&regs, SPCFLAG_BLTNASTY);
        decide_blitter (hpos);
     }
     if (changed & (DMA_MASTER | 0x0f))
@@ -2560,7 +2552,7 @@ static int intlev_2 (void)
     int i;
 
     if (!(imask && (intena & 0x4000))) {
-       unset_special (SPCFLAG_INT);
+       unset_special (&regs, SPCFLAG_INT);
        return -1;
     }
     for (i = 14; i >= 0; i--) {
@@ -2613,7 +2605,7 @@ int intlev (void)
 #endif
        il = intlev_2 ();
        if (il >= 0 && il <= regs.intmask)
-           unset_special (SPCFLAG_INT);
+           unset_special (&regs, SPCFLAG_INT);
 #ifdef JIT
     }
 #endif
@@ -2625,7 +2617,7 @@ static void doint (void)
     int i;
     uae_u16 imask;
 
-    set_special (SPCFLAG_INT);
+    set_special (&regs, SPCFLAG_INT);
 #ifdef JIT
     if (currprefs.cachesize)
        return;
@@ -2877,17 +2869,6 @@ STATIC_INLINE void BPL1DAT (int hpos, uae_u16 v)
     maybe_first_bpl1dat (hpos);
 }
 
-#if 0
-/* We could do as well without those... */
-STATIC_INLINE void BPL2DAT (uae_u16 v) { bpl2dat = v; }
-STATIC_INLINE void BPL3DAT (uae_u16 v) { bpl3dat = v; }
-STATIC_INLINE void BPL4DAT (uae_u16 v) { bpl4dat = v; }
-STATIC_INLINE void BPL5DAT (uae_u16 v) { bpl5dat = v; }
-STATIC_INLINE void BPL6DAT (uae_u16 v) { bpl6dat = v; }
-STATIC_INLINE void BPL7DAT (uae_u16 v) { bpl7dat = v; }
-STATIC_INLINE void BPL8DAT (uae_u16 v) { bpl8dat = v; }
-#endif
-
 static void DIWSTRT (int hpos, uae_u16 v)
 {
     if (diwstrt == v && ! diwhigh_written)
@@ -3209,7 +3190,6 @@ static void CLXCON (uae_u16 v)
     clxcon = v;
     clxcon_bpl_enable = (v >> 6) & 63;
     clxcon_bpl_match = v & 63;
-    //write_log("CLXCON: %04.4X PC=%x\n", v, m68k_getpc());
 }
 
 static void CLXCON2 (uae_u16 v)
@@ -3219,13 +3199,11 @@ static void CLXCON2 (uae_u16 v)
     clxcon2 = v;
     clxcon_bpl_enable |= v & (0x40|0x80);
     clxcon_bpl_match |= (v & (0x01|0x02)) << 6;
-    //write_log("CLXCON2: %04.4X\n", v);
 }
 
 static uae_u16 CLXDAT (void)
 {
     uae_u16 v = clxdat | 0x8000;
-    //write_log("%d:CLXDAT %04.4X PC=%x\n", vpos, v, m68k_getpc());
     clxdat = 0;
     return v;
 }
@@ -3386,7 +3364,7 @@ static int test_copper_dangerous (unsigned int address)
     if ((address & 0x1fe) < (copcon & 2 ? ((currprefs.chipset_mask & CSMASK_AGA) ? 0 : 0x40u) : 0x80u)) {
        cop_state.state = COP_stop;
        copper_enabled_thisline = 0;
-       unset_special (SPCFLAG_COPPER);
+       unset_special (&regs, SPCFLAG_COPPER);
        return 1;
     }
     return 0;
@@ -3396,8 +3374,10 @@ static void perform_copper_write (int old_hpos)
 {
     unsigned int address = cop_state.saved_i1 & 0x1FE;
 
+#ifdef DEBUGGER
     if (debug_copper)
        record_copper (cop_state.saved_ip - 4, old_hpos, vpos);
+#endif
 
     if (test_copper_dangerous (address))
        return;
@@ -3624,12 +3604,12 @@ static void update_copper (int until_hpos)
            if (cop_state.saved_i1 == 0xFFFF && cop_state.saved_i2 == 0xFFFE) {
                cop_state.state = COP_stop;
                copper_enabled_thisline = 0;
-               unset_special (SPCFLAG_COPPER);
+               unset_special (&regs, SPCFLAG_COPPER);
                goto out;
            }
            if (vp < cop_state.vcmp) {
                copper_enabled_thisline = 0;
-               unset_special (SPCFLAG_COPPER);
+               unset_special (&regs, SPCFLAG_COPPER);
                goto out;
            }
 
@@ -3650,12 +3630,14 @@ static void update_copper (int until_hpos)
                /* We need to wait for the blitter.  */
                cop_state.state = COP_bltwait;
                copper_enabled_thisline = 0;
-               unset_special (SPCFLAG_COPPER);
+               unset_special (&regs, SPCFLAG_COPPER);
                goto out;
            }
 
+#ifdef DEBUGGER
            if (debug_copper)
                record_copper (cop_state.ip - 4, old_hpos, vpos);
+#endif
 
            cop_state.state = COP_read1;
            break;
@@ -3695,8 +3677,10 @@ static void update_copper (int until_hpos)
                test_copper_dangerous (chipmem_agnus_wget(cop_state.ip));
            }
 
+#ifdef DEBUGGER
            if (debug_copper)
                record_copper (cop_state.ip - 4, old_hpos, vpos);
+#endif
 
            break;
        }
@@ -3712,7 +3696,7 @@ static void update_copper (int until_hpos)
 static void compute_spcflag_copper (void)
 {
     copper_enabled_thisline = 0;
-    unset_special (SPCFLAG_COPPER);
+    unset_special (&regs, SPCFLAG_COPPER);
     if (!dmaen (DMA_COPPER) || cop_state.state == COP_stop || cop_state.state == COP_bltwait || nocustom())
        return;
 
@@ -3725,13 +3709,13 @@ static void compute_spcflag_copper (void)
     copper_enabled_thisline = 1;
 
     if (! eventtab[ev_copper].active)
-       set_special (SPCFLAG_COPPER);
+       set_special (&regs, SPCFLAG_COPPER);
 }
 
 static void copper_handler (void)
 {
     /* This will take effect immediately, within the same cycle.  */
-    set_special (SPCFLAG_COPPER);
+    set_special (&regs, SPCFLAG_COPPER);
 
     if (! copper_enabled_thisline)
        uae_abort ("copper_handler");
@@ -3768,7 +3752,7 @@ STATIC_INLINE void sync_copper_with_cpu (int hpos, int do_schedule)
        eventtab[ev_copper].active = 0;
        if (do_schedule)
            events_schedule ();
-       set_special (SPCFLAG_COPPER);
+       set_special (&regs, SPCFLAG_COPPER);
     }
     if (copper_enabled_thisline)
        update_copper (hpos);
@@ -3973,34 +3957,59 @@ static void init_sprites (void)
     memset (sprctl, 0, sizeof sprctl);
 }
 
+/*
+ * On systems without virtual memory or with low memory, we allocate the
+ * sprite_entries and color_changes tables dynamically rather than having
+ * them declared static. We don't initially allocate at their maximum sizes;
+ * we start the tables off small and grow them as required.
+ *
+ * This function expands the tables if necessary.
+ */
 static void adjust_array_sizes (void)
 {
 #ifdef OS_WITHOUT_MEMORY_MANAGEMENT
     if (delta_sprite_entry) {
-       void *p1,*p2;
-       int mcc = max_sprite_entry + 50 + delta_sprite_entry;
+       void *p1;
+       void *p2;
+       int   mcc = max_sprite_entry + 50 + delta_sprite_entry;
+
        delta_sprite_entry = 0;
+
        p1 = realloc (sprite_entries[0], mcc * sizeof (struct sprite_entry));
        p2 = realloc (sprite_entries[1], mcc * sizeof (struct sprite_entry));
-       if (p1) sprite_entries[0] = p1;
-       if (p2) sprite_entries[1] = p2;
+
        if (p1 && p2) {
-           write_log ("new max_sprite_entry=%d\n",mcc);
+           sprite_entries[0] = p1;
+           sprite_entries[1] = p2;
+
+           memset (&sprite_entries[0][max_sprite_entry], (mcc - max_sprite_entry) * sizeof(struct sprite_entry), 0);
+           memset (&sprite_entries[1][max_sprite_entry], (mcc - max_sprite_entry) * sizeof(struct sprite_entry), 0);
+
+           write_log ("New max_sprite_entry=%d\n", mcc);
+
            max_sprite_entry = mcc;
-       }
+       } else
+           write_log ("WARNING: Failed to enlarge sprite_entries table\n");
     }
     if (delta_color_change) {
-       void *p1,*p2;
-       int mcc = max_color_change + 200 + delta_color_change;
+       void *p1;
+       void *p2;
+       int   mcc = max_color_change + 200 + delta_color_change;
+
        delta_color_change = 0;
+
        p1 = realloc (color_changes[0], mcc * sizeof (struct color_change));
        p2 = realloc (color_changes[1], mcc * sizeof (struct color_change));
-       if (p1) color_changes[0] = p1;
-       if (p2) color_changes[1] = p2;
+
        if (p1 && p2) {
-           write_log ("new max_color_change=%d\n",mcc);
+           color_changes[0] = p1;
+           color_changes[1] = p2;
+
+           write_log ("New max_color_change=%d\n", mcc);
+
            max_color_change = mcc;
-       }
+       } else
+           write_log ("WARNING: Failed to enlarge color_changes table\n");
     }
 #endif
 }
@@ -4018,8 +4027,6 @@ static void init_hardware_frame (void)
 
 void init_hardware_for_drawing_frame (void)
 {
-    adjust_array_sizes ();
-
     /* Avoid this code in the first frame after a customreset.  */
     if (prev_sprite_entries) {
        int first_pixel = prev_sprite_entries[0].first_pixel;
@@ -4034,6 +4041,8 @@ void init_hardware_for_drawing_frame (void)
     next_color_entry = 0;
     remembered_color_entry = -1;
 
+    adjust_array_sizes ();
+
     prev_sprite_entries = sprite_entries[current_change_set];
     curr_sprite_entries = sprite_entries[current_change_set ^ 1];
     prev_color_changes = color_changes[current_change_set];
@@ -4067,7 +4076,7 @@ static int rpt_vsync (void)
 static void framewait (void)
 {
     frame_time_t curr_time;
-    int start;
+    frame_time_t start;
 
     for (;;) {
        double v = rpt_vsync () / (syncbase / 1000.0);
@@ -4085,7 +4094,7 @@ static void framewait (void)
     idletime += read_processor_time() - start;
 }
 
-static int frametime2;
+static frame_time_t frametime2;
 
 void fpscounter_reset (void)
 {
@@ -4098,7 +4107,7 @@ void fpscounter_reset (void)
 
 static void fpscounter (void)
 {
-    int now, last;
+    frame_time_t now, last;
 
     now = read_processor_time ();
     last = now - lastframetime;
@@ -4228,8 +4237,6 @@ static __inline__ int trigger_frh(int v)
     return (v & (N_LINES - 1)) == 0;
 }
 
-extern int gonebad;
-
 static long int diff32(frame_time_t x, frame_time_t y)
 {
     return (long int)(x-y);
@@ -4249,7 +4256,6 @@ static void frh_handler(void)
        /* Allow this to be one frame's worth of cycles out */
        while (diff32 (curr_time, vsyncmintime + vsynctime) > 0) {
            vsyncmintime += vsynctime * N_LINES / maxvpos;
-           gonebad++;
            if (turbo_emulation)
                break;
        }
@@ -4460,7 +4466,7 @@ void customreset (void)
     int i;
     int zero = 0;
 
-    write_log ("reset at %x\n", m68k_getpc());
+    write_log ("reset at %x\n", m68k_getpc(&regs));
     hsync_counter = 0;
     if (! savestate_state) {
        currprefs.chipset_mask = changed_prefs.chipset_mask;
@@ -4506,7 +4512,7 @@ void customreset (void)
 #ifdef JIT
     compemu_reset ();
 #endif
-    unset_special (~(SPCFLAG_BRK | SPCFLAG_MODE_CHANGE));
+    unset_special (&regs, ~(SPCFLAG_BRK | SPCFLAG_MODE_CHANGE));
 
     vpos = 0;
 
@@ -4519,7 +4525,7 @@ void customreset (void)
     sprite_entries[1][0].first_pixel = MAX_SPR_PIXELS;
     sprite_entries[0][1].first_pixel = 0;
     sprite_entries[1][1].first_pixel = MAX_SPR_PIXELS;
-    memset (spixels, 0, sizeof spixels);
+    memset (spixels, 0, 2 * MAX_SPR_PIXELS * sizeof *spixels);
     memset (&spixstate, 0, sizeof spixstate);
 
     bltstate = BLT_done;
@@ -4656,22 +4662,49 @@ static void gen_custom_tables (void)
 }
 
 /* mousehack is now in "filesys boot rom" */
-static uae_u32 mousehack_helper_old (void)
+static uae_u32 REGPARAM2 mousehack_helper_old (struct TrapContext *ctx)
 {
     return 0;
 }
 
-void custom_init (void)
+static int allocate_sprite_tables (void)
 {
-
 #ifdef OS_WITHOUT_MEMORY_MANAGEMENT
     int num;
 
-    for (num = 0; num < 2; num++) {
-       sprite_entries[num] = xmalloc (max_sprite_entry * sizeof (struct sprite_entry));
-       color_changes[num] = xmalloc (max_color_change * sizeof (struct color_change));
+    delta_sprite_entry = 0;
+    delta_color_change = 0;
+
+    if (!sprite_entries[0]) {
+        max_sprite_entry = DEFAULT_MAX_SPRITE_ENTRY;
+        max_color_change = DEFAULT_MAX_COLOR_CHANGE;
+
+       for (num = 0; num < 2; num++) {
+           sprite_entries[num] = xmalloc (max_sprite_entry * sizeof (struct sprite_entry));
+           color_changes[num] = xmalloc (max_color_change * sizeof (struct color_change));
+
+           if (sprite_entries[num] && color_changes[num]) {
+               memset (sprite_entries[num], 0, max_sprite_entry * sizeof (struct sprite_entry));
+               memset (color_changes[num], 0, max_color_change * sizeof (struct color_change));
+           } else
+               return 0;
+       }
+    }
+
+    if (!spixels) {
+       spixels = xmalloc (2 * MAX_SPR_PIXELS * sizeof *spixels);
+       if (!spixels)
+           return 0;
     }
 #endif
+    return 1;
+}
+
+int custom_init (void)
+{
+
+    if (!allocate_sprite_tables())
+       return 0;
 
 #ifdef AUTOCONFIG
     {
@@ -4696,18 +4729,20 @@ void custom_init (void)
     drawing_init ();
 
     create_cycle_diagram_table ();
+
+    return 1;
 }
 
 /* Custom chip memory bank */
 
-static uae_u32 custom_lget (uaecptr) REGPARAM;
-static uae_u32 custom_wget (uaecptr) REGPARAM;
-static uae_u32 custom_bget (uaecptr) REGPARAM;
-static uae_u32 custom_lgeti (uaecptr) REGPARAM;
-static uae_u32 custom_wgeti (uaecptr) REGPARAM;
-static void custom_lput (uaecptr, uae_u32) REGPARAM;
-static void custom_wput (uaecptr, uae_u32) REGPARAM;
-static void custom_bput (uaecptr, uae_u32) REGPARAM;
+static uae_u32 REGPARAM3 custom_lget (uaecptr) REGPARAM;
+static uae_u32 REGPARAM3 custom_wget (uaecptr) REGPARAM;
+static uae_u32 REGPARAM3 custom_bget (uaecptr) REGPARAM;
+static uae_u32 REGPARAM3 custom_lgeti (uaecptr) REGPARAM;
+static uae_u32 REGPARAM3 custom_wgeti (uaecptr) REGPARAM;
+static void REGPARAM3 custom_lput (uaecptr, uae_u32) REGPARAM;
+static void REGPARAM3 custom_wput (uaecptr, uae_u32) REGPARAM;
+static void REGPARAM3 custom_bput (uaecptr, uae_u32) REGPARAM;
 
 addrbank custom_bank = {
     custom_lget, custom_wget, custom_bget,
@@ -4949,15 +4984,6 @@ static int REGPARAM2 custom_wput_1 (int hpos, uaecptr addr, uae_u32 value, int n
 #endif
 
      case 0x110: BPL1DAT (hpos, value); break;
-#if 0 /* no point */
-     case 0x112: BPL2DAT (value); break;
-     case 0x114: BPL3DAT (value); break;
-     case 0x116: BPL4DAT (value); break;
-     case 0x118: BPL5DAT (value); break;
-     case 0x11A: BPL6DAT (value); break;
-     case 0x11C: BPL7DAT (value); break;
-     case 0x11E: BPL8DAT (value); break;
-#endif
 
      case 0x180: case 0x182: case 0x184: case 0x186: case 0x188: case 0x18A:
      case 0x18C: case 0x18E: case 0x190: case 0x192: case 0x194: case 0x196:
@@ -5054,8 +5080,8 @@ static void REGPARAM2 custom_bput (uaecptr addr, uae_u32 value)
 #endif
     custom_wput (addr & ~1, rval);
     if (warned < 10) {
-       if (m68k_getpc() < 0xe00000 || m68k_getpc() >= 0x10000000) {
-           write_log ("Byte put to custom register %04.4X PC=%08.8X\n", addr, m68k_getpc());
+       if (m68k_getpc(&regs) < 0xe00000 || m68k_getpc(&regs) >= 0x10000000) {
+           write_log ("Byte put to custom register %04.4X PC=%08.8X\n", addr, m68k_getpc(&regs));
            warned++;
        }
     }
@@ -5070,6 +5096,8 @@ static void REGPARAM2 custom_lput(uaecptr addr, uae_u32 value)
     custom_wput ((addr + 2) & 0xfffe, (uae_u16)value);
 }
 
+#ifdef SAVESTATE
+
 void custom_prepare_savestate (void)
 {
 }
@@ -5215,6 +5243,10 @@ uae_u8 *restore_custom (uae_u8 *src)
     return src;
 }
 
+#endif /* SAVESTATE */
+
+#if defined SAVESTATE || defined DEBUGGER
+
 #define SB save_u8
 #define SW save_u16
 #define SL save_u32
@@ -5371,6 +5403,10 @@ uae_u8 *save_custom (int *len, uae_u8 *dstptr, int full)
     return dstbak;
 }
 
+#endif /* SAVESTATE || DEBUGGER */
+
+#ifdef SAVESTATE
+
 uae_u8 *restore_custom_agacolors (uae_u8 *src)
 {
     int i;
@@ -5444,6 +5480,8 @@ uae_u8 *save_custom_sprite(int num, int *len, uae_u8 *dstptr)
     return dstbak;
 }
 
+#endif /* SAVESTATE */
+
 void check_prefs_changed_custom (void)
 {
     currprefs.gfx_framerate = changed_prefs.gfx_framerate;
@@ -5467,12 +5505,14 @@ void check_prefs_changed_custom (void)
        }
        init_custom ();
     }
+#ifdef GFXFILTER
     currprefs.gfx_filter_horiz_zoom = changed_prefs.gfx_filter_horiz_zoom;
     currprefs.gfx_filter_vert_zoom = changed_prefs.gfx_filter_vert_zoom;
     currprefs.gfx_filter_horiz_offset = changed_prefs.gfx_filter_horiz_offset;
     currprefs.gfx_filter_vert_offset = changed_prefs.gfx_filter_vert_offset;
     currprefs.gfx_filter_scanlines = changed_prefs.gfx_filter_scanlines;
     currprefs.gfx_filter_filtermode = changed_prefs.gfx_filter_filtermode;
+#endif
 }
 
 #ifdef CPUEMU_6
diff --git a/debug.c b/debug.c
index 4707221405128e40537a8ee198acad4b5ea96364..c2600a90b599c6710687fac99b7da7e2628b54b3 100755 (executable)
--- a/debug.c
+++ b/debug.c
@@ -14,9 +14,7 @@
 #include <ctype.h>
 #include <signal.h>
 
-#include "config.h"
 #include "options.h"
-#include "threaddep/thread.h"
 #include "uae.h"
 #include "memory.h"
 #include "custom.h"
@@ -25,7 +23,6 @@
 #include "debug.h"
 #include "cia.h"
 #include "xwin.h"
-#include "gui.h"
 #include "identify.h"
 #include "sound.h"
 #include "disk.h"
@@ -60,7 +57,7 @@ void activate_debugger (void)
     if (debugger_active)
        return;
     debugger_active = 1;
-    set_special (SPCFLAG_BRK);
+    set_special (&regs, SPCFLAG_BRK);
     debugging = 1;
     mmu_triggered = 0;
 }
@@ -68,7 +65,6 @@ void activate_debugger (void)
 int firsthist = 0;
 int lasthist = 0;
 static struct regstruct history[MAX_HIST];
-static struct flag_struct historyf[MAX_HIST];
 
 static char help[] = {
     "          HELP for UAE Debugger\n"
@@ -102,7 +98,7 @@ static char help[] = {
     "  Cl                    List currently found trainer addresses\n"
     "  D                     Deep trainer\n"
     "  W <address> <value>   Write into Amiga memory\n"
-    "  w <num> <address> <length> <R/W/RW> [<value>]\n"
+    "  w <num> <address> <length> <R/W/RW/F> [<value>]\n"
     "                        Add/remove memory watchpoints\n"
     "  wd                    Enable illegal access logger\n"
     "  S <file> <addr> <n>   Save a block of Amiga memory\n"
@@ -128,7 +124,8 @@ static void debug_help (void)
 
 static void ignore_ws (char **c)
 {
-    while (**c && isspace(**c)) (*c)++;
+    while (**c && isspace(**c))
+       (*c)++;
 }
 
 static uae_u32 readint (char **c);
@@ -817,6 +814,7 @@ struct memwatch_node {
     int val_enabled;
     uae_u32 modval;
     int modval_written;
+    int frozen;
 };
 static struct memwatch_node mwnodes[MEMWATCH_TOTAL];
 static struct memwatch_node mwhit;
@@ -881,7 +879,7 @@ static void illg_debug_check (uaecptr addr, int rw, int size, uae_u32 val)
 static void illg_debug_do (uaecptr addr, int rw, int size, uae_u32 val)
 {
     uae_u8 mask;
-    uae_u32 pc = m68k_getpc ();
+    uae_u32 pc = m68k_getpc (&regs);
     char rws = rw ? 'W' : 'R';
     int i;
 
@@ -920,7 +918,7 @@ static int debug_mem_off (uaecptr addr)
     return munge24 (addr) >> 16;
 }
 
-static void memwatch_func (uaecptr addr, int rw, int size, uae_u32 val)
+static int memwatch_func (uaecptr addr, int rw, int size, uae_u32 val)
 {
     int i, brk;
 
@@ -928,14 +926,15 @@ static void memwatch_func (uaecptr addr, int rw, int size, uae_u32 val)
        illg_debug_do (addr, rw, size, val);
     addr = munge24 (addr);
     for (i = 0; i < MEMWATCH_TOTAL; i++) {
-       uaecptr addr2 = mwnodes[i].addr;
-       uaecptr addr3 = addr2 + mwnodes[i].size;
-       int rw2 = mwnodes[i].rw;
+       struct memwatch_node *m = &mwnodes[i];
+       uaecptr addr2 = m->addr;
+       uaecptr addr3 = addr2 + m->size;
+       int rw2 = m->rw;
 
        brk = 0;
-       if (mwnodes[i].size == 0)
+       if (m->size == 0)
            continue;
-       if (mwnodes[i].val_enabled && mwnodes[i].val != val)
+       if (m->val_enabled && m->val != val)
            continue;
        if (rw != rw2 && rw2 < 2)
            continue;
@@ -945,18 +944,20 @@ static void memwatch_func (uaecptr addr, int rw, int size, uae_u32 val)
            brk = 1;
        if (!brk && size == 4 && ((addr + 2 >= addr2 && addr + 2 < addr3) || (addr + 3 >= addr2 && addr + 3 < addr3)))
            brk = 1;
-       if (brk && mwnodes[i].modval_written) {
+       if (brk && m->modval_written) {
            if (!rw) {
                brk = 0;
-           } else if (mwnodes[i].modval_written == 1) {
-               mwnodes[i].modval_written = 2;
-               mwnodes[i].modval = val;
+           } else if (m->modval_written == 1) {
+               m->modval_written = 2;
+               m->modval = val;
                brk = 0;
-           } else if (mwnodes[i].modval == val) {
+           } else if (m->modval == val) {
                brk = 0;
            }
        }
        if (brk) {
+           if (m->frozen)
+               return 0;
            mwhit.addr = addr;
            mwhit.rw = rw;
            mwhit.size = size;
@@ -965,15 +966,16 @@ static void memwatch_func (uaecptr addr, int rw, int size, uae_u32 val)
                mwhit.val = val;
            memwatch_triggered = i + 1;
            debugging = 1;
-           set_special (SPCFLAG_BRK);
-           break;
+           set_special (&regs, SPCFLAG_BRK);
+           return 1;
        }
     }
+    return 1;
 }
 
 static int mmu_hit (uaecptr addr, int size, int rw, uae_u32 *v);
 
-static uae_u32 REGPARAM mmu_lget (uaecptr addr)
+static uae_u32 REGPARAM2 mmu_lget (uaecptr addr)
 {
     int off = debug_mem_off (addr);
     uae_u32 v = 0;
@@ -981,7 +983,7 @@ static uae_u32 REGPARAM mmu_lget (uaecptr addr)
         v = debug_mem_banks[off]->lget(addr);
     return v;
 }
-static uae_u32 REGPARAM mmu_wget (uaecptr addr)
+static uae_u32 REGPARAM2 mmu_wget (uaecptr addr)
 {
     int off = debug_mem_off (addr);
     uae_u32 v = 0;
@@ -989,7 +991,7 @@ static uae_u32 REGPARAM mmu_wget (uaecptr addr)
         v = debug_mem_banks[off]->wget(addr);
     return v;
 }
-static uae_u32 REGPARAM mmu_bget (uaecptr addr)
+static uae_u32 REGPARAM2 mmu_bget (uaecptr addr)
 {
     int off = debug_mem_off (addr);
     uae_u32 v = 0;
@@ -1016,7 +1018,7 @@ static void REGPARAM2 mmu_bput (uaecptr addr, uae_u32 v)
        debug_mem_banks[off]->bput(addr, v);
 }
 
-static uae_u32 REGPARAM debug_lget (uaecptr addr)
+static uae_u32 REGPARAM2 debug_lget (uaecptr addr)
 {
     int off = debug_mem_off (addr);
     uae_u32 v;
@@ -1043,20 +1045,20 @@ static uae_u32 REGPARAM2 debug_bget (uaecptr addr)
 static void REGPARAM2 debug_lput (uaecptr addr, uae_u32 v)
 {
     int off = debug_mem_off (addr);
-    memwatch_func (addr, 1, 4, v);
-    debug_mem_banks[off]->lput(addr, v);
+    if (memwatch_func (addr, 1, 4, v))
+       debug_mem_banks[off]->lput(addr, v);
 }
 static void REGPARAM2 debug_wput (uaecptr addr, uae_u32 v)
 {
     int off = debug_mem_off (addr);
-    memwatch_func (addr, 1, 2, v);
-    debug_mem_banks[off]->wput(addr, v);
+    if (memwatch_func (addr, 1, 2, v))
+       debug_mem_banks[off]->wput(addr, v);
 }
 static void REGPARAM2 debug_bput (uaecptr addr, uae_u32 v)
 {
     int off = debug_mem_off (addr);
-    memwatch_func (addr, 1, 1, v);
-    debug_mem_banks[off]->bput(addr, v);
+    if (memwatch_func (addr, 1, 1, v))
+       debug_mem_banks[off]->bput(addr, v);
 }
 
 static int REGPARAM2 debug_check (uaecptr addr, uae_u32 size)
@@ -1133,7 +1135,7 @@ static void memwatch_dump (int num)
                continue;
            console_out ("%d: %08.8X - %08.8X (%d) %s",
                i, mwn->addr, mwn->addr + (mwn->size - 1), mwn->size,
-               mwn->rw == 0 ? "R" : (mwn->rw == 1 ? "W" : "RW"));
+               mwn->frozen ? "F" : (mwn->rw == 0 ? "R" : (mwn->rw == 1 ? "W" : "RW")));
            if (mwn->val_enabled)
                console_out (" =%X", mwn->val);
            if (mwn->modval_written)
@@ -1205,6 +1207,7 @@ static void memwatch (char **c)
     mwn->size = 1;
     mwn->rw = 2;
     mwn->val_enabled = 0;
+    mwn->frozen = 0;
     mwn->modval_written = 0;
     ignore_ws (c);
     if (more_params (c)) {
@@ -1212,7 +1215,9 @@ static void memwatch (char **c)
        ignore_ws (c);
        if (more_params (c)) {
            char nc = toupper (next_char (c));
-           if (nc == 'W')
+           if (nc == 'F')
+               mwn->frozen = 1;
+           else if (nc == 'W')
                mwn->rw = 1;
            else if (nc == 'R' && toupper(**c) != 'W')
                mwn->rw = 0;
@@ -1620,19 +1625,19 @@ static void m68k_modify (char **inptr)
        regs.vbr = v;
     else if (!strcmp (parm, "USP")) {
        regs.usp = v;
-       MakeFromSR ();
+       MakeFromSR (&regs);
     } else if (!strcmp (parm, "ISP")) {
        regs.isp = v;
-       MakeFromSR ();
+       MakeFromSR (&regs);
     } else if (!strcmp (parm, "MSP")) {
        regs.msp = v;
-       MakeFromSR ();
+       MakeFromSR (&regs);
     } else if (!strcmp (parm, "SR")) {
        regs.sr = v;
-       MakeFromSR ();
+       MakeFromSR (&regs);
     } else if (!strcmp (parm, "CCR")) {
        regs.sr = (regs.sr & ~15) | (v & 15);
-       MakeFromSR ();
+       MakeFromSR (&regs);
     }
 }
 
@@ -1712,7 +1717,7 @@ static void debug_1 (void)
                skipaddr_doskip = readint (&inptr);
            if (skipaddr_doskip <= 0 || skipaddr_doskip > 10000)
                skipaddr_doskip = 1;
-           set_special (SPCFLAG_BRK);
+           set_special (&regs, SPCFLAG_BRK);
            exception_debugging = 1;
            return;
        case 'z':
@@ -1739,8 +1744,8 @@ static void debug_1 (void)
 
        case 'g':
            if (more_params (&inptr)) {
-               m68k_setpc (readhex (&inptr));
-               fill_prefetch_slow ();
+               m68k_setpc (&regs, readhex (&inptr));
+               fill_prefetch_slow (&regs);
            }
            debugger_active = 0;
            debugging = 0;
@@ -1750,9 +1755,8 @@ static void debug_1 (void)
        case 'H':
        {
            int count, temp, badly;
-           uae_u32 oldpc = m68k_getpc();
+           uae_u32 oldpc = m68k_getpc(&regs);
            struct regstruct save_regs = regs;
-           struct flag_struct save_flags = regflags;
 
            badly = 0;
            if (inptr[0] == 'H') {
@@ -1775,8 +1779,7 @@ static void debug_1 (void)
            }
            while (temp != lasthist) {
                regs = history[temp];
-               regflags = historyf[temp];
-               m68k_setpc(history[temp].pc);
+               m68k_setpc(&regs, history[temp].pc);
                if (badly) {
                    m68k_dumpstate(stdout, NULL);
                } else {
@@ -1786,8 +1789,7 @@ static void debug_1 (void)
                    temp = 0;
            }
            regs = save_regs;
-           regflags = save_flags;
-           m68k_setpc(oldpc);
+           m68k_setpc(&regs, oldpc);
        }
        break;
        case 'm':
@@ -1847,8 +1849,7 @@ static void debug_1 (void)
 static void addhistory(void)
 {
     history[lasthist] = regs;
-    history[lasthist].pc = m68k_getpc();
-    historyf[lasthist] = regflags;
+    history[lasthist].pc = m68k_getpc(&regs);
     if (++lasthist == MAX_HIST)
        lasthist = 0;
     if (lasthist == firsthist) {
@@ -1887,7 +1888,7 @@ void debug (void)
 
     if (!memwatch_triggered) {
        if (do_skip) {
-           uae_u32 pc = munge24 (m68k_getpc());
+           uae_u32 pc = munge24 (m68k_getpc(&regs));
            uae_u16 opcode = (currprefs.cpu_compatible || currprefs.cpu_cycle_exact) ? regs.ir : get_word (pc);
            int bp = 0;
 
@@ -1920,7 +1921,7 @@ void debug (void)
                }
            }
            if (!bp) {
-               set_special (SPCFLAG_BRK);
+               set_special (&regs, SPCFLAG_BRK);
                return;
            }
        }
@@ -1932,7 +1933,7 @@ void debug (void)
     if (skipaddr_doskip > 0) {
        skipaddr_doskip--;
        if (skipaddr_doskip > 0) {
-           set_special (SPCFLAG_BRK);
+           set_special (&regs, SPCFLAG_BRK);
            return;
        }
     }
@@ -1965,8 +1966,8 @@ void debug (void)
            do_skip = 1;
     }
     if (do_skip) {
-       set_special (SPCFLAG_BRK);
-       unset_special (SPCFLAG_STOP);
+       set_special (&regs, SPCFLAG_BRK);
+       unset_special (&regs, SPCFLAG_STOP);
        debugging = 1;
     }
     resume_sound ();
@@ -1975,7 +1976,7 @@ void debug (void)
 
 int notinrom (void)
 {
-    if (munge24 (m68k_getpc()) < 0xe0000)
+    if (munge24 (m68k_getpc(&regs)) < 0xe0000)
        return 1;
     return 0;
 }
@@ -2019,10 +2020,15 @@ static struct mmunode **mmunl;
 #define MMU_WRITE_U (1 << 1)
 #define MMU_READ_S (1 << 2)
 #define MMU_WRITE_S (1 << 3)
-#define MMU_MAP_READ_U (1 << 4)
-#define MMU_MAP_WRITE_U (1 << 5)
-#define MMU_MAP_READ_S (1 << 6)
-#define MMU_MAP_WRITE_S (1 << 7)
+#define MMU_READI_U (1 << 4)
+#define MMU_READI_S (1 << 5)
+
+#define MMU_MAP_READ_U (1 << 8)
+#define MMU_MAP_WRITE_U (1 << 9)
+#define MMU_MAP_READ_S (1 << 10)
+#define MMU_MAP_WRITE_S (1 << 11)
+#define MMU_MAP_READI_U (1 << 12)
+#define MMU_MAP_READI_S (1 << 13)
 
 void mmu_do_hit(void)
 {
@@ -2031,62 +2037,62 @@ void mmu_do_hit(void)
     uae_u32 pc;
 
     mmu_triggered = 0;
-    pc = m68k_getpc();
+    pc = m68k_getpc(&regs);
     p = mmu_regs + 18 * 4;
     put_long (p, pc);
     regs = mmu_backup_regs;
     regs.intmask = 7;
     regs.t0 = regs.t1 = 0;
     if (!regs.s) {
-       regs.usp = m68k_areg(regs, 7);
+       regs.usp = m68k_areg(&regs, 7);
        if (currprefs.cpu_level >= 2)
-           m68k_areg(regs, 7) = regs.m ? regs.msp : regs.isp;
+           m68k_areg(&regs, 7) = regs.m ? regs.msp : regs.isp;
        else
-           m68k_areg(regs, 7) = regs.isp;
+           m68k_areg(&regs, 7) = regs.isp;
        regs.s = 1;
     }
-    MakeSR();
-    m68k_setpc(mmu_callback);
-    fill_prefetch_slow ();
+    MakeSR (&regs);
+    m68k_setpc (&regs, mmu_callback);
+    fill_prefetch_slow (&regs);
 
     if (currprefs.cpu_level > 0) {
        for (i = 0 ; i < 9; i++) {
-           m68k_areg(regs, 7) -= 4;
-           put_long (m68k_areg(regs, 7), 0);
+           m68k_areg(&regs, 7) -= 4;
+           put_long (m68k_areg(&regs, 7), 0);
        }
-       m68k_areg(regs, 7) -= 4;
-       put_long (m68k_areg(regs, 7), mmu_fault_addr);
-       m68k_areg(regs, 7) -= 2;
-       put_word (m68k_areg(regs, 7), 0); /* WB1S */
-       m68k_areg(regs, 7) -= 2;
-       put_word (m68k_areg(regs, 7), 0); /* WB2S */
-       m68k_areg(regs, 7) -= 2;
-       put_word (m68k_areg(regs, 7), 0); /* WB3S */
-       m68k_areg(regs, 7) -= 2;
-       put_word (m68k_areg(regs, 7),
+       m68k_areg(&regs, 7) -= 4;
+       put_long (m68k_areg(&regs, 7), mmu_fault_addr);
+       m68k_areg(&regs, 7) -= 2;
+       put_word (m68k_areg(&regs, 7), 0); /* WB1S */
+       m68k_areg(&regs, 7) -= 2;
+       put_word (m68k_areg(&regs, 7), 0); /* WB2S */
+       m68k_areg(&regs, 7) -= 2;
+       put_word (m68k_areg(&regs, 7), 0); /* WB3S */
+       m68k_areg(&regs, 7) -= 2;
+       put_word (m68k_areg(&regs, 7),
            (mmu_fault_rw ? 0 : 0x100) | (mmu_fault_size << 5)); /* SSW */
-       m68k_areg(regs, 7) -= 4;
-       put_long (m68k_areg(regs, 7), mmu_fault_bank_addr);
-       m68k_areg(regs, 7) -= 2;
-       put_word (m68k_areg(regs, 7), 0x7002);
+       m68k_areg(&regs, 7) -= 4;
+       put_long (m68k_areg(&regs, 7), mmu_fault_bank_addr);
+       m68k_areg(&regs, 7) -= 2;
+       put_word (m68k_areg(&regs, 7), 0x7002);
     }
-    m68k_areg(regs, 7) -= 4;
-    put_long (m68k_areg(regs, 7), get_long (p - 4));
-    m68k_areg(regs, 7) -= 2;
-    put_word (m68k_areg(regs, 7), mmur.sr);
+    m68k_areg(&regs, 7) -= 4;
+    put_long (m68k_areg(&regs, 7), get_long (p - 4));
+    m68k_areg(&regs, 7) -= 2;
+    put_word (m68k_areg(&regs, 7), mmur.sr);
 
-    set_special(SPCFLAG_END_COMPILE);
+    set_special(&regs, SPCFLAG_END_COMPILE);
 }
 
-static void mmu_do_hit_pre (struct mmudata *md, uaecptr addr, int size, int rw, uae_u32 v)
+static void mmu_do_hit_pre (struct mmudata *md, uaecptr addr, int size, int rwi, uae_u32 v)
 {
     uae_u32 p, pc;
     int i;
 
     mmur = regs;
-    pc = m68k_getpc();
+    pc = m68k_getpc(&regs);
     if (mmu_logging)
-       console_out ("MMU: hit %08.8X SZ=%d RW=%d V=%08.8X PC=%08.8X\n", addr, size, rw, v, pc);
+       console_out ("MMU: hit %08.8X SZ=%d RW=%d V=%08.8X PC=%08.8X\n", addr, size, rwi, v, pc);
 
     p = mmu_regs;
     put_long (p, 0); p += 4;
@@ -2100,18 +2106,18 @@ static void mmu_do_hit_pre (struct mmudata *md, uaecptr addr, int size, int rw,
     put_long (p, regs.isp); p += 4;
     put_long (p, regs.msp); p += 4;
     put_word (p, regs.sr); p += 2;
-    put_word (p, (size << 1) | (rw ? 1 : 0)); /* size and rw */ p += 2;
+    put_word (p, (size << 1) | ((rwi & 2) ? 1 : 0)); /* size and rw */ p += 2;
     put_long (p, addr); /* fault address */ p += 4;
     put_long (p, md->p_addr); /* bank address */ p += 4;
     put_long (p, v); p += 4;
     mmu_fault_addr = addr;
     mmu_fault_bank_addr = md->p_addr;
     mmu_fault_size = size;
-    mmu_fault_rw = rw;
+    mmu_fault_rw = rwi;
     mmu_triggered = 1;
 }
 
-static int mmu_hit (uaecptr addr, int size, int rw, uae_u32 *v)
+static int mmu_hit (uaecptr addr, int size, int rwi, uae_u32 *v)
 {
     int s, trig;
     uae_u32 flags;
@@ -2130,23 +2136,27 @@ static int mmu_hit (uaecptr addr, int size, int rw, uae_u32 *v)
        md = mn->mmubank;
        if (addr >= md->addr && addr < md->addr + md->len) {
            flags = md->flags;
-           if (flags & (MMU_MAP_READ_U | MMU_MAP_WRITE_U | MMU_MAP_READ_S | MMU_MAP_WRITE_S)) {
+           if (flags & (MMU_MAP_READ_U | MMU_MAP_WRITE_U | MMU_MAP_READ_S | MMU_MAP_WRITE_S | MMU_MAP_READI_U | MMU_MAP_READI_S)) {
                trig = 0;
-               if (!s && (flags & MMU_MAP_READ_U) && !rw)
+               if (!s && (flags & MMU_MAP_READ_U) && (rwi & 1))
+                   trig = 1;
+               if (!s && (flags & MMU_MAP_WRITE_U) && (rwi & 2))
                    trig = 1;
-               if (!s && (flags & MMU_MAP_WRITE_U) && rw)
+               if (s && (flags & MMU_MAP_READ_S) && (rwi & 1))
                    trig = 1;
-               if (s && (flags & MMU_MAP_READ_S) && !rw)
+               if (s && (flags & MMU_MAP_WRITE_S) && (rwi & 2))
                    trig = 1;
-               if (s && (flags & MMU_MAP_WRITE_S) && rw)
+               if (!s && (flags & MMU_MAP_READI_U) && (rwi & 4))
+                   trig = 1;
+               if (s && (flags & MMU_MAP_READI_S) && (rwi & 4))
                    trig = 1;
                if (trig) {
                    uaecptr maddr = md->remap + (addr - md->addr);
                    if (maddr == addr) /* infinite mmu hit loop? no thanks.. */
                        return 1;
                    if (mmu_logging)
-                       console_out ("MMU: remap %08.8X -> %08.8X SZ=%d RW=%d\n", addr, maddr, size, rw);
-                   if (rw) {
+                       console_out ("MMU: remap %08.8X -> %08.8X SZ=%d RW=%d\n", addr, maddr, size, rwi);
+                   if ((rwi & 2)) {
                        switch (size)
                        {
                            case 4:
@@ -2176,18 +2186,22 @@ static int mmu_hit (uaecptr addr, int size, int rw, uae_u32 *v)
                    return 1;
                }
            }
-           if (flags & (MMU_READ_U | MMU_WRITE_U | MMU_READ_S | MMU_WRITE_S)) {
+           if (flags & (MMU_READ_U | MMU_WRITE_U | MMU_READ_S | MMU_WRITE_S | MMU_READI_U | MMU_READI_S)) {
                trig = 0;
-               if (!s && (flags & MMU_READ_U) && !rw)
+               if (!s && (flags & MMU_READ_U) && (rwi & 1))
+                   trig = 1;
+               if (!s && (flags & MMU_WRITE_U) && (rwi & 2))
+                   trig = 1;
+               if (s && (flags & MMU_READ_S) && (rwi & 1))
                    trig = 1;
-               if (!s && (flags & MMU_WRITE_U) && rw)
+               if (s && (flags & MMU_WRITE_S) && (rwi & 2))
                    trig = 1;
-               if (s && (flags & MMU_READ_S) && !rw)
+               if (!s && (flags & MMU_READI_U) && (rwi & 4))
                    trig = 1;
-               if (s && (flags & MMU_WRITE_S) && rw)
+               if (s && (flags & MMU_READI_S) && (rwi & 4))
                    trig = 1;
                if (trig) {
-                   mmu_do_hit_pre (md, addr, size, rw, *v);
+                   mmu_do_hit_pre (md, addr, size, rwi, *v);
                    return 1;
                }
            }
@@ -2329,6 +2343,6 @@ int mmu_init(int mode, uaecptr parm, uaecptr parm2)
     initialize_memwatch(1);
     console_out ("MMU: enabled, %d banks, CB=%08.8X S=%08.8X BNK=%08.8X SF=%08.8X, %d*%d\n",
        size - 1, mmu_callback, parm, banks, mmu_regs, mmu_slots, 1 << MMU_PAGE_SHIFT);
-    set_special (SPCFLAG_BRK);
+    set_special (&regs, SPCFLAG_BRK);
     return 1;
 }
diff --git a/disk.c b/disk.c
index d1eaf97264f80487e03c321bc50994a00b0f00ff..b29b4144da29cc309268c6e16205ba13701c9337 100755 (executable)
--- a/disk.c
+++ b/disk.c
@@ -15,9 +15,7 @@
 #include "sysdeps.h"
 
 #include "uae.h"
-#include "config.h"
 #include "options.h"
-#include "threaddep/thread.h"
 #include "memory.h"
 #include "events.h"
 #include "custom.h"
@@ -25,9 +23,7 @@
 #include "disk.h"
 #include "gui.h"
 #include "zfile.h"
-#include "autoconf.h"
 #include "newcpu.h"
-#include "xwin.h"
 #include "osemu.h"
 #include "execlib.h"
 #include "savestate.h"
@@ -474,7 +470,8 @@ static int createimagefromexe (struct zfile *src, struct zfile *dst)
 static int get_floppy_speed (void)
 {
     int m = currprefs.floppy_speed;
-    if (m <= 10) m = 100;
+    if (m <= 10)
+       m = 100;
     m = NORMAL_FLOPPY_SPEED * 100 / m;
     return m;
 }
@@ -2103,7 +2100,7 @@ void DISK_select (uae_u8 data)
     static int step;
 
     if (disk_debug_logging > 1)
-       write_log ("%08.8X %02.2X %s", m68k_getpc(), data, tobin(data));
+       write_log ("%08.8X %02.2X %s", M68K_GETPC, data, tobin(data));
 
     lastselected = selected;
     selected = (data >> 3) & 15;
@@ -2210,7 +2207,7 @@ uae_u8 DISK_status (void)
                    st &= ~0x20;
                /* dskrdy needs some cycles after switching the motor off.. (Pro Tennis Tour) */
                if (drv->motordelay) {
-                   write_log ("MOTORDELAY! %x\n", m68k_getpc());
+                   write_log ("MOTORDELAY! %x\n", M68K_GETPC);
                    st &= ~0x20;
                    drv->motordelay = 0;
                }
@@ -2561,7 +2558,7 @@ static void disk_doupdate_read (drive * drv, int floppybits)
 static void disk_dma_debugmsg(void)
 {
     write_log ("LEN=%04.4X (%d) SYNC=%04.4X PT=%08.8X ADKCON=%04.4X PC=%08.8X\n",
-       dsklength, dsklength, (adkcon & 0x400) ? dsksync : 0xffff, dskpt, adkcon, m68k_getpc());
+       dsklength, dsklength, (adkcon & 0x400) ? dsksync : 0xffff, dskpt, adkcon, M68K_GETPC);
 }
 
 #if 0
@@ -2729,9 +2726,9 @@ void DSKLEN (uae_u16 v, int hpos)
        if (dskdmaen) {
            /* Megalomania and Knightmare does this */
            if (disk_debug_logging > 0 && dskdmaen == 2)
-               write_log ("warning: Disk read DMA aborted, %d words left PC=%x\n", dsklength, m68k_getpc());
+               write_log ("warning: Disk read DMA aborted, %d words left PC=%x\n", dsklength, M68K_GETPC);
            if (dskdmaen == 3)
-               write_log ("warning: Disk write DMA aborted, %d words left PC=%x\n", dsklength, m68k_getpc());
+               write_log ("warning: Disk write DMA aborted, %d words left PC=%x\n", dsklength, M68K_GETPC);
            dskdmaen = 0;
        }
     }
@@ -2886,7 +2883,7 @@ void DSKDAT (uae_u16 v)
 #endif
     if (count < 5) {
        count++;
-       write_log ("%04.4X written to DSKDAT. Not good. PC=%08.8X", v, m68k_getpc());
+       write_log ("%04.4X written to DSKDAT. Not good. PC=%08.8X", v, M68K_GETPC);
        if (count == 5)
            write_log ("(further messages suppressed)");
 
@@ -2997,6 +2994,8 @@ end:
 
 /* Disk save/restore code */
 
+#if defined SAVESTATE || defined DEBUGGER
+
 void DISK_save_custom (uae_u32 *pdskpt, uae_u16 *pdsklength, uae_u16 *pdsksync, uae_u16 *pdskbytr)
 {
     if(pdskpt) *pdskpt = dskpt;
@@ -3005,6 +3004,10 @@ void DISK_save_custom (uae_u32 *pdskpt, uae_u16 *pdsklength, uae_u16 *pdsksync,
     if(pdskbytr) *pdskbytr = dskbytr_val;
 }
 
+#endif /* SAVESTATE || DEBUGGER */
+
+#ifdef SAVESTATE
+
 void DISK_restore_custom (uae_u32 pdskpt, uae_u16 pdsklength, uae_u16 pdskbytr)
 {
     dskpt = pdskpt;
@@ -3145,4 +3148,4 @@ uae_u8 *save_floppy(int *len, uae_u8 *dstptr)
     return dstbak;
 }
 
-
+#endif /* SAVESTATE */
index 1a129a57833258748f1039c0a4b4a30b1f322747..a1490c46a35b681ad31abff01a87299d0d876166 100755 (executable)
 
 
 static USHORT Process_Track(struct zfile *, struct zfile *, UCHAR *, UCHAR *, USHORT, USHORT, USHORT);
-static USHORT Unpack_Track(UCHAR *, UCHAR *, USHORT, USHORT, UCHAR, UCHAR);
+static USHORT Unpack_Track(UCHAR *, UCHAR *, USHORT, USHORT, UCHAR, UCHAR, USHORT, USHORT, USHORT);
 static void printbandiz(UCHAR *, USHORT);
-static void dms_decrypt(UCHAR *, USHORT);
 
+static int passfound, passretries;
 
 static char modes[7][7]={"NOCOMP","SIMPLE","QUICK ","MEDIUM","DEEP  ","HEAVY1","HEAVY2"};
 static USHORT PWDCRC;
 
 UCHAR *text;
 
-
+static void log_error(int track)
+{
+    write_log ("DMS: Ignored error on track %d!\n", track);
+}
 
 USHORT DMS_Process_File(struct zfile *fi, struct zfile *fo, USHORT cmd, USHORT opt, USHORT PCRC, USHORT pwd){
        USHORT from, to, geninfo, c_version, cmode, hcrc, disktype, pv, ret;
@@ -55,6 +58,8 @@ USHORT DMS_Process_File(struct zfile *fi, struct zfile *fo, USHORT cmd, USHORT o
        time_t date;
 
 
+       passfound = 0;
+       passretries = 2;
        b1 = (UCHAR *)calloc((size_t)TRACK_BUFFER_LEN,1);
        if (!b1) return ERR_NOMEMORY;
        b2 = (UCHAR *)calloc((size_t)TRACK_BUFFER_LEN,1);
@@ -195,8 +200,8 @@ USHORT DMS_Process_File(struct zfile *fi, struct zfile *fo, USHORT cmd, USHORT o
                write_log(" ------  -------  -------  ------  ----  ----  ---- -----\n");
        }
 
-       if (((cmd==CMD_UNPACK) || (cmd==CMD_SHOWBANNER)) && (geninfo & 2) && (!pwd))
-               return ERR_NOPASSWD;
+//     if (((cmd==CMD_UNPACK) || (cmd==CMD_SHOWBANNER)) && (geninfo & 2) && (!pwd))
+//             return ERR_NOPASSWD;
 
        ret=NO_PROBLEM;
 
@@ -232,7 +237,7 @@ USHORT DMS_Process_File(struct zfile *fi, struct zfile *fo, USHORT cmd, USHORT o
 
 
 static USHORT Process_Track(struct zfile *fi, struct zfile *fo, UCHAR *b1, UCHAR *b2, USHORT cmd, USHORT opt, USHORT pwd){
-       USHORT hcrc, dcrc, usum, number, pklen1, pklen2, unpklen, l, r;
+       USHORT hcrc, dcrc, usum, number, pklen1, pklen2, unpklen, l;
        UCHAR cmode, flags;
 
 
@@ -279,48 +284,28 @@ static USHORT Process_Track(struct zfile *fi, struct zfile *fo, UCHAR *b1, UCHAR
 
        if (zfile_fread(b1,1,(size_t)pklen1,fi) != pklen1) return ERR_SREAD;
 
-       if (CreateCRC(b1,(ULONG)pklen1) != dcrc) return ERR_TDCRC;
-
+       if (CreateCRC(b1,(ULONG)pklen1) != dcrc) {
+           log_error (number);
+           //return ERR_TDCRC;
+       }
        /*  track 80 is FILEID.DIZ, track 0xffff (-1) is Banner  */
        /*  and track 0 with 1024 bytes only is a fake boot block with more advertising */
        /*  FILE_ID.DIZ is never encrypted  */
 
-       if (pwd && (number!=80)) dms_decrypt(b1,pklen1);
+       //if (pwd && (number!=80)) dms_decrypt(b1,pklen1);
 
        if ((cmd == CMD_UNPACK) && (number<80) && (unpklen>2048)) {
-               r = Unpack_Track(b1, b2, pklen2, unpklen, cmode, flags);
-               if (r != NO_PROBLEM)
-                       if (pwd)
-                               return ERR_BADPASSWD;
-                       else
-                               return r;
-               if (usum != Calc_CheckSum(b2,(ULONG)unpklen))
-                       if (pwd)
-                               return ERR_BADPASSWD;
-                       else
-                               return ERR_CSUM;
+               Unpack_Track(b1, b2, pklen2, unpklen, cmode, flags, number, pklen1, usum);
                if (zfile_fwrite(b2,1,(size_t)unpklen,fo) != unpklen) return ERR_CANTWRITE;
        }
 
        if ((cmd == CMD_SHOWBANNER) && (number == 0xffff)){
-               r = Unpack_Track(b1, b2, pklen2, unpklen, cmode, flags);
-               if (r != NO_PROBLEM)
-                       if (pwd)
-                               return ERR_BADPASSWD;
-                       else
-                               return r;
-               if (usum != Calc_CheckSum(b2,(ULONG)unpklen))
-                       if (pwd)
-                               return ERR_BADPASSWD;
-                       else
-                               return ERR_CSUM;
+               Unpack_Track(b1, b2, pklen2, unpklen, cmode, flags, number, pklen1, usum);
                printbandiz(b2,unpklen);
        }
 
        if ((cmd == CMD_SHOWDIZ) && (number == 80)) {
-               r = Unpack_Track(b1, b2, pklen2, unpklen, cmode, flags);
-               if (r != NO_PROBLEM) return r;
-               if (usum != Calc_CheckSum(b2,(ULONG)unpklen)) return ERR_CSUM;
+               Unpack_Track(b1, b2, pklen2, unpklen, cmode, flags, number, pklen1, usum);
                printbandiz(b2,unpklen);
        }
 
@@ -330,7 +315,7 @@ static USHORT Process_Track(struct zfile *fi, struct zfile *fo, UCHAR *b1, UCHAR
 
 
 
-static USHORT Unpack_Track(UCHAR *b1, UCHAR *b2, USHORT pklen2, USHORT unpklen, UCHAR cmode, UCHAR flags){
+static USHORT Unpack_Track_2(UCHAR *b1, UCHAR *b2, USHORT pklen2, USHORT unpklen, UCHAR cmode, UCHAR flags){
        switch (cmode){
                case 0:
                        /*   No Compression   */
@@ -384,22 +369,78 @@ static USHORT Unpack_Track(UCHAR *b1, UCHAR *b2, USHORT pklen2, USHORT unpklen,
 
 }
 
-
 /*  DMS uses a lame encryption  */
-static void dms_decrypt(UCHAR *p, USHORT len){
+static void dms_decrypt(UCHAR *p, USHORT len, UCHAR *src){
        USHORT t;
 
        while (len--){
-               t = (USHORT) *p;
-               *p++ ^= (UCHAR)PWDCRC;
+               t = (USHORT) *src++;
+               *p++ = t ^ (UCHAR)PWDCRC;
                PWDCRC = (USHORT)((PWDCRC >> 1) + t);
        }
 }
 
+static USHORT Unpack_Track(UCHAR *b1, UCHAR *b2, USHORT pklen2, USHORT unpklen, UCHAR cmode, UCHAR flags, USHORT number, USHORT pklen1, USHORT usum1)
+{
+    USHORT r, err = NO_PROBLEM, prevpass;
+    static USHORT pass;
+    int maybeencrypted;
+    int pwrounds;
+    UCHAR *tmp;
+
+    if (passfound) {
+       if (number != 80)
+           dms_decrypt(b1, pklen1, b1);
+       r = Unpack_Track_2(b1, b2, pklen2, unpklen, cmode, flags);
+       if (r == NO_PROBLEM) {
+           if (usum1 == Calc_CheckSum(b2,(ULONG)unpklen))
+               return NO_PROBLEM;
+       }
+       log_error(number);
+       if (passretries <= 0)
+           return ERR_CSUM;
+    }
+
+    passretries--;
+    pwrounds = 0;
+    maybeencrypted = 0;
+    tmp = malloc (pklen1);
+    memcpy (tmp, b1, pklen1);
+    for (;;) {
+       r = Unpack_Track_2(b1, b2, pklen2, unpklen, cmode, flags);
+       if (r == NO_PROBLEM) {
+           if (usum1 == Calc_CheckSum(b2,(ULONG)unpklen)) {
+               passfound = maybeencrypted;
+               if (passfound)
+                   write_log("DMS: decryption key = 0x%04.4X\n", pass);
+               err = NO_PROBLEM;
+               pass = prevpass;
+               break;
+           }
+       }
+       if (number == 80) {
+           err = ERR_CSUM;
+           break;
+       }
+       maybeencrypted = 1;
+       prevpass = pass;
+       PWDCRC = pass;
+       pass++;
+       dms_decrypt(b1, pklen1, tmp);
+       pwrounds++;
+       if (pwrounds == 65536) {
+           err = ERR_CSUM;
+           passfound = 0;
+           break;
+       }
+    }
+    free (tmp);
+    return err;
+}
 
 
 static void printbandiz(UCHAR *m, USHORT len){
-       UCHAR *i,*j;
+    UCHAR *i,*j;
 
        i=j=m;
        while (i<m+len) {
@@ -410,7 +451,6 @@ static void printbandiz(UCHAR *m, USHORT len){
                }
                i++;
        }
-
 }
 
 
index f632ab301b2fbd65452df728ca0712664a00cea5..304e3ed6e37382907e350a123a1e0e0e908888f6 100755 (executable)
--- a/drawing.c
+++ b/drawing.c
@@ -34,7 +34,6 @@
 #include <ctype.h>
 #include <assert.h>
 
-#include "config.h"
 #include "options.h"
 #include "threaddep/thread.h"
 #include "uae.h"
@@ -46,7 +45,9 @@
 #include "gui.h"
 #include "picasso96.h"
 #include "drawing.h"
+#ifdef JIT
 #include "compemu.h"
+#endif
 #include "savestate.h"
 
 int lores_factor, lores_shift;
@@ -115,13 +116,18 @@ union {
     uae_u32 apixels_l[MAX_PIXELS_PER_LINE * 2 / 4];
 } pixdata;
 
+#ifdef OS_WITHOUT_MEMORY_MANAGEMENT
+uae_u16 *spixels;
+#else
 uae_u16 spixels[2 * MAX_SPR_PIXELS];
+#endif
+
 /* Eight bits for every pixel.  */
 union sps_union spixstate;
 
 static uae_u32 ham_linebuf[MAX_PIXELS_PER_LINE * 2];
 
-char *xlinebuffer;
+uae_u8 *xlinebuffer;
 #ifdef XLINECHECK
 char *xlinebuffer_start, *xlinebuffer_end;
 static void xlinecheck (int start, int end)
@@ -139,7 +145,7 @@ static void xlinecheck (int start, int end)
 #endif
 
 static int *amiga2aspect_line_map, *native2amiga_line_map;
-static char *row_map[MAX_VIDHEIGHT + 1];
+static uae_u8 *row_map[MAX_VIDHEIGHT + 1];
 static int max_drawn_amiga_line;
 
 /* line_draw_funcs: pfield_do_linetoscr, pfield_do_fill_line, decode_ham */
@@ -177,6 +183,8 @@ static int last_redraw_point;
 static int first_drawn_line, last_drawn_line;
 static int first_block_line, last_block_line;
 
+#define NO_BLOCK -3
+
 /* These are generated by the drawing code from the line_decisions array for
    each line that needs to be drawn.  These are basically extracted out of
    bit fields in the hardware registers.  */
@@ -375,199 +383,55 @@ static uae_u32 merge_2pixel32(uae_u32 p1, uae_u32 p2)
     return v;
 }
 
-/* If C++ compilers didn't suck, we'd use templates.  */
-
-#define TYPE uae_u8
-#define PMERGE merge_2pixel8
-
-#define LNAME linetoscr_8
-#define SRC_INC 1
-#define HDOUBLE 0
-#define AGAC 0
-#define HMERGE 0
-#include "linetoscr.c"
-#define LNAME linetoscr_8_stretch1
-#define SRC_INC 1
-#define HDOUBLE 1
-#define AGAC 0
-#define HMERGE 0
-#include "linetoscr.c"
-#define LNAME linetoscr_8_shrink1
-#define SRC_INC 2
-#define HDOUBLE 0
-#define AGAC 0
-#define HMERGE 0
-#include "linetoscr.c"
-#define LNAME linetoscr_8_shrink2
-#define SRC_INC 2
-#define HDOUBLE 0
-#define AGAC 0
-#define HMERGE 1
-#include "linetoscr.c"
-
-#ifdef AGA
-#define LNAME linetoscr_8_aga
-#define SRC_INC 1
-#define HDOUBLE 0
-#define AGAC 1
-#define HMERGE 0
-#include "linetoscr.c"
-#define LNAME linetoscr_8_stretch1_aga
-#define SRC_INC 1
-#define HDOUBLE 1
-#define AGAC 1
-#define HMERGE 0
-#include "linetoscr.c"
-#define LNAME linetoscr_8_shrink1_aga
-#define SRC_INC 2
-#define HDOUBLE 0
-#define AGAC 1
-#define HMERGE 0
-#include "linetoscr.c"
-#define LNAME linetoscr_8_shrink2_aga
-#define SRC_INC 2
-#define HDOUBLE 0
-#define AGAC 1
-#define HMERGE 1
-#include "linetoscr.c"
-#endif
-
-#undef TYPE
-#undef PMERGE
-#define TYPE uae_u16
-#define PMERGE merge_2pixel16
-
-#define LNAME linetoscr_16
-#define SRC_INC 1
-#define HDOUBLE 0
-#define AGAC 0
-#define HMERGE 0
-#include "linetoscr.c"
-#define LNAME linetoscr_16_stretch1
-#define SRC_INC 1
-#define HDOUBLE 1
-#define AGAC 0
-#define HMERGE 0
-#include "linetoscr.c"
-#define LNAME linetoscr_16_shrink1
-#define SRC_INC 2
-#define HDOUBLE 0
-#define AGAC 0
-#define HMERGE 0
-#include "linetoscr.c"
-#define LNAME linetoscr_16_shrink2
-#define SRC_INC 2
-#define HDOUBLE 0
-#define AGAC 0
-#define HMERGE 1
-#include "linetoscr.c"
-
-#ifdef AGA
-#define LNAME linetoscr_16_aga
-#define SRC_INC 1
-#define HDOUBLE 0
-#define AGAC 1
-#define HMERGE 0
-#include "linetoscr.c"
-#define LNAME linetoscr_16_stretch1_aga
-#define SRC_INC 1
-#define HDOUBLE 1
-#define AGAC 1
-#define HMERGE 0
-#include "linetoscr.c"
-#define LNAME linetoscr_16_shrink1_aga
-#define SRC_INC 2
-#define HDOUBLE 0
-#define AGAC 1
-#define HMERGE 0
-#include "linetoscr.c"
-#define LNAME linetoscr_16_shrink2_aga
-#define SRC_INC 2
-#define HDOUBLE 0
-#define AGAC 1
-#define HMERGE 1
-#include "linetoscr.c"
-#endif
-
-#undef TYPE
-#undef PMERGE
-#define TYPE uae_u32
-#define PMERGE merge_2pixel32
-
-#define LNAME linetoscr_32
-#define SRC_INC 1
-#define HDOUBLE 0
-#define AGAC 0
-#define HMERGE 0
-#include "linetoscr.c"
-#define LNAME linetoscr_32_stretch1
-#define SRC_INC 1
-#define HDOUBLE 1
-#define AGAC 0
-#define HMERGE 0
-#include "linetoscr.c"
-#define LNAME linetoscr_32_shrink1
-#define SRC_INC 2
-#define HDOUBLE 0
-#define AGAC 0
-#define HMERGE 0
-#include "linetoscr.c"
-#define LNAME linetoscr_32_shrink2
-#define SRC_INC 2
-#define HDOUBLE 0
-#define AGAC 0
-#define HMERGE 1
-#include "linetoscr.c"
-
-#ifdef AGA
-#define LNAME linetoscr_32_aga
-#define SRC_INC 1
-#define HDOUBLE 0
-#define AGAC 1
-#define HMERGE 0
-#include "linetoscr.c"
-#define LNAME linetoscr_32_stretch1_aga
-#define SRC_INC 1
-#define HDOUBLE 1
-#define AGAC 1
-#define HMERGE 0
-#include "linetoscr.c"
-#define LNAME linetoscr_32_shrink1_aga
-#define SRC_INC 2
-#define HDOUBLE 0
-#define AGAC 1
-#define HMERGE 0
-#include "linetoscr.c"
-#define LNAME linetoscr_32_shrink2_aga
-#define SRC_INC 2
-#define HDOUBLE 0
-#define AGAC 1
-#define HMERGE 1
-#include "linetoscr.c"
-#endif
-
-#undef TYPE
-
-static void fill_line_8 (char *buf, int start, int stop)
+static void fill_line_8 (uae_u8 *buf, unsigned int start, unsigned int stop)
 {
     uae_u8 *b = (uae_u8 *)buf;
-    int i;
+    unsigned int i;
+    unsigned int rem = 0;
     xcolnr col = brdblank ? 0 : colors_for_drawing.acolors[0];
-    for (i = start; i < stop; i++)
-       b[i] = (uae_u8)col;
+    while (((long)&b[start]) & 3) {
+       b[start++] = (uae_u8)col;
+       if (start == stop)
+          return;
+    }
+    if (((long)&b[stop]) & 3) {
+       rem = ((long)&b[stop]) & 3;
+       stop -= rem;
+    }
+    for (i = start; i < stop; i += 4) {
+       uae_u32 *b2 = (uae_u32 *)&b[i];
+       *b2 = col;
+    }
+    while (rem--)
+       b[stop++] = (uae_u8) col;
 }
-static void fill_line_16 (char *buf, int start, int stop)
+
+static void fill_line_16 (uae_u8 *buf, unsigned int start, unsigned int stop)
 {
     uae_u16 *b = (uae_u16 *)buf;
-    int i;
+    unsigned int i;
+    unsigned int rem = 0;
     xcolnr col = brdblank ? 0 : colors_for_drawing.acolors[0];
-    for (i = start; i < stop; i++)
-       b[i] = (uae_u16)col;
+    if (((long)&b[start]) & 1)
+       b[start++] = (uae_u16) col;
+    if (start >= stop)
+       return;
+    if (((long)&b[stop]) & 1) {
+       rem++;
+       stop--;
+    }
+    for (i = start; i < stop; i += 2) {
+       uae_u32 *b2 = (uae_u32 *)&b[i];
+       *b2 = col;
+    }
+    if (rem)
+       b[stop] = (uae_u16)col;
 }
-static void fill_line_32 (char *buf, int start, int stop)
+
+static void fill_line_32 (uae_u8 *buf, unsigned int start, unsigned int stop)
 {
     uae_u32 *b = (uae_u32 *)buf;
-    int i;
+    unsigned int i;
     xcolnr col = brdblank ? 0 : colors_for_drawing.acolors[0];
     for (i = start; i < stop; i++)
        b[i] = col;
@@ -595,8 +459,6 @@ STATIC_INLINE void fill_line (void)
 #else
     val = colors_for_drawing.acolors[0];
 #endif
-    if (gfxvidinfo.pixbytes == 2)
-       val |= val << 16;
     for (; nints > 0; nints -= 8, start += 8) {
        *start = val;
        *(start+1) = val;
@@ -628,6 +490,8 @@ STATIC_INLINE void fill_line (void)
 
 static int linetoscr_double_offset;
 
+#include "linetoscr.c"
+
 static void pfield_do_linetoscr (int start, int stop)
 {
 #ifdef AGA
@@ -701,18 +565,6 @@ static void pfield_do_fill_line (int start, int stop)
     }
 }
 
-static void pfield_do_linetoscr_full (int double_line)
-{
-    char *oldxlb = (char *)xlinebuffer;
-    int old_src_pixel = src_pixel;
-
-    xlinecheck(playfield_start, playfield_end);
-    pfield_do_linetoscr (playfield_start, playfield_end);
-    xlinebuffer = oldxlb + linetoscr_double_offset;
-    src_pixel = old_src_pixel;
-    pfield_do_linetoscr (playfield_start, playfield_end);
-}
-
 static void dummy_worker (int start, int stop)
 {
 }
@@ -1243,6 +1095,10 @@ static void init_aspect_maps (void)
     int i, maxl;
     double native_lines_per_amiga_line;
 
+    if (gfxvidinfo.height == 0)
+       /* Do nothing if the gfx driver hasn't initialized the screen yet */
+       return;
+
     if (native2amiga_line_map)
        free (native2amiga_line_map);
     if (amiga2aspect_line_map)
@@ -1323,15 +1179,15 @@ static void do_flush_line_1 (int lineno)
     if (gfxvidinfo.maxblocklines == 0)
        flush_line (lineno);
     else {
-       if ((last_block_line+1) != lineno) {
-           if (first_block_line != -2)
+       if ((last_block_line + 2) < lineno) {
+           if (first_block_line != NO_BLOCK)
                flush_block (first_block_line, last_block_line);
            first_block_line = lineno;
        }
        last_block_line = lineno;
        if (last_block_line - first_block_line >= gfxvidinfo.maxblocklines) {
            flush_block (first_block_line, last_block_line);
-           first_block_line = last_block_line = -2;
+           first_block_line = last_block_line = NO_BLOCK;
        }
     }
 }
@@ -1353,7 +1209,7 @@ STATIC_INLINE void do_flush_screen (int start, int stop)
        Should be corrected.
        (sjo 26.9.99) */
 
-    if (gfxvidinfo.maxblocklines != 0 && first_block_line != -2) {
+    if (gfxvidinfo.maxblocklines != 0 && first_block_line != NO_BLOCK) {
        flush_block (first_block_line, last_block_line);
     }
     unlockscr ();
@@ -1857,7 +1713,7 @@ static void init_drawing_frame (void)
     last_drawn_line = 0;
     first_drawn_line = 32767;
 
-    first_block_line = last_block_line = -2;
+    first_block_line = last_block_line = NO_BLOCK;
     if (currprefs.test_drawing_speed)
        frame_redraw_necessary = 1;
     else if (frame_redraw_necessary)
@@ -1895,7 +1751,7 @@ static int td_pos = (TD_RIGHT|TD_BOTTOM);
 
 #define TD_BORDER 0x333
 
-static char *numbers = { /* ugly  0123456789CHD% */
+static const char *numbers = { /* ugly  0123456789CHD% */
 "+++++++--++++-+++++++++++++++++-++++++++++++++++++++++++++++++++++++++++++++-++++++-++++----++---+"
 "+xxxxx+--+xx+-+xxxxx++xxxxx++x+-+x++xxxxx++xxxxx++xxxxx++xxxxx++xxxxx++xxxx+-+x++x+-+xxx++-+xx+-+x"
 "+x+++x+--++x+-+++++x++++++x++x+++x++x++++++x++++++++++x++x+++x++x+++x++x++++-+x++x+-+x++x+--+x++x+"
@@ -1933,7 +1789,7 @@ STATIC_INLINE void putpixel (int x, xcolnr c8)
 static void write_tdnumber (int x, int y, int num)
 {
     int j;
-    uae_u8 *numptr;
+    const char *numptr;
 
     numptr = numbers + num * TD_NUM_WIDTH + NUMBERS_NUM * TD_NUM_WIDTH * y;
     for (j = 0; j < TD_NUM_WIDTH; j++) {
@@ -2160,6 +2016,7 @@ void vsync_handle_redraw (int long_frame, int lof_changed)
         * done at other times.
         */
 
+#ifdef SAVESTATE
        if (savestate_state == STATE_DORESTORE) {
            savestate_state = STATE_RESTORE;
            reset_drawing ();
@@ -2169,18 +2026,21 @@ void vsync_handle_redraw (int long_frame, int lof_changed)
            reset_drawing ();
            uae_reset (0);
        }
+#endif
 
        if (quit_program < 0) {
            quit_program = -quit_program;
            set_inhibit_frame (IHF_QUIT_PROGRAM);
-           set_special (SPCFLAG_BRK);
+           set_special (&regs, SPCFLAG_BRK);
 #ifdef FILESYS
            filesys_prepare_reset ();
 #endif
            return;
        }
 
+#ifdef SAVESTATE
        savestate_capture (0);
+#endif
        count_frame ();
        check_picasso ();
 
@@ -2193,7 +2053,9 @@ void vsync_handle_redraw (int long_frame, int lof_changed)
        }
 
        check_prefs_changed_audio ();
+#ifdef JIT
        check_prefs_changed_comp ();
+#endif
        check_prefs_changed_custom ();
        check_prefs_changed_cpu ();
 
@@ -2252,6 +2114,41 @@ void hsync_record_line_state (int lineno, enum nln_how how, int changed)
     }
 }
 
+static void dummy_flush_line (struct vidbuf_description *gfxinfo, int line_no)
+{
+}
+
+static void dummy_flush_block (struct vidbuf_description *gfxinfo, int first_line, int last_line)
+{
+}
+
+static void dummy_flush_screen (struct vidbuf_description *gfxinfo, int first_line, int last_line)
+{
+}
+
+static void dummy_flush_clear_screen (struct vidbuf_description *gfxinfo)
+{
+}
+
+static int  dummy_lock (struct vidbuf_description *gfxinfo)
+{
+    return 1;
+}
+
+static void dummy_unlock (struct vidbuf_description *gfxinfo)
+{
+}
+
+static void gfxbuffer_reset (void)
+{
+    gfxvidinfo.flush_line         = dummy_flush_line;
+    gfxvidinfo.flush_block        = dummy_flush_block;
+    gfxvidinfo.flush_screen       = dummy_flush_screen;
+    gfxvidinfo.flush_clear_screen = dummy_flush_clear_screen;
+    gfxvidinfo.lockscr            = dummy_lock;
+    gfxvidinfo.unlockscr          = dummy_unlock;
+}
+
 void notice_interlace_seen (void)
 {
     interlace_seen = 1;
@@ -2260,7 +2157,7 @@ void notice_interlace_seen (void)
 
 void reset_drawing (void)
 {
-    int i;
+    unsigned int i;
 
     max_diwstop = 0;
 
@@ -2299,6 +2196,7 @@ void drawing_init (void)
     xlinebuffer = gfxvidinfo.bufmem;
     inhibit_frame = 0;
 
+    gfxbuffer_reset ();
     reset_drawing ();
 }
 
index d6661b466afa2e3f1baaeb90c287e8eb9afa72e3..634522d3acd0ef8c8affddbc3d7d57ed39c28c4b 100755 (executable)
@@ -12,7 +12,6 @@
 #ifdef DRIVESOUND
 
 #include "uae.h"
-#include "config.h"
 #include "options.h"
 #include "sounddep/sound.h"
 #include "zfile.h"
index 3e06068e789f77cd247e8738e6e10178b0f9a1ba..5b4cdd98ea1687fa9a32af89aada83192763e843 100755 (executable)
@@ -46,21 +46,21 @@ static int enforcer_hit = 0; /* set to 1 if displaying the hit */
 #define ENFORCER_BUF_SIZE 4096
 static char enforcer_buf[ENFORCER_BUF_SIZE];
 
-uae_u32 REGPARAM2 (*saved_chipmem_lget) (uaecptr addr);
-uae_u32 REGPARAM2 (*saved_chipmem_wget) (uaecptr addr);
-uae_u32 REGPARAM2 (*saved_chipmem_bget) (uaecptr addr);
-void REGPARAM2  (*saved_chipmem_lput) (uaecptr addr, uae_u32 l);
-void REGPARAM2  (*saved_chipmem_wput) (uaecptr addr, uae_u32 w);
-void REGPARAM2  (*saved_chipmem_bput) (uaecptr addr, uae_u32 b);
-int REGPARAM2 (*saved_chipmem_check) (uaecptr addr, uae_u32 size);
-uae_u8 * REGPARAM2 (*saved_chipmem_xlate) (uaecptr addr);
-uae_u32 REGPARAM2 (*saved_dummy_lget) (uaecptr addr);
-uae_u32 REGPARAM2 (*saved_dummy_wget) (uaecptr addr);
-uae_u32 REGPARAM2 (*saved_dummy_bget) (uaecptr addr);
-void REGPARAM2 (*saved_dummy_lput) (uaecptr addr, uae_u32 l);
-void REGPARAM2 (*saved_dummy_wput) (uaecptr addr, uae_u32 w);
-void REGPARAM2 (*saved_dummy_bput) (uaecptr addr, uae_u32 b);
-int REGPARAM2 (*saved_dummy_check) (uaecptr addr, uae_u32 size);
+uae_u32 (REGPARAM3 *saved_chipmem_lget) (uaecptr addr);
+uae_u32 (REGPARAM3 *saved_chipmem_wget) (uaecptr addr);
+uae_u32 (REGPARAM3 *saved_chipmem_bget) (uaecptr addr);
+void (REGPARAM3 *saved_chipmem_lput) (uaecptr addr, uae_u32 l);
+void (REGPARAM3 *saved_chipmem_wput) (uaecptr addr, uae_u32 w);
+void (REGPARAM3 *saved_chipmem_bput) (uaecptr addr, uae_u32 b);
+int (REGPARAM3 *saved_chipmem_check) (uaecptr addr, uae_u32 size);
+uae_u8 *(REGPARAM3 *saved_chipmem_xlate) (uaecptr addr);
+uae_u32 (REGPARAM3 *saved_dummy_lget) (uaecptr addr);
+uae_u32 (REGPARAM3 *saved_dummy_wget) (uaecptr addr);
+uae_u32 (REGPARAM3 *saved_dummy_bget) (uaecptr addr);
+void (REGPARAM3 *saved_dummy_lput) (uaecptr addr, uae_u32 l);
+void (REGPARAM3 *saved_dummy_wput) (uaecptr addr, uae_u32 w);
+void (REGPARAM3 *saved_dummy_bput) (uaecptr addr, uae_u32 b);
+int (REGPARAM3 *saved_dummy_check) (uaecptr addr, uae_u32 size);
 
 /*************************************************************
  Returns the first node entry of an exec list or 0 if
@@ -217,18 +217,18 @@ static void enforcer_display_hit(const char *addressmode, uae_u32 pc, uaecptr ad
 
        /* Data registers */
        sprintf(enforcer_buf_ptr,"Data: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
-               m68k_dreg (regs, 0), m68k_dreg (regs, 1), m68k_dreg (regs, 2), m68k_dreg (regs, 3),
-               m68k_dreg (regs, 4), m68k_dreg (regs, 5), m68k_dreg (regs, 6), m68k_dreg (regs, 7));
+               m68k_dreg (&regs, 0), m68k_dreg (&regs, 1), m68k_dreg (&regs, 2), m68k_dreg (&regs, 3),
+               m68k_dreg (&regs, 4), m68k_dreg (&regs, 5), m68k_dreg (&regs, 6), m68k_dreg (&regs, 7));
        enforcer_buf_ptr += strlen(enforcer_buf_ptr);
 
        /* Address registers */
        sprintf(enforcer_buf_ptr,"Addr: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
-               m68k_areg (regs, 0), m68k_areg (regs, 1), m68k_areg (regs, 2), m68k_areg (regs, 3),
-               m68k_areg (regs, 4), m68k_areg (regs, 5), m68k_areg (regs, 6), m68k_areg (regs, 7));
+               m68k_areg (&regs, 0), m68k_areg (&regs, 1), m68k_areg (&regs, 2), m68k_areg (&regs, 3),
+               m68k_areg (&regs, 4), m68k_areg (&regs, 5), m68k_areg (&regs, 6), m68k_areg (&regs, 7));
        enforcer_buf_ptr += strlen(enforcer_buf_ptr);
 
        /* Stack */
-       a7 = m68k_areg(regs,7);
+       a7 = m68k_areg(&regs,7);
        for (i = 0; i < 8 * STACKLINES; i++)
        {
                a7 -= 4;
@@ -245,7 +245,7 @@ static void enforcer_display_hit(const char *addressmode, uae_u32 pc, uaecptr ad
        }
 
        /* Segtracker output */
-       a7 = m68k_areg(regs,7);
+       a7 = m68k_areg(&regs,7);
        if (get_long(a7-4) != pc)
        {
                if (enforcer_decode_hunk_and_offset(buf,pc))
@@ -388,7 +388,7 @@ uae_u32 REGPARAM2 chipmem_lget2 (uaecptr addr)
                enforcer_display_hit("LONG READ from",(uae_u32)(regs.pc_p - NMEM_OFFSET),addr);
        if (enforcermode & 1)
                        {
-                       set_special (SPCFLAG_TRAP);
+                       set_special (&regs, SPCFLAG_TRAP);
                        }
                }
     return do_get_mem_long (m);
@@ -407,7 +407,7 @@ uae_u32 REGPARAM2 chipmem_wget2(uaecptr addr)
                enforcer_display_hit("WORD READ from",(uae_u32)(regs.pc_p - NMEM_OFFSET),addr);
        if (enforcermode & 1)
                        {
-                       set_special (SPCFLAG_TRAP);
+                       set_special (&regs, SPCFLAG_TRAP);
                        }
        }
     return do_get_mem_word (m);
@@ -423,7 +423,7 @@ uae_u32 REGPARAM2 chipmem_bget2 (uaecptr addr)
                enforcer_display_hit("BYTE READ from",(uae_u32)(regs.pc_p - NMEM_OFFSET),addr);
                if (enforcermode & 1)
                {
-               set_special (SPCFLAG_TRAP);
+               set_special (&regs, SPCFLAG_TRAP);
                }
        }
 
@@ -443,7 +443,7 @@ void REGPARAM2 chipmem_lput2 (uaecptr addr, uae_u32 l)
                enforcer_display_hit("LONG WRITE to",(uae_u32)(regs.pc_p - NMEM_OFFSET),addr);
                if (enforcermode & 1)
                {
-               if ( addr!=0x100 ) set_special (SPCFLAG_TRAP);
+               if ( addr!=0x100 ) set_special (&regs, SPCFLAG_TRAP);
                }
        }
     do_put_mem_long (m, l);
@@ -462,7 +462,7 @@ void REGPARAM2 chipmem_wput2 (uaecptr addr, uae_u32 w)
                enforcer_display_hit("WORD WRITE to",(uae_u32)(regs.pc_p - NMEM_OFFSET),addr);
        if (enforcermode & 1)
        {
-               set_special (SPCFLAG_TRAP);
+               set_special (&regs, SPCFLAG_TRAP);
        }
        }
     do_put_mem_word (m, w);
@@ -478,7 +478,7 @@ void REGPARAM2 chipmem_bput2 (uaecptr addr, uae_u32 b)
                enforcer_display_hit("BYTE WRITE to",(uae_u32)(regs.pc_p - NMEM_OFFSET),addr);
                        if (enforcermode & 1)
                        {
-                       set_special (SPCFLAG_TRAP);
+                       set_special (&regs, SPCFLAG_TRAP);
                        }
        }
     chipmemory[addr] = b;
@@ -504,7 +504,7 @@ uae_u32 REGPARAM2 dummy_lget2 (uaecptr addr)
        enforcer_display_hit("LONG READ from",(uae_u32)(regs.pc_p - NMEM_OFFSET), addr);
        if (enforcermode & 1)
        {
-               set_special (SPCFLAG_TRAP);
+               set_special (&regs, SPCFLAG_TRAP);
                return 0;
        }
        return 0xbadedeef;
@@ -533,7 +533,7 @@ uae_u32 REGPARAM2 dummy_wget2 (uaecptr addr)
        enforcer_display_hit("WORD READ from",(uae_u32)(regs.pc_p - NMEM_OFFSET),addr);
        if (enforcermode & 1)
        {
-                       set_special (SPCFLAG_TRAP);
+                       set_special (&regs, SPCFLAG_TRAP);
                        return 0;
        }
        return 0xbadf;
@@ -545,7 +545,7 @@ uae_u32     REGPARAM2 dummy_bget2 (uaecptr addr)
        enforcer_display_hit("BYTE READ from",(uae_u32)(regs.pc_p - NMEM_OFFSET),addr);
        if (enforcermode & 1)
        {
-               set_special (SPCFLAG_TRAP);
+               set_special (&regs, SPCFLAG_TRAP);
                return 0;
        }
        return 0xbadedeef;
@@ -557,7 +557,7 @@ void REGPARAM2 dummy_lput2 (uaecptr addr, uae_u32 l)
        enforcer_display_hit("LONG WRITE to",(uae_u32)(regs.pc_p - NMEM_OFFSET),addr);
     if (enforcermode & 1)
        {
-           set_special (SPCFLAG_TRAP);
+           set_special (&regs, SPCFLAG_TRAP);
                return;
        }
 }
@@ -568,7 +568,7 @@ void REGPARAM2 dummy_wput2 (uaecptr addr, uae_u32 w)
        enforcer_display_hit("WORD WRITE to",(uae_u32)(regs.pc_p - NMEM_OFFSET),addr);
     if (enforcermode & 1)
        {
-               set_special (SPCFLAG_TRAP);
+               set_special (&regs, SPCFLAG_TRAP);
                return;
        }
 }
@@ -579,7 +579,7 @@ void REGPARAM2 dummy_bput2 (uaecptr addr, uae_u32 b)
        enforcer_display_hit("BYTE WRITE to",(uae_u32)(regs.pc_p - NMEM_OFFSET),addr);
        if (enforcermode & 1)
        {
-               set_special (SPCFLAG_TRAP);
+               set_special (&regs, SPCFLAG_TRAP);
                return;
        }
 }
index f68a44c2dcb1a2b4fc5bda83dd2113e76c5e777c..180465caf181d8b1804db30ad08671b6746233e3 100755 (executable)
--- a/ersatz.c
+++ b/ersatz.c
@@ -10,7 +10,6 @@
 #include "sysconfig.h"
 #include "sysdeps.h"
 
-#include "config.h"
 #include "options.h"
 #include "uae.h"
 #include "memory.h"
@@ -80,7 +79,7 @@ static void ersatz_failed (void)
 
 static void ersatz_doio (void)
 {
-    uaecptr request = m68k_areg(regs, 1);
+    uaecptr request = m68k_areg(&regs, 1);
     switch (get_word (request + 0x1C)) {
      case 9: /* TD_MOTOR is harmless */
      case 2: case 0x8002: /* READ commands */
@@ -126,11 +125,11 @@ static void ersatz_init (void)
        put_long (a, 0xF8001A);
     }
     regs.isp = regs.msp = regs.usp = 0x800;
-    m68k_areg(regs, 7) = 0x80000;
+    m68k_areg(&regs, 7) = 0x80000;
     regs.intmask = 0;
 
     /* Build a dummy execbase */
-    put_long (4, m68k_areg(regs, 6) = 0x676);
+    put_long (4, m68k_areg(&regs, 6) = 0x676);
     put_byte (0x676 + 0x129, 0);
     for (f = 1; f < 105; f++) {
        put_word (0x676 - 6*f, 0x4EF9);
@@ -149,7 +148,7 @@ static void ersatz_init (void)
     put_long (request + 0x28, 0x4000);
     put_long (request + 0x2C, 0);
     put_long (request + 0x24, 0x200 * 4);
-    m68k_areg(regs, 1) = request;
+    m68k_areg(&regs, 1) = request;
     ersatz_doio ();
     /* kickstart disk loader */
     if (get_long(0x4000) == 0x4b49434b) {
@@ -163,7 +162,7 @@ static void ersatz_init (void)
        put_long (request + 0x28, 0xF80000);
        put_long (request + 0x2C, 0x200);
        put_long (request + 0x24, 0x200 * 512);
-       m68k_areg(regs, 1) = request;
+       m68k_areg(&regs, 1) = request;
        ersatz_doio ();
 
        /* read rom image once again to mirror address space.
@@ -172,20 +171,20 @@ static void ersatz_init (void)
        put_long (request + 0x28, 0xFC0000);
        put_long (request + 0x2C, 0x200);
        put_long (request + 0x24, 0x200 * 512);
-       m68k_areg(regs, 1) = request;
+       m68k_areg(&regs, 1) = request;
        ersatz_doio ();
 
        disk_eject (0);
 
-       m68k_setpc (0xFC0002);
-       fill_prefetch_slow ();
+       m68k_setpc (&regs, 0xFC0002);
+       fill_prefetch_slow (&regs);
        uae_reset (0);
        ersatzkickfile = 0;
        return;
     }
 
-    m68k_setpc (0x400C);
-    fill_prefetch_slow ();
+    m68k_setpc (&regs, 0x400C);
+    fill_prefetch_slow (&regs);
 
     /* Init the hardware */
     put_long (0x3000, 0xFFFFFFFEul);
@@ -226,15 +225,15 @@ void ersatz_perform (uae_u16 what)
        break;
 
      case EOP_AVAILMEM:
-       m68k_dreg(regs, 0) = m68k_dreg(regs, 1) & 4 ? 0 : 0x70000;
+       m68k_dreg(&regs, 0) = m68k_dreg(&regs, 1) & 4 ? 0 : 0x70000;
        break;
 
      case EOP_ALLOCMEM:
-       m68k_dreg(regs, 0) = m68k_dreg(regs, 1) & 4 ? 0 : 0x0F000;
+       m68k_dreg(&regs, 0) = m68k_dreg(&regs, 1) & 4 ? 0 : 0x0F000;
        break;
 
      case EOP_ALLOCABS:
-       m68k_dreg(regs, 0) = m68k_areg(regs, 1);
+       m68k_dreg(&regs, 0) = m68k_areg(&regs, 1);
        break;
 
      case EOP_NIMP:
@@ -243,7 +242,7 @@ void ersatz_perform (uae_u16 what)
        
        /* fall through */
      case EOP_LOOP:
-       m68k_setpc (0xF80010);
+       m68k_setpc (&regs, 0xF80010);
        break;
 
      case EOP_OPENLIB:
index 28dee526c973db08505139163d51afde87c4040d..81d9dba78831171a9c712651f2a528d788994a74 100755 (executable)
 #include "sysconfig.h"
 #include "sysdeps.h"
 
-#include "config.h"
 #include "options.h"
 #include "uae.h"
 #include "memory.h"
 #include "autoconf.h"
-#include "picasso96.h"
 #include "custom.h"
 #include "newcpu.h"
 #include "savestate.h"
@@ -180,12 +178,12 @@ static void expamem_init_clear2 (void)
     ecard = MAX_EXPANSION_BOARDS - 1;
 }
 
-static uae_u32 expamem_lget (uaecptr) REGPARAM;
-static uae_u32 expamem_wget (uaecptr) REGPARAM;
-static uae_u32 expamem_bget (uaecptr) REGPARAM;
-static void expamem_lput (uaecptr, uae_u32) REGPARAM;
-static void expamem_wput (uaecptr, uae_u32) REGPARAM;
-static void expamem_bput (uaecptr, uae_u32) REGPARAM;
+static uae_u32 REGPARAM3 expamem_lget (uaecptr) REGPARAM;
+static uae_u32 REGPARAM3 expamem_wget (uaecptr) REGPARAM;
+static uae_u32 REGPARAM3 expamem_bget (uaecptr) REGPARAM;
+static void REGPARAM3 expamem_lput (uaecptr, uae_u32) REGPARAM;
+static void REGPARAM3 expamem_wput (uaecptr, uae_u32) REGPARAM;
+static void REGPARAM3 expamem_bput (uaecptr, uae_u32) REGPARAM;
 
 addrbank expamem_bank = {
     expamem_lget, expamem_wget, expamem_bget,
@@ -260,7 +258,7 @@ static void REGPARAM2 expamem_wput (uaecptr addr, uae_u32 value)
         case 0x44:
            if (expamem_type() == zorroIII) {
                // +Bernd Roesch
-               value = (value - 0x4000) + (z3fastmem_start >> 16); /* hack address */
+               value = (value - 0x4000) + (z3fastmem_start >> 16); /* hack address (TW) */
                chipmem_wput (regs.regs[11] + 0x20, value);
                chipmem_wput (regs.regs[11] + 0x28, value);
                // -Bernd Roesch
@@ -329,14 +327,14 @@ static void REGPARAM2 expamem_bput (uaecptr addr, uae_u32 value)
 
 static uae_u32 fastmem_mask;
 
-static uae_u32 fastmem_lget (uaecptr) REGPARAM;
-static uae_u32 fastmem_wget (uaecptr) REGPARAM;
-static uae_u32 fastmem_bget (uaecptr) REGPARAM;
-static void fastmem_lput (uaecptr, uae_u32) REGPARAM;
-static void fastmem_wput (uaecptr, uae_u32) REGPARAM;
-static void fastmem_bput (uaecptr, uae_u32) REGPARAM;
-static int fastmem_check (uaecptr addr, uae_u32 size) REGPARAM;
-static uae_u8 *fastmem_xlate (uaecptr addr) REGPARAM;
+static uae_u32 REGPARAM3 fastmem_lget (uaecptr) REGPARAM;
+static uae_u32 REGPARAM3 fastmem_wget (uaecptr) REGPARAM;
+static uae_u32 REGPARAM3 fastmem_bget (uaecptr) REGPARAM;
+static void REGPARAM3 fastmem_lput (uaecptr, uae_u32) REGPARAM;
+static void REGPARAM3 fastmem_wput (uaecptr, uae_u32) REGPARAM;
+static void REGPARAM3 fastmem_bput (uaecptr, uae_u32) REGPARAM;
+static int REGPARAM3 fastmem_check (uaecptr addr, uae_u32 size) REGPARAM;
+static uae_u8 *REGPARAM3 fastmem_xlate (uaecptr addr) REGPARAM;
 
 uaecptr fastmem_start; /* Determined by the OS */
 static uae_u8 *fastmemory;
@@ -398,7 +396,7 @@ static int REGPARAM2 fastmem_check (uaecptr addr, uae_u32 size)
     return (addr + size) <= allocated_fastmem;
 }
 
-static uae_u8 REGPARAM2 *fastmem_xlate (uaecptr addr)
+static uae_u8 *REGPARAM2 fastmem_xlate (uaecptr addr)
 {
     addr -= fastmem_start & fastmem_mask;
     addr &= fastmem_mask;
@@ -418,14 +416,14 @@ addrbank fastmem_bank = {
  * Catweasel ZorroII
  */
 
-static uae_u32 catweasel_lget (uaecptr) REGPARAM;
-static uae_u32 catweasel_wget (uaecptr) REGPARAM;
-static uae_u32 catweasel_bget (uaecptr) REGPARAM;
-static void catweasel_lput (uaecptr, uae_u32) REGPARAM;
-static void catweasel_wput (uaecptr, uae_u32) REGPARAM;
-static void catweasel_bput (uaecptr, uae_u32) REGPARAM;
-static int catweasel_check (uaecptr addr, uae_u32 size) REGPARAM;
-static uae_u8 *catweasel_xlate (uaecptr addr) REGPARAM;
+static uae_u32 REGPARAM3 catweasel_lget (uaecptr) REGPARAM;
+static uae_u32 REGPARAM3 catweasel_wget (uaecptr) REGPARAM;
+static uae_u32 REGPARAM3 catweasel_bget (uaecptr) REGPARAM;
+static void REGPARAM3 catweasel_lput (uaecptr, uae_u32) REGPARAM;
+static void REGPARAM3 catweasel_wput (uaecptr, uae_u32) REGPARAM;
+static void REGPARAM3 catweasel_bput (uaecptr, uae_u32) REGPARAM;
+static int REGPARAM3 catweasel_check (uaecptr addr, uae_u32 size) REGPARAM;
+static uae_u8 *REGPARAM3 catweasel_xlate (uaecptr addr) REGPARAM;
 
 static uae_u32 catweasel_mask;
 static uae_u32 catweasel_start;
@@ -490,7 +488,7 @@ static int REGPARAM2 catweasel_check (uaecptr addr, uae_u32 size)
     return 0;
 }
 
-static uae_u8 REGPARAM2 *catweasel_xlate (uaecptr addr)
+static uae_u8 *REGPARAM2 catweasel_xlate (uaecptr addr)
 {
     write_log ("catweasel_xlate @%08.8X size %08.8X\n", addr);
     return 0;
@@ -540,17 +538,19 @@ static void expamem_init_catweasel (void)
 
 #endif
 
+#ifdef FILESYS
+
 /*
  * Filesystem device ROM
  * This is very simple, the Amiga shouldn't be doing things with it.
  */
 
-static uae_u32 filesys_lget (uaecptr) REGPARAM;
-static uae_u32 filesys_wget (uaecptr) REGPARAM;
-static uae_u32 filesys_bget (uaecptr) REGPARAM;
-static void filesys_lput (uaecptr, uae_u32) REGPARAM;
-static void filesys_wput (uaecptr, uae_u32) REGPARAM;
-static void filesys_bput (uaecptr, uae_u32) REGPARAM;
+static uae_u32 REGPARAM3 filesys_lget (uaecptr) REGPARAM;
+static uae_u32 REGPARAM3 filesys_wget (uaecptr) REGPARAM;
+static uae_u32 REGPARAM3 filesys_bget (uaecptr) REGPARAM;
+static void REGPARAM3 filesys_lput (uaecptr, uae_u32) REGPARAM;
+static void REGPARAM3 filesys_wput (uaecptr, uae_u32) REGPARAM;
+static void REGPARAM3 filesys_bput (uaecptr, uae_u32) REGPARAM;
 
 static uae_u32 filesys_start; /* Determined by the OS */
 uae_u8 *filesysory;
@@ -594,7 +594,7 @@ static void REGPARAM2 filesys_lput (uaecptr addr, uae_u32 l)
 #ifdef JIT
     special_mem |= S_WRITE;
 #endif
-    write_log ("filesys_lput called PC=%p\n", m68k_getpc());
+    write_log ("filesys_lput called PC=%p\n", M68K_GETPC);
 }
 
 static void REGPARAM2 filesys_wput (uaecptr addr, uae_u32 w)
@@ -602,7 +602,7 @@ static void REGPARAM2 filesys_wput (uaecptr addr, uae_u32 w)
 #ifdef JIT
     special_mem |= S_WRITE;
 #endif
-    write_log ("filesys_wput called PC=%p\n", m68k_getpc());
+    write_log ("filesys_wput called PC=%p\n", M68K_GETPC);
 }
 
 static void REGPARAM2 filesys_bput (uaecptr addr, uae_u32 b)
@@ -624,20 +624,22 @@ static addrbank filesys_bank = {
     default_xlate, default_check, NULL, "Filesystem Autoconfig Area"
 };
 
+#endif /* FILESYS */
+
 /*
  *  Z3fastmem Memory
  */
 
 static uae_u32 z3fastmem_mask;
 
-static uae_u32 z3fastmem_lget (uaecptr) REGPARAM;
-static uae_u32 z3fastmem_wget (uaecptr) REGPARAM;
-static uae_u32 z3fastmem_bget (uaecptr) REGPARAM;
-static void z3fastmem_lput (uaecptr, uae_u32) REGPARAM;
-static void z3fastmem_wput (uaecptr, uae_u32) REGPARAM;
-static void z3fastmem_bput (uaecptr, uae_u32) REGPARAM;
-static int z3fastmem_check (uaecptr addr, uae_u32 size) REGPARAM;
-static uae_u8 *z3fastmem_xlate (uaecptr addr) REGPARAM;
+static uae_u32 REGPARAM3 z3fastmem_lget (uaecptr) REGPARAM;
+static uae_u32 REGPARAM3 z3fastmem_wget (uaecptr) REGPARAM;
+static uae_u32 REGPARAM3 z3fastmem_bget (uaecptr) REGPARAM;
+static void REGPARAM3 z3fastmem_lput (uaecptr, uae_u32) REGPARAM;
+static void REGPARAM3 z3fastmem_wput (uaecptr, uae_u32) REGPARAM;
+static void REGPARAM3 z3fastmem_bput (uaecptr, uae_u32) REGPARAM;
+static int REGPARAM3 z3fastmem_check (uaecptr addr, uae_u32 size) REGPARAM;
+static uae_u8 *REGPARAM3 z3fastmem_xlate (uaecptr addr) REGPARAM;
 
 uaecptr z3fastmem_start; /* Determined by the OS */
 static uae_u8 *z3fastmem;
@@ -699,7 +701,7 @@ static int REGPARAM2 z3fastmem_check (uaecptr addr, uae_u32 size)
     return (addr + size) <= allocated_z3fastmem;
 }
 
-static uae_u8 REGPARAM2 *z3fastmem_xlate (uaecptr addr)
+static uae_u8 *REGPARAM2 z3fastmem_xlate (uaecptr addr)
 {
     addr -= z3fastmem_start & z3fastmem_mask;
     addr &= z3fastmem_mask;
@@ -762,6 +764,8 @@ static void expamem_init_fastcard (void)
 
 /* ********************************************************** */
 
+#ifdef FILESYS
+
 /*
  * Filesystem device
  */
@@ -823,6 +827,8 @@ static void expamem_init_filesys (void)
     memcpy (filesysory, expamem, 0x3000);
 }
 
+#endif
+
 /*
  * Zorro III expansion memory
  */
@@ -884,7 +890,7 @@ static void expamem_init_z3fastmem (void)
 
 }
 
-#if defined(PICASSO96)
+#ifdef PICASSO96
 /*
  *  Fake Graphics Card (ZORRO III) - BDK
  */
@@ -928,7 +934,9 @@ static void expamem_init_gfxcard (void)
 }
 #endif
 
-static long fast_filepos, z3_filepos, p96_filepos;
+#ifdef SAVESTATE
+static size_t fast_filepos, z3_filepos, p96_filepos;
+#endif
 
 static void allocate_expamem (void)
 {
@@ -969,7 +977,7 @@ static void allocate_expamem (void)
        }
        clearexec ();
     }
-#if defined(PICASSO96)
+#ifdef PICASSO96
     if (allocated_gfxmem != currprefs.gfxmem_size) {
        if (gfxmemory)
            mapped_free (gfxmemory);
@@ -992,6 +1000,7 @@ static void allocate_expamem (void)
     z3fastmem_bank.baseaddr = z3fastmem;
     fastmem_bank.baseaddr = fastmemory;
 
+#ifdef SAVESTATE
     if (savestate_state == STATE_RESTORE) {
        if (allocated_fastmem > 0) {
            restore_ram (fast_filepos, fastmemory);
@@ -1003,7 +1012,7 @@ static void allocate_expamem (void)
            map_banks (&z3fastmem_bank, z3fastmem_start >> 16, currprefs.z3fastmem_size >> 16,
                allocated_z3fastmem);
        }
-#if defined(PICASSO96)
+#ifdef PICASSO96
        if (allocated_gfxmem > 0 && gfxmem_start > 0) {
            restore_ram (p96_filepos, gfxmemory);
            map_banks (&gfxmem_bank, gfxmem_start >> 16, currprefs.gfxmem_size >> 16,
@@ -1011,6 +1020,7 @@ static void allocate_expamem (void)
        }
 #endif
     }
+#endif /* SAVESTATE */
 }
 
 extern int cdtv_enabled;
@@ -1043,28 +1053,31 @@ void expamem_reset (void)
        write_log ("Kickstart version is below 1.3!  Disabling autoconfig devices.\n");
        do_mount = 0;
     }
+#ifdef FILESYS
     /* No need for filesystem stuff if there aren't any mounted.  */
     if (nr_units (currprefs.mountinfo) == 0)
        do_mount = 0;
-
+#endif
     if (fastmemory != NULL) {
        card_init[cardno] = expamem_init_fastcard;
        card_map[cardno++] = expamem_map_fastcard;
     }
-    if (z3fastmem != NULL && kickstart_version >= 36) {
+    if (z3fastmem != NULL) {
        card_init[cardno] = expamem_init_z3fastmem;
        card_map[cardno++] = expamem_map_z3fastmem;
     }
 #ifdef PICASSO96
-    if (gfxmemory != NULL && kickstart_version >= 36) {
+    if (gfxmemory != NULL) {
        card_init[cardno] = expamem_init_gfxcard;
        card_map[cardno++] = expamem_map_gfxcard;
     }
 #endif
+#ifdef FILESYS
     if (do_mount && ! ersatzkickfile) {
        card_init[cardno] = expamem_init_filesys;
        card_map[cardno++] = expamem_map_filesys;
     }
+#endif
 #ifdef CATWEASEL
     if (currprefs.catweasel && catweasel_init ()) {
        card_init[cardno] = expamem_init_catweasel;
@@ -1077,60 +1090,74 @@ void expamem_reset (void)
     }
 
     (*card_init[0]) ();
-
 }
 
 void expansion_init (void)
 {
-    z3fastmem = 0;
-    gfxmemory = 0;
-    fastmemory = 0;
-    allocated_z3fastmem = 0;
-    allocated_gfxmem = 0;
     allocated_fastmem = 0;
     fastmem_mask = fastmem_start = 0;
     fastmemory = 0;
-#if defined(PICASSO96)
+
+#ifdef PICASSO96
+    allocated_gfxmem = 0;
     gfxmem_mask = gfxmem_start = 0;
     gfxmemory = 0;
 #endif
-#if defined(CATWEASEL)
+
+#ifdef CATWEASEL
     catweasel_mask = catweasel_start = 0;
 #endif
+
+#ifdef FILESYS
     filesys_start = 0;
     filesysory = 0;
+#endif
+
+    allocated_z3fastmem = 0;
     z3fastmem_mask = z3fastmem_start = 0;
     z3fastmem = 0;
 
     allocate_expamem ();
 
+#ifdef FILESYS
     filesysory = (uae_u8 *) mapped_malloc (0x10000, "filesys");
     if (!filesysory) {
        write_log ("virtual memory exhausted (filesysory)!\n");
        exit (0);
     }
     filesys_bank.baseaddr = (uae_u8*)filesysory;
+#endif
 }
 
 void expansion_cleanup (void)
 {
     if (fastmemory)
        mapped_free (fastmemory);
+    fastmemory = 0;
+
     if (z3fastmem)
        mapped_free (z3fastmem);
+    z3fastmem = 0;
+
+#ifdef PICASSO96
     if (gfxmemory)
        mapped_free (gfxmemory);
+    gfxmemory = 0;
+#endif
+
+#ifdef FILESYS
     if (filesysory)
        mapped_free (filesysory);
-    fastmemory = 0;
-    z3fastmem = 0;
-    gfxmemory = 0;
     filesysory = 0;
-#if defined(CATWEASEL)
+#endif
+
+#ifdef CATWEASEL
     catweasel_free ();
 #endif
 }
 
+#ifdef SAVESTATE
+
 /* State save/restore code.  */
 
 uae_u8 *save_fram (int *len)
@@ -1151,19 +1178,19 @@ uae_u8 *save_pram (int *len)
     return gfxmemory;
 }
 
-void restore_fram (int len, long filepos)
+void restore_fram (int len, size_t filepos)
 {
     fast_filepos = filepos;
     changed_prefs.fastmem_size = len;
 }
 
-void restore_zram (int len, long filepos)
+void restore_zram (int len, size_t filepos)
 {
     z3_filepos = filepos;
     changed_prefs.z3fastmem_size = len;
 }
 
-void restore_pram (int len, long filepos)
+void restore_pram (int len, size_t filepos)
 {
     p96_filepos = filepos;
     changed_prefs.gfxmem_size = len;
@@ -1189,3 +1216,5 @@ uae_u8 *restore_expansion (uae_u8 *src)
     gfxmem_start = restore_u32 ();
     return src;
 }
+
+#endif /* SAVESTATE */
\ No newline at end of file
index 991cea165a84ecee2435440346514ff4ef50f8f6..1a665fee2f61afcbf4e31c66e07c30426b2a60ef 100755 (executable)
--- a/filesys.c
+++ b/filesys.c
@@ -27,7 +27,6 @@
 #include "sysconfig.h"
 #include "sysdeps.h"
 
-#include "config.h"
 #include "threaddep/thread.h"
 #include "options.h"
 #include "uae.h"
@@ -37,6 +36,7 @@
 #include "newcpu.h"
 #include "filesys.h"
 #include "autoconf.h"
+#include "traps.h"
 #include "fsusage.h"
 #include "native2amiga.h"
 #include "scsidev.h"
@@ -54,6 +54,8 @@
 #define DUMPLOCK(u,x)
 #endif
 
+static uae_sem_t test_sem;
+
 static void aino_test (a_inode *aino)
 {
 #ifdef AINO_DEBUG
@@ -140,6 +142,8 @@ int nr_units (struct uaedev_mount_info *mountinfo)
 
 int is_hardfile (struct uaedev_mount_info *mountinfo, int unit_no)
 {
+    if (!mountinfo)
+       mountinfo = &current_mountinfo;
     if (mountinfo->ui[unit_no].volname)
        return FILESYS_VIRTUAL;
     if (mountinfo->ui[unit_no].hf.secspertrack == 0) {
@@ -631,7 +635,7 @@ typedef uae_u8 *dpacket;
 static char *char1 (uaecptr addr)
 {
     static char buf[1024];
-    int i = 0;
+    unsigned int i = 0;
     do {
        buf[i] = get_byte(addr);
        addr++;
@@ -1305,7 +1309,7 @@ static Unit *startup_create_unit (UnitInfo *uinfo)
     uinfo->self = unit;
 
     unit->volume = 0;
-    unit->port = m68k_areg (regs, 5);
+    unit->port = m68k_areg (&regs, 5);
     unit->unit = unit_num++;
 
     startup_update_unit (unit, uinfo);
@@ -1344,14 +1348,14 @@ static Unit *startup_create_unit (UnitInfo *uinfo)
     return unit;
 }
 
-static uae_u32 startup_handler (void)
+static uae_u32 REGPARAM2 startup_handler (TrapContext *context)
 {
     /* Just got the startup packet. It's in A4. DosBase is in A2,
      * our allocated volume structure is in D6, A5 is a pointer to
      * our port. */
-    uaecptr rootnode = get_long (m68k_areg (regs, 2) + 34);
+    uaecptr rootnode = get_long (m68k_areg (&context->regs, 2) + 34);
     uaecptr dos_info = get_long (rootnode + 24) << 2;
-    uaecptr pkt = m68k_dreg (regs, 3);
+    uaecptr pkt = m68k_dreg (&context->regs, 3);
     uaecptr arg2 = get_long (pkt + dp_Arg2);
     int i, namelen;
     char* devname = bstr1 (get_long (pkt + dp_Arg1) << 2);
@@ -1391,16 +1395,16 @@ static uae_u32 startup_handler (void)
 
     /* fill in our process in the device node */
     put_long ((get_long (pkt + dp_Arg3) << 2) + 8, unit->port);
-    unit->dosbase = m68k_areg (regs, 2);
+    unit->dosbase = m68k_areg (&context->regs, 2);
 
     /* make new volume */
-    unit->volume = m68k_areg (regs, 3) + 32;
+    unit->volume = m68k_areg (&context->regs, 3) + 32;
 #ifdef UAE_FILESYS_THREADS
-    unit->locklist = m68k_areg (regs, 3) + 8;
+    unit->locklist = m68k_areg (&context->regs, 3) + 8;
 #else
-    unit->locklist = m68k_areg (regs, 3);
+    unit->locklist = m68k_areg (&context->regs, 3);
 #endif
-    unit->dummy_message = m68k_areg (regs, 3) + 12;
+    unit->dummy_message = m68k_areg (&context->regs, 3) + 12;
 
     put_long (unit->dummy_message + 10, 0);
 
@@ -2487,7 +2491,7 @@ action_read (Unit *unit, dpacket packet)
        }
     } else {
        char *buf;
-       unsigned long old, filesize;
+       off_t old, filesize;
 
        write_log ("unixfs warning: Bad pointer passed for read: %08x, size %d\n", addr, size);
        /* ugh this is inefficient but easy */
@@ -3267,13 +3271,13 @@ action_flush (Unit *unit, dpacket packet)
  * know whether AmigaOS takes care of that, but this does. */
 static uae_sem_t singlethread_int_sem;
 
-static uae_u32 exter_int_helper (void)
+static uae_u32 REGPARAM2 exter_int_helper (TrapContext *context)
 {
     UnitInfo *uip = current_mountinfo.ui;
     uaecptr port;
     static int unit_no;
 
-    switch (m68k_dreg (regs, 0)) {
+    switch (m68k_dreg (&context->regs, 0)) {
      case 0:
        /* Determine whether a given EXTER interrupt is for us. */
        if (uae_int_requested) {
@@ -3298,8 +3302,8 @@ static uae_u32 exter_int_helper (void)
         */
 #ifdef UAE_FILESYS_THREADS
        {
-           Unit *unit = find_unit (m68k_areg (regs, 5));
-           uaecptr msg = m68k_areg (regs, 4);
+           Unit *unit = find_unit (m68k_areg (&context->regs, 5));
+           uaecptr msg = m68k_areg (&context->regs, 4);
            unit->cmds_complete = unit->cmds_acked;
            while (comm_pipe_has_data (unit->ui.back_pipe)) {
                uaecptr locks, lockend;
@@ -3314,9 +3318,9 @@ static uae_u32 exter_int_helper (void)
                    lockend = get_long (lockend);
                    cnt++;
                }
-               TRACE(("%d %x %x %x\n", cnt, locks, lockend, m68k_areg (regs, 3)));
-               put_long (lockend, get_long (m68k_areg (regs, 3)));
-               put_long (m68k_areg (regs, 3), locks);
+               TRACE(("%d %x %x %x\n", cnt, locks, lockend, m68k_areg (&context->regs, 3)));
+               put_long (lockend, get_long (m68k_areg (&context->regs, 3)));
+               put_long (m68k_areg (&context->regs, 3), locks);
            }
        }
 #else
@@ -3340,26 +3344,26 @@ static uae_u32 exter_int_helper (void)
            int cmd = read_comm_pipe_int_blocking (&native2amiga_pending);
            switch (cmd) {
             case 0: /* Signal() */
-               m68k_areg (regs, 1) = read_comm_pipe_u32_blocking (&native2amiga_pending);
-               m68k_dreg (regs, 1) = read_comm_pipe_u32_blocking (&native2amiga_pending);
+               m68k_areg (&context->regs, 1) = read_comm_pipe_u32_blocking (&native2amiga_pending);
+               m68k_dreg (&context->regs, 1) = read_comm_pipe_u32_blocking (&native2amiga_pending);
                return 2;
 
             case 1: /* PutMsg() */
-               m68k_areg (regs, 0) = read_comm_pipe_u32_blocking (&native2amiga_pending);
-               m68k_areg (regs, 1) = read_comm_pipe_u32_blocking (&native2amiga_pending);
+               m68k_areg (&context->regs, 0) = read_comm_pipe_u32_blocking (&native2amiga_pending);
+               m68k_areg (&context->regs, 1) = read_comm_pipe_u32_blocking (&native2amiga_pending);
                return 1;
 
             case 2: /* ReplyMsg() */
-               m68k_areg (regs, 1) = read_comm_pipe_u32_blocking (&native2amiga_pending);
+               m68k_areg (&context->regs, 1) = read_comm_pipe_u32_blocking (&native2amiga_pending);
                return 3;
 
             case 3: /* Cause() */
-               m68k_areg (regs, 1) = read_comm_pipe_u32_blocking (&native2amiga_pending);
+               m68k_areg (&context->regs, 1) = read_comm_pipe_u32_blocking (&native2amiga_pending);
                return 4;
 
             case 4: /* NotifyHack() */
-               m68k_areg (regs, 0) = read_comm_pipe_u32_blocking (&native2amiga_pending);
-               m68k_areg (regs, 1) = read_comm_pipe_u32_blocking (&native2amiga_pending);
+               m68k_areg (&context->regs, 0) = read_comm_pipe_u32_blocking (&native2amiga_pending);
+               m68k_areg (&context->regs, 1) = read_comm_pipe_u32_blocking (&native2amiga_pending);
                return 5;
 
             default:
@@ -3386,8 +3390,8 @@ static uae_u32 exter_int_helper (void)
        uip[unit_no].self->cmds_acked = uip[unit_no].self->cmds_sent;
        port = uip[unit_no].self->port;
        if (port) {
-           m68k_areg (regs, 0) = port;
-           m68k_areg (regs, 1) = find_unit (port)->dummy_message;
+           m68k_areg (&context->regs, 0) = port;
+           m68k_areg (&context->regs, 1) = find_unit (port)->dummy_message;
            unit_no++;
            return 1;
        }
@@ -3466,7 +3470,7 @@ static void *filesys_thread (void *unit_v)
 {
     UnitInfo *ui = (UnitInfo *)unit_v;
 
-    set_thread_priority (2);
+    uae_set_thread_priority (2);
     for (;;) {
        uae_u8 *pck;
        uae_u8 *msg;
@@ -3503,35 +3507,30 @@ static void *filesys_thread (void *unit_v)
        if (get_long (ui->self->locklist) != 0)
            write_comm_pipe_int (ui->back_pipe, (int)(get_long (ui->self->locklist)), 0);
        put_long (ui->self->locklist, 0);
+
     }
     return 0;
 }
 #endif
 
 /* Talk about spaghetti code... */
-static uae_u32 filesys_handler (void)
+static uae_u32 REGPARAM2 filesys_handler (TrapContext *context)
 {
-    Unit *unit = find_unit (m68k_areg (regs, 5));
-    uaecptr packet_addr = m68k_dreg (regs, 3);
-    uaecptr message_addr = m68k_areg (regs, 4);
+    Unit *unit = find_unit (m68k_areg (&context->regs, 5));
+    uaecptr packet_addr = m68k_dreg (&context->regs, 3);
+    uaecptr message_addr = m68k_areg (&context->regs, 4);
     uae_u8 *pck;
     uae_u8 *msg;
     if (! valid_address (packet_addr, 36) || ! valid_address (message_addr, 14)) {
-       write_log ("Bad address passed for packet.\n");
+       write_log ("FILESYS: Bad address %x/%x passed for packet.\n", packet_addr, message_addr);
        goto error2;
     }
     pck = get_real_address (packet_addr);
     msg = get_real_address (message_addr);
 
-#if 0
-    if (unit->reset_state == FS_GO_DOWN)
-       /* You might as well queue it, if you live long enough */
-       return 1;
-#endif
-
     do_put_mem_long ((uae_u32 *)(msg + 4), -1);
     if (!unit || !unit->volume) {
-       write_log ("Filesystem was not initialized.\n");
+       write_log ("FILESYS: was not initialized.\n");
        goto error;
     }
 #ifdef UAE_FILESYS_THREADS
@@ -3540,8 +3539,8 @@ static uae_u32 filesys_handler (void)
        if (!unit->ui.unit_pipe)
            goto error;
        /* Get two more locks and hand them over to the other thread. */
-       morelocks = get_long (m68k_areg (regs, 3));
-       put_long (m68k_areg (regs, 3), get_long (get_long (morelocks)));
+       morelocks = get_long (m68k_areg (&context->regs, 3));
+       put_long (m68k_areg (&context->regs, 3), get_long (get_long (morelocks)));
        put_long (get_long (morelocks), 0);
 
        /* The packet wasn't processed yet. */
@@ -3693,18 +3692,19 @@ static uaecptr uaeresource_startup (uaecptr resaddr)
 }
 */
 
-static uae_u32 filesys_diagentry (void)
+static uae_u32 REGPARAM2 filesys_diagentry (TrapContext *context)
 {
-    uaecptr resaddr = m68k_areg (regs, 2) + 0x10;
+    uaecptr resaddr = m68k_areg (&context->regs, 2) + 0x10;
     uaecptr start = resaddr;
     uaecptr residents, tmp;
 
     TRACE (("filesystem: diagentry called\n"));
 
-    filesys_configdev = m68k_areg (regs, 3);
+    filesys_configdev = m68k_areg (&context->regs, 3);
     init_filesys_diagentry ();
 
     uae_sem_init (&singlethread_int_sem, 0, 1);
+    uae_sem_init (&test_sem, 0, 1);
     if (ROM_hardfile_resid != 0) {
        /* Build a struct Resident. This will set up and initialize
         * the uae.device */
@@ -3755,7 +3755,7 @@ static uae_u32 filesys_diagentry (void)
     put_word (resaddr + 14, 0x7001); /* moveq.l #1,d0 */
     put_word (resaddr + 16, RTS);
 
-    m68k_areg (regs, 0) = residents;
+    m68k_areg (&context->regs, 0) = residents;
     return 1;
 }
 
@@ -3767,15 +3767,15 @@ static uae_u32 filesys_diagentry (void)
 #define PP_EXPLIB 412
 #define PP_FSHDSTART 416
 
-static uae_u32 filesys_dev_bootfilesys (void)
+static uae_u32 REGPARAM2 filesys_dev_bootfilesys (TrapContext *context)
 {
-    uaecptr devicenode = m68k_areg (regs, 3);
-    uaecptr parmpacket = m68k_areg (regs, 1);
+    uaecptr devicenode = m68k_areg (&context->regs, 3);
+    uaecptr parmpacket = m68k_areg (&context->regs, 1);
     uaecptr fsres = get_long (parmpacket + PP_FSRES);
     uaecptr fsnode;
     uae_u32 dostype, dostype2;
     UnitInfo *uip = current_mountinfo.ui;
-    int no = m68k_dreg (regs, 6);
+    int no = m68k_dreg (&context->regs, 6);
     int unit_no = no & 65535;
     int type = is_hardfile (&current_mountinfo, unit_no);
 
@@ -3799,15 +3799,15 @@ static uae_u32 filesys_dev_bootfilesys (void)
 
 /* Remember a pointer AmigaOS gave us so we can later use it to identify
  * which unit a given startup message belongs to.  */
-static uae_u32 filesys_dev_remember (void)
+static uae_u32 REGPARAM2 filesys_dev_remember (TrapContext *context)
 {
-    int no = m68k_dreg (regs, 6);
+    int no = m68k_dreg (&context->regs, 6);
     int unit_no = no & 65535;
     int sub_no = no >> 16;
     UnitInfo *uip = &current_mountinfo.ui[unit_no];
     int i;
-    uaecptr devicenode = m68k_areg (regs, 3);
-    uaecptr parmpacket = m68k_areg (regs, 1);
+    uaecptr devicenode = m68k_areg (&context->regs, 3);
+    uaecptr parmpacket = m68k_areg (&context->regs, 1);
 
     /* copy filesystem loaded from RDB */
     if (get_long (parmpacket + PP_FSPTR)) {
@@ -3817,7 +3817,7 @@ static uae_u32 filesys_dev_remember (void)
        uip->rdb_filesysstore = 0;
        uip->rdb_filesyssize = 0;
     }
-    if (m68k_dreg (regs, 3) >= 0)
+    if (m68k_dreg (&context->regs, 3) >= 0)
        uip->startup = get_long (devicenode + 28);
     return devicenode;
 }
@@ -3994,7 +3994,7 @@ static int rdb_mount (UnitInfo *uip, int unit_no, int partnum, uaecptr parmpacke
     }
 
     if (!(flags & 1)) /* not bootable */
-       m68k_dreg (regs, 7) = 0;
+       m68k_dreg (&regs, 7) = 0;
 
     buf[37 + buf[36]] = 0; /* zero terminate BSTR */
     uip->rdb_devname_amiga[partnum] = ds (device_dupfix (get_long (parmpacket + PP_EXPLIB), buf + 37));
@@ -4181,14 +4181,14 @@ static void get_new_device (int type, uaecptr parmpacket, char **devname, uaecpt
 }
 
 /* Fill in per-unit fields of a parampacket */
-static uae_u32 filesys_dev_storeinfo (void)
+static uae_u32 REGPARAM2 filesys_dev_storeinfo (TrapContext *context)
 {
     UnitInfo *uip = current_mountinfo.ui;
-    int no = m68k_dreg (regs, 6);
+    int no = m68k_dreg (&context->regs, 6);
     int unit_no = no & 65535;
     int sub_no = no >> 16;
     int type = is_hardfile (&current_mountinfo, unit_no);
-    uaecptr parmpacket = m68k_areg (regs, 0);
+    uaecptr parmpacket = m68k_areg (&context->regs, 0);
 
     if (type == FILESYS_HARDFILE_RDB || type == FILESYS_HARDDRIVE) {
        /* RDB hardfile */
@@ -4238,34 +4238,34 @@ void filesys_install (void)
     fsdevname = ds ("uae.device"); /* does not really exist */
 
     ROM_filesys_diagentry = here();
-    calltrap (deftrap(filesys_diagentry));
+    calltrap (deftrap2(filesys_diagentry, 0, "filesys_diagentry"));
     dw(0x4ED0); /* JMP (a0) - jump to code that inits Residents */
 
     loop = here ();
 
     org (RTAREA_BASE + 0xFF18);
-    calltrap (deftrap (filesys_dev_bootfilesys));
+    calltrap (deftrap2 (filesys_dev_bootfilesys, 0, "filesys_dev_bootfilesys"));
     dw (RTS);
 
     /* Special trap for the assembly make_dev routine */
     org (RTAREA_BASE + 0xFF20);
-    calltrap (deftrap (filesys_dev_remember));
+    calltrap (deftrap2 (filesys_dev_remember, 0, "filesys_dev_remember"));
     dw (RTS);
 
     org (RTAREA_BASE + 0xFF28);
-    calltrap (deftrap (filesys_dev_storeinfo));
+    calltrap (deftrap2 (filesys_dev_storeinfo, 0, "filesys_dev_storeinfo"));
     dw (RTS);
 
     org (RTAREA_BASE + 0xFF30);
-    calltrap (deftrap (filesys_handler));
+    calltrap (deftrap2 (filesys_handler, 0, "filesys_handler"));
     dw (RTS);
 
     org (RTAREA_BASE + 0xFF40);
-    calltrap (deftrap (startup_handler));
+    calltrap (deftrap2 (startup_handler, 0, "startup_handler"));
     dw (RTS);
 
     org (RTAREA_BASE + 0xFF50);
-    calltrap (deftrap (exter_int_helper));
+    calltrap (deftrap2 (exter_int_helper, 0, "exter_int_helper"));
     dw (RTS);
 
     org (loop);
diff --git a/fpp.c b/fpp.c
index 8d577c575e89967d879893253f07bab84f93ebec..ca2a986c9a728d962772d91f268ff2f09b77daa9 100755 (executable)
--- a/fpp.c
+++ b/fpp.c
@@ -13,7 +13,6 @@
 #include "sysconfig.h"
 #include "sysdeps.h"
 
-#include "config.h"
 #include "options.h"
 #include "memory.h"
 #include "custom.h"
 #include "md-fpp.h"
 #include "savestate.h"
 
-uae_u32 xhex_pi[]    ={0x2168c235, 0xc90fdaa2, 0x4000};
+static uae_u32 xhex_pi[]    ={0x2168c235, 0xc90fdaa2, 0x4000};
 uae_u32 xhex_exp_1[] ={0xa2bb4a9a, 0xadf85458, 0x4000};
-uae_u32 xhex_l2_e[]  ={0x5c17f0bc, 0xb8aa3b29, 0x3fff};
-uae_u32 xhex_ln_2[]  ={0xd1cf79ac, 0xb17217f7, 0x3ffe};
+static uae_u32 xhex_l2_e[]  ={0x5c17f0bc, 0xb8aa3b29, 0x3fff};
+static uae_u32 xhex_ln_2[]  ={0xd1cf79ac, 0xb17217f7, 0x3ffe};
 uae_u32 xhex_ln_10[] ={0xaaa8ac17, 0x935d8ddd, 0x4000};
 uae_u32 xhex_l10_2[] ={0xfbcff798, 0x9a209a84, 0x3ffd};
 uae_u32 xhex_l10_e[] ={0x37287195, 0xde5bd8a9, 0x3ffd};
@@ -39,8 +38,8 @@ uae_u32 xhex_1e512[] ={0xa60e91c7, 0xe319a0ae, 0x46a3};
 uae_u32 xhex_1e1024[]={0x81750c17, 0xc9767586, 0x4d48};
 uae_u32 xhex_1e2048[]={0xc53d5de5, 0x9e8b3b5d, 0x5a92};
 uae_u32 xhex_1e4096[]={0x8a20979b, 0xc4605202, 0x7525};
-uae_u32 xhex_inf[]   ={0x00000000, 0x00000000, 0x7fff};
-uae_u32 xhex_nan[]   ={0xffffffff, 0xffffffff, 0x7fff};
+static uae_u32 xhex_inf[]   ={0x00000000, 0x00000000, 0x7fff};
+static uae_u32 xhex_nan[]   ={0xffffffff, 0xffffffff, 0x7fff};
 #if USE_LONG_DOUBLE
 static long double *fp_pi     = (long double *)xhex_pi;
 static long double *fp_exp_1  = (long double *)xhex_exp_1;
@@ -101,7 +100,7 @@ float  fp_1e0 = 1, fp_1e1 = 10, fp_1e2 = 100, fp_1e4 = 10000;
 
 STATIC_INLINE int isinrom (void)
 {
-    return (munge24 (m68k_getpc ()) & 0xFFF80000) == 0xF80000;
+    return (munge24 (m68k_getpc (&regs)) & 0xFFF80000) == 0xF80000;
 }
 
 #define DEBUG_FPP 0
@@ -110,7 +109,7 @@ STATIC_INLINE int isinrom (void)
 #define FFLAG_N            0x0100
 #define FFLAG_NAN   0x0400
 
-#define MAKE_FPSR(r)  regs.fp_result=(r)
+#define MAKE_FPSR(regs, r)  (regs)->fp_result=(r)
 
 static uae_u16 x87_cw_tab[] = {
   0x137f, 0x1f7f, 0x177f, 0x1b7f,  /* Extended */
@@ -303,16 +302,16 @@ STATIC_INLINE int get_fp_value (uae_u32 opcode, uae_u16 extra, fptype *src)
     case 0:
        switch (size) {
        case 6:
-           *src = (fptype) (uae_s8) m68k_dreg (regs, reg);
+           *src = (fptype) (uae_s8) m68k_dreg (&regs, reg);
            break;
        case 4:
-           *src = (fptype) (uae_s16) m68k_dreg (regs, reg);
+           *src = (fptype) (uae_s16) m68k_dreg (&regs, reg);
            break;
        case 0:
-           *src = (fptype) (uae_s32) m68k_dreg (regs, reg);
+           *src = (fptype) (uae_s32) m68k_dreg (&regs, reg);
            break;
        case 1:
-           *src = to_single (m68k_dreg (regs, reg));
+           *src = to_single (m68k_dreg (&regs, reg));
            break;
        default:
            return 0;
@@ -321,42 +320,42 @@ STATIC_INLINE int get_fp_value (uae_u32 opcode, uae_u16 extra, fptype *src)
     case 1:
        return 0;
     case 2:
-       ad = m68k_areg (regs, reg);
+       ad = m68k_areg (&regs, reg);
        break;
     case 3:
-       ad = m68k_areg (regs, reg);
-       m68k_areg (regs, reg) += reg == 7 ? sz2[size] : sz1[size];
+       ad = m68k_areg (&regs, reg);
+       m68k_areg (&regs, reg) += reg == 7 ? sz2[size] : sz1[size];
        break;
     case 4:
-       m68k_areg (regs, reg) -= reg == 7 ? sz2[size] : sz1[size];
-       ad = m68k_areg (regs, reg);
+       m68k_areg (&regs, reg) -= reg == 7 ? sz2[size] : sz1[size];
+       ad = m68k_areg (&regs, reg);
        break;
     case 5:
-       ad = m68k_areg (regs, reg) + (uae_s32) (uae_s16) next_iword ();
+       ad = m68k_areg (&regs, reg) + (uae_s32) (uae_s16) next_iword (&regs);
        break;
     case 6:
-       ad = get_disp_ea_020 (m68k_areg (regs, reg), next_iword ());
+       ad = get_disp_ea_020 (&regs, m68k_areg (&regs, reg), next_iword (&regs));
        break;
     case 7:
        switch (reg) {
        case 0:
-           ad = (uae_s32) (uae_s16) next_iword ();
+           ad = (uae_s32) (uae_s16) next_iword (&regs);
            break;
        case 1:
-           ad = next_ilong ();
+           ad = next_ilong (&regs);
            break;
        case 2:
-           ad = m68k_getpc ();
-           ad += (uae_s32) (uae_s16) next_iword ();
+           ad = m68k_getpc (&regs);
+           ad += (uae_s32) (uae_s16) next_iword (&regs);
            break;
        case 3:
-           tmppc = m68k_getpc ();
-           tmp = next_iword ();
-           ad = get_disp_ea_020 (tmppc, tmp);
+           tmppc = m68k_getpc (&regs);
+           tmp = next_iword (&regs);
+           ad = get_disp_ea_020 (&regs, tmppc, tmp);
            break;
        case 4:
-           ad = m68k_getpc ();
-           m68k_setpc (ad + sz2[size]);
+           ad = m68k_getpc (&regs);
+           m68k_setpc (&regs, ad + sz2[size]);
            if (size == 6)
                ad++;
            break;
@@ -411,7 +410,7 @@ STATIC_INLINE int get_fp_value (uae_u32 opcode, uae_u16 extra, fptype *src)
     return 1;
 }
 
-STATIC_INLINE int put_fp_value (fptype value, uae_u32 opcode, uae_u16 extra)
+STATIC_INLINE int put_fp_value (struct regstruct *regs, fptype value, uae_u32 opcode, uae_u16 extra)
 {
     uae_u16 tmp;
     uaecptr tmppc;
@@ -425,7 +424,7 @@ STATIC_INLINE int put_fp_value (fptype value, uae_u32 opcode, uae_u16 extra)
        write_log ("PUTFP: %f %04.4X %04.4X\n", value, opcode, extra);
 #endif
     if (!(extra & 0x4000)) {
-       regs.fp[(extra >> 10) & 7] = value;
+       regs->fp[(extra >> 10) & 7] = value;
        return 1;
     }
     reg = opcode & 7;
@@ -467,31 +466,31 @@ STATIC_INLINE int put_fp_value (fptype value, uae_u32 opcode, uae_u16 extra)
        ad = m68k_areg (regs, reg);
        break;
     case 5:
-       ad = m68k_areg (regs, reg) + (uae_s32) (uae_s16) next_iword ();
+       ad = m68k_areg (regs, reg) + (uae_s32) (uae_s16) next_iword (regs);
        break;
     case 6:
-       ad = get_disp_ea_020 (m68k_areg (regs, reg), next_iword ());
+       ad = get_disp_ea_020 (regs, m68k_areg (regs, reg), next_iword (regs));
        break;
     case 7:
        switch (reg) {
        case 0:
-           ad = (uae_s32) (uae_s16) next_iword ();
+           ad = (uae_s32) (uae_s16) next_iword (regs);
            break;
        case 1:
-           ad = next_ilong ();
+           ad = next_ilong (regs);
            break;
        case 2:
-           ad = m68k_getpc ();
-           ad += (uae_s32) (uae_s16) next_iword ();
+           ad = m68k_getpc (regs);
+           ad += (uae_s32) (uae_s16) next_iword (regs);
            break;
        case 3:
-           tmppc = m68k_getpc ();
-           tmp = next_iword ();
-           ad = get_disp_ea_020 (tmppc, tmp);
+           tmppc = m68k_getpc (regs);
+           tmp = next_iword (regs);
+           ad = get_disp_ea_020 (regs, tmppc, tmp);
            break;
        case 4:
-           ad = m68k_getpc ();
-           m68k_setpc (ad + sz2[size]);
+           ad = m68k_getpc (regs);
+           m68k_setpc (regs, ad + sz2[size]);
            break;
        default:
            return 0;
@@ -560,36 +559,36 @@ STATIC_INLINE int get_fp_ad (uae_u32 opcode, uae_u32 * ad)
     case 1:
        return 0;
     case 2:
-       *ad = m68k_areg (regs, reg);
+       *ad = m68k_areg (&regs, reg);
        break;
     case 3:
-       *ad = m68k_areg (regs, reg);
+       *ad = m68k_areg (&regs, reg);
        break;
     case 4:
-       *ad = m68k_areg (regs, reg);
+       *ad = m68k_areg (&regs, reg);
        break;
     case 5:
-       *ad = m68k_areg (regs, reg) + (uae_s32) (uae_s16) next_iword ();
+       *ad = m68k_areg (&regs, reg) + (uae_s32) (uae_s16) next_iword (&regs);
        break;
     case 6:
-       *ad = get_disp_ea_020 (m68k_areg (regs, reg), next_iword ());
+       *ad = get_disp_ea_020 (&regs, m68k_areg (&regs, reg), next_iword (&regs));
        break;
     case 7:
        switch (reg) {
        case 0:
-           *ad = (uae_s32) (uae_s16) next_iword ();
+           *ad = (uae_s32) (uae_s16) next_iword (&regs);
            break;
        case 1:
-           *ad = next_ilong ();
+           *ad = next_ilong (&regs);
            break;
        case 2:
-           *ad = m68k_getpc ();
-           *ad += (uae_s32) (uae_s16) next_iword ();
+           *ad = m68k_getpc (&regs);
+           *ad += (uae_s32) (uae_s16) next_iword (&regs);
            break;
        case 3:
-           tmppc = m68k_getpc ();
-           tmp = next_iword ();
-           *ad = get_disp_ea_020 (tmppc, tmp);
+           tmppc = m68k_getpc (&regs);
+           tmp = next_iword (&regs);
+           *ad = get_disp_ea_020 (&regs, tmppc, tmp);
            break;
        default:
            return 0;
@@ -685,10 +684,10 @@ STATIC_INLINE int fpp_cond (uae_u32 opcode, int contition)
     return -1;
 }
 
-void fdbcc_opp (uae_u32 opcode, uae_u16 extra)
+void fdbcc_opp (uae_u32 opcode, struct regstruct *regs, uae_u16 extra)
 {
-    uaecptr pc = (uae_u32) m68k_getpc ();
-    uae_s32 disp = (uae_s32) (uae_s16) next_iword ();
+    uaecptr pc = (uae_u32) m68k_getpc (regs);
+    uae_s32 disp = (uae_s32) (uae_s16) next_iword (regs);
     int cc;
 
 #if DEBUG_FPP
@@ -697,19 +696,19 @@ void fdbcc_opp (uae_u32 opcode, uae_u16 extra)
 #endif
     cc = fpp_cond (opcode, extra & 0x3f);
     if (cc == -1) {
-       m68k_setpc (pc - 4);
-       op_illg (opcode);
+       m68k_setpc (regs, pc - 4);
+       op_illg (opcode, regs);
     } else if (!cc) {
        int reg = opcode & 0x7;
 
        m68k_dreg (regs, reg) = ((m68k_dreg (regs, reg) & ~0xffff)
            | ((m68k_dreg (regs, reg) - 1) & 0xffff));
        if ((m68k_dreg (regs, reg) & 0xffff) == 0xffff)
-           m68k_setpc (pc + disp);
+           m68k_setpc (regs, pc + disp);
     }
 }
 
-void fscc_opp (uae_u32 opcode, uae_u16 extra)
+void fscc_opp (uae_u32 opcode, struct regstruct *regs, uae_u16 extra)
 {
     uae_u32 ad;
     int cc;
@@ -720,20 +719,20 @@ void fscc_opp (uae_u32 opcode, uae_u16 extra)
 #endif
     cc = fpp_cond (opcode, extra & 0x3f);
     if (cc == -1) {
-       m68k_setpc (m68k_getpc () - 4);
-       op_illg (opcode);
+       m68k_setpc (regs, m68k_getpc (regs) - 4);
+       op_illg (opcode, regs);
     } else if ((opcode & 0x38) == 0) {
        m68k_dreg (regs, opcode & 7) = (m68k_dreg (regs, opcode & 7) & ~0xff) | (cc ? 0xff : 0x00);
     } else {
        if (get_fp_ad (opcode, &ad) == 0) {
-           m68k_setpc (m68k_getpc () - 4);
-           op_illg (opcode);
+           m68k_setpc (regs, m68k_getpc (regs) - 4);
+           op_illg (opcode, regs);
        } else
            put_byte (ad, cc ? 0xff : 0x00);
     }
 }
 
-void ftrapcc_opp (uae_u32 opcode, uaecptr oldpc)
+void ftrapcc_opp (uae_u32 opcode, struct regstruct *regs, uaecptr oldpc)
 {
     int cc;
 
@@ -743,14 +742,14 @@ void ftrapcc_opp (uae_u32 opcode, uaecptr oldpc)
 #endif
     cc = fpp_cond (opcode, opcode & 0x3f);
     if (cc == -1) {
-       m68k_setpc (oldpc);
-       op_illg (opcode);
+       m68k_setpc (regs, oldpc);
+       op_illg (opcode, regs);
     }
     if (cc)
-       Exception (7, oldpc - 2);
+       Exception (7, regs, oldpc - 2);
 }
 
-void fbcc_opp (uae_u32 opcode, uaecptr pc, uae_u32 extra)
+void fbcc_opp (uae_u32 opcode, struct regstruct *regs, uaecptr pc, uae_u32 extra)
 {
     int cc;
 
@@ -760,16 +759,16 @@ void fbcc_opp (uae_u32 opcode, uaecptr pc, uae_u32 extra)
 #endif
     cc = fpp_cond (opcode, opcode & 0x3f);
     if (cc == -1) {
-       m68k_setpc (pc);
-       op_illg (opcode);
+       m68k_setpc (regs, pc);
+       op_illg (opcode, regs);
     } else if (cc) {
        if ((opcode & 0x40) == 0)
            extra = (uae_s32) (uae_s16) extra;
-       m68k_setpc (pc + extra);
+       m68k_setpc (regs, pc + extra);
     }
 }
 
-void fsave_opp (uae_u32 opcode)
+void fsave_opp (uae_u32 opcode, struct regstruct *regs)
 {
     uae_u32 ad;
     int incr = (opcode & 0x38) == 0x20 ? -1 : 1;
@@ -783,8 +782,8 @@ void fsave_opp (uae_u32 opcode)
        write_log ("fsave_opp at %08lx\n", m68k_getpc ());
 #endif
     if (get_fp_ad (opcode, &ad) == 0) {
-       m68k_setpc (m68k_getpc () - 2);
-       op_illg (opcode);
+       m68k_setpc (regs, m68k_getpc (regs) - 2);
+       op_illg (opcode, regs);
        return;
     }
 
@@ -824,7 +823,7 @@ void fsave_opp (uae_u32 opcode)
        m68k_areg (regs, opcode & 7) = ad;
 }
 
-void frestore_opp (uae_u32 opcode)
+void frestore_opp (uae_u32 opcode, struct regstruct *regs)
 {
     uae_u32 ad;
     uae_u32 d;
@@ -835,8 +834,8 @@ void frestore_opp (uae_u32 opcode)
        write_log ("frestore_opp at %08lx\n", m68k_getpc ());
 #endif
     if (get_fp_ad (opcode, &ad) == 0) {
-       m68k_setpc (m68k_getpc () - 2);
-       op_illg (opcode);
+       m68k_setpc (regs, m68k_getpc (regs) - 2);
+       op_illg (opcode, regs);
        return;
     }
     if (currprefs.cpu_level >= 4) {
@@ -901,7 +900,7 @@ static void fround (int reg)
     regs.fp[reg] = (float)regs.fp[reg];
 }
 
-void fpp_opp (uae_u32 opcode, uae_u16 extra)
+void fpp_opp (uae_u32 opcode, struct regstruct *regs, uae_u16 extra)
 {
     int reg;
     fptype src;
@@ -912,9 +911,9 @@ void fpp_opp (uae_u32 opcode, uae_u16 extra)
 #endif
     switch ((extra >> 13) & 0x7) {
     case 3:
-       if (put_fp_value (regs.fp[(extra >> 7) & 7], opcode, extra) == 0) {
-           m68k_setpc (m68k_getpc () - 4);
-           op_illg (opcode);
+       if (put_fp_value (regs, regs->fp[(extra >> 7) & 7], opcode, extra) == 0) {
+           m68k_setpc (regs, m68k_getpc (regs) - 4);
+           op_illg (opcode, regs);
        }
        return;
     case 4:
@@ -922,49 +921,49 @@ void fpp_opp (uae_u32 opcode, uae_u16 extra)
        if ((opcode & 0x38) == 0) {
            if (extra & 0x2000) {
                if (extra & 0x1000)
-                   m68k_dreg (regs, opcode & 7) = regs.fpcr;
+                   m68k_dreg (regs, opcode & 7) = regs->fpcr;
                if (extra & 0x0800)
                    m68k_dreg (regs, opcode & 7) = get_fpsr ();
                if (extra & 0x0400)
-                   m68k_dreg (regs, opcode & 7) = regs.fpiar;
+                   m68k_dreg (regs, opcode & 7) = regs->fpiar;
            } else {
                if (extra & 0x1000) {
-                   regs.fpcr = m68k_dreg (regs, opcode & 7);
-                   native_set_fpucw (regs.fpcr);
+                   regs->fpcr = m68k_dreg (regs, opcode & 7);
+                   native_set_fpucw (regs->fpcr);
                }
                if (extra & 0x0800)
                    set_fpsr (m68k_dreg (regs, opcode & 7));
                if (extra & 0x0400)
-                   regs.fpiar = m68k_dreg (regs, opcode & 7);
+                   regs->fpiar = m68k_dreg (regs, opcode & 7);
            }
        } else if ((opcode & 0x38) == 0x08) {
            if (extra & 0x2000) {
                if (extra & 0x1000)
-                   m68k_areg (regs, opcode & 7) = regs.fpcr;
+                   m68k_areg (regs, opcode & 7) = regs->fpcr;
                if (extra & 0x0800)
                    m68k_areg (regs, opcode & 7) = get_fpsr ();
                if (extra & 0x0400)
-                   m68k_areg (regs, opcode & 7) = regs.fpiar;
+                   m68k_areg (regs, opcode & 7) = regs->fpiar;
            } else {
                if (extra & 0x1000) {
-                   regs.fpcr = m68k_areg (regs, opcode & 7);
-                   native_set_fpucw (regs.fpcr);
+                   regs->fpcr = m68k_areg (regs, opcode & 7);
+                   native_set_fpucw (regs->fpcr);
                }
                if (extra & 0x0800)
                    set_fpsr (m68k_areg (regs, opcode & 7));
                if (extra & 0x0400)
-                   regs.fpiar = m68k_areg (regs, opcode & 7);
+                   regs->fpiar = m68k_areg (regs, opcode & 7);
            }
        } else if ((opcode & 0x3f) == 0x3c) {
            if ((extra & 0x2000) == 0) {
                if (extra & 0x1000) {
-                   regs.fpcr = next_ilong ();
-                   native_set_fpucw (regs.fpcr);
+                   regs->fpcr = next_ilong (regs);
+                   native_set_fpucw (regs->fpcr);
                }
                if (extra & 0x0800)
-                   set_fpsr (next_ilong ());
+                   set_fpsr (next_ilong (regs));
                if (extra & 0x0400)
-                   regs.fpiar = next_ilong ();
+                   regs->fpiar = next_ilong (regs);
            }
        } else if (extra & 0x2000) {
            /* FMOVEM FPP->memory */
@@ -972,8 +971,8 @@ void fpp_opp (uae_u32 opcode, uae_u16 extra)
            int incr = 0;
 
            if (get_fp_ad (opcode, &ad) == 0) {
-               m68k_setpc (m68k_getpc () - 4);
-               op_illg (opcode);
+               m68k_setpc (regs, m68k_getpc (regs) - 4);
+               op_illg (opcode, regs);
                return;
            }
            if ((opcode & 0x38) == 0x20) {
@@ -986,7 +985,7 @@ void fpp_opp (uae_u32 opcode, uae_u16 extra)
            }
            ad -= incr;
            if (extra & 0x1000) {
-               put_long (ad, regs.fpcr);
+               put_long (ad, regs->fpcr);
                ad += 4;
            }
            if (extra & 0x0800) {
@@ -994,7 +993,7 @@ void fpp_opp (uae_u32 opcode, uae_u16 extra)
                ad += 4;
            }
            if (extra & 0x0400) {
-               put_long (ad, regs.fpiar);
+               put_long (ad, regs->fpiar);
                ad += 4;
            }
            ad -= incr;
@@ -1007,14 +1006,14 @@ void fpp_opp (uae_u32 opcode, uae_u16 extra)
            uae_u32 ad;
 
            if (get_fp_ad (opcode, &ad) == 0) {
-               m68k_setpc (m68k_getpc () - 4);
-               op_illg (opcode);
+               m68k_setpc (regs, m68k_getpc (regs) - 4);
+               op_illg (opcode, regs);
                return;
            }
            ad = (opcode & 0x38) == 0x20 ? ad - 12 : ad;
            if (extra & 0x1000) {
-               regs.fpcr = get_long (ad);
-               native_set_fpucw(regs.fpcr);
+               regs->fpcr = get_long (ad);
+               native_set_fpucw(regs->fpcr);
                ad += 4;
            }
            if (extra & 0x0800) {
@@ -1022,7 +1021,7 @@ void fpp_opp (uae_u32 opcode, uae_u16 extra)
                ad += 4;
            }
            if (extra & 0x0400) {
-               regs.fpiar = get_long (ad);
+               regs->fpiar = get_long (ad);
                ad += 4;
            }
            if ((opcode & 0x38) == 0x18)
@@ -1039,8 +1038,8 @@ void fpp_opp (uae_u32 opcode, uae_u16 extra)
        if (extra & 0x2000) {
            /* FMOVEM FPP->memory */
            if (get_fp_ad (opcode, &ad) == 0) {
-               m68k_setpc (m68k_getpc () - 4);
-               op_illg (opcode);
+               m68k_setpc (regs, m68k_getpc (regs) - 4);
+               op_illg (opcode, regs);
                return;
            }
            switch ((extra >> 11) & 3) {
@@ -1064,7 +1063,7 @@ void fpp_opp (uae_u32 opcode, uae_u16 extra)
            while (list) {
                uae_u32 wrd1, wrd2, wrd3;
                if (incr < 0) {
-                   from_exten (regs.fp[fpp_movem_index2[list]], &wrd1, &wrd2, &wrd3);
+                   from_exten (regs->fp[fpp_movem_index2[list]], &wrd1, &wrd2, &wrd3);
                    ad -= 4;
                    put_long (ad, wrd3);
                    ad -= 4;
@@ -1072,7 +1071,7 @@ void fpp_opp (uae_u32 opcode, uae_u16 extra)
                    ad -= 4;
                    put_long (ad, wrd1);
                } else {
-                   from_exten (regs.fp[fpp_movem_index1[list]], &wrd1, &wrd2, &wrd3);
+                   from_exten (regs->fp[fpp_movem_index1[list]], &wrd1, &wrd2, &wrd3);
                    put_long (ad, wrd1);
                    ad += 4;
                    put_long (ad, wrd2);
@@ -1089,8 +1088,8 @@ void fpp_opp (uae_u32 opcode, uae_u16 extra)
        } else {
            /* FMOVEM memory->FPP */
            if (get_fp_ad (opcode, &ad) == 0) {
-               m68k_setpc (m68k_getpc () - 4);
-               op_illg (opcode);
+               m68k_setpc (regs, m68k_getpc (regs) - 4);
+               op_illg (opcode, regs);
                return;
            }
            switch ((extra >> 11) & 3) {
@@ -1120,7 +1119,7 @@ void fpp_opp (uae_u32 opcode, uae_u16 extra)
                    wrd2 = get_long (ad);
                    ad -= 4;
                    wrd1 = get_long (ad);
-                   regs.fp[fpp_movem_index2[list]] = to_exten (wrd1, wrd2, wrd3);
+                   regs->fp[fpp_movem_index2[list]] = to_exten (wrd1, wrd2, wrd3);
                } else {
                    wrd1 = get_long (ad);
                    ad += 4;
@@ -1128,7 +1127,7 @@ void fpp_opp (uae_u32 opcode, uae_u16 extra)
                    ad += 4;
                    wrd3 = get_long (ad);
                    ad += 4;
-                   regs.fp[fpp_movem_index1[list]] = to_exten (wrd1, wrd2, wrd3);
+                   regs->fp[fpp_movem_index1[list]] = to_exten (wrd1, wrd2, wrd3);
                }
                list = fpp_movem_next[list];
            }
@@ -1145,89 +1144,89 @@ void fpp_opp (uae_u32 opcode, uae_u16 extra)
        if ((extra & 0xfc00) == 0x5c00) {
            switch (extra & 0x7f) {
            case 0x00:
-               regs.fp[reg] = *fp_pi;
+               regs->fp[reg] = *fp_pi;
                break;
            case 0x0b:
-               regs.fp[reg] = *fp_l10_2;
+               regs->fp[reg] = *fp_l10_2;
                break;
            case 0x0c:
-               regs.fp[reg] = *fp_exp_1;
+               regs->fp[reg] = *fp_exp_1;
                break;
            case 0x0d:
-               regs.fp[reg] = *fp_l2_e;
+               regs->fp[reg] = *fp_l2_e;
                break;
            case 0x0e:
-               regs.fp[reg] = *fp_l10_e;
+               regs->fp[reg] = *fp_l10_e;
                break;
            case 0x0f:
-               regs.fp[reg] = 0.0;
+               regs->fp[reg] = 0.0;
                break;
            case 0x30:
-               regs.fp[reg] = *fp_ln_2;
+               regs->fp[reg] = *fp_ln_2;
                break;
            case 0x31:
-               regs.fp[reg] = *fp_ln_10;
+               regs->fp[reg] = *fp_ln_10;
                break;
            case 0x32:
-               regs.fp[reg] = (fptype)fp_1e0;
+               regs->fp[reg] = (fptype)fp_1e0;
                break;
            case 0x33:
-               regs.fp[reg] = (fptype)fp_1e1;
+               regs->fp[reg] = (fptype)fp_1e1;
                break;
            case 0x34:
-               regs.fp[reg] = (fptype)fp_1e2;
+               regs->fp[reg] = (fptype)fp_1e2;
                break;
            case 0x35:
-               regs.fp[reg] = (fptype)fp_1e4;
+               regs->fp[reg] = (fptype)fp_1e4;
                break;
            case 0x36:
-               regs.fp[reg] = (fptype)fp_1e8;
+               regs->fp[reg] = (fptype)fp_1e8;
                break;
            case 0x37:
-               regs.fp[reg] = *fp_1e16;
+               regs->fp[reg] = *fp_1e16;
                break;
            case 0x38:
-               regs.fp[reg] = *fp_1e32;
+               regs->fp[reg] = *fp_1e32;
                break;
            case 0x39:
-               regs.fp[reg] = *fp_1e64;
+               regs->fp[reg] = *fp_1e64;
                break;
            case 0x3a:
-               regs.fp[reg] = *fp_1e128;
+               regs->fp[reg] = *fp_1e128;
                break;
            case 0x3b:
-               regs.fp[reg] = *fp_1e256;
+               regs->fp[reg] = *fp_1e256;
                break;
            case 0x3c:
-               regs.fp[reg] = *fp_1e512;
+               regs->fp[reg] = *fp_1e512;
                break;
            case 0x3d:
-               regs.fp[reg] = *fp_1e1024;
+               regs->fp[reg] = *fp_1e1024;
                break;
            case 0x3e:
-               regs.fp[reg] = *fp_1e2048;
+               regs->fp[reg] = *fp_1e2048;
                break;
            case 0x3f:
-               regs.fp[reg] = *fp_1e4096;
+               regs->fp[reg] = *fp_1e4096;
                break;
            default:
-               m68k_setpc (m68k_getpc () - 4);
-               op_illg (opcode);
+               m68k_setpc (regs, m68k_getpc (regs) - 4);
+               op_illg (opcode, regs);
                return;
            }
-           MAKE_FPSR (regs.fp[reg]); /* see Motorola 68k Manual */
+           MAKE_FPSR (regs, regs->fp[reg]); /* see Motorola 68k Manual */
            return;
        }
        if (get_fp_value (opcode, extra, &src) == 0) {
-           m68k_setpc (m68k_getpc () - 4);
-           op_illg (opcode);
+           m68k_setpc (regs, m68k_getpc (regs) - 4);
+           op_illg (opcode, regs);
            return;
        }
        switch (extra & 0x7f) {
        case 0x00: /* FMOVE */
        case 0x40: /* Explicit rounding. This is just a quick fix. */
        case 0x44: /* Same for all other cases that have three choices */
-           regs.fp[reg] = src;        /* Brian King was here. */
+           regs->fp[reg] = src;        /* Brian King was here. */
            /*<ea> to register needs FPSR updated. See Motorola 68K Manual. */
            if ((extra & 0x44) == 0x40)
                fround (reg);
@@ -1243,7 +1242,7 @@ void fpp_opp (uae_u32 opcode, uae_u16 extra)
                frndint
                fstp LDPTR tmp_fp
              }
-             regs.fp[reg] = tmp_fp;
+             regs->fp[reg] = tmp_fp;
            }
 #else /* no X86_MSVC */
            switch ((regs.fpcr >> 4) & 3) {
@@ -1268,154 +1267,154 @@ void fpp_opp (uae_u32 opcode, uae_u16 extra)
 #endif /* X86_MSVC */
            break;
        case 0x02: /* FSINH */
-           regs.fp[reg] = sinh (src);
+           regs->fp[reg] = sinh (src);
            break;
        case 0x03: /* FINTRZ */
            if (src >= 0.0)
-               regs.fp[reg] = floor (src);
+               regs->fp[reg] = floor (src);
            else
-               regs.fp[reg] = ceil (src);
+               regs->fp[reg] = ceil (src);
            break;
        case 0x04: /* FSQRT */
        case 0x41:
        case 0x45:
-           regs.fp[reg] = sqrt (src);
+           regs->fp[reg] = sqrt (src);
            if ((extra & 0x44) == 0x40)
                fround (reg);
            break;
        case 0x06: /* FLOGNP1 */
-           regs.fp[reg] = log (src + 1.0);
+           regs->fp[reg] = log (src + 1.0);
            break;
        case 0x08: /* FETOXM1 */
-           regs.fp[reg] = exp (src) - 1.0;
+           regs->fp[reg] = exp (src) - 1.0;
            break;
        case 0x09: /* FTANH */
-           regs.fp[reg] = tanh (src);
+           regs->fp[reg] = tanh (src);
            break;
        case 0x0a: /* FATAN */
-           regs.fp[reg] = atan (src);
+           regs->fp[reg] = atan (src);
            break;
        case 0x0c: /* FASIN */
-           regs.fp[reg] = asin (src);
+           regs->fp[reg] = asin (src);
            break;
        case 0x0d: /* FATANH */
 #if 1  /* The BeBox doesn't have atanh, and it isn't in the HPUX libm either */
-           regs.fp[reg] = 0.5 * log ((1 + src) / (1 - src));
+           regs->fp[reg] = 0.5 * log ((1 + src) / (1 - src));
 #else
-           regs.fp[reg] = atanh (src);
+           regs->fp[reg] = atanh (src);
 #endif
            break;
        case 0x0e: /* FSIN */
-           regs.fp[reg] = sin (src);
+           regs->fp[reg] = sin (src);
            break;
        case 0x0f: /* FTAN */
-           regs.fp[reg] = tan (src);
+           regs->fp[reg] = tan (src);
            break;
        case 0x10: /* FETOX */
-           regs.fp[reg] = exp (src);
+           regs->fp[reg] = exp (src);
            break;
        case 0x11: /* FTWOTOX */
-           regs.fp[reg] = pow (2.0, src);
+           regs->fp[reg] = pow (2.0, src);
            break;
        case 0x12: /* FTENTOX */
-           regs.fp[reg] = pow (10.0, src);
+           regs->fp[reg] = pow (10.0, src);
            break;
        case 0x14: /* FLOGN */
-           regs.fp[reg] = log (src);
+           regs->fp[reg] = log (src);
            break;
        case 0x15: /* FLOG10 */
-           regs.fp[reg] = log10 (src);
+           regs->fp[reg] = log10 (src);
            break;
        case 0x16: /* FLOG2 */
-           regs.fp[reg] = *fp_l2_e * log (src);
+           regs->fp[reg] = *fp_l2_e * log (src);
            break;
        case 0x18: /* FABS */
        case 0x58:
        case 0x5c:
-           regs.fp[reg] = src < 0 ? -src : src;
+           regs->fp[reg] = src < 0 ? -src : src;
            if ((extra & 0x44) == 0x40)
                fround (reg);
            break;
        case 0x19: /* FCOSH */
-           regs.fp[reg] = cosh (src);
+           regs->fp[reg] = cosh (src);
            break;
        case 0x1a: /* FNEG */
        case 0x5a:
        case 0x5e:
-           regs.fp[reg] = -src;
+           regs->fp[reg] = -src;
            if ((extra & 0x44) == 0x40)
                fround (reg);
            break;
        case 0x1c: /* FACOS */
-           regs.fp[reg] = acos (src);
+           regs->fp[reg] = acos (src);
            break;
        case 0x1d: /* FCOS */
-           regs.fp[reg] = cos (src);
+           regs->fp[reg] = cos (src);
            break;
        case 0x1e: /* FGETEXP */
            {
              int expon;
              frexp (src, &expon);
-             regs.fp[reg] = (double) (expon - 1);
+             regs->fp[reg] = (double) (expon - 1);
            }
            break;
        case 0x1f: /* FGETMAN */
            {
              int expon;
-             regs.fp[reg] = frexp (src, &expon) * 2.0;
+             regs->fp[reg] = frexp (src, &expon) * 2.0;
            }
            break;
        case 0x20: /* FDIV */
        case 0x60:
        case 0x64:
-           regs.fp[reg] /= src;
+           regs->fp[reg] /= src;
            if ((extra & 0x44) == 0x40)
                fround (reg);
            break;
        case 0x21: /* FMOD */
            {
-             fptype divi = regs.fp[reg] / src;
+             fptype divi = regs->fp[reg] / src;
 
              if (divi >= 0.0)
-               regs.fp[reg] -= src * floor (divi);
+               regs->fp[reg] -= src * floor (divi);
              else
-               regs.fp[reg] -= src * ceil (divi);
+               regs->fp[reg] -= src * ceil (divi);
            }
            break;
        case 0x22: /* FADD */
        case 0x62:
        case 0x66:
-           regs.fp[reg] += src;
+           regs->fp[reg] += src;
            if ((extra & 0x44) == 0x40)
                fround (reg);
            break;
        case 0x23: /* FMUL */
        case 0x63:
        case 0x67:
-           regs.fp[reg] *= src;
+           regs->fp[reg] *= src;
            if ((extra & 0x44) == 0x40)
                fround (reg);
            break;
        case 0x24: /* FSGLDIV */
-           regs.fp[reg] /= src;
+           regs->fp[reg] /= src;
            break;
        case 0x25: /* FREM */
-           regs.fp[reg] -= src * floor ((regs.fp[reg] / src) + 0.5);
+           regs->fp[reg] -= src * floor ((regs->fp[reg] / src) + 0.5);
            break;
        case 0x26: /* FSCALE */
 #ifdef ldexp
-           regs.fp[reg] = ldexp (regs.fp[reg], (int) src);
+           regs->fp[reg] = ldexp (regs->fp[reg], (int) src);
 #else
-           regs.fp[reg] *= exp (*fp_ln_2 * (int) src);
+           regs->fp[reg] *= exp (*fp_ln_2 * (int) src);
 #endif
            break;
        case 0x27: /* FSGLMUL */
-           regs.fp[reg] *= src;
+           regs->fp[reg] *= src;
            break;
        case 0x28: /* FSUB */
        case 0x68:
        case 0x6c:
-           regs.fp[reg] -= src;
+           regs->fp[reg] -= src;
            if ((extra & 0x44) == 0x40)
                fround (reg);
            break;
@@ -1427,30 +1426,30 @@ void fpp_opp (uae_u32 opcode, uae_u16 extra)
        case 0x35:
        case 0x36:
        case 0x37:
-           regs.fp[extra & 7] = cos (src);
-           regs.fp[reg] = sin (src);
+           regs->fp[extra & 7] = cos (src);
+           regs->fp[reg] = sin (src);
            break;
        case 0x38: /* FCMP */
            {
-             fptype tmp = regs.fp[reg] - src;
-             regs.fpsr = 0;
-             MAKE_FPSR (tmp);
+             fptype tmp = regs->fp[reg] - src;
+             regs->fpsr = 0;
+             MAKE_FPSR (regs, tmp);
            }
            return;
        case 0x3a: /* FTST */
-           regs.fpsr = 0;
-           MAKE_FPSR (src);
+           regs->fpsr = 0;
+           MAKE_FPSR (regs, src);
            return;
        default:
-           m68k_setpc (m68k_getpc () - 4);
-           op_illg (opcode);
+           m68k_setpc (regs, m68k_getpc (regs) - 4);
+           op_illg (opcode, regs);
            return;
        }
-       MAKE_FPSR (regs.fp[reg]);
+       MAKE_FPSR (regs, regs->fp[reg]);
        return;
     }
-    m68k_setpc (m68k_getpc () - 4);
-    op_illg (opcode);
+    m68k_setpc (regs, m68k_getpc (regs) - 4);
+    op_illg (opcode, regs);
 }
 
 #endif
@@ -1463,7 +1462,7 @@ uae_u8 *restore_fpu (uae_u8 *src)
     restore_u32 ();
     if (currprefs.cpu_level == 2) {
        currprefs.cpu_level++;
-       init_m68k_full ();
+       init_m68k ();
     }
     changed_prefs.cpu_level = currprefs.cpu_level;
     for (i = 0; i < 8; i++) {
diff --git a/fsdb.c b/fsdb.c
index 69310f21cb9db8ba247a0d35f6dca2e5daa3f24d..7e7e9aca3aefe9fe1510f5aef5fd3c7170354432 100755 (executable)
--- a/fsdb.c
+++ b/fsdb.c
@@ -10,8 +10,6 @@
 #include "sysconfig.h"
 #include "sysdeps.h"
 
-#include "config.h"
-#include "threaddep/thread.h"
 #include "options.h"
 #include "uae.h"
 #include "memory.h"
diff --git a/gayle.c b/gayle.c
index 5dd8e9b8bda053890e4d31a19c0e7b0cc39dbe59..c3f4a102995a06c5fe1743cb44cd00d03c10adb1 100755 (executable)
--- a/gayle.c
+++ b/gayle.c
@@ -146,7 +146,7 @@ static int gayle_read (uaecptr addr, int size)
     special_mem |= S_READ;
 #endif
     if (GAYLE_LOG)
-       write_log ("GAYLE_READ %08.8X PC=%08.8X\n", addr, m68k_getpc());
+       write_log ("GAYLE_READ %08.8X PC=%08.8X\n", addr, M68K_GETPC);
     addr &= 0xfffff;
     if(addr >= 0xa0000 && addr <= 0xaffff)
        return ide_read(addr, size);
@@ -162,7 +162,7 @@ static void gayle_write (uaecptr addr, int val, int size)
     special_mem |= S_WRITE;
 #endif
     if (GAYLE_LOG)
-       write_log ("GAYLE_WRITE %08.8X=%08.8X (%d) PC=%08.8X\n", addr, val, size, m68k_getpc());
+       write_log ("GAYLE_WRITE %08.8X=%08.8X (%d) PC=%08.8X\n", addr, val, size, M68K_GETPC);
     addr &= 0x3ffff;
     if(addr >= 0xa0000 && addr <= 0xaffff)
        ide_write(addr, val, size);
@@ -170,12 +170,12 @@ static void gayle_write (uaecptr addr, int val, int size)
        ide_write(addr, val, size);
 }
 
-static uae_u32 gayle_lget (uaecptr) REGPARAM;
-static uae_u32 gayle_wget (uaecptr) REGPARAM;
-static uae_u32 gayle_bget (uaecptr) REGPARAM;
-static void gayle_lput (uaecptr, uae_u32) REGPARAM;
-static void gayle_wput (uaecptr, uae_u32) REGPARAM;
-static void gayle_bput (uaecptr, uae_u32) REGPARAM;
+static uae_u32 REGPARAM3 gayle_lget (uaecptr) REGPARAM;
+static uae_u32 REGPARAM3 gayle_wget (uaecptr) REGPARAM;
+static uae_u32 REGPARAM3 gayle_bget (uaecptr) REGPARAM;
+static void REGPARAM3 gayle_lput (uaecptr, uae_u32) REGPARAM;
+static void REGPARAM3 gayle_wput (uaecptr, uae_u32) REGPARAM;
+static void REGPARAM3 gayle_bput (uaecptr, uae_u32) REGPARAM;
 
 addrbank gayle_bank = {
     gayle_lget, gayle_wget, gayle_bget,
index c019395d48fac9323931e233c63c460872cb6486..1e33527cc5e3dcd3fc2cd4931dcc9305826a9fde 100755 (executable)
@@ -37,7 +37,6 @@ static void generate_func(void)
     unsigned int i;
     printf("#include \"sysconfig.h\"\n");
     printf("#include \"sysdeps.h\"\n");
-    printf("#include \"config.h\"\n");
     printf("#include \"options.h\"\n");
     printf("#include \"custom.h\"\n");
     printf("#include \"memory.h\"\n");
@@ -209,13 +208,12 @@ static void generate_table(void)
     unsigned int i;
     printf("#include \"sysconfig.h\"\n");
     printf("#include \"sysdeps.h\"\n");
-    printf("#include \"config.h\"\n");
     printf("#include \"options.h\"\n");
     printf("#include \"custom.h\"\n");
     printf("#include \"memory.h\"\n");
     printf("#include \"blitter.h\"\n");
     printf("#include \"blitfunc.h\"\n\n");
-    printf("blitter_func *blitfunc_dofast[256] = {\n");
+    printf("blitter_func * const blitfunc_dofast[256] = {\n");
     for (i = 0; i < 256; i++) {
        if (index < sizeof(blttbl) && i == blttbl[index]) {
            printf("blitdofast_%x",i);
@@ -228,7 +226,7 @@ static void generate_table(void)
     printf("};\n\n");
 
     index = 0;
-    printf("blitter_func *blitfunc_dofast_desc[256] = {\n");
+    printf("blitter_func * const blitfunc_dofast_desc[256] = {\n");
     for (i = 0; i < 256; i++) {
        if (index < sizeof(blttbl) && i == blttbl[index]) {
            printf("blitdofast_desc_%x",i);
index 64e00591ef229144b93a7330d2a3e0086a134880..ce5a04a30859e301bcf6f897b73718c2a8867cad 100755 (executable)
--- a/gencomp.c
+++ b/gencomp.c
@@ -725,12 +725,12 @@ genmovemel (uae_u16 opcode)
     switch(table68k[opcode].size) {
      case sz_long:
        comprintf("\t\t\tmov_l_rR(i,native,offset);\n"
-                 "\t\t\tbswap_32(i);\n"
+                 "\t\t\tgen_bswap_32(i);\n"
                  "\t\t\toffset+=4;\n");
        break;
      case sz_word:
        comprintf("\t\t\tmov_w_rR(i,native,offset);\n"
-                 "\t\t\tbswap_16(i);\n"
+                 "\t\t\tgen_bswap_16(i);\n"
                  "\t\t\tsign_extend_16_rr(i,i);\n"
                  "\t\t\toffset+=2;\n");
        break;
@@ -796,13 +796,13 @@ genmovemle (uae_u16 opcode)
        switch(table68k[opcode].size) {
         case sz_long:
            comprintf("\t\t\tmov_l_rr(tmp,i);\n"
-                     "\t\t\tbswap_32(tmp);\n"
+                     "\t\t\tgen_bswap_32(tmp);\n"
                      "\t\t\tmov_l_Rr(native,tmp,offset);\n"
                      "\t\t\toffset+=4;\n");
            break;
         case sz_word:
            comprintf("\t\t\tmov_l_rr(tmp,i);\n"
-                     "\t\t\tbswap_16(tmp);\n"
+                     "\t\t\tgen_bswap_16(tmp);\n"
                      "\t\t\tmov_w_Rr(native,tmp,offset);\n"
                      "\t\t\toffset+=2;\n");
            break;
@@ -815,14 +815,14 @@ genmovemle (uae_u16 opcode)
         case sz_long:
            comprintf("\t\t\toffset-=4;\n"
                      "\t\t\tmov_l_rr(tmp,15-i);\n"
-                     "\t\t\tbswap_32(tmp);\n"
+                     "\t\t\tgen_bswap_32(tmp);\n"
                      "\t\t\tmov_l_Rr(native,tmp,offset);\n"
                      );
            break;
         case sz_word:
            comprintf("\t\t\toffset-=2;\n"
                      "\t\t\tmov_l_rr(tmp,15-i);\n"
-                     "\t\t\tbswap_16(tmp);\n"
+                     "\t\t\tgen_bswap_16(tmp);\n"
                      "\t\t\tmov_w_Rr(native,tmp,offset);\n"
                      );
            break;
@@ -2865,7 +2865,6 @@ generate_includes (FILE * f)
     fprintf (f, "#include \"sysconfig.h\"\n");
     fprintf (f, "#if defined(JIT)\n");
     fprintf (f, "#include \"sysdeps.h\"\n");
-    fprintf (f, "#include \"config.h\"\n");
     fprintf (f, "#include \"options.h\"\n");
     fprintf (f, "#include \"memory.h\"\n");
     fprintf (f, "#include \"custom.h\"\n");
@@ -3010,11 +3009,11 @@ generate_one_opcode (int rp, int noflags)
        } else {
            if (noflags) {
                fprintf (stblfile, "{ op_%lx_%d_comp_nf, %ld, 0x%08x }, /* %s */\n", opcode, postfix, opcode, flags, lookuptab[i].name);
-               fprintf (headerfile, "extern cpuop_func op_%lx_%d_comp_nf;\n", opcode, postfix);
+               fprintf (headerfile, "extern compop_func op_%lx_%d_comp_nf;\n", opcode, postfix);
                printf ("unsigned long REGPARAM2 op_%lx_%d_comp_nf(uae_u32 opcode) /* %s */\n{\n", opcode, postfix, lookuptab[i].name);
            } else {
                fprintf (stblfile, "{ op_%lx_%d_comp_ff, %ld, 0x%08x }, /* %s */\n", opcode, postfix, opcode, flags, lookuptab[i].name);
-               fprintf (headerfile, "extern cpuop_func op_%lx_%d_comp_ff;\n", opcode, postfix);
+               fprintf (headerfile, "extern compop_func op_%lx_%d_comp_ff;\n", opcode, postfix);
                printf ("unsigned long REGPARAM2 op_%lx_%d_comp_ff(uae_u32 opcode) /* %s */\n{\n", opcode, postfix, lookuptab[i].name);
            }
            com_flush();
@@ -3037,9 +3036,9 @@ generate_func (int noflags)
        postfix = i;
 
        if (noflags)
-           fprintf (stblfile, "struct cputbl op_smalltbl_%d_comp_nf[] = {\n", postfix);
+           fprintf (stblfile, "const struct comptbl op_smalltbl_%d_comp_nf[] = {\n", postfix);
        else
-           fprintf (stblfile, "struct cputbl op_smalltbl_%d_comp_ff[] = {\n", postfix);
+           fprintf (stblfile, "const struct comptbl op_smalltbl_%d_comp_ff[] = {\n", postfix);
 
 
        /* sam: this is for people with low memory (eg. me :)) */
index 9ba5b0d185b3a7bd917fa101dc2250483ecac903..47cf46c52a2675773dea233cf4a701ed429b9b72 100755 (executable)
--- a/gencpu.c
+++ b/gencpu.c
@@ -193,26 +193,26 @@ static void gen_nextilong (char *type, char *name, int norefill)
        printf ("\t%s %s;\n", type, name);
        /* we must do this because execution order of (something | something2) is not defined */
        if (norefill) {
-           printf ("\t%s = get_word_ce_prefetch (%d) << 16;\n", name, r + 2);
-           printf ("\t%s |= regs.irc;\n", name);
+           printf ("\t%s = get_word_ce_prefetch (regs, %d) << 16;\n", name, r + 2);
+           printf ("\t%s |= regs->irc;\n", name);
        } else {
-           printf ("\t%s = get_word_ce_prefetch (%d) << 16;\n", name, r + 2);
-           printf ("\t%s |= get_word_ce_prefetch (%d);\n", name, r + 4);
+           printf ("\t%s = get_word_ce_prefetch (regs, %d) << 16;\n", name, r + 2);
+           printf ("\t%s |= get_word_ce_prefetch (regs, %d);\n", name, r + 4);
        }
     } else {
        if (using_prefetch) {
            if (norefill) {
                printf ("\t%s %s;\n", type, name);
-               printf ("\t%s = get_word_prefetch (%d) << 16;\n", name, r + 2);
-               printf ("\t%s |= regs.irc;\n", name);
+               printf ("\t%s = get_word_prefetch (regs, %d) << 16;\n", name, r + 2);
+               printf ("\t%s |= regs->irc;\n", name);
                insn_n_cycles += 4;
            } else {
-               printf ("\t%s %s = get_long_prefetch (%d);\n", type, name, r + 2);
+               printf ("\t%s %s = get_long_prefetch (regs, %d);\n", type, name, r + 2);
                insn_n_cycles += 8;
            }
        } else {
            insn_n_cycles += 8;
-           printf ("\t%s %s = get_ilong (%d);\n", type, name, r);
+           printf ("\t%s %s = get_ilong (regs, %d);\n", type, name, r);
        }
     }
 }
@@ -225,19 +225,19 @@ static const char *gen_nextiword (int norefill)
 
     if (using_ce) {
        if (norefill)
-           strcpy (buffer, "regs.irc");
+           strcpy (buffer, "regs->irc");
        else
-           sprintf (buffer, "get_word_ce_prefetch (%d)", r + 2);
+           sprintf (buffer, "get_word_ce_prefetch (regs, %d)", r + 2);
     } else {
        if (using_prefetch) {
            if (norefill) {
-               sprintf (buffer, "regs.irc", r);
+               sprintf (buffer, "regs->irc", r);
            } else {
-               sprintf (buffer, "get_word_prefetch (%d)", r + 2);
+               sprintf (buffer, "get_word_prefetch (regs, %d)", r + 2);
                insn_n_cycles += 4;
            }
        } else {
-           sprintf (buffer, "get_iword (%d)", r);
+           sprintf (buffer, "get_iword (regs, %d)", r);
            insn_n_cycles += 4;
        }
     }
@@ -252,20 +252,20 @@ static const char *gen_nextibyte (int norefill)
 
     if (using_ce) {
        if (norefill)
-           strcpy (buffer, "(uae_u8)regs.irc");
+           strcpy (buffer, "(uae_u8)regs->irc");
        else
-           sprintf (buffer, "(uae_u8)get_word_ce_prefetch (%d)", r + 2);
+           sprintf (buffer, "(uae_u8)get_word_ce_prefetch (regs, %d)", r + 2);
     } else {
        insn_n_cycles += 4;
        if (using_prefetch) {
            if (norefill) {
-               sprintf (buffer, "(uae_u8)regs.irc", r);
+               sprintf (buffer, "(uae_u8)regs->irc", r);
            } else {
-               sprintf (buffer, "(uae_u8)get_word_prefetch (%d)", r + 2);
+               sprintf (buffer, "(uae_u8)get_word_prefetch (regs, %d)", r + 2);
                insn_n_cycles += 4;
            }
        } else {
-           sprintf (buffer, "get_ibyte (%d)", r);
+           sprintf (buffer, "get_ibyte (regs, %d)", r);
            insn_n_cycles += 4;
        }
     }
@@ -276,7 +276,7 @@ static void irc2ir (void)
 {
     if (!using_prefetch)
        return;
-    printf ("\tregs.ir = regs.irc;\n");
+    printf ("\tregs->ir = regs->irc;\n");
 }
 
 static int did_prefetch;
@@ -286,9 +286,9 @@ static void fill_prefetch_2 (void)
     if (!using_prefetch)
        return;
     if (using_ce)
-       printf ("\tget_word_ce_prefetch (%d);\n", m68k_pc_offset + 2);
+       printf ("\tget_word_ce_prefetch (regs, %d);\n", m68k_pc_offset + 2);
     else
-       printf ("\tget_word_prefetch (%d);\n", m68k_pc_offset + 2);
+       printf ("\tget_word_prefetch (regs, %d);\n", m68k_pc_offset + 2);
     did_prefetch = 1;
     insn_n_cycles += 4;
 }
@@ -298,9 +298,9 @@ static void fill_prefetch_1 (int o)
     if (!using_prefetch)
        return;
     if (using_ce) {
-       printf ("\tget_word_ce_prefetch (%d);\n", o);
+       printf ("\tget_word_ce_prefetch (regs, %d);\n", o);
     } else {
-       printf ("\tget_word_prefetch (%d);\n", o);
+       printf ("\tget_word_prefetch (regs, %d);\n", o);
     }
     did_prefetch = 1;
     insn_n_cycles += 4;
@@ -318,9 +318,9 @@ static void fill_prefetch_0 (void)
     if (!using_prefetch)
        return;
     if (using_ce)
-       printf ("\tget_word_ce_prefetch (0);\n");
+       printf ("\tget_word_ce_prefetch (regs, 0);\n");
     else
-       printf ("\tget_word_prefetch (0);\n");
+       printf ("\tget_word_prefetch (regs, 0);\n");
     did_prefetch = 1;
     insn_n_cycles += 4;
 }
@@ -368,7 +368,7 @@ static void sync_m68k_pc (void)
 {
     if (m68k_pc_offset == 0)
        return;
-    printf ("\tm68k_incpc (%d);\n", m68k_pc_offset);
+    printf ("\tm68k_incpc (regs, %d);\n", m68k_pc_offset);
     m68k_pc_offset = 0;
 }
 
@@ -468,16 +468,16 @@ static void genamode2 (amodes mode, char *reg, wordsizes size, char *name, int g
            start_brace ();
            /* This would ordinarily be done in gen_nextiword, which we bypass.  */
            insn_n_cycles += 4;
-           printf ("\t%sa = get_disp_ea_020(m68k_areg(regs, %s), next_iword());\n", name, reg);
+           printf ("\t%sa = get_disp_ea_020(regs, m68k_areg(regs, %s), next_iword(regs));\n", name, reg);
        } else
-           printf ("\t%sa = get_disp_ea_000(m68k_areg(regs, %s), %s);\n", name, reg, gen_nextiword (flags & GF_NOREFILL));
+           printf ("\t%sa = get_disp_ea_000(regs, m68k_areg(regs, %s), %s);\n", name, reg, gen_nextiword (flags & GF_NOREFILL));
        if (!(flags & GF_AD8R)) {
            addcycles (2);
            insn_n_cycles += 2;
        }
        break;
     case PC16:
-       printf ("\tuaecptr %sa = m68k_getpc () + %d;\n", name, m68k_pc_offset);
+       printf ("\tuaecptr %sa = m68k_getpc (regs) + %d;\n", name, m68k_pc_offset);
        printf ("\t%sa += (uae_s32)(uae_s16)%s;\n", name, gen_nextiword (flags & GF_NOREFILL));
        break;
     case PC8r:
@@ -490,11 +490,11 @@ static void genamode2 (amodes mode, char *reg, wordsizes size, char *name, int g
            start_brace ();
            /* This would ordinarily be done in gen_nextiword, which we bypass.  */
            insn_n_cycles += 4;
-           printf ("\ttmppc = m68k_getpc();\n");
-           printf ("\t%sa = get_disp_ea_020(tmppc, next_iword());\n", name);
+           printf ("\ttmppc = m68k_getpc(regs);\n");
+           printf ("\t%sa = get_disp_ea_020(regs, tmppc, next_iword(regs));\n", name);
        } else {
-           printf ("\ttmppc = m68k_getpc() + %d;\n", m68k_pc_offset);
-           printf ("\t%sa = get_disp_ea_000(tmppc, %s);\n", name, gen_nextiword (flags & GF_NOREFILL));
+           printf ("\ttmppc = m68k_getpc(regs) + %d;\n", m68k_pc_offset);
+           printf ("\t%sa = get_disp_ea_000(regs, tmppc, %s);\n", name, gen_nextiword (flags & GF_NOREFILL));
        }
        if (!(flags & GF_PC8R)) {
            addcycles (2);
@@ -554,7 +554,7 @@ static void genamode2 (amodes mode, char *reg, wordsizes size, char *name, int g
 
     if ((using_prefetch || using_ce) && using_exception_3 && getv != 0 && size != sz_byte) {
        printf ("\tif (%sa & 1) {\n", name);
-       printf ("\t\texception3 (opcode, m68k_getpc() + %d, %sa);\n",
+       printf ("\t\texception3 (opcode, m68k_getpc(regs) + %d, %sa);\n",
            m68k_pc_offset_last + e3fudge, name);
        printf ("\t\tgoto %s;\n", endlabelstr);
        printf ("\t}\n");
@@ -856,7 +856,7 @@ static void duplicate_carry (int n)
     int i;
     for (i = 0; i <= n; i++)
        printf ("\t");
-    printf ("COPY_CARRY;\n");
+    printf ("COPY_CARRY (&regs->ccrflags);\n");
 }
 
 typedef enum
@@ -956,53 +956,53 @@ static void genflags_normal (flagtypes type, wordsizes size, char *value, char *
 
     switch (type) {
      case flag_logical:
-       printf ("\tCLEAR_CZNV;\n");
-       printf ("\tSET_ZFLG (%s == 0);\n", vstr);
-       printf ("\tSET_NFLG (%s < 0);\n", vstr);
+       printf ("\tCLEAR_CZNV (&regs->ccrflags);\n");
+       printf ("\tSET_ZFLG   (&regs->ccrflags, %s == 0);\n", vstr);
+       printf ("\tSET_NFLG   (&regs->ccrflags, %s < 0);\n", vstr);
        break;
      case flag_logical_noclobber:
-       printf ("\tSET_ZFLG (%s == 0);\n", vstr);
-       printf ("\tSET_NFLG (%s < 0);\n", vstr);
+       printf ("\tSET_ZFLG (&regs->ccrflags, %s == 0);\n", vstr);
+       printf ("\tSET_NFLG (&regs->ccrflags, %s < 0);\n", vstr);
        break;
      case flag_av:
-       printf ("\tSET_VFLG ((flgs ^ flgn) & (flgo ^ flgn));\n");
+       printf ("\tSET_VFLG (&regs->ccrflags, (flgs ^ flgn) & (flgo ^ flgn));\n");
        break;
      case flag_sv:
-       printf ("\tSET_VFLG ((flgs ^ flgo) & (flgn ^ flgo));\n");
+       printf ("\tSET_VFLG (&regs->ccrflags, (flgs ^ flgo) & (flgn ^ flgo));\n");
        break;
      case flag_zn:
-       printf ("\tSET_ZFLG (GET_ZFLG & (%s == 0));\n", vstr);
-       printf ("\tSET_NFLG (%s < 0);\n", vstr);
+       printf ("\tSET_ZFLG (&regs->ccrflags, GET_ZFLG (&regs->ccrflags) & (%s == 0));\n", vstr);
+       printf ("\tSET_NFLG (&regs->ccrflags, %s < 0);\n", vstr);
        break;
      case flag_add:
-       printf ("\tSET_ZFLG (%s == 0);\n", vstr);
-       printf ("\tSET_VFLG ((flgs ^ flgn) & (flgo ^ flgn));\n");
-       printf ("\tSET_CFLG (%s < %s);\n", undstr, usstr);
+       printf ("\tSET_ZFLG (&regs->ccrflags, %s == 0);\n", vstr);
+       printf ("\tSET_VFLG (&regs->ccrflags, (flgs ^ flgn) & (flgo ^ flgn));\n");
+       printf ("\tSET_CFLG (&regs->ccrflags, %s < %s);\n", undstr, usstr);
        duplicate_carry (0);
-       printf ("\tSET_NFLG (flgn != 0);\n");
+       printf ("\tSET_NFLG (&regs->ccrflags, flgn != 0);\n");
        break;
      case flag_sub:
-       printf ("\tSET_ZFLG (%s == 0);\n", vstr);
-       printf ("\tSET_VFLG ((flgs ^ flgo) & (flgn ^ flgo));\n");
-       printf ("\tSET_CFLG (%s > %s);\n", usstr, udstr);
+       printf ("\tSET_ZFLG (&regs->ccrflags, %s == 0);\n", vstr);
+       printf ("\tSET_VFLG (&regs->ccrflags, (flgs ^ flgo) & (flgn ^ flgo));\n");
+       printf ("\tSET_CFLG (&regs->ccrflags, %s > %s);\n", usstr, udstr);
        duplicate_carry (0);
-       printf ("\tSET_NFLG (flgn != 0);\n");
+       printf ("\tSET_NFLG (&regs->ccrflags, flgn != 0);\n");
        break;
      case flag_addx:
-       printf ("\tSET_VFLG ((flgs ^ flgn) & (flgo ^ flgn));\n"); /* minterm SON: 0x42 */
-       printf ("\tSET_CFLG (flgs ^ ((flgs ^ flgo) & (flgo ^ flgn)));\n"); /* minterm SON: 0xD4 */
+       printf ("\tSET_VFLG (&regs->ccrflags, (flgs ^ flgn) & (flgo ^ flgn));\n"); /* minterm SON: 0x42 */
+       printf ("\tSET_CFLG (&regs->ccrflags, flgs ^ ((flgs ^ flgo) & (flgo ^ flgn)));\n"); /* minterm SON: 0xD4 */
        duplicate_carry (0);
        break;
      case flag_subx:
-       printf ("\tSET_VFLG ((flgs ^ flgo) & (flgo ^ flgn));\n"); /* minterm SON: 0x24 */
-       printf ("\tSET_CFLG (flgs ^ ((flgs ^ flgn) & (flgo ^ flgn)));\n"); /* minterm SON: 0xB2 */
+       printf ("\tSET_VFLG (&regs->ccrflags, (flgs ^ flgo) & (flgo ^ flgn));\n"); /* minterm SON: 0x24 */
+       printf ("\tSET_CFLG (&regs->ccrflags, flgs ^ ((flgs ^ flgn) & (flgo ^ flgn)));\n"); /* minterm SON: 0xB2 */
        duplicate_carry (0);
        break;
      case flag_cmp:
-       printf ("\tSET_ZFLG (%s == 0);\n", vstr);
-       printf ("\tSET_VFLG ((flgs != flgo) && (flgn != flgo));\n");
-       printf ("\tSET_CFLG (%s > %s);\n", usstr, udstr);
-       printf ("\tSET_NFLG (flgn != 0);\n");
+       printf ("\tSET_ZFLG (&regs->ccrflags, %s == 0);\n", vstr);
+       printf ("\tSET_VFLG (&regs->ccrflags, (flgs != flgo) && (flgn != flgo));\n");
+       printf ("\tSET_CFLG (&regs->ccrflags, %s > %s);\n", usstr, udstr);
+       printf ("\tSET_NFLG (&regs->ccrflags, flgn != 0);\n");
        break;
     }
 }
@@ -1148,14 +1148,14 @@ static void gen_opcode (unsigned long int opcode)
 
        /* fall through */
     case 2: /* priviledged */
-       printf ("if (!regs.s) { Exception(8,0); goto %s; }\n", endlabelstr);
+       printf ("if (!regs->s) { Exception(8, regs, 0); goto %s; }\n", endlabelstr);
        need_endlabel = 1;
        start_brace ();
        break;
     case 3: /* privileged if size == word */
        if (curi->size == sz_byte)
            break;
-       printf ("if (!regs.s) { Exception(8,0); goto %s; }\n", endlabelstr);
+       printf ("if (!regs->s) { Exception(8, regs, 0); goto %s; }\n", endlabelstr);
        need_endlabel = 1;
        start_brace ();
        break;
@@ -1175,26 +1175,26 @@ static void gen_opcode (unsigned long int opcode)
        break;
     case i_ORSR:
     case i_EORSR:
-       printf ("\tMakeSR();\n");
+       printf ("\tMakeSR(regs);\n");
        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0);
        if (curi->size == sz_byte) {
            printf ("\tsrc &= 0xFF;\n");
        }
        addcycles (4);
        fill_prefetch_next ();
-       printf ("\tregs.sr %c= src;\n", curi->mnemo == i_EORSR ? '^' : '|');
-       printf ("\tMakeFromSR();\n");
+       printf ("\tregs->sr %c= src;\n", curi->mnemo == i_EORSR ? '^' : '|');
+       printf ("\tMakeFromSR(regs);\n");
        break;
     case i_ANDSR:
-       printf ("\tMakeSR();\n");
+       printf ("\tMakeSR(regs);\n");
        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0);
        if (curi->size == sz_byte) {
            printf ("\tsrc |= 0xFF00;\n");
        }
        addcycles (4);
        fill_prefetch_next ();
-       printf ("\tregs.sr &= src;\n");
-       printf ("\tMakeFromSR();\n");
+       printf ("\tregs->sr &= src;\n");
+       printf ("\tMakeFromSR(regs);\n");
        break;
     case i_SUB:
        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0);
@@ -1229,7 +1229,7 @@ static void gen_opcode (unsigned long int opcode)
            addcycles (2);
        fill_prefetch_next ();
        start_brace ();
-       printf ("\tuae_u32 newv = dst - src - (GET_XFLG ? 1 : 0);\n");
+       printf ("\tuae_u32 newv = dst - src - (GET_XFLG (&regs->ccrflags) ? 1 : 0);\n");
        genflags (flag_subx, curi->size, "newv", "src", "dst");
        genflags (flag_zn, curi->size, "newv", "", "");
        genastore ("newv", curi->dmode, "dstreg", curi->size, "dst");
@@ -1239,17 +1239,17 @@ static void gen_opcode (unsigned long int opcode)
        genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0, GF_AA);
        fill_prefetch_next ();
        start_brace ();
-       printf ("\tuae_u16 newv_lo = (dst & 0xF) - (src & 0xF) - (GET_XFLG ? 1 : 0);\n");
+       printf ("\tuae_u16 newv_lo = (dst & 0xF) - (src & 0xF) - (GET_XFLG (&regs->ccrflags) ? 1 : 0);\n");
        printf ("\tuae_u16 newv_hi = (dst & 0xF0) - (src & 0xF0);\n");
        printf ("\tuae_u16 newv, tmp_newv;\n");
        printf ("\tint bcd = 0;\n");
        printf ("\tnewv = tmp_newv = newv_hi + newv_lo;\n");
        printf ("\tif (newv_lo & 0xF0) { newv -= 6; bcd = 6; };\n");
-       printf ("\tif ((((dst & 0xFF) - (src & 0xFF) - (GET_XFLG ? 1 : 0)) & 0x100) > 0xFF) { newv -= 0x60; }\n");
-       printf ("\tSET_CFLG ((((dst & 0xFF) - (src & 0xFF) - bcd - (GET_XFLG ? 1 : 0)) & 0x300) > 0xFF);\n");
+       printf ("\tif ((((dst & 0xFF) - (src & 0xFF) - (GET_XFLG (&regs->ccrflags) ? 1 : 0)) & 0x100) > 0xFF) { newv -= 0x60; }\n");
+       printf ("\tSET_CFLG (&regs->ccrflags, (((dst & 0xFF) - (src & 0xFF) - bcd - (GET_XFLG (&regs->ccrflags) ? 1 : 0)) & 0x300) > 0xFF);\n");
        duplicate_carry (0);
        genflags (flag_zn, curi->size, "newv", "", "");
-       printf ("\tSET_VFLG ((tmp_newv & 0x80) != 0 && (newv & 0x80) == 0);\n");
+       printf ("\tSET_VFLG (&regs->ccrflags, (tmp_newv & 0x80) != 0 && (newv & 0x80) == 0);\n");
        addcycles (2);
        genastore ("newv", curi->dmode, "dstreg", curi->size, "dst");
        break;
@@ -1286,7 +1286,7 @@ static void gen_opcode (unsigned long int opcode)
            addcycles (2);
        fill_prefetch_next ();
        start_brace ();
-       printf ("\tuae_u32 newv = dst + src + (GET_XFLG ? 1 : 0);\n");
+       printf ("\tuae_u32 newv = dst + src + (GET_XFLG (&regs->ccrflags) ? 1 : 0);\n");
        genflags (flag_addx, curi->size, "newv", "src", "dst");
        genflags (flag_zn, curi->size, "newv", "", "");
        genastore ("newv", curi->dmode, "dstreg", curi->size, "dst");
@@ -1296,7 +1296,7 @@ static void gen_opcode (unsigned long int opcode)
        genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0, GF_AA);
        fill_prefetch_next ();
        start_brace ();
-       printf ("\tuae_u16 newv_lo = (src & 0xF) + (dst & 0xF) + (GET_XFLG ? 1 : 0);\n");
+       printf ("\tuae_u16 newv_lo = (src & 0xF) + (dst & 0xF) + (GET_XFLG (&regs->ccrflags) ? 1 : 0);\n");
        printf ("\tuae_u16 newv_hi = (src & 0xF0) + (dst & 0xF0);\n");
        printf ("\tuae_u16 newv, tmp_newv;\n");
        printf ("\tint cflg;\n");
@@ -1304,10 +1304,10 @@ static void gen_opcode (unsigned long int opcode)
        printf ("\tif (newv_lo > 9) { newv += 6; }\n");
        printf ("\tcflg = (newv & 0x3F0) > 0x90;\n");
        printf ("\tif (cflg) newv += 0x60;\n");
-       printf ("\tSET_CFLG (cflg);\n");
+       printf ("\tSET_CFLG (&regs->ccrflags, cflg);\n");
        duplicate_carry (0);
        genflags (flag_zn, curi->size, "newv", "", "");
-       printf ("\tSET_VFLG ((tmp_newv & 0x80) == 0 && (newv & 0x80) != 0);\n");
+       printf ("\tSET_VFLG (&regs->ccrflags, (tmp_newv & 0x80) == 0 && (newv & 0x80) != 0);\n");
        addcycles (2);
        genastore ("newv", curi->dmode, "dstreg", curi->size, "dst");
        break;
@@ -1326,7 +1326,7 @@ static void gen_opcode (unsigned long int opcode)
                addcycles (2);
        fill_prefetch_next ();
        start_brace ();
-       printf ("\tuae_u32 newv = 0 - src - (GET_XFLG ? 1 : 0);\n");
+       printf ("\tuae_u32 newv = 0 - src - (GET_XFLG (&regs->ccrflags) ? 1 : 0);\n");
        genflags (flag_subx, curi->size, "newv", "src", "0");
        genflags (flag_zn, curi->size, "newv", "", "");
        genastore_rev ("newv", curi->smode, "srcreg", curi->size, "src");
@@ -1337,7 +1337,7 @@ static void gen_opcode (unsigned long int opcode)
                addcycles (2);
        fill_prefetch_next ();
        start_brace ();
-       printf ("\tuae_u16 newv_lo = - (src & 0xF) - (GET_XFLG ? 1 : 0);\n");
+       printf ("\tuae_u16 newv_lo = - (src & 0xF) - (GET_XFLG (&regs->ccrflags) ? 1 : 0);\n");
        printf ("\tuae_u16 newv_hi = - (src & 0xF0);\n");
        printf ("\tuae_u16 newv;\n");
        printf ("\tint cflg;\n");
@@ -1345,7 +1345,7 @@ static void gen_opcode (unsigned long int opcode)
        printf ("\tnewv = newv_hi + newv_lo;");
        printf ("\tcflg = (newv & 0x1F0) > 0x90;\n");
        printf ("\tif (cflg) newv -= 0x60;\n");
-       printf ("\tSET_CFLG (cflg);\n");
+       printf ("\tSET_CFLG (&regs->ccrflags, cflg);\n");
        duplicate_carry(0);
        genflags (flag_zn, curi->size, "newv", "", "");
        genastore ("newv", curi->smode, "srcreg", curi->size, "src");
@@ -1383,7 +1383,7 @@ static void gen_opcode (unsigned long int opcode)
            printf ("\tsrc &= 7;\n");
        else
            printf ("\tsrc &= 31;\n");
-       printf ("\tSET_ZFLG (1 ^ ((dst >> src) & 1));\n");
+       printf ("\tSET_ZFLG (&regs->ccrflags, 1 ^ ((dst >> src) & 1));\n");
        break;
     case i_BCHG:
        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0);
@@ -1396,7 +1396,7 @@ static void gen_opcode (unsigned long int opcode)
        else
            printf ("\tsrc &= 31;\n");
        printf ("\tdst ^= (1 << src);\n");
-       printf ("\tSET_ZFLG (((uae_u32)dst & (1 << src)) >> src);\n");
+       printf ("\tSET_ZFLG (&regs->ccrflags, ((uae_u32)dst & (1 << src)) >> src);\n");
        genastore ("dst", curi->dmode, "dstreg", curi->size, "dst");
        break;
     case i_BCLR:
@@ -1409,7 +1409,7 @@ static void gen_opcode (unsigned long int opcode)
            printf ("\tsrc &= 7;\n");
        else
            printf ("\tsrc &= 31;\n");
-       printf ("\tSET_ZFLG (1 ^ ((dst >> src) & 1));\n");
+       printf ("\tSET_ZFLG (&regs->ccrflags, 1 ^ ((dst >> src) & 1));\n");
        printf ("\tdst &= ~(1 << src);\n");
        genastore ("dst", curi->dmode, "dstreg", curi->size, "dst");
        break;
@@ -1423,7 +1423,7 @@ static void gen_opcode (unsigned long int opcode)
            printf ("\tsrc &= 7;\n");
        else
            printf ("\tsrc &= 31;\n");
-       printf ("\tSET_ZFLG (1 ^ ((dst >> src) & 1));\n");
+       printf ("\tSET_ZFLG (&regs->ccrflags, 1 ^ ((dst >> src) & 1));\n");
        printf ("\tdst |= (1 << src);\n");
        genastore ("dst", curi->dmode, "dstreg", curi->size, "dst");
        break;
@@ -1535,23 +1535,23 @@ static void gen_opcode (unsigned long int opcode)
        if (isreg (curi->smode))
            addcycles (2);
        fill_prefetch_next ();
-       printf ("\tMakeSR();\n");
+       printf ("\tMakeSR(regs);\n");
        if (curi->size == sz_byte)
-           genastore ("regs.sr & 0xff", curi->smode, "srcreg", sz_word, "src");
+           genastore ("regs->sr & 0xff", curi->smode, "srcreg", sz_word, "src");
        else
-           genastore ("regs.sr", curi->smode, "srcreg", sz_word, "src");
+           genastore ("regs->sr", curi->smode, "srcreg", sz_word, "src");
        break;
     case i_MV2SR:
        genamode (curi->smode, "srcreg", sz_word, "src", 1, 0, 0);
        if (curi->size == sz_byte) {
            addcycles (8);
-           printf ("\tMakeSR();\n\tregs.sr &= 0xFF00;\n\tregs.sr |= src & 0xFF;\n");
+           printf ("\tMakeSR(regs);\n\tregs->sr &= 0xFF00;\n\tregs->sr |= src & 0xFF;\n");
        } else {
            addcycles (4);
-           printf ("\tregs.sr = src;\n");
+           printf ("\tregs->sr = src;\n");
        }
        fill_prefetch_next ();
-       printf ("\tMakeFromSR();\n");
+       printf ("\tMakeFromSR(regs);\n");
        break;
     case i_SWAP:
        genamode (curi->smode, "srcreg", sz_long, "src", 1, 0, 0);
@@ -1601,25 +1601,25 @@ static void gen_opcode (unsigned long int opcode)
     case i_TRAP:
        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0);
        sync_m68k_pc ();
-       printf ("\tException (src + 32,0);\n");
+       printf ("\tException (src + 32, regs, 0);\n");
        did_prefetch = 1;
        m68k_pc_offset = 0;
        break;
     case i_MVR2USP:
        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0);
        fill_prefetch_next ();
-       printf ("\tregs.usp = src;\n");
+       printf ("\tregs->usp = src;\n");
        break;
     case i_MVUSP2R:
        genamode (curi->smode, "srcreg", curi->size, "src", 2, 0, 0);
        fill_prefetch_next ();
-       genastore ("regs.usp", curi->smode, "srcreg", curi->size, "src");
+       genastore ("regs->usp", curi->smode, "srcreg", curi->size, "src");
        break;
     case i_RESET:
        fill_prefetch_next ();
        printf ("\tcpureset();\n");
        if (using_prefetch)
-           printf ("\tregs.irc = get_iword(4);\n");
+           printf ("\tregs->irc = get_iword(regs, 4);\n");
        break;
     case i_NOP:
        fill_prefetch_next ();
@@ -1627,9 +1627,9 @@ static void gen_opcode (unsigned long int opcode)
     case i_STOP:
        /* real stop do not prefetch anything, later... */
        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0);
-       printf ("\tregs.sr = src;\n");
-       printf ("\tMakeFromSR();\n");
-       printf ("\tm68k_setstopped(1);\n");
+       printf ("\tregs->sr = src;\n");
+       printf ("\tMakeFromSR(regs);\n");
+       printf ("\tm68k_setstopped(regs, 1);\n");
        sync_m68k_pc ();
        fill_prefetch_full ();
        break;
@@ -1637,8 +1637,8 @@ static void gen_opcode (unsigned long int opcode)
        if (cpu_level == 0) {
            genamode (Aipi, "7", sz_word, "sr", 1, 0, GF_NOREFILL);
            genamode (Aipi, "7", sz_long, "pc", 1, 0, GF_NOREFILL);
-           printf ("\tregs.sr = sr; m68k_setpc_rte(pc);\n");
-           printf ("\tMakeFromSR();\n");
+           printf ("\tregs->sr = sr; m68k_setpc(regs, pc);\n");
+           printf ("\tMakeFromSR(regs);\n");
        } else {
            int old_brace_level = n_braces;
            if (next_cpu_level < 0)
@@ -1656,14 +1656,14 @@ static void gen_opcode (unsigned long int opcode)
            printf ("\telse if ((format & 0xF000) == 0x9000) { m68k_areg(regs, 7) += 12; break; }\n");
            printf ("\telse if ((format & 0xF000) == 0xa000) { m68k_areg(regs, 7) += 24; break; }\n");
            printf ("\telse if ((format & 0xF000) == 0xb000) { m68k_areg(regs, 7) += 84; break; }\n");
-           printf ("\telse { Exception(14,0); goto %s; }\n", endlabelstr);
-           printf ("\tregs.sr = newsr; MakeFromSR();\n}\n");
+           printf ("\telse { Exception(14, regs, 0); goto %s; }\n", endlabelstr);
+           printf ("\tregs->sr = newsr; MakeFromSR(regs);\n}\n");
            pop_braces (old_brace_level);
-           printf ("\tregs.sr = newsr; MakeFromSR();\n");
+           printf ("\tregs->sr = newsr; MakeFromSR(regs);\n");
            printf ("\tif (newpc & 1)\n");
-           printf ("\t\texception3 (0x%04.4X, m68k_getpc(), newpc);\n", opcode);
+           printf ("\t\texception3 (0x%04.4X, m68k_getpc(regs), newpc);\n", opcode);
            printf ("\telse\n");
-           printf ("\t\tm68k_setpc_rte(newpc);\n");
+           printf ("\t\tm68k_setpc(regs, newpc);\n");
            need_endlabel = 1;
        }
        /* PC is set and prefetch filled. */
@@ -1675,9 +1675,9 @@ static void gen_opcode (unsigned long int opcode)
        genamode (curi->smode, "srcreg", curi->size, "offs", 1, 0, 0);
        printf ("\tm68k_areg(regs, 7) += offs;\n");
        printf ("\tif (pc & 1)\n");
-       printf ("\t\texception3 (0x%04.4X, m68k_getpc(), pc);\n", opcode);
+       printf ("\t\texception3 (0x%04.4X, m68k_getpc(regs), pc);\n", opcode);
        printf ("\telse\n");
-       printf ("\t\tm68k_setpc_rte(pc);\n");
+       printf ("\t\tm68k_setpc(regs, pc);\n");
        /* PC is set and prefetch filled. */
        m68k_pc_offset = 0;
        fill_prefetch_full ();
@@ -1700,35 +1700,35 @@ static void gen_opcode (unsigned long int opcode)
        break;
     case i_RTS:
        if (using_ce)
-           printf ("\tm68k_do_rts_ce();\n");
+           printf ("\tm68k_do_rts_ce(regs);\n");
        else
-           printf ("\tm68k_do_rts();\n");
+           printf ("\tm68k_do_rts(regs);\n");
        m68k_pc_offset = 0;
        fill_prefetch_full ();
        break;
     case i_TRAPV:
        sync_m68k_pc ();
-       printf ("\tif (GET_VFLG) {\n");
-       printf ("\t\tException (7, m68k_getpc ());\n");
+       printf ("\tif (GET_VFLG (&regs->ccrflags)) {\n");
+       printf ("\t\tException (7, regs, m68k_getpc (regs));\n");
        printf ("\t\tgoto %s;\n", endlabelstr);
        printf ("\t}\n");
        fill_prefetch_next ();
        need_endlabel = 1;
        break;
     case i_RTR:
-       printf ("\tMakeSR();\n");
+       printf ("\tMakeSR(regs);\n");
        genamode (Aipi, "7", sz_word, "sr", 1, 0, 0);
        genamode (Aipi, "7", sz_long, "pc", 1, 0, 0);
-       printf ("\tregs.sr &= 0xFF00; sr &= 0xFF;\n");
-       printf ("\tregs.sr |= sr; m68k_setpc(pc);\n");
-       printf ("\tMakeFromSR();\n");
+       printf ("\tregs->sr &= 0xFF00; sr &= 0xFF;\n");
+       printf ("\tregs->sr |= sr; m68k_setpc(regs, pc);\n");
+       printf ("\tMakeFromSR(regs);\n");
        m68k_pc_offset = 0;
        fill_prefetch_full ();
        break;
     case i_JSR:
        genamode (curi->smode, "srcreg", curi->size, "src", 0, 0, GF_AA|GF_NOREFILL);
        start_brace ();
-       printf ("\tuaecptr oldpc = m68k_getpc() + %d;\n", m68k_pc_offset);
+       printf ("\tuaecptr oldpc = m68k_getpc(regs) + %d;\n", m68k_pc_offset);
        if (using_exception_3) {
            printf ("\tif (srca & 1) {\n");
            printf ("\t\texception3i (opcode, oldpc, srca);\n");
@@ -1736,7 +1736,7 @@ static void gen_opcode (unsigned long int opcode)
            printf ("\t}\n");
            need_endlabel = 1;
        }
-       printf ("\tm68k_setpc (srca);\n");
+       printf ("\tm68k_setpc (regs, srca);\n");
        m68k_pc_offset = 0;
        fill_prefetch_1 (0);
        printf("\tm68k_areg (regs, 7) -= 4;\n");
@@ -1752,14 +1752,14 @@ static void gen_opcode (unsigned long int opcode)
        genamode (curi->smode, "srcreg", curi->size, "src", 0, 0, GF_AA|GF_NOREFILL);
        if (using_exception_3) {
            printf ("\tif (srca & 1) {\n");
-           printf ("\t\texception3i (opcode, m68k_getpc() + 6, srca);\n");
+           printf ("\t\texception3i (opcode, m68k_getpc(regs) + 6, srca);\n");
            printf ("\t\tgoto %s;\n", endlabelstr);
            printf ("\t}\n");
            need_endlabel = 1;
        }
        if (curi->smode == Ad16 || curi->smode == Ad8r || curi->smode == absw || curi->smode == PC16 || curi->smode == PC8r)
            addcycles (2);
-       printf ("\tm68k_setpc(srca);\n");
+       printf ("\tm68k_setpc(regs, srca);\n");
        m68k_pc_offset = 0;
        fill_prefetch_full ();
     break;
@@ -1769,16 +1769,16 @@ static void gen_opcode (unsigned long int opcode)
        printf ("\ts = (uae_s32)src + 2;\n");
        if (using_exception_3) {
            printf ("\tif (src & 1) {\n");
-           printf ("\t\texception3i (opcode, m68k_getpc() + 2, m68k_getpc() + s);\n");
+           printf ("\t\texception3i (opcode, m68k_getpc(regs) + 2, m68k_getpc(regs) + s);\n");
            printf ("\t\tgoto %s;\n", endlabelstr);
            printf ("\t}\n");
            need_endlabel = 1;
        }
        addcycles (2);
        if (using_ce)
-           printf ("\tm68k_do_bsr_ce (m68k_getpc() + %d, s);\n", m68k_pc_offset);
+           printf ("\tm68k_do_bsr_ce (regs, m68k_getpc(regs) + %d, s);\n", m68k_pc_offset);
        else
-           printf ("\tm68k_do_bsr (m68k_getpc() + %d, s);\n", m68k_pc_offset);
+           printf ("\tm68k_do_bsr (regs, m68k_getpc(regs) + %d, s);\n", m68k_pc_offset);
        m68k_pc_offset = 0;
        fill_prefetch_full ();
        break;
@@ -1786,8 +1786,8 @@ static void gen_opcode (unsigned long int opcode)
        if (curi->size == sz_long) {
            if (cpu_level < 2) {
                addcycles (2);
-               printf ("\tif (cctrue(%d)) {\n", curi->cc, endlabelstr);
-               printf ("\t\texception3i (opcode, m68k_getpc() + 2, m68k_getpc() + 1);\n");
+               printf ("\tif (cctrue(&regs->ccrflags, %d)) {\n", curi->cc, endlabelstr);
+               printf ("\t\texception3i (opcode, m68k_getpc(regs) + 2, m68k_getpc(regs) + 1);\n");
                printf ("\t\tgoto %s;\n", endlabelstr);
                printf ("\t}\n");
                sync_m68k_pc ();
@@ -1802,19 +1802,19 @@ static void gen_opcode (unsigned long int opcode)
        }
        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, GF_AA | GF_NOREFILL);
        addcycles (2);
-       printf ("\tif (!cctrue(%d)) goto didnt_jump;\n", curi->cc);
+       printf ("\tif (!cctrue(&regs->ccrflags, %d)) goto didnt_jump;\n", curi->cc);
        if (using_exception_3) {
            printf ("\tif (src & 1) {\n");
-           printf ("\t\texception3i (opcode, m68k_getpc() + 2, m68k_getpc() + 2 + (uae_s32)src);\n");
+           printf ("\t\texception3i (opcode, m68k_getpc(regs) + 2, m68k_getpc(regs) + 2 + (uae_s32)src);\n");
            printf ("\t\tgoto %s;\n", endlabelstr);
            printf ("\t}\n");
            need_endlabel = 1;
        }
        if (using_prefetch) {
            if (curi->size == sz_byte) {
-               printf ("\tm68k_incpc ((uae_s32)src + 2);\n");
+               printf ("\tm68k_incpc (regs, (uae_s32)src + 2);\n");
            } else {
-               printf ("\tm68k_incpc ((uae_s32)src + 2);\n");
+               printf ("\tm68k_incpc (regs, (uae_s32)src + 2);\n");
            }
            fill_prefetch_full ();
            if (using_ce)
@@ -1822,7 +1822,7 @@ static void gen_opcode (unsigned long int opcode)
            else
                printf ("\treturn 10 * %d;\n", CYCLE_UNIT / 2);
        } else {
-           printf ("\tm68k_incpc ((uae_s32)src + 2);\n");
+           printf ("\tm68k_incpc (regs, (uae_s32)src + 2);\n");
            returncycles ("\t", 10);
        }
        printf ("didnt_jump:;\n");
@@ -1859,17 +1859,17 @@ static void gen_opcode (unsigned long int opcode)
        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, GF_AA | GF_NOREFILL);
        genamode (curi->dmode, "dstreg", curi->size, "offs", 1, 0, GF_AA | GF_NOREFILL);
 
-       printf ("\tuaecptr oldpc = m68k_getpc();\n");
+       printf ("\tuaecptr oldpc = m68k_getpc(regs);\n");
        addcycles (2);
-       printf ("\tif (!cctrue(%d)) {\n", curi->cc);
-       printf ("\t\tm68k_incpc((uae_s32)offs + 2);\n");
+       printf ("\tif (!cctrue(&regs->ccrflags, %d)) {\n", curi->cc);
+       printf ("\t\tm68k_incpc(regs, (uae_s32)offs + 2);\n");
        printf ("\t"); fill_prefetch_1 (0);
        printf ("\t"); genastore ("(src-1)", curi->smode, "srcreg", curi->size, "src");
 
        printf ("\t\tif (src) {\n");
        if (using_exception_3) {
            printf ("\t\t\tif (offs & 1) {\n");
-           printf ("\t\t\t\texception3i (opcode, m68k_getpc() + 2, m68k_getpc() + 2 + (uae_s32)offs + 2);\n");
+           printf ("\t\t\t\texception3i (opcode, m68k_getpc(regs) + 2, m68k_getpc(regs) + 2 + (uae_s32)offs + 2);\n");
            printf ("\t\t\t\tgoto %s;\n", endlabelstr);
            printf ("\t\t\t}\n");
            need_endlabel = 1;
@@ -1883,7 +1883,7 @@ static void gen_opcode (unsigned long int opcode)
        printf ("\t} else {\n");
        addcycles2 ("\t\t", 2);
        printf ("\t}\n");
-       printf ("\tm68k_setpc (oldpc + %d);\n", m68k_pc_offset);
+       printf ("\tm68k_setpc (regs, oldpc + %d);\n", m68k_pc_offset);
        m68k_pc_offset = 0;
        fill_prefetch_full ();
        insn_n_cycles = 12;
@@ -1894,7 +1894,7 @@ static void gen_opcode (unsigned long int opcode)
        start_brace ();
        fill_prefetch_next();
        start_brace ();
-       printf ("\tint val = cctrue(%d) ? 0xff : 0;\n", curi->cc);
+       printf ("\tint val = cctrue(&regs->ccrflags, %d) ? 0xff : 0;\n", curi->cc);
        if (using_ce) {
            printf ("\tint cycles = 0;\n");
            if (isreg (curi->smode))
@@ -1904,20 +1904,20 @@ static void gen_opcode (unsigned long int opcode)
        genastore ("val", curi->smode, "srcreg", curi->size, "src");
        break;
     case i_DIVU:
-       printf ("\tuaecptr oldpc = m68k_getpc();\n");
+       printf ("\tuaecptr oldpc = m68k_getpc(regs);\n");
        genamode (curi->smode, "srcreg", sz_word, "src", 1, 0, 0);
        genamode (curi->dmode, "dstreg", sz_long, "dst", 1, 0, 0);
-       printf ("\tCLEAR_CZNV;\n");
+       printf ("\tCLEAR_CZNV (&regs->ccrflags);\n");
        printf ("\tif (src == 0) {\n");
        if (cpu_level > 0) {
            /* 68020 sets V when dividing by zero and N if dst is negative
             * 68000 clears both
             */
-           printf("\t\tSET_VFLG (1);\n");
-           printf("\t\tif (dst < 0) SET_NFLG (1);\n");
+           printf("\t\tSET_VFLG (&regs->ccrflags, 1);\n");
+           printf("\t\tif (dst < 0) SET_NFLG (&regs->ccrflags, 1);\n");
        }
-       printf ("\t\tm68k_incpc (%d);\n", m68k_pc_offset);
-       printf ("\t\tException (5, oldpc);\n");
+       printf ("\t\tm68k_incpc (regs, %d);\n", m68k_pc_offset);
+       printf ("\t\tException (5, regs, oldpc);\n");
        printf ("\t\tgoto %s;\n", endlabelstr);
        printf ("\t} else {\n");
        printf ("\t\tuae_u32 newv = (uae_u32)dst / (uae_u32)(uae_u16)src;\n");
@@ -1929,13 +1929,13 @@ static void gen_opcode (unsigned long int opcode)
        /* The N flag appears to be set each time there is an overflow.
         * Weird. but 68020 only sets N when dst is negative.. */
        printf ("\t\tif (newv > 0xffff) {\n");
-       printf ("\t\t\tSET_VFLG (1);\n");
+       printf ("\t\t\tSET_VFLG (&regs->ccrflags, 1);\n");
 #ifdef UNDEF68020
        if (cpu_level >= 2)
            printf ("\t\t\tif (currprefs.cpu_level == 0 || dst < 0) SET_NFLG (1);\n");
        else /* ??? some 68000 revisions may not set NFLG when overflow happens.. */
 #endif
-           printf ("\t\t\tSET_NFLG (1);\n");
+           printf ("\t\t\tSET_NFLG (&regs->ccrflags, 1);\n");
        printf ("\t\t} else {\n");
        printf ("\t\t"); genflags (flag_logical, sz_word, "newv", "", "");
        printf ("\t\t\tnewv = (newv & 0xffff) | ((uae_u32)rem << 16);\n");
@@ -1948,20 +1948,20 @@ static void gen_opcode (unsigned long int opcode)
        need_endlabel = 1;
        break;
     case i_DIVS:
-       printf ("\tuaecptr oldpc = m68k_getpc();\n");
+       printf ("\tuaecptr oldpc = m68k_getpc(regs);\n");
        genamode (curi->smode, "srcreg", sz_word, "src", 1, 0, 0);
        genamode (curi->dmode, "dstreg", sz_long, "dst", 1, 0, 0);
-       printf ("\tCLEAR_CZNV;\n");
+       printf ("\tCLEAR_CZNV (&regs->ccrflags);\n");
        printf ("\tif (src == 0) {\n");
        if (cpu_level > 0) {
            /* 68020 sets V when dividing by zero. Z is also set.
             * 68000 clears both
             */
-           printf("\t\tSET_VFLG (1);\n");
-           printf("\t\tSET_ZFLG (1);\n");
+           printf("\t\tSET_VFLG (&regs->ccrflags, 1);\n");
+           printf("\t\tSET_ZFLG (&regs->ccrflags, 1);\n");
        }
-       printf ("\t\tm68k_incpc (%d);\n", m68k_pc_offset);
-       printf ("\t\tException (5, oldpc);\n");
+       printf ("\t\tm68k_incpc (regs, %d);\n", m68k_pc_offset);
+       printf ("\t\tException (5, regs, oldpc);\n");
        printf ("\t\tgoto %s;\n", endlabelstr);
        printf ("\t} else {\n");
        printf ("\t\tuae_s32 newv = (uae_s32)dst / (uae_s32)(uae_s16)src;\n");
@@ -1971,13 +1971,13 @@ static void gen_opcode (unsigned long int opcode)
            addcycles3 ("\t\t");
        }
        printf ("\t\tif ((newv & 0xffff8000) != 0 && (newv & 0xffff8000) != 0xffff8000) {\n");
-       printf ("\t\t\tSET_VFLG (1);\n");
+       printf ("\t\t\tSET_VFLG (&regs->ccrflags, 1);\n");
 #ifdef UNDEF68020
        if (cpu_level > 0)
            printf ("\t\t\tif (currprefs.cpu_level == 0) SET_NFLG (1);\n");
        else
 #endif
-           printf ("\t\t\tSET_NFLG (1);\n");
+           printf ("\t\t\tSET_NFLG (&regs->ccrflags, 1);\n");
        printf ("\t\t} else {\n");
        printf ("\t\t\tif (((uae_s16)rem < 0) != ((uae_s32)dst < 0)) rem = -rem;\n");
        genflags (flag_logical, sz_word, "newv", "", "");
@@ -2029,47 +2029,47 @@ static void gen_opcode (unsigned long int opcode)
        insn_n_cycles += (70 - 38) / 2 + 38; /* average */
        break;
     case i_CHK:
-       printf ("\tuaecptr oldpc = m68k_getpc();\n");
+       printf ("\tuaecptr oldpc = m68k_getpc(regs);\n");
        genamode (curi->smode, "srcreg", curi->size, "src", 1, 0, 0);
        genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0, 0);
        sync_m68k_pc ();
        addcycles (6);
        fill_prefetch_next ();
        printf ("\tif ((uae_s32)dst < 0) {\n");
-       printf ("\t\tSET_NFLG (1);\n");
-       printf ("\t\tException (6, oldpc);\n");
+       printf ("\t\tSET_NFLG (&regs->ccrflags, 1);\n");
+       printf ("\t\tException (6, regs, oldpc);\n");
        printf ("\t\tgoto %s;\n", endlabelstr);
        printf ("\t} else if (dst > src) {\n");
-       printf ("\t\tSET_NFLG (0);\n");
-       printf ("\t\tException (6, oldpc);\n");
+       printf ("\t\tSET_NFLG (&regs->ccrflags, 0);\n");
+       printf ("\t\tException (6, regs, oldpc);\n");
        printf ("\t\tgoto %s;\n", endlabelstr);
        printf ("\t}\n");
        need_endlabel = 1;
        break;
     case i_CHK2:
-       printf ("\tuaecptr oldpc = m68k_getpc();\n");
+       printf ("\tuaecptr oldpc = m68k_getpc(regs);\n");
        genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0, 0);
        genamode (curi->dmode, "dstreg", curi->size, "dst", 2, 0, 0);
        fill_prefetch_0 ();
-       printf ("\t{uae_s32 upper,lower,reg = regs.regs[(extra >> 12) & 15];\n");
+       printf ("\t{uae_s32 upper,lower,reg = regs->regs[(extra >> 12) & 15];\n");
        switch (curi->size) {
        case sz_byte:
-           printf ("\tlower=(uae_s32)(uae_s8)get_byte(dsta); upper = (uae_s32)(uae_s8)get_byte(dsta+1);\n");
+           printf ("\tlower = (uae_s32)(uae_s8)get_byte(dsta); upper = (uae_s32)(uae_s8)get_byte(dsta+1);\n");
            printf ("\tif ((extra & 0x8000) == 0) reg = (uae_s32)(uae_s8)reg;\n");
            break;
        case sz_word:
-           printf ("\tlower=(uae_s32)(uae_s16)get_word(dsta); upper = (uae_s32)(uae_s16)get_word(dsta+2);\n");
+           printf ("\tlower = (uae_s32)(uae_s16)get_word(dsta); upper = (uae_s32)(uae_s16)get_word(dsta+2);\n");
            printf ("\tif ((extra & 0x8000) == 0) reg = (uae_s32)(uae_s16)reg;\n");
            break;
        case sz_long:
-           printf ("\tlower=get_long(dsta); upper = get_long(dsta+4);\n");
+           printf ("\tlower = get_long(dsta); upper = get_long(dsta+4);\n");
            break;
        default:
            abort ();
        }
-       printf ("\tSET_ZFLG (upper == reg || lower == reg);\n");
-       printf ("\tSET_CFLG_ALWAYS (lower <= upper ? reg < lower || reg > upper : reg > upper || reg < lower);\n");
-       printf ("\tif ((extra & 0x800) && GET_CFLG) { Exception(6,oldpc); goto %s; }\n}\n", endlabelstr);
+       printf ("\tSET_ZFLG (&regs->ccrflags, upper == reg || lower == reg);\n");
+       printf ("\tSET_CFLG_ALWAYS (&regs->ccrflags, lower <= upper ? reg < lower || reg > upper : reg > upper || reg < lower);\n");
+       printf ("\tif ((extra & 0x800) && GET_CFLG (&regs->ccrflags)) { Exception(6, regs, oldpc); goto %s; }\n}\n", endlabelstr);
        need_endlabel = 1;
        break;
 
@@ -2087,17 +2087,17 @@ static void gen_opcode (unsigned long int opcode)
        printf ("\tuae_u32 sign = (%s & val) >> %d;\n", cmask (curi->size), bit_size (curi->size) - 1);
        printf ("\tint ccnt = cnt & 63;\n");
        printf ("\tcnt &= 63;\n");
-       printf ("\tCLEAR_CZNV;\n");
+       printf ("\tCLEAR_CZNV (&regs->ccrflags);\n");
        printf ("\tif (cnt >= %d) {\n", bit_size (curi->size));
        printf ("\t\tval = %s & (uae_u32)-sign;\n", bit_mask (curi->size));
-       printf ("\t\tSET_CFLG (sign);\n");
+       printf ("\t\tSET_CFLG (&regs->ccrflags, sign);\n");
        duplicate_carry (1);
        if (source_is_imm1_8 (curi))
            printf ("\t} else {\n");
        else
            printf ("\t} else if (cnt > 0) {\n");
        printf ("\t\tval >>= cnt - 1;\n");
-       printf ("\t\tSET_CFLG (val & 1);\n");
+       printf ("\t\tSET_CFLG (&regs->ccrflags, val & 1);\n");
        duplicate_carry (1);
        printf ("\t\tval >>= 1;\n");
        printf ("\t\tval |= (%s << (%d - cnt)) & (uae_u32)-sign;\n",
@@ -2122,10 +2122,10 @@ static void gen_opcode (unsigned long int opcode)
        }
        printf ("\tint ccnt = cnt & 63;\n");
        printf ("\tcnt &= 63;\n");
-       printf ("\tCLEAR_CZNV;\n");
+       printf ("\tCLEAR_CZNV (&regs->ccrflags);\n");
        printf ("\tif (cnt >= %d) {\n", bit_size (curi->size));
-       printf ("\t\tSET_VFLG (val != 0);\n");
-       printf ("\t\tSET_CFLG (cnt == %d ? val & 1 : 0);\n",
+       printf ("\t\tSET_VFLG (&regs->ccrflags, val != 0);\n");
+       printf ("\t\tSET_CFLG (&regs->ccrflags, cnt == %d ? val & 1 : 0);\n",
                bit_size (curi->size));
        duplicate_carry (1);
        printf ("\t\tval = 0;\n");
@@ -2137,9 +2137,9 @@ static void gen_opcode (unsigned long int opcode)
                bit_mask (curi->size),
                bit_size (curi->size) - 1,
                bit_mask (curi->size));
-       printf ("\t\tSET_VFLG ((val & mask) != mask && (val & mask) != 0);\n");
+       printf ("\t\tSET_VFLG (&regs->ccrflags, (val & mask) != mask && (val & mask) != 0);\n");
        printf ("\t\tval <<= cnt - 1;\n");
-       printf ("\t\tSET_CFLG ((val & %s) >> %d);\n", cmask (curi->size), bit_size (curi->size) - 1);
+       printf ("\t\tSET_CFLG (&regs->ccrflags, (val & %s) >> %d);\n", cmask (curi->size), bit_size (curi->size) - 1);
        duplicate_carry (1);
        printf ("\t\tval <<= 1;\n");
        printf ("\t\tval &= %s;\n", bit_mask (curi->size));
@@ -2161,9 +2161,9 @@ static void gen_opcode (unsigned long int opcode)
        }
        printf ("\tint ccnt = cnt & 63;\n");
        printf ("\tcnt &= 63;\n");
-       printf ("\tCLEAR_CZNV;\n");
+       printf ("\tCLEAR_CZNV (&regs->ccrflags);\n");
        printf ("\tif (cnt >= %d) {\n", bit_size (curi->size));
-       printf ("\t\tSET_CFLG ((cnt == %d) & (val >> %d));\n",
+       printf ("\t\tSET_CFLG (&regs->ccrflags, (cnt == %d) & (val >> %d));\n",
                bit_size (curi->size), bit_size (curi->size) - 1);
        duplicate_carry (1);
        printf ("\t\tval = 0;\n");
@@ -2172,7 +2172,7 @@ static void gen_opcode (unsigned long int opcode)
        else
            printf ("\t} else if (cnt > 0) {\n");
        printf ("\t\tval >>= cnt - 1;\n");
-       printf ("\t\tSET_CFLG (val & 1);\n");
+       printf ("\t\tSET_CFLG (&regs->ccrflags, val & 1);\n");
        duplicate_carry (1);
        printf ("\t\tval >>= 1;\n");
        printf ("\t}\n");
@@ -2193,9 +2193,9 @@ static void gen_opcode (unsigned long int opcode)
        }
        printf ("\tint ccnt = cnt & 63;\n");
        printf ("\tcnt &= 63;\n");
-       printf ("\tCLEAR_CZNV;\n");
+       printf ("\tCLEAR_CZNV (&regs->ccrflags);\n");
        printf ("\tif (cnt >= %d) {\n", bit_size (curi->size));
-       printf ("\t\tSET_CFLG (cnt == %d ? val & 1 : 0);\n",
+       printf ("\t\tSET_CFLG (&regs->ccrflags, cnt == %d ? val & 1 : 0);\n",
                bit_size (curi->size));
        duplicate_carry (1);
        printf ("\t\tval = 0;\n");
@@ -2204,7 +2204,7 @@ static void gen_opcode (unsigned long int opcode)
        else
            printf ("\t} else if (cnt > 0) {\n");
        printf ("\t\tval <<= (cnt - 1);\n");
-       printf ("\t\tSET_CFLG ((val & %s) >> %d);\n", cmask (curi->size), bit_size (curi->size) - 1);
+       printf ("\t\tSET_CFLG (&regs->ccrflags, (val & %s) >> %d);\n", cmask (curi->size), bit_size (curi->size) - 1);
        duplicate_carry (1);
        printf ("\t\tval <<= 1;\n");
        printf ("\tval &= %s;\n", bit_mask (curi->size));
@@ -2226,7 +2226,7 @@ static void gen_opcode (unsigned long int opcode)
        }
        printf ("\tint ccnt = cnt & 63;\n");
        printf ("\tcnt &= 63;\n");
-       printf ("\tCLEAR_CZNV;\n");
+       printf ("\tCLEAR_CZNV (&regs->ccrflags);\n");
        if (source_is_imm1_8 (curi))
            printf ("{");
        else
@@ -2237,7 +2237,7 @@ static void gen_opcode (unsigned long int opcode)
        printf ("\tval <<= cnt;\n");
        printf ("\tval |= loval;\n");
        printf ("\tval &= %s;\n", bit_mask (curi->size));
-       printf ("\tSET_CFLG (val & 1);\n");
+       printf ("\tSET_CFLG (&regs->ccrflags, val & 1);\n");
        printf ("}\n");
        genflags (flag_logical_noclobber, curi->size, "val", "", "");
        shift_ce (curi->dmode, curi->size);
@@ -2256,7 +2256,7 @@ static void gen_opcode (unsigned long int opcode)
        }
        printf ("\tint ccnt = cnt & 63;\n");
        printf ("\tcnt &= 63;\n");
-       printf ("\tCLEAR_CZNV;\n");
+       printf ("\tCLEAR_CZNV (&regs->ccrflags);\n");
        if (source_is_imm1_8 (curi))
            printf ("{");
        else
@@ -2267,7 +2267,7 @@ static void gen_opcode (unsigned long int opcode)
        printf ("\tval >>= cnt;\n");
        printf ("\tval |= hival;\n");
        printf ("\tval &= %s;\n", bit_mask (curi->size));
-       printf ("\tSET_CFLG ((val & %s) >> %d);\n", cmask (curi->size), bit_size (curi->size) - 1);
+       printf ("\tSET_CFLG (&regs->ccrflags, (val & %s) >> %d);\n", cmask (curi->size), bit_size (curi->size) - 1);
        printf ("\t}\n");
        genflags (flag_logical_noclobber, curi->size, "val", "", "");
        shift_ce (curi->dmode, curi->size);
@@ -2286,7 +2286,7 @@ static void gen_opcode (unsigned long int opcode)
        }
        printf ("\tint ccnt = cnt & 63;\n");
        printf ("\tcnt &= 63;\n");
-       printf ("\tCLEAR_CZNV;\n");
+       printf ("\tCLEAR_CZNV (&regs->ccrflags);\n");
        if (source_is_imm1_8 (curi))
            printf ("{");
        else {
@@ -2297,11 +2297,11 @@ static void gen_opcode (unsigned long int opcode)
        printf ("\t{\n\tuae_u32 carry;\n");
        printf ("\tuae_u32 loval = val >> (%d - cnt);\n", bit_size (curi->size) - 1);
        printf ("\tcarry = loval & 1;\n");
-       printf ("\tval = (((val << 1) | GET_XFLG) << cnt) | (loval >> 1);\n");
-       printf ("\tSET_XFLG (carry);\n");
+       printf ("\tval = (((val << 1) | GET_XFLG (&regs->ccrflags)) << cnt) | (loval >> 1);\n");
+       printf ("\tSET_XFLG (&regs->ccrflags, carry);\n");
        printf ("\tval &= %s;\n", bit_mask (curi->size));
        printf ("\t} }\n");
-       printf ("\tSET_CFLG (GET_XFLG);\n");
+       printf ("\tSET_CFLG (&regs->ccrflags, GET_XFLG (&regs->ccrflags));\n");
        genflags (flag_logical_noclobber, curi->size, "val", "", "");
        shift_ce (curi->dmode, curi->size);
        genastore ("val", curi->dmode, "dstreg", curi->size, "data");
@@ -2319,7 +2319,7 @@ static void gen_opcode (unsigned long int opcode)
        }
        printf ("\tint ccnt = cnt & 63;\n");
        printf ("\tcnt &= 63;\n");
-       printf ("\tCLEAR_CZNV;\n");
+       printf ("\tCLEAR_CZNV (&regs->ccrflags);\n");
        if (source_is_imm1_8 (curi))
            printf ("{");
        else {
@@ -2328,16 +2328,16 @@ static void gen_opcode (unsigned long int opcode)
        }
        printf ("\tcnt--;\n");
        printf ("\t{\n\tuae_u32 carry;\n");
-       printf ("\tuae_u32 hival = (val << 1) | GET_XFLG;\n");
+       printf ("\tuae_u32 hival = (val << 1) | GET_XFLG (&regs->ccrflags);\n");
        printf ("\thival <<= (%d - cnt);\n", bit_size (curi->size) - 1);
        printf ("\tval >>= cnt;\n");
        printf ("\tcarry = val & 1;\n");
        printf ("\tval >>= 1;\n");
        printf ("\tval |= hival;\n");
-       printf ("\tSET_XFLG (carry);\n");
+       printf ("\tSET_XFLG (&regs->ccrflags, carry);\n");
        printf ("\tval &= %s;\n", bit_mask (curi->size));
        printf ("\t} }\n");
-       printf ("\tSET_CFLG (GET_XFLG);\n");
+       printf ("\tSET_CFLG (&regs->ccrflags, GET_XFLG (&regs->ccrflags));\n");
        genflags (flag_logical_noclobber, curi->size, "val", "", "");
        shift_ce (curi->dmode, curi->size);
        genastore ("val", curi->dmode, "dstreg", curi->size, "data");
@@ -2356,7 +2356,7 @@ static void gen_opcode (unsigned long int opcode)
        printf ("\tuae_u32 cflg = val & 1;\n");
        printf ("\tval = (val >> 1) | sign;\n");
        genflags (flag_logical, curi->size, "val", "", "");
-       printf ("\tSET_CFLG (cflg);\n");
+       printf ("\tSET_CFLG (&regs->ccrflags, cflg);\n");
        duplicate_carry (0);
        genastore ("val", curi->smode, "srcreg", curi->size, "data");
        break;
@@ -2375,10 +2375,10 @@ static void gen_opcode (unsigned long int opcode)
        printf ("\tval <<= 1;\n");
        genflags (flag_logical, curi->size, "val", "", "");
        printf ("\tsign2 = %s & val;\n", cmask (curi->size));
-       printf ("\tSET_CFLG (sign != 0);\n");
+       printf ("\tSET_CFLG (&regs->ccrflags, sign != 0);\n");
        duplicate_carry (0);
 
-       printf ("\tSET_VFLG (GET_VFLG | (sign2 != sign));\n");
+       printf ("\tSET_VFLG (&regs->ccrflags, GET_VFLG (&regs->ccrflags) | (sign2 != sign));\n");
        genastore ("val", curi->smode, "srcreg", curi->size, "data");
        break;
     case i_LSRW:
@@ -2394,7 +2394,7 @@ static void gen_opcode (unsigned long int opcode)
        printf ("\tuae_u32 carry = val & 1;\n");
        printf ("\tval >>= 1;\n");
        genflags (flag_logical, curi->size, "val", "", "");
-       printf ("SET_CFLG (carry);\n");
+       printf ("SET_CFLG (&regs->ccrflags, carry);\n");
        duplicate_carry (0);
        genastore ("val", curi->smode, "srcreg", curi->size, "data");
        break;
@@ -2411,7 +2411,7 @@ static void gen_opcode (unsigned long int opcode)
        printf ("\tuae_u32 carry = val & %s;\n", cmask (curi->size));
        printf ("\tval <<= 1;\n");
        genflags (flag_logical, curi->size, "val", "", "");
-       printf ("SET_CFLG (carry >> %d);\n", bit_size (curi->size) - 1);
+       printf ("SET_CFLG (&regs->ccrflags, carry >> %d);\n", bit_size (curi->size) - 1);
        duplicate_carry (0);
        genastore ("val", curi->smode, "srcreg", curi->size, "data");
        break;
@@ -2429,7 +2429,7 @@ static void gen_opcode (unsigned long int opcode)
        printf ("\tval <<= 1;\n");
        printf ("\tif (carry)  val |= 1;\n");
        genflags (flag_logical, curi->size, "val", "", "");
-       printf ("SET_CFLG (carry >> %d);\n", bit_size (curi->size) - 1);
+       printf ("SET_CFLG (&regs->ccrflags, carry >> %d);\n", bit_size (curi->size) - 1);
        genastore ("val", curi->smode, "srcreg", curi->size, "data");
        break;
     case i_RORW:
@@ -2446,7 +2446,7 @@ static void gen_opcode (unsigned long int opcode)
        printf ("\tval >>= 1;\n");
        printf ("\tif (carry) val |= %s;\n", cmask (curi->size));
        genflags (flag_logical, curi->size, "val", "", "");
-       printf ("SET_CFLG (carry);\n");
+       printf ("SET_CFLG (&regs->ccrflags, carry);\n");
        genastore ("val", curi->smode, "srcreg", curi->size, "data");
        break;
     case i_ROXLW:
@@ -2461,9 +2461,9 @@ static void gen_opcode (unsigned long int opcode)
        }
        printf ("\tuae_u32 carry = val & %s;\n", cmask (curi->size));
        printf ("\tval <<= 1;\n");
-       printf ("\tif (GET_XFLG) val |= 1;\n");
+       printf ("\tif (GET_XFLG (&regs->ccrflags)) val |= 1;\n");
        genflags (flag_logical, curi->size, "val", "", "");
-       printf ("SET_CFLG (carry >> %d);\n", bit_size (curi->size) - 1);
+       printf ("SET_CFLG (&regs->ccrflags, carry >> %d);\n", bit_size (curi->size) - 1);
        duplicate_carry (0);
        genastore ("val", curi->smode, "srcreg", curi->size, "data");
        break;
@@ -2479,9 +2479,9 @@ static void gen_opcode (unsigned long int opcode)
        }
        printf ("\tuae_u32 carry = val & 1;\n");
        printf ("\tval >>= 1;\n");
-       printf ("\tif (GET_XFLG) val |= %s;\n", cmask (curi->size));
+       printf ("\tif (GET_XFLG (&regs->ccrflags)) val |= %s;\n", cmask (curi->size));
        genflags (flag_logical, curi->size, "val", "", "");
-       printf ("SET_CFLG (carry);\n");
+       printf ("SET_CFLG (&regs->ccrflags, carry);\n");
        duplicate_carry (0);
        genastore ("val", curi->smode, "srcreg", curi->size, "data");
        break;
@@ -2490,7 +2490,7 @@ static void gen_opcode (unsigned long int opcode)
        fill_prefetch_next ();
        start_brace ();
        printf ("\tint regno = (src >> 12) & 15;\n");
-       printf ("\tuae_u32 *regp = regs.regs + regno;\n");
+       printf ("\tuae_u32 *regp = regs->regs + regno;\n");
        printf ("\tif (! m68k_movec2(src & 0xFFF, regp)) goto %s;\n", endlabelstr);
        break;
     case i_MOVE2C:
@@ -2498,7 +2498,7 @@ static void gen_opcode (unsigned long int opcode)
        fill_prefetch_next ();
        start_brace ();
        printf ("\tint regno = (src >> 12) & 15;\n");
-       printf ("\tuae_u32 *regp = regs.regs + regno;\n");
+       printf ("\tuae_u32 *regp = regs->regs + regno;\n");
        printf ("\tif (! m68k_move2c(src & 0xFFF, regp)) goto %s;\n", endlabelstr);
        break;
     case i_CAS:
@@ -2511,7 +2511,7 @@ static void gen_opcode (unsigned long int opcode)
        printf ("\tint ru = (src >> 6) & 7;\n");
        printf ("\tint rc = src & 7;\n");
        genflags (flag_cmp, curi->size, "newv", "m68k_dreg(regs, rc)", "dst");
-       printf ("\tif (GET_ZFLG)");
+       printf ("\tif (GET_ZFLG (&regs->ccrflags))");
        old_brace_level = n_braces;
        start_brace ();
        genastore ("(m68k_dreg(regs, ru))", curi->dmode, "dstreg", curi->size, "dst");
@@ -2524,20 +2524,20 @@ static void gen_opcode (unsigned long int opcode)
     break;
     case i_CAS2:
        genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0, 0);
-       printf ("\tuae_u32 rn1 = regs.regs[(extra >> 28) & 15];\n");
-       printf ("\tuae_u32 rn2 = regs.regs[(extra >> 12) & 15];\n");
+       printf ("\tuae_u32 rn1 = regs->regs[(extra >> 28) & 15];\n");
+       printf ("\tuae_u32 rn2 = regs->regs[(extra >> 12) & 15];\n");
        if (curi->size == sz_word) {
            int old_brace_level = n_braces;
            printf ("\tuae_u16 dst1 = get_word(rn1), dst2 = get_word(rn2);\n");
            genflags (flag_cmp, curi->size, "newv", "m68k_dreg(regs, (extra >> 16) & 7)", "dst1");
-           printf ("\tif (GET_ZFLG) {\n");
+           printf ("\tif (GET_ZFLG (&regs->ccrflags)) {\n");
            genflags (flag_cmp, curi->size, "newv", "m68k_dreg(regs, extra & 7)", "dst2");
-           printf ("\tif (GET_ZFLG) {\n");
+           printf ("\tif (GET_ZFLG (&regs->ccrflags)) {\n");
            printf ("\tput_word(rn1, m68k_dreg(regs, (extra >> 22) & 7));\n");
            printf ("\tput_word(rn1, m68k_dreg(regs, (extra >> 6) & 7));\n");
            printf ("\t}}\n");
            pop_braces (old_brace_level);
-           printf ("\tif (! GET_ZFLG) {\n");
+           printf ("\tif (! GET_ZFLG (&regs->ccrflags)) {\n");
            printf ("\tm68k_dreg(regs, (extra >> 22) & 7) = (m68k_dreg(regs, (extra >> 22) & 7) & ~0xffff) | (dst1 & 0xffff);\n");
            printf ("\tm68k_dreg(regs, (extra >> 6) & 7) = (m68k_dreg(regs, (extra >> 6) & 7) & ~0xffff) | (dst2 & 0xffff);\n");
            printf ("\t}\n");
@@ -2545,14 +2545,14 @@ static void gen_opcode (unsigned long int opcode)
            int old_brace_level = n_braces;
            printf ("\tuae_u32 dst1 = get_long(rn1), dst2 = get_long(rn2);\n");
            genflags (flag_cmp, curi->size, "newv", "m68k_dreg(regs, (extra >> 16) & 7)", "dst1");
-           printf ("\tif (GET_ZFLG) {\n");
+           printf ("\tif (GET_ZFLG (&regs->ccrflags)) {\n");
            genflags (flag_cmp, curi->size, "newv", "m68k_dreg(regs, extra & 7)", "dst2");
-           printf ("\tif (GET_ZFLG) {\n");
+           printf ("\tif (GET_ZFLG (&regs->ccrflags)) {\n");
            printf ("\tput_long(rn1, m68k_dreg(regs, (extra >> 22) & 7));\n");
            printf ("\tput_long(rn1, m68k_dreg(regs, (extra >> 6) & 7));\n");
            printf ("\t}}\n");
            pop_braces (old_brace_level);
-           printf ("\tif (! GET_ZFLG) {\n");
+           printf ("\tif (! GET_ZFLG (&regs->ccrflags)) {\n");
            printf ("\tm68k_dreg(regs, (extra >> 22) & 7) = dst1;\n");
            printf ("\tm68k_dreg(regs, (extra >> 6) & 7) = dst2;\n");
            printf ("\t}\n");
@@ -2565,7 +2565,7 @@ static void gen_opcode (unsigned long int opcode)
        printf ("\tif (extra & 0x800)\n");
        old_brace_level = n_braces;
        start_brace ();
-       printf ("\tuae_u32 src = regs.regs[(extra >> 12) & 15];\n");
+       printf ("\tuae_u32 src = regs->regs[(extra >> 12) & 15];\n");
        genamode (curi->dmode, "dstreg", curi->size, "dst", 2, 0, 0);
        genastore ("src", curi->dmode, "dstreg", curi->size, "dst");
        pop_braces (old_brace_level);
@@ -2587,27 +2587,27 @@ static void gen_opcode (unsigned long int opcode)
     break;
     case i_BKPT:               /* only needed for hardware emulators */
        sync_m68k_pc ();
-       printf ("\top_illg(opcode);\n");
+       printf ("\top_illg(opcode, regs);\n");
        break;
     case i_CALLM:              /* not present in 68030 */
        sync_m68k_pc ();
-       printf ("\top_illg(opcode);\n");
+       printf ("\top_illg(opcode, regs);\n");
        break;
     case i_RTM:                /* not present in 68030 */
        sync_m68k_pc ();
-       printf ("\top_illg(opcode);\n");
+       printf ("\top_illg(opcode, regs);\n");
        break;
     case i_TRAPcc:
        if (curi->smode != am_unknown && curi->smode != am_illg)
            genamode (curi->smode, "srcreg", curi->size, "dummy", 1, 0, 0);
        fill_prefetch_0 ();
-       printf ("\tif (cctrue(%d)) { Exception(7,m68k_getpc()); goto %s; }\n", curi->cc, endlabelstr);
+       printf ("\tif (cctrue(&regs->ccrflags, %d)) { Exception(7, regs, m68k_getpc(regs)); goto %s; }\n", curi->cc, endlabelstr);
        need_endlabel = 1;
        break;
     case i_DIVL:
        sync_m68k_pc ();
        start_brace ();
-       printf ("\tuaecptr oldpc = m68k_getpc();\n");
+       printf ("\tuaecptr oldpc = m68k_getpc(regs);\n");
        genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0, 0);
        genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0, 0);
        sync_m68k_pc ();
@@ -2641,8 +2641,8 @@ static void gen_opcode (unsigned long int opcode)
            printf ("\ttmp = (bf0 << (offset & 7)) | (bf1 >> (8 - (offset & 7)));\n");
        }
        printf ("\ttmp >>= (32 - width);\n");
-       printf ("\tSET_NFLG_ALWAYS (tmp & (1 << (width-1)) ? 1 : 0);\n");
-       printf ("\tSET_ZFLG (tmp == 0); SET_VFLG (0); SET_CFLG (0);\n");
+       printf ("\tSET_NFLG_ALWAYS (&regs->ccrflags, tmp & (1 << (width-1)) ? 1 : 0);\n");
+       printf ("\tSET_ZFLG (&regs->ccrflags, tmp == 0); SET_VFLG (&regs->ccrflags, 0); SET_CFLG (&regs->ccrflags, 0);\n");
        switch (curi->mnemo) {
        case i_BFTST:
            break;
@@ -2653,7 +2653,7 @@ static void gen_opcode (unsigned long int opcode)
            printf ("\ttmp = ~tmp;\n");
            break;
        case i_BFEXTS:
-           printf ("\tif (GET_NFLG) tmp |= width == 32 ? 0 : (-1 << width);\n");
+           printf ("\tif (GET_NFLG (&regs->ccrflags)) tmp |= width == 32 ? 0 : (-1 << width);\n");
            printf ("\tm68k_dreg(regs, (extra >> 12) & 7) = tmp;\n");
            break;
        case i_BFCLR:
@@ -2669,8 +2669,8 @@ static void gen_opcode (unsigned long int opcode)
            break;
        case i_BFINS:
            printf ("\ttmp = m68k_dreg(regs, (extra >> 12) & 7);\n");
-           printf ("\tSET_NFLG (tmp & (1 << (width - 1)) ? 1 : 0);\n");
-           printf ("\tSET_ZFLG (tmp == 0);\n");
+           printf ("\tSET_NFLG (&regs->ccrflags, tmp & (1 << (width - 1)) ? 1 : 0);\n");
+           printf ("\tSET_ZFLG (&regs->ccrflags, tmp == 0);\n");
            break;
        default:
            break;
@@ -2744,48 +2744,48 @@ static void gen_opcode (unsigned long int opcode)
        fpulimit();
        genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0, 0);
        sync_m68k_pc ();
-       printf ("\tfpp_opp(opcode,extra);\n");
+       printf ("\tfpp_opp(opcode, regs, extra);\n");
        break;
     case i_FDBcc:
        fpulimit();
        genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0, 0);
        sync_m68k_pc ();
-       printf ("\tfdbcc_opp(opcode,extra);\n");
+       printf ("\tfdbcc_opp(opcode, regs, extra);\n");
        break;
     case i_FScc:
        fpulimit();
        genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0, 0);
        sync_m68k_pc ();
-       printf ("\tfscc_opp(opcode,extra);\n");
+       printf ("\tfscc_opp(opcode, regs, extra);\n");
        break;
     case i_FTRAPcc:
        fpulimit();
        sync_m68k_pc ();
        start_brace ();
-       printf ("\tuaecptr oldpc = m68k_getpc();\n");
+       printf ("\tuaecptr oldpc = m68k_getpc(regs);\n");
        if (curi->smode != am_unknown && curi->smode != am_illg)
            genamode (curi->smode, "srcreg", curi->size, "dummy", 1, 0, 0);
        sync_m68k_pc ();
-       printf ("\tftrapcc_opp(opcode,oldpc);\n");
+       printf ("\tftrapcc_opp(opcode, regs, oldpc);\n");
        break;
     case i_FBcc:
        fpulimit();
        sync_m68k_pc ();
        start_brace ();
-       printf ("\tuaecptr pc = m68k_getpc();\n");
+       printf ("\tuaecptr pc = m68k_getpc(regs);\n");
        genamode (curi->dmode, "srcreg", curi->size, "extra", 1, 0, 0);
        sync_m68k_pc ();
-       printf ("\tfbcc_opp(opcode,pc,extra);\n");
+       printf ("\tfbcc_opp(opcode,regs, pc,extra);\n");
        break;
     case i_FSAVE:
        fpulimit();
        sync_m68k_pc ();
-       printf ("\tfsave_opp(opcode);\n");
+       printf ("\tfsave_opp(opcode, regs);\n");
        break;
     case i_FRESTORE:
        fpulimit();
        sync_m68k_pc ();
-       printf ("\tfrestore_opp(opcode);\n");
+       printf ("\tfrestore_opp(opcode, regs);\n");
        break;
 
      case i_CINVL:
@@ -2845,7 +2845,7 @@ static void gen_opcode (unsigned long int opcode)
     case i_MMUOP:
        genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0, 0);
        sync_m68k_pc ();
-       printf ("\tmmu_op(opcode,extra);\n");
+       printf ("\tmmu_op(opcode, regs, extra);\n");
        break;
     default:
        abort ();
@@ -2867,7 +2867,6 @@ static void generate_includes (FILE * f)
 {
     fprintf (f, "#include \"sysconfig.h\"\n");
     fprintf (f, "#include \"sysdeps.h\"\n");
-    fprintf (f, "#include \"config.h\"\n");
     fprintf (f, "#include \"options.h\"\n");
     fprintf (f, "#include \"memory.h\"\n");
     fprintf (f, "#include \"custom.h\"\n");
@@ -2877,8 +2876,8 @@ static void generate_includes (FILE * f)
     fprintf (f, "#include \"cputbl.h\"\n");
 
     fprintf (f, "#define CPUFUNC(x) x##_ff\n"
-            "#define SET_CFLG_ALWAYS(x) SET_CFLG(x)\n"
-            "#define SET_NFLG_ALWAYS(x) SET_NFLG(x)\n"
+            "#define SET_CFLG_ALWAYS(flags, x) SET_CFLG(flags, x)\n"
+            "#define SET_NFLG_ALWAYS(flags, x) SET_NFLG(flags, x)\n"
             "#ifdef NOFLAGS\n"
             "#include \"noflags.h\"\n"
             "#endif\n");
@@ -3025,7 +3024,7 @@ static void generate_one_opcode (int rp)
     printf ("/* %s */\n", outopcode (opcode));
     if (i68000)
        printf("#ifndef CPUEMU_68000_ONLY\n");
-    printf ("%s REGPARAM2 CPUFUNC(op_%04lx_%d)(uae_u32 opcode)\n{\n", using_ce ? "void" : "unsigned long", opcode, postfix);
+    printf ("%s REGPARAM2 CPUFUNC(op_%04lx_%d)(uae_u32 opcode, struct regstruct *regs)\n{\n", using_ce ? "void" : "unsigned long", opcode, postfix);
 
     switch (table68k[opcode].stype) {
     case 0: smsk = 7; break;
@@ -3183,7 +3182,7 @@ int main (int argc, char **argv)
        }
        if (i > 0 && i < 4)
            fprintf (stblfile, "#ifndef CPUEMU_68000_ONLY\n");
-       fprintf (stblfile, "struct cputbl CPUFUNC(op_smalltbl_%d)[] = {\n", postfix);
+       fprintf (stblfile, "const struct cputbl CPUFUNC(op_smalltbl_%d)[] = {\n", postfix);
        generate_func ();
        if (i > 0 && i < 4)
            fprintf (stblfile, "#endif /* CPUEMU_68000_ONLY */\n");
diff --git a/genlinetoscr.c b/genlinetoscr.c
new file mode 100755 (executable)
index 0000000..0bf5c6e
--- /dev/null
@@ -0,0 +1,340 @@
+/*
+ * E-UAE - The portable Amiga Emulator
+ *
+ * Generate pixel output code.
+ *
+ * (c) 2006 Richard Drummond
+ */
+
+#include <stdlib.h>
+#include <stdarg.h>
+#include <stdio.h>
+
+/* Output for big-endian target if true, little-endian is false. */
+int do_bigendian;
+
+typedef enum
+{
+    DEPTH_8BPP,
+    DEPTH_16BPP,
+    DEPTH_32BPP,
+} DEPTH_T;
+#define DEPTH_MAX DEPTH_32BPP
+
+static const char *get_depth_str (DEPTH_T bpp)
+{
+   if (bpp == DEPTH_8BPP)
+       return "8";
+   else if (bpp == DEPTH_16BPP)
+       return "16";
+   else
+       return "32";
+}
+
+static const char *get_depth_type_str (DEPTH_T bpp)
+{
+    if (bpp == DEPTH_8BPP)
+       return "uae_u8";
+    else if (bpp == DEPTH_16BPP)
+       return "uae_u16";
+    else
+       return "uae_u32";
+}
+
+
+typedef enum
+{
+    HMODE_NORMAL,
+    HMODE_DOUBLE,
+    HMODE_HALVE,
+    HMODE_HALVE2
+} HMODE_T;
+#define HMODE_MAX HMODE_HALVE2
+
+static const char *get_hmode_str (HMODE_T hmode)
+{
+    if (hmode == HMODE_DOUBLE)
+       return "_stretch1";
+   else if (hmode == HMODE_HALVE)
+       return "_shrink1";
+   else if (hmode == HMODE_HALVE2)
+       return "_shrink2";
+   else
+       return "";
+}
+
+
+typedef enum
+{
+    CMODE_NORMAL,
+    CMODE_DUALPF,
+    CMODE_EXTRAHB,
+    CMODE_HAM
+} CMODE_T;
+#define CMODE_MAX CMODE_HAM
+
+
+static FILE *outfile;
+static unsigned int outfile_indent = 0;
+
+void set_outfile (FILE *f)
+{
+    outfile = f;
+}
+
+int set_indent (int indent)
+{
+    int old_indent = outfile_indent;
+    outfile_indent = indent;
+    return old_indent;
+}
+
+void outln (const char *s)
+{
+    unsigned int i;
+    for (i = 0; i < outfile_indent; i++)
+       fputc (' ', outfile);
+    fprintf (outfile, "%s\n", s);
+}
+
+void outlnf (const char *s, ...)
+{
+    va_list ap;
+    unsigned int i;
+    for (i = 0; i < outfile_indent; i++)
+       fputc (' ', outfile);
+    va_start (ap, s);
+    vfprintf (outfile, s, ap);
+    fputc ('\n', outfile);
+}
+
+static void out_linetoscr_decl (DEPTH_T bpp, HMODE_T hmode, int aga)
+{
+    outlnf ("static int NOINLINE linetoscr_%s%s%s (int spix, int dpix, int stoppos)",
+           get_depth_str (bpp),
+           get_hmode_str (hmode), aga ? "_aga" : "");
+}
+
+static void out_linetoscr_do_srcpix (DEPTH_T bpp, HMODE_T hmode, int aga, CMODE_T cmode)
+{
+    if (aga && cmode != CMODE_DUALPF)
+       outln (         "    spix_val = pixdata.apixels[spix] ^ xor_val;");
+    else if (cmode != CMODE_HAM)
+       outln (         "    spix_val = pixdata.apixels[spix];");
+}
+
+static void out_linetoscr_do_dstpix (DEPTH_T bpp, HMODE_T hmode, int aga, CMODE_T cmode)
+{
+    if (aga && cmode == CMODE_HAM)
+       outln (         "    dpix_val = CONVERT_RGB (ham_linebuf[spix]);");
+    else if (cmode == CMODE_HAM)
+       outln (         "    dpix_val = xcolors[ham_linebuf[spix]];");
+    else if (aga && cmode == CMODE_DUALPF) {
+       outln (         "    if (spriteagadpfpixels[spix]) {");
+       outln (         "        dpix_val = colors_for_drawing.acolors[spriteagadpfpixels[spix]];");
+       outln (         "        spriteagadpfpixels[spix] = 0;");
+       outln (         "    } else {");
+       outln (         "        unsigned int val = lookup[spix_val];");
+       outln (         "        if (lookup_no[spix_val] == 2)");
+       outln (         "            val += dblpfofs[bpldualpf2of];");
+       outln (         "        val ^= xor_val;");
+       outln (         "        dpix_val = colors_for_drawing.acolors[val];");
+       outln (         "    }");
+    } else if (cmode == CMODE_DUALPF) {
+       outln (         "    dpix_val = colors_for_drawing.acolors[lookup[spix_val]];");
+    } else if (aga && cmode == CMODE_EXTRAHB) {
+       outln (         "    if (spix_val >= 32 && spix_val < 64) {");
+       outln (         "        unsigned int c = (colors_for_drawing.color_regs_aga[spix_val - 32] >> 1) & 0x7F7F7F;");
+       outln (         "        dpix_val = CONVERT_RGB (c);");
+       outln (         "    } else");
+       outln (         "        dpix_val = colors_for_drawing.acolors[spix_val];");
+    } else if (cmode == CMODE_EXTRAHB) {
+       outln (         "    if (spix_val <= 31)");
+       outln (         "        dpix_val = colors_for_drawing.acolors[spix_val];");
+       outln (         "    else");
+       outln (         "        dpix_val = xcolors[(colors_for_drawing.color_regs_ecs[spix_val - 32] >> 1) & 0x777];");
+    } else
+       outln (         "    dpix_val = colors_for_drawing.acolors[spix_val];");
+}
+
+static void out_linetoscr_do_incspix (DEPTH_T bpp, HMODE_T hmode, int aga, CMODE_T cmode)
+{
+    if (hmode == HMODE_HALVE2) {
+       outln (         "    spix++;");
+       outln (         "    tmp_val = dpix_val;");
+       out_linetoscr_do_srcpix (bpp, hmode, aga, cmode);
+       out_linetoscr_do_dstpix (bpp, hmode, aga, cmode);
+       outlnf (        "    dpix_val = merge_2pixel%d (dpix_val, tmp_val);", bpp == 0 ? 8 : bpp == 1 ? 16 : 32);
+       outln (         "    spix++;");
+    } else if (hmode == HMODE_HALVE)
+       outln (         "    spix += 2;");
+    else
+       outln (         "    spix++;");
+}
+
+static void out_linetoscr_mode (DEPTH_T bpp, HMODE_T hmode, int aga, CMODE_T cmode)
+{
+    int old_indent = set_indent (8);
+
+    if (aga && cmode == CMODE_DUALPF) {
+       outln (        "int *lookup    = bpldualpfpri ? dblpf_ind2_aga : dblpf_ind1_aga;");
+       outln (        "int *lookup_no = bpldualpfpri ? dblpf_2nd2     : dblpf_2nd1;");
+    } else if (cmode == CMODE_DUALPF)
+       outln (        "int *lookup = bpldualpfpri ? dblpf_ind2 : dblpf_ind1;");
+
+
+    /* TODO: add support for combining pixel writes in 8-bpp modes. */
+
+    if (bpp == DEPTH_16BPP && hmode != HMODE_DOUBLE) {
+       outln (         "int rem;");
+       outln (         "if (((long)&buf[dpix]) & 2) {");
+       outln (         "    uae_u32 spix_val;");
+       outln (         "    uae_u32 dpix_val;");
+       if (hmode == HMODE_HALVE2)
+           outln (     "    uae_u32 tmp_val;");
+
+       out_linetoscr_do_srcpix (bpp, hmode, aga, cmode);
+       out_linetoscr_do_dstpix (bpp, hmode, aga, cmode);
+       out_linetoscr_do_incspix (bpp, hmode, aga, cmode);
+
+       outln (         "    buf[dpix++] = dpix_val;");
+       outln (         "}");
+       outln (         "if (dpix >= stoppos)");
+       outln (         "    return spix;");
+       outln (         "rem = (((long)&buf[stoppos]) & 2);");
+       outln (         "if (rem)");
+       outln (         "    stoppos--;");
+    }
+
+
+    outln (            "while (dpix < stoppos) {");
+    outln (            "    uae_u32 spix_val;");
+    outln (            "    uae_u32 dpix_val;");
+    outln (            "    uae_u32 out_val;");
+    if (hmode == HMODE_HALVE2)
+       outln (         "    uae_u32 tmp_val;");
+    outln (            "");
+
+    out_linetoscr_do_srcpix (bpp, hmode, aga, cmode);
+    out_linetoscr_do_dstpix (bpp, hmode, aga, cmode);
+    out_linetoscr_do_incspix (bpp, hmode, aga, cmode);
+
+    outln (            "    out_val = dpix_val;");
+
+    if (hmode != HMODE_DOUBLE && bpp == DEPTH_16BPP) {
+       out_linetoscr_do_srcpix (bpp, hmode, aga, cmode);
+       out_linetoscr_do_dstpix (bpp, hmode, aga, cmode);
+       out_linetoscr_do_incspix (bpp, hmode, aga, cmode);
+
+       if (do_bigendian)
+           outln (     "    out_val = (out_val << 16) | (dpix_val & 0xFFFF);");
+       else
+           outln (     "    out_val = (out_val & 0xFFFF) | (dpix_val << 16);");
+    }
+
+    if (hmode == HMODE_DOUBLE) {
+       if (bpp == DEPTH_8BPP) {
+           outln (     "    *((uae_u16 *)&buf[dpix]) = (uae_u16) out_val;");
+           outln (     "    dpix += 2;");
+       } else if (bpp == DEPTH_16BPP) {
+           outln (     "    *((uae_u32 *)&buf[dpix]) = out_val;");
+           outln (     "    dpix += 2;");
+       } else {
+           outln (     "    buf[dpix++] = out_val;");
+           outln (     "    buf[dpix++] = out_val;");
+       }
+    } else {
+       if (bpp == DEPTH_16BPP) {
+           outln (     "    *((uae_u32 *)&buf[dpix]) = out_val;");
+           outln (     "    dpix += 2;");
+        } else
+           outln (     "    buf[dpix++] = out_val;");
+    }
+
+    outln (            "}");
+
+
+    if (bpp == DEPTH_16BPP && hmode != HMODE_DOUBLE) {
+       outln (         "if (rem) {");
+       outln (         "    uae_u32 spix_val;");
+       outln (         "    uae_u32 dpix_val;");
+       if (hmode == HMODE_HALVE2)
+           outln (     "    uae_u32 tmp_val;");
+
+       out_linetoscr_do_srcpix (bpp, hmode, aga, cmode);
+       out_linetoscr_do_dstpix (bpp, hmode, aga, cmode);
+       out_linetoscr_do_incspix (bpp, hmode, aga, cmode);
+
+       outln (         "    buf[dpix++] = dpix_val;");
+       outln (         "}");
+    }
+
+    set_indent (old_indent);
+
+    return;
+}
+
+static void out_linetoscr (DEPTH_T bpp, HMODE_T hmode, int aga)
+{
+    if (aga)
+       outln  ("#ifdef AGA");
+
+    out_linetoscr_decl (bpp, hmode, aga);
+    outln  (   "{");
+
+    outlnf (   "    %s *buf = (%s *) xlinebuffer;", get_depth_type_str (bpp), get_depth_type_str (bpp));
+    if (aga)
+       outln ( "    uae_u8 xor_val = (uae_u8)(dp_for_drawing->bplcon4 >> 8);");
+    outln  (   "");
+
+    outln  (   "    if (dp_for_drawing->ham_seen) {");
+    out_linetoscr_mode (bpp, hmode, aga, CMODE_HAM);
+    outln  (   "    } else if (bpldualpf) {");
+    out_linetoscr_mode (bpp, hmode, aga, CMODE_DUALPF);
+    outln  (   "    } else if (bplehb) {");
+    out_linetoscr_mode (bpp, hmode, aga, CMODE_EXTRAHB);
+    outln  (   "    } else {");
+    out_linetoscr_mode (bpp, hmode, aga, CMODE_NORMAL);
+
+    outln  (   "    }\n");
+    outln  (   "    return spix;");
+    outln  (   "}");
+
+    if (aga)
+       outln ( "#endif");
+    outln  (   "");
+}
+
+int main (int argc, char *argv[])
+{
+   DEPTH_T bpp;
+   int aga;
+   HMODE_T hmode;
+   unsigned int i;
+
+    do_bigendian = 0;
+
+    for (i = 1; i < argc; i++) {
+       if (argv[i][0] != '-')
+           continue;
+       if (argv[i][1] == 'b' && argv[i][2] == '\0')
+           do_bigendian = 1;
+    }
+
+   set_outfile (stdout);
+
+   outln ("/*");
+   outln (" * E-UAE - The portable Amiga emulator.");
+   outln (" *");
+   outln (" * This file was generated by genlinetoscr. Don't edit.");
+   outln (" */");
+   outln ("");
+
+   for (bpp = DEPTH_8BPP; bpp <= DEPTH_MAX; bpp++) {
+       for (aga = 0; aga <= 1 ; aga++) {
+           for (hmode = HMODE_NORMAL; hmode <= HMODE_MAX; hmode++)
+               out_linetoscr (bpp, hmode, aga);
+       }
+    }
+    return 0;
+}
index f4fac262d411ed3c5784a2eb8e7ead9857eaca0c..64ddd9c50d62aff324c13054715837dfb13b8c84 100755 (executable)
--- a/gfxlib.c
+++ b/gfxlib.c
@@ -29,7 +29,6 @@
 
 #include <assert.h>
 
-#include "config.h"
 #include "options.h"
 #include "threaddep/thread.h"
 #include "memory.h"
@@ -38,7 +37,6 @@
 #include "xwin.h"
 #include "autoconf.h"
 #include "osemu.h"
-#include "osdep/exectasks.h"
 
 #ifdef USE_EXECLIB
 
index ef585d2b633f58b793d832becd039047cbdd3c0d..7fd6f64c5564818f17c852eb6c3e4a86721a4655 100755 (executable)
--- a/gfxutil.c
+++ b/gfxutil.c
@@ -8,7 +8,6 @@
 
 #include "sysconfig.h"
 #include "sysdeps.h"
-#include "options.h"
 #include "custom.h"
 #include "xwin.h"
 
@@ -28,7 +27,7 @@ static uae_u8 dither[4][4] =
 };
 
 
-unsigned long doMask (int p, int bits, int shift)
+unsigned int doMask (int p, int bits, int shift)
 {
     /* scale to 0..255, shift to align msb with mask, and apply mask */
     unsigned long val = p << 24;
@@ -60,7 +59,7 @@ int mask_shift (unsigned long mask)
     return n;
 }
 
-unsigned long doMask256 (int p, int bits, int shift)
+unsigned int doMask256 (int p, int bits, int shift)
 {
     /* p is a value from 0 to 255 (Amiga color value)
      * shift to align msb with mask, and apply mask */
@@ -126,8 +125,9 @@ static void colormodify (int *r, int *g, int *b)
 }
 #endif
 
-void alloc_colors64k (int rw, int gw, int bw, int rs, int gs, int bs, int aw, int as, int alpha)
+void alloc_colors64k (int rw, int gw, int bw, int rs, int gs, int bs, int aw, int as, int alpha, int byte_swap)
 {
+    int bpp = rw + gw + bw + aw;
     int i;
 
     for (i = 0; i < 4096; i++) {
@@ -138,6 +138,17 @@ void alloc_colors64k (int rw, int gw, int bw, int rs, int gs, int bs, int aw, in
        g = greyscale (g);
        b = greyscale (b);
        xcolors[i] = doMask(r, rw, rs) | doMask(g, gw, gs) | doMask(b, bw, bs) | doAlpha (alpha, aw, as);
+        if (byte_swap) {
+           if (bpp <= 16)
+               xcolors[i] = bswap_16 (xcolors[i]);
+           else
+               xcolors[i] = bswap_32 (xcolors[i]);
+       }
+        if (bpp <= 16) {
+           /* Fill upper 16 bits of each colour value
+            * with a copy of the colour. */
+           xcolors[i] |= xcolors[i] * 0x00010001;
+       }
     }
 #ifdef AGA
     /* create AGA color tables */
@@ -146,6 +157,25 @@ void alloc_colors64k (int rw, int gw, int bw, int rs, int gs, int bs, int aw, in
        xgreencolors[i] = greyscale (doColor (i, gw, gs)) | doAlpha (alpha, aw, as);
        xbluecolors[i] = greyscale (doColor (i, bw, bs)) | doAlpha (alpha, aw, as);
     }
+    if (byte_swap) {
+       if (bpp <= 16) {
+           xredcolors  [i] = bswap_16 (xredcolors[i]);
+           xgreencolors[i] = bswap_16 (xgreencolors[i]);
+           xbluecolors [i] = bswap_16 (xbluecolors[i]);
+       } else {
+           xredcolors  [i] = bswap_32 (xredcolors[i]);
+           xgreencolors[i] = bswap_32 (xgreencolors[i]);
+           xbluecolors [i] = bswap_32 (xbluecolors[i]);
+       }
+    }
+    if (bpp <= 16) {
+        /* Fill upper 16 bits of each colour value with
+         * a copy of the colour. */
+        xredcolors  [i] = xredcolors  [i] * 0x00010001;
+        xgreencolors[i] = xgreencolors[i] * 0x00010001;
+        xbluecolors [i] = xbluecolors [i] * 0x00010001;
+    }
+
 #endif
     xredcolor_b = rw;
     xgreencolor_b = gw;
@@ -158,7 +188,6 @@ void alloc_colors64k (int rw, int gw, int bw, int rs, int gs, int bs, int aw, in
     xbluecolor_m = (1 << bw) - 1;
 }
 
-static int allocated[4096];
 static int color_diff[4096];
 static int newmaxcol = 0;
 
@@ -303,7 +332,7 @@ void setup_greydither_maxcol (int maxcol, allocfunc_type allocfunc)
     xcolnr *map;
 
     for (i = 0; i < 4096; i++)
-       xcolors[i] = i;
+       xcolors[i] = i << 16 | i;
 
     map = (xcolnr *)malloc (sizeof(xcolnr) * maxcol);
     if (!map) {
@@ -376,7 +405,7 @@ void setup_dither (int bits, allocfunc_type allocfunc)
     }
 
     for (i = 0; i < 4096; i++)
-       xcolors[i] = i;
+       xcolors[i] = i << 16 | i;
 
     /*
      * compute #cols per components
index cec7d66cc9d7020f08e894eb0d634b9ec10f2b65..3546e8de54efc43d33a911330b0ca61c81a585b8 100755 (executable)
@@ -10,7 +10,6 @@
 #include "sysconfig.h"
 #include "sysdeps.h"
 
-#include "config.h"
 #include "threaddep/thread.h"
 #include "options.h"
 #include "memory.h"
@@ -18,6 +17,7 @@
 #include "newcpu.h"
 #include "disk.h"
 #include "autoconf.h"
+#include "traps.h"
 #include "filesys.h"
 #include "execlib.h"
 #include "native2amiga.h"
@@ -78,7 +78,7 @@
 #define ASYNC_REQUEST_TEMP 1
 #define ASYNC_REQUEST_CHANGEINT 10
 
-static struct hardfileprivdata {
+struct hardfileprivdata {
     volatile uaecptr d_request[MAX_ASYNC_REQUESTS];
     volatile int d_request_type[MAX_ASYNC_REQUESTS];
     volatile uae_u32 d_request_data[MAX_ASYNC_REQUESTS];
@@ -107,8 +107,6 @@ static int rl (uae_u8 *p)
     return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | (p[3]);
 }
 
-#if 0 // not yet production ready
-
 static uae_u64 cmd_read (struct hardfiledata *hfd, uaecptr dataptr, uae_u64 offset, uae_u64 len)
 {
     addrbank *bank_data = &get_mem_bank (dataptr);
@@ -128,55 +126,6 @@ static uae_u64 cmd_write (struct hardfiledata *hfd, uaecptr dataptr, uae_u64 off
     return hdf_write (hfd, bank_data->xlateaddr (dataptr), offset, len);
 }
 
-#else
-
-static uae_u64 cmd_read (struct hardfiledata *hfd, uaecptr dataptr, uae_u64 offset, uae_u64 len)
-{
-    uae_u64 got = 0;
-    uae_u8 buffer[FILESYS_MAX_BLOCKSIZE];
-    int i;
-
-    gui_hd_led (1);
-    hf_log2 ("cmd_read: %p %04.4x-%08.8x %08.8x\n", dataptr, (uae_u32)(offset >> 32), (uae_u32)offset, (uae_u32)len);
-    while (len > 0) {
-       int got2;
-       got2 = hdf_read (hfd, buffer, offset, hfd->blocksize);
-       if (got2 != hfd->blocksize)
-           break;
-       for (i = 0; i < got2; i++)
-           put_byte(dataptr + i, buffer[i]);
-       len -= got2;
-       got += got2;
-       dataptr += got2;
-       offset += got2;
-    }
-    return got;
-}
-static uae_u64 cmd_write (struct hardfiledata *hfd, uaecptr dataptr, uae_u64 offset, uae_u64 len)
-{
-    uae_u64 got = 0;
-    uae_u8 buffer[FILESYS_MAX_BLOCKSIZE];
-    int i;
-
-    gui_hd_led (1);
-    hf_log2 ("cmd_write: %p %04.4x-%08.8x %08.8x\n", dataptr, (uae_u32)(offset >> 32), (uae_u32)offset, (uae_u32)len);
-    while (len > 0) {
-       int got2;
-       for (i = 0; i < hfd->blocksize; i++)
-           buffer[i] = get_byte (dataptr + i);
-       got2 = hdf_write (hfd, buffer, offset, hfd->blocksize);
-       if (got2 != hfd->blocksize)
-           break;
-       len -= got2;
-       got += got2;
-       dataptr += got2;
-       offset += got2;
-    }
-    return got;
-}
-
-#endif
-
 static int handle_scsi (uaecptr request, struct hardfiledata *hfd)
 {
     uae_u32 acmd = get_long (request + 40);
@@ -305,7 +254,7 @@ static int handle_scsi (uaecptr request, struct hardfiledata *hfd)
        ls = 12;
        break;
        default:
-       lr = -1;
+        lr = -1;
        write_log ("UAEHF: unsupported scsi command 0x%02.2X\n", cmd);
        status = 2; /* CHECK CONDITION */
        s[0] = 0x70;
@@ -440,43 +389,47 @@ static int mangleunit (int unit)
     return -1;
 }
 
-static uae_u32 hardfile_open (void)
+static uae_u32 REGPARAM2 hardfile_open (TrapContext *context)
 {
-    uaecptr tmp1 = m68k_areg(regs, 1); /* IOReq */
-    int unit = mangleunit (m68k_dreg (regs, 0));
+    uaecptr tmp1 = m68k_areg(&context->regs, 1); /* IOReq */
+    int unit = mangleunit (m68k_dreg (&context->regs, 0));
     struct hardfileprivdata *hfpd = &hardfpd[unit];
+    int err = -1;
 
-    hf_log ("hardfile_open, unit %d (%d)\n", unit, m68k_dreg (regs, 0));
     /* Check unit number */
     if (unit >= 0 && get_hardfile_data (unit) && start_thread (unit)) {
        hfpd->opencount++;
-       put_word (m68k_areg(regs, 6) + 32, get_word (m68k_areg(regs, 6) + 32) + 1);
+       put_word (m68k_areg(&context->regs, 6) + 32, get_word (m68k_areg(&context->regs, 6) + 32) + 1);
        put_long (tmp1 + 24, unit); /* io_Unit */
        put_byte (tmp1 + 31, 0); /* io_Error */
        put_byte (tmp1 + 8, 7); /* ln_type = NT_REPLYMSG */
+       hf_log ("hardfile_open, unit %d (%d), OK\n", unit, m68k_dreg (&context->regs, 0));
        return 0;
     }
-
-    put_long (tmp1 + 20, (uae_u32)-1);
-    put_byte (tmp1 + 31, (uae_u8)-1);
-    return (uae_u32)-1;
+    if (is_hardfile(NULL, unit) == FILESYS_VIRTUAL)
+       err = -6;
+    hf_log ("hardfile_open, unit %d (%d), ERR=%d\n", unit, m68k_dreg (&context->regs, 0), err);
+    put_long (tmp1 + 20, (uae_u32)err);
+    put_byte (tmp1 + 31, (uae_u8)err);
+    return (uae_u32)err;
 }
 
-static uae_u32 hardfile_close (void)
+static uae_u32 REGPARAM2 hardfile_close (TrapContext *context)
 {
-    uaecptr request = m68k_areg(regs, 1); /* IOReq */
+    uaecptr request = m68k_areg(&context->regs, 1); /* IOReq */
     int unit = mangleunit (get_long (request + 24));
     struct hardfileprivdata *hfpd = &hardfpd[unit];
 
-    if (!hfpd->opencount) return 0;
+    if (!hfpd->opencount)
+       return 0;
     hfpd->opencount--;
     if (hfpd->opencount == 0)
        write_comm_pipe_u32 (&hfpd->requests, 0, 1);
-    put_word (m68k_areg(regs, 6) + 32, get_word (m68k_areg(regs, 6) + 32) - 1);
+    put_word (m68k_areg(&context->regs, 6) + 32, get_word (m68k_areg(&context->regs, 6) + 32) - 1);
     return 0;
 }
 
-static uae_u32 hardfile_expunge (void)
+static uae_u32 REGPARAM2 hardfile_expunge (TrapContext *context)
 {
     return 0; /* Simply ignore this one... */
 }
@@ -555,10 +508,6 @@ static uae_u32 hardfile_do_io (struct hardfiledata *hfd, struct hardfileprivdata
     switch (cmd)
     {
        case CMD_READ:
-#if 0
-       if (dataptr & 1)
-           goto bad_command;
-#endif
        offset = get_long (request + 44);
        len = get_long (request + 36); /* io_Length */
        if ((offset & bmask) || (len & bmask)) {
@@ -574,10 +523,6 @@ static uae_u32 hardfile_do_io (struct hardfiledata *hfd, struct hardfileprivdata
 
        case TD_READ64:
        case NSCMD_TD_READ64:
-#if 0
-       if (dataptr & 1)
-           goto bad_command;
-#endif
        offset64 = get_long (request + 44) | ((uae_u64)get_long (request + 32) << 32);
        len = get_long (request + 36); /* io_Length */
        if ((offset64 & bmask) || (len & bmask)) {
@@ -596,10 +541,6 @@ static uae_u32 hardfile_do_io (struct hardfiledata *hfd, struct hardfileprivdata
        if (hfd->readonly) {
            error = 28; /* write protect */
        } else {
-#if 0
-           if (dataptr & 1)
-               goto bad_command;
-#endif
            offset = get_long (request + 44);
            len = get_long (request + 36); /* io_Length */
            if ((offset & bmask) || (len & bmask)) {
@@ -621,10 +562,6 @@ static uae_u32 hardfile_do_io (struct hardfiledata *hfd, struct hardfileprivdata
        if (hfd->readonly) {
            error = 28; /* write protect */
        } else {
-#if 0
-           if (dataptr & 1)
-               goto bad_command;
-#endif
            offset64 = get_long (request + 44) | ((uae_u64)get_long (request + 32) << 32);
            len = get_long (request + 36); /* io_Length */
            if ((offset64 & bmask) || (len & bmask)) {
@@ -713,10 +650,12 @@ static uae_u32 hardfile_do_io (struct hardfiledata *hfd, struct hardfileprivdata
        break;
 
        case HD_SCSICMD: /* SCSI */
-           if (hfd->nrcyls == 0)
+           if (hfd->nrcyls == 0) {
                error = handle_scsi (request, hfd);
-           else /* we don't want users trashing their "partition" hardfiles with hdtoolbox */
-               error = -3; /* io_Error */
+           } else { /* we don't want users trashing their "partition" hardfiles with hdtoolbox */
+               error = -3; /* IOERR_NOCMD */
+               write_log ("UAEHF: HD_SCSICMD tried on regular HDF, unit %d", unit);
+           }
        break;
 
        default:
@@ -733,9 +672,9 @@ static uae_u32 hardfile_do_io (struct hardfiledata *hfd, struct hardfileprivdata
     return async;
 }
 
-static uae_u32 hardfile_abortio (void)
+static uae_u32 REGPARAM2 hardfile_abortio (TrapContext *context)
 {
-    uae_u32 request = m68k_areg(regs, 1);
+    uae_u32 request = m68k_areg(&context->regs, 1);
     int unit = mangleunit (get_long (request + 24));
     struct hardfiledata *hfd = get_hardfile_data (unit);
     struct hardfileprivdata *hfpd = &hardfpd[unit];
@@ -777,9 +716,9 @@ static int hardfile_canquick (struct hardfiledata *hfd, uaecptr request)
     return hardfile_can_quick (command);
 }
 
-static uae_u32 hardfile_beginio (void)
+static uae_u32 REGPARAM2 hardfile_beginio (TrapContext *context)
 {
-    uae_u32 request = m68k_areg(regs, 1);
+    uae_u32 request = m68k_areg(&context->regs, 1);
     uae_u8 flags = get_byte (request + 30);
     int cmd = get_word (request + 28);
     int unit = mangleunit (get_long (request + 24));
@@ -810,7 +749,7 @@ static void *hardfile_thread (void *devs)
 {
     struct hardfileprivdata *hfpd = devs;
 
-    set_thread_priority (2);
+    uae_set_thread_priority (2);
     hfpd->thread_running = 1;
     uae_sem_post (&hfpd->sync_sem);
     for (;;) {
@@ -842,7 +781,7 @@ void hardfile_reset (void)
        if (hfpd->opencount > 0) {
            for (j = 0; j < MAX_ASYNC_REQUESTS; j++) {
                uaecptr request;
-               if (request = hfpd->d_request[i])
+               if ((request = hfpd->d_request[i]))
                    abort_async (hfpd, request, 0, 0);
            }
        }
index 391c62b9146818222e308a70846a8826fcce55a2..cd5ba3470c3f36964002e5ceffdc239de1309a1c 100755 (executable)
@@ -13,7 +13,7 @@
 #include "memory.h"
 #include "identify.h"
 
-struct mem_labels int_labels[] =
+const struct mem_labels int_labels[] =
 {
     { "Reset:SSP",  0x0000 },
     { "EXECBASE",   0x0004 },
@@ -39,7 +39,7 @@ struct mem_labels int_labels[] =
     { 0, 0 }
 };
 
-struct mem_labels trap_labels[] =
+const struct mem_labels trap_labels[] =
 {
     { "TRAP 00",    0x0080 },
     { "TRAP 01",    0x0084 },
@@ -60,7 +60,7 @@ struct mem_labels trap_labels[] =
     { 0, 0 }
 };
 
-struct mem_labels mem_labels[] =
+const struct mem_labels mem_labels[] =
 {
     { "CIAB PRA",   0xBFD000 },
     { "CIAB PRB",   0xBFD100 },
@@ -114,7 +114,7 @@ struct mem_labels mem_labels[] =
 /* This table was generated from the list of AGA chip names in
  * AGA.guide available on aminet. It could well have errors in it. */
 
-struct customData custd[] =
+const struct customData custd[] =
 {
 #if 0
     { "BLTDDAT",  0xdff000 }, /* Blitter dest. early read (dummy address) */
index 2f6e6b911764487729059bd6dbbccfac325a377e..de84a01030cc2405aa2ddc067129f8d503bc0a93 100755 (executable)
@@ -12,5 +12,12 @@ extern void akiko_entergui (void);
 extern void akiko_exitgui (void);
 extern void AKIKO_hsync_handler (void);
 
+extern uae_u32 REGPARAM3 akiko_lget (uaecptr addr) REGPARAM;
+extern uae_u32 REGPARAM3 akiko_wget (uaecptr addr) REGPARAM;
+extern uae_u32 REGPARAM3 akiko_bget (uaecptr addr) REGPARAM;
+extern void REGPARAM3 akiko_bput (uaecptr addr, uae_u32 value) REGPARAM;
+extern void REGPARAM3 akiko_wput (uaecptr addr, uae_u32 value) REGPARAM;
+extern void REGPARAM3 akiko_lput (uaecptr addr, uae_u32 value) REGPARAM;
+
 extern int cd32_enabled;
 extern uae_u8 *extendedkickmemory;
index ac4401086921389033e45dad7ad57d9e8add7f24..de70e663308d74e317114b81429a50031bbe4890 100755 (executable)
@@ -45,11 +45,11 @@ extern void action_replay_init (int);
 extern void action_replay_cleanup (void);
 extern void action_replay_chipwrite(void);
 extern void action_replay_map_banks(void);
-extern void REGPARAM2 chipmem_lput_actionreplay23 (uaecptr addr, uae_u32 l) REGPARAM;
-extern void REGPARAM2 chipmem_wput_actionreplay23 (uaecptr addr, uae_u32 w) REGPARAM;
-extern void REGPARAM2 chipmem_bput_actionreplay1 (uaecptr addr, uae_u32 b) REGPARAM;
-extern void REGPARAM2 chipmem_wput_actionreplay1 (uaecptr addr, uae_u32 w) REGPARAM;
-extern void REGPARAM2 chipmem_lput_actionreplay1 (uaecptr addr, uae_u32 l) REGPARAM;
+extern void REGPARAM3 chipmem_lput_actionreplay23 (uaecptr addr, uae_u32 l) REGPARAM;
+extern void REGPARAM3 chipmem_wput_actionreplay23 (uaecptr addr, uae_u32 w) REGPARAM;
+extern void REGPARAM3 chipmem_bput_actionreplay1 (uaecptr addr, uae_u32 b) REGPARAM;
+extern void REGPARAM3 chipmem_wput_actionreplay1 (uaecptr addr, uae_u32 w) REGPARAM;
+extern void REGPARAM3 chipmem_lput_actionreplay1 (uaecptr addr, uae_u32 l) REGPARAM;
 
 extern void action_replay_version(void);
 
index df84631993947f14809cb477d28fa41373df01c6..f1acc0812b817b0a32e7f1a4456f9a6b90f80336 100755 (executable)
@@ -6,25 +6,23 @@
   * (c) 1996 Ed Hanway
   */
 
-typedef uae_u32 (*TrapFunction) (void);
-
-extern int lasttrap;
-extern uae_u8 *rtarea;
-extern void do_emultrap (int nr);
-
 extern uae_u32 addr (int);
 extern void db (uae_u8);
 extern void dw (uae_u16);
 extern void dl (uae_u32);
-extern uae_u32 ds (char *);
+extern uae_u32 ds (const char *);
 extern void calltrap (uae_u32);
 extern void org (uae_u32);
 extern uae_u32 here (void);
-extern int deftrap2 (TrapFunction func, int mode, const char *str);
-extern int deftrap (TrapFunction);
+
+#define deftrap(f) define_trap((f), 0, "")
+#ifdef TRACE_TRAPS
+# define deftrap2(f, mode, str) define_trap((f), (mode), (str))
+#else
+# define deftrap2(f, mode, str) define_trap((f), (mode), "")
+#endif
+
 extern void align (int);
-extern uae_u32 CallLib (uaecptr base, uae_s16 offset);
-extern void call_calltrap (int nr) REGPARAM;
 
 extern volatile int uae_int_requested;
 extern void set_uae_int_flag (void);
@@ -80,14 +78,9 @@ extern void emulib_install (void);
 extern void expansion_init (void);
 extern void expansion_cleanup (void);
 
-extern uae_u8* rtarea;
-
 #define TRAPFLAG_NO_REGSAVE 1
 #define TRAPFLAG_NO_RETVAL 2
 #define TRAPFLAG_EXTRA_STACK 4
 #define TRAPFLAG_DORET 8
 
-extern uaecptr libemu_InstallFunction (TrapFunction, uaecptr, int, const char *);
-extern uaecptr libemu_InstallFunctionFlags (TrapFunction, uaecptr, int, int, const char *);
-
 #define RTAREA_BASE 0xF00000
index bc7d50166b6c2171a3db7253b99d680b8b4355e2..a245cc0d4f3b0352d8375d64ea1123bd5ff052a5 100755 (executable)
@@ -6,15 +6,6 @@
   * (c) 1995 Bernd Schmidt
   */
 
-#if 0
-struct bltinfo {
-    int blitzero;
-    int blitashift,blitbshift,blitdownashift,blitdownbshift;
-    uae_u32 bltadat, bltbdat, bltcdat,bltddat,bltahold,bltbhold,bltafwm,bltalwm;
-    int vblitsize,hblitsize;
-    int bltamod,bltbmod,bltcmod,bltdmod;
-};
-#else
 struct bltinfo {
     int blitzero;
     int blitashift,blitbshift,blitdownashift,blitdownbshift;
@@ -22,7 +13,7 @@ struct bltinfo {
     int vblitsize,hblitsize;
     int bltamod,bltbmod,bltcmod,bltdmod;
 };
-#endif
+
 extern enum blitter_states {
     BLT_done, BLT_init, BLT_read, BLT_work, BLT_write, BLT_next
 } bltstate;
@@ -50,8 +41,8 @@ typedef void blitter_func(uaecptr, uaecptr, uaecptr, uaecptr, struct bltinfo *);
 
 #define BLITTER_MAX_WORDS 2048
 
-extern blitter_func *blitfunc_dofast[256];
-extern blitter_func *blitfunc_dofast_desc[256];
+extern blitter_func * const blitfunc_dofast[256];
+extern blitter_func * const blitfunc_dofast_desc[256];
 extern uae_u32 blit_masktable[BLITTER_MAX_WORDS];
 
 #define BLIT_MODE_IMMEDIATE -1
index ea4ff77d6094b5b54bf10d0de17c23dee0f4e02d..55053e77cb5ae237456ee79316441c62f4f5d254 100755 (executable)
@@ -68,6 +68,23 @@ struct socketbase {
     void *hAsyncTask;          /* async task handle */
     void *hEvent;              /* thread event handle */
     unsigned int *mtable;      /* window messages allocated for asynchronous event notification */
+#else
+    uae_sem_t sem;             /* semaphore to notify the socket thread of work */
+    uae_thread_id thread;      /* socket thread */
+    int  sockabort[2];         /* pipe used to tell the thread to abort a select */
+    int action;
+    int s;                     /* for accept */
+    uae_u32 name;              /* For gethostbyname */
+    uae_u32 a_addr;            /* gethostbyaddr, accept */
+    uae_u32 a_addrlen;         /* for gethostbyaddr, accept */
+    uae_u32 flags;
+    void *buf;
+    uae_u32 len;
+    uae_u32 to, tolen, from, fromlen;
+    int nfds;
+    uae_u32 sets [3];
+    uae_u32 timeout;
+    uae_u32 sigmp;
 #endif
 } *socketbases;
 
@@ -76,7 +93,7 @@ struct socketbase {
 
 struct UAEBSDBase {
     char dummy[LIBRARY_SIZEOF];
-    uae_u32 sb[sizeof (void*) / 4];
+    struct socketbase *sb;
     char scratchbuf[SCRATCHBUFSIZE];
 };
 
@@ -103,20 +120,18 @@ struct UAEBSDBase {
 #define SF_BLOCKING 0x80000000
 #define SF_BLOCKINGINPROGRESS 0x40000000
 
-struct socketbase *get_socketbase (void);
-
-extern uae_u32 addstr (uae_u32 *, char *);
-extern uae_u32 addmem (uae_u32 *, char *, int len);
+extern uae_u32 addstr (uae_u32 *, const char *);
+extern uae_u32 addmem (uae_u32 *, const char *, int len);
 
 extern char *strncpyah (char *, uae_u32, int);
 extern char *strcpyah (char *, uae_u32);
-extern uae_u32 strcpyha (uae_u32, char *);
-extern uae_u32 strncpyha (uae_u32, char *, int);
+extern uae_u32 strcpyha (uae_u32, const char *);
+extern uae_u32 strncpyha (uae_u32, const char *, int);
 
 #define SB struct socketbase *sb
 
-extern void seterrno (SB, int);
-extern void setherrno (SB, int);
+extern void bsdsocklib_seterrno (SB, int);
+extern void bsdsocklib_setherrno (SB, int);
 
 extern void sockmsg (unsigned int, WPARAM, LPARAM);
 extern void sockabort (SB);
@@ -133,10 +148,10 @@ extern int getsd (SB, SOCKET_TYPE);
 extern SOCKET_TYPE getsock (SB, int);
 extern void releasesock (SB, int);
 
-extern void waitsig (SB);
-extern void cancelsig (SB);
+extern void waitsig (TrapContext *context, SB);
+extern void cancelsig (TrapContext *context, SB);
 
-extern int host_sbinit (SB);
+extern int host_sbinit (TrapContext*, SB);
 extern void host_sbcleanup (SB);
 extern void host_sbreset (void);
 extern void host_closesocketquick (SOCKET_TYPE);
@@ -145,40 +160,39 @@ extern int host_dup2socket (SB, int, int);
 extern int host_socket (SB, int, int, int);
 extern uae_u32 host_bind (SB, uae_u32, uae_u32, uae_u32);
 extern uae_u32 host_listen (SB, uae_u32, uae_u32);
-extern void host_accept (SB, uae_u32, uae_u32, uae_u32);
-extern void host_sendto (SB, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32);
-extern void host_recvfrom (SB, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32);
+extern void host_accept (TrapContext *, SB, uae_u32, uae_u32, uae_u32);
+extern void host_sendto (TrapContext *, SB, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32);
+extern void host_recvfrom (TrapContext *, SB, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32);
 extern uae_u32 host_shutdown (SB, uae_u32, uae_u32);
 extern void host_setsockopt (SB, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32);
 extern uae_u32 host_getsockopt (SB, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32);
 extern uae_u32 host_getsockname (SB, uae_u32, uae_u32, uae_u32);
 extern uae_u32 host_getpeername (SB, uae_u32, uae_u32, uae_u32);
-extern uae_u32 host_IoctlSocket (SB, uae_u32, uae_u32, uae_u32);
+extern uae_u32 host_IoctlSocket (TrapContext *, SB, uae_u32, uae_u32, uae_u32);
 extern uae_u32 host_shutdown (SB, uae_u32, uae_u32);
-extern int host_CloseSocket (SB, int);
-extern void host_connect (SB, uae_u32, uae_u32, uae_u32);
-extern void host_WaitSelect (SB, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32);
+extern int host_CloseSocket (TrapContext *, SB, int);
+extern void host_connect (TrapContext *, SB, uae_u32, uae_u32, uae_u32);
+extern void host_WaitSelect (TrapContext *, SB, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32);
 extern uae_u32 host_SetSocketSignals (void);
 extern uae_u32 host_getdtablesize (void);
 extern uae_u32 host_ObtainSocket (void);
 extern uae_u32 host_ReleaseSocket (void);
 extern uae_u32 host_ReleaseCopyOfSocket (void);
-extern uae_u32 host_Inet_NtoA (SB, uae_u32);
+extern uae_u32 host_Inet_NtoA (TrapContext *context, SB, uae_u32);
 extern uae_u32 host_inet_addr (uae_u32);
 extern uae_u32 host_Inet_LnaOf (void);
 extern uae_u32 host_Inet_NetOf (void);
 extern uae_u32 host_Inet_MakeAddr (void);
 extern uae_u32 host_inet_network (void);
-extern void host_gethostbynameaddr (SB, uae_u32, uae_u32, long);
+extern void host_gethostbynameaddr (TrapContext *, SB, uae_u32, uae_u32, long);
 extern uae_u32 host_getnetbyname (void);
 extern uae_u32 host_getnetbyaddr (void);
-extern void host_getservbynameport (SB, uae_u32, uae_u32, uae_u32);
-extern void host_getprotobyname (SB, uae_u32);
-extern uae_u32 host_getprotobynumber (void);
+extern void host_getservbynameport (TrapContext *, SB, uae_u32, uae_u32, uae_u32);
+extern void host_getprotobyname (TrapContext *, SB, uae_u32);
+extern void host_getprotobynumber (TrapContext *, SB, uae_u32);
 extern uae_u32 host_vsyslog (void);
 extern uae_u32 host_Dup2Socket (void);
 extern uae_u32 host_gethostname (uae_u32, uae_u32);
 
-
 extern void bsdlib_install (void);
 extern void bsdlib_reset (void);
index 462baa1f9f5a5872bd03c130636342723771e94b..dcc047116930552d438141c27bd3885be5a26f0e 100755 (executable)
@@ -17,12 +17,6 @@ extern void cia_diskindex (void);
 
 extern void dumpcia (void);
 extern void rethink_cias (void);
-extern unsigned int ciaaicr,ciaaimask,ciabicr,ciabimask;
-extern unsigned int ciaacra,ciaacrb,ciabcra,ciabcrb;
-extern unsigned int ciabpra;
-extern unsigned long ciaata,ciaatb,ciabta,ciabtb;
-extern unsigned long ciaatod,ciabtod,ciaatol,ciabtol,ciaaalarm,ciabalarm;
-extern int ciaatlatch,ciabtlatch;
 
 extern int parallel_direct_write_data (uae_u8, uae_u8);
 extern int parallel_direct_read_data (uae_u8*);
index 128009c361253c5ee678ad3b1f7e4f9c75416575..9c44f41e539e26ce0ac5a87e10725f19a48c4c86 100755 (executable)
@@ -29,7 +29,7 @@ typedef struct {
     volatile int reader_waiting;
 } smp_comm_pipe;
 
-static __inline__ void init_comm_pipe (smp_comm_pipe *p, int size, int chunks)
+STATIC_INLINE void init_comm_pipe (smp_comm_pipe *p, int size, int chunks)
 {
     memset (p, 0, sizeof (*p));
     p->data = (uae_pt *)malloc (size*sizeof (uae_pt));
@@ -43,14 +43,14 @@ static __inline__ void init_comm_pipe (smp_comm_pipe *p, int size, int chunks)
     uae_sem_init (&p->writer_wait, 0, 0);
 }
 
-static __inline__ void destroy_comm_pipe (smp_comm_pipe *p)
+STATIC_INLINE void destroy_comm_pipe (smp_comm_pipe *p)
 {
     uae_sem_destroy (&p->lock);
     uae_sem_destroy (&p->reader_wait);
     uae_sem_destroy (&p->writer_wait);
 }
 
-static __inline__ void maybe_wake_reader (smp_comm_pipe *p, int no_buffer)
+STATIC_INLINE void maybe_wake_reader (smp_comm_pipe *p, int no_buffer)
 {
     if (p->reader_waiting
        && (no_buffer || ((p->wrp - p->rdp + p->size) % p->size) >= p->chunks))
@@ -60,7 +60,7 @@ static __inline__ void maybe_wake_reader (smp_comm_pipe *p, int no_buffer)
     }
 }
 
-static __inline__ void write_comm_pipe_pt (smp_comm_pipe *p, uae_pt data, int no_buffer)
+STATIC_INLINE void write_comm_pipe_pt (smp_comm_pipe *p, uae_pt data, int no_buffer)
 {
     int nxwrp = (p->wrp + 1) % p->size;
 
@@ -89,7 +89,7 @@ static __inline__ void write_comm_pipe_pt (smp_comm_pipe *p, uae_pt data, int no
     uae_sem_post (&p->lock);
 }
 
-static __inline__ uae_pt read_comm_pipe_pt_blocking (smp_comm_pipe *p)
+STATIC_INLINE uae_pt read_comm_pipe_pt_blocking (smp_comm_pipe *p)
 {
     uae_pt data;
 
@@ -105,7 +105,6 @@ static __inline__ uae_pt read_comm_pipe_pt_blocking (smp_comm_pipe *p)
 
     /* We ignore chunks here. If this is a problem, make the size bigger in the init call. */
     if (p->writer_waiting) {
-       write_log ("read_comm_pipe_pt_blocking!\n");
        p->writer_waiting = 0;
        uae_sem_post (&p->writer_wait);
     }
@@ -113,43 +112,43 @@ static __inline__ uae_pt read_comm_pipe_pt_blocking (smp_comm_pipe *p)
     return data;
 }
 
-static __inline__ int comm_pipe_has_data (smp_comm_pipe *p)
+STATIC_INLINE int comm_pipe_has_data (smp_comm_pipe *p)
 {
     return p->rdp != p->wrp;
 }
 
-static __inline__ int read_comm_pipe_int_blocking (smp_comm_pipe *p)
+STATIC_INLINE int read_comm_pipe_int_blocking (smp_comm_pipe *p)
 {
     uae_pt foo = read_comm_pipe_pt_blocking (p);
     return foo.i;
 }
-static __inline__ uae_u32 read_comm_pipe_u32_blocking (smp_comm_pipe *p)
+STATIC_INLINE uae_u32 read_comm_pipe_u32_blocking (smp_comm_pipe *p)
 {
     uae_pt foo = read_comm_pipe_pt_blocking (p);
     return foo.u32;
 }
 
-static __inline__ void *read_comm_pipe_pvoid_blocking (smp_comm_pipe *p)
+STATIC_INLINE void *read_comm_pipe_pvoid_blocking (smp_comm_pipe *p)
 {
     uae_pt foo = read_comm_pipe_pt_blocking (p);
     return foo.pv;
 }
 
-static __inline__ void write_comm_pipe_int (smp_comm_pipe *p, int data, int no_buffer)
+STATIC_INLINE void write_comm_pipe_int (smp_comm_pipe *p, int data, int no_buffer)
 {
     uae_pt foo;
     foo.i = data;
     write_comm_pipe_pt (p, foo, no_buffer);
 }
 
-static __inline__ void write_comm_pipe_u32 (smp_comm_pipe *p, int data, int no_buffer)
+STATIC_INLINE void write_comm_pipe_u32 (smp_comm_pipe *p, int data, int no_buffer)
 {
     uae_pt foo;
     foo.u32 = data;
     write_comm_pipe_pt (p, foo, no_buffer);
 }
 
-static __inline__ void write_comm_pipe_pvoid (smp_comm_pipe *p, void *data, int no_buffer)
+STATIC_INLINE void write_comm_pipe_pvoid (smp_comm_pipe *p, void *data, int no_buffer)
 {
     uae_pt foo;
     foo.pv = data;
index 6f2348c09bf11fbc96b60374ac876096192584e9..0f12fc0e5654cc99dcbade46f1135857511b9575 100755 (executable)
@@ -58,7 +58,6 @@ extern void init_comp(void);
 extern void flush(int save_regs);
 extern void small_flush(int save_regs);
 extern void set_target(uae_u8* t);
-extern uae_u8* get_target(void);
 extern void freescratch(void);
 extern void build_comp(void);
 extern void set_cache_state(int enabled);
@@ -69,7 +68,6 @@ extern void flush_icache(int n);
 #endif
 extern void alloc_cache(void);
 extern void compile_block(cpu_history* pc_hist, int blocklen, int totcyles);
-extern void lopt_emit_all(void);
 extern int check_for_cache_miss(void);
 
 
@@ -119,9 +117,10 @@ typedef struct {
     uae_u8 is_addx;
     uae_u8 is_const_jump;
 } op_properties;
+
 extern op_properties prop[65536];
 
-static __inline__ int end_block(uae_u16 opcode)
+STATIC_INLINE int end_block(uae_u16 opcode)
 {
     return prop[opcode].is_jump ||
        (prop[opcode].is_const_jump && !currprefs.comp_constjump);
@@ -230,7 +229,7 @@ extern int touchcnt;
 #define MENDFUNC(nargs,func,args)
 #define COMPCALL(func) func
 
-#define LOWFUNC(flags,mem,nargs,func,args) static __inline__ void func args
+#define LOWFUNC(flags,mem,nargs,func,args) STATIC_INLINE void func args
 #define LENDFUNC(flags,mem,nargs,func,args)
 
 #if USE_OPTIMIZER
@@ -334,8 +333,8 @@ DECLARE(lea_l_brr_indexed(W4 d, R4 s, R4 index, IMM factor, IMM offset));
 DECLARE(mov_l_bRr(R4 d, R4 s, IMM offset));
 DECLARE(mov_w_bRr(R4 d, R2 s, IMM offset));
 DECLARE(mov_b_bRr(R4 d, R1 s, IMM offset));
-DECLARE(bswap_32(RW4 r));
-DECLARE(bswap_16(RW2 r));
+DECLARE(gen_bswap_32(RW4 r));
+DECLARE(gen_bswap_16(RW2 r));
 DECLARE(mov_l_rr(W4 d, R4 s));
 DECLARE(mov_l_mr(IMM d, R4 s));
 DECLARE(mov_w_mr(IMM d, R2 s));
@@ -547,3 +546,10 @@ void execute_normal(void);
 void exec_nostats(void);
 void do_nothing(void);
 
+void comp_fdbcc_opp (uae_u32 opcode, uae_u16 extra);
+void comp_fscc_opp (uae_u32 opcode, uae_u16 extra);
+void comp_ftrapcc_opp (uae_u32 opcode, uaecptr oldpc);
+void comp_fbcc_opp (uae_u32 opcode);
+void comp_fsave_opp (uae_u32 opcode);
+void comp_frestore_opp (uae_u32 opcode);
+void comp_fpp_opp (uae_u32 opcode, uae_u16 extra);
index 2025582fec9634d339e665968435e24e4e953734..01cfebc68bfb5977e8999f45e6e8eda5c78666b2 100755 (executable)
@@ -1,14 +1,14 @@
 
-STATIC_INLINE uae_u32 get_word_prefetch (int o)
+STATIC_INLINE uae_u32 get_word_prefetch (struct regstruct *regs, int o)
 {
-    uae_u32 v = regs.irc;
-    regs.irc = get_word (m68k_getpc() + o);
+    uae_u32 v = regs->irc;
+    regs->irc = get_word (m68k_getpc(regs) + o);
     return v;
 }
-STATIC_INLINE uae_u32 get_long_prefetch (int o)
+STATIC_INLINE uae_u32 get_long_prefetch (struct regstruct *regs, int o)
 {
-    uae_u32 v = get_word_prefetch (o) << 16;
-    v |= get_word_prefetch (o + 2);
+    uae_u32 v = get_word_prefetch (regs, o) << 16;
+    v |= get_word_prefetch (regs, o + 2);
     return v;
 }
 
@@ -76,10 +76,10 @@ STATIC_INLINE uae_u32 get_byte_ce (uaecptr addr)
     return mem_access_delay_byte_read (addr);
 }
 
-STATIC_INLINE uae_u32 get_word_ce_prefetch (int o)
+STATIC_INLINE uae_u32 get_word_ce_prefetch (struct regstruct *regs, int o)
 {
-    uae_u32 v = regs.irc;
-    regs.irc = get_word_ce (m68k_getpc() + o);
+    uae_u32 v = regs->irc;
+    regs->irc = get_word_ce (m68k_getpc(regs) + o);
     return v;
 }
 
@@ -102,31 +102,31 @@ STATIC_INLINE void put_byte_ce (uaecptr addr, uae_u8 v)
     mem_access_delay_byte_write (addr, v);
 }
 
-STATIC_INLINE void m68k_do_rts_ce (void)
+STATIC_INLINE void m68k_do_rts_ce (struct regstruct *regs)
 {
     uaecptr pc;
     pc = get_word_ce (m68k_areg (regs, 7)) << 16;
     pc |= get_word_ce (m68k_areg (regs, 7) + 2);
     m68k_areg (regs, 7) += 4;
     if (pc & 1)
-       exception3 (0x4e75, m68k_getpc(), pc);
+       exception3 (0x4e75, m68k_getpc(regs), pc);
     else
-       m68k_setpc (pc);
+       m68k_setpc (regs, pc);
 }
 
-STATIC_INLINE void m68k_do_bsr_ce (uaecptr oldpc, uae_s32 offset)
+STATIC_INLINE void m68k_do_bsr_ce (struct regstruct *regs, uaecptr oldpc, uae_s32 offset)
 {
     m68k_areg (regs, 7) -= 4;
     put_word_ce (m68k_areg (regs, 7), oldpc >> 16);
     put_word_ce (m68k_areg (regs, 7) + 2, oldpc);
-    m68k_incpc (offset);
+    m68k_incpc (regs, offset);
 }
 
-STATIC_INLINE void m68k_do_jsr_ce (uaecptr oldpc, uaecptr dest)
+STATIC_INLINE void m68k_do_jsr_ce (struct regstruct *regs, uaecptr oldpc, uaecptr dest)
 {
     m68k_areg (regs, 7) -= 4;
     put_word_ce (m68k_areg (regs, 7), oldpc >> 16);
     put_word_ce (m68k_areg (regs, 7) + 2, oldpc);
-    m68k_setpc (dest);
+    m68k_setpc (regs, dest);
 }
 #endif
\ No newline at end of file
index 897a95fb004a2680e58ef6fc6ad51588b391b312..98c93083cceaf0807e5d0c443c272168a13bdb02 100755 (executable)
@@ -6,6 +6,8 @@
   * (c) 1995 Bernd Schmidt
   */
 
+#include "machdep/rpt.h"
+
 /* These are the masks that are ORed together in the chipset_mask option.
  * If CSMASK_AGA is set, the ECS bits are guaranteed to be set as well.  */
 #define CSMASK_ECS_AGNUS 1
@@ -14,7 +16,7 @@
 
 uae_u32 get_copper_address(int copno);
 
-extern void custom_init (void);
+extern int custom_init (void);
 extern void customreset (void);
 extern int intlev (void);
 extern void dumpcustom (void);
@@ -101,7 +103,7 @@ extern uae_u16 INTREQR (void);
 
 extern int maxhpos, maxvpos, minfirstline, vblank_endline, numscrlines;
 extern int vblank_hz, fake_vblank_hz, vblank_skip;
-extern unsigned long syncbase;
+extern frame_time_t syncbase;
 #define NUMSCRLINES (maxvpos+1-minfirstline+1)
 
 #define DMA_AUD0      0x0001
index c5c9f35e3ce8d27a40494d0c19636e3cea89b38d..08c6cc2482a524147bbffd3cb07db64ce28e65ed 100755 (executable)
@@ -75,9 +75,14 @@ struct color_entry {
 
 #ifdef AGA
 /* convert 24 bit AGA Amiga RGB to native color */
-/* warning: ugly and works with little-endian cpu's only */
-#define CONVERT_RGB(c) \
+/* warning: this is still ugly, but now works with either byte order */
+#ifdef WORDS_BIGENDIAN
+# define CONVERT_RGB(c) \
+    ( xbluecolors[((uae_u8*)(&c))[3]] | xgreencolors[((uae_u8*)(&c))[2]] | xredcolors[((uae_u8*)(&c))[1]] )
+#else
+# define CONVERT_RGB(c) \
     ( xbluecolors[((uae_u8*)(&c))[0]] | xgreencolors[((uae_u8*)(&c))[1]] | xredcolors[((uae_u8*)(&c))[2]] )
+#endif
 #else
 #define CONVERT_RGB(c) 0
 #endif
@@ -146,7 +151,7 @@ STATIC_INLINE void color_reg_cpy (struct color_entry *dst, struct color_entry *s
 struct color_change {
     int linepos;
     int regno;
-    unsigned long value;
+    unsigned int value;
 };
 
 /* 440 rather than 880, since sprites are always lores.  */
@@ -175,7 +180,12 @@ union sps_union {
     uae_u32 words[2 * MAX_SPR_PIXELS / 4];
 };
 extern union sps_union spixstate;
+
+#ifdef OS_WITHOUT_MEMORY_MANAGEMENT
+extern uae_u16 *spixels;
+#else
 extern uae_u16 spixels[MAX_SPR_PIXELS * 2];
+#endif
 
 /* Way too much... */
 #define MAX_REG_CHANGE ((MAXVPOS + 1) * 2 * MAXHPOS)
index 71b03ce1c6c959781bff0d3ab1dd585cdbc6930f..eef0d8a3e75dd15bebf46fbf84383681cfec8e0c 100755 (executable)
@@ -19,7 +19,7 @@
 extern volatile frame_time_t vsynctime, vsyncmintime;
 extern void reset_frame_rate_hack (void);
 extern int rpt_available;
-extern unsigned long syncbase;
+extern frame_time_t syncbase;
 
 extern void compute_vsynctime (void);
 extern void init_eventtab (void);
index c9ec22a9ad60d79a9b78a43a73f8112d2f77c19b..43d7369658625dae1b55248fb344dd0ae8667a60 100755 (executable)
@@ -27,8 +27,8 @@ struct customData
  8: AGA only
 */
 
-extern struct mem_labels mem_labels[];
-extern struct mem_labels int_labels[];
-extern struct mem_labels trap_labels[];
-extern struct customData custd[];
+extern const struct mem_labels mem_labels[];
+extern const struct mem_labels int_labels[];
+extern const struct mem_labels trap_labels[];
+extern const struct customData custd[];
 
index 42b035d4059463bfa920e24edff8326480e55170..0807ae7b48870c0187e50ba53f30aec190422d1f 100755 (executable)
@@ -13,21 +13,26 @@ extern void a1000_reset (void);
 extern int special_mem;
 #define S_READ 1
 #define S_WRITE 2
-#endif
 
 extern void *cache_alloc (int);
 extern void cache_free (void*);
 
+extern int canbang;
+void init_shm (void);
+#endif
+
 #ifdef ADDRESS_SPACE_24BIT
 #define MEMORY_BANKS 256
+#define MEMORY_RANGE_MASK ((1<<24)-1)
 #else
 #define MEMORY_BANKS 65536
+#define MEMORY_RANGE_MASK (~0)
 #endif
 
-typedef uae_u32 (*mem_get_func)(uaecptr) REGPARAM;
-typedef void (*mem_put_func)(uaecptr, uae_u32) REGPARAM;
-typedef uae_u8 *(*xlate_func)(uaecptr) REGPARAM;
-typedef int (*check_func)(uaecptr, uae_u32) REGPARAM;
+typedef uae_u32 (REGPARAM3 *mem_get_func)(uaecptr) REGPARAM;
+typedef void (REGPARAM3 *mem_put_func)(uaecptr, uae_u32) REGPARAM;
+typedef uae_u8 *(REGPARAM3 *xlate_func)(uaecptr) REGPARAM;
+typedef int (REGPARAM3 *check_func)(uaecptr, uae_u32) REGPARAM;
 
 extern char *address_space, *good_address_map;
 extern uae_u8 *chipmemory;
@@ -109,14 +114,20 @@ extern int address_space_24;
 
 /* Default memory access functions */
 
-extern int default_check(uaecptr addr, uae_u32 size) REGPARAM;
-extern uae_u8 *default_xlate(uaecptr addr) REGPARAM;
+extern int REGPARAM3 default_check(uaecptr addr, uae_u32 size) REGPARAM;
+extern uae_u8 *REGPARAM3 default_xlate(uaecptr addr) REGPARAM;
 
 #define bankindex(addr) (((uaecptr)(addr)) >> 16)
 
 extern addrbank *mem_banks[MEMORY_BANKS];
+
+#ifdef JIT
 extern uae_u8 *baseaddr[MEMORY_BANKS];
+#endif
+
 #define get_mem_bank(addr) (*mem_banks[bankindex(addr)])
+
+#ifdef JIT
 #define put_mem_bank(addr, b, realstart) do { \
     (mem_banks[bankindex(addr)] = (b)); \
     if ((b)->baseaddr) \
@@ -124,14 +135,16 @@ extern uae_u8 *baseaddr[MEMORY_BANKS];
     else \
        baseaddr[bankindex(addr)] = (uae_u8*)(((long)b)+1); \
 } while (0)
+#else
+#define put_mem_bank(addr, b, realstart) \
+    (mem_banks[bankindex(addr)] = (b));
+#endif
 
 extern void memory_init (void);
 extern void memory_cleanup (void);
 extern void map_banks (addrbank *bank, int first, int count, int realsize);
 extern void map_overlay (int chip);
 
-#ifndef NO_INLINE_MEMORY_ACCESS
-
 #define longget(addr) (call_mem_get_func(get_mem_bank(addr).lget, addr))
 #define wordget(addr) (call_mem_get_func(get_mem_bank(addr).wget, addr))
 #define byteget(addr) (call_mem_get_func(get_mem_bank(addr).bget, addr))
@@ -139,55 +152,91 @@ extern void map_overlay (int chip);
 #define wordput(addr,w) (call_mem_put_func(get_mem_bank(addr).wput, addr, w))
 #define byteput(addr,b) (call_mem_put_func(get_mem_bank(addr).bput, addr, b))
 
-#else
-
-extern uae_u32 alongget(uaecptr addr);
-extern uae_u32 awordget(uaecptr addr);
-extern uae_u32 longget(uaecptr addr);
-extern uae_u32 wordget(uaecptr addr);
-extern uae_u32 byteget(uaecptr addr);
-extern void longput(uaecptr addr, uae_u32 l);
-extern void wordput(uaecptr addr, uae_u32 w);
-extern void byteput(uaecptr addr, uae_u32 b);
-
-#endif
-
-#ifndef MD_HAVE_MEM_1_FUNCS
-
-#define longget_1 longget
-#define wordget_1 wordget
-#define byteget_1 byteget
-#define longput_1 longput
-#define wordput_1 wordput
-#define byteput_1 byteput
-
-#endif
-
 STATIC_INLINE uae_u32 get_long(uaecptr addr)
 {
-    return longget_1(addr);
+    return longget(addr);
 }
 STATIC_INLINE uae_u32 get_word(uaecptr addr)
 {
-    return wordget_1(addr);
+    return wordget(addr);
 }
 STATIC_INLINE uae_u32 get_byte(uaecptr addr)
 {
-    return byteget_1(addr);
+    return byteget(addr);
+}
+
+/*
+ * Read a host pointer from addr
+ */
+#if SIZEOF_VOID_P == 4
+# define get_pointer(addr) ((void *)get_long(addr))
+#else
+# if SIZEOF_VOID_P == 8
+STATIC_INLINE void *get_pointer (uaecptr addr)
+{
+    const unsigned int n = SIZEOF_VOID_P / 4;
+    union {
+       void    *ptr;
+       uae_u32  longs[SIZEOF_VOID_P / 4];
+    } p;
+    unsigned int i;
+
+    for (i = 0; i < n; i++) {
+#ifdef WORDS_BIGENDIAN
+       p.longs[i]     = get_long (addr + i * 4);
+#else
+       p.longs[n - 1 - i] = get_long (addr + i * 4);
+#endif
+    }
+    return p.ptr;
 }
+# else
+#  error "Unknown or unsupported pointer size."
+# endif
+#endif
+
 STATIC_INLINE void put_long(uaecptr addr, uae_u32 l)
 {
-    longput_1(addr, l);
+    longput(addr, l);
 }
 STATIC_INLINE void put_word(uaecptr addr, uae_u32 w)
 {
-    wordput_1(addr, w);
+    wordput(addr, w);
 }
 STATIC_INLINE void put_byte(uaecptr addr, uae_u32 b)
 {
-    byteput_1(addr, b);
+    byteput(addr, b);
 }
 
+/*
+ * Store host pointer v at addr
+ */
+#if SIZEOF_VOID_P == 4
+# define put_pointer(addr, p) (put_long((addr), (uae_u32)(p)))
+#else
+# if SIZEOF_VOID_P == 8
+STATIC_INLINE void put_pointer (uaecptr addr, void *v)
+{
+    const unsigned int n = SIZEOF_VOID_P / 4;
+    union {
+       void    *ptr;
+       uae_u32  longs[SIZEOF_VOID_P / 4];
+    } p;
+    unsigned int i;
+
+    p.ptr = v;
+
+    for (i = 0; i < n; i++) {
+#ifdef WORDS_BIGENDIAN
+       put_long (addr + i * 4, p.longs[i]);
+#else
+       put_long (addr + i * 4, p.longs[n - 1 - i]);
+#endif
+    }
+}
+# endif
+#endif
+
 STATIC_INLINE uae_u8 *get_real_address(uaecptr addr)
 {
     return get_mem_bank(addr).xlateaddr(addr);
@@ -199,19 +248,19 @@ STATIC_INLINE int valid_address(uaecptr addr, uae_u32 size)
 }
 
 /* For faster access in custom chip emulation.  */
-extern uae_u32 chipmem_lget (uaecptr) REGPARAM;
-extern uae_u32 chipmem_wget (uaecptr) REGPARAM;
-extern uae_u32 chipmem_bget (uaecptr) REGPARAM;
-extern void chipmem_lput (uaecptr, uae_u32) REGPARAM;
-extern void chipmem_wput (uaecptr, uae_u32) REGPARAM;
-extern void chipmem_bput (uaecptr, uae_u32) REGPARAM;
-
-extern uae_u32 chipmem_agnus_lget (uaecptr) REGPARAM;
-extern uae_u32 chipmem_agnus_wget (uaecptr) REGPARAM;
-extern uae_u32 chipmem_agnus_bget (uaecptr) REGPARAM;
-extern void chipmem_agnus_lput (uaecptr, uae_u32) REGPARAM;
-extern void chipmem_agnus_wput (uaecptr, uae_u32) REGPARAM;
-extern void chipmem_agnus_bput (uaecptr, uae_u32) REGPARAM;
+extern uae_u32 REGPARAM3 chipmem_lget (uaecptr) REGPARAM;
+extern uae_u32 REGPARAM3 chipmem_wget (uaecptr) REGPARAM;
+extern uae_u32 REGPARAM3 chipmem_bget (uaecptr) REGPARAM;
+extern void REGPARAM3 chipmem_lput (uaecptr, uae_u32) REGPARAM;
+extern void REGPARAM3 chipmem_wput (uaecptr, uae_u32) REGPARAM;
+extern void REGPARAM3 chipmem_bput (uaecptr, uae_u32) REGPARAM;
+
+extern uae_u32 REGPARAM3 chipmem_agnus_lget (uaecptr) REGPARAM;
+extern uae_u32 REGPARAM3 chipmem_agnus_wget (uaecptr) REGPARAM;
+extern uae_u32 REGPARAM3 chipmem_agnus_bget (uaecptr) REGPARAM;
+extern void REGPARAM3 chipmem_agnus_lput (uaecptr, uae_u32) REGPARAM;
+extern void REGPARAM3 chipmem_agnus_wput (uaecptr, uae_u32) REGPARAM;
+extern void REGPARAM3 chipmem_agnus_bput (uaecptr, uae_u32) REGPARAM;
 
 extern uae_u32 chipmem_mask, kickmem_mask;
 extern uae_u8 *kickmemory;
@@ -219,12 +268,12 @@ extern int kickmem_size;
 extern addrbank dummy_bank;
 
 /* 68020+ Chip RAM DMA contention emulation */
-extern uae_u32 chipmem_lget_ce2 (uaecptr) REGPARAM;
-extern uae_u32 chipmem_wget_ce2 (uaecptr) REGPARAM;
-extern uae_u32 chipmem_bget_ce2 (uaecptr) REGPARAM;
-extern void chipmem_lput_ce2 (uaecptr, uae_u32) REGPARAM;
-extern void chipmem_wput_ce2 (uaecptr, uae_u32) REGPARAM;
-extern void chipmem_bput_c2 (uaecptr, uae_u32) REGPARAM;
+extern uae_u32 REGPARAM3 chipmem_lget_ce2 (uaecptr) REGPARAM;
+extern uae_u32 REGPARAM3 chipmem_wget_ce2 (uaecptr) REGPARAM;
+extern uae_u32 REGPARAM3 chipmem_bget_ce2 (uaecptr) REGPARAM;
+extern void REGPARAM3 chipmem_lput_ce2 (uaecptr, uae_u32) REGPARAM;
+extern void REGPARAM3 chipmem_wput_ce2 (uaecptr, uae_u32) REGPARAM;
+extern void REGPARAM3 chipmem_bput_c2 (uaecptr, uae_u32) REGPARAM;
 
 #ifdef NATMEM_OFFSET
 
@@ -240,8 +289,6 @@ extern shmpiece *shm_start;
 
 #endif
 
-extern int canbang;
-
 extern uae_u8 *mapped_malloc (size_t, char *);
 extern void mapped_free (uae_u8 *);
 extern void clearexec (void);
index 606e0f8a30d13c5d4c9da4be4f23e291d5fd8936..a2f8cdc00d9fbeaa26ce81df584a77d4ef0750db 100755 (executable)
@@ -31,8 +31,8 @@ void uae_NewList(uaecptr list);
  * function has to be setup with deftrap2() and
  * TRAPFLAG_EXTRA_STACK and stack magic is required.
  */
-uaecptr uae_AllocMem (uae_u32 size, uae_u32 flags);
-void uae_FreeMem (uaecptr memory, uae_u32 size);
+uaecptr uae_AllocMem (TrapContext *context, uae_u32 size, uae_u32 flags);
+void uae_FreeMem (TrapContext *context, uaecptr memory, uae_u32 size);
 
 
 /*
@@ -55,9 +55,9 @@ void native2amiga_startup (void);
 extern smp_comm_pipe native2amiga_pending;
 #endif
 
-STATIC_INLINE do_uae_int_requested(void)
+STATIC_INLINE void do_uae_int_requested (void)
 {
-       uae_int_requested = 1;
-       set_uae_int_flag ();
-       INTREQ (0x8000 | 0x0008);
+    uae_int_requested = 1;
+    set_uae_int_flag ();
+    INTREQ (0x8000 | 0x0008);
 }
index e78ddaa019ee0965998e583f831b555e5352a434..e0d9082ab4cc12621b7c7f37c7462ff4c68dfbbd 100755 (executable)
 
 #ifndef SET_CFLG
 
-#define SET_CFLG(x) (CFLG = (x))
-#define SET_NFLG(x) (NFLG = (x))
-#define SET_VFLG(x) (VFLG = (x))
-#define SET_ZFLG(x) (ZFLG = (x))
-#define SET_XFLG(x) (XFLG = (x))
-
-#define GET_CFLG CFLG
-#define GET_NFLG NFLG
-#define GET_VFLG VFLG
-#define GET_ZFLG ZFLG
-#define GET_XFLG XFLG
-
-#define CLEAR_CZNV do { \
- SET_CFLG (0); \
- SET_ZFLG (0); \
- SET_NFLG (0); \
- SET_VFLG (0); \
+#define SET_CFLG(regs, x) (CFLG(regs) = (x))
+#define SET_NFLG(regs, x) (NFLG(regs) = (x))
+#define SET_VFLG(regs, x) (VFLG(regs) = (x))
+#define SET_ZFLG(regs, x) (ZFLG(regs) = (x))
+#define SET_XFLG(regs, x) (XFLG(regs) = (x))
+
+#define GET_CFLG(regs) CFLG(regs)
+#define GET_NFLG(regs) NFLG(regs)
+#define GET_VFLG(regs) VFLG(regs)
+#define GET_ZFLG(regs) ZFLG(regs)
+#define GET_XFLG(regs) XFLG(regs)
+
+#define CLEAR_CZNV(regs) do { \
+ SET_CFLG (regs, 0); \
+ SET_ZFLG (regs, 0); \
+ SET_NFLG (regs, 0); \
+ SET_VFLG (regs, 0); \
 } while (0)
 
-#define COPY_CARRY (SET_XFLG (GET_CFLG))
+#define COPY_CARRY(regs) (SET_XFLG (regs, GET_CFLG (regs)))
 #endif
 
-extern int areg_byteinc[];
-extern int imm8_table[];
+extern const int areg_byteinc[];
+extern const int imm8_table[];
 
 extern int movem_index1[256];
 extern int movem_index2[256];
@@ -47,20 +47,27 @@ extern int fpp_movem_index2[256];
 extern int fpp_movem_next[256];
 #endif
 
-typedef unsigned long cpuop_func (uae_u32) REGPARAM;
-typedef void cpuop_func_ce (uae_u32) REGPARAM;
+struct regstruct;
+
+typedef unsigned long REGPARAM3 cpuop_func (uae_u32, struct regstruct *regs) REGPARAM;
+typedef void REGPARAM3 cpuop_func_ce (uae_u32, struct regstruct *regs) REGPARAM;
 
 struct cputbl {
     cpuop_func *handler;
-#ifndef JIT
     uae_u16 opcode;
-#else
+};
+
+#ifdef JIT
+typedef unsigned long REGPARAM3 compop_func (uae_u32) REGPARAM;
+
+struct comptbl {
+    compop_func *handler;
     uae_u32 opcode;
     int specific;
-#endif
 };
+#endif
 
-extern unsigned long op_illg (uae_u32) REGPARAM;
+extern unsigned long REGPARAM3 op_illg (uae_u32, struct regstruct *regs) REGPARAM;
 
 typedef char flagtype;
 
@@ -82,7 +89,13 @@ typedef double fptype;
 extern struct regstruct
 {
     uae_u32 regs[16];
-    uaecptr usp,isp,msp;
+    struct flag_struct ccrflags;
+
+    uae_u32 pc;
+    uae_u8 *pc_p;
+    uae_u8 *pc_oldp;
+
+    uaecptr usp, isp, msp;
     uae_u16 sr;
     flagtype t1;
     flagtype t0;
@@ -92,17 +105,13 @@ extern struct regstruct
     flagtype stopped;
     int intmask;
 
-    uae_u32 pc;
-    uae_u8 *pc_p;
-    uae_u8 *pc_oldp;
-
     uae_u32 vbr,sfc,dfc;
 
 #ifdef FPUEMU
     fptype fp[8];
     fptype fp_result;
 
-    uae_u32 fpcr,fpsr,fpiar;
+    uae_u32 fpcr,fpsr, fpiar;
     uae_u32 fpsr_highbyte;
 #endif
 
@@ -143,104 +152,103 @@ extern unsigned long irqcycles[15];
 extern int irqdelay[15];
 extern int mmu_enabled, mmu_triggered;
 
-STATIC_INLINE void set_special (uae_u32 x)
+STATIC_INLINE void set_special (struct regstruct *regs, uae_u32 x)
 {
-    regs.spcflags |= x;
+    regs->spcflags |= x;
     cycles_do_special();
 }
 
-STATIC_INLINE void unset_special (uae_u32 x)
+STATIC_INLINE void unset_special (struct regstruct *regs, uae_u32 x)
 {
-    regs.spcflags &= ~x;
+    regs->spcflags &= ~x;
 }
 
-#define m68k_dreg(r,num) ((r).regs[(num)])
-#define m68k_areg(r,num) (((r).regs + 8)[(num)])
+#define m68k_dreg(r,num) ((r)->regs[(num)])
+#define m68k_areg(r,num) (((r)->regs + 8)[(num)])
 
-STATIC_INLINE void m68k_setpc (uaecptr newpc)
+STATIC_INLINE void m68k_setpc (struct regstruct *regs, uaecptr newpc)
 {
-    regs.pc_p = regs.pc_oldp = get_real_address (newpc);
-    regs.pc = newpc;
+    regs->pc_p = regs->pc_oldp = get_real_address (newpc);
+    regs->pc = newpc;
 }
 
-STATIC_INLINE uaecptr m68k_getpc (void)
+STATIC_INLINE uaecptr m68k_getpc (struct regstruct *regs)
 {
-    return regs.pc + (uaecptr)(((char *)regs.pc_p - (char *)regs.pc_oldp));
+    return regs->pc + ((char *)regs->pc_p - (char *)regs->pc_oldp);
 }
+#define M68K_GETPC m68k_getpc(&regs)
 
-STATIC_INLINE uaecptr m68k_getpc_p (uae_u8 *p)
+STATIC_INLINE uaecptr m68k_getpc_p (struct regstruct *regs, uae_u8 *p)
 {
-    return regs.pc + (uaecptr)(((char *)p - (char *)regs.pc_oldp));
+    return regs->pc + ((char *)p - (char *)regs->pc_oldp);
 }
 
-#define get_ibyte(o) do_get_mem_byte((uae_u8 *)(regs.pc_p + (o) + 1))
-#define get_iword(o) do_get_mem_word((uae_u16 *)(regs.pc_p + (o)))
-#define get_ilong(o) do_get_mem_long((uae_u32 *)(regs.pc_p + (o)))
+#define get_ibyte(regs, o) do_get_mem_byte((uae_u8 *)((regs)->pc_p + (o) + 1))
+#define get_iword(regs, o) do_get_mem_word((uae_u16 *)((regs)->pc_p + (o)))
+#define get_ilong(regs, o) do_get_mem_long((uae_u32 *)((regs)->pc_p + (o)))
 
-#define m68k_incpc(o) (regs.pc_p += (o))
+#define m68k_incpc(regs, o) ((regs)->pc_p += (o))
 
 /* These are only used by the 68020/68881 code, and therefore don't
  * need to handle prefetch.  */
-STATIC_INLINE uae_u32 next_ibyte (void)
+STATIC_INLINE uae_u32 next_ibyte (struct regstruct *regs)
 {
-    uae_u32 r = get_ibyte (0);
-    m68k_incpc (2);
+    uae_u32 r = get_ibyte (regs, 0);
+    m68k_incpc (regs, 2);
     return r;
 }
 
-STATIC_INLINE uae_u32 next_iword (void)
+STATIC_INLINE uae_u32 next_iword (struct regstruct *regs)
 {
-    uae_u32 r = get_iword (0);
-    m68k_incpc (2);
+    uae_u32 r = get_iword (regs, 0);
+    m68k_incpc (regs, 2);
     return r;
 }
 
-STATIC_INLINE uae_u32 next_ilong (void)
+STATIC_INLINE uae_u32 next_ilong (struct regstruct *regs)
 {
-    uae_u32 r = get_ilong (0);
-    m68k_incpc (4);
+    uae_u32 r = get_ilong (regs, 0);
+    m68k_incpc (regs, 4);
     return r;
 }
 
-STATIC_INLINE void m68k_do_rts(void)
+STATIC_INLINE void m68k_do_rts(struct regstruct *regs)
 {
-    m68k_setpc(get_long(m68k_areg(regs, 7)));
+    m68k_setpc(regs, get_long(m68k_areg(regs, 7)));
     m68k_areg(regs, 7) += 4;
 }
 
-STATIC_INLINE void m68k_do_bsr(uaecptr oldpc, uae_s32 offset)
+STATIC_INLINE void m68k_do_bsr(struct regstruct *regs, uaecptr oldpc, uae_s32 offset)
 {
     m68k_areg(regs, 7) -= 4;
     put_long(m68k_areg(regs, 7), oldpc);
-    m68k_incpc(offset);
+    m68k_incpc(regs, offset);
 }
 
-STATIC_INLINE void m68k_do_jsr(uaecptr oldpc, uaecptr dest)
+STATIC_INLINE void m68k_do_jsr(struct regstruct *regs, uaecptr oldpc, uaecptr dest)
 {
     m68k_areg(regs, 7) -= 4;
     put_long(m68k_areg(regs, 7), oldpc);
-    m68k_setpc(dest);
+    m68k_setpc(regs, dest);
 }
 
-#define m68k_setpc_fast m68k_setpc
-#define m68k_setpc_bcc  m68k_setpc
-#define m68k_setpc_rte  m68k_setpc
-
-STATIC_INLINE void m68k_setstopped (int stop)
+STATIC_INLINE void m68k_setstopped (struct regstruct *regs, int stop)
 {
-    regs.stopped = stop;
+    regs->stopped = stop;
     /* A traced STOP instruction drops through immediately without
        actually stopping.  */
-    if (stop && (regs.spcflags & SPCFLAG_DOTRACE) == 0)
-       set_special (SPCFLAG_STOP);
+    if (stop && (regs->spcflags & SPCFLAG_DOTRACE) == 0)
+       set_special (regs, SPCFLAG_STOP);
 }
 
-extern uae_u32 get_disp_ea_020 (uae_u32 base, uae_u32 dp);
-extern uae_u32 get_disp_ea_000 (uae_u32 base, uae_u32 dp);
+extern uae_u32 REGPARAM3 get_disp_ea_020 (struct regstruct *regs, uae_u32 base, uae_u32 dp) REGPARAM;
+extern uae_u32 REGPARAM3 get_disp_ea_000 (struct regstruct *regs, uae_u32 base, uae_u32 dp) REGPARAM;
+extern void m68k_disasm_ea (void *f, uaecptr addr, uaecptr *nextpc, int cnt, uae_u32 *seaddr, uae_u32 *deaddr);
+extern void m68k_disasm (void *f, uaecptr addr, uaecptr *nextpc, int cnt);
 
-extern void MakeSR (void);
-extern void MakeFromSR (void);
-extern void Exception (int, uaecptr);
+extern void REGPARAM3 MakeSR (struct regstruct *regs) REGPARAM;
+extern void REGPARAM3 MakeFromSR (struct regstruct *regs) REGPARAM;
+extern void REGPARAM3 Exception (int, struct regstruct *regs, uaecptr) REGPARAM;
 extern void Interrupt (int nr);
 extern void dump_counts (void);
 extern int m68k_move2c (int, uae_u32 *);
@@ -252,45 +260,45 @@ extern void init_m68k_full (void);
 extern void m68k_go (int);
 extern void m68k_dumpstate (void *, uaecptr *);
 extern void m68k_disasm (void *, uaecptr, uaecptr *, int);
-extern void m68k_disasm_ea (void *, uaecptr, uaecptr *, int, uaecptr *, uaecptr *);
 extern void sm68k_disasm(char *, char *, uaecptr addr, uaecptr *nextpc);
 extern void m68k_reset (void);
 extern int getDivu68kCycles(uae_u32 dividend, uae_u16 divisor);
 extern int getDivs68kCycles(uae_s32 dividend, uae_s16 divisor);
 
-extern void mmu_op (uae_u32, uae_u16);
+extern void mmu_op       (uae_u32, struct regstruct *regs, uae_u16);
 
-extern void fpp_opp (uae_u32, uae_u16);
-extern void fdbcc_opp (uae_u32, uae_u16);
-extern void fscc_opp (uae_u32, uae_u16);
-extern void ftrapcc_opp (uae_u32,uaecptr);
-extern void fbcc_opp (uae_u32, uaecptr, uae_u32);
-extern void fsave_opp (uae_u32);
-extern void frestore_opp (uae_u32);
+extern void fpp_opp      (uae_u32, struct regstruct *regs, uae_u16);
+extern void fdbcc_opp    (uae_u32, struct regstruct *regs, uae_u16);
+extern void fscc_opp     (uae_u32, struct regstruct *regs, uae_u16);
+extern void ftrapcc_opp  (uae_u32, struct regstruct *regs, uaecptr);
+extern void fbcc_opp     (uae_u32, struct regstruct *regs, uaecptr, uae_u32);
+extern void fsave_opp    (uae_u32, struct regstruct *regs);
+extern void frestore_opp (uae_u32, struct regstruct *regs);
+extern uae_u32 fpp_get_fpsr (const struct regstruct *regs);
 
 extern void exception3 (uae_u32 opcode, uaecptr addr, uaecptr fault);
 extern void exception3i (uae_u32 opcode, uaecptr addr, uaecptr fault);
 extern void exception2 (uaecptr addr, uaecptr fault);
 extern void cpureset (void);
 
-extern void fill_prefetch_slow (void);
+extern void fill_prefetch_slow (struct regstruct *regs);
 
 #define CPU_OP_NAME(a) op ## a
 
 /* 68040 */
-extern struct cputbl op_smalltbl_0_ff[];
+extern const struct cputbl op_smalltbl_0_ff[];
 /* 68020 + 68881 */
-extern struct cputbl op_smalltbl_1_ff[];
+extern const struct cputbl op_smalltbl_1_ff[];
 /* 68020 */
-extern struct cputbl op_smalltbl_2_ff[];
+extern const struct cputbl op_smalltbl_2_ff[];
 /* 68010 */
-extern struct cputbl op_smalltbl_3_ff[];
+extern const struct cputbl op_smalltbl_3_ff[];
 /* 68000 */
-extern struct cputbl op_smalltbl_4_ff[];
+extern const struct cputbl op_smalltbl_4_ff[];
 /* 68000 slow but compatible.  */
-extern struct cputbl op_smalltbl_5_ff[];
+extern const struct cputbl op_smalltbl_5_ff[];
 /* 68000 slow but compatible and cycle-exact.  */
-extern struct cputbl op_smalltbl_6_ff[];
+extern const struct cputbl op_smalltbl_6_ff[];
 
 extern cpuop_func *cpufunctbl[65536] ASM_SYM_FOR_FUNC ("cpufunctbl");
 
index bff8e7f2788c667044405a1ea8c2a09c78a36f74..d045b9109a14992ee018b7c7c17ab21c83f834a0 100755 (executable)
@@ -8,8 +8,8 @@
   */
 
 #define UAEMAJOR 1
-#define UAEMINOR 3
-#define UAESUBREV 2
+#define UAEMINOR 4
+#define UAESUBREV 0
 
 typedef enum { KBD_LANG_US, KBD_LANG_DK, KBD_LANG_DE, KBD_LANG_SE, KBD_LANG_FR, KBD_LANG_IT, KBD_LANG_ES } KbdLang;
 
index bfa5ffe87f6c1f219a26f77592d98dcf6255ebe6..6394e2af83b4f0aa752ee7635051e8bf2e4a3af1 100755 (executable)
@@ -83,12 +83,12 @@ extern uae_u8 *save_keyboard (int *);
 extern uae_u8 *restore_filesys (uae_u8 *src);
 extern uae_u8 *save_filesys (int num, int *len);
 
-extern void restore_cram (int, long);
-extern void restore_bram (int, long);
-extern void restore_fram (int, long);
-extern void restore_zram (int, long);
-extern void restore_pram (int, long);
-extern void restore_ram (long, uae_u8*);
+extern void restore_cram (int, size_t);
+extern void restore_bram (int, size_t);
+extern void restore_fram (int, size_t);
+extern void restore_zram (int, size_t);
+extern void restore_pram (int, size_t);
+extern void restore_ram (size_t, uae_u8*);
 
 extern uae_u8 *save_cram (int *);
 extern uae_u8 *save_bram (int *);
index f2083276139fa1f65eb65ec2ce479876ed02d03c..0eb8834f6a2280742a0e97f5b2bcad51717f18eb 100755 (executable)
@@ -10,6 +10,7 @@
 extern void serial_init(void);
 extern void serial_exit(void);
 extern void serial_dtr_off(void);
+extern void serial_dtr_on (void);
 
 extern uae_u16 SERDATR(void);
 extern int   SERDATS(void);
index de324ab2c373b0a7acd1faa31b00a2f10d8910e2..63a416661055ba2913400321d5ff16111fd47bda 100755 (executable)
@@ -295,6 +295,11 @@ extern void gettimeofday( struct timeval *tv, void *blah );
 #define FILEFLAG_SCRIPT  0x20
 #define FILEFLAG_PURE    0x40
 
+#ifdef REGPARAM2
+#undef REGPARAM2
+#endif
+#define REGPARAM2 __fastcall
+#define REGPARAM3 __fastcall
 #define REGPARAM
 
 #include <io.h>
@@ -497,3 +502,26 @@ extern void logging_init(void);
  * Best to leave this as it is.
  */
 #define CPU_EMU_SIZE 0
+
+/*
+ * Byte-swapping functions
+ */
+
+/* Try to use system bswap_16/bswap_32 functions. */
+#if defined HAVE_BSWAP_16 && defined HAVE_BSWAP_32
+# include <byteswap.h>
+#  ifdef HAVE_BYTESWAP_H
+#  include <byteswap.h>
+# endif
+#else
+/* Else, if using SDL, try SDL's endian functions. */
+# ifdef USE_SDL
+#  include <SDL_endian.h>
+#  define bswap_16(x) SDL_Swap16(x)
+#  define bswap_32(x) SDL_Swap32(x)
+# else
+/* Otherwise, we'll roll our own. */
+#  define bswap_16(x) (((x) >> 8) | (((x) & 0xFF) << 8))
+#  define bswap_32(x) (((x) << 24) | (((x) << 8) & 0x00FF0000) | (((x) >> 8) & 0x0000FF00) | ((x) >> 24))
+# endif
+#endif
diff --git a/include/traps.h b/include/traps.h
new file mode 100755 (executable)
index 0000000..f703803
--- /dev/null
@@ -0,0 +1,54 @@
+ /*
+  * E-UAE - The portable Amiga Emulator
+  *
+  * Support for traps
+  *
+  * Copyright Richard Drummond 2005
+  *
+  * Based on code:
+  * Copyright 1995, 1996 Bernd Schmidt
+  * Copyright 1996 Ed Hanway
+  */
+
+#ifndef TRAPS_H
+#define TRAPS_H
+
+/*
+ * Data passed to a trap handler
+ */
+typedef struct TrapContext
+{
+    struct regstruct regs;
+} TrapContext;
+
+
+#define TRAPFLAG_NO_REGSAVE  1
+#define TRAPFLAG_NO_RETVAL   2
+#define TRAPFLAG_EXTRA_STACK 4
+#define TRAPFLAG_DORET       8
+
+/*
+ * A function which handles a 68k trap
+ */
+typedef uae_u32 (REGPARAM3 *TrapHandler) (TrapContext *) REGPARAM;
+
+
+/*
+ * Interface with 68k interpreter
+ */
+extern void REGPARAM3 m68k_handle_trap (unsigned int trap_num, struct regstruct *) REGPARAM;
+
+unsigned int define_trap (TrapHandler handler_func, int flags, const char *name);
+
+/*
+ * Call a 68k Library function from an extended trap
+ */
+extern uae_u32 CallLib (TrapContext *context, uaecptr library_base, uae_s16 func_offset);
+
+/*
+ * Initialization
+ */
+void init_traps (void);
+void init_extended_traps (void);
+
+#endif
index e43e8cffb42fcef91a912bb200f722ac890a2e70..e85b42ace5cda050b611fa150d993f09abba44df 100755 (executable)
@@ -16,6 +16,6 @@ struct uae_xcmd {
 #define UAEEXE_NOMEM       2
 
 extern void uaeexe_install(void);
-extern int  uaeexe(char *cmd);
+extern int  uaeexe(const char *cmd);
 
 
index f7c67ee17aefa973ee98224d792eca45817ee55a..f1081293a0c2174609a61d862e0721cb2b189e12 100755 (executable)
@@ -6,7 +6,7 @@
   * Copyright 1995-1997 Bernd Schmidt
   */
 
-typedef long int xcolnr;
+typedef uae_u32 xcolnr;
 
 typedef int (*allocfunc_type)(int, int, int, xcolnr *);
 
@@ -35,11 +35,11 @@ extern void screenshot (int,int);
 
 extern int bits_in_mask (unsigned long mask);
 extern int mask_shift (unsigned long mask);
-extern unsigned long doMask (int p, int bits, int shift);
-extern unsigned long doMask256 (int p, int bits, int shift);
+extern unsigned int doMask (int p, int bits, int shift);
+extern unsigned int doMask256 (int p, int bits, int shift);
 extern void setup_maxcol (int);
 extern void alloc_colors256 (int (*)(int, int, int, xcolnr *));
-extern void alloc_colors64k (int, int, int, int, int, int, int, int, int);
+extern void alloc_colors64k (int, int, int, int, int, int, int, int, int, int);
 extern void setup_greydither (int bits, allocfunc_type allocfunc);
 extern void setup_greydither_maxcol (int maxcol, allocfunc_type allocfunc);
 extern void setup_dither (int bits, allocfunc_type allocfunc);
@@ -47,6 +47,14 @@ extern void DitherLine (uae_u8 *l, uae_u16 *r4g4b4, int x, int y, uae_s16 len, i
 
 struct vidbuf_description
 {
+    /* Function implemented by graphics driver */
+    void (*flush_line)         (struct vidbuf_description *gfxinfo, int line_no);
+    void (*flush_block)        (struct vidbuf_description *gfxinfo, int first_line, int end_line);
+    void (*flush_screen)       (struct vidbuf_description *gfxinfo, int first_line, int end_line);
+    void (*flush_clear_screen) (struct vidbuf_description *gfxinfo);
+    int  (*lockscr)            (struct vidbuf_description *gfxinfo);
+    void (*unlockscr)          (struct vidbuf_description *gfxinfo);
+
     /* The graphics code has a choice whether it wants to use a large buffer
      * for the whole display, or only a small buffer for a single line.
      * If you use a large buffer:
index 99c4de6a1155df3dc2b575b01c24c0bb937ce538..67d64a81e11761ec21aa16e0f663172701812579 100755 (executable)
@@ -21,7 +21,6 @@
 #include "sysconfig.h"
 #include "sysdeps.h"
 
-#include "config.h"
 #include "options.h"
 #include "keyboard.h"
 #include "inputdevice.h"
@@ -55,8 +54,8 @@ static int potgo_logging = 0;
 #define DIR_DOWN 8
 
 struct inputevent {
-    char *confname;
-    char *name;
+    const char *confname;
+    const char *name;
     int allow_mask;
     int type;
     int unit;
@@ -1147,7 +1146,7 @@ void POTGO (uae_u16 v)
     int i;
 
     if (potgo_logging)
-       write_log ("W:%d: %04.4X %p\n", vpos, v, m68k_getpc());
+       write_log ("W:%d: %04.4X %p\n", vpos, v, M68K_GETPC);
 #ifdef DONGLE_DEBUG
     if (notinrom ())
        write_log ("POTGO %04.4X %s\n", v, debuginfo(0));
@@ -1184,7 +1183,7 @@ uae_u16 POTGOR (void)
        write_log ("POTGOR %04.4X %s\n", v, debuginfo(0));
 #endif
     if (potgo_logging)
-       write_log("R:%d:%04.4X %d %p\n", vpos, v, cd32_shifter[1], m68k_getpc());
+       write_log("R:%d:%04.4X %d %p\n", vpos, v, cd32_shifter[1], M68K_GETPC);
     return v;
 }
 
index feaa5f93c00ae06773faf1941541afe1d2050062..6ef67f9eea3c0a54fd7363427869136f20d62629 100755 (executable)
--- a/keybuf.c
+++ b/keybuf.c
@@ -16,7 +16,6 @@
 #include "sysdeps.h"
 #include <assert.h>
 
-#include "config.h"
 #include "options.h"
 #include "keybuf.h"
 #include "keyboard.h"
 
 static int fakestate[2][7] = { {0},{0} };
 
-static int *fs_np, *fs_ck, *fs_se, *fs_xa1, *fs_xa2;
+static int *fs_np, *fs_ck, *fs_se;
+#ifdef ARCADIA
+static int *fs_xa1, *fs_xa2;
+#endif
 
 /* Not static so the DOS code can mess with them */
 int kpb_first, kpb_last;
@@ -101,14 +103,15 @@ void record_key_direct (int kc)
     }
     if (fs_se != 0) {
        switch (k) {
-       case AK_T: fs = 1; fs_se[0] = b; break;
-       case AK_F: fs = 1; fs_se[1] = b; break;
-       case AK_H: fs = 1; fs_se[2] = b; break;
-       case AK_B: fs = 1; fs_se[3] = b; break;
+       case AK_W: fs = 1; fs_se[0] = b; break;
+       case AK_A: fs = 1; fs_se[1] = b; break;
+       case AK_D: fs = 1; fs_se[2] = b; break;
+       case AK_S: fs = 1; fs_se[3] = b; break;
        case AK_LALT: fs = 1; fs_se[4] = b; break;
        case AK_LSH: fs = 1; fs_se[5] = b; break;
        }
     }
+#ifdef ARCADIA
     if (fs_xa1 != 0) {
        switch (k) {
        case AK_NP8: fs = 1; fs_xa1[0] = b; break;
@@ -131,7 +134,7 @@ void record_key_direct (int kc)
        case AK_Q: fs = 1; fs_xa2[6] = b; break;
        }
     }
-
+#endif
     if (fs && currprefs.input_selected_setting == 0) {
        if (JSEM_ISANYKBD (0, &currprefs))
            do_fake (0);
@@ -143,6 +146,7 @@ void record_key_direct (int kc)
            kc ^= AK_RCTRL << 1;
            kc ^= AK_CTRL << 1;
        }
+#ifdef ARCADIA
        if (fs_xa1 || fs_xa2) {
            int k2 = k;
            if (k == AK_1)
@@ -170,6 +174,7 @@ void record_key_direct (int kc)
            if (k != k2)
                kc = (k2 << 1) | (b ? 0 : 1);
        }
+#endif
     }
 
     if (input_recording > 0) {
@@ -184,7 +189,10 @@ void record_key_direct (int kc)
 
 void joystick_setting_changed (void)
 {
-    fs_np = fs_ck = fs_se = fs_xa1 = fs_xa2 = 0;
+    fs_np = fs_ck = fs_se;
+#ifdef ARCADIA 
+    fs_xa1 = fs_xa2 = 0;
+#endif
 
     if (JSEM_ISNUMPAD (0, &currprefs))
        fs_np = fakestate[0];
@@ -201,6 +209,7 @@ void joystick_setting_changed (void)
     else if (JSEM_ISSOMEWHEREELSE (1, &currprefs))
        fs_se = fakestate[1];
 
+#ifdef ARCADIA 
     if (JSEM_ISXARCADE1 (0, &currprefs))
        fs_xa1 = fakestate[0];
     else if (JSEM_ISXARCADE1 (1, &currprefs))
@@ -210,7 +219,7 @@ void joystick_setting_changed (void)
        fs_xa2 = fakestate[0];
     else if (JSEM_ISXARCADE2 (1, &currprefs))
        fs_xa2 = fakestate[1];
-
+#endif
  }
 
 void keybuf_init (void)
@@ -219,6 +228,7 @@ void keybuf_init (void)
     inputdevice_updateconfig (&currprefs);
 }
 
+#ifdef SAVESTATE
 
 uae_u8 *save_keyboard (int *len)
 {
@@ -236,3 +246,5 @@ uae_u8 *restore_keyboard (uae_u8 *src)
     restore_u32 ();
     return src;
 }
+
+#endif /* SAVESTATE */
diff --git a/main.c b/main.c
index 2315c5c22f306717fbd11981348c14deb4bbc97a..4d32883862f1254facae329b8f5fe758c1528656 100755 (executable)
--- a/main.c
+++ b/main.c
@@ -10,7 +10,6 @@
 #include "sysdeps.h"
 #include <assert.h>
 
-#include "config.h"
 #include "options.h"
 #include "threaddep/thread.h"
 #include "uae.h"
@@ -30,8 +29,8 @@
 #include "gui.h"
 #include "zfile.h"
 #include "autoconf.h"
+#include "traps.h"
 #include "osemu.h"
-#include "osdep/exectasks.h"
 #include "picasso96.h"
 #include "bsdsocket.h"
 #include "uaeexe.h"
@@ -685,8 +684,8 @@ static void real_main2 (int argc, char **argv)
     }
 
     }
-#if defined (JIT) && (defined( _WIN32 ) || defined(_WIN64)) && !defined( NO_WIN32_EXCEPTION_HANDLER )
-    __except( EvalException( GetExceptionInformation(), GetExceptionCode() ) )
+#if defined (JIT) && (defined( _WIN32 ) || defined(_WIN64)) && !defined(NO_WIN32_EXCEPTION_HANDLER)
+    __except(EvalException(GetExceptionInformation(), GetExceptionCode()))
     {
        // EvalException does the good stuff...
     }
index b6b26e99429ed220ae2e721b3beb235178188815..a3a47440eb7287508e3d853e2ccf5bfc0c0e64fb 100755 (executable)
--- a/memory.c
+++ b/memory.c
@@ -9,7 +9,6 @@
 #include "sysconfig.h"
 #include "sysdeps.h"
 
-#include "config.h"
 #include "options.h"
 #include "uae.h"
 #include "memory.h"
@@ -49,9 +48,9 @@ uae_u32 max_z3fastmem = 2048UL * 1024 * 1024;
 uae_u32 max_z3fastmem = 512 * 1024 * 1024;
 #endif
 
-static long chip_filepos;
-static long bogo_filepos;
-static long rom_filepos;
+static size_t chip_filepos;
+static size_t bogo_filepos;
+static size_t rom_filepos;
 
 static struct romlist *rl;
 static int romlist_cnt;
@@ -492,13 +491,13 @@ uae_u32 kickmem_mask, extendedkickmem_mask, bogomem_mask, a3000mem_mask;
 static int illegal_count;
 /* A dummy bank that only contains zeros */
 
-static uae_u32 dummy_lget (uaecptr) REGPARAM;
-static uae_u32 dummy_wget (uaecptr) REGPARAM;
-static uae_u32 dummy_bget (uaecptr) REGPARAM;
-static void dummy_lput (uaecptr, uae_u32) REGPARAM;
-static void dummy_wput (uaecptr, uae_u32) REGPARAM;
-static void dummy_bput (uaecptr, uae_u32) REGPARAM;
-static int dummy_check (uaecptr addr, uae_u32 size) REGPARAM;
+static uae_u32 REGPARAM3 dummy_lget (uaecptr) REGPARAM;
+static uae_u32 REGPARAM3 dummy_wget (uaecptr) REGPARAM;
+static uae_u32 REGPARAM3 dummy_bget (uaecptr) REGPARAM;
+static void REGPARAM3 dummy_lput (uaecptr, uae_u32) REGPARAM;
+static void REGPARAM3 dummy_wput (uaecptr, uae_u32) REGPARAM;
+static void REGPARAM3 dummy_bput (uaecptr, uae_u32) REGPARAM;
+static int REGPARAM3 dummy_check (uaecptr addr, uae_u32 size) REGPARAM;
 
 #define        MAX_ILG 200
 #define NONEXISTINGDATA 0
@@ -518,10 +517,10 @@ static void dummylog(int rw, uaecptr addr, int size, uae_u32 val)
        illegal_count++;
     if (rw) {
        write_log ("Illegal %cput at %08lx=%08lx PC=%x\n",
-           size == 1 ? 'b' : size == 2 ? 'w' : 'l', addr, val, m68k_getpc());
+           size == 1 ? 'b' : size == 2 ? 'w' : 'l', addr, val, M68K_GETPC);
     } else {
        write_log ("Illegal %cget at %08lx PC=%x\n",
-           size == 1 ? 'b' : size == 2 ? 'w' : 'l', addr, m68k_getpc());
+           size == 1 ? 'b' : size == 2 ? 'w' : 'l', addr, M68K_GETPC);
     }
 }
 
@@ -595,7 +594,7 @@ int REGPARAM2 dummy_check (uaecptr addr, uae_u32 size)
        if (illegal_count < MAX_ILG || MAX_ILG < 0) {
            if (MAX_ILG >= 0)
                illegal_count++;
-           write_log ("Illegal check at %08lx PC=%x\n", addr, m68k_getpc());
+           write_log ("Illegal check at %08lx PC=%x\n", addr, M68K_GETPC);
        }
     }
 
@@ -605,13 +604,13 @@ int REGPARAM2 dummy_check (uaecptr addr, uae_u32 size)
 #ifdef AUTOCONFIG
 
 /* A3000 "motherboard resources" bank. */
-static uae_u32 mbres_lget (uaecptr) REGPARAM;
-static uae_u32 mbres_wget (uaecptr) REGPARAM;
-static uae_u32 mbres_bget (uaecptr) REGPARAM;
-static void mbres_lput (uaecptr, uae_u32) REGPARAM;
-static void mbres_wput (uaecptr, uae_u32) REGPARAM;
-static void mbres_bput (uaecptr, uae_u32) REGPARAM;
-static int mbres_check (uaecptr addr, uae_u32 size) REGPARAM;
+static uae_u32 REGPARAM3 mbres_lget (uaecptr) REGPARAM;
+static uae_u32 REGPARAM3 mbres_wget (uaecptr) REGPARAM;
+static uae_u32 REGPARAM3 mbres_bget (uaecptr) REGPARAM;
+static void REGPARAM3 mbres_lput (uaecptr, uae_u32) REGPARAM;
+static void REGPARAM3 mbres_wput (uaecptr, uae_u32) REGPARAM;
+static void REGPARAM3 mbres_bput (uaecptr, uae_u32) REGPARAM;
+static int REGPARAM3 mbres_check (uaecptr addr, uae_u32 size) REGPARAM;
 
 static int mbres_val = 0;
 
@@ -690,8 +689,8 @@ int REGPARAM2 mbres_check (uaecptr addr, uae_u32 size)
 
 uae_u8 *chipmemory;
 
-static int chipmem_check (uaecptr addr, uae_u32 size) REGPARAM;
-static uae_u8 *chipmem_xlate (uaecptr addr) REGPARAM;
+static int REGPARAM3 chipmem_check (uaecptr addr, uae_u32 size) REGPARAM;
+static uae_u8 *REGPARAM3 chipmem_xlate (uaecptr addr) REGPARAM;
 
 #ifdef AGA
 
@@ -903,7 +902,7 @@ int REGPARAM2 chipmem_check (uaecptr addr, uae_u32 size)
     return (addr + size) <= allocated_chipmem;
 }
 
-uae_u8 REGPARAM2 *chipmem_xlate (uaecptr addr)
+uae_u8 *REGPARAM2 chipmem_xlate (uaecptr addr)
 {
     addr -= chipmem_start & chipmem_mask;
     addr &= chipmem_mask;
@@ -914,14 +913,14 @@ uae_u8 REGPARAM2 *chipmem_xlate (uaecptr addr)
 
 static uae_u8 *bogomemory;
 
-static uae_u32 bogomem_lget (uaecptr) REGPARAM;
-static uae_u32 bogomem_wget (uaecptr) REGPARAM;
-static uae_u32 bogomem_bget (uaecptr) REGPARAM;
-static void bogomem_lput (uaecptr, uae_u32) REGPARAM;
-static void bogomem_wput (uaecptr, uae_u32) REGPARAM;
-static void bogomem_bput (uaecptr, uae_u32) REGPARAM;
-static int bogomem_check (uaecptr addr, uae_u32 size) REGPARAM;
-static uae_u8 *bogomem_xlate (uaecptr addr) REGPARAM;
+static uae_u32 REGPARAM3 bogomem_lget (uaecptr) REGPARAM;
+static uae_u32 REGPARAM3 bogomem_wget (uaecptr) REGPARAM;
+static uae_u32 REGPARAM3 bogomem_bget (uaecptr) REGPARAM;
+static void REGPARAM3 bogomem_lput (uaecptr, uae_u32) REGPARAM;
+static void REGPARAM3 bogomem_wput (uaecptr, uae_u32) REGPARAM;
+static void REGPARAM3 bogomem_bput (uaecptr, uae_u32) REGPARAM;
+static int REGPARAM3 bogomem_check (uaecptr addr, uae_u32 size) REGPARAM;
+static uae_u8 *REGPARAM3 bogomem_xlate (uaecptr addr) REGPARAM;
 
 uae_u32 REGPARAM2 bogomem_lget (uaecptr addr)
 {
@@ -980,7 +979,7 @@ int REGPARAM2 bogomem_check (uaecptr addr, uae_u32 size)
     return (addr + size) <= allocated_bogomem;
 }
 
-uae_u8 REGPARAM2 *bogomem_xlate (uaecptr addr)
+uae_u8 *REGPARAM2 bogomem_xlate (uaecptr addr)
 {
     addr -= bogomem_start & bogomem_mask;
     addr &= bogomem_mask;
@@ -993,14 +992,14 @@ uae_u8 REGPARAM2 *bogomem_xlate (uaecptr addr)
 
 static uae_u8 *a3000memory;
 
-static uae_u32 a3000mem_lget (uaecptr) REGPARAM;
-static uae_u32 a3000mem_wget (uaecptr) REGPARAM;
-static uae_u32 a3000mem_bget (uaecptr) REGPARAM;
-static void a3000mem_lput (uaecptr, uae_u32) REGPARAM;
-static void a3000mem_wput (uaecptr, uae_u32) REGPARAM;
-static void a3000mem_bput (uaecptr, uae_u32) REGPARAM;
-static int a3000mem_check (uaecptr addr, uae_u32 size) REGPARAM;
-static uae_u8 *a3000mem_xlate (uaecptr addr) REGPARAM;
+static uae_u32 REGPARAM3 a3000mem_lget (uaecptr) REGPARAM;
+static uae_u32 REGPARAM3 a3000mem_wget (uaecptr) REGPARAM;
+static uae_u32 REGPARAM3 a3000mem_bget (uaecptr) REGPARAM;
+static void REGPARAM3 a3000mem_lput (uaecptr, uae_u32) REGPARAM;
+static void REGPARAM3 a3000mem_wput (uaecptr, uae_u32) REGPARAM;
+static void REGPARAM3 a3000mem_bput (uaecptr, uae_u32) REGPARAM;
+static int REGPARAM3 a3000mem_check (uaecptr addr, uae_u32 size) REGPARAM;
+static uae_u8 *REGPARAM3 a3000mem_xlate (uaecptr addr) REGPARAM;
 
 uae_u32 REGPARAM2 a3000mem_lget (uaecptr addr)
 {
@@ -1059,7 +1058,7 @@ int REGPARAM2 a3000mem_check (uaecptr addr, uae_u32 size)
     return (addr + size) <= allocated_a3000mem;
 }
 
-uae_u8 REGPARAM2 *a3000mem_xlate (uaecptr addr)
+uae_u8 *REGPARAM2 a3000mem_xlate (uaecptr addr)
 {
     addr -= a3000mem_start & a3000mem_mask;
     addr &= a3000mem_mask;
@@ -1105,14 +1104,14 @@ void a1000_reset (void)
     a1000_handle_kickstart (1);
 }
 
-static uae_u32 kickmem_lget (uaecptr) REGPARAM;
-static uae_u32 kickmem_wget (uaecptr) REGPARAM;
-static uae_u32 kickmem_bget (uaecptr) REGPARAM;
-static void kickmem_lput (uaecptr, uae_u32) REGPARAM;
-static void kickmem_wput (uaecptr, uae_u32) REGPARAM;
-static void kickmem_bput (uaecptr, uae_u32) REGPARAM;
-static int kickmem_check (uaecptr addr, uae_u32 size) REGPARAM;
-static uae_u8 *kickmem_xlate (uaecptr addr) REGPARAM;
+static uae_u32 REGPARAM3 kickmem_lget (uaecptr) REGPARAM;
+static uae_u32 REGPARAM3 kickmem_wget (uaecptr) REGPARAM;
+static uae_u32 REGPARAM3 kickmem_bget (uaecptr) REGPARAM;
+static void REGPARAM3 kickmem_lput (uaecptr, uae_u32) REGPARAM;
+static void REGPARAM3 kickmem_wput (uaecptr, uae_u32) REGPARAM;
+static void REGPARAM3 kickmem_bput (uaecptr, uae_u32) REGPARAM;
+static int REGPARAM3 kickmem_check (uaecptr addr, uae_u32 size) REGPARAM;
+static uae_u8 *REGPARAM3 kickmem_xlate (uaecptr addr) REGPARAM;
 
 uae_u32 REGPARAM2 kickmem_lget (uaecptr addr)
 {
@@ -1235,7 +1234,7 @@ int REGPARAM2 kickmem_check (uaecptr addr, uae_u32 size)
     return (addr + size) <= kickmem_size;
 }
 
-uae_u8 REGPARAM2 *kickmem_xlate (uaecptr addr)
+uae_u8 *REGPARAM2 kickmem_xlate (uaecptr addr)
 {
     addr -= kickmem_start & kickmem_mask;
     addr &= kickmem_mask;
@@ -1262,14 +1261,14 @@ static int extromtype (void)
     return 0;
 }
 
-static uae_u32 extendedkickmem_lget (uaecptr) REGPARAM;
-static uae_u32 extendedkickmem_wget (uaecptr) REGPARAM;
-static uae_u32 extendedkickmem_bget (uaecptr) REGPARAM;
-static void extendedkickmem_lput (uaecptr, uae_u32) REGPARAM;
-static void extendedkickmem_wput (uaecptr, uae_u32) REGPARAM;
-static void extendedkickmem_bput (uaecptr, uae_u32) REGPARAM;
-static int extendedkickmem_check (uaecptr addr, uae_u32 size) REGPARAM;
-static uae_u8 *extendedkickmem_xlate (uaecptr addr) REGPARAM;
+static uae_u32 REGPARAM3 extendedkickmem_lget (uaecptr) REGPARAM;
+static uae_u32 REGPARAM3 extendedkickmem_wget (uaecptr) REGPARAM;
+static uae_u32 REGPARAM3 extendedkickmem_bget (uaecptr) REGPARAM;
+static void REGPARAM3 extendedkickmem_lput (uaecptr, uae_u32) REGPARAM;
+static void REGPARAM3 extendedkickmem_wput (uaecptr, uae_u32) REGPARAM;
+static void REGPARAM3 extendedkickmem_bput (uaecptr, uae_u32) REGPARAM;
+static int REGPARAM3 extendedkickmem_check (uaecptr addr, uae_u32 size) REGPARAM;
+static uae_u8 *REGPARAM3 extendedkickmem_xlate (uaecptr addr) REGPARAM;
 
 uae_u32 REGPARAM2 extendedkickmem_lget (uaecptr addr)
 {
@@ -1330,7 +1329,7 @@ int REGPARAM2 extendedkickmem_check (uaecptr addr, uae_u32 size)
     return (addr + size) <= extendedkickmem_size;
 }
 
-uae_u8 REGPARAM2 *extendedkickmem_xlate (uaecptr addr)
+uae_u8 *REGPARAM2 extendedkickmem_xlate (uaecptr addr)
 {
     addr -= extendedkickmem_start & extendedkickmem_mask;
     addr &= extendedkickmem_mask;
@@ -1346,7 +1345,7 @@ int REGPARAM2 default_check (uaecptr a, uae_u32 b)
 
 static int be_cnt;
 
-uae_u8 REGPARAM2 *default_xlate (uaecptr a)
+uae_u8 *REGPARAM2 default_xlate (uaecptr a)
 {
     if (quit_program == 0) {
        /* do this only in 68010+ mode, there are some tricky A500 programs.. */
@@ -1357,8 +1356,8 @@ uae_u8 REGPARAM2 *default_xlate (uaecptr a)
            if (be_cnt < 3) {
                int i, j;
                uaecptr a2 = a - 32;
-               uaecptr a3 = m68k_getpc() - 32;
-               write_log ("Your Amiga program just did something terribly stupid %p PC=%p\n", a, m68k_getpc());
+               uaecptr a3 = m68k_getpc(&regs) - 32;
+               write_log ("Your Amiga program just did something terribly stupid %p PC=%p\n", a, M68K_GETPC);
                m68k_dumpstate (0, 0);
                for (i = 0; i < 10; i++) {
                    write_log ("%08.8X ", i >= 5 ? a3 : a2);
@@ -1375,9 +1374,9 @@ uae_u8 REGPARAM2 *default_xlate (uaecptr a)
                be_cnt = 0;
            } else {
                regs.panic = 1;
-               regs.panic_pc = m68k_getpc ();
+               regs.panic_pc = m68k_getpc (&regs);
                regs.panic_addr = a;
-               set_special (SPCFLAG_BRK);
+               set_special (&regs, SPCFLAG_BRK);
            }
        }
     }
@@ -1967,7 +1966,7 @@ void map_overlay (int chip)
     else
        map_banks (&kickmem_bank, 0, i, 0x80000);
     if (savestate_state != STATE_RESTORE && savestate_state != STATE_REWIND)
-       m68k_setpc(m68k_getpc());
+       m68k_setpc(&regs, m68k_getpc(&regs));
 }
 
 void memory_reset (void)
@@ -2265,6 +2264,7 @@ void map_banks (addrbank *bank, int start, int size, int realsize)
     }
 }
 
+#ifdef SAVESTATE
 
 /* memory save/restore code */
 
@@ -2280,13 +2280,13 @@ uae_u8 *save_bram (int *len)
     return bogomemory;
 }
 
-void restore_cram (int len, long filepos)
+void restore_cram (int len, size_t filepos)
 {
     chip_filepos = filepos;
     changed_prefs.chipmem_size = len;
 }
 
-void restore_bram (int len, long filepos)
+void restore_bram (int len, size_t filepos)
 {
     bogo_filepos = filepos;
     changed_prefs.bogomem_size = len;
@@ -2404,3 +2404,5 @@ uae_u8 *save_rom (int first, int *len, uae_u8 *dstptr)
     *len = dst - dstbak;
     return dstbak;
 }
+
+#endif /* SAVESTATE */
index 191aeedb0167b7490be7ae632f0cd1336d43aac1..cc05e978eb4cb3327e0e75bd1afbfda197f00c4b 100755 (executable)
@@ -12,7 +12,6 @@
 #ifdef PROWIZARD
 
 #include "uae.h"
-#include "config.h"
 #include "options.h"
 #include "memory.h"
 #include "autoconf.h"
index 34ac6185f18218197e6540bf8f9394f3addc8f6a..3efc91e8ce0f360dca227c898054e464e34791a1 100755 (executable)
 #include "sysconfig.h"
 #include "sysdeps.h"
 
-#include "config.h"
 #include "threaddep/thread.h"
 #include "options.h"
 #include "memory.h"
 #include "custom.h"
 #include "newcpu.h"
-#include "disk.h"
 #include "autoconf.h"
-#include "filesys.h"
-#include "execlib.h"
+#include "traps.h"
 #include "native2amiga.h"
 
 smp_comm_pipe native2amiga_pending;
@@ -46,7 +43,7 @@ void native2amiga_startup (void)
 
 #ifdef SUPPORT_THREADS
 
-void uae_Cause(uaecptr interrupt)
+void uae_Cause (uaecptr interrupt)
 {
     uae_sem_wait (&n2asem);
     write_comm_pipe_int (&native2amiga_pending, 3, 0);
@@ -55,7 +52,7 @@ void uae_Cause(uaecptr interrupt)
     uae_sem_post (&n2asem);
 }
 
-void uae_ReplyMsg(uaecptr msg)
+void uae_ReplyMsg (uaecptr msg)
 {
     uae_sem_wait (&n2asem);
     write_comm_pipe_int (&native2amiga_pending, 2, 0);
@@ -64,7 +61,7 @@ void uae_ReplyMsg(uaecptr msg)
     uae_sem_post (&n2asem);
 }
 
-void uae_PutMsg(uaecptr port, uaecptr msg)
+void uae_PutMsg (uaecptr port, uaecptr msg)
 {
     uae_sem_wait (&n2asem);
     write_comm_pipe_int (&native2amiga_pending, 1, 0);
@@ -74,7 +71,7 @@ void uae_PutMsg(uaecptr port, uaecptr msg)
     uae_sem_post (&n2asem);
 }
 
-void uae_Signal(uaecptr task, uae_u32 mask)
+void uae_Signal (uaecptr task, uae_u32 mask)
 {
     uae_sem_wait (&n2asem);
     write_comm_pipe_int (&native2amiga_pending, 0, 0);
@@ -84,7 +81,7 @@ void uae_Signal(uaecptr task, uae_u32 mask)
     uae_sem_post (&n2asem);
 }
 
-void uae_NotificationHack(uaecptr port, uaecptr nr)
+void uae_NotificationHack (uaecptr port, uaecptr nr)
 {
     uae_sem_wait (&n2asem);
     write_comm_pipe_int (&native2amiga_pending, 4, 0);
@@ -96,23 +93,23 @@ void uae_NotificationHack(uaecptr port, uaecptr nr)
 
 #endif
 
-void uae_NewList(uaecptr list)
+void uae_NewList (uaecptr list)
 {
     put_long (list, list + 4);
     put_long (list + 4, 0);
     put_long (list + 8, list);
 }
 
-uaecptr uae_AllocMem (uae_u32 size, uae_u32 flags)
+uaecptr uae_AllocMem (TrapContext *context, uae_u32 size, uae_u32 flags)
 {
-    m68k_dreg (regs, 0) = size;
-    m68k_dreg (regs, 1) = flags;
-    return CallLib (get_long (4), -198); /* AllocMem */
+    m68k_dreg (&context->regs, 0) = size;
+    m68k_dreg (&context->regs, 1) = flags;
+    return CallLib (context, get_long (4), -198); /* AllocMem */
 }
 
-void uae_FreeMem (uaecptr memory, uae_u32 size)
+void uae_FreeMem (TrapContext *context, uaecptr memory, uae_u32 size)
 {
-    m68k_dreg (regs, 0) = size;
-    m68k_areg (regs, 1) = memory;
-    CallLib (get_long (4), -0xD2); /* FreeMem */
+    m68k_dreg (&context->regs, 0) = size;
+    m68k_areg (&context->regs, 1) = memory;
+    CallLib (context, get_long (4), -0xD2); /* FreeMem */
 }
index 3ad67c03b0e606f64a517a9bf855374b5d799e78..e3e58ba63c17a1226f201e8ab6f5a6d6b633a18c 100755 (executable)
--- a/newcpu.c
+++ b/newcpu.c
@@ -9,7 +9,6 @@
 #include "sysconfig.h"
 #include "sysdeps.h"
 
-#include "config.h"
 #include "options.h"
 #include "events.h"
 #include "uae.h"
@@ -18,6 +17,7 @@
 #include "newcpu.h"
 #include "cpu_prefetch.h"
 #include "autoconf.h"
+#include "traps.h"
 #include "ersatz.h"
 #include "debug.h"
 #include "gui.h"
@@ -54,8 +54,8 @@ unsigned long irqcycles[15];
 int irqdelay[15];
 int mmu_enabled, mmu_triggered;
 
-int areg_byteinc[] = { 1,1,1,1,1,1,1,2 };
-int imm8_table[] = { 8,1,2,3,4,5,6,7 };
+const int areg_byteinc[] = { 1,1,1,1,1,1,1,2 };
+const int imm8_table[] = { 8,1,2,3,4,5,6,7 };
 
 int movem_index1[256];
 int movem_index2[256];
@@ -123,12 +123,15 @@ void dump_counts (void)
 }
 #endif
 
+STATIC_INLINE void count_instr (unsigned int opcode)
+{
+}
+    
+static unsigned long REGPARAM3 op_illg_1 (uae_u32 opcode, struct regstruct *regs) REGPARAM;
 
-static unsigned long op_illg_1 (uae_u32 opcode) REGPARAM;
-
-static unsigned long REGPARAM2 op_illg_1 (uae_u32 opcode)
+static unsigned long REGPARAM2 op_illg_1 (uae_u32 opcode, struct regstruct *regs)
 {
-    op_illg (opcode);
+    op_illg (opcode, regs);
     return 4;
 }
 
@@ -136,7 +139,7 @@ static void build_cpufunctbl (void)
 {
     int i, opcnt;
     unsigned long opcode;
-    struct cputbl *tbl = 0;
+    const struct cputbl *tbl = 0;
 
    switch (currprefs.cpu_level)
     {
@@ -177,12 +180,9 @@ static void build_cpufunctbl (void)
 
     for (opcode = 0; opcode < 65536; opcode++)
        cpufunctbl[opcode] = op_illg_1;
-    for (i = 0; tbl[i].handler != NULL; i++) {
-#ifdef JIT
-       tbl[i].specific = 0;
-#endif
+    for (i = 0; tbl[i].handler != NULL; i++)
        cpufunctbl[tbl[i].opcode] = tbl[i].handler;
-    }
+
     opcnt = 0;
     for (opcode = 0; opcode < 65536; opcode++) {
        cpuop_func *f;
@@ -203,20 +203,20 @@ static void build_cpufunctbl (void)
        currprefs.cpu_cycle_exact ? -1 : currprefs.cpu_compatible ? 1 : 0,
        currprefs.address_space_24);
 #ifdef JIT
-    build_comp();
+    build_comp ();
 #endif
 }
 
-void fill_prefetch_slow (void)
+void fill_prefetch_slow (struct regstruct *regs)
 {
 #ifdef CPUEMU_6
     if (currprefs.cpu_cycle_exact) {
-       regs.ir = get_word_ce (m68k_getpc ());
-       regs.irc = get_word_ce (m68k_getpc () + 2);
+       regs->ir = get_word_ce (m68k_getpc (regs));
+       regs->irc = get_word_ce (m68k_getpc (regs) + 2);
     } else {
 #endif
-       regs.ir = get_word (m68k_getpc ());
-       regs.irc = get_word (m68k_getpc () + 2);
+       regs->ir = get_word (m68k_getpc (regs));
+       regs->irc = get_word (m68k_getpc (regs) + 2);
 #ifdef CPUEMU_6
     }
 #endif
@@ -241,7 +241,7 @@ void check_prefs_changed_cpu (void)
        || currprefs.cpu_cycle_exact != changed_prefs.cpu_cycle_exact) {
 
        if (!currprefs.cpu_compatible && changed_prefs.cpu_compatible)
-           fill_prefetch_slow ();
+           fill_prefetch_slow (&regs);
 
        currprefs.cpu_level = changed_prefs.cpu_level;
        currprefs.cpu_compatible = changed_prefs.cpu_compatible;
@@ -350,18 +350,18 @@ void init_m68k (void)
     write_log ("%d CPU functions\n", nr_cpuop_funcs);
 
     build_cpufunctbl ();
-}
 
-void init_m68k_full (void)
-{
-    init_m68k ();
+#ifdef JIT
+    /* We need to check whether NATMEM settings have changed
+     * before starting the CPU */
+    check_prefs_changed_comp ();
+#endif
 }
 
-struct regstruct regs, lastint_regs, mmu_backup_regs;
+struct regstruct regs, mmu_backup_regs;
 static struct regstruct regs_backup[16];
 static int backup_pointer = 0;
 static long int m68kpc_offset;
-int lastint_no;
 
 #define get_ibyte_1(o) get_byte(regs.pc + (regs.pc_p - regs.pc_oldp) + (o) + 1)
 #define get_iword_1(o) get_word(regs.pc + (regs.pc_p - regs.pc_oldp) + (o))
@@ -405,7 +405,7 @@ static uae_s32 ShowEA (void *f, uae_u16 opcode, int reg, amodes mode, wordsizes
                sprintf (offtxt, "-$%04x", -disp16);
            else
                sprintf (offtxt, "$%04x", disp16);
-           addr = m68k_areg(regs,reg) + disp16;
+           addr = m68k_areg(&regs,reg) + disp16;
            sprintf (buffer,"(A%d,%s) == $%08lx", reg, offtxt, (unsigned long)addr);
        }
        break;
@@ -413,13 +413,13 @@ static uae_s32 ShowEA (void *f, uae_u16 opcode, int reg, amodes mode, wordsizes
        dp = get_iword_1 (m68kpc_offset); m68kpc_offset += 2;
        disp8 = dp & 0xFF;
        r = (dp & 0x7000) >> 12;
-       dispreg = dp & 0x8000 ? m68k_areg(regs,r) : m68k_dreg(regs,r);
+       dispreg = dp & 0x8000 ? m68k_areg(&regs,r) : m68k_dreg(&regs,r);
        if (!(dp & 0x800)) dispreg = (uae_s32)(uae_s16)(dispreg);
        dispreg <<= (dp >> 9) & 3;
 
        if (dp & 0x100) {
            uae_s32 outer = 0, disp = 0;
-           uae_s32 base = m68k_areg(regs,reg);
+           uae_s32 base = m68k_areg(&regs,reg);
            char name[10];
            sprintf (name,"A%d, ",reg);
            if (dp & 0x80) { base = 0; name[0] = 0; }
@@ -442,7 +442,7 @@ static uae_s32 ShowEA (void *f, uae_u16 opcode, int reg, amodes mode, wordsizes
                    disp,outer,
                    (unsigned long)addr);
        } else {
-         addr = m68k_areg(regs,reg) + (uae_s32)((uae_s8)disp8) + dispreg;
+         addr = m68k_areg(&regs,reg) + (uae_s32)((uae_s8)disp8) + dispreg;
          sprintf (buffer,"(A%d, %c%d.%c*%d, $%02x) == $%08lx", reg,
               dp & 0x8000 ? 'A' : 'D', (int)r, dp & 0x800 ? 'L' : 'W',
               1 << ((dp >> 9) & 3), disp8,
@@ -450,17 +450,17 @@ static uae_s32 ShowEA (void *f, uae_u16 opcode, int reg, amodes mode, wordsizes
        }
        break;
      case PC16:
-       addr = m68k_getpc () + m68kpc_offset;
+       addr = m68k_getpc (&regs) + m68kpc_offset;
        disp16 = get_iword_1 (m68kpc_offset); m68kpc_offset += 2;
        addr += (uae_s16)disp16;
        sprintf (buffer,"(PC,$%04x) == $%08lx", disp16 & 0xffff,(unsigned long)addr);
        break;
      case PC8r:
-       addr = m68k_getpc () + m68kpc_offset;
+       addr = m68k_getpc (&regs) + m68kpc_offset;
        dp = get_iword_1 (m68kpc_offset); m68kpc_offset += 2;
        disp8 = dp & 0xFF;
        r = (dp & 0x7000) >> 12;
-       dispreg = dp & 0x8000 ? m68k_areg(regs,r) : m68k_dreg(regs,r);
+       dispreg = dp & 0x8000 ? m68k_areg(&regs,r) : m68k_dreg(&regs,r);
        if (!(dp & 0x800)) dispreg = (uae_s32)(uae_s16)(dispreg);
        dispreg <<= (dp >> 9) & 3;
 
@@ -555,6 +555,7 @@ static uae_s32 ShowEA (void *f, uae_u16 opcode, int reg, amodes mode, wordsizes
     return offset;
 }
 
+#if 0
 /* The plan is that this will take over the job of exception 3 handling -
  * the CPU emulation functions will just do a longjmp to m68k_go whenever
  * they hit an odd address. */
@@ -570,30 +571,30 @@ static int verify_ea (int reg, amodes mode, wordsizes size, uae_u32 *val)
 
     switch (mode){
      case Dreg:
-       *val = m68k_dreg (regs, reg);
+       *val = m68k_dreg (&regs, reg);
        return 1;
      case Areg:
-       *val = m68k_areg (regs, reg);
+       *val = m68k_areg (&regs, reg);
        return 1;
 
      case Aind:
      case Aipi:
-       addr = m68k_areg (regs, reg);
+       addr = m68k_areg (&regs, reg);
        break;
      case Apdi:
-       addr = m68k_areg (regs, reg);
+       addr = m68k_areg (&regs, reg);
        break;
      case Ad16:
        disp16 = get_iword_1 (m68kpc_offset); m68kpc_offset += 2;
-       addr = m68k_areg(regs,reg) + (uae_s16)disp16;
+       addr = m68k_areg(&regs,reg) + (uae_s16)disp16;
        break;
      case Ad8r:
-       addr = m68k_areg (regs, reg);
+       addr = m68k_areg (&regs, reg);
      d8r_common:
        dp = get_iword_1 (m68kpc_offset); m68kpc_offset += 2;
        disp8 = dp & 0xFF;
        r = (dp & 0x7000) >> 12;
-       dispreg = dp & 0x8000 ? m68k_areg(regs,r) : m68k_dreg(regs,r);
+       dispreg = dp & 0x8000 ? m68k_areg(&regs,r) : m68k_dreg(&regs,r);
        if (!(dp & 0x800)) dispreg = (uae_s32)(uae_s16)(dispreg);
        dispreg <<= (dp >> 9) & 3;
 
@@ -619,12 +620,12 @@ static int verify_ea (int reg, amodes mode, wordsizes size, uae_u32 *val)
        }
        break;
      case PC16:
-       addr = m68k_getpc () + m68kpc_offset;
+       addr = m68k_getpc (&regs) + m68kpc_offset;
        disp16 = get_iword_1 (m68kpc_offset); m68kpc_offset += 2;
        addr += (uae_s16)disp16;
        break;
      case PC8r:
-       addr = m68k_getpc () + m68kpc_offset;
+       addr = m68k_getpc (&regs) + m68kpc_offset;
        goto d8r_common;
      case absw:
        addr = (uae_s32)(uae_s16)get_iword_1 (m68kpc_offset);
@@ -674,17 +675,18 @@ static int verify_ea (int reg, amodes mode, wordsizes size, uae_u32 *val)
     if ((addr & 1) == 0)
        return 1;
 
-    last_addr_for_exception_3 = m68k_getpc () + m68kpc_offset;
+    last_addr_for_exception_3 = m68k_getpc (&regs) + m68kpc_offset;
     last_fault_for_exception_3 = addr;
     last_writeaccess_for_exception_3 = 0;
     last_instructionaccess_for_exception_3 = 0;
     return 0;
 }
+#endif
 
-uae_u32 get_disp_ea_020 (uae_u32 base, uae_u32 dp)
+uae_u32 REGPARAM2 get_disp_ea_020 (struct regstruct *regs, uae_u32 base, uae_u32 dp)
 {
     int reg = (dp >> 12) & 15;
-    uae_s32 regd = regs.regs[reg];
+    uae_s32 regd = regs->regs[reg];
     if ((dp & 0x800) == 0)
        regd = (uae_s32)(uae_s16)regd;
     regd <<= (dp >> 9) & 3;
@@ -693,11 +695,11 @@ uae_u32 get_disp_ea_020 (uae_u32 base, uae_u32 dp)
        if (dp & 0x80) base = 0;
        if (dp & 0x40) regd = 0;
 
-       if ((dp & 0x30) == 0x20) base += (uae_s32)(uae_s16)next_iword();
-       if ((dp & 0x30) == 0x30) base += next_ilong();
+       if ((dp & 0x30) == 0x20) base += (uae_s32)(uae_s16)next_iword(regs);
+       if ((dp & 0x30) == 0x30) base += next_ilong(regs);
 
-       if ((dp & 0x3) == 0x2) outer = (uae_s32)(uae_s16)next_iword();
-       if ((dp & 0x3) == 0x3) outer = next_ilong();
+       if ((dp & 0x3) == 0x2) outer = (uae_s32)(uae_s16)next_iword(regs);
+       if ((dp & 0x3) == 0x3) outer = next_ilong(regs);
 
        if ((dp & 0x4) == 0) base += regd;
        if (dp & 0x3) base = get_long (base);
@@ -709,10 +711,10 @@ uae_u32 get_disp_ea_020 (uae_u32 base, uae_u32 dp)
     }
 }
 
-uae_u32 get_disp_ea_000 (uae_u32 base, uae_u32 dp)
+uae_u32 REGPARAM3 get_disp_ea_000 (struct regstruct *regs, uae_u32 base, uae_u32 dp) REGPARAM
 {
     int reg = (dp >> 12) & 15;
-    uae_s32 regd = regs.regs[reg];
+    uae_s32 regd = regs->regs[reg];
 #if 1
     if ((dp & 0x800) == 0)
        regd = (uae_s32)(uae_s16)regd;
@@ -733,98 +735,99 @@ uae_u32 get_disp_ea_000 (uae_u32 base, uae_u32 dp)
 #endif
 }
 
-void MakeSR (void)
+void REGPARAM2 MakeSR (struct regstruct *regs)
 {
 #if 0
-    assert((regs.t1 & 1) == regs.t1);
-    assert((regs.t0 & 1) == regs.t0);
-    assert((regs.s & 1) == regs.s);
-    assert((regs.m & 1) == regs.m);
+    assert((regs.t1 & 1) == regs->t1);
+    assert((regs.t0 & 1) == regs->t0);
+    assert((regs.s & 1) == regs->s);
+    assert((regs.m & 1) == regs->m);
     assert((XFLG & 1) == XFLG);
     assert((NFLG & 1) == NFLG);
     assert((ZFLG & 1) == ZFLG);
     assert((VFLG & 1) == VFLG);
     assert((CFLG & 1) == CFLG);
 #endif
-    regs.sr = ((regs.t1 << 15) | (regs.t0 << 14)
-              | (regs.s << 13) | (regs.m << 12) | (regs.intmask << 8)
-              | (GET_XFLG << 4) | (GET_NFLG << 3) | (GET_ZFLG << 2) | (GET_VFLG << 1)
-              | GET_CFLG);
-}
-
-void MakeFromSR (void)
-{
-    int oldm = regs.m;
-    int olds = regs.s;
-
-    SET_XFLG ((regs.sr >> 4) & 1);
-    SET_NFLG ((regs.sr >> 3) & 1);
-    SET_ZFLG ((regs.sr >> 2) & 1);
-    SET_VFLG ((regs.sr >> 1) & 1);
-    SET_CFLG (regs.sr & 1);
-    if (regs.t1 == ((regs.sr >> 15) & 1) &&
-       regs.t0 == ((regs.sr >> 14) & 1) &&
-       regs.s == ((regs.sr >> 13) & 1) &&
-       regs.m == ((regs.sr >> 12) & 1) &&
-       regs.intmask == ((regs.sr >> 8) & 7))
+    regs->sr = ((regs->t1 << 15) | (regs->t0 << 14)
+              | (regs->s << 13) | (regs->m << 12) | (regs->intmask << 8)
+              | (GET_XFLG(&regs->ccrflags) << 4) | (GET_NFLG(&regs->ccrflags) << 3)
+              | (GET_ZFLG(&regs->ccrflags) << 2) | (GET_VFLG(&regs->ccrflags) << 1)
+              |  GET_CFLG(&regs->ccrflags));
+}
+
+void REGPARAM2 MakeFromSR (struct regstruct *regs)
+{
+    int oldm = regs->m;
+    int olds = regs->s;
+
+    SET_XFLG (&regs->ccrflags, (regs->sr >> 4) & 1);
+    SET_NFLG (&regs->ccrflags, (regs->sr >> 3) & 1);
+    SET_ZFLG (&regs->ccrflags, (regs->sr >> 2) & 1);
+    SET_VFLG (&regs->ccrflags, (regs->sr >> 1) & 1);
+    SET_CFLG (&regs->ccrflags, regs->sr & 1);
+    if (regs->t1 == ((regs->sr >> 15) & 1) &&
+       regs->t0 == ((regs->sr >> 14) & 1) &&
+       regs->s  == ((regs->sr >> 13) & 1) &&
+       regs->m  == ((regs->sr >> 12) & 1) &&
+       regs->intmask == ((regs->sr >> 8) & 7))
            return;
-    regs.t1 = (regs.sr >> 15) & 1;
-    regs.t0 = (regs.sr >> 14) & 1;
-    regs.s = (regs.sr >> 13) & 1;
-    regs.m = (regs.sr >> 12) & 1;
-    regs.intmask = (regs.sr >> 8) & 7;
+    regs->t1 = (regs->sr >> 15) & 1;
+    regs->t0 = (regs->sr >> 14) & 1;
+    regs->s  = (regs->sr >> 13) & 1;
+    regs->m  = (regs->sr >> 12) & 1;
+    regs->intmask = (regs->sr >> 8) & 7;
     if (currprefs.cpu_level >= 2) {
-       if (olds != regs.s) {
+       if (olds != regs->s) {
            if (olds) {
                if (oldm)
-                   regs.msp = m68k_areg(regs, 7);
+                   regs->msp = m68k_areg(regs, 7);
                else
-                   regs.isp = m68k_areg(regs, 7);
-               m68k_areg(regs, 7) = regs.usp;
+                   regs->isp = m68k_areg(regs, 7);
+               m68k_areg(regs, 7) = regs->usp;
            } else {
-               regs.usp = m68k_areg(regs, 7);
-               m68k_areg(regs, 7) = regs.m ? regs.msp : regs.isp;
+               regs->usp = m68k_areg(regs, 7);
+               m68k_areg(regs, 7) = regs->m ? regs->msp : regs->isp;
            }
-       } else if (olds && oldm != regs.m) {
+       } else if (olds && oldm != regs->m) {
            if (oldm) {
-               regs.msp = m68k_areg(regs, 7);
-               m68k_areg(regs, 7) = regs.isp;
+               regs->msp = m68k_areg (regs, 7);
+               m68k_areg (regs, 7) = regs->isp;
            } else {
-               regs.isp = m68k_areg(regs, 7);
-               m68k_areg(regs, 7) = regs.msp;
+               regs->isp = m68k_areg (regs, 7);
+               m68k_areg (regs, 7) = regs->msp;
            }
        }
     } else {
-       regs.t0 = regs.m = 0;
-       if (olds != regs.s) {
+       regs->t0 = regs->m = 0;
+       if (olds != regs->s) {
            if (olds) {
-               regs.isp = m68k_areg(regs, 7);
-               m68k_areg(regs, 7) = regs.usp;
+               regs->isp = m68k_areg (regs, 7);
+               m68k_areg (regs, 7) = regs->usp;
            } else {
-               regs.usp = m68k_areg(regs, 7);
-               m68k_areg(regs, 7) = regs.isp;
+               regs->usp = m68k_areg (regs, 7);
+               m68k_areg (regs, 7) = regs->isp;
            }
        }
     }
 
-    set_special (SPCFLAG_INT);
-    if (regs.t1 || regs.t0)
-       set_special (SPCFLAG_TRACE);
+    set_special (regs, SPCFLAG_INT);
+    if (regs->t1 || regs->t0)
+       set_special (regs, SPCFLAG_TRACE);
     else
        /* Keep SPCFLAG_DOTRACE, we still want a trace exception for
           SR-modifying instructions (including STOP).  */
-       unset_special (SPCFLAG_TRACE);
+       unset_special (regs, SPCFLAG_TRACE);
 }
 
 static void exception_trace (int nr)
 {
-    unset_special (SPCFLAG_TRACE | SPCFLAG_DOTRACE);
+    unset_special (&regs, SPCFLAG_TRACE | SPCFLAG_DOTRACE);
     if (regs.t1 && !regs.t0) {
        /* trace stays pending if exception is div by zero, chk,
         * trapv or trap #x
         */
        if (nr == 5 || nr == 6 || nr ==  7 || (nr >= 32 && nr <= 47))
-           set_special (SPCFLAG_DOTRACE);
+           set_special (&regs, SPCFLAG_DOTRACE);
     }
     regs.t1 = regs.t0 = regs.m = 0;
 }
@@ -834,7 +837,7 @@ static void exception_debug (int nr)
 #ifdef DEBUGGER
     if (!exception_debugging)
        return;
-    console_out ("Exception %d, PC=%08.8X\n", nr, m68k_getpc());
+    console_out ("Exception %d, PC=%08.8X\n", nr, m68k_getpc(&regs));
 #endif
 }
 
@@ -842,14 +845,14 @@ static void exception_debug (int nr)
 
 /* cycle-exact exception handler, 68000 only */
 
-static void Exception_ce (int nr, uaecptr oldpc)
+static void Exception_ce (int nr, struct regstruct *regs, uaecptr oldpc)
 {
-    uae_u32 currpc = m68k_getpc (), newpc;
+    uae_u32 currpc = m68k_getpc (regs), newpc;
     int c;
-    int sv = regs.s;
+    int sv = regs->s;
 
     exception_debug (nr);
-    MakeSR();
+    MakeSR(regs);
 
     c = 0;
     switch (nr)
@@ -908,10 +911,10 @@ static void Exception_ce (int nr, uaecptr oldpc)
      */
     if (c)
        do_cycles (c * CYCLE_UNIT / 2);
-    if (!regs.s) {
-       regs.usp = m68k_areg(regs, 7);
-       m68k_areg(regs, 7) = regs.isp;
-       regs.s = 1;
+    if (!regs->s) {
+       regs->usp = m68k_areg(regs, 7);
+       m68k_areg(regs, 7) = regs->isp;
+       regs->s = 1;
     }
     if (nr == 2 || nr == 3) { /* 2=bus error,3=address error */
        uae_u16 mode = (sv ? 4 : 0) | (last_instructionaccess_for_exception_3 ? 2 : 1);
@@ -919,7 +922,7 @@ static void Exception_ce (int nr, uaecptr oldpc)
        m68k_areg(regs, 7) -= 14;
        /* fixme: bit3=I/N */
        put_word_ce (m68k_areg(regs, 7) + 12, last_addr_for_exception_3);
-       put_word_ce (m68k_areg(regs, 7) + 8, regs.sr);
+       put_word_ce (m68k_areg(regs, 7) + 8, regs->sr);
        put_word_ce (m68k_areg(regs, 7) + 10, last_addr_for_exception_3 >> 16);
        put_word_ce (m68k_areg(regs, 7) + 6, last_op_for_exception_3);
        put_word_ce (m68k_areg(regs, 7) + 4, last_fault_for_exception_3);
@@ -930,7 +933,7 @@ static void Exception_ce (int nr, uaecptr oldpc)
     }
     m68k_areg (regs, 7) -= 6;
     put_word_ce (m68k_areg(regs, 7) + 4, currpc);
-    put_word_ce (m68k_areg(regs, 7) + 0, regs.sr);
+    put_word_ce (m68k_areg(regs, 7) + 0, regs->sr);
     put_word_ce (m68k_areg(regs, 7) + 2, currpc >> 16);
 kludge_me_do:
     newpc = get_word_ce (4 * nr) << 16;
@@ -939,31 +942,31 @@ kludge_me_do:
        if (nr == 2 || nr == 3)
            uae_reset (1); /* there is nothing else we can do.. */
        else
-           exception3 (regs.ir, m68k_getpc(), newpc);
+           exception3 (regs->ir, m68k_getpc(regs), newpc);
        return;
     }
-    m68k_setpc (newpc);
-    fill_prefetch_slow ();
-    set_special(SPCFLAG_END_COMPILE);
+    m68k_setpc (regs, newpc);
+    fill_prefetch_slow (regs);
+    set_special(regs, SPCFLAG_END_COMPILE);
     exception_trace (nr);
 }
 #endif
 
-static void Exception_normal (int nr, uaecptr oldpc)
+static void Exception_normal (int nr, struct regstruct *regs, uaecptr oldpc)
 {
-    uae_u32 currpc = m68k_getpc (), newpc;
-    int sv = regs.s;
+    uae_u32 currpc = m68k_getpc (regs), newpc;
+    int sv = regs->s;
 
     exception_debug (nr);
-    MakeSR();
+    MakeSR(regs);
 
-    if (!regs.s) {
-       regs.usp = m68k_areg(regs, 7);
+    if (!regs->s) {
+       regs->usp = m68k_areg(regs, 7);
        if (currprefs.cpu_level >= 2)
-           m68k_areg(regs, 7) = regs.m ? regs.msp : regs.isp;
+           m68k_areg(regs, 7) = regs->m ? regs->msp : regs->isp;
        else
-           m68k_areg(regs, 7) = regs.isp;
-       regs.s = 1;
+           m68k_areg(regs, 7) = regs->isp;
+       regs->s = 1;
     }
     if (currprefs.cpu_level > 0) {
        if (nr == 2 || nr == 3) {
@@ -1015,22 +1018,22 @@ static void Exception_normal (int nr, uaecptr oldpc)
                m68k_areg(regs, 7) -= 2;
                put_word (m68k_areg(regs, 7), 0xb000 + nr * 4);
            }
-           write_log ("Exception %d (%x) at %x -> %x!\n", nr, oldpc, currpc, get_long (regs.vbr + 4*nr));
+           write_log ("Exception %d (%x) at %x -> %x!\n", nr, oldpc, currpc, get_long (regs->vbr + 4*nr));
        } else if (nr ==5 || nr == 6 || nr == 7 || nr == 9) {
            m68k_areg(regs, 7) -= 4;
            put_long (m68k_areg(regs, 7), oldpc);
            m68k_areg(regs, 7) -= 2;
            put_word (m68k_areg(regs, 7), 0x2000 + nr * 4);
-       } else if (regs.m && nr >= 24 && nr < 32) { /* M + Interrupt */
+       } else if (regs->m && nr >= 24 && nr < 32) { /* M + Interrupt */
            m68k_areg(regs, 7) -= 2;
            put_word (m68k_areg(regs, 7), nr * 4);
            m68k_areg(regs, 7) -= 4;
            put_long (m68k_areg(regs, 7), currpc);
            m68k_areg(regs, 7) -= 2;
-           put_word (m68k_areg(regs, 7), regs.sr);
-           regs.sr |= (1 << 13);
-           regs.msp = m68k_areg(regs, 7);
-           m68k_areg(regs, 7) = regs.isp;
+           put_word (m68k_areg(regs, 7), regs->sr);
+           regs->sr |= (1 << 13);
+           regs->msp = m68k_areg(regs, 7);
+           m68k_areg(regs, 7) = regs->isp;
            m68k_areg(regs, 7) -= 2;
            put_word (m68k_areg(regs, 7), 0x1000 + nr * 4);
        } else {
@@ -1045,31 +1048,31 @@ static void Exception_normal (int nr, uaecptr oldpc)
        put_word (m68k_areg(regs, 7) + 0, mode);
        put_long (m68k_areg(regs, 7) + 2, last_fault_for_exception_3);
        put_word (m68k_areg(regs, 7) + 6, last_op_for_exception_3);
-       put_word (m68k_areg(regs, 7) + 8, regs.sr);
+       put_word (m68k_areg(regs, 7) + 8, regs->sr);
        put_long (m68k_areg(regs, 7) + 10, last_addr_for_exception_3);
-       write_log ("Exception %d (%x) at %x -> %x!\n", nr, oldpc, currpc, get_long (regs.vbr + 4*nr));
+       write_log ("Exception %d (%x) at %x -> %x!\n", nr, oldpc, currpc, get_long (regs->vbr + 4*nr));
        goto kludge_me_do;
     }
     m68k_areg(regs, 7) -= 4;
     put_long (m68k_areg(regs, 7), currpc);
     m68k_areg(regs, 7) -= 2;
-    put_word (m68k_areg(regs, 7), regs.sr);
+    put_word (m68k_areg(regs, 7), regs->sr);
 kludge_me_do:
-    newpc = get_long (regs.vbr + 4 * nr);
+    newpc = get_long (regs->vbr + 4 * nr);
     if (newpc & 1) {
        if (nr == 2 || nr == 3)
            uae_reset (1); /* there is nothing else we can do.. */
        else
-           exception3 (regs.ir, m68k_getpc(), newpc);
+           exception3 (regs->ir, m68k_getpc(regs), newpc);
        return;
     }
-    m68k_setpc (newpc);
-    set_special(SPCFLAG_END_COMPILE);
-    fill_prefetch_slow ();
+    m68k_setpc (regs, newpc);
+    set_special(regs, SPCFLAG_END_COMPILE);
+    fill_prefetch_slow (regs);
     exception_trace (nr);
 }
 
-void Exception (int nr, uaecptr oldpc)
+void REGPARAM2 Exception (int nr, struct regstruct *regs, uaecptr oldpc)
 {
 #if 0
     if (1 || nr < 24)
@@ -1078,27 +1081,30 @@ void Exception (int nr, uaecptr oldpc)
 #endif
 #ifdef CPUEMU_6
     if (currprefs.cpu_cycle_exact && currprefs.cpu_level == 0)
-       Exception_ce (nr, oldpc);
+       Exception_ce (nr, regs, oldpc);
     else
 #endif
-       Exception_normal (nr, oldpc);
+       Exception_normal (nr, regs, oldpc);
 }
 
-void Interrupt (int nr)
+STATIC_INLINE void do_interrupt(int nr, struct regstruct *regs)
 {
 #if 0
     if (nr == 4)
        write_log("irq %d at %x (%04.4X)\n", nr, m68k_getpc(), intena & intreq);
 #endif
-    regs.stopped = 0;
-    unset_special (SPCFLAG_STOP);
+    regs->stopped = 0;
+    unset_special (regs, SPCFLAG_STOP);
     assert(nr < 8 && nr >= 0);
-    lastint_regs = regs;
-    lastint_no = nr;
-    Exception (nr + 24, 0);
+    Exception (nr + 24, regs, 0);
+
+    regs->intmask = nr;
+    set_special (regs, SPCFLAG_INT);
+}
 
-    regs.intmask = nr;
-    set_special (SPCFLAG_INT);
+void Interrupt (int nr)
+{
+    do_interrupt (nr, &regs);
 }
 
 static uae_u32 caar, cacr, itt0, itt1, dtt0, dtt1, tc, mmusr, urp, srp, buscr, pcr;
@@ -1134,7 +1140,7 @@ int m68k_move2c (int regno, uae_u32 *regp)
 {
     //write_log("move2c %04.4X <- %08.8X\n", regno, *regp);
     if (movec_illg (regno)) {
-       op_illg (0x4E7B);
+       op_illg (0x4E7B, &regs);
        return 0;
     } else {
        switch (regno) {
@@ -1167,14 +1173,14 @@ int m68k_move2c (int regno, uae_u32 *regp)
        case 0x800: regs.usp = *regp; break;
        case 0x801: regs.vbr = *regp; break;
        case 0x802: caar = *regp & 0xfc; break;
-       case 0x803: regs.msp = *regp; if (regs.m == 1) m68k_areg(regs, 7) = regs.msp; break;
-       case 0x804: regs.isp = *regp; if (regs.m == 0) m68k_areg(regs, 7) = regs.isp; break;
+       case 0x803: regs.msp = *regp; if (regs.m == 1) m68k_areg(&regs, 7) = regs.msp; break;
+       case 0x804: regs.isp = *regp; if (regs.m == 0) m68k_areg(&regs, 7) = regs.isp; break;
        case 0x805: mmusr = *regp; break;
        case 0x806: urp = *regp; break;
        case 0x807: srp = *regp; break;
        case 0x808: pcr = *regp & (0x40 | 2 | 1); break;
        default:
-           op_illg (0x4E7B);
+           op_illg (0x4E7B, &regs);
            return 0;
        }
     }
@@ -1185,7 +1191,7 @@ int m68k_movec2 (int regno, uae_u32 *regp)
 {
     //write_log("movec2 %04.4X\n", regno);
     if (movec_illg (regno)) {
-       op_illg (0x4E7A);
+       op_illg (0x4E7A, &regs);
        return 0;
     } else {
        switch (regno) {
@@ -1202,15 +1208,15 @@ int m68k_movec2 (int regno, uae_u32 *regp)
        case 0x800: *regp = regs.usp; break;
        case 0x801: *regp = regs.vbr; break;
        case 0x802: *regp = caar; break;
-       case 0x803: *regp = regs.m == 1 ? m68k_areg(regs, 7) : regs.msp; break;
-       case 0x804: *regp = regs.m == 0 ? m68k_areg(regs, 7) : regs.isp; break;
+       case 0x803: *regp = regs.m == 1 ? m68k_areg(&regs, 7) : regs.msp; break;
+       case 0x804: *regp = regs.m == 0 ? m68k_areg(&regs, 7) : regs.isp; break;
        case 0x805: *regp = mmusr; break;
        case 0x806: *regp = urp; break;
        case 0x807: *regp = srp; break;
        case 0x808: *regp = 0x04300100 | pcr; break;
 
        default:
-           op_illg (0x4E7A);
+           op_illg (0x4E7A, &regs);
            return 0;
        }
     }
@@ -1247,74 +1253,74 @@ void m68k_divl (uae_u32 opcode, uae_u32 src, uae_u16 extra, uaecptr oldpc)
 {
 #if defined(uae_s64)
     if (src == 0) {
-       Exception (5, oldpc);
+       Exception (5, &regs, oldpc);
        return;
     }
     if (extra & 0x800) {
        /* signed variant */
-       uae_s64 a = (uae_s64)(uae_s32)m68k_dreg(regs, (extra >> 12) & 7);
+       uae_s64 a = (uae_s64)(uae_s32)m68k_dreg(&regs, (extra >> 12) & 7);
        uae_s64 quot, rem;
 
        if (extra & 0x400) {
            a &= 0xffffffffu;
-           a |= (uae_s64)m68k_dreg(regs, extra & 7) << 32;
+           a |= (uae_s64)m68k_dreg(&regs, extra & 7) << 32;
        }
        rem = a % (uae_s64)(uae_s32)src;
        quot = a / (uae_s64)(uae_s32)src;
        if ((quot & UVAL64(0xffffffff80000000)) != 0
            && (quot & UVAL64(0xffffffff80000000)) != UVAL64(0xffffffff80000000))
        {
-           SET_VFLG (1);
-           SET_NFLG (1);
-           SET_CFLG (0);
+           SET_VFLG (&regs.ccrflags, 1);
+           SET_NFLG (&regs.ccrflags, 1);
+           SET_CFLG (&regs.ccrflags, 0);
        } else {
            if (((uae_s32)rem < 0) != ((uae_s64)a < 0)) rem = -rem;
-           SET_VFLG (0);
-           SET_CFLG (0);
-           SET_ZFLG (((uae_s32)quot) == 0);
-           SET_NFLG (((uae_s32)quot) < 0);
-           m68k_dreg(regs, extra & 7) = (uae_u32)rem;
-           m68k_dreg(regs, (extra >> 12) & 7) = (uae_u32)quot;
+           SET_VFLG (&regs.ccrflags, 0);
+           SET_CFLG (&regs.ccrflags, 0);
+           SET_ZFLG (&regs.ccrflags, ((uae_s32)quot) == 0);
+           SET_NFLG (&regs.ccrflags, ((uae_s32)quot) < 0);
+           m68k_dreg(&regs, extra & 7) = (uae_u32)rem;
+           m68k_dreg(&regs, (extra >> 12) & 7) = (uae_u32)quot;
        }
     } else {
        /* unsigned */
-       uae_u64 a = (uae_u64)(uae_u32)m68k_dreg(regs, (extra >> 12) & 7);
+       uae_u64 a = (uae_u64)(uae_u32)m68k_dreg(&regs, (extra >> 12) & 7);
        uae_u64 quot, rem;
 
        if (extra & 0x400) {
            a &= 0xffffffffu;
-           a |= (uae_u64)m68k_dreg(regs, extra & 7) << 32;
+           a |= (uae_u64)m68k_dreg(&regs, extra & 7) << 32;
        }
        rem = a % (uae_u64)src;
        quot = a / (uae_u64)src;
        if (quot > 0xffffffffu) {
-           SET_VFLG (1);
-           SET_NFLG (1);
-           SET_CFLG (0);
+           SET_VFLG (&regs.ccrflags, 1);
+           SET_NFLG (&regs.ccrflags, 1);
+           SET_CFLG (&regs.ccrflags, 0);
        } else {
-           SET_VFLG (0);
-           SET_CFLG (0);
-           SET_ZFLG (((uae_s32)quot) == 0);
-           SET_NFLG (((uae_s32)quot) < 0);
-           m68k_dreg(regs, extra & 7) = (uae_u32)rem;
-           m68k_dreg(regs, (extra >> 12) & 7) = (uae_u32)quot;
+           SET_VFLG (&regs.ccrflags, 0);
+           SET_CFLG (&regs.ccrflags, 0);
+           SET_ZFLG (&regs.ccrflags, ((uae_s32)quot) == 0);
+           SET_NFLG (&regs.ccrflags, ((uae_s32)quot) < 0);
+           m68k_dreg(&regs, extra & 7) = (uae_u32)rem;
+           m68k_dreg(&regs, (extra >> 12) & 7) = (uae_u32)quot;
        }
     }
 #else
     if (src == 0) {
-       Exception (5, oldpc);
+       Exception (5, &regs, oldpc);
        return;
     }
     if (extra & 0x800) {
        /* signed variant */
-       uae_s32 lo = (uae_s32)m68k_dreg(regs, (extra >> 12) & 7);
+       uae_s32 lo = (uae_s32)m68k_dreg(&regs, (extra >> 12) & 7);
        uae_s32 hi = lo < 0 ? -1 : 0;
        uae_s32 save_high;
        uae_u32 quot, rem;
        uae_u32 sign;
 
        if (extra & 0x400) {
-           hi = (uae_s32)m68k_dreg(regs, extra & 7);
+           hi = (uae_s32)m68k_dreg(&regs, extra & 7);
        }
        save_high = hi;
        sign = (hi ^ src);
@@ -1341,12 +1347,12 @@ void m68k_divl (uae_u32 opcode, uae_u32 src, uae_u16 extra, uaecptr oldpc)
        }
     } else {
        /* unsigned */
-       uae_u32 lo = (uae_u32)m68k_dreg(regs, (extra >> 12) & 7);
+       uae_u32 lo = (uae_u32)m68k_dreg(&regs, (extra >> 12) & 7);
        uae_u32 hi = 0;
        uae_u32 quot, rem;
 
        if (extra & 0x400) {
-           hi = (uae_u32)m68k_dreg(regs, extra & 7);
+           hi = (uae_u32)m68k_dreg(&regs, extra & 7);
        }
        if (div_unsigned(hi, lo, src, &quot, &rem)) {
            SET_VFLG (1);
@@ -1388,36 +1394,36 @@ void m68k_mull (uae_u32 opcode, uae_u32 src, uae_u16 extra)
 #if defined(uae_s64)
     if (extra & 0x800) {
        /* signed variant */
-       uae_s64 a = (uae_s64)(uae_s32)m68k_dreg(regs, (extra >> 12) & 7);
+       uae_s64 a = (uae_s64)(uae_s32)m68k_dreg(&regs, (extra >> 12) & 7);
 
        a *= (uae_s64)(uae_s32)src;
-       SET_VFLG (0);
-       SET_CFLG (0);
-       SET_ZFLG (a == 0);
-       SET_NFLG (a < 0);
+       SET_VFLG (&regs.ccrflags, 0);
+       SET_CFLG (&regs.ccrflags, 0);
+       SET_ZFLG (&regs.ccrflags, a == 0);
+       SET_NFLG (&regs.ccrflags, a < 0);
        if (extra & 0x400)
-           m68k_dreg(regs, extra & 7) = (uae_u32)(a >> 32);
+           m68k_dreg(&regs, extra & 7) = (uae_u32)(a >> 32);
        else if ((a & UVAL64(0xffffffff80000000)) != 0
                 && (a & UVAL64(0xffffffff80000000)) != UVAL64(0xffffffff80000000))
        {
-           SET_VFLG (1);
+           SET_VFLG (&regs.ccrflags, 1);
        }
-       m68k_dreg(regs, (extra >> 12) & 7) = (uae_u32)a;
+       m68k_dreg(&regs, (extra >> 12) & 7) = (uae_u32)a;
     } else {
        /* unsigned */
-       uae_u64 a = (uae_u64)(uae_u32)m68k_dreg(regs, (extra >> 12) & 7);
+       uae_u64 a = (uae_u64)(uae_u32)m68k_dreg(&regs, (extra >> 12) & 7);
 
        a *= (uae_u64)src;
-       SET_VFLG (0);
-       SET_CFLG (0);
-       SET_ZFLG (a == 0);
-       SET_NFLG (((uae_s64)a) < 0);
+       SET_VFLG (&regs.ccrflags, 0);
+       SET_CFLG (&regs.ccrflags, 0);
+       SET_ZFLG (&regs.ccrflags, a == 0);
+       SET_NFLG (&regs.ccrflags, ((uae_s64)a) < 0);
        if (extra & 0x400)
-           m68k_dreg(regs, extra & 7) = (uae_u32)(a >> 32);
+           m68k_dreg(&regs, extra & 7) = (uae_u32)(a >> 32);
        else if ((a & UVAL64(0xffffffff00000000)) != 0) {
-           SET_VFLG (1);
+           SET_VFLG (&regs.ccrflags, 1);
        }
-       m68k_dreg(regs, (extra >> 12) & 7) = (uae_u32)a;
+       m68k_dreg(&regs, (extra >> 12) & 7) = (uae_u32)a;
     }
 #else
     if (extra & 0x800) {
@@ -1427,7 +1433,7 @@ void m68k_mull (uae_u32 opcode, uae_u32 src, uae_u16 extra)
        uae_u32 sign;
 
        src1 = (uae_s32)src;
-       src2 = (uae_s32)m68k_dreg(regs, (extra >> 12) & 7);
+       src2 = (uae_s32)m68k_dreg(&regs, (extra >> 12) & 7);
        sign = (src1 ^ src2);
        if (src1 < 0) src1 = -src1;
        if (src2 < 0) src2 = -src2;
@@ -1442,26 +1448,26 @@ void m68k_mull (uae_u32 opcode, uae_u32 src, uae_u16 extra)
        SET_ZFLG (dst_hi == 0 && dst_lo == 0);
        SET_NFLG (((uae_s32)dst_hi) < 0);
        if (extra & 0x400)
-           m68k_dreg(regs, extra & 7) = dst_hi;
+           m68k_dreg(&regs, extra & 7) = dst_hi;
        else if ((dst_hi != 0 || (dst_lo & 0x80000000) != 0)
                 && ((dst_hi & 0xffffffff) != 0xffffffff
                     || (dst_lo & 0x80000000) != 0x80000000))
        {
            SET_VFLG (1);
        }
-       m68k_dreg(regs, (extra >> 12) & 7) = dst_lo;
+       m68k_dreg(&regs, (extra >> 12) & 7) = dst_lo;
     } else {
        /* unsigned */
        uae_u32 dst_lo,dst_hi;
 
-       mul_unsigned(src,(uae_u32)m68k_dreg(regs, (extra >> 12) & 7),&dst_hi,&dst_lo);
+       mul_unsigned(src,(uae_u32)m68k_dreg(&regs, (extra >> 12) & 7),&dst_hi,&dst_lo);
 
        SET_VFLG (0);
        SET_CFLG (0);
        SET_ZFLG (dst_hi == 0 && dst_lo == 0);
        SET_NFLG (((uae_s32)dst_hi) < 0);
        if (extra & 0x400)
-           m68k_dreg(regs, extra & 7) = dst_hi;
+           m68k_dreg(&regs, extra & 7) = dst_hi;
        else if (dst_hi != 0) {
            SET_VFLG (1);
        }
@@ -1472,39 +1478,36 @@ void m68k_mull (uae_u32 opcode, uae_u32 src, uae_u16 extra)
 
 #endif
 
-static char* ccnames[] =
-{ "T ","F ","HI","LS","CC","CS","NE","EQ",
-  "VC","VS","PL","MI","GE","LT","GT","LE" };
-
 void m68k_reset (void)
 {
     regs.kick_mask = 0x00F80000;
     regs.spcflags = 0;
+#ifdef SAVESTATE
     if (savestate_state == STATE_RESTORE || savestate_state == STATE_REWIND) {
-       m68k_setpc (regs.pc);
+       m68k_setpc (&regs, regs.pc);
        /* MakeFromSR() must not swap stack pointer */
        regs.s = (regs.sr >> 13) & 1;
-       MakeFromSR();
+       MakeFromSR(&regs);
        /* set stack pointer */
        if (regs.s)
-           m68k_areg(regs, 7) = regs.isp;
+           m68k_areg(&regs, 7) = regs.isp;
        else
-           m68k_areg(regs, 7) = regs.usp;
+           m68k_areg(&regs, 7) = regs.usp;
        return;
     }
-
-    m68k_areg (regs, 7) = get_long (0x00f80000);
-    m68k_setpc (get_long (0x00f80004));
+#endif
+    m68k_areg (&regs, 7) = get_long (0x00f80000);
+    m68k_setpc (&regs, get_long (0x00f80004));
     regs.s = 1;
     regs.m = 0;
     regs.stopped = 0;
     regs.t1 = 0;
     regs.t0 = 0;
-    SET_ZFLG (0);
-    SET_XFLG (0);
-    SET_CFLG (0);
-    SET_VFLG (0);
-    SET_NFLG (0);
+    SET_ZFLG (&regs.ccrflags, 0);
+    SET_XFLG (&regs.ccrflags, 0);
+    SET_CFLG (&regs.ccrflags, 0);
+    SET_VFLG (&regs.ccrflags, 0);
+    SET_NFLG (&regs.ccrflags, 0);
     regs.intmask = 7;
     regs.vbr = regs.sfc = regs.dfc = 0;
 #ifdef FPUEMU
@@ -1512,7 +1515,7 @@ void m68k_reset (void)
     regs.fp_result=1;
     regs.irc = 0xffff;
 #endif
-    fill_prefetch_slow ();
+    fill_prefetch_slow (&regs);
 }
 
 STATIC_INLINE int in_rom (uaecptr pc)
@@ -1525,78 +1528,80 @@ STATIC_INLINE int in_rtarea (uaecptr pc)
     return (munge24 (pc) & 0xFFFF0000) == RTAREA_BASE;
 }
 
-unsigned long REGPARAM2 op_illg (uae_u32 opcode)
+unsigned long REGPARAM2 op_illg (uae_u32 opcode, struct regstruct *regs)
 {
-    uaecptr pc = m68k_getpc ();
+    uaecptr pc = m68k_getpc (regs);
     static int warned;
+    int inrom = in_rom(pc);
+    int inrt = in_rtarea(pc);
 
     if (cloanto_rom && (opcode & 0xF100) == 0x7100) {
        m68k_dreg (regs, (opcode >> 9) & 7) = (uae_s8)(opcode & 0xFF);
-       m68k_incpc (2);
-       fill_prefetch_slow ();
+       m68k_incpc (regs, 2);
+       fill_prefetch_slow (regs);
        return 4;
     }
 
-    if (opcode == 0x4E7B && in_rom (pc) && get_long (0x10) == 0) {
+    if (opcode == 0x4E7B && inrom && get_long (0x10) == 0) {
        notify_user (NUMSG_KS68020);
        uae_restart (-1, NULL);
     }
 
 #ifdef AUTOCONFIG
     if (opcode == 0xFF0D) {
-       if (in_rom (pc)) {
+       if (inrom) {
            /* This is from the dummy Kickstart replacement */
-           uae_u16 arg = get_iword (2);
-           m68k_incpc (4);
+           uae_u16 arg = get_iword (regs, 2);
+           m68k_incpc (regs, 4);
            ersatz_perform (arg);
-           fill_prefetch_slow ();
+           fill_prefetch_slow (regs);
            return 4;
-       } else if (in_rtarea (pc)) {
+       } else if (inrt) {
            /* User-mode STOP replacement */
-           m68k_setstopped (1);
+           m68k_setstopped (regs, 1);
            return 4;
        }
     }
 
-    if ((opcode & 0xF000) == 0xA000 && in_rtarea (pc)) {
+    if ((opcode & 0xF000) == 0xA000 && inrt) {
        /* Calltrap. */
-       m68k_incpc(2);
-       call_calltrap (opcode & 0xFFF);
-       fill_prefetch_slow ();
+       m68k_incpc(regs, 2);
+       m68k_handle_trap (opcode & 0xFFF, regs);
+       fill_prefetch_slow (regs);
        return 4;
     }
 #endif
 
     if ((opcode & 0xF000) == 0xF000) {
        if (warned < 20) {
-           write_log ("B-Trap %x at %x (%p)\n", opcode, m68k_getpc () + m68kpc_offset, regs.pc_p);
+           write_log ("B-Trap %x at %x (%p)\n", opcode, m68k_getpc (regs) + m68kpc_offset, regs->pc_p);
            warned++;
        }
-       Exception(0xB,0);
+       Exception(0xB, regs, 0);
        return 4;
     }
     if ((opcode & 0xF000) == 0xA000) {
 #ifdef AUTOCONFIG
-       if (in_rtarea (pc)) {
+       if (inrt) {
            /* Calltrap. */
-           call_calltrap (opcode & 0xFFF);
+           m68k_handle_trap (opcode & 0xFFF, regs);
        }
 #endif
-       Exception(0xA,0);
+       Exception(0xA, regs, 0);
        return 4;
     }
     if (warned < 20) {
-       write_log ("Illegal instruction: %04x at %08.8X -> %08.8X\n", opcode, pc, get_long (regs.vbr + 0x10));
+       write_log ("Illegal instruction: %04x at %08.8X -> %08.8X\n", opcode, pc, get_long (regs->vbr + 0x10));
        warned++;
     }
 
-    Exception (4,0);
+    Exception (4, regs, 0);
     return 4;
 }
 
 #ifdef CPUEMU_0
 
-void mmu_op(uae_u32 opcode, uae_u16 extra)
+void mmu_op(uae_u32 opcode, struct regstruct *regs, uae_u16 extra)
 {
     if ((opcode & 0xFE0) == 0x0500) {
        /* PFLUSH */
@@ -1606,13 +1611,11 @@ void mmu_op(uae_u32 opcode, uae_u16 extra)
        /* PTEST */
        //write_log ("PTEST @$%lx\n", m68k_getpc());
     } else
-       op_illg (opcode);
+       op_illg (opcode, regs);
 }
 
 #endif
 
-static int n_insns = 0, n_spcinsns = 0;
-
 static uaecptr last_trace_ad = 0;
 
 static void do_trace (void)
@@ -1622,8 +1625,8 @@ static void do_trace (void)
        /* should also include TRAP, CHK, SR modification FPcc */
        /* probably never used so why bother */
        /* We can afford this to be inefficient... */
-       m68k_setpc (m68k_getpc ());
-       fill_prefetch_slow ();
+       m68k_setpc (&regs, m68k_getpc (&regs));
+       fill_prefetch_slow (&regs);
        opcode = get_word (regs.pc);
        if (opcode == 0x4e72            /* RTE */
            || opcode == 0x4e74                 /* RTD */
@@ -1634,30 +1637,30 @@ static void do_trace (void)
            || (opcode & 0xffc0) == 0x4ec0      /* JMP */
            || (opcode & 0xff00) == 0x6100  /* BSR */
            || ((opcode & 0xf000) == 0x6000     /* Bcc */
-               && cctrue((opcode >> 8) & 0xf))
+               && cctrue(&regs.ccrflags, (opcode >> 8) & 0xf))
            || ((opcode & 0xf0f0) == 0x5050 /* DBcc */
-               && !cctrue((opcode >> 8) & 0xf)
-               && (uae_s16)m68k_dreg(regs, opcode & 7) != 0))
+               && !cctrue(&regs.ccrflags, (opcode >> 8) & 0xf)
+               && (uae_s16)m68k_dreg(&regs, opcode & 7) != 0))
        {
-           last_trace_ad = m68k_getpc ();
-           unset_special (SPCFLAG_TRACE);
-           set_special (SPCFLAG_DOTRACE);
+           last_trace_ad = m68k_getpc (&regs);
+           unset_special (&regs, SPCFLAG_TRACE);
+           set_special (&regs, SPCFLAG_DOTRACE);
        }
     } else if (regs.t1) {
-       last_trace_ad = m68k_getpc ();
-       unset_special (SPCFLAG_TRACE);
-       set_special (SPCFLAG_DOTRACE);
+       last_trace_ad = m68k_getpc (&regs);
+       unset_special (&regs, SPCFLAG_TRACE);
+       set_special (&regs, SPCFLAG_DOTRACE);
     }
 }
 
 #define IDLETIME (currprefs.cpu_idle * sleep_resolution / 1000)
 
-static int do_specialties (int cycles)
+STATIC_INLINE int do_specialties (int cycles, struct regstruct *regs)
 {
     #ifdef ACTION_REPLAY
     #ifdef ACTION_REPLAY_HRTMON
-    if ((regs.spcflags & SPCFLAG_ACTION_REPLAY) && hrtmon_flag != ACTION_REPLAY_INACTIVE) {
-       int isinhrt = (m68k_getpc() >= hrtmem_start && m68k_getpc() < hrtmem_start + hrtmem_size);
+    if ((regs->spcflags & SPCFLAG_ACTION_REPLAY) && hrtmon_flag != ACTION_REPLAY_INACTIVE) {
+       int isinhrt = (m68k_getpc(regs) >= hrtmem_start && m68k_getpc(regs) < hrtmem_start + hrtmem_size);
        /* exit from HRTMon? */
        if(hrtmon_flag == ACTION_REPLAY_ACTIVE && !isinhrt)
            hrtmon_hide();
@@ -1666,11 +1669,11 @@ static int do_specialties (int cycles)
            hrtmon_breakenter();
        if(hrtmon_flag == ACTION_REPLAY_ACTIVATE)
            hrtmon_enter();
-       if(!(regs.spcflags & ~SPCFLAG_ACTION_REPLAY))
+       if(!(regs->spcflags & ~SPCFLAG_ACTION_REPLAY))
            return 0;
     }
     #endif
-    if ((regs.spcflags & SPCFLAG_ACTION_REPLAY) && action_replay_flag != ACTION_REPLAY_INACTIVE ) {
+    if ((regs->spcflags & SPCFLAG_ACTION_REPLAY) && action_replay_flag != ACTION_REPLAY_INACTIVE ) {
        /*if(action_replay_flag == ACTION_REPLAY_ACTIVE && !is_ar_pc_in_rom())*/
        /*      write_log("PC:%p\n",m68k_getpc());*/
 
@@ -1679,12 +1682,12 @@ static int do_specialties (int cycles)
        if(action_replay_flag == ACTION_REPLAY_HIDE && !is_ar_pc_in_rom())
        {
            action_replay_hide();
-           unset_special(SPCFLAG_ACTION_REPLAY);
+           unset_special(regs, SPCFLAG_ACTION_REPLAY);
        }
        if (action_replay_flag == ACTION_REPLAY_WAIT_PC )
        {
            /*write_log("Waiting for PC: %p, current PC= %p\n",wait_for_pc, m68k_getpc());*/
-           if (m68k_getpc() == wait_for_pc)
+           if (m68k_getpc(regs) == wait_for_pc)
            {
                action_replay_flag = ACTION_REPLAY_ACTIVATE; /* Activate after next instruction. */
            }
@@ -1692,15 +1695,15 @@ static int do_specialties (int cycles)
     }
     #endif
 
-    if (regs.spcflags & SPCFLAG_COPPER)
+    if (regs->spcflags & SPCFLAG_COPPER)
        do_copper ();
 
     /*n_spcinsns++;*/
 #ifdef JIT
-    unset_special(SPCFLAG_END_COMPILE);   /* has done its job */
+    unset_special(regs, SPCFLAG_END_COMPILE);   /* has done its job */
 #endif
 
-    while ((regs.spcflags & SPCFLAG_BLTNASTY) && dmaen (DMA_BLITTER) && cycles > 0 && !currprefs.blitter_cycle_exact) {
+    while ((regs->spcflags & SPCFLAG_BLTNASTY) && dmaen (DMA_BLITTER) && cycles > 0 && !currprefs.blitter_cycle_exact) {
        int c = blitnasty();
        if (c > 0) {
            cycles -= c * CYCLE_UNIT * 2;
@@ -1709,36 +1712,36 @@ static int do_specialties (int cycles)
        } else
            c = 4;
        do_cycles (c * CYCLE_UNIT);
-       if (regs.spcflags & SPCFLAG_COPPER)
+       if (regs->spcflags & SPCFLAG_COPPER)
            do_copper ();
     }
 
-    if (regs.spcflags & SPCFLAG_DOTRACE)
-       Exception (9,last_trace_ad);
-    if (regs.spcflags & SPCFLAG_TRAP) {
-       unset_special (SPCFLAG_TRAP);
-       Exception (3, 0);
+    if (regs->spcflags & SPCFLAG_DOTRACE)
+       Exception (9, regs, last_trace_ad);
+    if (regs->spcflags & SPCFLAG_TRAP) {
+       unset_special (regs, SPCFLAG_TRAP);
+       Exception (3, regs, 0);
     }
 
-    while (regs.spcflags & SPCFLAG_STOP) {
+    while (regs->spcflags & SPCFLAG_STOP) {
        do_cycles (4 * CYCLE_UNIT);
-       if (regs.spcflags & SPCFLAG_COPPER)
+       if (regs->spcflags & SPCFLAG_COPPER)
            do_copper ();
-       if (regs.spcflags & (SPCFLAG_INT | SPCFLAG_DOINT)) {
+       if (regs->spcflags & (SPCFLAG_INT | SPCFLAG_DOINT)) {
            int intr = intlev ();
 #ifdef JIT
            if (currprefs.cachesize)
-               unset_special (SPCFLAG_INT | SPCFLAG_DOINT);
+               unset_special (regs, SPCFLAG_INT | SPCFLAG_DOINT);
 #endif
-           if (intr != -1 && intr > regs.intmask)
+           if (intr != -1 && intr > regs->intmask)
                Interrupt (intr);
        }
-       if ((regs.spcflags & (SPCFLAG_BRK | SPCFLAG_MODE_CHANGE))) {
-           unset_special (SPCFLAG_BRK | SPCFLAG_MODE_CHANGE);
+       if ((regs->spcflags & (SPCFLAG_BRK | SPCFLAG_MODE_CHANGE))) {
+           unset_special (regs, SPCFLAG_BRK | SPCFLAG_MODE_CHANGE);
            return 1;
        }
 
-       if (currprefs.cpu_idle && currprefs.m68k_speed != 0 && ((regs.spcflags & SPCFLAG_STOP)) == SPCFLAG_STOP) {
+       if (currprefs.cpu_idle && currprefs.m68k_speed != 0 && ((regs->spcflags & SPCFLAG_STOP)) == SPCFLAG_STOP) {
            /* sleep 1ms if STOP-instruction is executed */
            if (1) {
                static int sleepcnt, lvpos, zerocnt;
@@ -1760,36 +1763,36 @@ static int do_specialties (int cycles)
        }
     }
 
-    if (regs.spcflags & SPCFLAG_TRACE)
+    if (regs->spcflags & SPCFLAG_TRACE)
        do_trace ();
 
     /* interrupt takes at least 2 cycles (maybe 4) to reach the CPU and
      * there are programs that require this delay (which is not too surprising..)
      */
 #ifdef JIT
-    if ((regs.spcflags & SPCFLAG_DOINT)
-       || (!currprefs.cachesize && (regs.spcflags & SPCFLAG_INT))) {
+    if ((regs->spcflags & SPCFLAG_DOINT)
+       || (!currprefs.cachesize && (regs->spcflags & SPCFLAG_INT))) {
 #else
-    if (regs.spcflags & SPCFLAG_INT) {
+    if (regs->spcflags & SPCFLAG_INT) {
 #endif
        int intr = intlev ();
 #ifdef JIT
        if (currprefs.cachesize)
-           unset_special (SPCFLAG_DOINT);
+           unset_special (regs, SPCFLAG_DOINT);
 #endif
-       if (intr != -1 && intr > regs.intmask)
-           Interrupt (intr);
+       if (intr != -1 && intr > regs->intmask)
+           do_interrupt (intr, regs);
     }
 
 #ifdef JIT
-    if ((regs.spcflags & SPCFLAG_INT) && currprefs.cachesize) {
-       unset_special (SPCFLAG_INT);
-       set_special (SPCFLAG_DOINT);
+    if ((regs->spcflags & SPCFLAG_INT) && currprefs.cachesize) {
+       unset_special (regs, SPCFLAG_INT);
+       set_special (regs, SPCFLAG_DOINT);
     }
 #endif
 
-    if ((regs.spcflags & (SPCFLAG_BRK | SPCFLAG_MODE_CHANGE))) {
-       unset_special (SPCFLAG_BRK | SPCFLAG_MODE_CHANGE);
+    if ((regs->spcflags & (SPCFLAG_BRK | SPCFLAG_MODE_CHANGE))) {
+       unset_special (regs, SPCFLAG_BRK | SPCFLAG_MODE_CHANGE);
        return 1;
     }
     return 0;
@@ -1811,9 +1814,14 @@ static void m68k_run_1 (void)
    This version emulates 68000's prefetch "cache" */
 static void m68k_run_1 (void)
 {
+    struct regstruct *r = &regs;
+
     for (;;) {
        int cycles;
-       uae_u32 opcode = regs.ir;
+       uae_u32 opcode = r->ir;
+
+       count_instr (opcode);
+
 #if 0
        int pc = m68k_getpc();
        if (pc == 0xdff002)
@@ -1824,28 +1832,14 @@ static void m68k_run_1 (void)
            //write_log("%08.8X-%04.4X ",pc, opcode);
        }
 #endif
-       /* assert (!regs.stopped && !(regs.spcflags & SPCFLAG_STOP)); */
-/*     regs_backup[backup_pointer = (backup_pointer + 1) % 16] = regs;*/
-#if COUNT_INSTRS == 2
-       if (table68k[opcode].handler != -1)
-           instrcount[table68k[opcode].handler]++;
-#elif COUNT_INSTRS == 1
-       instrcount[opcode]++;
-#endif
-#if defined X86_ASSEMBLY
-       __asm__ __volatile__("\tcall *%%ebx"
-                            : "=&a" (cycles) : "b" (cpufunctbl[opcode]), "0" (opcode)
-                            : "%edx", "%ecx",
-                            "%esi", "%edi", "%ebp", "memory", "cc");
-#else
-       cycles = (*cpufunctbl[opcode])(opcode);
-#endif
-       /*n_insns++;*/
+
+       cycles = (*cpufunctbl[opcode])(opcode, r);
+
        cycles &= cycles_mask;
        cycles |= cycles_val;
        do_cycles (cycles);
-       if (regs.spcflags) {
-           if (do_specialties (cycles))
+       if (r->spcflags) {
+           if (do_specialties (cycles, r))
                return;
        }
        if (!currprefs.cpu_compatible || (currprefs.cpu_cycle_exact && currprefs.cpu_level == 0))
@@ -1853,7 +1847,7 @@ static void m68k_run_1 (void)
     }
 }
 
-#endif
+#endif /* CPUEMU_5 */
 
 #ifndef CPUEMU_6
 
@@ -1867,18 +1861,14 @@ static void m68k_run_1_ce (void)
 
 static void m68k_run_1_ce (void)
 {
+    struct regstruct *r = &regs;
+
     for (;;) {
-       uae_u32 opcode = regs.ir;
-#if 0
-       int pc = m68k_getpc();
-       if (pc != pcs[0]) {
-           memmove (pcs + 1, pcs, 998 * 4);
-           pcs[0] = pc;
-       }
-#endif
-       (*cpufunctbl[opcode])(opcode);
-       if (regs.spcflags) {
-           if (do_specialties (0))
+       uae_u32 opcode = r->ir;
+
+       (*cpufunctbl[opcode])(opcode, r);
+       if (r->spcflags) {
+           if (do_specialties (0, r))
                return;
        }
        if (!currprefs.cpu_cycle_exact || currprefs.cpu_level > 0)
@@ -1896,33 +1886,23 @@ void do_nothing(void)
     /* I bet you didn't expect *that* ;-) */
 }
 
-#ifdef JIT
-
 void exec_nostats(void)
 {
+    struct regstruct *r = &regs;
     int new_cycles;
 
     for (;;)
     {
-       uae_u16 opcode = get_iword(0);
-#if defined X86_ASSEMBLY
-       __asm__ __volatile__("\tpush %%ebp\n\tcall *%%ebx\n\tpop %%ebp" /* FIXME */
-                            : "=&a" (new_cycles)
-                            : "b" (cpufunctbl[opcode]), "0" (opcode)
-                            : "%edx", "%ecx", "%esi", "%edi",
-                            "%ebp", "memory", "cc");
-#else
-       new_cycles = (*cpufunctbl[opcode])(opcode);
-#endif
+       uae_u16 opcode = get_iword(r, 0);
+
+       new_cycles = (*cpufunctbl[opcode])(opcode, r);
 
        new_cycles &= cycles_mask;
        new_cycles |= cycles_val;
        do_cycles (new_cycles);
 
-       if (end_block(opcode) ||
-           regs.spcflags) {
+       if (end_block(opcode) || r->spcflags)
            return; /* We will deal with the spcflags in the caller */
-       }
     }
 }
 
@@ -1930,6 +1910,7 @@ static int triggered;
 
 void execute_normal(void)
 {
+    struct regstruct *r = &regs;
     int blocklen;
     cpu_history pc_hist[MAXRUN];
     int new_cycles;
@@ -1937,32 +1918,27 @@ void execute_normal(void)
 
     if (check_for_cache_miss())
        return;
+
     total_cycles = 0;
     blocklen = 0;
-    start_pc_p = regs.pc_oldp;
-    start_pc = regs.pc;
-    for (;;)
-       /* Take note: This is the do-it-normal loop */
-       uae_u16 opcode = get_iword (0);
+    start_pc_p = r->pc_oldp;
+    start_pc = r->pc;
+    for (;;) {
+       /* Take note: This is the do-it-normal loop */
+       uae_u16 opcode = get_iword (r, 0);
 
        special_mem = DISTRUST_CONSISTENT_MEM;
-       pc_hist[blocklen].location = (uae_u16*)regs.pc_p;
-#if defined X86_ASSEMBLY
-       __asm__ __volatile__("\tpush %%ebp\n\tcall *%%ebx\n\tpop %%ebp" /* FIXME */
-                            : "=&a" (new_cycles)
-                            : "b" (cpufunctbl[opcode]), "0" (opcode)
-                            : "%edx", "%ecx", "%esi", "%edi",
-                            "%ebp", "memory", "cc");
-#else
-       new_cycles = (*cpufunctbl[opcode])(opcode);
-#endif
+       pc_hist[blocklen].location = (uae_u16*)r->pc_p;
+
+       new_cycles = (*cpufunctbl[opcode])(opcode, r);
+
        new_cycles &= cycles_mask;
        new_cycles |= cycles_val;
        do_cycles (new_cycles);
        total_cycles += new_cycles;
        pc_hist[blocklen].specmem = special_mem;
        blocklen++;
-       if (end_block(opcode) || blocklen >= MAXRUN || regs.spcflags) {
+       if (end_block(opcode) || blocklen >= MAXRUN || r->spcflags) {
            compile_block(pc_hist,blocklen,total_cycles);
            return; /* We will deal with the spcflags in the caller */
        }
@@ -1970,31 +1946,22 @@ void execute_normal(void)
           we'd have ended up inside that "if" */
     }
 }
-#endif
 
 typedef void compiled_handler(void);
 
 static void m68k_run_2a (void)
 {
     for (;;) {
-#if defined X86_ASSEMBLY
-       __asm__ __volatile__(
-           "\tpush %%ebp\n\tcall *%0\n\tpop %%ebp"  /* FIXME */
-           :: "m" (cache_tags[cacheline(regs.pc_p)].handler)
-           : "%edx", "%ecx", "%eax",
-           "%esi", "%ebx", "%edi", "%ebp", "memory", "cc");
-#else
        ((compiled_handler*)(pushall_call_handler))();
-#endif
        /* Whenever we return from that, we should check spcflags */
        if (regs.spcflags) {
-           if (do_specialties (0)) {
+           if (do_specialties (0, &regs)) {
                return;
            }
        }
     }
 }
-#endif
+#endif /* JIT */
 
 #ifndef CPUEMU_0
 
@@ -2059,33 +2026,31 @@ static void out_cd32io (uae_u32 pc)
 static void m68k_run_2p (void)
 {
     uae_u32 prefetch, prefetch_pc;
+    struct regstruct *r = &regs;
 
-    prefetch_pc = m68k_getpc ();
+    prefetch_pc = m68k_getpc (r);
     prefetch = get_long (prefetch_pc);
     for (;;) {
        int cycles;
        uae_u32 opcode;
-       uae_u32 pc = m68k_getpc ();
+       uae_u32 pc = m68k_getpc (r);
        if (pc == prefetch_pc)
            opcode = prefetch >> 16;
        else if (pc == prefetch_pc + 2)
            opcode = prefetch & 0xffff;
        else
            opcode = get_word (pc);
-#if COUNT_INSTRS == 2
-       if (table68k[opcode].handler != -1)
-           instrcount[table68k[opcode].handler]++;
-#elif COUNT_INSTRS == 1
-       instrcount[opcode]++;
-#endif
-       prefetch_pc = m68k_getpc () + 2;
+
+       count_instr (opcode);
+
+       prefetch_pc = m68k_getpc (r) + 2;
        prefetch = get_long (prefetch_pc);
-       cycles = (*cpufunctbl[opcode])(opcode);
+       cycles = (*cpufunctbl[opcode])(opcode, r);
        cycles &= cycles_mask;
        cycles |= cycles_val;
        do_cycles (cycles);
-       if (regs.spcflags) {
-           if (do_specialties (cycles))
+       if (r->spcflags) {
+           if (do_specialties (cycles, r))
                return;
        }
     }
@@ -2094,53 +2059,20 @@ static void m68k_run_2p (void)
 /* Same thing, but don't use prefetch to get opcode.  */
 static void m68k_run_2 (void)
 {
-    for (;;) {
+   struct regstruct *r = &regs;
+
+   for (;;) {
        int cycles;
-       uae_u32 opcode = get_iword (0);
+       uae_u32 opcode = get_iword (r, 0);
+       count_instr (opcode);
 
-#ifdef DEBUG_CD32IO
-       {
-           int pc = m68k_getpc();
-           if (pc >= 0xe57cc0 && pc <= 0xe57ef2)
-               out_cd32io (pc);
-           if (pc == cd32nextpc)
-               out_cd32io2 ();
-       }
-#endif
-#if 0
-       int pc = m68k_getpc();
-       if (pc == 0xd0000) {
-           write_log ("%x %x %x %x\n", pcs[0], pcs[1], pcs[2], pcs[3]);
-           activate_debugger();
-       }
-       if (pc != pcs[0] && pc <0xd00000) {
-           memmove (pcs + 1, pcs, 998 * 4);
-           pcs[0] = pc;
-       }
-#endif
-       /* assert (!regs.stopped && !(regs.spcflags & SPCFLAG_STOP)); */
-/*     regs_backup[backup_pointer = (backup_pointer + 1) % 16] = regs;*/
-#if COUNT_INSTRS == 2
-       if (table68k[opcode].handler != -1)
-           instrcount[table68k[opcode].handler]++;
-#elif COUNT_INSTRS == 1
-       instrcount[opcode]++;
-#endif
-#if defined X86_ASSEMBLY
-       __asm__ __volatile__("\tcall *%%ebx"
-                            : "=&a" (cycles) : "b" (cpufunctbl[opcode]), "0" (opcode)
-                            : "%edx", "%ecx",
-                            "%esi", "%edi", "%ebp", "memory", "cc");
-#else
-       cycles = (*cpufunctbl[opcode])(opcode);
-#endif
+       cycles = (*cpufunctbl[opcode])(opcode, r);
 
-       /*n_insns++;*/
        cycles &= cycles_mask;
        cycles |= cycles_val;
        do_cycles (cycles);
-       if (regs.spcflags) {
-           if (do_specialties (cycles))
+       if (r->spcflags) {
+           if (do_specialties (cycles, r))
                return;
        }
     }
@@ -2149,35 +2081,24 @@ static void m68k_run_2 (void)
 /* "MMU" 68k  */
 static void m68k_run_mmu (void)
 {
-    for (;;) {
+   for (;;) {
        int cycles;
-       uae_u32 opcode = get_iword (0);
+       uae_u32 opcode = get_iword (&regs, 0);
        mmu_backup_regs = regs;
-       cycles = (*cpufunctbl[opcode])(opcode);
+       cycles = (*cpufunctbl[opcode])(opcode, &regs);
        cycles &= cycles_mask;
        cycles |= cycles_val;
        if (mmu_triggered)
            mmu_do_hit();
        do_cycles (cycles);
        if (regs.spcflags) {
-           if (do_specialties (cycles))
+           if (do_specialties (cycles, &regs))
                return;
        }
     }
 }
 
-#endif
-
-#ifdef X86_ASSEMBLY
-STATIC_INLINE void m68k_run1 (void (*func)(void))
-{
-    /* Work around compiler bug: GCC doesn't push %ebp in m68k_run_1. */
-    __asm__ __volatile__ ("pushl %%ebp\n\tcall *%0\n\tpopl %%ebp"
-                         : : "r" (func) : "%eax", "%edx", "%ecx", "memory", "cc");
-}
-#else
-#define        m68k_run1(F) (F) ()
-#endif
+#endif /* CPUEMU_0 */
 
 int in_m68k_go = 0;
 
@@ -2187,7 +2108,7 @@ static void exception2_handle (uaecptr addr, uaecptr fault)
     last_fault_for_exception_3 = fault;
     last_writeaccess_for_exception_3 = 0;
     last_instructionaccess_for_exception_3 = 0;
-    Exception (2, addr);
+    Exception (2, &regs, addr);
 }
 
 void m68k_go (int may_quit)
@@ -2202,15 +2123,18 @@ void m68k_go (int may_quit)
 
     in_m68k_go++;
     for (;;) {
+       void (*run_func)(void);
        if (quit_program > 0) {
            int hardreset = quit_program == 3 ? 1 : 0;
            if (quit_program == 1)
                break;
            quit_program = 0;
+#ifdef SAVESTATE
            if (savestate_state == STATE_RESTORE)
                restore_state (savestate_fname);
            else if (savestate_state == STATE_REWIND)
                savestate_rewind ();
+#endif
            /* following three lines must not be reordered or
             * fastram state restore breaks
             */
@@ -2221,19 +2145,21 @@ void m68k_go (int may_quit)
                memset (chipmemory, 0, allocated_chipmem);
                write_log ("chipmem cleared\n");
            }
+#ifdef SAVESTATE
            /* We may have been restoring state, but we're done now.  */
            if (savestate_state == STATE_RESTORE || savestate_state == STATE_REWIND) {
                map_overlay (1);
-               fill_prefetch_slow (); /* compatibility with old state saves */
+               fill_prefetch_slow (&regs); /* compatibility with old state saves */
            }
            savestate_restore_finish ();
-           fill_prefetch_slow ();
+#endif
+           fill_prefetch_slow (&regs);
            if (currprefs.produce_sound == 0)
                eventtab[ev_audio].active = 0;
            handle_active_events ();
            if (regs.spcflags)
-               do_specialties (0);
-           m68k_setpc (regs.pc);
+               do_specialties (0, &regs);
+           m68k_setpc (&regs, regs.pc);
        }
 
 #ifdef DEBUGGER
@@ -2259,27 +2185,29 @@ void m68k_go (int may_quit)
        if (regs.spcflags) {
            uae_u32 of = regs.spcflags;
            regs.spcflags &= ~(SPCFLAG_BRK | SPCFLAG_MODE_CHANGE);
-           do_specialties (0);
+           do_specialties (0, &regs);
            regs.spcflags |= of & (SPCFLAG_BRK | SPCFLAG_MODE_CHANGE);
        }
 #ifndef JIT
-       m68k_run1 (currprefs.cpu_level == 0 && currprefs.cpu_cycle_exact ? m68k_run_1_ce :
+       run_func = currprefs.cpu_level == 0 && currprefs.cpu_cycle_exact ? m68k_run_1_ce :
                    currprefs.cpu_level == 0 && currprefs.cpu_compatible ? m68k_run_1 :
-                   currprefs.cpu_compatible ? m68k_run_2p : m68k_run_2);
+                   currprefs.cpu_compatible ? m68k_run_2p : m68k_run_2;
 #else
        if (mmu_enabled && !currprefs.cachesize) {
-           m68k_run1 (m68k_run_mmu);
+           run_func = m68k_run_mmu;
        } else {
-           m68k_run1 (currprefs.cpu_cycle_exact && currprefs.cpu_level == 0 ? m68k_run_1_ce :
+           run_func = currprefs.cpu_cycle_exact && currprefs.cpu_level == 0 ? m68k_run_1_ce :
                   currprefs.cpu_compatible > 0 && currprefs.cpu_level == 0 ? m68k_run_1 :
                   currprefs.cpu_level >= 2 && currprefs.cachesize ? m68k_run_2a :
-                  currprefs.cpu_compatible ? m68k_run_2p : m68k_run_2);
+                  currprefs.cpu_compatible ? m68k_run_2p : m68k_run_2;
        }
 #endif
+       run_func ();
     }
     in_m68k_go--;
 }
 
+#if 0
 static void m68k_verify (uaecptr addr, uaecptr *nextpc)
 {
     uae_u32 opcode, val;
@@ -2296,22 +2224,27 @@ static void m68k_verify (uaecptr addr, uaecptr *nextpc)
 
     if (dp->suse) {
        if (!verify_ea (dp->sreg, dp->smode, dp->size, &val)) {
-           Exception (3, 0);
+           Exception (3, &regs, 0);
            return;
        }
     }
     if (dp->duse) {
        if (!verify_ea (dp->dreg, dp->dmode, dp->size, &val)) {
-           Exception (3, 0);
+           Exception (3, &regs, 0);
            return;
        }
     }
 }
+#endif
+
+static const char* ccnames[] =
+{ "T ","F ","HI","LS","CC","CS","NE","EQ",
+  "VC","VS","PL","MI","GE","LT","GT","LE" };
 
 void m68k_disasm_2 (void *f, uaecptr addr, uaecptr *nextpc, int cnt, uae_u32 *seaddr, uae_u32 *deaddr, int safemode)
 {
     uaecptr newpc = 0;
-    m68kpc_offset = addr - m68k_getpc ();
+    m68kpc_offset = addr - m68k_getpc (&regs);
 
     while (cnt-- > 0) {
        char instrname[100], *ccpt;
@@ -2330,7 +2263,7 @@ void m68k_disasm_2 (void *f, uaecptr addr, uaecptr *nextpc, int cnt, uae_u32 *se
        for (lookup = lookuptab;lookup->mnemo != dp->mnemo; lookup++)
            ;
 
-       f_out (f, "%08lx ", m68k_getpc () + m68kpc_offset);
+       f_out (f, "%08lx ", m68k_getpc (&regs) + m68kpc_offset);
        m68kpc_offset += 2;
 
        strcpy (instrname, lookup->name);
@@ -2346,13 +2279,13 @@ void m68k_disasm_2 (void *f, uaecptr addr, uaecptr *nextpc, int cnt, uae_u32 *se
        }
 
        if (dp->suse) {
-           newpc = m68k_getpc () + m68kpc_offset;
+           newpc = m68k_getpc (&regs) + m68kpc_offset;
            newpc += ShowEA (0, opcode, dp->sreg, dp->smode, dp->size, instrname, seaddr, safemode);
        }
        if (dp->suse && dp->duse)
            strcat (instrname, ",");
        if (dp->duse) {
-           newpc = m68k_getpc () + m68kpc_offset;
+           newpc = m68k_getpc (&regs) + m68kpc_offset;
            newpc += ShowEA (0, opcode, dp->dreg, dp->dmode, dp->size, instrname, deaddr, safemode);
        }
 
@@ -2366,7 +2299,7 @@ void m68k_disasm_2 (void *f, uaecptr addr, uaecptr *nextpc, int cnt, uae_u32 *se
        if (ccpt != 0) {
            if (deaddr)
                *deaddr = newpc;
-           if (cctrue(dp->cc))
+           if (cctrue(&regs.ccrflags, dp->cc))
                f_out (f, " == %08lx (TRUE)", newpc);
            else
                f_out (f, " == %08lx (FALSE)", newpc);
@@ -2378,7 +2311,7 @@ void m68k_disasm_2 (void *f, uaecptr addr, uaecptr *nextpc, int cnt, uae_u32 *se
        f_out (f, "\n");
     }
     if (nextpc)
-       *nextpc = m68k_getpc () + m68kpc_offset;
+       *nextpc = m68k_getpc (&regs) + m68kpc_offset;
 }
 
 void m68k_disasm_ea (void *f, uaecptr addr, uaecptr *nextpc, int cnt, uae_u32 *seaddr, uae_u32 *deaddr)
@@ -2404,7 +2337,7 @@ void sm68k_disasm(char *instrname, char *instrcode, uaecptr addr, uaecptr *nextp
 
     uaecptr newpc = 0;
 
-    m68kpc_offset = addr - m68k_getpc ();
+    m68kpc_offset = addr - m68k_getpc (&regs);
 
     oldpc = m68kpc_offset;
     opcode = get_iword_1 (m68kpc_offset);
@@ -2429,13 +2362,13 @@ void sm68k_disasm(char *instrname, char *instrcode, uaecptr addr, uaecptr *nextp
     }
 
     if (dp->suse) {
-       newpc = m68k_getpc () + m68kpc_offset;
+       newpc = m68k_getpc (&regs) + m68kpc_offset;
        newpc += ShowEA (0, opcode, dp->sreg, dp->smode, dp->size, instrname, NULL, 0);
     }
     if (dp->suse && dp->duse)
        strcat (instrname, ",");
     if (dp->duse) {
-       newpc = m68k_getpc () + m68kpc_offset;
+       newpc = m68k_getpc (&regs) + m68kpc_offset;
        newpc += ShowEA (0, opcode, dp->dreg, dp->dmode, dp->size, instrname, NULL, 0);
     }
 
@@ -2450,7 +2383,7 @@ void sm68k_disasm(char *instrname, char *instrcode, uaecptr addr, uaecptr *nextp
     }
 
     if (nextpc)
-       *nextpc = m68k_getpc () + m68kpc_offset;
+       *nextpc = m68k_getpc (&regs) + m68kpc_offset;
 }
 
 void m68k_dumpstate (void *f, uaecptr *nextpc)
@@ -2458,21 +2391,22 @@ void m68k_dumpstate (void *f, uaecptr *nextpc)
     int i;
 
     for (i = 0; i < 8; i++){
-       f_out (f, "D%d: %08lx ", i, m68k_dreg(regs, i));
+       f_out (f, "D%d: %08lx ", i, m68k_dreg(&regs, i));
        if ((i & 3) == 3) f_out (f, "\n");
     }
     for (i = 0; i < 8; i++){
-       f_out (f, "A%d: %08lx ", i, m68k_areg(regs, i));
+       f_out (f, "A%d: %08lx ", i, m68k_areg(&regs, i));
        if ((i & 3) == 3) f_out (f, "\n");
     }
-    if (regs.s == 0) regs.usp = m68k_areg(regs, 7);
-    if (regs.s && regs.m) regs.msp = m68k_areg(regs, 7);
-    if (regs.s && regs.m == 0) regs.isp = m68k_areg(regs, 7);
+    if (regs.s == 0) regs.usp = m68k_areg(&regs, 7);
+    if (regs.s && regs.m) regs.msp = m68k_areg(&regs, 7);
+    if (regs.s && regs.m == 0) regs.isp = m68k_areg(&regs, 7);
     f_out (f, "USP=%08lx ISP=%08lx MSP=%08lx VBR=%08lx\n",
        regs.usp,regs.isp,regs.msp,regs.vbr);
     f_out (f, "T=%d%d S=%d M=%d X=%d N=%d Z=%d V=%d C=%d IMASK=%d STP=%d\n",
        regs.t1, regs.t0, regs.s, regs.m,
-       GET_XFLG, GET_NFLG, GET_ZFLG, GET_VFLG, GET_CFLG,
+       GET_XFLG(&regs.ccrflags), GET_NFLG(&regs.ccrflags), GET_ZFLG(&regs.ccrflags),
+       GET_VFLG(&regs.ccrflags), GET_CFLG(&regs.ccrflags),
        regs.intmask, regs.stopped);
 #ifdef FPUEMU
     if (currprefs.cpu_level >= 2) {
@@ -2499,11 +2433,12 @@ void m68k_dumpstate (void *f, uaecptr *nextpc)
        f_out (f, "Prefetch %04x (%s) %04x (%s)\n", regs.irc, lookup1->name, regs.ir, lookup2->name);
     }
 
-    m68k_disasm (f, m68k_getpc (), nextpc, 1);
+    m68k_disasm (f, m68k_getpc (&regs), nextpc, 1);
     if (nextpc)
        f_out (f, "Next PC: %08lx\n", *nextpc);
 }
 
+#ifdef SAVESTATE
 
 /* CPU save/restore code */
 
@@ -2559,7 +2494,7 @@ uae_u8 *restore_cpu (uae_u8 *src)
     l = restore_u32();
     if (l & CPUMODE_HALT) {
        regs.stopped = 1;
-       set_special (SPCFLAG_STOP);
+       set_special (&regs, SPCFLAG_STOP);
     } else
        regs.stopped = 0;
     if (model >= 68010) {
@@ -2583,8 +2518,8 @@ uae_u8 *restore_cpu (uae_u8 *src)
 
 void restore_cpu_finish(void)
 {
-    init_m68k_full ();
-    m68k_setpc (regs.pc);
+    init_m68k ();
+    m68k_setpc (&regs, regs.pc);
 }
 
 static int cpumodel[] = { 68000, 68010, 68020, 68020, 68040, 68060 };
@@ -2602,10 +2537,10 @@ uae_u8 *save_cpu (int *len, uae_u8 *dstptr)
     save_u32 (model);                                  /* MODEL */
     save_u32 (currprefs.address_space_24 ? 1 : 0);     /* FLAGS */
     for(i = 0;i < 15; i++) save_u32 (regs.regs[i]);    /* D0-D7 A0-A6 */
-    save_u32 (m68k_getpc ());                          /* PC */
+    save_u32 (m68k_getpc (&regs));                     /* PC */
     save_u16 (regs.irc);                               /* prefetch */
     save_u16 (regs.ir);                                        /* instruction prefetch */
-    MakeSR ();
+    MakeSR (&regs);
     save_u32 (!regs.s ? regs.regs[15] : regs.usp);     /* USP */
     save_u32 (regs.s ? regs.regs[15] : regs.isp);      /* ISP */
     save_u16 (regs.sr);                                        /* SR/CCR */
@@ -2624,6 +2559,8 @@ uae_u8 *save_cpu (int *len, uae_u8 *dstptr)
     return dstbak;
 }
 
+#endif /* SAVESTATE */
+
 static void exception3f (uae_u32 opcode, uaecptr addr, uaecptr fault, int writeaccess, int instructionaccess)
 {
     last_addr_for_exception_3 = addr;
@@ -2631,7 +2568,7 @@ static void exception3f (uae_u32 opcode, uaecptr addr, uaecptr fault, int writea
     last_op_for_exception_3 = opcode;
     last_writeaccess_for_exception_3 = writeaccess;
     last_instructionaccess_for_exception_3 = instructionaccess;
-    Exception (3, fault);
+    Exception (3, &regs, fault);
 }
 
 void exception3 (uae_u32 opcode, uaecptr addr, uaecptr fault)
@@ -2647,15 +2584,15 @@ void exception3i (uae_u32 opcode, uaecptr addr, uaecptr fault)
 void exception2 (uaecptr addr, uaecptr fault)
 {
     write_log ("delayed exception2!\n");
-    regs.panic_pc = m68k_getpc();
+    regs.panic_pc = m68k_getpc (&regs);
     regs.panic_addr = addr;
     regs.panic = 2;
-    set_special (SPCFLAG_BRK);
-    m68k_setpc (0xf80000);
+    set_special (&regs, SPCFLAG_BRK);
+    m68k_setpc (&regs, 0xf80000);
 #ifdef JIT
-    set_special(SPCFLAG_END_COMPILE);
+    set_special(&regs, SPCFLAG_END_COMPILE);
 #endif
-    fill_prefetch_slow ();
+    fill_prefetch_slow (&regs);
 }
 
 void cpureset (void)
@@ -2667,15 +2604,15 @@ void cpureset (void)
        customreset ();
        return;
     }
-    ins = get_word (m68k_getpc() + 2);
+    ins = get_word (m68k_getpc(&regs) + 2);
     if ((ins & ~7) == 0x4ed0) {
        int reg = ins & 7;
-       uae_u32 addr = m68k_areg (regs, reg);
+       uae_u32 addr = m68k_areg (&regs, reg);
        write_log ("reset/jmp (ax) combination emulated\n");
        customreset ();
        if (addr < 0x80000)
            addr += 0xf80000;
-       m68k_setpc (addr);
+       m68k_setpc (&regs, addr);
     }
 #endif
 }
index d2328953e2433a9e803eb8a3341aba8ee4e74c99..04ed3d344e630f54e0c154b37ee9c61de2b77275 100755 (executable)
 
 #if defined(AHI)
 
-#ifdef __GNUC__
-#define INITGUID
-#endif 
+#include <ctype.h>
+#include <assert.h>
+
 #include <windows.h>
 #include <stdlib.h>
 #include <stdarg.h>
-#include <mmsystem.h>
 #include <dsound.h>
 #include <stdio.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <io.h>
-#include "winspool.h"
-#include "sysdeps.h"
 
-#include "config.h"
+#include "sysdeps.h"
 #include "options.h"
 #include "memory.h"
 #include "events.h"
 #include "custom.h"
-#include "gensound.h"
 #include "newcpu.h"
-#include "threaddep/thread.h"
-#include <ctype.h>
-#include <assert.h>
+#include "traps.h"
 #include "od-win32/win32.h"
-#include "gui.h"
 #include "picasso96_win.h"
 #include "sounddep/sound.h"
-#include "od-win32/ahidsound.h"
-#include "vfw.h"
 #include "dxwrap.h"
 #include "win32.h"
 #include "win32gfx.h"
-#include "inputdevice.h"
-#include "avioutput.h"
 #include "parser.h"
 #include "enforcer.h"
+#include "ahidsound.h"
 
 static long samples,playchannel,intcount,norec;
 int ahi_on;
@@ -107,23 +94,23 @@ static struct winuae *a6;
 #define SET_NATIVE_FUNC2(x) native_func = (uae_u32 (*)(uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32,uae_u32,uae_u32))(x)
 #define CALL_NATIVE_FUNC2( d1,d2,d3,d4,d5,d6,d7,a1,a2,a3,a4,a5,a6,a7) if(native_func) return native_func( d1,d2,d3,d4,d5,d6,d7,a1,a2,a3,a4,a5,a6,a7,regs_ )
 
-static uae_u32 emulib_ExecuteNativeCode2 (void)
+static uae_u32 REGPARAM2 emulib_ExecuteNativeCode2 (TrapContext *context)
 { 
-    uae_u8* object_UAM = (uae_u8*) m68k_areg( regs, 0 );
-    uae_u32 d1 = m68k_dreg( regs, 1 );
-    uae_u32 d2 = m68k_dreg( regs, 2 );
-    uae_u32 d3 = m68k_dreg( regs, 3 );
-    uae_u32 d4 = m68k_dreg( regs, 4 );
-    uae_u32 d5 = m68k_dreg( regs, 5 );
-    uae_u32 d6 = m68k_dreg( regs, 6 );
-    uae_u32 d7 = m68k_dreg( regs, 7 );
-    uae_u32 a1 = m68k_areg( regs, 1 );
-    uae_u32 a2 = m68k_areg( regs, 2 );
-    uae_u32 a3 = m68k_areg( regs, 3 );
-    uae_u32 a4 = m68k_areg( regs, 4 );
-    uae_u32 a5 = m68k_areg( regs, 5 );
-    uae_u32 a7 = m68k_areg( regs, 7 );
-    uae_u32 regs_ = (uae_u32)&regs;
+    uae_u8* object_UAM = (uae_u8*) m68k_areg(&context->regs, 0);
+    uae_u32 d1 = m68k_dreg(&context->regs, 1);
+    uae_u32 d2 = m68k_dreg(&context->regs, 2);
+    uae_u32 d3 = m68k_dreg(&context->regs, 3);
+    uae_u32 d4 = m68k_dreg(&context->regs, 4);
+    uae_u32 d5 = m68k_dreg(&context->regs, 5);
+    uae_u32 d6 = m68k_dreg(&context->regs, 6);
+    uae_u32 d7 = m68k_dreg(&context->regs, 7);
+    uae_u32 a1 = m68k_areg(&context->regs, 1);
+    uae_u32 a2 = m68k_areg(&context->regs, 2);
+    uae_u32 a3 = m68k_areg(&context->regs, 3);
+    uae_u32 a4 = m68k_areg(&context->regs, 4);
+    uae_u32 a5 = m68k_areg(&context->regs, 5);
+    uae_u32 a7 = m68k_areg(&context->regs, 7);
+    uae_u32 regs_ = (uae_u32)&context->regs;
     CREATE_NATIVE_FUNC_PTR2;
     uaevar.z3offset = (uae_u32)(get_real_address (0x10000000) - 0x10000000);
     uaevar.amigawnd = hAmigaWnd;
@@ -503,7 +490,7 @@ static void *bswap_buffer = NULL;
 static uae_u32 bswap_buffer_size = 0;
 static double syncdivisor;
 
-uae_u32 ahi_demux (void)
+uae_u32 REGPARAM2 ahi_demux (TrapContext *context)
 {
 //use the extern int (6 #13)  
 // d0 0=opensound      d1=unit d2=samplerate d3=blksize ret: sound frequency
@@ -538,7 +525,7 @@ uae_u32 ahi_demux (void)
 // d0=108 free swap array
 // d0=200 ahitweak              d1=offset for dsound position pointer
 
-    int opcode = m68k_dreg (regs, 0);
+    int opcode = m68k_dreg (&context->regs, 0);
     switch (opcode)
     {
        int i,slen,t,todo,byte1,byte2;
@@ -552,17 +539,17 @@ uae_u32 ahi_demux (void)
            cap_pos = 0;
            sound_bits_ahi = 16;
            sound_channels_ahi = 2;
-           sound_freq_ahi = m68k_dreg (regs, 2);
-           amigablksize = m68k_dreg (regs, 3);
+           sound_freq_ahi = m68k_dreg (&context->regs, 2);
+           amigablksize = m68k_dreg (&context->regs, 3);
            sound_freq_ahi = ahi_open_sound();
            uaevar.changenum--;
        return sound_freq_ahi;
        case 6: /* new open function */
            cap_pos = 0;
-           sound_freq_ahi = m68k_dreg (regs, 2);
-           amigablksize = m68k_dreg (regs, 3);
-           sound_channels_ahi = m68k_dreg (regs, 4);
-           sound_bits_ahi = m68k_dreg (regs, 5);
+           sound_freq_ahi = m68k_dreg (&context->regs, 2);
+           amigablksize = m68k_dreg (&context->regs, 3);
+           sound_channels_ahi = m68k_dreg (&context->regs, 4);
+           sound_bits_ahi = m68k_dreg (&context->regs, 5);
            sound_freq_ahi = ahi_open_sound();
            uaevar.changenum--;
        return sound_freq_ahi;
@@ -574,7 +561,7 @@ uae_u32 ahi_demux (void)
 
        case 2:
        {
-           uaecptr addr = m68k_areg (regs, 0);
+           uaecptr addr = m68k_areg (&context->regs, 0);
            for (i = 0; i < amigablksize * 4; i += 4)
                *ahisndbufpt++ = get_long(addr + i);
            ahi_finish_sound_buffer();
@@ -609,7 +596,7 @@ uae_u32 ahi_demux (void)
            } else {
                cap_pos = 0;
            }  
-           addr = m68k_areg (regs, 0);
+           addr = m68k_areg (&context->regs, 0);
            sndbufrecpt = (unsigned int*)pos1;
            t=t/4;
            for (i = 0; i < t; i++) {
@@ -647,13 +634,13 @@ uae_u32 ahi_demux (void)
 
        case 11:
            for (i = 0; i < clipsize; i++)
-               put_byte(m68k_areg (regs, 0) + i,clipdat[i]);
+               put_byte(m68k_areg (&context->regs, 0) + i,clipdat[i]);
            CloseClipboard();
        return 0;
 
        case 12:
        {
-           uae_u8 *addr = get_real_address (m68k_areg (regs, 0));
+           uae_u8 *addr = get_real_address (m68k_areg (&context->regs, 0));
            if (OpenClipboard (0)) {
                EmptyClipboard();
                slen = strlen(addr);
@@ -679,15 +666,15 @@ uae_u32 ahi_demux (void)
            extern uae_u16 vtotal;
            extern unsigned int new_beamcon0;
            p96hack_vpos2 = 0;
-           if (m68k_dreg (regs, 1) > 0)
-           p96hack_vpos2 = 15625 / m68k_dreg (regs, 1);
+           if (m68k_dreg (&context->regs, 1) > 0)
+           p96hack_vpos2 = 15625 / m68k_dreg (&context->regs, 1);
            p96refresh_active=1;
            picasso_refresh (0);
        } //end for higher P96 mouse draw rate
        return 0;
 
        case 20:
-       return enforcer_enable(m68k_dreg (regs, 1));
+       return enforcer_enable(m68k_dreg (&context->regs, 1));
 
        case 21:
        return enforcer_disable();
@@ -702,7 +689,7 @@ uae_u32 ahi_demux (void)
        {
            char *dllname;
            uae_u32 result;
-           dllname = ( char *) m68k_areg (regs, 0);
+           dllname = ( char *) m68k_areg (&context->regs, 0);
            dllname = (char *)get_real_address ((uae_u32)dllname);
            result=(uae_u32) LoadLibrary(dllname);
            write_log("%s windows dll/alib loaded at %d (0 mean failure)\n",dllname,result); 
@@ -714,8 +701,8 @@ uae_u32 ahi_demux (void)
        {
            HMODULE m;
            char *funcname;
-           m = (HMODULE) m68k_dreg (regs, 1);
-           funcname = (char *)m68k_areg (regs, 0);
+           m = (HMODULE) m68k_dreg (&context->regs, 1);
+           funcname = (char *)m68k_areg (&context->regs, 0);
            funcname = (char *)get_real_address ((uae_u32)funcname);
        return (uae_u32) GetProcAddress(m,funcname);
        }
@@ -726,7 +713,7 @@ uae_u32 ahi_demux (void)
            unsigned long rate1;
            double v;
            rate1 = read_processor_time(); 
-           ret = emulib_ExecuteNativeCode2 ();
+           ret = emulib_ExecuteNativeCode2 (context);
            rate1 = read_processor_time() - rate1;
            v = syncdivisor * rate1;
            if (v > 0) {
@@ -740,7 +727,7 @@ uae_u32 ahi_demux (void)
        case 103:       //close dll
        {
            HMODULE libaddr;
-           libaddr = (HMODULE) m68k_dreg (regs, 1);
+           libaddr = (HMODULE) m68k_dreg (&context->regs, 1);
            FreeLibrary(libaddr);
            return 0;
        }
@@ -762,8 +749,8 @@ uae_u32 ahi_demux (void)
                    //a0 = start address
                    //d1 = number of 16bit vars
                    //returns address of new array
-           src = m68k_areg(regs, 0);
-           num_vars = m68k_dreg(regs, 1);
+           src = m68k_areg(&context->regs, 0);
+           num_vars = m68k_dreg(&context->regs, 1);
 
            if (bswap_buffer_size < num_vars * 2) {
                bswap_buffer_size = (num_vars + 1024) * 2;
@@ -825,8 +812,8 @@ uae_u32 ahi_demux (void)
                    //a0 = start address
                    //d1 = number of 32bit vars
                    //returns address of new array
-           src = m68k_areg(regs, 0);
-           num_vars = m68k_dreg(regs, 1);
+           src = m68k_areg(&context->regs, 0);
+           num_vars = m68k_dreg(&context->regs, 1);
            if (bswap_buffer_size < num_vars * 4) {
                bswap_buffer_size = (num_vars + 16384) * 4;
                free(bswap_buffer);
@@ -882,8 +869,8 @@ uae_u32 ahi_demux (void)
 #endif
 
        case 200:
-           ahitweak = m68k_dreg (regs, 1);
-           ahi_pollrate = m68k_dreg (regs, 2);
+           ahitweak = m68k_dreg (&context->regs, 1);
+           ahi_pollrate = m68k_dreg (&context->regs, 2);
            if (ahi_pollrate < 10)
                ahi_pollrate = 10;
            if (ahi_pollrate > 60)
index cd33aaa93cbc630cdc04944a8ffc68b323f0416d..f1da32bc0c801e6edc0637c02d1145164f6f56d9 100755 (executable)
@@ -1,5 +1,5 @@
-extern void ahi_updatesound( int force );
-extern uae_u32 ahi_demux(void);
+extern void ahi_updatesound(int force);
+extern uae_u32 REGPARAM2 ahi_demux(TrapContext*);
 extern int ahi_open_sound (void);
 extern void ahi_close_sound (void);
 extern void ahi_finish_sound_buffer( void );
index a21793687203f527b7561992429c1a257b6b0c21..eef5d8ed56e33bc5239467c1669f1aaddb5111a8 100755 (executable)
@@ -200,7 +200,7 @@ static int AVIOutput_AllocateAudio(void)
 
     // set the source format
     wfxSrc.wFormatTag = WAVE_FORMAT_PCM;
-    wfxSrc.nChannels = (currprefs.sound_stereo == 3 || currprefs.sound_stereo == 2) ? 4 : (currprefs.sound_stereo ? 2 : 1);
+    wfxSrc.nChannels = currprefs.sound_stereo == 3 ? 4 : (currprefs.sound_stereo ? 2 : 1);
     wfxSrc.nSamplesPerSec = workprefs.sound_freq;
     wfxSrc.nBlockAlign = wfxSrc.nChannels * (workprefs.sound_bits / 8);
     wfxSrc.nAvgBytesPerSec = wfxSrc.nBlockAlign * wfxSrc.nSamplesPerSec;
@@ -829,7 +829,7 @@ static void writewavheader (uae_u32 size)
     uae_u16 tw;
     uae_u32 tl;
     int bits = 16;
-    int channels = (currprefs.sound_stereo == 3 || currprefs.sound_stereo == 2) ? 4 : (currprefs.sound_stereo ? 2 : 1);
+    int channels = currprefs.sound_stereo == 3 ? 4 : (currprefs.sound_stereo ? 2 : 1);
 
     fseek (wavfile, 0, SEEK_SET);
     fwrite ("RIFF", 1, 4, wavfile);
index 2299e054843debed34b948b65e8b96c194b4b240..6679d5b7b2958bf6c54e6e9130d326be0154ae41 100755 (executable)
@@ -12,7 +12,6 @@
 
 #ifdef WINDDK
 
-#include "config.h"
 #include "uae.h"
 #include "threaddep/thread.h"
 #include "blkdev.h"
index 16e0b58e7fd4898f1dd4f76d5db39aa64dad5d84..523e9b9a53fc4e6a6d1b7068bd11224eb1186cc7 100755 (executable)
 #include <stddef.h>
 #include <process.h>
 
-#include "config.h"   
 #include "options.h"
 #include "memory.h"
 #include "custom.h"
 #include "events.h"
 #include "newcpu.h" 
 #include "autoconf.h"
+#include "traps.h"
 #include "bsdsocket.h"
 
-#include "osdep/exectasks.h"
 #include "threaddep/thread.h"
 #include "native2amiga.h"
 #include "resource.h"
@@ -52,17 +51,17 @@ static DWORD threadid;
 #define THREADEND(result) _endthreadex(result)
 #endif
 
-#define SETERRNO seterrno(sb,WSAGetLastError()-WSABASEERR)
-#define SETHERRNO setherrno(sb,WSAGetLastError()-WSABASEERR)
-#define WAITSIGNAL waitsig(sb)
+#define SETERRNO bsdsocklib_seterrno(sb, WSAGetLastError() - WSABASEERR)
+#define SETHERRNO bsdsocklib_setherrno(sb, WSAGetLastError() - WSABASEERR)
+#define WAITSIGNAL waitsig(context, sb)
 
 #define SETSIGNAL addtosigqueue(sb,0)
-#define CANCELSIGNAL cancelsig(sb)
+#define CANCELSIGNAL cancelsig(context, sb)
 
 #define FIOSETOWN _IOW('f', 124, long)   /* set owner (struct Task *) */
 #define FIOGETOWN _IOR('f', 123, long)   /* get owner (struct Task *) */
 
-#define BEGINBLOCKING if (sb->ftable[sd-1] & SF_BLOCKING) sb->ftable[sd-1] |= SF_BLOCKINGINPROGRESS
+#define BEGINBLOCKING if (sb->ftable[sd-1] & SF_BLOCKING) sb->ftable[sd - 1] |= SF_BLOCKINGINPROGRESS
 #define ENDBLOCKING sb->ftable[sd-1] &= ~SF_BLOCKINGINPROGRESS
 
 static WSADATA wsbData;
@@ -116,67 +115,58 @@ static CRITICAL_SECTION SockThreadCS;
 #define SF_RAW_RICMP 0x04000000
 
 typedef        struct ip_option_information {
-    u_char Ttl;                /* Time To Live (used for traceroute) */
-    u_char Tos;        /* Type Of Service (usually 0) */
-    u_char Flags;      /* IP header flags (usually 0) */
-    u_char OptionsSize; /* Size of options data (usually 0, max 40) */
-    u_char FAR *OptionsData;   /* Options data buffer */
+       u_char Ttl;             /* Time To Live (used for traceroute) */
+       u_char Tos;     /* Type Of Service (usually 0) */
+       u_char Flags;   /* IP header flags (usually 0) */
+       u_char OptionsSize; /* Size of options data (usually 0, max 40) */
+       u_char FAR *OptionsData;   /* Options data buffer */
 } IPINFO, *PIPINFO, FAR *LPIPINFO;
 
 static void bsdsetpriority (HANDLE thread)
 {
-    int pri = os_winnt ? THREAD_PRIORITY_NORMAL : priorities[currprefs.win32_active_priority].value;
-    SetThreadPriority(thread, pri);
+       int pri = os_winnt ? THREAD_PRIORITY_NORMAL : priorities[currprefs.win32_active_priority].value;
+       SetThreadPriority(thread, pri);
 }
 
 static int mySockStartup( void )
 {
-    int result = 0;
-    SOCKET dummy;
-    DWORD lasterror;
+       int result = 0;
+       SOCKET dummy;
+       DWORD lasterror;
 
-    if (WSAStartup(MAKEWORD( SOCKVER_MAJOR, SOCKVER_MINOR ), &wsbData))
-    {
+       if (WSAStartup(MAKEWORD( SOCKVER_MAJOR, SOCKVER_MINOR ), &wsbData)) {
            lasterror = WSAGetLastError();
-           
-           if( lasterror == WSAVERNOTSUPPORTED )
-           {
+
+           if( lasterror == WSAVERNOTSUPPORTED ) {
                        char szMessage[ MAX_DPATH ];
                        WIN32GUI_LoadUIString( IDS_WSOCK2NEEDED, szMessage, MAX_DPATH );
                                        gui_message( szMessage );
-           }
-           else
+           } else
                        write_log( "BSDSOCK: ERROR - Unable to initialize Windows socket layer! Error code: %d\n", lasterror );
            return 0;
-    }
+       }
 
-    if (LOBYTE (wsbData.wVersion) != SOCKVER_MAJOR || HIBYTE (wsbData.wVersion) != SOCKVER_MINOR )
-    {
-               char szMessage[ MAX_DPATH ];
-               WIN32GUI_LoadUIString( IDS_WSOCK2NEEDED, szMessage, MAX_DPATH );
-               gui_message( szMessage );
+       if (LOBYTE (wsbData.wVersion) != SOCKVER_MAJOR || HIBYTE (wsbData.wVersion) != SOCKVER_MINOR) {
+               char szMessage[MAX_DPATH];
+               WIN32GUI_LoadUIString(IDS_WSOCK2NEEDED, szMessage, MAX_DPATH);
+               gui_message(szMessage);
 
                return 0;
-    }
-    else
-    {
-       write_log( "BSDSOCK: using %s\n", wsbData.szDescription );
+       } else {
+               write_log( "BSDSOCK: using %s\n", wsbData.szDescription );
                // make sure WSP/NSPStartup gets called from within the regular stack
                // (Windows 95/98 need this)
-               if((dummy = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP)) != INVALID_SOCKET) 
-               {
+               if((dummy = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP)) != INVALID_SOCKET)  {
                        closesocket(dummy);
                        result = 1;
-               }
-               else
-               {
+               } else {
                        write_log( "BSDSOCK: ERROR - WSPStartup/NSPStartup failed! Error code: %d\n",
                                WSAGetLastError() );
                        result = 0;
                }
-    }
+       }
 
-    return result;
+       return result;
 }
 
 static int socket_layer_initialized = 0;
@@ -185,17 +175,11 @@ int init_socket_layer(void)
 {
     int result = 0;
 
-#ifndef CAN_DO_STACK_MAGIC
-    currprefs.socket_emu = 0;
-#endif
-    if(currprefs.socket_emu)
-    {
-               if((result = mySockStartup()))
-               {
+    if(currprefs.socket_emu) {
+               if((result = mySockStartup())) {
                        InitializeCriticalSection(&csSigQueueLock);
 
-                       if(hSockThread == NULL)
-                       {
+                       if(hSockThread == NULL) {
                                WNDCLASS wc;    // Set up an invisible window and dummy wndproc
                                
                                InitializeCriticalSection( &SockThreadCS );
@@ -212,35 +196,31 @@ int init_socket_layer(void)
                                wc.hbrBackground = GetStockObject (BLACK_BRUSH);
                                wc.lpszMenuName = 0;
                                wc.lpszClassName = "SocketFun";
-                               if(RegisterClass(&wc))
-                               {
+                               if(RegisterClass(&wc)) {
                                        hSockWnd = CreateWindowEx ( 0,
-                                                       "SocketFun", "WinUAE Socket Window",
-                                                       WS_POPUP,
-                                                       0, 0,
-                                                       1, 1, 
-                                                       NULL, NULL, 0, NULL);
+                                               "SocketFun", "WinUAE Socket Window",
+                                               WS_POPUP,
+                                               0, 0,
+                                               1, 1, 
+                                               NULL, NULL, 0, NULL);
                                        hSockThread = THREAD(sock_thread, NULL);
                                }
                        }
                }
-    }
-    socket_layer_initialized = result;
+       }
+       socket_layer_initialized = result;
 
-    return result;
+       return result;
 }
 
 void deinit_socket_layer(void)
 {
-    int i;
-    if(currprefs.socket_emu)
-    {
+       int i;
+       if(currprefs.socket_emu) {
                WSACleanup();
-               if(socket_layer_initialized)
-               {
+               if(socket_layer_initialized) {
                        DeleteCriticalSection(&csSigQueueLock);
-                       if(hSockThread)
-                       {
+                       if(hSockThread) {
                                DeleteCriticalSection(&SockThreadCS);
                                CloseHandle(hSockReq);
                                hSockReq = NULL;
@@ -248,28 +228,26 @@ void deinit_socket_layer(void)
                                WaitForSingleObject(hSockThread, INFINITE);
                                CloseHandle(hSockThread);
                        }
-                       for (i = 0; i < MAX_SELECT_THREADS; i++)
-                       {
-                               if (hThreads[i])
-                               {
+                       for (i = 0; i < MAX_SELECT_THREADS; i++) {
+                               if (hThreads[i]) {
                                        CloseHandle(hThreads[i]);
                                        hThreads[i] = NULL;
                                }
                        }
                }
-    }
+       }
 }
 
 #ifdef BSDSOCKET
 
 void locksigqueue(void)
 {
-    EnterCriticalSection(&csSigQueueLock);
+       EnterCriticalSection(&csSigQueueLock);
 }
 
 void unlocksigqueue(void)
 {
-    LeaveCriticalSection(&csSigQueueLock);
+       LeaveCriticalSection(&csSigQueueLock);
 }
 
 // Asynchronous completion notification
@@ -292,7 +270,7 @@ static SOCKET asyncsock[MAXPENDINGASYNC];
 static uae_u32 asyncsd[MAXPENDINGASYNC];
 static int asyncindex;
 
-int host_sbinit(SB)
+int host_sbinit(TrapContext *context, SB)
 {
        sb->sockAbort = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
        
@@ -403,12 +381,12 @@ void sockmsg(unsigned int msg, WPARAM wParam, LPARAM lParam)
 
                if (WSAGETASYNCERROR(lParam))
                {
-                       seterrno(sb,WSAGETASYNCERROR(lParam)-WSABASEERR);
-                       if (sb->sb_errno >= 1001 && sb->sb_errno <= 1005) setherrno(sb,sb->sb_errno-1000);
+                       bsdsocklib_seterrno(sb,WSAGETASYNCERROR(lParam)-WSABASEERR);
+                       if (sb->sb_errno >= 1001 && sb->sb_errno <= 1005) bsdsocklib_setherrno(sb,sb->sb_errno-1000);
                        else if (sb->sb_errno == 55)    // ENOBUFS
                                write_log("BSDSOCK: ERROR - Buffer overflow - %d bytes requested\n",WSAGETASYNCBUFLEN(lParam));
                }
-               else seterrno(sb,0);
+               else bsdsocklib_seterrno(sb,0);
 
 
                SETSIGNAL;
@@ -422,38 +400,31 @@ static unsigned   int allocasyncmsg(SB,uae_u32 sd,SOCKET s)
        int i;
        locksigqueue();
        
-       for (i = asyncindex+1; i != asyncindex; i++)
-       {
-               if (i == MAXPENDINGASYNC) i = 0;
-               
-               if (!asyncsb[i])
-               {
+       for (i = asyncindex+1; i != asyncindex; i++) {
+               if (i == MAXPENDINGASYNC)
+                       i = 0;
+               if (!asyncsb[i]) {
                        asyncsb[i] = sb;
                        if (++asyncindex == MAXPENDINGASYNC) asyncindex = 0;
                        unlocksigqueue();
-                       
-                       if (s == INVALID_SOCKET)
-                       {
+                       if (s == INVALID_SOCKET) {
                                return i*2+0xb001;
-                       }
-                       else
-                       {
+                       } else {
                                asyncsd[i] = sd;
                                asyncsock[i] = s;
-                               return i*2+0xb000;
+                               return i * 2+0xb000;
                        }
                }
        }
-       
        unlocksigqueue();
 
-       seterrno(sb,12); // ENOMEM
+       bsdsocklib_seterrno(sb,12); // ENOMEM
        write_log("BSDSOCK: ERROR - Async operation completion table overflow\n");
        
        return 0;
 }
 
-static void cancelasyncmsg(unsigned int wMsg)
+static void cancelasyncmsg(TrapContext *context, unsigned int wMsg)
 {
        SB;
        
@@ -461,8 +432,7 @@ static void cancelasyncmsg(unsigned int wMsg)
 
        sb = asyncsb[wMsg];
 
-       if (sb != NULL)
-       {
+       if (sb != NULL) {
                asyncsb[wMsg] = NULL;
                CANCELSIGNAL;
        }
@@ -477,8 +447,7 @@ void sockabort(SB)
 
 void setWSAAsyncSelect(SB, uae_u32 sd, SOCKET s, long lEvent )
 {
-       if (sb->mtable[sd-1])
-       {
+       if (sb->mtable[sd-1]) {
                long wsbevents = 0;
                long eventflags;
                int i;
@@ -487,12 +456,18 @@ void setWSAAsyncSelect(SB, uae_u32 sd, SOCKET s, long lEvent )
 
                eventflags = sb->ftable[sd-1]  & REP_ALL;
 
-               if (eventflags & REP_ACCEPT) wsbevents |= FD_ACCEPT;
-               if (eventflags & REP_CONNECT) wsbevents |= FD_CONNECT;
-               if (eventflags & REP_OOB) wsbevents |= FD_OOB;
-               if (eventflags & REP_READ) wsbevents |= FD_READ;
-               if (eventflags & REP_WRITE) wsbevents |= FD_WRITE;
-               if (eventflags & REP_CLOSE) wsbevents |= FD_CLOSE;
+               if (eventflags & REP_ACCEPT)
+                       wsbevents |= FD_ACCEPT;
+               if (eventflags & REP_CONNECT)
+                       wsbevents |= FD_CONNECT;
+               if (eventflags & REP_OOB)
+                       wsbevents |= FD_OOB;
+               if (eventflags & REP_READ)
+                       wsbevents |= FD_READ;
+               if (eventflags & REP_WRITE)
+                       wsbevents |= FD_WRITE;
+               if (eventflags & REP_CLOSE)
+                       wsbevents |= FD_CLOSE;
                wsbevents |= lEvent;
                i = (sb->mtable[sd-1]-0xb000)/2;
                asyncsb[i] = sb;
@@ -528,28 +503,22 @@ int host_dup2socket(SB, int fd1, int fd2)
        fd1++;
 
     s1 = getsock(sb, fd1);
-    if (s1 != INVALID_SOCKET)
-       {
-               if (fd2 != -1)
-               {
-                   if ((unsigned int) (fd2) >= (unsigned int) sb->dtablesize) 
-                       {
+    if (s1 != INVALID_SOCKET) {
+               if (fd2 != -1) {
+                   if ((unsigned int) (fd2) >= (unsigned int) sb->dtablesize)  {
                                TRACE (("Bad file descriptor (%d)\n", fd2));
-                               seterrno (sb, 9);       /* EBADF */
+                               bsdsocklib_seterrno (sb, 9); /* EBADF */
                        }
                        fd2++;
                        s2 = getsock(sb,fd2);
-                       if (s2 != INVALID_SOCKET)
-                       {
-                   shutdown(s2,1);
+                       if (s2 != INVALID_SOCKET) {
+                               shutdown(s2,1);
                            closesocket(s2);
                        }
                        setsd(sb,fd2,s1);
                    TRACE(("0\n"));
                        return 0;
-               }
-               else
-               {
+               } else {
                        fd2 = getsd(sb, 1);
                        setsd(sb,fd2,s1);
                    TRACE(("%d\n",fd2));
@@ -568,35 +537,29 @@ int host_socket(SB, int af, int type, int protocol)
 
     TRACE(("socket(%s,%s,%d) -> ",af == AF_INET ? "AF_INET" : "AF_other",type == SOCK_STREAM ? "SOCK_STREAM" : type == SOCK_DGRAM ? "SOCK_DGRAM " : "SOCK_RAW",protocol));
 
-    if ((s = socket(af,type,protocol)) == INVALID_SOCKET)
-    {
+    if ((s = socket(af,type,protocol)) == INVALID_SOCKET) {
                SETERRNO;
                TRACE(("failed (%d)\n",sb->sb_errno));
                return -1;
-    }
-    else
-       sd = getsd(sb,(int)s);
+    } else
+               sd = getsd(sb,(int)s);
 
        sb->ftable[sd-1] = SF_BLOCKING;
     ioctlsocket(s,FIONBIO,&nonblocking);
     TRACE(("%d\n",sd));
 
-       if (type == SOCK_RAW)
-       {
-               if (protocol==IPPROTO_UDP)
-               {
+       if (type == SOCK_RAW) {
+               if (protocol==IPPROTO_UDP) {
                        sb->ftable[sd-1] |= SF_RAW_UDP;
                }
-               if (protocol==IPPROTO_ICMP)
-               {
+               if (protocol==IPPROTO_ICMP) {
                        struct sockaddr_in sin;
 
                        sin.sin_family = AF_INET;
                        sin.sin_addr.s_addr = INADDR_ANY;
                        bind(s,(struct sockaddr *)&sin,sizeof(sin)) ;
                }
-               if (protocol==IPPROTO_RAW)
-               {
+               if (protocol==IPPROTO_RAW) {
                        sb->ftable[sd-1] |= SF_RAW_RAW;
                }
        }
@@ -613,24 +576,19 @@ uae_u32 host_bind(SB, uae_u32 sd, uae_u32 name, uae_u32 namelen)
     TRACE(("bind(%d,0x%lx,%d) -> ",sd,name,namelen));
     s = getsock(sb, sd);
 
-    if (s != INVALID_SOCKET)
-    {
-               if (namelen <= sizeof buf)
-               {
+    if (s != INVALID_SOCKET) {
+               if (namelen <= sizeof buf) {
                        memcpy(buf,get_real_address(name),namelen);
                    
                        // some Amiga programs set this field to bogus values
                        prephostaddr((SOCKADDR_IN *)buf);
 
-                       if ((success = bind(s,(struct sockaddr *)buf,namelen)) != 0)
-                       {
+                       if ((success = bind(s,(struct sockaddr *)buf,namelen)) != 0) {
                                SETERRNO;
                                TRACE(("failed (%d)\n",sb->sb_errno));
-                       }
-                       else
+                       } else
                                TRACE(("OK\n"));
-               }
-               else
+               } else
                        write_log("BSDSOCK: ERROR - Excessive namelen (%d) in bind()!\n",namelen);
     }
 
@@ -646,20 +604,17 @@ uae_u32 host_listen(SB, uae_u32 sd, uae_u32 backlog)
     TRACE(("listen(%d,%d) -> ",sd,backlog));
     s = getsock(sb, sd);
 
-    if (s != INVALID_SOCKET)
-    {
-               if ((success = listen(s,backlog)) != 0)
-               {
+    if (s != INVALID_SOCKET) {
+               if ((success = listen(s,backlog)) != 0) {
                        SETERRNO;
                        TRACE(("failed (%d)\n",sb->sb_errno));
-               }
-               else 
+               } else 
                        TRACE(("OK\n"));
     }
     return success;
 }
 
-void host_accept(SB, uae_u32 sd, uae_u32 name, uae_u32 namelen)
+void host_accept(TrapContext *context, SB, uae_u32 sd, uae_u32 name, uae_u32 namelen)
 {
     struct sockaddr *rp_name,*rp_nameuae;
     struct sockaddr sockaddr;
@@ -669,8 +624,7 @@ void host_accept(SB, uae_u32 sd, uae_u32 name, uae_u32 namelen)
     unsigned int wMsg;
     
     sd++;
-       if (name != 0 )
-       {
+       if (name != 0) {
                rp_nameuae = rp_name = (struct sockaddr *)get_real_address(name);
            hlenuae = hlen = get_long(namelen);
                if (hlenuae < sizeof(sockaddr))
@@ -678,9 +632,7 @@ void host_accept(SB, uae_u32 sd, uae_u32 name, uae_u32 namelen)
                        rp_name = &sockaddr; 
                        hlen = sizeof(sockaddr);
                }
-       }
-       else
-       {
+       } else {
                rp_name = &sockaddr; 
                hlen = sizeof(sockaddr);
        }
@@ -688,42 +640,31 @@ void host_accept(SB, uae_u32 sd, uae_u32 name, uae_u32 namelen)
 
     s = (SOCKET)getsock(sb,(int)sd);
     
-    if (s != INVALID_SOCKET)
-    {
+    if (s != INVALID_SOCKET) {
                BEGINBLOCKING;
                
                s2 = accept(s,rp_name,&hlen);
 
-               if (s2 == INVALID_SOCKET)
-               {
+               if (s2 == INVALID_SOCKET) {
                        SETERRNO;
 
-                       if (sb->ftable[sd-1] & SF_BLOCKING && sb->sb_errno == WSAEWOULDBLOCK-WSABASEERR)
-                       {
-                               if (sb->mtable[sd-1] || (wMsg = allocasyncmsg(sb,sd,s)) != 0)
-                               {
-                                       if (sb->mtable[sd-1] == 0)
-                                       {
+                       if (sb->ftable[sd-1] & SF_BLOCKING && sb->sb_errno == WSAEWOULDBLOCK-WSABASEERR) {
+                               if (sb->mtable[sd-1] || (wMsg = allocasyncmsg(sb,sd,s)) != 0) {
+                                       if (sb->mtable[sd-1] == 0) {
                                                WSAAsyncSelect(s,hWndSelector ? hAmigaWnd : hSockWnd,wMsg,FD_ACCEPT);
-                                       }
-                                       else
-                                       {
+                                       } else {
                                                setWSAAsyncSelect(sb,sd,s,FD_ACCEPT);
                                        }
 
                                        WAITSIGNAL;
 
-                                       if (sb->mtable[sd-1] == 0)
-                                       {
-                                               cancelasyncmsg(wMsg);
-                                       }
-                                       else
-                                       {
+                                       if (sb->mtable[sd-1] == 0) {
+                                               cancelasyncmsg(context, wMsg);
+                                       } else {
                                                setWSAAsyncSelect(sb,sd,s,0);
                                        }
                                    
-                                       if (sb->eintr)
-                                       {
+                                       if (sb->eintr) {
                                                TRACE(("[interrupted]\n"));
                                                ENDBLOCKING;
                                                return;
@@ -731,41 +672,31 @@ void host_accept(SB, uae_u32 sd, uae_u32 name, uae_u32 namelen)
 
                                        s2 = accept(s,rp_name,&hlen);
 
-                                       if (s2 == INVALID_SOCKET)
-                                       {
+                                       if (s2 == INVALID_SOCKET) {
                                                SETERRNO;
 
-                                               if (sb->sb_errno == WSAEWOULDBLOCK-WSABASEERR)
+                                               if (sb->sb_errno == WSAEWOULDBLOCK - WSABASEERR)
                                                        write_log("BSDSOCK: ERRRO - accept() would block despite FD_ACCEPT message\n");
                                        }
                                }
                        }
                }
                                
-               if (s2 == INVALID_SOCKET)
-               {
+               if (s2 == INVALID_SOCKET) {
                        sb->resultval = -1;
                        TRACE(("failed (%d)\n",sb->sb_errno));
-               }
-               else
-               {
+               } else {
                        sb->resultval = getsd(sb, s2);
                        sb->ftable[sb->resultval-1] = sb->ftable[sd-1]; // new socket inherits the old socket's properties
                        sb->resultval--;
-                       if (rp_name != 0)
-                       { // 1.11.2002 XXX
-                               if (hlen <= hlenuae)
-                               { // Fix for CNET BBS Part 2
+                       if (rp_name != 0) { // 1.11.2002 XXX
+                               if (hlen <= hlenuae) { // Fix for CNET BBS Part 2
                                        prepamigaaddr(rp_name,hlen);
-                                       if (namelen != 0)
-                                       {
+                                       if (namelen != 0) {
                                                put_long(namelen,hlen);
                                        }
-                               }
-                               else
-                               { // Copy only the number of bytes requested
-                                       if (hlenuae != 0)
-                                       {       
+                               } else { // Copy only the number of bytes requested
+                                       if (hlenuae != 0) {     
                                                prepamigaaddr(rp_name,hlenuae);
                                                memcpy(rp_nameuae,rp_name,hlenuae);
                                                put_long(namelen,hlenuae);
@@ -828,89 +759,76 @@ struct threadsock_packet
     SB;
 } sockreq;
 
-BOOL HandleStuff( void )
+static BOOL HandleStuff( void )
 {
     BOOL quit = FALSE;
     SB = NULL;
     BOOL handled = TRUE;
-    if( hSockReq )
-    {
+    if (hSockReq) {
        // 100ms sleepiness might need some tuning...
-       //if(WaitForSingleObject( hSockReq, 100 ) == WAIT_OBJECT_0 )
+               //if(WaitForSingleObject( hSockReq, 100 ) == WAIT_OBJECT_0 )
                {
                        switch( sockreq.packet_type )
                        {
-                       case connect_req:
-                       sockreq.sb->resultval = connect(sockreq.s,(struct sockaddr *)(sockreq.params.connect_s.buf),sockreq.params.connect_s.namelen);
-                       break;
-                       case sendto_req:
-                               if( sockreq.params.sendto_s.to )
-                               {
+                               case connect_req:
+                               sockreq.sb->resultval = connect(sockreq.s,(struct sockaddr *)(sockreq.params.connect_s.buf),sockreq.params.connect_s.namelen);
+                               break;
+                               case sendto_req:
+                               if(sockreq.params.sendto_s.to) {
                                        sockreq.sb->resultval = sendto(sockreq.s,sockreq.params.sendto_s.realpt,sockreq.params.sendto_s.len,sockreq.params.sendto_s.flags,(struct sockaddr *)(sockreq.params.sendto_s.buf),sockreq.params.sendto_s.tolen);
-                               }
-                               else
-                               {
+                               } else {
                                        sockreq.sb->resultval = send(sockreq.s,sockreq.params.sendto_s.realpt,sockreq.params.sendto_s.len,sockreq.params.sendto_s.flags);
                                }
-                       break;
-                       case recvfrom_req:
-                               if( sockreq.params.recvfrom_s.addr )
-                               {
-                                       sockreq.sb->resultval = recvfrom( sockreq.s, sockreq.params.recvfrom_s.realpt, sockreq.params.recvfrom_s.len,
-                                               sockreq.params.recvfrom_s.flags, sockreq.params.recvfrom_s.rp_addr,
-                                               sockreq.params.recvfrom_s.hlen );
-
-                               }
-                               else
-                               {
-                                       sockreq.sb->resultval = recv( sockreq.s, sockreq.params.recvfrom_s.realpt, sockreq.params.recvfrom_s.len,
-                                               sockreq.params.recvfrom_s.flags );
-                               }
-                       break;
-                       case abort_req:
-                               *(sockreq.params.abort_s.newsock) = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
-                               if (*(sockreq.params.abort_s.newsock) != sb->sockAbort)
-                               {
-                                       shutdown( sb->sockAbort, 1 );
-                                       closesocket(sb->sockAbort);
-                               }
-                               handled = FALSE; /* Don't bother the SETERRNO section after the switch() */
-                       break;
-                       case last_req:
-                       default:
-                               write_log( "BSDSOCK: Invalid sock-thread request!\n" );
-                               handled = FALSE;
-                       break;
+                               break;
+                               case recvfrom_req:
+                                       if(sockreq.params.recvfrom_s.addr) {
+                                               sockreq.sb->resultval = recvfrom( sockreq.s, sockreq.params.recvfrom_s.realpt, sockreq.params.recvfrom_s.len,
+                                                       sockreq.params.recvfrom_s.flags, sockreq.params.recvfrom_s.rp_addr,
+                                                       sockreq.params.recvfrom_s.hlen );
+
+                                       } else {
+                                               sockreq.sb->resultval = recv( sockreq.s, sockreq.params.recvfrom_s.realpt, sockreq.params.recvfrom_s.len,
+                                                       sockreq.params.recvfrom_s.flags );
+                                       }
+                               break;
+                               case abort_req:
+                                       *(sockreq.params.abort_s.newsock) = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
+                                       if (*(sockreq.params.abort_s.newsock) != sb->sockAbort) {
+                                               shutdown( sb->sockAbort, 1 );
+                                               closesocket(sb->sockAbort);
+                                       }
+                                       handled = FALSE; /* Don't bother the SETERRNO section after the switch() */
+                               break;
+                               case last_req:
+                               default:
+                                       write_log( "BSDSOCK: Invalid sock-thread request!\n" );
+                                       handled = FALSE;
+                               break;
                        }
-                       if( handled )
-                       {
-                               if( sockreq.sb->resultval == SOCKET_ERROR )
-                               {
+                       if(handled) {
+                               if(sockreq.sb->resultval == SOCKET_ERROR) {
                                        sb = sockreq.sb;
                                        SETERRNO;
                                }
                        }
                        SetEvent( hSockReqHandled );
                }
-    }
-    else
-    {
-       quit = TRUE;
+    } else {
+               quit = TRUE;
     }
     return quit;
 }
 
 static LRESULT CALLBACK SocketWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
 {
-    if( message >= 0xB000 && message < 0xB000+MAXPENDINGASYNC*2 )
-    {
+    if(message >= 0xB000 && message < 0xB000+MAXPENDINGASYNC * 2) {
 #if DEBUG_SOCKETS
-       write_log( "sockmsg(0x%x, 0x%x, 0x%x)\n", message, wParam, lParam );
+               write_log( "sockmsg(0x%x, 0x%x, 0x%x)\n", message, wParam, lParam );
 #endif
-       sockmsg( message, wParam, lParam );
-       return 0;
+               sockmsg(message, wParam, lParam);
+               return 0;
     }
-    return DefWindowProc( hwnd, message, wParam, lParam );
+    return DefWindowProc(hwnd, message, wParam, lParam);
 }
 
 
@@ -921,36 +839,30 @@ static unsigned int __stdcall sock_thread(void *blah)
     HANDLE WaitHandle;
     MSG msg;
 
-       if( hSockWnd )
-       {
+       if(hSockWnd) {
            // Make sure we're outrunning the wolves
            int pri = THREAD_PRIORITY_ABOVE_NORMAL;
            if (!os_winnt) {
                        pri = priorities[currprefs.win32_active_priority].value;
                        if (pri == THREAD_PRIORITY_HIGHEST)
-                   pri = THREAD_PRIORITY_TIME_CRITICAL;
+                               pri = THREAD_PRIORITY_TIME_CRITICAL;
                        else
                                pri++;
            }
-           SetThreadPriority( GetCurrentThread(), pri );
+           SetThreadPriority(GetCurrentThread(), pri);
            
-           while( TRUE )
-           {
-                       if( hSockReq )
-                       {
+           while(TRUE) {
+                       if(hSockReq) {
                                DWORD wait;
                                WaitHandle = hSockReq;
                                wait = MsgWaitForMultipleObjects (1, &WaitHandle, FALSE,INFINITE, QS_POSTMESSAGE);
-                               if (wait == WAIT_OBJECT_0)
-                               {
-                                       if( HandleStuff() ) // See if its time to quit...
+                               if (wait == WAIT_OBJECT_0) {
+                                       if(HandleStuff()) // See if its time to quit...
                                                break;
                                }
-                               if (wait == WAIT_OBJECT_0 +1)
-                               {
+                               if (wait == WAIT_OBJECT_0 +1) {
                                        Sleep(10);
-                                       while( PeekMessage( &msg, NULL, WM_USER, 0xB000+MAXPENDINGASYNC*2, PM_REMOVE ) > 0 )
-                                       {
+                                       while( PeekMessage(&msg, NULL, WM_USER, 0xB000+MAXPENDINGASYNC*2, PM_REMOVE) > 0) {
                                                TranslateMessage( &msg );
                                                DispatchMessage( &msg );
                                        }
@@ -964,31 +876,24 @@ static unsigned int __stdcall sock_thread(void *blah)
 }
 
 
-void host_connect(SB, uae_u32 sd, uae_u32 name, uae_u32 namelen)
+void host_connect(TrapContext *context, SB, uae_u32 sd, uae_u32 name, uae_u32 namelen)
 {
     SOCKET s;
     int success = 0;
     unsigned int wMsg;
     char buf[MAXADDRLEN];
 
-
        sd++;
     TRACE(("connect(%d,0x%lx,%d) -> ",sd,name,namelen));
 
     s = (SOCKET)getsock(sb,(int)sd);
     
-    if (s != INVALID_SOCKET)
-    {
-               if (namelen <= MAXADDRLEN)
-               {
-                       if (sb->mtable[sd-1] || (wMsg = allocasyncmsg(sb,sd,s)) != 0)
-                       {
-                               if (sb->mtable[sd-1] == 0)
-                               {
+    if (s != INVALID_SOCKET) {
+               if (namelen <= MAXADDRLEN) {
+                       if (sb->mtable[sd-1] || (wMsg = allocasyncmsg(sb,sd,s)) != 0) {
+                               if (sb->mtable[sd-1] == 0) {
                                        WSAAsyncSelect(s,hWndSelector ? hAmigaWnd : hSockWnd,wMsg,FD_CONNECT);
-                               }
-                               else
-                               {
+                               } else {
                                        setWSAAsyncSelect(sb,sd,s,FD_CONNECT);
                                }
 
@@ -1006,54 +911,42 @@ void host_connect(SB, uae_u32 sd, uae_u32 name, uae_u32 namelen)
 
                                TRIGGER_THREAD;
 
-                               if (sb->resultval)
-                               {
-                                       if (sb->sb_errno == WSAEWOULDBLOCK-WSABASEERR)
-                                       {
-                                               if (sb->ftable[sd-1] & SF_BLOCKING)
-                                               {
-                                                       seterrno(sb,0);
+                               if (sb->resultval) {
+                                       if (sb->sb_errno == WSAEWOULDBLOCK - WSABASEERR) {
+                                               if (sb->ftable[sd-1] & SF_BLOCKING) {
+                                                       bsdsocklib_seterrno(sb,0);
                                                
                                                        WAITSIGNAL;
 
-                                                       if (sb->eintr)
-                                                       {
+                                                       if (sb->eintr) {
                                                                // Destroy socket to cancel abort, replace it with fake socket to enable proper closing.
                                                                // This is in accordance with BSD behaviour.
                                                                                                shutdown(s,1);
                                                                closesocket(s);
                                                                sb->dtable[sd-1] = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
                                                        }
+                                               } else {
+                                                       bsdsocklib_seterrno(sb,36); // EINPROGRESS
                                                }
-                                               else
-                                               {
-                                                       seterrno(sb,36);        // EINPROGRESS
-                                               }
-                                       }
-                                       else
-                                       {
+                                       } else {
                                                CANCELSIGNAL; // Cancel pending signal
                                        }
                                }
 
                                ENDBLOCKING;
-                               if (sb->mtable[sd-1] == 0)
-                               {
-                                       cancelasyncmsg(wMsg);
-                               }
-                               else
-                               {
+                               if (sb->mtable[sd-1] == 0) {
+                                       cancelasyncmsg(context, wMsg);
+                               } else {
                                        setWSAAsyncSelect(sb,sd,s,0);
                                }
                        }
-       }
-       else
-           write_log("BSDSOCK: WARNING - Excessive namelen (%d) in connect()!\n",namelen);
+               } else
+                       write_log("BSDSOCK: WARNING - Excessive namelen (%d) in connect()!\n",namelen);
     }
     TRACE(("%d\n",sb->sb_errno));
 }
 
-void host_sendto(SB, uae_u32 sd, uae_u32 msg, uae_u32 len, uae_u32 flags, uae_u32 to, uae_u32 tolen)
+void host_sendto(TrapContext *context, SB, uae_u32 sd, uae_u32 msg, uae_u32 len, uae_u32 flags, uae_u32 to, uae_u32 tolen)
 {
     SOCKET s;
     char *realpt;
@@ -1063,31 +956,26 @@ void host_sendto(SB, uae_u32 sd, uae_u32 msg, uae_u32 len, uae_u32 flags, uae_u3
 
 #ifdef TRACING_ENABLED
     if (to)
-       TRACE(("sendto(%d,0x%lx,%d,0x%lx,0x%lx,%d) -> ",sd,msg,len,flags,to,tolen));
+               TRACE(("sendto(%d,0x%lx,%d,0x%lx,0x%lx,%d) -> ",sd,msg,len,flags,to,tolen));
     else
-       TRACE(("send(%d,0x%lx,%d,%d) -> ",sd,msg,len,flags));
+               TRACE(("send(%d,0x%lx,%d,%d) -> ",sd,msg,len,flags));
 #endif
        sd++;
     s = getsock(sb,sd);
 
-    if (s != INVALID_SOCKET)
-    {
-       realpt = get_real_address(msg);
+    if (s != INVALID_SOCKET) {
+               realpt = get_real_address(msg);
                
-               if (to)
-               {
+               if (to) {
                        if (tolen > sizeof buf) write_log("BSDSOCK: WARNING - Target address in sendto() too large (%d)!\n",tolen);
-                       else
-                       {
+                       else {
                                memcpy(buf,get_real_address(to),tolen);
                                // some Amiga software sets this field to bogus values
                                prephostaddr((SOCKADDR_IN *)buf);
                        }
                }
-               if (sb->ftable[sd-1]&SF_RAW_RAW)
-               {
-                       if (*(realpt+9) == 0x1)
-                       { // ICMP
+               if (sb->ftable[sd-1] & SF_RAW_RAW) {
+                       if (*(realpt+9) == 0x1) { // ICMP
                                struct sockaddr_in sin;
                                shutdown(s,1);
                                closesocket(s);
@@ -1102,8 +990,7 @@ void host_sendto(SB, uae_u32 sd, uae_u32 msg, uae_u32 len, uae_u32 flags, uae_u3
                                sb->ftable[sd-1]&= ~SF_RAW_RAW;
                                sb->ftable[sd-1]|= SF_RAW_RICMP;
                        }
-                       if (*(realpt+9) == 0x11)
-                       { // UDP
+                       if (*(realpt+9) == 0x11) { // UDP
                                struct sockaddr_in sin;
                                shutdown(s,1);
                                closesocket(s);
@@ -1122,8 +1009,8 @@ void host_sendto(SB, uae_u32 sd, uae_u32 msg, uae_u32 len, uae_u32 flags, uae_u3
                        
                BEGINBLOCKING;
 
-               for (;;)
-               {
+               for (;;) {
+
                        PREPARE_THREAD;
 
                        sockreq.packet_type = sendto_req;
@@ -1138,8 +1025,7 @@ void host_sendto(SB, uae_u32 sd, uae_u32 msg, uae_u32 len, uae_u32 flags, uae_u3
                        sockreq.params.sendto_s.to = to;
                        sockreq.params.sendto_s.tolen = tolen;
 
-                       if (sb->ftable[sd-1]&SF_RAW_UDP)
-                       {
+                       if (sb->ftable[sd-1]&SF_RAW_UDP) {
                                *(buf+2) = *(realpt+2);
                                *(buf+3) = *(realpt+3);
                                // Copy DST-Port
@@ -1147,8 +1033,7 @@ void host_sendto(SB, uae_u32 sd, uae_u32 msg, uae_u32 len, uae_u32 flags, uae_u3
                                sockreq.params.sendto_s.realpt += iCut;
                                sockreq.params.sendto_s.len -= iCut;
                        }
-                       if (sb->ftable[sd-1]&SF_RAW_RUDP)
-                       {
+                       if (sb->ftable[sd-1]&SF_RAW_RUDP) {
                                int iTTL;
                                iTTL = (int) *(realpt+8)&0xff;
                                setsockopt(s,IPPROTO_IP,4,(char*) &iTTL,sizeof(iTTL));
@@ -1159,8 +1044,7 @@ void host_sendto(SB, uae_u32 sd, uae_u32 msg, uae_u32 len, uae_u32 flags, uae_u3
                                sockreq.params.sendto_s.realpt += iCut;
                                sockreq.params.sendto_s.len -= iCut;
                        }
-                       if (sb->ftable[sd-1]&SF_RAW_RICMP)
-                       {
+                       if (sb->ftable[sd-1]&SF_RAW_RICMP) {
                                int iTTL;
                                iTTL = (int) *(realpt+8)&0xff;
                                setsockopt(s,IPPROTO_IP,4,(char*) &iTTL,sizeof(iTTL));
@@ -1170,60 +1054,48 @@ void host_sendto(SB, uae_u32 sd, uae_u32 msg, uae_u32 len, uae_u32 flags, uae_u3
                        }
 
                        TRIGGER_THREAD;
-                       if (sb->ftable[sd-1]&SF_RAW_UDP||sb->ftable[sd-1]&SF_RAW_RUDP||sb->ftable[sd-1]&SF_RAW_RICMP)
-                       {
+                       if (sb->ftable[sd-1]&SF_RAW_UDP||sb->ftable[sd-1]&SF_RAW_RUDP||sb->ftable[sd-1]&SF_RAW_RICMP) {
                                sb->resultval += iCut;
                        }
-                       if (sb->resultval == -1)
-                       {
+                       if (sb->resultval == -1) {
                                if (sb->sb_errno != WSAEWOULDBLOCK-WSABASEERR || !(sb->ftable[sd-1] & SF_BLOCKING))
                                        break;
-                       }
-                       else
-                       {
+                       } else {
                                realpt += sb->resultval;
                                len -= sb->resultval;
-                       
                                if (len <= 0)
                                        break;
                                else
                                        continue;
                        }
 
-                       if (sb->mtable[sd-1] || (wMsg = allocasyncmsg(sb,sd,s)) != 0)
-                       {
-                               if (sb->mtable[sd-1] == 0)
-                               {
+                       if (sb->mtable[sd-1] || (wMsg = allocasyncmsg(sb,sd,s)) != 0) {
+                               if (sb->mtable[sd-1] == 0) {
                                        WSAAsyncSelect(s,hWndSelector ? hAmigaWnd : hSockWnd,wMsg,FD_WRITE);
-                               }
-                               else
-                               {
+                               } else {
                                        setWSAAsyncSelect(sb,sd,s,FD_WRITE);
                                }
                                        
                                WAITSIGNAL;
                                
-                               if (sb->mtable[sd-1] == 0)
-                               {
-                                       cancelasyncmsg(wMsg);
-                               }
-                               else
-                               {
+                               if (sb->mtable[sd-1] == 0) {
+                                       cancelasyncmsg(context, wMsg);
+                               } else {
                                        setWSAAsyncSelect(sb,sd,s,0);
                                }
                                
-                               if (sb->eintr)
-                               {
+                               if (sb->eintr) {
                                        TRACE(("[interrupted]\n"));
                                        return;
                                }
-                       }
-                       else break;
+                       } else
+                               break;
                }
 
                ENDBLOCKING;
-    }
-    else sb->resultval = -1;
+
+       } else
+               sb->resultval = -1;
 
 #ifdef TRACING_ENABLED
     if (sb->resultval == -1)
@@ -1234,7 +1106,7 @@ void host_sendto(SB, uae_u32 sd, uae_u32 msg, uae_u32 len, uae_u32 flags, uae_u3
 
 }
 
-void host_recvfrom(SB, uae_u32 sd, uae_u32 msg, uae_u32 len, uae_u32 flags, uae_u32 addr, uae_u32 addrlen)
+void host_recvfrom(TrapContext *context, SB, uae_u32 sd, uae_u32 msg, uae_u32 len, uae_u32 flags, uae_u32 addr, uae_u32 addrlen)
 {
     SOCKET s;
     char *realpt;
@@ -1244,95 +1116,82 @@ void host_recvfrom(SB, uae_u32 sd, uae_u32 msg, uae_u32 len, uae_u32 flags, uae_
 
 #ifdef TRACING_ENABLED
     if (addr)
-       TRACE(("recvfrom(%d,0x%lx,%d,0x%lx,0x%lx,%d) -> ",sd,msg,len,flags,addr,get_long(addrlen)));
-    else
-       TRACE(("recv(%d,0x%lx,%d,0x%lx) -> ",sd,msg,len,flags));
+               TRACE(("recvfrom(%d,0x%lx,%d,0x%lx,0x%lx,%d) -> ",sd,msg,len,flags,addr,get_long(addrlen)));
+       else
+               TRACE(("recv(%d,0x%lx,%d,0x%lx) -> ",sd,msg,len,flags));
 #endif
     sd++;
     s = getsock(sb,sd);
 
-    if (s != INVALID_SOCKET)
-    {
-       realpt = get_real_address(msg);
+    if (s != INVALID_SOCKET) {
+               realpt = get_real_address(msg);
 
-       if (addr)
-       {
-           hlen = get_long(addrlen);
-           rp_addr = (struct sockaddr *)get_real_address(addr);
-       }
+               if (addr) {
+                       hlen = get_long(addrlen);
+                       rp_addr = (struct sockaddr *)get_real_address(addr);
+               }
 
-       BEGINBLOCKING;
+               BEGINBLOCKING;
 
-       for (;;)
-       {
-           PREPARE_THREAD;
-
-           sockreq.packet_type = recvfrom_req;
-           sockreq.s = s;
-           sockreq.sb = sb;
-           sockreq.params.recvfrom_s.addr = addr;
-           sockreq.params.recvfrom_s.flags = flags;
-           sockreq.params.recvfrom_s.hlen = &hlen;
-           sockreq.params.recvfrom_s.len = len;
-           sockreq.params.recvfrom_s.realpt = realpt;
-           sockreq.params.recvfrom_s.rp_addr = rp_addr;
-
-           TRIGGER_THREAD;
-           if (sb->resultval == -1)
-           {
-               if (sb->sb_errno == WSAEWOULDBLOCK-WSABASEERR && sb->ftable[sd-1] & SF_BLOCKING)
-               {
-                   if (sb->mtable[sd-1] || (wMsg = allocasyncmsg(sb,sd,s)) != 0)
-                   {
-                       if (sb->mtable[sd-1] == 0)
-                       {
-                           WSAAsyncSelect(s,hWndSelector ? hAmigaWnd : hSockWnd,wMsg,FD_READ|FD_CLOSE);
-                       }
-                       else
-                       {
-                           setWSAAsyncSelect(sb,sd,s,FD_READ|FD_CLOSE);
-                       }
+               for (;;) {
 
-                       WAITSIGNAL;
-               
-                       if (sb->mtable[sd-1] == 0)
-                       {
-                           cancelasyncmsg(wMsg);
-                       }
-                       else
+                       PREPARE_THREAD;
+
+                   sockreq.packet_type = recvfrom_req;
+                   sockreq.s = s;
+                   sockreq.sb = sb;
+                   sockreq.params.recvfrom_s.addr = addr;
+                   sockreq.params.recvfrom_s.flags = flags;
+                   sockreq.params.recvfrom_s.hlen = &hlen;
+                   sockreq.params.recvfrom_s.len = len;
+                   sockreq.params.recvfrom_s.realpt = realpt;
+                   sockreq.params.recvfrom_s.rp_addr = rp_addr;
+
+                   TRIGGER_THREAD;
+                   if (sb->resultval == -1) {
+                               if (sb->sb_errno == WSAEWOULDBLOCK-WSABASEERR && sb->ftable[sd-1] & SF_BLOCKING)
                        {
-                           setWSAAsyncSelect(sb,sd,s,0);
-                       }
+                   if (sb->mtable[sd-1] || (wMsg = allocasyncmsg(sb,sd,s)) != 0) {
+                               if (sb->mtable[sd-1] == 0) {
+                                       WSAAsyncSelect(s,hWndSelector ? hAmigaWnd : hSockWnd,wMsg,FD_READ|FD_CLOSE);
+                               } else {
+                                       setWSAAsyncSelect(sb,sd,s,FD_READ|FD_CLOSE);
+                               }
 
+                               WAITSIGNAL;
                
-                       if (sb->eintr)
-                       {
-                           TRACE(("[interrupted]\n"));
-                           return;
-                       }
-                   }
-                   else break;
+                               if (sb->mtable[sd-1] == 0) {
+                                       cancelasyncmsg(context, wMsg);
+                               } else {
+                                       setWSAAsyncSelect(sb,sd,s,0);
+                               }
+
+                               if (sb->eintr) {
+                                       TRACE(("[interrupted]\n"));
+                                       return;
+                               }
+                   } else
+                               break;
+               } else
+                       break;
+           } else
+                       break;
                }
-               else break;
-           }
-           else break;
-       }
        
-       ENDBLOCKING;
+               ENDBLOCKING;
 
-       if (addr)
-       {
-           prepamigaaddr(rp_addr,hlen);
-           put_long(addrlen,hlen);
-       }
-    }
-    else sb->resultval = -1;
+               if (addr) {
+                       prepamigaaddr(rp_addr,hlen);
+                       put_long(addrlen,hlen);
+               }
+    } else
+               sb->resultval = -1;
 
 #ifdef TRACING_ENABLED
     if (sb->resultval == -1)
-       TRACE(("failed (%d)\n",sb->sb_errno));
+               TRACE(("failed (%d)\n",sb->sb_errno));
     else
-       TRACE(("%d\n",sb->resultval));
+               TRACE(("%d\n",sb->resultval));
 #endif
 
 }
@@ -1345,18 +1204,14 @@ uae_u32 host_shutdown(SB, uae_u32 sd, uae_u32 how)
     sd++;
     s = getsock(sb,sd);
 
-    if (s != INVALID_SOCKET)
-    {
-       if (shutdown(s,how))
-       {
-           SETERRNO;
-           TRACE(("failed (%d)\n",sb->sb_errno));
-       }
-       else
-       {
-           TRACE(("OK\n"));
-           return 0;
-       }
+    if (s != INVALID_SOCKET) {
+               if (shutdown(s,how)) {
+                       SETERRNO;
+                       TRACE(("failed (%d)\n",sb->sb_errno));
+               } else {
+                       TRACE(("OK\n"));
+                       return 0;
+               }
     }
 
     return -1;
@@ -1371,62 +1226,62 @@ void host_setsockopt(SB, uae_u32 sd, uae_u32 level, uae_u32 optname, uae_u32 opt
     sd++;
     s = getsock(sb,sd);
 
-    if (s != INVALID_SOCKET)
-    {
-       if (len > sizeof buf)
-       {
-           write_log("BSDSOCK: WARNING - Excessive optlen in setsockopt() (%d)\n",len);
-           len = sizeof buf;
-       }       
-       if (level == IPPROTO_IP && optname == 2)
-               { // IP_HDRINCL emulated by icmp.dll
-               sb->resultval = 0;
-               return;
+    if (s != INVALID_SOCKET) {
+               if (len > sizeof buf) {
+                       write_log("BSDSOCK: WARNING - Excessive optlen in setsockopt() (%d)\n",len);
+                       len = sizeof buf;
+               }       
+               if (level == IPPROTO_IP && optname == 2) { // IP_HDRINCL emulated by icmp.dll
+                       sb->resultval = 0;
+                       return;
+                       }
+               if (level == SOL_SOCKET && optname == SO_LINGER) {
+                       ((LINGER *)buf)->l_onoff = get_long(optval);
+                       ((LINGER *)buf)->l_linger = get_long(optval+4);
+               } else {
+                       if (len == 4)
+                               *(long *)buf = get_long(optval);
+                       else if (len == 2)
+                               *(short *)buf = get_word(optval);
+                       else
+                               write_log("BSDSOCK: ERROR - Unknown optlen (%d) in setsockopt(%d,%d)\n",level,optname);
                }
-       if (level == SOL_SOCKET && optname == SO_LINGER)
-       {
-           ((LINGER *)buf)->l_onoff = get_long(optval);
-           ((LINGER *)buf)->l_linger = get_long(optval+4);
-       }
-       else
-       {
-           if (len == 4) *(long *)buf = get_long(optval);
-           else if (len == 2) *(short *)buf = get_word(optval);
-           else write_log("BSDSOCK: ERROR - Unknown optlen (%d) in setsockopt(%d,%d)\n",level,optname);
-       }
 
-       // handle SO_EVENTMASK
-       if (level == 0xffff && optname == 0x2001)
-       {
-           long wsbevents = 0;
-           uae_u32 eventflags = get_long(optval);
-
-           sb->ftable[sd-1] = (sb->ftable[sd-1] & ~REP_ALL) | (eventflags & REP_ALL);
-
-           if (eventflags & REP_ACCEPT) wsbevents |= FD_ACCEPT;
-           if (eventflags & REP_CONNECT) wsbevents |= FD_CONNECT;
-           if (eventflags & REP_OOB) wsbevents |= FD_OOB;
-           if (eventflags & REP_READ) wsbevents |= FD_READ;
-           if (eventflags & REP_WRITE) wsbevents |= FD_WRITE;
-           if (eventflags & REP_CLOSE) wsbevents |= FD_CLOSE;
+               // handle SO_EVENTMASK
+               if (level == 0xffff && optname == 0x2001) {
+                       long wsbevents = 0;
+                       uae_u32 eventflags = get_long(optval);
+
+                       sb->ftable[sd-1] = (sb->ftable[sd-1] & ~REP_ALL) | (eventflags & REP_ALL);
+
+                       if (eventflags & REP_ACCEPT)
+                               wsbevents |= FD_ACCEPT;
+                       if (eventflags & REP_CONNECT)
+                               wsbevents |= FD_CONNECT;
+                       if (eventflags & REP_OOB)
+                               wsbevents |= FD_OOB;
+                       if (eventflags & REP_READ)
+                               wsbevents |= FD_READ;
+                       if (eventflags & REP_WRITE)
+                               wsbevents |= FD_WRITE;
+                       if (eventflags & REP_CLOSE)
+                               wsbevents |= FD_CLOSE;
            
-           if (sb->mtable[sd-1] || (sb->mtable[sd-1] = allocasyncmsg(sb,sd,s)))
-           {
-                   WSAAsyncSelect(s,hWndSelector ? hAmigaWnd : hSockWnd,sb->mtable[sd-1],wsbevents);
-                   sb->resultval = 0;
-           }
-           else sb->resultval = -1;
-       }
-       else sb->resultval = setsockopt(s,level,optname,buf,len);
+                       if (sb->mtable[sd-1] || (sb->mtable[sd-1] = allocasyncmsg(sb,sd,s))) {
+                               WSAAsyncSelect(s,hWndSelector ? hAmigaWnd : hSockWnd,sb->mtable[sd-1],wsbevents);
+                               sb->resultval = 0;
+                       } else
+                               sb->resultval = -1;
+               } else
+                       sb->resultval = setsockopt(s,level,optname,buf,len);
                
-       if (!sb->resultval)
-       {
-           TRACE(("OK\n"));
-           return;
-       }
-       else SETERRNO;
+               if (!sb->resultval) {
+                       TRACE(("OK\n"));
+                       return;
+               } else
+                       SETERRNO;
                
-       TRACE(("failed (%d)\n",sb->sb_errno));
+               TRACE(("failed (%d)\n",sb->sb_errno));
     }
 }
 
@@ -1440,28 +1295,24 @@ uae_u32 host_getsockopt(SB, uae_u32 sd, uae_u32 level, uae_u32 optname, uae_u32
        sd++;
        s = getsock(sb,sd);
        
-       if (s != INVALID_SOCKET)
-       {
-               if (!getsockopt(s,level,optname,buf,&len))
-               {
-                       if (level == SOL_SOCKET && optname == SO_LINGER)
-                       {
+       if (s != INVALID_SOCKET) {
+               if (!getsockopt(s,level,optname,buf,&len)) {
+                       if (level == SOL_SOCKET && optname == SO_LINGER) {
                                put_long(optval,((LINGER *)buf)->l_onoff);
                                put_long(optval+4,((LINGER *)buf)->l_linger);
-                       }
-                       else
-                       {
-                               if (len == 4) put_long(optval,*(long *)buf);
-                               else if (len == 2) put_word(optval,*(short *)buf);
-                               else write_log("BSDSOCK: ERROR - Unknown optlen (%d) in setsockopt(%d,%d)\n",level,optname);
+                       } else {
+                               if (len == 4)
+                                       put_long(optval,*(long *)buf);
+                               else if (len == 2)
+                                       put_word(optval,*(short *)buf);
+                               else
+                                       write_log("BSDSOCK: ERROR - Unknown optlen (%d) in setsockopt(%d,%d)\n",level,optname);
                        }
 
-//                     put_long(optlen,len); // some programs pass the actual ength instead of a pointer to the length, so...
+//                     put_long(optlen,len); // some programs pass the actual length instead of a pointer to the length, so...
                        TRACE(("OK (%d,%d)\n",len,*(long *)buf));
                        return 0;
-               }
-               else
-               {
+               } else {
                        SETERRNO;
                        TRACE(("failed (%d)\n",sb->sb_errno));
                }
@@ -1483,17 +1334,13 @@ uae_u32 host_getsockname(SB, uae_u32 sd, uae_u32 name, uae_u32 namelen)
        
        s = getsock(sb,sd);
        
-       if (s != INVALID_SOCKET)
-       {
+       if (s != INVALID_SOCKET) {
                rp_name = (struct sockaddr *)get_real_address(name);
                
-               if (getsockname(s,rp_name,&len))
-               {
+               if (getsockname(s,rp_name,&len)) {
                        SETERRNO;
                        TRACE(("failed (%d)\n",sb->sb_errno));
-               }
-               else
-               {
+               } else {
                        TRACE(("%d\n",len));
                        prepamigaaddr(rp_name,len);
                        put_long(namelen,len);
@@ -1517,17 +1364,13 @@ uae_u32 host_getpeername(SB, uae_u32 sd, uae_u32 name, uae_u32 namelen)
        
        s = getsock(sb,sd);
        
-       if (s != INVALID_SOCKET)
-       {
+       if (s != INVALID_SOCKET) {
                rp_name = (struct sockaddr *)get_real_address(name);
                
-               if (getpeername(s,rp_name,&len))
-               {
+               if (getpeername(s,rp_name,&len)) {
                        SETERRNO;
                        TRACE(("failed (%d)\n",sb->sb_errno));
-               }
-               else
-               {
+               } else {
                        TRACE(("%d\n",len));
                        prepamigaaddr(rp_name,len);
                        put_long(namelen,len);
@@ -1538,7 +1381,7 @@ uae_u32 host_getpeername(SB, uae_u32 sd, uae_u32 name, uae_u32 namelen)
        return -1;
 }
 
-uae_u32 host_IoctlSocket(SB, uae_u32 sd, uae_u32 request, uae_u32 arg)
+uae_u32 host_IoctlSocket(TrapContext *context, SB, uae_u32 sd, uae_u32 request, uae_u32 arg)
 {
        SOCKET s;
        uae_u32 data;
@@ -1548,8 +1391,7 @@ uae_u32 host_IoctlSocket(SB, uae_u32 sd, uae_u32 request, uae_u32 arg)
        sd++;
        s = getsock(sb,sd);
 
-       if (s != INVALID_SOCKET)
-       {
+       if (s != INVALID_SOCKET) {
                switch (request)
                {
                        case FIOSETOWN:
@@ -1562,13 +1404,10 @@ uae_u32 host_IoctlSocket(SB, uae_u32 sd, uae_u32 request, uae_u32 arg)
                        break;
                        case FIONBIO:
                                TRACE(("[FIONBIO] -> "));
-                               if (get_long(arg))
-                               {
+                               if (get_long(arg)) {
                                        TRACE(("nonblocking\n"));
                                        sb->ftable[sd-1] &= ~SF_BLOCKING;
-                               }
-                               else
-                               {
+                               } else {
                                        TRACE(("blocking\n"));
                                        sb->ftable[sd-1] |= SF_BLOCKING;
                                }
@@ -1581,32 +1420,32 @@ uae_u32 host_IoctlSocket(SB, uae_u32 sd, uae_u32 request, uae_u32 arg)
                                success = 0;
                                break;
                        case FIOASYNC:
-                               if (get_long(arg))
-                               {
+                               if (get_long(arg)) {
                                        sb->ftable[sd-1] |= REP_ALL;
 
                                        TRACE(("[FIOASYNC] -> enabled\n"));
-                                       if (sb->mtable[sd-1] || (sb->mtable[sd-1] = allocasyncmsg(sb,sd,s)))
-                                       {
+                                       if (sb->mtable[sd-1] || (sb->mtable[sd-1] = allocasyncmsg(sb,sd,s))) {
                                                WSAAsyncSelect(s,hWndSelector ? hAmigaWnd : hSockWnd,sb->mtable[sd-1],FD_ACCEPT | FD_CONNECT | FD_OOB | FD_READ | FD_WRITE | FD_CLOSE);
                                                success = 0;
                                                break;
                                        }
                                }
-                               else write_log(("BSDSOCK: WARNING - FIOASYNC disabling unsupported.\n"));
+                               else
+                                       write_log(("BSDSOCK: WARNING - FIOASYNC disabling unsupported.\n"));
 
                                success = -1;
                                break;
                        default:
                                write_log("BSDSOCK: WARNING - Unknown IoctlSocket request: 0x%08lx\n",request);
-                               seterrno(sb,22);        // EINVAL
+                               bsdsocklib_seterrno(sb,22); // EINVAL
+                               break;
                }
        }
        
        return success;
 }
 
-int host_CloseSocket(SB, int sd)
+int host_CloseSocket(TrapContext *context, SB, int sd)
 {
     unsigned int wMsg;
     SOCKET s;
@@ -1615,55 +1454,48 @@ int host_CloseSocket(SB, int sd)
        sd++;
 
     s = getsock(sb,sd);
-    if (s != INVALID_SOCKET)
-    {
-       if (sb->mtable[sd-1])
-       {
-           asyncsb[(sb->mtable[sd-1]-0xb000)/2] = NULL;
-           sb->mtable[sd-1] = 0;
-       }
+    if (s != INVALID_SOCKET) {
 
-       if (checksd(sb ,sd) == TRUE)
-               return 0;
+               if (sb->mtable[sd-1]) {
+                       asyncsb[(sb->mtable[sd-1]-0xb000)/2] = NULL;
+                       sb->mtable[sd-1] = 0;
+               }
 
+               if (checksd(sb ,sd) == TRUE)
+                       return 0;
 
+               BEGINBLOCKING;
 
-       BEGINBLOCKING;
+               for (;;) {
 
-       for (;;)
-       {
-           shutdown(s,1);
-           if (!closesocket(s))
-           {
-               releasesock(sb,sd);
-               TRACE(("OK\n"));
-               return 0;
-           }
+                       shutdown(s,1);
+                       if (!closesocket(s)) {
+                               releasesock(sb,sd);
+                               TRACE(("OK\n"));
+                               return 0;
+                       }
 
-           SETERRNO;
+                       SETERRNO;
 
-           if (sb->sb_errno != WSAEWOULDBLOCK-WSABASEERR || !(sb->ftable[sd-1] & SF_BLOCKING)) break;
+                       if (sb->sb_errno != WSAEWOULDBLOCK-WSABASEERR || !(sb->ftable[sd-1] & SF_BLOCKING))
+                               break;
 
-           if ((wMsg = allocasyncmsg(sb,sd,s)) != 0)
-           {
-               WSAAsyncSelect(s,hWndSelector ? hAmigaWnd : hSockWnd,wMsg,FD_CLOSE);
+                       if ((wMsg = allocasyncmsg(sb,sd,s)) != 0) {
+                               WSAAsyncSelect(s,hWndSelector ? hAmigaWnd : hSockWnd,wMsg,FD_CLOSE);
 
-       
-               WAITSIGNAL;
+                               WAITSIGNAL;
                
-
-               cancelasyncmsg(wMsg);
+                               cancelasyncmsg(context, wMsg);
        
-               if (sb->eintr)
-               {
-                   TRACE(("[interrupted]\n"));
-                   break;
+                               if (sb->eintr) {
+                                       TRACE(("[interrupted]\n"));
+                                       break;
+                               }
+                       } else
+                               break;
                }
-           }
-           else break;
-       }
 
-       ENDBLOCKING;
+               ENDBLOCKING;
     }
 
     TRACE(("failed (%d)\n",sb->sb_errno));
@@ -1679,49 +1511,40 @@ static void makesocktable(SB, uae_u32 fd_set_amiga, struct fd_set *fd_set_win, i
        uae_u32 currlong, mask;
        SOCKET s;
 
-       if (addthis != INVALID_SOCKET)
-       {
+       if (addthis != INVALID_SOCKET) {
                *fd_set_win->fd_array = addthis;
                fd_set_win->fd_count = 1;
-       }
-       else fd_set_win->fd_count = 0;
+       } else
+               fd_set_win->fd_count = 0;
 
-       if (!fd_set_amiga)
-       {
+       if (!fd_set_amiga) {
                fd_set_win->fd_array[fd_set_win->fd_count] = INVALID_SOCKET;
                return;
        }
 
-       if (nfds > sb->dtablesize)
-       {
+       if (nfds > sb->dtablesize) {
                write_log("BSDSOCK: ERROR - select()ing more sockets (%d) than socket descriptors available (%d)!\n",nfds,sb->dtablesize);
                nfds = sb->dtablesize;
        }
 
-       for (j = 0; ; j += 32, fd_set_amiga += 4)
-       {
+       for (j = 0; ; j += 32, fd_set_amiga += 4) {
                currlong = get_long(fd_set_amiga);
 
                mask = 1;
                
-               for (i = 0; i < 32; i++, mask <<= 1)
-               {
-                       if (i+j > nfds)
-                       {
+               for (i = 0; i < 32; i++, mask <<= 1) {
+                       if (i+j > nfds) {
                                fd_set_win->fd_array[fd_set_win->fd_count] = INVALID_SOCKET;
                                return;
                        }
                        
-                       if (currlong & mask)
-                       {
+                       if (currlong & mask) {
                                s = getsock(sb,j+i+1);
                                
-                               if (s != INVALID_SOCKET)
-                               {
+                               if (s != INVALID_SOCKET) {
                                        fd_set_win->fd_array[fd_set_win->fd_count++] = s;
 
-                                       if (fd_set_win->fd_count >= FD_SETSIZE)
-                                       {
+                                       if (fd_set_win->fd_count >= FD_SETSIZE) {
                                                write_log("BSDSOCK: ERROR - select()ing more sockets (%d) than the hard-coded fd_set limit (%d) - please report\n",nfds,FD_SETSIZE);
                                                return;
                                        }
@@ -1738,19 +1561,15 @@ static void makesockbitfield(SB, uae_u32 fd_set_amiga, struct fd_set *fd_set_win
        int n, i, j, val, mask;
        SOCKET currsock;
 
-       for (n = 0; n < nfds; n += 32)
-       {
+       for (n = 0; n < nfds; n += 32) {
                val = 0;
                mask = 1;
                
-               for (i = 0; i < 32; i++, mask <<= 1)
-               {
-                       if ((currsock = getsock(sb, n+i+1)) != INVALID_SOCKET)
-                       { // Do not use sb->dtable directly because of Newsrog
-                               for (j = fd_set_win->fd_count; j--; )
-                               {
-                                       if (fd_set_win->fd_array[j] == currsock)
-                                       {
+               for (i = 0; i < 32; i++, mask <<= 1) {
+                       if ((currsock = getsock(sb, n+i+1)) != INVALID_SOCKET) {
+                               // Do not use sb->dtable directly because of Newsrog
+                               for (j = fd_set_win->fd_count; j--; ) {
+                                       if (fd_set_win->fd_array[j] == currsock) {
                                                val |= mask;
                                                break;
                                        }
@@ -1765,7 +1584,8 @@ static void makesockbitfield(SB, uae_u32 fd_set_amiga, struct fd_set *fd_set_win
 static void fd_zero(uae_u32 fdset, uae_u32 nfds)
 {
        unsigned int i;
-       for (i = 0; i < nfds; i += 32, fdset += 4) put_long(fdset,0);
+       for (i = 0; i < nfds; i += 32, fdset += 4)
+               put_long(fdset,0);
 }
 
 // This seems to be the only way of implementing a cancelable WinSock2 select() call... sigh.
@@ -1782,12 +1602,10 @@ static unsigned int __stdcall thread_WaitSelect(void *indexp)
 
     SB;
 
-    for (;;)
-    {
+    for (;;) {
            WaitForSingleObject(hEvents[index],INFINITE);
 
-           if ((args = threadargsw[index]) != NULL)
-           {
+           if ((args = threadargsw[index]) != NULL) {
                        sb = args->sb;
                    nfds = args->nfds;
                    readfds = args->readfds;
@@ -1797,11 +1615,12 @@ static unsigned int __stdcall thread_WaitSelect(void *indexp)
            
                    // construct descriptor tables
                    makesocktable(sb,readfds,&readsocks,nfds,sb->sockAbort);
-                   if (writefds) makesocktable(sb,writefds,&writesocks,nfds,INVALID_SOCKET);
-                   if (exceptfds) makesocktable(sb,exceptfds,&exceptsocks,nfds,INVALID_SOCKET);
+                   if (writefds)
+                               makesocktable(sb,writefds,&writesocks,nfds,INVALID_SOCKET);
+                   if (exceptfds)
+                               makesocktable(sb,exceptfds,&exceptsocks,nfds,INVALID_SOCKET);
            
-                   if (timeout)
-                   {
+                   if (timeout) {
                            tv.tv_sec = get_long(timeout);
                            tv.tv_usec = get_long(timeout+4);
                            TRACE(("(timeout: %d.%06d) ",tv.tv_sec,tv.tv_usec));
@@ -1810,50 +1629,45 @@ static unsigned int __stdcall thread_WaitSelect(void *indexp)
                    TRACE(("-> "));
            
                    sb->resultval = select(nfds+1,&readsocks,writefds ? &writesocks : NULL,exceptfds ? &exceptsocks : NULL,timeout ? &tv : 0);
-                       if (sb->resultval == SOCKET_ERROR)
-                   { 
-                       // select was stopped by sb->sockAbort
-                       if (readsocks.fd_count > 1)
-                               {
-                               makesocktable(sb,readfds,&readsocks,nfds,INVALID_SOCKET);
-                               tv.tv_sec = 0;
-                               tv.tv_usec = 10000;
-                               // Check for 10ms if data is available
-                               sb->resultval = select(nfds+1,&readsocks,writefds ? &writesocks : NULL,exceptfds ? &exceptsocks : NULL,&tv);
-                               if (sb->resultval == 0)
-                                       { // Now timeout -> really no data available
-                                       if (GetLastError() != 0)
-                                               {
-                                               sb->resultval = SOCKET_ERROR;
-                                               // Set old resultval
+                       if (sb->resultval == SOCKET_ERROR) { 
+                               // select was stopped by sb->sockAbort
+                               if (readsocks.fd_count > 1) {
+                                       makesocktable(sb,readfds,&readsocks,nfds,INVALID_SOCKET);
+                                       tv.tv_sec = 0;
+                                       tv.tv_usec = 10000;
+                                       // Check for 10ms if data is available
+                                       sb->resultval = select(nfds+1,&readsocks,writefds ? &writesocks : NULL,exceptfds ? &exceptsocks : NULL,&tv);
+                                       if (sb->resultval == 0) { // Now timeout -> really no data available
+                                               if (GetLastError() != 0) {
+                                                       sb->resultval = SOCKET_ERROR;
+                                                       // Set old resultval
                                                }
                                        }   
                                }
                    }
-                       if (FD_ISSET(sb->sockAbort,&readsocks))
-                               {
-                               if (sb->resultval != SOCKET_ERROR)
-                                       {
+                       if (FD_ISSET(sb->sockAbort,&readsocks)) {
+                               if (sb->resultval != SOCKET_ERROR) {
                                        sb->resultval--;
-                                       }
                                }
-                       else
-                               {
-                       sb->needAbort = 0;
-                               }
-                   if (sb->resultval == SOCKET_ERROR)
-                   {
+                       } else {
+                               sb->needAbort = 0;
+                       }
+                   if (sb->resultval == SOCKET_ERROR) {
                            SETERRNO;
                            TRACE(("failed (%d) - ",sb->sb_errno));
-                           if (readfds) fd_zero(readfds,nfds);
-                           if (writefds) fd_zero(writefds,nfds);
-                           if (exceptfds) fd_zero(exceptfds,nfds);
-                   }
-                   else
-                   {
-                           if (readfds) makesockbitfield(sb,readfds,&readsocks,nfds);
-                           if (writefds) makesockbitfield(sb,writefds,&writesocks,nfds);
-                           if (exceptfds) makesockbitfield(sb,exceptfds,&exceptsocks,nfds);
+                           if (readfds)
+                                       fd_zero(readfds,nfds);
+                           if (writefds)
+                                       fd_zero(writefds,nfds);
+                           if (exceptfds)
+                                       fd_zero(exceptfds,nfds);
+                   } else {
+                           if (readfds)
+                                       makesockbitfield(sb,readfds,&readsocks,nfds);
+                           if (writefds)
+                                       makesockbitfield(sb,writefds,&writesocks,nfds);
+                           if (exceptfds)
+                                       makesockbitfield(sb,exceptfds,&exceptsocks,nfds);
                    }
            
                    SETSIGNAL;
@@ -1866,7 +1680,7 @@ static unsigned int __stdcall thread_WaitSelect(void *indexp)
     return result;
 }
 
-void host_WaitSelect(SB, uae_u32 nfds, uae_u32 readfds, uae_u32 writefds, uae_u32 exceptfds, uae_u32 timeout, uae_u32 sigmp)
+void host_WaitSelect(TrapContext *context, SB, uae_u32 nfds, uae_u32 readfds, uae_u32 writefds, uae_u32 exceptfds, uae_u32 timeout, uae_u32 sigmp)
 {
        uae_u32 sigs, wssigs;
        int i;
@@ -1876,41 +1690,44 @@ void host_WaitSelect(SB, uae_u32 nfds, uae_u32 readfds, uae_u32 writefds, uae_u3
 
        TRACE(("WaitSelect(%d,0x%lx,0x%lx,0x%lx,0x%lx,0x%lx) ",nfds,readfds,writefds,exceptfds,timeout,wssigs));
 
-       if (!readfds && !writefds && !exceptfds && !timeout && !wssigs)
-       {
+       if (!readfds && !writefds && !exceptfds && !timeout && !wssigs) {
                sb->resultval = 0;
                TRACE(("-> [ignored]\n"));
                return;
        }
-       if (wssigs)
-       {
-               m68k_dreg(regs,0) = 0;
-               m68k_dreg(regs,1) = wssigs;
-               sigs = CallLib(get_long(4),-0x132) & wssigs;    // SetSignal()
+       if (wssigs) {
+               m68k_dreg(&context->regs,0) = 0;
+               m68k_dreg(&context->regs,1) = wssigs;
+               sigs = CallLib(context, get_long(4),-0x132) & wssigs; // SetSignal()
                
-               if (sigs)
-               {
+               if (sigs) {
                        TRACE(("-> [preempted by signals 0x%08lx]\n",sigs & wssigs));
                        put_long(sigmp,sigs & wssigs);
                        // Check for zero address -> otherwise WinUAE crashes
-                       if (readfds) fd_zero(readfds,nfds);
-                       if (writefds) fd_zero(writefds,nfds);
-                       if (exceptfds) fd_zero(exceptfds,nfds);
+                       if (readfds)
+                               fd_zero(readfds,nfds);
+                       if (writefds)
+                               fd_zero(writefds,nfds);
+                       if (exceptfds)
+                               fd_zero(exceptfds,nfds);
                        sb->resultval = 0;
-                       seterrno(sb,0);
+                       bsdsocklib_seterrno(sb,0);
                        return;
                }
        }
-       if (nfds == 0)
-       { // No sockets to check, only wait for signals
-               m68k_dreg(regs,0) = wssigs;
-               sigs = CallLib(get_long(4),-0x13e);     // Wait()
+       if (nfds == 0) {
+               // No sockets to check, only wait for signals
+               m68k_dreg(&context->regs,0) = wssigs;
+               sigs = CallLib(context, get_long(4),-0x13e); // Wait()
 
                put_long(sigmp,sigs & wssigs);
 
-               if (readfds) fd_zero(readfds,nfds);
-               if (writefds) fd_zero(writefds,nfds);
-               if (exceptfds) fd_zero(exceptfds,nfds);
+               if (readfds)
+                       fd_zero(readfds,nfds);
+               if (writefds)
+                       fd_zero(writefds,nfds);
+               if (exceptfds)
+                       fd_zero(exceptfds,nfds);
                sb->resultval = 0;
                return;
        }
@@ -1924,24 +1741,19 @@ void host_WaitSelect(SB, uae_u32 nfds, uae_u32 readfds, uae_u32 writefds, uae_u3
                        break;
        }
 
-       if (i >= MAX_SELECT_THREADS)
-       {
-           for (i = 0; i < MAX_SELECT_THREADS; i++)
-           {
-                       if (!hThreads[i])
-                       {
+       if (i >= MAX_SELECT_THREADS) {
+           for (i = 0; i < MAX_SELECT_THREADS; i++) {
+                       if (!hThreads[i]) {
                                hEvents[i] = CreateEvent(NULL,FALSE,FALSE,NULL);
                                hThreads[i] = THREAD(thread_WaitSelect,&i);
-                               if (hEvents[i] == NULL || hThreads[i] == NULL)
-                               {
+                               if (hEvents[i] == NULL || hThreads[i] == NULL) {
                                        hThreads[i] = 0;
                                        write_log("BSDSOCK: ERROR - Thread/Event creation failed - error code: %d\n",
                                                GetLastError());
-                                       seterrno(sb,12);        // ENOMEM
+                                       bsdsocklib_seterrno(sb,12); // ENOMEM
                                        sb->resultval = -1;
                                        return;
                                }
-                           
                                // this should improve responsiveness
                                SetThreadPriority(hThreads[i],THREAD_PRIORITY_TIME_CRITICAL);
                                break;
@@ -1949,9 +1761,9 @@ void host_WaitSelect(SB, uae_u32 nfds, uae_u32 readfds, uae_u32 writefds, uae_u3
            }
        }
        
-       if (i >= MAX_SELECT_THREADS) write_log("BSDSOCK: ERROR - Too many select()s\n");
-       else
-       {
+       if (i >= MAX_SELECT_THREADS)
+               write_log("BSDSOCK: ERROR - Too many select()s\n");
+       else {
                SOCKET newsock = INVALID_SOCKET;
 
                taw.sb = sb;
@@ -1965,21 +1777,19 @@ void host_WaitSelect(SB, uae_u32 nfds, uae_u32 readfds, uae_u32 writefds, uae_u3
 
                SetEvent(hEvents[i]);
 
-               m68k_dreg(regs,0) = (((uae_u32)1)<<sb->signal)|sb->eintrsigs|wssigs;
-               sigs = CallLib(get_long(4),-0x13e);     // Wait()
+               m68k_dreg(&context->regs,0) = (((uae_u32)1)<<sb->signal)|sb->eintrsigs|wssigs;
+               sigs = CallLib(context, get_long(4),-0x13e);    // Wait()
 /*
                if ((1<<sb->signal) & sigs)
                { // 2.3.2002/SR Fix for AmiFTP -> Thread is ready, no need to Abort
                    sb->needAbort = 0;
                }
 */
-               if (sb->needAbort)
-               {
+               if (sb->needAbort) {
                        if ((newsock = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP)) == INVALID_SOCKET)
                                write_log("BSDSOCK: ERROR - Cannot create socket: %d\n",WSAGetLastError());
                        shutdown(sb->sockAbort,1);
-                       if (newsock != sb->sockAbort)
-                       {
+                       if (newsock != sb->sockAbort) {
                                shutdown(sb->sockAbort,1);
                                closesocket(sb->sockAbort);
                        }
@@ -1989,41 +1799,35 @@ void host_WaitSelect(SB, uae_u32 nfds, uae_u32 readfds, uae_u32 writefds, uae_u3
 
                CANCELSIGNAL;
 
-               if (newsock != INVALID_SOCKET) sb->sockAbort = newsock;
+               if (newsock != INVALID_SOCKET)
+                       sb->sockAbort = newsock;
 
-       if( sigmp )
-       {
+               if(sigmp) {
                    put_long(sigmp,sigs & wssigs);
 
-                   if (sigs & sb->eintrsigs)
-                   {
+                   if (sigs & sb->eintrsigs) {
                            TRACE(("[interrupted]\n"));
                            sb->resultval = -1;
-                           seterrno(sb,4);     // EINTR
-                   }
-                   else if (sigs & wssigs)
-                   {
+                           bsdsocklib_seterrno(sb,4); // EINTR
+                   } else if (sigs & wssigs) {
                            TRACE(("[interrupted by signals 0x%08lx]\n",sigs & wssigs));
                                if (readfds) fd_zero(readfds,nfds);
                                if (writefds) fd_zero(writefds,nfds);
                                if (exceptfds) fd_zero(exceptfds,nfds);
-                           seterrno(sb,0);
+                           bsdsocklib_seterrno(sb,0);
                            sb->resultval = 0;
                    }
-                       if (sb->resultval >= 0)
-                       {
+                       if (sb->resultval >= 0) {
                                TRACE(("%d\n",sb->resultval));
-                       }
-                       else
-                       {
+                       } else {
                                TRACE(("%d errno %d\n",sb->resultval,sb->sb_errno));
                        }
-       }
-               else TRACE(("%d\n",sb->resultval));
+               } else
+                       TRACE(("%d\n",sb->resultval));
        }
 }
 
-uae_u32 host_Inet_NtoA(SB, uae_u32 in)
+uae_u32 host_Inet_NtoA(TrapContext *context, SB, uae_u32 in)
 {
        char *addr;
        struct in_addr ina;
@@ -2033,14 +1837,13 @@ uae_u32 host_Inet_NtoA(SB, uae_u32 in)
 
        TRACE(("Inet_NtoA(%lx) -> ",in));
 
-       if ((addr = inet_ntoa(ina)) != NULL)
-       {
-               scratchbuf = m68k_areg(regs,6)+offsetof(struct UAEBSDBase,scratchbuf);
+       if ((addr = inet_ntoa(ina)) != NULL) {
+               scratchbuf = m68k_areg(&context->regs,6) + offsetof(struct UAEBSDBase,scratchbuf);
                strncpyha(scratchbuf,addr,SCRATCHBUFSIZE);
                TRACE(("%s\n",addr));
                return scratchbuf;
-       }
-       else SETERRNO;
+       } else
+               SETERRNO;
 
        TRACE(("failed (%d)\n",sb->sb_errno));
 
@@ -2066,17 +1869,14 @@ BOOL CheckOnline(SB)
 {
        DWORD dwFlags;
        BOOL bReturn = TRUE;
-       if (InternetGetConnectedState(&dwFlags,0) == FALSE)
-       { // Internet is offline
-               if (InternetAttemptConnect(0) != ERROR_SUCCESS)
-               { // Show Dialer window
+       if (InternetGetConnectedState(&dwFlags,0) == FALSE) { // Internet is offline
+               if (InternetAttemptConnect(0) != ERROR_SUCCESS) { // Show Dialer window
                        sb->sb_errno = 10001;
                        sb->sb_herrno = 1;
                        bReturn = FALSE;
                        // No success or aborted
                }
-               if (isfullscreen())
-               {
+               if (isfullscreen()) {
                        ShowWindow (hAmigaWnd, SW_RESTORE);
                        SetActiveWindow(hAmigaWnd);
                }
@@ -2096,19 +1896,16 @@ static unsigned int __stdcall thread_get(void *indexp)
     char *buf;
     SB;
 
-    for (;;)
-    {
-           WaitForSingleObject(hGetEvents[index],INFINITE);
-               if (threadGetargs_inuse[index] == -1)
-               {
+    for (;;) {
+           WaitForSingleObject(hGetEvents[index], INFINITE);
+               if (threadGetargs_inuse[index] == -1) {
                        threadGetargs_inuse[index] = 0;
                        threadGetargs[index] = NULL;
                }
-           if ((args = threadGetargs[index]) != NULL )
-           {
+           if ((args = threadGetargs[index]) != NULL) {
                        sb = args->sb;
-                       if (args->args1 == 0)
-                       { // gethostbyname or gethostbyaddr
+                       if (args->args1 == 0) {
+                               // gethostbyname or gethostbyaddr
                                struct hostent *host;
                                name = args->args2;
                                namelen = args->args3;
@@ -2116,57 +1913,47 @@ static unsigned int __stdcall thread_get(void *indexp)
                                buf = args->args5;
                                name_rp = get_real_address(name);
 
-                               if (strchr(name_rp,'.') == 0 || CheckOnline(sb) == TRUE)
-                               { // Local Address or Internet Online ?
-                                       if (addrtype == -1)
-                                       {
+                               if (strchr(name_rp,'.') == 0 || CheckOnline(sb) == TRUE) {
+                                       // Local Address or Internet Online ?
+                                       if (addrtype == -1) {
                                                host = gethostbyname(name_rp);
-                                       }
-                                       else
-                                       {
+                                       } else {
                                                host = gethostbyaddr(name_rp,namelen,addrtype);
                                        }
-                                       if (threadGetargs_inuse[index] != -1)
-                                       { // No CTRL-C Signal
-                                               if (host == 0)
-                                               {
+                                       if (threadGetargs_inuse[index] != -1) {
+                                               // No CTRL-C Signal
+                                               if (host == 0) {
                                                        // Error occured 
                                                        SETERRNO;
                                                        TRACE(("failed (%d) - ",sb->sb_errno));
-                                               }
-                                               else
-                                               {
-                                                       seterrno(sb,0);
+                                               } else {
+                                                       bsdsocklib_seterrno(sb,0);
                                                        memcpy(buf,host,sizeof(HOSTENT));
                                                }
                                        }
                                }
                        }
-                       if (args->args1 == 1)
-                       { // getprotobyname
+                       if (args->args1 == 1) {
+                               // getprotobyname
                                struct protoent  *proto;
 
                                name = args->args2;
                                buf = args->args5;
                                name_rp = get_real_address(name);
                                proto = getprotobyname (name_rp);
-                               if (threadGetargs_inuse[index] != -1)
-                               { // No CTRL-C Signal
-                                       if (proto == 0)
-                                       {
+                               if (threadGetargs_inuse[index] != -1) { // No CTRL-C Signal
+                                       if (proto == 0) {
                                                // Error occured 
                                                SETERRNO;
                                                TRACE(("failed (%d) - ",sb->sb_errno));
-                                       }
-                                       else
-                                       {
-                                               seterrno(sb,0);
+                                       } else {
+                                               bsdsocklib_seterrno(sb,0);
                                                memcpy(buf,proto,sizeof(struct protoent));
                                        }
                                }
                        }
-                       if (args->args1 == 2)
-                       { // getservbyport and getservbyname
+                       if (args->args1 == 2) {
+                               // getservbyport and getservbyname
                                uae_u32 nameport;
                                uae_u32 proto;
                                uae_u32 type;
@@ -2178,28 +1965,23 @@ static unsigned int __stdcall thread_get(void *indexp)
                                type = args->args4;
                                buf = args->args5;
        
-                               if (proto) proto_rp = get_real_address(proto);
+                               if (proto)
+                                       proto_rp = get_real_address(proto);
 
-                               if (type)
-                               {
+                               if (type) {
                                        serv = getservbyport(nameport,proto_rp);
-                               }
-                               else
-                               {
+                               } else {
                                        name_rp = get_real_address(nameport);
                                        serv = getservbyname(name_rp,proto_rp);
                                }
-                               if (threadGetargs_inuse[index] != -1)
-                               { // No CTRL-C Signal
-                                       if (serv == 0)
-                                       {
+                               if (threadGetargs_inuse[index] != -1) {
+                                       // No CTRL-C Signal
+                                       if (serv == 0) {
                                                // Error occured 
                                                SETERRNO;
                                                TRACE(("failed (%d) - ",sb->sb_errno));
-                                       }
-                                       else
-                                       {
-                                               seterrno(sb,0);
+                                       } else {
+                                               bsdsocklib_seterrno(sb,0);
                                                memcpy(buf,serv,sizeof(struct servent));
                                        }
                                }
@@ -2219,19 +2001,16 @@ static unsigned int __stdcall thread_get(void *indexp)
     return result;
 }
 
-void host_gethostbynameaddr(SB, uae_u32 name, uae_u32 namelen, long addrtype)
+void host_gethostbynameaddr(TrapContext *context, SB, uae_u32 name, uae_u32 namelen, long addrtype)
 {
        HOSTENT *h;
        int size, numaliases = 0, numaddr = 0;
        uae_u32 aptr;
        char *name_rp;
        int i;
-
        struct threadargs args;
-
        uae_u32 addr;
        uae_u32 *addr_list[2];
-
        char buf[MAXGETHOSTSTRUCT];
        unsigned int wMsg = 0;
 
@@ -2242,14 +2021,12 @@ void host_gethostbynameaddr(SB, uae_u32 name, uae_u32 namelen, long addrtype)
        name_rp = get_real_address(name);
 
 
-       if (addrtype == -1)
-       {
+       if (addrtype == -1) {
                TRACE(("gethostbyname(%s) -> ",name_rp));
                
                // workaround for numeric host "names"
-               if ((addr = inet_addr(name_rp)) != INADDR_NONE)
-               {
-                       seterrno(sb,0);
+               if ((addr = inet_addr(name_rp)) != INADDR_NONE) {
+                       bsdsocklib_seterrno(sb,0);
                        ((HOSTENT *)buf)->h_name = name_rp;
                        ((HOSTENT *)buf)->h_aliases = NULL;
                        ((HOSTENT *)buf)->h_addrtype = AF_INET;
@@ -2260,9 +2037,7 @@ void host_gethostbynameaddr(SB, uae_u32 name, uae_u32 namelen, long addrtype)
        
                        goto kludge;
                }
-       }
-       else
-       {
+       } else {
                TRACE(("gethostbyaddr(0x%lx,0x%lx,%ld) -> ",name,namelen,addrtype));
        }
 
@@ -2273,30 +2048,24 @@ void host_gethostbynameaddr(SB, uae_u32 name, uae_u32 namelen, long addrtype)
        args.args4 = addrtype;
        args.args5 = buf;
 
-       for (i = 0; i < MAX_GET_THREADS; i++) 
-       {
-               if (threadGetargs_inuse[i] == -1)
-               {
+       for (i = 0; i < MAX_GET_THREADS; i++)  {
+               if (threadGetargs_inuse[i] == -1) {
                        threadGetargs_inuse[i] = 0;
                        threadGetargs[i] = NULL;
                }
                if (hGetThreads[i] && !threadGetargs_inuse[i]) break;
        }
 
-       if (i >= MAX_GET_THREADS)
-       {
-           for (i = 0; i < MAX_GET_THREADS; i++)
-           {
-                       if (hGetThreads[i] == NULL)
-                       {
+       if (i >= MAX_GET_THREADS) {
+           for (i = 0; i < MAX_GET_THREADS; i++) {
+                       if (hGetThreads[i] == NULL) {
                                hGetEvents[i] = CreateEvent(NULL,FALSE,FALSE,NULL);
                                hGetThreads[i] = THREAD(thread_get, &i);
-                               if (hGetEvents[i] == NULL || hGetThreads[i] == NULL)
-                               {
+                               if (hGetEvents[i] == NULL || hGetThreads[i] == NULL) {
                                        hGetThreads[i] = NULL;
                                        write_log("BSDSOCK: ERROR - Thread/Event creation failed - error code: %d\n",
                                                GetLastError());
-                                       seterrno(sb,12);        // ENOMEM
+                                       bsdsocklib_seterrno(sb,12); // ENOMEM
                                        sb->resultval = -1;
                                        return;
                                }
@@ -2305,27 +2074,25 @@ void host_gethostbynameaddr(SB, uae_u32 name, uae_u32 namelen, long addrtype)
            }
        }
        
-       if (i >= MAX_GET_THREADS) write_log("BSDSOCK: ERROR - Too many gethostbyname()s\n");
-       else
-       {
+       if (i >= MAX_GET_THREADS)
+               write_log("BSDSOCK: ERROR - Too many gethostbyname()s\n");
+       else {
                bsdsetpriority (hGetThreads[i]);
                threadGetargs[i] = &args;
                threadGetargs_inuse[i] = 1;
 
                SetEvent(hGetEvents[i]);
-               }
+       }
        sb->eintr = 0;
-       while ( threadGetargs_inuse[i] != 0 && sb->eintr == 0) 
-       {       
+       while ( threadGetargs_inuse[i] != 0 && sb->eintr == 0) {        
                WAITSIGNAL;
                if (sb->eintr == 1)
                        threadGetargs_inuse[i] = -1;
        }
-       
+
        CANCELSIGNAL;
-       
-       if (!sb->sb_errno)
-       {
+
+       if (!sb->sb_errno) {
 kludge:
                h = (HOSTENT *)buf;
                
@@ -2338,25 +2105,22 @@ kludge:
                        while (h->h_aliases[numaliases])
                                size += strlen(h->h_aliases[numaliases++])+5;
 
-               if (h->h_addr_list != NULL)
-               {
+               if (h->h_addr_list != NULL) {
                        while (h->h_addr_list[numaddr]) numaddr++;
                        size += numaddr*(h->h_length+4);
                }
 
-               if (sb->hostent)
-               {
-           uae_FreeMem( sb->hostent, sb->hostentsize );
+               if (sb->hostent) {
+                       uae_FreeMem(context, sb->hostent, sb->hostentsize);
                }
 
-       sb->hostent = uae_AllocMem( size, 0 );
+               sb->hostent = uae_AllocMem(context, size, 0);
 
-               if (!sb->hostent)
-               {
+               if (!sb->hostent) {
                        write_log("BSDSOCK: WARNING - gethostby%s() ran out of Amiga memory "
                                "(couldn't allocate %ld bytes) while returning result of lookup for '%s'\n",
                                addrtype == -1 ? "name" : "addr", size, name_rp);
-                       seterrno(sb,12); // ENOMEM
+                       bsdsocklib_seterrno(sb,12); // ENOMEM
                        return;
                }
                
@@ -2370,34 +2134,32 @@ kludge:
                put_long(sb->hostent+12,h->h_length);
                put_long(sb->hostent+16,sb->hostent+24+numaliases*4);
                
-               for (i = 0; i < numaliases; i++) put_long(sb->hostent+20+i*4,addstr(&aptr,h->h_aliases[i]));
+               for (i = 0; i < numaliases; i++)
+                       put_long(sb->hostent+20+i*4,addstr(&aptr,h->h_aliases[i]));
                put_long(sb->hostent+20+numaliases*4,0);
-               for (i = 0; i < numaddr; i++) put_long(sb->hostent+24+(numaliases+i)*4,addmem(&aptr,h->h_addr_list[i],h->h_length));
+               for (i = 0; i < numaddr; i++)
+                       put_long(sb->hostent+24+(numaliases+i)*4,addmem(&aptr,h->h_addr_list[i],h->h_length));
                put_long(sb->hostent+24+numaliases*4+numaddr*4,0);
                put_long(sb->hostent,aptr);
                addstr(&aptr,h->h_name);
 
                TRACE(("OK (%s)\n",h->h_name));
-               seterrno(sb,0);
-       }
-       else
-       {
+               bsdsocklib_seterrno(sb,0);
+
+       } else {
                TRACE(("failed (%d/%d)\n",sb->sb_errno,sb->sb_herrno));
        }
 
 }
 
-void host_getprotobyname(SB, uae_u32 name)
+void host_getprotobyname(TrapContext *context, SB, uae_u32 name)
 {
        PROTOENT *p;
        int size, numaliases = 0;
        uae_u32 aptr;
        char *name_rp;
        int i;
-
        struct threadargs args;
-
-
        char buf[MAXGETHOSTSTRUCT];
 
        name_rp = get_real_address(name);
@@ -2409,28 +2171,22 @@ void host_getprotobyname(SB, uae_u32 name)
        args.args2 = name;
        args.args5 = buf;
 
-       for (i = 0; i < MAX_GET_THREADS; i++) 
-       {
-               if (threadGetargs_inuse[i] == -1)
-               {
+       for (i = 0; i < MAX_GET_THREADS; i++)  {
+               if (threadGetargs_inuse[i] == -1) {
                        threadGetargs_inuse[i] = 0;
                        threadGetargs[i] = NULL;
                }
                if (hGetThreads[i] && !threadGetargs_inuse[i]) break;
        }
-       if (i >= MAX_GET_THREADS)
-       {
-           for (i = 0; i < MAX_GET_THREADS; i++)
-           {
-                       if (!hGetThreads[i])
-                       {
+       if (i >= MAX_GET_THREADS) {
+           for (i = 0; i < MAX_GET_THREADS; i++) {
+                       if (!hGetThreads[i]) {
                                hEvents[i] = CreateEvent(NULL,FALSE,FALSE,NULL);
                                hGetThreads[i] = THREAD(thread_get,&i);
-                               if (hGetEvents[i] == NULL || hGetThreads[i] == NULL)
-                               {
+                               if (hGetEvents[i] == NULL || hGetThreads[i] == NULL) {
                                        hGetThreads[i] = 0;
                                        write_log("BSDSOCK: ERROR - Thread/Event creation failed - error code: %d\n",GetLastError());
-                                       seterrno(sb,12);        // ENOMEM
+                                       bsdsocklib_seterrno(sb,12); // ENOMEM
                                        sb->resultval = -1;
                                        return;
                                }
@@ -2439,52 +2195,49 @@ void host_getprotobyname(SB, uae_u32 name)
            }
        }
        
-       if (i >= MAX_GET_THREADS) write_log("BSDSOCK: ERROR - Too many getprotobyname()s\n");
-       else
-       {
+       if (i >= MAX_GET_THREADS)
+               write_log("BSDSOCK: ERROR - Too many getprotobyname()s\n");
+       else {
                bsdsetpriority (hGetThreads[i]);
 
                threadGetargs[i] = &args;
                threadGetargs_inuse[i] = 1;
 
                SetEvent(hGetEvents[i]);
-               }
+       }
 
        sb->eintr = 0;
-       while ( threadGetargs_inuse[i] != 0 && sb->eintr == 0) 
-               {       
+       while ( threadGetargs_inuse[i] != 0 && sb->eintr == 0)  {       
                WAITSIGNAL;
                if (sb->eintr == 1)
                        threadGetargs_inuse[i] = -1;
-               }
+       }
 
        CANCELSIGNAL;
 
 
-       if (!sb->sb_errno)
-       {
+       if (!sb->sb_errno) {
                p = (PROTOENT *)buf;
 
                // compute total size of protoent
                size = 16;
-               if (p->p_name != NULL) size += strlen(p->p_name)+1;
+               if (p->p_name != NULL)
+                       size += strlen(p->p_name)+1;
 
                if (p->p_aliases != NULL)
                        while (p->p_aliases[numaliases]) size += strlen(p->p_aliases[numaliases++])+5;
 
-               if (sb->protoent)
-               {
-           uae_FreeMem( sb->protoent, sb->protoentsize );
+               if (sb->protoent) {
+                       uae_FreeMem(context, sb->protoent, sb->protoentsize);
                }
 
-               sb->protoent = uae_AllocMem( size, 0 );
+               sb->protoent = uae_AllocMem(context, size, 0);
 
-               if (!sb->protoent)
-               {
+               if (!sb->protoent) {
                        write_log("BSDSOCK: WARNING - getprotobyname() ran out of Amiga memory "
                                "(couldn't allocate %ld bytes) while returning result of lookup for '%s'\n",
                                size, name_rp);
-                       seterrno(sb,12); // ENOMEM
+                       bsdsocklib_seterrno(sb,12); // ENOMEM
                        return;
                }
 
@@ -2496,22 +2249,26 @@ void host_getprotobyname(SB, uae_u32 name)
                put_long(sb->protoent+4,sb->protoent+12);
                put_long(sb->protoent+8,p->p_proto);
                
-               for (i = 0; i < numaliases; i++) put_long(sb->protoent+12+i*4,addstr(&aptr,p->p_aliases[i]));
+               for (i = 0; i < numaliases; i++)
+                       put_long(sb->protoent+12+i*4,addstr(&aptr,p->p_aliases[i]));
                put_long(sb->protoent+12+numaliases*4,0);
                put_long(sb->protoent,aptr);
                addstr(&aptr,p->p_name);
                TRACE(("OK (%s, %d)\n",p->p_name,p->p_proto));
-               seterrno(sb,0);
-       }
-       else
-       {
+               bsdsocklib_seterrno(sb,0);
+
+       } else {
                TRACE(("failed (%d)\n",sb->sb_errno));
        }
 
 }
 
+void host_getprotobynumber(TrapContext *context, SB, uae_u32 name)
+{
+       bsdsocklib_seterrno(sb, 1);
+}
 
-void host_getservbynameport(SB, uae_u32 nameport, uae_u32 proto, uae_u32 type)
+void host_getservbynameport(TrapContext *context, SB, uae_u32 nameport, uae_u32 proto, uae_u32 type)
 {
        SERVENT *s;
        int size, numaliases = 0;
@@ -2522,14 +2279,12 @@ void host_getservbynameport(SB, uae_u32 nameport, uae_u32 proto, uae_u32 type)
        char buf[MAXGETHOSTSTRUCT];
        struct threadargs args;
 
-       if (proto) proto_rp = get_real_address(proto);
+       if (proto)
+               proto_rp = get_real_address(proto);
 
-       if (type)
-       {
+       if (type) {
                TRACE(("getservbyport(%d,%s) -> ",nameport,proto_rp ? proto_rp : "NULL"));
-       }
-       else
-       {
+       } else {
                name_rp = get_real_address(nameport);
                TRACE(("getservbyname(%s,%s) -> ",name_rp,proto_rp ? proto_rp : "NULL"));
        }
@@ -2541,28 +2296,22 @@ void host_getservbynameport(SB, uae_u32 nameport, uae_u32 proto, uae_u32 type)
        args.args4 = type;
        args.args5 = buf;
 
-       for (i = 0; i < MAX_GET_THREADS; i++) 
-       {
-               if (threadGetargs_inuse[i] == -1)
-               {
+       for (i = 0; i < MAX_GET_THREADS; i++)  {
+               if (threadGetargs_inuse[i] == -1) {
                        threadGetargs_inuse[i] = 0;
                        threadGetargs[i] = NULL;
                }
                if (hGetThreads[i] && !threadGetargs_inuse[i]) break;
        }
-       if (i >= MAX_GET_THREADS)
-       {
-           for (i = 0; i < MAX_GET_THREADS; i++)
-           {
-                       if (!hGetThreads[i])
-                       {
+       if (i >= MAX_GET_THREADS) {
+           for (i = 0; i < MAX_GET_THREADS; i++) {
+                       if (!hGetThreads[i]) {
                                hGetEvents[i] = CreateEvent(NULL,FALSE,FALSE,NULL);
                                hGetThreads[i] = THREAD(thread_get,&i);
-                               if (hGetEvents[i] == NULL || hGetThreads[i] == NULL)
-                               {
+                               if (hGetEvents[i] == NULL || hGetThreads[i] == NULL) {
                                        hGetThreads[i] = 0;
                                        write_log("BSDSOCK: ERROR - Thread/Event creation failed - error code: %d\n",GetLastError());
-                                       seterrno(sb,12);        // ENOMEM
+                                       bsdsocklib_seterrno(sb,12); // ENOMEM
                                        sb->resultval = -1;
                                        return;
                                }
@@ -2572,20 +2321,19 @@ void host_getservbynameport(SB, uae_u32 nameport, uae_u32 proto, uae_u32 type)
            }
        }
        
-       if (i >= MAX_GET_THREADS) write_log("BSDSOCK: ERROR - Too many getprotobyname()s\n");
-       else
-       {
+       if (i >= MAX_GET_THREADS)
+               write_log("BSDSOCK: ERROR - Too many getprotobyname()s\n");
+       else {
                bsdsetpriority (hGetThreads[i]);
 
                threadGetargs[i] = &args;
                threadGetargs_inuse[i] = 1;
 
                SetEvent(hGetEvents[i]);
-               }
+       }
 
        sb->eintr = 0;
-       while ( threadGetargs_inuse[i] != 0 && sb->eintr == 0) 
-       {       
+       while ( threadGetargs_inuse[i] != 0 && sb->eintr == 0) {        
                WAITSIGNAL;
                if (sb->eintr == 1)
                        threadGetargs_inuse[i] = -1;
@@ -2593,29 +2341,29 @@ void host_getservbynameport(SB, uae_u32 nameport, uae_u32 proto, uae_u32 type)
 
        CANCELSIGNAL;
 
-       if (!sb->sb_errno)
-       {
+       if (!sb->sb_errno) {
                s = (SERVENT *)buf;
 
                // compute total size of servent
                size = 20;
-               if (s->s_name != NULL) size += strlen(s->s_name)+1;
-               if (s->s_proto != NULL) size += strlen(s->s_proto)+1;
+               if (s->s_name != NULL)
+                       size += strlen(s->s_name)+1;
+               if (s->s_proto != NULL)
+                       size += strlen(s->s_proto)+1;
 
                if (s->s_aliases != NULL)
-                       while (s->s_aliases[numaliases]) size += strlen(s->s_aliases[numaliases++])+5;
+                       while (s->s_aliases[numaliases])
+                               size += strlen(s->s_aliases[numaliases++])+5;
 
-               if (sb->servent)
-               {
-           uae_FreeMem( sb->servent, sb->serventsize );
+               if (sb->servent) {
+                       uae_FreeMem(context, sb->servent, sb->serventsize);
                }
 
-       sb->servent = uae_AllocMem( size, 0 );
+               sb->servent = uae_AllocMem(context, size, 0);
 
-               if (!sb->servent)
-               {
+               if (!sb->servent) {
                        write_log("BSDSOCK: WARNING - getservby%s() ran out of Amiga memory (couldn't allocate %ld bytes)\n",type ? "port" : "name",size);
-                       seterrno(sb,12); // ENOMEM
+                       bsdsocklib_seterrno(sb,12); // ENOMEM
                        return;
                }
 
@@ -2636,10 +2384,9 @@ void host_getservbynameport(SB, uae_u32 nameport, uae_u32 proto, uae_u32 type)
                addstr(&aptr,s->s_proto);
 
                TRACE(("OK (%s, %d)\n",s->s_name,(unsigned short)htons(s->s_port)));
-               seterrno(sb,0);
-       }
-       else
-       {
+               bsdsocklib_seterrno(sb,0);
+
+       } else {
                TRACE(("failed (%d)\n",sb->sb_errno));
        }
 
diff --git a/od-win32/config.h b/od-win32/config.h
deleted file mode 100755 (executable)
index 24aab3e..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
- /* 
-  * UAE - The Un*x Amiga Emulator
-  * 
-  * User configuration options
-  *
-  * Copyright 1995 - 1998 Bernd Schmidt
-  */
-
-/*
- * Please note: Many things are configurable with command line parameters,
- * and you can put anything you can pass on the command line into a 
- * configuration file ~/.uaerc. Please read the documentation for more
- * information.
- * 
- * NOTE NOTE NOTE
- * Whenever you change something in this file, you have to "make clean"
- * afterwards.
- * Don't remove the '#' signs. If you want to enable something, move it out
- * of the C comment block, if you want to disable something, move it inside
- * the block.
- */
-
-/*
- * When USE_COMPILER is defined, a m68k->i386 instruction compiler will be
- * used. This is experimental. It has only been tested on a Linux/i386 ELF
- * machine, although it might work on other i386 Unices.
- * This is supposed to speed up application programs. It will not work very
- * well for hardware bangers like games and demos, in fact it will be much
- * slower. It can also be slower for some applications and/or benchmarks.
- * It needs a lot of tuning. Please let me know your results with this.
- * The second define, RELY_ON_LOADSEG_DETECTION, decides how the compiler 
- * tries to detect self-modifying code. If it is not set, the first bytes
- * of every compiled routine are used as checksum before executing the
- * routine. If it is set, the UAE filesystem will perform some checks to 
- * detect whether an executable is being loaded. This is less reliable
- * (it won't work if you don't use the harddisk emulation, so don't try to
- * use floppies or even the RAM disk), but much faster.
- *
- * @@@ NOTE: This option is unfortunately broken in this version. Don't
- * try to use it. @@@
- *
-#define USE_COMPILER
-#define RELY_ON_LOADSEG_DETECTION
- */
-
-/*
- * Set USER_PROGRAMS_BEHAVE to 1 or 2 to indicate that you are only running
- * non-hardware banging programs which leave all the dirty work to the
- * Kickstart. This affects the compiler. Any program that is _not_ in the ROM
- * (i.e. everything but the Kickstart) will use faster memory access 
- * functions.
- * There is of course the problem that the Amiga doesn't really distinguish
- * between user programs and the kernel. Not all of the OS is in the ROM,
- * e.g. the parallel.device is on the disk and gets loaded into RAM at least
- * with Kickstart 1.3 (don't know about newer Kickstarts). So you probably
- * can't print, and some other stuff may also fail to work.
- * A useless option, really, given the way lots of Amiga software is written.
-#define USER_PROGRAMS_BEHAVE 0
- */
-
-/***************************************************************************
- * Operating system/machine specific options
- * Configure these for your CPU. The default settings should work on any
- * machine, but may not give optimal performance everywhere.
- * (These don't do very much yet, except HAVE_RDTSC
- */
-
-/*
- * Define this where unaligned-accesses don't break things, and are "fast enough"
- */
-#define UNALIGNED_PROFITABLE
-
-/*
- * PPros don't like branches. With this option, UAE tries to avoid them in some
- * places.
- */
-#define BRANCHES_ARE_EXPENSIVE
\ No newline at end of file
index 46eaf9a1ba1a77b708e1f5de6d269b97e5bfac44..86422c6e9d67a0e65ac9695f49dcc8044ea9176c 100755 (executable)
@@ -11,7 +11,6 @@
 #define DI_DEBUG
 //#define DI_DEBUG2
 
-#include "config.h"
 #include "sysconfig.h"
 
 #include <stdlib.h>
index 88987f3dcfd2a696e69050d9e1a69d9bbe82f613..a85af1138163109fb4429d59f66baa6178a12e88 100755 (executable)
@@ -5,7 +5,6 @@
 
 #if defined (OPENGL) && defined (GFXFILTER)
 
-#include "config.h"
 #include "options.h"
 #include "xwin.h"
 #include "custom.h"
index a9b8f36ee8d0ff5f1492058f70f087ccced191eb..05130e044bf257167ea11902907c7dfceedfeb3c 100755 (executable)
@@ -12,7 +12,6 @@
 #ifdef DRIVESOUND
 
 #include "uae.h"
-#include "config.h"
 #include "options.h"
 #include "driveclick.h"
 #include "threaddep/thread.h"
index eef19134f3a4fa1e159d8b6d8d66685281d22c95..01f6cb4160a8cc1c158b120d227b5b7c76ef9f4b 100755 (executable)
@@ -6,11 +6,6 @@
  * Copyright 1999 Brian King, under GNU Public License
  *
  */
-#ifndef _MSC_VER
-#define INITGUID
-#endif
-
-#include "config.h"
 #include "sysconfig.h"
 
 #include <stdlib.h>
 #include <windows.h>
 #include <sys/timeb.h>
 
-#ifdef _MSC_VER
 #include <mmsystem.h>
 #include <ddraw.h>
 #include <dsound.h>
 #include <dxerr8.h>
-#else
-#include "winstuff.h"
-#endif
 
 #include "sysdeps.h"
 #include "options.h"
index 7d58f1ed132bb85a66a2972ea8935eeced35c4e8..6314537bb73ff5bc4980b68b035e5f67862c8cb8 100755 (executable)
@@ -11,7 +11,6 @@
 
 #include "sysconfig.h"
 #include "sysdeps.h"
-#include "config.h"
 #include "options.h"
 #include "memory.h"
 
diff --git a/od-win32/genlinetoscr_msvc/genlinetoscr_msvc.vcproj b/od-win32/genlinetoscr_msvc/genlinetoscr_msvc.vcproj
new file mode 100755 (executable)
index 0000000..8c461f1
--- /dev/null
@@ -0,0 +1,192 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+       ProjectType="Visual C++"
+       Version="8,00"
+       Name="genlinetoscr"
+       ProjectGUID="{E9F73E11-A463-45C6-A733-2BED75852BA1}"
+       RootNamespace="genlinetoscr_msvc"
+       Keyword="Win32Proj"
+       >
+       <Platforms>
+               <Platform
+                       Name="Win32"
+               />
+       </Platforms>
+       <ToolFiles>
+       </ToolFiles>
+       <Configurations>
+               <Configuration
+                       Name="Debug|Win32"
+                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+                       IntermediateDirectory="$(ConfigurationName)"
+                       ConfigurationType="1"
+                       CharacterSet="1"
+                       >
+                       <Tool
+                               Name="VCPreBuildEventTool"
+                       />
+                       <Tool
+                               Name="VCCustomBuildTool"
+                       />
+                       <Tool
+                               Name="VCXMLDataGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCWebServiceProxyGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCMIDLTool"
+                       />
+                       <Tool
+                               Name="VCCLCompilerTool"
+                               Optimization="0"
+                               PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+                               MinimalRebuild="true"
+                               BasicRuntimeChecks="3"
+                               RuntimeLibrary="3"
+                               UsePrecompiledHeader="0"
+                               WarningLevel="3"
+                               Detect64BitPortabilityProblems="true"
+                               DebugInformationFormat="4"
+                       />
+                       <Tool
+                               Name="VCManagedResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCPreLinkEventTool"
+                       />
+                       <Tool
+                               Name="VCLinkerTool"
+                               LinkIncremental="2"
+                               GenerateDebugInformation="true"
+                               SubSystem="1"
+                               TargetMachine="1"
+                       />
+                       <Tool
+                               Name="VCALinkTool"
+                       />
+                       <Tool
+                               Name="VCManifestTool"
+                       />
+                       <Tool
+                               Name="VCXDCMakeTool"
+                       />
+                       <Tool
+                               Name="VCBscMakeTool"
+                       />
+                       <Tool
+                               Name="VCFxCopTool"
+                       />
+                       <Tool
+                               Name="VCAppVerifierTool"
+                       />
+                       <Tool
+                               Name="VCWebDeploymentTool"
+                       />
+                       <Tool
+                               Name="VCPostBuildEventTool"
+                       />
+               </Configuration>
+               <Configuration
+                       Name="Release|Win32"
+                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+                       IntermediateDirectory="$(ConfigurationName)"
+                       ConfigurationType="1"
+                       CharacterSet="1"
+                       WholeProgramOptimization="1"
+                       >
+                       <Tool
+                               Name="VCPreBuildEventTool"
+                               Description=""
+                               CommandLine=""
+                       />
+                       <Tool
+                               Name="VCCustomBuildTool"
+                       />
+                       <Tool
+                               Name="VCXMLDataGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCWebServiceProxyGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCMIDLTool"
+                       />
+                       <Tool
+                               Name="VCCLCompilerTool"
+                               PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+                               RuntimeLibrary="2"
+                               UsePrecompiledHeader="0"
+                               WarningLevel="3"
+                               Detect64BitPortabilityProblems="true"
+                               DebugInformationFormat="3"
+                       />
+                       <Tool
+                               Name="VCManagedResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCPreLinkEventTool"
+                               Description="deleteing linetoscr.c"
+                               CommandLine="del ..\..\linetoscr.c"
+                       />
+                       <Tool
+                               Name="VCLinkerTool"
+                               OutputFile="genlinetoscr.exe"
+                               LinkIncremental="1"
+                               GenerateDebugInformation="true"
+                               SubSystem="1"
+                               OptimizeReferences="2"
+                               EnableCOMDATFolding="2"
+                               TargetMachine="1"
+                       />
+                       <Tool
+                               Name="VCALinkTool"
+                       />
+                       <Tool
+                               Name="VCManifestTool"
+                       />
+                       <Tool
+                               Name="VCXDCMakeTool"
+                       />
+                       <Tool
+                               Name="VCBscMakeTool"
+                       />
+                       <Tool
+                               Name="VCFxCopTool"
+                       />
+                       <Tool
+                               Name="VCAppVerifierTool"
+                       />
+                       <Tool
+                               Name="VCWebDeploymentTool"
+                       />
+                       <Tool
+                               Name="VCPostBuildEventTool"
+                               Description="generating linetoscr.c"
+                               CommandLine="genlinetoscr.exe &gt;..\..\linetoscr.c"
+                       />
+               </Configuration>
+       </Configurations>
+       <References>
+       </References>
+       <Files>
+               <Filter
+                       Name="Source Files"
+                       Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+                       UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+                       >
+                       <File
+                               RelativePath="..\..\genlinetoscr.c"
+                               >
+                       </File>
+               </Filter>
+       </Files>
+       <Globals>
+       </Globals>
+</VisualStudioProject>
index 2ca1132d8a828f1b8e946b03e2295d51ad01768e..ba4b79b0c8836117169313f9eb333f52877baa14 100755 (executable)
@@ -7,7 +7,6 @@
 #include <shellapi.h>
 #include "resource.h"
 
-#include "config.h"
 #include "threaddep/thread.h"
 #include "filesys.h"
 #include "blkdev.h"
@@ -398,7 +397,7 @@ void hfd_flush_cache (struct hardfiledata *hfd, int now)
 }
 #endif
 
-#if 0 // not yet production ready
+#if 0
 
 static int hdf_rw (struct hardfiledata *hfd, void *bufferp, uae_u64 offset, int len, int dowrite)
 {
@@ -488,7 +487,7 @@ int hdf_write (struct hardfiledata *hfd, void *buffer, uae_u64 offset, int len)
 
 #else
 
-int hdf_read (struct hardfiledata *hfd, void *buffer, uae_u64 offset, int len)
+static int hdf_read_2 (struct hardfiledata *hfd, void *buffer, uae_u64 offset, int len)
 {
     DWORD outlen = 0;
     int coffset;
@@ -523,7 +522,24 @@ int hdf_read (struct hardfiledata *hfd, void *buffer, uae_u64 offset, int len)
     return 0;
 }
 
-int hdf_write (struct hardfiledata *hfd, void *buffer, uae_u64 offset, int len)
+int hdf_read (struct hardfiledata *hfd, void *buffer, uae_u64 offset, int len)
+{
+    int got = 0;
+    uae_u8 *p = buffer;
+    while (len > 0) {
+       int maxlen = len > CACHE_SIZE ? CACHE_SIZE : len;
+       int ret = hdf_read_2(hfd, p, offset, maxlen);
+       got += ret;
+       if (ret != maxlen)
+           return got;
+       offset += maxlen;
+       p += maxlen;
+       len -= maxlen;
+    }
+    return got;
+}
+
+static int hdf_write_2 (struct hardfiledata *hfd, void *buffer, uae_u64 offset, int len)
 {
     DWORD outlen = 0;
     if (hfd->readonly)
@@ -538,6 +554,24 @@ int hdf_write (struct hardfiledata *hfd, void *buffer, uae_u64 offset, int len)
        outlen = zfile_fwrite (hfd->cache, 1, len, hfd->handle);
     return outlen;
 }
+
+int hdf_write (struct hardfiledata *hfd, void *buffer, uae_u64 offset, int len)
+{
+    int got = 0;
+    uae_u8 *p = buffer;
+    while (len > 0) {
+       int maxlen = len > CACHE_SIZE ? CACHE_SIZE : len;
+       int ret = hdf_write_2(hfd, p, offset, maxlen);
+       got += ret;
+       if (ret != maxlen)
+           return got;
+       offset += maxlen;
+       p += maxlen;
+       len -= maxlen;
+    }
+    return got;
+}
+
 #endif
 
 #ifdef WINDDK
@@ -599,9 +633,9 @@ Return Value:
                 &interfaceData          // Device Interface Data
                 );
 
-    if ( status == FALSE ) {
+    if (status == FALSE) {
         errorCode = GetLastError();
-        if ( errorCode != ERROR_NO_MORE_ITEMS ) {
+        if (errorCode != ERROR_NO_MORE_ITEMS) {
             write_log ("SetupDiEnumDeviceInterfaces failed with error: %d\n", errorCode);
         }
        ret = 0;
@@ -627,9 +661,9 @@ Return Value:
     // pass a bigger buffer to get the detail data
     //
 
-    if ( status == FALSE ) {
+    if (status == FALSE) {
         errorCode = GetLastError();
-        if ( errorCode != ERROR_INSUFFICIENT_BUFFER ) {
+        if (errorCode != ERROR_INSUFFICIENT_BUFFER) {
             write_log("SetupDiGetDeviceInterfaceDetail failed with error: %d\n", errorCode);
            ret = 0;
            goto end;
@@ -726,7 +760,7 @@ Return Value:
                         sizeof (outBuf),                      
                         &returnedLength,
                         NULL);
-        if ( !status ) {
+        if (!status) {
             write_log ("IOCTL_STORAGE_QUERY_PROPERTY failed with error code %d.\n", GetLastError());
            ret = 1;
            goto end;
@@ -738,24 +772,24 @@ Return Value:
            write_log ("not a direct access device, ignored (type=%d)\n", devDesc->DeviceType);
            goto end;
        }
-        if ( devDesc->VendorIdOffset && p[devDesc->VendorIdOffset] ) {
+        if (devDesc->VendorIdOffset && p[devDesc->VendorIdOffset]) {
             j = 0;
-            for ( i = devDesc->VendorIdOffset; p[i] != (UCHAR) NULL && i < returnedLength; i++ )
+            for (i = devDesc->VendorIdOffset; p[i] != (UCHAR) NULL && i < returnedLength; i++)
                udi->vendor_id[j++] = p[i];
         }
-        if ( devDesc->ProductIdOffset && p[devDesc->ProductIdOffset] ) {
+        if (devDesc->ProductIdOffset && p[devDesc->ProductIdOffset]) {
             j = 0;
-            for ( i = devDesc->ProductIdOffset; p[i] != (UCHAR) NULL && i < returnedLength; i++ )
+            for (i = devDesc->ProductIdOffset; p[i] != (UCHAR) NULL && i < returnedLength; i++)
                udi->product_id[j++] = p[i];
         }
-        if ( devDesc->ProductRevisionOffset && p[devDesc->ProductRevisionOffset] ) {
+        if (devDesc->ProductRevisionOffset && p[devDesc->ProductRevisionOffset]) {
            j = 0;
-           for ( i = devDesc->ProductRevisionOffset; p[i] != (UCHAR) NULL && i < returnedLength; i++ )
+           for (i = devDesc->ProductRevisionOffset; p[i] != (UCHAR) NULL && i < returnedLength; i++)
                udi->product_rev[j++] = p[i];
         }
-        if ( devDesc->SerialNumberOffset && p[devDesc->SerialNumberOffset] ) {
+        if (devDesc->SerialNumberOffset && p[devDesc->SerialNumberOffset]) {
            j = 0;
-           for ( i = devDesc->SerialNumberOffset; p[i] != (UCHAR) NULL && i < returnedLength; i++ )
+           for (i = devDesc->SerialNumberOffset; p[i] != (UCHAR) NULL && i < returnedLength; i++)
                udi->product_serial[j++] = p[i];
         }
        if (udi->vendor_id[0])
index f0a60b03b863340612222d2f2a85104799d72270..4d747775e80d5966052e123cc5f08fcf9df5e57d 100755 (executable)
@@ -9,7 +9,6 @@
  * (c) 2002 Toni Wilen
  */
 
-#include "config.h"
 #include "sysconfig.h"
 
 #include <assert.h>
@@ -35,7 +34,6 @@
 #include "win32.h"
 #include "debug.h"
 #include "ar.h"
-#include "ahidsound.h"
 #include "savestate.h"
 #include "sound.h"
 #include "akiko.h"
index 54cfbf55bc58a7c1cfae0b991e07498ce795cab7..a7e52bd31d1e65b1f177c9f1fe431e31a49f5c63 100755 (executable)
-#ifndef M68K_H
-#define M68K_H
-
- /* 
+/*
   * UAE - The Un*x Amiga Emulator
-  * 
+  *
   * MC68000 emulation - machine dependent bits
   *
   * Copyright 1996 Bernd Schmidt
+  * Copyright 2004-2005 Richard Drummond
   */
 
+ /*
+  * Machine dependent structure for holding the 68k CCR flags
+  */
 struct flag_struct {
     unsigned int cznv;
     unsigned int x;
 };
 
-#define FLAGVAL_Z 0x4000
-#define FLAGVAL_N 0x8000
-
-#define SET_ZFLG(y) (regflags.cznv = (regflags.cznv & ~0x4000) | (((y) ? 0x4000 : 0)))
-#define SET_CFLG(y) (regflags.cznv = (regflags.cznv & ~0x100) | (((y) ? 0x100 : 0)))
-#define SET_VFLG(y) (regflags.cznv = (regflags.cznv & ~0x1) | (((y) ? 1 : 0)))
-#define SET_NFLG(y) (regflags.cznv = (regflags.cznv & ~0x8000) | (((y) ? 0x8000 : 0)))
-#define SET_XFLG(y) (regflags.x = ((y) ? 1 : 0))
-
-#define GET_ZFLG ((regflags.cznv >> 14) & 1)
-#define GET_CFLG ((regflags.cznv >> 8) & 1)
-#define GET_VFLG ((regflags.cznv >> 0) & 1)
-#define GET_NFLG ((regflags.cznv >> 15) & 1)
-#define GET_XFLG (regflags.x & 1)
-
-#define CLEAR_CZNV (regflags.cznv = 0)
-#define GET_CZNV (regflags.cznv)
-#define IOR_CZNV(X) (regflags.cznv |= (X))
-#define SET_CZNV(X) (regflags.cznv = (X))
 
-#define COPY_CARRY (regflags.x = (regflags.cznv) >> 8)
-
-#ifdef X86_ASSEMBLY
-extern struct flag_struct regflags __asm__ ("regflags");
-#else
-extern struct flag_struct regflags;
-#endif
-
-static __inline__ int cctrue(int cc)
+/*
+ * The bits in the cznv field in the above structure are assigned to
+ * allow the easy mirroring of the x86 condition flags. (For example,
+ * from the AX register - the x86 overflow flag can be copied to AL
+ * with a setto %AL instr and the other flags copied to AH with an
+ * lahf instr).
+ *
+ * The 68k CZNV flags are thus assinged in cznv as:
+ *
+ * <--AL-->  <--AH-->
+ * 76543210  FEDCBA98 --------- ---------
+ * xxxxxxxV  NZxxxxxC xxxxxxxxx xxxxxxxxx
+ */
+
+#define FLAGBIT_N      15
+#define FLAGBIT_Z      14
+#define FLAGBIT_C      8
+#define FLAGBIT_V      0
+#define FLAGBIT_X      8
+
+#define FLAGVAL_N      (1 << FLAGBIT_N)
+#define FLAGVAL_Z      (1 << FLAGBIT_Z)
+#define FLAGVAL_C      (1 << FLAGBIT_C)
+#define FLAGVAL_V      (1 << FLAGBIT_V)
+#define FLAGVAL_X      (1 << FLAGBIT_X)
+
+#define SET_ZFLG(flags, y)     ((flags)->cznv = ((flags)->cznv & ~FLAGVAL_Z) | (((y) & 1) << FLAGBIT_Z))
+#define SET_CFLG(flags, y)     ((flags)->cznv = ((flags)->cznv & ~FLAGVAL_C) | (((y) & 1) << FLAGBIT_C))
+#define SET_VFLG(flags, y)     ((flags)->cznv = ((flags)->cznv & ~FLAGVAL_V) | (((y) & 1) << FLAGBIT_V))
+#define SET_NFLG(flags, y)     ((flags)->cznv = ((flags)->cznv & ~FLAGVAL_N) | (((y) & 1) << FLAGBIT_N))
+#define SET_XFLG(flags, y)     ((flags)->x    = (y) << FLAGBIT_X)
+
+#define GET_ZFLG(flags)                (((flags)->cznv >> FLAGBIT_Z) & 1)
+#define GET_CFLG(flags)                (((flags)->cznv >> FLAGBIT_C) & 1)
+#define GET_VFLG(flags)                (((flags)->cznv >> FLAGBIT_V) & 1)
+#define GET_NFLG(flags)                (((flags)->cznv >> FLAGBIT_N) & 1)
+#define GET_XFLG(flags)                (((flags)->x    >> FLAGBIT_X) & 1)
+
+#define CLEAR_CZNV(flags)      ((flags)->cznv  = 0)
+#define GET_CZNV(flags)                ((flags)->cznv)
+#define IOR_CZNV(flags, X)     ((flags)->cznv |= (X))
+#define SET_CZNV(flags, X)     ((flags)->cznv  = (X))
+
+#define COPY_CARRY(flags)      ((flags)->x = (flags)->cznv)
+
+
+/*
+ * Test CCR condition
+ */
+STATIC_INLINE int cctrue (struct flag_struct *flags, int cc)
 {
-    uae_u32 cznv = regflags.cznv;
-    switch(cc){
-     case 0: return 1;                       /* T */
-     case 1: return 0;                       /* F */
-     case 2: return (cznv & 0x4100) == 0; /* !GET_CFLG && !GET_ZFLG;  HI */
-     case 3: return (cznv & 0x4100) != 0; /* GET_CFLG || GET_ZFLG;    LS */
-     case 4: return (cznv & 0x100) == 0;  /* !GET_CFLG;               CC */
-     case 5: return (cznv & 0x100) != 0;  /* GET_CFLG;                CS */
-     case 6: return (cznv & 0x4000) == 0; /* !GET_ZFLG;               NE */
-     case 7: return (cznv & 0x4000) != 0; /* GET_ZFLG;                EQ */
-     case 8: return (cznv & 0x01) == 0;   /* !GET_VFLG;               VC */
-     case 9: return (cznv & 0x01) != 0;   /* GET_VFLG;                VS */
-     case 10:return (cznv & 0x8000) == 0; /* !GET_NFLG;               PL */
-     case 11:return (cznv & 0x8000) != 0; /* GET_NFLG;                MI */
-     case 12:return (((cznv << 15) ^ cznv) & 0x8000) == 0; /* GET_NFLG == GET_VFLG;             GE */
-     case 13:return (((cznv << 15) ^ cznv) & 0x8000) != 0;/* GET_NFLG != GET_VFLG;             LT */
-     case 14:
-       cznv &= 0xc001;
-       return (((cznv << 15) ^ cznv) & 0xc000) == 0; /* !GET_ZFLG && (GET_NFLG == GET_VFLG);  GT */
-     case 15:
-       cznv &= 0xc001;
-       return (((cznv << 15) ^ cznv) & 0xc000) != 0; /* GET_ZFLG || (GET_NFLG != GET_VFLG);   LE */
+    uae_u32 cznv = flags->cznv;
+
+    switch (cc) {
+       case 0:  return 1;                                                              /*                              T  */
+       case 1:  return 0;                                                              /*                              F  */
+       case 2:  return (cznv & (FLAGVAL_C | FLAGVAL_Z)) == 0;                          /* !CFLG && !ZFLG               HI */
+       case 3:  return (cznv & (FLAGVAL_C | FLAGVAL_Z)) != 0;                          /*  CFLG || ZFLG                LS */
+       case 4:  return (cznv & FLAGVAL_C) == 0;                                        /* !CFLG                        CC */
+       case 5:  return (cznv & FLAGVAL_C) != 0;                                        /*  CFLG                        CS */
+       case 6:  return (cznv & FLAGVAL_Z) == 0;                                        /* !ZFLG                        NE */
+       case 7:  return (cznv & FLAGVAL_Z) != 0;                                        /*  ZFLG                        EQ */
+       case 8:  return (cznv & FLAGVAL_V) == 0;                                        /* !VFLG                        VC */
+       case 9:  return (cznv & FLAGVAL_V) != 0;                                        /*  VFLG                        VS */
+       case 10: return (cznv & FLAGVAL_N) == 0;                                        /* !NFLG                        PL */
+       case 11: return (cznv & FLAGVAL_N) != 0;                                        /*  NFLG                        MI */
+       case 12: return (((cznv << (FLAGBIT_N - FLAGBIT_V)) ^ cznv) & FLAGVAL_N) == 0;  /*  NFLG == VFLG                GE */
+       case 13: return (((cznv << (FLAGBIT_N - FLAGBIT_V)) ^ cznv) & FLAGVAL_N) != 0;  /*  NFLG != VFLG                LT */
+       case 14: cznv &= (FLAGVAL_N | FLAGVAL_Z | FLAGVAL_V);                           /* ZFLG && (NFLG == VFLG)       GT */
+                return (((cznv << (FLAGBIT_N - FLAGBIT_V)) ^ cznv) & (FLAGVAL_N | FLAGVAL_Z)) == 0;
+       case 15: cznv &= (FLAGVAL_N | FLAGVAL_Z | FLAGVAL_V);                           /* ZFLG && (NFLG != VFLG)       LE */
+                return (((cznv << (FLAGBIT_N - FLAGBIT_V)) ^ cznv) & (FLAGVAL_N | FLAGVAL_Z)) != 0;
     }
-    abort();
+    abort ();
     return 0;
 }
-
-#ifdef X86_ASSEMBLY
-
-#define optflag_testl(v) \
-  __asm__ __volatile__ ("andl %0,%0\n\t" \
-                       "lahf\n\t" \
-                       "seto %%al\n\t" \
-                        "movb %%al,regflags\n\t" \
-                       "movb %%ah,regflags+1\n\t" \
-                       :: "r" (v) : "%eax","cc","memory")
-#define optflag_testw(v) \
-  __asm__ __volatile__ ("andw %w0,%w0\n\t" \
-                       "lahf\n\t" \
-                       "seto %%al\n\t" \
-                        "movb %%al,regflags\n\t" \
-                       "movb %%ah,regflags+1\n\t" \
-                       :: "r" (v) : "%eax","cc","memory")
-
-#define optflag_testb(v) \
-  __asm__ __volatile__ ("andb %b0,%b0\n\t" \
-                       "lahf\n\t" \
-                       "seto %%al\n\t" \
-                        "movb %%al,regflags\n\t" \
-                       "movb %%ah,regflags+1\n\t" \
-                       :: "q" (v) : "%eax","cc","memory")
-
-#define optflag_addl(v, s, d) do { \
-  __asm__ __volatile__ ("addl %k1,%k0\n\t" \
-                       "lahf\n\t" \
-                       "seto %%al\n\t" \
-                        "movb %%al,regflags\n\t" \
-                       "movb %%ah,regflags+1\n\t" \
-                       :"=r" (v) : "rmi" (s), "0" (d) : "%eax","cc","memory"); \
-    COPY_CARRY; \
-    } while (0)
-#define optflag_addw(v, s, d) do { \
-  __asm__ __volatile__ ("addw %w1,%w0\n\t" \
-                       "lahf\n\t" \
-                       "seto %%al\n\t" \
-                        "movb %%al,regflags\n\t" \
-                       "movb %%ah,regflags+1\n\t" \
-                       : "=r" (v) : "rmi" (s), "0" (d) : "%eax","cc","memory"); \
-    COPY_CARRY; \
-    } while (0)
-
-#define optflag_addb(v, s, d) do { \
-  __asm__ __volatile__ ("addb %b1,%b0\n\t" \
-                       "lahf\n\t" \
-                       "seto %%al\n\t" \
-                        "movb %%al,regflags\n\t" \
-                       "movb %%ah,regflags+1\n\t" \
-                       :"=q" (v) : "qmi" (s), "0" (d) : "%eax","cc","memory"); \
-    COPY_CARRY; \
-    } while (0)
-
-#define optflag_subl(v, s, d) do { \
-  __asm__ __volatile__ ("subl %k1,%k0\n\t" \
-                       "lahf\n\t" \
-                       "seto %%al\n\t" \
-                        "movb %%al,regflags\n\t" \
-                       "movb %%ah,regflags+1\n\t" \
-                       : "=r" (v) : "rmi" (s), "0" (d) : "%eax","cc","memory"); \
-    COPY_CARRY; \
-    } while (0)
-
-#define optflag_subw(v, s, d) do { \
-  __asm__ __volatile__ ("subw %w1,%w0\n\t" \
-                       "lahf\n\t" \
-                       "seto %%al\n\t" \
-                        "movb %%al,regflags\n\t" \
-                       "movb %%ah,regflags+1\n\t" \
-                       : "=r" (v) : "rmi" (s), "0" (d) : "%eax","cc","memory"); \
-    COPY_CARRY; \
-    } while (0)
-
-#define optflag_subb(v, s, d) do { \
-   __asm__ __volatile__ ("subb %b1,%b0\n\t" \
-                       "lahf\n\t" \
-                       "seto %%al\n\t" \
-                        "movb %%al,regflags\n\t" \
-                       "movb %%ah,regflags+1\n\t" \
-                       : "=q" (v) : "qmi" (s), "0" (d) : "%eax","cc","memory"); \
-    COPY_CARRY; \
-    } while (0)
-
-#define optflag_cmpl(s, d) \
-  __asm__ __volatile__ ("cmpl %k0,%k1\n\t" \
-                       "lahf\n\t" \
-                       "seto %%al\n\t" \
-                        "movb %%al,regflags\n\t" \
-                       "movb %%ah,regflags+1\n\t" \
-                       :: "rmi" (s), "r" (d) : "%eax","cc","memory")
-
-#define optflag_cmpw(s, d) \
-  __asm__ __volatile__ ("cmpw %w0,%w1\n\t" \
-                       "lahf\n\t" \
-                       "seto %%al\n\t" \
-                        "movb %%al,regflags\n\t" \
-                       "movb %%ah,regflags+1\n\t" \
-                       :: "rmi" (s), "r" (d) : "%eax","cc","memory");
-
-#define optflag_cmpb(s, d) \
-  __asm__ __volatile__ ("cmpb %b0,%b1\n\t" \
-                       "lahf\n\t" \
-                       "seto %%al\n\t" \
-                        "movb %%al,regflags\n\t" \
-                       "movb %%ah,regflags+1\n\t" \
-                       :: "qmi" (s), "q" (d) : "%eax","cc","memory")
-
-#endif
-
-#endif
\ No newline at end of file
index c0e573110bcbf46fbb524d6ae6c91a186c54242a..d293af04c3c2322c85bc648b72a1b724ca0d032b 100755 (executable)
  *   2002.05.xx  1.2    Bernd Roesch    - sysex in/MTC/Song Position pointer add
  */ 
 
-#include "config.h"
 #include "sysconfig.h"
 #include <windows.h>
 #include <stdlib.h>
 #include <stdarg.h>
-#ifdef _MSC_VER
 #include <mmsystem.h>
 #include <ddraw.h>
-#else
-#include "winstuff.h"
-#endif
 #include <stdio.h>
 #include <fcntl.h>
 #include <sys/stat.h>
index f236f43ded458cc2e3f7c414212210f155d5c057..7028d89c2c99ba25e43670eb8013fdb56423c229 100755 (executable)
@@ -7,7 +7,7 @@
 #include "sysconfig.h" 
 #include "sysdeps.h"
 #include "sys/mman.h"
-#include "include/memory.h"
+#include "memory.h"
 #include "options.h"
 #include "autoconf.h"
 #include "win32.h"
@@ -24,13 +24,6 @@ uae_u32 max_allowed_mman = 2048;
 uae_u32 max_allowed_mman = 512;
 #endif
 
-static uae_u8 stackmagic64asm[] = {
-    0x48,0x8b,0x44,0x24,0x28,  // mov rax,qword ptr [rsp+28h] 
-    0x49,0x8b,0xe1,            // mov rsp,r9 
-    0xff,0xd0                  // call rax
-};
-uae_u8 *stack_magic_amd64_asm_executable;
-
 void cache_free(void *cache)
 {
     VirtualFree (cache, 0, MEM_RELEASE);
@@ -57,13 +50,6 @@ void init_shm(void)
     uae_u64 totalphys64;
     MEMORYSTATUS memstats;
 
-#ifdef CPU_64_BIT
-    if (!stack_magic_amd64_asm_executable) {
-       stack_magic_amd64_asm_executable = cache_alloc(sizeof stackmagic64asm);
-       memcpy(stack_magic_amd64_asm_executable, stackmagic64asm, sizeof stackmagic64asm);
-    }
-#endif
-
     if (natmem_offset && os_winnt)
        VirtualFree(natmem_offset, 0, MEM_RELEASE);
     natmem_offset = NULL;
@@ -139,25 +125,18 @@ void init_shm(void)
 void mapped_free(uae_u8 *mem)
 {
     shmpiece *x = shm_start;
-    while( x )
-    {
+    while(x) {
        if( mem == x->native_address )
            shmdt( x->native_address);
        x = x->next;
     }
     x = shm_start;
-    while( x )
-    {
+    while(x) {
        struct shmid_ds blah;
-       if( mem == x->native_address )
-       {
-           if( shmctl( x->id, IPC_STAT, &blah ) == 0 )
-           {
-               shmctl( x->id, IPC_RMID, &blah );
-           }
-           else
-           {
-               //free( x->native_address );
+       if (mem == x->native_address) {
+           if (shmctl(x->id, IPC_STAT, &blah) == 0) {
+               shmctl(x->id, IPC_RMID, &blah);
+           } else {
                VirtualFree((LPVOID)mem, 0, os_winnt ? MEM_RESET : (MEM_DECOMMIT | MEM_RELEASE));
            }
        }
@@ -169,10 +148,8 @@ static key_t get_next_shmkey( void )
 {
     key_t result = -1;
     int i;
-    for( i = 0; i < MAX_SHMID; i++ )
-    {
-       if( shmids[i].key == -1 )
-       {
+    for (i = 0; i < MAX_SHMID; i++) {
+       if( shmids[i].key == -1) {
            shmids[i].key = i;
            result = i;
            break;
@@ -184,8 +161,7 @@ static key_t get_next_shmkey( void )
 STATIC_INLINE key_t find_shmkey( key_t key )
 {
     int result = -1;
-    if( shmids[key].key == key )
-    {
+    if(shmids[key].key == key) {
        result = key;
     }
     return result;
@@ -194,7 +170,6 @@ STATIC_INLINE key_t find_shmkey( key_t key )
 int mprotect(void *addr, size_t len, int prot)
 {
     int result = 0;
-  
     return result;
 }
 
@@ -207,38 +182,32 @@ void *shmat(int shmid, void *shmaddr, int shmflg)
     unsigned int size=shmids[shmid].size;
     if(shmids[shmid].attached )
        return shmids[shmid].attached;
-    if ((uae_u8*)shmaddr<natmem_offset){
-       if(!strcmp(shmids[shmid].name,"chip"))
-       {
+    if ((uae_u8*)shmaddr<natmem_offset) {
+       if(!strcmp(shmids[shmid].name,"chip")) {
            shmaddr=natmem_offset;
            got = TRUE;
 //         if(!currprefs.fastmem_size)
 //             size+=32;
        }
-       if(!strcmp(shmids[shmid].name,"kick"))
-       {
+       if(!strcmp(shmids[shmid].name,"kick")) {
            shmaddr=natmem_offset+0xf80000;
            got = TRUE;
            size+=32;
        }
-       if(!strcmp(shmids[shmid].name,"rom_e0"))
-       {
+       if(!strcmp(shmids[shmid].name,"rom_e0")) {
            shmaddr=natmem_offset+0xe00000;
            got = TRUE;
        }
-       if(!strcmp(shmids[shmid].name,"rom_f0"))
-       {
+       if(!strcmp(shmids[shmid].name,"rom_f0")) {
            shmaddr=natmem_offset+0xf00000;
            got = TRUE;
        }
-       if(!strcmp(shmids[shmid].name,"rtarea"))
-       {
+       if(!strcmp(shmids[shmid].name,"rtarea")) {
            shmaddr=natmem_offset+RTAREA_BASE;
            got = TRUE;
            size+=32;
        }
-       if(!strcmp(shmids[shmid].name,"fast"))
-       {
+       if(!strcmp(shmids[shmid].name,"fast")) {
            shmaddr=natmem_offset+0x200000;
            got = TRUE;
            size+=32;
@@ -251,8 +220,7 @@ void *shmat(int shmid, void *shmaddr, int shmflg)
                gfxoffs=allocated_z3fastmem;
            got = TRUE;
        }
-       if(!strcmp(shmids[shmid].name,"gfx"))
-       {
+       if(!strcmp(shmids[shmid].name,"gfx")) {
            shmaddr=natmem_offset+currprefs.z3fastmem_start+gfxoffs;
            got = TRUE;
            size+=32;
@@ -260,32 +228,27 @@ void *shmat(int shmid, void *shmaddr, int shmflg)
            shmids[shmid].attached=result;
            return result;
        }
-       if(!strcmp(shmids[shmid].name,"bogo"))
-       {
+       if(!strcmp(shmids[shmid].name,"bogo")) {
            shmaddr=natmem_offset+0x00C00000;
            got = TRUE;
            if (currprefs.bogomem_size <= 0x100000)
                size+=32;
        }
-       if(!strcmp(shmids[shmid].name,"filesys"))
-       {
+       if(!strcmp(shmids[shmid].name,"filesys")) {
            result=natmem_offset+0x10000;
            shmids[shmid].attached=result;
            return result;
        }
-       if(!strcmp(shmids[shmid].name,"arcadia"))
-       {
+       if(!strcmp(shmids[shmid].name,"arcadia")) {
            result=natmem_offset+0x10000;
            shmids[shmid].attached=result;
            return result;
        }
-       if(!strcmp(shmids[shmid].name,"hrtmon"))
-       {
+       if(!strcmp(shmids[shmid].name,"hrtmon")) {
            shmaddr=natmem_offset+0x00a10000;
            got = TRUE;
        }
-       if(!strcmp(shmids[shmid].name,"arhrtmon"))
-       {
+       if(!strcmp(shmids[shmid].name,"arhrtmon")) {
            shmaddr=natmem_offset+0x00800000;
            got = TRUE;
        }
@@ -324,18 +287,12 @@ int shmget(key_t key, size_t size, int shmflg, char *name)
 {
     int result = -1;
 
-    if( ( key == IPC_PRIVATE ) ||
-       ( ( shmflg & IPC_CREAT ) && ( find_shmkey( key ) == -1) ) )
-    {
-       write_log( "shmget of size %d (%dk) for %s\n", size, size >> 10, name );
-       if( ( result = get_next_shmkey() ) != -1 )
-       {
-           //blah = VirtualAlloc( 0, size,MEM_COMMIT, PAGE_EXECUTE_READWRITE );
+    if((key == IPC_PRIVATE) || ((shmflg & IPC_CREAT) && (find_shmkey(key) == -1))) {
+       write_log ("shmget of size %d (%dk) for %s\n", size, size >> 10, name);
+       if ((result = get_next_shmkey()) != -1) {
            shmids[result].size = size;
-           strcpy( shmids[result].name, name );
-       }
-       else
-        {
+           strcpy(shmids[result].name, name);
+       } else {
            result = -1;
        }
     }
@@ -346,9 +303,8 @@ int shmctl(int shmid, int cmd, struct shmid_ds *buf)
 {
     int result = -1;
 
-    if( ( find_shmkey( shmid ) != -1 ) && buf )
-    {
-       switch( cmd )
+    if ((find_shmkey(shmid) != -1) && buf) {
+       switch(cmd)
        {
            case IPC_STAT:
                *buf = shmids[shmid];
@@ -367,25 +323,18 @@ int shmctl(int shmid, int cmd, struct shmid_ds *buf)
 
 int isinf( double x )
 {
-#ifdef _MSC_VER
     const int nClass = _fpclass(x);
     int result;
-    if (nClass == _FPCLASS_NINF || nClass == _FPCLASS_PINF)  result = 1;
-       else
-    result = 0;
-#else
-    int result = 0;
-#endif
+    if (nClass == _FPCLASS_NINF || nClass == _FPCLASS_PINF)
+       result = 1;
+    else
+       result = 0;
     return result;
 }
 
-int isnan( double x )
+int isnan(double x)
 {
-#ifdef _MSC_VER
     int result = _isnan(x);
-#else
-    int result = 0;
-#endif
     return result;
 }
 
index 03a6ba68a7ce6d010a83c040d635351746280229..8588e309b2e08520302b39e119629bfa14a18bde 100755 (executable)
@@ -12,7 +12,6 @@
 
 #if defined (OPENGL) && defined (GFXFILTER)
 
-#include "config.h"
 #include "options.h"
 #include "xwin.h"
 #include "dxwrap.h"
diff --git a/od-win32/osdep/exectasks.h b/od-win32/osdep/exectasks.h
deleted file mode 100755 (executable)
index 05fda68..0000000
+++ /dev/null
@@ -1,99 +0,0 @@
- /*
-  * UAE - The Un*x Amiga Emulator
-  *
-  * Stack magic definitions for autoconf.c
-  *
-  * Copyright 1997 Bernd Schmidt
-  */
-
-#include <setjmp.h>
-
-#ifdef CAN_DO_STACK_MAGIC
-
-#ifdef CPU_64_BIT
-
- /*
-  * UAE - The Un*x Amiga Emulator
-  *
-  * AMD64/GCC stack magic definitions for autoconf.c
-  *
-  * Copyright 2005 Richard Drummond
-  */
-
-#include <setjmp.h>
-
-struct stack_frame
-{
-    uae_u64 back_chain;
-   
-    /* Local area */
-    uae_u32 local_has_retval;
-    uae_u32 local_retval;
-    uae_u64 dummy; /* keep 16-byte aligned */
-   
-    /* Previous frame */
-    uae_u64 end_back_chain;
-};
-
-typedef void stupidfunc(void*,void*,uae_u32*,void*,void*);
-
-extern uae_u8 *stack_magic_amd64_asm_executable;
-
-__declspec(noreturn) static __forceinline void transfer_control (void *s, int size, void *pc, void *f, int has_retval)
-{   
-    struct stack_frame *stacktop = (struct stack_frame *)((char *)s + size - sizeof (struct stack_frame));
-
-    stacktop->end_back_chain   = 0xC0DEDBAD;
-    stacktop->local_retval     = 0;
-    stacktop->local_has_retval = has_retval;
-    stacktop->back_chain       = (uae_u64) &stacktop->end_back_chain;
-
-    ((stupidfunc*)stack_magic_amd64_asm_executable)(s, f, &(stacktop->local_retval), ((uae_u8*)stacktop) - 4 * 8, pc);
-    /* Not reached. */
-    abort ();
-}
-
-STATIC_INLINE uae_u32 get_retval_from_stack (void *s, int size)
-{
-    return ((struct stack_frame *)((char *)s + size - sizeof(struct stack_frame)))->local_retval;
-}
-
-STATIC_INLINE int stack_has_retval (void *s, int size)
-{
-    return ((struct stack_frame *)((char *)s + size - sizeof(struct stack_frame)))->local_has_retval;
-}
-
-#else
-
-__declspec(noreturn) static __forceinline void transfer_control(void *s, int size, void *pc, void *f, int has_retval)
-{
-    unsigned long *stacktop = (unsigned long *)((char *)s + size - 5 * 4);
-    stacktop[0] = 0xC0DEDBAD; /* return address */
-    stacktop[1] = (int)s; /* function arg 1: stack */
-    stacktop[2] = (int)f; /* function arg 2: trap function */
-    stacktop[3] = (int)stacktop; /* function arg 3: return value address */
-    stacktop[4] = has_retval;
-
-    __asm
-    {
-        mov    esp, stacktop
-        push   pc
-        ret
-    }
-    /* Not reached. */
-    abort();
-}
-
-static __inline__ uae_u32 get_retval_from_stack (void *s, int size)
-{
-    return *(uae_u32 *)((char *)s + size - 5 * 4);
-}
-
-static __inline__ int stack_has_retval (void *s, int size)
-{
-    return *(int *)((char *)s + size - 4);
-}
-
-#endif
-
-#endif
index fba6ddf66f62120aab0c8d1abb9cf70239f8a373..d3037dce246814bf055ac3a72bec94b358190670 100755 (executable)
@@ -7,20 +7,15 @@
  * Copyright 1998-1999 Brian King - added MIDI output support
  */
 
-#include "config.h"
 #include "sysconfig.h"
 #include <windows.h>
 #include <winspool.h>
 #include <stdlib.h>
 #include <stdarg.h>
-#ifdef _MSC_VER
 #include <mmsystem.h>
 #include <ddraw.h>
 #include <commctrl.h>
 #include <commdlg.h>
-#else
-#include "winstuff.h"
-#endif
 #include <stdio.h>
 #include <fcntl.h>
 #include <sys/stat.h>
@@ -34,6 +29,8 @@
 #include "include/memory.h"
 #include "custom.h"
 #include "autoconf.h"
+#include "newcpu.h"
+#include "traps.h"
 #include "od-win32/win32gui.h"
 #include "od-win32/parser.h"
 #include "od-win32/midi.h"
index 4f8d6d5644b946986b6e76d39ae4644e3b15c192..34be99b9fe4f1e2680c55fb7f70088fa620a54e1 100755 (executable)
@@ -33,7 +33,6 @@
 #include "sysconfig.h"
 #include "sysdeps.h"
 
-#include "config.h"
 #include "options.h"
 #include "threaddep/thread.h"
 #include "uae.h"
@@ -44,6 +43,7 @@
 #include "xwin.h"
 #include "savestate.h"
 #include "autoconf.h"
+#include "traps.h"
 
 #if defined(PICASSO96)
 
@@ -1451,17 +1451,17 @@ d7.l: RGBFormat
 This function is used to paint a line on the board memory possibly using the blitter. It is called by Draw
 and obeyes the destination RGBFormat as well as ForeGround and BackGround pens and draw modes. 
 */
-uae_u32 picasso_DrawLine (void)
+uae_u32 REGPARAM2 picasso_DrawLine (struct regstruct *regs)
 {
     uae_u32 result = 0;
 #ifdef P96_DRAWLINE
     struct Line line;
     struct RenderInfo ri;
-    uae_u8 Mask = m68k_dreg( regs, 0 );
-    RGBFTYPE RGBFormat = m68k_dreg( regs, 7 );
+    uae_u8 Mask = m68k_dreg(regs, 0);
+    RGBFTYPE RGBFormat = m68k_dreg(regs, 7);
 
-    CopyRenderInfoStructureA2U( m68k_areg( regs, 1 ), &ri );
-    CopyLineStructureA2U( m68k_areg( regs, 2 ), &line );
+    CopyRenderInfoStructureA2U(m68k_areg(regs, 1), &ri);
+    CopyLineStructureA2U(m68k_areg(regs, 2), &line);
 #if defined( P96TRACING_ENABLED ) && P96TRACING_LEVEL > 0
     DumpLine( &line );
 #endif
@@ -1597,7 +1597,7 @@ uae_u32 picasso_SetSpriteColor (void)
 * BoardInfo struct supplied by the caller, the rtg.library, for example
 * the MemoryBase, MemorySize and RegisterBase fields.
 */
-uae_u32 picasso_FindCard (void)
+uae_u32 REGPARAM2 picasso_FindCard (struct regstruct *regs)
 {
     uaecptr AmigaBoardInfo = m68k_areg (regs, 0);
 
@@ -1698,7 +1698,7 @@ static int AssignModeID( int i, int count )
 * gbi_MaxHorResolution: fill this in for all modes (even if you don't support them)
 * gbi_MaxVerResolution: fill this in for all modes (even if you don't support them)
 */
-uae_u32 picasso_InitCard (void)
+uae_u32 REGPARAM2 picasso_InitCard (struct regstruct *regs)
 {
     struct LibResolution res;
     int i;
@@ -1781,7 +1781,7 @@ extern int x_size, y_size;
 *
 * NOTE: Return the opposite of the switch-state. BDK
 */
-uae_u32 picasso_SetSwitch (void)
+uae_u32 REGPARAM2 picasso_SetSwitch (struct regstruct *regs)
 {
     uae_u16 flag = m68k_dreg (regs, 0) & 0xFFFF;
 
@@ -1816,7 +1816,7 @@ void picasso_enablescreen (int on)
 * per cannon your board has. So you might have to shift the colors
 * before writing them to the hardware.
 */
-uae_u32 picasso_SetColorArray (void)
+uae_u32 REGPARAM2 picasso_SetColorArray (struct regstruct *regs)
 {
 /* Fill in some static UAE related structure about this new CLUT setting
     * We need this for CLUT-based displays, and for mapping CLUT to hi/true colour */
@@ -1852,7 +1852,7 @@ uae_u32 picasso_SetColorArray (void)
 * e.g. from chunky to TrueColor. Usually, all you have to do is to set
 * the RAMDAC of your board accordingly.
 */
-uae_u32 picasso_SetDAC (void)
+uae_u32 REGPARAM2 picasso_SetDAC (struct regstruct *regs)
 {
 /* Fill in some static UAE related structure about this new DAC setting
     * Lets us keep track of what pixel format the Amiga is thinking about in our frame-buffer */
@@ -1894,7 +1894,7 @@ static void init_picasso_screen( void )
 * or linear start adress. They will be set when appropriate by their
 * own functions.
 */
-uae_u32 picasso_SetGC (void)
+uae_u32 REGPARAM2 picasso_SetGC (struct regstruct *regs)
 {
     /* Fill in some static UAE related structure about this new ModeInfo setting */
     uae_u32 border   = m68k_dreg (regs, 0);
@@ -1940,11 +1940,11 @@ uae_u32 picasso_SetGC (void)
   * because SetSwitch() is not called for subsequent Picasso screens.
 */
 
-uae_u32 picasso_SetPanning (void)
+uae_u32 REGPARAM2 picasso_SetPanning (struct regstruct *regs)
 {   
     uae_u16 Width = m68k_dreg (regs, 0);
     uaecptr start_of_screen = m68k_areg (regs, 1);
-    uaecptr bi = m68k_areg( regs, 0 );
+    uaecptr bi = m68k_areg(regs, 0);
     uaecptr bmeptr = get_long( bi + PSSO_BoardInfo_BitMapExtra );  /* Get our BoardInfo ptr's BitMapExtra ptr */
     uae_u16 bme_width, bme_height;
 
@@ -2028,7 +2028,7 @@ static void do_xor8 (uae_u8 *ptr, long len, uae_u32 val)
 * This function is used to invert a rectangular area on the board. It is called by BltBitMap,
 * BltPattern and BltTemplate.
 */
-uae_u32 picasso_InvertRect (void)
+uae_u32 REGPARAM2 picasso_InvertRect (struct regstruct *regs)
 {
     uaecptr renderinfo = m68k_areg (regs, 1);
     unsigned long X = (uae_u16)m68k_dreg (regs, 0);
@@ -2094,7 +2094,7 @@ FillRect:
 * d5: UBYTE Mask
 * d7: uae_u32 RGBFormat
 ***********************************************************/
-uae_u32 picasso_FillRect (void)
+uae_u32 REGPARAM2 picasso_FillRect (struct regstruct *regs)
 {
     uaecptr renderinfo = m68k_areg (regs, 1);
     uae_u32 X = (uae_u16)m68k_dreg (regs, 0);
@@ -2384,7 +2384,7 @@ BlitRect:
 * d6:  UBYTE Mask
 * d7:  uae_u32 RGBFormat
 ***********************************************************/
-uae_u32 picasso_BlitRect (void)
+uae_u32 REGPARAM2 picasso_BlitRect (struct regstruct *regs)
 {
     uaecptr renderinfo = m68k_areg (regs, 1);
     unsigned long srcx = (uae_u16)m68k_dreg (regs, 0);
@@ -2431,7 +2431,7 @@ BlitRectNoMaskComplete:
 *      because the RGBFormat or opcode aren't supported.
 *      OTHERWISE return 1
 ***********************************************************/
-uae_u32 picasso_BlitRectNoMaskComplete (void)
+uae_u32 REGPARAM2 picasso_BlitRectNoMaskComplete (struct regstruct *regs)
 {
     uaecptr srcri = m68k_areg (regs, 1);
     uaecptr dstri = m68k_areg (regs, 2);
@@ -2532,7 +2532,7 @@ STATIC_INLINE void PixelWrite(uae_u8 *mem, int bits, uae_u32 fgpen, uae_u8 Bpp,
 * always 16 pixels (one word) and the height is calculated as 2^Size. The data must be shifted up
 * and to the left by XOffset and YOffset pixels at the beginning.
 */
-uae_u32 picasso_BlitPattern (void)
+uae_u32 REGPARAM2 picasso_BlitPattern (struct regstruct *regs)
 {
     uaecptr rinf = m68k_areg (regs, 1);
     uaecptr pinf = m68k_areg (regs, 2);
@@ -2707,7 +2707,7 @@ BlitTemplate:
 * using a single plane of image data which will be expanded to the destination RGBFormat
 * using ForeGround and BackGround pens as well as draw modes.
 ***********************************************************************************/
-uae_u32 picasso_BlitTemplate (void)
+uae_u32 REGPARAM2 picasso_BlitTemplate (struct regstruct *regs)
 {
     uae_u8 inversion = 0;
     uaecptr rinf = m68k_areg (regs, 1);
@@ -2884,7 +2884,7 @@ uae_u32 picasso_BlitTemplate (void)
 * This function calculates the amount of bytes needed for a line of
 * "Width" pixels in the given RGBFormat.
 */
-uae_u32 picasso_CalculateBytesPerRow (void)
+uae_u32 REGPARAM2 picasso_CalculateBytesPerRow (struct regstruct *regs)
 {
     uae_u16 width = m68k_dreg (regs, 0);
     uae_u32 type = m68k_dreg (regs, 7);
@@ -2903,7 +2903,7 @@ uae_u32 picasso_CalculateBytesPerRow (void)
 * 
 * NOTE: return the opposite of the state
 */
-uae_u32 picasso_SetDisplay (void)
+uae_u32 REGPARAM2 picasso_SetDisplay (struct regstruct *regs)
 {
     uae_u32 state = m68k_dreg (regs, 0);
     P96TRACE (("SetDisplay(%d)\n", state));
@@ -3029,7 +3029,7 @@ static void PlanarToChunky(struct RenderInfo *ri, struct BitMap *bm,
 * on the board. Watch out for plane pointers that are 0x00000000 (represents a plane with all bits "0")
 * or 0xffffffff (represents a plane with all bits "1").
 */
-uae_u32 picasso_BlitPlanar2Chunky (void)
+uae_u32 REGPARAM2 picasso_BlitPlanar2Chunky (struct regstruct *regs)
 {
     uaecptr bm = m68k_areg (regs, 1);
     uaecptr ri = m68k_areg (regs, 2);
@@ -3184,7 +3184,7 @@ static void PlanarToDirect(struct RenderInfo *ri, struct BitMap *bm,
 * triple bytes or longwords respectively similar to the color values used in FillRect(), BlitPattern() or
 * BlitTemplate(). 
 */
-uae_u32 picasso_BlitPlanar2Direct (void)
+uae_u32 REGPARAM2 picasso_BlitPlanar2Direct (struct regstruct *regs)
 {
     uaecptr bm = m68k_areg (regs, 1);
     uaecptr ri = m68k_areg (regs, 2);
index 16e4ab79af86ead734954a29c644cc378c97acd8..d6229a02623eede94d7d27ffe4af03f05dc571de 100755 (executable)
@@ -481,29 +481,31 @@ extern void InitPicasso96 (void);
 
 extern int GetNumResolutions( void );
 extern int GetDisplayModeIndex( uae_u32 x, uae_u32 y, uae_u32 d);
-extern uae_u32 picasso_SetDisplay (void);
-extern uae_u32 picasso_CalculateBytesPerRow (void);
-extern uae_u32 picasso_FillRect (void);
-extern uae_u32 picasso_BlitRect (void);
-extern uae_u32 picasso_InvertRect (void);
-extern uae_u32 picasso_SetPanning (void);
-extern uae_u32 picasso_SetGC (void);
-extern uae_u32 picasso_SetDAC (void);
-extern uae_u32 picasso_SetColorArray (void);
-extern uae_u32 picasso_SetSwitch (void);
-extern uae_u32 picasso_SetSwitch (void);
-extern uae_u32 picasso_FindCard (void);
-extern uae_u32 picasso_InitCard (void);
-extern uae_u32 picasso_BlitPlanar2Chunky (void);
-extern uae_u32 picasso_BlitPlanar2Direct (void);
-extern uae_u32 picasso_BlitTemplate (void);
-extern uae_u32 picasso_BlitPattern (void);
-extern uae_u32 picasso_BlitRectNoMaskComplete (void);
-extern uae_u32 picasso_SetSprite (void);
-extern uae_u32 picasso_SetSpritePosition (void);
-extern uae_u32 picasso_SetSpriteImage (void);
-extern uae_u32 picasso_SetSpriteColor (void);
-extern uae_u32 picasso_DrawLine (void);
+
+extern uae_u32 REGPARAM3 picasso_SetDisplay (struct regstruct *regs);
+extern uae_u32 REGPARAM3 picasso_CalculateBytesPerRow (struct regstruct *regs);
+extern uae_u32 REGPARAM3 picasso_FillRect (struct regstruct *regs);
+extern uae_u32 REGPARAM3 picasso_BlitRect (struct regstruct *regs);
+extern uae_u32 REGPARAM3 picasso_InvertRect (struct regstruct *regs);
+extern uae_u32 REGPARAM3 picasso_SetPanning (struct regstruct *regs);
+extern uae_u32 REGPARAM3 picasso_SetGC (struct regstruct *regs);
+extern uae_u32 REGPARAM3 picasso_SetDAC (struct regstruct *regs);
+extern uae_u32 REGPARAM3 picasso_SetColorArray (struct regstruct *regs);
+extern uae_u32 REGPARAM3 picasso_SetSwitch (struct regstruct *regs);
+extern uae_u32 REGPARAM3 picasso_SetSwitch (struct regstruct *regs);
+extern uae_u32 REGPARAM3 picasso_FindCard (struct regstruct *regs);
+extern uae_u32 REGPARAM3 picasso_InitCard (struct regstruct *regs);
+extern uae_u32 REGPARAM3 picasso_BlitPlanar2Chunky (struct regstruct *regs);
+extern uae_u32 REGPARAM3 picasso_BlitPlanar2Direct (struct regstruct *regs);
+extern uae_u32 REGPARAM3 picasso_BlitTemplate (struct regstruct *regs);
+extern uae_u32 REGPARAM3 picasso_BlitPattern (struct regstruct *regs);
+extern uae_u32 REGPARAM3 picasso_BlitRectNoMaskComplete (struct regstruct *regs);
+extern uae_u32 REGPARAM3 picasso_SetSprite (struct regstruct *regs);
+extern uae_u32 REGPARAM3 picasso_SetSpritePosition (struct regstruct *regs);
+extern uae_u32 REGPARAM3 picasso_SetSpriteImage (struct regstruct *regs);
+extern uae_u32 REGPARAM3 picasso_SetSpriteColor (struct regstruct *regs);
+extern uae_u32 REGPARAM3 picasso_DrawLine (struct regstruct *regs);
+
 extern uae_u32 gfxmem_mask;
 extern uae_u8 *gfxmemory;
 
index 7671aa2675d5e2444ba74e638c2f8a4431242d3d..c05328d7cc9014325bcc52ac5856a63cbd0c6887 100755 (executable)
@@ -6,7 +6,6 @@
  * Copyright 1997 Mathias Ortmann
  */
 
-#include "config.h"
 #include "sysconfig.h"
 #include "sysdeps.h"
 
 #include <sys/timeb.h>
 #include <sys/utime.h>
 #include <process.h>
+
 #include "options.h"
 #include "posixemu.h"
 #include "threaddep/thread.h"
 #include "filesys.h"
 
 /* Our Win32 implementation of this function */
-void gettimeofday( struct timeval *tv, void *blah )
+void gettimeofday (struct timeval *tv, void *blah)
 {
 #if 1
     struct timeb time;
@@ -53,8 +53,8 @@ void gettimeofday( struct timeval *tv, void *blah )
 }
 
 /* convert time_t to/from AmigaDOS time */
-#define secs_per_day ( 24 * 60 * 60 )
-#define diff ( (8 * 365 + 2) * secs_per_day )
+#define secs_per_day (24 * 60 * 60)
+#define diff ((8 * 365 + 2) * secs_per_day)
 
 static void get_time(time_t t, long* days, long* mins, long* ticks)
 {
@@ -83,8 +83,10 @@ static DWORD getattr(const char *name, LPFILETIME lpft, size_t *size)
 
     FindClose(hFind);
 
-    if (lpft) *lpft = fd.ftLastWriteTime;
-    if (size) *size = fd.nFileSizeLow;
+    if (lpft)
+       *lpft = fd.ftLastWriteTime;
+    if (size)
+       *size = fd.nFileSizeLow;
 
     return fd.dwFileAttributes;
 }
@@ -98,8 +100,10 @@ int posixemu_stat(const char *name, struct stat *statbuf)
        return -1;
     } else {
        statbuf->st_mode = (attr & FILE_ATTRIBUTE_READONLY) ? FILEFLAG_READ : FILEFLAG_READ | FILEFLAG_WRITE;
-       if (attr & FILE_ATTRIBUTE_ARCHIVE) statbuf->st_mode |= FILEFLAG_ARCHIVE;
-       if (attr & FILE_ATTRIBUTE_DIRECTORY) statbuf->st_mode |= FILEFLAG_DIR;
+       if (attr & FILE_ATTRIBUTE_ARCHIVE)
+           statbuf->st_mode |= FILEFLAG_ARCHIVE;
+       if (attr & FILE_ATTRIBUTE_DIRECTORY)
+           statbuf->st_mode |= FILEFLAG_DIR;
        FileTimeToLocalFileTime(&ft,&lft);
        statbuf->st_mtime = (long)((*(__int64 *)&lft-((__int64)(369*365+89)*(__int64)(24*60*60)*(__int64)10000000))/(__int64)10000000);
     }
@@ -109,20 +113,20 @@ int posixemu_stat(const char *name, struct stat *statbuf)
 int posixemu_chmod(const char *name, int mode)
 {
     DWORD attr = FILE_ATTRIBUTE_NORMAL;
-    if (!(mode & FILEFLAG_WRITE)) attr |= FILE_ATTRIBUTE_READONLY;
-    if (mode & FILEFLAG_ARCHIVE) attr |= FILE_ATTRIBUTE_ARCHIVE;
-    if (SetFileAttributes(name,attr)) return 1;
+    if (!(mode & FILEFLAG_WRITE))
+       attr |= FILE_ATTRIBUTE_READONLY;
+    if (mode & FILEFLAG_ARCHIVE)
+       attr |= FILE_ATTRIBUTE_ARCHIVE;
+    if (SetFileAttributes(name,attr))
+       return 1;
     return -1;
 }
 
 static void tmToSystemTime( struct tm *tmtime, LPSYSTEMTIME systime )
 {
-    if( tmtime == NULL )
-    {
-        GetSystemTime( systime );
-    }
-    else
-    {
+    if (tmtime == NULL) {
+        GetSystemTime (systime);
+    } else {
         systime->wDay       = tmtime->tm_mday;
         systime->wDayOfWeek = tmtime->tm_wday;
         systime->wMonth     = tmtime->tm_mon + 1;
@@ -171,48 +175,41 @@ int posixemu_utime( const char *name, struct utimbuf *ttime )
     }
     get_time(actime, &days, &mins, &ticks);
 
-    if( setfiletime( name, days, mins, ticks, tolocal ) )
+    if(setfiletime (name, days, mins, ticks, tolocal))
         result = 0;
 
        return result;
 }
 
 /* pthread Win32 emulation */
-void sem_init (HANDLE * event, int manual_reset, int initial_state)
+void uae_sem_init (uae_sem_t * event, int manual_reset, int initial_state)
 {
-    if( *event )
-    {
-       if( initial_state )
-       {
-           SetEvent( *event );
-       }
+    if(*event) {
+       if (initial_state)
+           SetEvent(*event);
        else
-       {
-           ResetEvent( *event );
-       }
-    }
-    else
-    {
-        *event = CreateEvent (NULL, manual_reset, initial_state, NULL);
+           ResetEvent(*event);
+    } else {
+       *event = CreateEvent (NULL, manual_reset, initial_state, NULL);
     }
 }
 
-void sem_wait (HANDLE * event)
+void uae_sem_wait (uae_sem_t * event)
 {
     WaitForSingleObject (*event, INFINITE);
 }
 
-void sem_post (HANDLE * event)
+void uae_sem_post (uae_sem_t * event)
 {
     SetEvent (*event);
 }
 
-int sem_trywait (HANDLE * event)
+int uae_sem_trywait (uae_sem_t * event)
 {
     return WaitForSingleObject (*event, 0) == WAIT_OBJECT_0 ? 0 : -1;
 }
 
-void sem_close (HANDLE * event)
+void uae_sem_destroy (uae_sem_t * event)
 {
     if( *event )
     {
@@ -223,12 +220,14 @@ void sem_close (HANDLE * event)
 
 typedef unsigned (__stdcall *BEGINTHREADEX_FUNCPTR)(void *);
 
-int start_penguin (void *(*f)(void *), void *arg, DWORD *foo)
+int uae_start_thread (void *(*f)(void *), void *arg, uae_thread_id *tid)
 {
     HANDLE hThread;
     int result = 1;
+    unsigned foo;
 
-    hThread = (HANDLE)_beginthreadex( NULL, 0, (BEGINTHREADEX_FUNCPTR)f, arg, 0, foo );
+    hThread = (HANDLE)_beginthreadex(NULL, 0, (BEGINTHREADEX_FUNCPTR)f, arg, 0, &foo);
+    *tid = hThread;
     if (hThread)
         SetThreadPriority (hThread, THREAD_PRIORITY_ABOVE_NORMAL);
     else
@@ -236,7 +235,9 @@ int start_penguin (void *(*f)(void *), void *arg, DWORD *foo)
     return result;
 }
 
-void set_thread_priority (int pri)
+void uae_set_thread_priority (int pri)
 {
+    /* workaround for filesystem emulation freeze with some dual core systems */
+    SetThreadAffinityMask(GetCurrentThread(), 1); 
 }
 
index b40d7175aaba83a5a06859e24ddf6483d0fd2464..6da88d12ee6449221ab1acb713becb2bb3dab731 100755 (executable)
@@ -838,8 +838,8 @@ IDI_PATHS               ICON                    "paths.ico"
 //
 
 VS_VERSION_INFO VERSIONINFO
- FILEVERSION 1,3,2,0
- PRODUCTVERSION 1,3,2,0
+ FILEVERSION 1,4,0,0
+ PRODUCTVERSION 1,4,0,0
  FILEFLAGSMASK 0x3fL
 #ifdef _DEBUG
  FILEFLAGS 0x1L
@@ -855,12 +855,12 @@ BEGIN
         BLOCK "040904b0"
         BEGIN
             VALUE "FileDescription", "WinUAE"
-            VALUE "FileVersion", "1.3.2"
+            VALUE "FileVersion", "1.4.0"
             VALUE "InternalName", "WinUAE"
             VALUE "LegalCopyright", "© 1996-2006 under the GNU Public License (GPL)"
             VALUE "OriginalFilename", "WinUAE.exe"
             VALUE "ProductName", "WinUAE"
-            VALUE "ProductVersion", "1.3.2"
+            VALUE "ProductVersion", "1.4.0"
         END
     END
     BLOCK "VarFileInfo"
index 4b04beab56e3ca2d0f43960e6f2557ab4889eff5..613c58cac4ae7566169f37b5d4957e6442850204 100755 (executable)
@@ -10,7 +10,6 @@
 #include "sysdeps.h"
 #include "options.h"
 #include "custom.h"
-#include "picasso96.h"
 #include "dxwrap.h"
 #include "win32.h"
 #include "win32gfx.h"
index 07bbfd86ca04e48b9f854834a14a6816a24004e6..362776cd1092cb81bfa43db06f79232204a6d859 100755 (executable)
@@ -11,7 +11,6 @@
 #include "sysconfig.h"
 #include "sysdeps.h"
  
-#include "config.h"
 #include "options.h"
 #include "uae.h"
 #include "memory.h"
@@ -58,7 +57,7 @@ void SERPER (uae_u16 w)
 
     if (w & 0x8000) {
         if (!warned) {
-            write_log( "SERIAL: program uses 9bit mode PC=%x\n", m68k_getpc() );
+            write_log("SERIAL: program uses 9bit mode PC=%x\n", M68K_GETPC);
            warned++;
         }
         ninebit = 1;
@@ -82,7 +81,7 @@ void SERPER (uae_u16 w)
        serial_period_hsyncs = 1;
     serial_period_hsync_counter = 0;
 
-    write_log ("SERIAL: period=%d, baud=%d, hsyncs=%d PC=%x\n", w, baud, serial_period_hsyncs, m68k_getpc());
+    write_log ("SERIAL: period=%d, baud=%d, hsyncs=%d PC=%x\n", w, baud, serial_period_hsyncs, M68K_GETPC);
 
     if (ninebit)
        baud *= 2;
index fbb2ea8710b1435f79ac38ee2ac45c2a9bebd845..cb98e5d3410713806ce5ab4d3cab2f94a07fa313 100755 (executable)
@@ -12,7 +12,6 @@
 #include "sysconfig.h"
 #include "sysdeps.h"
 
-#include "config.h"
 #include "options.h"
 #include "memory.h"
 #include "events.h"
@@ -20,7 +19,6 @@
 #include "gensound.h"
 #include "sounddep/sound.h"
 #include "threaddep/thread.h"
-#include "ahidsound.h"
 #include "avioutput.h"
 #include "gui.h"
 #include "dxwrap.h"
index 65eea52acc66ed15a2fe2ccaf732efd5cfa64959..b3b2550223665ff2fa854ff61c73ccfa657eb111 100755 (executable)
@@ -60,7 +60,3 @@ static __inline__ void check_sound_buffers (void)
 #define FILTER_SOUND_TYPE_A1200 1
 
 #define ISSTEREO(p) (p.sound_stereo == 1 || p.sound_stereo == 2)
-
-#ifdef AHI
-#include "ahidsound.h"
-#endif
index eb66895aa11e5f7f74fa6049248b301765c49bcd..634edaee24843254b8bd2446fc83215ec1e44f04 100755 (executable)
@@ -18,29 +18,36 @@ del compstbl.c
 del cpuemu_0.c
 del cpuemu_5.c
 del cpuemu_6.c
+del linetoscr.c
 
 cd od-win32
 
+cd genlinetoscr_msvc
+rm -f genlinetoscr.exe
+rm -rf debug
+rm -rf release
+cd ..
+
 cd build68k_msvc
-rm -f build68k.exe build68k_msvc.plg
+rm -f build68k.exe
 rm -rf debug
 rm -rf release
 cd ..
 
 cd genblitter_msvc
-rm -f genblitter.exe genblitter_msvc.plg
+rm -f genblitter.exe 
 rm -rf debug
 rm -rf release
 cd ..
 
 cd gencomp_msvc
-rm -f gencomp.exe gencomp_msvc.plg
+rm -f gencomp.exe
 rm -rf debug
 rm -rf release
 cd ..
 
 cd gencpu_msvc
-rm -f gencpu.exe gencpu_msvc.plg
+rm -f gencpu.exe
 rm -rf debug
 rm -rf release
 cd ..
diff --git a/od-win32/stackmagic_amd64.asm b/od-win32/stackmagic_amd64.asm
deleted file mode 100755 (executable)
index fbeef4e..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-_TEXT SEGMENT 
-
-_stack_magic_amd64:
-       mov rax, [rsp+16]   ; move parameter 'pc' to a spare register
-       mov rsp, r9        ; swap stack
-       mov rsp, r9        ; swap stack
-       call rax         ; call function pointed to by 'pc'
-
-       mov rax,rsp
-       sub rax,2300*512
-       ret
-       ret
-
-END
index 8f5d2fb24cc087627253eb0e40d2d3b9cb666d51..222393f1dc1a51ff38cbecadbb580627b29e30e6 100755 (executable)
@@ -22,7 +22,7 @@ struct shmid_ds {
     key_t  key;
     size_t size;
     void  *addr;
-    char   name[ MAX_PATH ];
+    char   name[MAX_PATH];
     void   *attached;
 };
 
@@ -33,8 +33,8 @@ int shmget (key_t key, size_t size, int shmflg, char*);
 int shmctl (int shmid, int cmd, struct shmid_ds *buf);
 void init_shm (void);
 
-int isinf( double x );
-int isnan( double x );
+int isinf(double x);
+int isnan(double x);
 
 #define PROT_READ  0x01
 #define PROT_WRITE 0x02
@@ -44,4 +44,5 @@ int isnan( double x );
 #define IPC_RMID    0x02
 #define IPC_CREAT   0x04
 #define IPC_STAT    0x08
-#endif
\ No newline at end of file
+
+#endif
index e5e9f282d205e0a4bc986c30cc604e227a6eed7b..96a58a964ef4b6deafefeab1a3d8c21097052117 100755 (executable)
@@ -1,6 +1,6 @@
 
 #pragma warning (disable : 4761)
-#pragma warning (disable: 4996)
+#pragma warning (disable : 4996)
 
 #define DIRECTINPUT_VERSION  0x0800
 #define DIRECT3D_VERSION 0x0900
@@ -9,7 +9,6 @@
 
 #define DRIVESOUND
 #define GFXFILTER
-#define CAN_DO_STACK_MAGIC
 #define X86_MSVC_ASSEMBLY
 
 #ifndef UAE_MINI
 #define UAE_FILESYS_THREADS
 #define AUTOCONFIG /* autoconfig support, fast ram, harddrives etc.. */
 #define JIT /* JIT compiler support */
-#undef USE_SDL
 #define NATMEM_OFFSET natmem_offset
-#define CAN_DO_STACK_MAGIC
-#define USE_NORMAL_CALLING_CONVENTION 1
+#define USE_NORMAL_CALLING_CONVENTION 0
 #define USE_X86_FPUCW 1
 #define WINDDK /* Windows DDK available, keyboard leds and harddrive support */
 #define CATWEASEL /* Catweasel MK2/3 support */
@@ -31,8 +28,8 @@
 #define AGA /* AGA chipset emulation */
 #define CD32 /* CD32 emulation */
 #define CDTV /* CDTV emulation */
-#define D3D /* D3D display support */
-#define OPENGL /* OpenGL display support */
+#define D3D /* D3D display filter support */
+#define OPENGL /* OpenGL display filter support */
 #define PARALLEL_PORT /* parallel port emulation */
 #define PARALLEL_DIRECT /* direct parallel port emulation */
 #define SERIAL_PORT /* serial port emulation */
 #define PICASSO96 /* Picasso96 display card emulation */
 #define BSDSOCKET /* bsdsocket.library emulation */
 #define CAPS /* CAPS-image support */
-#define FDI2RAW /* FDI 1.0 and 2.0 image support */
+#define FDI2RAW /* FDI 1.0 and 2.x image support */
 #define AVIOUTPUT /* Avioutput support */
 #define PROWIZARD /* Pro-Wizard module ripper */
 #define ARCADIA /* Arcadia arcade system */
 #define ARCHIVEACCESS /* ArchiveAccess decompression library */
 #define LOGITECHLCD /* Logitech G15 LCD */
+#define SAVESTATE /* State file support */
 
 #else
 
@@ -86,6 +84,9 @@
 #undef X86_MSVC_ASSEMBLY
 #define X64_MSVC_ASSEMBLY
 #define CPU_64_BIT
+#define SIZEOF_VOID_P 8
+#else
+#define SIZEOF_VOID_P 4
 #endif
 
 #if !defined(AHI)
index 551bb4342926af41bce078bbaf5a540059fd911b..2453f4997a5b96ba390c2a0481116202bf13c664 100755 (executable)
@@ -1,64 +1,18 @@
 
-#if 1
-
 typedef HANDLE uae_sem_t;
-typedef int uae_thread_id;
-extern void sem_close (void*);
-extern int sem_trywait (void*);
-extern void sem_post (void*);
-extern void sem_wait (void*t);
-extern void sem_init (void*, int manual_reset, int initial_state);
-extern int start_penguin (void *(*f)(void *), void *arg, DWORD * foo);
-extern void set_thread_priority (int);
+typedef HANDLE uae_thread_id;
 
-#define uae_sem_init sem_init
-#define uae_sem_destroy sem_close
-#define uae_sem_post sem_post
-#define uae_sem_wait sem_wait
-#define uae_sem_trywait sem_trywait
-#define uae_start_thread start_penguin
+extern void uae_sem_destroy (uae_sem_t*);
+extern int uae_sem_trywait (uae_sem_t*);
+extern void uae_sem_post (uae_sem_t*);
+extern void uae_sem_wait (uae_sem_t*t);
+extern void uae_sem_init (uae_sem_t*, int manual_reset, int initial_state);
+extern int uae_start_thread(void *(*f)(void *), void *arg, uae_thread_id *thread);
+extern void uae_set_thread_priority (int);
 
 #include "commpipe.h"
 
-#else
-
-/*
-  * UAE - The Un*x Amiga Emulator
-  *
-  * Threading support, using SDL
-  *
-  * Copyright 1997, 2001 Bernd Schmidt
-  */
-
-#include "SDL.h"
-#include "SDL_thread.h"
-
-/* Sempahores. We use POSIX semaphores; if you are porting this to a machine
- * with different ones, make them look like POSIX semaphores. */
-typedef SDL_sem *uae_sem_t;
-
-#define uae_sem_init(PSEM, DUMMY, INIT) do { \
-    *PSEM = SDL_CreateSemaphore (INIT); \
-} while (0)
-#define uae_sem_destroy(PSEM) SDL_DestroySemaphore (*PSEM)
-#define uae_sem_post(PSEM) SDL_SemPost (*PSEM)
-#define uae_sem_wait(PSEM) SDL_SemWait (*PSEM)
-#define uae_sem_trywait(PSEM) SDL_SemTryWait (*PSEM)
-#define uae_sem_getvalue(PSEM) SDL_SemValue (*PSEM)
-
-#include "commpipe.h"
-extern void set_thread_priority (int);
-
-typedef SDL_Thread *uae_thread_id;
-#define BAD_THREAD NULL
-
-static __inline__ int uae_start_thread (void *(*f) (void *), void *arg, uae_thread_id *foo)
+STATIC_INLINE uae_wait_thread(uae_thread_id *tid)
 {
-    *foo = SDL_CreateThread ((int (*)(void *))f, arg);
-    return *foo == 0;
+    WaitForSingleObject(tid, INFINITE);
 }
-
-/* Do nothing; thread exits if thread function returns.  */
-#define UAE_THREAD_EXIT do {} while (0)
-
-#endif
\ No newline at end of file
index c735b8fa5bf5c2309c71dd969640f143fed71a55..7be54525bb1fe221b7327024b4575144b75a4958 100755 (executable)
@@ -10,7 +10,6 @@
 /* Uncomment this line if you want the logs time-stamped */
 /* #define TIMESTAMP_LOGS */
 
-#include "config.h"
 #include "sysconfig.h"
 
 #include <stdlib.h>
 #include "memory.h"
 #include "custom.h"
 #include "events.h"
+#include "newcpu.h"
+#include "traps.h"
 #include "xwin.h"
 #include "keyboard.h"
 #include "inputdevice.h"
 #include "keybuf.h"
 #include "drawing.h"
 #include "dxwrap.h"
-#include "picasso96.h"
+#include "picasso96_win.h"
 #include "bsdsocket.h"
 #include "win32.h"
 #include "win32gfx.h"
@@ -52,7 +53,6 @@
 #include "resource.h"
 #include "autoconf.h"
 #include "gui.h"
-#include "newcpu.h"
 #include "sys/mman.h"
 #include "avioutput.h"
 #include "ahidsound.h"
@@ -2583,7 +2583,7 @@ static LONG WINAPI ExceptionFilter( struct _EXCEPTION_POINTERS * pExceptionPoint
            if ((p >= (void*)regs.pc_p && p < (void*)(regs.pc_p + 32))
                || (p >= (void*)prevpc && p < (void*)(prevpc + 32))) {
                int got = 0;
-               uaecptr opc = m68k_getpc();
+               uaecptr opc = m68k_getpc(&regs);
                void *ps = get_real_address (0);
                m68k_dumpstate (0, 0);
                efix (&ctx->Eax, p, ps, &got);
@@ -2592,12 +2592,12 @@ static LONG WINAPI ExceptionFilter( struct _EXCEPTION_POINTERS * pExceptionPoint
                efix (&ctx->Edx, p, ps, &got);
                efix (&ctx->Esi, p, ps, &got);
                efix (&ctx->Edi, p, ps, &got);
-               write_log ("Access violation! (68KPC=%08.8X HOSTADDR=%p)\n", m68k_getpc(), p);
+               write_log ("Access violation! (68KPC=%08.8X HOSTADDR=%p)\n", M68K_GETPC, p);
                if (got == 0) {
                    write_log ("failed to find and fix the problem (%p). crashing..\n", p);
                } else {
                    void *ppc = regs.pc_p;
-                   m68k_setpc (0);
+                   m68k_setpc (&regs, 0);
                    if (ppc != regs.pc_p) {
                        prevpc = (uae_u8*)ppc;
                    }
@@ -2798,15 +2798,11 @@ end:
     return m;
 }
 
-uae_u8 *win32_stackbase; 
-
 int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
 {
     HANDLE thread;
     DWORD_PTR oldaff;
 
-    win32_stackbase = _alloca(32768 * 32);
-
     thread = GetCurrentThread();
     oldaff = SetThreadAffinityMask(thread, 1); 
     __try {
index c97326621fdce875cd5405822329e356c6e96d06..561ee344d638dc75b9b7fd1f9ae08a01af7217a9 100755 (executable)
@@ -21,8 +21,8 @@ extern int manual_painting_needed;
 extern int manual_palette_refresh_needed;
 extern int mouseactive, focus;
 extern int ignore_messages_all;
-#define WINUAEBETA 0
-#define WINUAEBETASTR ""
+#define WINUAEBETA 1
+#define WINUAEBETASTR " Beta 1"
 
 extern char start_path_exe[MAX_DPATH];
 extern char start_path_data[MAX_DPATH];
index 837570c2bd298b575ea3def21dedba3db00ce847..883fb22facbffad269e3032cd9459738340db98d 100755 (executable)
@@ -4,7 +4,6 @@
 
 #ifdef GFXFILTER
 
-#include "config.h"
 #include "options.h"
 #include "xwin.h"
 #include "dxwrap.h"
index 64ca7a4fa6cbb78ce7e00623a28305dbb8f457d5..8d4bef607138eaa6861b1eb5b821528ac8cb36b9 100755 (executable)
@@ -7,7 +7,6 @@
  * Copyright 1997-2000 Brian King
  */
 
-#include "config.h"
 #include "sysconfig.h"
 
 #include <stdlib.h>
@@ -24,6 +23,8 @@
 #include "memory.h"
 #include "custom.h"
 #include "events.h"
+#include "newcpu.h"
+#include "traps.h"
 #include "xwin.h"
 #include "keyboard.h"
 #include "drawing.h"
@@ -1368,7 +1369,7 @@ void init_colors (void)
                }
            }
        }
-       alloc_colors64k (red_bits, green_bits, blue_bits, red_shift,green_shift, blue_shift, alpha_bits, alpha_shift, alpha);
+       alloc_colors64k (red_bits, green_bits, blue_bits, red_shift,green_shift, blue_shift, alpha_bits, alpha_shift, alpha, 0);
 #ifdef GFXFILTER
        S2X_configure (red_bits, green_bits, blue_bits, red_shift,green_shift, blue_shift);
 #endif
index ecd70280e64391ea74370d24a3db350931fd1c06..5cb9b73053b443b735dcaad9d7f5221a3272cfcc 100755 (executable)
@@ -27,7 +27,6 @@
 #include <ddraw.h>
 #include <shobjidl.h>
 
-#include "config.h"
 #include "resource.h"
 #include "sysconfig.h"
 #include "sysdeps.h"
@@ -37,6 +36,7 @@
 #include "custom.h"
 #include "events.h"
 #include "newcpu.h"
+#include "traps.h"
 #include "disk.h"
 #include "uae.h"
 #include "threaddep/thread.h"
@@ -4010,7 +4010,7 @@ static void values_from_chipsetdlg (HWND hDlg, UINT msg, WPARAM wParam, LPARAM l
     BOOL success = FALSE;
     int n, snd;
 
-    workprefs.genlock = IsDlgButtonChecked (hDlg, IDC_FASTCOPPER);
+    workprefs.genlock = IsDlgButtonChecked (hDlg, IDC_GENLOCK);
     workprefs.immediate_blits = IsDlgButtonChecked (hDlg, IDC_BLITIMM);
     n = IsDlgButtonChecked (hDlg, IDC_CYCLEEXACT) ? 1 : 0;
     if (workprefs.cpu_cycle_exact != n) {
@@ -9054,7 +9054,7 @@ static INT_PTR CALLBACK DialogProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lP
            switch (LOWORD(wParam))
            {
                case IDC_RESETAMIGA:
-                   uae_reset (0);
+                   uae_reset (1);
                    SendMessage (hDlg, WM_COMMAND, IDOK, 0);
                    return TRUE;
                case IDC_QUITEMU:
index a5a07878b933dcfb6f0e9c63a4a7b2b4d2f5b74c..ea1c80698b4fab7c07bff98cca68ef225dbe9330 100755 (executable)
                                RelativePath="..\sounddep\sound.c"
                                >
                        </File>
-                       <File
-                               RelativePath="..\support.c"
-                               >
-                       </File>
                        <File
                                RelativePath="..\win32.c"
                                >
                                RelativePath="..\..\scsiemul.c"
                                >
                        </File>
+                       <File
+                               RelativePath="..\..\traps.c"
+                               >
+                       </File>
                        <File
                                RelativePath="..\..\uaeexe.c"
                                >
index 3ccf5aea8a25769ca3475e3d7bdf2dfa85c5308c..71b202369a38ff7c1e0202472c16120ed1c542de 100755 (executable)
--- a/readcpu.c
+++ b/readcpu.c
@@ -141,7 +141,7 @@ struct mnemolookup lookuptab[] = {
     { i_ILLG, "" },
 };
 
-struct instr *table68k = 0;
+struct instr *table68k;
 
 static int specialcase (uae_u16 opcode, int cpu_lev)
 {
@@ -183,7 +183,7 @@ static amodes mode_from_str (const char     *str)
     return 0;
 }
 
-static amodes mode_from_mr (int mode, int reg)
+STATIC_INLINE amodes mode_from_mr (int mode, int reg)
 {
     switch (mode) {
      case 0: return Dreg;
@@ -706,7 +706,7 @@ static void build_insn (int insn)
       endofline:
        /* now, we have a match */
        if (table68k[opc].mnemo != i_ILLG)
-           printf ("Double match: %x: %s\n", opc, opcstr);
+           ;//write_log ("Double match: %x: %s\n", opc, opcstr);
        if (find == -1) {
            for (find = 0;; find++) {
                if (strcmp(mnemonic, lookuptab[find].name) == 0) {
index 79ec4b70839774541adc420b7ba0ed6b026224d1..04dc702e8b98870872d8baf51011f7227e29fac7 100755 (executable)
@@ -47,7 +47,6 @@
 #include "sysconfig.h"
 #include "sysdeps.h"
 
-#include "config.h"
 #include "options.h"
 #include "memory.h"
 #include "zfile.h"
@@ -171,13 +170,13 @@ char *restore_string_func (uae_u8 **dstp)
 
 /* read and write IFF-style hunks */
 
-static void save_chunk (struct zfile *f, uae_u8 *chunk, long len, char *name, int compress)
+static void save_chunk (struct zfile *f, uae_u8 *chunk, size_t len, char *name, int compress)
 {
     uae_u8 tmp[8], *dst;
     uae_u8 zero[4]= { 0, 0, 0, 0 };
     uae_u32 flags;
     size_t pos;
-    long chunklen, len2;
+    size_t chunklen, len2;
 
     if (!chunk)
        return;
@@ -232,11 +231,11 @@ static void save_chunk (struct zfile *f, uae_u8 *chunk, long len, char *name, in
     write_log ("Chunk '%s' chunk size %d (%d)\n", name, chunklen, len);
 }
 
-static uae_u8 *restore_chunk (struct zfile *f, char *name, long *len, long *totallen, long *filepos)
+static uae_u8 *restore_chunk (struct zfile *f, char *name, size_t *len, size_t *totallen, size_t *filepos)
 {
     uae_u8 tmp[4], dummy[4], *mem, *src;
     uae_u32 flags;
-    long len2;
+    size_t len2;
 
     *totallen = 0;
     /* chunk name */
@@ -289,7 +288,7 @@ static uae_u8 *restore_chunk (struct zfile *f, char *name, long *len, long *tota
     return mem;
 }
 
-void restore_ram (long filepos, uae_u8 *memory)
+void restore_ram (size_t filepos, uae_u8 *memory)
 {
     uae_u8 tmp[8];
     uae_u8 *src = tmp;
@@ -334,8 +333,8 @@ void restore_state (char *filename)
     struct zfile *f;
     uae_u8 *chunk,*end;
     char name[5];
-    long len, totallen;
-    long filepos;
+    size_t len, totallen;
+    size_t filepos;
 
     chunk = 0;
     f = zfile_fopen (filename, "rb");
index a553ef90a516244435cd480e95608993ec51fb27..58a11321d56048a7c30b233562e3683c83e50521 100755 (executable)
@@ -1,20 +1,9 @@
 #include "sysconfig.h"
 #include "sysdeps.h"
 
-#include "config.h"
-#include "threaddep/thread.h"
-#include "options.h"
-#include "memory.h"
-#include "custom.h"
-#include "newcpu.h"
-#include "disk.h"
-#include "autoconf.h"
-#include "filesys.h"
-#include "execlib.h"
 #include "scsidev.h"
 
 uaecptr scsidev_startup (uaecptr resaddr) { return resaddr; }
 void scsidev_install (void) {}
 void scsidev_reset (void) {}
 void scsidev_start_threads (void) {}
-
index b8fc8c2e644a2d47c782395216e914af86489402..7a9e69069fd1372d3a5b99d8df6dab9286e3198a 100755 (executable)
@@ -13,7 +13,6 @@
 #include "sysconfig.h"
 #include "sysdeps.h"
 
-#include "config.h"
 #include "uae.h"
 #include "threaddep/thread.h"
 #include "options.h"
@@ -22,6 +21,7 @@
 #include "events.h"
 #include "newcpu.h"
 #include "autoconf.h"
+#include "traps.h"
 #include "execlib.h"
 #include "native2amiga.h"
 #include "blkdev.h"
@@ -200,9 +200,9 @@ static void dev_close_3 (struct devstruct *dev, struct priv_devstruct *pdev)
     }
 }
 
-static uae_u32 dev_close_2 (void)
+static uae_u32 REGPARAM2 dev_close_2 (TrapContext *context)
 {
-    uae_u32 request = m68k_areg (regs, 1);
+    uae_u32 request = m68k_areg (&context->regs, 1);
     struct priv_devstruct *pdev = getpdevstruct (request);
     struct devstruct *dev;
 
@@ -215,17 +215,17 @@ static uae_u32 dev_close_2 (void)
        return 0;
     dev_close_3 (dev, pdev);
     put_long (request + 24, 0);
-    put_word (m68k_areg(regs, 6) + 32, get_word (m68k_areg(regs, 6) + 32) - 1);
+    put_word (m68k_areg(&context->regs, 6) + 32, get_word (m68k_areg(&context->regs, 6) + 32) - 1);
     return 0;
 }
 
-static uae_u32 dev_close (void)
+static uae_u32 REGPARAM2 dev_close (TrapContext *context)
 {
-    return dev_close_2 ();
+    return dev_close_2 (context);
 }
-static uae_u32 diskdev_close (void)
+static uae_u32 REGPARAM2 diskdev_close (TrapContext *context)
 {
-    return dev_close_2 ();
+    return dev_close_2 (context);
 }
 
 static int openfail (uaecptr ioreq, int error)
@@ -235,11 +235,11 @@ static int openfail (uaecptr ioreq, int error)
     return (uae_u32)-1;
 }
 
-static uae_u32 dev_open_2 (int type)
+static uae_u32 REGPARAM2 dev_open_2 (TrapContext *context, int type)
 {
-    uaecptr ioreq = m68k_areg(regs, 1);
-    uae_u32 unit = m68k_dreg (regs, 0);
-    uae_u32 flags = m68k_dreg (regs, 1);
+    uaecptr ioreq = m68k_areg (&context->regs, 1);
+    uae_u32 unit = m68k_dreg (&context->regs, 0);
+    uae_u32 flags = m68k_dreg (&context->regs, 1);
     struct devstruct *dev = getdevstruct (unit);
     struct priv_devstruct *pdev = 0;
     int i;
@@ -280,26 +280,26 @@ static uae_u32 dev_open_2 (int type)
     }
     dev->opencnt++;
 
-    put_word (m68k_areg(regs, 6) + 32, get_word (m68k_areg(regs, 6) + 32) + 1);
+    put_word (m68k_areg(&context->regs, 6) + 32, get_word (m68k_areg(&context->regs, 6) + 32) + 1);
     put_byte (ioreq + 31, 0);
     put_byte (ioreq + 8, 7);
     return 0;
 }
 
-static uae_u32 dev_open (void)
+static uae_u32 REGPARAM2 dev_open (TrapContext *context)
 {
-    return dev_open_2 (UAEDEV_SCSI_ID);
+    return dev_open_2 (context, UAEDEV_SCSI_ID);
 }
-static uae_u32 diskdev_open (void)
+static uae_u32 REGPARAM2 diskdev_open (TrapContext *context)
 {
-    return dev_open_2 (UAEDEV_DISK_ID);
+    return dev_open_2 (context, UAEDEV_DISK_ID);
 }
 
-static uae_u32 dev_expunge (void)
+static uae_u32 REGPARAM2 dev_expunge (TrapContext *context)
 {
     return 0;
 }
-static uae_u32 diskdev_expunge (void)
+static uae_u32 REGPARAM2 diskdev_expunge (TrapContext *context)
 {
     return 0;
 }
@@ -599,9 +599,9 @@ static int dev_canquick (struct devstruct *dev, uaecptr request)
     return dev_can_quick (command);
 }
 
-static uae_u32 dev_beginio (void)
+static uae_u32 REGPARAM2 dev_beginio (TrapContext *context)
 {
-    uae_u32 request = m68k_areg(regs, 1);
+    uae_u32 request = m68k_areg (&context->regs, 1);
     uae_u8 flags = get_byte (request + 30);
     int command = get_word (request + 28);
     struct priv_devstruct *pdev = getpdevstruct (request);
@@ -629,7 +629,7 @@ static void *dev_thread (void *devs)
 {
     struct devstruct *dev = devs;
 
-    set_thread_priority (2);
+    uae_set_thread_priority (2);
     dev->thread_running = 1;
     uae_sem_post (&dev->sync_sem);
     for (;;) {
@@ -653,26 +653,26 @@ static void *dev_thread (void *devs)
     return 0;
 }
 
-static uae_u32 dev_init_2 (int type)
+static uae_u32 REGPARAM2 dev_init_2 (TrapContext *context, int type)
 {
-    uae_u32 base = m68k_dreg (regs,0);
+    uae_u32 base = m68k_dreg (&context->regs,0);
     if (log_scsi)
        write_log ("%s init\n", getdevname (type));
     return base;
 }
 
-static uae_u32 dev_init (void)
+static uae_u32 REGPARAM2 dev_init (TrapContext *context)
 {
-    return dev_init_2 (UAEDEV_SCSI_ID);
+    return dev_init_2 (context, UAEDEV_SCSI_ID);
 }
-static uae_u32 diskdev_init (void)
+static uae_u32 REGPARAM2 diskdev_init (TrapContext *context)
 {
-    return dev_init_2 (UAEDEV_DISK_ID);
+    return dev_init_2 (context, UAEDEV_DISK_ID);
 }
 
-static uae_u32 dev_abortio (void)
+static uae_u32 REGPARAM2 dev_abortio (TrapContext *context)
 {
-    uae_u32 request = m68k_areg(regs, 1);
+    uae_u32 request = m68k_areg (&context->regs, 1);
     struct priv_devstruct *pdev = getpdevstruct (request);
     struct devstruct *dev;
 
@@ -906,19 +906,19 @@ void scsidev_install (void)
 
     /* initcode */
     initcode = here ();
-    calltrap (deftrap (dev_init)); dw (RTS);
+    calltrap (deftrap (diskdev_init)); dw (RTS);
 
     /* Open */
     openfunc = here ();
-    calltrap (deftrap (dev_open)); dw (RTS);
+    calltrap (deftrap (diskdev_open)); dw (RTS);
 
     /* Close */
     closefunc = here ();
-    calltrap (deftrap (dev_close)); dw (RTS);
+    calltrap (deftrap (diskdev_close)); dw (RTS);
 
     /* Expunge */
     expungefunc = here ();
-    calltrap (deftrap (dev_expunge)); dw (RTS);
+    calltrap (deftrap (diskdev_expunge)); dw (RTS);
 
     /* BeginIO */
     beginiofunc = here ();
diff --git a/traps.c b/traps.c
new file mode 100755 (executable)
index 0000000..6fc1b37
--- /dev/null
+++ b/traps.c
@@ -0,0 +1,471 @@
+ /*
+  * E-UAE - The portable Amiga Emulator
+  *
+  * Support for traps
+  *
+  * Copyright Richard Drummond 2005
+  *
+  * Inspired by code from UAE:
+  * Copyright 1995, 1996 Bernd Schmidt
+  * Copyright 1996 Ed Hanway
+  */
+
+#include "sysconfig.h"
+#include "sysdeps.h"
+
+#include "options.h"
+#include "memory.h"
+#include "custom.h"
+#include "newcpu.h"
+#include "threaddep/thread.h"
+#include "autoconf.h"
+#include "traps.h"
+
+/*
+ * Traps are the mechanism via which 68k code can call emulator code
+ * (and for that emulator code in turn to call 68k code). They are
+ * thus the basis for much of the cool stuff that E-UAE can do.
+ *
+ * Emulator traps take advantage of the illegal 68k opwords 0xA000 to
+ * 0xAFFF. Normally these would generate an A-line exception. However,
+ * when encountered in the RTAREA section of memory, these opwords
+ * instead invoke a corresponding emulator trap, allowing a host
+ * function to be called.
+ *
+ * Two types of emulator trap are available - a simple trap and an
+ * extended trap. A simple trap may not call 68k code; an extended
+ * trap can.
+ *
+ * Extended traps are rather complex beasts (to implement, not
+ * necessarily to use). This is because for the trap handler function
+ * to be able to call 68k code, we must somehow allow the emulator's
+ * 68k interpreter to resume execution of 68k code in the middle of
+ * the trap handler function.
+ *
+ * In UAE of old this used to be implemented via a stack-swap mechanism.
+ * While this worked, it was definitely in the realm of black magic and
+ * horribly non-portable, requiring assembly language glue specific to
+ * the host ABI and compiler to actually perform the swap.
+ *
+ * In this implementation, in essence we do something similar - but the
+ * new stack is provided by a new thread. No voodoo required, just a
+ * working thread layer.
+ *
+ * The complexity in this approach arises in synchronizing the trap
+ * threads with the emulator thread. This implementation errs on the side
+ * of paranoia when it comes to thread synchronization. Once all the
+ * bugs are knocked out of the bsdsocket emulation, a simpler scheme may
+ * suffice.
+ */
+
+/*
+ * Record of a defined trap (that is, a trap allocated to a host function)
+ */
+struct Trap
+{
+    TrapHandler handler;       /* Handler function to be invoked for this trap. */
+    int         flags;         /* Trap attributes. */
+    const char *name;          /* For debugging purposes. */
+};
+
+#define MAX_TRAPS 4096
+
+/* Defined traps */
+static struct Trap  traps[MAX_TRAPS];
+static unsigned int trap_count;
+
+
+static const int trace_traps = 1;
+
+
+static void trap_HandleExtendedTrap (TrapHandler, int has_retval);
+
+/*
+ * Define an emulator trap
+ *
+ * handler_func = host function that will be invoked to handle this trap
+ * flags        = trap attributes
+ * name         = name for debugging purposes
+ *
+ * returns trap number of defined trap
+ */
+unsigned int define_trap (TrapHandler handler_func, int flags, const char *name)
+{
+    if (trap_count == MAX_TRAPS) {
+       write_log ("Ran out of emulator traps\n");
+       abort ();
+       return 0;
+    } else {
+       unsigned int trap_num = trap_count++;
+       struct Trap *trap = &traps[trap_num];
+
+       trap->handler = handler_func;
+       trap->flags   = flags;
+       trap->name    = name;
+
+       return trap_num;
+    }
+}
+
+
+/*
+ * This function is called by the 68k interpreter to handle an emulator trap.
+ *
+ * trap_num = number of trap to invoke
+ * regs     = current 68k state
+ */
+void REGPARAM2 m68k_handle_trap (unsigned int trap_num, struct regstruct *regs)
+{
+    struct Trap *trap = &traps[trap_num];
+    uae_u32 retval = 0;
+
+    int has_retval   = (trap->flags & TRAPFLAG_NO_RETVAL) == 0;
+    int implicit_rts = (trap->flags & TRAPFLAG_DORET) != 0;
+
+    if (trap->name && trap->name[0] != 0 && trace_traps)
+       write_log ("TRAP: %s\n", trap->name);
+
+    if (trap_num < trap_count) {
+
+       if (trap->flags & TRAPFLAG_EXTRA_STACK) {
+           /* Handle an extended trap.
+            * Note: the return value of this trap is passed back to 68k
+            * space via a separate, dedicated simple trap which the trap
+            * handler causes to be invoked when it is done.
+            */
+           trap_HandleExtendedTrap (trap->handler, has_retval);
+       } else {
+           /* Handle simple trap */
+           retval = (trap->handler) ((TrapContext *)regs);
+
+           if (has_retval)
+               m68k_dreg (regs, 0) = retval;
+
+           if (implicit_rts) {
+               m68k_do_rts (regs);
+               fill_prefetch_slow (regs);
+           }
+       }
+
+    } else
+       write_log ("Illegal emulator trap %d\n", trap_num);
+}
+
+
+
+/*
+ * Implementation of extended traps
+ */
+
+typedef struct ExtendedTrapContext
+{
+    /*
+     * Same as simple trap
+     */
+    struct regstruct  regs;                    /* Trap's working copy of 68k state. This is what
+                                                * the trap handler should access to get arguments
+                                                * from 68k space. */
+
+    /*
+     * Extended trap only
+     */
+    TrapHandler       trap_handler;            /* Trap handler function that gets called on the trap context */
+    int               trap_has_retval;         /* Should the handler return a value to 68k space in D0? */
+    uae_u32           trap_retval;             /* Return value from trap handler */
+
+
+    struct regstruct  saved_regs;                /* Copy of 68k state at trap entry. */
+
+
+    uae_thread_id     thread;                  /* Thread which effects the trap context. */
+    uae_sem_t         switch_to_emu_sem;       /* For IPC between the main emulator. */
+    uae_sem_t         switch_to_trap_sem;      /* context and the trap context. */
+
+
+    uaecptr           call68k_func_addr;       /* When calling a 68k function from a trap handler, this
+                                                * is set to the address of the function to call. */
+    uae_u32           call68k_retval;          /* And this gets set to the return value of the 68k call */
+} ExtendedTrapContext;
+
+
+/* 68k addresses which invoke the corresponding traps. */
+static uaecptr m68k_call_trapaddr;
+static uaecptr m68k_return_trapaddr;
+static uaecptr exit_trap_trapaddr;
+
+/* For IPC between main thread and trap context */
+static uae_sem_t trap_mutex;
+static ExtendedTrapContext *current_context;
+
+
+/*
+ * Thread body for trap context
+ */
+static void *trap_thread (void *arg)
+{
+    ExtendedTrapContext *context = (ExtendedTrapContext *) arg;
+
+    uae_set_thread_priority (2);
+
+    /* Wait until main thread is ready to switch to the
+     * this trap context. */
+    uae_sem_wait (&context->switch_to_trap_sem);
+
+    /* Execute trap handler function. */
+    context->trap_retval = context->trap_handler ((TrapContext *)context);
+
+    /* Trap handler is done - we still need to tidy up
+     * and make sure the handler's return value is propagated
+     * to the calling 68k thread.
+     *
+     * We do this by causing our exit handler to be executed on the 68k context.
+     */
+
+    /* Enter critical section - only one trap at a time, please! */
+    uae_sem_wait (&trap_mutex);
+
+    /* Don't allow an interrupt and thus potentially another
+     * trap to be invoked while we hold the above mutex.
+     * This is probably just being paranoid. */
+    context->regs.intmask = 7;
+
+    /* Set PC to address of the exit handler, so that it will be called
+     * when the 68k context resumes. */
+    m68k_setpc (&context->regs, exit_trap_trapaddr);
+    current_context = context;
+
+    /* Switch back to 68k context */
+    uae_sem_post (&context->switch_to_emu_sem);
+
+    /* Good bye, cruel world... */
+
+    /* dummy return value */
+    return 0;
+}
+
+/*
+ * Set up extended trap context and call handler function
+ */
+static void trap_HandleExtendedTrap (TrapHandler handler_func, int has_retval)
+{
+    struct ExtendedTrapContext *context = calloc (1, sizeof (ExtendedTrapContext));
+
+    if (context) {
+       uae_sem_init (&context->switch_to_trap_sem, 0, 0);
+       uae_sem_init (&context->switch_to_emu_sem, 0, 0);
+
+       context->trap_handler    = handler_func;
+       context->trap_has_retval = has_retval;
+
+       context->regs = regs;       /* Working copy of regs */
+
+       context->saved_regs = regs; /* Copy of regs to be restored when trap is done */
+
+       /* Start thread to handle new trap context. */
+       uae_start_thread (trap_thread, (void *)context, &context->thread);
+
+       /* Switch to trap context to begin execution of
+        * trap handler function.
+        */
+       uae_sem_post (&context->switch_to_trap_sem);
+
+       /* Wait for trap context to switch back to us.
+        *
+        * It'll do this when the trap handler is done - or when
+        * the handler wants to call 68k code. */
+       uae_sem_wait (&context->switch_to_emu_sem);
+
+       /* Use trap's modified 68k state. This will reset the PC, so that
+        * execution will resume at either the m68k call handler or the
+        * the exit handler. */
+       regs = context->regs;
+    }
+}
+
+/*
+ * Call m68k function from an extended trap handler
+ *
+ * This function is to be called from the trap context.
+ */
+static uae_u32 trap_Call68k (ExtendedTrapContext *context, uaecptr func_addr)
+{
+    /* Enter critical section - only one trap at a time, please! */
+    uae_sem_wait (&trap_mutex);
+    current_context = context;
+
+    /* Don't allow an interrupt and thus potentially another
+     * trap to be invoked while we hold the above mutex.
+     * This is probably just being paranoid. */
+    context->regs.intmask = 7;
+
+    /* Set up function call address. */
+    context->call68k_func_addr = func_addr;
+
+    /* Set PC to address of 68k call trap, so that it will be
+     * executed when emulator context resumes. */
+    m68k_setpc (&context->regs, m68k_call_trapaddr);
+    fill_prefetch_slow (&context->regs);
+
+    /* Switch to emulator context. */
+    uae_sem_post (&context->switch_to_emu_sem);
+
+    /* Wait for 68k call return handler to switch back to us. */
+    uae_sem_wait (&context->switch_to_trap_sem);
+
+    /* End critical section. */
+    uae_sem_post (&trap_mutex);
+
+    /* Get return value from 68k function called. */
+    return context->call68k_retval;
+}
+
+/*
+ * Handles the emulator's side of a 68k call (from an extended trap)
+ */
+static uae_u32 REGPARAM2 m68k_call_handler (struct regstruct *regs)
+{
+    ExtendedTrapContext *context = current_context;
+
+    uae_u32 sp = m68k_areg (regs, 7);
+
+    /* Push address of trap context on 68k stack. This is
+     * so the return trap can find this context. */
+    sp -= sizeof (void *);
+    put_pointer (sp, context);
+
+    /* Push addr to return handler trap on 68k stack.
+     * When the called m68k function does an RTS, the CPU will pull this
+     * address off the stack and so call the return handler. */
+    sp -= 4;
+    put_long (sp, m68k_return_trapaddr);
+
+    m68k_areg (regs, 7) = sp;
+
+    /* Set PC to address of 68k function to call. */
+    m68k_setpc (regs, context->call68k_func_addr);
+    fill_prefetch_slow (&context->regs);
+
+    /* End critical section: allow other traps run. */
+    uae_sem_post (&trap_mutex);
+
+    /* Restore interrupts. */
+    regs->intmask = context->saved_regs.intmask;
+
+    /* Dummy return value. */
+    return 0;
+}
+
+/*
+ * Handles the return from a 68k call at the emulator's side.
+ */
+static uae_u32 REGPARAM2 m68k_return_handler (struct regstruct *regs)
+{
+    ExtendedTrapContext *context;
+    uae_u32 sp;
+
+    /* One trap returning at a time, please! */
+    uae_sem_wait (&trap_mutex);
+
+    /* Get trap context from 68k stack. */
+    sp = m68k_areg (regs, 7);
+    context = get_pointer(sp);
+    sp += sizeof (void *);
+    m68k_areg (regs, 7) = sp;
+
+    /* Get return value from the 68k call. */
+    context->call68k_retval = m68k_dreg (regs, 0);
+
+    /* Update trap's working copy of CPU state. */
+    context->regs = *regs;
+
+    /* Switch back to trap context. */
+    uae_sem_post (&context->switch_to_trap_sem);
+
+    /* Wait for trap context to switch back to us.
+     *
+     * It'll do this when the trap handler is done - or when
+     * the handler wants to call another 68k function. */
+    uae_sem_wait (&context->switch_to_emu_sem);
+
+    /* Use trap's modified 68k state. This will reset the PC, so that
+     * execution will resume at either the m68k call handler or the
+     * the exit handler. */
+    *regs = context->regs;
+
+    /* Dummy return value. */
+    return 0;
+}
+
+/*
+ * Handles completion of an extended trap and passes
+ * return value from trap function to 68k space.
+ */
+static uae_u32 REGPARAM2 exit_trap_handler (struct regstruct *regs)
+{
+    ExtendedTrapContext *context = current_context;
+
+    /* Wait for trap context thread to exit. */
+    uae_wait_thread (context->thread);
+
+    /* Restore 68k state saved at trap entry. */
+    *regs = context->saved_regs;
+
+    /* If trap is supposed to return a value, then store
+     * return value in D0. */
+    if (context->trap_has_retval)
+       m68k_dreg (regs, 0) = context->trap_retval;
+
+    uae_sem_destroy (&context->switch_to_trap_sem);
+    uae_sem_destroy (&context->switch_to_emu_sem);
+
+    free (context);
+
+    /* End critical section */
+    uae_sem_post (&trap_mutex);
+
+    /* Dummy return value. */
+    return 0;
+}
+
+
+
+/*
+ * Call a 68k library function from extended trap.
+ */
+uae_u32 CallLib (TrapContext *context, uaecptr base, uae_s16 offset)
+{
+    uae_u32 retval;
+    uaecptr olda6 = m68k_areg (&context->regs, 6);
+
+    m68k_areg (&context->regs, 6) = base;
+    retval = trap_Call68k ((ExtendedTrapContext *)context, base + offset);
+    m68k_areg (&context->regs, 6) = olda6;
+
+    return retval;
+}
+
+
+/*
+ * Initialize trap mechanism.
+ */
+void init_traps (void)
+{
+   trap_count = 0;
+}
+
+/*
+ * Initialize the extended trap mechanism.
+ */
+void init_extended_traps (void)
+{
+    m68k_call_trapaddr = here ();
+    calltrap (deftrap2 ((TrapHandler)m68k_call_handler, TRAPFLAG_NO_RETVAL, "m68k_call"));
+
+    m68k_return_trapaddr = here();
+    calltrap (deftrap2 ((TrapHandler)m68k_return_handler, TRAPFLAG_NO_RETVAL, "m68k_return"));
+
+    exit_trap_trapaddr = here();
+    calltrap (deftrap2 ((TrapHandler)exit_trap_handler, TRAPFLAG_NO_RETVAL, "exit_trap"));
+
+    uae_sem_init (&trap_mutex, 0, 1);
+}
index ac88ae90c101e30b5163a3556d1c7d5fdaccea1c..44fa1e254d5fffd3e01536f31ef9b96fc9befd87 100755 (executable)
--- a/uaeexe.c
+++ b/uaeexe.c
@@ -7,19 +7,19 @@
 #include "sysconfig.h"
 #include "sysdeps.h"
 
-#include "config.h"
 #include "options.h"
 #include "uae.h"
 #include "memory.h"
 #include "custom.h"
 #include "newcpu.h"
 #include "autoconf.h"
+#include "traps.h"
 #include "uaeexe.h"
 
 static struct uae_xcmd *first = NULL;
 static struct uae_xcmd *last  = NULL;
 static char running = 0;
-static uae_u32 uaeexe_server(void);
+static uae_u32 REGPARAM3 uaeexe_server (TrapContext *context) REGPARAM;
 
 /*
  * Install the server
@@ -44,17 +44,17 @@ void uaeexe_install(void)
  * to launch the command asynchronously. Please note also that the
  * remote cli works better if you've got the fifo-handler installed.
  */
-int uaeexe(char *cmd)
+int uaeexe(const char *cmd)
 {
     struct uae_xcmd *nw;
 
     if (!running)
        goto NORUN;
 
-    nw = (struct uae_xcmd *)malloc (sizeof *nw);
+    nw = malloc (sizeof *nw);
     if (!nw)
        goto NOMEM;
-    nw->cmd = (char *)malloc (strlen (cmd) + 1);
+    nw->cmd = malloc (strlen (cmd) + 1);
     if (!nw->cmd) {
        free (nw);
        goto NOMEM;
@@ -64,11 +64,13 @@ int uaeexe(char *cmd)
     nw->prev = last;
     nw->next = NULL;
 
-    if(!first) first  = nw;
+    if(!first)
+       first  = nw;
     if(last) {
-          last->next = nw;
-          last       = nw;
-    } else last       = nw;
+       last->next = nw;
+       last       = nw;
+    } else
+       last       = nw;
 
     return UAEEXE_OK;
   NOMEM:
@@ -86,10 +88,13 @@ static char *get_cmd(void)
     struct uae_xcmd *cmd;
     char *s;
 
-    if(!first) return NULL;
+    if(!first)
+       return NULL;
     s = first->cmd;
-    cmd = first; first = first->next;
-    if(!first) last = NULL;
+    cmd = first;
+    first = first->next;
+    if(!first)
+       last = NULL;
     free(cmd);
     return s;
 }
@@ -97,8 +102,8 @@ static char *get_cmd(void)
 /*
  * helper function
  */
-#define ARG(x) (get_long (m68k_areg (regs, 7) + 4*(x+1)))
-static uae_u32 uaeexe_server(void)
+#define ARG(x) (get_long (m68k_areg (&context->regs, 7) + 4*(x+1)))
+static uae_u32 REGPARAM2 uaeexe_server (TrapContext *context)
 {
     int len;
     char *cmd;
@@ -109,15 +114,18 @@ static uae_u32 uaeexe_server(void)
        write_log("Remote CLI started.\n");
     }
 
-    cmd = get_cmd(); if(!cmd) return 0;
-    if(!ARG(0)) {running = 0;return 0;}
+    cmd = get_cmd();
+    if(!cmd)
+       return 0;
+    if(!ARG(0)) {
+       running = 0;
+       return 0;
+    }
 
     dst = (char *)get_real_address(ARG(0));
     len = ARG(1);
     strncpy(dst,cmd,len);
-    printf("Sending '%s' to remote cli\n",cmd); /**/
+    write_log ("Sending '%s' to remote cli\n",cmd);
     free(cmd);
     return ARG(0);
 }
-
-
index 7b675c509abf628ae6f9cec575e0d3ec7cff7b85..1a296693d304eea9ac0ed31ad5800e53b8e37ccd 100755 (executable)
--- a/uaeipc.c
+++ b/uaeipc.c
@@ -1,5 +1,4 @@
 
-#include "config.h"
 #include "sysconfig.h"
 
 #include <stdlib.h>
@@ -145,16 +144,17 @@ void *geteventhandleIPC(void)
     return olevent;
 }
 
-static int isout;
-static char outmsg[IPC_BUFFER_SIZE];
+#define MAX_OUTMESSAGES 30
+static char *outmsg[MAX_OUTMESSAGES];
+static int outmessages;
 
 int sendIPC(char *msg)
 {
     if (hipc == INVALID_HANDLE_VALUE)
        return 0;
-    if (isout)
+    if (outmessages >= MAX_OUTMESSAGES)
        return 0;
-    strcpy (outmsg, msg);
+    outmsg[outmessages++] = my_strdup (msg);
     if (!readpending && !writepending)
        SetEvent (olevent);
     return 1;
@@ -169,11 +169,11 @@ int checkIPC(struct uae_prefs *p)
        return 0;
     if (WaitForSingleObject(olevent, 0) != WAIT_OBJECT_0)
        return 0;
-    if (!readpending && !writepending && isout) {
-       isout = 0;
+    if (!readpending && !writepending && outmessages > 0) {
        memset (&ol, 0, sizeof ol);
        ol.hEvent = olevent;
-       ok = WriteFile(hipc, outmsg, strlen (outmsg) + 1, &ret, &ol);
+       ok = WriteFile(hipc, outmsg[outmessages], strlen (outmsg[outmessages]) + 1, &ret, &ol);
+       xfree(outmsg[outmessages--]);
        err = GetLastError();
        if (!ok && err != ERROR_IO_PENDING) {
            write_log ("IPC: WriteFile() err=%d\n", err);
index d54942a24fc63ec3cfb5a36fecc1ad12d57d2459..d1075ff84cc5526f422883014064d1ae2d52c9dd 100755 (executable)
--- a/uaelib.c
+++ b/uaelib.c
 #include <assert.h>
 #include <string.h>
 
-#include "config.h"
 #include "options.h"
-#include "threaddep/thread.h"
 #include "uae.h"
 #include "memory.h"
 #include "custom.h"
 #include "newcpu.h"
 #include "xwin.h"
 #include "autoconf.h"
+#include "traps.h"
 #include "disk.h"
 #include "debug.h"
 #include "gensound.h"
@@ -130,14 +129,14 @@ static uae_u32 emulib_ChangeLanguage (uae_u32 which)
  * Changes chip memory size
  *  (reboots)
  */
-static uae_u32 emulib_ChgCMemSize (uae_u32 memsize)
+static uae_u32 REGPARAM2 emulib_ChgCMemSize (struct regstruct *regs, uae_u32 memsize)
 {
     if (memsize != 0x80000 && memsize != 0x100000 &&
        memsize != 0x200000) {
        memsize = 0x200000;
        write_log ("Unsupported chipmem size!\n");
     }
-    m68k_dreg(regs, 0) = 0;
+    m68k_dreg (regs, 0) = 0;
 
     currprefs.chipmem_size = memsize;
     uae_reset(0);
@@ -148,7 +147,7 @@ static uae_u32 emulib_ChgCMemSize (uae_u32 memsize)
  * Changes slow memory size
  *  (reboots)
  */
-static uae_u32 emulib_ChgSMemSize (uae_u32 memsize)
+static uae_u32 REGPARAM2 emulib_ChgSMemSize (struct regstruct *regs, uae_u32 memsize)
 {
     if (memsize != 0x80000 && memsize != 0x100000 &&
        memsize != 0x180000 && memsize != 0x1C0000) {
@@ -156,7 +155,7 @@ static uae_u32 emulib_ChgSMemSize (uae_u32 memsize)
        write_log ("Unsupported bogomem size!\n");
     }
 
-    m68k_dreg(regs, 0) = 0;
+    m68k_dreg (regs, 0) = 0;
     currprefs.bogomem_size = memsize;
     uae_reset (0);
     return 1;
@@ -166,14 +165,14 @@ static uae_u32 emulib_ChgSMemSize (uae_u32 memsize)
  * Changes fast memory size
  *  (reboots)
  */
-static uae_u32 emulib_ChgFMemSize (uae_u32 memsize)
+static uae_u32 REGPARAM2 emulib_ChgFMemSize (struct regstruct *regs, uae_u32 memsize)
 {
     if (memsize != 0x100000 && memsize != 0x200000 &&
        memsize != 0x400000 && memsize != 0x800000) {
        memsize = 0;
        write_log ("Unsupported fastmem size!\n");
     }
-    m68k_dreg(regs, 0) = 0;
+    m68k_dreg (regs, 0) = 0;
     currprefs.fastmem_size = memsize;
     uae_reset (0);
     return 0;
@@ -281,8 +280,12 @@ static uae_u32 emulib_GetDisk (uae_u32 drive, uaecptr name)
  */
 static uae_u32 emulib_Debug (void)
 {
+#ifdef DEBUGGER
     activate_debugger ();
     return 1;
+#else
+    return 0;
+#endif
 }
 
 /* We simply find the first "text" hunk, get the offset of its actual code segment (20 bytes away)
@@ -309,29 +312,29 @@ static uae_u32 FindFunctionInObject (uae_u8 *objectptr)
     return 0;
 }
 
-#define        CREATE_NATIVE_FUNC_PTR uae_u32 (* native_func)( uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, \
+#define CREATE_NATIVE_FUNC_PTR uae_u32 (* native_func)( uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, \
                                                 uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32)
-#define        SET_NATIVE_FUNC(x) native_func = (uae_u32 (*)(uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32))(x)
-#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 )
+#define SET_NATIVE_FUNC(x) native_func = (uae_u32 (*)(uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32))(x)
+#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 emulib_ExecuteNativeCode (void)
+/*      We simply find the first function in this .obj data, and execute it. */
+static uae_u32 REGPARAM2 emulib_ExecuteNativeCode (struct regstruct *regs)
 {
 #if 0
-    uaecptr object_AAM = m68k_areg( regs, 0 );
-    uae_u32 d1 = m68k_dreg( regs, 1 );
-    uae_u32 d2 = m68k_dreg( regs, 2 );
-    uae_u32 d3 = m68k_dreg( regs, 3 );
-    uae_u32 d4 = m68k_dreg( regs, 4 );
-    uae_u32 d5 = m68k_dreg( regs, 5 );
-    uae_u32 d6 = m68k_dreg( regs, 6 );
-    uae_u32 d7 = m68k_dreg( regs, 7 );
-    uae_u32 a1 = m68k_areg( regs, 1 );
-    uae_u32 a2 = m68k_areg( regs, 2 );
-    uae_u32 a3 = m68k_areg( regs, 3 );
-    uae_u32 a4 = m68k_areg( regs, 4 );
-    uae_u32 a5 = m68k_areg( regs, 5 );
-    uae_u32 a6 = m68k_areg( regs, 6 );
+    uaecptr object_AAM = m68k_areg (regs, 0);
+    uae_u32 d1 = m68k_dreg (regs, 1);
+    uae_u32 d2 = m68k_dreg (regs, 2);
+    uae_u32 d3 = m68k_dreg (regs, 3);
+    uae_u32 d4 = m68k_dreg (regs, 4);
+    uae_u32 d5 = m68k_dreg (regs, 5);
+    uae_u32 d6 = m68k_dreg (regs, 6);
+    uae_u32 d7 = m68k_dreg (regs, 7);
+    uae_u32 a1 = m68k_areg (regs, 1);
+    uae_u32 a2 = m68k_areg (regs, 2);
+    uae_u32 a3 = m68k_areg (regs, 3);
+    uae_u32 a4 = m68k_areg (regs, 4);
+    uae_u32 a5 = m68k_areg (regs, 5);
+    uae_u32 a6 = m68k_areg (regs, 6);
 
     uae_u8* object_UAM = NULL;
     CREATE_NATIVE_FUNC_PTR;
@@ -351,17 +354,17 @@ static uae_u32 emulib_ExecuteNativeCode (void)
 
 static uae_u32 emulib_Minimize (void)
 {
-    return OSDEP_minimize_uae();
+    return 0; // OSDEP_minimize_uae();
 }
 
-static uae_u32 uaelib_demux (void)
+static uae_u32 REGPARAM2 uaelib_demux (TrapContext *context)
 {
-#define ARG0 (get_long (m68k_areg (regs, 7) + 4))
-#define ARG1 (get_long (m68k_areg (regs, 7) + 8))
-#define ARG2 (get_long (m68k_areg (regs, 7) + 12))
-#define ARG3 (get_long (m68k_areg (regs, 7) + 16))
-#define ARG4 (get_long (m68k_areg (regs, 7) + 20))
-#define ARG5 (get_long (m68k_areg (regs, 7) + 24))
+#define ARG0 (get_long (m68k_areg (&context->regs, 7) + 4))
+#define ARG1 (get_long (m68k_areg (&context->regs, 7) + 8))
+#define ARG2 (get_long (m68k_areg (&context->regs, 7) + 12))
+#define ARG3 (get_long (m68k_areg (&context->regs, 7) + 16))
+#define ARG4 (get_long (m68k_areg (&context->regs, 7) + 20))
+#define ARG5 (get_long (m68k_areg (&context->regs, 7) + 24))
 
     switch (ARG0) {
      case 0: return emulib_GetVersion ();
@@ -373,9 +376,9 @@ static uae_u32 uaelib_demux (void)
      case 6: return emulib_EnableSound (ARG1);
      case 7: return emulib_EnableJoystick (ARG1);
      case 8: return emulib_SetFrameRate (ARG1);
-     case 9: return emulib_ChgCMemSize (ARG1);
-     case 10: return emulib_ChgSMemSize (ARG1);
-     case 11: return emulib_ChgFMemSize (ARG1);
+     case 9: return emulib_ChgCMemSize (&context->regs, ARG1);
+     case 10: return emulib_ChgSMemSize (&context->regs, ARG1);
+     case 11: return emulib_ChgFMemSize (&context->regs, ARG1);
      case 12: return emulib_ChangeLanguage (ARG1);
        /* The next call brings bad luck */
      case 13: return emulib_ExitEmu ();
@@ -383,35 +386,35 @@ static uae_u32 uaelib_demux (void)
      case 15: return emulib_Debug ();
 
 #ifdef PICASSO96
-     case 16: return picasso_FindCard ();
-     case 17: return picasso_FillRect ();
-     case 18: return picasso_SetSwitch ();
-     case 19: return picasso_SetColorArray ();
-     case 20: return picasso_SetDAC ();
-     case 21: return picasso_SetGC ();
-     case 22: return picasso_SetPanning ();
-     case 23: return picasso_CalculateBytesPerRow ();
-     case 24: return picasso_BlitPlanar2Chunky ();
-     case 25: return picasso_BlitRect ();
-     case 26: return picasso_SetDisplay ();
-     case 27: return picasso_BlitTemplate ();
-     case 28: return picasso_BlitRectNoMaskComplete ();
-     case 29: return picasso_InitCard ();
-     case 30: return picasso_BlitPattern ();
-     case 31: return picasso_InvertRect ();
-     case 32: return picasso_BlitPlanar2Direct ();
+     case 16: return picasso_FindCard (&context->regs);
+     case 17: return picasso_FillRect (&context->regs);
+     case 18: return picasso_SetSwitch (&context->regs);
+     case 19: return picasso_SetColorArray (&context->regs);
+     case 20: return picasso_SetDAC (&context->regs);
+     case 21: return picasso_SetGC (&context->regs);
+     case 22: return picasso_SetPanning (&context->regs);
+     case 23: return picasso_CalculateBytesPerRow (&context->regs);
+     case 24: return picasso_BlitPlanar2Chunky (&context->regs);
+     case 25: return picasso_BlitRect (&context->regs);
+     case 26: return picasso_SetDisplay (&context->regs);
+     case 27: return picasso_BlitTemplate (&context->regs);
+     case 28: return picasso_BlitRectNoMaskComplete (&context->regs);
+     case 29: return picasso_InitCard (&context->regs);
+     case 30: return picasso_BlitPattern (&context->regs);
+     case 31: return picasso_InvertRect (&context->regs);
+     case 32: return picasso_BlitPlanar2Direct (&context->regs);
      /* case 34: return picasso_WaitVerticalSync (); handled in asm-code */
      case 35: return allocated_gfxmem ? 1 : 0;
 #ifdef HARDWARE_SPRITE_EMULATION
-     case 36: return picasso_SetSprite ();
-     case 37: return picasso_SetSpritePosition ();
-     case 38: return picasso_SetSpriteImage ();
-     case 39: return picasso_SetSpriteColor ();
+     case 36: return picasso_SetSprite (&context->regs);
+     case 37: return picasso_SetSpritePosition (&context->regs);
+     case 38: return picasso_SetSpriteImage (&context->regs);
+     case 39: return picasso_SetSpriteColor (&context->regs);
 #endif
-     case 40: return picasso_DrawLine ();
+     case 40: return picasso_DrawLine (&context->regs);
 #endif
      case 68: return emulib_Minimize ();
-     case 69: return emulib_ExecuteNativeCode ();
+     case 69: return emulib_ExecuteNativeCode (&context->regs);
 
      case 80: return currprefs.maprom ? currprefs.maprom : 0xffffffff;
      case 81: return cfgfile_uaelib (ARG1, ARG2, ARG3, ARG4);
@@ -432,10 +435,12 @@ void emulib_install (void)
     uaecptr a = here ();
     currprefs.mmkeyboard = 0;
     org (RTAREA_BASE + 0xFF60);
+#if 0
     dw (0x4eb9);
     dw ((RTAREA_BASE >> 16) | get_word(RTAREA_BASE + 36));
     dw (get_word(RTAREA_BASE + 38) + 12);
-    calltrap (deftrap (uaelib_demux));
+#endif
+    calltrap (define_trap (uaelib_demux, 0, ""));
     dw (RTS);
     org (a);
 }
diff --git a/zfile.c b/zfile.c
index 332e12aaab907be193292ee247a07ef172f514bc..46c5ede5b838b315ace949f8c490ee1661a74999 100755 (executable)
--- a/zfile.c
+++ b/zfile.c
@@ -12,7 +12,6 @@
 #include "sysconfig.h"
 #include "sysdeps.h"
 
-#include "config.h"
 #include "options.h"
 #include "zfile.h"
 #include "unzip.h"
@@ -340,9 +339,9 @@ static struct zfile *dms (struct zfile *z)
 }
 #endif
 
-static char *ignoreextensions[] =
+static const char *ignoreextensions[] =
     { ".gif", ".jpg", ".png", ".xml", ".pdf", ".txt", 0 };
-static char *diskimageextensions[] =
+static const char *diskimageextensions[] =
     { ".adf", ".adz", ".ipf", ".fdi", ".exe", 0 };
 
 static int isdiskimage (char *name)
@@ -658,9 +657,9 @@ static struct zfile *unzip (struct zfile *z)
     return z;
 }
 
-static char *plugins_7z[] = { "7z", "rar", "zip", NULL };
-static char *plugins_7z_x[] = { "7z", "Rar!", "MK" };
-static int plugins_7z_t[] = { ArchiveFormat7Zip, ArchiveFormatRAR, ArchiveFormatZIP };
+static const char *plugins_7z[] = { "7z", "rar", "zip", NULL };
+static const char *plugins_7z_x[] = { "7z", "Rar!", "MK" };
+static const int plugins_7z_t[] = { ArchiveFormat7Zip, ArchiveFormatRAR, ArchiveFormatZIP };
 
 static int iszip (struct zfile *z)
 {