====== 6502 Math Lab ====== In this lab, you will continue learning some of the basics of [[6502]] assembly language, in preparation for learning more complex x86_64 and AArch64 assembly language. ===== Resources ===== * Background knowledge * [[Computer Architecture]] basics * [[Assembly Language]] vs [[Machine Language]] * [[Assembler Basics]] * [[6502]] - Basic information about the processor * [[6502 Addressing Modes]] * [[6502 Instructions]] * [[6502 Jumps, Branches, and Procedures]] * [[6502 Math]] * [[6502 Emulator]] * Opcode/Instruction References * On this Wiki * [[6502 Instructions]] * [[6502 Addressing Modes]] * External * [[https://www.pagetable.com/c64ref/6502/?tab=2|6502 instructions via the "Ultimate Commodore 64 Reference" site]] * [[http://www.6502.org/tutorials/6502opcodes.html|6502 Opcodes with Register Definitions]] * [[https://www.masswerk.at/6502/6502_instruction_set.html|6502 Opcodes with Detailed Operation Information]] * [[https://docs.google.com/spreadsheets/d/1a1-ZZ1opY8xcuUHNxj3YW75dxOPynSuP2-QGSvZGzYY/edit?usp=sharing|Spreadsheet of bitmapped display memory locations]] ===== Lab 2 ===== ==== In-Class Lab: Mob Programming ==== //[[https://en.wikipedia.org/wiki/Team_programming#Mob_programming|Mob Programming]]// is an extended form of [[https://en.wikipedia.org/wiki/Pair_programming|Pair Programming.]] Follow these steps: - You will be assigned to a Zoom breakout group. Within the group, select someone to be the initial "Driver" - the person who will be typing. - 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://pastebin.com/|pastebin]], e-mail attachment, Git repository, or any other scheme that everyone agrees upon. - Have the Driver share their screen with the group. - Collaborate with the Driver using audio and/or video. In Pair or Mob Programming, most of the coding suggestions come from those observing the Driver, not the Driver themselves. - It can be a good idea to switch the driver periodically as you see fit. - Perform the lab as outlined below. ==== Setup ==== 1. Have the Driver open the [[6502 Emulator]] at http://6502.cdot.systems in another tab or window, keeping this lab open. Important: The emulator **does not** save your work automatically. Remember to periodically save it to a file (copy-and-paste the code or use the ''Save'' button to create local files). Recommendation: save your files to a directory, and use [[https://git-scm.com/|git]] to manage that directory. ==== Initial Code ==== 2. The following code moves a 5x5 graphic diagonally across the screen: ; ; 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+ ; ; ; The subroutine is below starting at the ; label "DRAW:" ; ; Test code for our subroutine ; Moves an image diagonally across the screen ; 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: ; Set pointer to the image ; Use G_O or G_X as desired ; The syntax # 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 ==== 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. 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's X and Y position. 7. Make the graphic bounce when it hits the edge of the bitmapped screen, both vertically (when it hits the top/bottom) and horizontally (when it hits the left/right edge). ---- **========== This is the end of the in-class portion of the lab. ==========** Continue the remaining portion of the lab on your own. ---- ==== Challenges (Optional, Recommended) ==== Here are some challenges for further experimentation if you're interested: * Permit integer values other than -1 and +1 for the X and Y increments (deltas). * Permit fractional values for the X and Y increments (e.g., +1.5 or -0.75). One way of doing this would be to use 16-bit (2-byte) X and Y increment values (deltas), where the lowest byte is fractional and the highest byte is integer (i.e., the radix point is between the two bytes). * Perturb (subtly disrupt or randomize) the ball's position or bounce so that it is not overly predictable. (Remember that there's a pseudo-random number generator available in memory location $00FE). * Change the graphic image or colour each time it bounces. ==== Write-Up ==== Post an entry on your blog describing your experiments in this lab. Follow the [[Blog Guidelines]]. Include code as text (and not screenshots), but feel free to include screenshots of the bitmapped display. Include in your blog post: - An introduction, so that someone who happens across your blog will understand the context of what you're writing about. - The results from the lab, including the code, a description of how the code works, and the results produced. - The results of the Challenge section(s), if you performed them, including your code. - Your experiences with this lab -- your impressions of Assembly Language, what you learned, and your reflections on the process. Remember that labs are marked on a scale of 0-3: * 0 - Lab not completed, or significant errors. * 1 - Very basic completion, or some small errors. * **2 - Satisfactory completion of the lab.** (This is the default mark for lab completion). * 3 - Lab completed with additional experiments, investigation, research, or explanation. For example, you could do some of the optional sections in this lab, and include those in your blog writeup -- or you could create your own experiments. Remember to follow the [[Blog Guidelines]] as you write. The labs in SPO600 do not have specific due dates, but: - All labs must be completed to pass the course, and - Completing each lab will help you to understand the following topics in the course Therefore it is **strongly** recommended that you keep up with the labs. If you have partially or mostly completed the lab, write a blog post about what you've done, and you can supplement this with an additional blog post at a late date when you complete the lab -- multiple blog posts about one lab are completely acceptable.