Compare commits

..

21 Commits

Author SHA1 Message Date
byuu
81f43a4d01 Update to snes-20100807 release.
This represents a major code restructuring. The dot-based and
scanline-based renderers are now split into two separate core
libraries, asnes and bsnes.

For now at least, these are -internal- names. I'm not entirely decided
on how I'm going to handle releasing these two separate builds.
Regardless, the folders need names.

asnes has had all of the processor subfolders collapsed back into
their parent folders. In other words, ppu's functions were moved into
ppu/sppu, and then ppu was deleted, and then ppu/sppu became the new
ppu. Repeat this for the cpu, smp and dsp and there you go.

asnes/dsp also removed the DSP_STATE_MACHINE option. This was done for
the sake of consistency with the rest of the core.

asnes' debugger mode is currently extremely broken, but I will be
fixing it in time.

And for now, bsnes has kept the processor abstraction layer. I may
keep it around, not sure yet. It doesn't hurt speed or anything, so
I'm not too worried about making a decision right away.

I may throw snesfilter, snesreader and supergameboy into this folder,
just to have everything in one place. The alternate GUI forks are
definitely going in there as dotnet, cocoa and python.

Compiled output goes to the out/ folder now, to prevent conflicts with
a file and folder named bsnes, for instance.
2010-08-07 15:07:24 +00:00
byuu
9ea739aec1 Update to bsnes v067r05 release.
This will be the final release with the current source structure.

This WIP contains a bugfix so that the last scanline does not fetch
OAM items. This fixes flickering in Ninja Warriors and Lord of the
Rings.
2010-08-07 11:44:19 +00:00
byuu
254a5016e1 Update to bsnes v067r04 release.
This build simplifies the tile cache significantly, and it now builds
the cache and fetches the VRAM data during Hblank, the VRAM reads are
modeled after real hardware.
This fixes Mega lo Mania without regressing Winter Gold or Adventures
of Dr. Franken.
I also fixed a pseudo-hires back color glitch in Super Buster Bros.
2010-08-06 14:06:31 +00:00
byuu
dcc661cb28 Update to bsnes v067r03 release.
This substantially improves the S-PPU dot-renderer's sprite
processing. Instead of happening immediately at the start of the
scanline, each pixel is rendered one at a time. It eliminates the
SpriteList caching, sprite width/height caching, oam_palette caching
and oam_priority caching.

I'll explain it in more detail in the public thread in a bit.

Most noticeable is that Winter Olympics is now perfect, with no known
regressions on any of the sprite-sensitive games.
2010-08-05 14:37:02 +00:00
byuu
431d5c8db7 Update to bsnes v067r01 release.
This adds the SA-1 compiler bug workaround for GCC 4.5.0, and updates
the load special libsnes functions to also generate XML mapping data
if given empty strings.
I built the binary above with GCC 4.5.0, so let me know if any new
problems appear. What I've noticed is that when not profiled, 4.5.0 is
about 3-5% faster, but when profiled, they are equivalent in speed.

Lastly, I did some more work on the .NET/C# and Snow Leopard/Cocoa
ports. They can both load all special types of ROMs, including Super
Game Boy.

For .NET, you need to be on a 64-bit version of Windows, have .NET 3.5
installed, and have SlimDX installed (I used February 2010, but
anything later should be fine.)
For Snow Leopard, you may want to build and install libsupergameboy,
but you don't have to. Just don't try loading SGB games without it.

Yes, the .NET one is pure 64-bit. I built snes.dll and
supergameboy.dll using MinGW64-GCC 4.5.0. Since the core library
doesn't use Qt, it builds fine in 64-bit mode.
2010-08-04 12:57:37 +00:00
byuu
7b7a95af67 Update to bsnes v067 release.
I apologize, bsnes v066 had a small error in the source that resulted in the PPU not synchronizing properly to the CPU. This bug was not exposed in the images I use to test releases. I have also updated the cheat code database, which is maintained by mightymo.
2010-08-02 00:25:53 +00:00
byuu
a266a2b5e2 Update to bsnes v066 release.
Major features in this release are: serial controller emulation, a brand new scheduler that supports multiple simultaneous coprocessors, and accuracy improvements.
The serial controller is something devised by blargg. With the proper voltage adjustments (5v-9v), it is possible to wire an SNES controller to a serial port, which can then be used for bidirectional communication between the SNES, and (usually, but not only) a PC. The support in bsnes was added so that such programs could be debugged and ran from within an emulator, and not just on real hardware.
The scheduler rewrite was meant to allow the combination of coprocessors. It was specifically meant to allow the serial controller thread to run alongside the SuperFX and SA-1 coprocessor threads, but it also allows fun things like MSU1 support in SuperFX and SA-1 games, and even creating dev cartridges that utilize both the SuperFX and SA-1 at the same time. The one thing not yet allowed is running multiple instances of the exact same coprocessor at the same time, as this is due to design constraints favoring code inlining.
There are two important accuracy updates. The first is that when PAL video mode is used without being in overscan mode, black bars are shown. Emulators have always shown this black bar at the bottom of the screen, but this is actually incorrect. resxto took pictures from his PAL TV that shows the image is in fact vertically centered in the screen. bsnes has been updated to reflect this.
Also interesting is that I have backported some code from the dot-based PPU renderer. In the game Uniracers, it writes to OAM during Hblank, and expects the write to go to a specific address. In previous releases, that address was hard-coded to go to the required memory location. But the way the hardware really works is that the write goes to the extended attribute address for the last sprite that the PPU fetched, as the PPU is still asserting the OAM address bus. Now, due to the precision limitations, I was not able to also port timing access during the active display period. However, this is sufficient to at least remove the last global hack from the older, speed-focused scanline renderer.
2010-08-01 05:46:17 +00:00
byuu
53f03be5a2 Update to bsnes v065r05 release.
Fairly major changes here, I'd appreciate some testing if anyone's not
busy. Note that the save state version has been bumped, so consider
WIP saves unstable until v066 official.

Rewrote the entire scheduling system. Instead of having a global class
that all of the chips call into, each class now contains its own
thread, clock and frequency information. They also implement their own
syncing primitives, but with a tiny bit of standardization.
void step(unsigned clocks) -- add to/subtract from counter based on
master/slave select.
void synchronize_chip() -- make sure chip is caught up to our current
thread before continuing.

So we go from scheduler.sync_copcpu() to sa1.synchronize_cpu(); with
the sa1. being omitted inside the SA1 class itself.

The S-CPU implementation also adds an array<Processor*> coprocessors;
list, and iterates them all. This allows bsnes to have an infinite
number of additional coprocessors at the same time. But there is still
the limitation of only one of each type. So you can use the XML memory
mapping to make a cartridge that contains a SuperFX2 chip, an SA-1
chip, an MSU1 chip and that can be debugged via serial communications.
However, you can't make a cart that has two SA-1 chips. That
limitation probably could be overcome as well, but it's less
important. I mainly wanted to be able to use MSU1 and Serial on
special chip games.

I implemented the synchronization primitives in the chip base classes,
which means that for inlining purposes I had to make it all global, so
you'll have src/cpu/synchronization.hpp, etc now. This was to reduce
some redundancy of having the same exact code inside both bPPU and
sPPU, etc. I'll probably make a Coprocessor : Processor class to
automatically implement the step+synchronize_cpu functions for the
five coprocessors next.

The Scheduler class is actually still around, but it's very trivial
now. It simply saves the program thread and last active emulation
thread for the purpose of entering and exiting emulation. Because I
killed Scheduler::init(), which was responsible for destroying and re-
creating threads, I had to create the threads inside
ChipName::create(), which I call at power and reset. This means that
to load a save state, the system needs to be reset to destroy those
threads.

This caused some troubles with the SA-1, specifically in Kirby's
Dreamland 3, but no other games I tried. I had to move the SA-1 bus
initialization to the power-on event, and only reset when loading a
save state. It would appear that the SA-1 is leaking bus mapping state
information, presumably from the SA-1 MMIO registers that control some
of the mapping layout. If I add remapping of those sections into the
SA1::serialize() function, it should take care of that problem and I
can move sa1bus.init() back into SA1::reset().

All of this results in a 2-3% speed hit for normal games, and a 6-7%
speed hit for special chip games. The former should not have any speed
hit, so I will have to look into what's going on there. The latter we
have no choice on, to allow for more than one coprocessor, the
coprocessor synchronization needs to iterate a list, compared to a
single hard-coded check in the previous builds. If I can figure out
what is happening with the regular game speeds, it should drop the
special chip hit to 4%. Worst part is this hit is in addition to the
10-15% speed hit from v065 official where I wasn't syncing the special
chips up to the CPU except once per scanline and on MMIO accesses.

