User Tools

Site Tools


notes:comporg:spring2024:projects:cta0

This is an old revision of the document!


CTA0

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.

The examples we went over in class can be found in the public class directory under “examples”:

cd /var/public/spring2024/comporg/examples

the most recent example is 06_hello_memory

Assembly

Random Spawn

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 a 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.

Text Area

Data

Registers

Vircon has 16 registers (0-15) with 14 and 15 being reserved for stack purposes

  • Registers are used to store values/data in
  • For example in R0 we are storing a value of 1
  mov R0, 1
  • We can also modify the values in R0
  iadd R0, 1
  • This will make R0 = 2

A register will also store a “yes” or “no” value from certain operation like “ige” is greater than or equal

  ige R0, 1
  • This checks if R0 is greater than or equal to 1. If so it returns a 1 for true which will then be stored in R0 and the 2 will be lost forever
  • But if you wanted to save the 2 in R0, before the “ige” you could
  mov R1, R0
  • This will copy the 2 in R0 to R1

Instructions

notes/comporg/spring2024/projects/cta0.1709079403.txt.gz · Last modified: 2024/02/28 00:16 by cmazzara