summaryrefslogtreecommitdiff
path: root/interpreter.c
blob: 14ef40081f11b4028888e9605f19c7322e5f6e98 (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
59
60
61
//interpreter.c is a tool which can interpret 6502 assembly on the go, for the purposes of testing.
/*	Special Commands for debug information
		Q - Quit
		P - Processor status dump
		M - Dump a page of memory
*/

#include"headers/include.h"
#include"headers/debug.h"

int main(){
	AppleOn();

	while(1){
		c = fgetc(stdin);

		//	Exit condition
		if ( (c == 'Q') || (c == 'q') || (c == EOF) ) break;

		if (dCharToNum(c) == -1){
			//	Debug print conditions
			switch(c){
				//	Print debug information
				case 'P': case 'p':
					dStatusDump();
					break;
				//	Dump memory page
				case 'M': case 'm':
					byte m;
					m += dCharToNum(fgetc(stdin)) << 4;
					m += dCharToNum(fgetc(stdin));
					dPageDump(m);
					break;
				case ' ': case '\n':
					break;
			}
		}else{ // RUN INSTRUCTION
			// Pass in Instruction
			byte inst = dCharToNum(c) << 4;
			inst += dCharToNum(fgetc(stdin));
			// Pass in Value
			address pass = 0x0000;
			int range = fAddressGetLength(getITAddressing(inst));
			printf("range = %d\n", range); //DEBUG
			range = ((2*range)-2);
			c = fgetc(stdin);
			for(int i = 0; i < range; i++){
				if ((c == ' ') || (c == '\n')){
					i--;
				}else{
					pass <<= 4;
					pass += c;
				}
				c = fgetc(stdin);
			}
			current_instruction = getITFunction(inst);
			callIT(current_instruction, pass);
		}
	}
	return 0;
}