Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix Real Graphics modes #27

Merged
merged 3 commits into from Nov 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/main/java/ca/craigthomas/yacoco3e/components/CPU.java
Expand Up @@ -1516,8 +1516,10 @@ public int executeInstruction() throws IllegalIndexedPostbyteException {
case 0x3D:
a = io.getByteRegister(Register.A);
b = io.getByteRegister(Register.B);
opLongDesc += "A=" + a + ", B=" + b + ", ";
UnsignedWord tempResult = new UnsignedWord(a.getShort() * b.getShort());
io.setD(tempResult);
opLongDesc += "D'=" + tempResult;
cc = io.getCC();
cc.and(~(IOController.CC_Z | IOController.CC_C));
cc.or(tempResult.isZero() ? IOController.CC_Z : 0);
Expand Down Expand Up @@ -2918,7 +2920,9 @@ public void executeByteFunctionM(Function<UnsignedByte, UnsignedByte> function,
* @return the complimented value
*/
public UnsignedByte compliment(UnsignedByte value) {
opLongDesc += "R=" + value + ", ";
UnsignedByte result = new UnsignedByte(~(value.getShort()));
opLongDesc += "R'=" + result;
UnsignedByte cc = io.getCC();
cc.and(~(IOController.CC_N | IOController.CC_Z | IOController.CC_V));
cc.or(IOController.CC_C);
Expand Down Expand Up @@ -2967,11 +2971,13 @@ public UnsignedByte negate(UnsignedByte value) {
* @return the shifted byte value
*/
public UnsignedByte logicalShiftRight(UnsignedByte value) {
opLongDesc = "R=" + value + ", C=" + io.ccCarrySet() + ", ";
UnsignedByte result = new UnsignedByte(value.getShort() >> 1);
UnsignedByte cc = io.getCC();
cc.and(~(IOController.CC_N | IOController.CC_Z | IOController.CC_C));
cc.or(value.isMasked(0x1) ? IOController.CC_C : 0);
cc.or(result.isZero() ? IOController.CC_Z : 0);
opLongDesc += "R'=" + result + ", C'=" + io.ccCarrySet();
return result;
}

Expand Down
162 changes: 119 additions & 43 deletions src/main/java/ca/craigthomas/yacoco3e/components/IOController.java
Expand Up @@ -37,19 +37,22 @@ public class IOController
/* SAM Display Offset Register */
protected UnsignedByte samDisplayOffsetRegister;

/* PIA1 DRB */
protected UnsignedByte pia1DRA;
protected UnsignedByte pia1CRA;
/* PIA1 */
protected UnsignedByte pia1DRA; /* PIA 1 Data Register A */
protected UnsignedByte pia1CRA; /* PIA 1 Control Register A */
protected UnsignedByte pia1DDRA; /* PIA 1 Data Direction Register A */

protected UnsignedByte pia1DRB;
protected UnsignedByte pia1CRB;

/* PIA2 Data Register and Control Register */
protected UnsignedByte pia2DRA;
protected UnsignedByte pia2CRA;
/* PIA2 */
protected UnsignedByte pia2DRA; /* PIA 2 Data Register A */
protected UnsignedByte pia2CRA; /* PIA 2 Control Register A*/
protected UnsignedByte pia2DDRA; /* PIA 2 Data Direction Register A */

protected UnsignedByte pia2DRB;
protected UnsignedByte pia2CRB;
protected UnsignedByte pia2DDRB;

/* Video mode related functions */
protected UnsignedByte vdgOperatingMode;
Expand Down Expand Up @@ -140,15 +143,18 @@ public IOController(Memory memory, RegisterSet registerSet, Keyboard keyboard, S
/* PIAs */
pia1CRA = new UnsignedByte(0);
pia1DRA = new UnsignedByte(0);
pia1DDRA = new UnsignedByte(0);

pia1CRB = new UnsignedByte(0);
pia1DRB = new UnsignedByte(0);

pia2CRA = new UnsignedByte(0);
pia2DRA = new UnsignedByte(0);
pia2DDRA = new UnsignedByte(0);

pia2CRB = new UnsignedByte(0);
pia2DRB = new UnsignedByte(0);
pia2DDRB = new UnsignedByte(0);

/* Interrupts */
irqStatus = new UnsignedByte(0);
Expand Down Expand Up @@ -274,19 +280,22 @@ public UnsignedByte readIOByte(int address) {

/* PIA 2 Data Register A */
case 0xFF20:
pia2DRA.and(0);
if (pia2CRA.isMasked(0x4)) {
pia2DRA.and(0);

/* Bit 0 = Cassette Data Input */
pia2DRA.or(cassette.nextBit());
return pia2DRA;
/* Bit 0 = Cassette Data Input */
pia2DRA.or(cassette.nextBit());
return pia2DRA;
}
return pia2DDRB;

/* PIA 2 Control Register A */
case 0xFF21:
return pia2CRA;

/* VDG Operating Mode */
/* PIA 2 DRB / DDRB */
case 0xFF22:
return vdgOperatingMode;
return pia2CRB.isMasked(0x4) ? vdgOperatingMode : pia2DDRB;

/* PIA 2 Control Register B */
case 0xFF23:
Expand Down Expand Up @@ -392,14 +401,32 @@ public void writeIOByte(UnsignedWord address, UnsignedByte value) {
int intAddress = address.getInt() - 0xFF00;
ioMemory[intAddress] = value.getShort();

// if (!address.equals(new UnsignedWord(0xFF20)) && !address.equals(new UnsignedWord(0xFF02))) {
// System.out.println("Writing " + value + " to address " + address);
// }

switch (address.getInt()) {
/* PIA 1 Data Register A */
case 0xFF00:
case 0xFF04:
case 0xFF08:
case 0xFF0C:
case 0xFF10:
case 0xFF14:
case 0xFF18:
case 0xFF1C:
pia1DRA = value.copy();
break;

/* PIA 1 Control Register A */
case 0xFF01:
case 0xFF05:
case 0xFF09:
case 0xFF0D:
case 0xFF11:
case 0xFF15:
case 0xFF19:
case 0xFF1D:
/* Bit 0 = IRQ 63.5 microseconds */
if (value.isMasked(0x1)) {
pia1FastTimerEnabled = true;
Expand All @@ -420,11 +447,25 @@ public void writeIOByte(UnsignedWord address, UnsignedByte value) {

/* PIA 1 Data Register B */
case 0xFF02:
case 0xFF06:
case 0xFF0A:
case 0xFF0E:
case 0xFF12:
case 0xFF16:
case 0xFF1A:
case 0xFF1E:
pia1DRB = value.copy();
break;

/* PIA 1 Control Register B */
case 0xFF03:
case 0xFF07:
case 0xFF0B:
case 0xFF0F:
case 0xFF13:
case 0xFF17:
case 0xFF1B:
case 0xFF1F:
/* Bit 0 = IRQ 16 milliseconds */
if (value.isMasked(0x1)) {
pia1SlowTimerEnabled = true;
Expand All @@ -443,14 +484,28 @@ public void writeIOByte(UnsignedWord address, UnsignedByte value) {
(pia1CRB.isMasked(0x40) ? 0x40 : 0));
break;

/* PIA 2 Data Register A */
/* PIA 2 Data Register A / Data Direction Register A */
case 0xFF20:
case 0xFF24:
case 0xFF28:
case 0xFF2C:
case 0xFF30:
case 0xFF34:
case 0xFF38:
case 0xFF3C:
/* Bits 2-7 = digital analog values */
cassette.byteInput(value);
break;

/* PIA 2 Control Register A */
case 0xFF21:
case 0xFF25:
case 0xFF29:
case 0xFF2D:
case 0xFF31:
case 0xFF35:
case 0xFF39:
case 0xFF3D:
/* Bit 0 = FIRQ from serial I/O port */

/* Bit 1 = hi/lo edge triggered */
Expand All @@ -464,18 +519,36 @@ public void writeIOByte(UnsignedWord address, UnsignedByte value) {
pia2CRA = value.copy();
break;

/* VDG Operating Mode */
/* PIA 2 Data Register B / Data Direction Register B */
case 0xFF22:
vdgOperatingMode = value.copy();
updateVideoMode();
case 0xFF26:
case 0xFF2A:
case 0xFF2E:
case 0xFF32:
case 0xFF36:
case 0xFF3A:
case 0xFF3E:
if (pia2CRB.isMasked(0x4)) {
vdgOperatingMode = value.copy();
vdgOperatingMode.and(pia2DDRB.getShort());
updateVideoMode();
} else {
pia2DDRB = value.copy();
}
break;

/* PIA 2 Control Register B */
case 0xFF23:
/* Bit 0 = FIRQ from cartridge ROM */

case 0xFF27:
case 0xFF2B:
case 0xFF2F:
case 0xFF33:
case 0xFF37:
case 0xFF3B:
case 0xFF3F:
/* Bit 2 = Control whether Data Register or Data Direction Register active */
/* Bit 1 = hi/lo edge triggered */

/* Bit 0 = FIRQ from cartridge ROM */
pia2CRB = value.copy();
break;

Expand Down Expand Up @@ -845,64 +918,67 @@ public void updateVerticalOffset() {
}

public void updateVideoMode() {
// Semigraphics text checks
ScreenMode.Mode mode = screen.getMode();
int colorSet = vdgOperatingMode.isMasked(0x8) ? 1 : 0;
int vdgBytes = vdgOperatingMode.getShort() & 0x70;

// System.out.println("VDG " + vdgOperatingMode);
// System.out.println("SAM " + samControlBits);

if (!vdgOperatingMode.isMasked(0x80)) {
if (vdgOperatingMode.isMasked(0x10)) {
if (samControlBits.equals(new UnsignedByte())) {
screen.setMode(ScreenMode.Mode.SG6, vdgOperatingMode.isMasked(0x8) ? 1 : 0);
mode = ScreenMode.Mode.SG6;
}
} else {
if (samControlBits.equals(new UnsignedByte())) {
screen.setMode(ScreenMode.Mode.SG4, 0);
mode = ScreenMode.Mode.SG4;
colorSet = 0;
}

if (samControlBits.equals(new UnsignedByte(0x2))) {
screen.setMode(ScreenMode.Mode.SG8, 0);
}
mode = ScreenMode.Mode.SG8;
colorSet = 0; }

if (samControlBits.equals(new UnsignedByte(0x4))) {
screen.setMode(ScreenMode.Mode.SG12, 0);
mode = ScreenMode.Mode.SG12;
colorSet = 0;
}

if (samControlBits.equals(new UnsignedByte(0x6))) {
screen.setMode(ScreenMode.Mode.SG24, 0);
mode = ScreenMode.Mode.SG24;
colorSet = 0;
}
}
} else {
int vdgBytes = vdgOperatingMode.getShort() & 0x70;
if (vdgBytes == 0x00 && samControlBits.equals(new UnsignedByte(0x1))) {
screen.setMode(ScreenMode.Mode.G1C, vdgOperatingMode.isMasked(0x8) ? 1 : 0);
return;
mode = ScreenMode.Mode.G1C;
}
if (vdgBytes == 0x10 && samControlBits.equals(new UnsignedByte(0x1))) {
screen.setMode(ScreenMode.Mode.G1R, vdgOperatingMode.isMasked(0x8) ? 1 : 0);
return;
mode = ScreenMode.Mode.G1R;
}
if (vdgBytes == 0x20 && samControlBits.equals(new UnsignedByte(0x2))) {
screen.setMode(ScreenMode.Mode.G2C, vdgOperatingMode.isMasked(0x8) ? 1 : 0);
return;
mode = ScreenMode.Mode.G2C;
}
if (vdgBytes == 0x30 && samControlBits.equals(new UnsignedByte(0x3))) {
screen.setMode(ScreenMode.Mode.G2R, vdgOperatingMode.isMasked(0x8) ? 1 : 0);
return;
mode = ScreenMode.Mode.G2R;
}
if (vdgBytes == 0x40 && samControlBits.equals(new UnsignedByte(0x4))) {
screen.setMode(ScreenMode.Mode.G3C, vdgOperatingMode.isMasked(0x8) ? 1 : 0);
return;
mode = ScreenMode.Mode.G3C;
}
if (vdgBytes == 0x50 && samControlBits.equals(new UnsignedByte(0x5))) {
screen.setMode(ScreenMode.Mode.G3R, vdgOperatingMode.isMasked(0x8) ? 1 : 0);
return;
mode = ScreenMode.Mode.G3R;
}
if (vdgBytes == 0x60 && samControlBits.equals(new UnsignedByte(0x6))) {
screen.setMode(ScreenMode.Mode.G6C, vdgOperatingMode.isMasked(0x8) ? 1 : 0);
return;
mode = ScreenMode.Mode.G6C;
}
if (vdgBytes == 0x70 && samControlBits.equals(new UnsignedByte(0x6))) {
screen.setMode(ScreenMode.Mode.G6R, vdgOperatingMode.isMasked(0x8) ? 1 : 0);
return;
mode = ScreenMode.Mode.G6R;
}
}
int memoryOffset = screen.getMemoryOffset();
screen.setMode(mode, colorSet);
screen.setMemoryOffset(memoryOffset);
}

/**
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/ca/craigthomas/yacoco3e/components/Screen.java
Expand Up @@ -108,6 +108,10 @@ public void setMode(ScreenMode.Mode mode, int colorSet) {
currentMode = mode;
}

public ScreenMode.Mode getMode() {
return currentMode;
}

/**
* Sets an IO controller.
*
Expand All @@ -130,12 +134,12 @@ public void setMemoryOffset(int offset) {
}

/**
* Returns true if the memory offset of the backbuffer has changed.
* Returns the area in physical memory where the screen should draw from.
*
* @return true if the memory offset window has changed
* @return the offset in physical memory where the screen should draw from
*/
public int getMemoryOffset() {
return screenMode.getMemoryOffset();
return memoryOffset;
}

/**
Expand Down