Our group chose to work on Pong since it seemed like an enjoyable app to create and at least a couple of us had a bit of a grasp on how they wanted to tackle the problem. We started off by looking at some example code that was provided for us for a fairly unrelated program but it allowed us to get some good ideas for how to create out code (Link to Example Code). This code specifically helped us with Three things.
- How to turn a screen made of pages into coordinates
- How to use those coordinates to draw on the screen
- How to take keyboard input
; 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
The code above is greatly unaltered from the etch-a-sketch code. All it does is use that code to draw a line across the screen continuously but It allowed us to learn quite a lot about how to get a ball moving across the screen since it practically is that just without the previous position being removed thus a line is drawn. So from that base it is quite simple to begin to work out how a ball will move properly such as in pong which will be talked about in the next Blog.
Great job Ryan, very interesting!
ReplyDelete