forked from CodeAsm/M2000
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAsm.S
194 lines (180 loc) · 4.25 KB
/
Asm.S
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*** M2000: Portable P2000 emulator *****************************************/
/*** ***/
/*** Asm.S ***/
/*** ***/
/*** This file contains MS-DOS specific assembler routines ***/
/*** ***/
/*** Copyright (C) Marcel de Kogel 1996,1997 ***/
/*** You are not allowed to distribute this software commercially ***/
/*** Please, notify me, if you make any changes to this file ***/
/****************************************************************************/
.file "Asm.S"
.data
.align 4
DisplayStart: .long 0xA0000
TimerCount: .long 0
OldInt8: .long 0
OldInt8Selector:.word 0
.globl _DosSelector
.globl _cs_alias
.text
.globl _nofunc
_nofunc:
ret
.globl ___enable
___enable:
sti
ret
.globl ___disable
___disable:
cli
ret
.globl _JoyGetPos
_JoyGetPos:
pushl %ebx
pushl %ecx
pushl %edx
pushl %esi
pushl %edi
movw $0x201,%dx
movl $10000,%ecx
subl %esi,%esi
subl %edi,%edi
cli
outb %al,%dx
jmp _JoyGetPos_Loop
_JoyGetPos_Loop:
inb %dx,%al
movl %eax,%ebx
shrl $1,%ebx
adcl $0,%esi
shrl $1,%ebx
adcl $0,%edi
testb $3,%al
loopnz _JoyGetPos_Loop
sti
movl %edi,%eax
shll $16,%eax
movw %si,%ax
popl %edi
popl %esi
popl %edx
popl %ecx
popl %ebx
ret
.globl _ReadTimer
_ReadTimer:
pushl %edi
pushl %esi
pushl %edx
pushl %ecx
pushl %ebx
movl $50,%ecx
ReadTimer_Loop:
call _nofunc
loop ReadTimer_Loop
ReadTimer_Again:
movl (TimerCount),%eax
shll $16,%eax
outb %al,$0x43
jmp ReadTim1
ReadTim1:
jmp ReadTim2
ReadTim2:
inb $0x40,%al
jmp ReadTim3
ReadTim3:
jmp ReadTim4
ReadTim4:
movb %al,%ah
inb $0x40,%al
xchgb %al,%ah
notw %ax
movl (TimerCount),%ebx
shll $16,%ebx
movw %ax,%bx
cmpl %eax,%ebx
jne ReadTimer_Again
popl %ebx
popl %ecx
popl %edx
popl %esi
popl %edi
ret
timer_interrupt:
pushl %eax
pushw %ds
.byte 0x2e
movw _cs_alias,%ax
movw %ax,%ds
incl (TimerCount)
pushfl
lcall (OldInt8)
popw %ds
popl %eax
iret
install_timer_int:
pushal
movl $0x204,%eax
movb $8,%bl
int $0x31
movl %edx,OldInt8
movw %cx,OldInt8Selector
movw %cs,%cx
leal timer_interrupt,%edx
movb $8,%bl
movl $0x205,%eax
int $0x31
popal
ret
restore_timer_int:
pushal
movl OldInt8,%edx
movw OldInt8Selector,%cx
movb $8,%bl
movl $0x205,%eax
int $0x31
popal
ret
.globl _StartTimer
_StartTimer:
pushl %eax
cli
movb $0x34,%al
outb %al,$0x43
jmp StartTim1
StartTim1:
jmp StartTim2
StartTim2:
subb %al,%al
outb %al,$0x40
jmp StartTim3
StartTim3:
jmp StartTim4
StartTim4:
outb %al,$0x40
sti
call install_timer_int
popl %eax
ret
.globl _RestoreTimer
_RestoreTimer:
pushl %eax
cli
movb $0x36,%al
outb %al,$0x43
jmp ResTim1
ResTim1:
jmp ResTim2
ResTim2:
subb %al,%al
outb %al,$0x40
jmp ResTim3
ResTim3:
jmp ResTim4
ResTim4:
outb %al,$0x40
sti
call restore_timer_int
popl %eax
ret