1313BITS 64
1414
1515
16-
17-
1816; -----------------------------------------------------------------------------
1917; ui_input -- Take string from keyboard entry
2018; IN: RDI = location where string will be stored
@@ -30,9 +28,10 @@ ui_input:
3028 xor ecx , ecx ; Offset from start
3129
3230ui_input_more:
33- ; mov al, '_' ; Cursor character
34- ; call output_char ; Output the cursor
35- ; call dec_cursor ; Set the cursor back by 1
31+ mov al , '_' ; Cursor character
32+ call output_char ; Output the cursor
33+ mov al , 0x03 ; Decrement cursor
34+ call output_char ; Output the cursor
3635ui_input_halt:
3736 hlt ; Halt until an interrupt is received
3837 call [ b_input ] ; Returns the character entered. 0 if there was none
@@ -50,17 +49,18 @@ ui_input_process:
5049 je ui_input_more ; Jump if we have (should beep as well)
5150 stosb ; Store AL at RDI and increment RDI by 1
5251 inc rcx ; Increment the counter
53- ; push rax
54- ; mov al, 0x0E ; Cursor character
55- ; call output_char ; Output the cursor
56- ; pop rax
5752 call output_char ; Display char
5853 jmp ui_input_more
5954
6055ui_input_backspace:
6156 test rcx , rcx ; backspace at the beginning? get a new char
6257 jz ui_input_more
58+ mov al , ' '
6359 call output_char ; Output backspace as a character
60+ mov al , 0x03 ; Decrement cursor
61+ call output_char ; Output the cursor
62+ mov al , 0x03 ; Decrement cursor
63+ call output_char ; Output the cursor
6464 dec rdi ; go back one in the string
6565 mov byte [ rdi ], 0x00 ; NULL out the char
6666 dec rcx ; decrement the counter by one
@@ -113,34 +113,6 @@ output_char:
113113; -----------------------------------------------------------------------------
114114
115115
116- ; -----------------------------------------------------------------------------
117- ; screen_clear -- Clear the screen
118- ; IN: Nothing
119- ; OUT: All registers preserved
120- screen_clear:
121- push rdi
122- push rcx
123- push rax
124-
125- mov word [ Screen_Cursor_Col ], 0
126- mov word [ Screen_Cursor_Row ], 0
127-
128- ; Set the Frame Buffer to the background colour
129- mov rdi , [ VideoBase ]
130- mov eax , [ BG_Color ]
131- mov ecx , [ Screen_Bytes ]
132- shr ecx , 2 ; Quick divide by 4
133- rep stosd
134-
135- call draw_line
136-
137- pop rax
138- pop rcx
139- pop rdi
140- ret
141- ; -----------------------------------------------------------------------------
142-
143-
144116; -----------------------------------------------------------------------------
145117; draw_line
146118draw_line:
@@ -218,112 +190,9 @@ string_length:
218190; -----------------------------------------------------------------------------
219191
220192
221- ; -----------------------------------------------------------------------------
222- ; ui_api -- API calls for the UI
223- ; IN: RCX = API function
224- ; RAX = Value (depending on the function)
225- ; OUT: RAX = Value (depending on the function)
226- ; All other registers preserved
227- ui_api:
228- ; Use CL register as an index to the function table
229- and ecx , 0xFF ; Keep lower 8-bits only
230- ; To save memory, the functions are placed in 16-bit frames
231- lea ecx , [ ui_api_table + ecx * 2 ] ; extract function from table by index
232- mov cx , [ ecx ] ; limit jump to 16-bit
233- jmp rcx ; jump to function
234-
235- ui_api_ret:
236- ret
237-
238- ui_api_get_fg:
239- mov eax , [ FG_Color ]
240- ret
241-
242- ui_api_get_bg:
243- mov eax , [ BG_Color ]
244- ret
245-
246- ui_api_get_cursor_row:
247- xor eax , eax
248- mov ax , [ Screen_Cursor_Row ]
249- ret
250-
251- ui_api_get_cursor_col:
252- xor eax , eax
253- mov ax , [ Screen_Cursor_Col ]
254- ret
255-
256- ui_api_get_cursor_row_max:
257- xor eax , eax
258- mov ax , [ Screen_Rows ]
259- ret
260-
261- ui_api_get_cursor_col_max:
262- xor eax , eax
263- mov ax , [ Screen_Cols ]
264- ret
265-
266- ui_api_set_fg:
267- mov [ FG_Color ], eax
268- ret
269-
270- ui_api_set_bg:
271- mov [ BG_Color ], eax
272- ret
273-
274- ui_api_set_cursor_row:
275- mov [ Screen_Cursor_Row ], ax
276- ret
277-
278- ui_api_set_cursor_col:
279- mov [ Screen_Cursor_Col ], ax
280- ret
281-
282- ui_api_set_cursor_row_max:
283- mov [ Screen_Rows ], ax
284- ret
285-
286- ui_api_set_cursor_col_max:
287- mov [ Screen_Cols ], ax
288- ret
289- ; -----------------------------------------------------------------------------
290-
291-
292- ; -----------------------------------------------------------------------------
293- ; UI API index table
294- ui_api_table:
295- dw ui_api_ret ; 0x00
296- dw ui_api_get_fg ; 0x01
297- dw ui_api_get_bg ; 0x02
298- dw ui_api_get_cursor_row ; 0x03
299- dw ui_api_get_cursor_col ; 0x04
300- dw ui_api_get_cursor_row_max ; 0x05
301- dw ui_api_get_cursor_col_max ; 0x06
302- dw ui_api_ret ; 0x07
303- dw ui_api_ret ; 0x08
304- dw ui_api_ret ; 0x09
305- dw ui_api_ret ; 0x0A
306- dw ui_api_ret ; 0x0B
307- dw ui_api_ret ; 0x0C
308- dw ui_api_ret ; 0x0D
309- dw ui_api_ret ; 0x0E
310- dw ui_api_ret ; 0x0F
311- dw ui_api_ret ; 0x10
312- dw ui_api_set_fg ; 0x11
313- dw ui_api_set_bg ; 0x12
314- dw ui_api_set_cursor_row ; 0x13
315- dw ui_api_set_cursor_col ; 0x14
316- dw ui_api_set_cursor_row_max ; 0x15
317- dw ui_api_set_cursor_col_max ; 0x16
318- ; -----------------------------------------------------------------------------
319-
320-
321- font_height: db 12
322- font_width: db 6
323193font_h equ 12
324194font_w equ 6
325195
326- font_data:
327196
328197; Variables
329198align 16
0 commit comments