diff --git a/docs/source/todo.rst b/docs/source/todo.rst index d67a13205..d6bd81ab2 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -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 ;-) diff --git a/examples/charset.p8 b/examples/charset.p8 new file mode 100644 index 000000000..a4d97054e --- /dev/null +++ b/examples/charset.p8 @@ -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)) + + } +} diff --git a/examples/compiled/charset.prg b/examples/compiled/charset.prg new file mode 100644 index 000000000..c0473e1d4 Binary files /dev/null and b/examples/compiled/charset.prg differ