-
Notifications
You must be signed in to change notification settings - Fork 6
/
COMMENTS_sector1
205 lines (146 loc) · 4.31 KB
/
COMMENTS_sector1
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
sector1 (boot sector) will be loaded into memory 7C00 by BIOS
Running in 16-bit x86 Real Mode.
0500: RAM Variables (uninitialized on start)
0500 Input buffer pointer offset relative to 0501
0501..05FF Input buffer
7C00 to 7D4F: Main code
Startup
7C00 MOVDX word 7DBD
7C03 CALL word +14A to 7D50 (Message)
7C06 CALL word +87 to 7C90 (Init)
7C09 CALL word +164 to 7D70 (Prompt)
7C0C..7C0F NOP
Scan and print; typing. Also calls 7C30 to handle each character.
7C10 XOR (reg to rm) byte 11AHAH
7C12 INT byte 16
7C14 CALL word +19 to 7C30
7C17 NOP
7C18 CALL word +165 to 7D80
7C1B NOP
7C1C JMP byte -E to 7C10
Halt the system.
7C20 MOVDX word 7DD2
7C23 CALL word +12A to 7D50
7C26 NOP
7C27 NOP
7C28 CLI
7C29 HLT
Handle keyboard character.
7C30 CMPAL byte 11 (Ctrl-Q ascii)
7C32 JZ byte -14 to 7C20
7C34 CMPAL byte D (return ascii)
7C36 JZ byte +F to 7C47
7C38 CMPAL byte 8 (backspace ascii)
7C3A JZ byte +26 to 7C62
Handle normal character.
7C3C..7C3F NOP
7C40 CALL word +25 to 7C68
7C43 NOP
7C44 NOP
7C45 RET
7C46 NOP
Handle return.
7C47 MOVDX word 7DCD
7C4A CALL +103 word to 7D50
7C4D..7C51 NOP
7C52 MOV (immediate8) byte 00000110 word 500 byte 0 (Reset input buffer pointer)
7C57 NOP
7C58 NOP
7C59 CALL word +114 to 7D70
7C5C ADD byte 11000SP word 2
7C60 JMP byte -52 to 7C10 (don't print, return to read immediately)
Bounce Hub: Handle Characters -- Handle Backspace
7C62 JMP byte +62 to 7CC6 ( --> Jump over into function)
7C64 JMP byte -21 to 7C45 ( <-- Print but don't handle)
7C66 NOP
7C67 NOP
Handle putting characters into input buffer. Check overflow.
7C68 MOV (r/m to reg) byte 00CL110 word 7DE7
7C6C XOR (r/m to reg) byte 11BXBX
7C6E MOV (r/m to reg) byte 00BL110 word 500
7C72 CMP (reg first) byte 11BLCL
7C74 JA byte +E to 7C84
Put into buffer
7C76 MOV (reg to r/m) byte 10AL111 word +501 ([BX + 501])
7C7A NOP
7C7B INC byte 00000110 word 500
7C7F NOP
7C80 NOP
7C81 RET
Handle rejecting overflow.
7C84 INCCL
7C85 NOP
7C86 MOV (reg to r/m) byte 00CL110 word 500 (offset = max + 1 in case it was more. it is max + 1 because max is writable, max + 1 is not. offset represents the next writing position. by setting to max it means that you can overwrite the last one after overflow, which is unintended. by max + 1, it means that you can not [over]write anything until you go back, which is intended.)
7C8A ADD byte 11000SP word 4
7C8E JMP byte -80 to 7C10 (don't print, return to read immediately)
Initialize system
7C90 MOVDX word 7DE8
7C93 CALL word +BA to 7D50
7C96 MOVDX word 7DF2
7C99 CALL word +B4 to 7D50
7C9C MOV (immediate8) byte 00000110 word 500 byte 0 (Reset input buffer pointer)
7CA1..7CAC NOP
7CAD MOVDX word 7DE8
7CB0 CALL word +9D to 7D50
7CB3 MOVDX word 7DE0
7CB6 CALL word +97 to 7D50
7CB9 MOVDX word 7DCD
7CBC CALL word +91 to 7D50
7CBF MOVALMEM word 7DCE
7CC2 CALL word +BB to 7D80
7CC5 RET
Handle backspace
7CC6 CMP (immediate8) byte 00000110 word 500 byte 0
7CCB JZ byte -6D to 7C60 (don't print, return to read immediately)
7CCD DEC byte 00001110 word 500
7CD1 JMP byte -6F to 7C64 (print but don't handle as normal
character -- don't input into buffer)
7D40 to 7D4F: Procedures far-call vector table code
7D40 CALL word +D to 7D50
7D43 RETF
7D44 CALL word +29 to 7D70
7D47 RETF
7D48 CALL word to 7D80
7D4A RETF
7D50 to 7DBC: Procedures code
7D50 to 7D6F: String print code
In DX: String address, null-terminated.
Out SI: Length of string, excluding null-term character.
7D50 XOR (r/m to reg) byte 11SISI
7D52 MOV (r/m to reg) byte 11BXDX
7D54 MOV (r/m to reg) byte 00AX000 ([BX + SI])
7D56 CMPAL byte 0
7D58 JZ byte +9 to 7D63
7D5A CALL word +23 to 7D80
7D5D NOP
7D5E NOP
7D5F NOP
7D60 INCSI
7D61 JMP byte -11 to 7D52
7D63 RET
7D70 to 7D7F: Print prompt code
Out DX: Prompt string address.
7D70 MOVDX word 7DE4
7D73 CALL word -26 to 7D50
7D76 NOP
7D77 NOP
7D78 RET
7D80 to 7D8F: Print character with default options
In AL: Character ASCII
7D80 XOR (r/m to reg) byte 11BXBX
7D82 to 7D8F: Print character with options
In BL: next
In BH: Refer to int-10h options E.
7D82 MOVAH byte E
7D84 INT byte 10
7D86 RET
7DBD to 7DFD: Data
7DBD 7, "TestOS loaded.", A
7DCD D (carriagereturn@7DCD), A (linefeed@7DCE), 0
7DD2 D, A, A, "System halt"
7DE0 "ed.", 0
7DE4 "$ ", 0 (Prompt)
7DE7 byte FE (Input buffer max pointer offset, must not be FF)
7DE8 "Initializ", 0
7DF2 "ing...", D, A, 0
7DFE to 7DFF: Bootable magic numbers data