Sunday 19 January 2020

Week 2 - Lab 2

As with last week, this week too we were expected to work with 6502 (Wiki: https://wiki.cdot.senecacollege.ca/wiki/6502) emulator (http://6502.cdot.systems/). We had to complete a group lab and we were given an initial code to start with:

lda #$00 ; set a pointer at $40 to point to $0200
 sta $40
 lda #$02
 sta $41

 lda #$07 ; colour

 ldy #$00 ; set index to 0

loop: sta ($40),y ; set pixel

 iny  ; increment index
 bne loop ; continue until done the page

 inc $41  ; increment the page
 ldx $41  ; get the page
 cpx #$06 ; compare with 6
 bne loop ; continue until done all pages

This code fills the whole bit mapped display with yellow color. More information on how this code works can be found in my last blog under Week 1 - Lecture. Lab is followed under:

Add this instruction after the loop: label and before the sta ($40),y instruction:
 tya
What visual effect does this cause, and how many colours are on the screen? Why?
tya instruction transfers index Y to accumulator. Since accumulator is used to determine what color will be drawn on the screen and since y is loaded with 00 and gets transferred to accumulator, so first pixel gets loaded with color black and after that y register keeps incrementing and gets transferred to accumulator in start of every iteration of the loop so display gets filled with 16 different colors as lower bit becomes same after 16 iterations and again until it fills the entire display.

Add this instruction after the tya:
 lsr
What visual effect does this cause, and how many colours are on the screen? Why?
lsr instruction stands for logical shift right and shifts all the bits to the right once. This causes the bytes to be divided by 2 and same color gets outputted twice and we don't see repetition of colors this time and only 16 colors are outputted.

Repeat the above tests with two, three, four, and five lsr instructions in a row. Describe and explain the effect in each case.
When lsr is tested by putting it two, three, four and five times in a row, the same result multiplies and bytes get divided by 2 each time it is done and the colors take up twice the size of pixels than previous result which is:
Two:      Each color is taking up 4 pixels. Outputting all colors now requires two lines.
Three:   Each color is taking up 8 pixels. Outputting all colors now requires three lines.
Four:     Each color is taking up 16 pixels. Outputting all colors now requires 8 lines.
Five:      Each color is taking up 32 pixels. Outputting all colors now requires 16 lines.

Repeat the tests using asl instructions instead of lsr instructions. Describe and explain the effect in each case.
asl stands for arithmetic shift left which can considered opposite to lsr and instead of shifting bits to right it shifts it to right, resulting in multiplying of byte by 2 and amount of colors being displayed starts dividing by 2 so at once asl it divides the number by 2 i.e 16/2 results in displaying first 8 colors then after second it displays first 4 colors, 2 colors on executing asl 2 times and results in only black color being printed in 4th and fifth execute which is because it displays only black color.

Remove the tya and all asl and lsr instructions.
The original code includes one iny instruction. Test with one to five consecutive iny instructions. Describe and explain the effect in each case. Note: ensure that the Speed slider is on its lowest setting (left) for these experiments.
This results in one yellow and one black line after one 2 executions of iny which is because it is adding 2 indexes to the y in each iteration and results in it skipping one pixel and filling every even pixel. and next iteration makes it add 3 indexes and this one fills entire display because it only exits loop after y reaches FF but since it takes 3 iterations over whole display for it to reach FF it eventually fills in entire display (1,4,7). After 4th time it skips 4 pixels and hits FF at first iteration itself so we just see one yellow followed by 3 black lines. Something similar to putting iny 3 times happens when we execute iny 5 times consecutively and it also starts from start, prints yellow after 5 pixels and does this to very end of display but does not hits FF and comes back to 2nd pixel from start and keeps doing this until it hits FF and fills in entire display.

Writing Code, Part 1[edit]

14. Write code to draw a green line across the top of the bitmap screen and a blue line across the bottom.

Writing Code, Part 2[edit]

15. Extend the previous code to draw a yellow line down the left side of the screen and a purple line down the right side.
There were another two questions in the lab which are listed above which we were not able to figure out due to end of time for the class. Overall it was a fun lab, playing around with the bits and colors over the display using different instructions and their executions.

No comments:

Post a Comment