NEW
  AUTO 3,1
				.LIST OFF
				.OP	65C02
				.OR	$2000
				.TF bin/atbrowse
*--------------------------------------
				.INB inc/macros.i
				.INB inc/a2osx.i
				.INB inc/mli.i
				.INB inc/mli.e.i
				.INB inc/appletalk.i
*--------------------------------------
				.DUMMY
				.OR ZPBIN
ZS.START
ZPAtlkParams	.BS 2
ZPPTR1			.BS 2
BufPtr			.BS 2
hBuf			.BS 1
ZS.END			.ED
*--------------------------------------
*			File Header (16 Bytes)
*--------------------------------------
CS.START		cld
				jmp (.1,x)
				.DA #$61				6502,Level 1 (65c02)
				.DA #1					BIN Layout Version 1
				.DA 0
				.DA CS.END-CS.START		CS
				.DA DS.END-DS.START		DS
				.DA #64					Stack Size
				.DA #ZS.END-ZS.START	Zero Page Size
				.DA 0
*--------------------------------------
* Relocation Table
*--------------------------------------
.1				.DA CS.INIT
				.DA CS.RUN
				.DA CS.DOEVENT		
				.DA	CS.QUIT
L.MSG.NOATK		.DA MSG.NOATK
L.MSG.ATKERR	.DA MSG.ATKERR
L.MSG.GETINFO	.DA MSG.GETINFO
L.MSG.MYZONE	.DA MSG.MYZONE
L.SEARCH.STRING	.DA SEARCH.STRING
L.MSG.ZONES		.DA MSG.ZONES
L.MSG.PSTR		.DA MSG.PSTR
L.MSG.DUMP0		.DA MSG.DUMP0
L.MSG.DUMP		.DA MSG.DUMP
				.DA 0
*--------------------------------------
CS.INIT			clc
CS.INIT.RTS		rts
*--------------------------------------
CS.RUN			jsr CS.RUN.GetInfo
				bcs .9

				jsr CS.RUN.GetMyZone

				>LDYAI 1024
				>SYSCALL GetMem
				bcs .9

				>STYA BufPtr
				stx hBuf
				
				jsr CS.RUN.GetZoneList

				jsr CS.RUN.LookupName
				
				lda #0

				sec
.9				rts
*--------------------------------------
CS.RUN.GetInfo	>LEA.G P.GetInfo
				ldx #AT.GetInfo
				jsr CS.RUN.GOATLK
				bcs .9

				>PUSHW L.MSG.GETINFO
				>PUSHB.G P.GetInfo+$08	THIS-NET
				>PUSHB.G P.GetInfo+$09	THIS-NET
				>PUSHB.G P.GetInfo+$0E	NODE
				
				>PUSHB.G P.GetInfo+$0A	BRIDGE
				
				>PUSHB.G P.GetInfo+$0C	HARDWARE ID
				>PUSHB.G P.GetInfo+$0D	HARDWARE ID
				>PUSHB.G P.GetInfo+$0B	ROM VERSION
				
				>PUSHBI 7
				>SYSCALL PrintF
				rts

.9				pha
				>LDYA L.MSG.NOATK
				>SYSCALL PutS
				pla
				sec
				rts
*--------------------------------------
CS.RUN.GetMyZone
				>LEA.G ZoneBuf
				>STYA.G P.GetMyZone+$08

				lda #4					1/4 sec
				>STA.G P.GetMyZone+$0C	RetInt
				>STA.G P.GetMyZone+$0D	RetCnt
				
				>LEA.G P.GetMyZone
				ldx #AT.GetMyZone
				jsr CS.RUN.GOATLK
				bcs .9
				
				>PUSHW L.MSG.MYZONE
				>PUSHEA.G ZoneBuf
				>PUSHBI 2
				>SYSCALL PrintF
.9				rts
*--------------------------------------
CS.RUN.GetZoneList
				>LDYAI 1024
				>STYA.G P.GetZoneList+$08	BufLen
				>LDYA BufPtr
				>STYA.G P.GetZoneList+$0A	BufPtr

				>LDA.G P.GetInfo+$0A		BRIDGE
				>STA.G P.GetZoneList+$0E

				lda #1
				>STA.G P.GetZoneList+$0F	Start Index

				lda #4					1/4 sec
				>STA.G P.GetZoneList+$11	RetInt
				>STA.G P.GetZoneList+$12	RetCnt
				
				>LEA.G P.GetZoneList
				ldx #AT.GetZoneList
				jsr CS.RUN.GOATLK
				bcs .9

				>LDYA L.MSG.ZONES
				>SYSCALL PutS
				
				>LDA.G P.GetZoneList+$13	Zone #
				beq .8
				
				tax
				>LDYA BufPtr
				jsr CS.RUN.PrintListYAX
				
