memory.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * PicoDrive
  3. * (C) notaz, 2008
  4. *
  5. * This work is licensed under the terms of MAME license.
  6. * See COPYING file in the top-level directory.
  7. */
  8. #include "../pico_int.h"
  9. #include "../memory.h"
  10. #include "../sound/sn76496.h"
  11. /*
  12. void dump(u16 w)
  13. {
  14. static FILE *f[0x10] = { NULL, };
  15. char fname[32];
  16. int num = PicoPicohw.r12 & 0xf;
  17. w = (w << 8) | (w >> 8);
  18. sprintf(fname, "ldump%i.bin", num);
  19. if (f[num] == NULL)
  20. f[num] = fopen(fname, "wb");
  21. fwrite(&w, 1, 2, f[num]);
  22. //fclose(f);
  23. }
  24. */
  25. static u32 PicoRead8_pico(u32 a)
  26. {
  27. u32 d = 0;
  28. if ((a & 0xffffe0) == 0x800000) // Pico I/O
  29. {
  30. switch (a & 0x1f)
  31. {
  32. case 0x01: d = PicoPicohw.r1; break;
  33. case 0x03:
  34. d = PicoPad[0]&0x1f; // d-pad
  35. d |= (PicoPad[0]&0x20) << 2; // pen push -> C
  36. d = ~d;
  37. break;
  38. case 0x05: d = (PicoPicohw.pen_pos[0] >> 8); break; // what is MS bit for? Games read it..
  39. case 0x07: d = PicoPicohw.pen_pos[0] & 0xff; break;
  40. case 0x09: d = (PicoPicohw.pen_pos[1] >> 8); break;
  41. case 0x0b: d = PicoPicohw.pen_pos[1] & 0xff; break;
  42. case 0x0d: d = (1 << (PicoPicohw.page & 7)) - 1; break;
  43. case 0x12: d = PicoPicohw.fifo_bytes == 0 ? 0x80 : 0; break; // guess
  44. default:
  45. goto unhandled;
  46. }
  47. return d;
  48. }
  49. unhandled:
  50. elprintf(EL_UIO, "m68k unmapped r8 [%06x] @%06x", a, SekPc);
  51. return d;
  52. }
  53. static u32 PicoRead16_pico(u32 a)
  54. {
  55. u32 d = 0;
  56. if (a == 0x800010)
  57. d = (PicoPicohw.fifo_bytes > 0x3f) ? 0 : (0x3f - PicoPicohw.fifo_bytes);
  58. else if (a == 0x800012)
  59. d = PicoPicohw.fifo_bytes == 0 ? 0x8000 : 0; // guess
  60. else
  61. elprintf(EL_UIO, "m68k unmapped r16 [%06x] @%06x", a, SekPc);
  62. return d;
  63. }
  64. static void PicoWrite8_pico(u32 a, u32 d)
  65. {
  66. switch (a & ~0x800000) {
  67. case 0x19: case 0x1b: case 0x1d: case 0x1f: break; // 'S' 'E' 'G' 'A'
  68. default:
  69. elprintf(EL_UIO, "m68k unmapped w8 [%06x] %02x @%06x", a, d & 0xff, SekPc);
  70. break;
  71. }
  72. }
  73. static void PicoWrite16_pico(u32 a, u32 d)
  74. {
  75. //if (a == 0x800010) dump(d);
  76. if (a == 0x800010)
  77. {
  78. PicoPicohw.fifo_bytes += 2;
  79. if (PicoPicohw.xpcm_ptr < PicoPicohw.xpcm_buffer + XPCM_BUFFER_SIZE) {
  80. *PicoPicohw.xpcm_ptr++ = d >> 8;
  81. *PicoPicohw.xpcm_ptr++ = d;
  82. }
  83. else if (PicoPicohw.xpcm_ptr == PicoPicohw.xpcm_buffer + XPCM_BUFFER_SIZE) {
  84. elprintf(EL_ANOMALY|EL_PICOHW, "xpcm_buffer overflow!");
  85. PicoPicohw.xpcm_ptr++;
  86. }
  87. }
  88. else if (a == 0x800012) {
  89. int r12_old = PicoPicohw.r12;
  90. PicoPicohw.r12 = d;
  91. if (r12_old != d)
  92. PicoReratePico();
  93. }
  94. else
  95. elprintf(EL_UIO, "m68k unmapped w16 [%06x] %04x @%06x", a, d & 0xffff, SekPc);
  96. }
  97. PICO_INTERNAL void PicoMemSetupPico(void)
  98. {
  99. PicoMemSetup();
  100. // no MD IO or Z80 on Pico
  101. m68k_map_unmap(0x400000, 0xbfffff);
  102. // map Pico I/O
  103. cpu68k_map_set(m68k_read8_map, 0x800000, 0x80ffff, PicoRead8_pico, 1);
  104. cpu68k_map_set(m68k_read16_map, 0x800000, 0x80ffff, PicoRead16_pico, 1);
  105. cpu68k_map_set(m68k_write8_map, 0x800000, 0x80ffff, PicoWrite8_pico, 1);
  106. cpu68k_map_set(m68k_write16_map, 0x800000, 0x80ffff, PicoWrite16_pico, 1);
  107. }