Guest User

Untitled

a guest
Jun 11th, 2012
233
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void PPU::raster_scanline() {
  2. if((status.ly >= 240 && status.ly <= 260)) {
  3. for(unsigned x = 0; x < 341; x++) tick();
  4. return scanline();
  5. }
  6.  
  7. raster.oam_iterator = 0;
  8. raster.oam_counter = 0;
  9.  
  10. for(unsigned n = 0; n < 8; n++) {
  11. raster.soam[n].id = 64;
  12. raster.soam[n].y = 0xff;
  13. raster.soam[n].tile = 0xff;
  14. raster.soam[n].attr = 0xff;
  15. raster.soam[n].x = 0xff;
  16. raster.soam[n].tiledatalo = 0;
  17. raster.soam[n].tiledatahi = 0;
  18. }
  19.  
  20. for(unsigned tile = 0; tile < 32; tile++) { // 0-255
  21. unsigned nametable = chr_load(0x2000 | (status.vaddr & 0x0fff));
  22. unsigned tileaddr = status.bg_addr + (nametable << 4) + (scrolly() & 7);
  23. raster_pixel();
  24. tick();
  25.  
  26. raster_pixel();
  27. tick();
  28.  
  29. unsigned attribute = chr_load(0x23c0 | (status.vaddr & 0x0fc0) | ((scrolly() >> 5) << 3) | (scrollx() >> 5));
  30. if(scrolly() & 16) attribute >>= 4;
  31. if(scrollx() & 16) attribute >>= 2;
  32. raster_pixel();
  33. tick();
  34.  
  35. scrollx_increment();
  36. if(tile == 31) scrolly_increment();
  37. raster_pixel();
  38. raster_sprite();
  39. tick();
  40.  
  41. unsigned tiledatalo = chr_load(tileaddr + 0);
  42. raster_pixel();
  43. tick();
  44.  
  45. raster_pixel();
  46. tick();
  47.  
  48. unsigned tiledatahi = chr_load(tileaddr + 8);
  49. raster_pixel();
  50. tick();
  51.  
  52. raster_pixel();
  53. raster_sprite();
  54. tick();
  55.  
  56. raster.nametable = (raster.nametable << 8) | nametable;
  57. raster.attribute = (raster.attribute << 2) | (attribute & 3);
  58. raster.tiledatalo = (raster.tiledatalo << 8) | tiledatalo;
  59. raster.tiledatahi = (raster.tiledatahi << 8) | tiledatahi;
  60. }
  61.  
  62. for(unsigned n = 0; n < 8; n++) raster.oam[n] = raster.soam[n];
  63.  
  64. for(unsigned sprite = 0; sprite < 8; sprite++) { //256-319
  65. unsigned nametable = chr_load(0x2000 | (status.vaddr & 0x0fff));
  66. tick();
  67.  
  68. if(raster_enable() && sprite == 0) status.vaddr = (status.vaddr & 0x7be0) | (status.taddr & 0x041f); //257
  69. tick();
  70.  
  71. unsigned attribute = chr_load(0x23c0 | (status.vaddr & 0x0fc0) | ((scrolly() >> 5) << 3) | (scrollx() >> 5));
  72. unsigned tileaddr = (sprite_height() == 8)
  73. ? status.sprite_addr + raster.oam[sprite].tile * 16
  74. : ((raster.oam[sprite].tile & ~1) * 16) + ((raster.oam[sprite].tile & 1) * 0x1000);
  75. tick();
  76. tick();
  77.  
  78. unsigned spritey = (status.ly - raster.oam[sprite].y) & (sprite_height() - 1);
  79. if(raster.oam[sprite].attr & 0x80) spritey ^= (sprite_height() - 1);
  80. tileaddr += spritey + (spritey & 8);
  81.  
  82. raster.oam[sprite].tiledatalo = chr_load(tileaddr + 0);
  83. tick();
  84. tick();
  85.  
  86. raster.oam[sprite].tiledatahi = chr_load(tileaddr + 8);
  87. tick();
  88. tick();
  89.  
  90. if(raster_enable() && sprite == 6 && status.ly == 261) status.vaddr = status.taddr; //304
  91. }
  92.  
  93. for(unsigned tile = 0; tile < 2; tile++) { //320-335
  94. unsigned nametable = chr_load(0x2000 | (status.vaddr & 0x0fff));
  95. unsigned tileaddr = status.bg_addr + (nametable << 4) + (scrolly() & 7);
  96. tick();
  97. tick();
  98.  
  99. unsigned attribute = chr_load(0x23c0 | (status.vaddr & 0x0fc0) | ((scrolly() >> 5) << 3) | (scrollx() >> 5));
  100. if(scrolly() & 16) attribute >>= 4;
  101. if(scrollx() & 16) attribute >>= 2;
  102. tick();
  103.  
  104. scrollx_increment();
  105. tick();
  106.  
  107. unsigned tiledatalo = chr_load(tileaddr + 0);
  108. tick();
  109. tick();
  110.  
  111. unsigned tiledatahi = chr_load(tileaddr + 8);
  112. tick();
  113. tick();
  114.  
  115. raster.nametable = (raster.nametable << 8) | nametable;
  116. raster.attribute = (raster.attribute << 2) | (attribute & 3);
  117. raster.tiledatalo = (raster.tiledatalo << 8) | tiledatalo;
  118. raster.tiledatahi = (raster.tiledatahi << 8) | tiledatahi;
  119. }
  120.  
  121. //336-339
  122. chr_load(0x2000 | (status.vaddr & 0x0fff));
  123. tick();
  124. bool skip = (raster_enable() && status.field == 1 && status.ly == 261);
  125. tick();
  126.  
  127. chr_load(0x2000 | (status.vaddr & 0x0fff));
  128. tick();
  129. tick();
  130.  
  131. //340
  132. if(skip == false) tick();
  133.  
  134. return scanline();
  135. }
RAW Paste Data