Changeset 1b74fa2 in thomson for code/C/HxCHost/main.c
- Timestamp:
- Mar 10, 2012, 2:46:13 PM (12 years ago)
- Branches:
- main
- Children:
- ee447bf
- Parents:
- 53c4be3
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note:
See TracChangeset
for help on using the changeset viewer.