#!/usr/bin/env python3 """BASIC's graphics modes in tools/rv32emu.py (tools/boardemu.py models the graphics): SCREEN 1 (640x480 in two colours) and back to SCREEN 0. python3 test-screen.py Needs pyte. """ import importlib.util import os import sys HERE = os.path.dirname(os.path.abspath(__file__)) spec = importlib.util.spec_from_file_location("test_edit", os.path.join(HERE, "test-edit.py")) te = importlib.util.module_from_spec(spec) spec.loader.exec_module(te) def main(): b = te.Basic() errors = 0 def check(what, ok): nonlocal errors print(("PASS " if ok else "FAIL ") + what) errors += not ok def last(): rows = [l.rstrip() for l in b.screen_text().display if l.strip()] return rows[-2] if rows and rows[-1] == "READY" else rows[-1:] CR = b"\r" b.type(b"") b.type(b"SCREEN 1,14,1" + CR) check("SCREEN 1 turns on 640x480 with its colours", b.g_hires == 1 and b.g_cols == 0x1E) b.type(b"LINE 0,0,639,479:CIRCLE 320,240,200:PLOT 600,470,0:PRINT POINT(639,479);POINT(320,40);POINT(1,0);POINT(700,10)" + CR) check("POINT reads pixels past 320x240", last() == " 1 1 0 0") h = b.hgfx check("the line reaches the corner", h[0] == 1 and h[479 * 640 + 639] == 1 and h[240 * 640 + 320] == 1) check("the circle is in the 640x480 plane", h[240 * 640 + 520] == 1 and h[440 * 640 + 320] == 1) check("the 320x240 plane is untouched", not any(b.gfx)) b.type(b"FILL 600,460,639,479:PLOT 639,479,0:PRINT POINT(600,460);POINT(639,479)" + CR) check("FILL and erasing with colour 0", last() == " 1 0") b.type(b"CLS:PRINT POINT(320,40)" + CR) check("CLS clears but stays in 640x480", b.g_hires == 1 and not any(b.hgfx) and last() == " 0") b.type(b"SCREEN 0:PLOT 319,239,9:PRINT POINT(319,239);POINT(320,40)" + CR) check("SCREEN 0 goes back to 320x240 in 16 colours", b.g_hires == 0 and last() == " 9 0") b.type(b"SCREEN 2" + CR) check("SCREEN 2 is an error", "?" in "".join(b.screen_text().display) or "ERROR" in "".join(b.screen_text().display)) # a game's fill ends 640x480 mode; BASIC follows the hardware b.type(b"SCREEN 1:OUT 52,0:PLOT 319,239,5:PRINT POINT(319,239)" + CR) check("after a plain fill BASIC is back in 320x240", b.g_hires == 0 and last() == " 5") print("%d error(s)" % errors) sys.exit(1 if errors else 0) main()