mem.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* Hey EMACS -*- linux-c -*- */
  2. /* $Id: main.c 245 2004-05-23 20:45:43Z roms $ */
  3. /* TiEmu - Tiemu Is an EMUlator
  4. *
  5. * Copyright (c) 2000-2001, Thomas Corvazier, Romain Liévin
  6. * Copyright (c) 2001-2003, Romain Liévin
  7. * Copyright (c) 2003, Julien Blache
  8. * Copyright (c) 2004, Romain Liévin
  9. * Copyright (c) 2005, Romain Liévin, Kevin Kofler
  10. * Copyright (c) 2007, 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. #ifndef __TI68K_MEMORY__
  27. #define __TI68K_MEMORY__
  28. #include "stdint.h"
  29. /* Typedefs */
  30. typedef uint8_t (*GETBYTE_FUNC) (uint32_t);
  31. typedef uint16_t (*GETWORD_FUNC) (uint32_t);
  32. typedef uint32_t (*GETLONG_FUNC) (uint32_t);
  33. typedef uint8_t* (*REALADR_FUNC) (uint32_t addr);
  34. extern GETBYTE_FUNC mem_get_byte_ptr;
  35. extern GETWORD_FUNC mem_get_word_ptr;
  36. extern GETLONG_FUNC mem_get_long_ptr;
  37. extern REALADR_FUNC mem_get_real_addr_ptr;
  38. /* Functions */
  39. int hw_mem_init(void);
  40. // defs similar to UAE's memory.h (interface)
  41. extern uint8_t hw_get_byte_noexcept(uint32_t addr);
  42. extern uint8_t hw_get_byte(uint32_t addr);
  43. extern uint16_t hw_get_word(uint32_t addr);
  44. extern uint32_t hw_get_long(uint32_t addr);
  45. extern uint8_t* hw_get_real_address(uint32_t addr);
  46. /* Useful macros for memory access */
  47. #define IN_BOUNDS(a,v,b) (((v) >= (a)) && ((v) <= (b)))
  48. #define IN_RANGE(v,b,r) (((v) >= (b)) && ((v) <= ((b) + ((r)-1))))
  49. #define get_b(ptr,adr,mask) (ptr[(adr) & (mask)])
  50. #define get_w(ptr,adr,mask) ((uint16_t) ((get_b(ptr,adr,mask) << 8) | get_b(ptr,(adr)+1,mask)))
  51. #define get_l(ptr,adr,mask) ((uint32_t) ((get_w(ptr,adr,mask) << 16) | get_w(ptr,(adr)+2,mask)))
  52. #define get_p(ptr,adr,mask) ((ptr) + ((adr) & (mask)))
  53. #endif