Add a 640x480 two-colour graphics mode; start in white

The graphics memory doubles as 640x480 at a bit a pixel (port 38), four
pixels to an entry, plotted by read-modify-write, in two colours from
port 39 (0 transparent). BASIC gets SCREEN 0 / SCREEN 1 [,set[,clear]];
a plain fill (as every game does) returns to 320x240 and BASIC follows.
The text now starts in white (SW5:4 = 00; 10 is green). The README is
rewritten to stand on its own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
brad ArantandClaude Opus 5.5 committed 2026-12-01 06:06:30 -08:00
1 parent 71fd403294
commit bda9bb67b6
13 files changed
+2985 -2680

No files matched your search

+43 -20
View File
@@ -9,8 +9,8 @@
* statement typed without a line number runs at once. Ctrl-C stops a program.
*
* Graphics: 320x240 in 16 colours over the text, origin top left, colour 0
* transparent. CLS COLOR PLOT LINE RECT FILL CIRCLE and POINT(x,y); LOCATE and
* INK place and colour text.
* transparent, or (SCREEN 1) 640x480 in two. CLS COLOR PLOT LINE RECT FILL
* CIRCLE and POINT(x,y); LOCATE and INK place and colour text.
*
* Files: SAVE "NAME", LOAD "NAME", RUN "NAME", DIR, DEL "NAME" keep programs
* in the spare part of the configuration flash (see the file system below).
@@ -53,10 +53,15 @@ static u8 scr_width(void) { return con_stat & 4 ? 132 : 80; }
#define gy_p IO8(0x32)
#define gpix IO8(0x33) /* write plots and moves right; read gives the colour */
#define gfill IO8(0x34)
static void g_at(u16 x, u8 y) { gx_lo = x; gx_hi = x >> 8; gy_p = y; }
#define gmode IO8(0x38) /* bit 0: 640x480 in two colours (a game's fill ends it) */
#define gcols IO8(0x39) /* its colours: set pixels 3:0, clear ones 7:4 */
static void g_at(u16 x, u16 y) { gx_lo = x; gx_hi = x >> 8 | (y >> 8) << 2; gy_p = y; }
static void g_put(u8 c) { gpix = c; }
static u8 g_get(void) { return gpix; }
static void g_clear(u8 c) { gfill = c; while (gfill & 1); }
/* clear to colour 0, sprites off, scroll to 0; the fill also ends 640x480 mode */
static void g_clear(u8 hi) { gfill = 0; while (gfill & 1); gmode = hi; }
static void g_colours(u8 set, u8 clr) { gcols = set | clr << 4; }
static u8 g_hires(void) { return gmode & 1; }
/* SPI flash: port 40h opens/ends a command (bit 1 reads back "refused"),
41h shifts a byte. The hardware refuses to write below the file area. */
@@ -118,13 +123,14 @@ static void io_out(u8 p, u8 v) { (void)p; (void)v; }
static void close_all(void);
static void bye(void) { close_all(); exit(0); }
static u8 scr_width(void) { return 80; }
static u8 gmem[240][320];
static u16 hgx;
static u8 hgy;
static void g_at(u16 x, u8 y) { hgx = x; hgy = y; }
static void g_put(u8 c) { if (hgx < 320 && hgy < 240) gmem[hgy][hgx] = c; hgx++; }
static u8 g_get(void) { return hgx < 320 && hgy < 240 ? gmem[hgy][hgx] : 0; }
static void g_clear(u8 c) { memset(gmem, c, sizeof gmem); }
static u8 gmem[480][640];
static u16 hgx, hgy, hgw = 320, hgh = 240;
static void g_at(u16 x, u16 y) { hgx = x; hgy = y; }
static void g_put(u8 c) { if (hgx < hgw && hgy < hgh) gmem[hgy][hgx] = hgw > 320 ? c != 0 : c; hgx++; }
static u8 g_get(void) { return hgx < hgw && hgy < hgh ? gmem[hgy][hgx] : 0; }
static void g_clear(u8 hi) { memset(gmem, 0, sizeof gmem); hgw = hi ? 640 : 320; hgh = hi ? 480 : 240; }
static void g_colours(u8 set, u8 clr) { (void)set; (void)clr; }
static u8 g_hires(void) { return hgw > 320; }
/* flash file area kept in basic-flash.img */
#define HOST_BASE 0x240000UL
@@ -174,12 +180,17 @@ static struct chan ch[NCHAN];
static struct chan *chan_arg(u8 mode);
static u8 chan_line(struct chan *c);
static u8 ghi; /* 640x480 (SCREEN 1) */
static u16 gw = 320, gh = 240; /* the graphics' size */
/* follow the hardware's mode: a game run with CALL may have ended SCREEN 1 */
static void g_sync(void) { ghi = g_hires(); gw = ghi ? 640 : 320; gh = ghi ? 480 : 240; }
/* ----------------------------------------------------------------- tokens */
enum {
T_LET = 0x80, T_PRINT, T_INPUT, T_IF, T_THEN, T_GOTO, T_GOSUB, T_RETURN, T_FOR,
T_TO, T_STEP, T_NEXT, T_DIM, T_DEF, T_END, T_STOP, T_REM, T_READ, T_DATA,
T_RESTORE, T_ON, T_RANDOMIZE, T_POKE, T_OUT, T_RUN, T_LIST, T_NEW, T_SCRATCH,
T_BYE, T_CLS, T_COLOR, T_PLOT, T_LINE, T_RECT, T_FILL, T_CIRCLE, T_LOCATE, T_INK,
T_BYE, T_CLS, T_COLOR, T_PLOT, T_LINE, T_RECT, T_FILL, T_CIRCLE, T_LOCATE, T_INK, T_SCREEN,
T_SAVE, T_LOAD, T_DIR, T_DEL, T_DATE, T_OPEN, T_CLOSE, T_MONITOR, T_CALL, T_BSAVE, T_BLOAD, T_OUTPUT, T_APPEND, T_AND, T_OR, T_NOT, T_SIN, T_COS, T_TAN, T_ATN, T_EXP, T_LOG, T_ABS,
T_SQR, T_INT, T_RND, T_SGN, T_FN, T_TAB, T_PEEK, T_INP, T_LEN, T_VAL, T_ASC, T_EOF,
T_CHRS, T_STRS, T_LEFTS, T_RIGHTS, T_MIDS, T_DATES, T_TIM, T_POINT, T_LE, T_GE, T_NE, T_RENUM, T_LAST
@@ -189,7 +200,7 @@ static const char *const kw[] = {
"LET", "PRINT", "INPUT", "IF", "THEN", "GOTO", "GOSUB", "RETURN", "FOR",
"TO", "STEP", "NEXT", "DIM", "DEF", "END", "STOP", "REM", "READ", "DATA",
"RESTORE", "ON", "RANDOMIZE", "POKE", "OUT", "RUN", "LIST", "NEW", "SCRATCH",
"BYE", "CLS", "COLOR", "PLOT", "LINE", "RECT", "FILL", "CIRCLE", "LOCATE", "INK",
"BYE", "CLS", "COLOR", "PLOT", "LINE", "RECT", "FILL", "CIRCLE", "LOCATE", "INK", "SCREEN",
"SAVE", "LOAD", "DIR", "DEL", "DATE", "OPEN", "CLOSE", "MONITOR", "CALL", "BSAVE", "BLOAD", "OUTPUT", "APPEND", "AND", "OR", "NOT", "SIN", "COS", "TAN", "ATN", "EXP", "LOG", "ABS",
"SQR", "INT", "RND", "SGN", "FN", "TAB", "PEEK", "INP", "LEN", "VAL", "ASC", "EOF",
"CHR$", "STR$", "LEFT$", "RIGHT$", "MID$", "DATE$", "TIM", "POINT", "<=", ">=", "<>", "RENUM"
@@ -763,7 +774,8 @@ static float func(u8 t)
expect(',');
y = to_int(expr());
expect(')');
if ((u16)x >= 320 || (u16)y >= 240) return 0;
g_sync();
if ((u16)x >= gw || (u16)y >= gh) return 0;
g_at(x, y);
return g_get();
}
@@ -1570,16 +1582,16 @@ static void hline(i16 x1, i16 x2, i16 y, u8 c)
{
i16 t;
if (x1 > x2) { t = x1; x1 = x2; x2 = t; }
if ((u16)y >= 240 || x2 < 0 || x1 > 319) return;
if ((u16)y >= gh || x2 < 0 || x1 >= (i16)gw) return;
if (x1 < 0) x1 = 0;
if (x2 > 319) x2 = 319;
if (x2 >= (i16)gw) x2 = gw - 1;
g_at(x1, y);
for (; x1 <= x2; x1++) g_put(c);
}
static void pset(i16 x, i16 y, u8 c)
{
if ((u16)x < 320 && (u16)y < 240) { g_at(x, y); g_put(c); }
if ((u16)x < gw && (u16)y < gh) { g_at(x, y); g_put(c); }
}
static void line(i16 x1, i16 y1, i16 x2, i16 y2, u8 c)
@@ -1623,12 +1635,23 @@ static void graphics(u8 t)
{
i16 a[5];
u8 n, c;
g_sync();
switch (t) {
case T_CLS:
out_c(27); out_c('['); out_c('2'); out_c('J');
out_c(27); out_c('['); out_c('H');
col = 0;
g_clear(0);
g_clear(ghi);
break;
case T_SCREEN: /* SCREEN 0 | SCREEN 1 [, set [, clear]] */
n = int_args(a, 1, 3);
if ((u16)a[0] > 1 || (n > 1 && (u16)a[1] > 15) || (n > 2 && (u16)a[2] > 15))
error(E_FUNC);
ghi = a[0];
gw = ghi ? 640 : 320;
gh = ghi ? 480 : 240;
g_colours(n > 1 ? a[1] : 15, n > 2 ? a[2] : 0);
g_clear(ghi);
break;
case T_COLOR:
int_args(a, 1, 1);
@@ -1658,7 +1681,7 @@ static void graphics(u8 t)
y = a[1] < a[3] ? a[1] : a[3];
y2 = a[1] < a[3] ? a[3] : a[1];
if (y < 0) y = 0;
if (y2 > 239) y2 = 239;
if (y2 >= (i16)gh) y2 = gh - 1;
for (; y <= y2; y++) hline(a[0], a[2], y, c);
break;
}
@@ -2311,7 +2334,7 @@ static void statement(void)
graphics(t);
break;
case T_CLS: case T_COLOR: case T_PLOT: case T_RECT:
case T_FILL: case T_CIRCLE: case T_LOCATE: case T_INK:
case T_FILL: case T_CIRCLE: case T_LOCATE: case T_INK: case T_SCREEN:
graphics(t);
break;
default: