'--------------------------------------------------------------------------
'                               QBASWIN2.TMP
'
'  This is a "template" upon which to build your QBASIC programs using
'  QBASWIN II.  Copy this file to a .BAS extension and you're ready!

'  IMPORTANT:  The window memory buffer is set at maximum, 32766...if you're
'  running out of memory, you may decrease this number, but be careful.
'  If you overfill the buffer, you'll run into a String Space Corrupt for
'  sure!  And that's bad.  If you're using ZoomUp or ZoomDown, leave it
'  it at 32766 if at all possible.  If you're using just PopUp and PopDown,
'  you can calculate the exact amount of memory you'll need to set aside.
'  The memory required to save one window is (r+1)*(c+1)+10, where r and c
'  are the number of rows and columns, respectively.  So, if you know
'  how many windows you'll have up at one time, and their size, you know
'  the minimum memory you'll need to set aside.  Say, for 4 windows,
'  20x20, you'll need a minimum of (21*21+10)*4 = 1764.  Set winmem% to
'  1764.
'
'                        *         *         *
'
'  THIS IS PUBLIC DOMAIN SOFTWARE.  YOU MAY FREELY DISTRIBUTE THIS PROGRAM
'  ONLY IN ITS ORIGINAL FORM.  MODIFIED VERSIONS ARE NOT TO BE DISTRIBUTED.
'
'  For more information on QuickBASIC programming libraries or if you have
'  any questions about QBASWIN II, you may contact the author, John Strong,
'  at Strongsoft, 3155 SW 178th Avenue, Aloha, OR 97006. (203)436-2836
'
'---------------------------------------------------------------------------

DECLARE SUB InitWindow (mem%)
DECLARE SUB popup (ulr%, ulc%, lrr%, lrc%, attr%, frame%, shadow%, saveit%)
DECLARE SUB popdown ()
DECLARE SUB ZoomUp (ulr%, ulc%, lrr%, lrc%, attr%, frame%, shadow%, saveit%, snd%, zooms%)
DECLARE SUB ZoomDown (snd%, zooms%)
REDIM SHARED work%(0), winmem%(0)            'InitWindow will redim these

winmem% = 32766                              'window memory buffer size
CALL InitWindow(winmem%)                     'this must be done first

'---------------------------------------------------------------------------



'         Your code goes here!  If you have any COMMON variables, you'll
'         need to declare them just after the DECLARE statements above.
'         Have fun!
CALL popup(10, 10, 20, 20, 31, 1, 1, 1)
CALL popup(13, 13, 23, 23, 31, 1, 1, 1)
SLEEP 1
CALL popdown
SLEEP 1
CALL popdown

'---------------------- Machine language program data -----------------------
prog:
DATA 55,8B,EC,83,EC,10,53,51,6,57,56,B9,8,0,BF,0,0,8B,5B,6,8B,7,48,89
DATA 43,F0,47,47,E2,F3,FF,46,F6,FF,46,F4,FF,46,F2,FF,46,F0,BB,0,B0,A1,10,0
DATA 25,30,0,3D,30,0,74,3,BB,0,B8,8E,C3,8B,5E,FE,B8,A0,0,F7,E3,8B,5E,FC
DATA D1,E3,3,C3,8B,F8,57,8B,46,F8,8B,5E,FC,2B,C3,40,8B,D8,53,8B,46,FA,8B,56
DATA FE,2B,C2,40,8B,C8,51,8B,46,F6,3D,0,0,7F,5B,F7,D0,40,89,46,F6,1E,6,57
DATA 51,53,8B,F7,6,8B,46,F0,8E,C0,1F,26,8B,3E,0,0,83,C7,A,57,41,43,51,51
DATA 8B,CB,F3,A5,59,2B,F3,2B,F3,81,C6,A0,0,E2,F0,59,26,89,3E,0,0,8B,46,FE
DATA 26,89,5,8B,46,FC,26,89,45,2,8B,46,FA,26,89,45,4,8B,46,F8,26,89,45,6
DATA 58,26,89,45,8,5B,59,5F,7,1F,BA,0,0,8A,66,F6,B0,20,83,7E,F4,0,74,5
DATA B0,C4,BA,1,0,51,8B,CB,83,7E,F4,0,74,8,50,B0,B3,AB,83,E9,1,58,F3,AB
DATA 83,7E,F4,0,74,8,50,83,EF,2,B0,B3,AB,58,83,FA,0,75,E,83,7E,F2,0,74
DATA 8,50,B0,8,47,AA,4F,4F,58,2B,FB,2B,FB,81,C7,A0,0,59,B0,20,83,7E,F4,0
DATA 74,7,83,F9,2,75,2,B0,C4,BA,0,0,E2,AF,83,7E,F2,0,74,B,8B,CB,B0,8
DATA 83,C7,2,47,AA,E2,FC,83,7E,F4,0,74,27,59,5B,5F,B0,DA,AB,3,FB,3,FB,83
DATA EF,4,B0,BF,AB,50,B8,A0,0,49,F7,E1,3,F8,58,83,EF,2,B0,D9,AB,2B,FB,2B
DATA FB,B0,C0,AB,5E,5F,7,59,5B,8B,E5,5D,CA,10,0
DATA 55,8B,EC,53,51,52,6,57,56,1E,BB,0,B0,A1,10,0,25,30,0,3D,30,0,74,5
DATA BB,0,B8,8E,C3,8B,76,6,8E,1C,8B,36,0,0,83,FE,0,74,44,8B,1C,B8,A0,0
DATA F7,E3,8B,5C,2,D1,E3,3,C3,8B,F8,8B,44,6,8B,5C,2,2B,C3,40,8B,D8,8B,44
DATA 4,8B,14,2B,C2,40,8B,C8,8B,74,8,83,EE,A,89,36,0,0,83,C6,A,41,43,51
DATA 8B,CB,F3,A5,59,2B,FB,2B,FB,81,C7,A0,0,E2,F0,1F,5E,5F,7,5A,59,5B,8B,E5
DATA 5D,CA,2,0

