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