From a86a19fc8c3ddc4690b9592f1f61864ddd98f284 Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Tue, 4 Jan 2022 15:38:06 +0100 Subject: [PATCH] Add raw mode for charwin --- autotest/autotest.bat | 3 ++ autotest/charwintest.c | 64 ++++++++++++++++++++++++++++++++++ include/c64/charwin.c | 79 ++++++++++++++++++++++++++++++++++++++++++ include/c64/charwin.h | 30 ++++++++++++++++ 4 files changed, 176 insertions(+) create mode 100644 autotest/charwintest.c diff --git a/autotest/autotest.bat b/autotest/autotest.bat index 430e46e..252f1c9 100644 --- a/autotest/autotest.bat +++ b/autotest/autotest.bat @@ -120,6 +120,9 @@ rem @echo off @call :test scrolltest.c @if %errorlevel% neq 0 goto :error +@call :test charwintest.c +@if %errorlevel% neq 0 goto :error + @exit /b 0 :error diff --git a/autotest/charwintest.c b/autotest/charwintest.c new file mode 100644 index 0000000..418926e --- /dev/null +++ b/autotest/charwintest.c @@ -0,0 +1,64 @@ +#include +#include +#include + +int main(void) +{ + CharWin cw; + + cwin_init(&cw, (char *)0x0400, 2, 2, 32, 20); + + cwin_clear(&cw); + + for(int y=0; y<20; y++) + { + for(int x=0; x<32; x++) + { + assert(cwin_getat_char_raw(&cw, x, y) == ' '); + } + } + + for(int y=0; y<20; y++) + { + for(int x=0; x<32; x++) + { + cwin_putat_char(&cw, x, y, p'a' - 1 + x, 7); + } + } + + + for(int y=0; y<20; y++) + { + for(int x=0; x<32; x++) + { + assert(cwin_getat_char(&cw, x, y) == p'a' -1 + x); + } + } + + + for(int y=0; y<20; y++) + { + for(int x=0; x<32; x++) + { + cwin_putat_char(&cw, x, y, p'A' - 1 + x, 8); + } + } + + for(int y=0; y<20; y++) + { + for(int x=0; x<32; x++) + { + cwin_putat_char_raw(&cw, x, y, x + 32 * y, 8); + } + } + + for(int y=0; y<8; y++) + { + for(int x=0; x<32; x++) + { + assert(cwin_getat_char_raw(&cw, x, y) == x + 32 * y); + } + } + + return 0; +} diff --git a/include/c64/charwin.c b/include/c64/charwin.c index dca0e90..7e8e1bd 100644 --- a/include/c64/charwin.c +++ b/include/c64/charwin.c @@ -254,6 +254,32 @@ char cwin_put_string(CharWin * win, const char * str, char color) return n; } + +void cwin_put_char_raw(CharWin * win, char ch, char color) +{ + cwin_putat_char_raw(win, win->cx, win->cy, ch, color); + win->cx++; + if (win->cx == win->wx) + { + win->cx = 0; + win->cy++; + } +} + +void cwin_put_chars_raw(CharWin * win, const char * chars, char num, char color) +{ + cwin_putat_chars_raw(win, win->cx, win->cy, chars, color); + win->cx += num; + if (win->cx >= win->wx) + { + win->cx = 0; + win->cy++; + } +} + + + + void cwin_putat_char(CharWin * win, char x, char y, char ch, char color) { int offset = mul40[y] + x; @@ -303,6 +329,35 @@ char cwin_putat_string(CharWin * win, char x, char y, const char * str, char col #pragma native(cwin_putat_string) +void cwin_putat_char_raw(CharWin * win, char x, char y, char ch, char color) +{ + int offset = mul40[y] + x; + + win->sp[offset] = ch; + win->cp[offset] = color; +} + +#pragma native(cwin_putat_char_raw) + +void cwin_putat_chars_raw(CharWin * win, char x, char y, const char * chars, char num, char color) +{ + int offset = mul40[y] + x; + + char * sp = win->sp + offset; + char * cp = win->cp + offset; + + for(char i=0; isp + mul40[y] + x; @@ -310,6 +365,8 @@ char cwin_getat_char(CharWin * win, char x, char y) return s2p(*sp); } +#pragma native(cwin_getat_char) + void cwin_getat_chars(CharWin * win, char x, char y, char * chars, char num) { char * sp = win->sp + mul40[y] + x; @@ -320,6 +377,28 @@ void cwin_getat_chars(CharWin * win, char x, char y, char * chars, char num) } } +#pragma native(cwin_getat_chars) + +char cwin_getat_char_raw(CharWin * win, char x, char y) +{ + char * sp = win->sp + mul40[y] + x; + + return *sp; +} + +#pragma native(cwin_getat_char_raw) + +void cwin_getat_chars_raw(CharWin * win, char x, char y, char * chars, char num) +{ + char * sp = win->sp + mul40[y] + x; + + for(char i=0; i