; 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 ;use NOPs to position the players STA WSYNC NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP STA RESM0 STA RESP0 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 ;;;;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 ;;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