is it possible to use redefined characters with this program?

Basic and Machine Language

Moderator: Moderators

Post Reply
the777
Vic 20 Newbie
Posts: 16
Joined: Tue Feb 23, 2021 9:08 am

is it possible to use redefined characters with this program?

Post by the777 »

this program makes the screen bigger.

https://techtinkering.com/articles/chan ... re-vic-20/

Code: Select all

10 rem demonstrate a 27x33 screen
  20 rem lawrence woodman, nov 2019
  30 print "{clr}"

 100 rem lower top of basic to $1c00
 110 poke 55,0:poke 56,28:poke 51,0:poke 52,28:clr
 120 sm=7168:cm=37888:rem screen map: $1c00 colour map: $9400
 130 sw=27:sh=33:rem screen width/height
 140 ox=-5:oy=-19:rem picture origin x/y offset

 200 rem record initial screen settings
 210 da=peek(36866):db=peek(36867):dc=peek(36869)
 220 dd=peek(36864):de=peek(36865)

 300 rem set up screen
 310 poke 36869,240:rem set screen map: $1c00
 320 poke 36866,sw:rem width
 330 poke 36867,(peek(36867)and 128)or (sh*2):rem height
 340 poke 36864,peek(36864)+ox:rem picture origin x offset
 350 poke 36865,peek(36865)+oy:rem picture origin y offset

 400 rem clear screen
 410 for i=0 to (sw*sh)-1
 420 poke sm+i,32:poke cm+i,6
 430 next i

 500 rem print hello worlds
 501 10 POKE 36869, (PEEK(36869) AND 240) OR 15
 510 pc=0
 520 for py=1 to sh-2
 530 px=sw-27:st$="AAAAAAAAAAAAAAAAAA@@@@@@@@@@@@@@@@":gosub 5000
 540 pc=pc+1:if pc=1 then pc=2
 550 if pc>7 then pc=2
 560 next py

 600 rem wait for a key press
 610 pc=0:px=(sw-13)/2:py=sh-1:st$="Press any key":gosub 5000
 620 get a$:if a$="" then 620

 700 rem restore screen settings
 710 poke 36866,da:poke 36867,db:poke 36869,dc
 720 poke 36864,dd:poke 36865,de
 730 print "{clr}"
 740 end

4000 rem ascii to screen code - p111 mapping the vic
4001 rem args: ac - ret: sc
4010 sc=ac:if ac>127 and ac<159 then sc=0: goto 4100
4020 if ac<64 then 4100
4030 sc=ac-32
4040 if ac<96 then sc=sc-32:goto 4100
4050 if ac<128 then 4100
4060 sc=sc-32
4070 if ac>191 then sc=sc-64
4080 if ac=255 then sc=30
4100 return

5000 rem print string - args: st$, px, py, pc
5010 for i=1 to len(st$)
5020 ac=asc(mid$(st$,i,1)):gosub 4000
5030 ps=sc
5040 gosub 6000
5050 px=px+1
5060 next i
5070 return

6000 rem print char - args: px,py,ps,pc
6010 poke sm+px+(py*sw),ps:poke cm+px+(py*sw),pc
6020 return
and this program creates two new characters, 'A' and '@' are redefined...

https://sleepingelephant.com/~sleeping/ ... php?t=9928

Code: Select all

10 POKE 36869, (PEEK(36869) AND 240) OR 15

11 rem and the rest is redefining my characters!
12 rem first, the smiley-face from the 8-bit guy's Commodore History video
20 poke 7168, 126
30 poke 7169, 129
40 poke 7170, 165
50 poke 7171, 129
60 poke 7172, 165
70 poke 7173, 153
80 poke 7174, 129
90 poke 7175, 126

