'===========================================================================
' Subject: TSR IN QUICKBASIC                  Date: 10-26-95 (18:29)       
'  Author: Tyler Barnes                       Code: QB, QBasic, PDS        
'  Origin: FidoNet QUIK_BAS Echo            Packet: DOS.ABC
'===========================================================================
'Ok, here's the source code to a TSR that will make a small screen saver pop up
'every time you hit the printscreen key. You can make other types of tsr's with 
'this also, all you have to do is hook the right interrupts.
'I don't really want to explain how to use this source, so for the most part, 
'you'll have to figure it out for yourself. One thing you should know though...

'In the program introduction (The part where I wrote A = 1000: B = 1000 etc.) 
'you should put any variables that you plan on using. For example. if you are 
'using A as a variable in your program, and the biggest possible number that 
'will ever be in A is 1000, you'd type A = 1000. Same goes for string 
'variables. If you are going to use A$, and the contents of A$ is never going 
'to exceed 1000 characters, you'd put A$ = SPACE$(1000)
'On line 20000, there is a place on the line where there is a number. You can 
'use the number that is there, or the number that is on the same line commented
'out... Using one number will cause the computer to continue what it was doing

'after doing what the TSR told it to, the other one will do what the tsr told 
'it to do, and abort any other processes. For example, in my screensaver 
'thingy... one number will cause the screen saver to popup when you hit 
'printscreen, and then return to DOS when you hit a key, the other number will 
'cause the screensaver to popup, and return to dos, AND print the screen when 
'you hit a key.
'Also, you will notice in the source that it creates a small .COM file, 
'runs it with a shell command, and then kills it. This is unavoidable...
'Load QUickbasic with the /L switch.
'Do *NOT* run the TSR source from the environment
'Always compile into the Stand-Alone format.
'And last but not least: I wrote the screensaver, but I did not write the TSR 
'source itself.
'Um, I guess that's it. Here it is. Not the best, but the closest I've seen to 
'a QuickBasic TSR...
'--------------------------------------------------------------
'                       TSR_IN_BASIC
'                   QuickBasic version
'              start QB with"/lqb" switch
1    '  start introduction program here
'
A = 1000: B = 1000: C = 1000: D = 1000: I = 1000: COL = 1000: MP = 1000: Z = 1000
6999 '  end introduction program here
'
7000 '  set-up program
'
7010    DIM GMMCKAY%(600)
GMMCKAY%(600) = 0: GMMCKAY%(599) = 0: GMMCKAY% = 0: GMMCKAY$ = "00"

GMMCKAY%(598) = VARPTR(GMMCKAY%(0))
DEF SEG = VARSEG(GMMCKAY%(0))
FOR GMMCKAY% = 0 TO 800
READ GMMCKAY$
POKE GMMCKAY%(598) + GMMCKAY%, VAL("&H" + GMMCKAY$)
NEXT GMMCKAY%
IF GMMCKAY$ <> "00" THEN PRINT "error loading program": STOP

7500    GMMCKAY%(597) = 1'  *** first interrupt ***
7520    GMMCKAY%(598) = 5
7540    GOSUB 9000

7600 '  GMMCKAY%(597)=2  '  *** second interrupt ***
7620 '  GMMCKAY%(598)=5
7640 '  GOSUB 9000

7700 '  GMMCKAY%(597)=3  ' ** third interrupt ***
7720 '  GMMCKAY%(598)=5
7740 '  GOSUB 9000

8140    DEF SEG = VARSEG(GMMCKAY%(0))
GMMCKAY% = VARPTR(GMMCKAY%(0))

8160    CALL absolute(GMMCKAY%) ' call set-up
IF GMMCKAY%(599) = 1 THEN 10000
GMMCKAY%(599) = 1
LOCATE , , 1
Z = FREEFILE: OPEN "CS.COM" FOR OUTPUT AS Z
PRINT #Z, "Ȼ" + CHR$(0) + CHR$(0) + ">" + CHR$(0) + "L!";
CLOSE Z
SHELL "CS.COM"
KILL "CS.COM"
GMMCKAY% = VARPTR(GMMCKAY%(0)) + 763
DEF SEG = VARSEG(GMMCKAY%(0))
8340    CALL absolute(GMMCKAY%) ' terminate as TSR
GOTO 10000
9000    GMMCKAY% = VARPTR(GMMCKAY%(0)) + 643
DEF SEG = VARSEG(GMMCKAY%(0))
9040    CALL absolute(GMMCKAY%(598), GMMCKAY%(597), GMMCKAY%)' call interrupt  .......
9060    RETURN
'
10000 ' start TSR program here

SCREEN 12
RANDOMIZE TIMER
DO
A = INT(RND * 640)
B = INT(RND * 480)
C = INT(RND * 640)
D = INT(RND * 480)
COL = INT(RND * 15)
FOR I = A TO INT(RND * (640 - A))
Z = INT(RND * 3) + 1
MP = INT(RND * 2)
SELECT CASE Z
CASE 1: C = C + 1
CASE 2: D = D + 1
CASE 3: B = B + 1
END SELECT
LINE (A, B)-(C, D), COL
NEXT I
LOOP WHILE INKEY$ = ""
SCREEN 0
CLS

19999 ' end TSR program here
'
20000   GMMCKAY% = 437'**** or have GMMCKAY%=551
20020   GMMCKAY% = GMMCKAY% + VARPTR(GMMCKAY%(0))
DEF SEG = VARSEG(GMMCKAY%(0))
20060   CALL absolute(GMMCKAY%) ' return to original program
GOTO 10000
20100   END

