; TITLE "SHGO1 - Syslib 4.0" NAME ('HGOTO1') ;================================================================= ; The Libraries, Version 4, (C) 1989 by Alpha Systems Corp. ;----------------------------------------------------------------- ; Author : Harold F. Bower ; Derived from SHGO1.Z80 Ver 1.1 by Richard Conn ; Date : 17 Sep 89 ; Version : 1.2 ; Module : SHGO1 ; Abstract: This module contains the single routine HGOTO1 which ; is a computed GOTO. When called, register pair HL contains ; a Zero-based index into a table of addresses of routines. ; Useage of this routine is as: ; ; LD HL,INDEX ; zero-relative ; CALL HGOTO1 ; DEFW ADDR0 ; IF HL=0 ; DEFW ADDR1 ; IF HL=1 ; DEFW ADDR2 ; IF HL=2 ; ... ; ADDR0: ; COME HERE IF HL=0 ; ... ; ADDR1: ; COME HERE IF HL=1 ; ... ; ADDR2: ; COME HERE IF HL=2 ; ... ; ; No error or range checking is done ; Revision: ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ; Module Entry Points: PUBLIC HGOTO1 .Z80 CSEG ;========================================================================= ; NAME - HGOTO1 - A computed Goto based on indexing into a table of 16-bit ; addresses with a zero-based value passed in the HL register pair. ; Entry: HL - Contains the index into the address table ; Exit : - No values returned, program execution is passed to another addr ; Uses : - None (all values preserved for destination routine) ; Special Requirements: The user must insure that the value passed is ; within the limits of the table and does not evaluate to an address ; outside the address table. ;========================================================================= HGOTO1: EX (SP),HL ; (Index) -> (stack), (Table) -> EX DE,HL ; (Table) -> DE, (DE val) -> EX (SP),HL ; (DE val) -> (stack), (Index) -> PUSH AF ; Save the rest of the registers PUSH HL ADD HL,HL ; HL = offset (index * 2) ADD HL,DE ; point to jump in HL LD A,(HL) ; get low INC HL LD H,(HL) ; get high LD L,A ; HL = address to return to POP DE ; Restore Table value POP AF ; ..and AF EX (SP),HL ; restore DE, address of routine to stack EX DE,HL ; table to HL, DE back in place RET ; Execute the address from the stack END