Annotation of hatari/src/stMemory.c, revision 1.1.1.12

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

unix.superglobalmegacorp.com

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