mirror of
https://github.com/jborza/emu6502.git
synced 2024-11-24 12:30:48 +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);
|
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) {
|
void clear_flags(State6502 * state) {
|
||||||
state->flags.b =
|
state->flags.b =
|
||||||
state->flags.c =
|
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_flags(State6502* state);
|
||||||
void clear_state(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;
|
State6502 state;
|
||||||
clear_state(&state);
|
clear_state(&state);
|
||||||
state.memory = malloc(MEMORY_SIZE);
|
state.memory = malloc(MEMORY_SIZE);
|
||||||
|
@ -182,7 +182,5 @@ void disassemble_6502(byte* buffer, word pc) {
|
|||||||
else {
|
else {
|
||||||
printf(" ");
|
printf(" ");
|
||||||
}
|
}
|
||||||
printf(op);
|
printf(" %s", op);
|
||||||
|
|
||||||
printf("\n");
|
|
||||||
}
|
}
|
45
emu6502.c
45
emu6502.c
@ -9,33 +9,46 @@
|
|||||||
#include "disassembler.h"
|
#include "disassembler.h"
|
||||||
#include "opcodes.h"
|
#include "opcodes.h"
|
||||||
#include "test6502.h"
|
#include "test6502.h"
|
||||||
|
#include <errno.h>
|
||||||
|
#include <direct.h>
|
||||||
|
|
||||||
byte* read_game() {
|
#define NESTEST_SIZE 0x4000
|
||||||
FILE* file = fopen("..\\bins\\tetris.bin", "r");
|
#define NESTEST_DST 0xC000
|
||||||
//byte* buffer = malloc(0x800);
|
#define MEMORY_SIZE 0xFFFF
|
||||||
byte buffer[32];
|
|
||||||
int read = fread(&buffer, sizeof(byte), 32, file);
|
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);
|
fclose(file);
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void run_nestest() {
|
||||||
|
|
||||||
void emulate_game() {
|
|
||||||
State6502 state;
|
State6502 state;
|
||||||
//FILE* file = fopen("..\\bins\\tetris.bin", "r");
|
|
||||||
clear_state(&state);
|
clear_state(&state);
|
||||||
state.memory = read_game();
|
state.memory = malloc(MEMORY_SIZE);
|
||||||
for (int i = 0; i < 100; i++) {
|
memset(state.memory, 0, MEMORY_SIZE);
|
||||||
disassemble_6502(state.memory, i);
|
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()
|
int main()
|
||||||
{
|
{
|
||||||
//emulate_game();
|
run_nestest();
|
||||||
run_tests();
|
//run_tests();
|
||||||
printf("All tests succeeded.\n");
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,6 +152,7 @@
|
|||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="cpu.c" />
|
<ClCompile Include="cpu.c" />
|
||||||
|
<ClCompile Include="debugger_windows.c" />
|
||||||
<ClCompile Include="disassembler.c" />
|
<ClCompile Include="disassembler.c" />
|
||||||
<ClCompile Include="emu6502.c" />
|
<ClCompile Include="emu6502.c" />
|
||||||
<ClCompile Include="memory.c" />
|
<ClCompile Include="memory.c" />
|
||||||
|
@ -40,6 +40,7 @@ void print_all(State6502 * state) {
|
|||||||
void test_step(State6502 * state) {
|
void test_step(State6502 * state) {
|
||||||
print_all(state);
|
print_all(state);
|
||||||
disassemble_6502(state->memory, state->pc);
|
disassemble_6502(state->memory, state->pc);
|
||||||
|
printf("\n");
|
||||||
emulate_6502_op(state);
|
emulate_6502_op(state);
|
||||||
print_all(state);
|
print_all(state);
|
||||||
}
|
}
|
||||||
@ -48,6 +49,7 @@ void test_step_until_break(State6502 * state) {
|
|||||||
do {
|
do {
|
||||||
print_all(state);
|
print_all(state);
|
||||||
disassemble_6502(state->memory, state->pc);
|
disassemble_6502(state->memory, state->pc);
|
||||||
|
printf("\n");
|
||||||
emulate_6502_op(state);
|
emulate_6502_op(state);
|
||||||
} while (state->flags.b != 1);
|
} while (state->flags.b != 1);
|
||||||
print_all(state);
|
print_all(state);
|
||||||
@ -1870,6 +1872,7 @@ void test_PHA_PLA() {
|
|||||||
//act
|
//act
|
||||||
for (int i = 0; i < 9; i++) {
|
for (int i = 0; i < 9; i++) {
|
||||||
disassemble_6502(state.memory, state.pc);
|
disassemble_6502(state.memory, state.pc);
|
||||||
|
printf("\n");
|
||||||
emulate_6502_op(&state);
|
emulate_6502_op(&state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user