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

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.7 ! root       17: const char Cart_rcsid[] = "Hatari $Id: cart.c,v 1.14 2006/03/02 09:17:16 thothy Exp $";
1.1       root       18: 
                     19: #include "main.h"
                     20: #include "cart.h"
1.1.1.4   root       21: #include "configuration.h"
                     22: #include "file.h"
1.1.1.7 ! root       23: #include "log.h"
1.1       root       24: #include "stMemory.h"
1.1.1.4   root       25: #include "vdi.h"
1.1       root       26: 
1.1.1.5   root       27: #include "cartData.c"
1.1       root       28: 
                     29: 
1.1.1.7 ! root       30: /* Possible cartridge file extensions to scan for */
        !            31: static const char * const psCartNameExts[] =
        !            32: {
        !            33:        ".img",
        !            34:        ".rom",
        !            35:        ".stc",
        !            36:        NULL
        !            37: };
        !            38: 
        !            39: 
1.1       root       40: /*-----------------------------------------------------------------------*/
                     41: /*
1.1.1.7 ! root       42:   Load an external cartridge image file.
1.1       root       43: */
1.1.1.7 ! root       44: static void Cart_LoadImage(void)
1.1       root       45: {
1.1.1.7 ! root       46:        Uint8 *pCartData;
        !            47:        long nCartSize;
1.1.1.4   root       48:        char *pCartFileName = ConfigureParams.Rom.szCartridgeImageFileName;
                     49: 
1.1.1.7 ! root       50:        /* Try to load the image file: */
        !            51:        pCartData = File_Read(pCartFileName, NULL, &nCartSize, psCartNameExts);
        !            52:        if (!pCartData)
        !            53:        {
        !            54:                Log_Printf(LOG_ERROR, "Failed to load '%s'.\n", pCartFileName);
        !            55:                return;
        !            56:        }
        !            57: 
        !            58:        if (nCartSize < 40 || (nCartSize > 0x20000 && nCartSize != 0x20004))
        !            59:        {
        !            60:                Log_Printf(LOG_ERROR, "Cartridge file '%s' has illegal size.\n", pCartFileName);
        !            61:                free(pCartData);
        !            62:                return;
        !            63:        }
        !            64: 
        !            65:        /* There are two type of cartridge images, normal 1:1 images which are
        !            66:         * always smaller than or equal to 0x20000 bytes, and the .STC images,
        !            67:         * which are always 0x20004 bytes (the first 4 bytes are a dummy header).
        !            68:         * So if size is 0x20004 bytes we have to skip the first 4 bytes */
        !            69:        if (nCartSize == 0x20004)
        !            70:        {
        !            71:                memcpy(&STRam[0xfa0000], pCartData+4, 0x20000);
        !            72:        }
        !            73:        else
        !            74:        {
        !            75:                memcpy(&STRam[0xfa0000], pCartData, nCartSize);
        !            76:        }
        !            77: 
        !            78:        free(pCartData);
        !            79: }
        !            80: 
        !            81: 
        !            82: /*-----------------------------------------------------------------------*/
        !            83: /*
        !            84:   Copy ST GEMDOS intercept program image into cartridge memory space
        !            85:   or load an external cartridge file.
        !            86:   The intercept program is part of Hatari and used as an interface to the host
        !            87:   file system through GemDOS. It is also needed for Line-A-Init when using
        !            88:   extended VDI resolutions.
        !            89: */
        !            90: void Cart_ResetImage(void)
        !            91: {
1.1.1.4   root       92:        /* "Clear" cartridge ROM space */
                     93:        memset(&STRam[0xfa0000], 0xff, 0x20000);
                     94: 
1.1.1.7 ! root       95:        /* Print a warning if user tries to use an external cartridge file
        !            96:         * together with GEMDOS HD emulation or extended VDI resolution: */
        !            97:        if (strlen(ConfigureParams.Rom.szCartridgeImageFileName) > 0)
        !            98:        {
        !            99:                if (bUseVDIRes)
        !           100:                        Log_Printf(LOG_WARN, "Cartridge can't be used together with extended VDI resolution!\n");
        !           101:                if (ConfigureParams.HardDisk.bUseHardDiskDirectories)
        !           102:                        Log_Printf(LOG_WARN, "Cartridge can't be used together with GEMDOS hard disk emulation!\n");
        !           103:        }
        !           104: 
        !           105:        /* Use internal cartridge when user wants extended VDI resolution or GEMDOS HD. */
1.1.1.6   root      106:        if (bUseVDIRes || ConfigureParams.HardDisk.bUseHardDiskDirectories)
1.1.1.4   root      107:        {
1.1.1.7 ! root      108:                /* Copy built-in cartrige data into the cartridge memory of the ST */
1.1.1.5   root      109:                memcpy(&STRam[0xfa0000], Cart_data, sizeof(Cart_data));
1.1.1.4   root      110:        }
1.1.1.7 ! root      111:        else if (strlen(ConfigureParams.Rom.szCartridgeImageFileName) > 0)
1.1.1.4   root      112:        {
1.1.1.7 ! root      113:                /* Load external image file: */
        !           114:                Cart_LoadImage();
1.1.1.4   root      115:        }
1.1       root      116: }

unix.superglobalmegacorp.com

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