' $INCLUDE: 'future.bi'
DECLARE SUB putlevels ()
DECLARE SUB checkver (I%, n%, item%)
DECLARE SUB check (I%, n%, item%)
DEFINT A-Z
'$DYNAMIC
DECLARE FUNCTION int86qb$ (intnr%, flag%, ax%, bx%, CX%, dx%, di%, si%, bp%, ds%, es%)
DECLARE FUNCTION int2str$ (sword%)
DECLARE FUNCTION PlayMIDI% ()
DECLARE FUNCTION LoadAndPlayMIDI% (Filename$)
DECLARE SUB LoadMIDI (Filename$)
DECLARE SUB stopmidi ()
DECLARE SUB Pokestring (SEGJE%, OFFJE%, Main$)
DECLARE FUNCTION TimeMIDI! ()
DECLARE SUB del (dela%)
DECLARE SUB LoadGIF (a$)
DECLARE SUB Pause (tdelay#)
DECLARE SUB fliplay (Filename$)
COMMON SHARED win%
DIM SHARED MIDI.LOADED AS INTEGER
DIM SHARED MIDI.PLAYTIME AS SINGLE
DIM SHARED MIDI.INTERRUPT AS INTEGER
DIM SHARED row1(-15 TO 45)
DIM SHARED row2(-15 TO 45)
DIM SHARED row3(-15 TO 45)
DIM SHARED row4(-15 TO 45)
DIM SHARED row5(-15 TO 45)
DIM SHARED row6(-15 TO 45)
DIM SHARED row7(-15 TO 45)

MIDI.LOADED = 0
MIDI.PLAYTIME = 0
MIDI.INTERRUPT = &H81

CONST FALSE = 0
CONST TRUE = NOT FALSE

TYPE FLIheaderType
	Size AS LONG               'Size (in bytes) of entire Flic file
	ID AS INTEGER              'Always &hAF11 for FLI files
	Frames AS INTEGER          'Number of Frames (not including ring frame)
	XRes AS INTEGER            'Always 320 for FLI files
	YRes AS INTEGER            'Always 200 for FLI files
	ColorBits AS INTEGER       'Always 8 for FLI files (bits per pixel)
	Flags AS INTEGER           'Always 0 for FLI files
	Speed AS INTEGER           'Pauses 1/70 second between frames (FLI only)
	Reserved AS STRING * 110
END TYPE

TYPE FLIframeChunkType
	Size AS LONG               'Size of frame chunk, including header
	ID AS INTEGER              'Always &hF1FA for FLI files
	Chunks AS INTEGER          'Number of subordinate chunks in frame chunk
	Reserved AS STRING * 8
END TYPE

TYPE FLIdataChunkType
	Size AS LONG               'Size of data chunk, including header
	ID AS INTEGER              'Data Type ID (see below)
END TYPE

'-- Data Type ID has following values: --
'        4  - COLOR256 : Change Palette using values 0-255 for RGB
'        7  - SS2      : (FLC) Word Aligned Delta Compression (Pixel Data)
'        11 - COLOR64  : Change Palette using values 0-63 for RGB
'        12 - LC       : Byte Aligned Delta Compression (Pixel Data)
'        13 - BLACK    : Black Screen
'        15 - BRUN     : Byte Run Length Compression (Pixel Data)
'        16 - COPY     : Bitmap of entire image (Pixel Data)
DEFINT A-Z
set320x200 8
stopmidi
fliplay "logo.fli"
IF LoadAndPlayMIDI%("lucca.mid") = 0 THEN  ELSE
fliplay "open.fli"
SLEEP
DIM bg#(1 TO 8000)
DIM pc1#(1 TO 60)
DIM pc2#(1 TO 60)
DIM pc3#(1 TO 75)
DIM pc4#(1 TO 75)
'DIM pc5#(1 TO 60)
'DIM pc6#(1 TO 60)
'DIM pc7#(1 TO 65)
'DIM pc8#(1 TO 65)
DIM ball#(1 TO 65)
DIM dino1#(1 TO 300)
DIM dino2#(1 TO 300)
DIM dino3#(1 TO 300)
DIM bg1#(1 TO 530)
DIM bg2#(1 TO 530)
DIM bg3#(1 TO 530)
DIM bg4#(1 TO 530)
DIM bomb1#(1 TO 630)
DIM bomb2#(1 TO 1430)
DIM attack#(1 TO 75)
LoadGIF "bg1.gif"
future.emsget 1, 71, 319, 199, bg#
LoadGIF "pieces.gif"
future.emsget 1, 73, 19, 90, pc1#
future.emsget 21, 73, 39, 90, pc2#
future.emsget 41, 73, 59, 90, pc3#
future.emsget 61, 73, 79, 90, pc4#
'future.emsget 81, 73,99, 90, pc5#
'future.emsget 101, 73,119, 90, pc6#
'future.emsget 121, 73,139, 90, pc7#
'future.emsget 141, 73,159, 90, pc8#
future.emsget 161, 73, 179, 90, ball#
future.emsget 5, 38, 49, 69, dino1#
future.emsget 53, 38, 97, 69, dino2#
future.emsget 101, 38, 145, 69, dino3#
LoadGIF "suzie.gif"
future.emsget 1, 1, 69, 61, bg1#
future.emsget 71, 1, 139, 61, bg2#
future.emsget 141, 1, 209, 61, bg3#
future.emsget 211, 1, 279, 61, bg4#
future.emsget 1, 64, 69, 124, bomb1#
future.emsget 72, 64, 184, 152, bomb2#
future.emsget 186, 64, 204, 81, attack#
future.LINE 0, 0, 320, 200, 0, BF
X% = 250
Y% = 0
0
win% = 0
FOR I% = 1 TO 20
FOR ii% = 1 TO 7
RANDOMIZE TIMER
X% = INT(RND * 5)
IF ii% = 1 THEN row1(I%) = X%
IF ii% = 2 THEN row2(I%) = X%
IF ii% = 3 THEN row3(I%) = X%
IF ii% = 4 THEN row4(I%) = X%
IF ii% = 5 THEN row5(I%) = X%
IF ii% = 6 THEN row6(I%) = X%
IF ii% = 7 THEN row7(I%) = X%
NEXT ii%
NEXT I%
putlevels
last% = 0
time% = 3
WHILE INKEY$ <> "": WEND
IF LoadAndPlayMIDI%("ctend.mid") = 0 THEN  ELSE
1
IF TimeMIDI > 250 THEN
IF LoadAndPlayMIDI%("ctend.mid") = 0 THEN  ELSE
time% = time% - 1
END IF
GK$ = INKEY$
WHILE INKEY$ <> "": WEND
LINE (1, 0)-(320, 70), 0, BF
PUT (1, 71), bg#, PSET
IF bomb% >= 1 THEN
PUT (205 - ABS(205 - drag%), 30), dino3#
bomb% = bomb% + 1
IF bomb% = 100 THEN bomb% = 0
ELSE
drag% = drag% + 5
IF drag% <= 205 THEN PUT (drag%, 30), dino1#
IF drag% > 205 THEN PUT (205 - ABS(205 - drag%), 30), dino2#
IF drag% = 410 THEN drag% = 5
IF drag% > 205 THEN zz% = 205 - ABS(205 - drag%) ELSE zz% = drag%
IF last% = 1 THEN PUT (zz% + 5, 55), pc1#, OR
IF last% = 2 THEN PUT (zz% + 5, 55), pc2#, OR
IF last% = 3 THEN PUT (zz% + 5, 55), pc3#, OR
IF last% = 4 THEN PUT (zz% + 5, 55), pc4#, OR

END IF
FOR I% = 1 TO time%
PUT (1 + (I% * 18), 1), ball#
NEXT I%

IF time% = 0 THEN
LOCATE 15, 15: PRINT "TIME OVER!!!"
SLEEP
GOTO 0
END IF

'piece placement start
FOR I% = 1 TO 12
IF row1(I%) = 1 THEN PUT ((I% * 20), 80), pc1#, PSET
IF row1(I%) = 2 THEN PUT ((I% * 20), 80), pc2#, PSET
IF row1(I%) = 3 THEN PUT ((I% * 20), 80), pc3#, PSET
IF row1(I%) = 4 THEN PUT ((I% * 20), 80), pc4#, PSET
'IF row1(i%) = 5 THEN PUT ((i% * 20), 80), pc5#, PSET
'IF row1(i%) = 6 THEN PUT ((i% * 20), 80), pc6#, PSET
'IF row1(i%) = 7 THEN PUT ((i% * 20), 80), pc7#, PSET
'IF row1(i%) = 8 THEN PUT ((i% * 20), 80), pc8#, PSET
IF row1(I%) = 10 THEN PUT ((I% * 20), 80), ball#, PSET

IF row2(I%) = 1 THEN PUT ((I% * 20), 97), pc1#, PSET
IF row2(I%) = 2 THEN PUT ((I% * 20), 97), pc2#, PSET
IF row2(I%) = 3 THEN PUT ((I% * 20), 97), pc3#, PSET
IF row2(I%) = 4 THEN PUT ((I% * 20), 97), pc4#, PSET
'IF row2(i%) = 5 THEN PUT ((i% * 20), 97), pc5#, PSET
'IF row2(i%) = 6 THEN PUT ((i% * 20), 97), pc6#, PSET
'IF row2(i%) = 7 THEN PUT ((i% * 20), 97), pc7#, PSET
'IF row2(i%) = 8 THEN PUT ((i% * 20), 97), pc8#, PSET
IF row2(I%) = 10 THEN PUT ((I% * 20), 97), ball#, PSET

IF row3(I%) = 1 THEN PUT ((I% * 20), 114), pc1#, PSET
IF row3(I%) = 2 THEN PUT ((I% * 20), 114), pc2#, PSET
IF row3(I%) = 3 THEN PUT ((I% * 20), 114), pc3#, PSET
IF row3(I%) = 4 THEN PUT ((I% * 20), 114), pc4#, PSET
'IF row3(i%) = 5 THEN PUT ((i% * 20), 114), pc5#, PSET
'IF row3(i%) = 6 THEN PUT ((i% * 20), 114), pc6#, PSET
'IF row3(i%) = 7 THEN PUT ((i% * 20), 114), pc7#, PSET
'IF row3(i%) = 8 THEN PUT ((i% * 20), 114), pc8#, PSET
IF row3(I%) = 10 THEN PUT ((I% * 20), 114), ball#, PSET

IF row4(I%) = 1 THEN PUT ((I% * 20), 131), pc1#, PSET
IF row4(I%) = 2 THEN PUT ((I% * 20), 131), pc2#, PSET
IF row4(I%) = 3 THEN PUT ((I% * 20), 131), pc3#, PSET
IF row4(I%) = 4 THEN PUT ((I% * 20), 131), pc4#, PSET
'IF row4(i%) = 5 THEN PUT ((i% * 20), 131), pc5#, PSET
'IF row4(i%) = 6 THEN PUT ((i% * 20), 131), pc6#, PSET
'IF row4(i%) = 7 THEN PUT ((i% * 20), 131), pc7#, PSET
'IF row4(i%) = 8 THEN PUT ((i% * 20), 131), pc8#, PSET
IF row4(I%) = 10 THEN PUT ((I% * 20), 131), ball#, PSET

IF row5(I%) = 1 THEN PUT ((I% * 20), 148), pc1#, PSET
IF row5(I%) = 2 THEN PUT ((I% * 20), 148), pc2#, PSET
IF row5(I%) = 3 THEN PUT ((I% * 20), 148), pc3#, PSET
IF row5(I%) = 4 THEN PUT ((I% * 20), 148), pc4#, PSET
'IF row5(i%) = 5 THEN PUT ((i% * 20), 148), pc5#, PSET
'IF row5(i%) = 6 THEN PUT ((i% * 20), 148), pc6#, PSET
'IF row5(i%) = 7 THEN PUT ((i% * 20), 148), pc7#, PSET
'IF row5(i%) = 8 THEN PUT ((i% * 20), 148), pc8#, PSET
IF row5(I%) = 10 THEN PUT ((I% * 20), 148), ball#, PSET

IF row6(I%) = 1 THEN PUT ((I% * 20), 165), pc1#, PSET
IF row6(I%) = 2 THEN PUT ((I% * 20), 165), pc2#, PSET
IF row6(I%) = 3 THEN PUT ((I% * 20), 165), pc3#, PSET
IF row6(I%) = 4 THEN PUT ((I% * 20), 165), pc4#, PSET
'IF row6(I%) = 5 THEN PUT ((I% * 20), 165), pc5#, PSET
'IF row6(I%) = 6 THEN PUT ((I% * 20), 165), pc6#, PSET
'IF row6(I%) = 7 THEN PUT ((I% * 20), 165), pc7#, PSET
'IF row6(I%) = 8 THEN PUT ((I% * 20), 165), pc8#, PSET
IF row6(I%) = 10 THEN PUT ((I% * 20), 165), ball#, PSET

IF row7(I%) = 1 THEN PUT ((I% * 20), 182), pc1#, PSET
IF row7(I%) = 2 THEN PUT ((I% * 20), 182), pc2#, PSET
IF row7(I%) = 3 THEN PUT ((I% * 20), 182), pc3#, PSET
IF row7(I%) = 4 THEN PUT ((I% * 20), 182), pc4#, PSET
'IF row7(I%) = 5 THEN PUT ((I% * 20), 182), pc5#, PSET
'IF row7(I%) = 6 THEN PUT ((I% * 20), 182), pc6#, PSET
'IF row7(I%) = 7 THEN PUT ((I% * 20), 182), pc7#, PSET
'IF row7(I%) = 8 THEN PUT ((I% * 20), 182), pc8#, PSET
IF row7(I%) = 10 THEN PUT ((I% * 20), 182), ball#, PSET

NEXT I%
'piece placement end
IF last% > 4 THEN last% = 4

'check explosions!!!
FOR I% = 1 TO 7
IF bomb% = 0 AND item% = 5 THEN
IF ABS(X% - (205 - ABS(205 - drag%))) <= 25 AND ABS(Y% - 30) <= 25 AND drag% > 205 THEN
toss% = 99
bomb% = 1
blow% = 1
END IF

IF ABS(X% - drag%) <= 25 AND ABS(Y% - 30) <= 25 AND drag% < 205 THEN
toss% = 99
bomb% = 1
END IF
END IF
FOR n% = 1 TO 12
IF ABS(X% - (n% * 20)) <= 15 AND ABS(Y% - (63 + (I% * 17))) <= 12 THEN
blow% = 0
IF I% = 1 AND row1(n%) > 0 THEN blow% = 1
IF I% = 2 AND row2(n%) > 0 THEN blow% = 1
IF I% = 3 AND row3(n%) > 0 THEN blow% = 1
IF I% = 4 AND row4(n%) > 0 THEN blow% = 1
IF I% = 5 AND row5(n%) > 0 THEN blow% = 1
IF I% = 6 AND row6(n%) > 0 THEN blow% = 1
IF I% = 7 AND row7(n%) > 0 THEN blow% = 1

IF I% = 1 AND row1(n%) = 10 THEN win% = 1
IF I% = 2 AND row2(n%) = 10 THEN win% = 1
IF I% = 3 AND row3(n%) = 10 THEN win% = 1
IF I% = 4 AND row4(n%) = 10 THEN win% = 1
IF I% = 5 AND row5(n%) = 10 THEN win% = 1
IF I% = 6 AND row6(n%) = 10 THEN win% = 1
IF I% = 7 AND row7(n%) = 10 THEN win% = 1



IF blow% >= 1 THEN
IF X% < 31 THEN X% = 31
IF Y% > 140 THEN Y% = 130
'LOCATE 1, 1: PRINT x% - 30, y% - 8
PUT (X% - 30, Y% - 8), bomb1#
toss% = 99
IF I% = 1 AND row1(n%) = item% THEN
ch% = 1
row1(n%) = 0
checkver I% + 0, n% + 0, item% + 0
END IF
IF I% = 2 AND row2(n%) = item% THEN
ch% = 1
row2(n%) = 0
checkver I% + 0, n% + 0, item% + 0
END IF
IF I% = 3 AND row3(n%) = item% THEN
ch% = 1
row3(n%) = 0
checkver I% + 0, n% + 0, item% + 0
END IF
IF I% = 4 AND row4(n%) = item% THEN
ch% = 1
row4(n%) = 0
checkver I% + 0, n% + 0, item% + 0
END IF
IF I% = 5 AND row5(n%) = item% THEN
ch% = 1
row5(n%) = 0
checkver I% + 0, n% + 0, item% + 0
END IF
IF I% = 6 AND row6(n%) = item% THEN
ch% = 1
row6(n%) = 0
checkver I% + 0, n% + 0, item% + 0
END IF
IF I% = 7 AND row7(n%) = item% THEN
ch% = 1
row7(n%) = 0
checkver I% + 0, n% + 0, item% + 0
END IF
IF ch% = 1 THEN
check I%, n%, item%
END IF
END IF
END IF
NEXT n%
IF ch% = 0 AND I% = 7 AND toss% = 99 THEN
FOR t% = 1 TO 12
IF 205 - ABS(205 - drag%) > (20 * t%) AND 205 - ABS(205 - drag%) < (38 * t%) THEN IF row1(t%) = 0 THEN row1(t%) = last% ELSE IF row1(t% + 1) = 0 THEN row1(t% + 1) = last%
NEXT t%
IF item% < 5 THEN last% = item%
END IF
NEXT I%
ch% = 0
blow% = 0
IF bomb% > 0 THEN last% = 0
'gravity effects start
FOR n% = 2 TO 7
FOR I% = 1 TO 20
IF n% = 2 THEN
IF row2(I%) = 0 THEN
row2(I%) = row1(I%)
row1(I%) = 0
END IF
END IF
IF n% = 3 THEN
IF row3(I%) = 0 THEN
row3(I%) = row2(I%)
row2(I%) = 0
END IF
END IF
IF n% = 4 THEN
IF row4(I%) = 0 THEN
row4(I%) = row3(I%)
row3(I%) = 0
END IF
END IF
IF n% = 5 THEN
IF row5(I%) = 0 THEN
row5(I%) = row4(I%)
row4(I%) = 0
END IF
END IF
IF n% = 6 THEN
IF row6(I%) = 0 THEN
row6(I%) = row5(I%)
row5(I%) = 0
END IF
END IF
IF n% = 7 THEN
IF row7(I%) = 0 THEN
row7(I%) = row6(I%)
row6(I%) = 0
END IF
END IF
NEXT I%
NEXT n%
'gravity effects end

IF toss% >= 1 THEN toss% = toss% + 1

PUT (250, 10), bg1#, PSET
'balls thrown!!!
IF toss% = 1 THEN PUT (250, 10), bg2#, PSET
IF toss% = 2 THEN PUT (250, 10), bg3#, PSET
IF toss% >= 3 THEN
PUT (250, 10), bg4#, PSET
IF toss% < arc% / 2 THEN Y% = Y% - arc% / 4 + 1 ELSE Y% = Y% + arc% / 4 + 3
add% = arc% / 2.7
'FOR i% = 1 TO 36

X% = X% - (pow% / 2) + add%
IF X% > 240 THEN X% = 240
IF pow% = 0 THEN X% = 240
IF X% <= 1 OR Y% >= 180 OR X% >= 300 THEN
X% = 1
Y% = 180
last% = item%
toss% = 100
END IF
IF Y% < 1 THEN
ELSE
IF item% = 1 THEN PUT (X%, Y%), pc1#', PSET
IF item% = 2 THEN PUT (X%, Y%), pc2#', PSET
IF item% = 3 THEN PUT (X%, Y%), pc3#', PSET
IF item% = 4 THEN PUT (X%, Y%), pc4#', PSET
IF item% = 5 THEN PUT (X%, Y%), attack#
END IF
END IF
'end balls thrown!!!
IF toss% = 100 THEN
toss% = 0
item% = INT(RND * 5) + 1
END IF
IF toss% = 0 THEN
X% = 240
Y% = 40
END IF



IF pow% < 0 THEN pow% = 0
IF pow% > 60 THEN pow% = 60
IF arc% < 0 THEN arc% = 0
IF arc% > 36 THEN arc% = 36


LINE (236, 38 - arc%)-(248, 38), 212, BF
LINE (236, 1)-(248, 38), 16, B

LINE (310 - pow%, 3)-(310, 15), 212, BF
LINE (250, 3)-(310, 15), 16, B
IF item% < 1 THEN item% = 1
LINE (250, 16)-(270, 38), 16, BF
IF item% = 1 THEN PUT (250, 17), pc1#, PSET
IF item% = 2 THEN PUT (250, 17), pc2#, PSET
IF item% = 3 THEN PUT (250, 17), pc3#, PSET
IF item% = 4 THEN PUT (250, 17), pc4#, PSET
IF item% = 5 THEN PUT (250, 17), attack#, PSET

IF toss% = 0 THEN
IF GK$ = CHR$(0) + "H" THEN arc% = arc% + 1
IF GK$ = CHR$(0) + "P" THEN arc% = arc% - 1
IF GK$ = CHR$(0) + "K" THEN pow% = pow% + 1
IF GK$ = CHR$(0) + "M" THEN pow% = pow% - 1
'IF GK$ = CHR$(32) THEN
'item% = item% + 1
'IF item% = 6 THEN item% = 1
'END IF
IF GK$ = CHR$(13) THEN toss% = 1
END IF
IF GK$ = CHR$(27) THEN
stopmidi
SYSTEM
END IF
LOCATE 1, 1: PRINT win%
del 1500
IF win% = 1 THEN
COLOR 176
'LINE (0, 50)-(250, 200), 0, BF
FOR I% = 0 TO 8
del 1500
PUT (I% * 20 + 1, 50), bomb2#
PUT (I% * 20 + 1, 110), bomb2#
NEXT I%
del 20000
IF time% = 1 THEN fliplay "suzie.fli"
IF time% = 2 THEN fliplay "suzie2.fli"
IF time% = 3 THEN fliplay "suzie3.fli"
LOCATE 10, 15: PRINT "YOU WIN"
del 20000
SLEEP 1
'stopmidi
level% = level% + 1
GOTO 0
END IF
GOTO 1

REM $STATIC
SUB check (I%, n%, item%)

FOR X% = 1 TO 12 - n%
pass% = 0
IF I% = 1 THEN
IF row1(n% + X%) = item% THEN
row1(n% + X%) = 0
checkver I% + 0, n% + X%, item%
pass% = 1
END IF
END IF
IF I% = 2 THEN
IF row2(n% + X%) = item% THEN
row2(n% + X%) = 0
checkver I% + 0, n% + X%, item%
pass% = 2
END IF
END IF
IF I% = 3 THEN
IF row3(n% + X%) = item% THEN
row3(n% + X%) = 0
checkver I% + 0, n% + X%, item%
pass% = 3
END IF
END IF
IF I% = 4 THEN
IF row4(n% + X%) = item% THEN
row4(n% + X%) = 0
checkver I% + 0, n% + X%, item%
pass% = 4
END IF
END IF
IF I% = 5 THEN
IF row5(n% + X%) = item% THEN
row5(n% + X%) = 0
checkver I% + 0, n% + X%, item%
pass% = 5
END IF
END IF
IF I% = 6 THEN
IF row6(n% + X%) = item% THEN
row6(n% + X%) = 0
checkver I% + 0, n% + X%, item%
pass% = 6
END IF
END IF
IF I% = 7 THEN
IF row7(n% + X%) = item% THEN
row7(n% + X%) = 0
checkver I% + 0, n% + X%, item%
pass% = 7
END IF
END IF
IF pass% = 0 THEN X% = 13
NEXT X%

FOR X% = 1 TO (12 - (12 - n%)) + 1
IF I% = 1 THEN
IF row1(n% - X%) = item% THEN
row1(n% - X%) = 0
checkver I% + 0, n% + X%, item%
pass% = 1
END IF
END IF
IF I% = 2 THEN
IF row2(n% - X%) = item% THEN
row2(n% - X%) = 0
checkver I% + 0, n% + X%, item%
pass% = 2
END IF
END IF
IF I% = 3 THEN
IF row3(n% - X%) = item% THEN
row3(n% - X%) = 0
checkver I% + 0, n% + X%, item%
pass% = 3
END IF
END IF
IF I% = 4 THEN
IF row4(n% - X%) = item% THEN
row4(n% - X%) = 0
checkver I% + 0, n% + X%, item%
pass% = 4
END IF
END IF
IF I% = 5 THEN
IF row5(n% - X%) = item% THEN
row5(n% - X%) = 0
checkver I% + 0, n% + X%, item%
pass% = 5
END IF
END IF
IF I% = 6 THEN
IF row6(n% - X%) = item% THEN
row6(n% - X%) = 0
checkver I% + 0, n% + X%, item%
pass% = 6
END IF
END IF
IF I% = 7 THEN
IF row7(n% - X%) = item% THEN
row7(n% - X%) = 0
checkver I% + 0, n% + X%, item%
pass% = 7
END IF
END IF
IF pass% = 0 THEN X% = (12 - (12 - n%)) + 1
NEXT X%


END SUB

SUB checkver (I%, n%, item%)

FOR X% = 1 TO 7 - I%
IF I% + X% = 2 THEN
IF row2(n%) = item% THEN
pass% = 1
row2(n%) = 0
check I% + X%, n% + 0, item% + 0
END IF
END IF
IF I% + X% = 3 THEN
IF row3(n%) = item% THEN
pass% = 1
row3(n%) = 0
check I% + X%, n% + 0, item% + 0
END IF
END IF
IF I% + X% = 4 THEN
IF row4(n%) = item% THEN
pass% = 1
row4(n%) = 0
check I% + X%, n% + 0, item% + 0
END IF
END IF
IF I% + X% = 5 THEN
IF row5(n%) = item% THEN
pass% = 1
row5(n%) = 0
check I% + X%, n% + 0, item% + 0
END IF
END IF
IF I% + X% = 6 THEN
IF row6(n%) = item% THEN
pass% = 1
row6(n%) = 0
check I% + X%, n% + 0, item% + 0
END IF
END IF
IF I% + X% = 7 THEN
IF row7(n%) = item% THEN
pass% = 1
row7(n%) = 0
check I% + X%, n% + 0, item% + 0
END IF
END IF

IF pass% = 0 THEN X% = 8 - I%
pass% = 0
NEXT X%

FOR X% = 1 TO 7 - (7 - I%)
IF I% - X% = 2 THEN
IF row2(n%) = item% THEN
pass% = 1
row2(n%) = 0
check I% - X%, n% + 0, item% + 0
END IF
END IF
IF I% - X% = 3 THEN
IF row3(n%) = item% THEN
pass% = 1
row3(n%) = 0
check I% - X%, n% + 0, item% + 0
END IF
END IF
IF I% - X% = 4 THEN
IF row4(n%) = item% THEN
pass% = 1
row4(n%) = 0
check I% - X%, n% + 0, item% + 0
END IF
END IF
IF I% - X% = 5 THEN
IF row5(n%) = item% THEN
pass% = 1
row5(n%) = 0
check I% - X%, n% + 0, item% + 0
END IF
END IF
IF I% - X% = 6 THEN
IF row6(n%) = item% THEN
pass% = 1
row6(n%) = 0
check I% - X%, n% + 0, item% + 0
END IF
END IF
IF I% - X% = 7 THEN
IF row7(n%) = item% THEN
pass% = 1
row7(n%) = 0
check I% - X%, n% + 0, item% + 0
END IF
END IF

IF pass% = 0 THEN X% = 7
pass% = 0
NEXT X%



END SUB

DEFSNG A-Z
SUB del (dela%)
FOR I# = 1 TO dela%
NEXT I#
END SUB

FUNCTION int86qb$ (intnr%, flag%, ax%, bx%, CX%, dx%, di%, si%, bp%, ds%, es%)
'------------------------------------------------------------------------
'Conversion of all integers in strings
flag$ = LEFT$(int2str$(flag%), 1): ax$ = int2str$(ax%):
bx$ = int2str$(bx%): CX$ = int2str$(CX%): dx$ = int2str$(dx%):
di$ = int2str$(di%): si$ = int2str$(si%): bp$ = int2str$(bp%):
ds$ = int2str$(ds%): es$ = int2str$(es%):
'Now all integersvalues are direct usable in asm$
'------------------------------------------------------------------------
DIM datas%(11)    'that is all we need
dataseg% = VARSEG(datas%(0)): flagoff% = VARPTR(datas%(0))
dataseg$ = int2str$(dataseg%): flagoff$ = int2str$(flagoff%)
axoff$ = int2str$(flagoff% + 2): bxoff$ = int2str$(flagoff% + 4)
cxoff$ = int2str$(flagoff% + 6): dxoff$ = int2str$(flagoff% + 8)
dioff$ = int2str$(flagoff% + 10): sioff$ = int2str$(flagoff% + 12)
bpoff$ = int2str$(flagoff% + 14): dsoff$ = int2str$(flagoff% + 16)
esoff$ = int2str$(flagoff% + 18): intnroff$ = int2str$(flagoff% + 20)
'Now all integers are directly adressable in memory through asm$
'We could have used only this as pointers and leave the immediate values
'but....we don't.
'------------------------------------------------------------------------
asm$ = ""
asm$ = asm$ + CHR$(&H9C)                       'pushf
asm$ = asm$ + CHR$(&H50)                       'push ax
asm$ = asm$ + CHR$(&H53)                       'push bx
asm$ = asm$ + CHR$(&H51)                       'push cx
asm$ = asm$ + CHR$(&H52)                       'push dx
asm$ = asm$ + CHR$(&H57)                       'push di
asm$ = asm$ + CHR$(&H56)                       'push si
asm$ = asm$ + CHR$(&H55)                       'push bp
asm$ = asm$ + CHR$(&H1E)                       'push ds
asm$ = asm$ + CHR$(&H6)                        'push es

'2)LOAD REGISTERS
'First the flags( questionable if this ever happens):
asm$ = asm$ + CHR$(&HB4) + flag$              'mov ax,flag$
asm$ = asm$ + CHR$(&H9E)                      'sahf stores ah into flags

'Segment registers mbv ax :  only when not (accidentally) 0
IF ds% <> 0 THEN                              'safety
  asm$ = asm$ + CHR$(&HB8) + ds$              'mov ax,ds$
  asm$ = asm$ + CHR$(&H8E) + CHR$(&HD8)       'mov ds,ax
END IF
IF es% <> 0 THEN                              'safety
  asm$ = asm$ + CHR$(&HB8) + es$              'mov ax,es$
  asm$ = asm$ + CHR$(&H8E) + CHR$(&HC0)       'mov es,ax
END IF
'the rest of registers :
asm$ = asm$ + CHR$(&HB8) + ax$                'mov ax,ax$
asm$ = asm$ + CHR$(&HBB) + bx$                'mov bx,bx$
asm$ = asm$ + CHR$(&HB9) + CX$                'mov cx,cx$
asm$ = asm$ + CHR$(&HBA) + dx$                'mov dx,dx$
asm$ = asm$ + CHR$(&HBF) + di$                'mov di,di$
asm$ = asm$ + CHR$(&HBE) + si$                'mov si,si$
asm$ = asm$ + CHR$(&HBD) + bp$                'mov bp,bp$
'oke now the interrupt himself
asm$ = asm$ + CHR$(&HCD) + CHR$(intnr%)       'interrupt nr

'First make our DATAS% adressable:
asm$ = asm$ + CHR$(&H1E)                         'push ds
asm$ = asm$ + CHR$(&HB8) + dataseg$              'mov ax,DATASseg$
asm$ = asm$ + CHR$(&H8E) + CHR$(&HD8)            'mov ds,ax
					  
'We first pushed DS segment register since we want to adress our DATA_segment
asm$ = asm$ + CHR$(&H8F) + CHR$(&H6) + dsoff$    'pop dsoff$
asm$ = asm$ + CHR$(&H8C) + CHR$(&H6) + esoff$    'mov esoff$,ES

asm$ = asm$ + CHR$(&H9F)                         'lahf
asm$ = asm$ + CHR$(&H88) + CHR$(&H26) + flagoff$ 'mov flagoff$,ah
		    
'The rest is more simple i think:
asm$ = asm$ + CHR$(&H89) + CHR$(&H2E) + bpoff$   'mov bpoff$,bp
asm$ = asm$ + CHR$(&H89) + CHR$(&H36) + sioff$   'mov sioff$,si
asm$ = asm$ + CHR$(&H89) + CHR$(&H3E) + dioff$   'mov dioff$,di
asm$ = asm$ + CHR$(&H89) + CHR$(&H16) + dxoff$   'mov dxoff$,dx
asm$ = asm$ + CHR$(&H89) + CHR$(&HE) + cxoff$    'mov cxoff$,cx
asm$ = asm$ + CHR$(&H89) + CHR$(&H1E) + bxoff$   'mov bxoff$,bx
asm$ = asm$ + CHR$(&HA3) + axoff$                'mov axoff$,ax
			       
'Now let us neatly finish by just popping everything back in order
asm$ = asm$ + CHR$(&H7)                          'pop es
asm$ = asm$ + CHR$(&H1F)                         'pop ds
asm$ = asm$ + CHR$(&H5D)                         'pop bp
asm$ = asm$ + CHR$(&H5E)                         'pop si
asm$ = asm$ + CHR$(&H5F)                         'pop di
asm$ = asm$ + CHR$(&H5A)                         'pop dx
asm$ = asm$ + CHR$(&H59)                         'pop cx
asm$ = asm$ + CHR$(&H5B)                         'pop bx
asm$ = asm$ + CHR$(&H58)                         'pop ax
asm$ = asm$ + CHR$(&H9D)                         'popf
'We are done?
asm$ = asm$ + CHR$(&HCB)                         'retf

DEF SEG = VARSEG(asm$)
offcode% = SADD(asm$): CALL absolute(offcode%): DEF SEG

ui$ = HEX$(intnr%)
FOR I% = 0 TO 9
  hx$ = HEX$(datas%(I%))
  hx$ = STRING$(4 - LEN(hx$), "0") + hx$
  ui$ = ui$ + "," + hx$
NEXT

int86qb$ = ui$

END FUNCTION

DEFINT A-Z
SUB Pause (tdelay#)
'----------------------------------------------------------------------------
time1# = TIMER
DO
LOOP WHILE (TIMER - time1# < tdelay#) OR (time1# > TIMER)
END SUB

DEFSNG A-Z
SUB Pokestring (SEGJE%, OFFJE%, Main$)
'------------------------------------------------------
'This function pokes a string (might be ASCIIZ)into
'memory at a given location, making it possible to
'access strings in byte form
'------------------------------------------------------

DEF SEG = SEGJE%
FOR I% = 0 TO LEN(Main$) - 1
  POKE OFFJE% + I%, ASC(MID$(Main$, I% + 1, 1))
NEXT
DEF SEG

END SUB

DEFINT A-Z
SUB putlevels
SHARED level%
RANDOMIZE TIMER
IF level% = 0 THEN
FOR I% = -1 TO 14
row1(I%) = 0
NEXT I%
row2(6) = 10
END IF

IF level% = 1 THEN
FOR I% = 1 TO 12
row1(I%) = 0
row2(I%) = 0
row3(I%) = 0
NEXT I%
row4(9) = 10
END IF

IF level% = 2 THEN
FOR I% = 1 TO 6
row1(I%) = 1
row2(I% + 5) = 3
row3(I% + 8) = 2
NEXT I%
row2(3) = 10
END IF

IF level% = 3 THEN
FOR I% = 1 TO 3
row2(I%) = 1
row2(I% + 3) = 2
row2(I% + 6) = 3
row2(I% + 9) = 4
row1(I% + 5) = 4
row3(I% + 8) = 1
NEXT I%
row3(4) = 10
END IF

IF level% = 4 THEN
FOR I% = 1 TO 8
row1(I%) = 0
row2(I%) = 1
row3(I% + 4) = 2
row4(I% + 5) = 3
row5(I% + 6) = 4
row6(I% + 7) = 3
row7(I% + 8) = 2
NEXT I%
row3(3) = 10
END IF

IF level% = 5 THEN
RANDOMIZE TIMER
FOR I% = 1 TO 12
X% = INT(RND * 4) + 1
row1(I%) = X%
NEXT I%
row2(6) = 10
END IF

IF level% = 6 THEN
FOR I% = 1 TO 12
row1(I%) = 0
row2(I%) = 1
row6(I%) = 0
NEXT I%
row5(9) = 10
END IF

IF level% = 7 THEN
FOR I% = 1 TO 6
row1(I%) = 1
row2(I% + 5) = 3
row3(I% + 8) = 2
NEXT I%
row3(3) = 10
END IF

IF level% = 8 THEN
FOR I% = 1 TO 3
row2(I%) = 1
row2(I% + 3) = 2
row2(I% + 6) = 3
row2(I% + 9) = 4
row1(I% + 5) = 4
row3(I% + 8) = 1
NEXT I%
row4(4) = 10
END IF

IF level% = 9 THEN
FOR I% = 1 TO 3
row1(I%) = 0
row2(I%) = 1
row3(I% + 4) = 2
row4(I% + 5) = 3
row5(I% + 6) = 4
row6(I% + 7) = 3
row7(I% + 8) = 2
NEXT I%
row5(2) = 10
END IF


IF level% = 10 THEN
FOR I% = -1 TO 14
row1(I%) = 2
NEXT I%
row3(4) = 10
END IF

IF level% = 11 THEN
FOR I% = 1 TO 12
row1(I%) = 0
row2(I%) = 0
row3(I%) = 0
X% = INT(RND * 4) + 1
row4(I%) = X%
row5(I%) = X%
row6(I%) = X%
row7(I%) = X%
NEXT I%
row3(8) = 1
row3(9) = 2
row3(10) = 3
row4(9) = 10
END IF

IF level% = 12 THEN
FOR I% = 1 TO 6
row1(I%) = 1
row2(I% + 5) = 3
row3(I% + 8) = 2
NEXT I%
row4(3) = 10
END IF

IF level% = 13 THEN
FOR I% = 1 TO 3
row2(I%) = 1
row2(I% + 3) = 2
row2(I% + 6) = 3
row3(I%) = 4
NEXT I%
row3(10) = 10
END IF

IF level% = 14 THEN
FOR I% = 1 TO 12
row1(I%) = 0
row2(I%) = 2
row3(I% + 4) = 2
row4(I% + 5) = 3
row5(I% + 6) = 4
row6(I% + 7) = 3
row7(I% + 8) = 2
NEXT I%
row4(1) = 1
row4(2) = 2
row4(3) = 3
row5(3) = 10
END IF

IF level% >= 15 THEN
X% = INT(RND * 7)
I% = INT(RND * 12)
IF X% = 1 THEN row1(I%) = 10
IF X% = 2 THEN row2(I%) = 10
IF X% = 3 THEN row3(I%) = 10
IF X% = 4 THEN row4(I%) = 10
IF X% = 5 THEN row5(I%) = 10
IF X% = 6 THEN row6(I%) = 10
IF X% = 7 THEN row7(I%) = 10
END IF

END SUB

DEFSNG A-Z
SUB trash


END SUB

