spo600:6502_math_lab
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
spo600:6502_math_lab [2024/09/17 18:58] – chris | spo600:6502_math_lab [2025/01/29 16:25] (current) – [In-Class Lab: Mob Programming] chris | ||
---|---|---|---|
Line 29: | Line 29: | ||
==== In-Class Lab: Mob Programming ==== | ==== In-Class Lab: Mob Programming ==== | ||
- | //Mob Programming// | + | //[[https:// |
Follow these steps: | Follow these steps: | ||
- You will be assigned to a Zoom breakout group. Within the group, select someone to be the initial " | - You will be assigned to a Zoom breakout group. Within the group, select someone to be the initial " | ||
- | | + | - Decide on how you're going to share the final code between members of your group. This might be as simple as pasting it into the Zoom chat (Caution!), or you could use a [[https:// |
- | | + | |
- Have the Driver share their screen with the group. | - Have the Driver share their screen with the group. | ||
- Collaborate with the Driver using audio and/or video. In Pair or Mob Programming, | - Collaborate with the Driver using audio and/or video. In Pair or Mob Programming, | ||
- | - Feel free to switch the driver periodically as you see fit. | + | - It can be a good idea to switch the driver periodically as you see fit. |
- Perform the lab as outlined below. | - Perform the lab as outlined below. | ||
- | |||
==== Setup ==== | ==== Setup ==== | ||
Line 48: | Line 46: | ||
==== Initial Code ==== | ==== Initial Code ==== | ||
- | 2. The following code moves a graphic | + | 2. The following code moves a 5x5 graphic |
< | < | ||
- | ; TEST CODE FOR OUR SUBROUTINE | + | ; |
+ | ; draw-image-subroutine.6502 | ||
+ | ; | ||
+ | ; This is a routine that can place an arbitrary | ||
+ | ; rectangular image on to the screen at given | ||
+ | ; coordinates. | ||
+ | ; | ||
+ | ; Chris Tyler 2024-09-17 | ||
+ | ; Licensed under GPLv2+ | ||
+ | ; | ||
- | ; SET UP STRUCTURE IN MEMORY | + | ; |
- | LDA #< | + | ; The subroutine is below starting at the |
- | STA $10 | + | ; label " |
- | LDA #>G_X | + | ; |
- | STA $11 | + | |
- | LDA #$05 | + | |
- | STA $12 ; IMAGE WIDTH | + | |
- | STA $13 ; IMAGE HEIGHT | + | |
- | LDA #$00 | + | ; Test code for our subroutine |
- | STA XPOS | + | ; Moves an image diagonally across the screen |
- | STA YPOS | + | |
+ | ; Zero-page variables | ||
+ | define XPOS $20 | ||
+ | define YPOS $21 | ||
+ | |||
+ | |||
+ | START: | ||
+ | |||
+ | ; Set up the width and height elements of the data structure | ||
+ | LDA #$05 | ||
+ | STA $12 ; IMAGE WIDTH | ||
+ | STA $13 ; IMAGE HEIGHT | ||
+ | |||
+ | ; Set initial position X=Y=0 | ||
+ | LDA #$00 | ||
+ | STA XPOS | ||
+ | STA YPOS | ||
+ | |||
+ | ; Main loop for diagonal animation | ||
MAINLOOP: | MAINLOOP: | ||
- | | + | |
+ | ; Set pointer to the image | ||
+ | ; Use G_O or G_X as desired | ||
+ | ; The syntax #<LABEL returns the low byte of LABEL | ||
+ | ; The syntax #>LABEL returns the high byte of LABEL | ||
LDA #<G_O | LDA #<G_O | ||
STA $10 | STA $10 | ||
Line 73: | Line 98: | ||
STA $11 | STA $11 | ||
- | ; CALL THE SUBROUTINE | + | ; Place the image on the screen |
- | LDA #$10 ; LOCATION OF DATA STRUCTURE | + | LDA #$10 ; Address in zeropage of the data structure |
- | LDX XPOS | + | LDX XPOS ; X position |
- | LDY YPOS | + | LDY YPOS ; Y position |
- | JSR DRAW | + | JSR DRAW ; Call the subroutine |
- | LDY #$FF | + | |
+ | | ||
LDX #$50 | LDX #$50 | ||
DELAY: | DELAY: | ||
Line 87: | Line 113: | ||
BNE DELAY | BNE DELAY | ||
+ | ; Set pointer to the blank graphic | ||
LDA #< | LDA #< | ||
STA $10 | STA $10 | ||
Line 92: | Line 119: | ||
STA $11 | STA $11 | ||
+ | ; Draw the blank graphic to clear the old image | ||
LDA #$10 ; LOCATION OF DATA STRUCTURE | LDA #$10 ; LOCATION OF DATA STRUCTURE | ||
LDX XPOS | LDX XPOS | ||
Line 97: | Line 125: | ||
JSR DRAW | JSR DRAW | ||
+ | ; Increment the position | ||
INC XPOS | INC XPOS | ||
INC YPOS | INC YPOS | ||
+ | |||
+ | ; Continue for 29 frames of animation | ||
LDA #28 | LDA #28 | ||
CMP XPOS | CMP XPOS | ||
BNE MAINLOOP | BNE MAINLOOP | ||
- | JMP $0600 | + | ; Repeat infinitely |
+ | | ||
; ========================================== | ; ========================================== | ||
Line 223: | Line 255: | ||
; ========================================== | ; ========================================== | ||
+ | ; 5x5 pixel images | ||
+ | |||
+ | ; Image of a blue " | ||
G_O: | G_O: | ||
DCB $00, | DCB $00, | ||
Line 230: | Line 265: | ||
DCB $00, | DCB $00, | ||
+ | ; Image of a yellow " | ||
G_X: | G_X: | ||
DCB $07, | DCB $07, | ||
Line 237: | Line 273: | ||
DCB $07, | DCB $07, | ||
+ | ; Image of a black square | ||
G_BLANK: | G_BLANK: | ||
DCB $00, | DCB $00, | ||
Line 244: | Line 281: | ||
DCB $00, | DCB $00, | ||
</ | </ | ||
- | |||
- | 3. Test the code by pressing the Assemble button, then the Run button. If the there are any errors assembling (compiling) the code, they will appear in the message area at the bottom of the page. Make sure the code is running correctly and that you understands how it works. Don't be afraid to experiment! | + | 3. Test the code by pressing the Assemble button, then the Run button. You can adjust the speed slider as needed. If the there are any errors assembling (compiling) the code, they will appear in the message area at the bottom of the page. Make sure the code is running correctly and that you understands how it works. Don't be afraid to experiment! |
==== Bouncing Graphic ==== | ==== Bouncing Graphic ==== | ||
Line 252: | Line 288: | ||
4. Select a starting location for the graphic where X and Y have different values. | 4. Select a starting location for the graphic where X and Y have different values. | ||
- | 5. Select an X increment that is -1 or +1, and a Y increment that is -1 or +1. | + | 5. Select an X increment that is -1 or +1, and a Y increment that is -1 or +1. You can choose to use either a signed byte or some other representation to hold these values. |
6. Successively move the graphic by adding the X and Y increments to the graphic' | 6. Successively move the graphic by adding the X and Y increments to the graphic' | ||
- | 7. Make the graphic bounce when it hits the edge of the bitmapped screen, both vertically (when it hits the top/bottom) and vertically | + | 7. Make the graphic bounce when it hits the edge of the bitmapped screen, both vertically (when it hits the top/bottom) and horizontally |
---- | ---- | ||
Line 266: | Line 302: | ||
==== Challenges (Optional, Recommended) | ==== Challenges (Optional, Recommended) | ||
- | Try these experiments: | + | Here are some challenges for further experimentation if you're interested: |
- | - Permit values other than -1 and +1 for the X and Y increments. | + | |
- | - Permit fractional values for the X and Y increments (e.g., +1.5 or -0.75) | + | |
- | - Change the graphic each time it bounces. | + | * Perturb (subtly disrupt or randomize) the ball's position or bounce so that it is not overly predictable. (Remember that there' |
+ | * Change the graphic | ||
==== Write-Up | ==== Write-Up |
spo600/6502_math_lab.1726599538.txt.gz · Last modified: 2024/09/17 18:58 by chris