Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private int inrange(int y){
- if((scanline+1)-(y)>=0)
- return (scanline+1)-y;
- else
- return 9;
- }
- boolean dodebug;
- private int stage = 1;
- private int n,m = 0;
- int spritec = 0;
- int c3=0;
- boolean spriteeven=false;
- boolean cont = false;
- void spriteEvaluation(){
- if(pcycle>=1 &&pcycle<=64){
- if(pcycle==1){
- Arrays.fill(oambuffer,(byte) 0xff);
- oamsignal = true;
- }
- }
- else if(pcycle>=65 &&pcycle<=256){
- oamsignal = false;
- int y = 0;
- switch(stage){//1
- case 1:
- //System.out.println("in stage 1: " +inrange(y));
- y=Byte.toUnsignedInt(map.ppureadoam(4*n));
- oambuffer[4*oamBCounter]=map.ppureadoam(4*n);
- if(inrange(y)<8&&y<241){
- oambuffer[4*oamBCounter+1]=map.ppureadoam(4*n+1);
- oambuffer[4*oamBCounter+2]=map.ppureadoam(4*n+2);
- oambuffer[4*oamBCounter+3]=map.ppureadoam(4*n+3);
- oamBCounter++;
- if(n==0){
- //spritezerohit= true;
- }
- }
- stage = 2;
- break;
- case 2: //2
- //System.out.println("in stage 2");
- if(n==63){
- n =0;
- cont = true;
- }
- else
- n++;
- if(cont){
- stage = 4;
- }
- else if(oamBCounter<8){
- stage = 1;
- }
- else if(oamBCounter ==8){
- //disable writes
- m=0;
- c3=0;
- stage = 3;
- }
- break;
- case 3: //3
- //System.out.println("in stage 3");
- y = Byte.toUnsignedInt(map.ppureadoam((4*n+m)));
- if(inrange(y)<8){
- PPUSTATUS_so = true;
- if(m==3){
- n++;
- m=0;
- c3++;
- }
- else{
- m++;
- c3++;
- }
- }
- else{
- if(n==63){
- stage = 4;
- n = 0;
- m = 0;
- c3++;
- }
- else{
- n++;
- c3++;
- if(m==3)
- m=0;
- else
- m++;
- }
- }
- break;
- case 4: //4
- //System.out.println("in stage 4");
- //do nothing forever
- oamBCounter=0;
- break;
- default: break;
- }
- }
- else if(pcycle>=257&&pcycle<=320){
- if(pcycle==257){
- oamBCounter=0;
- }
- switch((pcycle)%8){
- case 0:
- oamBCounter++;
- spritec++;
- break;
- case 1:
- spriteco[spritec] = Byte.toUnsignedInt(oambuffer[4*oamBCounter+3]);
- //spritela[spritec] = oambuffer[4*oamBCounter+2];
- byte b = oambuffer[4*oamBCounter+2];
- spritepalette[spritec] = b&3;
- spritepriority[spritec] = (b&32)>0?true:false;
- int y = inrange(oambuffer[4*oamBCounter]);
- int tileindex;
- if((b&0x80)!=0){
- tileindex = (Byte.toUnsignedInt(oambuffer[4*oamBCounter+1])<<4)+(8-y);
- }
- else
- tileindex = (Byte.toUnsignedInt(oambuffer[4*oamBCounter+1])<<4)+y;
- tileindex+= PPUCTRL_spta?0x1000:0;
- //int y = inrange(oambuffer[4*oamBCounter]);
- //int tileindex = (Byte.toUnsignedInt(oambuffer[4*oamBCounter+1])<<4)+y;
- //if((mem.read(0x2000)&0b1000)!=0)
- // tileindex+=0x1000;
- //System.out.println("Tile index of sprite "+oamBCounter+": "+Integer.toHexString(tileindex));
- /*if((b&0x40)!=0){
- byte z = map.ppuread(tileindex);
- byte flip = 0;
- flip|=z&1;z>>>=1;flip<<=1;
- flip|=z&1;z>>>=1;flip<<=1;
- flip|=z&1;z>>>=1;flip<<=1;
- flip|=z&1;z>>>=1;flip<<=1;
- flip|=z&1;z>>>=1;flip<<=1;
- flip|=z&1;z>>>=1;flip<<=1;
- flip|=z&1;z>>>=1;flip<<=1;
- flip|=z&1;
- x = flip<<8;
- z = map.ppuread(tileindex+8);
- flip=0;
- flip|=z&1;z>>>=1;flip<<=1;
- flip|=z&1;z>>>=1;flip<<=1;
- flip|=z&1;z>>>=1;flip<<=1;
- flip|=z&1;z>>>=1;flip<<=1;
- flip|=z&1;z>>>=1;flip<<=1;
- flip|=z&1;z>>>=1;flip<<=1;
- flip|=z&1;z>>>=1;flip<<=1;
- flip|=z&1;
- flip<<=1;
- x|=flip;
- spritebm[spritec]=x;
- }
- else*/
- spritebm[spritec] = (Byte.toUnsignedInt((map.ppuread(tileindex)))<<8)|Byte.toUnsignedInt((map.ppuread(tileindex+8)));
- //int x = Integer.reverse(Byte.toUnsignedInt(map.ppuread(tileindex)))>>>24;
- //spritebm[spritec] = (x<<8)|(Integer.reverse(Byte.toUnsignedInt(map.ppuread(tileindex+8)))>>>24);
- break;
- default: break;
- }
- }
- else{
- stage=1;
- n = 0;
- m =0;
- cont=false;
- oamBCounter=0;
- spritec=0;
- }
- if(dodebug){
- try {
- System.in.read();
- System.out.println("v: "+Integer.toHexString(v)
- +" yfine: "+ (v>>12)
- +" scanline: "+scanline
- +" pcycle: "+pcycle
- +" n: "+n
- +" Sprites found: "+oamBCounter);
- //debugSprites();
- System.out.println(Arrays.toString(oambuffer));
- System.out.println(Arrays.toString(map.ppu_oam));
- // mem.printMemoryoam();
- //cpu.debug();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement