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 (match op
(where [mvx srcbank dstbank] (where [mvx srcbank dstbank]
(= (type srcbank) :number) (= (type dstbank) :number) (= (mvx:sub 1 2) :mv)) (= (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] [_ offset :s] [:sr offset]
(where [_ imm] (or (= (type imm) :number) (= (type imm) :function))) [:imm imm] (where [_ imm] (or (= (type imm) :number) (= (type imm) :function))) [:imm imm]
[_ [[addr]] :y] [:idly addr] [_ [[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))]])] [[:lda (bit.bor (bit.lshift r 8) (bit.lshift g 4) b)] [:sta (tostring (+ addr (* icolor 2) -2))]])]
(lume.concat [:block] (table.unpack writes))))]) (lume.concat [:block] (table.unpack writes))))])
(fn draw-tile (tile (long addr)) (fn draw-tile (tile addr)
(asm (asm
(lda addr) (sta [ssc.ADDR_LO]) (lda 16) (sta [ssc.LONG_LO]) (clc)
(lda addr 2) (sta [ssc.ADDR_HI]) (lda tile) (tax) (lda addr) (tay)
(ldy 0) (ldx 16) (clc) (bra draw)
loop loop
(lda (tile) :y) (sta (([ssc.ADDR_LO])) :y) (iny) (iny) (tya) (adc 152) (tay)
(lda (tile) :y) (sta (([ssc.ADDR_LO])) :y) (iny) (iny) draw
(lda (tile) :y) (sta (([ssc.ADDR_LO])) :y) (iny) (iny) (lda 7) (mvn 0 0xe1)
(lda (tile) :y) (sta (([ssc.ADDR_LO])) :y) (iny) (iny) (dec [ssc.LONG_LO]) (bne loop)))
(lda [ssc.ADDR_LO]) (adc 152) (sta [ssc.ADDR_LO])
(dex) (bne loop)))
(global word userID) (global word userID)
@ -68,7 +66,7 @@
(set! i (+ i 1))))) (set! i (+ i 1)))))
(fn draw-test-tiles () (fn draw-test-tiles ()
(let (x 0 y 0 screen screen-addr) (let (x 0 y 0 screen 0x2000)
(while (< y 12) (while (< y 12)
(draw-tile (ref tiles) screen) (draw-tile (ref tiles) screen)
(set! x (+ x 1)) (set! x (+ x 1))
@ -87,9 +85,11 @@
(EMStartUp 0x2000 0 0 320 0 200 userID) (EMStartUp 0x2000 0 0 320 0 200 userID)
(GrafOn) (GrafOn)
(ClearScreen 0)
(set-palette 0 [pal]) (set-palette 0 [pal])
(SetAllSCBs 0) (SetAllSCBs 0)
(wait-for-key)
(draw-test-tiles) (draw-test-tiles)
(wait-for-key) (wait-for-key)

View file

@ -70,7 +70,7 @@
:word) :word)
c-setup (when opgen.setup (opgen.setup)) c-setup (when opgen.setup (opgen.setup))
c-hi (when opgen.hi [(opgen.hi :lda) [:pha]]) 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) _ (table.insert self.locals loc)
c-lo [(opgen.lo :lda) [:pha]]] c-lo [(opgen.lo :lda) [:pha]]]
(set loc.type etype) (set loc.type etype)
@ -343,7 +343,7 @@
(var stacklen 0) (var stacklen 0)
(for [i 1 (length self.locals)] (for [i 1 (length self.locals)]
(let [loc (. self.locals i) (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)) (set stacklen (+ stacklen size))
(when (or (= i name-or-index) (= loc.name name-or-index)) (when (or (= i name-or-index) (= loc.name name-or-index))
(set offset stacklen)))) (set offset stacklen))))