From 298ea624768cb41b3678e48069c82a18618550c8 Mon Sep 17 00:00:00 2001 From: Steven Hugg Date: Tue, 21 Nov 2017 16:36:38 -0500 Subject: [PATCH] local storage editor --- editstorage.html | 65 ++++++++++++ presets/verilog/ball_slip_counter.v | 53 ++++++++++ presets/verilog/sprite_bitmap.v | 88 ++++++++++++++++ presets/verilog/sprite_multiple.v | 106 +++++++++++++++++++ presets/verilog/sprite_renderer.v | 151 ++++++++++++++++++++++++++++ src/platform/verilog.js | 4 +- src/ui.js | 19 ++-- 7 files changed, 479 insertions(+), 7 deletions(-) create mode 100644 editstorage.html create mode 100644 presets/verilog/ball_slip_counter.v create mode 100644 presets/verilog/sprite_bitmap.v create mode 100644 presets/verilog/sprite_multiple.v create mode 100644 presets/verilog/sprite_renderer.v diff --git a/editstorage.html b/editstorage.html new file mode 100644 index 00000000..6558bfe8 --- /dev/null +++ b/editstorage.html @@ -0,0 +1,65 @@ + + + +8bitworkshop + + + + +

8bitworkshop Local Storage Editor

+

+ +

+ +

