; TITLE "SACAS2 - Syslib 4.0" NAME ('ACASE2') ;================================================================= ; The Libraries, Version 4, (C) 1989 by Alpha Systems Corp. ;----------------------------------------------------------------- ; Author : Harold F. Bower ; Derived from SACAS2.Z80 Ver 1.1 by Richard Conn ; Date : 17 Sep 89 ; Version : 1.2 ; Module : SACAS2 ; Abstract: This module contains the routine ACASE2 which is a ; case statement processor similar to ACASE1, but features ; a remotely located table. It branches to specified ; routines based on the value in the A register. It is ; implemented as: ; ; LD A,TEST ; test value ; LD DE,TABLE ; case table ; CALL ACASE2 ; ... ; TABLE: ; DEFB NUM$ENT ; number of entries in CASE table ; DEFW DEFAULT ; address to goto if no match in acase2 ; 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 ACASE2 .Z80 CSEG ;=============================================================== ; NAME - ACASE2 ; Entry: DE - Points to the Case table ; A - Contains the value against which to test ; Exit : - N/A ; Uses : - None (preserved for destination routine) ; Special Requirements: None ;=============================================================== ACASE2: EX (SP),HL ; return address in HL LD H,D ; HL=DE=case table address LD L,E 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