DEFINT A-Z
SUB InitWindow (mem)
     'work() holds the program
     REDIM work(250)
     DEF SEG = VARSEG(work(0))
     RESTORE prog
     FOR i = 1 TO 499
        READ D$
        POKE i - 1, VAL("&H" + D$)
     NEXT
     DEF SEG
     REDIM winmem(mem)
END SUB

SUB popdown
     DEF SEG = VARSEG(work(0))
     winseg = VARSEG(winmem(0))
     CALL absolute(winseg, 375)
     DEF SEG
END SUB

SUB popup (ulr, ulc, lrr, lrc, attr, frame, shadow, saveit)
     IF ulr < lrr AND ulc < lrc THEN
          DEF SEG = VARSEG(work(0))
          winseg = VARSEG(winmem(0))
          IF saveit THEN newattr = -attr ELSE newattr = attr
          CALL absolute(ulr, ulc, lrr, lrc, newattr, frame, shadow, winseg, 0)
          DEF SEG
     END IF
END SUB

SUB ZoomDown (snd, zooms)
    
     FOR i = 49 TO zooms + 1 STEP -1
          IF snd THEN SOUND i * 110 + 440, .05 ELSE SOUND 0, .08
     NEXT
     FOR i = 1 TO zooms
          CALL popdown
          IF snd THEN SOUND (zooms - i) * 110 + 440, .08 ELSE SOUND 0, .08
     NEXT
     zooms = 0

END SUB

SUB ZoomUp (ulr, ulc, lrr, lrc, attr, frame, shadow, saveit, snd, zooms)
    
     IF ulr < lrr AND ulc < lrc THEN
          DEF SEG = VARSEG(work(0))
          winseg = VARSEG(winmem(0))
         
          crow = (ulr + lrr) / 2
          ccol = (ulc + lrc) / 2
          IF lrr - ulr > lrc - ulc THEN
               dc = 1
               dr = INT((lrr - ulr) / (lrc - ulc))
          ELSE
               dr = 1
               dc = INT((lrc - ulc) / (lrr - ulr))
          END IF

          ulr0 = crow - 1
          lrr0 = crow + 1
          ulc0 = ccol - 1
          lrc0 = ccol + 1
          c = 0
          z = 1
         
          IF saveit = 1 THEN newattr = -attr ELSE newattr = attr
          DO
               z = z + 2
               CALL absolute(ulr0, ulc0, lrr0, lrc0, newattr, frame, 0, winseg, 0)
               ulr0 = ulr0 - dr
               ulc0 = ulc0 - dc
               CALL absolute(ulr0, ulc0, lrr0, lrc0, newattr, frame, 0, winseg, 0)
               lrr0 = lrr0 + dr
               lrc0 = lrc0 + dc
               IF snd THEN SOUND z * 110 + 440, .08 ELSE SOUND 0, .08
          LOOP UNTIL lrr0 >= lrr OR lrc0 >= lrc
          z2 = z
          CALL absolute(ulr, ulc, lrr, lrc, newattr, frame, shadow, winseg, 0)
                   
          DO UNTIL z2 > 49
               z2 = z2 + 2
               IF snd THEN SOUND z2 * 110 + 440, .08 ELSE SOUND 0, .08
          LOOP

          DEF SEG
     END IF
     zooms = -(saveit = 1) * z

END SUB

