'===========================================================================
' Subject: Micro-Timer                        Date: 06-15-01 (19:34)       
'  Author: Richard Kelly                      Code: QB, QBasic, PDS        
'  Origin: Newson@37.com                    Packet: DATETIME.ABC
'===========================================================================
'Author: Richard Kelly       05/27/2001      E-Mail: Newson@37.com
'
'This program is released into the Public Domain.  It should work
'fine in Q-BASIC, QuickBASIC, PDS, or FirstBASIC.
'
'It demonstrates a "Microtimer" that's supported in several BASIC
'languages.
'
'The "moving ball routine" is purposely "un-fancy", as I was more
'concerned with making the demo fast and simple.  This way, there's
'less code for the user to go through to figure out the Timer
'routine.  I hope this routine is useful to you.  :-)
'
'Special thanks to Edward Di Geronimo Jr. and Eric Carr.

'Draw the ball, then "GET" it
DIM A%(100), B%(100): SCREEN 9, 0, 1, 0: COLOR 7: CLS : GET (0, 0)-(12, 8), A%
CIRCLE (6, 4), 6, 7: PAINT (6, 2), 7, 7: CIRCLE (6, 4), 4, 15: PAINT (6, 3), 15, 15
GET (0, 0)-(12, 8), B%: CLS : SCREEN 9, 0, 0, 0

X0 = 316: Y0 = 0: X1 = X0: Y1 = Y0: Y = 0

'If you want 60hz, use "N& = 19886"

N& = 29830            'Reprogram the timer to 40hz
LB& = N& AND &HFF     'instead of 18.2 (for 40 frames
HB& = (N& / 256) AND &HFF'per second.)
OUT &H43, &H3C: OUT &H40, LB&: OUT &H40, HB&

BLOOP:
DEF SEG = 0
POKE (1132), 0                        'Sets PEEK(1132) to Zero.  (1132)
PUT (X1, Y1), A%, PSET                'is the Microtimer, so this will
PUT (X0, Y0), B%, PSET                '*not* reset the system clock
X1 = X0: Y1 = Y0                      'to Midnight.
YY = 0: IF Y0 + Y > 340 THEN Y = -Y: YY = 1
Y = Y + 1: IF Y = 0 AND YY = 1 THEN GOTO FINIS
Y0 = Y0 + Y
ROUTINE:
I$ = INKEY$: IF I$ > "" THEN GOTO FINIS
IF PEEK(1132) < 1 THEN GOTO ROUTINE   'Don't go to the next frame until
WAIT 936, 8                           'a certain time has elapsed.
GOTO BLOOP

FINIS:
SCREEN 0, 0, 0, 0: WIDTH 80
N& = 65535                      'Program the timer back to
LB& = N& AND &HFF               '18.2hz before exiting!
HB& = (N& / 256) AND &HFF
OUT &H43, &H3C: OUT &H40, LB&: OUT &H40, HB&
CLEAR   'need to have this if reprograming the timer
END

