Skip to content

Commit 5b943b2

Browse files
committed
VERSION 1.4
2 parents fa02955 + 1729909 commit 5b943b2

File tree

555 files changed

+266560
-317
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

555 files changed

+266560
-317
lines changed

.gitignore

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,22 @@ nexys4ddr/work_cpu_debug
33
usage_statistics_webtalk.html
44
nexys4ddr/webtalk.log
55
nexys4ddr/webtalk_impact.xml
6+
nexys4ddr/webtalk_pn.xml
67
nexys4ddr/iseconfig
8+
nexys4ddr/_xmsgs
9+
nexys4ddr/env1.gise
10+
nexys4ddr/env1_summary.html
711
impact.xsl
812
impact_impact.xwbt
913
assembler/qasm
1014
assembler/qasm2rom
1115
register_file.sym
1216
emulator/qnice
17+
*.bin
1318
*.lis
1419
*.out
20+
*.o
1521
*.rom
16-
*.bin
1722
*.def
1823
*.aux
1924
*.log
@@ -23,3 +28,14 @@ emulator/qnice
2328
*.stc
2429
*.swp
2530
*.swo
31+
*.obj
32+
c/vasm/vasmqnice_std
33+
c/vasm/vobjdump
34+
c/vbcc/bin
35+
c/vlink/vlink
36+
c/test_programs/mapfile
37+
c/qnice/qniceconv
38+
c/test_programs/wolfram
39+
c/vclib
40+
c/vclib*.tgz
41+
c/qnice/monitor-lib/lib/*.asm

README.md

Lines changed: 205 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ system-on-a-chip in portable VHDL on a FPGA. Specifications:
1515
* 32k words RAM (64kB)
1616
* UART 115.200 baud, 8-N-1, CTS
1717
* VGA 80x40 character textmode display (640x480 resolution)
18-
* PS/2 keyboard support (mapped to USB on the Nexys4 DDR)
18+
* PS/2 keyboard support (mapped to USB on the Nexys 4 DDR)
19+
* SD Card and FAT32 support (microSD card on the Nexys 4 DDR)
1920
* 4-digit 7-segment display
2021
* 16 hardware toggle switches
2122

@@ -24,36 +25,57 @@ The main purpose of QNICE-FPGA is learning, teaching and having fun.
2425
Getting Started
2526
---------------
2627

28+
* Clone GitHub repo: Make sure you have `git` installed on your computer,
29+
open a Terminal or Command Line. We will automatically create a subdirectory
30+
called QNICE-FPGA, so navigate to an appropriate folder. Use this command
31+
to clone the `master` branch of QNICE-FPGA, as the `master` branch always
32+
contains the latest stable version:
33+
`git clone https://github.com/sy2002/QNICE-FPGA.git`
34+
(Hint: It is important, that you clone the repository instead of just
35+
downloading it as a ZIP. The reason is, that some build scripts rely on
36+
the fact, that there is an underlying git repository.)
37+
2738
* Hardware: Currently, we develop QNICE-FPGA on a Nexys 4 DDR development
2839
board, so if you own one, the fastest way of getting started is to
29-
download the bitstream file `dist_kit/qnice.bit` on the SD card of the
30-
Nexys board and set the jumpers to read the FPGA configuration from the
31-
SD card. Do not copy more than one `*.bit` file on the SD card, i.e. do
32-
not copy `dist_kit/q-tris.bit`, yet. Do empty the "Recycle Bin" or similar
33-
of your host OS between two `*.bit` copies, so that the Nexys board does not
34-
accidentally read the `*.bit` from your trash instead of the recent one.
40+
download the bitstream file `dist_kit/qnice-v14.bit` on a microSD card or
41+
a USB stick, insert it into the Nexys board and set the jumpers to read the
42+
FPGA configuration from the SD card or USB stick. Do not copy more than one
43+
`*.bit` file on the SD card, i.e. do not copy `dist_kit/q-tris.bit`, yet.
44+
Do empty the "Recycle Bin" or similar of your host OS between two `*.bit`
45+
copies, so that the Nexys board does not accidentally read the `*.bit` from
46+
your trash instead of the recent one.
3547

3648
* If you do not own a Nexys 4 DDR board, then use your VHDL development
3749
environment to synthesize QNICE-FPGA. The root file for the system
3850
is `vhdl/env1.vhdl`. Make sure that you connect at least the IO pins
39-
for PS2, VGA, UART and the two switches.
51+
for PS2, VGA, UART and the two switches. In the file `nexys4ddr/env1.ucf`
52+
you will find some advise of how to do the mapping.
4053

4154
* Attach an "old" USB keyboard supporting boot mode to the board and attach
4255
a VGA monitor. Attach the USB cable to your desktop computer, so that you
4356
can setup a serial (terminal) connection between the desktop and the FPGA.
57+
(The file `doc/constraints.txt` contains a list of known-to-work USB
58+
keyboards.)
4459

45-
* On your host computer: Open a terminal and head to the root folder of the
46-
QNICE-FPGA GIT repository.
60+
* On your host computer: Open a command line and head to the root folder of
61+
the QNICE-FPGA GIT repository.
4762

48-
* Compile the assembler and the ROM generator by entering
49-
`cc assembler/qasm.c -o assembler/qasm` and then
50-
`cc assembler/qasm2rom.c -o assembler/qasm2rom -std=c99`
51-
on the command line from the root folder of the GIT repository.
63+
* Compile the toolchain: You need to have the GNU compiler toolchain
64+
installed, particularly `gcc` and `make` will be used. Open a terminal in
65+
the QNICE root folder. Enter the following (it is important, that you `cd`
66+
into the folder):
67+
```
68+
cd tools
69+
./make-toolchain.sh
70+
```
71+
You will be asked several questions. Answer them using the default answers
72+
by pressing `Enter` instead of answering manually by choosing `y` or `n`.
73+
When done, `cd ..` back to the QNICE root folder.
5274

5375
* Compile the mandelbrot demo by entering
5476
`assembler/asm demos/mandel.asm`.
5577

56-
* On OSX, you now have an ASCII file in the clipboard/pasteboard that starts
78+
* On macOS, you now have an ASCII file in the clipboard/pasteboard that starts
5779
with the line `0xA000 0x0F80`. On other operating systems, you might see an
5880
error message, stating that `pbcopy` is not available. You can savely
5981
ignore this and manually copy the file `demos/mandel.out` into your
@@ -90,7 +112,36 @@ Getting Started
90112
VGA screen as shown in the above-mentioned screenshot. Use cursor keys
91113
and page up/down keys to scroll.
92114

93-
More documentation to come.
115+
Using the File System
116+
---------------------
117+
118+
* QNICE-FPGA supports SD Cards (microSD Cards on the Nexys 4 DDR), that are
119+
formatted using FAT32. Make sure that you read the file
120+
[doc/constraints.txt](doc/constraints.txt) to understand what works and what
121+
does not.
122+
123+
* Copy the folder `qbin from the QNICE-FPGA root folder to your SD Card. It
124+
contains some nice demo programs in the directly loadable `.out` file
125+
format.
126+
127+
* In the Monitor, enter `F` and then `D` to browse a directory.
128+
129+
* Enter `F` and then `C` and then enter `/qbin` to change into the `qbin`
130+
folder that you copied (in case you copied it to the root folder of the
131+
SD Card, otherwise enter the right path and use `/` as a delimiter for
132+
subfolders).
133+
134+
* Enter `F` and then `R` and then enter `adventure.out` to load and run a
135+
small text adventure.
136+
137+
* Browse the `qbin` folder using `F` and `D` for more `.out` files, which
138+
are QNICE demos. Particularly nice examples are:
139+
140+
* `q-tris.out` Tetris clone for QNICE-FPGA, VGA and USB keyboard mandatory
141+
* `sierpinski.out` Draws Sierpinski fractals on UART or VGA
142+
* `ttt2.out` Tic-Tac-Toe on UART or VGA
143+
* `wolfram.out` Draws cellular automata according to Wolfram's New Kind of
144+
Science
94145

95146
Q-TRIS
96147
------
@@ -109,10 +160,144 @@ next level. The game speed increases from level to level. If you clear
109160

110161
Q-TRIS uses the PS2/USB keyboard and VGA, no matter how STDIN/STDOUT
111162
are routed. All speed calculations are based on a 50 MHz CPU that is equal
112-
to the CPU revision contained in release V1.3.
163+
to the CPU revision contained in release V1.4.
164+
165+
Have a look at the current highscore in
166+
[doc/demos/q-tris-highscore.txt](doc/demos/q-tris-highscore.txt).
113167

114168
The game can run stand-alone, i.e. instead of the Monitor as the "ROM"
115169
for the QNICE-FPGA: Just use `dist_kit/q-tris.bit` instead of the
116-
above-mentioned `dist_kit/qnice.bit`. Or, you can run it regularly as an app
117-
within the Monitor environment. In this case, compile it and then load it with
118-
the `M L` command sequence and start Q-TRIS using the address `0x8000`.
170+
above-mentioned `dist_kit/qnice-v14.bit`. Or, you can run it regularly as an
171+
app within the Monitor environment:
172+
173+
* If you copied the `qbin` folder on your SD Card, you can load and run it
174+
directly from the Monitor by entering `F R` and then `/qbin/q-tris.out`.
175+
176+
* Alternately, you can open a command line, head to the root folder of
177+
QNICE-FPGA and enter this sequence to compile it:
178+
```
179+
cd demos
180+
../assembler/asm q-tris.asm
181+
```
182+
Transfer the resulting `q-tris.out` via your terminal program using
183+
Monitor's `M L` command sequence and start Q-TRIS using `C R` and the
184+
address `8000`.
185+
186+
Programming in Assembler
187+
------------------------
188+
189+
* Read the [Intro](doc/intro/qnice_intro.pdf) and have a look at the
190+
[Programming Card](doc/programming_card/programming_card_screen.pdf).
191+
192+
* The `dist_kit` folder contains important include files, that contain
193+
command shortcuts (RET, INCRB, DECRB, NOP, SYSCALL), register short names
194+
(PC, SR, SP), addresses for memory mapped I/O of peripheral devices and
195+
commonly used constants.
196+
197+
* You can choose between two assemblers: The native QNICE assembler located
198+
in the folder `assembler` and the VASM assembler, which is a part of the
199+
VBCC toolchain and which is located in `c/vasm` (source code) and in
200+
`c/vbcc/bin` (executable binary).
201+
202+
* Native QNICE assembler:
203+
204+
* A typical assembler program starts with the following sequence that first
205+
includes the above-mentioned include file `sysdef.asm` plus the definition
206+
file of the "operating system" functions `monitor.def`. Then the program's
207+
start address is set to 0x8000, which is the first address in RAM.
208+
```
209+
#include "../dist_kit/sysdef.asm"
210+
#include "../dist_kit/monitor.def"
211+
.ORG 0x8000
212+
```
213+
214+
* You can use any other address greater or equal to `0x8000` for your
215+
program. `test_programs/mandel.asm` for example uses `0xA000`. Make sure
216+
that you leave enough room for the stack, which grows from top to bottom.
217+
218+
* The folder `test_programs` contains a wealth of examples. You might want
219+
to start with `hello.asm`, which combines the classical "Hello World!"
220+
example with some more advanced things like using "operating system"
221+
functions and sub routines.
222+
223+
* VASM assembler:
224+
225+
* Each time you open a new command line (terminal) window, make sure, that
226+
you go to the folder "c" and enter `source setenv.source`, which sets
227+
up the right path and environment variables.
228+
229+
* In your command line, navigate to `c/test_programs`.
230+
231+
* Enter `qvasm vasm_test.asm`. Use the `M L` mechanism to transfer the
232+
resulting `vasm_test.out` to the RAM of QNICE. Run the program using
233+
`C R`and then `8000`.
234+
235+
* VASM has another syntax than the native QNICE assembler, so you need
236+
to use other include files. Have a look at
237+
[dist_kit/README.md](dist_kit/README.md) for more details.
238+
239+
Programming in C
240+
----------------
241+
242+
QNICE also features a fully-fledged C programming environment. This is how
243+
you are getting started:
244+
245+
* The vbcc toolchain is automatically build, when you follow the
246+
above-mentioned "Getting Started" guide and run `make-toolchain.sh`.
247+
248+
* Open a terminal and from the QNICE root folder enter `cd c`.
249+
250+
* Let's compile a small shell, that can be used to browse the microSD Card
251+
of the FPGA board. Enter the following commands:
252+
```
253+
source setenv.source
254+
cd test_programs
255+
qvc shell.c -c99
256+
```
257+
258+
* Just as described above in "Getting Started", on macOS you now have the
259+
excutable in your clipboard so that you can use the `M` `L` Monitor
260+
command to load the shell. On other operating systems you need to copy
261+
`shell.out` manually to your clipboard and then transfer it using the
262+
`M` `L` Monitor command.
263+
264+
* Run the shell using `C` `R` `8000`.
265+
266+
* Browse the microSD Card using `dir`, `cd`, `cat` and `cathex` commands.
267+
Exit the shell using `exit`.
268+
269+
* **Important hint**: You either need to run `source setenv.source` each time
270+
you open a new terminal when you want to work with C - or - you need to add
271+
the paths and the enviornment variables in your shell preferences,
272+
so that they are being set automatically.
273+
274+
* Switch from ANSI-C to C99 using the `-c99` command line switch.
275+
276+
* Standard C Library: When using the `qvc` shell script, located in the
277+
folder `c/qnice` and to which `source setenv.source` automatically sets up
278+
a path, all the include and library paths are automatically set correctly,
279+
so that you can just work with the Standard C Library as you would expect
280+
it. For example, have a look at `fread_basic.c`, which shows how to read
281+
files and some printf examples. (Make sure you run fread_basic.out while
282+
being in the folder /qbin, because only there are the text files needed
283+
by the program.)
284+
285+
* Additionally and sometimes alternatively to the Standard C Library, you
286+
might want to use the "operating system" library aka the Monitor library.
287+
All include and library paths are set, so just include `qmon.h` for
288+
getting started. You find it in `c/qnice/monitor-lib/include`. The
289+
above-mentioned `shell.c` is an example of how to read files without
290+
using the Standard C library but by directly using Monitor functions.
291+
292+
Acknowledgements
293+
----------------
294+
295+
* [sy2002](http://www.sy2002.de): Creator and maintainer of QNICE-FPGA:
296+
hardware development (VHDL), FAT32 library, additional Monitor libraries and
297+
functions, Q-TRIS, additional QNICE specific vbcc toolchain.
298+
299+
* [vaxman](http://www.vaxman.de): Inventor of the [QNICE ISA](http://qnice.sourceforge.net):
300+
system architect, assembler, emulator, Monitor and Monitor libraries, tools.
301+
302+
* [Volker Barthelmann](http://www.compilers.de): vbcc compiler system,
303+
QNICE specific vbcc backend incl. standard C library.

0 commit comments

Comments
 (0)