From 9b0480c50df0c23a552f36cdeffce43aff3e0d7a Mon Sep 17 00:00:00 2001 From: water111 <48171810+water111@users.noreply.github.com> Date: Wed, 1 Sep 2021 16:59:26 -0400 Subject: [PATCH] [decompiler] process initialization macros (#807) * implementation and a few working cases * fix self issue * fix run-function-in-process * fix up set-to-run --- decompiler/IR2/AtomicOpTypeAnalysis.cpp | 31 ++++++++ decompiler/IR2/FormExpressionAnalysis.cpp | 29 ++++++++ decompiler/config/all-types.gc | 10 +-- .../jak1_ntsc_black_label/type_casts.jsonc | 32 +-------- decompiler/util/TP_Type.cpp | 8 +++ decompiler/util/TP_Type.h | 16 +++++ goal_src/engine/camera/cam-start.gc | 72 +++++++++---------- goal_src/engine/game/collectables.gc | 2 +- goal_src/engine/game/game-info.gc | 10 +-- goal_src/engine/game/generic-obs.gc | 2 +- goal_src/engine/game/main.gc | 56 +++++++-------- goal_src/engine/game/task/process-taskable.gc | 2 +- goal_src/engine/gfx/merc/merc-h.gc | 2 +- goal_src/engine/target/logic-target.gc | 14 +--- goal_src/levels/beach/beach-rocks.gc | 30 ++------ goal_src/levels/beach/bird-lady-beach.gc | 10 +-- goal_src/levels/beach/sculptor.gc | 10 +-- goal_src/levels/common/dark-eco-pool.gc | 6 +- goal_src/levels/misty/misty-warehouse.gc | 5 +- goal_src/levels/village1/sage.gc | 5 +- goal_src/levels/village2/sunken-elevator.gc | 6 +- goal_src/levels/village_common/oracle.gc | 26 +++---- .../decompiler/reference/decompiler-macros.gc | 20 ++++++ .../reference/engine/camera/cam-start_REF.gc | 22 ++---- .../reference/engine/game/game-info_REF.gc | 66 ++++++++++------- .../reference/engine/gfx/merc/merc-h_REF.gc | 12 ++-- .../engine/target/logic-target_REF.gc | 14 +--- .../reference/levels/beach/beach-rocks_REF.gc | 30 ++------ .../levels/beach/bird-lady-beach_REF.gc | 10 +-- .../reference/levels/beach/sculptor_REF.gc | 10 +-- .../levels/common/dark-eco-pool_REF.gc | 4 +- .../levels/misty/misty-warehouse_REF.gc | 5 +- .../reference/levels/village1/sage_REF.gc | 9 +-- .../levels/village2/sunken-elevator_REF.gc | 6 +- .../levels/village_common/oracle_REF.gc | 10 +-- 35 files changed, 285 insertions(+), 317 deletions(-) diff --git a/decompiler/IR2/AtomicOpTypeAnalysis.cpp b/decompiler/IR2/AtomicOpTypeAnalysis.cpp index d130c9aa1d..3f66ec2e8f 100644 --- a/decompiler/IR2/AtomicOpTypeAnalysis.cpp +++ b/decompiler/IR2/AtomicOpTypeAnalysis.cpp @@ -84,6 +84,10 @@ TP_Type SimpleAtom::get_type(const TypeState& input, return TP_Type::make_from_ts(TypeSpec("pointer")); } else if (m_string == "enter-state") { return TP_Type::make_enter_state(); + } else if (m_string == "run-function-in-process") { + return TP_Type::make_run_function_in_process_function(); + } else if (m_string == "set-to-run" && env.func->guessed_name.to_string() != "enter-state") { + return TP_Type::make_set_to_run_function(); } // look up the type of the symbol @@ -1204,6 +1208,33 @@ TypeState CallOp::propagate_types_internal(const TypeState& input, in_type = state_to_go_function(state_type); } + if (in_tp.kind == TP_Type::Kind::RUN_FUNCTION_IN_PROCESS_FUNCTION || + in_tp.kind == TP_Type::Kind::SET_TO_RUN_FUNCTION) { + auto func_to_run_type = input.get(Register(Reg::GPR, arg_regs[1])); + auto func_to_run_ts = func_to_run_type.typespec(); + if (func_to_run_ts.base_type() != "function" || func_to_run_ts.arg_count() == 0 || + func_to_run_ts.arg_count() > 7) { + throw std::runtime_error( + fmt::format("Call to run-function-in-process or set-to-run at op {} with an invalid " + "function type: {}", + m_my_idx, func_to_run_type.print())); + } + + std::vector new_arg_types; + if (in_tp.kind == TP_Type::Kind::RUN_FUNCTION_IN_PROCESS_FUNCTION) { + new_arg_types.push_back(TypeSpec("process")); + } else { + new_arg_types.push_back(TypeSpec("thread")); + } + new_arg_types.push_back(TypeSpec("function")); + + for (size_t i = 0; i < func_to_run_ts.arg_count() - 1; i++) { + new_arg_types.push_back(func_to_run_ts.get_arg(i)); + } + new_arg_types.push_back(TypeSpec("none")); + in_type = TypeSpec("function", new_arg_types); + } + if (in_type.arg_count() < 1) { throw std::runtime_error("Called a function, but we do not know its type"); } diff --git a/decompiler/IR2/FormExpressionAnalysis.cpp b/decompiler/IR2/FormExpressionAnalysis.cpp index 5e8824a2dc..48383f2722 100644 --- a/decompiler/IR2/FormExpressionAnalysis.cpp +++ b/decompiler/IR2/FormExpressionAnalysis.cpp @@ -2666,6 +2666,35 @@ void FunctionCallElement::update_from_stack(const Env& env, std::swap(all_pop_vars.at(0), all_pop_vars.at(1)); } + if (tp_type.kind == TP_Type::Kind::RUN_FUNCTION_IN_PROCESS_FUNCTION) { + if (unstacked.at(0)->to_string(env) != "run-function-in-process") { + throw std::runtime_error( + fmt::format("Expression pass could not find the run-function-in-process function. Found " + "{} instead. Make sure there are no casts on this function.", + all_pop_vars.at(0).to_string(env))); + } + unstacked.at(0) = pool.form("run-now-in-process"); + } + + if (tp_type.kind == TP_Type::Kind::SET_TO_RUN_FUNCTION) { + if (unstacked.at(0)->to_string(env) != "set-to-run") { + throw std::runtime_error( + fmt::format("Expression pass could not find the set-to-run function. Found " + "{} instead. Make sure there are no casts on this function.", + all_pop_vars.at(0).to_string(env))); + } + unstacked.at(0) = pool.form("run-next-time-in-process"); + // also need to clean up (-> main-thread) to just + auto matcher = + Matcher::deref(Matcher::any(0), false, {DerefTokenMatcher::string("main-thread")}); + auto mr = match(matcher, unstacked.at(1)); + if (!mr.matched) { + throw std::runtime_error(fmt::format("set-to-run called on a strange thread: {}", + unstacked.at(1)->to_string(env))); + } + unstacked.at(1) = mr.maps.forms.at(0); + } + std::vector arg_forms; bool has_good_types = env.has_type_analysis() && function_type.arg_count() == nargs + 1; TypeSpec first_arg_type; diff --git a/decompiler/config/all-types.gc b/decompiler/config/all-types.gc index 689eda859d..1452c32e47 100644 --- a/decompiler/config/all-types.gc +++ b/decompiler/config/all-types.gc @@ -7844,7 +7844,7 @@ (vertex-skip int32 :offset-assert 20) (vertex-count int32 :offset-assert 24) (current-loc int32 :offset-assert 28) - (data2 uint8 :dynamic :offset-assert 32) ;; renamed from data. suspect inline-array has some magic. + (data vector :inline :dynamic :offset-assert 32) ) :method-count-assert 9 :size-assert #x20 @@ -18921,7 +18921,7 @@ (define-extern camera-look-at function) (define-extern camera-pov-from function) (define-extern command-get-trans function) -(define-extern manipy-init (function trsqv vector entity skeleton-group symbol none)) ;; TODO - not confirmed yet +(define-extern manipy-init (function trsqv vector entity skeleton-group none)) ;; TODO - not confirmed yet (define-extern part-tracker-notify function) (define-extern clone-anim-once function) (define-extern convert-to-hud-object function) @@ -18933,7 +18933,7 @@ (define-extern camera-tracker-init (function function none)) ;; TODO - not confirmed, see misty-warehouse::camera-view (define-extern cam-launcher-joystick function) (define-extern launcher-init-by-other function) -(define-extern touch-tracker-init function) +(define-extern touch-tracker-init (function object object object none)) (define-extern process-drawable-pair-random-point! function) (define-extern birth-func-set-quat function) (define-extern draw-eco-beam function) @@ -20308,7 +20308,7 @@ (define-extern ecovalve-init-by-other function) (define-extern birth-pickup-at-point (function vector int float symbol process-drawable symbol none)) ;; TODO - unconfirmed - see beach-rocks (define-extern fuel-cell-pick-anim function) -(define-extern othercam-init-by-other (function int symbol symbol none)) ;; TODO - unconfirmed - see beach-rocks +(define-extern othercam-init-by-other (function int symbol symbol symbol none)) ;; TODO - unconfirmed - see beach-rocks (define-extern fuel-cell-animate function) (define-extern add-blue-motion function) (define-extern check-blue-suck function) @@ -20317,7 +20317,7 @@ (define-extern money-init-by-other function) (define-extern money-init-by-other-no-bob function) (define-extern fuel-cell-init-by-other function) -(define-extern fuel-cell-init-as-clone (function game-task none)) ;; TODO - unconfirmed - see beach-rocks +(define-extern fuel-cell-init-as-clone (function handle object none)) ;; TODO - unconfirmed - see beach-rocks (define-extern buzzer-init-by-other function) ;; - Symbols diff --git a/decompiler/config/jak1_ntsc_black_label/type_casts.jsonc b/decompiler/config/jak1_ntsc_black_label/type_casts.jsonc index 746fc48ffe..395c98f65c 100644 --- a/decompiler/config/jak1_ntsc_black_label/type_casts.jsonc +++ b/decompiler/config/jak1_ntsc_black_label/type_casts.jsonc @@ -874,15 +874,12 @@ ], "main-cheats": [ - [1221, "t9", "(function cpu-thread function none)"], [[1123, 1126], "v1", "dma-packet"] ], "on": [[33, "t9", "(function cpu-thread function none)"]], "bg": [[37, "a0", "symbol"]], - "start": [[27, "t9", "(function process function symbol object)"]], - "level-update-after-load": [ [[29, 55], "s2", "drawable-tree"], [[121, 146], "s1", "drawable-inline-array-tfrag"], @@ -1701,11 +1698,6 @@ [[187, 231], "gp", "camera-slave"] ], - "cam-start": [ - [[18, 22], "t9", "(function process object function)"], - [[38, 42], "t9", "(function process object function)"] - ], - "cam-master-init": [ [[0, 999], "s6", "camera-master"], [[111, 115], "t9", "(function cpu-thread function)"], @@ -1810,10 +1802,6 @@ ], "draw-ocean-transition": [[255, "v1", "ocean-mid-mask"]], - - "init-target": [ - [408, "t9", "(function process function object)"] - ], "do-target-shadow": [ [46, "v1", "collide-shape-prim"] // `event-other` from collide-shape @@ -1928,7 +1916,6 @@ ], "misty-camera-view": [ - [19, "t9", "(function object object object object)"], [25, "v1", "handle"] ], @@ -2084,18 +2071,11 @@ [19, "v1", "float"] ], - "(method 32 bird-lady-beach)": [ - [44, "t9", "(function process function object object object object object)"], - [119, "t9", "(function process function object object object object object)"] - ], - "muse-to-idle": [ - [36, "t9", "(function process function object object object object object)"], [57, "v1", "muse"] ], "(method 32 sculptor)": [ - [66, "t9", "(function process function object object object object object)"], [87, "v1", "muse"] ], @@ -2135,11 +2115,6 @@ [11, "v1", "collide-shape"] ], - "(method 11 oracle)": [ - [83, "t9", "(function process function object object object object object)"], - [166, "t9", "(function process function object object object object object)"] - ], - "(method 43 farmer)": [ [19, "v1", "float"] ], @@ -2197,7 +2172,6 @@ "(method 32 sage)": [ [76, "v1", "float"], - [175, "t9", "(function process function object object object object object)"], [262, "v1", "assistant"] ], @@ -2241,9 +2215,7 @@ [258, "v1", "target"], [272, "v1", "target"], [287, "v1", "target"], - [298, "v1", "target"], - [556, "t9", "(function process function vector meters int none)"], - [635, "t9", "(function cpu-thread function process-drawable none)"] + [298, "v1", "target"] ], "(method 7 process)": [ @@ -2585,8 +2557,6 @@ ], "(code falling beach-rock)": [ - [63, "t9", "(function object object object object object object)"], - [98, "t9", "(function object object object object object)"], [138, "gp", "handle"], [150, "gp", "handle"], [[158, 165], "s5", "handle"] diff --git a/decompiler/util/TP_Type.cpp b/decompiler/util/TP_Type.cpp index 167ff5e98a..51c94a2310 100644 --- a/decompiler/util/TP_Type.cpp +++ b/decompiler/util/TP_Type.cpp @@ -73,6 +73,10 @@ std::string TP_Type::print() const { return fmt::format("", m_int); case Kind::ENTER_STATE_FUNCTION: return ""; + case Kind::SET_TO_RUN_FUNCTION: + return ""; + case Kind::RUN_FUNCTION_IN_PROCESS_FUNCTION: + return ""; case Kind::INVALID: default: assert(false); @@ -127,6 +131,8 @@ bool TP_Type::operator==(const TP_Type& other) const { return m_pcpyud == other.m_pcpyud && m_ts == other.m_ts; case Kind::LABEL_ADDR: case Kind::ENTER_STATE_FUNCTION: + case Kind::RUN_FUNCTION_IN_PROCESS_FUNCTION: + case Kind::SET_TO_RUN_FUNCTION: return true; case Kind::INVALID: default: @@ -189,6 +195,8 @@ TypeSpec TP_Type::typespec() const { case Kind::LABEL_ADDR: return TypeSpec("pointer"); // ? case Kind::ENTER_STATE_FUNCTION: + case Kind::RUN_FUNCTION_IN_PROCESS_FUNCTION: + case Kind::SET_TO_RUN_FUNCTION: // give a general function so we can't call it normally. return TypeSpec("function"); case Kind::INVALID: diff --git a/decompiler/util/TP_Type.h b/decompiler/util/TP_Type.h index 14c234ff0b..fe8330a39a 100644 --- a/decompiler/util/TP_Type.h +++ b/decompiler/util/TP_Type.h @@ -37,6 +37,8 @@ class TP_Type { LEFT_SHIFTED_BITFIELD, // (bitfield << some-constant) LABEL_ADDR, ENTER_STATE_FUNCTION, + RUN_FUNCTION_IN_PROCESS_FUNCTION, + SET_TO_RUN_FUNCTION, INVALID } kind = Kind::UNINITIALIZED; TP_Type() = default; @@ -67,6 +69,8 @@ class TP_Type { case Kind::PCPYUD_BITFIELD_AND: case Kind::LABEL_ADDR: case Kind::ENTER_STATE_FUNCTION: + case Kind::RUN_FUNCTION_IN_PROCESS_FUNCTION: + case Kind::SET_TO_RUN_FUNCTION: return false; case Kind::UNINITIALIZED: case Kind::OBJECT_NEW_METHOD: @@ -269,6 +273,18 @@ class TP_Type { return result; } + static TP_Type make_run_function_in_process_function() { + TP_Type result; + result.kind = Kind::RUN_FUNCTION_IN_PROCESS_FUNCTION; + return result; + } + + static TP_Type make_set_to_run_function() { + TP_Type result; + result.kind = Kind::SET_TO_RUN_FUNCTION; + return result; + } + const TypeSpec& get_objects_typespec() const { assert(kind == Kind::TYPESPEC || kind == Kind::INTEGER_CONSTANT_PLUS_VAR); return m_ts; diff --git a/goal_src/engine/camera/cam-start.gc b/goal_src/engine/camera/cam-start.gc index 5bedbea90e..82b5e9d4ef 100644 --- a/goal_src/engine/camera/cam-start.gc +++ b/goal_src/engine/camera/cam-start.gc @@ -23,49 +23,41 @@ (defun cam-start ((arg0 symbol)) (cam-stop) (let ((s5-0 (get-process *camera-dead-pool* camera-combiner #x4000))) - (when s5-0 - (let ((t9-2 (method-of-type camera-combiner activate))) - (t9-2 - (the-as camera-combiner s5-0) - *camera-pool* - 'camera-combiner - (the-as pointer #x70004000) - ) - ) - ((the-as (function process object function) run-function-in-process) - s5-0 - cam-combiner-init - ) - (-> s5-0 ppointer) - ) - ) - (let* ((s5-1 (get-process *camera-master-dead-pool* camera-master #x4000)) - (v1-5 (when s5-1 - (let ((t9-5 (method-of-type camera-master activate))) - (t9-5 - (the-as camera-master s5-1) - *camera-pool* - 'camera-master - (the-as pointer #x70004000) - ) - ) - ((the-as (function process object function) set-to-run) - (the-as process (-> s5-1 main-thread)) - cam-master-init - ) - (-> s5-1 ppointer) - ) + (when s5-0 + (let ((t9-2 (method-of-type camera-combiner activate))) + (t9-2 + (the-as camera-combiner s5-0) + *camera-pool* + 'camera-combiner + (the-as pointer #x70004000) + ) + ) + (run-now-in-process s5-0 cam-combiner-init) + (-> s5-0 ppointer) + ) + ) + (let ((s5-1 (get-process *camera-master-dead-pool* camera-master #x4000))) + (set! *camera* + (the-as camera-master + (ppointer->process + (when s5-1 + (let ((t9-5 (method-of-type camera-master activate))) + (t9-5 (the-as camera-master s5-1) + *camera-pool* + 'camera-master + (the-as pointer #x70004000) + ) + ) + (run-next-time-in-process s5-1 cam-master-init) + (-> s5-1 ppointer) + ) + ) + ) ) - ) - (set! *camera* (the-as camera-master (if v1-5 - (-> v1-5 0 self) - ) - ) ) - ) (if arg0 - (reset-cameras) - ) + (reset-cameras) + ) 0 (none) ) diff --git a/goal_src/engine/game/collectables.gc b/goal_src/engine/game/collectables.gc index d0351964be..d3cd21db93 100644 --- a/goal_src/engine/game/collectables.gc +++ b/goal_src/engine/game/collectables.gc @@ -78,4 +78,4 @@ :size-assert #x19c :flag-assert #x1f0130019c ) -(define-extern fuel-cell-init-as-clone (function game-task none)) +(define-extern fuel-cell-init-as-clone (function handle object none)) diff --git a/goal_src/engine/game/game-info.gc b/goal_src/engine/game/game-info.gc index d948bba8b3..f085d0411a 100644 --- a/goal_src/engine/game/game-info.gc +++ b/goal_src/engine/game/game-info.gc @@ -562,7 +562,7 @@ ) (declare-type vent process-drawable) -(define-extern touch-tracker-init function) +(define-extern touch-tracker-init (function object object object none)) (defmethod pickup-collectable! fact-info-target ((obj fact-info-target) (kind pickup-type) (amount float) (source-handle handle)) "Pickup a thing!" @@ -820,7 +820,7 @@ (let ((t9-28 (method-of-type touch-tracker activate))) (t9-28 (the-as touch-tracker s3-5) s5-1 'touch-tracker (the-as pointer #x70004000)) ) - (run-next-time-in-process s3-5 touch-tracker-init (-> s5-1 root trans) (-> *FACT-bank* suck-bounce-dist) 300) + (run-now-in-process s3-5 touch-tracker-init (-> s5-1 root trans) (-> *FACT-bank* suck-bounce-dist) 300) (-> s3-5 ppointer) ) ) @@ -890,11 +890,7 @@ (let ((t9-35 (method-of-type process activate))) (t9-35 s4-4 s5-1 'process (the-as pointer #x70004000)) ) - ((the-as - (function cpu-thread function process-drawable none) - set-to-run - ) - (-> s4-4 main-thread) + (run-next-time-in-process s4-4 (lambda ((arg0 process-drawable)) (with-pp (let ((start-time (-> *display* base-frame-counter))) diff --git a/goal_src/engine/game/generic-obs.gc b/goal_src/engine/game/generic-obs.gc index 38d115e59f..32bb5ee6ab 100644 --- a/goal_src/engine/game/generic-obs.gc +++ b/goal_src/engine/game/generic-obs.gc @@ -19,6 +19,6 @@ (define-extern camera-change-to (function string int symbol none)) ;; TODO - not confirmed yet (define-extern process-release? (function process symbol)) ;; TODO - for bird-lady-beach -(define-extern manipy-init (function trsqv vector entity skeleton-group symbol none)) ;; TODO - not confirmed yet +(define-extern manipy-init (function trsqv vector entity skeleton-group none)) ;; TODO - not confirmed yet ;; TODO - for projectiles | dark-eco-pool (define-extern part-tracker-init (function sparticle-launch-group int basic basic basic vector none)) ;; TODO - not confirmed diff --git a/goal_src/engine/game/main.gc b/goal_src/engine/game/main.gc index eb6415f2b1..3d0a42d283 100644 --- a/goal_src/engine/game/main.gc +++ b/goal_src/engine/game/main.gc @@ -899,35 +899,35 @@ (if (when game-end-proc (let ((t9-28 (method-of-type process activate))) (t9-28 - game-end-proc - *default-pool* - 'process - (the-as pointer #x70004000) - ) + game-end-proc + *default-pool* + 'process + (the-as pointer #x70004000) + ) + ) + (run-next-time-in-process + game-end-proc + (lambda () + (set-blackout-frames #x7530) + (set! (-> *setting-control* default allow-pause) #f) + (set! (-> *setting-control* default allow-progress) #f) + (copy-settings-from-target! *setting-control*) + (set! (-> *setting-control* default sfx-volume) 0.0) + (set! (-> *setting-control* default music-volume) 0.0) + (set! (-> *setting-control* default dialog-volume) 0.0) + (set! (-> *setting-control* default ambient-volume) 0.0) + (let ((gp-0 (-> *display* base-frame-counter))) + (until (begin + (suspend) + (>= (the-as int (- (-> *display* base-frame-counter) gp-0)) 30) + ) + (empty) + ) + ) + (kernel-shutdown) + (none) + ) ) - ((the-as (function cpu-thread function none) set-to-run) - (-> game-end-proc main-thread) - (lambda () - (set-blackout-frames #x7530) - (set! (-> *setting-control* default allow-pause) #f) - (set! (-> *setting-control* default allow-progress) #f) - (copy-settings-from-target! *setting-control*) - (set! (-> *setting-control* default sfx-volume) 0.0) - (set! (-> *setting-control* default music-volume) 0.0) - (set! (-> *setting-control* default dialog-volume) 0.0) - (set! (-> *setting-control* default ambient-volume) 0.0) - (let ((gp-0 (-> *display* base-frame-counter))) - (until (begin - (suspend) - (>= (the-as int (- (-> *display* base-frame-counter) gp-0)) 30) - ) - (empty) - ) - ) - (kernel-shutdown) - (none) - ) - ) (-> game-end-proc ppointer) ) ;; failed to create process, just die. diff --git a/goal_src/engine/game/task/process-taskable.gc b/goal_src/engine/game/task/process-taskable.gc index 67718a764c..893aded833 100644 --- a/goal_src/engine/game/task/process-taskable.gc +++ b/goal_src/engine/game/task/process-taskable.gc @@ -6,4 +6,4 @@ ;; dgos: GAME, ENGINE ;; TODO - for beach-rocks -(define-extern othercam-init-by-other (function int symbol symbol none)) +(define-extern othercam-init-by-other (function int symbol symbol symbol none)) diff --git a/goal_src/engine/gfx/merc/merc-h.gc b/goal_src/engine/gfx/merc/merc-h.gc index fd426a3e26..44ac701500 100644 --- a/goal_src/engine/gfx/merc/merc-h.gc +++ b/goal_src/engine/gfx/merc/merc-h.gc @@ -10,7 +10,7 @@ (vertex-skip int32 :offset-assert 20) (vertex-count int32 :offset-assert 24) (current-loc int32 :offset-assert 28) - (data2 uint8 :dynamic :offset-assert 32) ;; renamed from data. suspect inline-array has some magic. + (data vector :inline :dynamic :offset-assert 32) ) :method-count-assert 9 :size-assert #x20 diff --git a/goal_src/engine/target/logic-target.gc b/goal_src/engine/target/logic-target.gc index ae316ec9b6..b4f88ec9e5 100644 --- a/goal_src/engine/target/logic-target.gc +++ b/goal_src/engine/target/logic-target.gc @@ -2936,10 +2936,7 @@ ) ) ) - ((the-as - (function process function object) - run-function-in-process - ) + (run-now-in-process s5-1 init-sidekick ) @@ -2988,14 +2985,7 @@ (&-> *dram-stack* 14336) ) ) - ((the-as - (function process function symbol object) - run-function-in-process - ) - s5-0 - init-target - (the-as symbol arg1) - ) + (run-now-in-process s5-0 init-target arg1) (-> s5-0 ppointer) ) ) diff --git a/goal_src/levels/beach/beach-rocks.gc b/goal_src/levels/beach/beach-rocks.gc index a13be9f0af..242fbb99a1 100644 --- a/goal_src/levels/beach/beach-rocks.gc +++ b/goal_src/levels/beach/beach-rocks.gc @@ -1327,26 +1327,13 @@ (the-as pointer #x70004000) ) ) - (let - ((t9-6 - (the-as function run-function-in-process) - ) - (a0-9 gp-1) - (a1-4 othercam-init-by-other) - (a3-2 7) - (t0-1 #f) - ) + (run-now-in-process + gp-1 + othercam-init-by-other + self + 7 + #f #t - ((the-as - (function object object object object object object) - t9-6 - ) - a0-9 - a1-4 - self - a3-2 - t0-1 - ) ) (-> gp-1 ppointer) ) @@ -1363,10 +1350,7 @@ (the-as pointer #x70004000) ) ) - ((the-as - (function object object object object object) - run-function-in-process - ) + (run-now-in-process s5-0 fuel-cell-init-as-clone (process->handle self) diff --git a/goal_src/levels/beach/bird-lady-beach.gc b/goal_src/levels/beach/bird-lady-beach.gc index a98bf18526..e109e76c0b 100644 --- a/goal_src/levels/beach/bird-lady-beach.gc +++ b/goal_src/levels/beach/bird-lady-beach.gc @@ -87,10 +87,7 @@ (the-as pointer #x70004000) ) ) - ((the-as - (function process function object object object object object) - run-function-in-process - ) + (run-now-in-process s5-1 manipy-init (-> obj root trans) @@ -134,10 +131,7 @@ (the-as pointer #x70004000) ) ) - ((the-as - (function process function object object object object object) - run-function-in-process - ) + (run-now-in-process s5-2 manipy-init (-> obj root trans) diff --git a/goal_src/levels/beach/sculptor.gc b/goal_src/levels/beach/sculptor.gc index 300f443d18..b9b9bf9602 100644 --- a/goal_src/levels/beach/sculptor.gc +++ b/goal_src/levels/beach/sculptor.gc @@ -155,10 +155,7 @@ ) ) ) - ((the-as - (function process function object object object object object) - run-function-in-process - ) + (run-now-in-process s5-0 manipy-init (-> @@ -338,10 +335,7 @@ (the-as pointer #x70004000) ) ) - ((the-as - (function process function object object object object object) - run-function-in-process - ) + (run-now-in-process s5-1 manipy-init (-> obj root trans) diff --git a/goal_src/levels/common/dark-eco-pool.gc b/goal_src/levels/common/dark-eco-pool.gc index fb85c42a6c..4d904af98c 100644 --- a/goal_src/levels/common/dark-eco-pool.gc +++ b/goal_src/levels/common/dark-eco-pool.gc @@ -1186,7 +1186,7 @@ (the-as pointer #x70004000) ) ) - (run-function-in-process + (run-now-in-process s4-1 part-tracker-init (-> *part-group-id-table* 445) @@ -1194,7 +1194,7 @@ #f #f #f - (+ (+ (* s3-0 16) 28) (the-as int s5-0)) + (-> s5-0 data s3-0) ) (-> s4-1 ppointer) ) @@ -1218,5 +1218,3 @@ ) - - diff --git a/goal_src/levels/misty/misty-warehouse.gc b/goal_src/levels/misty/misty-warehouse.gc index dc2782ddaf..b149dabbe7 100644 --- a/goal_src/levels/misty/misty-warehouse.gc +++ b/goal_src/levels/misty/misty-warehouse.gc @@ -91,10 +91,7 @@ (the-as pointer #x70004000) ) ) - ((the-as - (function object object object object) - run-function-in-process - ) + (run-now-in-process gp-0 camera-tracker-init (lambda :behavior camera-tracker diff --git a/goal_src/levels/village1/sage.gc b/goal_src/levels/village1/sage.gc index 990a811f22..91a2c1b7d9 100644 --- a/goal_src/levels/village1/sage.gc +++ b/goal_src/levels/village1/sage.gc @@ -643,10 +643,7 @@ (the-as pointer #x70004000) ) ) - ((the-as - (function process function object object object object object) - run-function-in-process - ) + (run-now-in-process s5-2 manipy-init (-> obj root trans) diff --git a/goal_src/levels/village2/sunken-elevator.gc b/goal_src/levels/village2/sunken-elevator.gc index ac5fa1c39b..4fe8e9c44d 100644 --- a/goal_src/levels/village2/sunken-elevator.gc +++ b/goal_src/levels/village2/sunken-elevator.gc @@ -87,7 +87,7 @@ (the-as pointer #x70004000) ) ) - (run-function-in-process + (run-now-in-process gp-0 pov-camera-init-by-other (-> self spawn-pos) @@ -120,7 +120,7 @@ (the-as pointer #x70004000) ) ) - (run-function-in-process + (run-now-in-process gp-1 pov-camera-init-by-other (-> self spawn-pos) @@ -177,7 +177,7 @@ (the-as pointer #x70004000) ) ) - (run-function-in-process + (run-now-in-process gp-0 pov-camera-init-by-other (-> self spawn-pos) diff --git a/goal_src/levels/village_common/oracle.gc b/goal_src/levels/village_common/oracle.gc index f52bad8eab..00506da516 100644 --- a/goal_src/levels/village_common/oracle.gc +++ b/goal_src/levels/village_common/oracle.gc @@ -697,10 +697,7 @@ ) ) ) - ((the-as - (function process function object object object object object) - run-function-in-process - ) + (run-now-in-process s3-0 manipy-init s4-0 @@ -725,9 +722,10 @@ uint (lambda :behavior oracle () - (let ((v0-0 (create-launch-control (-> *part-group-id-table* 63) self))) + (let + ((v0-0 (create-launch-control (-> *part-group-id-table* 63) self))) (set! (-> self part) v0-0) - v0-0 + (the-as sparticle-launch-group v0-0) ) ) ) @@ -770,10 +768,7 @@ ) ) ) - ((the-as - (function process function object object object object object) - run-function-in-process - ) + (run-now-in-process s3-1 manipy-init s4-0 @@ -798,9 +793,10 @@ uint (lambda :behavior oracle () - (let ((v0-0 (create-launch-control (-> *part-group-id-table* 63) self))) + (let + ((v0-0 (create-launch-control (-> *part-group-id-table* 63) self))) (set! (-> self part) v0-0) - v0-0 + (the-as sparticle-launch-group v0-0) ) ) ) @@ -819,4 +815,8 @@ (dummy-42 obj) (none) ) - ) \ No newline at end of file + ) + + + + diff --git a/test/decompiler/reference/decompiler-macros.gc b/test/decompiler/reference/decompiler-macros.gc index 8bc82d7cb9..f604707557 100644 --- a/test/decompiler/reference/decompiler-macros.gc +++ b/test/decompiler/reference/decompiler-macros.gc @@ -493,4 +493,24 @@ *res-static-buf* ) ) + ) + +;; run the given function in a process right now. +;; will return to here when: +;; - you return +;; - you deactivate +;; - you go +;; - you throw to 'initialize +(defmacro run-now-in-process (proc func &rest args) + `((the (function _varargs_ object) run-function-in-process) + ,proc ,func ,@args + ) + ) + +;; sets the main thread of the given process to run the given thing. +;; this resets the main thread stack back to the top +(defmacro run-next-time-in-process (proc func &rest args) + `((the (function _varargs_ object) set-to-run) + (-> ,proc main-thread) ,func ,@args + ) ) \ No newline at end of file diff --git a/test/decompiler/reference/engine/camera/cam-start_REF.gc b/test/decompiler/reference/engine/camera/cam-start_REF.gc index ddddf0de4f..7b9f197e56 100644 --- a/test/decompiler/reference/engine/camera/cam-start_REF.gc +++ b/test/decompiler/reference/engine/camera/cam-start_REF.gc @@ -28,10 +28,7 @@ (the-as pointer #x70004000) ) ) - ((the-as (function process object function) run-function-in-process) - s5-0 - cam-combiner-init - ) + (run-now-in-process s5-0 cam-combiner-init) (-> s5-0 ppointer) ) ) @@ -58,17 +55,8 @@ ) ) ) - ((the-as - (function process object function) - set-to-run - ) - (the-as - process - (-> - s5-1 - main-thread - ) - ) + (run-next-time-in-process + s5-1 cam-master-init ) (-> s5-1 ppointer) @@ -86,3 +74,7 @@ ;; failed to figure out what this is: (cam-start #f) + + + + diff --git a/test/decompiler/reference/engine/game/game-info_REF.gc b/test/decompiler/reference/engine/game/game-info_REF.gc index a576827d5e..5f7b5ace9e 100644 --- a/test/decompiler/reference/engine/game/game-info_REF.gc +++ b/test/decompiler/reference/engine/game/game-info_REF.gc @@ -939,10 +939,7 @@ (the-as pointer #x70004000) ) ) - ((the-as - (function process function vector meters int none) - run-function-in-process - ) + (run-now-in-process s3-5 touch-tracker-init (-> s5-1 root trans) @@ -1033,28 +1030,45 @@ (let ((t9-35 (method-of-type process activate))) (t9-35 s4-4 s5-1 'process (the-as pointer #x70004000)) ) - ((the-as - (function cpu-thread function process-drawable none) - set-to-run - ) - (-> s4-4 main-thread) - (lambda ((arg0 process-drawable)) - (with-pp - (let ((s5-0 (-> *display* base-frame-counter))) - (until (>= (- (-> *display* base-frame-counter) s5-0) 180) - (let ((a1-0 (new 'stack-no-clear 'event-message-block))) - (set! (-> a1-0 from) pp) - (set! (-> a1-0 num-params) 1) - (set! (-> a1-0 message) 'effect) - (set! (-> a1-0 param 0) (the-as uint 'eco-blue)) - (send-event-function arg0 a1-0) - ) - (suspend) - ) - ) - (none) - ) - ) + (run-next-time-in-process s4-4 (lambda ((arg0 process-drawable)) + (with-pp + (let + ((s5-0 + (-> *display* base-frame-counter) + ) + ) + (until + (>= + (- + (-> + *display* + base-frame-counter + ) + s5-0 + ) + 180 + ) + (let + ((a1-0 + (new 'stack-no-clear 'event-message-block + ) + ) + ) + (set! (-> a1-0 from) pp) + (set! (-> a1-0 num-params) 1) + (set! (-> a1-0 message) 'effect) + (set! + (-> a1-0 param 0) + (the-as uint 'eco-blue) + ) + (send-event-function arg0 a1-0) + ) + (suspend) + ) + ) + (none) + ) + ) s5-1 ) (-> s4-4 ppointer) diff --git a/test/decompiler/reference/engine/gfx/merc/merc-h_REF.gc b/test/decompiler/reference/engine/gfx/merc/merc-h_REF.gc index 07de463221..57d07b34ee 100644 --- a/test/decompiler/reference/engine/gfx/merc/merc-h_REF.gc +++ b/test/decompiler/reference/engine/gfx/merc/merc-h_REF.gc @@ -3,11 +3,11 @@ ;; definition of type ripple-merc-query (deftype ripple-merc-query (inline-array-class) - ((start-vertex int32 :offset-assert 16) - (vertex-skip int32 :offset-assert 20) - (vertex-count int32 :offset-assert 24) - (current-loc int32 :offset-assert 28) - (data2 uint8 :dynamic :offset-assert 32) + ((start-vertex int32 :offset-assert 16) + (vertex-skip int32 :offset-assert 20) + (vertex-count int32 :offset-assert 24) + (current-loc int32 :offset-assert 28) + (data vector :inline :dynamic :offset-assert 32) ) :method-count-assert 9 :size-assert #x20 @@ -23,7 +23,7 @@ (format #t "~Tvertex-skip: ~D~%" (-> obj vertex-skip)) (format #t "~Tvertex-count: ~D~%" (-> obj vertex-count)) (format #t "~Tcurrent-loc: ~D~%" (-> obj current-loc)) - (format #t "~Tdata[0] @ #x~X~%" (-> obj data2)) + (format #t "~Tdata[0] @ #x~X~%" (-> obj data)) obj ) diff --git a/test/decompiler/reference/engine/target/logic-target_REF.gc b/test/decompiler/reference/engine/target/logic-target_REF.gc index 1f84948966..ef5bfc88c7 100644 --- a/test/decompiler/reference/engine/target/logic-target_REF.gc +++ b/test/decompiler/reference/engine/target/logic-target_REF.gc @@ -2929,10 +2929,7 @@ ) ) ) - ((the-as - (function process function object) - run-function-in-process - ) + (run-now-in-process s5-1 init-sidekick ) @@ -2981,14 +2978,7 @@ (&-> *dram-stack* 14336) ) ) - ((the-as - (function process function symbol object) - run-function-in-process - ) - s5-0 - init-target - (the-as symbol arg1) - ) + (run-now-in-process s5-0 init-target arg1) (-> s5-0 ppointer) ) ) diff --git a/test/decompiler/reference/levels/beach/beach-rocks_REF.gc b/test/decompiler/reference/levels/beach/beach-rocks_REF.gc index 9f6b788eb4..9669de75d9 100644 --- a/test/decompiler/reference/levels/beach/beach-rocks_REF.gc +++ b/test/decompiler/reference/levels/beach/beach-rocks_REF.gc @@ -1321,26 +1321,13 @@ (the-as pointer #x70004000) ) ) - (let - ((t9-6 - (the-as function run-function-in-process) - ) - (a0-9 gp-1) - (a1-4 othercam-init-by-other) - (a3-2 7) - (t0-1 #f) - ) + (run-now-in-process + gp-1 + othercam-init-by-other + self + 7 + #f #t - ((the-as - (function object object object object object object) - t9-6 - ) - a0-9 - a1-4 - self - a3-2 - t0-1 - ) ) (-> gp-1 ppointer) ) @@ -1357,10 +1344,7 @@ (the-as pointer #x70004000) ) ) - ((the-as - (function object object object object object) - run-function-in-process - ) + (run-now-in-process s5-0 fuel-cell-init-as-clone (process->handle self) diff --git a/test/decompiler/reference/levels/beach/bird-lady-beach_REF.gc b/test/decompiler/reference/levels/beach/bird-lady-beach_REF.gc index bf7ae4f532..4f805aa62a 100644 --- a/test/decompiler/reference/levels/beach/bird-lady-beach_REF.gc +++ b/test/decompiler/reference/levels/beach/bird-lady-beach_REF.gc @@ -91,10 +91,7 @@ (the-as pointer #x70004000) ) ) - ((the-as - (function process function object object object object object) - run-function-in-process - ) + (run-now-in-process s5-1 manipy-init (-> obj root trans) @@ -138,10 +135,7 @@ (the-as pointer #x70004000) ) ) - ((the-as - (function process function object object object object object) - run-function-in-process - ) + (run-now-in-process s5-2 manipy-init (-> obj root trans) diff --git a/test/decompiler/reference/levels/beach/sculptor_REF.gc b/test/decompiler/reference/levels/beach/sculptor_REF.gc index c5b59d3ca2..a633619015 100644 --- a/test/decompiler/reference/levels/beach/sculptor_REF.gc +++ b/test/decompiler/reference/levels/beach/sculptor_REF.gc @@ -124,10 +124,7 @@ ) ) ) - ((the-as - (function process function object object object object object) - run-function-in-process - ) + (run-now-in-process s5-0 manipy-init (-> @@ -307,10 +304,7 @@ (the-as pointer #x70004000) ) ) - ((the-as - (function process function object object object object object) - run-function-in-process - ) + (run-now-in-process s5-1 manipy-init (-> obj root trans) diff --git a/test/decompiler/reference/levels/common/dark-eco-pool_REF.gc b/test/decompiler/reference/levels/common/dark-eco-pool_REF.gc index 425eddfa41..bbb225c710 100644 --- a/test/decompiler/reference/levels/common/dark-eco-pool_REF.gc +++ b/test/decompiler/reference/levels/common/dark-eco-pool_REF.gc @@ -1190,7 +1190,7 @@ (the-as pointer #x70004000) ) ) - (run-function-in-process + (run-now-in-process s4-1 part-tracker-init (-> *part-group-id-table* 445) @@ -1198,7 +1198,7 @@ #f #f #f - (+ (+ (* s3-0 16) 28) (the-as int s5-0)) + (-> s5-0 data s3-0) ) (-> s4-1 ppointer) ) diff --git a/test/decompiler/reference/levels/misty/misty-warehouse_REF.gc b/test/decompiler/reference/levels/misty/misty-warehouse_REF.gc index b1fdcdeaad..86a003c947 100644 --- a/test/decompiler/reference/levels/misty/misty-warehouse_REF.gc +++ b/test/decompiler/reference/levels/misty/misty-warehouse_REF.gc @@ -88,10 +88,7 @@ (the-as pointer #x70004000) ) ) - ((the-as - (function object object object object) - run-function-in-process - ) + (run-now-in-process gp-0 camera-tracker-init (lambda :behavior camera-tracker diff --git a/test/decompiler/reference/levels/village1/sage_REF.gc b/test/decompiler/reference/levels/village1/sage_REF.gc index 9b3df66b39..4d76afaba2 100644 --- a/test/decompiler/reference/levels/village1/sage_REF.gc +++ b/test/decompiler/reference/levels/village1/sage_REF.gc @@ -647,10 +647,7 @@ (the-as pointer #x70004000) ) ) - ((the-as - (function process function object object object object object) - run-function-in-process - ) + (run-now-in-process s5-2 manipy-init (-> obj root trans) @@ -1398,7 +1395,3 @@ (dummy-42 obj) (none) ) - - - - diff --git a/test/decompiler/reference/levels/village2/sunken-elevator_REF.gc b/test/decompiler/reference/levels/village2/sunken-elevator_REF.gc index 165d0235fa..34ebecc623 100644 --- a/test/decompiler/reference/levels/village2/sunken-elevator_REF.gc +++ b/test/decompiler/reference/levels/village2/sunken-elevator_REF.gc @@ -95,7 +95,7 @@ (the-as pointer #x70004000) ) ) - (run-function-in-process + (run-now-in-process gp-0 pov-camera-init-by-other (-> self spawn-pos) @@ -128,7 +128,7 @@ (the-as pointer #x70004000) ) ) - (run-function-in-process + (run-now-in-process gp-1 pov-camera-init-by-other (-> self spawn-pos) @@ -185,7 +185,7 @@ (the-as pointer #x70004000) ) ) - (run-function-in-process + (run-now-in-process gp-0 pov-camera-init-by-other (-> self spawn-pos) diff --git a/test/decompiler/reference/levels/village_common/oracle_REF.gc b/test/decompiler/reference/levels/village_common/oracle_REF.gc index e0b759ef08..bcd2d4e251 100644 --- a/test/decompiler/reference/levels/village_common/oracle_REF.gc +++ b/test/decompiler/reference/levels/village_common/oracle_REF.gc @@ -703,10 +703,7 @@ ) ) ) - ((the-as - (function process function object object object object object) - run-function-in-process - ) + (run-now-in-process s3-0 manipy-init s4-0 @@ -777,10 +774,7 @@ ) ) ) - ((the-as - (function process function object object object object object) - run-function-in-process - ) + (run-now-in-process s3-1 manipy-init s4-0