Sunday, 20 March 2011

Showing the contents of CHAR ROM

While reading the Commodore 64 Programmer's Reference Guide (PRG), page 109 talked about reading Character ROM. I felt inspired, and wrote this:


1 rem prints char rom contents as
2 rem pretty strings
3 rem by thejpster 2011/03/20 
10 print "enter letter or space to quit"
20 get a$:if a$="" then 6
30 if a$=" " then end
39 turn petscii into screen code
40 z%=asc(a$) : gosub 2000
49 rem disable interrupts
50 poke 56334,peek(56334)and254
59 rem map char rom into $d000
60 poke 1,peek(1)and251
69 rem read char data
70 for i=0 to 7
80 a%(i)=peek(53248+(z%*8)+i)
90 next
99 rem put $d000 back to i/o
100 poke 1,peek(1)or4
109 rem re-enable interrupts
110 poke 56334,peek(56334)or1
120 for i=0 to 7
130 z%=a%(i) : gosub 1000
140 next
150 goto 10
1000 rem prints a byte in z% as *s
1010 p$="" : v%=256
1020 for b=7 to 0 step -1
1030 v%=v% / 2
1040 if z% and v% then 1060
1050 p$=p$+" ": goto 1070
1060 p$=p$+"*"
1070 next
1080 print p$
1090 return
2000 rem PETSCII to screen code
2010 if z% <= 31 then z%=z%+128:return
2020 if z% <= 63 then return
2030 if z% <= 95 then z%=z%-64:return
2040 if z% <= 127 then z%=z%-32:return
2050 if z% <= 159 then z%=z%+64:return
2060 if z% <= 191 then z%=z%-64:return
2070 if z% <= 223 then z%=z%-128:return
2080 return


The whole thing was a useful exercise in reminding myself of C64 basic and getting files in and out of VICE (a C64 emulator), using petcat and c1541.

It looks like this:



Some useful commands I've learned:
jonathan@laptop$ x64 # start vice, create new disc, save code
jonathan@laptop$ c1541
c1541 #8> attach my_disk.d64
c1541 #8> dir
0 "                "    2a
1     "hello           "  prg 
4     "big letters     "  prg 
659 blocks free.
c1541 #8> read "big letters" "big letters.prg"
c1541 #8> exit
jonathan@laptop$ petcat -o big_letters.txt -- "big letters.prg"