-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy_operating_system.asm
577 lines (365 loc) · 11.2 KB
/
my_operating_system.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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
[bits 16] ; tell assembler that working in real mode(16 bit mode)
[org 0x7c00] ; organize from 0x7C00 memory location where BIOS will load us
start: ; start label from where our code starts
xor ax,ax ; set ax register to 0
mov ds,ax ; set data segment(ds) to 0
mov es,ax ; set extra segment(es) to 0
mov bx,0x8000
mov ax,0x13 ;clears the screen
int 0x10 ;call bios video interrupt
mov ah,02 ;clear the screen with big font
int 0x10 ;interrupt display
;set cursor to specific position on screen
mov ah,0x02 ; set value for change to cursor position
mov bh,0x00 ; page
mov dh,0x06 ; y cordinate/row
mov dl,0x09 ; x cordinate/col
int 0x10
mov si, start_os_intro ; point start_os_intro string to source index
call _print_DiffColor_String ; call print different color string function
;set cursor to specific position on screen
mov ah,0x02
mov bh,0x00
mov dh,0x10
mov dl,0x06
int 0x10
mov si,press_key ; point press_key string to source index
call _print_GreenColor_String ; call print green color string function
mov ax,0x00 ; get keyboard input
int 0x16 ; interrupt for hold & read input
;/////////////////////////////////////////////////////////////
; load second sector into memory
mov ah, 0x02 ; load second stage to memory
mov al, 1 ; numbers of sectors to read into memory
mov dl, 0x80 ; sector read from fixed/usb disk
mov ch, 0 ; cylinder number
mov dh, 0 ; head number
mov cl, 2 ; sector number
mov bx, _OS_Stage_2 ; load into es:bx segment :offset of buffer
int 0x13 ; disk I/O interrupt
jmp _OS_Stage_2 ; jump to second stage
;/////////////////////////////////////////////////////////////
; declaring string datas here
start_os_intro db 'Welcome to TralahTek OS!',0
press_key db '>>>> Press any key <<<<',0
login_username db 'Username : ',0
login_password db 'Password : ',0
display_text db '! Welcome to TralahTek Operating System !', 0
os_info db 10, 'TralahTek Operating System, 16-Bit, version=1.0.0',13,0
press_key_2 db 10,'Press any key to go to graphics view',0
window_text db 10,'Graphics in OS......', 0
hello_world_text db 10,10, ' Hello from TralahTek!',0
login_label db '#] Login please....(ESC to skip login)', 0
;/////////////////////////////////////////////////////////////
; defining printing string functions here
;****** print string without color
print_string:
mov ah, 0x0E ; value to tell interrupt handler that take value from al & print it
.repeat_next_char:
lodsb ; get character from string
cmp al, 0 ; cmp al with end of string
je .done_print ; if char is zero, end of string
int 0x10 ; otherwise, print it
jmp .repeat_next_char ; jmp to .repeat_next_char if not 0
.done_print:
ret ;return
;****** print string with different colors
_print_DiffColor_String:
mov bl,1 ;color value
mov ah, 0x0E
.repeat_next_char:
lodsb
cmp al, 0
je .done_print
add bl,6 ;increase color value by 6
int 0x10
jmp .repeat_next_char
.done_print:
ret
;****** print string with green color
_print_GreenColor_String:
mov bl,10
mov ah, 0x0E
.repeat_next_char:
lodsb
cmp al, 0
je .done_print
int 0x10
jmp .repeat_next_char
.done_print:
ret
;****** print string with white color
_print_WhiteColor_String:
mov bl,15
mov ah, 0x0E
.repeat_next_char:
lodsb
cmp al, 0
je .done_print
int 0x10
jmp .repeat_next_char
.done_print:
ret
;****** print string with yellow color
_print_YellowColor_String:
mov bl,14
mov ah, 0x0E
.repeat_next_char:
lodsb
cmp al, 0
je .done_print
int 0x10
jmp .repeat_next_char
.done_print:
ret
;///////////////////////////////////////////
; boot loader magic number
times ((0x200 - 2) - ($ - $$)) db 0x00 ;set 512 bytes for boot sector which are necessary
dw 0xAA55 ; boot signature 0xAA & 0x55
;////////////////////////////////////////////////////////////////////////////////////////
_OS_Stage_2 :
mov al,2 ; set font to normal mode
mov ah,0 ; clear the screen
int 0x10 ; call video interrupt
mov cx,0 ; initialize counter(cx) to get input
;***** print login_label on screen
;set cursor to specific position on screen
mov ah,0x02
mov bh,0x00
mov dh,0x00
mov dl,0x00
int 0x10
mov si,login_label ; point si to login_username
call print_string ; display it on screen
;****** read username
;set cursor to specific position on screen
mov ah,0x02
mov bh,0x00
mov dh,0x02
mov dl,0x00
int 0x10
mov si,login_username ; point si to login_username
call print_string ; display it on screen
_getUsernameinput:
mov ax,0x00 ; get keyboard input
int 0x16 ; hold for input
cmp ah,0x1C ; compare input is enter(1C) or not
je .exitinput ; if enter then jump to exitinput
cmp ah,0x01 ; compare input is escape(01) or not
je _skipLogin ; jump to _skipLogin
mov ah,0x0E ;display input char
int 0x10
inc cx ; increase counter
cmp cx,5 ; compare counter reached to 5
jbe _getUsernameinput ; yes jump to _getUsernameinput
jmp .inputdone ; else jump to inputdone
.inputdone:
mov cx,0 ; set counter to 0
jmp _getUsernameinput ; jump to _getUsernameinput
ret ; return
.exitinput:
hlt
;****** read password
;set x y position to text
mov ah,0x02
mov bh,0x00
mov dh,0x03
mov dl,0x00
int 0x10
mov si,login_password ; point si to login_username
call print_string ; display it on screen
_getPasswordinput:
mov ax,0x00
int 0x16
cmp ah,0x1C
je .exitinput
cmp ah,0x01
je _skipLogin
inc cx
cmp cx,5
jbe _getPasswordinput
jmp .inputdone
.inputdone:
mov cx,0
jmp _getPasswordinput
ret
.exitinput:
hlt
;****** display display_text on screen
;set x y position to text
mov ah,0x02
mov bh,0x00
mov dh,0x08
mov dl,0x12
int 0x10
mov si, display_text ;display display_text on screen
call print_string
;set x y position to text
mov ah,0x02
mov bh,0x00
mov dh,0x9
mov dl,0x10
int 0x10
mov si, os_info ;display os_info on screen
call print_string
;set x y position to text
mov ah,0x02
mov bh,0x00
mov dh,0x11
mov dl,0x11
int 0x10
mov si, press_key_2 ;display press_key_2 on screen
call print_string
mov ah,0x00
int 0x16
;//////////////////////////////////////////////////////////////////
_skipLogin:
;/////////////////////////////////////////////////////////////
; load third sector into memory
mov ah, 0x03 ; load third stage to memory
mov al, 1
mov dl, 0x80
mov ch, 0
mov dh, 0
mov cl, 3 ; sector number 3
mov bx, _OS_Stage_3
int 0x13
jmp _OS_Stage_3
;////////////////////////////////////////////////////////////////////////////////////////
_OS_Stage_3:
mov ax,0x13 ; clears the screen
int 0x10
;//////////////////////////////////////////////////////////
; drawing window with lines
push 0x0A000 ; video memory graphics segment
pop es ; pop any extar segments from stack
xor di,di ; set destination index to 0
xor ax,ax ; set color register to zero
;//////////////////////////////////////////////
;******drawing top line of our window
mov ax,0x02 ; set color to green
mov dx,0 ; initialize counter(dx) to 0
add di,320 ; add di to 320(next line)
imul di,10 ;multiply by 10 to di to set y cordinate from where we need to start drawing
add di,10 ;set x cordinate of line from where to be drawn
_topLine_perPixel_Loop:
mov [es:di],ax ; move value ax to memory location es:di
inc di ; increment di for next pixel
inc dx ; increment our counter
cmp dx,300 ; comprae counter value with 300
jbe _topLine_perPixel_Loop ; if <= 300 jump to _topLine_perPixel_Loop
hlt ; halt process after drawing
;//////////////////////////////////////////////
;******drawing bottm line of our window
xor dx,dx
xor di,di
add di,320
imul di,190 ; set y cordinate for line to be drawn
add di,10 ;set x cordinate of line to be drawn
mov ax,0x01 ; blue color
_bottmLine_perPixel_Loop:
mov [es:di],ax
inc di
inc dx
cmp dx,300
jbe _bottmLine_perPixel_Loop
hlt
;//////////////////////////////////////////////
;******drawing left line of our window
xor dx,dx
xor di,di
add di,320
imul di,10 ; set y cordinate for line to be drawn
add di,10 ; set x cordinate for line to be drawn
mov ax,0x03 ; cyan color
_leftLine_perPixel_Loop:
mov [es:di],ax
inc dx
add di,320
cmp dx,180
jbe _leftLine_perPixel_Loop
hlt
;//////////////////////////////////////////////
;******drawing right line of our window
xor dx,dx
xor di,di
add di,320
imul di,10 ; set y cordinate for line to be drawn
add di,310 ; set x cordinate for line to be drawn
mov ax,0x06 ; orange color
_rightLine_perPixel_Loop:
mov [es:di],ax
inc dx
add di,320
cmp dx,180
jbe _rightLine_perPixel_Loop
hlt
;//////////////////////////////////////////////
;******drawing line below top line of our window
xor dx,dx
xor di,di
add di,320
imul di,27 ; set y cordinate for line to be drawn
add di,11 ; set x cordinate for line to be drawn
mov ax,0x05 ; pink color
_belowLineTopLine_perPixel_Loop:
mov [es:di],ax
inc di
inc dx
cmp dx,298
jbe _belowLineTopLine_perPixel_Loop
hlt
;***** print window_text & X char
;set cursor to specific position
mov ah,0x02
mov bh,0x00
mov dh,0x01 ; y cordinate
mov dl,0x02 ; x cordinate
int 0x10
mov si,window_text ; point si to window_text
call _print_YellowColor_String
hlt
;set cursor to specific position
mov ah,0x02
mov bh,0x00
mov dh,0x02 ; y cordinate
mov dl,0x25 ; x cordinate
int 0x10
mov ah,0x0E
mov al,0x58 ; 0x58=X
mov bh,0x00
mov bl,4 ; red color
int 0x10
hlt
;set cursor to specific position
mov ah,0x02
mov bh,0x00
mov dh,0x02 ; y cordinate
mov dl,0x23 ; x cordinate
int 0x10
mov ah,0x0E
mov al,0x5F ; 0x58=X
mov bh,0x00
mov bl,9 ; red color
int 0x10
hlt
;set cursor to specific position
mov ah,0x02
mov bh,0x00
mov dh,0x05 ; y cordinate
mov dl,0x09 ; x cordinate
int 0x10
mov si,hello_world_text
call _print_DiffColor_String
hlt
;set cursor to specific position
mov ah,0x02
mov bh,0x00
mov dh,0x12 ; y cordinate
mov dl,0x03 ; x cordinate
int 0x10
mov si,display_text
call _print_WhiteColor_String
hlt
; add how much memory we need
times (1024 - ($-$$)) db 0x00