Added save/restore to fix clobbered RAMWorks memory
This commit is contained in:
parent
ad01fd3185
commit
59b07fcf11
Binary file not shown.
BIN
bin/GWRAMutil.po
BIN
bin/GWRAMutil.po
Binary file not shown.
56
ram2e.c
56
ram2e.c
|
@ -7,6 +7,60 @@
|
||||||
|
|
||||||
#include "util.h"
|
#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 _cmd;
|
||||||
static char _arg;
|
static char _arg;
|
||||||
/* ram2e_cmd(...) issues a coded command+argument sequence to the RAM2E */
|
/* ram2e_cmd(...) issues a coded command+argument sequence to the RAM2E */
|
||||||
|
@ -247,6 +301,7 @@ int ram2e_main(void)
|
||||||
int reset_count;
|
int reset_count;
|
||||||
|
|
||||||
// Check for RAM2E
|
// Check for RAM2E
|
||||||
|
ramworks_save(); // Save what will be clobbered
|
||||||
if(!auxram_detect() || !ram2e_detect()) {
|
if(!auxram_detect() || !ram2e_detect()) {
|
||||||
// If no RAM2E, show an error message and quit
|
// If no RAM2E, show an error message and quit
|
||||||
gotoxy(0, 8);
|
gotoxy(0, 8);
|
||||||
|
@ -255,6 +310,7 @@ int ram2e_main(void)
|
||||||
cputs(" Press any key to quit.");
|
cputs(" Press any key to quit.");
|
||||||
cgetc(); // Wait for key
|
cgetc(); // Wait for key
|
||||||
clrscr(); // Clear screen before quitting
|
clrscr(); // Clear screen before quitting
|
||||||
|
ramworks_restore();
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue