Why cursor doesn't move vertically on real hardware but does on a virtual machine?












4















I want to implement cursor movement using keys in my OS. I tried this code to do that:



mouse:
mov ah,0h
int 16h

cmp al, 107
je Down


cmp al, 105
je Up


cmp al, 106
je Left


cmp al, 108
je Right

jmp mouse

Right:
add dl, 1
call SetCursor
jmp mouse
ret

Left:
sub dl, 1
call SetCursor
jmp mouse
ret

Up:
sub dh, 1
call SetCursor
jmp mouse
ret

Down:
add dh, 1
call SetCursor
jmp mouse
ret

SetCursor:
mov ah, 02h
mov bh, 00
int 10h
ret


Bootloader (a little part of it):



%include "stage2info.inc"

STAGE2_LOAD_SEG equ STAGE2_ABS_ADDR>>4

.stage2_loaded:
mov ax, STAGE2_RUN_SEG
mov ds, ax
mov es, ax
jmp STAGE2_RUN_SEG:STAGE2_RUN_OFS

TIMES 510-($-$$) db 0
dw 0xaa55


Why cursor doesn't moves vertically on real hardware but does on a virtual machine?
I tried to change the keys but nothing, same.
Why the code doesn't work on real hardware?
Is my code wrong?










share|improve this question




















  • 1





    Where does this program run? Is this your whole code? Does it run from within DOS?

    – fuz
    Jan 2 at 14:35











  • It run bootable. Yes whole code is mine.

    – fsdfff
    Jan 2 at 14:36








  • 1





    @fsdfff That might be the issues. Most BIOSes don't like to boot from a medium without a boot signature.

    – fuz
    Jan 2 at 15:08






  • 2





    @fsdfff Please post updated code with the boot signature in it.

    – fuz
    Jan 2 at 15:44






  • 1





    it works only for up key , left key and right key. Down key on real hardware it still does not work.

    – fsdfff
    Jan 2 at 17:31
















4















I want to implement cursor movement using keys in my OS. I tried this code to do that:



mouse:
mov ah,0h
int 16h

cmp al, 107
je Down


cmp al, 105
je Up


cmp al, 106
je Left


cmp al, 108
je Right

jmp mouse

Right:
add dl, 1
call SetCursor
jmp mouse
ret

Left:
sub dl, 1
call SetCursor
jmp mouse
ret

Up:
sub dh, 1
call SetCursor
jmp mouse
ret

Down:
add dh, 1
call SetCursor
jmp mouse
ret

SetCursor:
mov ah, 02h
mov bh, 00
int 10h
ret


Bootloader (a little part of it):



%include "stage2info.inc"

STAGE2_LOAD_SEG equ STAGE2_ABS_ADDR>>4

.stage2_loaded:
mov ax, STAGE2_RUN_SEG
mov ds, ax
mov es, ax
jmp STAGE2_RUN_SEG:STAGE2_RUN_OFS

TIMES 510-($-$$) db 0
dw 0xaa55


Why cursor doesn't moves vertically on real hardware but does on a virtual machine?
I tried to change the keys but nothing, same.
Why the code doesn't work on real hardware?
Is my code wrong?










share|improve this question




















  • 1





    Where does this program run? Is this your whole code? Does it run from within DOS?

    – fuz
    Jan 2 at 14:35











  • It run bootable. Yes whole code is mine.

    – fsdfff
    Jan 2 at 14:36








  • 1





    @fsdfff That might be the issues. Most BIOSes don't like to boot from a medium without a boot signature.

    – fuz
    Jan 2 at 15:08






  • 2





    @fsdfff Please post updated code with the boot signature in it.

    – fuz
    Jan 2 at 15:44






  • 1





    it works only for up key , left key and right key. Down key on real hardware it still does not work.

    – fsdfff
    Jan 2 at 17:31














4












4








4


0






I want to implement cursor movement using keys in my OS. I tried this code to do that:



mouse:
mov ah,0h
int 16h

cmp al, 107
je Down


cmp al, 105
je Up


cmp al, 106
je Left


cmp al, 108
je Right

jmp mouse

Right:
add dl, 1
call SetCursor
jmp mouse
ret

Left:
sub dl, 1
call SetCursor
jmp mouse
ret

Up:
sub dh, 1
call SetCursor
jmp mouse
ret

Down:
add dh, 1
call SetCursor
jmp mouse
ret

SetCursor:
mov ah, 02h
mov bh, 00
int 10h
ret


Bootloader (a little part of it):



%include "stage2info.inc"

STAGE2_LOAD_SEG equ STAGE2_ABS_ADDR>>4

.stage2_loaded:
mov ax, STAGE2_RUN_SEG
mov ds, ax
mov es, ax
jmp STAGE2_RUN_SEG:STAGE2_RUN_OFS

TIMES 510-($-$$) db 0
dw 0xaa55


Why cursor doesn't moves vertically on real hardware but does on a virtual machine?
I tried to change the keys but nothing, same.
Why the code doesn't work on real hardware?
Is my code wrong?










share|improve this question
















I want to implement cursor movement using keys in my OS. I tried this code to do that:



mouse:
mov ah,0h
int 16h

cmp al, 107
je Down


cmp al, 105
je Up


cmp al, 106
je Left


cmp al, 108
je Right

jmp mouse

Right:
add dl, 1
call SetCursor
jmp mouse
ret

Left:
sub dl, 1
call SetCursor
jmp mouse
ret

Up:
sub dh, 1
call SetCursor
jmp mouse
ret

Down:
add dh, 1
call SetCursor
jmp mouse
ret

SetCursor:
mov ah, 02h
mov bh, 00
int 10h
ret


Bootloader (a little part of it):



%include "stage2info.inc"

STAGE2_LOAD_SEG equ STAGE2_ABS_ADDR>>4

.stage2_loaded:
mov ax, STAGE2_RUN_SEG
mov ds, ax
mov es, ax
jmp STAGE2_RUN_SEG:STAGE2_RUN_OFS

TIMES 510-($-$$) db 0
dw 0xaa55


Why cursor doesn't moves vertically on real hardware but does on a virtual machine?
I tried to change the keys but nothing, same.
Why the code doesn't work on real hardware?
Is my code wrong?







assembly operating-system x86-16 bootloader osdev






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 1 at 13:51









Paul Floyd

2,73421831




2,73421831










asked Jan 2 at 14:31









fsdffffsdfff

426




426








  • 1





    Where does this program run? Is this your whole code? Does it run from within DOS?

    – fuz
    Jan 2 at 14:35











  • It run bootable. Yes whole code is mine.

    – fsdfff
    Jan 2 at 14:36








  • 1





    @fsdfff That might be the issues. Most BIOSes don't like to boot from a medium without a boot signature.

    – fuz
    Jan 2 at 15:08






  • 2





    @fsdfff Please post updated code with the boot signature in it.

    – fuz
    Jan 2 at 15:44






  • 1





    it works only for up key , left key and right key. Down key on real hardware it still does not work.

    – fsdfff
    Jan 2 at 17:31














  • 1





    Where does this program run? Is this your whole code? Does it run from within DOS?

    – fuz
    Jan 2 at 14:35











  • It run bootable. Yes whole code is mine.

    – fsdfff
    Jan 2 at 14:36








  • 1





    @fsdfff That might be the issues. Most BIOSes don't like to boot from a medium without a boot signature.

    – fuz
    Jan 2 at 15:08






  • 2





    @fsdfff Please post updated code with the boot signature in it.

    – fuz
    Jan 2 at 15:44






  • 1





    it works only for up key , left key and right key. Down key on real hardware it still does not work.

    – fsdfff
    Jan 2 at 17:31








1




1





Where does this program run? Is this your whole code? Does it run from within DOS?

– fuz
Jan 2 at 14:35





Where does this program run? Is this your whole code? Does it run from within DOS?

– fuz
Jan 2 at 14:35













It run bootable. Yes whole code is mine.

– fsdfff
Jan 2 at 14:36







It run bootable. Yes whole code is mine.

– fsdfff
Jan 2 at 14:36






1




1





@fsdfff That might be the issues. Most BIOSes don't like to boot from a medium without a boot signature.

– fuz
Jan 2 at 15:08





@fsdfff That might be the issues. Most BIOSes don't like to boot from a medium without a boot signature.

