vgi: prepare for triangles

This commit is contained in:
Vince Weaver 2021-06-21 11:12:21 -04:00
parent eb9a362a89
commit 6dafbd8ba6
5 changed files with 161 additions and 46 deletions

View File

@ -25,7 +25,8 @@ VGI: vgi.o
ld65 -o VGI vgi.o -C $(LINKERSCRIPTS)/apple2_c00.inc
vgi.o: clock.data rocket.data \
vgi.s vgi_clearscreen.s vgi_rectangle.s vgi_circles.s vgi_lines.s
vgi.s vgi_clearscreen.s vgi_rectangle.s vgi_circles.s vgi_lines.s \
vgi_triangles.s
ca65 -o vgi.o vgi.s -l vgi.lst

View File

@ -1,31 +1,79 @@
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#define VGI_CLEARSCREEN 0
#define VGI_RECTANGLE 1
#define VGI_CIRCLE 2
#define VGI_FILLED_CIRCLE 3
#define VGI_POINT 4
#define VGI_LINETO 5
#define VGI_DITHER_RECTANGLE 6
#define VGI_VERT_TRIANGLE 7
#define VGI_HORIZ_TRIANGLE 8
#define VGI_END 15
int main(int argc, char **argv) {
char buffer[1024];
char *ptr;
int type,color1,color2,x1,x2,y1,y2,r;
int type,color1,color2,x1,x2,y1,y2,r,xl,xr,yt,yb;
int line=1;
while(1) {
type=0;
ptr=fgets(buffer,1024,stdin);
if (ptr==NULL) break;
if (buffer[0]==';') continue;
sscanf(buffer,"%i",&type);
if (isalpha(buffer[0])) {
if (!strncmp(buffer,"CLS",3)) {
type=VGI_CLEARSCREEN;
}
if (!strncmp(buffer,"RECT",4)) {
type=VGI_RECTANGLE;
}
if (!strncmp(buffer,"CIRC",4)) {
type=VGI_CIRCLE;
}
if (!strncmp(buffer,"FCIRC",5)) {
type=VGI_FILLED_CIRCLE;
}
if (!strncmp(buffer,"POINT",5)) {
type=VGI_POINT;
}
if (!strncmp(buffer,"LINETO",6)) {
type=VGI_LINETO;
}
if (!strncmp(buffer,"DRECT",5)) {
type=VGI_DITHER_RECTANGLE;
}
if (!strncmp(buffer,"VTRI",4)) {
type=VGI_VERT_TRIANGLE;
}
if (!strncmp(buffer,"HTRI",4)) {
type=VGI_HORIZ_TRIANGLE;
}
if (!strncmp(buffer,"END",3)) {
type=VGI_END;
}
}
else {
sscanf(buffer,"%i",&type);
}
switch(type) {
case 0: /* clear screen */
sscanf(buffer,"%i %i",&type,&color1);
case VGI_CLEARSCREEN: /* clear screen */
sscanf(buffer,"%*s %i",&color1);
printf(".byte $%02X,",(type<<4)|2);
printf("$%02X\n",color1);
break;
case 1: /* compact rectangle */
sscanf(buffer,"%i %i %i %i %i %i %i",
&type,
case VGI_RECTANGLE: /* compact rectangle */
sscanf(buffer,"%*s %i %i %i %i %i %i",
&color1,&color2,
&x1,&y1,&x2,&y2);
printf(".byte $%02X,",(type<<4)|6);
@ -36,9 +84,8 @@ int main(int argc, char **argv) {
printf("$%02X\n",y2-y1);
break;
case 2: /* circle */
sscanf(buffer,"%i %i %i %i %i",
&type,
case VGI_CIRCLE: /* circle */
sscanf(buffer,"%*s %i %i %i %i",
&color1,
&x1,&y1,&r);
printf(".byte $%02X,",(type<<4)|5);
@ -48,9 +95,8 @@ int main(int argc, char **argv) {
printf("$%02X\n",r);
break;
case 3: /* filled circle */
sscanf(buffer,"%i %i %i %i %i",
&type,
case VGI_FILLED_CIRCLE: /* filled circle */
sscanf(buffer,"%*s %i %i %i %i",
&color1,
&x1,&y1,&r);
printf(".byte $%02X,",(type<<4)|5);
@ -60,9 +106,8 @@ int main(int argc, char **argv) {
printf("$%02X\n",r);
break;
case 4: /* point */
sscanf(buffer,"%i %i %i %i",
&type,
case VGI_POINT: /* point */
sscanf(buffer,"%*s %i %i %i",
&color1,
&x1,&y1);
printf(".byte $%02X,",(type<<4)|4);
@ -71,18 +116,16 @@ int main(int argc, char **argv) {
printf("$%02X\n",y1);
break;
case 5: /* line to */
sscanf(buffer,"%i %i %i",
&type,
case VGI_LINETO: /* line to */
sscanf(buffer,"%*s %i %i",
&x1,&y1);
printf(".byte $%02X,",(type<<4)|3);
printf("$%02X,",x1);
printf("$%02X\n",y1);
break;
case 6: /* dithered rectangle */
sscanf(buffer,"%i %i %i %i %i %i %i",
&type,
case VGI_DITHER_RECTANGLE: /* dithered rectangle */
sscanf(buffer,"%*s %i %i %i %i %i %i",
&color1,&color2,
&x1,&y1,&x2,&y2);
printf(".byte $%02X,",(type<<4)|7);
@ -94,12 +137,39 @@ int main(int argc, char **argv) {
printf("$%02X\n",color2);
break;
case 15: /* end */
case VGI_VERT_TRIANGLE: /* vertical triangle */
sscanf(buffer,"%*s %i %i %i %i %i %i",
&color1,
&x1,&y1,&xl,&xr,&yb);
printf(".byte $%02X,",(type<<4)|7);
printf("$%02X,",color1);
printf("$%02X,",x1);
printf("$%02X,",y1);
printf("$%02X,",xl);
printf("$%02X,",xr);
printf("$%02X\n",yb);
break;
case VGI_HORIZ_TRIANGLE: /* horizontal triangle */
sscanf(buffer,"%*s %i %i %i %i %i %i",
&color1,
&x1,&y1,&yt,&yb,&xr);
printf(".byte $%02X,",(type<<4)|7);
printf("$%02X,",color1);
printf("$%02X,",x1);
printf("$%02X,",y1);
printf("$%02X,",yt);
printf("$%02X,",yb);
printf("$%02X\n",xr);
break;
case VGI_END: /* end */
printf(".byte $FF\n");
break;
default:
fprintf(stderr,"Unknown type %i\n",type);
fprintf(stderr,"Unknown type %i line %d\n",
type,line);
break;
}

View File

@ -1,22 +1,26 @@
; Rocket from Myst
0 255 ; white background
1 1 6 0 122 140 191 ; ocean left
1 1 6 140 122 279 191 ; ocean right
CLS 255 ; white background
RECT 1 6 0 122 140 191 ; ocean left
RECT 1 6 140 122 279 191 ; ocean right
; base
6 0x8 0x22 86 124 193 191 ; green brick dock
3 7 99 121 4 ; left platform
3 7 180 121 4 ; right platform
1 7 7 99 119 175 125 ; platform
1 0 0 102 128 116 191 ; left shade
1 0 0 179 126 194 191 ; right shade
1 7 7 89 137 93 146 ; left light
1 7 7 186 139 190 147 ; right light
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 0 0 102 128 116 191 ; left 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
; 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
1 6 6 174 88 179 126 ; pole
1 6 6 174 73 179 80 ; insulator
4 6 177 90 ; thinner pole
5 177 74 ; to top
5 237 64 ; to top
;5 279 53 ; to top
5 255 60 ; to top
15
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
END

View File

@ -110,8 +110,8 @@ vgi_rts_table:
.word vgi_point-1 ; 4 = dot
.word vgi_lineto-1 ; 5 = line to
.word vgi_dithered_rectangle-1 ; 6 = dithered rectangle
.word all_done-1
.word all_done-1
.word vgi_vertical_triangle-1 ; 7 = vertical triangle
.word vgi_horizontal_triangle-1 ; 8 = horizontal triangle
.word all_done-1
.word all_done-1
.word all_done-1
@ -128,6 +128,7 @@ all_done:
.include "vgi_circles.s"
.include "vgi_rectangle.s"
.include "vgi_lines.s"
.include "vgi_triangles.s"
.include "clock.data"
.include "rocket.data"

View File

@ -0,0 +1,39 @@
; VGI Triangles
;========================
; VGI vertical triangle
;========================
VGI_TCOLOR = P0
VGI_VX = P1
VGI_VY = P2
VGI_TX1 = P3
VGI_TX2 = P4
vgi_vertical_triangle:
ldx VGI_TCOLOR
lda COLORTBL,X
sta HGR_COLOR
ldy #0
ldx VGI_VX
lda VGI_VY
jsr HPLOT0 ; plot at (Y,X), (A)
; ldx #0
; ldy VGI_LY
; lda VGI_LX
; jsr HGLIN ; line to (X,A),(Y)
; jmp vgi_loop
jmp vgi_loop
vgi_horizontal_triangle:
jmp vgi_loop