; From: "Svyatoslav Ws. Mironov" <papa@svyat.usr.pu.ru>
; Organization: Institute of Physiology SPbUniversity
; Date: Fri, 26 Apr 1996 02:09:06 +0400 (MSD)

;+
; This short program creates PLAS region for using EN handler,
; passes it address and initializes EN handler.
; Must be included in TCPIP.COM command file.
;
; created       Sv. Ws. Mironov		22-feb-96
; corrected                     	28-apr-96
;
; updated	Alan R. Baldwin		 1-aug-98
;-
        .DSABL  GBL

        .MCALL  .CRRG   .ELRG   .CRAW   .ELAW   .MAP
        .MCALL  .UNMAP  .GMCX   .WDBBK  .WDBDF  .RDBBK

        .MCALL  .EXIT, .PRINT, .TTYOU

START::
        mov     #LKPBLK,r0      ; .lookup #LKPBLK,#5,#ENNAME
        emt     375             ; open EN
        BCC     10$             ;
        mov     #LKPERR,r1      ;
        br      BAD             ;
10$:                            ;
        MOVB    #300,SPFFUN+1   ;
        mov     #rgsiz,spfbuf   ;
        mov     #SPFBLK,r0      ; .spfun #SPFBLK,#5,#300,#RGSIZ,#0,#0
        emt     375             ; #300 - get EN wanted PLAS region size
        bcc     20$             ; good if handler supports this spfun
        mov     #SIZERR,r1      ;
        br      BAD             ;
20$:                            ;
        movb    #207,spffun+1   ; try to get ethernet address
        mov     #adrbuf,spfbuf  ; buffer for station address
        mov     #SPFBLK,r0      ; .spfun #SPFBLK,#5,#207,#adrbuf,#0,#0
        emt     375             ;
        bcs     30$             ; handler is not initialized, yet
        .PRINT  #ALRD           ; already initialized,
        call    praddr          ; print ethernet station address
        clr     r0              ; well return
        .exit                   ;
30$:                            ;
        INC     RGSIZ           ; set size some more
        MOV     #CRRG,R0        ; Create region EMT parameters block
        EMT     375             ;
        BCC     40$             ;
        mov     #CRRERR,r1      ; error
        BR      BAD             ;
40$:                            ;
        CMP     #END,#20000     ; to exclude any false
        BLOS    NEXT            ;
        mov     #BIG,r1         ;
BAD:                            ; severe error printing
        .print  #SEVER          ; "?ENREG-F-"
        mov     r1,r0           ;
        .print                  ; message
        bisb    #10,@#53        ; userrb
        clr     r0              ;
        .exit                   ;
NEXT:                           ;
        MOV     RGID,WNRID      ; move PLAS region ID to WDB
        MOV     #CRAW,R0        ; Create window EMT parameters block
        EMT     375             ;
        BCC     10$             ;
        mov     #CRWERR,r1      ; error
        br      BAD             ;
10$:                            ;
        BIT     #WS.CRW,WNSTS   ; window created without problems?
        BNE     20$             ;
        mov     #NOWCR,r1       ;
        br      BAD             ;
20$:                            ;
        CMP     WNBAS,#20000    ; window virtual address good?
        BEQ     30$             ;
        mov     #WVADDR,r1      ;
        br      BAD             ;
30$:                            ;
        MOVB    #301,SPFFUN+1   ; .spfun #SPFBLK,#5,#301,#20000,#0,#0
        MOV     #20000,SPFBUF   ; #301 - set handler PLAS buffer address
        mov     #SPFBLK,r0      ; as address of user buffer and initialize
        emt     375             ; i.e. give first address of window
        bcc     40$             ;
        mov     #INIERR,r1      ;
        br      bad             ;
40$:                            ;
        movb    #207,spffun+1   ; get ethernet address
        mov     #adrbuf,spfbuf  ; buffer for station address
        mov     #SPFBLK,r0      ; .spfun #SPFBLK,#5,#207,#adrbuf,#0,#0
        emt     375             ;
        bcc     50$             ;
        mov     #PROBL,r1       ; some unknown problems
        br      bad             ;
50$:                            ; well done
        call    praddr          ; print ethernet station address
        clr     r0              ; and success return
        .EXIT                   ;
                                ;
       .page
praddr:                         ; print ethernet address in hex
        .print  #ether          ; text
        mov     #adrbuf+2,r1    ; buffer
        mov     #3,r2           ; word's counter
10$:                            ;
        mov     (r1)+,r3        ;
        call    pribyt          ; bytes ordering like NITEST
        .ttyout #40             ;
        swab    r3              ;
        call    pribyt          ;
        .ttyout #40             ;
        sob     r2,10$          ;
        .print  #crlf           ;
        return                  ;

