Skip to content

Commit d703d40

Browse files
authored
Merge pull request #122 from ReturnInfinity/cursor
Cursor
2 parents 23142f3 + 312900a commit d703d40

File tree

3 files changed

+109
-3
lines changed

3 files changed

+109
-3
lines changed

src/drivers/lfb/lfb.asm

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
146146
lfb_inc_cursor_done:
147+
call lfb_update_cursor
148+
147149
pop rax
148150
ret
149151
; -----------------------------------------------------------------------------
@@ -164,12 +166,89 @@ lfb_dec_cursor:
164166

165167
lfb_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
524603
align 16
525604

526605
LastLine: dq 0
606+
lfb_last_cursor: dq 0
527607
lfb_glyph_next_line: dq 0
528608
FG_Color: dd 0x00FFFFFF ; White
529609
BG_Color: dd 0x00404040 ; Dark grey
610+
Cursor_Color: dd 0x00A0A0A0
530611
Line_Color: dd 0x00F7CA54 ; Return Infinity Yellow/Orange
531612
Screen_Pixels: dd 0
532613
Screen_Bytes: dd 0
@@ -537,6 +618,7 @@ Screen_Rows: dw 0
537618
Screen_Cols: dw 0
538619
Screen_Cursor_Row: dw 0
539620
Screen_Cursor_Col: dw 0
621+
lfb_cursor_on: db 1
540622

541623

542624
; =============================================================================

src/drivers/ps2.asm

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@ ps2_keyboard_interrupt:
109109
in al, PS2_DATA ; Get the scan code from the keyboard
110110
cmp al, 0x01
111111
je keyboard_escape
112+
cmp al, 0x48
113+
je keyboard_up
114+
cmp al, 0x50
115+
je keyboard_down
116+
cmp al, 0x4B
117+
je keyboard_left
118+
cmp al, 0x4D
119+
je keyboard_right
112120
cmp al, 0x1D
113121
je keyboard_control
114122
cmp al, 0x2A ; Left Shift Make
@@ -148,6 +156,22 @@ keyboard_escape:
148156
keyup:
149157
jmp keyboard_done
150158

159+
keyboard_left:
160+
mov byte [key], 0x03
161+
jmp keyboard_done
162+
163+
keyboard_right:
164+
mov byte [key], 0x02
165+
jmp keyboard_done
166+
167+
keyboard_up:
168+
mov byte [key], 0x04
169+
jmp keyboard_done
170+
171+
keyboard_down:
172+
mov byte [key], 0x05
173+
jmp keyboard_done
174+
151175
keyboard_control:
152176
mov byte [key_control], 0x01
153177
jmp keyboard_done

src/drivers/serial.asm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
serial_init:
1111
; Pure64 has already initialized the serial port
1212

13-
; Check if PS/2 is present via ACPI IAPC_BOOT_ARCH
13+
; Check if Serial is present via ACPI IAPC_BOOT_ARCH
1414
mov ax, [os_boot_arch]
1515
bt ax, 0 ; LEGACY_DEVICES
1616
jnc serial_init_error

0 commit comments

Comments
 (0)