-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiss_hard.pas
244 lines (190 loc) · 5.59 KB
/
iss_hard.pas
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
233
234
235
236
237
238
239
240
241
242
243
244
{
Copyright (c) 1998-2001,2014 Karoly Balogh <[email protected]>
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
}
{ * ISS_HARD.PAS - Routines for IRQ and DMA and other system hardware }
{ OS - GO32V2 only. }
{$INCLUDE ISS_SET.INC}
{$ASMMODE INTEL}
{$MODE FPC}
Unit ISS_Hard;
Interface
Uses ISS_Var, { * Uses the system variables and types * }
GO32; { * Uses GO32 unit, because DOS-only driver * }
Const ISS_IRQMapping : Array[$00..$0F] Of Byte =(
$08,$09,$0A,$0B,$0C,$0D,$0E,$0F, { * 1st controller * }
$70,$71,$72,$73,$74,$75,$76,$77); { * 2nd controller * }
ISS_DMARead = %00000100;
ISS_DMAWrite = %00001000;
ISS_DMAAutoInit = %00010000;
ISS_DMAModeDemand = %00000000;
ISS_DMAModeSingle = %01000000;
Var ISS_DMASegment : Word; { * DMA Buffer Segment Address * }
ISS_DMAAddress : Pointer; { * DMA Buffer Pascal Pointer * }
ISS_DMASelector : Word; { * DMA Buffer Selector * }
Procedure ISS_IRQEnable(IRQNum : Byte);
Procedure ISS_IRQDisable(IRQNum : Byte);
Procedure ISS_DMAAllocBuffer;
Procedure ISS_DMAFreeBuffer;
Procedure ISS_DMAStart(DMAChannel : DWord; Address: Pointer;
BlockLength,Mode : DWord);
Procedure ISS_DMAStop(DMAChan : DWord);
Implementation
Const DMACPage : Array[0..7] Of Byte = ($087,$083,$081,$082,$08F,$08B,$089,$08A);
DMACOffset : Array[0..7] Of Byte = ($000,$002,$004,$006,$0C0,$0C4,$0C8,$0CC);
DMACLength : Array[0..7] Of Byte = ($001,$003,$005,$007,$0C2,$0C6,$0CA,$0CE);
DMACMask : Array[0..7] Of Byte = ($00A,$00A,$00A,$00A,$0D4,$0D4,$0D4,$0D4);
DMACMode : Array[0..7] Of Byte = ($00B,$00B,$00B,$00B,$0D6,$0D6,$0D6,$0D6);
DMACClear : Array[0..7] Of Byte = ($00C,$00C,$00C,$00C,$0D8,$0D8,$0D8,$0D8);
{ * Enables the specified IRQ * }
Procedure ISS_IRQEnable(IRQNum : Byte); Assembler;
Asm
MOV CL,IRQNum
MOV BX,Not 1
ROL BX,CL
CMP CL,7
JA @EnableOnPic2
{ * Specified IRQ is on controller 1 * }
IN AL,$21
AND AL,BL
OUT $21,AL
JMP @Exit
@EnableOnPIC2:
{ * Specified IRQ is on controller 2 * }
IN AL,$0A1
AND AL,BH
OUT $0A1,AL
IN AL,$21
AND AL,11111011B { * Enable IRQ 2 cascade * }
OUT $21,AL
@Exit:
End ['EAX','EBX','ECX'];
{ * Disables the specified IRQ * }
Procedure ISS_IRQDisable(IRQNum : Byte); Assembler;
Asm
MOV CL,IRQNum
MOV BX,1
SHL BX,CL
CMP CL,7
JA @DisableOnPIC2
{ * Specified IRQ is on controller 1 * }
IN AL,$21
OR AL,BL
OUT $21,AL
JMP @Exit
@DisableOnPIC2:
{ * Specified IRQ is on controller 2 * }
IN AL,$0A1
OR AL,BH
OUT $0A1,AL
@Exit:
End ['EAX','EBX','ECX'];
{ * Allocates the DMA Buffer * }
Procedure ISS_DMAAllocBuffer;
Var Linear : DWord;
Begin
{ * We allocate 32kb for DMA buffer, but we using only 16kb of it. * }
{ * One 16kb piece of DMA buffer will not cross DMA Page for sure. * }
{ * Yepp, this hacking another good example to show, how "good" * }
{ * the PC architecture is... * }
Linear:=Global_DOS_Alloc(32768);
ISS_DMASegment :=Linear Shr 16; { * High Word is Segment Address * }
ISS_DMAAddress :=Pointer((Linear And $FFFF0000) Shr 12);
ISS_DMASelector:=Linear And $FFFF; { * Low Word is Selector * }
{ * Clearing DMA buffer * }
Asm
MOV EDI,ISS_DMAAddress
MOV ECX,32768/4
XOR EAX,EAX
@ClearLoop:
MOV FS:[EDI],EAX
ADD EDI,4
LOOP @ClearLoop
End ['EAX','ECX','EDI'];
{ * Checking DMA Page Limit * }
If (((DWord(ISS_DMAAddress) And $0FFFF)+16384)>$10000) Then Begin
Inc(DWord(ISS_DMAAddress),16384);
End;
End;
{ * Free up the DMA Buffer * }
Procedure ISS_DMAFreeBuffer;
Begin
Unlock_Linear_Region(DWord(ISS_DMAAddress)+
Get_Segment_Base_Address(DosMemSelector),32768);
Global_DOS_Free(ISS_DMASelector);
ISS_DMASelector:=0;
ISS_DMASegment:=0;
End;
{ * This routine is by Aleksey V. Vaneev, from his FPSound API. * }
Procedure ISS_DMAStart(DMAChannel : DWord; Address: Pointer;
BlockLength,Mode : DWord); Assembler;
Asm
CMP [DMAChannel],7
JA @Done
AND [Mode],$0FC
MOV EAX,4
MOV ESI,[DMAChannel]
ADD EAX,ESI
CMP ESI,4
JB @LowDMA1
SHR [BlockLength],1
SHR [Address],1
SHL WORD PTR [Address+2],1
SUB EAX,4
@LowDMA1:
CMP [BlockLength],0
JE @Done
XOR EDX,EDX
MOV DL,[DMACMask+ESI]
OUT DX,AL
MOV DL,[DMACClear+ESI]
OUT DX,AL
MOV EAX,[Mode]
ADD EAX,ESI
CMP ESI,4
JB @LowDMA2
SUB EAX,4
@LowDMA2:
MOV DL,[DMACMode+ESI]
OUT DX,AL
MOV AL,BYTE PTR [Address+2]
MOV DL,[DMACPage+ESI]
OUT DX,AL
MOV AX,WORD PTR [Address]
MOV DL,[DMACOffset + esi]
OUT DX,AL
MOV AL,AH
OUT DX,AL
MOV DL,[DMACLength + esi]
MOV EAX, [BlockLength]
DEC EAX
OUT DX,AL
MOV AL,AH
OUT DX,AL
MOV EAX,ESI
CMP EAX,4
JB @LowDMA3
SUB EAX,4
@LowDMA3:
MOV DL,[DMACMask+ESI]
OUT DX,AL
@Done:
End ['EAX', 'EDX', 'ESI'];
Procedure ISS_DMAStop(DMAChan : DWord);
Begin
DMAChan:=DMAChan And 7;
OutPortB(DMACClear[DMAChan],0);
OutPortB(DMACMask[DMAChan],DMAChan Or 4);
End;
Begin
End.