StarAlchemist

mousecoord

Oct 2nd, 2024
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Z80 Assembler 2.17 KB | Source Code | 0 0
  1. .model small
  2. .stack 100h
  3. .data
  4. mouseX dw 0        ; Mouse X coordinate
  5. mouseY dw 0        ; Mouse Y coordinate
  6. num_text db 5 dup('0'),10,13, '$'
  7. number_size db 0
  8.  
  9. .code
  10.  
  11. IMPRIMIR MACRO text
  12.    lea dx, text
  13.    mov ah, 09h
  14.    int 21h          
  15. ENDM
  16.  
  17. posicion macro x, y
  18.     mov ah, 02H
  19.     mov bh, 00h
  20.     mov dl, x
  21.     mov dh, y
  22.     int 10H
  23. endm
  24.  
  25. JMP_NOT_CLICKED MACRO not_clicked
  26.     mov ax, 3
  27.     int 33h
  28.     test bx, 1
  29.     jz not_clicked
  30. endm
  31.  
  32. main proc
  33.     mov ax,@data
  34.     mov ds, ax
  35.     ;set video mode (320x200, 256 colors)
  36.     mov ax, 13h
  37.     int 10h
  38.     call init_mouse
  39.     coord_loop:
  40.         JMP_NOT_CLICKED not_mouse
  41.         call get_mouse_pos
  42.         not_mouse:
  43.         call PrintMousePos
  44.         jmp coord_loop
  45. ret
  46. main endp
  47.  
  48. init_mouse proc
  49.     mov ax,0
  50.     int 33h
  51.     mov ax,1
  52.     int 33h
  53. ret
  54. init_mouse endp
  55.  
  56. get_mouse_pos proc
  57.     mov ax,3
  58.     int 33h
  59.     shr cx, 1
  60.     mov [mouseX], cx
  61.     mov [mouseY], dx
  62. ret
  63. get_mouse_pos endp
  64.  
  65. ;------IMPRIMIR------
  66. PrintMousePos proc
  67.     posicion 0, 0
  68.     mov ax,mouseX
  69.     mov number_size,3
  70.     call NumberToString
  71.     IMPRIMIR num_text
  72.     mov ax,mouseY
  73.     call NumberToString
  74.     IMPRIMIR num_text
  75. ret
  76. PrintMousePos endp
  77.  
  78. NumberToString proc
  79.     push cx
  80.     xor cx,cx           ;How many numbers have been written
  81.     lea di, num_text      
  82.     cmp ax, 0           ; Check if AX is 0
  83.     je zeroNumber
  84.     mov bx, 10          ; BX = 10 for division        
  85. divideLoop:
  86.     xor dx, dx          ; Clear DX for division
  87.     div bx              ; AX / 10, quotient in AL, remainder in DX
  88.     add dl, '0'         ; ASCII
  89.     push dx ; Remainder
  90.     inc cx
  91.     test ax, ax        ; Check if quotient is zero
  92.     jnz divideLoop
  93.  
  94. reverseDigits:
  95.     pop dx              ; Pop a digit from stack
  96.     mov [di], dl        ; Store the digit
  97.     inc di              ; Move to next position in buffer
  98.     loop reverseDigits
  99.     jmp checkPadding
  100. zeroNumber:
  101. mov [di],'0'
  102. inc di
  103. checkPadding:
  104.     mov ax,di
  105.     sub ax, offset num_text
  106.  
  107.     cmp al, number_size
  108.     jge setTerminator
  109.     mov byte ptr [di], '_'  ; Add a space for padding
  110.     inc di
  111.     dec bx
  112.     jmp checkPadding
  113.  
  114. setTerminator:
  115.     mov [di], 10
  116.     mov [di+1],13
  117.     mov [di+2], '$'
  118.     pop cx
  119.     ret
  120. NumberToString endp
  121.  
  122.  
  123. end
Tags: assembly
Advertisement
Add Comment
Please, Sign In to add comment