Here’s some example assembler code to show the basic mechanisms for accessing the two colour modes provided by the Chroma 81 interface.
CHECK AVAILABILITY
Reading I/O port $7FEF can be used to check whether the Chroma colour facility is enabled:
The A register will hold $00 if Chroma colour is available, else $20. A program can therefore be designed to only use the Chroma colour facilities if they are present and enabled, e.g. the games from Bob's Stuff that include support for Chroma colour perform check for the colour facilities at start up but if not found then the games fall back to running in black and white.
SELECT COLOUR MODE
Writing to I/O port $7FEF is used to select between the two colour modes (bit 4) and to enable the colour mechanism (bit 5). It is also used to set the border colour (bits 0-3). Bits 6 and 7 are reserved for use in future revisions of the interface and should both be set to 0.
BORDER COLOUR
The border colour is set at the same time as selecting the colour mode and enabling the colour facility. Bits 2-0 defines the colour (GRB), with bit 3 defining whether the colour is BRIGHT or not.
COLOUR MODE 0
Colour mode 0 allows specific colours to be assigned to each character of the character set. Each character will be displayed in its colours no matter where it appears on the screen. This mode allows games to colourised without changing the actual game code. The table of colour values is located at $C000. It consists of the colour definitions for the 64 non-inverted characters ($C000-$C1FF) followed by the definitions for the inverse characters ($C200-$C3FF). Different colours can be defined for the 8 lines that make up each character.
Code: Select all
LD A,$20+border_colour
LD BC,$7FEF
OUT (C),A
LD HL,$C000
LD B,$08
LOOP:
LD (HL),attribute_colour
INC HL
DJNZ LOOP
The above example sets the same colour scheme for the 8 lines that make up the first character, i.e. the SPACE character.
COLOUR MODE 1
Colour mode 1 allows specific colours to be assigned to each display position irrespective of which characters are being shown. This mode is similar to the Spectrum’s attributes file. However, unlike on the Spectrum the Chroma attribute file does not reside at a fixed location. It mirrors the position of the display file but in the 48K-64K memory region, i.e. (DFILE)+$8000. The attributes file follows the same layout as the display file, i.e. if the display file is collapsed then so too is the attributes file. Note that if the display file moves up or down in memory, e.g. because BASIC lines are added or removed, then the location of the attributes file will also move but its contents will not be automatically shifted.
Code: Select all
LD A,$30+border_colour
LD BC,$7FEF
OUT (C),A
LD HL,($400C)
INC HL
SET 7,H
LD C,$18
LOOP_ROW:
LD B,$20
LOOP_COL:
LD (HL),attribute_colour
INC HL
DJNZ LOOP_COL
INC HL
DEC C
JR NZ,LOOP_ROW
The above example sets the same colour throughout a fully expanded attributes file. Note that the attributes file includes positions corresponding to the NEWLINE characters in the display file. However, the contents of these locations are ignored.
ATTRIBUTE BYTES
The format of colour attributes is the same for colour modes 0 and 1 and follows a pattern similar (but not identical) to that of the Spectrum’s attributes. Bits 2-0 defines the INK colour (GRB), with bit 3 defining BRIGHT for INK. Bits 6-4 defines the PAPER colour (GRB), with bit 7 defining BRIGHT for PAPER. So instead of a shared BRIGHT bit and a FLASH bit as on the Spectrum, Chroma supports separate BRIGHT bits for the ink and paper and there are no FLASH bits.