; I/O function library for machine language programs ; input functions: (all no echo) public getc, getc1r, getc2r, getc3r, getcnr, getc1t ; output functions: public puta, putc, prnt, putstr$, putstrn, print, putstr0 .Z80 bdos equ 05 bconi equ 01 bcono equ 02 bdcio equ 06 bdci equ 0ffh ; value of e reg. for status/input on direct i/o call bprint equ 09 getc: ; get a character from the console, no echo, no control-s, control-p, ; or tab trapping/expanding (uses direct console I/O) ; ; entry parameters: none. ; ; exit parameters: character returned in a acc. ; ; registers affected: a acc. ; push hl push de push bc getc2: ld c,bdcio ; direct console i/o, ld e,bdci ; set to console input. call bdos or a jr z,getc2 ; wait until character is ready pop bc pop de pop hl ret getc1r: ; get a character within a range of parameters passed in de ; such that the returned character will be greater than or ; equal to the value in d and less than or equal to the ; value in e ( d<=char<=e ). ; ; entry parameters: range in de ; ( low range parameter in d, ; high range parameter in e ) ; ; exit parameters: character returned in a acc. ; ; registers affected: a acc. ; gtc1r1: call getc ; get a character cp d jr c,gtc1r1 ; if smaller than low range, get another. cp e ret c ret z jr gtc1r1 ; too large, keep trying defw 0000 getc2r: ; get a character within one of two ranges. ; ; entry parameters: first range in de, ; second range in hl ; ; exit parameters: character returned in a acc. ; ; registers affected: a acc. ; gtc2r1: call getc cp d jr c,gt2r2 cp e ret c ret z gt2r2: cp h jr c,getc2r cp l ret c ret z jr gtc2r1 getc3r: ; get a character within three ranges. ; ; entry parameters: first range in de, ; second range in hl, ; third range in bc. ; ; exit parameters: character returned in a acc. ; gtc3r1: call getc cp d jr c,gtc3r2 cp e ret c ret z gtc3r2: cp h jr c,gtc3r3 cp l ret c ret z gtc3r3: cp b jr c,gtc3r1 cp c ret c ret z jr gtc3r1 ; not in any range, exit getcnr: ; get a character within n ranges. ; ; entry parameters: hl:=address of test string. ; first byte of test string is number of ; ranges to test, rest of string are byte ; pairs of ranges ; ; exit parameters: character returned in a acc. ; ; registers affected: a acc. ; push hl push bc ld b,(hl) call gtcnr1 pop bc pop hl ret gtcnr1: inc hl call getc cp (hl) inc hl jr c,gtcnr2 cp (hl) ret c ret z gtcnr2: djnz gtcnr1 pop bc pop hl jr getcnr ; start over getc1t: ; get a character in a table. ; ; entry parameters: table address in hl, ; first byte of table is table length, ; table consists of single-byte entries. ; ; exit parameters: character returned in a acc. ; ; registers affected: a acc. ; push hl push bc ld b,(hl) call gtc1t1 pop bc pop hl ret gtc1t1: call getc gtc1t2: inc hl cp (hl) ret z djnz gtc1t1 pop bc pop hl jr getc1t puta: ; output the character in the a acc. ; ; entry parameters: output character in a acc. ; ; exit parameters: none ; ; registers affected: none ; push bc ld c,a call putc pop bc ret putc: ; output the character in c to the console device. ; ; entry parameters: output character in c ; ; exit parameters: none ; ; registers affected: none ; push hl push de push bc push af ld e,c ld c,bcono call bdos pop af pop bc pop de pop hl ret prnt: putstr$:; output a string of characters to the console, string terminated ; by a '$', string address in hl ; push hl push de push bc push af ex de,hl ld c,bprint call bdos pop af pop bc pop de pop hl ret putstrn:; output a string of characters to the console, address in hl, ; first two bytes of string are string length. (first byte is ; high-order, second byte is low order count. ; push hl push bc ld b,(hl) inc hl ld c,(hl) ptstn1: inc hl ld a,(hl) call puta dec bc ld a,b or c jr nz,ptstn1 ret print: putstr0:; output a string of characters to the console, ; address on the stack, terminated by a null, or 00, byte ; ex (sp),hl push de push bc push af call ptst01 pop af pop bc pop de ex (sp),hl ret ptst01: ld a,(hl) inc hl or a ret z call puta jr ptst01 defw 0000h END