-
Notifications
You must be signed in to change notification settings - Fork 0
/
go, be free my child
163 lines (146 loc) · 2.65 KB
/
go, be free my child
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
HWID_LEGS equ 0x1
HWID_LIDAR equ 0x3
HWID_CLOCK equ 0x8
HWID_HOLO equ 0x9
HWID_BATTERY equ 0xA
LIDAR_GET_POS equ 0x1
SET_DIRECTION_AND_WALK equ 0x2
INVENTORY_POLL equ 1
INVENTORY_CLEAR equ 2
BATTERY_POLL equ 1
BATTERY_GET_MAX_CAPACITY equ 2
CMD_DONE equ 0x00
CMD_GO equ 0x01
CMD_DRILL equ 0x02
CMD_LASER equ 0x03
CMD_INVENTORY equ 0x04
CMD_WAIT equ 0x05
DIR_NORTH equ 0x0
DIR_EAST equ 0x1
DIR_SOUTH equ 0x2
DIR_WEST equ 0x3
.data
initialized: dw 0
restore_valid: dw 0
restore_sp: dw 0
.text
mov a,[restore_valid]
test a,a
jnz RestorePrevTickState
mov a,[initialized]
test a,a
jnz InvalidRestore
mov a,1
mov [initialized],a
mov [debug_text],0x3333
call WaitForNextTick
mov [debug_text],0x2222
call WaitForNextTick
mov [debug_text],0x1111
call WaitForNextTick
Main:
mov bp,sp
sub sp,1
xor a,a
mov [bp-1],a
Main_mainloop:
Main_finishedLoop:
mov [prgm_status],0xd000
call WaitForNextTick
jmp Main_finishedLoop
GoInDirection:
push bp
mov bp,sp
sub sp,5
mov [bp-5],0
mov a,[bp+3] ; get distance
mov [bp-1],a
mov a,GET_POS
hwi HWID_LIDAR
GoInDirection_loop2:
mov [bp-4],3
GoInDirection_loop1:
sub [bp-4],1
jz GoInDirection_end
mov [bp-2],x
mov [bp-3],y
mov b,[bp+2] ; get direction
mov a,SET_DIRECTION_AND_WALK
hwi HWID_LEGS
call WaitForNextTick
mov a,LIDAR_GET_POS
hwi HWID_LIDAR
cmp x,[bp-2]
jnz GoInDirection_notEqual
cmp y,[bp-3]
jz GoInDirection_loop1
GoInDirection_notEqual:
mov a,[bp-1]
sub a,1
mov [bp-1],a
jnz GoInDirection_loop2
mov [bp-5],1
GoInDirection_end:
mov a,[bp-5]
mov sp,bp
pop bp
ret
ShowBattery:
mov a, BATTERY_POLL
hwi HWID_BATTERY
push b
mov a, BATTERY_GET_MAX_CAPACITY
hwi HWID_BATTERY
xor y,y
pop a
mul 1000
div b
xor y,y
div 10
mov b,y
shl b,8
xor y,y
div 10
shr b,4
shl y,8
or b,y
xor y,y
div 10
shr b,4
shl y,8
or b,y
test a,a
jz ShowBattery_notgt
mov b,0x0999
ShowBattery_notgt:
or b,0xb000
mov a,b
hwi 9
ret
WaitForNextTick:
push bp
mov [restore_sp],sp
mov a,1
mov [restore_valid],a
mov a,[debug_text]
test a,a
mov [debug_text],0
jnz WaitForNextTick_validText
call ShowBattery
WaitForNextTick_validText:
hwi HWID_HOLO
brk
RestorePrevTickState:
xor a,a
mov [restore_valid],a
mov sp,[restore_sp]
pop bp
ret
CrashPrgm:
mov [prgm_status],0xc000
call WaitForNextTick
jmp CrashPrgm
InvalidRestore:
mov a,0xff80
hwi HWID_HOLO
brk