Scrap Metal - Palette for the ZX Spectrum in various graphic modes.

Info Guide #11
Palette for ZX Spectrum
Alone Coder 

 Over the years, many additional features have appeared─
multiple graphic devices that can─
can be connected to Speccy (this is, of course, not
is about "accelerators" that aggressively 
are promoted in the context of the Spectrum, but 
which really cannot be connected, speech 
only about real devices): Eva V9990 
(2009), IPVC (2011), SPECTRA interface 
(2012), METEOR-2013 (2013), ZXM-VideoCard 
(2014).The capabilities of these video controls─ 
Lehrs are very wide, but on the Spectrum
not enough developers to support─
get all this variety in the software.

   The only ones really supported
graphics extensions remain the simplest ones
raster - mainly ATM Turbo modes,
for which there are dozens of games and demos.
Multicolor and Timex hires are also supported
(or soldered Pentagon/Scorpion; hires
512x192 is also available in Byte).  More appeared
ULAplus, it only exists for now─tually (it is clear that it can be real─
called a soldering iron, but there is no diagram - that’s it─
only emulators and FPGA firmware of some
board designers).
   But a palette is a thing that
does not particularly affect the complexity of development and
compatibility, but is a nice addition─
lack of knowledge about computer functionality. In this
The article describes the implementation of the palette on ATM
Turbo, which is successfully used in 
ZX Evo and Pentagon 2.6bbLE, as well as in races─ 
wide variation from DDp was connected
to Pentagon 1024 SL2.x. Palette scheme from
DDp can be connected in principle to any─ 
bum Speccy, but is still suffering due to absence─
Support options in emulators.

                  * * *

   During the development of ATM Turbo in 1991 and
Turbo 2/2+ in 1993 the goal was to make 
on the Spectrum graphics “like on IBM”, what are you─
reflected in copying the geometry of one of
EGA video modes (namely320x200, but
to the wishes of the developers - with square
pixels). The EGA geometry was supplied with
EGA's own palette of 64 colors, which was
easy to implement on 1SSPY2 (SN7489),
and without any extra DACs.
   How does the palette work?
   The palette is organized as an external mouth─
swarm - cell number for both drawing and
the recording is determined by what comes from the computer─
tera RGBI signal, and the recording data for
cells are taken from the processor data bus
when accessing the port#FF. Because in pa─
liter 6 bits, two bits in a byte are not used─
are. The byte order of the colors has been chosen
quite original -%grbG11RB.
 RGBI here is not the border color, but
exactly the color of the current output pixel
(without quenching). But we recommend writing in the palette─
it is necessary to choose the color of the border, in
starting to scan the screen. Because port#FE
does not support border brightness (available
onlyRGB ), the same port was added
#F6, entry to which includes on the border
brightness(I) - so we can choose to select
choose any of 16 colors.
   In 2009, a 12-bit scheme appeared
palettes for 4096 colors from DDp (http://
realddp.narod.ru/zx/palЧЧ4/index.htm ) -
originally an add-on for Pentagon 102ХSL2.x,
but it can be soldered to other spectrums─
mom. It is made the same as the original. Time─
The point is that additionalleast significant bits
colors are taken from the most significant bits of the bus
addresses.  With short port addressing
(OUT (#FF),A - in existing software as
times short addressing) high order bits
The address bus corresponds to the data bus.
   DDp wrote several demos
programs for your scheme: PALCLC (choice
colors), RADIAL (animation using palettes─
ry), SHOWPAL (showing multiple palettes),
GIRL (multicolor picture) and ART (coloured─ 
Rnik of pictures by color per point for the whole
disk).
   By default on ATM Turbo 2, entry to
port#FF is prohibited (the port is hidden in the area
TR-DOS ports, units in the data - per month─
those signals FDC reset and FDC halt, but dos─
blunt to the palette, switchable). In the DDp scheme -
allowed. But the DDp circuit can be made completely
compatible, in the simplest case by inverting
signalDOS (if we do not implement
port protection). On Pentagon 2.6bbLE selected
combined option for accessing the palette -
so that it is possible in addition to ATM programs
run demo programs from
DDp without modification. 

   How to manage the palette?

Step 0.HALT

 Step 1. Enable shadow ports and access
to palette:
LD A,%10101011;6912 screen, turbo
     ;LD A,%10100011 ;6912 screen, not turbo
LD BC,#BD77
 LD HL,#2A53 ;out (c),a:ret in TR-DOS
PUSH HL
 JP #3D2F  ;nop:ret in TR-DOS

 Step 2. Select a changeable color using the method
