From 47cbc7b1f9691a56ef51267f73a5dafe4f0f7331 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sat, 31 Oct 2020 02:26:59 +0100 Subject: [PATCH] added a custom-charset example for the c64 --- docs/source/todo.rst | 1 - examples/charset.p8 | 90 ++++++++++++++++++++++++++++++++++ examples/compiled/charset.prg | Bin 0 -> 917 bytes 3 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 examples/charset.p8 create mode 100644 examples/compiled/charset.prg 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 0000000000000000000000000000000000000000..c0473e1d45f1ad155772b722bbcaa62b70ab8b52 GIT binary patch literal 917 zcmdr~F=$gk82;~G^7`U|aePCC-$itZ;$o31ZE9^3f=bL#w>KJR2bT^)uITWTbdw}6 zkHQHjICK-qTT97s@8RUqO~M;9iITq5yEZPi(p?Vj|L*>e|Kq#+h%@hep9}ET&D#rj z=N&$-KU!PB@>8tbuL3~riu3Ku+a}vN`s_-=x3R$Fi_pO$L#OZw4)}#0sG&SGJKkf` zItCS%MxcB+kgo40vKczHBJ*+SWcjdCUtMlg9_L|bjKUI(!K6pN944K$oC)~O3+Xy24aIDvUL4a7iZmP=>SwK8$jHe zhS1JNxrC1LwH-%j)eR5dI9k>gHV<^|hn5{&?Y~ZbiN4!JeTLnjT5Sg+FyehPb4pZV zO-Za}Ienm)pm>9&XE6R^p36IrFKuI6d;epbQ~R{KoclNHESJ~*HT%k#^k37ljbD%UlOJA0)PTf1Gojhdya6#8 zBC`y65mk4IN_#{ZczFg>Hv+Xul)jE2-Xw94#2%zumgewDL}Pv!5yi7e51wl3M?HGd O&i04N&kt6bdcOf-8Hr#3 literal 0 HcmV?d00001