fireworks: include hgr routines

otherwise wouldn't run on original Apple II
This commit is contained in:
Vince Weaver 2018-09-07 22:36:43 -04:00
parent a46e345e50
commit a06a08dbd9
5 changed files with 778 additions and 25 deletions

376
asm_routines/hgr.s Normal file
View File

@ -0,0 +1,376 @@
HGR_SHAPE = $1A
HGR_SHAPE_H = $1B
HGR_BITS = $1C
HGR_COUNT = $1D
HMASK = $30
DSCTMP = $9D
HGR_DX = $D0
HGR_DX_H = $D1
HGR_DY = $D2
HGR_QUADRANT = $D3
HGR_E = $D4
HGR_E_H = $D5
HGR_X = $E0
HGR_X_H = $E1
HGR_Y = $E2
;HGR_COLOR = $E4
HGR_HORIZ = $E5
HGR_PAGE = $E6
TXTCLR = $C050
MIXSET = $C053
LOWSCR = $C054
MIXCLR = $C052
HISCR = $C055
hgr2:
; F3D8
bit HISCR ; BIT SW.HISCR Use PAGE2 ($C055)
bit MIXCLR ; BIT SW.MIXCLR
lda #$40 ; HIRES Page 2 at $4000
bne sethpg
hgr:
; F3E2
lda #$20 ; HIRES Page 1 at $2000
bit LOWSCR ; BIT SW.LOWSCR Use PAGE1 ($C054)
bit MIXSET ; BIT SW.MIXSET (Mixed text)
sethpg:
; F3EA
sta HGR_PAGE
lda HIRES
lda TXTCLR
hclr:
lda #0 ; black background
sta HGR_BITS
bkgnd:
; F3F6
lda HGR_PAGE
sta HGR_SHAPE+1
ldy #0
sty HGR_SHAPE
bkgnd_loop:
lda HGR_BITS
sta (HGR_SHAPE),y
jsr color_shift
iny
bne bkgnd_loop
inc HGR_SHAPE+1
lda HGR_SHAPE+1
and #$1f ; see if $40 or $60
bne bkgnd_loop
rts
msktbl: .byte $81,$82,$84,$88,$90,$A0,$C0
hposn:
; F411
sta HGR_Y
stx HGR_X
sty HGR_X+1
pha
and #$C0
sta GBASL
lsr
lsr
ora GBASL
sta GBASL
pla
; F423
sta GBASH
asl
asl
asl
rol GBASH
asl
rol GBASH
asl
ror GBASL
lda GBASH
and #$1f
ora HGR_PAGE
sta GBASH
; F438
txa
cpy #0
beq hposn_2
ldy #35
adc #4
hposn_1:
iny
; f442
hposn_2:
sbc #7
bcs hposn_1
sty HGR_HORIZ
tax
lda msktbl-$100+7,x ; LDA MSKTBL-$100+7,X BIT MASK
; MSKTBL=F5B2
sta HMASK
tya
lsr
lda HGR_COLOR
sta HGR_BITS
bcs color_shift
rts
hplot0:
; F457
jsr hposn
lda HGR_BITS
eor (GBASL),y
and HMASK
eor (GBASL),y
sta (GBASL),y
rts
move_left_or_right:
; F465
bpl move_right
lda HMASK
lsr
bcs lr_2
eor #$c0
lr_1:
sta HMASK
rts
lr_2:
dey
bpl lr_3
ldy #39
lr_3:
lda #$c0
lr_4:
sta HMASK
sty HGR_HORIZ
lda HGR_BITS
color_shift:
; F47E
asl
cmp #$c0
bpl done_color_shift
lda HGR_BITS
eor #$7f
sta HGR_BITS
done_color_shift:
rts
move_right:
lda HMASK
asl
eor #$80
bmi lr_1
lda #$81
iny
cpy #40
bcc lr_4
ldy #0
bcs lr_4
con_1c: .byte $1c
con_03: .byte $03
con_04: .byte $04
move_up_or_down:
; F4D3
bmi move_down
clc
lda GBASH
bit con_1c ; CON.1C
bne mu_5
asl GBASL
bcs mu_3
bit con_03 ; CON.03
beq mu_1
adc #$1f
sec
bcs mu_4
; F4Eb
mu_1:
adc #$23
pha
lda GBASL
adc #$b0
bcs mu_2
adc #$f0
; f4f6
mu_2:
sta GBASL
pla
bcs mu_4
mu_3:
adc #$1f
mu_4:
ror GBASL
mu_5:
adc #$fc
ud_1:
sta GBASH
rts
; f505
move_down:
lda GBASH
adc #$4
bit con_1c
bne ud_1
asl GBASL
bcc md_2
adc #$e0
clc
bit con_04
beq md_3;
lda GBASL
adc #$50
eor #$f0
beq md_1
eor #$f0
md_1:
sta GBASL
lda HGR_PAGE
bcc md_3
md_2:
adc #$e0
md_3:
ror GBASL
bcc ud_1
hglin:
; F53A
pha
sec
sbc HGR_X
pha
txa
sbc HGR_X+1
sta HGR_QUADRANT
; F544
bcs hglin_1
pla
eor #$ff
adc #1
pha
lda #0
sbc HGR_QUADRANT
; F550
hglin_1:
sta HGR_DX+1
sta HGR_E+1
pla
sta HGR_DX
sta HGR_E
pla
sta HGR_X
stx HGR_X+1
tya
clc
sbc HGR_Y
bcc hglin_2
eor #$ff
adc #$fe
hglin_2:
; F568
sta HGR_DY
sty HGR_Y
ror HGR_QUADRANT
sec
sbc HGR_DX
tax
lda #$ff
sbc HGR_DX+1
sta HGR_COUNT
ldy HGR_HORIZ
bcs movex2 ; always?
; f57c
movex:
asl
jsr move_left_or_right
sec
; f581
movex2:
lda HGR_E
adc HGR_DY
sta HGR_E
lda HGR_E+1
sbc #0
movex2_1:
sta HGR_E+1
lda (GBASL),y
eor HGR_BITS
and HMASK
eor (GBASL),y
sta (GBASL),y
inx
bne movex2_2
inc HGR_COUNT
beq rts22
; F59e
movex2_2:
lda HGR_QUADRANT
bcs movex
jsr move_up_or_down
clc
lda HGR_E
adc HGR_DX
sta HGR_E
lda HGR_E+1
adc HGR_DX+1
bvc movex2_1
hplot_to:
; F712
sty DSCTMP
tay
txa
ldx DSCTMP
jsr hglin
rts22:
rts
; Color in X
hcolor_equals:
; F6E9
; TODO: mask to be less than 8
lda colortbl,x
sta HGR_COLOR
rts
colortbl:
.byte $00,$2A,$55,$7F,$80,$AA,$D5,$FF

