Re: A92: Strange interrupt behavior
[Prev][Next][Index][Thread]
Re: A92: Strange interrupt behavior
NDStein@aol.com wrote:
>
> I'm working on the chip8 emulator for the TI-92/92+/89. It requires a delay
> timer that runs at 60 Hz, which I implemented with interrupts. This is my
> first time working with interrupts. I looked at other people's code and found
> out how it works, so I implemented it in mine, and the delay works correctly.
> I remembered to back up all registers used in the interrupt function at the
> beginning of the function and restore them at the end. However, it causes
> random data to be written to the screen and after a few minutes of sitting
> there with the random data being written to the screen (along with the normal
> data) it will crash with an address error. I am really lost as to why this is
> happening, and as I couldn't find a very good reference on interrupts, I
> decided to pose the question here. This is my interrupt handler routine:
> DelayRegTimer:
> movem d0/a0,-(a7)
> lea dtimer(PC),a0
> move.w (a0),d0
> cmp.w #0,d0
> beq AfterDec
> sub.w #1,d0
> move.w d0,(a0)
> AfterDec:
> movem (a7)+,d0/a0
> rte
>
> It is supposed to decrement dtimer if it's not zero, and leave it alone if it
> is, and then return to wherever the program was at before. Can you tell me
> why this causes the random data to be written to the screen?
Why is <dtimer> accessed through an adress register? Why not use it as a
variable? Speed?
One thing you could try is to write movem.l instead of movem, since if
movem:s default datalength is a word you'll get the wrong adress to the
variable.
Also, a minor optimization: you can remove the line "cmp.w #0,d0"
completely - the flags are set when moving data into d0 :)
At least that's what I remember, haven't touched 68k in 4 months...
References: