0.1.0 • Published 2 years ago

@sfotty-pie/cli v0.1.0

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

Sfotty Pie CLI

Sfotty Pie CLI is an emulator for a virtual 6502-based computer. The current implementation allows you two write CLI programs with access to stdin, stdout, and stderr.

Executable file format

OffsetSizeDescription
0x00000x06Magic number (The word SFOTTY in ASCII)
0x00060x04Reserved (must be zero)
0x000A0x06Interrupt vectors
0x0010variableProgram contents

System documentation

The interrupt vectors are the NMI, reset, and IRQ vectors, in that order. They are loaded starting from the address $FFFA. The NMI and IRQ vectors are currently unused and should be set to 0. The reset vector at $FFFC is the main program entry.

The program contents are loaded starting from the address $0400.

Page 2 (addresses from $0200 to $02FF) is reserved for I/O operations. Currently, the following I/O operations are defined:

AddressNameRead / WriteDescription
$0200EXITWAny write here exists the program with the written exit code.
$0201STDINRRead a byte from the standard input (blocking).
$0202STDOUTWWrite a byte to the standard output.
$0203STDERRWWrite a byte to the standard error.
$0240RANDRRead a random byte.
$0241FSTINRStatus of stdin: EOF if bit 7 set.

On program start, all CPU registers will be in an unknown state. In particular, you should remember to clear the decimal flag. page 3 (addresses from $0300 to $03FF) will contain the command line arguments as a null-terminated list of null-terminated strings.

Everything other than the I/O area is RAM, including the command line argument area, the program contents, and the interrupt vectors. Free areas will contain all zeroes.

Executing an undocumented opcode ends the program with exit code 2.

Sample programs

Executables for the sample programs are in the samples directory. The sources are available in src/samples. You need the ca65 assembler from the cc65 package to build them.

NameDescription
helloPrints "Hello, world!" to stdout.
catReads stdin and writes to stdout.
echoPrints the arguments to stdout.
guessGuess the number game.

Ideas for future versions

  • Provide a lib6502 implementation (file I/O and more)
  • Provide a cc65 library implementation