From 6c19e4098a43c47f8cd1824902f7335e124b834f Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Sun, 16 Dec 2007 23:11:40 +0000 Subject: [PATCH] Extensive changes to remove gcc 4.x warnings, general code cleanup --- Makefile | 3 -- src/blitter.cpp | 10 ++++-- src/cdintf.cpp | 2 ++ src/cdrom.cpp | 10 ++++-- src/clock.cpp | 12 ++------ src/dac.cpp | 11 ++++--- src/dsp.cpp | 40 ++++++++++++++---------- src/dsp.h | 3 +- src/eeprom.cpp | 6 +++- src/eeprom.h | 3 +- src/gpu.cpp | 29 ++++++++++++------ src/gpu.h | 3 +- src/gui.cpp | 12 +++++--- src/jagdasm.cpp | 5 ++- src/jagdasm.h | 2 +- src/jaguar.cpp | 12 +++++++- src/jaguar.h | 9 +++--- src/jerry.cpp | 17 ++++++++--- src/joystick.cpp | 4 +++ src/log.cpp | 5 +-- src/log.h | 2 +- src/memory.cpp | 50 +++++++++++++++++++++++++++--- src/memory.h | 11 +++---- src/objectp.cpp | 71 +++++++++++++++++++++---------------------- src/objectp.h | 8 ++--- src/sdlemu_config.cpp | 5 +-- src/settings.cpp | 3 +- src/tom.cpp | 34 +++++++++++++-------- src/tom.h | 4 ++- src/unzip.h | 1 - src/video.cpp | 4 ++- src/vj.cpp | 15 ++++----- 32 files changed, 259 insertions(+), 147 deletions(-) diff --git a/Makefile b/Makefile index 1601060..eeb8989 100644 --- a/Makefile +++ b/Makefile @@ -94,9 +94,6 @@ OBJS = \ obj/video.o \ obj/vj.o \ $(ICON) -# obj/anajoy.o -# obj/cdbios.o -# obj/cdi.o all: checkenv message obj $(TARGET)$(EXESUFFIX) @echo diff --git a/src/blitter.cpp b/src/blitter.cpp index 66179d0..c767e5b 100644 --- a/src/blitter.cpp +++ b/src/blitter.cpp @@ -8,11 +8,17 @@ // to Curt. ;-) Without that excellent documentation which shows *exactly* // what's going on inside the TOM chip, we'd all still be guessing as to how // the wily blitter and other pieces of the Jaguar puzzle actually work. +// Now how about those JERRY ASIC nets gentlemen...? ;-) // -#include "jaguar.h" #include "blitter.h" +#include +#include +#include +#include "jaguar.h" +#include "log.h" + // Various conditional compilation goodies... //#define USE_ORIGINAL_BLITTER @@ -1724,7 +1730,7 @@ doGPUDis = true; void LogBlit(void) { - char * opStr[16] = { "LFU_CLEAR", "LFU_NSAND", "LFU_NSAD", "LFU_NOTS", "LFU_SAND", "LFU_NOTD", "LFU_N_SXORD", "LFU_NSORND", + const char * opStr[16] = { "LFU_CLEAR", "LFU_NSAND", "LFU_NSAD", "LFU_NOTS", "LFU_SAND", "LFU_NOTD", "LFU_N_SXORD", "LFU_NSORND", "LFU_SAD", "LFU_XOR", "LFU_D", "LFU_NSORD", "LFU_REPLACE", "LFU_SORND", "LFU_SORD", "LFU_ONE" }; uint32 cmd = GET32(blitter_ram, 0x38); uint32 m = (REG(A1_FLAGS) >> 9) & 0x03, e = (REG(A1_FLAGS) >> 11) & 0x0F; diff --git a/src/cdintf.cpp b/src/cdintf.cpp index 35ebf98..fbf227f 100644 --- a/src/cdintf.cpp +++ b/src/cdintf.cpp @@ -71,6 +71,8 @@ bool CDIntfInit(void) return false; } + WriteLog("CDINTF: Successfully opened CD-ROM interface.\n"); + return true; } diff --git a/src/cdrom.cpp b/src/cdrom.cpp index 9e2d44a..1eb8445 100644 --- a/src/cdrom.cpp +++ b/src/cdrom.cpp @@ -6,10 +6,14 @@ // Extensive rewrites/cleanups/fixes by James L. Hammons // +#include "cdrom.h" + +#include // For memset, etc. #include "jaguar.h" // For GET32/SET32 macros #include "m68k.h" #include "cdintf.h" // System agnostic CD interface functions -#include "cdrom.h" +#include "log.h" +#include "dac.h" //#define CDROM_LOG // For CDROM logging, obviously @@ -133,9 +137,9 @@ static uint16 CDROMBusRead(void); #define I2SDAT2 BUTCH + 0x28 // i2s FIFO data (old) #define UNKNOWN BUTCH + 0x2C // Seems to be some sort of I2S interface -char * BReg[12] = { "BUTCH", "DSCNTRL", "DS_DATA", "???", "I2CNTRL", "SBCNTRL", "SUBDATA", "SUBDATB", +const char * BReg[12] = { "BUTCH", "DSCNTRL", "DS_DATA", "???", "I2CNTRL", "SBCNTRL", "SUBDATA", "SUBDATB", "SB_TIME", "FIFO_DATA", "I2SDAT2", "UNKNOWN" }; -extern char * whoName[9]; +extern const char * whoName[9]; static uint8 cdRam[0x100]; diff --git a/src/clock.cpp b/src/clock.cpp index f4ef419..9353b1a 100644 --- a/src/clock.cpp +++ b/src/clock.cpp @@ -8,18 +8,10 @@ // - Handling for an event that occurs NOW // -//#include -//#include "SDL.h" -//#include "SDL_opengl.h" -//#include "jaguar.h" -//#include "m68k.h" -//#include "gpu.h" -//#include "dsp.h" -//#include "settings.h" -//#include "video.h" -#include "log.h" #include "clock.h" +#include "log.h" + #define EVENT_LIST_SIZE 512 /* diff --git a/src/dac.cpp b/src/dac.cpp index 0ad2b9f..4b4bfab 100644 --- a/src/dac.cpp +++ b/src/dac.cpp @@ -11,11 +11,13 @@ // work correctly...! Perhaps just need to set up SSI stuff so BUTCH doesn't get // confused... +#include "dac.h" + #include "SDL.h" #include "m68k.h" #include "jaguar.h" #include "settings.h" -#include "dac.h" +#include "log.h" //#define DEBUG_DAC @@ -43,7 +45,7 @@ static bool SDLSoundInitialized = false; // We can get away with using native endian here because we can tell SDL to use the native // endian when looking at the sample buffer, i.e., no need to worry about it. -static uint16 * DACBuffer; +static uint16 DACBuffer[BUFFER_SIZE]; static uint8 SCLKFrequencyDivider = 19; // Default is roughly 22 KHz (20774 Hz in NTSC mode) /*static*/ uint16 serialMode = 0; @@ -57,7 +59,8 @@ int GetCalculatedFrequency(void); // void DACInit(void) { - memory_malloc_secure((void **)&DACBuffer, BUFFER_SIZE * sizeof(uint16), "DAC buffer"); +// memory_malloc_secure((void **)&DACBuffer, BUFFER_SIZE * sizeof(uint16), "DAC buffer"); +// DACBuffer = (uint16 *)memory_malloc(BUFFER_SIZE * sizeof(uint16), "DAC buffer"); desired.freq = GetCalculatedFrequency(); // SDL will do conversion on the fly, if it can't get the exact rate. Nice! desired.format = AUDIO_S16SYS; // This uses the native endian (for portability)... @@ -96,7 +99,7 @@ void DACDone(void) SDL_CloseAudio(); } - memory_free(DACBuffer); +// memory_free(DACBuffer); WriteLog("DAC: Done.\n"); } diff --git a/src/dsp.cpp b/src/dsp.cpp index 6f27dd8..812d103 100644 --- a/src/dsp.cpp +++ b/src/dsp.cpp @@ -6,9 +6,17 @@ // Extensive cleanups/rewrites by James L. Hammons // +#include "dsp.h" + #include #include // Used only for SDL_GetTicks... -#include "dsp.h" +#include "memory.h" +#include "log.h" +#include "jaguar.h" +#include "jerry.h" +#include "gpu.h" +#include "jagdasm.h" +#include "m68k.h" //#define DSP_DEBUG //#define DSP_DEBUG_IRQ @@ -332,7 +340,7 @@ void (* dsp_opcode[64])() = uint32 dsp_opcode_use[65]; -char * dsp_opcode_str[65]= +const char * dsp_opcode_str[65]= { "add", "addc", "addq", "addqt", "sub", "subc", "subq", "subqt", @@ -364,8 +372,8 @@ static uint32 dsp_data_organization; uint32 dsp_control; static uint32 dsp_div_control; static uint8 dsp_flag_z, dsp_flag_n, dsp_flag_c; -static uint32 * dsp_reg, * dsp_alternate_reg; -static uint32 * dsp_reg_bank_0, * dsp_reg_bank_1; +static uint32 * dsp_reg = NULL, * dsp_alternate_reg = NULL; +static uint32 dsp_reg_bank_0[32], dsp_reg_bank_1[32]; static uint32 dsp_opcode_first_parameter; static uint32 dsp_opcode_second_parameter; @@ -393,7 +401,7 @@ static uint32 dsp_opcode_second_parameter; uint32 dsp_convert_zero[32] = { 32,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31 }; uint8 * dsp_branch_condition_table = NULL; static uint16 * mirror_table = NULL; -static uint8 * dsp_ram_8 = NULL; +static uint8 dsp_ram_8[0x2000]; #define BRANCH_CONDITION(x) dsp_branch_condition_table[(x) + ((jaguar_flags & 7) << 5)] @@ -433,7 +441,7 @@ void dsp_build_branch_condition_table(void) { // Allocate the mirror table if (!mirror_table) - mirror_table = (uint16 *)malloc(65536 * sizeof(mirror_table[0])); + mirror_table = (uint16 *)memory_malloc(65536 * sizeof(uint16), "DSP mirror table"); // Fill in the mirror table if (mirror_table) @@ -449,7 +457,7 @@ void dsp_build_branch_condition_table(void) if (!dsp_branch_condition_table) { - dsp_branch_condition_table = (uint8 *)malloc(32 * 8 * sizeof(dsp_branch_condition_table[0])); + dsp_branch_condition_table = (uint8 *)memory_malloc(32 * 8 * sizeof(uint8), "DSP branch condition table"); // Fill in the condition table if (dsp_branch_condition_table) @@ -537,12 +545,12 @@ uint16 DSPReadWord(uint32 offset, uint32 who/*=UNKNOWN*/) if (offset==0xF1B2C2) return(0x0000); } */ - // pour permettre à wolfenstein 3d de tourner sans le dsp + // pour permettre � wolfenstein 3d de tourner sans le dsp /* if ((offset==0xF1B0D0)||(offset==0xF1B0D2)) return(0); */ - // pour permettre à nba jam de tourner sans le dsp + // pour permettre � nba jam de tourner sans le dsp /* if (jaguar_mainRom_crc32==0x4faddb18) { if (offset==0xf1b2c0) return(0); @@ -1226,9 +1234,9 @@ DSPHandleIRQsNP(); void DSPInit(void) { - memory_malloc_secure((void **)&dsp_ram_8, 0x2000, "DSP work RAM"); - memory_malloc_secure((void **)&dsp_reg_bank_0, 32 * sizeof(int32), "DSP bank 0 regs"); - memory_malloc_secure((void **)&dsp_reg_bank_1, 32 * sizeof(int32), "DSP bank 1 regs"); +// memory_malloc_secure((void **)&dsp_ram_8, 0x2000, "DSP work RAM"); +// memory_malloc_secure((void **)&dsp_reg_bank_0, 32 * sizeof(int32), "DSP bank 0 regs"); +// memory_malloc_secure((void **)&dsp_reg_bank_1, 32 * sizeof(int32), "DSP bank 1 regs"); dsp_build_branch_condition_table(); DSPReset(); @@ -1666,7 +1674,7 @@ if ((dsp_pc < 0xF1B000 || dsp_pc > 0xF1CFFE) && !tripwire) static void dsp_opcode_jump(void) { #ifdef DSP_DIS_JUMP -char * condition[32] = +const char * condition[32] = { "T", "nz", "z", "???", "nc", "nc nz", "nc z", "???", "c", "c nz", "c z", "???", "???", "???", "???", "???", "???", "???", "???", "???", "nn", "nn nz", "nn z", "???", "n", "n nz", "n z", "???", @@ -1701,7 +1709,7 @@ char * condition[32] = static void dsp_opcode_jr(void) { #ifdef DSP_DIS_JR -char * condition[32] = +const char * condition[32] = { "T", "nz", "z", "???", "nc", "nc nz", "nc z", "???", "c", "c nz", "c z", "???", "???", "???", "???", "???", "???", "???", "???", "???", "nn", "nn nz", "nn z", "???", "n", "n nz", "n z", "???", @@ -3683,7 +3691,7 @@ static void DSP_illegal(void) static void DSP_jr(void) { #ifdef DSP_DIS_JR -char * condition[32] = +const char * condition[32] = { "T", "nz", "z", "???", "nc", "nc nz", "nc z", "???", "c", "c nz", "c z", "???", "???", "???", "???", "???", "???", "???", "???", "???", "nn", "nn nz", "nn z", "???", "n", "n nz", "n z", "???", @@ -3793,7 +3801,7 @@ char * condition[32] = static void DSP_jump(void) { #ifdef DSP_DIS_JUMP -char * condition[32] = +const char * condition[32] = { "T", "nz", "z", "???", "nc", "nc nz", "nc z", "???", "c", "c nz", "c z", "???", "???", "???", "???", "???", "???", "???", "???", "???", "nn", "nn nz", "nn z", "???", "n", "n nz", "n z", "???", diff --git a/src/dsp.h b/src/dsp.h index cb1b0c2..4dbb2f8 100644 --- a/src/dsp.h +++ b/src/dsp.h @@ -5,7 +5,8 @@ #ifndef __DSP_H__ #define __DSP_H__ -#include "jaguar.h" +//#include "jaguar.h" +#include "types.h" #define DSP_CONTROL_RAM_BASE 0x00F1A100 #define DSP_WORK_RAM_BASE 0x00F1B000 diff --git a/src/eeprom.cpp b/src/eeprom.cpp index 517a269..6b2ef65 100644 --- a/src/eeprom.cpp +++ b/src/eeprom.cpp @@ -6,9 +6,13 @@ // Cleanups/enhancements by James L. Hammons // -#include #include "eeprom.h" + +#include // For memset +#include #include "settings.h" +#include "log.h" +#include "jaguar.h" #define eeprom_LOG diff --git a/src/eeprom.h b/src/eeprom.h index 2a52638..776e651 100644 --- a/src/eeprom.h +++ b/src/eeprom.h @@ -5,7 +5,8 @@ #ifndef __EEPROM_H__ #define __EEPROM_H__ -#include "jaguar.h" +//#include "jaguar.h" +#include "types.h" void eeprom_init(void); void eeprom_reset(void); diff --git a/src/gpu.cpp b/src/gpu.cpp index 900c6c8..10d337b 100644 --- a/src/gpu.cpp +++ b/src/gpu.cpp @@ -12,9 +12,18 @@ // Same problem with ADDC... // -#include #include "gpu.h" +#include // For memset +#include +#include "log.h" +#include "jaguar.h" +#include "m68k.h" +#include "tom.h" +#include "memory.h" +#include "jagdasm.h" +#include "dsp.h" + //#define GPU_DEBUG // For GPU dissasembly... @@ -283,7 +292,7 @@ void (*gpu_opcode[64])()= gpu_opcode_store_r14_ri, gpu_opcode_store_r15_ri, gpu_opcode_sat24, gpu_opcode_pack, }; -static uint8 * gpu_ram_8; +static uint8 gpu_ram_8[0x1000]; uint32 gpu_pc; static uint32 gpu_acc; static uint32 gpu_remain; @@ -298,8 +307,8 @@ static uint32 gpu_div_control; // a bit before writing a result. I.e., if the result of an operation leaves a zero in // the carry flag, you don't have to zero gpu_flag_c before you can write that zero! static uint8 gpu_flag_z, gpu_flag_n, gpu_flag_c; -static uint32 * gpu_reg_bank_0; -static uint32 * gpu_reg_bank_1; +static uint32 gpu_reg_bank_0[32]; +static uint32 gpu_reg_bank_1[32]; static uint32 * gpu_reg; static uint32 * gpu_alternate_reg; @@ -342,7 +351,7 @@ uint8 * branch_condition_table = 0; uint32 gpu_opcode_use[64]; -char * gpu_opcode_str[64]= +const char * gpu_opcode_str[64]= { "add", "addc", "addq", "addqt", "sub", "subc", "subq", "subqt", @@ -968,9 +977,9 @@ void GPUSetIRQLine(int irqline, int state) void gpu_init(void) { - memory_malloc_secure((void **)&gpu_ram_8, 0x1000, "GPU work RAM"); - memory_malloc_secure((void **)&gpu_reg_bank_0, 32 * sizeof(int32), "GPU bank 0 regs"); - memory_malloc_secure((void **)&gpu_reg_bank_1, 32 * sizeof(int32), "GPU bank 1 regs"); +// memory_malloc_secure((void **)&gpu_ram_8, 0x1000, "GPU work RAM"); +// memory_malloc_secure((void **)&gpu_reg_bank_0, 32 * sizeof(int32), "GPU bank 0 regs"); +// memory_malloc_secure((void **)&gpu_reg_bank_1, 32 * sizeof(int32), "GPU bank 1 regs"); build_branch_condition_table(); @@ -1335,7 +1344,7 @@ GPU opcodes use (offset punch--vertically below bad guy): static void gpu_opcode_jump(void) { #ifdef GPU_DIS_JUMP -char * condition[32] = +const char * condition[32] = { "T", "nz", "z", "???", "nc", "nc nz", "nc z", "???", "c", "c nz", "c z", "???", "???", "???", "???", "???", "???", "???", "???", "???", "nn", "nn nz", "nn z", "???", "n", "n nz", "n z", "???", @@ -1378,7 +1387,7 @@ if (gpu_start_log) static void gpu_opcode_jr(void) { #ifdef GPU_DIS_JR -char * condition[32] = +const char * condition[32] = { "T", "nz", "z", "???", "nc", "nc nz", "nc z", "???", "c", "c nz", "c z", "???", "???", "???", "???", "???", "???", "???", "???", "???", "nn", "nn nz", "nn z", "???", "n", "n nz", "n z", "???", diff --git a/src/gpu.h b/src/gpu.h index 1b83d74..1af1a36 100644 --- a/src/gpu.h +++ b/src/gpu.h @@ -5,7 +5,8 @@ #ifndef __GPU_H__ #define __GPU_H__ -#include "jaguar.h" +//#include "jaguar.h" +#include "types.h" #define GPU_CONTROL_RAM_BASE 0x00F02100 #define GPU_WORK_RAM_BASE 0x00F03000 diff --git a/src/gui.cpp b/src/gui.cpp index 38fc128..0c0627d 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -5,6 +5,8 @@ // by James L. Hammons // +#include "gui.h" + #include #include // For MacOS dependency #include @@ -24,7 +26,9 @@ #include "zlib.h" #include "unzip.h" #include "sdlemu_opengl.h" -#include "gui.h" +#include "log.h" +#include "jaguar.h" +#include "eeprom.h" using namespace std; // For STL stuff @@ -68,7 +72,7 @@ bool exitGUI = false; // GUI (emulator) done variable int mouseX = 0, mouseY = 0; uint32 background[1280 * 256]; // GUI background buffer -char separator[] = "--------------------------------------------------------"; +const char separator[] = "--------------------------------------------------------"; // // Case insensitive string compare function @@ -80,7 +84,7 @@ int stringCmpi(const string &s1, const string &s2) // Select the first element of each string: string::const_iterator p1 = s1.begin(), p2 = s2.begin(); - while (p1 != s1.end() && p2 != s2.end()) // Don’t run past the end + while (p1 != s1.end() && p2 != s2.end()) // Don�t run past the end { if (toupper(*p1) != toupper(*p2)) // Compare upper-cased chars return (toupper(*p1) < toupper(*p2) ? -1 : 1);// Report which was lexically greater @@ -2070,7 +2074,7 @@ Window * RunEmu(void) else if (jaguar_mainRom_crc32 == 0x55A0669C) cartType = 3; - char * cartTypeName[5] = { "2M Cartridge", "4M Cartridge", "CD BIOS", "CD Dev BIOS", "Homebrew" }; + const char * cartTypeName[5] = { "2M Cartridge", "4M Cartridge", "CD BIOS", "CD Dev BIOS", "Homebrew" }; uint32 elapsedTicks = SDL_GetTicks(), frameCount = 0, framesPerSecond = 0; while (!finished) diff --git a/src/jagdasm.cpp b/src/jagdasm.cpp index 2e449a7..6fadae8 100644 --- a/src/jagdasm.cpp +++ b/src/jagdasm.cpp @@ -1,3 +1,6 @@ +#include "jagdasm.h" + +#include #include "jaguar.h" #define ROPCODE(a) JaguarReadWord(a) @@ -5,7 +8,7 @@ uint8 convert_zero[32] = { 32,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31 }; -char * condition[32] = +const char * condition[32] = { "", "nz,", diff --git a/src/jagdasm.h b/src/jagdasm.h index 1591899..0171f2b 100644 --- a/src/jagdasm.h +++ b/src/jagdasm.h @@ -4,6 +4,6 @@ #define JAGUAR_GPU 0 #define JAGUAR_DSP 1 -unsigned dasmjag(int dsp_type, char *buffer, unsigned pc); +unsigned dasmjag(int dsp_type, char * buffer, unsigned pc); #endif diff --git a/src/jaguar.cpp b/src/jaguar.cpp index 494dacf..82e9af8 100644 --- a/src/jaguar.cpp +++ b/src/jaguar.cpp @@ -9,12 +9,22 @@ // #include "jaguar.h" + #include "video.h" #include "settings.h" //#include "m68kdasmAG.h" #include "clock.h" #include #include "SDL_opengl.h" +#include "m68k.h" +#include "log.h" +#include "tom.h" +#include "jerry.h" +#include "cdrom.h" +#include "dsp.h" +#include "gpu.h" +#include "memory.h" +#include "joystick.h" #define CPU_DEBUG //Do this in makefile??? Yes! Could, but it's easier to define here... @@ -43,7 +53,7 @@ extern int effect_start2, effect_start3, effect_start4, effect_start5, effect_st // Memory debugging identifiers -char * whoName[9] = +const char * whoName[9] = { "Unknown", "Jaguar", "DSP", "GPU", "TOM", "JERRY", "M68K", "Blitter", "OP" }; uint32 jaguar_active_memory_dumps = 0; diff --git a/src/jaguar.h b/src/jaguar.h index e1358b9..ecd7197 100644 --- a/src/jaguar.h +++ b/src/jaguar.h @@ -1,6 +1,9 @@ #ifndef __JAGUAR_H__ #define __JAGUAR_H__ +#include "types.h" + +#if 0 #include // Why??? (for memset, etc... Lazy!) Dunno why, but this just strikes me as wrong... #include // For exit() #include "types.h" @@ -15,21 +18,19 @@ #include "objectp.h" #include "blitter.h" #include "clock.h" -//#include "anajoy.h" #include "joystick.h" #include "dac.h" #include "jagdasm.h" #include "cdrom.h" #include "eeprom.h" -//#include "cdi.h" -//#include "cdbios.h" +#endif // Exports from JAGUAR.CPP extern int32 jaguar_cpu_in_exec; extern uint32 jaguar_mainRom_crc32, jaguarRomSize, jaguarRunAddress; extern char * jaguar_eeproms_path; -extern char * whoName[9]; +extern const char * whoName[9]; void jaguar_init(void); void jaguar_reset(void); diff --git a/src/jerry.cpp b/src/jerry.cpp index bc1541f..742cfb2 100644 --- a/src/jerry.cpp +++ b/src/jerry.cpp @@ -144,17 +144,25 @@ // F1DE00 R xxxxxxxx xxxxxxxx ROM_NOISE - white noise // ------------------------------------------------------------ +#include "jerry.h" + +#include // For memcpy //#include #include "jaguar.h" #include "wavetable.h" -#include "jerry.h" #include "clock.h" +#include "dsp.h" +#include "dac.h" +#include "joystick.h" +#include "eeprom.h" +#include "log.h" +#include "cdrom.h" //Note that 44100 Hz requires samples every 22.675737 usec. #define NEW_TIMER_SYSTEM //#define JERRY_DEBUG -/*static*/ uint8 * jerry_ram_8; +/*static*/ uint8 jerry_ram_8[0x10000]; //#define JERRY_CONFIG 0x4002 // ??? What's this ??? @@ -348,6 +356,7 @@ void JERRYI2SCallback(void) { // Why is it called this? Instead of SCLK? Shouldn't this be read from DAC.CPP??? //Yes, it should. !!! FIX !!! +#warning Yes, it should. !!! FIX !!! jerry_i2s_interrupt_divide &= 0xFF; // We don't have to divide the RISC clock rate by this--the reason is a bit // convoluted. Will put explanation here later... @@ -410,7 +419,7 @@ void jerry_init(void) DACInit(); //This should be handled with the cart initialization... // eeprom_init(); - memory_malloc_secure((void **)&jerry_ram_8, 0x10000, "JERRY RAM/ROM"); +// memory_malloc_secure((void **)&jerry_ram_8, 0x10000, "JERRY RAM/ROM"); memcpy(&jerry_ram_8[0xD000], wave_table, 0x1000); JERRYPIT1Prescaler = 0xFFFF; @@ -440,7 +449,7 @@ void jerry_reset(void) void jerry_done(void) { WriteLog("JERRY: M68K Interrupt control ($F10020) = %04X\n", GET16(jerry_ram_8, 0x20)); - memory_free(jerry_ram_8); +// memory_free(jerry_ram_8); // clock_done(); // anajoy_done(); joystick_done(); diff --git a/src/joystick.cpp b/src/joystick.cpp index 82057d9..cd1bdca 100644 --- a/src/joystick.cpp +++ b/src/joystick.cpp @@ -6,11 +6,15 @@ // Cleanups/fixes by James L. Hammons // +#include "joystick.h" + #include #include #include "jaguar.h" #include "video.h" #include "settings.h" +#include "gpu.h" +#include "log.h" #define BUTTON_U 0 #define BUTTON_D 1 diff --git a/src/log.cpp b/src/log.cpp index 1f6b882..ce660e8 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -6,17 +6,18 @@ // Cleanups/new stuff by James L. Hammons // +#include "log.h" + #include #include #include "types.h" -#include "log.h" #define MAX_LOG_SIZE 10000000 // Maximum size of log file (10 MB) static FILE * log_stream = NULL; static uint32 logSize = 0; -int log_init(char * path) +int log_init(const char * path) { log_stream = fopen(path, "wrt"); diff --git a/src/log.h b/src/log.h index 0804df9..1c10e68 100644 --- a/src/log.h +++ b/src/log.h @@ -11,7 +11,7 @@ extern "C" { #endif -int log_init(char *); +int log_init(const char *); FILE * log_get(void); void log_done(void); void WriteLog(const char * text, ...); diff --git a/src/memory.cpp b/src/memory.cpp index d51fc38..fe7ac6b 100644 --- a/src/memory.cpp +++ b/src/memory.cpp @@ -6,17 +6,18 @@ // Cleanups by James L. Hammons // +#include "memory.h" + #include #include #include "log.h" -#include "memory.h" // Useful structs (for doubly linked list in this case) typedef struct sMemBlockInfo { void * ptr; - char * info; + const char * info; uint32 size; sMemBlockInfo * next; sMemBlockInfo * prev; @@ -30,7 +31,7 @@ static uint32 currentAllocatedMemory; static uint32 maximumAllocatedMemory; -void memory_addMemInfo(void * ptr, uint32 size, char * info) +void memory_addMemInfo(void * ptr, uint32 size, const char * info) { sMemBlockInfo * alias = &memoryInfo; @@ -63,7 +64,7 @@ void MemoryDone(void) { } -void * memory_malloc(uint32 size, char * info) +void * memory_malloc(uint32 size, const char * info) { void * ptr = (void *)malloc(size); @@ -79,7 +80,11 @@ void * memory_malloc(uint32 size, char * info) return ptr; } -void memory_malloc_secure(void ** new_ptr, uint32 size, char * info) +// OK, this sux, causes the compiler to complain about type punned pointers. +// The only difference between this and the previous is that this one ABORTS +// if it can't allocate the memory. BAD BAD BAD + +void memory_malloc_secure(void ** new_ptr, uint32 size, const char * info) { WriteLog("Memory: Allocating %i bytes of memory for <%s>...", size, (info == NULL ? "unknown" : info)); @@ -89,6 +94,11 @@ void memory_malloc_secure(void ** new_ptr, uint32 size, char * info) { WriteLog("Failed!\n"); log_done(); + +//BAD, BAD, BAD! Need to do better than this!!! +//And since we ARE keeping track of all memory allocations, we should unwind the stack here as well...! +// !!! FIX !!! + exit(0); } @@ -102,6 +112,36 @@ void memory_malloc_secure(void ** new_ptr, uint32 size, char * info) WriteLog("OK\n"); } +/* +void * memory_malloc_secure2(uint32 size, const char * info) +{ + WriteLog("Memory: Allocating %i bytes of memory for <%s>...", size, (info == NULL ? "unknown" : info)); + + void * ptr = malloc(size); + + if (ptr == NULL) + { + WriteLog("Failed!\n"); + log_done(); + +//BAD, BAD, BAD! Need to do better than this!!! +//And since we ARE keeping track of all memory allocations, we should unwind the stack here as well...! +// !!! FIX !!! + + exit(0); + } + + memory_addMemInfo(ptr, size, info); + currentAllocatedMemory += size; + + if (currentAllocatedMemory > maximumAllocatedMemory) + maximumAllocatedMemory = currentAllocatedMemory; + + new_ptr = ptr; + WriteLog("OK\n"); +} +*/ + void memory_free(void * ptr) { // sMemBlockInfo * alias= &memoryInfo; diff --git a/src/memory.h b/src/memory.h index 5e922de..b1a8b5d 100644 --- a/src/memory.h +++ b/src/memory.h @@ -5,16 +5,15 @@ #ifndef __MEMORY_H__ #define __MEMORY_H__ -#include -//#include -//#include +//This module needs some serious cleanup. !!! FIX !!! +#include // For FILE struct #include "types.h" -//#include "log.h" void InitMemory(void); void MemoryDone(void); -void memory_malloc_secure(void ** new_ptr, uint32 size, char * info); -void * memory_malloc(uint32 size, char * info); +void memory_malloc_secure(void ** new_ptr, uint32 size, const char * info); +//void * memory_malloc_secure2(uint32 size, const char * info); +void * memory_malloc(uint32 size, const char * info); void memory_free(void * ptr); void memory_memoryUsage(FILE * fp); diff --git a/src/objectp.cpp b/src/objectp.cpp index db643af..9467145 100644 --- a/src/objectp.cpp +++ b/src/objectp.cpp @@ -6,10 +6,15 @@ // Extensive cleanups/fixes/rewrites by James L. Hammons // -//#include +#include "objectp.h" + #include #include +#include "tom.h" #include "jaguar.h" +#include "log.h" +#include "gpu.h" +#include "m68k.h" //#define OP_DEBUG //#define OP_DEBUG_BMP @@ -44,12 +49,14 @@ uint64 op_load_phrase(uint32 offset); // Local global variables -static uint8 * op_blend_y; -static uint8 * op_blend_cr; +// Blend tables (64K each) +static uint8 op_blend_y[0x10000]; +static uint8 op_blend_cr[0x10000]; // There may be a problem with this "RAM" overlapping (and thus being independent of) // some of the regular TOM RAM... -static uint8 objectp_ram[0x40]; // This is based at $F00000 -uint8 objectp_running; +//#warning objectp_ram is separated from TOM RAM--need to fix that! +//static uint8 objectp_ram[0x40]; // This is based at $F00000 +uint8 objectp_running = 0; //bool objectp_stop_reading_list; static uint8 op_bitmap_bit_depth[8] = { 1, 2, 4, 8, 16, 24, 32, 0 }; @@ -66,10 +73,6 @@ int32 phraseWidthToPixels[8] = { 64, 32, 16, 8, 4, 2, 0, 0 }; // void op_init(void) { - // Blend tables (64K each) - memory_malloc_secure((void **)&op_blend_y, 0x10000, "Jaguar Object processor Y blend lookup table"); - memory_malloc_secure((void **)&op_blend_cr, 0x10000, "Jaguar Object processor CR blend lookup table"); - // Here we calculate the saturating blend of a signed 4-bit value and an // existing Cyan/Red value as well as a signed 8-bit value and an existing intensity... // Note: CRY is 4 bits Cyan, 4 bits Red, 16 bits intensitY @@ -116,15 +119,15 @@ void op_init(void) // void op_reset(void) { - memset(objectp_ram, 0x00, 0x40); +// memset(objectp_ram, 0x00, 0x40); objectp_running = 0; } void op_done(void) { - char * opType[8] = + const char * opType[8] = { "(BITMAP)", "(SCALED BITMAP)", "(GPU INT)", "(BRANCH)", "(STOP)", "???", "???", "???" }; - char * ccType[8] = + const char * ccType[8] = { "\"==\"", "\"<\"", "\">\"", "(opflag set)", "(second half line)", "?", "?", "?" }; uint32 olp = op_get_list_pointer(); @@ -149,8 +152,8 @@ void op_done(void) } WriteLog("\n"); - memory_free(op_blend_y); - memory_free(op_blend_cr); +// memory_free(op_blend_y); +// memory_free(op_blend_cr); } // @@ -162,6 +165,7 @@ void op_done(void) // F00026 W -------- -------x OBF - object processor flag // +#if 0 uint8 OPReadByte(uint32 offset, uint32 who/*=UNKNOWN*/) { offset &= 0x3F; @@ -190,33 +194,27 @@ WriteLog("OP: Setting lo list pointer: %04X\n", data); if (offset == 0x22) WriteLog("OP: Setting hi list pointer: %04X\n", data);//*/ } +#endif uint32 op_get_list_pointer(void) { // Note: This register is LO / HI WORD, hence the funky look of this... -// return (objectp_ram[0x22] << 24) | (objectp_ram[0x23] << 16) | (objectp_ram[0x20] << 8) | objectp_ram[0x21]; - return GET16(objectp_ram, 0x20) | (GET16(objectp_ram, 0x22) << 16); + return GET16(tom_ram_8, 0x20) | (GET16(tom_ram_8, 0x22) << 16); } // This is WRONG, since the OBF is only 16 bits wide!!! [FIXED] uint32 op_get_status_register(void) { -// return (objectp_ram[0x26] << 24) | (objectp_ram[0x27] << 16) | (objectp_ram[0x28] << 8) | objectp_ram[0x29]; -// return GET32(objectp_ram, 0x26); - return GET16(objectp_ram, 0x26); + return GET16(tom_ram_8, 0x26); } // This is WRONG, since the OBF is only 16 bits wide!!! [FIXED] void op_set_status_register(uint32 data) { -/* objectp_ram[0x26] = (data & 0xFF000000) >> 24; - objectp_ram[0x27] = (data & 0x00FF0000) >> 16; - objectp_ram[0x28] = (data & 0x0000FF00) >> 8; - objectp_ram[0x29] |= (data & 0xFE);*/ - objectp_ram[0x26] = (data & 0x0000FF00) >> 8; - objectp_ram[0x27] |= (data & 0xFE); + tom_ram_8[0x26] = (data & 0x0000FF00) >> 8; + tom_ram_8[0x27] |= (data & 0xFE); } void op_set_current_object(uint64 object) @@ -233,15 +231,15 @@ void op_set_current_object(uint64 object) objectp_ram[0x15] = object & 0xFF; object >>= 8; objectp_ram[0x14] = object & 0xFF;*/ // Let's try regular good old big endian... - objectp_ram[0x17] = object & 0xFF; object >>= 8; - objectp_ram[0x16] = object & 0xFF; object >>= 8; - objectp_ram[0x15] = object & 0xFF; object >>= 8; - objectp_ram[0x14] = object & 0xFF; object >>= 8; - - objectp_ram[0x13] = object & 0xFF; object >>= 8; - objectp_ram[0x12] = object & 0xFF; object >>= 8; - objectp_ram[0x11] = object & 0xFF; object >>= 8; - objectp_ram[0x10] = object & 0xFF; + tom_ram_8[0x17] = object & 0xFF; object >>= 8; + tom_ram_8[0x16] = object & 0xFF; object >>= 8; + tom_ram_8[0x15] = object & 0xFF; object >>= 8; + tom_ram_8[0x14] = object & 0xFF; object >>= 8; + + tom_ram_8[0x13] = object & 0xFF; object >>= 8; + tom_ram_8[0x12] = object & 0xFF; object >>= 8; + tom_ram_8[0x11] = object & 0xFF; object >>= 8; + tom_ram_8[0x10] = object & 0xFF; } uint64 op_load_phrase(uint32 offset) @@ -314,6 +312,7 @@ void DumpFixedObject(uint64 p0, uint64 p1) // //Need to fix this so that when an GPU object IRQ happens, we can pick up OP processing //where we left off. !!! FIX !!! +#warning Need to fix this so that when an GPU object IRQ happens, we can pick up OP processing where we left off. !!! FIX !!! void OPProcessList(int scanline, bool render) { extern int op_start_log; @@ -460,8 +459,8 @@ if (!inhibit) // For OP testing only! //???Does this really happen??? Doesn't seem to work if you do this...! //Probably not. Must be a bug in the documentation...! // uint32 link = (p0 & 0x7FFFF000000) >> 21; -// SET16(objectp_ram, 0x20, link & 0xFFFF); // OLP -// SET16(objectp_ram, 0x22, link >> 16); +// SET16(tom_ram_8, 0x20, link & 0xFFFF); // OLP +// SET16(tom_ram_8, 0x22, link >> 16); /* uint32 height = (p0 & 0xFFC000) >> 14; if (height - 1 > 0) height--;*/ diff --git a/src/objectp.h b/src/objectp.h index 9d2a6cc..82327d5 100644 --- a/src/objectp.h +++ b/src/objectp.h @@ -17,9 +17,9 @@ void op_set_status_register(uint32 data); uint32 op_get_status_register(void); void op_set_current_object(uint64 object); -uint8 OPReadByte(uint32, uint32 who = UNKNOWN); -uint16 OPReadWord(uint32, uint32 who = UNKNOWN); -void OPWriteByte(uint32, uint8, uint32 who = UNKNOWN); -void OPWriteWord(uint32, uint16, uint32 who = UNKNOWN); +//uint8 OPReadByte(uint32, uint32 who = UNKNOWN); +//uint16 OPReadWord(uint32, uint32 who = UNKNOWN); +//void OPWriteByte(uint32, uint8, uint32 who = UNKNOWN); +//void OPWriteWord(uint32, uint16, uint32 who = UNKNOWN); #endif // __OBJECTP_H__ diff --git a/src/sdlemu_config.cpp b/src/sdlemu_config.cpp index 75d7644..539de40 100644 --- a/src/sdlemu_config.cpp +++ b/src/sdlemu_config.cpp @@ -16,11 +16,12 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - + +#include "sdlemu_config.h" + #include #include #include -#include "sdlemu_config.h" using namespace std; diff --git a/src/settings.cpp b/src/settings.cpp index ac64832..40d417e 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -4,12 +4,13 @@ // by James L. Hammons // +#include "settings.h" + #include #include #include "SDL.h" #include "sdlemu_config.h" #include "log.h" -#include "settings.h" using namespace std; diff --git a/src/tom.cpp b/src/tom.cpp index 7bd954e..44617b3 100644 --- a/src/tom.cpp +++ b/src/tom.cpp @@ -244,14 +244,20 @@ // F02298 W xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx B_Z0 - Z0 // ------------------------------------------------------------ -//#include #include "tom.h" + +#include // For memset() +#include // For rand() #include "video.h" #include "gpu.h" #include "objectp.h" #include "cry2rgb.h" #include "settings.h" #include "clock.h" +#include "jaguar.h" +#include "log.h" +#include "blitter.h" +#include "m68k.h" #define NEW_TIMER_SYSTEM @@ -310,7 +316,7 @@ extern uint8 objectp_running; -static uint8 * tom_ram_8; +uint8 tom_ram_8[0x4000]; uint32 tom_width, tom_height; static uint32 tom_timer_prescaler; static uint32 tom_timer_divider; @@ -323,7 +329,7 @@ uint16 tom_jerry_int_pending, tom_timer_int_pending, tom_object_int_pending, //int16 * TOMBackbuffer; uint32 * TOMBackbuffer; -static char * videoMode_to_str[8] = +static const char * videoMode_to_str[8] = { "16 BPP CRY", "24 BPP RGB", "16 BPP DIRECT", "16 BPP RGB", "Mixed mode", "24 BPP RGB", "16 BPP DIRECT", "16 BPP RGB" }; @@ -991,7 +997,7 @@ void tom_init(void) op_init(); blitter_init(); //This should be done by JERRY! pcm_init(); - memory_malloc_secure((void **)&tom_ram_8, 0x4000, "TOM RAM"); +// memory_malloc_secure((void **)&tom_ram_8, 0x4000, "TOM RAM"); tom_reset(); // Setup the non-stretchy scanline rendering... memcpy(scanline_render, scanline_render_normal, sizeof(scanline_render)); @@ -1011,7 +1017,7 @@ void tom_done(void) // WriteLog("tom: INT1=0x%.2x%.2x\n",TOMReadByte(0xf000e0),TOMReadByte(0xf000e1)); // gpu_done(); // dsp_done(); - memory_free(tom_ram_8); +// memory_free(tom_ram_8); // memory_free(tom_cry_rgb_mix_lut); } @@ -1192,8 +1198,8 @@ uint8 TOMReadByte(uint32 offset, uint32 who/*=UNKNOWN*/) return GPUReadByte(offset, who); else if ((offset >= GPU_WORK_RAM_BASE) && (offset < GPU_WORK_RAM_BASE+0x1000)) return GPUReadByte(offset, who); - else if ((offset >= 0xF00010) && (offset < 0xF00028)) - return OPReadByte(offset, who); +/* else if ((offset >= 0xF00010) && (offset < 0xF00028)) + return OPReadByte(offset, who);*/ else if ((offset >= 0xF02200) && (offset < 0xF022A0)) return BlitterReadByte(offset, who); else if (offset == 0xF00050) @@ -1251,8 +1257,8 @@ if (offset >= 0xF02000 && offset <= 0xF020FF) return GPUReadWord(offset, who); else if ((offset >= GPU_WORK_RAM_BASE) && (offset < GPU_WORK_RAM_BASE + 0x1000)) return GPUReadWord(offset, who); - else if ((offset >= 0xF00010) && (offset < 0xF00028)) - return OPReadWord(offset, who); +/* else if ((offset >= 0xF00010) && (offset < 0xF00028)) + return OPReadWord(offset, who);*/ else if ((offset >= 0xF02200) && (offset < 0xF022A0)) return BlitterReadWord(offset, who); else if (offset == 0xF00050) @@ -1287,11 +1293,11 @@ void TOMWriteByte(uint32 offset, uint8 data, uint32 who/*=UNKNOWN*/) GPUWriteByte(offset, data, who); return; } - else if ((offset >= 0xF00010) && (offset < 0xF00028)) +/* else if ((offset >= 0xF00010) && (offset < 0xF00028)) { OPWriteByte(offset, data, who); return; - } + }*/ else if ((offset >= 0xF02200) && (offset < 0xF022A0)) { BlitterWriteByte(offset, data, who); @@ -1365,11 +1371,11 @@ if (offset >= 0xF02000 && offset <= 0xF020FF) TOMWriteByte(offset, data >> 8); TOMWriteByte(offset+1, data & 0xFF); }*/ - else if ((offset >= 0xF00010) && (offset < 0xF00028)) +/* else if ((offset >= 0xF00010) && (offset < 0xF00028)) { OPWriteWord(offset, data, who); return; - } + }*/ else if (offset == 0xF00050) { tom_timer_prescaler = data; @@ -1412,6 +1418,8 @@ if (offset >= 0xF02000 && offset <= 0xF020FF) offset &= 0x3FFF; if (offset == 0x28) // VMODE (Why? Why not OBF?) +//Actually, we should check to see if the Enable bit of VMODE is set before doing this... !!! FIX !!! +#warning Actually, we should check to see if the Enable bit of VMODE is set before doing this... !!! FIX !!! objectp_running = 1; if (offset >= 0x30 && offset <= 0x4E) diff --git a/src/tom.h b/src/tom.h index faaf4f7..091cd0c 100644 --- a/src/tom.h +++ b/src/tom.h @@ -5,7 +5,8 @@ #ifndef __TOM_H__ #define __TOM_H__ -#include "jaguar.h" +//#include "jaguar.h" +#include "types.h" #define VIDEO_MODE_16BPP_CRY 0 #define VIDEO_MODE_24BPP_RGB 1 @@ -54,5 +55,6 @@ void TOMResetBackbuffer(uint32 * backbuffer); extern uint32 tom_width; extern uint32 tom_height; +extern uint8 tom_ram_8[]; #endif // __TOM_H__ diff --git a/src/unzip.h b/src/unzip.h index 5137192..d8ddb31 100644 --- a/src/unzip.h +++ b/src/unzip.h @@ -1,7 +1,6 @@ #ifndef __UNZIP_H__ #define __UNZIP_H__ -//#include "types.h" #include #include diff --git a/src/video.cpp b/src/video.cpp index cbf1ffe..4507363 100644 --- a/src/video.cpp +++ b/src/video.cpp @@ -4,10 +4,12 @@ // by James L. Hammons // +#include "video.h" + #include "tom.h" #include "sdlemu_opengl.h" #include "settings.h" -#include "video.h" +#include "log.h" // External global variables diff --git a/src/vj.cpp b/src/vj.cpp index 309ec23..2e2480e 100644 --- a/src/vj.cpp +++ b/src/vj.cpp @@ -7,7 +7,8 @@ // #ifdef __GCCUNIX__ -#include // Is this necessary anymore? +//#include // Is this necessary anymore? +//Looks like the answer is no... #endif #include @@ -17,6 +18,9 @@ #include "gui.h" #include "sdlemu_opengl.h" #include "settings.h" // Pull in "vjs" struct +#include "log.h" +#include "version.h" +#include "memory.h" // Uncomment this to use built-in BIOS/CD-ROM BIOS // You'll need a copy of jagboot.h & jagcd.h for this to work...! @@ -37,7 +41,7 @@ extern uint8 * jaguar_bootRom; extern uint8 * jaguar_CDBootROM; // Global variables (export capable) -//should these even be here anymore? +//should these even be here anymore? prolly not... bool finished = false; bool showGUI = false; @@ -132,11 +136,11 @@ int main(int argc, char * argv[]) if (!strcmp(argv[i], "-ntsc")) vjs.hardwareTypeNTSC = true; - if (!strcmp(argv[i], "-help") || !strcmp(argv[i], "-?")) + if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-?")) { printf("Usage: \n\n"); printf("vj [romfile] [switches]\n"); - printf(" -? or -help : Display usage and switches \n"); + printf(" -? or --help : Display usage and switches \n"); printf(" -frameskip 1-10 : Enable frameskip 1 - 10 (default: none) \n"); printf(" -joystick : Enable joystick/gamepad \n"); printf(" -joyport 0-3 : Select desired joystick port \n"); @@ -160,8 +164,6 @@ int main(int argc, char * argv[]) // Set up SDL library if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO | SDL_INIT_TIMER) < 0) -// | SDL_INIT_CDROM) < 0) -// | SDL_INIT_CDROM | SDL_INIT_NOPARACHUTE) < 0) { WriteLog("VJ: Could not initialize the SDL library: %s\n", SDL_GetError()); return -1; @@ -217,7 +219,6 @@ WriteLog("About to start GUI...\n"); log_done(); // Free SDL components last...! -// SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO | SDL_INIT_TIMER | SDL_INIT_CDROM); SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO | SDL_INIT_TIMER); SDL_Quit(); -- 2.37.2