TITLE "Z3SHPUSH - Z3lib 4.0" ;================================================================ ; The Libraries, Version 4, (C) 1989 by Alpha Systems Corp. ;---------------------------------------------------------------- ; Author : Harold F. Bower ; Derived from Z3SHPUSH.Z80 Ver 1.1 by Richard Conn ; Date : 29 Mar 89 ; Version : 1.2 ; Module : Z3SHPUSH ; Abstract: This module contains the routine SHPUSH which tries ; to push a string onto the Shell Stack. Flags return the ; results of the operation ; Revision: ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ; Module Entry Points PUBLIC SHPUSH ; External References EXT GETSH2 .Z80 CSEG ;=============================================================== ; NAME - SHPUSH ; Entry: HL - Points to a Null-terminated string to push ; Exit : A = 0, Zero Flag Set (Z) if Push successful ; A = Flag, Zero Reset (NZ) ; 1 - No Shell Stack Available ; 2 - Shell Stack is Full ; 3 - String too long for Shell Stack Entry ; Uses : AF ; Special Requirements: None ;=============================================================== SHPUSH: PUSH HL ;save registers PUSH DE PUSH BC ; Get Shell Data for Later Use PUSH HL ; Save ptr to string CALL GETSH2 ; Get ptr to shell stack POP HL ; .Restore ptr to string LD A,1 ; ..set for No Shell Error JR Z,SHEXIT ; ...jump if error ; See if string is too long PUSH HL ; Save ptr to string CKSIZE: LD A,(HL) ; Get elt INC HL ; Pt to next OR A ; End of string? JR Z,CKS1 ; ..jump if so DEC E ; Count down JR NZ,CKSIZE ; .loop if not EOL LD A,3 ; ..set for String Too Long Error JR SHEXV ; ...jump to Error Exit ; Check to see if shell stack is full CKS1: CALL GETSH2 ; Get values for copy FCHK: LD A,(HL) ; Get next element OR A ; Last element on stack? JR Z,FCHK1 ; ..jump if stack ok ADD HL,DE ; Advance to next element DJNZ FCHK ; .loop LD A,2 ; ..Set Shell Stack Full Error JR SHEXV ; ...jump to Error exit ; Copy current shell stack up FCHK1: CALL GETSH2 ;get shell stack values ; Point to end of new top element PUSH BC MOVE0: LD A,B ; Check for done DEC A JR Z,MOVE1 ; ..jump if so ADD HL,DE ; Pt to next DEC B ; Count down JR MOVE0 MOVE1: POP BC LD C,E ; Get count of elements in C DEC HL ; Pt to first byte to copy EX DE,HL ; DE pts to source ADD HL,DE ; HL pts to destination ; Copy stack up one entry size MOVE2: LD A,B ; Check for copy done CP 1 ; One less element JR Z,MOVE4 DEC B ; Count down PUSH BC ; B=number of elements left , C=size of each MOVE3: LD A,(DE) ; Get LD (HL),A ; ..put DEC HL ; Back up DEC DE DEC C ; Count down JR NZ,MOVE3 POP BC ; Get values JR MOVE2 MOVE4: CALL GETSH2 ; Get ptr to shell stack POP DE ; Get ptr to string ; Copy new shell entry from DE to HL COPY: LD A,(DE) ; Get byte LD (HL),A ; .put byte INC HL ; Pt to next INC DE OR A ; Done? JR NZ,COPY ; ..loop if not, else fall thru w/0 in A PUSH HL ; Fiddle with the stack SHEXV: POP HL ; ..restore the stack SHEXIT: OR A ; Set return flags POP BC ; Restore registers POP DE POP HL RET END