Kendryte K210 running Quake 1
This will show how you can get Quake 1 running on an MCU.
Installing the SDK and compiler
For the installation of SDK and compiler you can find instructions here. SDK and compiler must be installed before you can start with the following steps.
Compile Quake 1 for the K210
The source code contains only the engine itself, but no other files like graphics or levels. This data can be taken from the Quake 1 shareware version, or from an installed full version. Quake 1 can still be purchased DRM free legally at GOG.com.To compile Quake 1 we have to clone the source code from the Git repository of elect_gombe. To do this we open a terminal or terminal window and navigate with cd ~/kendryte-standalone-sdk/src/ to the project folder of the K210 SDK. Here we clone now with git clone https://github.com/elect-gombe/quake-k210.git the source code, so that a quake-k210 folder is created.
Now we have to overwrite some files of the SDK with the ones from the quake-k210 folder. In the still open terminal we copy a modified linker file into the SDK with cp quake-k210/additionalparts/kendryte.ld ../lds/kendryte.ld. With cp quake-k210/additionalparts/compile-flags.cmake ../cmake/compile-flags.cmake modified compiler flags, i.e. parameters for compiling the source code, are copied into the SDK. This is necessary because the source code of Quake 1 still contains code parts that cannot be compiled with the modern settings of today's compilers. In the folder ./quake-k210/additionalparts/ there is a crt.S-replace file. This needs a few modifications so that we can use it with the current SDK. With nano ~/kendryte-standalone-sdk/src/quake-k210/additionalparts/crt.S-replace the crt.S-replace is opened. In this file are the first few lines of source code, here assembler, which the K210 executes. Additionally some interrupts are handled here. Since this file was modified at a time when Standalone SDK and FreeRTOS SDK were still intertwined, there are a few entries here that cause errors when compiling and linking. It is necessary to delete the assembler instructions in the trap_entry section from line 166 to line 160. Between line 133 and line 140 there should be only the following:
133 trap_entry:
134 addi sp, sp, -REGBYTES
135 sd t0, 0x0(sp)
136
137 .handle_other:
138 ld t0, 0x0(sp)
139 addi sp, sp, REGBYTES
140 addi sp, sp, -64*REGBYTES
134 addi sp, sp, -REGBYTES
135 sd t0, 0x0(sp)
136
137 .handle_other:
138 ld t0, 0x0(sp)
139 addi sp, sp, REGBYTES
140 addi sp, sp, -64*REGBYTES
When the file is adjusted accordingly, this must be saved. Now copy the file to the appropriate place in the SDK. To do this, enter cp ~/kendryte-standalone-sdk/src/quake-k210/additionalparts/crt.S-replace ~/kendryte-standalone-sdk/lib/bsp/crt.S in the terminal.
In the still open terminal we change now with cd ~/kendryte-standalone-sdk/build/ into the build directory of the SDK. In order to have no remainders of earlier projects in the build directory, we empty it with rm * -r. With cmake ... -DPROJ=quake-k210 -DTOOLCHAIN=/opt/kendryte-toolchain/bin the project is now prepared.
Although 8MB of SRAM is available, this is very tight for Quake 1. We need the AI RAM for Quake. For this we change with cd ~/kendryte-standalone-sdk/lib/. With nano CMakeLists.txt now adjustments must be made to the file. The CMakeLists.txt contains in line 5 ADD_SUBDIRECTORY(nncase) this is commented out by a # and results in #ADD_SUBDIRECTORY(nncase). In line 45 now also TARGET_LINK_LIBRARIES(kendryte PUBLIC nncase) must be commented out, so that #TARGET_LINK_LIBRARIES(kendryte PUBLIC nncase) is in line 45. Save the changes.
With nano ~/kendryte-standalone-sdk/src/quake-k210/source/sys_ctr.c we open the file with the quake_main. In line 378 and line 379 5.5MB RAM are allocated. Here we have to reduce the value. As minimum value we can use MINIMUM_MEMORY here. This value is defined in the Quake source code and determines the smallest amount of memory Quake starts with. For Quake 1 and the shareware version this is sufficient. Line 378 is then parms.memsize = MINIMUM_MEMORY; .
Now Quake can be compiled. To do this change to the build directory with cd ~/kendryte-standalone-sdk/build/ in the still open terminal and type make. The result is a quake-k210.bin in the build directory which can now be written to the K210. The klash_gui is used for this.
You have to prepare a SD-card by copying the id1 from Quake 1. If everything is successfully copied, flashed and assembled, Quake 1 should start after insertion and the demos should run.
Discussie (0 opmerking(en))