10 REM > SERVERS/S
   20 REM Broadcast for and display list of servers on network
   30 :
   40 REM 08/04/1989 v1.00 SJ/Stu: Initial version from SJ
   50 REM 12/06/1998 v2.00 JGH: Rewritten to use code space more efficiently
   60 :
   70 OSASCI=&FFE3:OSWRCH=&FFEE
   80 DIM mcode% &300:Start%=&0900
   90 FORP=0TO1
  100   P%=Start%:O%=mcode%
  110   [OPT P*3+4
  120   EQUS "Station Type   Vers Name":EQUB 13:BRK
  130   :
  140   .Go%
  150   LDY #0:LDX #0:JSR PrTextY
  160   LDA #1:STA PrTextY+2      :\ Alter PrTextY pointer
  170   :
  180   JSR RxOpen
  190   .MainTxLoop
  200   JSR Transmit
  210   LDA #5:STA RxCount+1      :\ Poll Rx &500 times
  220   .PollRxLoop
  230   JSR RxPoll:TXA:BMI RxReceived
  240   DEC RxCount:BNE PollRxLoop
  250   DEC RxCount+1:BNE PollRxLoop
  260   DEC TxCount:BNE MainTxLoop:\ Broadcast 5 times
  270   .ServersExit
  280   JMP RxDelete
  290   :
  300   .RxReceived
  310   JSR RxRead
  320   LDA Entries:BEQ RxUnique  :\ None received yet
  330   LDY #&00
  340   .ScanTableLoop
  350   TYA:PHA                   :\ Save pointer
  360   JSR Times10Y
  370   LDA &0F01,Y:CMP NetNum:BNE NoMatch
  380   LDA &0F00,Y:CMP StnNum:BNE NoMatch
  390   LDX #&00
  400   .ScanServerName
  410   LDA &0103,X:CMP &0F02,Y:BNE NoMatch
  420   INY:INX:CPX #&08:BCC ScanServerName
  430   PLA:JMP PrServerDone
  440   .NoMatch
  450   PLA:TAY:INY
  460   CPY Entries:BCC ScanTableLoop
  470   :
  480   .RxUnique
  490   LDY Entries:INC Entries:TYA:JSR Times10Y:\ Point to entry
  500   LDA NetNum:INY:JSR PrNetStnNum          :\ Print network number
  510   LDA #ASC".":JSR OSWRCH
  520   LDA StnNum:DEY:JSR PrNetStnNum          :\ Print station number
  530   JSR PrSpace:LDX #&03
  540   .PrServerNameLp
  550   LDA &0100,X:STA &0F02,Y:JSR OSWRCH
  560   INX:INY:CPX #&0B:BCC PrServerNameLp
  570   JSR PrSpace:LDA &0102:JSR PrHex         :\ Print version number
  580   JSR PrSpace
  590   LDY #&0C:LDX &010B:BEQ PrSkipName
  600   JSR PrTextY                             :\ Print name
  610   .PrSkipName
  620   JSR OSNEWL:LDA &0100:BEQ PrServerNext   :\ If no error, finish
  630   LDX #&14:LDA #&20
  640   .PrSpacesLoop
  650   JSR OSWRCH:DEX:BNE PrSpacesLoop         :\ Indent by 20 spaces
  660   JSR PrTextY:JSR OSNEWL                  :\  Print error message
  670   .PrServerNext
  680   LDY Entries:CPY #&18:BCS PrServersFinished:\ Can only store 25 entries
  690   .PrServerDone
  700   JSR RxOpen
  710   JMP PollRxLoop
  720   :
  730   .Times10Y
  740   STA &AC:ASL &AC:ASL A:ASL A:ASL A:CLC:ADC &AC:TAY
  750   .PrServersFinished
  760   RTS
  770   :
  780   .PrTextY:\ Gets altered to &0100
  790   LDA Start%,Y:BEQ PrTextYEnd:JSR OSASCI
  800   INY:DEX:BNE PrTextY
  810   .PrTextYEnd
  820   RTS
  830   :
  840   .PrHex
  850   PHA:LSR A:LSR A:LSR A:LSR A:JSR PrNybble:PLA
  860   .PrNybble
  870   AND #&0F:SED:CLC:ADC #&90:ADC #&40:CLD
  880   .PrChar
  890   JMP OSWRCH
  900   :
  910   .PrSpace
  920   LDA #ASC" ":BNE PrChar
  930   :
  940   .PrNetStnNum
  950   STA &0F00,Y :\ Drop into PrDec
  960   :
  970   .PrDec
  980   LDX #&FF
  990   .PrDec100Lp
 1000   INX:SEC:SBC #&64:BCS PrDec100Lp
 1010   ADC #&64:JSR PrDigit
 1020   LDX #&FF
 1030   .PrDec10Lp
 1040   INX:SEC:SBC #&0A:BCS PrDec10Lp
 1050   ADC #&0A:JSR PrDigit
 1060   TAX
 1070   .PrDigit
 1080   PHA:TXA:ORA #&30:JSR OSWRCH
 1090   PLA:RTS
 1100   :
 1110   .RxDelete         :\ Delete open control block
 1120   LDA #&34:EQUB &2C :\ BIT &xxxx to skip next two bytes
 1130   :
 1140   .RxPoll           :\ Poll open control block
 1150   LDA #&33
 1160   .RxPollByte
 1170   LDX RxCtrl:JMP OSBYTE
 1180   :
 1190   .RxOpen
 1200   LDA #&00:STA RxCtrl
 1210   STA StnNum:STA NetNum
 1220   LDA #&7F:STA RxFlag
 1230   LDA #&50:STA EndAddr
 1240   LDA #&01:STA EndAddr+1
 1250   JSR RxRead:LDA RxCtrl:BNE TxPollDone
 1260   BRK:EQUB &C0:EQUS "Rxcb?":BRK
 1270   :
 1280   .RxRead
 1290   LDA #&11:LDX #RxCtrl AND 255:LDY #RxCtrl DIV 256:JMP OSWORD
 1300   :
 1310   .Transmit
 1320   LDA #&80:STA TxCtrl
 1330   LDA #&10:LDX #TxCtrl AND 255:LDY #TxCtrl DIV 256:JSR OSWORD
 1340   LDA TxCtrl:BEQ Transmit        :\ Loop until opened
 1350   :
 1360   .TxPollLoop
 1370   LDA #&32:JSR OSBYTE
 1380   TXA:BMI TxPollLoop:BNE Transmit:\ Loop until completed
 1390   .TxPollDone
 1400   RTS
 1410   :
 1420   .RxCount:EQUW &0500
 1430   .TxCount:EQUB &05
 1440   .Entries:EQUB &00
 1450   .TxCtrl :EQUB &80
 1460            EQUB &B0
 1470            EQUW &FFFF
 1480            EQUS "        "
 1490   :
 1500   .RxCtrl :EQUB &00
 1510   .RxFlag :EQUB &7F:EQUB &B1
 1520   .StnNum :EQUB &00
 1530   .NetNum :EQUB &00
 1540   .StrAddr:EQUD &FFFF0100
 1550   .EndAddr:EQUD &FFFF0150
 1560   EQUS "JGH 15/06/1998"
 1570   :
 1580 ]:NEXT
 1590 PRINT"*SAVE Servers ";~mcode%;" ";~O%;" ";~Go%OR&FFFF0000;" ";~Start%OR&FFFF0000