CMD: Your Output Chameleon

CMD: Your Output Chameleon

Ever wish you could send your Commodore 64's text output to somewhere besides the screen? Say hello to CMD, the command that lets you redirect output to a different device like a printer, disk drive, or even a modem! Think of it as a switchboard operator for your text, routing it to wherever you need it to go.

Syntax

CMD <file number> [, <expressions>]

Where: - <file number>: The number (1-255) assigned to the device when you opened it using OPEN. - <expressions>: Optional expressions to print to the device. If omitted, subsequent PRINT statements will send their output to the device until you use CMD again to switch back to the screen.

Applications

The CMD command opens up a world of possibilities, allowing you to:

  • Print documents: Send text directly to a printer without having to save it as a file first.
  • Save data to disk: Write text to a disk file without having to open and close it for each write operation.
  • Communicate over a modem: Transmit text data to another computer or online service.
  • Create custom output: Redirect output to a device driver you've written yourself to create unique effects.

Code Examples

1. Simple Printer Output:

10 OPEN 4,4 :rem Open the printer
20 CMD 4    :rem Redirect output to the printer
30 PRINT "Hello, printer!" :rem This line will be printed
40 CMD 4, "" :rem Stop redirecting (future PRINTs go to the screen)
50 CLOSE 4  :rem Close the printer

This snippet demonstrates how to open a channel to the printer, redirect output to it, print a message, and then close the channel.

2. Saving Data to Disk:

10 OPEN 1,8,8,"DATAFILE,S,W" :rem Open a sequential file for writing
20 CMD 1                     :rem Redirect output to the file
30 FOR I=1 TO 10
40 PRINT I*I                 :rem Write squares of numbers to the file
50 NEXT I
60 CMD 1, ""                 :rem Stop redirecting
70 CLOSE 1                   :rem Close the file

This example writes the squares of the numbers 1 through 10 to a file named "DATAFILE".

CMD in the Wild: The Inter-Commodore Communicator

Imagine you and your friend each have a Commodore 64 connected to a modem. With the CMD command, you could write a program to send messages back and forth, essentially creating a real-time chat application!

Don't be limited by the screen! With CMD, you can take control of your text output and send it wherever your imagination (and hardware) will allow. It's a versatile tool that can add a whole new dimension to your Commodore 64 projects. So go ahead and explore—the world of output awaits!


Privacy Policy

Let's be honest, we collect some data. But we promise not to sell it, we'll mostly use it to improve our service. You can read the nitty-gritty details below, but be warned, it uses big words that lawyers like (we don't judge).

By using our service, you agree to this privacy policy. This disclaimer strikes a balance between lightheartedness and informing users that they should still read the full privacy policy if they choose.