Raw File
1 ; _____________________________________________
2 ; | |
3 ; | Project: APPLER |
4 ; | File: GLOBALS.ASM |
5 ; | Compiler: 16-bit TASM (2.5) |
6 ; | |
7 ; | Subject: Common Definitions & Macros |
8 ; | |
9 ; | Author: Alexander Patalenski |
10 ; |_____________________________________________|
11
12 .386
13
14 ;============== Constants ======================================================
15
16 WriteOFS = 99h ;98h ; Write Memory offset
17 StackPage = 1 ; Apple Stack page number
18 GRchar = 'ß' ; Character used in GR Mode
19 LNdelimiter = 'ú' ; License Name Delimiter (#250)
20 Tlen = 16 ; Max counters number
21 IRQmasks = 10011100b ; IRQ Interrupts activity (1-disabled)
22 MotorOffDelay = 2 * 18 ; Floppy Drive stop delay
23
24 RESETvector = 0FFFCh ; 65C02
25 ABORTvector = 0FFF8h ; exception
26 NMIvector = 0FFFAh ; interrupt
27 IRQvector = 0FFFEh ; vectors
28 BRKvector = 0FFFEh ;
29
30 ReadAdd = 0
31 WriteAdd = 0
32 DataSearchLen = 22 ; Max distance b/address&data fields
33 TrackBufferLen = 186Ah ; Number of Bytes on disk
34 TrackBuffer2Len = DataSearchLen+31+156h ; Max Sector length
35 FormatLimit = 156h+20
36 ; .DSK type only:
37 Gap1 = 07FFFh ; From begining to first sector
38 Gap2 = 0FFFFh ; B/ address and data fields
39 Gap3 = 07FFFh ; B/ two sectors
40 Gap1Len = 0Bh
41 Gap2Len = 04h
42 Gap3Len = 0Bh
43
44 ;-------------- Process IDs ----------------------------------------------------
45 PID_EMULATOR = 000h
46 PID_DEBUGGER = 001h
47 PID_FILE_MANAGER = 002h
48 PID_FLOPPY_DISK_MANAGER = 003h
49 PID_KEYBOARD_SETUP = 004h
50 PID_ABOUT_SCREEN = 005h
51 PID_HELP_SCREEN = 006h
52 PID_DOS_SHELL = 007h
53 PID_QUIT_APPLER = 008h
54 PID_PREVIOUS_PROCESS = 0FEh
55 PID_DONT_SWITCH = 0FFh
56
57 ;-------------- Keyboard Status Bits -------------------------------------------
58 M_CTRL = 00000001b
59 M_LEFT_SHIFT = 00000010b
60 M_RIGHT_SHIFT = 00000100b
61 M_ALT = 00001000b
62 M_NUM_LOCK = 00100000b
63 M_CAPS_LOCK = 01000000b
64
65 ;============== Macroses =======================================================
66
67 Save MACRO a,b,c,d,e,f,g,h,i,j,k
68 IRP r,<a,b,c,d,e,f,g,h,i,j,k>
69 IFNB <r>
70 push r
71 ENDIF
72 ENDM
73 ENDM
74
75 Restore MACRO a,b,c,d,e,f,g,h,i,j,k
76 IRP r,<k,j,i,h,g,f,e,d,c,b,a>
77 IFNB <r>
78 pop r
79 ENDIF
80 ENDM
81 ENDM
82
83 SaveAll MACRO
84 push ax bx cx dx si di bp ds es
85 ENDM
86
87 RestoreAll MACRO
88 pop es ds bp di si dx cx bx ax
89 ENDM
90
91 FastStos MACRO Count ; AL - byte to stos
92 Local L1 ; CX|Count - count in bytes
93 mov ah,al
94 IFNB <Count>
95 mov cx,(Count)/2
96 rep stosw
97 IF (Count) mod 2
98 stosb
99 ENDIF
100 ELSE
101 shr cx,1
102 rep stosw
103 jnc L1
104 stosb
105 L1:
106 ENDIF
107 ENDM
108
109 FastMovs MACRO Count ; CX|Count - count in bytes
110 Local L1
111 IFNB <Count>
112 mov cx,(Count)/2
113 rep movsw
114 IF (Count) mod 2
115 movsb
116 ENDIF
117 ELSE
118 shr cx,1
119 rep movsw
120 jnc L1
121 movsb
122 L1:
123 ENDIF
124 ENDM
125
126 SmartStos MACRO Dest,Count ; AL - byte to stos
127 Local L1,L2 ; DI|Dest - destination address
128 mov ah,al ; CX|Count - count in bytes
129 IFNB <Dest>
130 mov di,offset Dest
131 IFNB <Count>
132 Temp = Count
133 IF (offset Dest) mod 2
134 stosb
135 Temp = Temp-1
136 ENDIF
137 mov cx,Temp/2
138 rep stosw
139 IF Temp mod 2
140 stosb
141 ENDIF
142 ELSE
143 IF (offset Dest) mod 2
144 stosb
145 dec cx
146 ENDIF
147 shr cx,1
148 rep stosw
149 jnc L2
150 stosb
151 L2:
152 ENDIF
153 ELSE
154 IFNB <Count>
155 mov cx,Count
156 ENDIF
157 test di,1b
158 jz L1
159 stosb
160 dec cx
161 L1: shr cx,1
162 rep stosw
163 jnc L2
164 stosb
165 L2:
166 ENDIF
167 ENDM
168
169 Print MACRO a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q
170 %OUT a&b&c&d&e&f&g&h&i&j&k&l&m&n&o&p&q
171 ENDM
172
173 ;-------------- Specific use definitions ---------------------------------------
174
175 If_this_is_file MACRO FileName
176 IRP ThisFile,%@FileName
177 IFIDNI <ThisFile>,<FileName>
178 ENDM
179 ENDM
180
181 db_LICENSE_NAME MACRO
182 IFDEF LICENSE_NAME
183 IRP s,%LICENSE_NAME
184 IRPC c,<s>
185 IF "&c" NE LNdelimiter
186 db "&c"
187 ELSE
188 db " "
189 ENDIF
190 ENDM
191 ENDM
192 ELSE
193 db 'SHAREWARE'
194 ENDIF
195 ENDM
196
197
198 Opcode MACRO Code
199 org Code*100h
200 EndAddress = $+WriteOFS-1
201 IRP n,<% Code>
202 ValidOpcode&&n equ 1
203 ENDM
204 ENDM
205
206 WriteAllFreeSpace MACRO
207 IFDEF Update
208 IF1
209 Temp = 0
210 FreeSpacePtr = 0
211 REPT 100h
212 IRP n,<%Temp>
213 IFNDEF ValidOpcode&&&n
214 ENDM
215 Print <FreeSpace>,%FreeSpacePtr,< = >,%Temp
216 FreeSpacePtr = FreeSpacePtr+1
217 ENDIF
218 Temp = Temp+1
219 ENDM
220 Print <FreeSpaceCount>,< = >,%FreeSpacePtr
221 Print < IF 0 >
222 ENDIF
223 ENDIF
224 ENDM
225
226 ReadAllFreeSpace MACRO
227 include 65C02.INC
228 ENDIF
229 ENDM
230
231 FreeSpacePtr = 0
232
233 UseNextFreeSpace MACRO
234 IF FreeSpacePtr LT FreeSpaceCount
235 IRP n,<%FreeSpacePtr>
236 org FreeSpace&&n*100h + 3
237 EndAddress = $-3+WriteOFS-1
238 ENDM
239 FreeSpacePtr = FreeSpacePtr + 1
240 ELSE
241 ERR
242 Print < Not enough free space!!>
243 ENDIF
244 ENDM
245
246 WriteMem MACRO Page
247 org Page*100h+WriteOFS
248 EndAddress = $-WriteOFS+0FFh
249 ENDM
250
251 CheckAddress MACRO Lab
252 Len = EndAddress-($-1)
253 IF Len LT 0
254 ERR
255 ENDIF
256 IFNB <Lab>
257 IF Len LT 0
258 Print < >,<Lab>,<: >,<Fragment is >,%0-Len,< bytes bigger.>
259 ELSE
260 Print < >,<Lab>,<: >,%Len,< bytes left.>
261 ENDIF
262 ENDIF
263 ENDM
264
265 AddTiming MACRO ms
266 lea eax,[eax+10000h*ms]
267 ENDM
268
269 DoNext MACRO
270 lodsb
271 mov bh,al
272 jmp bx
273 ENDM
274
275 GoWrite MACRO
276 mov al,WriteOFS
277 jmp ax
278 ENDM
279
280 SwitchToProcess macro ProcessID
281 mov al,ProcessID
282 call TaskSwitch
283 endm
284
285 ;-------------- Floppy emulation interface -------------------------------------
286
287 Drive_S Struc
288 ID db ? ; 0 or 1
289 Phase db 00000000b ; 0D0C0B0A - Phase A..D
290 PhasePTR db 0 ; ex. ^----- Half-step phase ptr
291 StepCounter db 0 ; Half-step counter
292 Track db 0 ; Double-step Track Number
293 ; Disk attributes:
294 FileHandle dw 0FFFFh ; 0FFFFh if no disk in the drive
295 WriteProtect db 0 ; 0FFh-protected, 0-not
296 DiskType db 0 ; 0 - .NBL, 1 - .DSK
297 Volume db 0FEh ; .DSK: Disk Volume
298 Drive_S Ends
299
300 SectorImage_S Struc
301 AddressProlog db 0D5h,0AAh,096h ; Address Field Prolog
302 AddressCheckSum db 000h ; Address Field CheckSum
303 AddressEpilog db 0DEh,0AAh,0EBh ; Address Field Epilog
304 DataProlog db 0D5h,0AAh,0ADh ; Data Field Prolog
305 DataCheckSum db 000h ; Data Field CheckSum
306 DataEpilog db 0DEh,0AAh,0EBh ; Data Field Epilog
307 EndByte db 0FFh ; End Of Sector byte
308 SectorImage_S Ends
309
310 SectorImageF_S Struc
311 AddressProlog db 0FFh,0FFh,0FFh ; Sector Image compare flags
312 AddressCheckSum db 0FFh ;
313 AddressEpilog db 0FFh,0FFh,000h ; 0 - ignore, 0FFh - compare
314 DataProlog db 0FFh,0FFh,0FFh ;
315 DataCheckSum db 0FFh ;
316 DataEpilog db 0FFh,0FFh,000h ;
317 EndByte db 000h ;
318 SectorImageF_S Ends
319
320 ;------ Error Codes:
321 ; ; AL: DL:
322 e_BadAdrCheckSum = 0 ; Yes No ; Bad Address Field Checksum
323 e_BadAdrEpilog = 1 ; No Yes ; Bad Address Field Epilog
324 e_BadTrackNumber = 2 ; Yes Yes ; Track Number mismatch
325 e_BadSectorNumber = 3 ; Yes No ; Not [0..F] Sector Number
326 e_MissingDataField = 4 ; No Yes ; Data Field not found
327 e_DuplicateSector = 5 ; Yes Yes ; Sector found again
328 e_BadDataCheckSum = 6 ; Yes Yes ; Bad Data Field Checksum
329 e_BadDataImage = 7 ; No Yes ; Not 6&2 coded byte found
330 e_BadDataEpilog = 8 ; No Yes ; Bad Data Field Epilog
331 e_BadEndByte = 9 ; Yes Yes ; Bad End Byte
332 e_MissingSector = 10 ; Yes No ; Sector not found
333
334 e_WriteAttempt = 11 ; Write attempt on protected disk
335
336
Generated by GNU Enscript 1.6.6, and GophHub 1.3.