From 000116b2a25d42b2071715aeedfa6ec347ee79b1 Mon Sep 17 00:00:00 2001 From: Eremey Valetov Date: Tue, 10 Mar 2026 22:38:42 -0400 Subject: [PATCH] Fix POINT coordinate mapping, remove orphaned palette array, expand tests Apply coordinate mapping (VIEW/WINDOW) to POINT(x,y) function so it returns correct pixel values when WINDOW is active. Remove unused palette[] array from graphics.c (Sixel encoder uses palette_map[] directly). Expand view_window.bas test to cover WINDOW SCREEN mode, VIEW+WINDOW combination, and PMAP inverse mapping. Fix CI test count in docs. --- docs/development.md | 2 +- src/eval.c | 15 +++++++++-- src/graphics.c | 6 +---- tests/expected/view_window.expected | 9 +++++++ tests/programs/view_window.bas | 39 +++++++++++++++++++++-------- 5 files changed, 53 insertions(+), 18 deletions(-) diff --git a/docs/development.md b/docs/development.md index e4e4d68..6256db3 100644 --- a/docs/development.md +++ b/docs/development.md @@ -50,6 +50,6 @@ bash tests/run_compat.sh ## CI GitHub Actions runs on every push to `main` and on pull requests. The workflow -builds the project with PulseAudio support and runs all 64 test programs. +builds the project with PulseAudio support and runs all 66 test programs. See [`.github/workflows/ci.yml`](https://github.com/evvaletov/gw-basic-2026/blob/main/.github/workflows/ci.yml). diff --git a/src/eval.c b/src/eval.c index 7e6d847..f191d9f 100644 --- a/src/eval.c +++ b/src/eval.c @@ -865,9 +865,20 @@ static gw_value_t eval_atom(void) if (tok == TOK_POINT) { gw_chrget(); gw_expect('('); - int px = gw_eval_int(); + int px, py; + if (gfx_has_window()) { + gw_value_t vx = gw_eval_num(); + px = gfx_map_x(gw_to_dbl(&vx)); + } else { + px = gfx_map_x((double)gw_eval_int()); + } gw_expect(','); - int py = gw_eval_int(); + if (gfx_has_window()) { + gw_value_t vy = gw_eval_num(); + py = gfx_map_y(gw_to_dbl(&vy)); + } else { + py = gfx_map_y((double)gw_eval_int()); + } gw_expect_rparen(); gw_value_t v; v.type = VT_INT; diff --git a/src/graphics.c b/src/graphics.c index 1e01507..f02c377 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -22,7 +22,6 @@ static const uint32_t default_palette[16] = { /* Active palette: palette_map[attr] gives the physical color index */ static int palette_map[16]; -static uint32_t palette[16]; /* Viewport state (VIEW) */ static bool vp_active; @@ -36,10 +35,8 @@ static double win_x1, win_y1, win_x2, win_y2; static void reset_palette(void) { - for (int i = 0; i < 16; i++) { + for (int i = 0; i < 16; i++) palette_map[i] = i; - palette[i] = default_palette[i]; - } } bool gfx_active(void) { return framebuf != NULL; } @@ -663,7 +660,6 @@ void gfx_palette_set(int attr, int color) { if (attr < 0 || attr > 15 || color < 0 || color > 15) return; palette_map[attr] = color; - palette[attr] = default_palette[color]; } void gfx_palette_reset(void) diff --git a/tests/expected/view_window.expected b/tests/expected/view_window.expected index 06e68a5..d36241e 100644 --- a/tests/expected/view_window.expected +++ b/tests/expected/view_window.expected @@ -4,4 +4,13 @@ PMAP(100,0)= 639 PMAP(100,1)= 0 PMAP(0,2)= 0 PMAP(199,3)= 0 +SCR PMAP(0,1)= 0 +SCR PMAP(100,1)= 199 +SCR PMAP(50,0)= 319.5 +SCR PMAP(0,3)= 0 +SCR PMAP(199,3)= 100 +VP PMAP(0,0)= 100 +VP PMAP(10,0)= 300 +VP PMAP(0,1)= 150 +VP PMAP(10,1)= 50 VIEW/WINDOW/PALETTE OK diff --git a/tests/programs/view_window.bas b/tests/programs/view_window.bas index 7687e50..c77a433 100644 --- a/tests/programs/view_window.bas +++ b/tests/programs/view_window.bas @@ -1,6 +1,6 @@ 10 REM VIEW / WINDOW / PALETTE test 20 SCREEN 2 -30 REM Test WINDOW coordinate mapping +30 REM === Test WINDOW (Cartesian, Y-up) === 40 WINDOW (0,0)-(100,100) 50 REM PMAP: logical to physical 60 PRINT "PMAP(0,0)="; PMAP(0,0) @@ -10,12 +10,31 @@ 100 REM PMAP: physical to logical 110 PRINT "PMAP(0,2)="; PMAP(0,2) 120 PRINT "PMAP(199,3)="; PMAP(199,3) -130 WINDOW -140 REM Test VIEW -150 VIEW (10,10)-(100,50) -160 REM After VIEW, drawing clips to viewport -170 VIEW -180 REM Test PALETTE (just reset, no visual check) -190 PALETTE -200 SCREEN 0 -210 PRINT "VIEW/WINDOW/PALETTE OK" +130 REM === Test WINDOW SCREEN (Y-down) === +140 WINDOW SCREEN (0,0)-(100,100) +150 REM In SCREEN mode, Y=0 maps to top (0), Y=100 maps to bottom (199) +160 PRINT "SCR PMAP(0,1)="; PMAP(0,1) +170 PRINT "SCR PMAP(100,1)="; PMAP(100,1) +180 PRINT "SCR PMAP(50,0)="; PMAP(50,0) +190 REM Inverse: physical to logical +200 PRINT "SCR PMAP(0,3)="; PMAP(0,3) +210 PRINT "SCR PMAP(199,3)="; PMAP(199,3) +220 WINDOW +230 REM === Test VIEW === +240 VIEW (10,10)-(100,50) +250 REM After VIEW, reset to check state +260 VIEW +270 REM === Test WINDOW + VIEW together === +280 VIEW (100,50)-(300,150) +290 WINDOW (0,0)-(10,10) +300 REM PMAP should map relative to viewport (100..300, 50..150) +310 PRINT "VP PMAP(0,0)="; PMAP(0,0) +320 PRINT "VP PMAP(10,0)="; PMAP(10,0) +330 PRINT "VP PMAP(0,1)="; PMAP(0,1) +340 PRINT "VP PMAP(10,1)="; PMAP(10,1) +350 WINDOW +360 VIEW +370 REM === Test PALETTE (just reset, no visual check) === +380 PALETTE +390 SCREEN 0 +400 PRINT "VIEW/WINDOW/PALETTE OK"