100 rem next, a skate (my profile icon on most forums lol)
110 poke 7176, 192
120 poke 7177, 192
130 poke 7178, 224
140 poke 7179, 254
150 poke 7180, 255
160 poke 7181, 255
170 poke 7182, 195
180 poke 7183, 126
the 1st program needs a memory expansion to work and the 2nd program also works with a memory expansion. they work separately but not together. i have tried running the 2nd program and then doing a soft reset and running the 1st program but it seems to delete all the character data. i added line 10 in the 2nd program to line 501 in the 1st program to switch from rom to ram characters. am i missing something here?
User avatar
chysn
Vic 20 Scientist
Posts: 1205
Joined: Tue Oct 22, 2019 12:36 pm
Website: http://www.beigemaze.com
Location: Michigan, USA
Occupation: Software Dev Manager

Re: is it possible to use redefined characters with this program?

Post by chysn »

Your incompatible lines are:

Code: Select all

120 sm=7168
...
410 for i=0 to (sw*sh)-1
420 poke sm+i,32:poke cm+i,6
430 next i
and from the other program:

Code: Select all

20 poke 7168, 126
30 poke 7169, 129
...and so on
You're using 7168 (and up) for two different things. Relocate either your character set or your screen memory.
VIC-20 Projects: wAx Assembler, TRBo: Turtle RescueBot, Helix Colony, Sub Med, Trolley Problem, Dungeon of Dance, ZEPTOPOLIS, MIDI KERNAL, The Archivist, Ed for Prophet-5

WIP: MIDIcast BASIC extension

he/him/his
the777
Vic 20 Newbie
Posts: 16
Joined: Tue Feb 23, 2021 9:08 am

Re: is it possible to use redefined characters with this program?

Post by the777 »

chysn wrote:[...]

You're using 7168 (and up) for two different things. Relocate either your character set or your screen memory.
ok, thank you. i may need a little help with that though....
Last edited by Mike on Wed Aug 23, 2023 1:37 am, edited 2 times in total.
Reason: full quote shortened, rest of replied-to post clear from context
User avatar
chysn
Vic 20 Scientist
Posts: 1205
Joined: Tue Oct 22, 2019 12:36 pm
Website: http://www.beigemaze.com
Location: Michigan, USA
Occupation: Software Dev Manager

Re: is it possible to use redefined characters with this program?

Post by chysn »

the777 wrote: Sun Aug 20, 2023 8:32 pm ok, thank you. i may need a little help with that though....
Sure, I should have some time tomorrow to help out, for now I have to get to bed. But basically, it boils down to setting the 36869 register properly.
the777
Vic 20 Newbie
Posts: 16
Joined: Tue Feb 23, 2021 9:08 am

Re: is it possible to use redefined characters with this program?

Post by the777 »

chysn wrote: Sun Aug 20, 2023 9:05 pm
the777 wrote: Sun Aug 20, 2023 8:32 pm ok, thank you. i may need a little help with that though....
Sure, I should have some time tomorrow to help out, for now I have to get to bed. But basically, it boils down to setting the 36869 register properly.
are you about?
User avatar
Mike
Herr VC
Posts: 4841
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: is it possible to use redefined characters with this program?

Post by Mike »

the777 wrote:ok, thank you. i may need a little help with that though....
chysn wrote:Sure, I should have some time tomorrow to help out, for now I have to get to bed. But basically, it boils down to setting the 36869 register properly.
the777 wrote:are you about?
Mr. 777,

you seem to have somewhat unrealistic ideas about the response times in Internet forums.

There is a notion about different time zones to be considered, sure - but not only do you bump an enquiry just 6 hours after your other correspondent has chiefly indicated that it would take at least (hopefully) 8 hours for him to be awake again, and then you think the first thing he is supposed to do, around breakfast, was providing you a working solution on a silver platter? Get real!

As had been noted, your home assignment can be solved by setting 36869 (and other relevant VIC registers) correctly, and before that: define where the character set is to be located, how big the character set is supposed to be, where the text screen is supposed to be located (and how big), and finally, how BASIC memory is supposed to be set so graphics/text and BASIC data do not interfere. The Programmer's Reference Guide is your friend here.

Greetings,

Michael
User avatar
Mike
Herr VC
Posts: 4841
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: is it possible to use redefined characters with this program?

Post by Mike »

Here we go: (download)

