From 9fe45798e95d6d3122146f831c13c00e4db21e53 Mon Sep 17 00:00:00 2001 From: ManDude <7569514+ManDude@users.noreply.github.com> Date: Sat, 13 Aug 2022 15:40:32 +0100 Subject: [PATCH] move and cleanup pc debug code --- goal_src/jak1/engine/gfx/hw/display-h.gc | 9 +++ goal_src/jak1/examples/display-all-colors.gc | 61 ------------------- goal_src/jak1/pc/util/display-font-color.gc | 52 ++++++++++++++++ .../{pc_debug => pc/util}/font-encode-test.gc | 39 +++++------- .../{pc_debug => pc/util}/pc-pad-utils.gc | 14 ++--- 5 files changed, 81 insertions(+), 94 deletions(-) delete mode 100644 goal_src/jak1/examples/display-all-colors.gc create mode 100644 goal_src/jak1/pc/util/display-font-color.gc rename goal_src/jak1/{pc_debug => pc/util}/font-encode-test.gc (66%) rename goal_src/jak1/{pc_debug => pc/util}/pc-pad-utils.gc (95%) diff --git a/goal_src/jak1/engine/gfx/hw/display-h.gc b/goal_src/jak1/engine/gfx/hw/display-h.gc index deaff89224..680d02d2ba 100644 --- a/goal_src/jak1/engine/gfx/hw/display-h.gc +++ b/goal_src/jak1/engine/gfx/hw/display-h.gc @@ -246,3 +246,12 @@ (defmacro real-current-time () `(-> *display* real-frame-counter) ) + + +;; debug stuff really +(defmacro get-screen-x (frac) + `(the int (* ,frac 512))) + +(defmacro get-screen-y (frac) + `(the int (* ,frac 224))) + diff --git a/goal_src/jak1/examples/display-all-colors.gc b/goal_src/jak1/examples/display-all-colors.gc deleted file mode 100644 index 3a068c8a43..0000000000 --- a/goal_src/jak1/examples/display-all-colors.gc +++ /dev/null @@ -1,61 +0,0 @@ -;;-*-Lisp-*- -(in-package goal) - -;; This script creates a simple process that draws text demonstrating -;; all of GOAL's color constants to the on-screen debug output. - -;; Create somewhere for the handle to the process to live. See https://open-goal.github.io/docs/reference/process_and_state -;; as well as kernel/gstate.gc -(define *color-display-handle* (new 'static 'handle)) -(set! *color-display-handle* (the handle #f)) - - -(defun-debug start-display-text-colors () - "Spawn an onscreen string displaying all possible colors" - (if (not (handle->process *color-display-handle*)) - (let ((disp-proc - (process-spawn-function process :name 'display-proc - (lambda :behavior process () - (stack-size-set! (-> self main-thread) 256) - (loop - ;; These constants live in engine/gfx/font-h.gc - (format *stdcon* "~0k~%~% -~0L 0 default ~1L 1 white -~2L 2 gray ~3L 3 orange-red -~4L 4 bright-orange-red ~5L 5 bright-orange-red -~6L 6 bright-green ~7L 7 dark-blue -~8L 8 light-blue ~9L 9 dark-pink -~10L10 lighter-blue ~11L11 dark-light-blue -~12L12 dim-white ~13L13 dim-gray -~14L14 orange-red-2 ~15L15 yellow-green -~16L16 dark-green ~17L17 another-gray -~18L18 dark-dark-green ~19L19 flat-dark-purple -~20L20 flat-yellow ~21L21 blue-white -~22L22 pad-back ~23L23 pad-shine -~24L24 pad-square ~25L25 pad-circle -~26L26 pad-triangle ~27L27 pad-x -~28L28 lighter-lighter-blue ~29L29 yellow-orange -~30L30 yellow-green-2 ~31L31 another-light-blue -~32L32 light-yellow ~33L33 red-orange -~34L34 another-orange-red~0L~% - alternate names - ~3L3 red ~4L4 red2 ~5L5 yellow ~6L6 green ~7L7 blue - ~10L10 cyan ~33L33 red-reverse ~34L34 red-obverse~0L" - ) - (suspend) - ) - ) - ) - )) - (set! *color-display-handle* (ppointer->handle disp-proc)) - ) - ;; else - (format #t "Colors are already being displayed") - ) - ) - - -(defun-debug stop-display-text-colors () - "Kill the example text color display" - (kill-by-name 'display-proc *active-pool*) - ) diff --git a/goal_src/jak1/pc/util/display-font-color.gc b/goal_src/jak1/pc/util/display-font-color.gc new file mode 100644 index 0000000000..e2eecfe9ab --- /dev/null +++ b/goal_src/jak1/pc/util/display-font-color.gc @@ -0,0 +1,52 @@ +;;-*-Lisp-*- +(in-package goal) + +;; This script creates a simple process that draws text demonstrating +;; all of GOAL's color constants to the on-screen debug output. + +;; Create somewhere for the handle to the process to live. See https://open-goal.github.io/docs/reference/process_and_state +;; as well as kernel/gstate.gc +(define *color-displays* (new 'global 'inline-array 'handle 1)) + +(defmacro get-color-display-handle () + `(-> *color-displays* 0)) + +(set! (get-color-display-handle) INVALID_HANDLE) + +;; font-color is from font-h.gc +(defun font-color->string ((val font-color)) + "return the name of the font-color" + (enum->string font-color val) + ) + +(defun draw-all-font-colors () + "draws all font color names onscreen" + (with-dma-buffer-add-bucket ((buf (-> (current-frame) debug-buf)) + (bucket-id debug-no-zbuf)) + (dotimes (i 48) + (draw-string-xy (string-format "~2D ~S" i (font-color->string (the font-color i))) buf + (+ 4 (* (get-screen-x 0.5) (mod i 2))) (+ 8 (* 8 (/ i 2))) (the font-color i) (font-flags shadow))) + ) + ) + +(defun start-display-text-colors () + "Spawn an onscreen string displaying all possible colors" + (if (handle->process (get-color-display-handle)) + (format #t "Colors are already being displayed") + ;; else + (set! (get-color-display-handle) + (ppointer->handle (process-spawn-function process :name 'display-proc + (lambda :behavior process () + (loop + (draw-all-font-colors) + (suspend)) + ) + ))) + ) + ) + + +(defun-debug stop-display-text-colors () + "Kill the example text color display" + (kill-by-name 'display-proc *active-pool*) + ) diff --git a/goal_src/jak1/pc_debug/font-encode-test.gc b/goal_src/jak1/pc/util/font-encode-test.gc similarity index 66% rename from goal_src/jak1/pc_debug/font-encode-test.gc rename to goal_src/jak1/pc/util/font-encode-test.gc index 05809eef87..4b1d5ef91a 100644 --- a/goal_src/jak1/pc_debug/font-encode-test.gc +++ b/goal_src/jak1/pc/util/font-encode-test.gc @@ -8,11 +8,9 @@ ;; To run this: #| -(make-group "iso") ;; build the game -(lt) ;; connect to the runtime -(lg) ;; have the runtime load the game engine -(test-play) ;; start the game loop -(ml "goal_src/pc_debug/font-encode-test.gc") ;; build and load this file. +(mi) ;; build the game +(lt) ;; connect to the runtime +(ml "goal_src/jak1/pc/util/font-encode-test.gc") ;; build and load this file. |# @@ -30,8 +28,8 @@ ;;;; functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(define *font-string* (new 'global 'string 64 (the-as string #f))) -(define *font-string-ex* "") +(define *font-string* (new 'global 'string 64 (the string #f))) +(define *font-string-ex* (the string #f)) (define *font-string-val* #x96) (defun-debug font-encode-test-start () @@ -40,9 +38,6 @@ (unless (process-by-name 'font-encode *active-pool*) (process-spawn-function process :name 'font-encode (lambda :behavior process () - - (stack-size-set! (-> self main-thread) 768) - (let ((fnt (new 'stack 'font-context *font-default-matrix* FONT_ENCODE_TEXT_LEFT FONT_ENCODE_TEXT_Y 0.0 (font-color orange-red) (font-flags shadow kerning large middle))) ) @@ -54,27 +49,20 @@ (suspend) (if (or (cpad-pressed? 0 left) (cpad-hold? 0 l1)) - (-! *font-string-val* 1) - ) + (-! *font-string-val* 1)) (if (or (cpad-pressed? 0 right) (cpad-hold? 0 r1)) - (+! *font-string-val* 1) - ) - (if (< *font-string-val* 1) - (set! *font-string-val* 1) - ) - (if (> *font-string-val* #x1ff) - (set! *font-string-val* #x1ff) - ) + (+! *font-string-val* 1)) + (minmax! *font-string-val* 1 #x1ff) (clear *font-string*) (cond ((>= *font-string-val* #x100) (set! (-> *font-string* data 0) (/ *font-string-val* 256)) - (set! (-> *font-string* data 1) (mod *font-string-val* 256)) + (set! (-> *font-string* data 1) (logand *font-string-val* #xff)) (set! (-> *font-string* data 2) 0) ) (else - (set! (-> *font-string* data 0) (mod *font-string-val* 256)) + (set! (-> *font-string* data 0) (logand *font-string-val* #xff)) (set! (-> *font-string* data 1) 0) ) ) @@ -82,11 +70,12 @@ (set-origin! fnt FONT_ENCODE_TEXT_LEFT FONT_ENCODE_TEXT_Y) (set-flags! fnt (font-flags shadow kerning large middle)) (print-game-text *font-string* fnt #f 128 24) - (set-origin! fnt FONT_ENCODE_TEXT_LEFT (+ FONT_ENCODE_TEXT_Y 32)) - (print-game-text *font-string-ex* fnt #f 128 24) + (when *font-string-ex* + (set-origin! fnt FONT_ENCODE_TEXT_LEFT (+ FONT_ENCODE_TEXT_Y 32)) + (print-game-text *font-string-ex* fnt #f 128 24)) (set-origin! fnt FONT_ENCODE_TEXT_LEFT (- FONT_ENCODE_TEXT_Y 16)) (set-flags! fnt (font-flags shadow kerning middle)) - (print-game-text (string-format "#x~X" *font-string-val*) fnt #f 128 12) + (print-game-text (string-format "#x~x" *font-string-val*) fnt #f 128 12) ) ) diff --git a/goal_src/jak1/pc_debug/pc-pad-utils.gc b/goal_src/jak1/pc/util/pc-pad-utils.gc similarity index 95% rename from goal_src/jak1/pc_debug/pc-pad-utils.gc rename to goal_src/jak1/pc/util/pc-pad-utils.gc index fd00295898..a240aedaf6 100644 --- a/goal_src/jak1/pc_debug/pc-pad-utils.gc +++ b/goal_src/jak1/pc/util/pc-pad-utils.gc @@ -10,11 +10,9 @@ ;; To run this: #| -(make-group "iso") ;; build the game -(lt) ;; connect to the runtime -(lg) ;; have the runtime load the game engine -(test-play) ;; start the game loop -(ml "goal_src/pc_debug/pc-pad-utils.gc") ;; build and load this file. +(mi) ;; build the game +(lt) ;; connect to the runtime +(ml "goal_src/jak1/pc/util/pc-pad-utils.gc") ;; build and load this file. |# @@ -30,12 +28,12 @@ ) (define *pc-pad-proc-list* (new 'static 'pc-pad-proc-list)) -(set! (-> *pc-pad-proc-list* show) (the handle #f)) -(set! (-> *pc-pad-proc-list* input) (the handle #f)) +(set! (-> *pc-pad-proc-list* show) INVALID_HANDLE) +(set! (-> *pc-pad-proc-list* input) INVALID_HANDLE) ;; a pc pad process (deftype pc-pad-proc (process) - ((state-time int64) + ((state-time time-frame) (input-index uint64) (pad-idx int64) )