home *** CD-ROM | disk | FTP | other *** search
- ;
- ; Z3LIB Module Name: Z3IF
- ; Author: Richard Conn
- ; Z3LIB Version Number: 1.3
- ; Module Version Number: 1.1
- ;
- public ift,iff
-
- ext getmsg
-
- ;
- ; IFT turns on the next level of IF and sets it TRUE. Return
- ; with A=0 and Zero Flag Set (Z) if IF level overflow.
- ;
- ift:
- push bc ;save BC
- ld b,0ffh ;turn on
- call ifset
- pop bc
- ret
-
- ;
- ; IFF turns on the next level of IF and sets it FALSE. Return
- ; with A=0 and Zero Flag Set (Z) if IF level overflow.
- ;
- iff:
- push bc ;save BC
- ld b,0 ;turn off
- call ifset
- pop bc
- ret
-
- ;
- ; Turn on next IF level
- ; B register is 0 if level is inactive, 0FFH is level is active
- ; Return with Z flag set if IF overflow
- ;
- ifset:
- push hl ;save regs
- push de
- push bc
- call getmsg ;pt to messages
- inc hl ;pt to IF byte
- ld a,(hl) ;get IF byte
- or a ;if no IF at all, start 1st one
- jp z,ifset1
- cp 80h ;check for overflow (8 IFs max)
- jp z,iferr
- inc hl ;pt to active IF
- and (hl) ;check to see if current IF is TRUE
- jp nz,ifset0 ;continue if so
- ld b,a ;B=0 to set next IF to FALSE
- ifset0:
- dec hl ;pt to IF level
- ld a,(hl) ;get it
- rlca ;advance to next level
- and 0feh ;only 1 bit on
- ld (hl),a ;set IF byte
- jp ifset2
- ifset1:
- inc a ;A=1
- ld (hl),a ;set 1st IF
- inc hl ;clear active IF byte
- ld (hl),0
- dec hl
- ifset2:
- ld d,a ;get IF byte
- and b ;set interested bit
- ld b,a
- inc hl ;pt to active flag
- ld a,d ;complement IF byte
- cpl
- ld d,a
- ld a,(hl) ;get active byte
- and d ;mask in only uninterested bits
- or b ;mask in complement of interested bit
- ld (hl),a ;save result
- pop bc ;restore regs
- pop de
- pop hl
- xor a ;return with NZ
- dec a
- ret
- iferr:
- pop bc ;restore regs
- pop de
- pop hl
- xor a ;set Z
- ret
-
- end