This is for unexpanded VIC-20, just drag and drop the program into the main window of VICE, with all RAM expansions deactivated before. NTSC users will see the message cropped around all borders.

Code: Select all

10 POKE55,0:POKE56,24:CLR
11 :
12 DIMB%(255)
13 FORT=0TO31:B%(32+T)=32+T:B%(64+T)=T:B%(160+T)=96+T:IFT<>30THENB%(192+T)=64+T
14 NEXT:B%(255)=94
15 :
16 V=36864:POKE648,28:SYS58648:CO=37888-7168
17 POKEV,PEEK(60900)-5:POKEV+1,PEEK(60901)-20:POKEV+2,27:POKEV+3,66:POKEV+5,254
18 :
19 FORT=0TO1023
20 POKE6144+T,PEEK(34816+T)
21 NEXT
22 :
23 FORT=7168TO8059
24 POKET,32
25 POKET+CO,6
26 NEXT
27 :
28 X=2:Y=0:T$="{SHIFT-T}HIS IS TEXT ON A 27X33":GOSUB40
29 X=2:Y=2:T$="SCREEN WITH A SPECIALLY":GOSUB40
30 X=5:Y=4:T$="CRAFTED {SHIFT-S}MILEY: {PI}":GOSUB40
31 X=0:Y=30:T$="{SHIFT-N}OW, THAT WASN'T THAT HARD,":GOSUB40
32 X=10:Y=32:T$="WAS IT?":GOSUB40
33 :
34 FORT=0TO7:READA:POKE6144+8*94+T,A:NEXT
35 DATA 60,126,211,255,251,199,102,60
36 :
37 GETA$:IFA$=""THEN37
38 SYS58648:END
39 :
40 IFX<0ORY<0THENRETURN
41 IFT$=""THENRETURN
42 IFX>26THENX=0:Y=Y+1
43 IFY>32THENRETURN
44 POKE7168+27*Y+X,B%(ASC(T$))
45 T$=MID$(T$,2):X=X+1:GOTO41
Right, to explain:
  • Line 10 lowers the roof to address 6144 ($1800) to protect the character set data at $1800 and the text screen at $1C00 from activities of the BASIC interpreter.
  • Lines 12..14 set up the table for PETSCII to screencode conversion. Note, together with the rather simple text display sub-routine at line 40, this only supports the non-inverted characters.
  • Lines 16 and 17 move the screen to $1C00 and change the VIC registers to a 27x33 screen, recentered, with a user defined character set at $1800. The PEEKs to 60900 and 60901 access the ROM default values, not the current VIC register contents (which could already have been altered!),
  • Lines 19..21 copy the non-inverted part of the lower-case character set from $8800..$8BFF to $1800..$1BFF.
  • Lines 23..26 clear the whole text screen with spaces (screen code 32) and initialise the colour RAM to Blue (colour code 6).
  • Lines 28..32 print a non-sense message to the text screen.
  • Lines 34 and 35 redefine the {PI} character (which actually appears as checkerboard pattern with the original lower-case character set!).
  • Lines 37 and 38 wait for a keypress and then restore the default screen size and standard character set.
  • Lines 40..45 are a simple sub-routine to print out strings at pre-defined positions on the expanded text screen.
The program can be adapted for the use of RAM expansions and for a full character set (including inverse characters). Doing this needs to re-arrange a few things in memory (including some VIC register values) as well as expanding the text output routine to switch between normal and inversed characters upon encountering {RVS OFF} or {RVS ON} in the text string. Details left as exercise for the reader. :mrgreen:
User avatar
chysn
Vic 20 Scientist
Posts: 1205
Joined: Tue Oct 22, 2019 12:36 pm
Website: http://www.beigemaze.com
Location: Michigan, USA
Occupation: Software Dev Manager

Re: is it possible to use redefined characters with this program?

Post by chysn »

Mike wrote: Mon Aug 21, 2023 4:41 am There is a notion about different time zones to be considered, sure - but not only do you bump an enquiry just 6 hours after your other correspondent has chiefly indicated that it would take at least (hopefully) 8 hours for him to be awake again
There's also the unfortunate matter of work. I'm troubleshooting an exim server and it's driving me crazy. I'll have a lunch break in an hour, but it looks like Mike already got to the salient details (thanks, Mike!) so I'll probably just fire up VICE and play around with the code.

