mirror of
https://github.com/jborza/emu6502.git
synced 2024-11-29 14:49:55 +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/
|
/.vs/
|
||||||
/Debug
|
/Debug
|
||||||
/Release
|
/Release
|
||||||
|
/emu6502.vcxproj.user
|
||||||
|
/emu6502.vcxproj.filters
|
||||||
|
1
cpu.c
1
cpu.c
@ -3,6 +3,7 @@
|
|||||||
#include "opcodes.h"
|
#include "opcodes.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <memory.h>
|
#include <memory.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
void* unimplemented_instruction(State6502* state) {
|
void* unimplemented_instruction(State6502* state) {
|
||||||
printf("Error: unimplemented instruction\n");
|
printf("Error: unimplemented instruction\n");
|
||||||
|
@ -1,32 +1,50 @@
|
|||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "opcodes.h"
|
#include "opcodes.h"
|
||||||
#include "disassembler.h"
|
#include "disassembler.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
void disassemble_6502(byte* buffer, word pc) {
|
void disassemble_6502(byte* buffer, word pc) {
|
||||||
printf("%04d ", pc);
|
printf("%04d ", pc);
|
||||||
byte* code = &buffer[pc];
|
byte* code = &buffer[pc];
|
||||||
|
int bytes = 1;
|
||||||
|
char op[128];
|
||||||
switch (*code) {
|
switch (*code) {
|
||||||
case 0x00: printf("BRK"); break;
|
case 0x00: sprintf(op,"BRK"); break;
|
||||||
case ORA_IMM: printf("ORA #$%02x", code[1]); break;
|
case ORA_IMM: sprintf(op, "ORA #$%02x", code[1]); break;
|
||||||
case ORA_ZP: printf("ORA $%02x", code[1]); break;
|
case ORA_ZP: sprintf(op, "ORA $%02x", code[1]); break;
|
||||||
case ORA_ZPX: printf("ORA $%02x,X", code[1]); break;
|
case ORA_ZPX: sprintf(op, "ORA $%02x,X", code[1]); break;
|
||||||
case ORA_ABS: printf("ORA $%02x%02x", code[2], code[1]); break;
|
case ORA_ABS: sprintf(op, "ORA $%02x%02x", code[2], code[1]); break;
|
||||||
case ORA_ABSX: printf("ORA $%02x%02x,X", code[2], code[1]); break;
|
case ORA_ABSX: sprintf(op, "ORA $%02x%02x,X", code[2], code[1]); break;
|
||||||
case ORA_ABSY: printf("ORA $%02x%02x,Y", code[2], code[1]); break;
|
case ORA_ABSY: sprintf(op, "ORA $%02x%02x,Y", code[2], code[1]); break;
|
||||||
case ORA_INDX: printf("ORA ($%02x,X)", code[1]); break;
|
case ORA_INDX: sprintf(op, "ORA ($%02x,X)", code[1]); break;
|
||||||
case ORA_INDY: printf("ORA ($%02x),Y", code[1]); break;
|
case ORA_INDY: sprintf(op, "ORA ($%02x),Y", code[1]); break;
|
||||||
case LDA_IMM: printf("LDA #$%02x", code[1]); break;
|
case LDA_IMM: sprintf(op, "LDA #$%02x", code[1]); break;
|
||||||
case LDA_ZP: printf("LDA $%02x", code[1]); break;
|
case LDA_ZP: sprintf(op, "LDA $%02x", code[1]); break;
|
||||||
case LDA_ZPX: printf("LDA $%02x,X", code[1]); break;
|
case LDA_ZPX: sprintf(op, "LDA $%02x,X", code[1]); break;
|
||||||
case LDA_ABS: printf("LDA $%02x%02x", code[2], code[1]); break;
|
case LDA_ABS: sprintf(op, "LDA $%02x%02x", code[2], code[1]); break;
|
||||||
case LDA_ABSX: printf("LDA $%02x%02x,X", code[2], code[1]); break;
|
case LDA_ABSX: sprintf(op, "LDA $%02x%02x,X", code[2], code[1]); break;
|
||||||
case LDA_ABSY: printf("LDA $%02x%02x,Y", code[2], code[1]); break;
|
case LDA_ABSY: sprintf(op, "LDA $%02x%02x,Y", code[2], code[1]); break;
|
||||||
case LDA_INDX: printf("LDA ($%02x,X)", code[1]); break;
|
case LDA_INDX: sprintf(op, "LDA ($%02x,X)", code[1]); break;
|
||||||
case LDA_INDY: printf("LDA ($%02x),Y", code[1]); break;
|
case LDA_INDY: sprintf(op, "LDA ($%02x),Y", code[1]); break;
|
||||||
|
|
||||||
case 0xEA: printf("NOP"); break;
|
case 0xEA: printf("NOP"); break;
|
||||||
default:
|
default:
|
||||||
printf("UNKNOWN %02x", *code);
|
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");
|
printf("\n");
|
||||||
}
|
}
|
@ -21,6 +21,8 @@ byte* read_game() {
|
|||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
run_tests();
|
run_tests();
|
||||||
|
printf("All tests succeeded.\n");
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//void emulate() {
|
//void emulate() {
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
#include <memory.h>
|
#include <memory.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "test6502.h"
|
#include "test6502.h"
|
||||||
#include "opcodes.h"
|
#include "opcodes.h"
|
||||||
#include "state.h"
|
#include "state.h"
|
||||||
#include "disassembler.h"
|
#include "disassembler.h"
|
||||||
|
#include "cpu.h"
|
||||||
|
|
||||||
|
|
||||||
void print_state(State6502* state) {
|
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);
|
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);
|
||||||
|
5
types.h
5
types.h
@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
typedef unsigned __int8 uint8_t;
|
#include <stdint.h>
|
||||||
typedef unsigned __int16 uint16_t;
|
//typedef unsigned __int8 uint8_t;
|
||||||
|
//typedef unsigned __int16 uint16_t;
|
||||||
typedef uint8_t byte;
|
typedef uint8_t byte;
|
||||||
typedef uint16_t word;
|
typedef uint16_t word;
|
Loading…
Reference in New Issue
Block a user