vgi: more work on triangles and too-big points

This commit is contained in:
Vince Weaver 2021-06-21 12:34:43 -04:00
parent 6dafbd8ba6
commit 2088611f97
5 changed files with 228 additions and 21 deletions

144
graphics/hgr/vgi/README.VGI Normal file
View File

@ -0,0 +1,144 @@
VGI -- VMW Retro Vector Graphics Interface
This was designed mostly as a proof-of-concept to drawing some Myst
scenes. Might not work well for general graphics.
The Apple II Hi-res screen is 280x192 and 6 colors with lots of limitations
that are a bit complex to get into here. Some of the limitations in the
interface here are working around Apple II issues.
Apple II Hi-res Colors:
~~~~~~~~~~~~~~~~~~~~~~~
0 = black (for purple/green)
1 = green
2 = purple
3 = white (for purple/green)
4 = black (for blue/orange)
5 = orange
6 = blue
7 = white (for blue/orange)
Note Apple II uses NTSC artifact colors, so weird things happens when
you try to put colors next to each other:
+ Colors need to be two pixels wide, if you draw single width
they may not appear depending on even/odd column
+ White lines drawn single width will be colored instead
+ Two colors of same group next to each other will have white or black
border between
+ Two colors of different group next to each other will have odd effects
as can only change group every 3.5 pixels.
The VGI Commands
~~~~~~~~~~~~~~~~
===================
VGI Clearscreen (0)
CLS color
clears screen using ROM routine using color
=================
VGI Rectangle (1)
RECT color1 color2 x1 y1 x2 y2
draw filled rectangle from (x1,y1) to (x2,y2)
color1 and color2 are drawn as alternating colors (horizontal stripes)
x1 must be < 255. relative drawing is used so x2 can go to
the edge of the screen (279)
==============
VGI Circle (2)
CIRC color cx cy r
Draw a circle of color with center (cx,cy) and radius r
Circles with radius 0 will give an interesting non-circle effect.
Bresenham circles are drawn and so certain sizes don't look the
best. Also if the radius is too big things might break
as the 8-bit unsigned int oveflows
=====================
VGI Filled Circle (3)
FCIRC color cx cy r
Draw a filled circle of color at location (cx,cy) with radius r
=============
VGI Point (4)
POINT color x y
Draws a point of color at (x,y)
Note, X can be up to 279 here (the color is overloaded behind
the scenes to support this)
The last point you draw is the starting point for LINETO
==============
VGI Lineto (5)
LINETO x y
Draws a line to (x,y). The starting point and color come from
the last POINT command.
Note X cannot be > 255 so it can be trouble drawing at the right
edge of the screen. POINT can go up to 279, so you might be able
to get what you want by drawing from right to left
==========================
VGI Dithered Rectangle (6)
DRECT c1 c2 x1 y1 x2 y2
Draws a rectangle, but this time the two colors are raw bitmaps
for the output colors, not one of the Apple II colors. This lets
you do fancier dithered color patterns, but it's really hard
getting dither patterns that look nice.
=========================
VGI Vertical Triangle (7)
VTRI color vx vy xl xr yb
Draw a flat bottom filled triangle of color.
The top vertex is at (vx,vy)
The bottom goes from (xl,yb) to (xr,yb)
If your triangle is too tall you might get moire effects.
This was much simpler than a proper filled triangle routine.
===========================
VGI Horizontal Triangle (8)
HTRI color vx vy yt yb xr
Draw a flat-sided filled triangle of color.
The side vertex is at (vx,vy)
The opposite side goes from (xr,yt) to (xr,yb)
============
VGI End (15)
END
this tells the drawing routine that we are done
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -111,6 +111,10 @@ int main(int argc, char **argv) {
&color1,
&x1,&y1);
printf(".byte $%02X,",(type<<4)|4);
if (x1>255) {
x1=x1&0xff;
color1|=128;
}
printf("$%02X,",color1);
printf("$%02X,",x1);
printf("$%02X\n",y1);

View File

