Jump to content
IGNORED

Death by Paddle WIP (Learning assembly)


gozar

Recommended Posts

With the three day weekend, I'm starting down the path to learn assembly. It's just a Pong clone, but hey, we have to start somewhere.

 

So far, I've got it to set the background color to black and draw the field:

post-3959-0-28022100-1441594648_thumb.png

 

 

Why can't I get rid of that cursor?

 

Here's my source so far:

;	Death By Paddle
;	2015/09/06

	org $2000	;Start of code block

COLOR2		= $2c6
CRSINH		= $2f0
SAVMSC		= $58
SAVMSCLO	= $58
SAVMSCHI 	= $59
XY		= $c0
XYLO		= $c0
XYHI		= $c1

start	lda #0
	sta color2	; Set background color to black
	lda #1
	sta crsinh	; Turn off cursor

; Set up player scores
	lda #16
	ldy #5
	sta (savmsc),y	; Temporary, print a score of 0 for player one

	ldy #35
	sta (savmsc),y	; Same for player 2
	
; Draw playfield
drawplayfied
	lda savmsclo	; Save screen locations
	adc #112 
	sta xylo
	lda savmschi
	adc #3
	sta xyhi	; Calculate location of bottom line (savmsc + 920)
	lda #82		; control-w
	ldy #40
line
	sta (savmsc),y
	sta (xy),y
	iny
	cpy #80
	bcs linedone
	jmp line
linedone

vline	clc		; Set up to draw the vertical line
	ldy #0
	lda savmsclo
	adc #99
	sta xylo	; in xy store the location of the vertical bar
	lda savmschi
	sta xyhi
	
	lda #0		; Loop counter to do it 20 times
	sta $c2		
	
	lda #124	; Vertical bar - first bar
	sta (xy),y
vlineloop
	clc
	lda xylo
	adc #40		; Calculate next position
	sta xylo
	bcc contline	; If the numbers wrapped, increment hi
	clc
	lda xyhi
	adc #1
	sta xyhi
contline
	lda #124
	sta (xy),y	; Print the bar character
	inc $c2		; Increment loop
	lda $c2
	cmp #20		; Are we done?
	bcs vlinedone
	jmp vlineloop

vlinedone
	jmp *
  • Like 6
Link to comment
Share on other sites

I'd suggest don't assume the configuration will be Graphics 0. Many games menu loaders use a different screen mode and often the default DList and screen Ram will be overwritten.

 

Though you can deal with that sort of thing right at the end. While in dev you can have a known configuration on entry, then fix it later.

Link to comment
Share on other sites

Bill Wilkinson will show you how to emulate the BASIC GRAPHICS 0 command via assembly. He even gives you an assembler library to invoke all the BASIC graphics commands (which are actually part of the ROM OS).

 

http://archive.org/stream/1982-02-compute-magazine/Compute_Issue_021_1982_Feb#page/n77/mode/2up

 

I think what a lot of game programmers do eventually is set up their own display list in their code (oftentimes with some assembler data statements) and point ANTIC at it.

 

(I pointed you to the start of the article, containing Bill's discussion. The actual assembler code to implement GRAPHICS q appears on page 86.)

Edited by FifthPlayer
Link to comment
Share on other sites

  • 1 year later...

I've made some progress, and now have a nice playfield to start with:

 

post-3959-0-21768500-1482593255_thumb.png

 

Does it look like I'm on the right track?

; GozPong
; Ryan 'Gozar' Collins
; 12/21/16

	org $3000	;start of code
	jmp main
	
; Constants

SDMCTL = $022f
SDLSTL = $0230
SDLSTH = $0231
GRACTL = $d01d

COLOR0 = $02C4
COLOR1 = $02C5
COLOR2 = $02C6
COLOR3 = $02C7
COLOR4 = $02C8

PCOLR0 = $02c0

PMBASE = $d407
HPOSP0 = $d000


;Initialize variables
bx 	.byte 0
by 	.byte 0
bdx	.byte 4
bdy	.byte 3

scoreline dta d "    0            0  "

;PMG data

ball	.byte $18,$3c,$3c,$18


gamescreen
	.byte $70,$70,$70 	;3 blank lines
	.byte $46 		; LMS Antic mode 6
	.word scoreline
	.byte $42 		; LMS Antic mode 2
	.word $1000		; Store the page at $1000 
	.byte $02,$02,$02,$02,$02,$02,$02,$02,$02,$02
	.byte $02,$02,$02,$02,$02,$02,$02,$02,$02,$02
	.byte $02,$02
	.byte $41 		;JVB instruction
	.word gamescreen 	; back to the top
	
setupgamescreen
	; Show screen
	lda #0
	sta SDMCTL
	lda #gamescreen&255
	sta SDLSTL
	lda #gamescreen/256
	sta SDLSTH
	lda #$22
	sta SDMCTL
	
	;build field
	lda #82
	ldx #0
looptop ; top and bottom
	sta $1000,X
	sta $1370,X
	inx
	cpx #40
	bne looptop
	
	; middle line
	lda #87
	sta $1014
	lda #88
	sta $1384

	lda #$3c	;Store the location of the middle line
	sta $b0	
	lda #$10 	
	sta $b1
	
	ldy #0
	sty $b2
	lda #124
	
loopline		;Create the middle line
	sta ($b0),y
	lda $b0
	clc
	adc #40
	sta $b0
	bcc drawline
	ldx $b1
	inx
	stx $b1
drawline	
	lda #124
	sta ($b0),y
	ldx $b2
	inx
	cpx #20
	stx $b2
	bne loopline
	ldx #0
	stx COLOR2	;Set the gamefield color
	ldx #255
	stx COLOR0	;set the score color
	stx COLOR1	;Set the gamefield brightness

	rts		;Done with screen setup
;Main game
main
	jsr setupgamescreen
	
infinity
	jmp infinity
	
	run main
	
  • Like 2
Link to comment
Share on other sites

yes!

 

 

Thanks!

 

I'm such a newbie at this, and assembly seems so... I don't know, it feels like when I get something working that there is a better way of doing it.

 

I got a ball player/missile moving yesterday, but now my problem is that it moves way too fast!

Link to comment
Share on other sites

I'm trying to make the ball move like in Pong, but it flies across the screen. What's the best way to make the ball wait until a certain amount of time has passed before moving?

 

Do I use the built in clock or is there a better way?

 

 

Sent from my iPhone using Tapatalk

Link to comment
Share on other sites

For a case like this, I'd say it's probably best to synch your game code to the VBI. The disadvantage is that PAL and NTSC will play at different speeds. There are workarounds for this however.

 

Let's say you have two variables, dX and dY. This will represent the horizontal and vertical ball speed. Each VBI, increment the object position, check for collisions, etc.

 

If you need some examples of running code in VBI, I can share them. I have a simple left/right joystick routine which runs at 30Hz that's only a few lines of code. As with all things ASM, there are certain steps which need to be taken to ensure your VBI code is "hooked" properly.

  • Like 1
Link to comment
Share on other sites

What you want is fixed-point math. It's in-between integer and floating-point math in that it handles fractional numbers, but the range and precision is not as adaptable as floating-point. Typically for this you would use 16-bit numbers in 8.8 form, where 8 bits hold the whole part and 8 bits hold the fractional part.

 

Here's a simple example:

ANIM_SPEED = $0038

animloop:
    lda    pos_lo
    clc
    adc    #<ANIM_SPEED    ;$38
    sta    pos_lo
    lda    pos_hi
    adc    #>ANIM_SPEED    ;$00
    sta    pos_hi

    ;move missile horizontally
    lda    pos_hi
    sta    hposm0

    ;wait for next frame
    lda    rtclok+2
wait:
    cmp    rtclok+2
    beq    wait

    jmp    animloop

This code moves missile 0 right at the rate of $38/$100 = 0.22 pixels per tick. The first part is just a 16-bit add, and then the high byte is used to set the missile position. For a pong-like game, you'd put the speed into a variable of its own so you could change it as needed on playfield or paddle collisions. Fixed-point has several advantages over trying to space out +1/-1 increments with delays: backwards motion works with the same code just by using a negative speed, the speed value is linear instead of non-linear as with the delay value, and it handles in-between values smoothly.

 

As for running your code off the vertical blank interrupt, that's a good idea but not required. You can get pretty far with the little wait loop I posted above, and then start moving code to the VBI once you're comfortable working with interrupts.

  • Like 3
Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...