;---------------------------------------------------------------- ; This is a module in the ASMLIB library. ; ; This module reads a line of input from the console and puts it into ; a standard CP/M console buffer pointed to by DE on entry. This is ; a little nicer that CP/M as it allows buffers to be pre-initialized ; so that it is printed when the buffer is input so that defaults can ; be loaded before entry of data. ; ; Written R.C.H. 22/10/83 ; Last Update R.C.H. 22/10/83 ;---------------------------------------------------------------- ; name 'cbuff' public cbuff extrn bell,cie,coe ; get and put a byte to screen ; maclib z80 ; cbuff: push psw ldax d ; get buffer size in bytes ora a jrz cbuff$end push h push b push d xchg ; put string address into HL mov c,a ; Now C = buffer maximum size init: mvi b,00 ; character read = 0 inx h ; hl -> size of character read now ; Here we detect if there is some data in the buffer to be pre printed ; and if there is the we print it. mov a,m ; get number of chars. in the buffer inx h ; point to string space now. ora a jrz rdloop ; Print the initialized character string, save the size for later mov b,a push b ; save init2: mov a,m ; get the character inx h ; point to next string space byte call dspchr ; print it, maybe control character djnz init2 ; print all characters pop b ; restore # of characters ; ; On entry here HL-> string space, next free byte, B = number of characters ; in the string. C = number of bytes in the buffer. rdloop: call cie ; get a character cpi 0dh ; end if carriage return jrz exitrd ; exit cpi 0ah jrz exitrd cpi 08 ; backspace ?? jrnz rdlp1 ; if not then continue call backsp ; else backspace jr rdloop ; keep on backspacing rdlp1: cpi 018h ; delete line ? jrnz rdlp2 del1: call backsp ; delete a character jrnz del1 ; keep on till all character deaded jr rdloop ; start again ebonettes ; ; If here we check if the buffer is full. If so we ring the bell rdlp2: mov e,a ; save the character mov a,b ; load byte count cmp c ; is it equal to the maximum ? jrc strch ; store the character if not full call bell ; else ring the bell jr rdloop ; get more characters ; ; Buffer not full so save the character strch: mov a,e ; get character mov m,a ; save it inx h ; point to next buffer byte inr b ; increment byte count call dspchr ; display the (maybe control) character jr rdloop ; do again, more characters ; ; Display a control character by preceeding it with a '^' ; dspchr: cpi 020h ; was it a space ? jnc coe ; if not then print & return mov e,a ; else save character mvi a,'^' ; indicate a control character call coe mov a,e ; restore character adi 040h ; make printable jmp coe ; ; Send a backspace and detect if at the start of the line. ; backsp: mov a,b ; get character count ora a rz ; return if line empty dcx h ; decrement byte pointer mov a,m ; get the character cpi 020h ; is it a control character ? jrnc bsp1 ; if not then delete 1 char only call bsp ; send a backspace bsp1: call bsp ; backspace 1 dcr b ; one less string byte ret ; ; Send the backspace bsp: mvi a,08 call coe mvi a,' ' ; erase the character call coe mvi a,08 jmp coe ; send and return exitrd: ; Set the number of bytes read into the buffer byte at DE + 1. ; pop d ; restore all registers (buffer addr) mov a,b ; get # of characters inx d stax d ; save in characters read byte dcx d ; restore de ; pop b pop h cbuff$end: pop psw ret end