refactored the read_word function to allow for wrap

This commit is contained in:
jborza 2019-05-07 21:04:04 +02:00
parent 94aea533a9
commit c4b2b70d96
3 changed files with 32 additions and 36 deletions

View File

@ -12,13 +12,14 @@ word fetch_word(State6502* state) {
}
word read_word(State6502 * state, word address) {
if ((address & 0xFF) == 0xFF)
{
return state->memory[address] | state->memory[address - 0xFF] << 8;
}
else {
return state->memory[address] | state->memory[address + 1] << 8;
}
word read_word_wrap(State6502 * state, word address) {
word address_low = address;
//page wraparound
word address_high = (address_low & 0xFF) == 0xFF ? address - 0xFF : address_low + 1;
return state->memory[address_low] | state->memory[address_high] << 8;
}
word get_address_zero_page(State6502 * state) {
@ -84,15 +85,9 @@ byte get_byte_absolute_y(State6502* state) {
}
word get_address_indirect_jmp(State6502 * state) {
//AN INDIRECT JUMP MUST NEVER USE A VECTOR BEGINNING ON THE LAST BYTE OF A PAGE
word indirect_address = fetch_word(state);
if ((indirect_address & 0xFF) == 0xFF) {
//avoid crossing the page boundary
return state->memory[indirect_address] | state->memory[indirect_address - 0xFF] << 8;
}
else {
return read_word(state, indirect_address);
}
//AN INDIRECT JUMP MUST NEVER USE A VECTOR BEGINNING ON THE LAST BYTE OF A PAGE
return read_word_wrap(state, indirect_address);
}
word get_address_indirect_x(State6502 * state) {
@ -100,7 +95,7 @@ word get_address_indirect_x(State6502* state) {
//zero-page address is added to x register
byte indirect_address = fetch_byte(state) + state->x;
//pointing to address of a word holding the address of the operand
word address = read_word(state, indirect_address);
word address = read_word_wrap(state, indirect_address);
return address;
}

View File

@ -7,6 +7,8 @@ word fetch_word(State6502* state);
word read_word(State6502* state, word address);
word read_word_wrap(State6502* state, word address);
word get_address_zero_page(State6502* state);
byte get_byte_zero_page(State6502* state);

View File

@ -2533,7 +2533,6 @@ void run_suite(fp * *suite, int size) {
}
void run_tests() {
test_LDA_INDX_wraparound();
RUN(tests_ror);
RUN(tests_asl);
RUN(tests_rti);