Karma Universe - demuynck.org Lesson 16
TI-82 ASM Corner :: Programming Guide :: Lesson 16 Back | Home | Search
Lesson 16 : Introduction to ports

This lesson will give you an introduction to ports. What are they and what can you do with them?

Intro | Ports on the 82 | Port instructions | More Port info | Example


You all know now how you can check which key has been pressed and how to copy the GRAPH_MEM to the LCD. It is done by calls to functions in the ROM. Knowing that these functions in the ROM are written in exact the same language, you might wonder how they can get input from the keyboard for example. Well, this is done by sending data to and getting input from ports. These are the ways the processor is connected with external devices. According to the information these devices get, they will perform a certain action or send back data.

Please note that not all the port functions on the TI-82 are known yet.

Known ports on the TI-82

Here is a list of the port numbers (each port has its own number) :

Known ports on the TI-82
Number Name Read/Write
0 Link Port R/W
1 Keyboard R/W
2 Select rom page R/W
3 Status R/W
4 Interrupt control W
10 Display controller (control port)R/W
11 Display controller (data port) R/W


To write to or to read data from ports, you need new instructions. The instructions used are IN to get input from a port and OUT to write data to a port. There are more instructions that use ports, but I'll talk about them when I'm telling about block instructions. That will be in a lesson soon.


This instruction gets input (one byte) from a port and stores the result a register. There are 2 possibilities: either you give the number of the port directly, or you store the number of the port in C. In the last case, you can store the incoming data to whatever register you want (ABCDEHL). In the first case however, you can only store to the A register. Some examples will make this clear:

Good examples:
 IN	A,(2)
 IN	A,(11)
 IN	C,(C)
 IN	A,(C)
 IN	H,(C)
Bad examples:
 IN	(HL),(3)
 IN	C,(2)
 IN	F,(C)
 IN	(IX+2),(C)

Both instructions (indirect and direct) take the same amount of bytes (2), but the direct way (without using the C register) is slightly faster (1 T-state).


This instruction writes one byte of output to a specific port. The arguments are the same as with the IN instruction. This means that if you point to the port directly (using its number), you can only write data from the A register. If you point to the port indirectly (using the C register), you can write data from any CPU register (ABCDEHL).


Good Examples:
 OUT	(3),A
 OUT	(C),B
 OUT	(C),A
Bad Examples:
 OUT	(4),D
 OUT	(C),R
 OUT	(C),(HL)

Both instructions (indirect and direct) take the same amount of bytes (2), but the direct way (without using the C register) is slightly faster (1 T-state).

Some more info

Below are listed the most important known functions of the TI-82 ports. When you want to have more detailed information about these functions and about the ports, you should read the 82-ports.txt file by Matthias Lindqvist and Dines Justesen.

Port Functions
0 link port


  • Write $C0: white wire positive, red wire positive
  • Write $D4: white wire positive, red wire negative
  • Write $E8: white wire negative, red wire positive
  • Write $FC: white wire negative, red wire negative


  • bit 1 set: White wire is positive, but circuit is open
  • bit 1 res: White wire negative, or positive with electrons flowing
  • bit 0 set: Red wire is positibe, but circuit is open
  • bit 0 res: Red wire negative, or positive with electrons flowing
  • 1 Keyboard port

    Write: A byte with one bit set to mask out several keys

  • bit 5: STO> LN LOG X^2 X^-1 MATH ALPHA
  • bit 4: 0 1 4 7 , SIN MATRX x,t,o
  • bit 3: . 2 5 8 ( COS PRGM STAT
  • bit 2: (-) 3 6 9 ) TAN VARS
  • bit 1: ENTER + - * / ^ CLEAR

    Read: A byte with bytes set according to the keys from the mask that were pressed.

  • bit 7: ALPHA x,t,o DEL STAT
  • bit 5: X^-1 SIN COS TAN ^
  • bit 4: X^2 , ( ) / Y=
  • bit 3: LOG 7 8 9 * WINDOW UP
  • bit 2: LN 4 5 6 - ZOOM RIGHT
  • bit 1: STO> 1 2 3 + TRACE LEFT
  • bit 0: 0 . (-) ENTER GRAPH DOWN
  • 2 Set rom page

    Write: A byte of the format %10001xxx where xxx is the number of the rompage in binary format (0 to 7).

    3 Status

    It's better not use this one, there's not enough information about it right now.

    4 Interrupt Control

    Used for turboing the calculars interrupts. This doesn't make the calculator faster, but some people might get that impression because of the faster handling of keypresses and the fast blinking of the cursor (this is a result from the faster interrupts).


  • %00010110 : Normal interrupts
  • %00010100 : Faster interrupts
  • %00010010 : Even faster interrupts
  • %00010000 : The fastest interrupts
  • 10 Display controller control port

    Note: Before all write operations to the display controller (port 10 or 11), you need to call DISP_DELAY or $7F3. If you don't do this, the controller might not execute the command written to it or even execute something else.


    11 Display controller data port

    Previous lesson | Contents | Next lesson