All The Ports

z80 » Advanced

Port 0 - Screen Offset

Port 0 is used for the screen offset. You can only write to this port. You can send any value between $00 and $3c. These equations show the relationship between what is sent and the resulting address. Address is the address of the Video Memory and send is the byte sent out port 0.
address = $100 * ( send + $c0 )

send =  address - $c000 
	     $100

Port 1 - Key Port

Port 1 is used for the keypresses. If you don't remember us talking about that, look back at the keypress section. I went into some pretty good detail about it.

Port 2 - Contrast

Port 2 is used to adjust the contrast. It is another write-only port. You can send any value between 0 and 31 to specify different contrast levels. Since it's a read-only port, there has to be some way of recording what we do to it. We have to save what we do with that port into _contrast ($c008). We have to check what that value is, see if it's maxed out or at the minimum. Then we send the new contrast through port 2 and save what we did to _contrast. The program Contrast.asm is an example of changing the contrast with the Up and Down keys. Here's another routine that increases the contrast if possible.
_contrast	=$c008		;where contrast is stored
contrast_port	=2		;port controlling contrast

increase_contrast:
	ld hl,_contrast		;address of contrast
	ld a,(hl)		;get contrast
	cp 31			;compare it to max
	ret z			;it was 31 so return
	inc a			;increase contrast
	ld (hl),a		;put back changes
	out (contrast_port),a	;update contrast
	ret

Port 3 - [ON] and Interrupts

Port 3 is used with the [ON] button and the LCD power. This is a read and write port. Here's a chart to tell you what the bits mean when they're either set or reset:
  Set Reset
Read: Bit 3 - [ON] key was not pressed
Bit 2 - Timer interrupt happened
Bit 1 - LCD is on
Bit 0 - [ON] interrupt happened
Bit 3 - [ON] was pressed
Bit 2 - Timer interrupt hasn't happened
Bit 1 - LCD is off
Bit 0 - [ON] interrupt hasn't happened
Write: Bit 3 - Turn LCD off
Bit 2 - Don't mask timer interrupts (200Hz)
Bit 1 - LCD status on*
Bit 0 - Don't mask [ON] key interrupts*
Bit 3 - Turn LCD on
Bit 2 - Mask timer interrupts (200Hz)
Bit 1 - LCD status off
Bit 0 - Mask [ON] key interrupts

* Don't exit to TI-OS with bits 0 or 1 reset or the calculator will freeze.

The PressOn.asm program shows how to check for [ON] being pressed like this. More on this in the On-Off Section.

	in a,(on_port)		;get status
	bit 3,a			;on's bit..reset if down
	call z,pressing		;[on] is being held
				; down now so call
				; 'pressing' routine

You can turn off the screen manually too. Note that this doesn't turn off the calculator, it merely quits refreshing the Video Memory to the screen. The TI86 will still be running in normal power mode, as opposed to low power mode when TI-OS turns if off. Details in the On-Off Section. Since the processor is executing this code fast, it will be turning on and off probably 50 times while you're pushing the [ON] button down and releasing it. You can try to slow down the processor some by having it check other stuff in the mean time or just doing other tasks instead of continually checking for the [ON] key being pressed.

turn_off:
	ld a,%00000001
	out (3),a		;turn off lcd
	halt			;wait for [on]
	ld a,%00000010
	out (3),a		;turn on lcd
        res onInterrupt,(iy+onFlags)
				;turn off the flag so
				;ti-os doesn't detect it too
	ret

Port 4 - Power Mode

Port 4 is used for the the Power Mode mainly. It's either in Normal Power Mode or Low Power Mode. This is all done with bit 0. TI-OS puts the calculator in Low Power Mode before shutting down to save battery life. If bit 0 is reset, it's in Low Power Mode; set is High Power Mode. Here's how to check if it's in low power mode.
mode_port	=4		;port to check
power_mode:
	in a,(mode_port)	;get status
	bit 0,a			;check mode
	jr z,in_low_power_mode	;is in low power mode
	ret

Port 5 - ROM Pages

See Memory and R_M Pages.

Port 6 - RAM Pages

See Memory and R_M Pages.

Port 7 - Link Port

Port 7 is used for the link port. It can be used for sound, memory expanders, or sending/receiving information. I haven't researched this area much. Check back sometime because I've ordered a second TI86 to work with.

I can direct you to Randy Gluvna's LinkRout.h or ACZ's copy Link86.asm. With this routine, you will be able to send and receive single bytes. I'm sorry for the inconvenience this may have caused.


More from z80 » Advanced
All The Ports // APD // Assembler Directives // Entry Stack // User Fonts // IM 1 // IM 2 // Index, Shadow, and Other Registers // User Interrupt // Morphic Code // On-Off // Reading Keypresses from Port // Shift and Rotate // Simulating Key Presses // Sound // Square-Root Programs // System Flags of TI-OS