; TITLE "SDGO1 - Syslib 4.0" NAME ('DGOTO1') ;================================================================= ; The Libraries, Version 4, (C) 1989 by Alpha Systems Corp. ;----------------------------------------------------------------- ; Author : Harold F. Bower ; Derived from SDGO1.Z80 Ver 1.1 by Richard Conn ; Date : 17 Sep 89 ; Version : 1.2 ; Module : SDGO1 ; Abstract: This module contains the routine DGOTO1 which is a ; computed GOTO based on 16-bit values as opposed to the ; AGOTO family. Both the index value and a maximum legal ; value are passed to the routine. It is used as: ; ; LD HL,INDEX ; zero-relative ; LD DE,2 ; max value allowed ; CALL DGOTO1 ; DEFW ADDR0 ; IF HL=0 ; DEFW ADDR1 ; IF HL=1 ; DEFW 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 DGOTO1 .Z80 CSEG ;=============================================================== ; NAME - DGOTO1 ; Entry: (Stack) - Contains the address table starting address ; HL - Zero-relative index into address table ; DE - Maximum permissable value of index ; Exit : - N/A ; Uses : - None (all parameters preserved for destination) ; Special Requirements: None ;=============================================================== DGOTO1: 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 ; get regs POP AF POP HL ; get return address PUSH DE ; save regs PUSH AF EX DE,HL ; return address in DE LD HL,(INDEX) ; HL = index value 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 AF ; get regs POP DE PUSH HL ; set address of routine LD HL,(HLSAVE) ; restore HL RET ; Save buffers DSEG ; Put in Data Segment HLSAVE: DEFS 2 ; original HL INDEX: DEFS 2 ; index value END