home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / jsage / zsus / progpack / debug11.lbr / TCAPVID.LZB / TCAPVID.LIB
Encoding:
Text File  |  1992-05-13  |  9.6 KB  |  530 lines

  1. ;
  2. ; VLIB ROUTINES
  3. ;
  4.  
  5.  
  6. ;
  7. ; Common vlib routine to find terminal info in ENV
  8. ;
  9. vterm:
  10.     ld    hl,z3env+80h    ; Pt to environment
  11.     ld    a,(hl)        ; No terminal?
  12.     cp    ' '+1
  13.     ret
  14.  
  15.  
  16. ;
  17. ; CLEAR SCREEN ON TERMINAL
  18. ;
  19.      if    [not clson]
  20. cls:
  21.     push    hl        ; Save regs
  22.     push    de
  23.     call    vterm
  24.     jr    c,clserr
  25.     ld    de,14h        ; Pt to cls delay
  26.     add    hl,de
  27.     ld    d,(hl)        ; Get it
  28.     inc    hl        ; Pt to cls string
  29.     inc    hl
  30.     inc    hl
  31.     ld    a,(hl)        ; Get first char of string
  32.     or    a        ; If no string, error
  33.     jr    z,clserr
  34.     call    vidout        ; Output string with delay
  35.     pop    de        ; Done
  36.     pop    hl
  37.     xor    a        ; Return nz
  38.     dec    a
  39.     ret
  40. clserr:
  41.     pop    de        ; Done
  42.     pop    hl
  43.     xor    a        ; Return z
  44.     ret
  45.  
  46.      endif            ; Not clson
  47.  
  48. ;
  49. ; Erase to End of Line
  50. ;    Return with A=0 and Zero Flag Set if not done
  51. ;
  52. ereol:
  53.     push    bc        ; Save regs
  54.     push    de
  55.     push    hl
  56.     call    vterm
  57.     jr    c,err
  58.     ld    de,16h        ; Pt to ereol delay
  59.     add    hl,de
  60.     ld    d,(hl)        ; Get it
  61.     inc    hl        ; Pt to cls string
  62.     call    vidskp        ; Skip over it
  63.     call    vidskp        ; Skip over cm string
  64.     ld    a,(hl)        ; Get first char of ereol string
  65.     or    a        ; If no string, error
  66.     jr    z,err
  67.     call    vidout        ; Output string with delay
  68.     jr    noerr
  69.  
  70. ;
  71. ; GOTO XY
  72. ;    HL = Row/Col, with Home=1/1
  73. ;    Return with A=0 and Zero Flag Set if not done
  74. ;
  75. gotoxy:
  76.     push    bc        ; Save regs
  77.     push    de
  78.     push    hl
  79.     call    vterm
  80.     jr    c,err
  81.     ld    de,15h        ; Pt to cm delay
  82.     add    hl,de
  83.     ld    a,(hl)        ; Get it
  84.     ld    (cmdelay),a    ; Save it
  85.     inc    hl        ; Pt to cl string
  86.     inc    hl
  87.     call    vidskp        ; Skip cl string
  88.     ld    a,(hl)        ; Get first char of cm string
  89.     or    a        ; If no string, error
  90.     jr    z,err
  91.     ex    de,hl        ; De=address of cm string
  92.     pop    hl        ; Get coordinates in hl
  93.     push    hl
  94.     call    gxy        ; Output xy string with delay
  95.     ld    a,(cmdelay)    ; Pause
  96.     call    videlay
  97. noerr:
  98.     pop    hl        ; Done
  99.     pop    de
  100.     pop    bc
  101.     xor    a        ; Return nz
  102.     dec    a
  103.     ret
  104. err:
  105.     pop    hl        ; Done
  106.     pop    de
  107.     pop    bc
  108.     xor    a        ; Return z
  109.     ret
  110.  
  111. ;
  112. ; Position Cursor at Location Specified by Return Address
  113. ; Usage:
  114. ;    call    at
  115. ;    db    row,col ;location
  116. ;
  117. at:
  118.     ex    (sp),hl        ; Pt to address
  119.     push    de        ; Save de
  120.     ld    d,(hl)        ; Get row
  121.     inc    hl
  122.     ld    e,(hl)
  123.     inc    hl        ; Hl pts to return byte
  124.     ex    de,hl        ; De pts to return byte, hl contains screen loc
  125.     call    gotoxy        ; Position cursor
  126.     ex    de,hl        ; Hl pts to return byte
  127.     pop    de        ; Restore registers
  128.     ex    (sp),hl        ; Restore stack ptr
  129.     ret
  130.  
  131. ;
  132. ; GOTOXY
  133. ;   On input, H=Row and L=Column to Position To (1,1 is Home)
  134. ;   On input, DE=address of CM string
  135. ;
  136. gxy:
  137.     dec    h        ; Adjust to 0,0 for home
  138.     dec    l
  139.     xor    a        ; Set row/column
  140.     ld    (rcorder),a    ; Row before column
  141.     ld    (rcbase),a    ; Add 0 to base
  142. ;
  143. ; Cycle thru string
  144. ;
  145. gxyloop:
  146.     ld    a,(de)        ; Get next char
  147.     inc    de        ; Pt to next
  148.     or    a        ; Done?
  149.     ret    z
  150.     cp    '%'        ; Command?
  151.     jr    z,gxycmd
  152.     cp    '\'        ; Escape?
  153.     jr    z,gxyesc
  154.     call    conout        ; Send char
  155.     jr    gxyloop
  156.  
  157. ;
  158. ; Escape - output following byte literally
  159. ;
  160. gxyesc:
  161.     ld    a,(de)        ; Get next char
  162.     call    conout        ; Output literally
  163.     inc    de        ; Pt to next
  164.     jr    gxyloop
  165. ;
  166. ; Interpret next character as a command character
  167. ;
  168. gxycmd:
  169.     ld    a,(de)        ; Get command char
  170.     inc    de        ; Pt to next
  171.     cp    'd'        ; %d
  172.     jr    z,gxyout1
  173.     cp    '2'        ; %2
  174.     jr    z,gxyout2
  175.     cp    '3'        ; %3
  176.     jr    z,gxyout3
  177.     cp    '.'        ; %.
  178.     jr    z,gxyout4
  179.     cp    '+'        ; %+v
  180.     jr    z,gxyout5
  181.     cp    '>'        ; %>xy
  182.     jr    z,gxygt
  183.     cp    'r'        ; %r
  184.     jr    z,gxyrev
  185.     cp    'i'        ; %i
  186.     jr    z,gxyinc
  187.     call    conout        ; Output char if nothing else
  188.     jr    gxyloop
  189. ;
  190. ; Set row/col home to 1,1 rather than 0,0
  191. ;
  192. gxyinc:
  193.     ld    a,1        ; Set rcbase to 1
  194.     ld    (rcbase),a
  195.     jr    gxyloop
  196. ;
  197. ; Reverse order of output to column then row (default is row then column)
  198. ;
  199. gxyrev:
  200.     ld    a,1        ; Set column and row order
  201.     ld    (rcorder),a
  202.     jr    gxyloop
  203. ;
  204. ; Command: >xy
  205. ;   If value of row/col is greater than x, add y to it
  206. ;
  207. gxygt:
  208.     call    getval        ; Get value
  209.     ld    c,a        ; Save value
  210.     ld    a,(de)        ; Get value to test
  211.     inc    de        ; Pt to next
  212.     cp    c        ; If carry, value>x
  213.     jr    nc,gxygt1
  214.     ld    a,(de)        ; Get value to add
  215.     add    a,c
  216.     call    putval        ; Put value back
  217. gxygt1:
  218.     inc    de        ; Pt to next
  219.     jp    gxyloop        ; Resume
  220. ;
  221. ; Command: +n
  222. ;   Add n to next value and output
  223. ;
  224. gxyout5:
  225.     ld    a,(de)        ; Get value to add
  226.     inc    de        ; Pt to next
  227.     ld    b,a        ; Save in b
  228.     call    getval        ; Get value
  229.     add    a,b        ; Add in b
  230.     call    conout        ; Output value
  231. rcmark:
  232.     ld    a,(rcorder)    ; Mark output
  233.     or    80h
  234.     ld    (rcorder),a
  235.     jp    gxyloop
  236. ;
  237. ; Command: .
  238. ;   Output next value
  239. ;
  240. gxyout4:
  241.     call    getval        ; Get value
  242.     call    conout        ; Output value
  243.     jp    rcmark
  244. ;
  245. ; Command: 3
  246. ;   Output next value as 3 decimal digits
  247. ;
  248. gxyout3:
  249.     call    getval        ; Get value
  250.     ld    b,100        ; Output 100's
  251.     ld    c,1        ; Leading zeroes
  252.     call    digout
  253. gxyot3:
  254.     ld    b,10        ; Output 10's
  255.     ld    c,1        ; Leading zeroes
  256. gxyot2:
  257.     call    digout
  258.     add    '0'        ; Output 1's
  259.     call    conout
  260.     jp    rcmark
  261. ;
  262. ; Command: 2
  263. ;   Output next value as 2 decimal digits
  264. ;
  265. gxyout2:
  266.     call    getval        ; Get value
  267.     jr    gxyot3
  268. ;
  269. ; Command: d
  270. ;   Output next value as n decimal digits with no leading zeroes
  271. ;
  272. gxyout1:
  273.     call    getval        ; Get value
  274.     ld    b,100        ; Output 100's
  275.     ld    c,0        ; No leading zeroes
  276.     call    digout
  277.     ld    b,10        ; Output 10's
  278.     ld    c,0        ; No leading zeroes
  279.     jr    gxyot2
  280. ;
  281. ; Return next value in A
  282. ;
  283. getval:
  284.     ld    a,(rcorder)    ; Get order flag
  285.     or    a        ; Already output the first value?
  286.     jp    m,getval2
  287.     and    1        ; Look at lsb
  288.     jr    z,getvalr    ; If 0, row first
  289. getvalc:
  290.     ld    a,(rcbase)    ; Get base offset
  291.     add    a,l        ; Get column
  292.     ret
  293. getvalr:
  294.     ld    a,(rcbase)    ; Get base offset
  295.     add    a,h        ; Get row
  296.     ret
  297. getval2:
  298.     and    1        ; Look at lsb
  299.     jr    z,getvalc
  300.     jr    getvalr
  301. ;
  302. ; Store A as next value
  303. ;
  304. putval:
  305.     ld    c,a        ; Save value
  306.     ld    a,(rcorder)    ; Get order flag
  307.     or    a        ; Already output the first value?
  308.     jp    m,putval2
  309.     and    1        ; Look at lsb
  310.     jr    z,putvalr    ; If 0, row first
  311. putvalc:
  312.     ld    l,c        ; Set column
  313.     ret
  314. putvalr:
  315.     ld    h,c        ; Set row
  316.     ret
  317. putval2:
  318.     and    1        ; Look at lsb
  319.     jr    z,putvalc
  320.     jr    putvalr
  321. ;
  322. ; Output A as decimal digit char
  323. ;   B=Quantity to Subtract from A, C=0 if no leading zero
  324. ;
  325. digout:
  326.     push    de        ; Save de
  327.     ld    d,'0'        ; Char
  328. decot1:
  329.     sub    b        ; Subtract
  330.     jr    c,decot2
  331.     inc    d        ; Increment char
  332.     jr    decot1
  333. decot2:
  334.     add    a,b        ; Add back in
  335.     push    af        ; Save result
  336.     ld    a,d        ; Get digit
  337.     cp    '0'        ; Zero?
  338.     jr    nz,decot3
  339.     ld    a,c        ; Get zero flag
  340.     or    a        ; 0=no zero
  341.     jr    z,decot4
  342. decot3:
  343.     ld    a,d        ; Get digit
  344.     call    conout        ; Print it
  345. decot4:
  346.     pop    af        ; Get a
  347.     pop    de        ; Restore de
  348.     ret
  349. ;
  350. ; GXY Buffers
  351. ;
  352. rcorder:
  353.     ds    1        ; 0=row/col, else col/row
  354. rcbase:
  355.     ds    1        ; 0=org is 0,0, else org is 1,1
  356. cmdelay:
  357.     ds    1        ; Number of milliseconds to delay for cm
  358.  
  359. ;
  360. ; Begin Standout Mode
  361. ;    Return with A=0 and Zero Flag Set if not done
  362. ;
  363. stndout:
  364.     push    bc
  365.     push    de
  366.     push    hl        ; Save regs
  367.     call    vterm
  368.     jp    c,err
  369.     ld    de,17h        ; Pt to cls string
  370.     add    hl,de
  371.     ld    d,0        ; No delay
  372. stnd1:    call    vidskp        ; Skip over cl string
  373.     call    vidskp        ; Skip over cm string
  374.     call    vidskp        ; Skip over ce string
  375.     ld    a,(hl)        ; Get first char of so string
  376.     or    a        ; If no string, error
  377.     jp    z,err
  378.     call    vidout        ; Output string with delay
  379.     jp    noerr
  380.  
  381. ;
  382. ; Terminate Standout Mode
  383. ;    Return with A=0 and Zero Flag Set if not done
  384. ;
  385. stndend:
  386.     push    bc
  387.     push    de
  388.     push    hl        ; Save regs
  389.     call    vterm
  390.     jp    c,err
  391.     ld    de,17h        ; Pt to cls string
  392.     add    hl,de
  393.     ld    d,0        ; No delay
  394.     call    vidskp        ; Skip over cl string
  395.     jr    stnd1
  396.  
  397. ;
  398. ; Initialize Terminal
  399. ;    Affect No Registers
  400. ;
  401. tinit:
  402.     push    hl        ; Save regs
  403.     push    de
  404.     push    af
  405.     call    vterm
  406.     jp    c,tid
  407.     ld    de,17h        ; Pt to cls string
  408.     add    hl,de
  409.     ld    d,0        ; No delay
  410. tinit1:    call    vidskp        ; Skip over cl string
  411.     call    vidskp        ; Skip over cm string
  412.     call    vidskp        ; Skip over ce string
  413.     call    vidskp        ; Skip over so string
  414.     call    vidskp        ; Skip over se string
  415.     ld    a,(hl)        ; Get first char of ti string
  416.     or    a        ; If no string, error
  417.     jp    z,tid
  418.     call    vidout        ; Output string with delay
  419. tid:
  420.     pop    af        ; Done
  421.     pop    de
  422.     pop    hl
  423.     ret
  424.  
  425. ;
  426. ; De-Initialize Terminal
  427. ;    Affect No Registers
  428. ;
  429. dinit:
  430.     push    hl        ; Save regs
  431.     push    de
  432.     push    af
  433.     call    vterm
  434.     jp    c,tid
  435.     ld    de,17h        ; Pt to cls string
  436.     add    hl,de
  437.     ld    d,0        ; No delay
  438.     call    vidskp        ; Skip over cl string
  439.     jr    tinit1
  440.  
  441.  
  442. ;
  443. ;  VIDOUT - Output video string pted to by HL
  444. ;    Output also a delay contained in the D register
  445. ;
  446. vidout:
  447.     ld    a,(hl)        ; Get next char
  448.     or    a        ; Done if zero
  449.     jr    z,vid2
  450.     inc    hl        ; Pt to next
  451.     cp    '\'        ; Literal value?
  452.     jr    nz,vid1
  453.     ld    a,(hl)        ; Get literal char
  454.     inc    hl        ; Pt to after it
  455. vid1:
  456.     call    conout        ; Output char
  457.     jr    vidout
  458. vid2:
  459.     ld    a,d        ; Output delay and fall thru to videlay
  460.  
  461. ;
  462. ;    VIDELAY pauses for the number of milliseconds indicated by the A
  463. ; register.  VIDELAY assumes a ZCPR3 environment and uses it to determine
  464. ; processor speed.
  465. ;
  466. videlay:
  467.     push    af        ; Save regs
  468.     push    bc
  469.     push    de
  470.     push    hl
  471.     ld    c,a        ; Save count in c
  472.     or    a        ; No delay?
  473.     jr    z,done
  474.     ld    hl,z3env    ; Pt to environment
  475.     ld    de,2bh        ; Offset to processor speed
  476.     add    hl,de
  477.     ld    a,(hl)        ; Get processor speed
  478.     or    a        ; Zero?
  479.     jr    nz,vidl1
  480.     ld    a,4        ; Assume 4 mhz
  481. vidl1:
  482.     ld    b,a        ; Processor speed in b
  483. vidl2:
  484.     push    bc        ; Delay 1 ms
  485.     call    delay
  486.     pop    bc
  487.     dec    c        ; Count down
  488.     jr    nz,vidl2
  489. done:
  490.     pop    hl        ; Restore regs
  491.     pop    de
  492.     pop    bc
  493.     pop    af
  494.  
  495.     ret
  496. ;
  497. ;  Delay 1 ms at Clock speed
  498. ;
  499. delay:
  500.     call    del1        ; Delay 1 ms at 1mhz
  501.     dec    b        ; Count down clock speed
  502.     jp    nz,delay
  503.     ret
  504. ;
  505. ;  Delay 1 ms at 1MHz
  506. ;
  507. del1:
  508.     ld    c,20        ; 20 loops of 51 cycles each ~ 1000 cycles
  509. del1a:
  510.     ex    (sp),hl        ; 18 cycles
  511.     ex    (sp),hl        ; +18 = 36 cycles
  512.     dec    c        ; + 5 = 41 cycles
  513.     jr    nz,del1a    ; +10 = 51 cycles
  514.     ret
  515.  
  516. ;
  517. ;  VIDSKP - Skip over video string pted to by HL; pt to byte after string
  518. ;
  519. vidskp:
  520.     ld    a,(hl)        ; Get next char
  521.     inc    hl        ; Pt to next
  522.     or    a        ; Done if zero
  523.     ret    z
  524.     cp    '\'        ; Literal value?
  525.     jr    nz,vidskp    ; Continue if not
  526.     inc    hl        ; Pt to after literal value
  527.     jr    vidskp
  528. if zero
  529.     ret    z
  530.     cp    '\'        ; Literal value?
  531.