support non-debug-mode (#1347)

This commit is contained in:
water111 2022-04-30 14:55:13 -04:00 committed by GitHub
parent 3ed009924f
commit 347572d9df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 88 additions and 33 deletions

View file

@ -122,6 +122,11 @@ void OpenGlDebugGui::draw(const DmaStats& dma_stats) {
ImGui::MenuItem("Dump to file", nullptr, &dump_events); ImGui::MenuItem("Dump to file", nullptr, &dump_events);
ImGui::EndMenu(); ImGui::EndMenu();
} }
if (ImGui::BeginMenu("Reboot in Debug Mode")) {
want_reboot_in_debug = true;
ImGui::EndMenu();
}
} }
ImGui::EndMainMenuBar(); ImGui::EndMainMenuBar();

View file

@ -66,6 +66,7 @@ class OpenGlDebugGui {
bool small_profiler = false; bool small_profiler = false;
bool record_events = false; bool record_events = false;
bool dump_events = false; bool dump_events = false;
bool want_reboot_in_debug = false;
private: private:
FrameTimeRecorder m_frame_timer; FrameTimeRecorder m_frame_timer;

View file

@ -463,10 +463,16 @@ static void gl_render_display(GfxDisplay* display) {
g_gfx_data->sync_cv.notify_all(); g_gfx_data->sync_cv.notify_all();
} }
// reboot whole game, if requested
if (g_gfx_data->debug_gui.want_reboot_in_debug) {
g_gfx_data->debug_gui.want_reboot_in_debug = false;
MasterExit = RuntimeExitStatus::RESTART_IN_DEBUG;
}
// exit if display window was closed // exit if display window was closed
if (glfwWindowShouldClose(window)) { if (glfwWindowShouldClose(window)) {
std::unique_lock<std::mutex> lock(g_gfx_data->sync_mutex); std::unique_lock<std::mutex> lock(g_gfx_data->sync_mutex);
MasterExit = 2; MasterExit = RuntimeExitStatus::EXIT;
g_gfx_data->sync_cv.notify_all(); g_gfx_data->sync_cv.notify_all();
} }
} }
@ -481,7 +487,9 @@ u32 gl_vsync() {
} }
std::unique_lock<std::mutex> lock(g_gfx_data->sync_mutex); std::unique_lock<std::mutex> lock(g_gfx_data->sync_mutex);
auto init_frame = g_gfx_data->frame_idx_of_input_data; auto init_frame = g_gfx_data->frame_idx_of_input_data;
g_gfx_data->sync_cv.wait(lock, [=] { return MasterExit || g_gfx_data->frame_idx > init_frame; }); g_gfx_data->sync_cv.wait(lock, [=] {
return (MasterExit != RuntimeExitStatus::RUNNING) || g_gfx_data->frame_idx > init_frame;
});
return g_gfx_data->frame_idx & 1; return g_gfx_data->frame_idx & 1;
} }

View file

