📄 shell.asm
字号:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Project: LeeOS
;; Author: Robert Lee <robert.lee@leeos.cjb.net>
;; Date: Thursday, January 04, 2001
;; Description: LeeOS shell
;; Binary Location: /system/shell.sys
;;
;; Notes:
;; In its current form this file provides a command prompt the user can
;; use to execute simple commands. This whole command prompt thing is just
;; temporary. Add some graphics stuff here and we'd have a GUI. Perhaps
;; easier said then done?
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.model tiny
.code
.386
jmp initialize
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Data
;;
;; Variable Declarations
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
username db 'Guest',0,26 dup(?) ; Stuff that should be done by kernel
password db 32 dup(?)
folder db '/',0,254 dup(?)
crlf db 13,10,0 ; Other data
prompt db ' > ',0
space db ' ',0
command1 db 'status',0
command2 db 'help',0
command3 db 'login',0
command4 db 'shutdown',0
command5 db 'run',0
command6 db 'reset',0
command7 db 'cls',0
command8 db 'mem',0
command9 db 'type',0
command10 db 'beep',0
cmd1msg db 'Commands entered so far: ',0
cmd2msg db 'LeeOS version 0.0.2 Copyright (c) 2001 by Robert Lee',13,10,13,10
db 'The following commands are available:',13,10,13,10
db ' + help Display this message',13,10
db ' + status Display session information',13,10
db ' + login Change user',13,10
db ' + run Execute machine code on a specified sector',13,10
db ' + type Display the contents of a specified sector',13,10
db ' + cls Clear the screen',13,10
db ' + reset Restart the system',13,10
db ' + shutdown Prepare system for reset',13,10,0
cmd3msg1 db 'Username> ',0
cmd3msg2 db 'Password> ',0
cmd3msg3 db ' logged in OK',13,10,0
cmd5msg1 db 'Sector> ',0
cmd8msg1 db 'Segment> ',0
cmd8msg2 db 'Offset> ',0
cmd8dat1 dw ?
cmd8dat2 dw ?
cmd8dat3 db ?
badcmd db 'Unknown Command',13,10,0
buffer db 64 dup(?)
proc caller
databuff db 512 dup(?),0
endp
cmdcount dw ?
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Initialize
;;
;; Set segments
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
initialize:
mov ax, 5000h
mov ds, ax
mov es, ax
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Command Prompt
;;
;; Display a prompt and get user input
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov cmdcount, 0
Getcmd:
mov si, offset crlf ; Print a new line
mov ah, 2
int 20h
mov si, offset username ; Print username
mov ah, 2
int 20h
mov si, offset space ; Print a space
mov ah, 2
int 20h
mov si, offset folder ; Print folder
mov ah, 2
int 20h
mov si, offset prompt ; Print a prompt
mov ah, 2
int 20h
mov di, offset buffer ; Get input from the user
mov cx, 64
mov ah, 3
int 20h
add cmdcount, 1
mov si, offset crlf ; Print a new line
mov ah, 2
int 20h
lea si, command1 ; Test for 'status'
lea di, buffer
mov cx, 7
cld
repe cmpsb
je lbl_status
lea si, command2 ; Test for 'help'
lea di, buffer
mov cx, 5
cld
repe cmpsb
je lbl_help
lea si, command3 ; Test for 'login'
lea di, buffer
mov cx, 6
cld
repe cmpsb
je lbl_login
lea si, command4 ; Test for 'shutdown'
lea di, buffer
mov cx, 9
cld
repe cmpsb
je lbl_shutdown
lea si, command5 ; Test for 'run'
lea di, buffer
mov cx, 4
cld
repe cmpsb
je lbl_run
lea si, command6 ; Test for 'reset'
lea di, buffer
mov cx, 6
cld
repe cmpsb
je lbl_reset
lea si, command7 ; Test for 'cls'
lea di, buffer
mov cx, 4
cld
repe cmpsb
je lbl_cls
lea si, command8 ; Test for 'mem'
lea di, buffer
mov cx, 4
cld
repe cmpsb
je lbl_mem
lea si, command9 ; Test for 'type'
lea di, buffer
mov cx, 5
cld
repe cmpsb
je lbl_type
lea si, command10 ; Test for 'beep'
lea di, buffer
mov cx, 5
cld
repe cmpsb
je lbl_beep
mov si, offset badcmd ; Command not found message
mov ah, 2
int 20h
jmp Getcmd
lbl_status:
mov si, offset cmd1msg ; Print current status
mov ah, 2
int 20h
mov cx, cmdcount
mov bx, 10
call prntnum
mov si, offset crlf ; Print a new line
mov ah, 2
int 20h
mov si, offset username ; Print username
mov ah, 2
int 20h
mov si, offset cmd3msg3 ; Print confirm message
mov ah, 2
int 20h
jmp Getcmd
lbl_help:
mov si, offset cmd2msg ; Print help message
mov ah, 2
int 20h
jmp Getcmd
lbl_login:
mov si, offset cmd3msg1 ; Print username prompt
mov ah, 2
int 20h
mov di, offset username ; Get username
mov cx, 32
mov ah, 3
int 20h
mov si, offset crlf ; Print a new line
mov ah, 2
int 20h
mov si, offset cmd3msg2 ; Print password prompt
mov ah, 2
int 20h
mov di, offset password ; Get password
mov cx, 32
mov ah, 3
int 20h
mov si, offset crlf ; Print a new line
mov ah, 2
int 20h
mov si, offset username ; Print username
mov ah, 2
int 20h
mov si, offset cmd3msg3 ; Print confirm message
mov ah, 2
int 20h
jmp Getcmd
lbl_shutdown:
mov ah, 6
int 20h
jmp Getcmd
lbl_run:
mov si, offset cmd5msg1 ; Print sector prompt
mov ah, 2
int 20h
mov di, offset buffer ; Input Number
mov cx, 4
mov ah, 3
int 20h
mov si, offset buffer ; Convert 'buffer' to number in BX
call str2num
xor ecx, ecx ; ECX = BX
mov cx, bx
mov si, offset crlf ; Print a new line
mov ah, 2
int 20h
mov ah, 1 ; Run Application at CX
int 20h
mov ax, cs ; Restore segments
mov ds, ax
mov es, ax
jmp Getcmd
lbl_reset:
int 19h
jmp Getcmd
lbl_cls:
mov ah, 4
int 20h
jmp Getcmd
lbl_mem:
mov si, offset cmd8msg1 ; Segment Prompt
mov ah, 2
int 20h
mov di, offset buffer ; Get Segment
mov cx, 5
mov ah, 3
int 20h
mov si, offset crlf ; Print a new line
mov ah, 2
int 20h
mov si, offset buffer
call str2num
mov cmd8dat1, bx
mov si, offset cmd8msg2 ; Segment Prompt
mov ah, 2
int 20h
mov di, offset buffer ; Get Segment
mov cx, 5
mov ah, 3
int 20h
mov si, offset crlf ; Print a new line
mov ah, 2
int 20h
mov si, offset buffer
call str2num
mov cmd8dat2, bx
mov ax, cmd8dat1 ; Set segment
mov ds, ax
mov si, cmd8dat2 ; Set offset
mov cmd8dat3, 0
bytloop: ; Print 16 bytes as hex
lodsb
mov cx, ax
mov bx, 16
call prntnum
mov si, offset space ; Print a space
mov ah, 2
int 20h
add cmd8dat3, 1
cmp cmd8dat3, 16
jbe bytloop
mov ah, 5
int 20h
mov ax, 5000
mov ds, ax
jmp Getcmd
lbl_type:
mov si, offset cmd5msg1 ; Print sector prompt
mov ah, 2
int 20h
mov di, offset buffer ; Input Number
mov cx, 4
mov ah, 3
int 20h
mov si, offset buffer ; Convert 'buffer' to number in BX
call str2num
xor ecx, ecx ; ECX = BX
mov cx, bx
mov si, offset crlf ; Print a new line
mov ah, 2
int 20h
mov bx, offset databuff ; Load Sector CX into 'databuff'
mov si, 1 ; Read 1 Sector
mov dl, 0 ; Floppy A:
mov ah, 7
int 20h
mov si, offset databuff
mov ah, 2
int 20h
jmp Getcmd
fail:
jmp $
lbl_beep:
mov ah, 5
int 20h
jmp Getcmd
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; prntnum proc
;;
;; Print number in CX with base in BX
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
prntnum proc
mov ax, 0
push ax
mov ax, cx
digits:
xor dx, dx
div bx
cmp dl, 9
ja alpha
jmp numeric
alpha:
add dl, 55
jmp gotdigit
numeric:
add dl, 48
jmp gotdigit
gotdigit:
xor dh, dh
push dx
cmp ax, 0
jnz digits
dloop:
pop ax
cmp ax, 0
je exit
mov ah, 0Eh
mov bx, 0007h
int 10h
jmp dloop
exit:
ret
prntnum endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; str2num proc
;;
;; Convert string at DS:SI (SI) into word in BX
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
str2num proc
xor dx, dx
xor bx, bx
mov cl, 10
getdigit:
lodsb
cmp al, 0
jz goodnum
cmp al, 48
jb badnum
cmp al, 57
ja badnum
sub al, 48
mov dl, al
mov ax, bx
mul cl
add ax, dx
mov bx, ax
jmp getdigit
goodnum:
mov ax, 0 ; Success
ret
badnum:
mov ax, 1 ; Bad Number
ret
str2num endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; The End
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -