|
|
1.1 root 1: /*
1.1.1.3 root 2: Hatari - stMemory.c
1.1 root 3:
1.1.1.3 root 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.
6:
1.1.1.4 root 7: ST Memory access functions.
1.1 root 8: */
1.1.1.9 ! root 9: const char STMemory_rcsid[] = "Hatari $Id: stMemory.c,v 1.20 2008-03-31 17:28:51 eerot Exp $";
1.1.1.7 root 10:
11: #include "config.h"
1.1 root 12:
1.1.1.4 root 13: #include "stMemory.h"
1.1.1.6 root 14: #include "configuration.h"
15: #include "floppy.h"
16: #include "ioMem.h"
17: #include "tos.h"
18: #include "vdi.h"
1.1.1.7 root 19: #include "memory.h"
20:
1.1.1.2 root 21:
1.1.1.7 root 22: /* STRam points to our ST Ram. Unless the user enabled SMALL_MEM where we have
23: * to save memory, this includes all TOS ROM and IO hardware areas for ease
24: * and emulation speed - so we create a 16 MiB array directly here.
25: * But when the user turned on ENABLE_SMALL_MEM, this only points to a malloc'ed
26: * buffer with the ST RAM; the ROM and IO memory will be handled separately. */
27: #if ENABLE_SMALL_MEM
28: Uint8 *STRam;
29: #else
30: Uint8 STRam[16*1024*1024];
31: #endif
1.1.1.4 root 32:
1.1.1.7 root 33: Uint32 STRamEnd; /* End of ST Ram, above this address is no-mans-land and ROM/IO memory */
1.1 root 34:
1.1.1.2 root 35:
36: /*-----------------------------------------------------------------------*/
1.1.1.7 root 37: /**
38: * Clear section of ST's memory space.
39: */
1.1.1.5 root 40: void STMemory_Clear(Uint32 StartAddress, Uint32 EndAddress)
1.1 root 41: {
1.1.1.5 root 42: memset(&STRam[StartAddress], 0, EndAddress-StartAddress);
1.1 root 43: }
44:
1.1.1.6 root 45:
46: /*-----------------------------------------------------------------------*/
1.1.1.7 root 47: /**
48: * Set default memory configuration, connected floppies, memory size and
49: * clear the ST-RAM area.
50: * As TOS checks hardware for memory size + connected devices on boot-up
51: * we set these values ourselves and fill in the magic numbers so TOS
52: * skips these tests.
53: */
1.1.1.6 root 54: void STMemory_SetDefaultConfig(void)
55: {
56: int i;
1.1.1.7 root 57: int screensize;
58: int memtop;
1.1.1.6 root 59: Uint8 nMemControllerByte;
60: static const int MemControllerTable[] =
61: {
62: 0x01, /* 512 KiB */
63: 0x05, /* 1 MiB */
64: 0x02, /* 2 MiB */
65: 0x06, /* 2.5 MiB */
66: 0x0A /* 4 MiB */
67: };
68:
1.1.1.7 root 69: if (bRamTosImage)
70: {
71: /* Clear ST-RAM, excluding the RAM TOS image */
72: STMemory_Clear(0x00000000, TosAddress);
73: STMemory_Clear(TosAddress+TosSize, STRamEnd);
74: }
1.1.1.6 root 75: else
1.1.1.7 root 76: {
77: /* Clear whole ST-RAM */
78: STMemory_Clear(0x00000000, STRamEnd);
79: }
1.1.1.6 root 80:
81: /* Mirror ROM boot vectors */
82: STMemory_WriteLong(0x00, STMemory_ReadLong(TosAddress));
83: STMemory_WriteLong(0x04, STMemory_ReadLong(TosAddress+4));
84:
85: /* Fill in magic numbers, so TOS does not try to reference MMU */
86: STMemory_WriteLong(0x420, 0x752019f3); /* memvalid - configuration is valid */
87: STMemory_WriteLong(0x43a, 0x237698aa); /* another magic # */
88: STMemory_WriteLong(0x51a, 0x5555aaaa); /* and another */
89:
1.1.1.7 root 90: /* Set memory size, adjust for extra VDI screens if needed.
91: * Note: TOS seems to set phys_top-0x8000 as the screen base
92: * address - so we have to move phys_top down in VDI resolution
93: * mode, although there is more "physical" ST RAM available. */
94: screensize = VDIWidth * VDIHeight / 8 * VDIPlanes;
95: /* Use 32 kiB in normal screen mode or when the screen size is smaller than 32 kiB */
96: if (!bUseVDIRes || screensize < 0x8000)
97: screensize = 0x8000;
98: /* mem top - upper end of user memory (right before the screen memory).
99: * Note: memtop / phystop must be dividable by 512, or TOS crashes */
100: memtop = (STRamEnd - screensize) & 0xfffffe00;
101: STMemory_WriteLong(0x436, memtop);
102: /* phys top - This must be memtop + 0x8000 to make TOS happy */
103: STMemory_WriteLong(0x42e, memtop+0x8000);
1.1.1.6 root 104:
105: /* Set memory controller byte according to different memory sizes */
106: /* Setting per bank: %00=128k %01=512k %10=2Mb %11=reserved. - e.g. %1010 means 4Mb */
107: if (ConfigureParams.Memory.nMemorySize <= 4)
108: nMemControllerByte = MemControllerTable[ConfigureParams.Memory.nMemorySize];
109: else
110: nMemControllerByte = 0x0f;
111: STMemory_WriteByte(0x424, nMemControllerByte);
112: IoMem_WriteByte(0xff8001, nMemControllerByte);
113:
1.1.1.7 root 114: /* Set the Falcon memory (and monitor) configuration register: */
115: if (ConfigureParams.System.nMachineType == MACHINE_FALCON)
116: {
117: Uint8 nFalcSysCntrl;
118: /* TODO: How does the 0xff8006 register work exactly on the Falcon?
119: * The following values are just guessed... */
120: if (ConfigureParams.Memory.nMemorySize == 14)
121: nFalcSysCntrl= 0x26;
122: else if (ConfigureParams.Memory.nMemorySize >= 4)
123: nFalcSysCntrl = 0x16;
124: else if (ConfigureParams.Memory.nMemorySize >= 2)
125: nFalcSysCntrl = 0x14;
126: else if (ConfigureParams.Memory.nMemorySize == 1)
127: nFalcSysCntrl = 0x06;
128: else
129: nFalcSysCntrl = 0x04;
130: nFalcSysCntrl &= FALCON_MONITOR_MASK;
1.1.1.8 root 131: switch(ConfigureParams.Screen.nMonitorType) {
1.1.1.7 root 132: case MONITOR_TYPE_TV:
133: nFalcSysCntrl |= FALCON_MONITOR_TV;
134: break;
135: case MONITOR_TYPE_VGA:
136: nFalcSysCntrl |= FALCON_MONITOR_VGA;
137: break;
138: case MONITOR_TYPE_RGB:
139: nFalcSysCntrl |= FALCON_MONITOR_RGB;
140: break;
141: case MONITOR_TYPE_MONO:
142: nFalcSysCntrl |= FALCON_MONITOR_MONO;
143: break;
144: }
145: STMemory_WriteByte(0xff8006, nFalcSysCntrl);
146: }
147:
1.1.1.6 root 148: /* Set TOS floppies */
149: STMemory_WriteWord(0x446, nBootDrive); /* Boot up on A(0) or C(2) */
150:
151: /* Create connected drives mask: */
152: ConnectedDriveMask = 0;
153: for (i = 0; i < nNumDrives; i++)
154: {
155: ConnectedDriveMask |= (1 << i);
156: }
157: /* Set connected drives system variable.
158: * NOTE: some TOS images overwrite this value, see 'OpCode_SysInit', too */
159: STMemory_WriteLong(0x4c2, ConnectedDriveMask);
160: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.