Index: firmware/5200/regs.c
===================================================================
--- firmware/5200/regs.c	(revision 205)
+++ firmware/5200/regs.c	(nonexistent)
@@ -1,62 +0,0 @@
-#include "regs.h"
-#include "memory.h"
-
-int volatile * zpu_in1 = (int *)(0*4+config_regbase);
-int volatile * zpu_in2 = (int *)(1*4+config_regbase);
-int volatile * zpu_in3 = (int *)(2*4+config_regbase);
-int volatile * zpu_in4 = (int *)(3*4+config_regbase);
-
-int volatile * zpu_out1 = (int *)(4*4+config_regbase);
-int volatile * zpu_out2 = (int *)(5*4+config_regbase);
-int volatile * zpu_out3 = (int *)(6*4+config_regbase);
-int volatile * zpu_out4 = (int *)(7*4+config_regbase);
-
-int volatile * zpu_pause = (int *)(8*4+config_regbase);
-
-int volatile * zpu_spi_data = (int *)(9*4+config_regbase);
-int volatile * zpu_spi_state = (int *)(10*4+config_regbase);
-
-int volatile * zpu_sio = (int *)(11*4+config_regbase);
-
-int volatile * zpu_board = (int *)(12*4+config_regbase);
-
-int volatile * zpu_spi_dma = (int *)(13*4+config_regbase);
-
-unsigned char volatile * zpu_pokey_audf0 = (unsigned char *)(0x10*4+config_regbase);
-unsigned char volatile * zpu_pokey_audc0 = (unsigned char *)(0x11*4+config_regbase);
-unsigned char volatile * zpu_pokey_audf1 = (unsigned char *)(0x12*4+config_regbase);
-unsigned char volatile * zpu_pokey_audc1 = (unsigned char *)(0x13*4+config_regbase);
-unsigned char volatile * zpu_pokey_audf2 = (unsigned char *)(0x14*4+config_regbase);
-unsigned char volatile * zpu_pokey_audc2 = (unsigned char *)(0x15*4+config_regbase);
-unsigned char volatile * zpu_pokey_audf3 = (unsigned char *)(0x16*4+config_regbase);
-unsigned char volatile * zpu_pokey_audc3 = (unsigned char *)(0x17*4+config_regbase);
-
-unsigned char volatile * zpu_pokey_audctl = (unsigned char *)(0x18*4+config_regbase);
-
-unsigned char volatile * zpu_pokey_skrest = (unsigned char *)(0x1a*4+config_regbase);
-unsigned char volatile * zpu_pokey_serout = (unsigned char *)(0x1d*4+config_regbase);
-unsigned char volatile * zpu_pokey_irqen = (unsigned char *)(0x1e*4+config_regbase);
-unsigned char volatile * zpu_pokey_skctl = (unsigned char *)(0x1f*4+config_regbase);
-
-unsigned char volatile * atari_colbk = (unsigned char *)(0xc01a + atari_regbase);
-unsigned char volatile * atari_colpf1 = (unsigned char *)(0xc017 + atari_regbase);
-unsigned char volatile * atari_colpf2 = (unsigned char *)(0xc018 + atari_regbase);
-unsigned char volatile * atari_colpf3 = (unsigned char *)(0xc019 + atari_regbase);
-unsigned char volatile * atari_colpf0 = (unsigned char *)(0xc016 + atari_regbase);
-unsigned char volatile * atari_prior = (unsigned char *)(0xc01b + atari_regbase);
-unsigned char volatile * atari_trig0 = (unsigned char *)(0xc010 + atari_regbase);
-
-unsigned char volatile * atari_porta = (unsigned char *)(0xd300 + atari_regbase);
-unsigned char volatile * atari_portb = (unsigned char *)(0xd301 + atari_regbase);
-
-unsigned char volatile * atari_chbase = (unsigned char *)(0xd409 + atari_regbase);
-unsigned char volatile * atari_chactl = (unsigned char *)(0xd401 + atari_regbase);
-unsigned char volatile * atari_dmactl = (unsigned char *)(0xd400 + atari_regbase);
-unsigned char volatile * atari_dlistl = (unsigned char *)(0xd402 + atari_regbase);
-unsigned char volatile * atari_dlisth = (unsigned char *)(0xd403 + atari_regbase);
-unsigned char volatile * atari_nmien = (unsigned char *)(0xd40e + atari_regbase);
-
-unsigned char volatile * atari_skctl = (unsigned char *)(0xe80f + atari_regbase);
-unsigned char volatile * atari_kbcode = (unsigned char *)(0xe809 + atari_regbase);
-unsigned char volatile * atari_random = (unsigned char *)(0xe80a + atari_regbase);
-
Index: firmware/a800/regs.c
===================================================================
--- firmware/a800/regs.c	(revision 205)
+++ firmware/a800/regs.c	(nonexistent)
@@ -1,58 +0,0 @@
-#include "regs.h"
-#include "memory.h"
-
-int volatile * zpu_in1 = (int *)(0*4+config_regbase);
-int volatile * zpu_in2 = (int *)(1*4+config_regbase);
-int volatile * zpu_in3 = (int *)(2*4+config_regbase);
-int volatile * zpu_in4 = (int *)(3*4+config_regbase);
-
-int volatile * zpu_out1 = (int *)(4*4+config_regbase);
-int volatile * zpu_out2 = (int *)(5*4+config_regbase);
-int volatile * zpu_out3 = (int *)(6*4+config_regbase);
-int volatile * zpu_out4 = (int *)(7*4+config_regbase);
-
-int volatile * zpu_pause = (int *)(8*4+config_regbase);
-
-int volatile * zpu_spi_data = (int *)(9*4+config_regbase);
-int volatile * zpu_spi_state = (int *)(10*4+config_regbase);
-
-int volatile * zpu_sio = (int *)(11*4+config_regbase);
-
-int volatile * zpu_board = (int *)(12*4+config_regbase);
-
-int volatile * zpu_spi_dma = (int *)(13*4+config_regbase);
-
-unsigned char volatile * zpu_pokey_audf0 = (unsigned char *)(0x10*4+config_regbase);
-unsigned char volatile * zpu_pokey_audc0 = (unsigned char *)(0x11*4+config_regbase);
-unsigned char volatile * zpu_pokey_audf1 = (unsigned char *)(0x12*4+config_regbase);
-unsigned char volatile * zpu_pokey_audc1 = (unsigned char *)(0x13*4+config_regbase);
-unsigned char volatile * zpu_pokey_audf2 = (unsigned char *)(0x14*4+config_regbase);
-unsigned char volatile * zpu_pokey_audc2 = (unsigned char *)(0x15*4+config_regbase);
-unsigned char volatile * zpu_pokey_audf3 = (unsigned char *)(0x16*4+config_regbase);
-unsigned char volatile * zpu_pokey_audc3 = (unsigned char *)(0x17*4+config_regbase);
-
-unsigned char volatile * zpu_pokey_audctl = (unsigned char *)(0x18*4+config_regbase);
-
-unsigned char volatile * zpu_pokey_skrest = (unsigned char *)(0x1a*4+config_regbase);
-unsigned char volatile * zpu_pokey_serout = (unsigned char *)(0x1d*4+config_regbase);
-unsigned char volatile * zpu_pokey_irqen = (unsigned char *)(0x1e*4+config_regbase);
-unsigned char volatile * zpu_pokey_skctl = (unsigned char *)(0x1f*4+config_regbase);
-
-unsigned char volatile * atari_nmien = (unsigned char *)(0xd40e + atari_regbase);
-unsigned char volatile * atari_dlistl = (unsigned char *)(0xd402 + atari_regbase);
-unsigned char volatile * atari_dlisth = (unsigned char *)(0xd403 + atari_regbase);
-unsigned char volatile * atari_colbk = (unsigned char *)(0xd01a + atari_regbase);
-unsigned char volatile * atari_colpf1 = (unsigned char *)(0xd017 + atari_regbase);
-unsigned char volatile * atari_colpf2 = (unsigned char *)(0xd018 + atari_regbase);
-unsigned char volatile * atari_colpf3 = (unsigned char *)(0xd019 + atari_regbase);
-unsigned char volatile * atari_colpf0 = (unsigned char *)(0xd016 + atari_regbase);
-unsigned char volatile * atari_prior = (unsigned char *)(0xd01b + atari_regbase);
-unsigned char volatile * atari_random = (unsigned char *)(0xd20a + atari_regbase);
-unsigned char volatile * atari_porta = (unsigned char *)(0xd300 + atari_regbase);
-unsigned char volatile * atari_portb = (unsigned char *)(0xd301 + atari_regbase);
-unsigned char volatile * atari_trig0 = (unsigned char *)(0xd010 + atari_regbase);
-unsigned char volatile * atari_chbase = (unsigned char *)(0xd409 + atari_regbase);
-unsigned char volatile * atari_chactl = (unsigned char *)(0xd401 + atari_regbase);
-unsigned char volatile * atari_dmactl = (unsigned char *)(0xd400 + atari_regbase);
-unsigned char volatile * atari_skctl = (unsigned char *)(0xd20f + atari_regbase);
-
Index: firmware/Makefile
===================================================================
--- firmware/Makefile	(revision 205)
+++ firmware/Makefile	(revision 206)
@@ -54,9 +54,9 @@
 COMMON_SRC = cartridge.c fileutils.c fileselector.c pokey/uart.c hexdump.c printf/printf.c fat/pff_file.c fat/pff.c common/utils.c
 SDCARD_SRC = sd_direct/diskio_mmc.c sd_direct/spi.c sd_direct/mmc2.c
 A800_SRC_LIGHT = a800/freeze.c  a800/mainmenu.c atari_drive_emulator.c
