Fixed up Altera support
This commit is contained in:
parent
ac1d41f282
commit
0dc8b9b981
BIN
bin/GWRAM.dbg.po
BIN
bin/GWRAM.dbg.po
Binary file not shown.
BIN
bin/GWRAM.po
BIN
bin/GWRAM.po
Binary file not shown.
75
ram2gs.c
75
ram2gs.c
|
@ -11,9 +11,13 @@
|
||||||
|
|
||||||
static void ram2gs_erase() { ram2gs_cmd(0x28); }
|
static void ram2gs_erase() { ram2gs_cmd(0x28); }
|
||||||
static void ram2gs_program() { ram2gs_cmd(0x24); }
|
static void ram2gs_program() { ram2gs_cmd(0x24); }
|
||||||
static void ram2gs_set4mb() { ram2gs_cmd(0x10); }
|
static void ram2gs_set(char en8meg, char enled) {
|
||||||
static void ram2gs_set8mb() { ram2gs_cmd(0x11); }
|
char cmd = 0x10;
|
||||||
static void ram2gs_setnvm(char en8meg) {
|
if (en8meg) { cmd |= 0x01; }
|
||||||
|
if (enled) { cmd |= 0x02; }
|
||||||
|
ram2gs_cmd(cmd);
|
||||||
|
}
|
||||||
|
static void ram2gs_set_nvm(char en8meg, char enled) {
|
||||||
char i;
|
char i;
|
||||||
// Clock in 0 to enable this setting entry
|
// Clock in 0 to enable this setting entry
|
||||||
ram2gs_cmd(0x20);
|
ram2gs_cmd(0x20);
|
||||||
|
@ -29,8 +33,18 @@ static void ram2gs_setnvm(char en8meg) {
|
||||||
ram2gs_cmd(0x22);
|
ram2gs_cmd(0x22);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clock in 14 dummy "1"s
|
if (enled) {
|
||||||
for (i = 0; i < 14; i++) {
|
// Clock in 0 to enable LED
|
||||||
|
ram2gs_cmd(0x20);
|
||||||
|
ram2gs_cmd(0x22);
|
||||||
|
} else {
|
||||||
|
// Clock in 1 to disable LED
|
||||||
|
ram2gs_cmd(0x21);
|
||||||
|
ram2gs_cmd(0x23);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clock in 13 dummy "1"s
|
||||||
|
for (i = 0; i < 13; i++) {
|
||||||
ram2gs_cmd(0x21);
|
ram2gs_cmd(0x21);
|
||||||
ram2gs_cmd(0x23);
|
ram2gs_cmd(0x23);
|
||||||
}
|
}
|
||||||
|
@ -38,7 +52,15 @@ static void ram2gs_setnvm(char en8meg) {
|
||||||
ram2gs_program();
|
ram2gs_program();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void menu(void)
|
static void menu_led(char enled) {
|
||||||
|
if (enled) {
|
||||||
|
gwcputsxy(1, 15, "LED enabled. Press [L] to disable LED.");
|
||||||
|
} else {
|
||||||
|
gwcputsxy(1, 15, "LED disabled. Press [L] to enable LED.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void menu()
|
||||||
{
|
{
|
||||||
uint8_t bankcount = ram2gs_getsize();
|
uint8_t bankcount = ram2gs_getsize();
|
||||||
gwcputsxy(5, 1, "-- RAM2GS Capacity Settings --");
|
gwcputsxy(5, 1, "-- RAM2GS Capacity Settings --");
|
||||||
|
@ -63,28 +85,32 @@ static void menu(void)
|
||||||
|
|
||||||
int ram2gs_main(void)
|
int ram2gs_main(void)
|
||||||
{
|
{
|
||||||
char en8meg;
|
char hasled = 1;
|
||||||
char nvm;
|
char typecode = 0;
|
||||||
int reset_count;
|
char enled = 0;
|
||||||
|
char en8meg = 1;
|
||||||
|
char nvm = 0;
|
||||||
|
int reset_count = 0;
|
||||||
|
|
||||||
// Check for RAM2GS
|
if (ram2gs_detect(0 << 2)) {
|
||||||
#ifndef SKIP_RAM2GS_DETECT
|
hasled = !ram2gs_detect(0x04);
|
||||||
if(!ram2gs_detect()) {
|
typecode = 0x0;
|
||||||
|
} else {
|
||||||
|
#ifndef SKIP_RAM2GS_DETECT
|
||||||
// If no RAM2GS, show an error message and quit
|
// If no RAM2GS, show an error message and quit
|
||||||
gwcputsxy(0, 8, " No RAM2GS II detected.");
|
gwcputsxy(0, 8, " No RAM2GS II detected.");
|
||||||
gwcputsxy(0, 10, " Press any key to quit.");
|
gwcputsxy(0, 10, " Press any key to quit.");
|
||||||
cgetc(); // Wait for key
|
cgetc(); // Wait for key
|
||||||
clrscr(); // Clear screen before quitting
|
clrscr(); // Clear screen before quitting
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
menu(); // Print menu
|
if (hasled) { enled = !ram2gs_detect(typecode | 0x02); }
|
||||||
|
menu();
|
||||||
|
if (hasled) { menu_led(enled); }
|
||||||
|
|
||||||
// Get user choice from menu
|
// Get user choice from menu
|
||||||
en8meg = 0;
|
|
||||||
nvm = 0;
|
|
||||||
reset_count = 0;
|
|
||||||
while (true) {
|
while (true) {
|
||||||
// Set capacity or quit according to keypress.
|
// Set capacity or quit according to keypress.
|
||||||
switch (toupper(cgetc() & 0x7F)) {
|
switch (toupper(cgetc() & 0x7F)) {
|
||||||
|
@ -92,9 +118,14 @@ int ram2gs_main(void)
|
||||||
clrscr();
|
clrscr();
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
case '1': en8meg = 0; ram2gs_set4mb(); break;
|
case '1': en8meg = 0; ram2gs_set(0, enled); break;
|
||||||
case '2': en8meg = 1; ram2gs_set8mb(); break;
|
case '2': en8meg = 1; ram2gs_set(1, enled); break;
|
||||||
case 'R': {
|
case 'L': {
|
||||||
|
if (enled == 0) { enled = 1; }
|
||||||
|
else { enled = 0; }
|
||||||
|
if (hasled) { menu_led(enled); };
|
||||||
|
continue;
|
||||||
|
} case 'R': {
|
||||||
reset_count++;
|
reset_count++;
|
||||||
if (reset_count >= 25) {
|
if (reset_count >= 25) {
|
||||||
// Show message about resetting.
|
// Show message about resetting.
|
||||||
|
@ -103,7 +134,7 @@ int ram2gs_main(void)
|
||||||
gwcputsxy(1, 9, "Do not turn off your Apple.");
|
gwcputsxy(1, 9, "Do not turn off your Apple.");
|
||||||
|
|
||||||
ram2gs_erase(); // Erase RAM2GS settings memory
|
ram2gs_erase(); // Erase RAM2GS settings memory
|
||||||
ram2gs_set8mb(); // Enable 8 megabytes now
|
ram2gs_set(1, 0); // Enable 8 megabytes and disable LED
|
||||||
|
|
||||||
// Wait for >= 500ms on even the fastest systems.
|
// Wait for >= 500ms on even the fastest systems.
|
||||||
spin(32, 8);
|
spin(32, 8);
|
||||||
|
@ -130,7 +161,7 @@ int ram2gs_main(void)
|
||||||
gwcputsxy(1, 8, "Saving RAM2GS capacity setting.");
|
gwcputsxy(1, 8, "Saving RAM2GS capacity setting.");
|
||||||
gwcputsxy(1, 9, "Do not turn off your Apple.");
|
gwcputsxy(1, 9, "Do not turn off your Apple.");
|
||||||
// Save capacity in nonvolatile memory.
|
// Save capacity in nonvolatile memory.
|
||||||
ram2gs_setnvm(en8meg);
|
ram2gs_set_nvm(en8meg, enled);
|
||||||
// Wait for >= 500ms on even the fastest systems.
|
// Wait for >= 500ms on even the fastest systems.
|
||||||
spin(33, 8);
|
spin(33, 8);
|
||||||
// Print success message
|
// Print success message
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
#ifndef RAM2GS_ASM_H
|
#ifndef RAM2GS_ASM_H
|
||||||
#define RAM2GS_ASM_H
|
#define RAM2GS_ASM_H
|
||||||
|
|
||||||
uint8_t __fastcall__ ram2gs_getsize(void);
|
|
||||||
uint8_t __fastcall__ ram2gs_detect(void);
|
|
||||||
uint8_t __fastcall__ ram2gs_cmd(char cmd);
|
uint8_t __fastcall__ ram2gs_cmd(char cmd);
|
||||||
|
uint8_t __fastcall__ ram2gs_detect(char typecode);
|
||||||
|
uint8_t __fastcall__ ram2gs_getsize(void);
|
||||||
|
|
||||||
#endif /* RAM2GS_ASM_H */
|
#endif /* RAM2GS_ASM_H */
|
||||||
|
|
205
ram2gs_asm.s
205
ram2gs_asm.s
|
@ -2,9 +2,9 @@
|
||||||
.autoimport on
|
.autoimport on
|
||||||
.importzp sp
|
.importzp sp
|
||||||
|
|
||||||
|
.export _ram2gs_cmd
|
||||||
.export _ram2gs_getsize
|
.export _ram2gs_getsize
|
||||||
.export _ram2gs_detect
|
.export _ram2gs_detect
|
||||||
.export _ram2gs_cmd
|
|
||||||
|
|
||||||
.define GetTWConfig $BCFF3C
|
.define GetTWConfig $BCFF3C
|
||||||
.define SetTWConfig $BCFF40
|
.define SetTWConfig $BCFF40
|
||||||
|
@ -44,7 +44,6 @@
|
||||||
|
|
||||||
.segment "CODE"
|
.segment "CODE"
|
||||||
|
|
||||||
|
|
||||||
.proc _thrash: near
|
.proc _thrash: near
|
||||||
.A8
|
.A8
|
||||||
.I8
|
.I8
|
||||||
|
@ -125,12 +124,18 @@
|
||||||
rts
|
rts
|
||||||
.endproc
|
.endproc
|
||||||
|
|
||||||
.proc _unswap: near
|
.proc _ram2gs_cmd: near
|
||||||
.A8
|
.A8
|
||||||
.I8
|
.I8
|
||||||
; Save current bank and accumulator
|
; Preamble
|
||||||
phb
|
php ; Push status
|
||||||
pha
|
sei ; Disable interrupts
|
||||||
|
clc ; Clear carry
|
||||||
|
xce ; Clear emulation bit
|
||||||
|
php ; Push status again, reflecting emulation bit
|
||||||
|
phb ; Push bank
|
||||||
|
pha ; Push command in accumulator
|
||||||
|
AI8
|
||||||
; Switch to bank 0xFB
|
; Switch to bank 0xFB
|
||||||
lda #$FB
|
lda #$FB
|
||||||
pha
|
pha
|
||||||
|
@ -141,36 +146,30 @@
|
||||||
lda #$AD
|
lda #$AD
|
||||||
sta $FFFF
|
sta $FFFF
|
||||||
; Pull and submit command
|
; Pull and submit command
|
||||||
lda #$00
|
|
||||||
sta $FFFD
|
|
||||||
; Restore accumulator and bank and return
|
|
||||||
pla
|
pla
|
||||||
plb
|
sta $FFFD
|
||||||
|
; Postamble
|
||||||
|
plb ; Restore bank
|
||||||
|
plp ; Restore status
|
||||||
|
xce ; Restore emulation bit
|
||||||
|
plp ; Pull status again to pull I flag
|
||||||
rts
|
rts
|
||||||
.endproc
|
.endproc
|
||||||
|
|
||||||
|
.proc _unswap: near
|
||||||
|
.A8
|
||||||
|
.I8
|
||||||
|
tya
|
||||||
|
ora #$00
|
||||||
|
jmp _ram2gs_cmd
|
||||||
|
.endproc
|
||||||
|
|
||||||
.proc _swap: near
|
.proc _swap: near
|
||||||
.A8
|
.A8
|
||||||
.I8
|
.I8
|
||||||
; Save current bank and accumulator
|
tya
|
||||||
phb
|
ora #$01
|
||||||
pha
|
jmp _ram2gs_cmd
|
||||||
; Switch to bank 0xFB
|
|
||||||
lda #$FB
|
|
||||||
pha
|
|
||||||
plb
|
|
||||||
; Submit C1AD
|
|
||||||
lda #$C1
|
|
||||||
sta $FFFE
|
|
||||||
lda #$AD
|
|
||||||
sta $FFFF
|
|
||||||
; Pull and submit command
|
|
||||||
lda #$01
|
|
||||||
sta $FFFD
|
|
||||||
; Restore accumulator and bank and return
|
|
||||||
pla
|
|
||||||
plb
|
|
||||||
rts
|
|
||||||
.endproc
|
.endproc
|
||||||
|
|
||||||
.proc _ram2gs_getsize: near
|
.proc _ram2gs_getsize: near
|
||||||
|
@ -183,40 +182,8 @@
|
||||||
xce ; Clear emulation bit
|
xce ; Clear emulation bit
|
||||||
php ; Push status again, reflecting emulation bit
|
php ; Push status again, reflecting emulation bit
|
||||||
phb ; Push bank
|
phb ; Push bank
|
||||||
|
|
||||||
; Check for TranswarpGS
|
|
||||||
AI8
|
AI8
|
||||||
lda #0
|
|
||||||
pha ; Push "TWGS absent" flag
|
|
||||||
; AI16
|
|
||||||
; lda $BCFF00
|
|
||||||
; cmp #$5754 ; "WT"
|
|
||||||
; bne _ram2gs_getsize_notwgs1
|
|
||||||
; lda $BCFF02
|
|
||||||
; cmp #$5347 ; "SG"
|
|
||||||
; bne _ram2gs_getsize_notwgs1
|
|
||||||
;
|
|
||||||
; ; Get and push TWGS config
|
|
||||||
; jsl GetTWConfig
|
|
||||||
; pha
|
|
||||||
; ; Disable TWGS data cache
|
|
||||||
; jsl DisableDataCache ; Disable data cache
|
|
||||||
;
|
|
||||||
; ; Pull to restore TWGS settings into A
|
|
||||||
; pla
|
|
||||||
; ; Pull "TWGS absent" flag into x, and discard it
|
|
||||||
; AI8
|
|
||||||
; plx
|
|
||||||
; AI16
|
|
||||||
; ; Push TWGS settings
|
|
||||||
; pha
|
|
||||||
; ; Push "TWGS exists" flag
|
|
||||||
; AI8
|
|
||||||
; ldx #1
|
|
||||||
; phx
|
|
||||||
|
|
||||||
_ram2gs_getsize_notwgs1:
|
|
||||||
AI8
|
|
||||||
; Go to bank 3F
|
; Go to bank 3F
|
||||||
ldy #$3F
|
ldy #$3F
|
||||||
phy
|
phy
|
||||||
|
@ -261,27 +228,13 @@
|
||||||
stx $3456
|
stx $3456
|
||||||
|
|
||||||
; Check result
|
; Check result
|
||||||
ldx #$80
|
lda #$80
|
||||||
plp
|
plp
|
||||||
beq _ram2gs_getsize_return
|
beq _ram2gs_getsize_return
|
||||||
ldx #$40
|
lda #$40
|
||||||
; Restore TWGS config
|
|
||||||
_ram2gs_getsize_return:
|
|
||||||
pla ; Pull TWGS flag
|
|
||||||
phx ; Push to save return value
|
|
||||||
; beq _ram2gs_getsize_post ; Skip if no TWGS
|
|
||||||
; plx ; Get return value back
|
|
||||||
; AI16
|
|
||||||
; pla ; Pull TWGS config
|
|
||||||
; AI8
|
|
||||||
; phx
|
|
||||||
; AI16
|
|
||||||
; jsl SetTWConfig
|
|
||||||
; AI8
|
|
||||||
|
|
||||||
; Postamble
|
; Postamble
|
||||||
_ram2gs_getsize_post:
|
_ram2gs_getsize_return:
|
||||||
pla ; Pull return value
|
|
||||||
plb ; Restore bank
|
plb ; Restore bank
|
||||||
plp ; Restore status
|
plp ; Restore status
|
||||||
xce ; Restore emulation bit
|
xce ; Restore emulation bit
|
||||||
|
@ -289,50 +242,9 @@
|
||||||
rts
|
rts
|
||||||
.endproc
|
.endproc
|
||||||
|
|
||||||
.proc _ram2gs_detect: near
|
.proc _ram2gs_detect_internal: near
|
||||||
.A8
|
.A8
|
||||||
.I8
|
.I8
|
||||||
; Preamble
|
|
||||||
php ; Push status
|
|
||||||
sei ; Disable interrupts
|
|
||||||
clc ; Clear carry
|
|
||||||
xce ; Clear emulation bit
|
|
||||||
php ; Push status again, reflecting emulation bit
|
|
||||||
phb ; Push bank
|
|
||||||
|
|
||||||
; Check for TranswarpGS
|
|
||||||
AI8
|
|
||||||
lda #0
|
|
||||||
pha ; Push "TWGS absent" flag
|
|
||||||
; AI16
|
|
||||||
; lda $BCFF00
|
|
||||||
; cmp #$5754 ; "WT"
|
|
||||||
; bne _ram2gs_detect_notwgs1
|
|
||||||
; lda $BCFF02
|
|
||||||
; cmp #$5347 ; "SG"
|
|
||||||
; bne _ram2gs_detect_notwgs1
|
|
||||||
;
|
|
||||||
; ; Get and push TWGS config
|
|
||||||
; jsl GetTWConfig
|
|
||||||
; pha
|
|
||||||
; ; Disable TWGS data cache
|
|
||||||
; jsl DisableDataCache ; Disable data cache
|
|
||||||
;
|
|
||||||
; ; Pull to restore TWGS settings into A
|
|
||||||
; pla
|
|
||||||
; ; Pull "TWGS absent" flag into x, and discard it
|
|
||||||
; AI8
|
|
||||||
; plx
|
|
||||||
; AI16
|
|
||||||
; ; Push TWGS settings
|
|
||||||
; pha
|
|
||||||
; ; Push "TWGS exists" flag
|
|
||||||
; AI8
|
|
||||||
; ldx #1
|
|
||||||
; phx
|
|
||||||
|
|
||||||
_ram2gs_detect_notwgs1:
|
|
||||||
AI8
|
|
||||||
; Switch to bank 0x3F
|
; Switch to bank 0x3F
|
||||||
lda #$3F
|
lda #$3F
|
||||||
pha
|
pha
|
||||||
|
@ -389,65 +301,44 @@
|
||||||
|
|
||||||
; Done, now put back clobbered bytes
|
; Done, now put back clobbered bytes
|
||||||
_ram2gs_detect_done:
|
_ram2gs_detect_done:
|
||||||
jsr _swap ; Swap
|
jsr _swap ; Swap
|
||||||
pla ; Get value to restore to swapped bank 3F
|
pla ; Get value to restore to swapped bank 3F
|
||||||
sta $8000 ; Restore
|
sta $8000 ; Restore
|
||||||
jsr _unswap ; Unswap
|
jsr _unswap ; Unswap
|
||||||
pla ; Get value to restore to unswapped bank 3F
|
pla ; Get value to restore to unswapped bank 3F
|
||||||
sta $8000 ; Restore
|
sta $8000 ; Restore
|
||||||
|
|
||||||
; Restore TWGS config
|
; Return
|
||||||
_ram2gs_detect_return:
|
|
||||||
pla ; Pull TWGS flag
|
|
||||||
phx ; Push to save return value
|
|
||||||
; beq _ram2gs_detect_post ; Skip if no TWGS
|
|
||||||
; plx ; Get return value back
|
|
||||||
; AI16
|
|
||||||
; pla ; Pull TWGS config
|
|
||||||
; AI8
|
|
||||||
; phx
|
|
||||||
; AI16
|
|
||||||
; jsl SetTWConfig
|
|
||||||
; AI8
|
|
||||||
|
|
||||||
; Postamble
|
|
||||||
_ram2gs_detect_post:
|
|
||||||
pla ; Pull return value
|
|
||||||
plb ; Restore bank
|
|
||||||
plp ; Restore status
|
|
||||||
xce ; Restore emulation bit
|
|
||||||
plp ; Pull status again to pull I flag
|
|
||||||
rts
|
rts
|
||||||
.endproc
|
.endproc
|
||||||
|
|
||||||
.proc _ram2gs_cmd: near
|
.proc _ram2gs_detect: near
|
||||||
.A8
|
.A8
|
||||||
.I8
|
.I8
|
||||||
; Preamble
|
; Preamble
|
||||||
|
phx ; Push X
|
||||||
|
phy ; Push Y
|
||||||
php ; Push status
|
php ; Push status
|
||||||
sei ; Disable interrupts
|
sei ; Disable interrupts
|
||||||
clc ; Clear carry
|
clc ; Clear carry
|
||||||
xce ; Clear emulation bit
|
xce ; Clear emulation bit
|
||||||
php ; Push status again, reflecting emulation bit
|
php ; Push status again, reflecting emulation bit
|
||||||
phb ; Push bank
|
phb ; Push bank
|
||||||
pha ; Push command in accumulator
|
|
||||||
AI8
|
AI8
|
||||||
; Switch to bank 0xFB
|
|
||||||
lda #$FB
|
; Transfer typecode (shifted) to Y register
|
||||||
pha
|
and #$0E
|
||||||
plb
|
tay
|
||||||
; Submit C1AD
|
|
||||||
lda #$C1
|
jsr _ram2gs_detect_internal
|
||||||
sta $FFFE
|
|
||||||
lda #$AD
|
|
||||||
sta $FFFF
|
|
||||||
; Pull and submit command
|
|
||||||
pla
|
|
||||||
sta $FFFD
|
|
||||||
; Postamble
|
; Postamble
|
||||||
|
txa ; Get return value
|
||||||
plb ; Restore bank
|
plb ; Restore bank
|
||||||
plp ; Restore status
|
plp ; Restore status
|
||||||
xce ; Restore emulation bit
|
xce ; Restore emulation bit
|
||||||
plp ; Pull status again to pull I flag
|
plp ; Pull status again to pull I flag
|
||||||
|
ply ; Pull X
|
||||||
|
plx ; Pull Y
|
||||||
rts
|
rts
|
||||||
.endproc
|
.endproc
|
||||||
|
|
Loading…
Reference in New Issue