1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-11-29 14:51:17 +00:00
8bitworkshop/presets/verilog/cpu_platform.v

191 lines
3.7 KiB
Coq
Raw Normal View History

`include "hvsync_generator.v"
`include "font_cp437_8x8.v"
`include "ram.v"
`include "tile_renderer.v"
`include "sprite_scanline_renderer.v"
`include "lfsr.v"
`include "sound_generator.v"
`include "cpu16.v"
2018-05-27 18:13:06 +00:00
module cpu_platform(clk, reset, hsync, vsync, hpaddle, vpaddle, rgb);
input clk, reset;
2018-05-27 18:13:06 +00:00
input hpaddle, vpaddle;
output hsync, vsync;
output [3:0] rgb;
wire display_on;
wire [8:0] hpos;
wire [8:0] vpos;
// video RAM bus
2018-02-28 03:35:42 +00:00
wire [15:0] ram_read;
reg [15:0] ram_write;
reg ram_writeenable;
// multiplex sprite and tile RAM
reg [15:0] tile_ram_addr;
2018-02-28 03:35:42 +00:00
reg [5:0] sprite_ram_addr;
wire tile_reading;
wire sprite_reading;
wire [14:0] mux_ram_addr; // 15-bit RAM access
always @(*)
if (cpu_busy) begin
if (sprite_reading)
mux_ram_addr = {9'b111111100, sprite_ram_addr};
2018-02-28 03:35:42 +00:00
else
mux_ram_addr = tile_ram_addr[14:0];
end else
mux_ram_addr = cpu_ram_addr[14:0];
// tile and sprite ROM
wire [10:0] tile_rom_addr;
wire [7:0] tile_rom_data;
wire [15:0] sprite_rom_addr;
wire [15:0] sprite_rom_data;
// gfx outputs
wire [3:0] tile_rgb;
wire [3:0] sprite_rgb;
hvsync_generator hvsync_gen(
.clk(clk),
.reset(reset),
.hsync(hsync),
.vsync(vsync),
.display_on(display_on),
.hpos(hpos),
.vpos(vpos)
);
2018-02-28 03:35:42 +00:00
// RAM (32k x 16 bits)
RAM_sync #(15,16) ram(
.clk(clk),
2018-02-28 03:35:42 +00:00
.dout(ram_read),
.din(ram_write),
.addr(mux_ram_addr),
.we(ram_writeenable)
);
tile_renderer tile_gen(
.clk(clk),
.reset(reset),
.hpos(hpos),
.vpos(vpos),
.ram_addr(tile_ram_addr),
2018-02-28 03:35:42 +00:00
.ram_read(ram_read),
.ram_busy(tile_reading),
.rom_addr(tile_rom_addr),
.rom_data(tile_rom_data),
.rgb(tile_rgb)
);
sprite_scanline_renderer ssr(
.clk(clk),
.reset(reset),
.hpos(hpos),
.vpos(vpos),
.ram_addr(sprite_ram_addr),
2018-02-28 03:35:42 +00:00
.ram_data(ram_read),
.ram_busy(sprite_reading),
.rom_addr(sprite_rom_addr),
.rom_data(sprite_rom_data),
.rgb(sprite_rgb)
);
font_cp437_8x8 tile_rom(
.addr(tile_rom_addr),
.data(tile_rom_data)
);
example_bitmap_rom bitmap_rom(
.addr(sprite_rom_addr),
.data(sprite_rom_data)
);
2018-02-28 03:35:42 +00:00
// sprites overlay tiles
assign rgb = display_on
? (sprite_rgb>0 ? sprite_rgb : tile_rgb)
: 0;
2018-02-28 03:35:42 +00:00
// CPU
reg cpu_hold = 0;
wire cpu_busy;
wire [15:0] cpu_ram_addr;
wire busy;
2018-02-28 03:35:42 +00:00
wire [15:0] cpu_bus;
2018-05-27 18:13:06 +00:00
wire [15:0] flags = {11'b0, vsync, hsync, vpaddle, hpaddle, display_on};
2018-02-28 03:35:42 +00:00
assign cpu_bus = cpu_ram_addr[15]
2018-05-27 18:13:06 +00:00
? (cpu_ram_addr == 16'hffff)
? flags
: program_rom[cpu_ram_addr[9:0]]
2018-02-28 03:35:42 +00:00
: ram_read;
CPU16 cpu(
.clk(clk),
.reset(reset),
2018-02-28 03:35:42 +00:00
.hold(tile_reading | sprite_reading),
.busy(cpu_busy),
.address(cpu_ram_addr),
.data_in(cpu_bus),
.data_out(ram_write),
.write(ram_writeenable));
2018-03-02 05:15:33 +00:00
reg [15:0] program_rom[0:1023];
2018-02-28 03:35:42 +00:00
`ifdef EXT_INLINE_ASM
initial begin
2018-03-02 05:15:33 +00:00
program_rom = '{
2018-02-28 03:35:42 +00:00
__asm
.arch femto16
.org 0x8000
.len 1024
mov sp,@$6fff
mov dx,@InitPageTable
2018-02-28 03:35:42 +00:00
jsr dx
mov ax,@$4ffe
mov dx,@ClearTiles
jsr dx
mov dx,@ClearSprites
2018-02-28 03:35:42 +00:00
jsr dx
reset
InitPageTable:
2018-02-28 03:35:42 +00:00
mov ax,@$6000 ; screen buffer
mov bx,@$7e00 ; page table start
mov cx,#32 ; 32 rows
InitPTLoop:
2018-02-28 03:35:42 +00:00
mov [bx],ax
add ax,#32
inc bx
dec cx
bnz InitPTLoop
2018-02-28 03:35:42 +00:00
rts
ClearTiles:
mov bx,@$6000
2018-03-02 05:15:33 +00:00
mov cx,@$3c0
2018-02-28 03:35:42 +00:00
ClearLoop:
mov [bx],ax
inc bx
dec cx
bnz ClearLoop
rts
ClearSprites:
mov bx,@$7f00
mov ax,#0
2018-03-02 02:17:37 +00:00
mov cx,#$40
ClearSLoop:
mov ax,[bx]
add ax,@$101
mov [bx],ax
inc bx
dec cx
bnz ClearSLoop
2018-02-28 03:35:42 +00:00
__endasm
};
end
`endif
endmodule