-
Notifications
You must be signed in to change notification settings - Fork 15
/
robot.asm
171 lines (128 loc) · 2.63 KB
/
robot.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#start=robot.exe#
name "robot"
#make_bin#
#cs = 500#
#ds = 500#
#ss = 500# ; stack
#sp = ffff#
#ip = 0#
; this is an example of contoling the robot.
; this code randomly moves the robot,
; and makes it to switch the lamps on and off.
; robot is a mechanical creature and it takes
; some time for it to complete a task.
; status register is used to see if robot is busy or not.
; c:\emu8086\devices\robot.exe uses ports 9, 10 and 11
; source code of the robot and other devices is in:
; c:\emu8086\devices\developer\sources\
; robot is programmed in visual basic 6.0
; robot base i/o port:
r_port equ 9
;===================================
eternal_loop:
; wait until robot
; is ready:
call wait_robot
; examine the area
; in front of the robot:
mov al, 4
out r_port, al
call wait_exam
; get result from
; data register:
in al, r_port + 1
; nothing found?
cmp al, 0
je cont ; - yes, so continue.
; wall?
cmp al, 255
je cont ; - yes, so continue.
; switched-on lamp?
cmp al, 7
jne lamp_off ; - no, so skip.
; - yes, so switch it off,
; and turn:
call switch_off_lamp
jmp cont ; continue
lamp_off: nop
; if gets here, then we have
; switched-off lamp, because
; all other situations checked
; already:
call switch_on_lamp
cont:
call random_turn
call wait_robot
; try to step forward:
mov al, 1
out r_port, al
call wait_robot
; try to step forward again:
mov al, 1
out r_port, al
jmp eternal_loop ; go again!
;===================================
; this procedure does not
; return until robot is ready
; to receive next command:
wait_robot proc
; check if robot busy:
busy: in al, r_port+2
test al, 00000010b
jnz busy ; busy, so wait.
ret
wait_robot endp
;===================================
; this procedure does not
; return until robot completes
; the examination:
wait_exam proc
; check if has new data:
busy2: in al, r_port+2
test al, 00000001b
jz busy2 ; no new data, so wait.
ret
wait_exam endp
;===================================
; switch off the lamp:
switch_off_lamp proc
mov al, 6
out r_port, al
ret
switch_off_lamp endp
;===================================
; switch on the lamp:
switch_on_lamp proc
mov al, 5
out r_port, al
ret
switch_on_lamp endp
;===================================
; generates a random turn using
; system timer:
random_turn proc
; get number of clock
; ticks since midnight
; in cx:dx
mov ah, 0
int 1ah
; randomize using xor:
xor dh, dl
xor ch, cl
xor ch, dh
test ch, 2
jz no_turn
test ch, 1
jnz turn_right
; turn left:
mov al, 2
out r_port, al
; exit from procedure:
ret
turn_right:
mov al, 3
out r_port, al
no_turn:
ret
random_turn endp
;===================================