; ; TBJMPDMO.ASM 03-05-83 Mark J. Pulver - AIMS Sysop ; (312) 789-0499 24hrs / 7 days ; ; In search of a new way to check for a special character typed ; versus a long list of CMP / JZ / CMP / ad nauseum, ; this routine was developed. Presented here in a commented example ; form, I'm sure that it can be cleaned up for speed, (characters ; could be stored as control, etc.), but the base concept is what ; I was after. ; ; The routine, ( CHECK ), is to be entered with @HL pointing to ; a table of control characters to be checked, and @DE pointing to the ; table of addresses to be jumped to if a match is found. The charcters ; be stored as caps due to a SUI 040h to convert to control ; characters. The table itself could be control characters, if the SUI ; was removed, but it may not be as clear, even though a hair faster. ; ; ;----------------- ; The Basics ; ;----------------- ; bkspc: equ 8 ; backspace lf: equ 10 ; line feed cr: equ 13 ; carriage return ; bdos: equ 5 ; bdos entry dio: equ 6 ; direct console i/o prnt: equ 9 ; bdos print function ; ; org 0100h ; ; ; Print signon message ; lxi d,signon mvi c,prnt call bdos ; ; ; Check console for typed character ; getone: mvi c,dio ; use bdos direct i/o mvi e,0ffh ; we want input call bdos ; check... ora a ; was there one? jz getone ; no, look again ; ; ; We have a character, was it control? ; cpi ' ' ; was it a control character jc ctrl ; yep, handle special mvi c,dio ; no, so echo it back mov e,a call bdos jmp getone ; get another one ; ctrl: lxi h,comm ; point to "okay" character lookup lxi d,commj ; point to beginning of address table ; ; ; Check character typed against table pointed at by @H ; check: mvi b,0 cknxt: push psw ; save typed character mov a,m ; get character from table ora a ; end of table? jz done ; yes, exit from lookup sui 40h ; make table char control mov c,a ; setup for compare pop psw ; this is typed character cmp c ; do they match? jz gotit ; yep, exit inr b ; no, so bump counter inx h ; and pointer jmp cknxt ; look again ; ; ; Found a match, setup and jump to routine ; gotit: mov a,b ; counter to @A ral ; mult by two, (2 byte addresses) xchg ; address table pointer was in @DE mvi d,0 ; clear @D mov e,a ; counter is now an offset into table dad d ; add offset to pointer mov e,m ; first byte to @E inx h ; bump pointer mov d,m ; next byte to @D xchg ; swap @DE & @HL pchl ; @HL to @PC, (will execute routine) ; ; ; Control character was not in table ; done: pop psw ; clean up stack lxi d,noent ; point to message mvi c,prnt ; bdos print call bdos jmp getone ; return to caller ; ; ; All of the following print a simple message, AJUMP prints the ; literal "Control-A", BJUMP prints "Control-B", etc, and then go ; back for another character. Realize that anything could happen ; at these routines...Not just printing a message, each of the ; routines are written out versus using a common print function ; to emphasize this. ; ajump: lxi d,amsg ; point to message mvi c,prnt ; BDOS print function call bdos ; print it jmp getone ; look again ; bjump: lxi d,bmsg mvi c,prnt call bdos jmp getone ; cjump: lxi d,cmsg mvi c,prnt call bdos jmp 0 ; gotta get outta here somehow... ; djump: lxi d,dmsg mvi c,prnt call bdos jmp getone ; ejump: lxi d,emsg mvi c,prnt call bdos jmp getone ; bck: lxi d,bkstr mvi c,prnt call bdos jmp getone ; lfd: mvi c,dio mvi e,lf call bdos jmp getone ; crlf: lxi d,crstr mvi c,prnt call bdos jmp getone ; ; ; comm: db 'ABCDEHJM',0 ; char table, must be caps... commj: dw ajump,bjump,cjump,djump,ejump ; address table dw bck,lfd,crlf ; ; amsg: db cr,lf,'Control-A',cr,lf,'$' ;\ bmsg: db cr,lf,'Control-B',cr,lf,'$' ; \ cmsg: db cr,lf,lf,'Hope this helped!',cr,lf,'$' ; |---Simple Messages dmsg: db cr,lf,'Control-D',cr,lf,'$' ; / emsg: db cr,lf,'Control-E',cr,lf,'$' ;/ ; noent: db cr,lf,'Unknown Entry',cr,lf,'$' ; just to let ya know ; bkstr: db bkspc,' ',bkspc,'$' ; Backspace / Delete crstr: db cr,lf,'$' ; Return / Linefeed ; signon: db cr,lf,lf db 'TBJMPDMO - A simple routine to demonstrate an alternate',cr,lf db ' method for special character entry.',cr,lf,lf db ' Enter printing and non-printing characters, control is',cr,lf db 'transfered on control characters. Use Control-C to end.' db cr,lf,lf,'$' ; ; end