Skip to content

Commit

Permalink
[#314] correctly compute attribute address + fix keys
Browse files Browse the repository at this point in the history
  • Loading branch information
vbmacher committed Jan 29, 2023
1 parent 7910faa commit bdf1148
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ ext.versions = [
]

ext.libs = [
emuLib : "net.emustudio:emulib:11.7.0-SNAPSHOT",
cpuTestSuite : "net.emustudio:cpu-testsuite_11.6:1.2.0-SNAPSHOT",
emuLib : "net.emustudio:emulib:11.7.0",
cpuTestSuite : "net.emustudio:cpu-testsuite_11.7:1.2.0",

jcipAnnotations : "net.jcip:jcip-annotations:1.0",
antlr : "org.antlr:antlr4:4.11.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,15 @@
public class ULA implements Context8080.CpuPortDevice, Keyboard.OnKeyListener {
public static final int SCREEN_WIDTH = 32; // in bytes; each byte represents 8 pixels in a row, reversed
public static final int SCREEN_HEIGHT = 192;
public static final int ATTRIBUTE_HEIGHT = SCREEN_HEIGHT / 8;

private final static byte[] RST_7 = new byte[0x38]; // works for IM1 and IM2 modes

private final MemoryContext<Byte> memory;
private final Context8080 cpu;
private final byte[] keymap = new byte[8];
public final byte[][] videoMemory = new byte[SCREEN_WIDTH][SCREEN_HEIGHT];
public final byte[][] attributeMemory = new byte[SCREEN_WIDTH][SCREEN_HEIGHT / 8];
public final byte[][] attributeMemory = new byte[SCREEN_WIDTH][ATTRIBUTE_HEIGHT];
private final static int[] lineStartOffsets = computeLineStartOffsets();

private static int[] computeLineStartOffsets() {
Expand All @@ -95,8 +96,10 @@ public void readScreen() {
for (int x = 0; x < SCREEN_WIDTH; x++) {
for (int y = 0; y < SCREEN_HEIGHT; y++) {
videoMemory[x][y] = memory.read(0x4000 + lineStartOffsets[y] + x);
if (y < SCREEN_HEIGHT / 8) {
attributeMemory[x][y] = memory.read(0x5800 + lineStartOffsets[y] + x);
if (y < ATTRIBUTE_HEIGHT) {
int off = ((y >>> 3) << 8) | (((y & 0x07) << 5) | x);
int attributeAddress = 0x5800 + off;
attributeMemory[x][y] = memory.read(attributeAddress);
}
}
}
Expand Down Expand Up @@ -156,45 +159,59 @@ public void onKeyDown(byte data) {
case KeyEvent.VK_SHIFT:
keymap[0] |= 0x1;
break;
case 'z':
case 'Z':
keymap[0] |= 0x2;
break;
case 'x':
case 'X':
keymap[0] |= 0x4;
break;
case 'c':
case 'C':
keymap[0] |= 0x8;
break;
case 'v':
case 'V':
keymap[0] |= 0x10;
break;
case 'a':
case 'A':
keymap[1] |= 0x1;
break;
case 's':
case 'S':
keymap[1] |= 0x2;
break;
case 'd':
case 'D':
keymap[1] |= 0x4;
break;
case 'f':
case 'F':
keymap[1] |= 0x8;
break;
case 'g':
case 'G':
keymap[1] |= 0x10;
break;
case 'q':
case 'Q':
keymap[2] |= 0x1;
break;
case 'w':
case 'W':
keymap[2] |= 0x2;
break;
case 'e':
case 'E':
keymap[2] |= 0x4;
break;
case 'r':
case 'R':
keymap[2] |= 0x8;
break;
case 't':
case 'T':
keymap[2] |= 0x10;
break;
Expand Down Expand Up @@ -228,46 +245,58 @@ public void onKeyDown(byte data) {
case '6':
keymap[4] |= 0x10;
break;
case 'p':
case 'P':
keymap[5] |= 0x1;
break;
case 'o':
case 'O':
keymap[5] |= 0x2;
break;
case 'i':
case 'I':
keymap[5] |= 0x4;
break;
case 'u':
case 'U':
keymap[5] |= 0x8;
break;
case 'y':
case 'Y':
keymap[5] |= 0x10;
break;
case KeyEvent.VK_ENTER:
keymap[6] |= 0x1;
break;
case 'l':
case 'L':
keymap[6] |= 0x2;
break;
case 'k':
case 'K':
keymap[6] |= 0x4;
break;
case 'j':
case 'J':
keymap[6] |= 0x8;
break;
case 'h':
case 'H':
keymap[6] |= 0x10;
break;
case ' ':
keymap[7] |= 0x1;
break;
// SYM SHFT ???
case 'm':
case 'M':
keymap[7] |= 0x4;
break;
case 'n':
case 'N':
keymap[7] |= 0x8;
break;
case 'b':
case 'B':
keymap[7] |= 0x10;
break;
Expand Down

0 comments on commit bdf1148

Please sign in to comment.