Changeset 1b74fa2 in thomson
- Timestamp:
- Mar 10, 2012, 2:46:13 PM (12 years ago)
- Branches:
- main
- Children:
- ee447bf
- Parents:
- 53c4be3
- Location:
- code/C/HxCHost
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/C/HxCHost/Makefile
r53c4be3 r1b74fa2 27 27 # Linking 28 28 TEST.BIN: $(OBJECTS) 29 $(CC) -Os $(OBJECTS) -o TEST.BIN -Wl,--map -Wl,-Ttext,0x 7100 -nostdlib -lgcc29 $(CC) -Os $(OBJECTS) -o TEST.BIN -Wl,--map -Wl,-Ttext,0x6100 -nostdlib -lgcc 30 30 31 31 #Compiling 32 obj/$(TARGET)/%.o: %.c 32 obj/$(TARGET)/%.o: %.c obj/$(TARGET) 33 33 $(CC) $(CFLAGS) -c $< -o $@ 34 34 35 obj/$(TARGET)/%.o: pff/%.c 35 obj/$(TARGET)/%.o: pff/%.c obj/$(TARGET) 36 36 $(CC) $(CFLAGS) -c $< -o $@ 37 37 38 obj/$(TARGET)/%.o: %.s 38 obj/$(TARGET)/%.o: %.s obj/$(TARGET) 39 39 $(AS) $< -o $@ 40 41 # init 42 obj/$(TARGET): 43 mkdir -p obj/$(TARGET) -
code/C/HxCHost/main.c
r53c4be3 r1b74fa2 18 18 unsigned char mark[512 + 16] = "HxCFEDA"; 19 19 unsigned char* secbuf = mark+16; 20 21 const char* HXCSDFECFG = "HXCTEST.CFG"; 20 22 21 23 void printhex(unsigned char n) … … 89 91 } 90 92 91 int main(void) 93 struct opt 94 { 95 char* name; 96 BYTE off; 97 BYTE type; 98 }; 99 100 static const struct opt options[7] = 101 { 102 {"\x1B\x50\x0CHxC floppy emulator setup\r\n" 103 "UP/DOWN move - +/- change\r\n" 104 "space save - left quit\r\n" 105 "Step sound ", 16, 0}, 106 {"\r\nGUI sound ", 17, 0}, 107 {"\r\nBacklight delay ", 18, 1}, 108 {"\r\nStandby delay ", 19, 1}, 109 {"\r\nDrive selector ", 20, 0}, 110 {"\r\nLoad last floppy ", 26, 0}, 111 {"\r\nLCD scroll speed ", 28, 1}, 112 }; 113 114 inline static void config() 115 { 116 // If it's HXCSDFE.CFG, enter config mode 117 // Read the config part of the file 118 WORD byteCount = 29; 119 FRESULT r = pf_read(secbuf, byteCount, &byteCount); 120 if (r != 0 || byteCount != 29) 121 { 122 my_puts("read error"); 123 abort(); 124 } 125 126 BYTE selected; 127 for(;;) { 128 for (int j = 0; j < 7; j++) 129 { 130 my_puts(options[j].name); 131 mon_putc(0x1B); // Select back color 132 mon_putc(selected == j ? 0x54: 0x50) // Blue 133 if(options[j].type) 134 printhex(*(secbuf+options[j].off)); 135 else 136 my_puts(*(secbuf+options[j].off) ? "ON":"OFF"); 137 mon_putc(0x1B); // Select back color 138 mon_putc(0x50); // Select back color 139 } 140 141 do { 142 asm("SWI \t \t;\n" 143 ".fcb \t0x0A\t;GETC\n"); 144 } while(KEY == 0); 145 146 switch(KEY) 147 { 148 case 0x08: // UP 149 // select next file 150 if (selected != 0) --selected; 151 // TODO next page ? 152 break; 153 154 case 0x19: // SPACE 155 // save configuration 156 r = pf_open(HXCSDFECFG); 157 if (r) { 158 my_puts("can't open cfg"); 159 printhex(r); 160 } 161 byteCount = 29; 162 r = pf_write(secbuf, byteCount, &byteCount); 163 if (r || byteCount != 29) { 164 my_puts("can't write cfg"); 165 printhex(r); 166 } 167 r = pf_write(0, 0, &byteCount); // flush sector 168 if (r) { 169 my_puts("can't close cfg"); 170 printhex(r); 171 } 172 // fall through 173 case 0x10: // LEFT 174 // Quit (without saving) 175 return; 176 break; 177 178 case 0x18: // DOWN 179 // select previous file 180 if (++selected > 7) selected = 7; 181 // TODO previous page ? 182 break; 183 case 0x13: // - 184 // decrease current option value 185 if(options[selected].type) 186 --*(secbuf+options[selected].off); 187 else 188 *(secbuf+options[selected].off) = 0; 189 break; 190 case 0x0B: // + 191 if(options[selected].type) 192 ++*(secbuf+options[selected].off); 193 else 194 *(secbuf+options[selected].off) = 0xFF; 195 break; 196 } 197 } 198 } 199 200 int __attribute__((noreturn)) main(void) 92 201 { 93 202 // Detect HxC and print version code … … 106 215 } 107 216 108 mon_putc('z'); 217 // Enter "fixed timings" mode - make sure track 255 sends index pulses 218 // every 200ms. Makes everything a bit slower, but the CD90-640 ROM 219 // requires it. 220 int j = 8; 221 mark[j++] = 3; 222 mark[j++] = 0xFF; 223 for(; j <512; j++) mark[j] = 0; 224 write(255,0,mark); 109 225 110 226 // Open root directory 111 227 pf_opendir(&d, ""); 112 mon_putc('y');113 228 114 229 // List files 115 230 ls(DIRECTORY_BUFFER); 116 mon_putc('x');117 231 118 232 int selected = 0; … … 183 297 ls(DIRECTORY_BUFFER); 184 298 } else { 185 // TODO file open 186 // If it's HXCSDFE.CFG, enter config mode 187 // If it's a file, load it in HxCSDFE.CFG, then reboot 299 const char* cmp = HXCSDFECFG; 300 FRESULT res = pf_open(cmp); 301 if (res) { 302 my_puts("Can't open CFG file: "); 303 printhex(res); 304 exit(0); 305 } 306 if (*(long*)(fp->fname) == *(long*)(cmp) 307 && *(long*)(fp->fname + 4) == *(long*)(cmp+4) 308 && *(long*)(fp->fname + 8) == *(long*)(cmp+8) 309 ) 310 { 311 config(); 312 } else { 313 my_puts("LOADING FILE"); 314 // If it's an HFE file, load it in HxCSDFE.CFG, then reboot 315 316 // reboot 317 exit(0); 318 } 188 319 } 189 320 break; … … 194 325 } 195 326 } 196 197 // Leave LBA mode 198 /* 199 200 */ 201 202 // Reboot 203 exit(0); 204 } 327 } -
code/C/HxCHost/pff/diskio.c
r53c4be3 r1b74fa2 12 12 extern unsigned char* secbuf; 13 13 extern unsigned char mark[]; 14 15 static DWORD prevsec = -1; 14 16 /*******/ 15 17 … … 35 37 36 38 39 void map_sector(DWORD sector, BYTE write) 40 { 41 // Set LBA address 42 int j = 8; 43 mark[j++] = 1; 44 mark[j++] = sector; 45 mark[j++] = (sector>>8); 46 mark[j++] = (sector>>16); 47 mark[j++] = (sector>>24); 48 mark[j++] = write; 49 mark[j++] = 1; // Sector count 50 // BEWARE of changing this to something else than 1 ! 51 // In write burst mode it could erase all the sectors you don't rewrite 52 53 // TODO extract a send_hxc_command function from this 54 for(; j <512; j++) mark[j] = 0; 55 write(255,0,mark); 56 } 57 37 58 38 59 /*-----------------------------------------------------------------------*/ … … 47 68 ) 48 69 { 49 static DWORD prevsec = -1;50 70 // TODO implement caching system 51 71 // * If sector is reachable with current LBA, don't change it 52 72 53 printhex(sector>>24);54 printhex(sector>>16);55 printhex(sector>>8);56 printhex(sector);57 mon_putc(' ');58 59 73 if (prevsec != sector) 60 74 { 61 62 // Set LBA address 63 int j = 8; 64 mark[j++] = 1; 65 mark[j++] = sector; 66 mark[j++] = (sector>>8); 67 mark[j++] = (sector>>16); 68 mark[j++] = (sector>>24); 69 mark[j++] = 0; // Write disabled 70 mark[j++] = 6; // Sector count 71 for(; j <512; j++) mark[j] = 0; 72 write(255,0,mark); 73 75 map_sector(sector, 0); 74 76 prevsec = sector; 75 77 // Read sector … … 98 100 ) 99 101 { 100 // TODO write it 101 // Beware of using the sector buffer, read is doing caching there... 102 DRESULT res = RES_ERROR; 103 102 static WORD ptr; 103 static char* wrbuf[256]; 104 // Separate buffer because we need to use map_sector, and it kills secbuf 104 105 105 106 if (!buff) { 106 107 if (sc) { 108 mon_putc('A'); 109 // Initiate write process 110 prevsec = sc; 111 ptr = 0; 112 } else { 113 mon_putc('C'); 114 mon_putc(' '); 115 printhex(ptr); 116 // Called with both param = 0 - flush buffer to disk 117 // First make sure it's zero-filled 118 for(;ptr < 512; ++ptr) 119 { 120 *(wrbuf + ptr) = 0; 121 } 107 122 108 // Initiate write process 123 // map in the sector (no need to read from SD) 124 map_sector(prevsec, 0xA5); 109 125 110 } else { 126 for(int j = 0; j < 40; j++) 127 printhex(*(char*)(wrbuf + j)); 111 128 112 // Finalize write process 113 129 write(255,1,wrbuf); 114 130 } 115 131 } else { 116 117 // Send data to the disk 118 132 mon_putc('B'); 133 // Here SC is a bytecount. copy that much bytes to the buffer 134 for(int j = 0; j <sc;++j) 135 { 136 *(char*)(wrbuf+ptr) = *(char*)(ptr++ + buff); 137 } 119 138 } 120 139 121 return res;140 return RES_OK; 122 141 } 123 142
Note:
See TracChangeset
for help on using the changeset viewer.