********************************
* PM-HELPER DEMO
* ASSEMBLERECKE 02
* COMPUTER KONTAKT 03/85
* PETER FINZEL
********************************

HPOS     EQU $0600
VPOS     EQU $0604
SHPADR   EQU $0608
LAENGE   EQU $0610

PMBADR   EQU $0611
VPALT    EQU $0612
PNUM     EQU $0616
PADR     EQU $80
SADR     EQU $82

PMBASE   EQU $D407
DMACTL   EQU $D400
GRACTL   EQU $D01D
GRAFP0   EQU $D00D
HPOSP0   EQU $D000
PCOLR0   EQU $02C0

SDMCTL   EQU $022F
SETVBV   EQU $E45C
XITVBV   EQU $E462

* HAUPTPROGRAMM-SCHLEIFE

         ORG $A800

         LDA #16	SHAPE LAENGE
         STA LAENGE
         LDX #$B0	MSB PLAYER-SPEICHER
         LDY #0		LSB PLAYER-SPEICHER
         STX PMBADR	PLAYER-SPEICHER IN ZWISCHENVARIABLE
         STY SHPADR	SHAPE-VORLAGE LIEGT AM ANFANG DES PLAYER-SPEICHER
         STX SHPADR+1	FUER ALLE 4 PLAYER GLEICHES SHAPE
         STY SHPADR+2      
         STX SHPADR+3
         STY SHPADR+4
         STX SHPADR+5
         STY SHPADR+6
         STX SHPADR+7

         LDA SHPADR	SHAPE IN SHAPE-ADRESSE KOPIEREN
         STA SADR
         LDA SHPADR+1
         STA SADR+1
         LDY #0
SHPLOA   LDA SHAPE1,Y
         STA (SADR),Y
         INY
         CPY #16
         BNE SHPLOA

         JSR PMHEIN	PM-GRAFIK UND VBI EINSCHALTEN

         LDA #12	PLAYER FARBEN SETZEN
         STA PCOLR0
         LDA #186
         STA PCOLR0+1
         LDA #134
         STA PCOLR0+2
         LDA #46
         STA PCOLR0+3

         LDA #120	PLAYER BEWEGUNG
         STA VPOS
         STA HPOS+1
SRTPOS   LDX #0
         LDY #255
NXTPOS   STX HPOS
         STX VPOS+1
         STX HPOS+2
         STX VPOS+2
         STX VPOS+2
         STY HPOS+3
         STY VPOS+3
         LDA 20
WAIT1    CMP 20
         BEQ WAIT1
         LDA $D01F
         AND %00000001	START GEDRUECK?
         BEQ ENDE	JA -> DANN ENDE
         DEY
         INX
         CPX #255
         BEQ SRTPOS
         JMP NXTPOS

ENDE     JSR PMHAUS	PM-GRAFIK UND VBI AUS
         RTS		RUECKSPRUNG


SHAPE1   DFB 0,24,60,60,126,90,255
         DFB 231,255,255,90,102
         DFB 60,60,24,0


*
* UNTERPROGRAMM
* PM-HELPER EINSCHELTEN
*

PMHEIN   LDA #0            ALLE PLAYER VARIABLEN AUF 0
         LDX #3
VARCLR   STA VPOS,X
         STA HPOS,X
         STA VPALT,X
         STA HPOSP0,X
         DEX
         BPL VARCLR

         CLC               PM-SPEICHERBEREICH LOESCHEN
         LDA PMBADR
         ADC #3
         STA PADR+1
         LDA #0
         STA PADR
         LDX #5
PLCLR1   LDY #0
PLCLR2   STA (PADR),Y
         INY
         BNE PLCLR2
         INC PADR+1
         DEX
         BNE PLCLR1

* VBI-PROGRAMM STARTEN

         LDX #PMHVBI:H
         LDY #PMHVBI:L
         LDA #7
         JSR SETVBV

* PM-GRAFIK EINSCHALTEN

         LDA PMBADR
         STA PMBASE
         LDA #$3E
         STA SDMCTL
         LDA #3
         STA GRACTL
         RTS

*
* UNTERPROGRAMM
* PM-HELPER AUSSCHALTEN
*

PMHAUS   LDA #0
         STA GRACTL
         LDX #4
GTCLR    STA GRAFP0,X
         DEX
         BPL GTCLR

         LDA #$22
         STA SDMCTL
         LDX #XITVBV:H
         LDY #XITVBV:L
         LDA #7
         JSR SETVBV

         RTS

*
* DIE PM-HELPER VBI-ROUTINE
*

PMHVBI   LDA PMBADR
         CLC
         ADC #7
         STA PADR+1
         LDA #3
         STA PNUM

ALLE4    LDA PNUM
         ASL
         TAX
         LDA SHPADR,X
         STA SADR
         LDA SHPADR+1,X
         STA SADR+1
         LDX PNUM
         LDA HPOS,X
         STA HPOSP0,X
         LDA VPALT,X
         CMP VPOS,X		POSITION VERAENDERT?	
         BEQ NAECHST		NEIN -> WEITER

         STA PADR		ALTEN PLAYER LOESCHEN
         LDY #0
         LDA #0
PLRCLR   STA (PADR),Y
         INY
         CPY LAENGE
         BNE PLRCLR

         LDA VPOS,X		NEUEN PLAYER MALEN
         STA PADR
         LDY #0
PLRSHP   LDA (SADR),Y
         STA (PADR),Y
         INY
         CPY LAENGE
         BNE PLRSHP

         LDA VPOS,X
         STA VPALT,X
NAECHST  DEC PADR+1
         DEC PNUM
         BPL ALLE4

         JMP XITVBV		SPRUNG ZUM OS-VBI 

