-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-invalid-instruction.asm
157 lines (136 loc) · 2.56 KB
/
test-invalid-instruction.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
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
;; command-interpreter.asm
;; Designed to allow you to enter simple commands
;; Scroll down to "command_list:"
HWID_LEGS equ 0x1
HWID_LASER equ 0x2
HWID_LIDAR equ 0x3
HWID_KEYBOARD equ 0x4
HWID_DRILL equ 0x5
HWID_INVENTORY equ 0x6
HWID_RNG equ 0x7 ; random number generator
HWID_CLOCK equ 0x8
HWID_HOLO equ 0x9
HWID_BATTERY equ 0xA
HWID_FLOPPY equ 0xB
GET_POS equ 0x1
SET_DIRECTION_AND_WALK equ 0x2
LASER_WITHDRAW equ 1
LASER_DEPOSIT equ 2
DRILL_POLL equ 1
DRILL_GATHER_SLOW equ 2
DRILL_GATHER_FAST equ 3
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
DIR_NORTH equ 0x0
DIR_EAST equ 0x1
DIR_SOUTH equ 0x2
DIR_WEST equ 0x3
.data
print_text:
dw 0x0020
initialized: dw 0
restore_valid: dw 0
restore_sp: dw 0
prgm_status: dw 0
inhibit_status: dw 0
debug_text: 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_loop:
Main_finishedLoop:
mov [inhibit_status],0
mov [prgm_status],0xd000
call WaitForNextTick
jmp Main_finishedLoop
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:
mov a,[prgm_status]
test a,a
jnz ShowBattery_noReloadSt
mov a,0xb000
ShowBattery_noReloadSt:
or b,a
mov a,b
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
mov a,[inhibit_status]
test a,a
mov a,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