2016-01-05 14:45:51 +00:00
|
|
|
<!doctype linuxdoc system> <!-- -*- text-mode -*- -->
|
|
|
|
|
|
|
|
<article>
|
|
|
|
|
|
|
|
<title>sim65 Users Guide
|
2019-05-26 03:38:18 +00:00
|
|
|
<author><url url="mailto:polluks@sdf.lonestar.org" name="Stefan A. Haubenthal">,<newline>
|
|
|
|
<url url="mailto:bbbradsmith@users.noreply.github.com" name="Brad Smith">
|
|
|
|
|
2016-01-05 14:45:51 +00:00
|
|
|
|
|
|
|
<abstract>
|
|
|
|
sim65 is a simulator for 6502 and 65C02 CPUs. It allows to test target
|
2019-05-25 06:56:53 +00:00
|
|
|
independent code.
|
2016-01-05 14:45:51 +00:00
|
|
|
</abstract>
|
|
|
|
|
|
|
|
<!-- Table of contents -->
|
|
|
|
<toc>
|
|
|
|
|
|
|
|
<!-- Begin the document -->
|
|
|
|
|
|
|
|
<sect>Overview<p>
|
|
|
|
|
|
|
|
|
2019-05-25 06:56:53 +00:00
|
|
|
sim65 is used as part of the toolchain to test 6502 or 65C02 code.
|
2019-05-25 07:00:44 +00:00
|
|
|
The binary to test should be compiled with <tt/--target sim6502/ or <tt/--target sim65c02/.
|
2016-01-05 14:45:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
<sect>Usage<p>
|
|
|
|
|
|
|
|
The simulator is called as follows:
|
|
|
|
|
|
|
|
<tscreen><verb>
|
2019-02-12 21:50:49 +00:00
|
|
|
Usage: sim65 [options] file [arguments]
|
|
|
|
Short options:
|
|
|
|
-h Help (this text)
|
|
|
|
-c Print amount of executed CPU cycles
|
|
|
|
-v Increase verbosity
|
|
|
|
-V Print the simulator version number
|
|
|
|
-x <num> Exit simulator after <num> cycles
|
|
|
|
|
|
|
|
Long options:
|
|
|
|
--help Help (this text)
|
|
|
|
--cycles Print amount of executed CPU cycles
|
|
|
|
--verbose Increase verbosity
|
|
|
|
--version Print the simulator version number
|
2016-01-05 14:45:51 +00:00
|
|
|
</verb></tscreen>
|
|
|
|
|
2023-05-07 20:51:12 +00:00
|
|
|
sim65 will exit with the error code of the simulated program,
|
|
|
|
which is limited to an 8-bit result 0-255.
|
|
|
|
|
|
|
|
An error in sim65, like bad arguments or an internal problem will exit with <tt/1/.
|
|
|
|
|
2023-11-14 06:22:36 +00:00
|
|
|
A timeout from <tt/-x/ will exit with <tt/2/.
|
2023-05-07 20:51:12 +00:00
|
|
|
|
2016-01-05 14:45:51 +00:00
|
|
|
|
|
|
|
<sect1>Command line options in detail<p>
|
|
|
|
|
|
|
|
Here is a description of all the command line options:
|
|
|
|
|
|
|
|
<descrip>
|
|
|
|
|
|
|
|
<tag><tt>-h, --help</tt></tag>
|
|
|
|
|
|
|
|
Print the short option summary shown above.
|
|
|
|
|
|
|
|
|
2016-07-05 15:07:39 +00:00
|
|
|
<tag><tt>-c, --cycles</tt></tag>
|
|
|
|
|
|
|
|
Print the number of executed CPU cycles when the program terminates.
|
|
|
|
The cycles for the final "<tt>jmp exit</tt>" are not included in this
|
|
|
|
count.
|
|
|
|
|
|
|
|
|
2016-01-05 14:45:51 +00:00
|
|
|
<tag><tt>-v, --verbose</tt></tag>
|
|
|
|
|
|
|
|
Increase the simulator verbosity.
|
|
|
|
|
|
|
|
|
|
|
|
<tag><tt>-V, --version</tt></tag>
|
|
|
|
|
|
|
|
Print the version number of the utility. When submitting a bug report,
|
|
|
|
please include the operating system you're using, and the compiler
|
|
|
|
version.
|
|
|
|
|
|
|
|
|
|
|
|
<tag><tt>-x num</tt></tag>
|
|
|
|
|
|
|
|
Exit simulator after num cycles.
|
|
|
|
</descrip>
|
|
|
|
|
|
|
|
|
|
|
|
<sect>Input and output<p>
|
|
|
|
|
2016-01-05 16:45:18 +00:00
|
|
|
The simulator will read one binary file per invocation and can log the
|
|
|
|
program loading and paravirtualization calls to stderr.
|
2016-01-05 14:45:51 +00:00
|
|
|
|
|
|
|
Example output for the command
|
|
|
|
<tscreen><verb>
|
|
|
|
sim65 --verbose --verbose samples/gunzip65
|
|
|
|
</verb></tscreen>
|
|
|
|
<tscreen><verb>
|
2019-01-05 19:57:12 +00:00
|
|
|
Loaded 'samples/gunzip65' at $0200-$151F
|
2016-01-05 14:45:51 +00:00
|
|
|
PVWrite ($0001, $13C9, $000F)
|
|
|
|
GZIP file name:PVWrite ($0001, $151F, $0001)
|
|
|
|
|
|
|
|
PVRead ($0000, $FFD7, $0001)
|
|
|
|
PVOpen ("", $0001)
|
|
|
|
PVRead ($0003, $1520, $6590)
|
|
|
|
PVClose ($0003)
|
|
|
|
PVWrite ($0001, $13D9, $000F)
|
|
|
|
Not GZIP formatPVWrite ($0001, $151F, $0001)
|
|
|
|
|
|
|
|
PVExit ($01)
|
|
|
|
</verb></tscreen>
|
|
|
|
|
|
|
|
|
2019-05-25 06:56:53 +00:00
|
|
|
<sect>Creating a Test in C<p>
|
|
|
|
|
2019-05-25 17:42:13 +00:00
|
|
|
For a C test compiled and linked with <tt/--target sim6502/ the
|
2019-05-25 06:56:53 +00:00
|
|
|
command line arguments to <tt/sim65/ will be passed to <tt/main/,
|
|
|
|
and the return value from <tt/main/ will become sim65's exit code.
|
|
|
|
The <tt/exit/ function may also be used to terminate with an exit code.
|
2022-04-17 14:05:10 +00:00
|
|
|
|
2019-05-25 06:56:53 +00:00
|
|
|
Exit codes are limited to 8 bits.
|
|
|
|
|
2019-05-30 19:34:05 +00:00
|
|
|
The standard C library high level file input and output is functional.
|
|
|
|
A sim65 application can be written like a command line application,
|
|
|
|
providing arguments to <tt/main/ and using the <tt/stdio.h/ interfaces.
|
2019-05-25 17:42:13 +00:00
|
|
|
|
2019-05-30 19:34:05 +00:00
|
|
|
Internally, file input and output is provided at a lower level by
|
|
|
|
a set of built-in paravirtualization functions (<ref id="paravirt-internal" name="see below">).
|
2019-05-27 18:57:31 +00:00
|
|
|
|
2019-05-25 06:56:53 +00:00
|
|
|
|
|
|
|
<sect>Creating a Test in Assembly<p>
|
|
|
|
|
2019-05-25 07:00:44 +00:00
|
|
|
Assembly tests may similarly be assembled and linked with
|
2023-05-07 20:35:05 +00:00
|
|
|
<tt/--target sim6502/ or <tt/--target sim65c02/.
|
|
|
|
Define and export <tt/_main/ as an entry point,
|
|
|
|
and the sim65 library provides two ways to return an 8-bit exit code:
|
|
|
|
|
|
|
|
<itemize>
|
|
|
|
|
|
|
|
<item>Return from <tt/_main/ with the exit code in <tt/A/.
|
|
|
|
|
|
|
|
<item><tt/jmp exit/ with the code in <tt/A/.
|
|
|
|
|
|
|
|
</itemize>
|
2019-05-25 06:56:53 +00:00
|
|
|
|
2019-05-29 20:04:54 +00:00
|
|
|
The binary file has a 12 byte header:
|
2019-05-25 06:56:53 +00:00
|
|
|
|
|
|
|
<itemize>
|
|
|
|
|
2019-05-29 20:14:48 +00:00
|
|
|
<item>5 byte <bf/signature/: <tt/$73, $69, $6D, $36, $35/ or <tt/'sim65'/
|
2019-05-25 06:56:53 +00:00
|
|
|
|
2019-05-29 20:14:48 +00:00
|
|
|
<item>1 byte <bf/version/: <tt/2/
|
2019-05-29 20:04:54 +00:00
|
|
|
|
2019-05-29 20:14:48 +00:00
|
|
|
<item>1 byte <bf/CPU type/: <tt/0/ = 6502, <tt/1/ = 65C02
|
2019-05-29 20:04:54 +00:00
|
|
|
|
2019-05-29 20:14:48 +00:00
|
|
|
<item>1 byte <bf/sp address/: the zero page address of the C parameter stack pointer <tt/sp/ used by the paravirtualization functions
|
2019-05-29 20:04:54 +00:00
|
|
|
|
2019-05-29 20:14:48 +00:00
|
|
|
<item>1 word <bf/load address/: where to load the data from the file into memory (default: <tt/$0200/)
|
2019-05-29 20:04:54 +00:00
|
|
|
|
2019-05-29 20:14:48 +00:00
|
|
|
<item>1 word <bf/reset address/: specifies where to begin execution after loading (default: <tt/$0200/)
|
2019-05-29 20:04:54 +00:00
|
|
|
|
|
|
|
</itemize>
|
|
|
|
|
|
|
|
Other internal details:
|
|
|
|
|
|
|
|
<itemize>
|
2019-05-25 06:56:53 +00:00
|
|
|
|
|
|
|
<item>The entire 64 kilobyte address space is writeable RAM.
|
|
|
|
Aside from the loaded binary, the reset vector at <tt/$FFFC/ will be
|
2019-05-29 20:14:48 +00:00
|
|
|
pre-loaded with the given <bf/reset address/.
|
2019-05-25 06:56:53 +00:00
|
|
|
|
2019-05-29 22:10:17 +00:00
|
|
|
<item>The <tt/exit/ address is <tt/$FFF9/.
|
2019-05-25 06:56:53 +00:00
|
|
|
Jumping to this address will terminate execution with the A register value as an exit code.
|
|
|
|
|
2019-05-30 19:34:05 +00:00
|
|
|
<label id="paravirt-internal">
|
|
|
|
<item>Several bytes immediately below the vector table are reserved for paravirtualization functions.
|
|
|
|
Except for <tt/exit/, a <tt/JSR/ to one of these addresses will return immediately after performing a special function.
|
|
|
|
These use cc65 calling conventions, and are intended for use with the sim65 target C library.
|
|
|
|
|
2019-05-25 06:56:53 +00:00
|
|
|
<item><tt/IRQ/ and <tt/NMI/ events will not be generated, though <tt/BRK/
|
|
|
|
can be used if the IRQ vector at <tt/$FFFE/ is manually prepared by the test code.
|
|
|
|
|
|
|
|
</itemize>
|
|
|
|
|
2016-01-05 14:45:51 +00:00
|
|
|
|
|
|
|
<sect>Copyright<p>
|
|
|
|
|
|
|
|
sim65 (and all cc65 binutils) are (C) Copyright 1998-2000 Ullrich von
|
|
|
|
Bassewitz. For usage of the binaries and/or sources the following conditions
|
|
|
|
do apply:
|
|
|
|
|
|
|
|
This software is provided 'as-is', without any expressed or implied
|
|
|
|
warranty. In no event will the authors be held liable for any damages
|
|
|
|
arising from the use of this software.
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
including commercial applications, and to alter it and redistribute it
|
|
|
|
freely, subject to the following restrictions:
|
|
|
|
|
|
|
|
<enum>
|
2019-02-12 21:50:49 +00:00
|
|
|
<item> The origin of this software must not be misrepresented; you must not
|
|
|
|
claim that you wrote the original software. If you use this software
|
|
|
|
in a product, an acknowledgment in the product documentation would be
|
|
|
|
appreciated but is not required.
|
|
|
|
<item> Altered source versions must be plainly marked as such, and must not
|
|
|
|
be misrepresented as being the original software.
|
|
|
|
<item> This notice may not be removed or altered from any source
|
|
|
|
distribution.
|
2016-01-05 14:45:51 +00:00
|
|
|
</enum>
|
|
|
|
|
|
|
|
</article>
|