(Note from the translator: if I wasn't sure a translated word would be the correct synonym, I placed it between question marks. FJK, 2010-05-05) mc-soft Guido Dampf Graphics with the NEC 7220 Direct access with Turbo Pascal The NEC 7220 graphics processor is a powerful chip and is used in many computers, for instance the Epson QX-10, QX-16 and the mc-CP/M-Plus-Computer. Because of the fast drop in price of semiconductors, it is an attractive processor, also for the D.I.Y computer builder. The 7220 provides a powerful set of graphics commands. But from reading the datasheet from NEC, it is easy to loose faith, because the chip is not simple to to understand. That's why we describe the most important commands here. The author is member of the WDR-computer club. Two I/O channels are used, addressing A0 and A1. With the QX-10 these map to I/O ports 38h and 39h. Reading A0 retrieves the 7220 status. Reading A1 fetches the first byte from the internal queue. Some commands return values, and those are placed in the queue. As the queue is also used as buffer for commands and parameters, writing a new command before reading the return value of the previous one, will distroy this return value. The Status register can be checked for available data in the queue. Writing to the 7220 uses both registers; A1 for writing the command, A0 for writing the parameters to the queue. Some commands have optional parameters. Because of the fixed order of parameters, only parameters at the end can be omitted. In this case, the execution starts when the next command from the queue is recognised. 54 The 7220 contains complete logic for monochrome and color signal generation. This article only describes the monochrome mode. The status register The bits in the status register contain information needed for reliable communication with the 7220. Bit 0 is set if the queue contains data. Only read from the queue if this bit is set. Bit 1 set indicates the queue is full. No new command or data should be send to the 7220 if this bit is set. Bit 2 set indicates the 7220 is processing commands from the queue. Bit 3 set indicates the 7220 has completed processing of a command. Only then is the queue ready to be read. Bit 4 set indicates a DMA access is in progress. Bit 5 set indicates the 7220 scan is currently outside the visible area (vertical sync). Syncing data transfer (specially DMA) with this bit prevents visible anomalies Bit 6 set is similar to bit 5, but is also active during horizontal sync) Bit 7 set indicates the 7220 detected the light pen and the coordinates can be retrieved. The frame buffer RAM and the parameter RAM The frame buffer RAM (video RAM) can be up to 512 kByte large and is organised as 16 bit values. The exact organisation and size are parameters of the Sync command. 55 [PASCAL listing] 56 In character mode, a word consists of character with up to 8 attributes (like blinking, inverse, half bright, etc. In graphics mode is very bit a screen pixel. The Parameter RAM (PRAM) is a fast internal 16 byte memory, which can be modified by the CPU using the PRAM command. The first eight bytes always contain information on the video RAM organisation. In character mode is also true for the rest of the PRAM. A ?region? definition consists of four bytes: Byte 1: LSB of the start address in video RAM (LSB=least significant bits) Byte 2: ISB of the start address in video RAM (ISB=intermediate significant bits) Byte 3: bit 4..7 least significant nibble of the MSB (MSB=most significant bits) bit 2,3 have no meaning bit 0,1 most significant bits of the MSB. Used only in graphics and mixed mode. Byte 4: bit 0..5 highest part of the line length bit 6 0 for text mode, 1 for graphics mode bit 7 should always 0 The line length of the ?region? is defined in screen lines and independently, the mode; text or graphics. The start address is defined in words. By incrementing the start address by the line length, a fast scroll operation is possible. The 7220 ?interprets? this data as follows: When constructing the screen image, the 7220 reads the start address of the first ?region?. It paints the data from this address as many screen lines as are defined for this ?region?. If there are more lines to be drawn for the complete screen, it starts with the next ?region?. In character mode up to four ?regions? can be defined. In mix and graphics mode only two ?regions? can be defined, because the Parameter RAM uses locations 8 to 15 as ?patterns? for lines, graphics characters and ?planes? (see FIGD and GCHRD commands). The memory access (Read Modify Write Cycle) Every change to be applied to the video RAM, follows the following scheme: First the word is read from the internal EAd register. This value is ?processed? with the result of an AND operation between the PATTERN register and the MASK register. The ?proceesing? type depends on the selected mode, being one of REPLACE, INVERT, SET or RESET. The result is written back to the original position. For the four modes, the following bit-operations (?processed?) ((EAd) is a pointer to the video RAM address in EAd): REPLACE: (EAd) := Pattern and Mask INVERT (EAd) := (EAd) xor (Pattern and Mask) SET (EAd) := (EAd) or (Pattern and Mask) RESET (EAd) := (EAd) and (not(Pattern and Mask)) The result of the operation depends on the command send to the 7220 (see CURS, PRAM, WDAT, MASK, FIGS and RDAT). The DMA channel The 7220 is capable of of DMA transfers from and to the video RAM with controllers of the types 8257 and 8237. Every DMA operation is initated with a DMAR or DMAW command. The 7220 remains in DMA transfer mode until the specified number of bytes is transferred. Integration into Turbo Pascal Now it gets practical. The following routines can be used (with minor changes) by all Turbo Pascal capable computers with a 7220 mapped to memory addresses or I/O ports. For memory based access, the Port-Array must be replaced by a Memory-Array. Now some basic routines in Bild 1. 57 These procedures and functions are the base for the complete data exchange between CPU and 7220: putcmd(b) writes the command b to the queue; putval(b) writes the one byte parameter b to the queue; putdval(i) writes two byte parameters to the queue; the function inpval waits for a byte from the 7220 and delivers it as return value. The remainder of the routines check one bit of the status byte each and return a boolean (TRUE/FALSE). With these procedures and functions, all 7220 commands can be used. Some commands control the video logic (RESET, SYNC, START, BCTRL). Others control the rendering of the video RAM to the screen (ZOOM, CCHAR, PITCH) or the video RAM contents. Video RAM changing commands exist in two types; those presetting the 7220 for following commands (CURS, PRAM, FIGS, MASK) and those resulting in direct change (WDAT, FIGD, GCHRD). Finally there are commands that return data related to video RAM contents. Bild 2 contains an example of a procedure resetting the 7220 to a sane state. The setting of the hardware dependent parameter is omitted here, as it is possible to set it later with the SYNC command. Once set, it doesn't need resetting until after a hardware reset. To get the hardware dependent parameters right, it is useful to define a record with presets. This is also useful as cache for the last applied settings. This is in Bild 3. Direct contact with the 7220 With these presets (possible with minor change) it is simple to fully use the possibilities of the 7220. Bild 4 contains the procedures which directly represent the 7220 commands (RESET is in BILD 3). The WDAT commands are in Bild 5; direct write access to the video RAM. The individual commands differ in parameter interpretation only. All retrieve the write modus from the gdcparam-record. The data to be written are supplied as parameters. In this the command differs from the FIGD and GCHRD which retrieve the data from the pattern register resp. RAM. The ?processing? of the data is for all these commands the same. In graphics mode is only bit 0 of interest (all other bits get the same value). Depending on the MASK-register and the write modus, the video RAM is modified. In character mode all bits are meaningful. When using the WDAT command in Mixed mode, the actual mode is determined by bit 14 of the dc-parameter of the previously issued FIG command (see FIGS). So this command must be issued at least once with at least the parameters CHARANDOT, dir and dc. The bits 0-13 in the dc parameter are interpreted as repeat factor, with dc=0 meaning execute once (no repeat). Depending on the direction specified with the dir parameter, the cursor postion is moved with each WDAT execution. 58 It is not needed to issue WDAT again if only the data to write changes, with the same direction and write modus. The new data can be entered as extra parameters with the PUTVAL or PUTDVAL commands. Note that the dc parameter value will be set to 0 by WDAT execution and is not changed by PUTVAL / PUTDVAL. The various FIGS commands (see Bild 6) differ only in the number of parameters. The parameters have the following meaning: figure: type of the shape to define - CHARADOT = character in character mode, DMA access, WDAT,RDAT (also single points), - STRAIGHTLINE = draw straight lines, - GRAPHICSCHAR = characters in graphics mode, fill surface (?sample?) - CIRC = draw circles and circle segments, - RECT = draw rectangles, - SLANTED = like GRAPHICSCHAR but with italics orientation. dir: character direction 0 = down 1 = right down 2 = right 3 = right up 4 = up 5 = left up 6 = left 7 = left down dc: bit 0-13 = number of memory access operations minus 1 bit 14 = selects graphics or character mode d,d2,d1: paramtere specific for the figure to be drawn dm: number of pixels to be masked while drawing circles or circle segments The commands FIGD and GCHRD (Bild 7) start execution of the paint process. During the process the mask register and the cursor address will be modified. The write mode will be defined by the last WDAT command (also see set mode). The pattern register is set by FIGD from the PRAM address 8 (low) and 9 (high) (see set.pattern). The used ?sample? for GCHRD is found as 8*8 matrix in the PRAM, address 8 to 15 (see define.char). The RDAT command reads a byte (half word) or word from the video RAM. Similar to the WDAT command, multiple values in a range can be read. For this the dc parameter of a previously issued FIGS command must be set to the exact number of values to be read. This differs from the WDAT commands where the value is number - 1. The extra data is read with the inpval function. Word transfer is LSB first. Like the WDAT situation, the transfer is started with data at the the cursor position address. CURD returns the cursor position address as absolute coordinate in two integer values. In total 22 bits are reserved for this, depending on video RAM size and organisation. ih = most significant word, il = least significant word (see Bild 9). If the position of the light pen is localised (see status register), the LPRD command can retrieve the address of the word the pen points at. If more than 64 kWord video RAM is used, use version 2. With less than 64 kWord video RAM use Version 1. The DMAW command (Bild 11). This command is very similar to the WDAT command. It however does not write directlt into video RAM, but start a DMA write. The parameters set with the FIGS4 procedure (CHARANDOT, dir, dc1, dc2) have slightly different meaning compared with their WDAT usage: DMA always reads or writes a rectangular piece from/to the video RAM. The orientation of this rectangle depends on the dir parameter. The dc1 parameter contains the number of words perpendicular to the direction specified with dir (rectangle height -1). dc2 contains the number of bytes in line with the dir orientation (rectangle width -1). Higher level command With the described wealth of procedures and functions, all 7220 commands are accessible. Because this second API (the first is the set of functions and procedures accessing the 7220 ports) is not very user friendly, another layer will make 7220 interfacing so simple, even the uninitiated can use it (see Bild 12). The two final procedures demonstrate how to store a rectangle from the video RAM to disk and retrieve it later (see Bild 13). The routines are not build for maximum performance, but to be as modular as possible. For specific purposes they can be further integrated to improve efficiency. It is also unlikely that all possibilities will be applied in a single program. However, the routines should give the programmer an overview and enable him to implement his own goals. Much success! 65