Advertisement
Guest User

Untitled

a guest
Sep 11th, 2014
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // This module handles the hold and modify mode (HAM).
  2. // The module has its own colour palette bank, this is to let
  3. // the sprites run simultanously with a HAM playfield.
  4. //
  5. module hamgenerator
  6. (
  7.     input wire  clk,                    // bus clock
  8.     input wire  clk28m,                 // 35ns pixel clock
  9.    
  10.     input wire [8:1] reg_address_in,    // register address inputs
  11.     input wire [11:0] data_in,          // bus data in
  12.     input   wire [7:0] bpldata,         // bitplane data input
  13.    
  14.     input   wire ham8,                      // Enable HAM8 mode. (enabled when BPU[3] and HOMOD bits are set. OzOnE.)
  15.     input wire [2:0] bank,              // Bank bits. (bank[0] allows access to second group of color table entries in HAM8 mode.)
  16.                                                 // Extra bank bits brought in for future use. OzOnE
  17.    
  18.     input wire  loct,                       // LOCT bit.
  19.    
  20.     output reg [23:0] ham_rgb           // RGB output (24-bit packed, RRRRRRRRGGGGGGGGBBBBBBBB.)
  21. );
  22.  
  23. //register names and adresses      
  24. parameter COLORBASE = 9'h180;  // colour table base address
  25.  
  26. //local signals
  27. reg     [11:0] colortable_high [63:0];  // colour table. (Extended from 16 to 64 entries. AGA stuff. OzOnE.)
  28.                                                     // Note: HAM6 mode only accesses palette entries 0 to 15!
  29.  
  30. reg     [11:0] colortable_low [63:0];       // colour table. (Lower 12-bits, for AGA. OzOnE.)
  31.  
  32. wire    [23:0] selcolor;                        // selected colour output from colour table
  33.  
  34. //--------------------------------------------------------------------------------------
  35.  
  36. //writing of HAM colour table from bus (implemented using dual port distributed ram)
  37. //
  38. //     (LOCT bit Low, OCS/ECS)       (LOCT bit High, AGA only)
  39. //               ||                             ||
  40. //  Only 16 entries for OCS/ECS!        64 Entries for AGA!
  41. //   [Colour table - HIGH bits]      [Colour tablet, LOW bits]
  42. //
  43. // 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]
  44. // 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]
  45. // 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]
  46. // .
  47. // .
  48. // 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]
  49. // 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]
  50. // 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]
  51. //
  52. // NOTE: HAM6 only uses palette entries 0 to 15.
  53. //
  54. //
  55. // NOTE2: HAM8 can use palette entries 0 to 63.
  56. //
  57. // 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]
  58. // 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]
  59. // 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]
  60. // .
  61. // .
  62. // 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]
  63. // 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]
  64. // 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]
  65. //
  66. // 2nd Bank. (Bank0 bit High, AGA only)...
  67. //
  68. // 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]
  69. // 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]
  70. // 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]
  71. // .
  72. // .
  73. // 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]
  74. // 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]
  75. // 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]
  76. //
  77. //
  78. // COLORxx 180-1BE W COLOR table xx
  79. // There are thirty-two (32) of these registers
  80. // (xx=00~31) and together with the banking bits they
  81. // address the 256 locations in the Color Palette.
  82. // There are actually 2 sets of color registers,
  83. // selection of which is controlled by the LOCT
  84. // register bit. When LOCT=0, the 4 MSB of
  85. // RED,GREEEN, and BLUE video data are selected along
  86. // with the ZD bit for Genlocks. The low-order set of
  87. // registers is also selected simultaneously, so that
  88. // the 4 bit values are automatically extended to 8
  89. // bits. This provides compatibility with old
  90. // software. If the full range of palette values are
  91. // desired, then LOCT can be set high and independent
  92. // values for the 4 LSB of RED,GREEN, and BLUE can be
  93. // written. The low-order color registers do not
  94. // contain a transparency(T) bit. The Table below
  95. // shows the color register bit usage.
  96. //
  97. // (Our data bus is only 12-bits atm, so data bits 15:12 don't exist on Minimig yet. OzOnE.)
  98. //
  99. // BIT *  15,14,13,12, 11,10,09,08, 07,06,05,04, 03,02,01,00
  100. // LOCT=0  T  X  X  X  R7 R6 R5 R4  G7 G6 G5 G4  B7 B6 B5 B4  (colortable_high, LOCT=0 !)
  101. // LOCT=1  X  X  X  X  R3 R2 R1 R0  G3 G2 G1 GO  B3 B2 B1 HO  (colortable_low, LOCT=1 !)
  102. //
  103. // T = TRANSPARENCY   R = RED   G = GREEN   B = BLUE   X = UNUSED
  104. //
  105. //
  106.  
  107. wire [6:1] ct_addr = (ham8==1'b1) ? {bank[0],reg_address_in[5:1]} : {2'b00,reg_address_in[4:1]};
  108.  
  109. always @(posedge clk)
  110. //  if (reg_address_in[8:6]==COLORBASE[8:6]) begin  // True for Reg Addr 0x180 up to 0x1BE.
  111. //                                                                  // (colour table entries 0 to 31.) OzOnE.
  112.  
  113. //  if (reg_address_in[8:5]==COLORBASE[8:5]) begin  // True for Reg Addr 0x180 up to 0x19E.
  114. //                                                                  // (colour table entries 0 to 15.) OzOnE.
  115.  
  116.         if (ham8==1'b1 && reg_address_in[8:6]==COLORBASE[8:6]) begin    // HAM8 mode, and Reg Addr between 0x180 and 0x1BE...
  117.                                                                                             // (color table entries 0 to 31) OzOnE.
  118.             if (loct==1'b0) begin
  119.                 colortable_high[ct_addr] <= data_in[11:0];  // In HAM8 mode, writes with LOCT set LOW go to both the
  120.                 colortable_low[ct_addr] <= data_in[11:0];       // upper and lower 12-bits of the colour table....
  121.             end
  122.             else begin
  123.                 colortable_low[ct_addr] <= data_in[11:0];   // ...Writes with LOCT set HIGH go to the LOWER 12-bits of the colour table only.
  124.             end
  125.         end
  126.         else if (ham8==1'b0 && reg_address_in[8:5]==COLORBASE[8:5]) begin       // HAM6 mode, and Reg Addr between 0x180 and 0x19E...
  127.                                                                                                     // (color table entries 0 to 15). OzOnE.
  128.  
  129.             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.
  130.         end                                                         // ...(and only writes to the Upper 12-bits of each color table entry. I think?)
  131. //  end
  132.  
  133. //reading of colour table
  134. //
  135. // In HAM8 mode, the two extra bitplane bits are then used to access colour table entries 0 to 63.
  136. // The upper and lower 12-bit colour tables are also combined for output.
  137. //
  138. 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.
  139.  
  140.                                           { colortable_high[{2'b00,bpldata[3:0]}], colortable_high[{2'b00,bpldata[3:0]}] }; // HAM6 (duplicated the 12-bit output to both halves). OzOnE.
  141.                                                                                                                                                         // HAM6 only access the first 16 color table entries, so padding the top two bits of the address.
  142. //--------------------------------------------------------------------------------------
  143. // HAM selcolor...
  144. //
  145. //      Color Table HIGH (HAM6 and HAM8)                Color Table LOW (HAM8 only)
  146. //
  147. // [11,10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]   [11,10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
  148. // [R7,R6,R5,R4,G7,G6,G5,G4,B7,B6,B5,B4]   [R3,R2,R1,R0,G3,G2,G1,G0,B3,B2,B1,B0]
  149. //
  150. //
  151. //HAM instruction decoder/processor
  152.  
  153. always @(posedge clk28m)
  154. begin
  155.     if (ham8==1'b1) begin   // HAM8 mode enabled....
  156.         case (bpldata[1:0]) // Note: HAM8 uses the two LOW bits of the bitplane data as the control bits!
  157.  
  158.             // NOTE: Take care when unpacking the correct bits from the color table output! OzOnE...
  159.             2'b00://Load (set) RGB output wite color table. R=[23:20]+[11:8]. G=[19:16]+[7:4]. B=[15:12]+[3:0].
  160.                 ham_rgb <= {selcolor[23:20],selcolor[11:8], selcolor[19:16],selcolor[7:4], selcolor[15:12],selcolor[3:0]};
  161.             2'b01://HOLD red and green, MODIFY Blue
  162.                 ham_rgb <= {ham_rgb[23:8]   ,bpldata[7:2],ham_rgb[1:0]};
  163.             2'b10://HOLD green and blue, MODIFY Red
  164.                 ham_rgb <= {bpldata[7:2],ham_rgb[17:16],   ham_rgb[15:0]};
  165.             2'b11://HOLD red and blue, MODIFY Green
  166.                 ham_rgb <= {ham_rgb[23:16]   ,bpldata[7:2],ham_rgb[9:8],   ,ham_rgb[7:0]};
  167.         endcase
  168.     end
  169.     else begin                  // HAM6 mode enabled... (D Paint V definitely using HAM6 for the "Elke_Mund.HAM" file). OzOnE
  170.         case (bpldata[5:4]) // Note: HAM6 uses the two HIGH bits of the bitplane data as the control bits!
  171.            
  172.             2'b00://Load (set) RGB output with color from table
  173.                 ham_rgb <= {selcolor[23:20],4'b0000, selcolor[19:16],4'b0000, selcolor[15:12],4'b0000};
  174.             2'b01://HOLD red and green, MODIFY Blue
  175.                 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
  176.             2'b10://HOLD green and blue, MODIFY Red
  177.                 ham_rgb <= {bpldata[3:0],4'b0000,  ham_rgb[19:16],4'b0000,  ham_rgb[15:12],4'b0000};
  178.             2'b11://HOLD red and blue, MODIFY Green
  179.                 ham_rgb <= {ham_rgb[23:20],4'b0000,  bpldata[3:0],4'b0000,  ham_rgb[15:12],4'b0000};
  180.         endcase
  181.     end
  182. end
  183.  
  184.  
  185. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement