Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Cursor problem

shaolin007shaolin007 Member Posts: 1,018
How do you set the cursor if your writing directly to video memory? The Program below is a to upper case converter, and works well except for a few minor glitches, but when I run it the cursor is at 0,0 all the time.
NASM CODE
[code]
;NASM-IDE ASM Assistant Assembler Project File
BITS 16 ;Set code generation to 16 bit mode
ORG 0x0100 ;Set code start address to 0100h


SEGMENT .text ;Main code segment
push es
mov ax, 0b800h
mov es, ax ;Get location for di after the string is printed
mov si, key
xor di, di
mov ah, 7
call Print
pop es

push es
mov bx, upcase
mov ax, 0b800h
mov es, ax
inc di ;Have the input 2 spaces from string
inc di
call GetInput
pop es

push es
mov si, new
mov di, 640
mov ax, 0b800h ;Show message for uppercase conversion
mov es, ax
mov ah, 7
call Print
pop es

push es
mov di, 688
mov ax, 0b800h
mov es, ax
mov si, upcase ;Show upper case
mov cx, 16
mov ah, 7
call ToUpper
pop es

mov ah, 0
int 16h

mov ax, 4c00h
int 21h



ToUpper:
cmp cx, 0
je .Done
lodsb
and al, 11011111b ;make uppercase
stosw
dec cx
jmp ToUpper
.Done:
ret

Print:
cmp byte [si], 0
je .Done
lodsb
stosw
jmp Print
.Done:
ret

GetInput:
mov ah, 0
int 16h
mov ah, 7

cmp al,8 ;check for backspace. This is glitchy
je .ErrorTrap

cmp al, 13 ;check for enter
je .Done

cmp al, 97
jl GetInput
;can't enter anything but lower case!
cmp al, 122
jg GetInput

cmp di, 124 ;if di is greater than 124 then go back 1
jg .ErrorTrap

stosw
cmp bx, 16 ;check to see if the input will exceed 16-
je .ErrorTrap ;if it does then go back 1
mov byte [bx], al
inc bx

jmp GetInput
.ErrorTrap:
dec bx ;go back 1 in array
dec di
dec di ;go back 1 word in index
jmp GetInput
.Done:
ret



SEGMENT .data ;Initialised data segment

key db "Type a lowercase word to convert to uppercase:",0
new db "Converted to uppercase:",0
upcase times 16 db ' '

SEGMENT .bss ;Uninitialised data segment
[/code]
Thanks for the help!

Comments

  • jeffleydajeffleyda Member Posts: 390
    : How do you set the cursor if your writing directly to video memory? The Program below is a to upper case converter, and works well except for a few minor glitches, but when I run it the cursor is at 0,0 all the time.

    The cursor is an independant element in the video hardware and has nothing to with the contents on the screen. You have to control it yourself.

    Here's some code that uses INT 10 to set the location, and a compliment routine to read the position off the screen.
    It assumes you're using text modes.

    -jeff!

    [code]
    ;===========================================================================
    ;procedure: locate
    ;
    ;purpose: Moves the cursor to row,col
    ;
    ;requires: DH=row, DL=column
    ;
    ;returns: nothing
    ;
    ;notes: No checking is done for valid coordinates
    ;----------------------------------------------------------------------------
    locate PROC NEAR
    push ax
    push bx
    mov ah,2
    mov bh,0 ;page 0
    int 10h ;position cursor at DX
    pop bx
    pop ax
    ret
    locate ENDP
    ;===========================================================================
    ;procedure: _locate
    ;
    ;purpose: returns the current cursor location in DX
    ;
    ;requires: nothing
    ;
    ;returns: DH=row, DL=column CX=cursor size, attributes
    ;
    ;notes:
    ;----------------------------------------------------------------------------
    _locate PROC NEAR
    push ax
    push bx
    mov ah,3
    mov bh,0 ;page 0
    int 10h ;position cursor at DX
    pop bx
    pop ax
    ret
    _locate ENDP


    [/code]

  • shaolin007shaolin007 Member Posts: 1,018
    : : How do you set the cursor if your writing directly to video memory? The Program below is a to upper case converter, and works well except for a few minor glitches, but when I run it the cursor is at 0,0 all the time.
    :
    : The cursor is an independant element in the video hardware and has nothing to with the contents on the screen. You have to control it yourself.
    :
    : Here's some code that uses INT 10 to set the location, and a compliment routine to read the position off the screen.
    : It assumes you're using text modes.
    :
    : -jeff!
    :
    : [code]
    : ;===========================================================================
    : ;procedure: locate
    : ;
    : ;purpose: Moves the cursor to row,col
    : ;
    : ;requires: DH=row, DL=column
    : ;
    : ;returns: nothing
    : ;
    : ;notes: No checking is done for valid coordinates
    : ;----------------------------------------------------------------------------
    : locate PROC NEAR
    : push ax
    : push bx
    : mov ah,2
    : mov bh,0 ;page 0
    : int 10h ;position cursor at DX
    : pop bx
    : pop ax
    : ret
    : locate ENDP
    : ;===========================================================================
    : ;procedure: _locate
    : ;
    : ;purpose: returns the current cursor location in DX
    : ;
    : ;requires: nothing
    : ;
    : ;returns: DH=row, DL=column CX=cursor size, attributes
    : ;
    : ;notes:
    : ;----------------------------------------------------------------------------
    : _locate PROC NEAR
    : push ax
    : push bx
    : mov ah,3
    : mov bh,0 ;page 0
    : int 10h ;position cursor at DX
    : pop bx
    : pop ax
    : ret
    : _locate ENDP
    :
    :
    : [/code]
    [green] Thanks jeff, I got it to work mainly but for a few little glitches that I'll work out with no problem.[/green]
Sign In or Register to comment.