# SAM

"Frodo! Mr.Frodo, my dear!" cried Sam,
tears almost blinding him. "It's Sam, I've come!"

Frodo has a built-in machine language monitor that can be activated at any time by pressing F9 (Unix) or selecting the appropriate menu item (BeOS/AmigaOS/MacOS): SAM (Simple Assembler and Monitor). It provides full access to the memory and hardware of the emulated C64 and 1541 (under BeOS, you must only start SAM if you launched Frodo from the Shell).

SAM is controlled by a command-based interface, all numbers are in hex. With the command "h" you can display a list of all commands. The command "x" quits SAM and returns to Frodo.

SAM has two modes of operation, indicated by the prompt "C64>" or "1541>". You can switch between them with the "64" and "1541" commands. In "C64" mode, all commands that access memory or the CPU operate on the memory/CPU of the emulated C64. In "1541" mode, they operate on the emulated 1541 (this is only useful if the processor-level 1541 emulation is turned on).

All commands that access the C64 memory use the memory configuration set with the "k" command. On starting up SAM, the configuration is set to the one the processor is in. Accesses from within SAM have the same effect as accesses of the emulated processor. This affects especially the I/O registers: a memory dump of $dc00-$de00 clears pending CIA interrupts as SAM reads from $dc0d and $dd0d. With the "v" commands, you can examine the state of the I/O chips without modifying the state of the emulation.

In all places where SAM expects a number (except in the assembler) you can also enter an expression of hex numbers containing '+', '-', '*', '/' and parens. Commands that create a longer output can be interrupted with Ctrl-C.

Here is a description of all commands ('[]' marks a parameter than can be left out, '{}' marks a parameter that can be repeated many times. If a [start] parameter is left out, SAM continues at the address where the last command stopped):

     a [start]           Assemble

starts the assembler at the address "start". SAM always prints the address where the next instruction will be written to. The syntax of the instructions conforms to the standard except for shift/rotation instructions in the "accumulator" addressing mode. Those have to be entered without operand, e.g. "lsr" instead of "lsr a". Entering a blank line quits the assembler and returns to the command mode of SAM.

     b [start] [end]     Binary dump

displays the memory from "start" to "end" byte-wise binary. With this command, you can view character sets.

     c start end dest    Compare memory

compares the memory in the range from "start" to (and including) "end" with the memory at "dest". The addresses of all different bytes and the total number of differences (decimal) are printed.

     d [start] [end]     Disassemble

disassembles the memory from "start" to "end". Undocumented opcodes are markes with a star '*'.

     e                   Show interrupt vectors

shows the currently active interrupt vectors of the 6510 (C64) or 6502 (1541) and (in C64 mode, if the Kernal ROM is mapped in) of the Kernal.

     f start end byte    Fill memory

fills the memory in the range from "start" to (and including) "end" with the value "byte".

     i [start] [end]     ASCII/PETSCII dump

shows the memory from "start" to "end" as ASCII/PETSCII characters.

     k [config]          Show/set C64 memory configuration

"k" without parameters shows the memory configuration that is set for SAM, "k" with parameter modifies it. On exiting SAM, the configuration set with the processor port is reactivated. The memory configuration has no effect in 1541 mode. The 8 possible configurations are:

      #  $a000-$bfff  $d000-$dfff  $e000-$ffff
      ----------------------------------------
      0      RAM          RAM          RAM
      1      RAM       Char ROM        RAM
      2      RAM       Char ROM    Kernal ROM
      3   Basic ROM    Char ROM    Kernal ROM
      4      RAM          RAM          RAM
      5      RAM          I/O          RAM
      6      RAM          I/O      Kernal ROM
      7   Basic ROM       I/O      Kernal ROM

     l start "file"      Load data

loads the contents of the specified file into memory starting from address "start". The file name must be enclosed in quotation marks even if it contains no spaces. This command cannot be used to load C64 programs as it doesn't respect the embedded load address in the programs.

     m [start] [end]     Memory dump

displays the memory from "start" to "end" as hexadecimal numbers and ASCII characters.

     n [start] [end]     Screen code dump

displays the memory from "start" to "end" as ASCII characters, interpreting each byte as a screen code of the standard character set.

     o ["file"]          Redirect output

When a file name is specified, all following output is redirected to this file. The file name must be enclosed in quotation marks even if it contains no spaces. Entering "o" without parameters closes the file and directs the output into the window of SAM again.

     p [start] [end]     Sprite dump

displays the memory from "start" to "end" binary with three bytes per line. With this command, you can display sprite data.

     r [reg value]       Show/set CPU registers

"r" without parameters shows all 6510 (C64) or 6502 (1541) registers and flags and the instruction at the address specified by the program counter. For the 6510, "DR" and "PR" are the data direction register and data register of the processor port. To modify a register, give its name ("reg") and the new value ("value") as parameters.

     s start end "file"  Save data

writes the memory from "start" to (and including) "end" to the specified file. The file name must be enclosed in quotation marks even if it contains no spaces. This command cannot be used to save C64 programs as it doesn't save a load address in the file.

     t start end dest    Transfer memory

transfers the memory from "start" to (and including) "end" to "dest". Source and destination may overlap.

     vc1                 View CIA 1 state

shows the state of CIA 1 ($dc00).

     vc2                 View CIA 2 state

shows the state of CIA 2 ($dd00).

     vf                  View floppy state

shows the state of the processor-level 1541 emulation.

     vs                  View SID state

shows the state of the SID.

     vv                  View VIC state

shows the state of the VIC.

     x                   Return to Frodo

quits SAM and returns to Frodo.

     : addr {byte}       Modify memory

writes the space-separated values "byte" into memory starting at "addr".

     1541                Switch to 1541 mode

switches to 1541 mode. All commands that access memory or the CPU will then operate on the emulated 1541 (processor-level).

     64                  Switch to C64 mode

switches to C64 mode. All commands that access memory or the CPU will then operate on the emulated C64.

     ? expression        Calculate expression

calculates the value of the given expression and displays it in decimal and hexadecimal.