home *** CD-ROM | disk | FTP | other *** search
/ norge.freeshell.org (192.94.73.8) / 192.94.73.8.tar / 192.94.73.8 / pub / computers / cpm / alphatronic / DRIPAK.ZIP / CPM_3-0 / SOURCES / GETF.ASM < prev    next >
Assembly Source File  |  1982-12-31  |  11KB  |  487 lines

  1. $title('GETF  - CP/M 3.0 Input Redirection - August 1982')
  2.     name    getf
  3. ;******************************************************************
  4. ;
  5. ;    get  'Input Redirection Initializer'  version 3.0
  6. ;
  7. ;     11/30/82 - Doug Huskey
  8. ;******************************************************************
  9. ;
  10. ;
  11. ;    Copyright (c) 1982
  12. ;    Digital Research
  13. ;    P.O. Box 579
  14. ;    Pacific Grove, Ca.
  15. ;    93950
  16. ;
  17. ;
  18. ;    generation procedure
  19. ;
  20. ;    seteof get.plm
  21. ;    seteof getscan.dcl
  22. ;    seteof getf.asm
  23. ;    seteof getscan.plm
  24. ;    seteof parse.asm
  25. ;    is14
  26. ;    asm80 getf.asm debug
  27. ;    asm80 mcd80a.asm debug
  28. ;    asm80 parse.asm debug
  29. ;    plm80 get.plm pagewidth(100) debug optimize
  30. ;    link mcd80a.obj,get.obj,parse.obj,getf.obj,plm80.lib to get.mod
  31. ;    locate get.mod code(0100H) stacksize(100)
  32. ;    era get.mod
  33. ;    cpm
  34. ;    objcpm get
  35. ;    rmac getrsx
  36. ;    link getrsx[op]
  37. ;    era get.rsx
  38. ;    ren get.rsx=getrsx.prl
  39. ;    gencom get.com
  40. ;    gencom get.com get.rsx 
  41. ;    
  42. ;
  43. ;
  44. ;    This module is called as an external routine by the
  45. ;    PL/M routines GET and SUBMIT.  It is passed a structure
  46. ;    with the following format:
  47. ;
  48. ;
  49. ;          declare getpb structure
  50. ;            (input$type   byte,
  51. ;             echo$flag     byte,
  52. ;             filtered$flag byte,
  53. ;             program$flag  byte);
  54. ;
  55. ;    input$type     = 0     > console input (default)
  56. ;                = 1     > auxiliary output
  57. ;
  58. ;    echo        = true  > echo input to real device
  59. ;                  (default)
  60. ;            = false > don't echo input (output is 
  61. ;                  still echoed)
  62. ;    filtered     = true  > convert control characters
  63. ;                  to a printable form 
  64. ;                      preceeded by an ^ in echo
  65. ;                  (default)
  66. ;            = false > no character conversions
  67. ;    program         = false > continue until EOF or 
  68. ;                  GET INPUT FROM CONSOLE
  69. ;                      command
  70. ;            = true  > active only until program
  71. ;                  termination
  72. ;
  73.     public    getf
  74.     extrn    mon1,fcb,memsiz
  75. ;
  76. ;
  77. true        equ    0ffffh
  78. false        equ    00000h
  79. ;
  80. biosfunctions    equ    true        ;intercept BIOS conin & constat 
  81. ;
  82. ;
  83. ;    low memory locations
  84. ;
  85. wboot    equ    0000h
  86. wboota    equ    wboot+1
  87. ;
  88. ;    equates for non graphic characters
  89. ;
  90. cr    equ    0dh    ; carriage return
  91. lf    equ    0ah    ; line feed
  92. ;
  93. ;    BDOS function equates
  94. ;
  95. cinf    equ    1    ;read character
  96. coutf    equ    2    ;output character
  97. crawf    equ    6    ;raw console I/O
  98. creadf    equ    10    ;read buffer
  99. cstatf    equ    11    ;status
  100. pchrf    equ    5    ;print character
  101. pbuff    equ    9    ;print buffer
  102. openf    equ    15    ;open file
  103. closef    equ    16    ;close file
  104. delf    equ    19    ;delete file
  105. dreadf    equ    20    ;disk read
  106. dmaf    equ    26    ;set dma function
  107. curdrv    equ    25
  108. userf    equ    32    ;set/get user number
  109. scbf    equ    49    ;set/get system control block word
  110. rsxf    equ    60    ;RSX function call
  111. initf    equ    128    ;GET initialization sub-function no.
  112. killf    equ    129    ;GET delete sub-function no.
  113. jkillf    equ    141    ;JOURNAL delete sub-function no.
  114. ;
  115. ;    System Control Block definitions
  116. ;
  117. scba    equ    03ah    ;offset of scbadr from SCB base
  118. ccpflg2    equ    0b4h    ;offset of 2nd ccp flag byte from pg bound
  119. errflg    equ    0aah    ;offset of error flag from page boundary
  120. conmode    equ    0cfh    ;offset of console mode from page boundary
  121. listcp    equ    0d4h    ;offset of ^P flag from page boundary
  122. common    equ    0f9h    ;offset of common memory base from pg. bound
  123. wbootfx    equ    068h    ;offset of warm boot jmp from page. bound
  124. constfx    equ    06eh    ;offset of constat jmp from page. bound
  125. coninfx    equ    074h    ;offset of conin jmp from page. bound
  126. conoufx    equ    07ah    ;offset of conout jmp from page. bound
  127. listfx    equ    080h    ;offset of list jmp from page. bound
  128. realdos    equ    098h    ;offset of real BDOS entry from pg. bound
  129. ;
  130. ;    Restore mode equates    (used with inr a, rz, rm, rpe, ret)
  131. ;
  132. norestore    equ    0ffh    ;no BIOS interception
  133. biosonly    equ    07fh    ;restore BIOS jump table only
  134. stfix    equ    080h    ;restore BIOS jump table and
  135.                 ;restore JMP in RESBDOS for constat
  136. everything    equ    0    ;restore BIOS jump table and jmps in
  137.                 ;RESBDOS (default mode)
  138. ;
  139. ;    Instructions
  140. ;
  141. lxih        equ    21h    ;LXI H, instruction
  142. jmpi        equ    0c3h    ;JMP instruction
  143. shldi        equ    22h    ;SHLD instruction
  144. ;
  145. ;******************************************************************
  146. ;        START OF INITIALIZATION CODE
  147. ;******************************************************************
  148.  
  149.         cseg
  150.  
  151. getf:
  152.     ;get parameters
  153.     mov    h,b
  154.     mov    l,c        ;HL = .(parameter block)
  155.     mov    a,m        ;input type 0=con:,1=aux:
  156.     cpi    1        ;is it aux?
  157.     jz    notimp        ;error if so
  158.     inx    h
  159.     mov    a,m        ;echo/noecho mode
  160.     sta    echo
  161.     inx    h
  162.     mov    a,m        ;cooked/raw mode    
  163.     sta    cooked    
  164.     inx    h
  165.     mov    a,m
  166.     sta    program
  167.     ;
  168.     ;check if enough memory
  169.     ;
  170.     lhld    memsiz
  171.     mov    a,h
  172.     cpi    20h
  173.     jc    nomem
  174.     ;
  175.     ;close to get those blocks in the directory
  176.     ;
  177.     lxi    d,fcb
  178.     mvi    c,closef
  179.     call    mon1
  180.     ;
  181.     ;check if drive specified
  182.     lxi    h,fcb
  183.     mov    a,m        ;drive code
  184.     ora    a        ;default?
  185.     jnz    movfcb
  186.     ;
  187.     ;set to current drive, if  not
  188.     ;
  189.     push    h        ;save .fcb
  190.     mvi    c,curdrv
  191.     call    mon1
  192.     pop    h        ;a=current drive, hl=.fcb
  193.     inr    a
  194.     mov    m,a        ;set fcb to force drive select
  195.     ;
  196. movfcb:    ;copy default fcb up into data area for move to RSX
  197.     ;
  198.     lxi    d,subfcb
  199.     lxi    b,32        ;length of fcb
  200.     call    ldir        ;move it to subfcb
  201.     ;
  202.     ;initialize other variables to be moved to RSX
  203.     ;
  204.     call    getusr        ;get current user number
  205.     sta    subusr        ;save for redirection file I/O
  206.     call    getscbadr
  207.     shld    scbadr        ;System Control Block address
  208.     ;
  209.     ;get real BDOS address (bypass chain to check for user break)
  210.     ;
  211.     mvi    l,realdos
  212.     mov    e,m
  213.     inx    h
  214.     mov    d,m
  215.     xchg
  216.     shld    realbdos+1
  217.     ;
  218.     ;check for user abort
  219.     ;
  220.     xchg
  221.     mvi    l,conmode
  222.     mov    a,m
  223.     ori    1        ;set ^C status mode
  224.     mov    m,a
  225.     mvi    c,cstatf
  226.     call    realbdos    ;check for user abort
  227.     ora    a
  228.     jnz    error1        ;abort if so
  229.     ;
  230.     ;get address of initialization table in RSX
  231.     ;
  232.     mvi    c,rsxf
  233.     lxi    d,journkill
  234.     call    mon1        ;terminate any PUT INPUT commands
  235.     mvi    c,rsxf
  236.     lxi    d,rsxinit
  237.     call    mon1        ;call GET.RSX initialization routine
  238.     push    h        ;save for move at end of setup
  239.     mov    e,m
  240.     inx    h
  241.     mov    d,m        ;DE = .RSXKILL flag 
  242.     push    d        ;set flag to zero if successfull
  243.     inx    h        ;HL = .(real bios status routine)
  244.     push    h
  245.     ;
  246. if biosfunctions
  247.     ;
  248.     ;check if BIOS jump table looks valid (jmp in right places)
  249.     lhld    wboota
  250.     lxi    d,3
  251.     dad    d        ;HL = .(jmp constat address)
  252.     mov    a,m
  253.     cpi    jmpi        ;should be a jump
  254.     jnz    bioserr        ;skip bios redirection if not
  255.     dad    d        ;HL = .(jmp conin address)
  256.     mov    a,m
  257.     cpi    jmpi
  258.     jnz    bioserr        ;skip bios redirection if not
  259.     ;
  260.     ;fix up RESBDOS to do BIOS calls to intercepted functions
  261.     ;
  262.     lhld    scbadr
  263.     mvi    l,common+1
  264.     mov    a,m        ;get high byte of common base
  265.     ora    a        
  266.     jnz    fix0        ;high byte = zero if non-banked
  267.     mvi    a,biosonly
  268.     sta    biosmode
  269.     jmp    trap        ;skip code that fixes resbdos
  270.     ;fix BIOS constat
  271. fix0:    mvi    l,constfx        ;hl = .constfx in SCB
  272.     mov    a,m
  273.     cpi    jmpi        ;is it a jump instruction?
  274.     jz    fix1        ;jump if so
  275.     mvi    a,biosonly    ;whoops already changed
  276.     sta    biosmode    ;restore jump table only
  277. fix1:    mvi    m,lxih
  278.     ;fix BIOS conin
  279.     mvi    l,coninfx    ;hl = .coninfx in SCB
  280.     mov    a,m
  281.     cpi    jmpi        ;is it a jump instruction?
  282.     lda    biosmode
  283.     jz    fix2        ;jump if so
  284.     cpi    biosonly
  285.     jnz    bioserr        ;error if conin is LXI but not constat
  286.     xra    a        ;zero accumulator to jnz below
  287. fix2:    cpi    biosonly    ;was const already an LXI h?
  288.     jnz    fix3        ;jmp if not
  289.     mvi    a,stfix    ;restore constat jmp but not conin
  290.     sta    biosmode
  291. fix3:    mvi    m,lxih
  292.     ;get addresses of RSX const and conin traps
  293. trap:    pop    h
  294.     mov      c,m        ;HL = .(.bios constat trap)
  295.     inx    h
  296.     mov    b,m        ;BC = .bios constat trap in RSX
  297.     inx    h
  298.     push    h        ;save for CONIN setup
  299.     ;
  300.     ;patch RSX constat entry into BIOS jump table 
  301.     ;save real constat address in RSX exit table
  302.     ;
  303.     lhld    wboota
  304.     lxi    d,4
  305.     dad    d        ;HL = .(jmp constat address)
  306.     shld    constjmp    ;save for RSX restore at end
  307.     mov    e,m
  308.     mov    m,c
  309.     inx    h
  310.     mov    d,m        ;DE = constat address
  311.     mov    m,b        ;BIOS constat jumps to RSX
  312.     xchg
  313.     shld    biosta        ;save real constat address
  314.     ;
  315.     ;get address of RSX bios conin entry point
  316.     ;
  317.     pop    h        ;HL = .(RSX BIOS conin trap)
  318.     mov    c,m
  319.     inx    h
  320.     mov    b,m
  321.     ;
  322.     ;patch RSX conin entry into BIOS jump table 
  323.     ;save real conin address in RSX exit table
  324.     ;
  325.     xchg
  326.     inx    h        ;past jmp instruction
  327.     inx    h        ;HL = .(conin address)
  328.     shld    coninjmp
  329.     mov    e,m
  330.     mov    m,c
  331.     inx    h
  332.     mov    d,m        ;DE = conin address
  333.     mov    m,b        ;BIOS conin jumps to RSX
  334.     xchg
  335.     shld    biosin        ;save real conin address
  336. endif
  337.     ;
  338.     ;move data area to RSX
  339.     ;
  340. rsxmov:
  341.     pop    h        ;HL = .Kill flag in RSX
  342.     inr    m        ;switch from FF to 0
  343.     lxi    h,movstart
  344.     pop    d        ;RSX data area address
  345.     lxi    b,movend-movstart
  346.     call    ldir
  347.     mvi    c,crawf
  348.     mvi    e,0fdh        ;raw console input
  349.     call    mon1        ;prime RSX by reading a char
  350.     jmp    wboot
  351.  
  352. if biosfunctions
  353. ;
  354. ;    can't do BIOS redirection
  355. ;
  356. bioserr:
  357.     lxi    d,nobios
  358.     mvi    c,pbuff
  359.     call    mon1
  360.     lxi    h,biosmode
  361.     mvi    m,norestore    ;no bios redirection 
  362.     pop    h        ;throw away bios constat trap adr
  363.     jmp    rsxmov
  364. endif
  365. ;
  366. ;    auxiliary redirection
  367. ;
  368. notimp:
  369.     lxi    d,notdone
  370. error:
  371.     mvi    c,pbuff
  372.     call    mon1    
  373. error1:    mvi    c,closef
  374.     lxi    d,fcb
  375.     call    mon1
  376.     mvi    c,delf
  377.     lxi    d,fcb
  378.     call    mon1
  379.     jmp    wboot
  380. ;
  381. ;    insufficient memory
  382. ;
  383. nomem:    lxi    d,memerr
  384.     jmp    error
  385.     
  386. ;
  387. ;    get/set user number
  388. ;
  389. getusr:    mvi    a,0ffh        ;get current user number
  390. setusr:    mov    e,a        ;set current user number (in A)
  391.     mvi    c,userf
  392.     jmp    mon1
  393. ;
  394. ;    get system control block address 
  395. ;    (BDOS function #49)
  396. ;
  397. ;    exit:    hl = system control block address
  398. ;
  399. getscbadr:
  400.     mvi    c,scbf
  401.     lxi    d,data49
  402.     jmp    mon1
  403. ;
  404. data49:    db    scba,0        ;data structure for getscbadd
  405. ;
  406. ;    copy memory bytes (emulates z80 ldir instruction)
  407. ;
  408. ldir:    mov    a,m        ;get byte
  409.     stax    d        ;store it at destination
  410.     inx    h        ;advance pointers
  411.     inx    d
  412.     dcx    b        ;decrement byte count
  413.     mov    a,c        ;loop if non-zero
  414.     ora    b
  415.     jnz    ldir
  416.     ret
  417. ;
  418. ;******************************************************************
  419. ;        DATA AREA
  420. ;******************************************************************
  421.  
  422.     ;
  423. journkill:    db    jkillf
  424. rsxinit:    db    initf
  425. nobios:        db    'WARNING: Cannot redirect from BIOS',cr,lf,'$'
  426. notdone:
  427.     db 'ERROR: Auxiliary device redirection not implemented',cr,lf,'$'
  428. memerr:
  429.     db 'ERROR: Insufficient Memory',cr,lf,'$'
  430.     ;    
  431. ;******************************************************************
  432. ;    Following variables are initialized by GET.COM
  433. ;    and moved to the GET RSX - Their order must not be changed
  434. ;******************************************************************
  435.     ;
  436.     ;
  437.     ;
  438. movstart:
  439. inittable:            ;addresses used by GET.COM for 
  440. scbadr:    dw    0        ;address of System Control Block
  441.     ;
  442.     if biosfunctions    ;GET.RSX initialization
  443.     ;
  444. biosta:    dw    0        ;set to real BIOS routine
  445. biosin:    dw    0        ;set to real BIOS routine
  446.     ;
  447.                 ;restore only if changed when removed.
  448. biosmode:
  449.     db    0        ;if non-zero change LXI @jmpadr to JMP
  450.                 ;when removed.
  451. restorebios:
  452.     ;hl = real constat routine
  453.     ;de = real conin routine
  454.     db    shldi
  455. constjmp:
  456.     dw    0        ;address of const jmp initialized by COM
  457.     xchg
  458.     db    shldi
  459. coninjmp:
  460.     dw    0        ;address of conin jmp initialized by COM
  461.     ret
  462.     endif
  463.     ;
  464. realbdos:
  465.     jmp    0        ;address filled in by COM
  466.     ;
  467. echo:    db    1
  468. cooked:    db    0
  469.     ;
  470. program:
  471.     db    0        ;true if only program input 
  472. subusr:    db    0        ;user number for redirection file
  473. subfcb:    db    1        ;a:
  474.     db    'SYSIN   '
  475.     db    'SUB'
  476.     db    0,0
  477. submod:    db    0
  478. subrc:    db    0
  479.     ds    16        ;map
  480. subcr:    db    0
  481.     ;
  482. movend:
  483. ;*******************************************************************
  484.     end
  485. EOF
  486.  
  487.