View File

@ -16,7 +16,7 @@ fireworks.dsk: FIREWORKS.BAS FIREWORKS
FIREWORKS: fireworks.o
ld65 -o FIREWORKS fireworks.o -C ../linker_scripts/apple2_1000.inc
fireworks.o: fireworks.s gr_copy.s random16.s fw.s \
fireworks.o: fireworks.s gr_copy.s random16.s fw.s hgr.s \
background_final.inc
ca65 -o fireworks.o fireworks.s -l fireworks.lst

View File

@ -38,10 +38,10 @@ PADDL0 = $C064
PTRIG = $C070
; ROM routines
HGR = $F3E2
HPLOT0 = $F457
HGLIN = $F53A
COLORTBL= $F6F6
;HGR = $F3E2
;HPLOT0 = $F457
;HGLIN = $F53A
;COLORTBL= $F6F6
TEXT = $FB36 ;; Set text mode
HOME = $FC58 ;; Clear the text screen
WAIT = $FCA8 ;; delay 1/2(26+27A+5A^2) us
@ -399,6 +399,7 @@ gr_offsets:
.include "gr_copy.s"
.include "random16.s"
.include "fw.s"
.include "hgr.s"
background:

View File

@ -38,7 +38,7 @@ draw_fireworks:
jsr HOME ; clear screen
jsr HGR ; set high-res, clear screen, page0
jsr hgr ; set high-res, clear screen, page0
jsr draw_stars ; draw the stars
@ -233,7 +233,7 @@ draw_rocket:
lda COLOR_GROUP
adc #3
tax
lda COLORTBL,X ; get color from table
lda colortbl,X ; get color from table
sta HGR_COLOR
; HPLOT X,Y: X= (y,x), Y=a
@ -241,20 +241,20 @@ draw_rocket:
ldx X_OLD
lda Y_OLD
ldy #0
jsr HPLOT0 ; hplot(x_old,y_old);
jsr hplot0 ; hplot(x_old,y_old);
; HPLOT to X,Y X=(x,a), y=Y
lda XPOS_L
ldx #0
ldy YPOS_H
jsr HGLIN ; hplot_to(xpos_l,ypos_h);
jsr hglin ; hplot_to(xpos_l,ypos_h);
erase_rocket:
; erase with proper color black (0 or 4)
ldx COLOR_GROUP
lda COLORTBL,X ; get color from table
lda colortbl,X ; get color from table
sta HGR_COLOR
; HPLOT X,Y: X= (y,x), Y=a
@ -262,13 +262,13 @@ erase_rocket:
ldx X_OLDER
lda Y_OLDER
ldy #0
jsr HPLOT0 ; hplot(x_old,y_old);
jsr hplot0 ; hplot(x_old,y_old);
; HPLOT to X,Y X=(x,a), y=Y
lda X_OLD
ldx #0
ldy Y_OLD
jsr HGLIN ; hplot_to(x_old,y_old);
jsr hglin ; hplot_to(x_old,y_old);
done_with_loop:
@ -313,7 +313,7 @@ draw_explosion:
clc
adc #$3
tax
lda COLORTBL,X ; get color from table
lda colortbl,X ; get color from table
sta HGR_COLOR
; hplot(xpos,ypos_h); // draw at center of explosion
@ -323,7 +323,7 @@ draw_explosion:
ldx XPOS_L
lda YPOS_H
ldy #0
jsr HPLOT0 ; hplot(x_old,y_old);
jsr hplot0 ; hplot(x_old,y_old);
@ -346,7 +346,7 @@ explosion_loop:
clc
adc #$3
tax
lda COLORTBL,X ; get color from table
lda colortbl,X ; get color from table
sta HGR_COLOR
ldx TEMPY
@ -361,7 +361,7 @@ explosion_erase:
; erase with proper color black (0 or 4)
ldx COLOR_GROUP
lda COLORTBL,X ; get color from table
lda colortbl,X ; get color from table
sta HGR_COLOR
ldx TEMPY
@ -410,7 +410,7 @@ explosion:
lda YPOS_H
adc OFFSET
jsr HPLOT0 ; hplot(xpos+o,ypos_h+o); SE
jsr hplot0 ; hplot(xpos+o,ypos_h+o); SE
@ -424,7 +424,7 @@ explosion:
lda YPOS_H
sbc OFFSET
jsr HPLOT0 ; hplot(xpos+o,ypos_h-o); NE
jsr hplot0 ; hplot(xpos+o,ypos_h-o); NE
sec
@ -437,7 +437,7 @@ explosion:
lda YPOS_H
sbc OFFSET
jsr HPLOT0 ; hplot(xpos-o,ypos_h-o); NW
jsr hplot0 ; hplot(xpos-o,ypos_h-o); NW
sec
@ -450,7 +450,7 @@ explosion:
lda YPOS_H
adc OFFSET
jsr HPLOT0 ; hplot(xpos-o,ypos_h+o); SW
jsr hplot0 ; hplot(xpos-o,ypos_h+o); SW
; HPLOT X,Y: X= (y,x), Y=a
@ -465,7 +465,7 @@ explosion:
lsr
adc YPOS_H
jsr HPLOT0 ; hplot(xpos,ypos_h+(o*1.5)); S
jsr hplot0 ; hplot(xpos,ypos_h+(o*1.5)); S
ldx XPOS_L
ldy #0
@ -480,7 +480,7 @@ explosion:
adc #1
adc YPOS_H
jsr HPLOT0 ; hplot(xpos,ypos_h-(o*1.5)); N
jsr hplot0 ; hplot(xpos,ypos_h-(o*1.5)); N
; HPLOT X,Y: X= (y,x), Y=a
@ -497,7 +497,7 @@ explosion:
lda YPOS_H
jsr HPLOT0 ; hplot(xpos+(o*1.5),ypos_h); E
jsr hplot0 ; hplot(xpos+(o*1.5),ypos_h); E
clc ; O O*1.5 NEG
@ -515,7 +515,7 @@ explosion:
lda YPOS_H
jsr HPLOT0 ; hplot(xpos-(o*1.5),ypos_h); // W
jsr hplot0 ; hplot(xpos-(o*1.5),ypos_h); // W
rts
@ -543,7 +543,7 @@ star_loop:
lda stars+1,Y
ldy #0
jsr HPLOT0
jsr hplot0
pla
tay

