'We were too lazy to write an infofile, so we'll give you the source instead.
'Greetings to elfsong btw =)
'The files required to run this demo are 380volt.com, Sune.exe and Dit.Dat.
'All other files are unnecessary and should be deleted.
'The total demo size is just below 2.3mb.
'If something fucks, call liket at +46-31-11010110001111110001001b
'ask for liket
'(the number IS correct, as long as you convert the binary digits to decimal)

'The demo runs every frame (50hz) on a dx2-66, just so you know. Pentium is
'not needed nor used. Pentium sucks.


$dynamic
DEFINT a - z
clearherc = 1
$include"include.bas"

$include"cs3mtsr.drv"
$include"msynclib.bas"

'parms beforerun "380x"
'$parms beforerun "lh cs3mtsr 1234.s3m 40"
'$parms afterrun "cs3mtsr"

TYPE VesaInfo
    shit1 AS WORD
    shit2 AS BYTE
    shit3 AS BYTE
    gran AS WORD
    shitshit AS STRING * 1000
END TYPE

DIM vesa AS vesainfo

shared vesa, granularity

SHARED red1?(), green1?(), blue1?(), xred2?(), xgreen2?(), xblue2?()
SHARED xred3?(), xgreen3?(), xblue3?()

SHARED Frms.Batman, Pages.BatMan

meminfo = 1

'vu = 1

DIM red1?( 255 )
DIM green1?( 255 )
DIM blue1?( 255 )


DIM xred2?( 255 )
DIM xgreen2?( 255 )
DIM xblue2?( 255 )

DIM xred3?( 255 )
DIM xgreen3?( 255 )
DIM xblue3?( 255 )

SHARED Vmodes()

DIM Vmodes( 10 )

vmodes( 1 ) = 1
vmodes( 2 ) = 1

VideoSelect Vmodes()

open "video.dat" for output as #1
print #1,vmodes(2)
close #1


screen13

SHARED LowRes192, HighRes192

Set256192

'$include "tweaks\50\256192c1.256"

initmusic

PrintMemReference

TorusLineCalc

Demopart.CheckerBoard

'jump 9

'DemoPart.TioTommaSekunder

DemoPart.VoxelCredits

Picture.Brum

DemoPart.SvenskFlagga

'jump 12+1

DemoPart.CityAnim

'DemoPart.BatmanAnim

DemoPart.Tunnel

Picture.Goato10

DO
    mvbl
LOOP until order=>23

'DemoPart.TheEndLogo

END



SUB DemoPart.CheckerBoard

    DIM firemul( 100 )
    DIM screenmul( 100 )
    FOR a = 0 TO 99
        firemul( a ) = a * 128
        screenmul( a ) = (( a - 1 ) * 256 )
    NEXT a

    yyyyy! = 0.9

    highestpaskaa = 799
    paskaadiv = highestpaskaa \ 50
    paskaadiv2 = highestpaskaa \ 25

    antal = 6

    DIM sinus( 359 )

    FOR v = 0 TO 359
        sinus( v ) = SIN( v * pi! / 180 ) * 30
    NEXT v

    DIM sineshake!( 100 )
    FOR v = 0 TO 100
        sineshake!( v ) = SIN( v * pi! / 50 )
    NEXT v

    DIM sinepaskaa( 1600 )

    FOR v = 0 TO 1600
        sinepaskaa( v ) = SIN( v * pi! / 800 ) * 20
    NEXT v

    DIM paskaaPOSITIONS( antal ), paskaacolour( antal ), xpos( antal ), ypos( antal )

    DIM temp( antal )

    tx = highestpaskaa / antal

    FOR a = 1 TO antal
        t = t + tx
        paskaaPOSITIONS( a ) = t - 1
    NEXT a

    DIM rpaskaa( antal ), gpaskaa( antal ), bpaskaa( antal )

    rpaskaa( 1 ) = 1: gpaskaa( 1 ) = 0: bpaskaa( 1 ) = 0 'red
    rpaskaa( 2 ) = 1: gpaskaa( 2 ) = 0: bpaskaa( 2 ) = 1 'purple
    rpaskaa( 3 ) = 0: gpaskaa( 3 ) = 0: bpaskaa( 3 ) = 1 'blue
    rpaskaa( 4 ) = 0: gpaskaa( 4 ) = 1: bpaskaa( 4 ) = 1 'cyan
    rpaskaa( 5 ) = 1: gpaskaa( 5 ) = 1: bpaskaa( 5 ) = 0 'yellow
    rpaskaa( 6 ) = 1: gpaskaa( 6 ) = 1: bpaskaa( 6 ) = 1 'white
    '    rpaskaa(7)=1:gpaskaa(7)=0:bpaskaa(7)=1  'purple
    '    rpaskaa(8)=1:gpaskaa(8)=0:bpaskaa(8)=0  'red
    '    rpaskaa(9)=0:gpaskaa(9)=0:bpaskaa(9)=1  'blue

    '    screen13

    mcls 0

    FOR a = 0 TO 255
        setpal a, 0, 0, 0
    NEXT a

    DEF SEG = &ha000

    c = 5

    DIM zoompaskaa( highestpaskaa, 20 )

    DEF SEG = &ha000

    tt = highestpaskaa \ 50

    c = 0
    FOR d = highestpaskaa TO tt STEP - 1
        b! = d / ( highestpaskaa / 50 )
        yy = ( -d + highestpaskaa ) \ ( highestpaskaa \ 100 )
        add! = (( 0 * ( 1 / ( b! )) * 1000 ) + ( 1 * ( 1 / ( b! )) * 1000 )) / 2
        'hercprint 0,0,15,str$(d)+" "
        FOR a = - 10 TO + 10
            xp = ( a * ( 1 / ( b! )) * 1000 ) + add!
            'mpset xp+160,yy,15
            zoompaskaa( -d + highestpaskaa, a + 10 ) = xp
        NEXT a
    NEXT b

    FOR d = highestpaskaa - ( tt ) TO highestpaskaa
        FOR a = - 10 TO + 10
            zoompaskaa( d, a + 10 ) = zoompaskaa( highestpaskaa - tt - 1, a + 10 )
        NEXT a
    NEXT d

    mcls 0

    FOR a = 1 TO antal
        paskaacolour( a ) = a
    NEXT a

    paskaaADD = 1

    eee = 0

    control = 1: vk = 0

    ss! = 15

    maxantal = 3

    '   rastermeter=1

    BaseValue = 1200

    my = 80

    'u!=1

    xvalue = 128 * 76

    ucontrol = 0


    setpal 254, 0, 0, 0
    setpal 253, 0, 0, 0

    '    setpal 60,63,63,63


    DIM Burn?( 16000 )
    DEF SEG = VARSEG( burn?( 0 ))

    OPEN "burn.raw" FOR BINARY AS #1
    GET$ #1, 8, t$
    IF NOT t$ = "mhwanh" + CHR$( 0, 4 ) THEN errormessage "Corrupted picture"
    SEEK #1, 800
    m& = 0
    DO: GET$ #1, 8000, Lg$: POKE$ m&, Lg$: m& = m& + 8000: LOOP UNTIL EOF( 1 )
    CLOSE #1

    FOR a = 0 TO 255
        setpal a, 0, 0, 0
    NEXT a
    WAIT &h3da, 8

    OPEN "gubbar.raw" FOR BINARY AS #1
    GET$ #1, 8, t$
    IF NOT t$ = "mhwanh" + CHR$( 0, 4 ) THEN errormessage "Corrupted picture"

    GET #1,, xsize: xsize = swapendians( xsize )
    GET #1,, ysize: ysize = swapendians( ysize )
    GET #1,, colours: colours = swapendians( colours )

    GET$ #1, 18, t$

    FOR a = 0 TO 255
        GET #1,, r?: GET #1,, g?: GET #1,, b?
        red1?( a ) = r? \ 4
        green1?( a ) = g? \ 4
        blue1?( a ) = b? \ 4
    NEXT a

    SEEK #1, 800

    FOR a = 0 TO 255
        setpal a, 0, 0, 0
    NEXT a

    px = PBVDEFSEG
    DEF SEG = &ha000

    FOR a = 0 TO 199
        GET$ #1, 320, t$
        POKE$ a * 320, t$
    NEXT a

    t$ = ""
    CLOSE #1

    DIM gubbe$( 20, 50 )

    FOR frames = 0 TO 19
        y = frames \ 5
        x = frames MOD 5

        x = ( x * 63 ) + 1
        y = y * 50

        'mpset x+0,y+0,65
        'mpset x+1,y+0,65
        'mpset x+2,y+0,65

        FOR yy = 0 TO 49
            offset?? = (( yy + y ) * 320 ) + x
            gubbe$( frames, yy ) = PEEK$( offset??, 62 )
        NEXT yy

    NEXT a

    OPEN "gubbeb.raw" FOR BINARY AS #1
    GET$ #1, 8, t$
    IF NOT t$ = "mhwanh" + CHR$( 0, 4 ) THEN errormessage "Corrupted picture"

    SEEK #1, 800

    mcls 0

    FOR a = 0 TO 192
        GET$ #1, 256, t$
        POKE$ a * 256, t$
    NEXT a

    CLOSE #1

    DEF SEG = px

    DIM firetabell??( 16000 )
    ms = VARSEG( firetabell??( 0 ))
    FireSeg = ms
    DEF SEG = FireSeg

    OPEN "gubbel.raw" FOR BINARY AS #1
    GET$ #1, 8, t$
    IF NOT t$ = "mhwanh" + CHR$( 0, 4 ) THEN errormessage "Corrupted picture"
    SEEK #1, 32
    FOR a = 0 TO 255
        GET #1,, r?: GET #1,, g?: GET #1,, b?
        xred3?( a ) = r? \ 4
        xgreen3?( a ) = g? \ 4
        xblue3?( a ) = b? \ 4
    NEXT a
    SEEK #1, 800
    m& = 0: DO: GET$ #1, 8000, Lg$: POKE$ m&, Lg$: m& = m& + 8000: LOOP UNTIL EOF( 1 )
    CLOSE #1

    DIM GtiLogo128?( 8000 )
    DEF SEG = VARSEG( gtilogo128?( 0 ))

    OPEN "gt128.raw" FOR BINARY AS #1
    GET$ #1, 8, t$
    IF NOT t$ = "mhwanh" + CHR$( 0, 4 ) THEN errormessage "Corrupted picture"
    SEEK #1, 800
    GET$ #1, 8000, Lg$
    POKE$ 0, lg$
    CLOSE #1


    DIM Logo380?( 16000 )
    DEF SEG = VARSEG( Logo380?( 0 ))

    OPEN "3333.raw" FOR BINARY AS #1
    GET$ #1, 8, t$
    IF NOT t$ = "mhwanh" + CHR$( 0, 4 ) THEN errormessage "Corrupted picture"
    SEEK #1, 800
    m& = 0: DO: GET$ #1, 8000, Lg$: POKE$ m&, Lg$: m& = m& + 8000: LOOP UNTIL EOF( 1 )
    SEEK #1, 32
    FOR a = 0 TO 255
        GET #1,, r?: GET #1,, g?: GET #1,, b?
        xred2?( a ) = r? \ 4
        xgreen2?( a ) = g? \ 4
        xblue2?( a ) = b? \ 4
    NEXT a
    '    setpal 255,63,63,63

    CLOSE #1

    DIM Logo3802?( 32000 )
    DEF SEG = VARSEG( Logo3802?( 0 ))

    OPEN "3334.raw" FOR BINARY AS #1
    GET$ #1, 8, t$
    IF NOT t$ = "mhwanh" + CHR$( 0, 4 ) THEN errormessage "Corrupted picture"
    SEEK #1, 800
    m& = 0: DO: GET$ #1, 8000, Lg$: POKE$ m&, Lg$: m& = m& + 8000: LOOP UNTIL EOF( 1 )
    SEEK #1, 32
    FOR a = 0 TO 255
        GET #1,, r?: GET #1,, g?: GET #1,, b?
        xred2?( a ) = r? \ 4
        xgreen2?( a ) = g? \ 4
        xblue2?( a ) = b? \ 4
    NEXT a
    '    setpal 255,63,63,63

    CLOSE #1




    lg$ = ""

    LogoSeg = VARSEG( GTILogo128?( 0 ))
    LogoPtr = VARPTR( GTILogo128?( 0 ))

    LogoSeg380 = VARSEG( Logo380?( 0 ))
    LogoPtr380 = VARPTR( Logo380?( 0 ))
    LogoSeg3802 = VARSEG( Logo3802?( 0 ))
    LogoPtr3802 = VARPTR( Logo3802?( 0 ))

    DIM minnepaskaa?( 32700 )
    paskaaseg = VARSEG( minnepaskaa?( 0 ))

    jump 1

    '    exit sub

    '          m  e  i  n  e  d  a  m  e  n  u  n  d  h  e rr  e  n
    data 3, 5, 4, 4, 4, 7, 4, 5, 4, 5, 7, 5, 5, 5, 4, 3, 3, 4, 8, 40

    offset?? = 42 * 256 + 90

    FOR frames = 0 TO 19
        FOR y = 0 TO 49
            PBVDEFSEG = &ha000
            POKE$ y * 256 + offset??, gubbe$( frames, y )
        NEXT y
        READ vbls
        FOR a = 1 TO vbls * 1
            mvbl
        NEXT a

        IF frames = 0 THEN
            FOR e = 0 TO 50
                mvbl
                FOR a = 0 TO 255
                    r = ( red1?( a ) * e ) \ 50
                    g = ( green1?( a ) * e ) \ 50
                    b = ( blue1?( a ) * e ) \ 50
                    setpal a, r, g, b
                NEXT a
            NEXT e
            DO
                mvbl
            LOOP UNTIL order > 1
        END IF

        IF order > 2 THEN EXIT FOR

    NEXT frames

    ERASE gubbe$()


    FOR e = 50 TO 35 STEP - 1
        mvbl
        FOR a = 0 TO 255
            r = ( red1?( a ) * e ) \ 50
            g = ( green1?( a ) * e ) \ 50
            b = ( blue1?( a ) * e ) \ 50
            setpal a, r, g, b
        NEXT a
    NEXT e

    DO
        mvbl
    LOOP UNTIL sync( 3, 255 )


    FillMode = 1

    lf = 64

    DEF SEG = CODESEG( FireValuesmodify1 )
    POKEI CODEPTR( firevaluesmodify1 ) + 1, &h0000
    DEF SEG = CODESEG( firevaluesmodify2 )
    POKEI CODEPTR( firevaluesmodify2 ) + 2, &h0000

    DO


        lf = lf - 1
        IF lf < 0 THEN

            IF scenedone = 0 THEN
                FillMode = 0
                SceneDone = 1
                DEF SEG = VARSEG( firetabell??( 0 ))
                POKE$ 0, STRING$( 32000, 0 )
                DEF SEG = CODESEG( FireValueSModify1 )
                POKEI CODEPTR( firevaluesmodify1 ) + 1, &h0808
                DEF SEG = CODESEG( firevaluesmodify2 )
                POKEI CODEPTR( firevaluesmodify2 ) + 2, &h0808
                setpal 255, 63, 63, 63
            END IF

            lf = 0

        END IF

        IF ucontrol = 0 THEN u! = u! + 0.005
        IF u! > 1 THEN u! = 1: ucontrol = 1

        INCR paskaacounter

        IF paskaacounter MOD 4 = 1 THEN eee = eee - 1: IF eee = - 1 THEN eee = 0



        '    ss!=ss!*0.95

        '    yshk=((paskaacounter mod 2)-0.5)*ss!

        'hercprint 1,1,15,keypressed$


        IF vk = 0 THEN control = 1
        IF vk = 400 THEN control = 2
        IF vkx = 175 AND control = 2 THEN vkx = 0: control = 3
        IF vk = 1200 THEN control = 4
        IF vkx = 175 AND control = 4 THEN vkx = 0: control = 3



        IF control = 1 OR control = 3 THEN vk = vk + 4
        IF control = 2 OR control = 4 THEN vkx = vkx + 1
        IF vk > 1599 THEN vk = 0: control = 1


        IF order > = 5 THEN vk = BaseValue

        paskaaADD = sinepaskaa( vk )

        'hercprint 1,3,15,str$(vk)+"   "
        'hercprint 1,4,15,str$(vkx)+"   "

        FOR a = 1 TO antal
            paskaapositions( a ) = paskaapositions( a ) + paskaaADD
        NEXT a


        IF paskaaPOSITIONS( antal ) > ( highestpaskaa - 1 ) THEN

            FOR a = 1 TO antal
                temp( a ) = paskaaPOSITIONS( a )
            NEXT a
            paskaaPOSITIONS( 1 ) = paskaaPOSITIONS( antal ) - ( highestpaskaa - 1 )
            FOR a = 2 TO antal
                paskaaPOSITIONS( a ) = temp( a - 1 )
            NEXT a

            rrrx = rrrx + 10
            IF rrrx > 359 THEN rrrx = rrrx - 359
            rrry = rrry + 12
            IF rrry > 359 THEN rrry = rrry - 359

            FOR a = 1 TO antal
                temp( a ) = xpos( a )
            NEXT a

            xpos( 1 ) = sinus( rrrx )
            IF NoCheckerBoardTurns = 1 THEN Xpos( 1 ) = 0

            FOR a = 2 TO antal
                xpos( a ) = temp( a - 1 )
            NEXT a

            FOR a = 1 TO antal
                temp( a ) = ypos( a )
            NEXT a

            ypos( 1 ) = sinus( rrry )
            IF NoCheckerBoardTurns = 1 THEN Ypos( 1 ) = 0

            FOR a = 2 TO antal
                ypos( a ) = temp( a - 1 )
            NEXT a



            FOR a = 1 TO antal
                temp( a ) = paskaacolour( a )
            NEXT a

            paskaacolour( 1 ) = paskaacolour( antal )
            FOR a = 2 TO antal
                paskaacolour( a ) = temp( a - 1 )
            NEXT a

        END IF


        IF paskaaPOSITIONS( 1 ) < 0 THEN

            FOR a = 1 TO antal
                temp( a ) = paskaaPOSITIONS( a )
            NEXT a
            paskaaPOSITIONS( antal ) = paskaaPOSITIONS( 1 ) + ( highestpaskaa )
            FOR a = 1 TO antal - 1
                paskaaPOSITIONS( a ) = temp( a + 1 )
            NEXT a

            rrrx = rrrx + 8
            IF rrrx > 359 THEN rrrx = rrrx - 359
            rrry = rrry + 10
            IF rrry > 359 THEN rrry = rrry - 359


            FOR a = 1 TO antal
                temp( a ) = xpos( a )
            NEXT a
            xpos( antal ) = sinus( rrrx )
            IF NoCheckerBoardTurns = 1 THEN Xpos( antal ) = 0

            FOR a = 1 TO antal - 1
                xpos( a ) = temp( a + 1 )
            NEXT a

            FOR a = 1 TO antal
                temp( a ) = ypos( a )
            NEXT a
            ypos( antal ) = sinus( rrry )
            IF NoCheckerBoardTurns = 1 THEN Ypos( antal ) = 0

            FOR a = 1 TO antal - 1
                ypos( a ) = temp( a + 1 )
            NEXT a

            FOR a = 1 TO antal
                temp( a ) = paskaacolour( a )
            NEXT a
            paskaacolour( antal ) = paskaacolour( 1 )
            FOR a = 1 TO antal - 1
                paskaacolour( a ) = temp( a + 1 )
            NEXT a

        END IF


        FOR zm = 1 TO antal
            rh = zm

            zoom = paskaaPOSITIONS( rh )

            IF zoom > highestpaskaa OR zoom < 0 THEN
                setpal 0, 63, 0, 0
                END
            END IF

            colour = paskaacolour( zm )

            cnt = ( zoompaskaa( zoom, 15 ) - zoompaskaa( zoom, 16 )) \ 2

            cnt = 0

            xa = xpos( rh )
            ya = ypos( rh )



            FOR y = 7 TO 11

                tt = - ( y MOD 2 ) + 1

                FOR x = 6 TO 11 STEP 2

                    xp1 = zoompaskaa( zoom, x + tt ) + xa
                    yp1 = zoompaskaa( zoom, y ) + ya
                    xp2 = zoompaskaa( zoom, x + 1 + tt ) + xa
                    yp2 = zoompaskaa( zoom, y + 1 ) + ya

                    sg = paskaaseg

                    clx = colour

                    x1 = xp1 + 64
                    y1 = yp1 + 48 + yshk
                    x2 = xp2 + 63 + cnt
                    y2 = yp2 + 47 + cnt + yshk

                    IF x1 > x2 THEN SWAP x1, x2
                    IF y1 > y2 THEN SWAP y1, y2

                    IF x1 = < 0 AND x2 = < 0 THEN GOTO hell
                    IF x1 > = 127 AND x2 > = 127 THEN GOTO hell

                    IF y1 = < 0 AND y2 = < 0 THEN GOTO hell
                    IF y1 > = 99 AND y2 > = 99 THEN GOTO hell


                    IF x1 < 0 THEN x1 = 0
                    IF y1 < 0 THEN y1 = 0
                    IF x2 > = 127 THEN x2 = 127
                    IF y2 > = 99 THEN y2 = 99

                    paivalaiva = y1 * 128

                    '       Filler -> BIIIIG thank you's to Skywalker of Fraction

                    IF x2 MOD 2 = 1 THEN

                        !       mov ax,paivalaiva

                        !       mov es,sg

                        !   mov bx,y2
                        !       sub bx,y1
                        'bx is Y-length
                        !   inc bx

                        !       mov di,y1
                        'di is y-start position

                        !       mov di,paivalaiva

                        !       mov cx,x2
                        !       mov dx,x1
                        !   sub cx,dx
                        'cx is the X-length
                        !   inc cx
                        !       add di,dx
                        'di is the real XY-offset

                        !   mov ax,clx
                        !   mov ah,al
                        'ax is colour (low and highbyte)

                        !       mov si,128
                        !   sub si,cx
                        'si is how much to add after each line - no more mul! =)

                        Yshit:
                        !   push cx
                        !   shr cx,1
                        !   jnc Xshit
                        !   mov es:[di],al      'if ODD offset then put ONE pixel
                        !       inc di


                        Xshit:
                        !       mov es:[di],ax
                        !       inc di
                        !       inc di
                        'two pixels forward
                        !       dec cx
                        !       jnz Xshit

                        !       pop cx


                        !       add di,si
                        'now make sure we're at the beginning of next line
                        !   dec bx
                        !       jnz Yshit
                        'if box is not fully drawn, then loop again


                    ELSE



                        !       mov es,sg

                        !   mov bx,y2
                        !       sub bx,y1           ;bx is Y-length
                        !   inc bx

                        !       mov di,y1
                        'di is y-start position

                        !       mov di,paivalaiva


                        !       mov cx,x2
                        !       mov dx,x1
                        !   sub cx,dx   ;cx is the X-length
                        !       add di,dx       ;di is the real XY-offset

                        !   mov ax,clx
                        !   mov ah,al   ;ax is colour (low and highbyte)

                        !       mov si,128
                        !   sub si,cx   ;si is how much to add after each line - no more mul! =)

                        YshitP:
                        !   push cx
                        !   shr cx,1
                        !   jnc XshitP
                        !   mov es:[di],al      'if ODD offset then put ONE pixel
                        !       inc di


                        XshitP:
                        !       mov es:[di],ax
                        !       inc di
                        !       inc di                ;two pixels forward
                        !       dec cx
                        !       jnz XshitP

                        !       pop cx


                        !       add di,si       ;now make sure we're at the beginning of next line
                        !   dec bx
                        !       jnz YshitP              ;if box is not fully drawn, then loop again



                        offs1?? = ( y1 * 128 ) + x2
                        offs2?? = ( y2 * 128 ) + x2 + 128

                        !       mov es,sg
                        !       mov bx,offs1??
                        !       mov cx,offs2??
                        !       mov ax,clx
                        FixLoop:
                        !       mov es:[bx],al
                        !       add bx,128
                        !       cmp bx,cx
                        !       jne fixloop

                    END IF


                    hell:


                NEXT x

            NEXT y


        NEXT zm


        checkmusic

        IF order < 5 AND order > 3 THEN
            IF pattpos MOD 4 < 2 THEN rc = 0 ELSE rc = 1
        ELSE
            rc = 0
        END IF

        IF sync( 5, 0 ) THEN eee = 63

        '        if sync(6,255) then xvalue=15000
        '
        '        def seg=codeseg(selfmodify1)
        '        mm=codeptr(selfmodify1)
        '        pokei mm+2,xvalue

        IF Order > = 6 AND PattPos > = 32 THEN
            yyyyy! = yyyyy! * 1.05
            IF yyyyy! > 100 THEN yyyyy! = 100
            logoYADD = INT( yyyyy! ) * 128
            IF u! > 0.25 THEN u! = u! - 0.01
            '           NoCheckerBoardTurns=1
        END IF

        'hercprint 0,0,15,str$(basevalue)

        IF CombPos > 416 AND BaseValue < 1420 THEN
            BaseValue = BaseValue + 2
        END IF

        IF order = 5 THEN

            FOR a = 16 TO 255
                r = xred2?( a )
                g = xgreen2?( a )
                b = xgreen2?( a )
                setpal a, r, g, b
            NEXT a

