mirror of
https://github.com/mlaux/gb6.git
synced 2026-04-21 16:16:56 +00:00
split out debug logging
This commit is contained in:
@@ -8,7 +8,6 @@
|
||||
#include "mbc.h"
|
||||
#include "types.h"
|
||||
#include "bootstrap.h"
|
||||
#include "platform.h"
|
||||
|
||||
void dmg_new(struct dmg *dmg, struct cpu *cpu, struct rom *rom, struct lcd *lcd)
|
||||
{
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
/* platform.h - Platform abstraction for GB emulator */
|
||||
|
||||
#ifndef PLATFORM_H
|
||||
#define PLATFORM_H
|
||||
|
||||
/*
|
||||
* Set the status bar text displayed below the LCD.
|
||||
* On System 6, this replaces the FPS counter.
|
||||
* On CLI/ImGui, this is a no-op (debug info shown elsewhere).
|
||||
*/
|
||||
void set_status_bar(const char *str);
|
||||
|
||||
#endif
|
||||
@@ -24,6 +24,7 @@ add_application(Emulator
|
||||
../compiler/reg_loads.c
|
||||
../compiler/alu.c
|
||||
dialogs.c
|
||||
debug.c
|
||||
dispatcher_asm.c
|
||||
jit.c
|
||||
input.c
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
#include <Files.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "debug.h"
|
||||
|
||||
static int debug_enabled = 1;
|
||||
|
||||
void debug_log_string(const char *str)
|
||||
{
|
||||
short fref;
|
||||
char buf[128];
|
||||
long len;
|
||||
OSErr err;
|
||||
err = FSOpen("\pjit_log.txt", 0, &fref);
|
||||
if (err == fnfErr) {
|
||||
Create("\pjit_log.txt", 0, 'ttxt', 'TEXT');
|
||||
err = FSOpen("\pjit_log.txt", 0, &fref);
|
||||
}
|
||||
if (err != noErr) return;
|
||||
// Seek to end
|
||||
SetFPos(fref, fsFromLEOF, 0);
|
||||
len = strlen(str);
|
||||
FSWrite(fref, &len, str);
|
||||
buf[0] = '\n';
|
||||
len = 1;
|
||||
FSWrite(fref, &len, buf);
|
||||
|
||||
FSClose(fref);
|
||||
}
|
||||
|
||||
// this tries to avoid losing data on crash by opening the file every time,
|
||||
// but it doesn't really work
|
||||
void debug_log_block(struct code_block *block)
|
||||
{
|
||||
short fref;
|
||||
char buf[128];
|
||||
long len;
|
||||
int k;
|
||||
OSErr err;
|
||||
|
||||
if (!debug_enabled) return;
|
||||
|
||||
err = FSOpen("\pjit_log.txt", 0, &fref);
|
||||
if (err == fnfErr) {
|
||||
Create("\pjit_log.txt", 0, 'ttxt', 'TEXT');
|
||||
err = FSOpen("\pjit_log.txt", 0, &fref);
|
||||
}
|
||||
if (err != noErr) return;
|
||||
|
||||
// Seek to end
|
||||
SetFPos(fref, fsFromLEOF, 0);
|
||||
|
||||
// Write block header
|
||||
sprintf(buf, "Block %04x->%04x (%d bytes):\n",
|
||||
block->src_address, block->end_address, (int) block->length);
|
||||
len = strlen(buf);
|
||||
FSWrite(fref, &len, buf);
|
||||
|
||||
// Write hex dump of generated code
|
||||
for (k = 0; k < block->length; k++) {
|
||||
sprintf(buf, "%02x", block->code[k]);
|
||||
len = 2;
|
||||
FSWrite(fref, &len, buf);
|
||||
if ((k & 15) == 15 || k == block->length - 1) {
|
||||
buf[0] = '\n';
|
||||
len = 1;
|
||||
FSWrite(fref, &len, buf);
|
||||
} else {
|
||||
buf[0] = ' ';
|
||||
len = 1;
|
||||
FSWrite(fref, &len, buf);
|
||||
}
|
||||
}
|
||||
|
||||
// Newline separator
|
||||
buf[0] = '\n';
|
||||
len = 1;
|
||||
FSWrite(fref, &len, buf);
|
||||
|
||||
FSClose(fref);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#ifndef _DEBUG_H
|
||||
#define _DEBUG_H
|
||||
|
||||
#include "compiler.h"
|
||||
|
||||
void debug_log_string(const char *str);
|
||||
|
||||
void debug_log_block(struct code_block *block);
|
||||
|
||||
#endif
|
||||
+2
-83
@@ -26,6 +26,7 @@
|
||||
#include "rom.h"
|
||||
#include "mbc.h"
|
||||
|
||||
#include "debug.h"
|
||||
#include "dialogs.h"
|
||||
#include "input.h"
|
||||
#include "lcd_mac.h"
|
||||
@@ -35,82 +36,6 @@
|
||||
|
||||
#include "compiler.h"
|
||||
|
||||
// Debug logging - open/close each time to avoid losing data on crash
|
||||
static int debug_enabled = 1;
|
||||
|
||||
void debug_log_string(const char *str)
|
||||
{
|
||||
short fref;
|
||||
char buf[128];
|
||||
long len;
|
||||
OSErr err;
|
||||
err = FSOpen("\pjit_log.txt", 0, &fref);
|
||||
if (err == fnfErr) {
|
||||
Create("\pjit_log.txt", 0, 'ttxt', 'TEXT');
|
||||
err = FSOpen("\pjit_log.txt", 0, &fref);
|
||||
}
|
||||
if (err != noErr) return;
|
||||
// Seek to end
|
||||
SetFPos(fref, fsFromLEOF, 0);
|
||||
len = strlen(str);
|
||||
FSWrite(fref, &len, str);
|
||||
buf[0] = '\n';
|
||||
len = 1;
|
||||
FSWrite(fref, &len, buf);
|
||||
|
||||
FSClose(fref);
|
||||
}
|
||||
|
||||
static void debug_log_block(struct code_block *block)
|
||||
{
|
||||
short fref;
|
||||
char buf[128];
|
||||
long len;
|
||||
int k;
|
||||
OSErr err;
|
||||
|
||||
if (!debug_enabled) return;
|
||||
|
||||
err = FSOpen("\pjit_log.txt", 0, &fref);
|
||||
if (err == fnfErr) {
|
||||
Create("\pjit_log.txt", 0, 'ttxt', 'TEXT');
|
||||
err = FSOpen("\pjit_log.txt", 0, &fref);
|
||||
}
|
||||
if (err != noErr) return;
|
||||
|
||||
// Seek to end
|
||||
SetFPos(fref, fsFromLEOF, 0);
|
||||
|
||||
// Write block header
|
||||
sprintf(buf, "Block %04x->%04x (%d bytes):\n",
|
||||
block->src_address, block->end_address, (int) block->length);
|
||||
len = strlen(buf);
|
||||
FSWrite(fref, &len, buf);
|
||||
|
||||
// Write hex dump of generated code
|
||||
for (k = 0; k < block->length; k++) {
|
||||
sprintf(buf, "%02x", block->code[k]);
|
||||
len = 2;
|
||||
FSWrite(fref, &len, buf);
|
||||
if ((k & 15) == 15 || k == block->length - 1) {
|
||||
buf[0] = '\n';
|
||||
len = 1;
|
||||
FSWrite(fref, &len, buf);
|
||||
} else {
|
||||
buf[0] = ' ';
|
||||
len = 1;
|
||||
FSWrite(fref, &len, buf);
|
||||
}
|
||||
}
|
||||
|
||||
// Newline separator
|
||||
buf[0] = '\n';
|
||||
len = 1;
|
||||
FSWrite(fref, &len, buf);
|
||||
|
||||
FSClose(fref);
|
||||
}
|
||||
|
||||
// Called by dmg.c when ROM bank switches
|
||||
static void on_rom_bank_switch(int new_bank)
|
||||
{
|
||||
@@ -175,7 +100,7 @@ static pascal void interrupt_tm_proc(void)
|
||||
);
|
||||
|
||||
jit_ctx.interrupt_check = 1;
|
||||
PrimeTime((QElemPtr)&interrupt_tm.task, INTERRUPT_PERIOD);
|
||||
PrimeTime((QElemPtr) &interrupt_tm.task, INTERRUPT_PERIOD);
|
||||
|
||||
asm volatile(
|
||||
"move.l (%%sp)+, %%a5\n\t"
|
||||
@@ -232,9 +157,6 @@ void set_status_bar(const char *str)
|
||||
DrawString(pstr);
|
||||
}
|
||||
|
||||
// -- JIT EXECUTION --
|
||||
|
||||
|
||||
void StartEmulation(void)
|
||||
{
|
||||
if (g_wp) {
|
||||
@@ -322,8 +244,6 @@ int LoadRom(Str63 fileName, short vRefNum)
|
||||
return true;
|
||||
}
|
||||
|
||||
// -- EVENT FUNCTIONS --
|
||||
|
||||
void OnMenuAction(long action)
|
||||
{
|
||||
short menu, item;
|
||||
@@ -470,7 +390,6 @@ static int CheckFinderFiles(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// -- ENTRY POINT --
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
unsigned int frame_count = 0;
|
||||
|
||||
+1
-1
@@ -36,6 +36,6 @@
|
||||
|
||||
int LoadRom(Str63, short);
|
||||
|
||||
#include "platform.h"
|
||||
void set_status_bar(const char *str);
|
||||
|
||||
#endif
|
||||
@@ -1,48 +0,0 @@
|
||||
data 'ICON' (128) {
|
||||
$"07FF FFE0 0FFF FFF0 0A00 0050 0A0F FE50" /* ...........P...P */
|
||||
$"0A10 0150 0AD1 1150 0AD1 1150 0A11 1150" /* ...P.—.P.—.P...P */
|
||||
$"0A10 0150 0A12 0950 0A11 F150 0A10 0150" /* ...P..∆P...P...P */
|
||||
$"0A0F FE50 0A00 0050 09FF FF90 0800 0010" /* ...P...P∆..ê.... */
|
||||
$"0870 0010 0870 0010 0870 01D0 0BFE 01D0" /* .p...p...p.–...– */
|
||||
$"0BFE 01D0 0BFE 1C10 0870 1C10 0870 1C10" /* ...–.....p...p.. */
|
||||
$"0870 0010 0800 0010 0800 0010 0800 0010" /* .p.............. */
|
||||
$"0807 3820 080E 7020 0800 00C0 07FF FF00" /* ..8 ..p ...¿.... */
|
||||
};
|
||||
|
||||
data 'ICON' (130) {
|
||||
$"0000 0000 0000 0000 00AA A800 00AA A800" /* .........™®..™®. */
|
||||
$"01FF FC00 07FF FF00 01BF FC00 07FF FF00" /* .........ø...... */
|
||||
$"01FF FC00 07FF FF00 01FF 8000 07FE 7F00" /* ..........Ä..... */
|
||||
$"01FD 9CC0 07FA 3E20 01FA 0020 07FB 80E0" /* ..ú¿..> ... ..Ä. */
|
||||
$"01FA 7F20 07FA 0020 01FA 0820 00AA 1C20" /* ... ... ... .™. */
|
||||
$"00AA 0820 0002 0020 0002 0020 0002 0020" /* .™. ... ... ... */
|
||||
$"0002 0020 0002 0020 0002 1C20 0002 0020" /* ... ... ... ... */
|
||||
$"0001 80C0 0000 7F00 0000 0000 0000 0000" /* ..Ä¿............ */
|
||||
};
|
||||
|
||||
data 'ICON' (129) {
|
||||
$"0000 0000 0FFF FFC0 1000 0040 1F3F FCF8" /* .......¿...@.?.. */
|
||||
$"1040 0208 1E40 0278 1040 0208 1F3F FCF8" /* .@...@.x.@...?.. */
|
||||
$"1000 0008 11FF FF88 1340 0348 12C0 02C8" /* .......à.@.H.¿.» */
|
||||
$"1340 0348 12C0 02C8 1340 0348 12C0 02C8" /* .@.H.¿.».@.H.¿.» */
|
||||
$"1340 0348 12C0 02C8 1340 0348 12C0 02C8" /* .@.H.¿.».@.H.¿.» */
|
||||
$"1340 0348 12C0 02C8 1340 0348 12C0 02C8" /* .@.H.¿.».@.H.¿.» */
|
||||
$"1340 0348 12C0 02C8 11FF FF88 1000 0008" /* .@.H.¿.»...à.... */
|
||||
$"1001 C008 1000 8008 1000 0008 0FFF FFF0" /* ..¿...Ä......... */
|
||||
};
|
||||
|
||||
data 'ICON' (131) {
|
||||
$"0FFF FE00 0800 0300 0855 4280 0855 4240" /* .........UBÄ.UB@ */
|
||||
$"08FF E220 0BFF FA10 08DF E3F8 0BFF F808" /* ... ............ */
|
||||
$"08FF E008 0BFF F808 08FF 0008 0BFC FE08" /* ................ */
|
||||
$"08FB 3988 0BF4 7C48 08F4 0048 0857 01C8" /* ..9à..|H...H.W.» */
|
||||
$"0854 FE48 0804 0048 0804 1048 0804 3848" /* .T.H...H...H..8H */
|
||||
$"0804 1048 0804 0048 0804 0048 0804 0048" /* ...H...H...H...H */
|
||||
$"0804 0048 0804 0048 0804 3848 0804 0048" /* ...H...H..8H...H */
|
||||
$"0803 0188 0800 FE08 0800 0008 0FFF FFF8" /* ...à............ */
|
||||
};
|
||||
|
||||
data 'SIZE' (128) {
|
||||
$"0080 0000 0800 0000 0400" /* .Ä........ */
|
||||
};
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@
|
||||
#include "dmg.h"
|
||||
#include "lru.h"
|
||||
#include "dispatcher_asm.h"
|
||||
#include "platform.h"
|
||||
#include "emulator.h"
|
||||
|
||||
#define CYCLES_PER_INTERRUPT 70224
|
||||
|
||||
|
||||
+1
-1
@@ -197,7 +197,7 @@ data 'SICN' (128) {
|
||||
};
|
||||
|
||||
data 'SIZE' (-1) {
|
||||
$"0080 0020 0000 0010 0000" /* .Ä. ...... */
|
||||
$"0080 0030 0000 0010 0000" /* .Ä. ...... */
|
||||
};
|
||||
|
||||
data 'ics#' (128) {
|
||||
|
||||
Reference in New Issue
Block a user