65816 emulator available?

Topics pertaining to the emulation or simulation of the 65xx microprocessors and their peripheral chips.
Post Reply
User avatar
Ruud
Posts: 259
Joined: 12 Dec 2003
Location: Heerlen, NL
Contact:

65816 emulator available?

Post by Ruud »

Hallo allemaal,


I'm busy with the 65816 core. Is there a 65816 emulator available that enables me to test my (still to create) ASM file?

Thank you!

Code: Select all

    ___
   / __|__
  / /  |_/     Groetjes, Ruud 
  \ \__|_\
   \___|       URL: www.baltissen.org

User avatar
BigEd
Posts: 11464
Joined: 11 Dec 2008
Location: England
Contact:

Post by BigEd »

Yep! Samuel's lib65816
User avatar
Ruud
Posts: 259
Joined: 12 Dec 2003
Location: Heerlen, NL
Contact:

Post by Ruud »

BigEd wrote:
Yep! Samuel's lib65816
It looks to me like a library for C ???
Not being a C programmer I prefer something VICE like i.e. something that enables me to load a program and check it with a monitor.

Code: Select all

    ___
   / __|__
  / /  |_/     Groetjes, Ruud 
  \ \__|_\
   \___|       URL: www.baltissen.org

User avatar
BigEd
Posts: 11464
Joined: 11 Dec 2008
Location: England
Contact:

Post by BigEd »

Ah yes, it looks like I wrote/borrowed a command-line invocation wrapper called run65816 (modeled after run6502)

Perhaps you could use KEGS?

Or I could try to help you with run65816 (which is unpublished) [Edit - now published - see below]

Code: Select all

$ ./run65816 -B -l 0 bbc.img
loading ROM file bbc.img
WARP FACTOR 5

BBC Computer 32K

BASIC

>PRINT PI
3.14159265
>

Code: Select all

$ ./run65816 [option ...] -B [image ...]
  -B                -- (mandatory) minimal Acorn 'BBC Model B' compatibility
  -h                -- help (print this message)
  -l addr file      -- load file at addr
  image             -- '-l 8000 image' in available ROM slot

'last' can be an address (non-inclusive) or '+size' (in bytes)
Quote:
$ less README.txt
Ed S
2009-03-28

run65816.c is a minimal BBC-micro emulator based on a test program
posted on 6502.org by Samuel A. Falvo II aka kc5tja and also based
on run6502 by Ian Piumarta which forms part of his lib6502 package

it emulates a BBC micro with a 65816, additional RAM, and some
supporting decode logic.

usage:
./run65816 -B -l c000 ../rom-images/OS12.ROM \
../rom-images/BASIC2.ROM ../boot816/boot816.bin

the Makefile is adjusted to build run65816 as well as lib65816

lib65816 has been tweaked to support run65816:
src/dispatch.c
to use the new M_FETCH instead of M_READ for instruction fetches
to resurrect the E_UPDATE cycle count mechanism for regular IRQs
config.mk
to pick up CCOPTS and to add the -g flag to cc
to default CCOPTS to add -DDEBUG -DOLDCYCLES for tracing and E_UPDATE
lib65816/cpu.h
to define the new M_FETCH

TODO/BUGS
BRK is handled by appropriating the WDM opcode hook
WDM is not available to trigger tracing or stack dumps
IRQ vector is pulled from bank0, with no easy way to emulate hardware redirection
Most of the run6502 command line interface is not ported
There's no means of selecting non-BBC or other hardware variants
There's no command line interface to the tracing capability
The regular IRQs are done using a deprecated mechanism
The regular IRQs are not done by emulating VIA hardware
Should handle Vector Pull and Valid Program Address by passing up from lib65816 to the emulator
Last edited by BigEd on Fri Jun 12, 2015 3:56 pm, edited 2 times in total.
kc5tja
Posts: 1706
Joined: 04 Jan 2003

Post by kc5tja »

lib65816 is a library, hence the 'lib' part of its name. It's intended to be linked into an emulator driver.

run65816, which uses lib65816 IIRC, is probably what you're looking for. I was thinking of writing a similar CLI-based invoker to develop a Forth image that I could port elsewhere, but never got around to it.

lib65816 is used in my Kestrel-2 emulator, but I suspect that's way overkill, and I don't have any OS for it. Since it lacks a text-mode display, you'd have to write your own text output routines.
User avatar
BigEd
Posts: 11464
Joined: 11 Dec 2008
Location: England
Contact:

Post by BigEd »

Ruud wrote:
BigEd wrote:
Yep! Samuel's lib65816
It looks to me like a library for C ???
Not being a C programmer I prefer something VICE like i.e. something that enables me to load a program and check it with a monitor.
Hi Ruud I'm away from keyboard, but the MESS emulator has an apple2gs mode and some kind of debugger - might be worth a try
Cheers Ed
User avatar
Ruud
Posts: 259
Joined: 12 Dec 2003
Location: Heerlen, NL
Contact:

Post by Ruud »

Hallo BigEd, kc5tja,

Thank you for your input. Your ideas about the 2GS are good but there is a small problem: I have no idea how to operate this computer. OK, everything can be learned but I doubt if have the patience for it or the time. Then I rather prefer BigEd's BBC emulator.

I'm also thinking of equiping one of my Commodores of the 3000 series with a 65816 and replace the ROM with my test-FRAM. The advantage of the 3000 series is that they have a TTL-video part i.e. no initialisation of the video-IC needed. This is way how I tested the ROM for the 6502 under VICE.

Code: Select all

    ___
   / __|__
  / /  |_/     Groetjes, Ruud 
  \ \__|_\
   \___|       URL: www.baltissen.org

User avatar
BigEd
Posts: 11464
Joined: 11 Dec 2008
Location: England
Contact:

Post by BigEd »

Ruud wrote:
... prefer BigEd's BBC emulator.
But sadly there's no built-in monitor or debug. In fact I don't think I've yet run a 65816 single-stepper. There are several possible ways forward:
- Daryl's Sysmon (SBC monitor) can do most things
- Jammon might be good but I haven't yet seen it working (based on C64/SuperCPU)
- The Apple II gs has a ROM-resident monitor, so a GS emulator like KEGS, MESS or Florence should be able to run that
- Each of those GS emulators also have a debugger at the emulator level - it might be possible to boot into your own code and single-step it, without needing any I/O or machine initialisation
- There are also SNES emulators out there.
- running any emulator, including one based on lib65816, inside gdb might allow for some means of single stepping, dumping machine state and setting breakpoints. If there's a function to print machine state, that could be called (I think) from gdb.
- finally, it's surely possible to write a debugger for lib65816 (but I'm not likely to do it)

For me, probably booting a GS emulator and trying the Apple monitor would be the first tactic to try. It looks like I did have KEGS running BASIC a year ago, so it shouldn't be too hard to do that.

Edit: turns out to be easy to download and run KEGS - even with a ROM, it's just about possible to use the emulator's debugger to load code, single step it and see the machine state. (Middle-mouse to get into the debugger - some trouble with the way it reads some extra junk character on each newline, so I cleaned up the following a bit.)

This is on Windows, but using cygwin:

Code: Select all

$ echo ea200000|xxd -r -p > test.dmp

> 0ultest.dmp
Unix commands
Loading..About to open: test.dmp,len: 8
Read/write: addr 000000 for 20000 bytes, ret: 4 bytes

> 0l
1=m 1=x 1=LCBANK
00/0000: ea             NOP
00/0001: 20 00 00       JSR     $0000
00/0004: 00 00          BRK     $00

> ^E
  PC=00.0001 A=0000 X=0000 Y=0000 P=134 S=0133 D=0000 B=00,cyc:8089250.144

> s
leaving run_prog, halt_sim:0
  PC=00.0000 A=0000 X=0000 Y=0000 P=134 S=0131 D=0000 B=00,cyc:8089250.188
00/0000: ea             NOP

> h
KEGS Debugger help (courtesy Fredric Devernay
General command syntax: [bank]/[address][command]
e.g. 'e1/0010B' to set a breakpoint at the interrupt jump pt
Enter all addresses using lower-case
As with the IIgs monitor, you can omit the bank number after
having set it: 'e1/0010B' followed by '14B' will set
breakpoints at e1/0010 and e1/0014

g                       Go
[bank]/[addr]g          Go from [bank]/[address]
s                       Step one instruction
[bank]/[addr]s          Step one instr at [bank]/[address]
[bank]/[addr]B          Set breakpoint at [bank]/[address]
B                       Show all breakpoints
[bank]/[addr]D          Delete breakpoint at [bank]/[address]
[bank]/[addr1].[addr2]  View memory
[bank]/[addr]L          Disassemble memory
P                       Dump the trace to 'pc_log_out'
Z                       Dump SCC state
I                       Dump IWM state
[drive].[track]I        Dump IWM state
E                       Dump Ensoniq state
[osc]E                  Dump oscillator [osc] state
R                       Dump dtime array and events
T                       Show toolbox log
[bank]/[addr]T          Dump tools using ptr [bank]/[addr]
                            as 'tool_set_info'
[mode]V                 XOR verbose with 1=DISK, 2=IRQ,
                         4=CLK,8=SHADOW,10=IWM,20=DOC,
                         40=ABD,80=SCC, 100=TEST, 200=VIDEO
[mode]H                 XOR halt_on with 1=SCAN_INT,
                         2=IRQ, 4=SHADOW_REG, 8=C70D_WRITES
r                       Reset
[0/1]=m                 Changes m bit for l listings
[0/1]=x                 Changes x bit for l listings
[t]=z                   Stops at absolute time t (obsolete)
S                       show_bankptr_bank0 & smartport errs
P                       show_pmhz
A                       show_a2_line_stuff show_adb_log
Ctrl-e                  Dump registers
[bank]/[addr1].[addr2]us[file]  Save mem area to [file]
[bank]/[addr1].[addr2]ul[file]  Load mem area from [file]
v                       Show video information
q                       Exit Debugger (and KEGS)
>
User avatar
BigEd
Posts: 11464
Joined: 11 Dec 2008
Location: England
Contact:

Re: 65816 emulator available?

Post by BigEd »

Due to popular demand (one request) I decided to publish run65816 with a GPL license - see attached.

This is a minimal wrapper for Sam Falvo's lib65816, which you'll find at
https://github.com/sam-falvo/lib65816 (previously at https://bitbucket.org/kc5tja/lib65816)

Cheers
Ed

Edit: fix linkrot
Attachments
run65816.tgz
(5.42 KiB) Downloaded 488 times
Last edited by BigEd on Sat Oct 24, 2020 2:58 pm, edited 1 time in total.
kc5tja
Posts: 1706
Joined: 04 Jan 2003

Re: 65816 emulator available?

Post by kc5tja »

By request, I'm listing a link to my lib65816 library here: https://bitbucket.org/kc5tja/lib65816

Documentation is pertty sucky, but here's a project for a very early Kestrel emulator where I use lib65816 to emulate its CPU. https://bitbucket.org/kc5tja/kestrel-em ... at=default
Post Reply