Thursday 23 January 2020

Week 2 - Lecture (Lab 2 continued)

Continuing from the previous blog we were still working with 6502 emulator for the course (http://6502.cdot.systems/) and on the last two questions on the lab which were:

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.
The professor thankfully gave us the answers to these questions.
Q. 14 was comparatively easier to 15 and was acheived by loading green color in the accumulator and starting from 0200, progressing it with the index same way we did earlier using a loop, but only for 20 iterations since one line was 32 bits which is 20 in hexadecimal and we would compare it using cpy #$20 and once y reaches 20 we make it exit the loop since cpy #$20 makes it to remember the result make it exit the loop. and for blue line we again load accumulator with blue color and starting to fill it from 05E0 which is start of last line and keep progressing it using loop until next 20 iterations.

Q.15 involved a little more complexity since only incrementing y index would not work so we got to learn a new instruction which was for addition adc which stands for add with carry and adds the number specified including the carry flag. Since carry flag can be set or unset at times and can cause uncertainty so we were advised to always clear the carry before doing additions and set the carry flag during subtractions due to similar reason. (subc). So we just amend the previous idea to add 20 during each cycle of loop so it ends up being on next line on the exact next pixel vertically and continue till it it fills whole of the display.

Then we were shown a part of code that would move a pixel with the help of arrow keys. Code can be found under Etch-a-Sketch Style Drawing on this link: https://wiki.cdot.senecacollege.ca/wiki/6502_Emulator_Example_Code

There are few things I would point out in this code that I thought were important; dcb stands for declare constant byte and was used in this code to declare the values for the high and low bytes of specific positions on the screen. The last pressed key is stored in $FF as ASCII code. To ensure the pixel does not go out of screen and overflows to appear at other end the instruction to draw rows and columns were anded with #$1F which is for 31 and ensures pixel always remains on the screen. Checks were coded from #$80 to #$83 to check if up, right, down, left keys were pressed respectively, then according to the key rows and columns were incremented and decremented to move the pixel accordingly.

Honestly, every week I feel there was alot more stuff thrown at us than expected. It could be because we are new to this language but not new to programming. So I guess once we get an hang of it, it should not be that hard.

No comments:

Post a Comment