; TITLE "SDGO2 - Syslib 4.0" NAME ('DGOTO2') ;================================================================= ; The Libraries, Version 4, (C) 1989 by Alpha Systems Corp. ;----------------------------------------------------------------- ; Author : Harold F. Bower ; Derived from SDGO2.Z80 Ver 1.1 by Richard Conn ; Date : 17 Sep 89 ; Version : 1.2 ; Module : SDGO2 ; Abstract: This module contains the routine DGOTO2 which is a ; computed goto based on a 16-bit value passed to the ; routine. A 16-bit maximum value is also passed to insure ; that the jump table limit is not exceeded. The table is ; made up of JP xx instructions as opposed to the DEFW xx ; table of addresses in DGOTO1. The routine is used as: ; ; LD HL,INDEX ; zero-relative ; LD DE,2 ; max value allowed ; CALL DGOTO2 ; JP ADDR0 ; IF HL=0 ; JP ADDR1 ; IF HL=1 ; JP ADDR2 ; IF HL=2 ; ; IF HL > DE ; ... ; ADDR0: ; COME HERE IF HL=0 ; ... ; ADDR1: ; COME HERE IF HL=1 ; ... ; ADDR2: ; COME HERE IF HL=2 ; ... ; Revision: ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ; Module Entry Points PUBLIC DGOTO2 .Z80 CSEG ;=============================================================== ; NAME - DGOTO2 ; Entry: (Stack) - Contains the JP table starting address ; HL - Contains the Zero-relative index into the table ; DE - Contains the maximum legal value of the index ; Exit : - N/A ; Uses : - None (all parameters preserved for destination) ; Special Requirements: None ;=============================================================== DGOTO2: LD (HLSAVE),HL ; save HL PUSH AF ; save regs PUSH DE LD A,D ; check for range error CP H JR C,RANGERR ; H > D, so set max JR NZ,GOTO LD A,E ; check for range error CP L JR NC,GOTO ; E >= L, H = D RANGERR: EX DE,HL ; HL = DE = return index INC HL ; return index + 1 for error return GOTO: LD (INDEX),HL ; save index POP DE ; restore regs POP AF POP HL ; get return address PUSH DE ; save regs PUSH AF PUSH HL ; save return address LD HL,(INDEX) ; HL = index value LD D,H ; DE = HL = index value LD E,L ADD HL,HL ; HL = index * 2 ADD HL,DE ; HL = offset = index * 3 POP DE ; get return address ADD HL,DE ; HL = destination address POP AF ; get regs POP DE PUSH HL ; set address of routine LD HL,(HLSAVE) ; restore HL RET ; Save buffer DSEG ; Put in Data Segment HLSAVE: DEFS 2 ; original HL INDEX: DEFS 2 ; index entry END