'            FOR a = 16 TO 255
'                r = xred2?( a ) * 2
'                g = xgreen2?( a ) * 3
'                b = xgreen2?( a ) * 2
'                l = ( r + g + b ) \ 8
'                setpal a, l, l, l
'            NEXT a

        END IF

        IF order = 6 THEN


        END IF

        if order=5 then lsls=logoseg380
        if order=6 then lsls=logoseg3802

        IF Order = 5 OR order = 6 THEN

            !   mov ax,PaskaaSeg
            '   Extended instruction: MOV GS,AX
            $INLINE &H8E,&HE8

            !   mov ax,LSLS
            '   Extended instruction: MOV FS,AX
            $INLINE &H8E,&HE0
            !   mov si,LogoPtr380
            !   add si,LogoYADD
            !   mov es,paskaaseg

            !   mov bx,0

            HummLop:

            '   Extended instruction: MOV CX,GS:[BX]
            $INLINE &H65,&H8B,&HF

            '   Extended instruction: MOV AX,FS:[SI+BX]
            $INLINE &H64,&H8B,&H0

            !   cmp al,0
            !   je fump1

            !   mov cl,al

            fump1:

            !   cmp ah,0
            !   je flump

            !   mov ch,ah

            flump:

            '   Extended instruction: MOV ES:[BX],CX
            $INLINE &H26,&H89,&HF

            !   add bx,2
            'selfmodify1:
            '   Extended instruction: CMP BX,15000
            $INLINE &H81,&HFB,&H98,&H3A
            !   jne HummLop

        END IF


        IF order = 4 THEN
            eee = 0
            IF sync( 4, 255 ) AND pattpos > 32 THEN eee = (( pattpos ) - 32 ) * 2
            '            if trig(3,15) then eee=getvolume(3)
        END IF

        IF sync( 7, 255 ) AND TorusInit = 0 THEN

            TorusInit = 1
            FillMode = 1

            OUT &H3C8, 8

            z! = 1.5

            FOR v = 0 TO 63 STEP 1
                OUT &H3C9, wrap( v * z!, 63 )
                OUT &H3C9, wrap( v * 0.25, 63 )
                OUT &H3C9, 0
            NEXT v
            FOR v = 0 TO 63 STEP 1
                OUT &H3C9, 63
                OUT &H3C9, wrap(( v + 12 ) * z!, 63 )
                OUT &H3C9, 0
            NEXT v

            FOR v = 0 TO 63 STEP 1
                OUT &H3C9, 63
                OUT &H3C9, 63
                OUT &H3C9, wrap( v * z!, 63 )
            NEXT v

            FOR v = 0 TO 52
                OUT &H3C9, 63
                OUT &H3C9, 63
                OUT &H3C9, 63
            NEXT v

        END IF



        IF TorusInit = 1 THEN

            my = my - 1
            IF my = - 1 THEN my = 0

            activepage = rot \ 5

            startoffs = ( rot MOD 5 ) * 3264

            ems.mappage activepage, 0

            myoffset = my * 128

            !   mov ax,FireSeg
            '   Extended instruction: MOV FS,AX
            $INLINE &H8E,&HE0

            !   mov ax,emmseg
            '   Extended instruction: MOV GS,AX
            $INLINE &H8E,&HE8

            !   mov dx,myoffset

            !   mov ax,emmseg
            !   mov es,ax
            '   Extended instruction: XOR BX,BX
            $INLINE &H33,&HDB
            !   mov di,startoffs
            '   Extended instruction: XOR ECX,ECX
            $INLINE &H66,&H33,&HC9

            lppp:

            '   Extended instruction: MOV CX,ES:[BX+DI]
            $INLINE &H26,&H8B,&H9
            '   Extended instruction: ADD CX,128*14
            $INLINE &H81,&HC1,&H0,&H7

            !   sub cx,dx
            !   cmp cx,0
            !   jl nopixel

            '   Extended instruction: ADD BYTE PTR FS:[ECX],5
            $INLINE &H64,&H67,&H80,&H1,&H5

            nopixel:

            '   Extended instruction: ADD BX,2
            $INLINE &H83,&HC3,&H2
            '   Extended instruction: CMP BX,3264
            $INLINE &H81,&HFB,&HC0,&HC
            !   jb lppp

            rot = rot + 1: rot = rot AND 255

            !   mov ax,&ha000
            '   Extended instruction: MOV GS,AX
            $INLINE &H8E,&HE8

            '        $if 0

            FOR y = 1 TO 92

                mulx = firemul( y )
                'muls = screenmul(y)

                'Poke32 CodePtr32(FireSelfModify1)+3,Screenmul(y)

                !   mov si,mulx
                !   mov di,25

                Fire.Xloop:

                !   xor ax,ax
                !   xor dx,dx
                !   xor cx,cx
                !   mov bx,si
                !   add bx,di
                !   dec bx

                '   Extended instruction: MOV EAX,FS:[BX]
                $INLINE &H66,&H64,&H8B,&H7

                !   mov cl,al
                !   add dx,cx
                '   Extended instruction: BSWAP EAX
                $INLINE &H66,&HF,&HC8
                !   mov cl,ah
                !   add dx,cx

                '   Extended instruction: MOV EAX,FS:[BX+128]
                $INLINE &H66,&H64,&H8B,&H87,&H80,&H0

                !   mov cl,al
                !   add dx,cx
                !   mov cl,ah
                !   add dx,cx
                '   Extended instruction: BSWAP EAX
                $INLINE &H66,&HF,&HC8
                !   mov cl,ah
                !   add dx,cx

                '   Extended instruction: MOV EAX,FS:[BX+256]
                $INLINE &H66,&H64,&H8B,&H87,&H0,&H1

                !   mov cl,al
                !   add dx,cx
                !   mov cl,ah
                !   add dx,cx
                '   Extended instruction: BSWAP EAX
                $INLINE &H66,&HF,&HC8
                !   mov cl,ah
                !   add dx,cx

                '   Extended instruction: SHR DX,3
                $INLINE &HC1,&HEA,&H3

                '   Extended instruction: MOV BYTE PTR FS:[BX+1],DL
                $INLINE &H64,&H88,&H57,&H1

                '        !   mov bx,di
                '        !   shl bx,1
                '        !   mov dh,dl
                '
                '        FireSelfModify1:
                '        '   Extended instruction: MOV GS:[BX+0F0F0H],DX
                '        $INLINE &H65,&H89,&H97,&HF0,&HF0

                !   inc di
                !   cmp di,106
                !   jb fire.xloop

            NEXT y

        END IF




        IF rc = 1 THEN

            !   mov ax,LogoSeg
            '   Extended instruction: MOV FS,AX
            $INLINE &H8E,&HE0
            !   mov si,LogoPtr
            !   mov es,paskaaseg

            !   xor bx,bx

            HummLoop:

            '   Extended instruction: MOV EAX,FS:[SI+BX]
            $INLINE &H66,&H64,&H8B,&H0

            '   Extended instruction: OR ES:[BX+128*24],EAX
            $INLINE &H66,&H26,&H9,&H87,&H0,&HC

            !   add bx,4
            !   cmp bx,8000
            !   jne HummLoop

        END IF

        mu1 = VARSEG( Burn?( 0 ))

        !   mov ax,paskaaseg
        '   Extended instruction: MOV FS,AX
        $INLINE &H8E,&HE0

        IF order = 8 THEN

            !   mov es,mu1
            !   mov bx,7000
            BurnLoop:
            '   Extended instruction: MOV EAX,ES:[BX]
            $INLINE &H66,&H26,&H8B,&H7
            '   Extended instruction: OR FS:[BX],EAX
            $INLINE &H66,&H64,&H9,&H7
            !   add bx,4
            !   cmp bx,12000
            !   jb BurnLoop

        END IF

        mvbl

        IF SceneDone = 0 THEN

            e = lf

            FOR a = 10 TO 255

                r = ( xred3?( a ) * e )
                g = ( xgreen3?( a ) * e )
                b = ( xblue3?( a ) * e )
                !   mov cl,6
                !   shr r,cl
                !   shr g,cl
                !   shr b,cl
                OUT &h3c8, a
                OUT &h3c9, r
                OUT &h3c9, g
                OUT &h3c9, b
            NEXT a

        END IF

        FOR u = 1 TO antal

            a = paskaacolour( u )

            bc = paskaaPOSITIONS( u ) \ paskaadiv

            IF rpaskaa( a ) = 1 THEN r = bc * 1 ELSE r = bc * 0.85
            IF gpaskaa( a ) = 1 THEN g = bc * 1 ELSE g = bc * 0.85
            IF bpaskaa( a ) = 1 THEN b = bc * 1 ELSE b = bc * 0.85

            IF paskaapositions( u ) > highestpaskaa - paskaadiv2 THEN r = 0: g = 0: b = 0
            IF paskaapositions( u ) < paskaadiv2 THEN r = 0: g = 0: b = 0

            uu! = u!
            IF FillMode = 1 THEN uu! = uu! * 1.7

            r = r * uu!
            g = g * uu!
            b = b * uu!

            IF r < eee THEN r = eee
            IF g < eee THEN g = eee
            IF b < eee THEN b = eee

            setpal a, r, g, b

        NEXT u

        IF rastermeter = 0 THEN setpal 0, eee, eee, eee

        '        setpal 255,63*u!,63*u!,63*u!


        IF FillMode = 0 THEN

            OUT &h3d4, 9
            OUT &h3d5, LowRes192

            !   push ds
            !   mov ax,paskaaseg
            !   mov ds,ax
            !   mov ax,&ha000
            !   mov es,ax
            !   sub bx,bx
            !   sub cx,cx
            !   sub di,di


            PaskaaAsm1:
            !   mov ax,ds:[bx]
            !   mov ds:[bx],cx
            !   mov dl,ah
            !   mov dh,dl
            '   Extended instruction: BSWAP EDX
            $INLINE &H66,&HF,&HCA
            !   mov dl,al
            !   mov dh,dl
            '   Extended instruction: MOV ES:[DI],EDX
            $INLINE &H66,&H26,&H89,&H15
            !   add di,4
            !   add bx,2
            !   cmp bx,128*98
            !   jne PaskaaAsm1

            !   pop ds

        ELSE

            OUT &h3d4, 9
            OUT &h3d5, HighRes192

            !   mov ax,paskaaseg
            '   Extended instruction: MOV FS,AX
            $INLINE &H8E,&HE0

            !   mov ax,&ha000
            '   Extended instruction: MOV GS,AX
            $INLINE &H8E,&HE8

            mh = mh + 1

            IF mh MOD 2 = 0 THEN

                FOR y = 0 TO 96

                    !   mov es,FireSeg

                    y1 = y * 128
                    y2 = y * 512

                    !   mov bx,y1
                    !   mov si,y2
                    !   xor di,di

                    HurkLoop:

                    !   mov ax,es:[bx+128]
                    FireValueSModify1:
                    '   Extended instruction: ADD AX,0808H
                    $INLINE &H5,&H8,&H8

                    '   Extended instruction: MOV CX,FS:[BX]
                    $INLINE &H64,&H8B,&HF
                    '   Extended instruction: MOV WORD PTR FS:[BX],0
                    $INLINE &H64,&HC7,&H7,&H0,&H0
                    !   mov dh,ah
                    !   mov dl,ch
                    '   Extended instruction: BSWAP EDX
                    $INLINE &H66,&HF,&HCA
                    !   mov dl,al
                    !   mov dh,cl
                    '   Extended instruction: MOV GS:[SI],EDX
                    $INLINE &H66,&H65,&H89,&H14

                    '   Extended instruction: BSWAP EDX
                    $INLINE &H66,&HF,&HCA

                    '   Extended instruction: ROL EDX,16
                    $INLINE &H66,&HC1,&HC2,&H10

                    '   Extended instruction: MOV GS:[SI+256],EDX
                    $INLINE &H66,&H65,&H89,&H94,&H0,&H1
                    !   add bx,2
                    !   add si,4
                    !   inc di
                    !   cmp di,64
                    !   jb HurkLoop

                NEXT y


            ELSE

                FOR y = 0 TO 96

                    !   mov es,FireSeg

                    y1 = y * 128
                    y2 = y * 512

                    !   mov bx,y1
                    !   mov si,y2
                    !   xor di,di

                    HurkLoop2:

                    !   mov cx,es:[bx+128]
                    FireValueSModify2:
                    '   Extended instruction: ADD CX,0808H
                    $INLINE &H81,&HC1,&H8,&H8

                    '   Extended instruction: MOV AX,FS:[BX]
                    $INLINE &H64,&H8B,&H7

                    '   Extended instruction: MOV WORD PTR FS:[BX],0
                    $INLINE &H64,&HC7,&H7,&H0,&H0
                    !   mov dh,ah
                    !   mov dl,ch
                    '   Extended instruction: BSWAP EDX
                    $INLINE &H66,&HF,&HCA
                    !   mov dl,al
                    !   mov dh,cl
                    '   Extended instruction: MOV GS:[SI],EDX
                    $INLINE &H66,&H65,&H89,&H14

                    '   Extended instruction: BSWAP EDX
                    $INLINE &H66,&HF,&HCA

                    '   Extended instruction: ROL EDX,16
                    $INLINE &H66,&HC1,&HC2,&H10

                    '   Extended instruction: MOV GS:[SI+256],EDX
                    $INLINE &H66,&H65,&H89,&H94,&H0,&H1
                    !   add bx,2
                    !   add si,4
                    !   inc di
                    !   cmp di,64
                    !   jb HurkLoop2

                NEXT y

            END IF

        END IF

    LOOP UNTIL combpos > = ( 64 * 8 ) + 47 AND order = > 8



    DEF SEG = &ha000
    OPEN "ring2.raw" FOR BINARY AS #1
    GET$ #1, 8, t$
    IF NOT t$ = "mhwanh" + CHR$( 0, 4 ) THEN errormessage "Corrupted picture"
    SEEK #1, 800
    GET$ #1, 32000, t1$
    GET$ #1, 32000, t2$

    WAIT &h3da, 8

    OUT &h3d4, 9
    OUT &h3d5, HighRes192

    SEEK #1, 32

    DIM plt?( 768 )

    FOR a = 0 TO 767
        GET #1,, p?
        plt?( a ) = p? \ 4
    NEXT a

    OUT &h3c8, 0
    FOR a = 0 TO 767
        OUT &h3c9, plt?( a )
    NEXT a

    DEF SEG = &ha000
    POKE$ 0, t1$
    POKE$ 32000, t2$

    t1$ = ""
    t2$ = ""

    CLOSE #1

    ems.ReAlloc 1

