; Program: NT - Note Taker ; Author: Rob Friefeld (original author), Carson Wilson (update). ; Assembly: SLR's Z80ASM ; SLRNK, SYSLIB, Z3LIB ; DSLIB, ZSLIB (NTxxDS only) ; Version: 4.6 VERS equ 46 ; ; Date: 12 Feb 90 ; Author: Rob Friefeld ; Changes: - ZPRSFN re-instated (works with BGii, ZCPR 3.0) ; - Uses internal stack ; - Reorganized code for clarity, incorporated SYSDEF.LIB ; - Added assembly directive for Type4 version ; - Type4 requires hand configuration. ; ; Date: 11 Feb 90 ; Author: Carson Wilson ; Changes: - Now works with ZCPR 3.3 and up. NT now type 1 only. ; Z33 required for PARSE2. ; - CONOUT now strips bit 7 for high-bit sensitive terminals. ; - Now calls Z3INIT. ; - Removed vestigial data area from NT 4.2. ; - Now terminates file with EOF if input overflows buffer. ; - Check for valid filespec tightened up. ; Date: 02 Feb 90 ; Author: Carson Wilson ; Changes: Made "File: " prompt a configurable option. ; Increased SEPLEN by one. ; ; Date: 25 Jan 90 ; Author: Carson Wilson ; Changes: Now works with CP/M Plus. Bonus: allows CPM+ edit controls! ; - Calls DSLIB universal RCLOCK routine for DateStamper, ; ZSDOS, or CP/M Plus time. ; - Now stops at column 78 to prevent CP/M+ from going to next ; line when CP/M+ console width is set to 79 (Morrow default). ; - Modified Z33FUNCT.LIB for use with Z3PLUS. Bug still ; exists in Z3LIB's GETCCP routine. Since NT does not ; currently prompt for a filename, Z33FUNCT.LIB is not ; called. It is included for reference/future use. ; Secure system capability added by disallowing file ; specification privileges to nonwheels (always use default). ; Separate help for nonwheels. ; Faster operation: no longer "erases" non-existent NOTES.NT ; before creating a new one; aborts immediately if first input ; line contains no characters. ; No longer rings bell when asking the "File: " question. ; No longer asks the "File: " question (commented out). ; Removed optional RCP code during rapid development. This ; should be fairly easy to add back later, if wanted. ; Removed type3 code; use either type1 or type4. Now requires ; Z34 to run (1st instruction is RST 0). ; Changed prompt from ":" to "> ". ; Improved help screen. ; Now uses ZSLIB MDAT2 and MTIMC2 to store date and time in ; NOTES.NT file. ; ; ; Comments: ; 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 Friefeld 4607 Colorado St., Long Beach, CA ; Electronic mail: Ladera Znode ; Version: 4.2 3/18/88 ; Assembly: SLR ; ----------------- ; DEFINITIONS N EQU 0 Y EQU NOT N .ACCEPT 'Assemble with DATE routine? (Y/N) ',DSTAMP .ACCEPT 'Assemble for Type 4 program? (Y/N) ',TYPE4 PUBLIC $MEMRY ; Allows DSEG in linked modules IF DSTAMP external TIMINI,RCLOCK ; From DSLIB external MDAT2,MTIMC2 ; From ZSLIB ENDIF external Z3INIT,ZPRSFN,FCBCHK ; From Z3LIB ; ; STANDARD EQUATES ; ; System Functions RDCONF EQU 1 WRCONF EQU 2 RDBUFF EQU 10 OPENF EQU 15 CLOSEF EQU 16 WRITEF EQU 21 MAKEF EQU 22 SETDMAF EQU 26 SGUSERF EQU 32 DREADF EQU 33 ; Direct access read COMPSZF EQU 35 ; System Addresses BDOS EQU 5H FCB EQU 5CH RECS EQU FCB+33 ; Direct access record TBUF EQU 80H ; ASCII Definitions BELL EQU 07H LF EQU 0AH CR EQU 0DH EOF EQU 1AH ; ; PROGRAM DEFS ; CRTWID equ 80 ; CRT width LINWID equ CRTWID-4 ; Line width to use SEPLEN equ 17 ; Length of note separator (not 0) SEPCHR equ '-' ; Note separator character ; File buffer ; ; BUFLOC -------- Start of buffer ; / Last record of existing note file ; BUFSP Note separator ; \ Date ; --------- Start of new text ; BUFSZ ; BUFTOP --------- Check here for full buffer AFTER line input ; Overflow Can go 1 line plus a little over BUFTOP BUFSZ equ 2000H ; Nominal text space (~50 lines/1000H) BUFMAX equ BUFSZ+LINWID+10 ; Allow a line of overflow BUFSP equ 100H ; Record, sep, CRLF, date &tc, CRLF ; ----------------- ; PROGRAM CODE ; ENTRY: jp START db 'Z3ENV' if TYPE4 db 4 Z3EADR: dw 0 ; Patch with code size reported by linker dw 0 ; Patch with size + data reported by linker else db 1 ; Type-1 environment Z3EADR: dw 0 ; Filled in by Z33 endif ; TYPE4 ; ; 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 PFLAG: db 0 ; Prompt for "File: " on exit if nonzero ; ; MAIN PROGRAM ; START: ld a,(FCB+1) ; Help? cp '/' jp z,HELP ; ID message ld hl,(Z3EADR) ; Get ENV pointer ld a,h ; Test for installation or l jp z,NOTZCPR ; Need Z30+ ld (STKSAV),sp ; Use local stack ld sp,STACK call Z3INIT ; Needed if internal file name parser used ; ; DEFINE TEXT BUFFER ; ; Type 4 program text buffer is placed below run-time location of code. if TYPE4 ld hl,ENTRY ; Start of program ld de,-[LINWID+10] ; Room for a line of overflow plus a bit add hl,de ld (BUFTOP),hl ; Program checks this loc after each line ld de,-BUFSZ ; Now figure start of text buffer add hl,de ld (INDEX),hl ; Init text input pointer ld (TEXTLOC),hl ; Init start of new text ld de,-BUFSP ; Below that is space for date &tc. add hl,de ld (BUFLOC),hl ; Beginning of output buffer else ; Type 1 buffer starts after DSEG ld hl,($MEMRY) ; Start of text buffer ld (BUFLOC),hl ld de,BUFSP add hl,de ld (INDEX),hl ; Input location for text ld (TEXTLOC),hl ld de,BUFSZ add hl,de ld (BUFTOP),hl endif ;TYPE4 call GET_TEXT ; Text input ld hl,(INDEX) ; Tail of text ld de,(TEXTLOC) ; Start of buffer or a sbc hl,de jr z,EXIT ; Nothing in, just quit call GET_NAME ; File name for output call SET_FCB ; Prepare FCB call WRITE_FILE ; Write buffer to file EXIT: ld sp,(STKSAV) ret ; ----------------- ; SUBROUTINES ; ; ; GET TEXT INPUT ; ; Here we just use the BDOS read string function. A more functional ; editor could be employed instead. ; GET_TEXT0: ld de,LINWID ; Input loop add hl,de ; Check remaining room call c,BUZZER ; No more than 1 line left, warn user GET_TEXT: call PRINT ; Display prompt dc '> ' call GET_LINE ; Get a line from console ret z ; Empty line, done. call CRLF ld de,(BUFTOP) ; Check overflow xor a sbc hl,de jr c,GET_TEXT0 call TOOBIG ; Overflow ret ; ; LINE INPUT ; ; INDEX points to location - at current end of text (EOF) ; Use BDOS read string function ; Return Z = no entry, else HL --> new EOF ; GET_LINE: ld hl,TBUF ; Read line to TBUF ld (hl),LINWID ; Maximum chars to accept ex de,hl ld c,RDBUFF ; Get the line call BDOS ld hl,TBUF+1 ; Returned char count ld a,(hl) or a ret z ; Nothing ld c,a ; Move input to position ld b,0 inc hl ld de,(INDEX) ldir ex de,hl ; DE pointed to end of output buffer call INSCRLF ; Insert the CRLF ld (INDEX),hl ld (hl),EOF ; Mark end of text now, overwrite if more or -1 ; Return NZ = still going ret ; ; GET A FILE NAME ; ; This section accepts a file name AFTER the note has been made. If ; PFLAG is false, uses installed name unless specified on command line. ; GET_NAME: call WHLCHK ; Wheel? jp z,RESFCB ; Nonwheel, clear spec and return NOW GETNAME1: ld a,(FCB+1) cp ' ' ; Command line name? jr z,GETNAME2 ; No ld de,FCB call FCBCHK ; Command line filespec valid? ret z ; Yes, use it. GETNAME2: call RESFCB ; No, remove it ld a,(PFLAG) ; Prompt for filename? or a ret z ; No, use installed defaults GETNAME3: ; Input a file name call PRINT dc CR,LF,'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 call ZPRSFN ; Parse token call FCBCHK ; OK? jr nz,GETNAME3 ; Oops ret RESFCB: ; Get rid of FCB spec. ld a,' ' ld (FCB+1),a ; Flag for SETFCB ld (FCB+9),a ld c,SGUSERF ; Reset user to current ld e,0FFh call BDOS ld (FCB+13),a ret ; ; SET UP FCB ; Use default if DU:FILE.EXT not specified on command line ; SET_FCB: ld de,FCB+1 ; Target: FCB ld h,d ld l,e ld a,(de) ; Was name specified? cp ' ' jr nz,SETFCB1 ; Yes, copy name to self, use input drive/user ld hl,DFNAM ; No, use default name ld a,(DFDR) ; ..and default du: ld (FCB),a ld a,(DFUSR) cp 0FFh ; ..and current jr z,SETFCB1 ld (FCB+13),a ; ..or default (installed) user SETFCB1: ld bc,8 ldir ; Copy name (specified or default) ld a,(de) cp ' ' ; Was .EXT specified? ret nz ; Yes ld hl,DFEXT ; No, use default ld bc,3 ldir ret ; ; WRITE THE OUTPUT FILE ; WRITE_FILE: 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,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 BDOSFCB: ld de,FCB jp BDOS ; ; 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 ld a,EOF ADDF2: inc hl cp (hl) 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 ; HL --> read buffer call TIMINI jr z,ADDF4B ; No clock ld hl,CLKBUF call RCLOCK jr nz,ADDF4B ; No clock ld hl,CLKBUF pop de call MDAT2 ld a,' ' ld (de),a inc de ld (de),a inc de call MTIMC2 ex de,hl call INSCRLF push hl ADDF4B: pop hl ENDIF ;dstamp ex de,hl ; DE --> read buffer ADDF5: ld hl,(TEXTLOC) ; Move text to output buffer ld bc,BUFMAX ldir ; Append to read buffer 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 cr,lf,'Ovfl' BUZZER: call PRINT dc BELL ret WHLCHK: ; Test wheel byte ld hl,(Z3EADR) ; HL --> Z3ENV ld de,29h add hl,de ; (HL) --> wheel byte ld e,(hl) inc hl ld d,(hl) ; DE --> wheel byte ld a,(de) or a ; Wheel? ret ; Return (Z) if not INSCRLF: ld (hl),CR ; CR,LF written into text buffer inc hl ld (hl),LF inc hl ret CRLF: call PRINT ; Prints CRLF sequence dc CR,LF ret CONOUT: push bc push de push hl push af and 7fh 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 CR,LF db 'NT, v ',VERS / 10 + '0','.',VERS MOD 10 + '0' db ' - Note Taker',CR,LF dc ' Syntax: NT' call WHLCHK jr z,NWHELP call PRINT db ' [dir:][file][.typ]',CR,LF dc ' Text added to default file if none specified.' NWHELP: call PRINT db CR,LF,' Input blank line to quit.' dc CR,LF ret NOTZCPR: call PRINT dc cr,lf,bell,'Need ZCPR 3.0+' ret ; ; DATA ; $MEMRY: ds 2 ; Initialized by linker DSEG 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 DSTAMP clkbuf: ds 6 ; For clock read ENDIF STKSAV: ds 50 STACK equ $ ; Top of local stack end ; END NT.Z80