vgi: move some things around

This commit is contained in:
Vince Weaver 2021-07-29 16:56:45 -04:00
parent 80ab6fefbf
commit 18a286dc0d
18 changed files with 2070 additions and 0 deletions

View File

@ -0,0 +1,303 @@
; VGI_Circles
XX = TEMP0
MINUSXX = TEMP1
YY = TEMP2
MINUSYY = TEMP3
D = TEMP4
COUNT = TEMP5
;========================
; VGI circle
;========================
VGI_CCOLOR = P0
VGI_CX = P1
VGI_CY = P2
VGI_CR = P3
vgi_circle:
ldx VGI_CCOLOR
lda COLORTBL,X
sta HGR_COLOR
;===============================
; 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
lda #0
sta XX
lda VGI_CR
sta YY
lda #3
sec
sbc VGI_CR
sbc VGI_CR
sta D
jmp do_plots
circle_loop:
; X=X+1
inc XX
; IF D>0 THEN Y=Y-1:D=D+4*(X-Y)+10
lda D
bmi else
dec YY
lda XX
sec
sbc YY
asl
asl
clc
adc D
adc #10
jmp store_D
else:
; ELSE D=D+4*X+6
lda XX
asl
asl
clc
adc D
adc #6
store_D:
sta D
do_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
; calc X co-ord
lda #7
sta COUNT
pos_loop:
lda COUNT
and #$4
lsr
tay
lda COUNT
lsr
bcc xnoc
iny
xnoc:
lda VGI_CX
clc
adc XX,Y
tax
; calc y co-ord
lda COUNT
lsr
eor #$2
tay
lda VGI_CY
clc
adc XX,Y
ldy #0
jsr HPLOT0 ; plot at (Y,X), (A)
dec COUNT
bpl pos_loop
; IFY>=XTHEN4
lda YY
cmp XX
bcs circle_loop
jmp vgi_loop
;========================
; 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

View File

@ -0,0 +1,7 @@
vgi_clearscreen:
lda P0
jsr BKGND0
jmp vgi_loop ; return

View File

@ -0,0 +1,72 @@
; VGI library
VGI_MAXLEN = 7
;==================================
; play_vgi
;==================================
play_vgi:
vgi_loop:
ldy #0
data_smc:
lda (VGIL),Y
sta VGI_BUFFER,Y
iny
cpy #VGI_MAXLEN
bne data_smc
lda VGI_TYPE
and #$f
clc
adc VGIL
sta VGIL
bcc no_oflo
inc VGIH
no_oflo:
lda VGI_TYPE
lsr
lsr
lsr
lsr
; look up action in jump table
asl
tax
lda vgi_rts_table+1,X
pha
lda vgi_rts_table,X
pha
rts ; "jump" to subroutine
vgi_rts_table:
.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 vgi_point-1 ; 4 = dot
.word vgi_lineto-1 ; 5 = line to
.word vgi_dithered_rectangle-1 ; 6 = dithered rectangle
.word vgi_vertical_triangle-1 ; 7 = vertical triangle
.word vgi_horizontal_triangle-1 ; 8 = horizontal triangle
.word vgi_vstripe_rectangle-1 ; 9 = vstripe rectangle
.word vgi_line-1 ;10 = line
.word vgi_line_far-1 ;11 = line far
.word all_done-1
.word all_done-1
.word all_done-1
.word all_done-1 ; 15 = done
all_done:
rts
.include "vgi_clearscreen.s"
.include "vgi_circles.s"
.include "vgi_rectangle.s"
.include "vgi_lines.s"
.include "vgi_triangles.s"

View File

