mirror of
https://github.com/open-goal/jak-project.git
synced 2024-10-20 21:27:52 -04:00
cd68cb671e
Major change to how `deftype` shows up in our code: - the decompiler will no longer emit the `offset-assert`, `method-count-assert`, `size-assert` and `flag-assert` parameters. There are extremely few cases where having this in the decompiled code is helpful, as the types there come from `all-types` which already has those parameters. This also doesn't break type consistency because: - the asserts aren't compared. - the first step of the test uses `all-types`, which has the asserts, which will throw an error if they're bad. - the decompiler won't emit the `heap-base` parameter unless necessary now. - the decompiler will try its hardest to turn a fixed-offset field into an `overlay-at` field. It falls back to the old offset if all else fails. - `overlay-at` now supports field "dereferencing" to specify the offset that's within a field that's a structure, e.g.: ```lisp (deftype foobar (structure) ((vec vector :inline) (flags int32 :overlay-at (-> vec w)) ) ) ``` in this structure, the offset of `flags` will be 12 because that is the final offset of `vec`'s `w` field within this structure. - **removed ID from all method declarations.** IDs are only ever automatically assigned now. Fixes #3068. - added an `:overlay` parameter to method declarations, in order to declare a new method that goes on top of a previously-defined method. Syntax is `:overlay <method-name>`. Please do not ever use this. - added `state-methods` list parameter. This lets you quickly specify a list of states to be put in the method table. Same syntax as the `states` list parameter. The decompiler will try to put as many states in this as it can without messing with the method ID order. Also changes `defmethod` to make the first type definition (before the arguments) optional. The type can now be inferred from the first argument. Fixes #3093. --------- Co-authored-by: Hat Kid <6624576+Hat-Kid@users.noreply.github.com>
190 lines
5.1 KiB
Common Lisp
190 lines
5.1 KiB
Common Lisp
;;-*-Lisp-*-
|
|
(in-package goal)
|
|
|
|
;; name: rpc-h.gc
|
|
;; name in dgo: rpc-h
|
|
;; dgos: ENGINE, GAME
|
|
|
|
;; DECOMP BEGINS
|
|
|
|
(deftype rpc-buffer (basic)
|
|
((elt-size uint32)
|
|
(elt-count uint32)
|
|
(elt-used uint32)
|
|
(busy basic)
|
|
(base pointer)
|
|
(data uint8 :dynamic :offset 32)
|
|
)
|
|
(:methods
|
|
(new (symbol type uint uint) rpc-buffer)
|
|
)
|
|
)
|
|
|
|
|
|
(defmethod new rpc-buffer ((allocation symbol) (type-to-make type) (arg0 uint) (arg1 uint))
|
|
(let* ((a2-2 (+ (-> type-to-make size) 63 (* (the-as int arg0) (the-as int arg1))))
|
|
(v0-0 (object-new allocation type-to-make (the-as int a2-2)))
|
|
)
|
|
(set! (-> v0-0 elt-size) arg0)
|
|
(set! (-> v0-0 elt-count) arg1)
|
|
(set! (-> v0-0 elt-used) (the-as uint 0))
|
|
(set! (-> v0-0 busy) #f)
|
|
(set! (-> v0-0 base) (logand -64 (&-> (-> v0-0 data) 63)))
|
|
v0-0
|
|
)
|
|
)
|
|
|
|
(deftype rpc-buffer-pair (basic)
|
|
((buffer rpc-buffer 2)
|
|
(current rpc-buffer)
|
|
(last-recv-buffer pointer)
|
|
(rpc-port int32)
|
|
)
|
|
(:methods
|
|
(new (symbol type uint uint int) rpc-buffer-pair)
|
|
(call (rpc-buffer-pair uint pointer uint) int)
|
|
(add-element (rpc-buffer-pair) pointer)
|
|
(decrement-elt-used (rpc-buffer-pair) int)
|
|
(sync (rpc-buffer-pair symbol) int)
|
|
(check-busy (rpc-buffer-pair) symbol)
|
|
(pop-last-received (rpc-buffer-pair) pointer)
|
|
)
|
|
)
|
|
|
|
|
|
(defmethod new rpc-buffer-pair ((allocation symbol) (type-to-make type) (arg0 uint) (arg1 uint) (arg2 int))
|
|
(let ((s3-0 (object-new allocation type-to-make (the-as int (-> type-to-make size)))))
|
|
(set! (-> s3-0 buffer 0) (new 'global 'rpc-buffer arg0 arg1))
|
|
(set! (-> s3-0 buffer 1) (new 'global 'rpc-buffer arg0 arg1))
|
|
(set! (-> s3-0 current) (-> s3-0 buffer 0))
|
|
(set! (-> s3-0 last-recv-buffer) (the-as pointer #f))
|
|
(set! (-> s3-0 rpc-port) arg2)
|
|
s3-0
|
|
)
|
|
)
|
|
|
|
(defmethod sync ((this rpc-buffer-pair) (arg0 symbol))
|
|
(let ((s5-0 (if (= (-> this current) (-> this buffer 0))
|
|
(-> this buffer 1)
|
|
(-> this buffer 0)
|
|
)
|
|
)
|
|
)
|
|
(when (-> s5-0 busy)
|
|
(when (nonzero? (rpc-busy? (-> this rpc-port)))
|
|
(if arg0
|
|
(format 0 "STALL: waiting for IOP on RPC port #~D~%" (-> this rpc-port))
|
|
)
|
|
(while (nonzero? (rpc-busy? (-> this rpc-port)))
|
|
(nop!)
|
|
(nop!)
|
|
(nop!)
|
|
(nop!)
|
|
(nop!)
|
|
(nop!)
|
|
(nop!)
|
|
(nop!)
|
|
)
|
|
)
|
|
(set! (-> s5-0 busy) #f)
|
|
(set! (-> s5-0 elt-used) (the-as uint 0))
|
|
0
|
|
)
|
|
)
|
|
0
|
|
)
|
|
|
|
(defmethod check-busy ((this rpc-buffer-pair))
|
|
(let ((gp-0 (if (= (-> this current) (-> this buffer 0))
|
|
(-> this buffer 1)
|
|
(-> this buffer 0)
|
|
)
|
|
)
|
|
)
|
|
(when (-> gp-0 busy)
|
|
(if (nonzero? (rpc-busy? (-> this rpc-port)))
|
|
(return #t)
|
|
)
|
|
(set! (-> gp-0 busy) #f)
|
|
(set! (-> gp-0 elt-used) (the-as uint 0))
|
|
0
|
|
)
|
|
)
|
|
#f
|
|
)
|
|
|
|
(defmethod call ((this rpc-buffer-pair) (arg0 uint) (arg1 pointer) (arg2 uint))
|
|
(when (nonzero? (-> this current elt-used))
|
|
(let ((s2-0 (if (= (-> this current) (-> this buffer 0))
|
|
(-> this buffer 1)
|
|
(-> this buffer 0)
|
|
)
|
|
)
|
|
)
|
|
(when (-> s2-0 busy)
|
|
(when (nonzero? (rpc-busy? (-> this rpc-port)))
|
|
(format 0 "STALL: waiting for IOP on RPC port #~D~%" (-> this rpc-port))
|
|
(while (nonzero? (rpc-busy? (-> this rpc-port)))
|
|
(nop!)
|
|
(nop!)
|
|
(nop!)
|
|
(nop!)
|
|
(nop!)
|
|
(nop!)
|
|
(nop!)
|
|
(nop!)
|
|
)
|
|
)
|
|
(set! (-> s2-0 busy) #f)
|
|
(set! (-> s2-0 elt-used) (the-as uint 0))
|
|
0
|
|
)
|
|
(let ((s1-0 (-> this current)))
|
|
(rpc-call
|
|
(-> this rpc-port)
|
|
arg0
|
|
(the-as uint 1)
|
|
(the-as uint (-> s1-0 base))
|
|
(the-as int (* (-> s1-0 elt-size) (-> s1-0 elt-used)))
|
|
(the-as uint arg1)
|
|
(the-as int arg2)
|
|
)
|
|
(set! (-> s1-0 busy) (the-as basic #t))
|
|
)
|
|
(set! (-> this last-recv-buffer) arg1)
|
|
(set! (-> this current) s2-0)
|
|
)
|
|
)
|
|
0
|
|
)
|
|
|
|
(defmethod pop-last-received ((this rpc-buffer-pair))
|
|
(let ((v0-0 (-> this last-recv-buffer)))
|
|
(set! (-> this last-recv-buffer) (the-as pointer #f))
|
|
v0-0
|
|
)
|
|
)
|
|
|
|
(defmethod add-element ((this rpc-buffer-pair))
|
|
(let ((v1-0 (-> this current)))
|
|
(when (= (-> v1-0 elt-used) (-> v1-0 elt-count))
|
|
(if (zero? (-> this rpc-port))
|
|
(format 0 "WARNING: too many sound commands queued~%")
|
|
)
|
|
(call this (the-as uint 0) (the-as pointer 0) (the-as uint 0))
|
|
(set! v1-0 (-> this current))
|
|
)
|
|
(let ((v0-2 (&+ (-> v1-0 base) (* (-> v1-0 elt-used) (-> v1-0 elt-size)))))
|
|
(+! (-> v1-0 elt-used) 1)
|
|
v0-2
|
|
)
|
|
)
|
|
)
|
|
|
|
(defmethod decrement-elt-used ((this rpc-buffer-pair))
|
|
(if (> (-> this current elt-used) 0)
|
|
(+! (-> this current elt-used) -1)
|
|
)
|
|
0
|
|
)
|