– fuz
Jan 2 at 15:08




2




2





@fsdfff Please post updated code with the boot signature in it.

– fuz
Jan 2 at 15:44





@fsdfff Please post updated code with the boot signature in it.

– fuz
Jan 2 at 15:44




1




1





it works only for up key , left key and right key. Down key on real hardware it still does not work.

– fsdfff
Jan 2 at 17:31





it works only for up key , left key and right key. Down key on real hardware it still does not work.

– fsdfff
Jan 2 at 17:31












1 Answer
1






active

oldest

votes


















4














Issues and comments:




  • To check for the arrow keys you need to look at the scancodes in AH, not the ASCII characters in AL. Scan codes are 0x50 for down, 0x48 for up, 0x4b for left, and 0x4d for right

  • You don't initialize DH and DL before entering your mouse loop. Retrieve the current coordinates with Int 10h/AH=3h before entering the loop

  • You don't test the bounds going off the top, left, right, and bottom edges of the screen so if the cursor goes out of bounds unexpected things can happen

  • You have unnecessary ret instructions after jmp mouse that can never be reached.

  • You can use INC and DEC instructions to add or subtract one from a register rather than using ADD and SUB with a value of one.

  • For people viewing the question, the bootloader being used is a template I put together in this Stackoverflow Answer.


This code should work:



%include "stage2info.inc"
ORG STAGE2_RUN_OFS

BITS 16

MAX_ROW equ 25 ; 80x25 screen extents
MAX_COL equ 80

mouse:
mov ah, 3 ; Get cursor BIOS call
mov bh, 0 ; Page number is zero
int 10h ; DH and DL will be set to current coordinates.

mov ah,0h
int 16h

cmp ah, 0x50
je Down

cmp ah, 0x48
je Up

cmp ah, 0x4b
je Left

cmp ah, 0x4d
je Right

jmp mouse

Right:
inc dl
cmp dl, MAX_COL ; Test for right edge.
jl right_bound_ok
mov dl, MAX_COL-1
right_bound_ok:
call SetCursor
jmp mouse

Left:
dec dl
jge left_bound_ok ; Test for left edge (<0?)

mov dl, 0
left_bound_ok:
call SetCursor
jmp mouse

Up:
dec dh
jge up_bound_ok ; Test for upper edge (<0?)

mov dh, 0
up_bound_ok:
call SetCursor
jmp mouse

Down:
inc dh
cmp dh, MAX_ROW ; Test for bottom edge
jl down_bound_ok
mov dh, MAX_ROW-1
down_bound_ok:
call SetCursor
jmp mouse

SetCursor:
mov ah, 02h
mov bh, 00
int 10h
ret





share|improve this answer


























  • Comments are not for extended discussion; this conversation has been moved to chat.

    – Samuel Liew
    Jan 2 at 22:59











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54008141%2fwhy-cursor-doesnt-move-vertically-on-real-hardware-but-does-on-a-virtual-machin%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









4














Issues and comments:




  • To check for the arrow keys you need to look at the scancodes in AH, not the ASCII characters in AL. Scan codes are 0x50 for down, 0x48 for up, 0x4b for left, and 0x4d for right

  • You don't initialize DH and DL before entering your mouse loop. Retrieve the current coordinates with Int 10h/AH=3h before entering the loop

  • You don't test the bounds going off the top, left, right, and bottom edges of the screen so if the cursor goes out of bounds unexpected things can happen

  • You have unnecessary ret instructions after jmp mouse that can never be reached.

  • You can use INC and DEC instructions to add or subtract one from a register rather than using ADD and SUB with a value of one.

  • For people viewing the question, the bootloader being used is a template I put together in this Stackoverflow Answer.


This code should work:



%include "stage2info.inc"
ORG STAGE2_RUN_OFS

BITS 16

MAX_ROW equ 25 ; 80x25 screen extents
MAX_COL equ 80

mouse:
mov ah, 3 ; Get cursor BIOS call
mov bh, 0 ; Page number is zero
int 10h ; DH and DL will be set to current coordinates.

mov ah,0h
int 16h

cmp ah, 0x50
je Down

cmp ah, 0x48
je Up

cmp ah, 0x4b
je Left