-A800_SRC = ${A800_SRC_LIGHT} a800/joystick.c a800/regs.c
+A800_SRC = ${A800_SRC_LIGHT} a800/joystick.c libgcc_divmod.c
 5200_SRC_LIGHT = 5200/freeze.c  5200/mainmenu.c
-5200_SRC = ${5200_SRC_LIGHT} 5200/joystick.c 5200/regs.c
+5200_SRC = ${5200_SRC_LIGHT} 5200/joystick.c
 
 AEON_LITE_PRJ = AEON_LITE
 AEON_LITE_SRC = $(COMMON_SRC) $(SDCARD_SRC) $(A800_SRC) de1/dirs.c
@@ -110,9 +110,12 @@
 
 HOST_CFLAGS += -I. -Isd_direct -Iprintf -Ifat -Icommon -Isdram_common -DDISABLE_UART_RX
 
-LFLAGS  = -nostartfiles -Wl,--relax -g -Os -Wl,-Map=out.map
+LFLAGS  = -nostartfiles -nostdlib -Wl,--relax -g -Os -Wl,-Map=out.map
+LFLAGS_5200  = -nostartfiles -Wl,--relax -g -Os -Wl,-Map=out.map
 #LFLAGS  = -nostartfiles -Os
 
+CFLAGS_5200 = $(CFLAGS) -DFIRMWARE_5200
+HOST_CFLAGS_5200 = $(HOST_CFLAGS) -DFIRMWARE_5200
 
 # Our target.
 all: mcc mist de1 aeon_lite chameleon  de1_5200 mist_5200
