unrom512.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * UNROM Mapper - The peTI-NESulator Project
  3. * unrom.h
  4. *
  5. * Created by Manoel TRAPIER.
  6. * Copyright (c) 2003-2018 986-Studio. All rights reserved.
  7. *
  8. */
  9. #include <ppu/ppu.h>
  10. #include "unrom512.h"
  11. static byte mirroring_set;
  12. static byte loaded_vbank;
  13. static byte loaded_pbank;
  14. /*
  15. * not great but as we currently don't support higher than 8K VRAM, allocate it here as we can have
  16. * 32K on such a cart
  17. */
  18. static uint8_t vram[32768];
  19. void ppu_setPagePtr8k(byte page, byte *ptr);
  20. static void unrom512_applyValues()
  21. {
  22. /*if (mirroring_set)
  23. {
  24. ppu_setMirroring(PPU);
  25. }
  26. else
  27. {
  28. ppu_setMirroring(PPU_MIRROR_VERTICAL);
  29. }*/
  30. ppu_setPagePtr8k(0x00, vram + (loaded_vbank * 8 * 1024));
  31. set_prom_bank_16k(0x8000, loaded_pbank);
  32. }
  33. static void unrom512_MapperWriteHook(byte Addr, byte Value)
  34. {
  35. mirroring_set = (Value >> 7) & 0x01;
  36. loaded_vbank = (Value >> 5) & 0x03;
  37. loaded_pbank = (Value ) & 0x1F;
  38. printf(">> P:%d | V:%d | M:%d <<\n", loaded_pbank, loaded_vbank, mirroring_set);
  39. unrom512_applyValues();
  40. }
  41. int unrom512_InitMapper(NesCart * cart)
  42. {
  43. int i;
  44. loaded_vbank = 0;
  45. loaded_pbank = 0;
  46. set_prom_bank_16k(0xC000, GETLAST16KBANK(cart));
  47. unrom512_applyValues();
  48. /* Register the write hook */
  49. for (i = 0x80; i < 0x100; i++)
  50. {
  51. set_page_wr_hook(i, unrom512_MapperWriteHook);
  52. set_page_writeable(i, true);
  53. }
  54. return 0;
  55. }
  56. void unrom512_MapperDump(FILE *fp)
  57. {
  58. fprintf(fp,"unrom512: vbank:%d pbank:%d\n", loaded_vbank, loaded_pbank);
  59. }