mem89.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /* Hey EMACS -*- linux-c -*- */
  2. /* $Id: mem89.c 2428 2007-04-04 17:05:38Z 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. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
  23. */
  24. /*
  25. Memory management: TI89 FLASH without Hardware Protection.
  26. Some values may be hard-coded for performance reasons !
  27. */
  28. #include <stdlib.h>
  29. #include <string.h>
  30. #include <stdio.h>
  31. #include "mem.h"
  32. #include "mem89.h"
  33. #include "ti68k_def.h"
  34. #include "mem_size.h"
  35. #include "main.h"
  36. // 000000-0fffff : RAM (256 KB)
  37. // 100000-1fffff :
  38. // 200000-2fffff : internal FLASH (2 MB)
  39. // 300000-3fffff :
  40. // 400000-4fffff :
  41. // 500000-5fffff :
  42. // 600000-6fffff : memory mapped I/O (all HW)
  43. // 700000-7fffff : memory mapped I/O (HW2, HW3)
  44. // 800000-8fffff : unused
  45. // 900000-9fffff : ...
  46. // a00000-afffff :
  47. // b00000-bfffff :
  48. // c00000-cfffff :
  49. // d00000-dfffff :
  50. // e00000-efffff : ...
  51. // d00000-ffffff : unused
  52. int ti89_mem_init(void)
  53. {
  54. // set mappers
  55. mem_get_byte_ptr = ti89_get_byte;
  56. mem_get_word_ptr = ti89_get_word;
  57. mem_get_long_ptr = ti89_get_long;
  58. mem_get_real_addr_ptr = ti89_get_real_addr;
  59. return 0;
  60. }
  61. uint8_t* ti89_get_real_addr(uint32_t adr)
  62. {
  63. // RAM access
  64. if(IN_BOUNDS(0x000000, adr, 0x1fffff))
  65. {
  66. return get_p(ram, adr, RAM_SIZE_TI89 - 1);
  67. }
  68. // FLASH access
  69. else if(IN_BOUNDS(0x200000, adr, 0x5fffff))
  70. {
  71. return get_p(rom, adr, ROM_SIZE_TI89 - 1);
  72. }
  73. return unused;
  74. }
  75. uint32_t ti89_get_long(uint32_t adr)
  76. {
  77. // RAM access
  78. if(IN_BOUNDS(0x000000, adr, 0x1fffff))
  79. {
  80. return get_l(ram, adr, RAM_SIZE_TI89 - 1);
  81. }
  82. // FLASH access
  83. else if(IN_BOUNDS(0x200000, adr, 0x5fffff))
  84. {
  85. return get_l(rom, adr, ROM_SIZE_TI89 - 1);
  86. }
  87. return 0x14141414;
  88. }
  89. uint16_t ti89_get_word(uint32_t adr)
  90. {
  91. // RAM access
  92. if(IN_BOUNDS(0x000000, adr, 0x1fffff))
  93. {
  94. return get_w(ram, adr, RAM_SIZE_TI89 - 1);
  95. }
  96. // FLASH access
  97. else if(IN_BOUNDS(0x200000, adr, 0x5fffff))
  98. {
  99. return get_w(rom, adr, ROM_SIZE_TI89 - 1);
  100. }
  101. return 0x1414;
  102. }
  103. uint8_t ti89_get_byte(uint32_t adr)
  104. {
  105. // RAM access
  106. if(IN_BOUNDS(0x000000, adr, 0x1fffff))
  107. {
  108. return get_b(ram, adr, RAM_SIZE_TI89 - 1);
  109. }
  110. // FLASH access
  111. else if(IN_BOUNDS(0x200000, adr, 0x5fffff))
  112. {
  113. return get_b(rom, adr, ROM_SIZE_TI89 - 1);
  114. }
  115. return 0x14;
  116. }