jak-project/goal_src/jak1/engine/gfx/generic/generic-merc.gc
Hat Kid fc43870d85
decompiler: obj -> this, set-time! and time-elapsed? macros (#3026)
This renames the method object in `defmethod`s to `this` and adds
detection for the `set-time!` and `time-elapsed?` macros.

Definitely my biggest PR yet...
2023-09-26 15:17:00 +01:00

205 lines
8.2 KiB
Common Lisp

;;-*-Lisp-*-
(in-package goal)
;; name: generic-merc.gc
;; name in dgo: generic-merc
;; dgos: GAME, ENGINE
;; DECOMP BEGINS
(define mercneric-vu0-block (new 'static 'vu-function :length #x0 :origin #x0 :qlength #x0))
(deftype invinitdata (structure)
((count uint8 :offset-assert 0)
(init-data uint8 :offset-assert 1)
(init-addr uint16 :offset-assert 2)
)
:pack-me
:method-count-assert 9
:size-assert #x4
:flag-assert #x900000004
)
(defmethod inspect invinitdata ((this invinitdata))
(format #t "[~8x] ~A~%" this 'invinitdata)
(format #t "~Tcount: ~D~%" (-> this count))
(format #t "~Tinit-data: ~D~%" (-> this init-data))
(format #t "~Tinit-addr: ~D~%" (-> this init-addr))
this
)
(define *inv-init-table* (new 'static 'inline-array invinitdata 8
(new 'static 'invinitdata :count #x48 :init-addr #x1)
(new 'static 'invinitdata :count #x43 :init-data #xc :init-addr #x11)
(new 'static 'invinitdata :count #x3d :init-data #x18 :init-addr #x21)
(new 'static 'invinitdata :count #x38 :init-data #x22 :init-addr #xe0)
(new 'static 'invinitdata :count #x38 :init-data #x24 :init-addr #xe1)
(new 'static 'invinitdata :count #x33 :init-data #x30 :init-addr #xf1)
(new 'static 'invinitdata :count #x2e :init-data #x3a :init-addr #x190)
(new 'static 'invinitdata :count #x2d :init-data #x3c :init-addr #x191)
)
)
(def-mips2c generic-merc-init-asm (function none))
;; (def-mips2c mercneric-matrix-asm function) ;; TODO mips2c
;; (def-mips2c mercneric-shader-asm function) ;; TODO mips2c
;; (def-mips2c mercneric-bittable-asm function) ;; TODO mips2c
(def-mips2c mercneric-convert function)
;; (def-mips2c high-speed-reject function) ;; TODO mips2c
(def-mips2c high-speed-reject (function none))
(def-mips2c generic-merc-execute-asm (function none)) ;; TODO mips2c
(defun generic-merc-add-to-cue ((arg0 generic-dma-foreground-sink))
(set! (-> *merc-globals* sink) arg0)
(+! (-> *merc-global-array* count) 1)
(set! *merc-globals* (-> *merc-global-array* globals (-> *merc-global-array* count)))
(none)
)
(defun generic-merc-execute-all ((arg0 dma-buffer))
"Run the EE part of the generic renderer for all generic merc stuff.
This will build DMA data in the format for generic."
(local-vars (a0-26 int) (a0-28 int))
;; (format 0 "[GMERC] starting generic-merc-execute-all with ~d to execute~%" (-> *merc-global-array* count))
(when (nonzero? (-> *merc-global-array* count))
(let ((gp-0 (-> *display* frames (-> *display* on-screen) frame global-buf base)))
;; set up performance stats
(if *debug-segment*
(add-frame
(-> *display* frames (-> *display* on-screen) frame profile-bar 0)
'draw
(new 'static 'rgba :r #x40 :b #x40 :a #x80)
)
)
(reset! (-> *perf-stats* data 1))
(set! (-> (scratchpad-object terrain-context) work foreground generic-work saves to-vu0-waits)
(the-as uint 0)
)
(set! (-> (scratchpad-object terrain-context) work foreground generic-work saves to-spr-waits)
(the-as uint 0)
)
(set! (-> (scratchpad-object terrain-context) work foreground generic-work saves from-spr-waits)
(the-as uint 0)
)
(flush-cache 0)
;; first, initialize the generic renderer.
(generic-initialize-without-sink (-> *math-camera* perspective) *default-lights*)
;; next, initialize the merc-specific stuff.
;; this give us function pointers to
;; - mercneric-convert
;; - generic-prepare-dma-single
;; - generic-prepare-dma-double
;; - generic-light-proc
;; - generic-envmap-proc
;; - high-speed-reject
;; and also loads the mercneric-vu0-block block with an offset of 280.
(generic-merc-init-asm)
;; set a limit, so we don't write off the end of the dma buffer.
(set! (-> (scratchpad-object terrain-context) work foreground generic-work in-buf merc shadow write-limit)
(&+ (-> arg0 end) -65536)
)
(dotimes (s4-0 (the-as int (-> *merc-global-array* count)))
(set! *merc-globals* (-> *merc-global-array* globals s4-0))
(let ((s3-0 (-> *merc-globals* sink)))
(when (nonzero? (-> *merc-globals* first))
(let* ((s1-0 (-> *display* frames (-> *display* on-screen) frame global-buf))
(s2-0 (-> s1-0 base))
)
;; (format 0 "[GMERC] running ~D~%" s4-0)
(generic-work-init s3-0)
(set! (-> (scratchpad-object terrain-context) work foreground generic-work saves basep)
(the-as uint (-> s1-0 base))
)
(generic-merc-execute-asm)
(set! (-> s1-0 base)
(the-as pointer (-> (scratchpad-object terrain-context) work foreground generic-work saves basep))
)
;; todo: this part might be important...
; (let ((v1-36 (the-as object #x1000d000))
; (a0-19 (the-as object #x7000006c))
; )
; (b! (zero? (logand (-> (the-as terrain-context v1-36) bsp lev-index) 256)) cfg-9 :delay (nop!))
; (let ((a1-6 (-> (the-as generic-envmap-saves a0-19) index-mask x)))
; (nop!)
; (let ((a2-1 (-> (the-as (pointer int32) v1-36) 0)))
; (nop!)
; (let ((a2-2 (logand a2-1 256))
; (a1-7 (+ a1-6 1))
; )
; (b! (nonzero? a2-2) cfg-8 :delay (s.w! (the-as int a0-19) a1-7))
; )
; )
; )
; )
; (label cfg-9)
; 0
(let ((a3-0 (-> s1-0 base)))
(let ((v1-38 (the-as object (-> s1-0 base))))
(set! (-> (the-as dma-packet v1-38) dma) (new 'static 'dma-tag :id (dma-tag-id next)))
(set! (-> (the-as dma-packet v1-38) vif0) (new 'static 'vif-tag))
(set! (-> (the-as dma-packet v1-38) vif1) (new 'static 'vif-tag))
(set! (-> s1-0 base) (&+ (the-as pointer v1-38) 16))
)
(dma-bucket-insert-tag
(-> *display* frames (-> *display* on-screen) frame bucket-group)
(-> s3-0 bucket)
s2-0
(the-as (pointer dma-tag) a3-0)
)
)
)
; (let ((v1-44 (-> arg0 base)))
; (.sync.l)
; (.cache dxwbin v1-44 0)
; (.sync.l)
; (.cache dxwbin v1-44 1)
; )
; (.sync.l)
0
)
)
)
(read! (-> *perf-stats* data 1))
0
(update-wait-stats
(-> *perf-stats* data 1)
(-> (scratchpad-object terrain-context) work foreground generic-work saves to-vu0-waits)
(-> (scratchpad-object terrain-context) work foreground generic-work saves to-spr-waits)
(-> (scratchpad-object terrain-context) work foreground generic-work saves from-spr-waits)
)
(if *debug-segment*
(add-frame
(-> *display* frames (-> *display* on-screen) frame profile-bar 0)
'draw
(new 'static 'rgba :r #xff :g #xff :b #xff :a #x80)
)
)
(let ((v1-64 *dma-mem-usage*))
(when (nonzero? v1-64)
(set! (-> v1-64 length) (max 87 (-> v1-64 length)))
(set! (-> v1-64 data 86 name) "pris-generic")
(+! (-> v1-64 data 86 count) 1)
(+! (-> v1-64 data 86 used)
(&- (-> *display* frames (-> *display* on-screen) frame global-buf base) (the-as uint gp-0))
)
(set! (-> v1-64 data 86 total) (-> v1-64 data 86 used))
)
)
)
)
;; (format 0 "[GMERC] made it to the end of generic-merc-execute-all.~%")
(none)
)