At 07:43 22-04-97 -0300, Giovanni Nunes wrote:
> Where the color palette are stored in MSX2 machines?
> And how I can access it using teh MSX BASIC or Assembly?

In MSX-BASIC the palette is stored in VRAM. The addresses are:
SCREEN 0 (width 40) &H0400-&H041F
SCREEN 0 (width 80) &H0F00-&H0F1F
SCREEN 1,2,3,4      &H2020-&H203F
SCREEN 5,6          &H7680-&H769F
SCREEN 7,8          &HFA80-&HFA9F

Ofcourse SCREEN 8 doesn't have a palette, but it's still stored, just ignored.
SCREEN 6 only has 4 colors. I don't know exactly how it works, but I think
the last 12 are ignored. (I think COLOR= instruction gives Illegal Function
Call.)

In screen 5,6,7 and 8 each page can hold it's own palette. Add &H8000 for
each page in SCREEN 5 and 6 and &H10000 for each page in SCREEN 7 and 8.
This will give an Illegal Function Call in BASIC (VPOKE can only handle 16
bit addresses), but in Assembly you can access the whole 128kB VRAM.

The palette is stored in those addresses just like in the VDP, like this:
1st byte:  7  6  5  4  3  2  1  0   R=Red
           0 R2 R1 R0  0 B2 B1 B0   B=Blue
2nd byte:  7  6  5  4  3  2  1  0   G=Green
           0  0  0  0  0 G2 G1 G0

After writing new data to the palette in VRAM, you should do COLOR=RESTORE.
BASIC will then send the palette data to the VDP.

Keeping the palette in VRAM is something that BASIC does by itself, it's
not a feature of the VDP. The VDP has 16 palette registers (P#0-P#15) BUT
they can only be WRITTEN TO (that's why BASIC keeps copies in VRAM!) and
only in an INDIRECT manner. It's very simple though.

Just write the palettenumber to R#16, followed by 2 bytes containing the
palette data to VDP-port #2 (&H9A). The palettenumber is automatically
increased, so you can send for example colors 5 to 8 by writing 5 in R#16
and then sending 8 bytes to &H9A. Here's example assembly to write FULL
palette from adress 'PALETTE':

DI              ; always disable interrupts when writing to the VDP.
XOR A           ; faster way of LD A,0 (first palettenumber)
OUT (&H99),A
LD A,16+128     ; write to R#16
OUT (&H99),A
LD BC,&H209A    ; B = &H20 (32 bytes) C = I/O port
LD HL,PALETTE
OTIR            ; OUT B bytes starting from HL to I/O port C
; and then EI enable interrupts somewhere.

I hope this info is of some help. If you have any other questions, feel
free to e-mail me!

Greetz,

                                Patriek


,--.   ,-------.   ,--. Homepage:               \ "To make a mistake is
|  '--.|   __   \  \__/ www.xs4all.nl/~newimage /  human, but to really
|   __||  |  |  |  ,--. E-mail:                 \  fuck things up, you
|  |   |  |  |  |  |  | [EMAIL PROTECTED]      /  need a computer."
|  '---'  |  |  '--'  |                         \ - Glenn Scott,
\_________|  |________| The New Image: MSX4Ever /   Secret Agent W7



Reply via email to