unrom512.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. unrom512_applyValues();
  39. }
  40. int unrom512_InitMapper(NesCart * cart)
  41. {
  42. int i;
  43. loaded_vbank = 0;
  44. loaded_pbank = 0;
  45. set_prom_bank_16k(0xC000, GETLAST16KBANK(cart));
  46. unrom512_applyValues();
  47. /* Register the write hook */
  48. for (i = 0x80; i < 0x100; i++)
  49. {
  50. set_page_wr_hook(i, unrom512_MapperWriteHook);
  51. set_page_writeable(i, true);
  52. }
  53. return 0;
  54. }
  55. void unrom512_MapperDump(FILE *fp)
  56. {
  57. fprintf(fp,"unrom512: vbank:%d pbank:%d\n", loaded_vbank, loaded_pbank);
  58. }