home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / vol239 / z8e.mqc / Z8E.MAC
Encoding:
Text File  |  1986-02-10  |  173.6 KB  |  6,851 lines

  1.           .xlist
  2.  
  3.     title    *   *** Z8E - Z80 DEBUG MONITOR ***    *
  4.     subttl    (c) Copyright 1984 by Richard A. Surwilo  
  5.  
  6.     .Z80
  7.  
  8. rcv    equ    01
  9. txrdy    equ    04
  10. dcd    equ    08
  11.  
  12. iobyte    equ    03
  13.  
  14. maxbp    equ    16        ;Number    of Breakpoints Configured
  15.                 ;
  16. BS    equ    08H        ;ASCII     Backspace
  17. TAB    equ    09H        ;    Tab
  18. LF    equ    0AH        ;    Line Feed
  19. FORMF    equ    0CH        ;    Form Feed
  20. CR    equ    0DH        ;    Carriage Return
  21. ESC    equ    1BH        ;       Escape    
  22. CTLX    equ    'X' and    1FH    ;    Control    X - Delete Line
  23. CTLC    equ    'C' and    1FH    ;    Control    C - Warm Boot
  24. EOF    equ    'Z' and    1FH    ;    Control    Z - Logical EOF
  25. QUOTE    equ    27H        ;    QUOTE
  26. TILDE    equ    7EH        ;    Tilde
  27.  
  28. BDOS    equ    05
  29. CPMfcb    equ    5CH        ;CP/M Default FCB
  30.  
  31. nop    equ    000        ;Z80 Instructions
  32. jp    equ    0C3H
  33. rst38    equ    0FFH
  34.  
  35. iobuf    equ    80H        ;Disk read Buffer for Symbol loading
  36.  
  37.     page
  38.  
  39. ;******************************************************************************
  40. ;*
  41. ;*    NINT:      Initialization - Relocating Loader - Symbol Loader
  42. ;*
  43. ;*    INITIALIZATION:
  44. ;*        - Save system I    register
  45. ;*        - Determine Max Symbol Length Before Loading Symbol Table
  46. ;*                Permissable Values are 6 and 14 Which are Converted to Bit
  47. ;*          Masks by Bumping by One 
  48. ;*        - Set CP/M DMA Address to 80H
  49. ;*        - Check First Command Line Argument for (XX) Where XX is the
  50. ;*          the Number of Slots in the Symbol Table to Reserve.
  51. ;*        - Move First File Name Found in Command Line to Local Memory
  52. ;*          Since it Will Be Loaded Last.  At the End of Initialization
  53. ;*          (or Symbol Loading if Required) this File Name Will Be Loaded
  54. ;*          into the Keyboard Input Buffer and the File Will Be Loaded
  55. ;*          Just As If the User Had Entered the Info As a Z8E Command.
  56. ;*        - Move All Subsequent File Names in the    Command    Line Buffer to
  57. ;*          Local Input Buffer (INBF) in Low Memory, Where They Can
  58. è;*          Be Found by the Parse    Routine (PRSR).
  59. ;*
  60. ;*    RELOCATING LOADER:
  61. ;*        - Move Absolute    Memory Image of    Z8E to Top of TPA
  62. ;*        - Adjust all Addresses in Relocated Monitor to Reflect New
  63. ;*          Execution Area. This is Accomplished by Repeated Calls to
  64. ;*          ZLEN to Calculate Instruction    Lengths.
  65. ;*        - All Addresses    < the Absolute Value of    Z8EORG are Considered
  66. ;*          to Be    Absolute Values    and Are    NOT Modified.
  67. ;*        - Relocate All Address Pointers    in Command and Operand Jump
  68. ;*          Tables.
  69. ;*
  70. ;******************************************************************************
  71.  
  72.     ASEG
  73.  
  74.     global    case,column,init,row,rowb4?,mxycp
  75.     global    ttyi,ttyi00,ttyo,ttyq,maxlen,bdos,xycp
  76.  
  77.     ORG    100H
  78.  
  79.     jp    nint
  80.  
  81. mbannr:    defb    CR,LF
  82.     defm    'Z8E V1.0'
  83.     defb    CR,LF
  84.     defb    0
  85.  
  86. nint:
  87.     ld    sp,stack
  88.     ld    a,i        ;Save I Reg for User
  89.     ld    (ireg),a    ;
  90.     call    init
  91.     ld    de,mbannr    ;Dispense With Formalities
  92.     call    print
  93.                 ;Do Config Based On Max Length of Symbol Names
  94.                 ;                
  95.     ld    a,(maxlen)    ;Check Max Symbol Length
  96.     inc    a        ;Create Mask        
  97.     cp    15
  98.     ld    b,a        ;B - MAXLEN Mask - 15
  99.     ld    a,62        ;A - MAXLIN Disassembly Line Length (62)
  100.     ld    c,68        ;C - Column to Display First Byte of Memory
  101.                 ;    Window for J Command
  102.     ld    d,3        ;D - Bytes per Line of Memory Window Display
  103.     jp    z,nint00    ;Z - Max Symbol Length is 14
  104.  
  105.                 ;If Not 14 - Use Default Values
  106.     ld    b,7        ;B - MAXLEN Mask -  7
  107.     ld    a,30        ;A - MAXLIN Disassembly Line Length (30)
  108.     ld    c,56        ;C - Column to Display First Byte of Memory
  109.     ld    d,7        ;    Window for J Command
  110. nint00:    ld    (maxlin),a
  111.     ld    a,b
  112.     ld    (maxlen),a
  113.     ld    a,c
  114.     ld    (fwndow),a
  115.     ld    a,d
  116.     ld    (nlmask),a
  117.  
  118.                 ;Reset CP/M DMA Address for Those Instances
  119.                 ;in Which Z8E is Used to Debug Itself.
  120.                 ;Otherwise DMA Address is Left Where Z8E
  121.                 ;Stopped Loading Itself.
  122.                 ;
  123.     ld    de,80H
  124.     ld    c,26
  125.     call    BDOS
  126.     
  127.     ld    a,jp        ;Initialize Where L80 Fears to Tread
  128.     ld    (038h),a    ;Init Trap to Breakpoint Handler
  129.     ld    hl,5DH        ;Save Current Contents of Default FCB
  130.     ld    a,(hl)
  131.     cp    '('        ;Is First Char in FCB a Paren?
  132.     dec    hl        
  133.     jr    nz,nint25    ;Not Paren - NO User Symbol Table Requested
  134.     inc    hl        ;Point Back to Paren
  135.     ld    de,inbf        ;Start of Input Buffer Here in Low Memory
  136.     ld    b,15        ;Max Chars in FCB Following First Paren
  137. nint05:    inc    hl        ;Bump FCB Pointer
  138.     ld    (de),a        ;Move Char to Low Memory Keyboard Input Buffer
  139.                 ;so That PRSR Thinks This is Keyboard Input
  140.     inc    de        ;Bump Input Buffer Pointer 
  141.     ld    a,(hl)
  142.     cp    ')'        ;Look for Trailing Paren
  143.     jr    z,nint10
  144.     djnz    nint05        ;Examine entire FCB at 5CH Looking for Paren
  145.     ld    hl,CPMfcb    ;Trailing Paren NOT Found - This Must Be
  146.                 ;Kookie File Name
  147.     jr    nint25        ;Ignore
  148.                 
  149.                 ;Call IARG to Determine Amount of Space to 
  150.                 ;Allocate in User Symbol Table.  This Arg
  151.                 ;Must Be Enclosed in Parens and Appear After
  152.                 ;the First Arg in the Command Line.
  153.                 ;Since Opening and Closing Parens Were Found
  154.                 ;Add  A Pound Sign to Make This into Default 
  155.                 ;Decimal Number then Call XVAL to Evaluate.
  156.  
  157. nint10:    ex    de,hl        ;HL - Input Buffer Pointer
  158.     ld    (hl),'#'    ;Add Trailing Paren Before Calling IARG
  159.                 ;Who Will Evaluate Argument as if it Was
  160.                 ;Entered From Keyboard
  161.     inc    hl
  162.     ld    (hl),a        ;Restore Trailing Paren Following Pound Sign
  163.     inc    hl
  164.     ld    (hl),0        ;Add End of Line Null
  165.     call    iarg
  166.     ex    de,hl        ;DE - Evaluated Argument
  167.     ld    hl,CPMfcb
  168.     jr    nz,nint25    ;Arg Error - Ignore Input
  169.     ld    hl,81H        ;Start of Command Line Tail
  170. nint15:    ld    a,(hl)
  171.     ld    (hl),' '    ;Replace the Text which Appeared Between
  172.                 ;the Parens and the Parens Themselves with
  173.                 ;Spaces
  174.  
  175.     cp    ')'        ;Closing Paren Ends Search
  176.     jr    z,nint20
  177.     inc    hl        ;Point to Char Following Closing Paren
  178.     jr    nint15
  179. nint20:    ex    de,hl        ;Arg to HL for Mult Times MAXLEN Bytes per 
  180.                 ;Symbol Table Entry
  181.     add    hl,hl
  182.     add    hl,hl
  183.     add    hl,hl
  184.     ld    a,(maxlen)    ;8 or 16 Bytes per Symbol Table Entry?
  185.     cp    7
  186.     jp    z,nint22    ;Z - Must be 8
  187.     add    hl,hl
  188. nint22:    ex    de,hl    
  189.     ld    (usymbl),de    ;Save Number of Bytes to Reserve
  190.     ld    hl,6CH        ;Since User Symbol Table Arg Was Present Then
  191.                 ;Target File Must Be in Default FCB Number 2
  192.  
  193. nint25:    ld    de,zbuf        ;Local Buffer
  194.     ld    bc,16
  195.     ldir            ;Move FCB contents to local memory
  196.     ld    hl,80H        ;Command Line Buffer Address
  197.     ld    a,(hl)
  198.     and    a        ;Test for no Input
  199.     jr    z,nint55    ;No Input - Clear Symbol Table
  200.     ld    c,a        ;BC - Number of    Chars in Command Line Buffer
  201.     ld    (hl),b        ;Clear Byte Count
  202.     add    hl,bc        ;Point to Last Char in Buffer
  203.     inc    hl
  204.     ld    (hl),b        ;Set End of Line Null After Last Char
  205.     ld    hl,81H
  206. nint30:    ld    a,(hl)        ;Look for Start    of First File Name
  207.     and    a        ;Found the End of Line Null?
  208.     jr    z,nint55    ;Z - No    Files to Load
  209.     cp    ' '        ;Leading Space?
  210.     jr    nz,nint35    ;Not Space - Found Start of File Name
  211.     inc    hl
  212.     dec    c        ;Decrement Command Line    Byte Count
  213.     jr    nint30        ;Keep Looking for Start    of File    Name
  214. nint35:    ld    de,znmbuf    ;Save Name Here    For Later Display
  215. è    ld    (de),a        ;
  216.     inc    de
  217. nint40:    inc    hl        ;Find First Trailing Space
  218.     ld    a,(hl)
  219.     cp    ' '
  220.     jr    z,nint45    ;Found Space - Move Remainder of Buffer
  221.     ld    (de),a        ;Save File Name    Character for Display
  222.     inc    de
  223.     and    a        ;End of    Line?
  224.     jr    z,nint55    ;Z - Only One File Specified
  225.     dec    c
  226.     jr    nint40
  227. nint45:    ld    a,c        ;Check Byte Count
  228.     cp    inbfsz        ;Versus    Size of    Our Local Input    Buffer
  229.     jr    c,nint50    ;Carry - Size Is OK
  230.     ld    c,inbfsz    ;Only Move As Much As Will Fit
  231. nint50:    ld    de,inbf
  232.     ldir            ;Move Command Line to Local Memory
  233.     xor    a
  234.  
  235. nint55:    ld    hl,Z8Eorg    ;Clear Local Symbol Table to Nulls
  236.     ld    b,Z8E-Z8Eorg    ;Symbol    Table Size
  237. nint60:    ld    (hl),a        ;Nulls to Entire Local Symbol Table
  238.     inc    hl
  239.     djnz    nint60
  240.     ld    hl,(06)        ;Start of BDOS
  241.     ld    l,a        ;Init Stack Address to 256 Boundary
  242.     ld    bc,nmem        ;Monitor Size
  243.     and    a
  244.     sbc    hl,bc        ;HL - Starting Address of Z8E in Upper
  245.                 ;Memory
  246.     ld    (Z8Eb),hl    ;Monitor bias -    for relocation work
  247.     ld    de,(usymbl)
  248.     sbc    hl,de
  249.     ld    (ntpa),hl    ;End of    tpa - for Symbol loading
  250.     ld    a,d        ;Check for NO user Symbol Table
  251.     or    e
  252.     jr    z,nint75    ;No Table - no clearing required
  253. nint70:    ld    (hl),0        ;Fill user Symbol Table with nulls
  254.     inc    hl
  255.     dec    de
  256.     ld    a,d
  257.     or    e
  258.     jr    nz,nint70
  259. nint75:    ex    de,hl        ;HL - start of Z8E in hi memory
  260.     
  261.     ld    hl,bphn-Z8Eorg    ;Entry Point to    Breakpoint handler
  262.     add    hl,de
  263.     ld    (039h),hl    ;Init rst 038h trap location
  264.     ld    hl,Z8Eorg
  265.     ldir            ;Z8E NOW IN HI MEMORY - RELOCATE ADDRESSES
  266.     ld    hl,(Z8Eb)    ;Recover hi memory starting Address
  267.     ld    de,Z8Ecmd-Z8Eorg
  268.     add    hl,de        ;First Instruction to relocate
  269.     ex    de,hl
  270. nint80:    call    zlen00        ;Calculate Instruction length
  271.     ld    h,d
  272.     ld    l,e        ;DE - Current Instruction   HL - ditto
  273.     ld    b,0
  274.     add    hl,bc
  275.     ex    de,hl        ;DE - Next Address to relocate
  276.     ld    a,c        ;Test length
  277.     sub    3
  278.     jr    c,nint90    ;One or    two byters are non-Relocatable
  279.     ld    c,a
  280.     add    hl,bc        ;Bump if four byter
  281.     ld    a,(hl)
  282.     ld    hl,Z80r        ;Table of Relocatable Instructions
  283. è    ld    c,Z80rl        ;Size
  284.     cpir
  285.     jr    nz,nint90    ;NZ - not Relocatable
  286.     ex    de,hl
  287.     dec    hl        ;Point to Address Byte requiring bias
  288.     ld    a,(hl)
  289.     sub    Z8Eorg shr 8    ;Test for absolute Address < Z8Eorg
  290.     jr    c,nint85    ;Absolute - no relocation needed
  291.     ld    b,a
  292.     ld    a,(Z8Ebh)    ;HI Order Byte of Address bias
  293.     add    a,b        ;Plus upper Byte of operand Address
  294.     ld    (hl),a        ;Set relocated Address
  295. nint85:    inc    hl
  296.     ex    de,hl        ;DE - Next Address to test
  297. nint90:    ld    bc,nrel-Z8Eorg    ;End of    Relocatable portion of monitor
  298.     ld    hl,(Z8Eb)
  299.     add    hl,bc        ;HL - absolute End of relocated    monitor
  300.     and    a
  301.     sbc    hl,de        ;Reached End?
  302.     jr    nc,nint80    ;Nc - more
  303.     ld    de,ncmd+zopjtl    ;Size -    command    and operand jump Tables
  304.     ld    hl,(Z8Eb)    ;Base of relocated monitor
  305.     ld    a,-(Z8Eorg/256)
  306.     add    a,h        ;Relocation bias Byte to add to    ptrs
  307.     ld    d,a        ;D - bias to add  e - count
  308.     add    hl,bc        ;First Point to    operand    names
  309.     ld    bc,zopjtb    ;Add length of operand Name Table
  310.     add    hl,bc        ;Point to First    entry in jump Table
  311. nint95:    inc    hl
  312.     ld    a,(hl)        ;Hi Byte jump Table entry
  313.     add    a,d        ;Plus bias
  314.     ld    (hl),a        ;Replace in Table
  315.     inc    hl
  316.     dec    e
  317.     jr    nz,nint95    ;NZ - more Table entries to relocate
  318. ;******************************************************************************
  319. ;*
  320. ;*    ZSYM:    Symbol Table build from    .SYM and .PRN files
  321. ;*
  322. ;*        IFCB called to parse the Input Buffer (INBF) in low memory.
  323. ;*        INBF contains the command line tail which BDOS passed to us at
  324. ;*        80H and which we have since moved to INBF (so that PRSR thinks
  325. ;*        its just keyboard Input).
  326. ;*
  327. ;*        All valid File names are opened for Input.
  328. ;*
  329. ;*        If the File Name terminates with a comma then we assume    the
  330. ;*        user is    specifying a bias which    is to be added to every    Symbol
  331. ;*        loaded from the    File.
  332. ;*
  333. ;*        ZSYM    general    File handiling
  334. ;*        .SYM    Load L80 .SYM File
  335. ;*        .PRN    Load M80 .PRN File
  336. ;*
  337. ;*        Symbol Table always begins on an 8 byte    boundary.  This    makes
  338. ;*        life very easy since the Symbol    Name is    Found in bytes 0 - 5
  339. ;*        of a Symbol Table entry    and the    Address    (LO Order Byte First)
  340. è;*        is contained in    bytes 6    and 7.
  341. ;*
  342. ;******************************************************************************
  343.  
  344. zsym:    call    ifcb        ;Initialize FCB
  345.     jp    nz,zstx        ;NZ - error
  346.     ld    de,mldg        ;Display LOADING message
  347.     call    nprint        ;Output    crlf - then print
  348.     ld    de,prsbf
  349.     call    print        ;Display File Name
  350.     ld    a,c         ;IFCB returns delimeter in C reg
  351.     ld    (delim),a    ;Temp Save delimiter so we know if a bias has
  352.                 ;Been specified
  353.     call    crlf
  354.     call    iopn        ;Try to    open File
  355.     dec    a        ;
  356.     jp    m,zfnf        ;M - File not Found
  357.     ld    a,(delim)    ;Check delimeter
  358.     cp    ','
  359.     ld    hl,00
  360.     jr    nz,zsym10    ;NZ - no comma means no    Symbol bias
  361.     call    prsr        ;Let PRSR extract Symbol bias
  362.     jp    nz,zoff        ;Parse error - use bias    of 0000
  363.     ld    (delim),a    ;Save delimeter    which followed bias
  364.     ld    de,prsbf
  365.     ld    hl,00
  366.     call    xval        ;Evaluate bias
  367.     jr    z,zsym10    ;Z - numeric bias
  368.  
  369.     ld    hl,(ntpa)    ;Check bias specified by Symbol    Name
  370.     ld    a,(maxlen)
  371.     cpl
  372.     ld    e,a
  373.     ld    d,0FFH        ;Lower End of TPA by Amount Equal to 
  374.                 ;the Value of MAXLEN Negated to Insert
  375.                 ;Jump to BDOS
  376.     add    hl,de
  377.     ld    a,(case)
  378.     and    a
  379.     jp    z,zsym05    ;Z - already upper case
  380.     ld    de,prsbf
  381. zsym00:    ld    a,(de)
  382.     and    a
  383.     jp    z,zsym05    ;Z - End of label Symbol Name
  384.     call    ilcs        ;Change to LOWER case        
  385.     ld    (de),a
  386.     inc    de        ;Store Converted Character
  387.     jp    zsym00
  388. zsym05:    ld    de,prsbf    
  389.     call    fsym00        ;Search    Symbol Table
  390.     jp    nz,zoff        ;NZ - not Found
  391.     ld    a,(maxlen)
  392.     or    l
  393.     ld    l,a
  394.     ld    a,(hl)        ;Fetch HI Order    Address    associated
  395.                 ;With Symbol
  396.     dec    hl             
  397.     ld    l,(hl)         
  398.     ld    h,a        ;HL - Symbol value
  399. zsym10:    ld    (bias),hl    ;Bias to add to    each Symbol Address
  400.     ld    hl,00          
  401.     ld    a,(fcbtyp)     
  402.     ld    bc,(ntpa)    ;Current End of TPA
  403.     cp    'S'        ;Is this a .SYM    File?
  404.     jp    z,.sym        ;.SYM File loaded differently than .PRN
  405.     cp    'L'
  406.     jp    nz,.prn
  407.     ld    de,.LST??    ;Look for .LST String ID string      
  408.     ld    (pstrng),de
  409.     call    fstrng
  410.  
  411.  
  412.  
  413.  
  414.  
  415.  
  416. .sym:    ld    a,(maxlen)    ;Lower TPA Address by MAXLEN
  417.     cpl
  418.     and    c        ;For storing Next Symbol and Address
  419.     ld    c,a
  420.     ld    a,(maxlen)
  421.     cpl            ;This is Negate Plus One
  422.     add    a,c
  423.     ld    c,a
  424.     jp    c,.sym00    ;Treat Carry as Complement of Subtraction
  425.     dec    b
  426. .sym00:
  427.     ex    de,hl
  428.     ld    hl,stack+8    ;Check for monster Symbol Table    ready to eat us
  429.     and    a
  430.     sbc    hl,bc
  431.     jp    nc,zmem        ;End Symbol load before    stack is clobbered
  432.     ex    de,hl
  433.     ld    a,(maxlen)
  434.     dec    a
  435.     ld    d,a        ;
  436.     xor    a
  437. .sym10:    ld    (bc),a        ;Init Symbol Table Entry to Nulls
  438.     inc    bc
  439.     dec    d
  440.     jr    nz,.sym10
  441.     ld    e,d        ;Clear DE for hex00
  442.     xor    a
  443.     ld    (star),a    ;Clear ** Found Flag
  444.     ld    a,4        ;Convert four bytes of Address
  445.     ld    (bytes),a
  446. .sym20:    call    nchr        ;Fetch Next Character in File
  447.     cp    EOF
  448.     jp    z,.eof
  449.     cp    '0'
  450.     jr    nc,.sym25    ;C -  Must Be Control Character or Space
  451.                 ;NC - Possible First Char of Address
  452.     cp    LF
  453.     jp    z,.sym21    ;     
  454.     cp    '*'        ;Space Means ** In SLR .SYM File
  455.     jp    nz,.sym20
  456.     ld    (star),a
  457.     jp    .sym25
  458.     
  459. .sym21:
  460.     call    nchr        ;Fetch Char Following LF    
  461.     cp    CR
  462.     jp    z,.sym22    ;Z - Consecutive CRLF's Means End of Page
  463.     cp    '0'
  464.     jp    nc,.sym25    ;NC - Symbol Address On New Line
  465.     cp    EOF
  466.     jp      z,.eof
  467.     cp    '*'        ;** ?
  468.     jp    nz,.sym20
  469.     ld    (star),a
  470.     jp    .sym25
  471.     
  472. .sym22:
  473.     ld    a,(fcbtyp)
  474.     cp    'L'
  475.     jp    z,.sym23
  476.     cp    'P'        ;Macro 80 V3.4
  477.     jp    nz,.sym20    
  478. .sym23:
  479.     ld    de,.LST??    ;Bypass Inter-Page Verbiage
  480.     ld    (pstrng),de
  481.     call    fstrng        ;
  482.     cp    EOF
  483.     jp    z,.eof
  484.  
  485.     call    nchr
  486.     cp    EOF
  487.     jp    z,.eof
  488.     
  489.  
  490. .sym25:    call    hex00        ;Have First Char of Address - convert
  491.     call    totsym        ;Bump total of Symbols loaded
  492.     ld    a,(fcbtyp)    ;Is This a .SYM File
  493.     cp    'S'
  494.     call    nz,nchr        ;Address/Symbol Separator for .LST File
  495.     ld    a,(maxlen)
  496.     dec    a
  497.     ld    (bytes),a
  498. .sym30:    call    nchr        ;Read Symbol Name Char
  499.     cp    TAB
  500.     jp    z,.sym45
  501.     cp    CR
  502.     jp    z,.sym45
  503.     cp    ' '
  504.     jp    z,.sym45
  505.     ld    (bc),a
  506.         ld    a,(case)        ;Check user requested case
  507.     and    a
  508.     jr    z,.sym35    ;Z - Upper Case    Requested by User
  509.     ld    a,(bc)        ;Recover Char
  510.     cp    'A'
  511.     jr    c,.sym35    ;C - Must Be Number
  512.     cp    'Z'+1
  513.     jp    nc,.sym35
  514.     or    20h
  515.     ld    (bc),a          ;Restore Symbol Name Char as lower case
  516. .sym35:    inc    bc              
  517.     ld    a,(bytes)
  518.     dec    a
  519.     ld    (bytes),a
  520.     jr    nz,.sym30
  521. .sym40:    call    nchr
  522.     cp    21H
  523.     jp    nc,.sym40
  524. .sym45:    ld    a,(star)    ;Check If This Was ** In Address Field
  525.     and    a
  526.     jp    nz,.sym50  
  527.     ld    a,(relchr)    ;Check For External Symbol
  528.     cp    ' '        ;
  529.     jp    z,.sym        ;Space Means Absolute
  530.     cp    QUOTE    
  531.     jp    z,.sym        ;Quote Means Relocatable
  532. .sym50:    ld    a,(maxlen)
  533.     or    c
  534.     ld    c,a
  535.     inc    bc        ;Point BC To Next Higher Symbol Block So
  536.                 ;That Rewinding By MAXLEN Bytes Will Actually
  537.                 ;Overlay This Symbol. This Ensures That No
  538.                 ;External Symbols Are Not Kept in Table. 
  539.     
  540.     jp    .sym
  541.  
  542.  
  543. .prn:    ld    de,.PRN??
  544.     ld    (pstrng),de
  545.     call    fstrng
  546.     cp    EOF
  547.     jp    nz,.prn00
  548.  
  549.     ld    de,msymnf       ;Display Symbol Table Not Found msg   
  550.     call    print
  551.     jp    .eof50          ;Check for more Symbol files to load
  552.  
  553. .prn00:
  554.     ld    bc,(ntpa)       ;BC - Current End of the TPA
  555.     dec    bc              ;This Points us into the Next Lower 
  556.                                 ;Symbol Table block
  557.                 ;This is First Char of Symbol Table
  558.     xor    a               ;        
  559.     or    l        ;Get Next Byte from File but Without Bumping
  560.                 ;Pointer Allowing Us to Reread Same Char in
  561.                 ;Case It is Last Character in Buffer    
  562.  
  563.     call    z,read        ;Only do True Read if LAST Character Was Last
  564.                 ;in Buffer    
  565.     ld    a,(hl)
  566.     cp    '0'
  567.     jp    c,.pr325    ;Non-Numeric: Macro-80 V3.44    
  568.                 
  569.     cp    '9'+1
  570.     jp    c,.pr4        ;Numeric:     Macro-80 V3.4
  571.  
  572.  
  573.                 ;Macro-80 V3.4 Dec 1980 Symbol Table Load    
  574.                 
  575. .pr325:    ld    a,(maxlen)      ;
  576.     cpl
  577.     and    c               ;Now rewind within 8 Byte block to Point to
  578.                 ;First Byte                               
  579.     ld    c,a
  580.  
  581.         ex    de,hl           ;DE - Save File Buffer Pointer 
  582. è    ld    hl,stack+16     ;Check for encroaching Symbol Table
  583.     sbc    hl,bc           ;Versus Current Symbol Table Address
  584.     jp    nc,zmem         ;NC - out of memory
  585.     ex    de,hl           ;Return File Buffer Pointer
  586.     ld    a,(maxlen)
  587.     ld    d,a
  588.     dec    d        ;D - Symbol Name length
  589.     xor    a              
  590.     ld    e,a
  591. .pr330:    ld    (bc),a          ;Pre-clear Name portion of Symbol Table to 
  592.                                 ;Nulls
  593.     inc    bc
  594.     dec    d               ;Now Any Name Less Than MAXLEN Chars in Length
  595.     jp    nz,.pr330       ;is Terminated with a Null
  596.     ld    a,(maxlen)
  597.     cpl
  598.     and    c
  599.     ld    c,a
  600. .pr335:    call    nchr            ;Next Char from File Buffer
  601.     cp    21H
  602.     jp    nc,.pr351    ;NC - This is First Character of Symbol Name
  603.     cp    EOF        ;End of    File?
  604.     jp    z,.eof
  605.     cp    LF        ;Line feed?
  606.     jp    nz,.pr335
  607. .pr340:    call    nchr        ;Get Character Following Line Feed
  608.     cp    CR
  609.     jp    z,.pr342
  610.     cp    FORMF        ;Form feed?
  611.     jp    nz,.pr351
  612. .pr342:    ld    e,3        ;Symbols resume    three lines hence following
  613.                                 ;A form feed - so count linefeeds
  614.     cp    CR        ;Did We Find CR of FORMF?
  615.     jp    nz,.pr345    ;NZ - FORMF
  616.     dec    e        ;Just Look for Two LF's
  617. .pr345:    call    nchr
  618.     cp    LF
  619.     jp    nz,.pr345       ;Loop til three Found
  620.     dec    e
  621.     jp    nz,.pr345
  622.  
  623.     xor    a               ;        
  624.     or    l        ;Get Next Byte from File but Without Bumping
  625.                 ;Pointer Allowing Us to Reread Same Char in
  626.                 ;Case It is Last Character in Buffer    
  627.  
  628.     call    z,read        ;Only do True Read if LAST Character Was Last
  629.                 ;in Buffer    
  630.     ld    a,(hl)
  631.     cp    CR        ;Four CRLF's is EOF
  632.     jp    z,.eof
  633.  
  634. .pr350:    call    nchr            ;Next Char from File
  635.     cp    EOF
  636.     jp    z,.eof
  637.     cp    TAB
  638.     jp    z,.pr355
  639. .pr351:    ld    (bc),a        ;Move Character    of Symbol Name
  640.     ld    a,(case)        ;Check user requested case
  641.     cp    'a'
  642.     jr    c,.pr352        ;C - user wants upper case
  643.     ld    a,(bc)          ;Get Char back from Symbol Table
  644.     cp    'A'
  645.     jr    c,.pr352        ;Must be numeric - no case here
  646.     cp    'Z'+1
  647.     jr    nc,.pr352
  648.     add    a,20h
  649.     ld    (bc),a          ;Replace Char with lower case equivalent
  650. .pr352:    inc    bc
  651.     jp    .pr350
  652.  
  653. .pr355:    ld    a,4
  654.     ld    (bytes),a
  655. .pr357:    call    nchr
  656.     cp    ' '
  657.     jp    z,.pr357
  658.  
  659.     call    hex00           ;Now read the Next four Characters from the
  660.                                 ;File and convert then to a hex Address -
  661.                                 ;Store in Symbol Table entry
  662.  
  663.  
  664.     ld    a,(relchr)      ;Recover Char Which Followed Address
  665.  
  666.     cp    ' '             ;This Char followed Address
  667.     jr    z,.pr370        ;Microsoft Absolute Address 
  668.     cp    QUOTE           ;Relocatable Address?
  669.     jp    nz,.pr325
  670.                                 ;By not rewinding the Symbol Table Pointer
  671.                                 ;the next Symbol will overlay this one.  
  672.  
  673. .pr370:    dec    bc
  674.     call    totsym
  675.  
  676.     jp    .pr325
  677.  
  678.  
  679.                 ;Macro-80 V3.44 Symbol Loading Routine
  680.                 
  681. .pr4:    ld    a,(maxlen)    ;Lower TPA Address by MAXLEN
  682.     cpl
  683.     and    c        ;For storing Next Symbol and Address
  684.     ld    c,a
  685.     ex    de,hl
  686.     ld    hl,stack+8    ;Check for Monster Symbol Table    
  687.     and    a
  688.     sbc    hl,bc
  689.     jp    nc,zmem        ;End Symbol Load Before    Stack is Clobbered
  690.     ex    de,hl
  691.     ld    a,(maxlen)
  692.     dec    a        ;Pre-Clear Symbol Table Entry with Nulls
  693.     ld    d,a        ;
  694.     xor    a
  695. .pr410:    ld    (bc),a        ;For Length Equal to MAXLEN
  696.     inc    bc
  697.     dec    d
  698.     jr    nz,.pr410
  699.     ld    e,d        ;Clear DE for HEX00
  700.     ld    a,4        ;Convert Four Bytes of Address
  701.     ld    (bytes),a
  702. .pr420:    call    nchr        ;Fetch Next Character in File
  703.     cp    EOF
  704.     jp    z,.eof
  705.     cp    '0'
  706.     jr    nc,.pr425    ;NC - Address Digit
  707.     cp    LF
  708.     jp    nz,.pr420    ;NZ - Leading Space or CR
  709.  
  710.  
  711.     call    nchr        ;Check Character Following LF
  712.     cp    CR
  713.     jp    z,.eof        ;Blank Line is EOF
  714.  
  715.     cp    FORMF        ;Form Feed?
  716.     jp    nz,.pr425    ;No - First Character of Next Address
  717.  
  718.     ld    e,3        ;Must be Form Feed
  719. .pr421:    call    nchr
  720.     cp    LF        ;Three LF's Follow Form Feed Before Symbols
  721.                 ;Resume on Next Page
  722.     jp    nz,.pr421
  723.     dec    e
  724.     jp    nz,.pr421
  725.  
  726.     call    nchr
  727.     cp    EOF
  728.     jp    z,.eof
  729.  
  730. .pr425:    
  731.     call    hex00        ;Have First Char of Address - Convert
  732.  
  733.     call    nchr        ;Eat Address/Symbol separator
  734.  
  735.     ld    a,(maxlen)
  736.     dec    a
  737.     ld    (bytes),a    ;Max Chars to Store in Symbol Table
  738.  
  739.  
  740. .pr430:    call    nchr        ;Read Symbol Name Char
  741.     cp    21H        
  742.     jp    c,.pr440    ;Found Separator
  743.     ld    (bc),a
  744.         ld    a,(case)        ;Check user requested case
  745.     and    a
  746.     jr    c,.pr435    ;C - Upper Case    Requested by User
  747.     ld    a,(bc)        ;Recover Char
  748.     cp    'A'
  749.     jr    c,.pr435    ;C - Must Be Number
  750.     cp    'Z'+1
  751.     jr    nc,.pr435
  752.     or    20h
  753.     ld    (bc),a          ;Restore Symbol Name Char as lower case
  754. .pr435:    inc    bc              ;Bump Symbol Table Pointer
  755.     ld    a,(bytes)    ;Character Counter
  756.     dec    a
  757.     ld    (bytes),a
  758.     jp    nz,.pr430    ;Not Max Length
  759.  
  760.                 
  761. .pr438:    call    nchr        ;Eat Chars Until Next Address Found
  762.     cp    EOF        
  763.     jp    z,.eof
  764.     cp    ' '        ;Found Symbol/Address
  765.     jp    nz,.pr438
  766.  
  767.  
  768. .pr440:    ld    a,(maxlen)
  769.     cpl
  770.     and    c
  771.     ld    c,a
  772.  
  773.     ld    a,(relchr)      ;Recover Char Which Followed Address
  774.     cp    ' '             ;This Char followed Address
  775.     jr    z,.pr450        ;Microsoft absolute Address 
  776.     cp    QUOTE           ;Relocatable Address?
  777.     jp    nz,.pr4            ;NZ - must be  EXTERNAL Symbol. We don't
  778.                                 ;Actually load them or count them in total.
  779.                                 ;By not rewinding the Symbol Table Pointer
  780.                                 ;the next Symbol will overlay this one.  
  781.  
  782. .pr450:    dec    bc
  783.     call    totsym
  784.     jp    .pr4
  785.  
  786.  
  787.  
  788.  
  789. .eof:                           ;We always pre decrement the Symbol Table
  790.                                 ;Pointer in anticipation of storing the Next
  791.                                 ;Symbol. Now that we hit the End of a Symbol
  792.                                 ;Table we must adjust the Pointer in 
  793.                                 ;Preparation for loading the Symbols from the
  794.                                 ;Next File (if there is one).
  795.         ld    a,(maxlen)      ;
  796.     ld    l,a
  797.     ld    h,0
  798.     inc    l
  799.     add    hl,bc           ;Point to Last loaded Symbol
  800.     ld    b,h
  801.     ld    c,l             ;BC - spare copy
  802.     cpl
  803.     and    c
  804.     ld    c,a
  805.     ld    (ntpa),bc       ;Save Current End of TPA Address
  806.         ld    a,(nsymhi)      ;HI Order Number of Symbols loaded (BCD)
  807.     call    hexc            ;Convert to ASCII  
  808.     ld    h,a             ;Returned in A - move to H (other digit in L)
  809.     ld    (mhex),hl       ;Store in message
  810.     ld    a,(nsymlo)
  811.     call    hexc            ;Convert LO Order
  812.     ld    h,a
  813.     ld    (mhex+2),hl
  814.     ld    de,msym..       ;Display Number of Symbols Loaded message
  815.     ld    c,9
  816.     call    BDOS
  817.     ld    de,mhex         ;Now look thru ASCII Number of Symbols to 
  818.                                 ;Strip leading zeros
  819.     ld    b,3
  820. .eof10:    ld    a,(de)          
  821.     cp    '0'
  822.     jr    nz,.eof20       ;NZ - Found First non-zero
  823.     inc    de
  824.     djnz    .eof10          ;If First three Chars zero - fall thru and
  825.                                 ;Print the fourth regardless
  826. .eof20: ld      c,09
  827.     call    BDOS            ;Print the Number as string ending with $
  828.     call    crlf
  829.     ld    hl,(tsym)       ;Now add in BCD total for this File to BCD
  830.                                 ;Total for all files
  831.     ld    de,(nsym)       ;TSYM - total for all files
  832.                                 ;NSYM - total for this File
  833.     ld    a,h
  834.     add    a,d
  835.     daa
  836.     ld    h,a
  837.     ld    a,l
  838.     adc    a,e
  839.     daa
  840.     ld    l,a
  841.     ld    (tsym),hl
  842.     ld      hl,00           ;Clear out total for Next File
  843.     ld    (nsym),hl
  844. è    ld    hl,(Z8Eb)       ;
  845.     ld    de,symflg-Z8Eorg
  846.     add    hl,de           ;HL - Pointer to Symbol flag in hi memory
  847.     xor    a               
  848.     ld    (hl),a        ;zero -    Symbol Table present
  849.     ld    (symflg),a      ;Also set flag in lo memory where we are
  850.                                 ;Currently so that FSYM knows theres a Symbol
  851.                                 ;Table to search thru if the user specified a
  852.                                 ;Symbol Name bias as part of the command line
  853.  
  854. .eof50:    ld    a,(delim)       ;Check command line delimter
  855.     and    a               ;Test for End of line null
  856.     jp    nz,zsym         ;NZ - not null means more files
  857.  
  858.  
  859.  
  860.                     
  861. load:    ld    hl,(ntpa)    ;Current End of    memory
  862.     ld    a,(symflg)    ;Check for Symbol Table
  863.     and    a
  864.     jr    nz,load00    ;NZ - no Symbol    Table
  865.     ld    d,a
  866.     ld    a,(maxlen)
  867.     ld    e,a        ;DE - Length of a Symbol Table Block
  868.     inc    e
  869.     sbc    hl,de        ;Compensate for    pre - increment    of ptr
  870. load00:    ld    de,(06)        ;DE - real entry Point to BDOS
  871.     ld    (06),hl        ;Point to our origin in    hi memory
  872.     ld    (hl),jp        ;Init jump to BDOS at start of Z8E
  873.     inc    hl
  874.     ld    (hl),e        ;
  875.     inc    hl
  876.     ld    (hl),d
  877.     ld    e,0        ;DE - old start of BDOS Address in also our 
  878.                                 ;Ending Address
  879.     ld    hl,(Z8Eb)       ;Load out starting Address in hi memory
  880.     ld    bc,Z8E-Z8Eorg   ;Fetch the Number of bytes between Z8E's base
  881.                                 ;Addres≤ and the entry Point of the command    
  882.                                 ;Processo≥á - internal Symbol Table size
  883.  
  884.     add    hl,bc
  885.     ld    b,h
  886.     ld    c,l        ;Bc - relocated    Z8E Address
  887.     ex    de,hl           ;DE - entry Point Z8E   HL - old start of BDOS
  888.     dec    hl              ;HL - Last Byte in our memory
  889.     ld    (hl),b          ;Now we "rom" our entry Point onto the top of
  890.                                 ;The stack so that all commands can return to
  891.                                 ;The command processor via a simple RET.
  892.     dec    hl
  893.     ld    (hl),c        ;Z8E (monitor entry Point) on stack
  894.     ld    sp,hl           ;Now set Current stack to just below our  
  895.                                 ;Return Address
  896.     ex    de,hl           ;HL - relocated Address Z8E
  897.     inc    hl
  898.     inc    hl              ;HL - Points to LD  SP,0000 Instruction at the
  899.                                 ;Start of the Command Processor. Replace 0000
  900.     ld    (hl),e          ;Set real stack Address
  901.     inc    hl
  902.     ld    (hl),d
  903.     ld    hl,(Z8Eb)    ;Base of relocated Code
  904.     ld    de,FCB-Z8Eorg    ;Relative offset from start of monitor
  905.     add    hl,de
  906.     ex    de,hl        ;DE - FCB Address in relocated monitor in hi
  907.                                 ;Memory
  908.     ld    hl,zbuf        ;
  909.     ld    bc,16
  910.     ldir            ;Init FCB with Saved File Name
  911.     ld    de,mZ8Eld    ;Print memory space occupied by    Z8E
  912.     call    print
  913.     ld    hl,(Z8Eb)       ;Display our base Address in upper memory
  914.     call    outadr
  915.     ld    a,'-'           
  916.     call    ttyo
  917.     call    space
  918.     call    space
  919.     ld    hl,(06)         ;This Points to the new jump to BDOS
  920.     inc    hl              
  921.     ld    e,(hl)          ;DE - old start of BDOS Address
  922.     inc    hl
  923.     ld    d,(hl)
  924.     ex    de,hl
  925.     ld    l,0             ;256 Byte boundary to bypass CP/M serial no.
  926.     call    outadr
  927.  
  928.     ld    a,(symflg)      ;Test for presence of Symbol Table
  929.     and    a
  930.     jr    nz,load40       ;NZ - no Table
  931.     ld    de,msymld       ;Display starting Address of Symbol Table msg
  932.     call    print
  933.     ld    hl,(06)         ;Vector to BDOS is start of Symbol Table
  934.     call    outadr
  935.     ld    a,'-'
  936.     call    ttyo
  937.     call    space
  938.     call    space
  939.     ld    hl,(Z8Eb)       ;Start of internal Symbol Table is End of 
  940.                                 ;Symbol Table built from files
  941.     dec    hl
  942.     call    outadr
  943.  
  944. è    ld    a,(tsymhi)      ;Total Number of Symbols from all files (BCD)
  945.     call    hexc            ;Convert to ASCII
  946.     ld    h,a             ;Move HI Order ASCII digit to H
  947.     ld    (mhex),hl       ;Store double ASCII digit
  948.     ld    a,(tsymlo)
  949.     call    hexc            ;Convert LO Order
  950.     ld    h,a
  951.     ld    (mhex+2),hl     ;Save in string
  952.     ld    de,tsym..       ;Total Symbols msg
  953.     ld    c,9
  954.     call    BDOS
  955.     ld    de,mhex         ;Address of ASCII digits
  956.     ld    b,3             ;Check for leading zeros
  957. load20:    ld    a,(de)          
  958.     cp    '0'
  959.     jr    nz,load30       ;NZ - Found First nz in string
  960.     inc    de
  961.     djnz    load20          ;Check First three digits then fall thru and
  962.                                 ;Print fourth regardless
  963. load30:    ld    c,09
  964.     call    BDOS
  965.  
  966. load40:    ld    hl,(06)
  967.     dec    hl              ;HL - Address of new TPA
  968.     ld    de,mnvmem       ;Display Address as Memory AvailTable
  969.     call    print
  970.     call    outadr
  971.     call    crlf
  972.     ld    (hl),0          ;Now store two zeros at the top of the TPA and
  973.                                 ;Set stack Pointer to this very same Address.
  974.                                 ;This allows users to do a warm boot via RET 
  975.                                 ;In the same way as if they had been loaded by
  976.                                 ;CP/M.
  977.     dec    hl
  978.     ld    (hl),0
  979.     ld    bc,(Z8Eb)       ;Our relocated Address in hi memory 
  980.     ex    de,hl           ;DE - Last Available Location in TPA
  981.     ld    hl,spreg-Z8Eorg ;Address (relative to the start of Z8E) where
  982.                                 ;We store the user stack Pointer Address
  983.     add    hl,bc           ;HL - Pointer to 
  984.     ld    (hl),e          ;Save user stack in SPREG in hi memory 
  985.     inc    hl
  986.     ld    (hl),d
  987.     ld    hl,Z8E-Z8Eorg   
  988.     ld    a,(zbufnm)    ;First Char of File Name
  989.     cp    ' '             ;Do we have a File to load?
  990.     jr    z,load50        ;Z - no 
  991.     ld    de,mldg         ;Display Loading msg and target File Name
  992.     call    nprint
  993.     ld    de,znmbuf
  994.     call    print           
  995.                                 ;Enter the monitor in hi memory at entry
  996.                                 ;Point ILDR10 
  997.         
  998.     ld    hl,ildr10-Z8Eorg
  999.     ld    bc,(Z8Eb)
  1000. load50:    add    hl,bc           ;HL - actual Address of ILDR10 in hi memory
  1001.     ex    de,hl           ;Now clear out the Buffer at 80H so the user
  1002.                                 ;Program doesn't mistakenly think that our
  1003.                                 ;Command line tail is really his.
  1004.     ld    hl,iobuf
  1005.     ld    (hl),0          ;Set Number of Chars zero (80H)
  1006.     inc    hl              ;
  1007.     ld    b,127           ;Clear until start of TPA
  1008. load60:    ld    (hl),' '
  1009.     inc    hl
  1010.     djnz    load60
  1011.     ex    de,hl           ;ILDR10 Address back to HL
  1012.     jp    (hl)            ;HI-HO, HI-HO to the loader we must go 
  1013.  
  1014.  
  1015.  
  1016.     page
  1017.                                 ;Thi≤ routinσ read≤ onσ Char froφ thσ disδ I/╧ 
  1018.                                 ;Buffe≥ returninτ i⌠ iε A« Upoε entr∙ wσ checδ
  1019. áááááááááááááááááááááááááááááááá;Thσ LO Order Buffer Pointer - 0 means wσ hi⌠ 
  1020.                                 ;Thσá 25╢ boundar∙ (End oµ Buffer⌐ anΣ ßá reaΣ
  1021.                                 ;I≤ needed« 
  1022.                                 ;
  1023. nchr:    xor    a               ;        
  1024.     or    l
  1025.     call    z,read
  1026.     ld    a,(hl)
  1027.     inc    hl
  1028.     ret
  1029.  
  1030. read:    push    bc
  1031.     push    de
  1032.     ld    de,FCB
  1033.     ld    c,20            ;Sequential File read
  1034.     call    BDOS
  1035.     and    a               ;Test for error
  1036.     ld    hl,iobuf        ;Assume OK - init I/O Buffer Address
  1037.     pop    de
  1038.     pop    bc
  1039.     ret    z               ;Z - no errors
  1040.     ld    de,msymnf       ;Display Symbol Table Not Found msg   
  1041.     call    print
  1042.     ld    sp,stack        ;Reinit stack
  1043.     jp    .eof50          ;Check for more Symbol files to load
  1044.  
  1045.  
  1046.                                 ;HEXC
  1047.                                 ;Conver⌠ Byte iε ┴ t∩ tw∩ ASCII he° digits.
  1048.                                 ;Return: A - converted HI Order digit
  1049.                                 ;        L -           LO Order digit
  1050.  
  1051. èhexc:    ld    h,a
  1052.     rrca
  1053.     rrca
  1054.     rrca
  1055.     rrca
  1056.     call    hexc00
  1057.     ld    l,a
  1058.     ld    a,h
  1059. hexc00:    and    0fh
  1060.     add    a,90h
  1061.     daa
  1062.     adc    a,40h
  1063.     daa
  1064.     ret
  1065.  
  1066.  
  1067.                                 ;HEX:
  1068.                                 ;This routine is called by the Symbol Table
  1069.                                 ;Building routines, .SYM and .PRN and its
  1070.                                 ;Its function is to convert ASCII Addresses
  1071.                                 ;Into binary.  Since we are reading files in
  1072.                                 ;A known format we don't init any loop counts;
  1073.                                 ;Instead, we look for delimeters. 
  1074.  
  1075.  
  1076. hex:    call    nchr            ;Get Char from disk I/O Buffer
  1077. hex00:    cp    3AH             ;Convert ASCII to hex
  1078.     jp    c,hex10         ;C - must be delimeter
  1079.     sub    7
  1080. hex10:    sub    '0'
  1081.     ex    de,hl           ;Shift HL left four
  1082.     add    hl,hl
  1083.     add    hl,hl
  1084.     add    hl,hl
  1085.     add    hl,hl
  1086.     or    l               ;Or in this new digit
  1087.     ld    l,a
  1088.     ex    de,hl
  1089.     ld    a,(bytes)
  1090.     dec    a
  1091.     ld    (bytes),a
  1092.     jp    nz,hex
  1093.     call    nchr
  1094.     cp    'I'             ;Global?
  1095.     call    z,nchr          ;Z - need to read Next to determine absolute
  1096.                                 ;    or Relocatable
  1097.  
  1098.     ld    (relchr),a      ;We need to Save this Character for .PRN Files
  1099.                                 ;so we can tell whether to add this Symbol
  1100.                                 ;to the Count of Symbols Loaded.  If this
  1101.                                 ;is an EXTERNAL Name We Skip the Add.
  1102.  
  1103.     cp    ' '             ;Space means absolute
  1104.     jr    z,hex30         ;No bias added to absolute Symbols
  1105.     ld    a,(biaslo)
  1106. è    add    a,e             ;Add in bias as specified by user or default
  1107.                                 ;As initialized by us (zero)
  1108.     ld    e,a
  1109.     ld    a,(biashi)
  1110.     adc    a,d
  1111.     ld    d,a
  1112. hex30:    ld    a,(maxlen)      ;Now Point to Last Byte of Symbol Table
  1113.                                 ;Entry, Which is Where We Will Store
  1114.                                 ;Address Just Computed 
  1115.     cpl
  1116.     and    c
  1117.     ld    c,a
  1118.     ld    a,(maxlen)
  1119.     or    c
  1120.     ld    c,a             ;Never worry about carry - we always start 
  1121.                                 ;With 256 boundary
  1122.         ld    a,d             ;Store LO Order Symbol Address
  1123.     ld    (bc),a
  1124.     dec    bc        ;Point to Penultimate Byte in Block
  1125.     ld    a,e             ;HI Order Byte of Address Into Symbol Table
  1126.     ld    (bc),a
  1127.     ld    a,(maxlen)    ;Mask to Rewind Symbol Table Pointer to the
  1128.                 ;Start of This Block
  1129.     cpl
  1130.     and    c
  1131.     ld    c,a
  1132.     ret
  1133.  
  1134.  
  1135. totsym:    ld    de,nsymlo       ;NSYM - BCD running count of the Number of 
  1136.     ld    a,(de)          ;       Symbols loaded so far
  1137.     add    a,1             ;Bump by one Symbol
  1138.     daa                     ;Keep BCD format
  1139.     ld    (de),a          
  1140.     ret    nc              
  1141.     dec    de              ;Account for carry by Bumpind HI Order byte
  1142.     ld    a,(de)
  1143.     add    a,1
  1144.     daa
  1145.     ld    (de),a
  1146.     ret
  1147.                                 
  1148.  
  1149.                 ;ZSTX:            
  1150.                     ;Possible syntax error was detected as IFCB 
  1151.                 ;Tried to init the FCB. However, we neve≥ kee≡
  1152.                  ;Tracδ oµ ho≈ man∙ file≤áappeared in the 
  1153.                     ;Command line we just keep calling IFCB.  
  1154.                 ;Hence, we will always get an error return at 
  1155.                 ;Some Point when the Input Buffer runs out of 
  1156.                 ;Valid Input.  We check for real syntax error 
  1157.                 ;Or End of command line by  examining the 
  1158.                 ;First Byte of the parse Buffer:  if zero then
  1159.                 ;PRSR Found no valid Characters in the Input 
  1160.                 ;Buffer and this is the End of Input - else,
  1161.                 ;IFCB Found real syntax error.
  1162.  
  1163.  
  1164. zstx:    ld    a,(prsbf)
  1165.     and    a        ;Real syntax error - or    End of Input?
  1166.     jp    z,load          ;Z - more files 
  1167.     ld    de,mldg        ;Display Loading msg followed by Symbol Name
  1168. è                ;To preserve the syntax used on good loads
  1169.     call    nprint
  1170.     ld    de,prsbf    ;Display File Name Currently in parse Buffer so
  1171.                 ;User knows where goof was
  1172.     call    print
  1173.     call    crlf
  1174.     ld    de,msntx    ;Now display Syntax Error
  1175.     call    print
  1176.     jp    .eof50        ;Check for more files to load
  1177.  
  1178.  
  1179. zfnf:    ld    de,mfilnf    ;Display File Not Found 
  1180.     call    print
  1181.     jp    .eof50
  1182.  
  1183.  
  1184. zmem:    ld    de,mmem??    ;Display Out of Memory msg
  1185.     call    print
  1186.     call    crlf
  1187.     ld    hl,maxlen
  1188.     ld    l,(hl)
  1189.     ld    h,00        
  1190.     add    hl,bc
  1191.     ld    (ntpa),hl
  1192.     jp    load
  1193.  
  1194.  
  1195. zoff:    ld    de,minvof    ;Display Invalid Offset Using 0000 msg
  1196.     call    print
  1197.     ld    hl,00
  1198.     jp    zsym10
  1199.  
  1200.  
  1201. fstrng:    
  1202.     push    bc
  1203.     push    de
  1204. fstr00:    
  1205.     ld    de,(pstrng)     ;Address of Canned String Pointer
  1206.     ld    a,(de)        ;Length
  1207.     ld    b,a
  1208.     inc    de
  1209. fstr10:    call    nchr        ;Get Char
  1210.     cp    EOF
  1211.     jp    z,fstr20
  1212.     ex    de,hl        ;DE - Buffer ptr  HL - "Symbols:" string ptr
  1213.     cp    (hl)
  1214.     ex    de,hl
  1215.     jp    nz,fstr00    ;Mismatch read more from File
  1216.     inc    de
  1217.     djnz    fstr10          ;Check entire string length
  1218. fstr20:    pop    de
  1219.     pop    bc    
  1220.     ret
  1221.  
  1222. .LST??:    defb    .LSTsz        ;String Length
  1223.     defm    'Symbol Table:'
  1224.     defb    CR,LF,CR,LF
  1225. .LSTsz    equ    $ - .LST?? - 1
  1226.  
  1227.  
  1228. .PRN??:    defb    .PRNsz        ;String Length    
  1229.     defm    'Symbols:'    ;String to search for in M80's .PRN files 
  1230.                 ;Indicating start of Symbol Table
  1231.     defb    CR,LF
  1232. .PRNsz    equ    $ - .PRN?? - 1
  1233.  
  1234.  
  1235. tsym:
  1236. tsymhi:    defb    0
  1237. tsymlo:    defb    0
  1238.  
  1239. usymbl:    defw    0
  1240.  
  1241. pstrng:    defw    0
  1242.  
  1243. relchr:    defb    0
  1244.  
  1245. .idprn:    defb    0
  1246.  
  1247. star:    defb    0
  1248.  
  1249. nsym:
  1250. nsymhi:    defb    0
  1251. nsymlo:    defb    0
  1252. mhex:    defm    '    '
  1253.     defb    '$'
  1254.  
  1255. msym..:    defm    'Number of Symbols Loaded: $'
  1256.  
  1257. tsym..:    defb    CR,LF
  1258.     defm    'Total Symbols:   $'
  1259.  
  1260. msymnf:    defm    'Symbol Table Not Found'
  1261.     defb    CR,LF,0
  1262.  
  1263. minvof:    defm    'Invalid Offset - Using 0000'
  1264.     defb    CR,LF,0
  1265. è
  1266. msymld:    defb    CR,LF
  1267.     defm    'Symbol Table:    '
  1268.     defb    0
  1269.  
  1270. mZ8Eld:    defb    CR,LF
  1271.     defm    'Z8E Relocated:   '
  1272.     defb    0
  1273.  
  1274. mnvmem:    defb    CR,LF
  1275.     defm    'Top of Memory:   '
  1276.     defb    00
  1277.  
  1278. Z8Eb:    defb    00
  1279. Z8Ebh:    defb    00
  1280. ntpa:    defw    00
  1281.  
  1282. bytes:    defb    00
  1283.  
  1284. zbuf:    defb    00
  1285. zbufnm:    defs    15,00
  1286. znmbuf:    defs    72,00
  1287.  
  1288. init:    ret
  1289.     defs    255
  1290.     
  1291.     
  1292.  
  1293.     page
  1294. ;******************************************************************************
  1295. ;*
  1296. ;*    Z8E:    Entry Point to monitor
  1297. ;*
  1298. ;*        Each command begins with the Output of the '*' prompt.
  1299. ;*        Command    Character in validated by checking the CMD Table,
  1300. ;*        if command Found we determine if it requires a call to ILIN
  1301. ;*        to pick    up an argument.
  1302. ;*
  1303. ;*        Relative position of command letter in CMD Table also used
  1304. ;*        as index into command jump Table JTCMD.
  1305. ;*
  1306. ;*        All commands entered with B = 0.
  1307. ;*
  1308. ;******************************************************************************
  1309.  
  1310.  
  1311.        org    256*(($+255)/256)
  1312.  
  1313. Z8Eorg:
  1314.                 ;NOTE: First three bytes here become a jump to
  1315.     defs    16        ;      BDOS after we are loaded
  1316.                 ;
  1317.                 ;This is the internal Symbol Table
  1318.  
  1319. Z8E:    and    a        ;Any do-nothing    Instruction with the sign
  1320.                 ;Bit set to indicate End of internal Symbol
  1321.                 ;Table
  1322.  
  1323.     defb    31H        ;LD SP,NNNN - Load Monitor Stack Pointer
  1324. Z8Esp:    defw    8000H        ;Actual    Address    Filled in by NINT at Load
  1325.                 ;Time When We Figure Out Where BDOS Is
  1326. è
  1327. Z8Ecmd:    ld    hl,Z8E
  1328.     push    hl
  1329.     ld    de,prompt    ;Display Prompt (Asterisk)
  1330.     call    nprint
  1331.     ld    hl,jstepf    ;Full Screen Debugging in Effect?
  1332.     ld    a,(hl)
  1333.     and    a
  1334.     jr    nz,Z8E10    ;NZ - NO
  1335.  
  1336.     ld    c,10
  1337.     call    spaces        ;If This Was JDBG Clear Command Line Residue
  1338.     ld    b,10        
  1339. Z8E00:    call    bksp
  1340.     djnz    Z8E00
  1341.  
  1342. Z8E10:    call    inchar        ;Read in Command Character
  1343.     call    ixlt        ;Translate to Upper Case for Compare
  1344.     ld    (lcmd),a
  1345.     cp    'J'        ;If Command is Anything but J then Indicate
  1346.                 ;That Screen is Corrupted.  At Next Invokation
  1347.                 ;JDBG Will Know to Repaint the Screen. 
  1348.     jr    z,Z8E20
  1349.     ld    (jstepf),a    ;Full Screen Flag NZ - Full Screen Debugging
  1350.                 ;in Progress
  1351.  
  1352.  
  1353. Z8E20:    ld    bc,ncmd        ;Total Number of Commands
  1354.     ld    hl,cmd        ;Table of ASCII    Command    Characters
  1355.     cpir
  1356.     jp    nz,e???        ;Command Letter Not Found in Table
  1357.     ld    hl,jtcmd    ;Command Jump Table
  1358.     add    hl,bc
  1359.     add    hl,bc        ;Index into Table
  1360.     ld    e,(hl)        ;LO Order command processing routine
  1361.     inc    hl
  1362.     ld    d,(hl)        ;Upper Address
  1363.     ld    c,3
  1364.     call    spaces        ;Print Spaces Regardless
  1365.     ex    de,hl        ;HL - Address of Command Processing Routine
  1366.     jp    (hl)        ;
  1367.     page
  1368. ;******************************************************************************
  1369. ;*
  1370. ;*    BPHN:    BreakPoint Handler - RST38s Land Here
  1371. ;*
  1372. ;*        BPHN   - BPHN00      Save all user    registers
  1373. ;*        BPHN10 - BPHN20      Check    that user PC matches entry in BRKTBL.
  1374. ;*        BPHN80          Special single step processing.
  1375. ;*
  1376. ;*    NOTE:    SBPS is    both a flag AND    the count of the Number    of step    BPs.
  1377. ;*        SBPS is    set to 1 merely    to indicate that the single-stepping
  1378. ;*        is in effect.  Then the    Number of step BPs is added to one.
  1379. ;*        Hence, if 1 STEP BP was    set then  SBPS = 2 and if 2 step BPs
  1380. ;*        were set (conditional jump, call, ret) SBPS = 3.
  1381. ;*
  1382. ;******************************************************************************
  1383.  
  1384. bphn:    ld    (hlreg),hl    ;Save user hl
  1385.     pop    hl        ;Pop Breakpoint    pc from    stack
  1386.     ld    (spreg),sp    ;Save user sp
  1387.     ld    sp,(Z8Esp)    ;Switch    to our stack
  1388.     dec    hl        ;Point to location of rst Instruction
  1389.     ld    (pcreg),hl    ;Save user pc
  1390.     ld    (dereg),de    ;Save user de
  1391.     ld    (bcreg),bc    ;Save user bc
  1392.     push    af
  1393.     pop    hl        ;User accumulator and flag to hl
  1394.     ld    (afreg),hl    ;Save user af
  1395.     ld    a,i
  1396.     ld    h,a        ;Save user i reg
  1397.     ld    a,r
  1398.     ld    l,a        ;Save user r reg
  1399.     ld    (rreg),hl
  1400.     ex    af,af'          ;Bank in prime regs
  1401.     exx
  1402. è    ld    (hlpreg),hl    ;Save
  1403.     ld    (depreg),de
  1404.     ld    (bcpreg),bc
  1405.     push    af
  1406.     pop    hl
  1407.     ld    (afpreg),hl
  1408.     ld    (ixreg),ix    ;Save user ix
  1409.     ld    (iyreg),iy    ;Save user iy
  1410.     ld    a,(bps)
  1411.     and    a        ;Check for zero    BP count
  1412.     jp    z,bp???        ;Error - no BPs    set
  1413.     ld    b,a        ;B - Number of Breakpoints
  1414.     ld    hl,brktbl    ;BreakPoint storage Table
  1415.     xor    a
  1416.     ld    c,a        ;Init Breakpoint Found flag
  1417. bphn10:    ld    e,(hl)
  1418.     inc    hl
  1419.     ld    d,(hl)        ;DE - Breakpoint Address
  1420.     inc    hl
  1421.     ld    a,(hl)        ;Saved contents    of Breakpoint Address
  1422.     inc    hl
  1423.     ld    (de),a        ;Replace rst 38    with actual data
  1424.     ld    a,(pcregl)    ;User pc - LO Order
  1425.     xor    e
  1426.     ld    e,a        ;Versus    Breakpoint Address in Table
  1427.     ld    a,(pcregh)
  1428.     xor    d        ;Check HI Order
  1429.     or    e
  1430.     jr    nz,bphn20    ;No match - check Next entry in    Table
  1431.     ld    c,b        ;PC Found in Table set C reg NZ
  1432. bphn20:    djnz    bphn10        ;Restore all user data
  1433.     ld    hl,sbps        ;Fetch Number of STEP BPs (0-2)
  1434.     ld    b,(hl)
  1435.     xor    a
  1436.     ld    (hl),a        ;Clear regardless
  1437.     or    c        ;Test BP Found flag
  1438.     jp    z,bp???        ;Z - BP    not in Table
  1439.     inc    hl        ;Point to BP count
  1440.     ld    d,(hl)        ;D - BP count
  1441.     dec    b
  1442.     jp    m,bphn30    ;M - this was user BP not STEP or JDBG
  1443.     ld    a,(hl)
  1444.     sub    b        ;Subtract Number of STEP BPs from BP count
  1445.     ld    (hl),a        ;Restore BP count
  1446.     ld    a,(lcmd)    ;What command got us here?
  1447.     cp    'S'        ;Step?
  1448.     jr    z,bphn90    ;Step command - check count
  1449.  
  1450.                 ;Now we know we have JDBG in progress.  Need
  1451.                 ;To check for user specified BP at the same 
  1452.                 ;Address. If we find one stop trace. 
  1453.     ld    a,b        ;Number of STEP BPs to accumulator (1 or 2).
  1454.                 
  1455.     sub    c        ;Compare Number of STEP BPs with the offset 
  1456.                 ;Into the BP Table where the Current BP was
  1457. è                ;Found.  Since STEP BPs are always at the End
  1458.                 ;Of the Table we can determine how BP was set.
  1459.  
  1460.      jp    nc,jdbg30    ;NC - we are at End of Table so more tracing
  1461.  
  1462. bphn30:    ld    a,c
  1463.     neg
  1464.     add    a,d        ;Create index into pass count Table
  1465.     add    a,a
  1466.     ld    hl,psctbl    ;Pass count Table
  1467.     add    a,l
  1468.     ld    l,a
  1469.     jr    nc,bphn35
  1470.     inc    h
  1471. bphn35:    ld    e,(hl)
  1472.     inc    hl
  1473.     ld    d,(hl)        ;DE - pass count
  1474.     ld    a,d
  1475.     or    e
  1476.     jr    z,bphn50    ;No count in effect 
  1477.     dec    de
  1478.     ld    (hl),d
  1479.     dec    hl
  1480.     ld    (hl),e        ;Restored updated count
  1481.     ld    a,d
  1482.     or    e        ;Did it    just go    zero?
  1483.     jr    z,bphn50    ;Count just expired
  1484.     ld    a,b        ;Pass count not zero - GO or JDBG?
  1485.     and    a
  1486.     jp    p,jdbg30    ;If step flag P we had step BPs
  1487.     ld    hl,(pcreg)
  1488.     jp    g100        ;Continue GO command
  1489. bphn50:    or    b        ;Test if we had STEP BPs
  1490.     jp    m,bphn60    ;This was GO - print BP message
  1491.     ld    a,'X'
  1492.     ld    (lcmd),a    ;Clear command letter so XREG disassembles
  1493.     call    home        ;Home cursor
  1494.     call    xreg
  1495.     ld    b,22        ;Cursor on penultimate line 
  1496.     ld    c,00
  1497.     call    xycp
  1498.         
  1499. bphn60:    ld    de,bpmsg    ;Print *BP*
  1500.     call    print        ;Print msg Pointed to by DE
  1501.     ld    hl,(pcreg)
  1502.     call    outadr        ;Display Breakpoint Address
  1503.     ex    de,hl
  1504.     call    fadr        ;Attempt to find label at this Address
  1505.     ex    de,hl        ;DE - BP Address
  1506.     jp    nz,Z8E        ;NZ - no label Found
  1507.     ld    a,(maxlen)
  1508.     dec    a    
  1509.     ld    c,a        ;Six Chars max for label
  1510.     call    printb
  1511.     jp    Z8E
  1512. bphn90:    call    xreg        ;Display all registers
  1513.     ld    hl,(nstep)    ;Fetch trace count
  1514. è    dec    hl
  1515.     ld    a,l
  1516.     or    h                  
  1517.     jp    z,Z8E        ;Count expired - prompt    for command
  1518.     call    ttyq        ;Test for abort    trace
  1519.     cp    CR
  1520.     jp    z,Z8E
  1521.     call    crlf        ;
  1522.     jp    step40        ;Continue trace
  1523.  
  1524.  
  1525. bp???:    ld    de,bpemsg
  1526.     call    print
  1527.     ld    hl,(pcreg)
  1528.     call    outadr
  1529.     jp    Z8E
  1530.  
  1531.  
  1532. e???:    ex    de,hl
  1533.     ld    de,em???
  1534.     call    print
  1535.     ex    de,hl
  1536.     ret
  1537.     page
  1538. ;******************************************************************************
  1539. ;*
  1540. ;*    JDBG:    ANIMATED DEBUGGER
  1541. ;*        
  1542. ;*        JDBG allows the user to view the Z80 CPU actullay executed the
  1543. ;*        Code.  JDBG displays 18 disassembled Instructions on the 
  1544. ;*        as well as a user defined memory block referred to in the 
  1545. ;*        comments as a window.
  1546. ;*
  1547. ;*    ENTRY POINT JDBG:
  1548. ;*    
  1549. ;*        JDBG processes user Input as a prelude to the actual animation
  1550. ;*        of the Code.  The user enters the starting Address to animate
  1551. ;*        optionally preceded by a subroutine qualifier. The subroutine
  1552. ;*        qualifier may be either a "*" which Instructs Z8E not to trace
  1553. ;*        any subroutines which are located below 100H (ie. BDOS calls),
  1554. ;*        or it may be a "/" which means no tracing of any subroutines.
  1555. ;*        JDBG will also paint the original screen with the register
  1556. ;*        contents as well as the memory window. The contents of the 
  1557. ;*        memory window are also moved into ARGBUF so that we can compare
  1558. ;*        the 'old' contents with the 'new' contents once a the First BP
  1559. ;*        is reached.
  1560. ;*
  1561. ;*    ENTRY POINT JDBG30:
  1562. ;*
  1563. ;*         Entered here via BPHN who determines that animation is in
  1564. ;*        effect.  In order to cut down on superfluous cursor move-
  1565. ;*        ment on the screen we compare the old register and memory
  1566. ;*        window contents with the new contents following the latest
  1567. ;*        BP.  We only Output the changes. Next we determine if the 
  1568. ;*        Current PC exists in disassembled form somewhere on the 
  1569. ;*        screen; if not, we display 18 new disassembled Instructions 
  1570. è;*        with the Current PC as line one.
  1571. ;*
  1572. ;*    EXIT JDBG95:
  1573. ;*
  1574. ;*        Save Current register contents and jump to STEP40 for Next
  1575. ;*        single step.
  1576. ;*
  1577. ;*
  1578. ;******************************************************************************
  1579.  
  1580. jdbg:
  1581.     call    iedtbc        ;Get command line
  1582.     jp    p,jdbg02    ;P - have Input
  1583.  
  1584. jdbg00:    ld    hl,lastro
  1585.     ld    b,(hl)        ;Row position of arrow on screen
  1586.     ld    c,18        ;Column
  1587.     call    xycp
  1588.     ld    c,2
  1589.     call    spaces
  1590.     ld    b,17H
  1591.     ld    c,00
  1592.     call    xycp
  1593.     ld    hl,jstepf
  1594.     ld    a,(hl)
  1595.     ld    (hl),1
  1596.     and    a
  1597.     jp    z,jdbg90    ;J was Last means screen intact - just move
  1598.                 ;Arrow.  Else fall thru and repaint screen.
  1599.                 ;Indicate single step
  1600.     ld    a,10
  1601.     jr    jdbg10        ;Init Timer    
  1602.  
  1603. jdbg02:    ld    a,(hl)        ;Check First Char of Input
  1604.     ex    de,hl        ;DE - Save Input Buffer    Address
  1605.     ld    hl,wflag    ;WFLAG tells us    whether    to trace subroutines
  1606.                 ;Or walk around    them
  1607.     ld    (hl),0ffh    ;Conditionally assume trace all
  1608.     sub    '/'        ;Slash means don't trace ANY
  1609.     jr    z,jdbg03    ;
  1610.     add    a,'/'-'*'    ;Check for star    - no trace of BDOS subs
  1611.     jr    nz,jdbg05
  1612.     inc    a        ;Set flag one to indicate no trace of subs
  1613.                 ;At Address < 100H (BDOS calls)
  1614. jdbg03:    ld    (hl),a        ;Set WFLAG
  1615.     xor    a        ;If slash or space replace with    null in    INBF
  1616.                 ;So parser will    ignore
  1617.     ld    (de),a
  1618. jdbg05:    call    iarg        ;Now evaluate Address
  1619.     jr    z,jdbg08    ;Z - no error
  1620.     ld    a,(inbfnc)    ;Check Number of Characters
  1621.     dec    a        ;Check for just / or just *
  1622.     jr    z,jdbg00    ;Treat as single step
  1623.     ld    (jstepf),a    ;Indicate screen corrupted
  1624.     jp    e???        ;ERROR -
  1625. jdbg08:    ld    (pcreg),hl    ;Save Address at which to start    tracing
  1626.     and    a        ;Check delimter
  1627.     ld    a,10        ;No delimeter use default timer value
  1628.     jr    z,jdbg10
  1629.     call    iarg        ;Check if user wants non-default timer
  1630.     ld    a,10
  1631.     jr    nz,jdbg10    ;ERROR - use default
  1632.     ld    a,l        ;A - timer value as entered by user
  1633. jdbg10:    ld    (timer),a
  1634.     ld    b,24        ;Xmit crlf's to clear screen
  1635. jdbg15:    call    crlf        ;Clear screen
  1636.     djnz    jdbg15
  1637.     call    rgdisp        ;Display Current user regs
  1638.     call    zwnw        ;Display disassembled window
  1639.     ld    a,(wnwsiz)
  1640.     and    a        ;Test if window being displayed
  1641.     jr    z,jdbg28
  1642.     ld    de,window    ;Save user specified memory block til Next BP
  1643.     ld    hl,(wnwtab)    ;Start of memory window Address
  1644.     ld    bc,3
  1645. jdbg20: ld    a,(fwndow)    ;Position cursor starting at column 
  1646.     sub    6
  1647.     call    curs
  1648.            call    outadr        ;Display Address of memory window
  1649. èjdbg25:    ld    a,(fwndow)        ;
  1650.     call    curs        ;Column position on screen of memory window
  1651.                 ;Is (rel pos * 3) + (FWNDOW)
  1652.     ld    a,(hl)        ;Display this byte
  1653.  
  1654.     ld    (de),a        ;SAVE this Byte in WINDOW between BPs
  1655.     call    outhex
  1656.     inc    b        ;Move and display user specifed Number 
  1657.                                 ;Of bytes (WNWSIZ)
  1658.     ld    a,(wnwsiz)
  1659.     sub    b
  1660.     jr    z,jdbg28
  1661.     inc    hl
  1662.     inc    de
  1663.     ld    a,(nlmask)    ;Check for New Line Time
  1664.     and    b
  1665.     jr    nz,jdbg25    ;Not End of Line - Display Next Byte Else...
  1666.     jr    jdbg20        ;...Display Address First
  1667. jdbg28:    ld    a,3        ;Point to Very First Instruction
  1668.     jp    jdbg75
  1669.  
  1670.  
  1671.                 ;BREAKPOINT HANDLER JUMPS HERE FOR FULL
  1672.                 ;SCREEN SINGLE STEP
  1673. jdbg30:    ld      c,3 
  1674.     call    spaces        ;Remove => from screen
  1675.     ld    b,c  
  1676.     ld    hl,regcon    ;NEW contents of registers following BP
  1677.     ld    de,regsav    ;OLD prior to BP       
  1678. jdbg35:    ld    a,(de)        ;Compare old vs new
  1679.     cp    (hl)
  1680.     inc    hl
  1681.     inc    de
  1682.     jr    nz,jdbg40    ;DIFFERENT - display new
  1683.     ld    a,(de)        ;Check HI Order Byte of this reg pair 
  1684.     cp    (hl)
  1685.     jr    z,jdbg45    ;Z - hi and lo bytes the same so try Next reg
  1686. jdbg40:    ld    a,4        ;Col position of reg pair is (rel pos * 9) + 3
  1687.     and    b
  1688.     jr    z,jdbg42
  1689.     ld    a,3
  1690.     and    b
  1691.     inc    a
  1692. jdbg42:    add    a,3
  1693.     call    curs
  1694.     ld    a,(hl)        ;Display upper Byte of reg contents
  1695.     call    outhex
  1696.     dec    hl        ;Rewind to pick up LO Order byte
  1697.     ld    a,(hl)
  1698.     inc    hl
  1699.     call    outhex        ;Display LO Order
  1700. jdbg45:    inc    hl
  1701.     inc    de
  1702.     inc    b
  1703.     ld    a,regsiz/2    ;Number of reg pairs to display
  1704.     sub    b
  1705.     jr    nz,jdbg35            
  1706.     call    space
  1707.     ld    b,1
  1708.     ld    c,36
  1709.     call    xycp
  1710.     
  1711.     ld    b,0
  1712.     call    psw        ;Now display FLAG reg mnemonics
  1713.     
  1714.     ld    a,(wnwsiz)    ;Check Window Size
  1715.     and    a
  1716.     jr    z,jdbg60    ;Z - no memory window in effect
  1717.     ld    hl,(wnwtab)    ;HL - Address of start of window
  1718.     ld    bc,03
  1719.     ld    de,window    ;Old contents of window stored here 
  1720. jdbg50:    ld    a,(de)        ;Compare old vs new
  1721.     cp    (hl)
  1722.     jr    z,jdbg55    ;Same - no reason to display
  1723.     ld    a,(fwndow)    ;Col position of Byte is (rel pos * 3) + 50
  1724.     call    curs
  1725.     ld    a,(hl)        ;Display byte
  1726.  
  1727.     ld    (de),a        ;We only need to move Byte if it changed
  1728.  
  1729.     call    outhex
  1730. jdbg55:    inc    b        ;Bump memory window Byte count
  1731.     ld    a,(wnwsiz)      ;Max size
  1732.     inc    hl
  1733.     inc    de
  1734.     sub    b
  1735.     jr    nz,jdbg50    ;Loop until entire window examined
  1736.             
  1737. jdbg60:    ld    a,18        ;Init count of disassembled Instructions
  1738.     ld    (jlines),a
  1739.     ld    de,(zasmfl)    ;Address of First disassembled Instruction
  1740.                 ;On screen
  1741. jdbg65:    ld    hl,(pcreg)
  1742.     and    a
  1743.     sbc    hl,de
  1744.     jr    z,jdbg70    ;Found - PC exists somewhere on screen
  1745.     call    zlen00        ;Compute length    of this    Instruction
  1746.     ld    b,0
  1747.     ex    de,hl        ;HL - Address on disassembled Instruction
  1748.     add    hl,bc        ;Add length to compute Address of Next inline
  1749.                 ;Instruction for display
  1750.     ex    de,hl        ;DE - restore new istruction Pointer
  1751.     ld    hl,jlines
  1752.     dec    (hl)        ;Dec screen line count
  1753.     jr    nz,jdbg65
  1754.     ld    hl,(pcreg)    ;PC not    on screen - so Current PC will be new
  1755.                 ;First PC on screen
  1756.     ld    (zasmfl),hl
  1757.     ld    bc,0300H    ;Cursor    ROW 4 -    COL 1
  1758.     call    xycp
  1759.     call    zwnw        ;Instruction NOT on screen so paint a new
  1760.                 ;Screen    starting at Current PC
  1761. è    ld    a,3        ;Disassembled Instructions start on line 4
  1762.     jr    jdbg75
  1763. jdbg70:    ld    a,(jlines)
  1764.     neg
  1765.     add    a,21        ;A - screen row    on which to position cursor
  1766. jdbg75:    ld    (lastro),a    ;Save position of arrow
  1767.     ld    b,a        ;Pass to XYCP
  1768.     ld    c,18        ;Pass column
  1769.     call    xycp        ;Position cursor routine
  1770.     ld    de,mrrow
  1771.     call    print
  1772.     ld    a,(jstepf)
  1773.     dec    a        ;Test if single stepping
  1774.     jp    z,jdbg95
  1775.     call    ttyq
  1776.     ld    hl,timer
  1777.     ld    b,(hl)
  1778.     jr    z,jdbg80
  1779.     cp    '0'
  1780.     jr    c,jdbg78
  1781.     cp    3Ah
  1782.     jr    nc,jdbg95
  1783.     and    0fh
  1784.     ld    (hl),a
  1785.     ld    b,a
  1786.     jr    jdbg80
  1787. jdbg78:    cp    CR        ;Carriage return ends command
  1788.     jr    z,jdbg95
  1789.         
  1790. jdbg80:    call    clok
  1791.  
  1792. jdbg90:    ld    de,regsav    ;Move Current reg contents to Save area 
  1793.     ld    hl,regcon
  1794.     ld    bc,regsiz
  1795.     ldir
  1796.     jp    step40
  1797.  
  1798.  
  1799.                 ;User requested abort from console
  1800. jdbg95: ld    b,22        ;Position cursor on line 23 for prompt
  1801.     ld    c,0
  1802.     call    xycp
  1803.     xor    a
  1804.     ld    (jstepf),a    ;Indicate we have full screen of data
  1805.     jp    Z8E        ;To Z8E command processor 
  1806.  
  1807.  
  1808.  
  1809.  
  1810.  
  1811.  
  1812. zwnw:                ;Display disassembly window
  1813.     ld    a,18        ;Number of Instructions to disassemble 
  1814. zwnw05:    ld    hl,(pcreg)
  1815.     ld    (zasmfl),hl    ;Save PC of First line
  1816. zwnw10:    ld    (jlines),a
  1817.     ld    (zasmpc),hl    ;Save here as well
  1818.     ld    de,zasmbf+96    ;Disassemble in upper portion of Buffer to
  1819.                 ;Prevent overlap with big memory windows.
  1820.                 ;Otherwise, every time we disassemble a new
  1821.                 ;Screen we have to repaint the window.
  1822.  
  1823.     call    zasm10        ;Disassemble First Instruction
  1824.     ld    a,30        ;Test Line Length
  1825.     cp    c
  1826.     jr    z,zwnw20
  1827.     ld    c,42
  1828. zwnw20:    call    printb
  1829.     call    crlf
  1830.     ld    hl,(zasmnx)    ;HL - Next Address to disassemble
  1831.     ld    a,(jlines)
  1832.     dec    a
  1833.     jr    nz,zwnw10
  1834.     ld    b,3        ;Position cursor Next to Next Instruction    
  1835.                 ;To execute which is the First one on the 
  1836.                 ;Screen - LINE 4  COL 20 
  1837.     ld    c,20
  1838.     call    xycp
  1839.     ret
  1840. è
  1841.  
  1842.                 ;Display regs at top of screen:
  1843. rgdisp:    call    home        ;Home cursor
  1844.     call    xreg        ;Display regs
  1845.     call    psw        ;Display FLAG reg
  1846.     jp    crlf
  1847.  
  1848.  
  1849.  
  1850. curs:    push    bc
  1851.     push    de
  1852.     push    hl
  1853.     ld    d,a
  1854.     ld    e,c        ;Save Base Row Address
  1855.     cp    3        ;Test if Reg or Memory Window (3 is Reg)
  1856.     ld    a,7
  1857.     jr    z,curs00    ;Z - Regs are Eight Per Line (First Line)
  1858.  
  1859.     ld    a,(nlmask)
  1860. curs00:    and    b        ;Item Number mod lnmask is the relative pos of
  1861.     ld    c,a        ;Reg contents or memory data byte
  1862.                 ;
  1863.     add    a,a        ;
  1864.     add    a,c
  1865.     ld    c,a        ;C - REL Pos Times Three
  1866.  
  1867.     ld    a,d        ;If base column Address is < 50 then this is
  1868.                 ;Reg display
  1869.     
  1870.     sub    3
  1871.     ld    h,a
  1872.     ld    a,c
  1873.     jr    nz,curs20    ;NZ - Not Reg Display - Must Be Memory
  1874.     add    a,a        ;So multiply times three again 
  1875.     add    a,c        ;Times 9 in all for register display
  1876.  
  1877. curs20:    add    a,d        ;Add in base
  1878.     ld    c,a        ;C - Absolute COL Number
  1879.     xor    a        ;Test if This is Reg or Memory Window Display
  1880.     or    h
  1881.     jr    z,curs30    ;Z - This is Register Display
  1882.     ld    a,(fwndow)
  1883.     cp    68        ;14 Char Symbols in Effect?
  1884.     jp    z,curs40
  1885. curs30:    srl    b
  1886. curs40:    ld    a,0FCH
  1887.     and    b        ;Now Compute Row Number 
  1888.     rrca
  1889.     rrca
  1890.     add    a,e        ;Base row Address
  1891.     ld    b,a        ;B - absolute row Number
  1892.     call    xycp        ;Convert row and column to xy cursor Address
  1893.     pop    hl
  1894.     pop    de
  1895.     pop    bc
  1896.     ret
  1897.  
  1898.  
  1899.  
  1900. clok:    ld    d,50          ;Idle loop - decrement to 0 and reload
  1901.     ld    e,00
  1902.     dec    b        ;User specified the loop counter
  1903.     ret    m
  1904. clok10:    dec    de
  1905.     ld    a,e
  1906.     or    d
  1907. è    jr    nz,clok10
  1908.     jr    clok
  1909.  
  1910.     page
  1911. ;******************************************************************************
  1912. ;*
  1913. ;*    EXAM:    Examine    memory and display in hex and ASCII.  User is allowed
  1914. ;*        to modify memory afet every Byte is displayed.    ILIN called
  1915. ;*        to parse Input Buffer into a single string of bytes which is
  1916. ;*        returned in ARGBUF.  The Byte count of the string is returned
  1917. ;*        in ARGBC, and this Number of bytes is transferred to the
  1918. ;*        Current    memory Address.
  1919. ;*
  1920. ;*        User may optionally scan memory    by entering CR.     Command
  1921. ;*        terminates when    a single space is entered.
  1922. ;*
  1923. ;*        Enter:    B - 0
  1924. ;*               DE - Address at which to    display    First byte
  1925. ;*
  1926. ;******************************************************************************
  1927.  
  1928. exam:    call    ilin
  1929.     jp    nz,e???
  1930.     ex    de,hl    
  1931. exam00:    call    newlin
  1932.     ld    a,(de)        ;Fetch Byte to display regardless
  1933.     call    outbyt
  1934.     call    byte
  1935.     jr    nz,exam00     ;NZ - don't replace memory contents
  1936.     cp    '.'
  1937.     jr    nz,exam10
  1938.     ld    a,(inbfnc)
  1939.     dec    a
  1940.     ret    z
  1941. exam10:    ld    hl,argbc    ;Byte count to c
  1942.     ld    c,(hl)
  1943.     ld    b,0
  1944.     ld    (exampt),de
  1945.     ld    hl,argbf    ;Start of evaluated Input
  1946.     ldir
  1947.     ld    a,(trmntr)
  1948.     cp    CR
  1949.     jr    z,exam00
  1950.     ld    de,(exampt)
  1951.     jr    exam00
  1952.     page
  1953. ;******************************************************************************
  1954. ;*
  1955. ;*    HSYM:    Display Symbol Table
  1956. è;*
  1957. ;*        User may display the Symbol Table on the console.  If no arg
  1958. ;*        entered on command line then the entire Table is dumped start-
  1959. ;*        ing with the First Symbol.  If a valid Symbol is entered then
  1960. ;*        we will try to find the Symbol in the Table; if Found, the 
  1961. ;*        Table is dumped starting at that Point.  If the Symbol is not
  1962. ;*        Found the user gets a ? and the command terminates.
  1963. ;*
  1964. ;*        Symbols are displayed in blocks of 32.  After each block the 
  1965. ;*        user is given the opportunity of continuing or ending the 
  1966. ;*        command:
  1967. ;*
  1968. ;*            CR - Display Next
  1969. ;*            NOT CR - Terminate
  1970. ;*
  1971. ;******************************************************************************
  1972.  
  1973. hsym:    call    ilin        ;Read in line of data
  1974.     ld    hl,Z8E        ;Assume no Symbol entered
  1975.     jr    nz,hsym10    ;NZ - no Input means display entire Table
  1976.     ld    de,prsbf    
  1977.     call    fsym        ;Attempt to find this Symbol Name in Table
  1978.     jp    nz,e???        ;Error - Symbol    not Found in Symbol Table
  1979.     ld    a,(maxlen)
  1980.     or    l        ;Point to Next Symbol Table entry (Next Block)
  1981.     ld    l,a        ;HL - ptr to Last Byte in this entry 
  1982.     inc    hl        ;Now Next entry toward hi memory
  1983. hsym10:    ld    a,(maxlen)    ;Max size of Symbol Name
  1984.     ld    c,a
  1985.     dec    c
  1986.     inc    a        ;Make 8 or 16
  1987.     ld    e,a
  1988.     xor    a
  1989.     ld    d,a        ;DE - Size of Symbol Table Entry
  1990.     sbc    hl,de        ;Previous entry toward lo memory
  1991.     ld    a,(hl)        ;Null means this is unused slot is user 
  1992.                 ;Defined Symbol Table
  1993.     and    a
  1994.     jr    z,hsym10
  1995.     dec    a        ;NEG Means This is JP Opcode (0C3H) of Jump to
  1996.                 ;BDOS
  1997.     ret    m
  1998.     ld    a,(maxlen)
  1999.     srl    a
  2000.     srl    a
  2001.     xor    2
  2002.     and    b        ;Check Symbols per line count
  2003.     call    z,crlf        ;Crlf every fourth
  2004.     dec    b        ;Now decrement Symbols per line count
  2005.     call    printb        ;Treat Symbol Table entry as a Buffer and 
  2006.                 ;Six Chars or until null, whichever is First
  2007.     inc    c        ;Tack on two spaces
  2008.     inc    c
  2009.     call    spaces
  2010.     ld    a,(maxlen)
  2011.     or    l        ;Point to Last Byte in Symbol Table Block
  2012.     ld    l,a
  2013.     ld    d,(hl)        ;Upper Byte of Symbol Address
  2014.     dec    hl
  2015.     ld    e,(hl)        ;Lo Order
  2016.     ex    de,hl
  2017.     call    outadr        ;HL - Symbol Address to display
  2018.     ld    c,4
  2019.     call    spaces        ;Next Symbol Name starts 4 spaces to the right
  2020.     ex    de,hl        ;HL - Symbol Table Pointer
  2021.     ld    a,(maxlen)
  2022.     cpl
  2023.     and    l        ;Rewind to Point to Byte zero of entry
  2024.     ld    l,a
  2025.     ld    a,b
  2026.     and    31        ;Displayed block of 32 Symbols?
  2027.     jr    nz,hsym10
  2028.     call    crlf
  2029.     call    ttyi        ;Test if user wants abort
  2030.     cp    CR
  2031.     jr    z,hsym10
  2032.     ret            ;Not CR - End command
  2033.     page
  2034. ;*****************************************************************************
  2035. ;*
  2036. ;*    USYM:   Write Symbol Table to Disk
  2037. ;*
  2038. ;*****************************************************************************
  2039.  
  2040. usym:    call    iedtbc        ;Get a command line 
  2041.     ret    m        ;No Input ends command
  2042.     call    bldf        ;Build FCB
  2043.     jp    nz,esntx    ;Syntax error
  2044.     ld    hl,Z8E        ;Start at beginning
  2045.     ld    a,(symflg)    ;Do we even have a Symbol Table?
  2046.     and    a
  2047.     ret    nz        ;No Table - End command
  2048.     ld    b,128        ;Disk write Buffer size
  2049.     ld    (lines),a    ;Clear Symbols per line counter
  2050.     ld    de,symbuf
  2051. usym10:    ld    a,(maxlen)
  2052.     ld    c,a        ;Max size of Symbol Name
  2053.     cpl
  2054.     and    l        ;Rewind to Byte zero of Symbol Table entry
  2055.     ld    l,a
  2056.     ld    a,b        ;Temp Save Buffer Count
  2057.     ld    b,0
  2058.     sbc    hl,bc
  2059.     dec    hl        ;Point to 8 or 16 Byte Boundary
  2060.     ld    b,a        ;Restore Buffer Count    
  2061.  
  2062.     ld    a,(hl)        ;Null means this is unused slot in user 
  2063.                 ;Defined Symbol Table
  2064.     and    a
  2065.     jr    z,usym10
  2066.     dec    a        ;Neg means this is JP Opcode (0C3H) of jump to
  2067.                 ;BDOS
  2068.     jp    p,usym20
  2069.     call    pcrlf        ;Hit End of Table - put crlf in Buffer
  2070.     ld    a,EOF
  2071.     ld    b,1        ;Force Buffer write
  2072.     call    putc        ;Put EOF in File
  2073.     jp    closef        ;This is a wrap
  2074. usym20:    ld    a,(maxlen)
  2075.     or    l
  2076.     ld    l,a        ;Point to HI Order Byte of Symbol Address
  2077.     call    pbin        ;Put Address in Buffer
  2078.     ld    a,' '
  2079.     call    putc        ;Followed by space just like L80
  2080.     ld    a,(maxlen)
  2081.     cpl
  2082.     and    l        ;Rewind to Byte zero of Symbol entry
  2083.     ld    l,a
  2084. usym25:    ld    a,(hl)        ;Fetch Char of Symbol Name
  2085.     and    a        ;Null?
  2086.     jr    z,usym40    ;Name is less than 6 Chars long
  2087.     call    putc        ;Put valid Symbol Name Chars in Buffer
  2088.     dec    c
  2089.     jr    z,usym40    ;Z - Just Moved Last Char    
  2090.     inc    hl
  2091.     jr    usym25
  2092. usym40:    ld    a,TAB        ;Tab separates Name and Next Address
  2093.     call    putc        ;Insert TAB before Address field
  2094.     ld    a,(lines)
  2095.     dec    a
  2096.     ld    (lines),a
  2097.     and    3        ;Insert crlf every fourth Symbol
  2098.     jr    nz,usym10
  2099.     call    pcrlf
  2100.     jr    usym10
  2101.  
  2102.  
  2103.  
  2104. pcrlf:    ld    a,CR
  2105.     call    putc
  2106.     ld    a,LF
  2107.     jr    putc
  2108.  
  2109.  
  2110.                 ;Convert two Byte binary Address to ASCII
  2111.                 ;And put into Buffer
  2112. pbin:    call    pbin00        ;
  2113.     dec    hl
  2114. pbin00:    ld    a,(hl)
  2115.     call    binx            
  2116.     call    putc        ;
  2117.     ld    a,(hl)
  2118.     call    binx00
  2119.  
  2120.  
  2121. putc:    ld    (de),a        ;Just like PASCAL - put Char into Buffer
  2122.     inc    de
  2123.     dec    b        ;Buffer count passed in b 
  2124.     ret    nz
  2125. putc00:    ld    de,symbuf    ;Hit End of Buffer - reinit Pointer to start
  2126.     call    write        ;Write Current Buffer
  2127.     ld    b,128        ;Reinit tally
  2128.     ret
  2129.     page
  2130.  
  2131. ;******************************************************************************
  2132. ;*
  2133. ;*    DUMP:  Dump memory in hex and ASCII
  2134. ;*
  2135. ;*    Memory is dumped in hex    and ASCII in user specified block size.
  2136. ;*    If the D command is given without arguments then memory    is dumped
  2137. ;*    beginning at the Address where we left off as store in BLKPTR.
  2138. ;*    User is    queried    after each block is dumped:
  2139. ;*
  2140. ;*        CR - dump Next consecutive block
  2141. ;*        NOT    CR - End command
  2142. ;*
  2143. ;******************************************************************************
  2144.  
  2145. dump:    call    iedtbc        ;Solicit Input
  2146.     jp    p,dump00    ;P - Input present
  2147.     ld    de,(bsiz)    ;No Input means    use previous block size
  2148.     ld    hl,(blkptr)    ;   ...    and Address
  2149.     jr    dump30
  2150. dump00:    call    iarg        ;Read in Next arg (starting Address)
  2151.     jp    nz,e???        ;Invalid starting Address
  2152.     ex    de,hl        ;DE - starting Address to dump
  2153.     call    iarg        ;Next arg (block size)
  2154.     jr    z,dump15    ;Z - no    errors
  2155.     ld    hl,000        ;Default to blocksize of 256
  2156.     jr    dump20
  2157. dump15:    xor    a
  2158.     or    h        ;Test for block    size or    ending Address
  2159.     jr    z,dump20    ;Less than 256 must be block size
  2160.     sbc    hl,de        ;Compute size
  2161.     jp    c,e???
  2162. dump20:    ld    a,l
  2163.     or    h
  2164.     jr    nz,dump25
  2165.     inc    h
  2166. dump25:    ld    (bsiz),hl
  2167.     ex    de,hl        ;DE - block size   HL -    memory Pointer
  2168. dump30:    ld    b,16        ;Init bytes per    line count
  2169.     call    ttyq
  2170.     cp    CR
  2171.     ret    z
  2172.     call    crlf        ;Display Current Address on new line
  2173.     call    outadr
  2174.     ld    c,2
  2175.     call    spaces        ;Hex display starts two    spaces right
  2176. dump40:    dec    b        ;Decrement column count
  2177. è    ld    a,(hl)
  2178.     inc    hl
  2179.     call    othxsp        ;Display memory    in hex
  2180.     inc    c        ;Tally of hex bytes displayed
  2181.     dec    de        ;Decrement block count
  2182.     ld    a,d
  2183.     or    e        ;Test for End of block
  2184.     jr    z,dump50    ;Z - End of block
  2185.     xor    a
  2186.     or    b        ;End of    line?
  2187.     jr    nz,dump40    ;Not End of line - dump    more in    hex
  2188.     jr    dump60
  2189. dump50:    ld    a,(bsizhi)
  2190.     and    a        ;Block size greater than 256?
  2191.     jr    nz,dump55    ;NZ - greater
  2192.     ld    a,(bsizlo)
  2193.     and    0f0h        ;Block size less than 16?
  2194.     jr    z,dump60    ;Z - less
  2195. dump55:    ld    a,(bsizlo)
  2196.     and    0fh        ;Block size multiple of    16?
  2197.     jr    z,dump60    ;Multiple of 16
  2198.     neg
  2199.     add    a,16
  2200.     ld    b,a
  2201.     add    a,a
  2202.     add    a,b
  2203. dump60:    add    a,3        ;Plus three - begin ASCII display
  2204.     ld    b,a        ;Pad line until    ascii display area
  2205. dump70:    call    space
  2206.     djnz    dump70
  2207.     sbc    hl,bc        ;Rewind    memory Point by    like amount
  2208. dump80:    ld    a,(hl)        ;Start ASCII display
  2209.     inc    hl
  2210.     call    asci
  2211.     dec    c
  2212.     jr    nz,dump80
  2213.     call    ttyq        ;CR aborts command
  2214.     cp    CR
  2215.     jp    z,Z8E
  2216.     ld    a,d        ;Test for block    size tally expired
  2217.     or    e
  2218.     jr    nz,dump30    ;
  2219.     ld    de,(bsiz)    ;Reinit    block size
  2220.     call    ttyi        ;Query user for    more
  2221.     cp    CR
  2222.     call    z,crlf
  2223.     jr    z,dump30    ;Not CR    - Next block
  2224.     ld    (blkptr),hl
  2225.     ret            ;End command
  2226.     page
  2227. ;******************************************************************************
  2228. ;*
  2229. ;*    RGST:  display and optionally modify individual    registers
  2230. ;*
  2231. ;*    Call IEDT:   read edited Input into inbf
  2232. ;*    Call PRSR:   parse Input
  2233. ;*    Call MREG:   validate register Name and    map into reg storage
  2234. ;*    Call IARG:   query user    for replacement
  2235. è;*
  2236. ;******************************************************************************
  2237.  
  2238. rgst:    ld    c,' '        ;Get edited Input
  2239.     ld    b,inbfsz
  2240.     call    iedt
  2241.     ret    m
  2242.     ld    a,(trmntr)
  2243.     cp    ' '
  2244.     call    z,bksp
  2245.     call    prsr
  2246.     or    b        ;Unbalanced quotes (prime reg?)
  2247.     jp    p,rgst00
  2248.     and    7FH
  2249.     cp    3
  2250.     jr    nz,rgst25
  2251.     dec    hl
  2252.     ld    a,(hl)
  2253.     sub    QUOTE
  2254.     jr    nz,rgst25
  2255.     ld    (hl),a
  2256. rgst00:    ld    a,(inbfnc)    ;Number    of Characters in Buffer
  2257.     cp    4
  2258.     jr    nc,rgst25    ;ERROR - too many Chars
  2259.     neg
  2260.     add    a,4        ;Calculate space padding
  2261.     ld    c,a
  2262.     cp    3        ;Was it    one?
  2263.     jr    nz,rgst10
  2264.     ld    a,(de)
  2265.     call    ixlt
  2266.     cp    'P'
  2267.     jr    nz,rgst10
  2268.     ld    (inbfnc),a    ;Any Number > 2    indicates 16 bit register
  2269. rgst10:    call    spaces
  2270.     ld    a,(hl)        ;Check Last Char in parse Buffer
  2271.     sub    QUOTE
  2272.     jr    nz,rgst15    ;Not QUOTE
  2273.     ld    (hl),a        ;Replace with null
  2274. rgst15:    call    mreg        ;Validate register Name
  2275.     jr    nz,rgst25    ;ERROR
  2276.     ld    a,(regtrm)    ;Mreg stored Char following reg    Name
  2277.     and    a
  2278.     jr    nz,rgst25    ;ERROR - no operators allowed
  2279.     ld    a,(inbfnc)    ;Now check Number of Chars in Buffer
  2280.     ld    b,a        ;Save in b reg for 8 or    16 bit reg test
  2281.     dec    a        ;Test for one -    8 bit reg
  2282.     ld    c,3
  2283.     jr    z,rgst20
  2284.     ld    a,(hl)
  2285.     call    outhex        ;Display Byte of reg contents
  2286.     dec    hl
  2287.     ld    c,1
  2288. rgst20:    ld    a,(hl)
  2289.     call    othxsp
  2290. è    call    spaces        ;Reg c - Number    of spaces to print
  2291.     ex    de,hl        ;DE - Save reg contents    Pointer
  2292. rgst22:    call    istr        ;Query user for    reg value replacement
  2293.     ld    a,(inbfnc)    ;Test Number of    Chars in Input Buffer
  2294.     dec    a        ;
  2295.     jp    m,rgst40    ;None -    prompt for Next    reg Name
  2296.     call    irsm
  2297.     jr    z,rgst30
  2298.     ld    a,(inbfnc)
  2299.     and    a
  2300.     jr    z,rgst22
  2301. rgst25:    call    e???        ;
  2302.     jr    rgst40        ;Accept    new reg    Name
  2303. rgst30:    ex    de,hl
  2304.     ld    (hl),e
  2305.     dec    b        ;Test for 16 bit reg
  2306.     jr    z,rgst40    ;Z - 8 bit reg
  2307.     inc    hl
  2308.     ld    (hl),d        ;Save upper Byte of user Input
  2309. rgst40:    call    crlf
  2310.     call    space5
  2311.     jp    rgst
  2312.  
  2313.  
  2314.  
  2315. mreg:    ld    c,23        ;Number    of reserved operands
  2316.     call    oprn00        ;Check validity    of register Name
  2317.     ld    a,(de)        ;Last Char examined by operand routine
  2318.     call    oprtor
  2319.     ret    nz        ;ERROR - not null or valid operator
  2320.     ld    (regtrm),a    ;Save terminator Character for rgst
  2321.     ld    a,c
  2322.     cp    17        ;Valid reg names are less than 17
  2323.     jr    c,mreg00    ;So far    so good
  2324.     sub    23        ;Last chance - may be pc
  2325.     ret    nz        ;ERROR - invalid reg Name
  2326.     ld    a,10        ;Make pc look like p for mapping
  2327. mreg00:    ld    hl,regmap    ;Ptrs to register contents storage
  2328.     add    a,l        ;Index into Table by operand value
  2329.     ld    l,a
  2330.     jr    nc,mreg05
  2331.     inc    h
  2332. mreg05:    ld    a,b        ;B reg set m by    prsr if    trailing QUOTE
  2333.     and    a
  2334.     ld    a,0        ;Assume    no QUOTE - not prime reg
  2335.     jp    p,mreg10    ;P - correct assumption
  2336.     ld    a,8        ;Bias Pointer for prime    reg contents
  2337. mreg10:    add    a,(hl)
  2338.     ld    c,a        ;Save mapping byte
  2339.     and    7FH        ;Strip sign
  2340.                 ;So IARG Knows 16 Bit Reg Pair
  2341.     ld    hl,regcon    ;Use Mapping Byte to Build Pointer
  2342.     add    a,l
  2343.     ld    l,a
  2344.     jr    nc,mreg50
  2345.     inc    h
  2346. mreg50:    xor    a        ;HL - Pointer to Register Contents
  2347.     ret
  2348. è
  2349.     page
  2350. ;******************************************************************************
  2351. ;*
  2352. ;*    QPRT:    Read and display / write to I/O    ports
  2353. ;*
  2354. ;*        Contents of ports are displayed    and the    user is    queried
  2355. ;*        Input Character    effects    the Current port Address:
  2356. ;*
  2357. ;*        space -    display    Next sequential    port on    same line
  2358. ;*        LF    -    display    Next sequential    port on    new line
  2359. ;*        CR    -    End command
  2360. ;*        slash -    display    same port on same line
  2361. ;*        ^     -    display    previous port on new line
  2362. ;*
  2363. ;*        any other Input    is treated as a    replacement Byte and
  2364. ;*        is Output to the Current port Address.    any of the
  2365. ;*        above Characters may be    used to    continue the display.
  2366. ;*
  2367. ;*        ENTER: E  - port at which to begin display
  2368. ;*
  2369. ;******************************************************************************
  2370.  
  2371. qprt:
  2372. nprt:
  2373.     xor    a
  2374.     ld    (parenf),a
  2375.       call    iedtbc        ;Get port specified by user
  2376.     ld    hl,port
  2377.     ld    e,(hl)
  2378.     jp    m,qprt30    ;M - no Input means use Last port Number
  2379.     ex    de,hl
  2380.         call    iarg        ;Extract Address
  2381.     jp    nz,e???
  2382.     ex    de,hl         ;E - new port Number
  2383.     ld    (hl),e
  2384.     ld    a,(parenf)
  2385.     cp    '('
  2386.     jr    nz,qprt30
  2387.     ld    c,2
  2388.     call    spaces
  2389. qprt00:    ld    c,e
  2390.     in    a,(c)
  2391.     ld    b,a
  2392.     call    outhex
  2393.     ld    c,2
  2394.     call    spaces
  2395.     ld    c,8        ;Number of bits to display
  2396. qprt10:    sla    b        ;Most significant bit to carry
  2397.     ld    a,'0'        
  2398.     adc    a,0        ;Carry makes it a 1
  2399.     call    ttyo
  2400.     dec    c
  2401.     jr    nz,qprt10
  2402.     ld    c,e
  2403. è    ld    b,3
  2404.     call    ttyq
  2405.     cp    CR
  2406.     ret    z
  2407.     call    clok        ;So we don't go faster than the terminal
  2408.     ld    e,c
  2409.     ld    a,b
  2410.     and    a
  2411.     ret    p
  2412.     ld    b,12
  2413. qprt20:    call    bksp
  2414.     djnz    qprt20
  2415.     jr    qprt00
  2416. qprt30:    call    crlf
  2417.     ld    a,e
  2418.     ld    (port),a
  2419.     call    othxsp
  2420.     call    space
  2421.     ld    c,e
  2422.     ld    a,(lcmd)
  2423.     cp    'N' 
  2424.     jr    z,qprt50
  2425.            in    a,(c)    
  2426.     call    outbyt        
  2427. qprt50:    call    byte
  2428.     ld    a,(trmntr)
  2429.     jr    nz,qprt60
  2430.     cp    '.'
  2431.     ret    z
  2432.     ld    hl,argbc
  2433.     ld    b,(hl)
  2434.     ld    hl,argbf
  2435.     ld    c,e        ;Port Number
  2436.     otir
  2437.     jr    qprt30    
  2438. qprt60:    cp    ' '
  2439.     jr    nz,qprt30
  2440.     dec    de
  2441.     jr    qprt30
  2442.  
  2443.  
  2444.     page
  2445. ;******************************************************************************
  2446. ;*
  2447. ;*    BREAK:    set Breakpoint routine
  2448. ;*
  2449. ;*    BreakPoint Address storage Table (BRKTBL) is examined and user
  2450. ;*    specified Breakpoint is    considered valid unless:
  2451. ;*
  2452. ;*             - Table full
  2453. ;*             - Address already exists in Table
  2454. ;*
  2455. ;*    Optional pass counts can be specified by the user immediatley following
  2456. ;*    the Breakpoint if they are enclosed in parens.
  2457. ;*
  2458. ;*    Entry Point BRK30:
  2459. ;*          Entered from single step command to set Breakpoint.  Two Table
  2460. ;*          slots are    permanently availTable for step Breakpoints. STEP
  2461. ;*          routine calls with C pos to tell us not to look for more args
  2462. è;*          in the Input Buffer.
  2463. ;*
  2464. ;******************************************************************************
  2465.  
  2466. break:    call    iedtbc
  2467.     ret    m        ;End command - no Input
  2468.     ld    c,0ffh        ;Set neg - distinguish ourselves from STEP
  2469. brk10:    ld    a,(bps)        ;Fetch Current bp count
  2470.     cp    maxbp        ;Table full
  2471.     jp    nc,e???        ;Full -    abort command
  2472.     ld    b,a        ;Save Current count
  2473.     call    iarg
  2474.     jp    nz,e???
  2475.     ex    de,hl        ;DE - Breakpoint Address to set
  2476. brk30:    ld    hl,brktbl
  2477.     xor    a
  2478.     or    b        ;Check for no Breakpoints in effect
  2479.     jr    z,brk60        ;None -    bypass check for duplicate
  2480. brk40:    ld    a,e
  2481.     cp    (hl)        ;Check LO Order    Address    match
  2482.     inc    hl
  2483.     jr    nz,brk50    ;No match - check Next
  2484.     ld    a,d
  2485.     sub    (hl)        ;Check HI Order
  2486.     jr    nz,brk50    ;No match - check Next
  2487.     or    c
  2488.     ret    p
  2489.     ld    hl,bps        ;Pointer to BP count
  2490.     ld    a,(hl)
  2491.     sub    b        ;Create    index into PSCTBL
  2492.     jr    brk70
  2493. brk50:    inc    hl
  2494.     inc    hl        ;Bump past contents storage byte
  2495.     djnz    brk40
  2496. brk60:    ld    (hl),e        ;Set in    Table
  2497.     inc    hl
  2498.     ld    (hl),d
  2499.     ld    hl,bps        ;BreakPoint count
  2500.     ld    a,(hl)        ;Fetch Current count for user as index
  2501.     inc    (hl)        ;Bump BP count
  2502. brk70:    ld    de,psctbl    ;Base of pass count Table
  2503.     add    a,a        ;Two Byte Table
  2504.     add    a,e
  2505.     ld    e,a
  2506.     jr    nc,brk80
  2507.     inc    d
  2508. brk80:    xor    a
  2509.     ld    (de),a        ;Pre-clear pass    count Table entry
  2510.     inc    de
  2511.     ld    (de),a
  2512.     or    c        ;Test if this was STEP calling
  2513.     ret    p        ;I'm positive it was
  2514.     ld    a,(delim)    ;Check delimeter which followed    bp Address
  2515.     and    a
  2516.     ret    z        ;End of    line null - terminate command
  2517. è    cp    ','        ;Check for pass    count delimeter
  2518.     jp    nz,brk10    ;Not comma means treatt    this as    new BP
  2519.     call    iarg        ;Get Next arg
  2520.     jp    nz,e???        ;NZ - evaluation error
  2521.     ex    de,hl        ;DE - pass count as entered by user
  2522.     ld    (hl),d        ;Store pass count in Table
  2523.     dec    hl
  2524.     ld    (hl),e
  2525.     and    a        ;Check delimeter
  2526.     jp    nz,brk10    ;NZ - more arguments follow
  2527.     ret            ;End of    line null - terminate command
  2528.     page
  2529.  
  2530. ;******************************************************************************
  2531. ;*
  2532. ;*    CBREAK:    clear Breakpoint routine
  2533. ;*
  2534. ;*    BreakPoint Address storage Table (BRKTBL) is examined and Breakpoint
  2535. ;*    is removed if Found. BreakPoint    is removed by bubbling up all bp
  2536. ;*    Addresses which    follow,    ditto for pass counts.
  2537. ;*
  2538. ;******************************************************************************
  2539.  
  2540. cbreak:    call    iedtbc
  2541.     ret    m        ;No Input ends command
  2542.     ld    a,(bps)        ;Fetch Breakpoint count
  2543.     or    a        ;Any if    effect
  2544.     ret    z        ;No
  2545.     ld    b,a        ;Temp Save count
  2546.     call    iarg        ;Extract Address to clear from Input Buffer
  2547.     ld    de,brktbl    ;BP Address storage Table
  2548.     jr    z,cbrk10
  2549.     ld    a,(prsbf)
  2550.     cp    '*'
  2551.     jp    nz,e???
  2552.     ld    a,(inbfnc)
  2553.     dec    a
  2554.     jp    nz,e???
  2555.     ld    (bps),a
  2556.     ret
  2557.  
  2558. cbrk10:    ld    a,(de)        ;Test LO Order Address for match
  2559.     cp    l
  2560.     inc    de
  2561.     jr    nz,cbrk20    ;No match - examine Next entry
  2562.     ld    a,(de)
  2563.     cp    h        ;Versus    HI Order bp Address
  2564. cbrk20:    inc    de
  2565.     inc    de        ;Bump past contents Save location
  2566.     jr    z,cbrk30    ;zero -    Found bp in Table
  2567.     djnz    cbrk10
  2568.     jp    e???        ;ERROR - Breakpoint not    Found
  2569. cbrk30:    ld    h,0ffh        ;Rewind    to Point to bp Address
  2570.     ld    l,-3
  2571.     add    hl,de        ;
  2572. è    ex    de,hl        ;DE - ptr to bp      HL - ptr to Next bp
  2573.     ld    a,b        ;Multiply Number of bps    remaining in Table
  2574.                 ;Times three bytes per entry
  2575.     add    a,a
  2576.     add    a,b
  2577.     ld    c,a        ;Init c    for ldir
  2578.     ld    a,b        ;Save Number of    bps remaining
  2579.     ld    b,0
  2580.     ldir            ;Bubble    up all remaining entries in Table
  2581.     ld    c,a        ;
  2582.     ld    hl,bps        ;Address of bp count
  2583.     ld    a,(hl)        ;
  2584.     dec    (hl)        ;Decrement system Breakpoint count
  2585.     sub    c        ;Compute relative Number of pass count Table
  2586.                 ;Entry we wish to clear
  2587.     add    a,a        ;Times two bytes per entry
  2588.     ld    l,a
  2589.     ld    h,b        ;Cheap clear
  2590.     ld    de,psctbl
  2591.     add    hl,de        ;Index into pass count Table
  2592.     ex    de,hl
  2593.     ld    hl,02
  2594.     add    hl,de        ;DE - ptr to pass count     HL - Next in Table
  2595.     sla    c        ;Number    of pass    counts to move
  2596.     ldir
  2597.     ld    a,(delim)    ;Recheck delimeter
  2598.     and    a
  2599.     jr    nz,cbreak    ;Not End of line terminator - clear more
  2600.     ret
  2601.     page
  2602. ;***********************************************************************
  2603. ;*
  2604. ;*     OBREAK:    Output all Breakpoints and associated pass counts to
  2605. ;*        console.  Search Symbol    Table for match, if Symbol Name
  2606. ;*        Found display it along with Address.
  2607. ;*
  2608. ;*     WBREAK:    wipe out (clear) all Breakpoints Currently in effect
  2609. ;*
  2610. ;*        entered:  b - zero
  2611. ;*
  2612. ;***********************************************************************
  2613.  
  2614. obreak:    ld    a,(bps)        ;Fetch BP count
  2615.     dec    a        ;Test for no Breakpoints
  2616.     ret    m        ;M - none
  2617.     ld    b,a        ;Save count
  2618. obrk00:    ld    hl,brktbl    ;Base of Breakpoint storage Table
  2619.     ld    e,b        ;Use Current Breakpoint    count as index
  2620.     ld    d,0        ;Clear
  2621.     add    hl,de        ;This is a three Byte Table
  2622.     add    hl,de
  2623.     add    hl,de
  2624.     ld    e,(hl)        ;Fetch LO Order    BP Address
  2625.     inc    hl
  2626.     ld    d,(hl)        ;Upper Address
  2627. è    ex    de,hl
  2628.     call    outadr        ;Display Address
  2629.     ex    de,hl        ;HL - Breakpoint Table
  2630.     call    fadr        ;Check Symbol Table for    Name match
  2631.                 ;   Symbol Table Pointer returned in de
  2632.                 ;   zero flag set if Found
  2633.     ld    a,(maxlen)
  2634.     ld    c,a
  2635.     dec    bc        ;Max Number of Chars in    a Symbol Name
  2636.     ex    de,hl        ;HL - Symbol Table Address if
  2637.     call    z,printb    ;Display Name if Found in Symbol Table
  2638.     ld    a,b
  2639.     add    a,a        ;BP Number times two
  2640.     ld    hl,psctbl    ;Base of pass count Table
  2641.     add    a,l
  2642.     ld    l,a
  2643.     jr    nc,obrk10
  2644.     inc    h
  2645. obrk10:    ld    e,(hl)        ;LO Order pass count
  2646.     inc    hl
  2647.     ld    d,(hl)        ;Upper byte
  2648.     ld    a,d        ;Test if pass count in effect
  2649.     or    e
  2650.     jr    z,obrk20    ;Z - no    pass count for this BP
  2651.     inc    c
  2652.     call    spaces        ;
  2653.     ex    de,hl
  2654.     call    outadr        ;Display pass count in hex
  2655. obrk20:    call    crlf
  2656.     ld    c,5
  2657.     call    spaces
  2658.     dec    b        ;Dec BP    count
  2659.     jp    p,obrk00
  2660.     ret
  2661.  
  2662.  
  2663.  
  2664. kdmp:    call    iedtbc        ;Let Uer Input Address of Memory to Display
  2665.     ret    m        ;No Input ends command
  2666.     call    iarg        ;Evaluate user Arg        
  2667.     jp    nz,e???
  2668.     ex    de,hl        ;DE - Save Memory Address
  2669.     call    iarg        ;Now Get Count
  2670.     ld    a,0 
  2671.     jr    nz,kdmp20    ;Error During Input - Display 00 Bytes
  2672.     or    h
  2673.     jp    nz,e???        ;Greater than 256 is ERROR
  2674.     ld    a,(maxlen)    ;Max Symbol Length
  2675.     ld    b,2        ;Assume Big Names
  2676.     cp    15        
  2677.     ld    a,18        ;Number of Disassembled Lines Displayed
  2678.     jr    z,kdmp00
  2679.     ld    b,3        ;Double Number of Lines One Extra Time
  2680. kdmp00:    add    a,a        ;Times Two
  2681.     djnz    kdmp00
  2682.     cp    l
  2683.     jr    c,kdmp20    ;If Number of Bytes Specified By User is Too
  2684.                 ;Large Then Use Default
  2685.     ld    a,l        ;Use value specified by user
  2686. kdmp20:    ld    (wnwtab),de
  2687.     ld    (wnwsiz),a
  2688.     ret
  2689.     page
  2690. ;**************************************************************************
  2691. è;*
  2692. ;*             begin/resume execution of user program
  2693. ;*
  2694. ;*    Address    entered:     execution begins at entered Address
  2695. ;*    no Address entered:  execution resumed at specified by Saved pc
  2696. ;*
  2697. ;*    Breakpoint Table examined:
  2698. ;*          -    memory contents    from each Address is removed from user
  2699. ;*        program    and Saved in Breakpoint    Table
  2700. ;*          -    rst 38 Instruction is placed at    each Breakpoint    Address
  2701. ;*        in user    program
  2702. ;*
  2703. ;*    user registers restored
  2704. ;***************************************************************************
  2705.  
  2706. go:    call    iedtbc        ;Query user for    execution Address
  2707.     ret    m        ;No - Input reprompt
  2708.     call    iarg
  2709.     jp    nz,e???        ;Error - invalid argument
  2710.     call    crlf
  2711.     call    crlf
  2712. g100:    ld    (jmplo),hl    ;Store execution Address
  2713.     ld    a,jp
  2714.     ld    (jmp),a        ;Set JP    Instruction
  2715.     ld    (jmp2jp),a    ;Just In Case 
  2716.     ld    a,(bps)        ;Check Breakpoint Count
  2717.     and    a
  2718.     jp    z,g600        ;Z - no    BPs in effect -    no restoration needed
  2719.     ld    b,a
  2720.     ld    hl,brktbl
  2721.     ld    c,0ffh
  2722. g300:    ld    e,(hl)
  2723.     inc    hl
  2724.     ld    d,(hl)        ;DE - Breakpoint Address removed from Table
  2725.     inc    hl        ;Point to contents Save    Byte in    Table
  2726.     ld    a,(de)
  2727.     ld    (hl),a
  2728.     ld    a,(jmplo)
  2729.     cp    e        ;Check if BP from Table    matches    Next PC
  2730.     jr    nz,g400        ;No match - set    Breakpoint
  2731.     ld    a,(jmphi)
  2732.     cp    d        ;Check HI Order    Next pc    Address
  2733.     jr    nz,g400        ;No match - set    BP
  2734.     ld    c,b        ;Set flag - Current PC Matches Breakpoint
  2735.     jr    g500
  2736. g400:    ld    a,rst38        ;Set RST38 Instruction
  2737.     ld    (de),a        ;Save User Byte    in BRKTBL
  2738. g500:    inc    hl
  2739.     djnz    g300        ;Examine all entries
  2740.     inc    c        ;Current PC Match Breakpoint?
  2741.     jp    z,g600        ;Z - NO (C Reg Not 0FFH)
  2742.     ld    a,(sbps)    ;Check Number of STEP Breakpoints
  2743. è    and    a        ;Tracing?
  2744.     jp    nz,g600        ;NZ - This is Trace
  2745.  
  2746.                 ;
  2747.                 ;PC Points to Address in Breakpoint Table
  2748.                 ;Next Instruction will not be executed where
  2749.                 ;it resides.  It will be moved to our internal
  2750.                 ;buffer (EXECBF) and executed there. Then we
  2751.                 ;set an RST38 at actual location in user 
  2752.                 ;program.  This allows us to debug loops in 
  2753.                 ;which only one BP is set.  Otherwise we would
  2754.                 ;not be able to set a BP at the address where
  2755.                 ;the PC points and debugging loops would be
  2756.                 ;impossible.      
  2757.     ld    hl,execbf
  2758.     ld    de,(jmplo)    ;DE - Pointer to Next Instruction to Execute
  2759.     ld    (jmplo),hl    ;Execute Buffer
  2760.     ld    b,4        ;Clear Execute Buffer
  2761. g505:    ld    (hl),nop
  2762.     inc    hl
  2763.     djnz    g505
  2764.     call    zlen00        ;Calculate Length
  2765.                 ;If Instruction Modifies PC Then ZLEN Lets Us
  2766.                 ;Know By Setting B Reg NZ and C Contains 
  2767.                 ;Instruction Length
  2768.  
  2769.     ld    (jropnd),hl    ;If This is a JR Instruction We Need to Save
  2770.                 ;Address Where We Will Be Jumping 
  2771.  
  2772. ;    ld    b,0        ;Clear B Regardless
  2773. ;    and    a
  2774. ;    jr    nz,g510        ;NZ -  A PC Modifying Instruction
  2775. ;    ld    h,d
  2776. ;    ld    l,e        ;HL - Next PC Address
  2777. ;    add    hl,bc        ;Point to Byte Following Next Instruction
  2778. ;    scf            ;Set Carry - Not A PC Modifier
  2779. ;g510:    ld    (jmp2),hl    ;Address of Next Inline    Instruction
  2780. ;    ld    a,jp
  2781. ;    ld    (jmp2jp),a    ;Set Jump to Next Inline Instruction
  2782.  
  2783.                 ;Default EXECBF Has Been Initialized:
  2784.                 ;
  2785.                 ;Four NOPs     
  2786.                 ;     JP   User Program 
  2787.                 ;     
  2788.     ex    de,hl        ;HL - PTR to User Instruction
  2789.     ld    de,execbf
  2790.     ld    a,(hl)        ;First Object Byte from    User Program
  2791.     ld    (hl),RST38    ;Replace
  2792.     push    bc        ;B - IF NZ This is a PC modifying Instruction
  2793.                 ;C - Number of Bytes of Object Code for This
  2794.                 ;    Instruction
  2795. g520:    ld    (de),a        ;Into Execute Buffer
  2796.     inc    de        ;
  2797.     inc    hl        ;Bump User Program Pointer
  2798.     ld    a,(hl)        ;Next Byte of Instruction from User Program
  2799.     dec    c
  2800.     jr    nz,g520
  2801.     pop    bc
  2802.                 ;The Four NOPs in EXECBF Have Now Been Replaced
  2803.                 ;By From One to Four Bytes of Actual User
  2804.                 ;Instruction.  If User Instruction Was Shorter
  2805.                 ;than Four Bytes the NOPs Remain and are 
  2806.                 ;Executed Until the Jump Back to the User 
  2807.                 ;Program at JMP2JP is Reached.
  2808.  
  2809.  
  2810.     ld    (jmp2),hl    ;Address of Next Inline Instruction Within
  2811.                 ;User Code    
  2812.  
  2813.     ex    de,hl        ;DE - Next Inline Instruction in User Program
  2814.     xor    a
  2815.     or    b
  2816.     jr    z,g600        ;Z - The Instruction in EXECBF is Not a PC 
  2817.                 ;Modifying Instruction
  2818.  
  2819.     ld    a,(execbf)    ;First Byte of Instruction
  2820.     dec    c        ;One Byte Instruction?
  2821.     jr    z,g600
  2822.     dec    c
  2823.     jr    z,g550        ;Two byter
  2824.     dec    c
  2825.     jr    nz,g600        ;NZ - Must be Four Byter
  2826.     ld    b,c        ;Clear for CPIR
  2827.     ld    c,Z803sl    ;Test for CALL Instruction
  2828.     ld    hl,Z803s    ;Load List of First Byte of Call Instructions
  2829.     cpir
  2830.     jr    nz,g600        ;NZ - Not Call
  2831.  
  2832.                 ;Moving CALL Instructions and Executing Them
  2833.                 ;Locally Requires Special Processing Because
  2834.                 ;the Z80 Will Store the Address PC+3 on the
  2835.                 ;Stack.  In This Case We Do Not Want the 
  2836.                 ;Address  EXECBF+3 on the Stack.  We Want the
  2837.                 ;Address of the Actual Location of the User
  2838.                 ;Instruction+3 on the Stack.  We Must Do This
  2839.                 ;By Simulating a CALL Instruction. We Use the
  2840.                 ;JP Instruction Which is Equivalent to the
  2841.                 ;CALL and We Also Push a Computed Return 
  2842.                 ;Address on to the User Stack Pointed to by 
  2843.                 ;SPREG.
  2844.  
  2845.     ld    bc,08        ;Point to JUMP Instruction Which is Equivalent
  2846.                 ;to CALL (CALL NZ = JP NZ)
  2847.     add    hl,bc
  2848.     ld    a,(hl)        ;Fetch Jump Object Byte 
  2849.     ld    hl,(spreg)    ;Push Next PC Onto User Stack
  2850.     dec    hl        ;Decrement User SP
  2851.     ld    (hl),d        ;DE - "Return Address"
  2852.     dec    hl
  2853.     ld    (hl),e
  2854.     ld    (spreg),hl
  2855.     ld    (execbf),a    ;Store JP OP Code    
  2856.     ld    hl,jmp2        ;If Conditional CALL and We Fall Thru
  2857.                 ;We Need to Go Back to Address of CALL
  2858.                 ;in User Program + 3
  2859. è    ld    (hl),e
  2860.     inc    hl
  2861.     ld    (hl),d
  2862.     jr    g600
  2863.                 ;If Next Instructiopn to Execute is a 
  2864.                 ;Relative Jump We Need to Replace it with
  2865.                 ;an Absolute Equivalent.  This is because
  2866.                 ;Having Relocated the User JR Instruction
  2867.                 ;Into EXECBF We Will Undoubtedly Be Out of
  2868.                 ;Range of the Destination.
  2869.  
  2870. g550:    ld    c,Z802cl    ;Check if This is Relative Jump
  2871.     ld    hl,Z802c
  2872.     and    a        ;Clear Carry
  2873.     cpir
  2874.     jr    nz,g600        ;Not a JR
  2875.     ld    a,c
  2876.     ld    bc,Z802c
  2877.     sbc    hl,bc
  2878.     dec    hl
  2879.     ld    bc,Z803c
  2880.     add    hl,bc        ;Point to Equivalent Absolute Jump
  2881.     and    a
  2882.     ld    a,(hl)
  2883.     ld    hl,execbf
  2884.     jr    nz,g555        ;NZ - Not Last in List (NOT DJNZ)
  2885.  
  2886.                 ;Replace DJNZ with  DEC   B
  2887.                 ;                JP    NZ,
  2888.              
  2889.     ld    (hl),05        ;Dec B Instruction
  2890.     inc    hl
  2891.     ld    a,0c2h        ;JP NZ Absolute
  2892. g555:    ld    (hl),a
  2893.     inc    hl
  2894.     ld    bc,(jropnd)    ;If This is a Conditional JR We Need the
  2895.                 ;Absolute Destination of the Jump                ;
  2896.     ld    (hl),c
  2897.     inc    hl
  2898.     ld    (hl),b
  2899. ;    ld    hl,jmp2
  2900. ;    ld    (hl),e
  2901. ;    inc    hl
  2902. ;    ld    (hl),d
  2903.  
  2904. g600:    ld    iy,(iyreg)    ;Restore User IY
  2905.     ld    ix,(ixreg)    ;Restore User IX
  2906.     ld    a,(rreg)
  2907.     ld    r,a        ;Restore User R    Reg
  2908.     ld    a,(ireg)
  2909.     ld    i,a        ;Restore User I    Reg
  2910.     ld    bc,(bcpreg)    ;Restore User Grade A Prime Regs
  2911.     ld    de,(depreg)
  2912.     ld    hl,(afpreg)
  2913.     push    hl
  2914.     pop    af
  2915.     ld    hl,(hlpreg)
  2916.     ex    af,af'
  2917.     exx
  2918.     ld    hl,(afreg)    ;Restore User Accumulator and Flag
  2919.     push    hl
  2920.     pop    af
  2921.     ld    bc,(bcreg)    ;Restore User bc
  2922.     ld    de,(dereg)    ;Restore User de
  2923.     ld    hl,(hlreg)    ;Restore User hl
  2924. è    ld    sp,(spreg)    ;Restore User sp
  2925.     jp    jmp
  2926.     page
  2927. ;******************************************************************************
  2928. ;*
  2929. ;*    STEP:  Single Step (trace) Routine
  2930. ;*
  2931. ;*    Call ZLEN to determine where to    set Breakpoint.
  2932. ;*
  2933. ;*        Pass:       DE -    Current    PC Address
  2934. ;*
  2935. ;*        Returned:  B:  Z - Next    Instruction will not modify PC.
  2936. ;*                   Set BP at Address specified by PC+length.
  2937. ;*
  2938. ;*               B: NZ - Next    Instruction will modify    PC (jumps,
  2939. ;*                   calls, and returns) thus set    BP at Address
  2940. ;*                   returned in HL.
  2941. ;*
  2942. ;*               C:     - Number of bytes in Current Instruction.
  2943. ;*
  2944. ;*        ZLEN handles secondary Breakpoint to set for all conditional
  2945. ;*        call, return, and jump Instructions.
  2946. ;*
  2947. ;*    Call BRK00 to set Breakpoint.
  2948. ;*
  2949. ;*        Pass:       B - Current Number of Breakpoints.
  2950. ;*              HL - Address at which    to set Breakpoint.
  2951. ;*
  2952. ;*    Entry Point STEP:    Entered by    user via (S)ingle step command.
  2953. ;*    Entry Point STEP40:  Entered by    Breakpoint handler - step count    nz
  2954. ;*
  2955. ;*    EXIT:    to GO routine to resume    execution.
  2956. ;*
  2957. ;******************************************************************************
  2958.  
  2959. step:    ld    a,0ffh
  2960.     ld    (wflag),a    ;Set trace subroutine flag on
  2961.     call    iedtbc        ;Query user for    trace count
  2962.     ld    hl,0001
  2963.     jp    m,step40    ;Null Input - step count of one
  2964.     call    prsr
  2965.     jp    nz,e???
  2966.     ld    a,(de)        ;First Character from parse Buffer
  2967.     sub    '/'
  2968.     ld    (wflag),a    ;May be    slash -    no subroutine tracing
  2969.     ld    hl,00
  2970.     jr    nz,step20
  2971.     ld    (de),a
  2972.     ld    a,(inbfnc)
  2973.     dec    a
  2974.     inc    hl
  2975.     jr    z,step40
  2976.     dec    hl
  2977. step20:    call    xval        ;Evaluate contents of parse Buffer
  2978.     jp    nz,e???
  2979. è    ld    de,(pcreg)
  2980.     ld    a,(de)        ;First Byte of op Code at Current PC
  2981.     cp    0C7H        ;Test for RST
  2982.     jp    z,e???        ;No tracing of RSTs 
  2983. step40:    ld    (nstep),hl    ;Save step count
  2984.     ld    hl,sbps        ;Set step flag nz - trace in effect
  2985.     inc    (hl)
  2986.     ld    de,(pcreg)    ;Fetch Current pc
  2987.     call    zlen00        ;Determine Number of bytes in Instruction
  2988.     inc    b        ;Test where to set Breakpoint
  2989.     djnz    step50        ;NZ - set at Address in    hl
  2990.     ex    de,hl
  2991.     add    hl,bc        ;Z - set at Address pc + Instruction length
  2992. step50:    ld    a,(bps)        ;Get Current Number of BPs
  2993.     ld    b,a        ;Pass to set BP    routine    in B reg
  2994.     ex    de,hl        ;DE - BP Address to set
  2995.     call    brk30
  2996.     ld    hl,(pcreg)    ;Resume    execution at Next pc
  2997.     xor    a
  2998.     or    b
  2999.     jp    nz,g100        ;NZ - collision    with user BP
  3000.     ex    de,hl
  3001.     ld    hl,sbps        ;Step BP set by    brk30 -    Bump count
  3002.     inc    (hl)
  3003.     ex    de,hl
  3004.     jp    g100
  3005.     page
  3006. ;******************************************************************************
  3007. ;*
  3008. ;*    ASMBLR:    Z80 Assembler
  3009. ;*
  3010. ;******************************************************************************
  3011.  
  3012. asmblr:
  3013.     call    ilin
  3014.     jp    nz,e???
  3015. asm000:    call    crlf
  3016.     ld    (zasmpc),hl    ;Save here as well
  3017.     call    zasm08        ;Disassemble First Instruction
  3018.  
  3019. asm005:
  3020.     ld    hl,(asmbpc)
  3021. asm010:    call    crlf
  3022.     call    outadr        ;Display Current assembly pc
  3023.     ld    c,22        ;
  3024.     call    spaces        ;Leave room for    object Code
  3025.     ld    a,3
  3026.     ld    hl,objbuf    ;zero scratch object Code Buffer
  3027. asm015:    ld    (hl),c
  3028.     inc    hl
  3029.     dec    a
  3030.     jp    p,asm015
  3031. è    ld    (oprn01),a    ;Init operand key values to 0ffh
  3032.     ld    (oprn02),a
  3033.     call    iedtbc        ;Get user Input
  3034.     ret    m        ;M - no    Input ends command
  3035.     call    cret
  3036.     call    prsr        ;Parse to obtain label
  3037.     ld    a,(hl)        ;Check Last Character
  3038.     cp    ':'
  3039.     jr    nz,asm040    ;No colon Found    - must be op Code
  3040.     ld    (hl),0        ;Erase colon
  3041.     ld    a,(de)        ;Fetch First Char of label from    parse Buffer
  3042.     cp    'A'
  3043.     jp    c,asm??L    ;Error - First Character must be alpha
  3044.     cp    'z'+1
  3045.     jp    nc,asm??L    ;Label error
  3046.     cp    'a'
  3047.     jr    nc,asm030
  3048.     cp    'Z'+1
  3049.     jp    nc,asm??L
  3050. asm030:    ld    hl,00
  3051.     ld    (isympt),hl    ;Clear Pointer
  3052.     call    isym        ;Attempt to insert Symbol into Symbol Table
  3053.     jp    nz,asm??T    ;Error - Symbol    Table full
  3054.     ld    (isympt),hl    ;Save Pointer to Symbol    value in Symbol    Table
  3055.     call    prsr        ;Extract opCode
  3056.     jp    m,asm005    ;M - statement contains    label only
  3057. asm040:    ld    a,(delim)    ;Check delimeter
  3058.     cp    ','        ;Check for invalid terminator
  3059.     jp    z,asm??O
  3060.     ld    c,73        ;Number    of Opcodes in Table as Index
  3061. asm050:    dec    c
  3062.     jp    m,asm??O    ;OpCode    not Found
  3063.     ld    b,0
  3064.     ld    hl,zopcnm    ;Table of opCode names
  3065.     add    hl,bc
  3066.     add    hl,bc        ;Index times four
  3067.     add    hl,bc
  3068.     add    hl,bc
  3069.     ld    de,prsbf    ;Start of parse    Buffer
  3070.     ld    b,4
  3071. asm060:    ld    a,(de)        ;Character from    parse Buffer
  3072.     and    a        ;Null?
  3073.     jr    nz,asm070    ;
  3074.     ld    a,' '        ;For comparison    purposes
  3075. asm070:    call    ixlt        ;Force upper case for compare
  3076.     cp    (hl)
  3077.     jr    nz,asm050    ;Mismatch - Next opCode    Name
  3078.     inc    de
  3079.     inc    hl
  3080.     djnz    asm060        ;Must match all    four
  3081.     ld    a,(de)        ;Null following    opCode?
  3082.     and    a
  3083.     jp    nz,asm??O    ;Error - opCode    more than 4 Characaters
  3084.     ld    hl,ikey        ;Relative position in Table is key value
  3085.     ld    (hl),c        ;Save opCode key value
  3086. è    call    prsr        ;Extract First operand
  3087.     jp    m,asm085    ;M - none
  3088.     call    oprn        ;Evaluate operand
  3089.     jr    nz,asm??U    ;Error - bad First operand
  3090.     ld    de,oprn01    ;
  3091.     call    opnv        ;Save operand value and    key
  3092.     ld    a,(delim)
  3093.     cp    ','
  3094.     jr    nz,asm085    ;Need comma for    two operands
  3095.     call    prsr        ;Extract second    operand
  3096.     jp    m,asm??S    ;Error - comma with no second operand
  3097.     cp    ','
  3098.     jp    z,asm??S    ;Illegal line termination
  3099.     call    oprn        ;Evaluate operand
  3100.     jr    nz,asm??U    ;Error - bad second operand
  3101.     ld    de,oprn02
  3102.     call    opnv        ;Save second operand value and key
  3103. asm085:    xor    a
  3104.     ld    c,a
  3105. asm090:    ld    hl,zopcpt    ;OpCode    Name Pointer Table
  3106.     ld    b,0
  3107.     add    hl,bc        ;Index into Table
  3108.     ld    a,(ikey)    ;Fetch opCode key value
  3109.     cp    (hl)        ;Check for match
  3110.     jr    nz,asm095    ;
  3111.     inc    h        ;Point to First    operand    Table
  3112.     ld    de,oprn01    ;Address of First operand key value
  3113.     call    opnm        ;Check validity
  3114.     jr    nz,asm095    ;No match - Next
  3115.     ld    b,a        ;Save modified key value
  3116.     inc    h        ;Point to second operand Table
  3117.     ld    de,oprn02    ;Address of second operand key value
  3118.     call    opnm
  3119.     jr    z,ibld        ;Match - attempt final resolution
  3120. asm095:    inc    c        ;Bump index
  3121.     jr    nz,asm090    ;NZ - check more
  3122. asm??U:    ld    a,'U'        ;Error
  3123.     jp    asm???
  3124.  
  3125.  
  3126.  
  3127.  
  3128. ibld:    ld    hl,objbuf    ;Object    Code temp Buffer
  3129.     ld    e,a        ;Save second operand key
  3130.     ld    a,(hl)        ;Check First Byte of object Buffer
  3131.     and    a        ;Null?
  3132.     ld    a,c        ;Instruction key to accumulator    regardless
  3133.     ld    c,e        ;Save second operand modified key
  3134.     jr    z,ibld00    ;Z - not ix or iy Instruction
  3135.     inc    hl        ;Point to Byte two of object Code
  3136. ibld00:    cp    40h
  3137.     jr    c,ibld55    ;C - 8080 Instruction
  3138.     cp    0a0h
  3139.     jr    nc,ibld10    ;Nc - not ed Instruction
  3140.     ld    (hl),0edh    ;Init Byte one of object Code
  3141. è    inc    hl
  3142.     cp    80h        ;Check which ed    Instruction we have
  3143.     jr    c,ibld55    ;C - this is exact object byte
  3144.     add    a,20h        ;Add bias to obtain object byte
  3145.     jr    ibld55
  3146. ibld10:    cp    0E0H
  3147.     jr    nc,ibld20
  3148.     add    a,20h        ;8080 type - range 0c0h    to 0ffh
  3149.     jr    ibld55        ;Object    Byte built
  3150. ibld20:    cp    0E8H        ;
  3151.     jr    c,ibld50    ;8 bit reg-reg arithmetic or logic
  3152.     cp    0F7H        ;Check for halt    disguised as  ld (hl),(h
  3153.     jr    nz,ibld30    ;
  3154.     ld    a,76H        ;Halt object Code
  3155.     jr    ibld55
  3156. ibld30:    cp    0F8H
  3157.     jr    nc,ibld50    ;8 bit reg-reg load
  3158.     ld    d,a        ;Temp Save Instruction key value
  3159.     ld    a,(objbuf)
  3160.     and    a        ;Check for previously stored First object byte
  3161.     ld    a,d
  3162.     ld    (hl),0cbh    ;Init Byte regardless
  3163.     inc    hl
  3164.     jr    z,ibld40    ;Z - not ix or iy Instruction
  3165.     inc    hl        ;Bump object Code Pointer - this is four byter
  3166. ibld40:    add    a,0a8h        ;Add bias for comparison purposes
  3167.     cp    98h
  3168.     jr    c,ibld50    ;C - shift or rotate Instruction
  3169.     rrca
  3170.     rrca
  3171.     and    0c0h        ;This is skeleton for bit instuctions
  3172.     jr    ibld55
  3173. ibld50:    add    a,a        ;Form skeleton
  3174.     add    a,a
  3175.     add    a,a
  3176.     add    a,80h
  3177. ibld55:    ld    (hl),a        ;Store object byte
  3178.     xor    a
  3179.     or    c        ;Second    operand    need more processing?
  3180.     ld    de,oprn02
  3181.     call    nz,rslv        ;Resolve second    operand
  3182.     jp    nz,asm??V    ;Error - invalid operand size
  3183.     ld    de,oprn01
  3184.     ld    a,b
  3185.     and    a        ;First operand resolved?
  3186.     call    nz,rslv        ;More work to do
  3187.     jp    nz,asm??V    ;Error - invalid operand size
  3188.     ld    a,(ikey)
  3189.     sub    67        ;Org directive?
  3190.     jr    nz,ibld60
  3191.     ld    d,(hl)
  3192.     dec    hl
  3193.     ld    e,(hl)
  3194.     ex    de,hl
  3195.     jp    asm000        ;Z - org directive
  3196. èibld60:    ld    de,objbuf
  3197.     jr    c,ibld70    ;C - Instruction  nc - directive
  3198.     ld    b,a        ;Number    of bytes for defb or defw or ddb
  3199.     inc    de        ;Point past erroneous assembled    op Code
  3200.     inc    de
  3201.     sub    3        ;Test for ddb
  3202.     jr    c,ibld75    ;C - must be defb or defw
  3203.     dec    a
  3204.     jr    nz,ibld65    ;NZ - must be ddb
  3205.     ld    d,(hl)        ;Must be equ
  3206.     dec    hl
  3207.     ld    e,(hl)
  3208.     ld    hl,(isympt)    ;Fetch Pointer to entry    in Symbol Table
  3209.     ld    a,h
  3210.     or    l
  3211.     jp    z,asm??U    ;Error - no label on equ statement
  3212.     ld    (hl),d
  3213.     dec    hl
  3214.     ld    (hl),e        ;Store value of    Symbol in Symbol Table
  3215.     ld    c,6
  3216.     call    spaces
  3217.     ld    a,d
  3218.     call    othxsp
  3219.     ld    a,e
  3220.     call    othxsp
  3221.     jp    asm005        ;Ready for Next    Input
  3222. ibld65:    dec    b        ;Set count of object bytes to 2
  3223.     ld    c,(hl)        ;Exchange hi and LO Order bytes    for ddb
  3224.     dec    hl
  3225.     ld    a,(hl)
  3226.     ld    (hl),c        ;New hi    order
  3227.     inc    hl
  3228.     ld    (hl),a        ;New hi    order replaces old LO Order
  3229.     jr    ibld75
  3230. ibld70:    call    zlen00        ;Compute length    of Instruction in bytes
  3231.     ld    b,c        ;B - Number of bytes of    object Code
  3232. ibld75:    ld    hl,(asmbpc)
  3233.     call    outadr        ;Re-display Current location counter
  3234. ibld80:    ld    a,(de)        ;Move from scratch object Buffer
  3235.     ld    (hl),a        ;Into Address Pointed to by location counter
  3236.     inc    hl
  3237.     inc    de
  3238.     call    othxsp        ;Display each object Code byte
  3239.     djnz    ibld80
  3240. ibld90:    ld    (asmbpc),hl
  3241.     jp    asm005        ;Next Input from user
  3242.  
  3243.  
  3244.  
  3245.  
  3246. opnm:    ld    a,(de)        ;Key value computed by operand routine
  3247.     xor    (hl)        ;Compare with Table operand Table entry
  3248.     ret    z        ;True match of operand key values
  3249.     xor    (hl)        ;Restore
  3250.     add    a,a        ;86 all    no operand key values (0ffh)
  3251. è    ret    m
  3252.     ld    a,(hl)        ;Fetch Table entry
  3253.     and    7FH        ;Sans paren flag for comparison    purposes
  3254.     cp    1bh        ;Check Table entry 8 bit - 16 bit - $ rel ?
  3255.     jr    c,opnm00    ;C - none of the above
  3256.     ld    a,(de)        ;Fetch computed    key
  3257.     xor    (hl)        ;Compare with paren flags
  3258.     ret    m        ;Error - paren mismatch
  3259.     ld    a,(de)        ;Fetch key once    more
  3260.     and    7FH        ;Remove    paren flag
  3261.     cp    17H        ;Computed as 8 bit - 16    bit - $    rel?
  3262.     jr    z,opnm40    ;So far    so good
  3263.     ret            ;
  3264. opnm00:    cp    19h        ;Check for 8 bit reg
  3265.     jr    nc,opnm20    ;8 bit register    match
  3266.     cp    18h        ;Table says must be HL - ix - iy
  3267.     ret    nz        ;Computed key disagrees
  3268.     ld    a,(de)        ;Fetch computed    key
  3269.     and    7        ;Computed as hl    - ix - iy ?
  3270.     ret    nz        ;No
  3271. opnm10:    ld    a,(de)        ;Fetch computed    key
  3272.     xor    (hl)
  3273.     ret    m        ;Error - paren mismatch    on HL -    ix - iy
  3274.     jr    opnm40
  3275. opnm20:    ld    a,(de)        ;Fetch computed    key of 8 bit reg
  3276.     and    a        ;
  3277.     jr    nz,opnm30    ;NZ - not (hl)
  3278.     dec    a        ;Error - 8 bit (hl) missing parens
  3279.     ret
  3280. opnm30:    cp    8        ;Test user entered valid 8 bit reg
  3281.     jr    c,opnm40    ;C - ok
  3282.     and    a        ;Test if no carry caused by paren flag
  3283.     ret    p        ;Error - this is not 8 bit reg with parens
  3284.     and    7        ;Psuedo    8 bit reg: (hl)    (ix) (iy)?
  3285.     ret    nz        ;No
  3286. opnm40:    ld    a,(hl)        ;Fetch Table entry
  3287.     and    7FH
  3288.     sub    18h        ;Make values 18    thru 1f    relative zero
  3289.     cp    a        ;zero means match
  3290.     ret
  3291.  
  3292. rslv:    dec    a        ;
  3293.     jr    z,rslv00    ;Z - 8 bit reg (bits 0-2 of object byte)
  3294.     dec    a        ;
  3295.     jr    nz,rslv20    ;NZ - not 8 bit    reg (bits 3-5 of object    byte)
  3296.     dec    a        ;Make neg to indicate shift left required
  3297. rslv00:    ld    c,a
  3298.     ld    a,(de)        ;Fetch computed    operand    key
  3299.     and    07        ;Lo three bits specify reg
  3300.     xor    6        ;Create    true object Code bits
  3301.     inc    c        ;Test if bits 0-2 or bits 3-5
  3302.     jr    nz,rslv10    ;NZ - 0    thru 2
  3303.     add    a,a
  3304.     add    a,a
  3305.     add    a,a
  3306. èrslv10:    or    (hl)        ;Or with skeleton
  3307.     ld    (hl),a        ;Into scratch object Buffer
  3308.     cp    a        ;Set zero - no error
  3309.     ret
  3310. rslv20:    inc    de        ;Point to low order of operand value
  3311.     ld    c,(hl)        ;C - Current skeleton  (if needed)
  3312.     inc    hl        ;Bump object Code Buffer Pointer
  3313.     dec    a
  3314.     jr    nz,rslv30    ;NZ - not relative jump
  3315.     ex    de,hl        ;Save object Code Pointer in de
  3316.     ld    a,(hl)        ;
  3317.     inc    hl
  3318.     ld    h,(hl)
  3319.     ld    l,a        ;HL - operand value computed by    xval
  3320.     ld    a,b
  3321.     ld    bc,(asmbpc)    ;Current location counter
  3322.     inc    bc
  3323.     inc    bc
  3324.     sbc    hl,bc        ;Calculate displacement    from Current counter
  3325.     ex    de,hl        ;DE - displacement  HL - object    Code Pointer
  3326.     ld    b,a        ;Restore b reg
  3327.     ld    a,e        ;LO Order displacement
  3328.     inc    d        ;Test HI Order
  3329.     jr    z,rslv25    ;Must have been    ff (backward displacement)
  3330.     dec    d
  3331.     ret    nz        ;Error - HI Order not zero or ff
  3332.     cpl            ;Set sign bit for valid    forward    displacement
  3333. rslv25:    xor    80h        ;Toggle    sign
  3334.     ret    m        ;Error - sign bit disagrees with upper byte
  3335.     ld    (hl),e        ;Store displacement object byte
  3336.     cp    a        ;Set zero flag - no errors
  3337.     ret
  3338. rslv30:    dec    a
  3339.     jr    nz,rslv40    ;NZ - not 8 bit    immediate
  3340.     ld    a,36h        ;Test for reg indirect - (hl),nn
  3341.     cp    c
  3342.     jr    nz,rslv35    ;
  3343.     ld    a,(objbuf)    ;Test First object byte
  3344.     cp    c
  3345.     jr    z,rslv35    ;Z - (hl),nn
  3346.     inc    hl        ;Must be (ix+index),nn    or  (iy+index),nn
  3347. rslv35:    ld    a,(de)        ;Move LO Order operand value to    object Buffer
  3348.     ld    (hl),a
  3349.     inc    de
  3350.     ld    a,(de)        ;Test HI Order
  3351.     and    a        ;
  3352.     ret    z        ;Z - must be 0 thru +255
  3353.     inc    a        ;Error if not -1 thru -256
  3354.     ret
  3355. rslv40:    dec    a
  3356.     jr    nz,rslv50    ;NZ - not 16 bit operand
  3357.     ld    a,(de)        ;Move both bytes of operand to object Buffer
  3358.     ld    (hl),a
  3359.     inc    hl
  3360.     inc    de
  3361. è    ld    a,(de)        ;Byte two
  3362.     ld    (hl),a
  3363.     cp    a        ;Set zero flag - no errors of course
  3364.     ret
  3365. rslv50:    dec    a        ;Test restart Instruction or bit Number
  3366.     jr    nz,rslv60    ;NZ - bit or interrupt mode Number
  3367.     ld    a,(de)        ;Check restart value specified
  3368.     and    0C7H        ;Betweed 0 and 38h?
  3369.     ret    nz        ;Error
  3370.     ld    a,(de)        ;Fetch LO Order    operand    value
  3371.     or    0C7H        ;Or with Instruction skeleton
  3372.     dec    hl
  3373.     ld    (hl),a        ;Rewind    object Code Pointer
  3374.     inc    de
  3375.     ld    a,(de)        ;Check HI Order    operand    value
  3376.     and    a        ;Error if not zero
  3377.     ret
  3378. rslv60:    dec    hl        ;Rewind    object Code Buffer Pointer
  3379.     ld    a,(de)
  3380.     and    0f8h        ;Ensure    bit Number in range 0 -    7
  3381.     ret    nz        ;Error
  3382.     ld    a,(ikey)    ;Fetch opCode key value
  3383.     sub    13h        ;Is this bit Number of interrupt mode Number?
  3384.     ld    a,(de)        ;Fetch operand value regardless
  3385.     jr    nz,rslv70    ;NZ - bit Number
  3386.     ld    (hl),46h
  3387.     and    03        ;Im 0?
  3388.     ret    z
  3389.     ld    (hl),56h
  3390.     dec    a        ;Im 1?
  3391.     ret    z
  3392.     ld    (hl),5eh
  3393.     dec    a        ;Error if not im 2
  3394.     ret
  3395. rslv70:    add    a,a        ;Shift bit Number left three
  3396.     add    a,a
  3397.     add    a,a
  3398.     or    (hl)        ;Or with skeleton
  3399.     ld    (hl),a
  3400.     cp    a        ;Indicate no error
  3401.     ret
  3402.  
  3403.  
  3404.  
  3405. oprn:    ld    bc,22        ;Count of reserved operand
  3406. oprn00:    ld    de,prsbf    ;Buffer    contains operand
  3407.     ld    a,(hl)        ;Last Character    of operand in parse Buffer
  3408.     sub    ')'
  3409.     jr    nz,oprn20    ;Not paren
  3410.     ld    (hl),a        ;Remove    trailing paren - replace with null
  3411.     ld    a,(de)        ;Check First Character of parse    Buffer
  3412.     sub    '('
  3413.     ret    nz        ;Error - unbalanced parens
  3414.     ld    (de),a        ;Remove    leading    paren -    replace    with null
  3415.     inc    de        ;Point to Next Character in parse Buffer
  3416. èoprn20:    ld    hl,zopnm    ;Index into reserved operand Name Table
  3417.     ld    a,c
  3418.     add    a,a        ;Index times two
  3419.     add    a,l
  3420.     ld    l,a
  3421.     jr    nc,oprn25
  3422.     inc    h
  3423. oprn25:    ld    a,(de)        ;From parse Buffer
  3424.     call    ixlt        ;Translate to upper case for compare
  3425.     cp    (hl)        ;Versus    Table entry
  3426.     inc    de
  3427.     jr    nz,oprn70    ;No match - check Next
  3428.     ld    a,(de)        ;Check second Character
  3429.     call    ixlt        ;Translate to upper case
  3430.     and    a        ;If null - this    is one Character reg Name
  3431.     jr    nz,oprn30
  3432.     ld    a,' '        ;For comparison    purposes
  3433. oprn30:    inc    hl        ;Bump Table Pointer
  3434.     sub    (hl)
  3435.     jr    nz,oprn70    ;No match - check Next
  3436.     inc    de        ;Have match - Bump Buffer Pointer
  3437.     or    b        ;
  3438.     ret    nz        ;NZ - mreg calling
  3439.     ld    a,c        ;Check index value
  3440.     and    07
  3441.     jr    nz,oprn80    ;Not hl    ix iy -    check for residue
  3442.     ld    a,(de)        ;
  3443.     call    oprtor        ;Check for expression operator
  3444.     jr    nz,oprn85    ;No operator but not End of operand
  3445.     ld    a,ix.. or iy..    ;Special ix iy hl processing
  3446.     and    c        ;Test for index    reg
  3447.     jr    z,oprn35    ;Z - must be hl
  3448.     and    10h        ;Transform index into 0ddh or 0fdh
  3449.     add    a,a
  3450.     add    a,0ddh        ;A - First byte    of index reg opCode
  3451. oprn35:    ld    c,a        ;Temp Save First object    byte
  3452.     ld    hl,objbuf
  3453.     xor    (hl)
  3454.     jr    z,oprn40    ;Z - First operand matches second
  3455.     cp    c        ;
  3456.     ret    nz        ;Illegal ix iy hl combination
  3457.     ld    a,(oprn01)
  3458.     and    a        ;Test if index reg was First operand
  3459.     jr    nz,oprn40
  3460.     dec    a        ;Error - hl illegal as second
  3461.     ret
  3462.  
  3463.  
  3464. oprn40:    ld    (hl),c        ;Init First Byte of object Code
  3465.     ld    a,(prsbf)
  3466.     and    a        ;Check for previously removed parens
  3467.     ld    a,c        ;
  3468.     ld    c,0
  3469.     jr    nz,oprn80    ;No parens - no    indexed    displacement
  3470.     and    a        ;Check for ix or iy indexed Instruction
  3471. è    jr    z,oprn80    ;Z - not index reg Instruction
  3472.  
  3473.     sbc    hl,hl        ;Clear hl
  3474.     ld    a,(de)        ;Index reg displacement    processing
  3475.     and    a        ;Test for default displacement
  3476.     call    nz,xval        ;Not zero - evaluate
  3477.     jr    nz,oprn85    ;NZ - displacement in error
  3478.     ld    c,00
  3479.     ld    a,l
  3480.     ld    (objbuf+2),a    ;Displacement always third byte
  3481.     inc    h        ;Check upper Byte of index value
  3482.     jr    z,oprn50    ;Must have been    0ffh
  3483.     dec    h        ;
  3484.     ret    nz        ;Error - index not -128    to +127
  3485.     cpl
  3486. oprn50:    xor    80h        ;Check sign bit
  3487.     ret    m        ;Bit on    - index    out of range
  3488.     cp    a        ;No error - set    zero flag
  3489.     ret
  3490. oprn70:    dec    c        ;Decrement reserved operand Table index
  3491.     jp    m,oprn85    ;M - not a reserved operand
  3492.     dec    de        ;Rewind    parse Buffer Pointer
  3493.     jp    oprn20        ;Next Table entry
  3494. oprn80:    ld    a,(de)        ;Check for End of parse    Buffer
  3495.     and    a
  3496.     ret    z        ;Found End of line null
  3497. oprn85:    ld    de,prsbf    ;Rewind    to start of Input
  3498.     xor    a
  3499.     or    b        ;
  3500.     ret    nz        ;NZ - this was mreg calling
  3501.     sbc    hl,hl        ;Clear hl
  3502.     call    xval        ;Evaluate operand
  3503.     ld    c,17h        ;Assume    numeric    operand    Found
  3504.     ret
  3505.  
  3506.  
  3507. xval:    ld    a,(de)        ;Check First Char of parse Buffer
  3508.     and    a
  3509.     jr    nz,xval00    ;
  3510.     inc    de        ;Bump past previously removed paren
  3511. xval00:    ld    (mexp),hl    ;Init expression accumulator
  3512.     xor    a
  3513.     ld    (base10),a    ;Clear upper digit decimal accumulator
  3514.     sbc    hl,hl        ;Clear HL
  3515.     ld    (fndsym),hl    ;Clear Symbol Found Flag
  3516.     ld    (pass2),hl
  3517. xval05:    ld    a,(de)        ;Char from parse Buffer
  3518.     call    ixlt        ;Translate to upper case
  3519.     ld    c,a        ;Save Character
  3520.     inc    de        ;Bump parse Buffer Pointer
  3521.     cp    '0'        ;Check for valid ASCII hex digit
  3522.     jr    c,xval25
  3523.     cp    ':'
  3524.     jr    c,xval15
  3525.     cp    'A'
  3526.     jr    c,xval25
  3527.     cp    'G'
  3528. è    jr    nc,xval25
  3529.     xor    a        ;Check Number entered flag (b reg sign bit)
  3530.     or    b
  3531.     jp    m,xval10    ;M - this was not First    Char
  3532.     ld    a,(symflg)    ;Check if Symbol Table present in memory
  3533.     and    a
  3534. xval10:    ld    a,c        ;Input Character back to accumulator
  3535.     jp    p,xval25    ;P - have Symbol Table or invalid hex digit
  3536.     sub    7
  3537. xval15:    sub    '0'        ;Ascii hex to hex nibble
  3538.     add    a,a        ;Shift left five - hi bit of nibble to carry
  3539.     add    a,a
  3540.     add    a,a
  3541.     add    a,a
  3542.     add    a,a
  3543.     ld    c,4        ;Loop count
  3544. xval20:    adc    hl,hl        ;HL left into carry - rotate carry into    hl
  3545.     adc    a,a        ;Next bit of nibble into carry
  3546.     dec    c
  3547.     jr    nz,xval20
  3548.     ld    (base10),a    ;Store what was    shifted    left out of hl
  3549.     ld    a,80h        ;Set sign of b - Number    entered    flag
  3550.     or    b
  3551.     ld    b,a
  3552.     jr    xval05        ;Next Character
  3553.  
  3554. xval25:    call    oprtor        ;Have expression operator?
  3555.     jr    z,xval30
  3556.     ld    a,(pass2)
  3557.     and    a
  3558.     ret    nz
  3559.     ld    a,(pass2+1)
  3560.     and    a
  3561.     jp    z,xval35
  3562.     ret
  3563.  
  3564. xval30:    xor    a
  3565.     or    b        ;Check Number Entered Flag
  3566.     ld    a,c        ;Restore Unmodified Input Character to A
  3567.     jp    nz,xval90    ;NZ - take care    of previous operator
  3568.     and    a        ;End of    line null?
  3569.     ret    z        ;
  3570.     ld    b,c        ;This operator was First Char of parse Buffer
  3571.     jr    xval05        ;Extract what follows this leading operator
  3572.  
  3573. xval35:    ld    a,c        ;Recover Character
  3574.     cp    '#'        ;Decimal processing?
  3575.     jr    nz,xval50    ;NZ - not decimal
  3576.     ld    a,b        ;Check Number entered flag
  3577.     xor    80h        ;Toggle
  3578.     ret    m        ;Error - pound sign with no Number
  3579.     ld    b,a
  3580.     push    bc
  3581.     push    de
  3582.     ex    de,hl        ;Save hex Number in de
  3583.     ld    hl,base10
  3584.     ld    a,6
  3585.     cp    (hl)        ;Check ten thousands digit
  3586.     jr    c,xval40    ;Error - obviously greater than    65535
  3587.     rrd            ;Nibble    to accumulator
  3588.      inc    hl        ;
  3589.     ld    (hl),d        ;Store hex Number in temp Buffer
  3590.     inc    hl
  3591. è    ld    (hl),e        ;LO Order hex Number
  3592.     dec    hl        ;Point back to upper byte
  3593.     ld    e,a        ;
  3594.     xor    a
  3595.     ld    d,a        ;DE - hex nibble
  3596.     call    bcdx        ;Convert HI Order byte
  3597.     jr    nz,xval40    ;NZ - error detected during conversion
  3598.     inc    hl        ;Bump to lo Byte to convert
  3599.     call    bcdx
  3600.     ex    de,hl        ;HL - converted    value
  3601. xval40:    pop    de
  3602.     pop    bc
  3603.     jr    z,xval65    ;Z - no    errors detected
  3604.     ret
  3605.  
  3606.  
  3607.  
  3608. xval50:    cp    QUOTE        ;Ascii literal processing
  3609.     jr    nz,xval60    ;NZ - not QUOTE
  3610.     ex    de,hl        ;
  3611.     ld    e,(hl)        ;Fetch literal from Buffer
  3612.     inc    hl
  3613.     cp    (hl)        ;Trailing QUOTE    Found?
  3614.     jr    z,xval55    ;Found
  3615.     ld    d,e        ;Make literal just fetch HI Order of operand
  3616.     ld    e,(hl)        ;Fetch new literal as LO Order
  3617.     inc    hl
  3618.     cp    (hl)        ;Trailing QUOTE?
  3619.     ret    nz        ;Error - more than two Chars between quotes
  3620. xval55:    ex    de,hl        ;DE - parse Buffer ptr     HL - operand
  3621.     inc    de        ;Bump past trailing QUOTE
  3622.     jr    xval65
  3623.  
  3624.  
  3625. xval60:    dec    de        ;Point to start    of operand in parse Buffer
  3626.     ld    (pass2),de
  3627.     call    fsym        ;Search    Symbol Table
  3628.     jp    z,xval62    ;Symbol    Found
  3629.     ld    a,(de)
  3630.     inc    de
  3631.     cp    '$'        ;Check for PC Relative Expression
  3632.     jp    nz,xval61
  3633.     ld    hl,(asmbpc)    ;Current Location Value    is Expression Value
  3634.     jr    xval65
  3635.                 ;Symbol Not Found - Retry Evaluation Process
  3636.                 ;with PASS2 Flag SET.  Now Token Must be a
  3637.                 ;Valid Hex Digit or Error 
  3638. xval61:    ld    de,(pass2)    
  3639.     ld    a,b
  3640.     or    80H        ;Set Sign in B - Valid Digit Detected Which
  3641.                 ;Tells XVAL This Must Be Hex Number
  3642.     ld    b,a
  3643.     sbc    hl,hl        ;Clear Hex Number Accumulator
  3644.     jp    xval05
  3645. xval62:    ld    a,(maxlen)    ;Point to Last Byte of Sym Table Entry
  3646.     or    l
  3647.     ld    l,a
  3648.     ld    a,(hl)        ;HI Order Symbol Address
  3649.     dec    hl
  3650.     ld    l,(hl)        ;LO Order
  3651.     ld    h,a
  3652. xval65:    ld    a,b        ;Check Number entered flag
  3653.     and    a
  3654.     ret    m        ;Error - numbers entered previous to Symbol
  3655.     xor    80h        ;Toggle    flag
  3656.     ld    b,a
  3657.     ld    a,(de)        ;Check Char following Symbol Name in Buffer
  3658.     ld    c,a        ;Make it new Current Character
  3659. è    inc    de        ;
  3660.     jp    xval30
  3661.  
  3662.  
  3663.  
  3664.  
  3665.  
  3666. xval90:    ld    c,a        ;Temp Save operator
  3667.     ld    a,80h        ;Toggle    Number entered flag
  3668.     xor    b
  3669.     ret    m        ;Return    nz - consecutive operators
  3670.     ld    b,c        ;New on    deck operator
  3671.     cp    '-'        ;Test Last operator
  3672.     push    de        ;Save Buffer Pointer
  3673.     jr    nz,xval95    ;NZ - addition
  3674.     ex    de,hl
  3675.     sbc    hl,hl        ;Clear
  3676.     sbc    hl,de        ;Force Current value neg by subtraction from 0
  3677. xval95:    ex    de,hl
  3678.     ld    hl,(mexp)    ;Fetch accumulated operand total
  3679.     add    hl,de        ;Add in    Current
  3680.     pop    de        ;Restore Buffer    Pointer
  3681.     ld    a,b        ;Check operator    that got us here
  3682.     and    a        ;End of    line null?
  3683.     jp    nz,xval00    ;No -
  3684.     ret            ;Operand processing complete
  3685.  
  3686.  
  3687.  
  3688. fsym:
  3689.     ld    hl,(06)        ;DE - Buffer   HL - Symbol Table
  3690. fsym00:    ld    a,(maxlen)
  3691.     and    l        ;
  3692.     ld    c,a
  3693.     ld    a,b        ;Temp Save
  3694.     ld    b,0
  3695.     ex    de,hl        ;DE - Symbol Table ptr    HL - parse Buffer
  3696.     sbc    hl,bc        ;Rewind    parse Buffer to    start of Symbol
  3697.     ex    de,hl        ;DE - parse Buffer  HL - Symbol    Table Pointer
  3698.     ld    b,a        ;Restore b reg
  3699.     ld    a,(maxlen)
  3700.     or    l
  3701.     ld    l,a
  3702.     inc    hl        ;Next Block of Symbol Table
  3703.     ld    a,(hl)        ;First Character of Symbol Name
  3704.     dec    a        ;
  3705.     ret    m        ;End of    Table
  3706.     ld    a,(maxlen)
  3707.     dec    a
  3708.     ld    c,a        ;Chars per Symbol 
  3709. fsym10:    ld    a,(de)        ;Fetch Char from Buffer
  3710.     call    oprtor
  3711.     jr    nz,fsym20    ;NZ - not operator or End of line null
  3712.     ld    a,(hl)
  3713. è    and    a        ;Null means End    of Symbol Name in Symbol Table
  3714.     jr    nz,fsym00    ;
  3715.     ld    (fndsym),hl    ;Set Symbol Found Flag NZ -
  3716.     ret
  3717. fsym20:    cp    (hl)
  3718.     jr    nz,fsym00
  3719.     inc    hl
  3720.     inc    de
  3721.     dec    c
  3722.     jr    nz,fsym10
  3723.     ld    (fndsym),hl    ;Set Symbol Found Flag NZ -
  3724. fsym30:    ld    a,(de)
  3725.     call    oprtor
  3726.     ret    z
  3727.     inc    de
  3728.     jr    fsym30
  3729.  
  3730.  
  3731.  
  3732. isym:    call    fsym        ;Search    for Symbol in Table
  3733.     jr    z,isym00    ;Z - Symbol Found
  3734.     ld    a,(hl)        ;Test for empty    slot in    Table
  3735.     and    a
  3736.     ret    nz        ;Symbol    Table full
  3737.     ld    (symflg),a    ;Indicate non-empty Symbol Table
  3738. isym00:    ld    a,(maxlen)    ;Rewind    Point to start of Table    entry
  3739.     ld    c,a
  3740.     cpl    
  3741.     and    l
  3742.     ld    l,a
  3743.     ex    de,hl        ;DE - Pointer to start of Symbol
  3744.     ld    hl,prsbf
  3745.     ld    b,0        ;Move Symbol from parse    Buffer to Table
  3746.     dec    c
  3747.     ldir
  3748.     ld    hl,(asmbpc)    ;Fetch value of    Symbol
  3749.     ex    de,hl        ;HL - Pointer to Address storage
  3750.     ld    (hl),e        ;LO Order Current location into    Table
  3751.     inc    hl
  3752.     ld    (hl),d        ;Upper byte
  3753.     xor    a
  3754.     ret
  3755.     page
  3756. ;******************************************************************************
  3757. ;*
  3758. ;*    PRSR:    command    line parse routine
  3759. ;*
  3760. ;*        PRSR will extract one argument from the    Input Buffer (INBF) and
  3761. ;*        write it into the parse    Buffer (PRSBF).    An argument is treated
  3762. ;*        as starting with the First non-delimeter Character encountered
  3763. ;*        in the Input Buffer and    ends with the Next delimeter Found.
  3764. ;*        All intervening    Characters between the two delimeters are
  3765. ;*        treated    as the argument    and are    moved to PRSBF.
  3766. ;*
  3767. ;*        As each    Character is from INBF a zero is written back to re-
  3768. ;*        place it.  Thus    a program which    needs to extract multiple args
  3769. ;*        need not Save Pointers in between calls    since PRSR is trained
  3770. ;*        to strip leading delimeters while looking for the start    of an
  3771. ;*        argument:
  3772. ;*
  3773. ;*                 DELIMETERS: null, space, comma
  3774. ;*
  3775. ;*    EXIT:        DE - starting Address of parse Buffer
  3776. ;*             B - sign bit: set if unbalanced parens, else sign reset
  3777. ;*             bits 6-0: Number of Chars in the parse    Buffer
  3778. ;*             A - actual    delimter Char which caused to terminate
  3779. ;*             F - zero flag set if no error
  3780. ;*        QUOFLG - set equal to ASCII QUOTE if at    leeat one QUOTE    Found
  3781. ;*
  3782. ;*    ERROR EXIT:  F - zero flag reset
  3783. ;*
  3784. è;******************************************************************************
  3785.  
  3786. prsr:    xor    a
  3787.     ld    (quoflg),a    ;Clear QUOTE flag
  3788.     ld    hl,prsbf    ;Start of parser scratch Buffer
  3789.     ld    b,prsbfz    ;Buffer    size
  3790.     ld    c,b
  3791. prsr10:    ld    (hl),0        ;Clear parse Buffer to nulls
  3792.     inc    hl
  3793.     djnz    prsr10
  3794.     ld    hl,prsbf    ;Start of parse    Buffer
  3795.     ld    de,inbf        ;Start of Input    Buffer
  3796.     ld    c,inbfl        ;Max size of Input Buffer
  3797. prsr20:    ld    a,(de)        ;From Input Buffer
  3798.     ex    de,hl
  3799.     ld    (hl),0        ;Erase as we pick from Input Buffer
  3800.     ex    de,hl
  3801.     dec    c        ;Decrement Buffer size tally
  3802.     ret    m        ;Error -  End of Input Buffer reached
  3803.     inc    de        ;Bump Input Buffer Pointer
  3804.     call    zdlm00        ;Check for delimeter
  3805.     jr    z,prsr20    ;Delimeter Found - continue search
  3806.     ld    (parenf),a
  3807.     ld    c,nprsbf-prsbf    ;Parse Buffer size
  3808. prsr30:    ld    (hl),a        ;
  3809.     and    a
  3810.     jr    z,prsr60    ;End of    line null always ends parse
  3811.     cp    QUOTE        ;Quote?
  3812.     jr    nz,prsr50
  3813.     ld    (quoflg),a
  3814.     ld    a,b        ;Quote Found - toggle flag
  3815.     xor    80h
  3816.     ld    b,a
  3817. prsr50:    dec    c        ;Decrement Buffer size tally
  3818.     ret    m        ;Error - End of    parse Buffer reached
  3819.     ld    a,(de)        ;Next Char from    Input Buffer
  3820.     ex    de,hl
  3821.     ld    (hl),0        ;Clear as we remove
  3822.     ex    de,hl
  3823.     inc    de
  3824.     inc    b        ;Bumping Character count tests QUOTE flag
  3825.     call    p,zdlm        ;Only look for    delimeters if QUOTE flag off
  3826.     inc    hl        ;Bump parse Buffer Pointer
  3827.     jr    nz,prsr30
  3828.     dec    hl
  3829. prsr60:    ld    de,prsbf    ;Return    Pointing to start of parse Buffer
  3830.     ld    (delim),a
  3831.     ret            ;zero flag set - no errors
  3832.  
  3833.  
  3834.  
  3835. asm??L:    ld    a,'L'
  3836.     jr    asm???
  3837. asm??O:    ld    a,'O'
  3838.     jr    asm???
  3839. èasm??P:    ld    a,'P'
  3840.     jr    asm???
  3841. asm??S:    ld    a,'S'
  3842.     jr    asm???
  3843. asm??T:    ld    a,'T'
  3844.     jr    asm???
  3845. asm??V:    ld    a,'V'
  3846.  
  3847. asm???:    ld    (asmflg),a
  3848.     call    cret
  3849.     ld    hl,(asmbpc)
  3850.     call    outadr
  3851.     ld    de,m????
  3852.     call    print
  3853.     jp    asm010
  3854.  
  3855.  
  3856. zdlm:    cp    ','
  3857.     ret    z
  3858. zdlm00:    and    a
  3859.     ret    z
  3860.     cp    TAB
  3861.     ret    z
  3862.     cp    ' '
  3863.     ret
  3864.  
  3865. oprtor: cp    '+'
  3866.     ret    z
  3867.     cp    '-'
  3868.     ret    z
  3869.     and    a
  3870.     ret
  3871.  
  3872.  
  3873.  
  3874. opnv:    ex    de,hl        ;DE - operand value  hl    - operand key storage
  3875.     ld    a,(prsbf)    ;Check First Byte of parse Buffer
  3876.     and    a        ;If null - paren was removed
  3877.     ld    a,c        ;Key value to accumulator
  3878.     jr    nz,opnv00    ;NZ - no paren
  3879.     or    80h        ;Found null - set paren    flag
  3880. opnv00:    ld    (hl),a        ;Store key value
  3881.     inc    hl
  3882.     ld    (hl),e        ;LO Order operand value
  3883.     inc    hl
  3884.     ld    (hl),d        ;HI Order
  3885.     ret                                                
  3886.  
  3887.  
  3888.     page
  3889. ;******************************************************************************
  3890. ;*
  3891. ;*    ZLEN:  Determine the Number of bytes in    a Z80 Instruction
  3892. ;*
  3893. ;*
  3894. è;*    Entry Point ZLEN00: Used to return Instruction length.
  3895. ;*
  3896. ;*                DE:     Address of Instruction
  3897. ;*
  3898. ;*    Return:     B:  Z - Inline    Instruction (Next PC will be PC    plus length)
  3899. ;*            NZ - PC modifying Instruction such as call,     jump, or ret
  3900. ;*             (see HL below)
  3901. ;*         C:     Number    of bytes in this Instruction.
  3902. ;*        DE:     Preserved
  3903. ;*        HL:     Next PC following the execution of the    Instruction
  3904. ;*             Pointed to by DE.
  3905. ;*
  3906. ;******************************************************************************
  3907.  
  3908. zlen00:    ld    a,(de)        ;Fetch First Byte of op    Code
  3909.     cp    0CBH        ;Test for shift/bit manipulation Instruction
  3910.     ld    bc,02
  3911.     ret    z        ;10-4 this is a    cb and length is always    2
  3912.     cp    0EDH        ;Test for fast eddie
  3913.     jr    nz,zlen15    ;
  3914.     inc    de        ;Fetch Byte two    of ed Instruction
  3915.     ld    a,(de)
  3916.     dec    de        ;Restore Pointer
  3917.     ld    hl,Z80ed    ;Ed four byter Table
  3918.     ld    c,Z80edl    ;Length
  3919.     cpir
  3920.     ld    c,4        ;Assume    ed four    byter
  3921.     ret    z        ;Correct assumption
  3922.     ld    c,2        ;Set length for    return - if not    2 must be 4
  3923.     cp    45h        ;Test for retn
  3924.     jr    z,zlen10
  3925.     cp    4DH        ;Test for RETI
  3926.     ret    nz        ;Non-pc    modifying two Byte ed
  3927. zlen10:    ld    a,0C9H        ;Treat as ordinary return Instruction
  3928.     jp    zlen80
  3929. zlen15:    cp    0DDH        ;Check for dd and fd index reg Instructions
  3930.     jr    z,zlen20
  3931.     cp    0FDH
  3932.     jr    nz,zlen40
  3933. zlen20:    inc    de        ;Fetch Byte two    of index reg Instruction
  3934.     ld    a,(de)
  3935.     dec    de        ;Restore Pointer
  3936.     cp    0E9H        ;Check for reg indirect    jump
  3937.     jr    nz,zlen30    ;
  3938.     inc    b        ;Reg indirect jump - set pc modified flag nz
  3939.     ld    a,(de)        ;Recheck for ix    or iy
  3940.     ld    hl,(ixreg)    ;Assume    ix
  3941.     cp    0DDH
  3942.     ret    z        ;Correct assumption
  3943.     ld    hl,(iyreg)
  3944.     ret
  3945. zlen30:    ld    hl,Z80fd    ;Check for dd or fd two    byter
  3946.     ld    c,Z80fdl
  3947.     cpir
  3948.     ld    c,2        ;Assume    two
  3949. è    ret    z
  3950.     ld    hl,Z80f4    ;Not two - try four
  3951.     ld    c,Z80f4l
  3952.     cpir
  3953.     ld    c,4        ;Assume    four
  3954.     ret    z        ;Correct assumption
  3955.     dec    c        ;Must be three
  3956.     ret
  3957. zlen40:    and    0C7H        ;Check for 8 bit immediate load
  3958.     cp    06
  3959.     ld    c,2        ;Assume    so
  3960.     ret    z
  3961.     dec    c        ;Assume    one Byte op Code
  3962.     ld    a,(de)
  3963.     cp    3FH
  3964.     jr    c,zlen50    ;OpCodes 0 - 3f    require    further    investig
  3965.     cp    0C0H        ;8 bit reg-reg loads and arithmetics do    not
  3966.     ret    c
  3967. zlen50:    ld    hl,Z803        ;Check for three byter
  3968.     ld    c,Z803l
  3969.     cpir
  3970.     jr    nz,zlen60    ;NZ - not three
  3971.     ld    hl,Z803s    ;Established three byter - test    for cond
  3972.     ld    c,Z803cl
  3973.     cpir
  3974.     ld    c,3        ;Set length
  3975.     ret    nz        ;NZ - three Byte inline    Instruction
  3976.     ld    hl,Z803s
  3977.     ld    c,Z803sl    ;Now weed out jumps from calls
  3978.     cpir
  3979.     ld    c,3
  3980.     ld    b,c        ;Set pc    modified flag -    we have    call or    jump
  3981.     ex    de,hl
  3982.     inc    hl
  3983.     ld    e,(hl)
  3984.     inc    hl
  3985.     ld    d,(hl)        ;DE - Address from Instruction
  3986.     ex    de,hl
  3987.     dec    de
  3988.     dec    de        ;Restore Instruction Pointer
  3989.     jr    z,zlen55    ;Z - this is a call
  3990.     cp    jp        ;Test for unconditional jump
  3991.     jr    nz,zlen85
  3992.     ret
  3993. zlen55:    ld    a,(wflag)    ;Test for no subroutine    trace flag
  3994.     and    a        ;zero means no sub tracing
  3995.     ld    b,a        ;Clear for return - if sub trace off
  3996.     ret    z        ;Subroutine trace OFF -    return with B reg 00
  3997.                 ;So BP is set at Next inline Instruction
  3998.     dec    b
  3999.     jr    nz,zlen58
  4000.     ld    a,b
  4001.     or    h
  4002.     ret    z
  4003. zlen58:    ld    a,(de)        ;Recover CALL object byte
  4004. è    ld    b,c        ;Set NZ    - PC modifying Instruction
  4005.     cp    0CDH        ;Unconditional call??
  4006.     jr    nz,zlen85    ;zlen85    - set secondary    Breakpoint if tracing
  4007.     ret
  4008. zlen60:    ld    hl,Z802
  4009.     ld    c,Z802l        ;Test for two byter
  4010.     cpir
  4011.     jr    nz,zlen70    ;Not two
  4012.     ld    hl,Z802c    ;Test for relative jump
  4013.     ld    c,Z802cl
  4014.     cpir
  4015.     ld    c,2        ;In any    case length is two
  4016.     ret    nz        ;NZ - not relative jump
  4017.     ld    h,b        ;Clear
  4018.     inc    b        ;Set pc    modified flag nz
  4019.     inc    de        ;Fetch relative    displacement
  4020.     ld    a,(de)
  4021.     ld    l,a
  4022.     add    a,a        ;Test forward or backward
  4023.     jr    nc,zlen65    ;P - forward
  4024.     dec    h        ;Set hl    negative
  4025. zlen65:    add    hl,de        ;Compute distance from Instruction
  4026.     inc    hl        ;Adjust    for built in bias
  4027.     dec    de        ;Restore Pointer
  4028.     ld    a,(de)        ;Fetch First Byte of Instruction
  4029.     cp    18H        ;Uncondtional jump?
  4030.     jr    nz,zlen85    ;Conditional - set secondary bp    if tracing
  4031.     ret
  4032. zlen70:    ld    hl,Z801        ;Check for return Instruction
  4033.     ld    c,Z801l
  4034.     cpir
  4035.     ld    c,1        ;Length    must be    1 in any case
  4036.     ret    nz
  4037.     cp    0e9h        
  4038.     jr    nz,zlen80    ;NZ - not  jp (hl)
  4039.     inc    b        ;Set pc    modified flag
  4040.     ld    hl,(hlreg)    ;Next pc contained in hlreg
  4041.     ret
  4042. zlen80:    ld    hl,(spreg)    ;Return    Instructions hide Next PC in stack
  4043.     ld    b,(hl)
  4044.     inc    hl
  4045.     ld    h,(hl)
  4046.     ld    l,b        ;HL - return Address removed from stack
  4047.     ld    b,c        ;Set b nz - pc modification flag
  4048.     cp    0C9H
  4049.     ret    z        ;Unconditional return
  4050. zlen85:    ld    a,(sbps)    ;Count of special step Breakpoints
  4051.     and    a        ;Test for zero
  4052.     ret    z        ;zero -    monitor    is not tracing
  4053.     ld    a,(bps)        ;Fetch Number of bps Currently in effect
  4054.     ld    b,a        ;Pass to set Breakpoint    routine    in b reg
  4055.     ex    de,hl        ;DE - bp to set
  4056.     call    brk30        ;Set conditional Breakpoint
  4057.     xor    a
  4058.     or    b
  4059. è    ld    b,0
  4060.     ld    de,(pcreg)    ;For setting inline bp - condition not m
  4061.     ret    nz        ;NZ - collision    with user bp
  4062.     ld    hl,sbps
  4063.     inc    (hl)        ;Bump count of step bps
  4064.     ret
  4065.     page
  4066. ;******************************************************************************
  4067. ;*
  4068. ;*    PSW:    Display    Current    state of flag register
  4069. ;*
  4070. ;*        PSWBIT:    Table of bit masks with    which to test F    reg.
  4071. ;*            Two Byte entry per bit (sign, zero, carry, parity).
  4072. ;*
  4073. ;*        PSWMAP - Table of offsets into operand Name Table featuring a
  4074. ;*             two Byte entry    for each flag bit.
  4075. ;*             Bit 4 (unused by Z80) from PSWBIT entry is on/off flag
  4076. ;*             Lo bytes are the off states (p    nz nc po).
  4077. ;*             Hi bytes are the on states  (m     z  c pe).
  4078. ;*
  4079. ;*        - Current state    of flag    register is displayed
  4080. ;*        - User queried for changes
  4081. ;*        - Input    is parsed and tested for valid flag reg    mnemonics
  4082. ;*        - If valid mnemonic Found flag bit is set or reset accordingly
  4083. ;*
  4084. ;*        EXIT:    to Z8E for Next    command
  4085. ;*
  4086. ;******************************************************************************
  4087.  
  4088. psw:    ld    de,3
  4089. psw00:    ld    hl,pswbit        ;Table of bit mask for flags
  4090.     add    hl,de            ;
  4091.     add    hl,de            ;Index times two
  4092.     ld    a,e
  4093.     neg                ;Now calculate index into pswmap
  4094.     add    a,3
  4095.     add    a,a
  4096.     ld    c,a
  4097.     ld    a,(freg)        ;Fetch Current flag of user
  4098.     and    0f7h
  4099.     and    (hl)            ;Unused    bit in flag - ensure it's off
  4100.     ld    hl,pswmap
  4101.     add    hl,bc            ;Pointer to mnemonic is    8 bytes    away
  4102.     jr    z,psw10            ;This is an off    bit (nz    nc p po)
  4103.     inc    hl            ;On
  4104. psw10:    ld    c,(hl)            ;Fetch index into operand Name Table
  4105.     ld    hl,zopnm
  4106.     add    hl,bc            ;Two bytes per Table entry
  4107.     add    hl,bc
  4108.     ld    c,2            ;Print both Chars of mnemonic Name
  4109.     call    printb
  4110.     call    space
  4111.     dec    e            ;Do all    four flag bits
  4112.     jp    p,psw00
  4113.     call    crlf
  4114. è    ld    a,(lcmd)
  4115.     cp    'J'
  4116.     ret    z
  4117.     call    space5
  4118. psw50:    call    iedtbc
  4119.     ret    m            ;No Input
  4120. psw55:    call    prsr
  4121.     ret    nz            ;Parse error - End command
  4122.     ld    bc,116h            ;
  4123.     call    oprn20            ;Check validity    of this    token
  4124.     ld    a,c
  4125.     ld    bc,pswcnt        ;Number    of flag    reg mnemonics
  4126.     ld    hl,pswmap
  4127.     cpir                ;Check Table
  4128.     jp    nz,e???            ;Error - nmemonic not Found
  4129.     ld    hl,pswbit        ;Bit mask Table
  4130.     add    hl,bc
  4131.     ld    a,(hl)            ;Fetch mask
  4132.     ex    de,hl            ;
  4133.     ld    hl,freg            ;DE - mask ptr     HL - user flag    ptr
  4134.     and    08            ;Bit says turn on or off
  4135.     ld    a,(de)            ;New copy of mask
  4136.     jr    nz,psw60        ;NZ - turn on
  4137.     cpl
  4138.     and    (hl)            ;And with Current user flag
  4139.     ld    (hl),a            ;Return    flag reg with bit now off
  4140.     jr    psw55            ;Check for more    Input
  4141. psw60:    and    0f7h            ;Turn off on/off flag (bit 4)
  4142.     or    (hl)
  4143.     ld    (hl),a            ;Now turn on specified bit
  4144.     jr    psw55
  4145.     page
  4146. ;******************************************************************************
  4147. ;*
  4148. ;*    MOVB:    Move Memory
  4149. ;*
  4150. ;*        Call BCDE to fetch destination block Address and Byte count
  4151. ;*        Call PRSR
  4152. ;*              Check for HEAD to HEAD or TAIL to TAIL move
  4153. ;*
  4154. ;*        EXIT: to Z8E for Next command
  4155. ;*
  4156. ;******************************************************************************
  4157.  
  4158. movb:    call    bcde        ;Bc - Byte count  de - destination  HL - source
  4159.     jp    nz,e???        ;Input error ends command
  4160.     xor    a
  4161.     sbc    hl,de
  4162.     adc    a,a
  4163.     add    hl,de
  4164.     add    hl,bc
  4165.     dec    hl
  4166.     ex       de,hl        ;DE - Address of Last Byte of source block
  4167.     sbc    hl,de
  4168.     adc    a,a
  4169.     add    hl,de        ;HL - original destination Address
  4170.     ex    de,hl
  4171.     cp    3
  4172.     jr    nz,movb00    ;Head to head
  4173.     ex    de,hl
  4174.     add    hl,bc
  4175.     dec    hl
  4176.     ex    de,hl
  4177.     lddr
  4178.     ret
  4179. movb00:    inc    hl
  4180.     and    a
  4181.     sbc    hl,bc
  4182.     ldir    
  4183.     ret
  4184.     page
  4185. ;******************************************************************************
  4186. ;*
  4187. ;*            YFIL:    Fill Memory
  4188. ;*
  4189. ;*        Call BCDE to get Byte Count, Starting Address, and Fill Byte
  4190. ;*
  4191. ;*        EXIT:    to Z8E for Next    command
  4192. ;*
  4193. ;******************************************************************************
  4194.  
  4195. yfil:    call    bcde        ;Bc - Byte count  de - fill Byte  HL - block
  4196.     jp    nz,e???        ;Input error ends command
  4197.     ex    de,hl
  4198. yfil00:    ld    hl,argbf
  4199.     ld    a,(argbc)
  4200. yfil10:    ldi
  4201.     inc    b
  4202.     djnz    yfil20
  4203.     inc    c
  4204.     dec    c
  4205.     ret    z
  4206. yfil20:    dec    a
  4207.     jr    nz,yfil10
  4208.     jr    yfil00
  4209.     page
  4210. ;******************************************************************************
  4211. ;*
  4212. ;*    ILDR:    Load File
  4213. ;*        User may supply    optional load bias if File Name    ends with comma
  4214. ;*
  4215. ;*        IFCB: Parse Input Buffer (INBF)    and Init FCB
  4216. ;*
  4217. ;*            Return:    Z  - FCB Initialized
  4218. ;*                NZ - SYNTAX ERROR
  4219. ;*
  4220. ;*        IOPN: Attempt to Open File
  4221. ;*
  4222. ;*            Return:    NZ - File Opened
  4223. ;*                 Z - File Not Found
  4224. ;*
  4225. ;*        IMEM: Test if Sufficient Memory    AvailTable For Loading
  4226. ;*
  4227. ;*            Return:    NC - Out of Memory
  4228. è;*
  4229. ;*        IBIN: Loader
  4230. ;*
  4231. ;*            EOF Found:     End Command
  4232. ;*            OUT OF MEMORY: Query User Whether to Continue
  4233. ;*
  4234. ;******************************************************************************
  4235.  
  4236. ildr:    call    iedtbc        ;Get File Name
  4237.     jp     p,ildr00         ;P - have Input in INBF
  4238.     ld    hl,(loadn)
  4239.     ld    a,l
  4240.     or    h
  4241.     jp    z,e???
  4242.     ld    c,a
  4243.     jp    ibin22
  4244. ildr00:    call    crlf
  4245.     call    ifcb        ;Init FCB with Name and    drive
  4246.     jp    nz,esntx    ;NZ - syntax error
  4247.     ld    de,mldg        ;Display loading string
  4248.     call    nprint
  4249.     ld    de,prsbf    ;
  4250.     ld    a,(de)        ;A - First Char    of File    Name
  4251.     ld    b,a
  4252.     call    print
  4253.     ld    a,','        ;
  4254.     cp    c        ;C - terminator    following File Name (from ifcb)
  4255.     ld    hl,100h        ;Assume    no bias
  4256.     jr    nz,ildr05    ;NZ - no comma means no    load bias
  4257.     call    iarg        ;Check for load    bias
  4258.     jp    nz,esntx    ;Error - bad argument
  4259.     call    imem        ;Check availTable memory
  4260.     jp    nc,emem??    ;Out of    memory
  4261. ildr05:    ld    (loadb),hl    ;Save load bias
  4262.     ld    a,'.'        ;Test if File Name is period
  4263.     sub    b
  4264.     jr    z,ibin        ;File Name is period - no open needed
  4265. ildr10:    call    iopn        ;Attempt to open File -    entry from nint
  4266.     jp    z,efilnf    ;Z - File not Found
  4267.  
  4268.  
  4269. ibin:
  4270.     ld    hl,(loadb)    ;Fetch starting    load Address
  4271. ibin00:    push    hl
  4272.     ex    de,hl
  4273.     ld    c,26        ;Set CP/M DMA Address
  4274.     call    BDOS        ;
  4275.     ld    de,FCB
  4276.     ld    c,20        ;CP/M Sequential File Read
  4277.     call    BDOS
  4278.     pop    de        ;Recover DMA Address
  4279.     ld    hl,80h
  4280.     add    hl,de        ;Compute Next DMA Address
  4281.     ld    (cflag),a    ;Save EOF indicator as continuation flag
  4282.     ld    c,a
  4283.     and    a
  4284.     jr    nz,ibin20    ;NZ - End of File
  4285.     call    imem        ;Test if memory    availTable to load Next sector
  4286.     jr    c,ibin00    ;C - not out of    memory
  4287. ibin20:    ex    de,hl
  4288.     dec    hl
  4289.     ld      (loadn),hl    ;End of load Address
  4290. èibin22: ld    de,mlodm    ;Print Loaded message
  4291.     call    nprint
  4292.     ex    de,hl        ;DE - ending Address of    load
  4293.     ld    hl,(loadb)    ;
  4294.     call    outadr        ;Display starting Address of load
  4295.     ex    de,hl
  4296.     call    outadr        ;Display ending    Address
  4297.     and    a
  4298.     sbc    hl,de
  4299.     inc    h
  4300.     ld    de,mlodpg
  4301.     call    nprint        ;Display pages string
  4302.     ld    l,a        ;zero l    reg
  4303.     ld    a,h        ;Hi Byte of ending Address is Number of    pages
  4304.     cp    100        ;
  4305.     jr    c,ibin30    ;Less than 100
  4306.     ld    l,'2'        ;
  4307.     sub    200        ;
  4308.     jr    nc,ibin25    ;Greater than 200
  4309.     dec    l        ;Change    to ASCII 1
  4310.     add    a,100        ;Restore actual    page count less    100
  4311. ibin25:    ld    h,a        ;Save page count
  4312.     ld    a,l
  4313.     call    ttyo
  4314. ibin30:    ld    d,2fh
  4315.     ld    a,h
  4316. ibin35:    inc    d        ;Tens and units    decimal    conversion loop
  4317.     sub    10
  4318.     jr    nc,ibin35
  4319.     add    a,10        ;Restore remainder
  4320.     ld    e,a        ;Temp Save while we print tens
  4321.     ld    a,d
  4322.     inc    l
  4323.     dec    l        ;Test l    reg
  4324.     jr    nz,ibin40    ;NZ - ASCII 1 or 2 in l
  4325.     cp    '0'        ;Suppress leading zero - less than 10 pages
  4326. ibin40:    call    nz,ttyo        ;Print tens digit
  4327.     ld    a,e
  4328.     or    '0'
  4329.     call    ttyo        ;Print units
  4330.     call    crlf
  4331.     xor    a        ;Test EOF flag
  4332.     or    c
  4333.     jp    nz,Z8E        ;NZ - true EOF means File loading complete
  4334.     ld    de,mmem??    ;Print out of memory message
  4335.     call    print
  4336.     ld    de,mcntu
  4337.     call    print        ;Print continue? prompt
  4338.     call    inchar
  4339.     call    ixlt        ;Make sure its upper case
  4340.     cp    'Y'
  4341.     call    crlf
  4342.     jp    z,ibin        ;User wants more loading
  4343.     jp    Z8E        ;Next command
  4344.  
  4345.  
  4346. ifcb:    call    prsr        ;Parse Input Buffer to extract File Name
  4347.     ld    d,a        ;Save Char which terminated File Name
  4348.     ld    a,14
  4349. è    cp    b        ;Over 14 Chars is ng File Name
  4350.     ret    c
  4351.     ld    c,b        ;B and c - byte    count of File Name
  4352.     djnz    ifcb00        ;Test for only one Char    in Name
  4353.     ld    a,(prsbf)    ;Only one - is it period?
  4354.     sub    '.'
  4355.     jr    nz,ifcb00
  4356.     ld    c,d        ;Return    terminator
  4357.     ld    a,(cflag)    ;Continuation allowed?
  4358.     and    a        ;Let ildr decide
  4359.     ret
  4360. ifcb00:    ld    b,0
  4361.     ld    a,':'        ;Check for drive specifier in Input
  4362.     cpdr
  4363.     ld    b,c        ;B - Number of Chars preceding colon
  4364.     ld    c,d        ;Return    terminator in c
  4365.     ld    de,FCB
  4366.     ld    a,0
  4367.     jr    nz,ifcb10    ;NZ - no colon
  4368.     dec    b        ;
  4369.     ret    nz        ;Syntax    error -    more than one Char
  4370.     ld    a,(hl)        ;Fetch drive specifier
  4371.     call    ixlt
  4372.     ld    (hl),a        ;Back to Parse Buffer as Upper Case    
  4373.     sub    40H        ;Make Name into    Number
  4374.     inc    hl
  4375. ifcb10:                
  4376.            ld    (de),a        ;Store drive Number in FCB
  4377.     ld    a,' '
  4378.     ld    b,11        ;Clear File Name in FCB    to spaces
  4379. ifcb20:    inc    de
  4380.     ld    (de),a
  4381.     djnz    ifcb20
  4382.     ld    b,8        ;Max Chars allowed in File Name
  4383.     ld    de,fcbnam
  4384. ifcb30:    call    ifcb90
  4385.     ret    m        ;Error - too many Chars    in File    Name
  4386.     ld    b,3        ;Max Chars allowed in File type
  4387.     ld    de,fcbtyp
  4388.     and    a        ;
  4389.     ret    z        ;Z - no    File type after    all
  4390.  
  4391.  
  4392.  
  4393. ifcb90:    inc    hl        ;Bump Buffer Pointer
  4394.     ld    a,(hl)
  4395.     and    a        ;Test for EOF null
  4396.     ret    z        ;Null Found - read File
  4397.     call    ixlt
  4398.     ld    (hl),a        ;Translate parse Buffer    to upper case
  4399.     cp    '.'
  4400.     ret    z        ;Period    Found -    move File type into FCB
  4401.     dec    b        ;Dec max Chars allowed
  4402.     ret    m        ;Error
  4403.     ld    (de),a        ;Upper case only into FCB
  4404.     inc    de
  4405.     jr    ifcb90
  4406.  
  4407.  
  4408. èiopn:
  4409.     ld    hl,fcbnam    ;Test for File Name present
  4410.     ld    a,(hl)
  4411.     cp    ' '
  4412.     ret    z        ;Space Found means not File
  4413.     dec    hl
  4414.     ld    a,(hl)        ;Drive specifier
  4415.     and    a        ;Test for default drive
  4416. ;    jr    z,iopn00    ;Z - default means no selection    required
  4417. ;    dec    a        ;Select    drive
  4418. ;    ld    e,a
  4419. ;    ld    c,14
  4420. ;    call    BDOS
  4421. iopn00:    ld    de,FCB
  4422.     ld    b,nfcb-fcbext
  4423.     ld    hl,fcbext    ;Clear remainder of FCB
  4424. iopn10:    ld    (hl),0
  4425.     inc    hl
  4426.     djnz    iopn10
  4427.     ld    c,15
  4428.     call    BDOS        ;Tell BDOS to open File
  4429.     inc    a        ;Test open return Code
  4430.     ret            ;NZ - open ok
  4431.  
  4432. imem:    ex    de,hl        ;DE - Next load    Address
  4433.     ld    a,d
  4434.     ld    hl,07        ;Ptr to    prt to start of    Z8E
  4435.     cp    (hl)
  4436.     ex    de,hl        ;
  4437.     ret    c        ;C - not out of memory
  4438.     ex    de,hl
  4439.     ret            ;DE - Last Address loaded plus one
  4440.  
  4441. esntx:    ld    de,msntx    ;Print syntax error
  4442.     jr    eprint
  4443.  
  4444. emem??:    ld    de,mmem??    ;Print out of memory
  4445.     call    nprint
  4446.     jr    eprint
  4447.  
  4448. efilnf:    ld    de,mfilnf    ;Print File not    Found
  4449.  
  4450. eprint:    call    nprint
  4451.     jp    Z8E
  4452.     page
  4453. ;*****************************************************************************
  4454. ;*
  4455. ;*            Write Memory Segment to Disk Command
  4456. ;*
  4457. ;*****************************************************************************
  4458.  
  4459. writ:    call    iedtbc        ;Fetch Line of Input
  4460.     ret    m        ;No Input - 
  4461.     call    bldf        ;Build FCB with First Arg in Buffer
  4462.     jr    nz,esntx    ;Oops - Syntax Error
  4463.     ld    a,(delim)    ;Check Char That Terminated File Name
  4464.     and    a
  4465.     jr    nz,writ10    ;NZ - Not Null Means User Entered Addresses
  4466.  
  4467.     ld    de,(loadb)    ;Use Default Begin and End Address of the Last
  4468.     ld    hl,(loadn)    ;File Loaded
  4469.     jr    writ30
  4470. writ10:    call    iarg        ;Get Address
  4471.     jp    nz,e???        ;Invalid Address
  4472.     ex    de,hl
  4473.     cp    ' '        ;Space Terminator
  4474.     jp    nz,e???        ;Anything But is Error
  4475. writ20:    call    iarg        ;Get End Address 
  4476.     jp    nz,e???
  4477. writ30:    ld    (endw),hl    ;Save Address of Where to End Writing
  4478.     ex    de,hl
  4479.     ld    c,3
  4480.     call    spaces
  4481.     call    outadr        
  4482.     ex    de,hl
  4483.     ld    c,6
  4484.     call    spaces
  4485. writ40:    call    bwrite
  4486.     ld    hl,127
  4487.     add    hl,de
  4488.     ld    b,6
  4489. writ50:    call    bksp
  4490.     djnz    writ50
  4491.     call    outadr
  4492.     inc    hl
  4493.     ex    de,hl
  4494.     ld    hl,(endw)
  4495.     sbc    hl,de
  4496.     jr    nc,writ40
  4497.     jp    closef
  4498.     
  4499.     
  4500.  
  4501. ;******************************************************************************
  4502. ;*
  4503. ;*    FIND:    Locate string in memory
  4504. ;*
  4505. ;*        call IARG - get    starting Address of seach
  4506. ;*
  4507. ;*        call IN00 - get    match data concatenating multiple arguments
  4508. ;*                into a single string
  4509. ;*
  4510. ;*        Addresses at which matches Found displayed 8 per line.
  4511. ;*        Search continues until End of memory reached
  4512. ;*        User may cancel    search at any time by hitting any key.
  4513. è;*
  4514. ;*        EXIT: to Z8E for Next command
  4515. ;*
  4516. ;******************************************************************************
  4517.  
  4518. find:    call    iedtbc
  4519.     ret    m        ;M - no    Input
  4520.     call    iarg        ;Extract starting Address of search
  4521.     jp    nz,e???        ;Error
  4522.     ex    de,hl        ;Save starting Address of search in DE
  4523. find00:    call    in00        ;Extract search    string concatenating multiple
  4524.                 ;Arguments
  4525.     jp    nz,e???        ;Error - Output    command    prompt
  4526.     xor    a
  4527.     ld    (lines),a    ;Clear crlf flag
  4528.     ex    de,hl        ;Starting Address of search - HL
  4529.     ld    de,argbf    ;Argument stored here
  4530.     
  4531.     ld    bc,(fndsym)
  4532.     ld    a,c
  4533.     or    b        ;Symbol Found?
  4534.     jp    z,find40    ;No
  4535.     
  4536.     ex    de,hl        ;HL - Argument Buffer
  4537.     ld    b,(hl)        ;Reverse Order of the Two Bytes for Symbols
  4538.     inc    hl
  4539.     ld    a,(hl)
  4540.     ld    (hl),b
  4541.     dec    hl
  4542.     ld    (hl),a
  4543.     ex    de,hl
  4544.     
  4545. find40:    ld    bc,(argbc)    ;Number    of bytes to look for
  4546.     call    crlf
  4547. find50:    call    srch        ;Do the    search
  4548.     jr    nz,find60    ;Not Found
  4549.     call    outadr        ;Display Address where match Found
  4550.     ld    a,(lines)
  4551.     dec    a        ;Carriage return after 8 Addresses displayed
  4552.     ld    (lines),a
  4553.     and    7
  4554.     call    z,crlf
  4555.     call    ttyq        ;User requesting abort?
  4556.     cp    CR
  4557.     ret    z        ;Abort - return    to Z8E
  4558. find60:    inc    hl        ;Point to Next Address at which    to start search
  4559.     add    hl,bc        ;Ensure    we won't hit End of memory by adding
  4560.                 ;In string size
  4561.     ret    c        ;Impending End of memory
  4562.     sbc    hl,bc        ;Restore Pointer
  4563.     jr    find50
  4564.  
  4565. srch:    push    bc
  4566.     push    de
  4567.     push    hl
  4568. srch00:    ld    a,(de)
  4569.     cpi
  4570.     jp    nz,srch10    ;No match
  4571.     inc    de
  4572.     jp    pe,srch00    ;Tally not expired - check Next
  4573. srch10:    pop    hl
  4574.     pop    de
  4575.     pop    bc
  4576.     ret
  4577.  
  4578.  
  4579.     page
  4580. ;******************************************************************************
  4581. ;*
  4582. ;*    verify:    verify two blocks of data are identical
  4583. ;*
  4584. è;*        enter: de - starting Address of    block 1
  4585. ;*
  4586. ;*        call bcde to get Address of block 2 and    Byte count
  4587. ;*
  4588. ;*        mismatch:   block 1 Address and    Byte are displayed
  4589. ;*                block 2 Address and    Byte are displayed
  4590. ;*                console intrrogated    - any Input terminates verify
  4591. ;*
  4592. ;*        exit:    to Z8E for Next    command
  4593. ;*
  4594. ;******************************************************************************
  4595.  
  4596. verify:    call    bcde        ;Get block 2 Address and Byte count
  4597.     jp    nz,e???
  4598.     ex    de,hl
  4599. verf00:    ld    a,(de)        ;Byte from block 1
  4600.     xor    (hl)        ;Versus    Byte from block    two
  4601.     jr    z,verf10    ;Match - no display
  4602.     call    newlin
  4603.     ld    a,(de)        ;
  4604.     call    othxsp        ;Display block 1 data
  4605.     call    space
  4606.     call    outadr        ;Display block two Address
  4607.     ld    a,(hl)
  4608.     call    outhex        ;Display results of xor
  4609.     call    ttyq        ;Check Input status
  4610.     cp    CR
  4611.     ret    z
  4612. verf10:    inc    hl        ;Bump block 1 Pointer
  4613.     inc    de        ;Bump block 2 Pointer
  4614.     dec    bc        ;Dec Byte count
  4615.     ld    a,b
  4616.     or    c
  4617.     jr    nz,verf00
  4618.     ret
  4619.     page
  4620. ;******************************************************************************
  4621. ;*
  4622. ;*    XREG:    Display    Machine    State
  4623. ;*
  4624. ;*        REGPTR:    Table contains offsets to names    in operand Name    Table.
  4625. ;*            Sign bit set indicates prime register.
  4626. ;*
  4627. ;*        REGMAP:    Table contains offsets to reg contents Table (REGCON)
  4628. ;*            Sign bit ignored (used by RGST command).
  4629. ;*
  4630. ;*        REGCON:    Table of register contents.
  4631. ;*
  4632. ;*        EXIT:    Make Current PC    Current    disassembly location counter.
  4633. ;*            Set bit    6 of disassembly flag Byte (ZASMFB)
  4634. ;*            Jump to    ZASM30 to disassemble Current Instruction.
  4635. ;*
  4636. ;******************************************************************************
  4637.  
  4638. xreg:    call    cret
  4639.     ld    bc,0        ;Init reg index
  4640. èxreg00:    call    xreg05        ;Display reg Name and contents
  4641.     inc    c
  4642.     ld    a,c
  4643.     cp    8        ;
  4644.     call    z,crlf
  4645.     ld    a,c
  4646.     cp    0ch
  4647.     ld    b,0
  4648.     jr    nz,xreg00
  4649.     ld    a,(lcmd)
  4650.     cp    'J'        ;Animated Command in Effect?
  4651.     ret    z        ;Z - No Disassembly Required
  4652.     ld    hl,(pcreg)
  4653.     ld    (zasmpc),hl
  4654.     jp    zasm30
  4655.  
  4656.  
  4657.  
  4658. xreg05:    ld    hl,regptr        ;Map of    reg Name Pointers
  4659.     ld    d,b
  4660.     add    hl,bc
  4661.     ld    a,(hl)            ;Extract Pointer
  4662.     and    7FH            ;Strip sign for    Name indexing
  4663.     ld    e,a
  4664.     ld    b,(hl)            ;Save copy of offset - need sign later
  4665.     ld    hl,zopnm        ;Register Name Table
  4666.     add    hl,de
  4667.     add    hl,de            ;Two bytes per entry
  4668.     ld    a,(hl)
  4669.     call    ttyo            ;Display Character one
  4670.     inc    hl
  4671.     ld    a,(hl)
  4672.     cp    ' '            ;Is second Character a space?
  4673.     jr    nz,xreg10
  4674.     ld    a,'C'            ;Replace space - this is pc
  4675. xreg10:    call    ttyo            ;Display second    Character
  4676.     xor    a
  4677.     or    b            ;Now test sign
  4678.     jp    p,xreg20        ;Sign not set -    not prime reg
  4679.     ld    a,27h            ;Display QUOTE
  4680.     call    ttyo
  4681. xreg20:    ld    a,':'
  4682.     call    ttyo
  4683.     ld    hl,regmap        ;Map of    Pointers to reg    contents
  4684.     add    hl,de
  4685.     ld    a,(hl)
  4686.     jp    p,xreg30        ;P - not prime reg
  4687.     add    a,8            ;Prime contents    8 bytes    past non-prime
  4688. èxreg30:    and    7FH            ;Ignore    sign
  4689.     ld    e,a
  4690.     ld    hl,regcon        ;Start of register contents storage
  4691.     add    hl,de
  4692.     ld    d,(hl)            ;HI Order contents
  4693.     dec    hl
  4694.     ld    e,(hl)
  4695.     ex    de,hl
  4696.     call    outadr            ;Display contents
  4697.     ret
  4698.  
  4699.     page
  4700. ;******************************************************************************
  4701. ;*
  4702. ;*    ZASM
  4703. ;*
  4704. ;*    The disassembler is divided into two routines:
  4705. ;*
  4706. ;*    ZASM - Computes    the Instruction    key value and finds the    opCode nmemonic
  4707. ;*    OPN  - Uses the    key value to determine the Number of operands and
  4708. ;*           displays    the operands.
  4709. ;*
  4710. ;*    Entered: DE - starting Address to disassemble
  4711. ;*
  4712. ;*        ZASM maps the 695 Z80 instrucions into 256 key values. 
  4713. ;*              The Instruction key value becomes the index into the
  4714. ;*              opCode Name Pointer Table (ZOPCNM), the First operand Table
  4715. ;*        (ZOPND1), and the second operand Table (ZOPND2).
  4716. ;*
  4717. ;*        Disassembly is done in user specified block sizes if the
  4718. ;*        disassembly count evaluates to a Number    between    1 and 255. If
  4719. ;*        the count is greater than 255 the block    is disassembled    and the
  4720. ;*        the command terminates.
  4721. ;*
  4722. ;*
  4723. ;*        ZASM15 - start of the disassembly loop
  4724. ;*        ZASMPC - Address of the    Instruction being disassembled
  4725. ;*        ZASMFB - disassembly flag byte
  4726. ;*        ZMFLAG - flag indicating directive processing (defb and    defw)
  4727. ;*
  4728. ;*                bit    6 - XREG calling
  4729. ;*                bit    5 - ASMBLR calling
  4730. ;*                bit    0 - write to disk flag
  4731. ;*
  4732. ;*
  4733. ;*
  4734. ;******************************************************************************
  4735.  
  4736.  
  4737. zasm:
  4738.     call    iedtbc
  4739.     ret    m
  4740.     call    iarg
  4741.     jp    nz,e???
  4742. è    ex    de,hl
  4743.     call    iarg        ;Read in block size
  4744.     ld    b,a        ;Save delimeter
  4745.     jr    z,zasm00
  4746.     ld    hl,1        ;Change    zero count to one
  4747. zasm00:    xor    a
  4748.     or    h
  4749.     jr    z,zasm05
  4750.     sbc    hl,de
  4751.     jp    c,e???        ;Error - start Address greater than End
  4752.     add    hl,de
  4753. zasm05:    ld    (zasmct),hl    ;Save as permanent block count
  4754.     ld    (zasmwt),hl    ;Save as working tally
  4755.     ex    de,hl        ;HL - Current Instruction Pointer
  4756.     ld    (zasmpc),hl
  4757.     call    crlf
  4758.     ld    a,b        ;Check command line delimeter
  4759.     ld    (dwrite),a    ;Save as write to disk flag:
  4760.                 ;Z - no write   NZ - write
  4761.     and    a
  4762.     call    nz,bldf        ;Not End of line - build FCB
  4763.     jp    nz,esntx
  4764.  
  4765. zasm08:    ld    de,zasmbf    ;Start of disassembly Buffer
  4766.  
  4767. zasm10:    ld    (zasmio),de    ;Init Pointer
  4768.  
  4769. zasm15:    ld    de,(zasmpc)    ;Fetch Address to disassemble
  4770.     call    zlen00        ;Calculate length
  4771.     ex    de,hl
  4772.  
  4773.                 ;Loop back here for interactive disassembly -
  4774.                 ;User requests format change. C reg:
  4775.                 ;     6 and 7 off: disassemble as Code
  4776.                 ;     6       on:  hex DEFB
  4777.                 ;     7       on:  hex DEFW or ASCII defb
  4778.  
  4779. zasm18:    call    outadr        ;Display Instruction Address
  4780.     ld    de,zmflag
  4781.     ld    a,c        ;Save Instruction length and format bits 
  4782.     ld    (de),a
  4783.     and    3fh
  4784.     ld    b,a        ;B  - length
  4785.     ld    c,a        ;C  - ditto
  4786. zasm20:    ld    a,(hl)
  4787.     call    othxsp        ;Display object    Code
  4788.     inc    hl
  4789.     djnz    zasm20
  4790.     ld    a,c        ;Number    of object bytes
  4791.     dec    a
  4792.     xor    3
  4793.     ld    b,a        ;Calculate space padding
  4794.     add    a,a
  4795.     add    a,b
  4796.     add    a,2
  4797.     ld    b,a
  4798. zasm25:    call    space
  4799.     djnz    zasm25
  4800. è    ld    (zasmnx),hl    ;Store Address of Next Instruction
  4801.     and    a        ;Clear carry
  4802.     sbc    hl,bc        ;Point to First    Byte in    Instruction
  4803. zasm30:    ex    de,hl        ;DE - Current Instruction Pointer
  4804.     ld    hl,(zasmio)    ;Buffer    Address    storage
  4805.     ld    a,(maxlin)
  4806.     ld    b,a        ;Line Length Based on Max Symbol Size
  4807. zasm35:    ld    (hl),' '    ;Space out Buffer
  4808.     inc    hl
  4809.     djnz    zasm35
  4810.     ld    a,b
  4811.     ld    (opnflg),a
  4812.     ld    (hl),CR        ;Append    crlf
  4813.     inc    hl
  4814.     ld    (hl),LF
  4815.     call    fadr        ;Find Address match
  4816.     ld    hl,(zasmio)
  4817.     jr    nz,zasm40    ;NZ - no Table or not Found
  4818.     call    xsym
  4819.     ld    (hl),':'
  4820.     ld    de,(zasmpc)
  4821. zasm40:    ld    hl,zmflag    ;Check interactive disassembly flag
  4822.     ld    a,(hl)        ;Sign bit tells all
  4823.     and    a
  4824.     jp    p,zasm42    ;Bit off - not interactive
  4825.     ld    b,6DH        ;Test for defb
  4826.     sub    82h
  4827.     jr    z,zasm90
  4828.     xor    a        ;Must be defw
  4829.     dec    b
  4830.     jr    zasm90
  4831. zasm42:    ld    a,(de)        ;First Byte of op Code
  4832.     ld    hl,op1000    ;Table of Z80 specific opCodes
  4833.     ld    c,4
  4834. zasm45:    cpir            ;Check for fd dd ed or CB
  4835.     jr    z,zasm55    ;Z - Found
  4836. zasm50:    cp    40h
  4837.     jr    c,zasm90    ;OpCode    range 0    - 3f
  4838.     ld    b,0e0h        ;
  4839.     cp    0c0h        ;
  4840.     jr    nc,zasm90    ;OpCode    range c0 - ff
  4841.     cp    80h
  4842.     jr    nc,zasm85    ;OpCode    range 80 - bf
  4843.     ld    b,0f8h        ;
  4844.     cp    76h        ;Test for halt Instruction
  4845.     jr    nz,zasm85    ;OpCode    range 40 - 7f
  4846.     ld    a,0ffh        ;Set halt Instruction key value    to 0f7h
  4847.     jr    zasm90
  4848. zasm55:    inc    de        ;
  4849.     ld    a,(de)        ;Byte two of multi-byte    Instruction
  4850.     dec    c        ;Test for ed Instruction
  4851.     jr    nz,zasm65    ;NZ - not an ED
  4852.     cp    80h
  4853.     jr    nc,zasm60    ;OpCode    range ED 40 - ed 7f
  4854.     cp    40h
  4855.     jr    nc,zasm90    ;Legal
  4856.     ld    a,09fh
  4857.     jr    zasm90        ;Map to    question marks
  4858. èzasm60:    ld    b,0e0h        ;Set bias
  4859.     cp    0c0h        ;Test for illegal ED
  4860.     jr    c,zasm90    ;Legal
  4861.     ld    a,0bfh        ;Map to    question marks
  4862.     jr    zasm90        ;OpCode    range ed a0 - ed bb
  4863.  
  4864.  
  4865. zasm65:    inc    c
  4866.     jr    z,zasm80    ;Z - CB    Instruction
  4867.     cp    0CBh        ;FD or DD - check for CB in Byte two
  4868.     jr    nz,zasm70
  4869.     inc    de        ;Fetch Last Byte of FDCB or DDCB
  4870.     inc    de
  4871.     ld    a,(de)
  4872.     rrca
  4873.     jr    c,zasm75
  4874.     and    3
  4875.     cp    3
  4876.     jr    nz,zasm75    ;Error
  4877.     ld    a,(de)
  4878.     jr    zasm80
  4879. zasm70:    ld    a,(zmflag)
  4880.     sub    3
  4881.     ld    a,(de)
  4882.     jr    nz,zasm50
  4883.     ld    hl,Z80f3
  4884.     ld    c,Z80f3l
  4885.     cpir
  4886.     jr    z,zasm50
  4887. zasm75:    ld    a,09fh
  4888.     jr    zasm90
  4889. zasm80:    cp    40h        ;Test type of CB Instruction
  4890.     ld    b,0e8h
  4891.     jr    c,zasm85    ;OpCode    range CB 00 - CB 3f (shift)
  4892.     rlca
  4893.     rlca
  4894.     and    03        ;HI Order bits become index
  4895.     ld    b,0f0h
  4896.     jr    zasm90        ;OpCode    range CB 40 - CB ff
  4897. zasm85:    rrca
  4898.     rrca
  4899.     rrca            ;Bits 3-5 of CB    shift yield key
  4900.     and    07h
  4901. zasm90:    add    a,b        ;Add in    bias from B reg
  4902.     ld    c,a        ;C - Instruction key value
  4903.     xor    a
  4904.     ld    b,a
  4905.     ld    hl,zopcpt    ;OpCode    Name Pointer Table
  4906.     add    hl,bc        ;Index into Table
  4907.     ld    l,(hl)        ;Fetch opname index
  4908.     ld    h,a
  4909.     add    hl,hl
  4910.     add    hl,hl        ;Index times four
  4911.     ld    de,zopcnm    ;Op Code Name Table
  4912.     add    hl,de
  4913. è    ex    de,hl        ;DE - Pointer to opCode    Name
  4914.     ld    hl,(zasmio)    ;Buffer    Pointer    storage
  4915.     ld    a,c
  4916.     ld    (zasmkv),a    ;Opcode Key Value 
  4917.     ld    a,(maxlen)
  4918.     ld    c,a
  4919.     inc    c        ;Set Label Length Based on Max Size
  4920.     
  4921.     ld    a,(lcmd)    ;If XREG use compressed Output format
  4922.     cp    'X'
  4923.     jr    z,zasm92
  4924.     cp    'S'        ;STEP needs compressed format
  4925. zasm92:    add    hl,bc
  4926.     ld    c,4
  4927.     ex    de,hl        ;DE - Buffer   HL - Opcode Name    Pointer
  4928.     ldir
  4929.     inc    bc        ;One space after Opcode    for compressed format
  4930.     jr    z,zasm95
  4931.     ld    c,4        ;Four spaces for true disassembly
  4932. zasm95:    ex    de,hl        ;HL - Buffer Pointer
  4933.     add    hl,bc        ;Start of operand field    in Buffer
  4934.     ld    a,(zasmkv)    ;Save the Instruction key value
  4935.     cp    09fh
  4936.     jr    nz,zasm99
  4937.     ld    de,(zasmpc)
  4938.     ld    a,(zmflag)
  4939.     ld    b,a
  4940. zasm97:    ld    a,(de)
  4941.     ld    c,d
  4942.     call    zhex
  4943.     dec    b
  4944.     jp    z,opn020
  4945.     ld    (hl),','
  4946.     inc    hl
  4947.     ld    d,c
  4948.     inc    de
  4949.     jr    zasm97
  4950. zasm99:    ld    de,zopnd1    ;Table of First    operands
  4951.     add    a,e
  4952.     ld    e,a        ;Instant offset
  4953.     ld    a,d
  4954.     adc    a,b
  4955.     ld    d,a
  4956.     ld    a,(de)
  4957.     inc    a
  4958.     jr    z,opn040    ;No operands
  4959.  
  4960.     page
  4961. ;******************************************************************************
  4962. ;*
  4963. ;*                          - OPERAND PROCESSING -
  4964. ;*
  4965. ;*    ENTER:    B - ZERO (process First    operand)
  4966. ;*        C - Instruction    Key Value
  4967. ;*
  4968. ;*   Instruction key value is used to fetch Operand Key Value:
  4969. ;*
  4970. ;*    Operand    Key Value is in    the range 0 - 1FH
  4971. ;*    Operand Key value interpretted as follows:
  4972. ;*
  4973. ;*      0 - 17H  Use as index to fetch literal from operand
  4974. è;*         Name Table (sign bit set - parens required)
  4975. ;*
  4976. ;*     18 - 1FH  Operand requires processing - use as index
  4977. ;*             into oprerand jump Table which is located
  4978. ;*             immediately after Name Table
  4979. ;*
  4980. ;*       0FFH  No operand
  4981. ;*
  4982. ;*   Operand Key Value Jump Table Routines: (Buffer Address in DE)
  4983. ;*
  4984. ;*
  4985. ;*   Entry Point   Key         Action
  4986. ;*
  4987. ;*     OPN100       18h     Relative Jump
  4988. ;*     OPN200       19h     Convert 8 Bit Operand to Hex
  4989. ;*     OPN300       1Ah     Convert 16 Bit    Operand    to Hex
  4990. ;*     OPN400       1Ch     Register Specified in Instruction
  4991. ;*     OPN600       1Dh     HL/IX/IY Instruction
  4992. ;*     OPN700       1Eh     Mask RST Operand from Bit 3-5 of RST Instruction
  4993. ;*     OPN800       1Fh     Bit Number is Specified in Bits 3-5 of    OP Code
  4994. ;*
  4995. ;*    EXIT: To ZASM15 to Continue Block Disassembly
  4996. ;*
  4997. ;******************************************************************************
  4998.  
  4999. opn:    dec    a        ;Save operand key value
  5000.     jp    p,opn010
  5001.     ld    (hl),'('
  5002.     inc    hl
  5003. opn010:    ex    de,hl        ;DE - Buffer Address
  5004.     ld    b,a
  5005.     add    a,a        ;Operand key value times two
  5006. opn012:    ld    hl,zopnm    ;Base of operand Name/jump Table
  5007.     add    a,l        ;Index into Table
  5008.     ld    l,a
  5009.     jr    nc,opn014
  5010.     inc    h        ;Account for carry
  5011. opn014:    ld    a,1FH
  5012.     and    b
  5013.     cp    zopnml        ;Test if processing required
  5014.     jr    c,opn015    ;C - operand is    a fixed    literal
  5015.     ld    a,(hl)        ;Fetch processing routine Address
  5016.     inc    hl
  5017.     ld    h,(hl)        ;
  5018.     ld    l,a        ;HL - operand processing routine
  5019.     jp    (hl)        ;Geronimoooooooo
  5020. opn015:    ldi            ;First Byte of operand literal
  5021.     inc    bc        ;Compensate for    ldi
  5022.     ex    de,hl        ;HL - Buffer
  5023.     ld    a,(de)
  5024.     cp    ' '        ;Test for space    as byte    two of literal
  5025.     jr    z,opn020    ;Ignore    spaces appearing in Byte two
  5026.     ld    (hl),a
  5027.     inc    hl        ;Bump Buffer Pointer
  5028. opn020:    ld    a,b        ;Operand key value
  5029. è    cp    80h        ;Test for closed paren required
  5030.     jr    c,opn030    ;C - none required
  5031.     ld    (hl),')'
  5032.     inc    hl
  5033. opn030:    ld    a,(opnflg)    ;Get flag byte
  5034.     xor    0ffH        ;Toggle operand Number
  5035.     ld    (opnflg),a    ;
  5036.     jr    z,opn040    ;Z - just finished Number two
  5037.     ld    a,(zasmkv)    ;Get op Code key value
  5038.     ld    de,zopnd2    ;Index into operand2 Table
  5039.     add    a,e
  5040.     ld    e,a
  5041.     jr    nc,opn035
  5042.     inc    d
  5043. opn035:    ld    a,(de)        ;Get operand2 key value 
  5044.     inc    a
  5045.     jr    z,opn040    ;Z - no    second operand
  5046.     ld    (hl),','    ;Separate operands with comma in Buffer
  5047.     inc    hl
  5048.     jr    opn
  5049. opn040:    ld    hl,(zasmio)    ;Rewind    Buffer Pointer
  5050.     ld    a,(maxlin)
  5051.     ld    c,a
  5052. opn041:
  5053.     ld    a,(case)
  5054.     and    a
  5055.     jr    z,opn044    ;Upper Case Requested - No Need to Convert
  5056.                 ;Reg Names    
  5057. opn042:    ld    a,(hl)
  5058.     and    a        ;If sign on no case conversion
  5059.     call    p,ilcs
  5060.     and    7FH        ;In case we fell thru
  5061.     ld    (hl),a
  5062.     inc    hl
  5063.     dec    c
  5064.     jr    nz,opn042
  5065.     ld    a,(maxlin)
  5066.     cp    30
  5067.     jp    z,opn043
  5068.     ld    a,44        ;Allow 16 Comment Chars
  5069. opn043:
  5070.     ld    c,a        ;Number of Chars to print (omit crlf)
  5071.     ld    hl,(zasmio)
  5072. opn044:    ld    a,(lcmd)
  5073.     cp    'J'        ;J Command
  5074.     ret    z        ;End of the Line for Full Screen Animation
  5075.     call    printb        ;Print Buffer
  5076.     inc    hl        ;Point past crlf to Next 32 Byte group
  5077.     inc    hl
  5078.     ex    de,hl
  5079.     ld    a,(lcmd)    ;Jettison all commands except Z
  5080.     cp    'X'
  5081.     jp    z,crlf
  5082.     cp    'A'
  5083.     jp    z,crlf        
  5084.     cp    'S'
  5085.     jp    z,crlf
  5086.     xor    a
  5087.     ld    (zasmf),a
  5088.     ld    hl,(zasmct)    ;Check disassembly count
  5089.     dec    hl        
  5090.     ld    a,h
  5091.     or    l        ;Test for count expired
  5092.     jp    nz,opn060    ;NZ - this is not a count of one so this is not
  5093.                 ;Interactive disassebly
  5094.  
  5095.     call    ttyi        ;Check Input command letter for interactive
  5096.     call    ixlt        ;Force upper case
  5097.     ld    (zasmf),a
  5098.     cp    'C'        ;CODE?
  5099. è    call    z,cret        ;If user wants Code return cursor to start of
  5100.                 ;Line and disassemble again
  5101.     jp    z,zasm15
  5102.     ld    c,82h        ;Assume DEFW
  5103.     cp    'D'        
  5104.     jr    z,opn045    ;DEFW -    082H
  5105.     dec    c        ;Assume ASCII DEFB
  5106.     cp    'A'
  5107.     jr    z,opn045    ;ASCII DEFB - 081H
  5108.     cp    'B'
  5109.     jr    nz,opn046    ;None of the above
  5110.     ld    c,0c1h        ;HEX DEFB - 0C1H
  5111. opn045:    call    cret
  5112.     ld    hl,(zasmpc)
  5113.     jp    zasm18
  5114.  
  5115.                 ;zasmf - 0 means this is block disassembly
  5116.                 ;      - NZ means Char entered during 
  5117.                       ;        interactive mode was not C D A or B. 
  5118.         
  5119. opn046:    cp    ';'        ;Check if user wants to insert comments
  5120.     jr    nz,opn060    ;NZ - User Does Not Want to Add Comment    
  5121.  
  5122.     call    ttyo        ;Echo semicolon
  5123.     dec    de
  5124.     dec    de        ;Point to carriage return
  5125.     ld    a,' '
  5126.     ld    (de),a        ;Clear CRLF from Buffer
  5127.     inc    de
  5128.     ld    (de),a
  5129.     inc    de
  5130.     call    write        ;End of Buffer - Write if Required
  5131.     ld    b,29
  5132.     ld    a,(maxlin)
  5133.     sub    30
  5134.     jp    z,opn048
  5135.     dec    de
  5136.     ld    b,16
  5137.     xor    a
  5138. opn048:    ld    c,a
  5139.     push    bc
  5140.     push    de        ;Save disassembly Buffer Pointer
  5141.     ld    d,a
  5142.     call    iedt03
  5143.     pop    de
  5144.     pop    bc
  5145.     ld    a,b        ;Recover Max Size of Comment
  5146.     dec    hl
  5147.     ld    b,(hl)        ;Number Actually Entered
  5148.     sub    b
  5149.     ld    c,a        ;Trailing spaces 
  5150.     inc    hl
  5151.     ex    de,hl        ;DE - Input Buffer   HL - Disassembly Buffer
  5152.     ld    (hl),';'
  5153.     inc    hl
  5154. opn049:    dec    b        ;Pre-test count
  5155.     jp    m,opn050
  5156.     ld    a,(de)        ;First Char of Input
  5157.     inc    de
  5158.     ld    (hl),a        ;Into disassembly Buffer
  5159.     inc    hl
  5160.     jr    opn049
  5161. opn050:    dec    c
  5162.     jp    m,opn055
  5163.     ld    (hl),' '
  5164.     inc    hl
  5165.     jr    opn050
  5166. opn055:    ld    (hl),CR
  5167.     inc    hl
  5168.     ld    (hl),LF
  5169.     inc    hl
  5170.     ex    de,hl
  5171.     jp    opn065
  5172.  
  5173. opn060:
  5174.     ld    a,(maxlin)    
  5175.     cp    30        ;Test for 6 Chars in Label
  5176.     jp    z,opn065    ;Z - Buffer Point OK
  5177.     ld    a,64-46        ;Bump Buffer Pointer to Next 64 Byte Chunk
  5178.     add    a,e
  5179.     ld    e,a
  5180.     jp    nc,opn065     
  5181.     inc    d
  5182.  
  5183. opn065:    call    write        ;Check if Write to Disk Flag in Effect    
  5184.     
  5185.     call    crlf
  5186.     ld    (zasmio),de    ;Save new Buffer Pointer
  5187.     ld    hl,(zasmwt)    ;Check disassembly count
  5188.     xor    a
  5189.     or    h        ;Less than 256?
  5190.     jr    z,opn080    ;Less -    this is    tally
  5191.     ld    bc,(zasmnx)    ;Fetch Next disassembly    Address
  5192.     sbc    hl,bc        ;Versus    requested End Address
  5193.     jr    c,opn095    ;C - End
  5194.     add    hl,bc        ;Restore Next disassembly Address
  5195.     jr    opn085        ;More
  5196. opn080:    dec    hl
  5197.     ld    a,h
  5198.     or    l
  5199.     jr    nz,opn085    ;NZ - more
  5200.     ld    hl,(zasmct)    ;Fetch permanent block size
  5201.     ld    a,(zasmf)
  5202.     and    a
  5203.     call    z,ttyi        ;Query user - more?
  5204.     cp    CR        ;Return    means End
  5205.     jr    z,opn095
  5206.     jr    opn090
  5207. opn085:
  5208.     call    ttyq
  5209.     cp    CR
  5210.     jr    z,opn095    ;NZ - terminate    disassembly
  5211. opn090:
  5212.     ld    (zasmwt),hl    ;Restore count
  5213.     ld    hl,(zasmnx)    ;Next Instruction Pointer
  5214.     ld    (zasmpc),hl    ;Make Current
  5215.     jp    zasm15        ;Disassemble Next Instruction
  5216.  
  5217. opn095:    ld    a,(dwrite)    ;Writing to disk?
  5218.     and    a
  5219.     ret    z
  5220.     ld    a,EOF        ;
  5221. è    ld    (de),a        ;Set EOF
  5222.     ld    de,zasmbf
  5223.     call    write
  5224.  
  5225.  
  5226.  
  5227. closef:    ld    de,FCB        ;Close File
  5228.     ld    c,16
  5229.     jp    BDOS
  5230.  
  5231.  
  5232.  
  5233. write:    push    bc    
  5234.     push    hl
  5235.     ld    hl,nzasm    ;Address of End of Disassembly Buffer    
  5236.     and    a
  5237.     sbc    hl,de
  5238.     jr    nz,wrt10    ;Not End of Buffer
  5239.     ld    de,zasmbf    ;Need to Rewind Buffer Pointer 
  5240.     ld    a,(dwrite)    ;Test Write to Disk Flag
  5241.     and    a
  5242.     call    nz,bwrite    ;NZ - Writing to Disk
  5243. wrt10:    pop    hl
  5244.     pop    bc
  5245.     ret
  5246.  
  5247.  
  5248.  
  5249. bwrite:    push    bc        ;BDOS Write Routine
  5250.     push    de
  5251.     push    hl
  5252.     ld    c,26        ;Set DMA Address
  5253.     call    BDOS
  5254.     ld    de,FCB
  5255.     ld    c,21
  5256.     call    BDOS        ;Write Buffer
  5257.     pop    hl
  5258.     pop    de
  5259.     pop    bc
  5260.     ret
  5261.  
  5262.  
  5263.  
  5264. bldf:    call    ifcb        ;Initialize FCB
  5265.     ret    nz        ;Error - invalid File Name
  5266.     call    iopn
  5267.     jr    z,bldf00    ;No File - create one
  5268.     ld    de,FCB
  5269.     ld    c,19        ;File exists - delete it
  5270.     call    BDOS 
  5271. bldf00:    ld    de,FCB        ;Create    new File
  5272.     ld    c,22
  5273.     call    BDOS        ;If no File create one
  5274.     xor    a
  5275.     ret
  5276.  
  5277.     page
  5278.  
  5279. opn100:    ld    hl,(zasmpc)
  5280.     inc    hl
  5281.     ld    a,(hl)        ;Fetch relative    displacement
  5282.     ld    c,a
  5283.     inc    c
  5284.     add    a,a        ;Test sign for displacement direction
  5285.     ld    b,0
  5286.     jr    nc,opn105
  5287.     dec    b        ;Produce zero for forward - ff for back
  5288. opn105:    add    hl,bc        ;Adjust    pc
  5289.     ex    de,hl        ;DE - Instruction ptr    HL - Buffer
  5290.     call    fadr
  5291.     call    z,xsym
  5292.     jp    z,opn040    ;Symbol    Found
  5293.     ld    (hl),'$'    ;
  5294.     inc    hl
  5295.     ld    a,c
  5296.     inc    a
  5297.     ld    b,0
  5298.     cp    82h
  5299.     jp    opn610        ;Convert to displacement to ASCII
  5300.  
  5301. opn200:    call    zmqf        ;Check for interactive disassembly
  5302.     jr    nc,opn205    ;Sign off - not interactive
  5303.     add    a,a        ;Shift out bit 6
  5304.     ld    a,(hl)
  5305.     jr    c,opn215    ;On - must be hex defb
  5306.     call    zascii        ;User wants ASCII - check validity
  5307.     jr    nz,opn215    ;NZ - unTable to convert to ASCII
  5308.     jp    opn020
  5309. opn205:    call    zndx        ;Check for ix or iy Instruction
  5310.     ex    de,hl        ;Buffer back to DE
  5311.     jr    nz,opn210    ;NZ - not IX or    IY
  5312.     inc    hl
  5313.     inc    hl        ;Must be  LD (IX+ind),NN
  5314. opn210:    inc    hl        ;
  5315.     ld    a,(hl)        ;Fetch object byte
  5316.     jr    z,opn215    ;No conversion of IX and IY displacements 
  5317.                 ;To ASCII        
  5318.     ld    a,(zasmkv)    ;Check for IN or OUT Instruction
  5319.     cp    0B3H    
  5320.     jr    z,opn215    ;No conversion of port Addresses to ASCII
  5321.     cp    0BBH
  5322.     jr    z,opn215
  5323.     ld    a,(hl)    
  5324.     call    zascii
  5325.     jp    z,opn020
  5326. opn215:    ex    de,hl
  5327.     ld    a,(de)
  5328.     cp    10        ;Decimal Number?
  5329.     jr    nc,opn220    ;No - convert to hex
  5330.     call    zhex20        ;86 the    leading    zero and trailing h
  5331.     jp    opn020
  5332. opn220:    call    zhex        ;Do hex    to asii    conversion
  5333.     ld    (hl),'H'    ;Following 8 bit hex byte
  5334.     inc    hl
  5335.     jp    opn020
  5336.  
  5337. opn300:    call    zmqf
  5338.     jr    c,opn315    ;C - this is defw
  5339.     call    zndx
  5340.     ex    de,hl        ;DE - Buffer   HL - Instruction    Pointer
  5341.     jr    nz,opn310    ;NZ - not ix or    iy
  5342.     inc    hl
  5343. opn310:    inc    hl
  5344. opn315:    ld    a,(hl)        ;Fetch LO Order    16 bit operand
  5345.     inc    hl
  5346.     ld    h,(hl)        ;HI Order
  5347.     ld    l,a
  5348.     ex    de,hl        ;DE - 16 bit operand   HL - Buffer
  5349.     call    fadr
  5350.     call    z,xsym
  5351.     jp    z,opn020    ;Symbol    Found
  5352.     ld    a,d        ;Convert HI Order to hex
  5353.     ld    c,a        ;Save spare copy
  5354.     call    zhex
  5355.     ld    a,e
  5356.     ld    d,a
  5357.     call    zhex10
  5358.     xor    a
  5359.     or    c
  5360.     jr    nz,opn320
  5361.     ld    a,d
  5362.     cp    10
  5363.     jp    c,opn020
  5364. opn320:    ld    (hl),'h'
  5365.     inc    hl
  5366.     jp    opn020
  5367.  
  5368. opn400:
  5369.     call    zndx
  5370.     jr    nz,opn410    ;NZ - not ix or    iy Instruction
  5371.     inc    de
  5372. è    ld    a,(de)
  5373.     cp    0CBh        ;Check for indexed bit Instruction
  5374.     jr    nz,opn410
  5375.     inc    de        ;Byte of interest is Number four
  5376.     inc    de
  5377. opn410:    ld    a,01        ;Check low bit of operand key value
  5378.     and    b
  5379.     ld    a,(de)        ;Fetch op Code
  5380.     jr    nz,opn500    ;NZ - index 01bh
  5381.     rra            ;Register specified in bits 0-5
  5382.     rra
  5383.     rra
  5384. opn500:    and    007        ;Register specified in bits 0-2
  5385.     xor    006        ;From the movie    of the same Name
  5386.     jp    nz,opn010    ;NZ - not hl or    ix or iy
  5387.     ld    a,(zasmpc)    ;
  5388.     xor    e        ;Test if pc was    incremented
  5389.     ld    (hl),'('    ;Set leading paren
  5390.     inc    hl
  5391.     ld    b,080h        ;Set sign bit -    closed paren required
  5392.     ex    de,hl        ;DE - Buffer
  5393.     jp    z,opn012
  5394.  
  5395.  
  5396.  
  5397. opn600:
  5398.     call    zndx        ;DEtermine if ix or iy
  5399.     jr    z,opn605    ;Z - must be ix    of iy
  5400.     ld    a,80h
  5401.     and    b
  5402.     jp    opn010
  5403. opn605:    ld    (hl),'i'    ;Set First Character
  5404.     inc    hl
  5405.     adc    a,'x'        ;Carry determines x or y (from zndx)
  5406.     ld    (hl),a
  5407.     inc    hl
  5408.     ld    a,80h        ;Test for parens
  5409.     and    b
  5410.     jp    z,opn030    ;Z - not indexed Instruction
  5411.     inc    de
  5412.     ld    a,(de)        ;Fetch second Byte of Instruction
  5413.     cp    0e9h        ;Test for jp (ix) or jp    (iy)
  5414.     jp    z,opn020    ;Output    closed paren
  5415.     inc    de
  5416.     ld    a,(de)        ;Fetch displacement byte
  5417.     cp    80h        ;Test sign
  5418. opn610:    ld    (hl),'+'    ;Assume    forward
  5419.     jr    c,opn620    ;C - forward
  5420.     neg            ;Force positive
  5421.     ld    (hl),'-'
  5422. opn620:    inc    hl        ;Bump Buffer Pointer
  5423.     and    7FH        ;Strip sign
  5424.     call    zhex        ;Convert to hex
  5425.     ld    a,9
  5426.     cp    d
  5427. è    jp    nc,opn020
  5428.     ld    (hl),'h'
  5429.     inc    hl
  5430.     jp    opn020        ;Output    closed paren
  5431.  
  5432.  
  5433.  
  5434.  
  5435. opn700:    ld    hl,(zasmpc)
  5436.     ld    a,(hl)        ;Fetch restart Instruction
  5437.     ex    de,hl        ;DE - Buffer   hl Instruction Pointer
  5438.     and    038h        ;
  5439.     call    zhex        ;Convert restart Number    to ASCII
  5440.     ld    (hl),'H'
  5441.     jp    opn020
  5442.  
  5443.  
  5444.  
  5445. opn800:    call    zndx
  5446.     jr    nz,opn810    ;NZ - not DDCB or FDCB Instruction
  5447.     inc    de
  5448.     inc    de
  5449.     inc    de        ;
  5450.     ld    a,(de)        ;Byte 4    of ix or iy bit    Instruction
  5451.     jr    opn820
  5452. opn810:    cp    10h        ;Weed out interrupt mode Instructions
  5453.     ld    a,(de)        ;Second    Byte of    Instruction regardless
  5454.     jr    nz,opn820    ;NZ - CB bit Instruction
  5455.     xor    046h        ;
  5456.     jr    z,opn830    ;Z - interrupt mode zero
  5457.     sub    8
  5458. opn820:    rra
  5459.     rra
  5460.     rra
  5461.     and    07        ;Leave only bit    Number
  5462. opn830:    call    zhex20        ;Convert to ASCII
  5463.     jp    opn030
  5464.     page
  5465. ;******************************************************************************
  5466. ;*
  5467. ;*             disassembler utility subroutines
  5468. ;*
  5469. ;*    ZNDX:      determines if    FD DD ED or CB Instruction
  5470. ;*          caller uses returned values on an individual basis
  5471. ;*
  5472. ;*           Z  -    DD FD
  5473. ;*          NZ  -    neither    of the above
  5474. ;*          Current Instruction Pointer Bumped if    CB or ED Instruction
  5475. ;*
  5476. ;*    ZHEX:      convert to Byte in the accumulator to ASCII with leading zero
  5477. ;*          store    in Buffer
  5478. ;*          D - reg destroyed
  5479. ;*
  5480. ;*    ZHEX10:      No leading zero permitted
  5481. ;*    ZHEX20:      Convert LO Order nibble only
  5482. è;*
  5483. ;*******************************************************************************
  5484.  
  5485. zndx:    ld    hl,(zasmpc)    ;Fetch Current Instruction Pointer
  5486.     ex    de,hl        ;DE - Instruction Pointer   HL - Buffer
  5487.     ld    a,(de)
  5488.     add    a,-0FDH        ;IY check
  5489.     ret    z
  5490.     sub    0DDh-0FDh    ;IX check
  5491.     ret    z
  5492.     cp    10h        ;ED check
  5493.     jr    z,zndx00
  5494.     cp    0eeh        ;CB check
  5495.     ld    a,0        ;Clear
  5496.     ret    nz
  5497. zndx00:    inc    de        ;CB or ED - Bump Instruction Pointer
  5498.     cpl
  5499.     and    a        ;Ensure    nz set
  5500.     cpl
  5501.     ret
  5502.  
  5503.  
  5504.  
  5505. zhex:    ld    d,a
  5506.     cp    0a0h        ;Test Byte to convert
  5507.     jr    c,zhex00    ;Starts    with decimal digit - 86    the lead zero
  5508.     ld    (hl),'0'
  5509.     inc    hl
  5510.     jr    zhex10
  5511. zhex00:    cp    10
  5512.     jr    c,zhex20
  5513. zhex10:    rrca
  5514.     rrca
  5515.     rrca
  5516.     rrca
  5517.     and    0fh
  5518.     add    a,90h
  5519.     daa
  5520.     adc    a,40h
  5521.     daa            ;A - ASCII digit
  5522.     ld    (hl),a
  5523.     inc    hl
  5524.     ld    a,d        ;Lo nibble conversion
  5525. zhex20:    and    0fh
  5526.     add    a,90h
  5527.     daa
  5528.     adc    a,40h
  5529.     daa
  5530.     ld    (hl),a
  5531.     inc    hl
  5532.     ret
  5533.  
  5534.  
  5535.  
  5536. zmqf:    ld    hl,zmflag    ;Check interactive disassembly flag
  5537. è    ld    a,(hl)        ;
  5538.     ld    (hl),0        ;Clear regardless
  5539.     ld    hl,(zasmpc)    ;Fetch Current disassembly Address
  5540.     add    a,a        ;Check sign - on means interactive
  5541.     ret
  5542.  
  5543.  
  5544. zascii:    cp    ' '
  5545.     ret    c
  5546.     and    a
  5547.     ret    m
  5548.     cp    7FH        ;Rubout?
  5549.     jr    z,zasc10
  5550.     cp    QUOTE
  5551.     jr    nz,zasc20
  5552. zasc10:    and    a        ;Set nz - conversion not done
  5553.     ret
  5554. zasc20:    ex    de,hl
  5555.     ld    (hl),QUOTE    ;Defb -    quoted Character
  5556.     inc    hl
  5557.     or    80H        ;Hi bit on - no case conversion for this guy
  5558.     ld    (hl),a
  5559.     inc    hl
  5560.     ld    (hl),QUOTE
  5561.     cp    a
  5562.     ret
  5563. è
  5564.  
  5565.  
  5566. fadr:    push    bc
  5567.     push    hl
  5568.     ld    hl,(06)        ;Fetch top of tpa - start of Symbol Table
  5569.     ld    bc,(maxlen)
  5570.     add    hl,bc        ;Point to Start of Symbol Name
  5571.     inc    hl
  5572. fadr00:    ld    a,(hl)        ;First Byte of Symbol Name
  5573.     dec    a        ;Check validity
  5574.     jp    m,fadr30    ;End of    Table
  5575.     add    hl,bc
  5576.     ld    a,(hl)        ;Fetch Hi Order    Address    from Table
  5577.     cp    d
  5578.     jp    nz,fadr10
  5579.     dec    hl
  5580.     ld    a,(hl)
  5581.     inc    hl
  5582.     cp    e
  5583.     jp    z,fadr20
  5584. fadr10:    inc    hl
  5585.     jp    fadr00
  5586. fadr20:    ex    de,hl        ;Return Pointer in DE
  5587.     ld    a,c
  5588.     cpl
  5589.     and    e
  5590.     ld    e,a
  5591.     xor    a
  5592. fadr30:    pop    hl
  5593.     pop    bc
  5594.     ret
  5595.  
  5596. xsym:
  5597.     ld    a,(maxlen)
  5598.     dec    a
  5599.     ld    c,a
  5600. xsym00:    ld    a,(de)
  5601.     and    a
  5602.     ret    z
  5603.     ld    (hl),a
  5604.     inc    hl
  5605.     inc    de
  5606.     dec    c
  5607.     jr    nz,xsym00
  5608.     ret
  5609.     page
  5610.  
  5611.  
  5612. ;******************************************************************************
  5613. ;*
  5614. ;*    BCDE:  Query User for 3    Arguments: Source Address
  5615. ;*                       Destination Address
  5616. ;*                       Byte    Count
  5617. ;*
  5618. è;*           Used by MOVE, VERIFY, and YFIL Routines
  5619. ;*
  5620. ;*           RETURN: BC - Byte Count
  5621. ;*               DE - Destination
  5622. ;*               HL - Source Pointer
  5623. ;*            Z - No Errors
  5624. ;*
  5625. ;*               NZ - No Input Entered
  5626. ;*              - UnTable to Evaluate Argument
  5627. ;*              - Destination    Address    < Source
  5628. ;*
  5629. ;*******************************************************************************
  5630.  
  5631. bcde:    call    iedtbc
  5632.     ret    m        ;No Input is treated as    error
  5633.     call    iarg        ;Read in starting block    Address
  5634.     ret    nz
  5635.     ex    de,hl
  5636.     call    iarg
  5637.     ret    nz
  5638.     sbc    hl,de        ;End - start = Byte count - 1
  5639.     ret    c
  5640.     ld    b,h
  5641.     ld    c,l
  5642.     inc    bc
  5643.     call    in00        ;Read in destination block Address
  5644.     ret    nz
  5645.     ex    de,hl        ;Set regs right
  5646.     ret
  5647.  
  5648.     page
  5649.  
  5650. ;******************************************************************************
  5651. ;*
  5652. ;*               CONSOLE I/O ROUTINES
  5653. ;*
  5654. ;*   "physical"    i/o routines: ttyi - keyboard Input
  5655. ;*                  ttyo - console Output
  5656. ;*                  ttyq - console status
  5657. ;*
  5658. ;*   logical Input routines:  inchar - Input Character processing
  5659. ;*                       control Characters echoed with ^    
  5660. ;*
  5661. ;*   logical Output routines: crlf   - Output carriage return/line feed
  5662. ;*                  cret   - Output carriage return only
  5663. ;*                 space   - Output space
  5664. ;*                spaces   - Output Number of    spaces in C
  5665. ;*                outhex   - Output hex Byte in a
  5666. ;*                othxsp   - Output hex Byte in a followed by    space
  5667. ;*                outadr   - Output 16 bit hex value in hl followed
  5668. ;*                       by space    - hl preserved
  5669. ;*                 print   - Output string - Address in de
  5670. ;*                       string terminated by null
  5671. ;*                printb   - Output string - Address in hl
  5672. ;*                               Byte count in c
  5673. è;*                               End at First null
  5674. ;*
  5675. ;******************************************************************************
  5676.  
  5677.  
  5678.  
  5679. ttyq:    push    bc
  5680.     push    de
  5681.     push    hl
  5682.     ld    c,11
  5683.     call    bdos
  5684.     and    a
  5685.     ld    c,6
  5686.     ld    e,0FFH
  5687.     call    nz,bdos
  5688.     pop    hl
  5689.     pop    de
  5690.     pop    bc
  5691.     and    7FH
  5692.     ret
  5693.  
  5694.     org    ttyq+32
  5695.  
  5696.  
  5697. ttyi:    push    bc
  5698.     push    de
  5699.     push    hl
  5700. ttyi00:    ld    c,6
  5701.     ld    e,0FFH
  5702.     call    bdos
  5703.     and    7FH
  5704.     jr    z,ttyi00
  5705.     pop    hl
  5706.     pop    de
  5707.     pop    bc
  5708.     ret
  5709.  
  5710.     org    ttyi+32
  5711.  
  5712.  
  5713. ttyo:    push    af
  5714.     push    bc
  5715.     push    de
  5716.     push    hl
  5717.     ld    e,a
  5718.     ld    c,2
  5719.     call    bdos
  5720.     pop    hl
  5721.     pop    de
  5722.     pop    bc
  5723.     pop    af
  5724.     ret
  5725.  
  5726.     org    ttyo+32
  5727.  
  5728.  
  5729. inchar:    call    ttyi
  5730.     cp    CTLC
  5731.     jp    z,00
  5732.     cp    CR
  5733.     ret    z
  5734.     cp    TAB
  5735.     ret    z
  5736.     cp    LF
  5737.     ret    z
  5738.     cp    BS
  5739.     ret    z
  5740.     cp    CTLX
  5741.     ret    z
  5742.     cp    ' '
  5743.     jr    nc,ttyo
  5744.     push    af
  5745.     ld    a,'^'
  5746.     call    ttyo
  5747.     pop    af
  5748.     xor    40h
  5749.     call    ttyo
  5750. è    xor    40h
  5751.     ret
  5752.  
  5753.  
  5754. ilcs:    cp    'A'
  5755.     ret    c
  5756.     cp    'Z'+1
  5757.     ret    nc
  5758.     or    20h
  5759.     ret
  5760.  
  5761.  
  5762.  
  5763. ixlt:    cp    'a'
  5764.     ret    c
  5765.     sub    20h
  5766.     ret
  5767.  
  5768.     page
  5769. crlf:    ld    a,LF
  5770.     call    ttyo
  5771. cret:    ld    a,CR
  5772.     jp    ttyo
  5773.  
  5774. othxsp:    call    outhex
  5775.  
  5776. space:    ld    a,' '
  5777.     jp    ttyo
  5778.  
  5779. space5:    ld    c,5
  5780.  
  5781. spaces:    call    space
  5782.     dec    c
  5783.     jr    nz,spaces
  5784.     ret
  5785.  
  5786.  
  5787.  
  5788. newlin:    call    crlf
  5789.     ex    de,hl
  5790.     call    outadr
  5791.     ex    de,hl
  5792.     ret
  5793.  
  5794.     
  5795. outadr:    ld    a,h
  5796.     call    outhex
  5797.     ld    a,l
  5798. è    call    othxsp
  5799.     jr    space
  5800.  
  5801.  
  5802.  
  5803. outhex:    push    af
  5804.     call    binx
  5805.     call    ttyo
  5806.     pop    af
  5807.     call    binx00
  5808.     jp    ttyo
  5809.  
  5810.  
  5811.  
  5812. binx:    rrca
  5813.     rrca
  5814.     rrca
  5815.     rrca
  5816. binx00:    and    0fh
  5817.     add    a,90h
  5818.     daa
  5819.     adc    a,40h
  5820.     daa
  5821.     ret
  5822.     page
  5823. ilin:    push    bc
  5824.     push    de
  5825.     ld    b,inbfsz
  5826.     ld    c,0
  5827.     call    in
  5828.     pop    de
  5829.     pop    bc
  5830.     ret
  5831.  
  5832.  
  5833. istr:    push    bc
  5834.     push    de
  5835.     ld    b,1
  5836.     ld    c,' '
  5837.     call    iedt
  5838.     pop    de
  5839.     pop    bc
  5840.     ret
  5841.  
  5842.         
  5843.                 ;Resume Input After Reading In One Char
  5844.  
  5845. irsm:    push    bc
  5846.     push    de
  5847.     ld    b,inbfsz-1    ;Max Input Size Less One Char Already Read In
  5848.     ld    c,' '        ;This is Terminator Char
  5849.     ld    d,1        ;Preset Byte Count
  5850.     ld    a,d
  5851.     ld    (strngf),a    ;Set NZ - This is String Function
  5852.     ld    hl,inbf+1    ;Init Buffer Pointer
  5853.     call    iedt05
  5854.     xor    a
  5855.     ld    (strngf),a    ;This is No Longer String Function
  5856.     or    d
  5857.     call    p,in00
  5858.     pop    de
  5859.     pop    bc
  5860.     ret
  5861.  
  5862. è
  5863.  
  5864. in:    call    iedt
  5865.     ret    m
  5866. in00:    xor    a
  5867.     ld    (argbc),a
  5868.     ld    hl,argbf
  5869.     ld    (argbpt),hl
  5870. in10:    call    iarg
  5871.     ret    nz
  5872.     and    a
  5873.     jr    nz,in10
  5874.     ret
  5875.  
  5876.  
  5877.  
  5878. iarg:    push    bc
  5879.     push    de
  5880.     call    parg
  5881.     ld    a,(delim)
  5882.     pop    de
  5883.     pop    bc
  5884.     ret
  5885.     page
  5886. parg:    call    prsr        ;Extract Next argument
  5887.     ret    nz        ;Parse error
  5888.     ld    a,(quoflg)    ;Test for ASCII    literal
  5889.     and    a
  5890.     jr    z,parg10    ;Quote Character not Found
  5891.     xor    a
  5892.     or    b        ;Test for balanced quotes
  5893.     ret    m        ;Error - unbalanced quotes
  5894.     ld    a,(de)        ;First Character of parse Buffer
  5895.     sub    QUOTE
  5896.     jr    nz,parg50    ;Invalid literal string but may be expression
  5897.                 ;Involving a literal
  5898.     ld    l,b        ;L - Character count of    parse Buffer
  5899.     ld    h,a        ;Clear
  5900.     add    hl,de        ;
  5901.     dec    hl        ;HL - Pointer to Last Char in parse Buffer
  5902.     ld    a,(hl)        ;
  5903.     sub    QUOTE        ;Ensure    literal    string ends with QUOTE
  5904.     jr     nz,parg50
  5905.     ld    (hl),a        ;Clear Trailing Quote
  5906.     ld    c,b        ;C - Character count of    parse Buffer
  5907.     ld    b,a        ;Clear
  5908.     dec    c        ;Subtract the QUOTE Characters from the    count
  5909.     dec    c
  5910.     dec    c        ;Extra dec set error flag nz for '' string
  5911.     ret    m        ;Inform    caller of null string
  5912.     inc    c        ;C - actual string length
  5913.     ld    a,c        ;Spare Copy
  5914.     inc    de        ;Point to Second Character of parse Buffer
  5915.     ld    hl,(argbpt)    ;Caller    wants evaluated    arg stored here
  5916.     ex    de,hl
  5917.     ldir
  5918. è    ex    de,hl
  5919.     dec    hl
  5920.     ld    e,(hl)
  5921.     dec    hl
  5922.     ld    d,(hl)
  5923.     inc    hl
  5924.     inc    hl        ;Point to Where to Store Next Arg
  5925.     dec    a        ;Argument Length 1?
  5926.     jr    nz,parg00
  5927.     ld    d,a
  5928. parg00:    ld    c,a
  5929.     inc    c        ;Account for Increment
  5930.     ld    a,(argbc)    ;Fetch Current Argument Byte Counter
  5931.     add    a,c
  5932.     jr    parg90
  5933. parg10:    call    mreg        ;Check for register specified
  5934.     jr    nz,parg50    ;NZ - invalid register Name
  5935.     ld    a,c
  5936.     add    a,a
  5937.     jr    c,parg60    ;Sign bit reset    - 16 bit register pair
  5938. parg50:    ld    hl,00
  5939.     ld    b,l
  5940.     ld    de,prsbf    ;Reinit    starting Address of parse Buffer
  5941.     call    xval
  5942.     jr    z,parg70
  5943.     ret
  5944. parg60:    ld    a,(hl)
  5945.     dec    hl
  5946.     ld    l,(hl)
  5947.     ld    h,a
  5948.     ld    a,(prsbf)    ;Check paren flag for indirection
  5949.     and    a
  5950.     jr    nz,parg65    ;NZ - parens not removed
  5951.     inc    de        ;Bump past trailing null
  5952.     ld    a,(hl)
  5953.     inc    hl
  5954.     ld    h,(hl)
  5955.     ld    l,a
  5956. parg65:    ld    b,80h
  5957.     call    xval
  5958.     ret    nz
  5959. parg70:    ex    de,hl
  5960.     ld    hl,(argbpt)
  5961.     ld    a,(argbc)
  5962.     inc    d
  5963.     dec    d
  5964.     jr    z,parg80
  5965.     ld    (hl),d
  5966.     inc    hl
  5967.     inc    a
  5968. parg80:    ld    (hl),e
  5969.     inc    hl
  5970.     inc    a
  5971. parg90:    ld    (argbc),a
  5972.     ld    (argbpt),hl
  5973.     ex    de,hl
  5974.     xor    a
  5975.     ret
  5976.     page
  5977. outbyt:    ld    b,a        ;Save spare copy    
  5978.     call    othxsp        ;Hex - display
  5979.     call    space
  5980.     ld    a,b        ;Display Byte in ASCII
  5981.     call    asci        ;Display ASCII equivalent
  5982.     ld    c,3
  5983.     jp    spaces        ;Solicit Input three spaces right
  5984.  
  5985. byte:    call    istr
  5986. è    ld    a,(inbfnc)    ;Number    of Chars in Input Buffer
  5987.     dec    a        ;Test for Input    Buffer count of    zero
  5988.     inc    de        ;Assume    zero - examine Next
  5989.     ret    m        ;No Input means examine Next
  5990.     dec    de        ;Incorrect assumption
  5991.     ld    a,(inbf)    ;Check First Char of Input Buffer
  5992.     cp    '.'
  5993.     ret    z        ;Period    ends command
  5994.     cp    '='        ;New Address?
  5995.     jr    nz,byte10
  5996.     xor    a        ;Clear equal sign so PRSR ignores it
  5997.     ld    (inbf),a
  5998.     call    irsm        ;Fetch new Address to examine
  5999.     jr    nz,byte30    ;ERROR
  6000.     ld    a,(inbfnc)
  6001.     sub    2
  6002.     jr    c,byte30    ;C - ERROR - equal sign was only Char of Input
  6003.     ex    de,hl        ;Return new Address in DE
  6004.     scf            ;Ensure NZ set for caller - no replacement data
  6005.                 ;Was entered
  6006.     sbc    a,a
  6007.     ret
  6008. byte10:    cp    '^'        ;
  6009.     jr    nz,byte15    ;NZ - not up arrow means need more Input
  6010.     dec    de        ;DEc Current memory Pointer
  6011.     scf             ;Set nz - no replacement data entered
  6012.     sbc    a,a
  6013.     ret
  6014. byte15:    call    irsm        ;Resume    Input from console
  6015.     ret    z        ;No errors on Input
  6016.     ld    a,(inbfnc)    ;Check Number of Chars Input
  6017.     and    a        
  6018.     jr    z,byte        ;None - user hit control X or backspaced to
  6019.                 ;Beginning of Buffer
  6020. byte30:    call    e???
  6021.     scf
  6022.     sbc    a,a        ;Set NZ - no replacement
  6023.     ret
  6024.     page
  6025. ;******************************************************************************
  6026. ;*
  6027. ;*    BDOS function 10 replacement to    make romming this program easier since
  6028. ;*    only two console I/O routines (TTYI and    TTYO) are required. This
  6029. ;*    routine    supports backspace, line delete, and TAB expansion.
  6030. ;*
  6031. ;*    All Input stored in Input Buffer INBF.
  6032. ;*
  6033. ;*
  6034. ;*    IEDTBC:    Solicit    console    for new    Input and initialize B and C registers
  6035. ;*        for max    size and Input and NO special line terminator.
  6036. ;*
  6037. ;*
  6038. ;*    IEDT:    Solicit    console    for new    Input using non-default    Byte count for
  6039. ;*        Buffer or non-standard terminator.
  6040. ;*
  6041. è;*        CALLED:     B - max Number    of Characters to receive
  6042. ;*             C - special terminator    other than carriage return
  6043. ;*
  6044. ;*
  6045. ;*    IEDT00:    Resume Input - used by routines    which call IEDT    with a Buffer
  6046. ;*        count of 1 to check for    special    Character as the First Char
  6047. ;*        received (such as exam looking for period).
  6048. ;*
  6049. ;*        CALLED:     B - max Number    of Characters to receive
  6050. ;*             C - special terminator    other than carriage return
  6051. ;*
  6052. ;******************************************************************************
  6053.  
  6054.  
  6055. iedtbc:    ld    b,inbfsz
  6056.     xor    a
  6057.     ld    c,a
  6058.     ld    (strngf),a
  6059. iedt:    xor    a
  6060.     ld    d,inbfsz
  6061.     ld    hl,inbf
  6062. iedt00:    ld    (hl),a
  6063.     inc    hl
  6064.     dec    d
  6065.     jr    nz,iedt00
  6066.     ld    (argbc),a    ;Init Number of    arguments tally
  6067.     ld    hl,argbf
  6068.     ld    (argbpt),hl    ;Init Pointer to start of Buffer
  6069. iedt03:    ld    hl,inbf        ;Start of Input    Buffer
  6070.     ld    (quoflg),a
  6071. iedt05:    call    inchar        ;Read Char from    console
  6072.     ld    (trmntr),a    ;Assume line terminator until proven otherwise
  6073.     cp    CR        ;End of    line?
  6074.     jr    z,iedt90    ;Z - End
  6075.     ld    e,a
  6076.     cp    QUOTE
  6077.     ld    a,(quoflg)
  6078.     jr    nz,iedt10
  6079.     xor    QUOTE
  6080.     ld    (quoflg),a
  6081.     ld    a,QUOTE
  6082.     jr    iedt60
  6083. iedt10:    and    a        ;Quote flag on?
  6084.     ld    a,e        ;Recover Input Character
  6085.     jr    z,iedt15    ;Off - check terminator
  6086.     ld    a,(lcmd)
  6087.     call    ixlt
  6088.     cp    'R'
  6089.     ld    a,e
  6090.     jr    nz,iedt20
  6091. iedt15:    cp    c        ;Compare with auxilary terminator
  6092.     jr    z,iedt90    ;Z - End
  6093. iedt20:    cp    TAB
  6094.     jr    nz,iedt35    ;NZ - not TAB check backspace
  6095. iedt25:    call    space        ;Space out until Char position mod 8 = zero
  6096. è    ld    (hl),a        ;Store space in Buffer as we expand TAB
  6097.     inc    hl 
  6098.     inc    d
  6099.     ld    a,7
  6100.     and    d
  6101.     jr    nz,iedt25
  6102.     ld    (hl),0        ;Set End of line null    
  6103.     jr    iedt70
  6104. iedt35:    ld    e,1        ;Assume    one backspace required
  6105.     cp    BS
  6106.     jr    z,iedt40    ;Z - correct assumption
  6107.     cp    CTLX        ;Erase line?
  6108.     jr    nz,iedt60    ;NZ - process normal Input Character
  6109.     ld    e,d        ;Backspace count is Number of Chars in Buffer
  6110. iedt40:    xor    a        ;Test if already at beginning of Buffer
  6111.     or    d
  6112.     jr    z,iedt05    ;Z - at    beginning so leave cursor as is
  6113. iedt50:    call    bksp        ;Transmit BS - space - BS string
  6114.     dec    d        ;Sub one from Input Buffer count
  6115.     dec    hl        ;Rewind    Buffer Pointer on notch
  6116.     ld    a,(hl)        ;Check for control Characters
  6117.     ld    (hl),0
  6118.     cp    QUOTE        ;Check for backspacing over a QUOTE
  6119.     jr    nz,iedt55
  6120.     ld    a,(quoflg)    ;Toggle QUOTE flag so we keep track of balance
  6121.                 ;Factor
  6122.     xor    QUOTE
  6123.     ld    (quoflg),a
  6124.     jr    iedt58
  6125. iedt55:    cp    ' '
  6126.     call    c,bksp        ;C - control Char requires extra BS for caret
  6127. iedt58:    dec    e        ;DEc backspace count
  6128.     jr    nz,iedt50    ;More backspacing
  6129.     ld    a,(strngf)    ;String    function flag on?
  6130.     and    a
  6131.     jr    z,iedt05    ;Off - get Next    Input Char
  6132.     xor    a        ;Did we    backspace to start of Buffer?
  6133.     or    d        ;Test via Character count
  6134.     jr    nz,iedt05    ;Not rewound all the way
  6135.     ld    (inbfnc),a    ;Set a zero Byte count so caller knows
  6136.                 ;Something is fishy
  6137.     ret
  6138. iedt60:    ld    (hl),a        ;Store Char in INBF
  6139.     inc    hl        ;Bump INBF Pointer
  6140.     ld    (hl),0        ;End of Line
  6141.     inc    d        ;Bump Number of    Chars in Buffer
  6142. iedt70:    ld    a,d        ;Current Size
  6143.     sub    b        ;Versus    MAX Size Requested by Caller
  6144.     jp    c,iedt05    ;More Room in Buffer
  6145. iedt90:    ld    hl,inbfnc    ;Store Number of Characters Received ala
  6146.                 ;BDOS Function 10
  6147.     ld    (hl),d
  6148.     inc    hl        ;Point to First    Char in    Buffer
  6149.     dec    d
  6150.     ret            ;Sayonara
  6151.  
  6152.  
  6153.  
  6154.  
  6155. bksp:    call    bksp00
  6156.     call    space
  6157. bksp00:    ld    a,BS
  6158. è    jp    ttyo
  6159.  
  6160.  
  6161.  
  6162.  
  6163. asci:    and    7FH        ;Convert contents on accumulator to ASCII   
  6164.     cp    7FH        ;
  6165.     jp    z,asci00
  6166.     cp    20h
  6167.     jp    nc,ttyo
  6168. asci00:    ld    a,'~'        ;Non-prinTables replaced with squiggle
  6169.            jp      ttyo
  6170.  
  6171.  
  6172.  
  6173. bcdx:    call    bcdx00
  6174.     ret    nz
  6175. bcdx00:    rld
  6176.     ex    de,hl
  6177.     add    hl,hl
  6178.     ld    b,h
  6179.     ld    c,l
  6180.     add    hl,hl
  6181.     add    hl,hl
  6182.     add    hl,bc
  6183.     ld    c,a
  6184.     ld    a,9
  6185.     cp    c
  6186.     ret    c
  6187.     xor    a
  6188.     ld    b,a
  6189.     add    hl,bc
  6190.     ex    de,hl
  6191.     adc    a,a
  6192.     ret
  6193.  
  6194.  
  6195.  
  6196. nprint:    call    crlf
  6197. print:    ld    a,(de)
  6198.     and    a
  6199.     ret    z
  6200.     call    ttyo
  6201.     inc    de
  6202.     jr    print
  6203.  
  6204.  
  6205. printb:    ld    a,(hl)
  6206.     and    a
  6207.     ret    z
  6208.     call    ttyo
  6209.     inc    hl
  6210.     dec    c
  6211.     jr    nz,printb
  6212.     ret
  6213.  
  6214.  
  6215.  
  6216. home:    ld    bc,00
  6217.  
  6218.  
  6219. xycp:    push    bc
  6220.     push    de
  6221.     push    hl
  6222.     ld    hl,mxycp
  6223.     ld    a,(row)        ;Add in row offset
  6224.     add    a,b
  6225.     ld    b,a        ;Save row Character
  6226.     ld    a,(column)    ;Add column bias
  6227.     add    a,c
  6228.     ld    c,a
  6229.     ld    e,(hl)        ;Number of Chars in cursor Addressing string
  6230. xycp00::
  6231.     inc    hl
  6232.     ld    a,(hl)
  6233.     call    ttyo
  6234.     dec    e
  6235.     jr    nz,xycp00
  6236.     ld    a,(rowb4?)
  6237.     and    a
  6238.     jr    nz,xycp10
  6239.     ld    a,b
  6240.     ld    b,c
  6241.     ld    c,a
  6242. xycp10::
  6243.     ld    a,b
  6244.     call    ttyo
  6245.     ld    a,c
  6246.     call    ttyo
  6247.     pop    hl
  6248.     pop    de
  6249.     pop    bc
  6250.     ret
  6251.  
  6252.     org    xycp+128
  6253. nrel:                    ;End of    Relocatable Code
  6254.     page
  6255.  
  6256. zopnm:
  6257.     defm    'HL'
  6258.     defm    'A '
  6259.     defm    'H '
  6260.     defm    'L '
  6261.     defm    'D '
  6262.     defm    'E '
  6263.     defm    'B '
  6264.     defm    'C '
  6265. ix.:    defm    'IX'
  6266.     defm    'SP'
  6267.     defm    'P '
  6268.     defm    'R '
  6269.     defm    'I '
  6270.     defm    'AF'
  6271.     defm    'BC'
  6272.     defm    'DE'
  6273. iy.:    defm    'IY'
  6274.     defm    'Z '
  6275.     defm    'NC'
  6276.     defm    'NZ'
  6277.     defm    'PE'
  6278.     defm    'PO'
  6279.     defm    'M '
  6280.     defm    'PC'
  6281.  
  6282. ix..    equ    (ix.-zopnm)/2        ;Relative position - IX
  6283. iy..    equ    (IY.-zopnm)/2        ;             IY
  6284.  
  6285. zopnml    equ    ($-ZopnM)/2
  6286.  
  6287. zopjtb    equ     $-NREL            ;Nrel to jump Table bias for loader
  6288.  
  6289. zoprjt:
  6290.     defw    opn600            ;18 - HL/IX/IY test
  6291.     defw    opn400            ;19 - register specified in bits 0-2
  6292.     defw    opn400            ;1A - register specified in bits 3-5
  6293.     defw    opn100            ;1B - relative jump
  6294.     defw    opn200            ;1C - nn
  6295.     defw    opn300            ;1D - nnnn
  6296.     defw    opn700            ;1E - restart
  6297.     defw    opn800            ;1F - bit Number
  6298.  
  6299. zasmio:    defw    zasmbf
  6300.  
  6301. zopjtl    equ    ($-zoprjt)/2        ;Length    of operand jump    Table
  6302. è
  6303. jtcmd:
  6304.     defw    ASMBLR
  6305.     defw    USYM
  6306.     defw    NPRT
  6307.     defw    JDBG
  6308.     defw    ZASM
  6309.     defw    EXAM
  6310.     defw    RGST
  6311.     defw    GO
  6312.     defw    YFIL
  6313.     defw    MOVB
  6314.     defw    VERIFY
  6315.     defw    PSW
  6316.     defw    BREAK
  6317.     defw    CBREAK
  6318.     defw    FIND
  6319.     defw    HSYM
  6320.     defw    STEP
  6321.     defw    OBREAK
  6322.     defw    ILDR
  6323.     defw    DUMP
  6324.     defw    QPRT
  6325.     defw    XREG
  6326.     defw    KDMP
  6327.     defw    WRIT
  6328. cmd:
  6329.     defm    'WKXQDIOSHFCB'
  6330.     defm    'PVMYGREZJNUA'
  6331. ncmd    equ    $-cmd        ;Number    of commands
  6332.  
  6333. bpemsg:
  6334.     defm    '*ERROR*'
  6335. bpmsg:
  6336.     defm    '*BP* @ '
  6337.     defb    0
  6338. prompt:
  6339.     defb    '*',' ',BS,0
  6340.  
  6341. mrrow:    defb    '=','>',BS,BS,BS
  6342.     defb    00
  6343.  
  6344. m????:    defm    '??'
  6345. m??:    defm    ' ??  '
  6346.  
  6347.  
  6348. asmflg:    defb    ' '
  6349.     defb    0
  6350.  
  6351. lcmd:    defm    ' '
  6352. em???:    defm    ' ??'
  6353.     defb    0
  6354.  
  6355. mldg:
  6356.     defb    'Loading: '
  6357.     defb    0
  6358.  
  6359. èmfilnf:
  6360.     defm    'File not Found'
  6361.     defb    CR,LF,00
  6362.  
  6363.  
  6364. mlodm:
  6365.     defm    'Loaded:  '
  6366.     defb    0
  6367. mlodpg:
  6368.  
  6369.     defm    'Pages:   '
  6370.     defb    0
  6371.  
  6372. msntx:
  6373.     defb    'Syntax Error'
  6374.     defb    CR,LF,0
  6375.  
  6376. mmem??:    defm    'Out of memory'
  6377.     defb    0
  6378.  
  6379. mcntu:    defm    ' - Continue? '
  6380.     defb    0
  6381.  
  6382. mireg:
  6383.     defm    'IR: '
  6384.     defb    0
  6385.     page
  6386.  
  6387. Z80Fd:    defb    009H,019H,02BH
  6388.     defb    023H,029H,039H,0E1H
  6389.     defb    0E3H,0E5H,0E9H,0F9H
  6390. Z80FDL    equ    $-Z80FD
  6391.  
  6392. Z80F4:    defb    021H,022H,02AH,036H,0CBH
  6393. Z80F4L    equ    $-Z80F4
  6394.  
  6395.  
  6396. Z801:    defb    0C0H,0E9H,0C9H,0D8H
  6397.     defb    0D0H,0C8H,0E8H,0E0H
  6398.     defb    0F8H,0F0H
  6399. Z801L    equ    $-Z801
  6400.  
  6401.  
  6402. Z802:    defb    036H,0C6H,0CEH,0D3H
  6403.     defb    0D6H,0DBH,0DEH,0E6H
  6404.     defb    0EEH,0F6H,0FEH
  6405. Z802C:    defb    018H,038H,030H
  6406.     defb    028H,020H,010H
  6407. Z802L    equ    $-Z802
  6408. Z802CL    equ    $-Z802C
  6409.  
  6410.  
  6411. Z80R:
  6412. Z803:    defb    001H,011H,021H,022H
  6413.     defb    02AH,031H,032H,03AH
  6414. è
  6415. Z803S:    defb    0CDH
  6416.     defb    0DCH,0D4H,0CCH,0C4H
  6417.     defb    0ECH,0E4H,0FCH,0F4H
  6418.  
  6419. Z803SL    equ    $-Z803S            ;NUMBER    OF CALL    INSTRUCTIONS
  6420.  
  6421. Z803C:    defb    0C3H
  6422.     defb    0DAH,0D2H,0CAH,0C2H
  6423.     defb    0EAH,0E2H,0FAH,0F2H
  6424.  
  6425. Z803L    equ    $-Z803            ;NUMBER    OF 3 BYTE INSTRUCTIONS
  6426. Z803CL    equ    $-Z803S            ;NUMBER    OF 3 BYTE PC MOD INSTRUCTIONS
  6427.  
  6428. Z80ED:    defb    043H,04BH,053H
  6429.     defb    05BH,073H,07BH
  6430.  
  6431. Z80EDL    equ    $-Z80ED
  6432.  
  6433. Z80RL    equ    $-Z80R            ;NUMBER    RELOCATABLE Z80    INSTRUCTIONS
  6434.  
  6435. Z80F3:
  6436.     defb    034H,035H,046H,04EH
  6437.     defb    056H,05EH,066H,06EH
  6438.     defb    070H,071H,072H,073H
  6439.     defb    074H,075H,077H,07EH
  6440.     defb    086H,08EH,096H,09EH
  6441.     defb    0A6H,0AEH,0B6H,0BEH
  6442. Z80F3L    equ    $-Z80F3
  6443.     page
  6444. ;***********************************************************************
  6445. ;*
  6446. ;*
  6447. ;*
  6448. ;*
  6449. ;*
  6450. ;***********************************************************************
  6451.  
  6452.     ORG    4*(($+3)/4)
  6453. ZOPCPT:
  6454.     defb    022H,01CH,01CH,015H    ;NOP    LD    LD    INC    00 - 03
  6455.     defb    015H,00CH,01CH,031H    ;INC    DEC    LD    RLCA    04 - 07
  6456.     defb    010H,000H,01CH,00CH    ;EX    ADD    LD    DEC    08 - 0B
  6457.     defb    015H,00CH,01CH,036H    ;INC    DEC    LD    RRCA    0C - 0F
  6458.     defb    00EH,01CH,01CH,015H    ;DJNZ    LD    LD    INC    10 - 13
  6459.     defb    015H,00CH,01CH,02FH    ;INC    DEC    LD    RLA    14 - 17
  6460.     defb    01BH,000H,01CH,00CH    ;JR    ADD    LD    DEC    18 - 1B
  6461.     defb    015H,00CH,01CH,034H    ;INC    DEC    LD    RRA    1C - 1F
  6462.     defb    01BH,01CH,01CH,015H    ;JR    LD    LD    INC    20 - 23
  6463.     defb    015H,00CH,01CH,00BH    ;INC    DEC    LD    DAA    24 - 27
  6464.     defb    01BH,000H,01CH,00CH    ;JR    ADD    LD    DEC    28 - 2B
  6465.     defb    015H,00CH,01CH,00AH    ;INC    DEC    LD    CPL    2C - 2F
  6466.     defb    01BH,01CH,01CH,015H    ;JR    LD    LD    INC    30 - 33
  6467.     defb    015H,00CH,01CH,03AH    ;INC    DEC    LD    SCF    34 - 37
  6468.     defb    01BH,000H,01CH,00CH    ;JR    ADD    LD    DEC    38 - 3B
  6469. è    defb    015H,00CH,01CH,004H    ;INC    DEC    LD    CCF    3C - 3F
  6470.  
  6471.  
  6472.     defb    014H,026H,039H,01CH    ;IN    OUT    SBC    LD    ED 40
  6473.     defb    021H,02DH,013H,01CH    ;NEG    RETN    IM    LD
  6474.     defb    014H,026H,001H,01CH    ;IN    OUT    ADC    LD
  6475.     defb    022H,02CH,022H,01CH    ;....    RETI    ...    LD
  6476.     defb    014H,026H,039H,01CH    ;IN    OUT    SBC    LD
  6477.     defb    022H,022H,013H,01CH    ;...    ...    IM    LD
  6478.     defb    014H,026H,001H,01CH    ;IN    OUT    ADC    LD
  6479.     defb    022H,022H,013H,01CH    ;...    ...    IM    LD
  6480.     defb    014H,026H,039H,022H    ;IN    OUT    SBC    ...
  6481.     defb    022H,022H,002H,037H    ;...    ...    ...    RRD
  6482.     defb    014H,026H,001H,022H    ;IN    OUT    ADC    ...
  6483.     defb    044H,045H,046H,032H    ;Defb*    defw*    DDB*    RLD
  6484.     defb    043H,047H,039H,01CH    ;ORG*    equ*    SBC    LD    ED 70
  6485.     defb    022H,022H,022H,022H    ;...    ...    ...    ...
  6486.     defb    014H,026H,001H,01CH    ;IN    OUT    ADC    LD
  6487.     defb    022H,022H,022H,022H    ;...    ...    ...    ...    ED 7F
  6488.  
  6489.  
  6490.     defb    01FH,008H,018H,028H    ;LDI    CPI    INI    OUTI
  6491.     defb    022H,022H,022H,022H    ;...    ...    ...    ...
  6492.     defb    01DH,006H,016H,027H    ;LDD    CPD    IND    OUTD
  6493.     defb    022H,022H,022H,022H    ;...    ...    ...    ...
  6494.     defb    020H,009H,019H,025H    ;LDIR    CPIR    INIR    OTIR
  6495.     defb    022H,022H,022H,022H    ;...    ...    ...    ...
  6496.     defb    01EH,007H,017H,024H    ;LDDR    CPDR    INDR    OTDR
  6497.     defb    022H,022H,022H,044H    ;...    ....    ....    defb*
  6498.  
  6499.  
  6500.     defb    02BH,029H,01AH,01AH    ;RET    POP    JP    JP    C0 - C3
  6501.     defb    003H,02AH,000H,038H    ;CALL    PUSH    ADD    RST    C4 - C7
  6502.     defb    02BH,02BH,01AH,022H    ;RET    RET    JP    ...    C8 - CB
  6503.     defb    003H,003H,001H,038H    ;CALL    CALL    ADC    RST    CC - CF
  6504.     defb    02BH,029H,01AH,026H    ;RET    POP    JP    OUT    D0 - D3
  6505.     defb    003H,02AH,03EH,038H    ;CALL    PUSH    SUB    RST    D4 - D7
  6506.     defb    02BH,011H,01AH,014H    ;RET    EXX    JP    IN    D8 - DB
  6507.     defb    003H,022H,039H,038H    ;CALL    ...    SBC    RST    DC - DF
  6508.     defb    02BH,029H,01AH,010H    ;RET    POP    JP    EX    E0 - E3
  6509.     defb    003H,02AH,002H,038H    ;CALL    PUSH    AND    RST    E4 - E7
  6510.     defb    02BH,01AH,01AH,010H    ;RET    JP    JP    EX    E8 - EB
  6511.     defb    003H,022H,03FH,038H    ;CALL    ...    XOR    RST    EC - EF
  6512.     defb    02BH,029H,01AH,00DH    ;RET    POP    JP    DI    F0 - F3
  6513.     defb    003H,02AH,023H,038H    ;CALL    PUSH    OR    RST    F4 - F7
  6514.     defb    02BH,01CH,01AH,00FH    ;RET    LD    JP    EI    F8 - FB
  6515.     defb    003H,022H,005H,038H    ;CALL    ...    CP    RST    FC - FF
  6516.  
  6517.     defb    000H,001H,03EH,039H    ;ADD    ADC    SUB    SBC
  6518.     defb    002H,03FH,023H,005H    ;AND    XOR    OR    CP
  6519.  
  6520.  
  6521.     defb    030H,035H,02EH,033H    ;RLC    RRC    RL    RR
  6522.     defb    03BH,03CH,022H,03DH    ;SLA    SRA    ...    SRL
  6523.     defb    022H,040H,041H,042H    ;...    BIT    RES    SET
  6524. è
  6525.  
  6526.     defb    022H,022H,022H,012H    ;...    ...    ...    HALT
  6527.  
  6528.  
  6529.     defb    01CH,01CH,01CH,01CH    ;LD    LD    LD    LD
  6530.     defb    01CH,01CH,01CH,01CH    ;LD    LD    LD    LD
  6531.  
  6532.     page
  6533. ;****************************************************************************
  6534. ;*
  6535. ;*            TABLE OF FIRST OPERANDS
  6536. ;*
  6537. ;****************************************************************************
  6538.  
  6539. zopnd1:
  6540.     defb    0FFH,00EH,08EH,00EH    ;00 - 03
  6541.     defb    006H,006H,006H,0FFH    ;04 - 07
  6542.     defb    00DH,018H,001H,00EH    ;08 - 0B
  6543.     defb    007H,007H,007H,0FFH    ;0C - 0F
  6544.     defb    01BH,00FH,08FH,00FH    ;10 - 13
  6545.     defb    004H,004H,004H,0FFH    ;14 - 17
  6546.     defb    01BH,018H,001H,00FH    ;18 - 1B
  6547.     defb    005H,005H,005H,0FFH    ;1C - 1F
  6548.     defb    013H,018H,09DH,018H    ;20 - 23
  6549.     defb    002H,002H,002H,0FFH    ;24 - 27
  6550.     defb    011H,018H,018H,018H    ;28 - 2B
  6551.     defb    003H,003H,003H,0FFH    ;2C - 2F
  6552.     defb    012H,009H,09DH,009H    ;30 - 33
  6553.     defb    098H,098H,098H,0FFH    ;34 - 37
  6554.     defb    007H,018H,001H,009H    ;38 - 3B
  6555.     defb    001H,001H,001H,0FFH    ;3C - 3F
  6556.  
  6557.     defb    006H,087H,000H,09DH    ;40 - 43
  6558.     defb    0FFH,0FFH,01FH,00CH    ;44 - 47
  6559.     defb    007H,087H,000H,00EH    ;48 - 4B
  6560.     defb    0FFH,0FFH,0FFH,00BH    ;4C - 4F
  6561.     defb    004H,087H,000H,09DH    ;50 - 53
  6562.     defb    0FFH,0FFH,01FH,001H    ;54 - 57
  6563.     defb    005H,087H,000H,00FH    ;58 - 5B
  6564.     defb    0FFH,0FFH,01FH,001H    ;5C - 5F
  6565.     defb    002H,087H,000H,0FFH    ;60 - 63
  6566.     defb    0FFH,0FFH,0FFH,0FFH    ;64 - 67
  6567.     defb    003H,087H,000H,0FFH    ;68 - 6B
  6568.     defb    01CH,01DH,01DH,0FFH    ;6C - 6F    defb  defw  DDB
  6569.     defb    01DH,01DH,000H,09DH    ;70 - 73    ORG   equ
  6570.     defb    0FFH,0FFH,0FFH,0FFH    ;74 - 77
  6571.     defb    001H,087H,000H,009H    ;78 - 7B
  6572.     defb    0FFH,0FFH,0FFH,0FFH    ;7C - 7F
  6573.  
  6574.     defb    0FFH,0FFH,0FFH,0FFH    ;A0 - BF
  6575.     defb    0FFH,0FFH,0FFH,0FFH    ;A4 - A7
  6576.     defb    0FFH,0FFH,0FFH,0FFH    ;A8 - AB
  6577.     defb    0FFH,0FFH,0FFH,0FFH    ;AC - AF
  6578.     defb    0FFH,0FFH,0FFH,0FFH    ;B0 - B3
  6579. è    defb    0FFH,0FFH,0FFH,0FFH    ;B4 - B7
  6580.     defb    0FFH,0FFH,0FFH,0FFH    ;B8 - BB
  6581.     defb    0FFH,0FFH,00FH,0FFH    ;BC - BF
  6582.  
  6583.     defb    013H,00EH,013H,01DH    ;C0 - C3
  6584.     defb    013H,00EH,001H,01EH    ;C4 - C7
  6585.     defb    011H,0FFH,011H,0FFH    ;C8 - CB
  6586.     defb    011H,01DH,001H,01EH    ;CC - CF
  6587.     defb    012H,00FH,012H,09CH    ;D0 - D3
  6588.     defb    012H,00FH,01CH,01EH    ;D4 - D7
  6589.     defb    007H,0FFH,007H,001H    ;D8 - DB
  6590.     defb    007H,0FFH,001H,01EH    ;DC - DF
  6591.     defb    015H,018H,015H,089H    ;E0 - E3
  6592.     defb    015H,018H,01CH,01EH    ;E4 - E7
  6593.     defb    014H,098H,014H,00FH    ;E8 - EB
  6594.     defb    014H,0FFH,01CH,01EH    ;EC - EF
  6595.     defb    00AH,00DH,00AH,0FFH    ;F0 - F3
  6596.     defb    00AH,00DH,01CH,01EH    ;F4 - F7
  6597.     defb    016H,009H,016H,0FFH    ;F8 - FB
  6598.     defb    016H,0FFH,01CH,01EH    ;FC - FF
  6599.  
  6600.  
  6601.     defb    001H,001H,019H,001H    ;8 bit logic and arithmetic
  6602.     defb    019H,019H,019H,019H    ;
  6603.  
  6604.  
  6605.     defb    019H,019H,019H,019H    ;Shift and rotate
  6606.     defb    019H,019H,019H,019H    ;
  6607.     defb    0FFH,01FH,01FH,01FH    ;Bit - res - set
  6608.  
  6609.     defb    0FFH,0FFH,0FFH,0FFH    ;Filler
  6610.  
  6611.     defb    01AH,01AH,01AH,01AH    ;8 bit load
  6612.     defb    01AH,01AH,01AH,01AH    ;
  6613.  
  6614.     page
  6615. ;***********************************************************************
  6616. ;*
  6617. ;*            TABLE OF SECOND    OPERANDS
  6618. ;*
  6619. ;***********************************************************************
  6620.  
  6621.  
  6622. zopnd2:
  6623.     defb    0FFH,01DH,001H,0FFH    ;00 - 03
  6624.     defb    0FFH,0FFH,01CH,0FFH    ;04 - 07
  6625.     defb    00DH,00EH,08EH,0FFH    ;08 - 0B
  6626.     defb    0FFH,0FFH,01CH,0FFH    ;0C - 0F
  6627.     defb    0FFH,01DH,001H,0FFH    ;10 - 13
  6628.     defb    0FFH,0FFH,01CH,0FFH    ;14 - 17
  6629.     defb    0FFH,00FH,08FH,0FFH    ;18 - 1B
  6630.     defb    0FFH,0FFH,01CH,0FFH    ;1C - 1F
  6631.     defb    01BH,01DH,018H,0FFH    ;20 - 23
  6632.     defb    0FFH,0FFH,01CH,0FFH    ;24 - 27
  6633.     defb    01BH,018H,09DH,0FFH    ;28 - 2B
  6634. è    defb    0FFH,0FFH,01CH,0FFH    ;2C - 2F
  6635.     defb    01BH,01DH,001H,0FFH    ;30 - 33
  6636.     defb    0FFH,0FFH,01CH,0FFH    ;34 - 37
  6637.     defb    01BH,009H,09DH,0FFH    ;38 - 3B
  6638.     defb    0FFH,0FFH,01CH,0FFH    ;3C - 3F
  6639.  
  6640.  
  6641.     defb    087H,006H,00EH,00EH    ;40 - 43
  6642.     defb    0FFH,0FFH,0FFH,001H    ;44 - 47
  6643.     defb    087H,007H,00EH,09DH    ;48 - 4B
  6644.     defb    0FFH,0FFH,0FFH,001H    ;4C - 4F
  6645.     defb    087H,004H,00FH,00FH    ;50 - 53
  6646.     defb    0FFH,0FFH,0FFH,00CH    ;54 - 57
  6647.     defb    087H,005H,00FH,09DH    ;58 - 5B
  6648.     defb    0FFH,0FFH,0FFH,00BH    ;5C - 5F
  6649.     defb    087H,002H,000H,0FFH    ;60 - 63
  6650.     defb    0FFH,0FFH,0FFH,0FFH    ;64 - 67
  6651.     defb    087H,003H,000H,0FFH    ;68 - 6B
  6652.     defb    0FFH,0FFH,0FFH,0FFH    ;6C - 6F
  6653.     defb    0FFH,0FFH,009H,009H    ;70 - 73
  6654.     defb    0FFH,0FFH,0FFH,0FFH    ;74 - 77
  6655.     defb    087H,001H,009H,09DH    ;78 - 7B
  6656.     defb    0FFH,0FFH,0FFH,0FFH
  6657.  
  6658.     defb    0FFH,0FFH,0FFH,0FFH    ;A0 - BF
  6659.     defb    0FFH,0FFH,0FFH,0FFH    ;A4 - A7
  6660.     defb    0FFH,0FFH,0FFH,0FFH    ;A8 - AB
  6661.     defb    0FFH,0FFH,0FFH,0FFH    ;AC - AF
  6662.     defb    0FFH,0FFH,0FFH,0FFH    ;B0 - B3
  6663.     defb    0FFH,0FFH,0FFH,0FFH    ;B4 - B7
  6664.     defb    0FFH,0FFH,0FFH,0FFH    ;B8 - BB
  6665.     defb    0FFH,0FFH,00FH,0FFH    ;BC - BF
  6666.  
  6667.     defb    0FFH,0FFH,01DH,0FFH    ;C0 - C3
  6668.     defb    01DH,0FFH,01CH,0FFH    ;C4 - C7
  6669.     defb    0FFH,0FFH,01DH,0FFH    ;C8 - CB
  6670.     defb    01DH,0FFH,01CH,0FFH    ;CC - CF
  6671.     defb    0FFH,0FFH,01DH,001H    ;D0 - D3
  6672.     defb    01DH,0FFH,0FFH,0FFH    ;D4 - D7
  6673.     defb    0FFH,0FFH,01DH,09CH    ;D8 - DB
  6674.     defb    01DH,0FFH,01CH,0FFH    ;DC - DF
  6675.     defb    0FFH,0FFH,01DH,018H    ;E0 - E3
  6676.     defb    01DH,0FFH,0FFH,0FFH    ;E4 - E7
  6677.     defb    0FFH,0FFH,01DH,000H    ;E8 - EB
  6678.     defb    01DH,0FFH,0FFH,0FFH    ;EC - EF
  6679.     defb    0FFH,0FFH,01DH,0FFH    ;F0 - F3
  6680.     defb    01DH,0FFH,0FFH,0FFH    ;F4 - F7
  6681.     defb    0FFH,018H,01DH,0FFH    ;F8 - FB
  6682.     defb    01DH,0FFH,0FFH,0FFH    ;FC - FF
  6683.  
  6684.     defb    019H,019H,0FFH,019H    ;8 bit logic and arithmetic
  6685.     defb    0FFH,0FFH,0FFH,0FFH    ;
  6686.  
  6687.     defb    0FFH,0FFH,0FFH,0FFH    ;Shift and rotate
  6688.     defb    0FFH,0FFH,0FFH,0FFH    ;
  6689. è    defb    0FFH,019H,019H,019H    ;Bit - res - set
  6690.  
  6691.     defb    0FFH,0FFH,0FFH,0FFH
  6692.  
  6693.     defb    019H,019H,019H,019H    ;8 bit load
  6694.     defb    019H,019H,019H,019H
  6695.     page
  6696.  
  6697. ;***********************************************************************
  6698. ;*
  6699. ;*            TABLE OF OP CODE NAMES
  6700. ;*
  6701. ;***********************************************************************
  6702.  
  6703.  
  6704. ZOPCNM:
  6705.     defm    'ADD ADC AND CALL'
  6706.     defm    'CCF CP  CPD CPDR'
  6707.     defm    'CPI CPIRCPL DAA '
  6708.     defm    'DEC DI  DJNZEI  '
  6709.     defm    'EX  EXX HALTIM  '
  6710.     defm    'IN  INC IND INDR'
  6711.     defm    'INI INIRJP  JR  '
  6712.     defm    'LD  LDD LDDRLDI '
  6713.     defm    'LDIRNEG NOP OR  '
  6714.     defm    'OTDROTIROUT OUTD'
  6715.     defm    'OUTIPOP PUSHRET '
  6716.     defm    'RETIRETNRL  RLA '
  6717.     defm    'RLC RLCARLD RR  '
  6718.     defm    'RRA RRC RRCARRD '
  6719.     defm    'RST SBC SCF SLA '
  6720.     defm    'SRA SRL SUB XOR '
  6721.     defm    'BIT RES SET ORG '
  6722.     defm    'DEFBDEFWDDB EQU '
  6723.  
  6724.  
  6725.  
  6726.  
  6727. OP1000:
  6728.     defm     0FDH,0DDH,0EDH,0CBH
  6729.  
  6730.  
  6731.  
  6732. PSWBIT:    defb    10001000B        ;Minus
  6733.     defb    10000000B        ;Positive
  6734.     defb    00001100B        ;Even parity
  6735.     defb    00000100B        ;Odd parity
  6736.     defb    01001000B        ;zero
  6737.     defb    01000000B        ;Not zero
  6738.     defb    00001001B        ;Carry
  6739.     defb    00000001B        ;No carry
  6740.  
  6741. pswmap:    defb    18,07,19,17,21,20,10,22
  6742. pswcnt    equ    $-pswmap
  6743.  
  6744. è
  6745. regmap:
  6746.     defb    87H,01H,07H,06H,05H,04H
  6747.     defb    03H,02H,95H,93H,91H,18H
  6748.     defb    19H,81H,83H,85H,97H
  6749.  
  6750. regptr:
  6751.     defb    0DH,0EH,0FH,00H
  6752.     defb    8DH,8EH,8FH,80H
  6753.     defb    0AH,09H,08H,10H
  6754.  
  6755. siotbl:    defb    0F5H,0F7H
  6756.  
  6757. symflg:    defb    0FFH        ;Symbol    Table flag   00    - Table    present
  6758.                 ;             ff    - no Table
  6759.  
  6760. bsiz:                ;DUMP block size storage
  6761. bsizlo:    defb    0        ;     Lo order
  6762. bsizhi:    defb    1        ;     HI Order
  6763. blkptr:    defw    100H        ;DUMP block Address
  6764.  
  6765. loadb:    defw    100H        ;Z8E Load Bias for ILDR command
  6766. loadn:    defw    00        ;End of Load Address
  6767.  
  6768. asmbpc:                ;Next PC location for assembly
  6769. zasmpc:    defw    100H        ;Next PC location for disassemble
  6770.                 ;Default at load time: start of    TPA
  6771. zasmfl:    defw    00        ;First disassembled Address on JDBG screen
  6772.  
  6773.  
  6774. from:
  6775. oprn01:
  6776. rlbias:
  6777. lines:
  6778. exampt:
  6779. endw:
  6780. zasmnx:    defb    0        ;Address of Next Instruction to    Disassemble
  6781. oprx01:    defb    0
  6782. bias:
  6783. biaslo:
  6784. zasmct:    defb    0        ;Disassembly Count
  6785. biashi:
  6786. oprn02:    defb    0
  6787. oprx02:
  6788. zasmwt:    defw    0        ;Disassembly Count - Working Tally
  6789. opnflg:    defb    0        ;00 - operand 1   FF - operand 2   ZASM
  6790.                 ;And Input Character Storage for Interactive
  6791.                 ;Disassembly 
  6792. quoflg:    defb    0
  6793. wflag:    defb    0FFH        ;TRACE SUBROUTINE FLAG:    NZ - Trace Subs
  6794.                 ;             Z - No    Trace
  6795.  
  6796. nstep:
  6797. nstepl:    defb    0
  6798. nsteph:    defb    0
  6799. è
  6800. sbps:    defb    0        ;Number    of STEP    BreakPoints
  6801. bps:    defb    0        ;Number    of Normal BreakPoints
  6802.  
  6803. zmflag:    defb    0
  6804. zasmf:    defb    0
  6805. execbf:                ;Execute Buffer    for Relocated Code
  6806. jlines:
  6807. parenf:    
  6808. nument:    defb    0        ;Number    of Digits Entered
  6809. delim:    defb    0        ;Argument Delimeter Character
  6810.     defb    0
  6811. base10:    defb    0
  6812. jmp2jp:    defb    0
  6813. jmp2:    defb    0
  6814. dwrite:
  6815. cflag:    defb    0
  6816.  
  6817. ikey:
  6818. zasmkv:
  6819. jmp:    defb    0
  6820. mexp:
  6821. jmplo:    defb    0
  6822. strngf:
  6823. jmphi:    defb    0
  6824. timer:
  6825. first:    defb    0
  6826. regtrm:    defb    0
  6827. trmntr: defb    0
  6828. isympt:    defw    0
  6829.  
  6830. jropnd:
  6831. pass2:    defw    0
  6832.  
  6833. fndsym:    defw    0
  6834.  
  6835. maxlen:    defw    14
  6836.  
  6837. maxlin:    defw    62
  6838.  
  6839. fwndow:    defb    00
  6840.  
  6841. nlmask:    defb    00    
  6842.     
  6843.  
  6844. case:    defb    0FFH        ;Flag to indicate case of Output
  6845.                 ;NZ - LOWER   Z - UPPER
  6846.  
  6847. jstepf:    defb    0FFH        ;00 -   Screen is Intact, if User Wants J 
  6848.                 ;       Single Step No Need to Repaint Screen, 
  6849.                 ;       Just Move Arrow.
  6850.                 ;01   - User Wants Single-Step J Command
  6851.                 ;Else - J Screen Corrupted by Non-J Command
  6852.  
  6853. lastro:    defb    03
  6854.  
  6855.  
  6856. rowb4?:    defb    01
  6857.  
  6858. mxycp:    defb    2,1bh,'='
  6859.     defs    8,00
  6860.  
  6861. xyrow:    defb    0
  6862. xycol:    defb    0
  6863.  
  6864. row:    defb    ' '
  6865. column:    defb    ' '
  6866.                                             
  6867.  
  6868. wnwtab:    defw    0
  6869. wnwsiz:    defw    0
  6870.  
  6871. port:    defw    0
  6872.  
  6873.  
  6874. brktbl:    defs    (maxbp+2)*3
  6875. psctbl:    defs    maxbp*2
  6876.  
  6877.  
  6878. regcon:
  6879. afreg:
  6880. freg:    defb    00
  6881.     defb    00
  6882. bcreg:    defw    00
  6883. dereg:    defw    00
  6884. hlreg:    defw    00
  6885. èafpreg:    defw    00
  6886. bcpreg:    defw    00
  6887. depreg:    defw    00
  6888. hlpreg:    defw    00
  6889. pcreg:
  6890. pcregl:    defb    00
  6891. pcregh:    defb    01
  6892. spreg:    defw    00
  6893. ixreg:    defw    00
  6894. iyreg:    defw    00
  6895.  
  6896. regsiz    equ    $-regcon
  6897.  
  6898. rreg:    defb    00
  6899. ireg:    defb    00
  6900.  
  6901.  
  6902. fstart:    defw    0
  6903. argbc:    defw    0
  6904. argbpt:    defw    argbf
  6905.  
  6906. regsav    equ    $        ;Storage for register contents in between BPs
  6907.                 ;While JDBG is in control
  6908.  
  6909. window    equ    regsav+regsiz    ;Memory window Save area
  6910.  
  6911. argbsz    equ    62
  6912.  
  6913. argbf:    defs    argbsz
  6914.  
  6915. FCB    equ     argbf+argbsz-36 ;CP/M File control block
  6916. fcbnam    equ    FCB+1        ;Start of File Name in FCB
  6917. fcbtyp    equ    fcbnam+8    ;Start of File type in FCB
  6918. fcbext    equ    fcbtyp+3    ;Current extent    Number
  6919. nfcb    equ    $        ;Last Byte of FCB plus one
  6920.  
  6921. gpbsiz    equ    164        ;Size of general purpose Buffer
  6922.  
  6923. symbuf:
  6924. objbuf:    defs    gpbsiz,00    ;Object    Code Buffer
  6925.  
  6926. inbfsz    equ    gpbsiz/2
  6927. inbfmx    equ    objbuf+4    ;Input Buffer -    max Byte count storage
  6928. inbfnc    equ    inbfmx+1    ;          -    Number Chars read in
  6929. inbf    equ    inbfnc+1    ;          -    starting Address
  6930. inbfl    equ    inbfsz-1    ;          -    Last relative position
  6931. ninbf    equ    inbf+inbfl    ;          -    Address    of Last    Char
  6932.  
  6933. prsbfz    equ    gpbsiz/2
  6934. prsbf    equ    inbf+inbfsz    ;Parse Buffer -    starting Address
  6935. lprsbf    equ    prsbf+prsbfz-1    ;          -    Last Char of parse buf
  6936. nprsbf    equ    lprsbf+1    ;          -    End Address plus one
  6937.  
  6938. nzasm    equ    $        ;End of Disassembly Buffer
  6939. zasmbf    equ    nzasm-128    ;Start of Disassembly Buffer
  6940.  
  6941.     defs    40
  6942. stack:
  6943. nmem    equ    ((256*(($+255)/256))-Z8Eorg) and 0FF00H
  6944.  
  6945.     .list
  6946.     End
  6947.  
  6948.