Skip to content

Flags for LD A, I #19

Description

@PsychedelicPalimpsest

There seems to be a little confusion about these. These flip flops are simultaneously set or reset by the EI and DI instructions. IFF1 determines whether interrupts are allowed, but its value cannot be read. The value of IFF2 is copied to the P/V flag by LD A,I and LD A,R. When an NMI occurs, IFF1 is reset, thereby disallowing further [maskable] interrupts, but IFF2 is left unchanged.

From the Interrupt flip-flops IFF1 and IFF2 section of https://worldofspectrum.org/z88forever/dn327/z80undoc.htm

Based on my own testing, this seems to be true (as least on my model of TI84plus)

Image

Here is my test code (with the z88dk c compiler):

// Low byte is with interupts enabled, high is with them disabled
int test_ldai() __z88dk_sdccdecl __naked {
  #asm
  di

  ld bc, $0

  push bc 
  pop af ; Reset ALL FLAGS

  ld a, i
  push af ; Capture flags
  ei

  push bc 
  pop af ; Reset ALL FLAGS


  ld a, i
  push af


  pop bc  ; Flags with interupts
  pop hl  ; Flags without interupts
  ld h, c
  ret
  #endasm
}

// Low byte is with interupts enabled, high is with them disabled
int test_ldar() __z88dk_sdccdecl __naked {
  #asm
  di

  ld bc, $0

  push bc 
  pop af ; Reset ALL FLAGS

  ld a, r
  push af ; Capture flags
  ei

  push bc 
  pop af ; Reset ALL FLAGS


  ld a, r
  push af


  pop bc  ; Flags with interupts
  pop hl  ; Flags without interupts
  ld h, c
  ret 
  #endasm
}

int main() {
  int out = test_ldai();
  printf("LD a, i:\nEI: %x DI: %x\n", out&0xff, (out >> 8) & 0xff);
  out = test_ldar();
  printf("LD a, r:\nEI: %x DI: %x\n", out&0xff, (out >> 8) & 0xff);

}

A fun little discovery, and might even be useful for somebody.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions