Skip to content

Commit

Permalink
Added readme
Browse files Browse the repository at this point in the history
  • Loading branch information
kasper201 committed Apr 8, 2024
1 parent 2fc8d31 commit 303d1d0
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 4 deletions.
84 changes: 80 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,87 @@
# How to install and run the project will be put here:
# Pre-installation

## How to update images
Zephyr version: 3.5 or later
CMake Version: 3.27.4
OS: Windows 11 23H2 or later
Vivado version: 2023.2
Board: STM NUCLEO-F030R8 (or better)

Updating images is done by replacing the .coe files in the vivado project.
# Installation

## Hardware:

[WIP]

## STM32

*[WIP]*
If you are using an STM NUCLEO-F030R8 one can simply follow the [zephyr tutorial](https://docs.zephyrproject.org/latest/develop/getting_started/index.html#build-the-blinky-sample) but instead of `samples\basic\blinky` it should direct to the folder containing the cmake and build files for this project.

## FPGA

To install the game on the FPGA first open the project in Vivado.
1. If there is no bitstream generated generate one. The option to generate a bitscream can be found in 'PROGRAM AND DEBUG'.
2. A few popups will appear Select OK on everything and wait.
3. Now you will either receive an error message or a popup that the bitstream has been generated. If the latter was the case continue to 4. Otherwise, check the error and continue to the topic: errors FPGA
4. In the hardware manager press on 'Open target' if no hardware target is open and press Auto Connect.
![Open Target](image.png)
5. After connecting to the FPGA press 'Program device' and then 'OK'. Now the device should get programmed.
![Program device](image-1.png)

### errors FPGA

It is possible that when generating a bitstream results in an error. There are many options however most are the following:
1. "error: no error" This error may be ignored and you can continue as normal.
2. "Constraint error" It is likely that you have accidentally renamed a variable in the main or constraints file or forgotten to add it to the constraints file.
3. "Timing constraints error" You might have added timing constraints to which the device was not built. One should either try to fix these by delving into the code or remove the timing constraints from the constraints file.
4. "Mismatched size ..." Match the size of the mismatched variables. Make sure to modify the correct variable since that has affect on how the program runs and how many variables you might have to change.

## Controls

There are 7 buttons for the user to interact with. There are 2 buttons to navigate the shop menu and 4 to navigate around the field.
There also is a button to confirm a purchase which places the selected plant from the menu on the location of the selector on the field.
![overview controlls](<System Overview - Page 1.png>)

# Modifying the program

## Update Sprites

Updating the sprites is done by replacing the .coe files in the vivado project.
It is important to note that a sprite must be 80x80 pixels

### How to convert png's to .coe files

1. locate the file you want to convert
2. download [matlab](https://www.mathworks.com/products/matlab.html)
3. open matlab
4. download the [converter]()
4. download the converter (img2coe.m)
5. Replace the *[path/to/file.png]* with the actual path to the file you want to convert.

### Replacing the sprite

1. Open the project and locate the sprite you want to replace.
2. Rightclick on the image you want to replace and give the path to the new sprite.
![replace file](<WhatsApp Image 2024-04-08 at 22.12.07.jpeg>)

3. In the ROM that matches the sprite you want to replace change the path to the path of your new sprite.
These ROM blocks can be found in main->vROM.
![load memory init coe](<WhatsApp Image 2024-04-08 at 22.13.58.jpeg>)

4. After replacing the path let it generate a new Block Memory.
5. When you're sure you've made all changes you can generate a new bitstream and program the device.

## Update text

Most text used in the game can be changed from main->textComp. Here one should look for the text they want changed.
The text is saved directly in the portmap for simplicity. When changing the text one should be careful and make sure they too change the 'textLength' to the length of the total amount of characters in 'displayText'.
![portmap example](<WhatsApp Image 2024-04-08 at 22.41.08.jpeg>)
After changing the length of 'displayText' and 'textLength' it might be necessary to change the horizontal position of the text. This can be done in 'position'.

## Change music

<!--To change the music in the game one has to manually change the variables to 2 times their actual frequency.-->
[WIP]

## Change damage sound

[WIP]
Binary file added System Overview - Page 1(1).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added System Overview - Page 1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added WhatsApp Image 2024-04-08 at 22.12.07.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added WhatsApp Image 2024-04-08 at 22.13.58.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added WhatsApp Image 2024-04-08 at 22.41.08.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 54 additions & 0 deletions img2coe.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
function img2 = img2coe(imgfile, outfile)
% Create .coe file from .jpg image
% .coe file contains 12-bit words
% each 12bits contains one 12-bit pixel
% color byte: [R3,R2,R1,R0,G3,G2,G1,G0,B3,B2,B1,B0]
% img2 = img2coe(imgfile, outfile)
% img2 is 8-bit color image
% imgfile = input .jpg file
% outfile = output .coe file
% Example:
% img2 = img2coe('loons240x160.jpg', 'loons240x160.coe');
img = imread('[path/to/file.png');
height = size(img, 1);
width = size(img, 2);
s = fopen('outputFile.coe','w+'); %opens the output file
fprintf(s,'%s\n','; VGA Memory Map ');
fprintf(s,'%s\n','; .COE file with hex coefficients ');
fprintf(s,'; Height: %d, Width: %d\n\n', height, width);
fprintf(s,'%s\n','memory_initialization_radix=16;');
fprintf(s,'%s\n','memory_initialization_vector=');
cnt = 0;
img2 = img;
for r=1:height
for c=1:width
cnt = cnt + 1;
R = img(r,c,1);
G = img(r,c,2);
B = img(r,c,3);
Rb = dec2bin(R,8);
Gb = dec2bin(G,8);
Bb = dec2bin(B,8);
img2(r,c,1) = bin2dec([Rb(1:4) '0000']);
img2(r,c,2) = bin2dec([Gb(1:4) '0000']);
img2(r,c,3) = bin2dec([Bb(1:4) '0000']);
Outbyte = [ Rb(1:4) Gb(1:4) Bb(1:4) ];
if (Outbyte(1:8) == '00000000')
fprintf(s,'00%X',bin2dec(Outbyte));
elseif (Outbyte(1:4) == '0000')
fprintf(s,'0%X',bin2dec(Outbyte));
else
fprintf(s,'%X',bin2dec(Outbyte));
end
if ((c == width) && (r == height))
fprintf(s,'%c',';');
else
if (mod(cnt,32) == 0)
fprintf(s,'%c\n',',');
else
fprintf(s,'%c',',');
end
end
end
end
fclose(s);

0 comments on commit 303d1d0

Please sign in to comment.