448i mode (select button), sram reliability checking

This commit is contained in:
ikari 2009-11-19 16:40:33 +01:00
parent 6d6fe8cfb7
commit 187595686e
8 changed files with 172 additions and 33 deletions

View File

@ -71,7 +71,7 @@ hdma_cg_addr_src
.byt $00
hdma_mode_src .byt 74, $03, $01, $05, $00
hdma_scroll_src .byt 74
.byt $00, $00, $ff, $00
.byt $00, $00, $ff, $0f
.byt $01
.byt $fc, $00, $05, $00
.byt $00

View File

@ -67,6 +67,11 @@ fd_fnoff .word 0 ; offset of filename in file descriptor
pad1mem .word 0
pad1trig .word 0
pad1delay .word 0
;----------menu layout/system constants (224/448)
listdisp .word 0 ; number of displayable list entries
textdmasize .word 0 ; number of bytes to copy each frame
barstep .byt 0 ; step size for bar
;----------hdma tables in WRAM (must be stable when cartridge is cut off)
hdma_pal .byt 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.byt 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

View File

@ -53,12 +53,12 @@ setup_gfx:
;clear BG1 tilemap
ldx #BG1_TILE_BASE
stx $2116
DMA0(#$09, #$800, #^zero, #!zero, #$18)
DMA0(#$09, #$1000, #^zero, #!zero, #$18)
;clear BG2 tilemap
ldx #BG2_TILE_BASE
stx $2116
DMA0(#$09, #$800, #^zero, #!zero, #$18)
DMA0(#$09, #$1000, #^zero, #!zero, #$18)
;copy logo tiles
ldx #$2000
@ -123,17 +123,18 @@ tests:
rep #$10 : .xl ;16-bit index
lda #$03 ;mode 3, mode 5 via HDMA :D
sta $2105
lda #$54 ;Tilemap addr 0xA800
lda #$58 ;Tilemap addr 0xB000
ora #$02 ;SC size 32x64
sta $2107 ;for BG1
lda #$50 ;Tilemap addr 0xA000
ora #$02 ;SC size 32x64
sta $2108 ;for BG2
lda #$40 ;chr base addr:
sta $210b ;BG1=0x0000, BG2=0x8000
lda #$03 ;enable BG1+BG2
sta $212c ;BG Main
sta $212d ;BG Sub
lda #$00 ;224 (01=448)
sta $2133 ;
jsr setup_224
lda #$00
sta $2130
stz $2121
@ -202,6 +203,7 @@ snes_init:
stz $2120 ;
stz $2121 ;
stz $2122 ; (CG Data?!)
stz $2122 ; (CG Data?!)
stz $2123 ;
stz $2124 ;
stz $2125 ;

View File

@ -53,7 +53,7 @@ menu_cleanup:
lsr
pha
menu_cleanup_loop
cmp #17
cmp listdisp
beq +
pha
clc
@ -108,6 +108,9 @@ menu_updates:
lda #$80
and pad1trig+1
bne key_b
lda #$20
and pad1trig+1
bne key_select
bra menuupd_out
key_down
jsr menu_key_down
@ -124,6 +127,10 @@ key_left
key_b
jsr menu_key_b
bra menuupd_out
key_select
jsr menu_key_select
bra menuupd_out
menuupd_out
lda #$0A
sta cursor_y
@ -146,7 +153,9 @@ redraw_filelist
redraw_filelist_loop
ldy dirptr_idx
tya
cmp #17*4
lsr
lsr
cmp listdisp
beq redraw_filelist_last
lda dirptr_bank
phb
@ -272,8 +281,9 @@ dirent_type_cont
rts
menu_key_down:
lda menu_sel
cmp #$10
lda listdisp
dec
cmp menu_sel
bne +
lda #$01
sta menu_dirty
@ -286,7 +296,8 @@ menu_key_down:
sta dirptr_addr
sep #$20 : .as
rts
+ inc
+ lda menu_sel
inc
sta menu_sel
down_out
rts
@ -317,9 +328,16 @@ menu_key_left:
lda dirptr_addr
beq +
sec
sbc #17*4
sbc listdisp
sec
sbc listdisp
sec
sbc listdisp
sec
sbc listdisp
cmp dirstart_addr
bcc +
bmi +
- sta dirptr_addr
sep #$20 : .as
rts
@ -336,9 +354,11 @@ menu_key_right:
lda #$01
sta menu_dirty
rep #$20 : .al
lda dirptr_addr
lda listdisp
asl
asl
clc
adc #17*4
adc dirptr_addr
sta dirptr_addr
sep #$20 : .as
rts
@ -353,6 +373,16 @@ menu_key_b:
jsr select_item
rts
menu_key_select:
lda barstep
beq do_setup448
do_setup224
jsr setup_224
rts
do_setup448
jsr setup_448
rts
select_item:
rep #$20 : .al
lda menu_sel
@ -384,7 +414,6 @@ sel_is_dir
select_file:
; have avr load the rom
sta @$fffffe
dey
lda (dirptr_addr), y
sta @AVR_PARAM+2
@ -399,7 +428,6 @@ select_file:
rts
select_dir: ; y = direntry ptr
sta @$ffffff ;for great breakpoint
dey
lda (dirptr_addr), y
clc
@ -432,3 +460,77 @@ select_dir: ; y = direntry ptr
sta @menu_dirty
plb
rts
setup_224:
php
rep #$30 : .xl : .al
lda #17
sta listdisp
dec
cmp menu_sel
bmi setup_228_adjsel
bra +
setup_228_adjsel
sta menu_sel
+
lda #18*64
sta textdmasize
lda #$0005
sta hdma_scroll+8
sep #$20 : .as
lda #$05
sta $2110
lda #$00
sta $2110
lda #$00
sta barstep
sta $2133
lda #$0a
sta hdma_math+6
lda #$01
sta menu_dirty
lda #^space64
ldx #!space64
sta print_bank
stx print_src
stz print_pal
lda #64
sta print_count
lda #27
sta print_y
stz print_x
jsr hiprint
lda #28
sta print_y
jsr hiprint
jsr hiprint
plp
rts
setup_448:
php
rep #$30 : .xl : .al
lda #34
sta listdisp
lda #36*64
sta textdmasize
lda #$ffba
sta hdma_scroll+8
sep #$20 : .as
lda #$ba
sta $2110
lda #$ff
sta $2110
lda #$01
sta barstep
sta $2133
lda #$06
sta hdma_math+6
lda #$01
sta menu_dirty
plp
rts

View File

@ -20,11 +20,11 @@ NMI_ROUTINE:
ldx #BG1_TILE_BASE+32*10
stx $2116
DMA0(#$01, #$380*2-64*10, #^BG1_TILE_BUF, #!BG1_TILE_BUF+64*10, #$18)
DMA0(#$01, #34*64, #^BG1_TILE_BUF, #!BG1_TILE_BUF+64*10, #$18)
ldx #BG2_TILE_BASE+32*10
stx $2116
DMA0(#$01, #$380*2-64*10, #^BG2_TILE_BUF, #!BG2_TILE_BUF+64*10, #$18)
DMA0(#$01, #34*64, #^BG2_TILE_BUF, #!BG2_TILE_BUF+64*10, #$18)
ldx #BG2_TILE_BASE
stx $2116
@ -33,7 +33,18 @@ NMI_ROUTINE:
lda bar_yl
asl
asl
tax
lda barstep
php
txa
plp
bne small_bar
asl
bra normal_bar
small_bar
clc
adc #36
normal_bar
sta bar_y
lda bar_y

View File

@ -245,11 +245,13 @@ int main(void) {
}
dprintf("cmd was %x, going to snes main loop\n", cmd);
led_std();
cmd=0;
while(1) {
if(get_snes_reset()) {
dprintf("RESET\n");
}
sram_reliable();
snes_main_loop();
}

View File

@ -218,30 +218,30 @@ uint32_t load_sram(uint8_t* filename, uint32_t base_addr) {
void save_sram(uint8_t* filename, uint32_t sram_size, uint32_t base_addr) {
uint32_t count = 0;
uint32_t count = 0;
uint32_t num = 0;
spi_none();
file_open(filename, FA_CREATE_ALWAYS | FA_WRITE);
file_open(filename, FA_CREATE_ALWAYS | FA_WRITE);
if(file_res) {
uart_putc(0x30+file_res);
}
while(count<sram_size) {
while(count<sram_size) {
set_avr_addr(base_addr+count);
spi_fpga();
spiTransferByte(0x81); // read
spiTransferByte(0); // dummy
for(int j=0; j<sizeof(file_buf); j++) {
file_buf[j] = spiTransferByte(0x00);
count++;
}
for(int j=0; j<sizeof(file_buf); j++) {
file_buf[j] = spiTransferByte(0x00);
count++;
}
spi_none();
num = file_write();
num = file_write();
if(file_res) {
uart_putc(0x30+file_res);
}
}
file_close();
}
file_close();
}
@ -269,13 +269,27 @@ uint32_t calc_sram_crc(uint32_t base_addr, uint32_t size) {
uint8_t sram_reliable() {
uint16_t score=0;
uint32_t val = sram_readlong(SRAM_SCRATCHPAD);
while(score<SRAM_RELIABILITY_SCORE) {
// uint32_t val = sram_readlong(SRAM_SCRATCHPAD);
uint8_t result = 0;
/* while(score<SRAM_RELIABILITY_SCORE) {
if(sram_readlong(SRAM_SCRATCHPAD)==val) {
score++;
} else {
set_pwr_led(0);
score=0;
}
}*/
for(uint16_t i = 0; i < SRAM_RELIABILITY_SCORE; i++) {
if(sram_readlong(SRAM_SCRATCHPAD)==0x12345678) {
score++;
}
}
return 1;
if(score<SRAM_RELIABILITY_SCORE) {
result = 0;
dprintf("score=%d\n", score);
} else {
result = 1;
}
set_pwr_led(result);
return result;
}

View File

@ -56,13 +56,15 @@ uint8_t get_snes_reset() {
* monitors SRAM changes and other things
*/
uint32_t diffcount = 0, samecount = 0;
uint8_t sram_valid = 0;
void snes_main_loop() {
if(initloop) {
saveram_crc_old = calc_sram_crc(saveram_base_addr, saveram_size);
initloop=0;
}
saveram_crc = calc_sram_crc(saveram_base_addr, saveram_size);
if(crc_valid) {
sram_valid = sram_reliable();
if(crc_valid && sram_valid) {
if(saveram_crc != saveram_crc_old) {
if(samecount) {
diffcount=1;
@ -84,7 +86,7 @@ void snes_main_loop() {
}
saveram_crc_old = saveram_crc;
}
dprintf("valid=%d diffcount=%ld samecount=%ld\n", crc_valid, diffcount, samecount);
dprintf("crc_valid=%d sram_valid=%d diffcount=%ld samecount=%ld\n", crc_valid, sram_valid, diffcount, samecount);
}
/*
@ -96,6 +98,7 @@ uint8_t menu_main_loop() {
sram_writebyte(0, SRAM_CMD_ADDR);
while(!cmd) {
if(!get_snes_reset()) {
while(!sram_reliable());
cmd = sram_readbyte(SRAM_CMD_ADDR);
}
if(get_snes_reset()) {