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 / SDGO2.Z80 < prev    next >
Text File  |  2000-06-30  |  2KB  |  70 lines

  1. ;
  2. ; SYSLIB Module Name: DGOTO2
  3. ; Author: Richard Conn
  4. ; SYSLIB Version Number: 3.6
  5. ; Module Version Number: 1.1
  6.  
  7.     public    dgoto2
  8.  
  9. ;
  10. ; DGOTO2 is a computed GOTO.  When called, register pair HL = index of
  11. ; following address to branch to and register pair DE = maximum value
  12. ; allowed, as indicated:
  13. ;
  14. ;    LXI    H,INDEX    ; zero-relative
  15. ;    LXI    D,2    ; max value allowed
  16. ;    CALL    DGOTO2
  17. ;    JMP    ADDR0    ; IF HL=0
  18. ;    JMP    ADDR1    ; IF HL=1
  19. ;    JMP    ADDR2    ; IF HL=2
  20. ;    <error instructions>    ; IF HL > DE
  21. ;    ...
  22. ; ADDR0:        ; COME HERE IF HL=0
  23. ;    ...
  24. ; ADDR1:        ; COME HERE IF HL=1
  25. ;    ...
  26. ; ADDR2:        ; COME HERE IF HL=2
  27. ;    ...
  28. ;
  29. dgoto2:
  30.     ld    (hlsave),hl    ; save HL
  31.     push    af        ; save regs
  32.     push    de
  33.     ld    a,d        ; check for range error
  34.     cp    h
  35.     jp    c,rangerr    ; H > D, so set max
  36.     jp    nz,goto
  37.     ld    a,e        ; check for range error
  38.     cp    l
  39.     jp    nc,goto        ; E >= L, H = D
  40. rangerr:
  41.     ex    de,hl        ; HL = DE = return index
  42.     inc    hl        ; return index + 1 for error return
  43. goto:
  44.     ld    (index),hl    ; save index
  45.     pop    de        ; restore regs
  46.     pop    af
  47.     pop    hl        ; get return address
  48.     push    de        ; save regs
  49.     push    af
  50.     push    hl        ; save return address
  51.     ld    hl,(index)    ; HL = index value
  52.     ld    d,h        ; DE = HL = index value
  53.     ld    e,l
  54.     add    hl,hl        ; HL = index * 2
  55.     add    hl,de        ; HL = offset = index * 3
  56.     pop    de        ; get return address
  57.     add    hl,de        ; HL = destination address
  58.     pop    af        ; get regs
  59.     pop    de
  60.     push    hl        ; set address of routine
  61.     ld    hl,(hlsave)    ; restore HL
  62.     ret
  63. ;
  64. ; Save buffer
  65. ;
  66. hlsave:    ds    2    ; original HL
  67. index:    ds    2    ; index entry
  68.  
  69.     end
  70.