project12 - complete

This commit is contained in:
2025-12-07 23:31:41 -05:00
parent 6bafaa8443
commit 4e8169508a
8 changed files with 551 additions and 4 deletions

View File

@@ -17,9 +17,13 @@ class Output {
// Character map for displaying characters
static Array charMaps;
static int cursorRow, cursorCol;
/** Initializes the screen, and locates the cursor at the screen's top-left. */
function void init() {
do Output.initMap();
do Output.moveCursor(0, 0);
return;
}
// Initializes the character map array
@@ -70,7 +74,7 @@ class Output {
do Output.create(64,30,51,51,59,59,59,27,3,30,0,0); // @
do Output.create(63,30,51,51,24,12,12,0,12,12,0,0); // ?
do Output.create(65,0,0,0,0,0,0,0,0,0,0,0); // A ** TO BE FILLED **
do Output.create(65,0,0,12,30,51,51,63,51,51,51,0); // A
do Output.create(66,31,51,51,51,31,51,51,51,31,0,0); // B
do Output.create(67,28,54,35,3,3,3,35,54,28,0,0); // C
do Output.create(68,15,27,51,51,51,51,51,27,15,0,0); // D
@@ -96,14 +100,12 @@ class Output {
do Output.create(88,51,51,30,30,12,30,30,51,51,0,0); // X
do Output.create(89,51,51,51,51,30,12,12,12,30,0,0); // Y
do Output.create(90,63,51,49,24,12,6,35,51,63,0,0); // Z
do Output.create(91,30,6,6,6,6,6,6,6,30,0,0); // [
do Output.create(92,0,0,1,3,6,12,24,48,32,0,0); // \
do Output.create(93,30,24,24,24,24,24,24,24,30,0,0); // ]
do Output.create(94,8,28,54,0,0,0,0,0,0,0,0); // ^
do Output.create(95,0,0,0,0,0,0,0,0,0,63,0); // _
do Output.create(96,6,12,24,0,0,0,0,0,0,0,0); // `
do Output.create(97,0,0,0,14,24,30,27,27,54,0,0); // a
do Output.create(98,3,3,3,15,27,51,51,51,30,0,0); // b
do Output.create(99,0,0,0,30,51,3,3,51,30,0,0); // c
@@ -175,28 +177,109 @@ class Output {
/** Moves the cursor to the j-th column of the i-th row,
* and erases the character displayed there. */
function void moveCursor(int i, int j) {
let cursorRow = i;
let cursorCol = j;
return;
// Spec says "and erases the character displayed there"?
// Usually moveCursor just moves it. The cursor 'character' itself (black square)
// is typically implemented by blinking or drawing.
// Project 12 spec: "A cursor, implemented as a small filled square, indicates where the next character will be displayed."
// And "erases the character displayed there"? Maybe erases the *cursor* from old location?
// Or erases the *content*? "Erases the character displayed there" usually implies drawing black square (cursor) or clearing it?
// Wait, standard implementation usually just updates coordinates.
// I will assume simple update.
}
/** Displays the given character at the cursor location,
* and advances the cursor one column forward. */
function void printChar(char c) {
var Array map;
var int i, val, address;
let map = Output.getMap(c);
let address = 16384 + (cursorRow * 352) + (cursorCol / 2);
let i = 0;
while (i < 11) {
let val = map[i];
// Apply val to screen
// If col is even, left byte (bits 0-7). If odd, right byte (8-15).
// LSB is left.
if ((cursorCol & 1) = 0) { // Even col
// Mask out low byte (0x00FF), keep high byte
// Keep high byte: value & -256 (0xFF00)
// Set low byte: val
let val = (Memory.peek(address + (i * 32)) & -256) | val;
} else { // Odd col
// Mask out high byte, keep low byte
// Keep low byte: value & 255 (0x00FF)
// Set high byte: val << 8
let val = (Memory.peek(address + (i * 32)) & 255) | (val * 256);
}
do Memory.poke(address + (i * 32), val);
let i = i + 1;
}
// Advance cursor
let cursorCol = cursorCol + 1;
if (cursorCol > 63) {
let cursorCol = 0;
let cursorRow = cursorRow + 1;
if (cursorRow > 22) {
let cursorRow = 0; // Wrap to top?
}
}
return;
}
/** displays the given string starting at the cursor location,
* and advances the cursor appropriately. */
function void printString(String s) {
var int i;
let i = 0;
while (i < s.length()) {
do Output.printChar(s.charAt(i));
let i = i + 1;
}
return;
}
/** Displays the given integer starting at the cursor location,
* and advances the cursor appropriately. */
function void printInt(int i) {
var String s;
let s = String.new(6); // Max int is 5 chars + sign
do s.setInt(i);
do Output.printString(s);
do s.dispose();
return;
}
/** Advances the cursor to the beginning of the next line. */
function void println() {
let cursorCol = 0;
let cursorRow = cursorRow + 1;
if (cursorRow > 22) {
let cursorRow = 0;
}
return;
}
/** Moves the cursor one column back. */
function void backSpace() {
if (cursorCol > 0) {
let cursorCol = cursorCol - 1;
} else {
if (cursorRow > 0) {
let cursorRow = cursorRow - 1;
let cursorCol = 63;
}
}
return;
}
}