1 /* Hey EMACS -*- linux-c -*- */ 2 /* $Id: main.c 245 2004-05-23 20:45:43Z roms $ */ 3 4 /* TiEmu - Tiemu Is an EMUlator 5 * 6 * Copyright (c) 2000-2001, Thomas Corvazier, Romain Lievin 7 * Copyright (c) 2001-2003, Romain Lievin 8 * Copyright (c) 2003, Julien Blache 9 * Copyright (c) 2004, Romain Li�vin 10 * Copyright (c) 2005, Romain Li�vin, Kevin Kofler 11 * 12 * This program is free software; you can redistribute it and/or modify 13 * it under the terms of the GNU General Public License as published by 14 * the Free Software Foundation; either version 2 of the License, or 15 * (at your option) any later version. 16 * 17 * This program is distributed in the hope that it will be useful, 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 * GNU General Public License for more details. 21 * 22 * You should have received a copy of the GNU General Public License 23 * along with this program; if not, write to the Free Software 24 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. 25 */ 26 27 #ifndef __TI68K_MEMORY__ 28 #define __TI68K_MEMORY__ 29 30 #include "stdint.h" 31 32 /* Typedefs */ 33 34 typedef uint8_t (*GETBYTE_FUNC) (uint32_t); 35 typedef uint16_t (*GETWORD_FUNC) (uint32_t); 36 typedef uint32_t (*GETLONG_FUNC) (uint32_t); 37 38 typedef void (*PUTBYTE_FUNC) (uint32_t, uint8_t ); 39 typedef void (*PUTWORD_FUNC) (uint32_t, uint16_t); 40 typedef void (*PUTLONG_FUNC) (uint32_t, uint32_t); 41 42 typedef uint8_t* (*REALADR_FUNC) (uint32_t addr); 43 44 extern GETBYTE_FUNC mem_get_byte_ptr; 45 extern GETWORD_FUNC mem_get_word_ptr; 46 extern GETLONG_FUNC mem_get_long_ptr; 47 48 extern PUTBYTE_FUNC mem_put_byte_ptr; 49 extern PUTWORD_FUNC mem_put_word_ptr; 50 extern PUTLONG_FUNC mem_put_long_ptr; 51 52 extern REALADR_FUNC mem_get_real_addr_ptr; 53 54 /* Functions */ 55 56 int hw_mem_init(void); 57 int hw_mem_reset(void); 58 int hw_mem_exit(void); 59 60 // defs similar to UAE's memory.h (interface) 61 extern uint8_t hw_get_byte_noexcept(uint32_t addr); 62 extern uint8_t hw_get_byte(uint32_t addr); 63 extern uint16_t hw_get_word(uint32_t addr); 64 extern uint32_t hw_get_long(uint32_t addr); 65 66 extern void hw_put_byte_noexcept(uint32_t addr, uint8_t arg); 67 extern void hw_put_byte(uint32_t addr, uint8_t arg); 68 extern void hw_put_word(uint32_t addr, uint16_t arg); 69 extern void hw_put_long(uint32_t addr, uint32_t arg); 70 71 extern uint8_t* hw_get_real_address(uint32_t addr); 72 73 /* Useful macros for memory access */ 74 75 #define IN_BOUNDS(a,v,b) (((v) >= (a)) && ((v) <= (b))) 76 #define IN_RANGE(v,b,r) (((v) >= (b)) && ((v) <= ((b) + ((r)-1)))) 77 78 #define put_b(ptr,adr,mask,arg) { ptr[(adr) & (mask)] = (arg); } 79 #define put_w(ptr,adr,mask,arg) { put_b(ptr,adr,mask,(uint8_t )((arg) >> 8)); put_b(ptr,(adr)+1,mask,(uint8_t )((arg) & 0x00ff)); } 80 #define put_l(ptr,adr,mask,arg) { put_w(ptr,adr,mask,(uint16_t)((arg) >> 16)); put_w(ptr,(adr)+2,mask,(uint16_t)((arg) & 0xffff)); } 81 82 #define get_b(ptr,adr,mask) (ptr[(adr) & (mask)]) 83 #define get_w(ptr,adr,mask) ((uint16_t) ((get_b(ptr,adr,mask) << 8) | get_b(ptr,(adr)+1,mask))) 84 #define get_l(ptr,adr,mask) ((uint32_t) ((get_w(ptr,adr,mask) << 16) | get_w(ptr,(adr)+2,mask))) 85 86 #define get_p(ptr,adr,mask) ((ptr) + ((adr) & (mask))) 87 88 #endif 89