Annotation of uae/src/expansion.c, revision 1.1.1.8

1.1       root        1:  /* 
                      2:   * UAE - The Un*x Amiga Emulator
                      3:   *
1.1.1.3   root        4:   * AutoConfig (tm) Expansions (ZorroII/III)
                      5:   *
                      6:   * Copyright 1996,1997 Stefan Reinauer <[email protected]>
                      7:   * Copyright 1997 Brian King <[email protected]>
                      8:   *   - added gfxcard code
                      9:   *
1.1       root       10:   */
                     11: 
                     12: #include "sysconfig.h"
                     13: #include "sysdeps.h"
                     14: 
                     15: #include "config.h"
                     16: #include "options.h"
1.1.1.3   root       17: #include "uae.h"
1.1       root       18: #include "memory.h"
                     19: #include "autoconf.h"
1.1.1.3   root       20: #include "picasso96.h"
1.1.1.8 ! root       21: #include "savestate.h"
1.1       root       22: 
1.1.1.3   root       23: #define MAX_EXPANSION_BOARDS   8
1.1       root       24: 
1.1.1.3   root       25: /* ********************************************************** */
1.1       root       26: /* 00 / 02 */
1.1.1.3   root       27: /* er_Type */
                     28: 
                     29: #define Z2_MEM_8MB     0x00 /* Size of Memory Block */
                     30: #define Z2_MEM_4MB     0x07
                     31: #define Z2_MEM_2MB     0x06
                     32: #define Z2_MEM_1MB     0x05
                     33: #define Z2_MEM_512KB   0x04
                     34: #define Z2_MEM_256KB   0x03
                     35: #define Z2_MEM_128KB   0x02
                     36: #define Z2_MEM_64KB    0x01
                     37: /* extended definitions */
                     38: #define Z2_MEM_16MB    0x00
                     39: #define Z2_MEM_32MB    0x01
                     40: #define Z2_MEM_64MB    0x02
                     41: #define Z2_MEM_128MB   0x03
                     42: #define Z2_MEM_256MB   0x04
                     43: #define Z2_MEM_512MB   0x05
                     44: #define Z2_MEM_1GB     0x06
                     45: 
                     46: #define chainedconfig  0x08 /* Next config is part of the same card */
                     47: #define rom_card       0x10 /* ROM vector is valid */
                     48: #define add_memory     0x20 /* Link RAM into free memory list */
1.1       root       49: 
1.1.1.3   root       50: #define zorroII                0xc0 /* Type of Expansion Card */
                     51: #define zorroIII       0x80
1.1       root       52: 
                     53: /* ********************************************************** */
1.1.1.3   root       54: /* 04 - 06 & 10-16 */
1.1       root       55: 
1.1.1.3   root       56: /* Manufacturer */
                     57: #define commodore_g     513 /* Commodore Braunschweig (Germany) */
                     58: #define commodore       514 /* Commodore West Chester */
                     59: #define gvp            2017 /* GVP */
                     60: #define ass            2102 /* Advanced Systems & Software */
                     61: #define hackers_id     2011 /* Special ID for test cards */
                     62: 
                     63: /* Card Type */
                     64: #define commodore_a2091             3 /* A2091 / A590 Card from C= */
                     65: #define commodore_a2091_ram 10 /* A2091 / A590 Ram on HD-Card */
                     66: #define commodore_a2232            70 /* A2232 Multiport Expansion */
                     67: #define ass_nexus_scsi      1 /* Nexus SCSI Controller */
1.1       root       68: 
1.1.1.3   root       69: #define gvp_series_2_scsi   11
                     70: #define gvp_iv_24_gfx      32
1.1       root       71: 
1.1.1.3   root       72: /* ********************************************************** */
                     73: /* 08 - 0A  */
                     74: /* er_Flags */
                     75: #define Z3_MEM_64KB    0x02
                     76: #define Z3_MEM_128KB   0x03
                     77: #define Z3_MEM_256KB   0x04
                     78: #define Z3_MEM_512KB   0x05
                     79: #define Z3_MEM_1MB     0x06 /* Zorro III card subsize */
                     80: #define Z3_MEM_2MB     0x07
                     81: #define Z3_MEM_4MB     0x08
                     82: #define Z3_MEM_6MB     0x09
                     83: #define Z3_MEM_8MB     0x0a
                     84: #define Z3_MEM_10MB    0x0b
                     85: #define Z3_MEM_12MB    0x0c
                     86: #define Z3_MEM_14MB    0x0d
                     87: #define Z3_MEM_16MB    0x00
                     88: #define Z3_MEM_AUTO    0x01
                     89: #define Z3_MEM_defunct1        0x0e
                     90: #define Z3_MEM_defunct2        0x0f
                     91: 
                     92: #define force_z3       0x10 /* *MUST* be set if card is Z3 */
                     93: #define ext_size       0x20 /* Use extended size table for bits 0-2 of er_Type */
                     94: #define no_shutup      0x40 /* Card cannot receive Shut_up_forever */
                     95: #define care_addr      0x80 /* Adress HAS to be $200000-$9fffff */
1.1       root       96: 
                     97: /* ********************************************************** */
1.1.1.3   root       98: /* 40-42 */
                     99: /* ec_interrupt (unused) */
1.1       root      100: 
1.1.1.3   root      101: #define enable_irq     0x01 /* enable Interrupt */
                    102: #define reset_card     0x04 /* Reset of Expansion Card - must be 0 */
                    103: #define card_int2      0x10 /* READ ONLY: IRQ 2 active */
                    104: #define card_irq6      0x20 /* READ ONLY: IRQ 6 active */
                    105: #define card_irq7      0x40 /* READ ONLY: IRQ 7 active */
                    106: #define does_irq       0x80 /* READ ONLY: Card currently throws IRQ */
1.1       root      107: 
                    108: /* ********************************************************** */
                    109: 
