[A83] Re: interrupt with shutdown


[Prev][Next][Index][Thread]

[A83] Re: interrupt with shutdown




> From: "SUCKER from the old days" <sucker_pvn@hotmail.com>
>
> With the password program I have right now, this piece
> of code works fine for shutting the calc down. But not
> in an interrupt. I don't get it! It's just a standard
> way of shutting it down, I guess.
>
> ld a,1
> out (3),a
> halt

Well, that's for outside interrupt routines. Turning the calculator on/off
has a lot to do with interrupts, so if you want to the turn the calc off
from within an interrupt routine, you have to take care of a lot of things.

One thing you must understand about interrupts is that they are actually
just signals for the Z80 which tells it to jump to some specific address.
Several Z80 external devices can generate such signals. In our calculator
one of those devices is a timer which generates pulses at 120/130Hz. But in
your case that's not the one we care about. You only want to check for
on-key interrupts, signals that tell the user has pressed on. Who cares if
there's something that generates signals at 130Hz. That's for routines that
have to repeat something, like greyscale routines.

So every interrupt that happens, your routine first checks if it's an on-key
interrupt and only then it continues. Otherwise it jumps to the TIOS
standard interrupt handler, which takes care of handling a specific kind of
interrupt in a proper way.

If an interrupt was an on-key interrupt, you check if 2nd has been set. If
so, turn off calc. If not, then just jump to the TIOS standard interrupt
handler which will further take care of things. (like setting the bit that
indicates an on-key interrupt has occured so that the TIOS can generate an
ERR:Break or stop drawing a graph, or...)

How the shutdown itself works I've already explained, but once again in
short. You HALT the calc so that it turns into low power mode and waits for
an interrupt. The problem is that our calc has some device that generates
signals at 130Hz, so the calc would immediately come out its low power
state. What do we do to fix that problem? Just simply turn that sort of
interrupts off and only allow the on-key to generate an interrupt. And that
is a very good solution, because now the calc will keep waiting in low power
mode until the user presses the on-key.

Tijl Coosemans
http://tijl.studentenweb.org/

PS: Have you tested that the LD A,8 \ OUT (3),A is really necessary?


> interrupt_start:
> ;---------------
>
>     ex af,af'
>     exx
>     ld a,($800A)
>     cp $11
>     jr nc,resume
> shutdown:
>     res shift2nd,(iy+shiftflags)
>     ld a,$74
>     ld ($800A),a

>     ld a,8
>     out (3),a

>     ld a,1
>     out (3),a
>     exx
>     ex af,af'
>     ei
>     halt
>     ret
> resume:
>     in a,(3)
>     bit 0,a
>     jr z,stop
>     bit shift2nd,(iy+shiftflags)
>     jr nz,shutdown
> stop:
>     jp    003Ah
>
> ;------------
> interrupt_end:





References: