tests: add hello2, simple, banktest smoke tests

hello2 — stdio vs conio output API comparison (fast/no-attr vs
slower/attributed), also exercises textcolor/textbackground.
simple — packed 2-bit style array bit-twiddling smoke test.
banktest — __banked function calls across two explicit banks in huge
memory mode.

hello2.c updated to call the renamed gettextmode/settextmode (see the
conio rename in 5e5e70d).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-23 17:12:19 +03:00
parent 8cfdcf307a
commit 1b39a60ff0
8 changed files with 212 additions and 0 deletions
+11
View File
@@ -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
+18
View File
@@ -0,0 +1,18 @@
#include <stdio.h>
#include <stdint.h>
#include <sprinter.h>
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;
}
+11
View File
@@ -0,0 +1,11 @@
#include <stdio.h>
#include <stdint.h>
#include <sprinter.h>
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);
}
+34
View File
@@ -0,0 +1,34 @@
#include <stdio.h>
#include <stdint.h>
#include <sprinter.h>
/* 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;
}
+5
View File
@@ -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
+82
View File
@@ -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 <stdio.h>
#include <conio.h>
#include <gfx.h>
#include <sprinter.h>
#include <sprinter_exit.h>
#include <errno.h>
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;
}
+5
View File
@@ -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
+46
View File
@@ -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 <stdio.h>
#include <conio.h>
#include <gfx.h>
#include <sprinter.h>
#include <sprinter_exit.h>
#include <errno.h>
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;
}