From 904ab244befac5dd3cd3727b8cbeb57486ebe1db Mon Sep 17 00:00:00 2001 From: Kyle J Cardoza Date: Fri, 12 Jul 2024 02:55:55 -0400 Subject: [PATCH] Added VERA font --- .gitignore | 3 + Makefile | 3 +- bin/makechrom | 52 ++++++++++++++++++ config/config.mk | 13 ++++- config/kernel.mk | 10 +++- config/kernel.scm | 4 +- include/macros.h | 2 - src/kernel/cstartup.s | 4 -- src/kernel/hardware/vera/vera_font.s | 10 ++++ .../{ => hardware/vera}/vera_font_0.ase | Bin 10 files changed, 88 insertions(+), 13 deletions(-) create mode 100644 .gitignore create mode 100755 bin/makechrom create mode 100644 src/kernel/hardware/vera/vera_font.s rename src/kernel/{ => hardware/vera}/vera_font_0.ase (100%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c6ee211 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.vscode/** +*.bin +*.o diff --git a/Makefile b/Makefile index 117f3f5..c88cded 100755 --- a/Makefile +++ b/Makefile @@ -24,7 +24,8 @@ clean: -name '*.lst' \ \) -delete @find src -type f \( \ - -name '*.o' \ + -name '*.o' -o \ + -name '*.bin' \ \) -delete .PHONY: flash diff --git a/bin/makechrom b/bin/makechrom new file mode 100755 index 0000000..2a37f24 --- /dev/null +++ b/bin/makechrom @@ -0,0 +1,52 @@ +#!/usr/bin/env python3 + +import sys, traceback +from PIL import Image + +flip_d = False + +if len(sys.argv)<2: + print('ERROR: Please specify at least one file to convert!') + print('Note: character size is calculated based on resolution assuming 16x16 grid.\n') + +for i in range(len(sys.argv)-1): + if sys.argv[i+1][:1]!='-': + continue + if sys.argv[i+1]=='-f': + flip_d = True + +for i in range(len(sys.argv)-1): + if sys.argv[i+1][:1]=='-': + continue + try: + print(f'Processing "{sys.argv[i+1]}"...') + img = Image.open(sys.argv[i+1]) + width, height = img.size + cw = width>>4 + ch = height>>4 + print(f'({width},{height}) => char({cw},{ch})') + pixels = img.load() + f = open(f'{sys.argv[i+1]}.bin','wb') + ba = bytearray() + for y in range(16): + for x in range(16): + for py in range(ch): + outbyte = 0 + for px in range(cw): + if flip_d: + outbyte = outbyte << 1 + if pixels[(x*cw)+px,(y*ch)+py]>0: + if flip_d: + outbyte = outbyte | 1 + else: + outbyte = outbyte | (1<<(px&7)) + if (px&7)==7: + ba.append(outbyte) + outbyte=0 + f.write(ba) + f.close() + + except Exception as e: + print(f'Exception caught!\n"{traceback.format_exc()}"') + +print('Task completed.\n') diff --git a/config/config.mk b/config/config.mk index 2cf8046..fa4be15 100755 --- a/config/config.mk +++ b/config/config.mk @@ -15,7 +15,8 @@ CFLAGS := -I include \ --strong-inline \ --force-switch jump-table -ASFLAGS := -I include \ +ASFLAGS := -I . \ + -I include \ --code-model=large \ --data-model=huge @@ -60,4 +61,12 @@ endif %.o: %.s @echo "Assembling $@..." - @$(AS) $(ASFLAGS) -o $@ $< \ No newline at end of file + @$(AS) $(ASFLAGS) -o $@ $< + +.SUFFIXES: .png .bin .ase +%.png: %.ase + aseprite -b $< -save-as $@ + +%.bin: %.png + bin/makechrom -f $< + mv $<.bin $@ diff --git a/config/kernel.mk b/config/kernel.mk index f50b114..bca26a9 100755 --- a/config/kernel.mk +++ b/config/kernel.mk @@ -3,18 +3,26 @@ KERNEL_ASM_SRC := $(wildcard src/kernel/*.s) \ $(wildcard src/kernel/*/*/*.s) \ $(wildcard src/kernel/*/*/*/*.s) \ $(wildcard src/kernel/*/*/*/*.s) + KERNEL_C_SRC := $(wildcard src/kernel/*.c) \ $(wildcard src/kernel/*/*.c) \ $(wildcard src/kernel/*/*/*.c) \ $(wildcard src/kernel/*/*/*/*.c) \ $(wildcard src/kernel/*/*/*/*/*.c) + +FONT_SOURCES := $(wildcard src/kernel/hardware/vera/vera_font_*.ase) KERNEL_OBJ := $(KERNEL_ASM_SRC:.s=.o) KERNEL_OBJ += $(KERNEL_C_SRC:.c=.o) +FONTS := $(FONT_SOURCES:.ase=.bin) + KERNEL_LDFLAGS := --list-file build/kernel.lst build/kernel.bin: $(KERNEL_OBJ) echo "Linking $@..." + echo "$(FONTS)" $(LD) -o $@ config/kernel.scm $(LDFLAGS) $(KERNEL_LDFLAGS) $^ - mv build/kernel.raw $@ \ No newline at end of file + mv build/kernel.raw $@ + +src/kernel/hardware/vera/vera_font.o: $(FONTS) \ No newline at end of file diff --git a/config/kernel.scm b/config/kernel.scm index 69f41ab..454f8c1 100755 --- a/config/kernel.scm +++ b/config/kernel.scm @@ -23,11 +23,9 @@ (section (low_rom #xC08000)) (section code) (section farcode) - (section cdata) (section switch) (section near) - (section data) - (section chuge) + (section cfar) (section ihuge) (section data_init_table) ) diff --git a/include/macros.h b/include/macros.h index cac1f50..621ae4c 100755 --- a/include/macros.h +++ b/include/macros.h @@ -1,5 +1,3 @@ -// SPDX-License-Identifier: MIT -// // include/macros.h // Utility macros for Calypsi compiler and assembler diff --git a/src/kernel/cstartup.s b/src/kernel/cstartup.s index f7f191e..e896920 100755 --- a/src/kernel/cstartup.s +++ b/src/kernel/cstartup.s @@ -1,9 +1,5 @@ -; SPDX-License-Identifier: MIT -; ; src/kernel/cstartup.s ; Critical boot and init code before calling main() -; -; Copyright © 2024 Kyle J Cardoza ;;; Startup variant, change attribute value if you make your own .rtmodel cstartup,"sentinel65x" diff --git a/src/kernel/hardware/vera/vera_font.s b/src/kernel/hardware/vera/vera_font.s new file mode 100644 index 0000000..c405b2f --- /dev/null +++ b/src/kernel/hardware/vera/vera_font.s @@ -0,0 +1,10 @@ +; SPDX-License-Identifier: MIT +; +; src/kernel/vera_font.s +; Assembly file to load the VERA font into the ROM image +; +; Copyright © 2024 Kyle J Cardoza + + .section cfar,rodata +vera_font_0: + .incbin "vera_font_0.bin" \ No newline at end of file diff --git a/src/kernel/vera_font_0.ase b/src/kernel/hardware/vera/vera_font_0.ase similarity index 100% rename from src/kernel/vera_font_0.ase rename to src/kernel/hardware/vera/vera_font_0.ase