END SUB

SUB TorusLineCalc

    hercprint 0, 24, 7, "Calculating torus.. "

    '*************************** Torus line calculations **************************

    xmitt = 64: ymitt = 40

    DIM sinus( 255 ), cosinus( 255 )

    FOR i = 0 TO 255
        cosinus( i ) = 100 * COS( i / 128 * pi! )
        sinus( i ) = 100 * SIN( i / 128 * pi! )
    NEXT i

    hm3 = 4
    hm2 = hm3 * 2
    hm1 = hm2 * 2

    antalpos = hm1 * hm2

    DIM x ( antalpos ), y( antalpos ), z( antalpos )
    DIM xfin( antalpos ), yfin( antalpos )

    FOR b = 1 TO hm2

        f = ( b - 1 ) * hm1

        yy = COS( b * pi! / hm3 ) * 38
        zz = SIN( b * pi! / hm3 ) * 38

        FOR a = 1 TO hm1
            x ( a + f ) = SIN( a * pi! / hm2 ) * ( 68 + yy )
            y( a + f ) = COS( a * pi! / hm2 ) * ( 68 + yy )
            z( a + f ) = zz
        NEXT a

    NEXT b

    linjeantal = 1000

    DIM source( linjeantal ), dest( linjeantal )
    DIM koordx( linjeantal ), koordy( linjeantal )
    DIM koordx2( linjeantal ), koordy2( linjeantal )

    linjeantal = ( hm1 * hm2 ) + ( hm1 * hm2 )

    FOR b = 1 TO hm2
        add.l = ( b - 1 ) * hm1
        FOR i = 1 TO hm1
            m = i - 1
            source( i + add.l ) = m + 1 + add.l
            dest( i + add.l ) = (( m + 1 ) MOD hm1 ) + 1 + add.l
        NEXT i
    NEXT b

    flum = hm1 * hm2 + 1

    FOR b = 0 TO hm2 - 1
        bc = b * hm1
        FOR a = 0 TO hm1 - 1
            source( a + flum + bc ) = 1 + a + ((( b ) MOD hm2 ) * hm1 )
            dest( a + flum + bc ) = 1 + a + ((( b + 1 ) MOD hm2 ) * hm1 )
        NEXT a
    NEXT b

    ems.alloc 52

    t$ = repeat$( 8192, CHR$( &HFF, &H7C ))

    DEF SEG = emmseg
    FOR a = 0 TO 51
        ems.mappage a, 0
        POKE$ 0, t$
    NEXT a

    t$ = ""

    !   mov ax,emmseg
    '   Extended instruction: MOV GS,AX
    $INLINE &H8E,&HE8

    FOR rot = 0 TO 255

        IF rot MOD 16 = 0 THEN
            hercprint 20, 24, 7, STR$( rot )
            mvbl
        END IF

        activepage = rot \ 5

        startoffs = ( rot MOD 5 ) * 1632
        bo = startoffs

        ems.mappage activepage, 0

        FOR i = 1 TO antalpos
            sinrot = sinus( rot )
            cosrot = cosinus( rot )
            yx = ( z( i ) * sinrot + y( i ) * cosrot ) \ 100
            zx = ( z( i ) * cosrot - y( i ) * sinrot ) \ 100
            xy = ( x ( i ) * cosrot - zx * sinrot ) \ 100
            zy = ( x ( i ) * sinrot + zx * cosrot ) \ 100
            xz = ( yx * sinrot + xy * cosrot ) \ 100
            yz = ( yx * cosrot - xy * sinrot ) \ 100
            IF zy = 0 THEN zy = 1
            tempxz = xz
            tempyz = yz
            xfin( i ) = ( tempxz * 64 ) \ ( zy + 200 ) + xmitt
            yfin( i ) = ( tempyz * 60 ) \ ( zy + 200 ) + ymitt
        NEXT i
        FOR i = 1 TO linjeantal

            x1 = xfin( source( i ))
            y1 = yfin( source( i ))
            x2 = xfin( dest( i ))
            y2 = yfin( dest( i ))

            xx1 = x1
            xx2 = x2
            yy1 = y1
            yy2 = y2

            lincol = 15

            IF yy1 > yy2 THEN
                SWAP yy1, yy2
            END IF

            IF xx1 > xx2 THEN
                SWAP xx1, xx2
            END IF

            deltax = xx2 - xx1
            deltay = yy2 - yy1 + 1

            IF deltax < deltay THEN GOTO ritalinje2 ELSE GOTO ritalinje1

            ritalinje1:

            IF y1 > y2 THEN
                SWAP y1, y2
                SWAP x1, x2
            END IF

            diffx = x2 - x1
            diffy = y2 - y1 + 1

            BUCKET = 0

            IF diffx > 0 THEN
                AD = 1
            ELSE
                AD = - 1
            END IF
            diffx = ABS( diffx )

            lx = x1: ly = y1

            !   mov bl,lx
            !   mov bh,ly
            !   mov al,bucket
            !   mov ah,diffx
            !   mov cl,AD
            !   mov ch,lincol
            !   mov dl,y2
            !   mov dh,diffy

            loop1:

            !   add al,ah

            loop2:
            !   sub al,dh
            !   add bl,cl

            !   inc startoffs
            !   mov si,startoffs
            !   shl si,1
            !   push bx
            !   push ax

            !   mov ax,bx
            !   xor bl,bl
            !   shr bx,1
            !   add bl,al

            '   Extended instruction: MOV GS:[SI],BX
            $INLINE &H65,&H89,&H1C
            !   pop ax
            !   pop bx

            '        '   Extended instruction: ADD BYTE PTR FS:[BX],5
            '        $INLINE &H64,&H80,&H7,&H5

            !   cmp al,dh
            !   ja loop2

            !   inc bh

            !   cmp bh,dl
            !   jbe loop1

            GOTO endlinje

            ritalinje2:

            SWAP x1, y1: SWAP x2, y2

            IF y1 > y2 THEN
                SWAP y1, y2
                SWAP x1, x2
            END IF

            diffx = x2 - x1
            diffy = y2 - y1 + 1

            BUCKET = 0

            IF diffx > 0 THEN
                AD = 1
            ELSE
                AD = - 1
            END IF

            diffx = ABS( diffx )

            lx = x1: ly = y1

            lincol = 14


            DO
                BUCKET = BUCKET + diffx
                DO
                    BUCKET = BUCKET - diffy
                    lx = lx + AD
                    !   mov bl,ly
                    !   mov bh,lx
                    !   inc startoffs
                    !   mov si,startoffs
                    !   shl si,1

                    !   mov ax,bx
                    !   xor bl,bl
                    !   shr bx,1
                    !   add bl,al

                    '   Extended instruction: MOV GS:[SI],BX
                    $INLINE &H65,&H89,&H1C

                    ''   Extended instruction: ADD BYTE PTR FS:[BX],5
                    '$INLINE &H64,&H80,&H7,&H5
                    ''            '   Extended instruction: MOV GS:[BX],CL
                    ''            $INLINE &H65,&H88,&HF
                LOOP WHILE BUCKET > = diffy
                ly = ly + 1
            LOOP WHILE ly = < y2

            endlinje:

            IF startoffs > ( 1632 + bo ) THEN errormessage "Precalculation memory overflow" + STR$( startoffs - bo )


        NEXT i

    NEXT rot




    hercprint 0, 24, 7, "                                  "

END SUB

FUNCTION Wrap( i, o )
    IF i > o THEN FUNCTION = o ELSE FUNCTION = i
END FUNCTION

SUB DemoPart.TioTommaSekunder
    DEF SEG = &ha000
    OPEN "10sek.raw" FOR BINARY AS #1
    GET$ #1, 8, t$
    IF NOT t$ = "mhwanh" + CHR$( 0, 4 ) THEN errormessage "Corrupted picture"
    SEEK #1, 800
    GET$ #1, 32000, t1$
    GET$ #1, 32000, t2$
    CLOSE #1

    WAIT &h3da, 8

    OUT &h3d4, 9
    OUT &h3d5, HighRes192

    FOR a = 0 TO 255
        '    b=-a+256
        b = a
        setpal a, b \ 4, b \ 4, b \ 4
    NEXT a

    DEF SEG = &ha000

    POKE$ 0, t1$
    POKE$ 32000, t2$

    t1$ = ""
    t2$ = ""
    'StringMemPack
    MEMPACK

    CLOSE #1

    '    do
    '        mvbl
    '    loop until sync(10,16)


END SUB



SUB DemoPart.CityAnim
    'demopart.cityanim:
    filnamn$ = "city.ani"
    pingpong = 0
    IF filnamn$ = "" THEN END

    ysize = 250

    DIM lines$( ysize )
    DIM reallines$( ysize )

    OPEN "ph-bw.raw" FOR BINARY AS #1
    GET$ #1, 8, t$
    IF NOT t$ = "mhwanh" + CHR$( 0, 4 ) THEN errormessage "Corrupted picture"

    GET #1,, xsize: xsize = swapendians( xsize )
    GET #1,, ysize: ysize = swapendians( ysize )
    GET #1,, colours: colours = swapendians( colours )

    GET$ #1, 18, t$

    SEEK #1, 800

    FOR y = 0 TO ysize - 1
        GET$ #1, xsize, lines$( y )
    NEXT y
    CLOSE #1

    DispMemInfo

    DIM palett?( 768 )

    OPEN "ph-clr.raw" FOR BINARY AS #1
    GET$ #1, 8, t$
    IF NOT t$ = "mhwanh" + CHR$( 0, 4 ) THEN errormessage "Corrupted picture"

    GET #1,, xsize: xsize = swapendians( xsize )
    GET #1,, ysize: ysize = swapendians( ysize )
    GET #1,, colours: colours = swapendians( colours )

    GET$ #1, 18, t$


    REG ax, &h4f01
    REG cx, &h111
    REG es, VARSEG( vesa )
    REG di, VARPTR( vesa )
    CALL INTERRUPT( &h10 )

    hercprint 40, 20, 15, "Granularity: "+STR$( vesa.gran )

    granularity=vesa.gran

'    do
'        mvbl
'    loop until sync(12,48)

    mcls 0

    REG 1, &h3
    CALL INTERRUPT( &h10 )
    REG 1, &h12
    CALL INTERRUPT( &h10 )
    REG 1, &h0
    CALL INTERRUPT( &h10 )
    REG 1, &h13
    CALL INTERRUPT( &h10 )

    SpeedValue = 1

    VideoMode1:
' *** Testa 320*100 16-bit ***

    VideoMode = 1
    !   mov ax,&h4f02
    !   mov bx,&h10e
    !   int &h10
    !   cmp ax,&H004F
    !   je okej

    VideoMode2:
' *** Testa 640*100 16-bit ***

    VideoMode = 2
    IF speedvalue = 0 THEN videomode = 3
    !   mov ax,&h4f02
    !   mov bx,&h111
    !   int &h10
    !   cmp ax,&h004f
    !   je okej

    VideoMode4:
