home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / ZSYS / SIMTEL20 / SYSLIB / SLIB1.LBR / SBGO1.Z80 < prev    next >
Text File  |  2000-06-30  |  1KB  |  55 lines

  1. ;
  2. ; SYSLIB Module Name: BGOTO1
  3. ; Author: Richard Conn
  4. ; SYSLIB Version Number: 3.6
  5. ; Module Version Number: 1.1
  6.  
  7.     public    bgoto1
  8.  
  9. ;
  10. ; BGOTO1 is a computed GOTO.  When called, register A = index of following
  11. ; address to branch to and register B = maximum value allowed, as indicated:
  12. ;
  13. ;    MVI    A,INDEX    ; zero-relative
  14. ;    MVI    B,2    ; max value allowed
  15. ;    CALL    BGOTO1
  16. ;    DW    ADDR0    ; IF A=0
  17. ;    DW    ADDR1    ; IF A=1
  18. ;    DW    ADDR2    ; IF A=2
  19. ;    <error instructions>    ; IF A>B
  20. ;    ...
  21. ; ADDR0:        ; COME HERE IF A=0
  22. ;    ...
  23. ; ADDR1:        ; COME HERE IF A=1
  24. ;    ...
  25. ; ADDR2:        ; COME HERE IF A=2
  26. ;    ...
  27. ;
  28. ; No error or range checking is done
  29. ;
  30. bgoto1:
  31.     ex    (sp),hl    ; get address of routines, save HL
  32.     push    de    ; save regs
  33.     push    af
  34.     cp    b    ; test for range error
  35.     jp    c,goto    ; OK if A < B
  36.     jp    z,goto    ; OK if A = B
  37.     ld    a,b    ; set A = error offset (B+1)
  38.     inc    a
  39. goto:
  40.     ld    d,0
  41.     ld    e,a    ; index in DE
  42.     ex    de,hl        ; index in HL, return address in DE
  43.     add    hl,hl    ; double index to compute offset
  44.     add    hl,de    ; point to jump in HL
  45.     ld    a,(hl)    ; get low
  46.     inc    hl
  47.     ld    h,(hl)    ; get high
  48.     ld    l,a    ; HL = address to return to
  49.     pop    af    ; get regs
  50.     pop    de
  51.     ex    (sp),hl    ; restore HL, set address of routine
  52.     ret
  53.  
  54.     end
  55.