@ -0,0 +1,95 @@
; VGI Lines
;========================
; VGI point
;========================
vgi_point:
jsr vgi_point_common
jmp vgi_loop
;========================
; VGI point common
;========================
VGI_PCOLOR = P0 ; if high bit set, then PX=PX+256
VGI_PX = P1
VGI_PY = P2
vgi_point_common:
ldy #0
lda VGI_PCOLOR
bpl vgi_point_color
iny
vgi_point_color:
and #$7f
tax
lda COLORTBL,X
sta HGR_COLOR
ldx VGI_PX
lda VGI_PY
jsr HPLOT0 ; plot at (Y,X), (A)
rts
;========================
; VGI line to
;========================
VGI_LX = P0
VGI_LY = P1
vgi_lineto:
ldx #0
ldy VGI_LY
lda VGI_LX
jsr HGLIN ; line to (X,A),(Y)
jmp vgi_loop
;========================
; VGI LINE
;========================
; VGI_LX = P0
; VGI_LY = P1
VGI_LX2 = P3
VGI_LY2 = P4
vgi_line:
jsr vgi_point_common
ldx #0
ldy VGI_LY2
lda VGI_LX2
jsr HGLIN ; line to (X,A),(Y)
jmp vgi_loop
;========================
; VGI LINE FAR
;========================
; assume second x-coord is > 256
; VGI_LX = P0
; VGI_LY = P1
; VGI_LX2 = P3
; VGI_LY2 = P4
vgi_line_far:
jsr vgi_point_common
ldx #1
ldy VGI_LY2
lda VGI_LX2
jsr HGLIN ; line to (X,A),(Y)
jmp vgi_loop

View File

@ -0,0 +1,462 @@
; VGI Rectangle
; VGI Rectangle test
COLOR_MODE = TEMP0
OTHER_MASK = TEMP1
XRUN = TEMP2
div7_table = $9000
mod7_table = $9100
USE_FAST = 1
.if (USE_FAST=0)
; slow
;=================================
; Simple Rectangle
;=================================
VGI_RCOLOR = P0
VGI_RX1 = P1
VGI_RY1 = P2
VGI_RXRUN = P3
VGI_RYRUN = P4
vgi_simple_rectangle:
simple_rectangle_loop:
lda VGI_RCOLOR
asl ; nibble swap by david galloway
adc #$80
rol
asl
adc #$80
rol
sta VGI_RCOLOR
and #$f
tax
lda COLORTBL,X
sta HGR_COLOR
ldx VGI_RX1 ; X1 into X
lda VGI_RY1 ; Y1 into A
ldy #0 ; always 0
jsr HPOSN ; (Y,X),(A) (values stores in HGRX,XH,Y)
lda VGI_RXRUN ; XRUN into A
ldx #0 ; always 0
ldy #0 ; relative Y is 0
jsr HLINRL ; (X,A),(Y)
inc VGI_RY1
dec VGI_RYRUN
bne simple_rectangle_loop
jmp vgi_loop
;=================================
; Dithered Rectangle
;=================================
; VGI_RCOLOR = P0
; VGI_RX1 = P1
; VGI_RY1 = P2
; VGI_RXRUN = P3
; VGI_RYRUN = P4
VGI_RCOLOR2 = P5
vgi_dithered_rectangle:
dithered_rectangle_loop:
lda COUNT
and #$1
beq even_color
odd_color:
lda VGI_RCOLOR
jmp save_color
even_color:
lda VGI_RCOLOR2
save_color:
sta HGR_COLOR
inc COUNT
ldx VGI_RX1 ; X1 into X
lda VGI_RY1 ; Y1 into A
ldy #0 ; always 0
jsr HPOSN ; (Y,X),(A) (values stores in HGRX,XH,Y)
lda VGI_RXRUN ; XRUN into A
ldx #0 ; always 0
ldy #0 ; relative Y is 0
jsr HLINRL ; (X,A),(Y)
inc VGI_RY1
dec VGI_RYRUN
bne dithered_rectangle_loop
jmp vgi_loop
.else
; FAST
;=================================
; Simple Rectangle
;=================================
VGI_RCOLOR = P0
VGI_RX1 = P1
VGI_RY1 = P2
VGI_RXRUN = P3
VGI_RYRUN = P4
VGI_RCOLOR2 = P5 ; only for dither
;==================================
; VGI Simple Rectangle
;==================================
vgi_simple_rectangle:
lda #0
sta COLOR_MODE
simple_rectangle_loop:
lda COLOR_MODE
beq simple_colors
bmi striped_colors
bpl handle_dither
simple_colors:
lda VGI_RCOLOR
asl ; nibble swap by david galloway
adc #$80
rol
asl
adc #$80
rol
sta VGI_RCOLOR
and #$f
tax
lda COLORTBL,X
sta HGR_COLOR
jmp done_colors
handle_dither:
lda COUNT
and #$1
beq deven_color
dodd_color:
lda VGI_RCOLOR
jmp dsave_color
deven_color:
lda VGI_RCOLOR2
dsave_color:
sta HGR_COLOR
inc COUNT
jmp done_colors
striped_colors:
; don't need to do anything here?
done_colors:
; get ROW into (GBASL)
ldx VGI_RX1 ; X1 into X
lda VGI_RY1 ; Y1 into A
ldy #0 ; always 0
jsr HPOSN ; (Y,X),(A) (values stores in HGRX,XH,Y)
; Y is already the RX1/7
; adjust color if in striped mode
lda COLOR_MODE
bpl not_striped
jsr swap_colors
not_striped:
; copy the XRUN
lda VGI_RXRUN
sta XRUN
inc XRUN ; needed because we compare with beq/bne
; check if narrow corner case where begin and end same block
; if RX%7 + XRUN < 8
ldx VGI_RX1
lda mod7_table,X
clc
adc XRUN
cmp #8
bcs not_corner
corner:
; want to use MASK of left_mask, MOD7 and 7-XRUN
lda mod7_table,X
tax
lda (GBASL),Y
eor HGR_BITS
and left_masks,X
ldx XRUN
and right_masks,X
eor (GBASL),Y
sta (GBASL),Y
jmp done_row ; that's all
not_corner:
; see if not starting on boundary
ldx VGI_RX1
lda mod7_table,X
beq draw_run
; handle not full left border
tax
lda (GBASL),Y
eor HGR_BITS
and left_masks,X
eor (GBASL),Y
sta (GBASL),Y
iny ; move to next
; adjust RUN length by 7- mod7
txa ; load mod7
eor #$ff
sec
adc #7
eor #$ff
sec
adc XRUN
sta XRUN
; lda HGR_BITS ; cycle colors for next
; jsr COLOR_SHIFT
jsr swap_colors
;no_shift:
; draw common
draw_run:
lda XRUN
cmp #7
bcc draw_right ; blt
lda HGR_BITS ; get color
sta (GBASL),Y ; store out
; jsr COLOR_SHIFT ; shift colors
iny ; move to next block
jsr swap_colors
lda XRUN ; take 7 off the run
sec
sbc #7
sta XRUN
jmp draw_run
; draw rightmost
draw_right:
beq done_row
; lda HGR_BITS
; jsr COLOR_SHIFT
; see if not starting on boundary
ldx XRUN
tax
lda (GBASL),Y
eor HGR_BITS
and right_masks,X
eor (GBASL),Y
sta (GBASL),Y
done_row:
inc VGI_RY1
dec VGI_RYRUN
;bne simple_rectangle_loop
beq done_done
jmp simple_rectangle_loop
done_done:
jmp vgi_loop
;==========================
; swap colors
;==========================
swap_colors:
lda COLOR_MODE
bmi swap_colors_striped
lda HGR_BITS ; get color
jsr COLOR_SHIFT ; shift colors
rts
swap_colors_striped:
tya
and #1
bne swap_odd
lda VGI_RCOLOR
jmp swap_done
swap_odd:
lda VGI_RCOLOR2
swap_done:
sta HGR_BITS
rts
;=================================
; Dithered Rectangle
;=================================
; VGI_RCOLOR = P0
; VGI_RX1 = P1
; VGI_RY1 = P2
; VGI_RXRUN = P3
; VGI_RYRUN = P4
; VGI_RCOLOR2 = P5
vgi_dithered_rectangle:
lda #1
sta COLOR_MODE
lda #0
sta COUNT
jmp simple_rectangle_loop
;=================================
; Vertical Striped Rectangle
;=================================
; VGI_RCOLOR = P0
; VGI_RX1 = P1
; VGI_RY1 = P2
; VGI_RXRUN = P3
; VGI_RYRUN = P4
; VGI_RCOLOR2 = P5
vgi_vstripe_rectangle:
lda #128
sta COLOR_MODE
lda #0
sta COUNT
jmp simple_rectangle_loop
.endif
;=====================
; make /7 %7 tables
;=====================
vgi_init:
vgi_make_tables:
ldy #0
lda #0
ldx #0
div7_loop:
sta div7_table,Y
inx
cpx #7
bne div7_not7
clc
adc #1
ldx #0
div7_not7:
iny
bne div7_loop
ldy #0
lda #0
mod7_loop:
sta mod7_table,Y
clc
adc #1
cmp #7
bne mod7_not7
lda #0
mod7_not7:
iny
bne mod7_loop
rts
left_masks:
.byte $FF,$FE,$FC,$F8, $F0,$E0,$C0
right_masks:
.byte $81,$83,$87, $8F,$9F,$BF,$FF

