Ver código fonte

bugfix map detect, configurable work address

ikari 14 anos atrás
pai
commit
aacabe41ad
5 arquivos alterados com 28 adições e 17 exclusões
  1. 3 0
      src/fileops.c
  2. 2 2
      src/filetypes.c
  3. 12 11
      src/main.c
  4. 3 0
      src/memory.h
  5. 8 4
      src/smc.c

+ 3 - 0
src/fileops.c

@@ -41,6 +41,9 @@ UINT file_write() {
 UINT file_readblock(void* buf, uint32_t addr, uint16_t size) {
 	UINT bytes_read;
 	file_res = f_lseek(&file_handle, addr);
+	if(file_handle.fptr != addr) {
+		return 0;
+	}
 	if(file_res) { dprintf("no lseek %d\n", file_res); _delay_ms(30); return 0;}
 	file_res = f_read(&file_handle, buf, size, &bytes_read);
 	if(file_res) { dprintf("no read %d\n", file_res); _delay_ms(30); }

+ 2 - 2
src/filetypes.c

@@ -25,7 +25,7 @@ uint16_t scan_dir(char* path, char mkdb) {
 	static uint32_t db_tgt;
 	if(depth==0) {
 		crc = 0;
-		db_tgt = 0x600010;
+		db_tgt = SRAM_WORK_ADDR+0x10;
 	}
 //	dprintf("path=%s depth=%d ptr=%lx\n", path, depth, db_tgt);
 //	_delay_ms(50);
@@ -93,7 +93,7 @@ uint16_t scan_dir(char* path, char mkdb) {
     } else uart_putc(0x30+res);
 //	dprintf("%x\n", crc);
 //	_delay_ms(50);
-	sram_writeblock(&db_tgt, 0x600004, sizeof(db_tgt));
+	sram_writeblock(&db_tgt, SRAM_WORK_ADDR+4, sizeof(db_tgt));
 	return crc;
 }
 

+ 12 - 11
src/main.c

@@ -152,14 +152,7 @@ int main(void) {
     set_avr_ena(0);
 	snes_reset(1);
 
-	uart_putc('(');
-	load_rom("/test.smc");
-	uart_putc(')');
-
-	uart_putc('[');
-	load_sram("/test.srm");
-	uart_putc(']');
-	*fs_path=0;
+    *fs_path=0;
 	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;
@@ -170,13 +163,21 @@ int main(void) {
 		dprintf("rebuilding database...");
 		_delay_ms(50);
 		curr_dir_id = scan_dir(fs_path, 1);	// then rebuild database
-		sram_writeblock(&curr_dir_id, 0x600000, 2);
+		sram_writeblock(&curr_dir_id, SRAM_WORK_ADDR, 2);
 		uint32_t endaddr;
-		sram_readblock(&endaddr, 0x600004, 4);
+		sram_readblock(&endaddr, SRAM_WORK_ADDR+4, 4);
 		dprintf("%lx\n", endaddr);
-		save_sram("/sd2snes/sd2snes.db", endaddr-0x600000, 0x600000);
+		save_sram("/sd2snes/sd2snes.db", endaddr-SRAM_WORK_ADDR, SRAM_WORK_ADDR);
 		dprintf("done\n"); 
 	}
+	uart_putc('[');
+	load_sram("/test.srm");
+	uart_putc(']');
+
+	uart_putc('(');
+	load_rom("/test.smc");
+	uart_putc(')');
+
 
 	set_busy_led(0);
 	set_avr_ena(1);

+ 3 - 0
src/memory.h

@@ -3,6 +3,9 @@
 
 #ifndef MEMORY_H
 #define MEMORY_H
+
+#define SRAM_WORK_ADDR	(0x100000L)
+
 	uint32_t load_rom(char* filename);
 	uint32_t load_sram(char* filename);
 	void sram_readblock(void* buf, uint32_t addr, uint16_t size);

+ 8 - 4
src/smc.c

@@ -58,14 +58,16 @@ void smc_id(snes_romprops_t* props) {
 	snes_header_t* header = &(props->header);
 	
 	for(uint8_t num = 0; num < 6; num++) {
-		file_readblock(header, hdr_addr[num], sizeof(snes_header_t));
-		if(file_res) {
-			dprintf("uh oh... %d\n", file_res);
-			_delay_ms(30);
+		if(!file_readblock(header, hdr_addr[num], sizeof(snes_header_t)) 
+		|| file_res) {
+//			dprintf("uh oh... %d\n", file_res);
+//			_delay_ms(30);
 			score = 0;
 		} else {
 			score = smc_headerscore(header);
 		}
+//		dprintf("%d: offset = %lX; score = %d\n", num, hdr_addr[num], score);
+//		_delay_ms(100);
 		if(score>=maxscore) {
 			score_idx=num;
 			maxscore=score;
@@ -79,6 +81,8 @@ void smc_id(snes_romprops_t* props) {
 	}
 	
 	// restore the chosen one
+//	dprintf("winner is %d\n", score_idx);
+//	_delay_ms(30);
 	file_readblock(header, hdr_addr[score_idx], sizeof(snes_header_t));
 	switch(header->map & 0xef) {
 		case 0x20: