Skip to content

Commit

Permalink
Add all commands, new library include scheme
Browse files Browse the repository at this point in the history
Added full support for all movement commands and paint functionality.
Devised a library include scheme that allows for the selective importing
of only the procedures that are needed, in order to minimize program
space wasted to unused procedure code.

MS-DOS version is fully tested.
  • Loading branch information
Trinitek committed Apr 12, 2014
1 parent 1cb139d commit 79663b7
Show file tree
Hide file tree
Showing 5 changed files with 415 additions and 239 deletions.
140 changes: 71 additions & 69 deletions keyboard.ASM
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
; NAMESPACE: "keyboard"
; REQUIRES: "string"
keyboard:
ret

; ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
; ### MACRO: "getKey"
Expand All @@ -24,13 +23,15 @@ macro keyboard.getKey
; return:
; ah = BIOS scan code
; al = ASCII code
.waitForKey:
keyboard.getKey
cmp ax, 0
jz .waitForKey
.waitForKey.return:
ret
macro keyboard.waitForKey {
.waitForKey:
keyboard.getKey
cmp ax, 0
jz .waitForKey
.waitForKey.return:
ret
}

; ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
Expand All @@ -43,66 +44,67 @@ macro keyboard.getKey
; di = pointer to new string destination
; return:
; di = pointer to new string, null terminated
.inputString:
push ax
push bx
push cx
push di
push dx
mov cl, al ; hold AX values elsewhere - will be destroyed by .getKey
mov ch, 0 ; cx = number of characters to get
mov bl, ah ; bl = echo flag
mov dx, di ; save start of pointer in dx

.inputString.getNextKey:
call .waitForKey
cmp al, 0x0D ; enter key pressed? stop accepting input and return string
je .inputString.appendTerminator
cmp al, 0x08 ; backspace key pressed? clear previous character
je .inputString.backspace
mov [di], al ; store character
inc di
cmp bl, 0 ; echo enabled?
jz .inputString.nextIteration
; loopz doesn't want to work for some reason? always decrements cx by 2.
; loopnz is horribly broken, too. infinite loop.
string.putChar ; display character on screen
macro keyboard.inputString {
.inputString:
push ax
push bx
push cx
push di
push dx
mov cl, al ; hold AX values elsewhere - will be destroyed by .getKey
mov ch, 0 ; cx = number of characters to get
mov bl, ah ; bl = echo flag
mov dx, di ; save start of pointer in dx
.inputString.nextIteration:
loop .inputString.getNextKey

.inputString.appendTerminator:
mov al, 0
mov [di], al
.inputString.return:
pop dx
pop di
pop cx
pop bx
pop ax
ret
.inputString.backspace:
cmp dx, di ; beginning of string?
je .inputString.getNextKey
; act like nothing ever happened
.inputString.getNextKey:
call .waitForKey
cmp al, 0x0D ; enter key pressed? stop accepting input and return string
je .inputString.appendTerminator
cmp al, 0x08 ; backspace key pressed? clear previous character
je .inputString.backspace
mov [di], al ; store character
inc di
cmp bl, 0 ; echo enabled?
jz .inputString.nextIteration
; loopz doesn't want to work for some reason? always decrements cx by 2.
; loopnz is horribly broken, too. infinite loop.
string.putChar ; display character on screen
.inputString.nextIteration:
loop .inputString.getNextKey
; else...
dec di ; previous position in buffer
cmp bl, 0 ; echo enabled?
jz .inputString.offsetCounter
string.putChar ; backspace cursor
mov al, ' '
string.putChar ; blank that character
mov al, 0x08
string.putChar ; and backspace again
.inputString.offsetCounter:
inc cx
jmp .inputString.getNextKey
.inputString.appendTerminator:
mov al, 0
mov [di], al
.inputString.return:
pop dx
pop di
pop cx
pop bx
pop ax
ret
.inputString.backspace:
cmp dx, di ; beginning of string?
je .inputString.getNextKey
; act like nothing ever happened
; else...
dec di ; previous position in buffer
cmp bl, 0 ; echo enabled?
jz .inputString.offsetCounter
string.putChar ; backspace cursor
mov al, ' '
string.putChar ; blank that character
mov al, 0x08
string.putChar ; and backspace again
.inputString.offsetCounter:
inc cx
jmp .inputString.getNextKey
}
10 changes: 0 additions & 10 deletions screen.asm
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
; Screen library
; NAMESPACE: "screen"
screen:
ret
; GLOBAL SYMBOLS
Expand All @@ -16,9 +15,6 @@ screen.mode.gfx.vga_hires equ 0x12 ; 16 colors, 640x480
screen.mode.gfx.vga_lowres equ 0x13 ; 256 colors, 320x200





; ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
; ### MACRO: "setMode"
;
Expand Down Expand Up @@ -48,9 +44,6 @@ macro screen.getMode
}





; SECTION: "text"
; ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
Expand Down Expand Up @@ -135,9 +128,6 @@ macro screen.text.getCharacter
}





; SECTION: "gfx"
; ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
Expand Down
Loading

0 comments on commit 79663b7

Please sign in to comment.