1.1.1.3   root      110: /* ROM defines (DiagVec) */
                    111: 
                    112: #define rom_4bit       (0x00<<14) /* ROM width */
                    113: #define rom_8bit       (0x01<<14)
                    114: #define rom_16bit      (0x02<<14)
                    115: 
                    116: #define rom_never      (0x00<<12) /* Never run Boot Code */
                    117: #define rom_install    (0x01<<12) /* run code at install time */
                    118: #define rom_binddrv    (0x02<<12) /* run code with binddrivers */
                    119: 
                    120: uaecptr ROM_filesys_resname = 0, ROM_filesys_resid = 0;
                    121: uaecptr ROM_filesys_diagentry = 0;
                    122: uaecptr ROM_hardfile_resname = 0, ROM_hardfile_resid = 0;
                    123: uaecptr ROM_hardfile_init = 0;
1.1       root      124: 
                    125: /* ********************************************************** */
                    126: 
1.1.1.3   root      127: static void (*card_init[MAX_EXPANSION_BOARDS]) (void);
                    128: static void (*card_map[MAX_EXPANSION_BOARDS]) (void);
1.1       root      129: 
1.1.1.3   root      130: static int ecard = 0;
1.1       root      131: 
                    132: /* ********************************************************** */
                    133: 
1.1.1.3   root      134: /* Please note: ZorroIII implementation seems to work different
                    135:  * than described in the HRM. This claims that ZorroIII config
                    136:  * address is 0xff000000 while the ZorroII config space starts
                    137:  * at 0x00e80000. In reality, both, Z2 and Z3 cards are 
                    138:  * configured in the ZorroII config space. Kickstart 3.1 doesn't
                    139:  * even do a single read or write access to the ZorroIII space.
                    140:  * The original Amiga include files tell the same as the HRM.
                    141:  * ZorroIII: If you set ext_size in er_Flags and give a Z2-size
                    142:  * in er_Type you can very likely add some ZorroII address space
                    143:  * to a ZorroIII card on a real Amiga. This is not implemented
                    144:  * yet.
                    145:  *  -- Stefan
                    146:  * 
                    147:  * Surprising that 0xFF000000 isn't used. Maybe it depends on the
                    148:  * ROM. Anyway, the HRM says that Z3 cards may appear in Z2 config
                    149:  * space, so what we are doing here is correct.
                    150:  *  -- Bernd
                    151:  */
1.1       root      152: 
1.1.1.3   root      153: /* Autoconfig address space at 0xE80000 */
                    154: static uae_u8 expamem[65536];
1.1       root      155: 
1.1.1.3   root      156: static uae_u8 expamem_lo;
                    157: static uae_u16 expamem_hi;
1.1       root      158: 
1.1.1.2   root      159: /*
1.1.1.3   root      160:  *  Dummy entries to show that there's no card in a slot
1.1.1.2   root      161:  */
1.1       root      162: 
1.1.1.3   root      163: static void expamem_map_clear (void)
                    164: {
                    165:     fprintf (stderr, "expamem_map_clear() got called. Shouldn't happen.\n");
                    166: }
                    167: 
                    168: static void expamem_init_clear (void)
                    169: {
                    170:     memset (expamem, 0xff, sizeof expamem);
                    171: }
1.1       root      172: 
1.1.1.4   root      173: static uae_u32 expamem_lget (uaecptr) REGPARAM;
                    174: static uae_u32 expamem_wget (uaecptr) REGPARAM;
                    175: static uae_u32 expamem_bget (uaecptr) REGPARAM;
                    176: static void expamem_lput (uaecptr, uae_u32) REGPARAM;
                    177: static void expamem_wput (uaecptr, uae_u32) REGPARAM;
                    178: static void expamem_bput (uaecptr, uae_u32) REGPARAM;
1.1       root      179: 
1.1.1.3   root      180: addrbank expamem_bank = {
                    181:     expamem_lget, expamem_wget, expamem_bget,
                    182:     expamem_lput, expamem_wput, expamem_bput,
1.1.1.8 ! root      183:     default_xlate, default_check, NULL
1.1.1.3   root      184: };
1.1       root      185: 
1.1.1.4   root      186: static uae_u32 REGPARAM2 expamem_lget (uaecptr addr)
1.1       root      187: {
1.1.1.7   root      188:     special_mem |= S_READ;
1.1.1.4   root      189:     write_log ("warning: READ.L from address $%lx \n", addr);
1.1.1.3   root      190:     return 0xfffffffful;
1.1       root      191: }
                    192: 
1.1.1.4   root      193: static uae_u32 REGPARAM2 expamem_wget (uaecptr addr)
1.1       root      194: {
1.1.1.7   root      195:     special_mem |= S_READ;
1.1.1.4   root      196:     write_log ("warning: READ.W from address $%lx \n", addr);
1.1.1.3   root      197:     return 0xffff;
                    198: }
                    199: 
1.1.1.4   root      200: static uae_u32 REGPARAM2 expamem_bget (uaecptr addr)
1.1.1.3   root      201: {
1.1.1.7   root      202:     special_mem |= S_READ;
1.1.1.3   root      203:     addr &= 0xFFFF;
                    204:     return expamem[addr];
1.1       root      205: }
                    206: 
1.1.1.3   root      207: static void REGPARAM2 expamem_write (uaecptr addr, uae_u32 value)
1.1       root      208: {
1.1.1.7   root      209:     special_mem |= S_WRITE;
1.1.1.3   root      210:     addr &= 0xffff;
                    211:     if (addr == 00 || addr == 02 || addr == 0x40 || addr == 0x42) {
                    212:        expamem[addr] = (value & 0xf0);
                    213:        expamem[addr + 2] = (value & 0x0f) << 4;
                    214:     } else {
                    215:        expamem[addr] = ~(value & 0xf0);
                    216:        expamem[addr + 2] = ~((value & 0x0f) << 4);
                    217:     }
                    218: }
                    219: 
1.1.1.4   root      220: static int REGPARAM2 expamem_type (void)
1.1.1.3   root      221: {
                    222:     return ((expamem[0] | expamem[2] >> 4) & 0xc0);
                    223: }
                    224: 
1.1.1.4   root      225: static void REGPARAM2 expamem_lput (uaecptr addr, uae_u32 value)
1.1.1.3   root      226: {
1.1.1.7   root      227:     special_mem |= S_WRITE;
1.1.1.4   root      228:     write_log ("warning: WRITE.L to address $%lx : value $%lx\n", addr, value);
1.1.1.3   root      229: }
                    230: 
