             Storing palette information in screen dumps             ===========================================           File: Docs.Comp.BBC.Filing.Palette - Update 0.10                Author: J.G.Harston - Date 12-10-1989Screens can be saved to disk with commands such as *SAVE pic FFFF3000+5000to save a MODE 0, 1, or 2 image. However, that only saves the contents ofthe screen itself, it does not save the palette. That may not be a problemif saving a MODE 2 screen as that has 16 colours, and the default palettecan be used. However, in a 4-colour or 2-colour mode the screen dump maynot neccesarily be using the default palette.As screen images are only *LOADed, not *RUN, the palette information can bestored in the file's execution address. If it is known what mode the screendump is for, then the file can be loaded to a known address, for examplewith *LOAD file FFFF3000, and so the load address can also be used to storeinformation.Execution address:			Load address:    b0-b2   = colour 0                      b0-2  = colour 4    b3-b5   = colour 1                      b3-5  = colour 5    b6-b8   = colour 2                      b6-8  = colour 6    b9-b11  = colour 3                      b9-11 = colour 7    b12-b15 = screen modeThere is no space to store colours 8 to 15 in 16-colour modes, so it isassumed that they are set to the same as colours 0 to 7.The palette can be set with the following code:    tmp%=load% AND &FFFF    FOR logical%=7 TO 4 STEP -1    VDU 19,logical%,(tmp% DIV 512)AND 7,0,0,0:tmp%=tmp%*8    NEXT    tmp%=exec% AND &FFFF    mode%=tmp% DIV &1000    FOR logical%=0 TO 3    VDU 19,logical%,(tmp% DIV 512)AND 7,0,0,0:tmp%=tmp%*8    NEXTSetting the palette information in reverse order ensures that low numberedentries take priority in 4-colour and 2-colour modes.The palette information can be written with the following code:    DIM ctrl% 15:X%=ctrl%:Y%=X%DIV256    tmp%=mode%    FOR logical%=3 TO 0 STEP -1    ?X%=logical:A%=11:CALL &FFF1    tmp%=tmp%*8+(X%?1)AND7    NEXT:exec%=tmp%    tmp%=0    FOR logical%=7 TO 4 STEP -1    ?X%=logical:A%=11:CALL &FFF1    tmp%=tmp%*8+(X%?1)AND7    NEXT:load%=tmp%