1
0
mirror of https://github.com/jborza/emu6502.git synced 2024-06-26 06:29:28 +00:00

better handling of nestest

This commit is contained in:
jborza 2019-05-01 07:21:36 +02:00
parent 2b52c43605
commit a2f4d4ef72
3 changed files with 180 additions and 201 deletions

View File

@ -3,13 +3,14 @@
#include "disassembler.h" #include "disassembler.h"
#include <stdio.h> #include <stdio.h>
void disassemble_6502(byte* buffer, word pc) { //returns the length of the disassembled line
printf("%04X ", pc);
char* disassemble_6502_to_string(byte* buffer, word pc) {
static char dasm_buffer[64];
byte* code = &buffer[pc]; byte* code = &buffer[pc];
int bytes = 1; int bytes = 1;
char op[128] = ""; char op[32] = "";
switch (*code) { switch (*code) {
case ADC_IMM: sprintf(op, "ADC #$%02X", code[1]); bytes = 2; break; case ADC_IMM: sprintf(op, "ADC #$%02X", code[1]); bytes = 2; break;
case ADC_ZP: sprintf(op, "ADC $%02X", code[1]); bytes = 2; break; case ADC_ZP: sprintf(op, "ADC $%02X", code[1]); bytes = 2; break;
case ADC_ZPX: sprintf(op, "ADC $%02X,X", code[1]); bytes = 2; break; case ADC_ZPX: sprintf(op, "ADC $%02X,X", code[1]); bytes = 2; break;
@ -164,23 +165,30 @@ void disassemble_6502(byte* buffer, word pc) {
default: default:
printf("UNKNOWN %02x", *code); sprintf(op, "UNKNOWN %02x", *code);
} }
//print opcode char arg1[3];
printf("%02X ", *code);
if (bytes > 1) { if (bytes > 1) {
printf("%02x ", code[1]); sprintf(arg1,"%02X", code[1]);
} }
else { else {
printf(" "); sprintf(arg1," ");
} }
char arg2[3];
if (bytes > 2) { if (bytes > 2) {
printf("%02x ", code[2]); sprintf(arg2,"%02X", code[2]);
} }
else { else {
printf(" "); sprintf(arg2, " ");
} }
printf(" %s", op);
sprintf(dasm_buffer, "%04X %02X %s %s %s", pc, *code, arg1, arg2, op);
return dasm_buffer;
}
void disassemble_6502(byte* buffer, word pc) {
printf("%s", disassemble_6502_to_string(buffer, pc));
} }

View File

@ -1,2 +1,3 @@
#pragma once #pragma once
void disassemble_6502(byte* buffer, word pc); void disassemble_6502(byte* buffer, word pc);
char* disassemble_6502_to_string(byte* buffer, word pc);

View File

@ -39,45 +39,15 @@ void run_nestest() {
memcpy(state.memory + 0x8000, bin, NESTEST_SIZE); memcpy(state.memory + 0x8000, bin, NESTEST_SIZE);
state.pc = NESTEST_DST; state.pc = NESTEST_DST;
do{ do{
disassemble_6502(state.memory, state.pc); char* dasm = disassemble_6502_to_string(state.memory, state.pc);
printf("%-50s A:%02X X:%02X Y:%02X P:%02X SP:%02X\n", dasm, state.a, state.x, state.y, flags_as_byte(&state), state.sp);
emulate_6502_op(&state); 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); } while (state.flags.b != 1);
} }
int main() int main()
{ {
run_nestest(); //run_nestest();
//run_tests(); run_tests();
return 0; return 0;
} }
//void emulate() {
// State6502 state;
// memset(&state.memory, 0, sizeof(State6502));
// print_state(&state);
// clear_state(&state);
// byte* memory = read_game();
// //state.memory = read_game();
// state.memory = malloc(4096);
// memset(state.memory, 0, sizeof(byte) * 4096);
// state.memory[0] = 0xEA;
// state.memory[1] = 0x05; //ORA $a0
// state.memory[2] = 0xA0;
// state.memory[3] = 0xEA; //NOP
// state.memory[4] = 0x09; //ORA #$ff
// state.memory[5] = 0xff;
// state.memory[6] = 0xA9; //LDA
// state.memory[7] = 0x00; //0
// state.memory[8] = 0x0D; //ORA $1234
// state.memory[9] = 0x34;
// state.memory[10] = 0x02;
// state.memory[0xA0] = 0x13;
// state.memory[0x0234] = 0xAA;
//
// for (int i = 0; i < 10; i++) {
// print_all(&state);
// disassemble_6502(state.memory, state.pc);
// emulate_6502_op(&state);
// }
//}