@@ -61,8 +61,6 @@ render_done:
6161 mul ecx
6262 mov [ Screen_Bytes ], eax
6363
64- ; call lfb_clear
65-
6664 ; Calculate display parameters based on font dimensions
6765 xor eax , eax
6866 xor edx , edx
@@ -112,6 +110,7 @@ render_done:
112110
113111 mov rax , [ os_screen_lfb ]
114112 mov [ LastLine ], rax
113+ mov [ lfb_last_cursor ], rax
115114
116115 ; Overwrite the kernel b_output function so output goes to the screen instead of the serial port
117116 mov rax , lfb_output_chars
@@ -143,7 +142,10 @@ lfb_inc_cursor:
143142 cmp ax , [ Screen_Rows ] ; Compare it to the # of rows for the screen
144143 jne lfb_inc_cursor_done ; If not equal we are done
145144 mov word [ Screen_Cursor_Row ], 0 ; Wrap around
145+
146146lfb_inc_cursor_done:
147+ call lfb_update_cursor
148+
147149 pop rax
148150 ret
149151; -----------------------------------------------------------------------------
@@ -164,12 +166,89 @@ lfb_dec_cursor:
164166
165167lfb_dec_cursor_done:
166168 dec word [ Screen_Cursor_Col ] ; Decrement the cursor as usual
169+ call lfb_update_cursor
167170
168171 pop rax
169172 ret
170173; -----------------------------------------------------------------------------
171174
172175
176+ ; -----------------------------------------------------------------------------
177+ ; lfb_update_cursor -- Update the cursor
178+ ; IN: Nothing
179+ ; OUT: All registers preserved
180+ lfb_update_cursor:
181+ ; Check if cursor is enabled
182+ cmp byte [ lfb_cursor_on ], 1 ; 1 means enabled
183+ jne lfb_update_cursor_skip ; If not, skip entire function
184+
185+ push rdi
186+ push rdx
187+ push rcx
188+ push rbx
189+ push rax
190+
191+ ; Clear old cursor
192+ mov rdi , [ lfb_last_cursor ] ; Gather the LFB memory address of the start of the cursor
193+ xor ecx , ecx
194+ xor ebx , ebx ; Used for value of bytes per line
195+ mov bx , [ os_screen_ppsl ]
196+ shl ebx , 2 ; Quick multiply by 4
197+ mov cl , font_h
198+ sub cl , 2
199+ sub rdi , 4
200+ mov eax , [ BG_Color ]
201+ lfb_update_cursor_line_old:
202+ add rdi , rbx ; Add value of bytes per line
203+ mov [ rdi ], eax
204+ dec cl
205+ jnz lfb_update_cursor_line_old
206+
207+ ; Calculate where to put cursor in the Linear Frame Buffer
208+ mov rdi , [ os_screen_lfb ]
209+
210+ ; Calculate offset for row into Linear Frame Buffer
211+ xor ecx , ecx
212+ mov eax , [ lfb_glyph_bytes_per_row ]
213+ mov cx , [ Screen_Cursor_Row ]
214+ mul ecx ; EDX:EAX := EAX * ECX
215+ add rdi , rax
216+
217+ ; Calculate offset for column into Linear Frame Buffer
218+ xor ecx , ecx
219+ mov eax , [ lfb_glyph_bytes_per_col ]
220+ mov cx , [ Screen_Cursor_Col ]
221+ mul ecx ; EDX:EAX := EAX * ECX
222+ add rdi , rax
223+
224+ ; Store cursor location
225+ mov [ lfb_last_cursor ], rdi
226+
227+ ; Draw new cursor
228+ xor ecx , ecx
229+ xor ebx , ebx
230+ mov bx , [ os_screen_ppsl ]
231+ shl ebx , 2 ; Quick multiply by 4
232+ mov cl , font_h
233+ sub cl , 2
234+ sub rdi , 4
235+ mov eax , [ Cursor_Color ]
236+ lfb_update_cursor_line:
237+ add rdi , rbx
238+ mov [ rdi ], eax
239+ dec cl
240+ jnz lfb_update_cursor_line
241+
242+ pop rax
243+ pop rbx
244+ pop rcx
245+ pop rdx
246+ pop rdi
247+ lfb_update_cursor_skip:
248+ ret
249+ ; -----------------------------------------------------------------------------
250+
251+
173252; -----------------------------------------------------------------------------
174253; lfb_output_chars -- Output text to LFB
175254; IN: RSI = message location (an ASCII string, not zero-terminated)
@@ -524,9 +603,11 @@ align 16
524603align 16
525604
526605LastLine: dq 0
606+ lfb_last_cursor: dq 0
527607lfb_glyph_next_line: dq 0
528608FG_Color: dd 0x00FFFFFF ; White
529609BG_Color: dd 0x00404040 ; Dark grey
610+ Cursor_Color: dd 0x00A0A0A0
530611Line_Color: dd 0x00F7CA54 ; Return Infinity Yellow/Orange
531612Screen_Pixels: dd 0
532613Screen_Bytes: dd 0
@@ -537,6 +618,7 @@ Screen_Rows: dw 0
537618Screen_Cols: dw 0
538619Screen_Cursor_Row: dw 0
539620Screen_Cursor_Col: dw 0
621+ lfb_cursor_on: db 1
540622
541623
542624; =============================================================================
0 commit comments