Draw on screen with mouse in assembly (emu8086)

The code below allows you to draw on the screen with your mouse and work perfectly. My problem is why do I CX

need to divide by 2? Why does it double in the first place?

code segment
main proc far

mov al, 12h
mov ah, 0   ; set graphics video mode.
int 10h   

mov ax, 1   ;shows mouse cursor
int 33h

Next:
mov ax, 3   ;get cursor positon in cx,dx
int 33h

call putpix ;call procedure 
jmp Next

mov ah,4ch
int 21h
main endp

;procedure to print
putpix proc   
mov al, 7   ;color of pixel  
mov ah, 0ch    
shr cx,1    ; cx will get double so we divide it by two
int 10h     ; set pixel.
ret
putpix endp
code ends 

      

+3


source to share


2 answers


The following screenshot of EMU8086 and your code will help us understand what's going on:

  • The purple arrow shows the 12h video mode, which is 640x480.
  • The blue arrow shows where the cursor is when the code gets the cursor position in CX, DX. In the lower right corner, I did this in order to get the maximum values.
  • I've added a "readkey" snippet to stop execution at this point and see the values ​​for CX and DX (yellow bar).
  • The red arrow shows the values ​​for CX and DX. DX - 01DB = 475, which is in the range 0..479. But CX - 04FA = 1274 (green arrow), which is not possible, because the video mode allows columns in the range 0..639.
  • The conclusion is simple: the mouse interrupt 33h returns twice the value for the cursor column. The way to solve this problem is to split the column by 2 ( shr cx,1

    ).


enter image description here

+1


source


It looks like you are facing an error in the emulator (or mouse driver). When I run your program on DOSBox and under MS-DOS 6.22, both running under VirtualBox and directly on the PC, your program only draws the pixels on the left side of the display.

DOSBox screenshot MS-DOS 6.22 under VirtualBox screenshot



You might want to file a bug report with the people who wrote your emulator.

+1


source







All Articles