top of page

Lab3 - 6502 Assembly Language Math (Not Working)

  • elisangli11
  • Feb 1, 2020
  • 3 min read

In this lab, we were given 5 options to choose and we as a team decided to go with Option 1 which is Bouncing Graphic. To test this code you can check this emulator (http://6502.cdot.systems/)


For a started point of this lab, we used this code as a guide (https://wiki.cdot.senecacollege.ca/wiki/6502_Emulator_Example_Code#Place_a_Graphic_on_the_Screen)

define WIDTH 4 ; width of graphic define HEIGHT 4 ; height of graphic lda #$25 ; create a pointer at $10 sta $10 ; which points to where lda #$02 ; the graphic should be drawn sta $11 lda #$00 ; number of rows we've drawn sta $12 ; is stored in $12 ldx #$00 ; index for data ldy #$00 ; index for screen column draw: lda data,x sta ($10),y inx iny cpy #WIDTH bne draw inc $12 ; increment row counter lda #HEIGHT ; are we done yet? cmp $12 beq done ; ...exit if we are lda $10 ; load pointer clc adc #$20 ; add 32 to drop one row sta $10 lda $11 ; carry to high byte if needed adc #$00 sta $11 ldy #$00 beq draw done: brk ; stop when finished data: dcb 00,03,03,00 dcb 07,00,00,07 dcb 07,00,00,07 dcb 00,03,03,00


With Option 1: Bouncing Graphic. We had to create a simple graphic with 5x5 or 7x7 pixels in size, encode the graphic in bytes using Declare Constant Byte instructions and the graphic needs to bounce around the screen reflecting off the edges when it hits.

With a challenge of randomizing the starting position and make the object bounce off at angles other than 45 degrees.


This is the code that we have so far with the graphic moving but once it hit the edges, the graphics mess up and do not bounce.


define WIDTH 5 ; width of graphic

define HEIGHT 5 ; height of graphic


lda #$00 ; create a pointer at $10

sta $10 ; which points to where

lda #$02 ; the graphic should be drawn

sta $11

lda #$00 ; number of rows we've drawn

sta $12 ; is stored in $12

ldx #$00 ; index for data

ldy #$00 ; index for screen column


move:

jsr clearScreen

;brk

jsr moveDown

jsr moveRight

;draw will modify our pointer, we need to backup and reset it later

lda $10

sta $14;backup

lda $11

sta $15

jsr draw

lda $14

sta $10;reset

lda $15

sta $11

;brk

jsr move

draw:

lda data,x

sta ($10),y

inx

iny

cpy #WIDTH

;brk

bne draw

inc $12 ; increment row counter

lda #HEIGHT ; are we done yet?

cmp $12

bne continue ; if not equal, go to continue

;beq done; ; comment out bne continue and beq done > movin


;lda $04;

;sta $11

ldx #$00; //reset index

ldy #$00;

sty $12

rts

continue:

;brk;

lda $10 ; load pointer

clc

adc #$20 ; add 32 to drop one row

sta $10

lda $11 ; carry to high byte if needed

adc #$00

cmp #$06

beq done

sta $11

ldy #$00

beq draw

;rts

done: brk ; stop when finished

;rts

data:

dcb 00,03,03,03,00

dcb 07,00,00,00,07

dcb 07,00,00,00,07

dcb 07,00,00,00,07

dcb 00,03,03,03,00


moveRight:

sty $13

ldy $10

iny

sty $10

ldy $13

rts


moveDown:

lda $10

clc

adc #$20 ;add a line

sta $10

lda $11

adc #$00

cmp #$06

beq done

sta $11

rts


resetPage:

lda #$02

sta $11

rts


clearScreen: ;we can create another sub route called clearPrevious to avoid flashing screen

sta $22 ;backup registers

stx $23

sty $24


lda #$00 ; create a pointer at $80

sta $20 ; which points to where

lda #$02 ; the graphic should be drawn

sta $21

lda #$00 ;black color

ldy #$00 ;

mloop:

sta ($20), y

iny

bne mloop

ldx $21

inx

stx $21

cpx #$06

bne mloop


lda $22 ;revert registers

ldx $23

ldy $24

rts


Note: What we encounter so far is that maybe the approach used here is hard to make it work, so currently we are working on another different approach. I will be posting the working result once I get it done.

Recent Posts

See All

コメント


Drop Me a Line, Let Me Know What You Think

Thanks for submitting!

© 2023 by Train of Thoughts. Proudly created with Wix.com

bottom of page