+ + + + + + + + + + + + + + + + + + + diff --git a/presets/verilog/ball_slip_counter.v b/presets/verilog/ball_slip_counter.v new file mode 100644 index 00000000..132bfa2d --- /dev/null +++ b/presets/verilog/ball_slip_counter.v @@ -0,0 +1,53 @@ +`include "hvsync_generator.v" + +module ball_paddle_top(clk, reset, hsync, vsync, rgb); + + input clk; + input reset; + output hsync, vsync; + output [2:0] rgb; + wire display_on; + wire [8:0] hpos; + wire [8:0] vpos; + + reg [7:0] ball_htimer; + reg [7:0] ball_vtimer; + + reg [3:0] ball_horiz_vel; + reg [3:0] ball_vert_vel; + + hvsync_generator hvsync_gen( + .clk(clk), + .hsync(hsync), + .vsync(vsync), + .display_on(display_on), + .hpos(hpos), + .vpos(vpos) + ); + + always @(posedge clk) + begin + if (hpos == 0 && vpos == 0) + ball_htimer <= ball_htimer + 8'(ball_horiz_vel) - 4; + else if (display_on) + ball_htimer <= ball_htimer + 1; + end; + + always @(posedge hsync) + begin + if (vpos > 9'(ball_vert_vel)) + ball_vtimer <= ball_vtimer + 1; + end; + + wire ball_hgfx = ball_htimer < 8; + wire ball_vgfx = ball_vtimer < 8; + wire ball_gfx = ball_hgfx & ball_vgfx; + + wire grid_gfx = (((hpos&7)==0) || ((vpos&7)==0)); + + wire r = display_on && (grid_gfx | ball_gfx); + wire g = display_on && ball_gfx; + wire b = display_on && ball_gfx; + assign rgb = {b,g,r}; + +endmodule diff --git a/presets/verilog/sprite_bitmap.v b/presets/verilog/sprite_bitmap.v new file mode 100644 index 00000000..4022bcc6 --- /dev/null +++ b/presets/verilog/sprite_bitmap.v @@ -0,0 +1,88 @@ +`include "hvsync_generator.v" + +module car_bitmap(yofs, bits); + + input [3:0] yofs; + output [7:0] bits; + + reg [7:0] bitarray[16]; + + assign bits = bitarray[yofs]; + + initial begin/*{w:8,h:16}*/ + bitarray[0] = 8'b0; + bitarray[1] = 8'b101110; + bitarray[2] = 8'b11101110; + bitarray[3] = 8'b11111110; + bitarray[4] = 8'b11101110; + bitarray[5] = 8'b1101110; + bitarray[6] = 8'b110000; + bitarray[7] = 8'b110000; + bitarray[8] = 8'b110000; + bitarray[9] = 8'b1110000; + bitarray[10] = 8'b1100000; + bitarray[11] = 8'b11100000; + bitarray[12] = 8'b11101100; + bitarray[13] = 8'b11111100; + bitarray[14] = 8'b11001100; + bitarray[15] = 8'b1100; + end +endmodule + +module test_top(clk, hsync, vsync, rgb, hpaddle, vpaddle); + + input clk; + input hpaddle, vpaddle; + output hsync, vsync; + output [2:0] rgb; + wire display_on; + wire [8:0] hpos; + wire [8:0] vpos; + + reg sprite_active; + reg [3:0] car_sprite_xofs; + reg [3:0] car_sprite_yofs; + wire [7:0] car_sprite_bits; + + reg [7:0] player_x = 128; + reg [7:0] player_y = 128; + + hvsync_generator hvsync_gen( + .clk(clk), + .hsync(hsync), + .vsync(vsync), + .display_on(display_on), + .hpos(hpos), + .vpos(vpos) + ); + + car_bitmap car( + .yofs(car_sprite_yofs), + .bits(car_sprite_bits)); + + always @(posedge hsync) + // start sprite? + if (vpos == {1'0,player_y}) + car_sprite_yofs <= 15; + else if (car_sprite_yofs != 0) + car_sprite_yofs <= car_sprite_yofs - 1; + + always @(posedge clk) + if (display_on) begin + if (hpos == {1'0,player_x}) + car_sprite_xofs <= 15; + else if (car_sprite_xofs != 0) + car_sprite_xofs <= car_sprite_xofs - 1; + end + + // mirror sprite in X direction + wire car_gfx = car_sprite_bits[car_sprite_xofs>=8 ? + 15-car_sprite_xofs: + car_sprite_xofs]; + + wire r = display_on && car_gfx; + wire g = display_on && car_gfx; + wire b = display_on && car_gfx; + assign rgb = {b,g,r}; + +endmodule diff --git a/presets/verilog/sprite_multiple.v b/presets/verilog/sprite_multiple.v new file mode 100644 index 00000000..d45bb5b9 --- /dev/null +++ b/presets/verilog/sprite_multiple.v @@ -0,0 +1,106 @@ +`include "hvsync_generator.v" +`include "sprite_renderer.v" + +module sprite_multiple_top(clk, hsync, vsync, rgb, hpaddle, vpaddle); + + input clk; + input hpaddle, vpaddle; + output hsync, vsync; + output [2:0] rgb; + wire display_on; + wire [8:0] hpos; + wire [8:0] vpos; + + reg [7:0] player_x; + reg [7:0] player_y; + reg [7:0] paddle_x; + reg [7:0] paddle_y; + reg [7:0] enemy_x = 128; + reg [7:0] enemy_y = 128; + + reg [15:0] track_pos = 0; + reg [7:0] speed = 31; + + hvsync_generator hvsync_gen( + .clk(clk), + .hsync(hsync), + .vsync(vsync), + .display_on(display_on), + .hpos(hpos), + .vpos(vpos) + ); + + wire [3:0] car_sprite_yofs; + wire [7:0] car_sprite_bits; + + car_bitmap car( + .yofs(car_sprite_yofs), + .bits(car_sprite_bits)); + + wire player_vstart = {1'0,player_y} == vpos; + wire player_hstart = {1'0,player_x} == hpos; + wire player_gfx; + wire player_is_drawing; + + wire enemy_vstart = {1'0,enemy_y} == vpos; + wire enemy_hstart = {1'0,enemy_x} == hpos; + wire enemy_gfx; + wire enemy_is_drawing; + + sprite_renderer player_renderer( + .clk(clk), + .vstart(player_vstart), + .load(hpos == 256), + .hstart(player_hstart), + .rom_yofs(car_sprite_yofs), + .rom_bits(car_sprite_bits), + .gfx(player_gfx), + .in_progress(player_is_drawing)); + + sprite_renderer enemy_renderer( + .clk(clk), + .vstart(enemy_vstart), + .load(hpos == 257), + .hstart(enemy_hstart), + .rom_yofs(car_sprite_yofs), + .rom_bits(car_sprite_bits), + .gfx(enemy_gfx), + .in_progress(player_is_drawing)); + + always @(posedge hsync) + begin + if (!hpaddle) paddle_x <= vpos[7:0]; + if (!vpaddle) paddle_y <= vpos[7:0]; + end + + always @(posedge vsync) + begin + player_x <= paddle_x; + player_y <= 180; + track_pos <= track_pos + {11'b0,speed[7:4]}; + enemy_y <= enemy_y + {3'b0, speed[7:4]}; + // collision check? + if (frame_collision) + speed <= 16; + else if (speed < 255) + speed <= speed + 1; + end + + reg frame_collision; + + always @(posedge clk) + if (player_gfx && (enemy_gfx || track_gfx)) + frame_collision <= 1; + else if (vsync) + frame_collision <= 0; + + wire track_offside = (hpos[7:5]==0) || (hpos[7:5]==7); + wire track_shoulder = (hpos[7:3]==3) || (hpos[7:3]==28); + wire track_gfx = (vpos[5:1]!=track_pos[5:1]) && track_offside; + + wire r = display_on && (player_gfx || enemy_gfx || track_shoulder); + wire g = display_on && (player_gfx || track_gfx); + wire b = display_on && (enemy_gfx || track_shoulder); + assign rgb = {b,g,r}; + +endmodule diff --git a/presets/verilog/sprite_renderer.v b/presets/verilog/sprite_renderer.v new file mode 100644 index 00000000..b8bef0f8 --- /dev/null +++ b/presets/verilog/sprite_renderer.v @@ -0,0 +1,151 @@ +`include "hvsync_generator.v" + +module car_bitmap(yofs, bits); + + input [3:0] yofs; + output [7:0] bits; + + reg [7:0] bitarray[16]; + + assign bits = bitarray[yofs]; + + initial begin/*{w:8,h:16}*/ + bitarray[0] = 8'b110000; + bitarray[1] = 8'b1110111; + bitarray[2] = 8'b11100110; + bitarray[3] = 8'b11111111; + bitarray[4] = 8'b11100110; + bitarray[5] = 8'b1100111; + bitarray[6] = 8'b110000; + bitarray[7] = 8'b110000; + bitarray[8] = 8'b110000; + bitarray[9] = 8'b1110000; + bitarray[10] = 8'b1100000; + bitarray[11] = 8'b11100000; + bitarray[12] = 8'b11101100; + bitarray[13] = 8'b11111100; + bitarray[14] = 8'b11001100; + bitarray[15] = 8'b1100; + end +endmodule + +module sprite_renderer(clk, vstart, load, hstart, rom_yofs, rom_bits, + gfx, in_progress); + + input clk, vstart, load, hstart; + output [3:0] rom_yofs; + input [7:0] rom_bits; + output gfx; + output in_progress = yactive; + + reg [3:0] ycount; + reg [3:0] xcount; + reg yactive; + reg xactive; + reg loading; + + reg [7:0] outbits; + + always @(posedge clk) + begin + // set a default value (blank) for pixel output + // note: multiple non-blocking assignments are vendor-specific + gfx <= 0; + // load next line? set ROM address + if (yactive && load) begin + rom_yofs <= ~ycount; + loading <= 1; + // ROM address was set, now latch bits from bus + end else if (loading) begin + outbits <= rom_bits; + loading <= 0; + ycount <= ycount + 1; + // start sprite at this vertical scanline + end else if (vstart) begin + yactive <= 1; + //ycount <= 0; + // start sprite at this horizontal clock + end else if (hstart && yactive) begin + xactive <= 1; + //xcount <= 0; + // both X & Y active, set pixel output + end else if (xactive && yactive) + begin + // mirror graphics left/right + gfx <= outbits[xcount[3]?~xcount[2:0]:xcount[2:0]]; + xcount <= xcount + 1; + if (xcount == 15) begin // pre-increment value + xactive <= 0; // done drawing this scanline + if (ycount == 0) // post-increment value + yactive <= 0; // done drawing sprite + end + end + end + +endmodule + +module test_top(clk, hsync, vsync, rgb, hpaddle, vpaddle); + + input clk; + input hpaddle, vpaddle; + output hsync, vsync; + output [2:0] rgb; + wire display_on; + wire [8:0] hpos; + wire [8:0] vpos; + + reg [7:0] player_x; + reg [7:0] player_y; + + reg [7:0] paddle_x; + reg [7:0] paddle_y; + + hvsync_generator hvsync_gen( + .clk(clk), + .hsync(hsync), + .vsync(vsync), + .display_on(display_on), + .hpos(hpos), + .vpos(vpos) + ); + + wire [3:0] car_sprite_yofs; + wire [7:0] car_sprite_bits; + + car_bitmap car( + .yofs(car_sprite_yofs), + .bits(car_sprite_bits)); + + wire vstart = {1'0,player_y} == vpos; + wire hstart = {1'0,player_x} == hpos; + wire car_gfx; + wire unused; + + sprite_renderer renderer( + .clk(clk), + .vstart(vstart), + .load(hsync), + .hstart(hstart), + .rom_yofs(car_sprite_yofs), + .rom_bits(car_sprite_bits), + .gfx(car_gfx), + .in_progress(unused)); + + always @(posedge hsync) + begin + if (!hpaddle) paddle_x <= vpos[7:0]; + if (!vpaddle) paddle_y <= vpos[7:0]; + end + + always @(posedge vsync) + begin + player_x <= paddle_x; + player_y <= paddle_y; + end + + wire r = display_on && car_gfx; + wire g = display_on && car_gfx; + wire b = display_on && car_gfx; + assign rgb = {b,g,r}; + +endmodule diff --git a/src/platform/verilog.js b/src/platform/verilog.js index 7c5c2683..c663cfcb 100644 --- a/src/platform/verilog.js +++ b/src/platform/verilog.js @@ -8,7 +8,9 @@ var VERILOG_PRESETS = [ {id:'digits10.v', name:'Digits'}, {id:'ball_slip_counter.v', name:'Ball Motion (slipping counter)'}, {id:'ball_paddle.v', name:'Brick Smash Game'}, - //{id:'pong.v', name:'Pong'}, + {id:'sprite_bitmap.v', name:'Sprite Bitmaps'}, + {id:'sprite_renderer.v', name:'Sprite Rendering'}, + {id:'sprite_multiple.v', name:'Multiple Sprites'}, ]; var VERILOG_KEYCODE_MAP = makeKeycodeMap([ diff --git a/src/ui.js b/src/ui.js index 6381f41a..a8bfe7ec 100644 --- a/src/ui.js +++ b/src/ui.js @@ -28,7 +28,7 @@ function gotoNewLocation() { } // make sure VCS doesn't start -Javatari.AUTO_START = false; +if (window.Javatari) Javatari.AUTO_START = false; // 8bitworkshop IDE user interface @@ -44,15 +44,20 @@ function getBiggestItems(storage) { var items = []; for (var i = 0; i < storage.length; i++) { var key = storage.key(i); - items.push([lpad(storage.getItem(key).length+"", 12), key]); + var len = storage.getItem(key).length; + if (len>=100) + items.push([lpad(len+"", 12), key]); } items.sort(); + return items; +} +/* var s = ""; for (var i=items.length-5; i