Yeah. As mentioned earlier, this is very straightforward.
Increase the number of bits in r, g, and b from four to five:
Code: Select all
output [3:0] r;
output [3:0] g;
output [3:0] b;
Code: Select all
reg [11:0] palette [15:0];
Code: Select all
assign r = resolution == 2 ? mono_intensity :
{palette[palette_index][10:8], palette[palette_index][11]};
assign g = resolution == 2 ? mono_intensity :
{palette[palette_index][6:4], palette[palette_index][7]};
assign b = resolution == 2 ? mono_intensity :
{palette[palette_index][2:0], palette[palette_index][3]};
Code: Select all
assign data_out = addr[4] == 1 ? {6'b0, resolution, 8'b0} : {4'b0, palette[addr[3:0]]};
... and similarly when writing:
Code: Select all
// register writes
always @(posedge CLOCK_32) begin
if (reset) begin
resolution <= 2'b0;
end else if (!cs && !rw) begin
if (addr == 16) begin
resolution <= data[1:0];
end else begin
palette[addr[3:0]] <= data[11:0];
end
end
end
If you wanted to go up to 8 bits per colour, just use eight bits instead of five, and then use address $ff8262 bit 4 as a flag to indicate that future writes to the palette will be for the higher bits of each palette entry (this is to remain compatible with 256-colour mode that is already implemented).
E.g.
Code: Select all
$ff8262 = $0 == Writes to palette entry 0 to 15 are for lower bits of palette 0 to 15
$ff8262 = $1 == Writes to palette entry 0 to 15 are for lower bits of palette 16 to 31
...
$ff8262 = $f == Writes to palette entry 0 to 15 are for lower bits of palette 240 to 255
$ff8262 = $10 == Writes to palette entry 0 to 15 are for higher bits of palette 0 to 15
$ff8262 = $11 == Writes to palette entry 0 to 15 are for higher bits of palette 16 to 31
...
$ff8262 = $1f == Writes to palette entry 0 to 15 are for higher bits of palette 240 to 255