mirror of
https://github.com/jborza/emu6502.git
synced 2024-11-21 23:31:19 +00:00
code cleanup
This commit is contained in:
parent
dc94c7235c
commit
da24007a36
2
.gitignore
vendored
2
.gitignore
vendored
@ -55,3 +55,5 @@ dkms.conf
|
||||
/.vs/
|
||||
/Debug
|
||||
/Release
|
||||
/emu6502.vcxproj.user
|
||||
/emu6502.vcxproj.filters
|
||||
|
1
cpu.c
1
cpu.c
@ -3,6 +3,7 @@
|
||||
#include "opcodes.h"
|
||||
#include <stdio.h>
|
||||
#include <memory.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void* unimplemented_instruction(State6502* state) {
|
||||
printf("Error: unimplemented instruction\n");
|
||||
|
@ -1,32 +1,50 @@
|
||||
#include "types.h"
|
||||
#include "opcodes.h"
|
||||
#include "disassembler.h"
|
||||
#include <stdio.h>
|
||||
|
||||
void disassemble_6502(byte* buffer, word pc) {
|
||||
printf("%04d ", pc);
|
||||
byte* code = &buffer[pc];
|
||||
int bytes = 1;
|
||||
char op[128];
|
||||
switch (*code) {
|
||||
case 0x00: printf("BRK"); break;
|
||||
case ORA_IMM: printf("ORA #$%02x", code[1]); break;
|
||||
case ORA_ZP: printf("ORA $%02x", code[1]); break;
|
||||
case ORA_ZPX: printf("ORA $%02x,X", code[1]); break;
|
||||
case ORA_ABS: printf("ORA $%02x%02x", code[2], code[1]); break;
|
||||
case ORA_ABSX: printf("ORA $%02x%02x,X", code[2], code[1]); break;
|
||||
case ORA_ABSY: printf("ORA $%02x%02x,Y", code[2], code[1]); break;
|
||||
case ORA_INDX: printf("ORA ($%02x,X)", code[1]); break;
|
||||
case ORA_INDY: printf("ORA ($%02x),Y", code[1]); break;
|
||||
case LDA_IMM: printf("LDA #$%02x", code[1]); break;
|
||||
case LDA_ZP: printf("LDA $%02x", code[1]); break;
|
||||
case LDA_ZPX: printf("LDA $%02x,X", code[1]); break;
|
||||
case LDA_ABS: printf("LDA $%02x%02x", code[2], code[1]); break;
|
||||
case LDA_ABSX: printf("LDA $%02x%02x,X", code[2], code[1]); break;
|
||||
case LDA_ABSY: printf("LDA $%02x%02x,Y", code[2], code[1]); break;
|
||||
case LDA_INDX: printf("LDA ($%02x,X)", code[1]); break;
|
||||
case LDA_INDY: printf("LDA ($%02x),Y", code[1]); break;
|
||||
case 0x00: sprintf(op,"BRK"); break;
|
||||
case ORA_IMM: sprintf(op, "ORA #$%02x", code[1]); break;
|
||||
case ORA_ZP: sprintf(op, "ORA $%02x", code[1]); break;
|
||||
case ORA_ZPX: sprintf(op, "ORA $%02x,X", code[1]); break;
|
||||
case ORA_ABS: sprintf(op, "ORA $%02x%02x", code[2], code[1]); break;
|
||||
case ORA_ABSX: sprintf(op, "ORA $%02x%02x,X", code[2], code[1]); break;
|
||||
case ORA_ABSY: sprintf(op, "ORA $%02x%02x,Y", code[2], code[1]); break;
|
||||
case ORA_INDX: sprintf(op, "ORA ($%02x,X)", code[1]); break;
|
||||
case ORA_INDY: sprintf(op, "ORA ($%02x),Y", code[1]); break;
|
||||
case LDA_IMM: sprintf(op, "LDA #$%02x", code[1]); break;
|
||||
case LDA_ZP: sprintf(op, "LDA $%02x", code[1]); break;
|
||||
case LDA_ZPX: sprintf(op, "LDA $%02x,X", code[1]); break;
|
||||
case LDA_ABS: sprintf(op, "LDA $%02x%02x", code[2], code[1]); break;
|
||||
case LDA_ABSX: sprintf(op, "LDA $%02x%02x,X", code[2], code[1]); break;
|
||||
case LDA_ABSY: sprintf(op, "LDA $%02x%02x,Y", code[2], code[1]); break;
|
||||
case LDA_INDX: sprintf(op, "LDA ($%02x,X)", code[1]); break;
|
||||
case LDA_INDY: sprintf(op, "LDA ($%02x),Y", code[1]); break;
|
||||
|
||||
case 0xEA: printf("NOP"); break;
|
||||
default:
|
||||
printf("UNKNOWN %02x", *code);
|
||||
}
|
||||
|
||||
if (bytes > 1) {
|
||||
printf("%02x ", code[1]);
|
||||
}
|
||||
else {
|
||||
printf(" ");
|
||||
}
|
||||
if (bytes > 2) {
|
||||
printf("%02x ", code[2]);
|
||||
}
|
||||
else {
|
||||
printf(" ");
|
||||
}
|
||||
printf(op);
|
||||
|
||||
printf("\n");
|
||||
}
|
@ -21,6 +21,8 @@ byte* read_game() {
|
||||
int main()
|
||||
{
|
||||
run_tests();
|
||||
printf("All tests succeeded.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
//void emulate() {
|
||||
|
@ -1,9 +1,13 @@
|
||||
#include <memory.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "types.h"
|
||||
#include "test6502.h"
|
||||
#include "opcodes.h"
|
||||
#include "state.h"
|
||||
#include "disassembler.h"
|
||||
#include "cpu.h"
|
||||
|
||||
|
||||
void print_state(State6502* state) {
|
||||
printf("\tC=%d,Z=%d,I=%d,D=%d,B=%d,V=%d,N=%d\n", state->flags.c, state->flags.z, state->flags.i, state->flags.d, state->flags.b, state->flags.v, state->flags.n);
|
||||
|
Loading…
Reference in New Issue
Block a user