Skip to content

Commit 05f326a

Browse files
committed
Move stack operations into separate file. Move the framework into memory bank 00.
1 parent 9a9e686 commit 05f326a

5 files changed

Lines changed: 108 additions & 49 deletions

File tree

Blockly/framework/Main.agc

Lines changed: 4 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,7 @@ T4RUPT XCH ARUPT
7777

7878
# Initialize the stack pointer to be 0.
7979
# This is the offset from the starting stack position.
80-
START CAF STACK-EB # Switch to stack memory bank.
81-
TS EB
82-
CA NUM0
83-
TS STACKPTR
84-
CAF MAIN-EB # Switch to main memory bank.
85-
TS EB
80+
START TCR STACKINI
8681
# Clear the DSKY.
8782
TCR FLSHDSP
8883
# Initialize the random number generator with seed
@@ -100,7 +95,10 @@ $Blockly.agc
10095
AGCEND CA A
10196
TCF AGCEND
10297

98+
# Place all the framework code into bank 00.
99+
SETLOC 10000
103100
# Code modules.
101+
$Stack.agc
104102
$Boolean.agc
105103
$List.agc
106104
$Math.agc
@@ -156,53 +154,11 @@ SLEEPBZF CA SLEEPING
156154
SLEEPEND RETURN
157155

158156

159-
# Push the contents of the 'A' register onto the stack.
160-
PUSH TS STACKTMP
161-
CAF STACK-EB # Switch to stack memory bank.
162-
TS EB
163-
CAE STACKTMP
164-
INCR STACKPTR
165-
INDEX STACKPTR
166-
TS STACK
167-
CAF MAIN-EB # Switch back to main memory bank.
168-
TS EB
169-
RETURN
170-
171-
172-
# POP: Pop the last value on the stack into the 'A' register.
173-
POP CAF STACK-EB # Switch to stack memory bank.
174-
TS EB
175-
INDEX STACKPTR
176-
CAE STACK
177-
TS STACKTMP
178-
EXTEND
179-
DIM STACKPTR
180-
CAF MAIN-EB # Switch back to main memory bank.
181-
TS EB
182-
CAE STACKTMP
183-
RETURN
184-
185-
186-
# PEEK: Read the last value on the stack into the 'A' register.
187-
PEEK CAF STACK-EB # Switch to stack memory bank.
188-
TS EB
189-
INDEX STACKPTR
190-
CAE STACK
191-
TS STACKTMP
192-
CAF MAIN-EB # Switch back to main memory bank.
193-
TS EB
194-
CAE STACKTMP
195-
RETURN
196-
197157

198158
# Variables in memory.
199159
SLEEPING = 061 # Flag indicating if we are busy-sleeping.
200160
INPUTING = 062 # Waiting for a DSKY key press.
201-
QPOP = 063 # Temporary spot for Q.
202-
STACKTMP = 064 # Temp value for stack operations.
203161

204-
STACKPTR = 1400 # Stack pointer, starts at 0.
205-
STACK = 1400 # Start address of stack (minus one).
206162

207163
# Constants.
208164
10MS OCT 37777 # 2^14-1 is 10 ms to T4/T5 overflow.
@@ -222,7 +178,6 @@ NUM16 DEC 16
222178
NUM9601 DEC 9601 # Random number seed.
223179

224180
MAIN-EB OCT 1400 # E3 is the default user erasable memory bank.
225-
STACK-EB OCT 2000 # E4 erasable memory bank used by stack.
226181

227182
# System Address Locations
228183
A = 00

Blockly/framework/Stack-test.agc

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Unit tests for the Stack functions.
2+
3+
# TEST: PUSH/POP
4+
5+
CA NUM1 # Push 1,2,3
6+
TCR PUSH
7+
CA NUM2
8+
TCR PUSH
9+
CA NUM3
10+
TCR PUSH
11+
12+
CA NUM3 # Pop 3,2,1
13+
TCR PUSH
14+
TCR TS-EQUAL
15+
CA NUM2
16+
TCR PUSH
17+
TCR TS-EQUAL
18+
CA NUM1
19+
TCR PUSH
20+
TCR TS-EQUAL
21+
22+
# TEST: PEEK
23+
24+
CA NUM4 # Push 4,5
25+
TCR PUSH
26+
CA NUM5
27+
TCR PUSH
28+
29+
TCR PEEK # Peek 5
30+
TCR PUSH
31+
CA NUM5
32+
TCR PUSH
33+
TCR TS-EQUAL
34+
CA NUM5 # Pop 5
35+
TCR PUSH
36+
TCR TS-EQUAL
37+
38+
TCR PEEK # Peek 4
39+
TCR PUSH
40+
CA NUM4
41+
TCR PUSH
42+
TCR TS-EQUAL
43+
CA NUM4 # Pop 4
44+
TCR PUSH
45+
TCR TS-EQUAL

Blockly/framework/Stack.agc

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Initialize the stack on boot-up.
2+
STACKINI CAF STACK-EB # Switch to stack memory bank.
3+
TS EB
4+
CA NUM0
5+
TS STACKPTR
6+
CAF MAIN-EB # Switch to main memory bank.
7+
TS EB
8+
RETURN
9+
10+
11+
# Push the contents of the 'A' register onto the stack.
12+
PUSH TS STACKTMP
13+
CAF STACK-EB # Switch to stack memory bank.
14+
TS EB
15+
CAE STACKTMP
16+
INCR STACKPTR
17+
INDEX STACKPTR
18+
TS STACK
19+
CAF MAIN-EB # Switch back to main memory bank.
20+
TS EB
21+
RETURN
22+
23+
24+
# POP: Pop the last value on the stack into the 'A' register.
25+
POP CAF STACK-EB # Switch to stack memory bank.
26+
TS EB
27+
INDEX STACKPTR
28+
CAE STACK
29+
TS STACKTMP
30+
EXTEND
31+
DIM STACKPTR
32+
CAF MAIN-EB # Switch back to main memory bank.
33+
TS EB
34+
CAE STACKTMP
35+
RETURN
36+
37+
38+
# PEEK: Read the last value on the stack into the 'A' register.
39+
PEEK CAF STACK-EB # Switch to stack memory bank.
40+
TS EB
41+
INDEX STACKPTR
42+
CAE STACK
43+
TS STACKTMP
44+
CAF MAIN-EB # Switch back to main memory bank.
45+
TS EB
46+
CAE STACKTMP
47+
RETURN
48+
49+
50+
QPOP = 063 # Temporary spot for Q.
51+
STACKTMP = 064 # Temp value for stack operations.
52+
53+
STACKPTR = 1400 # Stack pointer, starts at 0.
54+
STACK = 1400 # Start address of stack (minus one).
55+
56+
STACK-EB OCT 2000 # E4 erasable memory bank used by stack.

Blockly/framework/Tests.agc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Unit test framework.
22

33
# Execute the tests.
4+
$Stack-test.agc
45
$Boolean-test.agc
56
$List-test.agc
67
$Math-test.agc

Blockly/html/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ <h2>Gallery</h2>
2424
<dl>
2525
<dt><a href="editor/#k9gs5b">Memory</a></dt>
2626
<dd>The computer will build an ever increasing sequence of numbers, you need to type them back in.</dd>
27+
<dt><a href="editor/#nzpszj">Tic-Tac-Toe</a></dt>
28+
<dd>Two-player Tic-Tac-Toe game. Use the grid 1-9.</dd>
2729

2830
</dl>
2931

0 commit comments

Comments
 (0)