; TITLE "SACAS3 - Syslib 4.0" NAME ('ACASE3') ;================================================================= ; The Libraries, Version 4, (C) 1989 by Alpha Systems Corp. ;----------------------------------------------------------------- ; Author : Harold F. Bower ; Derived from SACAS3.Z80 Ver 1.1 by Richard Conn ; Date : 17 Sep 89 ; Version : 1.2 ; Module : SACAS3 ; Abstract: This module contains the routine ACASE3 which is a ; Case statement processor which differs from ACASE1 and ; ACASE2 in that the return address is preserved so that ; execution can resume after the branch by executing a ; simple Return instruction. It uses a remotely-located ; Case table as does ACASE2. It is used as: ; ; LD A,TEST ; test value ; LD DE,TABLE ; case table ; CALL ACASE3 ; ; resume here if routines RETurn ; ... ; TABLE: ; DEFB NUM$ENT ; number of entries in CASE table ; DEFW DEFAULT ; address to goto if no match in acase3 ; 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 ACASE3 .Z80 CSEG ;=============================================================== ; NAME - ACASE3 ; Entry: DE - Points to a Case Table of values and addresses ; A - Value against which to test ; Exit : - (return address pushed on stack) ; Uses : - None (Preserved for subroutine) ; Special Requirements: None ;=============================================================== ACASE3: PUSH HL ; save 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 run routine (original return address still on stack) 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 Data Segment DEFAULT: DEFS 2 END