' *** Testa 320*200 12-bit ***


    VideoMode = 4

    !   mov ax,&h13
    !   int &h10

    okej:

    $include "tweaks\50\200.256"

    IF videomode < = 3 THEN OUT &h3d4, 9: OUT &h3d5, &h43

    OUT &H3D4, &H11: T = INP( &H3D5 ): OUT &H3D5, T AND &H7F

    OUT &h3d4, 1
    OUT &h3d5, INP( &h3d5 ) - 1

    saturation! = 1

    FOR a = 0 TO 255
        setpal a, a \ 4, a \ 4, a \ 4
    NEXT a

    FOR a = 0 TO 255
        OUT &h3c8, a
        OUT &h3c9, 0
        OUT &h3c9, 0
        OUT &h3c9, 0
    NEXT a

    '$include "tweaks\50\320200c.256"

    SEEK #1, 800

    hercprint 0, 0, 15, "*** Loading ***"

    OPEN "computer.ani" FOR BINARY AS #3

    OPEN filnamn$ FOR BINARY AS #2
    frms = LOF( 2 ) \ 6000
    pages = ( LOF( 2 ) \ 16000 ) + 1

    frms.batman = LOF( 3 ) \ 6000
    pages.batman = ( LOF( 3 ) \ 16000 ) + 1


    ems.ReAlloc pages + 64 + pages.batman

    m = 0
    n = 0
    DO
        ems.mappage n, 0
        DEF SEG = emmseg
        GET$ #2, 16000, lg$
        POKE$ 0, lg$
        n = n + 1
        DispMemInfo
    LOOP UNTIL EOF( 2 )

    BasePage.Logos = n
    n = n + 64
    BasePage.Batman = n

    DO
        ems.mappage n, 0
        DEF SEG = emmseg
        GET$ #3, 16000, lg$
        POKE$ 0, lg$
        n = n + 1
        DispMemInfo
    LOOP UNTIL EOF( 3 )

    lg$ = ""
    CLOSE #3
    CLOSE #2
    CLOSE #1



    'logos=14
    '
    'ems.alloc logos*4

    pageadd = BasePage.Logos

    logos = 16

    DIM greet.palett?( 768, logos )

    'ems.realloc logos*4

    ARGH:

    data "blank.raw"
    data "complex.raw"
    data "diffusio.raw"
    data "dps_s.raw"
    data "ld_s.raw"
    data "omicron.raw"
    data "triad_ra.raw"
    data "vallogo.raw"
    data "twist.raw"
    data "proxima.raw"
    data "@.raw"
    data "pha.raw"
    data "powerlam.raw"
    data "tbr.raw"
    data "inside.raw"
    data "neu.raw"

    RESTORE argh

    logos = 16

    FOR k = 1 TO logos
        DispMemInfo

        READ file$

        hercprint 0, 0, 15, file$

        OPEN "" + file$ FOR BINARY AS #1
        GET$ #1, 8, t$
        IF NOT t$ = "mhwanh" + CHR$( 0, 4 ) THEN errormessage "Corrupted picture"

        GET #1,, xsize: xsize = swapendians( xsize )
        GET #1,, ysize: ysize = swapendians( ysize )
        GET #1,, colours: colours = swapendians( colours )

        GET$ #1, 18, t$

        GET$ #1, 768, p$

        FOR a = 0 TO 767
            greet.palett?( a, k ) = ASC( MID$( p$, a + 1, 1 )) \ 4
        NEXT a

        SEEK #1, 800

        GET$ #1, 32000, m$

        CLOSE #1

        DEF SEG = emmseg
        km = k - 1
        mx = ( km * 4 )
        ems.mappage mx + 0 + pageadd, 0
        ems.mappage mx + 1 + pageadd, 1
        ems.mappage mx + 2 + pageadd, 2
        ems.mappage mx + 3 + pageadd, 3

        POKE$ 0, m$

        m$ = ""

        IF ( k MOD 2 ) = 0 THEN

            !   mov ax,emmseg
            !   mov es,ax
            '   Extended instruction: MOV BX,65000
            $INLINE &HBB,&HE8,&HFD
            hummfyll:
            '   Extended instruction: ADD BYTE PTR ES:[BX],100
            $INLINE &H26,&H80,&H7,&H64
            !   dec bx
            !   jnz hummfyll

        END IF

    NEXT k


    PBVDEFSEG = &ha000

    DIM multabell( 1000 )

    m! = 10
    FOR a = 0 TO 200
        multabell( a ) = m!
        m! = m! * 1.03
    NEXT a

    a1 = a
    a2 = a \ 2

    temp1 = temp2
    temp3 = temp4
    temp5 = temp6

    faerg = shit

    DIM sincurv( 200 )
    DIM sindegr( 1000 )
    DIM blaha( 5 )

    DispMemInfo

    DIM tabell?( 200, 200 )
    DIM korvside( 25600 )
    korvseg = VARSEG( korvside( 0 ))
    DIM pryttel?( 26000 )
    pryttseg = VARSEG( pryttel?( 0 ))

    OPEN "twst2.raw" FOR BINARY AS #1
    GET$ #1, 8, t$
    IF NOT t$ = "mhwanh" + CHR$( 0, 4 ) THEN errormessage "Corrupted picture"

    GET #1,, xsize: xsize = swapendians( xsize )
    GET #1,, ysize: ysize = swapendians( ysize )
    GET #1,, colours: colours = swapendians( colours )

    GET$ #1, 18, t$

    DIM twistpalett?( 768 )

    '    out &h3c8,0
    FOR a = 0 TO 767
        GET #1,, r?
        twistpalett?( a ) = r? \ 4
        '        out &h3c9,0
    NEXT a



    SEEK #1, 800

    DEF SEG = korvseg

    FOR y = 0 TO ysize - 1
        GET$ #1, xsize, t$
        POKE$ y * 256, MID$( t$, 1, 256 )
        '        poke$ y*320,t$
    NEXT y

    t$ = ""

    CLOSE #1

    '    for y = 0 to 199
    '        for x = 0 to 255
    '            def seg = emmseg
    '            temptemp=peek(y*320+x)
    '            def seg=korvseg
    '            poke y*256+x,temptemp
    '        next x
    '    next y


    DEF SEG = emmseg

    'def seg=&ha000

    count = 0
    '    mcls 0

    FOR y = 1 TO 200
        FOR x = 0 TO y
            x! = x! + 62 / y
            IF y > 0 THEN tabell?( x, y ) = x! + 192
            IF y > 15 THEN tabell?( x, y ) = x! + 128
            IF y > 30 THEN tabell?( x, y ) = x! + 64
            IF y > 45 THEN tabell?( x, y ) = x!

            ' else tabell?(x,y) = x!+64
        NEXT x
        x! = 0
    NEXT y

    FOR a = 0 TO 200
        sincurv( a ) = SIN( a * pi! / 100 ) * 50
    NEXT a

    FOR a = 0 TO 1000
        sindegr( a ) = ( SIN( a * pi! / 500 ) * 100 ) + 100
    NEXT a

    FOR a = 0 TO 25000
        pryttel?( a ) = 63
    NEXT a

    FOR ypos = 0 TO 200
        FOR y = 0 TO 200 STEP 200 / 4
            count = count + 1
            tal = y + ypos
            IF tal > 200 THEN tal = tal - 200
            xpos = sincurv( tal )
            blaha( count ) = xpos
        NEXT y
        count = 0

        blaha( 5 ) = blaha( 1 )

        FOR a = 1 TO 4

            sidlen = blaha( a + 1 ) - blaha( a )
            FOR x = blaha( a ) TO blaha( a + 1 )
                'poke 170+x+ypos*320,korvside(tabell?(x-blaha(a),sidlen)+ypos*64)
                'poke 64+x+ypos*320,tabell?(x-blaha(a),sidlen)
                pryttel?( 50 + x + ypos * 128 ) = tabell?( x - blaha( a ), sidlen )
            NEXT x

        NEXT a
    NEXT ypos

    ERASE lines$(), reallines$()

    DEF SEG = &ha000

    '    do
    '        mvbl
    '    loop until sync(13,255)

    jump 14

    c = 0
    FOR b = 1 TO 15
        FOR r = 0 TO 15
            mm = (( r + b ) * 2 ) * ( -saturation! + 1 )
            setpal c, r * 4, mm, b * 4
            c = c + 1
        NEXT r
    NEXT b

    FOR g = 0 TO 15
        mm = ( g * 4 ) * ( -saturation! + 1 )
        setpal c, mm, g * 4, mm
        '    setpal c,0,0,0
        c = c + 1
    NEXT a

    Direction = 1

    DisplayAnim frms, 0, 15, 61, Videomode, 1
    DisplayAnim frms.batman, BasePage.Batman, 17, 62, videomode, 1

'    DO
'        mvbl
'    LOOP UNTIL sync( 15, 255 )

    DEF SEG = &ha000

'    set320200

$IF 0

    SpeedValue = 1

    xVideoMode1:
' *** Testa 320*100 16-bit ***

    VideoMode = 1
    !   mov ax,&h4f02
    !   mov bx,&h10e
    !   int &h10
    !   cmp ax,&H004F
    !   je xokej

    xVideoMode2:
' *** Testa 640*100 16-bit ***

    VideoMode = 2
    IF speedvalue = 0 THEN videomode = 3
    !   mov ax,&h4f02
    !   mov bx,&h111
    !   int &h10
    !   cmp ax,&h004f
    !   je xokej

    xVideoMode4:
' *** Testa 320*200 12-bit ***


    VideoMode = 4

    !   mov ax,&h13
    !   int &h10

    xokej:

    $include "tweaks\50\200.256"

    IF videomode < = 3 THEN OUT &h3d4, 9: OUT &h3d5, &h43

    OUT &H3D4, &H11: T = INP( &H3D5 ): OUT &H3D5, T AND &H7F

    OUT &h3d4, 1
    OUT &h3d5, INP( &h3d5 ) - 1


    saturation! = 1

    FOR a = 0 TO 255
        setpal a, a \ 4, a \ 4, a \ 4
    NEXT a

    c = 0
    FOR b = 1 TO 15
        FOR r = 0 TO 15
            mm = (( r + b ) * 2 ) * ( -saturation! + 1 )
            setpal c, r * 4, mm, b * 4
            c = c + 1
        NEXT r
    NEXT b

    FOR g = 0 TO 15
        mm = ( g * 4 ) * ( -saturation! + 1 )
        setpal c, mm, g * 4, mm
        '    setpal c,0,0,0
        c = c + 1
    NEXT a

$ENDIF

    DEF SEG = &ha000

    screen13
    set320200

    sin1 = 64 * 2
    sin2 = sin1 \ 2

    v1 = sin2 + 10
    v2 = sin2 + ( sin2 \ 2 ) + 10

    light = 0

    DO

        '        if sync(1000,32) then
        '            wait &h3da,8
        '            wait &h3da,8,8
        '            setpal 0,63,0,0
        '            wait &h3da,8
        '            wait &h3da,8,8
        '            setpal 0,0,0,0
        '            v1=sin2'kadd1=kadd1+2
        '            v2=sin2+(sin2\2)
        '        end if

        IF order = 18 THEN
            light = light + 1
            IF light = 51 THEN light = 50
        END IF

        IF order = 19 AND pattpos > 46 THEN
            light = light - 1
            IF light = - 1 THEN light = 0
        END IF

        v1 = v1 + 1
        IF v1 > sin1 THEN
            v1 = v1 - sin2
            kadd1 = kadd1 + 2
            y = 0
            m$ = STRING$( 220, 0 )
            DEF SEG = &ha000
            FOR a = 0 + y TO 95 + y
                POKE$ a * 320, m$
            NEXT a
        END IF

        v2 = v2 + 1
        IF v2 > sin1 THEN
            v2 = v2 - sin2
            kadd2 = kadd2 + 2
            y = 96
            m$ = STRING$( 220, 0 )
            DEF SEG = &ha000
            FOR a = 0 + y TO 95 + y
                POKE$ a * 320, m$
            NEXT a
        END IF

        IF kadd1 > = logos THEN EXIT DO: kadd1 = 0
        IF kadd2 > = logos THEN kadd2 = 0

        hercprint 0, 15, 15, STR$( kadd1 ) + "   "
        hercprint 0, 16, 15, STR$( kadd2 - 1 ) + "   "

        '        if v2>270 then v2=v2-180

        '    setpal 0,0,0,0

        'wait &h3da,8
        'wait &h3da,8,8
        mvbl

        OUT &h3c8, 200
        FOR a = 600 TO 768
            OUT &h3c9, twistpalett?( a ) * light \ 50
        NEXT a

        'setpal 0,0,0,32


        hx = 128 - ( SIN( v1 * pi! / sin2 ) * 128 + 128 )
        IF hx < 0 THEN hx = 0

        OUT &h3c8, 100
        FOR a = 0 TO 300
            OUT &h3c9, greet.palett?( a, 2 + kadd1 ) * hx \ 128
        NEXT a

        hx = 128 - ( SIN( v2 * pi! / sin2 ) * 128 + 128 )
        IF hx < 0 THEN hx = 0

        OUT &h3c8, 1
        FOR a = 3 TO 300
            OUT &h3c9, greet.palett?( a, 1 + kadd2 ) * hx \ 128
        NEXT a


        m1.m! = multabell( SIN( v1 * pi! / sin2 ) * 100 + 150 )
        m2.m! = multabell( SIN( v2 * pi! / sin2 ) * 100 + 150 )

        m1.h = m1.m!
        m2.h = m2.m!

        !   mov ax,&ha000
        '   Extended instruction: MOV GS,AX
        $INLINE &H8E,&HE8
        !   mov ax,emmseg
        '   Extended instruction: MOV FS,AX
        $INLINE &H8E,&HE0

        FOR k = 1 TO 2

            IF k = 1 THEN xadd = m1.h: yadd = m1.h
            IF k = 2 THEN xadd = m2.h: yadd = m2.h

            IF k = 1 THEN km = (( k MOD 2 ) + kadd1 ) * 4
            IF k = 2 THEN km = (( k MOD 2 ) + kadd2 ) * 4

            ems.mappage km + 0 + pageadd, 0
            ems.mappage km + 1 + pageadd, 1
            ems.mappage km + 2 + pageadd, 2
            ems.mappage km + 3 + pageadd, 3

            yp = 0

            mm = yadd / 1.8
            xxa = ( xadd * 2 )
            xxx = ( xadd * 2 ) / 1.15
            xxxx = xadd * 4

            yy = ( k - 1 ) * 96

            FOR y = 0 TO 95
                xp = 0
                yyp = yp \ 64 - mm + 36
                IF yyp > 0 AND yyp < 95 THEN
                    ymul = ( y + yy ) * 320
                    !   mov di,xxa
                    !   mov dx,yyp
                    '   Extended instruction: BSWAP EDX
                    $INLINE &H66,&HF,&HCA
                    !   mov dx,ymul
                    !   xor si,si
                    !   xor cx,cx
                    xloopx:
                    !   add si,di
                    !   mov ax,si
                    '   Extended instruction: SHR AX,6
                    $INLINE &HC1,&HE8,&H6
                    !   sub ax,xxx
                    !   add ax,128
                    '   Extended instruction: BSWAP EDX
                    $INLINE &H66,&HF,&HCA
                    !   mov bh,dl
                    !   mov bl,al
                    '   Extended instruction: MOV AX,FS:[BX]
                    $INLINE &H64,&H8B,&H7
                    '   Extended instruction: BSWAP EDX
                    $INLINE &H66,&HF,&HCA
                    !   mov bx,dx
                    !   add bx,cx
                    '   Extended instruction: MOV GS:[BX],AX
                    $INLINE &H65,&H89,&H7
                    !   add cx,2
                    !   cmp cx,219
                    !   jb xloopx

                END IF

                yp = yp + yadd


            NEXT y

            '        if inkey$=chr$(27) then end

        NEXT k

        sinc1 = sinc1 - 1
        IF sinc1 < 0 THEN sinc1 = sinc1 + 200

        sinc3 = sinc3 + 4
        IF sinc3 > 1000 THEN sinc3 = 0

        sinc2 = sinc3

        FOR y = 0 TO 199

            sinc2 = sinc2 + 2
            IF sinc2 > 1000 THEN sinc2 = sinc2 - 1000

            sinblaha = sinc1 + sindegr( sinc2 )

            IF sinblaha > 200 THEN sinblaha = sinblaha - 200

            '   di „r sinblaha
            '   ch „r y
            '   si „r x

            pryttelseg = VARSEG( pryttel?( 0 ))
            korvseg = VARSEG( korvside( 0 ))

            !   mov ax,&ha000
            '   Extended instruction: MOV GS,AX
            $INLINE &H8E,&HE8

            !   mov ax,pryttelseg
            '   Extended instruction: MOV FS,AX
            $INLINE &H8E,&HE0

            !   mov ax,korvseg
            !   mov es,ax

            shitemp = shit

            !   sub si,si

            !   mov di,sinblaha

            !   xor bx,bx

            mx = y * 320

            '   Extended instruction: XOR ESI,ESI
            $INLINE &H66,&H33,&HF6
            '   Extended instruction: XOR EDX,EDX
            $INLINE &H66,&H33,&HD2
            '   Extended instruction: XOR EBX,EBX
            $INLINE &H66,&H33,&HDB
            '   Extended instruction: XOR EAX,EAX
            $INLINE &H66,&H33,&HC0

            !   mov dx,mx

            !   mov ch,y

            !   xor ax,ax

            xloop:

            !   mov bx,di
            '   Extended instruction: SHL BX,7
            $INLINE &HC1,&HE3,&H7

            '   Extended instruction: MOV AL,FS:[BX+SI]
            $INLINE &H64,&H8A,&H0

            !   mov bl,ch
            '   Extended instruction: SHL BX,8
            $INLINE &HC1,&HE3,&H8
            !   add bx,ax

            !   mov al,es:[bx]
            !   mov cl,al

            '   Extended instruction: MOV GS:[EDX+ESI+220],CL
            $INLINE &H65,&H67,&H88,&H8C,&H32,&HDC,&H0,&H0,&H0

            !   add si,1
            !   cmp si,100
            !   jne xloop

        NEXT y

    LOOP until order=>20

    phaen:






    ems.ReAlloc 1
