Changeset 1b74fa2 in thomson


Ignore:
Timestamp:
Mar 10, 2012, 2:46:13 PM (12 years ago)
Author:
Adrien Destugues <pulkomandy@…>
Branches:
main
Children:
ee447bf
Parents:
53c4be3
Message:

work in progress write support.

  • With latest beta firmware there is no spinup problem anymore in direct access mode,
  • Read the CFG file and display settings menu
  • Save settings (not perfectly working yet)
  • Some tweaks all around.
  • Move code downwards in memory, because we run out of space !

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

Location:
code/C/HxCHost
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/C/HxCHost/Makefile

    r53c4be3 r1b74fa2  
    2727# Linking
    2828TEST.BIN: $(OBJECTS)
    29         $(CC) -Os $(OBJECTS) -o TEST.BIN -Wl,--map -Wl,-Ttext,0x7100 -nostdlib -lgcc
     29        $(CC) -Os $(OBJECTS) -o TEST.BIN -Wl,--map -Wl,-Ttext,0x6100 -nostdlib -lgcc
    3030
    3131#Compiling
    32 obj/$(TARGET)/%.o: %.c
     32obj/$(TARGET)/%.o: %.c obj/$(TARGET)
    3333        $(CC) $(CFLAGS) -c $< -o $@
    3434
    35 obj/$(TARGET)/%.o: pff/%.c
     35obj/$(TARGET)/%.o: pff/%.c obj/$(TARGET)
    3636        $(CC) $(CFLAGS) -c $< -o $@
    3737
    38 obj/$(TARGET)/%.o: %.s
     38obj/$(TARGET)/%.o: %.s obj/$(TARGET)
    3939        $(AS) $< -o $@
     40
     41# init
     42obj/$(TARGET):
     43        mkdir -p obj/$(TARGET)
  • code/C/HxCHost/main.c

    r53c4be3 r1b74fa2  
    1818unsigned char mark[512 + 16] = "HxCFEDA";
    1919unsigned char* secbuf = mark+16;
     20
     21const char* HXCSDFECFG = "HXCTEST.CFG";
    2022
    2123void printhex(unsigned char n)
     
    8991}
    9092
    91 int main(void)
     93struct opt
     94{
     95        char* name;
     96        BYTE off;
     97        BYTE type;
     98};
     99
     100static 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
     114inline 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
     200int __attribute__((noreturn)) main(void)
    92201{
    93202        // Detect HxC and print version code
     
    106215        }
    107216
    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);
    109225
    110226        // Open root directory
    111227        pf_opendir(&d, "");
    112         mon_putc('y');
    113228
    114229        // List files
    115230        ls(DIRECTORY_BUFFER);
    116         mon_putc('x');
    117231
    118232        int selected = 0;
     
    183297                                        ls(DIRECTORY_BUFFER);
    184298                                } 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                                        }
    188319                                }
    189320                                break;
     
    194325                }
    195326        }
    196 
    197         // Leave LBA mode
    198         /*
    199 
    200 */
    201 
    202         // Reboot
    203         exit(0);
    204 }
     327}
  • code/C/HxCHost/pff/diskio.c

    r53c4be3 r1b74fa2  
    1212extern unsigned char* secbuf;
    1313extern unsigned char mark[];
     14
     15static DWORD prevsec = -1;
    1416/*******/
    1517
     
    3537
    3638
     39void 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
    3758
    3859/*-----------------------------------------------------------------------*/
     
    4768)
    4869{
    49         static DWORD prevsec = -1;
    5070        // TODO implement caching system
    5171        //  * If sector is reachable with current LBA, don't change it
    5272
    53         printhex(sector>>24);
    54         printhex(sector>>16);
    55         printhex(sector>>8);
    56         printhex(sector);
    57         mon_putc(' ');
    58 
    5973        if (prevsec != sector)
    6074        {
    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);
    7476                prevsec = sector;
    7577                // Read sector
     
    98100)
    99101{
    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
    104105
    105106        if (!buff) {
    106107                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                        }
    107122
    108                         // Initiate write process
     123                        // map in the sector (no need to read from SD)
     124                        map_sector(prevsec, 0xA5);
    109125
    110                 } else {
     126                        for(int j = 0; j < 40; j++)
     127                                printhex(*(char*)(wrbuf + j));
    111128
    112                         // Finalize write process
    113 
     129                        write(255,1,wrbuf);
    114130                }
    115131        } 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                }
    119138        }
    120139
    121         return res;
     140        return RES_OK;
    122141}
    123142
Note: See TracChangeset for help on using the changeset viewer.