home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / vol264 / zlib1.lbr / Z3IF.Z80 < prev    next >
Encoding:
Text File  |  1986-03-23  |  1.8 KB  |  92 lines

  1. ;
  2. ; Z3LIB Module Name:  Z3IF
  3. ; Author:  Richard Conn
  4. ; Z3LIB  Version Number:  1.3
  5. ; Module Version Number:  1.1
  6. ;
  7.     public    ift,iff
  8.  
  9.     ext    getmsg
  10.  
  11. ;
  12. ;    IFT turns on the next level of IF and sets it TRUE.  Return
  13. ; with A=0 and Zero Flag Set (Z) if IF level overflow.
  14. ;
  15. ift:
  16.     push    bc        ;save BC
  17.     ld    b,0ffh        ;turn on
  18.     call    ifset
  19.     pop    bc
  20.     ret
  21.  
  22. ;
  23. ;    IFF turns on the next level of IF and sets it FALSE.  Return
  24. ; with A=0 and Zero Flag Set (Z) if IF level overflow.
  25. ;
  26. iff:
  27.     push    bc        ;save BC
  28.     ld    b,0        ;turn off
  29.     call    ifset
  30.     pop    bc
  31.     ret
  32.  
  33. ;
  34. ; Turn on next IF level
  35. ;   B register is 0 if level is inactive, 0FFH is level is active
  36. ;   Return with Z flag set if IF overflow
  37. ;
  38. ifset:
  39.     push    hl        ;save regs
  40.     push    de
  41.     push    bc
  42.     call    getmsg        ;pt to messages
  43.     inc    hl        ;pt to IF byte
  44.     ld    a,(hl)        ;get IF byte
  45.     or    a        ;if no IF at all, start 1st one
  46.     jp    z,ifset1
  47.     cp    80h        ;check for overflow (8 IFs max)
  48.     jp    z,iferr
  49.     inc    hl        ;pt to active IF
  50.     and    (hl)        ;check to see if current IF is TRUE
  51.     jp    nz,ifset0    ;continue if so
  52.     ld    b,a        ;B=0 to set next IF to FALSE
  53. ifset0:
  54.     dec    hl        ;pt to IF level
  55.     ld    a,(hl)        ;get it
  56.     rlca            ;advance to next level
  57.     and    0feh        ;only 1 bit on
  58.     ld    (hl),a        ;set IF byte
  59.     jp    ifset2
  60. ifset1:
  61.     inc    a        ;A=1
  62.     ld    (hl),a        ;set 1st IF
  63.     inc    hl        ;clear active IF byte
  64.     ld    (hl),0
  65.     dec    hl
  66. ifset2:
  67.     ld    d,a        ;get IF byte
  68.     and    b        ;set interested bit
  69.     ld    b,a
  70.     inc    hl        ;pt to active flag
  71.     ld    a,d        ;complement IF byte
  72.     cpl
  73.     ld    d,a
  74.     ld    a,(hl)        ;get active byte
  75.     and    d        ;mask in only uninterested bits
  76.     or    b        ;mask in complement of interested bit
  77.     ld    (hl),a        ;save result
  78.     pop    bc        ;restore regs
  79.     pop    de
  80.     pop    hl
  81.     xor    a        ;return with NZ
  82.     dec    a
  83.     ret
  84. iferr:
  85.     pop    bc        ;restore regs
  86.     pop    de
  87.     pop    hl
  88.     xor    a        ;set Z
  89.     ret
  90.  
  91.     end
  92.