Skip to content

Commit

Permalink
Fix inputString not counting chars, bksp offset
Browse files Browse the repository at this point in the history
keyboard.inputString was not counting character limits properly due to
an error in the function's execution structure, and it did not properly
offset the character counter appropriately to compensate for backspaced
characters.
  • Loading branch information
Trinitek committed Apr 11, 2014
1 parent 463b5c8 commit 1cb139d
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 21 deletions.
35 changes: 20 additions & 15 deletions keyboard.ASM
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,6 @@ macro keyboard.getKey
.inputString.nextIteration:
loop .inputString.getNextKey

.inputString.backspace:
cmp dx, di ; beginning of string?
je .inputString.nextIteration
dec di ; previous position in buffer
cmp bl, 0 ; echo enabled?
jz .inputString.nextIteration
string.putChar ; backspace cursor
mov al, ' '
string.putChar ; blank that character
mov al, 0x08
string.putChar ; and backspace again
jmp .inputString.nextIteration

.inputString.appendTerminator:
mov al, 0
mov [di], al
Expand All @@ -100,4 +85,24 @@ macro keyboard.getKey
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
51 changes: 45 additions & 6 deletions turtle.ASM
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
start.yPos equ 12
promptColor equ 0x1F ; white on blue text
fieldColor equ 0x2F ; white on green text
turtleFace equ 0x02 ; filled smiley face

; ==============================
; === ENTRY POINT ==============
Expand Down Expand Up @@ -63,7 +64,7 @@ createScreen:
mov cursor.xPos, start.xPos
mov cursor.yPos, start.yPos
screen.text.setCursorPosition
mov al, [data_turtle.face]
mov al, turtleFace
string.putChar
call showHelp
Expand All @@ -76,7 +77,7 @@ createScreen:
main:
; get command string from keyboard
; ==============================
mov al, 8 ; 23 max characters
mov al, 8 ; 8 max characters
mov ah, 1 ; echo enabled
mov di, data_str.buffer ; pointer to string buffer
call keyboard.inputString
Expand Down Expand Up @@ -152,7 +153,28 @@ handler:
; TODO
ret
.paint:
; TODO
mov al, byte [data_turtle.paintToggle]
cmp al, 0
jnz .paint.disable
.paint.enable: ; toggle bit to 1
mov byte [data_turtle.paintToggle], 1
call clearMessageArea ; clear message line
mov cursor.xPos, 0 ; "Paint enabled"
mov cursor.yPos, 23
screen.text.setCursorPosition
mov si, data_str.paintOn
call string.teletype
ret
.paint.disable: ; toggle bit to 0
mov byte [data_turtle.paintToggle], 0
call clearMessageArea ; clear message line
mov cursor.xPos, 0 ; "paint disabled"
mov cursor.yPos, 23
screen.text.setCursorPosition
mov si, data_str.paintOff
call string.teletype
ret

exit:
Expand All @@ -169,13 +191,28 @@ exit:
; === PROCEDURE SECTION ========
; ==============================

showHelp:
clearMessageArea:
pusha

mov cursor.xPos, 0 ; position at 0, 23
mov cursor.yPos, 23
screen.text.setCursorPosition
mov al, ' '
mov bl, promptColor
mov cx, 40
screen.text.setCharacter ; clear prompt line

popa
ret

showHelp:
pusha

mov cursor.xPos, 0 ; position at 0, 23
mov cursor.yPos, 23
screen.text.setCursorPosition
mov si, data_str.help ; show help message
call string.teletype
Expand All @@ -189,6 +226,7 @@ pusha
mov cursor.xPos, 0
mov cursor.yPos, 24
screen.text.setCursorPosition
mov al, ' '
mov bl, promptColor
mov cx, 40
Expand All @@ -197,6 +235,7 @@ pusha
mov cursor.xPos, 0 ; position at 0, 24
mov cursor.yPos, 24
screen.text.setCursorPosition
mov al, '>'
string.putChar ; display carat
Expand All @@ -216,8 +255,8 @@ data_turtle:
db ?
.yPos:
db ?
.face:
db 0x02 ; filled smiley face
.paintToggle:
db 0

data_command:
.up:
Expand Down
Binary file modified turtle.COM
Binary file not shown.

0 comments on commit 1cb139d

Please sign in to comment.