memory.c 3.0 KB

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