So far, I have a created a program to read the arrow keys and move the cursor around the screen. First the user must enter a 0 to start, and will be able to move around while getch() != 27 (ESC). However, the cursor doesn't move at all.
model tiny
.code
org 100h
program:
mov cx, 10
mov ah, 7
int 21h
cmp al, 0 ; start
je clearS ; clear screen
start:
mov ah, 7 ; AL = getch()
int 21h
cmp al, 27 ; ESC
je fin
cmp al, 72
je moveUp
cmp al, 75
je moveLeft
cmp al, 77
je moveRight
cmp al, 80
je moveDown
moveRight:
mov dl, posY
inc dl ; posY ++
mov posY, dl
jmp prntCrs
jmp start
moveLeft:
mov dh, posX
mov dl, posY
dec dl ; posY --
mov posY, dh
jmp prntCrs
jmp start
moveUp:
mov dl, posY
mov dh, posX
dec dh ; posX --
mov posX, dh
jmp prntCrs ; print cursor
jmp start
moveDown:
mov dl, posY
mov dh, posX
inc dh ; posX ++
mov posX, dh
jmp prntCrs
jmp start
prntCrs: ; print cursor
mov ah, 2h
int 10h
clearS: ; clear screen
mov ah, 7
mov al, 25
mov ch, 0
mov cl, 0
mov dh, 24
mov dl, 79
int 10h
mov ah, 2
mov bh, 0
mov dh, 0
mov dl, 0
int 10h
jmp start
fin:int 20h
posX db 1 dup(0) ; dh = posX -> controls row
posY db 1 dup(0) ; dl = posY -> controls column
end program
------------------------------------------------------------------
Let's say I have this:
moveDown:
mov dl, posX
mov dh, posY
cmp dh, 9 ; limit
je stayLine
inc dh ; posY ++
mov posY, dh
add curr_line, 36 ;increment by line/string size
jmp prntCrs
goBackLine:
mov dl, posX
mov dh, posY
cmp dh, 1 ; limit
je stayLine
mov dl, 37
dec dh
mov posX, dl
mov posY, dh
sub curr_line, 36 ; go to start of last line
add curr_char, 35 ; to go to last char of last line
jmp prntCrs
nextLine:
mov dl, posX
mov dh, posY
mov dl, 1
inc dh
mov posX, dl
mov posY, dh
add curr_line, 36
mov curr_char, 0 ; or move it to whatever dl is?
jmp prntCrs
posX db 1 dup(1) ; dl = posX -> controls column
posY db 1 dup(1) ; dh = posY -> controls row
xlimit dw 38 ; number of columns (w/ border)
ylimit dw 10 ; number of rows (w/ border)
matrix db 36*8 dup(42)
curr_line dw ? ; pointer to current line
curr_char dw ? ; pointer to current char
How would I save user input?
mov si, offset ???
add si, curr_char
mov byte ptr [si], al
mov cl, dl ; to not lose value of posX
mov dl, al ; to be able to print
mov ah, 2h ; character output
int 21h ; display character in dl
mov dl, cl
inc dl ; to move right
mov posX, dl ; update posX
cmp posX, 38
je nextline
inc si
jmp writing