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

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. */
1.1.1.15! root      122:        PatchIllegal = false;                           /* By default, don't patch opcodes */
1.1.1.13  root      123:        if ((bUseVDIRes || ConfigureParams.HardDisk.bUseHardDiskDirectories ||
1.1.1.14  root      124:            LogTraceFlags & (TRACE_OS_GEMDOS | TRACE_OS_BASE | TRACE_OS_VDI | TRACE_OS_AES))
1.1.1.12  root      125:            && TosVersion >= 0x100)
1.1.1.4   root      126:        {
1.1.1.12  root      127:                /* Copy built-in cartridge data into the cartridge memory of the ST */
1.1.1.9   root      128:                memcpy(&RomMem[0xfa0000], Cart_data, sizeof(Cart_data));
1.1.1.11  root      129:                PatchIllegal = true;
1.1.1.4   root      130:        }
1.1.1.7   root      131:        else if (strlen(ConfigureParams.Rom.szCartridgeImageFileName) > 0)
1.1.1.4   root      132:        {
1.1.1.7   root      133:                /* Load external image file: */
                    134:                Cart_LoadImage();
1.1.1.4   root      135:        }
1.1.1.14  root      136: }
                    137: 
1.1.1.8   root      138: 
1.1.1.14  root      139: /*-----------------------------------------------------------------------*/
                    140: /**
                    141:  * Patch the cpu tables to intercept some opcodes used for Gemdos HD
                    142:  * emulation or for NatFeats.
                    143:  * We need to split this from Cart_ResetImage(), as the patches should
                    144:  * be applied after building the cpu opcodes tables.
                    145:  */
                    146: void Cart_Patch(void)
                    147: {
1.1.1.11  root      148:        if (PatchIllegal == true)
1.1.1.8   root      149:        {
                    150:                //fprintf ( stderr ," Cart_ResetImage patch\n" );
                    151:                /* Hatari's specific illegal opcodes for HD emulation */
                    152:                cpufunctbl[GEMDOS_OPCODE] = OpCode_GemDos;      /* 0x0008 */
                    153:                cpufunctbl[SYSINIT_OPCODE] = OpCode_SysInit;    /* 0x000a */
                    154:                cpufunctbl[VDI_OPCODE] = OpCode_VDI;            /* 0x000c */
                    155:        }
                    156:        else
                    157:        {
                    158:                //fprintf ( stderr ," Cart_ResetImage no patch\n" );
                    159:                /* No built-in cartridge loaded : set same handler as 0x4afc (illegal) */
                    160:                cpufunctbl[GEMDOS_OPCODE] = cpufunctbl[ 0x4afc ];       /* 0x0008 */
                    161:                cpufunctbl[SYSINIT_OPCODE] = cpufunctbl[ 0x4afc ];      /* 0x000a */
                    162:                cpufunctbl[VDI_OPCODE] = cpufunctbl[ 0x4afc ];          /* 0x000c */
                    163:        }
1.1.1.12  root      164: 
                    165:        /* although these don't need cartridge code, it's better
                    166:         * to configure all illegal opcodes in same place...
                    167:         */
                    168:        if (ConfigureParams.Log.bNatFeats)
                    169:        {
                    170:                /* illegal opcodes for emulators Native Features */
                    171:                cpufunctbl[NATFEAT_ID_OPCODE] = OpCode_NatFeat_ID;      /* 0x7300 */
                    172:                cpufunctbl[NATFEAT_CALL_OPCODE] = OpCode_NatFeat_Call;  /* 0x7301 */
                    173:        }
                    174:        else
                    175:        {
                    176:                /* No Native Features : set same handler as 0x4afc (illegal) */
                    177:                cpufunctbl[NATFEAT_ID_OPCODE] = cpufunctbl[ 0x4afc ];   /* 0x7300 */
                    178:                cpufunctbl[NATFEAT_CALL_OPCODE] = cpufunctbl[ 0x4afc ]; /* 0x7300 */
                    179:        }
1.1       root      180: }

unix.superglobalmegacorp.com

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