From 8f2ab2f0729a67ae43550990db0691fa2829bf26 Mon Sep 17 00:00:00 2001 From: Aaron Culliney Date: Sun, 27 Oct 2019 14:24:30 -0700 Subject: [PATCH] Compress cpu65_vmem_* function tables to save space --- src/arm/cpu-regs.h | 2 + src/arm/cpu.S | 42 +- src/arm/glue-prologue.h | 3 + src/audio/mockingboard.c | 8 +- src/audio/speaker.c | 3 +- src/audio/speaker.h | 1 + src/cpu-supp.c | 4 +- src/cpu.h | 4 +- src/disk.c | 14 +- src/disk.h | 5 + src/glue.h | 2 + src/interface.c | 1 - src/vm.c | 913 ++++++++++++++++++++++----------------- src/vm.h | 34 +- src/x86/cpu-regs.h | 17 +- src/x86/cpu.S | 25 +- src/x86/glue-prologue.h | 3 + 17 files changed, 617 insertions(+), 464 deletions(-) diff --git a/src/arm/cpu-regs.h b/src/arm/cpu-regs.h index 5c6b9f61..1d9e54c8 100644 --- a/src/arm/cpu-regs.h +++ b/src/arm/cpu-regs.h @@ -46,6 +46,7 @@ # define wr0 w0 /* scratch/"important byte" */ # define xr1 x1 /* scratch */ # define wr1 w1 /* scratch */ +# define xr9 x2 /* scratch */ # define wr9 w2 /* scratch */ # define xr12 x5 /* overloaded both scratch */ @@ -87,6 +88,7 @@ # define wr0 r0 /* scratch/"important byte" */ # define xr1 r1 /* scratch */ # define wr1 r1 /* scratch */ +# define xr9 r9 /* scratch */ # define wr9 r9 /* scratch */ // NOTE: these need to be preserved in subroutine (C) invocations ... */ diff --git a/src/arm/cpu.S b/src/arm/cpu.S index a7599068..80b2d74c 100644 --- a/src/arm/cpu.S +++ b/src/arm/cpu.S @@ -129,8 +129,9 @@ #define GetFromPC_B \ mov EffectiveAddr, PC_Reg; \ + lsr wr1, EffectiveAddr, #8; \ IncUint16(PC_Reg) \ - ldr xr1, [reg_vmem_r, xEffectiveAddr, LSL PTR_SHIFT]; \ + ldr xr1, [reg_vmem_r, xr1, LSL PTR_SHIFT]; \ BLX xr1; \ TRACE_ARG @@ -140,14 +141,16 @@ #define GetFromPC_W \ mov EffectiveAddr, PC_Reg; \ + lsr wr1, EffectiveAddr, #8; \ AddUint16(PC_Reg, #2) \ lsl PC_Reg, PC_Reg, #16; \ - ldr xr1, [reg_vmem_r, xEffectiveAddr, LSL PTR_SHIFT]; \ + ldr xr1, [reg_vmem_r, xr1, LSL PTR_SHIFT]; \ BLX xr1; \ TRACE_ARG \ orr word_reg, word_reg, wr0; \ IncUint16(EffectiveAddr) \ - ldr xr1, [reg_vmem_r, xEffectiveAddr, LSL PTR_SHIFT]; \ + lsr wr1, EffectiveAddr, #8; \ + ldr xr1, [reg_vmem_r, xr1, LSL PTR_SHIFT]; \ BLX xr1; \ TRACE_ARG; \ lsl wr0, wr0, #8; /* hi byte */ \ @@ -168,20 +171,23 @@ #define GetFromEA_B \ /* Record CPU read: */ \ - ldrb wr1, [reg_args, #CPU65_RW]; \ - orr wr1, wr1, #1; \ - strb wr1, [reg_args, #CPU65_RW]; \ + lsr wr1, EffectiveAddr, #8; \ + ldrb wr9, [reg_args, #CPU65_RW]; \ + orr wr9, wr9, #1; \ + strb wr9, [reg_args, #CPU65_RW]; \ \ - ldr xr1, [reg_vmem_r, xEffectiveAddr, LSL PTR_SHIFT]; \ + ldr xr1, [reg_vmem_r, xr1, LSL PTR_SHIFT]; \ BLX xr1; #define GetFromEA_W \ + lsr wr1, EffectiveAddr, #8; \ lsl PC_Reg, PC_Reg, #16; \ - ldr xr1, [reg_vmem_r, xEffectiveAddr, LSL PTR_SHIFT]; \ + ldr xr1, [reg_vmem_r, xr1, LSL PTR_SHIFT]; \ BLX xr1; \ orr word_reg, word_reg, wr0; \ IncUint16(EffectiveAddr) \ - ldr xr1, [reg_vmem_r, xEffectiveAddr, LSL PTR_SHIFT]; \ + lsr wr1, EffectiveAddr, #8; \ + ldr xr1, [reg_vmem_r, xr1, LSL PTR_SHIFT]; \ BLX xr1; \ lsl wr0, wr0, #8; /* hi byte */ \ orr wr0, word_reg, wr0; \ @@ -191,18 +197,19 @@ #define PutToEA_B \ /* Record CPU write: */ \ + lsr wr1, EffectiveAddr, #8; \ strb wr0, [reg_args, #CPU65_D]; \ - ldrb wr1, [reg_args, #CPU65_RW]; \ - orr wr1, wr1, #2; \ - strb wr1, [reg_args, #CPU65_RW]; \ - \ - ldr xr1, [reg_args, #CPU65_VMEM_W]; \ - ldr xr1, [xr1, xEffectiveAddr, LSL PTR_SHIFT]; \ + ldrb wr9, [reg_args, #CPU65_RW]; \ + orr wr9, wr9, #2; \ + strb wr9, [reg_args, #CPU65_RW]; \ + ldr xr9, [reg_args, #CPU65_VMEM_W]; \ + ldr xr1, [xr9, xr1, LSL PTR_SHIFT]; \ BLX xr1; #define GetFromMem_B(x) \ mov EffectiveAddr, x; \ - ldr xr1, [reg_vmem_r, xEffectiveAddr, LSL PTR_SHIFT]; \ + lsr wr1, EffectiveAddr, #8; \ + ldr xr1, [reg_vmem_r, xr1, LSL PTR_SHIFT]; \ BLX xr1; #define GetFromMem_W(x) \ @@ -337,7 +344,8 @@ #if CPU_TRACING #define GetImm \ _GetImm \ - ldr xr1, [reg_vmem_r, xEffectiveAddr, LSL PTR_SHIFT]; \ + lsr wr1, EffectiveAddr, #8; \ + ldr xr1, [reg_vmem_r, xr1, LSL PTR_SHIFT]; \ BLX xr1; \ TRACE_ARG #else diff --git a/src/arm/glue-prologue.h b/src/arm/glue-prologue.h index d84b0004..2567fd04 100644 --- a/src/arm/glue-prologue.h +++ b/src/arm/glue-prologue.h @@ -111,6 +111,9 @@ ENTRY(func) ldrb wr0, [reg_args, x ## off]; \ _GLUE_RET #define GLUE_INLINE_READ(func,off) _GLUE_INLINE_READ(func,#,off) +#define GLUE_NOP(func) \ +ENTRY(func) _GLUE_RET + #define GLUE_C_WRITE(func) \ ENTRY(func) _GLUE_REG_SAVE0; \ diff --git a/src/audio/mockingboard.c b/src/audio/mockingboard.c index 3e3b7379..9ce82633 100644 --- a/src/audio/mockingboard.c +++ b/src/audio/mockingboard.c @@ -2256,8 +2256,8 @@ static void RegisterIoHandler(unsigned int uSlot, iorfunction IOReadC0, iowfunct assert((uintptr_t)IOWriteC0); for (unsigned int i = 0; i < 16; i++) { - cpu65_vmem_r[base_addr+i] = IOReadC0; - cpu65_vmem_w[base_addr+i] = IOWriteC0; + cpu65_vmem_r[(base_addr+i)>>8] = IOReadC0; + cpu65_vmem_w[(base_addr+i)>>8] = IOWriteC0; } } @@ -2265,8 +2265,8 @@ static void RegisterIoHandler(unsigned int uSlot, iorfunction IOReadC0, iowfunct base_addr = 0xC000 + (uSlot<<8); // uSlot == 4 => 0xC400 , uSlot == 5 => 0xC500 for (unsigned int i = 0; i < 0x100; i++) { - //cpu65_vmem_r[base_addr+i] = IOReadCx; -- CANNOT DO THIS HERE -- DEPENDS ON cxrom softswitch - cpu65_vmem_w[base_addr+i] = IOWriteCx; + //cpu65_vmem_r[(base_addr+i)>>8] = IOReadCx; -- CANNOT DO THIS HERE -- DEPENDS ON cxrom softswitch + cpu65_vmem_w[(base_addr+i)>>8] = IOWriteCx; } } #endif diff --git a/src/audio/speaker.c b/src/audio/speaker.c index f783d367..84bb3ae4 100644 --- a/src/audio/speaker.c +++ b/src/audio/speaker.c @@ -519,8 +519,7 @@ double speaker_cyclesPerSample(void) { // -------------------------------------------------------------------------------------------------------------------- // VM system entry point -GLUE_C_READ(speaker_toggle) -{ +uint8_t speaker_toggle(void) { ASSERT_ON_CPU_THREAD(); timing_checkpointCycles(); diff --git a/src/audio/speaker.h b/src/audio/speaker.h index 789227ed..7fed57e1 100644 --- a/src/audio/speaker.h +++ b/src/audio/speaker.h @@ -21,6 +21,7 @@ void speaker_destroy(void) CALL_ON_CPU_THREAD; void speaker_reset(void); void speaker_flush(void) CALL_ON_CPU_THREAD; bool speaker_isActive(void); +uint8_t speaker_toggle(void) CALL_ON_CPU_THREAD; /* * returns the machine cycles per sample diff --git a/src/cpu-supp.c b/src/cpu-supp.c index 3fe63ec5..7377bdf4 100644 --- a/src/cpu-supp.c +++ b/src/cpu-supp.c @@ -29,8 +29,8 @@ static pthread_mutex_t irq_mutex = PTHREAD_MUTEX_INITIALIZER; uint8_t cpu65_flags_encode[256] = { 0 }; uint8_t cpu65_flags_decode[256] = { 0 }; -void *cpu65_vmem_r[0x10000] = { 0 }; -void *cpu65_vmem_w[0x10000] = { 0 }; +void *cpu65_vmem_r[sizeof(void*) * 256] = { 0 }; +void *cpu65_vmem_w[sizeof(void*) * 256] = { 0 }; #if CPU_TRACING static int8_t opargs[3] = { 0 }; diff --git a/src/cpu.h b/src/cpu.h index ee068e0f..a50871a9 100644 --- a/src/cpu.h +++ b/src/cpu.h @@ -47,8 +47,8 @@ extern bool cpu65_loadState(StateHelper_s *helper); extern void cpu65_direct_write(int ea,int data); -extern void *cpu65_vmem_r[65536]; -extern void *cpu65_vmem_w[65536]; +extern void *cpu65_vmem_r[sizeof(void*) * 256]; +extern void *cpu65_vmem_w[sizeof(void*) * 256]; extern uint8_t cpu65_flags_encode[256]; extern uint8_t cpu65_flags_decode[256]; diff --git a/src/disk.c b/src/disk.c index c44843e8..ac42845b 100644 --- a/src/disk.c +++ b/src/disk.c @@ -679,8 +679,7 @@ static void _disk_modeSelect(uint16_t ea) { disk6.ddrw = (ea & 0x1); } -GLUE_C_READ(disk6_ioRead) -{ +uint8_t disk6_ioRead(uint16_t ea) { uint8_t sw = ea & 0xf; if (sw <= 0x7) { // C0E0 - C0E7 _disk6_phaseChange(ea); @@ -714,8 +713,7 @@ GLUE_C_READ(disk6_ioRead) return (ea & 1) ? floating_bus() : disk6.disk_byte; } -GLUE_C_WRITE(disk6_ioWrite) -{ +void disk6_ioWrite(uint16_t ea, uint8_t b) { uint8_t sw = ea & 0xf; if (sw <= 0x7) { // C0E0 - C0E7 _disk6_phaseChange(ea); @@ -761,14 +759,6 @@ void disk6_init(void) { // load Disk II ROM memcpy(apple_ii_64k[0] + 0xC600, slot6_rom, 0x100); - // disk softswitches - // 0xC0Xi : X = slot 0x6 + 0x8 == 0xE - - for (unsigned int i = 0xC0E0; i < 0xC0F0; i++) { - cpu65_vmem_r[i] = disk6_ioRead; - cpu65_vmem_w[i] = disk6_ioWrite; - } - stepper_phases = 0; disk6.disk[0].phase = disk6.disk[1].phase = 0; diff --git a/src/disk.h b/src/disk.h index c4914ada..2fe5602d 100644 --- a/src/disk.h +++ b/src/disk.h @@ -87,10 +87,15 @@ extern const char *disk6_eject(int drive); // flush all I/O extern void disk6_flush(int drive); +// save/restore state handling extern bool disk6_saveState(StateHelper_s *helper); extern bool disk6_loadState(StateHelper_s *helper); extern bool disk6_stateExtractDiskPaths(StateHelper_s *helper, JSON_ref json); +// CPU thread I/O +extern uint8_t disk6_ioRead(uint16_t ea) CALL_ON_CPU_THREAD; +extern void disk6_ioWrite(uint16_t ea, uint8_t b) CALL_ON_CPU_THREAD; + #if DISK_TRACING void disk6_traceToggle(const char *read_file, const char *write_file); void disk6_traceBegin(const char *read_file, const char *write_file); diff --git a/src/glue.h b/src/glue.h index 9459f904..e4915ab7 100644 --- a/src/glue.h +++ b/src/glue.h @@ -30,6 +30,8 @@ #define GLUE_EXTERN_C_READ(func) extern uint8_t func(uint16_t) +#define GLUE_NOP(func) extern void func(void); + #if VM_TRACING #define GLUE_C_WRITE(func) \ diff --git a/src/interface.c b/src/interface.c index dbc50ac6..4daf4a14 100644 --- a/src/interface.c +++ b/src/interface.c @@ -1089,7 +1089,6 @@ void c_interface_parameters() else if ((ch == kESC) || c_keys_is_interface_key(ch)) { timing_initialize(); - vm_reinitializeAudio(); c_joystick_reset(); #if !TESTING prefs_save(); diff --git a/src/vm.c b/src/vm.c index 3235b851..021b57dd 100644 --- a/src/vm.c +++ b/src/vm.c @@ -51,24 +51,7 @@ GLUE_BANK_MAYBE_READ_CX(iie_read_slot4, BASE_C4ROM); GLUE_BANK_MAYBE_READ_CX(iie_read_slot5, BASE_C5ROM); GLUE_BANK_MAYBE_READ_CX(iie_read_slotx, BASE_CXROM); -GLUE_EXTERN_C_READ(speaker_toggle); - -GLUE_C_READ(ram_nop) -{ - (void)ea; - return (run_args.cpu65_rw&MEM_WRITE_FLAG) ? 0x0 : floating_bus(); -} - -GLUE_C_READ(read_unmapped_softswitch) -{ - return c_ram_nop(ea); -} - -GLUE_C_WRITE(write_unmapped_softswitch) -{ - (void)ea; - (void)b; -} +GLUE_NOP(write_ram_nop); GLUE_C_READ(iie_read_peripheral_card) { @@ -101,14 +84,7 @@ GLUE_C_READ(iie_read_peripheral_card) return floating_bus(); } -GLUE_C_READ(read_keyboard) -{ - uint8_t b = apple_ii_64k[0][0xC000]; - return b; -} - -GLUE_C_READ(read_keyboard_strobe) -{ +static uint8_t read_keyboard_strobe(void) { apple_ii_64k[0][0xC000] &= 0x7F; apple_ii_64k[1][0xC000] &= 0x7F; return apple_ii_64k[0][0xC000]; @@ -117,8 +93,7 @@ GLUE_C_READ(read_keyboard_strobe) // ---------------------------------------------------------------------------- // graphics softswitches -GLUE_C_READ(iie_page2_off) -{ +static uint8_t iie_page2_off(void) { if (!(run_args.softswitches & SS_PAGE2)) { return floating_bus(); } @@ -140,8 +115,7 @@ GLUE_C_READ(iie_page2_off) return floating_bus(); } -GLUE_C_READ(iie_page2_on) -{ +static uint8_t iie_page2_on(void) { if (run_args.softswitches & SS_PAGE2) { return floating_bus(); } @@ -165,13 +139,7 @@ GLUE_C_READ(iie_page2_on) return floating_bus(); } -GLUE_C_READ(iie_check_page2) -{ - return (run_args.softswitches & SS_PAGE2) ? 0x80 : 0x00; -} - -GLUE_C_READ(read_switch_graphics) -{ +static uint8_t read_switch_graphics(void) { if (run_args.softswitches & SS_TEXT) { video_setDirty(A2_DIRTY_FLAG); run_args.softswitches &= ~SS_TEXT; @@ -179,8 +147,7 @@ GLUE_C_READ(read_switch_graphics) return floating_bus(); } -GLUE_C_READ(read_switch_text) -{ +static uint8_t read_switch_text(void) { if (!(run_args.softswitches & SS_TEXT)) { video_setDirty(A2_DIRTY_FLAG); run_args.softswitches |= SS_TEXT; @@ -188,13 +155,7 @@ GLUE_C_READ(read_switch_text) return floating_bus(); } -GLUE_C_READ(iie_check_text) -{ - return (run_args.softswitches & SS_TEXT) ? 0x80 : 0x00; -} - -GLUE_C_READ(read_switch_no_mixed) -{ +static uint8_t read_switch_no_mixed(void) { if (run_args.softswitches & SS_MIXED) { video_setDirty(A2_DIRTY_FLAG); run_args.softswitches &= ~SS_MIXED; @@ -202,8 +163,7 @@ GLUE_C_READ(read_switch_no_mixed) return floating_bus(); } -GLUE_C_READ(read_switch_mixed) -{ +static uint8_t read_switch_mixed(void) { if (!(run_args.softswitches & SS_MIXED)) { video_setDirty(A2_DIRTY_FLAG); run_args.softswitches |= SS_MIXED; @@ -211,21 +171,15 @@ GLUE_C_READ(read_switch_mixed) return floating_bus(); } -GLUE_C_READ(iie_check_mixed) -{ - return (run_args.softswitches & SS_MIXED) ? 0x80 : 0x00; -} - -GLUE_C_READ(iie_annunciator) +static uint8_t iie_annunciator(uint16_t ea) { if ((ea >= 0xC058) && (ea <= 0xC05B)) { // TODO: alternate joystick management? } - return (run_args.cpu65_rw&MEM_WRITE_FLAG) ? 0x0 : floating_bus(); + return floating_bus(); } -GLUE_C_READ(iie_hires_off) -{ +static uint8_t iie_hires_off(void) { if (!(run_args.softswitches & SS_HIRES)) { return floating_bus(); } @@ -248,8 +202,7 @@ GLUE_C_READ(iie_hires_off) return floating_bus(); } -GLUE_C_READ(iie_hires_on) -{ +static uint8_t iie_hires_on(void) { if (run_args.softswitches & SS_HIRES) { return floating_bus(); } @@ -272,11 +225,6 @@ GLUE_C_READ(iie_hires_on) return floating_bus(); } -GLUE_C_READ(iie_check_hires) -{ - return (run_args.softswitches & SS_HIRES) ? 0x80 : 0x00; -} - GLUE_C_WRITE(video__write_2e_text0) { do { @@ -419,27 +367,26 @@ GLUE_C_WRITE(video__write_2e_hgr1_mixed) #define CYCLES_PER_USEC (CLK_6502 / 1000000) #define JOY_STEP_CYCLES (JOY_STEP_USEC / CYCLES_PER_USEC) -GLUE_C_READ(read_button0) -{ +static uint8_t read_button0(void) { uint8_t b0 = floating_bus() & (~0x80); uint8_t b = run_args.joy_button0 & 0x80; return b0 | b; } -GLUE_C_READ(read_button1) -{ +static uint8_t read_button1(void) { uint8_t b0 = floating_bus() & (~0x80); uint8_t b = run_args.joy_button1 & 0x80; return b0 | b; } -GLUE_C_READ(read_button2) -{ - return run_args.joy_button0 | run_args.joy_button1; +static uint8_t read_button2(void) { + uint8_t b = floating_bus() & (~0x80); + uint8_t b0 = run_args.joy_button0 & 0x80; + uint8_t b1 = run_args.joy_button1 & 0x80; + return b | b0 | b1; } -GLUE_C_READ(read_gc_strobe) -{ +static uint8_t read_gc_strobe(void) { // Read Game Controller (paddle) strobe ... // From _Understanding the Apple IIe_ : // * 7-29, discussing PREAD : "The timer duration will vary between 2 and 3302 usecs" @@ -458,8 +405,7 @@ GLUE_C_READ(read_gc_strobe) return floating_bus(); } -GLUE_C_READ(read_gc0) -{ +static uint8_t read_gc0(void) { if (run_args.gc_cycles_timer_0 <= 0) { run_args.gc_cycles_timer_0 = 0; @@ -468,7 +414,7 @@ GLUE_C_READ(read_gc0) return 0xFF; } -GLUE_C_READ(read_gc1) +static uint8_t read_gc1(void) { if (run_args.gc_cycles_timer_1 <= 0) { @@ -478,13 +424,11 @@ GLUE_C_READ(read_gc1) return 0xFF; } -GLUE_C_READ(iie_read_gc2) -{ +static uint8_t iie_read_gc2(void) { return floating_bus(); } -GLUE_C_READ(iie_read_gc3) -{ +static uint8_t iie_read_gc3(void) { return floating_bus(); } @@ -503,8 +447,7 @@ static inline void _lc_to_auxmem() { } } -GLUE_C_READ(iie_c080) -{ +static uint8_t iie_c080(void) { run_args.softswitches |= (SS_LCRAM|SS_BANK2); run_args.softswitches &= ~(SS_LCSEC|SS_LCWRT); @@ -520,8 +463,7 @@ GLUE_C_READ(iie_c080) return floating_bus(); } -GLUE_C_READ(iie_c081) -{ +static uint8_t iie_c081(void) { if (run_args.softswitches & SS_LCSEC) { run_args.softswitches |= SS_LCWRT; run_args.base_d000_wrt = language_banks[0]-0xD000; @@ -540,8 +482,7 @@ GLUE_C_READ(iie_c081) return floating_bus(); } -GLUE_C_READ(lc_c082) -{ +static uint8_t lc_c082(void) { run_args.softswitches &= ~(SS_LCRAM|SS_LCWRT|SS_LCSEC); run_args.softswitches |= SS_BANK2; @@ -554,8 +495,7 @@ GLUE_C_READ(lc_c082) return floating_bus(); } -GLUE_C_READ(iie_c083) -{ +static uint8_t iie_c083(void) { if (run_args.softswitches & SS_LCSEC) { run_args.softswitches |= SS_LCWRT; run_args.base_d000_wrt = language_banks[0]-0xD000; @@ -572,8 +512,7 @@ GLUE_C_READ(iie_c083) return floating_bus(); } -GLUE_C_READ(iie_c088) -{ +static uint8_t iie_c088(void) { run_args.softswitches |= SS_LCRAM; run_args.softswitches &= ~(SS_LCWRT|SS_LCSEC|SS_BANK2); @@ -589,8 +528,7 @@ GLUE_C_READ(iie_c088) return floating_bus(); } -GLUE_C_READ(iie_c089) -{ +static uint8_t iie_c089(void) { if (run_args.softswitches & SS_LCSEC) { run_args.softswitches |= SS_LCWRT; run_args.base_d000_wrt = language_banks[0]-0xC000; @@ -609,8 +547,7 @@ GLUE_C_READ(iie_c089) return floating_bus(); } -GLUE_C_READ(lc_c08a) -{ +static uint8_t lc_c08a(void) { run_args.softswitches &= ~(SS_LCRAM|SS_LCWRT|SS_LCSEC|SS_BANK2); run_args.base_d000_rd = apple_ii_64k[0]; @@ -622,8 +559,7 @@ GLUE_C_READ(lc_c08a) return floating_bus(); } -GLUE_C_READ(iie_c08b) -{ +static uint8_t iie_c08b(void) { if (run_args.softswitches & SS_LCSEC) { run_args.softswitches |= SS_LCWRT; run_args.base_d000_wrt = language_banks[0]-0xC000; @@ -642,23 +578,13 @@ GLUE_C_READ(iie_c08b) return floating_bus(); } -GLUE_C_READ(iie_check_bank) -{ - return (run_args.softswitches & SS_BANK2) ? 0x80 : 0x00; -} - -GLUE_C_READ(iie_check_lcram) -{ - return (run_args.softswitches & SS_LCRAM) ? 0x80 : 0x00; -} - // ---------------------------------------------------------------------------- // Misc //e softswitches and vm routines -GLUE_C_READ(iie_80store_off) -{ +static uint8_t iie_80store_off(void) { + assert((run_args.cpu65_rw&MEM_WRITE_FLAG)); if (!(run_args.softswitches & SS_80STORE)) { - return floating_bus(); + return 0x0;//floating_bus(); } video_setDirty(A2_DIRTY_FLAG); @@ -685,13 +611,13 @@ GLUE_C_READ(iie_80store_off) run_args.softswitches |= SS_SCREEN; } - return floating_bus(); + return 0x0;//floating_bus(); } -GLUE_C_READ(iie_80store_on) -{ +static uint8_t iie_80store_on(void) { + assert((run_args.cpu65_rw&MEM_WRITE_FLAG)); if (run_args.softswitches & SS_80STORE) { - return floating_bus(); + return 0x0;//floating_bus(); } video_setDirty(A2_DIRTY_FLAG); @@ -719,18 +645,13 @@ GLUE_C_READ(iie_80store_on) run_args.softswitches &= ~SS_SCREEN; - return floating_bus(); + return 0x0;//floating_bus(); } -GLUE_C_READ(iie_check_80store) -{ - return (run_args.softswitches & SS_80STORE) ? 0x80 : 0x00; -} - -GLUE_C_READ(iie_ramrd_main) -{ +static uint8_t iie_ramrd_main(void) { + assert((run_args.cpu65_rw&MEM_WRITE_FLAG)); if (!(run_args.softswitches & SS_RAMRD)) { - return floating_bus(); + return 0x0;//floating_bus(); } video_setDirty(A2_DIRTY_FLAG); @@ -748,13 +669,13 @@ GLUE_C_READ(iie_ramrd_main) run_args.base_hgrrd = apple_ii_64k[0]; } - return floating_bus(); + return 0x0;//floating_bus(); } -GLUE_C_READ(iie_ramrd_aux) -{ +static uint8_t iie_ramrd_aux(void) { + assert((run_args.cpu65_rw&MEM_WRITE_FLAG)); if (run_args.softswitches & SS_RAMRD) { - return floating_bus(); + return 0x0;//floating_bus(); } video_setDirty(A2_DIRTY_FLAG); @@ -772,18 +693,13 @@ GLUE_C_READ(iie_ramrd_aux) run_args.base_hgrrd = apple_ii_64k[1]; } - return floating_bus(); + return 0x0;//floating_bus(); } -GLUE_C_READ(iie_check_ramrd) -{ - return (run_args.softswitches & SS_RAMRD) ? 0x80 : 0x00; -} - -GLUE_C_READ(iie_ramwrt_main) -{ +static uint8_t iie_ramwrt_main(void) { + assert((run_args.cpu65_rw&MEM_WRITE_FLAG)); if (!(run_args.softswitches & SS_RAMWRT)) { - return floating_bus(); + return 0x0;// floating_bus(); } run_args.softswitches &= ~SS_RAMWRT; @@ -800,13 +716,13 @@ GLUE_C_READ(iie_ramwrt_main) run_args.base_hgrwrt = apple_ii_64k[0]; } - return floating_bus(); + return 0x0;//floating_bus(); } -GLUE_C_READ(iie_ramwrt_aux) -{ +static uint8_t iie_ramwrt_aux(void) { + assert((run_args.cpu65_rw&MEM_WRITE_FLAG)); if (run_args.softswitches & SS_RAMWRT) { - return floating_bus(); + return 0x0;//floating_bus(); } run_args.softswitches |= SS_RAMWRT; @@ -823,19 +739,14 @@ GLUE_C_READ(iie_ramwrt_aux) run_args.base_hgrwrt = apple_ii_64k[1]; } - return floating_bus(); + return 0x0;//floating_bus(); } -GLUE_C_READ(iie_check_ramwrt) -{ - return (run_args.softswitches & SS_RAMWRT) ? 0x80 : 0x00; -} - -GLUE_C_READ_ALTZP(iie_altzp_main) -{ +static uint8_t iie_altzp_main(void) { + assert((run_args.cpu65_rw&MEM_WRITE_FLAG)); if (!(run_args.softswitches & SS_ALTZP)) { /* NOTE : test if ALTZP already off - due to d000-bank issues it is *needed*, not just a shortcut */ - return floating_bus(); + return 0x0;//floating_bus(); } run_args.softswitches &= ~SS_ALTZP; @@ -851,14 +762,14 @@ GLUE_C_READ_ALTZP(iie_altzp_main) run_args.base_e000_wrt = language_card[0] - 0xE000; } - return floating_bus(); + return 0x0;//floating_bus(); } -GLUE_C_READ_ALTZP(iie_altzp_aux) -{ +static uint8_t iie_altzp_aux(void) { + assert((run_args.cpu65_rw&MEM_WRITE_FLAG)); if (run_args.softswitches & SS_ALTZP) { /* NOTE : test if ALTZP already on - due to d000-bank issues it is *needed*, not just a shortcut */ - return floating_bus(); + return 0x0;//floating_bus(); } run_args.softswitches |= SS_ALTZP; @@ -866,89 +777,55 @@ GLUE_C_READ_ALTZP(iie_altzp_aux) _lc_to_auxmem(); - return floating_bus(); + return 0x0;//floating_bus(); } -GLUE_C_READ(iie_check_altzp) -{ - return (run_args.softswitches & SS_ALTZP) ? 0x80 : 0x00; -} - -GLUE_C_READ(iie_80col_off) -{ +static uint8_t iie_80col_off(void) { + assert((run_args.cpu65_rw&MEM_WRITE_FLAG)); if (!(run_args.softswitches & SS_80COL)) { - return floating_bus(); + return 0x0;//floating_bus(); } video_setDirty(A2_DIRTY_FLAG); run_args.softswitches &= ~SS_80COL; - return floating_bus(); + return 0x0;//floating_bus(); } -GLUE_C_READ(iie_80col_on) -{ +static uint8_t iie_80col_on(void) { + assert((run_args.cpu65_rw&MEM_WRITE_FLAG)); if (run_args.softswitches & SS_80COL) { - return floating_bus(); + return 0x0;//floating_bus(); } video_setDirty(A2_DIRTY_FLAG); run_args.softswitches |= SS_80COL; - return floating_bus(); + return 0x0;//floating_bus(); } -GLUE_C_READ(iie_check_80col) -{ - return (run_args.softswitches & SS_80COL) ? 0x80 : 0x00; -} - -GLUE_C_READ(iie_altchar_off) -{ +static uint8_t iie_altchar_off(void) { + assert((run_args.cpu65_rw&MEM_WRITE_FLAG)); if (run_args.softswitches & SS_ALTCHAR) { video_setDirty(A2_DIRTY_FLAG); run_args.softswitches &= ~SS_ALTCHAR; display_loadFont(/*start:*/0x40, /*qty:*/0x40, /*data:*/ucase_glyphs, FONT_MODE_FLASH); } - return floating_bus(); + return 0x0;//floating_bus(); } -GLUE_C_READ(iie_altchar_on) -{ +static uint8_t iie_altchar_on(void) { + assert((run_args.cpu65_rw&MEM_WRITE_FLAG)); if (!(run_args.softswitches & SS_ALTCHAR)) { video_setDirty(A2_DIRTY_FLAG); run_args.softswitches |= SS_ALTCHAR; display_loadFont(/*start:*/0x40, /*qty:*/0x20, /*data:*/mousetext_glyphs, FONT_MODE_MOUSETEXT); display_loadFont(/*start:*/0x60, /*qty:*/0x20, /*data:*/lcase_glyphs, FONT_MODE_INVERSE); } - return floating_bus(); + return 0x0;//floating_bus(); } -GLUE_C_READ(iie_check_altchar) -{ - return (run_args.softswitches & SS_ALTCHAR) ? 0x80 : 0x00; -} - -GLUE_C_READ(iie_ioudis_off) -{ - run_args.softswitches &= ~SS_IOUDIS; - return c_read_gc_strobe(ea); -} - -GLUE_C_READ(iie_ioudis_on) -{ - run_args.softswitches |= SS_IOUDIS; - return c_read_gc_strobe(ea); -} - -GLUE_C_READ(iie_check_ioudis) -{ - c_read_gc_strobe(ea); - return (run_args.softswitches & SS_IOUDIS) ? 0x80 : 0x00; -} - -GLUE_C_READ(iie_dhires_on) -{ +static uint8_t iie_dhires_on(void) { if (!(run_args.softswitches & SS_DHIRES)) { video_setDirty(A2_DIRTY_FLAG); run_args.softswitches |= SS_DHIRES; @@ -956,8 +833,7 @@ GLUE_C_READ(iie_dhires_on) return floating_bus(); } -GLUE_C_READ(iie_dhires_off) -{ +static uint8_t iie_dhires_off(void) { if (run_args.softswitches & SS_DHIRES) { video_setDirty(A2_DIRTY_FLAG); run_args.softswitches &= ~SS_DHIRES; @@ -965,22 +841,15 @@ GLUE_C_READ(iie_dhires_off) return floating_bus(); } -GLUE_C_READ(iie_check_dhires) -{ - c_read_gc_strobe(ea); // HACK FIXME : is this correct? - return (run_args.softswitches & SS_DHIRES) ? 0x80 : 0x00; -} - -GLUE_C_READ(iie_check_vbl) -{ +static uint8_t iie_check_vbl(void) { bool isVBL = false; video_scannerAddress(&isVBL); uint8_t key = apple_ii_64k[0][0xC000]; return (key & ~0x80) | (isVBL ? 0x00 : 0x80); } -GLUE_C_READ(iie_c3rom_peripheral) -{ +static uint8_t iie_c3rom_peripheral(void) { + assert((run_args.cpu65_rw&MEM_WRITE_FLAG)); run_args.softswitches &= ~SS_C3ROM; if (!(run_args.softswitches & SS_CXROM)) { run_args.base_c3rom = (void *)iie_read_peripheral_card; @@ -988,20 +857,15 @@ GLUE_C_READ(iie_c3rom_peripheral) return 0x0; } -GLUE_C_READ(iie_c3rom_internal) -{ +static uint8_t iie_c3rom_internal(void) { + assert((run_args.cpu65_rw&MEM_WRITE_FLAG)); run_args.softswitches |= SS_C3ROM; run_args.base_c3rom = apple_ii_64k[1]; return 0x0; } -GLUE_C_READ(iie_check_c3rom) -{ - return (run_args.softswitches & SS_C3ROM) ? 0x00 : 0x80; // reversed pattern -} - -GLUE_C_READ(iie_cxrom_peripheral) -{ +static uint8_t iie_cxrom_peripheral(void) { + assert((run_args.cpu65_rw&MEM_WRITE_FLAG)); run_args.softswitches &= ~SS_CXROM; run_args.base_cxrom = (void *)iie_read_peripheral_card; run_args.base_c4rom = (void *)iie_read_peripheral_card; @@ -1012,8 +876,8 @@ GLUE_C_READ(iie_cxrom_peripheral) return 0x0; } -GLUE_C_READ(iie_cxrom_internal) -{ +static uint8_t iie_cxrom_internal(void) { + assert((run_args.cpu65_rw&MEM_WRITE_FLAG)); run_args.softswitches |= SS_CXROM; run_args.base_cxrom = apple_ii_64k[1]; run_args.base_c3rom = apple_ii_64k[1]; @@ -1022,11 +886,395 @@ GLUE_C_READ(iie_cxrom_internal) return 0x0; } -GLUE_C_READ(iie_check_cxrom) +// ---------------------------------------------------------------------------- +// C0XX softswitch handlers + +GLUE_C_READ(read_softswitch) { - return (run_args.softswitches & SS_CXROM) ? 0x80 : 0x00; + uint8_t sw = ea & 0xFF; + + //return cpu65_c0_r[sw](ea, b); + + // keyboard data and strobe (READ) + if (sw >= 0x00 && sw < 0x10) { + return apple_ii_64k[0][0xC000]; + } + if (sw == 0x10) { + return read_keyboard_strobe(); + } + + if (sw >= 0x11 && sw < 0x20) { + // RDBNK2 switch + if (sw == 0x11) { + return (run_args.softswitches & SS_BANK2) SS_BANK2_SHIFT; + } + + // RDLCRAM switch + if (sw == 0x12) { + return (run_args.softswitches & SS_LCRAM) SS_LCRAM_SHIFT; + } + + // RAMRD switch + if (sw == 0x13) { + return (run_args.softswitches & SS_RAMRD) SS_RAMRD_SHIFT; + } + + // RAMWRT switch + if (sw == 0x14) { + return (run_args.softswitches & SS_RAMWRT) SS_RAMWRT_SHIFT; + } + + // SLOTCXROM switch + if (sw == 0x15) { + return (run_args.softswitches & SS_CXROM) SS_CXROM_SHIFT; + } + + // ALTZP switch + if (sw == 0x16) { + return (run_args.softswitches & SS_ALTZP) SS_ALTZP_SHIFT; + } + + // SLOTC3ROM switch + if (sw == 0x17) { + // reversed pattern! + return (run_args.softswitches & SS_C3ROM) ? 0x00 : 0x80; + } + + // 80STORE switch + if (sw == 0x18) { + return (run_args.softswitches & SS_80STORE) SS_80STORE_SHFT; + } + + // RDVBLBAR switch + if (sw == 0x19) { + return iie_check_vbl(); + } + + // TEXT check switch + if (sw == 0x1A) { + return (run_args.softswitches & SS_TEXT) SS_TEXT_SHIFT; + } + + // MIXED check switch + if (sw == 0x1B) { + return (run_args.softswitches & SS_MIXED) SS_MIXED_SHIFT; + } + + // PAGE2 check switch + if (sw == 0x1C) { + return (run_args.softswitches & SS_PAGE2) SS_PAGE2_SHIFT; + } + + // HIRES check switch + if (sw == 0x1D) { + return (run_args.softswitches & SS_HIRES) SS_HIRES_SHIFT; + } + + // ALTCHAR switch + if (sw == 0x1E) { + return (run_args.softswitches & SS_ALTCHAR) SS_ALTCHAR_SHFT; + } + + // 80COL switch + if (sw == 0x1F) { + return (run_args.softswitches & SS_80COL) SS_80COL_SHIFT; + } + } + + if (sw >= 0x30 && sw < 0x40) { + return speaker_toggle(); + } + + // TEXT switch + if (sw == 0x50) { + return read_switch_graphics(); + } + if (sw == 0x51) { + return read_switch_text(); + } + + // MIXED switch + if (sw == 0x52) { + return read_switch_no_mixed(); + } + if (sw == 0x53) { + return read_switch_mixed(); + } + + // PAGE2 switch + if (sw == 0x54) { + return iie_page2_off(); + } + if (sw == 0x55) { + return iie_page2_on(); + } + + // HIRES switch + if (sw == 0x56) { + return iie_hires_off(); + } + if (sw == 0x57) { + return iie_hires_on(); + } + + // Annunciator + if (sw >= 0x58 && sw < 0x5E) { + return iie_annunciator(ea); + } + + // DHIRES + if (sw == 0x5E) { + return iie_dhires_on(); + } + if (sw == 0x5F) { + return iie_dhires_off(); + } + + // game I/O switches + if (sw == 0x61 || sw == 0x69) { + return read_button0(); + } + if (sw == 0x62 || sw == 0x6A) { + return read_button1(); + } + if (sw == 0x63 || sw == 0x6B) { + return read_button2(); + } + if (sw == 0x64 || sw == 0x6C) { + return read_gc0(); + } + if (sw == 0x65 || sw == 0x6D) { + return read_gc1(); + } + + if (sw == 0x66) { + return iie_read_gc2(); + } + if (sw == 0x67) { + return iie_read_gc3(); + } + + if (sw >= 0x70 && sw < 0x7E) { + return read_gc_strobe(); + } + + // IOUDIS switch & read_gc_strobe + // HACK FIXME TODO : double-check this stuff against AWin... + if (sw == 0x7E) { + read_gc_strobe(); + return (run_args.softswitches & SS_IOUDIS) SS_IOUDIS_SHIFT; + } + if (sw == 0x7F) { + read_gc_strobe(); // HACK FIXME : is this correct? + return (run_args.softswitches & SS_DHIRES) SS_DHIRES_SHIFT; + } + + // language card softswitches + if (sw == 0x80 || sw == 0x84) { + return iie_c080(); + } + if (sw == 0x81 || sw == 0x85) { + return iie_c081(); + } + if (sw == 0x82 || sw == 0x86) { + return lc_c082(); + } + if (sw == 0x83 || sw == 0x87) { + return iie_c083(); + } + + if (sw == 0x88 || sw == 0x8C) { + return iie_c088(); + } + if (sw == 0x89 || sw == 0x8D) { + return iie_c089(); + } + if (sw == 0x8A || sw == 0x8E) { + return lc_c08a(); + } + if (sw == 0x8B || sw == 0x8F) { + return iie_c08b(); + } + + if (sw >= 0xE0 && sw < 0xF0) { + // disk softswitches + // 0xC0Xi : X = slot 0x6 + 0x8 == 0xE + return disk6_ioRead(ea); + } + + return floating_bus(); } +GLUE_C_WRITE(write_softswitch) +{ + uint8_t sw = ea & 0xFF; + + if (sw == 0x00) { + iie_80store_off(); + } + if (sw == 0x01) { + iie_80store_on(); + } + + // RAMRD switch + if (sw == 0x02) { + iie_ramrd_main(); + } + if (sw == 0x03) { + iie_ramrd_aux(); + } + + // RAMWRT switch + if (sw == 0x04) { + iie_ramwrt_main(); + } + if (sw == 0x05) { + iie_ramwrt_aux(); + } + + // SLOTCXROM switch + if (sw == 0x06) { + iie_cxrom_peripheral(); + } + if (sw == 0x07) { + iie_cxrom_internal(); + } + + // ALTZP switch + if (sw == 0x08) { + iie_altzp_main(); + } + if (sw == 0x09) { + iie_altzp_aux(); + } + + // SLOTC3ROM switch + if (sw == 0x0A) { + iie_c3rom_internal(); + } + if (sw == 0x0B) { + iie_c3rom_peripheral(); + } + + // 80COL switch + if (sw == 0x0C) { + iie_80col_off(); + } + if (sw == 0x0D) { + iie_80col_on(); + } + + // ALTCHAR switch + if (sw == 0x0E) { + iie_altchar_off(); + } + if (sw == 0x0F) { + iie_altchar_on(); + } + + if (sw >= 0x10 && sw < 0x20) { + read_keyboard_strobe(); + } + + if (sw >= 0x30 && sw < 0x40) { + speaker_toggle(); + } + + // TEXT switch + if (sw == 0x50) { + read_switch_graphics(); + } + if (sw == 0x51) { + read_switch_text(); + } + + // MIXED switch + if (sw == 0x52) { + read_switch_no_mixed(); + } + if (sw == 0x53) { + read_switch_mixed(); + } + + // PAGE2 switch + if (sw == 0x54) { + iie_page2_off(); + } + if (sw == 0x55) { + iie_page2_on(); + } + + // HIRES switch + if (sw == 0x56) { + iie_hires_off(); + } + if (sw == 0x57) { + iie_hires_on(); + } + + // Annunciator + if (sw >= 0x58 && sw < 0x5E) { + iie_annunciator(ea); + } + + // DHIRES + if (sw == 0x5E) { + iie_dhires_on(); + } + if (sw == 0x5F) { + iie_dhires_off(); + } + + if (sw >= 0x70 && sw < 0x7E) { + read_gc_strobe(); + } + + // IOUDIS switch & read_gc_strobe + // HACK FIXME TODO : double-check this stuff against AWin... + if (sw == 0x7E) { + run_args.softswitches |= SS_IOUDIS; + read_gc_strobe(); + } + if (sw == 0x7F) { + run_args.softswitches &= ~SS_IOUDIS; + read_gc_strobe(); + } + + // language card softswitches + if (sw == 0x80 || sw == 0x84) { + iie_c080(); + } + if (sw == 0x81 || sw == 0x85) { + iie_c081(); + } + if (sw == 0x82 || sw == 0x86) { + lc_c082(); + } + if (sw == 0x83 || sw == 0x87) { + iie_c083(); + } + + if (sw == 0x88 || sw == 0x8C) { + iie_c088(); + } + if (sw == 0x89 || sw == 0x8D) { + iie_c089(); + } + if (sw == 0x8A || sw == 0x8E) { + lc_c08a(); + } + if (sw == 0x8B || sw == 0x8F) { + iie_c08b(); + } + + if (sw >= 0xE0 && sw < 0xF0) { + disk6_ioWrite(ea, b); + } +} + +// ---------------------------------------------------------------------------- +// //e expansion ROM + GLUE_C_READ(iie_read_slot_expansion) { // HACK TODO FIXME : how does the expansion slot get referenced? Need to handle other ROMs that might use this area @@ -1148,19 +1396,23 @@ static void _initialize_apple_ii_memory(void) { static void _initialize_tables(void) { - for (unsigned int i = 0; i < 0x10000; i++) { + for (unsigned int i = 0; i < 0x100; i++) { cpu65_vmem_r[i] = iie_read_ram_default; cpu65_vmem_w[i] = iie_write_ram_default; } + for (unsigned int i = 0xC0; i < 0xD0; i++) { + cpu65_vmem_w[i] = write_ram_nop; + } + // language card read/write area - for (unsigned int i = 0xD000; i < 0xE000; i++) { + for (unsigned int i = 0xD0; i < 0xE0; i++) { cpu65_vmem_w[i] = write_ram_bank; cpu65_vmem_r[i] = read_ram_bank; } - for (unsigned int i = 0xE000; i < 0x10000; i++) { + for (unsigned int i = 0xE0; i < 0x100; i++) { cpu65_vmem_w[i] = write_ram_lc; cpu65_vmem_r[i] = read_ram_lc; } @@ -1168,17 +1420,18 @@ static void _initialize_tables(void) { // done common initialization // initialize zero-page, //e specific - for (unsigned int i = 0; i < 0x200; i++) { - cpu65_vmem_r[i] = iie_read_ram_zpage_and_stack; - cpu65_vmem_w[i] = iie_write_ram_zpage_and_stack; - } + cpu65_vmem_r[0] = iie_read_ram_zpage_and_stack; + cpu65_vmem_w[0] = iie_write_ram_zpage_and_stack; + cpu65_vmem_r[1] = iie_read_ram_zpage_and_stack; + cpu65_vmem_w[1] = iie_write_ram_zpage_and_stack; // initialize first text & hires page, which are specially bank switched - for (unsigned int i = 0x400; i < 0x800; i++) { - cpu65_vmem_r[i] = iie_read_ram_text_page0; - } + cpu65_vmem_r[4] = iie_read_ram_text_page0; + cpu65_vmem_r[5] = iie_read_ram_text_page0; + cpu65_vmem_r[6] = iie_read_ram_text_page0; + cpu65_vmem_r[7] = iie_read_ram_text_page0; - for (unsigned int i = 0x2000; i < 0x4000; i++) { + for (unsigned int i = 0x20; i < 0x40; i++) { cpu65_vmem_r[i] = iie_read_ram_hires_page0; } @@ -1187,180 +1440,46 @@ static void _initialize_tables(void) { uint16_t row = display_getVideoLineOffset(y); for (unsigned int x = 0; x < TEXT_COLS; x++) { unsigned int idx = row + x; + + // NOTE : we are doing too much work here calculating the lo_byte positions, but eh, this is just one-time setup :P + // text/lores pages if (y < 20) { - cpu65_vmem_w[idx+0x400] = video__write_2e_text0; - cpu65_vmem_w[idx+0x800] = video__write_2e_text1; + cpu65_vmem_w[(idx+0x400)>>8] = video__write_2e_text0; + cpu65_vmem_w[(idx+0x800)>>8] = video__write_2e_text1; } else { - cpu65_vmem_w[idx+0x400] = video__write_2e_text0_mixed; - cpu65_vmem_w[idx+0x800] = video__write_2e_text1_mixed; + cpu65_vmem_w[(idx+0x400)>>8] = video__write_2e_text0_mixed; + cpu65_vmem_w[(idx+0x800)>>8] = video__write_2e_text1_mixed; } // hires/dhires pages for (unsigned int i = 0; i < 8; i++) { idx = row + (0x400*i) + x; if (y < 20) { - cpu65_vmem_w[idx+0x2000] = video__write_2e_hgr0; - cpu65_vmem_w[idx+0x4000] = video__write_2e_hgr1; + cpu65_vmem_w[(idx+0x2000)>>8] = video__write_2e_hgr0; + cpu65_vmem_w[(idx+0x4000)>>8] = video__write_2e_hgr1; } else { - cpu65_vmem_w[idx+0x2000] = video__write_2e_hgr0_mixed; - cpu65_vmem_w[idx+0x4000] = video__write_2e_hgr1_mixed; + cpu65_vmem_w[(idx+0x2000)>>8] = video__write_2e_hgr0_mixed; + cpu65_vmem_w[(idx+0x4000)>>8] = video__write_2e_hgr1_mixed; } } } } // softswich rom - for (unsigned int i = 0xC000; i < 0xC100; i++) { - cpu65_vmem_r[i] = read_unmapped_softswitch; - cpu65_vmem_w[i] = write_unmapped_softswitch; - } - - // slot rom defaults - for (unsigned int i = 0xC100; i < 0xD000; i++) { - cpu65_vmem_r[i] = iie_read_ram_default; - cpu65_vmem_w[i] = ram_nop; - } - - // keyboard data and strobe (READ) - for (unsigned int i = 0xC000; i < 0xC010; i++) { - cpu65_vmem_r[i] = read_keyboard; - } - - for (unsigned int i = 0xC010; i < 0xC020; i++) { - cpu65_vmem_r[i] = cpu65_vmem_w[i] = read_keyboard_strobe; - } - - // RDBNK2 switch - cpu65_vmem_r[0xC011] = iie_check_bank; - - // RDLCRAM switch - cpu65_vmem_r[0xC012] = iie_check_lcram; - - // 80STORE switch - cpu65_vmem_w[0xC000] = iie_80store_off; - cpu65_vmem_w[0xC001] = iie_80store_on; - cpu65_vmem_r[0xC018] = iie_check_80store; - - // RAMRD switch - cpu65_vmem_w[0xC002] = iie_ramrd_main; - cpu65_vmem_w[0xC003] = iie_ramrd_aux; - cpu65_vmem_r[0xC013] = iie_check_ramrd; - - // RAMWRT switch - cpu65_vmem_w[0xC004] = iie_ramwrt_main; - cpu65_vmem_w[0xC005] = iie_ramwrt_aux; - cpu65_vmem_r[0xC014] = iie_check_ramwrt; - - // ALTZP switch - cpu65_vmem_w[0xC008] = iie_altzp_main; - cpu65_vmem_w[0xC009] = iie_altzp_aux; - cpu65_vmem_r[0xC016] = iie_check_altzp; - - // 80COL switch - cpu65_vmem_w[0xC00C] = iie_80col_off; - cpu65_vmem_w[0xC00D] = iie_80col_on; - cpu65_vmem_r[0xC01F] = iie_check_80col; - - // ALTCHAR switch - cpu65_vmem_w[0xC00E] = iie_altchar_off; - cpu65_vmem_w[0xC00F] = iie_altchar_on; - cpu65_vmem_r[0xC01E] = iie_check_altchar; - - // SLOTC3ROM switch - cpu65_vmem_w[0xC00A] = iie_c3rom_internal; - cpu65_vmem_w[0xC00B] = iie_c3rom_peripheral; - cpu65_vmem_r[0xC017] = iie_check_c3rom; - - // SLOTCXROM switch - cpu65_vmem_w[0xC006] = iie_cxrom_peripheral; - cpu65_vmem_w[0xC007] = iie_cxrom_internal; - cpu65_vmem_r[0xC015] = iie_check_cxrom; - - // RDVBLBAR switch - cpu65_vmem_r[0xC019] = iie_check_vbl; - - // TEXT switch - cpu65_vmem_r[0xC050] = cpu65_vmem_w[0xC050] = read_switch_graphics; - cpu65_vmem_r[0xC051] = cpu65_vmem_w[0xC051] = read_switch_text; - cpu65_vmem_r[0xC01A] = iie_check_text; - - // MIXED switch - cpu65_vmem_r[0xC052] = cpu65_vmem_w[0xC052] = read_switch_no_mixed; - cpu65_vmem_r[0xC053] = cpu65_vmem_w[0xC053] = read_switch_mixed; - cpu65_vmem_r[0xC01B] = iie_check_mixed; - - // PAGE2 switch - cpu65_vmem_r[0xC054] = cpu65_vmem_w[0xC054] = iie_page2_off; - cpu65_vmem_r[0xC01C] = iie_check_page2; - cpu65_vmem_r[0xC055] = cpu65_vmem_w[0xC055] = iie_page2_on; - - // HIRES switch - cpu65_vmem_r[0xC01D] = iie_check_hires; - cpu65_vmem_r[0xC056] = cpu65_vmem_w[0xC056] = iie_hires_off; - cpu65_vmem_r[0xC057] = cpu65_vmem_w[0xC057] = iie_hires_on; - - // game I/O switches - cpu65_vmem_r[0xC061] = cpu65_vmem_r[0xC069] = read_button0; - cpu65_vmem_r[0xC062] = cpu65_vmem_r[0xC06A] = read_button1; - cpu65_vmem_r[0xC063] = cpu65_vmem_r[0xC06B] = read_button2; - cpu65_vmem_r[0xC064] = cpu65_vmem_r[0xC06C] = read_gc0; - cpu65_vmem_r[0xC065] = cpu65_vmem_r[0xC06D] = read_gc1; - cpu65_vmem_r[0xC066] = iie_read_gc2; - cpu65_vmem_r[0xC067] = iie_read_gc3; - - for (unsigned int i = 0xC070; i < 0xC080; i++) { - cpu65_vmem_r[i] = cpu65_vmem_w[i] = read_gc_strobe; - } - - // IOUDIS switch & read_gc_strobe - cpu65_vmem_w[0xC07E] = iie_ioudis_on; - cpu65_vmem_w[0xC07F] = iie_ioudis_off; // HACK FIXME TODO : double-check this stuff against AWin... - cpu65_vmem_r[0xC07E] = iie_check_ioudis; - cpu65_vmem_r[0xC07F] = iie_check_dhires; - - // Annunciator - for (unsigned int i = 0xC058; i <= 0xC05D; i++) { - cpu65_vmem_w[i] = cpu65_vmem_r[i] = iie_annunciator; - } - - // DHIRES - cpu65_vmem_w[0xC05E] = cpu65_vmem_r[0xC05E] = iie_dhires_on; - cpu65_vmem_w[0xC05F] = cpu65_vmem_r[0xC05F] = iie_dhires_off; - - // language card softswitches - cpu65_vmem_r[0xC080] = cpu65_vmem_w[0xC080] = cpu65_vmem_r[0xC084] = cpu65_vmem_w[0xC084] = iie_c080; - cpu65_vmem_r[0xC081] = cpu65_vmem_w[0xC081] = cpu65_vmem_r[0xC085] = cpu65_vmem_w[0xC085] = iie_c081; - cpu65_vmem_r[0xC082] = cpu65_vmem_w[0xC082] = cpu65_vmem_r[0xC086] = cpu65_vmem_w[0xC086] = lc_c082; - cpu65_vmem_r[0xC083] = cpu65_vmem_w[0xC083] = cpu65_vmem_r[0xC087] = cpu65_vmem_w[0xC087] = iie_c083; - - cpu65_vmem_r[0xC088] = cpu65_vmem_w[0xC088] = cpu65_vmem_r[0xC08C] = cpu65_vmem_w[0xC08C] = iie_c088; - cpu65_vmem_r[0xC089] = cpu65_vmem_w[0xC089] = cpu65_vmem_r[0xC08D] = cpu65_vmem_w[0xC08D] = iie_c089; - cpu65_vmem_r[0xC08A] = cpu65_vmem_w[0xC08A] = cpu65_vmem_r[0xC08E] = cpu65_vmem_w[0xC08E] = lc_c08a; - cpu65_vmem_r[0xC08B] = cpu65_vmem_w[0xC08B] = cpu65_vmem_r[0xC08F] = cpu65_vmem_w[0xC08F] = iie_c08b; + cpu65_vmem_r[0xC0] = read_softswitch; + cpu65_vmem_w[0xC0] = write_softswitch; // slot i/o area - for (unsigned int i = 0xC100; i < 0xC300; i++) { - cpu65_vmem_r[i] = iie_read_slotx; // slots 1 & 2 (x) - } + cpu65_vmem_r[0xC1] = iie_read_slotx; // slots 1 + cpu65_vmem_r[0xC2] = iie_read_slotx; // slots 2 + cpu65_vmem_r[0xC3] = iie_read_slot3; // slot 3 (80col) + cpu65_vmem_r[0xC4] = iie_read_slot4; // slot 4 - MB or Phasor + cpu65_vmem_r[0xC5] = iie_read_slot5; // slot 5 - MB #2 + cpu65_vmem_r[0xC6] = iie_read_slotx; // slots 6 + cpu65_vmem_r[0xC7] = iie_read_slotx; // slots 7 - for (unsigned int i = 0xC300; i < 0xC400; i++) { - cpu65_vmem_r[i] = iie_read_slot3; // slot 3 (80col) - } - - for (unsigned int i = 0xC400; i < 0xC500; i++) { - cpu65_vmem_r[i] = iie_read_slot4; // slot 4 - MB or Phasor - } - - for (unsigned int i = 0xC500; i < 0xC600; i++) { - cpu65_vmem_r[i] = iie_read_slot5; // slot 5 - MB #2 - } - - for (unsigned int i = 0xC600; i < 0xC800; i++) { - cpu65_vmem_r[i] = iie_read_slotx; // slots 6 - 7 (x) - } - - for (unsigned int i = 0xC800; i < 0xD000; i++) { + for (unsigned int i = 0xC8; i < 0xD0; i++) { cpu65_vmem_r[i] = iie_read_slot_expansion; } @@ -1380,19 +1499,11 @@ void vm_initialize(void) { _initialize_font(); _initialize_apple_ii_memory(); _initialize_tables(); - vm_reinitializeAudio(); disk6_init(); _initialize_iie_switches(); c_joystick_reset(); } -void vm_reinitializeAudio(void) { - for (unsigned int i = 0xC030; i < 0xC040; i++) { - cpu65_vmem_r[i] = cpu65_vmem_w[i] = speaker_toggle; - } -#warning TODO FIXME ... should unset MB/Phasor hooks if volume is zero ... -} - bool vm_saveState(StateHelper_s *helper) { bool saved = false; int fd = helper->fd; diff --git a/src/vm.h b/src/vm.h index 560b6c00..2e3c41ad 100644 --- a/src/vm.h +++ b/src/vm.h @@ -125,8 +125,6 @@ extern uint8_t language_banks[2][8192]; void vm_initialize(void); -void vm_reinitializeAudio(void); - extern bool vm_saveState(StateHelper_s *helper); extern bool vm_loadState(StateHelper_s *helper); @@ -141,25 +139,57 @@ void vm_printSoftwitches(FILE *fp, bool output_mem, bool output_pseudo); #endif // !defined(__ASSEMBLER__) // softswitch flag bits +// SHIFT macros are for generating 0x80 or 0x00 bytes #define SS_TEXT 0x00000001 +#define SS_TEXT_SHIFT <<7 + #define SS_MIXED 0x00000002 +#define SS_MIXED_SHIFT <<6 + #define SS_HIRES 0x00000004 +#define SS_HIRES_SHIFT <<5 + #define SS_PAGE2 0x00000008 +#define SS_PAGE2_SHIFT <<4 + #define SS_BANK2 0x00000010 +#define SS_BANK2_SHIFT <<3 + #define SS_LCRAM 0x00000020 +#define SS_LCRAM_SHIFT <<2 + #define SS_LCSEC 0x00000040 // Pseudo-softswitch : enabled if 2+ reads have occurred #define SS_LCWRT 0x00000080 // Pseudo-softswitch : LC write enable + #define SS_80STORE 0x00000100 +#define SS_80STORE_SHFT >>1 + #define SS_80COL 0x00000200 +#define SS_80COL_SHIFT >>2 + #define SS_RAMRD 0x00000400 +#define SS_RAMRD_SHIFT >>3 + #define SS_RAMWRT 0x00000800 +#define SS_RAMWRT_SHIFT >>4 + #define SS_ALTZP 0x00001000 +#define SS_ALTZP_SHIFT >>5 + #define SS_DHIRES 0x00002000 +#define SS_DHIRES_SHIFT >>6 + #define SS_IOUDIS 0x00004000 +#define SS_IOUDIS_SHIFT >>7 + #define SS_CXROM 0x00008000 +#define SS_CXROM_SHIFT >>8 + #define SS_C3ROM 0x00010000 + #define SS_ALTCHAR 0x00020000 +#define SS_ALTCHAR_SHFT >>10 // Pseudo soft switches. These are actually functions of other SSes, but are tiresome to calculate as needed. #define SS_SCREEN 0x00040000 /* PAGE2 && !80STORE */ diff --git a/src/x86/cpu-regs.h b/src/x86/cpu-regs.h index 11f0edbc..2af4c301 100644 --- a/src/x86/cpu-regs.h +++ b/src/x86/cpu-regs.h @@ -34,7 +34,8 @@ #define X86_AF_Bit 0x4 /* x86 adj (nybble carry) */ #if __LP64__ -# define SZ_PTR 8 +# define SIZ_PTR 8 +# define SIZ_PTR_SHIFT 3 # define ROR_BIT 63 // x86_64 registers # define _XBP %rbp /* x86_64 base ptr/ scratch*/ @@ -71,7 +72,8 @@ # define testLQ testq # define xorLQ xorq #else -# define SZ_PTR 4 +# define SIZ_PTR 4 +# define SIZ_PTR_SHIFT 2 # define ROR_BIT 31 // x86 registers # define _XBP %ebp /* x86 base ptr / scratch */ @@ -122,13 +124,16 @@ movLQ BASE(reg_args), _XBP; \ movb (_XBP,OFF,1), REG; -#define CALL_IND(BASE,OFF) \ - movLQ BASE(reg_args), _XBP; \ - callLQ *(_XBP,OFF,SZ_PTR); +#define VMEM_RW_ACCESS(BASE) \ + movLQ EffectiveAddr_X, _XBP; \ + shrLQ $8, _XBP; \ + shlLQ $SIZ_PTR_SHIFT, _XBP; \ + addLQ BASE(reg_args), _XBP; \ + callLQ *(_XBP); #define JUMP_IND(BASE,OFF) \ movLQ BASE(reg_args), _XBP; \ - jmp *(_XBP,OFF,SZ_PTR); + jmp *(_XBP,OFF,SIZ_PTR); #endif // whole file diff --git a/src/x86/cpu.S b/src/x86/cpu.S index 78046e56..74c1ddd3 100644 --- a/src/x86/cpu.S +++ b/src/x86/cpu.S @@ -56,17 +56,17 @@ #define GetFromPC_B \ movLQ PC_Reg_X, EffectiveAddr_X; \ incw PC_Reg; \ - CALL_IND(CPU65_VMEM_R,EffectiveAddr_X); \ + VMEM_RW_ACCESS(CPU65_VMEM_R); \ TRACE_ARG; #define GetFromPC_W \ movLQ PC_Reg_X, EffectiveAddr_X; \ addw $2, PC_Reg; \ - CALL_IND(CPU65_VMEM_R,EffectiveAddr_X); \ + VMEM_RW_ACCESS(CPU65_VMEM_R); \ TRACE_ARG; \ movb %al, %ah; \ incw EffectiveAddr; \ - CALL_IND(CPU65_VMEM_R,EffectiveAddr_X); \ + VMEM_RW_ACCESS(CPU65_VMEM_R); \ TRACE_ARG; \ xchgb %al, %ah; @@ -82,23 +82,23 @@ #define GetFromEA_B \ orb $1, CPU65_RW(reg_args); \ - CALL_IND(CPU65_VMEM_R,EffectiveAddr_X); + VMEM_RW_ACCESS(CPU65_VMEM_R); #define GetFromEA_W \ incw EffectiveAddr; \ - CALL_IND(CPU65_VMEM_R,EffectiveAddr_X); \ + VMEM_RW_ACCESS(CPU65_VMEM_R); \ decw EffectiveAddr; \ movb %al, %ah; \ - CALL_IND(CPU65_VMEM_R,EffectiveAddr_X); + VMEM_RW_ACCESS(CPU65_VMEM_R); #define PutToEA_B \ orb $2, CPU65_RW(reg_args); \ movb %al, CPU65_D(reg_args); \ - CALL_IND(CPU65_VMEM_W,EffectiveAddr_X); + VMEM_RW_ACCESS(CPU65_VMEM_W); #define GetFromMem_B(x) \ movLQ x, EffectiveAddr_X; \ - CALL_IND(CPU65_VMEM_R,EffectiveAddr_X); + VMEM_RW_ACCESS(CPU65_VMEM_R); #define GetFromMem_W(x) \ movLQ x, EffectiveAddr_X; \ @@ -191,7 +191,7 @@ #if CPU_TRACING #define GetImm \ _GetImm \ - CALL_IND(CPU65_VMEM_R,EffectiveAddr_X); \ + VMEM_RW_ACCESS(CPU65_VMEM_R); \ TRACE_ARG; #else #define GetImm \ @@ -2216,11 +2216,6 @@ exit_reinit: movb $0, CPU65__SIGNAL(reg_args) ------------------------------------------------------------------------- */ ENTRY(cpu65_direct_write) - pushLQ EffectiveAddr_X - movLQ 8(_XSP),EffectiveAddr_X - movLQ 12(_XSP),_XAX - movLQ CPU65_VMEM_W(reg_args), _XBP; - callLQ *(_XBP,EffectiveAddr_X,SZ_PTR) - popLQ EffectiveAddr_X +#warning FIXME TODO correctly implement cpu65_direct_write ... ret diff --git a/src/x86/glue-prologue.h b/src/x86/glue-prologue.h index 1b0ae742..d60ec007 100644 --- a/src/x86/glue-prologue.h +++ b/src/x86/glue-prologue.h @@ -69,6 +69,9 @@ ENTRY(func) addLQ pointer(reg_args), EffectiveAddr_X; \ ENTRY(func) movb off(reg_args), %al; \ ret; +#define GLUE_NOP(func) \ +ENTRY(func) ret; + #ifdef __LP64__ # define _PUSH_ARGS pushLQ EffectiveAddr_X; /* preserve */ \