****************
* MODUL NEWGAME
* created 30/07/95
****************
* exports MODrun.NEWGAME
*         MODend.NEWGAME
*         MODlen.NEWGAME

;---------------
;- Choose Level
;---------------
LOOP            REG 6
LASTJOY         REG 5
SHOWLEVEL       REG 4

ChooseLevel::   moveq #0,r0
                movei #PrintR0,r1
                moveta r0,Cursor.a
                movei #AskLevel,r0
                JSR (r1)
                movei #ShowLevel,SHOWLEVEL
                movei #LastJoy+4,LASTJOY
                movei #.loop,LOOP
                movefa LastLevel.a,r0
                moveta r0,Level.a
                movei #joypad_ng,JOYPAD
.loop           JSR (SHOWLEVEL)
if 0
movei #$f00050,r0
load (r0),r0
moveq #1,r1
moveta r1,Cursor.a
movei #PrintHex,r1
JSR (r1)
endif

                PUSH r4
                JSR (JOYPAD)
                POP r4
                cmpq #0,r0
                jump z,(LOOP)
                nop
UNREG LOOP,LASTJOY,SHOWLEVEL
;---------------
InitPlay::      moveq #0,r0
                movei #PrintR0,r1
                moveta r0,Cursor.a
                movei #ScoreTxt,r0
                JSR (r1)

                movei #ClearPf,r0
                JSR (r0)
                movei #ShowLevel,r0
                JSR (r0)
                movei #ShowHigh,r0
                JSR (r0)

                moveq #0,r0
                moveta r0,Lines.a
                moveta r0,Points.a
                moveta r0,sec.a
                movei #1000,r2
                moveta r2,ms.a
                move r2,last_sec
                movefa DropInit0.a,r0
                movefa Level.a,r1
                moveta r0,DropInit.a
                moveta r1,LastLevel.a
                addq #2,r1
                mult r1,r0
                moveta r0,DropCounter.a
                moveq #0,Y_Flag
                moveq #0,X_Flag
                movefa Level.a,r1
                moveq #10,r0
                neg r1
                addq #10,r1
                mult r1,r0
                moveta r0,LinesToGo.a
                movei #stone_stat,r0
                moveq #7,r1
                moveq #0,r2
.loop           store r2,(r0)
                subq #1,r1
                addqt #4,r0
                jr nz,.loop
                nop
                movei #NewStone,r0
                jump (r0)
                nop
****************
ClearPf::       WAITBLITTER
                movei #PlayField-(PFmax_x+1)<<4,r0
                movei #BLIT_PITCH1|BLIT_PIXEL32|BLIT_WID3584|BLIT_XADDPHR,r1
                store r0,(blitter)
                store r1,(blitter+4)
                moveq #0,r0
                store r0,(blitter+$c)           ; a1 ptr
                movei #$f02268,r1
                store r0,(blitter+$10)          ; a1 step
                store r0,(r1)
                addq #4,r1
                store r0,(r1)                   ; pat data
                movei #1<<16|(PFmax_x+1)*(PFmax_y+4),r0

                movei #BLIT_PATDSEL,r1
                store r0,(blitter+$3C)
                store r1,(blitter+$38)
                WAITBLITTER

                movei #PlayField-(PFmax_x+1)<<4,r0
                moveq #8,r2
                move r0,r1
                moveq #9,r3
                addq #8*4,r1
                moveq #PFmax_y+4,r4
                addq #3*4,r1
.loop           store r2,(r0)   ; Rand
                addq #8*4,r0
                store r3,(r1)
                addq #8*4,r1
                subq #1,r4
                addqt #4*4,r0
                jr nz,.loop
                addq #4*4,r1

                moveq #11,r2
                moveq #12,r3
                store r2,(r0)   ; Ecken
                store r3,(r1)
                moveq #10,r2
                addq #4,r0
                moveq #10,r4
.loop1          store r2,(r0)   ; Boden
                subq #1,r4
                addqt #4,r0
                jr nz,.loop1
                nop
                RTS
****************
joypad_ng::     JOYPAD1
                cmpq #0,r1
                jr nz,.cont
                moveq #0,r0
                RTS
.cont           movei #CheckKey,r2
                moveq #10,r0
.loop           load (r2),r3
                and r1,r3
                cmp r1,r3
                jr z,.exit
                subq #1,r0
                jr nz,.loop
                addq #4,r2
                moveq #0,r0
                RTS
.exit           moveta r0,Level.a
                moveq #1,r0
                RTS
                ALIGN 4
CheckKey        dc.l 1<<4,1<<19,1<<7,1<<3,1<<18,1<<6,1<<2
                dc.l 1<<17,1<<5,1<<1

