Lab 1: 6502 Emulator Bitmap Display and Performance Optimization

Introduction

This blog post details my experiments and learnings from Lab 1 of the 6502 programming course. The lab focuses on filling a bitmapped display with colors using assembly language and optimizing the program's performance on the 6502 emulator. I also explored modifying the display to achieve various effects, calculated execution time, and analyzed mistakes made during this process to understand the intricacies of performance analysis.

Code Overview: Filling the Screen with Yellow


  lda #$00        ; Set a pointer in memory location $40 to point to $0200
  sta $40         ; Low byte ($00) goes in address $40
  lda #$02
  sta $41         ; High byte ($02) goes into address $41
  lda #$07        ; Color number (yellow)
  ldy #$00        ; Set index to 0
loop:
  sta ($40),y     ; Set pixel color at the address (pointer) + Y
  iny             ; Increment index
  bne loop        ; Continue until done with the page (256 pixels)
  inc $41         ; Increment the page
  ldx $41         ; Get the current page number
  cpx #$06        ; Compare with 6
  bne loop        ; Continue until done with all pages

    

How the Code Works

Performance Analysis

To calculate how long it takes to execute the code:

Instruction Counts

The table below shows the instruction counts and cycles:

Instruction Cycles Count Total Cycles
lda #$00212
sta $40313
lda #$02212
sta $41313
lda #$07212
ldy #$00212
sta ($40),y615369216
iny215363072
bne loop315304590
inc $415630
ldx $412612
cpx #$062612
bne loop3515

Total Cycles: 16,961.

Clock Time: 1 MHz

Cycle Time: 1μs

Execution Time: 16.961 ms (at 1 MHz clock speed).

Experiments

Reflections on Mistakes

While performing the lab, I initially miscalculated:

Reflections on Assembly Language

Writing in assembly language revealed the level of detail required to control hardware directly. It was rewarding to see the results visually on the bitmap display, and optimizing the program was a challenging but enlightening experience.

Conclusion

Through this lab, I learned how to analyze, optimize, and experiment with assembly language on the 6502 emulator. From filling the display with colors to optimizing performance, it was an engaging and educational journey.

You've visited this page 1 times.