1
0
mirror of https://github.com/jborza/emu6502.git synced 2024-06-01 04:41:41 +00:00

LDA_INDX and LDA_INDY implementation + test

This commit is contained in:
jborza 2019-04-14 11:49:24 +02:00
parent 9dff007767
commit d4bbfaba95
2 changed files with 108 additions and 7 deletions

19
cpu.c
View File

@ -75,7 +75,7 @@ word pop_word(State6502 * state) {
}
word get_word(State6502 * state, word address) {
return state->memory[address] << 8 | state->memory[address + 1];
return state->memory[address] | state->memory[address + 1] << 8;
}
int emulate_6502_op(State6502 * state) {
@ -173,9 +173,22 @@ int emulate_6502_op(State6502 * state) {
}
case LDA_INDX:
{
}
//pre-indexed indirect
//zero-page address is added to x register
byte indirect_address = pop_byte(state) + state->x;
//pointing to address of a word holding the address of the operand
word address = get_word(state, indirect_address);
LDA(state, state->memory[address]);
break;
}
case LDA_INDY:
{
//post-indexed indirect
byte indirect_address = pop_byte(state);
word address = get_word(state, indirect_address) + state->y;
LDA(state, state->memory[address]);
break;
}
default:
unimplemented_instruction(state); break;
}

View File

@ -125,12 +125,100 @@ void test_LDA_ABS() {
test_cleanup(&state);
}
void test_LDA_ABSX() {
//initialize
State6502 state = create_blank_state();
state.x = 0x02;
//arrange
char program[] = { LDA_ABSX, 0x01, 0x04, 0xAA }; //LDA $0401,x
memcpy(state.memory, program, sizeof(program));
state.memory[0x403] = 0xAA;
//act
test_step(&state);
//assert
assertA(&state, 0xAA);
//cleanup
test_cleanup(&state);
}
void test_LDA_ABSY() {
//initialize
State6502 state = create_blank_state();
state.y = 0x02;
//arrange
char program[] = { LDA_ABSY, 0x01, 0x04, 0xAA }; //LDA $0401,y
memcpy(state.memory, program, sizeof(program));
state.memory[0x403] = 0xAA;
//act
test_step(&state);
//assert
assertA(&state, 0xAA);
//cleanup
test_cleanup(&state);
}
void test_LDA_INDX() {
//initialize
State6502 state = create_blank_state();
state.x = 0x05;
//arrange
char program[] = { LDA_INDX, 0x3E }; //LDA ($3E, x)
memcpy(state.memory, program, sizeof(program));
state.memory[0x0043] = 0xA9;
state.memory[0x0044] = 0x04;
state.memory[0x04A9] = 0xAA;
//act
test_step(&state);
//assert
assertA(&state, 0xAA);
//cleanup
test_cleanup(&state);
}
void test_LDA_INDY() {
//initialize
State6502 state = create_blank_state();
state.y = 0x05;
//arrange
char program[] = { LDA_INDY, 0x3E, 0x04, 0xAA }; //LDA ($3E),y
memcpy(state.memory, program, sizeof(program));
state.memory[0x3E] = 0xA0; //0x04A0
state.memory[0x3F] = 0x04;
state.memory[0x04A5] = 0xAA; //address 0x04A0 + 0x05 = 0x04A5
//act
test_step(&state);
//assert
assertA(&state, 0xAA);
//cleanup
test_cleanup(&state);
}
int main()
{
test_LDA_IMM();
test_LDA_ZP();
test_LDA_ZPX();
test_LDA_ABS();
//test_LDA_IMM();
//test_LDA_ZP();
//test_LDA_ZPX();
//test_LDA_ABS();
//test_LDA_ABSX();
//test_LDA_ABSY();
test_LDA_INDX();
test_LDA_INDY();
}
int emulate() {