1.1.1.4   root      231: static void REGPARAM2 expamem_wput (uaecptr addr, uae_u32 value)
1.1.1.3   root      232: {
1.1.1.7   root      233:     special_mem |= S_WRITE;
1.1.1.3   root      234:     if (expamem_type() != zorroIII)
1.1.1.4   root      235:        write_log ("warning: WRITE.W to address $%lx : value $%x\n", addr, value);
1.1.1.3   root      236:     else {
                    237:        switch (addr & 0xff) {
                    238:         case 0x44:
                    239:            if (expamem_type() == zorroIII) {
                    240:                expamem_hi = value;
                    241:                (*card_map[ecard]) ();
1.1.1.4   root      242:                write_log ("   Card %d (Zorro%s) done.\n", ecard + 1, expamem_type() == 0xc0 ? "II" : "III");
1.1.1.3   root      243:                ++ecard;
1.1.1.6   root      244:                if (ecard < MAX_EXPANSION_BOARDS)
1.1.1.3   root      245:                    (*card_init[ecard]) ();
                    246:                else
                    247:                    expamem_init_clear ();
                    248:            }
                    249:            break;
                    250:        }
                    251:     }
                    252: }
                    253: 
1.1.1.4   root      254: static void REGPARAM2 expamem_bput (uaecptr addr, uae_u32 value)
1.1.1.3   root      255: {
1.1.1.7   root      256:     special_mem |= S_WRITE;
1.1.1.3   root      257:     switch (addr & 0xff) {
                    258:      case 0x30:
                    259:      case 0x32:
                    260:        expamem_hi = 0;
                    261:        expamem_lo = 0;
                    262:        expamem_write (0x48, 0x00);
                    263:        break;
                    264: 
                    265:      case 0x48:
                    266:        if (expamem_type () == zorroII) {
                    267:            expamem_hi = value & 0xFF;
                    268:            (*card_map[ecard]) ();
1.1.1.4   root      269:            write_log ("   Card %d (Zorro%s) done.\n", ecard + 1, expamem_type() == 0xc0 ? "II" : "III");
1.1.1.3   root      270:            ++ecard;
1.1.1.6   root      271:            if (ecard < MAX_EXPANSION_BOARDS)
1.1.1.3   root      272:                (*card_init[ecard]) ();
                    273:            else
                    274:                expamem_init_clear ();
                    275:        } else if (expamem_type() == zorroIII)
                    276:            expamem_lo = value;
                    277:        break;
                    278: 
                    279:      case 0x4a:
                    280:        if (expamem_type () == zorroII)
                    281:            expamem_lo = value;
                    282:        break;
                    283: 
                    284:      case 0x4c:
1.1.1.4   root      285:        write_log ("   Card %d (Zorro %s) had no success.\n", ecard + 1, expamem_type() == 0xc0 ? "II" : "III");
1.1.1.3   root      286:        ++ecard;
1.1.1.6   root      287:        if (ecard < MAX_EXPANSION_BOARDS)
1.1.1.3   root      288:            (*card_init[ecard]) ();
                    289:        else
                    290:            expamem_init_clear ();
                    291:        break;
                    292:     }
                    293: }
                    294: 
                    295: /* ********************************************************** */
                    296: 
                    297: /*
                    298:  *  Fast Memory
                    299:  */
                    300: 
                    301: static uae_u32 fastmem_mask;
                    302: 
1.1.1.4   root      303: static uae_u32 fastmem_lget (uaecptr) REGPARAM;
                    304: static uae_u32 fastmem_wget (uaecptr) REGPARAM;
                    305: static uae_u32 fastmem_bget (uaecptr) REGPARAM;
                    306: static void fastmem_lput (uaecptr, uae_u32) REGPARAM;
                    307: static void fastmem_wput (uaecptr, uae_u32) REGPARAM;
                    308: static void fastmem_bput (uaecptr, uae_u32) REGPARAM;
                    309: static int fastmem_check (uaecptr addr, uae_u32 size) REGPARAM;
                    310: static uae_u8 *fastmem_xlate (uaecptr addr) REGPARAM;
1.1.1.3   root      311: 
                    312: static uae_u32 fastmem_start; /* Determined by the OS */
                    313: static uae_u8 *fastmemory = NULL;
                    314: 
1.1.1.4   root      315: uae_u32 REGPARAM2 fastmem_lget (uaecptr addr)
1.1.1.3   root      316: {
                    317:     uae_u8 *m;
1.1       root      318:     addr -= fastmem_start & fastmem_mask;
                    319:     addr &= fastmem_mask;
                    320:     m = fastmemory + addr;
1.1.1.3   root      321:     return do_get_mem_long ((uae_u32 *)m);
1.1       root      322: }
                    323: 
1.1.1.4   root      324: uae_u32 REGPARAM2 fastmem_wget (uaecptr addr)
1.1       root      325: {
1.1.1.3   root      326:     uae_u8 *m;
1.1       root      327:     addr -= fastmem_start & fastmem_mask;
                    328:     addr &= fastmem_mask;
                    329:     m = fastmemory + addr;
1.1.1.3   root      330:     return do_get_mem_word ((uae_u16 *)m);
1.1       root      331: }
                    332: 
1.1.1.4   root      333: uae_u32 REGPARAM2 fastmem_bget (uaecptr addr)
1.1       root      334: {
                    335:     addr -= fastmem_start & fastmem_mask;
                    336:     addr &= fastmem_mask;
                    337:     return fastmemory[addr];
                    338: }
                    339: 
1.1.1.4   root      340: void REGPARAM2 fastmem_lput (uaecptr addr, uae_u32 l)
1.1       root      341: {
1.1.1.3   root      342:     uae_u8 *m;
1.1       root      343:     addr -= fastmem_start & fastmem_mask;
                    344:     addr &= fastmem_mask;
                    345:     m = fastmemory + addr;
1.1.1.3   root      346:     do_put_mem_long ((uae_u32 *)m, l);
1.1       root      347: }
                    348: 
1.1.1.4   root      349: void REGPARAM2 fastmem_wput (uaecptr addr, uae_u32 w)
1.1       root      350: {
1.1.1.3   root      351:     uae_u8 *m;
1.1       root      352:     addr -= fastmem_start & fastmem_mask;
                    353:     addr &= fastmem_mask;
                    354:     m = fastmemory + addr;
1.1.1.3   root      355:     do_put_mem_word ((uae_u16 *)m, w);
1.1       root      356: }
                    357: 