376
fireworks/hgr.s Normal file
View File

@ -0,0 +1,376 @@
HGR_SHAPE = $1A
HGR_SHAPE_H = $1B
HGR_BITS = $1C
HGR_COUNT = $1D
HMASK = $30
DSCTMP = $9D
HGR_DX = $D0
HGR_DX_H = $D1
HGR_DY = $D2
HGR_QUADRANT = $D3
HGR_E = $D4
HGR_E_H = $D5
HGR_X = $E0
HGR_X_H = $E1
HGR_Y = $E2
;HGR_COLOR = $E4
HGR_HORIZ = $E5
HGR_PAGE = $E6
TXTCLR = $C050
MIXSET = $C053
LOWSCR = $C054
MIXCLR = $C052
HISCR = $C055
hgr2:
; F3D8
bit HISCR ; BIT SW.HISCR Use PAGE2 ($C055)
bit MIXCLR ; BIT SW.MIXCLR
lda #$40 ; HIRES Page 2 at $4000
bne sethpg
hgr:
; F3E2
lda #$20 ; HIRES Page 1 at $2000
bit LOWSCR ; BIT SW.LOWSCR Use PAGE1 ($C054)
bit MIXSET ; BIT SW.MIXSET (Mixed text)
sethpg:
; F3EA
sta HGR_PAGE
lda HIRES
lda TXTCLR
hclr:
lda #0 ; black background
sta HGR_BITS
bkgnd:
; F3F6
lda HGR_PAGE
sta HGR_SHAPE+1
ldy #0
sty HGR_SHAPE
bkgnd_loop:
lda HGR_BITS
sta (HGR_SHAPE),y
jsr color_shift
iny
bne bkgnd_loop
inc HGR_SHAPE+1
lda HGR_SHAPE+1
and #$1f ; see if $40 or $60
bne bkgnd_loop
rts
msktbl: .byte $81,$82,$84,$88,$90,$A0,$C0
hposn:
; F411
sta HGR_Y
stx HGR_X
sty HGR_X+1
pha
and #$C0
sta GBASL
lsr
lsr
ora GBASL
sta GBASL
pla
; F423
sta GBASH
asl
asl
asl
rol GBASH
asl
rol GBASH
asl
ror GBASL
lda GBASH
and #$1f
ora HGR_PAGE
sta GBASH
; F438
txa
cpy #0
beq hposn_2
ldy #35
adc #4
hposn_1:
iny
; f442
hposn_2:
sbc #7
bcs hposn_1
sty HGR_HORIZ
tax
lda msktbl-$100+7,x ; LDA MSKTBL-$100+7,X BIT MASK
; MSKTBL=F5B2
sta HMASK
tya
lsr
lda HGR_COLOR
sta HGR_BITS
bcs color_shift
rts
hplot0:
; F457
jsr hposn
lda HGR_BITS
eor (GBASL),y
and HMASK
eor (GBASL),y
sta (GBASL),y
rts
move_left_or_right:
; F465
bpl move_right
lda HMASK
lsr
bcs lr_2
eor #$c0
lr_1:
sta HMASK
rts
lr_2:
dey
bpl lr_3
ldy #39
lr_3:
lda #$c0
lr_4:
sta HMASK
sty HGR_HORIZ
lda HGR_BITS
color_shift:
; F47E
asl
cmp #$c0
bpl done_color_shift
lda HGR_BITS
eor #$7f
sta HGR_BITS
done_color_shift:
rts
move_right:
lda HMASK
asl
eor #$80
bmi lr_1
lda #$81
iny
cpy #40
bcc lr_4
ldy #0
bcs lr_4
con_1c: .byte $1c
con_03: .byte $03
con_04: .byte $04
move_up_or_down:
; F4D3
bmi move_down
clc
lda GBASH
bit con_1c ; CON.1C
bne mu_5
asl GBASL
bcs mu_3
bit con_03 ; CON.03
beq mu_1
adc #$1f
sec
bcs mu_4
; F4Eb
mu_1:
adc #$23
pha
lda GBASL
adc #$b0
bcs mu_2
adc #$f0
; f4f6
mu_2:
sta GBASL
pla
bcs mu_4
mu_3:
adc #$1f
mu_4:
ror GBASL
mu_5:
adc #$fc
ud_1:
sta GBASH
rts
; f505
move_down:
lda GBASH
adc #$4
bit con_1c
bne ud_1
asl GBASL
bcc md_2
adc #$e0
clc
bit con_04
beq md_3;
lda GBASL
adc #$50
eor #$f0
beq md_1
eor #$f0
md_1:
sta GBASL
lda HGR_PAGE
bcc md_3
md_2:
adc #$e0
md_3:
ror GBASL
bcc ud_1
hglin:
; F53A
pha
sec
sbc HGR_X
pha
txa
sbc HGR_X+1
sta HGR_QUADRANT
; F544
bcs hglin_1
pla
eor #$ff
adc #1
pha
lda #0
sbc HGR_QUADRANT
; F550
hglin_1:
sta HGR_DX+1
sta HGR_E+1
pla
sta HGR_DX
sta HGR_E
pla
sta HGR_X
stx HGR_X+1
tya
clc
sbc HGR_Y
bcc hglin_2
eor #$ff
adc #$fe
hglin_2:
; F568
sta HGR_DY
sty HGR_Y
ror HGR_QUADRANT
sec
sbc HGR_DX
tax
lda #$ff
sbc HGR_DX+1
sta HGR_COUNT
ldy HGR_HORIZ
bcs movex2 ; always?
; f57c
movex:
asl
jsr move_left_or_right
sec
; f581
movex2:
lda HGR_E
adc HGR_DY
sta HGR_E
lda HGR_E+1
sbc #0
movex2_1:
sta HGR_E+1
lda (GBASL),y
eor HGR_BITS
and HMASK
eor (GBASL),y
sta (GBASL),y
inx
bne movex2_2
inc HGR_COUNT
beq rts22
; F59e
movex2_2:
lda HGR_QUADRANT
bcs movex
jsr move_up_or_down
clc
lda HGR_E
adc HGR_DX
sta HGR_E
lda HGR_E+1
adc HGR_DX+1
bvc movex2_1
hplot_to:
; F712
sty DSCTMP
tay
txa
ldx DSCTMP
jsr hglin
rts22:
rts
; Color in X
hcolor_equals:
; F6E9
; TODO: mask to be less than 8
lda colortbl,x
sta HGR_COLOR
rts
colortbl:
.byte $00,$2A,$55,$7F,$80,$AA,$D5,$FF