@@ -166,7 +169,7 @@
 	$(LD) $(LFLAGS) -T $(LINKMAP) -o $@ $+ $(LIBS)
 
 $(DE1_5200_PRJ).elf: $(MINSTARTUP_OBJ) $(DE1_5200_OBJ)
-	$(LD) $(LFLAGS) -T $(LINKMAP) -o $@ $+ $(LIBS)
+	$(LD) $(LFLAGS_5200) -T $(LINKMAP) -o $@ $+ $(LIBS)
 
 $(CHAMELEON_PRJ).elf: $(MINSTARTUP_OBJ) $(CHAMELEON_OBJ)
 	$(LD) $(LFLAGS) -T $(LINKMAP) -o $@ $+ $(LIBS)
@@ -178,7 +181,7 @@
 	$(LD) $(LFLAGS) -T $(LINKMAP) -o $@ $+ $(LIBS)
 
 $(MIST_5200_PRJ).elf: $(MINSTARTUP_OBJ) $(MIST_5200_OBJ)
-	$(LD) $(LFLAGS) -T $(LINKMAP) -o $@ $+ $(LIBS)
+	$(LD) $(LFLAGS_5200) -T $(LINKMAP) -o $@ $+ $(LIBS)
 
 $(LINUXSIM_EXE): $(LINUXSIM_OBJ)
 	$(HOST_LD) $(HOST_LDFLAGS) -o $@ $+
