Changeset 1efc42c in buchla-emu for emu/fdd.c


Ignore:
Timestamp:
07/30/2017 06:18:21 PM (7 years ago)
Author:
Thomas Lopatic <thomas@…>
Branches:
master
Children:
c5b6c90
Parents:
caff491
Message:

Load floppy disk image file.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • emu/fdd.c

    rcaff491 r1efc42c  
    2424int32_t fdd_verbose = 0;
    2525
     26#define N_CYL 80
     27#define N_SID 2
     28#define N_SEC 18
     29#define SZ_SEC 512
     30
     31#define SZ_DISK (N_CYL * N_SID * N_SEC * SZ_SEC)
     32
     33static uint8_t image[SZ_DISK];
     34
    2635void fdd_init(void)
    2736{
    2837        ver("fdd init");
     38        inf("loading disk image file %s", disk);
     39
     40        SDL_RWops *ops = SDL_RWFromFile(disk, "rb");
     41
     42        if (ops == NULL) {
     43                fail("error while opening disk image file %s", disk);
     44        }
     45
     46        size_t loaded = 0;
     47
     48        while (loaded < SZ_DISK) {
     49                size_t n_rd = SDL_RWread(ops, image + loaded, 1, SZ_DISK - loaded);
     50
     51                if (n_rd == 0) {
     52                        fail("error while reading disk image file %s", disk);
     53                }
     54
     55                loaded += n_rd;
     56        }
     57
     58        SDL_RWclose(ops);
    2959}
    3060
Note: See TracChangeset for help on using the changeset viewer.