-
Notifications
You must be signed in to change notification settings - Fork 0
/
nbp.lookup.s
426 lines (421 loc) · 12.4 KB
/
nbp.lookup.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
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
; %help
; nbp.lookup [nbp-name]
;
; Perform NBP lookups.
;
; options:
; nbp-name Optional, name or partial name to lookup.
;
; -v Verbose mode, prints query and zone
; info.
;
; Returns a list of addresses and associated NBP entries.
; or "No results." if none found.
; %hend
.pc02 ; appletalk requires it anyway
.include "davex-mg.inc"
;ch = $24 ; cursor horizontal pos
sptr = xczpage
sptr2 = sptr+2
stemp = sptr2+2
verbose = stemp+1 ; flag to show zone
zonebuf = filebuff2 ; for local zone name
namebuf = zonebuf+$0100 ; for building NBP name for lookup req
altbuf = filebuff3 ; used if no dynamic mem avail
altbufsz = $04 ; pages
DX_start dx_mg_auto_origin ; load address
DX_info $02,$12,dx_cc_iie_or_iigs,$00
DX_ptab
DX_parm $00,t_string ; name
DX_parm 'v',t_nil ; verbose
DX_end_ptab
DX_desc "Perform AppleTalk NBP lookups."
DX_main
cli ; appletalk requires interrupts
ATcall inforeq
bcc :+
jmp noatalk ; commented for debug
: jsr getatbuf ; allocate buffer
sta bufp+1
sty bufp
stx buflen+1
; process command line parms
stz verbose
lda #'v'|$80 ; verbose
jsr xgetparm_ch
bcs :+
inc verbose
: lda #<namebuf
sta sptr
lda #>namebuf
sta sptr+1
; get name
lda #$00
jsr xgetparm_n
ldx #$80 ; name, return wildcard if not given
jsr get_nbp
bcs badnbp1
inx
txa
jsr addsptr
; get type
lda #$00
jsr xgetparm_n
ldx #$81 ; type, return wildcard if not given
jsr get_nbp
badnbp1: bcs badnbp
inx
txa
jsr addsptr
; get zone
lda #$00
jsr xgetparm_n
ldx #$82 ; type, return * if not given
jsr get_nbp
bcs badnbp
; sptr points at where we put the zone
ldy #$01
lda (sptr),y
cmp #'*' ; were we given it?
bne doit
; get local zone if possible
ATcall myzone
bcs doit ; error, just stick with what we got
lda zonebuf ; if none
beq doit ; attempt with default value
ldx #<zonebuf ; copy returned zone in place of what we have
lda #>zonebuf
ldy #$00
jsr copystr
; now we have a complete name to look up
; rts ; DEBUG
doit: lda #<namebuf
sta sptr
lda #>namebuf
sta sptr+1
lda verbose
beq :+ ; don't print unless verbose
jsr prnbptup
jsr xmess
.byte $8d,$00
: ATcall lkupreq
bcc :+
jmp error ; TODO: check for buffer overflow and display what we get
: lda matches
bne :+
jsr xmess
asc_hi "No results."
.byte $8d,$00
rts
: lda bufp+1 ; set up pointer to response buffer
sta sptr+1
lda bufp
sta sptr
prent: ;lda #$00 ; this and next 2 debugging
;ldy matches
;jsr xprdec_2
jsr prnbpent
jsr xcheck_wait
bcs :+ ; if user pressed escape
dec matches
bne prent
: rts
badnbp: lda #$01
jsr xredirect
jsr xmess
asc_hi "Bad name."
.byte $00
bra exiterr
noatalk: lda #$01
jsr xredirect
jsr xmess
asc_hi "AppleTalk offline!"
.byte $00
exiterr: lda #$ff
jsr xredirect
error: jmp xerr
;
; ***
; get_nbp - get part of a name at ay and copy to sptr
; x = 0:name 1:type 2:zone, +$80 sub wildcard or default if none given
; return: (sptr) = string, x = length of it
.proc get_nbp
sty sptr2
sta sptr2+1
stx stemp
ldy #$00
sty colon ; init these
sty at
lda sptr ; copy sptr to self-modifying wrtdest
sta wrtdest+1
lda sptr+1
sta wrtdest+2
jsr incdest ; and move to first char position
lda (sptr2),y ; length
beq notfound ; zero, just give up
sta end
; find the delimiters
tay
: lda (sptr2),y
cmp #':'
bne notcolon
sty colon
notcolon: cmp #'@'
bne nxtdelim
sty at
nxtdelim: dey
bne :-
; now make sure that if @ is given, it is after :
lda at
beq :+
cmp colon
bcc bad
; now get the part requested
: lda stemp
and #$7f
beq getname
cmp #$01
beq gettype
getzone: ldy at
beq notfound
cpy end
beq notfound
; need to copy from at(+1) to end
docopy: ldx #$00
: iny
lda (sptr2),y
jsr wrtdest
cpy end ; was that the last char
bcc :- ; nope, next char
ldy #$00
txa
sta (sptr),y ; save copied length
clc
rts ; and return
getname: ldy colon
bne :+
ldy at
beq :++
: dey
sty end
: ldy end
beq notfound
ldy #$00 ; initially at pos 0
; need to copy from pos 1 to end
beq docopy ; always
gettype: ldy colon
beq notfound ; early out if no colon
cpy end
beq notfound
ldy at
beq :+ ; use end as-is
dey ; otherwise end at pos before @
sty end
: ldy colon
; need to copy from colon(+1) to end
bne docopy ; should be always
notfound: lda stemp
and #$80
bne :+ ; if client asked for a default
lda #$00
tay
tax ; x is officially length of string result
sta (sptr),y ; put a zero in destination
bad: sec ; tell client we gave an empty string
rts
: ldx #$01 ; length of default
ldy #$00
txa
sta (sptr),y
iny
lda stemp
cmp #$82 ; want default zone? ('*')
bne :++ ; nope
lda #'*'
: sta (sptr),y
clc
rts
: lda #'=' ; wildcard for name or type
bne :-- ; always
wrtdest: sta $ffff
inx ; inc count of copied chars
incdest: inc wrtdest+1
bne :+
inc wrtdest+2
: rts
colon: .byte $00
at: .byte $00
end: .byte $00
.endproc
; print an NBP entry at sptr
.proc prnbpent
ldy #$00 ; offset into entry, net number low byte
lda (sptr),y ; big end of network num
pha
iny
lda (sptr),y
tay
pla
jsr xprdec_2
jsr xmess
asc_hi "."
.byte $00
; print node
ldy #$02
lda (sptr),y
tay
lda #$00
jsr xprdec_2
jsr xmess
asc_hi ":"
.byte $00
; print socket
ldy #$03
lda (sptr),y
tay
lda #$00
jsr xprdec_2
jsr xmess
asc_hi " " ; print space in case output is not to screen.
.byte $00
lda #20 ; Position NBP tuple on screen.
sta ch
lda #$05 ; offset to NBP tuple
jsr addsptr
jsr prnbptup
jsr xmess ; CR
.byte $8d,$00
rts
.endproc
; print an NBP tuple at sptr
; leave sptr at byte just after tuple
.proc prnbptup
; print name
jsr prpas
jsr xmess
asc_hi ":"
.byte $00
; print type
jsr prpas
lda verbose
beq skipzone ; if not verbose, don't display @zone
jsr xmess
asc_hi "@"
.byte $00
; print zone
jsr prpas
bra :+
skipzone: ldy #$00
lda (sptr),y ; get length of zone name
inc a ; account for length byte
jsr addsptr ; and skip the lot
: rts ; done
.endproc
; increment sptr by a
.proc addsptr
clc
adc sptr
sta sptr
bcc :+
inc sptr+1
: rts
.endproc
; print pascal string at sptr
; leave sptr pointed at one past end
; of string
.proc prpas
ldy #$00
lda (sptr),y ; get length
tax
next: lda #$01
jsr addsptr
dex
bpl :+
rts
: lda (sptr),y ; get char
ora #$80 ; make printable
jsr cout
bra next
.endproc
; copy a pascal string to sptr offset by y
; a,x = source
; return: y = new offset after copied str
.proc copystr
sta sptr2+1
stx sptr2
sty stemp ; save offset
ldy #$00
lda (sptr2),y ; get number of chars
tax ; to copy
ldy stemp ; get the offset
sta (sptr),y ; store the length byte
inc stemp ; increment the offset
inc sptr2 ; next source char
bne :+
inc sptr2+1
: ldy #0
; copy loop
: phy
lda (sptr2),y
ldy stemp
sta (sptr),y
inc stemp
ply
iny
dex
bne :-
ldy stemp
rts
.endproc
; allocate a big buffer for appletalk operations
; returns ay = start, x = size in pages
; tries to use dynamic mem for operations
; otherwise returns altbuf, which should usually
; be one of the file buffers.
.proc getatbuf
ldx #mli_read
jsr xmmgr
bcs usealt
cmp #altbufsz
bcc usealt
sta tmp ; save num pages
ldx #mli_open
jsr xmmgr ; allocate all
bcc usealt ; if error
ldx tmp ; get num pages
ldy #$00 ; always on page boundary
rts
usealt: ldy #<altbuf
lda #>altbuf
ldx altbufsz
rts
tmp: .byte $00
.endproc
;
inforeq: .byte 0,2 ; sync GetInfo
.word $0000 ; result code
.dword $00000000 ; completion address
thisnet: .word $0000 ; this network #
abridge: .byte $00 ; local bridge
hwid: .byte $00 ; hardware ID, IIgs only
romver: .word $00 ; ROM version, IIgs only
nodenum: .byte $00 ; node number
;
myzone: .byte 0,$1a ; sync GetMyZone
.word $0000 ; result
.dword $00000000 ; completion
.dword zonebuf ; buffer, needs at least 33 bytes
.byte 4,4 ; 4 times every 1 sec
.word $0000 ; reserved
;
lkupreq: .byte 0,$10 ; sync LookupName
.word $0000 ; result
.dword $00000000 ; completion
.dword namebuf ; name pointer
.byte 4,4 ; 4 times every 1 sec
.word $0000 ; reserved
buflen: .word $0000 ; buffer length
bufp: .dword $00000000 ; buffer pointer
.byte $ff ; max # matches
matches: .byte $00 ; actual matches
DX_end