cmp ah, 0x4d
je Right

jmp mouse

Right:
inc dl
cmp dl, MAX_COL ; Test for right edge.
jl right_bound_ok
mov dl, MAX_COL-1
right_bound_ok:
call SetCursor
jmp mouse

Left:
dec dl
jge left_bound_ok ; Test for left edge (<0?)

mov dl, 0
left_bound_ok:
call SetCursor
jmp mouse

Up:
dec dh
jge up_bound_ok ; Test for upper edge (<0?)

mov dh, 0
up_bound_ok:
call SetCursor
jmp mouse

Down:
inc dh
cmp dh, MAX_ROW ; Test for bottom edge
jl down_bound_ok
mov dh, MAX_ROW-1
down_bound_ok:
call SetCursor
jmp mouse

SetCursor:
mov ah, 02h
mov bh, 00
int 10h
ret





share|improve this answer


























  • Comments are not for extended discussion; this conversation has been moved to chat.

    – Samuel Liew
    Jan 2 at 22:59
















4














Issues and comments:




  • To check for the arrow keys you need to look at the scancodes in AH, not the ASCII characters in AL. Scan codes are 0x50 for down, 0x48 for up, 0x4b for left, and 0x4d for right

  • You don't initialize DH and DL before entering your mouse loop. Retrieve the current coordinates with Int 10h/AH=3h before entering the loop

  • You don't test the bounds going off the top, left, right, and bottom edges of the screen so if the cursor goes out of bounds unexpected things can happen

  • You have unnecessary ret instructions after jmp mouse that can never be reached.

  • You can use INC and DEC instructions to add or subtract one from a register rather than using ADD and SUB with a value of one.

  • For people viewing the question, the bootloader being used is a template I put together in this Stackoverflow Answer.


This code should work:



%include "stage2info.inc"
ORG STAGE2_RUN_OFS

BITS 16

MAX_ROW equ 25 ; 80x25 screen extents
MAX_COL equ 80

mouse:
mov ah, 3 ; Get cursor BIOS call
mov bh, 0 ; Page number is zero
int 10h ; DH and DL will be set to current coordinates.

mov ah,0h
int 16h

cmp ah, 0x50
je Down

cmp ah, 0x48
je Up

cmp ah, 0x4b
je Left

cmp ah, 0x4d
je Right

jmp mouse

Right:
inc dl
cmp dl, MAX_COL ; Test for right edge.
jl right_bound_ok
mov dl, MAX_COL-1
right_bound_ok:
call SetCursor
jmp mouse

Left:
dec dl
jge left_bound_ok ; Test for left edge (<0?)

mov dl, 0
left_bound_ok:
call SetCursor
jmp mouse

Up:
dec dh
jge up_bound_ok ; Test for upper edge (<0?)

mov dh, 0
up_bound_ok:
call SetCursor
jmp mouse

Down:
inc dh
cmp dh, MAX_ROW ; Test for bottom edge
jl down_bound_ok
mov dh, MAX_ROW-1
down_bound_ok:
call SetCursor
jmp mouse

SetCursor:
mov ah, 02h
mov bh, 00
int 10h
ret





share|improve this answer


























  • Comments are not for extended discussion; this conversation has been moved to chat.

    – Samuel Liew
    Jan 2 at 22:59














4












4








4







Issues and comments:




  • To check for the arrow keys you need to look at the scancodes in AH, not the ASCII characters in AL. Scan codes are 0x50 for down, 0x48 for up, 0x4b for left, and 0x4d for right

  • You don't initialize DH and DL before entering your mouse loop. Retrieve the current coordinates with Int 10h/AH=3h before entering the loop

  • You don't test the bounds going off the top, left, right, and bottom edges of the screen so if the cursor goes out of bounds unexpected things can happen

  • You have unnecessary ret instructions after jmp mouse that can never be reached.

  • You can use INC and DEC instructions to add or subtract one from a register rather than using ADD and SUB with a value of one.

  • For people viewing the question, the bootloader being used is a template I put together in this Stackoverflow Answer.


This code should work:



%include "stage2info.inc"
ORG STAGE2_RUN_OFS

BITS 16

MAX_ROW equ 25 ; 80x25 screen extents
MAX_COL equ 80

