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 / SBGO2.Z80 < prev    next >
Text File  |  2000-06-30  |  1KB  |  56 lines

  1. ;
  2. ; SYSLIB Module Name: BGOTO2
  3. ; Author: Richard Conn
  4. ; SYSLIB Version Number: 3.6
  5. ; Module Version Number: 1.1
  6.  
  7.     public    bgoto2
  8.  
  9. ;
  10. ; BGOTO2 is a computed GOTO.  When called, register A = index of following
  11. ; jump to branch to and register B = maximum index value, as indicated:
  12. ;
  13. ;    MVI    A,INDEX    ; zero-relative
  14. ;    MVI    B,2    ; maximum index value
  15. ;    CALL    BGOTO2
  16. ;    JMP    ADDR0    ; IF A=0
  17. ;    JMP    ADDR1    ; IF A=1
  18. ;    JMP    ADDR2    ; IF A=2
  19. ;    <next instruction>    ; 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. bgoto2:
  31.     ex    (sp),hl    ; get address of routines, save HL
  32.     push    de    ; save regs
  33.     push    af
  34.     push    hl    ; save return address
  35.     cp    b    ; test for range error
  36.     jp    c,goto    ; OK if A < B
  37.     jp    z,goto    ; OK if A = B
  38.     ld    a,b    ; set A = error offset (B+1)
  39.     inc    a
  40. goto:
  41.     ld    h,0
  42.     ld    l,a
  43.     ex    de,hl    ; index in DE
  44.     ld    hl,0
  45.     add    hl,de    ; HL = index
  46.     add    hl,hl    ; HL = index * 2
  47.     add    hl,de    ; HL = index * 3
  48.     pop    de    ; get return address
  49.     add    hl,de    ; point to jump in HL
  50.     pop    af    ; get regs
  51.     pop    de
  52.     ex    (sp),hl    ; restore HL, set address of routine
  53.     ret
  54.  
  55.     end
  56.