Domanda

I want to use IM 1 interrupt mode on Z80.

In Interrupt mode 1 processor jumps to 38h address in memory(am I right?) and then continues interrupt. How can I specify this in my code? I have read about:

defs [,] ds [,] This pseudo instruction inserts a block of bytes into the code segment

I need some sample source code.

Kind Regards

Rafał R.

È stato utile?

Soluzione

First off, I don't have a Z80 in front of me.

Referencing: Z80asm directives

Use org to 'manually' locate a 'function' at a specified address. So, to write an IM1 handler:

org 0x38
; IM1 handler 
ld a, 100 ; ... whatever
ret

Also, I'm not sure of your normal starting address is, but the original Z80s started at location 0. If this is the case you should JMP past the 0x38 handler very early in your code. (You only have 56 bytes to play with)

Happy Coding!

Altri suggerimenti

In IM 1, upon spotting a pending interrupt (which is sampled on the rising edge of the last cycle before the end of an opcode; the IRQ line is just sampled, unlike NMI) IFF1 and 2 are cleared and an RST 38h is executed. So you should end up with the PC at 0x38, interrupts disabled and the old program counter on the top of the stack. You'll want to do whatever you have to do to respond to the interrupt, then perform an EI, RET or EI, RETI (there being no difference here because the two IFF flags have the same value following the interrupt acknowledge).

On a Z80 the PC is set to 0 upon power up or reset so probably you already have some control over the code down at that end of memory. Exact syntax depends on your assembler, but you probably want something like:

org 0

; setup initial state here, probably JP somewhere at the end
; possibly squeeze in another routine if you've the space

org 0x38
; respond to interrupt
EI
RET

I have figured out what to do when you are not starting from 0h:

org 1800h
START: ;Do the start, but It can't take more than 38 instructions
LD SP, 0x2000 ;Initialize SP!
JP MAIN ;Continue to rest of the program

ds 0x1838-$,0 ;Allocate block of memory for interrupt handler
INT:
  ;interrupt sub
  LD E, 0
  LD A, E
  OUT (066), A
  EI
  RETI

ds 0x1840-$,0 ;Alloc space for the rest of program.
MAIN:
  ;Rest of program here

As far as you make it like this, processor will put the JP 01838h instruction at the address 038h. So the handler is right. Also, remember to initialize stack pointer. If you doesnt, you will not be able to return from interrupt handler to program.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top