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

  1. ;
  2. ; SYSLIB Module Name: ACASE1
  3. ; Author: Richard Conn
  4. ; SYSLIB Version Number: 3.6
  5. ; Module Version Number: 1.1
  6.  
  7.     public    acase1
  8.  
  9. ;
  10. ; ACASE1 is a acase1 statement processor.  On input, register A contains a
  11. ; value to test against:
  12. ;
  13. ;    MVI    A,TEST    ; test value
  14. ;    CALL    ACASE1
  15. ;    DB    NUM$ENT    ; number of entries in CASE table
  16. ;    DW    DEFAULT    ; address to goto if no match in acase1
  17. ;    DB    VAL1    ; entry value 1 to test for
  18. ;    DW    ADDR1    ; address to goto if entry 1 matches
  19. ;    DB    VAL2    ; entry value 2 to test for
  20. ;    DW    ADDR2    ; address to goto if entry 2 matches
  21. ;    ...
  22. ;    DB    VALN    ; entry value N to test for (N = NUM$ENT)
  23. ;    DW    ADDRN    ; address to goto if entry N matches
  24. ;
  25. ; NUM$ENT is the number of values (VAL1 .. VALN) in the case table
  26. ;
  27. acase1:
  28.     ex    (sp),hl        ; return address in HL
  29.     push    af    ; save regs
  30.     push    bc
  31.     ld    b,(hl)    ; number of entries
  32.     inc    hl    ; pt to default
  33.     ld    (default),hl    ; save it
  34.     inc    hl    ; pt to first entry
  35.     inc    hl
  36. ;
  37. ; Loop through case table entries, looking for a match
  38. ;
  39. loop:
  40.     cp    (hl)    ; compare
  41.     jp    z,match
  42.     inc    hl    ; pt to next
  43.     inc    hl
  44.     inc    hl
  45.     dec    b    ; count down
  46.     jp    nz,loop
  47. ;
  48. ; No match found - use default
  49. ;
  50.     ld    hl,(default)    ; get default
  51.     jp    goto
  52. ;
  53. ; Match - use HL+1
  54. ;
  55. match:
  56.     inc    hl    ; point to address
  57. ;
  58. ; Get address in HL and return
  59. ;
  60. goto:
  61.     ld    a,(hl)    ; get low
  62.     inc    hl
  63.     ld    h,(hl)    ; get high
  64.     ld    l,a    ; HL = address
  65.     pop    bc    ; restore regs
  66.     pop    af
  67.     ex    (sp),hl        ; return address on stack, HL restored
  68.     ret
  69. ;
  70. ; Storage for default address
  71. ;
  72. default:
  73.     ds    2
  74.  
  75.     end
  76.