1.1.1.4   root      358: void REGPARAM2 fastmem_bput (uaecptr addr, uae_u32 b)
1.1       root      359: {
                    360:     addr -= fastmem_start & fastmem_mask;
                    361:     addr &= fastmem_mask;
                    362:     fastmemory[addr] = b;
                    363: }
                    364: 
1.1.1.4   root      365: static int REGPARAM2 fastmem_check (uaecptr addr, uae_u32 size)
1.1       root      366: {
                    367:     addr -= fastmem_start & fastmem_mask;
                    368:     addr &= fastmem_mask;
1.1.1.4   root      369:     return (addr + size) <= allocated_fastmem;
1.1       root      370: }
                    371: 
1.1.1.4   root      372: static uae_u8 REGPARAM2 *fastmem_xlate (uaecptr addr)
1.1       root      373: {
                    374:     addr -= fastmem_start & fastmem_mask;
                    375:     addr &= fastmem_mask;
                    376:     return fastmemory + addr;
                    377: }
                    378: 
                    379: addrbank fastmem_bank = {
                    380:     fastmem_lget, fastmem_wget, fastmem_bget,
                    381:     fastmem_lput, fastmem_wput, fastmem_bput,
1.1.1.8 ! root      382:     fastmem_xlate, fastmem_check, NULL
1.1       root      383: };
                    384: 
                    385: 
                    386: /*
                    387:  * Filesystem device ROM
1.1.1.3   root      388:  * This is very simple, the Amiga shouldn't be doing things with it.
1.1       root      389:  */
                    390: 
1.1.1.4   root      391: static uae_u32 filesys_lget (uaecptr) REGPARAM;
                    392: static uae_u32 filesys_wget (uaecptr) REGPARAM;
                    393: static uae_u32 filesys_bget (uaecptr) REGPARAM;
                    394: static void filesys_lput (uaecptr, uae_u32) REGPARAM;
                    395: static void filesys_wput (uaecptr, uae_u32) REGPARAM;
                    396: static void filesys_bput (uaecptr, uae_u32) REGPARAM;
1.1       root      397: 
1.1.1.3   root      398: static uae_u32 filesys_start; /* Determined by the OS */
1.1.1.8 ! root      399: uae_u8 *filesysory;
1.1       root      400: 
1.1.1.4   root      401: uae_u32 REGPARAM2 filesys_lget (uaecptr addr)
1.1       root      402: {
1.1.1.3   root      403:     uae_u8 *m;
1.1.1.7   root      404:     special_mem |= S_READ;
1.1       root      405:     addr -= filesys_start & 65535;
                    406:     addr &= 65535;
                    407:     m = filesysory + addr;
1.1.1.3   root      408:     return do_get_mem_long ((uae_u32 *)m);
1.1       root      409: }
                    410: 
1.1.1.4   root      411: uae_u32 REGPARAM2 filesys_wget (uaecptr addr)
1.1       root      412: {
1.1.1.3   root      413:     uae_u8 *m;
1.1.1.7   root      414:     special_mem |= S_READ;
1.1       root      415:     addr -= filesys_start & 65535;
                    416:     addr &= 65535;
                    417:     m = filesysory + addr;
1.1.1.3   root      418:     return do_get_mem_word ((uae_u16 *)m);
1.1       root      419: }
                    420: 
1.1.1.4   root      421: uae_u32 REGPARAM2 filesys_bget (uaecptr addr)
1.1       root      422: {
1.1.1.7   root      423:     special_mem |= S_READ;
1.1       root      424:     addr -= filesys_start & 65535;
                    425:     addr &= 65535;
                    426:     return filesysory[addr];
                    427: }
                    428: 
1.1.1.4   root      429: static void REGPARAM2 filesys_lput (uaecptr addr, uae_u32 l)
1.1       root      430: {
1.1.1.7   root      431:     special_mem |= S_WRITE;
1.1.1.3   root      432:     write_log ("filesys_lput called\n");
1.1       root      433: }
                    434: 
1.1.1.4   root      435: static void REGPARAM2 filesys_wput (uaecptr addr, uae_u32 w)
1.1       root      436: {
1.1.1.7   root      437:     special_mem |= S_WRITE;
1.1.1.3   root      438:     write_log ("filesys_wput called\n");
1.1       root      439: }
                    440: 
1.1.1.4   root      441: static void REGPARAM2 filesys_bput (uaecptr addr, uae_u32 b)
1.1       root      442: {
1.1.1.7   root      443:     special_mem |= S_WRITE;
1.1.1.3   root      444:     fprintf (stderr, "filesys_bput called. This usually means that you are using\n");
                    445:     fprintf (stderr, "Kickstart 1.2. Please give UAE the \"-a\" option next time\n");
                    446:     fprintf (stderr, "you start it. If you are _not_ using Kickstart 1.2, then\n");
                    447:     fprintf (stderr, "there's a bug somewhere.\n");
                    448:     fprintf (stderr, "Exiting...\n");
                    449:     uae_quit ();
1.1       root      450: }
                    451: 
                    452: addrbank filesys_bank = {
                    453:     filesys_lget, filesys_wget, filesys_bget,
                    454:     filesys_lput, filesys_wput, filesys_bput,
1.1.1.8 ! root      455:     default_xlate, default_check, NULL
1.1       root      456: };
                    457: 
1.1.1.3   root      458: /*
                    459:  *  Z3fastmem Memory
                    460:  */
1.1       root      461: 
                    462: 
1.1.1.3   root      463: static uae_u32 z3fastmem_mask;
1.1       root      464: 
1.1.1.4   root      465: static uae_u32 z3fastmem_lget (uaecptr) REGPARAM;
                    466: static uae_u32 z3fastmem_wget (uaecptr) REGPARAM;
                    467: static uae_u32 z3fastmem_bget (uaecptr) REGPARAM;
                    468: static void z3fastmem_lput (uaecptr, uae_u32) REGPARAM;
                    469: static void z3fastmem_wput (uaecptr, uae_u32) REGPARAM;
                    470: static void z3fastmem_bput (uaecptr, uae_u32) REGPARAM;
                    471: static int z3fastmem_check (uaecptr addr, uae_u32 size) REGPARAM;
                    472: static uae_u8 *z3fastmem_xlate (uaecptr addr) REGPARAM;
