Fixed Quartus VGA reversal bug/feature. Removed bit reversing logic and created bit-reversed font rom hex file

This commit is contained in:
Niels Moseley 2018-02-08 17:51:30 +01:00
parent 7886763229
commit 237d35491a
4 changed files with 676 additions and 24 deletions

View File

@ -0,0 +1,640 @@
00
00
1C
22
2A
3A
1A
02
3C
00
00
00
08
14
22
22
3E
22
22
00
00
00
1E
22
22
1E
22
22
1E
00
00
00
1C
22
02
02
02
22
1C
00
00
00
1E
22
22
22
22
22
1E
00
00
00
3E
02
02
1E
02
02
3E
00
00
00
3E
02
02
1E
02
02
02
00
00
00
3C
02
02
02
32
22
3C
00
00
00
22
22
22
3E
22
22
22
00
00
00
1C
08
08
08
08
08
1C
00
00
00
20
20
20
20
20
22
1C
00
00
00
22
12
0A
06
0A
12
22
00
00
00
02
02
02
02
02
02
3E
00
00
00
22
36
2A
2A
22
22
22
00
00
00
22
22
26
2A
32
22
22
00
00
00
1C
22
22
22
22
22
1C
00
00
00
1E
22
22
1E
02
02
02
00
00
00
1C
22
22
22
2A
12
2C
00
00
00
1E
22
22
1E
0A
12
22
00
00
00
1C
22
02
1C
20
22
1C
00
00
00
3E
08
08
08
08
08
08
00
00
00
22
22
22
22
22
22
1C
00
00
00
22
22
22
22
22
14
08
00
00
00
22
22
22
2A
2A
36
22
00
00
00
22
22
14
08
14
22
22
00
00
00
22
22
14
08
08
08
08
00
00
00
3E
20
10
08
04
02
3E
00
00
00
3E
06
06
06
06
06
3E
00
00
00
00
02
04
08
10
20
00
00
00
00
3E
30
30
30
30
30
3E
00
00
00
00
00
08
14
22
00
00
00
00
00
00
00
00
00
00
00
3E
00
00
00
00
00
00
00
00
00
00
00
00
00
08
08
08
08
08
00
08
00
00
00
14
14
14
00
00
00
00
00
00
00
14
14
3E
14
3E
14
14
00
00
00
08
3C
0A
1C
28
1E
08
00
00
00
06
26
10
08
04
32
30
00
00
00
04
0A
0A
04
2A
12
2C
00
00
00
08
08
08
00
00
00
00
00
00
00
08
04
02
02
02
04
08
00
00
00
08
10
20
20
20
10
08
00
00
00
08
2A
1C
08
1C
2A
08
00
00
00
00
08
08
3E
08
08
00
00
00
00
00
00
00
00
08
08
04
00
00
00
00
00
00
3E
00
00
00
00
00
00
00
00
00
00
00
00
08
00
00
00
00
20
10
08
04
02
00
00
00
00
1C
22
32
2A
26
22
1C
00
00
00
08
0C
08
08
08
08
3E
00
00
00
1C
22
20
18
04
02
3E
00
00
00
3E
20
10
18
20
22
1C
00
00
00
10
18
14
12
3E
10
10
00
00
00
3E
02
1E
20
20
22
1C
00
00
00
38
04
02
1E
22
22
1C
00
00
00
3E
20
10
08
04
04
04
00
00
00
1C
22
22
1C
22
22
1C
00
00
00
1C
22
22
3C
20
10
0E
00
00
00
00
00
08
00
08
00
00
00
00
00
00
00
08
00
08
08
04
00
00
00
10
08
04
02
04
08
10
00
00
00
00
00
3E
00
3E
00
00
00
00
00
04
08
10
20
10
08
04
00
00
00
1C
22
10
08
08
00
08
00

View File

@ -120,6 +120,8 @@ module apple1_de0_top(
// cnt <= cnt + 1;
//end
assign LEDG = 0;
endmodule

View File

@ -34,9 +34,9 @@ module font_rom(
);
`ifdef SIM
parameter ROM_FILENAME = "../roms/vga_font.hex";
parameter ROM_FILENAME = "../roms/vga_font_bitreversed.hex";
`else
parameter ROM_FILENAME = "../../roms/vga_font.hex";
parameter ROM_FILENAME = "../../roms/vga_font_bitreversed.hex";
`endif
reg [7:0] rom[0:1023];
@ -44,15 +44,22 @@ module font_rom(
initial
$readmemh(ROM_FILENAME, rom, 0, 1023);
// double width of pixel by ignoring bit 0
wire [2:0] pixel_ptr;
//assign pixel_ptr = (3'h7 - pixel[3:1]);
assign pixel_ptr = pixel[3:1];
// double height of pixel by ignoring bit 0
wire [3:0] line_ptr = line[4:1];
// Note: Quartus II reverses the pixels when we do:
//
// rom[address][bitindex]
//
// directly, so we use an intermediate
// signal, romout, to work around this
// problem.
//
// IceCube2 and Yosys don't seem to have this problem.
//
reg [7:0] romout;
always @(posedge clk)
begin
// mode
@ -60,9 +67,12 @@ module font_rom(
// 01 - vertical scanlines
// 10 - horizontal scanlines
// 11 - dotty mode
romout = rom[(character * 10) + {2'd0, line_ptr}];
out <= (mode[1] & line[0]) ? 1'b0 :
(mode[0] & pixel[0]) ? 1'b0 :
rom[(character * 10) + {2'd0, line_ptr}][pixel_ptr];
romout[pixel[3:1]];
end
endmodule

View File

@ -20,40 +20,40 @@ int main(int argc, char *argv[])
return 1;
}
FILE *fout = fopen("../../roms/vga_font.hex","wt");
FILE *fout = fopen("../../roms/vga_font_bitreversed.hex","wt");
if (fout == NULL)
{
printf("Error: cannot open vga_font.hex for writing!\n");
printf("Error: cannot open vga_font_bitreversed.hex for writing!\n");
fclose(fin);
return 1;
}
uint8_t count = 0;
uint8_t nibble = 0;
uint32_t bitcount = 0;
uint8_t byte = 0;
uint32_t bytecount = 0;
while(!feof(fin))
{
char c = fgetc(fin);
if ((c == '0') || (c == '1'))
{
nibble <<= 1;
nibble = nibble | (c - '0');
byte >>= 1;
if (c == '1')
byte |= 0x80;
count++;
if (count == 4)
if (count == 8)
{
fprintf(fout, "%c", hextbl[nibble]);
fprintf(fout, "%c", hextbl[byte >> 4]);
fprintf(fout, "%c", hextbl[byte & 0x0F]);
fprintf(fout, "\n");
count = 0;
nibble = 0;
if ((bitcount % 8) == 7)
{
fprintf(fout, "\n");
}
byte = 0;
bytecount++;
}
bitcount++;
}
}
printf("Done: converted %d bits\n", bitcount);
printf("Done: converted %d bytes\n", bytecount);
fclose(fout);
fclose(fin);