Skip to content

Commit

Permalink
Implement mode flag; fixes #2
Browse files Browse the repository at this point in the history
  • Loading branch information
Xyene committed Dec 8, 2015
1 parent 4ec6aea commit 54c72f3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 45 deletions.
16 changes: 12 additions & 4 deletions src/main/java/nitrous/lcd/LCD.java
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,15 @@ public void tick(long cycles)
core.mmu.hdma.tick();
}

core.mmu.registers[R_LCD_STAT] &= ~0x03;

int mode = 0;
if (isVBlank) mode = 0x01;

core.mmu.registers[R_LCD_STAT] |= mode;

int lcdStat = core.mmu.registers[R_LCD_STAT];
if(displayEnabled && !isVBlank)
if (displayEnabled && !isVBlank)
{
/**
* INT 48 - LCDC Status Interrupt
Expand All @@ -332,9 +339,10 @@ public void tick(long cycles)
if (lyc == LY)
{
core.setInterruptTriggered(LCDC_BIT);
core.mmu.registers[R_LYC] |= LCD_STAT.COINCIDENCE_BIT;
} else {
core.mmu.registers[R_LYC] &= ~LCD_STAT.COINCIDENCE_BIT;
core.mmu.registers[R_LCD_STAT] |= LCD_STAT.COINCIDENCE_BIT;
} else
{
core.mmu.registers[R_LCD_STAT] &= ~LCD_STAT.COINCIDENCE_BIT;
}
}

Expand Down
58 changes: 17 additions & 41 deletions src/main/java/nitrous/mbc/Memory.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ public void tick()
{
vram[vramPageStart + dest + i] = (byte) (getAddress(source + i) & 0xff);
}
core.cycle += 8;
core.ac += 8;
core.executed += 8;
// core.cycle += 8;
// core.ac += 8;
// core.executed += 8;
ptr += 0x10;
length -= 0x10;
System.err.printf("Ticked HDMA from %04X-%04X, %02X remaining\n", source, dest, length);
Expand Down Expand Up @@ -243,6 +243,11 @@ public void setAddress(int addr, int _data)
public void setIO(int addr, int data)
{
// System.out.printf("IO WRITE %04X=%02X\n", addr&0xffff, data&0xff);
if (addr == 0x4d)
{
if ((addr & 0x01) != 0) doubleSpeed = true;
else doubleSpeed = false;
}
_setIO(addr, data);
}

Expand Down Expand Up @@ -299,9 +304,9 @@ public void _setIO(int addr, int data)
if (hdma != null)
{
System.err.printf("!!! Terminated HDMA from %04X-%04X, %02X remaining\n", source, dest, length);
hdma = null;
registers[0x55] = (byte) 0x80;
break;
// hdma = null;
// registers[0x55] = (byte) 0x80;
// break;
}
// General DMA
for (int i = 0; i < length; i++)
Expand Down Expand Up @@ -505,8 +510,14 @@ public short _mapMemory(int addr)
}


boolean doubleSpeed = false;
public short getIO(int addr)
{
if (addr == 0x4d)
{
if (doubleSpeed) return 0x80;
return 0;
}
short ret = _readReg(addr);
// System.out.printf("IO READ %04X=%02X\n", addr&0xFFFF, (byte)ret);
return ret;
Expand Down Expand Up @@ -541,41 +552,6 @@ public short _readReg(int addr)
// I'm not sure if this is correct, but if its not it probably doesn't matter
return (short) ((0x30 | output | (reg & 0b1100000)) & 0xff);
}
case R.R_LCD_STAT:
byte reg = 0;
// Bit 2 - Coincidence Flag
// 0: LYC not equal to LY
// 1: LYC = LY
if (registers[R.R_LY] == registers[R.R_LYC])
{
reg |= 0x04;
}
// When 144 <= LY <= 153, we're in vblank
if ((registers[R.R_LY] & 0xFF) > 144)
{
reg |= 0x01;
} else
{
// System.out.println("!!!");
// FIXME
// long _cycle = core.cycle % R.INSTRS_PER_HBLANK;
// int section = R.INSTRS_PER_HBLANK / 6;
// if (_cycle < section * 3)
// {
// // We're in hblank
// } else if (_cycle <= section * 4)
// {
// // We're in OAM ram search
// reg |= 0x02;
// } else
// {
// // We're transferring data to LCD Driver
// reg |= 0x03;
// }
}
// Add whatever else might've been set in the other bits
reg |= registers[R.R_LCD_STAT] & 0xF8;
return 0;
}
return registers[addr];
}
Expand Down

0 comments on commit 54c72f3

Please sign in to comment.