diff --git a/boards/blackice2/README.md b/boards/blackice2/README.md new file mode 100644 index 0000000..55b76a2 --- /dev/null +++ b/boards/blackice2/README.md @@ -0,0 +1,21 @@ +# Blackice II with Digilent Pmods support + +This adds support for building the apple one design for [mystorm Blackice II](https://github.com/mystorm-org/BlackIce-II) with attached Digilent Pmods for vga and ps2 + +## Peripheral support + +VGA port is working through a Digilent VGA Pmod on Pmod 7/8/9/10 + +PS/2 keyboard uses a Digilent PS/2 Pmod on Pmod 12 + +## Building +Install a recent IceStorm toolchain, and: + +``` +$ cd yosys +$ make +``` + +## Use + +To load BASIC type "E000R" with CAPS LOCK on. diff --git a/boards/blackice2/yosys/Makefile b/boards/blackice2/yosys/Makefile new file mode 100644 index 0000000..5065932 --- /dev/null +++ b/boards/blackice2/yosys/Makefile @@ -0,0 +1,71 @@ +DEVICE = hx8k +PIN_DEF=blackice2.pcf + +SOURCEDIR = ../../../rtl +BUILDDIR = build + +all: apple1 prog + +info: + @echo " To build: make apple1" + @echo " To program: make prog" + @echo "To build report: make report" + @echo " To clean up: make clean" + +dir: + mkdir -p $(BUILDDIR) + +# ------ TEMPLATES ------ +$(BUILDDIR)/%.blif: $(SOURCEDIR)/%.v + yosys -q -p "chparam -list; hierarchy -top apple1_top; synth_ice40 -blif $@" $^ + +$(BUILDDIR)/%.asc: $(PIN_DEF) $(BUILDDIR)/%.blif + arachne-pnr -d 8k -P tq144:4k -o $@ -p $^ + +$(BUILDDIR)/%.bin: $(BUILDDIR)/%.asc + icepack $^ $@ + +%.rpt: $(BUILDDIR)/%.asc + icetime -d $(DEVICE) -P $(PACKAGE) -c $(FREQ_PLL) -mtr $@ $< + +%_tb.vvp: %_tb.v %.v + iverilog -o $@ $^ + +%_tb.vcd: %_tb.vvp + vvp -N $< +vcd=$@ + +# ------ APPLE 1 ------ +apple1: dir $(BUILDDIR)/apple1.bin +report: dir apple1.rpt + +$(BUILDDIR)/apple1.bin: $(BUILDDIR)/apple1.asc +$(BUILDDIR)/apple1.asc: $(BUILDDIR)/apple1.blif +$(BUILDDIR)/apple1.blif: $(SOURCEDIR)/apple1.v \ + $(SOURCEDIR)/clock.v \ + $(SOURCEDIR)/pwr_reset.v \ + $(SOURCEDIR)/ram.v \ + $(SOURCEDIR)/rom_wozmon.v \ + $(SOURCEDIR)/rom_basic.v \ + $(SOURCEDIR)/cpu/arlet_6502.v \ + $(SOURCEDIR)/cpu/arlet/ALU.v \ + $(SOURCEDIR)/cpu/arlet/cpu.v \ + $(SOURCEDIR)/uart/uart.v \ + $(SOURCEDIR)/uart/async_tx_rx.v \ + $(SOURCEDIR)/vga/vga.v \ + $(SOURCEDIR)/vga/vram.v \ + $(SOURCEDIR)/vga/font_rom.v \ + $(SOURCEDIR)/ps2keyboard/debounce.v \ + $(SOURCEDIR)/ps2keyboard/ps2keyboard.v \ + $(SOURCEDIR)/boards/blackice2/apple1_hx8k.v + +apple1.rpt: $(BUILDDIR)/apple1.asc + +prog: dir $(BUILDDIR)/apple1.bin + cat $(filter-out $<,$^) >/dev/ttyACM0 + +# ------ HELPERS ------ +clean: + rm -rf build apple1.rpt + +.SECONDARY: +.PHONY: all info clean prog iceprog diff --git a/boards/blackice2/yosys/blackice2.pcf b/boards/blackice2/yosys/blackice2.pcf new file mode 100644 index 0000000..407ffae --- /dev/null +++ b/boards/blackice2/yosys/blackice2.pcf @@ -0,0 +1,38 @@ +# For the Blackice II board + +### UART +set_io uart_rx 88 +set_io uart_tx 85 +set_io uart_cts 94 + +### LEDs +set_io led[0] 71 +set_io led[1] 67 +set_io led[2] 68 +set_io led[3] 70 + +### VGA Display +set_io vga_h_sync 8 +set_io vga_v_sync 7 +set_io vga_r[3] 15 +set_io vga_r[2] 16 +set_io vga_r[1] 19 +set_io vga_r[0] 20 +set_io vga_g[3] 1 +set_io vga_g[2] 2 +set_io vga_g[1] 9 +set_io vga_g[0] 10 +set_io vga_b[3] 11 +set_io vga_b[2] 12 +set_io vga_b[1] 17 +set_io vga_b[0] 18 + +set_io clk 129 + +set_io ps2_din 32 +set_io ps2_clk 26 + +### Buttons +set_io button[0] 63 +set_io button[1] 64 + diff --git a/rtl/boards/blackice2/apple1_hx8k.v b/rtl/boards/blackice2/apple1_hx8k.v new file mode 100644 index 0000000..22e6094 --- /dev/null +++ b/rtl/boards/blackice2/apple1_hx8k.v @@ -0,0 +1,126 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +// +// Description: Apple 1 implementation for the Blackeice II ICE40HX8K + +// +// Author.....: Lawrie Griffiths and Alan Garfield +// Date.......: 31-3-2018 +// + +module apple1_top #( + parameter BASIC_FILENAME = "../../../roms/basic.hex", + parameter FONT_ROM_FILENAME = "../../../roms/vga_font_bitreversed.hex", + parameter RAM_FILENAME = "../../../roms/ram.hex", + parameter VRAM_FILENAME = "../../../roms/vga_vram.bin", + parameter WOZMON_ROM_FILENAME = "../../../roms/wozmon.hex" +) ( + input clk, // 100 MHz board clock + + // I/O interface to computer + input uart_rx, // asynchronous serial data input from computer + output uart_tx, // asynchronous serial data output to computer + output uart_cts, // clear to send flag to computer - not used + + // I/O interface to keyboard + input ps2_clk, // PS/2 keyboard serial clock input + input ps2_din, // PS/2 keyboard serial data input + + // Outputs to VGA display + output vga_h_sync, // hozizontal VGA sync pulse + output vga_v_sync, // vertical VGA sync pulse + + output [3:0] vga_r, // red VGA signal + output [3:0] vga_g, // green VGA signal + output [3:0] vga_b, // blue VGA signal + + // Debugging ports + output [3:0] led, + input [1:0] button // 2 buttons on board +); + + assign led[0] = 1; + assign led[1] = reset_n; + assign led[2] = clr_screen_n; + assign led[3] = 0; + + wire clk25; + + // =============================================================== + // System Clock generation (25MHz) + // =============================================================== + + reg [1:0] clkpre = 2'b00; // prescaler, from 100MHz to 25MHz + + always @(posedge clk) + begin + clkpre <= clkpre + 1; + end + wire clk25 = clkpre[1]; + + wire vga_bit; + + // set the monochrome base colour here.. + assign vga_r[3:0] = vga_bit ? 4'b1000 : 4'b0000; + assign vga_g[3:0] = vga_bit ? 4'b1111 : 4'b0000; + assign vga_b[3:0] = vga_bit ? 4'b1000 : 4'b0000; + + // debounce reset button + wire reset_n; + debounce reset_button ( + .clk25(clk25), + .rst(1'b0), + .sig_in(button[0]), + .sig_out(reset_n) + ); + + // debounce clear screen button + wire clr_screen_n; + debounce clr_button ( + .clk25(clk25), + .rst(~reset_n), + .sig_in(button[1]), + .sig_out(clr_screen_n) + ); + + // apple one main system + apple1 #( + .BASIC_FILENAME (BASIC_FILENAME), + .FONT_ROM_FILENAME (FONT_ROM_FILENAME), + .RAM_FILENAME (RAM_FILENAME), + .VRAM_FILENAME (VRAM_FILENAME), + .WOZMON_ROM_FILENAME (WOZMON_ROM_FILENAME) + ) my_apple1( + .clk25(clk25), + .rst_n(reset_n), + + .uart_rx(uart_rx), + .uart_tx(uart_tx), + .uart_cts(uart_cts), + + .ps2_clk(ps2_clk), + .ps2_din(ps2_din), + .ps2_select(1'b1), // PS/2 enabled, UART TX disabled + //.ps2_select(1'b0), // PS/2 disabled, UART TX enabled + + .vga_h_sync(vga_h_sync), + .vga_v_sync(vga_v_sync), + .vga_red(vga_bit), + //.vga_grn(vga_bit), + //.vga_blu(vga_bit), + .vga_cls(~clr_screen_n), + ); +endmodule