Browse Source

Rev.B; dir structure

ikari 14 years ago
parent
commit
e999d052f0
7 changed files with 145 additions and 159 deletions
  1. 2 6
      snes/const.a65
  2. 17 2
      snes/data.a65
  3. 1 1
      src/config
  4. 119 59
      src/filetypes.c
  5. 2 88
      src/fpga.c
  6. 3 2
      src/main.c
  7. 1 1
      verilog/sd2snes/sd2snes.xise

+ 2 - 6
snes/const.a65

@@ -79,12 +79,8 @@ hdma_math_src	.byt 1
 		.byt $00, $e0
 		.byt 1
 		.byt $00, $e0
-		.byt 1
-		.byt $60, $bf
-		.byt 8
-		.byt $60, $b0
-		.byt 1
-		.byt $60, $bf
+		.byt 10
+		.byt $20, $f0
 		.byt 1
 		.byt $00, $e0
 		.byt 0

+ 17 - 2
snes/data.a65

@@ -35,9 +35,24 @@ dma_len		.word 0
 dma_mode	.byt 0
 
 ;----------state information----------
-bar_pos		.byt 0 ; y position of select bar
+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
+bar_y		.byt 0	; pixel y position of select bar
+bar_w		.byt 0	; bar width
+fd_addr		.word 0	; address of current "file descriptor"
+fd_bank		.byt 0	; bank of current "file descriptor"
+file_path		; assembled current path
+		.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
 
-;----------hdma values in RAM
+;----------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
 		.byt 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

+ 1 - 1
src/config

@@ -35,7 +35,7 @@ CONFIG_UART_BAUDRATE=38400
 CONFIG_UART_BUF_SHIFT=7
 CONFIG_HARDWARE_NAME=sd2snes
 CONFIG_SD_AUTO_RETRIES=10
-CONFIG_SD_DATACRC=y
+#CONFIG_SD_DATACRC=y
 CONFIG_EEPROM_SIZE=512
 CONFIG_EEPROM_OFFSET=512
 CONFIG_MAX_PARTITIONS=1

+ 119 - 59
src/filetypes.c

@@ -13,84 +13,144 @@
 #include "crc16.h"
 #include "memory.h"
 
+uint16_t scan_flat(const char* path) {
+	DIR dir;
+	FRESULT res;
+	FILINFO fno;
+	fno.lfn = NULL;
+	res = f_opendir(&dir, (unsigned char*)path);
+	uint16_t numentries = 0;
+	if (res == FR_OK) {
+		for (;;) {
+			res = f_readdir(&dir, &fno);
+			if(res != FR_OK || fno.fname[0] == 0)break;
+			numentries++;
+		}
+	}
+	return numentries;
+}
+
 uint16_t scan_dir(char* path, char mkdb) {
 	DIR dir;
 	FILINFO fno;
 	FRESULT res;
-    int len;
+	int len;
 	unsigned char* fn;
 	static unsigned char lfn[256];
 	static unsigned char depth = 0;
 	static uint16_t crc;
 	static uint32_t db_tgt;
+	static uint32_t dir_tgt;
+	uint32_t dir_tgt_save, dir_tgt_next;
+	uint16_t numentries;
+	uint32_t dirsize;
+	uint8_t pass = 0;
+
 	if(depth==0) {
 		crc = 0;
-		db_tgt = SRAM_WORK_ADDR+0x10;
-	}
-//	dprintf("path=%s depth=%d ptr=%lx\n", path, depth, db_tgt);
-//	_delay_ms(50);
+		db_tgt = SRAM_WORK_ADDR+0x200;
+		dir_tgt = SRAM_WORK_ADDR+0x100000;
+		dprintf("root dir @%lx\n", dir_tgt);
+	}	
+	
 	fno.lfn = lfn;