@ -40,7 +40,7 @@ char DebugBootMessage[64];
MasterConfig masterConfig; MasterConfig masterConfig;
// Set to 1 to kill GOAL kernel // Set to 1 to kill GOAL kernel
u32 MasterExit; RuntimeExitStatus MasterExit;
// Set to 1 to enable debug heap // Set to 1 to enable debug heap
u32 MasterDebug; u32 MasterDebug;
@ -57,7 +57,7 @@ void kboot_init_globals() {
strcpy(DebugBootLevel, "#f"); // no specified level strcpy(DebugBootLevel, "#f"); // no specified level
strcpy(DebugBootMessage, "play"); // play mode, the default retail mode strcpy(DebugBootMessage, "play"); // play mode, the default retail mode
MasterExit = 0; MasterExit = RuntimeExitStatus::RUNNING;
MasterDebug = 1; MasterDebug = 1;
MasterUseKernel = 1; MasterUseKernel = 1;
DebugSegment = 1; DebugSegment = 1;
@ -144,7 +144,7 @@ s32 goal_main(int argc, const char* const* argv) {
void KernelCheckAndDispatch() { void KernelCheckAndDispatch() {
u64 goal_stack = u64(g_ee_main_mem) + EE_MAIN_MEM_SIZE - 8; u64 goal_stack = u64(g_ee_main_mem) + EE_MAIN_MEM_SIZE - 8;
while (!MasterExit) { while (MasterExit == RuntimeExitStatus::RUNNING) {
// try to get a message from the listener, and process it if needed // try to get a message from the listener, and process it if needed
Ptr<char> new_message = WaitForMessageAndAck(); Ptr<char> new_message = WaitForMessageAndAck();
if (new_message.offset) { if (new_message.offset) {
@ -198,5 +198,5 @@ void KernelCheckAndDispatch() {
* DONE, EXACT * DONE, EXACT
*/ */
void KernelShutdown() { void KernelShutdown() {
MasterExit = 2; // GOAL Kernel Dispatch loop will stop now. MasterExit = RuntimeExitStatus::EXIT; // GOAL Kernel Dispatch loop will stop now.
} }

View file

@ -22,6 +22,13 @@ struct MasterConfig {
u16 territory; // added. this is normally burnt onto the disc executable. u16 territory; // added. this is normally burnt onto the disc executable.
}; };
enum class RuntimeExitStatus {
RUNNING = 0,
RESTART_RUNTIME = 1,
EXIT = 2,
RESTART_IN_DEBUG = 3,
};
// Level to load on boot // Level to load on boot
extern char DebugBootLevel[64]; extern char DebugBootLevel[64];
@ -29,7 +36,7 @@ extern char DebugBootLevel[64];
extern char DebugBootMessage[64]; extern char DebugBootMessage[64];
// Set to 1 to kill GOAL kernel // Set to 1 to kill GOAL kernel
extern u32 MasterExit; extern RuntimeExitStatus MasterExit;
// Set to 1 to enable debug heap // Set to 1 to enable debug heap
extern u32 MasterDebug; extern u32 MasterDebug;

View file

@ -66,6 +66,7 @@ void ClearPending() {
if (size > 0) { if (size > 0) {
printf("%s", PrintBufArea.cast<char>().c() + sizeof(ListenerMessageHeader)); printf("%s", PrintBufArea.cast<char>().c() + sizeof(ListenerMessageHeader));
} }
clear_print();
} }
} else { } else {
if (ListenerStatus) { if (ListenerStatus) {
@ -134,10 +135,10 @@ void ProcessListenerMessage(Ptr<char> msg) {
printf("[ERROR] unsupported message kind LTT_MSG_PRINT_SYMBOLS (NYI)\n"); printf("[ERROR] unsupported message kind LTT_MSG_PRINT_SYMBOLS (NYI)\n");
break; break;
case LTT_MSG_RESET: case LTT_MSG_RESET:
MasterExit = 1; MasterExit = RuntimeExitStatus::RESTART_RUNTIME;
break; break;
case LTT_MSG_SHUTDOWN: case LTT_MSG_SHUTDOWN:
MasterExit = 2; MasterExit = RuntimeExitStatus::EXIT;
break; break;
case LTT_MSG_CODE: { case LTT_MSG_CODE: {
auto buffer = kmalloc(kdebugheap, MessCount, 0, "listener-link-block"); auto buffer = kmalloc(kdebugheap, MessCount, 0, "listener-link-block");

View file

@ -67,7 +67,7 @@ Timer ee_clock_timer;
u32 vif1_interrupt_handler = 0; u32 vif1_interrupt_handler = 0;
void kmachine_init_globals() { void kmachine_init_globals() {
isodrv = iso_cd; isodrv = fakeiso; // changed. fakeiso is the only one that works in opengoal.
modsrc = 1; modsrc = 1;
reboot = 1; reboot = 1;
memset(pad_dma_buf, 0, sizeof(pad_dma_buf)); memset(pad_dma_buf, 0, sizeof(pad_dma_buf));
@ -88,6 +88,8 @@ void InitParms(int argc, const char* const* argv) {
isodrv = fakeiso; isodrv = fakeiso;
modsrc = 0; modsrc = 0;
reboot = 0; reboot = 0;
DebugSegment = 0;
MasterDebug = 0;
} }
for (int i = 1; i < argc; i++) { for (int i = 1; i < argc; i++) {
@ -367,9 +369,10 @@ int InitMachine() {
// MsgErr("dkernel: !init pad\n"); // MsgErr("dkernel: !init pad\n");
// } // }
if (MasterDebug) { // connect to GOAL compiler // do this always
InitGoalProto(); // if (MasterDebug) { // connect to GOAL compiler
} InitGoalProto();
//}
lg::info("InitSound"); lg::info("InitSound");
InitSound(); // do nothing! InitSound(); // do nothing!
@ -983,7 +986,7 @@ void InitMachine_PCPort() {
void vif_interrupt_callback() { void vif_interrupt_callback() {
// added for the PC port for faking VIF interrupts from the graphics system. // added for the PC port for faking VIF interrupts from the graphics system.
if (vif1_interrupt_handler && MasterExit == 0) { if (vif1_interrupt_handler && MasterExit == RuntimeExitStatus::RUNNING) {
call_goal(Ptr<Function>(vif1_interrupt_handler), 0, 0, 0, s7.offset, g_ee_main_mem); call_goal(Ptr<Function>(vif1_interrupt_handler), 0, 0, 0, s7.offset, g_ee_main_mem);
} }
} }

View file

@ -94,12 +94,35 @@ int main(int argc, char** argv) {
setup_logging(verbose); setup_logging(verbose);
bool force_debug_next_time = false;
while (true) { while (true) {
std::vector<std::string> args;
for (int i = 0; i < argc; i++) {
args.push_back(argv[i]);
}
if (force_debug_next_time) {
args.push_back("-boot");
args.push_back("-debug");
force_debug_next_time = false;
}
std::vector<char*> ptrs;
for (auto& str : args) {
ptrs.push_back(str.data());
}
// run the runtime in a loop so we can reset the game and have it restart cleanly // run the runtime in a loop so we can reset the game and have it restart cleanly
lg::info("OpenGOAL Runtime {}.{}", versions::GOAL_VERSION_MAJOR, versions::GOAL_VERSION_MINOR); lg::info("OpenGOAL Runtime {}.{}", versions::GOAL_VERSION_MAJOR, versions::GOAL_VERSION_MINOR);
auto exit_status = exec_runtime(ptrs.size(), ptrs.data());
if (exec_runtime(argc, argv) == 2) { switch (exit_status) {
return 0; case RuntimeExitStatus::EXIT:
return 0;
case RuntimeExitStatus::RESTART_RUNTIME:
case RuntimeExitStatus::RUNNING:
break;
case RuntimeExitStatus::RESTART_IN_DEBUG:
force_debug_next_time = true;
break;
} }
} }
return 0; return 0;

View file

@ -273,7 +273,7 @@ void dmac_runner(SystemThreadInterface& iface) {
* Main function to launch the runtime. * Main function to launch the runtime.
* GOAL kernel arguments are currently ignored. * GOAL kernel arguments are currently ignored.
*/ */
u32 exec_runtime(int argc, char** argv) { RuntimeExitStatus exec_runtime(int argc, char** argv) {
g_argc = argc; g_argc = argc;
g_argv = argv; g_argv = argv;
g_main_thread_id = std::this_thread::get_id(); g_main_thread_id = std::this_thread::get_id();
@ -315,17 +315,17 @@ u32 exec_runtime(int argc, char** argv) {
// step 3: start the EE! // step 3: start the EE!
iop_thread.start(iop_runner); iop_thread.start(iop_runner);
ee_thread.start(ee_runner); ee_thread.start(ee_runner);
deci_thread.start(deci2_runner); deci_thread.start(deci2_runner);
if (VM::use) { if (VM::use) {
vm_dmac_thread.start(dmac_runner); vm_dmac_thread.start(dmac_runner);
} else {
vm_dmac_thread.start(null_runner);
} }
// step 4: wait for EE to signal a shutdown. meanwhile, run video loop on main thread. // step 4: wait for EE to signal a shutdown. meanwhile, run video loop on main thread.
// TODO relegate this to its own function // TODO relegate this to its own function
if (enable_display) { if (enable_display) {
Gfx::Loop([]() { return !MasterExit; }); Gfx::Loop([]() { return MasterExit == RuntimeExitStatus::RUNNING; });
Gfx::Exit(); Gfx::Exit();
} }

View file

@ -5,10 +5,13 @@
* Setup and launcher for the runtime. * Setup and launcher for the runtime.
*/ */
#include "common/common_types.h"
#include <thread> #include <thread>
#include "common/common_types.h"
#include "game/kernel/kboot.h"
extern u8* g_ee_main_mem; extern u8* g_ee_main_mem;
u32 exec_runtime(int argc, char** argv);
RuntimeExitStatus exec_runtime(int argc, char** argv);
extern std::thread::id g_main_thread_id; extern std::thread::id g_main_thread_id;

View file

@ -270,7 +270,7 @@
(defun execute-math-engine () (defun execute-math-engine ()
(#when PC_PORT (#when PC_PORT
(with-dma-buffer-add-bucket ((debug-buf (-> (current-frame) debug-buf)) (with-dma-buffer-add-bucket ((debug-buf (-> (current-frame) global-buf))
(bucket-id debug-no-zbuf)) (bucket-id debug-no-zbuf))
(when (-> *pc-settings* display-actor-counts) (when (-> *pc-settings* display-actor-counts)
(draw-string-xy (string-format "M: ~D/~D A: ~D" (-> *matrix-engine* length) MATRIX_ENGINE_AMOUNT (process-count *active-pool*)) debug-buf 8 (- 224 18) (font-color default) (font-flags shadow kerning)) (draw-string-xy (string-format "M: ~D/~D A: ~D" (-> *matrix-engine* length) MATRIX_ENGINE_AMOUNT (process-count *active-pool*)) debug-buf 8 (- 224 18) (font-color default) (font-flags shadow kerning))

View file

@ -119,7 +119,7 @@
;; function to call in the main loop to run the debug menu ;; function to call in the main loop to run the debug menu
(declare-type debug-menu-context basic) (declare-type debug-menu-context basic)
(define-extern *menu-hook* (function debug-menu-context)) (define *menu-hook* (the (function debug-menu-context) nothing))
;; function to call in the main loop to run the progress menu ;; function to call in the main loop to run the progress menu
(define *progress-hook* nothing) (define *progress-hook* nothing)

View file

@ -671,7 +671,7 @@
(with-profiler "menu" (with-profiler "menu"
(with-pc (with-pc
(if (-> *pc-settings* display-sha) (if (and (-> *pc-settings* display-sha) *debug-segment*)
(draw-build-revision))) (draw-build-revision)))
(*menu-hook*) (*menu-hook*)

View file

@ -568,9 +568,11 @@
(set! (-> self spool-name) (-> *art-control* active-stream)) (set! (-> self spool-name) (-> *art-control* active-stream))
(set! (-> self cur-channel) (pc-subtitle-channel movie)) (set! (-> self cur-channel) (pc-subtitle-channel movie))
(with-proc ((handle->process (-> *art-control* spool-lock))) (with-proc ((handle->process (-> *art-control* spool-lock)))
(format *stdcon* "movie spool detected:~%~3L~A~0L~%current spool frame is ~3L~D~0L~%" (if *debug-segment*
(-> *art-control* active-stream) (the int (ja-aframe-num 0))) (format *stdcon* "movie spool detected:~%~3L~A~0L~%current spool frame is ~3L~D~0L~%"
) (-> *art-control* active-stream) (the int (ja-aframe-num 0)))
)
)
) )
(*hint-semaphore* (*hint-semaphore*
;; there's a hint playing ;; there's a hint playing
@ -581,11 +583,13 @@
(set! (-> self cur-channel) (if (-> self spool-name) (set! (-> self cur-channel) (if (-> self spool-name)
(pc-subtitle-channel hint-named) (pc-subtitle-channel hint-named)
(pc-subtitle-channel hint))) (pc-subtitle-channel hint)))
(format *stdcon* "hint detected!~%~3L~A~0L/~3L#x~X~0L~%current str pos is ~D (~3L~D~0L)~%" (if *debug-segment*
(-> self spool-name) (-> self text-id) (format *stdcon* "hint detected!~%~3L~A~0L/~3L#x~X~0L~%current str pos is ~D (~3L~D~0L)~%"
(current-str-pos (-> *hint-semaphore* 0 sound-id)) (-> self spool-name) (-> self text-id)
(subtitle-str-adjust (current-str-pos (-> *hint-semaphore* 0 sound-id)))) (current-str-pos (-> *hint-semaphore* 0 sound-id))
) (subtitle-str-adjust (current-str-pos (-> *hint-semaphore* 0 sound-id))))
)
)
) )
;; do subtitles ;; do subtitles