mirror of
https://github.com/open-goal/jak-project
synced 2026-06-20 08:13:33 -04:00
fa061ef7eb
* [timer decomp] preliminary decomp * [goal-lib] add inplace macros for logior, logxor, lognor and logand * [timer decomp] Finish decomp for now * [timer decomp] OCD whitespace * [all-types] fix type consistency Sorry mr. decompiler but you will have to take the hit * [timer decomp] Fix more type consistency * [timer decomp] ACTUALLY fix it + script so I don't forget * [timer] automatically choose gpr for rlet's
129 lines
4.0 KiB
Common Lisp
129 lines
4.0 KiB
Common Lisp
;;-*-Lisp-*-
|
|
(in-package goal)
|
|
|
|
;; name: timer-h.gc
|
|
;; name in dgo: timer-h
|
|
;; dgos: GAME, ENGINE
|
|
|
|
|
|
;; The Emotion Engine has 4 hardware timers.
|
|
(defconstant EE_TIMER0 #x10000000) ;; has HOLD register!
|
|
(defconstant EE_TIMER1 #x10000800) ;; has HOLD register!
|
|
(defconstant EE_TIMER2 #x10001000) ;; does NOT have HOLD register!
|
|
(defconstant EE_TIMER3 #x10001800) ;; does NOT have HOLD register!
|
|
|
|
;; this matches the Tn_MODE register structure of the ps2 EE timers.
|
|
;; Only the lower 32 bits of these registers are usable, and the upper 16 hardwired to zero
|
|
;; TODO : define constants for these bitfields?
|
|
(deftype timer-mode (uint32)
|
|
(;(data uint32 :offset 0 :size 32)
|
|
(clks uint8 :offset 0 :size 2)
|
|
(gate uint8 :offset 2 :size 1)
|
|
(gats uint8 :offset 3 :size 1)
|
|
(gatm uint8 :offset 4 :size 2)
|
|
(zret uint8 :offset 6 :size 1)
|
|
(cue uint8 :offset 7 :size 1)
|
|
(cmpe uint8 :offset 8 :size 1)
|
|
(ovfe uint8 :offset 9 :size 1)
|
|
(equf uint8 :offset 10 :size 1)
|
|
(ovff uint8 :offset 11 :size 1)
|
|
)
|
|
:method-count-assert 9
|
|
:size-assert #x4
|
|
:flag-assert #x900000004
|
|
)
|
|
|
|
;; this matches an EE timer (without a HOLD register, timers 2 and 3)
|
|
;; Each register is 128-bits wide, but only the lower 32-bits are usable, and the upper
|
|
;; 16-bits of that are hardwired to zero.
|
|
(deftype timer-bank (structure)
|
|
((count uint32 :offset-assert 0)
|
|
(mode timer-mode :offset 16)
|
|
(comp uint32 :offset 32)
|
|
)
|
|
:method-count-assert 9
|
|
:size-assert #x24
|
|
:flag-assert #x900000024
|
|
)
|
|
|
|
;; this matches an EE timer (with a HOLD register, timers 0 and 1)
|
|
(deftype timer-hold-bank (timer-bank)
|
|
((hold uint32 :offset 48)
|
|
)
|
|
:method-count-assert 9
|
|
:size-assert #x34
|
|
:flag-assert #x900000034
|
|
)
|
|
|
|
;; stopwatches are used to measure CPU clock cycles
|
|
(deftype stopwatch (basic)
|
|
((prev-time-elapsed uint64 :offset-assert 8)
|
|
(start-time uint64 :offset-assert 16)
|
|
(begin-level int32 :offset-assert 24)
|
|
)
|
|
:method-count-assert 9
|
|
:size-assert #x1c
|
|
:flag-assert #x90000001c
|
|
)
|
|
|
|
;; Confusing! What IS this measuring exactly? Hmm...
|
|
(define *ticks-per-frame* (/ 2500000 256)) ;; 2 500 000 / 256 = 9765
|
|
|
|
(defun timer-init ((timer timer-bank) (mode timer-mode))
|
|
"Initiate a timer, start counting at a rate of 1 every 256 bus clocks (BUSCLK: ~147.456MHz)."
|
|
(set! (-> timer mode) mode)
|
|
(set! (-> timer count) 0)
|
|
)
|
|
|
|
;; segfaults OpenGOAL as it does not support ps2 EE timers
|
|
; (timer-init (the-as timer-bank EE_TIMER1) (the-as timer-mode #x82))
|
|
|
|
|
|
(deftype profile-frame (structure)
|
|
((name basic :offset-assert 0)
|
|
(time-stamp uint32 :offset-assert 4)
|
|
(color uint32 :offset-assert 8)
|
|
(r uint8 :offset 8) ;; TODO : verify colors
|
|
(g uint8 :offset 9) ;; TODO (again) : these are actually bitfields
|
|
(b uint8 :offset 10)
|
|
)
|
|
:method-count-assert 9
|
|
:size-assert #xc
|
|
:flag-assert #x90000000c
|
|
)
|
|
|
|
(defmethod inspect profile-frame ((obj profile-frame))
|
|
(let ((this-frame obj))
|
|
(format #t "[~8x] profile-frame~%" this-frame)
|
|
(format #t "~Tname: ~A~%" (-> this-frame name))
|
|
(format #t "~Ttime-stamp: ~D~%" (-> this-frame time-stamp))
|
|
(format #t "~Tcolor: ~D ~D ~D~%" (-> this-frame r) (-> this-frame g) (-> this-frame b))
|
|
)
|
|
obj
|
|
)
|
|
|
|
|
|
(deftype profile-bar (basic)
|
|
((profile-frame-count int32 :offset-assert 4)
|
|
(cache-time uint64 :offset-assert 8)
|
|
(data profile-frame 1024 :inline :offset-assert 16)
|
|
)
|
|
:method-count-assert 14
|
|
:size-assert #x4010
|
|
:flag-assert #xe00004010
|
|
(:methods
|
|
(get-last-frame-time-stamp (profile-bar) uint 9)
|
|
(dummy-10 () none 10)
|
|
(dummy-11 () none 11)
|
|
(dummy-12 () none 12)
|
|
(dummy-13 () none 13)
|
|
)
|
|
)
|
|
|
|
;; tentative name
|
|
(defmethod get-last-frame-time-stamp profile-bar ((obj profile-bar))
|
|
"Returns the timestamp of the last (non-remaining) frame on the profiler bar."
|
|
(-> obj data (+ (-> obj profile-frame-count) -2) time-stamp)
|
|
)
|
|
|