1.1.1.3   root      473: 
                    474: static uae_u32 z3fastmem_start; /* Determined by the OS */
                    475: static uae_u8 *z3fastmem = NULL;
1.1       root      476: 
1.1.1.4   root      477: uae_u32 REGPARAM2 z3fastmem_lget (uaecptr addr)
1.1       root      478: {
1.1.1.3   root      479:     uae_u8 *m;
                    480:     addr -= z3fastmem_start & z3fastmem_mask;
                    481:     addr &= z3fastmem_mask;
                    482:     m = z3fastmem + addr;
                    483:     return do_get_mem_long ((uae_u32 *)m);
1.1       root      484: }
                    485: 
1.1.1.4   root      486: uae_u32 REGPARAM2 z3fastmem_wget (uaecptr addr)
1.1       root      487: {
1.1.1.3   root      488:     uae_u8 *m;
                    489:     addr -= z3fastmem_start & z3fastmem_mask;
                    490:     addr &= z3fastmem_mask;
                    491:     m = z3fastmem + addr;
                    492:     return do_get_mem_word ((uae_u16 *)m);
1.1       root      493: }
                    494: 
1.1.1.4   root      495: uae_u32 REGPARAM2 z3fastmem_bget (uaecptr addr)
1.1       root      496: {
1.1.1.3   root      497:     addr -= z3fastmem_start & z3fastmem_mask;
                    498:     addr &= z3fastmem_mask;
                    499:     return z3fastmem[addr];
1.1       root      500: }
                    501: 
1.1.1.4   root      502: void REGPARAM2 z3fastmem_lput (uaecptr addr, uae_u32 l)
1.1       root      503: {
1.1.1.3   root      504:     uae_u8 *m;
                    505:     addr -= z3fastmem_start & z3fastmem_mask;
                    506:     addr &= z3fastmem_mask;
                    507:     m = z3fastmem + addr;
                    508:     do_put_mem_long ((uae_u32 *)m, l);
1.1       root      509: }
                    510: 
1.1.1.4   root      511: void REGPARAM2 z3fastmem_wput (uaecptr addr, uae_u32 w)
1.1       root      512: {
1.1.1.3   root      513:     uae_u8 *m;
                    514:     addr -= z3fastmem_start & z3fastmem_mask;
                    515:     addr &= z3fastmem_mask;
                    516:     m = z3fastmem + addr;
                    517:     do_put_mem_word ((uae_u16 *)m, w);
1.1       root      518: }
                    519: 
1.1.1.4   root      520: void REGPARAM2 z3fastmem_bput (uaecptr addr, uae_u32 b)
1.1       root      521: {
1.1.1.3   root      522:     addr -= z3fastmem_start & z3fastmem_mask;
                    523:     addr &= z3fastmem_mask;
                    524:     z3fastmem[addr] = b;
1.1       root      525: }
                    526: 
1.1.1.4   root      527: static int REGPARAM2 z3fastmem_check (uaecptr addr, uae_u32 size)
1.1       root      528: {
1.1.1.3   root      529:     addr -= z3fastmem_start & z3fastmem_mask;
                    530:     addr &= z3fastmem_mask;
1.1.1.4   root      531:     return (addr + size) <= allocated_z3fastmem;
1.1       root      532: }
                    533: 
1.1.1.4   root      534: static uae_u8 REGPARAM2 *z3fastmem_xlate (uaecptr addr)
1.1       root      535: {
1.1.1.3   root      536:     addr -= z3fastmem_start & z3fastmem_mask;
                    537:     addr &= z3fastmem_mask;
                    538:     return z3fastmem + addr;
                    539: }
1.1       root      540: 
1.1.1.3   root      541: addrbank z3fastmem_bank = {
                    542:     z3fastmem_lget, z3fastmem_wget, z3fastmem_bget,
                    543:     z3fastmem_lput, z3fastmem_wput, z3fastmem_bput,
1.1.1.8 ! root      544:     z3fastmem_xlate, z3fastmem_check, NULL
1.1.1.3   root      545: };
1.1       root      546: 
1.1.1.3   root      547: /* Z3-based UAEGFX-card */
                    548: uae_u32 gfxmem_mask; /* for memory.c */
                    549: uae_u8 *gfxmemory;
                    550: uae_u32 gfxmem_start;
1.1       root      551: 
1.1.1.3   root      552: /* ********************************************************** */
1.1       root      553: 
1.1.1.2   root      554: /*
1.1       root      555:  *     Expansion Card (ZORRO II) for 1/2/4/8 MB of Fast Memory
1.1.1.2   root      556:  */
1.1       root      557: 
1.1.1.3   root      558: static void expamem_map_fastcard (void)
1.1       root      559: {
1.1.1.3   root      560:     fastmem_start = ((expamem_hi | (expamem_lo >> 4)) << 16);
1.1.1.8 ! root      561:     map_banks (&fastmem_bank, fastmem_start >> 16, allocated_fastmem >> 16, allocated_fastmem);
1.1.1.4   root      562:     write_log ("Fastcard: mapped @$%lx: %dMB fast memory\n", fastmem_start, allocated_fastmem >> 20);
1.1       root      563: }
                    564: 
