diff --git a/bin/GWRAMutil.dbg.po b/bin/GWRAMutil.dbg.po index 50770c3..7235ec5 100644 Binary files a/bin/GWRAMutil.dbg.po and b/bin/GWRAMutil.dbg.po differ diff --git a/bin/GWRAMutil.po b/bin/GWRAMutil.po index 0bad7b1..a7c8ae1 100644 Binary files a/bin/GWRAMutil.po and b/bin/GWRAMutil.po differ diff --git a/ram2e.c b/ram2e.c index 0a2a190..01c5b6d 100644 --- a/ram2e.c +++ b/ram2e.c @@ -7,6 +7,60 @@ #include "util.h" +static char _rwsave[256]; +static char _rwsave0_1; +static char _rwsave0_2; +static char _rwsave0_3; +static void ramworks_save() { + __asm__("sta $C009"); // Store in ALTZP + + // Save address 0x0000 in every bank + __asm__("ldx #0"); + saveloop: + __asm__("stx $C073"); + __asm__("lda $00,X"); + __asm__("sta %v,X", _rwsave); + __asm__("inx"); + __asm__("bne %g", saveloop); + + // Save addresses 0x0001-3 in bank 0 + __asm__("ldx #0"); + __asm__("stx $C073"); + __asm__("lda $01"); + __asm__("sta %v", _rwsave0_1); + __asm__("lda $02"); + __asm__("sta %v", _rwsave0_2); + __asm__("lda $03"); + __asm__("sta %v", _rwsave0_3); + + __asm__("sta $C008"); // Don't store in ALTZP +} + +static void ramworks_restore() { + __asm__("sta $C009"); // Store in ALTZP + + // Restore address 0x0000 in every bank + __asm__("ldx #0"); + restoreloop: + __asm__("stx $C073"); + __asm__("lda %v,X", _rwsave); + __asm__("sta $00,X"); + __asm__("inx"); + __asm__("bne %g", restoreloop); + + // Restore addresses 0x0001-3 in bank 0 + __asm__("ldx #0"); + __asm__("stx $C073"); + __asm__("lda %v", _rwsave0_1); + __asm__("sta $01"); + __asm__("lda %v", _rwsave0_2); + __asm__("sta $02"); + __asm__("lda %v", _rwsave0_3); + __asm__("sta $03"); + + __asm__("sta $C008"); // Don't store in ALTZP +} + static char _cmd; static char _arg; /* ram2e_cmd(...) issues a coded command+argument sequence to the RAM2E */ @@ -247,6 +301,7 @@ int ram2e_main(void) int reset_count; // Check for RAM2E + ramworks_save(); // Save what will be clobbered if(!auxram_detect() || !ram2e_detect()) { // If no RAM2E, show an error message and quit gotoxy(0, 8); @@ -255,6 +310,7 @@ int ram2e_main(void) cputs(" Press any key to quit."); cgetc(); // Wait for key clrscr(); // Clear screen before quitting + ramworks_restore(); return EXIT_SUCCESS; }