more generalisation of font code.

This commit is contained in:
Martin Preuss
2025-05-22 15:57:03 +02:00
parent 229e68077c
commit a4975038b4
10 changed files with 282 additions and 205 deletions

View File

@@ -0,0 +1,13 @@
<?xml?>
<gwbuild>
<extradist>
defs.asm
font8x8.asm
font1.asm
</extradist>
</gwbuild>

View File

@@ -0,0 +1,20 @@
; ***************************************************************************
; copyright : (C) 2025 by Martin Preuss
; email : martin@libchipcard.de
;
; ***************************************************************************
; * This file is part of the project "AqHome". *
; * Please see toplevel file COPYING of that project for license details. *
; ***************************************************************************
.equ FONT_OFFS_RENDERFN_LOW = 0
.equ FONT_OFFS_RENDERFN_HI = 1
.equ FONT_OFFS_DATASIZE = 2 ; one byte used, one byte reserved
.equ FONT_OFFS_WIDTH = 4
.equ FONT_OFFS_HEIGHT = 5
.equ FONT_OFFS_FIRSTCHAR = 6
.equ FONT_OFFS_NUMCHARS = 7

View File

@@ -0,0 +1,100 @@
; ***************************************************************************
; copyright : (C) 2025 by Martin Preuss
; email : martin@libchipcard.de
;
; ***************************************************************************
; * This file is part of the project "AqHome". *
; * Please see toplevel file COPYING of that project for license details. *
; ***************************************************************************
; ***************************************************************************
; This is a font from the project LCD_fonts at
; https://github.com/basti79/LCD-fonts.git
; which in turn is based on a post by Benedikt K. in a forum post on
; https://www.mikrocontroller.net/topic/54860
; ***************************************************************************
; ***************************************************************************
; code
.cseg
font1_8x8:
; header
rjmp font8x8MonoRenderCharacter ; renderFn
.db 128, 0 ; needed buffer size
.db 8, 8 ; width, height of chars
.db 32, 64 ; first char, num of chars in font
; data
.db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, ; 0x20
.db 0x0C,0x1E,0x1E,0x0C,0x0C,0x00,0x0C,0x00, ; 0x21
.db 0x36,0x36,0x36,0x00,0x00,0x00,0x00,0x00, ; 0x22
.db 0x36,0x36,0x7F,0x36,0x7F,0x36,0x36,0x00, ; 0x23
.db 0x0C,0x3E,0x03,0x1E,0x30,0x1F,0x0C,0x00, ; 0x24
.db 0x00,0x63,0x33,0x18,0x0C,0x66,0x63,0x00, ; 0x25
.db 0x1C,0x36,0x1C,0x6E,0x3B,0x33,0x6E,0x00, ; 0x26
.db 0x06,0x06,0x03,0x00,0x00,0x00,0x00,0x00, ; 0x27
.db 0x18,0x0C,0x06,0x06,0x06,0x0C,0x18,0x00, ; 0x28
.db 0x06,0x0C,0x18,0x18,0x18,0x0C,0x06,0x00, ; 0x29
.db 0x00,0x66,0x3C,0xFF,0x3C,0x66,0x00,0x00, ; 0x2A
.db 0x00,0x0C,0x0C,0x3F,0x0C,0x0C,0x00,0x00, ; 0x2B
.db 0x00,0x00,0x00,0x00,0x00,0x0E,0x0C,0x06, ; 0x2C
.db 0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00, ; 0x2D
.db 0x00,0x00,0x00,0x00,0x00,0x0C,0x0C,0x00, ; 0x2E
.db 0x60,0x30,0x18,0x0C,0x06,0x03,0x01,0x00, ; 0x2F
.db 0x1E,0x33,0x3B,0x3F,0x37,0x33,0x1E,0x00, ; 0x30
.db 0x0C,0x0F,0x0C,0x0C,0x0C,0x0C,0x3F,0x00, ; 0x31
.db 0x1E,0x33,0x30,0x1C,0x06,0x33,0x3F,0x00, ; 0x32
.db 0x1E,0x33,0x30,0x1C,0x30,0x33,0x1E,0x00, ; 0x33
.db 0x38,0x3C,0x36,0x33,0x7F,0x30,0x30,0x00, ; 0x34
.db 0x3F,0x03,0x1F,0x30,0x30,0x33,0x1E,0x00, ; 0x35
.db 0x1C,0x06,0x03,0x1F,0x33,0x33,0x1E,0x00, ; 0x36
.db 0x3F,0x33,0x30,0x18,0x0C,0x06,0x06,0x00, ; 0x37
.db 0x1E,0x33,0x33,0x1E,0x33,0x33,0x1E,0x00, ; 0x38
.db 0x1E,0x33,0x33,0x3E,0x30,0x18,0x0E,0x00, ; 0x39
.db 0x00,0x00,0x0C,0x0C,0x00,0x0C,0x0C,0x00, ; 0x3A
.db 0x00,0x00,0x0C,0x0C,0x00,0x0E,0x0C,0x06, ; 0x3B
.db 0x18,0x0C,0x06,0x03,0x06,0x0C,0x18,0x00, ; 0x3C
.db 0x00,0x00,0x3F,0x00,0x3F,0x00,0x00,0x00, ; 0x3D
.db 0x06,0x0C,0x18,0x30,0x18,0x0C,0x06,0x00, ; 0x3E
.db 0x1E,0x33,0x30,0x18,0x0C,0x00,0x0C,0x00, ; 0x3F
.db 0x3E,0x63,0x7B,0x7B,0x7B,0x03,0x1E,0x00, ; 0x40
.db 0x0C,0x1E,0x33,0x33,0x3F,0x33,0x33,0x00, ; 0x41
.db 0x3F,0x66,0x66,0x3E,0x66,0x66,0x3F,0x00, ; 0x42
.db 0x3C,0x66,0x03,0x03,0x03,0x66,0x3C,0x00, ; 0x43
.db 0x3F,0x36,0x66,0x66,0x66,0x36,0x3F,0x00, ; 0x44
.db 0x7F,0x46,0x16,0x1E,0x16,0x46,0x7F,0x00, ; 0x45
.db 0x7F,0x46,0x16,0x1E,0x16,0x06,0x0F,0x00, ; 0x46
.db 0x3C,0x66,0x03,0x03,0x73,0x66,0x7C,0x00, ; 0x47
.db 0x33,0x33,0x33,0x3F,0x33,0x33,0x33,0x00, ; 0x48
.db 0x1E,0x0C,0x0C,0x0C,0x0C,0x0C,0x1E,0x00, ; 0x49
.db 0x78,0x30,0x30,0x30,0x33,0x33,0x1E,0x00, ; 0x4A
.db 0x67,0x66,0x36,0x1E,0x36,0x66,0x67,0x00, ; 0x4B
.db 0x0F,0x06,0x06,0x06,0x46,0x66,0x7F,0x00, ; 0x4C
.db 0x63,0x77,0x7F,0x6B,0x63,0x63,0x63,0x00, ; 0x4D
.db 0x63,0x67,0x6F,0x7B,0x73,0x63,0x63,0x00, ; 0x4E
.db 0x1C,0x36,0x63,0x63,0x63,0x36,0x1C,0x00, ; 0x4F
.db 0x3F,0x66,0x66,0x3E,0x06,0x06,0x0F,0x00, ; 0x50
.db 0x1E,0x33,0x33,0x33,0x3B,0x1E,0x38,0x00, ; 0x51
.db 0x3F,0x66,0x66,0x3E,0x1E,0x36,0x67,0x00, ; 0x52
.db 0x1E,0x33,0x07,0x1C,0x38,0x33,0x1E,0x00, ; 0x53
.db 0x3F,0x2D,0x0C,0x0C,0x0C,0x0C,0x1E,0x00, ; 0x54
.db 0x33,0x33,0x33,0x33,0x33,0x33,0x3F,0x00, ; 0x55
.db 0x33,0x33,0x33,0x33,0x33,0x1E,0x0C,0x00, ; 0x56
.db 0x63,0x63,0x63,0x6B,0x7F,0x77,0x63,0x00, ; 0x57
.db 0x63,0x63,0x36,0x1C,0x36,0x63,0x63,0x00, ; 0x58
.db 0x33,0x33,0x33,0x1E,0x0C,0x0C,0x1E,0x00, ; 0x59
.db 0x7F,0x33,0x19,0x0C,0x46,0x63,0x7F,0x00, ; 0x5A
.db 0x1E,0x06,0x06,0x06,0x06,0x06,0x1E,0x00, ; 0x5B
.db 0x03,0x06,0x0C,0x18,0x30,0x60,0x40,0x00, ; 0x5C
.db 0x1E,0x18,0x18,0x18,0x18,0x18,0x1E,0x00, ; 0x5D
.db 0x08,0x1C,0x36,0x63,0x00,0x00,0x00,0x00, ; 0x5E
.db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF ; 0x5F