View File

@ -0,0 +1,96 @@
; VGI Triangles
SKIP = TEMP0
;========================
; VGI vertical triangle
;========================
VGI_TCOLOR = P0
VGI_VX = P1
VGI_VY = P2
VGI_TXL = P3
VGI_TXR = P4
VGI_TYB = P5
vgi_vertical_triangle:
lda VGI_TCOLOR
lsr
lsr
lsr
lsr
sta SKIP
lda VGI_TCOLOR
and #$f
tax
lda COLORTBL,X
sta HGR_COLOR
vtri_loop:
ldy #0
ldx VGI_VX
lda VGI_VY
jsr HPLOT0 ; plot at (Y,X), (A)
ldx #0
ldy VGI_TYB
lda VGI_TXL
jsr HGLIN ; line to (X,A),(Y)
lda VGI_TXL
clc
adc SKIP
sta VGI_TXL
; inc VGI_TXL
; lda VGI_TXL
cmp VGI_TXR
bcc vtri_loop
done_vtri:
jmp vgi_loop ; bra
;========================
; VGI horizontal triangle
;========================
; VGI_TCOLOR = P0
; VGI_VX = P1
; VGI_VY = P2
VGI_THYT = P3
VGI_THYB = P4
VGI_THXR = P5
vgi_horizontal_triangle:
ldx VGI_TCOLOR
lda COLORTBL,X
sta HGR_COLOR
htri_loop:
ldy #0
ldx VGI_VX
lda VGI_VY
jsr HPLOT0 ; plot at (Y,X), (A)
ldx #0
ldy VGI_THYT
lda VGI_THXR
jsr HGLIN ; line to (X,A),(Y)
inc VGI_THYT
lda VGI_THYT
cmp VGI_THYB
bcc htri_loop
done_htri:
jmp vgi_loop

View File

@ -0,0 +1,303 @@
; VGI_Circles
XX = TEMP0
MINUSXX = TEMP1
YY = TEMP2
MINUSYY = TEMP3
D = TEMP4
COUNT = TEMP5
;========================
; VGI circle
;========================
VGI_CCOLOR = P0
VGI_CX = P1
VGI_CY = P2
VGI_CR = P3
vgi_circle:
ldx VGI_CCOLOR
lda COLORTBL,X
sta HGR_COLOR
;===============================
; 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
lda #0
sta XX
lda VGI_CR
sta YY
lda #3
sec
sbc VGI_CR
sbc VGI_CR
sta D
jmp do_plots
circle_loop:
; X=X+1
inc XX
; IF D>0 THEN Y=Y-1:D=D+4*(X-Y)+10
lda D
bmi else
dec YY
lda XX
sec
sbc YY
asl
asl
clc
adc D
adc #10
jmp store_D
else:
; ELSE D=D+4*X+6
lda XX
asl
asl
clc
adc D
adc #6
store_D:
sta D
do_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
; calc X co-ord
lda #7
sta COUNT
pos_loop:
lda COUNT
and #$4
lsr
tay
lda COUNT
lsr
bcc xnoc
iny
xnoc:
lda VGI_CX
clc
adc XX,Y
tax
; calc y co-ord
lda COUNT
lsr
eor #$2
tay
lda VGI_CY
clc
adc XX,Y
ldy #0
jsr HPLOT0 ; plot at (Y,X), (A)
dec COUNT
bpl pos_loop
; IFY>=XTHEN4
lda YY
cmp XX
bcs circle_loop
jmp vgi_loop
;========================
; 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

View File

@ -0,0 +1,7 @@
vgi_clearscreen:
lda P0
jsr BKGND0
jmp vgi_loop ; return

View File

