-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelp.asm
148 lines (118 loc) · 4.92 KB
/
help.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
;=========================
; HELP
;=========================
[bits 16]
[org 0x7c00] ;tell NASM the code is running shell at address 0x0000_8000
%define BOOTSECTOR_ADDRESS 0x7c0
%define FILES_ADDRESS 0x7E00
%define FILES_ADDR_OFFSET 8
%define SHELL_SEGMENT 0x800
%define ENTER_KEY 0x1c
%define BACKSPACE_KEY 0x0e
;init segment register
mov ax, 0
mov ds, ax ;set data segment
mov es, ax ;set extra segment
mov ss, ax ;set stack segment
mov bp, 0x7c00 ;set stack base pointer
mov sp, bp ;set stack pointer
;mov ah, 0x00 ;BIOS code to set video mode
;mov al, 0x03 ;80x25 text mode
;int 0x10 ;set video mode
mov bx, FILES_ADDRESS ;destination address in RAM where data from sector 2 is going to be loaded
mov cl, 2 ;which sector (2) to read from HDD/USB
call read_sector ;read sector from USB
;mov si, new_line
;call print_string
call print_files
;mov si, new_line
;call print_string
;mov si, new_line
;call print_string
;mov si, any_key
;call print_string
;mov ah, 0x00 ;BIOS code to read keyboard
;int 0x16 ;read a single keystroke from the keyboard
jmp SHELL_SEGMENT:0x0000 ;go back to shell
;print all files avaiable on USB
;WOULD SEPARATE IN SEPARATE APP/FILE LATER ON
print_files:
cld
mov bx, 0 ;reset file counter
.next_file:
mov ax, FILES_ADDRESS ;[file_list + bx]
add ax, bx
;cmp byte[ax], byte[cl]
;je .return
call compare_strings
cmp cl, 1 ;if user input matches file name execute the file
je .return ;execute binary coresponding to the file name and sector (dl)
mov ax, FILES_ADDRESS ;si 1st char of curr file name in file_list( files.asm)
add ax, bx
mov si, ax
call print_string ;print first file from files.asm
mov si, new_line
call print_string
add bx, FILES_ADDR_OFFSET;2 ;point bx to next file name
jmp .next_file ;process next file name
.return: ret
compare_strings:
cld ;clear direction flag to use later
mov di, end_file ;point DI to target input
mov si, ax ;point SI to source string
.next_byte:
lodsb ;init AX = to where SI points to
scasb ;compare the value of whre DI is pointing at
jne .return_false
cmp al, 0 ;if reach term 0 at the end
je .return_true
jmp .next_byte
.return_true:
mov cl, 1
ret
.return_false:
mov cl, 0
ret
;procedure to print a string
print_string:
cld ;clear directional flag
mov ah, 0x0e ;enable teletype output for int 0x10 BIOS call
.next_char:
lodsb ;read next byte from (e)si and the inc si
cmp al, 0 ;match the '/000' termnating char of a string
je .return
int 0x10 ;assuming ah = 0x0e int 0x10 will print a single char
jmp .next_char
.return: ret
;procedure to read a single sector from USB/HDD
read_sector:
mov ah, 0x02 ;BIOS code for read from storage device
mov al, 1 ;how many sectors to read
mov ch, 0 ;specify celinder
mov dh, 0 ;specify head
mov dl, 0x80 ;specify HDD code
int 0x13 ;read the sector from USB/HDD
jc .error
ret
.error:
mov si, error_message
call print_string ;print error_message
jmp $ ;stuck here forever (infinite loop)
;variables
;any_key db 'Press any key to return...', 0
error_message db 'Failed to read sector from HDD/USB', 10, 13, 0
new_line db 10, 13
end_file db 0, 0, 0, 0, 0, 0, 0, 0
;no_file dw 0
;file_list dw FILES_ADDRESS ;list
; dw FILES_ADDRESS + FILES_ADDR_OFFSET ;info
; dw FILES_ADDRESS + 2 * FILES_ADDR_OFFSET ;clear
; dw FILES_ADDRESS + 3 * FILES_ADDR_OFFSET ;theme
; dw FILES_ADDRESS + 4 * FILES_ADDR_OFFSET ;clock
; dw FILES_ADDRESS + 5 * FILES_ADDR_OFFSET ;snake
; dw FILES_ADDRESS + 6 * FILES_ADDR_OFFSET ;mines
; dw FILES_ADDRESS + 7 * FILES_ADDR_OFFSET ;pong
; dw FILES_ADDRESS + 8 * FILES_ADDR_OFFSET ;reboot
; dw no_file
;temp vars
times 512 - ($ - $$) db 0 ;fill trailing zeros to get exacly 512 bytes long binary file