[A83] Re: Calculator power-off woes


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

[A83] Re: Calculator power-off woes



Thanks for all your help guys.

What I found is that the TI-OS interrupt needs to occur for the calc
shutdown to work properly.  It isn't enough just to ld a,1\out (3),a .  It
wasn't enough to just rst 38h because the halts *inside* the TI-OS interrupt
routine called my im 2 interrupt.  Plus, the ON key needed to be debounced
with my method, otherwise 2nd+off just turns the calc off for a fraction of
a second.

This is what I eventually did and it worked beautifully:

...
ichkon: call    ondebounce-interrupt_start+8282h
        ld      a,8
        out     (3),a
        ld      a,1
        out     (3),a           ;power off LCD, mask out timer interrupts
        im      1  ;<--------------
        ei
        exx
        ex      af,af'
        halt
        di                      ;calc is now on
        res     onInterrupt,(iy+onFlags)
        exx
        ex      af,af'
        im      2  ;<-------------
        call    ondebounce-interrupt_start+8282h
...
ondebounce:                     ;Wait for on-key to be released.
db0:    ld      b,0FFh
db1:    in      a,(3)           ;*COOL* Loop debounces switch.
        and     %00001000
        jr      z,db0
        djnz    db1
        ret
...

> > turnoff:
> >  res   pwrflag
> >  ex    af,af'
> >  exx
> >  push  af
> >  ld    a,01h
> >  ei
> >  out   (03h),a
> >  halt            ; Don't you feel that this instruction shouldn't be in
the interrupt routine?
> >  di
> >  pop   af
> >  exx
> >  ex    af,af'
> >
> What halt does is waiting for an interrupt to occur. However, since you
> put it in the middle of your interrupt routine, no IT's will be accepted.
> EI in itself isn't enough to reactivate them, you must acknowledge that
> you handled the IT by outting some values to port 3 and returning from it
> using RETI:
>
> Interrupt:
>  ex af,af'
>  exx
>
>  ... ; your IT routine
>
>  ld a,8
>  out (3),a
>  ld a,15
>  out (3),a
>  exx
>  ex af,af'
>  ei
>  reti
>
> If you want to arrive at a halt after your IT, you can do some tricks
> with the return address, like this:
>
> HaltLabel:
>  halt
>  jp OldValue ; This will be overwritten
>
> ...
>
> Interrupt:
>  ex af,af'
>  exx
>
>  ... ; your IT routine
>
> ; Here we assume that you want to go into halt after returning:
>  pop hl
>  ld (HaltLabel+2),hl ; the address we'll jump to after the halt:
>  continuing execution
>  ld hl,HaltLabel
>  push hl ; so RETI will jump to HaltLabel
>  ld a,8
>  out (3),a
>  ld a,15
>  out (3),a
>  exx
>  ex af,af'
>  ei
>  reti
>
> This is just an idea, the details are up to you.
>
> PG
>
> -- 
> http://www.fastmail.fm - The way an email service should be
>
>



References: