; WRTVARS.Z80 ; ; A module for the Z3VARS library to write out the list from memory. ; Note that the list is expected to be no longer than 32k. ; ; Author: Dreas Nielsen ; Revision history: ; Date Comments ; ------ ---------- ; 1/15/87 Created. ; 7/27/89 Shortened code -- Howard Goldstein ; ; EOF EQU 'Z'-'@' ; EXT Z3VARS,SHVNAM,XROOT PUBLIC WRTVARS EXT RETUD,LOGUD,INITFCB,F$MAKE,F$CLOSE,F$WRITE,SETDMA ; ; ; ;================ ; ;---- WRTVARS ; ; Enter with: ; no parameters needed. ; Return with: ; A = 0 and Z if success. ; NZ if vars not loaded or write error. ; WRTVARS: LD A,(Z3VARS+1) OR A JR NZ,WRT0 DEC A RET ; WRT0: PUSH BC PUSH DE PUSH HL CALL RETUD ;...in case it's been changed since loading PUSH BC ;store current du on stack CALL XROOT CALL LOGUD ; CALL SHVNAM ;...in case it's been changed since loading LD DE,Z3VARS+2 ;point to file control block CALL INITFCB ;delete old file and make new one CALL F$MAKE JP M,BACK LD HL,(Z3VARS) ;calculate # of sectors to write PUSH HL LD A,EOF LD BC,65535 CPIR ;HL = end of list POP DE ;DE = beginning XOR A ;clear carry flag SBC HL,DE ;# of bytes in HL ADD HL,HL ;divide by 128 -- shift left 1 bit ;...instead of right by 7 OR L ;if bits left in L, division truncated JR Z,SECTCT ;...so add 1 to sector count INC H SECTCT: LD B,H ;>32k of shell variables means trouble!! ; LD DE,Z3VARS+2 ;point to fcb LD HL,(Z3VARS) ;this is first DMA addr. WRFILE: CALL SETDMA ;write all sectors CALL F$WRITE PUSH AF ;save error status CALL NZ,F$CLOSE ;attempt to close file on error POP AF ;restore error status JR NZ,BACK ;write error PUSH DE ;increment DMA addr LD DE,128 ADD HL,DE POP DE DJNZ WRFILE ; close file CALL F$CLOSE BACK: POP BC ;restore original du CALL LOGUD POP HL POP DE POP BC RET ; ;---------------- ; END