User Tools

Site Tools


notes:comporg:spring2025:projects:mtb2

This is an old revision of the document!


Pong

scoring

Scoring in pong is as simple as checking if the ball has left the screen; if it crosses the left side the right player gets a point, and vice versa.

For our purposes, we can check if the ball's x position has exceeded 640 or subceeded 0

score storage

score display

Displaying the player's scores is where things start to get more complex, as we no longer have built in 'itoa' or 'print' functions, so we will have to build them manually.

First off, and debatably more complex portion, is creating an itoa function
To do this we can break down what we need to get printable characters from any arbitrary number
That process requires getting each digit from our number, ie to print 104, we need to have print a 1, a 0, and a 4, as they are all separate regions is the BIOS texture
One possible way of doing this is to use math to pick apart a number from right to left, converting each digit to its ASCII value, and store them, in a process that may look like:

   MOV  R0,   104
   MOV  R1,    R0   ; Store a copy of the original into R1
_itoa:
   MOV  R2,    R1   ; Store a copy of the number into R2
   IMOD R2,    10   ; Retrieve the last digit from the copy
   IADD R2,  0x30   ; Convert the number to its ASCII value
   PUSH R2          ; Store the digit onto the stack
   IDIV R1,    10   ; Remove the last digit from the original
   MOV  R3,    R1   ;                   ;
   IEQ  R3,     0   ; Repeat until zero ;
   JF   R3, _itoa   ;                   ;

Once we have each character we want to print, printing them is a simple matter
The process may look like:

   %define SELREG GPU_SelectedRegion
   %define SELTEX GPU_SelectedTexture
   %define DRAWX GPU_DrawingPointX
   %define DRAWY GPU_DrawingPointY
   %define GPUCOM GPU_Command
   %define DRAWREG GPUCommand_DrawRegion
   
   ...
   
   OUT  SELTEX,        -1    ; Select the BIOS texture
   MOV  R0,             0    ; Place a dummy value onto the stack ;
   PUSH R0                   ;                                    ;
   CALL _itoa                ; (assuming itoa has a RET instruction)
_innerloop:
   POP  R0                   ; Retrieve the first character
   MOV  R1,            R0
   IEQ  R1,             0
   JF   R1,       _return
   OUT  SELREG,        R0    ; Set the region
   OUT  DRAWX,         RX    ; Set the x position (whatever register contains the xpos)
   OUT  DRAWY,          #    ; Set the y position
   OUT  GPUCOM,   DRAWREG    ; Draw the character
   IADD RX,            10    ; Move xpos to next open space
   JMP  _innerloop
_return:
   RET

computer operated player

determining computer paddle movement

difficulty of computer player

notes/comporg/spring2025/projects/mtb2.1740440600.txt.gz · Last modified: 2025/02/24 23:43 by cgrant9