Friday, January 31, 2020

Lab 3

The program we chose to complete for this lab was pong. For something that seemed relatively simple, there were some complications with it. One thing that seems obvious now but wasn't at the time was that we needed something to delay the drawing of the "ball" on the screen so that it didn't just instantly fly all over the place and the game would be unplayable.

We used the following code for our "sleep function"

delay: iny
cpy #$FF
bne delay

ldy #$00
inx
cpx #$06
bne delay

The above function just gives the processor busy work for a while until it should draw again. In other languages you can call built in methods like sleep for this kind of thing. It was interesting to get a look behind the scenes at what the processor could potentially be doing to make these "sleep" functions happen, though in a real system it would probably be working on other tasks rather than just counting.

Thursday, January 23, 2020

Lab 2

For lab 2, we were required to write assembly code to colour the edges of the bitmap screen. The first thing that struck me about this lab is just how hard it is to do even the simplest things with assembly. Even something as simple as adding a value to another value is not quite as straight forward as in other languages.

tya ;move y value to a for adding command
adc #$1f ;add 32 to accumulator (display is 32 pixels wide)
tay ;transfer new value back to y

The above code for example, seems much more daunting than just typing "y += 32;" in c or java. One of the biggest issues i ran into with this lab was that I didn't really understand what the carry flag was or where it came from. It was ultimately explained in class, but until then, it just seemed like my results were getting a 1 added to them at random. It did create some interesting results on the bit map screen at least. I learned that CLC should be used before attempting to do addition in most cases.


Below is the code for lab 2.


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

lda #$05 ; colour
ldy #$00 ; set index to 0

loop: sta ($40),y ; set pixel
iny ; increment index
cpy #$20
bne loop ; continue until done the page

ldy #$E0 ; last line of 5
lda #$05 ; set page to 5
sta $41 ; set page to 5
lda #$06
loop2:

sta ($40),y
iny
cpy #$00
bne loop2

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

loop3:
clc
lda #$07
sta ($40),y
tya ;move y value to a for adding command
adc #$1f ;add 32 to accumulator (display is 32 pixels wide)
tay ;transfer new value back to y
lda #$04 ;load purple
sta ($40),y
iny ;increment to start of next line
cpy #$00 ;check if finished page
bne loop3
inc $41 ;increment page
ldx $41 ;load value of page
cpx #$06 ;check if passed end of display
bne loop3