Skip to content

Commit 6f7d6fd

Browse files
Added loadfont and fontctl utilities
1 parent 2a7b18c commit 6f7d6fd

File tree

8 files changed

+649
-7
lines changed

8 files changed

+649
-7
lines changed

Makefile

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
ASM=ez80asm
22

33
.PHONY: binaries
4-
binaries: mos/memfill.bin mos/more.bin mos/font.bin mos/comp.bin mos/nano.bin
4+
binaries: mos/memfill.bin mos/more.bin mos/font.bin mos/fontctl.bin mos/comp.bin mos/nano.bin bin/loadfont.bin
55

66
mos/memfill.bin: memfill.asm *.inc
77
$(ASM) $< $@
@@ -12,8 +12,17 @@ mos/more.bin: more.asm *.inc
1212
mos/font.bin: font.asm *.inc
1313
$(ASM) $< $@
1414

15+
mos/fontctl.bin: fontctl.asm *.inc
16+
$(ASM) $< $@
17+
1518
mos/comp.bin: comp.asm *.inc
1619
$(ASM) $< $@
1720

1821
mos/nano.bin: nano.asm *.inc
1922
$(ASM) $< $@
23+
24+
bin/loadfont.bin: loadfont/src/*.[ch]
25+
mkdir -p bin
26+
cd loadfont;make;mv bin/loadfont.bin ../bin
27+
28+

README.md

+68-6
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,15 @@ The project will include an editor some day. All are MOS commands, all are writt
66
Parts of the code are based on the repository https://github.com/breakintoprogram/agon-projects
77

88
The projects are built with ez80asm
9-
(https://github.com/envenomator/agon-ez80asm). Under Linux,
10-
make sure to have ez80asm in your path and you can just run make to
11-
build the utilities.
9+
(https://github.com/envenomator/agon-ez80asm) and AgDev
10+
(https://github.com/pcawte/AgDev). Under Linux, make sure to have a
11+
driectory containing ez80asm and the binary directory of AgDev in your
12+
path and you can just run make to build the utilities.
13+
14+
All pre-assembled and precompiled binaries are also provided. The
15+
`loadfont' program must be in the `bin' directory and the other
16+
binaries in the `mos' directory. Assumed is Agon Console8 MOS-2.23 and
17+
VDP-2.8.0.
1218

1319
Note: the copy utility has been removed because it is now an internal command in MOS.
1420

@@ -52,9 +58,65 @@ Three fonts are included:
5258
the bytes bit-reversed compared to what we need, so I changed it to the right format. It does not look pretty, but it's a start.
5359
https://github.com/dhepper/font8x8
5460

55-
You can check out https://github.com/epto/epto-fonts
56-
The `*.font` files included in the project contain meta-information, but they start with the bitmap data in a form that the font utility can use.
57-
The 8x8 fonts from this set, you can just load with the font utility. It ignores the meta data. Some of them are only ASCII, some of them have code page 437 fonts.
61+
You can check out https://github.com/epto/epto-fonts The `*.font`
62+
files included in the project contain meta-information, but they start
63+
with the bitmap data in a form that the font utility can use. The 8x8
64+
fonts from this set, you can just load with the font utility. It
65+
ignores the meta data. Some of them are only ASCII, some of them have
66+
code page 437 fonts. This program is superseded by the `loadfont' and
67+
`fontctl' programs.
68+
69+
### loadfont
70+
71+
This program uses the new font commands of VDP-2.8.0. It can load raw
72+
binary fonts (like the font program does) and PSF fonts as used by the
73+
Linux console.
74+
75+
Example:
76+
`loadfont 10 Lat15-Fixed16.psf'
77+
78+
The first parameter is a buffer ID, a number in the range 0..65534. Instead
79+
we can use the word `sys' to select the system font. The system font can
80+
only be loaded with 8x8 characters, while many font sizes are supported
81+
with PSF files. An optional third parameter on the command line specifies
82+
a code page. Currently supported code pages are CP1252 and CP437.
83+
84+
If a PSF font has a Unicode table, it will be used to place the glyphs
85+
of the font at the appropriate code points in the code page. Instead
86+
of a code page we can specify `none' for no translation and `upper' to
87+
load the upper 256 characters of a 512-character PSF font. Note that
88+
most PSF fonts with Latin-1 or Windows-1252 support have many of the
89+
non-ASCII characters at different positions, therefore the Unicode
90+
table will be needed.
91+
92+
Example:
93+
`loadfont 11 Lat15-terminus20x10.psf cp437'
94+
95+
Usable psf fonts can be found here
96+
https://www.zap.org.au/projects/console-fonts-zap/ and in the
97+
`/usr/share/consolefonts" directory of a Linux system (gunzip
98+
compressed psf files first). Also the terminus-fonts package can be
99+
used.
100+
101+
### fontctl
102+
103+
This program selects a font, previously loaded by the `loadfont' command.
104+
105+
Example:
106+
`fontctl 11'
107+
108+
The parameter is a buffer ID, the same as used with `loadfont'. The
109+
word `sys' can be used instead to select the system font.
110+
111+
A second parameter `show' can be used to show all 256 characters of the font.
112+
Instead, `clear' canb e used to remove the font and it s buffer.
113+
114+
Example:
115+
`font 11 clear'
116+
selectsfont 11 and shows it.
117+
118+
`font 11 clear'
119+
clears font 11.
58120

59121
### nano
60122

bin/loadfont.bin

14.5 KB
Binary file not shown.

fontctl.asm

+166
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
;
2+
; Title: Memfill - Main
3+
; Author: Lennart Benschop
4+
; Created: 19/04/2024
5+
6+
.ASSUME ADL = 1
7+
INCLUDE "mos_api.inc"
8+
ORG $b0000 ; Is a moslet
9+
10+
MACRO PROGNAME
11+
ASCIZ "fontctl.bin"
12+
ENDMACRO
13+
14+
include "init.inc"
15+
include "parse.inc"
16+
17+
18+
; This program selects a font previously loaded to a buffer or the system
19+
; font. With the show parameter it can show all characters in the font.
20+
; With the clear parameter it clears the font from teh buffer.
21+
; (clearing the system font) will reset the default font.
22+
;
23+
; fontctl sys
24+
; fontctl <num>
25+
; fontctl <num< show
26+
; fontctl <num> clear
27+
28+
;
29+
; The main routine
30+
; IXU: argv - pointer to array of parameters
31+
; C: argc - number of parameters
32+
; Returns:
33+
; HL: Error code, or 0 if OK
34+
;
35+
_main: LD A, C
36+
PUSH BC
37+
CP #2
38+
JR NC, main1
39+
LD HL, s_USAGE ; Number of args not 3 or 4, print usage string and exit
40+
CALL PRSTR
41+
POP BC
42+
LD HL, 19
43+
RET
44+
main1: LD HL, (IX+3) ; first parameter, bufid.
45+
LD A, (HL)
46+
CALL UPPRC
47+
CP 'S' ; Assume it's sys
48+
JR Z, main2
49+
CALL ASC_TO_NUMBER
50+
JR main3
51+
main2: LD DE, $FFFF ; Use 65535 for sys
52+
main3: POP BC
53+
LD A, C
54+
CP 3
55+
JR C, main4
56+
LD HL, (IX+6) ; second parameter, leng
57+
LD A, (HL)
58+
CALL UPPRC
59+
CP 'C' ; Assume it's clear.
60+
JR Z, do_clear
61+
main4: LD C, A ; Save second cmdline param.
62+
LD A, 23 ; Select the font.
63+
RST.L 10h
64+
XOR A
65+
RST.L 10h
66+
LD A,95h
67+
RST.L 10h
68+
XOR A
69+
RST.L 10h
70+
LD A, E
71+
RST.L 10h
72+
LD A, D
73+
RST.L 10h
74+
XOR A
75+
RST.L 10h
76+
; Font selected.
77+
LD A, C
78+
CP 'S' ; Was the second param 'show'?
79+
JR NZ, main_end
80+
; Show the font.
81+
LD E, 0
82+
LD C, 8
83+
show_loop: LD A, 13
84+
RST.L 10h
85+
LD A, 10
86+
RST.L 10h
87+
LD B, 32
88+
@@: lD A, E
89+
CP 127
90+
CALL Z, do_escape
91+
CP 32
92+
CALL C, do_escape
93+
RST.L 10h
94+
INC E
95+
DJNZ @B
96+
DEC C
97+
JR NZ, show_loop
98+
LD A, 13
99+
RST.L 10h
100+
LD A, 10
101+
RST.L 10h
102+
main_end: ; End with no error
103+
LD HL, 0
104+
RET
105+
do_clear: ; Clear the font.
106+
LD A, E
107+
AND D
108+
INC A
109+
JR Z, do_clear_sys ; Use special case for system font
110+
LD A, 23
111+
RST.L 10h
112+
XOR A
113+
RST.L 10h
114+
LD A,95h
115+
RST.L 10h
116+
LD A,4
117+
RST.L 10h
118+
LD A, E
119+
RST.L 10h
120+
LD A, D
121+
RST.L 10h ; Clear the font
122+
LD A, 23
123+
RST.L 10h
124+
XOR A
125+
RST.L 10h
126+
LD A,A0h
127+
RST.L 10h
128+
LD A, E
129+
RST.L 10h
130+
LD A, D
131+
RST.L 10h
132+
LD A,2
133+
RST.L 10h ; Clear the buffer
134+
JR main_end
135+
do_clear_sys: ; Clear (rest) system font.
136+
LD A, 23
137+
RST.L 10h
138+
XOR A
139+
RST.L 10h
140+
LD A,91h
141+
RST.L 10h
142+
JR main_end
143+
144+
; Print a zero-terminated string
145+
; Parameters:
146+
; HL: Address of string (24-bit pointer)
147+
;
148+
PRSTR: LD A,(HL)
149+
OR A
150+
RET Z
151+
RST.L 10h
152+
INC HL
153+
JR PRSTR
154+
155+
do_escape: PUSH AF
156+
LD A, 27
157+
RST.L 10h
158+
POP AF
159+
RET
160+
161+
; Text messages
162+
;
163+
s_USAGE: DB "Usage: fontctl <bufid>|sys [show|claar]\r\n", 0
164+
165+
; RAM
166+
;

loadfont/Makefile

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# ----------------------------
2+
# Makefile Options
3+
# ----------------------------
4+
5+
NAME = loadfont
6+
ICON = icon.png
7+
DESCRIPTION = "Utility to load fonts"
8+
COMPRESSED = NO
9+
ARCHIVED = NO
10+
INIT_LOC = 040000
11+
BSSHEAP_LOW = 050000
12+
BSSHEAP_HIGH = 0B7FFF
13+
STACK_HIGH = 0B7FFF
14+
15+
CFLAGS = -Werror -Wall -Wextra -Oz -DCEDEV
16+
CXXFLAGS = -Werror -Wall -Wextra -Oz - DCEDEV
17+
LDHAS_EXIT_HANDLER:=0
18+
# ----------------------------
19+
20+
include $(shell cedev-config --makefile)
21+

loadfont/src/codepages.h

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
codepages for loadfont
3+
CP437 and CP1215
4+
*/
5+
6+
7+
const uint16_t codepage_1252[] = {
8+
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
9+
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
10+
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
11+
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
12+
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027,
13+
0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f,
14+
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
15+
0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f,
16+
0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
17+
0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f,
18+
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,
19+
0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f,
20+
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,
21+
0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f,
22+
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,
23+
0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x0000,
24+
0x20ac, 0x0000, 0x201a, 0x0192, 0x201e, 0x2026, 0x2020, 0x2021,
25+
0x2c06, 0x2030, 0x0160, 0x2039, 0x0152, 0x0000, 0x017d, 0x0000,
26+
0x0000, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014,
27+
0x02dc, 0x2122, 0x0161, 0x203a, 0x0153, 0x0000, 0x017e, 0x0178,
28+
0x00a0, 0x00a1, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7,
29+
0x00a8, 0x00a9, 0x00aa, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af,
30+
0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x00b6, 0x00b7,
31+
0x00b8, 0x00b9, 0x00ba, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x00bf,
32+
0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7,
33+
0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf,
34+
0x00d0, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7,
35+
0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x00de, 0x00df,
36+
0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7,
37+
0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef,
38+
0x00f0, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7,
39+
0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x00ff,
40+
};
41+
42+
const uint16_t codepage_437[] = {
43+
0x0000, 0x263a, 0x263b, 0x2665, 0x2666, 0x2663, 0x2660, 0x2022,
44+
0x25d8, 0x25cb, 0x25d9, 0x2642, 0x2640, 0x266a, 0x266b, 0x263c,
45+
0x25ba, 0x25c4, 0x2195, 0x203c, 0x00b6, 0x00a7, 0x25ac, 0x21a8,
46+
0x2191, 0x2193, 0x2192, 0x2190, 0x221f, 0x2194, 0x25b2, 0x25bc,
47+
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027,
48+
0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f,
49+
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
50+
0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f,
51+
0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
52+
0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f,
53+
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,
54+
0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f,
55+
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,
56+
0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f,
57+
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,
58+
0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x2302,
59+
0x00c7, 0x00fc, 0x00e9, 0x00e2, 0x00e4, 0x00e0, 0x00e5, 0x00e7,
60+
0x00ea, 0x00eb, 0x00e8, 0x00ef, 0x00ee, 0x00ec, 0x00c4, 0x00c5,
61+
0x00c9, 0x00e6, 0x00c6, 0x00f4, 0x00f6, 0x00f2, 0x00fb, 0x00f9,
62+
0x00ff, 0x00d6, 0x00dc, 0x00a2, 0x00a3, 0x00a5, 0x20a7, 0x0192,
63+
0x00e1, 0x00ed, 0x00f3, 0x00fa, 0x00f1, 0x00d1, 0x00aa, 0x00ba,
64+
0x00bf, 0x2310, 0x00ac, 0x00bd, 0x00bc, 0x00a1, 0x00ab, 0x00bb,
65+
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556,
66+
0x2555, 0x2563, 0x2551, 0x2557, 0x255d, 0x255c, 0x255b, 0x2510,
67+
0x2514, 0x2534, 0x252c, 0x251c, 0x2500, 0x253c, 0x255e, 0x255f,
68+
0x255a, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256c, 0x2567,
69+
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256b,
70+
0x256a, 0x2518, 0x250c, 0x2588, 0x2584, 0x258c, 0x2590, 0x2580,
71+
0x03b1, 0x00df, 0x0393, 0x03c0, 0x03a3, 0x03c3, 0x00b5, 0x03c4,
72+
0x03a6, 0x0398, 0x03a9, 0x03b4, 0x221e, 0x03c6, 0x03b5, 0x2229,
73+
0x2261, 0x00b1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00f7, 0x2248,
74+
0x00b0, 0x2219, 0x00b7, 0x221a, 0x207f, 0x00b2, 0x25a0, 0x00a0,
75+
};

0 commit comments

Comments
 (0)