Update: Per usual, that's about as concise a demo as you can get. My physical medium is NTSC VIC, which sadly makes such huge screens unusable. Mapping the VIC has a five-page treatment of the screen/character register (36869, here V+5), and that's worth checking out. I had to read it over a few times, and I still refer to the charts rather than memorizing the values.
the777
Vic 20 Newbie
Posts: 16
Joined: Tue Feb 23, 2021 9:08 am

Re: is it possible to use redefined characters with this program?

Post by the777 »

Mike wrote:Here we go: (download)

[...]
thank you. that works, great!
Last edited by Mike on Wed Aug 23, 2023 1:03 am, edited 2 times in total.
Reason: unnecessary full quote shortened, rest of replied-to post clear from context
the777
Vic 20 Newbie
Posts: 16
Joined: Tue Feb 23, 2021 9:08 am

Re: is it possible to use redefined characters with this program?

Post by the777 »

just a quick other question. how would i use this program in multicolor mode? ive had a look at this site:

https://www.atarimagazines.com/compute/ ... he_VIC.php

and this program:

Code: Select all

10 PRINT "{CLEAR}"
100 POKE36869, 255
105 POKE36879, 61
110 FORI = 7168TO7679 : POKEI, PEEK(I + 25600): NEXT
130 FORI = 7176TO7191
150 READA : POKEI, A : NEXT
154 X = 7690 : C = 30720
155 POKEX, 1 : POKEX + C, 10 : POKEX + 1, 2 : POKEX + C + 1, 10
156 FORT = 1TO80 : NEXT : POKEX, 32 : POKEX + 1, 32
157 X = X + 22 : IFX> 8185THEN154
158 GOTO155
160 DATA8, 2, 5, 23, 85, 93, 85, 40, 32, 128, 80, 212, 85, 117, 85, 40
i kind of understand how it works but cant find a way of incorporating it into the bigger screen program. i just get screen garbage again
Last edited by Mike on Wed Aug 23, 2023 1:00 am, edited 1 time in total.
Reason: unnecessary full quote removed, replied-to post clear from context
User avatar
chysn
Vic 20 Scientist
Posts: 1205
Joined: Tue Oct 22, 2019 12:36 pm
Website: http://www.beigemaze.com
Location: Michigan, USA
Occupation: Software Dev Manager

Re: is it possible to use redefined characters with this program?

Post by chysn »

Keep in mind that pixels in multicolor characters become groups of two bits rendered as double-width pixels. So you need to redesign your characters completely for multicolor mode. The resource at the link you provided gives pretty good info on how to do that.

To actually put a screen location into multicolor mode, set bit 3 of the color value (since color is only a 3-bit value in the first place, "set bit 3" is the same as "add 8"). That's all there is to it!

But your screen probably looks like "garbage" because you haven't yet redesigned your characters for multicolor.

Try this: Start up an unexpanded VIC-20 and type

Code: Select all

POKE 38400, 7 + 8
The 7 sets the first character location's foreground color to yellow, and adding 8 turns on the multicolor bit 3. The top-left asterisk no longer really looks like an asterisk, right? That's because the VIC takes the character bits 2 at a time, 4 groups per line, and makes each set of 2 a different color (background, foreground, border, aux). You can see a little bit of border color (cyan) there, a little bit of foreground (yellow) there, and some aux, which is black because it's currently unset. Each "pixel" is no longer just a foreground or background color. There are two other possibilities, which is why you need to go back to the lab on character design.
the777
Vic 20 Newbie
Posts: 16
Joined: Tue Feb 23, 2021 9:08 am

Re: is it possible to use redefined characters with this program?

Post by the777 »

its ok, thank you, i managed to do it
Last edited by Mike on Wed Aug 23, 2023 1:01 am, edited 1 time in total.
Reason: unnecessary full quote removed, replied-to post clear from context
Post Reply