0

I am trying to get the mouse coordinates in dw values, with mx being the mouses x position, and my being the mouses y position, is there any way to do that in the kernel?

I have tried other stuff but it seems to not work and will just show nothing, but will build without errors.

boot.asm:

bits 16

jmp short bootloader_start
nop

OEMLabel db "OS"
BytesPerSector dw 512
SectorsPerCluster db 1
ReservedForBoot dw 1
NumberOfFats db 2
RootDirEntries dw 224
                    
LogicalSectors dw 2880
MediumByte db 0f0h
SectorsPerFat dw 9
SectorsPerTrack dw 18
Sides dw 2
HiddenSectors dd 0
LargeSectors dd 0
DriveNo dw 0
Signature db 41
VolumeID dd 00000000h
VolumeLabel db "           "
FileSystem db "FAT12   "

bootloader_start:
    mov ax, 07c0h
    add ax, 544
    cli
    mov ss, ax
    mov sp, 4096
    sti

    mov ax, 07c0h
    mov ds, ax
    cmp dl, 0
    je no_change
    mov [bootdev], dl
    mov ah, 8
    int 13h
    jc fatal_disk_error
    and cx, 3fh
    mov [SectorsPerTrack], cx
    movzx dx, dh
    add dx, 1
    mov [Sides], dx

no_change:
    mov eax, 0

floppy_ok:          
    mov ax, 19
    call l2hts

    mov si, buffer
    mov bx, ds
    mov es, bx
    mov bx, si

    mov ah, 2
    mov al, 14

    pusha

read_root_dir:
    popa
    pusha

    stc
    int 13h

    jnc search_dir
    call reset_floppy
    jnc read_root_dir

    jmp reboot

search_dir:
    popa

    mov ax, ds
    mov es, ax
    mov di, buffer

    mov cx, word [RootDirEntries]
    mov ax, 0

next_root_entry:
    xchg cx, dx

    mov si, kern_filename
    mov cx, 11
    rep cmpsb
    je found_file_to_load

    add ax, 32

    mov di, buffer
    add di, ax

    xchg dx, cx
    loop next_root_entry

    mov si, file_not_found
    call print_string
    jmp reboot

found_file_to_load:
    mov ax, word [es : di + 0fh]
    mov word [cluster], ax

    mov ax, 1
    call l2hts

    mov di, buffer
    mov bx, di

    mov ah, 2
    mov al, 9

    pusha

read_fat:
    popa
    pusha

    stc
    int 13h

    jnc read_fat_ok
    call reset_floppy
    jnc read_fat

fatal_disk_error:
    mov si, disk_error
    call print_string
    jmp reboot

read_fat_ok:
    popa

    mov ax, 2000h
    mov es, ax
    mov bx, 0

    mov ah, 2
    mov al, 1

    push ax

load_file_sector:
    mov ax, word [cluster]
    add ax, 31

    call l2hts

    mov ax, 2000h
    mov es, ax
    mov bx, word [pointer]

    pop ax
    push ax

    stc
    int 13h

    jnc calculate_next_cluster

    call reset_floppy
    jmp load_file_sector

calculate_next_cluster:
    mov ax, [cluster]
    mov dx, 0
    mov bx, 3
    mul bx
    mov bx, 2
    div bx
    mov si, buffer
    add si, ax
    mov ax, word [ds:si]

    or dx, dx

    jz even

odd:
    shr ax, 4
    jmp short next_cluster_cont

even:
    and ax, 0fffh

next_cluster_cont:
    mov word [cluster], ax

    cmp ax, 0ff8h
    jae end

    add word [pointer], 512
    jmp load_file_sector

end:
    pop ax
    mov dl, byte [bootdev]

    jmp 2000h:0000h

reboot:
    mov ax, 0
    int 16h
    mov ax, 0
    int 19h

print_string:
    pusha
    mov ah, 0eh

.repeat:
    lodsb
    cmp al, 0
    je .done
    int 10h
    jmp short .repeat

.done:
    popa
    ret

reset_floppy:
    push ax
    push dx
    mov ax, 0
    mov dl, byte [bootdev]
    stc
    int 13h
    pop dx
    pop ax
    ret

l2hts:
    push bx
    push ax

    mov bx, ax

    mov dx, 0
    div word [SectorsPerTrack]
    add dl, 01h
    mov cl, dl
    mov ax, bx

    mov dx, 0
    div word [SectorsPerTrack]
    mov dx, 0
    div word [Sides]
    mov dh, dl
    mov ch, al

    pop ax
    pop bx

    mov dl, byte [bootdev]

    ret

kern_filename   db "KERNEL  BIN"

disk_error  db "Floppy error! Press any key...", 0
file_not_found  db "KERNEL.BIN not found!", 0

bootdev db 0
cluster dw 0
pointer dw 0

times 510-($-$$) db 0
dw 0aa55h

buffer:

kernel.asm: (Hello World)

bits 16
[org 0]

mov ax, cs
mov ds, ax
mov es, ax
mov ax, 0x7000
mov ss, ax
mov sp, ss

start:
    pusha
    mov ah, 00h
    mov al, 03h
    int 10h
    popa
    mov si, msg
    call print_string
    jmp $

print_string:
    pusha
    mov ah, 0eh
.repeat:
    lodsb
    cmp al, 0
    je .done
    int 10h
    jmp short .repeat
.done:
    popa
    ret

msg db 'Hello World!', 0

ret
Peter Cordes
  • 286,368
  • 41
  • 520
  • 731
804k
  • 1
  • 2
  • 1
    Unclear how the existing boot loader is relevant to the question. There's no attempt to access the mouse in the code you posted. BIOS support for the PS/2 mouse is at [interrupt 15h, AH=C2](http://www.ctyme.com/intr/rb-1596.htm). – Raymond Chen Mar 29 '22 at 22:38

0 Answers0