mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2025-02-16 17:30:27 +00:00
more paddle/pong stuff; wider compiler msgs
This commit is contained in:
parent
5d14ade371
commit
ff8784da33
@ -20,16 +20,18 @@
|
|||||||
}
|
}
|
||||||
.tooltipbox .tooltiptext {
|
.tooltipbox .tooltiptext {
|
||||||
visibility: hidden;
|
visibility: hidden;
|
||||||
width: 120px;
|
width: 500px;
|
||||||
background-color: black;
|
background-color: #660000;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
padding: 5px 0;
|
padding: 5px 0;
|
||||||
|
|
||||||
/* Position the tooltip */
|
/* Position the tooltip */
|
||||||
position: absolute;
|
position: absolute;
|
||||||
z-index: 10;
|
z-index: 10;
|
||||||
|
/* <pre> tag wrap */
|
||||||
|
white-space: pre-wrap; /* css-3 */
|
||||||
|
white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
|
||||||
}
|
}
|
||||||
.tooltipbox:hover .tooltiptext {
|
.tooltipbox:hover .tooltiptext {
|
||||||
visibility: visible;
|
visibility: visible;
|
||||||
|
106
presets/verilog/ball_paddle.v
Normal file
106
presets/verilog/ball_paddle.v
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
`include "hvsync_generator.v"
|
||||||
|
|
||||||
|
module ball_paddle_top(clk, hpaddle, hsync, vsync, rgb);
|
||||||
|
|
||||||
|
input clk;
|
||||||
|
input hpaddle;
|
||||||
|
output hsync, vsync;
|
||||||
|
output [2:0] rgb;
|
||||||
|
wire display_on;
|
||||||
|
wire [8:0] hpos;
|
||||||
|
wire [8:0] vpos;
|
||||||
|
|
||||||
|
reg [8:0] paddle_pos;
|
||||||
|
|
||||||
|
reg [8:0] ball_x = 128;
|
||||||
|
reg [8:0] ball_y = 128;
|
||||||
|
reg signed [1:0] ball_vel_x = 0;
|
||||||
|
reg ball_vel_y = BALL_VEL_DOWN;
|
||||||
|
|
||||||
|
localparam BALL_VEL_DOWN = 1;
|
||||||
|
localparam BALL_VEL_UP = 0;
|
||||||
|
|
||||||
|
localparam PADDLE_WIDTH = 31;
|
||||||
|
localparam BALL_SIZE = 8;
|
||||||
|
|
||||||
|
hvsync_generator hvsync_gen(
|
||||||
|
.clk(clk),
|
||||||
|
.hsync(hsync),
|
||||||
|
.vsync(vsync),
|
||||||
|
.display_on(display_on),
|
||||||
|
.hpos(hpos),
|
||||||
|
.vpos(vpos)
|
||||||
|
);
|
||||||
|
|
||||||
|
// TODO: only works when paddle at bottom of screen!
|
||||||
|
always @(posedge hsync)
|
||||||
|
if (!hpaddle)
|
||||||
|
paddle_pos <= vpos;
|
||||||
|
|
||||||
|
// TODO: unsigned compare doesn't work in JS
|
||||||
|
wire [8:0] paddle_rel_x = ((hpos-paddle_pos) & 9'h1ff);
|
||||||
|
wire paddle_gfx = paddle_rel_x < PADDLE_WIDTH;
|
||||||
|
|
||||||
|
wire [8:0] ball_rel_x = (hpos-ball_x);
|
||||||
|
wire [8:0] ball_rel_y = (vpos-ball_y);
|
||||||
|
|
||||||
|
wire ball_gfx = ball_rel_x < BALL_SIZE
|
||||||
|
&& ball_rel_y < BALL_SIZE;
|
||||||
|
|
||||||
|
wire [5:0] hcell = hpos[8:3];
|
||||||
|
wire [5:0] vcell = vpos[8:3];
|
||||||
|
wire lr_border = hcell==0 || hcell==31;
|
||||||
|
|
||||||
|
wire main_gfx;
|
||||||
|
|
||||||
|
always @(posedge clk)
|
||||||
|
case (vpos[8:3])
|
||||||
|
0: main_gfx = 1;
|
||||||
|
28: main_gfx = paddle_gfx | lr_border;
|
||||||
|
default: main_gfx = lr_border;
|
||||||
|
endcase;
|
||||||
|
|
||||||
|
wire ball_pixel_collide = main_gfx & ball_gfx;
|
||||||
|
|
||||||
|
/* verilator lint_off MULTIDRIVEN */
|
||||||
|
reg [4:0] ball_collide_bits = 0;
|
||||||
|
/* verilator lint_on MULTIDRIVEN */
|
||||||
|
|
||||||
|
always @(posedge clk)
|
||||||
|
if (ball_pixel_collide) begin
|
||||||
|
if (paddle_gfx) begin // did we collide w/ paddle?
|
||||||
|
ball_collide_bits[4] <= 1;
|
||||||
|
end else begin // collided with playfield
|
||||||
|
if (!ball_rel_x[2] & !ball_rel_y[2]) ball_collide_bits[0] <= 1;
|
||||||
|
if (ball_rel_x[2] & !ball_rel_y[2]) ball_collide_bits[1] <= 1;
|
||||||
|
if (!ball_rel_x[2] & ball_rel_y[2]) ball_collide_bits[2] <= 1;
|
||||||
|
if (ball_rel_x[2] & ball_rel_y[2]) ball_collide_bits[3] <= 1;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
always @(posedge vsync)
|
||||||
|
begin
|
||||||
|
if (ball_collide_bits[4]) begin // collided with paddle?
|
||||||
|
reg signed [1:0] ball_paddle_dx = ball_x[6:5] - paddle_pos[6:5];
|
||||||
|
ball_vel_y <= BALL_VEL_UP; // paddle top
|
||||||
|
ball_vel_x <= ball_vel_x + ball_paddle_dx;
|
||||||
|
end else casez (ball_collide_bits[3:0]) // collided with playfield
|
||||||
|
0: ;
|
||||||
|
4'b01?1: if (ball_vel_x<0) ball_vel_x <= -ball_vel_x-1; // left
|
||||||
|
4'b101?: if (ball_vel_x>=0) ball_vel_x <= -ball_vel_x-1; // right
|
||||||
|
4'b1100: ball_vel_y <= BALL_VEL_UP;
|
||||||
|
4'b0011: ball_vel_y <= BALL_VEL_DOWN;
|
||||||
|
endcase;
|
||||||
|
ball_collide_bits <= 0;
|
||||||
|
ball_x <= ball_x + 9'(ball_vel_x) + 9'(ball_vel_x>=0); // TODO: signed?
|
||||||
|
ball_y <= ball_y + (ball_vel_y==BALL_VEL_DOWN?1:-1);
|
||||||
|
end;
|
||||||
|
|
||||||
|
wire grid_gfx = (((hpos&7)==0) || ((vpos&7)==0));
|
||||||
|
|
||||||
|
wire r = display_on && (grid_gfx | ball_gfx);
|
||||||
|
wire g = display_on && (main_gfx | ball_gfx);
|
||||||
|
wire b = display_on && ball_gfx;
|
||||||
|
assign rgb = {b,g,r};
|
||||||
|
|
||||||
|
endmodule
|
@ -1,12 +1,12 @@
|
|||||||
|
|
||||||
module hvsync_generator(
|
module hvsync_generator(
|
||||||
clk, hsync, vsync, inDisplayArea, CounterX, CounterY);
|
clk, hsync, vsync, display_on, hpos, vpos);
|
||||||
|
|
||||||
input clk;
|
input clk;
|
||||||
output hsync, vsync;
|
output hsync, vsync;
|
||||||
output inDisplayArea;
|
output reg display_on;
|
||||||
output [8:0] CounterX;
|
output reg [8:0] hpos;
|
||||||
output [8:0] CounterY;
|
output reg [8:0] vpos;
|
||||||
|
|
||||||
// constant declarations for VGA sync parameters
|
// constant declarations for VGA sync parameters
|
||||||
localparam H_DISPLAY = 256; // horizontal display area
|
localparam H_DISPLAY = 256; // horizontal display area
|
||||||
@ -25,35 +25,32 @@ module hvsync_generator(
|
|||||||
localparam START_V_RETRACE = V_DISPLAY + V_B_BORDER;
|
localparam START_V_RETRACE = V_DISPLAY + V_B_BORDER;
|
||||||
localparam END_V_RETRACE = V_DISPLAY + V_B_BORDER + V_RETRACE - 1;
|
localparam END_V_RETRACE = V_DISPLAY + V_B_BORDER + V_RETRACE - 1;
|
||||||
|
|
||||||
reg [8:0] CounterX;
|
wire hmaxxed = (hpos==H_MAX);
|
||||||
reg [8:0] CounterY;
|
wire vmaxxed = (vpos==V_MAX);
|
||||||
wire CounterXmaxed = (CounterX==H_MAX);
|
|
||||||
wire CounterYmaxed = (CounterY==V_MAX);
|
|
||||||
|
|
||||||
always @(posedge clk)
|
always @(posedge clk)
|
||||||
if(CounterXmaxed)
|
if(hmaxxed)
|
||||||
CounterX <= 0;
|
hpos <= 0;
|
||||||
else
|
else
|
||||||
CounterX <= CounterX + 1;
|
hpos <= hpos + 1;
|
||||||
|
|
||||||
always @(posedge clk)
|
always @(posedge clk)
|
||||||
if(CounterXmaxed)
|
if(hmaxxed)
|
||||||
if (!CounterYmaxed)
|
if (!vmaxxed)
|
||||||
CounterY <= CounterY + 1;
|
vpos <= vpos + 1;
|
||||||
else
|
else
|
||||||
CounterY <= 0;
|
vpos <= 0;
|
||||||
|
|
||||||
reg vga_HS, vga_VS;
|
reg vga_HS, vga_VS;
|
||||||
always @(posedge clk)
|
always @(posedge clk)
|
||||||
begin
|
begin
|
||||||
vga_HS <= (CounterX>=280 && CounterX<288); // change this value to move the display horizontally
|
vga_HS <= (hpos>=280 && hpos<288); // change this value to move the display horizontally
|
||||||
vga_VS <= (CounterY==START_V_RETRACE); // change this value to move the display vertically
|
vga_VS <= (vpos==START_V_RETRACE); // change this value to move the display vertically
|
||||||
end
|
end
|
||||||
|
|
||||||
reg inDisplayArea;
|
|
||||||
always @(posedge clk)
|
always @(posedge clk)
|
||||||
begin
|
begin
|
||||||
inDisplayArea <= (CounterX<H_DISPLAY) && (CounterY<V_DISPLAY);
|
display_on <= (hpos<H_DISPLAY) && (vpos<V_DISPLAY);
|
||||||
end
|
end
|
||||||
|
|
||||||
assign hsync = ~vga_HS;
|
assign hsync = ~vga_HS;
|
||||||
|
@ -5,23 +5,22 @@ module test_hvsync_top(clk, hsync, vsync, rgb);
|
|||||||
input clk;
|
input clk;
|
||||||
output hsync, vsync;
|
output hsync, vsync;
|
||||||
output [2:0] rgb;
|
output [2:0] rgb;
|
||||||
wire inDisplayArea;
|
wire display_on;
|
||||||
wire [8:0] CounterX;
|
wire [8:0] hpos;
|
||||||
wire [8:0] CounterY;
|
wire [8:0] vpos;
|
||||||
|
|
||||||
hvsync_generator hvsync_gen(
|
hvsync_generator hvsync_gen(
|
||||||
.clk(clk),
|
.clk(clk),
|
||||||
.hsync(hsync),
|
.hsync(hsync),
|
||||||
.vsync(vsync),
|
.vsync(vsync),
|
||||||
.inDisplayArea(inDisplayArea),
|
.display_on(display_on),
|
||||||
.CounterX(CounterX),
|
.hpos(hpos),
|
||||||
.CounterY(CounterY)
|
.vpos(vpos)
|
||||||
);
|
);
|
||||||
|
|
||||||
wire r = inDisplayArea &&
|
wire r = display_on && (((hpos&7)==0) || ((vpos&7)==0));
|
||||||
(((CounterX&7)==0) || ((CounterY&7)==0));
|
wire g = display_on && vpos[4];
|
||||||
wire g = inDisplayArea && CounterY[4];
|
wire b = display_on && hpos[4];
|
||||||
wire b = inDisplayArea && CounterX[4];
|
|
||||||
assign rgb = {b,g,r};
|
assign rgb = {b,g,r};
|
||||||
|
|
||||||
endmodule
|
endmodule
|
||||||
|
@ -22,15 +22,49 @@ var VERILOG_KEYCODE_MAP = makeKeycodeMap([
|
|||||||
[Keys.VK_7, 0, 0x400],
|
[Keys.VK_7, 0, 0x400],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
var VL_UL = function(x) { return x; }
|
||||||
|
|
||||||
|
/// Return true if data[bit] set
|
||||||
|
var VL_BITISSET_I = this.VL_BITISSET_I = function(data,bit) { return (data & (VL_UL(1)<<VL_BITBIT_I(bit))); }
|
||||||
|
|
||||||
|
var VL_EXTENDSIGN_I = this.VL_EXTENDSIGN_I = function(lbits, lhs) { return (-((lhs)&(VL_UL(1)<<(lbits-1)))); }
|
||||||
|
|
||||||
|
var VL_EXTEND_II = this.VL_EXTEND_II = function(obits,lbits,lhs) { return lhs; }
|
||||||
|
|
||||||
|
var VL_EXTENDS_II = this.VL_EXTENDS_II = function(x,lbits,lhs) {
|
||||||
|
return VL_EXTENDSIGN_I(lbits,lhs) | lhs;
|
||||||
|
}
|
||||||
|
|
||||||
|
var VL_EXTEND_II = this.VL_EXTEND_II = function(obits,lbits,lhs) { return lhs; }
|
||||||
|
|
||||||
|
var VL_NEGATE_I = this.VL_NEGATE_I = function(x) { return -x; }
|
||||||
|
|
||||||
|
var VL_LTS_III = this.VL_LTS_III = function(x,lbits,y,lhs,rhs) {
|
||||||
|
return VL_EXTENDS_II(x,lbits,lhs) < VL_EXTENDS_II(x,lbits,rhs); }
|
||||||
|
|
||||||
|
var VL_GTS_III = this.VL_GTS_III = function(x,lbits,y,lhs,rhs) {
|
||||||
|
return VL_EXTENDS_II(x,lbits,lhs) > VL_EXTENDS_II(x,lbits,rhs); }
|
||||||
|
|
||||||
|
var VL_LTES_III = this.VL_LTES_III = function(x,lbits,y,lhs,rhs) {
|
||||||
|
return VL_EXTENDS_II(x,lbits,lhs) <= VL_EXTENDS_II(x,lbits,rhs); }
|
||||||
|
|
||||||
|
var VL_GTES_III = this.VL_GTES_III = function(x,lbits,y,lhs,rhs) {
|
||||||
|
return VL_EXTENDS_II(x,lbits,lhs) >= VL_EXTENDS_II(x,lbits,rhs); }
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
function VerilatorBase() {
|
function VerilatorBase() {
|
||||||
this.VL_RAND_RESET_I = function(bits) { return Math.floor(Math.random() * (1<<bits)); }
|
|
||||||
|
var VL_RAND_RESET_I = this.VL_RAND_RESET_I = function(bits) { return Math.floor(Math.random() * (1<<bits)); }
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
function vl_fatal(msg) {
|
function vl_fatal(msg) {
|
||||||
console.log(msg);
|
console.log(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.reset2 = function() {
|
this.reset2 = function() {
|
||||||
if (this.reset !== 'undefined') {
|
if (this.reset !== undefined) {
|
||||||
this.reset = 1;
|
this.reset = 1;
|
||||||
for (var i=0; i<100; i++)
|
for (var i=0; i<100; i++)
|
||||||
this.tick2();
|
this.tick2();
|
||||||
@ -191,14 +225,18 @@ var VerilogPlatform = function(mainElement, options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function clamp(minv,maxv,v) {
|
||||||
|
return (v < minv) ? minv : (v > maxv) ? maxv : v;
|
||||||
|
}
|
||||||
|
|
||||||
this.start = function() {
|
this.start = function() {
|
||||||
// TODO
|
// TODO
|
||||||
video = new RasterVideo(mainElement,videoWidth,videoHeight);
|
video = new RasterVideo(mainElement,videoWidth,videoHeight);
|
||||||
video.create();
|
video.create();
|
||||||
setKeyboardFromMap(video, switches, VERILOG_KEYCODE_MAP);
|
setKeyboardFromMap(video, switches, VERILOG_KEYCODE_MAP);
|
||||||
$(video.canvas).mousemove(function(e) {
|
$(video.canvas).mousemove(function(e) {
|
||||||
paddle_x = Math.floor(e.offsetX * video.canvas.width / $(video.canvas).width());
|
paddle_x = clamp(4,255,Math.floor(e.offsetX * video.canvas.width / $(video.canvas).width() - 20));
|
||||||
paddle_y = Math.floor(e.offsetY * video.canvas.height / $(video.canvas).height() - 20);
|
paddle_y = clamp(4,255,Math.floor(e.offsetY * video.canvas.height / $(video.canvas).height() - 20));
|
||||||
});
|
});
|
||||||
audio = new SampleAudio(AUDIO_FREQ);
|
audio = new SampleAudio(AUDIO_FREQ);
|
||||||
idata = video.getFrameData();
|
idata = video.getFrameData();
|
||||||
|
@ -172,7 +172,7 @@ function scrollProfileView(_ed) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function newEditor(mode) {
|
function newEditor(mode) {
|
||||||
var isAsm = (mode != 'text/x-csrc');
|
var isAsm = mode=='6502' || mode =='z80';
|
||||||
editor = CodeMirror(document.getElementById('editor'), {
|
editor = CodeMirror(document.getElementById('editor'), {
|
||||||
theme: 'mbo',
|
theme: 'mbo',
|
||||||
lineNumbers: true,
|
lineNumbers: true,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user