I'm trying to draw a rectangle in graphics mode (13h) and check whether it was clicked at any time or not, if it was ever clicked I would like to go to "rectangleWasClicked:" , this was my approach for this, however it doesn't seem to work (in terms of getting the drawn rectangle clicked).
getAction:
mov ax, 0001h
int 33h ;Show Mouse
checkMousePointer ; This simply does: mov ax,3 int 33h
drawPlatform 65, 85, 15, 10, 240 ;This draws a rectangle, it takes x,y, color, height, width
cmp bx,1 ;The user clicked, we need to check if that was on the rectangle
;shr cx
jnz getAction ;It's not, so we keep checking
;Checking if the click was on the rectangle
cmp cx,65
jb done
cmp cx,305
ja done
cmp dx,85
jb done
cmp dx,95
ja done
JMP rectangleWasClicked
done:
jmp getAction
I even tried shr cx, 1 to accommodate to the fact that the macro might be using a 640x200 resolution, however that didn't seem to work. I also tried comparing bx to 0 instead of 1 so that whenever the mouse hovers in the region I specified it goes to the label however no matter where I hover in the whole screen it does nothing. Any thoughts?
This is the drawPlatform macro:
drawPlatform macro x, y, color, height, width ;x, y are the starting position (top left corner)
local whilePlatformBeingDrawn
mov cx,x
mov dx,y
whilePlatformBeingDrawn:
drawPixel_implicit color
inc cx ;the x-coordinate
checkDifference cx, x, width ;Keep adding Pixels till Cx-P_x=widthPlatform
JNG whilePlatformBeingDrawn
mov cx, x
inc dx
checkDifference dx, y, height
JNG whilePlatformBeingDrawn
endm drawPlatform
It looks to me like drawPlatform is trashing cx
and dx
before you compare them to mouse coordinates. If you push cx
push dx
before calling drawPlatform and then pop dx
pop cx
afterwards, it should work.
Doesn't TASM come with Turbo Debugger? Or at least if you have some print routines you could put some screen messages in strategic places in the code to see the flow of events.