But that's progress. v065 is definitely going to be the preferred
build for playing SuperFX/SA-1 games for a long time to come.
2010-07-29 16:24:28 +00:00
byuu
77375c3c68 Update to bsnes v065r04 release.
Only posting because the link changed, it's the exact same as r03.
Only difference is some improvements to nall:
- string class gains lower(), upper(), transform(), *trim(_once)
- file::print now accepts variadic arguments like print
Examples:
    strtr(item, "ABCDEF", "abcdef"); -> item.transform("ABCDEF",
    "abcdef");
    strlower(item); -> item.lower();
    fp.print(string("Age: ", age, "\n")); -> fp.print("Age: ", age,
    "\n");
2010-07-16 14:40:08 +00:00
byuu
dce3e61f06 Update to bsnes v065r03 release.
Polishing work. My dlopen wrapper accepts an optional path argument
now, and the basename setting is universal instead of just for MSU1,
so serial-based games can load in a dynamic client library directly.

Still need to update snesserver to accept another argument for the
program library name to load.

Upped the serial polling frequency to 8x UART speed per blargg.

And a very tricky change, I updated nall/string to remove sprint(). At
first, I used:
    string name = string() << path << basename << ".msu";


I then improved upon that with:
    string name = sprint(path, basename, ".msu");


Tonight I went ahead and finished this by taking advantage of variadic
templates for the constructor itself. Very tricky because my
conversion functions created new strings to copy data into, which
would create an infinite loop; then of course I also had to leave the
copy constructor behind even after this. So the end result is the
following:
    string name(path, basename, ".msu");


Oh, and I found a typo in MSU1, it wasn't using the proper extension
when loading a save state for the data file.
2010-07-12 15:56:17 +00:00
byuu
20b44ddfd1 Update to bsnes v065r02 release.
Be warned, this is going to get complicated.

To start out with, serial.tar.bz2 is a simple SNES program that is
right now being used for integrity testing. The important part is
here:

    serial_read:
    lda #$01
    -; bit $4017; bne -
    -; bit $4017; beq -
    nop #24
    pha; lda $4017; eor #$01; ror; pla; ror; nop #18
    pha; lda $4017; eor #$01; ror; pla; ror; nop #18
    pha; lda $4017; eor #$01; ror; pla; ror; nop #18
    pha; lda $4017; eor #$01; ror; pla; ror; nop #18
    pha; lda $4017; eor #$01; ror; pla; ror; nop #18
    pha; lda $4017; eor #$01; ror; pla; ror; nop #18
    pha; lda $4017; eor #$01; ror; pla; ror; nop #18
    pha; lda $4017; eor #$01; ror; pla; ror; rts

    serial_write:
    pha #6; pla #6; wdm #$00; stz $4016; sec
    pha #6; pla #6; wdm #$00; sta $4016; ror
    pha #6; pla #6; wdm #$00; sta $4016; ror
    pha #6; pla #6; wdm #$00; sta $4016; ror
    pha #6; pla #6; wdm #$00; sta $4016; ror
    pha #6; pla #6; wdm #$00; sta $4016; ror
    pha #6; pla #6; wdm #$00; sta $4016; ror
    pha #6; pla #6; wdm #$00; sta $4016; ror
    pha #6; pla #6; wdm #$00; sta $4016; ror
    pha #6; pla #6; wdm #$00; sta $4016; rts


Fairly ugly, but it works.

Next, I needed a way to be able to execute the client in such a way
that it would work with both bsnes and real hardware, with no
recompilation or changes needed. The nice way would be some form of
inter-process communication, but well, I don't really do that. And
it's probably extremely platform-dependent.

So I used what was available to me already, a cross-platform dlopen
wrapper for dynamic library support. The client application is written
and compiled into a shared library that exports a single function,
snesserial_main, which runs as if it is its own program and never
returns. It takes three parameters, the time tick(), read() and
write() function pointers. It can call them to do its work. This
process is put in a folder called snesserial for now. It's the
accompanying program to serial.sfc.

Now I have both bsnes (v065.02 above) and snesserver, they both act
the same way. They load in snesserial, and give it those three
functions and call its main entry point. The difference is that the
read/write functions in bsnes simulate a serial strobe to the
emulator, and the read/write functions in snesserver actually read and
write to the TTY device you specify as the program argument, eg for me
I use: ./snesserver /dev/ttyUSB0
Mmm, USB<>SNES for the win.

There's a limitation in my dlopen wrapper, it adds the libN.so or
N.dll stuff automatically, making it difficult to also specify a path.
That means that for now you have to put libsnesserial.so into
/usr/local/lib. Obviously you don't want to be limited to just one
program. The plan is to have it load the library that matches the game
name:
zelda.sfc + zelda.so/zelda.dll/zelda.dylib (yeah, no libzelda.so.)

Now, the bsnes+serial emulation works on any platform. However,
snesserver only works on Linux. You can blame that one on Microsoft.
They make you require special kernel drivers to be able to access the
serial port. I'm not going through the trouble. OS X can probably use
it if it makes the appropriate /dev/tty device, but I'm not going to
test it.

Activating the module can only be done with a custom XML file, as
before. Still need to work on integration with the controller port
options, as it's not really a special chip.

Lastly, the timing is "pretty good", but not perfect. It accepted a
374 cycle-per-bit loop for serial writes from the SNES to the PC, but
snesserver did not. I had to adjust to 364 cycle-per-bit loop for it
to work on both.

This is really bad, because the goal here is to use the PC as the
testbed to make sure it'll work on the real thing. On the plus side,
you only have to get it working one time, and stick with the
serial_read/serial_write functions like at the top of this post. But I
do need to address this. I'm not entirely sure how to more accurately
simulate a serial port at this point though.

Oh, and I am thinking I need to expand the read/write functions to
process more than one byte at a time. That should greatly speed up
transfer time on the real thing. I also need to add some slowdown so
the emulator more closely matches hardware speeds.
2010-07-11 18:27:42 +00:00
byuu
79f20030a0 Update to bsnes v065r01 release.
In order to fully decode the 16MB address maps, I am going to need to
use blargg's stop-and-swap, which will require a serial-communications
program. To develop this program, and others in the future, as well as
for testing automation, it would be very beneficial to have a way to
debug these programs through bsnes.

So what I'm working on now is emulating a serial port inside bsnes.
The basic premise is to start with a custom XML map that specifies its
presence:

    <?xml version="1.0" encoding="UTF-8"?>
    <cartridge region="NTSC">
    <rom>
    <map mode="linear" address="00-7f:8000-ffff"/>
    <map mode="linear" address="80-ff:8000-ffff"/>
    </rom>

    <ram size="2000">
    <map mode="linear" address="70-7f:0000-7fff"/>
    </ram>

    <serial baud="57600">
    </serial>
    </cartridge>


I am essentially treating the serial communication as a special chip.
One could argue this belongs as an option under controllers, and one
would be right. But as I can't have two coprocessor threads at the
same time, this is how it is for right now. Eventually it'll probably
be under controller port 2, and only enabled in the debugger builds.

So, this pseudo-coprocessor ... it's basically emulating the PC-side
communications program.
Meaning I still need to externalize this somehow so that any program
can be run.
The below program writes 0x96 six times, and then reads in data six
times. Well, technically forever, but the SNES ROM only writes six
times at the end.

    void Serial::enter() {
    scheduler.clock.cop_freq = cartridge.serial_baud_rate() * 2;

    latch = 0;
    add_clocks(512);

    for(unsigned i = 0; i < 6; i++) {
    latch = 1; add_clocks(2);

    latch = 1; add_clocks(2);
    latch = 0; add_clocks(2);
    latch = 0; add_clocks(2);
    latch = 1; add_clocks(2);
    latch = 0; add_clocks(2);
    latch = 1; add_clocks(2);
    latch = 1; add_clocks(2);
    latch = 0; add_clocks(2);

    latch = 0; add_clocks(2);
    }

    while(true) {
    while(cpu.joylatch() == 0) add_clocks(1);
    while(cpu.joylatch() == 1) add_clocks(1);
    add_clocks(1);

    uint8 data = 0;
    for(unsigned i = 0; i < 8; i++) {
    add_clocks(2);
    data = (data << 1) | cpu.joylatch();
    }

    print("Read ", strhex<2>(data), "\n");
    }
    }