@@ -200,7 +203,7 @@
 
 $(DE1_5200_BUILD_DIR)/%.o: %.c Makefile
 	mkdir -p `dirname $@`
-	$(CC) -I$(DE1_5200_DIR) $(CFLAGS)  -o $@ -c $<
+	$(CC) -I$(DE1_5200_DIR) $(CFLAGS_5200)  -o $@ -c $<
 
 $(MCC_BUILD_DIR)/%.o: %.c Makefile
 	mkdir -p `dirname $@`
@@ -212,7 +215,7 @@
 
 $(MIST_5200_BUILD_DIR)/%.o: %.c Makefile
 	mkdir -p `dirname $@`
-	$(CC) -I$(MIST_5200_DIR) $(CFLAGS)  -o $@ -c $<
+	$(CC) -I$(MIST_5200_DIR) $(CFLAGS_5200)  -o $@ -c $<
 
 $(LINUXSIM_BUILD_DIR)/%.o: %.c Makefile
 	@mkdir -p `dirname $@`
@@ -220,7 +223,7 @@
 
 $(LINUXSIM_5200_BUILD_DIR)/%.o: %.c Makefile
 	@mkdir -p `dirname $@`
-	$(HOST_CC) -I$(LINUXSIM_DIR) $(HOST_CFLAGS)  -o $@ -c $<
+	$(HOST_CC) -I$(LINUXSIM_DIR) $(HOST_CFLAGS_5200)  -o $@ -c $<
 
 $(BUILD_DIR)/%.o: %.s
 	$(AS) -o $@ $<
Index: firmware/cartridge.c
===================================================================
--- firmware/cartridge.c	(revision 205)
+++ firmware/cartridge.c	(revision 206)
@@ -110,14 +110,11 @@
 		LOG("illegal cart type %d\n", carttype);
 		return 0;
 	}