View File

@@ -0,0 +1,97 @@
; ***************************************************************************
; copyright : (C) 2025 by Martin Preuss
; email : martin@libchipcard.de
;
; ***************************************************************************
; * This file is part of the project "AqHome". *
; * Please see toplevel file COPYING of that project for license details. *
; ***************************************************************************
; ***************************************************************************
; code
.cseg
; ---------------------------------------------------------------------------
; @routine font8x8RenderCharacter
; @param R16 character to write
; @param R1:R0 background color
; @param R3:R2 foreground color
; @param Z pointer to font
; @param X pointer to RAM to store data to
; @param r18 char width in pixel
; @param r19 char height in pixel
; @clobbers r17, r24, r25, x
font8x8MonoRenderCharacter:
push zl
push zh
lsl zl
rol zh
rcall font8x8GetCharPosInFont8x8 ; (r17, r24, r25, z)
ldi r25, 8 ; 8 bytes
font8x8MonoRenderCharacter_loop1:
ldi r24, 8 ; 8 bits
lpm r17, Z+
font8x8MonoRenderCharacter_loop2:
lsr r17
brcs font8x8MonoRenderCharacter_writeForeground
st X+, r0
st X+, r1
rjmp font8x8MonoRenderCharacter_loop2end
font8x8MonoRenderCharacter_writeForeground:
st X+, r2
st X+, r3
font8x8MonoRenderCharacter_loop2end:
dec r24
brne font8x8MonoRenderCharacter_loop2
dec r25
brne font8x8MonoRenderCharacter_loop1
ldi r18, 8
ldi r19, 8
pop zh
pop zl
ret
; @end
; ---------------------------------------------------------------------------
; @routine font8x8GetCharPosInFont8x8
; @param R16 character to write
; @param Z pointer to font
; @return Z pointer to begin of char data
; @clobbers r17, r24, r25, z
font8x8GetCharPosInFont8x8:
mov r24, r16
adiw zh:zl, FONT_OFFS_FIRSTCHAR
lpm r24, Z+ ; first char num
lpm r25, Z+ ; num of chars
sub r16, r24
brcs font8x8GetCharPosInFont8x8_ret
cp r16, r25
brcc font8x8GetCharPosInFont8x8_ret
mov r24, r16
clr r25
lsl r24 ; x2
rol r25
lsl r24 ; x4
rol r25
lsl r24 ; x8
rol r25
add zl, r24
adc zh, r25
font8x8GetCharPosInFont8x8_ret:
ret
; @end