-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsystem.c
86 lines (73 loc) · 2.97 KB
/
system.c
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//*******************************************************************************************************
//*******************************************************************************************************
//
// Name: System.C
// Purpose: Emulator Control
// Author: Paul Robson
// Date: 2nd January 2014
//
//*******************************************************************************************************
//*******************************************************************************************************
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "general.h"
#include "hardware.h"
#include "core11.h"
#include "system.h"
#include "hwinterface.h"
#include "debugsc11.h"
static BOOL inDebugMode = FALSE;
static char lastKey = '\0';
//*******************************************************************************************************
// Process a key stroke
//*******************************************************************************************************
static void processKey(char command) {
switch(command) {
case 'K': // (K) Set Break Point
C11_SetBreakPoint(DB11_GetAddress());
break;
case 'H': // (H) Go Home
DB11_SetAddress(C11_GetStatus(NULL)->pctr);
break;
case 'S': // (S) Single Step
C11_Execute(1); // One Instruction
DB11_SetAddress(C11_GetStatus(NULL)->pctr);
break;
case 'V': // (V) Step Over.
C11_SetBreakPoint(C11_GetStatus(NULL)->pctr+1); // Break after next instruction.
inDebugMode = FALSE;
break;
case 'G': // (G) Go to Breakpoint or Monitor
inDebugMode = FALSE;
break;
default: // Check 0-9, A-F
if (isxdigit(command)) {
DB11_UpdateAddress(isdigit(command) ? command - '0' : command - 'A' + 10); // update the displayed address
}
break;
}
}
//*******************************************************************************************************
// Process a Frame
//*******************************************************************************************************
BOOL SYS_Process() {
if (!inDebugMode) { // In run mode
inDebugMode = C11_Execute(-1); // Do a single frame.
if (IF_KeyPressed('M')) inDebugMode = TRUE; // If (M) Monitor pressed the Break to Debug Mode.
if (inDebugMode) DB11_SetAddress(C11_GetStatus(NULL)->pctr);
} else {
XHWISetPitch(0); // Sound off.
char currentKey = '\0';
for (char c = '0';c <= 'Z';c++) if (IF_KeyPressed(c)) currentKey = c; // Figure out what is currently pressed
if (currentKey != lastKey) { // Key changed ?
if (currentKey == '\0') processKey(lastKey); // If Key-release then do key released.
lastKey = currentKey;
}
}
return inDebugMode;
}
void SYS_SetMode(BOOL debugMode) {
inDebugMode = debugMode;
}