mirror of
https://github.com/open-goal/jak-project
synced 2026-09-13 05:05:48 -04:00
138 lines
3.8 KiB
Common Lisp
138 lines
3.8 KiB
Common Lisp
;;-*-Lisp-*-
|
|
(in-package goal)
|
|
|
|
;; name: dma-buffer.gc
|
|
;; name in dgo: dma-buffer
|
|
;; dgos: ENGINE, GAME
|
|
|
|
(deftype dma-packet (structure)
|
|
((dma dma-tag :offset-assert 0)
|
|
(vif0 vif-tag :offset-assert 8)
|
|
(vif1 vif-tag :offset-assert 12)
|
|
(quad uint128 :offset 0)
|
|
)
|
|
:method-count-assert 9
|
|
:size-assert #x10
|
|
:flag-assert #x900000010
|
|
)
|
|
|
|
(deftype dma-packet-array (inline-array-class)
|
|
((data dma-packet :inline :dynamic :offset-assert 16)
|
|
)
|
|
:method-count-assert 9
|
|
:size-assert #x10
|
|
:flag-assert #x900000010
|
|
)
|
|
(set! (-> dma-packet-array heap-base) (the-as uint 16))
|
|
|
|
(deftype dma-gif (structure)
|
|
((gif uint64 2 :offset-assert 0)
|
|
(quad uint128 :offset 0)
|
|
)
|
|
:method-count-assert 9
|
|
:size-assert #x10
|
|
:flag-assert #x900000010
|
|
)
|
|
|
|
(deftype dma-gif-packet (structure)
|
|
((dma-vif dma-packet :inline :offset-assert 0)
|
|
(gif uint64 2 :offset-assert 16)
|
|
(quad uint128 2 :offset 0)
|
|
)
|
|
:method-count-assert 9
|
|
:size-assert #x20
|
|
:flag-assert #x900000020
|
|
)
|
|
|
|
(deftype dma-buffer (basic)
|
|
((allocated-length int32 :offset-assert 4)
|
|
(base pointer :offset-assert 8)
|
|
(end pointer :offset-assert 12)
|
|
(data uint64 1 :offset-assert 16)
|
|
)
|
|
:method-count-assert 9
|
|
:size-assert #x18
|
|
:flag-assert #x900000018
|
|
(:methods
|
|
(new (symbol type int) _type_ 0)
|
|
)
|
|
)
|
|
|
|
(defmethod new dma-buffer ((allocation symbol) (type-to-make type) (arg0 int))
|
|
(let ((v0-0 (object-new allocation type-to-make (+ arg0 -4 (-> type-to-make size)))))
|
|
(set! (-> v0-0 base) (-> v0-0 data))
|
|
(set! (-> v0-0 allocated-length) arg0)
|
|
v0-0
|
|
)
|
|
)
|
|
|
|
(defun dma-buffer-inplace-new ((arg0 dma-buffer) (arg1 int))
|
|
(set! (-> arg0 base) (-> arg0 data))
|
|
(set! (-> arg0 allocated-length) arg1)
|
|
arg0
|
|
)
|
|
|
|
(defmethod length dma-buffer ((obj dma-buffer))
|
|
(-> obj allocated-length)
|
|
)
|
|
|
|
(defmethod asize-of dma-buffer ((obj dma-buffer))
|
|
(+ (-> obj allocated-length) -4 (-> dma-buffer size))
|
|
)
|
|
|
|
(defun dma-buffer-length ((arg0 dma-buffer))
|
|
(the-as int (shr (+ (&- (-> arg0 base) (the-as uint (-> arg0 data))) 15) 4))
|
|
)
|
|
|
|
(defun dma-buffer-free ((arg0 dma-buffer))
|
|
(the-as int (shr (+ (&- (-> arg0 end) (the-as uint (-> arg0 base))) 15) 4))
|
|
)
|
|
|
|
(defun dma-buffer-add-vu-function ((arg0 dma-buffer) (arg1 vu-function) (arg2 int))
|
|
(let ((v1-0 (&-> arg1 data 4))
|
|
(a3-0 (-> arg1 qlength))
|
|
(a1-1 (-> arg1 origin))
|
|
)
|
|
(while (> a3-0 0)
|
|
(let ((t0-1 (min 127 a3-0)))
|
|
(let* ((t1-1 arg0)
|
|
(t2-0 (the-as object (-> t1-1 base)))
|
|
)
|
|
(set! (-> (the-as dma-packet t2-0) dma)
|
|
(new 'static 'dma-tag :id (dma-tag-id ref) :addr (the-as int v1-0) :qwc t0-1)
|
|
)
|
|
(set! (-> (the-as dma-packet t2-0) vif0) (new 'static 'vif-tag :cmd (if (zero? arg2) 16 19)))
|
|
(set! (-> (the-as dma-packet t2-0) vif1) (new 'static 'vif-tag :cmd (vif-cmd mpg) :num (* t0-1 2) :imm a1-1))
|
|
(set! (-> t1-1 base) (&+ (the-as pointer t2-0) 16))
|
|
)
|
|
(&+! v1-0 (* t0-1 16))
|
|
(set! a3-0 (- a3-0 t0-1))
|
|
(+! a1-1 (* t0-1 2))
|
|
)
|
|
)
|
|
)
|
|
#f
|
|
)
|
|
|
|
(defun dma-buffer-send ((arg0 dma-bank) (arg1 dma-buffer))
|
|
(when (< (-> arg1 allocated-length) (&- (-> arg1 base) (the-as uint (-> arg1 data))))
|
|
(crash!)
|
|
0
|
|
)
|
|
(dma-send arg0 (the-as uint (-> arg1 data)) (the-as uint (dma-buffer-length arg1)))
|
|
(none)
|
|
)
|
|
|
|
(defun dma-buffer-send-chain ((arg0 dma-bank-source) (arg1 dma-buffer))
|
|
(when (< (-> arg1 allocated-length) (&- (-> arg1 base) (the-as uint (-> arg1 data))))
|
|
(crash!)
|
|
0
|
|
)
|
|
(dma-send-chain arg0 (the-as uint (-> arg1 data)))
|
|
(none)
|
|
)
|
|
|
|
|
|
|
|
|