Debugging now uses a macro and trace statements
This commit is contained in:
parent
b594cd3998
commit
95e8b48dc0
5
Makefile
5
Makefile
@ -10,6 +10,7 @@ HEADERNAME = header
|
|||||||
LINK_FLAGS = -O1 -L$(ROOTDIR)/lib -L$(ROOTDIR)/mips64-elf/lib -ldragon -lmikmod -lmad -lyaml -lc -lm -ldragonsys -lnosys $(LIBS) -Tn64ld.x
|
LINK_FLAGS = -O1 -L$(ROOTDIR)/lib -L$(ROOTDIR)/mips64-elf/lib -ldragon -lmikmod -lmad -lyaml -lc -lm -ldragonsys -lnosys $(LIBS) -Tn64ld.x
|
||||||
PROG_NAME = menu
|
PROG_NAME = menu
|
||||||
CFLAGS = -std=gnu99 -march=vr4300 -mtune=vr4300 -O1 -I./inc -I$(ROOTDIR)/include -I$(ROOTDIR)/mips64-elf/include -lpthread -lrt -D_REENTRANT -DUSE_TRUETYPE
|
CFLAGS = -std=gnu99 -march=vr4300 -mtune=vr4300 -O1 -I./inc -I$(ROOTDIR)/include -I$(ROOTDIR)/mips64-elf/include -lpthread -lrt -D_REENTRANT -DUSE_TRUETYPE
|
||||||
|
CFLAGS += $(SET_DEBUG)
|
||||||
ASFLAGS = -mtune=vr4300 -march=vr4300
|
ASFLAGS = -mtune=vr4300 -march=vr4300
|
||||||
CC = $(GCCN64PREFIX)gcc
|
CC = $(GCCN64PREFIX)gcc
|
||||||
AS = $(GCCN64PREFIX)as
|
AS = $(GCCN64PREFIX)as
|
||||||
@ -34,5 +35,9 @@ test.dfs:
|
|||||||
|
|
||||||
all: $(PROG_NAME).v64
|
all: $(PROG_NAME).v64
|
||||||
|
|
||||||
|
debug: $(PROG_NAME).v64
|
||||||
|
|
||||||
|
debug: SET_DEBUG=-DDEBUG
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f *.v64 *.elf *.o *.bin *.dfs
|
rm -f *.v64 *.elf *.o *.bin *.dfs
|
||||||
|
26
inc/debug.h
Normal file
26
inc/debug.h
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
#define TRACEF(disp, text, ...) dbg_printf(disp, text, __VA_ARGS__);
|
||||||
|
#define TRACE(disp, text) printText(text, 3, -1, disp);
|
||||||
|
#else
|
||||||
|
#define TRACEF(disp, text, ...) do { if (0) dbg_printf(disp, text, __VA_ARGS__); } while (0)
|
||||||
|
#define TRACE(disp, text) do { if (0) printText(text, 3, -1, disp); } while (0)
|
||||||
|
#endif /* DEBUG */
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
void dbg_printf(display_context_t disp, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
char buf[32];
|
||||||
|
setbuf(stderr, buf);
|
||||||
|
|
||||||
|
va_list args;
|
||||||
|
va_start(args, fmt);
|
||||||
|
vfprintf(stderr, fmt, args);
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
|
u8 tmp[32];
|
||||||
|
sprintf(tmp, "%s", buf);
|
||||||
|
printText(tmp, 3, -1, disp);
|
||||||
|
}
|
@ -63,11 +63,6 @@ void drawRomConfigBox(display_context_t disp,int line);
|
|||||||
#define ishexchar(c) (((c >= '0') && (c <= '9')) || ((c >= 'A') && (c <= 'F')) || ((c >= 'a') && (c <= 'f')))
|
#define ishexchar(c) (((c >= '0') && (c <= '9')) || ((c >= 'A') && (c <= 'F')) || ((c >= 'a') && (c <= 'f')))
|
||||||
|
|
||||||
|
|
||||||
//debug flag to enable some debug outputs
|
|
||||||
///////////////////////////////////////////
|
|
||||||
#define DBG_MODE 0
|
|
||||||
///////////////////////////////////////////
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Return the uncached memory address of a cached address
|
* @brief Return the uncached memory address of a cached address
|
||||||
*
|
*
|
||||||
|
167
menu.c
167
menu.c
@ -39,6 +39,9 @@
|
|||||||
#include <mikmod.h>
|
#include <mikmod.h>
|
||||||
#include "mp3.h"
|
#include "mp3.h"
|
||||||
|
|
||||||
|
//debug
|
||||||
|
#include "debug.h"
|
||||||
|
|
||||||
// YAML parser
|
// YAML parser
|
||||||
#include <yaml.h>
|
#include <yaml.h>
|
||||||
|
|
||||||
@ -103,7 +106,6 @@ typedef struct
|
|||||||
|
|
||||||
volatile u32 *romaddr_ptr = (u32 *) ROM_ADDR;
|
volatile u32 *romaddr_ptr = (u32 *) ROM_ADDR;
|
||||||
unsigned int gBootCic=CIC_6102;
|
unsigned int gBootCic=CIC_6102;
|
||||||
u8 debug=DBG_MODE;
|
|
||||||
|
|
||||||
static uint8_t mempak_data[128 * 256];
|
static uint8_t mempak_data[128 * 256];
|
||||||
static void *bg_buffer;
|
static void *bg_buffer;
|
||||||
@ -1163,8 +1165,7 @@ void loadrom(display_context_t disp, u8 *buff, int fast){
|
|||||||
sleep(10);
|
sleep(10);
|
||||||
sleep(1000); //needless waiting :>
|
sleep(1000); //needless waiting :>
|
||||||
|
|
||||||
if (debug)
|
TRACE(disp, "timing done");
|
||||||
printText("timing done", 3, -1, disp);
|
|
||||||
|
|
||||||
u8 tmp[32];
|
u8 tmp[32];
|
||||||
u8 filename[64];
|
u8 filename[64];
|
||||||
@ -1173,22 +1174,20 @@ void loadrom(display_context_t disp, u8 *buff, int fast){
|
|||||||
sprintf(filename, "%s",buff);
|
sprintf(filename, "%s",buff);
|
||||||
int swapped=0;
|
int swapped=0;
|
||||||
|
|
||||||
if (debug)
|
TRACE(disp, buff);
|
||||||
printText(buff, 3, -1, disp);
|
|
||||||
|
|
||||||
FatRecord rec_tmpf;
|
FatRecord rec_tmpf;
|
||||||
//not needed any longer :>
|
//not needed any longer :>
|
||||||
//file IS there, it's selected at this point
|
//file IS there, it's selected at this point
|
||||||
ok = fatFindRecord(filename, &rec_tmpf, 0);
|
ok = fatFindRecord(filename, &rec_tmpf, 0);
|
||||||
if (debug)
|
|
||||||
printText("found", 3, -1, disp);
|
TRACE(disp, "found");
|
||||||
|
|
||||||
u8 resp = 0;
|
u8 resp = 0;
|
||||||
|
|
||||||
resp = fatOpenFileByeName(filename, 0); //err if not found ^^
|
resp = fatOpenFileByeName(filename, 0); //err if not found ^^
|
||||||
|
|
||||||
if (debug)
|
TRACE(disp, "opened");
|
||||||
printText("opened", 3, -1, disp);
|
|
||||||
|
|
||||||
int mb = file.sec_available/2048;
|
int mb = file.sec_available/2048;
|
||||||
int file_sectors = file.sec_available;
|
int file_sectors = file.sec_available;
|
||||||
@ -1246,10 +1245,7 @@ void loadrom(display_context_t disp, u8 *buff, int fast){
|
|||||||
// cart was found, use CIC and SaveRAM type
|
// cart was found, use CIC and SaveRAM type
|
||||||
}
|
}
|
||||||
|
|
||||||
if (debug) {
|
TRACEF(disp, "Info: cic=%i save=%i", cic, save);
|
||||||
sprintf(tmp, "Info: cic=%i save=%i",cic,save);
|
|
||||||
printText(tmp, 3, -1, disp);
|
|
||||||
}
|
|
||||||
|
|
||||||
//new rom_config
|
//new rom_config
|
||||||
boot_cic=rom_config[1]+1;
|
boot_cic=rom_config[1]+1;
|
||||||
@ -1267,23 +1263,16 @@ void loadrom(display_context_t disp, u8 *buff, int fast){
|
|||||||
printText(tmp, 3, -1, disp);
|
printText(tmp, 3, -1, disp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (debug)
|
TRACE(disp, "enalbe sd_mode");
|
||||||
printText("enalbe sd_mode", 3, -1, disp);
|
|
||||||
|
|
||||||
resp = evd_isSDMode();
|
resp = evd_isSDMode();
|
||||||
|
|
||||||
if (debug) {
|
TRACEF(disp, "sdmode: %i", resp);
|
||||||
sprintf(tmp, "sdmode: %i",resp);
|
TRACEF(disp, "Size: %i", file.sec_available);
|
||||||
printText(tmp, 3, -1, disp);
|
TRACEF(disp, "f_sector: %i", file.sector);
|
||||||
|
TRACE(disp, "loading:");
|
||||||
|
|
||||||
sprintf(tmp, "Size: %i", file.sec_available);
|
|
||||||
printText(tmp, 3, -1, disp);
|
|
||||||
|
|
||||||
sprintf(tmp, "f_sector: %i", file.sector);
|
|
||||||
printText(tmp, 3, -1, disp);
|
|
||||||
|
|
||||||
printText("loading:", 3, -1, disp);
|
|
||||||
}
|
|
||||||
sleep(10);
|
sleep(10);
|
||||||
|
|
||||||
if(swapped==1){
|
if(swapped==1){
|
||||||
@ -1291,8 +1280,7 @@ void loadrom(display_context_t disp, u8 *buff, int fast){
|
|||||||
sleep(400);
|
sleep(400);
|
||||||
evd_mmcSetDmaSwap(1);
|
evd_mmcSetDmaSwap(1);
|
||||||
|
|
||||||
if (debug)
|
TRACE(disp, "swapping on");
|
||||||
printText("swapping on", 3, -1, disp);
|
|
||||||
|
|
||||||
sleep(10);
|
sleep(10);
|
||||||
}
|
}
|
||||||
@ -1315,21 +1303,16 @@ void loadrom(display_context_t disp, u8 *buff, int fast){
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(resp){
|
if(resp){
|
||||||
if (debug) {
|
TRACEF(disp, "mmcToCart: %i", resp);
|
||||||
sprintf(tmp, "mmcToCart: %i",resp);
|
|
||||||
printText(tmp, 3, -1, disp);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (debug) {
|
//if (debug) {
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
u8 buff[16];
|
u8 buff[16];
|
||||||
dma_read_s(buff, 0xb0000000 + 0x00100000*i, 1);
|
dma_read_s(buff, 0xb0000000 + 0x00100000*i, 1);
|
||||||
sprintf(tmp, "probe: %hhx",buff[0]);
|
TRACEF(disp, "probe: %hhx", buff[0]);
|
||||||
printText(tmp, 3, -1, disp);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
//}
|
||||||
|
|
||||||
if(!fast){
|
if(!fast){
|
||||||
sleep(200);
|
sleep(200);
|
||||||
@ -1379,19 +1362,12 @@ int backupSaveData(display_context_t disp){
|
|||||||
|
|
||||||
resp = fatOpenFileByeName(config_file_path, 1); //if sector is set filemode=WR writeable
|
resp = fatOpenFileByeName(config_file_path, 1); //if sector is set filemode=WR writeable
|
||||||
|
|
||||||
if (debug) {
|
TRACEF(disp, "FAT_OpenFileByName returned: %i", resp);
|
||||||
sprintf(tmp, "FAT_OpenFileByName returned: %i",resp);
|
|
||||||
printText(tmp, 3, -1, disp);
|
|
||||||
}
|
|
||||||
|
|
||||||
resp = fatWriteFile(&cfg_data, 1); //filemode must be wr
|
resp = fatWriteFile(&cfg_data, 1); //filemode must be wr
|
||||||
|
|
||||||
if (debug) {
|
TRACE(disp, "Disabling save for subsequent system reboots");
|
||||||
printText("Disabling save for subsequent system reboots", 3, -1, disp);
|
TRACEF(disp, "FAT_WriteFile returned: %i", resp);
|
||||||
sprintf(tmp, "FAT_WriteFile returned: %i",resp);
|
|
||||||
printText(tmp, 3, -1, disp);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
volatile u8 save_config_state=0;
|
volatile u8 save_config_state=0;
|
||||||
evd_readReg(0);
|
evd_readReg(0);
|
||||||
@ -1405,9 +1381,7 @@ int backupSaveData(display_context_t disp){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (debug)
|
TRACE(disp, "Save not required.");
|
||||||
printText("Save not required.", 3, -1, disp);
|
|
||||||
else
|
|
||||||
printText("...ready", 3, -1, disp);
|
printText("...ready", 3, -1, disp);
|
||||||
|
|
||||||
sleep(200);
|
sleep(200);
|
||||||
@ -1416,34 +1390,28 @@ int backupSaveData(display_context_t disp){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
if (debug)
|
TRACE(disp, "No previous ROM loaded - the file 'last.crt' was not found!");
|
||||||
printText("No previous ROM loaded - the file 'last.crt' was not found!", 3, -1, disp);
|
|
||||||
else
|
|
||||||
printText("...ready", 3, -1, disp);
|
printText("...ready", 3, -1, disp);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (debug) {
|
//if (debug) {
|
||||||
sleep(5000);
|
// sleep(5000);
|
||||||
}
|
//}
|
||||||
|
|
||||||
//reset with save request
|
//reset with save request
|
||||||
if(save_reboot){
|
if (save_reboot) {
|
||||||
printText("Copying RAM to SD card...", 3, -1, disp);
|
printText("Copying RAM to SD card...", 3, -1, disp);
|
||||||
if( saveTypeToSd(disp, rom_filename, save_format) ){
|
if (saveTypeToSd(disp, rom_filename, save_format)) {
|
||||||
if (debug)
|
|
||||||
printText("Operation completed sucessfully...", 3, -1, disp);
|
printText("Operation completed sucessfully...", 3, -1, disp);
|
||||||
else
|
|
||||||
printText("...ready", 3, -1, disp);
|
|
||||||
}
|
|
||||||
else if (debug)
|
|
||||||
printText("ERROR: the RAM was not successfully saved!", 3, -1, disp);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (debug)
|
TRACE(disp, "ERROR: the RAM was not successfully saved!");
|
||||||
printText("no reset - save request", 3, -1, disp);
|
}
|
||||||
else
|
}
|
||||||
|
else {
|
||||||
|
TRACE(disp, "no reset - save request");
|
||||||
printText("...ready", 3, -1, disp);
|
printText("...ready", 3, -1, disp);
|
||||||
|
|
||||||
sleep(300);
|
sleep(300);
|
||||||
@ -1810,34 +1778,26 @@ int saveTypeFromSd(display_context_t disp, char* rom_name, int stype) {
|
|||||||
|
|
||||||
uint8_t cartsave_data[size];
|
uint8_t cartsave_data[size];
|
||||||
|
|
||||||
if (debug) {
|
//if (debug) {
|
||||||
printText(fname, 3, -1, disp);
|
TRACE(disp, fname);
|
||||||
sleep(2000);
|
//sleep(2000);
|
||||||
}
|
//}
|
||||||
|
|
||||||
FatRecord rec_tmpf;
|
FatRecord rec_tmpf;
|
||||||
found = fatFindRecord(fname, &rec_tmpf, 0);
|
found = fatFindRecord(fname, &rec_tmpf, 0);
|
||||||
|
|
||||||
if (debug) {
|
TRACEF(disp, "fatFindRecord returned: %i", found);
|
||||||
sprintf(tmp, "fatFindRecord ret=%i",found);
|
|
||||||
printText(tmp, 3, -1, disp);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(found==0){
|
if(found==0){
|
||||||
u8 resp = 0;
|
u8 resp = 0;
|
||||||
resp = fatOpenFileByeName(fname, 0);
|
resp = fatOpenFileByeName(fname, 0);
|
||||||
|
|
||||||
if (debug) {
|
TRACEF(disp, "fatOpenFileByeName returned: %i", resp);
|
||||||
sprintf(tmp, "fatOpenFileByeName ret=%i",resp);
|
|
||||||
printText(tmp, 3, -1, disp);
|
|
||||||
}
|
|
||||||
|
|
||||||
resp = fatReadFile(cartsave_data, size / 512);
|
resp = fatReadFile(cartsave_data, size / 512);
|
||||||
|
|
||||||
if (debug) {
|
TRACEF(disp, "fatReadFile returned: %i", resp);
|
||||||
sprintf(tmp, "fatReadFile ret=%i",resp);
|
|
||||||
printText(tmp, 3, -1, disp);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
printText("no savegame found", 3, -1, disp);
|
printText("no savegame found", 3, -1, disp);
|
||||||
@ -1872,10 +1832,7 @@ int saveTypeToSd(display_context_t disp, char* rom_name ,int stype) {
|
|||||||
int size;
|
int size;
|
||||||
size = saveTypeToSize(stype); // int byte
|
size = saveTypeToSize(stype); // int byte
|
||||||
|
|
||||||
if (debug) {
|
TRACEF(disp, "size for save=%i", size);
|
||||||
sprintf(tmp, "size for save=%i",size);
|
|
||||||
printText(tmp, 3, -1, disp);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
sprintf(fname, "/ED64/%s/%s.%s",save_path,rom_name,saveTypeToExtension(stype,ext_type));
|
sprintf(fname, "/ED64/%s/%s.%s",save_path,rom_name,saveTypeToExtension(stype,ext_type));
|
||||||
@ -1883,10 +1840,7 @@ int saveTypeToSd(display_context_t disp, char* rom_name ,int stype) {
|
|||||||
FatRecord rec_tmpf;
|
FatRecord rec_tmpf;
|
||||||
found = fatFindRecord(fname, &rec_tmpf, 0);
|
found = fatFindRecord(fname, &rec_tmpf, 0);
|
||||||
|
|
||||||
if (debug) {
|
TRACEF(disp, "found=%i", found);
|
||||||
sprintf(tmp, "found=%i",found);
|
|
||||||
printText(tmp, 3, -1, disp);
|
|
||||||
}
|
|
||||||
|
|
||||||
u8 resp=0;
|
u8 resp=0;
|
||||||
|
|
||||||
@ -1896,19 +1850,13 @@ int saveTypeToSd(display_context_t disp, char* rom_name ,int stype) {
|
|||||||
printText("try fatCreateRecIfNotExist", 3, -1, disp);
|
printText("try fatCreateRecIfNotExist", 3, -1, disp);
|
||||||
resp = fatCreateRecIfNotExist(fname, 0);
|
resp = fatCreateRecIfNotExist(fname, 0);
|
||||||
|
|
||||||
if (debug) {
|
TRACEF(disp, "fatCreateRecIfNotExist returned: %i", resp); //0 means try to create
|
||||||
sprintf(tmp, "fatCreateRecIfNotExist ret=%i",resp); //0 means try to create
|
|
||||||
printText(tmp, 3, -1, disp);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//open file with stype size
|
//open file with stype size
|
||||||
resp = fatOpenFileByeName(fname, size / 512);
|
resp = fatOpenFileByeName(fname, size / 512);
|
||||||
|
|
||||||
if (debug) {
|
TRACEF(disp, "fatOpenFileByeName returned: %i", resp); //100 not exist
|
||||||
sprintf(tmp, "fatOpenFileByeName ret=%i",resp); //100 not exist
|
|
||||||
printText(tmp, 3, -1, disp);
|
|
||||||
}
|
|
||||||
|
|
||||||
//for savegame
|
//for savegame
|
||||||
uint8_t cartsave_data[size];
|
uint8_t cartsave_data[size];
|
||||||
@ -1916,10 +1864,8 @@ int saveTypeToSd(display_context_t disp, char* rom_name ,int stype) {
|
|||||||
for(int zero=0; zero<size;zero++)
|
for(int zero=0; zero<size;zero++)
|
||||||
cartsave_data[zero]=0;
|
cartsave_data[zero]=0;
|
||||||
|
|
||||||
if (debug) {
|
TRACEF(disp, "cartsave_data=%p", &cartsave_data);
|
||||||
sprintf(tmp, "cartsave_data=%p",&cartsave_data);
|
|
||||||
printText(tmp, 3, -1, disp);
|
|
||||||
}
|
|
||||||
|
|
||||||
//universal dumpfunction
|
//universal dumpfunction
|
||||||
//returns data from fpga/cart to save on sd
|
//returns data from fpga/cart to save on sd
|
||||||
@ -2364,21 +2310,16 @@ void bootRom(display_context_t disp, int silent) {
|
|||||||
//set the fpga cart-save type
|
//set the fpga cart-save type
|
||||||
evd_setSaveType(boot_save);
|
evd_setSaveType(boot_save);
|
||||||
|
|
||||||
if (debug) {
|
TRACE(disp, "try to restore save from sd");
|
||||||
printText("try to restore save from sd", 3, -1, disp);
|
|
||||||
}
|
|
||||||
resp = saveTypeFromSd(disp, rom_filename, boot_save);
|
resp = saveTypeFromSd(disp, rom_filename, boot_save);
|
||||||
|
|
||||||
if (debug) {
|
TRACEF(disp, "saveTypeFromSd returned: %i", resp);
|
||||||
sprintf(tmp, "saveTypeFromSd ret=%i",resp);
|
|
||||||
printText(tmp, 3, -1, disp);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (debug) {
|
|
||||||
printText("Cartridge-Savetype set", 3, -1, disp);
|
TRACE(disp, "Cartridge-Savetype set");
|
||||||
printText("information stored for reboot-save...", 3, -1, disp);
|
TRACE(disp, "information stored for reboot-save...");
|
||||||
}
|
|
||||||
|
|
||||||
sleep(50);
|
sleep(50);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user