Help Redefining VIC-20 Character Set

Basic and Machine Language

Moderator: Moderators

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

Post by Mike »

saehn wrote:for using it as a full-screen [...] bitmap mode for game intros, etc.
Like in VICtoria Gold Edition? :wink:
... "low-res" ...
I'd like to know what's "low-res" about being able to change individual pixels (or twice-wide pixels in multi-colour). :?

Even though I had thought about writing an editor for MINIGRAFIK bitmap images, thus far I rather use MS Paint, and Irfanview (also for photos of my camera, etc.) to produce *.pgm files on the PC, and then convert them with a BASIC program using MINIGRAFIK commands:

Code: Select all

10 DIMC%(3,12,1):FORY=0TO3:FORT=0TO12:FORX=0TO1:READC%(Y,T,X):NEXT:NEXT:NEXT
11 :
12 INPUT"PGM FILE";PF$
13 INPUT"TARGET";TF$
14 INPUT"COLOUR 1  8{3 LEFT}";A
15 INPUT"COLOUR 2  9{3 LEFT}";G
16 :
17 LF$=CHR$(10):NU$=CHR$(0):OPEN2,8,2,PF$+",S,R"
18 GOSUB30:PRINTLI$:IFLI$<>"P5"THENCLOSE2:STOP
19 GOSUB30:PRINTLI$:IFLI$<>"80 192"THENCLOSE2:STOP
20 GOSUB30:PRINTLI$:IFLI$<>"255"THENCLOSE2:STOP
21 PRINT"HEADER OK. PRESS KEY."
22 GETA$:IFA$=""THEN22
23 POKE36879,16*G+8+0:POKE36878,16*A:POKE646,8+1:@ON:@CLR
24 FORY=0TO191:FORX=0TO79
25 GET#2,A$:@C%(YAND3,(24*ASC(A$+NU$)+255)/510,XAND1),2*X,Y
26 NEXT:NEXT:CLOSE2
27 GETA$:IFA$=""THEN27
28 @SAVETF$,8:@RETURN:END
29 :
30 LI$=""
31 GET#2,A$:IFA$<>LF$THENLI$=LI$+A$:GOTO31
32 IFLEFT$(LI$,1)="#"THEN30:REM IGNORE COMMENT LINES
33 RETURN
34 :
35 DATA 2,2, 2,2, 3,2, 3,3, 3,3, 3,3, 3,0, 0,0, 0,0, 0,0, 1,0, 1,1, 1,1
36 DATA 2,2, 2,3, 2,3, 2,3, 3,3, 0,3, 0,3, 0,3, 0,0, 0,1, 0,1, 0,1, 1,1
37 DATA 2,2, 2,2, 2,3, 3,3, 3,3, 3,3, 0,3, 0,0, 0,0, 0,0, 0,1, 1,1, 1,1
38 DATA 2,2, 3,2, 3,2, 3,2, 3,3, 3,0, 3,0, 3,0, 0,0, 1,0, 1,0, 1,0, 1,1
39 :
40 REM ** PGM IMPORT, MG VERSION 2008-11-21 BY MICHAEL KIRCHER
The original image should be cropped to 1.4:1 ratio, then resized to 80x192, and finally converted to grey-scale. A similar program exists for converting monochrome bitmaps.

Here's an example:

Image

Greetings,

Michael
Last edited by Mike on Fri Dec 14, 2012 1:36 pm, edited 2 times in total.
saehn
Vic 20 Devotee
Posts: 235
Joined: Wed Apr 01, 2009 12:22 pm

Post by saehn »

Mike wrote:Like in VICtoria Gold Edition? :wink:
Kind of. Explained below:
Mike wrote:I'd like to know what's "low-res" about being able to change individual pixels (or twice-wide pixels in multi-colour). :?
I'm visualizing each character as containing 4 chunky pixels. Each chunky pixel is two pixels wide and four tall. In the example below, there would be three active colors in the chunky pixel block.

00 00 | 11 11
00 00 | 11 11
00 00 | 11 11
00 00 | 11 11
-------+------
10 10 | 01 01
10 10 | 01 01
10 10 | 01 01
10 10 | 01 01

There are exactly 256 permutations of this pattern, including all color combinations. By redefining the character set, keeping a "char-bitmap", and maintaining color info, an unexpanded VIC should be able to display full-screen full-color low-res graphics. One consistent @border, @screen, and @auxiliary color with one character color per block. Hopefully? ;-)

I can't seem to figure out your program, it's not working for me. The resulting graphic looks really great but I'm trying to come up with something for the unexpanded VIC.

Results like this. It's only four colors and not at the right ratio, but you can see what I mean. 44x46 effective resolution, and you can get some pretty good result I think. And this is without using any individual character colors. I think this chunky mode would be a good addition to unexpanded VIC games, and I'd love to work within this mode.

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

Post by Mike »

saehn wrote:I'm visualizing each character as containing 4 chunky pixels. Each chunky pixel is two pixels wide and four tall.
This you mean. :idea:

Expanding on carlsson's program, you'd define the char-set as follows:

Code: Select all

10 poke55,0:poke56,22:poke648,22:clr 
15 poke36869,208:print"{clr}" 
20 fora=0to3:forb=0to3:forc=0to3:ford=0to3
25 ad=6144+8*(d*64+c*16+b*4+a)
30 b1=16*5*a+5*b
35 b2=16*5*c+5*d
40 fory=0to3:pokead+y,b1:pokead+y+4,b2:next
45 next:next:next:next
50 poke36869,222
Then you'd have the colours a,b,c, and d in the quadrant of each char as:

Code: Select all

a|b
-+-
c|d
with the character number:

Code: Select all

