honeylisp/neutgs/init.fnl
2021-12-11 13:51:31 -05:00

130 lines
3.7 KiB
Fennel

(local Ssc (require :ssc))
(local files (require :game.files))
(local {: pal} (require :editor.tiledraw.iigs))
(local u2-debug (require :ssc.iigs.u2-debug))
(local link (require :link))
(import-macros {:sss ! : compile} :ssc.macros)
(local ssc (Ssc {:parent u2-debug}))
(compile ssc
(require ssc.iigs.bootstub)
(require ssc.iigs.toolbox)
(require ssc.iigs.graphics)
(tooltable toolsets
ToolsetIntegerMath 0x0100
ToolsetText 0x0100
ToolsetQuickDraw 0x0100
ToolsetEventManager 0x0100
5 0x0100 ; desk manager
9 0x0100) ; ADB
(buffer hexbuf (cstr " "))
(fn printnum (num)
(long! (ref hexbuf) (HexIt num))
(WriteCString (far-ref hexbuf)))
(asm event-buffer)
(global word event-what)
(global long event-msg)
(global long event-when)
(global word event-y)
(global word event-x)
(global word event-mod)
(fn wait-for-key ()
(FlushEvents keyDownMask 0)
(while (not (GetNextEvent keyDownMask (far-ref event-buffer)))
(yield)))
(define screen-addr 0xe12000)
(define screen-size 0x9d00)
(compile-sprite tile0 [(. files.game.iso 3 :gfx)] 24 32)
(compile-sprite tile1 [(. files.game.iso 5 :gfx)] 24 32)
(compile-sprite tile2 [(. files.game.iso 11 :gfx)] 24 32)
(compile-sprite tile3 [(. files.game.iso 12 :gfx)] 24 32)
(asm tiles (jmp tile0) (nop) (jmp tile1) (nop) (jmp tile2) (nop) (jmp tile3) (nop))
(form set-palette [(fn [ssc index pal]
(let [addr (+ 0xe19e00 (* index 0x20))
writes (icollect [icolor [r g b] (ipairs pal)]
[[:lda (bit.bor (bit.lshift r 8) (bit.lshift g 4) b)] [:sta (tostring (+ addr (* icolor 2) -2))]])]
(lume.concat [:block] (table.unpack writes))))])
(global word userID)
(fn print-numbers-forever ()
(let (i 0) (while true
(printnum i)
(yield)
(set! i (+ i 1)))))
(form itile-to-tile [(fn [ssc itile]
[:block (ssc:expr-word itile) [:asl] [:asl] [:clc] [:adc #($1:lookup-addr :tiles)]])])
(global word with-shadowing 0)
(fn draw-test-tiles (i)
(when with-shadowing (disable-shadow-writes))
(let (x 0 y 0 screen 0x2000)
(while (< y 26)
(let (tile (itile-to-tile (& (+ x y i) 3)))
(draw-object screen tile))
(set! x (+ x 1))
(if (= x 12)
(do (set! y (+ y 1))
(set! x 0)
(set! screen (+ screen (if (& y 1) [(+ (- 160 (* 11 12)) (* 160 5) 6)]
[(+ (- 160 6 (* 11 12)) (* 160 5))]))))
(set! screen (+ screen 12))))))
(fn draw-test-tiles-forever ()
(let (i 0)
(forever
(draw-test-tiles i)
(yield)
(set! i (+ i 1)))))
(fn debug-task () (forever [(if (= link.name :udpdebug) [:u2-debug-server-poll] [:do])] (yield)))
(far-fn main ()
(new-task (ref debug-task))
(LoadTools (far-ref toolsets))
(set! userID (MMStartUp))
(IMStartUp)
(TextStartUp)
(QDStartUp 0x3100 0 0 userID)
(EMStartUp 0x3000 0 0 320 0 200 userID)
(GrafOn)
(ClearScreen 0)
(let (screen 0x12000) (while (< screen 0x1a000)
(word! screen 0)
(set! screen (+ screen 2))))
(set-palette 0 [pal])
(SetAllSCBs 0)
(enable-shadow-writes)
(draw-test-tiles 0)
(wait-for-key)
(let (tile-task (new-task (ref draw-test-tiles-forever)))
(wait-for-key)
; (set! with-shadowing 1)
; (wait-for-key)
; (set! with-shadowing 2)
; (wait-for-key)
; (set! with-shadowing false)
(reset-task tile-task (ref yield-forever))
(wait-for-key))
(GrafOff)
(EMShutDown)
(QDShutDown)
(TextShutDown)
(IMShutDown)
(MMShutDown userID)))
(ssc:assemble)