I_IBM_A.ASM 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. .386
  2. .MODEL small
  3. .DATA
  4. .CODE
  5. IF 0
  6. #define PEL_WRITE_ADR 0x3c8
  7. #define PEL_READ_ADR 0x3c7
  8. #define PEL_DATA 0x3c9
  9. ENDIF
  10. ;================
  11. ;
  12. ; I_DivException
  13. ;
  14. ;================
  15. PROC I_DivException_
  16. PUBLIC I_DivException_
  17. mov edx,03c9h
  18. mov al,63
  19. out dx,al
  20. mov ebx,0ffffffh
  21. mov eax,[ebx]
  22. retf
  23. ENDP
  24. ;================
  25. ;
  26. ; I_SetDivException
  27. ;
  28. ;================
  29. PROC I_SetDivException_
  30. PUBLIC I_SetDivException_
  31. pusha
  32. mov eax,0212h
  33. mov ebx,0
  34. mov ecx,cs
  35. mov edx,OFFSET I_DivException_
  36. int 31h
  37. jnc good
  38. popa
  39. mov eax,0
  40. ret
  41. good:
  42. popa
  43. mov eax,1
  44. ret
  45. ENDP
  46. ;================
  47. ;
  48. ; I_ReadJoystick
  49. ;
  50. ; Read the absolute joystick values
  51. ; returns false if not connected
  52. ;================
  53. .data
  54. _joystickx dd 0
  55. _joysticky dd 0
  56. PUBLIC _joystickx, _joysticky
  57. .code
  58. PROC I_ReadJoystick_
  59. PUBLIC I_ReadJoystick_
  60. pushad
  61. pushf ; state of interrupt flag
  62. cli
  63. mov dx,0201h
  64. in al,dx
  65. out dx,al ; Clear the resistors
  66. mov ah,1 ; Get masks into registers
  67. mov ch,2
  68. xor esi,esi ; Clear count registers
  69. xor edi,edi
  70. xor ebx,ebx ; Clear high byte of bx for later
  71. mov ebp,10000 ; joystick is disconnected if value is this big
  72. jloop:
  73. in al,dx ; Get bits indicating whether all are finished
  74. dec ebp ; Check bounding register
  75. jz bad ; We have a silly value - abort
  76. mov bl,al ; Duplicate the bits
  77. and bl,ah ; Mask off useless bits (in [xb])
  78. add esi,ebx ; Possibly increment count register
  79. mov cl,bl ; Save for testing later
  80. mov bl,al
  81. and bl,ch ; [yb]
  82. add edi,ebx
  83. add cl,bl
  84. jnz jloop ; If both bits were 0, drop out
  85. done:
  86. mov [_joystickx],esi
  87. shr edi,1 ; because 2s were added
  88. mov [_joysticky],edi
  89. popf ; restore interrupt flag
  90. popad
  91. mov eax,1 ; read was ok
  92. ret
  93. bad:
  94. popf ; restore interrupt flag
  95. popad
  96. xor eax, eax ; read was bad
  97. ret
  98. ENDP
  99. END