CPC Guide - Chips - INTEL 8255PPIINTEL 8255 Interface chip documents The 8255 is a general purpose input output chip. It is connected to the PSG, keyboard and cassette recorder. Programming the 8255 The 8255 has 3 8-bit ports (A,B and C), each of which can have a different I/O Status (i.e. input or output). Port C can also be programmed to operate in two halves. (As two separate 4-bit ports). There are 3 basic modes of operation under which the ports can function. Mode 0 - Basic Input/Output Mode 1 - Strobed Input/Output **NOT USED BY CPC** Mode 2 - Bi-Directional Bus **NOT USED BY CPC** In some of these modes port C is used as a control/status port for port A or B. It can be used to confirm when data transfer may take place, and reflect any other flags. The 8255 PPI is therefore supplied with the added option for the user to set or reset any individual bits in port C. The I/O status, mode of operation and bit setting is defined by the 8255 PPI control byte. (The control byte is accessed using port &F7xx.(8255 Control port)) The ports may be accessed separately by the CPU. Port A is accessed using port &F4xx. Port B is accessed using port &F5xx. Port C is accessed using port &F6xx. NOTE: Mode 0 operation: Mode 0 operation does not require other ports to be used to control data transfer. Data may only be sent to a port if the port is defined as output, and data may only be read from a port when the port is set to input. Using the 8255 Ports When writing to a port: 1) Make sure the port is operating as output. (This is done by sending a control byte to port &F7xx). 2) Write the data to the port. 3) Return the port to it's original I/O Status. When reading from a port: 1) Make sure the port is operating as input. (This is done by sending a control byte to port &F7xx). 2) Read the data from the port. 3) Return the port to it's original I/O Status. 8255 PPI Control Byte This byte controls the Input/Output (I/O) status and operating mode of each port. It also has a secondary function which allows the user to set or reset a particular bit of port C. To send a control byte to the 8255, simply sent the byte to port &F7xx. (NOTE: The control byte can only be written, it cannot be read.) The function to be executed by the 8255 is dependant on the state of bit 7. If bit 7 is 1, the remaining bits are used to define the I/O status, and operating mode of each port. If bit 7 is 0, the remaining bits are used to determine what bit is set (set to 1) or reset (set to 0) of port C. Configuration control byte When bit 7 is set to 1, the command byte operates in the following way: Bit 7: Control byte function (1=Configuration control byte) Bit 6: } Operating Mode (Port A and Port C upper) Bit 5: } Bit 4: Port A I/O Status 0: Output, 1: Input Bit 3: Port C (upper) I/O Status 0: Output, 1: Input Bit 2: Operating Mode selection (Port B and Port C lower) Bit 1: Port B I/O Status 0: Output, 1: Input Bit 0: Port C (lower) I/O Status 0: Output, 1: Input Port A and Port C (upper) Operating mode Bit 6 Bit 5 Mode selection ---------------------------------------------- 0 0 Mode 0 0 1 Mode 1 1 0 Mode 2 1 1 Mode 2 Port B and Port C (lower) operating mode Bit 2 Mode Selection ------------------------------ 0 Mode 0 1 Mode 1 Bit Set/Reset control byte When bit 7 is set to 0, the control byte operates in the following way: Bit 7: Control byte function (0=Bit Set/Reset control byte) Bit 6: } Not used. (send 0) Bit 5: } Bit 4: } Bit 3: } Bit to change. Bit 2: } Bit 1: } Bit 0: Bit operation 1: Set bit (make bit=1), 0: Reset bit (make bit=0) Table to show how bit to change is coded: Bit 3 Bit 2 Bit 1 Bit selected ------------------------------------------------------------ 0 0 0 Bit 0 0 0 1 Bit 1 0 1 0 Bit 2 0 1 1 Bit 3 1 0 0 Bit 4 1 0 1 Bit 5 1 1 0 Bit 6 1 1 1 Bit 7 Port Usage For each port, the port address (at which the port can be accessed) it's normal I/O Status (unless changed by the user), it's operating mode (unless changed by the user) are given. For more information on a particular function of each port, see the appropiate part of the CPC Guide. NOTE: If you are using the firmware, always return the operating modes and I/O status of the ports used to their status below, otherwise the firmware may crash. (The firmware expects the operating modes to be the same as given below). Port A (Port address:&F4xx) (I/O Status: Output) (Operating mode: 0) Bit 7: } PSG data Bit 6: } Bit 5: } Bit 4: } Bit 3: } Bit 2: } Bit 1: } Bit 0: } Port B (Port address: &F5xx) (I/O Status: Input) (Operating mode: 0) Bit 7: Cassette read data Bit 6: Printer configuration 1: Not-ready, 0: Ready Bit 5: Expansion peripheral detect 1: Expansion peripheral present, 0: Not present Bit 4: Screen refresh frequency (defined by hardware) 1: 50Hz 0: 60Hz Bit 3: } Computer name on power-up. Bit 2: } Bit 1: } Bit 0: VSYNC status (Frame flyback status) 1: VSYNC occured, 0: no VSYNC Table showing Computer name on power-up: Bit 3 Bit 2 Bit 1 Computer name ---------------------------------------- 0 0 0 Isp 0 0 1 Triumph 0 1 0 Saisho 0 1 1 Solavox 1 0 0 Awa 1 0 1 Schneider 1 1 0 Orion 1 1 1 Amstrad Port C (Port address: &F6xx) (I/O Status: Output) (Operating mode: 0) Bit 7: } PSG control Bit 6: } Bit 5: Cassette write data Bit 4: Cassette motor control 1: Turn motor on, 0: Turn motor off Bit 3: } Keyboard line to be scanned (0-10) Bit 2: } Bit 1: } Bit 0: } Programming Examples 1) Using the control byte a) Setting bit 7 of port C to 1, LD B,&F7 ;8255 Control port LD A,%00001111 ;Bit Set/reset function OUT (C),A ;Send it to 8255 RET b) Set port A to input, operating in mode 0, port B to output, operating in mode 0 and port C to input, operating in mode 0. LD B,&F7 ;8255 Control port LD A,%10011001 ;Configuration function OUT (C),A ;Send it to 8255 RET 2) Using port A/B/C, In this example, port A is set to output, port B is set to input, and port C is set to output, and they are all operating in mode 0. We will only be using port A for these examples. a) Reading from port A, ;Set port A to input LD B,&F7 ;8255 Control port LD A,%10010010 ;Configuration function OUT (C),A ;Send to 8255 LD B,&F4 ;Port A port address IN E,(C) ;Get byte from port ;Register E holds value from port ;Return port I/O status and operating modes ;to previous settings. LD B,&F7 ;8255 Control port LD A,%10000010 ;Configuration function OUT (C),A ;Send to 8255 RET b) Writing to port A, ;Set port A to output ;(Note the next few lines are not necessary ;as port A is already acting as output, however ;it is given here just to make the example ;more understandable) LD B,&F7 ;8255 Control port LD A,%10000010 ;Configuration function OUT (C),A ;Send to 8255 LD B,&F4 ;port A port address ;Register E holds value to put into port LD E,&FF ;Data to put into port OUT (C),A ;Send to port A ;Return port I/O status and operating modes ;to previous settings. LD B,&F7 ;8255 Control port LD A,%10000010 ;Configuration function OUT (C),A RET