Could anyone help me with my STAT code? Trying to get my timings right so the proper modes are set at the right time. Something major is wrong... I've attached my cpu, but here's some basic snippets of the code:
Here's the actual set mode function, stollen from Aprentice (this part works fine, it's the calling of it that is off):
Code:
#define reqINT(x) IOReg_IF|=x;
void VIDEO::SetLCDCMode(int mode)
{
IOReg_STAT=(IOReg_STAT&0xFC)|mode; //Clear and set bits 0,1
switch(mode)
{
case 0: //HBlank
if(IOReg_STAT&0x08) reqINT(INT_LCDC);
break;
case 1: //VBlank
if(IOReg_STAT&0x10) reqINT(INT_LCDC);
break;
case 2: //OAM
if(IOReg_STAT&0x20) reqINT(INT_LCDC);
break;
case 3: //Transfer
//if(cpu.hdma&0x80) hdma_hblank();
break;
}
}
Now, here's where I call it. This is in my main CPU loop, shortly after I execute my opcode...
Code:
/* handle input/output */
// set STAT mode
cpu.count_stat+=cpu.cycles;
if(cpu.count_stat_mode==0 && cpu.count_stat>=CYCLES_OAMTRANSFER){
vid.VIDEO::SetLCDCMode(MODE_HBLANK);
cpu.count_stat_mode=1;
cpu.count_stat=0;
}else{
if(cpu.count_stat_mode==1 && cpu.count_stat>=CYCLES_HBLANK){
vid.VIDEO::SetLCDCMode(CYCLES_TRANSFER);
cpu.count_stat_mode=2;
cpu.count_stat=0;
}else{
if(cpu.count_stat_mode==2 && cpu.count_stat>=CYCLES_TRANSFER){
vid.VIDEO::SetLCDCMode(MODE_OAMTRANSFER);
cpu.count_stat_mode=0;
cpu.count_stat=0;
}else{
if(cpu.count_stat_mode>2 && cpu.count_stat<CYCLES_VBLANK*10){
cpu.count_stat_mode=0;
cpu.count_stat=0;
}
}
}
}
// main input and output
if (IOReg_LY < 144){
vid.VIDEO::DrawScanline();
cpu.count_stat_mode++;
if(cpu.count_stat_mode==3)
{
cpu.count_stat=0;
vid.VIDEO::SetLCDCMode(MODE_VBLANK);
}
}
That's basically it. It's kinna sloppy... bare in mind the first thing I do is set the OAMTRANSFER mode outside of the loop, that's why the first mode set is actually the HBLANK. Anyways, I bugged Aprentice on IRC enough about it, so hopefully you guys will see something wrong. Currently, I don't think it is working.

Attached my core... STAT stuff is around line 2246. Thanks!
Regards,