END SUB
' return






SUB Set256192
    IF Vmodes( 2 ) = 1 THEN
        $include"tweaks\50\256192c1.256"
    END IF
    IF Vmodes( 2 ) = 2 THEN
        $include"tweaks\50\256192c2.256"
    END IF
    IF Vmodes( 2 ) = 3 THEN
        $include"tweaks\50\256192c3.256"
    END IF
    IF Vmodes( 2 ) = 4 THEN
        $include"tweaks\50\256192c4.256"
    END IF
    IF Vmodes( 2 ) = 5 THEN
        $include"tweaks\50\256192c5.256"
    END IF
    IF Vmodes( 2 ) = 6 THEN
        $include"tweaks\50\256192c6.256"
    END IF
    IF Vmodes( 2 ) = 7 THEN
        $include"tweaks\50\256192c7.256"
    END IF
    IF Vmodes( 2 ) = 8 THEN
        $include"tweaks\50\256192c8.256"
    END IF
    IF Vmodes( 2 ) = 9 THEN
        $include"tweaks\50\256192c.256"
    END IF

    IF Vmodes( 2 ) = 9 THEN
        LowRes192 = &H43
        HighRes192 = &H41
    ELSE
        LowRes192 = &H65
        HighRes192 = &H62
    END IF

END SUB

SUB Set320200
    $include "tweaks\50\320200c.256"
END SUB


$include "vmsltinc.bas"

SUB DemoPart.Tunnel

    screen13
    Set320200

    OUT &h43, &h36 'speed up the clock a little
    OUT &h40, 0
    OUT &h40, 100

    DIM sincirk?( 320 * 100 ), coscirk?( 320 * 100 ), ytab( 200 ), sinus( 640 ), cosinus( 640 )
    DIM si!( 320 ), co!( 320 ), bild( 32500 ), minne?( 32765 ), s ( 160 )

    DIM mellansinus( 359 )

    FOR v = 0 TO 359
        mellansinus( v ) = SIN( v * pi! / 180 ) * 8 + 8
    NEXT v

    DIM pmul( 8 )

    FOR a = 0 TO 7
        pmul( a ) = RND * 30 + 20
    NEXT a


    FOR a = 0 TO 254: setpal a, 0, 0, 0: NEXT a

    mvbl

    BLOAD "tu.raw"
    $include"tu.inc"

    paskaaseg = VARSEG( bild( 0 ))


    FOR a?? = 0 TO 63999 STEP 4
        PBVDEFSEG = &ha000
        t& = PEEKL( a?? )
        PBVDEFSEG = paskaaseg
        POKEL a??, t&
    NEXT a??

    DIM clogo$( 30 )

    DEF SEG = &ha000

    BLOAD "hatedope.raw"

    oo = 0
    FOR y = 177 TO 199
        clogo$( oo ) = PEEK$( y * 320, 34 )
        oo = oo + 1
    NEXT y

    mcls 0


    u1 = 12: u2 = 11: tr! = 10

    FOR v = 0 TO 320
        si!( v ) = SIN( v * pi! / 160 )
        co!( v ) = COS(( v + 160 ) * pi! / 160 )
    NEXT v

    FOR t = 0 TO 160
        tr! = ( tr! * 1.014 )
        oldtx = tx
        tx = tr!
        IF tx = oldtx THEN GOTO sata
        pa = pa + 1

        FOR v = 0 TO 320 STEP 2
            sinus( v ) = si!( v ) * tx
            cosinus( v ) = co!( v ) * tx
        NEXT v

        yo?? = ( t MOD 200 ) * 320

        ytab( pa ) = t * 2

        FOR v = 0 TO 320 STEP 2
            PBVDEFSEG = PaskaaSeg
            px = PEEK( yo?? + v )
            'px=bild?(yo+((v*2) mod 160))
            xp = sinus( v ) + 80 + 15
            yp = cosinus( v ) + 50 + 45
            sincirk?( pa * 320 + v ) = xp
            coscirk?( pa * 320 + v ) = yp
            PBVDEFSEG = &ha000
            'mpset xp,yp,px
        NEXT v
        sata:
    NEXT t

    FOR a = 0 TO 255
        setpal a, tur( a ), tug( a ), tub( a )
    NEXT a

    minneseg = VARSEG( minne?( 0 ))

    setpal 255, 0, 0, 0

    FOR v = 0 TO 160
        s ( v ) = SIN(( -v + 160 ) * pi! / 80 ) * 6
    NEXT v

    e! = - 3: i = 100

    mvbl

    FOR a = 0 TO 255
        setpal a, tur( a ), tug( a ), tub( a )
    NEXT a

    setpal 255, 0, 0, 0

    OUT &h3d4, 9
    OUT &h3d5, 3

    cnt = 0
    tim! = TIMER * 2

    cnt2 = 0

    '    do:mvbl:loop until sync(4,255)

    b1 = 0
    b2 = 1

    i! = 1

    xo = - 40

    setpal 1, 0, 63, 0

    FOR a = 0 TO 15
        setpal a, a * 4, a * 4, a * 4
    NEXT a

    setpal 20, 63, 63, 63

    DO
        m! = ( TIMER * 2 ) - tim!
        cnt = ( m! ) * 5 + 1

        hercprint 0, 0, 15, STR$( cnt )
        'hercprint 0,1,15,decconv$(i!,3)+"  "

        IF cnt > 160 AND cnt < 200 THEN
            j! = j! - 0.02: IF j! < - 0.8 THEN j! = - 0.8
            i! = i! - 0.05
            IF i! < 0.5 THEN i! = 0.5
        END IF

        IF cnt > 320 THEN
            i! = i! + 0.03
            IF i! > 1 THEN i! = 1
        END IF

        IF cnt > 320 AND cnt < 380 THEN
            j! = j! + 0.01: IF j! > 0 THEN j! = 0
        END IF

        i = - (( m! * 30 ) MOD 200 )
        IF i < 0 THEN i = i + 200

        i2 = ( m! * 19 ) MOD 320

        i2 = 0

        IF cnt > 0 AND cnt < 160 THEN
            e! = e! * 0.99
            e! = e! + 0.01
            IF e! = > 0 THEN e! = 0
        END IF


        IF cnt > 380 AND cnt < 460 THEN
            e! = e! / 0.98
            e! = e! - 0.01
            IF e! = > 1 THEN e! = 1
        END IF

        DEF SEG = &ha000

        rb = m! * 31 MOD 160
        rb2 = m! * 23 MOD 160

        rx = rb
        rx2 = rb2

        ym! = 52

        IF cnt > 480 THEN p = p + 1

        iii = i! * 100
        eee = e! * 100
        jjj = j! * 100

        FOR t = p TO 85

            PBVDEFSEG = CODESEG( notneeded )
            IF t > 30 THEN pq = 2 ELSE pq = 4
            POKE CODEPTR( notneeded ) + 2, pq

            rx = rx + 3
            IF rx > 160 THEN rx = rx - 160
            rx2 = rx2 + 2
            IF rx2 > 160 THEN rx2 = rx2 - 160
            yyy = ( s ( rx ) * iii ) \ 100
            xxx = ( s ( rx2 ) * iii ) \ 100
            yo?? = (( ytab( t ) + i ) MOD 199 ) * 320 + i2

            IF cnt > 0 AND cnt < 160 THEN
                rrx = ( t * eee ) \ 100
                rry = ( t * eee ) \ 100
            END IF

            IF cnt > 380 AND cnt < 540 THEN
                rrx = ( t * eee ) \ 100
                rry = ( t * eee ) \ 100
            END IF

            IF cnt > 160 AND cnt < 380 THEN
                rrx = 0
                ym! = ym! * 0.93
                rry = ( ym! * jjj ) \ 100
            END IF

            paskaa1 = - 15 + rrx + xxx
            paskaa2 = - 45 + rry + yyy

            paskaaseg1 = VARSEG( sincirk?( 0 )) 'FS
            paskaaseg2 = VARSEG( coscirk?( 0 )) 'GS

            paskaamul = t * 320

            paskapictureseg = VARSEG( bild( 0 ))


            'Main X-loop starts here!

            !   push ds

            !   mov ax,paskapictureseg
            !   mov ds,ax

            !   mov ax,paskaaseg1
            '   Extended instruction: MOV FS,AX
            $INLINE &H8E,&HE0

            !   mov ax,paskaaseg2
            '   Extended instruction: MOV GS,AX
            $INLINE &H8E,&HE8

            !   mov es,minneseg

            !   xor si,si

            PaskaaLoopb:

            !   mov ax,paskaamul
            !   mov bx,ax
            !   add bx,si
            !   db &H64
            !   mov di,[bx]
            !   add di,paskaa1


            !   cmp di,0
            !   jl NotNeeded
            !   cmp di,159
            !   jg NotNeeded

            !   mov ax,paskaamul
            !   mov bx,ax
            !   add bx,si
            !   db &H65
            !   mov cx,[bx]
            !   add cx,paskaa2

            !   cmp cx,0
            !   jl NotNeeded
            !   cmp cx,98
            !   jg NotNeeded

            !   mov bx,si
            !   add bx,bx
            !   add bx,yo??
            !   mov dx,ds:[bx]

            !   mov bx,cx

            '   Extended instruction: SHL BX,7
            $INLINE &HC1,&HE3,&H7

            '   Extended instruction: SHL CX,5
            $INLINE &HC1,&HE1,&H5

            !   add bx,cx
            !   add bx,di

            !   mov cx,dx

            '   Extended instruction: SHL EDX,16
            $INLINE &H66,&HC1,&HE2,&H10

            !   add dx,cx

            '   Extended instruction: MOV ES:[BX],EDX
            $INLINE &H66,&H26,&H89,&H17
            '   Extended instruction: MOV ES:[BX+160],EDX
            $INLINE &H66,&H26,&H89,&H97,&HA0,&H0
            '   Extended instruction: MOV ES:[BX+320],EDX
            $INLINE &H66,&H26,&H89,&H97,&H40,&H1
            '   Extended instruction: MOV ES:[BX+480],EDX
            $INLINE &H66,&H26,&H89,&H97,&HE0,&H1

            notneeded:
            '   Extended instruction: ADD SI,2
            $INLINE &H83,&HC6,&H2

            !   cmp si,320
            !   jb PaskaaLoopb

            !   pop ds

        NEXT t

        IF cnt > 160 AND cnt < 380 THEN uf = 2 ELSE uf = 1

        DEF SEG = minneseg

        IF cnt > 100 AND cccc = 0 THEN
            cccc = 1
            timi! = m!
        END IF

        IF cnt > 100 AND xo < 7 THEN
            xo = ( m! - timi! ) * 10 - 30
        END IF

        IF cnt > 350 AND cccc = 1 THEN
            cccc = 2
            timi! = m!
        END IF

        IF cnt > 350 AND xo > - 40 THEN
            xo = ( timi! - m! ) * 10 + 2
        END IF

        IF NOT cccc = 0 THEN

            yl = 7

            IF xo < 0 THEN
                FOR y = 0 TO 22
                    POKE$(( y + yl ) * 160 ), MID$( clogo$( y ), - xo + 1, 60 )
                NEXT y
            END IF

            IF xo > - 1 THEN
                FOR y = 0 TO 22
                    POKE$(( y + yl ) * 160 ) + xo, clogo$( y )
                NEXT y
            END IF

        END IF


        'out &h3c0,&h31
        'out &h3c0,254

        setpal 0, 0, 0, 0

        'if inkey$=chr$(27) then end

        mvbl

        '        setpal 0,63,0,0




        '       if cnt>420 then
        '
        '           u!=(-(cnt-420)+25)*0.04
        '           hercprint 0,2,15,decconv$(u!,3)
        '
        '           if u!<0 then exit sub
        '
        '           for a=0 to 255
        '               setpal a,tur(a)*u!,tug(a)*u!,tub(a)*u!
        '           next a
        '
        '       end if


        IF cnt > 240 THEN

            IF hurkel = 0 THEN
                bt! = m!
                hurkel = 1
            END IF

            rt! = m! - bt!

            ggy = - ( rt! * 12 ) + 100

            IF ggy < 0 THEN EXIT SUB

            pppp! = ggy / 100

            FOR ggx = 0 TO 7
                jaja = mellansinus(( rt! * pmul( ggx )) MOD 359 ) * pppp!
                ggxx = ggx * 20 + jaja
                filler ggxx, ggy, ggxx + 20, ggy + 99, 20, minneseg
            NEXT x

        END IF















        'Output the buffer to the screen!

        !   mov es,minneseg

        '   Extended instruction: XOR EAX,EAX
        $INLINE &H66,&H33,&HC0

        !   mov si,16000
        LPaskaa1:
        !   sub si,160

        '   Extended instruction: MOV ES:[SI],EAX
        $INLINE &H66,&H26,&H89,&H4
        '   Extended instruction: MOV ES:[SI+156],EAX
        $INLINE &H66,&H26,&H89,&H84,&H9C,&H0
        !   jnz Lpaskaa1

        !   push ds
        !   mov ds,minneseg
        !   mov ax,&ha000
        !   mov es,ax
        !   mov si,160
        !   mov di,320
        !   xor cx,cx

        PaskaaDumpLoop:
        !   mov ax,ds:[si]
        !   mov dx,ax
        !   mov al,ah
        !   mov dh,dl
        '   Extended instruction: ROL EAX,16
        $INLINE &H66,&HC1,&HC0,&H10
        !   mov ax,dx
        '   Extended instruction: MOV ES:[DI],EAX
        $INLINE &H66,&H26,&H89,&H5
        !   mov ds:[si],cx
        !   add di,4
        !   add si,2
        !   cmp si,16000
        !   jne PaskaaDumpLoop

        !   pop ds

    LOOP UNTIL cnt > 540

END SUB





$segment


SUB filler( xp1, yp1, xp2, yp2, clr, segment )
    sg = segment

    clx = clr

    'x1=xp1+80
    'y1=yp1+50+yshk
    'x2=xp2+79+cnt
    'y2=yp2+49+cnt+yshk

    x1 = xp1
    y1 = yp1
    x2 = xp2
    y2 = yp2

    IF x1 > x2 THEN SWAP x1, x2
    IF y1 > y2 THEN SWAP y1, y2

    IF x1 = < 0 AND x2 = < 0 THEN GOTO bhell
    IF x1 > = 159 AND x2 > = 159 THEN GOTO bhell

    IF y1 = < 0 AND y2 = < 0 THEN GOTO bhell
    IF y1 > = 99 AND y2 > = 99 THEN GOTO bhell


    IF x1 < 0 THEN x1 = 0
    IF y1 < 0 THEN y1 = 0
    IF x2 > = 159 THEN x2 = 159
    IF y2 > = 99 THEN y2 = 99


    ''hercprint 0,0,15,str$(x1)
    ''hercprint 0,1,15,str$(x2)
    ''hercprint 0,2,15,str$(y1)
    ''hercprint 0,3,15,str$(y2)
    '
    ''if x1=x2 or y1=y2 then exit sub
    '

    'y=0
    paivalaiva = y1 * 160


    '       Filler -> BIIIIG thank you's to Skywalker of Fraction

    '!      mov ax,&ha000

    IF x2 MOD 2 = 1 THEN

        !       mov ax,paivalaiva

        !       mov es,sg

        !   mov bx,y2
        !       sub bx,y1       ;bx is Y-length
        !   inc bx

        !       mov di,y1       ;di is y-start position

        '!   mov ax,di
        '!   mov cl,8
        '!      shl di,cl       ;di=di*256
        '!      mov cl,6
        '!      shl ax,cl       'ax=ax*64   ax is y*320   160!
        ''!     add di,ax       'di is the real Y-offset

        !       mov di,paivalaiva

        !       mov cx,x2
        !       mov dx,x1
        !   sub cx,dx   ;cx is the X-length
        !   inc cx
        !       add di,dx       ;di is the real XY-offset

        !   mov ax,clx
        !   mov ah,al   ;ax is colour (low and highbyte)

        !       mov si,160
        !   sub si,cx   ;si is how much to add after each line - no more mul! =)

        bYshit:
        !   push cx
        !   shr cx,1
        !   jnc bXshit
        !   mov es:[di],al      ;if ODD offset then put ONE pixel
        !       inc di


        bXshit:
        !       mov es:[di],ax
        !       inc di
        !       inc di                  ;two pixels forward
        !       dec cx
        !       jnz bXshit

        !       pop cx


        !       add di,si       ;now make sure we're at the beginning of next line
        !   dec bx
        !       jnz bYshit               ;if box is not fully drawn, then loop again











    ELSE



        !       mov es,sg

        !   mov bx,y2
        !       sub bx,y1       ;bx is Y-length
        !   inc bx

        !       mov di,y1       ;di is y-start position

        '!   mov ax,di
        '!   mov cl,8
        '!      shl di,cl
        '!      mov cl,6
        '!      shl ax,cl       ;ax is y*320       160!
        ''      mov ax,paivalaiva
        '
        '!      add di,ax       ;di is the real Y-offset

        !       mov di,paivalaiva


        !       mov cx,x2
        !       mov dx,x1
        !   sub cx,dx   ;cx is the X-length
        '!   inc cx
        !       add di,dx       ;di is the real XY-offset

        !   mov ax,clx
        !   mov ah,al   ;ax is colour (low and highbyte)

        !   mov si,160
        !   sub si,cx   ;si is how much to add after each line - no more mul! =)

        bYshitP:
        !   push cx
        !   shr cx,1
        !   jnc bXshitP
        !   mov es:[di],al      ;if ODD offset then put ONE pixel
        !       inc di


        bXshitP:
        !       mov es:[di],ax
        !       inc di
        !       inc di                  ;two pixels forward
        !       dec cx
        !       jnz bXshitP

        !       pop cx


        !       add di,si       ;now make sure we're at the beginning of next line
        !   dec bx
        !       jnz bYshitP              ;if box is not fully drawn, then loop again






        'setpal 0,63,63,0

        offs1?? = ( y1 * 160 ) + x2
        offs2?? = ( y2 * 160 ) + x2 + 160

        !       mov es,sg
        !       mov bx,offs1??
        !       mov cx,offs2??
        !       mov ax,clx
        bFixLoop:
        !       mov es:[bx],al
        !       add bx,160
        !       cmp bx,cx
        !       jne bfixloop

        'for a??=offs1?? to offs2?? step 320
        'poke a??,1
        'next a??


    END IF


    bhell:

END SUB










SUB DisplayAnim( frms, basepage, quitorder, quitpattpos, vm, pingpong )

    flmp=64 \ granularity

    videomode = vm

    DIM ftabell?( 2000 )
    DIM red?( 16384 )
    DIM green?( 16384 )
    DIM blue?( 16384 )

    Direction = 1

    mm?? = 47179

    OUT &h43, &h36
    OUT &h40, mm?? MOD 256
    OUT &h40, mm?? \ 256

    frames = frms

    DefTimer! = TIMER

    r = (( TIMER - DefTimer! ) * 18.206 ) MOD frames



    ppb = &h28

    hg = - 1
    r = 0
    DO

        x = ( r MOD 8 ) * 7

        DEF SEG = &hb000

        IF PingPong = 0 THEN

            r = (( TIMER - DefTimer! ) * 18.206 ) MOD ( frames - 1 )

        ELSE

            r = (( TIMER - DefTimer! ) * 18.206 ) MOD (( frames - 1 ) * 2 )
            IF r > frames - 1 THEN r = - r + (( frames - 1 ) * 2 )

        END IF

        hercprint 0, 0, 15, STR$( r ) + "    "


        rx = (( TIMER - DefTimer! ) * 18.206 )

        hg = hg + 1
        hercprint 0, 23, 15, STR$( rx ) + "     "
        hercprint 0, 24, 15, STR$( hg ) + "     "

        IF hg < rx THEN hercprint 0, 20, 15, "timer too fast"
        IF hg = rx THEN hercprint 0, 20, 15, "timer perfect "
        IF hg > rx THEN hercprint 0, 20, 15, "timer too slow"

        FOR g = 1 TO 3

            DEF SEG = CODESEG( selfmodify )
            mx = CODEPTR( selfmodify )

            IF videomode = 4 THEN
                POKE mx + 2, 0
                POKE mx + 5, 0
            ELSE
                IF g = 1 OR g = 3 THEN
                    POKE mx + 2, 1
                    POKE mx + 5, 1
                ELSE
                    POKE mx + 2, 2
                    POKE mx + 5, 2
                END IF

            END IF

            a = ( r * 3 ) + ( g - 1 )
            ac = a \ 8

            ems.mappage ac + basepage, 0
            DEF SEG = emmseg
            t$ = PEEK$(( a MOD 8 ) * 2000, 2000 )
            DEF SEG = VARSEG( ftabell?( 0 ))
            POKE$ 0, t$

            IF g = 1 THEN tempseg = VARSEG( red?( 0 ))
            IF g = 2 THEN tempseg = VARSEG( green?( 0 ))
            IF g = 3 THEN tempseg = VARSEG( blue?( 0 ))

            DEF SEG = tempseg


            IF rm = 1 THEN setpal 0, 0, 0, 31

            x = 0
            y = 0
        'jag hatar assembler

            fs = VARSEG( ftabell?( 0 ))


            !   mov es,fs

            !   mov ax,tempseg

        '   Extended instruction: MOV GS,AX
            $INLINE &H8E,&HE8


            !   sub di,di   ;di „r r„kneverk
            !   sub si,si   ;si „r r„kneverk
            !   sub cx,cx   ;ch „r buffer
            !   sub dx,dx   ;dx „r buffer
            !   sub ax,ax   ;ax „r buffer
            !   sub bx,bx   ;bx „r offset

            satapeittaa:


            !   mov ax,es:[di]

            !   mov dl,al
            !   mov dh,dl

            !   mov al,ah

            !   and dl,15
            !   and al,15


        '   Extended instruction: SHR DH,4
            $INLINE &HC0,&HEE,&H4

        '   dl och dh „r nu f„rdiga pixlar

        '   al „r ocks† en pixel (hoppas jag)

            SELFMODIFY:
        '   Extended instruction: SHL DX,&HFF 'SELF MODIFYING CODE!!!
            $INLINE &HC1,&HE2,&H2
        '   Extended instruction: SHL AL,&HFF 'SELF MODIFYING CODE!!!
            $INLINE &HC0,&HE0,&H2


            !   mov cl,dh
            !   add cl,dl
            !   shr cl,1

            !   mov ch,dh
            !   add ch,al
            !   shr ch,1

            !   mov ah,dh
            !   mov al,ch

        '   Extended instruction: BSWAP EAX
            $INLINE &H66,&HF,&HC8

            !   mov al,dl
            !   mov ah,cl

        '   Extended instruction: MOV GS:[BX],EAX
            $INLINE &H66,&H65,&H89,&H7

            !   add bx,4


            !   add si,4
            !   cmp si,160

            !   jne nej.inte.radbrytning.ennu
            !   sub si,si
            !   add bx,160
            nej.inte.radbrytning.ennu:

            !   inc di

            !   cmp di,1960

            !   jne satapeittaa

            IF rm = 1 THEN setpal 0, 0, 31, 31






            !   mov es,tempseg

            !   sub bx,bx   ;bx „r offset

            paskaaloop:

        '   Extended instruction: MOV EAX,ES:[BX]
            $INLINE &H66,&H26,&H8B,&H7

        '   Extended instruction: MOV EDX,ES:[BX+320]
            $INLINE &H66,&H26,&H8B,&H97,&H40,&H1

        '   Extended instruction: MOV ECX,EAX
            $INLINE &H66,&H8B,&HC8

        '   Extended instruction: ADD ECX,EDX
            $INLINE &H66,&H3,&HCA

        '   Extended instruction: SHR ECX,1
            $INLINE &H66,&HD1,&HE9

        ''   Extended instruction: AND ECX,0F0F0F0FH
        '$INLINE &H66,&H81,&HE1,&HF,&HF,&HF,&HF

        '   Extended instruction: AND ECX,3F3F3F3FH
            $INLINE &H66,&H81,&HE1,&H3F,&H3F,&H3F,&H3F

        '   Extended instruction: MOV ES:[BX+160],ECX
            $INLINE &H66,&H26,&H89,&H8F,&HA0,&H0


            !   add bx,4

            !   inc si
            !   cmp si,40
            !   jne paskaa

            !   xor si,si
            !   add bx,160

            paskaa:

            !   cmp bx,16000

            !   jne paskaaloop

            IF rm = 1 THEN setpal 0, 0, 0, 0

            IF rm = 1 THEN setpal 0, 31, 0, 0

            tv = ( by MOD 2 ) * 0

        NEXT g

        setpal 0, 0, 0, 0

        IF notSVGA = 1 THEN OUT &h3d4, 12 + 1: OUT &h3d5, 80
'        WAIT &h3da, 8

        justwait = 1
        mvbl
        justwait = 0

'    ma=rnd*20
'    if ma=2 then ma=0

        shit = INP( &h3da )
'    out &h3c0,&h33
'    out &h3c0,ma

        IF notSVGA = 1 THEN OUT &h3d4, 12 + 1: OUT &h3d5, 0
        IF notsvga = 1 THEN
'            WAIT &h3da, 8, 8
'            WAIT &h3da, 8
            mvbl
        END IF


        redseg = VARSEG( red?( 0 ))
        greenseg = VARSEG( green?( 0 ))
        blueseg = VARSEG( blue?( 0 ))







        SELECT CASE videomode

            CASE 1 '320*100


                !   mov ax,redseg       ;es
                !   mov bx,greenseg     ;fs
                !   mov cx,blueseg      ;gs
                !   mov dx,&ha000       ;ds

                !   push ds
                !   mov ds,dx
                !   mov es,ax
        '   Extended instruction: MOV FS,BX
                $INLINE &H8E,&HE3
        '   Extended instruction: MOV GS,CX
                $INLINE &H8E,&HE9

                !   xor bx,bx
                !   xor si,si


                psk:

                !   xor ax,ax

        '   Extended instruction: MOV AL,GS:[BX]
                $INLINE &H65,&H8A,&H7

                !   mov dx,ax

                !   xor ax,ax

        '   Extended instruction: MOV AL,FS:[BX]
                $INLINE &H64,&H8A,&H7

        '   Extended instruction: SHL AX,5
                $INLINE &HC1,&HE0,&H5

                !   add dx,ax

                !   xor ax,ax

        '   Extended instruction: MOV AL,ES:[BX]
                $INLINE &H26,&H8A,&H7

                !   and al,&HFE

        '   Extended instruction: SHL AX,11
                $INLINE &HC1,&HE0,&HB

                !   add dx,ax

                !   mov ax,dx
        '   Extended instruction: ROL EAX,16
                $INLINE &H66,&HC1,&HC0,&H10
                !   mov ax,dx

        '   Extended instruction: MOV DS:[SI],EAX
                $INLINE &H66,&H89,&H4

                !   add si,4
                !   inc bx
                !   cmp bx,16000
                !   jne psk


                !   pop ds




            CASE 2 '640*100

                !   mov ax,&h4f05
                !   mov bh,0
                !   mov dx,0
                !   int &h10

                !   mov ax,redseg       ;es
                !   mov bx,greenseg     ;fs
                !   mov cx,blueseg      ;gs
                !   mov dx,&ha000       ;ds

                !   mov si,0

                !   push ds
                !   mov ds,dx
                !   mov es,ax
        '   Extended instruction: MOV FS,BX
                $INLINE &H8E,&HE3
        '   Extended instruction: MOV GS,CX
                $INLINE &H8E,&HE9

                !   xor bx,bx

                pskv:

                !   xor ax,ax

        '   Extended instruction: MOV AL,GS:[BX]
                $INLINE &H65,&H8A,&H7

                !   mov dx,ax

                !   xor ax,ax

        '   Extended instruction: MOV AL,FS:[BX]
                $INLINE &H64,&H8A,&H7

        '   Extended instruction: SHL AX,5
                $INLINE &HC1,&HE0,&H5

                !   add dx,ax

                !   xor ax,ax

        '   Extended instruction: MOV AL,ES:[BX]
                $INLINE &H26,&H8A,&H7

                !   and al,&HFE

        '   Extended instruction: SHL AX,11
                $INLINE &HC1,&HE0,&HB

                !   add dx,ax

                !   mov ax,dx
        '   Extended instruction: ROL EAX,16
                $INLINE &H66,&HC1,&HC0,&H10
                !   mov ax,dx

                $INLINE &H66,&H89,&H4 ' 222C XI V2:                             MOV DS:[SI],EAX
                $INLINE &H66,&H89,&H44,&H4 ' 2943 XI V2:                      MOV DS:[SI+4],EAX

                !   add si,8
                !   inc bx
                !   cmp bx,8192
                !   jb pskv

                !   pop ds

                !   mov ax,&h4f05
                !   mov bh,0
                !   mov dx,flmp
                !   int &h10



                !   mov ax,redseg       ;es
                !   mov bx,greenseg     ;fs
                !   mov cx,blueseg      ;gs
                !   mov dx,&ha000       ;ds

                !   mov si,0

                !   push ds
                !   mov ds,dx
                !   mov es,ax
        '   Extended instruction: MOV FS,BX
                $INLINE &H8E,&HE3
        '   Extended instruction: MOV GS,CX
                $INLINE &H8E,&HE9

                !   mov bx,8192

                pskii:

                !   xor ax,ax

        '   Extended instruction: MOV AL,GS:[BX]
                $INLINE &H65,&H8A,&H7

                !   mov dx,ax

                !   xor ax,ax

        '   Extended instruction: MOV AL,FS:[BX]
                $INLINE &H64,&H8A,&H7

        '   Extended instruction: SHL AX,5
                $INLINE &HC1,&HE0,&H5

                !   add dx,ax

                !   xor ax,ax

        '   Extended instruction: MOV AL,ES:[BX]
                $INLINE &H26,&H8A,&H7

                !   and al,&HFE

        '   Extended instruction: SHL AX,11
                $INLINE &HC1,&HE0,&HB

                !   add dx,ax

                !   mov ax,dx
        '   Extended instruction: ROL EAX,16
                $INLINE &H66,&HC1,&HC0,&H10
                !   mov ax,dx

                $INLINE &H66,&H89,&H4 ' 222C XI V2:                             MOV DS:[SI],EAX
                $INLINE &H66,&H89,&H44,&H4 ' 2943 XI V2:              MOV DS:[SI+4],EAX

                !   add si,8
                !   inc bx
                !   cmp bx,15520
                !   jb pskii


                !   pop ds








            CASE 3 '640*100 x-interlaced

                hrk = hrk + 1
                IF hrk = 2 THEN hrk = 0
                xxxx = hrk * 4


                !   mov ax,&h4f05
                !   mov bh,0
                !   mov dx,0
                !   int &h10





                !   mov ax,redseg       ;es
                !   mov bx,greenseg     ;fs
                !   mov cx,blueseg      ;gs
                !   mov dx,&ha000       ;ds

                !   mov si,xxxx

                !   push ds
                !   mov ds,dx
                !   mov es,ax
        '   Extended instruction: MOV FS,BX
                $INLINE &H8E,&HE3
        '   Extended instruction: MOV GS,CX
                $INLINE &H8E,&HE9

                !   xor bx,bx

                pskiii:

                !   xor ax,ax

        '   Extended instruction: MOV AL,GS:[BX]
                $INLINE &H65,&H8A,&H7

                !   mov dx,ax

                !   xor ax,ax

        '   Extended instruction: MOV AL,FS:[BX]
                $INLINE &H64,&H8A,&H7

        '   Extended instruction: SHL AX,5
                $INLINE &HC1,&HE0,&H5

                !   add dx,ax

                !   xor ax,ax

        '   Extended instruction: MOV AL,ES:[BX]
                $INLINE &H26,&H8A,&H7

                !   and al,&HFE

        '   Extended instruction: SHL AX,11
                $INLINE &HC1,&HE0,&HB

                !   add dx,ax

                !   mov ax,dx
        '   Extended instruction: ROL EAX,16
                $INLINE &H66,&HC1,&HC0,&H10
                !   mov ax,dx

                $INLINE &H66,&H89,&H4 ' 222C XI V2:                             MOV DS:[SI],EAX

                !   add si,8
                !   inc bx
                !   cmp bx,8192
                !   jb pskiii


                !   pop ds


                !   mov ax,&h4f05
                !   mov bh,0
                !   mov dx,flmp
                !   int &h10


                !   mov ax,redseg       ;es
                !   mov bx,greenseg     ;fs
                !   mov cx,blueseg      ;gs
                !   mov dx,&ha000       ;ds

                !   mov si,xxxx

                !   push ds
                !   mov ds,dx
                !   mov es,ax
        '   Extended instruction: MOV FS,BX
                $INLINE &H8E,&HE3
        '   Extended instruction: MOV GS,CX
                $INLINE &H8E,&HE9

                !   mov bx,8192

                pskiv:

                !   xor ax,ax

        '   Extended instruction: MOV AL,GS:[BX]
                $INLINE &H65,&H8A,&H7

                !   mov dx,ax

                !   xor ax,ax

        '   Extended instruction: MOV AL,FS:[BX]
                $INLINE &H64,&H8A,&H7

        '   Extended instruction: SHL AX,5
                $INLINE &HC1,&HE0,&H5

                !   add dx,ax

                !   xor ax,ax

        '   Extended instruction: MOV AL,ES:[BX]
                $INLINE &H26,&H8A,&H7

                !   and al,&HFE

        '   Extended instruction: SHL AX,11
                $INLINE &HC1,&HE0,&HB

                !   add dx,ax

                !   mov ax,dx
        '   Extended instruction: ROL EAX,16
                $INLINE &H66,&HC1,&HC0,&H10
                !   mov ax,dx

                $INLINE &H66,&H89,&H4 ' 222C XI V2:                             MOV DS:[SI],EAX

                !   add si,8
                !   inc bx
                !   cmp bx,15520
                !   jb pskiv


                !   pop ds





            CASE 4 '320*200 fakemode



                !   mov ax,redseg       ;es
                !   mov bx,greenseg     ;fs
                !   mov cx,blueseg      ;gs
                !   mov dx,&ha000       ;ds

                !   push ds
                !   mov ds,dx
                !   mov es,ax
        '   Extended instruction: MOV FS,BX
                $INLINE &H8E,&HE3
        '   Extended instruction: MOV GS,CX
                $INLINE &H8E,&HE9

        '   Extended instruction: XOR EAX,EAX
                $INLINE &H66,&H33,&HC0
        '   Extended instruction: XOR ECX,ECX
                $INLINE &H66,&H33,&HC9
                !   xor bx,bx
                !   xor si,si
                !   xor di,di

        '   Extended instruction: XOR EDX,EDX
                $INLINE &H66,&H33,&HD2

                moiloop1:

                !   mov ax,es:[bx]

        '   Extended instruction: XOR ECX,ECX
                $INLINE &H66,&H33,&HC9

                !   mov cl,al

        '   Extended instruction: MOV EDX,ECX
                $INLINE &H66,&H8B,&HD1

        '   Extended instruction: XOR ECX,ECX
                $INLINE &H66,&H33,&HC9

                !   mov cl,ah
        '   Extended instruction: SHL ECX,16
                $INLINE &H66,&HC1,&HE1,&H10

        '   Extended instruction: ADD EDX,ECX
                $INLINE &H66,&H3,&HD1








        '   Extended instruction: XOR ECX,ECX
                $INLINE &H66,&H33,&HC9

        '   Extended instruction: MOV AX,GS:[BX]
                $INLINE &H65,&H8B,&H7

                !   mov cl,al
        '   Extended instruction: SHL CL,4
                $INLINE &HC0,&HE1,&H4

        '   Extended instruction: ADD EDX,ECX
                $INLINE &H66,&H3,&HD1

                !   mov cl,ah
        '   Extended instruction: SHL ECX,20
                $INLINE &H66,&HC1,&HE1,&H14

        '   Extended instruction: ADD EDX,ECX
                $INLINE &H66,&H3,&HD1



        '   Extended instruction: XOR ECX,ECX
                $INLINE &H66,&H33,&HC9

        '   Extended instruction: MOV AX,FS:[BX]
                $INLINE &H64,&H8B,&H7

                !   mov cl,al
                !   add cl,240

        '   Extended instruction: SHL CX,8
                $INLINE &HC1,&HE1,&H8

        '   Extended instruction: ADD EDX,ECX
                $INLINE &H66,&H3,&HD1

                !   mov cl,ah

        '   Extended instruction: ADD CL,240
                $INLINE &H80,&HC1,&HF0

        '   Extended instruction: SHL ECX,24
                $INLINE &H66,&HC1,&HE1,&H18

        '   Extended instruction: ADD EDX,ECX
                $INLINE &H66,&H3,&HD1


        '   Extended instruction: MOV DS:[SI],EDX
                $INLINE &H66,&H89,&H14

        '   Extended instruction: BSWAP EDX
                $INLINE &H66,&HF,&HCA

        '   Extended instruction: ROL EDX,16
                $INLINE &H66,&HC1,&HC2,&H10

        '   Extended instruction: MOV DS:[SI+320],EDX
                $INLINE &H66,&H89,&H94,&H40,&H1

                !   add bx,2

                !   add si,4

                !   inc di
                !   cmp di,80
                !   jne p1
                !   xor di,di
                !   add si,320


                p1:


                !   cmp bx,16000
                !   jne moiloop1




                !   pop ds










        END SELECT





    LOOP UNTIL( order = quitorder AND pattpos > quitpattpos )

    OUT &h43, &h36
    OUT &h40, 255
    OUT &h40, 255




