.Z80 ; *** V I E W *** ;Mini-text-editor for Write-Hand-Man ;Written for HiSoft by D.W.Clements Sept 1 1986 ; Tided by Dave Nutkins 1987 org 0 base equ $ bdos equ base+5 filefcb equ base+5ch buf equ base+80h dma equ buf+80h erase equ 19 open equ 15 close equ 16 readran equ 33 writeran equ 34 setdma equ 26 make equ 22 ctle equ 5 ctlx equ 24 ctla equ 1 ctld equ 4 ctlb equ 2 ctlf equ 6 ctlj equ 10 ctlq equ 17 org 100h jp start ;escape p reverse video screendat: db 1,27,1,"p",1,86h,32,8ah,1,8ch,1,13,1,10,1,85h,12,32 db 1,"V",1,32,1,"I",1,32,1,"E",1,32,1,"W",13,32,1,85h ;escape q normal video db 1,13,1,10,1,87h,32,8ah,1,8dh,1,13,1,10,1,27,1,"q",1,85h,32,32 db 1,85h,1,13,1,10,1,85h,32,32,1,85h,1,13,1,10,1,85h,32,32 db 1,85h,1,13,1,10,1,85h,32,32,1,85h,1,13,1,10,1,85h,32,32 db 1,85h,1,13,1,10,1,85h,32,32,1,85h,1,13,1,10,1,85h,32,32 db 1,85h,1,13,1,10,1,85h,32,32,1,85h db 1,13,1,10,1,83h,32,8ah db 1,89h,0,0 org 1a0h start: call doscreen call setwindow ld (savestack),sp restart: xor a ld l,a ld h,a ld (pagenum),hl ld (currow),a ld (curcol),a ld (curpos),hl dec hl dec a ld (blockstart),hl ld (blockend),hl call doenter call loadpage keyloop: xbios macro adr call 0fc5ah dw adr endm TE_ASK equ 0bfh KM_KT_GET equ 0dah KM_KT_PUT equ 0ddh kshift equ 21 kalt equ 80 kextra equ 84 kshlock equ 70 kright equ 6 kleft equ 15 kup equ 14 kdown equ 79 kplus equ 23 kminus equ 76 kexit equ 8 kdelback equ 72 kcopy equ 11 kfind equ 20 kcut equ 10 kcr equ 18 kenter equ 78 kfind equ 20 kC equ 62 kH equ 44 kJ equ 45 kV equ 55 kY equ 43 kcan equ 75 shift equ 5 ; bit in the shift status byte alt equ 7 loop: key1: xbios KM_KT_GET jr nc,loop ; key number in bc ;ignore shifted stuff on its own ld a,c cp kshift jr z,key1 cp kalt jr z,key1 cp kextra jr z,key1 cp kshlock jr Z,key1 res 3,b dec b inc b jr nz,Shifted ;the unshifted codes cp kexit jp z,exit cp kleft jp z,cursorleft cp kright jp z,cursorright cp kup jp z,cursorup cp kdown jp z,cursordown cp kcan jp z,anotherfile cp kcut jp z,cut ;now make it ASCII normal: ; key number in bc ;ignore shifted stuff on its own ld a,c xbios KM_KT_PUT ld c,6 loop2: ld e,255 call bdos or a jr z,loop2 cp " " jr c,key1 jp doedit Shifted: bit shift,b jr z,normal ;really shifted cp kright jp z,pageforward cp kleft jp z,pagebackward jr normal doedit: ld hl,(curpos) ld h,0 ld de,buf add hl,de ld (hl),a push af ld a,(curcol) inc a cp 32 push af jr nz,nowrap ld a,(currow) inc a and 7 ld (currow),a nowrap: pop af and 31 ld (curcol),a ld hl,(curpos) inc hl ld ix,currow or (ix+0) jr nz,donecurpos ld de,256 and a sbc hl,de donecurpos: ld (curpos),hl pop af ld b,1 call display2 call dopos jp keyloop ; Subroutines printit: ;input a=char output char to lst: push bc push de ld c,5 call chardos jr popdebc chardos: ld e,a savedos: push hl push af call bdos pop af pop hl ret writechar: ;input a=char output char to con: push bc push de ld c,2 call chardos popdebc: pop de pop bc ret readrandomrecord: ;inputs: de=fcb hl=record No. ; bc=dma address ;function: loads record number (hl) of file (de) ; into (bc) ;preserves hl returns error number in A Z if ok NZ error push hl push de ld e,c ld d,b ld c,setdma call bdos pop de ;fcb ld hl,33 add hl,de pop bc ld (hl),c inc hl ld (hl),b inc hl ld (hl),0 push bc ld c,readran call bdos or a pop hl ret ReadCheck: call readrandomrecord ret z jp discerror writerandomrecord: ;function: writes data at dma(bc) to file(de) ;record No. hl ;perserves hl ;inputs same as readranrec push hl push de ld e,c ld d,b ld c,setdma call bdos pop de ;fcb ld hl,33 add hl,de pop bc ld (hl),c inc hl ld (hl),b inc hl ld (hl),0 push bc ld c,writeran call bdos or a pop hl jp nz,discerror ret cut: ld hl,(blockstart) inc hl ld a,h or l jp z,markstart ld hl,(curpos) ld (blockend),hl ld de,(blockstart) push hl push de and a sbc hl,de pop de pop hl jr nz,diff ld hl,0ffffh ld (blockstart),hl ld (blockend),hl jp keyloop diff: jr nc,endbig ex de,hl endbig: ld (blockend),hl ld (blockstart),de call getakey and 05fh cp "M" jp z,cutram cp "P" jp z,cutprinter jp keyloop markstart: ld hl,(curpos) ld (blockstart),hl jp keyloop cutprinter: call setcut loopprint: ld a,(hl) call printit dec bc inc hl ld a,b or c jp z,doneprint push bc push hl ex de,hl ld hl,buf+128 and a sbc hl,de jr nz,notendbuf ld hl,(startpage) inc hl ld (startpage),hl ld de,filefcb ld bc,buf call ReadCheck pop hl ld hl,buf push hl notendbuf: pop hl pop bc jp loopprint doneprint: ld a,10 call printit call loadpage ld hl,0ffffh ld (blockstart),hl ld (blockend),hl jp keyloop anotherfile: ld de,filefcb ld c,close call bdos jp restart getakey: ;inputs: none outputs a=key pressed push bc push de push hl getak1: ld c,6 ld e,0ffh call bdos or a jr z,getak1 pop hl pop de pop bc ret cutram: ;function: writes a block of data from current file to ; ram disk file M:CUT.WHM ld de,discspace ld c,setdma call bdos ld e,12 ld c,46 call bdos ;get disk free space ;dma contains r0,r1,r2 ld hl,(blockend) ld de,(blockstart) and a sbc hl,de ex de,hl srl e ld e,d rl e ld d,0 rl d ; divide de by 128 inc de inc de ;safety margin ld hl,(discspace) ld a,(discspace+2) and a jr nz,roomondisk sbc hl,de jr nc,roomondisk ld a,2 jp discerror roomondisk: ld hl,0 ld (cutpageno),hl ld de,cutfcb ld c,erase call bdos ld de,cutfcb ld c,make call bdos ld de,cutfcb ld c,open call bdos call setcut loopi: ld de,dma ld a,128 loopw: ldi ex af,af ld a,b or c jp z,done ex af,af push de push bc PUSH af push hl ex de,hl ;de=pos ld hl,buf+128 and a sbc hl,de jp nz,nothlendbuf ld de,filefcb ld hl,(startpage) inc hl ld (startpage),hl ld bc,buf call ReadCheck noerrors: pop hl ld hl,buf push hl nothlendbuf: pop hl pop af pop bc pop de dec a jp nz,loopw call writedma jp loopi done: ld a,26 ld (de),a call writedma ld de,cutfcb ld c,close call bdos call loadpage ld hl,65535 ld (blockstart),hl ld (blockend),hl jp keyloop writedma: push hl push bc ld de,cutfcb ld bc,dma ld hl,(cutpageno) call writerandomrecord inc hl ld (cutpageno),hl pop bc pop hl ret setcut: call savepage ld hl,(blockstart) ld de,080h ld bc,0 loopdi: and a sbc hl,de jr c,donedi inc bc jr loopdi donedi: add hl,de ld de,buf add hl,de push hl ld hl,startpage ld (hl),c inc hl ld (hl),b inc hl ld (hl),0 ld hl,(blockend) ld de,(blockstart) and a sbc hl,de ld b,h ld c,l inc bc push bc ld hl,(startpage) xor a loadpage: ;function: loads two records into buf & dma ;the two current records ;inputs (pagenum) & filefcb ;outputs buf & dma contain 256 bytes of data from file ld de,filefcb ld hl,(pagenum) ld bc,buf call ReadCheck inc hl ld bc,dma ld de,filefcb call readrandomrecord ld (Second),a jr z,LoadOk dec a jp nz,DiscError ld de,dma+1 ; pad with spaces ld hl,dma ld (hl)," " ld bc,127 ldir LoadOK: call display call dopos ret savepage: ld hl,(pagenum) ld de,filefcb ld bc,buf call writerandomrecord ld a,(second) or a ret nz ; if only one record don't output ld bc,dma inc hl ld de,filefcb jp writerandomrecord display: ;displays two records of data in text window call dohome ld hl,buf ld b,0 displayloop: ld A,(hl) display2: and 07fh cp 32 ld e,a jr nc,notcontrol ld e,95 cp 9 jr nz,nottab ld e,252 jr notcontrol nottab: cp 13 jr nz,notreturn ld e,253 jr notcontrol notreturn: cp 10 jr nz,notlf ld e,167 jr notcontrol notlf: notcontrol: ld a,e call writechar inc hl djnz displayloop dohome: ld a,27 call writechar ld a,'H' jp writechar doscreen: ;find the current viewport size and position so we can restore it xbios TE_ASK ld (viewtop),bc ld (viewsize),de call dohome ld hl,screendat nextdata: ld a,(hl) or a ret z inc hl ld b,a ld a,(hl) inc hl loopdo: call writechar djnz loopdo jr nextdata discerror: ld sp,(savestack) ld hl,keyloop or a jr nz,makereturn ld hl,restart makereturn: push hl cp 10h jr nz,notdiscchanged ld a,3 notdiscchanged: cp 3 jr c,oknormal ld a,4 oknormal: ld hl,errtab ld de,21 test: or a jr z,doneadd21 add hl,de dec a jr test doneadd21: ld de,erroffset ld bc,21 ldir ld de,errwindow ld c,9 call bdos ld de,curof ld c,9 call bdos ErrorKey: xbios KM_KT_GET jr nc,ErrorKey ld a,c cp kexit push af ld de,curon ld c,9 call bdos pop af cp 27 jp z,exit2 ret cls: call dohome ld b,0 ld a,32 loopspace: call writechar djnz loopspace call dohome ret doenter: call cls ld de,promptmess ld c,9 call bdos ;Get the Console mode status ld c,109 ld de,65535 call bdos push hl ; save console mode status ld a,12 ;raw console mode and disable CTRL-C termination or l ld e,a ld d,h ld c,109 call bdos ld hl,cbbc xor a ld b,16 zeroloop: ld (hl),a inc hl djnz zeroloop ;now some naughty code to see if exit is the first key hit Chkexit: xbios KM_KT_GET jr nc,ChkExit ld a,c cp kexit jp z,exit2 xbios KM_KT_PUT ld c,10 ;get command line ld de,cbb call bdos ld de,pfcb ld c,152 ;parse filename ! call bdos pop de ;original console mode status ld c,109 ;restore it call bdos ld de,filefcb ld c,15 call bdos inc a jp z,discerror ld de,filefcb ld c,35 call bdos ld a,(filefcb+35) or a jp nz,discerror ;file too big (>8meg) ld hl,(filefcb+33) dec hl dec hl ld (filesize),hl ret cursorleft: ld a,(curcol) or a jp z,keyloop dec a ld (curcol),a ld hl,(curpos) dec hl ld (curpos),hl ld de,curleft ld c,9 call bdos jp keyloop cursorright: ld a,(curcol) cp 31 jp z,keyloop inc a ld (curcol),a ld hl,(curpos) inc hl ld (curpos),hl ld de,curright ld c,9 call bdos jp keyloop cursorup: ld a,(currow) or a jp z,keyloop dec a ld (currow),a ld hl,(curpos) ld de,32 and a sbc HL,DE ld (curpos),hl ld de,curup ld c,9 call bdos jp keyloop cursordown: ld a,(currow) cp 7 jp z,keyloop inc a ld (currow),a ld hl,(curpos) ld de,32 add hl,de ld (curpos),hl ld a,10 call writechar jp keyloop pageforward: ;Function: reads next record into buffer ;and displays page ld a,(Second) or a jp nz,keyloop ;only one block we are at end ld iy,pagenum ld ix,filesize ld a,(ix+0) cp (iy+0) jr nz,noteof ld a,(ix+1) cp (iy+1) jr nz,noteof jp keyloop noteof: call savepage ld hl,(pagenum) inc hl ld (pagenum),hl call loadpage ld hl,(curpos) ld de,128 add hl,de ld (curpos),hl call dopos jp keyloop pagebackward: ld ix,pagenum ld a,(ix+0) or (ix+1) jp z,keyloop call savepage ld hl,(pagenum) dec hl ld (pagenum),hl call loadpage ld hl,(curpos) ld de,128 and a sbc hl,de ld (curpos),hl call dopos jp keyloop dopos: call dohome ld a,(currow) loopdown: or a jr z,donedown ld e,a ld a,10 call writechar ld a,e dec a jr loopdown donedown: ld a,(curcol) ld de,curright ld c,9 ld b,a inc b acrossloop: dec b jr z,doneacross push de push bc call bdos pop bc pop de jr acrossloop doneacross: ret exit: call savepage ld de,filefcb ld c,close call bdos exit2: ld sp,(savestack) ld a,27 call writechar ld a,'X' call writechar ld a,(viewtop+1) call writeascii ld a,(viewtop) call writeascii ld a,(viewsize+1) call writeascii ld a,(viewsize) call writeascii jp base writeascii: add a,32 jp writechar setwindow: ld a,27 call writechar ld a,'X' call writechar ld a,(viewtop+1) add a,3 ; 3 down call writeascii ld a,(viewtop) ; 1 across inc a call writeascii ld a,(viewsize+1) call writeascii ;leave the length alone? ld a,31 ;width jr writeascii ;set the view port 0,0 31,89 ;screenstring: ; db 27,"X",32,32,63,121,24h ;set the view port 3,1 18,31 winstring: db 27,"X",35,33,50,63,24h startpage: ds 3 endpage: ds 3 blockend: dw 0ffffh blockstart: dw 0ffffh curcol: db 0 currow: db 0 curpos: dw 0 pagenum: ds 3,0 filesize: ds 3,0 cutfcb: db 13,"CUT WHM" ds 24,0 cutpageno: ds 3 savestack: dw 0 errtab: db "Can't find file! " db "Passed end of file " db "Disc is full " db "Disc has been changed" db "Unknown disc error " errwindow: ;escape C is cursor right db 27,"H",10,10,27,"C",27,"C",086h ds 23,08ah db 08ch,13,10,27,"C",27,"C",85h,32 erroffset: ds 22,32 db 85h,13,10,27,"C",27,"C",83h ds 23,08ah db 089h,24h promptmess: db 27,"H",10,"Enter Filename",13,10,">",24h cbb: db 16 cbbnc: db 0 cbbc: ds 16,0 pfcb: dw cbbc dw filefcb viewtop: ds 2 ;top of the view port viewsize: ds 2 ;size of the view port Second: ds 1 ;0 if second read in 1 if not discspace: ds 3 curleft: db 27,"D$" curright: db 27,"C$" curup: db 27,"A$" curon: db 27,"e$" curof: db 27,"f$" END