Skip to content

Commit

Permalink
LYNX: Redirect printfs to rg_system_log so they can appear in crash.log
Browse files Browse the repository at this point in the history
  • Loading branch information
ducalex committed Mar 9, 2022
1 parent 2846b36 commit 32e2dba
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 54 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Retro-Go 1.31.1 (2022-03-08)
- All: Fixed sound on MRGC-G32


# Retro-Go 1.31 (2022-02-15)
- Launcher: Fixed occasional crash when changing tab
- GBC: Fixed high cpu usage / slowdowns
Expand Down
6 changes: 1 addition & 5 deletions handy-go/components/handy/c65c02.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,6 @@ class C65C02
// mPC=CPU_PEEKW(NMI_VECTOR);
// }

// fprintf(stderr, "cpu update\n");

if(gSystemIRQ && !mI)
{
TRACE_CPU1("Update() IRQ taken at PC=%04x",mPC);
Expand Down Expand Up @@ -1756,9 +1754,7 @@ class C65C02

inline void xILLEGAL(void)
{
//char addr[1024];
//sprintf(addr,"C65C02::Update() - Illegal opcode (%02x) at PC=$%04x.",mOpcode,mPC);
fprintf(stderr, "C65C02::Update() - Illegal opcode (%02x) at PC=$%04x.",mOpcode,mPC);
log_printf("CPU: Illegal opcode $%02x at PC=$%04x.\n", mOpcode, mPC);
}

private:
Expand Down
9 changes: 4 additions & 5 deletions handy-go/components/handy/cart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@

//#define TRACE_CART

#include <rg_system.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
Expand Down Expand Up @@ -79,14 +78,14 @@ CCart::CCart(UBYTE *gamedata,ULONG gamesize)
if(mFileHeader.magic[0]!='L' || mFileHeader.magic[1]!='Y' || mFileHeader.magic[2]!='N'
|| mFileHeader.magic[3]!='X' || mFileHeader.version!=1) {

fprintf(stderr, "Invalid cart (no header?).\nGuessing a ROM layout...\n");
log_printf("Invalid cart (magic number).\n");
strncpy((char*)&mFileHeader.cartname,"NO HEADER",32);
strncpy((char*)&mFileHeader.manufname,"HANDY",16);
mFileHeader.page_size_bank0=gamesize>>8;// Hard workaround...
} else {
headersize=sizeof(LYNX_HEADER);
mCRC32=crc32_le(0, gamedata+headersize, gamesize-headersize);
printf("Cart '%s' loaded, CRC32=%08X\n", mFileHeader.cartname, mCRC32);
log_printf("Cart '%s' loaded, CRC32=%08X\n", mFileHeader.cartname, mCRC32);
}

// As this is a cartridge boot unset the boot address
Expand Down Expand Up @@ -123,7 +122,7 @@ CCart::CCart(UBYTE *gamedata,ULONG gamesize)
mCountMask0=0x7ff;
break;
default:
fprintf(stderr, "Invalid cart (bank0 size).\n");
log_printf("Invalid cart (bank0 size = %06x).\n", mFileHeader.page_size_bank0);
break;
}
TRACE_CART1("CCart() - Bank0 = $%06x",mMaskBank0);
Expand Down Expand Up @@ -158,7 +157,7 @@ CCart::CCart(UBYTE *gamedata,ULONG gamesize)
mCountMask1=0x7ff;
break;
default:
fprintf(stderr, "Invalid cart (bank1 size).\n");
log_printf("Invalid cart (bank1 size = %06x).\n", mFileHeader.page_size_bank1);
break;
}
TRACE_CART1("CCart() - Bank1 = $%06x",mMaskBank1);
Expand Down
21 changes: 10 additions & 11 deletions handy-go/components/handy/eeprom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void CEEPROM::Load(void)
if(!Available()) return;
FILE *fe;
if((fe=fopen(filename,"rb"))!=NULL){
printf("EEPROM LOAD %s\n",filename);
log_printf("EEPROM: Loading from '%s'\n",filename);
fread(romdata,1,1024,fe);
fclose(fe);
}
Expand All @@ -55,7 +55,7 @@ void CEEPROM::Save(void)
if(!Available()) return;
FILE *fe;
if((fe=fopen(filename,"wb+"))!=NULL){
printf("EEPROM SAVE %s\n",filename);
log_printf("EEPROM: Saving to '%s'\n",filename);
fwrite(romdata,1,Size(),fe);
fclose(fe);
}
Expand Down Expand Up @@ -111,55 +111,54 @@ bool CEEPROM::ContextLoad(LSS_FILE *fp)
void CEEPROM::SetEEPROMType(UBYTE b)
{
type=b;
printf("\nEEPROM: ");
const char *type = "none";
switch(b&0x7) {
case 1: // 93C46 , 8 bit mode
ADDR_MASK = 0x7F;
CMD_BITS = 10;
ADDR_BITS = 7;
printf("93C46 ");
type = "93C46";
break;
case 2: // 93C56 , 8 bit mode
ADDR_MASK = 0xFF;
CMD_BITS = 12;
ADDR_BITS = 9;
printf("93C56 ");
type = "93C56";
break;
case 3: // 93C66 , 8 bit mode
ADDR_MASK = 0x1FF;
CMD_BITS = 12;
ADDR_BITS = 9;
printf("93C66 ");
type = "93C66";
break;
case 4: // 93C76 , 8 bit mode
ADDR_MASK = 0x3FF;
CMD_BITS = 14;
ADDR_BITS = 11;
printf("93C76 ");
type = "93C76";
break;
case 5: // 93C86 , 8 bit mode
ADDR_MASK = 0x7FF;
CMD_BITS = 14;
ADDR_BITS = 11;
printf("93C86 ");
type = "93C86";
break;
case 0: // NONE, fallthrou
default:
ADDR_MASK = 0;
CMD_BITS = 1;
ADDR_BITS = 1;
printf("none ");
break;
}
if(b&0x80) { // 8 bit access
DONE_MASK = 0x100;
printf("8 bit\n");
log_printf("EEPROM: Type: %s 8bit\n", type);
} else { // 16 bit access
ADDR_MASK>>=1;
CMD_BITS--;
ADDR_BITS--;
DONE_MASK = 0x10000;
printf("16 bit\n");
log_printf("EEPROM: Type: %s 16bit\n", type);
}
}

