;
;  PROGRAM:  Z3LOC
;  AUTHOR:  RICHARD CONN
;  VERSION:  1.0
;  DATE:  18 MAY 84
;  PREVIOUS VERSIONS:  None
;  DERIVATION:  CCPLOC 1.1 (6 Jan 83)
;
VERS    EQU     10
z3env   SET     0f400h

;
;       Z3LOC -- ZCPR3 Environment Element Locator
;
;       The purpose of Z3LOC is to locate the addresses of the running
; ZCPR3 CCP, BDOS, and BIOS, and to display these values to the user.
; If the Z option is given, the addresses of the following system elements
; are also presented:
;
;               External Path
;               RCP
;               IOP
;               FCP
;               Named Directory
;               Command Line Buffer
;               Shell Stack
;               Environment Descriptor
;               External FCB
;               ZCPR3 Message Buffer
;               External Stack
;               Wheel Byte
;

;
;  CP/M Constants
;
bdos    equ     5       ; BDOS Entry
fcb     equ     5dh     ; 1st char in FCB
cr      equ     0dh
lf      equ     0ah

;
;  Externals
;
       ext     z3init,envptr
       ext     print,phl4hc,cout,crlf

;
; Environment Definition
;
       if      z3env ne 0
;
; External ZCPR3 Environment Descriptor
;
       jmp     start
       db      'Z3ENV' ;This is a ZCPR3 Utility
       db      1       ;External Environment Descriptor
z3eadr:
       dw      z3env
start:
       lhld    z3eadr  ;pt to ZCPR3 environment
;
       else
;
; Internal ZCPR3 Environment Descriptor
;
       MACLIB  Z3BASE.LIB
       MACLIB  SYSENV.LIB
z3eadr:
       jmp     start
       SYSENV
start:
       lxi     h,z3eadr        ;pt to ZCPR3 environment
       endif

;
; Start of Program -- Initialize ZCPR3 Environment
;
       call    z3init  ;initialize the ZCPR3 Env and the VLIB Env
       call    print
       db      'Z3LOC  Version '
       db      (vers/10)+'0','.',(vers mod 10)+'0',0
       lda     fcb     ;check for help
       cpi     'Z'     ;Z is only option
       jz      start1
       cpi     ' '     ;no option?
       jz      start1
       call    print
       db      cr,lf,' Z3LOC or Z3LOC Z'
       db      cr,lf,'Z3LOC gives the addresses of the CCP, BDOS, and BIOS.'
       db      cr,lf,'Z3LOC Z gives all key ZCPR3 addresses.',0
       ret
start1:
       call    print
       db      cr,lf,'ZCPR3 Element    Base Address'
       db      cr,lf,'-------------    ------------',0

       lhld    bdos+1  ;get base address of BDOS
       mvi     l,0     ;set to even boundary
       lxi     d,-800H ;back up to start of CCP (size of CCP)
       dad     d       ;HL pts to CCP
       call    print
       db      cr,lf,'    CCP          ',0
       call    prdata

       lhld    bdos+1  ;just get base address of BDOS again
       call    print
       db      cr,lf,'    BDOS ',0
       call    prdata

       mvi     l,0     ;set even page
       lxi     d,0e00h ;size of BDOS
       dad     d       ;HL pts to BIOS
       call    print
       db      cr,lf,'    BIOS ',0
       call    prdata

       call    crlf    ;new line
       lda     fcb     ;check for Z option
       cpi     'Z'
       rnz             ;done if not Z

       call    print
       db      cr,lf,'Env Descriptor   ',0
       lxi     d,18    ;offset to env descriptor element
       call    z3data
       call    crlf

       call    print
       db      cr,lf,'Pack: FCP        ',0
       lxi     d,9
       call    z3data

       call    print
       db      cr,lf,'      IOP        ',0
       lxi     d,6
       call    z3data

       call    print
       db      cr,lf,'      RCP        ',0
       lxi     d,3
       call    z3data
       call    crlf

       call    print
       db      cr,lf,'Buf: Cmd Line    ',0
       lxi     d,15
       call    z3data

       call    print
       db      cr,lf,'     Ext FCB     ',0
       lxi     d,27
       call    z3data

       call    print
       db      cr,lf,'     Ext Path    ',0
       lxi     d,0
       call    z3data

       call    print
       db      cr,lf,'     Ext Stk     ',0
       lxi     d,29
       call    z3data

       call    print
       db      cr,lf,'     Messages    ',0
       lxi     d,25
       call    z3data

       call    print
       db      cr,lf,'     Named Dir   ',0
       lxi     d,12
       call    z3data

       call    print
       db      cr,lf,'     Shell Stk   ',0
       lxi     d,21
       call    z3data

       call    print
       db      cr,lf,'     Wheel Byte  ',0
       lxi     d,32
       call    z3data

       jmp     crlf    ;new line and exit

;
;  Z3DATA -- Print Data Fields for a ZCPR3 Element
;
z3data:
       lhld    envptr  ;pt to environment
       dad     d       ;HL pts to element
       lxi     d,9     ;add 9 for initial offset
       dad     d       ;fall thru to PRDATA
       mov     e,m     ;get address
       inx     h
       mov     d,m
       xchg

;
;  PRDATA -- Print Data Field (Base Address)
;
prdata:
       call    print
       db      '   ',0
       call    phl4hc  ;print full address
       call    print
       db      ' H',0
       ret

       end