[SOLVED] How did 6.12 break it?

Just starting out? Need help? Post your questions and find answers here.
Randy Walker
Addict
Addict
Posts: 1109
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

[SOLVED] How did 6.12 break it?

Post by Randy Walker »

I imagine most everyone here has done their own Tetris on Windows. I did this long ago before even ver 4.xx but tried it in ver 6.12x64 and drawing is all messed up. Works ok in ver 5.62x64 so I don't think it's a 64 bit problem:

Code: Select all

; Author: Randy Walker (updated for PB 4.00)
; Date: January 2010
; OS: Windows
; Demo: Yes

Procedure pretest()
  If InitSprite() = 0
    MessageRequester("Error", "Can't open screen & sprite enviroment!", 0)
    End
  EndIf
  Global scard.i, sfx.i
  sfx.i = #True
  If InitSound() = 0
    MessageRequester("Error", "Can't open DirectX 7 or no sound card is available",  0)
    scard.i = #False
    sfx.i = #False
  EndIf
  If sfx = #True
    scard.i = #True
    ;Stepdown
    If LoadSound(0, "C:\WINDOWS\Media\Windows XP Menu Command.wav")
    Else
      Debug "missed 0"
      scard.i = #False
      sfx.i = #False
    EndIf
    ;Left / Right
    If LoadSound(1, "C:\WINDOWS\Media\Windows XP Start.wav")
    Else
      Debug "missed 1"
      scard.i = #False
      sfx.i = #False
    EndIf
    ;Rotate
    If LoadSound(2, "C:\WINDOWS\Media\Windows XP Start.wav")
    Else
      Debug "missed 2"
      scard.i = #False
      sfx.i = #False
    EndIf
    ;Drop
    If LoadSound(3, "C:\WINDOWS\Media\Windows XP Minimize.wav")
    Else
      Debug "missed 3"
      scard.i = #False
      sfx.i = #False
    EndIf
    ;Score
    If LoadSound(4, "C:\WINDOWS\Media\Windows XP Hardware Fail.wav")
    Else
      Debug "missed 4"
      scard.i = #False
      sfx.i = #False
    EndIf
    ;Pee break
    If LoadSound(5, "C:\WINDOWS\Media\Windows XP Hardware Remove.wav")
    Else
      Debug "missed 5"
      scard.i = #False
      sfx.i = #False
    EndIf
    ;Pee return
    If LoadSound(6, "C:\WINDOWS\Media\Windows XP Hardware Insert.wav")
    Else
      Debug "missed 6"
      scard.i = #False
      sfx.i = #False
    EndIf
    If sfx = #False
      MessageRequester("Error", "One or more Windows XP sound files is missing.",  0)
    EndIf
  EndIf
EndProcedure
Procedure initdata()
  DataSection
  ;;           ;;  FFFFFFFFFFF
  Data.w 5,45
  Data.w 5,60
  Data.w 5,75
  Data.w 5,90
  Data.w 5,105
  Data.w 5,120
  Data.w 5,135
  Data.w 5,150
  Data.w 5,165
  Data.w 20,45
  Data.w 35,45
  Data.w 50,45
  Data.w 65,45
  Data.w 20,105
  Data.w 35,105
  Data.w 50,105
  ;;          ;;  OOOOOOOOOOO
  Data.w 105,45
  Data.w 105,60
  Data.w 105,75
  Data.w 105,90
  Data.w 105,105
  Data.w 105,120
  Data.w 105,135
  Data.w 105,150
  Data.w 105,165
  Data.w 120,45
  Data.w 135,45
  Data.w 150,45
  Data.w 105,165
  Data.w 120,165
  Data.w 135,165
  Data.w 150,165
  Data.w 165,45
  Data.w 165,60
  Data.w 165,75
  Data.w 165,90
  Data.w 165,105
  Data.w 165,120
  Data.w 165,135
  Data.w 165,150
  Data.w 165,165
  ;;          ;;  UUUUUUUUUUU
  Data.w 205,45
  Data.w 205,60
  Data.w 205,75
  Data.w 205,90
  Data.w 205,105
  Data.w 205,120
  Data.w 205,135
  Data.w 205,150
  Data.w 205,165
  Data.w 205,165
  Data.w 220,165
  Data.w 235,165
  Data.w 250,165
  Data.w 265,45
  Data.w 265,60
  Data.w 265,75
  Data.w 265,90
  Data.w 265,105
  Data.w 265,120
  Data.w 265,135
  Data.w 265,150
  Data.w 265,165
  ;;          ;;   RRRRRRRRRR
  Data.w 305,45
  Data.w 305,60
  Data.w 305,75
  Data.w 305,90
  Data.w 305,105
  Data.w 305,120
  Data.w 305,135
  Data.w 305,150
  Data.w 305,165
  Data.w 320,45
  Data.w 335,45
  Data.w 350,45
  Data.w 350,60
  Data.w 350,90
  Data.w 320,105
  Data.w 335,105
  Data.w 350,105
  Data.w 365,60
  Data.w 365,75
  Data.w 365,90
  Data.w 335,120
  Data.w 335,135
  Data.w 350,135
  Data.w 350,150
  Data.w 365,150
  Data.w 365,165
  ;;              ;;   SSSSSSSSSSSS
  Data.w 420,45
  Data.w 420,60
  Data.w 405,60
  Data.w 405,75
  Data.w 405,90
  Data.w 420,90
  Data.w 435,45
  Data.w 450,45
  Data.w 450,60
  Data.w 465,60
  Data.w 465,75
  Data.w 435,90
  Data.w 435,105
  ;;Data 435,120
  Data.w 450,105
  Data.w 450,120
  Data.w 465,120
  Data.w 465,135
  Data.w 465,150
  Data.w 405,135
  Data.w 405,150
  Data.w 420,150
  Data.w 420,165
  Data.w 435,165
  Data.w 450,165
  Data.w 450,150
  ;;              ;;   KKKKKKKKKKKKKKK
  Data.w 505,45
  Data.w 505,60
  Data.w 505,75
  Data.w 505,90
  Data.w 520,90
  Data.w 520,105
  Data.w 550,60
  Data.w 550,75
  Data.w 535,75
  Data.w 535,90
  Data.w 535,105
  Data.w 535,120
  Data.w 550,120
  Data.w 550,135
  Data.w 550,150
  Data.w 565,150
  Data.w 565,165
  Data.w 505,105
  Data.w 505,120
  Data.w 505,135
  Data.w 505,150
  Data.w 505,165
  ;;              ;;   IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
  Data.w 605,45
  Data.w 605,60
  Data.w 605,75
  Data.w 605,90
  Data.w 605,105
  Data.w 605,120
  Data.w 605,135
  Data.w 605,150
  Data.w 605,165
  ;;              ;;   ++++++++++++
  Data.w  395,225
  Data.w  410,225
  Data.w 410,210
  Data.w 410,240
  Data.w 425,225
  EndDataSection
EndProcedure
Procedure SetGlobals()
  Global T.i, settled.i
  Global k.i, GameBoard.i
  Global l.i, beginner.i
  Global r.i
  Global d.i
  Global bN.i
  Global bR.i
  Global bL.i
  Global bH.i
  Global A$
  Global Pb$
  Global c.i
  Global x.i
  Global x1.i
  Global y.i
  Global y1.i
  Global score.i
  Global speed.i
  Global key.i
  Global wait.i
  Global Shape.i
  ;;  bN.i-block#, bR.i-block rotation, bL.i-block latitude, bH.i-block height
  ;;    lb|( type, x, y, rotation )
  Global Dim l.i(20,43)
  Global Dim Lb.i(7,4,4,4)
  Global Dim Pb$(7,4)
  Global Dim r.i(9)
  Global Dim T.i(4)
EndProcedure
SetGlobals()
Declare grabNext4()
Procedure Original_init_logic()
  ;;___________________________________________
  Lb(1,1,3,1) = 1   ;;  : :      Clockwise rotation
  Lb(1,2,3,1) = 1
  Lb(1,1,4,1) = 1
  Lb(1,2,4,1) = 1
  
  Lb(1,1,3,2) = 1
  Lb(1,2,3,2) = 1
  Lb(1,1,4,2) = 1
  Lb(1,2,4,2) = 1
  
  Lb(1,1,3,3) = 1
  Lb(1,2,3,3) = 1
  Lb(1,1,4,3) = 1
  Lb(1,2,4,3) = 1
  
  Lb(1,1,3,4) = 1
  Lb(1,2,3,4) = 1
  Lb(1,1,4,4) = 1
  Lb(1,2,4,4) = 1
  
  ;;___________________________________________
  Lb(2,1,4,1) = 1   ;;  - - - -
  Lb(2,2,4,1) = 1
  Lb(2,3,4,1) = 1
  Lb(2,4,4,1) = 1
  
  Lb(2,1,1,2) = 1
  Lb(2,1,2,2) = 1
  Lb(2,1,3,2) = 1
  Lb(2,1,4,2) = 1
  
  Lb(2,1,4,3) = 1
  Lb(2,2,4,3) = 1
  Lb(2,3,4,3) = 1
  Lb(2,4,4,3) = 1
  
  Lb(2,1,1,4) = 1
  Lb(2,1,2,4) = 1
  Lb(2,1,3,4) = 1
  Lb(2,1,4,4) = 1
  
  ;;___________________________________________
  Lb(3,1,4,1) = 1   ;;  ___|
  Lb(3,2,4,1) = 1
  Lb(3,3,4,1) = 1
  Lb(3,3,3,1) = 1
  
  Lb(3,2,4,2) = 1
  Lb(3,1,4,2) = 1
  Lb(3,1,3,2) = 1
  Lb(3,1,2,2) = 1
  
  Lb(3,1,4,3) = 1
  Lb(3,1,3,3) = 1
  Lb(3,2,3,3) = 1
  Lb(3,3,3,3) = 1
  
  Lb(3,1,2,4) = 1
  Lb(3,2,2,4) = 1
  Lb(3,2,3,4) = 1
  Lb(3,2,4,4) = 1
  
  ;;___________________________________________
  Lb(4,1,3,1) = 1   ;;  |___
  Lb(4,1,4,1) = 1
  Lb(4,2,4,1) = 1
  Lb(4,3,4,1) = 1
  
  Lb(4,2,2,2) = 1
  Lb(4,1,2,2) = 1
  Lb(4,1,3,2) = 1
  Lb(4,1,4,2) = 1
  
  Lb(4,1,3,3) = 1
  Lb(4,2,3,3) = 1
  Lb(4,3,3,3) = 1
  Lb(4,3,4,3) = 1
  
  Lb(4,1,4,4) = 1
  Lb(4,2,4,4) = 1
  Lb(4,2,3,4) = 1
  Lb(4,2,2,4) = 1
  
  ;;___________________________________________
  Lb(5,1,4,1) = 1   ;;  __,----
  Lb(5,2,4,1) = 1
  Lb(5,2,3,1) = 1
  Lb(5,3,3,1) = 1
  
  Lb(5,1,2,2) = 1
  Lb(5,1,3,2) = 1
  Lb(5,2,3,2) = 1
  Lb(5,2,4,2) = 1
  
  Lb(5,1,4,3) = 1
  Lb(5,2,4,3) = 1
  Lb(5,2,3,3) = 1
  Lb(5,3,3,3) = 1
  
  Lb(5,1,2,4) = 1
  Lb(5,1,3,4) = 1
  Lb(5,2,3,4) = 1
  Lb(5,2,4,4) = 1
  
  ;;___________________________________________
  Lb(6,1,3,1) = 1   ;;  ----,__
  Lb(6,2,3,1) = 1
  Lb(6,2,4,1) = 1
  Lb(6,3,4,1) = 1
  
  Lb(6,2,2,2) = 1
  Lb(6,2,3,2) = 1
  Lb(6,1,3,2) = 1
  Lb(6,1,4,2) = 1
  
  Lb(6,1,3,3) = 1
  Lb(6,2,3,3) = 1
  Lb(6,2,4,3) = 1
  Lb(6,3,4,3) = 1
  
  Lb(6,2,2,4) = 1
  Lb(6,2,3,4) = 1
  Lb(6,1,3,4) = 1
  Lb(6,1,4,4) = 1
  ;;___________________________________________
  Lb(7,1,4,1) = 1   ;;       . : .
  Lb(7,2,4,1) = 1
  Lb(7,2,3,1) = 1
  Lb(7,3,4,1) = 1
  
  Lb(7,1,2,2) = 1
  Lb(7,1,3,2) = 1
  Lb(7,2,3,2) = 1
  Lb(7,1,4,2) = 1
  
  Lb(7,1,3,3) = 1
  Lb(7,2,3,3) = 1
  Lb(7,2,4,3) = 1
  Lb(7,3,3,3) = 1
  
  Lb(7,2,2,4) = 1
  Lb(7,1,3,4) = 1
  Lb(7,2,3,4) = 1
  Lb(7,2,4,4) = 1