1.1.1.3   root      565: static void expamem_init_fastcard (void)
1.1       root      566: {
                    567:     expamem_init_clear();
1.1.1.4   root      568:     if (allocated_fastmem == 0x100000)
1.1.1.3   root      569:        expamem_write (0x00, Z2_MEM_1MB + add_memory + zorroII);
1.1.1.4   root      570:     else if (allocated_fastmem == 0x200000)
1.1.1.3   root      571:        expamem_write (0x00, Z2_MEM_2MB + add_memory + zorroII);
1.1.1.4   root      572:     else if (allocated_fastmem == 0x400000)
1.1.1.3   root      573:        expamem_write (0x00, Z2_MEM_4MB + add_memory + zorroII);
1.1.1.4   root      574:     else if (allocated_fastmem == 0x800000)
1.1.1.3   root      575:        expamem_write (0x00, Z2_MEM_8MB + add_memory + zorroII);
1.1       root      576: 
                    577:     expamem_write (0x08, care_addr);
                    578: 
                    579:     expamem_write (0x04, 1);
1.1.1.3   root      580: 
1.1       root      581:     expamem_write (0x10, hackers_id >> 8);
1.1.1.3   root      582:     expamem_write (0x14, hackers_id & 0xff);
1.1       root      583: 
                    584:     expamem_write (0x18, 0x00); /* ser.no. Byte 0 */
                    585:     expamem_write (0x1c, 0x00); /* ser.no. Byte 1 */
                    586:     expamem_write (0x20, 0x00); /* ser.no. Byte 2 */
                    587:     expamem_write (0x24, 0x01); /* ser.no. Byte 3 */
                    588: 
1.1.1.3   root      589:     expamem_write (0x28, 0x00); /* Rom-Offset hi */
                    590:     expamem_write (0x2c, 0x00); /* ROM-Offset lo */
1.1       root      591: 
                    592:     expamem_write (0x40, 0x00); /* Ctrl/Statusreg.*/
                    593: }
                    594: 
1.1.1.3   root      595: /* ********************************************************** */
                    596: 
1.1       root      597: /* 
                    598:  * Filesystem device
                    599:  */
                    600: 
1.1.1.3   root      601: static void expamem_map_filesys (void)
1.1       root      602: {
1.1.1.3   root      603:     uaecptr a;
                    604: 
                    605:     filesys_start = ((expamem_hi | (expamem_lo >> 4)) << 16);
1.1.1.8 ! root      606:     map_banks (&filesys_bank, filesys_start >> 16, 1, 0);
1.1.1.5   root      607:     write_log ("Filesystem: mapped memory @$%lx.\n", filesys_start);
1.1.1.3   root      608:     /* 68k code needs to know this. */
                    609:     a = here ();
                    610:     org (0xF0FFFC);
                    611:     dl (filesys_start + 0x2000);
                    612:     org (a);
1.1       root      613: }
                    614: 
1.1.1.3   root      615: static void expamem_init_filesys (void)
1.1       root      616: {
1.1.1.5   root      617:     /* struct DiagArea - the size has to be large enough to store several device ROMTags */
                    618:     uae_u8 diagarea[] = { 0x90, 0x00, /* da_Config, da_Flags */
                    619:                           0x02, 0x00, /* da_Size */
                    620:                           0x01, 0x00, /* da_DiagPoint */
                    621:                           0x01, 0x06  /* da_BootPoint */
                    622:     };
1.1       root      623: 
                    624:     expamem_init_clear();
1.1.1.3   root      625:     expamem_write (0x00, Z2_MEM_64KB | rom_card | zorroII);
1.1       root      626: 
1.1.1.3   root      627:     expamem_write (0x08, no_shutup);
1.1       root      628: 
                    629:     expamem_write (0x04, 2);
                    630:     expamem_write (0x10, hackers_id >> 8);
1.1.1.3   root      631:     expamem_write (0x14, hackers_id & 0xff);
1.1       root      632: 
                    633:     expamem_write (0x18, 0x00); /* ser.no. Byte 0 */
                    634:     expamem_write (0x1c, 0x00); /* ser.no. Byte 1 */
                    635:     expamem_write (0x20, 0x00); /* ser.no. Byte 2 */
                    636:     expamem_write (0x24, 0x01); /* ser.no. Byte 3 */
                    637: 
1.1.1.5   root      638:     /* er_InitDiagVec */
1.1.1.3   root      639:     expamem_write (0x28, 0x10); /* Rom-Offset hi */
                    640:     expamem_write (0x2c, 0x00); /* ROM-Offset lo */
1.1       root      641: 
                    642:     expamem_write (0x40, 0x00); /* Ctrl/Statusreg.*/
                    643: 
                    644:     /* Build a DiagArea */
1.1.1.3   root      645:     memcpy (expamem + 0x1000, diagarea, sizeof diagarea);
                    646: 
1.1       root      647:     /* Call DiagEntry */
1.1.1.3   root      648:     do_put_mem_word ((uae_u16 *)(expamem + 0x1100), 0x4EF9); /* JMP */
                    649:     do_put_mem_long ((uae_u32 *)(expamem + 0x1102), ROM_filesys_diagentry);
                    650: 
1.1       root      651:     /* What comes next is a plain bootblock */
1.1.1.3   root      652:     do_put_mem_word ((uae_u16 *)(expamem + 0x1106), 0x4EF9); /* JMP */
                    653:     do_put_mem_long ((uae_u32 *)(expamem + 0x1108), EXPANSION_bootcode);
                    654: 
                    655:     memcpy (filesysory, expamem, 0x3000);
1.1       root      656: }
                    657: 
1.1.1.2   root      658: /*
1.1.1.3   root      659:  * Zorro III expansion memory
1.1.1.2   root      660:  */
1.1       root      661: 
1.1.1.3   root      662: static void expamem_map_z3fastmem (void)
1.1       root      663: {
1.1.1.3   root      664:     z3fastmem_start = ((expamem_hi | (expamem_lo >> 4)) << 16);
1.1.1.8 ! root      665:     map_banks (&z3fastmem_bank, z3fastmem_start >> 16, currprefs.z3fastmem_size >> 16,
        !           666:               allocated_z3fastmem);
1.1.1.3   root      667: 
1.1.1.4   root      668:     write_log ("Fastmem (32bit): mapped @$%lx: %d MB Zorro III fast memory \n",
                    669:               z3fastmem_start, allocated_z3fastmem / 0x100000);
1.1.1.3   root      670: }
                    671: 
                    672: static void expamem_init_z3fastmem (void)
                    673: {
1.1.1.4   root      674:     int code = (allocated_z3fastmem == 0x100000 ? Z2_MEM_1MB
                    675:                : allocated_z3fastmem == 0x200000 ? Z2_MEM_2MB
                    676:                : allocated_z3fastmem == 0x400000 ? Z2_MEM_4MB
                    677:                : allocated_z3fastmem == 0x800000 ? Z2_MEM_8MB
                    678:                : allocated_z3fastmem == 0x1000000 ? Z2_MEM_16MB
                    679:                : allocated_z3fastmem == 0x2000000 ? Z2_MEM_32MB
                    680:                : allocated_z3fastmem == 0x4000000 ? Z2_MEM_64MB
                    681:                : allocated_z3fastmem == 0x8000000 ? Z2_MEM_128MB
                    682:                : allocated_z3fastmem == 0x10000000 ? Z2_MEM_256MB
                    683:                : allocated_z3fastmem == 0x20000000 ? Z2_MEM_512MB
1.1.1.3   root      684:                : Z2_MEM_1GB);
                    685:     expamem_init_clear();
                    686:     expamem_write (0x00, add_memory | zorroIII | code);
                    687: 
1.1.1.4   root      688:     expamem_write (0x08, no_shutup | force_z3 | (allocated_z3fastmem > 0x800000 ? ext_size : Z3_MEM_AUTO));
1.1.1.3   root      689: 
                    690:     expamem_write (0x04, 3);
                    691: 
                    692:     expamem_write (0x10, hackers_id >> 8);
                    693:     expamem_write (0x14, hackers_id & 0xff);
                    694: 
                    695:     expamem_write (0x18, 0x00); /* ser.no. Byte 0 */
                    696:     expamem_write (0x1c, 0x00); /* ser.no. Byte 1 */
                    697:     expamem_write (0x20, 0x00); /* ser.no. Byte 2 */
                    698:     expamem_write (0x24, 0x01); /* ser.no. Byte 3 */
                    699: 
                    700:     expamem_write (0x28, 0x00); /* Rom-Offset hi */
                    701:     expamem_write (0x2c, 0x00); /* ROM-Offset lo */
                    702: 
                    703:     expamem_write (0x40, 0x00); /* Ctrl/Statusreg.*/
1.1       root      704: }
                    705: 
