-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
apilist.asm
489 lines (386 loc) · 8.22 KB
/
apilist.asm
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
;--- UNAPI implementations lister v1.1
; By Konamiman, 2/2010
;
; You can compile it with sjasm (https://github.com/Konamiman/Sjasm/releases):
; sjasm apilist.asm apilist.com
; The resulting file is a MSX-DOS .COM program.
;
; Usage: apilist <implementation identifier>|*
;*******************
;*** CONSTANTS ***
;*******************
;--- System variables and routines
_TERM0: equ 00h
_CONOUT: equ 02h
_STROUT: equ 09h
RDSLT: equ 000Ch ;A=PEEK(Slot A, Addr HL)
CALSLT: equ 001Ch ;CALL Slot IYh, Addr IX
ARG: equ 0F847h
EXTBIO: equ 0FFCAh
;**********************
;*** MAIN PROGRAM ***
;**********************
org 100h
;--- Show welcome message
ld de,WELCOME_S
ld c,_STROUT
call 5
;--- Put a 0 at the end of the command line
; (needed when running DOS 1)
ld hl,(0080h)
ld h,0
ld bc,0081h
add hl,bc
ld (hl),0
;--- Search the parameter (skip spaces in command line)
ld hl,80h
SRCHPAR:
inc hl
ld a,(hl)
cp " "
jr z,SRCHPAR
or a
jr nz,GETPAR
;--- No parameters: show usage information
; and terminate
ld de,USAGE_S
ld c,_STROUT
call 5
ld c,_TERM0
jp 5
;--- Copy the parameter to ARG
GETPAR: ld de,ARG
ld a,(hl)
cp "*"
jr z,SPECLESS
ld bc,15
ldir
SPECLESS:
ex de,hl
ld (hl),0 ;To prevent paramater >15 chars
;--- Get number of installed implementations
ld de,2222h
xor a
ld b,0
call EXTBIO
ld a,b
ld (NUM_IMP),a
;--- Print the number of installed implementations
ld de,FOUND_S ;Print "Found"
ld c,_STROUT
call 5
ld a,(NUM_IMP)
ld ix,TEMP ;Print the number
call BYTE2ASC
ld (ix),"$"
ld de,TEMP
ld c,_STROUT
call 5
ld a,(ARG)
or a
jr z,SPECLESS2
;> No specificationless application
ld de,IMPLEMS_S ;Print "implementations of the"
ld c,_STROUT
call 5
ld hl,ARG ;Print the API identifier
PRINTID:
ld a,(hl)
or a
jr z,OKPRINTID
call TOUPPER
ld e,a
ld c,_CONOUT
push hl
call 5
pop hl
inc hl
jr PRINTID
OKPRINTID:
ld de,API_S ;Print "API"
ld c,_STROUT
call 5
jr OK_PRNUM
;> Specificationless application
SPECLESS2:
ld de,SPECLESS_S
ld c,_STROUT
call 5
OK_PRNUM:
;--- If no implementations found,
; print a dot and terminate; otherwise
; print a colon and continue
ld a,(NUM_IMP)
or a
jr nz,NOZEROIMP
ld de,DOT_S
ld c,_STROUT
call 5
ld c,_TERM0
jp 5
NOZEROIMP:
ld de,COLON_S
ld c,_STROUT
call 5
;--- Obtain the address of the RAM helper.
; If not installed, the address will be 0,
; but we will not call it anyway since
; there will be no RAM implementations.
ld de,2222h
ld hl,0
ld a,0FFh
call EXTBIO
ld (RAM_HELPER),hl
;>>> Here begins a loop for all implementations
MAIN_LOOP:
;--- Obtain location of the current implementation
ld a,(CUR_IMP)
ld de,2222h
call EXTBIO
ld (IMP_SLOT),a
ld a,b
ld (IMP_SEG),a
ld (IMP_ENTRY),hl
;--- Build code to read the implementation name
ld a,(IMP_ENTRY+1)
and 10000000b
jr z,BLDCODE2 ;Page 3 implemenation:
ld a,7Eh ;code for "ld a,(hl)"
ld (READ_CODE),a
jr OKBLDCODE
BLDCODE2:
ld a,0CDh ;code for "call"
ld (READ_CODE),a
ld a,(IMP_SEG)
ld hl,RDSLT ;ROM implem: call to RDSLT
cp 0FFh
jr z,BLDCODE3
ld hl,(RAM_HELPER)
inc hl
inc hl
inc hl ;RAM implem: call to RAM helper
BLDCODE3:
ld (READ_CODE+1),hl
OKBLDCODE:
;--- Call function 0 to obtain name and version
xor a
call EXE_UNAPI
push bc ;Save version number
;--- Print the implementation name
ld a,(IMP_SEG)
ld b,a
ld a,(IMP_SLOT)
NAME_LOOP:
push af
push bc
push hl
READ_CODE:
nop ;Will be "ld a,hl", "call RDLT" or "call HELPER+3"
nop
nop
or a
jr z,NAME_END
ld e,a
ld c,_CONOUT
call 5
pop hl
pop bc
pop af
inc hl
jr NAME_LOOP
NAME_END:
pop hl
pop bc
pop af
;--- Now print the implementation version
ld ix,TEMP+2
ld (ix-2)," "
ld (ix-1),"v"
pop bc
push bc
ld a,b
call BYTE2ASC ;Main version number
ld (ix),"."
inc ix
pop bc
ld a,c
call BYTE2ASC ;Secondary version number
ld (ix),"$"
ld de,TEMP
ld c,_STROUT
call 5
;--- Print the implementation location
ld de,ON_S
ld c,_STROUT
call 5
;* Location is page 3: simply print "page 3"
ld a,(IMP_ENTRY+1)
and 10000000b
jr z,NOPAGE3
ld de,PAGE3_S
ld c,_STROUT
call 5
jr PRNAME_END
NOPAGE3:
;* RAM or ROM: print slot number
ld de,SLOT_S
ld c,_STROUT
call 5
ld ix,TEMP
ld a,(IMP_SLOT) ;Build main slot number
and 00000011b
add "0"
ld (ix),a
inc ix
ld a,(IMP_SLOT)
bit 7,a
jr z,BLDSLOT_END
ld (ix),"-" ;If expanded, build subslot number
inc ix
rrca
rrca
and 00000011b
add "0"
ld (ix),a
inc ix
BLDSLOT_END: ld (ix),"$"
ld de,TEMP
ld c,_STROUT
call 5
;* RAM: print segment number
ld a,(IMP_SEG)
cp 0FFh
jr z,PRNAME_END
ld ix,TEMP
call BYTE2ASC
ld (ix),"$"
ld de,SEG_S
ld c,_STROUT
call 5
ld de,TEMP
ld c,_STROUT
call 5
PRNAME_END:
;--- Go for the next implementation, if any
ld de,CRLF_S
ld c,_STROUT
call 5
ld a,(NUM_IMP)
ld b,a
ld a,(CUR_IMP)
cp b
ld c,_TERM0 ;Terminate if no more implementations
jp z,5
inc a
ld (CUR_IMP),a
jp MAIN_LOOP
;*********************
;*** SUBROUTINES ***
;*********************
;--- Convert a 1-byte number to an unterminated ASCII string
; Input: A = Number to convert
; IX = Destination address for the string
; Output: IX points after the string
; Modifies: AF, C
BYTE2ASC: cp 10
jr c,B2A_1D
cp 100
jr c,B2A_2D
cp 200
jr c,B2A_1XX
jr B2A_2XX
;--- One digit
B2A_1D: add "0"
ld (ix),a
inc ix
ret
;--- Two digits
B2A_2D: ld c,"0"
B2A_2D2: inc c
sub 10
cp 10
jr nc,B2A_2D2
ld (ix),c
inc ix
jr B2A_1D
;--- Between 100 and 199
B2A_1XX: ld (ix),"1"
sub 100
B2A_XXX: inc ix
cp 10
jr nc,B2A_2D ;If 1XY with X>0
ld (ix),"0" ;If 10Y
inc ix
jr B2A_1D
;--- Between 200 and 255
B2A_2XX: ld (ix),"2"
sub 200
jr B2A_XXX
;--- Execute a function on an UNAPI implementation
EXE_UNAPI:
push af
ld ix,(IMP_ENTRY)
ld a,ixh
and 10000000b
jr z,EXEUNAP2
pop af
jp (ix) ;Direct call to page 3
EXEUNAP2:
ld a,(IMP_SEG)
cp 0FFh
jr nz,EXEUNAP3
ld iy,(IMP_SLOT-1)
ld ix,(IMP_ENTRY)
pop af
jp CALSLT ;Call to ROM
EXEUNAP3: ld a,(IMP_SLOT)
ld iyh,a
ld a,(IMP_SEG)
ld iyl,a
pop af
ld ix,(RAM_HELPER)
push ix
ld ix,(IMP_ENTRY) ;Call to segment
ret
;--- Convert a character to upper-case if it is a lower-case letter
TOUPPER:
cp "a"
ret c
cp "z"+1
ret nc
and 0DFh
ret
;**************************
;*** DATA AND STRINGS ***
;**************************
NUM_IMP: db 0 ;Number of implementations found
CUR_IMP: db 1 ;Index of the current implementation
IMP_SLOT: db 0 ;Slot of the current implementation
IMP_SEG: db 0 ;Segment of the current implementation
IMP_ENTRY: dw 0 ;Entry point of the current imp.
RAM_HELPER: dw 0 ;Address of the RAM helper
WELCOME_S:
db "UNAPI implementations lister 1.1",13,10
db "(c) 2010 by Konamiman",13,10
db 13,10
db "$"
USAGE_S:
db "Usage: APILIST <implementation identifier>|*",13,10
db " use * to list specificationless applications.",13,10,"$"
FOUND_S:
db "Found $"
IMPLEMS_S:
db " implementation(s) of the $"
API_S: db " API$"
SPECLESS_S:
db " specificationless applications$"
COLON_S:
db ":",13,10,13,10,"$"
DOT_S: db "."
CRLF_S: db 13,10,"$"
ON_S: db " on $"
PAGE3_S:
db "page 3$"
SLOT_S: db "slot $"
SEG_S: db ", segment $"
TEMP: ;For temporary data