EndProcedure
Procedure init_logic()
  ;;___________________________________________
  Lb(1,1,3,1) = 1   ;;  : :      Clockwise rotation
  Lb(1,2,3,1) = 1
  Lb(1,1,4,1) = 1
  Lb(1,2,4,1) = 1
  
  Lb(1,1,3,2) = 1
  Lb(1,2,3,2) = 1
  Lb(1,1,4,2) = 1
  Lb(1,2,4,2) = 1
  
  Lb(1,1,3,3) = 1
  Lb(1,2,3,3) = 1
  Lb(1,1,4,3) = 1
  Lb(1,2,4,3) = 1
  
  Lb(1,1,3,4) = 1
  Lb(1,2,3,4) = 1
  Lb(1,1,4,4) = 1
  Lb(1,2,4,4) = 1
  
  ;;___________________________________________
  Lb(2,1,1,1) = 1
  Lb(2,1,2,1) = 1
  Lb(2,1,3,1) = 1
  Lb(2,1,4,1) = 1
  
  Lb(2,1,4,2) = 1   ;;  - - - -
  Lb(2,2,4,2) = 1
  Lb(2,3,4,2) = 1
  Lb(2,4,4,2) = 1
  
  Lb(2,1,1,3) = 1
  Lb(2,1,2,3) = 1
  Lb(2,1,3,3) = 1
  Lb(2,1,4,3) = 1
  
  Lb(2,1,4,4) = 1
  Lb(2,2,4,4) = 1
  Lb(2,3,4,4) = 1
  Lb(2,4,4,4) = 1
  
  ;;___________________________________________
  Lb(3,1,4,1) = 1   ;;  ___|
  Lb(3,2,4,1) = 1
  Lb(3,3,4,1) = 1
  Lb(3,3,3,1) = 1
  
  Lb(3,2,4,2) = 1
  Lb(3,1,4,2) = 1
  Lb(3,1,3,2) = 1
  Lb(3,1,2,2) = 1
  
  Lb(3,1,4,3) = 1
  Lb(3,1,3,3) = 1
  Lb(3,2,3,3) = 1
  Lb(3,3,3,3) = 1
  
  Lb(3,1,2,4) = 1
  Lb(3,2,2,4) = 1
  Lb(3,2,3,4) = 1
  Lb(3,2,4,4) = 1
  
  ;;___________________________________________
  Lb(4,1,3,1) = 1   ;;  |___
  Lb(4,1,4,1) = 1
  Lb(4,2,4,1) = 1
  Lb(4,3,4,1) = 1
  
  Lb(4,2,2,2) = 1
  Lb(4,1,2,2) = 1
  Lb(4,1,3,2) = 1
  Lb(4,1,4,2) = 1
  
  Lb(4,1,3,3) = 1
  Lb(4,2,3,3) = 1
  Lb(4,3,3,3) = 1
  Lb(4,3,4,3) = 1
  
  Lb(4,1,4,4) = 1
  Lb(4,2,4,4) = 1
  Lb(4,2,3,4) = 1
  Lb(4,2,2,4) = 1
  
  ;;___________________________________________
  Lb(5,1,2,1) = 1
  Lb(5,1,3,1) = 1
  Lb(5,2,3,1) = 1
  Lb(5,2,4,1) = 1
  
  Lb(5,1,4,2) = 1   ;;  __,----
  Lb(5,2,4,2) = 1
  Lb(5,2,3,2) = 1
  Lb(5,3,3,2) = 1
  
  Lb(5,1,2,3) = 1
  Lb(5,1,3,3) = 1
  Lb(5,2,3,3) = 1
  Lb(5,2,4,3) = 1
  
  Lb(5,1,4,4) = 1
  Lb(5,2,4,4) = 1
  Lb(5,2,3,4) = 1
  Lb(5,3,3,4) = 1
  
  ;;___________________________________________
  Lb(6,2,2,1) = 1
  Lb(6,2,3,1) = 1
  Lb(6,1,3,1) = 1
  Lb(6,1,4,1) = 1
  
  Lb(6,1,3,2) = 1   ;;  ----,__
  Lb(6,2,3,2) = 1
  Lb(6,2,4,2) = 1
  Lb(6,3,4,2) = 1
  
  Lb(6,2,2,3) = 1
  Lb(6,2,3,3) = 1
  Lb(6,1,3,3) = 1
  Lb(6,1,4,3) = 1
  
  Lb(6,1,3,4) = 1
  Lb(6,2,3,4) = 1
  Lb(6,2,4,4) = 1
  Lb(6,3,4,4) = 1
  
  ;;___________________________________________
  Lb(7,1,4,1) = 1   ;;       . : .
  Lb(7,2,4,1) = 1
  Lb(7,2,3,1) = 1
  Lb(7,3,4,1) = 1
  
  Lb(7,1,2,2) = 1
  Lb(7,1,3,2) = 1
  Lb(7,2,3,2) = 1
  Lb(7,1,4,2) = 1
  
  Lb(7,1,3,3) = 1
  Lb(7,2,3,3) = 1
  Lb(7,2,4,3) = 1
  Lb(7,3,3,3) = 1
  
  Lb(7,2,2,4) = 1
  Lb(7,1,3,4) = 1
  Lb(7,2,3,4) = 1
  Lb(7,2,4,4) = 1
EndProcedure
Procedure init_draw()
  If OpenWindow(0, 0, 0, 425, 502, " Fourski III", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    ButtonGadget(0, 310, 435, 85, 22, "Mom's home!!!")
    TextGadget(1, 300, 40, 110, 18, "Hello", #PB_Text_Center)
    TextGadget(2, 300, 58, 110, 20, "Hello", #PB_Text_Center|#PB_Text_Border)
    TextGadget(3, 300, 120, 110, 20, "Hello", #PB_Text_Center|#PB_Text_Border)
    TextGadget(4, 300, 142, 110, 20, "Hello", #PB_Text_Center|#PB_Text_Border)
    TextGadget(5, 300, 300, 110, 18, "/\ Rotate \/", #PB_Text_Center)
    TextGadget(6, 300, 330, 110, 18, "< Left<>Right >", #PB_Text_Center)
    TextGadget(7, 300, 360, 110, 18, "Enter-Drop", #PB_Text_Center)
    TextGadget(8, 300, 390, 110, 18, "Space-Pause", #PB_Text_Center)
    TextGadget(9, 300, 170, 110, 18, "Player Mode", #PB_Text_Center|#PB_Text_Border)
    ButtonGadget(10, 310, 255, 85, 22, "Silent Mode")
    GameBoard.i = OpenWindowedScreen(WindowID(0), 0, 0, 280, 502, 0, 0, 0)
    If GameBoard.i
      ClearScreen(RGB(0, 0, 0))
      ; If StartDrawing(WindowOutput(0))
        ; Box(99, 29, 262, 421, RGB(255, 0, 0))  ; blank row
        ; StopDrawing()
      ; EndIf
      CreateSprite(0, 20, 20)
      If StartDrawing(SpriteOutput(0))
        Box(0, 0, 19, 19, RGB(110, 110, 110))  ; blank row
        StopDrawing()
      EndIf
      ;-
      ;/Color 1
      ;   : :
      ClearScreen(RGB(0, 0, 0))
      CreateSprite(1, 40, 80)
      If StartDrawing(SpriteOutput(1))
        Box(0, 40, 19, 19, RGB(195, 0, 155))
        Box(0, 60, 19, 19, RGB(195, 0, 155))
        Box(20, 40, 19, 19, RGB(195, 0, 155))
        Box(20, 60, 19, 19, RGB(195, 0, 155))
        StopDrawing()
      EndIf
      CopySprite(1,2)
      CopySprite(1,3)
      CopySprite(1,4)
      
      ;/Color 2
      ;  - - - -
      ClearScreen(RGB(0, 0, 0))
      CreateSprite(5, 40, 80)
      If StartDrawing(SpriteOutput(5))
        Box(0, 0, 19, 19, RGB(0, 100, 155))
        Box(0, 20, 19, 19, RGB(0, 100, 155))
        Box(0, 40, 19, 19, RGB(0, 100, 155))
        Box(0, 60, 19, 19, RGB(0, 100, 155))
        StopDrawing()
      EndIf
      ClearScreen(RGB(0, 0, 0))
      CreateSprite(6, 80, 80)
      If StartDrawing(SpriteOutput(6))
        Box(0, 60, 19, 19, RGB(0, 100, 155))
        Box(20, 60, 19, 19, RGB(0, 100, 155))
        Box(40, 60, 19, 19, RGB(0, 100, 155))
        Box(60, 60, 19, 19, RGB(0, 100, 155))
        StopDrawing()
      EndIf
      CopySprite(5,7)
      CopySprite(6,8)
      
      ;/Color 3
      ;  ___|
      ClearScreen(RGB(0, 0, 0))
      CreateSprite(9, 60, 80)
      If StartDrawing(SpriteOutput(9))
        Box(0, 60, 19, 19, RGB(155, 100, 0))
        Box(20, 60, 19, 19, RGB(155, 100, 0))
        Box(40, 60, 19, 19, RGB(155, 100, 0))
        Box(40, 40, 19, 19, RGB(155, 100, 0))
        StopDrawing()
      EndIf
      ClearScreen(RGB(0, 0, 0))
      CreateSprite(10, 60, 80)
      If StartDrawing(SpriteOutput(10))
        Box(0, 20, 19, 19, RGB(155, 100, 0))
        Box(0, 40, 19, 19, RGB(155, 100, 0))
        Box(0, 60, 19, 19, RGB(155, 100, 0))
        Box(20, 60, 19, 19, RGB(155, 100, 0))
        StopDrawing()
      EndIf
      ClearScreen(RGB(0, 0, 0))
      CreateSprite(11, 60, 80)
      If StartDrawing(SpriteOutput(11))
        Box(0, 40, 19, 19, RGB(155, 100, 0))
        Box(20, 40, 19, 19, RGB(155, 100, 0))
        Box(40, 40, 19, 19, RGB(155, 100, 0))
        Box(0, 60, 19, 19, RGB(155, 100, 0))
        StopDrawing()
      EndIf
      ClearScreen(RGB(0, 0, 0))
      CreateSprite(12, 40, 80)
      If StartDrawing(SpriteOutput(12))
        Box(0, 20, 19, 19, RGB(155, 100, 0))
        Box(20, 20, 19, 19, RGB(155, 100, 0))
        Box(20, 40, 19, 19, RGB(155, 100, 0))
        Box(20, 60, 19, 19, RGB(155, 100, 0))
        StopDrawing()
      EndIf
      
      ;/Color 4
      ;  |___
      ClearScreen(RGB(0, 0, 0))
      CreateSprite(13, 60, 80)
      If StartDrawing(SpriteOutput(13))
        Box(0, 40, 19, 19, RGB(0, 200, 55))
        Box(0, 60, 19, 19, RGB(0, 200, 55))
        Box(20, 60, 19, 19, RGB(0, 200, 55))
        Box(40, 60, 19, 19, RGB(0, 200, 55))
        StopDrawing()
      EndIf
      ClearScreen(RGB(0, 0, 0))
      CreateSprite(14, 40, 80)
      If StartDrawing(SpriteOutput(14))
        Box(0, 20, 19, 19, RGB(0, 200, 55))
        Box(0, 40, 19, 19, RGB(0, 200, 55))
        Box(0, 60, 19, 19, RGB(0, 200, 55))
        Box(20, 20, 19, 19, RGB(0, 200, 55))
        StopDrawing()
      EndIf
      ClearScreen(RGB(0, 0, 0))
      CreateSprite(15, 60, 80)
      If StartDrawing(SpriteOutput(15))
        Box(0, 40, 19, 19, RGB(0, 200, 55))
        Box(20, 40, 19, 19, RGB(0, 200, 55))
        Box(40, 40, 19, 19, RGB(0, 200, 55))
        Box(40, 60, 19, 19, RGB(0, 200, 55))
        StopDrawing()
      EndIf
      ClearScreen(RGB(0, 0, 0))
      CreateSprite(16, 40, 80)
      If StartDrawing(SpriteOutput(16))
        Box(0, 60, 19, 19, RGB(0, 200, 55))
        Box(20, 20, 19, 19, RGB(0, 200, 55))
        Box(20, 40, 19, 19, RGB(0, 200, 55))
        Box(20, 60, 19, 19, RGB(0, 200, 55))
        StopDrawing()
      EndIf
      
      ;/Color 5
      ;;  __,----
      ClearScreen(RGB(0, 0, 0))
      CreateSprite(17, 40, 80)
      If StartDrawing(SpriteOutput(17))
        Box(0, 20, 19, 19, RGB(255, 100, 0))
        Box(0, 40, 19, 19, RGB(255, 100, 0))
        Box(20, 40, 19, 19, RGB(255, 100, 0))
        Box(20, 60, 19, 19, RGB(255, 100, 0))
        StopDrawing()
      EndIf
      CreateSprite(18, 60, 80)
      If StartDrawing(SpriteOutput(18))
        Box(0, 60, 19, 19, RGB(255, 100, 0))
        Box(20, 60, 19, 19, RGB(255, 100, 0))
        Box(20, 40, 19, 19, RGB(255, 100, 0))
        Box(40, 40, 19, 19, RGB(255, 100, 0))
        StopDrawing()
      EndIf
      CopySprite(17,19)
      CopySprite(18,20)
      
      ;/Color 6
      ;  ----,__
      ClearScreen(RGB(0, 0, 0))
      CreateSprite(21, 40, 80)
      If StartDrawing(SpriteOutput(21))
        Box(20, 20, 19, 19, RGB(245, 215, 55))
        Box(20, 40, 19, 19, RGB(245, 215, 55))
        Box(0, 40, 19, 19, RGB(245, 215, 55))
        Box(0, 60, 19, 19, RGB(245, 215, 55))
        StopDrawing()
      EndIf
      CreateSprite(22, 60, 80)
      If StartDrawing(SpriteOutput(22))
        Box(0, 40, 19, 19, RGB(245, 215, 55))
        Box(20, 40, 19, 19, RGB(245, 215, 55))
        Box(20, 60, 19, 19, RGB(245, 215, 55))
        Box(40, 60, 19, 19, RGB(245, 215, 55))
        StopDrawing()
      EndIf
      CopySprite(21,23)
      CopySprite(22,24)
      
      ;/Color 7
      ;   . : .
      ClearScreen(RGB(0, 0, 0))
      CreateSprite(25, 60, 80)
      If StartDrawing(SpriteOutput(25))
        Box(0, 60, 19, 19, RGB(255, 90, 145))
        Box(20, 40, 19, 19, RGB(255, 90, 145))
        Box(20, 60, 19, 19, RGB(255, 90, 145))
        Box(40, 60, 19, 19, RGB(255, 90, 145))
        StopDrawing()
      EndIf
      ClearScreen(RGB(0, 0, 0))
      CreateSprite(26, 40, 80)
      If StartDrawing(SpriteOutput(26))
        Box(0, 20, 19, 19, RGB(255, 90, 145))
        Box(0, 40, 19, 19, RGB(255, 90, 145))
        Box(0, 60, 19, 19, RGB(255, 90, 145))
        Box(20, 40, 19, 19, RGB(255, 90, 145))
        StopDrawing()
      EndIf
      ClearScreen(RGB(0, 0, 0))
      CreateSprite(27, 60, 80)
      If StartDrawing(SpriteOutput(27))
        Box(0, 40, 19, 19, RGB(255, 90, 145))
        Box(20, 40, 19, 19, RGB(255, 90, 145))
        Box(40, 40, 19, 19, RGB(255, 90, 145))
        Box(20, 60, 19, 19, RGB(255, 90, 145))
        StopDrawing()
      EndIf
      ClearScreen(RGB(0, 0, 0))
      CreateSprite(28, 40, 80)
      If StartDrawing(SpriteOutput(28))
        Box(0, 40, 19, 19, RGB(255, 90, 145))
        Box(20, 20, 19, 19, RGB(255, 90, 145))
        Box(20, 40, 19, 19, RGB(255, 90, 145))
        Box(20, 60, 19, 19, RGB(255, 90, 145))
        StopDrawing()
      EndIf
      ;-
      ;/Color 1
      ;   : :
      ClearScreen(RGB(0, 0, 0))
      CreateSprite(29, 40, 80)
      If StartDrawing(SpriteOutput(29))
        Box(0, 40, 19, 19, RGB(1, 0, 0))
        Box(20, 40, 19, 19, RGB(1, 0, 0))
        Box(0, 60, 19, 19, RGB(1, 0, 0))
        Box(20, 60, 19, 19, RGB(1, 0, 0))
        StopDrawing()
      EndIf
      CopySprite(29,30)
      CopySprite(29,31)
      CopySprite(29,32)
      
      ;/Color 2
      ;  - - - -
      ClearScreen(RGB(0, 0, 0))
      CreateSprite(33, 40, 80)
      If StartDrawing(SpriteOutput(33))
        Box(0, 0, 19, 19, RGB(1, 0, 0))
        Box(0, 20, 19, 19, RGB(1, 0, 0))
        Box(0, 40, 19, 19, RGB(1, 0, 0))
        Box(0, 60, 19, 19, RGB(1, 0, 0))
        StopDrawing()
      EndIf
      ClearScreen(RGB(0, 0, 0))
      CreateSprite(34, 80, 80)
      If StartDrawing(SpriteOutput(34))
        Box(0, 60, 19, 19, RGB(1, 0, 0))
        Box(20, 60, 19, 19, RGB(1, 0, 0))
        Box(40, 60, 19, 19, RGB(1, 0, 0))
        Box(60, 60, 19, 19, RGB(1, 0, 0))
        StopDrawing()
      EndIf
      CopySprite(33,35)
      CopySprite(34,36)
      
      ;/Color 3
      ;  ___|
      ClearScreen(RGB(0, 0, 0))
      CreateSprite(37, 60, 80)
      If StartDrawing(SpriteOutput(37))
        Box(0, 60, 19, 19, RGB(1, 0, 0))
        Box(20, 60, 19, 19, RGB(1, 0, 0))
        Box(40, 60, 19, 19, RGB(1, 0, 0))
        Box(40, 40, 19, 19, RGB(1, 0, 0))
        StopDrawing()
      EndIf
      ClearScreen(RGB(0, 0, 0))
      CreateSprite(38, 60, 80)
      If StartDrawing(SpriteOutput(38))
        Box(0, 20, 19, 19, RGB(1, 0, 0))
        Box(0, 40, 19, 19, RGB(1, 0, 0))
        Box(0, 60, 19, 19, RGB(1, 0, 0))
        Box(20, 60, 19, 19, RGB(1, 0, 0))
        StopDrawing()
      EndIf
      ClearScreen(RGB(0, 0, 0))
      CreateSprite(39, 60, 80)
      If StartDrawing(SpriteOutput(39))
        Box(0, 40, 19, 19, RGB(1, 0, 0))
        Box(20, 40, 19, 19, RGB(1, 0, 0))
        Box(40, 40, 19, 19, RGB(1, 0, 0))
        Box(0, 60, 19, 19, RGB(1, 0, 0))
        StopDrawing()
      EndIf
      ClearScreen(RGB(0, 0, 0))
      CreateSprite(40, 40, 80)
      If StartDrawing(SpriteOutput(40))
        Box(0, 20, 19, 19, RGB(1, 0, 0))
        Box(20, 20, 19, 19, RGB(1, 0, 0))
        Box(20, 40, 19, 19, RGB(1, 0, 0))
        Box(20, 60, 19, 19, RGB(1, 0, 0))
        StopDrawing()
      EndIf
      
      ;/Color 4
      ;  |___
      ClearScreen(RGB(0, 0, 0))
      CreateSprite(41, 60, 80)
      If StartDrawing(SpriteOutput(41))
        Box(0, 40, 19, 19, RGB(1, 0, 0))
        Box(0, 60, 19, 19, RGB(1, 0, 0))
        Box(20, 60, 19, 19, RGB(1, 0, 0))
        Box(40, 60, 19, 19, RGB(1, 0, 0))
        StopDrawing()
      EndIf
      ClearScreen(RGB(0, 0, 0))
      CreateSprite(42, 40, 80)
      If StartDrawing(SpriteOutput(42))
        Box(0, 20, 19, 19, RGB(1, 0, 0))
        Box(0, 40, 19, 19, RGB(1, 0, 0))
        Box(0, 60, 19, 19, RGB(1, 0, 0))
        Box(20, 20, 19, 19, RGB(1, 0, 0))
        StopDrawing()
      EndIf
      ClearScreen(RGB(0, 0, 0))
      CreateSprite(43, 60, 80)
      If StartDrawing(SpriteOutput(43))
        Box(0, 40, 19, 19, RGB(1, 0, 0))
        Box(20, 40, 19, 19, RGB(1, 0, 0))
        Box(40, 40, 19, 19, RGB(1, 0, 0))
        Box(40, 60, 19, 19, RGB(1, 0, 0))
        StopDrawing()
      EndIf
      ClearScreen(RGB(0, 0, 0))
      CreateSprite(44, 40, 80)
      If StartDrawing(SpriteOutput(44))
        Box(0, 60, 19, 19, RGB(1, 0, 0))
        Box(20, 20, 19, 19, RGB(1, 0, 0))
        Box(20, 40, 19, 19, RGB(1, 0, 0))
        Box(20, 60, 19, 19, RGB(1, 0, 0))
        StopDrawing()
      EndIf
      
      ;/Color 5
      ;;  __,----
      ClearScreen(RGB(0, 0, 0))
      CreateSprite(45, 40, 80)
      If StartDrawing(SpriteOutput(45))
        Box(0, 20, 19, 19, RGB(1, 0, 0))
        Box(0, 40, 19, 19, RGB(1, 0, 0))
        Box(20, 40, 19, 19, RGB(1, 0, 0))
        Box(20, 60, 19, 19, RGB(1, 0, 0))
        StopDrawing()
      EndIf
      ClearScreen(RGB(0, 0, 0))
      CreateSprite(46, 60, 80)
      If StartDrawing(SpriteOutput(46))
        Box(0, 60, 19, 19, RGB(1, 0, 0))
        Box(20, 60, 19, 19, RGB(1, 0, 0))
        Box(20, 40, 19, 19, RGB(1, 0, 0))
        Box(40, 40, 19, 19, RGB(1, 0, 0))
        StopDrawing()
      EndIf
      CopySprite(45,47)
      CopySprite(46,48)
      
      ;/Color 6
      ;  ----,__
      ClearScreen(RGB(0, 0, 0))
      CreateSprite(49, 40, 80)
      If StartDrawing(SpriteOutput(49))
        Box(20, 20, 19, 19, RGB(1, 0, 0))
        Box(20, 40, 19, 19, RGB(1, 0, 0))
        Box(0, 40, 19, 19, RGB(1, 0, 0))
        Box(0, 60, 19, 19, RGB(1, 0, 0))
        StopDrawing()
      EndIf
      ClearScreen(RGB(0, 0, 0))
      CreateSprite(50, 60, 80)
      If StartDrawing(SpriteOutput(50))
        Box(0, 40, 19, 19, RGB(1, 0, 0))
        Box(20, 40, 19, 19, RGB(1, 0, 0))
        Box(20, 60, 19, 19, RGB(1, 0, 0))
        Box(40, 60, 19, 19, RGB(1, 0, 0))
        StopDrawing()
      EndIf
      CopySprite(49,51)
      CopySprite(50,52)
      
      ;/Color 7
      ;   . : .
      ClearScreen(RGB(0, 0, 0))
      CreateSprite(53, 60, 80)
      If StartDrawing(SpriteOutput(53))
        Box(0, 60, 19, 19, RGB(1, 0, 0))
        Box(20, 40, 19, 19, RGB(1, 0, 0))
        Box(20, 60, 19, 19, RGB(1, 0, 0))
        Box(40, 60, 19, 19, RGB(1, 0, 0))
        StopDrawing()
      EndIf
      ClearScreen(RGB(0, 0, 0))
      CreateSprite(54, 40, 80)
      If StartDrawing(SpriteOutput(54))
        Box(0, 20, 19, 19, RGB(1, 0, 0))
        Box(0, 40, 19, 19, RGB(1, 0, 0))
        Box(0, 60, 19, 19, RGB(1, 0, 0))
        Box(20, 40, 19, 19, RGB(1, 0, 0))
        StopDrawing()
      EndIf
      ClearScreen(RGB(0, 0, 0))
      CreateSprite(55, 60, 80)
      If StartDrawing(SpriteOutput(55))
        Box(0, 40, 19, 19, RGB(1, 0, 0))
        Box(20, 40, 19, 19, RGB(1, 0, 0))
        Box(40, 40, 19, 19, RGB(1, 0, 0))
        Box(20, 60, 19, 19, RGB(1, 0, 0))
        StopDrawing()
      EndIf
      ClearScreen(RGB(0, 0, 0))
      CreateSprite(56, 40, 80)
      If StartDrawing(SpriteOutput(56))
        Box(0, 40, 19, 19, RGB(1, 0, 0))
        Box(20, 20, 19, 19, RGB(1, 0, 0))
        Box(20, 40, 19, 19, RGB(1, 0, 0))
        Box(20, 60, 19, 19, RGB(1, 0, 0))
        StopDrawing()
      EndIf
      ;/
      ClearScreen(RGB(0, 0, 0))
      CreateSprite(57, 159, 440)
      If StartDrawing(SpriteOutput(57))
        Box(0, 0, 159, 440, RGB(1, 0, 0))
        StopDrawing()
      EndIf
      SetGadgetText(1, "Your score is:")
    Else
      MessageRequester("Error", "Can't open windowed screen!", 0)
      End
    EndIf
  EndIf
EndProcedure
Procedure setup()
  For x = 0 To 20
    For y = 0 To 43
      l(x,y) = 0   ; Clear L() Array
    Next
  Next
  bR.i = 1
  bL.i = 1
  bH.i = 1
  x = 101
  y.i = 11
  score=0
  speed=1500
  ; Print At(15,22);"Press:  Esc to quit,  N to start new game,  Space to pause"
  ; Print At(22,24);"Use arrows for left/right/rotate,  Enter to drop"
  ClearScreen(RGB(0, 0, 0))
  ; 0, 0, 262, 443, RGB(255, 0, 0)
  For r.i = 0 To 9
    a$ = Right(Str(ElapsedMilliseconds()),2)
    n.w = Val(a$) + Random(144)
    n.w = n.w % 7
    r.i(r.i) = n.w + 1
    l(r.i,23) = 1
    DisplayTransparentSprite(0, 99 + 16 * r, 29, 255)    ;Draw New Sprite
    DisplayTransparentSprite(0, 99 + 16 * r, 453, 255)    ;Draw New Sprite
    ; FlipBuffers()
  Next r.i
  For bH.i = 0 To 43
    DisplayTransparentSprite(0, 99, 9.8*bH+29, 255)    ;Draw New Sprite
    DisplayTransparentSprite(0, 243, 9.8*bH+29, 255)    ;Draw New Sprite
    l(0, bH.i) = 1
    l(9, bH.i) = 1
  Next bH.i
  DisplayTransparentSprite(57, 101, 31, 255)    ;Draw New Sprite
  Shape.i = (bN.i-1)*4
  Shape.i = (r.i(9))*4 -3
  DisplayTransparentSprite(Shape, 10, 200, 255)    ;Draw New Sprite
  FlipBuffers()
  Delay(10)
  WaitWindowEvent(20)
  Repeat
    Event = WindowEvent()
  Until Event=0
  answer.i = MessageRequester("  Choose difficulty ","      Are you still a beginner?",#PB_MessageRequester_YesNo)
  If answer = #PB_MessageRequester_No
    SetGadgetText(9,"I'm An Expert")
  Else
    beginner = #True
    SetGadgetText(9,"Learning Mode")
  EndIf
  SetGadgetText(3, "Beat your score!")
  grabNext4()
  ;;;
  ;SetGadgetText(1, Str(shape))
  ;;;
EndProcedure
Procedure randomizeRarray()
  A$ = Right(Str(ElapsedMilliseconds()),2)
  n.w = Val(A$) + Random(160)
  n.w = n.w % 7
  R.i(9) = R.i(8)
  R.i(8) = R.i(7)
  R.i(7) = R.i(6)
  R.i(6) = R.i(5)
  R.i(5) = R.i(4)
  R.i(4) = R.i(3)
  R.i(3) = R.i(2)
  R.i(2) = R.i(1)
  R.i(1) = R.i(0)
  R.i(0) = n.w + 1
EndProcedure
Procedure grabNext4()
  bN.i = R.i(9)
  bR.i = 1
  bL.i = 1
  bH.i = 1
  x = 101
  y.i = 31
  t.i = 0
  For x1 = 1 To 4
    For y1.i = 1 To 4
      If (Lb(bN.i,x1,y1.i,bR.i) & L(bL.i - 1 + x1,bH.i - 1 + y1.i)) = 1
        t.i = 1
      EndIf
    Next y1.i
  Next x1
  If t.i
    SetGadgetText(2, Str(score))
    SetGadgetText(3, "GAME OVER")
    Delay(2000)
    ; Print At(48,0);
    Result = MessageRequester(" That was fun!","Start a new game?",#PB_MessageRequester_YesNo)
    scoreB4 = score
    If Result = #PB_MessageRequester_Yes
      setup()
      SetGadgetText(4, Str(scoreB4))
    Else
      End
    EndIf
  Else
    ;;;
    Shape.i = (r.i(9))*4 -3
    DisplayTransparentSprite(Shape+28, 10, 200, 255)       ;Draw New Sprite
    ; FlipBuffers()
    ;;;
    Shape.i = (r.i(8))*4 -3
    DisplayTransparentSprite(Shape, 10, 200, 255)    ;Coming New Sprite
    ; FlipBuffers()
    ;;;
    Shape.i = (r.i(9))*4 -3
    DisplayTransparentSprite(Shape, x, y, 255)       ;Draw New Sprite
    FlipBuffers()
    ;;;
    randomizeRarray()
    If beginner.i = #True
      speed = speed*0.998
    Else
      speed = speed*0.988
    EndIf
    wait=ElapsedMilliseconds()+speed
    SetGadgetText(2, Str(score))
    Select score
      Case 1000 To 4999
        SetGadgetText(3, "Great start!")
      Case 5000 To 7999 
        SetGadgetText(3, "Savy player!")
      Case 8000 To 9999
        SetGadgetText(3, "All warmed up!")
      Case 10000 To 11999
        SetGadgetText(3, "Cranking it!")
      Case 12000 To 200000
        SetGadgetText(3, "Digi brain!!")
    EndSelect
  EndIf
  ;t.i=1
EndProcedure
Procedure shiftLeft()
  t.i = 0
  For x1 = 1 To 4
    For y1.i = 1 To 4
      If (Lb(bN.i,x1,y1.i,bR.i) & L(bL.i - 2 + x1,bH.i - 1 + y1.i)) = 1
        t.i = 1
      EndIf
    Next y1.i
  Next x1
  If t.i = 0
    ;;;
    shape.i = (bN.i-1)*4 + bR.i
    DisplayTransparentSprite(Shape+28, x, y, 255) ;Clear current sprite
    bL.i - 1
    x - 20
    DisplayTransparentSprite(Shape, x, y, 255)    ;Draw New Sprite
    FlipBuffers()
    ;;;
  EndIf
EndProcedure
Procedure rotate()
  t.i = 0
  bX.i = bR.i + 1
  If bX.i = 5
    bX.i = 1
  EndIf
  For x1 = 1 To 4
    For y1.i = 1 To 4
      If (Lb(bN.i,x1,y1.i,bX.i) & L(bL.i - 1 + x1,bH.i - 1 + y1.i)) = 1
        t.i = 1
      EndIf
    Next y1.i
  Next x1
  If t.i = 0
    ;;;
    shape.i = (R.i(9))*4 -3
    shape.i = (bN.i-1)*4 + bR.i
    DisplayTransparentSprite(Shape+28, x, y, 255) ;Clear current sprite
    bR.i = bX.i
    shape.i = (bN.i-1)*4 + bR.i
    DisplayTransparentSprite(Shape, x, y, 255)    ;Draw New Sprite
    FlipBuffers()
    ;;;
  EndIf
EndProcedure
Procedure shiftRight()
  t.i = 0
  For x1 = 1 To 4
    For y1.i = 1 To 4
      If (Lb(bN.i,x1,y1.i,bR.i) & L(bL.i + x1,bH.i - 1 + y1.i)) = 1
        t.i = 1
      EndIf
    Next y1.i
  Next x1
  If t.i = 0
    ;;;
    shape.i = (bN.i-1)*4 + bR.i
    DisplayTransparentSprite(Shape+28, x, y, 255) ;Clear current sprite
    bL.i + 1
    x + 20
    DisplayTransparentSprite(Shape, x, y, 255)    ;Draw New Sprite
    FlipBuffers()
    ;;;
  EndIf
EndProcedure
Procedure flash()
  For bJ.i=4 To 1 Step -1
    If t.i(bJ.i)
      score + 10
      For bX = 1 To 4
        GrabSprite(58,101,411,160,20)
        For c.i=1 To 4
          FlipBuffers()
          DisplayTransparentSprite(0, 81+c*20, (bH.i+3)*20+11 , 255)    ;Draw New Sprite
          DisplayTransparentSprite(0, 101+(8-c)*20, (bH.i+3)*20+11 , 255)    ;Draw New Sprite
          FlipBuffers()
          Delay(5)
        Next c.i
        DisplayTransparentSprite(58, 101, (bH.i+3)*20+11 , 255)    ;Draw New Sprite
        FlipBuffers()
        FreeSprite(58)
      Next bX
      If sfx And scard
        PlaySound(4)
      EndIf
      Delay(25)
      For c.i = bH + 3 To 3 Step -1
        For x1=1 To 8
          L(x1,c)=L(x1,c-1)
          L(x1,c-1)=0
        Next x1
      Next c.i
      GrabSprite(58, 101, 31, 160, (bH.i+3)*20-21)
      DisplayTransparentSprite(58, 101, 51, 255)    ;Draw New Sprite
      FlipBuffers()
      FreeSprite(58)
    Else
      bH.i - 1
    EndIf
  Next bJ.i
EndProcedure
Procedure checkRow()
  T.i(0) = 0
  T.i(1) = 0
  T.i(2) = 0
  T.i(3) = 0
  T.i(4) = 0
  For y1.i = 1 To 4
    If l(1,bH.i - 1 + y1.i) & l(2,bH.i - 1 + y1.i) = 1
      If l(3,bH.i - 1 + y1.i) & l(4,bH.i - 1 + y1.i) = 1
        If l(5,bH.i - 1 + y1.i) & l(6,bH.i - 1 + y1.i) = 1
          If l(7,bH.i - 1 + y1.i) & l(8,bH.i - 1 + y1.i) = 1
            t.i(y1.i) = 1    ;;  track Rows that are full
          EndIf
        EndIf
      EndIf
    EndIf
  Next
  flash()
EndProcedure
Procedure drop()
  t.i = 0
  settled.i = 0
  For x1 = 1 To 4
    For y1.i = 1 To 4
      If (Lb(bN.i,x1, y1.i,bR.i) & l(bL.i - 1 + x1, bH.i + y1.i)) = 1
        t.i = 1    ;;   Flag it unable To drop.
      EndIf
    Next y1.i
  Next x1
  If t.i          ;;      unable To drop
    For x1 = 1 To 4
      For y1.i = 1 To 4
        If Lb(bN.i, x1, y1.i, bR.i) & 1
          l(bL.i - 1 + x1, bH.i - 1 + y1.i) = 1
          settled.i = 1
        EndIf
      Next y1.i
    Next x1
    ;;;
    checkRow()
    grabNext4()
    FlipBuffers()
  Else    ;;    Able To drop
    ;;;
    If settled.i = 0
      score + 1
      Shape.i = (bN.i-1)*4 + bR.i
      DisplayTransparentSprite(Shape+28, x, y, 255) ;Clear current sprite
      ; FlipBuffers()
      bH.i + 1
      y + 20
      DisplayTransparentSprite(Shape, x, y, 255)    ;Draw New Sprite
      FlipBuffers()
      If sfx And scard
        PlaySound(0)
      EndIf
      SetGadgetText(2, Str(score))
    EndIf
    ;;;
  EndIf
EndProcedure
Procedure userInputLoop()
  t.i = 0
  wait=ElapsedMilliseconds()+speed
  Repeat
    key = 0
    Repeat
      Event = WindowEvent() : _wParam=EventwParam() : _lParam=EventlParam()
      Select Event
        Case #WM_KEYDOWN      ;-  KEYBOARD  ACTION
          Select _wParam
            Case #VK_LEFT          ;/ < GO Left<<<<
              shiftLeft()
              If sfx And scard
                PlaySound(1)
              EndIf
            Case #VK_UP, #VK_DOWN  ;/    /\Rotate\/
              rotate()
              If sfx And scard
                PlaySound(1)
              EndIf
            Case #VK_RIGHT         ;/    >>>>GO Right >
              shiftRight()
              If sfx And scard
                PlaySound(1)
              EndIf
            Case #VK_RETURN   ;       \ || /
              score + 10
              Repeat               ;/       Drop
                drop();                 \/
              Until settled.i = 1
              settled.i = 0
            Case #VK_ESCAPE        ;/    Escape to Quit
              ; Print At(48,0);
              ;Input "Quit Game Now? y/N ";A$
              result = MessageRequester(" That was fun!","Time to quit already?",#PB_MessageRequester_YesNo)
              If result = #PB_MessageRequester_Yes
                End
              EndIf
              wait=ElapsedMilliseconds()+speed
              ;
            Case #VK_SPACE         ;/     Pause To Pee
              If sfx And scard
                PlaySound(5)
              EndIf
              result = MessageRequester(" Pee break!   ^_^","Spacebar to continue...",#PB_MessageRequester_Ok)
              wait=ElapsedMilliseconds()+speed
              If sfx And scard
                PlaySound(6)
              EndIf
          EndSelect
        Case #PB_Event_Gadget  ;-  BUTTON  ACTION
          Select EventGadget()
            Case 0
              End
            Case 10
              If sfx
                sfx = #False
                SetGadgetText(10,"Silent Mode")
              Else
                sfx = #True
                SetGadgetText(10,"Sound On")
              EndIf
          EndSelect
        Case #PB_Event_CloseWindow
          End 
      EndSelect
    Until Event = 0
    Tick=ElapsedMilliseconds()
    If Tick >wait
      wait + speed
      drop()
      FlipBuffers()
    EndIf
    Delay(1)
  ForEver
EndProcedure
;-PROGRAM STARTS HERE
pretest()
init_draw()
init_logic()
setup()
userInputLoop()
End

; IDE Options = PureBasic 6.12 LTS (Windows - x64)
; CursorPosition = 568
; FirstLine = 561
; Folding = ---
; EnableXP
; EOF
; DontSaveDeclare
; Build=0
Last edited by Randy Walker on Tue Feb 11, 2025 7:04 am, edited 2 times in total.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
SMaag
Enthusiast
Enthusiast
Posts: 327
Joined: Sat Jan 14, 2023 6:55 pm
Location: Bavaria/Germany

Re: How did 6.12 break it?

Post by SMaag »

I tested on:
- PB5.45! O.k.!
. PB 6.12, 6.20! Not

It's hard to say what's the problem but I guess the problem is in your code and it was working by chance in older PB.

I expect the source of the problems is your excessive use of FlipBuffers().
Normaly you should have a seperate drawing routine for the screen.
The way how to do:
1. clear the screen
2. redraw the complete screen
3. do the FlipBuffers()
Repeat 1..3

At your code you can't be sure what's in the 2 DrawingBuffers() and it's not possible to debug it!

I guess there was a different behavior in older PB (a not 100% correct one) and now in newer PB it works correct!
Fred
Administrator
Administrator
Posts: 18350
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: How did 6.12 break it?

Post by Fred »

There is so much '.l' that it's probably the cause
SMaag
Enthusiast
Enthusiast
Posts: 327
Joined: Sat Jan 14, 2023 6:55 pm
Location: Bavaria/Germany

Re: How did 6.12 break it?

Post by SMaag »

I changed all .l to .i and it's same problem.

A futher analyze of the pgramm:
ClearSecreen(0) is only used in inti_draw() what's called only once
and in setup() what's called sometimes.

I'm nearly sure it is a problem of the software architecure what is hard to analyze and debug!

The drawing looks like there are older not completely cleard sprites in the Buffers() and this
would be exactly the problem of the uncontrolled use of FlipBuffers()
SMaag
Enthusiast
Enthusiast
Posts: 327
Joined: Sat Jan 14, 2023 6:55 pm
Location: Bavaria/Germany

Re: How did 6.12 break it?

Post by SMaag »

Code: Select all

Procedure shiftLeft()
  t.i = 0
  For x1 = 1 To 4
    For y1.i = 1 To 4
      If (Lb(bN.i,x1,y1.i,bR.i) & L(bL.i - 2 + x1,bH.i - 1 + y1.i)) = 1
        t.i = 1
      EndIf
    Next y1.i
  Next x1
  If t.i = 0
    ;;;
    shape.i = (bN.i-1)*4 + bR.i
    DisplayTransparentSprite(Shape+28, x, y, 255) ;Clear current sprite
    bL.i - 1
    x - 20
    DisplayTransparentSprite(Shape, x, y, 255)    ;Draw New Sprite
    FlipBuffers()
    ;;;
  EndIf
EndProcedure

; This clears the current Sprite in the Background Buffer but not in the displayed Buffer
DisplayTransparentSprite(Shape+28, x, y, 255) ;Clear current sprite

; This draws a new Sprite in the Backgorund Buffer
DisplayTransparentSprite(Shape, x, y, 255) ;Draw New Sprite

FlipBuffers()
; Now the 2 Buffers are exchanged and you get the the Sprite what you are cleard before back in the Background Buffer because you can't
; clear anything in the actual displayed Buffer.

I guess older PB cleard the background Buffer when calling FlipBuffers()
breeze4me
Enthusiast
Enthusiast
Posts: 633
Joined: Thu Mar 09, 2006 9:24 am
Location: S. Kor

Re: How did 6.12 break it?

Post by breeze4me »

If you set the 'Library Subsystem' to 'directx9', it will run fine in PB 6.20.
(Tested with PB 6.20 b4 x64 on Windows 10)
SMaag
Enthusiast
Enthusiast
Posts: 327
Joined: Sat Jan 14, 2023 6:55 pm
Location: Bavaria/Germany

Re: How did 6.12 break it?

Post by SMaag »

Here is a workarround for the FlipBuffers()!
The problem is: In older PB or directX the FlipBuffers() Function is a CopyBuffer().
In newer Version it's a real FlipBuffers() where only the Pointers are exchanged - that's much faster but you have to redraw your complete screen!

So I simulated the the older FlipBuffers() with the copy and it runs perfect.
But generally the problem of randys code is the wrong use of FlipBuffers()

here the new Code

Code: Select all

; Author: Randy Walker (updated for PB 4.00)
; Date: January 2010
; OS: Windows
; Demo: Yes

Procedure SimulateOldPBFlipBuffers()
  Protected *buf, *cpy
  Protected w=280, h=502, bytes, PixelSize
  
  StartDrawing(ScreenOutput())
  *buf = DrawingBuffer()
  Debug "*buf = " + *buf
  If *buf
    
    Select DrawingBufferPixelFormat()&$FF
      Case  #PB_PixelFormat_16Bits      
        PixelSize = 2
      Case #PB_PixelFormat_24Bits_RGB, #PB_PixelFormat_24Bits_BGR   
        PixelSize = 3
      Case #PB_PixelFormat_32Bits_RGB, #PB_PixelFormat_32Bits_BGR   
        PixelSize = 4
    EndSelect
    
    w = ScreenWidth()
    h = ScreenHeight()
    Debug "ScreenWidth = " + w
    Debug "ScreenHeight = " + h
    Debug "PixelSize = " + PixelSize
    
    bytes = w*h*PixelSize
    *cpy = AllocateMemory(bytes)
    CopyMemory(*buf, *cpy, bytes)
    StopDrawing()
    
    FlipBuffers()
    StartDrawing(ScreenOutput())
    *buf = DrawingBuffer()
    CopyMemory(*cpy, *buf, bytes)
    StopDrawing()
  EndIf

  FreeMemory(*cpy)
EndProcedure


; Macro SimulateOldPBFlipBuffers()
;   FlipBuffers()
; EndMacro

Macro mac_ClearScreen(ColorValue)
  ClearScreen(ColorValue)
EndMacro

#NearlyBlack = 1

Procedure pretest()
  If InitSprite() = 0
    MessageRequester("Error", "Can't open screen & sprite enviroment!", 0)
    End
  EndIf
  Global scard.i, sfx.i
  sfx.i = #True
  If InitSound() = 0
    MessageRequester("Error", "Can't open DirectX 7 or no sound card is available",  0)
    scard.i = #False
    sfx.i = #False
  EndIf
  If sfx = #True
    scard.i = #True
    ;Stepdown
    If LoadSound(0, "C:\WINDOWS\Media\Windows XP Menu Command.wav")
    Else
      Debug "missed 0"
      scard.i = #False
      sfx.i = #False
    EndIf
    ;Left / Right
    If LoadSound(1, "C:\WINDOWS\Media\Windows XP Start.wav")
    Else
      Debug "missed 1"
      scard.i = #False
      sfx.i = #False
    EndIf
    ;Rotate
    If LoadSound(2, "C:\WINDOWS\Media\Windows XP Start.wav")
    Else
      Debug "missed 2"
      scard.i = #False
      sfx.i = #False
    EndIf
    ;Drop
    If LoadSound(3, "C:\WINDOWS\Media\Windows XP Minimize.wav")
    Else
      Debug "missed 3"
      scard.i = #False
      sfx.i = #False
    EndIf
    ;Score
    If LoadSound(4, "C:\WINDOWS\Media\Windows XP Hardware Fail.wav")
    Else
      Debug "missed 4"
      scard.i = #False
      sfx.i = #False
    EndIf
    ;Pee break
    If LoadSound(5, "C:\WINDOWS\Media\Windows XP Hardware Remove.wav")
    Else
      Debug "missed 5"
      scard.i = #False
      sfx.i = #False
    EndIf
    ;Pee return
    If LoadSound(6, "C:\WINDOWS\Media\Windows XP Hardware Insert.wav")
    Else
      Debug "missed 6"
      scard.i = #False
      sfx.i = #False
    EndIf
    If sfx = #False
      MessageRequester("Error", "One or more Windows XP sound files is missing.",  0)
    EndIf
  EndIf
EndProcedure
Procedure initdata()
  DataSection
  ;;           ;;  FFFFFFFFFFF
  Data.w 5,45
  Data.w 5,60
  Data.w 5,75
  Data.w 5,90
  Data.w 5,105
  Data.w 5,120
  Data.w 5,135
  Data.w 5,150
  Data.w 5,165
  Data.w 20,45
  Data.w 35,45
  Data.w 50,45
  Data.w 65,45
  Data.w 20,105
  Data.w 35,105
  Data.w 50,105
  ;;          ;;  OOOOOOOOOOO
  Data.w 105,45
  Data.w 105,60
  Data.w 105,75
  Data.w 105,90
  Data.w 105,105
  Data.w 105,120
  Data.w 105,135
  Data.w 105,150
  Data.w 105,165
  Data.w 120,45
  Data.w 135,45
  Data.w 150,45
  Data.w 105,165
  Data.w 120,165
  Data.w 135,165
  Data.w 150,165
  Data.w 165,45
  Data.w 165,60
  Data.w 165,75
  Data.w 165,90
  Data.w 165,105
  Data.w 165,120
  Data.w 165,135
  Data.w 165,150
  Data.w 165,165
  ;;          ;;  UUUUUUUUUUU
  Data.w 205,45
  Data.w 205,60
  Data.w 205,75
  Data.w 205,90
  Data.w 205,105
  Data.w 205,120
  Data.w 205,135
  Data.w 205,150
  Data.w 205,165
  Data.w 205,165
  Data.w 220,165
  Data.w 235,165
  Data.w 250,165
  Data.w 265,45
  Data.w 265,60
  Data.w 265,75
  Data.w 265,90
  Data.w 265,105
  Data.w 265,120
  Data.w 265,135
  Data.w 265,150
  Data.w 265,165
  ;;          ;;   RRRRRRRRRR
  Data.w 305,45
  Data.w 305,60
  Data.w 305,75
  Data.w 305,90
  Data.w 305,105
  Data.w 305,120
  Data.w 305,135
  Data.w 305,150
  Data.w 305,165
  Data.w 320,45
  Data.w 335,45
  Data.w 350,45
  Data.w 350,60
  Data.w 350,90
  Data.w 320,105
  Data.w 335,105
  Data.w 350,105
  Data.w 365,60
  Data.w 365,75
  Data.w 365,90
  Data.w 335,120
  Data.w 335,135
  Data.w 350,135
  Data.w 350,150
  Data.w 365,150
  Data.w 365,165
  ;;              ;;   SSSSSSSSSSSS
  Data.w 420,45
  Data.w 420,60
  Data.w 405,60
  Data.w 405,75
  Data.w 405,90
  Data.w 420,90
  Data.w 435,45
  Data.w 450,45
  Data.w 450,60
  Data.w 465,60
  Data.w 465,75
  Data.w 435,90
  Data.w 435,105
  ;;Data 435,120
  Data.w 450,105
  Data.w 450,120
  Data.w 465,120
  Data.w 465,135
  Data.w 465,150
  Data.w 405,135
  Data.w 405,150
  Data.w 420,150
  Data.w 420,165
  Data.w 435,165
  Data.w 450,165
  Data.w 450,150
  ;;              ;;   KKKKKKKKKKKKKKK
  Data.w 505,45
  Data.w 505,60
  Data.w 505,75
  Data.w 505,90
  Data.w 520,90
  Data.w 520,105
  Data.w 550,60
  Data.w 550,75
  Data.w 535,75
  Data.w 535,90
  Data.w 535,105
  Data.w 535,120
  Data.w 550,120
  Data.w 550,135
  Data.w 550,150
  Data.w 565,150
  Data.w 565,165
  Data.w 505,105
  Data.w 505,120
  Data.w 505,135
  Data.w 505,150
  Data.w 505,165
  ;;              ;;   IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
  Data.w 605,45
  Data.w 605,60
  Data.w 605,75
  Data.w 605,90
  Data.w 605,105
  Data.w 605,120
  Data.w 605,135
  Data.w 605,150
  Data.w 605,165
  ;;              ;;   ++++++++++++
  Data.w  395,225
  Data.w  410,225
  Data.w 410,210
  Data.w 410,240
  Data.w 425,225
  EndDataSection
EndProcedure

Procedure SetGlobals()
  Global T.i, settled.i
  Global k.i, GameBoard.i
  Global l.i, beginner.i
  Global r.i
  Global d.i
  Global bN.i
  Global bR.i
  Global bL.i
  Global bH.i
  Global A$
  Global Pb$
  Global c.i
  Global x.i
  Global x1.i
  Global y.i
  Global y1.i
  Global score.i
  Global speed.i
  Global key.i
  Global wait.i
  Global Shape.i
  ;;  bN.i-block#, bR.i-block rotation, bL.i-block latitude, bH.i-block height
  ;;    lb|( type, x, y, rotation )
  Global Dim l.i(20,43)
  Global Dim Lb.i(7,4,4,4)
  Global Dim Pb$(7,4)
  Global Dim r.i(9)
  Global Dim T.i(4)
EndProcedure
SetGlobals()
Declare grabNext4()

Procedure Original_init_logic()
  ;;___________________________________________
  Lb(1,1,3,1) = 1   ;;  : :      Clockwise rotation
  Lb(1,2,3,1) = 1
  Lb(1,1,4,1) = 1
  Lb(1,2,4,1) = 1
  
  Lb(1,1,3,2) = 1
  Lb(1,2,3,2) = 1
  Lb(1,1,4,2) = 1
  Lb(1,2,4,2) = 1
  
  Lb(1,1,3,3) = 1
  Lb(1,2,3,3) = 1
  Lb(1,1,4,3) = 1
  Lb(1,2,4,3) = 1
  
  Lb(1,1,3,4) = 1
  Lb(1,2,3,4) = 1
  Lb(1,1,4,4) = 1
  Lb(1,2,4,4) = 1
  
  ;;___________________________________________
  Lb(2,1,4,1) = 1   ;;  - - - -
  Lb(2,2,4,1) = 1
  Lb(2,3,4,1) = 1
  Lb(2,4,4,1) = 1
  
  Lb(2,1,1,2) = 1
  Lb(2,1,2,2) = 1
  Lb(2,1,3,2) = 1
  Lb(2,1,4,2) = 1
  
  Lb(2,1,4,3) = 1
  Lb(2,2,4,3) = 1
  Lb(2,3,4,3) = 1
  Lb(2,4,4,3) = 1
  
  Lb(2,1,1,4) = 1
  Lb(2,1,2,4) = 1
  Lb(2,1,3,4) = 1
  Lb(2,1,4,4) = 1
  
  ;;___________________________________________
  Lb(3,1,4,1) = 1   ;;  ___|
  Lb(3,2,4,1) = 1
  Lb(3,3,4,1) = 1
  Lb(3,3,3,1) = 1
  
  Lb(3,2,4,2) = 1
  Lb(3,1,4,2) = 1
  Lb(3,1,3,2) = 1
  Lb(3,1,2,2) = 1
  
  Lb(3,1,4,3) = 1
  Lb(3,1,3,3) = 1
  Lb(3,2,3,3) = 1
  Lb(3,3,3,3) = 1
  
  Lb(3,1,2,4) = 1
  Lb(3,2,2,4) = 1
  Lb(3,2,3,4) = 1
  Lb(3,2,4,4) = 1
  
  ;;___________________________________________
  Lb(4,1,3,1) = 1   ;;  |___
  Lb(4,1,4,1) = 1
  Lb(4,2,4,1) = 1
  Lb(4,3,4,1) = 1
  
  Lb(4,2,2,2) = 1
  Lb(4,1,2,2) = 1
  Lb(4,1,3,2) = 1
  Lb(4,1,4,2) = 1
  
  Lb(4,1,3,3) = 1
  Lb(4,2,3,3) = 1
  Lb(4,3,3,3) = 1
  Lb(4,3,4,3) = 1
  
  Lb(4,1,4,4) = 1
  Lb(4,2,4,4) = 1
  Lb(4,2,3,4) = 1
  Lb(4,2,2,4) = 1
  
  ;;___________________________________________
  Lb(5,1,4,1) = 1   ;;  __,----
  Lb(5,2,4,1) = 1
  Lb(5,2,3,1) = 1
  Lb(5,3,3,1) = 1
  
  Lb(5,1,2,2) = 1
  Lb(5,1,3,2) = 1
  Lb(5,2,3,2) = 1
  Lb(5,2,4,2) = 1
  
  Lb(5,1,4,3) = 1
  Lb(5,2,4,3) = 1
  Lb(5,2,3,3) = 1
  Lb(5,3,3,3) = 1
  
  Lb(5,1,2,4) = 1
  Lb(5,1,3,4) = 1
  Lb(5,2,3,4) = 1
  Lb(5,2,4,4) = 1
  
  ;;___________________________________________
  Lb(6,1,3,1) = 1   ;;  ----,__
  Lb(6,2,3,1) = 1
  Lb(6,2,4,1) = 1
  Lb(6,3,4,1) = 1
  
  Lb(6,2,2,2) = 1
  Lb(6,2,3,2) = 1
  Lb(6,1,3,2) = 1
  Lb(6,1,4,2) = 1
  
  Lb(6,1,3,3) = 1
  Lb(6,2,3,3) = 1
  Lb(6,2,4,3) = 1
  Lb(6,3,4,3) = 1
  
  Lb(6,2,2,4) = 1
  Lb(6,2,3,4) = 1
  Lb(6,1,3,4) = 1
  Lb(6,1,4,4) = 1
  ;;___________________________________________
  Lb(7,1,4,1) = 1   ;;       . : .
  Lb(7,2,4,1) = 1
  Lb(7,2,3,1) = 1
  Lb(7,3,4,1) = 1
  
  Lb(7,1,2,2) = 1
  Lb(7,1,3,2) = 1
  Lb(7,2,3,2) = 1
  Lb(7,1,4,2) = 1
  
  Lb(7,1,3,3) = 1
  Lb(7,2,3,3) = 1
  Lb(7,2,4,3) = 1
  Lb(7,3,3,3) = 1
  
  Lb(7,2,2,4) = 1
  Lb(7,1,3,4) = 1
  Lb(7,2,3,4) = 1
  Lb(7,2,4,4) = 1
EndProcedure
Procedure init_logic()
  ;;___________________________________________
  Lb(1,1,3,1) = 1   ;;  : :      Clockwise rotation
  Lb(1,2,3,1) = 1
  Lb(1,1,4,1) = 1
  Lb(1,2,4,1) = 1
  
  Lb(1,1,3,2) = 1
  Lb(1,2,3,2) = 1
  Lb(1,1,4,2) = 1
  Lb(1,2,4,2) = 1
  
  Lb(1,1,3,3) = 1
  Lb(1,2,3,3) = 1
  Lb(1,1,4,3) = 1
  Lb(1,2,4,3) = 1
  
  Lb(1,1,3,4) = 1
  Lb(1,2,3,4) = 1
  Lb(1,1,4,4) = 1
  Lb(1,2,4,4) = 1
  
  ;;___________________________________________
  Lb(2,1,1,1) = 1
  Lb(2,1,2,1) = 1
  Lb(2,1,3,1) = 1
  Lb(2,1,4,1) = 1
  
  Lb(2,1,4,2) = 1   ;;  - - - -
  Lb(2,2,4,2) = 1
  Lb(2,3,4,2) = 1
  Lb(2,4,4,2) = 1
  
  Lb(2,1,1,3) = 1
  Lb(2,1,2,3) = 1
  Lb(2,1,3,3) = 1
  Lb(2,1,4,3) = 1
  
  Lb(2,1,4,4) = 1
  Lb(2,2,4,4) = 1
  Lb(2,3,4,4) = 1
  Lb(2,4,4,4) = 1
  
  ;;___________________________________________
  Lb(3,1,4,1) = 1   ;;  ___|
  Lb(3,2,4,1) = 1
  Lb(3,3,4,1) = 1
  Lb(3,3,3,1) = 1
  
  Lb(3,2,4,2) = 1
  Lb(3,1,4,2) = 1
  Lb(3,1,3,2) = 1
  Lb(3,1,2,2) = 1
  
  Lb(3,1,4,3) = 1
  Lb(3,1,3,3) = 1
  Lb(3,2,3,3) = 1
  Lb(3,3,3,3) = 1
  
  Lb(3,1,2,4) = 1
  Lb(3,2,2,4) = 1
  Lb(3,2,3,4) = 1
  Lb(3,2,4,4) = 1
  
  ;;___________________________________________
  Lb(4,1,3,1) = 1   ;;  |___
  Lb(4,1,4,1) = 1
  Lb(4,2,4,1) = 1
  Lb(4,3,4,1) = 1
  
  Lb(4,2,2,2) = 1
  Lb(4,1,2,2) = 1
  Lb(4,1,3,2) = 1
  Lb(4,1,4,2) = 1
  
  Lb(4,1,3,3) = 1
  Lb(4,2,3,3) = 1
  Lb(4,3,3,3) = 1
  Lb(4,3,4,3) = 1
  
  Lb(4,1,4,4) = 1
  Lb(4,2,4,4) = 1
  Lb(4,2,3,4) = 1
  Lb(4,2,2,4) = 1
  
  ;;___________________________________________
  Lb(5,1,2,1) = 1
  Lb(5,1,3,1) = 1
  Lb(5,2,3,1) = 1
  Lb(5,2,4,1) = 1
  
  Lb(5,1,4,2) = 1   ;;  __,----
  Lb(5,2,4,2) = 1
  Lb(5,2,3,2) = 1
  Lb(5,3,3,2) = 1
  
  Lb(5,1,2,3) = 1
  Lb(5,1,3,3) = 1
  Lb(5,2,3,3) = 1
  Lb(5,2,4,3) = 1
  
  Lb(5,1,4,4) = 1
  Lb(5,2,4,4) = 1
  Lb(5,2,3,4) = 1
  Lb(5,3,3,4) = 1
  
  ;;___________________________________________
  Lb(6,2,2,1) = 1
  Lb(6,2,3,1) = 1
  Lb(6,1,3,1) = 1
  Lb(6,1,4,1) = 1
  
  Lb(6,1,3,2) = 1   ;;  ----,__
  Lb(6,2,3,2) = 1
  Lb(6,2,4,2) = 1
  Lb(6,3,4,2) = 1
  
  Lb(6,2,2,3) = 1
  Lb(6,2,3,3) = 1
  Lb(6,1,3,3) = 1
  Lb(6,1,4,3) = 1
  
  Lb(6,1,3,4) = 1
  Lb(6,2,3,4) = 1
  Lb(6,2,4,4) = 1
  Lb(6,3,4,4) = 1
  
  ;;___________________________________________
  Lb(7,1,4,1) = 1   ;;       . : .
  Lb(7,2,4,1) = 1
  Lb(7,2,3,1) = 1
  Lb(7,3,4,1) = 1
  
  Lb(7,1,2,2) = 1
  Lb(7,1,3,2) = 1
  Lb(7,2,3,2) = 1
  Lb(7,1,4,2) = 1
  
  Lb(7,1,3,3) = 1
  Lb(7,2,3,3) = 1
  Lb(7,2,4,3) = 1
  Lb(7,3,3,3) = 1
  
  Lb(7,2,2,4) = 1
  Lb(7,1,3,4) = 1
  Lb(7,2,3,4) = 1
  Lb(7,2,4,4) = 1
EndProcedure

Procedure init_draw()
  If OpenWindow(0, 0, 0, 425, 502, " Fourski III", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    ButtonGadget(0, 310, 435, 85, 22, "Mom's home!!!")
    TextGadget(1, 300, 40, 110, 18, "Hello", #PB_Text_Center)
    TextGadget(2, 300, 58, 110, 20, "Hello", #PB_Text_Center|#PB_Text_Border)
    TextGadget(3, 300, 120, 110, 20, "Hello", #PB_Text_Center|#PB_Text_Border)
    TextGadget(4, 300, 142, 110, 20, "Hello", #PB_Text_Center|#PB_Text_Border)
    TextGadget(5, 300, 300, 110, 18, "/\ Rotate \/", #PB_Text_Center)
    TextGadget(6, 300, 330, 110, 18, "< Left<>Right >", #PB_Text_Center)
    TextGadget(7, 300, 360, 110, 18, "Enter-Drop", #PB_Text_Center)
    TextGadget(8, 300, 390, 110, 18, "Space-Pause", #PB_Text_Center)
    TextGadget(9, 300, 170, 110, 18, "Player Mode", #PB_Text_Center|#PB_Text_Border)
    ButtonGadget(10, 310, 255, 85, 22, "Silent Mode")
    GameBoard = OpenWindowedScreen(WindowID(0), 0, 0, 280, 502, 0, 0, 0)
    If GameBoard
      mac_ClearScreen(RGB(0, 0, 0))
      ; If StartDrawing(WindowOutput(0))
        ; Box(99, 29, 262, 421, RGB(255, 0, 0))  ; blank row
        ; StopDrawing()
      ; EndIf
      CreateSprite(0, 20, 20)
      If StartDrawing(SpriteOutput(0))
        Box(0, 0, 19, 19, RGB(110, 110, 110))  ; blank row
        StopDrawing()
      EndIf
      ;-
      ;/Color 1
      ;   : :
      mac_ClearScreen(RGB(0, 0, 0))
      CreateSprite(1, 40, 80)
      If StartDrawing(SpriteOutput(1))
        Box(0, 40, 19, 19, RGB(195, 0, 155))
        Box(0, 60, 19, 19, RGB(195, 0, 155))
        Box(20, 40, 19, 19, RGB(195, 0, 155))
        Box(20, 60, 19, 19, RGB(195, 0, 155))
        StopDrawing()
      EndIf
      CopySprite(1,2)
      CopySprite(1,3)
      CopySprite(1,4)
      
      ;/Color 2
      ;  - - - -
      mac_ClearScreen(RGB(0, 0, 0))
      CreateSprite(5, 40, 80)
      If StartDrawing(SpriteOutput(5))
        Box(0, 0, 19, 19, RGB(0, 100, 155))
        Box(0, 20, 19, 19, RGB(0, 100, 155))
        Box(0, 40, 19, 19, RGB(0, 100, 155))
        Box(0, 60, 19, 19, RGB(0, 100, 155))
        StopDrawing()
      EndIf
      mac_ClearScreen(RGB(0, 0, 0))
      CreateSprite(6, 80, 80)
      If StartDrawing(SpriteOutput(6))
        Box(0, 60, 19, 19, RGB(0, 100, 155))
        Box(20, 60, 19, 19, RGB(0, 100, 155))
        Box(40, 60, 19, 19, RGB(0, 100, 155))
        Box(60, 60, 19, 19, RGB(0, 100, 155))
        StopDrawing()
      EndIf
      CopySprite(5,7)
      CopySprite(6,8)
      
      ;/Color 3
      ;  ___|
      mac_ClearScreen(RGB(0, 0, 0))
      CreateSprite(9, 60, 80)
      If StartDrawing(SpriteOutput(9))
        Box(0, 60, 19, 19, RGB(155, 100, 0))
        Box(20, 60, 19, 19, RGB(155, 100, 0))
        Box(40, 60, 19, 19, RGB(155, 100, 0))
        Box(40, 40, 19, 19, RGB(155, 100, 0))
        StopDrawing()
      EndIf
      mac_ClearScreen(RGB(0, 0, 0))
      CreateSprite(10, 60, 80)
      If StartDrawing(SpriteOutput(10))
        Box(0, 20, 19, 19, RGB(155, 100, 0))
        Box(0, 40, 19, 19, RGB(155, 100, 0))
        Box(0, 60, 19, 19, RGB(155, 100, 0))
        Box(20, 60, 19, 19, RGB(155, 100, 0))
        StopDrawing()
      EndIf
      mac_ClearScreen(RGB(0, 0, 0))
      CreateSprite(11, 60, 80)
      If StartDrawing(SpriteOutput(11))
        Box(0, 40, 19, 19, RGB(155, 100, 0))
        Box(20, 40, 19, 19, RGB(155, 100, 0))
        Box(40, 40, 19, 19, RGB(155, 100, 0))
        Box(0, 60, 19, 19, RGB(155, 100, 0))
        StopDrawing()
      EndIf
      mac_ClearScreen(RGB(0, 0, 0))
      CreateSprite(12, 40, 80)
      If StartDrawing(SpriteOutput(12))
        Box(0, 20, 19, 19, RGB(155, 100, 0))
        Box(20, 20, 19, 19, RGB(155, 100, 0))
        Box(20, 40, 19, 19, RGB(155, 100, 0))
        Box(20, 60, 19, 19, RGB(155, 100, 0))
        StopDrawing()
      EndIf
      
      ;/Color 4
      ;  |___
      mac_ClearScreen(RGB(0, 0, 0))
      CreateSprite(13, 60, 80)
      If StartDrawing(SpriteOutput(13))
        Box(0, 40, 19, 19, RGB(0, 200, 55))
        Box(0, 60, 19, 19, RGB(0, 200, 55))
        Box(20, 60, 19, 19, RGB(0, 200, 55))
        Box(40, 60, 19, 19, RGB(0, 200, 55))
        StopDrawing()
      EndIf
      mac_ClearScreen(RGB(0, 0, 0))
      CreateSprite(14, 40, 80)
      If StartDrawing(SpriteOutput(14))
        Box(0, 20, 19, 19, RGB(0, 200, 55))
        Box(0, 40, 19, 19, RGB(0, 200, 55))
        Box(0, 60, 19, 19, RGB(0, 200, 55))
        Box(20, 20, 19, 19, RGB(0, 200, 55))
        StopDrawing()
      EndIf
      mac_ClearScreen(RGB(0, 0, 0))
      CreateSprite(15, 60, 80)
      If StartDrawing(SpriteOutput(15))
        Box(0, 40, 19, 19, RGB(0, 200, 55))
        Box(20, 40, 19, 19, RGB(0, 200, 55))
        Box(40, 40, 19, 19, RGB(0, 200, 55))
        Box(40, 60, 19, 19, RGB(0, 200, 55))
        StopDrawing()
      EndIf
      mac_ClearScreen(RGB(0, 0, 0))
      CreateSprite(16, 40, 80)
      If StartDrawing(SpriteOutput(16))
        Box(0, 60, 19, 19, RGB(0, 200, 55))
        Box(20, 20, 19, 19, RGB(0, 200, 55))
        Box(20, 40, 19, 19, RGB(0, 200, 55))
        Box(20, 60, 19, 19, RGB(0, 200, 55))
        StopDrawing()
      EndIf
      
      ;/Color 5
      ;;  __,----
      mac_ClearScreen(RGB(0, 0, 0))
      CreateSprite(17, 40, 80)
      If StartDrawing(SpriteOutput(17))
        Box(0, 20, 19, 19, RGB(255, 100, 0))
        Box(0, 40, 19, 19, RGB(255, 100, 0))
        Box(20, 40, 19, 19, RGB(255, 100, 0))
        Box(20, 60, 19, 19, RGB(255, 100, 0))
        StopDrawing()
      EndIf
      CreateSprite(18, 60, 80)
      If StartDrawing(SpriteOutput(18))
        Box(0, 60, 19, 19, RGB(255, 100, 0))
        Box(20, 60, 19, 19, RGB(255, 100, 0))
        Box(20, 40, 19, 19, RGB(255, 100, 0))
        Box(40, 40, 19, 19, RGB(255, 100, 0))
        StopDrawing()
      EndIf
      CopySprite(17,19)
      CopySprite(18,20)
      
      ;/Color 6
      ;  ----,__
      mac_ClearScreen(RGB(0, 0, 0))
      CreateSprite(21, 40, 80)
      If StartDrawing(SpriteOutput(21))
        Box(20, 20, 19, 19, RGB(245, 215, 55))
        Box(20, 40, 19, 19, RGB(245, 215, 55))
        Box(0, 40, 19, 19, RGB(245, 215, 55))
        Box(0, 60, 19, 19, RGB(245, 215, 55))
        StopDrawing()
      EndIf
      CreateSprite(22, 60, 80)
      If StartDrawing(SpriteOutput(22))
        Box(0, 40, 19, 19, RGB(245, 215, 55))
        Box(20, 40, 19, 19, RGB(245, 215, 55))
        Box(20, 60, 19, 19, RGB(245, 215, 55))
        Box(40, 60, 19, 19, RGB(245, 215, 55))
        StopDrawing()
      EndIf
      CopySprite(21,23)
      CopySprite(22,24)
      
      ;/Color 7
      ;   . : .
      mac_ClearScreen(RGB(0, 0, 0))
      CreateSprite(25, 60, 80)
      If StartDrawing(SpriteOutput(25))
        Box(0, 60, 19, 19, RGB(255, 90, 145))
        Box(20, 40, 19, 19, RGB(255, 90, 145))
        Box(20, 60, 19, 19, RGB(255, 90, 145))
        Box(40, 60, 19, 19, RGB(255, 90, 145))
        StopDrawing()
      EndIf
      mac_ClearScreen(RGB(0, 0, 0))
      CreateSprite(26, 40, 80)
      If StartDrawing(SpriteOutput(26))
        Box(0, 20, 19, 19, RGB(255, 90, 145))
        Box(0, 40, 19, 19, RGB(255, 90, 145))
        Box(0, 60, 19, 19, RGB(255, 90, 145))
        Box(20, 40, 19, 19, RGB(255, 90, 145))
        StopDrawing()
      EndIf
      mac_ClearScreen(RGB(0, 0, 0))
      CreateSprite(27, 60, 80)
      If StartDrawing(SpriteOutput(27))
        Box(0, 40, 19, 19, RGB(255, 90, 145))
        Box(20, 40, 19, 19, RGB(255, 90, 145))
        Box(40, 40, 19, 19, RGB(255, 90, 145))
        Box(20, 60, 19, 19, RGB(255, 90, 145))
        StopDrawing()
      EndIf
      mac_ClearScreen(RGB(0, 0, 0))
      CreateSprite(28, 40, 80)
      If StartDrawing(SpriteOutput(28))
        Box(0, 40, 19, 19, RGB(255, 90, 145))
        Box(20, 20, 19, 19, RGB(255, 90, 145))
        Box(20, 40, 19, 19, RGB(255, 90, 145))
        Box(20, 60, 19, 19, RGB(255, 90, 145))
        StopDrawing()
      EndIf
      ;-
      ;/Color 1
      ;   : :
      mac_ClearScreen(RGB(0, 0, 0))
      CreateSprite(29, 40, 80)
      If StartDrawing(SpriteOutput(29))
        Box(0, 40, 19, 19, #NearlyBlack)
        Box(20, 40, 19, 19, #NearlyBlack)
        Box(0, 60, 19, 19, #NearlyBlack)
        Box(20, 60, 19, 19, #NearlyBlack)
        StopDrawing()
      EndIf
      CopySprite(29,30)
      CopySprite(29,31)
      CopySprite(29,32)
      
      ;/Color 2
      ;  - - - -
      mac_ClearScreen(RGB(0, 0, 0))
      CreateSprite(33, 40, 80)
      If StartDrawing(SpriteOutput(33))
        Box(0, 0, 19, 19, #NearlyBlack)
        Box(0, 20, 19, 19, #NearlyBlack)
        Box(0, 40, 19, 19, #NearlyBlack)
        Box(0, 60, 19, 19, #NearlyBlack)
        StopDrawing()
      EndIf
      mac_ClearScreen(RGB(0, 0, 0))
      CreateSprite(34, 80, 80)
      If StartDrawing(SpriteOutput(34))
        Box(0, 60, 19, 19, #NearlyBlack)
        Box(20, 60, 19, 19, #NearlyBlack)
        Box(40, 60, 19, 19, #NearlyBlack)
        Box(60, 60, 19, 19, #NearlyBlack)
        StopDrawing()
      EndIf
      CopySprite(33,35)
      CopySprite(34,36)
      
      ;/Color 3
      ;  ___|
      mac_ClearScreen(RGB(0, 0, 0))
      CreateSprite(37, 60, 80)
      If StartDrawing(SpriteOutput(37))
        Box(0, 60, 19, 19, #NearlyBlack)
        Box(20, 60, 19, 19, #NearlyBlack)
        Box(40, 60, 19, 19, #NearlyBlack)
        Box(40, 40, 19, 19, #NearlyBlack)
        StopDrawing()
      EndIf
      mac_ClearScreen(RGB(0, 0, 0))
      CreateSprite(38, 60, 80)
      If StartDrawing(SpriteOutput(38))
        Box(0, 20, 19, 19, #NearlyBlack)
        Box(0, 40, 19, 19, #NearlyBlack)
        Box(0, 60, 19, 19, #NearlyBlack)
        Box(20, 60, 19, 19, #NearlyBlack)
        StopDrawing()
      EndIf
      mac_ClearScreen(RGB(0, 0, 0))
      CreateSprite(39, 60, 80)
      If StartDrawing(SpriteOutput(39))
        Box(0, 40, 19, 19, #NearlyBlack)
        Box(20, 40, 19, 19, #NearlyBlack)
        Box(40, 40, 19, 19, #NearlyBlack)
        Box(0, 60, 19, 19, #NearlyBlack)
        StopDrawing()
      EndIf
      mac_ClearScreen(RGB(0, 0, 0))
      CreateSprite(40, 40, 80)
      If StartDrawing(SpriteOutput(40))
        Box(0, 20, 19, 19, #NearlyBlack)
        Box(20, 20, 19, 19, #NearlyBlack)
        Box(20, 40, 19, 19, #NearlyBlack)
        Box(20, 60, 19, 19, #NearlyBlack)
        StopDrawing()
      EndIf
      
      ;/Color 4
      ;  |___
      mac_ClearScreen(RGB(0, 0, 0))
      CreateSprite(41, 60, 80)
      If StartDrawing(SpriteOutput(41))
        Box(0, 40, 19, 19, #NearlyBlack)
        Box(0, 60, 19, 19, #NearlyBlack)
        Box(20, 60, 19, 19, #NearlyBlack)
        Box(40, 60, 19, 19, #NearlyBlack)
        StopDrawing()
      EndIf
      mac_ClearScreen(RGB(0, 0, 0))
      CreateSprite(42, 40, 80)
      If StartDrawing(SpriteOutput(42))
        Box(0, 20, 19, 19, #NearlyBlack)
        Box(0, 40, 19, 19, #NearlyBlack)
        Box(0, 60, 19, 19, #NearlyBlack)
        Box(20, 20, 19, 19, #NearlyBlack)
        StopDrawing()
      EndIf
      mac_ClearScreen(RGB(0, 0, 0))
      CreateSprite(43, 60, 80)
      If StartDrawing(SpriteOutput(43))
        Box(0, 40, 19, 19, #NearlyBlack)
        Box(20, 40, 19, 19, #NearlyBlack)
        Box(40, 40, 19, 19, #NearlyBlack)
        Box(40, 60, 19, 19, #NearlyBlack)
        StopDrawing()
      EndIf
      mac_ClearScreen(RGB(0, 0, 0))
      CreateSprite(44, 40, 80)
      If StartDrawing(SpriteOutput(44))
        Box(0, 60, 19, 19, #NearlyBlack)
        Box(20, 20, 19, 19, #NearlyBlack)
        Box(20, 40, 19, 19, #NearlyBlack)
        Box(20, 60, 19, 19, #NearlyBlack)
        StopDrawing()
      EndIf
      
      ;/Color 5
      ;;  __,----
      mac_ClearScreen(RGB(0, 0, 0))
      CreateSprite(45, 40, 80)
      If StartDrawing(SpriteOutput(45))
        Box(0, 20, 19, 19, #NearlyBlack)
        Box(0, 40, 19, 19, #NearlyBlack)
        Box(20, 40, 19, 19, #NearlyBlack)
        Box(20, 60, 19, 19, #NearlyBlack)
        StopDrawing()
      EndIf
      mac_ClearScreen(RGB(0, 0, 0))
      CreateSprite(46, 60, 80)
      If StartDrawing(SpriteOutput(46))
        Box(0, 60, 19, 19, #NearlyBlack)
        Box(20, 60, 19, 19, #NearlyBlack)
        Box(20, 40, 19, 19, #NearlyBlack)
        Box(40, 40, 19, 19, #NearlyBlack)
        StopDrawing()
      EndIf
      CopySprite(45,47)
      CopySprite(46,48)
      
      ;/Color 6
      ;  ----,__
      mac_ClearScreen(RGB(0, 0, 0))
      CreateSprite(49, 40, 80)
      If StartDrawing(SpriteOutput(49))
        Box(20, 20, 19, 19, #NearlyBlack)
        Box(20, 40, 19, 19, #NearlyBlack)
        Box(0, 40, 19, 19, #NearlyBlack)
        Box(0, 60, 19, 19, #NearlyBlack)
        StopDrawing()
      EndIf
      mac_ClearScreen(RGB(0, 0, 0))
      CreateSprite(50, 60, 80)
      If StartDrawing(SpriteOutput(50))
        Box(0, 40, 19, 19, #NearlyBlack)
        Box(20, 40, 19, 19, #NearlyBlack)
        Box(20, 60, 19, 19, #NearlyBlack)
        Box(40, 60, 19, 19, #NearlyBlack)
        StopDrawing()
      EndIf
      CopySprite(49,51)
      CopySprite(50,52)
      
      ;/Color 7
      ;   . : .
      mac_ClearScreen(RGB(0, 0, 0))
      CreateSprite(53, 60, 80)
      If StartDrawing(SpriteOutput(53))
        Box(0, 60, 19, 19, #NearlyBlack)
        Box(20, 40, 19, 19, #NearlyBlack)
        Box(20, 60, 19, 19, #NearlyBlack)
        Box(40, 60, 19, 19, #NearlyBlack)
        StopDrawing()
      EndIf
      mac_ClearScreen(RGB(0, 0, 0))
      CreateSprite(54, 40, 80)
      If StartDrawing(SpriteOutput(54))
        Box(0, 20, 19, 19, #NearlyBlack)
        Box(0, 40, 19, 19, #NearlyBlack)
        Box(0, 60, 19, 19, #NearlyBlack)
        Box(20, 40, 19, 19, #NearlyBlack)
        StopDrawing()
      EndIf
      mac_ClearScreen(RGB(0, 0, 0))
      CreateSprite(55, 60, 80)
      If StartDrawing(SpriteOutput(55))
        Box(0, 40, 19, 19, #NearlyBlack)
        Box(20, 40, 19, 19, #NearlyBlack)
        Box(40, 40, 19, 19, #NearlyBlack)
        Box(20, 60, 19, 19, #NearlyBlack)
        StopDrawing()
      EndIf
      mac_ClearScreen(RGB(0, 0, 0))
      CreateSprite(56, 40, 80)
      If StartDrawing(SpriteOutput(56))
        Box(0, 40, 19, 19, #NearlyBlack)
        Box(20, 20, 19, 19, #NearlyBlack)
        Box(20, 40, 19, 19, #NearlyBlack)
        Box(20, 60, 19, 19, #NearlyBlack)
        StopDrawing()
      EndIf
      ;/
      mac_ClearScreen(RGB(0, 0, 0))
      CreateSprite(57, 159, 440)
      If StartDrawing(SpriteOutput(57))
        Box(0, 0, 159, 440, #NearlyBlack)
        StopDrawing()
      EndIf
      SetGadgetText(1, "Your score is:")
    Else
      MessageRequester("Error", "Can't open windowed screen!", 0)
      End
    EndIf
  EndIf
EndProcedure

Procedure setup()
  For x = 0 To 20
    For y = 0 To 43
      l(x,y) = 0   ; Clear L() Array
    Next
  Next
  bR.i = 1
  bL.i = 1
  bH.i = 1
  x = 101
  y.i = 11
  score=0
  speed=1500
  ; Print At(15,22);"Press:  Esc to quit,  N to start new game,  Space to pause"
  ; Print At(22,24);"Use arrows for left/right/rotate,  Enter to drop"
  mac_ClearScreen(RGB(0, 0, 0))
  ; 0, 0, 262, 443, RGB(255, 0, 0)
  For r.i = 0 To 9
    a$ = Right(Str(ElapsedMilliseconds()),2)
    n.w = Val(a$) + Random(144)
    n.w = n.w % 7
    r.i(r.i) = n.w + 1
    l(r.i,23) = 1
    DisplayTransparentSprite(0, 99 + 16 * r, 29, 255)    ;Draw New Sprite
    DisplayTransparentSprite(0, 99 + 16 * r, 453, 255)    ;Draw New Sprite
    ; FlipBuffers()
  Next r.i
  For bH.i = 0 To 43
    DisplayTransparentSprite(0, 99, 9.8*bH+29, 255)    ;Draw New Sprite
    DisplayTransparentSprite(0, 243, 9.8*bH+29, 255)    ;Draw New Sprite
    l(0, bH.i) = 1
    l(9, bH.i) = 1
  Next bH.i
  DisplayTransparentSprite(57, 101, 31, 255)    ;Draw New Sprite
  Shape.i = (bN.i-1)*4
  Shape.i = (r.i(9))*4 -3
  DisplayTransparentSprite(Shape, 10, 200, 255)    ;Draw New Sprite
  SimulateOldPBFlipBuffers()
  Delay(10)
  WaitWindowEvent(20)
  Repeat
    Event = WindowEvent()
  Until Event=0
  answer.i = MessageRequester("  Choose difficulty ","      Are you still a beginner?",#PB_MessageRequester_YesNo)
  If answer = #PB_MessageRequester_No
    SetGadgetText(9,"I'm An Expert")
  Else
    beginner = #True
    SetGadgetText(9,"Learning Mode")
  EndIf
  SetGadgetText(3, "Beat your score!")
  grabNext4()
  ;;;
  ;SetGadgetText(1, Str(shape))
  ;;;
EndProcedure

Procedure randomizeRarray()
  A$ = Right(Str(ElapsedMilliseconds()),2)
  n.w = Val(A$) + Random(160)
  n.w = n.w % 7
  R.i(9) = R.i(8)
  R.i(8) = R.i(7)
  R.i(7) = R.i(6)
  R.i(6) = R.i(5)
  R.i(5) = R.i(4)
  R.i(4) = R.i(3)
  R.i(3) = R.i(2)
  R.i(2) = R.i(1)
  R.i(1) = R.i(0)
  R.i(0) = n.w + 1
EndProcedure

Procedure grabNext4()
  bN.i = R.i(9)
  bR.i = 1
  bL.i = 1
  bH.i = 1
  x = 101
  y.i = 31
  t.i = 0
  For x1 = 1 To 4
    For y1.i = 1 To 4
      If (Lb(bN.i,x1,y1.i,bR.i) & L(bL.i - 1 + x1,bH.i - 1 + y1.i)) = 1
        t.i = 1
      EndIf
    Next y1.i
  Next x1
  If t.i
    SetGadgetText(2, Str(score))
    SetGadgetText(3, "GAME OVER")
    Delay(2000)
    ; Print At(48,0);
    Result = MessageRequester(" That was fun!","Start a new game?",#PB_MessageRequester_YesNo)
    scoreB4 = score
    If Result = #PB_MessageRequester_Yes
      setup()
      SetGadgetText(4, Str(scoreB4))
    Else
      End
    EndIf
  Else
    ;;;
    Shape.i = (r.i(9))*4 -3
    DisplayTransparentSprite(Shape+28, 10, 200, 255)       ;Draw New Sprite
    ; FlipBuffers()
    ;;;
    Shape.i = (r.i(8))*4 -3
    DisplayTransparentSprite(Shape, 10, 200, 255)    ;Coming New Sprite
    ; FlipBuffers()
    ;;;
    Shape.i = (r.i(9))*4 -3
    DisplayTransparentSprite(Shape, x, y, 255)       ;Draw New Sprite
    SimulateOldPBFlipBuffers()
    ;;;
    randomizeRarray()
    If beginner.i = #True
      speed = speed*0.998
    Else
      speed = speed*0.988
    EndIf
    wait=ElapsedMilliseconds()+speed
    SetGadgetText(2, Str(score))
    Select score
      Case 1000 To 4999
        SetGadgetText(3, "Great start!")
      Case 5000 To 7999 
        SetGadgetText(3, "Savy player!")
      Case 8000 To 9999
        SetGadgetText(3, "All warmed up!")
      Case 10000 To 11999
        SetGadgetText(3, "Cranking it!")
      Case 12000 To 200000
        SetGadgetText(3, "Digi brain!!")
    EndSelect
  EndIf
  ;t.i=1
EndProcedure

Procedure shiftLeft()
  t.i = 0
  For x1 = 1 To 4
    For y1.i = 1 To 4
      If (Lb(bN.i,x1,y1.i,bR.i) & L(bL.i - 2 + x1,bH.i - 1 + y1.i)) = 1
        t.i = 1
      EndIf
    Next y1.i
  Next x1
  If t.i = 0
    ;;;
    shape.i = (bN.i-1)*4 + bR.i
    DisplayTransparentSprite(Shape+28, x, y, 255) ;Clear current sprite
    bL.i - 1
    x - 20
    DisplayTransparentSprite(Shape, x, y, 255)    ;Draw New Sprite
    SimulateOldPBFlipBuffers()
    ;;;
  EndIf
EndProcedure

Procedure rotate()
  t.i = 0
  bX.i = bR.i + 1
  If bX.i = 5
    bX.i = 1
  EndIf
  For x1 = 1 To 4
    For y1.i = 1 To 4
      If (Lb(bN.i,x1,y1.i,bX.i) & L(bL.i - 1 + x1,bH.i - 1 + y1.i)) = 1
        t.i = 1
      EndIf
    Next y1.i
  Next x1
  If t.i = 0
    ;;;
    shape.i = (R.i(9))*4 -3
    shape.i = (bN.i-1)*4 + bR.i
    DisplayTransparentSprite(Shape+28, x, y, 255) ;Clear current sprite
    bR.i = bX.i
    shape.i = (bN.i-1)*4 + bR.i
    DisplayTransparentSprite(Shape, x, y, 255)    ;Draw New Sprite
    SimulateOldPBFlipBuffers()
    ;;;
  EndIf
EndProcedure
Procedure shiftRight()
  t.i = 0
  For x1 = 1 To 4
    For y1.i = 1 To 4
      If (Lb(bN.i,x1,y1.i,bR.i) & L(bL.i + x1,bH.i - 1 + y1.i)) = 1
        t.i = 1
      EndIf
    Next y1.i
  Next x1
  If t.i = 0
    ;;;
    shape.i = (bN.i-1)*4 + bR.i
    DisplayTransparentSprite(Shape+28, x, y, 255) ;Clear current sprite
    bL.i + 1
    x + 20
    DisplayTransparentSprite(Shape, x, y, 255)    ;Draw New Sprite
    SimulateOldPBFlipBuffers()
    ;;;
  EndIf
EndProcedure

Procedure flash()
  For bJ.i=4 To 1 Step -1
    If t.i(bJ.i)
      score + 10
      For bX = 1 To 4
        GrabSprite(58,101,411,160,20)
        For c.i=1 To 4
          SimulateOldPBFlipBuffers()
          DisplayTransparentSprite(0, 81+c*20, (bH.i+3)*20+11 , 255)    ;Draw New Sprite
          DisplayTransparentSprite(0, 101+(8-c)*20, (bH.i+3)*20+11 , 255)    ;Draw New Sprite
          SimulateOldPBFlipBuffers()
          Delay(5)
        Next c.i
        DisplayTransparentSprite(58, 101, (bH.i+3)*20+11 , 255)    ;Draw New Sprite
        SimulateOldPBFlipBuffers()
        FreeSprite(58)
      Next bX
      If sfx And scard
        PlaySound(4)
      EndIf
      Delay(25)
      For c.i = bH + 3 To 3 Step -1
        For x1=1 To 8
          L(x1,c)=L(x1,c-1)
          L(x1,c-1)=0
        Next x1
      Next c.i
      GrabSprite(58, 101, 31, 160, (bH.i+3)*20-21)
      DisplayTransparentSprite(58, 101, 51, 255)    ;Draw New Sprite
      SimulateOldPBFlipBuffers()
      FreeSprite(58)
    Else
      bH.i - 1
    EndIf
  Next bJ.i
EndProcedure
Procedure checkRow()
  T.i(0) = 0
  T.i(1) = 0
  T.i(2) = 0
  T.i(3) = 0
  T.i(4) = 0
  For y1.i = 1 To 4
    If l(1,bH.i - 1 + y1.i) & l(2,bH.i - 1 + y1.i) = 1
      If l(3,bH.i - 1 + y1.i) & l(4,bH.i - 1 + y1.i) = 1
        If l(5,bH.i - 1 + y1.i) & l(6,bH.i - 1 + y1.i) = 1
          If l(7,bH.i - 1 + y1.i) & l(8,bH.i - 1 + y1.i) = 1
            t.i(y1.i) = 1    ;;  track Rows that are full
          EndIf
        EndIf
      EndIf
    EndIf
  Next
  flash()
EndProcedure

Procedure drop()
  t.i = 0
  settled.i = 0
  For x1 = 1 To 4
    For y1.i = 1 To 4
      If (Lb(bN.i,x1, y1.i,bR.i) & l(bL.i - 1 + x1, bH.i + y1.i)) = 1
        t.i = 1    ;;   Flag it unable To drop.
      EndIf
    Next y1.i
  Next x1
  If t.i          ;;      unable To drop
    For x1 = 1 To 4
      For y1.i = 1 To 4
        If Lb(bN.i, x1, y1.i, bR.i) & 1
          l(bL.i - 1 + x1, bH.i - 1 + y1.i) = 1
          settled.i = 1
        EndIf
      Next y1.i
    Next x1
    ;;;
    checkRow()
    grabNext4()
    SimulateOldPBFlipBuffers()
  Else    ;;    Able To drop
    ;;;
    If settled.i = 0
      score + 1
      Shape.i = (bN.i-1)*4 + bR.i
      DisplayTransparentSprite(Shape+28, x, y, 255) ;Clear current sprite
      ; FlipBuffers()
      bH.i + 1
      y + 20
      DisplayTransparentSprite(Shape, x, y, 255)    ;Draw New Sprite
      SimulateOldPBFlipBuffers()
      If sfx And scard
        PlaySound(0)
      EndIf
      SetGadgetText(2, Str(score))
    EndIf
    ;;;
  EndIf
EndProcedure

Procedure userInputLoop()
  t.i = 0
  wait=ElapsedMilliseconds()+speed
  Repeat
    key = 0
    Repeat
      Event = WindowEvent() : _wParam=EventwParam() : _lParam=EventlParam()
      Select Event
        Case #WM_KEYDOWN      ;-  KEYBOARD  ACTION
          Select _wParam
            Case #VK_LEFT          ;/ < GO Left<<<<
              shiftLeft()
              If sfx And scard
                PlaySound(1)
              EndIf
            Case #VK_UP, #VK_DOWN  ;/    /\Rotate\/
              rotate()
              If sfx And scard
                PlaySound(1)
              EndIf
            Case #VK_RIGHT         ;/    >>>>GO Right >
              shiftRight()
              If sfx And scard
                PlaySound(1)
              EndIf
            Case #VK_RETURN   ;       \ || /
              score + 10
              Repeat               ;/       Drop
                drop();                 \/
              Until settled.i = 1
              settled.i = 0
            Case #VK_ESCAPE        ;/    Escape to Quit
              ; Print At(48,0);
              ;Input "Quit Game Now? y/N ";A$
              result = MessageRequester(" That was fun!","Time to quit already?",#PB_MessageRequester_YesNo)
              If result = #PB_MessageRequester_Yes
                End
              EndIf
              wait=ElapsedMilliseconds()+speed
              ;
            Case #VK_SPACE         ;/     Pause To Pee
              If sfx And scard
                PlaySound(5)
              EndIf
              result = MessageRequester(" Pee break!   ^_^","Spacebar to continue...",#PB_MessageRequester_Ok)
              wait=ElapsedMilliseconds()+speed
              If sfx And scard
                PlaySound(6)
              EndIf
          EndSelect
        Case #PB_Event_Gadget  ;-  BUTTON  ACTION
          Select EventGadget()
            Case 0
              End
            Case 10
              If sfx
                sfx = #False
                SetGadgetText(10,"Silent Mode")
              Else
                sfx = #True
                SetGadgetText(10,"Sound On")
              EndIf
          EndSelect
        Case #PB_Event_CloseWindow
          End 
      EndSelect
    Until Event = 0
    
    Tick=ElapsedMilliseconds()
    If Tick >wait
      wait + speed
      drop()
      SimulateOldPBFlipBuffers()
    EndIf
    Delay(5)
  ForEver
EndProcedure
;-PROGRAM STARTS HERE
pretest()
init_draw()
init_logic()
setup()
userInputLoop()
End

Randy Walker
Addict
Addict
Posts: 1109
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: How did 6.12 break it?

Post by Randy Walker »

Fred wrote: Thu Feb 06, 2025 10:54 am There is so much '.l' that it's probably the cause
Yeah, tried changing those to .i instead and same results.
I edited my OP so all those .l are now .i
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Randy Walker
Addict
Addict
Posts: 1109
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: How did 6.12 break it?

Post by Randy Walker »

SMaag wrote: Thu Feb 06, 2025 12:56 pm Here is a workarround for the FlipBuffers()!
The problem is: In older PB or directX the FlipBuffers() Function is a CopyBuffer().
In newer Version it's a real FlipBuffers() where only the Pointers are exchanged - that's much faster but you have to redraw your complete screen!

So I simulated the the older FlipBuffers() with the copy and it runs perfect.
But generally the problem of randys code is the wrong use of FlipBuffers()

here the new Code
Thank you SMaag!!!!! You fixed it and works perfect again. My use of FlipBuffers() probably stems from GFA basic where I developed my original code. Too far back to recall where I even learned of FlipBuffers. Obviously something to re-learn though. THANKS!!!!
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Randy Walker
Addict
Addict
Posts: 1109
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: How did 6.12 break it?

Post by Randy Walker »

Incidentally, i changed all the .i in SMaag's code to .l just for giggles and it still worked perfectly, and no errors.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Randy Walker
Addict
Addict
Posts: 1109
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: How did 6.12 break it?

Post by Randy Walker »

Also inidentally, I tested code from SMaag in PB 5.4 32 bit and ran perfectly as I'm sure he would expect. Thanks again SMaag!!!
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
SMaag
Enthusiast
Enthusiast
Posts: 327
Joined: Sat Jan 14, 2023 6:55 pm
Location: Bavaria/Germany

Re: How did 6.12 break it?

Post by SMaag »

Because I am interested in this phenomenon I did a little bit deeper reserch!

We call the 2 Buffers, Background and Foreground Buffer

- FipBuffers means exchanging the 2 buffers like a Swap: Content of Background -> Foreground and Foreground -> Background!

In former times (when grafics ram was inside the PC's RAM), this was done with a simple exchange of the Pointers.
I guess: since we have the Video Ram on the grafics card it is not possible with a simple PointerSwap. A real Copy of BackgroundBuffer
to ForegroundBuffer is necessary. In this case the most effective way is to keep the BackgroundBuffer untouched.
That's why randys code was working on older PB/DirectX

Now on PB6.12 or higher use newer DirectX with a different implementation of FlipBuffers.
What I did not understand first is, that the Adress of the BackgroundBuffer is identical before and after FlipBuffers.
So it looked like not exchaning the Pointers! It looked like a real DataSwap of all BufferDatas. But this would not make sense and would be slower
than the necessary copy from Foreground -> Background.

But in times of Virtual Address Tabels, MemoryMapping, PageMapping: I guess the FlipBuffer() now is just a change in the MappingTable. So we can reach the BackgroundBuffer under the same virtual Address after the FlipBuffers but point to other physical Address (the former ForgroundBuffer).
Post Reply