cpu 8086 bits 16 org 0x7c00 jmp 0:start start: cld cli ; Set up segments and stack mov ax, cs mov ds, ax mov es, ax mov ss, ax mov sp, $$ sti initialize_mouse: ; Initialize mouse ; https://www.ctyme.com/intr/rb-1601.htm mov ax, 0xc205 mov bh, 3 ; TODO: This is the usual PS/2 mouse packet size, but is it correct here? int 0x15 jc .error ; Set handler address ; https://www.ctyme.com/intr/rb-1603.htm mov ax, 0xc207 ; es is already set correctly mov bx, mouse_handler int 0x15 jc .error ; Enable mouse ; https://www.ctyme.com/intr/rb-1596.htm mov ax, 0xc200 mov bh, 1 int 0x15 jc .error jmp mainloop .error: ; https://www.ctyme.com/intr/rb-1601.htm mov ax, 0xc201 int 0x15 jmp initialize_mouse mainloop: ; TODO: everything hang: hlt ;mov ax, 0x0e00 + '.' ;int 0x10 jmp hang mouse_handler: push ax push bx push bp mov bp, sp ; status mov bx, [bp+16] ; X negative test bl, 0x10 jz .no_x_negative mov ax, 0x0e00 + '-' int 0x10 .no_x_negative: ; X overflow test bl, 0x40 jz .no_x_overflow mov ax, 0x0e00 + 'o' .no_x_overflow: ; X mov ax, [bp+14] call hexprint8 mov ax, 0x0e00 + ' ' int 0x10 ; Y negative test bl, 0x20 jz .no_y_negative mov ax, 0x0e00 + '-' int 0x10 .no_y_negative: ; Y overflow test bl, 0x80 jz .no_y_overflow mov ax, 0x0e00 + 'o' .no_y_overflow: ; Y mov ax, [bp+12] call hexprint8 mov ax, 0x0e00 + ' ' int 0x10 ; Left mouse test bl, 0x01 jz .no_lmb mov ax, 0x0e00 + 'L' int 0x10 .no_lmb: ; Right mouse test bl, 0x02 jz .no_rmb mov ax, 0x0e00 + 'R' int 0x10 .no_rmb mov ax, 0x0e00 + 13 int 0x10 mov ax, 0x0e00 + 10 int 0x10 pop bp pop bx pop ax retf hexprint16: xchg ah, al call hexprint8 xchg ah, al hexprint8: push ax push cx mov cl, 4 shr al, cl call hexprint4 pop cx pop ax hexprint4: push ax and al, 0xf cmp al, 10 jb .digit09 add al, 'a' - '0' - 10 .digit09: add al, '0' mov ah, 0x0e int 0x10 pop ax ret times 510-($-$$) db 0 db 0x55 db 0xaa