added a custom-charset example for the c64

This commit is contained in:
Irmen de Jong 2020-10-31 02:26:59 +01:00
parent e7b75d591c
commit 47cbc7b1f9
3 changed files with 90 additions and 1 deletions

View File

@ -9,7 +9,6 @@ TODO
- option to load the built-in library files from a directory instead of the embedded ones (for easier library development/debugging)
- see if we can group some errors together for instance the (now single) errors about unidentified symbols
- use VIC banking to move up the graphics bitmap memory location. Don't move it under the ROM though as that would require IRQ disabling and memory bank swapping for every bitmap manipulation
- add a c-64 example for using custom char sets, copying (part of) the default charset.
- some support for recursive subroutines? via %option recursive?: allocate all params and local vars on estack, don't allow nested subroutines, can begin by first not allowing any local variables just fixing the parameters
- get rid of all other TODO's in the code ;-)

90
examples/charset.p8 Normal file
View File

@ -0,0 +1,90 @@
%target c64
%import syslib
%import textio
%zeropage basicsafe
%option no_sysinit
; Create a custom character set on the C64.
main {
sub start() {
txt.color(1)
txt.print("creating charset...\n")
charset.make_custom_charset()
; activate the new charset in RAM
ubyte block = c64.CIA2PRA
const ubyte PAGE1 = ((c64.Screen >> 6) & $F0) | ((charset.CHARSET >> 10) & $0E)
c64.CIA2PRA = (block & $FC) | (lsb(c64.Screen >> 14) ^ $03)
c64.VMCSB = PAGE1
txt.print("\n @ @ @ @\n")
}
}
charset {
const uword CHARSET = $2000
sub copy_rom_charset() {
; copies the charset from ROM to RAM so we can modify it
set_irqd()
ubyte bank = @($0001)
@($0001) = bank & %11111011 ; enable CHAREN, so the character rom accessible at $d000
; memcopy($d000, CHARSET, 256*8*2) ; copy the charset to RAM TODO memcopy > 256 length
uword cc = 0
repeat 256*8*2 {
@(CHARSET+cc) = @($d000+cc)
cc++
}
@($0001) = bank ; reset previous memory banking
clear_irqd()
}
sub make_custom_charset() {
copy_rom_charset()
; make all characters italic
ubyte c
for c in 0 to 255 {
uword ptr = CHARSET + c*$0008
@(ptr) >>= 2
@(ptr+1) >>= 2
@(ptr+2) >>= 1
@(ptr+3) >>= 1
;@(ptr+4) >>= 0
;@(ptr+5) >>= 0
@(ptr+6) <<= 1
@(ptr+7) <<= 1
ptr = CHARSET + 256*8 + c*$0008
@(ptr) >>= 2
@(ptr+1) >>= 2
@(ptr+2) >>= 1
@(ptr+3) >>= 1
;@(ptr+4) >>= 0
;@(ptr+5) >>= 0
@(ptr+6) <<= 1
@(ptr+7) <<= 1
}
; add a smiley over the '@'
ubyte[] smiley = [
%00111100,
%01000010,
%10100101,
%10000001,
%10100101,
%10011001,
%01000010,
%00111100
]
memcopy(smiley, CHARSET, len(smiley))
}
}

Binary file not shown.