Please use this as a resource for your ascii/vt100 coding, :-)
Change for your target and memory map.
Settings: Teraterm: vt100, font: consolas, 9600, n, 8, 2 , receive: auto, transmit: any, local echo: any
Assumes monitor cin and cout functions exist in ROM, called seamlessly.
textcharlist.c (in RAM, 8000-FFFFH
Code: Select all
#include <stdio.h>
// Custom function to determine if a character is printable (ASCII 32-126)
int is_custom_printable(int ch) {
return (ch >= 32 && ch <= 126);
}
int main() {
// Print multiple CRLF lines at the beginning for a clean terminal display
for (int i = 0; i < 11; i++) {
printf("\r\n");
}
// Print the header for the ASCII section
printf("ASCII Test Pattern (32 to 126):\n");
printf("Dec | Char\n");
printf("-----------\n");
// Print the ASCII test pattern from 32 to 126
for (int i = 32; i < 127; i++) {
// Use the custom function to check if the character is printable
char display_char = is_custom_printable(i) ? i : '.';
// Print the ASCII code and its corresponding character or placeholder
printf("%3d | %c\n", i, display_char);
}
// Print a separator between sections
printf("\n");
// Print a header for the UTF-8 extended character output
printf("UTF-8 Extended Characters (128 to 255):\n");
printf("Dec | UTF-8 | Hex\n");
printf("-------------------------\n");
// Loop through the values 128 to 255
for (int i = 128; i <= 255; i++) {
// Prepare the UTF-8 encoded character as a string
char utf8_char[3] = {0}; // Two bytes plus null terminator
if (i <= 191) {
utf8_char[0] = (char)0xC2;
utf8_char[1] = (char)i;
} else {
utf8_char[0] = (char)0xC3;
utf8_char[1] = (char)(i - 64);
}
// Print the UTF-8 encoded character and its code point
printf("%3d | %s | 0x%02X\n", i, utf8_char, i);
}
// Print a separator between sections
printf("\n");
// Print a header for the DEC Special Graphics characters
printf("DEC Special Graphics Characters (32 to 127):\n");
printf("Dec | Char\n");
printf("-----------\n");
// Switch to DEC Special Graphics Mode
printf("\033(0");
// Print the DEC SG characters from 32 to 127
for (int i = 32; i < 128; i++) {
printf("%3d | %c\n", i, i);
}
// Switch back to US ASCII Mode
printf("\033(B");
// Ensure a final newline for terminal neatness
printf("\n");
return 0;
}
Code: Select all
#include <stdio.h>
int fputc_cons_native(char c) __naked
{
__asm
pop b ;return address
pop h ;character to print in l
push h
push b
MOV a,l
MOV c,a
call $0006 ; replace with your address, outputs a char
ret
__endasm;
}
int fgetc_cons() __naked
{
__asm
call $0031 ; replace with your address, gets a char
mov l,a ;Return the result in hl
mvi h,0
ret
__endasm;
}
Code: Select all
zcc +z80 -clib=8085 textcharlist.c monitor.c -pragma-define:CRT_ORG_CODE=0x8000 -pragma-define:REGISTER_SP=0xFFFE -m -create-app
Cheers,
Andrew