From: Alan Cox Date: Thu, 4 Jun 2015 23:38:53 +0000 (+0100) Subject: dragon-nx32: experimenting with cartridge auto-ident X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=c8e3d3a44d21289311d1a529935be656422a6c90;p=FUZIX.git dragon-nx32: experimenting with cartridge auto-ident --- diff --git a/Kernel/platform-dragon-nx32/main.c b/Kernel/platform-dragon-nx32/main.c index cbeaf88c..7fdb531a 100644 --- a/Kernel/platform-dragon-nx32/main.c +++ b/Kernel/platform-dragon-nx32/main.c @@ -8,7 +8,7 @@ uint8_t membanks; uint8_t system_id; uint8_t cartslots = 1; -uint16_t carthash[4]; +uint8_t carttype[4]; uint8_t bootslot = 0; void platform_idle(void) @@ -42,22 +42,60 @@ void pagemap_init(void) static const char *sysname[] = {"Dragon", "COCO", "COCO3", "Unknown"}; +struct cart_rom_id { + uint16_t hash; + uint8_t id; + const char *name; +}; + +static const char empty[] = "(empty)"; + +struct cart_rom_id carts[] = { + { 0x72B0, 1, "DragonDOS" }, + { 0x9063, 3, "DeltaDOS" }, + { 0xB400, 0, empty }, + { 0xC248, 2, "RS-DOS" }, + { 0x0000, 0, "No ROM" } +}; + +static struct cart_rom_id *cart_lookup(uint16_t hash) +{ + struct cart_rom_id *cart = carts; + do { + if (cart->hash == hash) + return cart; + } while(cart++->hash); + return NULL; +} + void map_init(void) { uint8_t i; + uint8_t bslot = 0; + uint16_t hash; + struct cart_rom_id *rom; kprintf("%s system.\n", sysname[system_id]); if (mpi_present()) { kputs("MPI cartridge detected.\n"); cartslots = 4; bootslot = mpi_set_slot(0); + bslot = bootslot & 3; } for (i = 0; i < cartslots; i++) { mpi_set_slot((i << 4) | i); - carthash[i] = cart_hash(); - kprintf("%d: %x %c\n", - i, carthash[i], - i == bootslot ? '*':' '); + hash = cart_hash(); + rom = cart_lookup(hash); + if (rom) { + kprintf("%d: %s %c\n", + i, rom->name, + i == bootslot ? '*':' '); + carttype[i] = rom->id; + } + else + kprintf("%d: Unknown(%x) %c\n", + i, hash, + i == bslot ? '*':' '); } mpi_set_slot(bootslot); }