-    res = f_opendir(&dir, (unsigned char*)path);
-    if (res == FR_OK) {
-        len = strlen((char*)path);
-        for (;;) {
-            res = f_readdir(&dir, &fno);
-            if (res != FR_OK || fno.fname[0] == 0) break;
-            fn = *fno.lfn ? fno.lfn : fno.fname;
-//			dprintf("%s\n", fn);
-//			_delay_ms(100);
-            if (*fn == '.') continue;
-            if (fno.fattrib & AM_DIR) {
-				path[len]='/';
-                strncpy(path+len+1, (char*)fn, sizeof(fs_path)-len);
-				depth++;
-                scan_dir(path, mkdb);
-				depth--;
-				path[len]=0;
-//                if (res != FR_OK) {
-//					break;
-//				}
-            } else {
-				SNES_FTYPE type = determine_filetype((char*)fn);
-				if(type != TYPE_UNKNOWN) {
-					if(mkdb) {
-						snes_romprops_t romprops;
+	numentries=0;
+	for(pass = 0; pass < 2; pass++) {
+		if(pass) {
+			dprintf("path=%s depth=%d ptr=%lx entries=%d next subdir @%lx\n", path, depth, db_tgt, numentries, numentries*4+dir_tgt);
+			_delay_ms(50);	
+		}
+		dirsize = 4*(numentries+1);
+		dir_tgt_next = dir_tgt + dirsize;
+		res = f_opendir(&dir, (unsigned char*)path);
+		if (res == FR_OK) {
+			len = strlen((char*)path);
+			for (;;) {
+				res = f_readdir(&dir, &fno);
+				if (res != FR_OK || fno.fname[0] == 0) break;
+				fn = *fno.lfn ? fno.lfn : fno.fname;
+	//			dprintf("%s\n", fn);
+	//			_delay_ms(100);
+				if (*fn == '.') continue;
+				if (fno.fattrib & AM_DIR) {
+					numentries++;
+					if(pass) {
 						path[len]='/';
 						strncpy(path+len+1, (char*)fn, sizeof(fs_path)-len);
-						switch(type) {
-							case TYPE_SMC:
-								file_open_by_filinfo(&fno);
-								if(file_res){
-									dprintf("ZOMG NOOOO %d\n", file_res);
-									_delay_ms(30);
-								}
-								smc_id(&romprops);
-								file_close();
-								dprintf("%lx\n", db_tgt);
-//								_delay_ms(30);
-								sram_writeblock((uint8_t*)&romprops, db_tgt, sizeof(romprops));
-								sram_writeblock(path, db_tgt + sizeof(romprops), 256);
-								db_tgt += 0x140;
-								break;
-							case TYPE_UNKNOWN:
-							default:
-								break;
+						depth++;
+						dir_tgt_save = dir_tgt;
+						dir_tgt = dir_tgt_next;
+						if(mkdb) {
+							// write element pointer to current dir structure
+							dprintf("d=%d Saving %lX to Address %lX  [dir]\n", depth, db_tgt, dir_tgt_save);
+							_delay_ms(50);
+							sram_writeblock((uint8_t*)&db_tgt, dir_tgt_save, sizeof(dir_tgt_save));
+
+							// save element:
+							//  - path name
+							//  - pointer to sub dir structure
+							sram_writeblock(path, db_tgt, 256);
+							sram_writeblock((uint8_t*)&dir_tgt, db_tgt+256, sizeof(dir_tgt));
+							db_tgt += 0x200;
 						}
+						scan_dir(path, mkdb);
+						dir_tgt = dir_tgt_save;
+						dir_tgt += 4;
+						depth--;
 						path[len]=0;
-//						dprintf("%s ", path);
-//						_delay_ms(30);
 					}
-					unsigned char* sfn = fno.fname;
-					while(*sfn != 0) {
-						crc += crc16_update(crc, sfn++, 1);
+				} else {
+					SNES_FTYPE type = determine_filetype((char*)fn);
+					if(type != TYPE_UNKNOWN) {
+						numentries++;
+						if(pass) {
+							if(mkdb) {
+								snes_romprops_t romprops;
+								path[len]='/';
+								strncpy(path+len+1, (char*)fn, sizeof(fs_path)-len);
+								switch(type) {
+									case TYPE_SMC:
+										file_open_by_filinfo(&fno);
+										if(file_res){
+											dprintf("ZOMG NOOOO %d\n", file_res);
+											_delay_ms(30);
+										}
+										smc_id(&romprops);
+										file_close();
+		//								_delay_ms(30);
+										// write element pointer to current dir structure
+										dprintf("d=%d Saving %lX to Address %lX  [file]\n", depth, db_tgt, dir_tgt);
+										_delay_ms(50);
+										sram_writeblock((uint8_t*)&db_tgt, dir_tgt, sizeof(db_tgt));
+										dir_tgt += 4;
+										// save element:
+										//  - SNES header information
+										//  - file name
+										sram_writeblock((uint8_t*)&romprops, db_tgt, sizeof(romprops));
+										sram_writeblock(path, db_tgt + sizeof(romprops), 256);
+										db_tgt += 0x200;
+										break;
+									case TYPE_UNKNOWN:
+									default:
+										break;
+								}
+								path[len]=0;
+		//						dprintf("%s ", path);
+		//						_delay_ms(30);
+							}
+						} else {
+							unsigned char* sfn = fno.fname;
+							while(*sfn != 0) {
+								crc += crc16_update(crc, sfn++, 1);
+							}
+						}
 					}
+	//					dprintf("%s/%s\n", path, fn);
+	//					_delay_ms(50);
 				}
-//					dprintf("%s/%s\n", path, fn);
-//					_delay_ms(50);
-//				_delay_ms(10);
-            }
-        }
-    } else uart_putc(0x30+res);
+			}
+		} else uart_putc(0x30+res);
+	}
 //	dprintf("%x\n", crc);
 //	_delay_ms(50);
 	sram_writeblock(&db_tgt, SRAM_WORK_ADDR+4, sizeof(db_tgt));

+ 2 - 88
src/fpga.c

@@ -6,27 +6,6 @@
 
    FPGA pin mapping
    ================
- PSM:
- ====
-   FPGA			AVR		dir
-   ------------------------
-   PROG_B		PD3		OUT
-   CCLK			PD4		OUT
-   CS_B			PD7		OUT
-   INIT_B		PB2		IN
-   RDWR_B		PB3		OUT
-
-   D7			PC0		OUT
-   D6			PC1		OUT
-   D5			PC2		OUT
-   D4			PC3		OUT
-   D3			PC4		OUT
-   D2			PC5		OUT
-   D1			PC6		OUT
-   D0			PC7		OUT
-
- SSM:
- ====
    PROG_B		PD3		OUT
    CCLK			PD4		OUT
    INIT_B		PD7		IN
@@ -59,22 +38,6 @@ void set_prog_b(uint8_t val) {
 	}
 }
 
-void set_cs_b(uint8_t val) {
-	if(val) {
-		PORTD |= _BV(PD7);
-	} else {
-		PORTD &= ~_BV(PD7);
-	}
-}
-
-void set_rdwr_b(uint8_t val) {
-	if(val) {
-		PORTB |= _BV(PB3);
-	} else {
-		PORTB &= ~_BV(PB3);
-	}
-}
-
 void set_cclk(uint8_t val) {
 	if(val) {
 		PORTD |= _BV(PD4);
@@ -84,8 +47,6 @@ void set_cclk(uint8_t val) {
 }
 
 void fpga_init() {
-	DDRB |= _BV(PB3);	// PB3 is output
-
 	DDRD &= ~_BV(PD7);  // PD7 is input
 
 	DDRC = _BV(PC7);	// for FPGA config, PC7 is output
@@ -108,7 +69,7 @@ void fpga_postinit() {
 
 void fpga_pgm(char* filename) {
 	int MAXRETRIES = 10;
-//	int retries = MAXRETRIES;
+	int retries = MAXRETRIES;
 	do {
 		set_prog_b(0);
 		uart_putc('P');
@@ -125,9 +86,6 @@ void fpga_pgm(char* filename) {
 			uart_putc(0x30+file_res);
 			return;
 		}
-		// file open successful
-		set_cs_b(0);
-		set_rdwr_b(0);
 	
 		for (;;) {
 			bytes_read = file_read();
@@ -138,7 +96,7 @@ void fpga_pgm(char* filename) {
 		}
 		file_close();
 		_delay_ms(10);
-	} while (0); //(!fpga_get_done() && retries--);
+	} while (!fpga_get_done() && retries--);
 	if(!fpga_get_done()) {
 		dprintf("FPGA failed to configure after %d tries.\n", MAXRETRIES);
 		_delay_ms(50);
@@ -146,22 +104,6 @@ void fpga_pgm(char* filename) {
 	fpga_postinit();
 }
 
-void set_avr_read(uint8_t val) {
-	if(val) {
-		PORTB |= _BV(PB3);
-	} else {
-		PORTB &= ~_BV(PB3);
-	}
-}
-
-void set_avr_write(uint8_t val) {
-	if(val) {
-		PORTB |= _BV(PB2);
-	} else {
-		PORTB &= ~_BV(PB2);
-	}
-}
-
 void set_avr_ena(uint8_t val) {
 	if(val) {
 		PORTD |= _BV(PD7);
@@ -170,34 +112,6 @@ void set_avr_ena(uint8_t val) {
 	}
 }
 
-void set_avr_nextaddr(uint8_t val) {
-	if(val) {
-		PORTA |= _BV(PA4);
-	} else {
-		PORTA &= ~_BV(PA4);
-	}
-}
-
-void set_avr_addr_reset(uint8_t val) {
-	if(val) {
-		PORTA |= _BV(PA5);
-	} else {
-		PORTA &= ~_BV(PA5);
-	}
-}
-
-void set_avr_data(uint8_t data) {
-	PORTC = data;
-}
-
-void set_avr_addr_en(uint8_t val) {
-	if(val) {
-		PORTA |= _BV(PA6);
-	} else {
-		PORTA &= ~_BV(PA6);
-	}
-}
-
 void set_avr_mapper(uint8_t val) {
 	SPI_SS_HIGH();
 	FPGA_SS_LOW();

+ 3 - 2
src/main.c

@@ -127,11 +127,12 @@ int main(void) {
 #ifdef CLOCK_PRESCALE
 	clock_prescale_set(CLOCK_PRESCALE);
 #endif
+	set_pwr_led(0);
+	set_busy_led(1);
 	spi_none();
 	snes_reset(1);
 	uart_init();
 	sei();   // suspected to reset the AVR when inserting an SD card
-	set_busy_led(0);
 	_delay_ms(100);
 	disk_init();
 	snes_init();
@@ -158,7 +159,7 @@ int main(void) {
 	dprintf("curr dir id = %x\n", curr_dir_id);
 	uint16_t saved_dir_id;
 	if((get_db_id(&saved_dir_id) != FR_OK)	// no database?
-	|| saved_dir_id != curr_dir_id) {	// files changed?
+	|| 1 /*saved_dir_id != curr_dir_id*/) {	// files changed? // XXX
 		dprintf("saved dir id = %x\n", saved_dir_id);
 		_delay_ms(50);
 		dprintf("rebuilding database...");

+ 1 - 1
verilog/sd2snes/sd2snes.xise

@@ -73,7 +73,7 @@
     <property xil_pn:name="Constraints Entry" xil_pn:value="Constraints Editor"/>
     <property xil_pn:name="Device" xil_pn:value="xc3s200"/>
     <property xil_pn:name="Device Family" xil_pn:value="Spartan3"/>
-    <property xil_pn:name="Drive Done Pin High" xil_pn:value="true"/>
+    <property xil_pn:name="Enable BitStream Compression" xil_pn:value="true"/>
     <property xil_pn:name="Extra Effort" xil_pn:value="Normal"/>
     <property xil_pn:name="Extra Effort (Highest PAR level only)" xil_pn:value="Normal"/>
     <property xil_pn:name="Fitter Report Format" xil_pn:value="HTML"/>