浏览代码

ROM launching

ikari 14 年之前
父节点
当前提交
32fb6f3188
共有 5 个文件被更改,包括 39 次插入9 次删除
  1. 3 2
      snes/main.a65
  2. 14 0
      snes/menu.a65
  3. 18 3
      src/filetypes.c
  4. 2 2
      src/main.c
  5. 2 2
      src/memory.h

+ 3 - 2
snes/main.a65

@@ -11,9 +11,10 @@ GAME_MAIN:
 	sep #$20 : .as
 	lda #$00
 	sta @AVR_CMD
-	sta @AVR_PARAM
 	rep #$20 : .al
-	sta @AVR_PARAM+1
+	lda #$0000
+	sta @AVR_PARAM
+	sta @AVR_PARAM+2
 	jsr menu_init
 	sep #$20 : .as
 	jsr menuloop

+ 14 - 0
snes/menu.a65

@@ -384,6 +384,18 @@ sel_is_dir
 
 select_file:
 	; have avr load the rom
+	sta @$fffffe
+	dey
+	lda (dirptr_addr), y
+	sta @AVR_PARAM+2
+	rep #$20 : .al
+	dey
+	dey
+	lda (dirptr_addr), y
+	sta @AVR_PARAM
+	sep #$20 : .as
+	lda #$01
+	sta @AVR_CMD
 	rts
 
 select_dir: ; y = direntry ptr
@@ -413,6 +425,8 @@ select_dir: ; y = direntry ptr
 	lda !0, x ; load linked dir start address
 	sta @dirptr_addr
 	sta @dirstart_addr
+	lda #$0000
+	sta @menu_sel
 	sep #$20 : .as
 	lda #$01
 	sta @menu_dirty

+ 18 - 3
src/filetypes.c

@@ -41,6 +41,7 @@ uint16_t scan_dir(char* path, char mkdb, uint32_t this_dir_tgt) {
 	static uint16_t crc;
 	static uint32_t db_tgt;
 	static uint32_t next_subdir_tgt;
+	static uint32_t parent_tgt;
 	static uint32_t dir_end = 0;
 	static uint8_t was_empty = 0;
 	uint32_t dir_tgt;
@@ -54,6 +55,8 @@ uint16_t scan_dir(char* path, char mkdb, uint32_t this_dir_tgt) {
 		db_tgt = SRAM_DB_ADDR+0x10;
 		dir_tgt = SRAM_DIR_ADDR;
 		next_subdir_tgt = SRAM_DIR_ADDR;
+		this_dir_tgt = SRAM_DIR_ADDR;
+		parent_tgt = 0;
 		dprintf("root dir @%lx\n", dir_tgt);
 	}	
 	
@@ -64,10 +67,11 @@ uint16_t scan_dir(char* path, char mkdb, uint32_t this_dir_tgt) {
 			dirsize = 4*(numentries);
 //			dir_tgt_next = dir_tgt + dirsize + 4; // number of entries + end marker
 			next_subdir_tgt += dirsize + 4;
+			if(parent_tgt) next_subdir_tgt += 4;
 			if(next_subdir_tgt > dir_end) {
 				dir_end = next_subdir_tgt;
 			}
-			dprintf("path=%s depth=%d ptr=%lx entries=%d next subdir @%lx\n", path, depth, db_tgt, numentries, next_subdir_tgt /*dir_tgt_next*/);
+			dprintf("path=%s depth=%d ptr=%lx entries=%d parent=%lx next subdir @%lx\n", path, depth, db_tgt, numentries, parent_tgt, next_subdir_tgt /*dir_tgt_next*/);
 //			_delay_ms(50);
 			if(mkdb) {
 				dprintf("d=%d Saving %lX to Address %lX  [end]\n", depth, 0L, next_subdir_tgt - 4);
@@ -77,6 +81,15 @@ uint16_t scan_dir(char* path, char mkdb, uint32_t this_dir_tgt) {
 		}
 		res = f_opendir(&dir, (unsigned char*)path);
 		if (res == FR_OK) {
+			if(pass && parent_tgt) {
+				// write backlink to parent dir
+				sram_writelong(parent_tgt, db_tgt);
+				sram_writebyte(0, db_tgt+sizeof(next_subdir_tgt));
+				sram_writeblock("../\0", db_tgt+sizeof(next_subdir_tgt)+sizeof(len), 4);
+				sram_writelong(db_tgt|((uint32_t)0x80<<24), dir_tgt);
+				db_tgt += sizeof(next_subdir_tgt)+sizeof(len)+4;
+				dir_tgt += 4;
+			}
 			len = strlen((char*)path);
 			for (;;) {
 				toggle_busy_led();
@@ -112,10 +125,12 @@ uint16_t scan_dir(char* path, char mkdb, uint32_t this_dir_tgt) {
 //							_delay_ms(100);
 							sram_writelong(next_subdir_tgt, db_tgt);
 							sram_writebyte(len+1, db_tgt+sizeof(next_subdir_tgt));
-							sram_writeblock(path, db_tgt+sizeof(next_subdir_tgt)+sizeof(len), pathlen + 1);
+							sram_writeblock(path, db_tgt+sizeof(next_subdir_tgt)+sizeof(len), pathlen);
+							sram_writeblock("/\0", db_tgt + sizeof(next_subdir_tgt) + sizeof(len) + pathlen, 2);
 //							sram_writeblock((uint8_t*)&dir_tgt, db_tgt+256, sizeof(dir_tgt));
-							db_tgt += sizeof(next_subdir_tgt) + sizeof(len) + pathlen + 1;
+							db_tgt += sizeof(next_subdir_tgt) + sizeof(len) + pathlen + 2;
 						}
+						parent_tgt = this_dir_tgt;
 						scan_dir(path, mkdb, next_subdir_tgt);
 						dir_tgt += 4;
 //						if(was_empty)dir_tgt_next += 4;

+ 2 - 2
src/main.c

@@ -163,7 +163,7 @@ int main(void) {
 	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...");
@@ -214,7 +214,7 @@ int main(void) {
 				_delay_ms(100);
 //				snes_reset(1);
 				set_avr_ena(0);
-				dprintf("Selected name: %s\n", file_lfn);
+//				dprintf("Selected name: %s\n", file_lfn);
 				load_rom(file_lfn);
 				set_avr_ena(1);
 				snes_reset(1);

+ 2 - 2
src/memory.h

@@ -7,8 +7,8 @@
 #define SRAM_WORK_ADDR	(0x100000L)
 #define SRAM_DB_ADDR (0x080000L)
 #define SRAM_DIR_ADDR (0x300000L)
-#define SRAM_CMD_ADDR (0x600004L)
-#define SRAM_FD_ADDR (0x600000L)
+#define SRAM_CMD_ADDR (0x601004L)
+#define SRAM_FD_ADDR (0x601000L)
 #define SRAM_SAVE_ADDR (0x600000L)
 #define SRAM_SCRATCHPAD (0x7FFFF0L)
 #define SRAM_RELIABILITY_SCORE (0x100)