-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMySimpleSystem.asm
333 lines (301 loc) · 4.87 KB
/
MySimpleSystem.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
assume cs:code
code segment
str1 db "Install success!",0
str2 db "install error!" ,0
start:
mov ax,cs ;write the bootup program to the soft disk
mov es,ax
mov bx,offset bootup
mov ax,0301h
mov cx,1
mov dx,0
int 13h
cmp ah,0
jne error
cmp al,1
jne error
mov bx,offset system ;write the mysystem to the soft disk
mov ax,0302h
mov cx,2
mov dx,0
int 13h
cmp ah,0
jne error
cmp al,2
jne error
mov cl,2
mov si,offset str1
jmp short suc
error: mov cl,4
mov si,offset str2
suc: mov ax,cs
mov ds,ax
mov dh,12
mov dl,35
call showstr
mov ax,4c00h
int 21h
;___________________________________copy mysystem to safe memory area ,
;___________________________________in order to be not overwritten by other boot programs .
bootup:
mov ax,0
mov es,ax
mov bx,7e00h
mov ax,0202h
mov cx,2
mov dx,0
int 13h
mov ax,7e00h
jmp ax
;___________________________________my system
system:
jmp begin
f0 db 'Welcome to XF System!',0 ;menu
f1 db '1) restart pc',0
f2 db '2) start system',0
f3 db '3) clock',0
f4 db '4) set clock',0
f5 db 'Enter number(1~4) to execute.',0
pz db 9,8,7,4,2,0
strtable dw f1-f0,f2-f1,f3-f2,f4-f3,f5-f4
funtable dw resart-system+7e00h,startsys-system+7e00h, showtime-system+7e00h,settime-system+7e00h
begin: mov ax,cs
mov ds,ax
mov dl,0
main: mov bx,f0-system+7e00h
call cls
mov dh,0
mov bx,strtable-system+7e00h
mov si,f0-system+7e00h
mov cx,6
ms: push cx ;this loop for printing menu
mov cl,2
call showstr
pop cx
add si,cs:[bx]
add bx,2
inc dh
loop ms
ssub: mov ah,0 ;check input
int 16h
sub al,49
cmp al,3
ja ssub
mov bh,0
mov bl,al
add bl,bl
add bx,funtable-system+7e00h
call cls
call word ptr cs:[bx]
jmp short main
retf
;___________________________________restart pc
resart:
mov ax,0ffffh
mov bx,0
push ax
push bx
retf
;___________________________________start system from hard disk
startsys:
mov bx,7c00h
mov ax,0201h
mov cx,0001h
mov dx,0080h
int 13h
mov ax,7c00h
jmp ax
;___________________________________show now date and time
showtime:jmp short stbegin
timeb db 'Now time is : 20'
time db 'YY/MM/DD HH:MM:SS',0
color db 2
stbegin: push ax
push bx
push cx
push dx
push si
mov dh,12
mov dl,23
sts: mov si,time-system+7e00h
mov bx,pz-system+7e00h
mov cx,6
strlp: mov al,cs:[bx]
out 70h,al
in al,71h
push cx
mov ah,al
mov cl,4
shr al,cl
pop cx
and ah,00001111b
mov [si],ax
add byte ptr cs:[si],30h
add byte ptr cs:[si+1],30h
add bx,1
add si,3
loop strlp
in al,60h
cmp al,3bh
je cc
cmp al,1
je stok
mov si,timeb-system+7e00h
mov cl,cs:[color-system+7e00h]
call showstr
jmp short sts
cc: inc byte ptr cs:[color-system+7e00h]
jmp short sts
stok: pop si
pop dx
pop cx
pop bx
pop ax
ret
;________________________________set time by a string(YYMMDDHHMMSS) , don't check legality .
settime:
jmp setbegin
setstr db 'Enter a string to set time :',0
result db '000000000000',0
setbegin: push si
push bx
push dx
push es
push ds
push ax
mov ax,cs
mov ds,ax
mov si,setstr-system+7e00h
mov cl,2
mov dx,0
call showstr
mov si,result-system+7e00h
mov dx,0100h
call showstr
mov ax,0b800h
mov es,ax
mov bx,160+0
mov si,result-system+7e00h
sets: mov ah,0
int 16h
cmp al,20h
jb nochar
cmp al,'0'
jb sets
cmp al,'9'
ja sets
cmp bx,160+11*2
ja sets
mov es:[bx],al
mov cs:[si],al
mov byte ptr es:[bx+1],2
inc si
add bx,2
jmp short sets
nochar: cmp ah,0eh
je backspace
cmp ah,1ch
je enter
cmp ah,1h
je setok
jmp short sets
enter: mov si,result-system+7e00h
call savetime
jmp short setok
backspace:cmp bx,160
je sets
sub bx,2
dec si
mov byte ptr es:[bx],'0'
mov byte ptr cs:[si],'0'
jmp short sets
setok: pop ax
pop ds
pop es
pop dx
pop bx
pop si
ret
;________________________________save time
savetime:
push ax
push bx
push cx
push si
mov bx,pz-system+7e00h
mov cx,6
saves: mov ah,[si+1]
mov al,[si]
sub al,48
sub ah,48
push cx
mov cl,4
shl al,cl
pop cx
add ah,al
mov al,cs:[bx]
out 70h,al
mov al,ah
out 71h,al
inc bx
add si,2
loop saves
pop si
pop cx
pop bx
pop ax
ret
;________________________________clear screen
cls:
push bx
push ds
push cx
mov bx,0b800h
mov ds,bx
mov bx,0
mov cx,2000
clss: mov word ptr [bx],0
add bx,2
loop clss
pop cx
pop ds
pop bx
ret
;________________________________show a string
;________________________________dh , dl : row,col
;________________________________cl:color
;________________________________ds:si the first address of the string which ends with 0(ascii=0)
showstr: push ax
push bx
push cx
push dx
push si
push es
mov ax,160
mul dh
mov dh,0
add ax,dx
add ax,dx
mov bx,ax
mov ax,0b800h
mov es,ax
mov al,cl
mov ch,0
strs: mov cl,[si]
jcxz strok
mov es:[bx],cl
mov es:[bx+1],al
inc si
add bx,2
jmp short strs
strok: pop es
pop si
pop dx
pop cx
pop bx
pop ax
ret
;___________________________________
sysend:nop
code ends
end start