diff --git a/kernel/char.asm b/kernel/char.asm deleted file mode 100644 index 4c1998e..0000000 --- a/kernel/char.asm +++ /dev/null @@ -1,140 +0,0 @@ -section .data - -conbx dw 7 - -section .text - - ; raw console output - ; IN dl character -conout mov al, dl - mov ah, 0x0e - mov bx, [cs:conbx] - int 0x10 - ret - - ; check if character has characters ready - ; OUT al 0xFF if data, 0 if none -const mov ah, 1 - int 0x16 - jz .emp - mov ax, 0xFF - ret -.emp mov al, 0 - ret - - ; read character from console - ; OUT al character or zero -conin call const - test al, al - jz .ret - mov al, 0 - int 0x16 -.ret ret - - ; dummy: write to auxillary dev -auxout ret - - ; dummy: read from auxillary dev -auxin mov al, 0x1A - ret - - ; dummy: lister out -lstout ret - - ; character input with echo - ; OUT al character -getc call const - test al, al - jz getc - call conin - push ax - mov dl, al - call putc - pop ax - ret - - ; character input without echo -readc call const - test al, al - jz readc - jmp conin - - ; character output - ; IN dl character -putc jmp conout - - ; direct console I/O - ; IN dl character to output or 0xFF if input - ; OUT al character to read -dcon cmp dl, 0xFF - je conin - jmp conout - - ; output character string - ; IN ds:dx far ptr to string, '$'-terminated -puts push si - mov si, dx -.loop lodsb - cmp al, '$' - je .ret - mov dl, al - call putc - jmp .loop -.ret pop si - ret - - ; send a beep ctl to console -beep mov dl, 0x07 - jmp conout - - ; buffered input - ; IN ds:dx far ptr to buffer -gets mov si, dx - mov cx, [si] - mov ch, 0 - ; ch = actual number of chars - ; cl = maximum number of chars -.loop call readc - cmp al, 0x0D - je .cr - cmp al, 0x08 - je .bs - cmp al, 0x20 - jc .loop - ; check if there is space in the buffer - ; emit a beep if not - mov dl, cl - dec dl - cmp ch, dl - jc .append - call beep - jmp .loop - ; append to buffer -.append mov bh, 0 - mov bl, ch - mov [si+2+bx], al - inc ch - mov dl, al - call putc - jmp .loop - ; handle backspace -.bs: test ch, ch - jz .loop - mov dl, 0x08 - call putc - mov dl, 0x20 - call putc - mov dl, 0x08 - call putc - dec ch - jmp .loop - ; handle carriage return -.cr mov bx, 0 - mov bl, ch - mov [si+2+bx], al - mov [si], cx - mov dl, 0x0A - call putc - mov dl, 0x0D - call putc - ret diff --git a/src/@rdos.asm b/src/@rdos.asm index 4d3c5de..2dfac29 100644 --- a/src/@rdos.asm +++ b/src/@rdos.asm @@ -12,6 +12,141 @@ DRVEXT equ 0x04 ; bit 2 - EBIOS supported DIRTY equ 0x08 ; bit 3 - dskbuf dirty DRVCHS equ 0x10 ; bit 4 - CHS geometry known + ; raw console output + ; IN dl character +conout xchg ax, dx + mov ah, 0x0e + mov bx, 7 + int 0x10 + ret + + ; check if character has characters ready + ; OUT al 0xFF if data, 0 if none +const mov ah, 1 + int 0x16 + jz .emp + mov ax, 0xFF + ret +.emp mov al, 0 + ret + + ; read character from console + ; OUT al character or zero +conin call const + test al, al + jz .ret + mov al, 0 + int 0x16 +.ret ret + + ; dummy: write to auxillary dev +auxout ret + + ; dummy: read from auxillary dev +auxin mov al, 0x1A + ret + + ; dummy: lister out +lstout ret + + ; character input with echo + ; OUT al character +getc call const + test al, al + jz getc + call conin + push ax + mov dl, al + call putc + pop ax + ret + + ; character input without echo +readc call const + test al, al + jz readc + jmp conin + + ; character output + ; IN dl character +putc jmp conout + + ; direct console I/O + ; IN dl character to output or 0xFF if input + ; OUT al character to read +dcon cmp dl, 0xFF + je conin + jmp conout + + ; output character string + ; IN ds:dx far ptr to string, '$'-terminated +puts push si + mov si, dx +.loop lodsb + cmp al, '$' + je .ret + mov dl, al + call putc + jmp .loop +.ret pop si + ret + + ; send a beep ctl to console +beep mov dl, 0x07 + jmp conout + + ; buffered input + ; IN ds:dx far ptr to buffer +gets mov si, dx + mov cx, [si] + mov ch, 0 + ; ch = actual number of chars + ; cl = maximum number of chars +.loop call readc + cmp al, 0x0D + je .cr + cmp al, 0x08 + je .bs + cmp al, 0x20 + jc .loop + ; check if there is space in the buffer + ; emit a beep if not + mov dl, cl + dec dl + cmp ch, dl + jc .append + call beep + jmp .loop + ; append to buffer +.append mov bh, 0 + mov bl, ch + mov [si+2+bx], al + inc ch + mov dl, al + call putc + jmp .loop + ; handle backspace +.bs: test ch, ch + jz .loop + mov dl, 0x08 + call putc + mov dl, 0x20 + call putc + mov dl, 0x08 + call putc + dec ch + jmp .loop + ; handle carriage return +.cr mov bx, 0 + mov bl, ch + mov [si+2+bx], al + mov [si], cx + mov dl, 0x0A + call putc + mov dl, 0x0D + call putc + ret + align 16 ; IBM Interrupt Sharing Protocol structure i13isp jmp short int13i @@ -268,18 +403,18 @@ diskio mov cl, 1 ; read len ; dx = cylinder, ax = head * spt + sector div byte [drvspt] ; dx = cylinder, al = head, ah = sector - xchg dl, dh - ror dl, 1 - ror dl, 1 - or dl, ah - inc dx - ; al: head number - ; dh bit 0-7: cylinder bits 0-7 - ; dl bit 0-5: sector bits 0-5 - ; dl bit 6-7: cylinder bits 8-9 + xchg ax, dx + xchg al, ah + ror al, 1 + ror al, 1 + or al, dh + inc ax + ; dl: head number + ; ah bit 0-7: cylinder bits 0-7 + ; al bit 0-5: sector bits 0-5 + ; al bit 6-7: cylinder bits 8-9 ; shuffle values around for bios xchg ax, cx - xchg cx, dx xchg dh, dl mov bx, dskbuf .do mov dl, [biosnum]