mirror of
https://github.com/open-goal/jak-project
synced 2026-07-30 07:55:01 -04:00
integer constant program working up to ir
This commit is contained in:
@@ -33,7 +33,7 @@ enum class ListenerMessageKind : u16 {
|
||||
/*!
|
||||
* Type of message sent from compiler
|
||||
*/
|
||||
enum ListenerToTargetMsgKind {
|
||||
enum ListenerToTargetMsgKind : u16 {
|
||||
LTT_MSG_POKE = 1, //! "Poke" the game and have it flush buffers
|
||||
LTT_MSG_INSEPCT = 5, //! Inspect an object
|
||||
LTT_MSG_PRINT = 6, //! Print an object
|
||||
@@ -47,11 +47,15 @@ enum ListenerToTargetMsgKind {
|
||||
* TODO - there are other copies of this somewhere
|
||||
*/
|
||||
struct ListenerMessageHeader {
|
||||
Deci2Header deci2_header; //! The header used for DECI2 communication
|
||||
ListenerMessageKind msg_kind; //! GOAL Listener message kind
|
||||
u16 u6; //! Unknown
|
||||
u32 msg_size; //! Size of data after this header
|
||||
u64 u8; //! Unknown
|
||||
Deci2Header deci2_header; //! The header used for DECI2 communication
|
||||
union {
|
||||
ListenerMessageKind msg_kind; //! GOAL Listener message kind
|
||||
ListenerToTargetMsgKind ltt_msg_kind;
|
||||
};
|
||||
|
||||
u16 u6; //! Unknown
|
||||
u32 msg_size; //! Size of data after this header
|
||||
u64 u8; //! Unknown
|
||||
};
|
||||
|
||||
constexpr int DECI2_PORT = 8112; // TODO - is this a good choise?
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
#ifndef JAK_BINARYWRITER_H
|
||||
#define JAK_BINARYWRITER_H
|
||||
|
||||
#include <cassert>
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
|
||||
struct BinaryWriterRef {
|
||||
size_t offset;
|
||||
size_t write_size;
|
||||
};
|
||||
|
||||
class BinaryWriter {
|
||||
public:
|
||||
BinaryWriter() = default;
|
||||
|
||||
template<typename T>
|
||||
BinaryWriterRef add(const T& obj) {
|
||||
auto orig_size = data.size();
|
||||
data.resize(orig_size + sizeof(T));
|
||||
memcpy(data.data() + orig_size, &obj, sizeof(T));
|
||||
return {orig_size, sizeof(T)};
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void add_at_ref(const T& obj, const BinaryWriterRef& ref) {
|
||||
assert(ref.write_size == sizeof(T));
|
||||
assert(ref.offset + ref.write_size < get_size());
|
||||
memcpy(data.data() + ref.offset, &obj, sizeof(T));
|
||||
}
|
||||
|
||||
void add_str_len(const std::string& str, size_t len) {
|
||||
add_cstr_len(str.c_str(), len);
|
||||
}
|
||||
|
||||
void add_cstr_len(const char* str, size_t len) {
|
||||
size_t i = 0;
|
||||
while(*str) {
|
||||
data.push_back(*str);
|
||||
str++;
|
||||
i++;
|
||||
}
|
||||
|
||||
while(i < len) {
|
||||
data.push_back(0);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
BinaryWriterRef add_data(void* d, size_t len) {
|
||||
auto orig_size = data.size();
|
||||
data.resize(orig_size + len);
|
||||
memcpy(data.data() + orig_size, d, len);
|
||||
return {orig_size, len};
|
||||
}
|
||||
|
||||
size_t get_size() {
|
||||
return data.size();
|
||||
}
|
||||
|
||||
void* get_data() {
|
||||
return data.data();
|
||||
}
|
||||
|
||||
void write_to_file(const std::string& filename) {
|
||||
auto fp = fopen(filename.c_str(), "wb");
|
||||
if(!fp) throw std::runtime_error("failed to open " + filename);
|
||||
if(fwrite(get_data(), get_size(), 1, fp) != 1) throw std::runtime_error("failed to write " + filename);
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<uint8_t> data;
|
||||
};
|
||||
|
||||
#endif // JAK_BINARYWRITER_H
|
||||
Reference in New Issue
Block a user