Advertisement
Guest User

Untitled

a guest
May 18th, 2015
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. //NES-CNROM (treble mapper)
  2.  
  3. class Settings {
  4. integer mirror; //0 = horizontal, 1 = vertical
  5. }
  6.  
  7. Settings settings;
  8. integer chr_bank;
  9.  
  10. function prg_read(integer addr) returns integer {
  11. if(addr & 0x8000) return prg.read(addr & 0x7fff);
  12. return cpu.mdr();
  13. }
  14.  
  15. function prg_write(integer addr, integer data) {
  16. if(addr & 0x8000) chr_bank = data & 0x03;
  17. }
  18.  
  19. function chr_read(integer addr) returns integer {
  20. if(addr & 0x2000) {
  21. if(settings.mirror == 0) addr = ((addr & 0x0800) >> 1) | (addr & 0x03ff);
  22. return ciram.read(addr & 0x07ff);
  23. }
  24. addr = (chr_bank * 0x2000) + (addr & 0x1fff);
  25. return chr.read(addr);
  26. }
  27.  
  28. function chr_write(integer addr, integer data) {
  29. if(addr & 0x2000) {
  30. if(settings.mirror == 0) addr = ((addr & 0x0800) >> 1) | (addr & 0x03ff);
  31. return ciram.write(addr & 0x07ff, data);
  32. }
  33. addr = (chr_bank * 0x2000) + (addr & 0x1fff);
  34. chr.write(addr, data);
  35. }
  36.  
  37. function power() {
  38. settings.mirror = manifest("cartridge/mirror/mode") == "vertical";
  39. }
  40.  
  41. function reset() {
  42. chr_bank = 0;
  43. }
  44.  
  45. function serialize(serializer& s) {
  46. s.integer(chr_bank);
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement