hgr: vgi: filled circles

This commit is contained in:
Vince Weaver 2021-06-18 15:46:45 -04:00
parent 0218fe7eb6
commit c2edf45b18
5 changed files with 240 additions and 128 deletions

View File

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

View File

@ -1,16 +1,23 @@
; Clock from Myst
0 255 ; white background
;
1 1 6 0 90 140 191 ; ocean left
1 1 6 140 90 279 191 ; ocean right
1 4 1 157 121 208 191 ; tower shadow
;
1 0 7 141 116 231 135 ; gear base
1 0 7 180 17 213 121 ;
1 7 0 156 20 209 126 ; tower
1 7 0 145 9 212 20
1 0 7 162 0 220 20
1 5 0 172 91 187 123
1 7 7 169 31 191 63 ; clock face tall
1 7 7 165 39 194 60 ; clock face wide
; clock face
3 5 179 49 20 ; clock face ring
3 7 179 49 18 ; clock face white
2 5 179 49 10 ; clock face inner
4 0 179 49 ; clock hand origin
5 179 32 ; clock hand
;
1 5 1 0 163 63 191 ; grass
1 5 1 63 167 177 191 ; grass
1 5 1 177 185 230 191 ; grass
@ -19,5 +26,4 @@
1 5 0 0 0 20 188 ; tree
1 0 5 66 0 81 187 ; tree
1 1 5 66 1 99 19 ; leaves
1 0 0 177 32 181 50 ; clock hand
15

View File

@ -4,7 +4,7 @@ int main(int argc, char **argv) {
char buffer[1024];
char *ptr;
int type,color1,color2,x1,x2,y1,y2;
int type,color1,color2,x1,x2,y1,y2,r;
int line=1;
while(1) {
@ -35,6 +35,50 @@ int main(int argc, char **argv) {
printf("$%02X\n",y2-y1);
break;
case 2: /* circle */
sscanf(buffer,"%d %d %d %d %d",
&type,
&color1,
&x1,&y1,&r);
printf(".byte $%02X,",(type<<4)|5);
printf("$%02X,",color1);
printf("$%02X,",x1);
printf("$%02X,",y1);
printf("$%02X\n",r);
break;
case 3: /* filled circle */
sscanf(buffer,"%d %d %d %d %d",
&type,
&color1,
&x1,&y1,&r);
printf(".byte $%02X,",(type<<4)|5);
printf("$%02X,",color1);
printf("$%02X,",x1);
printf("$%02X,",y1);
printf("$%02X\n",r);
break;
case 4: /* point */
sscanf(buffer,"%d %d %d %d",
&type,
&color1,
&x1,&y1);
printf(".byte $%02X,",(type<<4)|4);
printf("$%02X,",color1);
printf("$%02X,",x1);
printf("$%02X\n",y1);
break;
case 5: /* line to */
sscanf(buffer,"%d %d %d",
&type,
&x1,&y1);
printf(".byte $%02X,",(type<<4)|3);
printf("$%02X,",x1);
printf("$%02X\n",y1);
break;
case 15: /* end */
printf(".byte $FF\n");
break;

View File

@ -51,13 +51,12 @@ no_oflo:
rts ; "jump" to subroutine
vgi_rts_table:
.word vgi_clearscreen-1
.word vgi_simple_rectangle-1
.word all_done-1
.word all_done-1
.word all_done-1
.word all_done-1
.word all_done-1
.word vgi_clearscreen-1 ; 0 = clearscreen
.word vgi_simple_rectangle-1 ; 1 = simple rectangle
.word vgi_circle-1 ; 2 = plain circle
.word vgi_filled_circle-1 ; 3 = filled circle
.word all_done-1 ; 4 = dot
.word all_done-1 ; 5 = line to
.word all_done-1
.word all_done-1
.word all_done-1
@ -67,6 +66,7 @@ vgi_rts_table:
.word all_done-1
.word all_done-1
.word all_done-1
.word all_done-1 ; 15 = done
all_done:
jmp all_done
@ -74,5 +74,6 @@ all_done:
.include "vgi_clearscreen.s"
.include "vgi_rectangle.s"
.include "vgi_circles.s"
.include "clock.data"

View File

@ -1,118 +1,33 @@
; circles tiny -- Apple II Hires
; VGI_Circles
; 229 -- first
; 228 -- remove shift
; 190 -- move hplots into two loops
; 169 -- move hplots into one loop
; 166 -- small enough we can use bcs again
; 157 -- some more math
XX = $70
MINUSXX = $71
YY = $72
MINUSYY = $73
D = $74
COUNT = $75
; D0+ used by HGR routines
;========================
; VGI circle
;========================
HGR_COLOR = $E4
HGR_PAGE = $E6
VGI_CCOLOR = P0
VGI_CX = P1
VGI_CY = P2
VGI_CR = P3
COUNT = $F6
XX = $F7
MINUSXX = $F8
YY = $F9
MINUSYY = $FA
D = $FB
R = $FC
CX = $FD
CY = $FE
FRAME = $FF
; soft-switches
KEYPRESS = $C000
KEYRESET = $C010
; ROM routines
HGR2 = $F3D8 ; set hires page2 and clear $4000-$5fff
HGR = $F3E2 ; set hires page1 and clear $2000-$3fff
HPLOT0 = $F457 ; plot at (Y,X), (A)
HCOLOR1 = $F6F0 ; set HGR_COLOR to value in X
COLORTBL = $F6F6
PLOT = $F800 ; PLOT AT Y,A (A colors output, Y preserved)
NEXTCOL = $F85F ; COLOR=COLOR+3
SETCOL = $F864 ; COLOR=A
SETGR = $FB40 ; set graphics and clear LO-RES screen
BELL2 = $FBE4
WAIT = $FCA8 ; delay 1/2(26+27A+5A^2) us
circles:
lda #0
sta R
draw_next:
lda KEYPRESS
bpl draw_next
bit KEYRESET
jsr HGR2
;draw_next:
.if 0
inc FRAME
ldy FRAME
; Random Color
; HCOLOR=1+RND(1)*7
lda $F000,Y
and #$7 ; mask to 0...7
tax
vgi_circle:
ldx VGI_CCOLOR
lda COLORTBL,X
sta HGR_COLOR
; CX
lda $F100,Y
and #$7f
clc
adc #$40
sta CX
; CY
lda $F200,Y
and #$7f
clc
adc #$20
sta CY
; R
lda $F300,Y
and #$3f
sta R
.endif
; A=40+RND(1)*200:B=40+RND(1)*100:Y=RND(1)*40
lda #128
sta CX
lda #96
sta CY
;===============================
; draw circle
;===============================
; draw circle at (CX,CY) of radius R
; signed 8-bit math so problems if R > 64?
; XX=0 YY=R
; D=3-2*R
; GOTO6
@ -120,13 +35,13 @@ draw_next:
lda #0
sta XX
lda R
lda VGI_CR
sta YY
lda #3
sec
sbc R
sbc R
sbc VGI_CR
sbc VGI_CR
sta D
jmp do_plots
@ -200,7 +115,7 @@ pos_loop:
bcc xnoc
iny
xnoc:
lda CX
lda VGI_CX
clc
adc XX,Y
tax
@ -212,7 +127,7 @@ xnoc:
eor #$2
tay
lda CY
lda VGI_CY
clc
adc XX,Y
@ -229,14 +144,160 @@ xnoc:
cmp XX
bcs circle_loop
done:
lda R
clc
adc #1
sta R
stop:
cmp #90
beq stop
jmp vgi_loop
; GOTO1
jmp draw_next
;========================
; VGI circle
;========================
; VGI_CCOLOR = P0
; VGI_CX = P1
; VGI_CY = P2
; VGI_CR = P3
vgi_filled_circle:
ldx VGI_CCOLOR
lda COLORTBL,X
sta HGR_COLOR
;===============================
; draw filled circle
;===============================
; draw filled circle at (CX,CY) of radius R
; signed 8-bit math so problems if R > 64?
; XX=0 YY=R
; D=3-2*R
; GOTO6
lda #0
sta XX
lda VGI_CR
sta YY
lda #3
sec
sbc VGI_CR
sbc VGI_CR
sta D
jmp do_filled_plots
filled_circle_loop:
; X=X+1
inc XX
; IF D>0 THEN Y=Y-1:D=D+4*(X-Y)+10
lda D
bmi filled_else
dec YY
lda XX
sec
sbc YY
asl
asl
clc
adc D
adc #10
jmp store_filled_D
filled_else:
; ELSE D=D+4*X+6
lda XX
asl
asl
clc
adc D
adc #6
store_filled_D:
sta D
do_filled_plots:
; setup constants
lda XX
eor #$FF
sta MINUSXX
inc MINUSXX
lda YY
eor #$FF
sta MINUSYY
inc MINUSYY
; HPLOT CX+X,CY+Y
; HPLOT CX-X,CY+Y
; HPLOT CX+X,CY-Y
; HPLOT CX-X,CY-Y
; HPLOT CX+Y,CY+X
; HPLOT CX-Y,CY+X
; HPLOT CX+Y,CY-X
; HPLOT CX-Y,CY-X
lda #3
sta COUNT
filled_pos_loop:
; calc left side
; calc X co-ord
lda COUNT
ora #$1
eor #$2
tay
lda VGI_CX
clc
adc XX,Y
tax
; calc y co-ord
ldy COUNT
lda VGI_CY
clc
adc XX,Y
ldy #0
pha ; save Y value for later
jsr HPLOT0 ; plot at (Y,X), (A)
; calc right side
lda COUNT
and #$2
eor #$2
tay
lda XX,Y
asl
ldy #0
ldx #0
jsr HLINRL ; plot relative (X,A), (Y)
; so in our case (0,XX*2),0
dec COUNT
bpl filled_pos_loop
; IFY>=XTHEN4
lda YY
cmp XX
bcs filled_circle_loop
jmp vgi_loop