Skip to content

Commit

Permalink
Matched MidiReader, FileChecksum, Debug (#282)
Browse files Browse the repository at this point in the history
* misc rnd work

* rndtexrenderer work

* rndoverlay work

* rndconsole work

* buttonholder tweaks

* midi inlines added

* midi tweaks

* actual midi reader progress

* midireader work

* midireader metaevent work

* match midireader meta events

* almost done with midireader

* match midireader

* match filechecksum, attempt to link debug

* Debug has link issues

* debug matched
  • Loading branch information
rjkiv authored Jul 9, 2024
1 parent 8f3d676 commit 2698386
Show file tree
Hide file tree
Showing 28 changed files with 489 additions and 172 deletions.
14 changes: 8 additions & 6 deletions config/SZBE69_B8/objects.json
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@

"system/math/Color.cpp": "NonMatching",
"system/math/Decibels.cpp": "Matching",
"system/math/FileChecksum.cpp": "NonMatching",
"system/math/FileChecksum.cpp": "Matching",
"system/math/Geo.cpp": "NonMatching",
"system/math/Interp.cpp": "Matching",
"system/math/Primes.cpp": "Matching",
Expand All @@ -239,13 +239,12 @@
"system/meta/ConnectionStatusPanel.cpp": "Matching",
"system/meta/CreditsPanel.cpp": "Matching",
"system/meta/DataArraySongInfo.cpp": "NonMatching",
"system/meta/FixedSizeSaveable.cpp": "NonMatching",
"system/meta/FixedSizeSaveableStream.cpp": "Matching",
"system/meta/HAQManager.cpp": "Matching",
"system/meta/FixedSizeSaveable.cpp": {
"status": "LinkIssues",
"comment": "std::type_info issues"
},
"system/meta/FixedSizeSaveableStream.cpp": "Matching",
"system/meta/HAQManager.cpp": "Matching",
"system/meta/HeldButtonPanel.cpp": "NonMatching",
"system/meta/MemcardAction.cpp": "Matching",
"system/meta/Meta.cpp": "NonMatching",
Expand All @@ -263,7 +262,7 @@
"system/midi/DataEventList.cpp": "NonMatching",
"system/midi/MidiParser.cpp": { "status": "NonMatching", "extra_cflags": [ "-fp_contract off" ] },
"system/midi/MidiParserMgr.cpp": "NonMatching",
"system/midi/MidiReader.cpp": "NonMatching",
"system/midi/MidiReader.cpp": "Matching",
"system/midi/MidiReceiver.cpp": "Matching",
"system/midi/MidiVarLen.cpp": "Matching",

Expand Down Expand Up @@ -304,7 +303,10 @@
"system/os/ContentMgr.cpp": "NonMatching",
"system/os/CritSec.cpp": "Matching",
"system/os/DateTime.cpp": "NonMatching",
"system/os/Debug.cpp": "NonMatching",
"system/os/Debug.cpp": {
"status": "Matching",
"comment": "kAssertStr's appearance relative to stlport stuff"
},
"system/os/File.cpp": "NonMatching",
"system/os/File_Wii.cpp": "Matching",
"system/os/FileCache.cpp": "NonMatching",
Expand Down
17 changes: 12 additions & 5 deletions src/system/math/FileChecksum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,19 @@ bool HasFileChecksumData(){
}

unsigned char* GetFileChecksum(const char* cc, bool b){
const char* fname = b ? FileGetName(cc) : FileLocalize(cc, 0);
std::vector<ChecksumData>::iterator it = gChecksumData.begin();
std::vector<ChecksumData>::iterator itEnd = gChecksumData.end();
// don't question it, okay? it works lol
std::vector<ChecksumData>::iterator itEnd;
FileChecksum* sumEnd;
std::vector<ChecksumData>::iterator it;
FileChecksum* sum;
const char* fname;

fname = b ? FileGetName(cc) : FileLocalize(cc, 0);
it = gChecksumData.begin();
itEnd = gChecksumData.end();
for(; it != itEnd; it++){
FileChecksum* sum = (*it).start;
FileChecksum* sumEnd = (*it).end;
sum = (*it).start;
sumEnd = (*it).end;
for(; sum != sumEnd; sum++){
if(strcmp(sum->file, fname) == 0){
return sum->checksum;
Expand Down
4 changes: 4 additions & 0 deletions src/system/math/MathFuncs.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ inline float pow_f(double x, double y){
return pow(x, y);
}

inline double pow_d(double x, double y){
return pow(x, y);
}

inline float sin_f(double d){
return sin(d);
}
Expand Down
24 changes: 17 additions & 7 deletions src/system/meta/ButtonHolder.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "meta/ButtonHolder.h"
#include "obj/Data.h"
#include "utl/Symbols.h"

ProcessedButtonDownMsg::ProcessedButtonDownMsg(LocalUser* user, JoypadButton butt, JoypadAction act, int i, bool b)
: Message(Type(), DataNode(user), DataNode(butt), DataNode(act), DataNode(i), DataNode(b)){
Expand All @@ -10,33 +11,42 @@ LocalUser* ProcessedButtonDownMsg::GetUser() const {
return mData->Obj<LocalUser>(2);
}

// fn_805098A0
ActionRec::ActionRec(JoypadAction act, float f, UserMgr* umgr) : mAction(act), mHoldTime(f), mPresses() {
std::vector<LocalUser*> uservec;
umgr->GetLocalUsers(uservec);

for(int i = 0; i < uservec.size(); i++){
PressRec prec;
mPresses.push_back(prec);
mPresses[i].a = 0;
mPresses[i].iUser = 0;
mPresses[i].c = 0;
mPresses[i].d = 0;
mPresses[i].e = 0;
mPresses[i].iUser = uservec[i];
mPresses[i].unk4 = 0;
mPresses[i].unk8 = 0;
mPresses[i].unkc = 0;
mPresses[i].unk10 = 0;
}
}

// fn_80509E7C
PressRec& ActionRec::GetPressRec(int padnum){
for(int i = 0; i < mPresses.size(); i++){

if(mPresses[i].iUser->GetPadNum() == padnum) return mPresses[i];
}
MILO_FAIL("No PressRec exists for this padnum");
return *mPresses.begin();
}

// fn_80509F10
ButtonHolder::ButtonHolder(Hmx::Object* obj, UserMgr* umgr){
mCallback = obj;
MILO_ASSERT(mCallback, 0x40);

if(umgr) mUserMgr = umgr;
else mUserMgr = TheUserMgr;
}
}

BEGIN_HANDLERS(ButtonHolder)
HANDLE(set_hold_actions, OnSetHoldActions)
HANDLE_MESSAGE(ButtonDownMsg)
HANDLE_CHECK(0xE3)
END_HANDLERS
29 changes: 18 additions & 11 deletions src/system/meta/ButtonHolder.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "os/User.h"
#include "os/UserMgr.h"
#include "os/Joypad.h"
#include "os/JoypadMsgs.h"
#include <vector>

BEGIN_MESSAGE(ProcessedButtonDownMsg, processed_button_down, LocalUser*, JoypadButton, JoypadAction, int, bool);
Expand All @@ -12,15 +13,17 @@ BEGIN_MESSAGE(ProcessedButtonDownMsg, processed_button_down, LocalUser*, JoypadB
JoypadButton GetButton() const { return (JoypadButton)mData->Int(3); }
JoypadAction GetAction() const { return (JoypadAction)mData->Int(4); }
int GetPadNum() const { return mData->Int(5); }
bool IsHeldDown() const { return mData->Int(6) != 0; } // TODO: figure out what this bool represents
bool IsHeldDown() const { return mData->Int(6) != 0; }
END_MESSAGE;

struct PressRec {
PressRec() : a(0), iUser(0), c(0), d(0), e(0) {}
// PressRec(){}

int a;
User* iUser;
int c, d, e;
LocalUser* iUser;
int unk4;
int unk8;
float unkc;
int unk10;
};

// // RB2
Expand All @@ -39,22 +42,26 @@ class ActionRec {
ActionRec(JoypadAction, float, UserMgr*);
PressRec& GetPressRec(int);

JoypadAction mAction;
float mHoldTime;
std::vector<PressRec> mPresses;
JoypadAction mAction; // 0x0
float mHoldTime; // 0x4
std::vector<PressRec> mPresses; // 0x8
};

class ButtonHolder : public Hmx::Object {
public:
ButtonHolder(Hmx::Object*, UserMgr*);
virtual ~ButtonHolder(){}
virtual DataNode Handle(DataArray*, bool);

void Poll();
void ClearHeldButtons();
void SetHoldActions(std::vector<ActionRec>&);
DataNode OnSetHoldActions(DataArray*);
DataNode OnMsg(const ButtonDownMsg&);

Hmx::Object* mCallback;
UserMgr* mUserMgr;
std::vector<ActionRec> mActionRecs;
Hmx::Object* mCallback; // 0x1c
UserMgr* mUserMgr; // 0x20
std::vector<ActionRec> mActionRecs; // 0x24
};

#endif
19 changes: 18 additions & 1 deletion src/system/midi/Midi.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,23 @@ enum State {

class MidiChunkID : public ChunkID {
public:
MidiChunkID(BinStream& bs) : ChunkID(bs) {}
MidiChunkID(const char* str) : ChunkID(str) {}
static MidiChunkID kMThd;
static MidiChunkID kMTrk;
};

class MidiChunkHeader {
public:
MidiChunkHeader(BinStream& bs) : mID(bs) {
mLength = 0;
bs >> mLength;
}
// total size: 0x8
MidiChunkID mID; // offset 0x0, size 0x4
unsigned int mLength; // offset 0x4, size 0x4
};

class MidiReceiver {
public:
MidiReceiver();
Expand Down Expand Up @@ -71,6 +83,11 @@ class MidiReader {
void ReadEvent(BinStream&);
void ReadTrackHeader(BinStream&);
void ReadFileHeader(BinStream&);
void ProcessMidiList();
void ReadMidiEvent(int, unsigned char, unsigned char, BinStream&);
void ReadSystemEvent(int, unsigned char, BinStream&);
void QueueChannelMsg(int, unsigned char, unsigned char, unsigned char);
void ReadMetaEvent(int, unsigned char, BinStream&);

void Error(const char* msg) {
mRcvr.Error(msg, mCurTick);
Expand All @@ -91,7 +108,7 @@ class MidiReader {
int mCurTick; // offset 0x2C, size 0x4
unsigned char mPrevStatus; // offset 0x30, size 0x1
class String mCurTrackName; // offset 0x34, size 0xC
std::vector<String> mTrackNames;
std::vector<String> mTrackNames; // 0x40
std::vector<Midi> mMidiList;
int mMidiListTick;
bool (* mLessFunc)(const struct Midi &, const struct Midi &);
Expand Down
36 changes: 9 additions & 27 deletions src/system/midi/MidiConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,21 @@ unsigned char MidiGetStatus(unsigned char uc){

}

unsigned char MidiGetType(unsigned char uc){
return uc & 0xF0;
inline bool MidiIsStatus(unsigned char status){
return status & 0x80;
}

bool MidiIdk(unsigned char uc){
return (MidiGetType(uc) & 0xF0) == 0xF0;
inline unsigned char MidiGetType(unsigned char status){
MILO_ASSERT(MidiIsStatus(status), 0x2f);
return status & 0xF0;
}

unsigned char MidiGetChannel(unsigned char uc){

inline bool MidiIsSystem(unsigned char uc){
return MidiGetType(uc) == 0xF0;
}

// MidiReader::ReadEvent(BinStream&)
// debug
// else {
// bVar1 = false;
// if (-1 < (char)local_27[0]) {
// pcVar3 = ::MakeString(kAssertStr,@STRING@MidiGetType__FUc_80BFB4D8,0x2f,
// @STRING@MidiGetType__FUc@0_80BFB4C0);
// Debug::Fail((Debug *)TheDebug,pcVar3);
// }
// if (((byte)MVar2 & 0xf0) != 0xf0) {
// this[0x30] = local_27[0];
// }
// }
unsigned char MidiGetChannel(unsigned char uc){

// retail
// else {
// bVar1 = false;
// iVar2 = fn_8048DBE8(local_17[0]);
// if (iVar2 == 0) {
// *(uchar *)(param_1 + 0x30) = local_17[0];
// }
// }
}

#endif
2 changes: 1 addition & 1 deletion src/system/midi/MidiParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ DataNode* MidiParser::mpBeforeDeltaSec = 0;
DataNode* MidiParser::mpAfterDeltaSec = 0;

void MidiParser::Init(){
Hmx::Object::RegisterFactory(StaticClassName(), NewObject);
MidiParser::Register();
MidiParser::mpStart = DataVariable("mp.start");
MidiParser::mpEnd = DataVariable("mp.end");
MidiParser::mpLength = DataVariable("mp.length");
Expand Down
3 changes: 3 additions & 0 deletions src/system/midi/MidiParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ class MidiParser : public MsgSource { // 0xd0

static Hmx::Object* NewObject();
static void Init();
static void Register(){
REGISTER_OBJ_FACTORY(MidiParser)
}

static DataNode* mpStart;
static DataNode* mpEnd;
Expand Down
Loading

0 comments on commit 2698386

Please sign in to comment.