1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-09-29 03:56:15 +00:00
kickc/src/test/ref/font-hex-show.asm

151 lines
3.1 KiB
NASM
Raw Normal View History

2019-06-23 09:26:11 +00:00
// Shows a font where each char contains the number of the char (00-ff)
/// @file
2021-06-19 20:11:26 +00:00
/// Commodore 64 Registers and Constants
/// @file
2021-06-19 20:11:26 +00:00
/// The MOS 6526 Complex Interface Adapter (CIA)
2021-06-19 20:28:44 +00:00
///
/// http://archive.6502.org/datasheets/mos_6526_cia_recreated.pdf
// Commodore 64 PRG executable file
.file [name="font-hex-show.prg", type="prg", segments="Program"]
.segmentdef Program [segments="Basic, Code, Data"]
.segmentdef Basic [start=$0801]
.segmentdef Code [start=$80d]
.segmentdef Data [startAfter="Code"]
.segment Basic
2019-06-22 19:13:22 +00:00
:BasicUpstart(main)
2021-06-20 10:45:52 +00:00
/// $D018 VIC-II base addresses
// @see #VICII_MEMORY
2019-06-22 19:13:22 +00:00
.label D018 = $d018
.label SCREEN = $400
.label CHARSET = $2000
.segment Code
2019-06-22 19:13:22 +00:00
main: {
.const toD0181_return = (>(SCREEN&$3fff)*4)|(>CHARSET)/4&$f
2020-02-23 08:44:36 +00:00
// *D018 = toD018(SCREEN, CHARSET)
2019-06-22 19:13:22 +00:00
lda #toD0181_return
sta D018
2020-02-23 08:44:36 +00:00
// init_font_hex(CHARSET)
2019-06-23 09:26:11 +00:00
jsr init_font_hex
ldx #0
// Show all chars on screen
__b1:
2020-02-23 08:44:36 +00:00
// SCREEN[c] = c
2019-06-23 09:26:11 +00:00
txa
sta SCREEN,x
2020-02-23 08:44:36 +00:00
// for (byte c: 0..255)
2019-06-23 09:26:11 +00:00
inx
cpx #0
bne __b1
2020-02-23 08:44:36 +00:00
// }
2019-06-23 09:26:11 +00:00
rts
}
// Make charset from proto chars
// void init_font_hex(__zp(5) char *charset)
2019-06-23 09:26:11 +00:00
init_font_hex: {
.label __0 = $b
2019-06-23 09:26:11 +00:00
.label idx = $a
.label proto_lo = 7
.label charset = 5
.label c1 = 9
.label proto_hi = 2
.label c = 4
2019-06-22 19:13:22 +00:00
lda #0
sta.z c
2019-06-22 19:13:22 +00:00
lda #<FONT_HEX_PROTO
sta.z proto_hi
2019-06-22 19:13:22 +00:00
lda #>FONT_HEX_PROTO
sta.z proto_hi+1
2019-06-23 09:26:11 +00:00
lda #<CHARSET
sta.z charset
2019-06-23 09:26:11 +00:00
lda #>CHARSET
sta.z charset+1
__b1:
2019-06-23 09:26:11 +00:00
lda #0
sta.z c1
2019-06-22 19:13:22 +00:00
lda #<FONT_HEX_PROTO
sta.z proto_lo
2019-06-22 19:13:22 +00:00
lda #>FONT_HEX_PROTO
sta.z proto_lo+1
__b2:
2020-02-23 08:44:36 +00:00
// charset[idx++] = 0
2019-06-23 09:26:11 +00:00
lda #0
tay
sta (charset),y
lda #1
sta.z idx
2019-06-23 09:26:11 +00:00
ldx #0
__b3:
2020-02-23 08:44:36 +00:00
// proto_hi[i]<<4
2019-06-23 09:26:11 +00:00
txa
tay
2019-06-22 19:13:22 +00:00
lda (proto_hi),y
asl
asl
asl
2019-06-23 09:26:11 +00:00
asl
sta.z __0
2020-02-23 08:44:36 +00:00
// proto_lo[i]<<1
2019-06-23 09:26:11 +00:00
txa
tay
lda (proto_lo),y
asl
2020-02-23 08:44:36 +00:00
// proto_hi[i]<<4 | proto_lo[i]<<1
ora.z __0
2020-02-23 08:44:36 +00:00
// charset[idx++] = proto_hi[i]<<4 | proto_lo[i]<<1
ldy.z idx
2019-06-22 19:13:22 +00:00
sta (charset),y
2020-02-23 08:44:36 +00:00
// charset[idx++] = proto_hi[i]<<4 | proto_lo[i]<<1;
inc.z idx
2020-02-23 08:44:36 +00:00
// for( byte i: 0..4)
2019-06-23 09:26:11 +00:00
inx
cpx #5
bne __b3
2020-02-23 08:44:36 +00:00
// charset[idx++] = 0
2019-06-22 19:13:22 +00:00
lda #0
ldy.z idx
2019-06-22 19:13:22 +00:00
sta (charset),y
2020-02-23 08:44:36 +00:00
// charset[idx++] = 0;
2019-06-23 09:26:11 +00:00
iny
2020-02-23 08:44:36 +00:00
// charset[idx++] = 0
2019-06-22 19:13:22 +00:00
sta (charset),y
2020-02-23 08:44:36 +00:00
// proto_lo += 5
2019-06-22 19:13:22 +00:00
lda #5
clc
adc.z proto_lo
sta.z proto_lo
2019-06-22 19:13:22 +00:00
bcc !+
inc.z proto_lo+1
2019-06-22 19:13:22 +00:00
!:
2020-02-23 08:44:36 +00:00
// charset += 8
2019-06-22 19:13:22 +00:00
lda #8
clc
adc.z charset
sta.z charset
2019-06-22 19:13:22 +00:00
bcc !+
inc.z charset+1
2019-06-22 19:13:22 +00:00
!:
2020-02-23 08:44:36 +00:00
// for( byte c: 0..15 )
inc.z c1
2019-06-23 09:26:11 +00:00
lda #$10
cmp.z c1
bne __b2
2020-02-23 08:44:36 +00:00
// proto_hi += 5
2019-06-22 19:13:22 +00:00
lda #5
clc
adc.z proto_hi
sta.z proto_hi
2019-06-22 19:13:22 +00:00
bcc !+
inc.z proto_hi+1
2019-06-22 19:13:22 +00:00
!:
2020-02-23 08:44:36 +00:00
// for( byte c: 0..15 )
inc.z c
2019-06-22 19:13:22 +00:00
lda #$10
cmp.z c
bne __b1
2020-02-23 08:44:36 +00:00
// }
2019-06-22 19:13:22 +00:00
rts
}
.segment Data
2019-06-23 09:26:11 +00:00
// Bit patterns for symbols 0-f (3x5 pixels) used in font hex
FONT_HEX_PROTO: .byte 2, 5, 5, 5, 2, 6, 2, 2, 2, 7, 6, 1, 2, 4, 7, 6, 1, 2, 1, 6, 5, 5, 7, 1, 1, 7, 4, 6, 1, 6, 3, 4, 6, 5, 2, 7, 1, 1, 1, 1, 2, 5, 2, 5, 2, 2, 5, 3, 1, 1, 2, 5, 7, 5, 5, 6, 5, 6, 5, 6, 2, 5, 4, 5, 2, 6, 5, 5, 5, 6, 7, 4, 6, 4, 7, 7, 4, 6, 4, 4