@ -0,0 +1,72 @@
; VGI library
VGI_MAXLEN = 7
;==================================
; play_vgi
;==================================
play_vgi:
vgi_loop:
ldy #0
data_smc:
lda (VGIL),Y
sta VGI_BUFFER,Y
iny
cpy #VGI_MAXLEN
bne data_smc
lda VGI_TYPE
and #$f
clc
adc VGIL
sta VGIL
bcc no_oflo
inc VGIH
no_oflo:
lda VGI_TYPE
lsr
lsr
lsr
lsr
; look up action in jump table
asl
tax
lda vgi_rts_table+1,X
pha
lda vgi_rts_table,X
pha
rts ; "jump" to subroutine
vgi_rts_table:
.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 vgi_point-1 ; 4 = dot
.word vgi_lineto-1 ; 5 = line to
.word vgi_dithered_rectangle-1 ; 6 = dithered rectangle
.word vgi_vertical_triangle-1 ; 7 = vertical triangle
.word vgi_horizontal_triangle-1 ; 8 = horizontal triangle
.word vgi_vstripe_rectangle-1 ; 9 = vstripe rectangle
.word vgi_line-1 ;10 = line
.word vgi_line_far-1 ;11 = line far
.word all_done-1
.word all_done-1
.word all_done-1
.word all_done-1 ; 15 = done
all_done:
rts
.include "vgi_clearscreen.s"
.include "vgi_circles.s"
.include "vgi_rectangle.s"
.include "vgi_lines.s"
.include "vgi_triangles.s"

View File

@ -0,0 +1,95 @@
; VGI Lines
;========================
; VGI point
;========================
vgi_point:
jsr vgi_point_common
jmp vgi_loop
;========================
; VGI point common
;========================
VGI_PCOLOR = P0 ; if high bit set, then PX=PX+256
VGI_PX = P1
VGI_PY = P2
vgi_point_common:
ldy #0
lda VGI_PCOLOR
bpl vgi_point_color
iny
vgi_point_color:
and #$7f
tax
lda COLORTBL,X
sta HGR_COLOR
ldx VGI_PX
lda VGI_PY
jsr HPLOT0 ; plot at (Y,X), (A)
rts
;========================
; VGI line to
;========================
VGI_LX = P0
VGI_LY = P1
vgi_lineto:
ldx #0
ldy VGI_LY
lda VGI_LX
jsr HGLIN ; line to (X,A),(Y)
jmp vgi_loop
;========================
; VGI LINE
;========================
; VGI_LX = P0
; VGI_LY = P1
VGI_LX2 = P3
VGI_LY2 = P4
vgi_line:
jsr vgi_point_common
ldx #0
ldy VGI_LY2
lda VGI_LX2
jsr HGLIN ; line to (X,A),(Y)
jmp vgi_loop
;========================
; VGI LINE FAR
;========================
; assume second x-coord is > 256
; VGI_LX = P0
; VGI_LY = P1
; VGI_LX2 = P3
; VGI_LY2 = P4
vgi_line_far:
jsr vgi_point_common
ldx #1
ldy VGI_LY2
lda VGI_LX2
jsr HGLIN ; line to (X,A),(Y)
jmp vgi_loop

View File

