mirror of
https://github.com/jborza/emu6502.git
synced 2024-11-21 08:31:23 +00:00
attempt to run nestest
This commit is contained in:
parent
be5bd3aa27
commit
2b52c43605
6
cpu.c
6
cpu.c
@ -30,6 +30,12 @@ void set_NZ_flags(State6502 * state, byte value) {
|
||||
state->flags.n = is_negative(value);
|
||||
}
|
||||
|
||||
byte flags_as_byte(State6502* state) {
|
||||
byte flags_value;
|
||||
memcpy(&flags_value, &state->flags, sizeof(Flags));
|
||||
return flags_value;
|
||||
}
|
||||
|
||||
void clear_flags(State6502 * state) {
|
||||
state->flags.b =
|
||||
state->flags.c =
|
||||
|
1
cpu.h
1
cpu.h
@ -8,3 +8,4 @@ int emulate_6502_op(State6502* state);
|
||||
|
||||
void clear_flags(State6502* state);
|
||||
void clear_state(State6502* state);
|
||||
byte flags_as_byte(State6502* state);
|
@ -134,7 +134,7 @@ void print_frame() {
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
int main2(int argc, char* argv[]) {
|
||||
State6502 state;
|
||||
clear_state(&state);
|
||||
state.memory = malloc(MEMORY_SIZE);
|
||||
|
@ -182,7 +182,5 @@ void disassemble_6502(byte* buffer, word pc) {
|
||||
else {
|
||||
printf(" ");
|
||||
}
|
||||
printf(op);
|
||||
|
||||
printf("\n");
|
||||
printf(" %s", op);
|
||||
}
|
45
emu6502.c
45
emu6502.c
@ -9,33 +9,46 @@
|
||||
#include "disassembler.h"
|
||||
#include "opcodes.h"
|
||||
#include "test6502.h"
|
||||
#include <errno.h>
|
||||
#include <direct.h>
|
||||
|
||||
byte* read_game() {
|
||||
FILE* file = fopen("..\\bins\\tetris.bin", "r");
|
||||
//byte* buffer = malloc(0x800);
|
||||
byte buffer[32];
|
||||
int read = fread(&buffer, sizeof(byte), 32, file);
|
||||
#define NESTEST_SIZE 0x4000
|
||||
#define NESTEST_DST 0xC000
|
||||
#define MEMORY_SIZE 0xFFFF
|
||||
|
||||
byte* read_nestest() {
|
||||
FILE* file = fopen("nestest\\nestest.bin", "rb");
|
||||
if (!file) {
|
||||
int err = errno;
|
||||
exit(1);
|
||||
}
|
||||
byte buffer[NESTEST_SIZE];
|
||||
int read = fread(&buffer, sizeof(byte), NESTEST_SIZE, file);
|
||||
fclose(file);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void emulate_game() {
|
||||
void run_nestest() {
|
||||
State6502 state;
|
||||
//FILE* file = fopen("..\\bins\\tetris.bin", "r");
|
||||
clear_state(&state);
|
||||
state.memory = read_game();
|
||||
for (int i = 0; i < 100; i++) {
|
||||
disassemble_6502(state.memory, i);
|
||||
}
|
||||
state.memory = malloc(MEMORY_SIZE);
|
||||
memset(state.memory, 0, MEMORY_SIZE);
|
||||
byte* bin = read_nestest();
|
||||
//const word TARGET = 0xC000;
|
||||
memcpy(state.memory + NESTEST_DST, bin, NESTEST_SIZE);
|
||||
memcpy(state.memory + 0x8000, bin, NESTEST_SIZE);
|
||||
state.pc = NESTEST_DST;
|
||||
do{
|
||||
disassemble_6502(state.memory, state.pc);
|
||||
emulate_6502_op(&state);
|
||||
printf(" A:%02X X:%02X Y:%02X P:%02X SP:%02X\n", state.a, state.x, state.y, flags_as_byte(&state), state.sp);
|
||||
} while (state.flags.b != 1);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
//emulate_game();
|
||||
run_tests();
|
||||
printf("All tests succeeded.\n");
|
||||
run_nestest();
|
||||
//run_tests();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -152,6 +152,7 @@
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="cpu.c" />
|
||||
<ClCompile Include="debugger_windows.c" />
|
||||
<ClCompile Include="disassembler.c" />
|
||||
<ClCompile Include="emu6502.c" />
|
||||
<ClCompile Include="memory.c" />
|
||||
|
@ -40,6 +40,7 @@ void print_all(State6502 * state) {
|
||||
void test_step(State6502 * state) {
|
||||
print_all(state);
|
||||
disassemble_6502(state->memory, state->pc);
|
||||
printf("\n");
|
||||
emulate_6502_op(state);
|
||||
print_all(state);
|
||||
}
|
||||
@ -48,6 +49,7 @@ void test_step_until_break(State6502 * state) {
|
||||
do {
|
||||
print_all(state);
|
||||
disassemble_6502(state->memory, state->pc);
|
||||
printf("\n");
|
||||
emulate_6502_op(state);
|
||||
} while (state->flags.b != 1);
|
||||
print_all(state);
|
||||
@ -1870,6 +1872,7 @@ void test_PHA_PLA() {
|
||||
//act
|
||||
for (int i = 0; i < 9; i++) {
|
||||
disassemble_6502(state.memory, state.pc);
|
||||
printf("\n");
|
||||
emulate_6502_op(&state);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user