; TITLE "SACAS1 - Syslib 4.0" NAME ('ACAS1') ;================================================================= ; The Libraries, Version 4, (C) 1989 by Alpha Systems Corp. ;----------------------------------------------------------------- ; Author : Harold F. Bower ; Derived from SACAS1.Z80 Ver 1.1 by Richard Conn ; Date : 17 Sep 89 ; Version : 1.2 ; Module : SACAS1 ; Abstract: This module contains the routine ACASE1 which is a ; statement processor. It evaluates an 8-bit value passed ; by the user, and branches to a specified address, or a ; default address depending on whether or not a match is ; obtained. It is used as follows: ; ; LD A,TEST ; test value ; CALL ACASE1 ; DEFB NUM$ENT ; number of entries in CASE table ; DEFW DEFAULT ; address to goto if no match in acase1 ; DEFB VAL1 ; entry value 1 to test for ; DEFW ADDR1 ; address to goto if entry 1 matches ; DEFB VAL2 ; entry value 2 to test for ; DEFW ADDR2 ; address to goto if entry 2 matches ; ... ; DEFB VALN ; entry value N to test for (N = NUM$ENT) ; DEFW ADDRN ; address to goto if entry N matches ; NUM$ENT is the number of values (VAL1..VALN) in the case table ; Revision: ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ; Module Entry Points PUBLIC ACASE1 .Z80 CSEG ;=============================================================== ; NAME - ACASE1 ; Entry: A - Contains value to test against ; Exit : - N/A ; Uses : - None ; Special Requirements: None ;=============================================================== ACASE1: EX (SP),HL ; return address in HL PUSH AF ; save regs PUSH BC LD B,(HL) ; number of entries INC HL ; pt to default LD (DEFAULT),HL ; save it INC HL ; pt to first entry INC HL ; Loop through case table entries, looking for a match LOOP: CP (HL) ; compare JR Z,MATCH INC HL ; pt to next INC HL INC HL DJNZ LOOP ; count down ; No match found - use default LD HL,(DEFAULT) ; get default JR GOTO ; Match - use HL+1 MATCH: INC HL ; point to address ; Get address in HL and return GOTO: LD A,(HL) ; get low INC HL LD H,(HL) ; get high LD L,A ; HL = address POP BC ; restore regs POP AF EX (SP),HL ; return address on stack, HL restored RET ; Storage for default address DSEG ; Put in the Data Segment DEFAULT: DEFS 2 END