Directory Dark Arts: The Auto Run Injection code

Directory Dark Arts: The Auto Run Injection code

Well, my dirart injection code from previous articles would work properly if there was no ” quotes in the filename. Once the directory command encounters the double quote it disables certain command codes from working. We are going to make an autorun command. After you load the directory, it will generate multiple stage basic line of commands which will: clear the screen, load the first file on the disk and run it (after you press enter).

Normally, in basic if you type:

LOAD"*",8

You will need to type run after that.

if you type:

LOAD"*",8:RUN

This will not autorun the program — as after the LOAD command finishes, it forgets to execute the run command. So we have to queue up some commands in advance, ?before? the load? Yes, before.

?CHR$(147):LOAD"*",8 --> Clears the screen then loads

So, there is a way to inject keystrokes into the keyboard buffer located at 631-641 (decimal).

POKE631,82 -> "R"
POKE632,85 -> "U"
POKE633,78 -> "N"
POKE634,58 -> ":"
POKE635,13 -> "[return key]"

So if type that into basic in one line, nothing visually happens. The bytes are in the buffer, but nothing comes out — you need to trigger the buffer to write out.. with:

POKE198,5

So now you get the following command:

?CHR$(147):POKE631,82:POKE632,85:POKE633,78:POKE634,58:POKE635,13:POKE198,5:LOAD"*",8

So entering the above queue of commands will clear the screen then inject RUN:[enter] into the keyboard buffer and tell the system to dump out the buffer and initiate the load command. Because of the order of operations with how the commands are laid out, the run command get queued up after the load starts. Handy 🙂

So how do we fit an 85 letter command string in a 16 letter filename?
We also need to consider that file name has quotes around them and a block count at the beginning and file type at the end. My previous PETSCII/Dirart articles explain how to fool the directory lister to inject command codes like the basic print uses (as the lister uses that too). So as an example..

0 "LOAD"*",8: PRG
0 "Command 2" PRG
0 "Command 1" PRG
0 BLOCKS FREE.
READY.

We need 1 line of basic, without other garbage on the line and the cursor to end up at the end of the listing (after ready) to be on our newly crafted basic command line. Starting with pacing enter commands at the beginning and end of the filename.

0 "
LOAD"*",8:
" PRG
0 "
Command 2
" PRG
0 "
Command 1
" PRG
0 BLOCKS FREE.
READY.

Then we need to issue a few cursor commands, go up 3 lines [up] at the beginning of each file, which ends up overwriting each filename with the last one. looking like this:

Command 1:
" PRG
0 BLOCKS FREE.
READY.

So if we add in 2 more files, to fix this by using the insert commands

0 "[enter][up][up][up]LOAD"*",8:[enter]" PRG
0 "[enter][up][up][up][INS][INS][INS][INS][INS][INS][INS][INS][INS][enter]" PRG
0 "[enter][up][up][up]Command 2:[enter]" PRG
0 "[enter][up][up][up][INS][INS][INS][INS][INS][INS][INS][INS][INS][enter]" PRG
0 "[enter][up][up][up]Command 1:[enter]" PRG
0 BLOCKS FREE.
READY.

And we get the Load command printed first, then its next filename shifts it over, then the next filename goes into the newly created space and so on and so on.. like below

Command 1:Command 2:LOAD"*",8:
" PRG
0 BLOCKS FREE.
READY.

Final filename moves the cursor to the line where our new basic command queue has been setup. Here is what the final code looks like as a directory:

Here it is running in VICE:

After Pressing ENTER:

So in the end you just need to remember a few things:

  1. This only works in a stock c64/1541 setup. Action Replay’s and DOS wedges that uses their own output will likely barf with this.
  2. 79 chars is the limit to the total that a basic line can be before it breaks the screen editor
  3. use short form basic commands
  4. you may need to adjust how far up you go depending on how long the basic line is getting. in the above example, 8 files down from the top you see the up commands go to one less.
  5. Try not to use too many double quotes.. every time they get used the output commands get scrambled. I used the ?CHR$(147) instead of ?”[heart]” because it was less BS.

Leave a Reply

Your email address will not be published. Required fields are marked *