Advertisement
Guest User

nespaste

a guest
Mar 29th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.56 KB | None | 0 0
  1. private int inrange(int y){
  2. if((scanline+1)-(y)>=0)
  3. return (scanline+1)-y;
  4. else
  5. return 9;
  6. }
  7. boolean dodebug;
  8. private int stage = 1;
  9. private int n,m = 0;
  10. int spritec = 0;
  11. int c3=0;
  12. boolean spriteeven=false;
  13. boolean cont = false;
  14. void spriteEvaluation(){
  15. if(pcycle>=1 &&pcycle<=64){
  16. if(pcycle==1){
  17. Arrays.fill(oambuffer,(byte) 0xff);
  18. oamsignal = true;
  19. }
  20.  
  21. }
  22. else if(pcycle>=65 &&pcycle<=256){
  23. oamsignal = false;
  24. int y = 0;
  25. switch(stage){//1
  26. case 1:
  27. //System.out.println("in stage 1: " +inrange(y));
  28. y=Byte.toUnsignedInt(map.ppureadoam(4*n));
  29. oambuffer[4*oamBCounter]=map.ppureadoam(4*n);
  30. if(inrange(y)<8&&y<241){
  31. oambuffer[4*oamBCounter+1]=map.ppureadoam(4*n+1);
  32. oambuffer[4*oamBCounter+2]=map.ppureadoam(4*n+2);
  33. oambuffer[4*oamBCounter+3]=map.ppureadoam(4*n+3);
  34. oamBCounter++;
  35. if(n==0){
  36. //spritezerohit= true;
  37. }
  38. }
  39.  
  40. stage = 2;
  41. break;
  42. case 2: //2
  43. //System.out.println("in stage 2");
  44. if(n==63){
  45. n =0;
  46. cont = true;
  47. }
  48. else
  49. n++;
  50. if(cont){
  51. stage = 4;
  52. }
  53. else if(oamBCounter<8){
  54. stage = 1;
  55. }
  56. else if(oamBCounter ==8){
  57. //disable writes
  58. m=0;
  59. c3=0;
  60. stage = 3;
  61. }
  62.  
  63. break;
  64. case 3: //3
  65. //System.out.println("in stage 3");
  66. y = Byte.toUnsignedInt(map.ppureadoam((4*n+m)));
  67. if(inrange(y)<8){
  68. PPUSTATUS_so = true;
  69. if(m==3){
  70. n++;
  71. m=0;
  72. c3++;
  73. }
  74. else{
  75. m++;
  76. c3++;
  77. }
  78. }
  79. else{
  80. if(n==63){
  81. stage = 4;
  82. n = 0;
  83. m = 0;
  84. c3++;
  85. }
  86. else{
  87. n++;
  88. c3++;
  89. if(m==3)
  90. m=0;
  91. else
  92. m++;
  93. }
  94. }
  95.  
  96. break;
  97. case 4: //4
  98. //System.out.println("in stage 4");
  99.  
  100. //do nothing forever
  101. oamBCounter=0;
  102. break;
  103. default: break;
  104. }
  105. }
  106. else if(pcycle>=257&&pcycle<=320){
  107. if(pcycle==257){
  108. oamBCounter=0;
  109. }
  110. switch((pcycle)%8){
  111. case 0:
  112. oamBCounter++;
  113. spritec++;
  114. break;
  115. case 1:
  116. spriteco[spritec] = Byte.toUnsignedInt(oambuffer[4*oamBCounter+3]);
  117. //spritela[spritec] = oambuffer[4*oamBCounter+2];
  118. byte b = oambuffer[4*oamBCounter+2];
  119. spritepalette[spritec] = b&3;
  120. spritepriority[spritec] = (b&32)>0?true:false;
  121. int y = inrange(oambuffer[4*oamBCounter]);
  122. int tileindex;
  123. if((b&0x80)!=0){
  124. tileindex = (Byte.toUnsignedInt(oambuffer[4*oamBCounter+1])<<4)+(8-y);
  125. }
  126. else
  127. tileindex = (Byte.toUnsignedInt(oambuffer[4*oamBCounter+1])<<4)+y;
  128. tileindex+= PPUCTRL_spta?0x1000:0;
  129. //int y = inrange(oambuffer[4*oamBCounter]);
  130. //int tileindex = (Byte.toUnsignedInt(oambuffer[4*oamBCounter+1])<<4)+y;
  131. //if((mem.read(0x2000)&0b1000)!=0)
  132. // tileindex+=0x1000;
  133. //System.out.println("Tile index of sprite "+oamBCounter+": "+Integer.toHexString(tileindex));
  134. /*if((b&0x40)!=0){
  135. byte z = map.ppuread(tileindex);
  136. byte flip = 0;
  137. flip|=z&1;z>>>=1;flip<<=1;
  138. flip|=z&1;z>>>=1;flip<<=1;
  139. flip|=z&1;z>>>=1;flip<<=1;
  140. flip|=z&1;z>>>=1;flip<<=1;
  141. flip|=z&1;z>>>=1;flip<<=1;
  142. flip|=z&1;z>>>=1;flip<<=1;
  143. flip|=z&1;z>>>=1;flip<<=1;
  144. flip|=z&1;
  145. x = flip<<8;
  146. z = map.ppuread(tileindex+8);
  147. flip=0;
  148. flip|=z&1;z>>>=1;flip<<=1;
  149. flip|=z&1;z>>>=1;flip<<=1;
  150. flip|=z&1;z>>>=1;flip<<=1;
  151. flip|=z&1;z>>>=1;flip<<=1;
  152. flip|=z&1;z>>>=1;flip<<=1;
  153. flip|=z&1;z>>>=1;flip<<=1;
  154. flip|=z&1;z>>>=1;flip<<=1;
  155. flip|=z&1;
  156. flip<<=1;
  157. x|=flip;
  158. spritebm[spritec]=x;
  159. }
  160. else*/
  161. spritebm[spritec] = (Byte.toUnsignedInt((map.ppuread(tileindex)))<<8)|Byte.toUnsignedInt((map.ppuread(tileindex+8)));
  162.  
  163. //int x = Integer.reverse(Byte.toUnsignedInt(map.ppuread(tileindex)))>>>24;
  164. //spritebm[spritec] = (x<<8)|(Integer.reverse(Byte.toUnsignedInt(map.ppuread(tileindex+8)))>>>24);
  165. break;
  166. default: break;
  167. }
  168. }
  169. else{
  170. stage=1;
  171. n = 0;
  172. m =0;
  173. cont=false;
  174. oamBCounter=0;
  175. spritec=0;
  176. }
  177. if(dodebug){
  178. try {
  179. System.in.read();
  180.  
  181. System.out.println("v: "+Integer.toHexString(v)
  182. +" yfine: "+ (v>>12)
  183. +" scanline: "+scanline
  184. +" pcycle: "+pcycle
  185. +" n: "+n
  186. +" Sprites found: "+oamBCounter);
  187. //debugSprites();
  188. System.out.println(Arrays.toString(oambuffer));
  189. System.out.println(Arrays.toString(map.ppu_oam));
  190. // mem.printMemoryoam();
  191. //cpu.debug();
  192. } catch (IOException e) {
  193. e.printStackTrace();
  194. }
  195. }
  196. }
  197.  
  198. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement