dos33fsprogs/graphics/hgr/tiny_triangles/sier_hgr.s

242 lines
4.3 KiB
ArmAsm
Raw Normal View History

2021-04-12 05:33:27 +00:00
; sierpinski-like demo
; based on the code from Hellmood's Memories demo
; by Vince `deater` Weaver <vince@deater.net>
; the simple sierpinski you more or less just plot
; X AND Y
; Hellmood's you plot something more or less like
; COLOR = ( (Y-(X*T)) & (X+(Y*T) ) & 0xf0
; where T is an incrementing frame value
; to get speed on 6502/Apple II we change the multiplies to
; a series of 16-bit 8.8 fixed point adds
; TODO:
2021-04-12 20:39:28 +00:00
; HPLOT: roughly 30s / frame
; MOVERIGHT: roughly 14s / frame
; MOVERIGHT NO COLORSHIFT:roughly 11s / frame
; MOVERIGHT MOVEDOWN roughly 11s / frame
; INLINE HPLOT roughly 9s / frame
; INLINE EVERYTHING roughly 7s / frame
; XT/YT lookup tables roughly 6s / frame
2021-04-13 05:01:06 +00:00
; only write 1/7 of time roughly 3s / frame
; only draw 128 lines roughly 2s / frame
2021-04-12 05:33:27 +00:00
; zero page
HGR_BITS = $1C
2021-04-12 18:47:49 +00:00
GBASL = $26
2021-04-12 05:33:27 +00:00
GBASH = $27
MASK = $2E
COLOR = $30
2021-04-12 18:47:49 +00:00
HGR_HMASK = $30
2021-04-12 05:33:27 +00:00
HGR_X = $E0
HGR_Y = $E2
HGR_COLOR = $E4
2021-04-12 19:17:21 +00:00
HGR_HORIZ = $E5
2021-04-12 18:47:49 +00:00
2021-04-13 01:39:26 +00:00
SEVEN = $F6
NEXTCOL = $F7
2021-04-12 05:33:27 +00:00
XX_TH = $F8
XX_TL = $F9
2021-04-12 18:47:49 +00:00
YY = $FA
2021-04-12 05:33:27 +00:00
YY_TH = $FB
YY_TL = $FC
2021-04-12 18:47:49 +00:00
T_L = $FD
T_H = $FE
2021-04-12 05:33:27 +00:00
SAVED = $FF
; Soft switches
FULLGR = $C052
PAGE1 = $C054
PAGE2 = $C055
; ROM routines
HGR = $F3E2
HGR2 = $F3D8
2021-04-12 18:47:49 +00:00
HPOSN = $F411
HPLOT0 = $F457
HPLOT1 = $F45A ; skip the HPOSN call
COLOR_SHIFT = $F47E ; shift color for odd/even Y (0..7 or 7..13)
MOVE_RIGHT = $F48A ; move next plot location one to the right
MOVE_DOWN = $F504 ; clc at f504, needed?
; f505 is applesoft entry point but assumes c?
; move next plot location one to the right
; note moveright/movedown respect HGR_PAGE
COLORTBL = $F6F6
2021-04-12 05:33:27 +00:00
2021-04-12 20:39:28 +00:00
XT_LOOKUP_TABLE = $1000
YT_LOOKUP_TABLE = $1100
2021-04-12 05:33:27 +00:00
;.zeropage
;.globalzp T_L,T_H
;================================
; Clear screen and setup graphics
;================================
sier:
jsr HGR2 ; set FULLGR, sets A=0
2021-04-12 20:39:28 +00:00
sta T_L ; start with multiplier 0
2021-04-12 18:47:49 +00:00
sta T_H
2021-04-12 05:33:27 +00:00
sier_outer:
2021-04-13 01:39:26 +00:00
2021-04-12 20:39:28 +00:00
ldx #0 ; get X 0 for later
stx YY ; YY starts at 0
; create XX_T and YY_T lookup tables
2021-04-12 05:33:27 +00:00
stx XX_TL ; always start at 0
2021-04-12 20:39:28 +00:00
stx XX_TH
2021-04-12 05:33:27 +00:00
2021-04-12 20:39:28 +00:00
; calc XX*T
; only really care about XX_TH
xt_table_loop:
2021-04-13 05:01:06 +00:00
clc ; 2
2021-04-12 20:39:28 +00:00
lda XX_TL ; 3
adc T_L ; 2
sta XX_TL ; 3
2021-04-12 20:39:28 +00:00
lda XX_TH ; 3
adc T_H ; 3
sta XX_TH ; 3
2021-04-12 20:39:28 +00:00
sta YT_LOOKUP_TABLE,X ; 5
2021-04-12 20:39:28 +00:00
eor #$ff ; negate, as we subtract ; 2
sta XT_LOOKUP_TABLE,X ; 5
inx ; 2
bne xt_table_loop ; 3/2
2021-04-12 05:33:27 +00:00
2021-04-13 05:01:06 +00:00
; inc T
; clc
lda T_L
speed_smc:
adc #2
sta T_L
bcc no_carry
inc T_H
no_carry:
; speed up the zoom as it goes
inc speed_smc+1
; set initial position on screen at line 32
2021-04-12 18:47:49 +00:00
lda #$0 ;
sta GBASL
2021-04-13 05:01:06 +00:00
lda #$42 ; start on page2 line 32 ($4200)
sta GBASH
2021-04-13 05:01:06 +00:00
sier_yloop:
2021-04-12 18:47:49 +00:00
; GBASH is in A here
; lda GBASH ; update output pointer
sta gb_smc+2
lda GBASL ; adjust so centered
clc
adc #$1
sta gb_smc+1
; YY*T only needs to be updated once per line
; so do it here and then self-modify into place
2021-04-12 20:39:28 +00:00
ldx YY ; 3
2021-04-13 05:01:06 +00:00
stx add_yy_smc+1 ; 4
2021-04-12 20:39:28 +00:00
lda YT_LOOKUP_TABLE,X ; 4
sta yy_th_smc+1 ; 4
2021-04-12 05:33:27 +00:00
; reset XX to 0
ldx #0 ; XX
2021-04-13 01:39:26 +00:00
seven_loop:
ldy #7 ; apple ii 7 pixels per byte
2021-04-13 01:39:26 +00:00
2021-04-12 05:33:27 +00:00
sier_xloop:
; want (YY-(XX*T)) & (XX+(YY*T)
; SAVED = XX+(Y*T)
clc ; needed for proper colors ; 2
2021-04-12 18:47:49 +00:00
txa ; XX ; 2
2021-04-12 20:39:28 +00:00
yy_th_smc:
2021-04-13 05:01:06 +00:00
adc #$dd ; 2
2021-04-12 18:47:49 +00:00
sta SAVED ; 3
2021-04-12 05:33:27 +00:00
2021-04-12 20:39:28 +00:00
lda XT_LOOKUP_TABLE,X ; ~(XX*T) ; 4
; calc (YY-XX*T)
2021-04-12 18:47:49 +00:00
sec ; 2
2021-04-13 05:01:06 +00:00
add_yy_smc:
adc #$dd ; 2
2021-04-12 19:17:21 +00:00
2021-04-12 05:33:27 +00:00
; want (YY-(XX*T)) & (XX+(YY*T)
2021-04-12 18:47:49 +00:00
and SAVED ; 3
;============
2021-04-13 05:01:06 +00:00
; 20
2021-04-12 05:33:27 +00:00
2021-04-12 21:11:41 +00:00
clc ; 2
2021-04-12 19:17:21 +00:00
beq black ; 2/3
2021-04-12 05:33:27 +00:00
white:
2021-04-12 21:11:41 +00:00
sec ; 2
2021-04-12 19:17:21 +00:00
black:
;=====
2021-04-13 05:01:06 +00:00
; 5/6
2021-04-12 19:17:21 +00:00
2021-04-13 05:01:06 +00:00
ror NEXTCOL ; rotate in next bit ; 5
2021-04-12 21:11:41 +00:00
2021-04-13 05:01:06 +00:00
inx ; increment x ; 2
2021-04-12 21:11:41 +00:00
2021-04-13 05:01:06 +00:00
dey ; dec seven count ; 2
bne sier_xloop ; 2/3
2021-04-12 19:17:21 +00:00
2021-04-13 05:01:06 +00:00
;===========================================================
2021-04-12 05:33:27 +00:00
2021-04-13 05:01:06 +00:00
lda NEXTCOL ; sign extend top bit, ; 3
cmp #$80 ; matches earlier cool colors ; 2
ror ; 2
gb_smc:
sta $4000 ; write to hi-res display ; 4
2021-04-13 05:01:06 +00:00
inc gb_smc+1 ; increase GBASL ; 6
cpx #248 ; 2
bcc seven_loop ; 3/2
2021-04-12 05:33:27 +00:00
2021-04-12 19:42:09 +00:00
;=================
2021-04-13 05:01:06 +00:00
; total roughly ???
; full screen each inner cycle is done 256*192 = 49152
2021-04-12 19:42:09 +00:00
; apple II cyles/frame = 17,030
; 1FPS = 1,021,800
2021-04-12 18:47:49 +00:00
;==================================
jsr MOVE_DOWN ; ROM routine to skip the next line
; as this is non-trivial on Apple II
; X/Y left alone
2021-04-13 05:01:06 +00:00
; returns with GBASH in A
2021-04-12 18:47:49 +00:00
2021-04-13 05:01:06 +00:00
inc YY ; repeat until YY=128
bpl sier_yloop
2021-04-12 05:33:27 +00:00
;flip_pages:
2021-04-12 18:47:49 +00:00
; TODO if frame rate ever gets fast enough
2021-04-12 05:33:27 +00:00
bmi sier_outer ; branch always
2021-04-12 05:33:27 +00:00