issuing its number to the border (colors 0..7 -
OUT (#FE), colors 8..15 -OUT (#F6) ). 

 Step 3. Write color data through the port
#FF:
 D0 B (Blue)(inverse)
D1 R (Red)(inverse)
 D2 is not used, must be 1
 D3 is not used, must be 1
D4 G (Green)(inverse)
D5 b (low bit Blue)(inverse)
D6 r (low bit Red)(inverse)
D7 g (low bit Green)(inverse)

   A8-A15 control additional young─
the lowest bits of color components for 12-
bit palette (if any), in the same
ok.

   Repeat steps 2-3 for all colors.

 Step 4. Close shadow ports:
LD A,%10101011;6912 screen, turbo
     ;LD A,%10100011 ;6912 screen, not turbo
LD BC,#FF77
 OUT (C),A

   An example of the procedure for installing a 6-bit pa─
liters:

SETPAL
HALT
 LD HL,TZXPAL+15
LD DE,#ABOF;6912,turbo
                ;(D=%1010t000 for EGA,
                ;%1010t010 for multicolor)
LD BC,#BD77;open ports and palette
 CALL OUTDOS
SETPALO
 LD A,E     BIT 3,E
     RES 3,A
     OUT (#FE),A
     JR Z,$+4
     OUT (#F6),A
     LD A,(HL);most significant bits
     DEC HL
     OUT (#FF),A
     DEC E
     JP P,SETPALO
     LD BC,#FF77;close ports and palette
     OUT (C),D
     RET
TZXPAL
;%grbG11RB 
     DB #FF,#FE,#FD,#FC,#EF,#EE,#ED,#EC
     DB #FF,#DE,#BD,#9C,#6F,#4E,#2D,#0C

   Пример  процедуры  установки  12-битной
палитры (для теневых портов):

SETPAL12
     HALT     LD HL,TZXPAL+31
     LD DE,#ABOF;6912,turbo
                ;(D=%1010t000 for EGA,
                ;%1010t010 for multicolor)
     LD BC,#BD77;open ports and palette
     CALL OUTDOS
     LD C,#FF
SETPAL120
     LD A,E
     BIT 3,E
     RES 3,A
     OUT (#FE),A
     JR Z,$+4
     OUT (#F6),A
     LD B,(HL);least significant bits
     DEC HL
     LD A,(HL);most significant bits
     DEC HL
     OUT (C),A
     DEC E
     JP P,SETPAL120
     LD BC,#FF77;close ports and palette
     OUT (C),D
     RET
TZXPAL
;%grbG11RB 
     DW #FFFF,#FEFE,#FDFD,#FCFC
     DW #EFEF,#EEEE,#EDED,#ECEC
     DW #FFFF,#DEDE,#BDBD,#9C9C
     DW #бFбF,#ЧEЧE,#2D2D,#OCOC

OUTDOS
     PUSH HL
     LD HL,#2A53
     EX (SP),HL
     JP #3D2F

                  * * *

   Долгое время не было утилиты для редак─
тирования  палитры, поэтому  палитра редко
использовалась  в режиме 6912. Я набросал
такую утилиту в начале 2014 года и с небо─
льшими именениями представляю здесь.
   Итак, Palchanger (иPalchanger12, about ko─
torus below) - palette settings program
and launch BGE (or other program) with
this palette.
   Consists, as usual, of BASIC loading─
chik and code block. BASIC block occupied─
is enabled by disk operations - it can be from─
edit to stick customizer
palettes for the program you need.
   The code block has two entry points:32768
- edit the palette, 32771 - easy
set the palette. That is, you can for─
just change the editor to install palit─
ry, if you fix the BASIC.
   An example of using Palchanger as
palette installer - coloring game
AMC1:http://alonecoder.nedopc.com/zx/ 
AMC1pal.zip. For coloring old games
there is absolutely no need to break them :)
   In addition to the program for standard 6-bit─
The new palette "PALCHG" is accompanied by a program
for the full 12-bit palette "PALCHG12". U
PALCHG code block is calledpalchg, and 
palette pal (16 byte palette in format
%grbG11RB ). PALCHG12 has a code block called─
is palchg12, and the palette is pal12 (palette
in 32 bytes, each color is stored in order
senior-junior). Actually it's two
different programs, they are compiled from
different sources, which you can also
find on disk.
   The palette is loaded with BASIC at startup
programs.

   Management:
  -arrows- color selection.
  -r- change the red component.
  -CS+R- change the low part of the red
component (only in PALCHG12). 
  -g- change the green component.
  -CS+G- change the low part of the green
component (only in PALCHG12). 
  -b- change the blue component.
  -CS+B- change the low part of the blue
component (only in PALCHG12). 
  -0- reset the color.
  -Enter- output to BASIC block (loads
BGE or another program that you enter─ 
those in the last line of the BASIC block). 
  -s- output to BASIC block withpreservation
palettes to file. 

   For example, attached is a converted one─
No picture"lisa". To load the car─
teen when starting Palchanger, hold
Space during loading, then enter the name
pictures. This way you can edit pa─
liter in the background of the picture.
   How was the image converted? That's all
the same converter con18:http://
alonecoder.nedopc.com/zx/con18pal.rar
 Unfortunately, the converter cannot yet
find the best palette yourself. For conversion
with palette create a 16 color palette in
format.act (Photoshop) and download it from
using the "Pal" button.

 In older versions of the Unreal emulator
Speccythere is a bug - the 8th color looks like 
0th. Be careful :)

Share your thoughts about the article