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

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.12  root       31: #include "tos.h"
1.1.1.4   root       32: #include "vdi.h"
1.1.1.8   root       33: #include "hatari-glue.h"
                     34: #include "newcpu.h"
1.1       root       35: 
1.1.1.5   root       36: #include "cartData.c"
1.1       root       37: 
                     38: 
1.1.1.7   root       39: /* Possible cartridge file extensions to scan for */
                     40: static const char * const psCartNameExts[] =
                     41: {
                     42:        ".img",
                     43:        ".rom",
                     44:        ".stc",
                     45:        NULL
                     46: };
                     47: 
1.1.1.14! root       48: static int PatchIllegal = false;
        !            49: 
1.1.1.7   root       50: 
1.1       root       51: /*-----------------------------------------------------------------------*/
1.1.1.8   root       52: /**
                     53:  * Load an external cartridge image file.
                     54:  */
1.1.1.7   root       55: static void Cart_LoadImage(void)
1.1       root       56: {
1.1.1.7   root       57:        Uint8 *pCartData;
                     58:        long nCartSize;
1.1.1.4   root       59:        char *pCartFileName = ConfigureParams.Rom.szCartridgeImageFileName;
                     60: 
1.1.1.7   root       61:        /* Try to load the image file: */
1.1.1.8   root       62:        pCartData = File_Read(pCartFileName, &nCartSize, psCartNameExts);
1.1.1.7   root       63:        if (!pCartData)
                     64:        {
                     65:                Log_Printf(LOG_ERROR, "Failed to load '%s'.\n", pCartFileName);
                     66:                return;
                     67:        }
                     68: 
                     69:        if (nCartSize < 40 || (nCartSize > 0x20000 && nCartSize != 0x20004))
                     70:        {
                     71:                Log_Printf(LOG_ERROR, "Cartridge file '%s' has illegal size.\n", pCartFileName);
                     72:                free(pCartData);
                     73:                return;
                     74:        }
                     75: 
                     76:        /* There are two type of cartridge images, normal 1:1 images which are
                     77:         * always smaller than or equal to 0x20000 bytes, and the .STC images,
                     78:         * which are always 0x20004 bytes (the first 4 bytes are a dummy header).
                     79:         * So if size is 0x20004 bytes we have to skip the first 4 bytes */
                     80:        if (nCartSize == 0x20004)
                     81:        {
1.1.1.8   root       82:                memcpy(&RomMem[0xfa0000], pCartData+4, 0x20000);
1.1.1.7   root       83:        }
                     84:        else
                     85:        {
1.1.1.8   root       86:                memcpy(&RomMem[0xfa0000], pCartData, nCartSize);
1.1.1.7   root       87:        }
                     88: 
                     89:        free(pCartData);
                     90: }
                     91: 
                     92: 
                     93: /*-----------------------------------------------------------------------*/
1.1.1.8   root       94: /**
                     95:  * Copy ST GEMDOS intercept program image into cartridge memory space
                     96:  * or load an external cartridge file.
                     97:  * The intercept program is part of Hatari and used as an interface to the host
                     98:  * file system through GemDOS. It is also needed for Line-A-Init when using
                     99:  * extended VDI resolutions.
                    100:  */
1.1.1.7   root      101: void Cart_ResetImage(void)
                    102: {
1.1.1.4   root      103:        /* "Clear" cartridge ROM space */
1.1.1.8   root      104:        memset(&RomMem[0xfa0000], 0xff, 0x20000);
1.1.1.4   root      105: 
1.1.1.7   root      106:        /* Print a warning if user tries to use an external cartridge file
                    107:         * together with GEMDOS HD emulation or extended VDI resolution: */
                    108:        if (strlen(ConfigureParams.Rom.szCartridgeImageFileName) > 0)
                    109:        {
                    110:                if (bUseVDIRes)
                    111:                        Log_Printf(LOG_WARN, "Cartridge can't be used together with extended VDI resolution!\n");
                    112:                if (ConfigureParams.HardDisk.bUseHardDiskDirectories)
                    113:                        Log_Printf(LOG_WARN, "Cartridge can't be used together with GEMDOS hard disk emulation!\n");
1.1.1.14! root      114:                if (LogTraceFlags & (TRACE_OS_GEMDOS | TRACE_OS_BASE | TRACE_OS_VDI | TRACE_OS_AES))
1.1.1.13  root      115:                        Log_Printf(LOG_WARN, "Cartridge can't be used together with GEMDOS/VDI/AES tracing!\n");
1.1.1.7   root      116:        }
                    117: 
1.1.1.13  root      118:        /* Use internal cartridge trampoline code when user wants extended VDI
                    119:         * resolution, GEMDOS HD emulation or to trace GEMDOS, VDI or AES.
1.1.1.14! root      120:         * (OS_BASE does subset of GEMDOS tracing)
1.1.1.13  root      121:         * But don't use it on TOS 0.00, it does not work there. */
                    122:        if ((bUseVDIRes || ConfigureParams.HardDisk.bUseHardDiskDirectories ||
1.1.1.14! root      123:            LogTraceFlags & (TRACE_OS_GEMDOS | TRACE_OS_BASE | TRACE_OS_VDI | TRACE_OS_AES))
1.1.1.12  root      124:            && TosVersion >= 0x100)
1.1.1.4   root      125:        {
1.1.1.12  root      126:                /* Copy built-in cartridge data into the cartridge memory of the ST */
1.1.1.9   root      127:                memcpy(&RomMem[0xfa0000], Cart_data, sizeof(Cart_data));
1.1.1.11  root      128:                PatchIllegal = true;
1.1.1.4   root      129:        }
1.1.1.7   root      130:        else if (strlen(ConfigureParams.Rom.szCartridgeImageFileName) > 0)
1.1.1.4   root      131:        {
1.1.1.7   root      132:                /* Load external image file: */
                    133:                Cart_LoadImage();
1.1.1.4   root      134:        }
1.1.1.14! root      135: }
        !           136: 
1.1.1.8   root      137: 
1.1.1.14! root      138: /*-----------------------------------------------------------------------*/
        !           139: /**
        !           140:  * Patch the cpu tables to intercept some opcodes used for Gemdos HD
        !           141:  * emulation or for NatFeats.
        !           142:  * We need to split this from Cart_ResetImage(), as the patches should
        !           143:  * be applied after building the cpu opcodes tables.
        !           144:  */
        !           145: void Cart_Patch(void)
        !           146: {
1.1.1.11  root      147:        if (PatchIllegal == true)
1.1.1.8   root      148:        {
                    149:                //fprintf ( stderr ," Cart_ResetImage patch\n" );
                    150:                /* Hatari's specific illegal opcodes for HD emulation */
                    151:                cpufunctbl[GEMDOS_OPCODE] = OpCode_GemDos;      /* 0x0008 */
                    152:                cpufunctbl[SYSINIT_OPCODE] = OpCode_SysInit;    /* 0x000a */
                    153:                cpufunctbl[VDI_OPCODE] = OpCode_VDI;            /* 0x000c */
                    154:        }
                    155:        else
                    156:        {
                    157:                //fprintf ( stderr ," Cart_ResetImage no patch\n" );
                    158:                /* No built-in cartridge loaded : set same handler as 0x4afc (illegal) */
                    159:                cpufunctbl[GEMDOS_OPCODE] = cpufunctbl[ 0x4afc ];       /* 0x0008 */
                    160:                cpufunctbl[SYSINIT_OPCODE] = cpufunctbl[ 0x4afc ];      /* 0x000a */
                    161:                cpufunctbl[VDI_OPCODE] = cpufunctbl[ 0x4afc ];          /* 0x000c */
                    162:        }
1.1.1.12  root      163: 
                    164:        /* although these don't need cartridge code, it's better
                    165:         * to configure all illegal opcodes in same place...
                    166:         */
                    167:        if (ConfigureParams.Log.bNatFeats)
                    168:        {
                    169:                /* illegal opcodes for emulators Native Features */
                    170:                cpufunctbl[NATFEAT_ID_OPCODE] = OpCode_NatFeat_ID;      /* 0x7300 */
                    171:                cpufunctbl[NATFEAT_CALL_OPCODE] = OpCode_NatFeat_Call;  /* 0x7301 */
                    172:        }
                    173:        else
                    174:        {
                    175:                /* No Native Features : set same handler as 0x4afc (illegal) */
                    176:                cpufunctbl[NATFEAT_ID_OPCODE] = cpufunctbl[ 0x4afc ];   /* 0x7300 */
                    177:                cpufunctbl[NATFEAT_CALL_OPCODE] = cpufunctbl[ 0x4afc ]; /* 0x7300 */
                    178:        }
1.1       root      179: }

unix.superglobalmegacorp.com

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