The SNES code looks like this:

    //21,477,272hz cpu / 57,600hz serial = ~372.87 clocks/tick

    org $8000
    xce; rep #$10
    ldx #$01ff; txs

    jsr serial_read; sta $700000
    jsr serial_read; sta $700001
    jsr serial_read; sta $700002
    jsr serial_read; sta $700003
    jsr serial_read; sta $700004
    jsr serial_read; sta $700005

    nop #46

    jsr serial_write
    jsr serial_write
    jsr serial_write
    jsr serial_write
    jsr serial_write
    jsr serial_write

    //hang
    -; bra -

    serial_read:
    -; lda $4017; and #$01; bne -
    -; lda $4017; and #$01; beq -
    nop #23; lda $00; nop #10

    lda $4017; and #$01; asl $00; ora $00; sta $00; lda $00; nop #13
    lda $4017; and #$01; asl $00; ora $00; sta $00; lda $00; nop #13
    lda $4017; and #$01; asl $00; ora $00; sta $00; lda $00; nop #13
    lda $4017; and #$01; asl $00; ora $00; sta $00; lda $00; nop #13
    lda $4017; and #$01; asl $00; ora $00; sta $00; lda $00; nop #13
    lda $4017; and #$01; asl $00; ora $00; sta $00; lda $00; nop #13
    lda $4017; and #$01; asl $00; ora $00; sta $00; lda $00; nop #13
    lda $4017; and #$01; asl $00; ora $00; sta $00; lda $00; nop #13

    rts

    serial_write:
    lda #$01; sta $4016; nop #23

    lda #$00; sta $4016; nop #23

    lda #$01; sta $4016; nop #23
    lda #$00; sta $4016; nop #23
    lda #$00; sta $4016; nop #23
    lda #$01; sta $4016; nop #23
    lda #$00; sta $4016; nop #23
    lda #$01; sta $4016; nop #23
    lda #$01; sta $4016; nop #23
    lda #$00; sta $4016; nop #23

    lda #$01; sta $4016; nop #23

    rts


That reads six times, and then writes six times.

I haven't made the test do an infinite PC->SNES transfer, but I have
for SNES->PC. No errors after millions of bytes, even if I stride the
CPU timing.

As this is just an example, it's pretty lousy with actual timing, but
I guess that's a good thing as it still works quite well. More
tolerance = less potential for errors.

**Now, this part is important.**

While debugging this, I noticed that my serial coprocessor was only
running when Vcounter=n,Hcounter=0. In other words, nothing was making
the CPU synchronize back to the coprocessor, except the once-per-
scanline synchronization that was there in case of CPU stalls.

That's ... really bad. MSU1 worked only because it buffers a few
hundred samples for audio mixing. I don't really know why this didn't
cause an issue for SuperFX, SA-1 or Super Game Boy games; but in
theory they were at most 682x less precise than they should have been
in terms of CPU->coprocessor synchronization.

Making it sync after every add_clocks() call results in a 10% speed
hit to SuperFX, SA-1 and Super Game Boy emulation, unfortunately.

I don't notice any quality improvements in emulation, but in theory
the lack of this syncing before effectively eliminated the benefits of
the SuperFX and SA-1 being cycle based.

I'm going to have to look into this more to understand if I was
intentionally not doing this sync before, or if I really did forget
it. I'm thinking it was an oversight right now. The SuperFX and SA-1
don't really talk back and forth a whole hell of a lot, so once a
scanline probably wouldn't be that noticeable.

But holy hell ... now that I'm thinking about it, I wonder if this was
the cause of all that craziness in trying to sync up the Super Game
Boy's VRAM transfers. Yeah, definitely need to look into this more ...
2010-07-09 15:02:23 +00:00
byuu
79b939e1c7 Update to bsnes v065 release.
It's been a while, so here is a new release of bsnes.
Unfortunately I don't have a full changelog this time. Most of the work went into stabilizing libsnes (which is used by the experimental .NET, Cocoa and Python UIs; as well as by Richard Bannister's OS X port).
The Windows binary package now comes with all three variants included: bsnes.exe, the standard version that casual users should run; bsnes-debugger.exe, for SNES programmers and ROM hackers only; and bsnes-accurate.exe, which should not be used by anybody, ever.
In all seriousness, bsnes-accurate.exe is bsnes with the dot-based S-PPU renderer. It's twice as slow as the normal build, and you won't really notice any differences except in Air Strike Patrol. It's there for the curious and for any SNES programmers who want to try making some really awesome video demos.
Changelog:
* OS X port builds once again; now requires gcc44 from Macports
* libsnes API finalized
* fixed a bug with S-CPU debugger breakpoints
* various source cleanup
2010-06-27 12:29:18 +00:00
byuu
3ae74ff5a5 Update to bsnes v064r08 release.
Fixes Super Game Boy save RAM/RTC data.
Fixes a crash when you pass a null pointer for the second Sufami Turbo
cartridge, etc.

[No archive available]
2010-06-14 02:01:12 +00:00
byuu
7351b910c5 Update to bsnes v064r07 release.
Wow, that's probably a record for the longest time between two WIPs.
My priority has obviously shifted to language learning, but as time
goes on things should balance out better.

Okay, changes:
- linear_vector, pointer_vector and array are greatly improved: added
insert and remove (can insert or remove more than one item at a time
for O(n) performance); renamed add to append; improved array::find to
use optional<unsigned> instead of -1 trick ala the new strpos function
- fixed string to floating-point conversion for international systems
that use "," for fractions
- libsnes::snes_get_memory_(size|data) will return 0 if you try and
access: BS-X data without a BS-X cartridge loaded, same for ST, same
for SGB; this is in case someone tries to write a generic function
that writes all memory that is valid instead of special casing based
on the cartridge type they loaded
- libsnes::snes_load_cartridge_* returns a boolean result to indicate
success; always returns true for now, but it's meant to eventually
catch when libgambatte fails to load a GB cartridge -- bsnes itself
will never fail to load an SNES/BSX/ST cartridge
- Linux monospace font changed from "Monospace" to "Liberation Mono",
because the former is not monospaced when your desktop environment is
set to Japanese, etc.
- some other misc. cleanups

[No archive available]
2010-06-06 05:28:35 +00:00
byuu
6bbb609f2f Update to bsnes v064r06 release.
Updated to build using Xcode Snow Leopard+Qt/Cocoa 4.6.2+Macports
gcc44.
2010-05-03 14:04:30 +00:00
byuu
0d19902435 Update to bsnes v064r05 release.
- swaps the video_refresh output from BGR555 to RGB555, for the sake
of direct copying for certain APIs. Not going to do RGB565 because the
G5 bit doesn't exist, and faking it is lame.

[Meanwhile, in bsnesui 2010-04-24...]

bsnes.python:
- adds more icons and stuff.
bsnes.net:
- new port, targets C#, binds every function in libsnes
- targets .NET 3.5 ... I honestly would have went with 4.0 for the
nicer IntPtr addition alone, but the SP3 requirement may put off a lot
of people
- video output that doesn't scale (or clean up when dropping to a
smaller size)
- Port1 joypad input support via keyboard only
bsnes.cocoa:
- stuck in a time/space wormhole until Apple gets their heads out of
their asses and updates GCC

Probably the coolest thing about Python and .NET is that anyone can
now compile these GUIs and modify them just by having the run-times
installed. I really like the way MS is distributing the complete
development chain along with the run-time.
2010-04-25 08:39:41 +00:00
byuu
44bab83d68 Update to bsnes v064r04 release.
Fixes S-CPU debugger breakpoint issue.
libsnes always returns 0 for "no memory present" now, never -1U.

[Meanwhile, in bsnes-python 2010-04-20...]

Won't error if there's no joypad present.
Swaps menu and status bars with a toolbar.
Adds keyboard support - you can use both a keyboard and joypad for
input now.
Won't crash if RAM doesn't exist yet.
Won't crash if game uses no RAM.
2010-04-20 22:33:44 +00:00
byuu
42a4c1d60e Update to bsnes v064r03 release.
Some changes to libsnes. Really hoping the API will be stable from
this point out ...
2010-04-19 17:37:14 +00:00
byuu
645689e683 Update to bsnes v064r02 release.
Nothing interesting, just added bsnes-qt.py to ui_python. No input
handling, but OpenGL-based video resizing and libao audio. Doesn't use
numpy, found a workaround for that. It's obvious that we need
video/audio/input handled by an external library for this to work, so
I'm thinking now about a rewrite of ruby to a C-like interface.
2010-04-18 14:09:17 +00:00
byuu
8b0153daf0 Update to bsnes v064r01 release.
Adds bool snes_get_region(void) to libsnes (permanent).
Adds snes_blit_colortable and snes_blit to libsnes (temporary).
Adds src/ui_python with a basic Python GUI, and abstraction between
the libsnes wrapper and PyGTK (so it can be reused for PyQt, etc.)

The GUI has:
- menubar
- video output (2x scale, supports NTSC/PAL, hires, overscan and
interlace correctly)
- audio output (libao through ALSA)
- input (very lousy key press events, they toggle off and on if you
hold a key down ...)

I'm getting full-speed, so that's good.