1.1.1.3   root      706: #ifdef PICASSO96
                    707: /*
                    708:  *  Fake Graphics Card (ZORRO III) - BDK
                    709:  */
                    710: 
                    711: static void expamem_map_gfxcard (void)
1.1       root      712: {
1.1.1.3   root      713:     gfxmem_start = ((expamem_hi | (expamem_lo >> 4)) << 16);
1.1.1.8 ! root      714:     map_banks (&gfxmem_bank, gfxmem_start >> 16, allocated_gfxmem >> 16, allocated_gfxmem);
1.1.1.4   root      715:     write_log ("UAEGFX-card: mapped @$%lx \n", gfxmem_start);
1.1       root      716: }
1.1.1.3   root      717: 
                    718: static void expamem_init_gfxcard (void)
                    719: {
                    720:     expamem_init_clear();
                    721:     expamem_write (0x00, zorroIII);
                    722: 
1.1.1.4   root      723:     switch (allocated_gfxmem) {
1.1.1.3   root      724:      case 0x00100000:
                    725:        expamem_write (0x08, no_shutup | force_z3 | Z3_MEM_1MB);
                    726:        break;
                    727:      case 0x00200000:
                    728:        expamem_write (0x08, no_shutup | force_z3 | Z3_MEM_2MB);
                    729:        break;
                    730:      case 0x00400000:
                    731:        expamem_write (0x08, no_shutup | force_z3 | Z3_MEM_4MB);
                    732:        break;
                    733:      case 0x00800000:
                    734:        expamem_write (0x08, no_shutup | force_z3 | Z3_MEM_8MB);
                    735:        break;
                    736:     }
                    737: 
                    738:     expamem_write (0x04, 96);
                    739: 
                    740:     expamem_write (0x10, hackers_id >> 8);
                    741:     expamem_write (0x14, hackers_id & 0xff);
                    742: 
                    743:     expamem_write (0x18, 0x00); /* ser.no. Byte 0 */
                    744:     expamem_write (0x1c, 0x00); /* ser.no. Byte 1 */
                    745:     expamem_write (0x20, 0x00); /* ser.no. Byte 2 */
                    746:     expamem_write (0x24, 0x01); /* ser.no. Byte 3 */
                    747: 
                    748:     expamem_write (0x28, 0x00); /* Rom-Offset hi */
                    749:     expamem_write (0x2c, 0x00); /* ROM-Offset lo */
                    750: 
                    751:     expamem_write (0x40, 0x00); /* Ctrl/Statusreg.*/
                    752: }
                    753: #endif
                    754: 
1.1.1.8 ! root      755: static long fast_filepos, z3_filepos;
        !           756: 
        !           757: static void allocate_expamem (void)
        !           758: {
        !           759:     currprefs.fastmem_size = changed_prefs.fastmem_size;
        !           760:     currprefs.z3fastmem_size = changed_prefs.z3fastmem_size;
        !           761:     currprefs.gfxmem_size = changed_prefs.gfxmem_size;
        !           762: 
        !           763:     if (allocated_fastmem != currprefs.fastmem_size) {
        !           764:        if (fastmemory)
        !           765:            free (fastmemory);
        !           766:        fastmemory = 0;
        !           767:        allocated_fastmem = currprefs.fastmem_size;
        !           768:        fastmem_mask = allocated_fastmem - 1;
        !           769: 
        !           770:        if (allocated_fastmem) {
        !           771:            fastmemory = mapped_malloc (allocated_fastmem, "fast");
        !           772:            if (fastmemory == 0) {
        !           773:                write_log ("Out of memory for fastmem card.\n");
        !           774:                allocated_fastmem = 0;
        !           775:            }
        !           776:        }
        !           777:     }
        !           778:     if (allocated_z3fastmem != currprefs.z3fastmem_size) {
        !           779:        if (z3fastmem)
        !           780:            free (z3fastmem);
        !           781:        z3fastmem = 0;
        !           782: 
        !           783:        allocated_z3fastmem = currprefs.z3fastmem_size;
        !           784:        z3fastmem_mask = allocated_z3fastmem - 1;
        !           785: 
        !           786:        if (allocated_z3fastmem) {
        !           787:            z3fastmem = mapped_malloc (allocated_z3fastmem, "z3");
        !           788:            if (z3fastmem == 0) {
        !           789:                write_log ("Out of memory for 32 bit fast memory.\n");
        !           790:                allocated_z3fastmem = 0;
        !           791:            }
        !           792:        }
        !           793:     }
        !           794:     if (allocated_gfxmem != currprefs.gfxmem_size) {
        !           795:        if (gfxmemory)
        !           796:            free (gfxmemory);
        !           797:        gfxmemory = 0;
        !           798: 
        !           799:        allocated_gfxmem = currprefs.gfxmem_size;
        !           800:        gfxmem_mask = allocated_gfxmem - 1;
        !           801: 
        !           802:        if (allocated_gfxmem) {
        !           803:            gfxmemory = mapped_malloc (allocated_gfxmem, "gfx");
        !           804:            if (gfxmemory == 0) {
        !           805:                write_log ("Out of memory for graphics card memory\n");
        !           806:                allocated_gfxmem = 0;
        !           807:            }
        !           808:        }
        !           809:     }
        !           810: 
        !           811:     z3fastmem_bank.baseaddr = z3fastmem;
        !           812:     fastmem_bank.baseaddr = fastmemory;
        !           813: 
        !           814:     if (savestate_state == STATE_RESTORE) {
        !           815:        if (allocated_fastmem > 0) {
        !           816:            fseek (savestate_file, fast_filepos, SEEK_SET);
        !           817:            fread (fastmemory, 1, allocated_fastmem, savestate_file);
        !           818:            map_banks (&fastmem_bank, fastmem_start >> 16, currprefs.fastmem_size >> 16,
        !           819:                       allocated_fastmem);
        !           820:        }
        !           821:        if (allocated_z3fastmem > 0) {
        !           822:            fseek (savestate_file, z3_filepos, SEEK_SET);
        !           823:            fread (z3fastmem, 1, allocated_z3fastmem, savestate_file);
        !           824:            map_banks (&z3fastmem_bank, z3fastmem_start >> 16, currprefs.z3fastmem_size >> 16,
        !           825:                       allocated_z3fastmem);
        !           826:        }
        !           827:     }
        !           828: }
        !           829: 
        !           830: void expamem_reset (void)
