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
/
SACAS3.Z80
< prev
next >
Wrap
Text File
|
2000-06-30
|
2KB
|
85 lines
;
; SYSLIB Module Name: ACASE3
; Author: Richard Conn
; SYSLIB Version Number: 3.6
; Module Version Number: 1.1
public acase3
;
; ACASE3 is a case statement processor. On input, register A contains a
; value to test against and DE contains the address of the case table.
; Unlike ACASE1 and ACASE2, the return address to ACASE3 is preserved,
; so routines can continue execution by issuing a simple RET, and control
; will resume after the call to ACASE3.
;
; MVI A,TEST ; test value
; LXI D,TABLE ; case table
; CALL ACASE3
; < instr to return to > ; control resumes here if routines RET
; ...
; TABLE:
; DB NUM$ENT ; number of entries in CASE table
; DW DEFAULT ; address to goto if no match in acase3
; DB VAL1 ; entry value 1 to test for
; DW ADDR1 ; address to goto if entry 1 matches
; DB VAL2 ; entry value 2 to test for
; DW ADDR2 ; address to goto if entry 2 matches
; ...
; DB VALN ; entry value N to test for (N = NUM$ENT)
; DW ADDRN ; address to goto if entry N matches
;
; NUM$ENT is the number of values (VAL1 .. VALN) in the case table
;
acase3:
push hl ; save HL
ld h,d ; HL=DE=case table address
ld l,e
push af ; save regs
push bc
ld b,(hl) ; number of entries
inc hl ; pt to default
ld (default),hl ; save it
inc hl ; pt to first entry
inc hl
;
; Loop through case table entries, looking for a match
;
loop:
cp (hl) ; compare
jp z,match
inc hl ; pt to next
inc hl
inc hl
dec b ; count down
jp nz,loop
;
; No match found - use default
;
ld hl,(default) ; get default
jp goto
;
; Match - use HL+1
;
match:
inc hl ; point to address
;
; Get address in HL and run routine (original return address still on stack)
;
goto:
ld a,(hl) ; get low
inc hl
ld h,(hl) ; get high
ld l,a ; HL = address
pop bc ; restore regs
pop af
ex (sp),hl ; return address on stack, HL restored
ret
;
; Storage for default address
;
default:
ds 2
end