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

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.6 ! root        9: const char STMemory_rcsid[] = "Hatari $Id: stMemory.c,v 1.9 2006/02/21 14:15:35 thothy Exp $";
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"
        !            14: #include "ioMem.h"
        !            15: #include "tos.h"
        !            16: #include "vdi.h"
        !            17: #include "uae-cpu/memory.h"
1.1.1.2   root       18: 
1.1.1.4   root       19: 
                     20: Uint8 STRam[16*1024*1024];      /* This is our ST Ram, includes all TOS/hardware areas for ease */
                     21: Uint32 STRamEnd;                /* End of ST Ram, above this address is no-mans-land and hardware vectors */
1.1       root       22: 
1.1.1.2   root       23: 
                     24: /*-----------------------------------------------------------------------*/
1.1       root       25: /*
1.1.1.3   root       26:   Clear section of ST's memory space.
1.1       root       27: */
1.1.1.5   root       28: void STMemory_Clear(Uint32 StartAddress, Uint32 EndAddress)
1.1       root       29: {
1.1.1.5   root       30:        memset(&STRam[StartAddress], 0, EndAddress-StartAddress);
1.1       root       31: }
                     32: 
1.1.1.6 ! root       33: 
        !            34: /*-----------------------------------------------------------------------*/
        !            35: /*
        !            36:   Set default memory configuration, connected floppies, memory size and
        !            37:   clear the ST-RAM area.
        !            38:   As TOS checks hardware for memory size + connected devices on boot-up
        !            39:   we set these values ourselves and fill in the magic numbers so TOS
        !            40:   skips these tests.
        !            41: */
        !            42: void STMemory_SetDefaultConfig(void)
        !            43: {
        !            44:        int i;
        !            45:        Uint8 nMemControllerByte;
        !            46:        static const int MemControllerTable[] =
        !            47:        {
        !            48:                0x01,   /* 512 KiB */
        !            49:                0x05,   /* 1 MiB */
        !            50:                0x02,   /* 2 MiB */
        !            51:                0x06,   /* 2.5 MiB */
        !            52:                0x0A    /* 4 MiB */
        !            53:        };
        !            54: 
        !            55:        /* Calculate end of RAM */
        !            56:        if (ConfigureParams.Memory.nMemorySize > 0 && ConfigureParams.Memory.nMemorySize <= 14)
        !            57:                STRamEnd = ConfigureParams.Memory.nMemorySize * 0x100000;
        !            58:        else
        !            59:                STRamEnd = 0x80000;   /* 512 KiB */
        !            60: 
        !            61:        /* Clear ST-RAM */
        !            62:        STMemory_Clear(0x00000000, STRamEnd);
        !            63: 
        !            64:        /* Mirror ROM boot vectors */
        !            65:        STMemory_WriteLong(0x00, STMemory_ReadLong(TosAddress));
        !            66:        STMemory_WriteLong(0x04, STMemory_ReadLong(TosAddress+4));
        !            67: 
        !            68:        /* Fill in magic numbers, so TOS does not try to reference MMU */
        !            69:        STMemory_WriteLong(0x420, 0x752019f3);            /* memvalid - configuration is valid */
        !            70:        STMemory_WriteLong(0x43a, 0x237698aa);            /* another magic # */
        !            71:        STMemory_WriteLong(0x51a, 0x5555aaaa);            /* and another */
        !            72: 
        !            73:        /* Set memory size, adjust for extra VDI screens if needed */
        !            74:        if (bUseVDIRes)
        !            75:        {
        !            76:                /* This is enough for 1024x768x16colors (0x60000) */
        !            77:                STMemory_WriteLong(0x436, STRamEnd-0x60000);  /* mem top - upper end of user memory (before 32k screen) */
        !            78:                STMemory_WriteLong(0x42e, STRamEnd-0x58000);  /* phys top */
        !            79:        }
        !            80:        else
        !            81:        {
        !            82:                STMemory_WriteLong(0x436, STRamEnd-0x8000);   /* mem top - upper end of user memory (before 32k screen) */
        !            83:                STMemory_WriteLong(0x42e, STRamEnd);          /* phys top */
        !            84:        }
        !            85: 
        !            86:        /* Set memory controller byte according to different memory sizes */
        !            87:        /* Setting per bank: %00=128k %01=512k %10=2Mb %11=reserved. - e.g. %1010 means 4Mb */
        !            88:        if (ConfigureParams.Memory.nMemorySize <= 4)
        !            89:                nMemControllerByte = MemControllerTable[ConfigureParams.Memory.nMemorySize];
        !            90:        else
        !            91:                nMemControllerByte = 0x0f;
        !            92:        STMemory_WriteByte(0x424, nMemControllerByte);
        !            93:        IoMem_WriteByte(0xff8001, nMemControllerByte);
        !            94: 
        !            95:        /* Set TOS floppies */
        !            96:        STMemory_WriteWord(0x446, nBootDrive);          /* Boot up on A(0) or C(2) */
        !            97: 
        !            98:        /* Create connected drives mask: */
        !            99:        ConnectedDriveMask = 0;
        !           100:        for (i = 0; i < nNumDrives; i++)
        !           101:        {
        !           102:                ConnectedDriveMask |= (1 << i);
        !           103:        }
        !           104:        /* Set connected drives system variable.
        !           105:         * NOTE: some TOS images overwrite this value, see 'OpCode_SysInit', too */
        !           106:        STMemory_WriteLong(0x4c2, ConnectedDriveMask);
        !           107: 
        !           108:        /* Initialize the memory banks: */
        !           109:        memory_uninit();
        !           110:        memory_init(STRamEnd, 0, TosAddress);
        !           111: }

unix.superglobalmegacorp.com

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