END SUB


SUB Picture.Goato10

    OPEN "goato10.raw" FOR BINARY AS #1
    GET$ #1, 8, t$
    IF NOT t$ = "mhwanh" + CHR$( 0, 4 ) THEN errormessage "Corrupted picture"

    GET #1,, xsize: xsize = swapendians( xsize )
    GET #1,, ysize: ysize = swapendians( ysize )
    GET #1,, colours: colours = swapendians( colours )

    GET$ #1, 18, t$

    DIM plt?( 768 )

    FOR a = 0 TO 767
        GET #1,, p?
        plt?( a ) = p? \ 4
    NEXT a

    FOR a = 0 TO 255
        setpal a, 63, 63, 63
    NEXT a

    mcls 0

    set320200

    DEF SEG = &ha000

    SEEK #1, 800

    FOR y = 0 TO ysize - 1
        GET$ #1, xsize, t$
        POKE$ y * 320, t$
    NEXT y

    FOR e = 63 TO 0 STEP - 1
        WAIT &h3da, 8
        WAIT &h3da, 8, 8
        OUT &h3c8, 0
        FOR a = 0 TO 100
            b = plt?( a )
            IF b < e THEN b = e
            OUT &h3c9, b
        NEXT a
    NEXT e

    CLOSE #1

END SUB

SUB ShowPic( Filnamn$ )

    OPEN filnamn$ FOR BINARY AS #1
    GET$ #1, 8, t$
    IF NOT t$ = "mhwanh" + CHR$( 0, 4 ) THEN errormessage "Corrupted picture"

    GET #1,, xsize: xsize = swapendians( xsize )
    GET #1,, ysize: ysize = swapendians( ysize )
    GET #1,, colours: colours = swapendians( colours )

    GET$ #1, 18, t$

    DIM plt?( 768 )

    FOR a = 0 TO 767
        GET #1,, p?
        plt?( a ) = p? \ 4
    NEXT a

    OUT &h3c8, 0
    FOR a = 0 TO 767
        OUT &h3c9, plt?( a )
    NEXT a

    SEEK #1, 800

    GET$ #1, 32000, t1$
    GET$ #1, 32000, t2$

    POKE$ 0, t1$
    POKE$ 32000, t2$

    CLOSE #1

END SUB








SUB Picture.Brum

    ysize = 250

    DIM lines$( ysize )
    DIM reallines$( ysize )

    OPEN "bild2b.raw" FOR BINARY AS #1
    GET$ #1, 8, t$
    IF NOT t$ = "mhwanh" + CHR$( 0, 4 ) THEN errormessage "Corrupted picture"

    GET #1,, xsize: xsize = swapendians( xsize )
    GET #1,, ysize: ysize = swapendians( ysize )
    GET #1,, colours: colours = swapendians( colours )

    GET$ #1, 18, t$

    SEEK #1, 800

    FOR y = 0 TO ysize - 1
        GET$ #1, xsize, lines$( y )
    NEXT y
    CLOSE #1

    DIM palett?( 768 )

    OPEN "bild2.raw" FOR BINARY AS #1
    GET$ #1, 8, t$
    IF NOT t$ = "mhwanh" + CHR$( 0, 4 ) THEN errormessage "Corrupted picture"

    GET #1,, xsize: xsize = swapendians( xsize )
    GET #1,, ysize: ysize = swapendians( ysize )
    GET #1,, colours: colours = swapendians( colours )


    GET$ #1, 18, t$

    FOR a = 0 TO 255
        GET #1,, r?: GET #1,, g?: GET #1,, b?
        palett?(( a * 3 )) = r? \ 4
        palett?(( a * 3 ) + 1 ) = g? \ 4
        palett?(( a * 3 ) + 2 ) = b? \ 4
    NEXT a

    SEEK #1, 800


    FOR y = 0 TO ysize - 1
        GET$ #1, xsize, reallines$( y )
    NEXT y
    CLOSE #1

    OUT &h3c0, &h31
    OUT &h3c0, 1

    DO
        mvbl
    LOOP UNTIL sync( 11, 255 )

    OUT &h3c8, 0: FOR a = 0 TO 767: OUT &h3c9, palett?( a ): NEXT a

    'vu=1


    DO

        IF getsample( 1 ) = 20 THEN

            IF current = 2 THEN mcls 0

            e! = ( RND * 0.5 ) + 0.5
            FOR a = 0 TO 255
                b = ( a \ 4 ) * e!
                setpal a, b, b, b
            NEXT a

            !   mov ax,&ha000
            '   Extended instruction: MOV GS,AX
            $INLINE &H8E,&HE8

            FOR a = 0 TO 179
                xp = 14 + RND * 10
                ma = STRSEG( lines$( a ))
                ms = STRPTR( lines$( a ))
                offset?? = ( a + 20 ) * 256 + xp
                le = 256 - xp
                !   mov ax,ma
                '   Extended instruction: MOV FS,AX
                $INLINE &H8E,&HE0
                sg = RND * &hffff

                '   Extended instruction: XOR EDI,EDI
                $INLINE &H66,&H33,&HFF

                !   mov di,ms

                !   mov si,offset??
                !   mov es,sg

                '   Extended instruction: XOR EBX,EBX
                $INLINE &H66,&H33,&HDB
                !   mov bx,xp
                '   Extended instruction: XOR ECX,ECX
                $INLINE &H66,&H33,&HC9

                lplplp:

                '   Extended instruction: MOV AX,FS:[ECX+EDI]
                $INLINE &H64,&H67,&H8B,&H4,&H39
                '   Extended instruction: MOV DX,ES:[BX+DI]
                $INLINE &H26,&H8B,&H11
                !   and dx,&b0000111100001111
                !   add ax,dx
                '   Extended instruction: MOV GS:[BX+SI],AX
                $INLINE &H65,&H89,&H0
                '   Extended instruction: ADD ECX,2
                $INLINE &H66,&H83,&HC1,&H2
                !   add bx,2
                !   cmp bx,le
                !   jb lplplp

            NEXT a

            current = 1

        ELSE


            FOR a = 0 TO 767: OUT &h3c9, palett?( a ): NEXT a

            DEF SEG = &ha000
            FOR y = 0 TO ysize - 1
                POKE$ y * 256, reallines$( y )
            NEXT y

            current = 2

        END IF

        mvbl

    LOOP UNTIL order = 12

END SUB


SUB demopart.VoxelCredits

    hercprint 0,0,15,"Dimming                        "

    DIM buff?( 32766 )
    buffseg = VARSEG( buff?( 0 ))
    DIM bakgrund( 3300 )
    bakseg = VARSEG( bakgrund( 0 ))
    DIM poss( 3300 )
    posseg = VARSEG( poss( 0 ))
    DIM hight( 12999 )
    hightseg = VARSEG( hight( 0 ))
    DIM bild??( 32766 )
    bildseg = VARSEG( bild??( 0 ))
    DIM faergmap??( 32766 )
    fmapseg = VARSEG( faergmap??( 0 ))
    DIM donepos( 3266 )
    doneseg = VARSEG( donepos( 0 ))
    DIM faergput( 3266 )
    faergseg = VARSEG( faergput( 0 ))
    DIM sincurv1( 1100 )
    DIM sincurv2( 1100 )



    hercprint 0,0,15,"Load1                          "


    DEF SEG = fmapseg

    OPEN "frgrid.raw" FOR BINARY AS #1
    GET$ #1, 8, t$
    IF NOT t$ = "mhwanh" + CHR$( 0, 4 ) THEN errormessage "Corrupted picture"

    GET #1,, xsize: xsize = swapendians( xsize )
    GET #1,, ysize: ysize = swapendians( ysize )
    GET #1,, colours: colours = swapendians( colours )


    GET$ #1, 18, t$

    DIM puss?( 768 )

    FOR a = 0 TO 767
        GET #1,, p?
        puss?( a ) = p? \ 4
    NEXT a

'    FOR a = 0 TO 255
'        GET #1,, r?: GET #1,, g?: GET #1,, b?
'        setpal a, r? \ 4, g? \ 4, b? \ 4
'    NEXT a

    SEEK #1, 800

    GET$ #1, 16000, t$
    POKE$ 0, t$
    GET$ #1, 16000, t$
    POKE$ 16000, t$
    GET$ #1, 16000, t$
    POKE$ 32000, t$
    GET$ #1, 16000, t$
    POKE$ 48000, t$

    t$ = ""

    'FOR y = 0 TO ysize - 1
    '    GET$ #1, xsize, t$
    '    POKE$ y * 320, t$
    'NEXT y

    CLOSE #1

    hercprint 0,0,15,"Load2                          "


    DEF SEG = bildseg

    BLOAD "grid.raw", 0



    FOR y = 0 TO 49
        FOR faerg = 0 TO 255
            hight( faerg + y * 256 ) = INT( faerg * ( y + 10 ) / 130 ) * 256
        NEXT faerg
    NEXT y

'def seg = &ha000
    FOR y = 0 TO 49
        FOR x = 0 TO 63
            poss( x + y * 64 ) = 63 + ( x - 32 ) * ( 1 + y * y / 2500 ) + ( INT( 49 - y * y / 50 )) * 320
        'poke 63+(x-32)*(1+y*y/2500)+(int(49-y*y/50))*320,1
        NEXT x
    NEXT y

'sleep
'end

    hercprint 0,0,15,"Sinus                          "

    FOR a = 0 TO 1000
        sincurv1( a ) = ( SIN( a * pi! / 500 ) * 90 ) + 95
        sincurv2( a ) = ( SIN( a * pi! / 500 ) * 75 ) + 75
    NEXT a



    antialias = 30
    DIM anti( antialias )

    hercprint 0,0,15,"Emsload                        "


'--------------------------
    ems.realloc 100

    OPEN "namn2.raw" FOR BINARY AS #1
    GET$ #1, 8, t$
    IF NOT t$ = "mhwanh" + CHR$( 0, 4 ) THEN errormessage "Corrupted picture"

    GET #1,, xsize: xsize = swapendians( xsize )
    GET #1,, ysize: ysize = swapendians( ysize )
    GET #1,, colours: colours = swapendians( colours )

    GET$ #1, 18, t$

    SEEK #1, 32

    DIM plt?( 768 )

    FOR a = 0 TO 767
        GET #1,, p?
        plt?( a ) = p? \ 4
    NEXT a


    SEEK #1, 800

    DIM NamnBild$( ysize )

    FOR b = 0 TO ysize

        DEF SEG = emmseg

        IF b > 249 THEN
            mx = 4
            moj = b - 249
        ELSE
            mx = 0
            moj = b
        END IF

        ems.mappage mx + 0 + pageadd, 0
        ems.mappage mx + 1 + pageadd, 1
        ems.mappage mx + 2 + pageadd, 2
        ems.mappage mx + 3 + pageadd, 3

        GET$ #1, xsize, NamnBild$
        POKE$ moj * 256, NamnBild$
    NEXT b


    CLOSE #1

    DEF SEG = &ha000

    DIM sinus( 359 )

    FOR v = 0 TO 359
        sinus( v ) = SIN( v * pi! / 180 ) * 75 + 145
    NEXT v

    t$ = STRING$( 256, 0 )

    v = 0
    b& = - 100 * 100

'    DO
'        WAIT &h3da, 8
'    LOOP UNTIL sync( 9, 255 )

    pseg = VARSEG( poss( 0 ))
    fputseg = VARSEG( faergput( 0 ))

    hercprint 0,0,15,"Wait                           "

    DO
        mvbl
    LOOP UNTIL order = > 9

    def seg=&ha000

    poke$ 0,string$(25000,0)
    poke$ 25000,string$(25000,0)

