-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstage.gs
134 lines (125 loc) · 2.99 KB
/
stage.gs
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
costumes "files/background.svg";
# Global variables
struct cpu {
pc,
index,
opcode,
cols,
rows,
delaytimer,
soundtimer,
speed,
scale,
hires,
plane
}
struct quirks {
shift,
memoryIncrementByX,
memoryLeaveIUnchanged,
wrap,
jump,
logic,
limitrpl,
schip,
xochip
}
onflag {
initlists;
init;
broadcast "main";
}
proc init {
local i = 1;
local j = 1;
ask "Please input a program";
local result = answer();
repeat ((length result) / 2) {
memory[511 + i] = result[j] & result[j + 1]; # Replace each item of memory starting from 512 with the first and second character of the program starting from j
j += 2; # Increment local variable j by 2 to move to next half of instruction (opcode)
i++; # Increment local variable i by 1 to move to next item of memory
}
cpu cpu = cpu {
pc: 512,
index: 0,
opcode: 0x0000,
cols: 64,
rows: 32,
delaytimer: 0,
soundtimer: 0,
speed: 24,
scale: 7.5,
hires: 0,
plane: 1
};
quirks quirks = quirks {
shift: 0,
memoryIncrementByX: 0,
memoryLeaveIUnchanged: 0,
wrap: 1,
jump: 0,
logic: 0,
limitrpl: 0,
schip: 1,
xochip: 1
};
# If xochip is enabled then schip should also be enabled
# By default the XO-CHIP quirks set is enabled
}
proc initlists {
if quirks.xochip {
local memsize = 65536;
} else {
local memsize = 4096;
}
local i = 1;
delete registers;
delete memory;
delete display;
delete display1;
delete stack;
delete RPL;
repeat 16 {
add "00" to registers;
}
repeat memsize {
add "00" to memory;
}
repeat length font {
memory[i] = font[i];
i++;
}
restoreRPL;
}
proc restoreRPL {
if length RPLpersist > 0 { # Check if RPLpersist exists or isn't empty
local i = 1;
local line = "";
until i == (length RPLpersist) + 1 { # Loop until i is the length of RPLpersist (iterate through every character of variable RPLpersist)
if RPLpersist[i] == " " { # RPLpersist is basically a space delimited list, so when a space is encountered add the current line (which is 2 chars) to the RPL list
add line to RPL;
line = "";
} else { # If a space is not encountered add i character of RPLpersist to the line local variable
line &= RPLpersist[i];
}
i++;
}
} else { # If RPLpersist doesn't exist or is empty initalize it as empty
cloud RPLpersist = "";
}
if length RPL < 16 {
until length RPL >= 16 { # Fill in missing items of RPL list
add "00" to RPL;
}
}
}
# Global lists
list registers;
list stack;
list display;
list display1;
list keypad;
list realkeypad;
list memory;
list RPL;
list font = file ```files/font.txt```;