Expand Down
14 changes: 2 additions & 12 deletions handy-go/components/handy/mikie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,6 @@ static inline ULONG GetLfsrNext(ULONG current)
#endif
}

void CMikie::BlowOut(void)
{
C6502_REGS regs;
mSystem.mCpu->GetRegs(regs);
printf("Runtime Error - System Halted\nCMikie::Poke() - Read/Write to counter clocks at PC=$%04x.\n",regs.PC);
gSystemHalt=TRUE;
abort();
}


CMikie::CMikie(CSystem& parent, ULONG displayformat, ULONG samplerate)
:mSystem(parent)
Expand Down Expand Up @@ -1573,7 +1564,7 @@ void CMikie::Poke(ULONG addr,UBYTE data)
if(!(data&0x02)) {
C6502_REGS regs;
mSystem.mCpu->GetRegs(regs);
printf("Runtime Alert - System Halted\nCMikie::Poke(SYSCTL1) - Lynx power down occurred at PC=$%04x.\nResetting system.\n",regs.PC);
log_printf("CMikie::Poke(SYSCTL1) - Lynx power down occurred at PC=$%04x.\nResetting system.\n", regs.PC);
mSystem.Reset();
gSystemHalt=TRUE;
}
Expand Down Expand Up @@ -1701,7 +1692,7 @@ void CMikie::Poke(ULONG addr,UBYTE data)
case 0xFE19+3: mSystem.HLE_BIOS_FE19(); break;
case 0xFE4A+3: mSystem.HLE_BIOS_FE4A(); break;
case 0xFF80+3: mSystem.HLE_BIOS_FF80(); break;
default: printf("ROM code missing...\n");
default: log_printf("BIOS: Missing function $%04X\n", mSystem.mCpu->GetPC());
}
break;
case (GREEN0&0xff):
Expand Down Expand Up @@ -3023,7 +3014,6 @@ inline void CMikie::Update(void)
UpdateSound();
}

