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

1.1       root        1: /*
1.1.1.4   root        2:   Hatari - cart.c
                      3: 
                      4:   This file is distributed under the GNU Public License, version 2 or at
                      5:   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.4   root       31: #include "vdi.h"
1.1.1.8   root       32: #include "hatari-glue.h"
                     33: #include "newcpu.h"
1.1       root       34: 
1.1.1.5   root       35: #include "cartData.c"
1.1       root       36: 
                     37: 
1.1.1.7   root       38: /* Possible cartridge file extensions to scan for */
                     39: static const char * const psCartNameExts[] =
                     40: {
                     41:        ".img",
                     42:        ".rom",
                     43:        ".stc",
                     44:        NULL
                     45: };
                     46: 
                     47: 
1.1       root       48: /*-----------------------------------------------------------------------*/
1.1.1.8   root       49: /**
                     50:  * Load an external cartridge image file.
                     51:  */
1.1.1.7   root       52: static void Cart_LoadImage(void)
1.1       root       53: {
1.1.1.7   root       54:        Uint8 *pCartData;
                     55:        long nCartSize;
1.1.1.4   root       56:        char *pCartFileName = ConfigureParams.Rom.szCartridgeImageFileName;
                     57: 
1.1.1.7   root       58:        /* Try to load the image file: */
1.1.1.8   root       59:        pCartData = File_Read(pCartFileName, &nCartSize, psCartNameExts);
1.1.1.7   root       60:        if (!pCartData)
                     61:        {
                     62:                Log_Printf(LOG_ERROR, "Failed to load '%s'.\n", pCartFileName);
                     63:                return;
                     64:        }
                     65: 
                     66:        if (nCartSize < 40 || (nCartSize > 0x20000 && nCartSize != 0x20004))
                     67:        {
                     68:                Log_Printf(LOG_ERROR, "Cartridge file '%s' has illegal size.\n", pCartFileName);
                     69:                free(pCartData);
                     70:                return;
                     71:        }
                     72: 
                     73:        /* There are two type of cartridge images, normal 1:1 images which are
                     74:         * always smaller than or equal to 0x20000 bytes, and the .STC images,
                     75:         * which are always 0x20004 bytes (the first 4 bytes are a dummy header).
                     76:         * So if size is 0x20004 bytes we have to skip the first 4 bytes */
                     77:        if (nCartSize == 0x20004)
                     78:        {
1.1.1.8   root       79:                memcpy(&RomMem[0xfa0000], pCartData+4, 0x20000);
1.1.1.7   root       80:        }
                     81:        else
                     82:        {
1.1.1.8   root       83:                memcpy(&RomMem[0xfa0000], pCartData, nCartSize);
1.1.1.7   root       84:        }
                     85: 
                     86:        free(pCartData);
                     87: }
                     88: 
                     89: 
                     90: /*-----------------------------------------------------------------------*/
1.1.1.8   root       91: /**
                     92:  * Copy ST GEMDOS intercept program image into cartridge memory space
                     93:  * or load an external cartridge file.
                     94:  * The intercept program is part of Hatari and used as an interface to the host
                     95:  * file system through GemDOS. It is also needed for Line-A-Init when using
                     96:  * extended VDI resolutions.
                     97:  */
1.1.1.7   root       98: void Cart_ResetImage(void)
                     99: {
1.1.1.11! root      100:        int PatchIllegal = false;
1.1.1.8   root      101: 
1.1.1.4   root      102:        /* "Clear" cartridge ROM space */
1.1.1.8   root      103:        memset(&RomMem[0xfa0000], 0xff, 0x20000);
1.1.1.4   root      104: 
1.1.1.7   root      105:        /* Print a warning if user tries to use an external cartridge file
                    106:         * together with GEMDOS HD emulation or extended VDI resolution: */
                    107:        if (strlen(ConfigureParams.Rom.szCartridgeImageFileName) > 0)
                    108:        {
                    109:                if (bUseVDIRes)
                    110:                        Log_Printf(LOG_WARN, "Cartridge can't be used together with extended VDI resolution!\n");
                    111:                if (ConfigureParams.HardDisk.bUseHardDiskDirectories)
                    112:                        Log_Printf(LOG_WARN, "Cartridge can't be used together with GEMDOS hard disk emulation!\n");
                    113:        }
                    114: 
                    115:        /* Use internal cartridge when user wants extended VDI resolution or GEMDOS HD. */
1.1.1.6   root      116:        if (bUseVDIRes || ConfigureParams.HardDisk.bUseHardDiskDirectories)
1.1.1.4   root      117:        {
1.1.1.7   root      118:                /* Copy built-in cartrige data into the cartridge memory of the ST */
1.1.1.9   root      119:                memcpy(&RomMem[0xfa0000], Cart_data, sizeof(Cart_data));
1.1.1.11! root      120:                PatchIllegal = true;
1.1.1.4   root      121:        }
1.1.1.7   root      122:        else if (strlen(ConfigureParams.Rom.szCartridgeImageFileName) > 0)
1.1.1.4   root      123:        {
1.1.1.7   root      124:                /* Load external image file: */
                    125:                Cart_LoadImage();
1.1.1.4   root      126:        }
1.1.1.8   root      127: 
1.1.1.11! root      128:        if (PatchIllegal == true)
1.1.1.8   root      129:        {
                    130:                //fprintf ( stderr ," Cart_ResetImage patch\n" );
                    131:                /* Hatari's specific illegal opcodes for HD emulation */
                    132:                cpufunctbl[GEMDOS_OPCODE] = OpCode_GemDos;      /* 0x0008 */
                    133:                cpufunctbl[SYSINIT_OPCODE] = OpCode_SysInit;    /* 0x000a */
                    134:                cpufunctbl[VDI_OPCODE] = OpCode_VDI;            /* 0x000c */
                    135:        }
                    136:        else
                    137:        {
                    138:                //fprintf ( stderr ," Cart_ResetImage no patch\n" );
                    139:                /* No built-in cartridge loaded : set same handler as 0x4afc (illegal) */
                    140:                cpufunctbl[GEMDOS_OPCODE] = cpufunctbl[ 0x4afc ];       /* 0x0008 */
                    141:                cpufunctbl[SYSINIT_OPCODE] = cpufunctbl[ 0x4afc ];      /* 0x000a */
                    142:                cpufunctbl[VDI_OPCODE] = cpufunctbl[ 0x4afc ];          /* 0x000c */
                    143:        }
1.1       root      144: }

unix.superglobalmegacorp.com

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