--- uae/src/expansion.c 2018/04/24 17:00:04 1.1.1.8 +++ uae/src/expansion.c 2018/04/24 17:18:22 1.1.1.13 @@ -1,4 +1,4 @@ - /* + /* * UAE - The Un*x Amiga Emulator * * AutoConfig (tm) Expansions (ZorroII/III) @@ -12,7 +12,6 @@ #include "sysconfig.h" #include "sysdeps.h" -#include "config.h" #include "options.h" #include "uae.h" #include "memory.h" @@ -121,6 +120,7 @@ uaecptr ROM_filesys_resname = 0, ROM_fil uaecptr ROM_filesys_diagentry = 0; uaecptr ROM_hardfile_resname = 0, ROM_hardfile_resid = 0; uaecptr ROM_hardfile_init = 0; +int uae_boot_rom, uae_boot_rom_size; /* size = code size only */ /* ********************************************************** */ @@ -134,7 +134,7 @@ static int ecard = 0; /* Please note: ZorroIII implementation seems to work different * than described in the HRM. This claims that ZorroIII config * address is 0xff000000 while the ZorroII config space starts - * at 0x00e80000. In reality, both, Z2 and Z3 cards are + * at 0x00e80000. In reality, both, Z2 and Z3 cards are * configured in the ZorroII config space. Kickstart 3.1 doesn't * even do a single read or write access to the ZorroIII space. * The original Amiga include files tell the same as the HRM. @@ -143,7 +143,7 @@ static int ecard = 0; * to a ZorroIII card on a real Amiga. This is not implemented * yet. * -- Stefan - * + * * Surprising that 0xFF000000 isn't used. Maybe it depends on the * ROM. Anyway, the HRM says that Z3 cards may appear in Z2 config * space, so what we are doing here is correct. @@ -162,7 +162,7 @@ static uae_u16 expamem_hi; static void expamem_map_clear (void) { - fprintf (stderr, "expamem_map_clear() got called. Shouldn't happen.\n"); + write_log ("expamem_map_clear() got called. Shouldn't happen.\n"); } static void expamem_init_clear (void) @@ -170,6 +170,12 @@ static void expamem_init_clear (void) memset (expamem, 0xff, sizeof expamem); } +static void expamem_init_clear2 (void) +{ + expamem_init_clear (); + ecard = MAX_EXPANSION_BOARDS - 1; +} + static uae_u32 expamem_lget (uaecptr) REGPARAM; static uae_u32 expamem_wget (uaecptr) REGPARAM; static uae_u32 expamem_bget (uaecptr) REGPARAM; @@ -180,33 +186,29 @@ static void expamem_bput (uaecptr, uae_u addrbank expamem_bank = { expamem_lget, expamem_wget, expamem_bget, expamem_lput, expamem_wput, expamem_bput, - default_xlate, default_check, NULL + default_xlate, default_check, NULL, "Autoconfig" }; static uae_u32 REGPARAM2 expamem_lget (uaecptr addr) { - special_mem |= S_READ; write_log ("warning: READ.L from address $%lx \n", addr); return 0xfffffffful; } static uae_u32 REGPARAM2 expamem_wget (uaecptr addr) { - special_mem |= S_READ; write_log ("warning: READ.W from address $%lx \n", addr); return 0xffff; } static uae_u32 REGPARAM2 expamem_bget (uaecptr addr) { - special_mem |= S_READ; addr &= 0xFFFF; return expamem[addr]; } static void REGPARAM2 expamem_write (uaecptr addr, uae_u32 value) { - special_mem |= S_WRITE; addr &= 0xffff; if (addr == 00 || addr == 02 || addr == 0x40 || addr == 0x42) { expamem[addr] = (value & 0xf0); @@ -224,13 +226,11 @@ static int REGPARAM2 expamem_type (void) static void REGPARAM2 expamem_lput (uaecptr addr, uae_u32 value) { - special_mem |= S_WRITE; write_log ("warning: WRITE.L to address $%lx : value $%lx\n", addr, value); } static void REGPARAM2 expamem_wput (uaecptr addr, uae_u32 value) { - special_mem |= S_WRITE; if (expamem_type() != zorroIII) write_log ("warning: WRITE.W to address $%lx : value $%x\n", addr, value); else { @@ -244,7 +244,7 @@ static void REGPARAM2 expamem_wput (uaec if (ecard < MAX_EXPANSION_BOARDS) (*card_init[ecard]) (); else - expamem_init_clear (); + expamem_init_clear2 (); } break; } @@ -253,7 +253,6 @@ static void REGPARAM2 expamem_wput (uaec static void REGPARAM2 expamem_bput (uaecptr addr, uae_u32 value) { - special_mem |= S_WRITE; switch (addr & 0xff) { case 0x30: case 0x32: @@ -271,7 +270,7 @@ static void REGPARAM2 expamem_bput (uaec if (ecard < MAX_EXPANSION_BOARDS) (*card_init[ecard]) (); else - expamem_init_clear (); + expamem_init_clear2 (); } else if (expamem_type() == zorroIII) expamem_lo = value; break; @@ -287,7 +286,7 @@ static void REGPARAM2 expamem_bput (uaec if (ecard < MAX_EXPANSION_BOARDS) (*card_init[ecard]) (); else - expamem_init_clear (); + expamem_init_clear2 (); break; } } @@ -379,7 +378,7 @@ static uae_u8 REGPARAM2 *fastmem_xlate ( addrbank fastmem_bank = { fastmem_lget, fastmem_wget, fastmem_bget, fastmem_lput, fastmem_wput, fastmem_bput, - fastmem_xlate, fastmem_check, NULL + fastmem_xlate, fastmem_check, NULL, "Fast memory" }; @@ -401,7 +400,6 @@ uae_u8 *filesysory; uae_u32 REGPARAM2 filesys_lget (uaecptr addr) { uae_u8 *m; - special_mem |= S_READ; addr -= filesys_start & 65535; addr &= 65535; m = filesysory + addr; @@ -411,7 +409,6 @@ uae_u32 REGPARAM2 filesys_lget (uaecptr uae_u32 REGPARAM2 filesys_wget (uaecptr addr) { uae_u8 *m; - special_mem |= S_READ; addr -= filesys_start & 65535; addr &= 65535; m = filesysory + addr; @@ -420,7 +417,6 @@ uae_u32 REGPARAM2 filesys_wget (uaecptr uae_u32 REGPARAM2 filesys_bget (uaecptr addr) { - special_mem |= S_READ; addr -= filesys_start & 65535; addr &= 65535; return filesysory[addr]; @@ -428,31 +424,28 @@ uae_u32 REGPARAM2 filesys_bget (uaecptr static void REGPARAM2 filesys_lput (uaecptr addr, uae_u32 l) { - special_mem |= S_WRITE; write_log ("filesys_lput called\n"); } static void REGPARAM2 filesys_wput (uaecptr addr, uae_u32 w) { - special_mem |= S_WRITE; write_log ("filesys_wput called\n"); } static void REGPARAM2 filesys_bput (uaecptr addr, uae_u32 b) { - special_mem |= S_WRITE; - fprintf (stderr, "filesys_bput called. This usually means that you are using\n"); - fprintf (stderr, "Kickstart 1.2. Please give UAE the \"-a\" option next time\n"); - fprintf (stderr, "you start it. If you are _not_ using Kickstart 1.2, then\n"); - fprintf (stderr, "there's a bug somewhere.\n"); - fprintf (stderr, "Exiting...\n"); + write_log ("filesys_bput called. This usually means that you are using\n"); + write_log ("Kickstart 1.2. Please give UAE the \"-a\" option next time\n"); + write_log ("you start it. If you are _not_ using Kickstart 1.2, then\n"); + write_log ("there's a bug somewhere.\n"); + write_log ("Exiting...\n"); uae_quit (); } addrbank filesys_bank = { filesys_lget, filesys_wget, filesys_bget, filesys_lput, filesys_wput, filesys_bput, - default_xlate, default_check, NULL + default_xlate, default_check, NULL, "Filesystem Autoconfig Area" }; /* @@ -541,7 +534,7 @@ static uae_u8 REGPARAM2 *z3fastmem_xlate addrbank z3fastmem_bank = { z3fastmem_lget, z3fastmem_wget, z3fastmem_bget, z3fastmem_lput, z3fastmem_wput, z3fastmem_bput, - z3fastmem_xlate, z3fastmem_check, NULL + z3fastmem_xlate, z3fastmem_check, NULL, "ZorroIII Fast RAM" }; /* Z3-based UAEGFX-card */ @@ -564,7 +557,7 @@ static void expamem_map_fastcard (void) static void expamem_init_fastcard (void) { - expamem_init_clear(); + expamem_init_clear (); if (allocated_fastmem == 0x100000) expamem_write (0x00, Z2_MEM_1MB + add_memory + zorroII); else if (allocated_fastmem == 0x200000) @@ -594,7 +587,7 @@ static void expamem_init_fastcard (void) /* ********************************************************** */ -/* +/* * Filesystem device */ @@ -607,7 +600,7 @@ static void expamem_map_filesys (void) write_log ("Filesystem: mapped memory @$%lx.\n", filesys_start); /* 68k code needs to know this. */ a = here (); - org (0xF0FFFC); + org (RTAREA_BASE+0xFFFC); dl (filesys_start + 0x2000); org (a); } @@ -616,12 +609,12 @@ static void expamem_init_filesys (void) { /* struct DiagArea - the size has to be large enough to store several device ROMTags */ uae_u8 diagarea[] = { 0x90, 0x00, /* da_Config, da_Flags */ - 0x02, 0x00, /* da_Size */ - 0x01, 0x00, /* da_DiagPoint */ - 0x01, 0x06 /* da_BootPoint */ + 0x02, 0x00, /* da_Size */ + 0x01, 0x00, /* da_DiagPoint */ + 0x01, 0x06 /* da_BootPoint */ }; - expamem_init_clear(); + expamem_init_clear (); expamem_write (0x00, Z2_MEM_64KB | rom_card | zorroII); expamem_write (0x08, no_shutup); @@ -682,7 +675,7 @@ static void expamem_init_z3fastmem (void : allocated_z3fastmem == 0x10000000 ? Z2_MEM_256MB : allocated_z3fastmem == 0x20000000 ? Z2_MEM_512MB : Z2_MEM_1GB); - expamem_init_clear(); + expamem_init_clear (); expamem_write (0x00, add_memory | zorroIII | code); expamem_write (0x08, no_shutup | force_z3 | (allocated_z3fastmem > 0x800000 ? ext_size : Z3_MEM_AUTO)); @@ -717,7 +710,7 @@ static void expamem_map_gfxcard (void) static void expamem_init_gfxcard (void) { - expamem_init_clear(); + expamem_init_clear (); expamem_write (0x00, zorroIII); switch (allocated_gfxmem) { @@ -762,7 +755,7 @@ static void allocate_expamem (void) if (allocated_fastmem != currprefs.fastmem_size) { if (fastmemory) - free (fastmemory); + mapped_free (fastmemory); fastmemory = 0; allocated_fastmem = currprefs.fastmem_size; fastmem_mask = allocated_fastmem - 1; @@ -775,52 +768,64 @@ static void allocate_expamem (void) } } } - if (allocated_z3fastmem != currprefs.z3fastmem_size) { + if (currprefs.address_space_24) { if (z3fastmem) - free (z3fastmem); + mapped_free (z3fastmem); z3fastmem = 0; - - allocated_z3fastmem = currprefs.z3fastmem_size; - z3fastmem_mask = allocated_z3fastmem - 1; - - if (allocated_z3fastmem) { - z3fastmem = mapped_malloc (allocated_z3fastmem, "z3"); - if (z3fastmem == 0) { - write_log ("Out of memory for 32 bit fast memory.\n"); - allocated_z3fastmem = 0; - } - } - } - if (allocated_gfxmem != currprefs.gfxmem_size) { + allocated_z3fastmem = 0; if (gfxmemory) - free (gfxmemory); + mapped_free (gfxmemory); gfxmemory = 0; - - allocated_gfxmem = currprefs.gfxmem_size; - gfxmem_mask = allocated_gfxmem - 1; - - if (allocated_gfxmem) { - gfxmemory = mapped_malloc (allocated_gfxmem, "gfx"); - if (gfxmemory == 0) { - write_log ("Out of memory for graphics card memory\n"); - allocated_gfxmem = 0; + allocated_gfxmem = 0; + } else { + if (allocated_z3fastmem != currprefs.z3fastmem_size) { + if (z3fastmem) + mapped_free (z3fastmem); + z3fastmem = 0; + + allocated_z3fastmem = currprefs.z3fastmem_size; + z3fastmem_mask = allocated_z3fastmem - 1; + + if (allocated_z3fastmem) { + z3fastmem = mapped_malloc (allocated_z3fastmem, "z3"); + if (z3fastmem == 0) { + write_log ("Out of memory for 32 bit fast memory.\n"); + allocated_z3fastmem = 0; + } + } + } + if (allocated_gfxmem != currprefs.gfxmem_size) { + if (gfxmemory) + mapped_free (gfxmemory); + gfxmemory = 0; + + allocated_gfxmem = currprefs.gfxmem_size; + gfxmem_mask = allocated_gfxmem - 1; + + if (allocated_gfxmem) { + gfxmemory = mapped_malloc (allocated_gfxmem, "gfx"); + if (gfxmemory == 0) { + write_log ("Out of memory for graphics card memory\n"); + allocated_gfxmem = 0; + } } } } - z3fastmem_bank.baseaddr = z3fastmem; fastmem_bank.baseaddr = fastmemory; if (savestate_state == STATE_RESTORE) { if (allocated_fastmem > 0) { - fseek (savestate_file, fast_filepos, SEEK_SET); - fread (fastmemory, 1, allocated_fastmem, savestate_file); + restore_ram (fast_filepos, fastmemory); + if (fastmem_start == 0 || fastmem_start & 0xFFFF) { + write_log ("Statefile most likely corrupt. Using a sane default for fastmem address.\n"); + fastmem_start = 0x200000; + } map_banks (&fastmem_bank, fastmem_start >> 16, currprefs.fastmem_size >> 16, allocated_fastmem); } if (allocated_z3fastmem > 0) { - fseek (savestate_file, z3_filepos, SEEK_SET); - fread (z3fastmem, 1, allocated_z3fastmem, savestate_file); + restore_ram (z3_filepos, z3fastmem); map_banks (&z3fastmem_bank, z3fastmem_start >> 16, currprefs.z3fastmem_size >> 16, allocated_z3fastmem); } @@ -829,18 +834,18 @@ static void allocate_expamem (void) void expamem_reset (void) { - int do_mount = 1; + int do_mount = currprefs.bootrom && !ersatzkickfile; int cardno = 0; ecard = 0; allocate_expamem (); /* check if Kickstart version is below 1.3 */ - if (! ersatzkickfile + if (! ersatzkickfile && kickstart_version && (/* Kickstart 1.0 & 1.1! */ - get_word (0xF8000C) == 0xFFFF + kickstart_version == 0xFFFF /* Kickstart < 1.3 */ - || get_word (0xF8000C) < 34)) + || kickstart_version < 34)) { /* warn user */ write_log ("Kickstart version is below 1.3! Disabling autoconfig devices.\n"); @@ -861,7 +866,7 @@ void expamem_reset (void) card_map[cardno++] = expamem_map_gfxcard; } #endif - if (do_mount && ! ersatzkickfile) { + if (do_mount) { card_init[cardno] = expamem_init_filesys; card_map[cardno++] = expamem_map_filesys; } @@ -884,13 +889,38 @@ void expansion_init (void) allocate_expamem (); - filesysory = (uae_u8 *) mapped_malloc (0x10000, "filesys"); + filesysory = mapped_malloc (0x10000, "filesys"); if (!filesysory) { write_log ("virtual memory exhausted (filesysory)!\n"); exit (0); } - filesys_bank.baseaddr = (uae_u8*)filesysory; + filesys_bank.baseaddr = filesysory; +} + +void expansion_cleanup (void) +{ + if (fastmemory) + mapped_free (fastmemory); + if (z3fastmem) + mapped_free (z3fastmem); + if (gfxmemory) + mapped_free (gfxmemory); + if (filesysory) + mapped_free (filesysory); + fastmemory = 0; + z3fastmem = 0; + gfxmemory = 0; + filesysory = 0; +} +void expansion_clear(void) +{ + if (fastmemory) + memset (fastmemory, 0, allocated_fastmem); + if (z3fastmem) + memset (z3fastmem, 0, allocated_z3fastmem > 0x800000 ? 0x800000 : allocated_z3fastmem); + if (gfxmemory) + memset (gfxmemory, 0, allocated_gfxmem); } /* State save/restore code. */ @@ -919,16 +949,19 @@ void restore_zram (int len, long filepos changed_prefs.z3fastmem_size = len; } -uae_u8 *save_expansion (int *len) +uae_u8 *save_expansion (int *len, uae_u8 *dstptr) { - static uae_u8 t[20], *dst = t; + static uae_u8 t[20]; + uae_u8 *dst = t, *dstbak = t; + if (dstptr) + dst = dstbak = dstptr; save_u32 (fastmem_start); save_u32 (z3fastmem_start); *len = 8; - return dst; + return dstbak; } -uae_u8 *restore_expansion (uae_u8 *src) +const uae_u8 *restore_expansion (const uae_u8 *src) { fastmem_start = restore_u32 (); z3fastmem_start = restore_u32 ();