This is an old revision of the document!
To update your vircon DevTools to v24.2.4, go to this link
https://github.com/vircon32/ComputerSoftware/releases/tag/devtools-v24.2.4
Then, depending on the system you use for class, follow the appropriate steps on the github page to install. There is even a section labeled “How to Install.”
With the new version of dev-tools, you can use %define to clean up your code, making it more readable and easier to detect errors. (example of this is in the 06b_hello_define directory within the public directory.
The examples we went over in class can be found in the public class directory under “examples.” To get to the public class directory cd into /var/public/spring2024/comporg/examples.
To have your snake food spawn randomly, we will use the built-in random function that is offered by Vircon32. In C, it is extremely simple to implement. You would simply do the following:
#include "misc.h" #include "time.h" // Seeding srand srand(get_time()); // Getting random X and Y cords for apple int xApple = rand() % (screen_width); int yApple = rand() % (screen_height);
So we simply just include the .h file that holds the function, seed srand and then use rand() and specify the range. But in asm we dont need to include any files.
Seeding srand in asm:
in R0, TIM_CurrentTime out RNG_CurrentValue, R0
So this first spot is the equivalent of seeding srand with get_time. We are getting the time and storing it in R0 and then feeding it into RND_CurrentValue.
; X value in R0, RNG_CurrentValue imod R0, 620 mov R14, R0 ; Y value in R0, RNG_CurrentValue imod R0, 320 mov R15, R0
Looking at the above, we are getting a random value between 0 and 620 and storing that in R0. we then feed that into R14. This is our X value for the food. We then repeat the same steps for the y value for the food.
Make sure your object moves at a predictable speed (example: 1 pixel at a time), for if you don't. Then you run the risk of the objects not touching again, as the random value will have a random number assigned to it. Imagine your speed is 5 pixels, then your object will only be able to land on the food in the 2/10 chance it lands in a position ending in 0 or 5.
Remember to add one to the result if your region bounds happen to be at 0, as although unlikely, the fruit can still spawn at 0,0 causing an unfortunate game over. You can add to the random number with iadd R0, 1. This snippet of code will add one to R0.
Vircon has 16 registers (0-15) with 14 and 15 being reserved for stack purposes.
mov R0, 1
iadd R0, 1
A register will also store a “yes” or “no” value from certain operation like “ige” is greater than or equal.
ige R0, 1
mov R1, R0
Instructions are things that can be done to effect registers, memory addresses, and where you are in your code. There are many different types of instruction sets, for example: