Lesson 11: Ports
What is a port? Well, a port is a way of communicating with the different pieces of hardware. On the TI-85 there are 8 ports, 0-7. To communticate, we use the commands in and out.
IN
The basic synatx is this: IN reg,(port)
Reg: an 8 bit register to store the retrieved data in.
Usually A.
port: either a nubmer 0-7 or C.
Not the ()'s around port are REQUIRED.
There is a catch to all of this: If you use a nubmer for the port, you must use A as the register. If you store what port is to be used in C and then do it, you are free to use any register for the first argument.
OUT
Now just to make things weird, the arguments are listed in the other order for out. This will take the data from an 8 bit register and put it at the port for its use. So, the syntax looks like this:
OUT (port),reg
If you think about it, it looks a lot like LD.
Now that we know how to get and send data to ports, now all we
need is to know how to interpret the data.
To do that we use the BIT command.
What it does is compares a certain bit in a register and sets the zero flag is the bit is 0, clears is when it is 1.
It looks like BIT bit,reg.
bit is a number 0-7. Reg is the register in
whitch to compare that bit.
Unfortunatley, BIT is a bit of a pain. You must ALWAYS use a
number for bit, you cannot use a register.
I belive that bit 7 in a byte is the leftmost bit. meaning if a=%10001000, a bit 0,a would set the zero flag.
I guess the easiest way to do this is to go by, port by port. I will tell you what each port does and what bits do what.
This data is copied directly from TI-PORTS.TXT
Bitmap Terminology
1 Set bit
0 Clear bit
. Used bit (1 or 0)
X Unused bit
? Bit of unknown use
All numbers are in hexadecimal, except where noted with (d).
Port 0: Video Buffer Offset (write only)
WRITE
X?...... 00-3F: LCD shows memory at 100h*(C0+this value)
Example: using a value of 3C, the LCD shows the normal memory,
FC00
Note: The ROM uses 7C, although it appears to give the same
result.
Port 1: Keypad (Read/Write)
READ
Bit 7 = 1: key pressed is one of { ALPHA x-VAR DEL MORE }
Bit 6 = 1: key pressed is one of { GRAPH STAT PRGM CUSTOM CLEAR
EXIT }
Bit 5 = 1: key pressed is one of { LOG SIN COS TAN ^ 2nd }
Bit 4 = 1: key pressed is one of { LN EE ( ) / F1 }
Bit 3 = 1: key pressed is one of { UP xý 7 8 9 * F2 }
Bit 2 = 1: key pressed is one of { RIGHT , 4 5 6 - F3 }
Bit 1 = 1: key pressed is one of { LEFT STO> 1 2 3 + F4 }
Bit 0 = 1: key pressed is one of { DOWN 0 . (-) ENTER F5}
WRITE
X....... 00-7F: prevents set of keys from being read
Bit 6 = 1: masks out { F5 F4 F3 F2 F1 2nd EXIT MORE }
Bit 5 = 1: masks out { STO> , xý LN LOG GRAPH ALPHA }
Bit 4 = 1: masks out { 0 1 4 7 EE SIN STAT x-VAR }
Bit 3 = 1: masks out { . 2 5 8 { COS PRGM DEL }
Bit 2 = 1: masks out { (-) 3 6 9 ) TAN CUSTOM }
Bit 1 = 1: masks out { ENTER + - * / ^ CLEAR }
Bit 0 = 1: masks out { DOWN LEFT RIGHT UP }
Port 2: Contrast Level (Wirte only)
WRITE
XX...... 00-1F: sets contrast to value
Port 3: Power statuses (Read/Write)
READ
0000....
Bit 3 = 1: ON not pressed
0: ON pressed now
Bit 2 = 1: ? \__ timer? interrupt indicator? what?
0: ? /
Bit 1 = 1: LCD is on
0: LCD is off
Bit 0 = 1: ON has been pressed, but may not be now
0: ON has not been pressed
WRITE
XXX?.?..
Bit 3 = 1: turn LCD on
0: turn LCD off
Bit 2 = 1: do not mask bit 2
0: mask bit 2
Bit 1 = 1: set bit 1 LCD status (on)
0: clear bit 1 LCD status (off)
Bit 0 = 1: do not mask bit 0
0: mask bit 0
Note: Do not exit a program with bits 0 and 1
clear. The TI-85 freezes.
Port 4: Video Buffer Width (Read/Write)
WRITE
XXX....?
Bits 4 and 3 = 00: 10-byte wide buffer
01: 12-byte wide buffer
10: 16-byte wide buffer (normal)
11: 20-byte wide buffer
Bits 2 and 1 = 00: very low resistance: black screen and frozen
calculator
01: low resistance: dark screen, top half of screen is
doubled in lower half, and interrupts go faster
10: less-than-normal resistance: slightly darker than normal
screen, top 1/4 of screen is doubled in bottom 1/4,
slightly faster interrupts
11: normal
Bit 0 = 1: freeze \_ don't know what this does
0: function /
Port 5: ROM Page (Read/Write)
READ
00000...
Returns current memory page (0-7)
WRITE
XXXXX... 0-7: sets memory page (accessed from 4000 to 7FFF) to
value
Port 6: Power Mode (Read/Write)
READ
???????. returns value written
WRITE
???????.
Bit 0 = 1: normal power
0: low power
Note: I don't know much about this port. To put
the processor in low-power mode, first turn off the LCD (port 3),
then write 40h to this port. To put the processor back in
normal-power mode, write 41h to this port, then turn the LCD back
on.
Port 7: The Illustrious Link Port (Read/Write (of course))
READ
0000....
Bits 3 and 2 are the same as they were in the value last written.
Bit 1 = 1: white is positive, but circuit is open
0: white is positive and electons are flowing,
or white is negative
Bit 0 = 1: red wire is positive, but circuit is open
0: red is positive and electons are flowing,
or red is negative
WRITE
??....??
Bits 7 & 6 : have an effect, but don't seem to be important
Bit 5 = 1 : white wire is negative or off
0 : white wire is negative or positive
Bit 4 = 1 : red wire is negative or off
0 : red wire is negative or positive
Bit 3 = 1 : white wire is negative
0 : white wire is positive or off
Bit 2 = 1 : red wire is negative
0 : red wire is positive or off
Bits 1 & 0 : have an effect, but don't seem to be important
Therefore:
00000000 00: read Bare->Red and Bare->White currents
00000100 04: read Bare->White or Red->White current
00001000 08: read Bare->Red or White->Red current
00010000 10: read Bare->White current
00100000 20: read Bare->Red current
Other combinations are redundant or useless.
Note: The ROM uses values with bits 6 and 7 set.
Lets do a sample run.
For no appearant reason, lets wait for someone to press ON, and then set the contrast to the highest notch.
WaitForOn:
IN a,(3)
BIT 3,a
jr nz,WaitForOn
ld a,$1F
OUT (2),a
That was sure a lot of info. If you have any questions, drop me a line.
In the next lesson we will be discussing Morphic code and how it can be used for graphics.