45 lines
939 B
C
45 lines
939 B
C
#include <stdio.h>
|
|
#include <stdint.h>
|
|
|
|
uint8_t program[0x10000];
|
|
|
|
uint8_t read6502(uint16_t address) {
|
|
return program[address];
|
|
}
|
|
void write6502(uint16_t address, uint8_t value) {
|
|
program[address] = value;
|
|
}
|
|
|
|
extern uint16_t pc;
|
|
extern uint8_t sp, a, x, y, status;
|
|
extern void step6502();
|
|
|
|
int main(int argc, char **argv) {
|
|
if (argc != 2) return 1;
|
|
FILE *f = fopen(argv[1], "r");
|
|
int c;
|
|
for (int i = 0; (c = fgetc(f)) != EOF; ++i)
|
|
program[i] = c;
|
|
fclose(f);
|
|
|
|
uint16_t ppc = 0x2345;
|
|
reset6502();
|
|
|
|
pc = 0x0400;
|
|
sp = a = x = y = 0;
|
|
|
|
while (ppc != pc) {
|
|
ppc = pc;
|
|
step6502();
|
|
printf("PC=%04x SP=%02x A=%02x X=%02x Y=%02x S=%02x\n",
|
|
pc, sp, a, x, y, status);
|
|
/*
|
|
if (pc == 0x37e9) {
|
|
printf("%02x%02x\n", program[0x100 + sp + 1], program[0x100 + sp]);
|
|
return 0;
|
|
}
|
|
*/
|
|
}
|
|
return 0;
|
|
}
|