-
Notifications
You must be signed in to change notification settings - Fork 0
/
Asm.S
232 lines (215 loc) · 5.03 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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/** ADAMEm: Coleco ADAM emulator ********************************************/
/** **/
/** Asm.S **/
/** **/
/** This file contains miscellaneous MS-DOS assembly routines **/
/** **/
/** Copyright (C) Marcel de Kogel 1996,1997,1998 **/
/** 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
TimerCount: .long 0
OldInt8: .long 0
OldInt8Selector:.word 0
.globl _cs_alias
.globl _DosSelector
.globl _DisplayBuf
.globl _videomode
.text
.globl _nofunc
_nofunc:
ret
.globl ___enable
___enable:
sti
ret
.globl ___disable
___disable:
cli
ret
#ifndef DEMO
.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
#endif
.globl _PutImage_Asm
_PutImage_Asm:
pushal
pushw %es
cld
movl $_DisplayBuf,%esi
movw _DosSelector,%es
cmpl $0,_videomode
je _PutImage_320x200
movl $0xA0000,%edi
cmp $1,_videomode
je _PutImage_256x192
movl $0xA1800,%edi
_PutImage_256x192:
movl $12288,%ecx
rep
movsl
jmp _PutImage_done
_PutImage_320x200:
movl $0xA0520,%edi
movl $192,%edx
movl $64,%ebx
_PutImage_320x200_Loop:
movl %ebx,%ecx
rep
movsl
addl %ebx,%edi
decl %edx
jnz _PutImage_320x200_Loop
_PutImage_done:
popw %es
popal
ret
TimerInterrupt:
pushw %ds
pushl %eax
.byte 0x2e
movw _cs_alias,%ax
movw %ax,%ds
incl TimerCount
popl %eax
popw %ds
.byte 0x2e
ljmp *(OldInt8)
InstallTimerInt:
pushal
movl $0x204,%eax
movb $8,%bl
int $0x31
movl %edx,OldInt8
movw %cx,OldInt8Selector
movw %cs,%cx
leal TimerInterrupt,%edx
movb $8,%bl
movl $0x205,%eax
int $0x31
popal
ret
RestoreTimerInt:
pushal
movl OldInt8,%edx
movw OldInt8Selector,%cx
movb $8,%bl
movl $0x205,%eax
int $0x31
popal
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
.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 InstallTimerInt
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 RestoreTimerInt
popl %eax
ret