From 3b4b1b80691f7667f52ee02265e569f00463fc78 Mon Sep 17 00:00:00 2001 From: ikari Date: Wed, 4 Nov 2009 19:11:10 +0100 Subject: [PATCH] menu progress, led pwm, db tweaks --- snes/Makefile | 2 +- snes/data.a65 | 18 +++++++++--------- snes/header.a65 | 2 +- snes/main.a65 | 19 ++++++++++--------- snes/reset.a65 | 20 ++++++++++++-------- src/ff.c | 12 ++++++------ src/led.c | 48 +++++++++++++++++++++++++++++++++++------------- src/led.h | 7 ++++--- src/main.c | 15 +++++++++------ src/memory.c | 5 +++-- src/sdcard.c | 6 ++++-- 11 files changed, 94 insertions(+), 60 deletions(-) diff --git a/snes/Makefile b/snes/Makefile index 92fb41a..12389b3 100644 --- a/snes/Makefile +++ b/snes/Makefile @@ -1,4 +1,4 @@ -OBJS = header.ips reset.o65 main.o65 font.o65 palette.o65 data.o65 const.o65 logo.o65 text.o65 dma.o65 # gfx.o65 # vars.o65 +OBJS = header.ips reset.o65 main.o65 font.o65 palette.o65 data.o65 const.o65 logo.o65 text.o65 dma.o65 menu.o65 # gfx.o65 # vars.o65 all: menu.bin diff --git a/snes/data.a65 b/snes/data.a65 index 061c977..a2cdc50 100644 --- a/snes/data.a65 +++ b/snes/data.a65 @@ -1,6 +1,13 @@ .data ;don't anger the stack! -;padding is necessary because snescom wouldn't heed *=$7E0200. +dirlog .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 stack .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 @@ -9,14 +16,6 @@ stack .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 - .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 - .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 - .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 - .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 - .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 - .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 - .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 - .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ;----------parameters for text output---------- print_x .byt 0 ;x coordinate @@ -35,6 +34,7 @@ dma_len .word 0 dma_mode .byt 0 ;----------state information---------- +isr_done .byt 0 ; isr done flag bar_xl .byt 0 ; logical x position of select bar bar_yl .byt 0 ; logical y position of select bar bar_x .byt 0 ; pixel x position of select bar diff --git a/snes/header.a65 b/snes/header.a65 index 4774bdd..f3c93b9 100644 --- a/snes/header.a65 +++ b/snes/header.a65 @@ -45,7 +45,7 @@ NMI_8bit: *= $C0FFB0 -.byt "01" ;2 bytes - company id +.byt "MR" ;2 bytes - company id .byt "SNSD" ;4 bytes - rom id *= $C0FFC0 diff --git a/snes/main.a65 b/snes/main.a65 index 8a8ddc6..8a7fcd9 100644 --- a/snes/main.a65 +++ b/snes/main.a65 @@ -8,17 +8,16 @@ GAME_MAIN: jsr setup_hdma jsr tests jsr colortest + sep #$20 : .as lda #$00 - sta @$306000 - lda #$50 - sta @$306001 - lda #$11 - sta @$306002 - lda #$00 - sta @$306003 - lda #$01 - sta @$306004 + sta @$AVR_CMD + sta @$AVR_BANK + rep #$20 : .al + sta @$AVR_ADDR + sep #$20 : .as + jsr menuloop cli + stz $4200 jmp @infloop ;infinite loop in WRAM colortest: @@ -163,6 +162,8 @@ tests: sta print_bank stx print_src jsr loprint + lda #10 + sta bar_yl rts snes_init: diff --git a/snes/reset.a65 b/snes/reset.a65 index 0c66fe5..4a9dc5b 100644 --- a/snes/reset.a65 +++ b/snes/reset.a65 @@ -23,17 +23,19 @@ NMI_ROUTINE: 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, #$380*2-64*10, #^BG2_TILE_BUF, #!BG2_TILE_BUF+64*10, #$18) ldx #BG2_TILE_BASE stx $2116 - DMA0(#$01, #64*10, #^BG2_TILE_BUF, #!BG2_TILE_BUF, #$18); + DMA0(#$01, #64*10, #^BG2_TILE_BUF, #!BG2_TILE_BUF, #$18) + + lda bar_yl + asl + asl + asl + sta bar_y lda bar_y - inc - bne + - inc -+ cmp #224 bne + lda #1 @@ -47,16 +49,18 @@ NMI_ROUTINE: bra math_cont lower_half clc - sbc #111 + sbc #110 sta hdma_math+3 lda #112 sta hdma_math math_cont lda #$3e ; ch. 1-5 sta @$420c ; trigger HDMA + lda #$01 + sta isr_done rtl -; IRQ - called when triggered (which is..?) +; IRQ - called when triggered IRQ_ROUTINE: sep #$20 : .as lda $4211 ;Acknowledge irq diff --git a/src/ff.c b/src/ff.c index 0eb4e36..432b640 100644 --- a/src/ff.c +++ b/src/ff.c @@ -59,7 +59,7 @@ #include "config.h" #include "ff.h" /* FatFs declarations */ #include "diskio.h" /* Include file for user provided disk functions */ - +#include "uart.h" /*-------------------------------------------------------------------------- @@ -1651,7 +1651,7 @@ FRESULT f_write ( *bw = 0; res = validate(fs /*, fp->id*/); /* Check validity of the object */ if (res != FR_OK) return res; - if (fp->flag & FA__ERROR) return FR_RW_ERROR; /* Check error flag */ + if (fp->flag & FA__ERROR) {dprintf("fp->flag & FA__ERROR \n"); return FR_RW_ERROR;} /* Check error flag */ if (!(fp->flag & FA_WRITE)) return FR_DENIED; /* Check access mode */ if (fp->fsize + btw < fp->fsize) return FR_OK; /* File size cannot reach 4GB */ @@ -1669,18 +1669,18 @@ FRESULT f_write ( clust = create_chain(fs, fp->curr_clust); /* Trace or streach cluster chain */ } if (clust == 0) break; /* Disk full */ - if (clust == 1 || clust >= fs->max_clust) goto fw_error; + if (clust == 1 || clust >= fs->max_clust) { dprintf("cluster alloc error\n"); goto fw_error; } fp->curr_clust = clust; /* Current cluster */ sect = clust2sect(fs, clust); /* Get current sector */ fp->csect = fs->csize; /* Re-initialize the left sector counter */ } - if(!move_fp_window(fp,0)) goto fw_error; + if(!move_fp_window(fp,0)) {dprintf("move_fp_window error\n"); goto fw_error;} fp->curr_sect = sect; /* Update current sector */ cc = btw / SS(fs); /* When left bytes >= SS(fs), */ if (cc) { /* Write maximum contiguous sectors directly */ if (cc > fp->csect) cc = fp->csect; if (disk_write(fs->drive, wbuff, sect, (BYTE)cc) != RES_OK) - goto fw_error; +{ dprintf("disk_write error\n"); goto fw_error;} fp->csect -= (BYTE)(cc - 1); fp->curr_sect += cc - 1; wcnt = cc * SS(fs); @@ -1695,7 +1695,7 @@ FRESULT f_write ( fp->fptr < fp->fsize && /* Fill sector buffer with file data if needed */ #endif !move_fp_window(fp,fp->curr_sect)) - goto fw_error; +{ dprintf("fract write error\n "); goto fw_error; } memcpy(&FPBUF.data[fp->fptr & (SS(fs) - 1)], wbuff, wcnt); FPBUF.dirty=TRUE; } diff --git a/src/led.c b/src/led.c index a787b71..3ca911a 100644 --- a/src/led.c +++ b/src/led.c @@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - led.c: Overdesigned LED handling + led.c: LED handling */ @@ -28,19 +28,11 @@ #include "config.h" #include "led.h" -volatile uint8_t led_state; +static uint8_t led_bright[16]={255,253,252,251,249,247,244,239,232,223,210,191,165,127,74,0}; +static uint8_t curr_bright = 0; +static uint8_t led_bounce_dir = 0; -/** - * update_leds - set LEDs to correspond to the buffer status - * - * This function sets the busy/dirty LEDs to correspond to the current state - * of the buffers, i.e. busy on of at least one non-system buffer is - * allocated and dirty on if at least one buffer is allocated for writing. - * Call if you have manually changed the LEDs and you want to restore the - * "default" state. - */ -void update_leds(void) { -} +volatile uint8_t led_state; void toggle_busy_led(void) { PORTB &= ~_BV(PB3); @@ -64,3 +56,33 @@ void set_pwr_led(uint8_t state) { DDRB &= ~_BV(PB0); } } + +void set_busy_pwm(uint8_t brightness) { + OCR0A = led_bright[brightness]; + set_busy_led(1); +} + +void bounce_busy_led() { + set_busy_pwm(curr_bright); + if(led_bounce_dir) { + curr_bright--; + if(curr_bright==0) { + led_bounce_dir = 0; + } + } else { + curr_bright++; + if(curr_bright==15) { + led_bounce_dir = 1; + } + } +} + +void led_pwm() { + set_busy_led(1); + TCCR0A = 0x83; + TCCR0B = 0x01; +} + +void led_std() { + TCCR0A = 0; +} diff --git a/src/led.h b/src/led.h index 4afe06e..ee2ab2c 100644 --- a/src/led.h +++ b/src/led.h @@ -38,10 +38,11 @@ extern volatile uint8_t led_state; /* Update the LEDs to match the buffer state */ -void update_leds(void); void toggle_busy_led(void); void set_busy_led(uint8_t); void set_pwr_led(uint8_t); - - +void set_busy_pwm(uint8_t brightness); +void bounce_busy_led(void); +void led_pwm(void); +void led_std(void); #endif diff --git a/src/main.c b/src/main.c index 13b037e..61ff2e6 100644 --- a/src/main.c +++ b/src/main.c @@ -159,8 +159,11 @@ int main(void) { uint16_t curr_dir_id = scan_dir(fs_path, 0); // generate files footprint dprintf("curr dir id = %x\n", curr_dir_id); uint16_t saved_dir_id; + + led_pwm(); + if((get_db_id(&saved_dir_id) != FR_OK) // no database? - || 1 || saved_dir_id != curr_dir_id) { // files changed? // XXX + || saved_dir_id != curr_dir_id) { // files changed? // XXX dprintf("saved dir id = %x\n", saved_dir_id); _delay_ms(50); dprintf("rebuilding database..."); @@ -181,12 +184,12 @@ int main(void) { load_sram((uint8_t*)"/sd2snes/sd2snes.dir", SRAM_DIR_ADDR); } - uart_putc('['); - load_sram((uint8_t*)"/test.srm", SRAM_SAVE_ADDR); - uart_putc(']'); +// uart_putc('['); +// load_sram((uint8_t*)"/test.srm", SRAM_SAVE_ADDR); +// uart_putc(']'); uart_putc('('); - load_rom((uint8_t*)"/test.smc"); + load_rom((uint8_t*)"/sd2snes/menu.bin"); uart_putc(')'); sram_writebyte(0, SRAM_CMD_ADDR); @@ -210,7 +213,7 @@ int main(void) { _delay_ms(100); // snes_reset(1); set_avr_ena(0); - dprintf("%s\n", file_lfn); + dprintf("Selected name: %s\n", file_lfn); load_rom(file_lfn); set_avr_ena(1); snes_reset(1); diff --git a/src/memory.c b/src/memory.c index bcc7dab..115c63f 100644 --- a/src/memory.c +++ b/src/memory.c @@ -123,8 +123,9 @@ uint32_t load_rom(uint8_t* filename) { if (file_res || !bytes_read) break; FPGA_SS_LOW(); spiTransferByte(0x91); // write w/ increment - if(!(count++ % 16)) { - toggle_busy_led(); + if(!(count++ % 8)) { +// toggle_busy_led(); + bounce_busy_led(); uart_putc('.'); } for(int j=0; j