-
Notifications
You must be signed in to change notification settings - Fork 0
/
shell.asm
118 lines (90 loc) · 1.58 KB
/
shell.asm
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
section code vstart=0x200000
[bits 32]
mov edi,buf ;user input buffer
mov ebx,tab ;scancode translation
cld
getargu:
lodsb
test al,0xDF
jnz getargu
;esi argu of command line
xor edx,edx
push esi
call (5*8):0x0 ;print
;esi as modify flag
;needs re-print when esi is not 0
msgloop:
xor edx,edx
push edx
inc edx
call (5*8):0x0 ;scan
xor ecx,ecx
cmp eax,ecx
jz print ;no more code
cmp al,0xF0
jnz msgloop ;only translate keys at falling edge (aka when release a key)
push ecx
call (5*8):0x0 ;scan again
test al,0x80
jnz msgloop ;not char keys
xlatb
;al ASCII
test al,al
jz msgloop ;not char
cmp al,0x0A ;Enter
jz exec
cmp al,0x08 ;backspace
jnz .nbc
cmp edi,buf
jbe msgloop ;no char in buf
;erase last char
xor eax,eax
dec edi
mov [edi],eax
inc esi ;modified
jmp msgloop
.nbc:
cmp edi,strshell+80
jae print ;buf overflow
stosb ;put char to buf
inc esi ;modified
jmp msgloop
print:
xor eax,eax
cmp esi,eax
jz sleep ;not modified
mov ecx,strshell ;print together with 'Shell > '
mov [edi],al
push ecx
mov edx,eax ;0
call (5*8):0x0 ;print
sleep:
push edx ;0
mov edx,5
call (5*8):0x0 ;sleep
xor esi,esi ;reset modify
jmp msgloop
exec:
mov eax,buf ;command
mov edx,6
push eax
call (5*8):0x0 ;create
;clear buf
xor edx,edx
mov edi,buf
mov [edi],edx
inc esi ;modified
cmp eax,edx
jnz print
;exec failed
mov ecx,strfail
push ecx
call (5*8):0x0 ;print
jmp sleep
strfail db 'cannot find file',0
align 16
tab:
incbin 'scancode2ascii.bin'
align 16
strshell db 'Shell > '
buf dd 0