home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 15 / CDACTUAL15.iso / cdactual / program / basic / QBNWS105.ZIP / DAZZLING.ZIP / DAZZLING.BAS < prev    next >
Encoding:
BASIC Source File  |  1990-11-22  |  15.6 KB  |  422 lines

  1. '           +===================================================+
  2. '           |                   DAZZLING.BAS                    |
  3. '           |             Written and Developed by:             |
  4. '           |                  Lawrence Stone                   |
  5. '           |                                                   |
  6. '           |                Copyright (C), 1990                |
  7. '           |                   Lawrence Stone                  |
  8. '           |                All Rights Reserved                |
  9. '           |                                                   |
  10. '           |   The code in this module is for the exclusive    |
  11. '           |   use of readers of the QBNews or any QuickBASIC, |
  12. '           |   BASCOM, or PDS programmer.  The source code and |
  13. '           |   object modules derived from this code may be    |
  14. '           |   freely distributed without the express written  |
  15. '           |   permission of the author.                       |
  16. '           |                                                   |
  17. '           |   Donations of appreciation for this author's     |
  18. '           |   work are gladly accepted.  Please, no donations |
  19. '           |   over $10,000 <GRIN>.                            |
  20. '           |                                                   |
  21. '           |   Lawrence Stone               November 22, 1990  |
  22. '           |   P.O. Box 5715                                   |
  23. '           |   Charleston, OR  97420                           |
  24. '           +---------------------------------------------------+
  25. '
  26. '           +===================================================+
  27. '           |   Compile swithces:  bc dazzling /o;              |
  28. '           +---------------------------------------------------+
  29.  
  30. ' $INCLUDE: 'DAZZLING.BI'
  31.  
  32. SUB Curtains (Direction%, Arry%()) STATIC
  33.  
  34.     ' Arry%()           The screen image array.
  35.     '
  36.     ' Direction = odd   Curtains close from outside toward inside.
  37.     ' Direction = even  Curtains open from inside toward outside.
  38.     '
  39.     ' Monitor -+------  Must be DIM SHARED or COMMON SHARED in main module.
  40.     ' ScrnEls /
  41.     
  42.     Start = 79: finish = 159
  43.     StepCount = 2
  44.     start2 = 1: finish2 = ScrnEls * 2
  45.     StepCount2 = 160
  46.     Direction = Direction MOD 2         'Force Direction into a "1" or "0".
  47.  
  48.     IF Direction THEN
  49.         SWAP Start, finish
  50.         StepCount = -StepCount
  51.         SWAP start2, finish2
  52.         finish2 = finish2 - 1
  53.         StepCount2 = -StepCount2
  54.     END IF
  55.     
  56.     FOR N = Start TO finish STEP StepCount
  57.         DEF SEG = Monitor
  58.         FOR J = start2 TO finish2 STEP StepCount2
  59.             IF (N + J) \ 2 < ScrnEls THEN   'Prevents subscript out of range.
  60.                 '---- Right side of screen.
  61.                 OneByte = Arry((N + J) \ 2) AND &HFF       'Extract high byte.
  62.                 count = &H0 - Direction + J + N
  63.                 GOSUB CurtainPoke
  64.                 OneByte = (Arry((N + J) \ 2) AND &HFF00) \ 256   'Extract low.
  65.                 count = &H0 + 1 - Direction + N + J
  66.                 GOSUB CurtainPoke
  67.                 
  68.                 '---- Left side of screen.
  69.                 I = (79 - N) * 2
  70.                 OneByte = Arry((N + J + I) \ 2) AND &HFF    'Extract high byte.
  71.                 count = &H0 - Direction + J + I + N
  72.                 GOSUB CurtainPoke
  73.                 OneByte = (Arry((N + J + I) \ 2) AND &HFF00) \ 256'Extract low.
  74.                 count = &H0 + 1 - Direction + N + J + I
  75.                 GOSUB CurtainPoke
  76.             END IF
  77.         NEXT
  78.         DEF SEG  'We must return to BASIC's segment before we call TickPause.
  79.         IF N MOD 3 THEN TickPause 1   'A short delay for effect.
  80.     NEXT
  81.  
  82.     EXIT SUB
  83.  
  84. CurtainPoke:
  85.     POKE count, OneByte
  86. RETURN
  87.  
  88. END SUB
  89.  
  90. SUB Dazzle (Operation%, Direction%, Arry%()) STATIC
  91.  
  92.     ' Operation         Description
  93.     ' ---------         ---------------------------------
  94.     '     0             Pull Full Screen Restore
  95.     '     1             Dazzled with Stair Steps
  96.     '     2             Dazzled with 8 Vertical Blinds
  97.     '     3             Dazzled with 4 Vertical Blinds
  98.     '     4             Dazzled with Slots
  99.     '     5             Dazzled with Diagonal Fills
  100.     '     6             Dazzled with Side Slides
  101.     '     7             Dazzled with Rolling Grates
  102.     '     8             Dazzled with Venetian Blinds
  103.     '
  104.     ' Direction = odd   Screen restore is left to right or, top to bottom
  105.     ' Direction = even  Screen restore is right to left or, bottom to top
  106.     '
  107.     ' Arry%()           Screen array
  108.     '
  109.     ' MaxLine \
  110.     ' Monitor -+------  Must be DIM SHARED or COMMON SHARED in main module.
  111.     ' ScrnEls /
  112.  
  113.     GOSUB InitDazzle
  114.     
  115.     FOR J = Start TO finish STEP StepCount   'Force a dazzle.
  116.         DEF SEG = Monitor                    'Define segment address.
  117.         FOR N = J TO finish2 STEP StepCount2
  118.             High = Arry(N \ 2) AND &HFF              'Extract the high byte.
  119.             Low = (Arry(N \ 2) AND &HFF00) \ 256     'Extract the low byte.
  120.             POKE &H0 - 1 + N, High           'POKE the high byte (color attr).
  121.             POKE &H0 + N, Low                'POKE the low byte (character).
  122.  
  123.             ' Slow pull down/up windows needed for compiled code if you
  124.             ' don't want it to just "flash" onto the monitor.
  125.             IF Operation = 0 AND N MOD 479 = 0 THEN
  126.                 DEF SEG
  127.                 TickPause 1
  128.                 DEF SEG = Monitor
  129.             END IF
  130.  
  131.         NEXT
  132.         DEF SEG                              'Back to BASIC.
  133.  
  134.         '**** Short Pause for added effect.
  135.         IF Operation < 4 THEN
  136.             TickPause 1
  137.         ELSEIF Operation > 7 THEN
  138.             IF J MOD 199 = 0 THEN TickPause 1
  139.         ELSEIF Operation = 7 THEN
  140.             IF J MOD 7 = 0 THEN TickPause 1
  141.         ELSEIF Operation <> 0 THEN
  142.             IF J MOD 3 = 0 THEN TickPause 1
  143.         END IF
  144.     NEXT
  145.     
  146.     EXIT SUB
  147.  
  148. InitDazzle:
  149.     StepCount = 2: Start = 1: finish2 = ScrnEls * 2
  150.     SELECT CASE Operation
  151.         CASE 0          'Pull Full Screen Restore
  152.             finish = 1: StepCount2 = finish + 1
  153.             IF Direction MOD 2 THEN
  154.                 Start = finish2 + 1: finish = Start
  155.                 finish2 = 0: StepCount2 = -StepCount2
  156.             END IF
  157.         CASE 1                      'Dazzled Stair Steps
  158.             finish = 42: StepCount2 = finish - 4
  159.         CASE 2                      'Dazzled with 8 Vertical Blinds
  160.             finish = 20: StepCount2 = finish
  161.         CASE 3                      'Dazzled with 4 Vertical Blinds
  162.             finish = 40:  StepCount2 = finish
  163.         CASE 4                      'Dazzled with Slots
  164.             finish = 119:  StepCount2 = finish - 1
  165.         CASE 5                      'Dazzled by Diagonal Fills
  166.             finish = 82: StepCount2 = finish
  167.         CASE 6                      'Dazzled by Side Slides
  168.             finish = 160: StepCount2 = finish
  169.         CASE 7                      'Dazzled by Rolling Grates
  170.             finish = 320: StepCount2 = finish
  171.         CASE 8                      'Dazzled with Venetian Blinds
  172.             finish = 80 * MaxLine - MaxLine
  173.             finish = finish - (finish MOD 160) + 160
  174.             StepCount2 = finish
  175.             StepCount2 = StepCount2 + (StepCount2 MOD 80)
  176.         CASE ELSE
  177.     END SELECT
  178.  
  179.     IF Direction MOD 2 = 0 AND Operation% <> 0 THEN
  180.         SWAP Start, finish
  181.         IF NOT Operation = 4 THEN Start = Start - 1
  182.         StepCount = -StepCount
  183.     END IF
  184. RETURN
  185.  
  186. END SUB
  187.  
  188. SUB GetMonitorSeg
  189.  
  190.     ' Monitor       Must be DIM SHARED or COMMON SHARED in main module.
  191.  
  192.     DEF SEG = 0
  193.     IF (PEEK(&H410) AND &H30) = &H30 THEN Monitor = &HB000 ELSE Monitor = &HB800
  194.     DEF SEG
  195.  
  196. END SUB
  197.  
  198. SUB Implode (Arry%()) STATIC
  199.  
  200.     ' Arry%()           The screen image array.
  201.     '
  202.     ' Direction = odd   Curtains close from outside toward inside.
  203.     ' Direction = even  Curtains open from inside toward outside.
  204.     '
  205.     ' Monitor -+------  Must be DIM SHARED or COMMON SHARED in main module.
  206.     ' ScrnEls /
  207.  
  208.     Start = 1: finish = ScrnEls * 2
  209.     StepCount = 160
  210.     start2 = 0: finish2 = 159
  211.     StepCount2 = 2
  212.  
  213.     FOR N = Start TO finish \ 2 STEP StepCount
  214.         DEF SEG = Monitor
  215.         IF (N) \ 2 < ScrnEls THEN    'Prevents subscript out of range.
  216.             FOR J = start2 TO finish2 STEP StepCount2
  217.                 '---- Top side of screen.
  218.                 OneByte = Arry((N + J) \ 2) AND &HFF       'Extract high byte.
  219.                 count = &H0 - 1 + J + N
  220.                 GOSUB ImplodePoke
  221.                 OneByte = (Arry((N + J) \ 2) AND &HFF00) \ 256   'Extract low.
  222.                 count = &H0 + N + J
  223.                 GOSUB ImplodePoke
  224.             NEXT
  225.  
  226.             FOR K = J - 1 TO finish - J - 1 STEP StepCount
  227.                 '---- Right side of screen.
  228.                 OneByte = Arry(K \ 2) AND &HFF       'Extract high byte.
  229.                 count = &H0 - 1 + K
  230.                 GOSUB ImplodePoke
  231.                 OneByte = (Arry(K \ 2) AND &HFF00) \ 256   'Extract low.
  232.                 count = &H0 + K
  233.                 GOSUB ImplodePoke
  234.             NEXT
  235.  
  236.             FOR I = finish - N TO finish - N - J + 2 STEP -StepCount2
  237.                 '---- Bottom side of screen.
  238.                 OneByte = Arry(I \ 2) AND &HFF       'Extract high byte.
  239.                 count = &H0 - 1 + I
  240.                 GOSUB ImplodePoke
  241.                 OneByte = (Arry(I \ 2) AND &HFF00) \ 256   'Extract low.
  242.                 count = &H0 + I
  243.                 GOSUB ImplodePoke
  244.             NEXT
  245.  
  246.             FOR J = I + 2 TO N STEP -StepCount
  247.                 '---- Left side of screen.
  248.                 OneByte = Arry(J \ 2) AND &HFF       'Extract high byte.
  249.                 count = &H0 - 1 + J
  250.                 GOSUB ImplodePoke
  251.                 OneByte = (Arry(J \ 2) AND &HFF00) \ 256   'Extract low.
  252.                 count = &H0 + J
  253.                 GOSUB ImplodePoke
  254.             NEXT
  255.             start2 = start2 + StepCount2: finish2 = finish2 - StepCount2
  256.         END IF
  257.         DEF SEG
  258.         TickPause 1     'Slow compiled programs down to see it happen!
  259.     NEXT
  260.  
  261.     EXIT SUB
  262.  
  263. ImplodePoke:
  264.     POKE count, OneByte
  265. RETURN
  266.  
  267. END SUB
  268.  
  269. SUB ReadBinFile (Arry%(), ScrFile$, LeadingRows%)
  270.  
  271.     ' Arry%()       The screen array to be filled.
  272.     ' ScrFile$      The name of the BIN file to open and read.
  273.     ' LeadingRows%  The number of rows in the video array to leave blank.
  274.     '
  275.     ' Note:  This routine does no error checking.  It is your responsibility
  276.     '        to make sure that ScrFile$ exists before calling this routine.
  277.  
  278.     OPEN ScrFile$ FOR BINARY AS #1         'Open a BIN file.
  279.     N = LOF(1)
  280.     temp$ = INPUT$(N, 1)                   'Input 'N' bytes to a work string.
  281.     CLOSE
  282.  
  283.     '---- Calculate a starting point for inserting our screen into the array.
  284.     IF LeadingRows THEN Start = (LeadingRows% * 80)
  285.  
  286.     FOR A = 1 TO N STEP 2
  287.         '---- Combine the two bytes into one, long integer.
  288.         N& = (ASC(MID$(temp$, A, 1)) + 256&) + (ASC(MID$(temp$, A + 1, 1)) * 256&) - 256&
  289.  
  290.         '---- Adjust integer's range to signed short integer range.
  291.         IF N& > 32767 THEN N& = N& - 65536
  292.  
  293.         Arry(Start + A \ 2) = N&            'Assign the integer to the array.
  294.     NEXT
  295.     temp$ = ""                              'Clear the temporary string.
  296.  
  297. END SUB
  298.  
  299. SUB Shake (HowMany%)
  300.  
  301. '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  302. '%                                                           %
  303. '%  HumbleWare Custom Programming                12/12/1988  %
  304. '%                                                           %
  305. '%  Routine to "shake" the screen by reprogramming the 6845  %
  306. '%  CRT controllers viewport into video RAM.                 %
  307. '%                                                           %
  308. '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  309. '
  310. '+===========================================================+
  311. '|                                                           |
  312. '|  Modified by Lawrence Stone Research Group    11/22/1990  |
  313. '|                                                           |
  314. '|  The principle modification made to this routine is the   |
  315. '|  substitutions of the TickPause delay routine in lieu of  |
  316. '|  the original TIMER + .01 code.                           |
  317. '|                                                           |
  318. '+-----------------------------------------------------------+
  319.  
  320.     FOR N = 0 TO HowMany
  321.  
  322.         'move viewport into video RAM by 3 text lines (ie, this is the number
  323.         'of lines your entire screen will jump with each shake.  -LS)
  324.         Lines% = 3
  325.  
  326.         'turn text lines into register values
  327.         Lo% = (Lines% * 80) MOD 256
  328.         Ho% = (Lines% * 80) \ 256
  329.  
  330.         'request access to register 12
  331.         OUT &H3D4, 12
  332.         'program register 12
  333.         OUT &H3D5, Ho%
  334.  
  335.         'request access to register 13
  336.         OUT &H3D4, 13
  337.         'program register 13
  338.         OUT &H3D5, Lo%
  339.  
  340.         'pause a moment for effect
  341.         TickPause 1
  342.  
  343.         'restore viewport into video RAM
  344.         Lines% = 0
  345.  
  346.         'turn text lines into register values
  347.         Lo% = (Lines% * 80) MOD 256
  348.         Ho% = (Lines% * 80) \ 256
  349.  
  350.         'request access to register 12
  351.         OUT &H3D4, 12
  352.         'program register 12
  353.         OUT &H3D5, Ho%
  354.  
  355.         'request access to register 13
  356.         OUT &H3D4, 13
  357.         'program register 13
  358.         OUT &H3D5, Lo%
  359.  
  360.         'pause a moment for effect
  361.         TickPause 1
  362.  
  363.     NEXT
  364.  
  365. END SUB
  366.  
  367. SUB StuffMess (Arry%(), Mess$, Row%, Col%, Fg%, Bg%) STATIC
  368.  
  369.     ' Arry%()       Screen image array.
  370.     ' Mess$         Message to place into the screen image array.
  371.     ' Row%          Screen row location for the message.
  372.     ' Col%          Screen column location for the message.
  373.     ' Fg%           Foreground color of the message.
  374.     ' Bg%           Background color of the message.
  375.  
  376.     '---- Convert Foreground & Baground colors to a screen attribute integer.
  377.     BColr = Bg * 16                          'Put color into proper range.
  378.     FColr = Fg                               'Set forground color.
  379.     IF FColr > 15 THEN BColr = BColr + 128   'Set blink attribute.
  380.     FColr = FColr AND 15                     'Remove blink attribute.
  381.     Colr = FColr + BColr                     'Create screen attribute integer.
  382.  
  383.     '---- Combine the Row & Col position into a starting point for video map.
  384.     Start = (((Row * 160) - 160) + (Col * 2)) - 2
  385.  
  386.     ArySeg = VARSEG(Arry%(0))       'Segment address of the array.
  387.     AryPtr = VARPTR(Arry%(0))       'Offset of the array.
  388.     I = 0                           'Initialize position counter.
  389.  
  390.     DEF SEG = ArySeg
  391.     FOR J = 1 TO LEN(Mess$)                             'Loop thru message.
  392.         POKE AryPtr + Start + I, ASC(MID$(Mess$, J, 1)) 'POKE the character.
  393.         POKE AryPtr + Start + I + 1, Colr               'POKE the color.
  394.         I = I + 2                                       'Increment 'I' by 2.
  395.     NEXT
  396.     DEF SEG
  397.     
  398. END SUB
  399.  
  400. SUB TickPause (Ticks%) STATIC
  401.  
  402.     ' Ticks%        The number of ticks to delay.  There are 18.2 ticks
  403.     '               per second.  This routine returns the ticks as an
  404.     '               integer - it does not use QB's floating point routine.
  405.  
  406.     TestTick = 0
  407.  
  408.     DEF SEG = zero
  409.     WHILE TestTick < Ticks
  410.  
  411.         lastTick = Tick
  412.         Tick = PEEK(&H46C)     'Get a tick from the clock.
  413.         
  414.         '   ---- Prevents endless loop when rolling past midnight.
  415.         IF lastTick <> Tick THEN TestTick = TestTick + 1
  416.  
  417.     WEND
  418.     DEF SEG
  419.  
  420. END SUB
  421.  
  422.