31000  '      GMMCKAY%() data statements
31001  DATA  9C,56,E8,00,00,5E,81,C6,7B,03,2E,8C,5C,08,0E
31002  DATA  1F,89,04,89,5C,02,89,4C,04,89,54,06,8C,54,0A
31003  DATA  8C,44,0C,58,89,44,0E,89,7C,10,89,6C,12,58,89
31004  DATA  44,16,B9,30,00,89,F0,05,60,00,05,18,00,07,89
31005  DATA  C7,29,CF,29,CF,8C,05,E2,F5,89,64,14,B8,00,00
31006  DATA  89,84,30,01,E9,A1,00,90,9C,56,E8,00,00,5E,81
31007  DATA  C6,28,03,2E,89,44,78,58,2E,89,44,7A,58,2E,89
31008  DATA  44,7C,2E,8B,84,30,01,3D,00,00,74,1C,2E,8B,84
31009  DATA  02,01,50,2E,8B,84,00,01,50,2E,8B,44,7C,50,2E
31010  DATA  8B,44,78,2E,8B,74,7A,9D,CB,90,B8,01,00,2E,89
31011  DATA  84,30,01,2E,8C,9C,88,00,0E,1F,90,90,8B,44,78
31012  DATA  89,84,80,00,8B,44,7C,89,84,96,00,8B,44,7A,89
31013  DATA  84,8E,00,89,9C,82,00,89,8C,84,00,89,94,86,00
31014  DATA  8C,94,8A,00,8C,84,8C,00,89,BC,90,00,89,AC,92
31015  DATA  00,B9,30,00,89,F0,05,60,00,05,98,00,07,89,C7
31016  DATA  29,CF,29,CF,8C,05,E2,F5,89,A4,94,00,8E,54,0A
31017  DATA  8B,64,14,B9,30,00,89,F0,05,16,00,89,C7,01,CF
31018  DATA  01,CF,8E,05,06,E2,F5,8B,6C,12,8B,7C,10,8E,44
31019  DATA  0C,8B,54,06,8B,4C,04,8B,5C,02,8B,44,16,50,8B
31020  DATA  44,0E,50,8B,04,8E,5C,08,5E,9D,FB,CB,90,90,9C
31021  DATA  56,E8,00,00,5E,81,C6,50,02,2E,89,44,78,58,2E
31022  DATA  89,44,7A,58,2E,89,44,7C,2E,8B,84,30,01,3D,00
31023  DATA  00,74,1C,2E,8B,84,06,01,50,2E,8B,84,04,01,50
31024  DATA  2E,8B,44,7C,50,2E,8B,44,78,2E,8B,74,7A,9D,CB
31025  DATA  90,B8,02,00,E9,25,FF,90,9C,56,E8,00,00,5E,81
31026  DATA  C6,0B,02,2E,89,44,78,58,2E,89,44,7A,58,2E,89
31027  DATA  44,7C,2E,8B,84,30,01,3D,00,00,74,1C,2E,8B,84
31028  DATA  0A,01,50,2E,8B,84,08,01,50,2E,8B,44,7C,50,2E
31029  DATA  8B,44,78,2E,8B,74,7A,9D,CB,90,B8,03,00,E9,E0
31030  DATA  FE,90,E8,00,00,5E,81,C6,C8,01,0E,1F,8E,94,8A
31031  DATA  00,8B,A4,94,00,B9,30,00,89,F0,05,96,00,89,C7
31032  DATA  01,CF,01,CF,8E,05,06,E2,F5,8B,AC,92,00,8B,BC
31033  DATA  90,00,8E,84,8C,00,8B,94,86,00,8B,8C,84,00,8B
31034  DATA  84,30,01,01,C0,01,C0,01,F0,BB,FE,00,01,C3,8B
31035  DATA  07,50,8B,47,FE,90,90,50,8B,9C,82,00,8B,84,96
31036  DATA  00,50,FA,B8,00,00,89,84,30,01,8B,84,80,00,8E
31037  DATA  9C,88,00,2E,8B,B4,8E,00,9D,CB,90,E8,00,00,5E
31038  DATA  81,C6,56,01,0E,1F,8E,94,8A,00,8B,A4,94,00,B9
31039  DATA  30,00,89,F0,05,96,00,89,C7,01,CF,01,CF,8E,05
31040  DATA  06,E2,F5,8B,AC,92,00,8B,BC,90,00,8E,84,8C,00
31041  DATA  8B,94,86,00,8B,8C,84,00,90,8B,9C,82,00,8B,84
31042  DATA  96,00,50,FA,B8,00,00,89,84,30,01,8B,84,80,00
31043  DATA  8E,9C,88,00,2E,8B,B4,8E,00,9D,FB,CF,90,E8,00
31044  DATA  00,5E,81,C6,FA,00,2E,8C,9C,A0,00,0E,1F,8C,84
31045  DATA  A2,00,89,AC,A4,00,89,BC,A6,00,89,E5,8B,7E,06
31046  DATA  8A,05,B4,35,CD,21,89,F2,8B,7E,04,8B,0D,83,F9
31047  DATA  01,75,0E,89,9C,00,01,8C,84,02,01,81,EA,2D,03
31048  DATA  EB,1F,83,F9,02,75,0E,89,9C,04,01,8C,84,06,01
31049  DATA  81,EA,55,02,EB,0C,89,9C,08,01,8C,84,0A,01,81
31050  DATA  EA,10,02,B4,25,CD,21,8B,AC,A4,00,8B,BC,A6,00
31051  DATA  8E,84,A2,00,8E,9C,A0,00,CA,04,00,90,90,B4,62
31052  DATA  CD,21,B8,00,00,8E,C0,26,A1,FE,03,29,D8,89,C2
31053  DATA  B8,00,31,CD,21,90,90,90,90,00,00,00,00,00,00
31054  DATA  00,00,00,00,00,00
31055  '         end GMMCKAY%() data statments

