jak-project/goal_src/jak2/levels/intro/vortex.gc
ManDude 6884b0f73e
start blit-displays decomp & renderer + improve decompilation of some DMA macros (#2616)
Adds sprite distort, fixes buggy sprite rendering in progress, adds
scissoring support (used in various scrolling menus) and a very basic
implementation of `blit-displays`. This is enough to make the fade
effect in the progress menu work, along with all the menus working
properly without needing to use the REPL. This does not make screen
flipping and the filter when failing a mission work.

Added support in the decompiler for detecting `dma-buffer-add-gs-set`
and `dma-buffer-add-gs-set-flusha` and updated all of the Jak 2 code to
use it. Readability improved!

Fixes decompiler issue with `with-dma-buffer-add-bucket` not inlining
forms which broke syntax. Fixes store error warnings showing up for
non-existent stores, there is now a dedicated pass for this at the end.

I started work on making `BITBLTBUF` stuff work in the DirectRenderer,
but stopped for now because it wasn't strictly necessary. It will still
assert like before.
2023-05-04 18:34:09 -04:00

129 lines
5.5 KiB
Common Lisp

;;-*-Lisp-*-
(in-package goal)
;; name: vortex.gc
;; name in dgo: vortex
;; dgos: INTROCST
;; DECOMP BEGINS
;; ERROR: function has no type analysis. Cannot decompile.
(def-mips2c init-vortex-regs (function none))
(def-mips2c draw-large-polygon-vortex function)
(def-mips2c render-vortex-quad (function vortex-vertex dma-buffer vector none))
(defun update-vortex-data ((arg0 float))
(when (not (paused?))
(+! (-> *vortex-work* off-s-0) (the int (* 4.0 arg0)))
(+! (-> *vortex-work* off-t-0) (the int (* -8.0 arg0)))
(+! (-> *vortex-work* off-s-1) (the int (* 4.0 arg0)))
(+! (-> *vortex-work* off-t-1) (the int (* -8.0 arg0)))
)
0
(none)
)
;; ERROR: Failed store: (s.w! (+ v1-76 8) 0) at op 268
(defun draw-vortex ()
(rlet ((vf27 :class vf))
(when (and (logtest? (-> *display* vu1-enable-user) (vu1-renderer-mask sky))
(logtest? (-> *texture-pool* texture-enable-user) (texture-enable-mask sky))
)
(let ((gp-0 (-> *display* frames (-> *display* on-screen) global-buf base)))
(update-vortex-data 60.0)
(with-dma-buffer-add-bucket ((s4-0 (-> *display* frames (-> *display* on-screen) global-buf))
(bucket-id sky-draw)
)
(dma-buffer-add-gs-set s4-0
(zbuf-1 (new 'static 'gs-zbuf :zbp #x130 :psm (gs-psm ct24)))
(test-1 (new 'static 'gs-test :ate #x1 :atst (gs-atest always) :zte #x1 :ztst (gs-ztest always)))
(rgbaq (new 'static 'gs-rgbaq :b #x40 :q 1.0))
)
(let ((v1-20 (-> s4-0 base)))
(set! (-> (the-as (pointer uint128) v1-20)) (-> *sky-work* sprite-tmpl dma-vif quad))
(set! (-> (the-as (pointer uint128) v1-20) 1) (-> *sky-work* sprite-tmpl quad 1))
)
(&+! (-> s4-0 base) 32)
(let ((v1-23 (-> s4-0 base)))
(set-vector! (the-as vector4w (&+ v1-23 0)) #x7000 #x7300 0 0)
(set-vector! (the-as vector4w (&+ v1-23 16)) #x9000 #x8d00 0 0)
)
(&+! (-> s4-0 base) 32)
(dma-buffer-add-gs-set s4-0
(tex0-1
(new 'static 'gs-tex0
:tbp0 #x100
:tbw #x2
:psm #x1b
:tcc #x1
:cbp #x300
:cld #x1
:th (log2 128)
:tw (log2 128)
)
)
(tex1-1 (new 'static 'gs-tex1 :mmag #x1 :mmin #x1))
(clamp-1 (new 'static 'gs-clamp))
(alpha-1 (new 'static 'gs-alpha :b #x1 :d #x1))
(texflush 0)
)
(init-vortex-regs)
;;(.lvf vf27 (&-> *vortex-work* giftag quad))
(set-sky-vf27 (&-> *vortex-work* giftag quad))
(set-tex-offset (the-as int (-> *vortex-work* off-s-0)) (the-as int (-> *vortex-work* off-t-0)))
(let ((s3-1 (the-as dma-packet (-> s4-0 base))))
(&+! (-> s4-0 base) 16)
(let ((s2-1 *vortex-poly*))
(dotimes (s1-2 304)
(render-vortex-quad (-> s2-1 (* s1-2 4)) s4-0 (new 'static 'vector :z 128.0 :w 128.0))
)
)
(close-sky-buffer s4-0)
(let ((v1-54 (/ (+ (- -16 (the-as int s3-1)) (the-as int (-> s4-0 base))) 16)))
(set! (-> s3-1 dma) (new 'static 'dma-tag :id (dma-tag-id cnt) :qwc v1-54))
(set! (-> s3-1 vif0) (new 'static 'vif-tag))
(set! (-> s3-1 vif1) (new 'static 'vif-tag :cmd (vif-cmd direct) :msk #x1 :imm v1-54))
)
)
(dma-buffer-add-gs-set s4-0
(alpha-1 (new 'static 'gs-alpha :b #x2 :d #x1))
(colclamp (new 'static 'gs-color-clamp :clamp #x1))
)
(set-tex-offset (the-as int (-> *vortex-work* off-s-1)) (the-as int (-> *vortex-work* off-t-1)))
(let ((s3-2 (the-as dma-packet (-> s4-0 base))))
(&+! (-> s4-0 base) 16)
(let ((s2-2 *vortex-poly*))
(dotimes (s1-3 304)
(render-vortex-quad (-> s2-2 (* s1-3 4)) s4-0 (new 'static 'vector :x 144.0 :y 128.0 :z 255.0 :w 128.0))
)
)
(close-sky-buffer s4-0)
(let ((v1-72 (/ (+ (- -16 (the-as int s3-2)) (the-as int (-> s4-0 base))) 16)))
(set! (-> s3-2 dma) (new 'static 'dma-tag :id (dma-tag-id cnt) :qwc v1-72))
(set! (-> s3-2 vif0) (new 'static 'vif-tag))
(set! (-> s3-2 vif1) (new 'static 'vif-tag :cmd (vif-cmd direct) :msk #x1 :imm v1-72))
)
)
)
(let ((v1-83 *dma-mem-usage*))
(when (nonzero? v1-83)
(set! (-> v1-83 length) (max 89 (-> v1-83 length)))
(set! (-> v1-83 data 88 name) "sky")
(+! (-> v1-83 data 88 count) 1)
(+! (-> v1-83 data 88 used)
(&- (-> *display* frames (-> *display* on-screen) global-buf base) (the-as uint gp-0))
)
(set! (-> v1-83 data 88 total) (-> v1-83 data 88 used))
)
)
)
)
0
(none)
)
)