// printf("CMikie::Update() - gSystemCycleCount==gNextTimerEvent, system lock likely\n");
// TRACE_MIKIE1("Update() - NextTimerEvent = %012d",gNextTimerEvent);

// Update system IRQ status as a result of timer activity
Expand Down
2 changes: 1 addition & 1 deletion handy-go/components/handy/ram.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class CRam : public CLynxBase
memcpy(&mFileHeader, filememory, sizeof(HOME_HEADER));
if(mFileHeader.magic[0]!='B' || mFileHeader.magic[1]!='S' ||
mFileHeader.magic[2]!='9' || mFileHeader.magic[3]!='3') {
fprintf(stderr, "Invalid cart.\n");
log_printf("Invalid cart (header).\n");
} else {
#ifndef MSB_FIRST
mFileHeader.load_address = mFileHeader.load_address<<8 | mFileHeader.load_address>>8;
Expand Down
4 changes: 2 additions & 2 deletions handy-go/components/handy/susie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@ ULONG CSusie::PaintSprites(void)
// Perform Sprite debugging if required, single step on sprite draw
if(gSingleStepModeSprites) {
// char message[256];
//sprintf("CSusie:PaintSprites() - Rendered Sprite %03d\n",sprcount);
//log_printf("CSusie:PaintSprites() - Rendered Sprite %03d\n",sprcount);
//SingleStepModeSprites=0;
}
} else {
Expand All @@ -1030,7 +1030,7 @@ ULONG CSusie::PaintSprites(void)
// Stop the system, otherwise we may just come straight back in.....
gSystemHalt=TRUE;
// Display warning message
printf("CSusie:PaintSprites(): Single draw sprite limit exceeded (>4096). The SCB is most likely looped back on itself. Reset/Exit is recommended\n");
log_printf("CSusie:PaintSprites(): Single draw sprite limit exceeded (>4096). The SCB is most likely looped back on itself. Reset/Exit is recommended\n");
// Signal error to the caller
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion handy-go/components/handy/susie.h
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ class CSusie : public CLynxBase

if(voff>101)
{
printf("CSusie::LineInit() Out of bounds (voff)\n");
log_printf("CSusie::LineInit() Out of bounds (voff)\n");
voff=0;
}

Expand Down
22 changes: 11 additions & 11 deletions handy-go/components/handy/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,12 @@ CSystem::CSystem(const char* gamefile, long displayformat, long samplerate)
filememory=(UBYTE*) new UBYTE[filesize];

if(fread(filememory, 1, filesize,fp)!=filesize) {
fprintf(stderr, "Invalid Cart (filesize).\n");
log_printf("Invalid cart (filesize).\n");
}

fclose(fp);
} else {
fprintf(stderr, "Invalid Cart.\n");
log_printf("Invalid cart (fopen failed).\n");
}

// Now try and determine the filetype we have opened
Expand All @@ -164,10 +164,10 @@ CSystem::CSystem(const char* gamefile, long displayformat, long samplerate)
if(!strcmp(&clip[6],"BS93")) mFileType=HANDY_FILETYPE_HOMEBREW;
else if(!strcmp(&clip[0],"LYNX")) mFileType=HANDY_FILETYPE_LNX;
else if(filesize==128*1024 || filesize==256*1024 || filesize==512*1024) {
fprintf(stderr, "Invalid Cart (type). but 128/256/512k size -> set to RAW and try to load raw rom image\n");
log_printf("Invalid cart (type). but 128/256/512k size -> set to RAW and try to load raw rom image\n");
mFileType=HANDY_FILETYPE_RAW;
} else {
fprintf(stderr, "Invalid Cart (type). -> set to RAW and try to load raw rom image\n");
log_printf("Invalid cart (type). -> set to RAW and try to load raw rom image\n");
mFileType=HANDY_FILETYPE_RAW;
}
}
Expand Down Expand Up @@ -420,10 +420,10 @@ bool CSystem::ContextLoad(LSS_FILE *fp)
ULONG checksum;
// Read CRC32 and check against the CART for a match
lss_read(&checksum,sizeof(ULONG),1,fp);
// if(mCart->CRC32()!=checksum) {
// fprintf(stderr, "[handy]LSS Snapshot CRC does not match the loaded cartridge image, aborting load.\n");
// return 0;
// }
if(mCart->CRC32()!=checksum) {
log_printf("CSystem::ContextLoad() LSS Snapshot CRC does not match the loaded cartridge image...\n");
// return 0;
}

