From e758110f6135bd10cf4266fa5c4ec5517d306f7f Mon Sep 17 00:00:00 2001 From: mrdudz Date: Mon, 13 Jul 2020 17:00:17 +0200 Subject: [PATCH] added testcode to check petscii char mapping, related to issue #988 --- testcode/lib/cbm/Makefile | 39 ++++++++++++++++++ testcode/lib/cbm/petscii.c | 82 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+) create mode 100644 testcode/lib/cbm/Makefile create mode 100644 testcode/lib/cbm/petscii.c diff --git a/testcode/lib/cbm/Makefile b/testcode/lib/cbm/Makefile new file mode 100644 index 000000000..5217f0cc6 --- /dev/null +++ b/testcode/lib/cbm/Makefile @@ -0,0 +1,39 @@ +# Run 'make SYS='; or, set a SYS env. +# var. to build for another target system. +SYS ?= c64 + +# Just the usual way to find out if we're +# using cmd.exe to execute make rules. +ifneq ($(shell echo),) + CMD_EXE = 1 +endif + +ifdef CMD_EXE + NULLDEV = nul: + DEL = -del /f + RMDIR = rmdir /s /q +else + NULLDEV = /dev/null + DEL = $(RM) + RMDIR = $(RM) -r +endif + +ifdef CC65_HOME + AS = $(CC65_HOME)/bin/ca65 + CC = $(CC65_HOME)/bin/cc65 + CL = $(CC65_HOME)/bin/cl65 + LD = $(CC65_HOME)/bin/ld65 +else + AS := $(if $(wildcard ../../../bin/ca65*),../../../bin/ca65,ca65) + CC := $(if $(wildcard ../../../bin/cc65*),../../../bin/cc65,cc65) + CL := $(if $(wildcard ../../../bin/cl65*),../../../bin/cl65,cl65) + LD := $(if $(wildcard ../../../bin/ld65*),../../../bin/ld65,ld65) +endif + +all: petscii.prg + +petscii.prg: petscii.c + $(CL) -t $(SYS) -O -o petscii.prg petscii.c + +clean: + $(DEL) petscii.prg diff --git a/testcode/lib/cbm/petscii.c b/testcode/lib/cbm/petscii.c new file mode 100644 index 000000000..60a12b18b --- /dev/null +++ b/testcode/lib/cbm/petscii.c @@ -0,0 +1,82 @@ + +/* this program prints all available "petscii" characters to screen, once + using putchar (which wraps to kernal i/o) and once using conio (which + will do direct videoram access). after that the produced screencodes + are compared (they should match) (related to issue #988 */ + +#include +#include +#include +#include + +#if defined(__C64__) +#define VRAMPEEK(x) (*(char*)(0x0400 + (x))) +#define CRAMPOKE(x, y) *(char*)(0xd800 + (x)) = (y) +#else +#error "this target is not supported yet" +#endif + +unsigned char x, y, c; +unsigned char c1, c2; +unsigned char *p1, *p2; + +int err = 0; + +int main(void) +{ + clrscr(); + bgcolor(COLOR_BLACK); + bordercolor(COLOR_BLACK); + + /* output all characters using putchar() */ + c = 0; + for (y = 0; y < 16; y++) { + for (x = 0; x < 16; x++) { + /* skip the codes that are unprintable control codes */ + if (!((c < 32) || ((c > 127) && (c < 160)))) { + gotoxy(x, y); putchar(c); + } + c++; + } + } + + /* output all characters using conio */ + c = 0; + for (y = 0; y < 16; y++) { + for (x = 0; x < 16; x++) { + /* skip the codes that are unprintable control codes */ + if (!((c < 32) || ((c > 127) && (c < 160)))) { + gotoxy(x + 20, y); cputc(c); + } + c++; + } + } + + /* compare the two outputs */ + for (y = 0; y < 16; y++) { + for (x = 0; x < 16; x++) { + c1 = VRAMPEEK((y * 40) + x); + c2 = VRAMPEEK((y * 40) + x + 0x14); + if (c1 == c2) { + c = COLOR_GREEN; + } else { + c = COLOR_RED; + err = 1; + } + CRAMPOKE((y * 40) + x, c); + CRAMPOKE((y * 40) + x + 0x14, c); + } + } + + /* show the result */ + textcolor(COLOR_WHITE); + gotoxy(0, 17); + if (err) { + bordercolor(COLOR_RED); + cputs("errors detected"); + } else { + bordercolor(COLOR_GREEN); + cputs("all fine"); + } + return 0; +}