; yet another moving dot 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
;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 #180
CMP P0YPosFromBot
BCS DoneCheckingHitCeilingP0
LDA #0;
SBC P0VertSpeed
STA P0VertSpeed
LDA #180
STA P0YPosFromBot
DoneCheckingHitCeilingP0
;check if player 1 hit ceiling - full rebound
LDA #180
CMP P1YPosFromBot
BCS DoneCheckingHitCeilingP1
LDA #0;
SBC P1VertSpeed
STA P1VertSpeed
LDA #180
STA P1YPosFromBot
DoneCheckingHitCeilingP1
;assum horiz movement will be zero
LDX #$00
LDA #$40 ;Left?
BIT SWCHA
BNE SkipMoveLeftP0
LDX #$10
LDA %00001000
STA REFP0 ;show reflected version
SkipMoveLeftP0
LDA #$80 ;Right?
BIT SWCHA
BNE SkipMoveRightP0
LDX #$F0
LDA %00000000
STA REFP0
SkipMoveRightP0
STX HMP0 ;set horiz movement for player 0
;assum horiz movement will be zero
LDX #$00
LDA #$04 ;Left?
BIT SWCHA
BNE SkipMoveLeftP1
LDX #$10
LDA %00001000
STA REFP1
SkipMoveLeftP1
LDA #$08 ;Right?
BIT SWCHA
BNE SkipMoveRightP1
LDX #$F0
LDA %00000000
STA REFP1
SkipMoveRightP1
STX HMP1 ;set horiz movement for player 0
WaitForVblankEnd
LDA INTIM
BNE WaitForVblankEnd
LDY #191
STA VBLANK
STA WSYNC
STA HMOVE
;main scanline loop...
ScanLoop
STA WSYNC
LDA P0DrawBuffer
STA GRP0
LDA P1DrawBuffer
STA GRP1
; 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
BNE SkipActivatePlayer0
LDA #8 ;8 lines tall
STA P0VisibleLine
SkipActivatePlayer0
;turn player off then see if it should be on
LDA #00
;
;if the P0VisibleLine is non zero,
;we're drawing it
;
LDX P0VisibleLine
BEQ FinishPlayer0
IsPlayer0On
LDA BigHeadGraphic-1,X
DEC P0VisibleLine
FinishPlayer0
STA P0DrawBuffer
; 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 BigHeadGraphic-1,X
DEC P1VisibleLine
FinishPlayer1
STA P1DrawBuffer
;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
org $FFFC
.word Start
.word Start
;;;;THE JUNKYARD
;;See if we're going too darn fast
; LDA MaximumSpeed
; SEC
; ;;;;SBC MaximumSpeed ; Maximum Speed
;
; CMP P0VertSpeed
; BCS SpeedNotMaxxed
;
;
;; BMI SpeedNotMaxxed ;if speed - maxspeed is positive, we need to slow down
; LDA MaximumSpeed
; STA P0VertSpeed
;
;SpeedNotMaxxed