Modifying the 6502 Assembly Program

Hello, Blog!

As promised, in this post, I’ll share the small tweaks I made to modify the functionality of the screen colouring 6502 assembly program.

Check out the previous post for complete breakdown of the base program’s logic: 6502 Assembly: Cal…


This content originally appeared on DEV Community and was authored by arinak1017

Hello, Blog!

As promised, in this post, I’ll share the small tweaks I made to modify the functionality of the screen colouring 6502 assembly program.

If you have just stumbled upon my SPO600 series of blog posts, it has been created to document and share my learnings as I progress through my Software Portability and Optimization college course.

Taking a look at the given program

The following code fills the emulator's display with the yellow colour:



 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
    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


Image description

Filling the display with a different colour

To fill the display with the colour of choice I just needed to load the value associated with the colour into the accumulator.

  • You can find information about the colour values by clicking the "Notes" button in the emulator and scrolling down to the "Bitmapped Display" section.

We can see that light blue = $e

Image description



lda #$00
    sta $40 
    lda #$02    
    sta $41
    lda #$0e  ; load $0e (light blue) instead of $07 (yellow) into the accumulator
    ldy #$00
 loop:  sta ($40),y
    iny
    bne loop
    inc $41
    ldx $41
    cpx #$06
    bne loop


Image description

Filling the display with different colour on each page

To colour each of the four pages with different colours, I decided to increment the colour value stored in the accumulator each time a page gets filled.



    lda #$00
    sta $40 
    lda #$02    
    sta $41
    lda #$07
    ldy #$00
 loop:  sta ($40),y
    iny
    bne loop
    inc $41
        adc #$01  ; increment the value in the accumulator, so the next page is coloured with different colour
    ldx $41
    cpx #$06
    bne loop


Image description

Making each pixel a random colour

Achieving this was a bit trickier, as getting random colour values involved using pseudo-random number generator located at address $FE in the emulator's Zero Page.



    lda #$00
    sta $40 
    lda #$02    
    sta $41
    ldy #$00
 loop: lda $fe ; load colour value from the pseudo-random number generator on each loop iteration
        sta ($40),y
    iny
    bne loop
    inc $41
    ldx $41
    cpx #$06
    bne loop


Image description

P. S.

Playing around with the Assembly code provided by the professor was fun. I found that the key to effectively tweaking the code was a solid understanding of the logic behind the original program.

Thank you for reading my post!


This content originally appeared on DEV Community and was authored by arinak1017


Print Share Comment Cite Upload Translate Updates
APA

arinak1017 | Sciencx (2024-10-06T03:18:31+00:00) Modifying the 6502 Assembly Program. Retrieved from https://www.scien.cx/2024/10/06/modifying-the-6502-assembly-program/

MLA
" » Modifying the 6502 Assembly Program." arinak1017 | Sciencx - Sunday October 6, 2024, https://www.scien.cx/2024/10/06/modifying-the-6502-assembly-program/
HARVARD
arinak1017 | Sciencx Sunday October 6, 2024 » Modifying the 6502 Assembly Program., viewed ,<https://www.scien.cx/2024/10/06/modifying-the-6502-assembly-program/>
VANCOUVER
arinak1017 | Sciencx - » Modifying the 6502 Assembly Program. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/10/06/modifying-the-6502-assembly-program/
CHICAGO
" » Modifying the 6502 Assembly Program." arinak1017 | Sciencx - Accessed . https://www.scien.cx/2024/10/06/modifying-the-6502-assembly-program/
IEEE
" » Modifying the 6502 Assembly Program." arinak1017 | Sciencx [Online]. Available: https://www.scien.cx/2024/10/06/modifying-the-6502-assembly-program/. [Accessed: ]
rf:citation
» Modifying the 6502 Assembly Program | arinak1017 | Sciencx | https://www.scien.cx/2024/10/06/modifying-the-6502-assembly-program/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.