Not sure where I want to take all of this stuff yet, but it's kind of
neat for now I suppose. It would be kinda fun to go really out there
with completely new GUI design styles that aren't just your standard
menubar+video. Things like a toolbar, mouse gestures, really deep
platform integration, AVI-based recording, frame analysis shit, game-
specific GUI shit (perhaps map touch-screen input + gyroscope on top
of a simulated gamepad; or perhaps read the contents of RAM and
provide statistical information on the sides of the video output
screen?), I dunno ... whatever. It's there, it's possible, but it's
certainly not good enough to replace the official C++ Qt port, and I
don't really have the time or patience to make it that good myself.
2010-04-16 13:40:27 +00:00
1202 changed files with 42640 additions and 85893 deletions

View File

@@ -1,10 +1,11 @@
include nall/Makefile
ui := ui_qt
snes := asnes
ui := qt
# compiler
c := $(compiler) -std=gnu99
cpp := $(subst cc,++,$(compiler)) -std=gnu++0x
flags := -O3 -fomit-frame-pointer -I.
flags := -O3 -fomit-frame-pointer -I. -I$(snes)
link :=
objects :=
@@ -20,9 +21,9 @@ ifeq ($(platform),x)
link += -s -ldl -lX11 -lXext
else ifeq ($(platform),osx)
else ifeq ($(platform),win)
link += -mwindows -mthreads
# link += -mconsole -mthreads
link += -s -luuid -lkernel32 -luser32 -lgdi32 -lshell32
link += -mwindows
# link += -mconsole
link += -mthreads -s -luuid -lkernel32 -luser32 -lgdi32 -lshell32
link += -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc
else
unknown_platform: help;
@@ -43,7 +44,7 @@ compile = \
all: build;
include snes/Makefile
include $(snes)/Makefile
include $(ui)/Makefile
objects := $(patsubst %,obj/%.o,$(objects))
@@ -54,7 +55,7 @@ ifeq ($(platform),osx)
test -d ../bsnes.app || mkdir -p ../bsnes.app/Contents/MacOS
$(strip $(cpp) -o ../bsnes.app/Contents/MacOS/bsnes $(objects) $(link))
else
$(strip $(cpp) -o ../bsnes $(objects) $(link))
$(strip $(cpp) -o out/$(snes) $(objects) $(link))
endif
install:
@@ -84,4 +85,7 @@ clean: ui_clean
-@$(call delete,*.pdb)
-@$(call delete,*.manifest)
archive-all:
tar -cjf snes-`date +%Y%m%d`.tar.bz2 asnes bsnes libco nall obj out qt ruby Makefile sync.sh
help:;

77
asnes/Makefile Normal file
View File

@@ -0,0 +1,77 @@
snes_objects := libco
snes_objects += snes-system
snes_objects += snes-cartridge snes-cheat
snes_objects += snes-memory snes-cpucore snes-cpu snes-smpcore snes-smp snes-dsp snes-ppu
snes_objects += snes-supergameboy snes-superfx snes-sa1
snes_objects += snes-bsx snes-srtc snes-sdd1 snes-spc7110
snes_objects += snes-cx4 snes-dsp1 snes-dsp2 snes-dsp3 snes-dsp4
snes_objects += snes-obc1 snes-st0010 snes-st0011 snes-st0018
snes_objects += snes-msu1 snes-serial
objects += $(snes_objects)
obj/libco.o : libco/libco.c libco/*
obj/libsnes.o: $(snes)/libsnes/libsnes.cpp $(snes)/libsnes/*
obj/snes-system.o : $(snes)/system/system.cpp $(call rwildcard,$(snes)/system/) $(call rwildcard,$(snes)/video/)
obj/snes-memory.o : $(snes)/memory/memory.cpp $(snes)/memory/*
obj/snes-cpucore.o : $(snes)/cpu/core/core.cpp $(call rwildcard,$(snes)/cpu/core/)
obj/snes-cpu.o : $(snes)/cpu/cpu.cpp $(snes)/cpu/*
obj/snes-smpcore.o : $(snes)/smp/core/core.cpp $(call rwildcard,$(snes)/smp/core/)
obj/snes-smp.o : $(snes)/smp/smp.cpp $(snes)/smp/*
obj/snes-dsp.o : $(snes)/dsp/dsp.cpp $(snes)/dsp/*
obj/snes-ppu.o : $(snes)/ppu/ppu.cpp $(snes)/ppu/*
obj/snes-cartridge.o: $(snes)/cartridge/cartridge.cpp $(snes)/cartridge/*
obj/snes-cheat.o : $(snes)/cheat/cheat.cpp $(snes)/cheat/*
obj/snes-supergameboy.o: $(snes)/chip/supergameboy/supergameboy.cpp $(call rwildcard,$(snes)/chip/supergameboy/)
obj/snes-superfx.o : $(snes)/chip/superfx/superfx.cpp $(call rwildcard,$(snes)/chip/superfx/)
obj/snes-sa1.o : $(snes)/chip/sa1/sa1.cpp $(call rwildcard,$(snes)/chip/sa1/)
obj/snes-bsx.o : $(snes)/chip/bsx/bsx.cpp $(snes)/chip/bsx/*
obj/snes-srtc.o : $(snes)/chip/srtc/srtc.cpp $(snes)/chip/srtc/*
obj/snes-sdd1.o : $(snes)/chip/sdd1/sdd1.cpp $(snes)/chip/sdd1/*
obj/snes-spc7110.o : $(snes)/chip/spc7110/spc7110.cpp $(snes)/chip/spc7110/*
obj/snes-cx4.o : $(snes)/chip/cx4/cx4.cpp $(snes)/chip/cx4/*
obj/snes-dsp1.o : $(snes)/chip/dsp1/dsp1.cpp $(snes)/chip/dsp1/*
obj/snes-dsp2.o : $(snes)/chip/dsp2/dsp2.cpp $(snes)/chip/dsp2/*
obj/snes-dsp3.o : $(snes)/chip/dsp3/dsp3.cpp $(snes)/chip/dsp3/*
obj/snes-dsp4.o : $(snes)/chip/dsp4/dsp4.cpp $(snes)/chip/dsp4/*
obj/snes-obc1.o : $(snes)/chip/obc1/obc1.cpp $(snes)/chip/obc1/*
obj/snes-st0010.o : $(snes)/chip/st0010/st0010.cpp $(snes)/chip/st0010/*
obj/snes-st0011.o : $(snes)/chip/st0011/st0011.cpp $(snes)/chip/st0011/*
obj/snes-st0018.o : $(snes)/chip/st0018/st0018.cpp $(snes)/chip/st0018/*
obj/snes-msu1.o : $(snes)/chip/msu1/msu1.cpp $(snes)/chip/msu1/*
obj/snes-serial.o : $(snes)/chip/serial/serial.cpp $(snes)/chip/serial/*
###########
# library #
###########
snes_objects := $(patsubst %,obj/%.o,$(snes_objects))
library: $(snes_objects) obj/libsnes.o
ifeq ($(platform),x)
ar rcs obj/libsnes.a $(snes_objects) obj/libsnes.o
$(cpp) -o obj/libsnes.so -shared -Wl,-soname,libsnes.so.1 $(snes_objects) obj/libsnes.o
else ifeq ($(platform),osx)
ar rcs obj/libsnes.a $(snes_objects) obj/libsnes.o
$(cpp) -o obj/libsnes.dylib -install_name @executable_path/../Libraries/libsnes.dylib -shared -dynamiclib $(snes_objects) obj/libsnes.o
else ifeq ($(platform),win)
$(cpp) -o obj/snes.dll -shared -Wl,--out-implib,libsnes.a $(snes_objects) obj/libsnes.o
endif
library-install:
ifeq ($(platform),x)
install -D -m 755 obj/libsnes.a $(DESTDIR)$(prefix)/lib/libsnes.a
install -D -m 755 obj/libsnes.so $(DESTDIR)$(prefix)/lib/libsnes.so
ldconfig -n $(DESTDIR)$(prefix)/lib
else ifeq ($(platform),osx)
cp obj/libsnes.dylib /usr/local/lib/libsnes.dylib
endif
library-uninstall:
ifeq ($(platform),x)
rm $(DESTDIR)$(prefix)/lib/libsnes.a
rm $(DESTDIR)$(prefix)/lib/libsnes.so
else ifeq ($(platform),osx)
rm /usr/local/lib/libsnes.dylib
endif

View File

@@ -14,12 +14,7 @@ void Audio::coprocessor_enable(bool state) {
void Audio::coprocessor_frequency(double input_frequency) {
double output_frequency;
if(system.region() == System::Region::NTSC) {
output_frequency = config.smp.ntsc_clock_rate / 768.0;
} else /* (system.region() == System::PAL) */ {
output_frequency = config.smp.pal_clock_rate / 768.0;
}
output_frequency = system.apu_frequency() / 768.0;
r_step = input_frequency / output_frequency;
r_frac = 0;
}

