Skip to content

Commit e66b8c9

Browse files
author
Ian Seyler
committed
Remove ui.asm
1 parent f66898e commit e66b8c9

File tree

2 files changed

+123
-219
lines changed

2 files changed

+123
-219
lines changed

src/monitor.asm

Lines changed: 123 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,29 @@ toomany:
742742

743743
; Internal functions
744744

745+
; -----------------------------------------------------------------------------
746+
; string_length -- Return length of a string
747+
; IN: RSI = string location
748+
; OUT: RCX = length (not including the NULL terminator)
749+
; All other registers preserved
750+
string_length:
751+
push rdi
752+
push rax
753+
754+
xor ecx, ecx
755+
xor eax, eax
756+
mov rdi, rsi
757+
not rcx
758+
repne scasb ; compare byte at RDI to value in AL
759+
not rcx
760+
dec rcx
761+
762+
pop rax
763+
pop rdi
764+
ret
765+
; -----------------------------------------------------------------------------
766+
767+
745768
; -----------------------------------------------------------------------------
746769
; string_compare -- See if two strings match
747770
; IN: RSI = string one
@@ -1002,6 +1025,106 @@ string_to_int_invalid:
10021025
; -----------------------------------------------------------------------------
10031026

10041027

1028+
; -----------------------------------------------------------------------------
1029+
; ui_input -- Take string from keyboard entry
1030+
; IN: RDI = location where string will be stored
1031+
; RCX = maximum number of characters to accept
1032+
; OUT: RCX = length of string that was received (NULL not counted)
1033+
; All other registers preserved
1034+
ui_input:
1035+
push rdi
1036+
push rdx ; Counter to keep track of max accepted characters
1037+
push rax
1038+
1039+
mov rdx, rcx ; Max chars to accept
1040+
xor ecx, ecx ; Offset from start
1041+
1042+
ui_input_more:
1043+
mov al, '_' ; Cursor character
1044+
call output_char ; Output the cursor
1045+
mov al, 0x03 ; Decrement cursor
1046+
call output_char ; Output the cursor
1047+
ui_input_halt:
1048+
hlt ; Halt until an interrupt is received
1049+
call [b_input] ; Returns the character entered. 0 if there was none
1050+
jz ui_input_halt ; If there was no character then halt until an interrupt is received
1051+
ui_input_process:
1052+
cmp al, 0x1C ; If Enter key pressed, finish
1053+
je ui_input_done
1054+
cmp al, 0x0E ; Backspace
1055+
je ui_input_backspace
1056+
cmp al, 32 ; In ASCII range (32 - 126)?
1057+
jl ui_input_more
1058+
cmp al, 126
1059+
jg ui_input_more
1060+
cmp rcx, rdx ; Check if we have reached the max number of chars
1061+
je ui_input_more ; Jump if we have (should beep as well)
1062+
stosb ; Store AL at RDI and increment RDI by 1
1063+
inc rcx ; Increment the counter
1064+
call output_char ; Display char
1065+
jmp ui_input_more
1066+
1067+
ui_input_backspace:
1068+
test rcx, rcx ; backspace at the beginning? get a new char
1069+
jz ui_input_more
1070+
mov al, ' '
1071+
call output_char ; Output backspace as a character
1072+
mov al, 0x03 ; Decrement cursor
1073+
call output_char ; Output the cursor
1074+
mov al, 0x03 ; Decrement cursor
1075+
call output_char ; Output the cursor
1076+
dec rdi ; go back one in the string
1077+
mov byte [rdi], 0x00 ; NULL out the char
1078+
dec rcx ; decrement the counter by one
1079+
jmp ui_input_more
1080+
1081+
ui_input_done:
1082+
xor al, al
1083+
stosb ; We NULL terminate the string
1084+
mov al, ' '
1085+
call output_char ; Overwrite the cursor
1086+
1087+
pop rax
1088+
pop rdx
1089+
pop rdi
1090+
ret
1091+
; -----------------------------------------------------------------------------
1092+
1093+
1094+
; -----------------------------------------------------------------------------
1095+
; ui_output -- Displays text
1096+
; IN: RSI = message location (zero-terminated string)
1097+
; OUT: All registers preserved
1098+
ui_output:
1099+
push rcx
1100+
1101+
call string_length ; Calculate the length of the provided string
1102+
call [b_output] ; Output the required number of characters
1103+
1104+
pop rcx
1105+
ret
1106+
; -----------------------------------------------------------------------------
1107+
1108+
1109+
; -----------------------------------------------------------------------------
1110+
; output_char -- Displays a char
1111+
; IN: AL = char to display
1112+
; OUT: All registers preserved
1113+
output_char:
1114+
push rsi
1115+
push rcx
1116+
1117+
mov [tchar], al
1118+
mov rsi, tchar
1119+
mov ecx, 1
1120+
call [b_output]
1121+
1122+
pop rcx
1123+
pop rsi
1124+
ret
1125+
; -----------------------------------------------------------------------------
1126+
1127+
10051128
; -----------------------------------------------------------------------------
10061129
; hex_string_to_int -- Convert up to 8 hexascii to bin
10071130
; IN: RSI = Location of hex asciiz string
@@ -1144,8 +1267,6 @@ FSType: db 0 ; File System
11441267
firstrun: db 1 ; A flag for running ui_init only once
11451268

11461269

1147-
%include 'ui/ui.asm'
1148-
11491270
; Temporary data
11501271
tchar: db 0, 0, 0
11511272
temp_string1: times 50 db 0

src/ui/ui.asm

Lines changed: 0 additions & 217 deletions
This file was deleted.

0 commit comments

Comments
 (0)