home *** CD-ROM | disk | FTP | other *** search
- ; SPACE routine for Z-systems RCP. 3-24-86 by Carson Wilson
- ; This routine is written as a complete program for demonstration and
- ; testing purposes.
- ;
- ; It is written in in the Z80 instruction set, and is compatible with
- ; public domain ZASM.COM or Z80MR.COM.
- ;
- ; To insert the SPACE procedure into your RCP, follow instructions marked with
- ; '*' below.
- ;
- ; * omit the next 3 lines for RCP: ---------
- bdos equ 5
- fcb1 equ 5ch
- org 100h
- ;
- ctab1:
- ; * remove ';'s and insert the following 2 lines at the beginning of
- ; "ctab1" in RCP:
- ; db 'S ' ; get disk space on current drive
- ; dw space ; C. Wilson
- ;
- ; * insert the following 153 lines at the beginning of the list of routines
- ; in your RCP. -----------------
- ;
- ;SPACE shows space remaining on logged drive
- ; * remove semicolons from next 2 lines:
- ;crSPACE: ; used to call SPACE after other subroutines
- ; call crlf ; (e.g., CP, ERA)
- SPACE:
- getdsk: call print
- db 'Space on',(' '+80h)
-
- ld a,(fcb1)
- cp 0 ; drive explicitly selected?
- jr nz,skip ; yes
-
- ld c,25
- call bdos ; get current disk
- jr skip2
-
- skip: sub 1 ; subtract 1 from A
- skip2: ld e,a
-
- add a,65
- call conout
-
- ld c,14 ; select disk
- call bdos ; not needed if no drive selected, but smallest
- ; possible code size this way.
- call print
- db ':',(' '+80h)
- ;
- ;* THIS ROUTINE EXTRACTS DISK PARAMETER INFORMATION FROM THE DPB AND
- ;* STORES THIS INFORMATION IN:
- ;* BLKSHF <-- BLOCK SHIFT FACTOR (1 BYTE)
- ;* BLKMAX <-- MAX NUMBER OF BLOCKS ON DISK (2 BYTES)
- ;*
- DPARAMS:
- ;*
- ;* VERSION 2.x OR MP/M
- ;*
- LD C,31 ; 2.x OR MP/M...REQUEST DPB
- CALL BDOS
- INC HL
- INC HL
- LD A,(HL) ; GET BLOCK SHIFT
- LD (BLKSHF),A ; BLOCK SHIFT FACTOR
- INC HL ; GET BLOCK MASK
- INC HL
- INC HL
- LD E,(HL) ; GET MAX BLOCK NUMBER
- INC HL
- LD D,(HL)
- EX DE,HL
- INC HL ; ADD 1 FOR MAX NUMBER OF BLOCKS
- LD (BLKMAX),HL ; MAXIMUM NUMBER OF BLOCKS
- ;*
- ;* PARAMETERS EXTRACTED
- ;* COMPUTE AMOUNT OF FREE SPACE LEFT ON DISK
- ;* THE DPARAMS ROUTINE MUST BE CALLED BEFORE THIS ROUTINE IS USED
- ;*
- DFREE:
- LD C,27 ; GET ADDRESS OF ALLOCATION VECTOR
- CALL BDOS
- EX DE,HL
- LD HL,(BLKMAX) ; GET LENGTH OF ALLOCATION VECTOR
- LD BC,0 ; INIT BLOCK COUNT TO 0
- ;*
- ;* BC IS ACCUMULATOR FOR SPACE
- ;*
- FREE1:
- PUSH DE ; SAVE ALLOC ADDRESS
- LD A,(DE) ; GET BIT PATTERN OF ALLOCATION BYTE
- LD E,8 ; SET TO PROCESS 8 BLOCKS
- FREE2:
- RLA ; ROTATE ALLOCATED BLOCK BIT INTO CARRY FLAG
- jr C,FREE3 ; IF SET (BIT=1), BLOCK IS ALLOCATED
- INC BC ; IF NOT SET, BLOCK IS NOT ALLOCATED, SO INCREMENT
- ; FREE BLOCK COUNT
- FREE3:
- LD D,A ; SAVE REMAINING ALLOCATION BITS IN D
- DEC HL ; COUNT DOWN NUMBER OF BLOCKS ON DISK
- LD A,L
- OR H
- jr Z,FREE4 ; DONE IF NO MORE BLOCKS LEFT
- LD A,D ; A=CURRENT ALLOCATION BIT PATTERN
- DEC E ; HAVE ALL 8 BITS BEEN EXAMINED?
- jr NZ,FREE2 ; CONTINUE IF NOT
- POP DE ; GET POINTER TO ALLOCATION VECTOR
- INC DE ; POINT TO NEXT ALLOCATION BYTE
- jr FREE1 ; CONTINUE BY PROCESSING NEXT ALLOCATION BYTE
- ;*
- ;* BC = TOTAL AMOUNT OF FREE SPACE IN TERMS OF BLOCKS
- ;*
- FREE4:
- POP DE ; CLEAR DE FROM STACK
- LD L,C ; HL=BC=NUMBER OF FREE BLOCKS
- LD H,B
- LD A,(BLKSHF) ; GET BLOCK SHIFT FACTOR
- SUB 3 ; CONVERT NUMBER OF BLOCKS TO K
- jr Z,FREE6 ; DONE IF SINGLE DENSITY (1K PER BLOCK)
-
- ;*
- ;* WE ARE AT A MORE ADVANCED DENSITY LEVEL; MULTIPLY THE NUMBER OF BLOCKS
- ;* BY THE SIZE OF A BLOCK IN K
- ;*
- FREE5:
- ADD HL,HL ; 2, 4, 8, 16, ETC K/BLK, SO BLOCK SHIFT FACTOR
- DEC A ; IS A POWER-OF-TWO MULTIPLE
- JR NZ,FREE5
- ;*
- ;* AT THIS POINT, HL=AMOUNT OF FREE SPACE ON DISK IN K
- ;*
- FREE6:
- ;
- DECOUT: ; output free space in decimal
- ld b,0
- ld de,-10000
- call subtr
- ld de,-1000
- call subtr
- ld de,-100
- call subtr
- ld de,-10
- call subtr
- ld a,l
- add a,'0' ; ASCII bias
- call conout
- ld a,'k'
- call conout
- ret ; final return from SPACE routine
- ;
- subtr: ld c,'0'-1
- subt2: inc c
- add hl,de
- jr c,subt2
- or a
- sbc hl,de
- ld a,c
- cp '1'
- jr nc,nzero
- ld a,b
- or a
- ld a,c
- ret z
- call conout
- ret
- ;
- nzero: ld b,0ffh
- call conout
- ret
- ;
- blkshf: db 0
- blkmax: dw 0
- ;
- ; * RCP IMPLANT ENDS HERE --------------------------
- ; CRLF, CONOUT, AND PRINT should already be implemented in your RCP, so
- ; omit these procedures from implant.
- ;
-
- crlf: call print
- db 0dh,(0ah+80h)
- ret
- ;
- ; Console Output Routine
- ;
- conout:
- push hl ; save regs
- push de
- push bc
- push af
- and 7fh ; mask MSB
- ld e,a ; char in E
- ld c,2 ; output
- call bdos
- pop af ; get regs
- pop bc
- pop de
- pop hl
- ret
- ;
- ; Print String (terminated in 0 or MSB Set) at Return Address
- ;
- print:
- ex (sp),hl ; get address
- call print1
- ex (sp),hl ; put address
- ret
- ;
- ; Print String (terminated in 0 or MSB Set) pted to by HL
- ;
- print1:
- ld a,(hl) ; done?
- inc hl ; pt to next
- or a ; 0 terminator
- ret z
- call conout ; print char
- ret m ; MSB terminator
- jr print1
- ;
-
- ; * omit this end statement for RCP, of course.
- end
- call conout ; print char
- ret m ; MSB terminator
- jr print1
- ;
-
- ; * omit this end statement