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 / CPM / ZCPR33 / S-Z / VFILER43.LBR / VFSUBS2.LZB / VFSUBS2.LIB
Text File  |  2000-06-30  |  9KB  |  408 lines

  1. ;===========================================================================
  2. ;
  3. ; VFSUBS2.Z80 - General Purpose Subroutines
  4. ;
  5. ;===========================================================================
  6.  
  7.  
  8. ; SETUP - Initialization: Set up VFILER 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.     inc    hl
  33.     ld    b,(hl)
  34.     inc    hl
  35.     ld    a,(hl)
  36.     ld    (ctpp),a    ; Text
  37.  
  38. ; Set Printer Data
  39.  
  40.     call    getprt        ; Printer data
  41.     inc    hl
  42.     ld    a,(hl)        ; Total lines per physical page
  43.     ld    (lppp),a
  44.     inc    hl
  45.     ld    a,(hl)        ; Lines of text per page
  46.     ld    (ltpp),a
  47.     inc    hl
  48.     ld    a,(hl)
  49.     ld    (lffeed),a    ; Can form feed?
  50.  
  51. ; Get Cursor Key definitions from the Environment
  52.  
  53.     ld    hl,(envptr)    ; Pt to zcpr3 env desc
  54.     ld    de,80h+10h    ; Pt to cursor commands
  55.     add    hl,de
  56.     ld    de,ctable    ; Pt to area
  57.     ld    b,4        ; 4 commands
  58.  
  59. curinit:
  60.     ld    a,(hl)        ; Get command
  61.     ld    (de),a        ; Put it
  62.     inc    hl        ; Pt to next
  63.     inc    de
  64.     inc    de
  65.     inc    de
  66.     inc    de
  67.     djnz    curinit
  68.  
  69. ; Begin Further Inits
  70.  
  71.     xor    a
  72.     ld    (helpdisp),a    ; No help display yet
  73.  
  74.     ld    hl,(bufentry)    ; Base address
  75.     ld    (ring),hl    ; Beginning of ring
  76.  
  77.     ld    hl,curhome    ; Home address for cursor
  78.     ld    (curat),hl
  79.  
  80.     call    getmdisk    ; Get max disk number (1-n)
  81.     ld    (maxdr),a    ; Save it.
  82.  
  83.     ld    a,(bdos+2)    ; Get bdos page
  84.      if    warmboot
  85.     dec    a        ; Next page below bdos
  86.      else
  87.     sub    10        ; 10 pages below bdos is the limit.
  88.      endif            ; Warmboot
  89.     ld    (maxpage),a    ; Set page limit.
  90.     ret
  91.  
  92. ;---------------------------------------------------------------------------
  93.  
  94. ; PUBLIC - Test the ZRDOS public status of the requested DU:
  95. ;   Return NZ if public, Z if not.
  96.  
  97. public:
  98.     ld    bc,(du$req)
  99.     ld    hl,(pubyts)    ; Get ZRDOS public bytes
  100.     ld    a,h
  101.     or    l
  102.     jr    z,nopub        ; Nothing is public
  103.     ld    a,b        ; Get drive number
  104.     cp    8
  105.     jr    nc,nopub    ; Out of range
  106.     ld    a,c        ; Get user number
  107.     or    a
  108.     jr    z,nopub        ; User 0 cannot be public
  109.     cp    9
  110.     jr    nc,nopub    ; Out of range
  111.     ld    d,c        ; User byte to d (minimum 1)
  112.     xor    a        ; Clear A
  113.     scf            ; Set the carry
  114. pubul:
  115.     rla            ; Shift user bit into A
  116.     dec    d
  117.     jr    nz,pubul    ; Shift until D is zero
  118.     and    h        ; And it with A
  119.     jr    z,nopub        ; Not public
  120.     ld    d,b        ; Drive byte to D
  121.     xor    a        ; Get a zero
  122.     scf            ; Set carry
  123. pubdl:
  124.     rla
  125.     dec    d
  126.     jp    p,pubdl        ; Loop till D is negative
  127.     and    l        ; And it with A
  128.     jr    z,nopub        ; Not public
  129.     xor    a
  130.     dec    a
  131.     ret
  132. nopub:
  133.     xor    a
  134.     ret
  135.  
  136. ;---------------------------------------------------------------------------
  137.  
  138. ; STACKSET - Set Stack Pointer
  139.  
  140. stackset:
  141.     pop    de        ; Get return address
  142.     ld    hl,(crctbl)    ; Top of stack
  143.     ld    sp,hl        ; Start local stack
  144.     push    de        ; Return address on new stack
  145.     ret
  146.  
  147. ;---------------------------------------------------------------------------
  148.  
  149. ; IDU - Set initial disk/user
  150.  
  151. idu:
  152.     call    retud        ; Get original du in bc.
  153.     ld    (du$orig),bc    ; Save for exit
  154.  
  155.     ld    de,fcb        ; Log into du specification
  156.     call    z3log        ; Perform login
  157.     call    retud        ; Get current du in bc
  158.     ld    (du$req),bc    ; Save as requested du
  159.     ret
  160.  
  161. ;---------------------------------------------------------------------------
  162.  
  163. ; RESET - Disk system reset (log in requested DU)
  164.  
  165. reset:
  166.     push    bc        ; Save regs
  167.     push    de
  168.     push    hl
  169.     ld    c,resetdk    ; Reset system
  170.     call    bdos
  171.     ld    bc,(du$req)    ; Get current du
  172.     call    logud        ; And set it up.
  173.     pop    hl        ; Restore regs
  174.     pop    de
  175.     pop    bc
  176.     ret
  177.  
  178. ;---------------------------------------------------------------------------
  179.  
  180. ; GETDPB - Determine Disk Parameter values for current drive.
  181.  
  182. getdpb:
  183.     ld    c,inqdisk    ; Determine current drive
  184.     call    bdos        ; Returns 0 as a:, 1 as b:, etc.
  185.     inc    a        ; Make 1 --> a:, 2 --> b:, etc.
  186.     ld    (fcb),a
  187.     ld    c,getparm    ; Current disk parameter block
  188.     call    bdos
  189.     inc    hl        ; Bump to..
  190.     inc    hl
  191.     ld    a,(hl)        ; Block shift factor.
  192.     ld    (bshiftf),a    ; 'bsh'
  193.     inc    hl        ; Bump to..
  194.     ld    a,(hl)        ; Block mask.
  195.     ld    (b$mask),a    ; 'blm'
  196.     inc    hl        ; Bump to..
  197.     inc    hl        ; Get..
  198.     ld    e,(hl)        ; Maximum block number..
  199.     inc    hl        ; Double..
  200.     ld    d,(hl)        ; Byte.
  201.     ex    de,hl
  202.     ld    (b$max),hl    ; 'dsm'
  203.     ret
  204.  
  205. ;---------------------------------------------------------------------------
  206.  
  207. ; FRESTOR - Determine free storage remaining on selected drive
  208. ;        - GETDPB ***MUST*** be called first to set current DPB values.
  209.  
  210. frestor:
  211.     ld    c,inqalc    ; Address of allocation vector
  212.     call    bdos
  213.     ex    de,hl        ; Get its length
  214.     ld    hl,(b$max)
  215.     inc    hl
  216.  
  217.     ld    bc,0        ; Initialize block count to zero
  218. gspbyt:
  219.     push    de        ; Save allocation address
  220.     ld    a,(de)
  221.     ld    e,8        ; Set to process 8 bits (blocks)
  222.  
  223. gsplup:
  224.     rla            ; Test bit
  225.     jr    c,not$fre
  226.     inc    bc
  227. not$fre:
  228.     ld    d,a        ; Save bits
  229.     dec    hl
  230.     ld    a,l
  231.     or    h
  232.     jr    z,end$alc    ; Quit if out of blocks
  233.     ld    a,d        ; Restore bits
  234.     dec    e        ; Count down 8 bits
  235.     jr    nz,gsplup    ; Branch to do another bit
  236.     pop    de        ; Bump to next count..
  237.     inc    de        ; Of allocation vector.
  238.     jr    gspbyt        ; Process it
  239.  
  240. end$alc:
  241.     pop    de        ; Clear alloc vector pointer from stack
  242.     ld    l,c        ; Copy # blocks to hl
  243.     ld    h,b
  244.     ld    a,(bshiftf)    ; Get block shift factor
  245.     sub    3        ; Convert from sectors to thousands (k)
  246.     jr    z,prt$fre    ; Skip shifts if 1k blocks
  247. frek$lp:
  248.     add    hl,hl        ; Multiply blocks by k-bytes per block
  249.     dec    a        ; Multiply by 2, 4, 8, or 16.
  250.     jr    nz,frek$lp
  251. prt$fre:
  252.     ld    (disksp),hl    ; Save disk space
  253.     ret
  254.  
  255. ;---------------------------------------------------------------------------
  256.  
  257. ; General Utility Subroutines -- filling, moving, comparing, shifting
  258.  
  259.  
  260. ; FILL - Fill buffer with 'spaces' with count in b-reg
  261.  
  262. fill:
  263.     ld    (hl),' '    ; Put in space character
  264.     inc    hl
  265.     djnz    fill        ; No, branch.
  266.     ret
  267.  
  268.  
  269. ; MOVE - move subroutine -- move B-reg # of bytes from HL to DE
  270.  
  271. movea:
  272.     ld    a,(hl)        ; Get hl referenced source byte
  273.     and    7fh        ; Strip attributes
  274.     ld    (de),a        ; Put to de referenced destination
  275.     inc    hl        ; Fix pointers for next search
  276.     inc    de
  277.     djnz    movea
  278.     ret
  279.  
  280.  
  281. ; MOVEB - Move subroutine (DE, HL not altered)
  282.  
  283. moveb:
  284.     push    hl        ; Save hl, de
  285.     push    de
  286.     call    movea
  287.     pop    de        ; Restore de, hl
  288.     pop    hl
  289.     ret
  290.  
  291.  
  292. ; MOVEC - As movea but without stripping attributes
  293.  
  294. movec:
  295.     ld    a,(hl)
  296.     ld    (de),a
  297.     inc    hl
  298.     inc    de
  299.     djnz    movec
  300.     ret
  301.  
  302.  
  303. ; CMPDEHL - Compare DE to HL (DE - HL) and set flags accordingly
  304.  
  305. cmpdehl:
  306.     ld    a,d        ; See if high bytes set flags
  307.     cp    h
  308.     ret    nz        ; Return if not equal, cy if h > d
  309.     ld    a,e
  310.     cp    l        ; Low bytes set flags instead
  311.     ret            ; Cy if l > e
  312.  
  313.  
  314. ; SHIFTLP - Shift HL b-reg bits (-1) to right (divider routine)
  315.  
  316. shiftlp:
  317.     dec    b
  318.     ret    z
  319.     ld    a,h
  320.     or    a
  321.     rra
  322.     ld    h,a
  323.     ld    a,l
  324.     rra
  325.     ld    l,a
  326.     jr    shiftlp
  327.  
  328. ;---------------------------------------------------------------------------
  329.  
  330. ; Prompting Routines and Keyboard Input
  331.  
  332. ; VFYREQ - Ask user whether to verify
  333.  
  334. vfyreq:
  335.     call    cprmpt        ; Print the following at the command prompt
  336.     db    'Verify (Y/N)? ',0
  337.     call    keyin        ; Get user's response
  338.     cp    ctrlc
  339.     jp    z,loop        ; Restart if Control C
  340.     ld    b,255        ; Set verify flag
  341.     cp    'Y'        ; ..if 'Y'
  342.     jr    z,vfyset
  343.     inc    b        ; Clear verify flag
  344.     cp    'N'        ; ..if 'N'
  345.     jr    z,vfyset
  346.     ld    a,(vflag)    ; Use default verify flag
  347.     ld    b,a        ; ..if neither 'Y' nor 'N'
  348. vfyset:
  349.     ld    a,b
  350.     ld    (vflag),a
  351.     ret
  352.  
  353.  
  354. ; BOTTOM - Position at Bottom of Screen and Prompt for Continuation
  355.  
  356. bottom:
  357.     ld    hl,botadr    ; Position cursor
  358.     call    gotoxy
  359.  
  360. ; SAK - Prompt for Continuation
  361.  
  362. sak:
  363.     call    vprint
  364.     db    dim,' Strike Any Key --',bright,' ',0
  365.  
  366.  
  367. ; DKEYIN - direct console input w/o echo (waits for input)
  368.  
  369. dkeyin:
  370.     call    cin        ; Get char from bios
  371.     jp    caps        ; Capitalize
  372.  
  373.  
  374. ; KEYIN - Conin routine (waits for response)
  375.  
  376. keyin:
  377.     call    dkeyin        ; Get input and capitalize.
  378.     jp    cout        ; Echo
  379.  
  380. ;---------------------------------------------------------------------------
  381.  
  382. ; RESDMA - Reset DMA Address
  383.  
  384. resdma:
  385.     ld    de,tbuff    ; Pt to temporary buffer
  386.     ld    c,setdma
  387.     jp    bdos
  388.  
  389. ;---------------------------------------------------------------------------
  390.  
  391. ; CPYBITS - Copy old file status bits ($r/o or $sys) to new filename
  392. ; Enter with DE pointing to old fcb and HL pointing to new one.
  393.  
  394. cpybits:
  395.     ld    b,11        ; # of bytes with tag bits
  396. cbits1:
  397.     ld    a,(de)        ; Fetch bit of old name character
  398.     and    128        ; Strip upper bit and..
  399.     ld    c,a        ; Save in b-reg.
  400.     ld    a,7fh        ; Mask for character only
  401.     and    (hl)        ; Put masked character into a-reg
  402.     or    c        ; Add old bit
  403.     ld    (hl),a        ; Copy new byte back
  404.     inc    hl        ; Bump copy pointers
  405.     inc    de
  406.     djnz    cbits1
  407.     ret
  408.