char := d*64+c*16+b*4+a
I can't seem to figure out your program, it's not working for me.
The program uses my MINIGRAFIK extension for CBM BASIC to create a 160x192 pixel screen. Its commands are prefaced with '@'.

Code: Select all

@C%(YAND3,(24*ASC(A$+NU$)+255)/510,XAND1),2*X,Y
plots a single pixel at the co-ordinates (2*X,Y) (2*X to accommodate for the twice-wide multi-colour pixels), where the logical colour is taken from the array C%() in a fashion to produce an ordered dither pattern for different intensities.

These dither patterns are defined in the bottom DATA lines, and provide for 13 different intensities calculated from the original 256. White, and black are fixed; the intermediary two colours can use any combination of the 16 available physical colours.
The resulting graphic looks really great [...]
Me :D.
I think this chunky mode would be a good addition to unexpanded VIC games, and I'd love to work within this mode.

Image
Is she Brooke Shields? :)

Greetings,

Michael
Last edited by Mike on Tue Apr 07, 2009 4:52 pm, edited 1 time in total.
saehn
Vic 20 Devotee
Posts: 235
Joined: Wed Apr 01, 2009 12:22 pm

Post by saehn »

Mike wrote:This you mean. :idea: ...
Exactly!
Mike wrote:The program uses my MINIGRAFIK extension for CBM BASIC to create a 160x192 pixel screen. Its commands are prefaced with '@'.
Thanks, I get it now. I just need to get that expansion and play around with it one day.
Mike wrote:Is she Brooke Shields? :)
No, it's my other wife, Jennifer Connelly. :D
saehn
Vic 20 Devotee
Posts: 235
Joined: Wed Apr 01, 2009 12:22 pm

Post by saehn »

Mike wrote:Expanding on carlsson's program, you'd define the char-set as follows:

Code: Select all

10 poke55,0:poke56,22:poke648,22:clr 
15 poke36869,208:print"{clr}" 
20 fora=0to3:forb=0to3:forc=0to3:ford=0to3
25 ad=6144+8*(d*64+c*16+b*4+a)
30 b1=16*5*a+5*b
35 b2=16*5*c+5*d
40 fory=0to3:pokead+y,b1:pokead+y+4,b2:next
45 next:next:next:next
50 poke36869,222
Sorry, Mike... I feel stupid for asking this, but now how do I access all of these new characters individually? They don't all appear when I display CHR$(0-255), so I'm guessing there's some other method? Screen codes? But, after running this program, the screen memory has been moved. POKE7680,x doesn't put a character at the top-left of the screen.
User avatar
Mike
Herr VC
Posts: 4832
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Post by Mike »

Saehn wrote:How do I access all of these new characters individually? ... Screen codes?
Yes, you need the screen codes. With CHR$() alone you'd miss out the reverse characters, unless you'd also use {RVS ON} and {RVS OFF}.

And of course, you surely want to set a single chunky pixel in a char position, without disturbing the other three. This needs some more work: you first read out the old contents of the char position, alter only the relevant two bits, and then write it back.
But, after running this program, the screen memory has been moved. POKE7680,x doesn't put a character at the top-left of the screen.
The screen starts at 5632 ($1600), and colour RAM is still at 38400 ($9600).

These two lines clear the screen to black, and assign physical colours to the logical colours:

Code: Select all

55 poke36879,16*10+8+0:poke36878,16*2
60 fort=0to505:poke5632+t,85:poke38400+t,8+1:next
(1/exterior border colour=black, 3/auxiliary colour=red, 0/background=light red, 2/foreground=white)

The next lines draw a centered "circle" in all four colours, and then repeat:

Code: Select all

65 r1=12:r2=20
70 forc=0to3:forp=0to2*{PI}step.05
75 x=int(r1*cos(p)+22.5):y=int(r2*sin(p)+23.5)
80 gosub100
85 next:next
90 goto 70
95 :
(Small note of caution: line 70 contains a {PI} which won't come out correct, when using copy&paste in VICE. You'll have to correct it manually.)

And this sub-routine draws individual chunky pixels in logical colour C at (X,Y):

Code: Select all

100 ad=5632+22*int(y/2)+int(x/2)
105 m=3
110 if(xand1)=1thenm=m*4
115 if(yand1)=1thenm=m*16
120 pokead,(peek(ad)andnotm)or(c*85andm)
125 return
Greetings,

Michael
saehn
Vic 20 Devotee
Posts: 235
Joined: Wed Apr 01, 2009 12:22 pm

Post by saehn »

Thanks so much Mike, that's a huge amount of detail and very helpful! I feel like I have a much better handle on all of this now.

Great little demo, too.
User avatar
Mike
Herr VC
Posts: 4832
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Post by Mike »

saehn wrote:Thanks so much Mike, that's a huge amount of detail and very helpful! I feel like I have a much better handle on all of this now.
I'm very pleased to read that. :D
I just need to get that expansion and play around with it one day.
The VIC must be equipped with at least an 8K RAM expansion. Start MINIGRAFIK first, then run PGM IMPORT. At the prompt:

Code: Select all

PGM FILE? AVRIL.PGM
TARGET? any name you wish
COLOUR 1? 2 (instead of 8)
COLOUR 2? 10 (instead of 9)
When the header has been checked, the program waits for a key. Then the *.pgm file is converted. This takes a few minutes (feel free to set 'No speed limit' with VICE ;) ). After another key press, the program saves the screen in MG format.

This file can be used in two ways: Either MINIGRAFIK is loaded. Then you can load the image within a program, with @LOAD, and continue processing. Or MINIGRAFIK is not loaded (or it isn't available). In that case you can simply LOAD the file (',8', not ',8,1'), RUN it, and then the image is displayed. A stand-alone display routine is built-in. After a keypress the VIC resets.

Greetings,

Michael
Post Reply