diff --git a/tests/banktest/Makefile b/tests/banktest/Makefile new file mode 100644 index 0000000..c19eca1 --- /dev/null +++ b/tests/banktest/Makefile @@ -0,0 +1,11 @@ +# Build banked.exe — HUGE memory mode (small + banked code in W3). +# +# Layout: +# CODE/HOME at 0x4100 (W1), DATA at 0x8000 (W2), banks at 0x{N}C000 (W3). +# crt0_banked.s loads N banks from the .EXE before calling main. + +PROJ_ROOT := $(abspath $(CURDIR)/../..) +EXAMPLE := banked +MEMORY := huge +EXTRA_FLAGS := --bank 1=bank1.c --bank 2=bank2.c +include $(PROJ_ROOT)/app.mk diff --git a/tests/banktest/bank1.c b/tests/banktest/bank1.c new file mode 100644 index 0000000..a742a9c --- /dev/null +++ b/tests/banktest/bank1.c @@ -0,0 +1,18 @@ +#include +#include +#include + +uint16_t bank1var = 0; +extern uint16_t bank2var; + +void bank1_func(void) __banked +{ + printf("BANK1: hello from the first bank, phys page = 0x%02X, var = %u\n", _io_page_w3, bank1var); +} + +void bank1_func2(uint16_t x) __banked +{ + printf("BANK1: hello from the first bank, phys page = 0x%02X, set var in SECOND bank to %u\n", _io_page_w3, x); + bank2var = x; +} + diff --git a/tests/banktest/bank2.c b/tests/banktest/bank2.c new file mode 100644 index 0000000..60e0bd5 --- /dev/null +++ b/tests/banktest/bank2.c @@ -0,0 +1,11 @@ +#include +#include +#include + +uint16_t bank2var = 0; + +void bank2_func(void) __banked +{ + printf("BANK2: hello from the second bank, phys page = 0x%02X, var = %u\n", _io_page_w3, bank2var); +} + diff --git a/tests/banktest/banked.c b/tests/banktest/banked.c new file mode 100644 index 0000000..58188ad --- /dev/null +++ b/tests/banktest/banked.c @@ -0,0 +1,34 @@ +#include +#include +#include + +/* crt0_banked.s reads this constant to know how many banks to load. */ +const uint8_t n_banks = 2; + +void bank1_func(void) __banked; +void bank2_func(void) __banked; +void bank1_func2(uint16_t) __banked; + +extern uint16_t bank1var; +extern uint16_t bank2var; + +extern uint8_t bank_pages[]; /* filled by crt0_banked.s */ + +int main(void) +{ + bank1var = 1; + bank2var = 2; + puts("HOME: program start."); + printf("HOME: window 3 phys page = 0x%02X\n", _io_page_w3); + printf("HOME: bank_pages[1] = 0x%02X\n", bank_pages[1]); + printf("HOME: bank_pages[2] = 0x%02X\n", bank_pages[2]); + + bank1_func(); + bank2_func(); + bank1_func2(25); + bank2_func(); + + puts("Press any key to exit..."); + (void)getchar(); + return 0; +} diff --git a/tests/hello2/Makefile b/tests/hello2/Makefile new file mode 100644 index 0000000..1ba04f7 --- /dev/null +++ b/tests/hello2/Makefile @@ -0,0 +1,5 @@ +# Build hello.exe — uses lib/sprinter.lib in TINY memory mode. + +PROJ_ROOT := $(abspath $(CURDIR)/../..) +EXAMPLE := hello2 +include $(PROJ_ROOT)/app.mk diff --git a/tests/hello2/hello2.c b/tests/hello2/hello2.c new file mode 100644 index 0000000..6583bfe --- /dev/null +++ b/tests/hello2/hello2.c @@ -0,0 +1,82 @@ +/* + * hello — smoke test for the two output APIs: + * + * stdio (printf/puts/putchar) — FAST, no attribute (ambient colour) + * conio (cprintf/cputs/putch) — SLOWER, applies textcolor/textbackground + * + * Demonstrates textcolor/textbackground (Turbo-C-compatible names). + */ + +#include +#include +#include +#include +#include +#include + +int main(void) +{ + errno = -1; + int16_t a0 = 0, a1 = 0; + a0 = get_text_attr(); + + uint8_t vMode = gettextmode(); + settextmode(TEXT_MODE_80x32); + + /* Wipe the screen with a known attribute so stdio printf/puts inherit + * a clean colour for the cursor. */ + clrscr_attr(COLOR(COLOR_LIGHTGRAY, COLOR_BLACK)); + + /* --- stdio set: fast, no attribute ------------------------------- */ + puts("hello (stdio) - fast PCHARS, ambient colour"); + printf("printf: a0=%d (initial attr)\n", a0); + + /* --- conio set: applies textcolor / textbackground --------------- */ + textcolor(COLOR_YELLOW); + textbackground(COLOR_BLUE); + cputs("conio: yellow on blue\r\n"); + + printf("printf: a0=%d (initial attr)\n", a0); + + textcolor(COLOR_LIGHTRED); + textbackground(COLOR_BLACK); + cprintf("cprintf %d %d %s\r\n", 42, -7, "args"); + + printf("printf: a0=%d (initial attr)\n", a0); + + /* set_text_attr / textattr replace the whole byte. */ + textattr(COLOR(COLOR_LIGHTGREEN, COLOR_BLACK)); + cputs("conio: light-green via textattr\r\n"); + + printf("printf: a0=%d (initial attr)\n", a0); + + /* Opting out of attribute control — conio falls back to fast path. */ + set_text_attr(KEEP_EXIST_ATTR); + cputs("conio with KEEP_EXIST_ATTR (fast path)\r\n"); + + printf("printf: a0=%d (initial attr)\n", a0); + + a1 = get_text_attr(); + + printf("printf: a0=%d (initial attr)\n", a0); + + /* Back to a normal attribute so the goodbye reads cleanly. */ + textattr(COLOR(COLOR_LIGHTCYAN, COLOR_BLACK)); + + printf("printf: a0=%d (initial attr)\n", a0); + + cprintf("a0=%d a1=%d now=%d errno=%d\n\r", + a0, a1, get_text_attr(), errno); + // cprintf("a0=%d a1=%d", + // a0, a1); + // cprintf(" now=%d errno=%d\n\r", + // get_text_attr(), errno); +#ifdef DEBUG_RT + printf("w2_self_allocated = %u\n", w2_self_allocated); +#endif + cputs("Press any key to exit..."); + + (void)getchar(); + settextmode(vMode); + return 0; +} diff --git a/tests/simple/Makefile b/tests/simple/Makefile new file mode 100644 index 0000000..b8fe6a3 --- /dev/null +++ b/tests/simple/Makefile @@ -0,0 +1,5 @@ +# Build hello.exe — uses lib/sprinter.lib in TINY memory mode. + +PROJ_ROOT := $(abspath $(CURDIR)/../..) +EXAMPLE := simple +include $(PROJ_ROOT)/app.mk diff --git a/tests/simple/simple.c b/tests/simple/simple.c new file mode 100644 index 0000000..834e838 --- /dev/null +++ b/tests/simple/simple.c @@ -0,0 +1,46 @@ +/* + * hello — smoke test for the two output APIs: + * + * stdio (printf/puts/putchar) — FAST, no attribute (ambient colour) + * conio (cprintf/cputs/putch) — SLOWER, applies textcolor/textbackground + * + * Demonstrates textcolor/textbackground (Turbo-C-compatible names). + */ + +#include +#include +#include +#include +#include +#include + +static uint8_t buff[] = {0xE4, 0x1B}; + +uint8_t get_style(uint32_t idx) { + return (uint8_t)((buff[idx >> 2] >> ((idx & 3) << 1)) & 3u); +} + +void set_style(uint32_t idx, uint8_t style) { + buff[idx >> 2] = buff[idx >> 2] & ~(3u << ((idx & 3) << 1)) | ((style & 3u) << ((idx & 3) << 1)); +} + +int main(void) +{ + for(int i = 0; i < 8; i++) { + dec8(get_style(i)); + puts(""); + } + + for(int i = 0; i < 8; i++) { + set_style(i, (i + 1) & 3); + } + puts(""); + for(int i = 0; i < 8; i++) { + dec8(get_style(i)); + puts(""); + } + + cputs("Press any key to exit..."); + (void)getchar(); + return 0; +}