-	// read data in 8k chunks
-	unsigned int block;
-	for(block = 0; block < def->size >> 3; block++) {
-		ok = file_read(file, CARTRIDGE_MEM + block * 0x2000, 0x2000, &len);
-		if (ok != SimpleFile_OK || len != 0x2000) {
-			LOG("cannot read cart data\n");
-			return 0;
-		}
+	unsigned int byte_len = (unsigned int) def->size << 10;
+	ok = file_read(file, CARTRIDGE_MEM, byte_len, &len);
+	if (ok != SimpleFile_OK || len != byte_len) {
+		LOG("cannot read cart data\n");
+		return 0;
 	}
 	LOG("cart type: %d size: %dk\n",
 		 def->mode, def->size);
Index: firmware/libgcc_divmod.c
===================================================================
--- firmware/libgcc_divmod.c	(nonexistent)
+++ firmware/libgcc_divmod.c	(revision 206)
@@ -0,0 +1,86 @@
+unsigned long
+udivmodsi4(unsigned long num, unsigned long den, int modwanted)
+{
+  unsigned long bit = 1;
+  unsigned long res = 0;
+
+  while (den < num && bit && !(den & (1L<<31)))
+    {
+      den <<=1;
+      bit <<=1;
+    }
+  while (bit)
+    {
+      if (num >= den)
+        {
+          num -= den;
+          res |= bit;
+        }
+      bit >>=1;
+      den >>=1;
+    }
+  if (modwanted) return num;
+  return res;
+}
+
+long
+__udivsi3 (long a, long b)
+{
+  return udivmodsi4 (a, b, 0);
+}
+
+long
+__umodsi3 (long a, long b)
+{
+  return udivmodsi4 (a, b, 1);
+}
+
+long
+__divsi3 (long a, long b)
+{
+  int neg = 0;
+  long res;
+
+  if (a < 0)
+    {
+      a = -a;
+      neg = !neg;
+    }
+
+  if (b < 0)
+    {
+      b = -b;
+      neg = !neg;
+    }
+
+  res = udivmodsi4 (a, b, 0);
+
+  if (neg)
+    res = -res;
+
+  return res;
+}
+
+long
+__modsi3 (long a, long b)
+{
+  int neg = 0;
+  long res;
+
+  if (a < 0)
+    {
+      a = -a;
+      neg = 1;
+    }
+
+  if (b < 0)
+    b = -b;
+
+  res = udivmodsi4 (a, b, 1);
+
+  if (neg)
+    res = -res;
+
+  return res;
+}
+
Index: firmware/linux/linux_memory.c
===================================================================
--- firmware/linux/linux_memory.c	(revision 205)
+++ firmware/linux/linux_memory.c	(revision 206)
@@ -4,61 +4,6 @@
 #include "memory.h"
 #include "linux_memory.h"
 
-int volatile * zpu_in1;
-int volatile * zpu_in2;
-int volatile * zpu_in3;
-int volatile * zpu_in4;
-
-int volatile * zpu_out1;
-int volatile * zpu_out2;
-int volatile * zpu_out3;
-int volatile * zpu_out4;
-
-int volatile * zpu_pause;
-
-int volatile * zpu_spi_data;
-int volatile * zpu_spi_state;
-
-int volatile * zpu_sio;
-
-int volatile * zpu_board;
-
-int volatile * zpu_spi_dma;
-
-unsigned char volatile * zpu_pokey_audf0;
-unsigned char volatile * zpu_pokey_audc0;
-unsigned char volatile * zpu_pokey_audf1;
-unsigned char volatile * zpu_pokey_audc1;
-unsigned char volatile * zpu_pokey_audf2;
-unsigned char volatile * zpu_pokey_audc2;
-unsigned char volatile * zpu_pokey_audf3;
-unsigned char volatile * zpu_pokey_audc3;
-
-unsigned char volatile * zpu_pokey_audctl;
-
-unsigned char volatile * zpu_pokey_skrest;
-unsigned char volatile * zpu_pokey_serout;
-unsigned char volatile * zpu_pokey_irqen;
-unsigned char volatile * zpu_pokey_skctl;
-
-unsigned char volatile * atari_nmien;
-unsigned char volatile * atari_dlistl;
-unsigned char volatile * atari_dlisth;
-unsigned char volatile * atari_colbk;
-unsigned char volatile * atari_colpf1;
-unsigned char volatile * atari_colpf2;
-unsigned char volatile * atari_colpf3;
-unsigned char volatile * atari_colpf0;
-unsigned char volatile * atari_prior;
-unsigned char volatile * atari_random;
-unsigned char volatile * atari_porta;
-unsigned char volatile * atari_portb;
-unsigned char volatile * atari_trig0;
-unsigned char volatile * atari_chbase;
-unsigned char volatile * atari_chactl;
-unsigned char volatile * atari_dmactl;
-unsigned char volatile * atari_skctl;
-
 void* SRAM_BASE;
 void* SDRAM_BASE;
 void* atari_regbase;
@@ -95,61 +40,6 @@
 	config_regbase = config_memory;
 	CARTRIDGE_MEM = cartridge_memory;
 
-	zpu_in1 = (int *)(0*4+config_regbase);
-	zpu_in2 = (int *)(1*4+config_regbase);
-	zpu_in3 = (int *)(2*4+config_regbase);
-	zpu_in4 = (int *)(3*4+config_regbase);
-
-	zpu_out1 = (int *)(4*4+config_regbase);
-	zpu_out2 = (int *)(5*4+config_regbase);
-	zpu_out3 = (int *)(6*4+config_regbase);
-	zpu_out4 = (int *)(7*4+config_regbase);
-
-	zpu_pause = (int *)(8*4+config_regbase);
-
-	zpu_spi_data = (int *)(9*4+config_regbase);
-	zpu_spi_state = (int *)(10*4+config_regbase);
-
-	zpu_sio = (int *)(11*4+config_regbase);
-
-	zpu_board = (int *)(12*4+config_regbase);
-
-	zpu_spi_dma = (int *)(13*4+config_regbase);
-
-	zpu_pokey_audf0 = (unsigned char *)(0x10*4+config_regbase);
-	zpu_pokey_audc0 = (unsigned char *)(0x11*4+config_regbase);
-	zpu_pokey_audf1 = (unsigned char *)(0x12*4+config_regbase);
-	zpu_pokey_audc1 = (unsigned char *)(0x13*4+config_regbase);
-	zpu_pokey_audf2 = (unsigned char *)(0x14*4+config_regbase);
-	zpu_pokey_audc2 = (unsigned char *)(0x15*4+config_regbase);
-	zpu_pokey_audf3 = (unsigned char *)(0x16*4+config_regbase);
-	zpu_pokey_audc3 = (unsigned char *)(0x17*4+config_regbase);
-
-	zpu_pokey_audctl = (unsigned char *)(0x18*4+config_regbase);
-
-	zpu_pokey_skrest = (unsigned char *)(0x1a*4+config_regbase);
-	zpu_pokey_serout = (unsigned char *)(0x1d*4+config_regbase);
-	zpu_pokey_irqen = (unsigned char *)(0x1e*4+config_regbase);
-	zpu_pokey_skctl = (unsigned char *)(0x1f*4+config_regbase);
-
-	atari_nmien = (unsigned char *)(0xd40e + atari_regbase);
-	atari_dlistl = (unsigned char *)(0xd402 + atari_regbase);
-	atari_dlisth = (unsigned char *)(0xd403 + atari_regbase);
-	atari_colbk = (unsigned char *)(0xd01a + atari_regbase);
-	atari_colpf1 = (unsigned char *)(0xd017 + atari_regbase);
-	atari_colpf2 = (unsigned char *)(0xd018 + atari_regbase);
-	atari_colpf3 = (unsigned char *)(0xd019 + atari_regbase);
-	atari_colpf0 = (unsigned char *)(0xd016 + atari_regbase);
-	atari_prior = (unsigned char *)(0xd01b + atari_regbase);
-	atari_random = (unsigned char *)(0xd20a + atari_regbase);
-	atari_porta = (unsigned char *)(0xd300 + atari_regbase);
-	atari_portb = (unsigned char *)(0xd301 + atari_regbase);
-	atari_trig0 = (unsigned char *)(0xd010 + atari_regbase);
-	atari_chbase = (unsigned char *)(0xd409 + atari_regbase);
-	atari_chactl = (unsigned char *)(0xd401 + atari_regbase);
-	atari_dmactl = (unsigned char *)(0xd400 + atari_regbase);
-	atari_skctl = (unsigned char *)(0xd20f + atari_regbase);
-
 	// command line is high
 	*zpu_sio = 1;
 	// no trigger pressed
Index: firmware/regs.h
===================================================================
--- firmware/regs.h	(revision 205)
+++ firmware/regs.h	(revision 206)
@@ -1,59 +1,83 @@
 #ifndef regs_h
 #define regs_h
+#include "memory.h"
 
 static const int screen_address = 11328;
 
-extern int volatile * zpu_in1;
-extern int volatile * zpu_in2;
-extern int volatile * zpu_in3;
-extern int volatile * zpu_in4;
+#define zpu_in1 ((int volatile *)(0*4+config_regbase))
+#define zpu_in2 ((int volatile *)(1*4+config_regbase))
+#define zpu_in3 ((int volatile *)(2*4+config_regbase))
+#define zpu_in4 ((int volatile *)(3*4+config_regbase))
 
-extern int volatile * zpu_out1;
-extern int volatile * zpu_out2;
-extern int volatile * zpu_out3;
-extern int volatile * zpu_out4;
+#define zpu_out1 ((int volatile *)(4*4+config_regbase))
+#define zpu_out2 ((int volatile *)(5*4+config_regbase))
+#define zpu_out3 ((int volatile *)(6*4+config_regbase))
+#define zpu_out4 ((int volatile *)(7*4+config_regbase))
 
-extern int volatile * zpu_pause;
-extern int volatile * zpu_spi_data;
-extern int volatile * zpu_spi_state;
-extern int volatile * zpu_sio;
-extern int volatile * zpu_board;
+#define zpu_pause ((int volatile *)(8*4+config_regbase))
 
-extern int volatile * zpu_spi_dma;
- 
-extern unsigned char volatile * zpu_pokey_audf0;
-extern unsigned char volatile * zpu_pokey_audc0;
-extern unsigned char volatile * zpu_pokey_audf1;
-extern unsigned char volatile * zpu_pokey_audc1;
-extern unsigned char volatile * zpu_pokey_audf2;
-extern unsigned char volatile * zpu_pokey_audc2;
-extern unsigned char volatile * zpu_pokey_audf3;
-extern unsigned char volatile * zpu_pokey_audc3;
- 
-extern unsigned char volatile * zpu_pokey_audctl;
- 
-extern unsigned char volatile * zpu_pokey_skrest;
-extern unsigned char volatile * zpu_pokey_serout;
-extern unsigned char volatile * zpu_pokey_irqen;
-extern unsigned char volatile * zpu_pokey_skctl;
+#define zpu_spi_data ((int volatile *)(9*4+config_regbase))
+#define zpu_spi_state ((int volatile *)(10*4+config_regbase))
 
-extern unsigned char volatile * atari_nmien;
-extern unsigned char volatile * atari_dlistl;
-extern unsigned char volatile * atari_dlisth;
-extern unsigned char volatile * atari_colbk;
-extern unsigned char volatile * atari_colpf1;
-extern unsigned char volatile * atari_colpf2;
-extern unsigned char volatile * atari_colpf3;
-extern unsigned char volatile * atari_colpf0;
-extern unsigned char volatile * atari_prior;
-extern unsigned char volatile * atari_random;
-extern unsigned char volatile * atari_porta;
-extern unsigned char volatile * atari_portb;
-extern unsigned char volatile * atari_trig0;
-extern unsigned char volatile * atari_chbase;
-extern unsigned char volatile * atari_chactl;
-extern unsigned char volatile * atari_dmactl;
-extern unsigned char volatile * atari_skctl;
-extern unsigned char volatile * atari_kbcode;
+#define zpu_sio ((int volatile *)(11*4+config_regbase))
 
+#define zpu_board ((int volatile *)(12*4+config_regbase))
+
+#define zpu_spi_dma ((int volatile *)(13*4+config_regbase))
+
+#define zpu_pokey_audf0 ((unsigned char volatile *)(0x10*4+config_regbase))
+#define zpu_pokey_audc0 ((unsigned char volatile *)(0x11*4+config_regbase))
+#define zpu_pokey_audf1 ((unsigned char volatile *)(0x12*4+config_regbase))
+#define zpu_pokey_audc1 ((unsigned char volatile *)(0x13*4+config_regbase))
+#define zpu_pokey_audf2 ((unsigned char volatile *)(0x14*4+config_regbase))
+#define zpu_pokey_audc2 ((unsigned char volatile *)(0x15*4+config_regbase))
+#define zpu_pokey_audf3 ((unsigned char volatile *)(0x16*4+config_regbase))
+#define zpu_pokey_audc3 ((unsigned char volatile *)(0x17*4+config_regbase))
+
+#define zpu_pokey_audctl ((unsigned char volatile *)(0x18*4+config_regbase))
+
+#define zpu_pokey_skrest ((unsigned char volatile *)(0x1a*4+config_regbase))
+#define zpu_pokey_serout ((unsigned char volatile *)(0x1d*4+config_regbase))
+#define zpu_pokey_irqen ((unsigned char volatile *)(0x1e*4+config_regbase))
+#define zpu_pokey_skctl ((unsigned char volatile *)(0x1f*4+config_regbase))
+
+#define atari_nmien ((unsigned char volatile *)(0xd40e + atari_regbase))
+#define atari_dlistl ((unsigned char volatile *)(0xd402 + atari_regbase))
+#define atari_dlisth ((unsigned char volatile *)(0xd403 + atari_regbase))
+
+#define atari_porta ((unsigned char volatile *)(0xd300 + atari_regbase))
+#define atari_portb ((unsigned char volatile *)(0xd301 + atari_regbase))
+#define atari_trig0 ((unsigned char volatile *)(0xd010 + atari_regbase))
+#define atari_chbase ((unsigned char volatile *)(0xd409 + atari_regbase))
+#define atari_chactl ((unsigned char volatile *)(0xd401 + atari_regbase))
+#define atari_dmactl ((unsigned char volatile *)(0xd400 + atari_regbase))
+
+#ifdef FIRMWARE_5200
+// 5200: GTIA and POKEY are on different addresses
+#define atari_colbk ((unsigned char volatile *)(0xc01a + atari_regbase))
+#define atari_colpf1 ((unsigned char volatile *)(0xc017 + atari_regbase))
+#define atari_colpf2 ((unsigned char volatile *)(0xc018 + atari_regbase))
+#define atari_colpf3 ((unsigned char volatile *)(0xc019 + atari_regbase))
+#define atari_colpf0 ((unsigned char volatile *)(0xc016 + atari_regbase))
+#define atari_prior ((unsigned char volatile *)(0xc01b + atari_regbase))
+
+#define atari_skctl ((unsigned char volatile *)(0xe80f + atari_regbase))
+#define atari_kbcode ((unsigned char volatile *)(0xe809 + atari_regbase))
+#define atari_random ((unsigned char volatile *)(0xe80a + atari_regbase))
+
+#else
+
+#define atari_colbk ((unsigned char volatile *)(0xd01a + atari_regbase))
+#define atari_colpf1 ((unsigned char volatile *)(0xd017 + atari_regbase))
+#define atari_colpf2 ((unsigned char volatile *)(0xd018 + atari_regbase))
+#define atari_colpf3 ((unsigned char volatile *)(0xd019 + atari_regbase))
+#define atari_colpf0 ((unsigned char volatile *)(0xd016 + atari_regbase))
+#define atari_prior ((unsigned char volatile *)(0xd01b + atari_regbase))
+
+#define atari_skctl ((unsigned char volatile *)(0xd20f + atari_regbase))
+#define atari_kbcode ((unsigned char volatile *)(0xd209 + atari_regbase))
+#define atari_random ((unsigned char volatile *)(0xd20a + atari_regbase))
+
+#endif
+
 #endif // regs_h
