--- uae/src/ersatz.c 2018/04/24 16:40:50 1.1.1.4 +++ uae/src/ersatz.c 2018/04/24 17:16:27 1.1.1.11 @@ -10,12 +10,10 @@ #include "sysconfig.h" #include "sysdeps.h" -#include "config.h" #include "options.h" #include "uae.h" #include "memory.h" #include "custom.h" -#include "readcpu.h" #include "newcpu.h" #include "cia.h" #include "disk.h" @@ -31,9 +29,11 @@ #define EOP_ALLOCABS 7 #define EOP_LOOP 8 +static int already_failed = 0; + void init_ersatz_rom (uae_u8 *data) { - fprintf(stderr, "Trying to use Kickstart replacement.\n"); + write_log ("Trying to use Kickstart replacement.\n"); *data++ = 0x00; *data++ = 0x08; /* initial SP */ *data++ = 0x00; *data++ = 0x00; *data++ = 0x00; *data++ = 0xF8; /* initial PC */ @@ -67,6 +67,18 @@ void init_ersatz_rom (uae_u8 *data) *data++ = 0x4E; *data++ = 0x75; } +static void ersatz_failed (void) +{ + if (already_failed) + return; + already_failed = 1; +#if 0 + notify_user (NUMSG_KICKREPNO); + uae_restart (-1, NULL); +#endif + uae_quit (); +} + static void ersatz_doio (void) { uaecptr request = m68k_areg(regs, 1); @@ -76,8 +88,8 @@ static void ersatz_doio (void) break; default: - fprintf(stderr, "Only CMD_READ supported in DoIO()\n"); - abort(); + write_log ("Only CMD_READ supported in DoIO()\n"); + ersatz_failed (); } { uaecptr dest = get_long (request + 0x28); @@ -101,7 +113,7 @@ static void ersatz_init (void) uaecptr a; if (disk_empty (0)) { - fprintf (stderr, "You need to have a diskfile in DF0 to use the Kickstart replacement!\n"); + write_log ("You need to have a diskfile in DF0 to use the Kickstart replacement!\n"); uae_quit (); m68k_setpc (0xF80010); return; @@ -138,8 +150,41 @@ static void ersatz_init (void) put_long (request + 0x24, 0x200 * 4); m68k_areg(regs, 1) = request; ersatz_doio (); + /* kickstart disk loader */ + if (get_long(0x4000) == 0x4b49434b) { + /* a kickstart disk was found in drive 0! */ + write_log ("Loading Kickstart rom image from Kickstart disk\n"); + /* print some notes... */ + write_log ("NOTE: if UAE crashes set CPU to 68000 and/or chipmem size to 512KB!\n"); + + /* read rom image from kickstart disk */ + put_word (request + 0x1C, 2); + put_long (request + 0x28, 0xF80000); + put_long (request + 0x2C, 0x200); + put_long (request + 0x24, 0x200 * 512); + m68k_areg(regs, 1) = request; + ersatz_doio (); + + /* read rom image once again to mirror address space. + not elegant, but it works... */ + put_word (request + 0x1C, 2); + put_long (request + 0x28, 0xFC0000); + put_long (request + 0x2C, 0x200); + put_long (request + 0x24, 0x200 * 512); + m68k_areg(regs, 1) = request; + ersatz_doio (); + + disk_eject (0); + + m68k_setpc (0xFC0002); + fill_prefetch_slow (); + uae_reset (0); + ersatzkickfile = 0; + return; + } + m68k_setpc (0x400C); - fill_prefetch_0 (); + fill_prefetch_slow (); /* Init the hardware */ put_long (0x3000, 0xFFFFFFFEul); @@ -192,9 +237,10 @@ void ersatz_perform (uae_u16 what) break; case EOP_NIMP: - fprintf (stderr, "Unimplemented Kickstart function called\n"); - uae_quit (); - + write_log ("Unimplemented Kickstart function called\n"); + ersatz_failed (); + break; + /* fall through */ case EOP_LOOP: m68k_setpc (0xF80010); @@ -202,7 +248,8 @@ void ersatz_perform (uae_u16 what) case EOP_OPENLIB: default: - fprintf(stderr, "Internal error. Giving up.\n"); - abort (); + write_log ("Internal error. Giving up.\n"); + ersatz_failed (); + break; } }