mouse:
mov ah, 3 ; Get cursor BIOS call
mov bh, 0 ; Page number is zero
int 10h ; DH and DL will be set to current coordinates.

mov ah,0h
int 16h

cmp ah, 0x50
je Down

cmp ah, 0x48
je Up

cmp ah, 0x4b
je Left

cmp ah, 0x4d
je Right

jmp mouse

Right:
inc dl
cmp dl, MAX_COL ; Test for right edge.
jl right_bound_ok
mov dl, MAX_COL-1
right_bound_ok:
call SetCursor
jmp mouse

Left:
dec dl
jge left_bound_ok ; Test for left edge (<0?)

mov dl, 0
left_bound_ok:
call SetCursor
jmp mouse

Up:
dec dh
jge up_bound_ok ; Test for upper edge (<0?)

mov dh, 0
up_bound_ok:
call SetCursor
jmp mouse

Down:
inc dh
cmp dh, MAX_ROW ; Test for bottom edge
jl down_bound_ok
mov dh, MAX_ROW-1
down_bound_ok:
call SetCursor
jmp mouse

SetCursor:
mov ah, 02h
mov bh, 00
int 10h
ret





share|improve this answer















Issues and comments:




  • To check for the arrow keys you need to look at the scancodes in AH, not the ASCII characters in AL. Scan codes are 0x50 for down, 0x48 for up, 0x4b for left, and 0x4d for right

  • You don't initialize DH and DL before entering your mouse loop. Retrieve the current coordinates with Int 10h/AH=3h before entering the loop

  • You don't test the bounds going off the top, left, right, and bottom edges of the screen so if the cursor goes out of bounds unexpected things can happen

  • You have unnecessary ret instructions after jmp mouse that can never be reached.

  • You can use INC and DEC instructions to add or subtract one from a register rather than using ADD and SUB with a value of one.

  • For people viewing the question, the bootloader being used is a template I put together in this Stackoverflow Answer.


This code should work:



%include "stage2info.inc"
ORG STAGE2_RUN_OFS

BITS 16

MAX_ROW equ 25 ; 80x25 screen extents
MAX_COL equ 80

mouse:
mov ah, 3 ; Get cursor BIOS call
mov bh, 0 ; Page number is zero
int 10h ; DH and DL will be set to current coordinates.

mov ah,0h
int 16h

cmp ah, 0x50
je Down

cmp ah, 0x48
je Up

cmp ah, 0x4b
je Left

cmp ah, 0x4d
je Right

jmp mouse

Right:
inc dl
cmp dl, MAX_COL ; Test for right edge.
jl right_bound_ok
mov dl, MAX_COL-1
right_bound_ok:
call SetCursor
jmp mouse

Left:
dec dl
jge left_bound_ok ; Test for left edge (<0?)

mov dl, 0
left_bound_ok:
call SetCursor
jmp mouse

Up:
dec dh
jge up_bound_ok ; Test for upper edge (<0?)

mov dh, 0
up_bound_ok:
call SetCursor
jmp mouse

Down:
inc dh
cmp dh, MAX_ROW ; Test for bottom edge
jl down_bound_ok
mov dh, MAX_ROW-1
down_bound_ok:
call SetCursor
jmp mouse

SetCursor:
mov ah, 02h
mov bh, 00
int 10h
ret






share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 3 at 1:07

























answered Jan 2 at 18:00









Michael PetchMichael Petch

26.7k556106




26.7k556106













  • Comments are not for extended discussion; this conversation has been moved to chat.

    – Samuel Liew
    Jan 2 at 22:59



















  • Comments are not for extended discussion; this conversation has been moved to chat.

    – Samuel Liew
    Jan 2 at 22:59

















Comments are not for extended discussion; this conversation has been moved to chat.

– Samuel Liew
Jan 2 at 22:59





Comments are not for extended discussion; this conversation has been moved to chat.

– Samuel Liew
Jan 2 at 22:59




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54008141%2fwhy-cursor-doesnt-move-vertically-on-real-hardware-but-does-on-a-virtual-machin%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Mossoró

Error while reading .h5 file using the rhdf5 package in R

Pushsharp Apns notification error: 'InvalidToken'