'===========================================================================
' Subject: POKEBUFFER SUBROUTINE              Date: 04/25/92 (00:00)       
'  Author: David L. Poskie                    Code: QB, QBasic, PDS        
'  Origin: POKE,BUFFER,SUBROUTINE           Packet: MEMORY.ABC
'===========================================================================
' POKEBUFF.BAS - Demonstrates PokeBuffer subroutine
'   Used to put a string into key buffer on program exit
'   by David L. Poskie   Madison, WI     QBASIC 1.0  25 April 92
'
'  Input:
'   Cmd$: A string of up to 14 characters to be used by DOS to invoke
'         the next program when leaving *this* QBASIC program.
' Output:
'   Cmd$ in the DOS key buffer
'
'> NOTE: Modifying for more than 14 chars + <CR> hangs your system! <
'
DEFINT A-Z
DECLARE SUB PokeBuffer (Cmd$)
CLS
PRINT "POKEBUFF - Subroutine Demo                       25 April 92"
PRINT " by David Poskie": PRINT
PRINT "This program demonstrates the PokeBuffer subroutine. It will"
PRINT " enter the command, 'DIR /W' to be used by DOS after this"
PRINT " program ends.": PRINT
PRINT "Press a key to quit this program . . ";
SLEEP
Work$ = "DIR /W"
CALL PokeBuffer(Work$)
PRINT : PRINT "POKEBUF.BAS ends here."
SYSTEM ' End of demo program
'      ================ Subroutine Begins Here ================
' POKEBUFF.SUB - Puts a string into key buffer - QBASIC 1.0 Subroutine
'    by David L. Poskie         Madison, WI           30 Nov 91
'
' Syntax:   CALL PokeBuffer (Cmd$)
'  Input:
'        Cmd$: A string of up to 14 characters to be used by DOS to invoke
'              the next program when leaving *this* QBASIC program.
' Output:
'        Cmd$ in the DOS key buffer
'
'> NOTE: Modifying for more than 14 chars + <CR> will hang your system!<
'
SUB PokeBuffer (Cmd$) STATIC
   '
   ' Limit the string to 14 characters plus <CR> and get its length
   Work$ = LEFT$(Cmd$, 14) + CHR$(13)
   Length% = LEN(Work$)
   '
   ' Set the segment for poking
   DEF SEG = 0
   '
   ' Define buffer's head & tail
   POKE 1050, 30
   POKE 1052, 30 + Length% * 2
   '
   ' Then poke each character.
   FOR Index% = 1 TO Length%
      POKE 1052 + Index% * 2, ASC(MID$(Work$, Index%))
   NEXT Index%
   '
END SUB ' PokeBuffer
