Tiledraw rewrite for speed and size, locals bugfix

This commit is contained in:
Jeremy Penner 2021-09-06 00:19:22 -04:00
parent 7a3436dc7e
commit a03c8b2865
3 changed files with 14 additions and 14 deletions

View file

@ -54,7 +54,7 @@
(match op
(where [mvx srcbank dstbank]
(= (type srcbank) :number) (= (type dstbank) :number) (= (mvx:sub 1 2) :mv))
[:bm [srcbank dstbank]]
[:bm [dstbank srcbank]] ; encoded backwards for some reason
[_ offset :s] [:sr offset]
(where [_ imm] (or (= (type imm) :number) (= (type imm) :function))) [:imm imm]
[_ [[addr]] :y] [:idly addr]

View file

@ -46,18 +46,16 @@
[[:lda (bit.bor (bit.lshift r 8) (bit.lshift g 4) b)] [:sta (tostring (+ addr (* icolor 2) -2))]])]
(lume.concat [:block] (table.unpack writes))))])
(fn draw-tile (tile (long addr))
(fn draw-tile (tile addr)
(asm
(lda addr) (sta [ssc.ADDR_LO])
(lda addr 2) (sta [ssc.ADDR_HI])
(ldy 0) (ldx 16) (clc)
(lda 16) (sta [ssc.LONG_LO]) (clc)
(lda tile) (tax) (lda addr) (tay)
(bra draw)
loop
(lda (tile) :y) (sta (([ssc.ADDR_LO])) :y) (iny) (iny)
(lda (tile) :y) (sta (([ssc.ADDR_LO])) :y) (iny) (iny)
(lda (tile) :y) (sta (([ssc.ADDR_LO])) :y) (iny) (iny)
(lda (tile) :y) (sta (([ssc.ADDR_LO])) :y) (iny) (iny)
(lda [ssc.ADDR_LO]) (adc 152) (sta [ssc.ADDR_LO])
(dex) (bne loop)))
(tya) (adc 152) (tay)
draw
(lda 7) (mvn 0 0xe1)
(dec [ssc.LONG_LO]) (bne loop)))
(global word userID)
@ -68,7 +66,7 @@
(set! i (+ i 1)))))
(fn draw-test-tiles ()
(let (x 0 y 0 screen screen-addr)
(let (x 0 y 0 screen 0x2000)
(while (< y 12)
(draw-tile (ref tiles) screen)
(set! x (+ x 1))
@ -87,9 +85,11 @@
(EMStartUp 0x2000 0 0 320 0 200 userID)
(GrafOn)
(ClearScreen 0)
(set-palette 0 [pal])
(SetAllSCBs 0)
(wait-for-key)
(draw-test-tiles)
(wait-for-key)

View file

@ -70,7 +70,7 @@
:word)
c-setup (when opgen.setup (opgen.setup))
c-hi (when opgen.hi [(opgen.hi :lda) [:pha]])
loc {: name :type :word}
loc {: name :type (if c-hi :word :placeholder)}
_ (table.insert self.locals loc)
c-lo [(opgen.lo :lda) [:pha]]]
(set loc.type etype)
@ -343,7 +343,7 @@
(var stacklen 0)
(for [i 1 (length self.locals)]
(let [loc (. self.locals i)
size (match loc.type :word 2 :long 4 _ (error (.. "how big is this local??" (fv loc))))]
size (match loc.type :placeholder 0 :word 2 :long 4 _ (error (.. "how big is this local??" (fv loc))))]
(set stacklen (+ stacklen size))
(when (or (= i name-or-index) (= loc.name name-or-index))
(set offset stacklen))))