mirror of
https://github.com/open-goal/jak-project
synced 2026-06-29 11:41:11 -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>
161 lines
5.0 KiB
Common Lisp
161 lines
5.0 KiB
Common Lisp
;;-*-Lisp-*-
|
|
(in-package goal)
|
|
|
|
;; name: timer-h.gc
|
|
;; name in dgo: timer-h
|
|
;; dgos: GAME, ENGINE
|
|
|
|
|
|
;; There are two sources for timing:
|
|
;; - EE TIMER1, used for the frame profiler. There are 9765 counts of this per frame. It gets reset in drawable.
|
|
;; - The "stopwatch" system, used for reading the CPU clock cycle counter, at 300 MHz (32-bit)
|
|
|
|
;; The Emotion Engine has 4 hardware timers, timer1 is used as the
|
|
(defconstant TIMER0_BANK #x10000000) ;; has HOLD register!
|
|
(defconstant TIMER1_BANK #x10000800) ;; has HOLD register!
|
|
(defconstant TIMER2_BANK #x10001000) ;; does NOT have HOLD register!
|
|
(defconstant TIMER3_BANK #x10001800) ;; does NOT have HOLD register!
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
;; PC Port Timer
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
(defmacro get-cpu-clock ()
|
|
"Read the 300 MHz clock."
|
|
;; __read-ee-timer is a 300 MHz timer from the C Kernel.
|
|
;; it's a real timer.
|
|
`(the uint (logand #xffffffff (__read-ee-timer)))
|
|
)
|
|
|
|
(defmacro get-bus-clock/256 ()
|
|
"Read the 150 MHz / 256 clock."
|
|
;; 300 MHz / (2^9)
|
|
`(the uint (logand #xffffffff (shr (__read-ee-timer) 9)))
|
|
)
|
|
|
|
(#when PC_PORT
|
|
;; the bus clock can be reset, which just stores the current count here.
|
|
(define *timer-reset-value* (the uint 0))
|
|
)
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
;; Timer HW
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
(defenum timer-clock-selection
|
|
:type uint8
|
|
(busclk 0)
|
|
(busclk/16 1)
|
|
(busclk/256 2)
|
|
(hblank 3)
|
|
)
|
|
|
|
;; DECOMP BEGINS
|
|
|
|
;; 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
|
|
(deftype timer-mode (uint32)
|
|
((clks timer-clock-selection :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)
|
|
)
|
|
)
|
|
|
|
;; 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 0)
|
|
(mode timer-mode :offset 16)
|
|
(comp uint32 :offset 32)
|
|
)
|
|
)
|
|
|
|
;; this matches an EE timer (with a HOLD register, timers 0 and 1)
|
|
(deftype timer-hold-bank (timer-bank)
|
|
((hold uint32 :offset 48)
|
|
)
|
|
)
|
|
|
|
;; stopwatches are used to measure CPU clock cycles
|
|
;; they don't use the timer above, but instead the Count COP0 register
|
|
;; which counts CPU clock cycles directly
|
|
(deftype stopwatch (basic)
|
|
((prev-time-elapsed time-frame)
|
|
(start-time time-frame)
|
|
(begin-level int32)
|
|
)
|
|
)
|
|
|
|
;; Confusing! What IS this measuring exactly? Hmm...
|
|
;; this is set by default for NTSC, it will later be changed if PAL.
|
|
(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)
|
|
)
|
|
|
|
;; needs PS2 TIMER porting
|
|
(#unless PC_PORT
|
|
(timer-init (the-as timer-bank TIMER1_BANK) (new 'static 'timer-mode :clks (timer-clock-selection busclk/16) :cue 1))
|
|
)
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
;; Profiler
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; The profiler uses the EE Timer 1 to record how long is spent in each part of the frame.
|
|
;; There is a EE and VU1 profiler. The EE profiler relies on code manually reporting how long
|
|
;; it takes to run, and the VU1 profiler uses VIF interrupts to do this automatically on
|
|
;; microprogram completion.
|
|
|
|
;; A single thing in the profiler
|
|
(deftype profile-frame (structure)
|
|
((name symbol)
|
|
(time-stamp uint32)
|
|
(color rgba)
|
|
)
|
|
)
|
|
|
|
|
|
;; A "bar" to display all the timed events
|
|
(declare-type dma-buffer basic)
|
|
(deftype profile-bar (basic)
|
|
((profile-frame-count int32)
|
|
(cache-time time-frame)
|
|
(data profile-frame 1024 :inline)
|
|
)
|
|
(:methods
|
|
(new (symbol type) _type_)
|
|
(get-last-frame-time-stamp (_type_) uint)
|
|
(reset (_type_) _type_)
|
|
(add-frame (_type_ symbol rgba) profile-frame)
|
|
(add-end-frame (_type_ symbol rgba) profile-frame)
|
|
(draw (_type_ dma-buffer int) float)
|
|
)
|
|
)
|
|
|
|
(defmacro add-ee-profile-frame (name &key (r 0) &key (g 0) &key (b 0) &key (a #x80))
|
|
`(if *debug-segment*
|
|
(add-frame
|
|
(-> *display* frames (-> *display* on-screen) frame profile-bar 0)
|
|
,name
|
|
(new 'static 'rgba :r ,r :g ,g :b ,b :a ,a)
|
|
)
|
|
)
|
|
)
|
|
|
|
;; tentative name
|
|
(defmethod get-last-frame-time-stamp profile-bar ((this profile-bar))
|
|
"Returns the timestamp of the last (non-remaining) frame on the profiler bar."
|
|
(-> this data (+ (-> this profile-frame-count) -2) time-stamp)
|
|
)
|