Annotation of hatari/src/cart.c, revision 1.1.1.17

1.1       root        1: /*
1.1.1.4   root        2:   Hatari - cart.c
                      3: 
1.1.1.12  root        4:   This file is distributed under the GNU General Public License, version 2
                      5:   or at your option any later version. Read the file gpl.txt for details.
1.1       root        6: 
1.1.1.5   root        7:   Cartridge program
1.1       root        8: 
1.1.1.7   root        9:   To load programs into memory, through TOS, we need to intercept GEMDOS so we
                     10:   can relocate/execute programs via GEMDOS call $4B (Pexec).
1.1.1.5   root       11:   We have some 68000 assembler, located at 0xFA0000 (cartridge memory), which is
                     12:   used as our new GEMDOS handler. This checks if we need to intercept the call.
1.1       root       13: 
1.1.1.7   root       14:   The assembler routine can be found in 'cart_asm.s', and has been converted to
                     15:   a byte array and stored in 'Cart_data[]' (see cartData.c).
1.1       root       16: */
1.1.1.10  root       17: const char Cart_fileid[] = "Hatari cart.c : " __DATE__ " " __TIME__;
1.1.1.8   root       18: 
                     19: /* 2007/12/09  [NP]    Change the function associated to opcodes $8, $a and $c only if hard drive      */
                     20: /*                     emulation is ON. Else, these opcodes should give illegal instructions (also     */
                     21: /*                     see uae-cpu/newcpu.c).                                                          */
                     22: 
1.1       root       23: 
                     24: #include "main.h"
                     25: #include "cart.h"
1.1.1.4   root       26: #include "configuration.h"
                     27: #include "file.h"
1.1.1.7   root       28: #include "log.h"
1.1.1.9   root       29: #include "m68000.h"
1.1       root       30: #include "stMemory.h"
1.1.1.16  root       31: #include "inffile.h"
1.1.1.12  root       32: #include "tos.h"
1.1.1.4   root       33: #include "vdi.h"
1.1.1.8   root       34: #include "hatari-glue.h"
                     35: #include "newcpu.h"
1.1       root       36: 
1.1.1.5   root       37: #include "cartData.c"
1.1       root       38: 
                     39: 
1.1.1.7   root       40: /* Possible cartridge file extensions to scan for */
                     41: static const char * const psCartNameExts[] =
                     42: {
                     43:        ".img",
                     44:        ".rom",
                     45:        ".stc",
                     46:        NULL
                     47: };
                     48: 
1.1.1.14  root       49: static int PatchIllegal = false;
                     50: 
1.1.1.7   root       51: 
1.1       root       52: /*-----------------------------------------------------------------------*/
1.1.1.8   root       53: /**
                     54:  * Load an external cartridge image file.
                     55:  */
1.1.1.7   root       56: static void Cart_LoadImage(void)
1.1       root       57: {
1.1.1.7   root       58:        Uint8 *pCartData;
                     59:        long nCartSize;
1.1.1.4   root       60:        char *pCartFileName = ConfigureParams.Rom.szCartridgeImageFileName;
                     61: 
1.1.1.7   root       62:        /* Try to load the image file: */
1.1.1.8   root       63:        pCartData = File_Read(pCartFileName, &nCartSize, psCartNameExts);
1.1.1.7   root       64:        if (!pCartData)
                     65:        {
                     66:                Log_Printf(LOG_ERROR, "Failed to load '%s'.\n", pCartFileName);
                     67:                return;
                     68:        }
                     69: 
                     70:        if (nCartSize < 40 || (nCartSize > 0x20000 && nCartSize != 0x20004))
                     71:        {
                     72:                Log_Printf(LOG_ERROR, "Cartridge file '%s' has illegal size.\n", pCartFileName);
                     73:                free(pCartData);
                     74:                return;
                     75:        }
                     76: 
                     77:        /* There are two type of cartridge images, normal 1:1 images which are
                     78:         * always smaller than or equal to 0x20000 bytes, and the .STC images,
                     79:         * which are always 0x20004 bytes (the first 4 bytes are a dummy header).
                     80:         * So if size is 0x20004 bytes we have to skip the first 4 bytes */
                     81:        if (nCartSize == 0x20004)
                     82:        {
1.1.1.8   root       83:                memcpy(&RomMem[0xfa0000], pCartData+4, 0x20000);
1.1.1.7   root       84:        }
                     85:        else
                     86:        {
1.1.1.8   root       87:                memcpy(&RomMem[0xfa0000], pCartData, nCartSize);
1.1.1.7   root       88:        }
                     89: 
                     90:        free(pCartData);
                     91: }
                     92: 
                     93: 
                     94: /*-----------------------------------------------------------------------*/
1.1.1.8   root       95: /**
                     96:  * Copy ST GEMDOS intercept program image into cartridge memory space
                     97:  * or load an external cartridge file.
                     98:  * The intercept program is part of Hatari and used as an interface to the host
                     99:  * file system through GemDOS. It is also needed for Line-A-Init when using
                    100:  * extended VDI resolutions.
                    101:  */
