Posts

Showing posts with the label Lab1

SPO600 Lab1 (Pt.5) - Challenges Question 2 Modified solution and reflection

Challenge 2 - Write a program which draws lines around the edge of the display with 6502 processor instruction: A red line across the top A green line across the bottom A blue line across the right side. A purple line across the left side. Modified solution The previous solution was using indirect addressing/ pointer and nested loop. However, since the screen has only 4 pages, it could be more readable and efficient by just using direct addressing and a single loop for the line across the left side/ right side. Here is the revised solution. ; add a purple line accrose left side           ldy #$00 ; set index to 0 leftloop: lda #$04 ;purple           sta $0200,y           sta $0300,y           sta $0400,y           sta $0500,y tya           clc adc #$20 tay bne leftloop ;add a blue line accrose right ...

SPO600 Lab1 (Pt.4) - Challenges

Image
Two challenges regarding 6502 processor instruction will be completed. Challenge 1 - fill in the screen with one color while the middle four pixel will be filled in with another color. Solution: 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       lda #$02        ; second colour number           sta $03ef       ; set pixel colour to the middle four pixels         ...

SPO600 Lab1 (Pt.3) - Experiments

Image
 I am going to try some experiment on the code below: 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   Experiment of adding tya and lsr instructions Firstly, add the "tya" instruction after the loop: label and before the sta ($40),y instruction. We got this output. There are 16 colors shown in the screen. The instruction tya is storing the value in Y register into the Accumulator. Since, the Y-register is storing the offset value, the offset/position value is now stored to the bit-mapped...

SPO600 Lab1 (Pt.2) - Modifying the code

 In this part, I have to revise the code to fulfill the task. task 1:  Change the code to fill the display with light blue instead of yellow. Solution:         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 #$e         ; 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 task 2.  Change the code to fill the display with a different colour on each page The idea of my solution is to store the selected color code in four consecutive memory. Then, use a pointer to reach those color code. Of course, anot...

SPO600 Lab1 (Pt.1) - Calculation of the execution time of a script

Image
In this Lab, we are told to calculate the execution time of a script of 6502 CPU instructions. We assume the clock speed is 1MHz. Meanwhile, when I was studying the 6502 CPU instructions in another  website .  I note that there are different type of addressing. Immediate addressing basically means we use a value instead of an address of memory. "Zeropage" addressing  means that we use a number within $FF, ie the memory is located in the page 0. "Absolute" addressing means that we use a memory location in the form of $00FF. "Indirect" addressing  means we can put the address of a memory, and that memory and the next memory will store the address of the target memory. It works like a pointer. The original Script of Lab 1:           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 ...