cbm64c

Index Home cbm64c

CBM64C

Cbm64c is a Commodre-64 BASIC compiler and run-time environment. It is not a Commodore-64 emulator - it cannot process 6502 machine language.  Instead, it compiles the BASIC program into p-codes and then executes the p-codes.  The p-codes are built off a generic Basic class, which is built on top of a Forth interpreter class.

When running a BASIC program, a terminal screen is used.  When the program finishes, the terminal screen is cleared.  To delay that screen clear, use -confirm to wait for user confirmation to exit.

Note that the disk subsystem is only rudimentarily supported.  Graphics mode is not supported. SYS is nominally supported. General I/O is well supported and may be integrated with the host system via command line options.

Command Line Options

filename

Load the file into the run-time environment.  The file may be a .pcx file (see -o), which is ready to execute; a .bas file, which is ready to compile; or a C-64 PRG file, which contains tokenized BASIC.  For a .bas or PRG file, cbm64c will compile the source code; for a .pcx file, it is ready to run without compiling.

-c

Only compile the file; do not run it. See -run.

-o filename

Output file for the compiled BASIC program. By convention, the filename exension is .pcx (p-code executable). If -run was also specified, then the dataspace state will be post-execution, which includes allocated variable and array values, but it does not include any values in the dataspace above those.  To save out that data, use -writemem.  If -run was not specified, then the .pcx file will include just blank allocated variables.

-run

After compiling the BASIC file, run it.  See -c. Note that the program runs in a terminal window that is cleared upon program completion. If your program simply outputs "Hello, World", you will see no output because it displays too fast. See -confirm to allow you to see the output.

-confirm

Upon program completion, wait for the user to press a key before clearing the terminal window.  This allows the user to view the terminal window, especially if the user is not able to select Quit inside the BASIC program. In the case of a "Hello, World" program, this allows the user to see the output before it is cleared.

-list

If a .bas or PRG file was provided, this option will output the BASIC source code to stdout.

There is a bug where some junk text will be output up to a " >" before the source listing.

-code

Display the p-codes of the compiled BASIC program to stderr.  The p-codes are based upon a multi-stack environment (integer, floating point, string, and return/system) with separated code and data spaces. Note that each data unit holds 8 bytes, which is large enough to hold a byte, integer, long, float, double float, or 8 characters of a string. Dynamic strings are managed outside the dataspace.

-slow

By default, the BASIC program is run at full speed if the host system. It can regulate delays by watching the TIME variable, which increments every 1/60th of a second.  Specify -slow to slow down program execution substantially, so output doesn't flash by so fast.

-monitor

After the p-codes are loaded into the run-time environment (and optionally the program run), the user is placed at the environment monitor prompt, which is a Forth intereter. Note that the BASIC program is not at $800; it is in a separate code space, starting at $0.  Instead, allocated variables start at $800. To fetch a variables address, use the keyword var_name, where name is capitalized and appended with type, e.g. var_A (float), var_A% (int), var_A$ (string), var_A() (float array), etc. To resume execution at a specific line, use the keyword LNline# where line# is the line number to execute, e.g. LN1000.

-screen filename

-cmd filename

This command line option redirects all output for the Commodore-64 screen to the specified file instead.  Note that any use of the Commodre 64 cursor or special keys will go to that output as well.  -cmd is an alternate form of the same command, named after the BASIC CMD command which redirects output.

-kbd filename

This option redirects queries for keyboard characters (form GET or INPUT) to instead read from the provided filename.  If the program continues to run after file EOF is reached, input resumes from the terminal keyboard.

-cass dirpath

The cassette device contains a series of files/programs which can be loaded.  Put those files into a directory and specify that directory path using dirpath (including the trailing /). When your program opens a file on the cassette, it will instead open the file in that directory.  If not specified, the current directory is used.

-diskn dirpath

The Disk number, n, ranges from 1 to 4.  The each disk drive contains a series of files/programs which can be loaded.  Put those files into a directory and specify that directory path using dirpath (including the trailing /). When your program opens a file on the disk drive, it will instead open the file in that directory.  If disk1 is not specified, the current directory is used.

-devn filename

The device number, n, ranges from 0 to 255.  Note that device 0, 1, 3, 4, and 8-11 have default behavior in cbm64c, but you can override that with this command (except for file system devices 1, 8, 9, 10, 11).  The filename provided may be used for reading or writing (per the BASIC program's logic).

-rdevn filename

The read-only device number, n, ranges from 0 to 255.  Note that device 0, 1, 3, 4, and 8-11 have default behavior in cbm64c, but you can override that with this command (except for file system devices 1, 8, 9, 10, 11).  The filename provided may be used for reading only; if the BASIC program attempts a write, it will err out.

-wdevn filename

The write-only device number, n, ranges from 0 to 255.  Note that device 0, 1, 3, 4, and 8-11 have default behavior in cbm64c, but you can override that with this command (except for file system devices 1, 8, 9, 10, 11).  The filename provided may be used for writing only; if the BASIC program attempts a read, it will err out.

-memwrite low  high  filename

Write out a block of dataspace values from the low address to the high address, which may range from 0 to 65535.  This data may later be read back using -memread.  The write operation is performed after any program execution.

-memread filename

Read in a block of dataspace values back in before any program execution.  The file must have been generated by -memwrite.