fork of PCE focusing on macplus, supporting DaynaPort SCSI network emulation
at master 219 lines 4.8 kB view raw
1/***************************************************************************** 2 * pce * 3 *****************************************************************************/ 4 5/***************************************************************************** 6 * File name: src/arch/macplus/mem.c * 7 * Created: 2007-11-13 by Hampa Hug <hampa@hampa.ch> * 8 * Copyright: (C) 2007-2011 Hampa Hug <hampa@hampa.ch> * 9 *****************************************************************************/ 10 11/***************************************************************************** 12 * This program is free software. You can redistribute it and / or modify it * 13 * under the terms of the GNU General Public License version 2 as published * 14 * by the Free Software Foundation. * 15 * * 16 * This program is distributed in the hope that it will be useful, but * 17 * WITHOUT ANY WARRANTY, without even the implied warranty of * 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * 19 * Public License for more details. * 20 *****************************************************************************/ 21 22 23#include "main.h" 24#include "macplus.h" 25#include "mem.h" 26 27 28void mac_set_overlay (macplus_t *sim, int overlay) 29{ 30 if (sim->overlay == (overlay != 0)) { 31 return; 32 } 33 34#ifdef DEBUG_MEM 35 mac_log_deb ("mem: overlay = %d\n", overlay); 36#endif 37 38 if (overlay) { 39 mem_rmv_blk (sim->mem, sim->ram); 40 mem_add_blk (sim->mem, sim->rom_ovl, 0); 41 mem_add_blk (sim->mem, sim->ram_ovl, 0); 42 43 e68_set_ram (sim->cpu, NULL, 0); 44 45 sim->overlay = 1; 46 } 47 else { 48 mem_rmv_blk (sim->mem, sim->rom_ovl); 49 mem_rmv_blk (sim->mem, sim->ram_ovl); 50 mem_add_blk (sim->mem, sim->ram, 0); 51 52 e68_set_ram (sim->cpu, 53 mem_blk_get_data (sim->ram), 54 mem_blk_get_size (sim->ram) 55 ); 56 57 sim->overlay = 0; 58 } 59} 60 61 62static 63int mac_addr_map (macplus_t *sim, unsigned long *addr) 64{ 65 unsigned long val; 66 67 /* repeated RAM images */ 68 if (*addr < 0x400000) { 69 if (sim->ram == NULL) { 70 return (0); 71 } 72 73 val = mem_blk_get_size (sim->ram); 74 75 if (val == 0) { 76 return (0); 77 } 78 79 val = *addr % val; 80 81 if (*addr == val) { 82 return (0); 83 } 84 85 *addr = val; 86 87 return (1); 88 } 89 90 /* repeated ROM images */ 91 if ((*addr >= 0x400000) && (*addr < 0x580000)) { 92 if (sim->rom == NULL) { 93 return (0); 94 } 95 96 val = mem_blk_get_size (sim->rom); 97 98 if (val == 0) { 99 return (0); 100 } 101 102 val = 0x400000 + (*addr % val); 103 104 if (*addr == val) { 105 return (0); 106 } 107 108 *addr = val; 109 110 return (1); 111 } 112 113 return (0); 114} 115 116unsigned char mac_mem_get_uint8 (void *ext, unsigned long addr) 117{ 118 macplus_t *sim = ext; 119 120 if (mac_addr_map (sim, &addr)) { 121 return (mem_get_uint8 (sim->mem, addr)); 122 } 123 124 if ((addr >= 0x580000) && (addr < 0x600000)) { 125 return (0x00); 126 } 127 128 if ((addr >= 0xc00000) && (addr < 0xe00000)) { 129 return (mac_iwm_get_uint8 (&sim->iwm, addr - 0xc00000)); 130 } 131 132 if ((addr & 0xf00000) == 0xd00000) { 133 return (0xaa); 134 } 135 136#ifdef DEBUG_MEM 137 mac_log_deb ("mem: get 8: %06lX -> 00\n", addr); 138#endif 139 140 return (0); 141} 142 143unsigned short mac_mem_get_uint16 (void *ext, unsigned long addr) 144{ 145 macplus_t *sim = ext; 146 147 if (mac_addr_map (sim, &addr)) { 148 return (mem_get_uint16_be (sim->mem, addr)); 149 } 150 151#ifdef DEBUG_MEM 152 mac_log_deb ("mem: get 16: %06lX -> 0000\n", addr); 153#endif 154 155 return (0); 156} 157 158unsigned long mac_mem_get_uint32 (void *ext, unsigned long addr) 159{ 160 macplus_t *sim = ext; 161 162 if (mac_addr_map (sim, &addr)) { 163 return (mem_get_uint32_be (sim->mem, addr)); 164 } 165 166#ifdef DEBUG_MEM 167 mac_log_deb ("mem: get 32: %06lX -> 00000000\n", addr); 168#endif 169 170 return (0); 171} 172 173void mac_mem_set_uint8 (void *ext, unsigned long addr, unsigned char val) 174{ 175 macplus_t *sim = ext; 176 177 if (mac_addr_map (sim, &addr)) { 178 mem_set_uint8 (sim->mem, addr, val); 179 } 180 181 if ((addr >= 0x580000) && (addr < 0x600000)) { 182 return; 183 } 184 185 if ((addr >= 0xc00000) && (addr < 0xe00000)) { 186 mac_iwm_set_uint8 (&sim->iwm, addr - 0xc00000, val); 187 return; 188 } 189 190#ifdef DEBUG_MEM 191 mac_log_deb ("mem: set 8: %06lX <- %02X\n", addr, val); 192#endif 193} 194 195void mac_mem_set_uint16 (void *ext, unsigned long addr, unsigned short val) 196{ 197 macplus_t *sim = ext; 198 199 if (mac_addr_map (sim, &addr)) { 200 mem_set_uint16_be (sim->mem, addr, val); 201 } 202 203#ifdef DEBUG_MEM 204 mac_log_deb ("mem: set 16: %06lX <- %02X\n", addr, val); 205#endif 206} 207 208void mac_mem_set_uint32 (void *ext, unsigned long addr, unsigned long val) 209{ 210 macplus_t *sim = ext; 211 212 if (mac_addr_map (sim, &addr)) { 213 mem_set_uint32_be (sim->mem, addr, val); 214 } 215 216#ifdef DEBUG_MEM 217 mac_log_deb ("mem: set 32: %06lX <- %02lX\n", addr, val); 218#endif 219}