Zilog Z80 - 如何使用中断模式 1(IM 1 指令)

发布于 2024-12-17 10:49:39 字数 219 浏览 4 评论 0原文

我想在 Z80 上使用 IM 1 中断模式。

在中断模式 1 中,处理器跳转到内存中的 38h 地址(我是对的吗?),然后继续中断。我如何在我的代码中指定这一点? 我读过:

defs[,]ds[,]这个伪 指令将字节块插入代码段

我需要一些示例源代码。

亲切的问候

Rafał R.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

小巷里的女流氓 2024-12-24 10:49:40

首先,我面前没有Z80。

参考:Z80asm指令

使用org“手动”在指定地址定位“函数” 。
因此,要编写 IM1 处理程序:

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

另外,我不确定您的正常起始地址是,但原始 Z80 从位置 0 开始。如果是这种情况,您应该 JMP 越过 0x38 处理程序非常 在代码的早期。 (您只有 56 个字节可以玩)

快乐编码!

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!

你怎么敢 2024-12-24 10:49:40

在 IM 1 中,一旦发现待处理中断(在操作码结束前的最后一个周期的上升沿进行采样;与 NMI 不同,只是对 IRQ 线进行采样),IFF1 和 2 被清除,并且 RST 38h 被执行。所以你最终应该看到 PC 位于 0x38,中断被禁用,旧程序计数器位于堆栈顶部。您需要做任何您必须做的事情来响应中断,然后执行 EI, RETEI, RETI (这里没有区别,因为这两个IFF 标志在中断应答后具有相同的值)。

在 Z80 上,PC 在加电或重置时设置为 0,因此您可能已经对内存末端的代码进行了一些控制。确切的语法取决于您的汇编器,但您可能想要类似的东西:

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

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
裂开嘴轻声笑有多痛 2024-12-24 10:49:40

我已经弄清楚当你不从 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

只要你这样做,处理器就会把 JP 01838h 指令放在地址 038h 处。
所以,处理者是对的。另外,请记住初始化堆栈指针。如果不这样做,您将无法从中断处理程序返回到程序。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文