; LOG.MAC - 5/2/85 - Log an event. ; Note: the log file buffer overlays INIT. .z80 maclib TNC.LIB entry chgl,log,logo,logdrn,lfcb,event,logtxt,llogtxt entry logging,loggate,logmsg,logfile,logloc external @move,@opena,@closew,tobuf,@ntobuf,@ctobuf external mcall,wfcb,curtime,$memry,ucase,date,time external ckname,ername,erdone,fcb2,mode,logbuf,logsiz asciictl tncdefs dseg lfcb: ds fcbsize ; FCB, filled by RDPARAM ltxt: ds 2 ; Length of txt in logtext bptr: dw logbuf ; Ponter into logbuf bcnt: dw 0 ; # chars in logbuf llogtxt equ 90 ; Max chars in log text string event: ds 1 ; Event code logging: ds 1 ; Logging of if false loggate: ds 1 ; Log gateway events? logmsg: ds 1 ; Log message events? logfile: ds 1 ; Log upload/downloads? logloc: ds 1 ; Log local user events? logtxt: ds llogtxt cseg chgl: ckname fcb2 jp z,ername zmov lfcb,fcb2,fcbsize jp erdone ; Log (A) as event, (B) as subevent, mcall as text. logo: ld (event),a ld hl,logtxt ld (hl),b inc hl ld (hl),' ' inc hl move ,mcall,6 ld (hl),cr log: cmpm logging,true ret nz ; Logging is off cmpm mode,lmode jr nz,loga ; Not local, log cmpm logloc,true ; Log local? ret nz ; No ; Check if we log this event type loga: ld a,(event) cp 'C' jr z,logd cp 'X' jr z,logd cp 'G' jr nz,logb cmpm loggate,true ret nz jr logd logb: cp 'M' jr nz,logc cmpm logmsg,true ret nz jr logd logc: cp 'F' ret nz cmpm logfile,true ret nz ; Yup, we log it. Do so. ; Count # chars in the text going into the file. logd: ld hl,logtxt ld bc,0 loge: ld a,(hl) inc bc inc hl cp cr jr nz,loge ld (ltxt),bc ; # chars in text, including CR ld hl,11 ; # chars in event, date, time add hl,bc ; # chars in this entry ex de,hl push de ; Save # chars in this entry ld hl,logsiz ; Size of buffer ld bc,(bcnt) ; chars now in buffer or a sbc hl,bc ; Left in buffer sbc hl,de ; Left after this entry added call c,logdrn ; Drain buffer if not enough room call curtime ; Get current date/time ld de,(bptr) ld a,(event) ld (de),a ; Move event to buffer inc de ld hl,date ld bc,6 ldir ; Move date to buffer ld hl,time ld bc,4 ldir ; Move time to buffer ld hl,logtxt ld bc,(ltxt) ldir ; Move log text to buffer ld (bptr),de pop de ; # chars in this entry ld hl,(bcnt) ; # chars already in buffer add hl,de ld (bcnt),hl ; # chars in buffer now ret ; Drain the log buffer. logdrn: dtz bcnt ; Anything in log buffer? ret z ; No opena lfcb ; Open log file for append lxim bptr,logbuf ; Point to start of log buffer logda: ld hl,(bptr) ; Point to char ld a,(hl) ; Pick up char inc hl ; Point to next char ld (bptr),hl ; Save pointer to next char call ucase ; Change char to upper case ld c,a cp eof ; Is char an eof? call nz,tobuf ; Put the char in the file buffer ld a,c ; Get the char back cp cr ; Was it a CR? jr nz,logdb ; No ld c,lf ; Had CR, now add LF call tobuf logdb: dcxm bcnt ; One less char in log buffer ld a,l or h ; Anything left in log buffer? jr nz,logda ; Yes, continue ld c,eof call tobuf ; Put EOF in file buffer closew ; Close the log file lxim bptr,logbuf ; Point to start of buffer ret end