Hires Graphics
Moderator: Moderators
Hires Graphics
The following program was listed in Elektronikvärlden, issue 6/7 June 1983. The hires routines were written by Thomas Magnusson, and presented as a ML listing, so VIC-MON or similar was required in order to input it. They used a lot of space describing the technique and some applications, but I think most people would have been better off with a Basic DATA loader.
The routines take 0.5K, the hires screen takes another 2K which leaves about 1K on an unexpanded machine. The routines would surely be possible to relocate or improve upon, but I haven't tried it yet. There may be better algorithms for e.g. line drawing too. Due to the limitations, there are no Basic extentions, so all routines are called via POKE and SYS:
Initialize screen
SYS 7168
Set dot colour to F
POKE 0,F:SYS 7212
Clear Screen
SYS 7223
Set Dot X,Y
POKE 0,X:POKE 1,Y:SYS 7346
Clear Dot X,Y
POKE 0,X:POKE 1,Y:SYS 7360
If Dot X,Y Then
POKE 0,X:POKE 1,Y:SYS 7373:IF PEEK(2) THEN
Draw Line X1,Y1 to X2,Y2
POKE 0,X1:POKE 1,Y1:POKE 2,X2:POKE 3,Y2:SYS 7576
Clear Line X1,Y1 to X2,Y2
POKE 0,X1:POKE 1,Y1:POKE 2,X2:POKE 3,Y2:SYS 7584
Save picture to tape
SYS 7592
Load picture from tape, set dot colour F, border R and background B
POKE 0,F:POKE 1,R:POKE 2,B:SYS 7610
Set dot colour F, border R and background B
POKE 0,F:POKE 1,R:POKE 2,B:SYS 7628
If you do SYS 7631, only border and background (equals POKE 36879) will change. The author suggests assigning variables such as:
SD=7346:POKE 0,X:POKE 1,Y:SYS SD
http://www.cbm.sfks.se/files/hires.d64
The routines take 0.5K, the hires screen takes another 2K which leaves about 1K on an unexpanded machine. The routines would surely be possible to relocate or improve upon, but I haven't tried it yet. There may be better algorithms for e.g. line drawing too. Due to the limitations, there are no Basic extentions, so all routines are called via POKE and SYS:
Initialize screen
SYS 7168
Set dot colour to F
POKE 0,F:SYS 7212
Clear Screen
SYS 7223
Set Dot X,Y
POKE 0,X:POKE 1,Y:SYS 7346
Clear Dot X,Y
POKE 0,X:POKE 1,Y:SYS 7360
If Dot X,Y Then
POKE 0,X:POKE 1,Y:SYS 7373:IF PEEK(2) THEN
Draw Line X1,Y1 to X2,Y2
POKE 0,X1:POKE 1,Y1:POKE 2,X2:POKE 3,Y2:SYS 7576
Clear Line X1,Y1 to X2,Y2
POKE 0,X1:POKE 1,Y1:POKE 2,X2:POKE 3,Y2:SYS 7584
Save picture to tape
SYS 7592
Load picture from tape, set dot colour F, border R and background B
POKE 0,F:POKE 1,R:POKE 2,B:SYS 7610
Set dot colour F, border R and background B
POKE 0,F:POKE 1,R:POKE 2,B:SYS 7628
If you do SYS 7631, only border and background (equals POKE 36879) will change. The author suggests assigning variables such as:
SD=7346:POKE 0,X:POKE 1,Y:SYS SD
http://www.cbm.sfks.se/files/hires.d64
Anders Carlsson
- Mike
- Herr VC
- Posts: 4839
- Joined: Wed Dec 01, 2004 1:57 pm
- Location: Munich, Germany
- Occupation: electrical engineer
I always was under the impression, that 'POKE and SYS' extensions for graphics didn't buy you much. After all, you still have to assign the pixel coordinates with POKE, while setting a pixel can also be done like in:
provided, the array BI() is suitably initialised. The only thing that really gains from assembly - when the client program is written in BASIC - is the screen clear routine. To illustrate my point I went ahead yesterday, and wrote a function plotter:
A RAM expansion is required. The program needs to be kept out of the place needed for the hires bitmap:
For +3K type: POKE 56,16:POKE648,16 + [RETURN] + [STOP/RESTORE].
For +8K (or more) type: POKE44,32:POKE8192,0:NEW + [RETURN]
before loading and running.
You see, most of the program doesn't have to do with access to the graphics. The pixel set routine is a subroutine in line 200, and I can live with the 6 lines at the beginning, that initialise and clear the graphics.
The ML part also contains a small routine that provides an ON ERROR GOTO 180 (if, for example, a calculation leads to a 'Division by Zero', the program still continues). Therefore the line 180 must not be renumbered.
Greetings,
Michael
Edit: In line 191 I replaced SYS8192 for another SYS that's guaranteed to contain a BRK instruction.
Code: Select all
AD=4352+INT(X/8)*192+Y:POKEAD,PEEK(AD)ORBI(XAND7)
Code: Select all
100 REM ** INITIALISE GRAPHICS
101 V=36864:FORT=0TO32:READA:POKE673+T,A:NEXT
102 POKEV+0,PEEK(60900)+2:POKEV+1,PEEK(60901)-2
103 POKEV+2,20:POKEV+3,25:POKEV+5,204:POKEV+15,27
104 FORY=0TO11:FORX=0TO19:POKE4096+Y*20+X,X*12+Y+16
105 POKE37888+Y*20+X,6:NEXT:NEXT:SYS673
106 DIMBI(7):S=1:FORT=0TO7:BI(7-T)=S:S=2*S:NEXT
107 :
110 REM ** SET SCREEN DIMENSIONS
111 XM=158:YM=190
112 :
120 REM ** SET DISPLAY RANGE
121 X0=-2.0:X1=3.0:XS=0.5
122 Y0=-5.0:Y1=5.0:YS=2.0
123 :
130 REM ** DRAW AXES AND SCALES
131 DX=(X1-X0)/XM:DY=(Y1-Y0)/YM
132 DEFFNX(Z)=INT((Z-X0)/DX+.5)
133 DEFFNY(Z)=INT((Z-Y0)/DY+.5)
134 XA=FNX(0):YA=FNY(0)
135 IFXA>=0ANDXA<=XMTHENXP=XA:FORYP=0TOYM:GOSUB200:NEXT
136 IFYA>=0ANDYA<=YMTHENYP=YA:FORXP=0TOXM:GOSUB200:NEXT
137 IFXA<0THENXA=0
138 IFXA>XMTHENXA=XM
139 IFYA<0THENYA=0
140 IFYA>YMTHENYA=YM
141 R=INT(X0/XS-1):S=INT(X1/XS+1)
142 FORT=RTOS:XP=FNX(XS*T):IFXP<0ORXP>XMTHEN144
143 FORYP=YA+(YA>0)TOYA-(YA<YM):GOSUB200:NEXT
144 NEXT
145 R=INT(Y0/YS-1):S=INT(Y1/YS+1)
146 FORT=RTOS:YP=FNY(YS*T):IFYP<0ORYP>YMTHEN148
147 FORXP=XA+(XA>0)TOXA-(XA<XM):GOSUB200:NEXT
148 NEXT
149 :
150 REM ** NUMBER OF FUNCTIONS
151 N=2:I=1
152 :
160 REM ** PLOT FUNCTIONS
161 XG=0:YF=-1
162 X=DX*XG+X0:YG=-1:POKE768,183:POKE769,2
163 ONIGOTO164,165,166,167,168,169,170,171,172,173
164 Y=(((8*X-14)*X-4)*X+8)*X+2:GOTO179
165 Y=X+1:GOTO179
166 Y=0:GOTO179
167 Y=0:GOTO179
168 Y=0:GOTO179
169 Y=0:GOTO179
170 Y=0:GOTO179
171 Y=0:GOTO179
172 Y=0:GOTO179
173 Y=0:GOTO179
178 :
179 YG=FNY(Y):IFYG<0ORYG>YMTHENYG=-1
180 REM ** NEVER RENUMBER THIS LINE
181 POKE768,58:POKE769,196:IFYG<>-1THENXP=XG:YP=YG:GOSUB200
182 IFYG=-1ORYF=-1ORABS(YF-YG)<2THEN185
183 YH=INT((YF+YG)/2):XP=XG-1:FORYP=YFTOYGSTEPSGN(YG-YF):IFYP=YHTHENXP=XG
184 GOSUB200:NEXT
185 YF=YG:XG=XG+1:IFXG<=XMTHEN162
186 I=I+1:IFI<=NTHEN161
190 REM ** WAIT FOR KEY TO FINISH
191 POKE198,0:WAIT198,1:SYS678
192 END
199 :
200 AD=4543+INT(XP/8)*192-YP:POKEAD,PEEK(AD)ORBI(XPAND7):RETURN
299 :
300 DATA169,17,133,252,169,0,133,251,168,162,15
301 DATA145,251,200,208,251,230,252,202,208,246,96
302 DATA169,180,133,20,169,0,133,21,76,163,200
399 :
400 REM ** VIC-20 FUNCTION PLOTTER
401 REM WRITTEN 2006-01-29 BY
402 REM MICHAEL KIRCHER
For +3K type: POKE 56,16:POKE648,16 + [RETURN] + [STOP/RESTORE].
For +8K (or more) type: POKE44,32:POKE8192,0:NEW + [RETURN]
before loading and running.
You see, most of the program doesn't have to do with access to the graphics. The pixel set routine is a subroutine in line 200, and I can live with the 6 lines at the beginning, that initialise and clear the graphics.
The ML part also contains a small routine that provides an ON ERROR GOTO 180 (if, for example, a calculation leads to a 'Division by Zero', the program still continues). Therefore the line 180 must not be renumbered.
Greetings,
Michael
Edit: In line 191 I replaced SYS8192 for another SYS that's guaranteed to contain a BRK instruction.
- Mike
- Herr VC
- Posts: 4839
- Joined: Wed Dec 01, 2004 1:57 pm
- Location: Munich, Germany
- Occupation: electrical engineer
Re: Hires Graphics
I had another programming session this weekend, thinking over a BASIC extension for the 160x192 hires mode.
In doing so I re-implemented the BASIC commands and function I once had in the MINIGRAFIK extension I mentioned here in another thread. I couldn't fit it into 256 Bytes however, mostly because 128x128 pixels (as in the original MINIGRAFIK) do have an easier address scheme, really. Then I replaced the relevant statements in the function plotter with the @-commands, and really was surprised, that the speed nearly doubled.
Cheers,
Michael
Edit: MINIGRAFIK V2 is obsolete. Please use V4.02 instead.
In doing so I re-implemented the BASIC commands and function I once had in the MINIGRAFIK extension I mentioned here in another thread. I couldn't fit it into 256 Bytes however, mostly because 128x128 pixels (as in the original MINIGRAFIK) do have an easier address scheme, really. Then I replaced the relevant statements in the function plotter with the @-commands, and really was surprised, that the speed nearly doubled.
So here it is: MINIGRAFIK V2, for 160x192 pixels. Beautifully cast into a DATA desert.carlsson wrote:[...], but I think most people would have been better off with a Basic DATA loader.
Code: Select all
[BASIC DATA loader deleted]
Michael
Edit: MINIGRAFIK V2 is obsolete. Please use V4.02 instead.
Last edited by Mike on Thu Mar 15, 2012 10:08 am, edited 1 time in total.
Hmmm.... I don't think that will work. But you could probably use Björg's basic editor. Or you could use the Yape Plus/4 emulator to paste text into the emulator's screen (because I don't think you can do that in VICE??).
PRG Starter - a VICE helper / Vic Software (Boray Gammon, SD2IEC music player, Vic Disk Menu, Tribbles, Mega Omega, How Many 8K etc.)
I just tried the copy/paste feature on yape(060), and it worked to a point. The file was there, but it contained errors like:
Got an illegal quantity error- yape lost some of the commas, making the numbers run together.
Got out of data error- yape omitted numbers, I even saw where the data entry 144 was changed to 145.
Not bad, but alot of proofreading after the file is transfered. This would be a great upgrade for Vice as long as the bugs were worked out.
Got an illegal quantity error- yape lost some of the commas, making the numbers run together.
Got out of data error- yape omitted numbers, I even saw where the data entry 144 was changed to 145.
Not bad, but alot of proofreading after the file is transfered. This would be a great upgrade for Vice as long as the bugs were worked out.
Rob
Cut&paste into my BasEdit and saved as Basic File:
http://www.stojalowski.de/files/minigrafx.prg
Didn't test it, but at least it looked ok
Björg
http://www.stojalowski.de/files/minigrafx.prg
Didn't test it, but at least it looked ok
Björg
- Mike
- Herr VC
- Posts: 4839
- Joined: Wed Dec 01, 2004 1:57 pm
- Location: Munich, Germany
- Occupation: electrical engineer
Two example programs
I wrote two small example programs, that use the MINIGRAFIK extension. The first one does 3D-Graphics:
Set aside a pot of coffee, and watch. It runs ~22 Minutes to completion.
The second program portrays the Mandelbrot set:
Here you should have more time to spare. It needs roughly 2 1/2 hours to finish. Alternatively run it in VICE and choose 'no speed limit'.
Cheers,
Michael
P.S.: The ':' between THEN and an '@' command is necessary. Otherwise you'll get a ?SYNTAX ERROR. This 'bug' is typical for this kind of BASIC extension.
Code: Select all
10 DIMMI(159),MA(159)
11 FORX=0TO159:MI(X)=192:MA(X)=-1:NEXT
12 POKE36879,26:@ON:@CLR
13 FORY=30TO-30STEP-1:XP=INT(2*SQR(900-Y*Y)+.5)
14 FORX=-XPTOXP:XR=X/28:YR=Y/14:R=SQR(XR*XR+YR*YR)
15 F=COS(R)-COS(3*R)/3+COS(5*R)/5-COS(7*R)/7
16 FL=0:XP=80+X-Y:YP=96+2*Y-INT(40*F+.5)
17 IFMI(XP)>YPTHENMI(XP)=YP:FL=1
18 IFMA(XP)<YPTHENMA(XP)=YP:FL=1
19 IFFLANDYP>=0ANDYP<192THEN:@1,XP,YP
20 NEXT:NEXT:POKE36879,27
21 GETA$:IFA$=""THEN21
22 @RETURN
The second program portrays the Mandelbrot set:
Code: Select all
10 X=0:Y=0:X2=0:Y2=0:XY=0:R=0:J=0
11 DIMD(2,159),R(159),J(191):A=0:B=1:C=2
12 R0=-2.4:R1=+0.8:DR=(R1-R0)/160:FORS=0TO159:R(S)=R0+DR*S:NEXT
13 J0=-1.25:J1=+1.25:DJ=(J1-J0)/192:FORT=0TO191:J(191-T)=J0+DJ*T:NEXT
14 N=30
15 POKE36879,14:POKE646,1:@ON:@CLR
16 FORT=0TO191:J=J(T):FORS=0TO159:R=R(S):X=R:Y=J
17 FORI=1TON:X2=X*X:Y2=Y*Y:IFX2+Y2<4THENXY=X*Y:X=X2-Y2+R:Y=XY+XY+J:NEXT
18 D(C,S)=I:IFI<=NTHEN:@1,S,T
19 IFS<2ORT<2THEN28
20 IF@(S-1,T-1)=0THEN28
21 M=D(B,S-1)
22 IFD(B,S-2)<MANDD(B,S)<MTHEN27
23 IFD(A,S-2)<MANDD(C,S)<MTHEN27
24 IFD(C,S-2)<MANDD(A,S)<MTHEN27
25 IFD(A,S-1)<MANDD(C,S-1)<MTHEN27
26 GOTO28
27 @0,S-1,T-1
28 NEXTS:Z=A:A=B:B=C:C=Z:NEXT
29 GETA$:IFA$=""THEN29
30 POKE36879,27:POKE646,6:@RETURN
Cheers,
Michael
P.S.: The ':' between THEN and an '@' command is necessary. Otherwise you'll get a ?SYNTAX ERROR. This 'bug' is typical for this kind of BASIC extension.
- Mike
- Herr VC
- Posts: 4839
- Joined: Wed Dec 01, 2004 1:57 pm
- Location: Munich, Germany
- Occupation: electrical engineer
Another example, with 3 useful sub-routines
Time for a bigger program. This example draws a 'minigrafik' logo. First the 'minigrafik' caption is read from DATA statements, and drawn using a line-routine (it's here only used to draw vertical lines).
Then two ellipses are drawn. I've assumed a 1.67:1 ratio for a VIC pixel on a TV set, so these ellipses actually should come out as circles. In VICE they'll appear more flattened.
Finally the gap between these two ellipses is filled with a flood fill routine.
The main program in the lines 1-9 shows, how to call the sub-routines in your own programs.
Greetings,
Michael
Then two ellipses are drawn. I've assumed a 1.67:1 ratio for a VIC pixel on a TV set, so these ellipses actually should come out as circles. In VICE they'll appear more flattened.
Finally the gap between these two ellipses is filled with a flood fill routine.
The main program in the lines 1-9 shows, how to call the sub-routines in your own programs.
Greetings,
Michael
Code: Select all
1 REM ** MINIGRAFIK DEMO
2 POKE36879,14:POKE646,7:@ON:@CLR
3 READX:IFX<>-1THENX1=X+31:X2=X1:READA,B:Y1=113-A:Y2=113-B:GOSUB40:GOTO3
4 MX=80:MY=96:A=54:B=90:GOSUB50:A=57:B=95:GOSUB50
5 X=111:Y=173:GOSUB70
6 GETA$:IFA$=""THEN6
7 POKE36879,27:POKE646,6:@RETURN
8 END
9 :
10 DATA1,9,24,2,15,24,3,21,23,4,23,24,5,23,25,6,23,25,7,9,24,8,9,23,9,20,23,10,22,24
11 DATA11,23,25,12,23,25,13,23,25,14,10,24,15,9,22,16,9,10,17,10,11
12 :
13 DATA19,11,22,19,29,30,20,9,24,20,29,30,21,9,10,22,10,11
14 :
15 DATA25,9,24,26,9,24,27,19,22,28,22,24,29,23,25,30,23,25,31,23,25,32,10,24,33,9,22
16 DATA34,9,10,35,10,11
17 :
18 DATA37,11,22,37,29,30,38,9,24,38,29,30,39,9,10,40,10,11
19 :
20 DATA43,13,18,44,2,3,44,11,21,45,1,3,45,10,12,45,20,23,46,1,3,46,9,11,46,22,24,47,1,3
21 DATA47,9,11,47,23,24,48,2,3,48,10,11,48,23,25,49,2,4,49,11,12,49,23,25,50,3,10
22 DATA50,12,15,50,23,25,51,6,25,52,19,24
23 :
24 DATA55,9,24,56,11,24,57,20,23,58,22,24,59,23,25,60,23,25
25 :
26 DATA63,13,18,64,11,22,65,10,12,65,20,23,66,9,11,66,22,24,67,9,11,67,23,24,68,10,12
27 DATA68,23,25,69,11,13,69,23,25,70,10,25,71,9,24,72,9,10,73,10,11
28 :
29 DATA71,1,3,72,1,3,73,1,3,74,2,4,74,23,24,75,3,7,75,23,24,76,4,30,77,11,32,78,23,24
30 DATA78,31,33,79,23,24,79,32,34,80,32,34,81,33,33
31 :
32 DATA82,11,22,82,29,30,83,9,24,83,29,30,84,9,10,85,10,11
33 :
34 DATA88,9,34,89,16,34,90,16,18,90,21,23,91,14,18,91,22,24,92,12,15,92,17,19,92,23,25
35 DATA93,10,13,93,18,20,93,23,25,94,9,11,94,19,24,95,9,11,95,20,23,96,10,11
36 :
37 DATA-1
38 :
39 REM ** LINE DRAW
40 DX=X2-X1:DY=Y2-Y1:IFDX=0ANDDY=0THEN:@1,X1,Y1:RETURN
41 IFABS(DX)<ABS(DY)THEN43
42 M=DY/DX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HAEL KIRCHER
- Mike
- Herr VC
- Posts: 4839
- Joined: Wed Dec 01, 2004 1:57 pm
- Location: Munich, Germany
- Occupation: electrical engineer
The reason why the thread runs under 'ML and other programs'. You'll need to run my MINIGRAFIK extension first. This is the DATA loader further up this topic. You can then use the following commands:Jeff-20 wrote:"@"?
Code: Select all
@ON : initialise 160x192 pixel hires screen
@CLR : clear hires screen, and set colour RAM
@RETURN : back to text mode
@<colour>,<x>,<y> : set point in <colour> at <x>,<y>
Code: Select all
<colour>: =0, clear point; =1, set point
<x>: between 0 and 159
<y>: between 0 and 191
Code: Select all
@(<x>,<y>) : returns 0 if pixel is clear at <x>,<y>; 1 if it is set.
Michael