A86: Re: turning off the calc


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

A86: Re: turning off the calc




Excellent question.  There is a wonderful file that everyone should read:

http://www.ticalc.org/pub/text/calcinfo/ti-ports.txt

(I'd assume everyone's read the 86ports.txt, ti-prot.txt, z80time.txt,
etc...all the stuff in /pub/text/z80/ is mandatory reading for calc
programming.)

Notice the section on port 3 (on status, lcd power):

Bit 3 = 1: turn LCD on
        0: turn LCD off
Bit 2 = 1: do not mask timer interrupts (200Hz)
        0: mask timer interrupts
Bit 1 = 1: set bit 1 LCD status (on)
        0: clear bit 1 LCD status (off)
Bit 0 = 1: do not mask ON key interrupts
        0: mask ON key interrupts

Now, a standard off routine that stays in the program (I think Bryonic shell
uses a routine like this):

power_off:
 ld a,1
 out (3),a
 halt
 ld a,11
 out (3),a
 res onInterrupt,(iy+onflags)

Now, the EI is just in case interrupts were disabled, otherwise it'd never
get out of the halt (actually, I don't think it'd matter, since I think ON
is an NMI interrupt, but that's another story).  That's why this routine
doesn't have/need it.

The first thing the routine does is to set bit 0 and clear all the other
bits.  That's going to setup the hardware as follows:

0  3 = turn lcd off
0  2 = mask (disable) timer interrupts (no ints 200 times a second...like
DI)
1  1 = clear lcd status bit (lcd is off)
0  0 = do not mask on key interrupts

This turns off the lcd, tells the hardware that it's off (not exactly sure
why that's need or what it does, but you need to do it), stops interrupts
from occuring ~200 times a second and enables the on key.

This is why the interrupts don't break out of the HALT--because they don't
occur!

So, when you press on, that generates an interrupt (nmi I believe) that
jumps to $0066.  The rom sets some stuff (like on pressed), and returns to
the halt.  Then, clean-up is done.

11d = 1011b

Thus, it sets up the hardware for the calc to be on:

  3 = turn lcd on
  2 = do not mask (enable) timer interrupts (ints happen 200 times a second
now)
  1 = set lcd status bit (lcd is on)
  0 = do not mask on key interrupts (still enable on key to be pressed?)

Now, I think the reason you'd want to mask on key interrupts is that since
they're non maskable, you wouldn't want them to be called again while it's
inside the nmi handler (is that possible?  key bounce?).

The last part just clears the on interrupt flag, so the OS doesn't think
that the on interrupt occured.  That way, you don't get the "Err: Break"
when exiting an asm program.

Hope this cleared some stuff up...this could be a whole tutorial :)

> i have seen several routines that turn the calc off
> they turn off the screen then do  ei \ halt
> how come the interrupts that occur at 200 Hz dont break the halt?




Follow-Ups: References: