News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Mouse and paint pixel issues.

Started by ccdcmc421, December 20, 2024, 10:55:08 AM

Previous topic - Next topic

ccdcmc421

Hello folks!

I am trying to work on creating a paint program in 16 bit mode. However, I am running into a strange issues that I am having a hard time really understanding. I will try to describe what the problems are:

Problem 1:
when I move the mouse, no matter the sensitivity of the mouse slow or fast, going across the x axis, it will always skip one pixel. so the original background (for this example white) will always be present inbetween red lines that I draw (picture provided). I am not sure if this is just how I have my crapy design of this mouse laid out or if it's just something I am completely missing.


Problem 2
the mouse and where the place of where I am trying to draw are not matching properly.

For example, if I do not move the mouse but tell the program to draw a red pixel somewhere, it will draw it waaaaayyy off to the right of the cursor. when I am moving the cursor and drawing, it feels like the cursor is following the speed of my system's mouse as opposed to the one generated? However, I am not sure how true that is, that is just what it feels like. the only time that the line matches the center of the cursor is if I move the cursor all the way to the left and it will be exactly where I want it. However, if I still want to continue drawing on the left hand side, it's like the black dot of the cursor overlaps the red that I am drawing and doesn't seem to draw it. Do I need to hide my cursor then draw the red then have the cursor re-appear?

Picture provided shows the cursor, the red lines and how far items are to the right of the cursor (the set of lines closest to the cursor that it's across to is the distance of how far these items are getting drawn from the cursor.

I appreciate your read. I would also love to know what I am doing wrong (which I am sure it's a lot lol). if there is anything that you feel like I should try and re-clarify please let me know as well. I really would like to understand what I am missing!


P.S. A question that is a bit off-topic, why do we need to define custom cursors like this?

Screenmask DW 1111111111111111b
DW 1111111111111111b
DW 1111111111111111b
DW 1111111111111111b
DW 1111111111111111b
DW 1111111111111111b
DW 1111110101111111b
DW 0000000000000000b
DW 1111110101111111b
DW 1111111111111111b
DW 1111111111111111b
DW 1111111111111111b
DW 1111111111111111b
DW 1111111111111111b
DW 1111111111111111b
DW 1111111111111111b; The bottom??
DW 1111111011111111b
DW 1111111011111111b
DW 1111111011111111b
DW 1111111011111111b
DW 1111111011111111b
DW 1111111011111111b
DW 1111111011111111b
DW 1111111011111111b
DW 1111111011111111b
DW 1111111011111111b
DW 1111111011111111b
DW 1111111011111111b
DW 1111111011111111b
DW 1111111011111111b
DW 1111111011111111b
DW 0000000000000000b

.CODE
main PROC
mov AX, @DATA
mov DS, AX

Call GraphicsMode
Call MainProgram

main ENDP


MainProgram PROC


mov AH, 0h ;Get Keystroke interrupt
    int 16h

cmp AL, 1bh
je ClosingProgramMessage ; figure out how to get a transparent overlay then draw the menu for hte paint and shit after that, 1bh is for the esc key on our keyboard

mov AX, 3H
int 33h

cmp BX, 0
je Drawing

jmp MainProgram

MainProgram ENDP

Drawing PROC

mov MouseXAxis, CX ; I am not sure if I should use these things yet. I will just have these here for now.
mov MouseYAxis, DX

;need to follow the equation "CellNumber = (y x Total Columns) + x"
mov AX, DX
mov CX, 320
mul CX
mov BX, [MouseXAxis]
add AX, BX

mov DI, AX

mov CX, 1
mov AL, [SelectedColor]
stosb ;ES is already set to the address of the video memory. DI is set to the column and row of where the hotspot of our mouse should be. so we're going to move the value of AL (which should be a color) to the coordinates

;return to main loop
jmp MainProgram


Drawing ENDP

DrawMenu PROC
ret
DrawMenu ENDP

GraphicsMode PROC

xor AX, AX
xor DX, DX ;Clear the registers just incase.

; I wanted to create a cancelation message, incase someone wanted to download this on the github or something like that. This way, if they accidentally started this program, they can cancel out with ease.
mov DX, Offset CancelMessage
mov AH, 9h ; interrupt prep
int 21h

mov AH, 0h ;Get Keystroke interrupt
    int 16h

;interaction to for the user to actually start the program
cmp AL, 'n'
je ClosingProgram
cmp AL, 'N'
je ClosingProgram
cmp AL, 'y'
je OpenProgram
cmp AL, 'Y'
je OpenProgram
cmp AL, 13h
je OpenProgram

OpenProgram:
mov AH, 0
mov AL, 13h
int 10h
call DrawScreen
ret

GraphicsMode ENDP

InitializeMouse PROC
xor AX, AX
mov AX, 0
int 33h

mov AX, 1
int 33h

mov AX, 2    ; Function 2h: Hide cursor
int 33h

call SetCustomCursor

mov AX, 1    ; Function 1h: Show cursor
int 33h

mov BX, 10
mov CX, 10
mov AX, 001ah ;Function 001Ah set mouse sensitivity
int 33h

ret

InitializeMouse ENDP

SetCustomCursor PROC

xor AX, AX ;Clear AX
mov AX, ES ; store the current value of the extra segment
mov VideoMemoryAddr, AX ; move the value of AX to a address place holder
mov AX, @DATA ; move AX with the address of our data segment
mov ES, AX ; move the value within AX into ES.
xor AX, AX

mov DX, OFFSET ScreenMask

mov CX, 7 ; Hotspot y = 7
mov BX, 7 ; HotSpot x = 7

mov AX, 9h
int 33h

mov AX, [VideoMemoryAddr]
mov ES, AX

mov AX, 002Ah
int 33h

mov MouseXAxis, BX
mov MouseYAxis, CX

ret

SetCustomCursor ENDP

DrawScreen PROC
;setup the extra segment register so we're able to write items to video memory

call SetWhite

xor AX, AX
mov ax, 0A000h ; address of VGA video memory for graphics mode
mov es, ax    ; move to ES register

mov DI, 0 ; start at the very first pixel (the top most left cornor)

mov CX, 320 * 200
    mov AL, 255 ; white color
    rep stosb              ; Store AL (color value) at [ES:DI] for CX amount of times

call initializeMouse ; setup mouse after writting screen
ret
DrawScreen ENDP

sinsi

If you are writing directly to video memory you should hide the mouse, write the pixels then show the mouse.

ccdcmc421

Quote from: sinsi on December 20, 2024, 01:43:07 PMIf you are writing directly to video memory you should hide the mouse, write the pixels then show the mouse.

Thank you for that spot Sinsi! Now we can successfully draw wherever the cursor is. However, I am so stumped on the other issues. I do not even know how to begin researching more about this :(