Refactor common functionality into zelda3 namespace; remove references to core::common
This commit is contained in:
72
src/app/zelda3/hyrule_magic.cc
Normal file
72
src/app/zelda3/hyrule_magic.cc
Normal file
@@ -0,0 +1,72 @@
|
||||
#include "hyrule_magic.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace zelda3 {
|
||||
|
||||
namespace {
|
||||
|
||||
// "load little endian value at the given byte offset and shift to get its
|
||||
// value relative to the base offset (powers of 256, essentially)"
|
||||
unsigned ldle(uint8_t const *const p_arr, unsigned const p_index) {
|
||||
uint32_t v = p_arr[p_index];
|
||||
v <<= (8 * p_index);
|
||||
return v;
|
||||
}
|
||||
|
||||
void stle(uint8_t *const p_arr, size_t const p_index, unsigned const p_val) {
|
||||
uint8_t v = (p_val >> (8 * p_index)) & 0xff;
|
||||
p_arr[p_index] = v;
|
||||
}
|
||||
|
||||
void stle0(uint8_t *const p_arr, unsigned const p_val) {
|
||||
stle(p_arr, 0, p_val);
|
||||
}
|
||||
|
||||
void stle1(uint8_t *const p_arr, unsigned const p_val) {
|
||||
stle(p_arr, 1, p_val);
|
||||
}
|
||||
|
||||
void stle2(uint8_t *const p_arr, unsigned const p_val) {
|
||||
stle(p_arr, 2, p_val);
|
||||
}
|
||||
|
||||
void stle3(uint8_t *const p_arr, unsigned const p_val) {
|
||||
stle(p_arr, 3, p_val);
|
||||
}
|
||||
|
||||
// Helper function to get the first byte in a little endian number
|
||||
uint32_t ldle0(uint8_t const *const p_arr) { return ldle(p_arr, 0); }
|
||||
|
||||
// Helper function to get the second byte in a little endian number
|
||||
uint32_t ldle1(uint8_t const *const p_arr) { return ldle(p_arr, 1); }
|
||||
|
||||
// Helper function to get the third byte in a little endian number
|
||||
uint32_t ldle2(uint8_t const *const p_arr) { return ldle(p_arr, 2); }
|
||||
|
||||
// Helper function to get the third byte in a little endian number
|
||||
uint32_t ldle3(uint8_t const *const p_arr) { return ldle(p_arr, 3); }
|
||||
|
||||
} // namespace
|
||||
|
||||
void stle16b_i(uint8_t *const p_arr, size_t const p_index,
|
||||
uint16_t const p_val) {
|
||||
stle16b(p_arr + (p_index * 2), p_val);
|
||||
}
|
||||
|
||||
void stle16b(uint8_t *const p_arr, uint16_t const p_val) {
|
||||
stle0(p_arr, p_val);
|
||||
stle1(p_arr, p_val);
|
||||
}
|
||||
|
||||
uint16_t ldle16b(uint8_t const *const p_arr) {
|
||||
uint16_t v = 0;
|
||||
v |= (ldle0(p_arr) | ldle1(p_arr));
|
||||
return v;
|
||||
}
|
||||
|
||||
uint16_t ldle16b_i(uint8_t const *const p_arr, size_t const p_index) {
|
||||
return ldle16b(p_arr + (2 * p_index));
|
||||
}
|
||||
|
||||
} // namespace zelda3
|
||||
} // namespace yaze
|
||||
36
src/app/zelda3/hyrule_magic.h
Normal file
36
src/app/zelda3/hyrule_magic.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifndef YAZE_APP_ZELDA3_HYRULE_MAGIC_H
|
||||
#define YAZE_APP_ZELDA3_HYRULE_MAGIC_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/strings/str_cat.h"
|
||||
#include "absl/strings/str_format.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace zelda3 {
|
||||
/**
|
||||
* @brief Store little endian 16-bit value using a byte pointer, offset by an
|
||||
* index before dereferencing
|
||||
*/
|
||||
void stle16b_i(uint8_t *const p_arr, size_t const p_index,
|
||||
uint16_t const p_val);
|
||||
|
||||
void stle16b(uint8_t *const p_arr, uint16_t const p_val);
|
||||
|
||||
/**
|
||||
* @brief Load little endian halfword (16-bit) dereferenced from an arrays of
|
||||
* bytes. This version provides an index that will be multiplied by 2 and added
|
||||
* to the base address.
|
||||
*/
|
||||
uint16_t ldle16b_i(uint8_t const *const p_arr, size_t const p_index);
|
||||
|
||||
// Load little endian halfword (16-bit) dereferenced from
|
||||
uint16_t ldle16b(uint8_t const *const p_arr);
|
||||
|
||||
} // namespace zelda3
|
||||
} // namespace yaze
|
||||
|
||||
#endif // YAZE_APP_ZELDA3_HYRULE_MAGIC_H
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "app/rom.h"
|
||||
#include "app/zelda3/hyrule_magic.h"
|
||||
#include "util/macro.h"
|
||||
|
||||
namespace yaze {
|
||||
@@ -923,9 +924,9 @@ void Tracker::SaveSongs(Rom &rom) {
|
||||
q = 1;
|
||||
|
||||
for (n = 0; n < 8; n++) {
|
||||
core::stle16b_i(trtbl->buf, n, SaveSpcCommand(rom, sp->tbl[n], p, q));
|
||||
stle16b_i(trtbl->buf, n, SaveSpcCommand(rom, sp->tbl[n], p, q));
|
||||
|
||||
if (core::ldle16b_i(trtbl->buf, n)) AddSpcReloc(trtbl, n << 1), q = 0;
|
||||
if (ldle16b_i(trtbl->buf, n)) AddSpcReloc(trtbl, n << 1), q = 0;
|
||||
}
|
||||
|
||||
sp->addr = trtbl->start;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
set(
|
||||
YAZE_APP_ZELDA3_SRC
|
||||
app/zelda3/hyrule_magic.cc
|
||||
app/zelda3/overworld/overworld_map.cc
|
||||
app/zelda3/overworld/overworld.cc
|
||||
app/zelda3/screen/inventory.cc
|
||||
|
||||
Reference in New Issue
Block a user