dos33fsprogs/demos/shapetable_party/dsr_shape.s

308 lines
5.3 KiB
ArmAsm
Raw Permalink Normal View History

2020-06-14 02:59:48 +00:00
; shapetable party
; by Deater for -=dSr=-
; @party 2020
2020-06-14 02:55:33 +00:00
2020-06-14 03:01:07 +00:00
; trying to beat 251 bytes
2020-06-14 03:00:07 +00:00
2020-06-14 02:55:33 +00:00
; zero page locations
HGR_SHAPE = $1A
SEEDL = $4E
FRAME = $A4
2020-06-14 02:57:19 +00:00
OUR_ROT = $A5
2020-06-14 02:55:33 +00:00
RND_EXP = $C9
HGR_PAGE = $E6
HGR_SCALE = $E7
HGR_ROTATION = $F9
SCALE = $FC
XPOS = $FD
YPOS = $FF
; Soft Switches
KEYPRESS = $C000
KEYRESET = $C010
SPEAKER = $C030
PAGE0 = $C054
PAGE1 = $C055
; ROM calls
RND = $EFAE
HGR2 = $F3D8
HCLR = $F3F2
HCLR_COLOR = $F3F4
HPOSN = $F411
XDRAW0 = $F65D
2020-06-14 02:59:48 +00:00
TEXT = $FB36 ; Set text mode
2020-06-14 02:55:33 +00:00
WAIT = $FCA8 ; delay 1/2(26+27A+5A^2) us
2020-06-14 02:59:48 +00:00
2020-06-14 02:55:58 +00:00
dsr_demo:
;=========================================
; SETUP
;=========================================
2020-06-14 02:55:33 +00:00
2020-06-14 02:56:29 +00:00
lda #$20 ; 2 ; set HGR page0
sta HGR_PAGE ; 2
sta XPOS ; 2 ; setup XPOS for future
2020-06-14 02:55:33 +00:00
2020-06-14 02:56:29 +00:00
lda #$ff ; 2
jsr HCLR_COLOR ; 3 ; clear HGR page0 to white
2020-06-14 02:55:33 +00:00
2020-06-14 02:56:29 +00:00
jsr HGR2 ; 3 ; set/clear HGR page1 to black
; Hi-res graphics, no text at bottom
; Y=0, A=$60 after this call
2020-06-14 02:55:33 +00:00
2020-06-14 02:56:29 +00:00
sty FRAME ; 2
2020-06-14 02:57:19 +00:00
sty OUR_ROT ; 2
2020-06-14 02:55:33 +00:00
2020-06-14 02:56:29 +00:00
iny ; 1 ; set shape table scale to 1
sty HGR_SCALE ; 2
;=========================
; draw crowd
;=========================
; XPOS already 32 from earlier
lda #180 ; 2
sta YPOS ; 2
2020-06-14 02:55:33 +00:00
crowd_loop:
2020-06-14 02:56:29 +00:00
jsr xdraw ; 3 ; xdraw on page1
2020-06-14 02:55:33 +00:00
2020-06-14 02:56:29 +00:00
lsr HGR_PAGE ; 2 ; switch to page0 ($40 -> $20)
2020-06-14 02:55:33 +00:00
2020-06-14 02:56:29 +00:00
jsr xdraw ; 3 ; xdraw on page 0
2020-06-14 02:55:33 +00:00
2020-06-14 02:56:29 +00:00
asl HGR_PAGE ; 2 ; switch back to page1 $20 -> $40
2020-06-14 02:55:33 +00:00
2020-06-14 02:56:29 +00:00
; clc ; carry should always be 0 from asl
lda XPOS ; 2
adc #16 ; 2
sta XPOS ; 2
2020-06-14 02:58:08 +00:00
bne crowd_loop ; 2
2020-06-14 02:55:33 +00:00
; get ready for DSR loop
2020-06-14 02:56:29 +00:00
ldx #<shape_dsr ; 2 ; point to dSr shape
stx shape_smc+1 ; 3 ; update self-modify code
2020-06-14 02:55:33 +00:00
2020-06-14 02:57:19 +00:00
;====================================
2020-06-14 02:58:08 +00:00
; 50 bytes to init/draw crowd
2020-06-14 02:55:58 +00:00
;=========================================
; OFFSCREEN RESET
;=========================================
2020-06-14 02:55:33 +00:00
reset_loop:
2020-06-14 02:56:29 +00:00
lda #10 ; 2 ; set initial x,y
sta XPOS ; 2
sta YPOS ; 2
2020-06-14 02:55:33 +00:00
2020-06-14 02:57:19 +00:00
inc HGR_SCALE ; 2 ; increment scale
2020-06-14 02:55:33 +00:00
2020-06-14 02:55:58 +00:00
;=========================================
; MAIN LOOP
;=========================================
2020-06-14 02:55:33 +00:00
main_loop:
2020-06-14 02:57:19 +00:00
inc OUR_ROT ; 2
inc OUR_ROT ; 2
2020-06-14 02:56:29 +00:00
2020-06-14 02:55:33 +00:00
; increment FRAME
2020-06-14 02:56:29 +00:00
inc FRAME ; 2
lda FRAME ; 2
2020-06-14 02:55:33 +00:00
2020-06-14 02:56:29 +00:00
and #$1f ; 2
beq long_frame ; 2
2020-06-14 02:55:33 +00:00
2020-06-14 03:00:07 +00:00
lda #15 ; 2
2020-06-14 02:57:44 +00:00
jsr draw_and_beep ; 3
2020-06-14 02:55:33 +00:00
2020-06-14 02:55:58 +00:00
done_frame:
2020-06-14 02:55:33 +00:00
2020-06-14 02:55:58 +00:00
;========================
; move dSr
;========================
2020-06-14 02:55:33 +00:00
2020-06-14 03:01:07 +00:00
inc YPOS ; 2
inc YPOS ; 2
inc YPOS ; 2
2020-06-14 03:00:07 +00:00
2020-06-14 03:01:07 +00:00
lda XPOS ; 2
adc #5 ; 2
sta XPOS ; 2
2020-06-14 02:55:33 +00:00
2020-06-14 03:01:07 +00:00
cmp #250 ; 2
bcs reset_loop ; 2
bcc main_loop ; 2
2020-06-14 02:55:33 +00:00
2020-06-14 03:00:07 +00:00
shape_person:
; Person, shoulders up
2020-06-14 03:01:07 +00:00
; thanks to Beagle Bros
2020-06-14 03:00:07 +00:00
;.byte $01,$00,$04,$00,
.byte $2d,$25,$3c,$24
.byte $2c,$2c,$35,$37,$6f,$25,$16,$3f
.byte $77,$2d,$1e,$37,$2d,$2d,$15,$3f
.byte $3f,$3f,$3f,$3f,$07,$00
shape_arm:
.byte $49,$49,$49,$24
.byte $24,$24,$ac,$36,$36,$36,$00
shape_dsr:
.byte $2d,$36,$ff,$3f
.byte $24,$ad,$22,$24,$94,$21,$2c,$4d
.byte $91,$3f,$36,$00
2020-06-14 02:55:58 +00:00
;===========================
; long frame
;===========================
2020-06-14 02:55:33 +00:00
long_frame:
2020-06-14 02:57:19 +00:00
bit PAGE0 ; 3 ; switch to page0
lsr HGR_PAGE ; 2 ; switch draw target to page0
2020-06-14 02:55:33 +00:00
2020-06-14 02:58:08 +00:00
;====================
; draw arm (inlined)
;=====================
draw_arm:
2020-06-14 02:59:48 +00:00
lda HGR_SCALE ; 2
pha ; 1
2020-06-14 02:58:08 +00:00
2020-06-14 02:59:48 +00:00
ldy #1 ; 2
sty HGR_SCALE ; 2
2020-06-14 02:58:08 +00:00
; setup X and Y co-ords
2020-06-14 03:01:07 +00:00
ldx FRAME
; no need to and, only called on multipl of 32s
; and #$f0 ; 32, 64, 96, 128, 160, 192, 224, 256
2020-06-14 02:58:08 +00:00
beq skip_arm
2020-06-14 03:01:07 +00:00
; tax ; XPOS
2020-06-14 02:58:08 +00:00
dey ; XPOSH=0
lda #180
jsr HPOSN ; X= (y,x) Y=(a)
ldx #<shape_arm ; 2 ; point to arm shape
jsr xdraw_custom_shape
skip_arm:
2020-06-14 02:59:48 +00:00
pla ; 1
asl ; 1 ; make twice as big
sta HGR_SCALE ; 2
2020-06-14 02:57:19 +00:00
2020-06-14 03:00:07 +00:00
lda #85 ; 2 ; long tone
2020-06-14 02:57:44 +00:00
jsr draw_and_beep ; 3 ; draw and beep
2020-06-14 02:57:19 +00:00
bit PAGE1 ; 3 ; display page back to page1
2020-06-14 02:55:33 +00:00
2020-06-14 02:57:19 +00:00
lsr HGR_SCALE ; 2 ; switch scale back
2020-06-14 02:55:33 +00:00
2020-06-14 02:57:19 +00:00
asl HGR_PAGE ; 2 ; switch draw page to page1
2020-06-14 02:55:33 +00:00
2020-06-14 03:00:07 +00:00
bpl done_frame ; 2 ; return
2020-06-14 02:55:33 +00:00
2020-06-14 02:57:19 +00:00
;=======================
; xdraw
;=======================
2020-06-14 02:55:33 +00:00
xdraw:
2020-06-14 02:57:19 +00:00
; setup X and Y co-ords
ldy #0 ; XPOSH always 0 for us
2020-06-14 02:55:33 +00:00
ldx XPOS
lda YPOS
jsr HPOSN ; X= (y,x) Y=(a)
shape_smc:
ldx #<shape_person ; point to our shape
2020-06-14 02:57:19 +00:00
xdraw_custom_shape:
2020-06-14 02:58:08 +00:00
ldy #>shape_person ; code fits in one page so this doesn't change
2020-06-14 02:55:33 +00:00
rot_smc:
2020-06-14 02:57:19 +00:00
lda OUR_ROT ; set rotation
2020-06-14 02:55:33 +00:00
jmp XDRAW0 ; XDRAW 1 AT X,Y
; Both A and X are 0 at exit
2020-06-14 02:55:58 +00:00
2020-06-14 02:55:33 +00:00
2020-06-14 02:57:44 +00:00
;==========================
; draw/beep/undraw
;==========================
draw_and_beep:
2020-06-14 03:00:40 +00:00
pha ; 1 ; save delay for later
2020-06-14 03:00:07 +00:00
2020-06-14 03:00:40 +00:00
jsr xdraw ; 3 ; xdraw
2020-06-14 02:57:44 +00:00
2020-06-14 03:00:07 +00:00
2020-06-14 02:55:33 +00:00
;===========================
2020-06-14 02:57:44 +00:00
; BEEP (inlined)
2020-06-14 02:55:33 +00:00
;===========================
beep:
2020-06-14 02:55:58 +00:00
2020-06-14 02:55:33 +00:00
; BEEP
2020-06-14 02:57:19 +00:00
; repeat 30 times
2020-06-14 03:00:40 +00:00
2020-06-14 02:59:48 +00:00
ldx #30 ; 2
2020-06-14 03:00:40 +00:00
pla ; 1 ; restore delay
tay ; 1 ; move to Y
2020-06-14 03:00:07 +00:00
2020-06-14 02:55:33 +00:00
tone1_loop:
2020-06-14 03:00:40 +00:00
tya ; 1 ; load delay
2020-06-14 02:59:48 +00:00
jsr WAIT ; 3 ; not as accurate as the cycle count
; method before, but saves a few bytes
2020-06-14 03:00:07 +00:00
lda FRAME ; 2 ; only play tone every 4th frame
and #$3 ; 2
bne no_click ; 2
2020-06-14 02:59:48 +00:00
2020-06-14 03:00:07 +00:00
bit SPEAKER ; 3 ; click speaker
no_click:
2020-06-14 02:59:48 +00:00
dex ; 1
bne tone1_loop ; 2
2020-06-14 02:57:44 +00:00
2020-06-14 02:59:48 +00:00
; WAIT equiv: delay 1/2(26+27A+5A^2) us
; A=2.5 B=13.5 C=13
; Try X=6 Y=21 cycles=757 C=-744 ; WAIT A=14.76
; Try X=6 Y=24 cycles=865 C=-852 ; WAIT A=15.95
; Try X=7 Y=235 cycles=9636 C=-19259 ; WAIT A=85.111
2020-06-14 02:55:33 +00:00
2020-06-14 02:59:48 +00:00
check_finished:
2020-06-14 03:00:40 +00:00
; check for keypress
lda KEYPRESS ; 3 ; see if key pressed
bmi exit_to_prompt ; 2 ; loop if not
2020-06-14 02:59:48 +00:00
lda FRAME ; 2 ; end with big dSr
2020-06-14 03:00:07 +00:00
bne xdraw ; 2 ; xdraw
2020-06-14 02:57:44 +00:00
2020-06-14 02:59:48 +00:00
;==================================
; exit to basic
wait_until_keypress:
lda KEYPRESS ; 3 ; see if key pressed
bpl wait_until_keypress ; 2 ; loop if not
exit_to_prompt:
2020-06-14 03:01:07 +00:00
; bit KEYRESET ; clear keyboard buffer
2020-06-14 02:59:48 +00:00
jsr TEXT ; 3 ; return to text mode
jmp $3D0 ; 3 ; return to Applesoft prompt
2020-06-14 02:57:44 +00:00
2020-06-14 03:00:40 +00:00