The int 10h , ah as 0d in assembly always returns 0 as the color of the pixel under the mouse pointer

Viewed 180

The code allows the player to move the mouse and when the player press the left button he compares the color of the pressed pixel with red. int 10h, ah as 0d always returns 0 as the color of the pixel, what should i do?

mov ax, 0
int 33h
mov ax,1h
int 33h
check:
    mov ax, 3
    int 33h
    cmp bx, 1
    jne check
mov ax, 4
int 33h
xor ax, ax
mov ah, 0Dh
mov bh, 0
int 10h
cmp al, 0100b
je print_white_screen
2 Answers

My guess is that the pixel is being reported as black because that's what the outline of the mouse pointer is. The BIOS won't compensate for showing the colour under the mouse pointer. Try hiding the mouse pointer (int 33h, ah = 02), doing the pixel read, and reshowing the pointer (int 33h, ah = 01).

  • Depending on the video mode, you might be probing the wrong screen dot.
    The mouse function 03h always returns X values in the range 0-639 and Y values in the range 0-199, regardless of video mode. But the video function 0Dh does expect screen dependent coordinates.

  • The coord reported by the mouse is the mouse cursor's hot spot. Make sure that it corresponds to an ON pixel in the mouse mask. You can use mouse function 09h to define these yourself. Alternatively offset the reported coords so as to refer to the middle of the standard mouse arrow. That's a point that will be ON.

  • cmp al, 0100b Why do you expect the color to be red? The standard mouse arrow obtained from mouse function 00h will be white. Best use cmp al, 15.

  • If you're testing for a pixel from the background then you should hide the mouse arrow (mouse function 02h) before asking BIOS to read that pixel. Your code currently does a redundant call of mouse function 04h!

Related