summaryrefslogtreecommitdiff
path: root/src/debug.h
blob: 59e3c476782ab435a59b9017e0f34ed070b0fc48 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// debug.h
// Various functions useful for use during development.

#include"stdio.h"
#include"cpu/6502.h"
#include"cpu/addressing.h"
#include"cpu/core.h"
#include"cpu/instructions.h"
#include"cpu/table.h"



//	Converts a single character to hexadecimal
int dCharToNum(char c){
	// 0x0 - 0x9
	if (c != 0x20 && (c >= 0x30 && c <= 0x39)){
		return (c - 0x30);
	}
	// 0xA - 0xF
	else if (c != 0x20 && (c >= 0x41 && c <= 0x46)){
		return (c - 0x37);
	// 0xa - 0xf
	}else if (c != 0x20 && (c >= 0x61 && c <= 0x66)){
		return (c - 0x57);
	// Invalid
	}else{
		return -1;
	}
}

//	Dump page m from memory to stdout.
void dPageDump(short m){
	m <<= 8;
	for(int i = 0; i < 256; i+=16){
		printf("\t");
		for(int j = 0; j < 16; j+=1){
			if ((j+1) % 4 == 0){
				printf("%02x  ", GetMemory((m+(i+j))));
			}
			else {
				printf("%02x ", GetMemory((m+(i+j))));
			}
		}
		printf("\n");
	}
}

//	Dump CPU values
void dStatusDump(void){
printf("\
\t..acc:\t%x\tcycles:\t%d\n\
\t....X:\t%x\tlength:\t%d\n\
\t....Y:\t%x\t...add:\t%x\n\
\tstack:\t%x\t.value:\t%x\n\
\tflags:\t%x\t....PC:\t%x\n\
\n\
", acc, idata.cycles, X, idata.length, Y, idata.add, S, idata.value, P, PC);
}