Page 12 of 16

Re: Chroma 81 - SCART and Colour interface for the ZX81

Posted: Sat Dec 30, 2017 7:56 pm
by nitrofurano
i’m interested to access Chroma81 colour attribute area from Boriel’s ZX-Basic Compiler (what i have done up to now for ZX81 using this cross-compiler is at http://www.boriel.com/wiki/en/index.php ... ams_-_ZX81 )

where from can we can get documentation about, or examples in assembly (Pasmo), or zx81 interpreted Basic (using poke)?

Re: Chroma 81 - SCART and Colour interface for the ZX81

Posted: Sat Dec 30, 2017 11:57 pm
by Fruitcake
A description of the colour modes can be found at the end of the document available from here.

Re: Chroma 81 - SCART and Colour interface for the ZX81

Posted: Sun Dec 31, 2017 4:31 am
by gammaray
From http://www.boriel.com/wiki/en/index.php/Main_Page
ZX BASIC
ZX Basic main page.
The ZX Basic compiler project documentation.
ZX BASIC is a BASIC compiler for the ZX Spectrum vintage machine. Alphabetical Keyword List
Language Reference & Syntax
Is this relevant?

Re: Chroma 81 - SCART and Colour interface for the ZX81

Posted: Mon Jan 01, 2018 12:20 am
by nitrofurano
gammaray wrote: Sun Dec 31, 2017 4:31 am From http://www.boriel.com/wiki/en/index.php/Main_Page
ZX BASIC
ZX Basic main page.
The ZX Basic compiler project documentation.
ZX BASIC is a BASIC compiler for the ZX Spectrum vintage machine. Alphabetical Keyword List
Language Reference & Syntax
Is this relevant?
partially - by using this cross-compiler, i bypassed the speciffic zx-spectrum specific parts, including custom routines specifically for zx81, and this way i wanted to extend to chroma81 display hardware as well

Re: Chroma 81 - SCART and Colour interface for the ZX81

Posted: Mon Jan 01, 2018 12:25 am
by nitrofurano
Fruitcake wrote: Sat Dec 30, 2017 11:57 pm A description of the colour modes can be found at the end of the document available from here.
i guess it is where it says "Colour Attribute File [Colour Mode 1] (appears in memory map between $C000-$FFFF, at DFILE+$8000)"
so if we poke randomly between 0xC000 and 0xFFFF we will have some colour appearing?
(i can’t remember where dfile is... is it an address provided from a system variable somewhere?)

Re: Chroma 81 - SCART and Colour interface for the ZX81

Posted: Mon Jan 01, 2018 1:58 am
by 1024MAK
Yes, the current value of D_FILE is stored in the system variables area (two bytes at 16396), because D_FILE moves around in memory. It moves whenever the BASIC program length changes.

See chapter 27 and 28 in the ZX81 BASIC Programming manual.

Mark

Re: Chroma 81 - SCART and Colour interface for the ZX81

Posted: Tue Jan 02, 2018 9:05 pm
by nitrofurano
thanks! :)

Re: Chroma 81 - SCART and Colour interface for the ZX81

Posted: Tue Jan 02, 2018 9:18 pm
by nitrofurano
so i guess this might work somehow (i’m going to test it soon on Boriel’s ZX-Basic Compiler):

Code: Select all

for eee=0 to 767
  seed=smsrnd(seed)
  dfile=peek uinteger(16396)
  poke dfile+$8000+eee,seed
  next
another question: the colours available from chroma81 are those like from zx-spectrum’s bright 1 (or bright 0)?

Re: Chroma 81 - SCART and Colour interface for the ZX81

Posted: Tue Jan 02, 2018 11:56 pm
by Fruitcake
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:

Code: Select all

    LD   BC,$7FEF
    IN   A,(C)
    AND  $20
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.

Re: Chroma 81 - SCART and Colour interface for the ZX81

Posted: Wed Jan 03, 2018 12:06 am
by Fruitcake
nitrofurano wrote: Tue Jan 02, 2018 9:18 pm

Code: Select all

for eee=0 to 767
  seed=smsrnd(seed)
  dfile=peek uinteger(16396)
  poke dfile+$8000+eee,seed
  next
The above code does not take into account the 'NEWLINE' positions within the attributes file.

The attributes file begins with a position corresponding to the initial NEWLINE character in the display file, followed by 32 positions for the 32 columns of the first row, then another NEWLINE position, then the 32 columns for the second row, etc. Although the NEWLINE positions are reproduced in the attributes file, they are ignored by the Chroma interface and so they do not need to be populated with a NEWLINE character. Having the attributes file replicate the 'shape' of the display file allows a program to easily handle both a fully expanded display file or collapsed display files where some rows don't contain the full 32 columns. When a program writes into the display file, it can simply follow it by setting bit 15 of the address to access the corresponding attributes file location.