SPO600 Lab2 - 6502 Assembly Language Lab

joycew414

Joyce Wei

Posted on November 1, 2021

SPO600 Lab2 - 6502 Assembly Language Lab

In lab2 we are going to draw borders around the bitmap screen with 4 different colours using 6502 assembly language.

result

Source Code

    LDA #$00    ; set a pointer at $40 to point to $0200
    STA $40
    LDA #$02
    STA $41

    LDA #$05    ; colour number: green
    LDY #$00    ; set index to 0

; draw green line at the top of the bitmap screen

top:    
    STA ($40),y ; set pixel at the address (pointer)+Y
    INY         ; increment index
    CPY #$20    ; 
    BNE top         ; continue until done the page


    LDA #$05    ; set page to 5
    STA $41     ; 

    LDA #$06    ; colour number: blue
    LDY #$E0    ; set index to starting index of last line in pg.5

; draw blue line at the bottom of the bitmap screen

bottom: 
    STA ($40),y ; set pixel at the address (pointer)+Y
    INY         ; increment index
    CPY #$00    ; 
    BNE bottom      ; continue until done the page


    LDA #$02    ; set page to 2
    STA $41     ; 

    LDY #$00    ; set index to starting index of pg.2

; draw yellow line to the left and 
; purple line to the right of the bitmap screen

sides:  
    CLC     ; clear carry to prevent accumulating of a value
    LDA #$07    ; colour number: yellow
    STA ($40),y ; set pixel at the address (pointer)+Y
    TYA     ; transfer y to a
    ADC #$1F    ; increment memory (a) by 1f (32 in hex = 1 line)
    TAY     ; transfer a to y
    LDA #$04    ; colour number: purple
    STA ($40),y ; set pixel at the address (pointer)+Y
    INY     ; increment y (to first index of next line)
    CPY #$00    ; 
    BNE sides   ; continue until done the page

    INC $41     ; increment 1 page
    LDX $41     ; get current page number
    CPX #$06    ; compare with 6
    BNE sides   ; continue until done the page
Enter fullscreen mode Exit fullscreen mode

I have break down the process of drawing the borders into 3 parts.

  1. loop "top" draws a green border at the top of the bitmap screen top
  2. loop "bottom draws a blue border at the bottom of the bitmap screen by setting the starting index to $05E0 bottom
  3. loop "sides" draws a yellow border to the left and a purple border to the right of the bitmap screen by keep switching between the two colours and increasing the index of the current line. sides
💖 💪 🙅 🚩
joycew414
Joyce Wei

Posted on November 1, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related