DEV Community

Qzhang125
Qzhang125

Posted on

Lab3 Math Lab

Image description
Hello, My friend. This blog is about the third lab for SPO666. In this lab, we are going in to create a pong game by using 6502 assembly language.
This is our work so far, I will uploaded when we finished the lab.

define POINTER $10
define POINTER_H $11
define POSITION $30
define ROW $20 ; current row
define COL $21 ; current column

; constants
define DOT $01 ; dot colour
define PADDLE $01 ; paddle colour

setup: lda #$0f ; set initial ROW,COL
sta ROW
lda #$0F
sta COL
lda #$20
LDA #05
STA POSITION

draw: lda ROW ; ensure ROW is in range 031
and #$1f
sta ROW

lda COL ; ensure COL is in range 031
and #$1f
sta COL

ldy ROW ; load POINTER with start-of-row
lda table_low,y
sta POINTER
lda table_high,y
sta POINTER_H

ldy COL ; store CURSOR at POINTER plus COL
lda #DOT
sta (POINTER),y




;SET A PROINTER TO THE BOTTOM-LEFT CORNER
LDA #$EC
STA POINTER
LDA #$05
STA POINTER_H

; STORE THE POSITION TO THE POINTER
LDA POINTER
CLC
ADC POSITION
STA POINTER

LDA #$01
LDY #$00
loop:
STA (POINTER),Y
INY
CPY #$07
BNE loop

getkey:lda $ff ; get a keystroke

ldx #$00 ; clear out the key buffer
stx $ff

cmp #$43 ; handle C or c
beq clear
cmp #$63
beq clear

cmp #$80 ; if not a cursor key, ignore
bmi getkey
cmp #$84
bpl getkey

;pha ; save A

;lda #POSITION ; set current position to POINTER
;sta (POINTER),y

;pla ; restore A

cmp #$81 ; check key == RIGHT
bne checkL

inc POSITION ; ... if yes, increment POSITION
jmp done



checkL: cmp #$83 ; check key == left
bne done

dec POSITION ; ... if yes, decrement POSITION
clc
bcc done

clear: lda table_low ; clear the screen
sta POINTER
lda table_high
sta POINTER_H

ldy #$00
tya




c_loop: sta (POINTER),y
iny
bne c_loop

inc POINTER_H
ldx POINTER_H
cpx #$06
bne c_loop



done: clc ; repeat
jmp draw

; these two tables contain the high and low bytes
; of the addresses of the start of each row
table_high:
dcb $02,$02,$02,$02,$02,$02,$02,$02
dcb $03,$03,$03,$03,$03,$03,$03,$03
dcb $04,$04,$04,$04,$04,$04,$04,$04
dcb $05,$05,$05,$05,$05,$05,$05,$05,

table_low:
dcb $00,$20,$40,$60,$80,$a0,$c0,$e0
dcb $00,$20,$40,$60,$80,$a0,$c0,$e0
dcb $00,$20,$40,$60,$80,$a0,$c0,$e0
dcb $00,$20,$40,$60,$80,$a0,$c0,$e0
Enter fullscreen mode Exit fullscreen mode

Top comments (0)