Remove trailing whitespace and clean up comments

This commit is contained in:
2025-12-10 13:50:02 -05:00
parent 1870e87a9c
commit 36b54929d0
5 changed files with 64 additions and 81 deletions

View File

@@ -5,13 +5,13 @@
/**
* A library of functions for displaying graphics on the screen.
* The Hack physical screen consists of 512 rows (indexed 0..511, top to bottom)
* of 256 pixels each (indexed 0..255, left to right). The top left pixel on
* of 256 pixels each (indexed 0..255, left to right). The top left pixel on
* the screen is indexed (0,0).
*/
class Screen {
static boolean color;
static Array powersOfTwo; // Helper for bit manipulation
/** Initializes the Screen. */
function void init() {
let color = true; // Default black
@@ -57,20 +57,19 @@ class Screen {
function void drawPixel(int x, int y) {
var int address, value;
var int mask;
let address = 16384 + (y * 32) + (x / 16);
let value = Memory.peek(address);
// Calculate 2^(x%16) logic inline or helper?
// x & 15 is x % 16
let mask = powersOfTwo[x & 15];
let mask = powersOfTwo[x & 15];
if (color) {
let value = value | mask;
} else {
let value = value & ~mask;
}
do Memory.poke(address, value);
return;
}
@@ -81,7 +80,7 @@ class Screen {
var int a, b;
var int diff;
var int temp;
if (x1 > x2) {
let temp = x1;
let x1 = x2;
@@ -90,13 +89,13 @@ class Screen {
let y1 = y2;
let y2 = temp;
}
let dx = x2 - x1;
let dy = y2 - y1;
let a = 0;
let b = 0;
let diff = 0;
// Vertical line
if (dx = 0) {
if (y1 > y2) {
@@ -110,7 +109,7 @@ class Screen {
}
return;
}
// Horizontal line
if (dy = 0) {
while (~(x1 > x2)) {
@@ -119,7 +118,7 @@ class Screen {
}
return;
}
// Diagonal
if (dy > 0) {
while ((~(a > dx)) & (~(b > dy))) {
@@ -144,7 +143,7 @@ class Screen {
}
}
}
return;
}
@@ -165,14 +164,14 @@ class Screen {
var int dy;
var int r2;
var int halfWidth;
if (r > 181) {
return; // overflow check
}
let dy = -r;
let r2 = r*r;
while (~(dy > r)) {
let halfWidth = Math.sqrt(r2 - (dy*dy));
do Screen.drawLine(x - halfWidth, y + dy, x + halfWidth, y + dy);