Changeset 7cabd49 in thomson for code/C/HxCHost/main.c


Ignore:
Timestamp:
Mar 19, 2012, 7:51:49 AM (12 years ago)
Author:
Adrien Destugues <pulkomandy@…>
Branches:
main
Children:
fe55aa5
Parents:
cc8f3af
Message:

HxC host software : work at Forever XIII party

  • Switch to lwtools gcc toolchain
  • Fix some bugs.
  • Editing the HxC settings works
  • Selecting a floppy image works (sometimes)

git-svn-id: svn://localhost/thomson@24 85ae3b6b-dc8f-4344-a89d-598714f2e4e5

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/C/HxCHost/main.c

    rcc8f3af r7cabd49  
    99void asm_write();
    1010
    11 #if PLATFORM == 5
    12         #define DIRECTORY_BUFFER (FILINFO*)0x3000
    13 #else
    14         // Thomson TO8 code
    15         #define DIRECTORY_BUFFER (FILINFO*)0xA000
    16 #endif
     11FILINFO DIRECTORY_BUFFER[23];
    1712
    1813unsigned char mark[512 + 16] = "HxCFEDA";
     
    10297        {"\x1B\x50\x0CHxC floppy emulator setup\r\n"
    10398        "UP/DOWN move - +/- change\r\n"
    104         "space save - left quit\r\n"
     99        "space save - left quit\r\n\n"
    105100                 "Step sound       ", 16, 0},
    106101        {"\r\nGUI sound        ", 17, 0},
     
    112107};
    113108
     109#define getcfg(off) *(char*)((int)confbuf+off)
     110#define putcfg(off, val) *(char*)((int)confbuf+off) = val
     111
    114112inline static void config()
    115113{
    116         unsigned char* confbuf[29];
     114        char confbuf[29];
    117115        // If it's HXCSDFE.CFG, enter config mode
    118116        // Read the config part of the file
     
    121119        if (r != 0 || byteCount != 29)
    122120        {
    123                 my_puts("read error");
     121                my_puts("read error ");
     122                printhex(r);
    124123                abort();
    125124        }
     
    133132                        mon_putc(selected == j ? 0x54: 0x50) // Blue
    134133                        if(options[j].type)
    135                                 printhex(*(confbuf+options[j].off));
     134                                printhex(getcfg(options[j].off));
    136135                        else
    137                                 my_puts(*(confbuf+options[j].off) ? "ON":"OFF");
     136                                my_puts(getcfg(options[j].off) ? "ON":"OFF");
    138137                        mon_putc(0x1B); // Select back color
    139138                        mon_putc(0x50); // Select back color
     
    141140
    142141                do {
    143                         asm("SWI \t    \t;\n"
    144                                 ".fcb \t0x0A\t;GETC\n");
     142                        asm(" SWI\n"
     143                                " FCB 0x0A\n");
    145144                } while(KEY == 0);
    146145
     
    170169                                }
    171170                                // fall through
    172                 do {
    173                         asm("SWI \t    \t;\n"
    174                                 ".fcb \t0x0A\t;GETC\n");
    175                 } while(KEY == 0);
    176171                        case 0x10: // LEFT
    177172                                // Quit (without saving)
     
    180175                        case 0x18: // DOWN
    181176                                // select previous file
    182                                 if (++selected > 7) selected = 7;
     177                                if (++selected > 6) selected = 6;
    183178                                // TODO previous page ?
    184179                                break;
     
    186181                                // decrease current option value
    187182                                if(options[selected].type)
    188                                         --*(confbuf+options[selected].off);
     183                                        --*(char*)((int)confbuf+options[selected].off);
    189184                                else
    190                                         *(confbuf+options[selected].off) = 0;
     185                                        putcfg(options[selected].off, 0);
    191186                                break;
    192187                        case 0x0B: // +
    193188                                if(options[selected].type)
    194                                         ++*(confbuf+options[selected].off);
     189                                        ++*(char*)((int)confbuf+options[selected].off);
    195190                                else
    196                                         *(confbuf+options[selected].off) = 0xFF;
     191                                        putcfg(options[selected].off, 0xFF);
    197192                                break;
    198193                }
     
    211206        FATFS fs;
    212207        FRESULT r = pf_mount(&fs);
     208
    213209        if (r != 0) {
    214210                my_puts("mount error ");
     
    265261                // Allow the user to select a file
    266262                do {
    267                         asm("SWI \t    \t;\n"
    268                                 ".fcb \t0x0A\t;GETC\n");
     263                        asm(" SWI \n"
     264                                " fcb 0x0A\n");
    269265                } while(KEY == 0);
    270266
     
    300296                                } else {
    301297                                        const char* cmp = HXCSDFECFG;
    302                                         FRESULT res = pf_open(cmp);
    303                                         if (res) {
    304                                                 my_puts("Can't open CFG file: ");
    305                                                 printhex(res);
    306                                                 exit(0);
    307                                         }
    308298                                        if (*(long*)(fp->fname) == *(long*)(cmp)
    309299                                                && *(long*)(fp->fname + 4) == *(long*)(cmp+4)
     
    311301                                        )
    312302                                        {
     303                                                FRESULT res = pf_open(cmp);
     304                                                if (res) {
     305                                                        my_puts("Can't open CFG file: ");
     306                                                        printhex(res);
     307                                                        exit(0);
     308                                                }
    313309                                                config();
    314310                                        } else {
     
    316312                                                // If it's an HFE file, load it in HxCSDFE.CFG, then reboot
    317313                                               
     314                                                // We need to open the file to get the starting cluster.
     315                                                // This is a PFF "limitation".
     316                                                pf_open(fp->fname);
     317                                                long off = LD_DWORD(&fs.org_clust);
     318
     319                                                FRESULT res = pf_open(cmp);
     320                                                if (res) {
     321                                                        my_puts("Can't open CFG file: ");
     322                                                        printhex(res);
     323                                                        exit(0);
     324                                                }
     325                                                pf_lseek(0x200);
     326
     327                                                int count = 12;
     328                                                pf_write(fp->fname, count, &count);
     329                                                count = 1;
     330                                                pf_write(&fp->fattrib, count, &count);
     331                                                count = 4;
     332                                                pf_write(&off, count, &count);
     333                                                off = LD_DWORD(&fp->fsize);
     334                                                pf_write(&off, count, &count);
     335                                                count = 17;
     336                                                pf_write(fp->fname, count, &count);
     337                                                pf_write(0,0,&count);
     338
    318339                                                // reboot
    319                                                 exit(0);
     340                                                asm(" SWI\n"
     341                                                        " FCB 0");
    320342                                        }
    321343                                }
Note: See TracChangeset for help on using the changeset viewer.