-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkerboard.asm
88 lines (65 loc) · 979 Bytes
/
checkerboard.asm
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
// when no key pressed print checkerboard in figure 1
// when 'c' pressed print inverse checkerboard
// print default checkboard
// create current_address variable, set starting value to 0x4000
@SCREEN
D=A
@current_address
M=D
//create counter to check when new row is reached
@i
M=0
@21845
D=A
@bw_word
M=D
(print_word)
//// set current_address to bwp
//get bwp value
@bw_word
D=M
//go to current_address
@current_address
A=M
//load bwp value
M=D
//increase current address by 1
//@16
//D=A
@current_address
M=M+1
// increment i
@i
M=M+1
D=M
// if i is 32 then reset i to 0 and invert bwp
@32
D=D-A
@invert_word_reset_i
D;JEQ
//check if KBD input == 'c' (67)
@KBD
D=M
@67
D=D-A
@invert_word_reset_i
D;JEQ
// jump to top of loop
@print_word
0;JMP
// after 32 words have been printed, reset i to 0 and invert bwp
(invert_word_reset_i)
@bw_word
M=!M
@i
M=0
@print_word
0;JMP
// go to top
@listen_for_c_press
0;JMP
(flipword)
@bw_word
M=!M
@print_word
0;JMP