home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / cpm / zcpr33 / syslbsrc.lbr / SBGO1.ZY0 / SBGO1.ZY0
Text File  |  1989-09-17  |  2KB  |  72 lines

  1. ;    TITLE    "SBGO1 - Syslib 4.0"
  2.     NAME    ('BGOTO1')
  3. ;=================================================================
  4. ;   The Libraries, Version 4, (C) 1989 by Alpha Systems Corp.
  5. ;-----------------------------------------------------------------
  6. ; Author  : Harold F. Bower
  7. ;        Derived from SBGO1.Z80 Ver 1.1 by Richard Conn
  8. ; Date    : 17 Sep 89
  9. ; Version : 1.2
  10. ; Module  : SBGO1
  11. ; Abstract:  This module contains the routine BGOTO1 which is a
  12. ;    computed GOTO.  It uses a table of DEFW xx addresses and
  13. ;    selects the proper address to execute based on the con-
  14. ;    tents of an 8-bit register.  A control value is also set
  15. ;    by the user who is responsible for range and error
  16. ;    checking.  Is is used as:
  17. ;
  18. ;      LD    A,INDEX        ; zero-relative
  19. ;      LD    B,2        ; max value allowed
  20. ;      CALL    BGOTO1
  21. ;      DEFW    ADDR0        ; IF A=0
  22. ;      DEFW    ADDR1        ; IF A=1
  23. ;      DEFW    ADDR2        ; IF A=2
  24. ;      <error instructions>    ; IF A>B
  25. ;      ...
  26. ;    ADDR0:            ; COME HERE IF A=0
  27. ;      ...
  28. ;    ADDR1:            ; COME HERE IF A=1
  29. ;      ...
  30. ;    ADDR2:            ; COME HERE IF A=2
  31. ;      ...
  32. ;  Revision:
  33. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  34. ; Module Entry Points
  35.  
  36.     PUBLIC        BGOTO1
  37.  
  38.     .Z80
  39.     CSEG
  40. ;===============================================================
  41. ; NAME - BGOTO1
  42. ; Entry:  A - Contains the Zero-based index into address table
  43. ;      B - Contains the maximum value allowed in A
  44. ; Exit : - N/A
  45. ; Uses : - None
  46. ; Special Requirements: None
  47. ;===============================================================
  48.  
  49. BGOTO1:    EX    (SP),HL        ; get address of routines, save HL
  50.     PUSH    DE        ; save regs
  51.     PUSH    AF
  52.     CP    B        ; test for range error
  53.     JR    C,GOTO        ; OK if A < B
  54.     JR    Z,GOTO        ; OK if A = B
  55.     LD    A,B        ; set A = error offset (B+1)
  56.     INC    A
  57. GOTO:    LD    D,0
  58.     LD    E,A        ; index in DE
  59.     EX    DE,HL        ; index in HL, return address in DE
  60.     ADD    HL,HL        ; double index to compute offset
  61.     ADD    HL,DE        ; point to jump in HL
  62.     LD    A,(HL)        ; get low
  63.     INC    HL
  64.     LD    H,(HL)        ; get high
  65.     LD    L,A        ; HL = address to return to
  66.     POP    AF        ; get regs
  67.     POP    DE
  68.     EX    (SP),HL        ; restore HL, set address of routine
  69.     RET
  70.  
  71.     END
  72.