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.
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:-
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:-
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
Comments
Post a Comment