Lab-1 Challenges

Introduction:
In this lab, we explored the 6502 assembly language using an online emulator. The primary goal was to understand how to manipulate the bitmapped display, calculate the performance of our code, and optimize it for faster execution. We started by filling the entire screen with a solid color (yellow) and then modified the code to experiment with different colors, patterns, and performance optimizations. Finally, we tackled some optional challenges to further deepen our understanding of the 6502 assembly language and its capabilities.


Challenges:

Challenge 1:
Set all of the display pixels to the same color, except for the middle four pixels, which will be drawn in another color.


To achieve this, we need to modify the original code to fill the entire screen with one color and then change the color of the middle four pixels. The middle four pixels are located at the center of the screen, which can be calculated based on the screen resolution.

    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        ; Colour number (yellow)

    ldy #$00        ; Set index to 0


loop:

    sta ($40),y     ; Set pixel colour at the address (pointer)+Y

    iny             ; Increment index

    bne loop        ; Continue until done 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 all pages


    ; Now, change the middle four pixels to a different color (e.g., red)

    lda #$02        ; Colour number (red)

    sta $040E    ; Set pixel colour at the middle

    sta $040F

    sta $0410

    sta $0411



Challenge 2:
Write a program which draws lines around the edge of the display.

To draw lines around the edges of the display, we need to set specific pixels to different colors. The top and bottom lines will span the entire width of the screen, while the left and right lines will span the height.


; PURPLE_LOOP: Store Y in memory locations $0200-$0500 with an offset of $20
LDY #$04          ; Load Y with 4
LDX #$00          ; Load X with 0
PURPLE_LOOP:
    TYA           ; Transfer Y to A
    STA $0200, X  ; Store A at $0200 + X
    STA $0300, X  ; Store A at $0300 + X
    STA $0400, X  ; Store A at $0400 + X
    STA $0500, X  ; Store A at $0500 + X
    TXA           ; Transfer X to A
    CLC           ; Clear carry flag
    ADC #$20      ; Add $20 to A (X + $20)
    TAX           ; Transfer A back to X
    CPX #$00      ; Compare X with 0
    BNE PURPLE_LOOP ; Loop until X wraps around to 0

; BLUE_LOOP: Store Y in memory locations $0200-$0500 with an offset of $20
LDY #$06          ; Load Y with 6
LDX #$1F          ; Load X with $1F
BLUE_LOOP:
    TYA           ; Transfer Y to A
    STA $0200, X  ; Store A at $0200 + X
    STA $0300, X  ; Store A at $0300 + X
    STA $0400, X  ; Store A at $0400 + X
    STA $0500, X  ; Store A at $0500 + X
    TXA           ; Transfer X to A
    CLC           ; Clear carry flag
    ADC #$20      ; Add $20 to A (X + $20)
    TAX           ; Transfer A back to X
    CPX #$1F      ; Compare X with $1F
    BNE BLUE_LOOP ; Loop until X reaches $1F again

; GREEN_LOOP: Store A in memory locations $05E0-$05FF
LDA #$05          ; Load A with 5
LDX #$00          ; Load X with 0
GREEN_LOOP:
    STA $05E0, X  ; Store A at $05E0 + X
    INX           ; Increment X
    CPX #$20      ; Compare X with $20
    BNE GREEN_LOOP ; Loop until X reaches $20

; RED_LOOP: Store A in memory locations $0200-$021F
LDA #$02          ; Load A with 2
LDX #$00          ; Load X with 0
RED_LOOP:
    STA $0200, X  ; Store A at $0200 + X
    INX           ; Increment X
    CPX #$20      ; Compare X with $20
    BNE RED_LOOP  ; Loop until X reaches $20




Comments

Popular posts from this blog

Lab-1: Exploring 6502 Assembly

Project Stage III: Multi-Clone Analysis in GCC Pass

Lab 2 - 6502 Math Lab