getting mouse input in x86 assembly | SCHIZONE EP-21
HTML-код
- Опубликовано: 9 сен 2024
- 21st video in a series on scientific computing from scratch using x86-64 assembly. This video describes capturing and using mouse input for different purposes on Linux.
code: github.com/xmd...
3 good resources:
x86 instruction reference:
www.felixclout...
linux/freebsd syscall concordance:
www.lurklurk.o...
old draft of System-V ABI:
refspecs.linux...
secret discord link:
xmdi.us/misc/d...
lol the beginning is gold
Not only did the third tower fall, it was reported that it collapsed before it actually happened! Cool video, joking aside. I've wanted to learn assembly, but the only assembly I've written is 6502
On PC booting MS DOS i used an edited true color picture from my web cam of a green watering can made of plastik with black background as a mouse pointer. I load the picture in the upper left corner of the linear framebuffer and then i made a table with the address 4 bytes and 4 bytes for color of each pixel. And additional we need space for a second table to store the background with the same size.
Without a mouse drive for PS2 mouse (USB mouse with USB legacy enable in mainboard setup) we can use our own mouse handler like the open source Cutemouse driver, if we modify the handler to store the mouse bytes into our data segment. Our main routine can use the coordinates to draw a mouse pointer.
checkPS2:
int 11h ; get equipment list
test al, 3
jz noPS2 ; jump if PS/2-Mouse not indicated
mov bh,3
mov ax, 0C205h
int 15h ; initialize mouse, bh=datasize
jc noPS2
mov bh,3
mov ax, 0C203h
int 15h ; set mouse resolution bh
jc noPS2
mov ax, cs
mov es, ax
mov bx, OFFSET PS2dummy
mov ax, 0C207h
int 15h ; mouse, es:bx=ptr to handler
jc noPS2
xor bx, bx
mov es, bx ; mouse, es:bx=ptr to handler
mov ax, 0C207h
int 15h
ret
noPS2:
stc
ret
PS2dummy:
retf
;---------------------------------------------------------
enablePS2:
call disablePS2
mov ax, cs
mov es, ax
mov bx, OFFSET IRQhandler
mov ax, 0C207h ; es:bx=ptr to handler
int 15h
mov bh,1 ; set mouse on
mov ax, 0C200h
int 15h
ret
;-------------------------------
disablePS2:
xor bx, bx ; set mouse off
mov ax, 0C200h
int 15h
xor bx, bx
mov es, bx
mov ax, 0C207h ; es:bx=ptr to handler
int 15h
ret
;---------------------------------------------------------------------------
IRQhandler:
assume ds:nothing,es:nothing
cld
push ds
push es
pusha
mov ax, cs
mov ds, ax
mov bp,sp
mov al,[bp+24+6] ; buttons
mov bl,al
shl al,3 ; CF=Y sign bit
sbb ch,ch ; signed extension 9->16 bit
cbw ; extend X sign bit
mov al,[bp+24+4] ; AX=X movement
mov cl,[bp+24+2] ; CX=Y movement
xchg bx,ax
neg cx ; reverse Y movement
; placeholder to store the mouse bytes into our data segment.
popa
pop es
pop ds
retf
I draw some button to click on and for mouseover to change the color of the button. And here comes the problem, if some button placed without a distance to each other nearby and we move the mouse very fast we can not check if the pointer is outside of a button and so it is not changing back into the first color. We have to check this too, if the pointer jump from inside one button into another button without to go between the button.
Great intro bro
On Android tablet with a touchscreen i made special batch files to get the mouse coordinates from the driver to output a text message on this location, but i don’t know how to do a mouse click on a touch screen without a mouse.😅
My routine put the coordinates of the mouse pointer into DosBox enviroment variables.
@echo off
REM MCONTROL.BAT
REM Mouse control
cls
call COLOR.BAT 1b
set XMOU=27
set YMOU=0C
echo X = %XMOU%
echo Y = %YMOU%
echo Move the mouse pointer to a position for text output and ...
call SHOWMOUS.BAT
call SETMOUS.BAT %XMOU% %YMOU%
pause
call GETMOUS.BAT
call CURSOR.BAT 0 0 0
echo X = %XMOU%
echo Y = %YMOU%
echo.
echo.
call HIDEMOUS.BAT
call ColText.bat %YMOU% %XMOU% 2f "test"
set XMOU=
set YMOU=
I'm new to Linux, what mouse image thing are you using to make it pepe?
Good question- it's actually not a Linux cursor (it's tracked and generated by the assembly code itself), and pepe is actually not an image file at all. Pepe's raw RGB pixel values are directly encoded as bytes in the assembly executable. The code then plots those RGB values on top of the rest of the screen based on where the mouse moves. Fun fact, the assembly code in this series is so minimal that the ~28x14 pixel pepe makes up around half of these Episode 21 executables (in terms of filesize). Thanks for your interest.
That's awesome! I hadn't finished the video, but now you've got my curious about overlaying the pixels. Thank you! @@xmdi0
You're on windows XP but using a KDE program, talking about how to read mouse input on linux, seems legit
I have attachment issues github.com/grassmunk/Chicago95
@@xmdi0 neat
Damn, that's really how you wanted to start the video? Oof.
The beginning is cringy af.