View File

@@ -1,4 +1,4 @@
#include <snes/snes.hpp>
#include <snes.hpp>
#include <nall/crc32.hpp>
#include <nall/sha256.hpp>
@@ -27,6 +27,7 @@ void Cartridge::load(Mode cartridge_mode, const lstring &xml_list) {
supergameboy_version = SuperGameBoyVersion::Version1;
supergameboy_ram_size = 0;
supergameboy_rtc_size = 0;
serial_baud_rate = 57600;
has_bsx_slot = false;
has_superfx = false;
@@ -45,6 +46,7 @@ void Cartridge::load(Mode cartridge_mode, const lstring &xml_list) {
has_st0011 = false;
has_st0018 = false;
has_msu1 = false;
has_serial = false;
parse_xml(xml_list);

View File

@@ -18,6 +18,10 @@ public:
Version2,
};
//assigned externally to point to file-system datafiles (msu1 and serial)
//example: "/path/to/filename.sfc" would set this to "/path/to/filename"
readwrite<string> basename;
readonly<bool> loaded;
readonly<unsigned> crc32;
readonly<string> sha256;
@@ -29,6 +33,7 @@ public:
readonly<SuperGameBoyVersion> supergameboy_version;
readonly<unsigned> supergameboy_ram_size;
readonly<unsigned> supergameboy_rtc_size;
readonly<unsigned> serial_baud_rate;
readonly<bool> has_bsx_slot;
readonly<bool> has_superfx;
@@ -47,6 +52,7 @@ public:
readonly<bool> has_st0011;
readonly<bool> has_st0018;
readonly<bool> has_msu1;
readonly<bool> has_serial;
struct Mapping {
Memory *memory;
@@ -95,6 +101,7 @@ private:
void xml_parse_setadsp(xml_element&);
void xml_parse_setarisc(xml_element&);
void xml_parse_msu1(xml_element&);
void xml_parse_serial(xml_element&);
void xml_parse_address(Mapping&, const string&);
void xml_parse_mode(Mapping&, const string&);

View File

@@ -46,6 +46,7 @@ void Cartridge::parse_xml_cartridge(const char *data) {
if(node.name == "setadsp") xml_parse_setadsp(node);
if(node.name == "setarisc") xml_parse_setarisc(node);
if(node.name == "msu1") xml_parse_msu1(node);
if(node.name == "serial") xml_parse_serial(node);
}
}
}
@@ -92,7 +93,7 @@ void Cartridge::xml_parse_rom(xml_element &root) {
if(attr.name == "offset") m.offset = strhex(attr.content);
if(attr.name == "size") m.size = strhex(attr.content);
}
mapping.add(m);
mapping.append(m);
}
}
}
@@ -111,7 +112,7 @@ void Cartridge::xml_parse_ram(xml_element &root) {
if(attr.name == "offset") m.offset = strhex(attr.content);
if(attr.name == "size") m.size = strhex(attr.content);
}
mapping.add(m);
mapping.append(m);
}
}
}
@@ -130,7 +131,7 @@ void Cartridge::xml_parse_superfx(xml_element &root) {
if(attr.name == "offset") m.offset = strhex(attr.content);
if(attr.name == "size") m.size = strhex(attr.content);
}
mapping.add(m);
mapping.append(m);
}
}
} else if(node.name == "ram") {
@@ -147,7 +148,7 @@ void Cartridge::xml_parse_superfx(xml_element &root) {
if(attr.name == "offset") m.offset = strhex(attr.content);
if(attr.name == "size") m.size = strhex(attr.content);
}
mapping.add(m);
mapping.append(m);
}
}
} else if(node.name == "mmio") {
@@ -157,7 +158,7 @@ void Cartridge::xml_parse_superfx(xml_element &root) {
foreach(attr, leaf.attribute) {
if(attr.name == "address") xml_parse_address(m, attr.content);
}
mapping.add(m);
mapping.append(m);
}
}
}
@@ -178,7 +179,7 @@ void Cartridge::xml_parse_sa1(xml_element &root) {
if(attr.name == "offset") m.offset = strhex(attr.content);
if(attr.name == "size") m.size = strhex(attr.content);
}
mapping.add(m);
mapping.append(m);
}
}
} else if(node.name == "iram") {
@@ -191,7 +192,7 @@ void Cartridge::xml_parse_sa1(xml_element &root) {
if(attr.name == "offset") m.offset = strhex(attr.content);
if(attr.name == "size") m.size = strhex(attr.content);
}
mapping.add(m);
mapping.append(m);
}
}
} else if(node.name == "bwram") {
@@ -208,7 +209,7 @@ void Cartridge::xml_parse_sa1(xml_element &root) {
if(attr.name == "offset") m.offset = strhex(attr.content);
if(attr.name == "size") m.size = strhex(attr.content);
}
mapping.add(m);
mapping.append(m);
}
}
} else if(node.name == "mmio") {
@@ -218,7 +219,7 @@ void Cartridge::xml_parse_sa1(xml_element &root) {
foreach(attr, leaf.attribute) {
if(attr.name == "address") xml_parse_address(m, attr.content);
}
mapping.add(m);
mapping.append(m);
}
}
}
@@ -239,7 +240,7 @@ void Cartridge::xml_parse_bsx(xml_element &root) {
if(attr.name == "offset") m.offset = strhex(attr.content);
if(attr.name == "size") m.size = strhex(attr.content);
}
mapping.add(m);
mapping.append(m);
}
}
} else if(node.name == "mmio") {
@@ -249,7 +250,7 @@ void Cartridge::xml_parse_bsx(xml_element &root) {
foreach(attr, leaf.attribute) {
if(attr.name == "address") xml_parse_address(m, attr.content);
}
mapping.add(m);
mapping.append(m);
}
}
}
@@ -280,7 +281,7 @@ void Cartridge::xml_parse_sufamiturbo(xml_element &root) {
if(attr.name == "offset") m.offset = strhex(attr.content);
if(attr.name == "size") m.size = strhex(attr.content);
}
if(m.memory->size() > 0) mapping.add(m);
if(m.memory->size() > 0) mapping.append(m);
}
}
} else if(slot.name == "ram") {
@@ -293,7 +294,7 @@ void Cartridge::xml_parse_sufamiturbo(xml_element &root) {
if(attr.name == "offset") m.offset = strhex(attr.content);
if(attr.name == "size") m.size = strhex(attr.content);
}
if(m.memory->size() > 0) mapping.add(m);
if(m.memory->size() > 0) mapping.append(m);
}
}
}
@@ -320,7 +321,7 @@ void Cartridge::xml_parse_supergameboy(xml_element &root) {
foreach(attr, leaf.attribute) {
if(attr.name == "address") xml_parse_address(m, attr.content);
}
mapping.add(m);
mapping.append(m);
}
}
}
@@ -338,7 +339,7 @@ void Cartridge::xml_parse_srtc(xml_element &root) {
foreach(attr, leaf.attribute) {
if(attr.name == "address") xml_parse_address(m, attr.content);
}
mapping.add(m);
mapping.append(m);
}
}
}
@@ -356,7 +357,7 @@ void Cartridge::xml_parse_sdd1(xml_element &root) {
foreach(attr, leaf.attribute) {
if(attr.name == "address") xml_parse_address(m, attr.content);
}
mapping.add(m);
mapping.append(m);
}
}
} else if(node.name == "mmio") {
@@ -366,7 +367,7 @@ void Cartridge::xml_parse_sdd1(xml_element &root) {
foreach(attr, leaf.attribute) {
if(attr.name == "address") xml_parse_address(m, attr.content);
}
mapping.add(m);
mapping.append(m);
}
}
}
@@ -384,7 +385,7 @@ void Cartridge::xml_parse_spc7110(xml_element &root) {
foreach(attr, leaf.attribute) {
if(attr.name == "address") xml_parse_address(m, attr.content);
}
mapping.add(m);
mapping.append(m);
}
}
} else if(node.name == "mcu") {
@@ -395,7 +396,7 @@ void Cartridge::xml_parse_spc7110(xml_element &root) {
if(attr.name == "address") xml_parse_address(m, attr.content);
if(attr.name == "offset") spc7110_data_rom_offset = strhex(attr.content);
}
mapping.add(m);
mapping.append(m);
}
}
} else if(node.name == "mmio") {
@@ -405,7 +406,7 @@ void Cartridge::xml_parse_spc7110(xml_element &root) {
foreach(attr, leaf.attribute) {
if(attr.name == "address") xml_parse_address(m, attr.content);
}
mapping.add(m);
mapping.append(m);
}
}
} else if(node.name == "ram") {
@@ -422,7 +423,7 @@ void Cartridge::xml_parse_spc7110(xml_element &root) {
if(attr.name == "offset") m.offset = strhex(attr.content);
if(attr.name == "size") m.size = strhex(attr.content);
}
mapping.add(m);
mapping.append(m);
}
}
} else if(node.name == "rtc") {
@@ -434,7 +435,7 @@ void Cartridge::xml_parse_spc7110(xml_element &root) {
foreach(attr, leaf.attribute) {
if(attr.name == "address") xml_parse_address(m, attr.content);
}
mapping.add(m);
mapping.append(m);
}
}
}
@@ -452,7 +453,7 @@ void Cartridge::xml_parse_cx4(xml_element &root) {
foreach(attr, leaf.attribute) {
if(attr.name == "address") xml_parse_address(m, attr.content);
}
mapping.add(m);
mapping.append(m);
}
}
}
@@ -491,7 +492,7 @@ void Cartridge::xml_parse_necdsp(xml_element &root) {
foreach(attr, leaf.attribute) {
if(attr.name == "address") xml_parse_address(m, attr.content);
}
mapping.add(m);
mapping.append(m);
}
}
} else if(node.name == "sr" && sr[program]) {
@@ -501,7 +502,7 @@ void Cartridge::xml_parse_necdsp(xml_element &root) {
foreach(attr, leaf.attribute) {
if(attr.name == "address") xml_parse_address(m, attr.content);
}
mapping.add(m);
mapping.append(m);
}
}
}
@@ -519,7 +520,7 @@ void Cartridge::xml_parse_obc1(xml_element &root) {
foreach(attr, leaf.attribute) {
if(attr.name == "address") xml_parse_address(m, attr.content);
}
mapping.add(m);
mapping.append(m);
}
}
}
@@ -551,7 +552,7 @@ void Cartridge::xml_parse_setadsp(xml_element &root) {
foreach(attr, leaf.attribute) {
if(attr.name == "address") xml_parse_address(m, attr.content);
}
mapping.add(m);
mapping.append(m);
}
}
}
@@ -580,7 +581,7 @@ void Cartridge::xml_parse_setarisc(xml_element &root) {
foreach(attr, leaf.attribute) {
if(attr.name == "address") xml_parse_address(m, attr.content);
}
mapping.add(m);
mapping.append(m);
}
}
}
@@ -598,13 +599,23 @@ void Cartridge::xml_parse_msu1(xml_element &root) {
foreach(attr, leaf.attribute) {
if(attr.name == "address") xml_parse_address(m, attr.content);
}
mapping.add(m);
mapping.append(m);
}
}
}
}
}
void Cartridge::xml_parse_serial(xml_element &root) {
has_serial = true;
foreach(attr, root.attribute) {
if(attr.name == "baud") {
serial_baud_rate = strunsigned(attr.content);
}
}
}
void Cartridge::xml_parse_address(Mapping &m, const string &data) {
lstring part;
part.split(":", data);

View File

@@ -1,4 +1,4 @@
#include <snes/snes.hpp>
#include <snes.hpp>
#define CHEAT_CPP
namespace SNES {
@@ -73,7 +73,7 @@ Cheat::Cheat() {
bool Cheat::decode(const char *s, unsigned &addr, uint8 &data, Type &type) {
string t = s;
strlower(t);
t.lower();
#define ischr(n) ((n >= '0' && n <= '9') || (n >= 'a' && n <= 'f'))
@@ -95,7 +95,7 @@ bool Cheat::decode(const char *s, unsigned &addr, uint8 &data, Type &type) {
for(unsigned i = 0; i < 8; i++) if(!ischr(t[i])) return false;
type = Type::GameGenie;
strtr(t, "df4709156bc8a23e", "0123456789abcdef");
t.transform("df4709156bc8a23e", "0123456789abcdef");
unsigned r = strhex((const char*)t);
//8421 8421 8421 8421 8421 8421
//abcd efgh ijkl mnop qrst uvwx
@@ -125,7 +125,7 @@ bool Cheat::encode(string &s, unsigned addr, uint8 data, Type type) {
char t[16];
if(type == Type::ProActionReplay) {
s = sprint(strhex<6>(addr), strhex<2>(data));
s = string(strhex<6>(addr), strhex<2>(data));
return true;
} else if(type == Type::GameGenie) {
unsigned r = addr;
@@ -141,8 +141,8 @@ bool Cheat::encode(string &s, unsigned addr, uint8 data, Type type) {
| (!!(r & 0x080000) << 5) | (!!(r & 0x040000) << 4)
| (!!(r & 0x020000) << 3) | (!!(r & 0x010000) << 2)
| (!!(r & 0x000800) << 1) | (!!(r & 0x000400) << 0);
s = sprint(strhex<2>(data), strhex<2>(addr >> 16), "-", strhex<4>(addr & 0xffff));
strtr(s, "0123456789abcdef", "df4709156bc8a23e");
s = string(strhex<2>(data), strhex<2>(addr >> 16), "-", strhex<4>(addr & 0xffff));
s.transform("0123456789abcdef", "df4709156bc8a23e");
return true;
} else {
return false;
@@ -180,8 +180,8 @@ bool CheatCode::operator=(string s) {
return false;
}
addr.add(addr_);
data.add(data_);
addr.append(addr_);
data.append(data_);
}
return true;

8
asnes/chip/bsx/bsx.cpp Normal file
View File

@@ -0,0 +1,8 @@
#include <snes.hpp>
#define BSX_CPP
namespace SNES {
#include "bsx_base.cpp"
#include "bsx_cart.cpp"
#include "bsx_flash.cpp"
}

31
asnes/chip/chip.hpp Normal file
View File

@@ -0,0 +1,31 @@
struct Coprocessor : Processor {
alwaysinline void step(unsigned clocks);
alwaysinline void synchronize_cpu();
};
#include <chip/supergameboy/supergameboy.hpp>
#include <chip/superfx/superfx.hpp>
#include <chip/sa1/sa1.hpp>
#include <chip/bsx/bsx.hpp>
#include <chip/srtc/srtc.hpp>
#include <chip/sdd1/sdd1.hpp>
#include <chip/spc7110/spc7110.hpp>
#include <chip/cx4/cx4.hpp>
#include <chip/dsp1/dsp1.hpp>
#include <chip/dsp2/dsp2.hpp>
#include <chip/dsp3/dsp3.hpp>
#include <chip/dsp4/dsp4.hpp>
#include <chip/obc1/obc1.hpp>
#include <chip/st0010/st0010.hpp>
#include <chip/st0011/st0011.hpp>
#include <chip/st0018/st0018.hpp>
#include <chip/msu1/msu1.hpp>
#include <chip/serial/serial.hpp>
void Coprocessor::step(unsigned clocks) {
clock += clocks * (uint64)cpu.frequency;
}
void Coprocessor::synchronize_cpu() {
if(clock >= 0 && scheduler.sync != Scheduler::SynchronizeMode::All) co_switch(cpu.thread);
}

View File

@@ -4,7 +4,7 @@
//Used in Rockman X2/X3 (Megaman X2/X3)
//Portions (c) anomie, Overload, zsKnight, Nach, byuu
#include <snes/snes.hpp>
#include <snes.hpp>
#define CX4_CPP
namespace SNES {

View File

@@ -1,4 +1,4 @@
#include <snes/snes.hpp>
#include <snes.hpp>
#define DSP1_CPP
namespace SNES {

View File

@@ -1,4 +1,4 @@
#include <snes/snes.hpp>
#include <snes.hpp>
#define DSP2_CPP
namespace SNES {

View File

@@ -1,4 +1,4 @@
#include <snes/snes.hpp>
#include <snes.hpp>
#define DSP3_CPP
namespace SNES {

View File

@@ -1,4 +1,4 @@
#include <snes/snes.hpp>
#include <snes.hpp>
#define DSP4_CPP
namespace SNES {

View File

@@ -1,4 +1,4 @@
#include <snes/snes.hpp>
#include <snes.hpp>
#define MSU1_CPP
namespace SNES {
@@ -7,9 +7,9 @@ MSU1 msu1;
#include "serialization.cpp"
void MSU1::enter() {
scheduler.clock.cop_freq = 44100;
void MSU1::Enter() { msu1.enter(); }
void MSU1::enter() {
while(true) {
if(scheduler.sync == Scheduler::SynchronizeMode::All) {
scheduler.exit(Scheduler::ExitReason::SynchronizeEvent);
@@ -36,8 +36,8 @@ void MSU1::enter() {
right = sclamp<16>((double)right * (double)mmio.audio_volume / 255.0);
audio.coprocessor_sample(left, right);
scheduler.addclocks_cop(1);
scheduler.sync_copcpu();
step(1);
synchronize_cpu();
}
}
@@ -49,7 +49,7 @@ void MSU1::enable() {
audio.coprocessor_frequency(44100.0);
if(datafile.open()) datafile.close();
datafile.open(string() << basename << ".msu", file::mode_read);
datafile.open(string() << cartridge.basename() << ".msu", file::mode_read);
}
void MSU1::power() {
@@ -57,6 +57,8 @@ void MSU1::power() {
}
void MSU1::reset() {
create(MSU1::Enter, 44100);
mmio.data_offset = 0;
mmio.audio_offset = 0;
mmio.audio_track = 0;
@@ -125,7 +127,7 @@ void MSU1::mmio_write(unsigned addr, uint8 data) {
if(audiofile.open()) audiofile.close();
char track[16];
sprintf(track, "-%u", mmio.audio_track);
if(audiofile.open(string() << basename << track << ".wav", file::mode_read)) {
if(audiofile.open(string() << cartridge.basename() << track << ".wav", file::mode_read)) {
audiofile.seek(mmio.audio_offset = 58); //skip WAV header
}
mmio.audio_busy = false;
@@ -143,8 +145,4 @@ void MSU1::mmio_write(unsigned addr, uint8 data) {
}
}
void MSU1::base(const string& name) {
basename = name;
}
}

View File

@@ -1,7 +1,7 @@
class MSU1 : public MMIO {
class MSU1 : public Coprocessor, public MMIO {
public:
static void Enter();
void enter();
void init();
void enable();
void power();
@@ -10,11 +10,9 @@ public:
uint8 mmio_read(unsigned addr);
void mmio_write(unsigned addr, uint8 data);
void base(const string &name);
void serialize(serializer&);
private:
string basename;
file datafile;
file audiofile;

View File

@@ -1,6 +1,8 @@
#ifdef MSU1_CPP
void MSU1::serialize(serializer &s) {
Processor::serialize(s);
s.integer(mmio.data_offset);
s.integer(mmio.audio_offset);
s.integer(mmio.audio_track);
@@ -11,14 +13,14 @@ void MSU1::serialize(serializer &s) {
s.integer(mmio.audio_play);
if(datafile.open()) datafile.close();
if(datafile.open(string() << basename << ".msun", file::mode_read)) {
if(datafile.open(string() << cartridge.basename() << ".msu", file::mode_read)) {
datafile.seek(mmio.data_offset);
}
if(audiofile.open()) audiofile.close();
char track[16];
sprintf(track, "-%u", mmio.audio_track);
if(audiofile.open(string() << basename << track << ".wav", file::mode_read)) {
if(audiofile.open(string() << cartridge.basename() << track << ".wav", file::mode_read)) {
audiofile.seek(mmio.audio_offset);
}
}

View File

@@ -1,4 +1,4 @@
#include <snes/snes.hpp>
#include <snes.hpp>
#define OBC1_CPP
namespace SNES {

View File

@@ -93,12 +93,12 @@ unsigned SA1IRAM::size() const {
}
uint8 SA1IRAM::read(unsigned addr) {
scheduler.sync_copcpu();
sa1.synchronize_cpu();
return memory::iram.read(addr);
}
void SA1IRAM::write(unsigned addr, uint8 data) {
scheduler.sync_copcpu();
sa1.synchronize_cpu();
memory::iram.write(addr, data);
}
@@ -111,12 +111,12 @@ unsigned CPUIRAM::size() const {
}
uint8 CPUIRAM::read(unsigned addr) {
scheduler.sync_cpucop();
cpu.synchronize_coprocessor();
return memory::iram.read(addr);
}
void CPUIRAM::write(unsigned addr, uint8 data) {
scheduler.sync_cpucop();
cpu.synchronize_coprocessor();
memory::iram.write(addr, data);
}
@@ -129,12 +129,12 @@ unsigned SA1BWRAM::size() const {
}
uint8 SA1BWRAM::read(unsigned addr) {
scheduler.sync_copcpu();
sa1.synchronize_cpu();
return memory::cartram.read(addr);
}
void SA1BWRAM::write(unsigned addr, uint8 data) {
scheduler.sync_copcpu();
sa1.synchronize_cpu();
memory::cartram.write(addr, data);
}
@@ -147,13 +147,13 @@ unsigned CC1BWRAM::size() const {
}
uint8 CC1BWRAM::read(unsigned addr) {
scheduler.sync_cpucop();
cpu.synchronize_coprocessor();
if(dma) return sa1.dma_cc1_read(addr);
return memory::cartram.read(addr);
}
void CC1BWRAM::write(unsigned addr, uint8 data) {
scheduler.sync_cpucop();
cpu.synchronize_coprocessor();
memory::cartram.write(addr, data);
}
@@ -166,7 +166,7 @@ unsigned BitmapRAM::size() const {
}
uint8 BitmapRAM::read(unsigned addr) {
scheduler.sync_copcpu();
sa1.synchronize_cpu();
if(sa1.mmio.bbf == 0) {
//4bpp
@@ -190,7 +190,7 @@ uint8 BitmapRAM::read(unsigned addr) {
}
void BitmapRAM::write(unsigned addr, uint8 data) {
scheduler.sync_copcpu();
sa1.synchronize_cpu();
if(sa1.mmio.bbf == 0) {
//4bpp

View File

@@ -521,7 +521,7 @@ uint8 SA1::mmio_r230e() {
}
uint8 SA1::mmio_read(unsigned addr) {
(co_active() == scheduler.thread_cpu ? scheduler.sync_cpucop() : scheduler.sync_copcpu());
(co_active() == cpu.thread ? cpu.synchronize_coprocessor() : synchronize_cpu());
addr &= 0xffff;
switch(addr) {
@@ -546,7 +546,7 @@ uint8 SA1::mmio_read(unsigned addr) {
}
void SA1::mmio_write(unsigned addr, uint8 data) {
(co_active() == scheduler.thread_cpu ? scheduler.sync_cpucop() : scheduler.sync_copcpu());
(co_active() == cpu.thread ? cpu.synchronize_coprocessor() : synchronize_cpu());
addr &= 0xffff;
switch(addr) {

View File

@@ -1,4 +1,4 @@
#include <snes/snes.hpp>
#include <snes.hpp>
#define SA1_CPP
namespace SNES {
@@ -11,6 +11,8 @@ SA1 sa1;
#include "memory/memory.cpp"
#include "mmio/mmio.cpp"
void SA1::Enter() { sa1.enter(); }
void SA1::enter() {
while(true) {
if(scheduler.sync == Scheduler::SynchronizeMode::All) {
@@ -20,7 +22,7 @@ void SA1::enter() {
if(mmio.sa1_rdyb || mmio.sa1_resb) {
//SA-1 co-processor is asleep
tick();
scheduler.sync_copcpu();
synchronize_cpu();
continue;
}
@@ -61,8 +63,8 @@ void SA1::last_cycle() {
}
void SA1::interrupt(uint16 vector) {
op_read(regs.pc.d);
op_io();
SA1::op_read(regs.pc.d);
SA1::op_io();
if(!regs.e) op_writestack(regs.pc.b);
op_writestack(regs.pc.h);
op_writestack(regs.pc.l);
@@ -78,8 +80,8 @@ bool SA1::interrupt_pending() {
}
void SA1::tick() {
scheduler.addclocks_cop(2);
if(++status.tick_counter == 0) scheduler.sync_copcpu();
step(2);
if(++status.tick_counter == 0) synchronize_cpu();
//adjust counters:
//note that internally, status counters are in clocks;
@@ -122,17 +124,18 @@ void SA1::enable() {
void SA1::power() {
regs.a = regs.x = regs.y = 0x0000;
regs.s = 0x01ff;
vbrbus.init();
sa1bus.init();
reset();
}
void SA1::reset() {
create(SA1::Enter, system.cpu_frequency());
memory::cc1bwram.dma = false;
for(unsigned addr = 0; addr < memory::iram.size(); addr++) {
memory::iram.write(addr, 0x00);
}
vbrbus.init();
sa1bus.init();
regs.pc.d = 0x000000;
regs.x.h = 0x00;

View File

@@ -1,6 +1,6 @@
#include "bus/bus.hpp"
class SA1 : public CPUcore, public MMIO {
class SA1 : public Coprocessor, public CPUcore, public MMIO {
public:
#include "dma/dma.hpp"
#include "memory/memory.hpp"
@@ -17,6 +17,7 @@ public:
uint16 hcounter;
} status;
static void Enter();
void enter();
void interrupt(uint16 vector);
void tick();

View File

@@ -1,6 +1,7 @@
#ifdef SA1_CPP
void SA1::serialize(serializer &s) {
Processor::serialize(s);
CPUcore::core_serialize(s);
//sa1.hpp

View File

@@ -1,4 +1,4 @@
#include <snes/snes.hpp>
#include <snes.hpp>
#define SDD1_CPP
namespace SNES {

View File

@@ -0,0 +1,97 @@
#include <snes.hpp>
#define SERIAL_CPP
namespace SNES {
Serial serial;
#include "serialization.cpp"
static void snesserial_tick(unsigned clocks) { serial.add_clocks(clocks * 8); }
static uint8 snesserial_read() { return serial.read(); }
static void snesserial_write(uint8 data) { serial.write(data); }
void Serial::Enter() { serial.enter(); }
void Serial::enter() {
latch = 0;
add_clocks(256 * 8); //warm-up
if(snesserial_main) snesserial_main(snesserial_tick, snesserial_read, snesserial_write);
while(true) add_clocks(frequency); //snesserial_main() fallback
}
void Serial::add_clocks(unsigned clocks) {
step(clocks);
synchronize_cpu();
}
uint8 Serial::read() {
while(cpu.joylatch() == 0) add_clocks(1);
while(cpu.joylatch() == 1) add_clocks(1);
add_clocks(4);
uint8 data = 0;
for(unsigned i = 0; i < 8; i++) {
add_clocks(8);
data = (cpu.joylatch() << 7) | (data >> 1);
}
return data;
}
void Serial::write(uint8 data) {
latch = 1;
add_clocks(8);
for(unsigned i = 0; i < 8; i++) {
latch = (data & 1) ^ 1;
data >>= 1;
add_clocks(8);
}
latch = 0;
add_clocks(8);
}
uint8 Serial::mmio_read(unsigned addr) {
cpu.synchronize_coprocessor();
switch(addr & 1) { default:
case 0: return r4016->mmio_read(addr);
case 1: return r4017->mmio_read(addr);
}
}
void Serial::mmio_write(unsigned addr, uint8 data) {
cpu.synchronize_coprocessor();
switch(addr & 1) { default:
case 0: r4016->mmio_write(addr, data); break;
case 1: r4017->mmio_write(addr, data); break;
}
}
void Serial::init() {
}
void Serial::enable() {
r4016 = memory::mmio.mmio[0x4016 - 0x2000];
r4017 = memory::mmio.mmio[0x4017 - 0x2000];
memory::mmio.mmio[0x4016 - 0x2000] = this;
memory::mmio.mmio[0x4017 - 0x2000] = this;
if(opened()) close();
string name = notdir(cartridge.basename());
string path = dir(cartridge.basename());
if(open(name, path)) {
snesserial_main = sym("snesserial_main");
}
}
void Serial::power() {
reset();
}
void Serial::reset() {
create(Serial::Enter, cartridge.serial_baud_rate() * 8);
}
}

View File

@@ -0,0 +1,25 @@
class Serial : public Coprocessor, public MMIO, public library, public property<Serial> {
public:
static void Enter();
void enter();
void init();
void enable();
void power();
void reset();
void serialize(serializer&);
readonly<bool> latch;
void add_clocks(unsigned clocks);
uint8 read();
void write(uint8 data);
uint8 mmio_read(unsigned addr);
void mmio_write(unsigned addr, uint8 data);
private:
MMIO *r4016, *r4017;
function<void (void (*)(unsigned), uint8_t (*)(), void (*)(uint8_t))> snesserial_main;
};
extern Serial serial;

View File

@@ -0,0 +1,8 @@
#ifdef SERIAL_CPP
void Serial::serialize(serializer &s) {
Processor::serialize(s);
s.integer((bool&)latch);
}
#endif

View File

@@ -1,4 +1,4 @@
#include <snes/snes.hpp>
#include <snes.hpp>
#define SPC7110_CPP
namespace SNES {

View File

@@ -1,4 +1,4 @@
#include <snes/snes.hpp>
#include <snes.hpp>
#define SRTC_CPP
namespace SNES {

View File

@@ -1,4 +1,4 @@
#include <snes/snes.hpp>
#include <snes.hpp>
#define ST0010_CPP
namespace SNES {

View File

@@ -1,4 +1,4 @@
#include <snes/snes.hpp>
#include <snes.hpp>
#define ST0011_CPP
namespace SNES {

View File

@@ -1,4 +1,4 @@
#include <snes/snes.hpp>
#include <snes.hpp>
#define ST0018_CPP
namespace SNES {

View File

@@ -27,7 +27,7 @@ unsigned SuperFXGSUROM::size() const {
uint8 SuperFXGSUROM::read(unsigned addr) {
while(!superfx.regs.scmr.ron && scheduler.sync != Scheduler::SynchronizeMode::All) {
superfx.add_clocks(6);
scheduler.sync_copcpu();
superfx.synchronize_cpu();
}
return memory::cartrom.read(addr);
}
@@ -35,7 +35,7 @@ uint8 SuperFXGSUROM::read(unsigned addr) {
void SuperFXGSUROM::write(unsigned addr, uint8 data) {
while(!superfx.regs.scmr.ron && scheduler.sync != Scheduler::SynchronizeMode::All) {
superfx.add_clocks(6);
scheduler.sync_copcpu();
superfx.synchronize_cpu();
}
memory::cartrom.write(addr, data);
}
@@ -47,7 +47,7 @@ unsigned SuperFXGSURAM::size() const {
uint8 SuperFXGSURAM::read(unsigned addr) {
while(!superfx.regs.scmr.ran && scheduler.sync != Scheduler::SynchronizeMode::All) {
superfx.add_clocks(6);
scheduler.sync_copcpu();
superfx.synchronize_cpu();
}
return memory::cartram.read(addr);
}
@@ -55,7 +55,7 @@ uint8 SuperFXGSURAM::read(unsigned addr) {
void SuperFXGSURAM::write(unsigned addr, uint8 data) {
while(!superfx.regs.scmr.ran && scheduler.sync != Scheduler::SynchronizeMode::All) {
superfx.add_clocks(6);
scheduler.sync_copcpu();
superfx.synchronize_cpu();
}
memory::cartram.write(addr, data);
}

View File

@@ -1,7 +1,7 @@
#ifdef SUPERFX_CPP
uint8 SuperFX::mmio_read(unsigned addr) {
scheduler.sync_cpucop();
cpu.synchronize_coprocessor();
addr &= 0xffff;
if(addr >= 0x3100 && addr <= 0x32ff) {
@@ -53,7 +53,7 @@ uint8 SuperFX::mmio_read(unsigned addr) {
}
void SuperFX::mmio_write(unsigned addr, uint8 data) {
scheduler.sync_cpucop();
cpu.synchronize_coprocessor();
addr &= 0xffff;
if(addr >= 0x3100 && addr <= 0x32ff) {

View File

@@ -1,6 +1,8 @@
#ifdef SUPERFX_CPP
void SuperFX::serialize(serializer &s) {
Processor::serialize(s);
//superfx.hpp
s.integer(clockmode);
s.integer(instruction_counter);

View File

@@ -1,4 +1,4 @@
#include <snes/snes.hpp>
#include <snes.hpp>
#define SUPERFX_CPP
namespace SNES {
@@ -13,6 +13,8 @@ namespace SNES {
SuperFX superfx;
void SuperFX::Enter() { superfx.enter(); }
void SuperFX::enter() {
while(true) {
if(scheduler.sync == Scheduler::SynchronizeMode::All) {
@@ -21,7 +23,7 @@ void SuperFX::enter() {
if(regs.sfr.g == 0) {
add_clocks(6);
scheduler.sync_copcpu();
synchronize_cpu();
continue;
}
@@ -30,7 +32,7 @@ void SuperFX::enter() {
if(++instruction_counter >= 128) {
instruction_counter = 0;
scheduler.sync_copcpu();
synchronize_cpu();
}
}
}
@@ -50,6 +52,7 @@ void SuperFX::power() {
}
void SuperFX::reset() {
create(SuperFX::Enter, system.cpu_frequency());
superfxbus.init();
instruction_counter = 0;

View File

@@ -1,6 +1,6 @@
#include "bus/bus.hpp"
class SuperFX : public MMIO {
class SuperFX : public Coprocessor, public MMIO {
public:
#include "core/core.hpp"
#include "memory/memory.hpp"
@@ -8,13 +8,12 @@ public:
#include "timing/timing.hpp"
#include "disasm/disasm.hpp"
static void Enter();
void enter();
void init();
void enable();
void power();
void reset();
void serialize(serializer&);
private:

View File

@@ -16,8 +16,8 @@ void SuperFX::add_clocks(unsigned clocks) {
}
}
scheduler.addclocks_cop(clocks);
scheduler.sync_copcpu();
step(clocks);
synchronize_cpu();
}
void SuperFX::rombuffer_sync() {

Some files were not shown because too many files have changed in this diff Show More