SPO600 Lab1 (Pt.3) - Experiments

 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 screen memory. Since there are only 16 color code available, for those value exceed $0f,  the screen displaying the color based on the last hexadecimal digit. 

Secondly, add "lsr" after tya and before sta ($40),y. We got this output.  

According to the documentation on the website mass:werk, "lsr" instruction is shifting all bits right one position. When no memory position is explicitly provided, the instruction will be applied on the Accumulator. Right shift of a bit is basically dividing the value by 2 with the remainder removed. This can explain why two consecutive memory will have same color code. For example, right shift $0 and $1 will both get $0. As explained,  there are only 16 color code available. For those value exceed $0f,  the screen displaying the color based on the last hexadecimal digit. 

Then, I tried to add more and more "lsr" instruction after the "tya" instruction and i got the display as below:-

2 lsr: 3lsr:  4lsr: 5lsr:

When we add more lsr instruction, the "column" become thicker. All of them have 16 colors.

Since every lsr instruction divided the offset value by 2, there will be 2^n consecutive memory having the same color code, where n is the number of lsr instruction. 


Experiment of adding tya and asl instructions

Now, I try the above test with asl, instead of lsr. I added tya and asl between loop: and sta ($40),y.

There are 8 colors in the output.

"asl" is a left shift operation to the accumulator. It is basically double the offset value stored in the accumulator before we store the accumulator's value into the bit-mapped memory. Since all the value are double, only even number will show up in the memory. Among 16 color code, there are only 8 even number. As a result, we can only find 8 colors on the screen.

Now, I added more "asl" after tya and got the output as follow:-

2asl:  3asl:  4asl or more: 

When we left shift a value, we are basically doubling the value. As a result, the value to be stored to the memory will be a multiple of 2^n, where is the number of asl. Since the screen display is base on the  the last hexadecimal digit, number of the color will be 16 divided by 2^n. For example, when we got 4asl or more, the value is always a multiple of 16 and the last hexadecimal  digit will always be 0. That's why we see a black screen. 

Increase the number of iny instruction

The next experiment is to increase the number of iny instruction in the original code. 

With one iny instruction originally, we observed that the loop put the value in the accumulator into the memory $0200 to $0600 in order and filled in the entire screen.


When we added another iny instructions (2 in total), . Two iny means we are adding 2 to the accumulator in every loop. Since the offset value stored in Y register is always even number, only memory with even address will be filled by the program.


When we added another iny instructions (3 in total), we can observe that the first page is filled in the order of 0,3,6,9...255. Then, the Y register overflowed to 2 and continued to fill the first page in the order of 2,5,8...254 and overflowed to 1. Then, fill the page  in order of 1,4,7...256. This process repeated for all pages and every memory are filled. 


When we added another iny instructions (4 in total), it is not hard to predict the result will be similar to that of 2 iny instruction. Only the memory of address of multiple of 4 is filled. 










 







Comments

Popular posts from this blog

SPO600 Project Stage 1 (Pt.1) - Create a GCC Pass

SPO600 Project Stage 2 (Pt.1) - GCC pass locating clone function

SPO600 Project Stage 2 (Pt.2) - GCC pass locating clone function -modified version