pribyt:                         ; print byte in hex
        mov     r3,r0           ;
                                ;
        ASR     R0              ; firs tetrade - most significant
        ASR     R0              ;
        ASR     R0              ;
        ASR     R0              ;
                                ;
        BIC     #177760,R0      ;
        CMP     R0,#10.         ;
        BGE     10$             ;
        ADD     #'0,R0          ;
        .ttyou                  ;
        Br      20$             ;
10$:                            ;
        ADD     #<'A-10.>,R0    ;
        .ttyou                  ;
20$:                            ;
        MOV     R3,R0           ; second tetrade
        BIC     #177760,R0      ;
        CMP     R0,#10.         ;
        BGE     30$             ;
        ADD     #'0,R0          ;
        .ttyou                  ;
        Br      40$             ;
30$:                            ;
        ADD     #<'A-10.>,R0    ;
        .ttyou                  ;
40$:                            ;
        return                  ;

       .page
CRRG:                           ; Create region EMT parameters block
        .BYTE   0,36            ;
        .WORD   RDB             ;
CRAW:                           ; Create window EMT parameters block
        .BYTE   2,36            ;
        .WORD   WDB             ;
LKPBLK:                         ;
        .byte   5,1             ; .lookup EMT parameters block
        .WORD   ENNAME          ;
        .word   0               ;
                                ;
SPFBLK: .byte   5,32            ; .spfun EMT parameters block
        .word   0               ; blk
SPFBUF: .word                   ; buf
SPFCNT: .word   0               ; wcnt
SPFFUN: .byte   377,300         ; 300 - get PLAS region size from handler
        .word   0               ; 301 - give PLAS region address to handler
                                ; 302 - init handler
                                ;
RDB::                           ; region descriptor block
RGID:   .WORD   0               ; region ID
RGSIZ:  .WORD   252             ; size, here must be 000770 from handler
RGSTS:  .WORD   RS.GBL+RS.CGR   ; region status
RGNAM:  .RAD50  /EI /           ; region name
        .RAD50  /$  /           ;
    RS.CRR=:^O100000            ;
    RS.UNM=:^O40000             ;
    RS.NAL=:^O20000             ;
    RS.NEW=:^O10000             ;
    RS.GBL=:^O4000              ;
    RS.CGR=:^O2000              ;
    RS.AGE=:^O1000              ;
    RS.EGR=:^O400               ;
    RS.EXI=:^O200               ;
				;
    RS.PVT=:^O000001            ; DIZ
    gr.pvt=:^O100000            ; A.R.Baldwin
    gr.nrf=:^O000040            ; A.R.Baldwin
				;
WDB::                           ; window descriptor block
WNID:   .BYTE                   ; window ID
WNARP:  .BYTE   1               ; winodw's PAR == PAR1
WNBAS:  .WORD                   ; base
WNSIZ:  .WORD   1               ; size == 1*64 bytes
WNRID:  .WORD                   ; region ID
WNOFF:  .WORD   0               ; OFFSET = 0
WNLEN:  .WORD   1               ; LENTH = 1*64
WNSTS:  .WORD   WS.MAP          ; mapping, please!
    WS.CRW=^O100000             ;
    WS.UNM=^O40000              ;
    WS.ELW=^O20000              ;
    WS.MAP=^O400                ;
                                ;
ENNAME:                         ; for .lookup
        .RAD50  /EN0/           ;
        .WORD   0,0             ;
ADRBUF:
        .blkw   4
       .page
        .nlist  bex
SEVER:  .ASCII  /?ENREG-F-/<200>
LKPERR: .ASCIZ  /EN handler .LOOKUP error/
SIZERR: .ASCIZ  /Can't get region size from EN - .SPFUN #300 error/
CRRERR: .ASCIZ  /Can't create region/
CRWERR: .ASCIZ  /.CRAW error/
NOWCR:  .ASCIZ  /Window is not created/
WVADDR: .ASCIZ  /Window virtual address error/
BIG:    .ASCIZ  /Program too big, try to use PAR2 for windowing/
INIERR: .ASCIZ  /Can't initialize EN handler - .SPFUN #301 error/
ALRD:   .ASCIZ  /?ENREG-I-EN handler already initialized/
ETHER:  .ASCII  /?ENREG-I-My ethernet station: /<200>
PROBL:  .ASCIZ  /Some EN problems - can't get station address/
CRLF:   .byte   15,12,200
END::

.IIF GE <. - START + 1000 - 20000> .ERROR
.END START


