Week 3: Lab 3 - Assembly Language Math Lab

Hello everyone and welcome to my blog!

We continue to learn and master our skills in assembly language using 6502. During this week's lab we were to practice assembly language math operations. We were to choose one of the five project options to work on in groups. The options were: to create a bouncing graphic, numeric display, pong game, kaleidoscope or line draw. In this lab we were to learn and practice such techniques as make the object bounce (the ball), controlling/moving object with keyboard, generate a random number and draw a line using keyboard.

After voting we chose to build a ping pong game. This project option seemed to be very interesting and challenging. So the task was:

  • Create a single-user version of the classic game: one paddle, controlled by the keyboard, and one single-pixel ball that bounces off the paddle plus the three sides of the screen not guarded by the paddle. The game is over if the ball hits the fourth side of the screen.
We started working on problem by looking into example code kindly provided by our teacher. The link is here, https://wiki.cdot.senecacollege.ca/wiki/6502_Emulator_Example_Code
We found "Etch-a-Sketch" Style Drawing example the most useful for us. This example gave us some understanding regarding turning screen into coordinates, using these coordinates for drawing and how to use keyboard to control drawing. So using "Etch-a-Sketch" as a base we started to make our experiments with the resulting code below.

; zero-page variable locations
define DOTROW $20 ; current row
define DOTCOL $21 ; current column
define DOTDELTAX $30 ; current Delta X
define DOTDELTAY $31 ; current Delta Y
define POINTER $10 ; ptr: start of row
define POINTER_H $11

; constants
define DOT $01 ; dot colour
define CURSOR $04 ; black colour

ldy #$00 ; put help text on screen
print: lda help,y
beq setup
sta $f000,y
iny
bne print

setup: lda #$0f ; set initial ROW,COL
sta DOTROW
lda #$02
sta DOTCOL
lda #$20 ;set angle to 45
sta DOTDELTAX
sta DOTDELTAY

game: lda DOTROW ; ensure ROW is in range 0:31
and #$1f
sta DOTROW

lda DOTCOL ; ensure COL is in range 0:31
and #$1f
sta DOTCOL

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

pha ; save A

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

pla ; restore A

DotMovA:lda DOTCOL
inc DOTCOL
lda DOTCOL

DotMovB:lda DOTROW
inc DOTROW
lda DOTROW

done: clc ; repeat
bcc game

; 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

; help message on character screen

help:
dcb "A","r","r","o","w",32,"k","e","y","s"
dcb 32,"d","r","a","w",32,"/",32,"'","C","'"
dcb 32,"k","e","y",32,"c","l","e","a","r","s"
dcb 00

This code is slightly cleaned, changed version of a "Etch-a-Sketch" example code. It is not a complete work for our Pong game. We continue to work on creating the pond game in the next lab period. You may read more about completing the pong game in my Lab 3 continued post

Comments