1.1.1.7   root      102: void Cart_ResetImage(void)
                    103: {
1.1.1.4   root      104:        /* "Clear" cartridge ROM space */
1.1.1.8   root      105:        memset(&RomMem[0xfa0000], 0xff, 0x20000);
1.1.1.4   root      106: 
1.1.1.7   root      107:        /* Print a warning if user tries to use an external cartridge file
1.1.1.17! root      108:         * together with something else requiring cartridge code:
        !           109:         * - GEMDOS hard disk emulation
        !           110:         * - extended VDI resolution
        !           111:         * - GEMDOS/AES/VDI tracing
        !           112:         */
        !           113:        if (strlen(ConfigureParams.Rom.szCartridgeImageFileName) > 0 &&
        !           114:            (bUseVDIRes || ConfigureParams.HardDisk.bUseHardDiskDirectories ||
        !           115:             (LogTraceFlags & (TRACE_OS_GEMDOS | TRACE_OS_BASE | TRACE_OS_VDI | TRACE_OS_AES))))
1.1.1.7   root      116:        {
1.1.1.17! root      117:                Log_AlertDlg(LOG_ERROR, "Cartridge disabled! It can't be used with VDI mode, GEMDOS HD emulation nor their tracing.");
1.1.1.7   root      118:        }
                    119: 
1.1.1.13  root      120:        /* Use internal cartridge trampoline code when user wants extended VDI
1.1.1.16  root      121:         * resolution, use GEMDOS HD emulation / Autostarting, or to trace GEMDOS,
                    122:         * VDI or AES (OS_BASE does subset of GEMDOS tracing).
                    123:         * But don't use it on TOS 0.00, it does not work there.
                    124:         */
1.1.1.15  root      125:        PatchIllegal = false;                           /* By default, don't patch opcodes */
1.1.1.16  root      126:        if ((bUseVDIRes || INF_Overriding(AUTOSTART_INTERCEPT) ||
                    127:             ConfigureParams.HardDisk.bUseHardDiskDirectories ||
1.1.1.14  root      128:            LogTraceFlags & (TRACE_OS_GEMDOS | TRACE_OS_BASE | TRACE_OS_VDI | TRACE_OS_AES))
1.1.1.17! root      129:            && (TosVersion >= 0x100 || !bUseTos))
1.1.1.4   root      130:        {
1.1.1.12  root      131:                /* Copy built-in cartridge data into the cartridge memory of the ST */
1.1.1.9   root      132:                memcpy(&RomMem[0xfa0000], Cart_data, sizeof(Cart_data));
1.1.1.11  root      133:                PatchIllegal = true;
1.1.1.4   root      134:        }
1.1.1.7   root      135:        else if (strlen(ConfigureParams.Rom.szCartridgeImageFileName) > 0)
1.1.1.4   root      136:        {
1.1.1.7   root      137:                /* Load external image file: */
                    138:                Cart_LoadImage();
1.1.1.4   root      139:        }
1.1.1.14  root      140: }
                    141: 
1.1.1.8   root      142: 
1.1.1.14  root      143: /*-----------------------------------------------------------------------*/
                    144: /**
                    145:  * Patch the cpu tables to intercept some opcodes used for Gemdos HD
                    146:  * emulation or for NatFeats.
                    147:  * We need to split this from Cart_ResetImage(), as the patches should
                    148:  * be applied after building the cpu opcodes tables.
                    149:  */
1.1.1.17! root      150: void Cart_PatchCpuTables(void)
1.1.1.14  root      151: {
1.1.1.17! root      152: //printf ( "Cart_PatchCpuTables\n" );
1.1.1.11  root      153:        if (PatchIllegal == true)
1.1.1.8   root      154:        {
                    155:                //fprintf ( stderr ," Cart_ResetImage patch\n" );
                    156:                /* Hatari's specific illegal opcodes for HD emulation */
                    157:                cpufunctbl[GEMDOS_OPCODE] = OpCode_GemDos;      /* 0x0008 */
                    158:                cpufunctbl[SYSINIT_OPCODE] = OpCode_SysInit;    /* 0x000a */
                    159:                cpufunctbl[VDI_OPCODE] = OpCode_VDI;            /* 0x000c */
                    160:        }
                    161:        else
                    162:        {
                    163:                //fprintf ( stderr ," Cart_ResetImage no patch\n" );
                    164:                /* No built-in cartridge loaded : set same handler as 0x4afc (illegal) */
                    165:                cpufunctbl[GEMDOS_OPCODE] = cpufunctbl[ 0x4afc ];       /* 0x0008 */
                    166:                cpufunctbl[SYSINIT_OPCODE] = cpufunctbl[ 0x4afc ];      /* 0x000a */
                    167:                cpufunctbl[VDI_OPCODE] = cpufunctbl[ 0x4afc ];          /* 0x000c */
                    168:        }
1.1.1.12  root      169: 
                    170:        /* although these don't need cartridge code, it's better
                    171:         * to configure all illegal opcodes in same place...
                    172:         */
                    173:        if (ConfigureParams.Log.bNatFeats)
                    174:        {
                    175:                /* illegal opcodes for emulators Native Features */
                    176:                cpufunctbl[NATFEAT_ID_OPCODE] = OpCode_NatFeat_ID;      /* 0x7300 */
                    177:                cpufunctbl[NATFEAT_CALL_OPCODE] = OpCode_NatFeat_Call;  /* 0x7301 */
                    178:        }
                    179:        else
                    180:        {
                    181:                /* No Native Features : set same handler as 0x4afc (illegal) */
                    182:                cpufunctbl[NATFEAT_ID_OPCODE] = cpufunctbl[ 0x4afc ];   /* 0x7300 */
                    183:                cpufunctbl[NATFEAT_CALL_OPCODE] = cpufunctbl[ 0x4afc ]; /* 0x7300 */
                    184:        }
1.1       root      185: }

unix.superglobalmegacorp.com

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