User Tools

Site Tools


notes:comporg:spring2024:projects:dapx

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:spring2024:projects:dapx [2024/03/20 10:42] – [debugmemory function] wgates1notes:comporg:spring2024:projects:dapx [2024/03/24 19:49] (current) – [Debug Registers] wgates1
Line 62: Line 62:
 ret ret
 </code> </code>
 +
 +=====Preserving our Textures=====
 +When making our debug function, we want it to strictly print out text and nothing else, if it were to do anything else than print out the text this can be perceived as an error and something that needs to be fixed. In order to preserve our texture we need to push it onto the stack before we execute the debug and pop it off the stack after debug has finished its run.
 +<code asm>
 +  in R0, GPU_SelectedTexture
 +  Push R0
 +  in R0, GPU_SelectedRegion
 +  PUSH R0
 +  POP R0
 +  out GPU_SelectedRegion, R0
 +  POP R0
 +  out GPU_SelectedTexture, R0
 +</code>
 +Remember Pop in the reverse order of what you pushed and to push with a register you have already pushed to the stack in order to preserve that register as well. In this example you should push R0, and after the last out POP R0, to fully preserve the texture/registers.
 +
 +Now that you have preserved the registers and textures you are free to change them as you please. Remember that the BIOS texture that you need to use to print out the ascii text for all your outputs is -1.
 +
 +<code asm>
 +  out GPU_SelectedTexture, -1
 +</code>
 +
 +And now that you are preserving your textures, it will go back to whatever you had before calling _debug. This can be extremely helpful if you are only using one texture for the whole game.
 =====bitwise operations===== =====bitwise operations=====
  
Line 146: Line 168:
  
 You will want to use a register to shift (see the bitwise example in the public directory). The shift is used to keep track of the number of bits to shift the mask when extracting each nibble from the value when converting the variable to hexadecimal. It ensures that the correct number of bits are extracted from the variable during each iteration of the loop subroutine used for conversion. The 28th bit is the most significant nibble. To go to the next nibble, shift right 4 (shift left -4).  You will want to use a register to shift (see the bitwise example in the public directory). The shift is used to keep track of the number of bits to shift the mask when extracting each nibble from the value when converting the variable to hexadecimal. It ensures that the correct number of bits are extracted from the variable during each iteration of the loop subroutine used for conversion. The 28th bit is the most significant nibble. To go to the next nibble, shift right 4 (shift left -4). 
 +
 +To extract the digits of a two-digit number (e.g.,10, 11, 12, etc.), you can use division by 10 to find the quotient (tens digit) and modulus operation to find the remainder (ones digit). 
 =====pseudocode===== =====pseudocode=====
  
Line 312: Line 336:
 </code> </code>
  
-Notice how in displaying the value at a given memory address we put brackets around the register which is important to note+Notice how in displaying the value at a given memory address we put brackets around the register and then move that into another register (R6 in this case) and then push R6 instead of the original R1
 ======debugregister function====== ======debugregister function======
 =====dapX imagery=====  =====dapX imagery===== 
Line 357: Line 381:
  
 *ior - "inclusive or" *ior - "inclusive or"
 +
 +
 +======Debug Registers======
 +
 +===Printing out R:===
 +To print the registers you have to figure out how to print out the R, the :, and the number that goes along with it. In this it is important to note that the ascii value for R is 82, and the ascii value for : is 58. Thus printing these out sequentially will look something like this. Remember to have your texture set to -1 so the text shows up.
 +
 +<code asm>
 +    mov R0, 82 ; printing R
 +    out  GPU_SelectedRegion, R0
 +    out  GPU_DrawingPointX, R1
 +    out  GPU_DrawingPointY, R2
 +    out  GPU_Command, GPUCommand_DrawRegion
 +    iadd R1, 10
 +    
 +    ;Print out the number here
 +    
 +    mov R0, 58 ; printing :
 +    out  GPU_SelectedRegion, R0
 +    out  GPU_DrawingPointX, R1; X value
 +    out  GPU_DrawingPointY, R2; Y value
 +    out  GPU_Command, GPUCommand_DrawRegion
 +</code>
 +
 +To print out the number in the middle, we first need to check if the number is greater than 10. If it is then we print out a 1 then subtract 10 from it, this is so we can do a ascii shift with the second number that changes it to the number we want to print.
 +
 +<code asm>
 +    ;R5 holds the value we want to print.
 +    mov R1, R5
 +    mov R2, R5
 +    ige R2, 10
 +    jf R2, _less_than_10
 +
 +    ;printing out a 1
 +    mov R0, 49
 +    out  GPU_SelectedRegion, R0
 +    out  GPU_DrawingPointX, R3
 +    out  GPU_DrawingPointY, R4
 +    out  GPU_Command, GPUCommand_DrawRegion
 +    iadd R3, 10
 +
 +    isub R1, 10 ;we subtract 10 as 1 has already been printed
 +
 +    _less_than_10:
 +    iadd R1, 48 ;ascii shift by 48 to print out the number
 +    out  GPU_SelectedRegion, R1
 +    out  GPU_DrawingPointX, R3
 +    out  GPU_DrawingPointY, R4
 +    out  GPU_Command, GPUCommand_DrawRegion
 +</code> 
 +
 +The last step is to put both of these together in a loop, remember to change the X/Y at the end of the loop.
 +
 +===Printing registers===
 +
 +===Debugging our debugregs Subroutine===
 +Trying to get your debugregs to have the correct output is challenging, but by far the best way to see if you have the correct output is by tossing in some random values into each register that you display to see if you have the correct output. Here is an example of that.
 +
 +<code asm>
 +mov R0, 0x00000000
 +mov R1, 0x00000001
 +mov R2, 0x00000002
 +mov R3, 0x00000003
 +mov R4, 0x00000004
 +mov R5, 0x00000005
 +</code>
 +
 +You repeat this above process for registers from 0 to 13. It is important to note that you do this right before you call the subroutine so the values that you just put in don't get wiped out from your previous ASM code. 
 +
 +
 +
 +===Calling debugregs===
 +As we have worked on these dap projects, the process of calling such debug subroutines has become simpler. With dap0, we had to have the following in our program: 
 +<code asm>
 +       mov  TMP, R8
 +       push TMP
 +       mov  TMP, 100
 +       push TMP
 +       mov  TMP, 200
 +       push TMP
 +       call          _debug
 + </code>
 +Then later after the hlt, you'll always have the %include "debug.s" for all the dap projects.
 +
 +Concerning dap2, we have drastically simplified the process of debugging. All that is need is just one line, Not accounting for the include line. Put the following to use your debug registers subroutine:
 +
 +<code asm>
 +call _debugregs
 +</code>
notes/comporg/spring2024/projects/dapx.1710945752.txt.gz · Last modified: 2024/03/20 10:42 by wgates1