Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This module handles the hold and modify mode (HAM).
- // The module has its own colour palette bank, this is to let
- // the sprites run simultanously with a HAM playfield.
- //
- module hamgenerator
- (
- input wire clk, // bus clock
- input wire clk28m, // 35ns pixel clock
- input wire [8:1] reg_address_in, // register address inputs
- input wire [11:0] data_in, // bus data in
- input wire [7:0] bpldata, // bitplane data input
- input wire ham8, // Enable HAM8 mode. (enabled when BPU[3] and HOMOD bits are set. OzOnE.)
- input wire [2:0] bank, // Bank bits. (bank[0] allows access to second group of color table entries in HAM8 mode.)
- // Extra bank bits brought in for future use. OzOnE
- input wire loct, // LOCT bit.
- output reg [23:0] ham_rgb // RGB output (24-bit packed, RRRRRRRRGGGGGGGGBBBBBBBB.)
- );
- //register names and adresses
- parameter COLORBASE = 9'h180; // colour table base address
- //local signals
- reg [11:0] colortable_high [63:0]; // colour table. (Extended from 16 to 64 entries. AGA stuff. OzOnE.)
- // Note: HAM6 mode only accesses palette entries 0 to 15!
- reg [11:0] colortable_low [63:0]; // colour table. (Lower 12-bits, for AGA. OzOnE.)
- wire [23:0] selcolor; // selected colour output from colour table
- //--------------------------------------------------------------------------------------
- //writing of HAM colour table from bus (implemented using dual port distributed ram)
- //
- // (LOCT bit Low, OCS/ECS) (LOCT bit High, AGA only)
- // || ||
- // Only 16 entries for OCS/ECS! 64 Entries for AGA!
- // [Colour table - HIGH bits] [Colour tablet, LOW bits]
- //
- // 1 [11,10,9,8,7,6,5,4,3,2,1,0] [11,10,9,8,7,6,5,4,3,2,1,0]
- // 2 [11,10,9,8,7,6,5,4,3,2,1,0] [11,10,9,8,7,6,5,4,3,2,1,0]
- // 3 [11,10,9,8,7,6,5,4,3,2,1,0] [11,10,9,8,7,6,5,4,3,2,1,0]
- // .
- // .
- // 13 [11,10,9,8,7,6,5,4,3,2,1,0] [11,10,9,8,7,6,5,4,3,2,1,0]
- // 14 [11,10,9,8,7,6,5,4,3,2,1,0] [11,10,9,8,7,6,5,4,3,2,1,0]
- // 15 [11,10,9,8,7,6,5,4,3,2,1,0] [11,10,9,8,7,6,5,4,3,2,1,0]
- //
- // NOTE: HAM6 only uses palette entries 0 to 15.
- //
- //
- // NOTE2: HAM8 can use palette entries 0 to 63.
- //
- // 16 [11,10,9,8,7,6,5,4,3,2,1,0] [11,10,9,8,7,6,5,4,3,2,1,0]
- // 17 [11,10,9,8,7,6,5,4,3,2,1,0] [11,10,9,8,7,6,5,4,3,2,1,0]
- // 18 [11,10,9,8,7,6,5,4,3,2,1,0] [11,10,9,8,7,6,5,4,3,2,1,0]
- // .
- // .
- // 29 [11,10,9,8,7,6,5,4,3,2,1,0] [11,10,9,8,7,6,5,4,3,2,1,0]
- // 30 [11,10,9,8,7,6,5,4,3,2,1,0] [11,10,9,8,7,6,5,4,3,2,1,0]
- // 31 [11,10,9,8,7,6,5,4,3,2,1,0] [11,10,9,8,7,6,5,4,3,2,1,0]
- //
- // 2nd Bank. (Bank0 bit High, AGA only)...
- //
- // 32 [11,10,9,8,7,6,5,4,3,2,1,0] [11,10,9,8,7,6,5,4,3,2,1,0]
- // 33 [11,10,9,8,7,6,5,4,3,2,1,0] [11,10,9,8,7,6,5,4,3,2,1,0]
- // 34 [11,10,9,8,7,6,5,4,3,2,1,0] [11,10,9,8,7,6,5,4,3,2,1,0]
- // .
- // .
- // 61 [11,10,9,8,7,6,5,4,3,2,1,0] [11,10,9,8,7,6,5,4,3,2,1,0]
- // 62 [11,10,9,8,7,6,5,4,3,2,1,0] [11,10,9,8,7,6,5,4,3,2,1,0]
- // 63 [11,10,9,8,7,6,5,4,3,2,1,0] [11,10,9,8,7,6,5,4,3,2,1,0]
- //
- //
- // COLORxx 180-1BE W COLOR table xx
- // There are thirty-two (32) of these registers
- // (xx=00~31) and together with the banking bits they
- // address the 256 locations in the Color Palette.
- // There are actually 2 sets of color registers,
- // selection of which is controlled by the LOCT
- // register bit. When LOCT=0, the 4 MSB of
- // RED,GREEEN, and BLUE video data are selected along
- // with the ZD bit for Genlocks. The low-order set of
- // registers is also selected simultaneously, so that
- // the 4 bit values are automatically extended to 8
- // bits. This provides compatibility with old
- // software. If the full range of palette values are
- // desired, then LOCT can be set high and independent
- // values for the 4 LSB of RED,GREEN, and BLUE can be
- // written. The low-order color registers do not
- // contain a transparency(T) bit. The Table below
- // shows the color register bit usage.
- //
- // (Our data bus is only 12-bits atm, so data bits 15:12 don't exist on Minimig yet. OzOnE.)
- //
- // BIT * 15,14,13,12, 11,10,09,08, 07,06,05,04, 03,02,01,00
- // LOCT=0 T X X X R7 R6 R5 R4 G7 G6 G5 G4 B7 B6 B5 B4 (colortable_high, LOCT=0 !)
- // LOCT=1 X X X X R3 R2 R1 R0 G3 G2 G1 GO B3 B2 B1 HO (colortable_low, LOCT=1 !)
- //
- // T = TRANSPARENCY R = RED G = GREEN B = BLUE X = UNUSED
- //
- //
- wire [6:1] ct_addr = (ham8==1'b1) ? {bank[0],reg_address_in[5:1]} : {2'b00,reg_address_in[4:1]};
- always @(posedge clk)
- // if (reg_address_in[8:6]==COLORBASE[8:6]) begin // True for Reg Addr 0x180 up to 0x1BE.
- // // (colour table entries 0 to 31.) OzOnE.
- // if (reg_address_in[8:5]==COLORBASE[8:5]) begin // True for Reg Addr 0x180 up to 0x19E.
- // // (colour table entries 0 to 15.) OzOnE.
- if (ham8==1'b1 && reg_address_in[8:6]==COLORBASE[8:6]) begin // HAM8 mode, and Reg Addr between 0x180 and 0x1BE...
- // (color table entries 0 to 31) OzOnE.
- if (loct==1'b0) begin
- colortable_high[ct_addr] <= data_in[11:0]; // In HAM8 mode, writes with LOCT set LOW go to both the
- colortable_low[ct_addr] <= data_in[11:0]; // upper and lower 12-bits of the colour table....
- end
- else begin
- colortable_low[ct_addr] <= data_in[11:0]; // ...Writes with LOCT set HIGH go to the LOWER 12-bits of the colour table only.
- end
- end
- else if (ham8==1'b0 && reg_address_in[8:5]==COLORBASE[8:5]) begin // HAM6 mode, and Reg Addr between 0x180 and 0x19E...
- // (color table entries 0 to 15). OzOnE.
- colortable_high[ct_addr] <= data_in[11:0]; // HAM6 has no bank bit(s), and it only accesses entries 0 to 15 of the color table.
- end // ...(and only writes to the Upper 12-bits of each color table entry. I think?)
- // end
- //reading of colour table
- //
- // In HAM8 mode, the two extra bitplane bits are then used to access colour table entries 0 to 63.
- // The upper and lower 12-bit colour tables are also combined for output.
- //
- assign selcolor = (ham8==1'b1) ? { colortable_high[bpldata[7:2]], colortable_low[bpldata[7:2]] } : // HAM8 - extra 2 bitplane bits (6 total) can access all 64 palette entries.
- { colortable_high[{2'b00,bpldata[3:0]}], colortable_high[{2'b00,bpldata[3:0]}] }; // HAM6 (duplicated the 12-bit output to both halves). OzOnE.
- // HAM6 only access the first 16 color table entries, so padding the top two bits of the address.
- //--------------------------------------------------------------------------------------
- // HAM selcolor...
- //
- // Color Table HIGH (HAM6 and HAM8) Color Table LOW (HAM8 only)
- //
- // [11,10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0] [11,10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
- // [R7,R6,R5,R4,G7,G6,G5,G4,B7,B6,B5,B4] [R3,R2,R1,R0,G3,G2,G1,G0,B3,B2,B1,B0]
- //
- //
- //HAM instruction decoder/processor
- always @(posedge clk28m)
- begin
- if (ham8==1'b1) begin // HAM8 mode enabled....
- case (bpldata[1:0]) // Note: HAM8 uses the two LOW bits of the bitplane data as the control bits!
- // NOTE: Take care when unpacking the correct bits from the color table output! OzOnE...
- 2'b00://Load (set) RGB output wite color table. R=[23:20]+[11:8]. G=[19:16]+[7:4]. B=[15:12]+[3:0].
- ham_rgb <= {selcolor[23:20],selcolor[11:8], selcolor[19:16],selcolor[7:4], selcolor[15:12],selcolor[3:0]};
- 2'b01://HOLD red and green, MODIFY Blue
- ham_rgb <= {ham_rgb[23:8] ,bpldata[7:2],ham_rgb[1:0]};
- 2'b10://HOLD green and blue, MODIFY Red
- ham_rgb <= {bpldata[7:2],ham_rgb[17:16], ham_rgb[15:0]};
- 2'b11://HOLD red and blue, MODIFY Green
- ham_rgb <= {ham_rgb[23:16] ,bpldata[7:2],ham_rgb[9:8], ,ham_rgb[7:0]};
- endcase
- end
- else begin // HAM6 mode enabled... (D Paint V definitely using HAM6 for the "Elke_Mund.HAM" file). OzOnE
- case (bpldata[5:4]) // Note: HAM6 uses the two HIGH bits of the bitplane data as the control bits!
- 2'b00://Load (set) RGB output with color from table
- ham_rgb <= {selcolor[23:20],4'b0000, selcolor[19:16],4'b0000, selcolor[15:12],4'b0000};
- 2'b01://HOLD red and green, MODIFY Blue
- ham_rgb <= {ham_rgb[23:20],4'b0000, ham_rgb[19:16],4'b0000, bpldata[3:0],4'b0000}; // Lower 4 bits of each colour padded with zeros. OzOnE
- 2'b10://HOLD green and blue, MODIFY Red
- ham_rgb <= {bpldata[3:0],4'b0000, ham_rgb[19:16],4'b0000, ham_rgb[15:12],4'b0000};
- 2'b11://HOLD red and blue, MODIFY Green
- ham_rgb <= {ham_rgb[23:20],4'b0000, bpldata[3:0],4'b0000, ham_rgb[15:12],4'b0000};
- endcase
- end
- end
- endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement