jak-project/goal_src/engine/ps2/memcard-h.gc
water111 ec412c7777
[decomp] ramdisk, load-dgo and rpc-h (#496)
* decompile ramdisk load-dgo and rpc-h

* add a bunch of offline tests

* clang-format
2021-05-16 21:07:22 -04:00

101 lines
3.1 KiB
Common Lisp

;;-*-Lisp-*-
(in-package goal)
;; name: memcard-h.gc
;; name in dgo: memcard-h
;; dgos: GAME, ENGINE
(deftype mc-handle (int32)
()
:flag-assert #x900000004
)
(deftype mc-file-info (structure)
((present int32 :offset-assert 0)
(blind-data float 16 :offset-assert 4)
(blind-data-int8 int8 64 :offset 4)
(level-index int32 :offset 4)
(fuel-cell-count float :offset 8)
(money-count float :offset 12)
(buzzer-count float :offset 16)
(completion-percentage float :offset 20)
(minute uint8 :offset 24)
(hour uint8 :offset 25)
(week uint8 :offset 26)
(day uint8 :offset 27)
(month uint8 :offset 28)
(year uint8 :offset 29)
)
:pack-me
:method-count-assert 9
:size-assert #x44
:flag-assert #x900000044
)
(deftype mc-slot-info (structure)
((handle int32 :offset-assert 0)
(known int32 :offset-assert 4)
(formatted int32 :offset-assert 8)
(inited int32 :offset-assert 12)
(last-file int32 :offset-assert 16)
(mem-required int32 :offset-assert 20)
(mem-actual int32 :offset-assert 24)
(file mc-file-info 4 :inline :offset-assert 28)
)
:pack-me
:method-count-assert 9
:size-assert #x12c
:flag-assert #x90000012c
)
(defun mc-sync ()
"Block here, waiting for the memory card to finish being read/written.
Note - this will freeze the entire game, so this should not be used
outside of debugging."
(local-vars (v0-0 int))
(set! v0-0 0)
(while (zero? v0-0)
;; run the memory card state machine (in C Kenrel)
(mc-run)
;; see if we got a good response
(set! v0-0 (mc-check-result))
)
v0-0
)
(defun show-mc-info ((dma-buf dma-buffer))
"Print mc info to the screen."
(let ((info (new 'stack-no-clear 'mc-slot-info)))
(dotimes (slot-idx 2)
(mc-get-slot-info slot-idx)
(cond
((zero? (-> info known))
(format (clear *temp-string*) "SLOT ~D: EXAMINING SLOT~%" slot-idx)
)
((zero? (-> info handle))
(format (clear *temp-string*) "SLOT ~D: NO CARD~%" slot-idx)
)
((zero? (-> info formatted))
(format (clear *temp-string*) "SLOT ~D: CARD [~D] : NOT FORMATTED~%" slot-idx (-> info handle))
)
((zero? (-> info inited))
(format (clear *temp-string*) "SLOT ~D: CARD [~D] : NO FILE [~D/~D]~%"
slot-idx (-> info handle) (-> info mem-required) (-> info mem-actual))
)
(else
(format (clear *temp-string*) "SLOT ~D: CARD [~D] : " slot-idx (-> info handle))
(format *temp-string* "SAVES ~D ~D ~D ~D : LAST ~D~%"
(-> info file 0 present)
(-> info file 1 present)
(-> info file 2 present)
(-> info file 3 present)
(-> info last-file)
)
)
)
(draw-string-xy *temp-string* dma-buf 32 (+ (* 12 slot-idx) 8) 3 1)
)
)
(none)
)