Usage from BASIC

Colour Modes

It is possible to control the colour modes provided by the Chroma 81 interface directly from BASIC with the aid of two small machine code routines. One routine detects the presence of the Chroma facilities by reading the colour input port and the other selects the active colour mode by writing to the Chroma colour output port. Once the colour mode has been selected, it is possible to set the colour attribute memory directly from BASIC using POKE commands.

The two routines are stored in a single REM statement. The following BASIC program will insert the routines into the REM line, after which program lines 10 to 190 can be deleted. Note that the BASIC program will not fit in 1K, although the resultant REM statement will.

BASIC program to set up Chroma colour I/O port machine code routines REM line containing Chroma colour I/O port machine code routines
BASIC program to construct machine code
routines in a REM statement
REM statement containing machine code routines
(BASIC program has been manually deleted)

A BASIC program can check whether the Chroma 81 interface is present by testing the return value from a USR call to 16522. A value of 0 indicates the colour modes are available, else a value of 32 will be returned, e.g.

  10 LET P=USR 16522
  20 PRINT "COLOUR MODES ARE "
  30 IF P<>0 THEN PRINT "NOT ";
  40 PRINT "AVAILABLE"

To select a colour mode, the value to write to the Colour output port must be POKEd to 16518 and then USR 16514 executed, e.g.

  10 LET BORDER=5
  20 LET MODE=1
  30 LET ENABLE=1
  40 POKE 16518,32*ENABLE+16*MODE+BORDER
  50 RAND USR 16514

Refer to the Chroma documentation for details on the control bits of the Colour I/O port.


Character Code Colour Mapping Mode

The following program demonstrates how to control Character Code colour mode from BASIC. It first sets the colour mapping for all characters to black ink on bright white paper. It then defines colour mappings for each letter in the word 'CHROMA'. It sets the top half of each character to bright ink on dull paper, and the bottom half to dull ink on bright paper. It also sets the border to dull white.

Chroma Character Code colour mode example program

The program performs most of its work in FAST mode due to the time it takes to initialise the default colour mappings. Line 190 enables colour output (bit 5 set), selects Character Code mode (bit 4 reset), and sets the border to dull white (bits 0-2 set, bit 3 reset), i.e. 32 + 7 = 39. When run, it produces the following output:

Chroma Character Code colour mode example program output


Attributes File Colour Mode

The following program demonstrates how to control Attributes File colour mode from BASIC. It first determines the address of the attributes file and then flood fills it such that all cells display as black ink on bright white paper. It then sets the attribute cell colours for the first 6 positions where the word 'CHROMA' will be displayed. It also sets the border to dull cyan.

Chroma Attributes File colour mode example program

The program performs most of its work in FAST mode due to the time it takes to initialise the default colours for the attributes file. Line 140 enables colour output (bit 5 set), selects Attributes File mode (bit 4 set), and sets the border to dull cyan (bits 0 and 2 set, bits 1 and 3 reset), i.e. 32 + 16 + 5 = 53. When run, it produces the following output:

Chroma Attributes File colour mode example program output


QS Character Board Emulation

The QS Character Board can be controlled directly from BASIC using POKE commands. The QS Character Board overlays 1K of RAM onto the character bitmaps held in the ZX81 ROM, but unlike the ROM it allows the non-inverted characters (code 0-63) and inverted characters (codes 128-191) to be independently defined. The 1K of RAM is mapped to $8400-$87FF (33792-34815), with the pixel patterns for the non-inverted characters appearing in the lower 0.5K and the pixel patterns for the inverted characters in the upper 0.5K. The ZX81 display hardware automatically inverts all characters with a code of 128 or higher, and this means that the QS Character Board must store the pixel patterns for characters 128-191 in an inverted form; the ZX81 display hardware will then correct them. The QS Character Board does not provide a means for software to determine if the board is present. Instead the board has a manual switch to allow selection between the standard Sinclair characters and those held in the board's RAM. The Chroma 81 interface replicates this functionality using its configuration switch 4.

The following program demonstrates use of the QS Character Board emulation facility. It first populates the 1K RAM with a copy of the Sinclair character set read from the ZX81 ROM. It then modifies a number of inverse letters with lower case representations.

Chroma QS Character Board emulation example program

The program performs most of its work in FAST mode due to the time it takes to copy the Sinclair character set. Note that configuration switch 4 must be set to on before running the program. The display will appear corrupted because the 1K RAM contains uninitialised values. However, the BASIC program is intact and can be run by pressing R and then NEWLINE. The program produces the following output:

Chroma QS Character Board emulation example program output


User Defined Characters (8K RAM)

The ZX81 display mechanism accesses the character set pixel patterns via the Z80's I register but only values that point within the first 8K of the memory map are supported by a standard ZX81. The Chroma 81 interface extends this range to cover the first 16K of the memory map, and allows this additional area to be populated with RAM. This RAM can then be used to hold an alternate character set. Note that the ZX81 display hardware ignores bit 0 of the I register and so in effect only even values can be used.

A small machine code routine is required to set the value of the I register, which can be stored in a REM statement. The following BASIC program will insert the routine into the REM line, after which program lines 10 to 50 can be deleted.

BASIC program to set up Chroma user defined characters machine code routine REM line containing Chroma user defined characters machine code routine
BASIC program to construct machine code
routine in a REM statement
REM statement containing machine code routine
(BASIC program has been manually deleted)

The following program demonstrates use of the 8K RAM to define an alternate character set. It first populates 0.5K of RAM located at 8192 with a copy of the Sinclair character set read from the ZX81 ROM. It then modifies a number of letters with lower case representations before setting the value of the I register to point at the new character set.

Chroma 8K RAM alternate character set example program

The program performs most of its work in FAST mode due to the time it takes to copy the Sinclair character set. The program produces the following output:

Chroma 8K RAM alternate character set example program output

The program places the new character set at address 8192, which requires the I register to set be to 32 since it forms the high byte of the address (32=$20, 8192=$2000). To place the character set at another location, the value assigned to variable I in line 30 needs to be changed but note that the program only supports even values.

Note that configuration switch 3 must be set to on to select the 8K RAM, and configuration switch 2 must be set to off otherwise WRX graphics mode will be selected for the 8K RAM.


Downloads

The BASIC programs presented above are available for download in .P and .P81 file formats.

Click here to download the Colour control routines contained within a REM statement.
Click here to download the Character Code colour mode example BASIC program.
Click here to download the Attributes File colour mode example BASIC program.
Click here to download the QS Character Board emulation example BASIC program.
Click here to download the User defined characters routine contained within a REM statement.
Click here to download the User defined characters example BASIC program.