User Tools

Site Tools


notes:comporg:spring2025:projects:mtb1

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
notes:comporg:spring2025:projects:mtb1 [2025/02/17 18:40] – [Defining Region] cgrant9notes:comporg:spring2025:projects:mtb1 [2025/02/20 03:33] (current) – [How to check if our sprite has reached a bound] tkastne1
Line 24: Line 24:
 In Assembly the process is similar, as the command is simply: In Assembly the process is similar, as the command is simply:
 <code> <code>
-out GPU_SelectedTexture #+out GPU_SelectedTexture texture_id
 </code> </code>
-Where the # is either the immediate value of the texture id, or a register containing the texture id+Where texture_id is either the immediate value of the texture id, or a register containing the texture id\\ 
 +**NOTE: To select any BIOS texture, such as the built in font, you need to use the texture id -1**
 ====Defining Region==== ====Defining Region====
 Defining a region is where assembly becomes much less simple, as in C one can use a variety of built in functions that handle everything, whereas in assembly we have to send the GPU every value ourselves Defining a region is where assembly becomes much less simple, as in C one can use a variety of built in functions that handle everything, whereas in assembly we have to send the GPU every value ourselves
Line 42: Line 43:
 Once again with # corresponding to an immediate value or register containing the values we want to input Once again with # corresponding to an immediate value or register containing the values we want to input
 ====Selecting Region==== ====Selecting Region====
 +Selecting texture is where the Assembly code once again directly mirrors the C code, as the instruction to select a region is simply: 
 +<code> 
 +out GPU_SelectedRegion region_id 
 +</code> 
 +**NOTE: if you are trying to print text, the region_id for each character is the ASCII value associated with it.\\ 
 +For example, to print the character '0' to the screen you need to use region_id 0x30 or 48<fs x-small>10</fs>**
 =====Check for keypresses===== =====Check for keypresses=====
  
 ====Selecting joystick==== ====Selecting joystick====
 +Selecting a joystick is very similar to the C process and only takes one command.
 +In C, we use:
 +<code>
 +select_gamepad( gamepadID );
 +</code>
 +Where gamepadID is the value of the gamepad you wish to select.
 +
 +In assembly we use:
 +<code>
 +out INP_SelectedGamepad, gamepadID
 +</code>
 +Where again, gamepadID is the gamepad we wish the use.
 +
  
 ====Reading joystick value==== ====Reading joystick value====
 +Reading the joystick values is also similar to the C version, the C version is the following:
 +<code>
 +variableName = gamepad_left();
 +</code>
 +Where variableName is a integer variable
  
 +In assembly we use registers instead of variables to store the returned value
 +<code>
 +in R0, INP_GamepadLeft
 +</code>
 +Reading the other directions can be done by using up/down/right instead of left
 ====translating read joystick value into X and Y==== ====translating read joystick value into X and Y====
 +The value returned by the gamepad is the number of frames it has been in that state
  
 +This value can be converted into a boolean with ige:
 +<code>
 +ige R0, 0
 +</code>
 +Where R0 is a joystick direction value
 +
 +After you have the boolean version, you can either use a conditional jump to a label that does whatever you want when a certain direction is pressed, or directly add/subtract the value to the x/y position
 +<code>
 +jt R0 _label
 +</code>
 +or
 +<code>
 +iadd R1, R0
 +</code>
 +Where R1 is a x/y position
 =====Playfield bounds checking===== =====Playfield bounds checking=====
  
Line 56: Line 101:
  
 ====How to check if our sprite has reached a bound==== ====How to check if our sprite has reached a bound====
 +Checking the bounds of the screen can be done using greater than/less than instructions
  
 +Remember that instructions overwrite the register
 +<code>
 +mov R0, R1
 +ilt R0, YMIN
 +jt  R0, _upper_bound
 +</code>
 +and
 +<code>
 +mov R0, R1
 +igt R0, YMAX
 +jt  R0, _lower_bound
 +</code>
 +Where R1 is a the y position and YMIN/YMAX are the min and max bounds
 ====How to limit our sprite from leaving the playfield==== ====How to limit our sprite from leaving the playfield====
  
 ====How to cause our sprite to wrap-around on the playfield==== ====How to cause our sprite to wrap-around on the playfield====
  
notes/comporg/spring2025/projects/mtb1.1739817658.txt.gz · Last modified: 2025/02/17 18:40 by cgrant9