'    mcls 0

    

    OUT &h3c8, 0
    FOR a = 0 TO 767
        OUT &h3c9, puss?( a )
    NEXT a

    FOR a = 0 TO 15
        OUT &h3c8, a
        OUT &h3c9, plt?( a * 3 )
        OUT &h3c9, plt?( a * 3 + 1 )
        OUT &h3c9, plt?( a * 3 + 2 )
    NEXT a


    hercprint 0,0,15,"Mainloop                       "

    bj = 0

    ct = 0
    DO
        ct = ct + 1
        IF ct > 100 THEN bj = bj + 1
        IF bj > 8 THEN bj = 8

        sin1 = sin1 + 40
        IF sin1 > 10000 THEN sin1 = 0
        sin2 = sin2 + 30
        IF sin2 > 10000 THEN sin2 = 0

        sin3 = sin3 + 40 + bj
        IF sin3 > 10000 THEN sin3 = 0
        sin4 = sin4 + 30 - bj
        IF sin4 > 10000 THEN sin4 = 0

        xpos1 = sincurv1( sin1 \ 10 )
        ypos1 = sincurv2( sin2 \ 10 )
        xpos2 = sincurv1( sin3 \ 10 )
        ypos2 = sincurv2( sin4 \ 10 )

        bgseg = VARSEG( bakgrund( 0 ))

        FOR y = 0 TO 49
            yoffset = y * 64
            offset?? = xpos1 + ypos1 * 320

            !   mov ax,pseg
            !   mov es,ax
            !   mov ax,bgseg
            $INLINE &H8E,&HE0 ' C11 XI V2:                            MOV FS,AX
            !   mov ax,bildseg
            $INLINE &H8E,&HE8 ' C16 XI V2:                            MOV GS,AX
            !   mov di,offset??
            $INLINE &H66,&H33,&HC0 ' 11D2 XI V2:                                XOR EAX,EAX
            !   xor cx,cx
            hurgelgluff2:
            !   mov bx,cx
            !   add bx,yoffset
            $INLINE &HD1,&HE3 ' 85D XI V2:                             SHL BX,1
            !   mov ax,bx
            !   mov bx,es:[bx]
            !   add bx,di
            $INLINE &H65,&H8A,&H17 ' 1EB3 XI V2:                 MOV DL,GS:[BX]
            !   xor dh,dh
            $INLINE &H64,&H67,&H89,&H10 ' 2262 XI V2:           MOV FS:[EAX],DX
            !   inc cx
            !   cmp cx,64
            !   jb hurgelgluff2
        NEXT y







        FOR y = 0 TO 49
            yoffset = y * 64
            offset?? = xpos2 + ypos2 * 320

            !   mov ax,pseg
            !   mov es,ax
            !   mov ax,fputseg
            $INLINE &H8E,&HE0 ' C11 XI V2:                            MOV FS,AX
            !   mov ax,fmapseg
            $INLINE &H8E,&HE8 ' C16 XI V2:                            MOV GS,AX
            !   mov di,offset??
            $INLINE &H66,&H33,&HC0 ' 11D2 XI V2:                                XOR EAX,EAX
            !   xor cx,cx
            hurgelgluff:
            !   mov bx,cx
            !   add bx,yoffset
            $INLINE &HD1,&HE3 ' 85D XI V2:                             SHL BX,1
            !   mov ax,bx
            !   mov bx,es:[bx]
            !   add bx,di
            $INLINE &H65,&H8A,&H17 ' 1EB3 XI V2:                 MOV DL,GS:[BX]
            !   xor dh,dh
            $INLINE &H64,&H67,&H89,&H10 ' 2262 XI V2:           MOV FS:[EAX],DX
            !   inc cx
            !   cmp cx,64
            !   jb hurgelgluff
        NEXT y


        FOR y = 0 TO 49

            yoffset1 = y * 256
            yoffset2 = ( 49 - y ) * 64

            !   mov ax,bakseg
            !   mov es,ax

            !   mov ax,doneseg
        '   Extended instruction: MOV FS,AX
            $INLINE &H8E,&HE0
            !   mov ax,hightseg
        '   Extended instruction: MOV GS,AX
            $INLINE &H8E,&HE8

            !   mov di,yoffset1
            !   mov si,yoffset2

            !   sub cx,cx
            xloop1:

            !   mov bx,si
            !   add bx,cx
            !   shl bx,1
        '   Extended instruction: MOV DX,ES:[BX]
            $INLINE &H26,&H8B,&H17


            !   mov bx,di
            !   add bx,dx
            !   shl bx,1
        '   Extended instruction: MOV AX,GS:[BX]
            $INLINE &H65,&H8B,&H7

            !   mov bx,5376
            !   add bx,di
            !   add bx,di
            !   add bx,cx
            !   add bx,cx
            !   add bx,cx
            !   add bx,cx
            !   sub bx,ax
            !   mov ax,bx

            !   mov bx,cx
            !   add bx,si
            !   shl bx,1
        '   Extended instruction: MOV FS:[BX],AX
            $INLINE &H64,&H89,&H7

            !   inc cx
            !   cmp cx,64
            !   jne xloop1

        NEXT y

    'for y = 0 to 49 'step -1
    '    for x = 0 to 63
    '    hjd = hight(bakgrund(x+(49-y)*64)+y*256)
    '
    '        possi = 5120+y*256+y*256+x+x+x+x-hjd
    '        donepos(x+(49-y)*64)=possi
    '    next x
    'next y

    'for y = 0 to 49 'step -1
    '    for x = 0 to 63
    '        buff?( donepos( x + y * 64 )) = faergput( x + y * 64 ) - ( y \ 2 )
    '    next x
    'next y

        FOR y = 0 TO 49

            yoffset1 = y * 256
            yoffset2 = ( 49 - y ) * 64

            !   mov ax,buffseg
        '   Extended instruction: MOV ES,AX
            $INLINE &H8E,&HC0
            !   mov ax,doneseg
        '   Extended instruction: MOV FS,AX
            $INLINE &H8E,&HE0
            !   mov ax,faergseg
        '   Extended instruction: MOV GS,AX
            $INLINE &H8E,&HE8

            !   mov di,yoffset1
            !   mov si,yoffset2

            !   sub cx,cx
            xloop2:

            !   mov dx,di

            !   mov bx,cx
            !   add bx,si
            !   shl bx,1
        '   Extended instruction: MOV DL,GS:[BX]
            $INLINE &H65,&H8A,&H17

            $INLINE &HD0,&HEE ' 819 XI V2:                                         SHR DH,1
            !   add dl,dh
            !   sub dl,24



            !   mov dh,dl
            !   mov ax,dx
        '   Extended instruction: BSWAP EDX
            $INLINE &H66,&HF,&HCA
            !   mov dx,ax

        '   Extended instruction: MOV AX,FS:[BX]
            $INLINE &H64,&H8B,&H7

            !   mov bx,ax

            !   cmp bx,25599
            !   ja noprick

        '   Extended instruction: MOV ES:[BX],EDX
            $INLINE &H66,&H26,&H89,&H17
        '   Extended instruction: MOV ES:[BX+256],EDX
            $INLINE &H66,&H26,&H89,&H97,&H0,&H1
        '   Extended instruction: MOV ES:[BX+512],EDX
            $INLINE &H66,&H26,&H89,&H97,&H0,&H2
        '   Extended instruction: MOV ES:[BX+768],EDX
            $INLINE &H66,&H26,&H89,&H97,&H0,&H3
        '   Extended instruction: MOV ES:[BX+1024],EDX
            $INLINE &H66,&H26,&H89,&H97,&H0,&H4
        '   Extended instruction: MOV ES:[BX+1280],EDX
            $INLINE &H66,&H26,&H89,&H97,&H0,&H5
        '   Extended instruction: MOV ES:[BX+1536],EDX
            $INLINE &H66,&H26,&H89,&H97,&H0,&H6
        '   Extended instruction: MOV ES:[BX+1792],EDX
            $INLINE &H66,&H26,&H89,&H97,&H0,&H7
'        '   Extended instruction: MOV ES:[BX+2048],EDX
            $INLINE &H66,&H26,&H89,&H97,&H0,&H8

            noprick:

            !   inc cx
            !   cmp cx,64
            !   jne xloop2

        NEXT y


        FOR x = 0 TO 63
            faerg = faergput( x )
            lsthjd = donepos( x ) + 2304

            !   mov ax,buffseg
            !   mov es,ax

            !   mov dl,faerg
            !   mov dh,dl
            !   mov cx,dx
        '   Extended instruction: BSWAP EDX
            $INLINE &H66,&HF,&HCA
            !   mov dx,cx

            !   mov bx,lsthjd
            yloop:
        '   Extended instruction: MOV ES:[BX],EDX
            $INLINE &H66,&H26,&H89,&H17
            !   add bx,256
            !   cmp bx,25340
            !   jna yloop
        NEXT x

    'for x = 0 to 63
    '    faerg = faergput(x)
    '    for y = donepos(x) to 99*256 step 256
    '        buff?(y) = faerg
    '    next y
    'next x



        hjd = hight( bakgrund( 32 ) + 49 * 256 ) \ 256

        ai = ai + 1
        IF ai = antialias THEN ai = 0
        anti( ai ) = hjd

        nn& = 0
        FOR a = 0 TO antialias - 1
            nn& = nn& + anti( a )
        NEXT a

        n = nn& \ antialias \ 2

        DEF SEG = CODESEG( markselfmodify1 )
        mm = CODEPTR( markselfmodify1 )
        POKEI mm + 5,( n + 90 ) * 256


        'CALL setpal( 0, 0, 0, 0 )
        mvbl
        'WAIT &h3da, 8
'        CALL setpal( 0, 0, 0, 20 )

        bufflen = 25340 - n * 256

    '   Extended instruction: SUB EBX,EBX
        $INLINE &H66,&H2B,&HDB
        !   mov bx,bufflen

        !   mov ax,buffseg
        !   mov es,ax

        !   mov ax,&ha000
    '   Extended instruction: MOV FS,AX
        $INLINE &H8E,&HE0

    '   Extended instruction: SUB EAX,EAX
        $INLINE &H66,&H2B,&HC0

        varsudd:
    '   Extended instruction: MOV EDX,ES:[EBX]
        $INLINE &H66,&H26,&H67,&H8B,&H13

        MarkSelfModify1:
    '   Extended instruction: MOV FS:[EBX+3700H],EDX
        $INLINE &H66,&H64,&H67,&H89,&H93,&H0,&H37,&H0,&H0
    '   Extended instruction: MOV ES:[EBX],EAX
        $INLINE &H66,&H26,&H67,&H89,&H3
    '   Extended instruction: SUB EBX,4
        $INLINE &H66,&H83,&HEB,&H4
        !   jnz varsudd


'--------------------------

        b& = b& + sinus( v )
        mb = b& \ 100
        v = v + 22
        IF v > 359 THEN v = v - 359

        FOR y = 0 TO 95
            IF ( y + mb ) < ysize AND ( y + mb ) > 0 THEN

                b = y + mb


                IF b > 249 AND oldmx = 0 THEN

                    mx = 4
                    mojmin = 249

                    ems.mappage mx + 0 + pageadd, 0
                    ems.mappage mx + 1 + pageadd, 1
                    ems.mappage mx + 2 + pageadd, 2
                    ems.mappage mx + 3 + pageadd, 3

                END IF

                IF b < 249 AND oldmx = 4 THEN

                    mx = 0
                    mojmin = 0

                    ems.mappage mx + 0 + pageadd, 0
                    ems.mappage mx + 1 + pageadd, 1
                    ems.mappage mx + 2 + pageadd, 2
                    ems.mappage mx + 3 + pageadd, 3

                END IF

                moj = b - mojmin

                oldmx = mx

                !   mov ax,emmseg
                !   mov es,ax
                !   mov ax,&ha000
                $INLINE &H8E,&HE8 ' C16 XI V2:                        MOV GS,AX
                !   xor bx,bx
                !   mov si,moj
                $INLINE &HC1,&HE6,&H8 ' 890 XI V2:                     SHL SI,8
                !   mov di,y
                $INLINE &HC1,&HE7,&H8 ' 845 XI V2:                     SHL DI,8
                asdf:
                $INLINE &H66,&H26,&H8B,&H0 ' 30C3 XI V2:     MOV EAX,ES:[BX+SI]
                $INLINE &H66,&H65,&H89,&H1 ' 2F2B XI V2:     MOV GS:[BX+DI],EAX
                !   add bx,4
                !   cmp bx,256
                !   jb asdf

            END IF
        NEXT y

    LOOP UNTIL order > = 11
END SUB

SUB DemoPart.SvenskFlagga


dim sincurv??(6000)
dim flgmap?(22800)

for a = 0 to 3000
    sincurv??(a) = (sin(a*pi!/500)*10)+10
    sincurv??(a+3000) = int((sin(a*pi!/500)*10)+10)*256
next a

for a = 0 to 63
    setpal a,0,0,0
    setpal a+64,0,0,a*1.5
    setpal a+128,a*1.5,a*1.5,0
next a

def seg=&ha000

bload "flag.raw"

for y = 0 to 119
    for x = 0 to 189
        mx=peek(x+y*320)
        if mx=0 then flgmap?(count) = 0
        if mx=1 then flgmap?(count) = 64
        if mx=42 then flgmap?(count) = 128
        count = count+1
    next x
next y
count = 0
mcls 0

do
    
    if ysin > 1000 then ysin = ysin-1000
    mainy = ysin
    
    if xsin > 1000 then xsin = xsin-1000
    mainx = xsin
    
    m2 = varseg(sincurv??(0))
    m1 = varseg(flgmap?(0))
    
    for y = 0 to 119
        
        ymul = y*256
        
        ymap = y*190
        
        if ysin > 1000 then ysin = ysin-1000
        oldy = ysin
        
        if xsin > 1000 then xsin = xsin-1000
        oldx = xsin
        
        '$if 0
        
        !   mov ax,&ha000
        '   Extended instruction: MOV GS,AX
        $INLINE &H8E,&HE8
        
        !   mov ax,m1
        '   Extended instruction: MOV FS,AX
        $INLINE &H8E,&HE0
        
        !   mov es,m2
        
        '   Extended instruction: XOR ESI,ESI
        $INLINE &H66,&H33,&HF6
        '   Extended instruction: XOR EDI,EDI
        $INLINE &H66,&H33,&HFF
        !   mov si,ysin
        '   Extended instruction: SHL ESI,1
        $INLINE &H66,&HD1,&HE6
        !   mov di,xsin
        '   Extended instruction: SHL EDI,1
        $INLINE &H66,&HD1,&HE7
        
        '   Extended instruction: XOR ECX,ECX
        $INLINE &H66,&H33,&HC9
        
        '   Extended instruction: XOR EAX,EAX
        $INLINE &H66,&H33,&HC0
        
        '   Extended instruction: XOR EDX,EDX
        $INLINE &H66,&H33,&HD2
        !   mov dx,ymul
        
        
        !   xor bx,bx
        
        xxloop:
        
        '   Extended instruction: ADD ESI,12
        $INLINE &H66,&H83,&HC6,&HC
        '   Extended instruction: MOV CX,ES:[ESI+6000]
        $INLINE &H26,&H67,&H8B,&H8E,&H70,&H17,&H0,&H0
        !   add cx,dx
        !   add cx,bx
        
        '   Extended instruction: ADD EDI,10
        $INLINE &H66,&H83,&HC7,&HA
        '   Extended instruction: ADD CX,ES:[EDI]
        $INLINE &H26,&H67,&H3,&HF
        
        '   Extended instruction: MOV AX,ES:[EDI]
        $INLINE &H26,&H67,&H8B,&H7
        '   Extended instruction: ADD AX,ES:[ESI]
        $INLINE &H26,&H67,&H3,&H6
        
        !   add bx,ymap
        '   Extended instruction: ADD AX,FS:[BX]
        $INLINE &H64,&H3,&H7
        '   Extended instruction: XOR AH,AH
        $INLINE &H32,&HE4
        !   sub bx,ymap
        
        
        !   mov ah,al
        
        $INLINE &H65,&H67,&H89,&H81,&H14,&H17,&H0,&H0 ' 4EAF XI V2: MOV GS:[ECX+20+01700H],AX
        
        
        !   inc bx
        
        '   Extended instruction: ADD ESI,12
        $INLINE &H66,&H83,&HC6,&HC
        '   Extended instruction: MOV CX,ES:[ESI+6000]
        $INLINE &H26,&H67,&H8B,&H8E,&H70,&H17,&H0,&H0
        !   add cx,dx
        !   add cx,bx
        
        '   Extended instruction: ADD EDI,10
        $INLINE &H66,&H83,&HC7,&HA
        '   Extended instruction: ADD CX,ES:[EDI]
        $INLINE &H26,&H67,&H3,&HF
        
        '   Extended instruction: MOV AX,ES:[EDI]
        $INLINE &H26,&H67,&H8B,&H7
        '   Extended instruction: ADD AX,ES:[ESI]
        $INLINE &H26,&H67,&H3,&H6
        
        !   add bx,ymap
        '   Extended instruction: ADD AX,FS:[BX]
        $INLINE &H64,&H3,&H7
        '   Extended instruction: XOR AH,AH
        $INLINE &H32,&HE4
        !   sub bx,ymap
        
        
        !   mov ah,al
        
        $INLINE &H65,&H67,&H89,&H81,&H14,&H17,&H0,&H0 ' 4EAF XI V2: MOV GS:[ECX+20+01700H],AX
        
        !   inc bx
        
        !   cmp bx,188
        !   jne xxloop
        
        '$endif
        
        
        
        
        $if 0
        
        for x = 0 to 189
            if flgmap(x+y*190) > 0 then
                flgmap = flgmap(x+y*190)
                ysin = ysin+4
                ypos = sincurv??(ysin+3000)
                
                xsin = xsin+3
                xpos = sincurv??(xsin)
                
                poke 40+x+xpos+((ymul+sincurv??(ysin+3000))),xpos+sincurv??(ysin)+flgmap
            else
                poke 40+x+xpos+((ymul+sincurv??(ysin+3000))),0
            end if
        next x
        
        $endif
        
        ysin = oldy+9
        xsin = oldx+7
        
    next y
    xsin = mainx+21
    ysin = mainy+15
    
    
'    setpal 0,0,0,30
'    wait &h3da,8
'    setpal 0,0,0,50

    mvbl

    LOOP UNTIL order = > 12 AND pattpos = > 48
    




END SUB