1.1.1.3   root      831: {
1.1.1.8 ! root      832:     int do_mount = 1;
1.1.1.3   root      833:     int cardno = 0;
                    834:     ecard = 0;
                    835: 
1.1.1.8 ! root      836:     allocate_expamem ();
        !           837: 
        !           838:     /* check if Kickstart version is below 1.3 */
        !           839:     if (! ersatzkickfile
        !           840:        && (/* Kickstart 1.0 & 1.1! */
        !           841:            get_word (0xF8000C) == 0xFFFF
        !           842:            /* Kickstart < 1.3 */
        !           843:            || get_word (0xF8000C) < 34))
        !           844:     {
        !           845:        /* warn user */
        !           846:        write_log ("Kickstart version is below 1.3!  Disabling autoconfig devices.\n");
        !           847:        do_mount = 0;
        !           848:     }
        !           849: 
1.1.1.3   root      850:     if (fastmemory != NULL) {
                    851:        card_init[cardno] = expamem_init_fastcard;
                    852:        card_map[cardno++] = expamem_map_fastcard;
                    853:     }
                    854:     if (z3fastmem != NULL) {
                    855:        card_init[cardno] = expamem_init_z3fastmem;
                    856:        card_map[cardno++] = expamem_map_z3fastmem;
                    857:     }
                    858: #ifdef PICASSO96
                    859:     if (gfxmemory != NULL) {
                    860:        card_init[cardno] = expamem_init_gfxcard;
                    861:        card_map[cardno++] = expamem_map_gfxcard;
                    862:     }
                    863: #endif
1.1.1.8 ! root      864:     if (do_mount && ! ersatzkickfile) {
1.1.1.3   root      865:        card_init[cardno] = expamem_init_filesys;
                    866:        card_map[cardno++] = expamem_map_filesys;
                    867:     }
                    868:     while (cardno < MAX_EXPANSION_BOARDS) {
                    869:        card_init[cardno] = expamem_init_clear;
                    870:        card_map[cardno++] = expamem_map_clear;
                    871:     }
                    872: 
                    873:     (*card_init[0]) ();
                    874: }
                    875: 
1.1.1.4   root      876: void expansion_init (void)
1.1.1.3   root      877: {
1.1.1.8 ! root      878:     z3fastmem = 0;
        !           879:     gfxmemory = 0;
        !           880:     fastmemory = 0;
        !           881:     allocated_z3fastmem = 0;
        !           882:     allocated_gfxmem = 0;
        !           883:     allocated_fastmem = 0;
        !           884: 
        !           885:     allocate_expamem ();
        !           886: 
        !           887:     filesysory = (uae_u8 *) mapped_malloc (0x10000, "filesys");
        !           888:     if (!filesysory) {
        !           889:        write_log ("virtual memory exhausted (filesysory)!\n");
        !           890:        exit (0);
1.1.1.3   root      891:     }
1.1.1.8 ! root      892:     filesys_bank.baseaddr = (uae_u8*)filesysory;
        !           893: 
1.1.1.3   root      894: }
                    895: 
1.1.1.8 ! root      896: /* State save/restore code.  */
        !           897: 
        !           898: uae_u8 *save_fram (int *len)
        !           899: {
        !           900:     *len = allocated_fastmem;
        !           901:     return fastmemory;
        !           902: }
        !           903: 
        !           904: uae_u8 *save_zram (int *len)
        !           905: {
        !           906:     *len = allocated_z3fastmem;
        !           907:     return z3fastmem;
        !           908: }
        !           909: 
        !           910: void restore_fram (int len, long filepos)
        !           911: {
        !           912:     fast_filepos = filepos;
        !           913:     changed_prefs.fastmem_size = len;
        !           914: }
        !           915: 
        !           916: void restore_zram (int len, long filepos)
        !           917: {
        !           918:     z3_filepos = filepos;
        !           919:     changed_prefs.z3fastmem_size = len;
        !           920: }
        !           921: 
        !           922: uae_u8 *save_expansion (int *len)
        !           923: {
        !           924:     static uae_u8 t[20], *dst = t;
        !           925:     save_u32 (fastmem_start);
        !           926:     save_u32 (z3fastmem_start);
        !           927:     *len = 8;
        !           928:     return dst;
        !           929: }
        !           930: 
        !           931: uae_u8 *restore_expansion (uae_u8 *src)
        !           932: {
        !           933:     fastmem_start = restore_u32 ();
        !           934:     z3fastmem_start = restore_u32 ();
        !           935:     return src;
        !           936: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.