@ -2,25 +2,72 @@
CLS 255 ; white background
RECT 1 6 0 122 140 191 ; ocean left
RECT 1 6 140 122 279 191 ; ocean right
; rock
RECT 1 5 239 171 279 191 ; green/orange rock
VTRI 4 228 162 226 245 171 ; black edge
VTRI 4 228 162 224 244 185 ; black edge
VTRI 4 232 191 224 244 184 ; upside down
VTRI 4 255 165 245 255 171 ; black right edge
VTRI 4 255 178 245 255 171 ; black right edge
RECT 4 4 255 170 279 178 ; rock shade
RECT 4 4 255 163 270 178 ; rock shade
; base
DRECT 0x8 0x22 86 124 193 191 ; green brick dock
FCIRC 7 99 121 4 ; left platform
FCIRC 7 180 121 4 ; right platform
RECT 7 7 99 119 175 125 ; platform
RECT 7 7 99 119 175 127 ; platform
RECT 0 0 102 128 116 191 ; left shade
RECT 0 0 156 126 169 191 ; center shade
RECT 0 0 179 126 194 191 ; right shade
RECT 7 7 89 137 93 146 ; left light
RECT 7 7 186 139 190 147 ; right light
RECT 3 3 89 137 93 146 ; left light
RECT 3 3 186 139 190 147 ; right light
; walkway
VTRI 7 129 129 109 129 191 ; left path
RECT 7 7 129 129 151 191 ; center path
VTRI 7 151 129 151 170 191 ; right path
; wire
VTRI 1 128 129 101 109 191 ; left path green
VTRI 3 129 129 109 129 191 ; left path white
RECT 3 3 129 129 151 191 ; center path
VTRI 1 153 129 170 179 191 ; right path green
VTRI 3 152 129 152 170 191 ; right path white
POINT 0 152 129 ; right gap
LINETO 170 191 ; right gap
POINT 0 129 129 ; left gap
LINETO 109 191 ; left gap
; left railing
POINT 0 127 115 ; far left pole
LINETO 128 133
POINT 3 127 115 ; far left rope
LINETO 122 129
POINT 2 123 126 ; center left pole
LINETO 123 147
POINT 3 120 128 ; center left rope
LINETO 116 144
LINETO 109 154
LINETO 99 158
RECT 2 2 97 164 100 191 ; near pole
FCIRC 2 98 161 4 ; near pole circle
; right railing
POINT 0 153 117 ; far right pole
LINETO 152 132
POINT 3 153 118 ; far right rope
LINETO 157 129
POINT 2 158 126 ; center right pole
LINETO 157 141
POINT 3 158 127 ; center right rope
LINETO 162 142
LINETO 168 154
LINETO 178 160
RECT 2 2 177 164 181 191 ; near pole
FCIRC 2 179 161 4 ; near pole circle
; wire pole
RECT 6 6 174 88 179 126 ; pole
RECT 6 6 174 73 179 80 ; insulator
POINT 6 177 90 ; thinner pole
LINETO 177 74 ; to top
LINETO 237 64 ; to top
;LINETO 279 53 ; to top
LINETO 255 60 ; to top
; power wire
POINT 6 279 54 ; from off screen
LINETO 238 65
LINETO 177 74
LINETO 170 82
LINETO 173 85
LINETO 189 88
LINETO 209 86
END

View File

@ -4,16 +4,22 @@
; VGI point
;========================
VGI_PCOLOR = P0
VGI_PCOLOR = P0 ; if high bit set, then PX=PX+256
VGI_PX = P1
VGI_PY = P2
vgi_point:
ldx VGI_PCOLOR
ldy #0
lda VGI_PCOLOR
bpl vgi_point_color
iny
vgi_point_color:
and #$7f
tax
lda COLORTBL,X
sta HGR_COLOR
ldy #0
ldx VGI_PX
lda VGI_PY

View File

@ -1,5 +1,6 @@
; VGI Triangles
;========================
; VGI vertical triangle
;========================
@ -7,8 +8,9 @@
VGI_TCOLOR = P0
VGI_VX = P1
VGI_VY = P2
VGI_TX1 = P3
VGI_TX2 = P4
VGI_TXL = P3
VGI_TXR = P4
VGI_TYB = P5
vgi_vertical_triangle:
@ -16,6 +18,7 @@ vgi_vertical_triangle:
lda COLORTBL,X
sta HGR_COLOR
vtri_loop:
ldy #0
ldx VGI_VX
lda VGI_VY
@ -23,15 +26,18 @@ vgi_vertical_triangle:
jsr HPLOT0 ; plot at (Y,X), (A)
; ldx #0
; ldy VGI_LY
; lda VGI_LX
ldx #0
ldy VGI_TYB
lda VGI_TXL
; jsr HGLIN ; line to (X,A),(Y)
; jmp vgi_loop
jsr HGLIN ; line to (X,A),(Y)
inc VGI_TXL
lda VGI_TXL
cmp VGI_TXR
bcc vtri_loop
done_vtri:
jmp vgi_loop