summaryrefslogtreecommitdiff
path: root/src/heretic/i_ibm_a.asm
blob: 06e5a9dff02f91b2e88b39e255826633743745c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
	.386
	.MODEL  small

.DATA



.CODE

IF 0
#define PEL_WRITE_ADR   0x3c8
#define PEL_READ_ADR    0x3c7
#define PEL_DATA                0x3c9
ENDIF

;================
;
; I_DivException
;
;================

PROC  	I_DivException_
PUBLIC 	I_DivException_
	mov	edx,03c9h
	mov	al,63
	out	dx,al

	mov	ebx,0ffffffh
	mov	eax,[ebx]
	retf
ENDP

;================
;
; I_SetDivException
;
;================

PROC  	I_SetDivException_
PUBLIC 	I_SetDivException_
	pusha

	mov	eax,0212h
	mov	ebx,0
	mov	ecx,cs
	mov	edx,OFFSET I_DivException_
	int 31h
	jnc	good

	popa
	mov	eax,0
	ret

good:
	popa
	mov	eax,1
	ret

ENDP


;================
;
; I_ReadJoystick
;
; Read the absolute joystick values
; returns false if not connected
;================

.data

_joystickx	dd	0
_joysticky	dd	0
PUBLIC	_joystickx, _joysticky

.code

PROC  	I_ReadJoystick_
PUBLIC 	I_ReadJoystick_
	pusha
	pushf					; state of interrupt flag
	cli

	mov		dx,0201h
	in		al,dx
	out		dx,al		; Clear the resistors

	mov		ah,1		; Get masks into registers
	mov		ch,2

	xor		esi,esi		; Clear count registers
	xor		edi,edi
	xor		ebx,ebx		; Clear high byte of bx for later

	mov		ebp,10000	; joystick is disconnected if value is this big

jloop:
	in		al,dx		; Get bits indicating whether all are finished

	dec		ebp			; Check bounding register
	jz		bad			; We have a silly value - abort

	mov		bl,al		; Duplicate the bits
	and		bl,ah		; Mask off useless bits (in [xb])
	add		esi,ebx		; Possibly increment count register
	mov		cl,bl		; Save for testing later

	mov		bl,al
	and		bl,ch		; [yb]
	add		edi,ebx

	add		cl,bl
	jnz		jloop 		; If both bits were 0, drop out

done:
	mov		[_joystickx],esi
	shr		edi,1		; because 2s were added
	mov		[_joysticky],edi

	popf			; restore interrupt flag
	popa
	mov	eax,1		; read was ok
	ret

bad:
	popf			; restore interrupt flag
	popa
	xor     eax, eax	; read was bad
	ret

ENDP


END