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

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

unix.superglobalmegacorp.com

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