home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / jsage / znode3 / uploads / zf11src.lbr / ZFSUBS2.ZZ0 / ZFSUBS2.Z80
Encoding:
Text File  |  1992-11-21  |  10.6 KB  |  477 lines

  1. .printx    Reading ZFSUBS2.Z80
  2. ;===========================================================================
  3. ;
  4. ; ZFSUBS2.Z80 - General Purpose Subroutines
  5. ;
  6. ;===========================================================================
  7.  
  8. ; SETUP - Initialization: Set up ZFILER buffers, pointers, CRT information.
  9.  
  10. setup:
  11.     call    codend        ; Start of free space
  12.     ld    de,100h        ; 256 bytes/unit
  13.     add    hl,de        ; Allow room for stack.
  14.     ld    (crctbl),hl    ; Table for crc list.
  15.     add    hl,de
  16.     ld    (cmdbuf),hl    ; Command line buffer
  17.     add    hl,de
  18.     ld    (dum$fcb),hl    ; Dummy fcb
  19.     inc    h
  20.     ld    l,0        ; Next page
  21.     ld    (bufentry),hl    ; Free space to end of tpa
  22.  
  23. ; Set CRT Data
  24.  
  25.     call    getcrt        ; Get cpsel info for current crt
  26.     ld    a,(hl)
  27.     sub    [cpadr mod 256]-1
  28.     ld    (cpecnt),a    ; Set # chars for command line simulated eol
  29.     ld    a,(hl)
  30.     sub    [eradr mod 256]-1
  31.     ld    (erecnt),a    ; Set # chars for error line simulated eol
  32.  
  33. ; Set Printer Data
  34.  
  35.     call    getprt        ; Printer data
  36.     inc    hl
  37.     ld    a,(hl)        ; Total lines per physical page
  38.     ld    (lppp),a
  39.     inc    hl
  40.     ld    a,(hl)        ; Lines of text per page
  41.     ld    (ltpp),a
  42.     inc    hl
  43.     ld    a,(hl)
  44.     ld    (lffeed),a    ; Can form feed?
  45.  
  46. ; Get Cursor Key definitions from the Environment
  47.  
  48.     ld    hl,(envptr)    ; Pt to zcpr3 env desc
  49.     ld    de,80h+10h    ; Pt to cursor commands
  50.     add    hl,de
  51.     ld    de,ctabk    ; Point to key binding table
  52.     ld    b,4        ; 4 commands
  53.  
  54. curinit:
  55.     ld    a,(hl)        ; Get command
  56.     ld    (de),a        ; Put it
  57.     inc    hl        ; Pt to next
  58.     inc    de        ; Go to next byte
  59.     inc    de        ; Skip wheel control byte
  60.     djnz    curinit
  61.  
  62. ; Begin Further Inits
  63.  
  64.     xor    a
  65.     ld    (helpdisp),a    ; No help display yet
  66.  
  67.     ld    hl,(bufentry)    ; Base address
  68.     ld    (ring),hl    ; Beginning of ring
  69.  
  70.     ld    hl,curhome    ; Home address for cursor
  71.     ld    (curat),hl
  72.  
  73.     call    getmdisk    ; Get max disk number (1-n)
  74.     ld    (maxdr),a    ; Save it.
  75.  
  76.     ld    a,(bdosptr+2)    ; Get bdos page
  77.      if    warmboot
  78.     dec    a        ; Next page below bdos
  79.      else
  80.     sub    10        ; 10 pages below bdos is the limit.
  81.      endif            ; Warmboot
  82.     ld    (maxpage),a    ; Set page limit.
  83.     ret
  84.  
  85. ;---------------------------------------------------------------------------
  86.  
  87. ; PUBLIC - Test the ZRDOS public status of the requested DU:
  88. ;   Return NZ if public, Z if not.
  89.  
  90. public:
  91.     ld    bc,(du$req)
  92.     ld    hl,(pubyts)    ; Get ZRDOS public bytes
  93.     ld    a,h
  94.     or    l
  95.     jr    z,nopub        ; Nothing is public
  96.     ld    a,b        ; Get drive number
  97.     cp    8
  98.     jr    nc,nopub    ; Out of range
  99.     ld    a,c        ; Get user number
  100.     or    a
  101.     jr    z,nopub        ; User 0 cannot be public
  102.     cp    9
  103.     jr    nc,nopub    ; Out of range
  104.     ld    d,c        ; User byte to d (minimum 1)
  105.     xor    a        ; Clear A
  106.     scf            ; Set the carry
  107. pubul:
  108.     rla            ; Shift user bit into A
  109.     dec    d
  110.     jr    nz,pubul    ; Shift until D is zero
  111.     and    h        ; And it with A
  112.     jr    z,nopub        ; Not public
  113.     ld    d,b        ; Drive byte to D
  114.     xor    a        ; Get a zero
  115.     scf            ; Set carry
  116. pubdl:
  117.     rla
  118.     dec    d
  119.     jp    p,pubdl        ; Loop till D is negative
  120.     and    l        ; And it with A
  121.     jr    z,nopub        ; Not public
  122.     xor    a
  123.     dec    a
  124.     ret
  125. nopub:
  126.     xor    a
  127.     ret
  128.  
  129. ;---------------------------------------------------------------------------
  130.  
  131. ; STACKSET - Set Stack Pointer
  132.  
  133. stackset:
  134.     pop    de        ; Get return address
  135.     ld    hl,(crctbl)    ; Top of stack
  136.     ld    sp,hl        ; Start local stack
  137.     push    de        ; Return address on new stack
  138.     ret
  139.  
  140. ;---------------------------------------------------------------------------
  141.  
  142. ; STACKDU and UNSTACKDU
  143.  
  144. ; Subroutines for saving and restoring du$orig and du$req to and from the shell
  145. ; stack entry (currently using bytes 0E-11).  STKREQDU saves only the requested
  146. ; DU onto the stack (it is the first word of the pair).
  147.  
  148. duoff    equ    0eh
  149.  
  150. stkreqdu:
  151.     call    stksub        ; Get pointer
  152.     ld    bc,(du$req)    ; Get working DU
  153.     jr    stackdu1    ; Save it on shell stack
  154.  
  155. stackdu:
  156.     call    stksub        ; Get pointer
  157.     ld    bc,(du$orig)    ; Home DU when program invoked by user into BC
  158.     ld    de,(du$req)    ; Requested DU area to work in into DE
  159.     ld    (hl),e        ; Save DUs on stack
  160.     inc    hl
  161.     ld    (hl),d
  162.     inc    hl
  163. stackdu1:
  164.     ld    (hl),c
  165.     inc    hl
  166.     ld    (hl),b
  167.     ret
  168.  
  169. unstackdu:
  170.     call    stksub        ; Get pointer
  171.     ld    c,(hl)        ; Load first word into BC
  172.     inc    hl
  173.     ld    b,(hl)
  174.     inc    hl
  175.     ld    e,(hl)        ; Load second word into DE
  176.     inc    hl
  177.     ld    d,(hl)
  178.     ld    (du$orig),de    ; Save second word as original DU
  179.     ld    (du$req),bc    ; Save first word as requested DU
  180.     jp    logud        ; ..and log into it
  181.  
  182. stksub:                ; Get pointer to DUs in shell stack
  183.     call    getsh2        ; Get pointer to first shell entry
  184.     ld    bc,duoff
  185.     add    hl,bc
  186.     ret
  187.  
  188. ;---------------------------------------------------------------------------
  189.  
  190. ; SETDEFDU - Set Default DU
  191.  
  192. ; Logs into the directory stored in du$orig and sets it into the default
  193. ; directory byte in the operating system at os$base+4.
  194.  
  195. setdefdu:
  196.     push    hl
  197.     call    getmsg        ; Get address of message buffer
  198.     ld    bc,2eh        ; Offset to current user/drive word
  199.     add    hl,bc
  200.     ld    bc,(du$orig)    ; Get original directory
  201.     call    logud        ; Log it in
  202.     ld    (hl),c        ; Set new user number in message buffer
  203.     inc    hl
  204.     ld    (hl),b        ; Set new drive
  205.     pop    hl
  206.     ld    a,c        ; Get user number
  207.     and    0fh        ; Mask low 16 user numbers only
  208.     rlca            ; Rotate into high nibble
  209.     rlca
  210.     rlca
  211.     rlca
  212.     or    b        ; Insert drive number
  213.     ld    (os$base+4),a    ; Set up default DU
  214.     ret
  215.  
  216. ;---------------------------------------------------------------------------
  217.  
  218. ; RESET - Disk system reset (log in requested DU)
  219. ;
  220. ; Do not reset if ZS/ZDDOS or CP/M Plus
  221.  
  222. reset:
  223.     push    bc        ; Save regs
  224.     push    de
  225.     push    hl
  226.     call    cpm3        ; Not needed if
  227.     jr    nc,reset1    ; ..CP/M Plus
  228.     ld    c,resetdk    ; Reset system
  229.     ld    a,(dosid)
  230.     or    a        ; ZS/ZDDOS?
  231.     call    z,bdosptr    ; No, do reset
  232. reset1:
  233.     ld    bc,(du$req)    ; Get current du
  234.     call    logud        ; And set it up.
  235.     pop    hl        ; Restore regs
  236.     pop    de
  237.     pop    bc
  238.     ret
  239.  
  240. ;---------------------------------------------------------------------------
  241.  
  242. ; GETDPB - Determine Disk Parameter values for current drive.
  243.  
  244. getdpb:
  245.     ld    c,inqdisk    ; Determine current drive
  246.     call    bdosptr        ; Returns 0 as a:, 1 as b:, etc.
  247.     inc    a        ; Make 1 --> a:, 2 --> b:, etc.
  248.     ld    (fcb),a
  249.     ld    c,getparm    ; Current disk parameter block
  250.     call    bdosptr
  251.     inc    hl        ; Bump to..
  252.     inc    hl
  253.     ld    a,(hl)        ; Block shift factor.
  254.     ld    (bshiftf),a    ; 'bsh'
  255.     inc    hl        ; Bump to..
  256.     ld    a,(hl)        ; Block mask.
  257.     ld    (b$mask),a    ; 'blm'
  258.     inc    hl        ; Bump to..
  259.     inc    hl        ; Get..
  260.     ld    e,(hl)        ; Maximum block number..
  261.     inc    hl        ; Double..
  262.     ld    d,(hl)        ; Byte.
  263.     ex    de,hl
  264.     ld    (b$max),hl    ; 'dsm'
  265.     ret
  266.  
  267. ;---------------------------------------------------------------------------
  268.  
  269. ; FRESTOR - Determine free storage remaining on selected drive
  270. ;        - GETDPB ***MUST*** be called first to set current DPB values.
  271.  
  272. frestor:
  273.     ld    c,inqalc    ; Address of allocation vector
  274.     call    bdosptr
  275.     ex    de,hl        ; Get its length
  276.     ld    hl,(b$max)
  277.     inc    hl
  278.  
  279.     ld    bc,0        ; Initialize block count to zero
  280. gspbyt:
  281.     push    de        ; Save allocation address
  282.     ld    a,(de)
  283.     ld    e,8        ; Set to process 8 bits (blocks)
  284.  
  285. gsplup:
  286.     rla            ; Test bit
  287.     jr    c,not$fre
  288.     inc    bc
  289. not$fre:
  290.     ld    d,a        ; Save bits
  291.     dec    hl
  292.     ld    a,l
  293.     or    h
  294.     jr    z,end$alc    ; Quit if out of blocks
  295.     ld    a,d        ; Restore bits
  296.     dec    e        ; Count down 8 bits
  297.     jr    nz,gsplup    ; Branch to do another bit
  298.     pop    de        ; Bump to next count..
  299.     inc    de        ; Of allocation vector.
  300.     jr    gspbyt        ; Process it
  301.  
  302. end$alc:
  303.     pop    de        ; Clear alloc vector pointer from stack
  304.     ld    l,c        ; Copy # blocks to hl
  305.     ld    h,b
  306.     ld    a,(bshiftf)    ; Get block shift factor
  307.     sub    3        ; Convert from sectors to thousands (k)
  308.     jr    z,prt$fre    ; Skip shifts if 1k blocks
  309. frek$lp:
  310.     add    hl,hl        ; Multiply blocks by k-bytes per block
  311.     dec    a        ; Multiply by 2, 4, 8, or 16.
  312.     jr    nz,frek$lp
  313. prt$fre:
  314.     ld    (disksp),hl    ; Save disk space
  315.     ret
  316.  
  317. ;---------------------------------------------------------------------------
  318.  
  319. ; General Utility Subroutines -- filling, moving, comparing, shifting
  320.  
  321. ; MOVE - move subroutine -- move B-reg # of bytes from HL to DE
  322.  
  323. movea:
  324.     ld    a,(hl)        ; Get hl referenced source byte
  325.     and    7fh        ; Strip attributes
  326.     ld    (de),a        ; Put to de referenced destination
  327.     inc    hl        ; Fix pointers for next search
  328.     inc    de
  329.     djnz    movea
  330.     ret
  331.  
  332.  
  333. ; SMOVEB - Move subroutine (DE, HL not altered), stripping attribute bits
  334.  
  335. smoveb:
  336.     push    hl        ; Save hl, de
  337.     push    de
  338.     call    movea
  339.     pop    de        ; Restore de, hl
  340.     pop    hl
  341.     ret
  342.  
  343.  
  344. ; MOVEC - As movea but without stripping attributes
  345.  
  346. movec:
  347.     ld    a,(hl)
  348.     ld    (de),a
  349.     inc    hl
  350.     inc    de
  351.     djnz    movec
  352.     ret
  353.  
  354.  
  355. ; CMPDEHL - Compare DE to HL (DE - HL) and set flags accordingly
  356.  
  357. cmpdehl:
  358.     ld    a,d        ; See if high bytes set flags
  359.     cp    h
  360.     ret    nz        ; Return if not equal, cy if h > d
  361.     ld    a,e
  362.     cp    l        ; Low bytes set flags instead
  363.     ret            ; Cy if l > e
  364.  
  365.  
  366. ; SHIFTLP - Shift HL b-reg bits (-1) to right (divider routine)
  367.  
  368. shiftlp:
  369.     dec    b
  370.     ret    z
  371.     ld    a,h
  372.     or    a
  373.     rra
  374.     ld    h,a
  375.     ld    a,l
  376.     rra
  377.     ld    l,a
  378.     jr    shiftlp
  379.  
  380.  
  381. ; Provide configurable delay for reading messages.
  382.  
  383. errpause:
  384.     call    getspeed    ; Get processor speed
  385.     ld    b,a        ; ..into B
  386.     ld    hl,(npause)    ; Get pause time in 0.1 secs
  387.     ld    h,0        ; Use only the low byte
  388.     ld    a,l        ; Make sure it's not 0
  389.     or    a
  390.     ret    z        ; If so, no delay
  391.     jp    pause        ; SYSLIB delay routine
  392.  
  393.  
  394. ;---------------------------------------------------------------------------
  395.  
  396. ; Prompting Routines and Keyboard Input
  397.  
  398. ; VFYREQ - Ask user whether to verify
  399.  
  400.      if    usedseg
  401.     dseg
  402.      endif
  403.  
  404. tvflag:    ds    1        ; Temporary verify default flag
  405.  
  406.      if    usedseg
  407.     cseg
  408.      endif
  409.  
  410. vfyreq:
  411.     ld    hl,msg107    ; "Verify (Y/N)? "
  412.     call    cprmptyn    ; Print the following at the command prompt
  413.     call    keyin        ; Get user's response
  414.     cp    ctrlc
  415.     jp    z,loop        ; Restart if Control C
  416.     call    testyn        ; Test for YES/NO answer
  417.     ld    a,(vflag)    ; Use default verify flag
  418.     jr    c,vfyset    ; ..if neither YES nor NO
  419.     xor    a        ; Clear verify flag
  420.     jr    nz,vfyset    ; ..if NO
  421.     dec    a        ; Set verify flag
  422. vfyset:
  423.     ld    (tvflag),a
  424.     ret
  425.  
  426.  
  427. ; SAK - Prompt for Continuation
  428.  
  429. sak:
  430.     ld    hl,msg108    ; " Strike Any Key --"
  431.     call    pstri
  432.  
  433.  
  434. ; DKEYIN - direct console input w/o echo (waits for input)
  435.  
  436. dkeyin:
  437.     call    cin        ; Get char from bios
  438.     jp    caps        ; Capitalize
  439.  
  440.  
  441. ; KEYIN - Conin routine (waits for response)
  442.  
  443. keyin:
  444.     call    dkeyin        ; Get input and capitalize.
  445.     jp    cout        ; Echo
  446.  
  447. ;---------------------------------------------------------------------------
  448.  
  449. ; RESDMA - Reset DMA Address
  450.  
  451. resdma:
  452.     ld    de,tbuff    ; Pt to temporary buffer
  453.     ld    c,setdma
  454.     jp    bdosptr
  455.  
  456. ;---------------------------------------------------------------------------
  457.  
  458. ; CPYBITS - Copy old file status bits ($r/o or $sys) to new filename
  459. ; Enter with DE pointing to old fcb and HL pointing to new one.
  460.  
  461. cpybits:
  462.     ld    b,11        ; # of bytes with tag bits
  463. cbits1:
  464.     ld    a,(de)        ; Fetch bit of old name character
  465.     and    128        ; Strip upper bit and..
  466.     ld    c,a        ; Save in b-reg.
  467.     ld    a,7fh        ; Mask for character only
  468.     and    (hl)        ; Put masked character into a-reg
  469.     or    c        ; Add old bit
  470.     ld    (hl),a        ; Copy new byte back
  471.     inc    hl        ; Bump copy pointers
  472.     inc    de
  473.     djnz    cbits1
  474.     ret
  475.  
  476. ; End of ZFSUBS2.Z80
  477.