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 <stdio.h>
void disassemble_6502(byte* buffer, word pc) {
printf("%04X ", pc);
//returns the length of the disassembled line
char* disassemble_6502_to_string(byte* buffer, word pc) {
static char dasm_buffer[64];
byte* code = &buffer[pc];
int bytes = 1;
char op[128] = "";
char op[32] = "";
switch (*code) {
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_ZPX: sprintf(op, "ADC $%02X,X", code[1]); bytes = 2; break;
@ -164,23 +165,30 @@ void disassemble_6502(byte* buffer, word pc) {
default:
printf("UNKNOWN %02x", *code);
sprintf(op, "UNKNOWN %02x", *code);
}
//print opcode
printf("%02X ", *code);
char arg1[3];
if (bytes > 1) {
printf("%02x ", code[1]);
sprintf(arg1,"%02X", code[1]);
}
else {
printf(" ");
sprintf(arg1," ");
}
char arg2[3];
if (bytes > 2) {
printf("%02x ", code[2]);
sprintf(arg2,"%02X", code[2]);
}
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
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);
state.pc = NESTEST_DST;
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);
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()
{
run_nestest();
//run_tests();
//run_nestest();
run_tests();
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);
// }
//}