2020-05-13 04:40:09 +00:00
|
|
|
; Sierpinski, based on the code in Hellmood's Memories
|
|
|
|
|
|
|
|
; by deater (Vince Weaver) <vince@deater.net>
|
|
|
|
|
|
|
|
; Zero Page
|
2020-05-17 04:17:25 +00:00
|
|
|
GBASL = $26
|
|
|
|
GBASH = $27
|
2020-05-13 04:40:09 +00:00
|
|
|
H2 = $2C
|
2020-05-17 04:17:25 +00:00
|
|
|
MASK = $2F
|
2020-05-13 04:40:09 +00:00
|
|
|
COLOR = $30
|
|
|
|
|
|
|
|
BH = $EF
|
|
|
|
Y1 = $F0
|
|
|
|
Y2 = $F1
|
|
|
|
|
|
|
|
NUM1L = $F2
|
|
|
|
NUM1H = $F3
|
|
|
|
NUM2L = $F4
|
|
|
|
NUM2H = $F5
|
|
|
|
RESULT0 = $F6
|
|
|
|
RESULT1 = $F7
|
|
|
|
RESULT2 = $F8
|
|
|
|
RESULT3 = $F9
|
|
|
|
|
|
|
|
|
|
|
|
TEMP = $FA
|
|
|
|
TEMPY = $FB
|
|
|
|
FRAMEL = $FC
|
|
|
|
FRAMEH = $FD
|
|
|
|
TEMPX = $FE
|
|
|
|
SCALED = $FF
|
|
|
|
|
|
|
|
|
|
|
|
; Soft Switches
|
|
|
|
KEYPRESS= $C000
|
|
|
|
KEYRESET= $C010
|
|
|
|
SET_GR = $C050 ; Enable graphics
|
|
|
|
FULLGR = $C052 ; Full screen, no text
|
|
|
|
PAGE0 = $C054 ; Page0
|
|
|
|
PAGE1 = $C055 ; Page1
|
|
|
|
LORES = $C056 ; Enable LORES graphics
|
|
|
|
|
|
|
|
; ROM routines
|
|
|
|
|
|
|
|
PLOT = $F800 ; plot, horiz=y, vert=A (A trashed, XY Saved)
|
|
|
|
SETCOL = $F864
|
|
|
|
TEXT = $FB36 ;; Set text mode
|
|
|
|
BASCALC = $FBC1
|
|
|
|
SETGR = $FB40
|
|
|
|
HOME = $FC58 ;; Clear the text screen
|
|
|
|
WAIT = $FCA8 ;; delay 1/2(26+27A+5A^2) us
|
|
|
|
HLINE = $F819
|
|
|
|
|
|
|
|
|
2020-05-13 15:12:45 +00:00
|
|
|
sierpx = $3000
|
|
|
|
sierpy = $3100
|
|
|
|
scaledx = $3200
|
|
|
|
scaledy = $3300
|
|
|
|
|
2020-05-13 04:40:09 +00:00
|
|
|
|
|
|
|
sierpinksi:
|
|
|
|
|
|
|
|
;===================
|
|
|
|
; init screen
|
|
|
|
jsr SETGR ; 3
|
|
|
|
bit FULLGR ; 3
|
|
|
|
|
2020-05-13 15:12:45 +00:00
|
|
|
; lda #>(2048)
|
|
|
|
lda #0
|
2020-05-13 04:40:09 +00:00
|
|
|
sta FRAMEH
|
|
|
|
lda #0
|
|
|
|
sta FRAMEL
|
|
|
|
|
|
|
|
jsr init_multiply_tables
|
|
|
|
|
|
|
|
sierpinski_forever:
|
|
|
|
|
|
|
|
|
|
|
|
inc FRAMEL ; 2
|
2020-05-13 15:12:45 +00:00
|
|
|
bne done_frame_inc
|
2020-05-13 04:40:09 +00:00
|
|
|
inc FRAMEH
|
2020-05-13 15:12:45 +00:00
|
|
|
done_frame_inc:
|
|
|
|
|
|
|
|
; pre-generate the multiplications
|
|
|
|
jsr sierpinski_generate
|
|
|
|
|
|
|
|
ldx #47 ; yy ; 2
|
|
|
|
|
2020-05-13 04:40:09 +00:00
|
|
|
|
|
|
|
yloop:
|
|
|
|
ldy #39 ; xx ; 2
|
|
|
|
xloop:
|
|
|
|
|
|
|
|
; t=frame-2048 (assuming we are effect #4?)
|
|
|
|
|
2020-05-13 15:12:45 +00:00
|
|
|
; lda FRAMEL
|
|
|
|
; sta NUM1L
|
|
|
|
|
|
|
|
; sec
|
|
|
|
; lda FRAMEH
|
|
|
|
; sbc #>(2048)
|
|
|
|
|
|
|
|
; rol NUM1L ; time<<=3, speed up by factor of 8
|
|
|
|
; rol
|
|
|
|
; rol NUM1L
|
|
|
|
; rol
|
|
|
|
; rol NUM1L
|
|
|
|
; rol
|
|
|
|
; sta NUM1H
|
|
|
|
|
|
|
|
; txa ; yy*=4
|
|
|
|
; asl
|
|
|
|
; asl
|
|
|
|
; sta NUM2L
|
|
|
|
; sta Y1
|
|
|
|
; lda #0
|
|
|
|
; sta NUM2H
|
|
|
|
|
|
|
|
; jsr multiply_u16x16 ; result = Y*T
|
|
|
|
|
|
|
|
; tya
|
|
|
|
; asl
|
|
|
|
; asl
|
|
|
|
; sta NUM2L
|
|
|
|
; lda #0
|
|
|
|
; rol NUM2L
|
|
|
|
; rol
|
|
|
|
; sta NUM2H ; NUM2 = X*8
|
2020-05-13 04:40:09 +00:00
|
|
|
|
|
|
|
; sign extend X
|
|
|
|
|
|
|
|
; xsext=xprime*8; // get X into DL
|
|
|
|
; if (xsext&0x80*8) xsext|=0xff00*8;
|
|
|
|
; else xsext&=0x00ff*8;
|
|
|
|
|
|
|
|
clc
|
2020-05-13 15:12:45 +00:00
|
|
|
lda sierpy,X ; RESULT1
|
|
|
|
adc scaledx,Y ; NUM2L
|
2020-05-13 04:40:09 +00:00
|
|
|
sta BH ; bh=((y*t)/256)+X
|
|
|
|
|
2020-05-13 15:12:45 +00:00
|
|
|
; jsr multiply_u16x16_same_num1 ; result = X*T
|
2020-05-13 04:40:09 +00:00
|
|
|
; dh=RESULT1
|
|
|
|
|
|
|
|
; dh=(temp>>8)&0xff; // dh=(X*T/256)
|
|
|
|
|
|
|
|
; color=(yy-dh)&bh; // color=(Y-(X*T/256))&(Y*T/256+X)
|
|
|
|
|
|
|
|
|
|
|
|
sec
|
2020-05-13 15:12:45 +00:00
|
|
|
txa
|
|
|
|
lda scaledy,X ; Y1
|
|
|
|
sbc sierpx,Y ; RESULT1
|
2020-05-13 04:40:09 +00:00
|
|
|
and BH
|
|
|
|
|
2020-05-13 15:12:45 +00:00
|
|
|
and #$f8 ; thicker sierpinksi
|
2020-05-13 04:40:09 +00:00
|
|
|
|
|
|
|
; if zero, color=9. Otherwise, 0
|
|
|
|
|
|
|
|
bne color_black ; leave black if not sierpinksi
|
|
|
|
lda #$99 ; otherwise: a nice orange
|
|
|
|
bne color_done
|
|
|
|
color_black:
|
|
|
|
lda #$00
|
|
|
|
color_done:
|
|
|
|
|
|
|
|
sta COLOR
|
|
|
|
|
|
|
|
txa ; A==Y1 ; 1
|
2020-05-17 04:17:25 +00:00
|
|
|
; jsr PLOT ; (X2,Y1) ; 3
|
|
|
|
jsr fast_plot
|
2020-05-13 04:40:09 +00:00
|
|
|
|
|
|
|
dey ; 1
|
|
|
|
bpl xloop ; 2
|
|
|
|
|
|
|
|
dex ; 1
|
|
|
|
bpl yloop ; 2
|
|
|
|
|
|
|
|
bmi sierpinski_forever ; 2
|
|
|
|
|
|
|
|
|
2020-05-17 04:17:25 +00:00
|
|
|
; for grabbing screenshot
|
|
|
|
;check_key:
|
|
|
|
; bit KEYPRESS
|
|
|
|
; bpl check_key
|
|
|
|
; jmp sierpinski_forever ; 2
|
|
|
|
|
|
|
|
|
2020-05-13 04:40:09 +00:00
|
|
|
|
2020-05-13 15:12:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sierpinski_generate:
|
|
|
|
|
|
|
|
; t=frame-2048 (assuming we are effect #4?)
|
|
|
|
|
|
|
|
lda FRAMEL
|
|
|
|
sta NUM1L
|
|
|
|
|
|
|
|
; sec
|
|
|
|
lda FRAMEH
|
|
|
|
; sbc #>(2048)
|
|
|
|
|
|
|
|
rol NUM1L ; time<<=3, speed up by factor of 8
|
|
|
|
rol
|
|
|
|
rol NUM1L
|
|
|
|
rol
|
|
|
|
rol NUM1L
|
|
|
|
rol
|
|
|
|
sta NUM1H
|
|
|
|
|
|
|
|
jsr multiply_u16x16 ; setup NUM1H/NUM1L
|
|
|
|
|
|
|
|
;========================
|
|
|
|
|
|
|
|
ldx #47 ; yy ; 2
|
|
|
|
genyloop:
|
|
|
|
|
|
|
|
|
|
|
|
txa ; yy*=4
|
|
|
|
asl
|
|
|
|
asl
|
|
|
|
sta NUM2L
|
|
|
|
sta scaledy,X
|
|
|
|
lda #0
|
|
|
|
sta NUM2H
|
|
|
|
|
|
|
|
jsr multiply_u16x16_same_num1 ; result = Y*T
|
|
|
|
|
|
|
|
lda RESULT1
|
|
|
|
sta sierpy,X
|
|
|
|
|
|
|
|
dex ; 1
|
|
|
|
bpl genyloop ; 2
|
|
|
|
|
|
|
|
;====================
|
|
|
|
;====================
|
|
|
|
;====================
|
|
|
|
|
|
|
|
ldy #39 ; xx ; 2
|
|
|
|
genxloop:
|
|
|
|
|
|
|
|
tya
|
|
|
|
asl
|
|
|
|
asl
|
|
|
|
sta NUM2L
|
|
|
|
lda #0
|
|
|
|
rol NUM2L
|
|
|
|
rol
|
|
|
|
sta NUM2H ; NUM2 = X*8
|
|
|
|
lda NUM2L
|
|
|
|
sta scaledx,Y
|
|
|
|
|
|
|
|
; sign extend X
|
|
|
|
|
|
|
|
; xsext=xprime*8; // get X into DL
|
|
|
|
; if (xsext&0x80*8) xsext|=0xff00*8;
|
|
|
|
; else xsext&=0x00ff*8;
|
|
|
|
|
|
|
|
jsr multiply_u16x16_same_num1 ; result = X*T
|
|
|
|
|
|
|
|
lda RESULT1
|
|
|
|
sta sierpx,Y
|
|
|
|
|
|
|
|
dey ; 1
|
|
|
|
bpl genxloop ; 2
|
|
|
|
|
|
|
|
rts
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-05-17 04:17:25 +00:00
|
|
|
.include "fast_plot.s"
|
2020-05-13 15:12:45 +00:00
|
|
|
|
|
|
|
.include "multiply_tables.s"
|
|
|
|
;.include "multiply_s16x16.s"
|
|
|
|
.include "multiply_u16x16_mod.s"
|
|
|
|
|
|
|
|
; original
|
2020-05-17 04:17:25 +00:00
|
|
|
; + plot is $5d cycles (93), so 178560 to draw screen
|
2020-05-13 15:12:45 +00:00
|
|
|
; + $169 (361) to calculate
|
2020-05-17 04:17:25 +00:00
|
|
|
; + 693120+178560 = 872k to draw screen (~1fps)
|
2020-05-13 15:12:45 +00:00
|
|
|
|
|
|
|
; with lookup table:
|
2020-05-17 04:17:25 +00:00
|
|
|
; + plot is $5d cycles (93), so 178560 to draw screen
|
|
|
|
; + $3a (58) to calculate
|
|
|
|
; + $2e5c (11,868) to setup tables
|
|
|
|
; + 111360+178560+11868=290k (~3fps)
|
|
|
|
|
|
|
|
; with lookup table+inline fast_plot
|
|
|
|
; + plot is $31 cycles (49), so 94080 to draw screen
|
2020-05-13 15:12:45 +00:00
|
|
|
; + $3a (58) to calculate
|
|
|
|
; + $2e5c (11,868) to setup tables
|
2020-05-17 04:17:25 +00:00
|
|
|
; + 111360+94080+11868=217k (~4fps)
|
|
|
|
|