.8				clc

.9				rts
*--------------------------------------
CS.RUN.LookupName
				>LDYA L.SEARCH.STRING
				>STYA.G P.LookupName+$08	Entry Name Ptr

				lda #4
				>STA.G P.LookupName+$0C	RetInt
				>STA.G P.LookupName+$0D	RetCnt

				>LDYAI 1024
				>STYA.G P.LookupName+$10	BufLen
				>LDYA BufPtr
				>STYA ZPPTR1
				>STYA.G P.LookupName+$12	BufPtr
				
				lda #16
				>STA.G P.LookupName+$16		MaxMatch
				
				>LEA.G P.LookupName
				ldx #AT.LookupName
				jsr CS.RUN.GOATLK
.99				bcs .9

				>LDYA L.MSG.DUMP0
				>SYSCALL PutS
				bcs .9

				>LDA.G P.LookupName+$17
				beq .8

.1				>PUSHW L.MSG.DUMP

				ldy #0

.2				>PUSHB (ZPPTR1),y
				iny
				cpy #5
				bne .2

				lda ZPPTR1
				clc
				adc #5
				sta ZPPTR1
				lda ZPPTR1+1
				adc #0
				sta ZPPTR1+1

				ldx #3

.3				>PUSHW ZPPTR1
				lda ZPPTR1
				sec
				adc (ZPPTR1)
				sta ZPPTR1
				lda ZPPTR1+1
				adc #0
				sta ZPPTR1+1
				dex
				bne .3
				
				>PUSHBI 11
				>SYSCALL PrintF
				bcs .9

				>DEC.G P.LookupName+$17
				bne .1

.8				clc
.9				rts
*--------------------------------------
CS.RUN.GOATLK	>STYA ZPAtlkParams

				ldy #1
				txa
				sta (ZPAtlkParams),y

				>LDYA ZPAtlkParams
				jsr A2osX.ATKCALL
				bcc .9

				pha

				>PUSHW L.MSG.ATKERR
				
				ldy #1
				lda (ZPAtlkParams),y
				>PUSHA
				
				ldy #3
				lda (ZPAtlkParams),y
				>PUSHA
				dey
				lda (ZPAtlkParams),y
				>PUSHA
				
				>PUSHBI 3
				>SYSCALL PrintF

				pla
				sec
.9				rts				
*--------------------------------------
CS.RUN.PrintListYAX
				>STYA ZPPTR1
				
.1				phx
				>PUSHW L.MSG.PSTR
				>PUSHW ZPPTR1
				>PUSHBI 2
				>SYSCALL PrintF				
				plx
				bcs .9
				
				lda (ZPPTR1)
				sec
				adc ZPPTR1
				sta ZPPTR1
				bcc .2
				inc ZPPTR1+1

.2				dex
				bne .1
				
.8				clc
.9				rts
*--------------------------------------
CS.DOEVENT		sec
				rts
*--------------------------------------
CS.QUIT			lda hBuf
				beq .8
				>SYSCALL FreeMem
				
.8				clc
				rts
*--------------------------------------
CS.END			
MSG.NOATK		.AZ "AppleTalk Not Loaded."
MSG.ATKERR		.AZ "AppleTalk Call %h, ERR:%H\r\n"
MSG.GETINFO		.AS "Network/Node:%H/%h\r\n"
				.AS "Bridge      :     %h\r\n"
				.AZ "HWID/ROMVER :%H/%h\r\n"
MSG.MYZONE		.AZ "Zone Name   :%S\r\n"
SEARCH.STRING	>PSTR "="
				>PSTR "="
				>PSTR "*"
MSG.ZONES		.AZ "Zone list :"
MSG.PSTR		.AZ " %S\r\n"
MSG.DUMP0		.AZ "Net  Nod SkT En# Object:Type@Zone"
MSG.DUMP		.AZ "\e[?7l%H %h  %h  %h  %S:%S@%S\r\n"
*--------------------------------------
				.DUMMY
				.OR 0
DS.START
P.GetInfo		.BS $0F
P.GetZoneList	.BS $19
P.GetMyZone		.BS $10
P.LookupName	.BS $18
ZoneBuf			.BS 33
DS.END			.ED
*--------------------------------------
MAN
SAVE usr/src/bin/atbrowse.s
ASM
