; NT Short program for short notes -- console to disk file. ; Usage: NT [dir:][file][.typ] ; If no file name, one is requested on exit. Blank name ; adds text to default file. ; Author: Rob Frifeld 4607 Colorado St., Long Beach, CA ; Electronic mail: Ladera Znode ; Version: 4.2 3/18/88 ; Assembly: SLR ; To assemble for use in an RCP, change the source file name to RCPNT.LIB ; and insert switches in Z33RCP.LIB and Z33RCP.Z80. Start addr is NTSTART. ; This module requires about 5 records. (The text buffer is below the CCP.) no equ 0 yes equ [not no] rcpver equ no if rcpver dstamp equ no ; Costs a lot of memory to use DATE.LIB endif ;rcpver ; STANDARD EQUATES if [not rcpver] include sysdef.lib ; Standard equates endif ;not rcpver RECS EQU FCB1+33 ; Direct access record DREADF EQU 33 ; Direct access read EOF EQU 1AH DEL EQU 7FH ; PROGRAM DEFS crtwid equ 80 ; CRT width width equ crtwid-2 ; Useable line width crtlns equ 24 ; CRT rows ; NT does not care how many lines are input, only how much memory is ; allocated. If memory is no problem, just set BUFSZ to 8000h or whatever. buflns equ crtlns ; Number of full text lines expected seplen equ 21 ; Length of note separator (not 0) sepchr equ '-' ; Note separator ; Nominal buffer size is large enough for each line to be full to [width] ; plus crlf, a full last record of the file being expanded, and the ; note separator line. ;bufsz equ crtwid*buflns + seplen + 128 ; Minimum for lines specified bufsz equ 3000h ; Text is entered above start of buffer. Leave room for full last record ; of extant file, separator line, crlf, datestamp string bufsp equ 128+seplen+2+24 if [not rcpver] y equ -1 n equ 0 .accept 'Assemble to load address 8000h? (Y/N) ',hiload .accept 'Assemble with DATE routine? (Y/N) ',dstamp if hiload progloc equ 8000h else progloc equ tpa ; Type 3 load address endif ;hiload ; ; CODE START ; org progloc ; TYPE 3 HEADER ; Code modified as suggested by Charles Irvine to function correctly with ; interrupts enabled. Program will abort with an error message when not ; loaded to the correct address (attempt to run it under CP/M or Z30). entry: jr start0 ; Must use relative jump nop ; Filler db 'Z3ENV',3 ; Type-3 environment z3eadr: dw 0 ; Filled in by Z33 dw entry ; Intended load address ; PATCH AREA dfdr: db 0 ; Default drive (A=1...) dfusr: db 0ffh ; Default user (FF=current user) dfnam: db 'NOTES ' ; Default filename dfext: db 'NT ' ; Default fileext ; CONTINUE TYPE 3 HEADER start0: ld hl,0 ; Point to warmboot entry ld a,(hl) ; Save the byte there di ; Protect against interrupts ld (hl),0c9h ; Replace warmboot with a return opcode rst 0 ; Call address 0, pushing RETADDR ; onto stack retaddr: ld (hl),a ; Restore byte at 0 dec sp ; Get stack pointer to point dec sp ; To the value of RETADDR pop hl ; Get it into HL and restore stack ei ; We can allow interrupts again ld de,retaddr ; This is where we should be xor a ; Clear carry flag push hl ; Save address again sbc hl,de ; Subtract -- we should have 0 now pop hl ; Restore value of RETADDR jr z,start ; If addresses matched, begin real code ld de,notz33msg-retaddr ; Offset to message add hl,de ex de,hl ; Switch pointer to message into DE ld c,9 jp 0005h ; Return via BDOS print string function notz33msg: db 'Not Z33+$' ; Abort message if not Z33-compatible start: ld a,(fcb+1) ; Help? cp '/' jp z,help ; ID message else z3eadr: ds 2 dfdr: db 0 ; Default drive (A=1...) dfusr: db 0ffh ; Default user (FF=current user) dfnam: db 'NOTES ' ; Default filename dfext: db 'NT ' ; Default fileext ntstart: call retsave ld hl,z3env ld (z3eadr),hl endif ;not rcpver ; ; DEFINE TEXT BUFFER ; if [not rcpver] ld hl,buf ; Start of text buffer ld (bufloc),hl push hl ld de,bufsp add hl,de ld (index),hl ; Input location for text ld (textloc),hl pop hl ld de,bufsz add hl,de ld (buftop),hl else call define ; Top of free memory in HL ld de,-crtwid add hl,de ld (buftop),hl ld de,-bufsz add hl,de ld (bufloc),hl ld de,bufsp ld (index),hl ld (textloc),hl endif ;not rcpver ; ; LINE INPUT LOOP ; inloop: call print ; Display prompt dc ':' call input ; Get a line from console jr z,getname ; Empty line, done. call crlf ; ld hl,(index) ; Check overflow ld de,(buftop) xor a sbc hl,de jr nc,inloop1 ; Yes ld de,80 ; Warn user only one line left add hl,de call c,buzzer jr inloop inloop1: call toobig ; ; GET A FILE NAME ; Use the Z33 scanner if no name on command line getname: ld a,(fcb+1) ; Already have a file? cp ' ' jr nz,setfcb ; Yes getname1: ; Input a file name call print dc cr,lf,bell,'File: ' ld hl,tbuf ld (hl),50 ex de,hl ld c,rdbuff call bdos ld hl,tbuf+1 ; Capitalize string and terminate it ld a,(hl) inc hl push hl ; Save start of token or a jr z,gnam1b ; No input ld b,a gnam1a: ld a,(hl) call caps ld (hl),a inc hl djnz gnam1a gnam1b: ld (hl),0 pop hl ld de,fcb ; Parse token call scan ; Z33 scanner call fcbchk ; OK? jr nz,getname1 ; Oops ; ; SET UP FCB ; Use default if DU:FILE.EXT not specified on command line ; setfcb: ld de,fcb+1 ; Was name specified? ld hl,dfnam ld a,(de) cp ' ' jr nz,setfcb1 ; Yes ld a,(dfdr) ; Load default du: ld (fcb),a ld a,(dfusr) cp 0ffh ; Use current user jr z,setfcb2 ld (fcb+13),a ; ...or load default user jr setfcb2 setfcb1: push de ; Copies name to itself pop hl setfcb2: ld bc,8 ldir ld hl,dfext ; Was ext specified? ld a,(de) cp ' ' jr nz,writefile ; Yes ld bc,3 ; No, use default ldir ; ; WRITE THE OUTPUT FILE ; writefile: ld a,(fcb+13) ; Set the user code ld e,a ld c,sguserf call bdos call addfil ; Append file, if exists jr nz,wrtf1 ; Appending ld c,erasef ; Delete original file call bdosfcb ld c,makef ; Make new file call bdosfcb ld hl,fcb+12 ; Zero control bytes ld b,24 ld (hl),0 inc hl djnz $-3 wrtf1: ld hl,(bufloc) ; Write buffer to file wrtloop: push hl ex de,hl ld c,setdmaf call bdos ld c,writef call bdosfcb pop hl ld bc,128 ld a,eof cpir ; Compare each character with EOF jr nz,wrtloop ; And get next record ld c,closef ; Close file and exit thru bdos if rcpver call bdosfcb jp exit endif ;rcpver bdosfcb: ld de,fcb jp bdos ; ; LINE INPUT ; Index points to location - at current end of text ; Use bdos rdbuff function, then move line back over buffer def bytes. ; Return Z = no entry input: ld hl,(index) ; Current file pos push hl ; Set it up for rdbuff push hl ld (hl),crtwid-2 ; Allow 78 chars ex de,hl ld c,rdbuff ; Get the line call bdos pop hl pop de inc hl ld a,(hl) ; Returned char count or a jr z,input0 ld c,a ; Move input to position ld b,0 inc hl ldir ex de,hl ; DE pointed to end of output buffer call inscrlf ld (index),hl or -1 ret input0: dec hl ld (hl),eof ret ; ; APPEND ; If the file exists, read the last record. ; Move text down from textloc to end of last record (or start of buffer). ; Return Z = new file ; addfil: ld c,openf ; Open file call bdosfcb inc a jr z,addx ; No file addf1: ld c,compszf ; 0 length file? call bdosfcb ld hl,(recs) ; Record bytes = 0 ? ld a,h or l jr z,addx ; Yes, nothing to read dec hl ; Read last record ld (recs),hl ld de,(bufloc) ld c,setdmaf call bdos ld c,dreadf call bdosfcb ld hl,(bufloc) ; Find EOF dec hl addf2: inc hl ld a,(hl) cp eof jr nz,addf2 ld b,seplen ; Since we are appending, insert separator. addf3: ld (hl),sepchr inc hl djnz addf3 call inscrlf ; Put crlf after it if dstamp addf4: push hl call date pop de jr z,addf4b ; No routine addf4a: ld a,(hl) cp '$' jr z,addf4b ldi jr addf4a addf4b: ex de,hl endif ;dstamp ex de,hl addf5: ld hl,(textloc) ; Move text to output buffer ld bc,bufsz+crtwid ldir or -1 ret addx: if dstamp ld hl,(bufloc) call addf4 else ld de,(bufloc) call addf5 endif ;dstamp xor a ret ; ; SUPPORT ROUTINES ; caps: cp 'a' ret c cp 'z'+1 ret nc and 5fh ret toobig: call print dc 'Ovfl' buzzer: call print dc bell ret inscrlf: ld (hl),cr ; CR,LF written into text buffer inc hl ld (hl),lf inc hl ret if [not rcpver] crlf: call print ; Prints CRLF sequence dc cr,lf ret conout: push bc push de push hl push af ld e,a ld c,wrconf call bdos pop af pop hl pop de pop bc ret print: ex (sp),hl call printhl ex (sp),hl ret ; ; Print String (terminated in 0) pted to by HL ; printhl: ld a,(hl) ; Done? inc hl ; Pt to next or a ; 0 terminator ret z call conout ; Print char ret m jr printhl help: call print db 'NT, v 4.2',cr,lf db 'Usage: NT [dir:][file][.typ]',cr,lf db 'Text added to default file if none specified.',cr,lf dc 'Input blank line to quit.' ret endif ;not rcpver include z33funct.lib ; SCAN, FCBCHK if dstamp include date.lib endif ; ; DATA ; bufloc: ds 2 ; Output buffer textloc: ds 2 ; Start of input text buftop: ds 2 ; Pointer to buffer top appfil: ds 1 ; Append flag index: ds 2 ; Pointer to output buffer if [not rcpver] buf equ $ ; "Worst case" memory requirements ds bufsz ; Buftop points here ds crtwid ; Overflow line nttop equ $ ; Max memory used endif ;not rcpver ;END NT.Z80