-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrule110.spar
70 lines (62 loc) · 1.85 KB
/
rule110.spar
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
// Triangle side length (stored at mem[9900] thru mem[9908])
// |
// V
mem 9900 + 300 storeq
// Initialize column pattern
// The column pattern is simply a condition for each
// column that is being drawn, in the form of a bit.
// It is updated throughout runtime, causing the fancy drawing
// you see in the output to appear.
// Example pattern: 11000010
// Example output: ** *
// Build initial table
// Store a `1` at the first byte of memory
mem 1 + 1 storeb
// Store a `1` at (amount of columns - 1) in memory
mem mem 9900 + loadq 1 - + 1 storeb
// Construct end of string in memory
mem mem 9900 + loadq + 10000 + 10 storeb // newline
mem mem 9900 + loadq + 10000 + 1 + 0 storeb // null terminator
0 // Loop over lines
while dup mem 9900 + loadq < do
// Load Pattern
mem loadb 1 << mem 1 + loadb or
// Loop over columns, shift pattern
mem 9900 + loadq 2 -
while dup 3 > do
1 -
// Pattern to top of stack, ((pattern << 1) && 7)
swap 1 << 7 and
// Copy index to top of stack, load value at memory address + index
over mem + loadb or
// Duplicate index + pattern
twodup
// ((110 >> pattern) && 1)
110 swap >> 1 and
// Swap duped index and pattern
swap
// Write new pattern to memory
mem + swap storeb
// Swap pattern and index for loop increment
swap
endwhile
drop drop
0 // Loop over columns, construct string from pattern at mem[10000]
while dup mem 9900 + loadq < do
// Test pattern to set current character to write to string.
dup mem + loadb if
// Load a '*' into current character within string memory
dup mem + 10000 + 42 storeb
else
// Load a ' ' into current character within string memory
dup mem + 10000 + 32 storeb
endif
1 +
endwhile
drop
// Print constructed string
mem 10000 + dump_s
// Increment line counter
1 +
endwhile
drop