// Check our block header
if(!lss_read(teststr,sizeof(char),20,fp)) status=0;
Expand Down Expand Up @@ -462,7 +462,7 @@ bool CSystem::ContextLoad(LSS_FILE *fp)

gAudioBufferPointer = 0;
} else {
fprintf(stderr, "[handy]Not a recognised LSS file\n");
log_printf("CSystem::ContextLoad() Not a recognised LSS file!\n");
}

return status;
Expand All @@ -475,7 +475,7 @@ void CSystem::DebugTrace(int address)
char message[1024+1];
int count=0;

sprintf(message,"%08x - DebugTrace(): ",gSystemCycleCount);
log_printf(message,"%08x - DebugTrace(): ",gSystemCycleCount);
count=strlen(message);

if(address) {
Expand All @@ -484,7 +484,7 @@ void CSystem::DebugTrace(int address)
char linetext[1024];
// Register dump
mCpu->GetRegs(regs);
sprintf(linetext,"PC=$%04x SP=$%02x PS=0x%02x A=0x%02x X=0x%02x Y=0x%02x",regs.PC,regs.SP, regs.PS,regs.A,regs.X,regs.Y);
log_printf(linetext,"PC=$%04x SP=$%02x PS=0x%02x A=0x%02x X=0x%02x Y=0x%02x",regs.PC,regs.SP, regs.PS,regs.A,regs.X,regs.Y);
strcat(message,linetext);
count=strlen(message);
} else {
Expand Down
14 changes: 8 additions & 6 deletions handy-go/components/handy/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ typedef uint32_t ULONG;
#define FALSE false
#endif

#include "lynxbase.h"

#define HANDY_SYSTEM_FREQ 16000000
#define HANDY_TIMER_FREQ 20
#define HANDY_AUDIO_SAMPLE_FREQ 24000 // 48000
Expand Down Expand Up @@ -139,6 +137,14 @@ extern UBYTE *gPrimaryFrameBuffer;
#define lss_write(s, vs, vc, fp) (fwrite(s, vs, vc, fp) > 0)
#define lss_printf(fp, str) (fputs(str, fp) >= 0)

//
// Define logging functions
//

#include <rg_system.h>
// #define log_printf(x...) printf(x)
#define log_printf(x...) rg_system_log(RG_LOG_USER, NULL, x)


//
// Define the interfaces before we start pulling in the classes
Expand Down Expand Up @@ -185,7 +191,6 @@ class CSystem : public CSystemBase

inline void Update(void)
{
// fprintf(stderr, "sys update\n");
//
// Only update if there is a predicted timer event
//
Expand All @@ -197,7 +202,6 @@ class CSystem : public CSystemBase
// Step the processor through 1 instruction
//
mCpu->Update();
// fprintf(stderr, "end cpu update\n");

#ifdef _LYNXDBG
// Check breakpoint
Expand All @@ -216,8 +220,6 @@ class CSystem : public CSystemBase
{
gSystemCycleCount=gNextTimerEvent;
}

// fprintf(stderr, "end sys update\n");
}

inline void UpdateFrame(bool draw)
Expand Down

0 comments on commit 32e2dba

Please sign in to comment.