mirror of
https://github.com/tdinucci/6502-emulator.git
synced 2024-06-17 22:29:39 +00:00
69 lines
2.1 KiB
C++
69 lines
2.1 KiB
C++
#include "utils.h"
|
|
|
|
namespace emu_6502 {
|
|
string uint_to_hex(uint64_t value) {
|
|
stringstream ss;
|
|
ss << hex << value;
|
|
|
|
return ss.str();
|
|
}
|
|
|
|
uint8_t get_zpg_address(uint8_t offset) {
|
|
return offset;
|
|
}
|
|
|
|
uint8_t get_zpg_x_address(uint8_t offset, Cpu& cpu) {
|
|
// expect wrap around
|
|
return offset + cpu.get_x().get_value();
|
|
}
|
|
|
|
uint8_t get_zpg_y_address(uint8_t offset, Cpu& cpu) {
|
|
// expect wrap around
|
|
return offset + cpu.get_y().get_value();
|
|
}
|
|
|
|
uint16_t get_abs_address(uint8_t low_byte, uint8_t high_byte) {
|
|
uint16_t address = (high_byte << 8) + low_byte;
|
|
return address;
|
|
}
|
|
|
|
uint16_t get_abs_x_address(uint8_t low_byte, uint8_t high_byte, Cpu& cpu) {
|
|
uint16_t address = (high_byte << 8) + low_byte + cpu.get_x().get_value();
|
|
return address;
|
|
}
|
|
|
|
uint16_t get_abs_y_address(uint8_t low_byte, uint8_t high_byte, Cpu& cpu) {
|
|
uint16_t address = (high_byte << 8) + low_byte + cpu.get_y().get_value();
|
|
return address;
|
|
}
|
|
|
|
uint16_t get_abs_x_address(Machine& machine, Cpu& cpu) {
|
|
auto low = machine.read_program_byte();
|
|
auto high = machine.read_program_byte();
|
|
return get_abs_x_address(low, high, machine.get_cpu());
|
|
}
|
|
|
|
uint16_t get_abs_y_address(Machine& machine, Cpu& cpu) {
|
|
auto low = machine.read_program_byte();
|
|
auto high = machine.read_program_byte();
|
|
return get_abs_y_address(low, high, machine.get_cpu());
|
|
}
|
|
|
|
uint16_t get_ind_x_address(uint8_t offset, Machine& machine) {
|
|
uint8_t paddress = machine.get_cpu().get_x().get_value() + offset;
|
|
auto low = machine.get_memory().get_at(paddress);
|
|
auto high = machine.get_memory().get_at(paddress + 1);
|
|
uint16_t address = (high << 8) + low;
|
|
|
|
return address;
|
|
}
|
|
|
|
uint16_t get_ind_y_address(uint8_t offset, Machine& machine) {
|
|
auto low = machine.get_memory().get_at(offset);
|
|
auto high = machine.get_memory().get_at(offset + 1);
|
|
auto y = machine.get_cpu().get_y().get_value();
|
|
uint16_t address = (high << 8) + low + y;
|
|
|
|
return address;
|
|
}
|
|
} |