tank, pixel edit > 8 bits

This commit is contained in:
Steven Hugg 2017-12-04 16:40:10 -05:00
parent d732f320b0
commit bafc23cb5b
3 changed files with 170 additions and 13 deletions

140
presets/verilog/tank.v Normal file
View File

@ -0,0 +1,140 @@
`include "hvsync_generator.v"
module minefield(hpos, vpos, mine_gfx);
input [8:0] hpos;
input [8:0] vpos;
output mine_gfx;
// mine X coordinates in ROM
reg [3:0] mine_xpos [0:15];
// 1 bit for each mine
reg [15:0] mine_exploded;
// screen-wide pattern for mines
wire mine_pattern = ~(hpos[0] ^ hpos[1]) ^ (vpos[0] ^ vpos[1])
&& hpos[2] && vpos[2];
// limit mine pattern to a rectangular window
wire mine_field = (hpos >= 64 && hpos < 160)
&& (vpos >= 48 && vpos < 176)
&& mine_pattern;
// index for each of the 16 mines in window
wire [3:0] mine_vindex = vpos[6:3]^8;
// select only 1 mine per horizontal slice
wire mine_all = (hpos[6:3]==(mine_xpos[mine_vindex]^8))
&& mine_field;
// only show mines that haven't exploded
wire mine_gfx = mine_all && !mine_exploded[mine_vindex];
initial begin
mine_exploded = 0;
mine_xpos[0] = 2;
mine_xpos[1] = 10;
mine_xpos[2] = 6;
mine_xpos[3] = 0;
mine_xpos[4] = 9;
mine_xpos[5] = 3;
mine_xpos[6] = 7;
mine_xpos[7] = 11;
mine_xpos[8] = 4;
mine_xpos[9] = 1;
mine_xpos[10] = 10;
mine_xpos[11] = 5;
mine_xpos[12] = 11;
mine_xpos[13] = 3;
mine_xpos[14] = 8;
mine_xpos[15] = 0;
end
endmodule
module playfield(hpos, vpos, playfield_gfx);
input [8:0] hpos;
input [8:0] vpos;
output playfield_gfx;
reg [31:0] maze [0:27];
wire [4:0] x = hpos[7:3];
wire [4:0] y = vpos[7:3] - 2;
assign playfield_gfx = maze[y][x];
initial begin/*{w:32,h:28,bpw:32}*/
maze[0] = 32'b11111111111111111111111111111111;
maze[1] = 32'b10000000000100000000001000000001;
maze[2] = 32'b10000000000100000000001000000001;
maze[3] = 32'b10000000000100000000000000000001;
maze[4] = 32'b10011110000000000000000000000001;
maze[5] = 32'b10000000000000000000000011111001;
maze[6] = 32'b10000000001000000000000000100001;
maze[7] = 32'b11100010000000000000000000100001;
maze[8] = 32'b10000010000000000000000000000001;
maze[9] = 32'b10000011100000000000000000000001;
maze[10] = 32'b10000000000000000000000000000001;
maze[11] = 32'b10000000000000000000000000000001;
maze[12] = 32'b11111000001000000000000000000001;
maze[13] = 32'b10001000001000000000000111100001;
maze[14] = 32'b10001110001000000000000000000001;
maze[15] = 32'b10000000001000000000000000000001;
maze[16] = 32'b10000000001000000000000000000001;
maze[17] = 32'b10001111000000000000000000000001;
maze[18] = 32'b10000000000000000000000100011001;
maze[19] = 32'b10000000000000000000000100010001;
maze[20] = 32'b10000001001000000000000100010001;
maze[21] = 32'b10000001001110000000000100000001;
maze[22] = 32'b10000001000000000010001100000001;
maze[23] = 32'b10001000000000000000000000000001;
maze[24] = 32'b10001000000111100000000000010001;
maze[25] = 32'b10001000000000100000000000010001;
maze[26] = 32'b10001000000000000010000000010001;
maze[27] = 32'b11111111111111111111111111111111;
end
endmodule
module mine_test_top(clk, hsync, vsync, rgb);
input clk;
output hsync, vsync;
output [2:0] rgb;
wire display_on;
wire [8:0] hpos;
wire [8:0] vpos;
wire mine_gfx;
wire playfield_gfx;
hvsync_generator hvsync_gen(
.clk(clk),
.reset(0),
.hsync(hsync),
.vsync(vsync),
.display_on(display_on),
.hpos(hpos),
.vpos(vpos)
);
minefield mine_gen(
.hpos(hpos),
.vpos(vpos),
.mine_gfx(mine_gfx)
);
playfield playfield_gen(
.hpos(hpos),
.vpos(vpos),
.playfield_gfx(playfield_gfx)
);
wire r = display_on && mine_gfx;
wire g = display_on && playfield_gfx;
wire b = display_on && 0;
assign rgb = {b,g,r};
endmodule

View File

@ -250,7 +250,8 @@ function convertBytesToImages(bytes, fmt) {
var count = fmt.count || 1;
var bpp = fmt.bpp || 1;
var nplanes = fmt.np || 1;
var bytesperline = fmt.sl || Math.ceil(width * bpp / 8);
var bitsperword = fmt.bpw || 8;
var bytesperline = fmt.sl || Math.ceil(width * bpp / bitsperword);
var mask = (1 << bpp)-1;
var pofs = fmt.pofs || bytesperline*height*count;
var images = [];
@ -264,11 +265,11 @@ function convertBytesToImages(bytes, fmt) {
var ofs = remapBits(ofs0, fmt.remap);
for (var p=0; p<nplanes; p++) {
var byte = bytes[ofs + p*pofs];
color |= ((fmt.brev ? byte>>(8-shift-bpp) : byte>>shift) & mask) << (p*bpp);
color |= ((fmt.brev ? byte>>(bitsperword-shift-bpp) : byte>>shift) & mask) << (p*bpp);
}
imgdata.push(color);
shift += bpp;
if (shift >= 8) {
if (shift >= bitsperword) {
ofs0 += 1;
shift = 0;
}
@ -285,10 +286,15 @@ function convertImagesToBytes(images, fmt) {
var count = fmt.count || 1;
var bpp = fmt.bpp || 1;
var nplanes = fmt.np || 1;
var bytesperline = fmt.sl || Math.ceil(fmt.w * bpp / 8);
var bitsperword = fmt.bpw || 8;
var bytesperline = fmt.sl || Math.ceil(fmt.w * bpp / bitsperword);
var mask = (1 << bpp)-1;
var pofs = fmt.pofs || bytesperline*height*count;
var bytes = new Uint8Array(bytesperline*height*count*nplanes);
var bytes;
if (bitsperword <= 8)
bytes = new Uint8Array(bytesperline*height*count*nplanes);
else
bytes = new Uint32Array(bytesperline*height*count*nplanes);
for (var n=0; n<count; n++) {
var imgdata = images[n];
var i = 0;
@ -300,10 +306,10 @@ function convertImagesToBytes(images, fmt) {
var ofs = remapBits(ofs0, fmt.remap);
for (var p=0; p<nplanes; p++) {
var c = (color >> (p*bpp)) & mask;
bytes[ofs + p*pofs] |= (fmt.brev ? (c << (8-shift-bpp)) : (c << shift));
bytes[ofs + p*pofs] |= (fmt.brev ? (c << (bitsperword-shift-bpp)) : (c << shift));
}
shift += bpp;
if (shift >= 8) {
if (shift >= bitsperword) {
ofs0 += 1;
shift = 0;
}

View File

@ -21,11 +21,17 @@ var VERILOG_KEYCODE_MAP = makeKeycodeMap([
[Keys.VK_DOWN, 0, 0x8],
[Keys.VK_SPACE, 0, 0x10],
[Keys.VK_SHIFT, 0, 0x20],
[Keys.VK_1, 0, 0x40],
[Keys.VK_2, 0, 0x80],
[Keys.VK_5, 0, 0x100],
[Keys.VK_6, 0, 0x200],
[Keys.VK_7, 0, 0x400],
[Keys.VK_A, 1, 0x1],
[Keys.VK_D, 1, 0x2],
[Keys.VK_W, 1, 0x4],
[Keys.VK_S, 1, 0x8],
[Keys.VK_Z, 1, 0x10],
[Keys.VK_X, 1, 0x20],
[Keys.VK_1, 2, 0x1],
[Keys.VK_2, 2, 0x2],
[Keys.VK_5, 2, 0x4],
[Keys.VK_6, 2, 0x8],
[Keys.VK_7, 2, 0x10],
]);
var vl_finished = false;
@ -65,6 +71,11 @@ var vl_stopped = false;
var VL_MODDIV_III = this.VL_MODDIV_III = function(lbits,lhs,rhs) {
return (((rhs)==0)?0:(lhs)%(rhs)); }
var VL_REDXOR_32 = this.VL_REDXOR_32 = function(r) {
r=(r^(r>>1)); r=(r^(r>>2)); r=(r^(r>>4)); r=(r^(r>>8)); r=(r^(r>>16));
return r;
}
var VL_WRITEF = this.VL_WRITEF = console.log; // TODO: $write
var vl_finish = this.vl_finish = function(filename,lineno,hier) {
@ -168,7 +179,7 @@ var VerilogPlatform = function(mainElement, options) {
var current_output;
var paddle_x = 0;
var paddle_y = 0;
var switches = [0];
var switches = [0,0,0];
var inspect_obj, inspect_sym;
var inspect_data = new Uint32Array(videoWidth * videoHeight);
var scope_time_x = 0; // scope cursor