[stella] gah! my suckitude knows no bounds

Subject: [stella] gah! my suckitude knows no bounds
From: KirkIsrael@xxxxxxxxxxxxx
Date: 23 Aug 2003 20:25:47 -0000

So, I decided to pick up my long slumbering JoustPong 
project.  And pretty dang quick, it layed the smackdown
and reminded me why I set it aside in the first place.


Below is about the code I started with. I decide to start
messing with the playfield, just trying to figure out 
a simple way of detecting "goals".

So the code here works...both players can hit the 
fire button, and it has a nice roughly joustlike flap
against gravity.

but if I uncomment these lines:
;	LDA #%00100000
;	STA PF0
becomes
	LDA #%00100000
	STA PF0
it all breaks. the guys get pinned to the top...
it's almost like an enormous amount is being subtracted from
P0VertSpeed or P1VertSpeed rather than just the constant 
FlapStrength.

I know I'm a ASM retard, but what's going on here?
This is tested with Z26.
















; JoustPong by Kirk Israel
	
	processor 6502
	include vcs.h
	org $F000



P0YPosFromBot = $80
P0VisibleLine = $81
P0DrawBuffer = $82
P0VertSpeed = $83
P1YPosFromBot = $84
P1VisibleLine = $85
P1DrawBuffer = $86
P1VertSpeed = $87

But0WasOn = $88
But1WasOn = $8A

GravTimer = $8B
 


;CONSTANTS
FlapStrength = #4;
GravDelay = #6	;How often does gravity pull 'em down?
MaximumSpeed = #6

;generic start up stuff...
Start
	SEI	
	CLD  	
	TXS	
	LDX #$FF	
	LDA #0		
ClearMem 
	STA 0,X		
	DEX		
	BNE ClearMem	
	LDA #$00		
	STA COLUBK	

;Some other initialization
	LDA GravDelay	
	STA GravTimer	;initialize gravity timer (only 1 in N ticks do we pull)

	LDA #33	
	STA COLUP0	;Set P0 Reddish

	LDA #66
	STA COLUP1	;Set P1 Purplish

	LDA #120
	STA P0YPosFromBot	;P0 Initial Y Position
	STA P1YPosFromBot	;P1 Initial Y Position

	LDA #0
	STA P0VertSpeed
	STA P1VertSpeed


;generate the background
;this is just one dot on the edge
;reflected. we'll use it for collision
;detection to know when a goal
;is scored


;	LDA #%00100000
;	STA PF0
	
;	LDA #99
;	STA COLUPF
	;color here
	
;	LDA #%00000001
;	STA CTRLPF 

	
;	LDA #%00000010
;	STA ENABL 
	
;	LDA #%01110000
;	STA HMBL

;use NOPs to position the players
	LDA #0
	STA WSYNC
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	STA RESM0	
	STA RESP0
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	STA RESBL
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	STA RESP1 
	NOP
	STA RESM1

	LDA %00001000
	STA REFP1

	LDA #2		
	STA ENAM0	
	STA ENAM1	
	;STA ENABL
	LDA #%10101010
	STA COLUPF

;VSYNC time
MainLoop
	LDA  #2
	STA  VSYNC	
	STA  WSYNC	
	STA  WSYNC 	
	STA  WSYNC	
	LDA  #43	
	STA  TIM64T	
	LDA #0		
	STA  VSYNC 	

CheckButton0
	LDA INPT4
	BMI NoButton0

	;Check to see if the button was already down
	LDA But0WasOn
	BNE Button0WasAlreadyDown

	;New Button Pressed Time to Flap!
	LDA P0VertSpeed
	SEC
	SBC FlapStrength
	STA P0VertSpeed
	
	LDA #1
	STA But0WasOn
Button0WasAlreadyDown
	JMP EndButton0
NoButton0	;button wasn't pressed, remember that
	LDA #0
	STA But0WasOn
EndButton0



CheckButton1
	LDA INPT5
	BMI NoButton1

	;Check to see if the button was already down
	LDA But1WasOn
	BNE Button1WasAlreadyDown

	;New Button Pressed Time to Flap!
	LDA P1VertSpeed
	SEC
	SBC FlapStrength
	STA P1VertSpeed
	
	LDA #1
	STA But1WasOn
Button1WasAlreadyDown
	JMP EndButton1
NoButton1	;button wasn't pressed, remember that
	LDA #0
	STA But1WasOn
EndButton1





;Time to Add Gravity to Speeds of P0/P1?
	DEC GravTimer
	BNE DoneWithGravity

	INC P0VertSpeed
	INC P1VertSpeed
	LDA GravDelay
	STA GravTimer
DoneWithGravity







;	LDA P0YPosFromBot
;	STA COLUBK	




;Move the Players first, then check if hit ceiling/floor
;
;

;Add the negative of the Player 0 Vert Speed to 0 in A
	LDA #0
	SEC
	SBC P0VertSpeed
;Then add the current position of p0
	CLC
	ADC P0YPosFromBot
	STA P0YPosFromBot

;Add the negative of the Player 1 Vert Speed to 0 in A
	LDA #0
	SEC
	SBC P1VertSpeed
;Then add the current position p1
	CLC
	ADC P1YPosFromBot
	STA P1YPosFromBot



;check if player 0 hit floor
	LDA #10	;10 is floor
	CLC
	CMP P0YPosFromBot
	BCC DoneCheckingHitFloorP0
;we need a better bounce routine, like reducing the speed?
;speed should be positve; let's divide it my two and then
;subtract it from zero to get the new speed (i.e. a half rebound)
	LDA P0VertSpeed
	CLC
	ROR
	STA P0VertSpeed

	LDA #0
	SEC
	SBC P0VertSpeed
	STA P0VertSpeed

	LDA #10
	STA P0YPosFromBot ;putplayer on floor
DoneCheckingHitFloorP0



;check if player 1 hit floor
	LDA #10	;10 is floor
	CLC
	CMP P1YPosFromBot
	BCC DoneCheckingHitFloorP1
;we need a better bounce routine, like reducing the speed?
;speed should be positve; let's divide it my two and then
;subtract it from zero to get the new speed (i.e. a half rebound)
	LDA P1VertSpeed
	CLC
	ROR
	STA P1VertSpeed
	LDA #0
	SEC
	SBC P1VertSpeed
	STA P1VertSpeed

	LDA #10
	STA P1YPosFromBot ;putplayer on floor
DoneCheckingHitFloorP1











;check if player 0 hit ceiling - full rebound
	LDA #90 ;#was 180 before 2 line kernal
	CMP P0YPosFromBot
	BCS DoneCheckingHitCeilingP0

	LDA #0;
	SBC P0VertSpeed
	STA P0VertSpeed
	LDA #90 ;#was 180
	STA P0YPosFromBot

DoneCheckingHitCeilingP0

;check if player 1 hit ceiling - full rebound
	LDA #90 ;#was 180 before 2 line kernal
	CMP P1YPosFromBot
	BCS DoneCheckingHitCeilingP1

	LDA #0;
	SBC P1VertSpeed
	STA P1VertSpeed
	LDA #90 ; was 180
	STA P1YPosFromBot

DoneCheckingHitCeilingP1




;;
;;used to have left and right flow here...
;;
;;



WaitForVblankEnd
	LDA INTIM	
	BNE WaitForVblankEnd	
	LDY #95 ; WAS, going for double #191 	

	STA VBLANK  	


	STA WSYNC	
	STA HMOVE 	

;main scanline loop...
ScanLoop 
	STA WSYNC 	

	LDA P0DrawBuffer	;[0]+3
	STA GRP0		;[3]+3

	LDA P1DrawBuffer	;[6]+3
	STA GRP1		;[9]+3


; here the idea is that P0VisibleLine
; is zero if the line isn't being drawn now,
; otherwise it's however many lines we have to go
CheckActivatePlayer0
	CPY P0YPosFromBot	;[12]+4
	BNE SkipActivatePlayer0	;[16]+3
	LDA #8 ;8 lines tall	;[19]+3
	STA P0VisibleLine 	;[22]+3
SkipActivatePlayer0

;turn player off then see if it should be on
	LDA #00			;[25]+3
;
;if the P0VisibleLine is non zero,
;we're drawing it
;
	LDX P0VisibleLine 	;[28]+3
	BEQ FinishPlayer0	;[31]+3
IsPlayer0On	
	LDA But0WasOn		;[34]+3
DoWing0
	BNE DrawWing0Down	;[37]+3
DrawWing0Up
	LDA WingUpGraphic-1,X	;[40]+3
	JMP Wing0Finish		;[43]+3
DrawWing0Down
	LDA WingDownGraphic-1,X
Wing0Finish
	DEC P0VisibleLine 	;[46]+3
FinishPlayer0
	STA P0DrawBuffer	;[49]+3






; here the idea is that P1VisibleLine
; is zero if the line isn't being drawn now,
; otherwise it's however many lines we have to go
CheckActivatePlayer1
	CPY P1YPosFromBot
	BNE SkipActivatePlayer1
	LDA #8 ;8 lines tall
	STA P1VisibleLine 
SkipActivatePlayer1

;turn player off then see if it should be on
	LDA #00		
;
;if the P0VisibleLine is non zero,
;we're drawing it
;
	LDX P1VisibleLine 
	BEQ FinishPlayer1
IsPlayer1On	
	LDA But1WasOn
DoWing1
	BNE DrawWing1Down
DrawWing1Up
	LDA WingUpGraphic-1,X
	JMP Wing1Finish
DrawWing1Down
	LDA WingDownGraphic-1,X
Wing1Finish
	DEC P1VisibleLine 
FinishPlayer1
	STA P1DrawBuffer


	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP



;now just finish counting of scanloop
	DEY		
	BNE ScanLoop	

	LDA #2		
	STA WSYNC  	
	STA VBLANK 	
	LDX #30		
OverScanWait
	STA WSYNC
	DEX
	BNE OverScanWait
	JMP MainLoop      
 
	org $FF00
BigHeadGraphic
	.byte %00111100
	.byte %01111110
	.byte %11000001
	.byte %10111111
	.byte %11111111
	.byte %11101011
	.byte %01111110
	.byte %00111100


WingUpGraphic
        .byte #%00001100
        .byte #%00001100
        .byte #%10001100
        .byte #%11011100
        .byte #%11111100
        .byte #%01111100
        .byte #%00101100
        .byte #%00001100

WingDownGraphic
        .byte #%00001100
        .byte #%00011100
        .byte #%00111100
        .byte #%01111100
        .byte #%01111100
        .byte #%00111100
        .byte #%00001100
        .byte #%00001100




	org $FFFC
	.word Start
	.word Start

----------------------------------------------------------------------------------------------
Archives (includes files) at http://www.biglist.com/lists/stella/archives/
Unsub & more at http://www.biglist.com/lists/stella/


Current Thread