home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / ZSYS / SIMTEL20 / ZCPR3 / VMENUCK.MQC / VMENUCK.MAC
Text File  |  2000-06-30  |  11KB  |  551 lines

  1. ;
  2. ;  PROGRAM:  VMENUCK
  3. ;  AUTHOR:  RICHARD CONN
  4. ;  VERSION:  1.0
  5. ;  DATE:  22 July 84
  6. ;  PREVIOUS VERSIONS:  None
  7. ;  DERIVATION:  MENUCK 1.0 (18 May 84)
  8. ;
  9. VERS    EQU    10    ;VERSION NUMBER
  10. z3env    SET    0f400h
  11.  
  12. ;
  13. ;    VMENUCK is used to check the syntax of a MENU.VMN file for the ZCPR3
  14. ; menu processor, VMENU.  VMENU was optimized for size and runtime speed, and
  15. ; I tried to keep the size under 2K (and succeeded, for that matter).  In
  16. ; keeping VMENU small, the error diagnostics it gives are quite limited, with
  17. ; a variety of errors producing the message "Str Err" for MENU.VMN
  18. ; structure error.
  19. ;
  20. ;    VMENUCK is intended to be used to check the syntax and other features
  21. ; of a user's MENU.VMN before allowing VMENU to run with it.  In this way,
  22. ; many errors may be caught before the MENU.VMN file comes into common use,
  23. ; and there is plenty of space for informative diagnostics.
  24. ;
  25.  
  26. ;
  27. ;  MENU Constants
  28. ;
  29. MCMD    EQU    ':'    ;Menu Jump Command
  30. MINDIC    EQU    '#'    ;Menu Indic
  31. GOPTION    EQU    '-'    ;Global Option Indic
  32. XOPTION    EQU    'X'
  33. VARFLAG    EQU    '$'    ;Variable Flag
  34.  
  35. ;
  36. ;  CP/M Constants
  37. ;
  38. bentry    equ    5    ;BDOS Entry
  39. fcb    equ    5ch    ;FCB
  40. tbuff    equ    80h    ;Temp I/O Buffer
  41. cr    equ    0dh
  42. lf    equ    0ah
  43. EOF    equ    'Z'-'@'    ;^Z=EOF
  44.  
  45. ;
  46. ;  Externals
  47. ;
  48.     ext    z3init,zfname,z3log
  49.  
  50.     ext    caps,crlf,eval10,retud
  51.     ext    f$open,f$close,f$read
  52.     ext    print,cout
  53.     ext    moveb
  54.     ext    phldc,padc,pfn2,pafdc
  55.     ext    codend
  56.  
  57. ;
  58. ; Environment Definition
  59. ;
  60.     if    z3env ne 0
  61. ;
  62. ; External ZCPR3 Environment Descriptor
  63. ;
  64.     jmp    start
  65.     db    'Z3ENV'    ;This is a ZCPR3 Utility
  66.     db    1    ;External Environment Descriptor
  67. z3eadr:
  68.     dw    z3env
  69. start:
  70.     lhld    z3eadr    ;pt to ZCPR3 environment
  71. ;
  72.     else
  73. ;
  74. ; Internal ZCPR3 Environment Descriptor
  75. ;
  76.     MACLIB    Z3BASE.LIB
  77.     MACLIB    SYSENV.LIB
  78. z3eadr:
  79.     jmp    start
  80.     SYSENV
  81. start:
  82.     lxi    h,z3eadr    ;pt to ZCPR3 environment
  83.     endif
  84.  
  85. ;
  86. ; Start of Program -- Initialize ZCPR3 Environment
  87. ;
  88.     call    z3init    ;initialize the ZCPR3 Env and the VLIB Env
  89.  
  90.     call    print
  91.     db    'VMENUCK  Version '
  92.     db    (vers/10)+'0','.',(vers mod 10)+'0',0
  93.  
  94.     lda    fcb+1    ;get first char
  95.     cpi    ' '    ;no file name?
  96.     jz    help
  97.     cpi    '/'    ;option?
  98.     jnz    start1
  99. ;
  100. ;  Print Help Message
  101. ;
  102. help:
  103.     call    print
  104.     db    cr,lf,'Syntax:'
  105.     db    cr,lf,'  VMENUCK dir:filename.typ <-- Check File'
  106.     db    cr,lf,'  VMENUCK dir:filename     <-- Check filename.VMN'
  107.     db    0
  108.     ret
  109.  
  110. ;
  111. ;  Begin serious processing -- locate the file pted to by HL
  112. ;
  113. start1:
  114.     lxi    d,fcb        ;pt to FCB
  115.     call    z3log        ;log into indicated FCB
  116.  
  117. ;
  118. ;  Set File Type to MNU if not specified
  119. ;
  120. start2:
  121.     lxi    h,fcb+9        ;pt to file type
  122.     mov    a,m        ;get first char
  123.     cpi    ' '        ;set type if <SP>
  124.     jnz    start3
  125.     push    b        ;save BC
  126.     lxi    d,mnutyp    ;set type to MNU
  127.     xchg
  128.     mvi    b,3        ;3 bytes
  129.     call    moveb
  130.     pop    b        ;get BC
  131. ;
  132. ;  Try to Open the File
  133. ;
  134. start3:
  135.     lxi    d,fcb        ;prepare to open file
  136.     xra    a        ;A=0 to select current disk
  137.     stax    d
  138.     call    f$open        ;open file
  139.     jz    readfile    ;read in file if OK
  140.     call    print
  141.     db    cr,lf,' File Not Found',0
  142.     ret
  143. ;
  144. ;  Read in File
  145. ;
  146. readfile:
  147.     call    codend        ;get address of first block
  148. readloop:
  149.     lxi    d,fcb        ;read block
  150.     call    f$read        ;do it
  151.     ora    a        ;check for error
  152.     jnz    readdone
  153.     lxi    d,tbuff        ;pt to block just read in
  154.     mvi    b,128        ;128 bytes
  155. readmove:
  156.     ldax    d        ;get byte
  157.     ani    7fh        ;mask MSB
  158.     mov    m,a        ;put byte
  159.     inx    h        ;pt to next
  160.     inx    d
  161.     dcr    b        ;count down
  162.     jnz    readmove
  163.     xchg            ;DE pts to next block
  164.     lhld    bentry+1    ;get address of BDOS
  165.     mov    a,h        ;check for possible overflow
  166.     sui    10        ;10 pages below BDOS is limit
  167.     cmp    d        ;within range?
  168.     xchg            ;HL pts to next block
  169.     jnc    readloop    ;continue read if within range
  170.     call    print
  171.     db    cr,lf,' TPA Overflow -- VMENU File is Too Big',0
  172.     ret
  173. ;
  174. ;  Read is Done -- Store Ending ^Z and Set Initial Values
  175. ;
  176. readdone:
  177.     mvi    m,EOF    ;Store ^Z to ensure EOF
  178.     lxi    d,fcb        ;Close File
  179.     call    f$close
  180.     mvi    a,0ffh        ;A = -1
  181.     sta    menunum        ;set menu number
  182.     sta    maxnum        ;set max number of all menus
  183.     lxi    h,0        ;HL=0
  184.     shld    errors        ;Set Error Count to 0
  185.     inx    h        ;HL=1
  186.     shld    linenum        ;Set Line Number to 1
  187. ;
  188. ;  Count Number of Menus
  189. ;
  190.     call    codend        ;Pt to First Byte
  191.     mov    a,m        ;get first byte
  192. ;
  193. ;  Skip to Beginning of Menu Display
  194. ;
  195. mdskip:
  196.     cpi    EOF        ;EOF?
  197.     jz    mdone
  198.     cpi    MINDIC        ;beginning of display?
  199.     jz    mcgo        ;now go skip commands
  200.     call    lskip        ;skip to next line
  201.     jmp    mdskip
  202. mcgo:
  203.     inx    h        ;pt to char after MINDIC
  204.     mov    a,m        ;another MINDIC?
  205.     cpi    MINDIC
  206.     jz    mdone        ;done if 2 in a row
  207.     lda    maxnum        ;get menu number count
  208.     inr    a        ;found another one
  209.     sta    maxnum
  210. mcskip:
  211.     call    lskip        ;skip to next line
  212.     jz    mdone        ;done if premature EOF
  213.     cpi    MINDIC        ;end of display?
  214.     jnz    mcskip
  215.     inx    h        ;pt to char after MINDIC
  216.     mov    a,m        ;get it
  217.     jmp    mdskip
  218. ;
  219. ;  Check for Valid First Character
  220. ;
  221. mdone:
  222.     call    print
  223.     db    cr,lf,'VMenu Syntax Check on ',0
  224.     call    retud        ;get dir
  225.     mov    a,b        ;get disk
  226.     adi    'A'
  227.     call    cout
  228.     mov    a,c        ;get user
  229.     call    pafdc
  230.     mvi    a,':'
  231.     call    cout
  232.     lxi    d,fcb+1        ;pt to FCB
  233.     call    pfn2
  234.     call    print        ;Print Header
  235.     db    cr,lf
  236.     db    cr,lf,' Line Comment/Error Message'
  237.     db    cr,lf,' ---- ---------------------',0
  238.  
  239.     xra    a        ;set no global option
  240.     sta    gopt
  241.     call    codend        ;get address of first byte
  242.     mov    a,m        ;get first char
  243.     cpi    GOPTION        ;global options?
  244.     jnz    newmenu        ;process globals
  245.     mvi    a,0ffh        ;set global option
  246.     sta    gopt
  247.     call    lprint
  248.     db    '** Global Options Detected **',0
  249.     call    optchk        ;check options
  250.     xra    a        ;set no global option
  251.     sta    gopt
  252.     call    nxtline        ;advance to next line
  253. ;
  254. ;  This is the main entry point for processing a menu
  255. ;
  256. newmenu:
  257.     mov    a,m        ;get Menu Indicator
  258.     cpi    MINDIC        ;must be MINDIC
  259.     jz    nm1
  260.     call    newerr        ;add to error count
  261.     call    lprint
  262.     db    ' New Menu Expected, But ',MINDIC,' NOT Found -- '
  263.     db    'Aborting',0
  264.     jmp    errxit
  265. ;
  266. ;  Print that we have a new menu
  267. ;
  268. nm1:
  269.     call    lprint
  270.     db    '** Menu Number ',0
  271.     lda    menunum        ;increment menu number
  272.     inr    a
  273.     sta    menunum
  274.     call    padc
  275.     call    optchk        ;check options
  276. ;
  277. ;  Skip Thru Display
  278. ;
  279. nm2:
  280.     call    nxtline        ;skip to next line
  281.     jnz    nm2a        ;continue if no EOF
  282. earlyeof:
  283.     call    newerr        ;add to error count
  284.     call    lprint
  285.     db    ' Premature EOF Encountered',0
  286.     jmp    errxit
  287. nm2a:
  288.     cpi    MINDIC        ;Menu Indicator?
  289.     jnz    nm2        ;Continue
  290. ;
  291. ;  Move Thru Menu Commands
  292. ;
  293. nm3:
  294.     call    mcmd1        ;check Menu Command Line
  295.     jz    earlyeof
  296.     call    lcheck        ;check line
  297.     cpi    MINDIC        ;check for menu indicator
  298.     jnz    nm3        ;continue until menu indicator encountered
  299.     inx    h        ;check for 2 indicators in a row for end
  300.     mov    a,m        ;get 2nd char
  301.     dcx    h        ;back up in case it is not
  302.     cpi    MINDIC        ;2 in a row?
  303.     jnz    newmenu        ;process as new menu if not
  304. errxit:
  305.     call    lprint
  306.     db    '** End of Menu Check **',cr,lf,'    ',0
  307.     lhld    errors        ;check error count
  308.     mov    a,h        ;check for Zero
  309.     ora    l
  310.     jnz    err1
  311.     call    print
  312.     db    'No',0
  313.     jmp    err2
  314. err1:
  315.     call    phldc        ;print as decimal
  316. err2:
  317.     call    print
  318.     db    ' Errors Detected',0
  319.     ret
  320.  
  321. ;
  322. ;  Utilities
  323. ;
  324.  
  325. ;
  326. ;  LPRINT -- Print "Line # "+text
  327. ;
  328. lprint:
  329.     call    crlf        ;new line
  330.     push    h        ;save HL
  331.     lhld    linenum        ;get line number
  332.     call    phldc        ;print as decimal
  333.     pop    h        ;restore HL
  334.     mvi    a,' '        ;print <sp>
  335.     call    cout
  336.     jmp    print        ;print text
  337. ;
  338. ;  NXTLINE -- Advance to next line, check for EOF, and increment Line Number
  339. ;  LSKIP -- Advance to next line and check for EOF
  340. ;    Return with HL pting to first char of next line and Z Set if EOF
  341. ;
  342. nxtline:
  343.     push    h        ;increment line count
  344.     lhld    linenum        ;add 1
  345.     inx    h
  346.     shld    linenum
  347.     pop    h        ;fall thru to skipping
  348. lskip:
  349.     mov    a,m        ;get char
  350.     cpi    EOF        ;EOF?
  351.     rz
  352.     inx    h        ;pt to next
  353.     cpi    lf        ;line feed?
  354.     jnz    lskip        ;continue if not
  355.     mov    a,m        ;get first char of next line
  356.     cpi    EOF        ;check for EOF
  357.     ret
  358. ;
  359. ;  MCMD1 -- Check Menu Line, check for EOF, and increment Line Number
  360. ;    Return with HL pting to first char of next line and Z Set if EOF
  361. ;
  362. mcmd1:
  363.     mov    a,m        ;get char
  364.     cpi    EOF        ;EOF?
  365.     jz    mcmdx
  366.     inx    h        ;pt to next
  367.     cpi    VARFLAG        ;variable?
  368.     jz    mcmd2
  369.     cpi    lf        ;line feed?
  370.     jnz    mcmd1        ;continue if not
  371. mcmdx:
  372.     push    h        ;increment line count
  373.     lhld    linenum        ;add 1
  374.     inx    h
  375.     shld    linenum
  376.     pop    h        ;fall thru to skipping
  377.     mov    a,m        ;get first char of next line
  378.     cpi    EOF        ;check for EOF
  379.     ret
  380. ;
  381. ; Check Variable
  382. ;
  383. mcmd2:
  384.     mov    a,m        ;get char
  385.     ani    7fh        ;mask
  386.     call    caps        ;capitalize
  387.     inx    h        ;pt to next
  388.     cpi    VARFLAG        ;OK if double VARFLAG
  389.     jz    mcmd1
  390.     cpi    'D'        ;OK if D
  391.     jz    mcmd1
  392.     cpi    'U'        ;OK if U
  393.     jz    mcmd1
  394.     cpi    'F'        ;filename.typ?
  395.     jz    mcmd3
  396.     cpi    'N'        ;filename?
  397.     jz    mcmd3
  398.     cpi    'T'        ;filetype?
  399.     jz    mcmd3
  400.     cpi    'P'        ;pointed-to file?
  401.     jz    mcmd6
  402. ;
  403. ; Invalid Variable
  404. ;
  405.     dcx    h        ;pt to previous (bad char)
  406.     push    psw        ;save char
  407.     call    lprint
  408.     db    ' Variable Error (Not $, D, U, F, N, or T) - ',0
  409.     pop    psw        ;get char
  410.     call    cout        ;print it
  411.     call    newerr        ;increment error count
  412.     jmp    mcmd1
  413. ;
  414. ; Digit from 1 to 4 should follow
  415. ;
  416. mcmd3:
  417.     mov    a,m        ;get next char
  418.     inx    h        ;pt to next
  419.     ani    7fh        ;mask and cap
  420.     call    caps
  421.     cpi    '1'        ;must be from 1 to 4
  422.     jc    mcmd4
  423.     cpi    '5'
  424.     jc    mcmd1
  425. ;
  426. ; Invalid Digit
  427. ;
  428. mcmd4:
  429.     push    psw
  430.     call    lprint
  431.     db    ' Invalid Digit for F, N, or T Variable (not 1-4) - ',0
  432. mcmd5:
  433.     pop    psw
  434.     dcx    h        ;pt to invalid char
  435.     call    cout
  436.     call    newerr        ;increment error count
  437.     jmp    mcmd1
  438.  
  439. ;
  440. ; Check for Pointed to File
  441. ;
  442. mcmd6:
  443.     mov    a,m        ;get next char
  444.     inx    h        ;pt to next
  445.     ani    7fh        ;mask
  446.     call    caps
  447.     cpi    'F'
  448.     jz    mcmd1
  449.     cpi    'N'
  450.     jz    mcmd1
  451.     cpi    'T'
  452.     jz    mcmd1
  453.     push    psw        ;save char
  454.     call    lprint
  455.     db    ' Invalid Pointed-to File Option (not F, N, or T) - ',0
  456.     jmp    mcmd5        ;process error and back up ptr
  457.  
  458. ;
  459. ;  OPTCHK -- Check Line Pted to by HL for Valid GOPTION and MINDIC options
  460. ;    Do Not Affect HL
  461. ;    Print Error Message and Character if Invalid Option Found
  462. ;
  463. optchk:
  464.     push    h        ;save HL
  465.     push    b
  466.     inx    h        ;skip indicator
  467. optclp:
  468.     mov    a,m        ;get char
  469.     call    caps        ;capitalize
  470.     inx    h        ;pt to next
  471.     cpi    cr        ;EOL?
  472.     jz    optcdn
  473.     mov    b,a        ;char in B
  474.     cpi    XOPTION        ;only exit option allowed
  475.     jz    optclp
  476.     call    newerr        ;increment error count
  477.     call    lprint
  478.     db    ' Invalid Option: ',0
  479.     mov    a,b        ;get char
  480.     call    cout        ;print char
  481.     jmp    optclp
  482. optcdn:
  483.     pop    b
  484.     pop    h        ;restore ptr
  485.     ret
  486. ;
  487. ;  Increment Error Count
  488. ;
  489. newerr:
  490.     push    h    ;save HL
  491.     lhld    errors    ;increment error count
  492.     inx    h
  493.     shld    errors
  494.     pop    h    ;restore HL
  495.     ret
  496. ;
  497. ;  Check Line, especially looking for Menu Jump
  498. ;
  499. lcheck:
  500.     push    h    ;save ptr to first char
  501.     inx    h    ;pt to 2nd char
  502.     mov    a,m    ;get it
  503.     cpi    MCMD    ;menu jump?
  504.     jnz    lchk1
  505.     inx    h    ;pt to menu number
  506.     call    eval10    ;convert to binary in DE
  507.     mov    a,d    ;D must be 0
  508.     ora    a    ;check
  509.     jz    lchk0
  510. lchker:
  511.     call    newerr    ;increment error count
  512.     call    lprint
  513.     db    ' Menu Number Out of Range',0
  514.     jmp    lchk1
  515. lchk0:
  516.     lda    maxnum    ;get max menu number
  517.     cmp    e    ;check for range
  518.     jc    lchker
  519. lchk1:
  520.     pop    h    ;restore ptr
  521.     mov    a,m    ;get first char in line
  522.     ret
  523. ;
  524. ;  Skip HL over Blanks
  525. ;
  526. sblank:
  527.     mov    a,m    ;get char
  528.     inx    h    ;pt to next
  529.     cpi    ' '    ;blank?
  530.     jz    sblank    ;continue skipping
  531.     dcx    h    ;pt to non-blank
  532.     ret
  533.  
  534. ;
  535. ;  Buffers
  536. ;
  537. mnutyp:
  538.     db    'VMN'
  539. errors:
  540.     ds    2    ;error count
  541. linenum:
  542.     ds    2    ;current line number
  543. menunum:
  544.     ds    1    ;current menu number
  545. maxnum:
  546.     ds    1    ;max menu number
  547. gopt:
  548.     ds    1    ;global option flag
  549.  
  550.     end
  551.