Add readch and for the sake of symmetry printch, simplify make.sh, and tweak the code a bit to make it more consistent.
This commit is contained in:
parent
cc35d72a4e
commit
9afbaae05d
|
@ -1,9 +1,9 @@
|
|||
[ORG 0x7c00]
|
||||
jmp short start
|
||||
jmp start
|
||||
nop
|
||||
|
||||
;1.44 MB 3.5" floppy disk description table
|
||||
OEMLabel db "EttinOS "
|
||||
OEMLabel db "ETTINOS "
|
||||
BytesPerSector dw 0x200
|
||||
SectorsPerCluster db 0x1
|
||||
BootRecordSectors dw 0x1
|
||||
|
@ -19,7 +19,7 @@ LargeSectors dd 0x0
|
|||
DriveNumber dw 0x0
|
||||
DriveSignature db 0x29
|
||||
VolumeID dd 0x0
|
||||
VolumeLabel db "EttinOS "
|
||||
VolumeLabel db "ETTINOS "
|
||||
FileSystem db "FAT12 "
|
||||
|
||||
start:
|
||||
|
@ -53,7 +53,7 @@ mov al, 0xe
|
|||
mov ah, 0x2
|
||||
int 0x13
|
||||
|
||||
;Search the root FAT for the system
|
||||
;Search the root FAT for the system FAT
|
||||
;Set DI to the root FAT
|
||||
mov ax, ds
|
||||
mov es, ax
|
||||
|
@ -64,7 +64,7 @@ mov ax, 0x0
|
|||
search:
|
||||
;Store CX in the stack
|
||||
push cx
|
||||
;Check for the binary
|
||||
;Check for the system FAT
|
||||
mov si, sysfile
|
||||
mov cx, 0xb
|
||||
rep cmpsb
|
||||
|
@ -79,7 +79,7 @@ loop search
|
|||
|
||||
;Load the system FAT
|
||||
loadsysfat:
|
||||
;???
|
||||
;Store the first cluster
|
||||
mov ax, word [es:di+0xf]
|
||||
mov word [cluster], ax
|
||||
;Set the source
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
;Converts a byte in ah to a hex string at di.
|
||||
;Converts a byte in AH to a hex string at DI.
|
||||
|
||||
byte2hex:
|
||||
|
||||
|
@ -8,16 +8,16 @@ pusha
|
|||
;Set a key for the hex digits
|
||||
mov si, .key
|
||||
|
||||
;Set a counter for the two characters of the hex string
|
||||
;Set a counter for the two hex digits
|
||||
mov cx, 0x2
|
||||
|
||||
.loop:
|
||||
|
||||
;Read the byte
|
||||
;Read a nibble
|
||||
rol ax, 0x4
|
||||
mov bx, ax
|
||||
|
||||
;Convert the byte to a hex digit
|
||||
;Convert the nibble to a hex digit
|
||||
and bx, 0xf
|
||||
mov bl, [si + bx]
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
;Compares strings from si and di and sets the carry flag if they are equal and clears it if not.
|
||||
;Compares strings from SI and SI and sets the carry flag if they are equal and clears it if not.
|
||||
|
||||
cmpstr:
|
||||
|
||||
|
@ -40,4 +40,4 @@ stc
|
|||
;Load the initial registers from the stack
|
||||
popa
|
||||
|
||||
ret
|
||||
ret
|
||||
|
|
|
@ -16,4 +16,4 @@ mov si, buffer
|
|||
call println
|
||||
|
||||
.done:
|
||||
ret
|
||||
ret
|
||||
|
|
|
@ -8,4 +8,4 @@ call println
|
|||
ret
|
||||
|
||||
.help:
|
||||
db "Input:", 0xd, 0xa, "* Typing a character overwrites the cursor location.", 0xd, 0xa, "* The erase (=tab) key erases the cursor location.", 0xd, 0xa, "* The space and backspace keys move the cursor.", 0xd, 0xa, "Commands:", 0xd, 0xa, "* echo: echoes its input.", 0xd, 0xa, "* hello: a hello world program.", 0xd, 0xa, "* help: you are reading it.", 0xd, 0xa, "* keycode: echoes the BIOS code of a key.", 0x0
|
||||
db "Input:", 0xd, 0xa, "* Typing a character overwrites the cursor location.", 0xd, 0xa, "* The erase (=tab) key erases the cursor location.", 0xd, 0xa, "* The space and backspace keys move the cursor.", 0xd, 0xa, "Commands:", 0xd, 0xa, "* echo: echoes its input.", 0xd, 0xa, "* hello: a hello world program.", 0xd, 0xa, "* help: you are reading it.", 0xd, 0xa, "* keycode: echoes the BIOS code of a key.", 0x0
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
;Reads a keypress and prints its BIOS code.
|
||||
;Reads a keypress and prints its BIOS keycode.
|
||||
|
||||
keycode:
|
||||
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
;Prints a character from AL
|
||||
|
||||
printch:
|
||||
|
||||
mov ah, 0xe
|
||||
int 0x10
|
||||
|
||||
ret
|
|
@ -1,4 +1,4 @@
|
|||
;Prints a string from si until a null, followed by a newline.
|
||||
;Prints a string from SI until a null, followed by a newline.
|
||||
|
||||
println:
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
;Prints a string from si until a null.
|
||||
;Prints a string from SI until a null.
|
||||
|
||||
printstr:
|
||||
|
||||
|
@ -16,7 +16,6 @@ je .done
|
|||
|
||||
;Print the character
|
||||
mov ah, 0xe
|
||||
mov bx, 0x0
|
||||
int 0x10
|
||||
|
||||
;Repeat
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
;Reads a character to AL
|
||||
|
||||
readch:
|
||||
|
||||
;Store the initial registers
|
||||
push bx
|
||||
push ax
|
||||
|
||||
;Read a keypress
|
||||
mov ah, 0x0
|
||||
int 0x16
|
||||
|
||||
;Check for non-printing characters
|
||||
cmp al, 0x1f
|
||||
jle readch
|
||||
cmp al, 0x7f
|
||||
je readch
|
||||
|
||||
;Print the character
|
||||
mov ah, 0xe
|
||||
int 0x10
|
||||
|
||||
;Load the initial registers
|
||||
pop bx
|
||||
mov ah, bh
|
||||
pop bx
|
||||
|
||||
.done:
|
||||
ret
|
|
@ -1,4 +1,4 @@
|
|||
;Reads a string of at most al characters to di until a return and prints a newline.
|
||||
;Reads a string of at most AL characters to DI until a return and prints a newline.
|
||||
|
||||
readln:
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
;Reads a string of at most al characters to di until a return.
|
||||
;Reads a string of at most AL characters to DI until a return.
|
||||
|
||||
readstr:
|
||||
|
||||
|
@ -29,32 +29,27 @@ int 0x16
|
|||
;Check for return
|
||||
cmp al, 0xd
|
||||
je .return
|
||||
|
||||
;Check for backspace
|
||||
cmp al, 0x8
|
||||
je .backspace
|
||||
|
||||
;Check for input end
|
||||
pop dx
|
||||
push dx
|
||||
cmp bl, dl
|
||||
je .loop
|
||||
|
||||
;Check for space
|
||||
cmp al, 0x20
|
||||
je .space
|
||||
|
||||
;Check for erase
|
||||
cmp al, 0x9
|
||||
je .erase
|
||||
|
||||
;Check for non-printing characters
|
||||
cmp al, 0x1f
|
||||
jle .loop
|
||||
cmp al, 0x7f
|
||||
je .loop
|
||||
|
||||
.char:
|
||||
.character:
|
||||
;Store the character
|
||||
stosb
|
||||
;Print the character
|
||||
|
@ -67,7 +62,7 @@ jmp .loop
|
|||
.erase:
|
||||
;Replace the cursor position with a space
|
||||
mov al, 0x20
|
||||
jmp .char
|
||||
jmp .character
|
||||
|
||||
.space:
|
||||
call .nextchar
|
||||
|
@ -86,19 +81,18 @@ jmp .loop
|
|||
|
||||
.return:
|
||||
|
||||
;Find and remove trailing spaces
|
||||
;Go to the end of the input
|
||||
pop ax
|
||||
mov bh, 0x0
|
||||
sub ax, bx
|
||||
push di
|
||||
add di, ax
|
||||
|
||||
.findtrailing:
|
||||
;Check for a trailing space
|
||||
cmp byte [di], 0x20
|
||||
je .deltrailing
|
||||
jmp .end
|
||||
|
||||
.deltrailing:
|
||||
;Delete a trailing space
|
||||
mov al, 0x0
|
||||
|
@ -106,8 +100,8 @@ stosb
|
|||
sub di, 0x2
|
||||
jmp .findtrailing
|
||||
|
||||
.end:
|
||||
;Move the cursor to the end of the input string
|
||||
.end:
|
||||
pop di
|
||||
.findend:
|
||||
cmp byte [di], 0x0
|
||||
|
@ -138,7 +132,6 @@ inc dl
|
|||
mov ah, 0x2
|
||||
int 0x10
|
||||
ret
|
||||
|
||||
.nextln:
|
||||
mov ah, 0x2
|
||||
inc dh
|
||||
|
@ -158,7 +151,6 @@ dec dl
|
|||
mov ah, 0x2
|
||||
int 0x10
|
||||
ret
|
||||
|
||||
.prevln:
|
||||
mov ah, 0x2
|
||||
dec dh
|
||||
|
|
|
@ -2,13 +2,15 @@
|
|||
jmp start
|
||||
|
||||
;Calls
|
||||
%include "BYTE2HEX.INC"
|
||||
%include "CMPSTR.INC"
|
||||
%include "PRINTNL.INC"
|
||||
%include "PRINTCH.INC"
|
||||
%include "PRINTSTR.INC"
|
||||
%include "PRINTLN.INC"
|
||||
%include "READCH.INC"
|
||||
%include "READSTR.INC"
|
||||
%include "READLN.INC"
|
||||
%include "CMPSTR.INC"
|
||||
%include "BYTE2HEX.INC"
|
||||
|
||||
;Commands
|
||||
%include "ECHO.INC"
|
||||
|
@ -38,13 +40,11 @@ mov di, buffer
|
|||
mov al, 0xff
|
||||
call readln
|
||||
|
||||
exec:
|
||||
;Identify and execute the command
|
||||
|
||||
exec:
|
||||
;Check for no command
|
||||
cmp byte [buffer], 0x0
|
||||
je loop
|
||||
|
||||
.echo:
|
||||
;Check
|
||||
mov si, buffer
|
||||
|
@ -54,7 +54,6 @@ jnc .hello
|
|||
;Execute
|
||||
call echo
|
||||
jmp loop
|
||||
|
||||
.hello:
|
||||
;Check
|
||||
mov si, buffer
|
||||
|
@ -64,7 +63,6 @@ jnc .help
|
|||
;Execute
|
||||
call hello
|
||||
jmp loop
|
||||
|
||||
.help:
|
||||
;Check
|
||||
mov si, buffer
|
||||
|
@ -74,7 +72,6 @@ jnc .keycode
|
|||
;Execute
|
||||
call help
|
||||
jmp loop
|
||||
|
||||
.keycode:
|
||||
;Check
|
||||
mov si, buffer
|
||||
|
@ -84,7 +81,6 @@ jnc .error
|
|||
;Execute
|
||||
call keycode
|
||||
jmp loop
|
||||
|
||||
.error:
|
||||
mov si, error
|
||||
call println
|
||||
|
@ -108,7 +104,6 @@ db "hello", 0x0
|
|||
db "help", 0x0
|
||||
.keycode:
|
||||
db "keycode", 0x0
|
||||
|
||||
error:
|
||||
db "Unknown command", 0x0
|
||||
|
||||
|
|
11
make.sh
11
make.sh
|
@ -1,14 +1,11 @@
|
|||
#!/bin/bash
|
||||
|
||||
cd SOURCE/
|
||||
nasm BOOT.ASM -f bin -O0 -o ../BOOT.BIN
|
||||
nasm SYSTEM.ASM -f bin -O0 -o ../SYSTEM.BIN
|
||||
nasm BOOT.ASM -f bin -o ../BOOT.BIN
|
||||
nasm SYSTEM.ASM -f bin -o ../SYSTEM.BIN
|
||||
|
||||
cd ..
|
||||
if [[ -f EttinOS.img ]]
|
||||
then
|
||||
rm EttinOS.img
|
||||
fi
|
||||
rm -f EttinOS.img
|
||||
mkfs.fat -C EttinOS.img 1440
|
||||
mcopy -i EttinOS.img SYSTEM.BIN ::
|
||||
dd if=BOOT.BIN of=EttinOS.img conv=notrunc bs=512 count=1
|
||||
mcopy -i EttinOS.img SYSTEM.BIN ::
|
||||
|
|
Loading…
Reference in New Issue