@ -0,0 +1,462 @@
; VGI Rectangle
; VGI Rectangle test
COLOR_MODE = TEMP0
OTHER_MASK = TEMP1
XRUN = TEMP2
div7_table = $9000
mod7_table = $9100
USE_FAST = 1
.if (USE_FAST=0)
; slow
;=================================
; Simple Rectangle
;=================================
VGI_RCOLOR = P0
VGI_RX1 = P1
VGI_RY1 = P2
VGI_RXRUN = P3
VGI_RYRUN = P4
vgi_simple_rectangle:
simple_rectangle_loop:
lda VGI_RCOLOR
asl ; nibble swap by david galloway
adc #$80
rol
asl
adc #$80
rol
sta VGI_RCOLOR
and #$f
tax
lda COLORTBL,X
sta HGR_COLOR
ldx VGI_RX1 ; X1 into X
lda VGI_RY1 ; Y1 into A
ldy #0 ; always 0
jsr HPOSN ; (Y,X),(A) (values stores in HGRX,XH,Y)
lda VGI_RXRUN ; XRUN into A
ldx #0 ; always 0
ldy #0 ; relative Y is 0
jsr HLINRL ; (X,A),(Y)
inc VGI_RY1
dec VGI_RYRUN
bne simple_rectangle_loop
jmp vgi_loop
;=================================
; Dithered Rectangle
;=================================
; VGI_RCOLOR = P0
; VGI_RX1 = P1
; VGI_RY1 = P2
; VGI_RXRUN = P3
; VGI_RYRUN = P4
VGI_RCOLOR2 = P5
vgi_dithered_rectangle:
dithered_rectangle_loop:
lda COUNT
and #$1
beq even_color
odd_color:
lda VGI_RCOLOR
jmp save_color
even_color:
lda VGI_RCOLOR2
save_color:
sta HGR_COLOR
inc COUNT
ldx VGI_RX1 ; X1 into X
lda VGI_RY1 ; Y1 into A
ldy #0 ; always 0
jsr HPOSN ; (Y,X),(A) (values stores in HGRX,XH,Y)
lda VGI_RXRUN ; XRUN into A
ldx #0 ; always 0
ldy #0 ; relative Y is 0
jsr HLINRL ; (X,A),(Y)
inc VGI_RY1
dec VGI_RYRUN
bne dithered_rectangle_loop
jmp vgi_loop
.else
; FAST
;=================================
; Simple Rectangle
;=================================
VGI_RCOLOR = P0
VGI_RX1 = P1
VGI_RY1 = P2
VGI_RXRUN = P3
VGI_RYRUN = P4
VGI_RCOLOR2 = P5 ; only for dither
;==================================
; VGI Simple Rectangle
;==================================
vgi_simple_rectangle:
lda #0
sta COLOR_MODE
simple_rectangle_loop:
lda COLOR_MODE
beq simple_colors
bmi striped_colors
bpl handle_dither
simple_colors:
lda VGI_RCOLOR
asl ; nibble swap by david galloway
adc #$80
rol
asl
adc #$80
rol
sta VGI_RCOLOR
and #$f
tax
lda COLORTBL,X
sta HGR_COLOR
jmp done_colors
handle_dither:
lda COUNT
and #$1
beq deven_color
dodd_color:
lda VGI_RCOLOR
jmp dsave_color
deven_color:
lda VGI_RCOLOR2
dsave_color:
sta HGR_COLOR
inc COUNT
jmp done_colors
striped_colors:
; don't need to do anything here?
done_colors:
; get ROW into (GBASL)
ldx VGI_RX1 ; X1 into X
lda VGI_RY1 ; Y1 into A
ldy #0 ; always 0
jsr HPOSN ; (Y,X),(A) (values stores in HGRX,XH,Y)
; Y is already the RX1/7
; adjust color if in striped mode
lda COLOR_MODE
bpl not_striped
jsr swap_colors
not_striped:
; copy the XRUN
lda VGI_RXRUN
sta XRUN
inc XRUN ; needed because we compare with beq/bne
; check if narrow corner case where begin and end same block
; if RX%7 + XRUN < 8
ldx VGI_RX1
lda mod7_table,X
clc
adc XRUN
cmp #8
bcs not_corner
corner:
; want to use MASK of left_mask, MOD7 and 7-XRUN
lda mod7_table,X
tax
lda (GBASL),Y
eor HGR_BITS
and left_masks,X
ldx XRUN
and right_masks,X
eor (GBASL),Y
sta (GBASL),Y
jmp done_row ; that's all
not_corner:
; see if not starting on boundary
ldx VGI_RX1
lda mod7_table,X
beq draw_run
; handle not full left border
tax
lda (GBASL),Y
eor HGR_BITS
and left_masks,X
eor (GBASL),Y
sta (GBASL),Y
iny ; move to next
; adjust RUN length by 7- mod7
txa ; load mod7
eor #$ff
sec
adc #7
eor #$ff
sec
adc XRUN
sta XRUN
; lda HGR_BITS ; cycle colors for next
; jsr COLOR_SHIFT
jsr swap_colors
;no_shift:
; draw common
draw_run:
lda XRUN
cmp #7
bcc draw_right ; blt
lda HGR_BITS ; get color
sta (GBASL),Y ; store out
; jsr COLOR_SHIFT ; shift colors
iny ; move to next block
jsr swap_colors
lda XRUN ; take 7 off the run
sec
sbc #7
sta XRUN
jmp draw_run
; draw rightmost
draw_right:
beq done_row
; lda HGR_BITS
; jsr COLOR_SHIFT
; see if not starting on boundary
ldx XRUN
tax
lda (GBASL),Y
eor HGR_BITS
and right_masks,X
eor (GBASL),Y
sta (GBASL),Y
done_row:
inc VGI_RY1
dec VGI_RYRUN
;bne simple_rectangle_loop
beq done_done
jmp simple_rectangle_loop
done_done:
jmp vgi_loop
;==========================
; swap colors
;==========================
swap_colors:
lda COLOR_MODE
bmi swap_colors_striped
lda HGR_BITS ; get color
jsr COLOR_SHIFT ; shift colors
rts
swap_colors_striped:
tya
and #1
bne swap_odd
lda VGI_RCOLOR
jmp swap_done
swap_odd:
lda VGI_RCOLOR2
swap_done:
sta HGR_BITS
rts
;=================================
; Dithered Rectangle
;=================================
; VGI_RCOLOR = P0
; VGI_RX1 = P1
; VGI_RY1 = P2
; VGI_RXRUN = P3
; VGI_RYRUN = P4
; VGI_RCOLOR2 = P5
vgi_dithered_rectangle:
lda #1
sta COLOR_MODE
lda #0
sta COUNT
jmp simple_rectangle_loop
;=================================
; Vertical Striped Rectangle
;=================================
; VGI_RCOLOR = P0
; VGI_RX1 = P1
; VGI_RY1 = P2
; VGI_RXRUN = P3
; VGI_RYRUN = P4
; VGI_RCOLOR2 = P5
vgi_vstripe_rectangle:
lda #128
sta COLOR_MODE
lda #0
sta COUNT
jmp simple_rectangle_loop
.endif
;=====================
; make /7 %7 tables
;=====================
vgi_init:
vgi_make_tables:
ldy #0
lda #0
ldx #0
div7_loop:
sta div7_table,Y
inx
cpx #7
bne div7_not7
clc
adc #1
ldx #0
div7_not7:
iny
bne div7_loop
ldy #0
lda #0
mod7_loop:
sta mod7_table,Y
clc
adc #1
cmp #7
bne mod7_not7
lda #0
mod7_not7:
iny
bne mod7_loop
rts
left_masks:
.byte $FF,$FE,$FC,$F8, $F0,$E0,$C0
right_masks:
.byte $81,$83,$87, $8F,$9F,$BF,$FF

View File

@ -0,0 +1,96 @@
; VGI Triangles
SKIP = TEMP0
;========================
; VGI vertical triangle
;========================
VGI_TCOLOR = P0
VGI_VX = P1
VGI_VY = P2
VGI_TXL = P3
VGI_TXR = P4
VGI_TYB = P5
vgi_vertical_triangle:
lda VGI_TCOLOR
lsr
lsr
lsr
lsr
sta SKIP
lda VGI_TCOLOR
and #$f
tax
lda COLORTBL,X
sta HGR_COLOR
vtri_loop:
ldy #0
ldx VGI_VX
lda VGI_VY
jsr HPLOT0 ; plot at (Y,X), (A)
ldx #0
ldy VGI_TYB
lda VGI_TXL
jsr HGLIN ; line to (X,A),(Y)
lda VGI_TXL
clc
adc SKIP
sta VGI_TXL
; inc VGI_TXL
; lda VGI_TXL
cmp VGI_TXR
bcc vtri_loop
done_vtri:
jmp vgi_loop ; bra
;========================
; VGI horizontal triangle
;========================
; VGI_TCOLOR = P0
; VGI_VX = P1
; VGI_VY = P2
VGI_THYT = P3
VGI_THYB = P4
VGI_THXR = P5
vgi_horizontal_triangle:
ldx VGI_TCOLOR
lda COLORTBL,X
sta HGR_COLOR
htri_loop:
ldy #0
ldx VGI_VX
lda VGI_VY
jsr HPLOT0 ; plot at (Y,X), (A)
ldx #0
ldy VGI_THYT
lda VGI_THXR
jsr HGLIN ; line to (X,A),(Y)
inc VGI_THYT
lda VGI_THYT
cmp VGI_THYB
bcc htri_loop
done_htri:
jmp vgi_loop