home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / SIMTEL / CPMUG / CPMUG049.ARK / FILTER2.Z80 < prev    next >
Text File  |  1984-04-29  |  5KB  |  221 lines

  1. ;********************************************************
  2. ;*                            *
  3. ;*        CODE TO IMPLEMENT THE            *
  4. ;*        ESSENTIAL CDOS CALLS            *
  5. ;*        WHICH WILL ALLOW MOST            *
  6. ;*        CROMEMCO SOFTWARE TO            *
  7. ;*        RUN UNDER CP/M                *
  8. ;*                            *
  9. ;********************************************************
  10. ;
  11. ;    From Dr. Dobbs, January 1980
  12. ;
  13. ;    by J. Warner, coded by Bill Bolton
  14. ;
  15. ;    FILTER2 version by Chuck Weingart:
  16. ;    1    added code to save and restore all
  17. ;        registers
  18. ;    2    correct small bug in program as pointed
  19. ;        out by Liegh F. Fiddes in October 1980
  20. ;        DDJ.
  21. ;    3    added code for 8D function (get CDOS version)
  22. ;    4    more comments supplied from original article
  23. ;
  24. ;    This program is uaed by making it part of the
  25. ;memory image of a Cromemco program. When it gets control
  26. ;it boosts the function code filter into place at the top
  27. ;of the TPA and then moves the original program down to
  28. ;100H and jumps to it.
  29. ;
  30. BDOS    EQU    0005H
  31. DUMMY    EQU    0000H
  32. IGOR    EQU    DUMMY
  33. ;
  34. ;    Measure the CP/M TPA size. Adjust the addresses in
  35. ;the function code of the function code filter for
  36. ;installation at the top of the TPA. Then change the jumps
  37. ;at 5,6 & 7 to route BDOS calls through the filter. Block
  38. ;move the filter to the top of the TPA.
  39. ;
  40. ;
  41.     ORG    100H
  42.     LD    HL,(6)        ;GET BDOS ENTRY
  43.     LD    (CPM1+1),HL    ;INSTALL
  44.     LD    (CPM2+1),HL
  45.     DEC    H        ;MAKE ROOM FOR FILTER
  46.     LD    L,0
  47.     LD    (6),HL        ;INSTALL FILTER ADDRESS
  48.     EX    DE,HL
  49.     LD    HL,(1)        ;GET WARM BOOT ADDRESS,
  50.     INC    HL        ;IN BIOS JUMP TABLE
  51.     INC    HL
  52.     INC    HL        ;CSTAT ADDRESS
  53.     LD    (CSTAT+1),HL    ;INSTALL
  54.     INC    HL        ;BUMP 3 TIMES TO FIND,
  55.     INC    HL        ;CONIN
  56.     INC    HL
  57.     LD    (GBYTE+1),HL    ;INSTALL
  58.     LD    HL,NAME-FILTER    ;CALCULATE RELATIVE,
  59.     ADD    HL,DE        ;SUBROUTINE ADDRESS
  60.     LD    (NAM1+1),HL
  61.     LD    (NAM2+1),HL
  62.     LD    HL,FILTER
  63.     LD    BC,END-FILTER
  64.     LDIR            ;INSTAL FILTER
  65. ;
  66. ;    Part 2
  67. ;
  68. ;    The filter just installed contains a one use
  69. ;routine to move the *.COM file on top of this stuff
  70. ;and into position. First put the stack between CP/M
  71. ;and the filter
  72. ;
  73. ;
  74.     LD    DE,(6)        ;GET FILTER ADDRESS
  75.     LD    IX,MOVE-FILTER
  76.     ADD    IX,DE        ; MOVE relocated addr
  77.     LD    HL,MOVE-FILTER+80H
  78.     ADD    HL,DE        ; for the
  79.     LD    SP,HL        ;  stack
  80.     LD    DE,MESG
  81.     LD    C,9
  82.     CALL    BDOS        ; send filter logo
  83.     JP    (IX)        ; jump to relocated MOVE routine
  84. ;
  85. MESG:    DEFW    0D0AH
  86.     DEFM    'CDOS FILTER LOADED'
  87.     DEFW    0D0AH
  88.     DEFW    0D0AH
  89.     DEFB    '$'
  90. ;
  91. ;    PART 3
  92. ;
  93. ;    The following CPM/CDOS codes are affected:
  94. ;      2    write character to console: the A-reg 
  95. ;        must be saved and restored
  96. ;     11    check console status: this request is
  97. ;        passed directly to the BIOS
  98. ;    128    read console (no echo): this request is
  99. ;        passed directly to the BIOS
  100. ;    134    format string to File Control Block. It
  101. ;        does not implement "*" wild cards.
  102. ;    141    get CDOS version. this is implemented by
  103. ;        simply ignoring the call entirely.
  104. ;
  105. ;    Note: it is a characteristic of CDOS that all
  106. ;    registers are saved and restored, even in the
  107. ;    "BIOS" portion of the code. Thus, a program that
  108. ;    runs under CDOS might not run under CP/M, even
  109. ;    if no specific CDOS calls are used.
  110. ;
  111. FILTER:    PUSH    AF
  112.     LD    A,C
  113.     CP    02H        ;write fcn code??
  114.     JR    NZ,NOTWR
  115.     POP    AF        ;going to re-save A-reg later
  116.     PUSH    DE
  117.     RES    7,E        ;turn off high-order bit in E-reg
  118.     PUSH    BC        
  119.     PUSH    HL        ;must save all registers
  120. ;
  121.     PUSH    AF
  122. CPM1:    CALL    DUMMY    ; >>> Addr supplied by Part 1 <<<
  123.     POP    AF
  124. ;
  125. GOBAK:    POP    HL
  126.     POP    BC        ;restore all registers
  127.     POP    DE
  128.     RET            ;and return
  129. ;
  130. GOCPM:    PUSH    DE        ;save all regs
  131.     PUSH    BC
  132.     PUSH    HL
  133. CPM2:    CALL    DUMMY    ; >>> Addr supplied by Part 1 <<<
  134.     JR    GOBAK
  135. ;
  136. NOTWR:    POP    AF        ;get A-reg back now
  137.     LD    A,C
  138.     CP    0BH        ;constat fcn code ??
  139. CSTAT:    JP    Z,DUMMY    ; >>> Addr supplied by Part 1 <<<
  140.     ADD    A,A
  141.     JR    NC,GOCPM    ;not a special fcn code
  142. ;
  143. GBYTE:    JP    Z,DUMMY        ;CY=1 & Z=1 --> FCN CODE=80H
  144.     LD    A,8DH
  145.     CP    C        ;get CDOS version fcn code ??
  146.     JR    Z,GOBAK
  147.     LD    A,86H
  148.     CP    C        ;format string to fcb fcn code ??
  149.     JP    NZ,IGOR
  150. ;
  151. ;    FORMAT STRING TO FCB - 86H
  152. ;
  153.     PUSH    DE
  154.     LD    B,(HL)        ;might be disk designator
  155.     INC    HL
  156.     LD    A,(HL)        ;if this is ":" then B-reg
  157.     CP    ':'        ; contains drive #
  158.     JR    NZ,NOCOL
  159.     INC    HL        ;pointer past colon
  160.     LD    A,7
  161.     AND    B        ;mask
  162.     JR    FIRST
  163. NOCOL:    DEC    HL
  164.     XOR    A        ;set for default disk drive
  165. FIRST:
  166.     LD    (DE),A        ;first byte of FCB
  167.     INC    DE
  168.     LD    B,8        ;max # of chars in name
  169. NAM1:    CALL    DUMMY    ; >>> Addr supplied by Part 1 <<<
  170.     LD    A,'.'
  171.     CP    (HL)        ;check for "."
  172.     JR    NZ,EXT
  173.     INC    HL
  174. EXT:    LD    B,3        ;max # of chars in extension
  175. NAM2:    CALL    DUMMY    ; >>> Addr supplied by Part 1 <<<
  176.     XOR    A        ;zero file extent
  177.     LD    (DE),A
  178. ;
  179. ;    next 5 lines from Leigh F. Fiddes
  180. ;
  181.     PUSH    HL        ;save HL reg pair
  182.     LD    HL,20        ;offset from extent to next rec.
  183.     ADD    HL,DE        ;HL points to next record field
  184.     LD    (HL),A        ;zero next record
  185.     POP    HL        ;restore HL reg pair
  186.     POP    DE
  187.     RET
  188. ;
  189. ;    internal routine to move ASCII string, with blank fill
  190. ;
  191. NAME:    LD    A,(HL)        ;get next char from string
  192.     CP    21H        ;termination character ??
  193.     JR    C,FILL
  194.     INC    HL
  195.     CP    '.'        ;none of these in FCB's
  196.     JR    Z,FILL
  197.     CP    60H        ;lower case "A"-1
  198.     JR    C,NAME1        ;JMP if not lower case
  199.     SUB    20H        ;convert lower case to upper
  200. NAME1:    LD    (DE),A
  201.     INC    DE        ;put character in FCB
  202.     DJNZ    NAME
  203.     RET            ;all done
  204. ;
  205. FILL:    LD    A,20H        ;ASCII space
  206.     LD    (DE),A
  207.     INC    DE        ;fill rest of FCB with blanks
  208.     DJNZ    FILL
  209.     RET
  210. ;
  211. ;    this routine does actual move of program back to 100H
  212. ;
  213. MOVE:    LD    HL,200H        ;bottom of program
  214.     LD    BC,(6)        ;top of TPA
  215.     DEC    B        ;amount to move down
  216.     LD    DE,100H        ;origin for COM files
  217.     LDIR
  218.     JP    100H        ;now, go to it
  219. END:    EQU    $
  220.     END
  221.