1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-11-21 23:30:58 +00:00

local storage editor

This commit is contained in:
Steven Hugg 2017-11-21 16:36:38 -05:00
parent 48baf73ecb
commit 298ea62476
7 changed files with 479 additions and 7 deletions

65
editstorage.html Normal file
View File

@ -0,0 +1,65 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>8bitworkshop</title>
<link rel="stylesheet" href="css/ui.css">
</head>
<body>
<h3>8bitworkshop Local Storage Editor</h3>
<p>
<select id="storageitems" size="20">
</select>
</p><p>
<button id="deleteitem">Delete Selected Item</button>
</p>
<script src="jquery/jquery-2.2.3.min.js"></script>
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
<script src="bootstrap/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="bootstrap/css/bootstrap-tour.min.css">
<script src="bootstrap/js/bootstrap-tour.min.js"></script>
<script src="codemirror/lib/codemirror.js"></script>
<script src="src/util.js"></script>
<script src="src/ui.js"></script>
<!-- <script src="src/audio/votrax.js"></script> -->
<script>
var storagelist = $("#storageitems");
var items = getBiggestItems(localStorage);
for (var i=items.length-1; i>=0; i--) {
var item = items[i];
var option = new Option(item[1] + " (" + item[0] + " bytes )", item[1]);
storagelist.append(option);
}
$("#deleteitem").click(function(e) {
var key = storagelist.find(":selected").val();
console.log(key);
if (key) {
if (confirm("Delete " + key + " from local storage (make sure you have any edits backed up!)")) {
localStorage.removeItem(key);
window.location = location;
}
} else {
alert("Please select an item first");
}
});
</script>
</body>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-54497476-9', 'auto');
ga('send', 'pageview');
</script>
</html>

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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([

View File

@ -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<items.length; i++) {
s += items[i] + "\n";
}
return s;
}
}*/
var FileStore = function(storage, prefix) {
var self = this;
@ -62,8 +67,10 @@ var FileStore = function(storage, prefix) {
} catch (e) {
if (e.name == 'NS_ERROR_DOM_QUOTA_REACHED') {
console.log(e);
alert("Sorry, you've reached your local storage quota for this browser.\n\nHere are the biggest items:\n\n" +
getBiggestItems(storage));
if (confirm("Sorry, you've reached your local storage quota for this browser.\n\nGo to local storage editor?")) {
window.location = 'editstorage.html';
return;
}
} else {
throw e;
}
@ -1094,7 +1101,7 @@ function toggleProfileWindow() {
}
function handleWindowMessage(e) {
console.log("window message", e.data);
//console.log("window message", e.data);
if (e.data.bytes) {
editor.replaceSelection(e.data.bytestr);
}