Compare commits

...

137 Commits
v021 ... v039

Author SHA1 Message Date
byuu
67318297dd Update to bsnes v039 release.
Changelog:
    - Recovered ~10% speed loss from last release via S-CPU IRQ timing optimizations
    - Implemented O(1) binary-heap priority queue for event scheduling
    - Fixed a bug where BS-X slotted carts were never mapping SRAM
    - Fixed a bug where invalid controller input was always being allowed
    - Fixed all compilation warnings with GCC 4.3 and Visual C++ 9.0
    - Added advanced options to control S-CPU ALU hardware delays
    - S-RTC and SPC7110 timers updated to handle time_t overflow (Y2k38) gracefully
    - Cheat codes can now have multiple codes per entry, and multiple lines per description
    - Rewrote config file parser; removed config/ class from emulator core
    - Windows: added 256x256 image to program icon set
    - Linux: fixed Xorg keysym mapping, key names should show correctly in all cases now
    - UI: updated video panel, added fullscreen-on-startup and NTSC merge fields options
    - UI: simplified audio panel
    - UI: boolean options on advanced panel can be toggled via double-click
    - Lots of code cleanup, especially for S-CPU IRQ handling and nall template library
2009-01-18 10:21:22 +00:00
byuu
1a6de37454 Update to bsnes v038r13? release.
<edit: removed outdated WIP>

**Delta queue support**

First up, I've added a binary min-heap delta queue. I converted all
events except IRQ/NMI test and hold. If we can convert these to use
the delta queue, there should be a speedup of 30-40% or so -- pretty
much the biggest low-hanging fruit there is. And the thing that has
plagued me for 12-18 months in the past before the major speed hit
v0.018 when I gave up and went with testing IRQ/NMI on every single
clock tick.

But it won't be easy: the delta queue works by adding an event when
you know its going to trigger. But we cannot _know_ if an IRQ or NMI
interrupt will trigger until we're at the current time. One can
literally disable or change these 2 clocks before they occur, which
would leave a bad trigger event in our queue.

IRQ/NMI hold also needs to be scheduled exactly four clocks after
IRQ/NMI trigger. Unless we queue these at least ~16 clocks in advance
of the trigger, then we may not be able to trip them exactly when
needed.

Since the test/hold are in the same inner loop, before or after the
delta queue time update, we can't just enqueue the hold and not the
test.

So, in the WIP I've included my insanely rigorous test ROMs for IRQ,
NMI and HDMA timing, and I'm asking for help. If anyone could please
help in merging sCPU::add_clocks() IRQ testing into the delta queue,
I'd be greatly in their debt.

Relevant code is at src/cpu/scpu/timing/[timing.cpp, irq.cpp] and
src/cpu/scpu/deltaqueue.cpp.

I'll be working on it as well, of course.

Note: removing events not at the top of the heap is not supported.
_If_ this is needed, it would probably be best to do an O(n) search
for the event, and overwrite the event code with 0 (meaning ignored)
than to try and pull out the event and renormalize the heap. IRQ/NMI
hold edge cases are very rare, so O(n) time shouldn't hurt speed.

**ALU delay**

Since there's no speed hit anymore, I added back hardware ALU (mul /
div) delays. While we still don't emulate the proper partial
calculation results, we should at least return 0 when reading too
soon.

The exact delay varies based upon the calculation, however. We ran
into problems with Taz-Mania in the past. So for this WIP only, I've
added settings to the advanced panel:
"temp.alu_mul_delay" + "temp.alu_div_delay"

The value has to be a _multiple of 2_ (2, 4, ... 32, 34, ...), and the
goal is to find the _highest_ possible value that will not cause any
bugs in games.

What I'm asking is for people to just set the value to something and
test a few games. If you spot a bug that's not in v038, try lowering
the value until it goes away. Then post the values here. We'll keep
lowering the current number until we find the best setting for future
releases.

Let's start with really high values that will definitely cause bugs:
ALU mul delay = 104
ALU div delay = 208

For example, pick any game ... say Zelda 3. Note how the triforces
won't render now. Lower the value until it works, post what numbers
you needed here plus the game name. Then everyone will use those
values and test other games. Rinse and repeat.

_Important note:_ you have to reset the game after changing these
values in the GUI for them to take effect.

**Fullscreen on startup**

I've added "video.start_in_fullscreen_mode". Because there's no way to
exit other than a keyboard shortcut, I've unhid the "Exit" option for
now. We can discuss the UI design stuff in the main v038 talk thread,
just stick to mentioning if you hit any bugs with it for this thread.

Thanks to all in advance for any help here!

[No archive available]
2009-01-02 12:01:00 +00:00
byuu
de47a2c7de Update to bsnes v038r12? release.
New WIP adds nothing new, but fixes Visual C++ compilation issues.
Stopped windows.h from defining min/max again, disabled (bool)intmax_t
stupidity, added a default: so VC doesn't assume a function has a
blank return path, omitted -static on libco, and reverted to always
using windres over rc. Express Edition lacks rc, and you already need
GNU make anyway, so why bother supporting rc, too?

> Can you tell me what I should include?


It looks like the taskbar is only 32x32 ... yet the result looks
really weird. Almost like the .ico file only has a 1-bit transparency
mask or something :/

Image

As you can see, all the other icons look much sharper.

> I always wondered why the entire line of an entry doesn't highlight.


I have no idea ... don't see any other listview styles I can use
that'd highlight the whole thing :/

[No archive available]
2009-01-13 15:12:00 +00:00
byuu
25ad9701ab Update to bsnes v038r11? release.
New WIP.

- invalid input is blocked again when input.allow_invalid_input ==
false
- vertical scrollbar only appears when needed in multi-line textboxes
- cheat editor properly encodes / decodes quotes and line breaks
- advanced panel now allows double clicking boolean items to toggle
their state
- cleaned up all of the nall template library
- nall::array was missing copy constructor, causing swap/sort to fail
- moved start in fullscreen to advanced panel for now
- renamed most of the options FitzRoy asked for

> Invalid input is always allowed in bsnes. The config file option
> doesn't change that.


Thank you very much, that was a huge oversight.

> In the latest WIP I've notice Pro Action Replay codes aren't working
> anymore. For example, try these codes for Super Mario World (U);


Those work fine for me ... maybe try the next WIP?

> Here's a couple of boolean advanced options I'd like to see:

> misc.minimize_to_system_tray
> misc.run_at_system_startup


System tray control is probably something the GUI library needs
anyway, but its value is completely lost for Windows 7 -- the taskbar
works similar to the system tray + quick launch. In fact, by default
tray items are hidden and require you to go through a menu to get to
them.

Run at startup would be tricky. I could only get that working on
Windows, and it's really something the user should do externally. Drag
it to the startup folder, put it in the registry, use MS config,
whatever. Also seems very niche, no? You'd still have to load a game
for it to be useful.

> maybe the two file ones as well, not sure what use those have


One is for OS X users. Some of them don't understand file extensions.
The other is for ROM hackers. It'd be needed to multi-chain UPS
patches in the future, as well.

> I'd also like a minor change in the system menu: flip the power
> settings with the controller settings.


Why? Seems arbitrary, and I like the current ordering. We can even
make up some crazy stuff to support the current ordering:

1) Looking at an SNES from top to bottom, you have the cart slot, then
power / reset, then controllers.

2) Group options that affect carts, then group options that affect
input.

> Let me know when you're ready to talk about the readme overhaul.


Will probably release v039 next weekend. Can work on the readme for
v040, I guess.

[No archive available]
2009-01-12 14:44:00 +00:00
byuu
9a5a3b8246 Update to bsnes v038r10? release.
Probably a mapping issue. Wish we could've spotted it less than 21
versions ago, would've been easier to find the regression. Ah well, at
least we found it now.

New WIP completes the multi-part cheat codes. I changed the file
format, and it may change again, so backup your old .cht files first.

Went with the unified textbox thing to allow infinite number of codes
per cheat item, though the textbox itself will stop parsing after
1,024 bytes at the moment. Really ... you're doing something wrong if
you need more than ~120 parts for one cheat code entry.

It will parse and treat spaces, +&|,;{tab} and {linefeed} as
separators for codes. You will lose the space formatting after you
okay the code and go back to edit it again.

Also one glitch if you toggle cheat status, it won't clip the extra
cheat parts as it should. Will fix it later, ran out of time. Don't
try multi-line descriptions or commas for separators just yet. Need to
iron proof that so it won't corrupt the file format.

Any testing of this new feature would be greatly appreciated.

Design questions:

- should we change the order of desc/code/enablestate on either the
main cheat window or the cheat sub-editing window? If so, why? Be
verbose, use examples.
- should we change the .cht file format? Again, please clarify what
the advantage would be.
- should we change the text labels for the sub cheat editor to
something more clear?
- should the default separator be changed from " + " to something
else? Maybe linefeed?

[No archive available]
2009-01-09 16:18:00 +00:00
byuu
daac76858b Update to bsnes v038r09? release.
Damn, absolutely loving this Aftershock I just picked up. Scary stuff
-- 80 proof and it tastes like a malt beverage.

New WIP, added the cheat code editor UI changes. The cheat code class
in the back-end still doesn't actually support multiple codes just
yet, but it will.

Image

Need to decide how many codes we should allow. A real Game Genie
didn't allow more than five, so I think we should go with either four
or six.

Also not shown, when a code you're editing is incomplete / bad,
there's a grayed out text label that appears on the right to tell you
that the code is invalid. It also disables the ok button during this
time.

I wouldn't try entering a multi-line description just yet. I don't
parse that at all. Worst case, it'll corrupt your cheat file. My plan
is to only show the first text line in the listbox, but allow extra
lines for more verbose comments.

I'm being lazy and disabling the add/edit/delete buttons from the main
window when the sub editor window is open. Prevents abuses like
deleting the code you're editing, then trying to update it.

[No archive available]
2009-01-06 15:58:00 +00:00
byuu
c63df7e009 Update to bsnes v038r08? release.
Another WIP, but nothing visible to end users. Still get it if you
don't have 07 for the nice speedup.

Mostly source-cleaning stuff.
- removed 'uint' type, replaced all instances with the proper unsigned
int.
- removed as many headers as I could from the global interface.hpp
file, including only in the cores that need each of them. Should help
compile time. Though I still have a lot of global header includes due
to needing ultra-hot sections of code inlined.
- added include protection bumpers to the CPU+SMP opcode core
generated files
- added const-correctness to a few more classes.
- updated S-RTC and SPC7110 time to handle time_t overflow: it's now
Y2K38 proof even on 32-bit signed time_t systems, and the file format
remains unchanged. But it adds one limitation that you'll lose your
time if you wait ~34 years before loading your last save game. I think
that's reasonable for now. Once 64-bit time_t systems are ubiquitous,
we should be able to trivially expand that without breaking old saves.

Relevant code (I tested with int16_t, uint16_t, int32_t, uint32_t,
int64_t and uint64_t):

      time_t diff
      = (current_time >= rtc_time)
      ? (current_time - rtc_time)
      : (std::numeric_limits<time_t>::max() - rtc_time + current_time
    + 1);  //compensate for overflow
      if(diff > std::numeric_limits<time_t>::max() / 2) diff = 0;
    //compensate for underflow


Avoided the obvious (y-x)&<time_t>::max() just in case there's some
crazy platform where the value != (some power of 2)-1. Modulus
(max()+1) won't work there either, as it'll overflow if
sizeof(unsigned) == sizeof(time_t). The +1 might throw it off by a
second on one's complement system, but I don't really care :P

Anyone with GCC 4.3 want to try something for me? Try modifying
src/lib/nall/platform.hpp and change #define alwaysinline
__attribute__((always_inline)) to:
    #define alwaysinline __attribute__((always_inline))
    __attribute__((hot))


... and let me know the FPS difference you get in some arbitrary game,
please :D

It's supposed to be like manual-PGO.

[No archive available]
2009-01-05 12:33:00 +00:00
byuu
3908890072 Update to bsnes v038r05? release.
New WIP, this one's fairly big as nightlies go.

First, moved the priority queue to a generic implementation so I can
re-use it elsewhere in the future. Took a ~1% speed hit or so by using
functors for the callback and using the signed math trick to avoid the
need for a normalize() function. Sadly it gets up to 3% slower if the
priorityqueue class code isn't placed right next to the CPU core.

Second, while I failed miserably at using the queues for IRQ / NMI
testing, I did come up with a neat compromise. NMI is only tested once
per scanline, IRQs only have PPU dot precision (every 4 clocks), the
hold time for both is four clock cycles, and scanlines for both NTSC
and PAL, even on the short colorburst scanline, are always evenly
divisible by four.
... so testing every 2 clock cycles was kind of pointless, as it'd
always be false. Since the delays between the PPU counter and CPU
trigger for NMI is 2, and IRQ is 10, they even align again with an
offset of 2.
... hence, I can call poll_interrupts() half as often by using
if(ppu.hcounter() & 2). I reverse that for the Super Scope / Justifier
dot testing and cut their overhead in half as well.

That gives us a nice ~10-15% speedup. Nowhere near the idealistic
~30-40% for range tested IRQs, because that only actually tests once
per scanline (~1364 cycles). This just cuts ~682 tests down to ~341
tests. Still, it's pretty close to half as good while still being
super clean and easy. It greatly diminishes the value of a range-based
IRQ tester, as that will only offer a ~15-20% speedup now at best.
Getting PGO working again is the new lowest-hanging fruit.

I also eked out a tiny bit more speed by adding some previous missed
"else" statements in the irq_valid testing part.

With the newfound speed, I gave a tiny bit up (1-2%) to simplify and
improve some old edge cases. It's known that IRQs won't trigger on the
very last dot of each field. It's due to the way the V and H counters
are misaligned, that we can't easily emulate.

So before I had a bunch of cruft to support that, update_interrupts()
was called at the start of each scanline, which would call irq_valid()
to run a bunch of tests to make sure the latch positions would
actually work on hardware. Writes to $4207-420a would also call the
update_interrupts() proc.

I killed all that, and now compute the HTIME position inline in
poll_interrupts(), and perform the last dot check there. Since testing
is ten clocks behind anyway, then we need only check to see if VTIME >
0 and ppu.vcounter(-6 clocks) == 0 to know that it was set for the
last dot on any given field.

This gives us two nice perks for free: one, no more need to hard-code
scanlines/frame inside the CPU core; and two, the old version was
missing an edge case in interlace mode where odd fields would allow an
IRQ on the last dot, which was simply because my old irq_valid() test
didn't have a third condition for that.

All that said, I'm getting ~157.5fps instead of ~137.5fps now in Zelda
3.

Third, I removed grayscale/sepia/invert from the video settings panel,
and stuck them in advanced. Used the new space to add checkboxes for
NTSC merge fields and the start in fullscreen thing.

Reference:
    //called once every four clock cycles;
    //as NMI steps by scanlines (divisible by 4) and IRQ by PPU
    4-cycle dots.
    //
    //ppu.(vh)counter(n) returns the value of said counters n-clocks
    before current time;
    //it is used to emulate hardware communication delay between
    opcode and interrupt units.
    alwaysinline void sCPU::poll_interrupts() {
      //NMI hold
      if(status.nmi_hold) {
        status.nmi_hold = false;
        if(status.nmi_enabled) status.nmi_transition = true;
      }

      //NMI test
      bool nmi_valid = (ppu.vcounter(2) >= (!ppu.overscan() ? 225 :
    240));
      if(!status.nmi_valid && nmi_valid) {
        //0->1 edge sensitive transition
        status.nmi_line = true;
        status.nmi_hold = true;  //hold /NMI for four cycles
      } else if(status.nmi_valid && !nmi_valid) {
        //1->0 edge sensitive transition
        status.nmi_line = false;
      }
      status.nmi_valid = nmi_valid;

      //IRQ hold
      status.irq_hold = false;
      if(status.irq_line) {
        if(status.virq_enabled || status.hirq_enabled)
    status.irq_transition = true;
      }

      //IRQ test (unrolling the duplicate Nirq_enabled tests causes
    speed hit)
      bool irq_valid = (status.virq_enabled || status.hirq_enabled);
      if(irq_valid) {
        if((status.virq_enabled && ppu.vcounter(10) !=
    (status.virq_pos))
        || (status.hirq_enabled && ppu.hcounter(10) !=
    (status.hirq_pos + 1) * 4)
        || (status.virq_pos && ppu.vcounter(6) == 0)  //IRQs cannot
    trigger on last dot of field
        ) irq_valid = false;
      }
      if(!status.irq_valid && irq_valid) {
        //0->1 edge sensitive transition
        status.irq_line = true;
        status.irq_hold = true;  //hold /IRQ for four cycles
      }
      status.irq_valid = irq_valid;
    }

[No archive available]
2009-01-04 15:41:00 +00:00
byuu
155b4fbfcd Update to bsnes v038r04? release.
New private WIP. Nothing worth downloading it over, really.
- fixed first scanline DRAM refresh event (passes irq.smc and nmi.smc
again)
- fixed PPUcounter to initialize before CPU; not that it affected
anything as-is, but it's nice for future proofing to do it right
- optimized priority queue thing to move instead of swap; didn't
affect overall emu speed sadly (still infinitesimally faster than the
last official release), but I still like the model for timing events
that will occur no matter what
- made the ALU delays more permanent advanced config options; 32 and
48 were still screwing with taz-mania ... not even a whole opcode on
the mul -- that game literally reads the regs immediately. We can't
get things any better than we already have until we emulate the
formula; so I set them both to 2 clock cycles for now, they're at
least there for hobbyist devs, who can set them fairly high to
guarantee their code would work on hardware
- removed a bit of cruft

> * RSA-1024 is busted


Really? What are its factors, then? Please tell me in private so I can
claim the $100,000 bounty when it's offered again :D
(they've only broken a 200-decimal digit one with the equivalent of 75
PC work-years, RSA-1024 has 309 and the problem is exponential, not
linear.)

[No archive available]
2009-01-03 15:26:00 +00:00
byuu
02ca0f1e69 Update to bsnes v038r05 release.
[No changelog available]
2009-01-02 20:13:50 +00:00
byuu
6cacb2517a Update to bsnes v038r03? release.
I haven't posted the new WIP, just updating on the status of it.

First, I noticed that Xorg changed the keycodes, at least for Kubuntu
8.10. belegdol, the other person at RPM fusion was mentioning that he
was getting weird key mappings like page_down for left, etc -- this
would be why. Didn't realize they were variable like that. I went back
and made a lookup table to convert the official keysyms to keycodes,
so this issue should now be fixed. Anyone packaging bsnes is free to
update to the latest WIPs to fix this if they like.

Second, I added "adjust" to brightness/contrast/gamma, and they all
start at 0% centered, go to -95% and +95%. Still not sure what to name
"Frequency adjust", so I left that alone for now.

Third, I updated the ~400 or so %0.nx sprintf statements to %.x, so
that GCC 4.2+ will shut the hell up.

Lastly, I can't come up with a good double->string conversion routine
(causes subtle rounding errors with the obvious approach), so I
wrapped strdouble() around snprintf. bsnes doesn't even use it yet,
but at least it can now ...

> How would dropdowns be better than what ZSNES is currently using?


The WIP link on Rapidshare is dead ... what are they using? If it
doesn't involve tab panels, then I can do that.

> Wouldn't these just be hardware filters like NTSC that simulate the
> lossy characteristics of certain type of analog output?


These are settings _for_ the NTSC filter to affect its quality. They
don't affect any other filters.

> There's no fundamental difference between a coprocessor and central
> processor in the scheme of emulation. That the coprocessor happened
> to be located on what we would physically categorize as the
> "cartridge" is immaterial.


There's quite a large distinction between something inside the SNES
and outside. I understand where you're coming from, but we shouldn't
pretend as though the SNES contains all these chips, either.

Sheesh, I don't even know what we're discussing here anymore :P

> You'd be crazy to externalize all your code just to allow people to
> create imaginary 10ft boards with 2ghz GPUs.


What I wouldn't give for just one person to make such a board ... :D

> The only invaluable option in that entire section is overload's
> gamma curve, everything else about the image can be destroyed in my
> video driver or monitor settings.


Haven't we covered this in the past? SNES games were played with
gamma, etc settings calibrated to NTSC / PAL televisions. Monitors are
calibrated very differently. I doubt anyone wants to go into their
driver control panels to adjust these settings every time they start
and close the emulator. And cheaper drivers (especially on Linux) may
not have these options at all.

Not saying we have to go crazy here ... I'm happy to leave out
hue/saturation settings.

> I am aware that any changes made to WIP releases are posted here on
> this forum, but maybe it's an idea to start including those as well
> on the WIP download page?


I _could_ ... but it's easier to type things up here later on at my
convenience :/

[No archive available]
2008-12-28 09:55:00 +00:00
byuu
9a8203b3c3 Update to bsnes v038r02? release.
New WIP.

- defaults are now centered for video settings panel sliders, modified
default gamma to 100 with gamma curve enabled.
- removed all the preset buttons, it looks terrible with just one.
- fixes 99% of the useless bullshit warnings with GCC 4.3, still
didn't change all the "%0.2x->%.2x" strings in the disassemblers
though.
- fixed up the double->nall::string conversion, but it still has some
rounding issues, so I can't use it yet. About ready to just implement
that as a wrapper around sprintf.

> Byuu i would like to request support for the following audio
> renderers.


Sure, you can post them here when you're done and I'll include them in
the source. If they don't cause missing driver errors on a clean
install of Win2k SP4 or newer (this is why Win/OpenAL is disabled),
then I'll enable them in the default binary as well.

[No archive available]
2008-12-22 13:20:00 +00:00
byuu
9c7ac24ff7 Update to bsnes v038r01? release.
New WIP. Audio panel was revised, it's now the same both in regular
and advanced mode.

Volume, Frequency and Latency all appear on one row and are all combo
boxes with sane defaults. Advanced mode gives them additional options.

Frequency adjust remains a slider. Given that 1 tick can mean the
difference between frame stuttering once a minute and once an hour, I
think it's worth keeping the precision.

Code-wise, I merged the ppucounter object into the PPU class (through
inheritance). This results in the following code simplification:

Before:
    ppucounter.vcounter()     //S-CPU time
    ppucounter.ppuvcounter()  //S-PPU time


After:
    ppu.vcounter()  //S-CPU time
    ivcounter()     //S-PPU time (called inside its own class, no need
    for ppu. prefix)


i just stands for "internal". It was that or slow things down with a
co_active() check inside the counter read calls.

Man, it feels weird editing C++ code after all of that CSS magic. I
find myself wanting to write a pattern-matching rule ...

    uint16 PPUcounter::vcounter() {
      return cpu_vcounter();
    }

    uint16 PPUcounter::vcounter() [class="PPU"] {
      return ppu_vcounter();
    }


> I probably would have stuck it in a carefully-styled <SPAN> rather
> than an attribute, but I notice your approach is sanctioned by HTML5
> (or at least it would be if you called it "data-date" instead of
> "date").


    <h3><span>2008-12-20</span>Title</h3>
    <blockquote><p>All that is necessary for the triumph of evil is
    that good men do nothing<span>Edmund Burke</span></p></blockquote>


Could work ... looks weird, though. Adding a class type to the spans
to state what they are makes it even more bloated, but perhaps worth
it ... hmm.

HTML5 approach looks cool, too. data- prefix isn't too bad. A good
indicator that it's not a real tag.

EDIT: oops, looks like I forgot that IE6 can't handle the text-align
attribute properly, either. Eh, I'll fix it tomorrow. Tired now.

[No archive available]
2008-12-20 11:36:00 +00:00
byuu
c13ae98863 Update to bsnes v038 release.
- eliminated S-DD1 DMA enslavement to the S-CPU; this allows the S-DD1 to behave more like the real chip, and it also simplifies the S-CPU DMA module
    - eliminated S-PPU enslavement to the S-CPU; all processor cores now run independently of each other
    - added cycle-level S-PPU timing for OAM address reset and OBSEL; fixes scanline glitches in Mega Lo Mania and Winter Olympics
    - removed ppu.hack.* settings; as they are no longer needed due to above changes
    - corrected VRAM tiledata cache bug; fixes Super Buster Bros v1.0 reset glitch
    - added memory export and trace logging key bindings to user interface
    - removed WAV logging (to trim the emulation core)
    - embedded readme and license texts inside executable
    - simplified S-CPU, S-SMP flag register handling
    - source code cleanup for S-CPU timing module
    - GUI-Linux: added style improvements to the listbox and combo box controls
    - GUI-Linux: finally added filetype filter support to the file open dialog
    - GUI-all: shrunk configuration panel [FitzRoy]
    - GUI-all: modified paths panel descriptions for clarity [FitzRoy]
2008-12-15 16:19:04 +00:00
byuu
e370a35d7d Update to bsnes v037r07? release.
New WIP.

The biggest news is that I've implemented what I was discussing
earlier, and it worked perfectly. The S-PPU enslavement to the S-CPU
is no more.

As of this point, all four processor cores, and all three of their
shared relationships, run completely independently of one another.

This required moving the inline timing code from the absolute most
timing-sensitive section of the emulator, to an entirely new external
class. It also required logging more state data, adding ~100k/second
more context switches, etc. It was unavoidable that the new approach
would be slower, but I was able to greatly mitigate the speed loss.
Right now, it stands at a ~6-8% speed loss from the previous release.

But there is good news:
1) aside from SuperFX / SA-1 support, which will require additional
processing inside the emulator core, no other changes should slow down
the emulator again. It can only get faster from here. Most
importantly, a range-based IRQ tester would offer a major speedup.
2) this approach will allow both a scanline-based and cycle-based
S-PPU core to work with only one S-CPU core. No need to subclass and
duplicate the timing code + scheduler as I was planning to before.
3) with this change, I was finally able to convert the scanline-based
S-PPU renderer to a hybrid that I've talked about with FitzRoy in the
past: this allowed me to finally cache OBSEL writes at (roughly) the
appropriate position, while still rendering the screen at a different
point. I render the screen at H=512, and cache OBSEL at H=1152. May
not be hardware accurate, but it allows Adv. of Dr. Franken + Winter
Olympics + Mega Lo Mania to all work as expected, all at the same
time.

It wasn't 100% exactly how I wanted to do things ... but I'm really
happy about this de-coupling. I've always been a purist when it comes
to implementing processor cores independently of one another, and it's
always bothered me greatly the way the CPU controlled the PPU and its
counters.

With the above changes, I've eliminated the four ppu.hack config
settings. I don't see much of a need for them.

I've also embedded the readme and license text files. FitzRoy, I
haven't had a chance to revise the readme as you were suggesting yet.
Not ignoring you there, it's just low on my priority list right now.

Lastly, I took FitzRoy's advice, and removed the WAV logger entirely.
I'm also going to leave the screenshot capture out. At least for now
... the UI is starting to get a bit too bloated for my tastes.

This is also the first uploaded WIP with the new debugging key-
bindings (tracing and memory export.) I don't expect anyone here to
have much use for them.

Anyway, testing would be appreciated. It's very likely that the OBSEL
cache position needs to be tweaked further. I recall LotR or something
also had issues with caching in the past ... but I couldn't find the
game at ::ahem:: the used game shop ... to test it.

I think there were other games that had different behavior based on
the old obsel_cache setting, too. Would be good to make sure they all
work as expected.

EDIT: Ah, "JRR Tolkein's LotR", bah. Yeah, no sprite flickering with
the new WIP. Also, speed hit only seems to affect Core 2's. No frame
drop on my Athlon. Probably something to do with locality of reference
or somesuch. Modern processors are too damned complicated :P

So then, assuming nobody spots any bugs ... how about a new release
tomorrow?

[No archive available]
2008-12-14 05:31:00 +00:00
byuu
a721c7e91b Update to bsnes v037r06? release.
What about calling the "Default" button on the paths window "Auto"
instead?

And no, label text does not wrap. That's why I have the forced line
breaks.

New WIP:
- fixes the tiledata cache glitch for Super Buster Bros V1.0; possibly
others
- adds updated nall templates: copy constructor vector class with
amortized constant growth being the most notable change. Resisted the
CC approach before because it's slower; but the amortized growth
avoids most of the overhead, and I'd rather do things through the CC
than possibly change the internal object memory base address
transparently (invalidating self-pointers and such.)
- adds snes.hide_light_cursors or something similar for Panzer88

Panzer88, I'd appreciate input on the last one. My fear is that
because the system is 100% relative, if you move your Wii remote too
far to the side, it will appear to "throw off" the alignment after the
cursor sticks to one end. Only way around that would be to use
absolute positioning.

It'd be really difficult to support both relative and absolute systems
at the same time, due to the way the drivers work. Absolute cannot
work with the mouse by its very design, and it'd be sketchy with
different window sizes and such for the light guns. And even if no
game uses it -- it _is_ possible to use a mouse on port 1, and a scope
on port 2.

[No archive available]
2008-11-25 15:05:00 +00:00
byuu
14bd3077e5 Update to bsnes v037r02? release.
New WIP.

If anyone on Linux uses this one, be careful. I'm not entirely sure,
but I think my style changes may be affecting the entire theme and not
just bsnes. I looked at example code of other popular apps that do the
same thing, though.

I'm not sure if it's just my imagination. Audacious' file open dialog
seems narrower, but every app still has the menu-style combo-boxes ...
so I don't know.

But if it is changing it -- I don't know how to revert it. Not like
it's a major change, anyway.

F-3582, cool thanks. You have the WIP URL, right?

henke37, it can't do point filtering when upscaling the image (eg the
image always gets blurry.)

[No archive available]
2008-11-03 09:16:00 +00:00
byuu
7236499e2f Update to bsnes v037r01? release.
New WIP.

For Linux users, this adds a PulseAudio driver, using
<pulse/simple.h>. Debian / Ubuntu users will need to add libpulse-dev,
or remove "audio.pulseaudio" from the ruby= line in the Makefile to
compile now.

I wasn't able to test the driver at all -- I get "Connection refused"
when I call pa_simple_new(). It appears that despite having Xubuntu
8.04, it doesn't come with PulseAudio installed. Guess they lied about
it on their website or something ...
I could install the packages, but hearing horror stories from others
-- I'd rather not.

If anyone can test for me, that'd be great. Check the console for
error messages.

Next, I finally got around to re-doing the S-DD1 driver to eliminate
the need to hook DMA transfers inside the S-CPU core to recognize
decompression events. That violated my strict feelings regarding
separation of cores and avoiding enslavement, even when it adds
significant overhead.

I'm now going with a radically different approach, that's hopefully
much more like the real hardware. It explains the way $4800 / $4801
behave, as well as why fixed transfers are required, but it may not be
faithful.

What I do is have the S-DD1 chip spy on $43x2-$43x6, and cache the
values internally. Then, whenever you read from $c0-ff:0000-ffff, it
will test if $4800 & $4801 != 0. If that's the case, we look at the
address requested, if it matches one of the active S-DD1 channels (eg
$4800 & $4801 & (1 << channel#) != 0), then we hijack the read with
decompressed data.

In my implementation, I decompress the entire block on the first read,
then stream from the buffer. On real hardware, it most likely starts
streaming on $4801.dN enable, but that's not too feasible for a few
reasons for me. Most notably the S-DD1 lib requires a size parameter.
It doesn't really matter, since we know the size from $43x5,6; so it
doesn't suffer the same problems the SPC7110 did.

Anyway, once all the data is transferred, it will clear the channel
bit from $4801. There may be some hardware differences here -- can you
perform two transfers at the same time? What happens if HDMA
terminates the DMA channel? These things never happen in Star Ocean or
SFA2, so they'll have to be tested manually.

If no channels are active or there are no address fetch matches, it
invokes the MMC to return raw ROM data.

All of that gives a ~1.5% speedup both to regular games and S-DD1
games. The former because DMA transfers don't have to test for the
S-DD1 during every transfer; the latter because I'm using a quick
lookup table (slower per fetch) in place of re-mapping the whole banks
on writes to the MMC (very slow per write.) The latter was much
cleaner and simpler, but I need the former to hook the decompression
stuff natively.

Windows binary is included, I'd appreciate if anyone could play some
Star Ocean / SFA2 and look for regressions from v037a.

> I'm just so used to seeing everyone having a "Close" button in their
> configuration dialogs I figured bsnes would have one. It just now
> that I looked around that I realised that only some of the
> configuration "panels" actually have buttons.


Ah, I see what you mean. Sorry. I can add one if you want, I suppose.

[No archive available]
2008-10-31 11:05:00 +00:00
byuu
9b03874f32 Update to bsnes v037a release.
[No changelog available]
2008-10-27 15:02:10 +00:00
byuu
a9bff19b5b Update to bsnes v037 release.
This release adds support for the SNES mouse, Super Scope and Justifier peripherals. It also simplifies cartridge loading and refines the user interface. Lastly, GZ and ZIP archives can now contain non-ANSI characters (Chinese, Japanese, Russian, ...) This support existed in the last release for all uncompressed files. Together, this means only JMA support on Windows lacks support for loading non-ANSI filenames. This is due to the library itself (really, it's more Windows' fault), and licensing issues prevent me from patching libjma as I did with zlib (bsnes is not GPL compatible.) I'm planning to work with Nach to fix this in a future release.
About the cartridge loading changes ... the emulator now determines what kind of cartridge is being loaded (eg normal, BS-X BIOS, Sufami Turbo cart, etc) by looking inside the file itself. If it detects a cart type that requires more than one ROM image to load, it will present you with the appropriate specialized load menu automatically. Aside from being more intuitive, this method also allows loading of BS-X and Sufami Turbo games from the command-line or via file association.
Changelog:
    - added mouse support to DirectInput and SDL input drivers
    - up to 96 buttons per controller; 8 buttons per mouse (5 per mouse on Linux) can be mapped now
    - added SNES mouse support (does not support speed setting yet)
    - added Super Scope support
    - added Justifier support (supports both Justifiers)
    - input management system almost completely rewritten to support new controllers
    - "Load Special" menu removed, all cart loading merged to "Load Cartridge ..." option
    - replaced "Power Cycle" and "Unload Cartridge" with "Power" -> "On" / "Off"
    - when video exceeds screen size and is scaled down, aspect ratio is now maintained [Ver Greeneyes]
    - zlib modified to support non-ANSI characters
    - cheat code count was limited to 1,024 codes before; it now supports unlimited codes per game
    - added sort by description setting for cheat code list
    - polished listbox control interaction (disable buttons when nothing selected, etc)
    - cleaned up OBC-1 chip emulation (code is functionally identical to v036)
    - added option to toggle fullscreen mode to settings menu
    - added advanced mode options to toggle base unit (none, Satellaview) and system region (Auto-detect, NTSC, PAL)
2008-10-26 19:59:04 +00:00
byuu
20be19f876 Update to bsnes v036r15? release.
Got the EP / Region stuff hidden in standard UI mode, and added the
text label to the audio panel. Didn't post the WIP, not much point in
testing that.

I think I'll just take it slow, wait another week or so, make sure no
bugs pop up; rather than rush a release this weekend.

> If there is a problem with it, please let me know as I just spent a
> while thinking about it


Yeah, I wasn't sure about the math. That's why I put the height scale
first. I think your code should be fine, too. If someone can
definitively show them to be the same, we can use that just because
it's smaller, which is nice.

> By the way, is it just me or has the NTSC filter's intentional
> glitchyness gotten erratic and unpleasant? It's like it randomly
> gets a seizure


I believe I turned off the NTSC filter's merge fields setting, now
that we have vsync. It needs to have its own panel just for that
filter, I'm just really lazy and don't want to add the hooks to
libfilter to allow modifying NTSC filter settings :/

The merge fields thing looks good when not running at perfect 60hz,
but it's less faithful. I figured more people would be using that
filter with the idea of faithfulness, and thus vsync, enabled.

> Oh, I wasn't bugging you about those again, they're years away from
> feasible.


Just stemming off the inevitable. I do wish it was quick and easy to
add those, like with the other chips. So far the Cx4 has been the
worst (thanks to Andreas Naive and neviksti's awesome S-DD1, SPC7110
and DSP-1 libraries, and Overload's DSP page for the rest.) And I even
had at least half of the Cx4 done by Nach.

> I'll just focus on the next two versions before I ask you if you're
> interested in contributing to something on the game management end
> of things.


I hear game-specific settings are in high-demand. But that's a
difficult thing to get working right. But yeah, thanks; we'll cover
that in a future release.

> 1. I noticed that you may have forgotten to remove video sync from
> the advanced section after it was added as a functional menu option.


Kay, we'll add that to the list.

> 2. What happens when someone uses multiple mice? You currently don't
> list the mapping as mouse00, just mouse. Will this ever pose a
> problem?


Both DirectInput and Xlib only support one mouse. If you plug in two,
they both return input to the same device. You'd need something like
ManyMouse to support multiple mice. I didn't bother as I didn't want
to add another library dependency, and really -- how many people
really have multiple mice on one PC?

It's definitely a really neat feature in ZSNES, and the library itself
is definitely awesome. But I think the analog joystick mapping should
cover people who really want to use dual justifiers / mice for bsnes.

If not, we can always add it in a future release. The guy's license is
really permissive (zlib), which is awesome.

EDIT: this _may_ pose some problems, too ...

> On Windows, ManyMouse requires Windows XP or later to function,
> since it
> relies on APIs that are new to XP...it uses LoadLibrary() on
> User32.dll and
> GetProcAddress() to get all the Windows entry points it uses, so on
> pre-XP
> systems, it will run, but fail to find any mice in ManyMouse_Init().

> ...

> Please note that using DirectInput at the same time
> as ManyMouse can cause problems; ManyMouse does not use DirectInput,
> due
> to DI8's limitations, but its parallel use seems to prevent
> ManyMouse from
> getting mouse input anyhow.

> ...

> (XInput code isn't finished yet, but in the future this note will be
> true.)


Mmm ... those are what I use now. But I think ZSNES uses DirectInput,
too; so who knows.

[No archive available]
2008-10-20 03:23:00 +00:00
byuu
f748a34e49 Update to bsnes v036r14? release.
New WIP. Couple of changes here.

Ran into that damn char *argv[] crushing Unicode on Windows thing
again with the MOTHER 3 patcher. Before I had to #ifdef the main()
entry point and add all kinds of magic to rebuild the command-line
string as UTF-8. So I moved all of that inside of hiro. Linux users
can now use GTK+ command-line arguments as a result, too. And
ui/main.cpp loses a bunch of platform-specific wrappers.

Moved realpath(), userpath() and mkdir() wrappers inside hiro; as they
all need UTF-8 <> UTF-16 stuff anyway. That cuts bbase.h to ~1.5kb.
Very close to killing it off now.

And probably most importantly, added VG's scaling changes. But I redid
the code to support the same effect in windowed mode. I also made sure
it works on portrait monitors, too (eg width is too big; scale height
instead). That was a messy section before. Please test it out and let
me know if it doesn't work as you guys were wanting.

I want to get a new release out shortly. Release-stoppers right now
are:
- axis sensitivity sucks; mouse maps too fast, joypad axes don't map
at all on Windows.
- need to swap mouse.button01 with mouse.button02 so Linux and Windows
use the same IDs; then I need to set defaults for the mouse / SS /
Justifiers.
- need to hide expansion port / region in simple UI mode.
- still need to add that skew help message to the audio settings
panel.

If I'm missing anything serious in the above, eg you know of some
critical bug or something, please let me know now.

I'm going to put off the video panel discussion and ROM PCB mapping
stuff until the next release or so. Too much to cover, and they'd take
too long at this point.

> That saddens me a little, not because I don't think you'd do a great
> job, but because there are far more people rom hacking than there
> are writing emulators or improving emulation.


And what have we been improving for the last two years? :/
It's been 95% GUI polishing and minor bug fixes. The only major change
I can think of off-hand was the HDMA timing improvements.

I'm really starting to doubt that it's possible to simultaneously
allow both the scanline and cycle-based PPUs. I try and come up with
something every other week, and nothing I think of will avoid a major
speed hit to the scanline renderer.

And I really don't personally care about the SuperFX / SA-1. Yes, I
know a lot of you do, and I'll hopefully get around to adding them.
But if I'm going to start a months-long RE task, it's going to be the
PPU first, sorry. And I'm at a major impasse there.

[No archive available]
2008-10-19 08:49:00 +00:00
byuu
0af5703c47 Update to bsnes v036r13? release.
New WIP finally adds non-ANSI filename support for GZ and ZIP
archives. That plus the existing support for uncompressed filenames
means it works with everything now but JMA archives. Compression
support was enabled with this WIP for testing.

I used Nach's suggestion with gzdOpen() for GZ, but I had to modify
ioapi.c for ZIP support, as there was no unzOpen() that took a file
descriptor. No big deal, it was only a four-line change and it works
great.

I noticed that the Windows hiro port wasn't sending the -1 position
for when no items in a listbox were selected. That turned out to an
absolutely major pain in the ass to support, thanks to the way Windows
works. Say you switch from item #3 to no item, it will send "item 3
lost focus", but nothing for the fact that no item has focus. Easy
enough, but then if you switch from item #3 to item #4, it sends "item
3 lost focus", followed by "item 4 gained focus." Since you can't tell
after the first message if a second message will occur, you don't know
whether or not to send a "no items selected" message; and if you try
and wait and there is no message, you won't get a chance to send it
again.

Took a lot of evil state tricks, but I got it working. That'll make
the input config, cheat editor and advanced panel buttons gray out
when nothing in the list is selected. Please let me know if you spot
any oddities with that.

That ate up nearly all of my time ... with only an hour left, I fixed
the input mapping once a cart was loaded; but I didn't have time to
fix the Windows joypad axis mapping bug, which should be the only bug
left at this point.

> Your website got foobared somehow, I can't navigate to places.


I knew what it was before even looking, based on your description.
Derrick's host turned off PHP register globals. Apparently we can't
have nice things because a few dumb fucks can't remember to initialize
variables. Whatever, it's fixed now.

[No archive available]
2008-10-17 14:02:00 +00:00
byuu
f73d0908c4 Update to bsnes v036r12? release.
New WIP, doesn't do much.

The core no longer scales axis values at all; and the platform input
manager scales joypad axes only by 4096. Mice are unscaled here.
Meaning you can use joypads and mice together at the same time now.

Also updated the input config panel to add all the new input devices.
Assignment is still sketchy. My idea is to separate axis movement from
button movement, and allow fast mouse movements (+/- 20 in a given
direction) or strong joypad axis movements (~50% tolerance+) to assign
axis stuff. For buttons, they'd work as before, but you can also click
a mouse button with the mouse over the input capture window.

Disabled Xlib mouse acceleration during capture mode. I don't notice a
difference, but I may as well leave it in case it matters somewhere.
Sadly, it looks like buttons 4/5 are never set via XQueryPointer(),
and you can only get buttons 6-9 with event callbacks. Since the input
wrapper doesn't own the window (in actuality, GTK+ does), I can't
safely bind the XEvents to capture those. So left, middle, right click
only on Linux.

After that's done, we should start polishing for the next release.

> gtk_tree_selection_get_selected() returns items from the underlying
> unsorted list rather than indexes into the sorted list.


Really? That's interesting. Not sure I like that. If I call
listbox.set_selection(0), I would expect it to select the first entry,
not the eleventh.

It does sound very convenient 99.9% of the time, though; I agree.

> (imagine porting to Mac OS X's Cocoa GUI which tries to do even more
> work for you...)


Oh geez, let me guess. You can drag a listbox item out of one app, and
drop it into another, and the other app can now invoke your callback
functions for activate / change with it? :P

> Since the X11 protocol only really supports three buttons, two
> button mice generally have buttons 0 and 2, and button 1 is emulated
> by clicking both 0 and 2 together (this is controlled by the
> Emulate3Buttons option in xorg.conf).


Excellent, very good to know, thank you. You sir, are a treasure trove
of knowledge! :D

So, should I go the Windows way for the majority; or the Xlib way
since it's a bit cleaner? At least, when you consider most mice have
three buttons these days.

[No archive available]
2008-10-14 12:45:00 +00:00
byuu
18389cb8f7 Update to bsnes v036r11? release.
Another WIP.

A few changes here; I added on_change notifications to both Windows
and Linux textboxes. I use that to only enable the "Add Code" button
on the cheat code screen when a valid GG/PAR code is entered. A bit
nicer than just not doing anything when you click "Add Code". Also
disabled toggle / delete code when one is not selected. Minor touches.

Added on_input mouse capture to the canvas widget for Linux. Needed
for the input.acquire() mouse capture hook.

Tried to use SDL_WM_GrabInput and SDL_GetRelativeMouseState ...
doesn't work at all. Unless SDL creates the window itself, it doesn't
give you any mouse info. SDL_WINDOWID hack doesn't work here either,
same issue with the keyboard input and why I had to use raw Xlib
there.

So, I use XGrabPointer + XQueryPointer + XWarpPointer and some magic
to make my own invisible cursor. Major pain in the ass. It works okay,
but it feels a bit too jumpy ... I'm going to try screwing around with
the acceleration controls to see if I can smooth it out a bit.

And hooray, more fucking cross-platform headache:
Windows: button 1 = right, 2 = middle
Linux: button 1 = middle, 2 = right

I had to completely disable the scale for this build to get the mouse
to work well on Linux, so no joypad axes for this one. I'd be
interested to see how the mouse performs for FitzRoy; where the last
one was too slow, this should be 5x faster. Surprisingly still
playable for me, but a bit too fast for my tastes.

The scalar of 1 feels great for Windows with the cheapo 400dpi mouse
here, too. I think this is a reasonable default.

-----

Detecting listbox column header clicks was easy enough on Windows:

    if(((LPNMHDR)lparam)->code == LVN_COLUMNCLICK) {
      printf("%d\n", ((LPNMLISTVIEW)lparam)->iSubItem);
    }


And of course, there's no obvious way to do the same with GTK+:

http://www.gtk.org/api/2.6/gtk/GtkTreeView.html
http://www.gtk.org/api/2.6/gtk/GtkTreeViewColumn.html
http://www.gtk.org/api/2.6/gtk/TreeWidget.html

I have a couple of hangups about a column sort click, anyway.

1) there's no logical reason to sort by code (they're technically
gibberish, especially encoded Game Genie codes), status (you want the
list to change around when you toggle the status? yuck), or by reverse
description (scroll to the bottom and read up, same thing.)
2) it won't save the setting across runs; each time you load a new
game, you'll have to re-click to sort the list.
3) there'd be no way to stop sorting completely.

But again, we can make this a hidden option like deep filetype
detection if it's too obscure.

[No archive available]
2008-10-13 13:31:00 +00:00
byuu
448a8336b1 Update to bsnes v036r10? release.
Sorry, was a bit under the weather lately.

Anyway, new WIP, very little changed.

Updated nall::sort from insertion sort to merge sort* [O(n log n)],
and then used that to add a "Keep cheat code list sorted by
description" checkbox to the cheat code editor. I'll admit this
probably isn't very useful, I really just wanted an excuse to
implement a proper sorting algorithm and get rid of the embarassing
O(n^2) sorting code I had in my template library. It's actually the
first time in 11 years of programming that I've ever used a sort
function in an application, believe it or not. I'll make it an
advanced mode option if it really bothers people (eg as feature
bloat.) It was only ~12 extra lines of code.
(* not using quick sort as I need a stable sort for my purposes (eg
two descriptions that are the same, but with different codes -- it
shouldn't bounce around every time the list changes or you toggle the
sort option), and it's nice avoiding the worst-case O(n^2) issue with
quick sort.)

Updated the mouse acquired check to work, but only on mouse input. Not
that it matters much since I still don't have a method for
distinguishing between mouse and joypad movement deltas. Eg this build
only works with joypads, not mice.

Moved the endian stuff from bsnes/src/lib/bbase.h to nall/endian.hpp.
I've been trying to eliminate bbase.h for quite a while now. Getting
pretty close, just some Windows POSIX wrappers and typedefs left.

Hid a bunch of the new config file options from the advanced panel.
The idea, of course, is to hide anything that can already be
controlled from the GUI anyway.

Sigh, no way I can make an October 14th release this year. Way too
much stuff is broken.

Dullaron, no, that's not the problem at all. See the input driver
thread for more info.

FitzRoy, wow, 1800dpi. Yeah, my mouse can do that, too; but I leave it
at 1000dpi. That's odd, the work mouse is only 400dpi and its slower
there than my 1000dpi. I'd have expected 1800dpi to be way too fast
for you. I'm at a loss, maybe I'll take a look at how other emulators
handle mouse movement ...

[No archive available]
2008-10-12 10:27:00 +00:00
byuu
233e645772 Update to bsnes v036r09? release.
I fixed up the SDL and X input drivers to work with the new model, so
the Linux port builds again.

For the sake of testing, this WIP disables the "mouse acquired"
requirement, and raises the divider on motion to 5000 from 5. In other
words, this release will work with gamepad thumb sticks, but not with
mice.

Having a _lot_ of trouble coming up with a way to get both working
cleanly. But yeah, you can at least see how it works now.

You want to set the X axes to "joypad00.axis00", and Y axes to
"joypad00.axis01". Use the config file, input assignment is still
screwed.

> I can't get bsnes to recognize thumbstick 2.


DIJOYSTATE2 has lX and lY, but that's it. I guess making that an array
would be too easy. I'll have to dig through and hope one of the 20
other oddly named variables (lHX, lRX, lRLX, etc) refer to the other
analog stick.

You think that's stupid ... the scroll wheel increments in ticks of
120 per one physical tick of the mouse. Always 120, it's a fixed
constant. Using DIPROP_GRANULARITY to get it from the mouse tells you
the driver doesn't support that operation, but there's a Windows
#define called WHEEL_DELTA for it.

Seriously, what's the point of an arbitrary, fixed-value multipler for
something, anyway?

> An idea that I had that would get these things working for everyone
> and every platform, would be to create 4 mappable directions that
> could be assigned to a dpad


If we could come up with some way to map both analog bi-directional
inputs and single push button controls together, then yes we could do
something like that. I think it would be too difficult to play like
that, but whatever. The flexibility would be nice at any rate.

[No archive available]
2008-10-09 17:00:00 +00:00
byuu
f0627239bb Update to bsnes v036r08? release.
New WIP. Not really worth grabbing if you have a previous one,
progress is very slow but steady here.

First, I kept the just-in-time cycle-accurate Super Scope / Justifier
latching support; but optimized things to reduce the overhead even
more. It's now ~0.5% speed hit with no light gun, and ~1.2-1.5% with.

Next, I rewrote ruby::input and the DirectInput driver to scan at O(1)
instead of O(n). With that, I increased the max # of joypad buttons
per controller to 128 (the # doesn't affect speed anymore -- 128 is
just a hard limit with DirectInput), and gained a ~2% speedup over the
old method.

Renamed the mouse axes again, to just "mouse.x" and "mouse.y", sorry.

Added a blocker for mouse.button00, but as the new input system merges
key_down/key_up/axis into one single-pass scan, it's now mapping mouse
motions, and if not that, lousy analog joypads that return sporadic
values.

Hey, it's a WIP release for a reason, right? Getting there, my idea is
to have the input driver return information about what "type" of input
each symcode is, and then pass masks from the input configuration
mapping to control which types of input are considered valid for each
of the different types of controls.

Not sure if I want to allow the Mouse/SS/Justifier axes to be mapped
by swinging the mouse fast in a given direction (the threshold now is
any movement at all, I'd make mapping it require +100/-100 in any
direction so you have to move it fast to map it), or use a dropdown
box for that.

Oh, and I added the glow shadow I was talking about earlier to the
light gun cursors. If you do decide to try out the WIP, let me know
what you think of that.

The Linux port is pretty much 100% busted at this point. I have to
port all of the SDL / X input drivers over to the new system.

Ah, and if anyone's bored and has a five button mouse, try mapping top
thumb to left, bottom thumb to right, left click to B, right click to
Y, and middle click to start; and then play Super Mario All Stars -
Mario 1. 100% control via mouse alone = good times :D
I made it to 4-2 on my first life.

> The speed at which the mouse moves is so slow


The scale is based on my gaming optical mouse (it was the only
5-button mouse I could find without a tilt wheel; fuck those things),
so the DPI scaling I use is pretty high. I'm having trouble getting it
to move at the speed of your regular mouse universally, because I
don't know what the speed of the mouse is to interpret the mouse
movement results.

[No archive available]
2008-10-08 11:14:00 +00:00
byuu
ae67f268a8 Update to bsnes v036r07? release.
New WIP.

This adds all the aforementioned fixes. I got the speed hit to ~1%
with no light gun, and ~7% with.

All three light gun modes allow you to go offscreen by 16 pixels in
either direction, and Super Scope's offscreen flag is now supported.
Mouse still needs the speed bits supported.

I also modified the cursor just a bit by adding dots to each side of
the circle. Makes it look a lot better. Not sure if I should add a
shadow around the cursor or not. It really helps on red screens, but
it seems kind of obtrusive to the view everywhere else.

Oh, and the cursor works as expected in hires and/or interlace modes
now.

Also, x_axis, y_axis, button_NN is now mouse.x_axis, mouse.y_axis,
mouse.buttonNN. joypadNN.button_NN and joypadNN.axis_NN are now
joypadNN.buttonNN and joypadNN.axisNN. So be sure to update the config
file again. Hopefully for the last time.

I have not added the new input changes just yet, so the mouse button 0
still auto-assigns in the GUI. Use the spacebar or enter to bring up
the assignment window for now. That also means that joypad analog axes
won't work well for mouse simulation still.

Other than what I mentioned above, please let me know if you spot any
bugs this time around. Especially regarding the shots not going where
you expect them to. I didn't test Yoshi's Safari myself, but it should
be fine now.

[No archive available]
2008-10-07 10:41:00 +00:00
byuu
b2331ddb85 Update to bsnes v036r06? release.
New WIP. About 12 hours of non-stop programming ...

I've added full mouse support to nall::input, hiro and
ruby::DirectInput. With that, I added some really hacked-together
support for the mouse, super scope and justifiers. Yes, all there --
now _please_ stop bugging me about this already.

Caveats:
- Mouse support doesn't honor the speed setting.
- Super Scope doesn't currently let you go offscreen, which I should
allow by at least a few pixels to allow the offscreen flag to be set
for any games that might need it.
- Dual Justifier mode is fucked. I don't understand where PIO is
supposed to be raised, and I used a hack to get the "shoot offscreen
to reload" thing to work for the single Justifier mode for now. The
dual one tends to desync when you go offscreen and stuff, not very
pleasant.
- I'm not going to support SS / Justifiers in port 1. Since they can't
latch counters anyway, and no games make use of them, I don't see much
point in cluttering the menu more and confusing new people. Both
multitap and mouse have games that can use port 1, so they stay.
- There's no input config panel to map buttons. You have to edit the
config file directly.
- The mouse delta absolutely sucks. It's just a simple div 5, so
moving the mouse really slowly won't even register, and moving it fast
has only a linear curve. This one's going to be a real pain in the ass
to get right on everyone's system, as the ranges DirectInput gives for
mice tends to vary based on resolution, software and hardware mouse
speed settings.
- Joystick delta range is -32768 to +32767, so div 5 means it'll be
pretty much unplayable with the joystick.
- Input capture window binds mouse clicks now. This needs to be
expanded quite a lot to support selective axis and mouse assignment.
- The software-rendered cursor doesn't work right in hires / interlace
modes.
- To get the PIO latching behavior 100% correct without a dead spot
during DRAM refresh, I'd have to test the cursor coordinates every
single clock cycle. That would be way too damn slow, so I used a huge
hack instead. I just test once per scanline and fake the latch
counters to the cursor position. This is really shitty, and some
timing-sensitive code that was looking for this could easily detect
the emulator because of this, but it's either a ~10-20% speed hit, or
no speed hit at all and hacky SS / Justifier support. Since it seems
to work with all the games anyway, I'll go with the latter for now.
- No Linux support for any of this stuff yet, sorry.

If you want to try it, the config file keysyms are:
"x_axis" - mouse x axis
"y_axis" - ...
"button_00" - "button_07" - mouse buttons; hope you have the side
buttons on your mouse for the Super Scope, otherwise have fun using a
keyboard + mouse at the same time.
"joypad00.axis_00" - "joypad00.axis_03" - joypad axes (only 0,1 work
with DirectInput; 0-3 for SDL.)

Yes, I'll rename the mouse ones to "mouse.foo" in the future.

Aside from all that, not really looking for bug reports at the moment.
Way too preliminary for that.

Oh, and you have to click inside the video output to acquire the
mouse. You'll know as the mouse cursor goes away. You can release the
mouse by pressing escape on the keyboard.

If the mouse is acquired, escape overrides any GUI key assignment to
that button. You can also toggle fullscreen mode and the mouse will
stay acquired.

You can't acquire the mouse unless you have a mouse/SS/justifier
attached to a controller port, and a game loaded.

[No archive available]
2008-10-05 15:08:00 +00:00
byuu
2a2f50a8bc Update to bsnes v036r05? release.
New WIP.

I was really hesitant to even do this much, but ... biggest feature:
Image

Lots of caveats here. The biggest one being that it isn't controlled
via the mouse, as I don't have any mouse driver code written; and I
really have no idea how to bind the mouse to the bsnes window region,
nor do I really want to do that.

I also can't map it to standard on/off keys, as there's no delta
response to them. It would be uncontrollable like that. Instead, I've
mapped it to the analog axis sticks on gamepads. The further you press
the gamepad axis stick, the faster the mouse moves in said direction.
Mouse left+right can be mapped to keyboard or gamepad buttons.

I know, I know, not everyone has analog gamepads. Sorry, this is the
best I can do for now.

Does it work well? Honestly ... not so much. I can clear the first
stage of the fly swatter game in Mario Paint, but that's about it. The
only real advantage is you don't need ManyMouse to emulate two mice at
the same time. It also works pretty good in the text games, like
Tokimeki Memorial.

Also, the documentation out there for the mouse absolutely _sucks_. I
have no idea how the speed bits are supposed to work, so they aren't
emulated at all. Thus, the mouse speed settings in games do nothing.
It also fails the SNES mouse electronics test. But it is usable.

Anyway, how to use it ... run the new WIP, then edit the config file.
You have to manually set it up as there's no GUI for configuring it
yet.

Look for "input.mouse(1, 2).(x, y, l, r)". Here, you want to set x, y
to axes, eg "joypad00.axis_00", and l, r to buttons, eg
"joypad00.button_00". This only maps four axes for now, so limit the
axis range from 0-3. Buttons can be 0-15.

**Please do not bug me to improve this!** This was just a functional
demonstration. It's going to be many months before proper mouse
support is added, it may never even be added, who knows ... I have a
_ton_ of complicated problems that must be overcome before I can get
real mouse support in there. If you want to actually help with the
programming side of things, then we can certainly talk about that.

Also, **please do not bug me to add the Super Scope / Justifier
next!** I can't even do it with the gamepad trick, because these two
are supposed to trip interrupts at exact points, which is really
difficult for me to do at this time. The SS would also require a
software cursor to be drawn on-screen, another technical challenge.

[No archive available]
2008-10-02 07:28:00 +00:00
byuu
30b19613d5 Update to bsnes v036r04? release.
New WIP. Quite a bit of neat stuff this time.

First, BS-X and ST BIOS detection is in. Attempting to load them will
bring up the multi-cart loader window with the BIOS fields filled in.
So now it doesn't matter what image the user tries to load, it'll just
work.

Next, added the expansion menu per FitzRoy. You can choose between
"None" and "Satellaview BS-X". I also added a new menu there, for
region selection. There's "Auto-detect" (base off the cart type),
"NTSC" and "PAL". Admittedly not very useful, but I figure since we
aren't automatically selecting the expansion unit, we should make it
possible to manually specify the SNES type. Looks like some games work
in either region, eg the SNES Test Program - Electronics Test. That
kind of surprised me.

I was thinking it might be best to hide expansion port + region when
advanced mode is disabled, since it's something I imagine 99% of users
will never need to touch.

Also, it's set up so that you can only change the settings when the
power is off, or no cart is loaded. This is very much intentional!
It's impossible to change the SNES console without a mod-switch while
it's on, and it'd be really stupid to try hot-swapping the BS-X base
unit while it's running. You can still expand the menu to see what is
currently selected, unlike power. I figured there wasn't much point in
seeing the power-on state with no cart loaded. It's obviously off in
that case.

Speaking of which, updated hiro to support MenuGroup::disable()
properly on Windows.

Fixed the minor cosmetic Y start offset on the drivers panel.

And I cleaned up the cart loading a bit more. Still need to do a bit
more work on that, but it's looking pretty good so far.

[No archive available]
2008-09-26 10:30:00 +00:00
byuu
98fc865130 Update to bsnes v036r03? release.
New WIP.

This one adds BS-X flash cart detection (please let me know if you get
any false-positives or false-negatives), the redesigned System menu
suggested by FitzRoy sans it still saying "Load Cartridge ..." (still
open to suggestions at this point, of course), Power on/off in place
of power cycle, henke37's fix for hiding the "Read Only" checkbox on
WinXP file dialog boxes, and henke37's suggestion to add ellipses to
form buttons that open new windows. Thanks to everyone for their help
with this.

Please note that Windows isn't disabling the "Power >" group as it
should. I'll work on that tomorrow, got tired of screwing with it.
It's ignoring MF_GRAYED and MF_DISABLED on group items for some
reason. It works fine on Linux, and nothing bad will happen if you
swap power states with no cart inserted.

I won't release a new version until it's fixed properly, or until I
find out I can't fix it properly (hopefully the former), of course.

I'm also open to suggestions for improving the layout of the advanced
mode audio panel. Note that it needs to be text boxes to enter values.
Spinboxes aren't going to work there.

[No archive available]
2008-09-25 03:13:00 +00:00
byuu
f6a04682f5 Update to bsnes v036r02? release.
Finally got belegdol's Polish locale up. Thank you again for that!

New WIP. The main thing is that all of the "Load N Cartridge ..."
options have been merged into one. Here's how it works:

- Load a normal cart, and the game starts right away.
- Load a BS-X slotted cart, and you get a window with the slotted cart
set to base, and the slot section empty. You can use Same Game + SG-
FEoEZ or whatever to test.
- Load a Sufami Turbo cart, and you get a window with the BIOS set to
whatever was used last (blank for the first time), the ST cart
assigned to slot A, and slot B blank. The ST won't actually play any
games with a cart only in slot B ... but it does display a unique
error message if you try. You can always clear slot A and then assign
again to slot B if you want.

Another benefit is this works with command-line loading, too. Before,
it was impossible to load BS-X / ST games from the console / bsnes
executable association. There is a bit of a lag in startup, as always,
so that's a bit noticeable.

Right now, I'm missing the algorithm for BS-X flash cart detection ...
Nach, I don't suppose you'd mind posting that for me, please?

Further, in the future I'd like to also detect the BS-X and ST BIOS
files, and assign those and show windows with all slots empty.

FitzRoy, if you want to mess around with the System menu layout again,
that's cool. Just keep in mind that "Power Cycle" is still there in
advanced mode. It looks tacky with load+unload+reset+powercycle with
no separator.

Unload cart does appear to have limited use, so if necessary, we can
consider removing that, I suppose :/

[No archive available]
2008-09-23 10:11:00 +00:00
byuu
87b91f0ace Update to bsnes v036r01? release.
Posted a new WIP.

The biggest change was that I rewrote nearly all of the cheat code
system, so heavy testing on that would be appreciated.

Someone was mentioning over at Snes9X that it was limited to 300
cheats or something, so someone bumped it to 3,000. Not to be outdone
(v036 is limited to 1,024), I vectorized the cheat table, meaning you
can have infinite cheats now (limited only to available memory.)
Actually cleans up the code quite a bit, too. Removed all the ugly
strlcpy() stuff, the limitations on description text length, etc.

Looks like I had a bug with deleting codes, too. I wasn't copying the
actual cheat codes. That would corrupt the descriptions on every code
after the one you deleted, I think. Strange nobody caught that.

I also cleaned up the OBC-1 code, and added a "Fullscreen" checkbox
after "Correct Aspect Ratio". Sorry for the delay with that, FitzRoy.
Hopefully the checkbox is good enough for now, as I can't change the
text to "Switch to ..." just yet.

[No archive available]
2008-09-16 15:28:00 +00:00
byuu
0114e10ede Update to bsnes v036 release.
This release fixes a somewhat serious bug introduced in v035, and also vastly improves Windows support for non-ANSI filenames.
The bug was triggered when HDMA would occur during DMA. If the DMA were long enough, subsequent HDMA transfers would be blocked. This caused graphical glitches in Star Ocean, Super Mario Kart, and possible more games. If you noticed any regressions from v034 to v035, this was almost certainly the cause. Once again, we're operating under the assumption that there are no known bugs currently, so please let us know here if you find any.
I've also rewritten the file handling for the emulator. On Windows, attempting to load a file with non-ANSI characters (eg Russian, Japanese, etc) would cause these characters to be removed. This meant that no version of bsnes thus far could load these files. This problem was exacerbated when I ported the user interface to Unicode (UTF-16), this caused even config and locale file loading to crash the emulator.
The root of the problem is that Windows only accepts non-ANSI strings in UTF-16 format, whereas bsnes' UI wrapper converts strings to UTF-8 interally. When passing these file names to the standard file functions (fopen(), std::ifstream, etc), file loading would fail. To fix this, I replaced all file access functions with a new version that would convert the UTF-8 filenames back to UTF-16, and use appropriate access functions (_wfopen(), _wmkdir(), etc.)
... but there is still one limitation to this: ZIP and GZ support use zlib, and JMA support uses libjma. Neither of these libraries convert UTF-8 strings to UTF-16 before attempting to open files. Due to licensing issues, as well as technical issues, I am unable to correct this at this time. What this means is that loading ZIP, GZ and JMA files; on Windows only; and with Unicode characters in the file name only; will cause the image load to fail. Loading uncompressed images (SMC, SFC, etc) will work with or without Unicode on all platforms.
I tried to be as thorough as possible with this fix: command-line arguments (via CommandLineToArvW + GetCommandLineW), user path (via SHGetFolderPathW), real path (via _wfullpath),folder creation (via _wmkdir) and file access/existence checks (via _wfopen) were updated in all cases. I also updated file loading for ROMs (SMC, SFC, etc), save RAM (SRM), real-time clock save (RTC), cheat files (CHT), UPS patches (UPS) and both configuration files (bsnes.cfg and locale.cfg.) Configuration file loading should work even if your username contains non-ANSI characters, and it should also detect config files put in the same folder as the bsnes executable, even if the path to the executable contains non-ANSI characters.
Still, if you spot any bugs, aside from the ZIP/GZ/JMA loading issue, please let me know via e-mail at setsunakun0; at hotmail.
Lastly, I'd like to apologize for the poor support for non-ANSI filenames in the past. Using an English version of Windows didn't expose the problems to me. I'll be more thorough in the future with this.
2008-09-15 05:29:14 +00:00
byuu
8c591ce44a Update to bsnes v035 release.
Changelog:
    - Added video synchronization support at long last [blargg, byuu].
    - Added audio panel to control volume, latency, frequency and SNES input frequency settings.
    - Added driver panel to select APIs to use for video, audio and input.
    - Added crash handler for driver initialization.
    - Xv and SDL video drivers now work with compositing enabled on Linux/Xorg.
    - Improved ALSA audio driver for Linux.
    - Now using a fixed output frequency, along with a 4-tap hermite resampler.
    - Improved header detection; fixes Batman: Revenge of The Joker and a few fan translations.
    - Frameskip will now randomly choose a frame in each set to display; helps with animations.
    - Locales now support meta-data, which allows for unique translations of the same English input.
2008-08-22 22:28:00 +00:00
byuu
e2cc164f70 Update to bsnes v034r06 release.
This will probably be the last public WIP, so get it now if you want
it.

    http://byuu.cinnamonpirate.com/temp/bsnes_v034_wip06.zip


I used the same "create a child window inside the output window" trick
for Xv that I used for OpenGL, so Xv will now work even with a
compositor enabled.

I also added Video::Synchronize support to OpenGL for Windows. My card
seems to force it on regardless of my driver settings, but maybe
you'll have better luck. That driver had the same issue with
allocating 16MB of memory instead of 4MB (that was due to copy and
pasting of code), so that's fixed too.

This version lowers the CPU<>SMP drifting by an order of magnitude.
You shouldn't notice the speed hit. I can't really get any lower
latency with that, though.

I also restricted the latency range to 25 - 175, with the default
being in the center, 100ms. Quite conservative, given the average we
see is 70-80ms. But you won't notice the difference, and this way we
ensure no popping even in exceptional circumstances by default. 25ms
is doable without video sync and with OSS4+cooked mode, but I
seriously doubt any Windows user will get lower without something
crazy going on with the sound card drivers.

Lastly, I've replaced the 2-tap linear resampler with a 4-tap hermite
resampler. You won't be able to tell the difference, but it's quite
pronounced if you use a waveform analyzer on much higher output
frequencies:

Linear:
Image

Hermite:
Image

Hermite is essentially better than cubic (for which cubic spline is an
optimized version of), as it is better at not going too far away from
the points, so you get a bit less clamping in the extreme cases. But
the difference isn't audible to humans anyway. It's still clearly
inferior to band-limited interpolation, as it will still have
noticeable aliasing of things like square waves and such, but it's
orders of magnitude less complex to implement.

Keep in mind that nobody could tell the difference even with linear
interpolation from the last few WIPs.

----------

Aside from that, I'm pretty much ready to release a new version. If
anyone has any show stoppers, _now_ is the time to say something.
Otherwise I'll probably post something tomorrow or Friday.
2008-08-20 20:36:54 +00:00
byuu
d09e54149b Update to bsnes v034r05 release.
http://byuu.org/temp/bsnes_v034_wip05.zip


OpenGL/Linux now destroys the window and colormap it creates, and it
also avoids allocating 16MB of memory when only 4MB are actually
needed. Forgot to remove the * sizeof(uint32_t) from the buffer
allocation after changing it from malloc to new. I use 4MB because the
internal buffer size is 1024x1024@32bpp. I make it larger than needed
to support both present and future filter requirements (eg HQ4x would
need 1024x960 minimum.)

The X-Video driver will now look for XV_SYNC_TO_VBLANK and add the
video synchronize option when it exists. Unfortunately, that doesn't
stop the binary nvidia driver from ignoring the setting anyway, but it
should be nice for those using the nv driver or somesuch, especially
as it lacks OpenGL support.

For whatever reason, I was able to get my latency in DirectSound down
to 70ms. Not sure if it's related to these changes or not, but I won't
complain. I also needed to set 32150hz / -50 for the input frequency
adjustment. Probably just differences between the monitor timings on
Windows and Linux.

That said, let's get some averages. With the new WIP, be sure to reset
all of your audio and driver settings. It may even default to no
driver at all if you were using a custom one before.

From there, please post the video driver, audio driver, latency and
SNES input adjustment values that work best for you.

> BTW, were you able to look into that status bar bug?


Thanks for pointing that out. The status bar properly restored its
state, but the menu bar did not. Rather than save the menubar state (I
wanted to avoid that for people who accidentally hide the menubar and
then close the app, and don't remember how to re-enable it), I just
made it not save the status bar state at all. Apologies to those who
hate the status bar, you'll have to turn it off more frequently now.
Direct your pitchforks at FirebrandX :P

[No archive available]
2008-08-19 13:55:00 +00:00
byuu
8e4f1be189 Update to bsnes v034r04 release.
14 hours of straight programming brings you this:
    http://byuu.cinnamonpirate.com/temp/bsnes_v034_wip04.zip


Windows binary and source included, binary does not have ZIP+JMA
support enabled, as it's a WIP release.

Yes, vsync works both on Windows and Linux. In fact, it actually seems
to work better on Linux, in that it requires lower audio latencies and
has no troubles at full 5x scale on my 1920x1200 monitor.

Overview of new features:

Most importantly, I've added a new menu group to the settings menu
group, "Synchronize", containing "Synchronize Video" and "Synchronize
Audio" checkboxes. You can have neither, one or both checked. Up to
you. That made the "Uncapped" speed setting redundant, so that was
removed.

Next, there's a new audio configuration panel with lots of new
goodies.

Volume lets you scale audio from 10% to 200%. Note that going over
100% will obviously cause aliasing. It's a much better idea to turn up
your speakers first. But who knows, it could come in handy. On one
machine with OSS4, I couldn't adjust volume in Audacious, and it
always bothered me that it was so much louder than bsnes, so I saw no
reason to cap the volume to 100% here.

Latency lets you control the number of milliseconds between adding
data to the sound buffer and it being played. Note that this is _not_
the absolute latency. Any sound servers and resamplers will obviously
add to this. It increments in steps of 5ms, because I don't want
people wasting their time trying to get it absolutely perfect. 5ms is
a small enough increment that no human being will notice. I also have
to re-create all the buffers and/or device itself when that changes,
so I want to keep it from changing too frequently. Not that there's a
memory / resource leak, but just in case.

PC output frequency let's you control the master frequency for the
sound card output. You can set this to 22050hz (not a good idea, loses
precision, there as a last resort), 32000hz (for purists), 44100hz
(for most cards), 48000hz (for higher end cards -- set as default
because it's a nicer multiple of 32000 than 44100 is) and, yes,
96000hz. And I'm sure all the audiophiles will remark how much better
it sounds, right?

Believe it or not, there's actually some value to higher frequencies
for the vsync. Higher rates lower the rounding errors with
interpolation and such, so you can use lower SNES input rates. And
speaking of which ...

SNES input frequency is what the base SNES input is skewed to. The
basic idea is that you want to get the value as low as possible
without sound crackling. The lower it is, the less video frames
duplicated, the less jerkiness of the video. The higher it is, the
less likely an audio breakup is.

Once again, Linux seems to come out on top here. Because of it's non-
ring buffer approach to audio, both ALSA and OpenAL can insert blank
samples in a way that DirectSound simply cannot. Whatever it does to
BS underflows, it works really well, because you can barely even
notice it.

The default is a tad on the dangerous side. If anything, you may need
to increase it.

Get the right values for everything, and you can easily play games and
never notice any video tearing or audio crackling whatsoever.

Lastly, I removed the "Show Statusbar" option from the misc menu, per
FitzRoy.

Oh, also note that with Linux (both for OpenGL and Xv) and Win/OpenGL,
you have to toggle the vsync enable in your video driver's control
panel. Pain in the ass, that. Linux/SDL and Win/GDI do not vsync. No,
I'm not even going to bother trying to add that to them.

My settings:

Hardware:
nVidia 8800 GTS 320, Intel HDA audio, 24" LG @ 1920x1200x24bpp@60hz

Windows:
Direct3D, DirectSound, Latency = 120ms, PC freq = 48000hz, SNES freq =
32050hz; 4x scale always works, 5x scale misses vblank every few
seconds

Linux:
OpenGL, ALSA, Latency = 60ms, PC freq = 48000hz, SNES freq = 32050hz;
4x and 5x scale always works

I'd be interested in hearing what works best for you guys. I'm
especially interested in how PAL works on a monitor running at 50hz. I
don't have any that can handle that resolution, nor 100hz. I don't
expect scrolling to look great at 100/120hz, as I have no special
handling for it.

> Even if it is wondows-only, you may want to add the option of using
> a short sleep in the advanced options panel.


No, I really can't :P
I tried just to see what would happen, calling Sleep(1) a single time
is enough to jump over the entire vblank period. In the worst case
scenario, you get stuck in a loop, never hitting vblank, and the
framerate drops to 1fps. Trust me, you don't want a sleep in there.

Now, I know you're thinking, "why not let the video card do the sync
for you?" -- well, one, some drivers still eat up all the CPU time in
their loops, and two, by polling the vblank status repeatedly, I
actually get better results with 5x scale in D3D on my system. And I
don't have to destroy the video device to toggle the video sync
enable.

[No archive available]
2008-08-17 20:22:00 +00:00
byuu
f529a84fd1 Update to bsnes v034r03v release.
For Windows / Direct3D / DirectSound _only_.

    http://byuu.cinnamonpirate.com/temp/bsnes_v034_wip03v.zip


Leave it at 100% speed, play NTSC games, leave frameskip off. I don't
care if any of that is broken or not right now.

There are two special variables this time: system.vsync_magic and
system.latency_magic.

The former is the skew for the resampler, you create that many samples
per 32000 samples of output. The latter is the latency in samples. It
will tell you how much total latency you'll end up getting when you
start the emulator.

Note that the system requirements are much greater with the CPU<>SMP
desync trick disabled. It's something like 10-20% slower. So leave off
the filters, please.

If vsync_magic is too low / high, it will tell you on the terminal by
printing an underflow warning. If latency_magic is too low, you'll
hear crackling.

The bad news: no matter what values I plug in, I still get crackling.
I can get it to be pretty rare, but I'm completely unable to get
smooth audio. Maybe you'll have better luck, who knows.

For me at least, the vsync_magic value that sounds best keeps varying
every few minutes between 32100 and 32250. The latency is through the
fucking roof. I've got it over 120ms and it's still not enough to
prevent occasional audio crackling. It's already much too high to be
practical for a release.

Note that without vsync, it only needed to be 60ms, and that was a
conservative number. We could get it down to 20-40ms with the right
hardware.

[No archive available]
2008-08-15 13:27:00 +00:00
byuu
567d415290 Update to bsnes v034r03 release.
New WIP, with _major_ changes to internal header detection.

This should get everything working, if we're lucky. It does get
Batman: RotJ working for the first time, as well as all the fan
translations.

I'm releasing it publicly, as I need all the help I can get with this
one. Windows binary with ZIP+JMA support included along with source
for the penguins.

    byuu.org/temp/bsnes_v034_wip03.zip


Do note that I left the console enabled in the binary. It's not a
release-grade version, anyway. But the main reason was to print the
scoring information. If any games fail, I'd like that information
posted. Might be good to note really close passes, as well, so we can
keep an eye on them for future changes. Right now, I'm only aware of
SFA2 that gets really really close.

Basically, it prints the address it tests for a header at, the score
it ended up getting, and the reset vector's first opcode. If the
values are equal, it defaults to LoROM, then HiROM, then ExHiROM. If
the reset vector is invalid, or the ROM is too small to contain a
header at a certain offset, you won't see any output for that line!
That means a lot of times, you'll only see one line output, and
sometimes you'll see two or three. No worries, just assume missing
means total fail. It only prints output for "possible" header
locations.

If you do test, you don't have to play in-game or anything. The second
you see any visible output whatsoever, that's good enough.

Many thanks to everyone who tests in advance :D

----------

Hunter and tukuyomi, thank you for the kind words and localizations :)

I really hate that table on the download page, and I need to go
through and get names out of all of the locales, but I'd like to get
an "Author:" field in that table on the download page. Sorry it's not
there just yet.

----------

Fes, thanks for the feedback.

> Apparently it has a limit of 65535 bytes for string literals.


I don't have a workaround for that. For whatever reason, ISO didn't
add an "incbin"-style command, and I need a platform-agnostic way of
encoding binary data.

Not for v035, but maybe a while after that, I'll use a more advanced
compressor to get the controller below 64kb of string data. Maybe I
can rig my order-0 arithmetic coder onto the end of LZSS for a quick
and dirty size cut. The reason I don't use 0xnn, 0xnn, is because that
takes 5 bytes of source to encode one byte of input, whereas base-64
strings only take ~1.25 bytes. I didn't want those files to slow down
compilation much.

> # Next, in dictionary.hpp, the first for loop uses 'i' as its
> counter, then declares 'i' again inside the loop body for additional
> work.


Oops, sorry. Didn't get a warning on GCC, so I overlooked it. This is
now fixed.

> # Cartridge::get_base_filename and Cartridge::apply_patch both claim
> to return a value, but don't seem to do so.


First should return the filename, it's just a convenience thing to
allow chaining commands. The second should return result of patching.
I've fixed both now, thanks.

> # spc_dsp.h, nal/file.hpp, and ups.hpp all attempted to include
> stdint.h, which isn't part of vc++. Are those files perhaps meant to
> include nall/stdint.h instead of the standard one?


Microsoft really pisses me off by intentionally ignoring stdint.h.
nall/stdint.hpp was meant as a workaround, so that I didn't have to
special case Visual C++. The idea was to not require you to get one of
those third-party add-ons.

So yes, two of those were a mistake on my part, I used stdint.h on
them before I created my own stdint wrapper. I've corrected both.

As for spc_dsp.h, that shouldn't be compiled. That is for blargg's
reference, unmodified S-DSP emulator. The ones modified to work in
bsnes do not require it. And in fact, only src/dsp/sdsp will compile
at the moment due to memory map changes.

> # pEditbox::get_text seems to declare a dynamically sized stack
> array, which CL balked at.


Hahah, yeah, that would be C99 syntax. Very nice, that.

Looks like I was allocating length*2 wchars, too. I don't know why I
was doing that ... I don't think Microsoft's system even supports the
extended Unicode symbols that need more than 16-bits, and even if so,
they aren't likely to appear in the emulator.

Dropped that back to length+1, and made it use new[]/delete[],
instead. That's one horribly inefficient routine by the way, but
whatever, it works for now.

The rest I can't do much about, sorry. Hopefully it'll make it easier
for you to compile in the future. Sorry for letting the port slip, I
just don't have the patience to load VS2k5 again. Software takes like
three hours to install >_< and creates slower code than GCC4 anyway.
If they'd fix their damn PGO support, I'd be all over it again,
though.
2008-08-13 21:09:15 +00:00
byuu
435a194ccd Update to bsnes v034r02 release.
New WIP.

First, the internal ROM header detected was enhanced. Nach was right,
so I went ahead and did it the right way ... it'll score all three
regions individually now, and then use some heuristics for those
annoying games that duplicate the header entirely in multiple places.
The hardest games to detect, that I recall, are Double Dragon and
Street Fighter Alpha 2, which seem okay. In fact, all ~50 of the games
I have seem to be working fine.
Please let me know if any games fail to start as of this WIP.

Second, finished updating all of src/memory to convert uint ->
unsigned. Yeah, I like the former more, but the latter is a built-in
type. Did the same to hiro, and converted Event to event_t, looks
nicer in code. Part of namespace libhiro, so no worries about other
things named event_t.

Third, added the frameskip cycling code. It just randomly chooses
which of the set of frames to display (random() % (frameskip + 1)).
Seems to work as expected, you can see Link blink when hit even with
FS=1, but obviously it stutters a bit more.

Fourth, I finally added RedDwarf and Nach's latest ALSA code. ALSA
will now with at 75% speed and with speed uncapped. It has the same
overhead as OpenAL. So, unfortunately, due to OpenAL's issues with
completely destroying echo / reverb for some reason, I'm going to have
to recommend Linux users set system.audio to "alsa" from now on :/
FreeBSD users should rely on "libao".

I'd like to release an update this weekend to address the ToP issue,
as well as a missing string in the translate[] hooks and to distribute
the new ALSA updates. I'm worried about the header detection changes
breaking some other games, though. So if you guys wouldn't mind
throwing a bunch of random games at it, I'd appreciate it.

It _should_ be fine, though. In theory, the LoROM / HiROM detection is
identical to the last release still, but I did restructure it, so you
never know ...

Oh, and I updated the website with new locales from Hatsuyuki, Itol,
khiav and wushu. Thanks, guys!

[No archive available]
2008-08-12 09:53:00 +00:00
byuu
df9de289b9 Update to bsnes v034r01 release.
New WIP (yes, already.)
Nothing that affects emulation, just a bunch of core changes I didn't
want to make last-minute before the release.

All of the APURAM / VRAM / OAM / CGRAM memory blocks have been moved
to the Memory class, and I've added operator[] bindings and such so
that I don't have to add .read(), .write() around everything. Required
several dozen individual changes, and I was afraid of introducing a
new bug. Everything looks good so far, anyway.

I also missed the translate[] call around "Paused", so it's not
possible to localize that in the new version. Oops.

> edit and thanks to Jonas Quinn for the $4810 register/Super Power
> League 4 fix.


Definitely, I wasn't going to release a new version this week because
of that bug.

Speaking of which, I just tried SPL4 on the Windows port. Holy hell,
that completely changed my opinion of OpenAL.

Seriously, those on Linux ... compare that game with OpenAL and ALSA.
With DirectSound / ALSA, the game actually has echo / reverb. It's
_completely_ missing with OpenAL. The woman announcer sounds like
she's speaking over a megaphone, but OpenAL makes her sound like she's
two feet away from you. Wild stuff.

And SDL video is going crazy on me now, it seems to be setting each
pixel's alpha value to some sort of inverse of chroma. Eg you can see
the background through the emulator window, and it's completely
transparent on full white / black screens. Really trippy looking.
Definitely be sure to set system.video to "glx" or "xv" if you use the
Linux port.

[No archive available]
2008-08-11 07:24:00 +00:00
byuu
dd83559786 Update to bsnes v034 release.
For this release: SPC7110 emulation speed has been greatly optimized, massive improvements to HDMA timing have been implemented, Multitap support was added, and the user interface was polished a bit more.
Changelog:
    - SPC7110 decompression code updated to latest version by neviksti and converted to a state machine; SPC7110 overhead is now identical to S-DD1 overhead (eg ~5% speed hit over standard games)
    - Fixed a major bug in SPC7110 data port emulation that was crashing Super Power League 4 [Jonas Quinn]
    - HDMA trigger point corrected to H=1104, bus sync timing corrected
    - All illegal DMA A-bus accesses should now be properly blocked
    - DMA state machine rewritten, greatly simplified
    - Major corrections to HDMA run timing; fixes flickering bugs in Mecarobot Golf and Super Mario Kart
    - Emulator now defaults to 2/1/3 SNES (CPU/PPU1/PPU2 revision numbers)
    - Multitap emulation added, can be attached to either or both controller ports; user interface updated to reflect this
    - Status messages (cartridge loaded / unloaded, UPS patch applied, etc) now appear in status bar
    - Added advanced configuration option, "input.analog_axis_resistance", to control gamepad analog stick sensitivity
Also, the SPC7110 emulator download link below was removed: if you are looking for this, please download the bsnes v034 source code, which has the most up-to-date version in the src/chip/spc7110 folder.
2008-08-11 11:33:54 +00:00
byuu
100ef3a271 Update to bsnes v033r09? release.
New WIP, probably not worth downloading.

For the sake of completeness, I finished optimizing the SPC7110 code.
I've converted the pixel buffer rotation from swaps to moves, which
should double the speed of the slowest part. I've also added reverse
morton lookup tables (2x8-bit and 4x-8-bit deinterleaving), which are
8-10x faster than doing it using pure bit logic, I removed the
redundant comparisons from the pixel context lookup (though a compiler
would've done the same anyway), and lastly I've cut the mode2 context
table in half, since the refcon add bit was only set on context 1
anyway. I could've replaced the other half with 5-6 if/else
statements, but I didn't see much of a point in that since it'd only
make the code harder to understand.

That results in a 1-2fps speedup, at best. Really, the code is simply
not a bottleneck. It's pointless to optimize anymore, as any changes
from this point on will just make it harder to understand what's
happening. I only added the morton tables because it does seem to aid
readability.

Also added translate[] wraps around all the new status messages, and
moved the two checkbox options on the paths window to the advanced
options list. No sense cluttering up the UI with near-useless
settings.

> It's hard going back to "Are you sure you'd like to exit?", no
> multiplier eyeball stretching, etc.


Heh, yeah. I never understood the floating point multiplier setups in
some emulators. I guess it's useful if you want your video output size
to be π x _e_.

I thought about the "Are you sure?" thing, it'd be nice if you
accidentally close the emulator, so you don't lose your save. But I
quickly realized that despite using emulators for ten years, I've
never _once_ actually done that. The only point where it might be
appropriate is if I add mouse / SS support, since you may want to have
the cursor near the top right of the window with the menubar off in
windowed mode (though you're just asking for trouble at that point,
honestly.)

To be fair though, you helped design at least half the bsnes GUI, so
obviously you should like it :P

> I should offer a bounty at this point to anyone who can find another
> bug that isn't PPU based.


Super Power League 4 seems to die after an inning or two with a S-SMP
crash. I still need to try screwing with the CPU/SMP scalars and try
substituting with anomie's DSP core to see if it still dies. If
neither of those affect it, it could very well be due to a timing
issue with not emulating the delays of the SPC7110 chip or something.
If someone wants to rule out the DSP core, they could try playing a
SPC dump from the game in one of the plugins that use blargg's core. I
doubt it's that, personally.

The usual rules about special chips apply, but you can list it as a
bug if you like. I probably will with a note. Maybe I can figure it
out before release. Probably not, but who knows.

Sigh, it's always the god damn baseball and golf games, isn't it? I'd
probably half-ass the game too, if it were my job to work on one.

> Two minor things that have probably been forgotten in all this
> excitement that could make the next release: libui is still not
> changed to "hiro" in the license, both online and text based. And
> mudlord wanted to be added to the contributors for his OpenGL stuff.


Ah, thanks. Updated the license file. Decided against listing all the
libraries there for now, as they're getting quite numerous.

As for credits, mudlord is already listed in the source file, and the
contributors list is for people who have submitted code to the core of
the emulator. It's not a good system, I admit. That obviously excludes
you and tetsuo55, despite the fact that your testing has been one of
the most helpful things I've received.

It's not that I mind listing people, but I don't want that window to
become cluttered with 100+ names of everyone up to and including
people pointing out spelling mistakes in WIPs. That would make the
window really onerous to look at.
I really don't want to come off as rude here, I'm really truly
grateful to everyone who has helped out even a little, and I'm happy
to thank them all in some perpetual fashion (eg website thank yous
tend to disappear as the news falls off the page.)

That's the second time someone's brought that list up. I was afraid
that adding such a list would just end up causing problems. Maybe I
should just remove the contributors list on the about screen, and put
everyone in the readme.txt file, so that everyone who ever contributed
anything is listed?

[No archive available]
2008-08-08 14:22:00 +00:00
byuu
bccc5b5a12 Update to bsnes v033r08? release.
I wish I could post the new WIP, I really need it tested. But it looks
like vstech.net (cinnamonpirate.com's host) got sucked into a black
hole, literally. You can't even nslookup it. So ... sorry.

What I did today was:
- remove an unnecessary ternary condition in HDMA CPUsync (no visible
effect on emulation or speed.)
- move controller ports from settings to system.
- rewrite SPC7110 decompression engine from scratch.

The last one obviously the most important. I took neviksti's most
recent decompressor code, made the essential variables static, added a
bool init parameter you can use to start a new decompression sequence,
and built up a dual-indexed (read+write cursor) ring buffer to stream
byte sequences. I set the buffer to >= 32 bytes at a time. I also
simplified a few parts, like the swap sequence for pixel ordering; and
I took out the end of each function that computes length, since that's
no longer needed (nor is bot.)

The result is you can stream an infinite number of bytes safely from
decompression, and nothing will ever go out of bounds of the data ROM.

Speed results on Core 2 Duo E6600 @ stock 2.4GHz:
FEoEZ cart riding sequence - 91fps (was 40fps)
MDH title screen - 111fps (was 29fps)
SPL4 title screen with players running across screen - 118fps (was
35fps)

For comparison, Star Ocean in-game gets ~95fps.

I didn't think we would need that many optimizations to get SPC7110
support running at full speed (how complex could a low-cost IC from
1995 be?), good to see I was right.

As soon as vstech comes back (hopefully tomorrow), I'll post the PD /
BSDL source, and get it sent over to GIGO. Hopefully he can add it to
SNESGT.

Speaking of which ... neviksti:
In your updated DecompMode0.c file, you declare NUM_CONTEXTS as 15,
but it should be 30. I'm guessing it runs fine in isolation (memory
initializes to zero and all that), but when mode 2 ran and set
contexts up to 32; only clearing 15 was resulting in corrupted
graphics all over. No big deal, just mentioning it.

> I don't really understand your (or byuu's) point. If the game does
> indeed works on 99.9% of units...on what do you base yourself to say
> their programming suck or that the game is "broken"? I mean, it
> works, it works right?


This is the problem I have with the black-and-white "bug" label ... it
implies a game is broken to a casual observer, or there is at least
noticeable corruption on at least one screen.

In truth, bsnes has a few visible bugs. Street Racer will flicker one
frame on the title screen, but only one time, and only once every ~4-8
runs. Adventures of Dr Franken and Winter Olympics show one black
scanline because the games update OBSEL at very unusual points mid-
frame.

And there are countless "anti-bugs", eg Battle Blaze on the fighter
select screen is supposed to show some garble up at the top due to
mid-scanline PPU writes. Because bsnes renders an entire scanline at
once, you don't see this. Lots and lots of games will have 1-16 pixels
on one scanline at the left (usually not even visible on TVs) that
flicker due to writing PPU regs past the end of hblank.

BoF2 German detects emulators by reading the division register early.
Since no emulator supports that, you don't see the anti-piracy splash
screen.

All of those could be considered bugs to varying degrees.

I suppose what would be nice is a bug severity ranking system.
"Severe" if it's game ruining, "Moderate" if it's more than one
scanline / frame that glitches graphics or something, and "Minor" for
the stuff 95% of people probably won't even notice. Or something like
that. My point is that it doesn't make a lot of sense to work on the
minor stuff. Most of that will probably go away with a cycle-based PPU
anyway, and the rest will probably continually appear and disappear
with infinitesimal timing changes.

[No archive available]
2008-08-07 13:39:00 +00:00
byuu
acee547da9 Update to bsnes v033r07? release.
And another one.

I've re-written the DMA state machine. I decided to keep it in one FSM
instead of two separate ones, because they honestly share so much. But
I rewrote it to be a lot cleaner, and to handle some really
exceptional edge cases. Due to the design, I was even able to make the
HDMA during DMA edge case "transparent", eg the same codepath is used
for normal HDMA and for HDMA during DMA :D

New WIP passes the last four tests in test_hdmatiming.smc. The ROM
posted doesn't validate the last four yet, so you have to compare the
SRAM file to the source logged values if you care to.

That should be everything with DMA and HDMA timing now, thankfully.
Really happy with that codepath for the very first time. Such an
improvement from the "don't even worry about HDMA syncing" code I had
a few versions ago.

I also reduced the DRAM refresh rotation from 7-lines of code testing
against the NTSC color burst case to 1-line, using the DMA counter
(dram_refresh_pos = 530 + 8 - dma_counter())

Lastly, I added a flush command to the status bar. Any important
messages will now flush all buffered ones to display the new one. Eg
load 10 games back-to-back and it'll say the name of the new game
immediately, instead of scrolling through the other 9. It will still
buffer lesser important ones, like unsupported chip and UPS patch
applied messages. I also removed config / locale path display, because
it annoyed me.

Nearing a release. I want to state machine neviksti's SPC7110
decompression code, and I should be ready on my end.

FitzRoy, I'll give you the final word. If you want controller port
selection moved to "System", I'll do so.

Any show stoppers should be mentioned now. I can't fix the "crash with
Unicode characters in the executable path" issue just yet, so that'll
have to wait.

[No archive available]
2008-08-05 11:58:00 +00:00
byuu
b1b146fd7d Update to bsnes v033r06? release.
New WIP. Adds some more HDMA timing improvements, DMA bus hold
simulation, and hopefully proper detection for ST011, which should
mean that every unsupported game will now notify you of that fact.

Also, I finally got around to writing that status bar message queue
system I mentioned a long time ago. Should make Deathlike happy. It'll
tell you whenever any UI event occurs (load, unload, reset, power
cycle, UPS patch applied, unsupported chip detected, config file /
locale file load, etc.)
Obviously if you turn off the status bar, you won't see them. Not a
problem for me personally: if you want to see status messages, leave
it on.

With that, I removed the annoyingly bland message window, and muted
the terminal message printing, putting it all inside the statusbar
instead.

I also got rid of some now-unused config variables, misc.status_text
(it was kind of overkill to let that be customizable) and
cpu.hdma_enable (it's always enabled now.)

Opinions on the new status bar system welcome.

I've also set the SNES to report itself as 2/1/3, rather than 1/1/1.
Since I don't emulate things like the HDMA conflict crash, I figured I
may as well set it to the CPU revision that doesn't have it.

> Probably the best it's ever been, but Street Racer's track does
> still flicker on "Head to Head" mode.


With the above changes, I was able to eliminate the flicker in-game in
all modes, as well as get rid of it ~80+% of the time on the title
screen. Only once every ~5 restarts will you see it for _maybe_ one
frame.

That's really the best I can do, I'm afraid. It's so subtle I doubt
anyone will even notice it now. Like Winter Olympics and Adventures of
Dr Franken, I'm not going to consider it an active bug (yes, how
convenient), but I'll watch the game closely with future timing
changes. Hopefully it'll go away entirely with more refinements in the
future.

[No archive available]
2008-08-04 06:35:00 +00:00
byuu
53e913e225 Update to bsnes v033r05? release.
New WIP.

After some more hardware testing, it seems my theory from before was
correct. See the HDMA thread for more info if you care.

With those changes plus a few others, I'm now able to get everything
in my "known troublesome" games list to work properly and with no
flickering:
- Breath of Fire 2 (G)
- Earthworm Jim 2 (U+E)
- Energy Breaker
- Jumbo Osaki no Hole in One
- Mecarobot Golf
- Secret of Mana
- Street Racer
- Super Mario Kart

I still can't get Street Racer to flicker, maybe you guys can?
Hopefully not, such a hard-to-trigger bug will be even harder to
debug.

Image
(ignore the framerate, from a pause/resume screen capture.)

And fucking _hell_ that game is hard.

Note that to get BoF2 (G) to work, I had to modify S-SMP cycle timing
from 32040hz*768 to 32041hz*768. It seems the game is very sensitive
to S-CPU <> S-SMP timing, and the improved HDMA timing was just
unlucky enough to just _barely_ miss the handshake. This was further
compounded by there being no input before the point in question to
vary timing.

It's not really a problem with the game itself -- d4s really pushed
the limits of these two chips to pull off that impressive intro. It
was more that I was hitting an extremely tiny window of time that
caused a deadlock.

This timing change only affects S-CPU <> S-SMP communications (eg
handshakes and such), and not timing inside each individual processor.
Recall that both processors in both regions (NTSC and PAL) have
slightly different timings, and the exact timings vary even on real
hardware, as the crystal clocks used are not perfect.

The NTSC S-SMP has been observed at ~32040hz on an oscilloscope by the
guy at alpha-ii.com, which is faster than the stock speed of ~32000hz.
But we still use stock speeds for the S-CPU because that's all we
have. Changing the S-CPU speed a bit would've fixed this as well.

So yeah, the fix is a bit of a kludge, but it's the best I can do when
the problem is in communication between the two chips.

Keep in mind that the S-SMP clock rates are cached in the config file.
You'll either need to delete it, or reset the values to the default in
the advanced panel. Otherwise the game will hang on first run.

Also, I tightened DMA transfer restrictions even more. A-bus accesses
to $4200-421f and $4016-4017 are now blocked. And I also block these
during HDMA line counter / indirect address fetches (as observed on
hardware.) Further, I was previously allowing invalid B->A transfers
to still write the the MMIO reg specified in A, but ignoring the B-bus
read. This seemed wrong: not being able to access the reg should mean
not being able to access it period, so I swapped that around.
Shouldn't affect any known games, but mentioning it just in case.

> Perfect timing matching isn't needed, the games are broken if they
> can't take a normal sized delay for this.


Mortal Kombat II breaks if you're exactly 6 cycles off from expected
timing (but works if you're more than six cycles off.) Jumbo Osaki was
failing by 20 cycles. Wild Guns fails if off by two cycles. A couple
other games were the same. There are roughly _21 million cycles_ in a
second.

Death Brade and some European racing game break if _uninitialized RAM_
doesn't return the values they like.

Uniracers is quite simply _beyond_ broken.

I wish I could get away with just saying the games themselves were
broken (and they are), but when it runs at least 99% of the time on
hardware, you can't use that as an excuse. Everyone will still call it
an emulation bug :(

> Err, not really. Fixed delay for all operations is as dumb as no
> delay for all operations.


I typically like the idea of emulating as much as we can ("building
blocks" and such), if that means guessing approximate delays, so much
the better. But for the DSP-1, adding any delays is even worse in my
opinion. Why?

First, the delay lengths will no doubt vary depending upon how complex
the transfer is. Second, emulating the delays would force us to
implement the DSP-1 as the dedicated processor that it is: thusly, its
overhead would soar from barely noticeable to nearly as intense as
SuperFX / SA-1 emulation. Third, it may be possible to read partially
computed results before the operations finish. We can't even figure
out the partial computations of mere _unsigned multiplication and
division_ in the S-CPU core, so how the hell would we ever plan to
figure out attitude / altitude calculations?

The only feasible way we're going to get this right is to dump the
program ROM and then emulate the instruction set. Even decapping the
DSP-1 has been no help for that, and even if by some miracle we got
the ROM, we'd have to figure out the instruction set and timing with
no documentation. And all of this to improve emulation of a couple of
lackluster action games. Good luck finding someone willing to do all
that for free, and just to end up getting ~90% of people bitching that
suddenly DSP-1 emulation is as demanding as SFX emulation, yet
provides no visible improvement over existing emulation. And it even
requires another DSP1program.rom file that they didn't need before!

Thus, it's really not worth the effort if our entire model of
emulating the chip is busted in such a manner that we couldn't improve
it more even if we wanted to anyway.

[No archive available]
2008-08-03 12:08:00 +00:00
byuu
0cf16ce784 Update to bsnes v033r04? release.
Posted a new WIP which can pass the test_hdmasync ROM I posted in the
other thread.

Please note that it's currently throwing off Jumbo Osaki exactly 50%
of the time. I'll look into it over the weekend. But the change I've
made is correct, so if I can't fix these, the games stay broken :/

One of the most unfortunate parts of emulation: when a game works
because two things are bad, but no longer when only one thing is bad.

[No archive available]
2008-08-01 13:11:00 +00:00
byuu
ce38d577ef Update to bsnes v033r03? release.
New WIP posted.

It adds my new findings on HDMA, which I've posted here:
http://board.zsnes.com/phpBB2/viewtopic.php?t=11804

This effectively fixes Mecarobot Golf once and for all. Interestingly
enough, it also eliminates the track line flickering in Super Mario
Kart.

Image
What a boring screenshot ...

I've tested for regressions with Battle Blaze, Battletoads,
Battletoads & DD, Breath of Fire 2 German, Circuit USA, Der
Langrisser, Energy Breaker, Earthworm Jim 2 (USA and EUR), F1 Grand-
Prix, FF: Mystic Quest, Mortal Kombat I & II, Jumbo Ozaki no Hole in
One, Secret of Mana and Street Racer. Basically, all the usual HDMA
suspects. Looks good to me.

Let me know if you guys find any new regressions, though.

[No archive available]
2008-07-29 06:24:00 +00:00
byuu
0a87b99370 Update to bsnes v033r02? release.
Alright, then. This was the new feature from the last WIP:

Image

Multitap support for Nach and tetsuo55 :)

New WIP up as well. This one adds Pogo's request, there's a new config
variable named input.analog_axis_resistance. The setting works both
for the DirectInput/Windows and SDL/Linux drivers.

It used to be 75% on Windows, 50% on Linux. Now it defaults to 50% on
both platforms. If any of you guys have an analog stick and want to
come up with a better default value, please feel free. I wasn't able
to pull off Ryu's spinning kick thing very easily at 75%, for
instance.

> The WIPs are private. Most of the people with access got it two
> years ago.


I used to give out access to anyone who found a new emulator bug in a
public release, but that's not working so well anymore ...

Eventually I'd like to get a system set up where anyone can get
access, yet avoid having the WIPs leak. I really don't want to bother
emu news site readers with daily WIP updates that change ~3kb of code.

[No archive available]
2008-07-28 09:56:00 +00:00
byuu
82d5761705 Update to bsnes v033r01? release.
Alright, new WIP. Added a new feature so people will stop _harassing_
me about it :P

Try and guess what it is.

[No archive available]
2008-07-27 14:44:00 +00:00
byuu
9133129209 Update to bsnes v033 release.
This release adds SPC7110 emulation, without the need for graphics packs!!, and a rewritten S-RTC (real-time clock) emulator.
SPC7110 support means that Far East of Eden Zero, FEoEZ: Shounen Jump Edition, Momotarou Dentetsu Happy and Super Power League 4 are now all fully playable. I will warn you, the emulation is very slow in this version -- while most areas of each game will run at the same speed as other games, there are a few peak moments where speed will drop by up to ~50%. The reason for the slow-down is that I am currently uncertain how to determine the amount of data to decompress in advance, so I default to the maximum amount possible. The reason I am releasing now anyway, is because I beleive in the "release early, release often" paradigm. It will likely take me a few weeks to finish researching this chip, and I didn't want to keep the work I had private during that time. But rest assured, bsnes v034 should feature much faster SPC7110 emulation.
neviksti, Andreas Naive and jolly_codger worked non-stop on the SPC7110 decompression algorithm for the past two weeks. caitsith2 provided valuable data to the effort. I only wish that I could've been of some use, but alas, I had no role in this. In the end, it was neviksti who managed to crack all three(!!) compression modes of this chip, which turned out to be a customized 8-bit QM-coder with a prediction model. You can read more about this here. I would also like to thank Dark Force and John Weidman (aka The Dumper) for their research notes on the SPC7110 register interface.
For those who don't understand the hoopla about figuring out this compression algorithm when we already had graphics pack simulation, I should note that we have since found a few errors in these packs. Not to mention, you no longer need ~4-16MB packs for each game you wish to run. They work like any other game now. Better still, the chip can now be used to compress new graphics, eg for any future translation efforts on these titles.
The real-time clocks in both Far East of Eden Zero and Dai Kaijuu Monogatari 2 will now save a ".rtc" file in your save folder, which contains the clock as set by the video game, as well as a timestamp from your computer when the time was last updated. It uses the difference between the saved timestamp and current time to update the time. This allows you to specify any time you like, whereas previously bsnes would just use your computer's current time, ignoring the time you set in-game. It also allows the "round clock by 30 seconds" option in both games to work. I avoided this before because this method makes supporting daylight savings time and such impractical, although I should note that the original hardware did not support DST, either. This method was required to pass the SPC7110 tests, and is overall much more faithful to how the original chips worked.
Once again, I'd really like to personally thank neviksti for his tireless efforts. Eliminating graphics packs from SNES emulation was one of my primary reasons for getting involved in the SNES emulation scene. That neviksti managed to crack this algorithm means a lot to me. Thank you so much, neviksti. This release is dedicated to you, now go get some sleep Wink
2008-07-20 00:06:28 +00:00
byuu
7d83cde40a Update to bsnes v032r01? release.
This worked great, thank you. libao is now tolerable on ALSA. Now I
just need to add support for disabling "Audio::Synchronize" (by
disabling sound output, since libao is a blocking API.)

---

EDIT: posted a new WIP, with RedDwarf's ALSA and libao fixes. Both
work very well for me, your mileage may vary.

No Windows binary, as it would be exactly the same as v032a, anyway.
This one's mainly for Linux users who can compile from source.

[No archive available]
2008-06-02 02:00:00 +00:00
byuu
bbc77a6cf2 Update to bsnes v032a release.
- Windows: file open filters are now working once again
    - All ports: emulation speed setting is now properly restored at startup
2008-05-26 08:46:05 +00:00
byuu
ebb9367c68 Update to bsnes v032 release.
- Core: simplified CPU / SMP flag calculations
    - Added ALSA audio output driver to Linux port [Nach]
    - Improved font handling for Windows and Linux ports
    - Greatly cleaned up the user interface
    - Windows port now uses Unicode instead of ANSI
    - Added localization support
    - Config and locale files can now be placed inside bsnes executable directory for single-user mode, if desired
    - Fixed crashing bug with HQ2x on Linux/amd64 port [RedDwarf, Nach]
    - Hid "Power Cycle" option by default, as it is too similar to "Reset"
    - Slighty tweaked program icon [FitzRoy]
    - Minor code cleanups -- replaced union bitfields with templates, improved memory allocation, etc
2008-05-25 18:45:59 +00:00
byuu
96fe8f760d Update to bsnes v031r08? release.
Thank you everyone for the translations! I've also posted a new WIP,
with an improved Japanese locale. No changes to the strings that
anyone has to worry about with theirs.

To strike a compromise, I've removed power cycle from the menu by
default, and added a new config file option, "advanced.enable". Set to
false initially, but if you set it to true and restart, power cycle
will re-appear. I intend to use this option to hide the debugger
functionality if and when that gets re-added, as well. Plus we can
remove other questionably useful / confusing stuff this way. The key
binding for it still shows up (removing it there would be tricky), but
it's not bound to anything by default, either. Sound fair?

Also, something I've been meaning to do for a while now ...
unload/reset/power cycle are now disabled when a cartridge is not
loaded.

[No archive available]
2008-05-22 09:18:00 +00:00
byuu
8abd1b2dfe Update to bsnes v031r07? release.
Okay, new WIP. Couple of changes.

One, I was displaying the warning message about unsupported chips no
matter what. Oops, fixed.

Two, removed the "Select Folder" text. The dialog looks a bit empty
now, but oh well.

Three, added "Ok" to the warning message box strings.

Four, added "Enabled" to the cheat editor strings. You'll notice that
"Disabled" is not there -- it's shared by the speed regulation
setting. I know, sharing strings sucks, but that's pretty much how the
localization system works, sorry. You can use something simple like
"On" / "Off" in place of "Enabled" / "Disabled", if necessary.

Also updated the locale.cfg file for everyone:
http://byuu.cinnamonpirate.com/temp/locale.cfg

[No archive available]
2008-05-20 07:02:00 +00:00
byuu
f6efcbe6fd Update to bsnes v031r06? release.
Okay, I've posted a new WIP, which has a completed locale.cfg file.
Well, it's completed for v032, at least. All translations are going to
have to be updated for every release, sadly.

For those interested in translating it, I'm looking to only have
native speakers perform translations. I don't care if things aren't a
perfect literal translation, so long as the general idea gets across.
But I don't want anyone using machine translation tools, either.
They're very unprofessional, better to wait until someone fluent comes
along. Yes, I know that's ironic given my translation to Japanese:
hoping someone will re-do that one.

The reference locale file is here:
http://byuu.cinnamonpirate.com/temp/locale.cfg

Format is obviously UTF-8. Yours will need to be in this format as
well. Any local encodings will fail miserably.

You can see most of the options in bsnes v031 to see where they come
into play. I have them mostly sorted per window. Some windows share
the same string. I doubt that's going to be a problem, but we'll see.

If you have access to the WIPs, be sure to get the latest one to test
with. If not, and you're willing to translate the UI, feel free to PM
me and I'll happily send you a link to it.

I've added a "Localization by:" field to the about screen. Please feel
free to add your name there.

Next up, I'm trying something a bit different for the config files,
and I've updated readme.txt to reflect this:

bsnes will now check in the same folder as the executable for
bsnes.cfg and locale.cfg. If they're found, bsnes will use these
files. If they are not found, it will use your user profile folder for
storage.

So, if you want bsnes to run in single-user mode, just make sure
bsnes.cfg and/or locale.cfg exist. If not, you can create a blank file
and bsnes will use that next time you run it. If you want multi-user
mode, delete the files. If you want multiple profiles, use single-user
mode and multiple copies of the executable.

I'll be distributing future Windows binaries with blank bsnes.cfg and
locale.cfg files, so that single-user mode is the default. Just delete
them to switch to the old method if you prefer. Hopefully this pleases
everyone.

[No archive available]
2008-05-19 08:48:00 +00:00
byuu
36859ea52c Update to bsnes v031r05? release.
Well, that was certainly a pain in the ass ...

Image

Had to port hiro to full-on Unicode / UTF-16. But the GUI API still
takes UTF-8, it's all converted internally now, bidirectionally.

Oh, and don't make fun of my Japanese :P

---

As for the new WIP, I've included my example locale.cfg. No other
lines will translate, so don't try yet. You need to put it in the
.bsnes folder next to bsnes.cfg. And don't try it unless you have
Japanese fonts, obviously.

[No archive available]
2008-05-15 07:51:00 +00:00
byuu
64589148d4 Update to bsnes v031r04? release.
New WIP.

This one adds DPI-independent font sizing for both Windows and Linux.
With that, I've reduced the font size back down to "Tahoma 8" on
Windows, and "Sans 8" on Linux.

Because of that, I was able to reduce textbox and button height from
30 to 25, and label, checkbox and radiobox height from 20 to 18. In
other words, the UI looks like it did back with v019.

There's only one tiny flaw with the Linux port, I'm unable to change
the font face for the listbox column header. It's not actually a
widget, so it ignores my gtk_container_foreach ->
gtk_widget_modify_font() calls. Any help would be greatly appreciated.

I've also added FitzRoy's new icon. It seems to only have 32-bit
icons, and no 256-color icons ... I guess we'll see how that looks on
Win2k soon enough.

Lastly, statusbar toggle was broken in the last WIP, that's fixed now.

[No archive available]
2008-05-12 05:26:00 +00:00
byuu
89ae1101ee Update to bsnes v031r03? release.
Another WIP. This one changes the GUI toolkit to not invoke callbacks
when the API is used to set the state of widgets. With that it was
really easy to get the speedreg / frameskip checks to update when
using the keyboard controls.

What I really need for this WIP is testing to see if any UI elements
are now broken as a result of the change. For example, try and get a
checkbox to not represent the actual state of something. Eg a
frameskip of 2 but the checkbox is on 0. Also check startup states and
that sort of thing.

The UI code really needs to be cleaned up at this point ...

[No archive available]
2008-05-07 06:30:00 +00:00
byuu
340d86845a Update to bsnes v031r02? release.
New WIP. Please be sure to test a few games with this one to look for
regressions.

I got tired of using bit packing for CPU / SMP register flags, because
they do not mask the upper bits properly.

In other words, (assume big endian) if you have struct { uint8_t n:1,
v:1, m:1, x:1, d:1, i:1, z:1, c:1; } p; and you set p.m = 7; it will
set p.v and p.n as well. It doesn't cast the type to bool.

So I rewrote the old template struct trick, but bound it with a
reference rather than relying upon union alignment. Looks something
like this:

    template<int mask>
    struct CPUFlag {
      uint8 &data;

      inline operator bool() const { return data & mask; }
      inline CPUFlag& operator=(bool i) { data = (data & ~mask) | (-i
    & mask); return *this; }

      CPUFlag(uint8 &data_) : data(data_) {}
    };

    class CPURegFlags {

    public:
      uint8 data;
      CPUFlag<0x80> n;
      CPUFlag<0x40> v;
    ...
      CPURegFlags() : data(0), n(data), v(data), m(data), x(data),
    d(data), i(data), z(data), c(data) {}

    };


Surprisingly, benchmarks show this method is ~2x faster, but flags
were never a bottleneck so it won't affect bsnes' speed.

Anyway, with this, I decided to get rid of the confusing and stupid
!!() stuff all throughout the CMP and SMP opfn.cpp files. It's no
longer needed since the template assignment takes only a boolean
argument. Anything not zero becomes one with that.

So code such as this:

    uint8 sSMP::op_adc(uint8 x, uint8 y) {
    int16 r = x + y + regs.p.c;
      regs.p.n = !!(r & 0x80);
      regs.p.v = !!(~(x ^ y) & (y ^ (uint8)r) & 0x80);
      regs.p.h = !!((x ^ y ^ (uint8)r) & 0x10);
      regs.p.z = ((uint8)r == 0);
      regs.p.c = (r > 0xff);
      return r;
    }


Now looks like this:

    uint8 sSMP::op_adc(uint8 x, uint8 y) {
      int r = x + y + regs.p.c;
      regs.p.n = r & 0x80;
      regs.p.v = ~(x ^ y) & (x ^ r) & 0x80;
      regs.p.h = (x ^ y ^ r) & 0x10;
      regs.p.z = (uint8)r == 0;
      regs.p.c = r > 0xff;
      return r;
    }


I also took the time to figure out how the hell the overflow stuff
worked. Pretty neat stuff.

Essentially, overflow is set when you add/subtract two positive or two
negative numbers, and the result ends up with a different sign. Hence,
the sign overflowed, so your negative number is now positive, or vice
versa.

A simple way to simulate it is:
int result = (int8_t)x + (int8_t)y;
bool overflow = (result < -128 || result > 127);

But there's no reason to perform signed math, since the result can't
be used for anything else, not even any other flags, as the opcode
math is always unsigned.

So to implement it with this:
int result = (uint8_t)x + (uint8_t)y;

We just verify that both signs in x and y are the same, and that their
sign is different from the result to set overflow, eg:
bool overflow = (x & 0x80) == (y & 0x80) && (x & 0x80) != (result &
0x80);

But that's kind of slow. We can test a single bit for equality and
merge the &0x80's by using a XOR table:
0^0=0, 0^1=1, 1^0=1, 1^1=0
The trick here is that if the two bits are equal, we get 0, if they
are not equal, we get one.

So if we want to see if x&0x80 == y&0x80, we can do:
!((x ^ y) & 0x80);

... or we can simply invert the XOR result so that 1 = equal, 0 =
different, eg ~(x ^ y) & 0x80;

The latter is nice because it keeps the bit positions in-tact. Whereas
the former reduces to 1 or 0, the latter remains 0x80 or 0x00. This is
good for chaining, as I'll demonstrate below.

Do the same for the second test and we get:
bool overflow = ~(x ^ y) & 0x80 && (x ^ result) & 0x80;

We complement the former because we want to verify they are the same,
we don't for the latter because we want to verify that they have
changed.

Now we can basically use one more trick to combine the two bit masks
here. We want to return 1 when overflow is set, so we can look for a
pattern that will only return one when both the first and second tests
pass.

An AND table works great here. 0&0=0, 0&1=0, 1&0=0, 1&1=1. Only if
both are true do we end up with 1.

So this means we can AND the two results, and then mask the only bit
we care about once to get the result, eg:
bool overflow = ~(x ^ y) & (x ^ result) & 0x80;

And there we go, that's where that bizarre math trick comes from. I
realized while doing this something that bugged me in the past.

I used to think that for some reason, the S-SMP add overflow test
required x^y & y^r, whereas S-CPU add overflow used x^y & x^r.
Probably because I read the algorithm from Snes9x's sources or
something.

But that was flawed -- since addition is commutative, it doesn't
matter whether the latter is x^result or y^result. Only in subtraction
does the order matter, where you must always use x^result to test the
initial value every time.

Subtraction switches up things a little. It sets overflow only when
the signs of x and y are _different_, and when x and the result are
also different, eg:
bool overflow = (x ^ y) & (x ^ result) & 0x80;

Fun stuff, huh?

So I was wanting this tested thoroughly, just in case there was a typo
or something when updating the opfn.cpp files.

---

That said, I also polished up the UI a bit. Moved disabled to the
bottom of the speed regulation list, and added key / joypad bindings
for "exit emulator", "speed regulation increase / decrease" and
"frameskip increase / decrease".

I know these key bindings do not update the menubar radiobox positions
yet. I'll get that taken care of shortly.

[No archive available]
2008-04-19 12:03:00 +00:00
byuu
b895f29bed Update to bsnes v031r01? release.
New WIP posted.

Not much to this one.

- added FitzRoy's updated program icon
- removed safe_free / safe_delete / safe_release template functions
- replaced nearly all malloc / free calls with new / delete[]

And lastly ... long ago, I used "File / Edit / Help" to conform to
standard UI design. I quickly replaced Edit with Settings, and later
Help with Misc. Lately, the last one has been bugging me ... "File"?
File what? Why is there a reset system option under file?

So, it may be somewhat controversial, but I renamed File to System,
and dropped the now superfluous " System" from Reset / Power Cycle.

I'd honestly like to remove "Exit" from that menu as well, but I know
I'd be pushing it then.

What I want to do next is move "Disabled" in speed regulation to the
bottom of the list, and add key bindings to increase / decrease speed
regulation. I'd like the step after fastest to be disabled. It makes
sense, as fastest can never be faster than disabled, but disabled can
be faster than fastest.

Other nice ideas would be: a cartridge info option under the system
menu somewhere, frameskip +/- key bindings, an exit emulator key
binding, a new GUI panel with options to warn on reset / unload /
exit, and cleaning up of the event namespace for the UI. Specifically,
start working on a more advanced status panel that can display five-
second alerts that override the normal output.

[No archive available]
2008-04-16 12:59:00 +00:00
byuu
1ef279cb83 Update to bsnes v031 release.
New release posted. Perhaps the most important change was fixing a bug in the Windows port when the keyboard was used for input. For some reason, the IsDialogMessage() function I use for tab key support was causing the main window to emit the Windows error beep every time a key was pressed after a few minutes of use. I do not know why this is, so I have simply disabled the tab key support to prevent this from happening.
Other than that, lots of polishing went into this release. UPS soft-patching will work with the recently released Der Langrisser v1.02 translation, for those curious. You can also store the UPS patches in GZ/ZIP/JMA support, and bsnes will detect this and decompress the patches first. Use the same ".ups" file extension for this, as it detects via file header.
If you wish to try out the newly added OpenGL support: start bsnes, go to Settings->Configuration->Advanced and set system.video to "wgl" (or "glx" for Linux users), and then restart the emulator. Please bear in mind that ATI's OpenGL drivers are an industry-wide joke, so I'd only recommend trying this on an nVidia or Intel video card.
Changelog:
    - Fixed bug and re-enabled HDMA bus sync delays
    - Emulated newly discovered IRQ timing edge case
    - Optimized offset-per-tile rendering
    - Added state-machine implementation of S-DSP core, ~5% speedup
    - Added SPC7110 detection, will now warn that this chip is unsupported
    - Fixed very annoying Windows port OS beeping noise when using keyboard for input
    - Linux port will now save most recent folder when no default ROM path is selected
    - Added OpenGL rendering support to Windows port [krom]
    - Fixed Direct3D pixel mode scaling bug [krom, sinamas, VG]
    - Improved SNES controller graphic [FitzRoy]
    - Added UPS (not IPS) soft-patching support; UPS patch must be made against unheadered ROM
    - As always, cleaned up source code a bit
2008-04-13 23:40:08 +00:00
byuu
0241dd78b7 Update to bsnes v030r08? release.
New WIP posted, which adds the immediate-mode opcode IRQ delay
findings from this past week. Doesn't have any visible effects on
anything. I also went back to a switch table for the CPU / SMP opcodes
instead of the jump table. Shaves ~100kb off the object files and
compiles faster with no speed loss. I used the jump table before to
simplify PGO, but since that's been broken for at least a year now
anyway ...

Fes, thanks for the temporary workaround. I'll try and get a new
release out this weekend if possible. I'd like to have UPS soft-
patching in before the next release, though, hence the delay.

[No archive available]
2008-04-10 11:05:00 +00:00
byuu
a13c3aece6 Update to bsnes v030r07? release.
New WIP.

Direct3D driver: removed diffuse color vertex information, and made
driver re-initialize whenever window size changes. Should fix ATI
resize in pixel scale mode bug once and for all. Confirmation would be
appreciated. Speed will still be bad on some cards that can't handle
large textures, and I don't really want to implement StretchRect()
profiling, so that's still an issue.

Windows/hiro: disabled IsDialogMessage(). This will prevent the tab
key from working in the configuration panel, but will also stop the
main window from beeping every time you push a key -- the lesser of
two evils. Blame Microsoft for this bullshit. IsDialogMessage() should
empty the key buffer, but it doesn't when there are no tabbed controls
on a window. I'll rig something up in the future for this.

Linux/hiro: GTK+ file open / file save / folder select dialogs will
now save the path if you selected a valid file, so that next time you
will start in that folder. This didn't matter if you set hard-coded
paths in bsnes, but it makes a positive difference if you did not.

[No archive available]
2008-04-07 03:34:00 +00:00
byuu
20977817ae Update to bsnes v030r06? release.
New WIP up.

This one fixes HDMA bus sync timing. I verified this was correct per
hardware with the HDMA test sync ROM. It was definitely wrong before.

Secret of Mana, Street Racer and Jumbo Ozaki no Hole in One all work.
Yes, they worked in the official v030 release, but that release had
HDMA sync disabled and rounded.

Mecarobot is improved greatly, but still flickers when the golf course
is moving. If you're as desperate as I am to play this amazing
masterpiece _right now_, you can always hex edit the ROM and change
offset 0x1c6f from 0x40 to 0x80 :)

I'm still investigating that issue more before I start running
hardware tests. I want to rule out things that can't be the cause of
the bug first.

I've also added (hopefully) proper SPC7110 detection. If anyone wants
to test all of them to make sure it works, great. It should give you a
popup now saying that it's unsupported. Down to just needing ST-011
detection now.

[No archive available]
2008-04-03 11:50:00 +00:00
byuu
ba25c82939 Update to bsnes v030r05? release.
New WIP posted, which adds:
- krom's Direct3D fix; point mode at multiples of 3x and higher
without aspect ratio correction is no longer blurry
- FitzRoy's updated SNES controller graphic
- glX improvement for Linux, window will clear to black on startup for
ATI cards now too, but it still doesn't redraw when the window is
damaged because I can't trap the exposure events
- tiny clarification to S-DSP emulator source (use echo_hist_pos enum
instead of just "8")
- started to add SPC7110 _detection_ for the sole purpose of advising
that the chip isn't supported. Not finished yet. Also need to fix
ST-011 detection while I'm at it (it's detected as ST-010 now; they
share ROM type and mapper IDs), and all special chip games should be
covered.
- re-added the slightly incorrect HDMA sync timing. It helps (but
doesn't fix) Mecarobot, it breaks the SoM intro again; but Street
Racer and Jumbo Ozaki are still working right -- looks like other
timing improvements since then were enough for those titles

For those asking for WIP access, I'm really sorry but I have way too
many testers now. It's extremely hard for me to even keep track
anymore. I just don't have the bandwidth.

If you absolutely need a specific WIP, I'll stick it on a file sharing
site or something for you. Otherwise, my apologies for not sending you
the link. I absolutely do appreciate the offers to help beta test,
though.

[No archive available]
2008-04-02 05:41:00 +00:00
byuu
3babe932fd Update to bsnes v030r04? release.
One thing we can always do is add some platform-specific profiling
code. Have bsnes try and determine what the fastest driver is upon
first run. As if I don't have enough to do already, heh.

New WIP, which converts the S-DSP ring buffers to an internal class
object. Surprisingly, it actually does make the code a bit nicer to
look at, although it's kind of unfortunate I can't hijack operator[]=,
heh. I'd be forced to use modulus for that.

Even more surprising, it's about ~2% faster than before. Even though
it's technically even more complex now with three writes instead of
two. Makes no sense at all, but I won't complain. Getting 122fps now
on Zelda 3 load screen.

---

ATI Radeon X300LS:
Direct3D = 64fps
OpenGL = 24(!!)fps

... as if we needed _another_ reason not to buy ATI products. What the
hell was AMD thinking, buying them?
Better yet, why do people buy ATI products? Laptops, I can understand.
But for desktops?? Seriously. That performance is so terrible, you
couldn't even play OpenGL games with that. We really need more OGL
titles to rape ATI on benchmark tests, so that they'll get their heads
out of their asses.

[No archive available]
2008-03-26 08:58:00 +00:00
byuu
6bdeaef0f4 Update to bsnes v030r03 release.
v030 wip3 posted.

This one add's krom's ruby changes, meaning Windows OpenGL support.

For consistency, I changed the Windows system.video setting to "wgl",
and Linux OpenGL to "glx". Linux users should be sure to update that
to avoid SDL video output.

I get ~119fps with OpenGL, and ~120fps with Direct3D. I'd appreciate
if everyone else would test OpenGL support. If it works everywhere
that D3D works, and avoids that texture size slowdown issue, then we
should make it the default driver.

The only issue I see with the driver now is that vsync is enabled no
matter what. You can turn it off in eg the nVidia control panel by
overriding the setting. I also recommend enabling triple buffering.
With that, video is perfectly smooth and audio is ~99.5% perfect. So,
so close. A slight cpu.freq change and you can probably get it
perfect.

God, it's so nice having perfect video and audio. I really wish that
worked across the board. It's absolute euphoria playing games like
that.

[No archive available]
2008-03-26 07:10:00 +00:00
byuu
9e3827e2a2 Update to bsnes v030 release.
I didn't want to release a new version so soon, however there is a rather serious bug in bsnes v029 where the path information for the save RAM files is discarded when one has not selected a default save RAM / cheat path from the path settings tab in the configuration settings window. Because of this, it gets stored to the base directory. For Windows users, this is c:\, and for Linux users, this is /
This bug forced my hand, so I'm releasing v030 to correct this issue. I also cleaned up the S-DSP emulation code to be more consistent with my programming style -- it gets bit-perfect matches to v029's wave output, so I don't foresee there being any problems.
2008-03-24 12:43:32 +00:00
byuu
e499670ad9 Update to bsnes dsp release.
Okay, it's just blargg's. I hope he doesn't mind ...

I rewrote his S-DSP emulator in pure C++. Only took me seven hours,
not bad. anomie's took a few days.

Now, given, it's extremely similar of course. First, the algorithms
are going to be mostly the same regardless of who writes the code.
Second, I really didn't see a reason to waste too much time on this
reverse engineering a bunch of stuff myself, so I pretty much just
took the code and "rewrote" (read: copied) it in my unique style, and
changed a few things here and there. Code flow, variable names,
tables, exact algorithms, etc were blatant, direct copies.

Things I did change:
- counter rate 0 is now hardcoded to not ever hit zero
- counter read is now boolean instead of unsigned short
- a lot of multiplication was converted to shifts
- broke up the program into ~9 source files
- no more global functions anywhere, all in one class
- removed the hooks for things like external channel muting -- will
re-add if I ever add an option like that to bsnes
- modified VREG to not need the voice regs handle passed to it
- all voice functions take a reference instead of pointer to the voice
structs now
- packed 32-line timing table expanded to multi-line
- left everything in their own small chunk functions ... kind of torn
on whether I want to merge that with the main timing function. I like
the encapsulation, but it would remove the need to keep so many
struct-based state variables
- added a few more comments on parts that confused me at first
- removed assignment inside conditional stuff; even though I do that
myself on occasion in other code I write, heh
- yadda yadda, more minor stuff like that

Going to keep working at it -- wanted to get it working now, so that
finding regressions will be easier. I want to remove the double writes
for the ring buffer, make a decision on whether I want to rely on sign
extension, or use sclip<> for that, implement a compile-time option to
bypass libco (will save 2.048 million co_switch calls a second) since
the S-DSP's entire operation fits into a single switch table quite
easily, convert a lot of the mul / div stuff to shifts, convert those
clever split up branches in the envelope and BRR decoding routines to
switch / case tables, remove the shift tables from the BRR decoding,
and try and figure out what's going on with some of the code so that I
can try and document it :)

I'll see if I can contribute something back, too. Perhaps I can look
into what happens when you enable mute or something.

New WIP up which has the new core enabled by default. For those
without WIP access, I've posted the new source for reference. Comments
welcome.

    byuu.org/files/bsnes_dsp.zip


... man, feels weird posting a new topic.

[No archive available]
2008-03-22 15:37:00 +00:00
byuu
805398e5a8 Update to bsnes v029 release.
A new version of bsnes has been released. It contains a few minor emulation fixes, as well as user interface improvements. Behind the scenes, the source has been cleaned up more in preparation for running the CPU and PPU (video processor) separately from each other (eg with no enslavement.) This is required for implementing a clock cycle based PPU renderer.
    - Greatly improved invalid DMA transfer behavior, should be nearly perfect now
    - Major code cleanup -- most importantly, almost all PPU timing-related settings moved back to PPU, from CPU
    - Added option to auto-detect file type by inspecting file headers rather than file extensions
    - Rewrote video filter system to move it out of the emulation core -- HQ2x and Scale2x will work even in hires and interlace modes now, 50% scanline filter added
    - Re-added bsnes window icon
    - Added new controller graphic when assigning joypad keys [FitzRoy]
    - Redundant "Advanced" panel settings which can be configured via the GUI are no longer displayed
    - Improved speed regulation settings
    - XP and Vista themes will now apply to bsnes controls
    - Added "Path Settings" window to allow easy selection of default file directories
    - Tab key now mostly works throughout most of the GUI (needs improvement)
    - Main window will no longer disappear when setting a video multipler which results in a window size larger than the current desktop resolution
    - Added two new advanced options: one to control GUI window opacity, and one to adjust the statusbar text
2008-03-18 06:19:43 +00:00
byuu
7e6e3e3a69 Update to bsnes v028r16? release.
Lots of talking.

 As I've said many times before, I typically don't like working on fan
translations. The programmers are almost always far less skilled than
professional developers, and they almost always test on emulators
rather than hardware.

 I may look into this when I'm feeling particularly bored, though I
don't know how you could have possibly picked a worse game for me to
be caught debugging at work. Well, maybe those "Adult Manga" PD ROMs
...

 EDIT: New WIP. This one adds IsDialogMessage() support. It isn't
perfect, the test apps get the highlighted dots around the active
controls, but bsnes isn't for some reason. Don't know why that is yet.
And it seems once tab enters into a child window, you can't get back
to the outer window. But otherwise, it's better than nothing. I even
got the z-order thing down so tab works in the right direction.

[No archive available]
2008-03-16 05:36:00 +00:00
byuu
16ba1d1191 Update to bsnes v028r15? release.
Thanks, FitzRoy. The controller graphic looks really amazing. I have
two very minor changes to request if you don't mind.

 First, I had to increase the size to 372x178 (Windows BMP format adds
alignment if width is not a multiple of 4 -- this makes it a real
bitch to convert the image to my UI wrapper pixel format), and shift
the actual image one pixel left to center the gradient fade.

 Second, and more importantly, could you store the controller graphic
in 32-bit format with alpha? Rather than using a white or gray
background, if I could get the full alpha channel information, then I
can adjust the background color to anything I like in the future.
Depending on how it looks, maybe I can just let the controller blend
against the window background itself.

 And thank you, King of Chaos, as well. It was extremely difficult to
choose one over the other. I wish I could use just both so as not to
offend anyone. But I kind of like FItzRoy's more. I was kind of going
for that pristine, "cleaner than real life" look. Still, I really
appreciate your help in making a controller graphic.

             ---

             New WIP.

 I've added FitzRoy's controller graphic to the input capture window.
It will only display when configuring joypad buttons, not when
configuring UI buttons.

 I've also added the new UI settings panel. This lets you control
window translucency for all but the main bsnes window. I capped
opacity to 50% minimum, because I don't want to hear bug reports when
people slide it to 0% and can't find the config window anymore :P
 Works on Windows and Linux. If you lack a compositor on Linux, it'll
just stay a solid color. If you have Compiz / Beryl and the blur
filter, use it with gaussian alpha blur. Then you can set opacity all
the way down to 50% and it will still look amazing. I want to post a
screenshot of it, but the image is ~3MB. Maybe later I'll post it to
one of those file hosting sites.

 There's also a setting here to control what gets written to the
statusbar. I went back to just displaying the raw ROM title. So you
can use %t for that, %n for the filename, and %f for the frame rate.
Still working on this feature. Plan to keep the game name visible when
pausing, add some additional info that can be output here, etc. It may
be better to keep this setting in the advanced panel, as it's not the
most user friendly thing in the world. Up to you guys, I guess.

             Need more settings here, though. Need to fill out that
window more.

[No archive available]
2008-03-09 06:01:00 +00:00
byuu
29c871ef62 Update to bsnes v028r14? release.
New WIP. Adds Win2k alpha adjust (against black background), some
minor code cleanups, LZSS compression / decompression for storing
graphics, and puts the program icon onto the about screen, which has
been shrunk down a bit again.

             So, too late mudlord, the answer was LZSS :P
 I wanted to just go with RLE for simplicity, but the compression
ratio sucked. LZSS is the same number of lines of code, yet is three
times more efficient with the icon. And something like a controller
with much more repetition will probably make an even bigger
difference. Meh, the code's easy enough. I wrote it for clarity over
speed, and decompression is always lightning fast with LZ anyway.

             Good job decoding the base64 portion, though. Very useful
routine for a library.

 As for the controller graphics, wow ... I'm really torn. I really
love how clean FitzRoy's version looks, yet at the same time King of
Chaos' version is so lifelike it's scary. I dislike the "flaws",
though. The scratches on the X, the dot on the bottom right, and the
off-center buttons ... since it's digital anyway, I'd prefer it to
appear perfect, if at all possible.

             But it's a tough call. I'll have to hold a vote or
something :)
             Thanks a million for helping with the controller graphic,
both of you!

[No archive available]
2008-03-03 09:24:00 +00:00
byuu
42f1d08c02 Update to bsnes v028r13? release.
New WIP.

 Adds a base64 encoder, which zaps the ~21kb icon down to ~5kb. With
the extra space, I used the 48x48 icon instead. It should look a tiny
bit better, but it still obviously can't beat a non-resampled icon.
Also added Linux icon support. That turned out to be a royal pain, as
the gdk-pixbuf library documentation was separate from the GDK
documentation. Tried finding visuals, to make colormaps, to get GCs,
to create pixmaps to blit onto as drawables, to create pixbufs with,
to attach to the window. Turns out, gdk-pixbuf has a function to turn
raw data into a pixbuf.







> Could we have an option to disable this effect in advanced settings
> so that the mode can appear "crisp" as it does in other emulators?




               This blurring is required for pseudo-hires to operate
properly, eg in Jurassic Park.

 Nonetheless, if you guys really want the option to disable the
blurring, I can add it. Just keep in mind that we're opening up a can
of worms. People will then want an option to disable the sprite
drawing limit, to add hi-res mode7, etc etc. Harder to draw a line in
the sand when you aren't all or nothing.







> This is a problem? If it's a question of storing them all in an ico,
> why not simply say "Here's a nicer ico set seperately, DL if you
> want'.




 I'm not going to put resources external to the executable, unless I
absolutely have to. Thus, I have to put all of these icons inside the
source code, and I have to modify the GUI API wrapper to handle this.







> I was thinking, you know, one of you could report it to them.




               "Hi, uh, Microsoft? Yeah, your compiler is erroring out
when I compile my emulator with it and PGO enabled."
               "Sure, as that's a $12,000 Team Suite Edition feature,
if I could just get your serial number, that'd be great."
               "Oh, uh ... I think I left that at home. I'll call you
right back with it, okay?"
               "Oh, no problem. If I can just get your full name, I'll
pull you up in our system ... ... hello? Sir?"
               ::dial tone::

               And for the _official_ legal record, I only used the
free trial and express editions :)







> Yeah, one issue they can fix is maybe implement blargg's spc core;
> then again, I thought Snes9x was dead.




 Not dead, but on severe life support. Same for SNEeSe and Super
Sleuth. anomie, TRAC and Overload have minimal presence anymore. A
damn shame. The SNES scene is in worse shape than most people realize
at the moment. NES emulators have had dot-based PPU renderers for
years now.

[No archive available]
2008-02-28 18:39:00 +00:00
byuu
521f4f6952 Update to bsnes v028r12? release.
New WIP.

 vcounter / hclock / hcounter renamed to vcounter / hcounter / hdot. I
think it's more clear this way. Fixed up the v/hc stuff to v/h in
bppu_mmio.cpp to match.

 Instead of building each driver for ruby independently, I grouped
them all together into one object file. I know everyone else hates
that, but too bad -- that's the way I program. No sense building ~10
object files when one will do just as well. I was able to cut out ~20
lines from the Makefile as a result of this.

 I added CB_SETITEMHEIGHT magic to actually set combo box to requested
height. Neat. Of course, bsnes doesn't currently use any combo boxes
in the UI, but it'll be nice when it does, at least.

             Lastly, I added something new to the Windows port (that
used to be there a long time ago), just for FitzRoy :P
             I'll go over that in more detail tomorrow. For now,
consider it a surprise.

[No archive available]
2008-02-27 05:55:00 +00:00
byuu
92cfb1268a Update to bsnes v028r11? release.
New WIP up.

             I was a little too busy to work on bsnes this weekend,
but I got some work done tonight.

             First, I moved the field / interlace / overscan status
functions over to the PPU, where they belong.

 This led me to kill a lot of extra CPU timing variables, such as
vblstart and vnmi_trigger_pos. The latter I had to kill because I can
no longer call sCPU::update_interrupts() when the PPU changes the
overscan setting. You may be wondering about interlace toggle -- well,
it can only take effect at the start of a new frame anyway, and the
timing for scanline 0 is the same regardless of interlace setting, so
it doesn't really need to call update_interrupts() anyway.

 With this moved back to the PPU, I was able to clean up the PPU
functions a bit, too. Before, I had PPU::scanline_is_hires() and
CPU::interlace(), and then a function called PPU::get_scanline_info()
that would read the previous two functions and copy them into a
struct. What an odd construct, I'm sure it was more complex in the
past. Cruft, basically. I just killed that, renamed scanline_is_hires
to just hires, and now SNES::Video just queries ppu.hires() and
ppu.interlace() directly. Much nicer.

 I didn't lose any speed here, either. I made up the difference by
force inlining the PPU states in the bPPU header file.

 I ran all my IRQ and NMI tests again, I didn't see any regressions.
Testing of games that use interlace and overscan, as well as of IRQ-
sensitive games, would be appreciated.

 While cleaning up the PPU, I had some code that would flush the PPU
buffer when disabling interlace. I removed that as it looked rather
ugly. Don't really have a clean way of handling that. Not like any
game out there toggles interlace every frame anyway.

 I went through and killed a bunch of config file options that don't
actually do anything anymore, such as audio.frequency and
video.use_vram.

 Lastly, I rewrote the advanced panel code finally. All options that
can be controlled through the UI have been removed. The list is ~80%
smaller now. I also improved a lot of the descriptions. I think it
looks a lot better now, at least. I went with a blacklist, rather than
whitelist. I figure, better to have extra options if I forget to
filter them out; than to have missing options if I forget to add them.

 Before the next release, I'd like to add back default_height() stuff
to get the textboxes and buttons smaller on the Windows port. Maybe
revert that back to Tahoma 8. I should also add descriptions to the
last few advanced panel options missing them. Other than that -- just
regression testing, I suppose. I can't break up the PPU enslavement
any more without adversely affecting performance at this point.

 Hmm, would also be nice to rename vcounter / hclock / hcounter to
vcounter / hcounter / hdot. Afraid of missing a reference somewhere
and screwing up the timing, heh.

 I tried to get the icon working again on the Windows port. But using
LoadImage or CreateIconIndirect doesn't handle the alpha level of
bsnes' icon properly. It ends up as a 1-bit transparency that looks
terrible in the titlebar, as well as the taskbar. The only way I can
get it to look good is with LoadIcon and grabbing the icon from the
resource file. The reason I don't want to do this is because it's not
at all portable to GTK+. Sigh. Tested this on Win2k, by the way. Win2k
isn't supposed to support the alpha channel in icons at all, but it
sure the hell does on the taskbar.

 I even tried GetIconInfo() on the icon returned from LoadIcon(), and
then CreateIconIndirect on that, and it crushes the translucency
again. So it isn't a problem with the format of hbmMask and hbmColor
in my ICONINFO struct.

[No archive available]
2008-02-26 04:07:00 +00:00
byuu
4d922ba17c Update to bsnes v028r10? release.
New WIP.

 This one nukes the region, region_scanlines, prev_line_clocks and
prev_field_lines variables, and removes timeshift.cpp; replaced with
the new history ring buffer. It doesn't appear to affect speed at all,
which is fine by me. Next up, I want to move interlace and overscan
settings back to the PPU.

 All of my NMI and IRQ test ROMs, even the absolutely insane clock-
perfect ones, still pass. So there shouldn't be any regressions. But
if you feel like testing any IRQ sensitive games, that's cool.

 More visibly, I've bound the .cht path to the selection in the path
settings window. So all three paths actually work now. I tested it by
sorting all of my images by ROM, SRAM and Cheat ... have to say, the
folder looks a whole hell of a lot nicer now. I can see why this
feature is so popular.







> Mainly, there needs to be mechanisms to capture the current frames,
> like through render targets.




               Well, I guess if you don't mind writing up a small
example I could work on porting the current code over.

[No archive available]
2008-02-22 15:05:00 +00:00
byuu
3b2918791c Update to bsnes v028r09? release.
New WIP with XP / Vista theming and cheat path selection. Note that
cheat selection is just a placeholder. It still saves in the same
folder as the ROM for now.

I also spent about four hours trying to get the dual counter into a
fork of bsnes ... and had my ass handed to me. Rigging something up
really quickly that will break every last timing test I have is easy.
But it looks like doing this properly is going to be an extreme
undertaking that will take at least a few weeks. The code is just too
old and too hardcoded.

 I've started cleaning up that code to match my modern programming
style. It seems the only way to really tackle this is going to be very
slowly moving variable by variable to a separate class/struct
somewhere (and running my regression test ROMs each time), and then
once the entire thing is moved out of the CPU, try and clone it and
fork off the PPU to its own thread.

 By my estimates, it appears that simply splitting the CPU and PPU,
and giving the PPU its own cothread, is eating ~8% of performance. The
good news though is that if and when I succeed, it's quite possible I
can emulate the OAM cache behavior, which would fix the black
scanlines in Dr Franken and Winter Olympics.

 Some other good news ... I decided there was really no sane reason to
have different clock frequencies for the CPU<>PPU and SMP<>DSP, since
the real SNES only has two crystal clocks anyway. A novelty, sure, but
that would complicate the fuck out of dual counters. With that gone, I
can avoid a 64-bit multiplication during each SMP/DSP addclocks call.
That gives a modest ~2% speedup -- possibly placebo.

 Looks like a ring buffer for timeshifting backwards isn't going to
help much. I only notice a ~1-2fps difference even when disabling
timeshifting completely. Not surprising, timeshifting really doesn't
have that much overhead to it.

 Oh yeah, it seems I disabled the code that set the hclock to 186 upon
reset a while back, which was causing some of my oldest tests to fail.
I can't remember why I disabled that (maybe something to do with
cothreads), and enabling it didn't seem to cause any problems, so ...
I left it enabled. Let me know if anything screwy happens.

[No archive available]
2008-02-21 05:34:00 +00:00
byuu
b7d34a8aa3 Update to bsnes v028r08? release.
New WIP.

 Fixed the frameskipping bug, fixed the DirectDraw renderer. I also
added a new folder_select function to both ports of hiro (Windows and
GTK+), and with that, I added a new path settings panel to the
configuration window.

               You can see how it looks here:






    http://byuu.cinnamonpirate.com/images/bsnes_20080219.png




 Also, I compiled the Windows binary with Direct3D support omitted.
tetsuo55, please grab this version, as I intend to compile with
Direct3D support for subsequent WIPs.

[No archive available]
2008-02-19 14:28:00 +00:00
byuu
8fd90cc123 Update to bsnes v028r07? release.
New WIP adds an option to enable or disable filetype
detection by reading the format header. I received no feedback, so I'm
defaulting to this behavior being off. In other words, I'm defaulting
to requiring the file extension to be correct to properly handle the
file. This is because there's no reason a real SNES would behave
different just because $8000 = 'P' and $8001 = 'K', and with the
option enabled by default, you wouldn't be able to get such a game to
run. But the option is there for those who want it.

I've also added bumpers to everything but the core (cpu, smp, ppu,
dsp) and some of the library stuff and platform-specific stuff (hiro,
libfilter, libco, ui) -- really can't add them to libco as I want each
individual file to compile on its own if the user wants. But overall,
it should make things a lot easier for those trying to build bsnes
without using my Makefile.

               Not in the WIP, I just fixed a frameskipping bug. It
was broken in the last few WIPs, including the most recent.







> You'd be best off reading 7 bytes, and then memcmp()'ing them.




 Can't memcmp() the low five bits of the GZ flags byte. I'm not
concerned about rigid speed here anyway. It's just file type
detection. I changed it to fread() the bytes, that's good enough.

               Thanks for the information, I've extended JMA to a
40-bit check.







> Anyway, the -mdynamic-no-pic option does work and is likely the
> better solution, since it apparently continues to allow linking to
> dynamic libraries, whereas -static apparently does not.




 Well, we use -static only when building libco.c. I like -static more,
because it exists in all versions of GCC. I will mention -mdynamic-no-
pic in the libco documentation for v0.13 official.







> Well, turns out the CGRAM content is the same... Surprised
>                    bsnes, ZSNES and vSNES show 8/16/24, so it's
> something to do with SNES9x.




               Thank you for testing! If only all beta testers had
your technical prowess :D

               Glad to see it's not a bug on my side. Not really in
the mood to track down bugs at the moment, heh.







> You obviously haven't been around here very long. Razz
>                    Believe me, someone has or will try it.




 I've actually been very fortunate in that regard. At least 95%, if
not all, of bsnes users have been very intelligent and well spoken :)







> Another small issue could be adding a list of recently loaded ROMs
> to the menu.




               Not a chance. I can't _stand_ recently opened document
lists.







> now I'll leave you all to this medical hijacking of the thread,
> while waiting for richard bannister to successfully compile and
> release a new bsnes




               He has. Get it here. Be sure to send him thanks, please
:)







> byuu's been planning to write documentation for ages, he's just
> never gotten around to it. Perhaps all the experience he's gained
> restructuring bsnes will help him plan out the documentation when he
> does, though




 I won't start on docs until I have a functional CPU<>PPU cycle-level
emulation model. I'll try documenting the PPU as I work on cycle
timing, and I can expand upon the documentation from there.

[No archive available]
2008-02-18 17:02:00 +00:00
byuu
e651beb72e Update to bsnes v028r06? release.
New WIP.

 Richard Bannister asked me a year ago to add support to detect the
file compression type by reading the header, as apparently Mac users
can't be bothered to use proper file extensions.

               In an act of extreme expediency, I've added his request
in record time :P

               Here's the detection code I wrote:







    Reader::Type Reader::detect(const char *fn) {
                       FILE *fp = fopen(fn, "rb");
                       if(!fp) return Unknown;

                       fseek(fp, 0, SEEK_END);
                       unsigned size = ftell(fp);
                       rewind(fp);

                       uint8_t a = size >= 1 ? fgetc(fp) : 0;
                       uint8_t b = size >= 2 ? fgetc(fp) : 0;
                       uint8_t c = size >= 3 ? fgetc(fp) : 0;
                       uint8_t d = size >= 4 ? fgetc(fp) : 0;
                       fclose(fp);

                       if(a == 0x1f && b == 0x8b && c == 0x08 && d <=
    0x1f) return GZIP;
                       if(a == 0x50 && b == 0x4b && c == 0x03 && d ==
    0x04) return ZIP;
                       if(a == 0x4a && b == 0x4d && c == 0x41 && d ==
    0x00) return JMA;
                       return Normal;
                       }




 If anyone sees any problems, please let me know. And unless your name
is Nach, I expect you to read and cite official documentation to point
out any problems.

 Note: I need more than 16-bit accuracy to avoid false positives, so I
read the compression type and flags for GZIP. Compression type should
always be 0x08 according to my understanding of GZ. Flag top 3 bits
are always 0 per spec. I guessed with JMA's fourth byte. I hope it's
always zero, but I don't know that for certain.

 The new WIP has GZ/ZIP/JMA support built-in, so testing would be
appreciated, though I doubt you'll hit any false positives.

               Now, a more important question. Should I enable this
detection by default in bsnes, or go by filename? It's _possible_ an
SNES ROM could have these headers, despite not being compressed at
all. One could even add these signatures intentionally if they really
wanted. A real SNES game could have these bytes at the top of the
file, quite obviously.

So, is it better to cater to people who misname extensions, or to the
possibility that a game might have these bytes in the signature (a one
in four billion chance of happening accidentally. One in 500 million
for GZ false detection.)

               ---

 Also, I added some changes by KarLKoX to allow OpenAL to build on
Windows. Namely, I removed the unused ALut dependency, and added
support to the makefile to include openal32. I don't intend to build
OpenAL into the default Windows binaries (because I don't want extra
DLL dependencies that most people do not have; and because OpenAL
support sucks on Windows for non-Creative cards), but perhaps in the
future I'll offer more than one version for download.







> The "almost black" color below the door is 8/16/24 in bsnes
> (standard preset) and 0/16/16 in SNES9x. It's best to see on a black
> background.

>                    EDIT: This might be due to the RGB565 format.




 Wow, that's quite a difference. If you have bsnes v013-v019, you can
dump the palette through the memory viewer. Perhaps see what SNES9x
has from its savestate, and if it's different -- one of us has an
emulation bug.

               Not an RGB565 problem, or the colors would match when
ignoring the low three bits (two for green.)

               bsnes:
               00001000
               00010000
               00011000

               SNES9x:
               00000000
               00010000
               00010000

[No archive available]
2008-02-17 16:49:00 +00:00
byuu
4cbba77fc7 Update to bsnes v028r05? release.
New WIP up. This one re-adds HQ2x and NTSC, so all
filters from v028 are back, plus there's the new scanline filter.

 So all of that code is now out of the core. It was pretty silly that
eg the S-SMP core was dependent upon the SNES class, which depended on
the VideoFilter class, which depended upon the HQ2x class, which
depended upon the ~50kb HQ2x blending tables. Well, no longer.

 While I didn't make V-only HQ2x and Scale2x filters (yet?), I did add
some code to make it fallback on the direct renderer if hires or
interlace is being used. This means the issues with hires games (eg
DKC intro) should be gone. Let me know if you find any problems.

 I also re-added DMPSDisable to the GTK+ screensaver disable code,
since that was triggering after ~30 minutes or so still. It probably
won't even work, but whatever.







> Why default to a crippled renderer to save those people a few
> clicks?




               First impressions and all that, mostly.







> I have an Intel Mac with OS X 10.4 (no Leopard, sorry, but it
> shouldn't be that different yet) I can test whatever on




               Thank you! :D

               Okay, first thing would be to make sure libco itself
works. Please download this:







    http://byuu.cinnamonpirate.com/files/libco_v13_rc2.zip




               You can compile the test program like this:







    g++ -O3 -fomit-frame-pointer -c test_timing.cpp
                       gcc -O3 -fomit-frame-pointer -o libco.o -c
    ../libco.c
                       g++ -O3 -fomit-frame-pointer test_timing.o
    libco.o -o test_timing




               Then just run test_timing that is produced, and let me
know what the output is, or if it segfaults.







> Really, you want a first-gen Core 2 Duo or newer.




               Yeah, it's pretty slow. Especially since v018. It used
to be easy to get 80-100fps with a 3500+.

[No archive available]
2008-02-14 13:54:00 +00:00
byuu
1194d3f9dc Update to bsnes v028r04? release.
New WIP. Windows binary included. I've added back
Scale2x support, and I also added a scanline filter for Snark. No, I
don't plan on combining them so you can do things like Scale2x +
scanlines. It's a 50% scanline filter. I may add 75% and 100% in the
future.

               Ah, and a while back I mentioned a certain software
filter I saw. Here is that picture:







    http://byuu.cinnamonpirate.com/temp/PhosphorSimTest1.jpg




 Unfortunately, I don't even remember where I found the image anymore,
let alone who made it. Does anyone here know how to recreate the
filtered image from the source image?

 I'd prefer to avoid baseless speculation, if you know how it is done
-- and better yet, if you can duplicate it -- please let me know. I
really, really like the filter and would love to add it to bsnes.

[No archive available]
2008-02-13 14:09:00 +00:00
byuu
89a1b3d65f Update to bsnes v028r03? release.
Posted a new WIP, which cleans up src/snes. I've completely killed all
the video filtering stuff, and cleaned up the rest. Only the audio WAV
logger remains. Didn't feel like moving that to the UI tonight.

 So far, I have the colortable and a direct filter moved to libfilter.
I'll probably just add Scale2X and a simple scanline filter for the
time being, but HQ2x and NTSC will have to be re-added before another
official release can happen.

[No archive available]
2008-02-12 13:45:00 +00:00
byuu
5a82cdf978 Update to bsnes v028r02? release.
Okay, I've posted a new WIP. Windows binary included.

             Changes:
             - Video output uses RGB888, rather than RGB565
 - Removed RGB modes from Xv. They're a major hassle, I can't test
them, and they didn't even work right. Maybe I'll try again in the
future
             - $(DESTDIR) added to Makefile
             - Increased Linux usleep idle delay from 20 to 20,000, so
bsnes appears to consume 0% CPU time when idle
             - Started moving src/snes/video to src/lib/libfilter. So
far, only the colortable has been moved over

 I held off on actually using libfilter's colortable. I'm intending to
break things completely here very shortly by eliminating
src/snes/video stuff, but I wanted to get a WIP out before doing so,
so that people could mess around with RGB888.

 Speed is going to be a little slower for Linux users who use the GLX
or Xv video driver. Very sorry about this. If you need to, stick with
v0.028 official for the time being.

             ---

 By the way, RGB888 is the bottom row. Thanks for playing. RGB888
doesn't make bright colors darker or vice versa, it avoids rounding
errors. It has the biggest effect on near-black colors, as before they
were getting crushed badly by the exponential curve gamma adjust. But
don't be fooled: really dark colors will still be much harder to see
than with the gamma curve turned off.

             Anyway, if you liked the top row more, then just adjust
the settings slightly on the raster settings tab :)

             EDIT: Neat, fglrx driver goes from 57.5fps to 59.5fps
with GLX. YMMV.

[No archive available]
2008-02-11 10:14:00 +00:00
byuu
52be510d2b Update to bsnes v028r01? release.
New WIP posted, Linux only. Need all the testers I can
get on this one, please.

 First and foremost, I spent about four hours figuring out how to
disable the screensaver on Linux. I tried XSetScreensaver,
XResetScreenSaver, XScreenSaverSuspend, DPMSDisable, synthetic
XSendEvent, and all of them failed miserably. I ended up getting it to
work with only one thing: XTestFakeKeyEvent. I send a fake keypress
every ~20 seconds. The key send is keycode (not keysym) 255. I don't
know of many 256-key keyboards, so I think that should be fine.

 Anyway, testing would be greatly appreciated. Please make sure the
synthetic key events do not interfere with your applications in any
way. Technically, the fake key send goes to whatever the active app
is. It shouldn't matter as the keycode used is undefined. I haven't
seen any GTK+ or Qt apps do anything with it, they just ignore it. If
any issues come up, then the best I can do is enable the screensaver
whenever bsnes doesn't have focus, and disable when it does have
focus. I think it should be fine, though. Totem uses the same trick
and nobody seems to mind. mplayer tries all of my above methods plus
bizarre fake messages and dbus commands to try and stop the
screensaver, and it still fails for a lot of people.

 Next up, I've extended the Xv renderer. It can handle RGB15, 16, 24,
32 and YUY2 formats now. It defaults to RGB ones if you have them. I'd
like if all of them could be tested. RGB15 and 16 should be perfect,
24 and 32 will likely have bad pointer arithmetic, but will hopefully
work.

 Need to set driver to "xv", and check what you have with "xvinfo". It
defaults to RGB16, then RGB15, then RGB32, then RGB24, then YUY2, then
it gives up and fails. In the future we can see about letting the
encoding be user-selectable.







> if your repository-maintaining friend doesn't have an amd64 install
> with which to build packages




               That's exactly it, sorry. Plus I don't want to burden
him more than I do already.

[No archive available]
2008-02-08 10:33:00 +00:00
byuu
8b7219bdef Update to bsnes v028 01 release.
[No changelog available]
2008-02-06 22:58:42 +00:00
byuu
926ffd9695 Update to bsnes v028 release.
Changelog:
    - OpenGL (with hardware filter mode support) and SDL video drivers added to Linux port
    - OpenAL (with speed regulation disable support) and OSS audio drivers added to Linux port [Nach]
    - SDL input driver (with joypad support) added to Linux port
    - Emulator pause option added
    - Added option to select behavior of bsnes when idle: allow input, ignore input or pause emulator
    - Added support to remap common GUI actions to key/joypad presses on the "Input Configuration" screen
    - bsnes will now clamp the video output size when it is larger than the screen resolution
    - GUI library has been enhanced, and renamed to hiro
    - Fullscreen mode now always centers video, rather than approximates
    - Fullscreen mode now works correctly on Linux/Openbox
    - Extra layer of abstraction in src/ui has been removed, as GUI lib unifies all ports anyway
    - Video, audio and input drivers unified into standard library, named ruby
    - All custom headers have been merged into a new template library, named nall
    - Makefile rewritten, vastly improved. Allows quick toggling of compiled-in drivers
    - Makefile: all object files now placed in /src/obj, binary placed in /
    - libco greatly enhanced, no longer requires an assembler to build [byuu, blargg, Nach]
    - libco SJLJ driver added; bsnes should now build on any Unix-derivative now (Solaris, OS X, PS3, etc) [Nach]
    - Fixed register $213e.d4 PPU1 open bus behavior [zones]
    - Windows port will not activate screensaver while bsnes is running [Nightcrawler]
    - Visual C++ target no longer requires stdint.h
    - And lots more -- mostly code refactoring related
2008-02-04 16:16:34 +00:00
byuu
a1389a2ba3 Update to bsnes v027r14? release.
> Anything is better than re-using an already well-established name
> (even a short acronym like "vai"), but that's just me.




               I was asking about eliminating the extra layer of
abstraction in the UI.

 But since you brought it up ... I'm sure vai has been taken before.
Quark certainly has been. Hell, BSNES was taken by some people trying
to port ZSNES to BeOS (they gave up). Given, none of those have
anywhere near the popularity of the programming language. But eh, I
_really_ don't care. I like the name, and nobody else in the world is
ever going to use any of my software libraries anyway, so I'll use it.

               Speaking of which, I hate the name miu for the GUI
library, it sounds stupid. So in the spirit of selecting **totally
random names** that are _certainly not associated with any licensed /
trademarked / copyrighted proper nouns_, **especially** not from any
_video games_ or somesuch; I've renamed miu to the **completely
arbitrary** name of hiro. Boy, I'm so creative and original with
naming.

               ---

               That said, new WIP up, with Windows binary.

 Windows users, be sure to set system.video to "direct3d",
system.audio to "directsound", system.input to "directinput".

               Linux users, "opengl", "openal" and "sdl" are
preferred. "xv", "ao" and "x" are safer fallbacks.

               Changes:

               - Finally found a problem with dots in folder names, it
screws with GNU make. So foo.bar has been renamed foo_bar.
 - Decided to drop the pointless duplications of folder names into
file names, such as miu.gtk/miu.gtk.button.cpp -> hiro_gtk/button.cpp.
Same for libco.
 - ruby is completed, all 13 drivers are in the ruby namespace, and
bound to the base ruby.cpp file. The UI just calls
ruby::video.driver("name"); to select a driver. Before v028's release,
omitting the name will select the default best-case driver. ruby is no
longer dependent on anything besides nall (the template library, for
those losing track in the sea of _arbitrary_ names.)
 - miu became hiro, as mentioned above. Like ruby, I wanted to remove
the need for platform-specific tests inside the UI for it. There's now
a base hiro.cpp file that will auto-select the best implementation and
compile it. Just build hiro.cpp on whatever platform you want and it
does the rest.
 - UI platform abstraction removed. src/ui/miu was moved to src/ui.
The two main.cpp files were merged into one. With the GUI wrapper and
hardware drivers moved out of this folder, it's quite orderly there
now.
 - More improvements to the Makefile system. New folder obj/
accumulates all of the object files now. Added streq(al) and
strn(ot)e(qual) to Makefile.string library. Improved the delete
command to support deleting from either obj/*.$(obj) with rm, or
obj\*.$(obj) with del. bsnes executable is moved up one folder above
src/ for both Windows and Linux now. The batch file doesn't perform
this copy anymore.
               - Killed the doc/ folder. Just a pointless, out of date
.dia file there anyway.

               Future plans:
 - I want to make ruby take advantage of nall/config.hpp, and output
to ~/.bsnes/ruby.cfg. This file will contain driver-specific
configuration settings. I may or may not add editing support for them
to the advanced window. Or maybe I'll be lazy and just throw
everything into bsnes.cfg.
               - Really need to add automatic driver selection to
ruby. Can't release it with "" defaulting to no driver.
 - I'd like to replace the god-awful GTK+ video driver (that spawns a
new window) with SDL video. Yeah, I know. At least with SDL_WINDOWID
environment variable hack, it will go into the main window. I'll
probably make this the default driver on Linux, since ATI can't even
seem to get X-Video right with their drivers.

[No archive available]
2008-02-03 10:12:00 +00:00
byuu
5263ffb7aa Update to bsnes v027r13? release.
Yeah, I'll probably worry about the axis stuff later. I didn't intend
to spend a ton of time on adding SDL input support like this, to be
honest. Though I guess I should have known better with SDL and Linux.

 Okay, new WIP with no Windows binary. There's really no reason to get
the WIP. The only change is renaming vai to ruby. That's right matz,
ruby. Deal.

 Moved the folder to lib/ruby from ui/vai. The main point is trying to
make it easier to use for other applications. Instead of having each
app include all sorts of platform-specific header files and manually
create the objects at runtime, it's all done for you now. Just
#include <ruby/ruby.h>, call ruby::input.init(const char *driver = "")
and use it. So far, only the input driver has been ported in this way.

 Note: if you use this WIP, you'll want to make sure system.input is
set to either "sdl"/Linux or "directinput"/Windows. It defaults to no
driver with "", for the time being.

 Once I finish the video and audio drivers in the same manner, I'm
strongly considering eliminating the "multiple UI" bindings, as my
Win32/GTK+ wrapper is pretty much meant to wrap all possible
interfaces into one. This means it would be harder to create a
standalone, GUI-less SDL or VESA2/DOS only port in the future, for
example. But I really don't have any plans to do that anyway. So it's
just needless separation of components, really.

 That extra separation layer was being blurred a lot recently anyway.
The config.cpp file was adding miu-specific GUI commands, where they
had to be to bind to interface.cpp, which binds to the core. Meh.

             So basically, I'm wanting to change the structure from:
             core <> abstracted UI <> miu, SDL, VESA2
             to:
             core <> miu

 Even with this, porting to pure SDL would still be doable in the
future, you'd just have more code to write to do it.

             Any objections?

[No archive available]
2008-02-02 11:58:00 +00:00
byuu
1744bcb99c Update to bsnes v027r12? release.
New WIP.

 I removed property.hpp, as I really didn't like it. Reverted Audio
wrappers to use cap/get/set method that Video and Input wrappers use.
Yay, consistency.

 Capped input.sdl to only poll up to six axes. I suppose if someone
really only has 2 or 4, and has phantom 5,6 axes, they'll run into
Glenn's problem. Meh. We'll wait for a way to configure vai settings
on a per-driver basis to work on that problem more. I was thinking of
just giving it the handle to either unique configuration class
objects, or to the bsnes.cfg one. Just dump all settings for all
(compiled-in) drivers in there, in case the user wants to keep
swapping between drivers.

 Added Nightcrawler's screensaver and monitorpower disable code. Happy
now? Note, I don't use screensavers, nor do I feel like playing for
ten minutes to verify. If anyone else could verify whether or not it's
working, I'd appreciate it. Note again, this won't work on X11, only
Windows.

 Improved the makefile a bit more for Visual C++. Disabled the warning
about passing "this" in a constructor. It's valid and safe C++, and
the only way to implement a bidirectional private implementation by
reference. The last warning is comparison between unsigned long long
and bool, which I can't see a problem with (it gives no warnings about
unsigned long and bool, either). Should I just disable that warning,
as well?







> It ended up being axis 6, but yes, that pinpointed it exactly.




 Oops, sorry. When there are two of something, I always have a really
hard time telling them apart (x/y, hidori/migi, edge/level
(sensitive), etc etc). Not sure why that is. Three or more choices and
it's never a problem.







> Would need porting for BSD gamepads however.




 If it doesn't support BSD, then I'm not really interested. I kind of
have to special case Windows (~95+% userbase), but I don't personally
want to waste my time writing Linux only code.

[No archive available]
2008-02-01 11:46:00 +00:00
byuu
6362044c05 Update to bsnes v027r11? release.
Alright, new WIP posted, Windows binary included.

 I've added the auto-pause setting. I removed the formerly useless
joypad selection comboboxes, as I want to stick those in the main menu
when they are ready anyway. It defaults to auto-pause, so that
discussion is moot now.

 Don't complain that three combo boxes are not natural compared to two
checkboxes -- I don't care. There are only three possible states, and
I like it the way it is. Thanks in advance.

 Nach, you have my humble thanks for your input today. This was
definitely a lot easier than I thought it would be with your help.

               For those curious, here's how things look at the
moment:

               [image]

 I also fixed up the CPU usage when paused. I tried to stress test as
many things as possible (manual pause <> auto pause conflicts,
statusbar update failures, toggling settings in real time, etc etc),
but I may have overlooked something. Rigorous testing would be
appreciated :)

               ---

 In other news, I completely rewrote the Makefile. It is now far more
advanced, and will allow you to easily remove vai modules. Once
removed, the dependencies on those modules will automatically be
removed. The source still needs to be updated to auto-detect non-
existent modules, but this is a step in the right direction.

               Take a look at some of my GNU make-fu:







    ifneq ($(findstring gcc,$(compiler)),) # GCC family
                       flags = -O3 -fomit-frame-pointer -Ilib
                       c = $(compiler) $(flags)
                       cpp = $(subst cc,++,$(compiler)) $(flags)










    ifeq ($(platform),x) # X11
                       miu = miu.gtk
                       vai = video.glx video.xv video.gtk audio.openal
    audio.oss audio.ao input.sdl input.x










    link += $(if $(findstring audio.directsound,$(vai)),$(call
    mklib,dsound))
                       link += $(if $(findstring
    audio.openal,$(vai)),$(call mklib,openal) $(call mklib,alut))
                       link += $(if $(findstring
    input.directinput,$(vai)),$(call mklib,dinput8) $(call
    mklib,dxguid))
                       link += $(if $(findstring
    input.sdl,$(vai)),`sdl-config --libs`)










    arch := $(patsubst %,$(call mkdef,%),$(arch))
                       objects := $(patsubst %,%.$(obj),$(objects))










    compile = $(strip \
                       $(if $(filter %.c,$<), \
                       $(c) $(1) $(rule), \
                       $(if $(filter %.cpp,$<), \
                       $(cpp) $(1) $(rule) \
                       ) \
                       ) \
                       )

                       %.$(obj): $<; $(call compile)










    video.glx.$(obj) : ui/vai/video/video.glx.cpp ui/vai/video/*
                       video.gtk.$(obj) : ui/vai/video/video.gtk.cpp
    ui/vai/video/*
                       $(call compile,`pkg-config --cflags gtk+-2.0`)




               Hahahahahah :)

[No archive available]
2008-01-29 07:42:00 +00:00
byuu
319b244af4 Update to bsnes v027r10? release.
New WIP posted.

 I downloaded a 64-bit Linux OS to verify that libco.x86-64.c worked
this time. Turns out the problem was that I declared "register stack =
*(long long*)to;" -- forgot the size qualifier, so it was being
truncated to 32-bits. Anyway, it works now.

 I also added two more GUI keys, one to pop open the load ROM window,
and one to pause emulation. Yes, took me eight versions, but I finally
re-added pause mode. It probably still consumes CPU time, not sure. I
don't really care, I'll fix it before release. The whole thing is
silly anyway, task scheduler is so easy to cheat. Add sleep(1) inside
the main loop and it states bsnes uses ~1-2% CPU time. As if.

               Windows binary updated, too.







> Unfortunately, it will be 64-bit and using Vista 64 Ultimate, so I'm
> not sure what all will be compatible in terms of software and
> emulators.




 32-bit software runs fine for the most part on Vista. bsnes works
there for sure. But if you want it 64-bit native, you'll have to
compile it yourself, as I have no idea how to make a 64-bit Windows
binary. Nor do I really feel like maintaining another build :/

[No archive available]
2008-01-28 06:27:00 +00:00
byuu
a3f1802845 Update to bsnes v027r09? release.
New WIP. No Windows binary. This one fixes the GTK+
fullscreen issue on Openbox completely. How do I know? Because I'm
running Openbox now to verify :P
               It's pretty spiffy, whole thing is only consuming ~5mb
of memory. Total mem usage sans the 'fox is ~40mb.

 The cool part with these changes is that video no longer flickers for
one frame when you toggle the menubar in fullscreen mode anymore. Not
even on XFCE.

 Just in case, verification always helps. Hopefully it'll work on all
the esoteric window managers out there, so long as they honor the
undecorate window request. You may have some small issues if not.

 I didn't need keepabove to get on top of my XFCE panel, even when I
run the panel in Openbox. I'd like to keep it off if possible.







    void pWindow::fullscreen() {
                       if(state.is_fullscreen == true) return;
                       state.is_fullscreen = true;

                       gtk_window_fullscreen(GTK_WINDOW(window));
                       gtk_window_set_decorated(GTK_WINDOW(window),
    false);
                       gtk_widget_set_size_request(window,
    gdk_screen_width(), gdk_screen_height());
                       }

                       void pWindow::unfullscreen() {
                       if(state.is_fullscreen == false) return;
                       state.is_fullscreen = false;

                       gtk_widget_set_size_request(formcontainer,
    state.width, state.height);
                       gtk_widget_set_size_request(window, -1, -1);
                       gtk_window_set_decorated(GTK_WINDOW(window),
    true);
                       gtk_window_unfullscreen(GTK_WINDOW(window));
                       }




 I also fixed the "esc" -> "escape" keysym for menu toggle, and
updated the x86-64 target with OpenGL + SDL input stuff. Thanks
everyone for the awesome feedback!







> EDIT3: How come you haven't added the icon to the window? Need to
> write another class for handling it (for MIU)? Adding the following
> to the end of pWindow::create() in
> 'src/lib/miu.gtk/miu.gtk.window.cpp':




 Yes, I need a way to do the same in Windows. Ideally, I need a way to
embed the icon inside the EXE, and have an API that allows me to set
the icon both on Windows and Linux from it. I'd prefer to not require
another external file for bsnes binary releases.

               Thanks for the GTK+ code, though. It's a step in the
right direction.







> I tested the linux version of bsnes with my Radeon Mobility x1400,
> and I don't get any video inside the bsnes window. I'm running
> Ubuntu, and I've set up all the ATI driver stuff, AFAIK (Compiz, at
> least, works).




 Aw ... well, thanks for trying. I kind of figured it wouldn't work.
Perhaps ATI doesn't support GLX ... I honestly have no idea. I'll look
into it.







> What other package(s) do I need to install to correct these
> warnings/errors?




               libsdl1.2-dev







> My first problem when running this WIP is that my statusbar is
> black. All black. No one else has complained, so this must just be
> happening over here... any ideas why? Also, fullscreen won't work
> for me... gameplay freezes for a moment when I toggle it and then
> continues windowed, as normal.




 Sigh. I fixed this a while back. Certain GTK+ themes weren't painting
the background of statusbars, so I embedded the statusbar inside an
event box. I don't know why it still isn't working for you. It seems
to work for everyone else now ...







> Secondly, when attempting to map my gamepad, every single key logged
> correctly... except my right directional. What? Weird.




 Good question. The SDL docs say axis 0 = x, axis 1 = y. but the two
thumbs are axes 2, 3 left and 4,5 right. The left thumb uses 2 for X
and 3 for Y, but the right uses 4 for Y and 5 for X. Since the API has
no way to tell you what direction an axis is in, I decided to play it
safe and do axis&1 over all axes. I guess I'll just hardcode for D-pad
+ two thumbs in the next version by swapping 4 and 5 ... no idea how
other apps do it.







> Finally, turning on Scale2x with or without opengl as video does
> this to the Donkey Kong Country intro (note the statusbar)...




 Longstanding issue. Never modified the hq2x and scale2x filters to
support hires modes. Only direct and NTSC do. Hoping to bypass the
issue with pixel shaders in the future. That, or wait until I cleanup
the video filter code and get it out of the core.







> Does GtkSocket not do what you're looking for?
>                    http://www.gtk.org/api/2.6/gtk/GtkSocket.html




 Nah, that's for other processes. I just need to convert an X11 handle
back to a gtk_drawing_area GtkWidget. Sounds weird, but miu only has
one handle() function for cross-platform reasons. So I make that
export an X11 handle (that Xv and OGL take) rather than a GtkWidget
handle (which requires gdkx.h header to extract the X11 handle from in
a safe manner.)

[No archive available]
2008-01-22 07:37:00 +00:00
byuu
4370acae2e Update to bsnes v027r08? release.
Okay, new WIP. This time there's a Windows binary.

 I improved input.hpp a lot, and now InputManager will scan the
joypads as well. DirectInput is fixed, so the Windows port works
again. Now that the InputCaptureWindow stuff is cleaned up, I made it
only capture joypad assignment keypresses when that window has focus.

 I'm also planning to make a "fast assign all keys" button or
something, like I used to have. Not sure how I want to do that just
yet.

               I also tested triggering UI events through the joypad,
it works great :)
 Now I just need to add entries to Input Configuration window for each
UI action. Hmm, should I list the UI entries above or below the SNES
joypad entries? (eg ui.fullscreen, joypad1.up, ... or ...
joypad2.start, ui.fullscreen?)

 The rest of my time tonight I spent working on my cross assembler,
xkas. Added sublabels to it, and some more parsing improvements. It's
getting messy already, though. Trying to write complex grammar parsers
in C++ usually does. But it has to be pure C++. No yacc, flex, etc.
So, I'll have to go back through and find redundant code to factor
out. Why would you care about xkas? Well, the sooner I get that done,
the sooner I can help out the Mother 3 translation project a bit more.
GBA cross assemblers suck for ROM hacking.







> You have a big disclaimer about how it's perfectly legal to use "_0"
> as an identifier inside a namespace... and then never actually do
> it.




 I was using it for joypad button IDs, but I just decided to go with
button_0n. I removed the comment in the latest WIP. Also added a way
to index joypad IDs at runtime, and packed the enums into a linear
list.







> Apps that process input according to 'the characters printed on the
> key' are my pet hate because I the Dvorak layout, so Z and X or WASD
> are not nearly as convenient as you might otherwise expect.




 Would require supporting every keyboard in existence, and needing
some sort of lower-level stuff to translate keycodes to raw keyboard
IDs. The only issue you'll have to reassign your keys one time on
first startup :(

 I envy you though for managing to switch to dvorak. I tried for a
really long time, I could never get above ~40wpm, whereas I get
~110wpm with qwerty now. I think programming is the worst part, all of
my brackets moved? Well, that or the fact that all apps use
Ctrl+C/X/V/Z. That hack to make Ctrl+ use qwerty on dvorak doesn't
solve the underlying issue, either.







> If there is any other areas in the bsnes ppu rendering code that you
> want me to verify in a similar fashion, please tell me, so that I
> can try and code something to prove if it is right.




               Hahah, there sure are :)

 I think the biggest one is that I've yet to test setting BG3 tilesize
to 16x16 when using Mode2/4/6's offset-per-tile mode. Does it affect
indexing? I don't think that it does. May want to also toggle BG1/2
tilesize, just for fun, but I'm almost certain I have that right
already.

 Don't worry about it if you're busy. It's obviously not a big deal
since no game in the world uses the effect (that, or I already emulate
it correctly), and I'll no doubt get around to it if I ever rewrite
the PPU emulation.

               Either way, many thanks for helping me with this :D

[No archive available]
2008-01-17 06:48:00 +00:00
byuu
5a804eac58 Update to bsnes v027r07? release.
Okay, new WIP.
 But before you download it ... there's no Windows binary, because I
haven't finished porting some changes over to DirectInput yet. So it
won't compile just yet.

             But, here's the changes anyway:
             - fixed up the recursive descent math parser, it should
reject 100% of invalid math now
 - added a new header, new.hpp, by Nach. This allows for uint8_t
*buffer = new(zeromemory) uint8_t[65536]; //zeromemory ==
memset(buffer, 0, 65536);
             - updated input.hpp more, and removed keymap.hpp
completely -- this is why DirectInput is broken right now
 - rewrote all of inputmgr.cpp, and InputCaptureWindow. The really
ugly, hackish code is now gone. InputCaptureWindow no longer needs to
hijack the main UI event loop to catch keycodes. Instead, a ~20ms
polling occurs that will alert event::key(up|down) of key changes. The
really, really good news about this, is that it also catches the UI
keypresses now, too. That means that I can now map GUI events to the
joypad, or alternate keys!! Expect that within the next release or
two.
 - ran krom's mode7 test -- holy hell, he has good eyes o.O -- took me
about 20 minutes to definitively tell which output looked correct on
my SNES. He was right of course, and I trusted him, but double
verification is always nice, right? Removed TRAC's theorem from the
mode7 code, and spruced up the formatting in that file a bit.
             - **a real emulation change!!** zones recently pointed
out that anomie figured out that $213e.d4 was PPU1 open bus. I'm
pretty sure I was really thorough when I initially added PPU1+PPU2
open bus (even verified CGRAM.d15 open bus (-much- harder than it
sounds)), but I guess I missed a bit ... odd. anomie also said that
$213e.d5 is basically tied to GND, so that should mean it always
returns 0. I read previously that it was some weird "no PPU activity
for ~40 frames" bit or something, but I don't even remember where I
saw that. I trust anomie anyway, so that means all PPU register status
bits should be accounted for. Thanks for the heads up, zones! :) Now,
of course, it's _extremely_ minor and it won't fix any games (there
aren't any known bugs anyway), but it's still nice to actually fix
something in the core for a change.

[No archive available]
2008-01-16 07:59:00 +00:00
byuu
3b65b50aea Update to bsnes v027r06? release.
Double post! Better to separate this, I think.

             Okay, new WIP lacks Windows binary, and only changes one
header.

 I figured it might be fun to show you guys what I've been doing as
far as code cleanup goes, something a little different, you know?

             Okay, here was the config.hpp file from the last WIP:
             http://byuu.cinnamonpirate.com/temp/config_old.txt

             And here is the new one:
             http://byuu.cinnamonpirate.com/temp/config_new.txt

             Or for those who do not know C++ ... :)
 Like a standard library should be, I've reverted UpperCase to
lower_case, I've converted everything to const-correctness, I've
hidden everything that should not be public, improved the code
formatting, added proper casting, removed the needless template
overloads all over the place, converted the variable names from
incomprehensible gibberish (idef, ifmt?) to clean, understandable
alternatives (default_value, type), removed needless copying of const
char* data, which means no more destructors needed, and added proper
int -> unsigned types when indexing arrays.

 The only thing left is to add better-named integer->string conversion
routines to string.hpp, to get rid of the ugly sprintf code.

[No archive available]
2008-01-09 06:53:00 +00:00
byuu
a85ff8c437 Update to bsnes v027r05? release.
Another WIP, this one's really just for myself to look
over at work tomorrow.

 Changed any.hpp again to not auto upcast fundamental types, as it
causes problems such as downcasting references to long doubles and
such. Sucks how limited the any type is by forced casting 100% of the
time, but whatever ... no endian issues possible now, at least.

 I added property.hpp and bound that to the Audio class (not to Video
or Input yet). It's a lot more complicated than the old integral
identifier cap/get/set functions, but I need the char*-named list
functionality to allow changing driver-specific settings from the GUI
one day. Not too much done there yet. Need to work on it more, I'd
like to make bconfig use property.hpp rather than the IntegerSetting +
StringSetting classes. Tried to make property.hpp read in a config
file without bstring, talk about pain ... ugh.

 Tried to move bstring into nall, failed miserably. When strcpy(char*,
const char*) is in the global namespace and strcpy(string&, const
char*) is not, the compiler gets angry. Not going to work. Really
should go object-oriented entirely and ditch libc functions, but ...
that's a _lot_ of code rewriting on my part. Need to think about it
more first.

 Removed bbase.h dependency from bstring, miu and xkas. Now I just
need to do something about bkeymap.h, and things will be looking a lot
better for code sanity.

               Nach wrote the _seventh(!!)_ libco driver tonight, an
implementation using setjmp / longjmp. Pretty neat, overhead is ~20x,
which puts it only slightly worse off than Windows Fibers on my
machine. Using it in bsnes slows the emulator down by <1%, but it
should be portable across all Unix-derivative systems now. This means
eg a PS3, Alpha, SPARC, etc port should be completely doable now, just
need someone to compile it.

               Planning to position libco as a competitor to GNU Pth,
so that leaves me with:

               SDL -> vai
               wxWidgets -> miu
               GNU Pth and pthreads -> libco
               boost and Loki -> nall
               std::string -> bstring

               Good times. Now I just need to register
inventedhere.org for all of these libraries.







> but it's pointless since the sound quality of the S-DSP isn't good
> enough to make a difference.




 The only thing we could possibly bypass would be the driver / API
resampling our audio (eg 32khz -> 44khz native). Running each SNES
channel through its own hardware channel is just silly. Either use an
API that bypasses the mixer, or don't.

 And yes, there's lots of ways to "enhance" the audio. Replacing
gaussian with a higher end interpolation, bypassing the clipping, etc.
But then you end up with "better" (in most cases), but less accurate
sound.







> is anyone currently working on an enhancement snes emu?




 ZSNES adds cubic spline audio interpolation, SNES9x adds "hi-res"
mode7, ZSNES/XBOX adds rumble pad support to most games.

               Other than smaller things like that, not really.

 I've talked about adding things like rumble, a new MMC to map more
than 64mbits, CD-audio and video playback capabilities. Nobody seemed
all that interested. Eh, maybe if someone finds and sends me one of
those SNES CD player addons used by that one English teaching game,
I'll add support for that to bsnes and then rig something like Der
Langrisser to use it :P

[No archive available]
2008-01-02 07:31:00 +00:00
byuu
a15d15047c Update to bsnes v027r04? release.
Okay, I posted a new WIP. This one's source only again,
since the Windows port is still unchanged.

 I went through and used std::min + std::max, rather than my own
#define, for the sole benefit of getting Nach's JMA code to compile
again (JMA includes a C++ standard header that doesn't like you
#defining min/max, apparently). I was kind of cheap with it though,
max(0, min(10, value)) -> max(0U, min(10U, value)), etc.
 Geez, std::min/max can't even cast between uint16 and uint32. What a
joke, I'll have to write my own that takes advantage of type traits.

 I also started killing off the "bheader.h" files. Since 90% of them
are just template classes, I figure I may as well stick them all in a
namespace and make something akin to boost / Loki. I'm calling this
one nall (I love making up all these names, lately). I also use gcc -I
to point to it, so you get #include <nall/array.hpp> instead of
#include "../../../lib/barray.h", much nicer.

 Taking advantage of the new template library, I added any.hpp
(generic object container), traits.hpp (type traits) and static.hpp
(static assert, if), and with that, I made stdint.hpp, which is a C++
implementation of stdint.h. Since stdint.h is part of C99, it isn't
included with all compilers (eg Visual C++). By using sizeof() and
static_if, I was able to make my own compiler-independent version of
this file. Thus, the dependency on stdint.h was removed.

               I'd be very interested in feedback on anything in nall/
(it's located in src/lib).

 Specifically, could someone with a big-endian machine test any.hpp?
I'm worried that downcasting will reverse the order of data read back.

               Example test app:






    #include <stdio.h>
                       #include <nall/any.hpp>
                       int main() {
                       nall::any t = 0x01020304;
                       printf("0x%x\n",nall::any_cast<short>(t));
    //should print 0x0304
                       return 0;
                       }










> Please byuu, can you extend the API, would you be so kind?




 Of course, I want vai to be used for more than just SNES emulation.
Though I've yet to get anyone using any of my libraries before, so it
may be a fairly pointless endeavor.

               It'll take me some time, though. I'm working on a lot
of other stuff first.







> Anyways, byuu, here's what I wrote of the OpenGL renderer so far, to
> prove its very much being worked on.




 Really cool! My only concern is the use of Win32-specific code
(header, GetForegroundWindow(), HDC stuff, setting up the pixel format
stuff) ... no idea how this is going to compile on Linux :(
               I don't know the Linux equivalents to all of the
Win32-specific stuff being done.

 Nonetheless, please take your time. I'll check it out when you have
the Win version finished. Thanks a million for making this :D







> What about guys like me who just stick to Intel HDA.




               Hah, I do the same. I'm not going to spend more on my
sound card than on my mainboard that comes _with_ onboard sound. HDA
sounds just fine to me :/

[No archive available]
2008-01-01 19:24:00 +00:00
byuu
f77aca7172 Update to bsnes v027r03? release.
I have a new WIP up. Again, this one has only source, as nothing has
changed on Windows since wip01.

 This time, I've just cleaned up the OSS and OpenAL drivers. Nach will
probably want to kill me, since by cleaned up, I mean "removed lots of
not-so-helpful comments and safety checks", but I intend to add them
back. Before v028, I'd like to have vai init() functions return a
boolean success value, and have bsnes continue to fall back on lesser
drivers until there are none left, in which case it won't use one. But
it will keep the program from crashing.

 Also, I tried some black magic on the OSS4 support. Because
soundcard.h is included in a different location than the OSS3 one, I
tried manually defining the new SNDCTL options and invoking ioctl
regardless of OSS version. This is supposed to be safe -- the ioctls
should just fail silently and it will behave just like OSS3. Let me
know if you have problems compiling or using the driver with OSS3,
especially on non-Linux boxen.

             > Will you update the readme with recommendations for
which sound driver to use on which system?

 I suppose I can do that. I was planning on writing up an article
about OSS4 and such, perhaps I can just link to that in the readme.

 > I changed it to set_background_color(0, 255, 0) and sure enough I
had a green statusbar. The main window background color was still
black though. Assuming that set_background_color() is meant to be used
for the main UI this is very odd.

 Okay, here's how this works. Inside the main window, there is a view
control, which is a gtk_drawing_area(). I draw the video to this. When
bsnes is in windowed mode, obviously this control fills the entire
window. And the view control draws a black background by default. But
when you go fullscreen, the view area centers itself on your screen
(or tries to, some issues in GTK+ size requests render it non-
perfect.) Now there's the problem that the window itself is exposed on
the sides. Therefore, I have to set the window background to black
here, otherwise it will show up gray, which is _very_ distracting in
fullscreen mode, to say the least.

 Now, I only tell GTK+ to set the window to black. The reason I do
this is because just setting the formcontainer to black has no effect,
since containers do not draw a background. As for why that is causing
your statusbar to render black ... good lord, I have no idea at all
o.O

 I don't know what to do to fix this, unfortunately ... but at least
we now know where the problem is so we can research it. Thank you very
much for tracking that down [vEX], I realize my request to have an
end-user look into that was unreasonable, but it's very much
appreciated.

 > EDIT2: After some testing it doesn't appear that bsnes was guilty.
I can't reproduce the memory consumption, but it could be all the
recompiling bsnes that somehow ate all my memory.

 bsnes does appear to have a tiny memory leak at the moment. It loses
about ~100k a minute on me. I'm not sure if it's specific to the Linux
port or not. This will certainly be a hard one to track down in such a
big program.

             > I believe OpenAL is pretty smart in frequency handling.

 Definitely. I don't really like complex APIs, but the buffering
system in OpenAL will actually come in handy. I failed with
DirectSound, but maybe with OpenAL I can manage to resample audio --
maybe even let OpenAL do the resampling for me by calculating the
frequency as a measure of "how many samples should have been created"
versus "how many actually were."

 That would be awesome. Combine that with OpenGL triple buffering, and
SDL/libjsw joypad support, and wow ... I'll have something really,
really usable :)

[No archive available]
2007-12-26 13:03:00 +00:00
byuu
c32195cbd6 Update to bsnes v027r02? release.
Okay, here's the deal with sound.

 wertigon's initial OpenAL driver was incomplete and produced no
audio, and _willow_'s had some Windows-specific bindings.

 So, Nach took those, some OpenAL sample code, and some other
application's OpenAL code and produced a working driver for it. Then
Nach and I refined the driver -- I got rid of the crashing on exit and
frequency changing, and both of us wrote new sample() functions.
Nach's is vastly superior on CPU resources, so we'll probably go with
that one.

               That code can be found here:
http://byuu.cinnamonpirate.com/temp/audio.openal.cpp

               This code wouldn't be possible without the help from
wertigon, _willow_ _and_ Nach, so many thanks to everyone, and I'm
sorry I wasn't able to go directly with anyone's specific OpenAL
driver. Linux compatibility was a big concern here. You'll all be
getting full credit in the source and documentation for bsnes v0.028.

               ---

 Now, as for the driver itself. It should work on Windows now with the
sample() and init() corrections, but maybe not. I don't have the means
at the moment to build a Windows binary with it, but maybe I can in
the future.

 But anyway, I don't intend to compile in OpenAL/Win support by
default with bsnes, but rather leave it as an option for those who
compile it themselves. Why? Because Windows does not come with
alut.dll and OpenAL32.dll. I don't want to require another download to
use bsnes, and I don't want to package an extra 300kb of DLLs with it
either. Plus, it doesn't seem to be working too well for most people
anyway thus far.

 Windows does come with DX9, and basically nobody has problems with
DirectSound. It's great, it has very low latency, and it seems to work
on everyone's sound cards, unlike the OpenAL stuff. So it's really not
needed for Windows.

               ---

 However, on Linux, OpenAL has a lot of good points. Unlike with
Linux/OSS3, OpenAL backends to ALSA which supports software mixing.
Meaning audacious and bsnes can run at the same time. And OpenAL has
much lower latency than libao, as well as the ability to disable speed
throttling when necessary.

               But! The OSS4 driver, with SND_DSP_COOKEDMODE,
absolutely _destroys_ even the OpenAL driver. In fact, it's even twice
as good as the DirectSound driver on Windows! No joke!

               From http://wiki.freebsd.org/RyanBeasley/ioctlref :






> ... this ioctl is meant to give processes direct access to the
> hardware buffer, giving the application the most control possible
> (ex: minimizing latency by avoiding in-kernel processing).




 With this, I get roughly ~15-20ms latency, at the very most, with
bsnes. It skips kernel processing entirely! It's hard to even describe
such a low latency. I've never heard Link's sword sound effect start
so quickly. It's really quite impressive. Remember when kode54 was
talking about ASIO or kmixer or whatever? That super low latency
kernel-level audio setup that bypasses the kernel and goes directly to
the sound card? This is it, but for Linux. It's that good.

 But the problem, of course, is Linux' obsession with ALSA, even
though OSS4 is GPLv2 now (and not to mention portable). ALSA is, of
course, total garbage. Anyone who's programmed for it knows that.

 It's very easy to install OSS4, download a DEB package, double click
it, hit install and reboot. But the problem is, many Linux distros try
their best to kill OSS now. Lots of apps are compiled by Linux distro
vendors to only support ALSA, so it does cause some problems, and you
have to reconfigure many apps to use OSS afterwards, so it's not a
very good solution to make bsnes default to the OSS driver.

 Further, because ALSA is so terrible, it causes the OpenAL driver
(which is really just a wrapper to ALSA here) to suck, and it causes
lots of static in the sound. And ALSA's OSS emulation causes severe
video lag -- bizarre, but it has something to do with the blocking
mechanism in ALSA. Only installing OSS4 fixes this. For both drivers,
in fact.

 So, because of ALSA's pathetically poor emulation of both OSS and
OpenAL, I can't default bsnes to either of these drivers. Therefore, I
have to leave the libao driver as the default, but I really recommend
the installation of OSS4 (if you haven't gotten that hint already) if
you really want the best audio possible, and don't mind losing a
couple of your favorite ALSA-only apps. If installing OSS4 is too much
of a plunge, then I still recommend experimenting with the OpenAL and
OSS (in that order) drivers under ALSA. If they work good, great. If
not, sorry, it isn't a problem with the bsnes drivers. You'll have to
stick with libao and it's terrible latency and forced blocking. Unless
someone else wants to write an ALSA driver. I have no intentions of
programming for yet another single-platform API, myself.

               ---

 With all of that said, I have a new WIP up. I'll send the link to any
Linux users who want to test it, as well. Feel free to ask.

               This WIP is source code _only_ (nothing changed on
Windows), and has both the new OpenAL and OSS drivers. Testing would
be greatly appreciated.

[No archive available]
2007-12-25 17:54:00 +00:00
byuu
161366df9b Update to bsnes v027r01? release.
I posted a new private WIP that adds the new statusbar. But much more
importantly, thanks to Nach, the Linux port now has an OSS driver.

             It's current set as the default. You can get ao again by
setting system.audio to, yep, you guessed it, "ao".

 Would some Linux users mind giving it a spin? For me, it appears to
be blocking and causing serious video lag (xv [XV_SYNC_TO_VBLANK=0] or
GTK+ video, 60hz monitor, speed regulation = normal). Not happening
for Nach ... it's quite possible the problem is just on my system.

 The complete and utter lack of perceived latency lag though, makes
this sound a million times better than the ao driver.

[No archive available]
2007-12-23 15:25:00 +00:00
byuu
4c43e85141 Update to bsnes v027 release.
This version replaces libui with miu -- a new GUI wrapper library, and cleans up large portions of the source code.
Unfortunately, the GUI rewrite took far, far longer than I ever imagined. As a result, no work has gone into the core emulation for this version. But with the GUI rewrite out of the way, that should change in the near future. And thanks to the new UI library, I can now begin work on adding a cross-platform debugger to bsnes, at long last.
Changelog:
    - Major source code cleanup (lib/, ui/miu/, ui/vai/)
    - Cheat code editor was broken in v0.026, this is now fixed
    - Cheat code file format simplified for human readability
    - Makefile install target improvements [belegdol]
    - libui replaced with miu GUI library
    - Custom video / audio / input drivers replaced with vai HW library
    - ppc and ppc64 libco targets added [Vas Crabb]
    - x86 and x86-64 libco targets now work on OS X [Lucas Newman]
2007-12-22 18:26:54 +00:00
byuu
9da42c18c3 Update to bsnes v026r04? release.
Another WIP. Consider this one v0.027 RC1.

             Bugs fixed:
 - cheat code editor works once again -- cart/ was not loading or
saving the files, and memory/ was not reading from it. Yeah, it was
completely broken in v0.026
 - miu/Win supports window.set_background_color(). The trick was to
capture WM_ERASEBKGND and use FillRect to draw the background myself.
 - miu/Win menubar toggle in fullscreen mode works as expected now for
me. Testing would be appreciated. A total shot in the dark, I tried
using SWP_FRAMECHANGED when resizing the windows, and it worked. It
seems to be an issue due to having two windows that are both set to
use the same menu (I have a hidden window I use for resize-purposes
only, because AdjustWindowRect doesn't work right on multi-line menus,
but the resize window is never visible.) I'm not sure exactly why
SWP_FRAMECHANGED fixed the problem, or why it wasn't needed in libui,
but it works, so I'll take it.
 - make install target uses "install" rather than cp+chmod, but
belegdol unfortunately removed his makefile patch, and I don't recall
where $(DESTDIR) and $(PREFIX) are supposed to go, so those aren't in
there yet ... belegdol, could you please repost that? You're of course
free to change my makefile with your packages as always in case it
gets missed before v027.

             Bugs remaining:
 - D3D renderer is still acting weird. If you start at 256x224 window
size, then the point video filter never works. If you resize to a
larger window and back to 256x224, the video image is linear filtered
no matter what. I tried to fix this tonight, but I had no luck. I'm
really not sure what's wrong, I don't think it's ever really worked
right. Should I fallback on the DDraw renderer for the next release?
It lacks the point filter mode (DDraw lacks an API to control mag
filtering), but that's it. Also, mudlord, PM me if I haven't given you
my WIP URL and you wanted to look at the latest stuff. I can never
remember who I gave the link to or not.
 - system.video / audio / input are not checked, so you get the
compiled defaults only. All vai drivers have now been ported, however.

             I changed the cheat code format. It is now:
             code = status, "description" \r\n

             Or for an example:
             7e1234:56 = enabled, "Infinite Lives"
             7e1235:67 = disabled, "Infinite Health"

 A little easier to read. But maybe still not perfect. I'd really like
to unify the .cht file format with other SNES emu devs ... I don't
want to use a binary file format like ZSNES and SNES9x does.

 I tried testing log audio data -- it seems to be working for me both
on Windows and Linux. FitzRoy, maybe the file isn't going to the
folder you are expecting? Or maybe I fixed it and didn't realize it?
Hmm ...

             Anything else I'm forgetting before a new release? Anyone
see any new / show stopping bugs?

[No archive available]
2007-12-20 10:43:00 +00:00
byuu
d115c7f6aa Update to bsnes v026r03? release.
Another WIP. This one builds on Windows and Linux, and the binary has
the terminal window disabled.

             Bugs fixed:
             - Added WM_ENTERMENULOOP message. Fixes audio looping for
the 37th time since I started on bsnes.
             - Esc toggles menu properly
 - F11 fullscreen centers, but only to the screen, not to the window
(meaning when the menubar is visible, it isn't really centered) --
this is because GTK+ does not return the correct widget size after
calling gtk_window_fullscreen() for up to ~200ms after processing all
messages via gtk_main_iteration_do(), and thus I can't make a
window.get_size() function. I really hope
GetSystemMetrics(SM_CXSCREEN) and gdk_screen_width() only return the
width of the active monitor, and not both for multi-monitor setups
 - Background of main window is black on Linux only. Only one
background brush per class for Windows. It may end up staying gray on
Windows for the next release ...
 - miu/Win enable/disable works. Even for menu items now, so I can
disable features that aren't supported by certain drivers now.

             Bugs remaining:
             - bsnes/Win background in fullscreen mode is gray --
quite ugly
             - D3D still blurring images even with perfect multiplier
             - cheat code editor still doesn't load .cht files on ROM
load

             New bugs:
             - bsnes/Win menubar is ultrafucked in fullscreen mode if
you toggle it on and off with esc. I have _no_ idea what the hell is
up with that. Code to show and hide the menu is identical to
libui/bsnes v026. Not sure I can fix this one. Basically, when the
menu gets toggled back on, clicking it does nothing, and if you press
alt, it will pop up the menu, but it will be _below_ the visible
menubar, so you end up seeing two of them. And you can only access the
new menubar via keyboard. Weird stuff ... could use some help here.
Anyone ever seen or heard of anything like this before?
             - I still need to work on that makefile cp+chmod ->
install thing for belegdol, I think ...

[No archive available]
2007-12-19 14:39:00 +00:00
byuu
2efce0fd83 Update to bsnes v026r02? release.
New WIP. Much, much closer to release quality. Linux port (probably)
won't compile at the moment due to minor changes to miu and vai. I
left the console enabled for this WIP.

             Bugs fixed:
             - Windows always appear at 0,0 instead of centered
 - Input capture window doesn't actually read anything. I actually can
get this working now, I just don't like the hacky way I did it before.
             - miu doesn't send Key events, so no F11 / esc shortcut
keys.
 - miu/Win is still missing some event messages, so some controls may
appear unresponsive. miu/Linux should be complete.
             - miu/Win may still send duplicate messages in some
cases, like that old log audio option bug was doing
             - miu lacks an on_show event, so the config window can't
set focus to the listbox on show just yet
 - bsnes will no longer crash when you try and load a GZ / ZIP / JMA
file with the support not built in (it obviously won't play the games
either) [Richard Bannister]

             Bugs remaining:
             - D3D still blurring image, haven't looked at it yet
 - Cheat code list never populates when loading ROM, probably doesn't
save either (I probably removed that code when rewriting cart/ and
memory/ a while back)
 - miu doesn't emit WM_ENTERMENULOOP, meaning audio cycles when going
into the menu. I wish there were a way to make it pre-emptive like
GTK+ without needing multiple threads ...

             New bugs:
             - Esc doesn't toggle menu yet
 - F11 fullscreen doesn't center, and window background is gray. This
will be tricky, as I only have one RegisterClass() in miu, but you can
only have one HBRUSH per class. Hopefully there's a window message I
can hijack to add back window.set_background_color().
             - miu/Win enable() / disable() doesn't work -- input
config dropdowns active, despite them not working yet

 Other than that, any new bug reports would be appreciated. I hope to
have v027 out by Sunday, but I may not make it in time.

[No archive available]
2007-12-18 12:29:00 +00:00
byuu
f6732133e7 Update to bsnes v026r01? release.
Alright, it's been a full month now since the last private WIP.

 I have Direct3D, DirectSound and DirectInput all working on the
Windows port now; and Xv, GTK+ Video, libao and XInput working on the
Linux port, so now's a good time for a beta.

             Note that countless things are broken, still.
             - D3D still blurring image, haven't looked at it yet
 - Cheat code list never populates when loading ROM, probably doesn't
save either (I probably removed that code when rewriting cart/ and
memory/ a while back)
             - Windows always appear at 0,0 instead of centered
 - miu doesn't emit WM_ENTERMENULOOP, meaning audio cycles when going
into the menu. I wish there were a way to make it pre-emptive like
GTK+ without needing multiple threads ...
 - Input capture window doesn't actually read anything. I actually can
get this working now, I just don't like the hacky way I did it before.
             - miu doesn't send Key events, so no F11 / esc shortcut
keys.
 - miu/Win is still missing some event messages, so some controls may
appear unresponsive. miu/Linux should be complete.
             - miu/Win may still send duplicate messages in some
cases, like that old log audio option bug was doing
             - miu lacks an on_show event, so the config window can't
set focus to the listbox on show just yet

             Any bugs outside of this that seem serious, please tell
me about. Otherwise, I'm working on the rest still :/

[No archive available]
2007-12-16 10:08:00 +00:00
byuu
95547f4ff8 Update to bsnes v026 release.
- Major source code cleanup
    - Completely rewrote memory mapper to support runtime MMCs
    - Updated S-DD1 MMC to use new memory mapping interface
    - Improved S-DD1 emulation, thanks to information from orwannon
    - Added support for SameGame -- load via "Load Special -> Load BS-X Slotted Cart" menu option
    - Completely rewrote cartridge loader to support BS-X, BS-X slotted carts and ST carts
    - Created custom dialog windows for multicart loading
    - Improved generic memory mapper, which eliminates the need for cart.db [Nach]
    - Added BS-X slotted cart detection to generic memory mapper [Nach]
    - Linux port will now ignore keypresses when window is inactive
    - Linux port will use much less CPU power when idle
    - Added detailed compilation instructions to Makefile for Linux port
    - Added "make install" target and PNG program icon for Linux port
    - Switched Windows compiler to MinGW/GCC4
    - Windows executable is now packed with UPX to decrease filesize
    - Removed .ufo, .gd7 and .078 ROM extensions; added .bs extension
    - Added preliminary support for the BS-X base unit, BS-X base cartridge + MMC, and BS-X flash I/O
2007-11-18 21:49:20 +00:00
byuu
4f5bdfe347 Update to bsnes v025r12? release.
New WIP is up.

 I fixed PSRAM size, it's now 512kbytes. SRAM was correct before at
32kbytes. I also now save these files to "bsxbios.psr" (PSRAM) and
"bsxbios.srm" (SRAM). I honestly don't know if the PSRAM is supposed
to be battery backed or not. If it's not, it'll be easy enough to
remove. I imagine it is, because that's where you'd store your games
on if you lacked a flash cart. Would be pretty lousy to have it wiped
every time you power cycle.

 I also save the PSRAM+SRAM data only once, just as a real BS-X cart
would work, and it also makes the Ancient Tablets series work with no
file renaming needed. I may add an option later to save these files
separately per-game.

 BS-X support overall is still pitiful. bs-x.txt doc says $03 has to
be set to mirror PSRAM, SNES9x thinks it needs to be clear. Neither
know whether it affects just $60-6f or also $70-77. bs-x.txt doesn't
say to mirror hi/lo on PSRAM based on $02 setting, but SNES9x seems to
try it. LoROM doesn't map well into 64k granularity banks. Still don't
emulate $0c/$0d flash i/o register enable. Base unit is still
completely unsupported, and it's apparently needed for some games. And
I have no intentions of including an internal database of times to
manually hack the clock (even while the system is running!) ala
SNESGT. I'm just going to map the BS-X base unit RTC to the PC clock.
Some stuff like Dragon Slayer Eiyuu Densetsu work fine under regular
mapping, yet don't work with BS-X mapping. No idea why. Still don't
hack-enable headers during load, so that has to be done manually still
(do this if the game doesn't show up in cart menu. Make a backup if
you care.)

 Added SameGame support. Load it with "Load BS-X Slotted Cartridge"
(that's what it is, after all.) Unfortunately, I don't know what the
memory map is supposed to be, so the add-on cart doesn't appear to be
working. Or maybe I just can't figure out how to tell.
 Nach or anyone else, would you mind sharing that info with me? The
code in SNES9x looks identical to what I have, but loading the FEoEZ
512kbyte cart doesn't seem to do anything. Well, at least the game
itself works under this menu option now.

 Fixed config::path.save, and added realpath() for the Linux port, so
./ paths work too. Of course it won't be useful at all if you
"install" bsnes to /usr/bin, but if you keep it in its own folder,
it's helpful.

 Fixed the SRAM mapping bug affecting Fire Emblem 776. Also optimized
the file loading stuff a little more, removing a couple redundant ROM
memcpy's. Still far from perfect.

             If possible, please test this WIP a lot. I'd like to post
a new public release this weekend.

[No archive available]
2007-11-17 10:09:00 +00:00
byuu
49b0bed1a6 Update to bsnes v025r11? release.
New WIP up. Has a Windows binary this time.

 I completed the BSX cart MMIO registers. It definitely doesn't work
too well. For one, I don't override the header bit in the emulator, so
anyone testing will have to modify the bit as discussed first. It also
doesn't work on my only other BS game, BS Dragon Quest. I don't know
why, it throws a St. GIGA error (09). Maybe it needs base unit
emulation ... who knows. There's probably bugs in the cart and flash
reg support, too.







> My notes on the subject tell me it's the year of download or'd with
> other data. I haven't entirely figured out everything it's or'd with
> though.




 Well, Lancer said the BIOS makes sure d15 of $ffd5,$ffd4 is not set.
If it is, the game does not appear in the list of games you can start.
I'm guessing certain (all?) games expired after a certain date. If
that's true, then we're quite fortunate that only a header bit was
set, rather than the entire cart erased. So then, most likely all of
these games with $80 in $ffd5 appeared "blank", but were dumped and
the games retrieved.

 Sigh, such a sad fate. Really makes you wonder why Nintendo hates
their fanbase so much to go out of their way to destroy these games.

[No archive available]
2007-11-15 10:43:00 +00:00
byuu
1554170312 Update to bsnes v025r10? release.
Yeah, even if we still don't have the S-DD1 100% understood, we can at
least get all known software working properly. And now we at least
have all the registers understood, just the edge cases that need to be
tested. I'm honestly glad I was incorrect in that the original patch
worked on hardware. Given it will never be updated again, this means I
won't have to get bug reports from now unto infinity about it.

 I posted a new binary WIP. If anyone wants to play through a few
levels of SFA2 or dungeons in SO and look for corrupted graphics, it'd
be appreciated. I'm sure it'll be fine, though. Oh, and the speedhit I
reported a few days ago was wrong. The old builds ran at the same
speed. Seems I have a ~6-8fps variance in that game per reboot.

 New WIP also starts the BS-X mapping. You can map in a cart now, but
it immediately freezes because the flash I/O registers do not respond.

             ---

             Also, I'd like to get serious about emulating the
SPC7110. But to do that, I need custom-made hardware.

 I asked someone about this already, but I may as well throw it out
there publicly in case anyone else would like to help.

             Here is the PCB for one of the SPC7110 games:
             http://nsrt.edgeemu.com/INFO/chip-pix/SPC7110.JPG

 What I would need is for the top two ICs to be desoldered, and socket
IC connectors to be placed on them instead. I would also obviously
need lots of compatible EEPROMs to connect to it (just two would
suffice, more would be better as it's quite possible I'd wear out the
write cycles with lots of intense testing, or bend up the pins like I
usually do when removing socket ICs).

             I would also need software+hardware to actually flash the
EEPROMs, as I don't have anything like this presently.

 More complex solutions, such as a ROM emulator with a parallel/USB
interface to the PC would be acceptable as well. So long as it's
something I can reprogram at my relatively low skill level.

 One cart would suffice, but again, the more carts the better in case
of failure. And I'd also like to see about sending one to another
person who's been interested in the SPC7110 for a while. So, three or
four preferred.

             I can supply the cartridges and money for time +
shipping. I'd prefer someone who _knows_ they can do this well try, so
that we don't ruin any unnecessary cartridges and so that the test
cartridges are as durable as possible. Especially since they most
likely won't be encased anymore.

             So, any takers?

[No archive available]
2007-11-13 16:08:00 +00:00
byuu
ec137d6fb9 Update to bsnes v025r09? release.
I posted a new WIP last night. No binary this time,
sorry.
 It redoes the memory mapping of the cartridge and moves it into the
cartridge class -- forking each slotted cart away from the base cart
memory.
 This allows me to determine the proper sizes for each individual cart
again, so I can now map RPG Tsukuru II again correctly.

               EDIT:

               Ahahahahahah!! Finally! I figured out how the S-DD1
$4800 and $4801 registers work! :D

               Original game transfer (should transfer
compressed->decompressed):







    CC2418 LDA #$4000 A:00DA X:F458 Y:1C00 S:01FA DB:00 D:0000 P:01 e
                       CC241B PEA $00DB [0000DB] A:4000 X:F458 Y:1C00
    S:01FA DB:00 D:0000 P:01 e
                       CC241E LDX #$E8ED A:4000 X:F458 Y:1C00 S:01F8
    DB:00 D:0000 P:01 e
                       CC2421 LDY #$0800 A:4000 X:E8ED Y:1C00 S:01F8
    DB:00 D:0000 P:81 e
                       CC2424 JSR $2470 [CC2470] A:4000 X:E8ED Y:0800
    S:01F8 DB:00 D:0000 P:01 e
                       CC2470 STA $2116 [002116] A:4000 X:E8ED Y:0800
    S:01F6 DB:00 D:0000 P:01 e
                       CC2473 SEP #$20 A:4000 X:E8ED Y:0800 S:01F6
    DB:00 D:0000 P:01 e
                       ;* enable $4800 *
                       CC2475 LDA #$01 A:4000 X:E8ED Y:0800 S:01F6
    DB:00 D:0000 P:21 e
                       CC2477 STA $4800 [004800] A:4001 X:E8ED Y:0800
    S:01F6 DB:00 D:0000 P:21 e
                       CC247A LDA #$09 A:4001 X:E8ED Y:0800 S:01F6
    DB:00 D:0000 P:21 e
                       CC247C STA $4300 [004300] A:4009 X:E8ED Y:0800
    S:01F6 DB:00 D:0000 P:21 e
                       CC247F LDA #$18 A:4009 X:E8ED Y:0800 S:01F6
    DB:00 D:0000 P:21 e
                       CC2481 STA $4301 [004301] A:4018 X:E8ED Y:0800
    S:01F6 DB:00 D:0000 P:21 e
                       CC2484 STX $4302 [004302] A:4018 X:E8ED Y:0800
    S:01F6 DB:00 D:0000 P:21 e
                       CC2487 LDA $03,S [0001F9] A:4018 X:E8ED Y:0800
    S:01F6 DB:00 D:0000 P:21 e
                       CC2489 STA $4304 [004304] A:40DB X:E8ED Y:0800
    S:01F6 DB:00 D:0000 P:A1 e
                       CC248C STY $4305 [004305] A:40DB X:E8ED Y:0800
    S:01F6 DB:00 D:0000 P:A1 e
                       CC248F LDA #$01 A:40DB X:E8ED Y:0800 S:01F6
    DB:00 D:0000 P:A1 e
                       CC2491 STA $4801 [004801] A:4001 X:E8ED Y:0800
    S:01F6 DB:00 D:0000 P:21 e
                       CC2494 PHA A:4001 X:E8ED Y:0800 S:01F6 DB:00
    D:0000 P:21 e
                       CC2495 PLA A:4001 X:E8ED Y:0800 S:01F5 DB:00
    D:0000 P:21 e
                       CC2496 STA $420B [00420B] A:4001 X:E8ED Y:0800
    S:01F6 DB:00 D:0000 P:21 e
                       CC2499 STZ $4800 [004800] A:4001 X:E8ED Y:0800
    S:01F6 DB:00 D:0000 P:21 e
                       CC249C REP #$20 A:4001 X:E8ED Y:0800 S:01F6
    DB:00 D:0000 P:21 e
                       CC249E RTS A:4001 X:E8ED Y:0800 S:01F6 DB:00
    D:0000 P:01 e




               Custom transfer (should transfer
decompressed->decompressed):







    CC2428 LDA #$5008 A:00DB X:E8ED Y:0800 S:01FA DB:00 D:0000 P:01 e
                       CC242B PEA $00E9 [0000E9] A:5008 X:E8ED Y:0800
    S:01FA DB:00 D:0000 P:01 e
                       CC242E LDX #$0400 A:5008 X:E8ED Y:0800 S:01F8
    DB:00 D:0000 P:01 e
                       CC2431 LDY #$04E0 A:5008 X:0400 Y:0800 S:01F8
    DB:00 D:0000 P:01 e
                       CC2434 JSR $244C [CC244C] A:5008 X:0400 Y:04E0
    S:01F8 DB:00 D:0000 P:01 e
                       CC244C STA $2116 [002116] A:5008 X:0400 Y:04E0
    S:01F6 DB:00 D:0000 P:01 e
                       CC244F SEP #$20 A:5008 X:0400 Y:04E0 S:01F6
    DB:00 D:0000 P:01 e
                       ;* disable $4800 *
                       CC2451 STZ $4800 [004800] A:5008 X:0400 Y:04E0
    S:01F6 DB:00 D:0000 P:21 e
                       ;* $43x0.d3 (fixed transfer flag) is irrelevent
    to S-DD1 *
                       ;* can be #$01 or #$09 here *
                       CC2454 LDA #$09 A:5008 X:0400 Y:04E0 S:01F6
    DB:00 D:0000 P:21 e
                       CC2456 BRA $247C [CC247C] A:5009 X:0400 Y:04E0
    S:01F6 DB:00 D:0000 P:21 e
                       CC247C STA $4300 [004300] A:5009 X:0400 Y:04E0
    S:01F6 DB:00 D:0000 P:21 e
                       CC247F LDA #$18 A:5009 X:0400 Y:04E0 S:01F6
    DB:00 D:0000 P:21 e
                       CC2481 STA $4301 [004301] A:5018 X:0400 Y:04E0
    S:01F6 DB:00 D:0000 P:21 e
                       CC2484 STX $4302 [004302] A:5018 X:0400 Y:04E0
    S:01F6 DB:00 D:0000 P:21 e
                       CC2487 LDA $03,S [0001F9] A:5018 X:0400 Y:04E0
    S:01F6 DB:00 D:0000 P:21 e
                       CC2489 STA $4304 [004304] A:50E9 X:0400 Y:04E0
    S:01F6 DB:00 D:0000 P:A1 e
                       CC248C STY $4305 [004305] A:50E9 X:0400 Y:04E0
    S:01F6 DB:00 D:0000 P:A1 e
                       CC248F LDA #$01 A:50E9 X:0400 Y:04E0 S:01F6
    DB:00 D:0000 P:A1 e
                       CC2491 STA $4801 [004801] A:5001 X:0400 Y:04E0
    S:01F6 DB:00 D:0000 P:21 e
                       CC2494 PHA A:5001 X:0400 Y:04E0 S:01F6 DB:00
    D:0000 P:21 e
                       CC2495 PLA A:5001 X:0400 Y:04E0 S:01F5 DB:00
    D:0000 P:21 e
                       CC2496 STA $420B [00420B] A:5001 X:0400 Y:04E0
    S:01F6 DB:00 D:0000 P:21 e
                       CC2499 STZ $4800 [004800] A:5001 X:0400 Y:04E0
    S:01F6 DB:00 D:0000 P:21 e
                       CC249C REP #$20 A:5001 X:0400 Y:04E0 S:01F6
    DB:00 D:0000 P:21 e
                       CC249E RTS A:5001 X:0400 Y:04E0 S:01F6 DB:00
    D:0000 P:01 e




               Original transfer right after custom transfer:







    CC2438 LDA #$4000 A:00E9 X:0400 Y:04E0 S:01FA DB:00 D:0000 P:01 e
                       CC243B PEA $00DC [0000DC] A:4000 X:0400 Y:04E0
    S:01FA DB:00 D:0000 P:01 e
                       CC243E LDX #$E0E8 A:4000 X:0400 Y:04E0 S:01F8
    DB:00 D:0000 P:01 e
                       CC2441 LDY #$1080 A:4000 X:E0E8 Y:04E0 S:01F8
    DB:00 D:0000 P:81 e
                       CC2444 JSR $2458 [CC2458] A:4000 X:E0E8 Y:1080
    S:01F8 DB:00 D:0000 P:01 e
                       CC2458 STA $2181 [002181] A:4000 X:E0E8 Y:1080
    S:01F6 DB:00 D:0000 P:01 e
                       CC245B SEP #$20 A:4000 X:E0E8 Y:1080 S:01F6
    DB:00 D:0000 P:01 e
                       CC245D LDA #$7F A:4000 X:E0E8 Y:1080 S:01F6
    DB:00 D:0000 P:21 e
                       CC245F STA $2183 [002183] A:407F X:E0E8 Y:1080
    S:01F6 DB:00 D:0000 P:21 e
                       CC2462 LDA #$01 A:407F X:E0E8 Y:1080 S:01F6
    DB:00 D:0000 P:21 e
                       ;* $4800 enabled again *
                       CC2464 STA $4800 [004800] A:4001 X:E0E8 Y:1080
    S:01F6 DB:00 D:0000 P:21 e
                       CC2467 LDA #$08 A:4001 X:E0E8 Y:1080 S:01F6
    DB:00 D:0000 P:21 e
                       CC2469 STA $4300 [004300] A:4008 X:E0E8 Y:1080
    S:01F6 DB:00 D:0000 P:21 e
                       CC246C LDA #$80 A:4008 X:E0E8 Y:1080 S:01F6
    DB:00 D:0000 P:21 e
                       CC246E BRA $2481 [CC2481] A:4080 X:E0E8 Y:1080
    S:01F6 DB:00 D:0000 P:A1 e
                       CC2481 STA $4301 [004301] A:4080 X:E0E8 Y:1080
    S:01F6 DB:00 D:0000 P:A1 e
                       CC2484 STX $4302 [004302] A:4080 X:E0E8 Y:1080
    S:01F6 DB:00 D:0000 P:A1 e
                       CC2487 LDA $03,S [0001F9] A:4080 X:E0E8 Y:1080
    S:01F6 DB:00 D:0000 P:A1 e
                       CC2489 STA $4304 [004304] A:40DC X:E0E8 Y:1080
    S:01F6 DB:00 D:0000 P:A1 e
                       CC248C STY $4305 [004305] A:40DC X:E0E8 Y:1080
    S:01F6 DB:00 D:0000 P:A1 e
                       CC248F LDA #$01 A:40DC X:E0E8 Y:1080 S:01F6
    DB:00 D:0000 P:A1 e
                       CC2491 STA $4801 [004801] A:4001 X:E0E8 Y:1080
    S:01F6 DB:00 D:0000 P:21 e
                       CC2494 PHA A:4001 X:E0E8 Y:1080 S:01F6 DB:00
    D:0000 P:21 e
                       CC2495 PLA A:4001 X:E0E8 Y:1080 S:01F5 DB:00
    D:0000 P:21 e
                       CC2496 STA $420B [00420B] A:4001 X:E0E8 Y:1080
    S:01F6 DB:00 D:0000 P:21 e
                       CC2499 STZ $4800 [004800] A:4001 X:E0E8 Y:1080
    S:01F6 DB:00 D:0000 P:21 e
                       CC249C REP #$20 A:4001 X:E0E8 Y:1080 S:01F6
    DB:00 D:0000 P:21 e
                       CC249E RTS A:4001 X:E0E8 Y:1080 S:01F6 DB:00
    D:0000 P:01 e




 I was completely wrong, and was thrown off by ZSNES' memory remapping
magic that worked due to an oversight with $43x0.d3, or the fixed
transfer flag. I never added a check for the fixed transfer flag
because it quite honestly made no sense. Why would the S-DD1 care
about that?

               Turns out, it doesn't. What really matters is $4800.
The register everyone currently ignores completely.

               I figured out what purpose it serves: it's a sticky
toggle, whereas $4801 is a loose toggle.

 It works like this: in order for the S-DD1 to decompress a DMA
transfer, both $4800 and $4801 have to be set. Upon completion of the
transfer, $4801 is cleared. But $4800 is not.

 If you look at the above logs, it becomes clear. And it's all
contained inside the S-DD1 code. It has nothing to do with $43x0.

 Now, how can I verify this? orwannon made a flash cart for Star Ocean
and ran my old title screen patch on it. Sure enough, it did not try
and decompress the graphics data, despite the fixed transfer flag
being set. That tells us that the fixed transfer flag has nothing to
do with this.

 What's interesting is that every single S-DD1 supporting emulator
works just fine with my title screen patch. Meaning that they've all
implemented these two registers wrong.

 What was also interesting is that it's supposedly been confirmed that
the patched SO works on real hardware. That means the bug was in bsnes
after all. No excuses, I was flat out wrong. My sincere apologies.

 I've added the above changes, and bsnes now works with the original
patch, and fails with my custom patch. This mimics the behavior of
real hardware.

 Huge thanks to orwannon for the screenshot of my patch running on
real hardware. This fix wouldn't have been possible without that.

[No archive available]
2007-11-12 21:52:00 +00:00
byuu
aee683a475 Update to bsnes v025r08? release.
New WIP up.

 I spent four hours completely rewriting everything but the generic
header parsing code in src/cart. I'm now happy with the code both in
src/memory and src/cart. Hoorah.

 With the new load_cart() functionality, I made the "Load Special"
menu entries functional. For those of you stuck on Windows or without
WIP access, you can see how nice the load menus look on Linux below :)

             http://byuu.cinnamonpirate.com/bsnes/images/ui_bsx.png
             http://byuu.cinnamonpirate.com/bsnes/images/ui_st.png

 There is one bug: because of the way I map the slotted carts into one
contigious chunk of ROM (and hence update the size accordingly), it
throws off the memory mirroring on some of the BS-X slotted cart games
(like RPG Tsukuru II). I need to work on that a bit. For now, you can
play it through the normal load cartridge menu option.

 And of course, there's still that annoying Windows issue where the
main window steals focus after loading a ROM. Haven't looked into that
yet.

 And I still need to rework the file extension stuff per previous
discussions. It'd be nice to have the BS-X / ST windows only show .bs
/ .st ROMs by default.

[No archive available]
2007-11-05 07:22:00 +00:00
byuu
cdbf07b642 Update to bsnes v025r07? release.
Ok, posted the new WIP with the LoROM map corrections. This one also
modified the load special menu. They now bring up a new window that
lets you select the base cart + slot cart(s). However, the menus do
not work yet. There's also some odd issue that it loses focus when you
select a ROM from the browse button, but only on Windows. Hitting load
just hides the window. I also need to add code to automatically load /
save the BIOS filenames where applicable.

Also, forgot to mention last time, but I added a new config file
option, cpu.wram_initial_value or something like that. It's purpose
should be pretty obvious.

[No archive available]
2007-11-04 11:36:00 +00:00
byuu
8a857dada3 Update to bsnes v025r06? release.
Ok, new WIP up. Pretty much all of the credit goes to others, this
time.

             Changelog:
             - I forgot to set the region, so PAL games were running
as NTSC; this is fixed
             - Added Nach's BS-X slotted flashcart detection (added
his Ys'3 SRAM detection earlier)
 - Used BSC-1A7M-10 PCB mapper from Overload's documentation for the
generic BS-X slotted cart games; Derby Stallion '96, Sound Novel
Tsukuru and RPG Tsukuru II are all playable once again; hopefully the
rest of the slotted games work, too (sans the SA-1 game(s)). Please
test if you can
 - Added krom's (and I suppose Nach's earlier submitted) MinGW32 icon
support; so FitzRoy's wonderful icon is there now on the EXE -- still
need to add it to the window titlebar (easy on Windows), and to Linux
in general, ugh
 - Removed win-mingw4-lui target, simplifying Makefile. Use win-mingw-
lui now. Thanks again to krom's suggestion to just copy the MinGW4
-sjlj files, that worked great
             - Some more cleanup work to src/cart. Still a lot to go
here.

 Everything that was playable in the last release should now be
playable, excepting Yoshi's Island music. Please let me know if
anything is broken that wasn't before now.

 As always, I'm really thankful to everyone for their contributions.
My program would be useless if not for all the help I've gotten from
everyone else.

             ---

 Now then, I aim to support those BS-X slotted cart games as well. But
one thing I did not know until today was that you could actually
exchange those carts between games. That ruins the model I planned to
use for them (eg make romname.smc -> romname.bsf files).

 Thinking about it -- I really need to completely redesign file
loading. BS-X and Sufami Turbo stuff really throws off the "Load ROM"
paradigm that is so popular amongst emulators.

 I'm thinking ... remove the "Load Special" menu completely. Modify
the main ROM loading routine to parse what exactly is being loaded.

 If it's a BS-X slotted cart, pop up a menu that lets one optionally
select to load an additional flash cart, or cancel the menu to load
nothing in the slot. This won't be hot-swappable in-game.

 If it's a Sufami Turbo cart, assume Slot A for the cart. If this game
supports dual slotting*, pop up an additional menu to select the Slot
B game, which can also be left empty. (* perhaps popup the menu no
matter what, to more closely simulate that with real hardware, you
could stick incompatible games in both slots anyway?)

             Same deal for Same Game, G-Next, and all that other crap,
if or whenever I end up supporting those.

 I think it's best to keep the BIOS stuff in the config file, rather
than giving an optional popup menu to modify which BIOS to load. The
reason being that it will allow direct loading of BS-X games with no
need to ever show a popup menu.

 Lastly, I will have to add a new Misc menu option to generate empty
BS-X flashcart files. Though it's really easy to make one, I imagine
end users might have trouble doing that.

             Ideas or suggestions welcome.

[No archive available]
2007-11-02 09:30:00 +00:00
byuu
ab1975a6cb Update to bsnes v025r05? release.
I mentioned that it wasn't there. Exact reason was because I reloaded
Ubuntu and Windows, and I really hate installing Visual C++. It takes
forever. I posted a new WIP, and built it with MinGW4. Need to figure
out how to get the icon into the binary with MinGW.

             Anyway, new stuff in the WIP:

 - Much, much faster mirror() function; thanks to lots of help from
Nach (doesn't speed anything up, but might help with BS-X MMIO
registers)
             - Removed cart.db and all database-related code, now that
Ys3 works
             - Lots of code cleanups everywhere
             - New help information for trying to run ./configure or
make by itself
             - Cheap temporary MinGW fix for non-C99 vsnprintf

 The BS-X slot games (Derby Stallion et al) won't work on this
release. Nach gave me the code to detect those, and I'll get that
mapper in eventually before the next release. Also, Yoshi's Island
won't play audio anymore most likely.

 If anything else is broken, it's due to mapping. Please let me know
so I can fix it. If there are more than three broken games, that's
good -- please don't overwhelm me with a list of 500+ broken games in
the morning :)

             EDIT: fixed the Windows issues I was having. The Realtek
HD Audio driver software is fucking stupid. You _have_ to unplug your
speakers, reconnect them, and then select line out (rather than the
option for speakers) to get audio. This is the _only_ way to get
audio. And apparently both regular Winamp (without visualization) and
Mozilla Firefox now need DEP turned off not to crash the fuck all over
themselves constantly. Wonderful.

 EDIT2: forgot to set the region, so PAL games will run as though they
are NTSC. Most will probably give you an error splash screen. I'll fix
that.

[No archive available]
2007-10-31 10:18:00 +00:00
byuu
476a1c819a Update to bsnes v025r04? release.
New WIP up. This one's a bit better than last, but I
don't want bug reports yet. This one only maps generic LoROM and HiROM
games.

 Took about four or five hours, but I reworked most of the new memory
mapper yet again. SRAM should be working now, and I managed to gain
back the speed lost by dropping the address masking and forcing Visual
C++ to inline (__forceinline). The masking was no good anyway, because
the ROM file loaded in is definitely not always a power of two, which
means I'd have to use modulus and holy fuck no I'm not adding a
division for every memory access.

 The old memory mapper didn't have this either, as it stored a bunch
of pointers into memory chunks. The new one just stores one pointer
plus integer offsets into that pointer (a bit slower but cleaner and
necessary for abstraction), so it's really mostly the same thing.

 Man, I was looking at my old generic LoROM / HiROM mapper, and the
difference from that and what I have now is astounding ... it would
seem I've certainly gotten better at programming since then.







    /* new */
                       void sBus::map_generic() {
                       switch(cartridge.info.mapper) {
                       case Cartridge::LOROM: {
                       map(MapLinear, 0x00, 0x3f, 0x8000, 0xffff,
    memory::rom);
                       map(MapLinear, 0x80, 0xbf, 0x8000, 0xffff,
    memory::rom);
                       map(MapLinear, 0x40, 0x7f, 0x0000, 0xffff,
    memory::rom);
                       map(MapLinear, 0xc0, 0xff, 0x0000, 0xffff,
    memory::rom);
                       } break;
                       case Cartridge::HIROM: {
                       map(MapShadow, 0x00, 0x3f, 0x8000, 0xffff,
    memory::rom);
                       map(MapShadow, 0x80, 0xbf, 0x8000, 0xffff,
    memory::rom);
                       map(MapLinear, 0x40, 0x7f, 0x0000, 0xffff,
    memory::rom);
                       map(MapLinear, 0xc0, 0xff, 0x0000, 0xffff,
    memory::rom);
                       } break;
                       }

                       if(memory::sram.size() == 0) { return; }
                       map(MapLinear, 0x20, 0x3f, 0x6000, 0x7fff,
    memory::sram);
                       map(MapLinear, 0xa0, 0xbf, 0x6000, 0x7fff,
    memory::sram);
                       map(MapLinear, 0x70, 0x7f, 0x0000, 0x7fff,
    memory::sram);

                       if(cartridge.info.mapper != Cartridge::LOROM) {
    return; }
                       map(MapLinear, 0xf0, 0xff, 0x0000, 0x7fff,
    memory::sram);
                       }

                       /* old */
                       void bMemBus::cart_map_generic(uint type) {
                       uint rom_size = cartridge.info.rom_size;
                       uint ram_size = cartridge.info.ram_size;

                       for(uint page = 0x0000; page <= 0xffff; page++)
    {
                       if(memory_type(page << 8) !=
    TYPE_CART)continue;

                       uint addr = page << 8;
                       uint bank = page >> 8;

                       //RAM mapping is incorrect in several games,
    this is the most compatible
                       //layout I can create using only ROM header
    information. Additional accuracy
                       //requires PCB identification.

                       //Unmapped region
                       //$[00-1f|80-9f]:[6000-7fff]
     if((bank & 0x7f) >= 0x00 && (bank & 0x7f) <= 0x1f && (addr &
    0xe000) == 0x6000) {
                       continue;
                       }

                       //HiROM RAM region
                       //$[20-3f|a0-bf]:[6000-7fff]
     if((bank & 0x7f) >= 0x20 && (bank & 0x7f) <= 0x3f && (addr &
    0xe000) == 0x6000) {
                       if(ram_size == 0)continue;

                       addr = ((bank & 0x7f) - 0x20) * 0x2000 + ((addr
    & 0xffff) - 0x6000);
                       addr %= ram_size;
                       page_handle[page] = cartridge.ram + addr;
                       page_read [page] = &bMemBus::read_ram;
                       page_write [page] = &bMemBus::write_ram;
                       continue;
                       }

                       //LoROM RAM region
                       //$[70-7f|f0-ff]:[0000-7fff]
                       //Note: WRAM is remapped over
    $[7e-7f]:[0000-ffff]
     if((bank & 0x7f) >= 0x70 && (bank & 0x7f) <= 0x7f && (addr &
    0x8000) == 0x0000) {
                       if(!(bank & 0x80) || type == Cartridge::LOROM)
    {
                       //HiROM maps $[f0-ff]:[0000-7fff] to ROM
                       if(ram_size == 0)continue;

                       addr = ((bank & 0x7f) - 0x70) * 0x8000 + (addr
    & 0x7fff);
                       addr %= ram_size;
                       page_handle[page] = cartridge.ram + addr;
                       page_read [page] = &bMemBus::read_ram;
                       page_write [page] = &bMemBus::write_ram;
                       continue;
                       }
                       }

                       //ROM region
                       switch(type) {

                       case Cartridge::LOROM: {
                       addr = (bank & 0x7f) * 0x8000 + (addr &
    0x7fff);
                       addr = mirror(rom_size, addr);
                       } break;

                       case Cartridge::HIROM: {
                       addr = mirror(rom_size, addr);
                       } break;

                       }

                       page_handle[page] = cartridge.rom + addr;
                       page_read [page] = &bMemBus::read_rom;
                       page_write [page] = &bMemBus::write_rom;
                       }
                       }




 Note that those two certainly aren't identical in function, and I'll
no doubt have some memory mapping bugs again (probably with Final
Fight, SFII and such), but it should only require minor changes to fix
that.







> byuu: is it possible there's supposed to be steam appearing there to
> create the illusion, but isn't?




               That's a lot more likely, honestly. Hopefully someone
can make it to level 5, heh. I know I sure as hell can't.

[No archive available]
2007-10-18 09:40:00 +00:00
byuu
42d3f2a37f Update to bsnes v025r03? release.
New WIP up, and this one is _not_ for playing games on.

 I replaced the memory mapper entirely with a new system that should
be infinitely easier to remap dynamically. This is a necessary step
for BS-X MMIO register emulation. It should also speed up S-DD1
emulation by eliminating the need for a special address conversion
routine to simulate its memory mapper.

 However, the new bus memory mapper is anything but complete. Right
now, it only loads really, really basic LoROM games. Stick to Super
Mario World and Zelda 3.

 Some good news is that it's ~1-2% faster with MinGW4, but the bad
news is that it's ~10% slower with Visual C++, and MS' compiler is
stupidly storing my 128kb array directly into the EXE, making the file
size bigger. And yet the ZIP of the whole thing is smaller! >_<

 Bah. I think I can fine tune most of the performance lost back out of
Visual C++ with some forced inlining, and I'll make that WRAM array
allocate at runtime.

 Surprised I was able to get any games playable in less than three
hours, replacing the entire memory mapping system like that. Lucky me.







> -O8 -mtune=prescott -ffloat-store -fforce-addr -finline-functions
> -fexpensive-optimizations -funroll-all-loops -ffast-math -fomit-
> frame-pointer




 I didn't realize you could go above -O3 ... interesting. If you want,
try building with profile guided optimizations for another ~15% speed
boost. It's pretty unstable like that, though. Maybe you'll have
better luck than me.

               The warning message is in src/cart/cart_file.cpp at the
top.

[No archive available]
2007-10-17 04:51:00 +00:00
byuu
c58e3af1b5 Update to bsnes v025r02? release.
Alright, posted a new WIP with the BS-X skeleton. The
BIOS needs to be named bsxbios.bin, and it can't have a header.

 There's also "Load Special -> Load BS-X Cartridge ...", but it
doesn't work yet. It maps the flash cart into $[c0-ff]:[0000-ffff],
but that doesn't do much good. The BIOS then detects the flash cart
and starts probing the memory mapping registers and eventually
deadlocks.

               To emulate the MMIO registers, I will have to
_completely_ rework my memory mapping code to support dynamic
remapping. Not necessarily a bad thing, I was planning to rewrite all
of that anyway (per my diagram yesterday). Might as well kill two
birds with one stone.

 Gonna take at least a few days of planning before I go at that. I
want to get it right this time, so I don't have to do this again.

               In the meantime, have fun walking around the dead St.
GIGA ghost town ;)







> Byuu, that's some sweet ass shiz. You are a man on a mission this
> week. Let me know when you feel you've supported it enough to remove
> it from the list.




 Yeah, not sure what's up. I rarely have motivation to do anything
anymore, but it always comes in bursts. So I'll take advantage of it
now, and hope it doesn't burn out soon.

 I've a long way to go with BS-X before we can remove it, sadly. I
think we can remove when I get >50-75% of games loading. I doubt we
can reach 100%. There's missing info, corrupted / hacked BS ROMs
galore, and I don't even have BS-X hardware to test with.







> byuu, you always show something cool in a new version RIGHT after
> your official releases




 Sorry about that, it's not intentional. The thing is that no BS-X
games are even playable yet. I suppose when it's stable, I'll post
another public version, assuming the core is still stable with all the
plans I have for it.







> I really enjoy following your development of bsnes. I can't wait for
> the day I have a computer that is actually fast enough to play games
> with it (I'm currently using an Athlon 1.1 GHz).




               Sorry about that :(

               ---

 Side note: I also posted v0.025a, which removes the warning message
when SRM files don't exist. Nothing else is different, though.

[No archive available]
2007-10-16 05:50:00 +00:00
byuu
8226e243b8 Update to bsnes v025a release.
My apologies, I added code to display an alert when the Sufami Turbo BIOS was not present at the last minute before the recent release. What I failed to realize was that I added the alert to the same routine that loads save RAM files. Meaning that whenever one loads a game that has not yet created a .srm file, one will get a warning that the save RAM file does not exist. Oops.
You'll never see the warning more than once, and it's harmless, but for those it annoys, and for people who haven't upgraded yet, I've posted bsnes v0.025a. This version changes absolutely nothing other than disabling the warning box in question. I'll be sure to get a proper, tested fix into the next release. Again, I apologize for any inconveniece this may have caused.

[No archive available]
2007-10-16 00:00:00 +00:00
byuu
9ab3fa6227 Update to bsnes v025r01? release.
I'll bet this will surprise you all, I already have a
private WIP for the v0.025 series up :P
 Absolutely no emulation changes, just lots of major code changes I
held off on as I didn't want to break anything last minute.

 - Polymorphism through pointers using compile-time flag is dead. It
took a ~10% speed hit, so it was never feasible to use anyway. This is
also a required step to encapsulating the entire emulator inside a
single class which can support multiple instances. r_cpu-> becomes
cpu. , r_smp-> becomes smp. , etc.
 - Greatly cleaned up interface.h as much as possible for now. Right
now, bsnes takes a lot longer than it should to compile because every
single object includes every last header for all objects. In the
future, I want to move headers so that only objects that need others
include those headers. Will increase compile speed a good bit.
               - Created chip/chip.h to start on the above.
               - Finally renamed chip/c4 to chip/cx4. Class name also
changed from C4 to Cx4.
               - Removed libsort, as it's not used (yet?). Was
needlessly slowing down compile time.
 - Created src/doc. This will be a folder that contains source code
documentation, diagrams, maps, to-do lists, etc. Started things off by
creating a _very_ basic overview of bsnes as a whole.

 Much more radical stuff to come. I don't anticipate making another
public release for quite a long time, so I should be able to go wild
here with restructuring things.







> I just checked out the new bsnes version 0.025, but I could not find
> any option in the config file to change the memory / mem via PRNG
> initialization byte, that we were talking about earlier to help get
> some old pd stuff working...




 Oh, I'm sorry about that. Didn't get a chance to add it this time. I
need to work a PRNG with a consistent seed value into the core first.
Not sure how I want to do that.

 For what it's worth, initializing RAM to 0x00 unfortunately did not
fix Sidmania's graphical issues as I had hoped. Given FitzRoy reports
the glitches occur on real hardware as well, I'm afraid there's not a
whole lot I can do about it. I will pay attention to it when working
on my cycle-based PPU in the future, though.







> On another note your emulator has inspired me to do my first
> translation for the snes "Albert Odyssey", and has been very useful
> for this purpose.




 Neat! Be sure to check out bsnes v0.013 on RHDN for its debugger.
It's the only SNES emulator with VRAM breakpoints, as far as I know.
Also be sure to try out xkas for your cross assembler :D </shameless
self-promotion>







> Oct. 14 also happens to be the 10th anniversary of the first public
> release of ZSNES, interestingly enough.




               o.O
 Holy crap, why didn't I ever hear about this before? That's really,
really interesting ... of course, the difference is that bsnes was
started on 10-14, ZSNES was first released then but obviously started
much sooner. Still cool, though.

 I wonder if anyone knows the exact date zsKnight started on ZSNES, or
Jeremy Koot on SNES9x. It would be really cool to have a history of
the SNES emulation scene. So many emulators most have never even heard
of ... RSRSNES, GrimSNES, TrepSNES, Moonlit Coalition's emulator (that
played one game, heh), Simkin's simulator thing ... heh, I wonder if
anyone here knows the name of the SNES emulator I tried (and failed)
making way before bsnes, back in 2001. Google doesn't even know of it
:)

[No archive available]
2007-10-15 05:21:00 +00:00
byuu
85fa3cc968 Update to bsnes v025 release.
bsnes is exactly three years old today. I've posted a new version which adds DSP-3 and DSP-4 special chip support. The DSP-3 is used by SD Gundam GX, and the DSP-4 is used by Top Gear 3000. Please note that the DSP-3 is not fully emulated, thusly SD Gundam GX is not fully playable. Also, due to lack of timing emulation with the DSP-4, the Top Gear 3000 track sometimes flickers in split screen mode. However, it is believed that Top Gear 3000 is fully playable.
I should also note that I have started on SuperFX emulation, as some will inevitably see said code in my source releases. What I have now is nothing more than a skeleton implementation, and absolutely nothing using it is playable yet. I am making absolutely no promises that I will ever be able to emulate this chip. It will take at least several months of work, and even then, the speed will probably be too slow to reach 60fps on any system, but ... I'm working on it. While I have no way to run tests on the actual SuperFX hardware, I will do the best I can to emulate the chip accurately. I will be emulating the caching and cycle delays as best I can, but the information I have on this chip is extremely limited, so don't expect miracles.
Lastly, as promised, I have released the special chips I have personally emulated to the public domain. See license.txt for more information if interested. I cannot release the special chips whose code I did not write to the public domain, but all of that is already available under the GPLv2 (from ZSNES) or the SNES9x license.
Changelog:
    - Added DSP-3 support, thanks to John Weidman, Kris Bleakley, Lancer, z80 gaiden
    - Added DSP-4 support, thanks to Dreamer Nom, John Weidman, Kris Bleakley, Nach, z80 gaiden
    - Started on support for SuperFX, no games playable as chip emulation is less than 1% complete
    - Unsupported special chips will now display an alert
    - Missing stbios.bin file when loading Sufami Turbo cartridges will now display an alert
    - Video settings now saved separately for windowed and fullscreen mode
    - Advanced option video<.mode>.synchronize can be enabled for vsync, but will cause sound crackling
    - Added menu option to toggle FPS counter
    - Minor source code cleanup
2007-10-15 10:03:36 +00:00
byuu
d1fcddee9c Update to bsnes v024r01? release.
New WIP up.

 This one merges the most recent DSP-3 / DSP-4 work. Not sure if it
fixes any bugs or not, but good to be up to date, right? Testing would
be appreciated.

             I also cleaned up the cart stuff a bit. Nicer enums,
removed some unused variables and such.

 Then I turned all of the special chip class object pointers into
actual objects. It was kind of stupid to dynamically create them all,
and was just wasting performance.

 I also finished adding all of the SuperFX registers, and mapped them
all to the GSU interface range ($3000-$32ff). Fixed an oversight with
the mapping, and added a new PCB database entry to get the memory map
for Yoshi's Island perfect. If you want to hear something nice, try
loading the USA version in this WIP with sound + speed regulation
enabled.

 Then I added a 'Show FPS' option to the misc menu. I also didn't
realize I was still embedding the SNES controller bitmap even though
it wasn't displayed anywhere, so for now that's been removed. Makes
the EXE and archive a bit smaller.

 Lastly, I redid the bsnes section of my site to look a little more
polished. Getting ready for 10/14. I've always hated the way SNES
emulator authors always cherry picked most of their screenshots to
show off their special chip support (jealousy because I didn't have
any for a long time), so I decided I'd do the exact same thing myself
this time :P
 Ripped off Overload yet again, this time I stole his screenshot
layout style. Sorry, Overload ... but imitation is the sincerest form
of flattery, right? :)

 Also, note that all of the ?page=bsnes_* URIs have changed to
?page=bsnes/* ... so if you get redirected to the main page from a
bookmark or something, that's why.

             Whew, busy day today ...

[No archive available]
2007-10-12 06:55:00 +00:00
byuu
9fd379613a Update to bsnes v024 release.
This is an interim release between some major changes to the video mode support, which may take a long time to complete. It also fixes a bug with CGRAM access timing, re-adds the Sufami Turbo load menu, and adds support for the ST-010 coprocessor, used by F1 Race of Champions.
To load Sufami Turbo cartridges, stbios.bin must be placed inside a folder named bios in the bsnes folder. There is not currently a warning if this file is missing.
2007-10-01 09:03:44 +00:00
byuu
aabf52d678 Update to bsnes v023r01? release.
Alright, I've posted the new WIP.

             Changelog:
             - CGRAM fix for WWF Super Wrestlemania
             - Updated to blargg's snes_ntsc library to version 0.2.2
             - Added ST and ST dual cart loading menu options (*)
             - Redesigned the video mode configuration panel a bit --
let me know what you think (**)

 (*) - You have to set path.bios to an -absolute- path, ./ is
currently broken and I need to fix that. So, set it to eg
"c:/path/to/bsnes/bios" where stbios.bin is inside that folder.
             (**) - The video menu obviously doesn't do anything, it's
just there for design advice / suggestions for now.

 You'll notice the icon is gone. This is because I built this version
with MinGW 4, and I'm not sure how to add the icon to MinGW apps.
You'll also notice it's ~6% faster on Core 2 processors as a result.

 The 16% speedup was only when PGO was enabled. But I can't enable
that, because it causes bsnes to crash randomly. GCC gets too risky
with its optimizations and ends up generating bad code (the GCC manual
states as much, I'm not just trying to blame problems in my app on GCC
here.)

 So, 6% is the best speedup we can do for now. Compare to v0.023
official if you like. You probably won't see the speedup on older
processors like the Pentium IV.

 EDIT: it seems like that MinGW vsnprintf problem is based on DLL
files on the local computer. Probably the MS VisualC runtime files.
The WIP works fine on my home PC (WinXP Pro), but not on my work PC
(Win2k). I'm going to have to stick with Visual C++ builds until I am
able to completely remove all sprintf-style calls from the emulator.

 If you get an error about memory at 0xffffffff which cannot be read,
you know why. Try building with Visual C++ if you have it, or maybe
there's some way to upgrade libc DLLs that the app is binding to.
Whatever DLL has vsnprintf is the one that needs to be updated, if at
all possible.

             Here's what the video config screen looks like at the
moment.

             [image]

 I tried putting the text at the top, that way there won't be any odd
gaps between the text and combo box dropdown, due to different sized
fonts on different platforms.

[No archive available]
2007-09-25 14:20:00 +00:00
byuu
c9ca01fe20 Update to bsnes v023 release.
I've recently fixed a bug in bsnes that I feel is serious enough to warrant a new release, even though little else has changed.
I attempted to build this release with MinGW, but ran into problems with profiling and JMA support, so this release was built with Visual C++ once again.
Changelog:
    - Fixed serious bug in S-SMP incw and decw instructions -- fixes sound bug in Emerald Dragon
    - Added Nach's MinGW fixes -- can now be compiled with MinGW/GCC3 or MinGW/GCC4
    - Fixed const char* cast warnings in GCC 4.2, thanks to [vEX] for the feedback
    - Updated source to use latest libraries for libco, libui, etc.
    - Added new advanced options to adjust aspect ratio correction
    - Cleaned up source code a bit
2007-09-16 19:30:35 +00:00
byuu
becf122aaa Update to bsnes v022r04? release.
Ok, I've posted a new WIP with the Emerald Dragon bug
fix. This time, I'm not posting the WIP publically. My last request
not to link directly to the file elsewhere was ignored, and ended up
on at least two emulation news sites (I won't mention names.) I'm not
trying to be a jerk about it, I really can't spare that kind of
bandwidth.

 If anyone has contributed any code or bug fixes, reported any
confirmed bugs, or is an emulator author I've spoken to in the past,
feel free to request a link to the WIP page from me in PM if desired.

               Sorry to everyone else. I'll have the new version out
as soon as possible.







> As for the AR advanced option, I think option 2 looks perfect.




 Done. I didn't add any sanity checks, so that people can have a
little fun with it. It's not going to be a GUI option, so only
advanced users can play with it anyway. Try setting a crazy aspect
like 3:1 and play a platform game. It's guaranteed to mess with your
mind.

 I also added the ... stuff, but I did not add the pause support back
in yet. Not sure if that'll make the next release, because it requires
some changes to the main loop functions that have been missing for a
while now. I usually like to leave more of a beta testing window
before messing with that stuff.







> byuu, you may know this, but on the front page of your web site, the
> link to your Philosophical Ramblings page is
> "http://localhost/index.php?page=articles/philosophy".




               Hahah, oops. No, I didn't notice that. I must have
copied the link from my browser instead of typing it manually.

 It's a stupid article, anyway. Didn't come out like I planned. I was
also reading some comments by Miguel de Icaza (supporting patent
pacts) and Linus Torvalds (bashing the hell out of C++ programmers),
and came across an interesting comment that got me thinking. Basically
that people who have any kind of notability really shouldn't go around
talking about things outside their specific expertise, because it
makes them look foolish when people take them too seriously (and
people do) as those two comments by de Icaza and Torvalds did. Lucky
for me I really _don't_ have any kind of notability, but it's a good
principle to adhere to anyway. Stick to talking about what I know
best. That goes against my whole personality though, so I probably
won't change at all anyway.

[No archive available]
2007-09-12 10:08:00 +00:00
byuu
1e130d7872 Update to bsnes v022r03 release.
Double post!

 I've uploaded a new WIP, which I'll make public (only to this forum,
please don't post about it anywhere else unless you mirror the file):







    http://byuu.org/files/bsnes_v022_wip03.zip




 This version adds all of Nach's MinGW fixes, updated libco, libui and
libfunctor, cleans up the code that detects if the main window has
focus or not (if not, ignore keyboard input), adds the new makefile
target win-mingw-lui, finally fixes all of the char* conversion
warnings with GCC 4.2.x (thanks [vEX]), and I'm sure there's more, but
I don't remember.

 The ZIP includes a Visual C++ generated binary, but it also works
with MinGW GCC4. It won't work with MinGW GCC3 because that one lacks
a C99-compliant vsnprintf function. You can hack your way around that
by editing src/lib/libstring_sprintf.cpp if you really want to use
MinGW GCC3.

 You may also need to change the CC / CPP variable names. I went with
the generic names mingw32-gcc and mingw32-g++, but the GCC4 binaries
have -sjlj or -dw2 appended to them. You'll also need to set
-I/path/to/directxheaders, or copy them all into
/path/to/mingw/include, since MinGW seems to ignore the include
environment variable.

 And finally, a bit of good news. It appears that MinGW GCC4 builds
binaries that are ~6% faster than Visual C++. That means with PGO
enabled, they should be at least ~16% faster than v0.022 official. If
I can figure out how to hide the ugly terminal window in the
background, I'll start making official releases with MinGW GCC4 from
now on.
2007-09-08 08:41:18 +00:00
byuu
c57c733d7d Update to bsnes v022 release.
Today marks a milestone for bsnes, and possibly for SNES emulation as a whole. With this new release, bsnes' compatibility has now reached 100.0%, with zero game-specific hacks. With every last commercially released game tested by both FitzRoy and tetsuo55 for at least five minutes each, all known bugs have been resolved.
Now, needless to say, I am referring to the emulation of the base SNES unit. As many SNES cartridges contain additional coprocessors on their PCBs, there are still unplayable titles. So how can I claim compatibility of 100%? Because I don't consider special chips inside game cartridges as part of the base SNES hardware. I realize that many people enjoy these games, and I do actively attempt to emulate as many coprocessors as possible (six are supported thus far). However, coprocessors such as the SuperFX and SA-1 continue to pose very significant challenges.
So, after nearly three years of development, I've finally achieved my primary goal. But it wasn't a complete victory ... I've learned a lot over the years. Emulation accuracy is not black and white -- there are heavy costs to pay and forced tradeoffs to achieve it. I no longer believe there is only one absolute path for emulation, as I did in 2004.
So does this mean bsnes is now perfect? Of course not. There are many technical details that are not emulated correctly. This also does mean that there are no bugs, merely that there are no bugs that we are aware of. While absolute verification of 100% compatibility is obvioulsy impossible, even by actually beating every single game from start to finish, this very well should be the first time any SNES emulator could claim zero known bugs with all known games tested. I very much expect this announcement to entice many new users to begin actively searching for bugs, in an effort to discredit my above claim. My response? Go for it! I would very much appreciate any and all discovered bugs to be posted here, so that they can be verified and addressed.
One major thing that needs to be said, is that there consists of one major hack in all SNES emulators, including bsnes: the use of scanline-based PPU renderers. This necessitates global hacks in all emulators to minimize their inaccuracies. I was going to write up a very long post here, going into specifics, but I've decided an article would be a better place for that. I will hopefully be writing up this article in a few days to post here.
In the meantime, one very important issue does need to be addressed. This version fixes a bug in Uniracers 2-player mode, where the game writes to OAM during active display. Like other PPU global hacks, Uniracers required a special consession. But because this hack only affects one game, it can very fairly be seen as cheating. Suffice to say, bsnes does not contain a game-specific hack, and the change made to fix Uniracers affects all games, but I do still very much consider it to be a hack. The fix I have added is quite literally and honestly more accurate than the behavior of bsnes v0.021. Before, writes to OAM and CGRAM during active display went where a programmer would expect, which would cause bugs when ran on real hardware. Uniracers is the only game known to do this, and it is very dangerous to do so. The writes do go through, but not where one would expect. The access address basically changes as the screen is rendered. With a scanline-based PPU, it is not possible to emulate the individual 
steppings of the PPU, as there is not enough precision. Further, the entire SNES emulation community has virtually no information on how active display OAM and CGRAM writes work. Now, as Uniracers is the only game known to do this, I had the choice of either intentionally remapping the writes to an arbitrary location, or change it to the address Uniracers expects. Neither would be more accurate than the other, as both are completely wrong from a haradware standpoint. So the decision was to either fix Uniracers and deal with some calling it a game-specific hack, or to leave it broken with absolutely no gain to accuracy. Rather than decide for myself, I asked those who have supported me over the past three years for their opinions. The decision was unanimous to fix Uniracers. You can read the discussion, along with a more technical explanation of the issue, here. I will be addressing this topic in much greater detail in the article I will be writing up shortly.
Changelog:
    - Fixed buffer overflow that was manifesting as corrupted tiles in Lemmings 2
    - OAM and CGRAM addresses are now invalidated during active display, however the algorithms for how this address invalidation occurs is currently still unknown, so reads/writes are mapped to static addresses for now
    - Re-added cheat code editor.
    - Windows only: keypresses when main emulation window is not active are ignored once again
2007-08-04 19:54:35 +00:00
byuu
e41aa25887 Update to bsnes v021r02? release.
I've posted a new private WIP. This one just adds the
cheat code editor back in again. Feedback on how it works is
appreciated. You'll notice it's a lot simpler than v0.019's cheat
editor ... I was going for simplicity this time. Editing a code means
deleting and re-adding it (or edit the text file directly). Yes, I
realize it's damn annoying entering codes because the emulator detects
your keypresses as controller presses (unless you're using a joypad).
Sorry, I still need to add code to determine if the active window is
the main emulator window or not for GTK+ before I can fix this on both
ports.

 Hopefully I can get that in before v0.022, but no promises. Worst
case, I'll add a dummy Window::active() function that always returns
true for GTK+ if needed.

 The cheat editor works the exact same on Windows and Linux, so this
should be the first release to allow Linux users to use it.

 Looking more at how useful bsnes is in its' current form ... I'm
simply not going to be able to walk away from it. Fuck it, I'll just
have to split the emulator and maintain two separate versions. It may
cost me some time, but whatever. It'll be good practice in trying to
streamline things to share as much code as possible. I'll keep them
together in one version as long as possible, too (using #defines and
such).

 If I do this, any suggestions on how to differentiate the two
versions? Different names? Different acronyms after bsnes (eg bsnes/AE
and bsnes/SE ...)? Different icons?







> One important point imo is the potential for "code longetivity".
> That is, I'd like the original, untouched code to continue to exist
> (while permitting derivative works) many decades from now.




 No matter the license, that won't change. People can close derived
works with PD, but it's their code that they added which becomes
closed, not mine. It won't make my code cease to be.

 It's not like it all matters that much. Regardless of license, anyone
is always free to get PD access to my code by asking. This is just me
trying to get a public consensus on whether or not I should allow
people to use my code without my permission, and to what extent I
should allow it.

 I was hoping the votes would be less 'all over the board' like the
Uniracers fix ... this vote isn't going very well. Sigh.

 It'd be annoying specifying licenses on everything. Maybe I'll just
bundle the core components (cpu, smp, ppu, dsp, memory, chip sans c4
(I don't own the rights to that)) and stick them in a separate
downloadable archive that's PD [or GPL w/permission exception]. That
way, I'm giving away the stuff that's important and can help others
the most, the emulation core. If someone can't be bothered to ask me
for mine, then they can write their own GUI. Call the package
something like 'libbsnes'. Meh.

[No archive available]
2007-08-03 08:23:00 +00:00
byuu
435f7d4371 Update to bsnes v021r01? release.
Alright, I've posted the new WIP.

             This one's really important, so please test it
thoroughly! :D
 I've ran it through my usual list of troublesome games, and
everything looks good, but it's possible I've overlooked something.

             The new config file settings are:
             ppu.hack.oam_address_invalidation
             ppu.hack.cgram_address_invalidation

 Set to true, OAM goes to 0x0218 (for Uniracers), CGRAM to 0x0000
(address is insignificant, we know of zero examples of this behavior,
so the address chosen does not matter for now). Set to false, the
writes are allowed and go where 'expected' (by programmers, not by
hardware).

 There's a slight difference in that OAM access is invalid even during
hblank, whereas CGRAM is obviously not (that's how games draw those
gradient fades and such).

             This WIP also has the Lemmings II fix.

             ---

 Now, I know I said I wouldn't bring this up again, but meh. So,
assuming I decide to go full force at this PPU renderer ... I still
want to let bsnes live on in its' current form, even if that means
losing my userbase to a competitor :(
 I'm planning for the next release to allow derivative works, in hopes
that someone will continue it. Does anyone have any objections to
that? Would it be better to use GPLv2/3 to ensure source availability
(even though I disagree with the notion of 'freedom through
restrictions' -- I liken it to becoming your enemies to defeat them),
or better to use PD to ensure the widest possible use of the code
(even if that means the source can be closed off to the public, and
the binary sold for profit -- which I also detest as immoral)? I
realize the latter means the value of all of my work will be lost, but
I never intended to profit from any of this anyway, so ...

 If you prefer GPL, please specify either v2 only, v2+ or v3. I can
use v3 and grant ZSNES an exception to use it under v2, so their v2
only license won't be a problem.

             Some examples:
             ZSNES is GPLv2, which got them the source to Zsnexbox.
 PocketNES is PD, which got the emulator used in commercial software
by Atlus, Hudson and Jaleco (though the assholes couldn't even be
bothered to send a thank you letter to the PocketNES devs).

 EDIT: I can also stick with the current license, a no-derivative one,
and do my best to maintain bsnes' old PPU renderer, if you like. But I
won't lie ... the pace of development _will_ slow down a lot on the
older version (it shouldn't affect my new PPU development speed much)
if we go with this option.

             Once again, I'll go with community opinion this time. I'm
personally not casting a vote for either.

[No archive available]
2007-08-02 08:46:00 +00:00
662 changed files with 40007 additions and 28727 deletions

BIN
cart.db

Binary file not shown.

View File

@@ -1,63 +0,0 @@
bsnes (TM) Open Source Reference License
Copyright (C) 2004 - 2007 byuu
All rights reserved
1. Definitions
The terms "reproduce", "reproduction", "distribute" and "distribution" have the
same meaning here as under U.S. copyright law.
"The software" means this software package as a whole, including, but not
limited to, this license, binaries, source code, documentation, and data.
"You" means the licensee of the software.
"The licensor" means the copyright holder of the software, byuu.
2. Grant of Rights
Subject to the terms of this license, the licensor grants you a
non-transferable, non-exclusive, worldwide, royalty-free copyright license to
reproduce the software for non-commercial use only, provided the software
remains unmodified, and there is no charge for the software itself, its' use,
nor for the medium upon which the software is distributed. The reproduction of
modified or derivative works of the software is strictly prohibited, except when
transmitted solely to the licensor.
3. Limitations
This license does not grant you any rights to use the licensor's name, logo or
trademarks.
The software is provided "as is", and any express or implied warranties,
including, but not limited to, the implied warranties of merchantability and
fitness for a particular purpose are disclaimed. In no event shall the licensor
be liable for any direct, indirect, incidental, special, exemplary, or
consequential damages (including, but not limited to, procurement of substitute
goods or services; loss of use, data, or profits; or business interruption)
however caused and on any theory of liability, whether in contract, strict
liability, or tort (including negligence or otherwise) arising in any way out of
the use of the software, even if advised of the possibility of such damage.
In the event that this license is determined to be invalid or unenforceable, the
Grant of Rights will become null and void, and no rights shall be granted to the
licensee, within the scope of U.S. copyright law.
4. Exemptions
The software includes the work of other copyright holders, which is licensed
under different agreements, and exempt from this license. Below is a complete
list of all such software, and their respective copyright holders and licenses.
Further, respective source code files are labeled with their correct licensing
information in the header. The lack of such a header indicates said file falls
under the bsnes license.
HQ2x Filter, author: MaxST, license: LGPL
JMA, author: NSRT Team, license: GPL *
libco, author: byuu, license: public domain
libui, author: byuu, license: public domain
NTSC Filter, author: blargg, license: LGPL
S-DD1, author: Andreas Naive, license: public domain
zlib, license: zlib license
* bsnes has received an exemption from the copyright holder to use this work.

View File

@@ -1,88 +0,0 @@
bsnes
Version 0.021
Author: byuu
General:
--------
bsnes is a Super Nintendo / Super Famicom emulator that began on
October 14th, 2004.
The latest version can be downloaded from:
http://byuu.org/
Please see license.txt for important licensing information.
Known Limitations:
------------------
S-CPU
- Invalid DMA / HDMA transfers (eg WRAM<>WRAM) not fully emulated
- Multiply / Divide register delays not implemented
S-PPU
- Uses scanline-based renderer. This is very inaccurate, but very few games
rely on mid-scanline writes to function correctly
- Does not support FirstSprite+Y priority
- OAM / CGRAM accesses during active display not supported correctly
- RTO flags are not calculated on frames that are skipped when frameskipping
is enabled. This provides a major speedup, however it will cause in issues
in games that test these flags, eg the SNES Test Program Electronics Test.
Turning frameskipping off will allow RTO flag calculation on every frame
Hardware Bugs
- CPUr1 HDMA crashing bug not emulated
- CPU<>APU communication bus conflicts not emulated
Unsupported Hardware:
---------------------
SA-1
Coprocessor used in many popular games, including:
- Dragon Ball Z Hyper Dimension
- Kirby Super Star
- Kirby's Dreamland 3
- Marvelous
- SD Gundam G-NEXT
- Super Mario RPG
Super FX
Coprocessor used in many popular games, including:
- Doom
- Star Fox
- Star Fox 2 (unreleased beta)
- Super Mario World 2: Yoshi's Island
SPC7110
Coprocessor used only by the following games:
- Far East of Eden Zero
- Far East of Eden Zero: Shounen Jump no Shou
- Momotarou Densetsu Happy
- Super Power League 4
DSP-3
Coprocessor used only by SD Gundam GX
DSP-4
Coprocessor used only by Top Gear 3000
ST010 / ST011 / ST018
SETA coprocessors used by very few games
BS-X (Broadcast Satellite)
Add-on unit sold only in Japan that played specially-made games that were
downloaded via satellite
BS-X Flashcart
Flash cartridge used by BS-X, as well as some standalone games by Asciisoft
Super Gameboy
Cartridge passthrough used for playing Gameboy games
Unsupported Controllers:
------------------------
Mouse
Super Scope
Justifier
Multitap (4-port and 5-port)

View File

@@ -1,274 +1,276 @@
######################
### bsnes makefile ###
######################
ifeq ($(PLATFORM),)
_null_: help
endif
##################################
### platform-specific settings ###
##################################
ifeq ($(PLATFORM),x-gcc-lui)
OS = unix
CC = gcc
CFLAGS = -O3 -fomit-frame-pointer -ffast-math -DPLATFORM_X -DCOMPILER_GCC -DPROCESSOR_X86 -DUI_LUI `pkg-config --cflags gtk+-2.0`
AS = nasm
ASFLAGS = -f elf
LIBS = `pkg-config --libs gtk+-2.0` -lXv -lao
LIBCO = libco_x86
LIBUI = libui_gtk
endif
ifeq ($(PLATFORM),x-gcc-lui-x64)
OS = unix
CC = gcc
CFLAGS = -O3 -fomit-frame-pointer -ffast-math -DPLATFORM_X -DCOMPILER_GCC -DPROCESSOR_X86_64 -DUI_LUI `pkg-config --cflags gtk+-2.0`
AS = yasm
ASFLAGS = -f elf64
LIBS = `pkg-config --libs gtk+-2.0` -lXv -lao
LIBCO = libco_x86_64
LIBUI = libui_gtk
endif
ifeq ($(PLATFORM),win-visualc-lui)
OS = win
CC = cl
CFLAGS = /nologo /wd4996 /O2 /EHsc /DPLATFORM_WIN /DCOMPILER_VISUALC /DPROCESSOR_X86 /DUI_LUI
AS = nasm
ASFLAGS = -f win32 -DWIN32
LIBS = d3d9.lib ddraw.lib dsound.lib dinput8.lib dxguid.lib
LIBCO = libco_x86
LIBUI = libui_win
endif
ifeq ($(PLATFORM),win-visualc-lui-pgi)
OS = win
CC = cl
CFLAGS = /nologo /wd4996 /O2 /GL /EHsc /DPLATFORM_WIN /DCOMPILER_VISUALC /DPROCESSOR_X86 /DUI_LUI
AS = nasm
ASFLAGS = -f win32 -DWIN32
LIBS = d3d9.lib ddraw.lib dsound.lib dinput8.lib dxguid.lib
LINK = /link /PGD:bsnes.pgd /LTCG:PGINSTRUMENT
LIBCO = libco_x86
LIBUI = libui_win
endif
ifeq ($(PLATFORM),win-visualc-lui-pgo)
OS = win
CC = cl
CFLAGS = /nologo /wd4996 /O2 /GL /EHsc /DPLATFORM_WIN /DCOMPILER_VISUALC /DPROCESSOR_X86 /DUI_LUI
AS = nasm
ASFLAGS = -f win32 -DWIN32
LIBS = d3d9.lib ddraw.lib dsound.lib dinput8.lib dxguid.lib
LINK = /link /PGD:bsnes.pgd /LTCG:PGOPTIMIZE
LIBCO = libco_x86
LIBUI = libui_win
endif
#####################################
### compiler / assembler switches ###
#####################################
ifeq ($(CC),gcc)
OUT = -obsnes
CPP = g++
OBJ = o
CARGS = -c $< -o $@
DEFINE = -D
endif
ifeq ($(CC),cl)
OUT = /Febsnes
CPP = cl
OBJ = obj
CARGS = /c $< /Fo$@
DEFINE = /D
endif
ifeq ($(AS),nasm)
ASARGS = $< -o $@
endif
ifeq ($(AS),yasm)
ASARGS = $< -o $@
endif
###################
### OS switches ###
###################
ifeq ($(OS),unix)
RM = rm -f
endif
ifeq ($(OS),win)
OUT := $(OUT).exe
RM = del
LIBS += kernel32.lib user32.lib gdi32.lib shell32.lib winmm.lib comdlg32.lib comctl32.lib
endif
####################################
### main target and dependencies ###
####################################
OBJECTS = main.$(OBJ) $(LIBCO).$(OBJ) $(LIBUI).$(OBJ) \
libstring.$(OBJ) \
reader.$(OBJ) cart.$(OBJ) cheat.$(OBJ) memory.$(OBJ) bmemory.$(OBJ) \
cpu.$(OBJ) scpu.$(OBJ) smp.$(OBJ) ssmp.$(OBJ) bdsp.$(OBJ) ppu.$(OBJ) \
bppu.$(OBJ) snes.$(OBJ) srtc.$(OBJ) sdd1.$(OBJ) c4.$(OBJ) dsp1.$(OBJ) \
dsp2.$(OBJ) obc1.$(OBJ)
ifeq ($(GZIP_SUPPORT),true)
OBJECTS += adler32.$(OBJ) compress.$(OBJ) crc32.$(OBJ) deflate.$(OBJ) \
gzio.$(OBJ) inffast.$(OBJ) inflate.$(OBJ) inftrees.$(OBJ) ioapi.$(OBJ) \
trees.$(OBJ) unzip.$(OBJ) zip.$(OBJ) zutil.$(OBJ)
CFLAGS += $(DEFINE)GZIP_SUPPORT
endif
ifeq ($(JMA_SUPPORT),true)
OBJECTS += jma.$(OBJ) jcrc32.$(OBJ) lzmadec.$(OBJ) 7zlzma.$(OBJ) \
iiostrm.$(OBJ) inbyte.$(OBJ) lzma.$(OBJ) winout.$(OBJ)
CFLAGS += $(DEFINE)JMA_SUPPORT
endif
ifeq ($(OS),win)
ifeq ($(CC),cl)
OBJECTS += bsnes.res
endif
endif
all: $(OBJECTS)
$(CPP) $(OUT) $(CFLAGS) $(OBJECTS) $(LIBS) $(LINK)
# mt -nologo -manifest bsnes.exe.manifest -outputresource:bsnes.exe;1
######################
### implicit rules ###
######################
%.$(OBJ): $<
$(if $(filter %.asm,$<),$(AS) $(ASFLAGS) $(ASARGS))
$(if $(filter %.c,$<),$(CC) $(CFLAGS) $(CARGS))
$(if $(filter %.cpp,$<),$(CPP) $(CFLAGS) $(CARGS))
#########################
### platform-specific ###
#########################
main.$(OBJ): ui/main.cpp config/* ui/* ui/video/* ui/audio/* ui/input/* \
ui/lui/* ui/lui/settings/* \
ui/win/* ui/win/settings/* ui/win/debugger/*
bsnes.res : ui/bsnes.rc ; rc /r /fobsnes.res ui/bsnes.rc
#############
### libco ###
#############
libco_x86.$(OBJ) : lib/libco_x86.asm lib/*
libco_x86_64.$(OBJ): lib/libco_x86_64.asm lib/*
#############
### libui ###
#############
libui_gtk.$(OBJ): lib/libui_gtk.cpp lib/*
libui_win.$(OBJ): lib/libui_win.cpp lib/*
#################
### libraries ###
#################
libstring.$(OBJ): lib/libstring.cpp lib/*
#################
### utilities ###
#################
reader.$(OBJ): reader/reader.cpp reader/*
cart.$(OBJ) : cart/cart.cpp cart/*
cheat.$(OBJ) : cheat/cheat.cpp cheat/*
##############
### memory ###
##############
memory.$(OBJ) : memory/memory.cpp memory/*
bmemory.$(OBJ): memory/bmemory/bmemory.cpp memory/bmemory/* memory/bmemory/mapper/*
###########
### cpu ###
###########
cpu.$(OBJ) : cpu/cpu.cpp cpu/*
scpu.$(OBJ): cpu/scpu/scpu.cpp cpu/scpu/* cpu/scpu/core/* cpu/scpu/dma/* cpu/scpu/memory/* cpu/scpu/mmio/* cpu/scpu/timing/*
###########
### smp ###
###########
smp.$(OBJ) : smp/smp.cpp smp/*
ssmp.$(OBJ): smp/ssmp/ssmp.cpp smp/ssmp/* smp/ssmp/core/* smp/ssmp/memory/* smp/ssmp/timing/*
###########
### dsp ###
###########
adsp.$(OBJ): dsp/adsp/adsp.cpp dsp/adsp/*
bdsp.$(OBJ): dsp/bdsp/bdsp.cpp dsp/bdsp/*
###########
### ppu ###
###########
ppu.$(OBJ) : ppu/ppu.cpp ppu/*
bppu.$(OBJ): ppu/bppu/bppu.cpp ppu/bppu/*
############
### snes ###
############
snes.$(OBJ): snes/snes.cpp snes/* snes/scheduler/* snes/video/* snes/audio/* snes/input/*
#####################
### special chips ###
#####################
srtc.$(OBJ): chip/srtc/srtc.cpp chip/srtc/*
sdd1.$(OBJ): chip/sdd1/sdd1.cpp chip/sdd1/*
c4.$(OBJ) : chip/c4/c4.cpp chip/c4/*
dsp1.$(OBJ): chip/dsp1/dsp1.cpp chip/dsp1/*
dsp2.$(OBJ): chip/dsp2/dsp2.cpp chip/dsp2/*
obc1.$(OBJ): chip/obc1/obc1.cpp chip/obc1/*
############
### zlib ###
############
adler32.$(OBJ) : reader/zlib/adler32.c reader/zlib/*
compress.$(OBJ): reader/zlib/compress.c reader/zlib/*
crc32.$(OBJ) : reader/zlib/crc32.c reader/zlib/*
deflate.$(OBJ) : reader/zlib/deflate.c reader/zlib/*
gzio.$(OBJ) : reader/zlib/gzio.c reader/zlib/*
inffast.$(OBJ) : reader/zlib/inffast.c reader/zlib/*
inflate.$(OBJ) : reader/zlib/inflate.c reader/zlib/*
inftrees.$(OBJ): reader/zlib/inftrees.c reader/zlib/*
ioapi.$(OBJ) : reader/zlib/ioapi.c reader/zlib/*
trees.$(OBJ) : reader/zlib/trees.c reader/zlib/*
unzip.$(OBJ) : reader/zlib/unzip.c reader/zlib/*
zip.$(OBJ) : reader/zlib/zip.c reader/zlib/*
zutil.$(OBJ) : reader/zlib/zutil.c reader/zlib/*
###########
### jma ###
###########
jma.$(OBJ) : reader/jma/jma.cpp reader/jma/*
jcrc32.$(OBJ) : reader/jma/jcrc32.cpp reader/jma/*
lzmadec.$(OBJ): reader/jma/lzmadec.cpp reader/jma/*
7zlzma.$(OBJ) : reader/jma/7zlzma.cpp reader/jma/*
iiostrm.$(OBJ): reader/jma/iiostrm.cpp reader/jma/*
inbyte.$(OBJ) : reader/jma/inbyte.cpp reader/jma/*
lzma.$(OBJ) : reader/jma/lzma.cpp reader/jma/*
winout.$(OBJ) : reader/jma/winout.cpp reader/jma/*
####################
### misc targets ###
####################
clean:
-@$(RM) *.$(OBJ)
-@$(RM) *.res
-@$(RM) *.pgd
-@$(RM) *.pgc
-@$(RM) *.ilk
-@$(RM) *.pdb
-@$(RM) *.manifest
help:
@echo Please specify which platform to compile for with PLATFORM=platform_name
include lib/nall/Makefile.string
prefix = /usr/local
################
### compiler ###
################
ifneq ($(findstring gcc,$(compiler)),) # GCC family
flags = -O3 -fomit-frame-pointer -Ilib
c = $(compiler) $(flags)
cpp = $(subst cc,++,$(compiler)) $(flags)
obj = o
rule = -c $< -o $@
link = -s
mkbin = -o$1
mkdef = -D$1
mklib = -l$1
else ifeq ($(compiler),cl) # Visual C++
flags = /nologo /wd4355 /wd4805 /wd4996 /Ox /GL /EHsc /Ilib
c = cl $(flags)
cpp = cl $(flags)
obj = obj
rule = /c $< /Fo$@
link = /link
mkbin = /Fe$1
mkdef = /D$1
mklib = $1.lib
else
unknown_compiler: help;
endif
##########
### os ###
##########
ifeq ($(platform),x) # X11
ruby = video.glx video.xv video.sdl audio.alsa audio.openal audio.oss audio.pulseaudio audio.ao input.sdl input.x
link += `pkg-config --libs gtk+-2.0`
link += $(call mklib,Xtst)
delete = rm -f $1
else ifeq ($(platform),win) # Windows
ruby = video.direct3d video.wgl video.directdraw video.gdi audio.directsound input.directinput
link += $(if $(findstring mingw,$(compiler)),-mwindows)
link += $(call mklib,uuid)
link += $(call mklib,kernel32)
link += $(call mklib,user32)
link += $(call mklib,gdi32)
link += $(call mklib,shell32)
link += $(call mklib,winmm)
link += $(call mklib,comdlg32)
link += $(call mklib,comctl32)
delete = $(if $(findstring i586-mingw-gcc,$(compiler)),rm -f $1,del $(subst /,\,$1))
else
unknown_platform: help;
endif
############
### ruby ###
############
rubyflags =
rubyflags += $(if $(findstring .sdl,$(ruby)),`sdl-config --cflags`)
link += $(if $(findstring video.direct3d,$(ruby)),$(call mklib,d3d9))
link += $(if $(findstring video.directdraw,$(ruby)),$(call mklib,ddraw))
link += $(if $(findstring video.glx,$(ruby)),$(call mklib,GL))
link += $(if $(findstring video.wgl,$(ruby)),$(call mklib,opengl32))
link += $(if $(findstring video.xv,$(ruby)),$(call mklib,Xv))
link += $(if $(findstring audio.alsa,$(ruby)),$(call mklib,asound))
link += $(if $(findstring audio.ao,$(ruby)),$(call mklib,ao))
link += $(if $(findstring audio.directsound,$(ruby)),$(call mklib,dsound))
link += $(if $(findstring audio.openal,$(ruby)),$(if $(call streq,$(platform),x),$(call mklib,openal),$(call mklib,openal32)))
link += $(if $(findstring audio.pulseaudio,$(ruby)),$(call mklib,pulse-simple))
link += $(if $(findstring input.directinput,$(ruby)),$(call mklib,dinput8) $(call mklib,dxguid))
link += $(if $(findstring input.sdl,$(ruby)),`sdl-config --libs`)
####################################
### main target and dependencies ###
####################################
objects = main libco hiro ruby libfilter string \
reader cart cheat \
memory smemory cpu scpu smp ssmp sdsp ppu bppu snes \
bsx srtc sdd1 spc7110 cx4 dsp1 dsp2 dsp3 dsp4 obc1 st010
ifeq ($(enable_gzip),true)
objects += adler32 compress crc32 deflate gzio inffast inflate inftrees ioapi trees unzip zip zutil
flags += $(call mkdef,GZIP_SUPPORT)
endif
ifeq ($(enable_jma),true)
objects += jma jcrc32 lzmadec 7zlzma iiostrm inbyte lzma winout
flags += $(call mkdef,JMA_SUPPORT)
endif
objects := $(patsubst %,obj/%.$(obj),$(objects))
rubydef := $(foreach c,$(subst .,_,$(call strupper,$(ruby))),$(call mkdef,$c))
# Windows resource file
ifeq ($(platform),win)
objects += obj/resource.$(obj)
endif
################
### implicit ###
################
compile = \
$(strip \
$(if $(filter %.c,$<), \
$(c) $1 $(rule), \
$(if $(filter %.cpp,$<), \
$(cpp) $1 $(rule) \
) \
) \
)
%.$(obj): $<; $(call compile)
all: build;
############
### main ###
############
obj/main.$(obj) : ui/main.cpp ui/* ui/base/* ui/event/* ui/loader/* ui/settings/*
obj/resource.$(obj): ui/bsnes.rc; windres ui/bsnes.rc obj/resource.$(obj)
#################
### libraries ###
#################
obj/ruby.$(obj): lib/ruby/ruby.cpp lib/ruby/* lib/ruby/video/* lib/ruby/audio/* lib/ruby/input/*
$(call compile,$(rubydef) $(rubyflags))
obj/hiro.$(obj): lib/hiro/hiro.cpp lib/hiro/* lib/hiro/gtk/* lib/hiro/win/*
$(call compile,$(if $(call streq,$(platform),x),`pkg-config --cflags gtk+-2.0`))
obj/libco.$(obj): lib/libco/libco.c lib/libco/*
$(call compile,$(if $(call strne,$(compiler),cl),-static))
obj/libfilter.$(obj): lib/libfilter/libfilter.cpp lib/libfilter/*
obj/string.$(obj): lib/nall/string.cpp lib/nall/*
#################
### utilities ###
#################
obj/reader.$(obj): reader/reader.cpp reader/*
obj/cart.$(obj) : cart/cart.cpp cart/*
obj/cheat.$(obj) : cheat/cheat.cpp cheat/*
##############
### memory ###
##############
obj/memory.$(obj) : memory/memory.cpp memory/*
obj/smemory.$(obj): memory/smemory/smemory.cpp memory/smemory/* memory/smemory/mapper/*
###########
### cpu ###
###########
obj/cpu.$(obj) : cpu/cpu.cpp cpu/*
obj/scpu.$(obj): cpu/scpu/scpu.cpp cpu/scpu/* cpu/scpu/core/* cpu/scpu/dma/* cpu/scpu/memory/* cpu/scpu/mmio/* cpu/scpu/timing/*
###########
### smp ###
###########
obj/smp.$(obj) : smp/smp.cpp smp/*
obj/ssmp.$(obj): smp/ssmp/ssmp.cpp smp/ssmp/* smp/ssmp/core/* smp/ssmp/memory/* smp/ssmp/timing/*
###########
### dsp ###
###########
obj/adsp.$(obj): dsp/adsp/adsp.cpp dsp/adsp/*
obj/sdsp.$(obj): dsp/sdsp/sdsp.cpp dsp/sdsp/*
###########
### ppu ###
###########
obj/ppu.$(obj) : ppu/ppu.cpp ppu/*
obj/bppu.$(obj): ppu/bppu/bppu.cpp ppu/bppu/*
############
### snes ###
############
obj/snes.$(obj): snes/snes.cpp snes/* snes/scheduler/* snes/video/* snes/audio/* snes/input/*
#####################
### special chips ###
#####################
obj/bsx.$(obj) : chip/bsx/bsx.cpp chip/bsx/*
obj/srtc.$(obj) : chip/srtc/srtc.cpp chip/srtc/*
obj/sdd1.$(obj) : chip/sdd1/sdd1.cpp chip/sdd1/*
obj/spc7110.$(obj): chip/spc7110/spc7110.cpp chip/spc7110/*
obj/cx4.$(obj) : chip/cx4/cx4.cpp chip/cx4/*
obj/dsp1.$(obj) : chip/dsp1/dsp1.cpp chip/dsp1/*
obj/dsp2.$(obj) : chip/dsp2/dsp2.cpp chip/dsp2/*
obj/dsp3.$(obj) : chip/dsp3/dsp3.cpp chip/dsp3/*
obj/dsp4.$(obj) : chip/dsp4/dsp4.cpp chip/dsp4/*
obj/obc1.$(obj) : chip/obc1/obc1.cpp chip/obc1/*
obj/st010.$(obj) : chip/st010/st010.cpp chip/st010/*
############
### zlib ###
############
obj/adler32.$(obj) : reader/zlib/adler32.c reader/zlib/*
obj/compress.$(obj): reader/zlib/compress.c reader/zlib/*
obj/crc32.$(obj) : reader/zlib/crc32.c reader/zlib/*
obj/deflate.$(obj) : reader/zlib/deflate.c reader/zlib/*
obj/gzio.$(obj) : reader/zlib/gzio.c reader/zlib/*
obj/inffast.$(obj) : reader/zlib/inffast.c reader/zlib/*
obj/inflate.$(obj) : reader/zlib/inflate.c reader/zlib/*
obj/inftrees.$(obj): reader/zlib/inftrees.c reader/zlib/*
obj/ioapi.$(obj) : reader/zlib/ioapi.c reader/zlib/*
obj/trees.$(obj) : reader/zlib/trees.c reader/zlib/*
obj/unzip.$(obj) : reader/zlib/unzip.c reader/zlib/*
obj/zip.$(obj) : reader/zlib/zip.c reader/zlib/*
obj/zutil.$(obj) : reader/zlib/zutil.c reader/zlib/*
###########
### jma ###
###########
obj/jma.$(obj) : reader/jma/jma.cpp reader/jma/*
obj/jcrc32.$(obj) : reader/jma/jcrc32.cpp reader/jma/*
obj/lzmadec.$(obj): reader/jma/lzmadec.cpp reader/jma/*
obj/7zlzma.$(obj) : reader/jma/7zlzma.cpp reader/jma/*
obj/iiostrm.$(obj): reader/jma/iiostrm.cpp reader/jma/*
obj/inbyte.$(obj) : reader/jma/inbyte.cpp reader/jma/*
obj/lzma.$(obj) : reader/jma/lzma.cpp reader/jma/*
obj/winout.$(obj) : reader/jma/winout.cpp reader/jma/*
###############
### targets ###
###############
build: $(objects)
$(strip $(cpp) $(call mkbin,../bsnes) $(objects) $(link))
install:
install -D -m 755 ../bsnes $(DESTDIR)$(prefix)/bin/bsnes
install -D -m 644 data/bsnes.png $(DESTDIR)$(prefix)/share/icons/bsnes.png
clean:
-@$(call delete,obj/*.$(obj))
-@$(call delete,*.res)
-@$(call delete,*.pgd)
-@$(call delete,*.pgc)
-@$(call delete,*.ilk)
-@$(call delete,*.pdb)
-@$(call delete,*.manifest)
help:
@echo "Usage: $(MAKE) platform=(os) compiler=(cc) [options]"
@echo ""
@echo "Supported platforms:"
@echo " x - Linux / BSD (x86, x86-64)"
@echo " win - Windows (x86, x86-64)"
@echo ""
@echo "Supported compilers:"
@echo " gcc - GCC compiler"
@echo " mingw32-gcc - MinGW compiler"
@echo " i586-mingw32-gcc - MinGW cross compiler"
@echo " cl - Visual C++"
@echo ""
@echo "Available options:"
@echo " enable_gzip=[true|false] - Enable ZIP / GZ support (default=false)"
@echo " enable_jma=[true|false] - Enable JMA support (default=false)"
@echo ""
@echo "Example: $(MAKE) platform=x compiler=gcc enable_gzip=true"
@echo ""

View File

@@ -1,58 +0,0 @@
#define BSNES_VERSION "0.021"
#define BSNES_TITLE "bsnes v" BSNES_VERSION
#define MEMCORE bMemBus
#define CPUCORE sCPU
#define SMPCORE sSMP
#define DSPCORE bDSP
#define PPUCORE bPPU
//#define FAVOR_ACCURACY
#define FAVOR_SPEED
//game genie + pro action replay code support (~1-3% speed hit)
#define CHEAT_SYSTEM
//snes core polymorphism
//(allow runtime cpu/smp/dsp/ppu/bus selection, ~10% speed hit)
//#define POLYMORPHISM
#include "lib/libbase.h"
#if defined(PROCESSOR_X86)
#define ARCH_LSB
#include "lib/libco_x86.h"
#elif defined(PROCESSOR_X86_64)
#define ARCH_LSB
#include "lib/libco_x86_64.h"
#elif defined(PROCESSOR_G5)
#define ARCH_MSB
#else
#error "unsupported processor"
#endif
#include "lib/libsort.h"
#include "lib/libarray.h"
#include "lib/libvector.h"
#include "lib/libstring.h"
#include "lib/libconfig.h"
//platform-specific global functions
void alert(char*, ...);
void dprintf(char*, ...);
void dprintf(uint, char*, ...);
namespace source {
enum {
none = 0,
debug,
cpu,
ppu,
smp,
dsp,
bus,
};
};
//various class interfaces
#include "interface.h"

49
src/base.hpp Normal file
View File

@@ -0,0 +1,49 @@
#define BSNES_VERSION "0.039"
#define BSNES_TITLE "bsnes v" BSNES_VERSION
#define BUSCORE sBus
#define CPUCORE sCPU
#define SMPCORE sSMP
#define DSPCORE sDSP
#define PPUCORE bPPU
//S-DSP can be encapsulated into a state machine using #define magic
//this avoids ~2.048m co_switch() calls per second (~5% speedup)
#define USE_STATE_MACHINE
//FAST_FRAMESKIP disables calculation of RTO during frameskip
//frameskip offers near-zero speedup if RTO is calculated
//accuracy is not affected by this define when frameskipping is off
#define FAST_FRAMESKIP
//game genie + pro action replay code support (~2% speed hit)
#define CHEAT_SYSTEM
#include <libco/libco.h>
#include <nall/algorithm.hpp>
#include <nall/array.hpp>
#include <nall/bit.hpp>
#include <nall/detect.hpp>
#include <nall/endian.hpp>
#include <nall/file.hpp>
#include <nall/function.hpp>
#include <nall/moduloarray.hpp>
#include <nall/new.hpp>
#include <nall/platform.hpp>
#include <nall/stdint.hpp>
#include <nall/string.hpp>
#include <nall/utility.hpp>
#include <nall/vector.hpp>
using namespace nall;
typedef int8_t int8;
typedef int16_t int16;
typedef int32_t int32;
typedef int64_t int64;
typedef uint8_t uint8;
typedef uint16_t uint16;
typedef uint32_t uint32;
typedef uint64_t uint64;
#include "interface.hpp"

Binary file not shown.

View File

@@ -1,156 +1,199 @@
#include "../base.h"
#include "database.cpp"
#include <../base.hpp>
#include <../chip/chip.hpp>
#include <../reader/reader.hpp>
#define CART_CPP
#include <nall/crc32.hpp>
#include <nall/ups.hpp>
#include "cart.hpp"
#include "cart_load.cpp"
#include "cart_normal.cpp"
#include "cart_bsx.cpp"
#include "cart_bsc.cpp"
#include "cart_st.cpp"
#include "cart_stdual.cpp"
#include "cart_file.cpp"
#include "cart_header.cpp"
namespace memory {
MappedRAM cartrom, cartram, cartrtc;
MappedRAM bscram;
MappedRAM stArom, stAram;
MappedRAM stBrom, stBram;
};
Cartridge cartridge;
void Cartridge::load_begin(uint cart_type) {
if(loaded() == true)return;
const char* Cartridge::name() const { return info.filename; }
Cartridge::CartridgeMode Cartridge::mode() const { return info.mode; }
Cartridge::MemoryMapper Cartridge::mapper() const { return info.mapper; }
Cartridge::Region Cartridge::region() const { return info.region; }
bool Cartridge::loaded() const { return cart.loaded; }
info.type = cart_type;
void Cartridge::load_begin(CartridgeMode mode) {
cart.rom = cart.ram = cart.rtc = 0;
bs.ram = 0;
stA.rom = stA.ram = 0;
stB.rom = stB.ram = 0;
info.srtc = false;
info.sdd1 = false;
info.c4 = false;
info.dsp1 = false;
info.dsp2 = false;
info.obc1 = false;
cart.rom_size = cart.ram_size = cart.rtc_size = 0;
bs.ram_size = 0;
stA.rom_size = stA.ram_size = 0;
stB.rom_size = stB.ram_size = 0;
info.dsp1_mapper = 0;
info.mode = mode;
info.patched = false;
info.header_index = 0xffc0;
info.mapper = PCB;
strcpy(info.name, "");
strcpy(info.pcb, "");
info.region = NTSC;
info.cart_mmio = false;
info.rom_size = 0;
info.ram_size = 0;
file.count = 0;
for(int i = 0; i < 8; i++) {
strcpy(file.rom_name[i], "");
strcpy(file.ram_name[i], "");
file.rom_size[i] = 0;
file.ram_size[i] = 0;
file.rom_data[i] = 0;
file.ram_data[i] = 0;
}
info.bsxcart = false;
info.bsxflash = false;
}
void Cartridge::load(const char *rom_fn) {
if(!rom_fn || !*rom_fn)return;
void Cartridge::load_end() {
memory::cartrom.map(cart.rom, cart.rom_size);
memory::cartram.map(cart.ram, cart.ram_size);
memory::cartrtc.map(cart.rtc, cart.rtc_size);
memory::bscram.map(bs.ram, bs.ram_size);
memory::stArom.map(stA.rom, stA.rom_size);
memory::stAram.map(stA.ram, stA.ram_size);
memory::stBrom.map(stB.rom, stB.rom_size);
memory::stBram.map(stB.ram, stB.ram_size);
char fn[4096], ram_fn[4096];
strcpy(fn, rom_fn);
//correct folder slashes
for(int i = strlen(fn) - 1; i >= 0; i--) {
if(fn[i] == '\\')fn[i] = '/';
}
memory::cartrom.write_protect(true);
memory::cartram.write_protect(false);
memory::bscram.write_protect(true);
memory::stArom.write_protect(true);
memory::stAram.write_protect(false);
memory::stBrom.write_protect(true);
memory::stBram.write_protect(false);
uint i = file.count++;
strcpy(file.rom_name[i], fn);
strcpy(fn, rom_fn);
//remove ROM extension
for(int i = strlen(fn) - 1; i >= 0; i--) {
if(fn[i] == '.') {
fn[i] = 0;
break;
}
}
if(i == 0) {
strcpy(file.patch_name, fn);
strcat(file.patch_name, ".ups");
}
strcpy(fn, strptr(config::file_updatepath(fn, config::path.save)));
if(i == 0) {
strcpy(file.cheat_name, fn);
strcat(file.cheat_name, ".cht");
}
strcpy(file.ram_name[i], fn);
strcat(file.ram_name[i], ".");
strcat(file.ram_name[i], config::path.save_ext);
}
bool Cartridge::load_end() {
for(int i = 0; i < file.count; i++) {
load_file(file.rom_name[i], file.rom_data[i], file.rom_size[i]);
}
if(fexists(file.cheat_name) == true) {
if(file::exists(get_cheat_filename(cart.fn, "cht"))) {
cheat.clear();
cheat.load(file.cheat_name);
cheat.load(cheatfn);
}
switch(info.type) {
case CART_NORMAL: {
load_rom_normal();
load_ram_normal();
} break;
case CART_ST: {
load_rom_st();
load_ram_st();
} break;
case CART_STDUAL: {
load_rom_stdual();
load_ram_stdual();
} break;
}
cart_loaded = true;
r_mem->load_cart();
return true;
cart.loaded = true;
bus.load_cart();
}
bool Cartridge::unload() {
if(cart_loaded == false)return false;
if(cart.loaded == false) return false;
r_mem->unload_cart();
bus.unload_cart();
switch(info.type) {
case CART_NORMAL: {
save_ram_normal();
} break;
case CART_ST: {
save_ram_st();
} break;
case CART_STDUAL: {
save_ram_stdual();
} break;
switch(info.mode) {
case ModeNormal: unload_cart_normal(); break;
case ModeBSX: unload_cart_bsx(); break;
case ModeBSC: unload_cart_bsc(); break;
case ModeSufamiTurbo: unload_cart_st(); break;
}
safe_free(rom);
safe_free(ram);
if(cart.rom) { delete[] cart.rom; cart.rom = 0; }
if(cart.ram) { delete[] cart.ram; cart.ram = 0; }
if(cart.rtc) { delete[] cart.rtc; cart.rtc = 0; }
if(bs.ram) { delete[] bs.ram; bs.ram = 0; }
if(stA.rom) { delete[] stA.rom; stA.rom = 0; }
if(stA.ram) { delete[] stA.ram; stA.ram = 0; }
if(stB.rom) { delete[] stB.rom; stB.rom = 0; }
if(stB.ram) { delete[] stB.ram; stB.ram = 0; }
if(cheat.count() > 0 || fexists(file.cheat_name) == true) {
cheat.save(file.cheat_name);
if(cheat.count() > 0 || file::exists(get_cheat_filename(cart.fn, "cht"))) {
cheat.save(cheatfn);
cheat.clear();
}
cart_loaded = false;
cart.loaded = false;
return true;
}
Cartridge::Cartridge() {
load_database();
cart_loaded = false;
rom = 0;
ram = 0;
cart.loaded = false;
}
Cartridge::~Cartridge() {
if(cart_loaded == true) {
unload();
}
if(cart.loaded == true) unload();
}
//==========
//cartinfo_t
//==========
void Cartridge::cartinfo_t::reset() {
type = TypeUnknown;
mapper = LoROM;
dsp1_mapper = DSP1Unmapped;
region = NTSC;
rom_size = 0;
ram_size = 0;
bsxslot = false;
superfx = false;
sa1 = false;
srtc = false;
sdd1 = false;
spc7110 = false;
spc7110rtc = false;
cx4 = false;
dsp1 = false;
dsp2 = false;
dsp3 = false;
dsp4 = false;
obc1 = false;
st010 = false;
st011 = false;
st018 = false;
}
//apply cart-specific settings to current cartridge mode settings
Cartridge::info_t& Cartridge::info_t::operator=(const Cartridge::cartinfo_t &source) {
mapper = source.mapper;
dsp1_mapper = source.dsp1_mapper;
region = source.region;
bsxslot = source.bsxslot;
superfx = source.superfx;
sa1 = source.sa1;
srtc = source.srtc;
sdd1 = source.sdd1;
spc7110 = source.spc7110;
spc7110rtc = source.spc7110rtc;
cx4 = source.cx4;
dsp1 = source.dsp1;
dsp2 = source.dsp2;
dsp3 = source.dsp3;
dsp4 = source.dsp4;
obc1 = source.obc1;
st010 = source.st010;
st011 = source.st011;
st018 = source.st018;
return *this;
}
//=======
//utility
//=======
string Cartridge::filepath(const char *filename, const char *pathname) {
//if no pathname, return filename as-is
string file(filename);
replace(file, "\\", "/");
if(!pathname || !*pathname) return file;
//ensure path ends with trailing '/'
string path(pathname);
replace(path, "\\", "/");
if(!strend(path, "/")) strcat(path, "/");
//replace relative path with absolute path
if(strbegin(path, "./")) {
ltrim(path, "./");
path = string() << snes.config.path.base << path;
}
//remove folder part of filename
lstring part;
split(part, "/", file);
return path << part[count(part) - 1];
}

View File

@@ -1,125 +0,0 @@
class Cartridge {
public:
/*****
* cart database
*****/
#include "db/db.h"
db_item dbi;
uint8 *database;
uint database_size;
uint database_blocksize;
void load_database();
bool read_database();
//
enum {
CART_NORMAL,
CART_ST,
CART_STDUAL,
};
bool cart_loaded;
uint8 rom_header[512], *rom, *ram;
enum {
//header fields
CART_NAME = 0x00,
MAPPER = 0x15,
ROM_TYPE = 0x16,
ROM_SIZE = 0x17,
RAM_SIZE = 0x18,
REGION = 0x19,
LICENSE = 0x1a,
VERSION = 0x1b,
ICKSUM = 0x1c,
CKSUM = 0x1e,
RESL = 0x3c,
RESH = 0x3d,
//regions
NTSC = 0,
PAL = 1,
//memory mappers
PCB = 0x00,
LOROM = 0x20,
HIROM = 0x21,
EXLOROM = 0x22,
EXHIROM = 0x25,
//special chip memory mappers
DSP1_LOROM_1MB = 1,
DSP1_LOROM_2MB = 2,
DSP1_HIROM = 3,
};
struct {
uint count;
char cheat_name[4096], patch_name[4096];
char rom_name[8][4096], ram_name[8][4096];
uint rom_size[8], ram_size[8];
uint8 *rom_data[8], *ram_data[8];
} file;
struct {
uint type;
//cart information
uint32 crc32;
char name[128];
char pcb[32];
uint region;
uint mapper;
uint rom_size;
uint ram_size;
//set to true for games that need cart MMIO mapping (c4, dsp-n, ...),
//for games that map outside the standard MMIO range of $2000-$5fff
bool cart_mmio;
bool srtc;
bool sdd1;
bool c4;
bool dsp1;
bool dsp2;
bool obc1;
uint dsp1_mapper;
//HiROM / LoROM specific code
uint header_index;
} info;
bool load_file(const char *fn, uint8 *&data, uint &size);
bool save_file(const char *fn, uint8 *data, uint size);
void load_rom_normal();
void load_ram_normal();
void save_ram_normal();
void load_rom_st();
void load_ram_st();
void save_ram_st();
void load_rom_stdual();
void load_ram_stdual();
void save_ram_stdual();
void find_header();
void read_header();
bool loaded() { return cart_loaded; }
void load_begin(uint cart_type);
void load(const char *rom_fn);
bool load_end();
bool unload();
Cartridge();
~Cartridge();
};
extern Cartridge cartridge;

205
src/cart/cart.hpp Normal file
View File

@@ -0,0 +1,205 @@
class Cartridge {
public:
enum CartridgeMode {
ModeNormal,
ModeBSC,
ModeBSX,
ModeSufamiTurbo,
};
enum CartridgeType {
TypeNormal,
TypeBSC,
TypeBSXBIOS,
TypeBSX,
TypeSufamiTurboBIOS,
TypeSufamiTurbo,
TypeUnknown,
};
enum HeaderField {
CartName = 0x00,
Mapper = 0x15,
RomType = 0x16,
RomSize = 0x17,
RamSize = 0x18,
CartRegion = 0x19,
Company = 0x1a,
Version = 0x1b,
Complement = 0x1c, //inverse checksum
Checksum = 0x1e,
ResetVector = 0x3c,
};
enum Region {
NTSC,
PAL,
};
enum MemoryMapper {
LoROM,
HiROM,
ExLoROM,
ExHiROM,
SPC7110ROM,
BSCLoROM,
BSCHiROM,
BSXROM,
STROM,
};
enum DSP1MemoryMapper {
DSP1Unmapped,
DSP1LoROM1MB,
DSP1LoROM2MB,
DSP1HiROM,
};
const char* name() const;
CartridgeMode mode() const;
MemoryMapper mapper() const;
Region region() const;
struct {
bool loaded;
char fn[PATH_MAX];
uint8 *rom, *ram, *rtc;
unsigned rom_size, ram_size, rtc_size;
} cart;
struct {
char fn[PATH_MAX];
uint8 *ram;
unsigned ram_size;
} bs;
struct {
char fn[PATH_MAX];
uint8 *rom, *ram;
unsigned rom_size, ram_size;
} stA, stB;
struct cartinfo_t {
CartridgeType type;
MemoryMapper mapper;
DSP1MemoryMapper dsp1_mapper;
Region region;
unsigned rom_size;
unsigned ram_size;
bool bsxslot;
bool superfx;
bool sa1;
bool srtc;
bool sdd1;
bool spc7110;
bool spc7110rtc;
bool cx4;
bool dsp1;
bool dsp2;
bool dsp3;
bool dsp4;
bool obc1;
bool st010;
bool st011;
bool st018;
void reset();
};
struct info_t {
char filename[PATH_MAX * 4];
bool patched;
CartridgeMode mode;
MemoryMapper mapper;
DSP1MemoryMapper dsp1_mapper;
Region region;
bool bsxcart; //is BS-X cart inserted?
bool bsxflash; //is BS-X flash cart inserted into BS-X cart?
bool bsxslot;
bool superfx;
bool sa1;
bool srtc;
bool sdd1;
bool spc7110;
bool spc7110rtc;
bool cx4;
bool dsp1;
bool dsp2;
bool dsp3;
bool dsp4;
bool obc1;
bool st010;
bool st011;
bool st018;
info_t& operator=(const cartinfo_t&);
} info;
struct {
char fn[PATH_MAX];
uint8_t *data;
unsigned size;
} image;
bool load_image(const char*);
bool inspect_image(cartinfo_t &cartinfo, const char *filename);
bool load_ram(const char *filename, uint8_t *&data, unsigned size, uint8_t init);
void load_cart_normal(const char*);
void load_cart_bsc(const char*, const char*);
void load_cart_bsx(const char*, const char*);
void load_cart_st(const char*, const char*, const char*);
void unload_cart_normal();
void unload_cart_bsx();
void unload_cart_bsc();
void unload_cart_st();
bool loaded() const;
void load_begin(CartridgeMode);
void load_end();
bool unload();
void read_header(cartinfo_t &info, const uint8_t *data, unsigned size);
unsigned find_header(const uint8_t *data, unsigned size);
unsigned score_header(const uint8_t *data, unsigned size, unsigned addr);
enum CompressionMode {
CompressionNone, //always load without compression
CompressionInspect, //use file header inspection
CompressionAuto, //use file extension or file header inspection (configured by user)
};
bool load_file(const char *fn, uint8 *&data, unsigned &size, CompressionMode compression = CompressionNone);
bool save_file(const char *fn, uint8 *data, unsigned size);
bool apply_patch(const uint8_t *pdata, unsigned psize, uint8_t *&data, unsigned &size);
char* modify_extension(char *filename, const char *extension);
char* get_base_filename(char *filename);
char* get_path_filename(char *filename, const char *path, const char *source, const char *extension);
char* get_patch_filename(const char *source, const char *extension);
char* get_save_filename(const char *source, const char *extension);
char* get_cheat_filename(const char *source, const char *extension);
static string filepath(const char *filename, const char *pathname);
Cartridge();
~Cartridge();
private:
char patchfn[PATH_MAX];
char savefn[PATH_MAX];
char rtcfn[PATH_MAX];
char cheatfn[PATH_MAX];
};
namespace memory {
extern MappedRAM cartrom, cartram, cartrtc;
extern MappedRAM bscram;
extern MappedRAM stArom, stAram;
extern MappedRAM stBrom, stBram;
};
extern Cartridge cartridge;

44
src/cart/cart_bsc.cpp Normal file
View File

@@ -0,0 +1,44 @@
#ifdef CART_CPP
void Cartridge::load_cart_bsc(const char *base, const char *slot) {
uint8_t *data;
unsigned size;
strcpy(cart.fn, base);
strcpy(bs.fn, slot);
load_begin(ModeBSC);
if(load_image(base) == false) return;
cartinfo_t cartinfo;
read_header(cartinfo, cart.rom = image.data, cart.rom_size = image.size);
info = cartinfo;
if(load_image(slot) == true) {
info.bsxflash = true;
bs.ram = image.data;
bs.ram_size = image.size;
}
if(cartinfo.ram_size > 0) {
load_ram(get_save_filename(base, "srm"), cart.ram, cart.ram_size = cartinfo.ram_size, 0xff);
}
load_end();
//set base filename
strcpy(info.filename, base);
get_base_filename(info.filename);
if(*slot) {
char filenameBS[PATH_MAX];
strcpy(filenameBS, slot);
get_base_filename(filenameBS);
strcat(info.filename, " + ");
strcat(info.filename, filenameBS);
}
}
void Cartridge::unload_cart_bsc() {
if(cart.ram) save_file(get_save_filename(cart.fn, "srm"), cart.ram, cart.ram_size);
}
#endif

49
src/cart/cart_bsx.cpp Normal file
View File

@@ -0,0 +1,49 @@
#ifdef CART_CPP
void Cartridge::load_cart_bsx(const char *base, const char *slot) {
uint8_t *data;
unsigned size;
strcpy(cart.fn, base);
strcpy(bs.fn, slot);
load_begin(ModeBSX);
if(load_image(base) == false) return;
info.bsxcart = true;
cartinfo_t cartinfo;
read_header(cartinfo, cart.rom = image.data, cart.rom_size = image.size);
info = cartinfo;
cart.ram = 0;
cart.ram_size = 0;
memset(bsxcart.sram.handle (), 0x00, bsxcart.sram.size ());
memset(bsxcart.psram.handle(), 0x00, bsxcart.psram.size());
if(load_file(get_save_filename(cart.fn, "srm"), data, size, CompressionNone) == true) {
memcpy(bsxcart.sram.handle (), data, min(bsxcart.sram.size (), size));
delete[] data;
}
if(load_file(get_save_filename(cart.fn, "psr"), data, size, CompressionNone) == true) {
memcpy(bsxcart.psram.handle(), data, min(bsxcart.psram.size(), size));
delete[] data;
}
if(load_image(slot)) {
info.bsxflash = true;
bs.ram = image.data;
bs.ram_size = image.size;
}
load_end();
strcpy(info.filename, !*slot ? base : slot);
get_base_filename(info.filename);
}
void Cartridge::unload_cart_bsx() {
save_file(get_save_filename(cart.fn, "srm"), bsxcart.sram.handle (), bsxcart.sram.size ());
save_file(get_save_filename(cart.fn, "psr"), bsxcart.psram.handle(), bsxcart.psram.size());
}
#endif

View File

@@ -1,72 +1,152 @@
#include "../reader/filereader.h"
#if defined(GZIP_SUPPORT)
#include "../reader/gzreader.h"
#include "../reader/zipreader.h"
#endif
#if defined(JMA_SUPPORT)
#include "../reader/jmareader.h"
#endif
bool Cartridge::load_file(const char *fn, uint8 *&data, uint &size) {
dprintf("* Loading \"%s\"...", fn);
if(fexists(fn) == false) {
return false;
}
switch(Reader::detect(fn)) {
case Reader::RF_NORMAL: {
FileReader ff(fn);
if(!ff.ready()) {
alert("Error loading image file (%s)!", fn);
return false;
}
size = ff.size();
data = ff.read();
} break;
#ifdef GZIP_SUPPORT
case Reader::RF_GZ: {
GZReader gf(fn);
if(!gf.ready()) {
alert("Error loading image file (%s)!", fn);
return false;
}
size = gf.size();
data = gf.read();
} break;
case Reader::RF_ZIP: {
ZipReader zf(fn);
size = zf.size();
data = zf.read();
} break;
#endif
#ifdef JMA_SUPPORT
case Reader::RF_JMA: {
try {
JMAReader jf(fn);
size = jf.size();
data = jf.read();
} catch(JMA::jma_errors jma_error) {
alert("Error loading image file (%s)!", fn);
return false;
}
} break;
#endif
}
return true;
}
bool Cartridge::save_file(const char *fn, uint8 *data, uint size) {
FileWriter ff(fn);
if(!ff.ready())return false;
ff.write(data, size);
return true;
}
#ifdef CART_CPP
#include "../reader/filereader.hpp"
#if defined(GZIP_SUPPORT)
#include "../reader/gzreader.hpp"
#include "../reader/zipreader.hpp"
#endif
#if defined(JMA_SUPPORT)
#include "../reader/jmareader.hpp"
#endif
char* Cartridge::modify_extension(char *filename, const char *extension) {
int i;
for(i = strlen(filename); i >= 0; i--) {
if(filename[i] == '.') break;
if(filename[i] == '/') break;
if(filename[i] == '\\') break;
}
if(i > 0 && filename[i] == '.') filename[i] = 0;
strcat(filename, ".");
strcat(filename, extension);
return filename;
}
//remove directory information and file extension ("/foo/bar.ext" -> "bar")
char* Cartridge::get_base_filename(char *filename) {
//remove extension
for(int i = strlen(filename) - 1; i >= 0; i--) {
if(filename[i] == '.') {
filename[i] = 0;
break;
}
}
//remove directory information
for(int i = strlen(filename) - 1; i >= 0; i--) {
if(filename[i] == '/' || filename[i] == '\\') {
i++;
char *output = filename;
while(true) {
*output++ = filename[i];
if(!filename[i]) break;
i++;
}
break;
}
}
return filename;
}
char* Cartridge::get_path_filename(char *filename, const char *path, const char *source, const char *extension) {
strcpy(filename, source);
modify_extension(filename, extension);
strcpy(filename, filepath(filename, path));
return filename;
}
char* Cartridge::get_patch_filename(const char *source, const char *extension) {
return get_path_filename(patchfn, snes.config.path.patch, source, extension);
}
char* Cartridge::get_save_filename(const char *source, const char *extension) {
return get_path_filename(savefn, snes.config.path.save, source, extension);
}
char* Cartridge::get_cheat_filename(const char *source, const char *extension) {
return get_path_filename(cheatfn, snes.config.path.cheat, source, extension);
}
bool Cartridge::load_file(const char *fn, uint8 *&data, unsigned &size, CompressionMode compression) {
if(file::exists(fn) == false) return false;
Reader::Type filetype = Reader::Normal;
if(compression == CompressionInspect) filetype = Reader::detect(fn, true);
if(compression == CompressionAuto) filetype = Reader::detect(fn, snes.config.file.autodetect_type);
switch(filetype) { default:
case Reader::Normal: {
FileReader ff(fn);
if(!ff.ready()) return false;
size = ff.size();
data = ff.read();
} break;
#ifdef GZIP_SUPPORT
case Reader::GZIP: {
GZReader gf(fn);
if(!gf.ready()) return false;
size = gf.size();
data = gf.read();
} break;
case Reader::ZIP: {
ZipReader zf(fn);
if(!zf.ready()) return false;
size = zf.size();
data = zf.read();
} break;
#endif
#ifdef JMA_SUPPORT
case Reader::JMA: {
try {
JMAReader jf(fn);
size = jf.size();
data = jf.read();
} catch(JMA::jma_errors jma_error) {
return false;
}
} break;
#endif
}
return true;
}
bool Cartridge::apply_patch(const uint8_t *pdata, const unsigned psize, uint8_t *&data, unsigned &size) {
uint8_t *outdata = 0;
unsigned outsize;
ups patcher;
ups::result result = patcher.apply(pdata, psize, data, size, outdata, outsize);
bool apply = false;
if(result == ups::ok) apply = true;
if(snes.config.file.bypass_patch_crc32 == true) {
if(result == ups::input_crc32_invalid) apply = true;
if(result == ups::output_crc32_invalid) apply = true;
}
//if patch application was successful, replace old data, size with new data, size
if(apply == true) {
delete[] data;
data = new uint8_t[size = outsize];
memcpy(data, outdata, outsize);
}
if(outdata) delete[] outdata;
return apply;
}
bool Cartridge::save_file(const char *fn, uint8 *data, unsigned size) {
file fp;
if(!fp.open(fn, file::mode_write)) return false;
fp.write(data, size);
fp.close();
return true;
}
#endif

View File

@@ -1,149 +1,273 @@
void Cartridge::read_header() {
info.srtc = false;
info.sdd1 = false;
info.c4 = false;
info.dsp1 = false;
info.dsp2 = false;
info.obc1 = false;
info.dsp1_mapper = 0;
if(info.header_index == 0x7fc0 && info.rom_size >= 0x401000) {
info.mapper = EXLOROM;
strcpy(info.pcb, "UNL-EXLOROM");
} else if(info.header_index == 0x7fc0 && rom[info.header_index + MAPPER] == 0x32) {
info.mapper = EXLOROM;
strcpy(info.pcb, "UNL-EXLOROM");
} else if(info.header_index == 0x7fc0) {
info.mapper = LOROM;
strcpy(info.pcb, "UNL-LOROM");
} else if(info.header_index == 0xffc0) {
info.mapper = HIROM;
strcpy(info.pcb, "UNL-HIROM");
} else { //info.header_index == 0x40ffc0
info.mapper = EXHIROM;
strcpy(info.pcb, "UNL-EXHIROM");
}
uint8 mapper = rom[info.header_index + MAPPER];
uint8 rom_type = rom[info.header_index + ROM_TYPE];
if(mapper == 0x35 && rom_type == 0x55) {
info.srtc = true;
}
if(mapper == 0x32 && (rom_type == 0x43 || rom_type == 0x45)) {
info.sdd1 = true;
}
if(mapper == 0x20 && rom_type == 0xf3) {
info.c4 = true;
}
if((mapper == 0x20 || mapper == 0x21) && rom_type == 0x03) {
info.dsp1 = true;
}
if(mapper == 0x30 && rom_type == 0x05) {
info.dsp1 = true;
}
if(mapper == 0x31 && (rom_type == 0x03 || rom_type == 0x05)) {
info.dsp1 = true;
}
if(info.dsp1 == true) {
if((mapper & 0x2f) == 0x20 && info.rom_size <= 0x100000) {
info.dsp1_mapper = DSP1_LOROM_1MB;
} else if((mapper & 0x2f) == 0x20) {
info.dsp1_mapper = DSP1_LOROM_2MB;
} else if((mapper & 0x2f) == 0x21) {
info.dsp1_mapper = DSP1_HIROM;
}
}
if(mapper == 0x20 && rom_type == 0x05) {
info.dsp2 = true;
}
if(mapper == 0x30 && rom_type == 0x25) {
info.obc1 = true;
}
info.cart_mmio = info.c4 | info.dsp1 | info.dsp2 | info.obc1;
if(rom[info.header_index + RAM_SIZE] & 7) {
info.ram_size = 1024 << (rom[info.header_index + RAM_SIZE] & 7);
} else {
info.ram_size = 0;
}
memcpy(&info.name, &rom[info.header_index + CART_NAME], 21);
info.name[21] = 0;
for(int i = 0; i < 22; i++) {
if(info.name[i] & 0x80) {
info.name[i] = '?';
}
}
}
void Cartridge::find_header() {
int32 score_lo = 0,
score_hi = 0,
score_ex = 0;
if(info.rom_size < 0x010000) {
//cart too small to be anything but lorom
info.header_index = 0x007fc0;
return;
}
if((rom[0x7fc0 + MAPPER] & ~0x10) == 0x20)score_lo++;
if((rom[0xffc0 + MAPPER] & ~0x10) == 0x21)score_hi++;
if(rom[0x7fc0 + ROM_TYPE] < 0x08)score_lo++;
if(rom[0xffc0 + ROM_TYPE] < 0x08)score_hi++;
if(rom[0x7fc0 + ROM_SIZE] < 0x10)score_lo++;
if(rom[0xffc0 + ROM_SIZE] < 0x10)score_hi++;
if(rom[0x7fc0 + RAM_SIZE] < 0x08)score_lo++;
if(rom[0xffc0 + RAM_SIZE] < 0x08)score_hi++;
if(rom[0x7fc0 + REGION] < 14)score_lo++;
if(rom[0xffc0 + REGION] < 14)score_hi++;
if(rom[0x7fc0 + LICENSE] < 3)score_lo++;
if(rom[0xffc0 + LICENSE] < 3)score_hi++;
if(rom[0x7fc0 + RESH] & 0x80)score_lo += 2;
if(rom[0xffc0 + RESH] & 0x80)score_hi += 2;
uint16 cksum, icksum;
cksum = rom[0x7fc0 + CKSUM] | (rom[0x7fc0 + CKSUM + 1] << 8);
icksum = rom[0x7fc0 + ICKSUM] | (rom[0x7fc0 + ICKSUM + 1] << 8);
if((cksum + icksum) == 0xffff && (cksum != 0) && (icksum != 0)) {
score_lo += 8;
}
cksum = rom[0xffc0 + CKSUM] | (rom[0xffc0 + CKSUM + 1] << 8);
icksum = rom[0xffc0 + ICKSUM] | (rom[0xffc0 + ICKSUM + 1] << 8);
if((cksum + icksum) == 0xffff && (cksum != 0) && (icksum != 0)) {
score_hi += 8;
}
if(info.rom_size < 0x401000) {
score_ex = 0;
} else {
if(rom[0x7fc0 + MAPPER] == 0x32)score_lo++;
else score_ex += 16;
}
if(score_lo >= score_hi && score_lo >= score_ex) {
info.header_index = 0x007fc0;
} else if(score_hi >= score_ex) {
info.header_index = 0x00ffc0;
} else {
info.header_index = 0x40ffc0;
}
}
#ifdef CART_CPP
void Cartridge::read_header(cartinfo_t &info, const uint8_t *data, unsigned size) {
info.reset();
unsigned index = find_header(data, size);
//=======================
//detect BS-X flash carts
//=======================
if(data[index + 0x13] == 0x00 || data[index + 0x13] == 0xff) {
if(data[index + 0x14] == 0x00) {
const uint8_t n15 = data[index + 0x15];
if(n15 == 0x00 || n15 == 0x80 || n15 == 0x84 || n15 == 0x9c || n15 == 0xbc || n15 == 0xfc) {
if(data[index + 0x1a] == 0x33 || data[index + 0x1a] == 0xff) {
info.type = TypeBSX;
info.mapper = BSXROM;
info.region = NTSC; //BS-X only released in Japan
return;
}
}
}
}
//=========================
//detect Sufami Turbo carts
//=========================
if(!memcmp(data, "BANDAI SFC-ADX", 14)) {
if(!memcmp(data + 16, "SFC-ADX BACKUP", 14)) {
info.type = TypeSufamiTurboBIOS;
} else {
info.type = TypeSufamiTurbo;
}
info.mapper = STROM;
info.region = NTSC; //Sufami Turbo only released in Japan
return; //RAM size handled internally by load_cart_st();
}
//=====================
//detect standard carts
//=====================
const uint8 mapper = data[index + Mapper];
const uint8 rom_type = data[index + RomType];
const uint8 rom_size = data[index + RomSize];
const uint8 company = data[index + Company];
const uint8 region = data[index + CartRegion] & 0x7f;
//detect presence of BS-X flash cartridge connector (reads extended header information)
if(data[index - 14] == 'Z') {
if(data[index - 11] == 'J') {
uint8 n13 = data[index - 13];
if((n13 >= 'A' && n13 <= 'Z') || (n13 >= '0' && n13 <= '9')) {
if(company == 0x33 || (data[index - 10] == 0x00 && data[index - 4] == 0x00)) {
info.bsxslot = true;
}
}
}
}
if(info.bsxslot == true) {
if(!memcmp(data + index, "Satellaview BS-X ", 21)) {
//BS-X base cart
info.type = TypeBSXBIOS;
info.mapper = BSXROM;
info.region = NTSC; //BS-X only released in Japan
return; //RAM size handled internally by load_cart_bsx() -> BSXCart class
} else {
//BS-X slotted cart
info.type = TypeBSC;
info.mapper = (index == 0x7fc0 ? BSCLoROM : BSCHiROM);
}
} else {
//standard cart
info.type = TypeNormal;
if(index == 0x7fc0 && size >= 0x401000) {
info.mapper = ExLoROM;
} else if(index == 0x7fc0 && mapper == 0x32) {
info.mapper = ExLoROM;
} else if(index == 0x7fc0) {
info.mapper = LoROM;
} else if(index == 0xffc0) {
info.mapper = HiROM;
} else { //index == 0x40ffc0
info.mapper = ExHiROM;
}
}
if(mapper == 0x20 && (rom_type == 0x13 || rom_type == 0x14 || rom_type == 0x15 || rom_type == 0x1a)) {
info.superfx = true;
}
if(mapper == 0x23 && (rom_type == 0x34 || rom_type == 0x35)) {
info.sa1 = true;
}
if(mapper == 0x35 && rom_type == 0x55) {
info.srtc = true;
}
if(mapper == 0x32 && (rom_type == 0x43 || rom_type == 0x45)) {
info.sdd1 = true;
}
if(mapper == 0x3a && (rom_type == 0xf5 || rom_type == 0xf9)) {
info.spc7110 = true;
info.spc7110rtc = (rom_type == 0xf9);
info.mapper = SPC7110ROM;
}
if(mapper == 0x20 && rom_type == 0xf3) {
info.cx4 = true;
}
if((mapper == 0x20 || mapper == 0x21) && rom_type == 0x03) {
info.dsp1 = true;
}
if(mapper == 0x30 && rom_type == 0x05 && company != 0xb2) {
info.dsp1 = true;
}
if(mapper == 0x31 && (rom_type == 0x03 || rom_type == 0x05)) {
info.dsp1 = true;
}
if(info.dsp1 == true) {
if((mapper & 0x2f) == 0x20 && size <= 0x100000) {
info.dsp1_mapper = DSP1LoROM1MB;
} else if((mapper & 0x2f) == 0x20) {
info.dsp1_mapper = DSP1LoROM2MB;
} else if((mapper & 0x2f) == 0x21) {
info.dsp1_mapper = DSP1HiROM;
}
}
if(mapper == 0x20 && rom_type == 0x05) {
info.dsp2 = true;
}
if(mapper == 0x30 && rom_type == 0x05 && company == 0xb2) {
info.dsp3 = true;
}
if(mapper == 0x30 && rom_type == 0x03) {
info.dsp4 = true;
}
if(mapper == 0x30 && rom_type == 0x25) {
info.obc1 = true;
}
if(mapper == 0x30 && rom_type == 0xf6 && rom_size >= 10) {
info.st010 = true;
}
if(mapper == 0x30 && rom_type == 0xf6 && rom_size < 10) {
info.st011 = true;
}
if(mapper == 0x30 && rom_type == 0xf5) {
info.st018 = true;
}
if(data[index + RamSize] & 7) {
info.ram_size = 1024 << (data[index + RamSize] & 7);
} else {
info.ram_size = 0;
}
//0, 1, 13 = NTSC; 2 - 12 = PAL
info.region = (region <= 1 || region >= 13) ? NTSC : PAL;
}
unsigned Cartridge::find_header(const uint8_t *data, unsigned size) {
unsigned score_lo = score_header(data, size, 0x007fc0);
unsigned score_hi = score_header(data, size, 0x00ffc0);
unsigned score_ex = score_header(data, size, 0x40ffc0);
if(score_ex) score_ex += 4; //favor ExHiROM on images > 32mbits
if(score_lo >= score_hi && score_lo >= score_ex) {
return 0x007fc0;
} else if(score_hi >= score_ex) {
return 0x00ffc0;
} else {
return 0x40ffc0;
}
}
unsigned Cartridge::score_header(const uint8_t *data, unsigned size, unsigned addr) {
if(size < addr + 64) return 0; //image too small to contain header at this location?
int score = 0;
uint16 resetvector = data[addr + ResetVector] | (data[addr + ResetVector + 1] << 8);
uint16 checksum = data[addr + Checksum ] | (data[addr + Checksum + 1] << 8);
uint16 complement = data[addr + Complement ] | (data[addr + Complement + 1] << 8);
uint8 resetop = data[(addr & ~0x7fff) | (resetvector & 0x7fff)]; //first opcode executed upon reset
uint8 mapper = data[addr + Mapper] & ~0x10; //mask off irrelevent FastROM-capable bit
//$00:[000-7fff] contains uninitialized RAM and MMIO.
//reset vector must point to ROM at $00:[8000-ffff] to be considered valid.
if(resetvector < 0x8000) return 0;
//some images duplicate the header in multiple locations, and others have completely
//invalid header information that cannot be relied upon.
//below code will analyze the first opcode executed at the specified reset vector to
//determine the probability that this is the correct header.
//most likely opcodes
if(resetop == 0x78 //sei
|| resetop == 0x18 //clc (clc; xce)
|| resetop == 0x38 //sec (sec; xce)
|| resetop == 0x9c //stz $nnnn (stz $4200)
|| resetop == 0x4c //jmp $nnnn
|| resetop == 0x5c //jml $nnnnnn
) score += 8;
//plausible opcodes
if(resetop == 0xc2 //rep #$nn
|| resetop == 0xe2 //sep #$nn
|| resetop == 0xad //lda $nnnn
|| resetop == 0xae //ldx $nnnn
|| resetop == 0xac //ldy $nnnn
|| resetop == 0xaf //lda $nnnnnn
|| resetop == 0xa9 //lda #$nn
|| resetop == 0xa2 //ldx #$nn
|| resetop == 0xa0 //ldy #$nn
|| resetop == 0x20 //jsr $nnnn
|| resetop == 0x22 //jsl $nnnnnn
) score += 4;
//implausible opcodes
if(resetop == 0x40 //rti
|| resetop == 0x60 //rts
|| resetop == 0x6b //rtl
|| resetop == 0xcd //cmp $nnnn
|| resetop == 0xec //cpx $nnnn
|| resetop == 0xcc //cpy $nnnn
) score -= 4;
//least likely opcodes
if(resetop == 0x00 //brk #$nn
|| resetop == 0x02 //cop #$nn
|| resetop == 0xdb //stp
|| resetop == 0x42 //wdm
|| resetop == 0xff //sbc $nnnnnn,x
) score -= 8;
//at times, both the header and reset vector's first opcode will match ...
//fallback and rely on info validity in these cases to determine more likely header.
//a valid checksum is the biggest indicator of a valid header.
if((checksum + complement) == 0xffff && (checksum != 0) && (complement != 0)) score += 4;
if(addr == 0x007fc0 && mapper == 0x20) score += 2; //0x20 is usually LoROM
if(addr == 0x00ffc0 && mapper == 0x21) score += 2; //0x21 is usually HiROM
if(addr == 0x007fc0 && mapper == 0x22) score += 2; //0x22 is usually ExLoROM
if(addr == 0x40ffc0 && mapper == 0x25) score += 2; //0x25 is usually ExHiROM
if(data[addr + Company] == 0x33) score += 2; //0x33 indicates extended header
if(data[addr + RomType] < 0x08) score++;
if(data[addr + RomSize] < 0x10) score++;
if(data[addr + RamSize] < 0x08) score++;
if(data[addr + CartRegion] < 14) score++;
if(score < 0) score = 0;
return score;
}
#endif

50
src/cart/cart_load.cpp Normal file
View File

@@ -0,0 +1,50 @@
#ifdef CART_CPP
bool Cartridge::load_image(const char *filename) {
if(!filename || !*filename) return false;
uint8_t *data;
unsigned size;
if(!load_file(filename, data, size, CompressionAuto)) return false;
if((size & 0x7fff) != 512) {
image.data = data;
image.size = size;
} else {
//remove 512-byte header
image.data = new uint8_t[image.size = size - 512];
memcpy(image.data, data + 512, image.size);
}
if(load_file(get_patch_filename(filename, "ups"), data, size, CompressionInspect) == true) {
apply_patch(data, size, image.data, image.size);
delete[] data;
info.patched = true;
}
return true;
}
bool Cartridge::inspect_image(cartinfo_t &cartinfo, const char *filename) {
cartinfo.reset();
if(!load_image(filename)) return false;
read_header(cartinfo, image.data, image.size);
delete[] image.data;
return true;
}
bool Cartridge::load_ram(const char *filename, uint8_t *&data, unsigned size, uint8_t init) {
data = new uint8_t[size];
memset(data, init, size);
uint8_t *savedata;
unsigned savesize;
if(load_file(filename, savedata, savesize, CompressionNone) == false) return false;
memcpy(data, savedata, min(size, savesize));
delete[] savedata;
return true;
}
#endif

View File

@@ -1,66 +1,35 @@
void Cartridge::load_rom_normal() {
uint size = 0;
for(int i = 0; i < file.count; i++) {
size += file.rom_size[i] - (((file.rom_size[i] & 0x7fff) == 512) ? 512 : 0);
}
info.rom_size = size;
rom = (uint8*)malloc(info.rom_size);
memset(rom, 0, info.rom_size);
uint offset = 0;
for(int i = 0; i < file.count; i++) {
uint8 *data = file.rom_data[i] + (((file.rom_size[i] & 0x7fff) == 512) ? 512 : 0);
uint size = file.rom_size[i] - (((file.rom_size[i] & 0x7fff) == 512) ? 512 : 0);
memcpy(rom + offset, data, size);
offset += size;
safe_free(file.rom_data[i]);
}
info.crc32 = crc32_calculate(rom, info.rom_size);
if(read_database() == true) {
info.srtc = false;
info.sdd1 = false;
info.c4 = false;
info.dsp1 = false;
info.dsp2 = false;
info.obc1 = false;
info.dsp1_mapper = 0;
info.header_index = 0xffc0;
info.mapper = PCB;
strcpy(info.name, dbi.name);
strcpy(info.pcb, dbi.pcb);
info.region = NTSC;
info.cart_mmio = false;
info.rom_size = dbi.rom;
info.ram_size = dbi.ram;
} else {
find_header();
read_header();
}
}
void Cartridge::load_ram_normal() {
if(info.ram_size == 0) {
ram = 0;
return;
}
ram = (uint8*)malloc(info.ram_size);
memset(ram, 0xff, info.ram_size);
if(load_file(file.ram_name[0], file.ram_data[0], file.ram_size[0]) == true) {
memcpy(ram, file.ram_data[0], min(info.ram_size, file.ram_size[0]));
safe_free(file.ram_data[0]);
}
}
void Cartridge::save_ram_normal() {
if(info.ram_size == 0)return;
save_file(file.ram_name[0], ram, info.ram_size);
}
#ifdef CART_CPP
void Cartridge::load_cart_normal(const char *base) {
uint8_t *data;
unsigned size;
strcpy(cart.fn, base);
load_begin(ModeNormal);
if(load_image(base) == false) return;
cartinfo_t cartinfo;
read_header(cartinfo, cart.rom = image.data, cart.rom_size = image.size);
info = cartinfo;
if(cartinfo.ram_size > 0) {
load_ram(get_save_filename(base, "srm"), cart.ram, cart.ram_size = cartinfo.ram_size, 0xff);
}
if(cartinfo.srtc || cartinfo.spc7110rtc) {
load_ram(get_save_filename(base, "rtc"), cart.rtc, cart.rtc_size = 20, 0x00);
}
load_end();
//set base filename
strcpy(info.filename, base);
get_base_filename(info.filename);
}
void Cartridge::unload_cart_normal() {
if(cart.ram) save_file(get_save_filename(cart.fn, "srm"), cart.ram, cart.ram_size);
if(cart.rtc) save_file(get_save_filename(cart.fn, "rtc"), cart.rtc, cart.rtc_size);
}
#endif

View File

@@ -1,45 +1,62 @@
void Cartridge::load_rom_st() {
uint8 *data;
uint size;
string bios = config::file_updatepath("stbios.bin", config::path.bios);
info.rom_size = 0x200000;
rom = (uint8*)malloc(info.rom_size);
memset(rom, 0, info.rom_size);
load_file(strptr(bios), data, size);
memcpy(rom, data, min(size, 0x040000));
safe_free(data);
memcpy(rom + 0x100000, file.rom_data[0], min(file.rom_size[0], 0x100000));
safe_free(file.rom_data[0]);
//
strcpy(info.name, "???");
strcpy(info.pcb, "STC-SOLO");
info.mapper = PCB;
info.region = NTSC;
info.rom_size = 0x200000;
info.ram_size = 0x020000;
//
info.crc32 = crc32_calculate(rom + 0x100000, file.rom_size[0]);
if(read_database() == true) {
strcpy(info.name, dbi.name);
}
}
void Cartridge::load_ram_st() {
ram = (uint8*)malloc(info.ram_size);
memset(ram, 0xff, info.ram_size);
if(load_file(file.ram_name[0], file.ram_data[0], file.ram_size[0]) == true) {
memcpy(ram, file.ram_data[0], min(file.ram_size[0], 0x020000));
safe_free(file.ram_data[0]);
}
}
void Cartridge::save_ram_st() {
save_file(file.ram_name[0], ram, 0x020000);
}
#ifdef CART_CPP
void Cartridge::load_cart_st(const char *base, const char *slotA, const char *slotB) {
uint8_t *data;
unsigned size;
strcpy(cart.fn, base);
strcpy(stA.fn, slotA);
strcpy(stB.fn, slotB);
load_begin(ModeSufamiTurbo);
if(load_image(base) == false) return;
cartinfo_t cartinfo;
read_header(cartinfo, cart.rom = image.data, cart.rom_size = image.size);
info = cartinfo;
if(load_image(slotA)) {
stA.rom = new(zeromemory) uint8_t[stA.rom_size = 0x100000];
memcpy(stA.rom, image.data, min(image.size, stA.rom_size));
delete[] image.data;
load_ram(get_save_filename(slotA, "srm"), stA.ram, stA.ram_size = 0x020000, 0xff);
}
if(load_image(slotB)) {
stB.rom = new(zeromemory) uint8_t[stB.rom_size = 0x100000];
memcpy(stB.rom, image.data, min(image.size, stB.rom_size));
delete[] image.data;
load_ram(get_save_filename(slotB, "srm"), stB.ram, stB.ram_size = 0x020000, 0xff);
}
load_end();
//set base filename
if(!*slotA && !*slotB) {
strcpy(info.filename, cart.fn);
get_base_filename(info.filename);
} else if(*slotA && !*slotB) {
strcpy(info.filename, slotA);
get_base_filename(info.filename);
} else if(!*slotA && *slotB) {
strcpy(info.filename, slotB);
get_base_filename(info.filename);
} else {
char filenameA[PATH_MAX], filenameB[PATH_MAX];
strcpy(filenameA, slotA);
get_base_filename(filenameA);
strcpy(filenameB, slotB);
get_base_filename(filenameB);
strcpy(info.filename, filenameA);
strcat(info.filename, " + ");
strcat(info.filename, filenameB);
}
}
void Cartridge::unload_cart_st() {
if(stA.ram) save_file(get_save_filename(stA.fn, "srm"), stA.ram, stA.ram_size);
if(stB.ram) save_file(get_save_filename(stB.fn, "srm"), stB.ram, stB.ram_size);
}
#endif

View File

@@ -1,66 +0,0 @@
void Cartridge::load_rom_stdual() {
uint8 *data;
uint size;
string bios = config::file_updatepath("stbios.bin", config::path.bios);
info.rom_size = 0x300000;
rom = (uint8*)malloc(info.rom_size);
memset(rom, 0, info.rom_size);
load_file(strptr(bios), data, size);
memcpy(rom, data, min(size, 0x040000));
safe_free(data);
memcpy(rom + 0x100000, file.rom_data[0], min(file.rom_size[0], 0x100000));
safe_free(file.rom_data[0]);
memcpy(rom + 0x200000, file.rom_data[1], min(file.rom_size[1], 0x100000));
safe_free(file.rom_data[1]);
char name_a[4096], name_b[4096];
strcpy(name_a, "???");
strcpy(name_b, "???");
//
info.mapper = PCB;
info.region = NTSC;
info.rom_size = 0x300000;
info.ram_size = 0x040000;
//
info.crc32 = crc32_calculate(rom + 0x100000, file.rom_size[0]);
if(read_database() == true) {
strcpy(name_a, dbi.name);
}
info.crc32 = crc32_calculate(rom + 0x200000, file.rom_size[1]);
if(read_database() == true) {
strcpy(name_b, dbi.name);
}
//
info.crc32 = 0;
strcpy(info.name, name_a);
strcat(info.name, " + ");
strcat(info.name, name_b);
strcpy(info.pcb, "STC-DUAL");
}
void Cartridge::load_ram_stdual() {
ram = (uint8*)malloc(info.ram_size);
memset(ram, 0xff, info.ram_size);
if(load_file(file.ram_name[0], file.ram_data[0], file.ram_size[0]) == true) {
memcpy(ram + 0x000000, file.ram_data[0], min(file.ram_size[0], 0x020000));
safe_free(file.ram_data[0]);
}
if(load_file(file.ram_name[1], file.ram_data[1], file.ram_size[1]) == true) {
memcpy(ram + 0x020000, file.ram_data[1], min(file.ram_size[1], 0x020000));
safe_free(file.ram_data[1]);
}
}
void Cartridge::save_ram_stdual() {
save_file(file.ram_name[0], ram + 0x000000, 0x020000);
save_file(file.ram_name[1], ram + 0x020000, 0x020000);
}

View File

@@ -1,37 +0,0 @@
void Cartridge::load_database() {
database = 0;
database_size = 0;
FILE *fp;
fp = fopen("cart.db", "rb");
if(!fp)return;
uint size = fsize(fp);
if(size < 8) {
fclose(fp);
return;
}
database = (uint8*)malloc(size);
fread(database, 1, size, fp);
fclose(fp);
database_blocksize = (database[6] << 0) | (database[7] << 8);
database_size = (size - 8) / database_blocksize;
}
bool Cartridge::read_database() {
uint i, crc32;
for(i = 0; i < database_size; i++) {
uint8 *p = database + 8 + (i * database_blocksize);
crc32 = *(p++) << 0;
crc32 |= *(p++) << 8;
crc32 |= *(p++) << 16;
crc32 |= *(p++) << 24;
if(crc32 == cartridge.info.crc32)break;
}
if(i >= database_size)return false;
db_read(dbi, database + 8 + (i * database_blocksize));
return true;
}

Binary file not shown.

View File

@@ -1,113 +0,0 @@
[0xbb5c4238]
name = "Bishoujo Senshi Sailor Moon Sailor Stars - Fuwa Fuwa Panic 2 (Japan)"
pcb = "STC-????"
rom = 8mbit
ram = 32kbit
[0x8eb753f3]
name = "Crayon Shin-chan - Nagagutsu Dobon!! (Japan)"
pcb = "STC-????"
rom = 4mbit
ram = 8kbit
[0x7aedd703]
name = "Der Langrisser (Japan) [!]"
pcb = "SHVC-1A3M-30"
rom = 16mbit
ram = 64kbit
[0x19bdcb19]
name = "Derby Stallion '96 (Japan) [!]"
pcb = "BSC-1A5M-01"
rom = 24mbit
ram = 256kbit
[0x4296500d]
name = "Gegege no Kitarou - Youkai Donjara (Japan)"
pcb = "STC-????"
rom = 4mbit
ram = 16kbit
[0x14c66fca]
name = "Gekisou Sentai Car Rangers (Japan)"
pcb = "STC-????"
rom = 4mbit
ram = 8kbit
[0x32b2b3dd]
name = "Poi Poi Ninja World (Japan)"
pcb = "STC-????"
rom = 4mbit
ram = 8kbit
[0x9684526d]
name = "Romancing SaGa (Japan) (V1.1) [!]"
pcb = "SHVC-1A3B-12"
rom = 8mbit
ram = 64kbit
[0xafd74dcb]
name = "SD Gundam Generation A - Ichinen Sensouki (Japan)"
pcb = "STC-????"
rom = 4mbit
ram = 8kbit
[0x48ecae44]
name = "SD Gundam Generation B - Grips Senki (Japan)"
pcb = "STC-????"
rom = 4mbit
ram = 8kbit
[0x72b4235f]
name = "SD Gundam Generation C - Axis Senki (Japan)"
pcb = "STC-????"
rom = 4mbit
ram = 8kbit
[0x792d884c]
name = "SD Gundam Generation D - Babylonia Kenkoku Senki (Japan)"
pcb = "STC-????"
rom = 4mbit
ram = 8kbit
[0xefd3a865]
name = "SD Gundam Generation E - Zanskar Senki (Japan)"
pcb = "STC-????"
rom = 4mbit
ram = 8kbit
[0xc5dfa8fd]
name = "SD Gundam Generation F - Colony Kakutouki (Japan)"
pcb = "STC-????"
rom = 4mbit
ram = 8kbit
[0x43ad5a45]
name = "SD Ultra Battle - Seven Densetsu (Japan)"
pcb = "STC-????"
rom = 4mbit
ram = 8kbit
[0x04939d14]
name = "SD Ultra Battle - Ultra Densetsu (Japan)"
pcb = "STC-????"
rom = 4mbit
ram = 8kbit
[0xa5c0045e]
name = "Secret of Evermore (USA) [!]"
pcb = "SHVC-1J3M-20"
rom = 32mbit
ram = 64kbit
[0x5ebf7246]
name = "Sound Novel Tsukuru (Japan) [!]"
pcb = "BSC-1A7M-10"
rom = 24mbit
ram = 512kbit
[0x64a91e64]
name = "Wanderers from Ys (USA) [!]"
pcb = "SHVC-1A3B-12"
rom = 8mbit
ram = 64kbit

View File

@@ -1,3 +0,0 @@
cl /nologo /O2 dbcreate.cpp
@pause
@del *.obj

View File

@@ -1 +0,0 @@
@del *.exe

View File

@@ -1,2 +0,0 @@
dbcreate
@copy cart.db ..\..\..\cart.db

View File

@@ -1,47 +0,0 @@
struct db_item {
uint32 crc32;
char name[128];
char pcb [32];
uint32 rom;
uint32 ram;
};
void db_write(FILE *fp, db_item &dbi) {
fputc(dbi.crc32 >> 0, fp);
fputc(dbi.crc32 >> 8, fp);
fputc(dbi.crc32 >> 16, fp);
fputc(dbi.crc32 >> 24, fp);
fwrite(dbi.name, 1, 128, fp);
fwrite(dbi.pcb, 1, 32, fp);
fputc(dbi.rom >> 0, fp);
fputc(dbi.rom >> 8, fp);
fputc(dbi.rom >> 16, fp);
fputc(dbi.rom >> 24, fp);
fputc(dbi.ram >> 0, fp);
fputc(dbi.ram >> 8, fp);
fputc(dbi.ram >> 16, fp);
fputc(dbi.ram >> 24, fp);
}
void db_read(db_item &dbi, uint8 *data) {
dbi.crc32 = (*data++) << 0;
dbi.crc32 |= (*data++) << 8;
dbi.crc32 |= (*data++) << 16;
dbi.crc32 |= (*data++) << 24;
memcpy(dbi.name, data, 128); dbi.name[127] = 0; data += 128;
memcpy(dbi.pcb, data, 32); dbi.pcb [ 31] = 0; data += 32;
dbi.rom = (*data++) << 0;
dbi.rom |= (*data++) << 8;
dbi.rom |= (*data++) << 16;
dbi.rom |= (*data++) << 24;
dbi.ram = (*data++) << 0;
dbi.ram |= (*data++) << 8;
dbi.ram |= (*data++) << 16;
dbi.ram |= (*data++) << 24;
}

View File

@@ -1,117 +0,0 @@
#include "../../lib/libbase.h"
#include "../../lib/libvector.h"
#include "../../lib/libstring.h"
#include "../../lib/libstring.cpp"
#include "db.h"
FILE *fp;
uint decode_size(string &str) {
//hex encoding
if(strbegin(str, "0x")) {
strltrim(str, "0x");
return strhex(str);
}
//mbit encoding
if(strend(str, "mbit")) {
strrtrim(str, "mbit");
return strdec(str) * 1024 * 1024 / 8;
}
//kbit encoding
if(strend(str, "kbit")) {
strrtrim(str, "kbit");
return strdec(str) * 1024 / 8;
}
//decimal encoding
return strdec(str);
}
void build_block(string &block) {
stringarray line, hashpart, part;
split(line, "\n", block);
if(strbegin(line[0], "[") == false) {
printf("error: invalid block detected: '%s'\n", strptr(line[0]));
return;
}
strltrim(line[0], "[");
strrtrim(line[0], "]");
replace(line[0], "0x", "");
split(hashpart, ",", line[0]);
db_item dbi;
dbi.crc32 = 0;
*dbi.name = 0;
*dbi.pcb = 0;
dbi.rom = 0;
dbi.ram = 0;
for(int i = 1; i < count(line); i++) {
uint pos;
if(strpos(line[i], ";", pos) == true) {
strset(line[i], pos, 0);
}
if(line[i] == "")continue;
split(part, "=", line[i]);
strunquote(part[1]);
if(part[0] == "name") {
strncpy(dbi.name, strptr(part[1]), 128);
dbi.name[128] = 0;
}
if(part[0] == "pcb") {
strncpy(dbi.pcb, strptr(part[1]), 32);
dbi.pcb[31] = 0;
}
if(part[0] == "rom") {
dbi.rom = decode_size(part[1]);
}
if(part[0] == "ram") {
dbi.ram = decode_size(part[1]);
}
}
for(int i = 0; i < count(hashpart); i++) {
dbi.crc32 = strhex(hashpart[i]);
db_write(fp, dbi);
}
}
void build_database() {
stringarray data, block;
if(strfread(data, "cartdb.txt") == false)return;
fp = fopen("cart.db", "wb");
fprintf(fp, "SNESDB");
uint blocksize = 4 + 128 + 32 + 4 + 4;
fputc(blocksize >> 0, fp);
fputc(blocksize >> 8, fp);
replace (data, "\r", "");
qreplace(data, " ", "");
qreplace(data, "\t", "");
split(block, "\n\n", data);
for(int i = 0; i < count(block); i++) {
build_block(block[i]);
}
fclose(fp);
}
int main() {
build_database();
return 0;
}

View File

@@ -1,3 +1,3 @@
@make -r PLATFORM=win-visualc-lui
@move bsnes.exe ../bsnes.exe>nul
@pause
@mingw32-make platform=win compiler=mingw32-gcc
::@mingw32-make platform=win compiler=mingw32-gcc enable_gzip=true enable_jma=true
@pause

View File

@@ -1,2 +1,2 @@
#!/bin/sh
make PLATFORM=x-gcc-lui
make platform=x compiler=gcc
#make platform=x compiler=gcc enable_gzip=true enable_jma=true

View File

@@ -1,339 +1,379 @@
#include "../base.h"
#include "../reader/filereader.h"
#include <../base.hpp>
#include <nall/sort.hpp>
Cheat cheat;
/*****
* string <> binary code translation routines
* decode() "7e1234:56" -> 0x7e123456
* encode() 0x7e123456 -> "7e1234:56"
*****/
Cheat::cheat_t& Cheat::cheat_t::operator=(const Cheat::cheat_t& source) {
enabled = source.enabled;
code = source.code;
desc = source.desc;
count = source.count;
bool Cheat::decode(char *str, uint32 &addr, uint8 &data, uint8 &type) {
stringarray t, part;
strcpy(t, str);
strlower(t);
if(strlen(t) == 8 || (strlen(t) == 9 && strptr(t)[6] == ':')) {
type = CT_PRO_ACTION_REPLAY;
replace(t, ":", "");
uint32 r = strhex(t);
addr = r >> 8;
data = r & 0xff;
return true;
} else if(strlen(t) == 9 && strptr(t)[4] == '-') {
type = CT_GAME_GENIE;
replace(t, "-", "");
strtr(t, "df4709156bc8a23e", "0123456789abcdef");
uint32 r = strhex(t);
//8421 8421 8421 8421 8421 8421
//abcd efgh ijkl mnop qrst uvwx
//ijkl qrst opab cduv wxef ghmn
addr = (!!(r & 0x002000) << 23) | (!!(r & 0x001000) << 22) |
(!!(r & 0x000800) << 21) | (!!(r & 0x000400) << 20) |
(!!(r & 0x000020) << 19) | (!!(r & 0x000010) << 18) |
(!!(r & 0x000008) << 17) | (!!(r & 0x000004) << 16) |
(!!(r & 0x800000) << 15) | (!!(r & 0x400000) << 14) |
(!!(r & 0x200000) << 13) | (!!(r & 0x100000) << 12) |
(!!(r & 0x000002) << 11) | (!!(r & 0x000001) << 10) |
(!!(r & 0x008000) << 9) | (!!(r & 0x004000) << 8) |
(!!(r & 0x080000) << 7) | (!!(r & 0x040000) << 6) |
(!!(r & 0x020000) << 5) | (!!(r & 0x010000) << 4) |
(!!(r & 0x000200) << 3) | (!!(r & 0x000100) << 2) |
(!!(r & 0x000080) << 1) | (!!(r & 0x000040) << 0);
data = r >> 24;
return true;
addr.reset();
data.reset();
for(unsigned n = 0; n < count; n++) {
addr[n] = source.addr[n];
data[n] = source.data[n];
}
return *this;
}
//used to sort cheat code list by description
bool Cheat::cheat_t::operator<(const Cheat::cheat_t& source) {
return strcmp(desc, source.desc) < 0;
}
//parse item ("0123-4567+89AB-CDEF"), return cheat_t item
//return true if code is valid, false otherwise
bool Cheat::decode(const char *s, Cheat::cheat_t &item) const {
item.enabled = false;
item.count = 0;
lstring list;
split(list, "+", s);
for(unsigned n = 0; n < list.size(); n++) {
unsigned addr;
uint8_t data;
type_t type;
if(decode(list[n], addr, data, type) == false) return false;
item.addr[item.count] = addr;
item.data[item.count] = data;
item.count++;
}
return true;
}
//read() is used by MemBus::read() if Cheat::enabled(addr) returns true to look up cheat code.
//returns true if cheat code was found, false if it was not.
//when true, cheat code substitution value is stored in data.
bool Cheat::read(unsigned addr, uint8_t &data) const {
addr = mirror_address(addr);
for(unsigned i = 0; i < code.size(); i++) {
if(enabled(i) == false) continue;
for(unsigned n = 0; n < code[i].count; n++) {
if(addr == mirror_address(code[i].addr[n])) {
data = code[i].data[n];
return true;
}
}
}
//code not found, or code is disabled
return false;
}
bool Cheat::encode(char *str, uint32 addr, uint8 data, uint8 type) {
if(type == CT_PRO_ACTION_REPLAY) {
sprintf(str, "%0.6x:%0.2x", addr, data);
return true;
} else if(type == CT_GAME_GENIE) {
uint32 r = addr;
addr = (!!(r & 0x008000) << 23) | (!!(r & 0x004000) << 22) |
(!!(r & 0x002000) << 21) | (!!(r & 0x001000) << 20) |
(!!(r & 0x000080) << 19) | (!!(r & 0x000040) << 18) |
(!!(r & 0x000020) << 17) | (!!(r & 0x000010) << 16) |
(!!(r & 0x000200) << 15) | (!!(r & 0x000100) << 14) |
(!!(r & 0x800000) << 13) | (!!(r & 0x400000) << 12) |
(!!(r & 0x200000) << 11) | (!!(r & 0x100000) << 10) |
(!!(r & 0x000008) << 9) | (!!(r & 0x000004) << 8) |
(!!(r & 0x000002) << 7) | (!!(r & 0x000001) << 6) |
(!!(r & 0x080000) << 5) | (!!(r & 0x040000) << 4) |
(!!(r & 0x020000) << 3) | (!!(r & 0x010000) << 2) |
(!!(r & 0x000800) << 1) | (!!(r & 0x000400) << 0);
sprintf(str, "%0.2x%0.2x-%0.4x", data, addr >> 16, addr & 0xffff);
strtr(str, "0123456789abcdef", "df4709156bc8a23e");
return true;
}
return false;
}
//================================
//cheat list manipulation routines
//================================
/*****
* address lookup table manipulation and mirroring
* mirror_address() 0x000000 -> 0x7e0000
* set() enable specified address, mirror accordingly
* clear() disable specified address, mirror accordingly
*****/
bool Cheat::add(bool enable, const char *code_, const char *desc_) {
cheat_t item;
if(decode(code_, item) == false) return false;
uint Cheat::mirror_address(uint addr) {
if((addr & 0x40e000) != 0x0000)return addr;
//8k WRAM mirror
//$[00-3f|80-bf]:[0000-1fff] -> $7e:[0000-1fff]
return (0x7e0000 + (addr & 0x1fff));
}
void Cheat::set(uint32 addr) {
addr = mirror_address(addr);
mask[addr >> 3] |= 1 << (addr & 7);
if((addr & 0xffe000) == 0x7e0000) {
//mirror $7e:[0000-1fff] to $[00-3f|80-bf]:[0000-1fff]
uint mirror;
for(int x = 0; x <= 0x3f; x++) {
mirror = ((0x00 + x) << 16) + (addr & 0x1fff);
mask[mirror >> 3] |= 1 << (mirror & 7);
mirror = ((0x80 + x) << 16) + (addr & 0x1fff);
mask[mirror >> 3] |= 1 << (mirror & 7);
}
}
}
void Cheat::clear(uint32 addr) {
addr = mirror_address(addr);
//is there more than one cheat code using the same address
//(and likely a different override value) that is enabled?
//if so, do not clear code lookup table entry for this address.
uint8 r;
if(read(addr, r) == true)return;
mask[addr >> 3] &= ~(1 << (addr & 7));
if((addr & 0xffe000) == 0x7e0000) {
//mirror $7e:[0000-1fff] to $[00-3f|80-bf]:[0000-1fff]
uint mirror;
for(int x = 0; x <= 0x3f; x++) {
mirror = ((0x00 + x) << 16) + (addr & 0x1fff);
mask[mirror >> 3] &= ~(1 << (mirror & 7));
mirror = ((0x80 + x) << 16) + (addr & 0x1fff);
mask[mirror >> 3] &= ~(1 << (mirror & 7));
}
}
}
/*****
* read() is used by MemBus::read() if Cheat::enabled(addr)
* returns true to look up cheat code.
* returns true if cheat code was found, false if it was not.
* when true, cheat code substitution value is stored in data.
*****/
bool Cheat::read(uint32 addr, uint8 &data) {
addr = mirror_address(addr);
for(int i = 0; i < cheat_count; i++) {
if(enabled(i) == false)continue;
if(addr == mirror_address(index[i].addr)) {
data = index[i].data;
return true;
}
}
//code not found, or code is disabled
return false;
}
/*****
* update_cheat_status() will scan to see if any codes are
* enabled. if any are, make sure the cheat system is on.
* otherwise, turn cheat system off to speed up emulation.
*****/
void Cheat::update_cheat_status() {
for(int i = 0; i < cheat_count; i++) {
if(index[i].enabled) {
cheat_enabled = true;
return;
}
}
cheat_enabled = false;
}
/*****
* cheat list manipulation routines
*****/
bool Cheat::add(bool enable, char *code, char *desc) {
if(cheat_count >= CHEAT_LIMIT)return false;
uint32 addr, len;
uint8 data, type;
if(decode(code, addr, data, type) == false)return false;
index[cheat_count].enabled = enable;
index[cheat_count].addr = addr;
index[cheat_count].data = data;
len = strlen(code);
len = len > 16 ? 16 : len;
memcpy(index[cheat_count].code, code, len);
index[cheat_count].code[len] = 0;
len = strlen(desc);
len = len > 128 ? 128 : len;
memcpy(index[cheat_count].desc, desc, len);
index[cheat_count].desc[len] = 0;
cheat_count++;
(enable) ? set(addr) : clear(addr);
unsigned i = code.size();
code[i] = item;
code[i].enabled = enable;
code[i].desc = desc_;
code[i].code = code_;
encode_description(code[i].desc);
update(code[i]);
update_cheat_status();
return true;
}
bool Cheat::edit(uint32 n, bool enable, char *code, char *desc) {
if(n >= cheat_count)return false;
bool Cheat::edit(unsigned i, bool enable, const char *code_, const char *desc_) {
cheat_t item;
if(decode(code_, item) == false) return false;
uint32 addr, len;
uint8 data, type;
if(decode(code, addr, data, type) == false)return false;
//disable current code and clear from code lookup table
code[i].enabled = false;
update(code[i]);
//disable current code and clear from code lookup table
index[n].enabled = false;
clear(index[n].addr);
//update code and enable in code lookup table
index[n].enabled = enable;
index[n].addr = addr;
index[n].data = data;
len = strlen(code);
len = len > 16 ? 16 : len;
memcpy(index[n].code, code, len);
index[n].code[len] = 0;
len = strlen(desc);
len = len > 128 ? 128 : len;
memcpy(index[n].desc, desc, len);
index[n].desc[len] = 0;
set(addr);
code[i] = item;
code[i].enabled = enable;
code[i].desc = desc_;
code[i].code = code_;
encode_description(code[i].desc);
update(code[i]);
update_cheat_status();
return true;
}
bool Cheat::remove(uint32 n) {
if(n >= cheat_count)return false;
bool Cheat::remove(unsigned i) {
unsigned size = code.size();
if(i >= size) return false; //also verifies size cannot be < 1
for(int i = n; i < cheat_count; i++) {
index[i].enabled = index[i + 1].enabled;
index[i].addr = index[i + 1].addr;
index[i].data = index[i + 1].data;
strcpy(index[i].desc, index[i + 1].desc);
}
cheat_count--;
for(unsigned n = i; n < size - 1; n++) code[n] = code[n + 1];
code.resize(size - 1);
update_cheat_status();
return true;
}
bool Cheat::get(uint32 n, bool &enable, uint32 &addr, uint8 &data, char *code, char *desc) {
if(n >= cheat_count)return false;
enable = index[n].enabled;
addr = index[n].addr;
data = index[n].data;
strcpy(code, index[n].code);
strcpy(desc, index[n].desc);
bool Cheat::get(unsigned i, cheat_t &item) const {
if(i >= code.size()) return false;
item = code[i];
decode_description(item.desc);
return true;
}
/*****
* code status modifier routines
*****/
//==============================
//cheat status modifier routines
//==============================
bool Cheat::enabled(uint32 n) {
if(n >= cheat_count)return false;
return index[n].enabled;
bool Cheat::enabled(unsigned i) const {
return (i < code.size() ? code[i].enabled : false);
}
void Cheat::enable(uint32 n) {
if(n >= cheat_count)return;
index[n].enabled = true;
set(index[n].addr);
void Cheat::enable(unsigned i) {
if(i >= code.size()) return;
code[i].enabled = true;
update(code[i]);
update_cheat_status();
}
void Cheat::disable(uint32 n) {
if(n >= cheat_count)return;
index[n].enabled = false;
clear(index[n].addr);
void Cheat::disable(unsigned i) {
if(i >= code.size()) return;
code[i].enabled = false;
update(code[i]);
update_cheat_status();
}
/*****
* cheat file manipulation routines
*****/
//===============================
//cheat file load / save routines
//
//file format:
//"description", status, nnnn-nnnn[+nnnn-nnnn...]\r\n
//...
//===============================
bool Cheat::load(const char *fn) {
FileReader rf(fn);
if(!rf.ready())return false;
uint8 *raw_data = rf.read();
stringarray data, line;
raw_data[rf.size()] = 0;
strcpy(data, (char*)raw_data);
safe_free(raw_data);
string data;
if(!fread(data, fn)) return false;
replace(data, "\r\n", "\n");
qreplace(data, " ", "");
lstring line;
split(line, "\n", data);
for(int i = 0; i < ::count(line); i++) {
stringarray part;
uint8 en = *(strptr(line[i]));
if(en == '+') {
strltrim(line[i], "+");
} else if(en == '-') {
strltrim(line[i], "-");
} else {
continue;
}
qreplace(line[i], " ", "");
for(unsigned i = 0; i < line.size(); i++) {
lstring part;
qsplit(part, ",", line[i]);
if(::count(part) != 2)continue;
strunquote(part[1]);
add(en == '+', strptr(part[0]), strptr(part[1]));
if(part.size() != 3) continue;
trim(part[0], "\"");
add(part[1] == "enabled", /* code = */ part[2], /* desc = */ part[0]);
}
return true;
}
bool Cheat::save(const char *fn) {
FileWriter wf(fn);
if(!wf.ready())return false;
string data;
char t[4096];
strcpy(data, "");
for(int i = 0; i < cheat_count; i++) {
sprintf(t, "%c%s, \"%s\"\r\n", index[i].enabled ? '+' : '-', index[i].code, index[i].desc);
strcat(data, t);
bool Cheat::save(const char *fn) const {
file fp;
if(!fp.open(fn, file::mode_write)) return false;
for(unsigned i = 0; i < code.size(); i++) {
fp.print(string()
<< "\"" << code[i].desc << "\", "
<< (code[i].enabled ? "enabled, " : "disabled, ")
<< code[i].code << "\r\n");
}
wf.write((uint8*)strptr(data), strlen(data));
fp.close();
return true;
}
/*****
* initialization routines
*****/
void Cheat::sort() {
if(code.size() <= 1) return; //nothing to sort?
cheat_t *buffer = new cheat_t[code.size()];
for(unsigned i = 0; i < code.size(); i++) buffer[i] = code[i];
nall::sort(buffer, code.size());
for(unsigned i = 0; i < code.size(); i++) code[i] = buffer[i];
delete[] buffer;
}
void Cheat::clear() {
cheat_enabled = false;
cheat_count = 0;
cheat_system_enabled = false;
memset(mask, 0, 0x200000);
for(int i = 0; i < CHEAT_LIMIT + 1; i++) {
index[i].enabled = false;
index[i].addr = 0x000000;
index[i].data = 0x00;
strcpy(index[i].code, "");
strcpy(index[i].desc, "");
}
code.reset();
}
Cheat::Cheat() {
clear();
}
//==================
//internal functions
//==================
//string <> binary code translation routines
//decode() "7e123456" -> 0x7e123456
//encode() 0x7e123456 -> "7e123456"
bool Cheat::decode(const char *s, unsigned &addr, uint8_t &data, type_t &type) const {
string t = s;
strlower(t);
#define ischr(n) ((n >= '0' && n <= '9') || (n >= 'a' && n <= 'f'))
if(strlen(t) == 8 || (strlen(t) == 9 && t[6] == ':')) {
//strip ':'
if(strlen(t) == 9 && t[6] == ':') t = string() << substr(t, 0, 6) << substr(t, 7);
//validate input
for(unsigned i = 0; i < 8; i++) if(!ischr(t[i])) return false;
type = ProActionReplay;
unsigned r = strhex((const char*)t);
addr = r >> 8;
data = r & 0xff;
return true;
} else if(strlen(t) == 9 && t[4] == '-') {
//strip '-'
t = string() << substr(t, 0, 4) << substr(t, 5);
//validate input
for(unsigned i = 0; i < 8; i++) if(!ischr(t[i])) return false;
type = GameGenie;
strtr(t, "df4709156bc8a23e", "0123456789abcdef");
unsigned r = strhex((const char*)t);
//8421 8421 8421 8421 8421 8421
//abcd efgh ijkl mnop qrst uvwx
//ijkl qrst opab cduv wxef ghmn
addr = (!!(r & 0x002000) << 23) | (!!(r & 0x001000) << 22)
| (!!(r & 0x000800) << 21) | (!!(r & 0x000400) << 20)
| (!!(r & 0x000020) << 19) | (!!(r & 0x000010) << 18)
| (!!(r & 0x000008) << 17) | (!!(r & 0x000004) << 16)
| (!!(r & 0x800000) << 15) | (!!(r & 0x400000) << 14)
| (!!(r & 0x200000) << 13) | (!!(r & 0x100000) << 12)
| (!!(r & 0x000002) << 11) | (!!(r & 0x000001) << 10)
| (!!(r & 0x008000) << 9) | (!!(r & 0x004000) << 8)
| (!!(r & 0x080000) << 7) | (!!(r & 0x040000) << 6)
| (!!(r & 0x020000) << 5) | (!!(r & 0x010000) << 4)
| (!!(r & 0x000200) << 3) | (!!(r & 0x000100) << 2)
| (!!(r & 0x000080) << 1) | (!!(r & 0x000040) << 0);
data = r >> 24;
return true;
} else {
return false;
}
}
bool Cheat::encode(string &s, unsigned addr, uint8_t data, type_t type) const {
char t[16];
if(type == ProActionReplay) {
sprintf(t, "%.6x%.2x", addr, data);
s = t;
return true;
} else if(type == GameGenie) {
unsigned r = addr;
addr = (!!(r & 0x008000) << 23) | (!!(r & 0x004000) << 22)
| (!!(r & 0x002000) << 21) | (!!(r & 0x001000) << 20)
| (!!(r & 0x000080) << 19) | (!!(r & 0x000040) << 18)
| (!!(r & 0x000020) << 17) | (!!(r & 0x000010) << 16)
| (!!(r & 0x000200) << 15) | (!!(r & 0x000100) << 14)
| (!!(r & 0x800000) << 13) | (!!(r & 0x400000) << 12)
| (!!(r & 0x200000) << 11) | (!!(r & 0x100000) << 10)
| (!!(r & 0x000008) << 9) | (!!(r & 0x000004) << 8)
| (!!(r & 0x000002) << 7) | (!!(r & 0x000001) << 6)
| (!!(r & 0x080000) << 5) | (!!(r & 0x040000) << 4)
| (!!(r & 0x020000) << 3) | (!!(r & 0x010000) << 2)
| (!!(r & 0x000800) << 1) | (!!(r & 0x000400) << 0);
sprintf(t, "%.2x%.2x-%.4x", data, addr >> 16, addr & 0xffff);
strtr(t, "0123456789abcdef", "df4709156bc8a23e");
s = t;
return true;
} else {
return false;
}
}
//update_cheat_status() will scan to see if any codes are
//enabled. if any are, make sure the cheat system is on.
//otherwise, turn cheat system off to speed up emulation.
void Cheat::update_cheat_status() {
for(unsigned i = 0; i < code.size(); i++) {
if(code[i].enabled) {
cheat_system_enabled = true;
return;
}
}
cheat_system_enabled = false;
}
//address lookup table manipulation and mirroring
//mirror_address() 0x000000 -> 0x7e0000
//set() enable specified address, mirror accordingly
//clear() disable specified address, mirror accordingly
unsigned Cheat::mirror_address(unsigned addr) const {
if((addr & 0x40e000) != 0x0000) return addr;
//8k WRAM mirror
//$[00-3f|80-bf]:[0000-1fff] -> $7e:[0000-1fff]
return (0x7e0000 + (addr & 0x1fff));
}
//updates mask[] table enabled bits;
//must be called after modifying item.enabled state.
void Cheat::update(const cheat_t &item) {
for(unsigned n = 0; n < item.count; n++) {
(item.enabled) ? set(item.addr[n]) : clear(item.addr[n]);
}
}
void Cheat::set(unsigned addr) {
addr = mirror_address(addr);
mask[addr >> 3] |= 1 << (addr & 7);
if((addr & 0xffe000) == 0x7e0000) {
//mirror $7e:[0000-1fff] to $[00-3f|80-bf]:[0000-1fff]
unsigned mirror;
for(unsigned x = 0; x <= 0x3f; x++) {
mirror = ((0x00 + x) << 16) + (addr & 0x1fff);
mask[mirror >> 3] |= 1 << (mirror & 7);
mirror = ((0x80 + x) << 16) + (addr & 0x1fff);
mask[mirror >> 3] |= 1 << (mirror & 7);
}
}
}
void Cheat::clear(unsigned addr) {
addr = mirror_address(addr);
//if there is more than one cheat code using the same address,
//(eg with a different override value) then do not clear code
//lookup table entry.
uint8_t r;
if(read(addr, r) == true) return;
mask[addr >> 3] &= ~(1 << (addr & 7));
if((addr & 0xffe000) == 0x7e0000) {
//mirror $7e:[0000-1fff] to $[00-3f|80-bf]:[0000-1fff]
unsigned mirror;
for(unsigned x = 0; x <= 0x3f; x++) {
mirror = ((0x00 + x) << 16) + (addr & 0x1fff);
mask[mirror >> 3] &= ~(1 << (mirror & 7));
mirror = ((0x80 + x) << 16) + (addr & 0x1fff);
mask[mirror >> 3] &= ~(1 << (mirror & 7));
}
}
}
//these two functions are used to safely store description text inside .cfg file format.
string& Cheat::encode_description(string &desc) const {
replace(desc, "\"", "\\q");
replace(desc, "\n", "\\n");
return desc;
}
string& Cheat::decode_description(string &desc) const {
replace(desc, "\\q", "\"");
replace(desc, "\\n", "\n");
return desc;
}

View File

@@ -1,48 +0,0 @@
#define CHEAT_LIMIT 1024
class Cheat {
public:
enum { CT_PRO_ACTION_REPLAY, CT_GAME_GENIE };
struct CheatIndex {
bool enabled;
uint32 addr;
uint8 data;
char code[ 16 + 1];
char desc[128 + 1];
} index[CHEAT_LIMIT + 1];
bool cheat_enabled;
uint32 cheat_count;
uint8 mask[0x200000];
inline bool enabled() { return cheat_enabled; }
inline uint count() { return cheat_count; }
inline bool exists(uint32 addr) { return bool(mask[addr >> 3] & 1 << (addr & 7)); }
bool decode(char *str, uint32 &addr, uint8 &data, uint8 &type);
bool encode(char *str, uint32 addr, uint8 data, uint8 type);
private:
uint mirror_address(uint addr);
void set(uint32 addr);
void clear(uint32 addr);
public:
bool read(uint32 addr, uint8 &data);
void update_cheat_status();
bool add(bool enable, char *code, char *desc);
bool edit(uint32 n, bool enable, char *code, char *desc);
bool get(uint32 n, bool &enable, uint32 &addr, uint8 &data, char *code, char *desc);
bool remove (uint32 n);
bool enabled(uint32 n);
void enable (uint32 n);
void disable(uint32 n);
bool load(const char *fn);
bool save(const char *fn);
void clear();
Cheat();
};
extern Cheat cheat;

64
src/cheat/cheat.hpp Normal file
View File

@@ -0,0 +1,64 @@
class Cheat {
public:
enum type_t {
ProActionReplay,
GameGenie,
};
struct cheat_t {
bool enabled;
string code;
string desc;
unsigned count;
array<unsigned> addr;
array<uint8_t> data;
cheat_t& operator=(const cheat_t&);
bool operator<(const cheat_t&);
};
bool decode(const char *s, cheat_t &item) const;
bool read(unsigned addr, uint8_t &data) const;
inline bool enabled() const { return cheat_system_enabled; }
inline unsigned count() const { return code.size(); }
inline bool exists(unsigned addr) const { return mask[addr >> 3] & 1 << (addr & 7); }
bool add(bool enable, const char *code, const char *desc);
bool edit(unsigned i, bool enable, const char *code, const char *desc);
bool remove(unsigned i);
bool get(unsigned i, cheat_t &item) const;
bool enabled(unsigned i) const;
void enable(unsigned i);
void disable(unsigned i);
bool load(const char *fn);
bool save(const char *fn) const;
void sort();
void clear();
Cheat();
private:
bool cheat_system_enabled;
uint8_t mask[0x200000];
vector<cheat_t> code;
bool decode(const char *str, unsigned &addr, uint8_t &data, type_t &type) const;
bool encode(string &str, unsigned addr, uint8_t data, type_t type) const;
void update_cheat_status();
unsigned mirror_address(unsigned addr) const;
void update(const cheat_t& item);
void set(unsigned addr);
void clear(unsigned addr);
string& encode_description(string &desc) const;
string& decode_description(string &desc) const;
};
extern Cheat cheat;

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

@@ -0,0 +1,8 @@
#include <../base.hpp>
#include <../cart/cart.hpp>
#define BSX_CPP
#include "bsx.hpp"
#include "bsx_base.cpp"
#include "bsx_cart.cpp"
#include "bsx_flash.cpp"

77
src/chip/bsx/bsx.hpp Normal file
View File

@@ -0,0 +1,77 @@
class BSXBase : public MMIO {
public:
void init();
void enable();
void power();
void reset();
uint8 mmio_read(unsigned addr);
void mmio_write(unsigned addr, uint8 data);
private:
struct {
uint8 r2188, r2189, r218a, r218b;
uint8 r218c, r218d, r218e, r218f;
uint8 r2190, r2191, r2192, r2193;
uint8 r2194, r2195, r2196, r2197;
uint8 r2198, r2199, r219a, r219b;
uint8 r219c, r219d, r219e, r219f;
uint8 r2192_counter;
uint8 r2192_hour, r2192_minute, r2192_second;
} regs;
};
class BSXCart : public MMIO {
public:
void init();
void enable();
void power();
void reset();
uint8 mmio_read(unsigned addr);
void mmio_write(unsigned addr, uint8 data);
MappedRAM sram;
MappedRAM psram;
BSXCart();
~BSXCart();
private:
uint8 *sram_data; //256kbit SRAM
uint8 *psram_data; // 4mbit PSRAM
struct {
uint8 r[16];
} regs;
void update_memory_map();
};
class BSXFlash : public Memory {
public:
void init();
void enable();
void power();
void reset();
unsigned size();
uint8 read(unsigned addr);
void write(unsigned addr, uint8 data);
private:
struct {
unsigned command;
uint8 write_old;
uint8 write_new;
bool flash_enable;
bool read_enable;
bool write_enable;
} regs;
};
extern BSXBase bsxbase;
extern BSXCart bsxcart;
extern BSXFlash bsxflash;

137
src/chip/bsx/bsx_base.cpp Normal file
View File

@@ -0,0 +1,137 @@
#ifdef BSX_CPP
void BSXBase::init() {
}
void BSXBase::enable() {
for(uint16 i = 0x2188; i <= 0x219f; i++) memory::mmio.map(i, *this);
}
void BSXBase::power() {
reset();
}
void BSXBase::reset() {
memset(&regs, 0x00, sizeof regs);
}
uint8 BSXBase::mmio_read(unsigned addr) {
addr &= 0xffff;
switch(addr) {
case 0x2188: return regs.r2188;
case 0x2189: return regs.r2189;
case 0x218a: return regs.r218a;
case 0x218c: return regs.r218c;
case 0x218e: return regs.r218e;
case 0x218f: return regs.r218f;
case 0x2190: return regs.r2190;
case 0x2192: {
unsigned counter = regs.r2192_counter++;
if(regs.r2192_counter >= 18) regs.r2192_counter = 0;
if(counter == 0) {
time_t rawtime;
time(&rawtime);
tm *t = localtime(&rawtime);
regs.r2192_hour = t->tm_hour;
regs.r2192_minute = t->tm_min;
regs.r2192_second = t->tm_sec;
}
switch(counter) {
case 0: return 0x00; //???
case 1: return 0x00; //???
case 2: return 0x00; //???
case 3: return 0x00; //???
case 4: return 0x00; //???
case 5: return 0x01;
case 6: return 0x01;
case 7: return 0x00;
case 8: return 0x00;
case 9: return 0x00;
case 10: return regs.r2192_second;
case 11: return regs.r2192_minute;
case 12: return regs.r2192_hour;
case 13: return 0x00; //???
case 14: return 0x00; //???
case 15: return 0x00; //???
case 16: return 0x00; //???
case 17: return 0x00; //???
}
} break;
case 0x2193: return regs.r2193 & ~0x0c;
case 0x2194: return regs.r2194;
case 0x2196: return regs.r2196;
case 0x2197: return regs.r2197;
case 0x2199: return regs.r2199;
}
return cpu.regs.mdr;
}
void BSXBase::mmio_write(unsigned addr, uint8 data) {
addr &= 0xffff;
switch(addr) {
case 0x2188: {
regs.r2188 = data;
} break;
case 0x2189: {
regs.r2189 = data;
} break;
case 0x218a: {
regs.r218a = data;
} break;
case 0x218b: {
regs.r218b = data;
} break;
case 0x218c: {
regs.r218c = data;
} break;
case 0x218e: {
regs.r218e = data;
} break;
case 0x218f: {
regs.r218e >>= 1;
regs.r218e = regs.r218f - regs.r218e;
regs.r218f >>= 1;
} break;
case 0x2191: {
regs.r2191 = data;
regs.r2192_counter = 0;
} break;
case 0x2192: {
regs.r2190 = 0x80;
} break;
case 0x2193: {
regs.r2193 = data;
} break;
case 0x2194: {
regs.r2194 = data;
} break;
case 0x2197: {
regs.r2197 = data;
} break;
case 0x2199: {
regs.r2199 = data;
} break;
}
}
#endif

99
src/chip/bsx/bsx_cart.cpp Normal file
View File

@@ -0,0 +1,99 @@
#ifdef BSX_CPP
void BSXCart::init() {
}
void BSXCart::enable() {
for(uint16 i = 0x5000; i <= 0x5fff; i++) memory::mmio.map(i, *this);
}
void BSXCart::power() {
reset();
}
void BSXCart::reset() {
for(unsigned i = 0; i < 16; i++) regs.r[i] = 0x00;
regs.r[0x07] = 0x80;
regs.r[0x08] = 0x80;
update_memory_map();
}
void BSXCart::update_memory_map() {
Memory &cart = (regs.r[0x01] & 0x80) == 0x00 ? (Memory&)bsxflash : (Memory&)psram;
if((regs.r[0x02] & 0x80) == 0x00) { //LoROM mapping
bus.map(Bus::MapLinear, 0x00, 0x7d, 0x8000, 0xffff, cart);
bus.map(Bus::MapLinear, 0x80, 0xff, 0x8000, 0xffff, cart);
} else { //HiROM mapping
bus.map(Bus::MapShadow, 0x00, 0x3f, 0x8000, 0xffff, cart);
bus.map(Bus::MapLinear, 0x40, 0x7d, 0x0000, 0xffff, cart);
bus.map(Bus::MapShadow, 0x80, 0xbf, 0x8000, 0xffff, cart);
bus.map(Bus::MapLinear, 0xc0, 0xff, 0x0000, 0xffff, cart);
}
if(regs.r[0x03] & 0x80) {
bus.map(Bus::MapLinear, 0x60, 0x6f, 0x0000, 0xffff, psram);
//bus.map(Bus::MapLinear, 0x70, 0x77, 0x0000, 0xffff, psram);
}
if((regs.r[0x05] & 0x80) == 0x00) {
bus.map(Bus::MapLinear, 0x40, 0x4f, 0x0000, 0xffff, psram);
}
if((regs.r[0x06] & 0x80) == 0x00) {
bus.map(Bus::MapLinear, 0x50, 0x5f, 0x0000, 0xffff, psram);
}
if(regs.r[0x07] & 0x80) {
bus.map(Bus::MapLinear, 0x00, 0x1f, 0x8000, 0xffff, memory::cartrom);
}
if(regs.r[0x08] & 0x80) {
bus.map(Bus::MapLinear, 0x80, 0x9f, 0x8000, 0xffff, memory::cartrom);
}
bus.map(Bus::MapShadow, 0x20, 0x3f, 0x6000, 0x7fff, psram);
bus.map(Bus::MapLinear, 0x70, 0x77, 0x0000, 0xffff, psram);
}
uint8 BSXCart::mmio_read(unsigned addr) {
if((addr & 0xf0ffff) == 0x005000) { //$[00-0f]:5000 MMIO
uint8 n = (addr >> 16) & 15;
return regs.r[n];
}
if((addr & 0xf8f000) == 0x105000) { //$[10-17]:[5000-5fff] SRAM
return sram.read(((addr >> 16) & 7) * 0x1000 + (addr & 0xfff));
}
return 0x00;
}
void BSXCart::mmio_write(unsigned addr, uint8 data) {
if((addr & 0xf0ffff) == 0x005000) { //$[00-0f]:5000 MMIO
uint8 n = (addr >> 16) & 15;
regs.r[n] = data;
if(n == 0x0e && data & 0x80) update_memory_map();
return;
}
if((addr & 0xf8f000) == 0x105000) { //$[10-17]:[5000-5fff] SRAM
return sram.write(((addr >> 16) & 7) * 0x1000 + (addr & 0xfff), data);
}
}
BSXCart::BSXCart() {
sram_data = new uint8_t[ 32 * 1024];
psram_data = new uint8_t[512 * 1024];
sram.map (sram_data, 32 * 1024);
psram.map(psram_data, 512 * 1024);
}
BSXCart::~BSXCart() {
delete[] sram_data;
delete[] psram_data;
}
#endif

113
src/chip/bsx/bsx_flash.cpp Normal file
View File

@@ -0,0 +1,113 @@
#ifdef BSX_CPP
void BSXFlash::init() {}
void BSXFlash::enable() {}
void BSXFlash::power() {
reset();
}
void BSXFlash::reset() {
regs.command = 0;
regs.write_old = 0x00;
regs.write_new = 0x00;
regs.flash_enable = false;
regs.read_enable = false;
regs.write_enable = false;
}
unsigned BSXFlash::size() {
return memory::bscram.size();
}
uint8 BSXFlash::read(unsigned addr) {
if(addr == 0x0002) {
if(regs.flash_enable) return 0x80;
}
if(addr == 0x5555) {
if(regs.flash_enable) return 0x80;
}
if(regs.read_enable && addr >= 0xff00 && addr <= 0xff13) {
//read flash cartridge vendor information
switch(addr - 0xff00) {
case 0x00: return 0x4d;
case 0x01: return 0x00;
case 0x02: return 0x50;
case 0x03: return 0x00;
case 0x04: return 0x00;
case 0x05: return 0x00;
case 0x06: return 0x2a; //0x2a = 8mbit, 0x2b = 16mbit (not known to exist, though BIOS recognizes ID)
case 0x07: return 0x00;
default: return 0x00;
}
}
return memory::bscram.read(addr);
}
void BSXFlash::write(unsigned addr, uint8 data) {
//there exist both read-only and read-write BS-X flash cartridges ...
//unfortunately, the vendor info is not stored inside memory dumps
//of BS-X flashcarts, so it is impossible to determine whether a
//given flashcart is writeable.
//however, it has been observed that LoROM-mapped BS-X carts always
//use read-write flashcarts, and HiROM-mapped BS-X carts always use
//read-only flashcarts.
//below is an unfortunately necessary workaround to this problem.
if(cartridge.mapper() == Cartridge::BSCHiROM) return;
if((addr & 0xff0000) == 0) {
regs.write_old = regs.write_new;
regs.write_new = data;
if(regs.write_enable && regs.write_old == regs.write_new) {
return memory::bscram.write(addr, data);
}
} else {
if(regs.write_enable) {
return memory::bscram.write(addr, data);
}
}
if(addr == 0x0000) {
regs.command <<= 8;
regs.command |= data;
if((regs.command & 0xffff) == 0x38d0) {
regs.flash_enable = true;
regs.read_enable = true;
}
}
if(addr == 0x2aaa) {
regs.command <<= 8;
regs.command |= data;
}
if(addr == 0x5555) {
regs.command <<= 8;
regs.command |= data;
if((regs.command & 0xffffff) == 0xaa5570) {
regs.write_enable = false;
}
if((regs.command & 0xffffff) == 0xaa55a0) {
regs.write_old = 0x00;
regs.write_new = 0x00;
regs.flash_enable = true;
regs.write_enable = true;
}
if((regs.command & 0xffffff) == 0xaa55f0) {
regs.flash_enable = false;
regs.read_enable = false;
regs.write_enable = false;
}
}
}
#endif

View File

@@ -1,199 +0,0 @@
/*
C4 emulation
Used in Rockman X2/X3 (Megaman X2/X3)
Portions (c) anomie, Overload, zsKnight, Nach, byuu
*/
#include "../../base.h"
C4 *c4;
#include "c4data.cpp"
#include "c4fn.cpp"
#include "c4oam.cpp"
#include "c4ops.cpp"
void C4::init() {}
void C4::enable() {}
uint32 C4::ldr(uint8 r) {
uint16 addr = 0x0080 + (r * 3);
return (reg[addr]) | (reg[addr + 1] << 8) | (reg[addr + 2] << 16);
}
void C4::str(uint8 r, uint32 data) {
uint16 addr = 0x0080 + (r * 3);
reg[addr ] = (data);
reg[addr + 1] = (data >> 8);
reg[addr + 2] = (data >> 16);
}
void C4::mul(uint32 x, uint32 y, uint32 &rl, uint32 &rh) {
int64 rx = x & 0xffffff;
int64 ry = y & 0xffffff;
if(rx & 0x800000)rx |= ~0x7fffff;
if(ry & 0x800000)ry |= ~0x7fffff;
rx *= ry;
rl = (rx) & 0xffffff;
rh = (rx >> 24) & 0xffffff;
}
uint32 C4::sin(uint32 rx) {
r0 = rx & 0x1ff;
if(r0 & 0x100)r0 ^= 0x1ff;
if(r0 & 0x080)r0 ^= 0x0ff;
if(rx & 0x100) {
return sin_table[r0 + 0x80];
} else {
return sin_table[r0];
}
}
uint32 C4::cos(uint32 rx) {
return sin(rx + 0x080);
}
void C4::immediate_reg(uint32 start) {
r0 = ldr(0);
for(uint32 i=start;i<48;i++) {
if((r0 & 0x0fff) < 0x0c00) {
ram[r0 & 0x0fff] = immediate_data[i];
}
r0++;
}
str(0, r0);
}
void C4::transfer_data() {
uint32 src;
uint16 dest, count;
src = (reg[0x40]) | (reg[0x41] << 8) | (reg[0x42] << 16);
count = (reg[0x43]) | (reg[0x44] << 8);
dest = (reg[0x45]) | (reg[0x46] << 8);
for(uint32 i=0;i<count;i++) {
write(dest++, r_mem->read(src++));
}
}
void C4::write(uint16 addr, uint8 data) {
addr &= 0x1fff;
if(addr < 0x0c00) {
//ram
ram[addr] = data;
return;
}
if(addr < 0x1f00) {
//unmapped
return;
}
//command register
reg[addr & 0xff] = data;
if(addr == 0x1f47) {
//memory transfer
transfer_data();
return;
}
if(addr == 0x1f4f) {
//c4 command
if(reg[0x4d] == 0x0e && !(data & 0xc3)) {
//c4 test command
reg[0x80] = data >> 2;
return;
}
switch(data) {
case 0x00:op00();break;
case 0x01:op01();break;
case 0x05:op05();break;
case 0x0d:op0d();break;
case 0x10:op10();break;
case 0x13:op13();break;
case 0x15:op15();break;
case 0x1f:op1f();break;
case 0x22:op22();break;
case 0x25:op25();break;
case 0x2d:op2d();break;
case 0x40:op40();break;
case 0x54:op54();break;
case 0x5c:op5c();break;
case 0x5e:op5e();break;
case 0x60:op60();break;
case 0x62:op62();break;
case 0x64:op64();break;
case 0x66:op66();break;
case 0x68:op68();break;
case 0x6a:op6a();break;
case 0x6c:op6c();break;
case 0x6e:op6e();break;
case 0x70:op70();break;
case 0x72:op72();break;
case 0x74:op74();break;
case 0x76:op76();break;
case 0x78:op78();break;
case 0x7a:op7a();break;
case 0x7c:op7c();break;
case 0x89:op89();break;
}
}
}
void C4::writeb(uint16 addr, uint8 data) {
write(addr, data);
}
void C4::writew(uint16 addr, uint16 data) {
write(addr, data);
write(addr + 1, data >> 8);
}
void C4::writel(uint16 addr, uint32 data) {
write(addr, data);
write(addr + 1, data >> 8);
write(addr + 2, data >> 16);
}
uint8 C4::read(uint16 addr) {
addr &= 0x1fff;
if(addr < 0x0c00) {
return ram[addr];
}
if(addr >= 0x1f00) {
return reg[addr & 0xff];
}
return r_cpu->regs.mdr;
}
uint8 C4::readb(uint16 addr) {
return read(addr);
}
uint16 C4::readw(uint16 addr) {
return read(addr) | (read(addr + 1) << 8);
}
uint32 C4::readl(uint16 addr) {
return read(addr) | (read(addr + 1) << 8) + (read(addr + 2) << 16);
}
void C4::power() {
reset();
}
void C4::reset() {
memset(ram, 0, 0x0c00);
memset(reg, 0, 0x0100);
}
C4::C4() {}

11
src/chip/chip.hpp Normal file
View File

@@ -0,0 +1,11 @@
#include "bsx/bsx.hpp"
#include "srtc/srtc.hpp"
#include "sdd1/sdd1.hpp"
#include "spc7110/spc7110.hpp"
#include "cx4/cx4.hpp"
#include "dsp1/dsp1.hpp"
#include "dsp2/dsp2.hpp"
#include "dsp3/dsp3.hpp"
#include "dsp4/dsp4.hpp"
#include "obc1/obc1.hpp"
#include "st010/st010.hpp"

197
src/chip/cx4/cx4.cpp Normal file
View File

@@ -0,0 +1,197 @@
/*
C4 emulation
Used in Rockman X2/X3 (Megaman X2/X3)
Portions (c) anomie, Overload, zsKnight, Nach, byuu
*/
#include <../base.hpp>
#define CX4_CPP
#include "cx4.hpp"
#include "cx4data.cpp"
#include "cx4fn.cpp"
#include "cx4oam.cpp"
#include "cx4ops.cpp"
void Cx4::init() {}
void Cx4::enable() {}
uint32 Cx4::ldr(uint8 r) {
uint16 addr = 0x0080 + (r * 3);
return (reg[addr]) | (reg[addr + 1] << 8) | (reg[addr + 2] << 16);
}
void Cx4::str(uint8 r, uint32 data) {
uint16 addr = 0x0080 + (r * 3);
reg[addr ] = (data);
reg[addr + 1] = (data >> 8);
reg[addr + 2] = (data >> 16);
}
void Cx4::mul(uint32 x, uint32 y, uint32 &rl, uint32 &rh) {
int64 rx = x & 0xffffff;
int64 ry = y & 0xffffff;
if(rx & 0x800000)rx |= ~0x7fffff;
if(ry & 0x800000)ry |= ~0x7fffff;
rx *= ry;
rl = (rx) & 0xffffff;
rh = (rx >> 24) & 0xffffff;
}
uint32 Cx4::sin(uint32 rx) {
r0 = rx & 0x1ff;
if(r0 & 0x100)r0 ^= 0x1ff;
if(r0 & 0x080)r0 ^= 0x0ff;
if(rx & 0x100) {
return sin_table[r0 + 0x80];
} else {
return sin_table[r0];
}
}
uint32 Cx4::cos(uint32 rx) {
return sin(rx + 0x080);
}
void Cx4::immediate_reg(uint32 start) {
r0 = ldr(0);
for(uint32 i = start; i < 48; i++) {
if((r0 & 0x0fff) < 0x0c00) {
ram[r0 & 0x0fff] = immediate_data[i];
}
r0++;
}
str(0, r0);
}
void Cx4::transfer_data() {
uint32 src;
uint16 dest, count;
src = (reg[0x40]) | (reg[0x41] << 8) | (reg[0x42] << 16);
count = (reg[0x43]) | (reg[0x44] << 8);
dest = (reg[0x45]) | (reg[0x46] << 8);
for(uint32 i=0;i<count;i++) {
write(dest++, bus.read(src++));
}
}
void Cx4::write(unsigned addr, uint8 data) {
addr &= 0x1fff;
if(addr < 0x0c00) {
//ram
ram[addr] = data;
return;
}
if(addr < 0x1f00) {
//unmapped
return;
}
//command register
reg[addr & 0xff] = data;
if(addr == 0x1f47) {
//memory transfer
transfer_data();
return;
}
if(addr == 0x1f4f) {
//c4 command
if(reg[0x4d] == 0x0e && !(data & 0xc3)) {
//c4 test command
reg[0x80] = data >> 2;
return;
}
switch(data) {
case 0x00: op00(); break;
case 0x01: op01(); break;
case 0x05: op05(); break;
case 0x0d: op0d(); break;
case 0x10: op10(); break;
case 0x13: op13(); break;
case 0x15: op15(); break;
case 0x1f: op1f(); break;
case 0x22: op22(); break;
case 0x25: op25(); break;
case 0x2d: op2d(); break;
case 0x40: op40(); break;
case 0x54: op54(); break;
case 0x5c: op5c(); break;
case 0x5e: op5e(); break;
case 0x60: op60(); break;
case 0x62: op62(); break;
case 0x64: op64(); break;
case 0x66: op66(); break;
case 0x68: op68(); break;
case 0x6a: op6a(); break;
case 0x6c: op6c(); break;
case 0x6e: op6e(); break;
case 0x70: op70(); break;
case 0x72: op72(); break;
case 0x74: op74(); break;
case 0x76: op76(); break;
case 0x78: op78(); break;
case 0x7a: op7a(); break;
case 0x7c: op7c(); break;
case 0x89: op89(); break;
}
}
}
void Cx4::writeb(uint16 addr, uint8 data) {
write(addr, data);
}
void Cx4::writew(uint16 addr, uint16 data) {
write(addr, data);
write(addr + 1, data >> 8);
}
void Cx4::writel(uint16 addr, uint32 data) {
write(addr, data);
write(addr + 1, data >> 8);
write(addr + 2, data >> 16);
}
uint8 Cx4::read(unsigned addr) {
addr &= 0x1fff;
if(addr < 0x0c00) {
return ram[addr];
}
if(addr >= 0x1f00) {
return reg[addr & 0xff];
}
return cpu.regs.mdr;
}
uint8 Cx4::readb(uint16 addr) {
return read(addr);
}
uint16 Cx4::readw(uint16 addr) {
return read(addr) | (read(addr + 1) << 8);
}
uint32 Cx4::readl(uint16 addr) {
return read(addr) | (read(addr + 1) << 8) + (read(addr + 2) << 16);
}
void Cx4::power() {
reset();
}
void Cx4::reset() {
memset(ram, 0, 0x0c00);
memset(reg, 0, 0x0100);
}

View File

@@ -1,29 +1,29 @@
class C4 {
class Cx4 : public Memory {
private:
uint8 ram[0x0c00];
uint8 reg[0x0100];
uint32 r0, r1, r2, r3, r4, r5, r6, r7,
r8, r9, r10, r11, r12, r13, r14, r15;
uint8 ram[0x0c00];
uint8 reg[0x0100];
uint32 r0, r1, r2, r3, r4, r5, r6, r7,
r8, r9, r10, r11, r12, r13, r14, r15;
static const uint8 immediate_data[48];
static const uint16 wave_data[40];
static const uint32 sin_table[256];
static const uint8 immediate_data[48];
static const uint16 wave_data[40];
static const uint32 sin_table[256];
static const int16 SinTable[512];
static const int16 CosTable[512];
static const int16 SinTable[512];
static const int16 CosTable[512];
int16 C4WFXVal, C4WFYVal, C4WFZVal, C4WFX2Val, C4WFY2Val, C4WFDist, C4WFScale;
int16 C41FXVal, C41FYVal, C41FAngleRes, C41FDist, C41FDistVal;
int16 C4WFXVal, C4WFYVal, C4WFZVal, C4WFX2Val, C4WFY2Val, C4WFDist, C4WFScale;
int16 C41FXVal, C41FYVal, C41FAngleRes, C41FDist, C41FDistVal;
double tanval;
double c4x,c4y,c4z, c4x2,c4y2,c4z2;
double tanval;
double c4x,c4y,c4z, c4x2,c4y2,c4z2;
void C4TransfWireFrame();
void C4TransfWireFrame2();
void C4CalcWireFrame();
void C4DrawLine(int32 X1, int32 Y1, int16 Z1, int32 X2, int32 Y2, int16 Z2, uint8 Color);
void C4DrawWireFrame();
void C4DoScaleRotate(int row_padding);
void C4TransfWireFrame();
void C4TransfWireFrame2();
void C4CalcWireFrame();
void C4DrawLine(int32 X1, int32 Y1, int16 Z1, int32 X2, int32 Y2, int16 Z2, uint8 Color);
void C4DrawWireFrame();
void C4DoScaleRotate(int row_padding);
public:
uint32 ldr(uint8 r);
@@ -75,22 +75,23 @@ public:
void op7c();
void op89();
uint8 readb(uint16 addr);
uint16 readw(uint16 addr);
uint32 readl(uint16 addr);
void writeb(uint16 addr, uint8 data);
void writew(uint16 addr, uint16 data);
void writel(uint16 addr, uint32 data);
//
void init();
void enable();
void power();
void reset();
void write (uint16 addr, uint8 data);
void writeb(uint16 addr, uint8 data);
void writew(uint16 addr, uint16 data);
void writel(uint16 addr, uint32 data);
uint8 read (uint16 addr);
uint8 readb(uint16 addr);
uint16 readw(uint16 addr);
uint32 readl(uint16 addr);
C4();
uint8 read (unsigned addr);
void write(unsigned addr, uint8 data);
};
extern C4 *c4;
extern Cx4 cx4;

View File

@@ -1,11 +1,13 @@
const uint8 C4::immediate_data[48] = {
#ifdef CX4_CPP
const uint8 Cx4::immediate_data[48] = {
0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff,
0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x80, 0xff, 0xff, 0x7f,
0x00, 0x80, 0x00, 0xff, 0x7f, 0x00, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0xff,
0x00, 0x00, 0x01, 0xff, 0xff, 0xfe, 0x00, 0x01, 0x00, 0xff, 0xfe, 0x00
};
const uint16 C4::wave_data[40] = {
const uint16 Cx4::wave_data[40] = {
0x0000, 0x0002, 0x0004, 0x0006, 0x0008, 0x000a, 0x000c, 0x000e,
0x0200, 0x0202, 0x0204, 0x0206, 0x0208, 0x020a, 0x020c, 0x020e,
0x0400, 0x0402, 0x0404, 0x0406, 0x0408, 0x040a, 0x040c, 0x040e,
@@ -13,7 +15,7 @@ const uint16 C4::wave_data[40] = {
0x0800, 0x0802, 0x0804, 0x0806, 0x0808, 0x080a, 0x080c, 0x080e
};
const uint32 C4::sin_table[256] = {
const uint32 Cx4::sin_table[256] = {
0x000000, 0x000324, 0x000648, 0x00096c, 0x000c8f, 0x000fb2, 0x0012d5, 0x0015f6,
0x001917, 0x001c37, 0x001f56, 0x002273, 0x002590, 0x0028aa, 0x002bc4, 0x002edb,
0x0031f1, 0x003505, 0x003817, 0x003b26, 0x003e33, 0x00413e, 0x004447, 0x00474d,
@@ -48,7 +50,7 @@ const uint32 C4::sin_table[256] = {
0xff013b, 0xff00f1, 0xff00b1, 0xff007b, 0xff004e, 0xff002c, 0xff0013, 0xff0004
};
const int16 C4::SinTable[512] = {
const int16 Cx4::SinTable[512] = {
0, 402, 804, 1206, 1607, 2009, 2410, 2811,
3211, 3611, 4011, 4409, 4808, 5205, 5602, 5997,
6392, 6786, 7179, 7571, 7961, 8351, 8739, 9126,
@@ -115,7 +117,7 @@ const int16 C4::SinTable[512] = {
-3211, -2811, -2410, -2009, -1607, -1206, -804, -402
};
const int16 C4::CosTable[512] = {
const int16 Cx4::CosTable[512] = {
32767, 32765, 32758, 32745, 32728, 32706, 32679, 32647,
32610, 32568, 32521, 32469, 32413, 32351, 32285, 32214,
32138, 32057, 31971, 31881, 31785, 31685, 31581, 31471,
@@ -181,3 +183,5 @@ const int16 C4::CosTable[512] = {
32138, 32214, 32285, 32351, 32413, 32469, 32521, 32568,
32610, 32647, 32679, 32706, 32728, 32745, 32758, 32765
};
#endif

View File

@@ -1,3 +1,5 @@
#ifdef CX4_CPP
#include <math.h>
#define Tan(a) (CosTable[a] ? ((((int32)SinTable[a]) << 16) / CosTable[a]) : 0x80000000)
#define sar(b, n) ((b) >> (n))
@@ -7,7 +9,7 @@
#define PI 3.1415926535897932384626433832795
//Wireframe Helpers
void C4::C4TransfWireFrame() {
void Cx4::C4TransfWireFrame() {
c4x = (double)C4WFXVal;
c4y = (double)C4WFYVal;
c4z = (double)C4WFZVal - 0x95;
@@ -32,7 +34,7 @@ void C4::C4TransfWireFrame() {
C4WFYVal = (int16)(c4y * C4WFScale / (0x90 * (c4z + 0x95)) * 0x95);
}
void C4::C4CalcWireFrame() {
void Cx4::C4CalcWireFrame() {
C4WFXVal = C4WFX2Val - C4WFXVal;
C4WFYVal = C4WFY2Val - C4WFYVal;
@@ -49,7 +51,7 @@ void C4::C4CalcWireFrame() {
}
}
void C4::C4TransfWireFrame2() {
void Cx4::C4TransfWireFrame2() {
c4x = (double)C4WFXVal;
c4y = (double)C4WFYVal;
c4z = (double)C4WFZVal;
@@ -74,34 +76,34 @@ void C4::C4TransfWireFrame2() {
C4WFYVal = (int16)(c4y * C4WFScale / 0x100);
}
void C4::C4DrawWireFrame() {
void Cx4::C4DrawWireFrame() {
uint32 line = readl(0x1f80);
uint32 point1, point2;
int16 X1, Y1, Z1;
int16 X2, Y2, Z2;
uint8 Color;
for(int32 i = ram[0x0295]; i > 0; i--, line += 5) {
if(r_mem->read(line) == 0xff && r_mem->read(line + 1) == 0xff) {
if(bus.read(line) == 0xff && bus.read(line + 1) == 0xff) {
int32 tmp = line - 5;
while(r_mem->read(tmp + 2) == 0xff && r_mem->read(tmp + 3) == 0xff && (tmp + 2) >= 0) { tmp -= 5; }
point1 = (read(0x1f82) << 16) | (r_mem->read(tmp + 2) << 8) | r_mem->read(tmp + 3);
while(bus.read(tmp + 2) == 0xff && bus.read(tmp + 3) == 0xff && (tmp + 2) >= 0) { tmp -= 5; }
point1 = (read(0x1f82) << 16) | (bus.read(tmp + 2) << 8) | bus.read(tmp + 3);
} else {
point1 = (read(0x1f82) << 16) | (r_mem->read(line) << 8) | r_mem->read(line + 1);
point1 = (read(0x1f82) << 16) | (bus.read(line) << 8) | bus.read(line + 1);
}
point2 = (read(0x1f82) << 16) | (r_mem->read(line + 2) << 8) | r_mem->read(line + 3);
point2 = (read(0x1f82) << 16) | (bus.read(line + 2) << 8) | bus.read(line + 3);
X1=(r_mem->read(point1 + 0) << 8) | r_mem->read(point1 + 1);
Y1=(r_mem->read(point1 + 2) << 8) | r_mem->read(point1 + 3);
Z1=(r_mem->read(point1 + 4) << 8) | r_mem->read(point1 + 5);
X2=(r_mem->read(point2 + 0) << 8) | r_mem->read(point2 + 1);
Y2=(r_mem->read(point2 + 2) << 8) | r_mem->read(point2 + 3);
Z2=(r_mem->read(point2 + 4) << 8) | r_mem->read(point2 + 5);
Color = r_mem->read(line + 4);
X1=(bus.read(point1 + 0) << 8) | bus.read(point1 + 1);
Y1=(bus.read(point1 + 2) << 8) | bus.read(point1 + 3);
Z1=(bus.read(point1 + 4) << 8) | bus.read(point1 + 5);
X2=(bus.read(point2 + 0) << 8) | bus.read(point2 + 1);
Y2=(bus.read(point2 + 2) << 8) | bus.read(point2 + 3);
Z2=(bus.read(point2 + 4) << 8) | bus.read(point2 + 5);
Color = bus.read(line + 4);
C4DrawLine(X1, Y1, Z1, X2, Y2, Z2, Color);
}
}
void C4::C4DrawLine(int32 X1, int32 Y1, int16 Z1, int32 X2, int32 Y2, int16 Z2, uint8 Color) {
void Cx4::C4DrawLine(int32 X1, int32 Y1, int16 Z1, int32 X2, int32 Y2, int16 Z2, uint8 Color) {
//Transform coordinates
C4WFXVal = (int16)X1;
C4WFYVal = (int16)Y1;
@@ -145,7 +147,7 @@ void C4::C4DrawLine(int32 X1, int32 Y1, int16 Z1, int32 X2, int32 Y2, int16 Z2,
}
}
void C4::C4DoScaleRotate(int row_padding) {
void Cx4::C4DoScaleRotate(int row_padding) {
int16 A, B, C, D;
//Calculate matrix
@@ -240,3 +242,5 @@ uint8 bit = 0x80;
LineY += D;
}
}
#endif

View File

@@ -1,5 +1,7 @@
#ifdef CX4_CPP
//Build OAM
void C4::op00_00() {
void Cx4::op00_00() {
uint32 oamptr = ram[0x626] << 2;
for(int32 i = 0x1fd; i > oamptr && i >= 0; i -= 4) {
//clear oam-to-be
@@ -27,28 +29,28 @@ uint32 srcptr = 0x220;
sprattr = ram[srcptr + 4] | ram[srcptr + 6];
uint32 spraddr = readl(srcptr + 7);
if(r_mem->read(spraddr)) {
if(bus.read(spraddr)) {
int16 x, y;
for(int sprcnt = r_mem->read(spraddr++); sprcnt > 0 && sprcount > 0; sprcnt--, spraddr += 4) {
x = (int8)r_mem->read(spraddr + 1);
for(int sprcnt = bus.read(spraddr++); sprcnt > 0 && sprcount > 0; sprcnt--, spraddr += 4) {
x = (int8)bus.read(spraddr + 1);
if(sprattr & 0x40) {
x = -x - ((r_mem->read(spraddr) & 0x20) ? 16 : 8);
x = -x - ((bus.read(spraddr) & 0x20) ? 16 : 8);
}
x += sprx;
if(x >= -16 && x <= 272) {
y = (int8)r_mem->read(spraddr + 2);
y = (int8)bus.read(spraddr + 2);
if(sprattr & 0x80) {
y = -y - ((r_mem->read(spraddr) & 0x20) ? 16 : 8);
y = -y - ((bus.read(spraddr) & 0x20) ? 16 : 8);
}
y += spry;
if(y >= -16 && y <= 224) {
ram[oamptr ] = (uint8)x;
ram[oamptr + 1] = (uint8)y;
ram[oamptr + 2] = sprname + r_mem->read(spraddr + 3);
ram[oamptr + 3] = sprattr ^ (r_mem->read(spraddr) & 0xc0);
ram[oamptr + 2] = sprname + bus.read(spraddr + 3);
ram[oamptr + 3] = sprattr ^ (bus.read(spraddr) & 0xc0);
ram[oamptr2] &= ~(3 << offset);
if(x & 0x100)ram[oamptr2] |= 1 << offset;
if(r_mem->read(spraddr) & 0x20)ram[oamptr2] |= 2 << offset;
if(bus.read(spraddr) & 0x20)ram[oamptr2] |= 2 << offset;
oamptr += 4;
sprcount--;
offset = (offset + 2) & 6;
@@ -73,12 +75,12 @@ uint32 srcptr = 0x220;
}
//Scale and Rotate
void C4::op00_03() {
void Cx4::op00_03() {
C4DoScaleRotate(0);
}
//Transform Lines
void C4::op00_05() {
void Cx4::op00_05() {
C4WFX2Val = read(0x1f83);
C4WFY2Val = read(0x1f86);
C4WFDist = read(0x1f89);
@@ -119,17 +121,17 @@ uint32 ptr2 = 0;
}
//Scale and Rotate
void C4::op00_07() {
void Cx4::op00_07() {
C4DoScaleRotate(64);
}
//Draw Wireframe
void C4::op00_08() {
void Cx4::op00_08() {
C4DrawWireFrame();
}
//Disintegrate
void C4::op00_0b() {
void Cx4::op00_0b() {
uint8 width, height;
uint32 startx, starty;
uint32 srcptr;
@@ -169,7 +171,7 @@ int32 i, j;
}
//Bitplane Wave
void C4::op00_0c() {
void Cx4::op00_0c() {
uint32 destptr = 0;
uint32 waveptr = read(0x1f83);
uint16 mask1 = 0xc0c0;
@@ -217,3 +219,5 @@ uint16 mask2 = 0x3f3f;
destptr += 16;
}
}
#endif

View File

@@ -1,5 +1,7 @@
#ifdef CX4_CPP
//Sprite Functions
void C4::op00() {
void Cx4::op00() {
switch(reg[0x4d]) {
case 0x00:op00_00();break;
case 0x03:op00_03();break;
@@ -12,13 +14,13 @@ void C4::op00() {
}
//Draw Wireframe
void C4::op01() {
void Cx4::op01() {
memset(ram + 0x300, 0, 2304);
C4DrawWireFrame();
}
//Propulsion
void C4::op05() {
void Cx4::op05() {
int32 temp = 0x10000;
if(readw(0x1f83)) {
temp = sar((temp / readw(0x1f83)) * readw(0x1f81), 8);
@@ -27,7 +29,7 @@ int32 temp = 0x10000;
}
//Set Vector length
void C4::op0d() {
void Cx4::op0d() {
C41FXVal = readw(0x1f80);
C41FYVal = readw(0x1f83);
C41FDistVal = readw(0x1f86);
@@ -40,7 +42,7 @@ void C4::op0d() {
}
//Triangle
void C4::op10() {
void Cx4::op10() {
r0 = ldr(0);
r1 = ldr(1);
@@ -64,7 +66,7 @@ void C4::op10() {
}
//Triangle
void C4::op13() {
void Cx4::op13() {
r0 = ldr(0);
r1 = ldr(1);
@@ -87,7 +89,7 @@ void C4::op13() {
}
//Pythagorean
void C4::op15() {
void Cx4::op15() {
C41FXVal = readw(0x1f80);
C41FYVal = readw(0x1f83);
C41FDist = (int16)sqrt((double)C41FXVal * (double)C41FXVal + (double)C41FYVal * (double)C41FYVal);
@@ -95,7 +97,7 @@ void C4::op15() {
}
//Calculate distance
void C4::op1f() {
void Cx4::op1f() {
C41FXVal = readw(0x1f80);
C41FYVal = readw(0x1f83);
if(!C41FXVal) {
@@ -113,7 +115,7 @@ void C4::op1f() {
}
//Trapezoid
void C4::op22() {
void Cx4::op22() {
int16 angle1 = readw(0x1f8c) & 0x1ff;
int16 angle2 = readw(0x1f8f) & 0x1ff;
int32 tan1 = Tan(angle1);
@@ -152,7 +154,7 @@ int16 left, right;
}
//Multiply
void C4::op25() {
void Cx4::op25() {
r0 = ldr(0);
r1 = ldr(1);
mul(r0, r1, r0, r1);
@@ -161,7 +163,7 @@ void C4::op25() {
}
//Transform Coords
void C4::op2d() {
void Cx4::op2d() {
C4WFXVal = readw(0x1f81);
C4WFYVal = readw(0x1f84);
C4WFZVal = readw(0x1f87);
@@ -175,7 +177,7 @@ void C4::op2d() {
}
//Sum
void C4::op40() {
void Cx4::op40() {
r0 = 0;
for(uint32 i=0;i<0x800;i++) {
r0 += ram[i];
@@ -184,7 +186,7 @@ void C4::op40() {
}
//Square
void C4::op54() {
void Cx4::op54() {
r0 = ldr(0);
mul(r0, r0, r1, r2);
str(1, r1);
@@ -192,31 +194,33 @@ void C4::op54() {
}
//Immediate Register
void C4::op5c() {
void Cx4::op5c() {
str(0, 0x000000);
immediate_reg(0);
}
//Immediate Register (Multiple)
void C4::op5e() { immediate_reg( 0); }
void C4::op60() { immediate_reg( 3); }
void C4::op62() { immediate_reg( 6); }
void C4::op64() { immediate_reg( 9); }
void C4::op66() { immediate_reg(12); }
void C4::op68() { immediate_reg(15); }
void C4::op6a() { immediate_reg(18); }
void C4::op6c() { immediate_reg(21); }
void C4::op6e() { immediate_reg(24); }
void C4::op70() { immediate_reg(27); }
void C4::op72() { immediate_reg(30); }
void C4::op74() { immediate_reg(33); }
void C4::op76() { immediate_reg(36); }
void C4::op78() { immediate_reg(39); }
void C4::op7a() { immediate_reg(42); }
void C4::op7c() { immediate_reg(45); }
void Cx4::op5e() { immediate_reg( 0); }
void Cx4::op60() { immediate_reg( 3); }
void Cx4::op62() { immediate_reg( 6); }
void Cx4::op64() { immediate_reg( 9); }
void Cx4::op66() { immediate_reg(12); }
void Cx4::op68() { immediate_reg(15); }
void Cx4::op6a() { immediate_reg(18); }
void Cx4::op6c() { immediate_reg(21); }
void Cx4::op6e() { immediate_reg(24); }
void Cx4::op70() { immediate_reg(27); }
void Cx4::op72() { immediate_reg(30); }
void Cx4::op74() { immediate_reg(33); }
void Cx4::op76() { immediate_reg(36); }
void Cx4::op78() { immediate_reg(39); }
void Cx4::op7a() { immediate_reg(42); }
void Cx4::op7c() { immediate_reg(45); }
//Immediate ROM
void C4::op89() {
void Cx4::op89() {
str(0, 0x054336);
str(1, 0xffffff);
}
#endif

View File

@@ -1,7 +1,8 @@
#include "../../base.h"
DSP1 *dsp1;
#include <../base.hpp>
#include <../cart/cart.hpp>
#define DSP1_CPP
#include "dsp1.hpp"
#include "dsp1emu.cpp"
void DSP1::init() {}
@@ -28,29 +29,30 @@ void DSP1::reset() {
*****/
bool DSP1::addr_decode(uint16 addr) {
switch(cartridge.info.dsp1_mapper) {
case Cartridge::DSP1LoROM1MB: {
//$[20-3f]:[8000-bfff] = DR, $[20-3f]:[c000-ffff] = SR
return (addr >= 0xc000);
}
case Cartridge::DSP1_LOROM_1MB:
//$[20-3f]:[8000-bfff] = DR, $[20-3f]:[c000-ffff] = SR
return (addr >= 0xc000);
case Cartridge::DSP1_LOROM_2MB:
//$[60-6f]:[0000-3fff] = DR, $[60-6f]:[4000-7fff] = SR
return (addr >= 0x4000);
case Cartridge::DSP1_HIROM:
//$[00-1f]:[6000-6fff] = DR, $[00-1f]:[7000-7fff] = SR
return (addr >= 0x7000);
case Cartridge::DSP1LoROM2MB: {
//$[60-6f]:[0000-3fff] = DR, $[60-6f]:[4000-7fff] = SR
return (addr >= 0x4000);
}
case Cartridge::DSP1HiROM: {
//$[00-1f]:[6000-6fff] = DR, $[00-1f]:[7000-7fff] = SR
return (addr >= 0x7000);
}
}
return 0;
}
uint8 DSP1::read(uint16 addr) {
uint8 DSP1::read(unsigned addr) {
return (addr_decode(addr) == 0) ? dsp1.getDr() : dsp1.getSr();
}
void DSP1::write(uint16 addr, uint8 data) {
void DSP1::write(unsigned addr, uint8 data) {
if(addr_decode(addr) == 0) {
dsp1.setDr(data);
}

View File

@@ -1,18 +0,0 @@
#include "dsp1emu.h"
class DSP1 {
private:
Dsp1 dsp1;
public:
void init();
void enable();
void power();
void reset();
bool addr_decode(uint16 addr);
uint8 read (uint16 addr);
void write(uint16 addr, uint8 data);
};
extern DSP1 *dsp1;

18
src/chip/dsp1/dsp1.hpp Normal file
View File

@@ -0,0 +1,18 @@
#include "dsp1emu.hpp"
class DSP1 : public Memory {
private:
Dsp1 dsp1;
bool addr_decode(uint16 addr);
public:
void init();
void enable();
void power();
void reset();
uint8 read(unsigned addr);
void write(unsigned addr, uint8 data);
};
extern DSP1 dsp1;

View File

@@ -1,3 +1,5 @@
#ifdef DSP1_CPP
// DSP-1's emulation code
//
// Based on research by Overload, The Dumper, Neviksti and Andreas Naive
@@ -1620,3 +1622,4 @@ const int16 Dsp1::SinTable[256] = {
//////////////////////////////////////////////////////////////////
#endif

View File

@@ -1,7 +1,7 @@
#include "../../base.h"
DSP2 *dsp2;
#include <../base.hpp>
#define DSP2_CPP
#include "dsp2.hpp"
#include "dsp2_op.cpp"
void DSP2::init() {}
@@ -30,8 +30,8 @@ void DSP2::reset() {
status.op0dinlen = 0;
}
uint8 DSP2::read(uint16 addr) {
uint8 r = 0xff;
uint8 DSP2::read(unsigned addr) {
uint8 r = 0xff;
if(status.out_count) {
r = status.output[status.out_index++];
status.out_index &= 511;
@@ -42,7 +42,7 @@ uint8 r = 0xff;
return r;
}
void DSP2::write(uint16 addr, uint8 data) {
void DSP2::write(unsigned addr, uint8 data) {
if(status.waiting_for_command) {
status.command = data;
status.in_index = 0;

View File

@@ -1,43 +0,0 @@
class DSP2 {
public:
struct {
bool waiting_for_command;
uint command;
uint in_count, in_index;
uint out_count, out_index;
uint8 parameters[512];
uint8 output[512];
uint8 op05transparent;
bool op05haslen;
int op05len;
bool op06haslen;
int op06len;
uint16 op09word1;
uint16 op09word2;
bool op0dhaslen;
int op0doutlen;
int op0dinlen;
} status;
void init();
void enable();
void power();
void reset();
void op01();
void op03();
void op05();
void op06();
void op09();
void op0d();
uint8 read (uint16 addr);
void write(uint16 addr, uint8 data);
DSP2();
~DSP2();
};
extern DSP2 *dsp2;

44
src/chip/dsp2/dsp2.hpp Normal file
View File

@@ -0,0 +1,44 @@
class DSP2 : public Memory {
public:
struct {
bool waiting_for_command;
unsigned command;
unsigned in_count, in_index;
unsigned out_count, out_index;
uint8 parameters[512];
uint8 output[512];
uint8 op05transparent;
bool op05haslen;
int op05len;
bool op06haslen;
int op06len;
uint16 op09word1;
uint16 op09word2;
bool op0dhaslen;
int op0doutlen;
int op0dinlen;
} status;
void init();
void enable();
void power();
void reset();
uint8 read(unsigned addr);
void write(unsigned addr, uint8 data);
DSP2();
~DSP2();
protected:
void op01();
void op03();
void op05();
void op06();
void op09();
void op0d();
};
extern DSP2 dsp2;

View File

@@ -1,3 +1,5 @@
#ifdef DSP2_CPP
//convert bitmap to bitplane tile
void DSP2::op01() {
//op01 size is always 32 bytes input and output
@@ -171,3 +173,5 @@ uint8 pixelarray[512];
status.output[i] = (pixelarray[i << 1] << 4) | pixelarray[(i << 1) + 1];
}
}
#endif

35
src/chip/dsp3/dsp3.cpp Normal file
View File

@@ -0,0 +1,35 @@
#include <../base.hpp>
#define DSP3_CPP
#include "dsp3.hpp"
namespace DSP3i {
#define bool8 uint8
#include "dsp3emu.c"
#undef bool8
};
void DSP3::init() {
}
void DSP3::enable() {
}
void DSP3::power() {
reset();
}
void DSP3::reset() {
DSP3i::DSP3_Reset();
}
uint8 DSP3::read(unsigned addr) {
DSP3i::dsp3_address = addr & 0xffff;
DSP3i::DSP3GetByte();
return DSP3i::dsp3_byte;
}
void DSP3::write(unsigned addr, uint8 data) {
DSP3i::dsp3_address = addr & 0xffff;
DSP3i::dsp3_byte = data;
DSP3i::DSP3SetByte();
}

12
src/chip/dsp3/dsp3.hpp Normal file
View File

@@ -0,0 +1,12 @@
class DSP3 : public Memory {
public:
void init();
void enable();
void power();
void reset();
uint8 read (unsigned addr);
void write(unsigned addr, uint8 data);
};
extern DSP3 dsp3;

1146
src/chip/dsp3/dsp3emu.c Normal file

File diff suppressed because it is too large Load Diff

55
src/chip/dsp4/dsp4.cpp Normal file
View File

@@ -0,0 +1,55 @@
#include <../base.hpp>
#define DSP4_CPP
#include "dsp4.hpp"
namespace DSP4i {
inline uint16 READ_WORD(uint8 *addr) {
return (addr[0]) + (addr[1] << 8);
}
inline uint32 READ_DWORD(uint8 *addr) {
return (addr[0]) + (addr[1] << 8) + (addr[2] << 16) + (addr[3] << 24);
}
inline void WRITE_WORD(uint8 *addr, uint16 data) {
addr[0] = data;
addr[1] = data >> 8;
}
#define bool8 uint8
#include "dsp4emu.c"
#undef bool8
};
void DSP4::init() {
}
void DSP4::enable() {
}
void DSP4::power() {
reset();
}
void DSP4::reset() {
DSP4i::InitDSP4();
}
uint8 DSP4::read(unsigned addr) {
addr &= 0xffff;
if(addr < 0xc000) {
DSP4i::dsp4_address = addr;
DSP4i::DSP4GetByte();
return DSP4i::dsp4_byte;
}
return 0x80;
}
void DSP4::write(unsigned addr, uint8 data) {
addr &= 0xffff;
if(addr < 0xc000) {
DSP4i::dsp4_address = addr;
DSP4i::dsp4_byte = data;
DSP4i::DSP4SetByte();
}
}

12
src/chip/dsp4/dsp4.hpp Normal file
View File

@@ -0,0 +1,12 @@
class DSP4 : public Memory {
public:
void init();
void enable();
void power();
void reset();
uint8 read (unsigned addr);
void write(unsigned addr, uint8 data);
};
extern DSP4 dsp4;

2150
src/chip/dsp4/dsp4emu.c Normal file

File diff suppressed because it is too large Load Diff

108
src/chip/dsp4/dsp4emu.h Normal file
View File

@@ -0,0 +1,108 @@
//DSP-4 emulator code
//Copyright (c) 2004-2006 Dreamer Nom, John Weidman, Kris Bleakley, Nach, z80 gaiden
#ifndef DSP4EMU_H
#define DSP4EMU_H
#undef TRUE
#undef FALSE
#define TRUE true
#define FALSE false
struct DSP4_t
{
bool8 waiting4command;
bool8 half_command;
uint16 command;
uint32 in_count;
uint32 in_index;
uint32 out_count;
uint32 out_index;
uint8 parameters[512];
uint8 output[512];
};
extern struct DSP4_t DSP4;
struct DSP4_vars_t
{
// op control
int8 DSP4_Logic; // controls op flow
// projection format
int16 lcv; // loop-control variable
int16 distance; // z-position into virtual world
int16 raster; // current raster line
int16 segments; // number of raster lines drawn
// 1.15.16 or 1.15.0 [sign, integer, fraction]
int32 world_x; // line of x-projection in world
int32 world_y; // line of y-projection in world
int32 world_dx; // projection line x-delta
int32 world_dy; // projection line y-delta
int16 world_ddx; // x-delta increment
int16 world_ddy; // y-delta increment
int32 world_xenv; // world x-shaping factor
int16 world_yofs; // world y-vertical scroll
int16 view_x1; // current viewer-x
int16 view_y1; // current viewer-y
int16 view_x2; // future viewer-x
int16 view_y2; // future viewer-y
int16 view_dx; // view x-delta factor
int16 view_dy; // view y-delta factor
int16 view_xofs1; // current viewer x-vertical scroll
int16 view_yofs1; // current viewer y-vertical scroll
int16 view_xofs2; // future viewer x-vertical scroll
int16 view_yofs2; // future viewer y-vertical scroll
int16 view_yofsenv; // y-scroll shaping factor
int16 view_turnoff_x; // road turnoff data
int16 view_turnoff_dx; // road turnoff delta factor
// drawing area
int16 viewport_cx; // x-center of viewport window
int16 viewport_cy; // y-center of render window
int16 viewport_left; // x-left of viewport
int16 viewport_right; // x-right of viewport
int16 viewport_top; // y-top of viewport
int16 viewport_bottom; // y-bottom of viewport
// sprite structure
int16 sprite_x; // projected x-pos of sprite
int16 sprite_y; // projected y-pos of sprite
int16 sprite_attr; // obj attributes
bool8 sprite_size; // sprite size: 8x8 or 16x16
int16 sprite_clipy; // visible line to clip pixels off
int16 sprite_count;
// generic projection variables designed for
// two solid polygons + two polygon sides
int16 poly_clipLf[2][2]; // left clip boundary
int16 poly_clipRt[2][2]; // right clip boundary
int16 poly_ptr[2][2]; // HDMA structure pointers
int16 poly_raster[2][2]; // current raster line below horizon
int16 poly_top[2][2]; // top clip boundary
int16 poly_bottom[2][2]; // bottom clip boundary
int16 poly_cx[2][2]; // center for left/right points
int16 poly_start[2]; // current projection points
int16 poly_plane[2]; // previous z-plane distance
// OAM
int16 OAM_attr[16]; // OAM (size,MSB) data
int16 OAM_index; // index into OAM table
int16 OAM_bits; // offset into OAM table
int16 OAM_RowMax; // maximum number of tiles per 8 aligned pixels (row)
int16 OAM_Row[32]; // current number of tiles per row
};
extern struct DSP4_vars_t DSP4_vars;
#endif

View File

@@ -1,6 +1,6 @@
#include "../../base.h"
OBC1 *obc1;
#include <../base.hpp>
#include <../cart/cart.hpp>
#include "obc1.hpp"
void OBC1::init() {}
void OBC1::enable() {}
@@ -10,81 +10,63 @@ void OBC1::power() {
}
void OBC1::reset() {
memset(cartridge.ram, 0xff, 0x2000);
status.baseptr = (cartridge.ram[0x1ff5] & 1) ? 0x1800 : 0x1c00;
status.address = (cartridge.ram[0x1ff6] & 0x7f);
status.shift = (cartridge.ram[0x1ff6] & 3) << 1;
for(unsigned i = 0x0000; i <= 0x1fff; i++) ram_write(i, 0xff);
status.baseptr = (ram_read(0x1ff5) & 1) ? 0x1800 : 0x1c00;
status.address = (ram_read(0x1ff6) & 0x7f);
status.shift = (ram_read(0x1ff6) & 3) << 1;
}
uint8 OBC1::read(uint16 addr) {
uint8 OBC1::read(unsigned addr) {
addr &= 0x1fff;
if((addr & 0x1ff8) != 0x1ff0) return ram_read(addr);
if((addr & 0x1ff8) != 0x1ff0) {
return cartridge.ram[addr];
switch(addr) { default: //never used, avoids compiler warning
case 0x1ff0: return ram_read(status.baseptr + (status.address << 2) + 0);
case 0x1ff1: return ram_read(status.baseptr + (status.address << 2) + 1);
case 0x1ff2: return ram_read(status.baseptr + (status.address << 2) + 2);
case 0x1ff3: return ram_read(status.baseptr + (status.address << 2) + 3);
case 0x1ff4: return ram_read(status.baseptr + (status.address >> 2) + 0x200);
case 0x1ff5: case 0x1ff6: case 0x1ff7: return ram_read(addr);
}
switch(addr) {
case 0x1ff0:
return cartridge.ram[status.baseptr + (status.address << 2) + 0];
case 0x1ff1:
return cartridge.ram[status.baseptr + (status.address << 2) + 1];
case 0x1ff2:
return cartridge.ram[status.baseptr + (status.address << 2) + 2];
case 0x1ff3:
return cartridge.ram[status.baseptr + (status.address << 2) + 3];
case 0x1ff4:
return cartridge.ram[status.baseptr + (status.address >> 2) + 0x200];
case 0x1ff5:
case 0x1ff6:
case 0x1ff7:
return cartridge.ram[addr];
}
//never used, blocks compiler warning
return 0x00;
}
void OBC1::write(uint16 addr, uint8 data) {
void OBC1::write(unsigned addr, uint8 data) {
addr &= 0x1fff;
if((addr & 0x1ff8) != 0x1ff0) {
cartridge.ram[addr] = data;
return;
}
if((addr & 0x1ff8) != 0x1ff0) return ram_write(addr, data);
switch(addr) {
case 0x1ff0:
cartridge.ram[status.baseptr + (status.address << 2) + 0] = data;
break;
case 0x1ff1:
cartridge.ram[status.baseptr + (status.address << 2) + 1] = data;
break;
case 0x1ff2:
cartridge.ram[status.baseptr + (status.address << 2) + 2] = data;
break;
case 0x1ff3:
cartridge.ram[status.baseptr + (status.address << 2) + 3] = data;
break;
case 0x1ff4: {
uint8 temp;
temp = cartridge.ram[status.baseptr + (status.address >> 2) + 0x200];
temp = (temp & ~(3 << status.shift)) | ((data & 3) << status.shift);
cartridge.ram[status.baseptr + (status.address >> 2) + 0x200] = temp;
} break;
case 0x1ff5:
status.baseptr = (data & 1) ? 0x1800 : 0x1c00;
cartridge.ram[addr] = data;
break;
case 0x1ff6:
status.address = (data & 0x7f);
status.shift = (data & 3) << 1;
cartridge.ram[addr] = data;
break;
case 0x1ff7:
cartridge.ram[addr] = data;
break;
case 0x1ff0: ram_write(status.baseptr + (status.address << 2) + 0, data); break;
case 0x1ff1: ram_write(status.baseptr + (status.address << 2) + 1, data); break;
case 0x1ff2: ram_write(status.baseptr + (status.address << 2) + 2, data); break;
case 0x1ff3: ram_write(status.baseptr + (status.address << 2) + 3, data); break;
case 0x1ff4: {
uint8 temp = ram_read(status.baseptr + (status.address >> 2) + 0x200);
temp = (temp & ~(3 << status.shift)) | ((data & 3) << status.shift);
ram_write(status.baseptr + (status.address >> 2) + 0x200, temp);
} break;
case 0x1ff5: {
status.baseptr = (data & 1) ? 0x1800 : 0x1c00;
ram_write(addr, data);
} break;
case 0x1ff6: {
status.address = (data & 0x7f);
status.shift = (data & 3) << 1;
ram_write(addr, data);
} break;
case 0x1ff7: {
ram_write(addr, data);
} break;
}
}
uint8 OBC1::ram_read(unsigned addr) {
return memory::cartram.read(addr & 0x1fff);
}
void OBC1::ram_write(unsigned addr, uint8 data) {
memory::cartram.write(addr & 0x1fff, data);
}
OBC1::OBC1() {}
OBC1::~OBC1() {}

View File

@@ -1,20 +0,0 @@
class OBC1 {
public:
struct {
uint16 address;
uint16 baseptr;
uint16 shift;
} status;
void init();
void enable();
void power();
void reset();
uint8 read (uint16 addr);
void write(uint16 addr, uint8 data);
OBC1();
~OBC1();
};
extern OBC1 *obc1;

25
src/chip/obc1/obc1.hpp Normal file
View File

@@ -0,0 +1,25 @@
class OBC1 : public Memory {
public:
void init();
void enable();
void power();
void reset();
uint8 read(unsigned addr);
void write(unsigned addr, uint8 data);
OBC1();
~OBC1();
private:
uint8 ram_read(unsigned addr);
void ram_write(unsigned addr, uint8 data);
struct {
uint16 address;
uint16 baseptr;
uint16 shift;
} status;
};
extern OBC1 obc1;

View File

@@ -1,14 +1,23 @@
#include "../../base.h"
SDD1 *sdd1;
#include <../base.hpp>
#include <../cart/cart.hpp>
#define SDD1_CPP
#include "sdd1.hpp"
#include "sdd1emu.cpp"
void SDD1::init() {}
void SDD1::enable() {
for(int i = 0x4800; i <= 0x4807; i++) {
r_mem->set_mmio_mapper(i, this);
//hook S-CPU DMA MMIO registers to gather information for struct dma[];
//buffer address and transfer size information for use in SDD1::read()
for(unsigned i = 0x4300; i <= 0x437f; i++) {
cpu_mmio[i & 0x7f] = memory::mmio.get(i);
memory::mmio.map(i, *this);
}
//hook S-DD1 MMIO registers
for(unsigned i = 0x4800; i <= 0x4807; i++) {
memory::mmio.map(i, *this);
}
}
@@ -17,78 +26,133 @@ void SDD1::power() {
}
void SDD1::reset() {
sdd1.index[0] = 0x000000;
sdd1.index[1] = 0x100000;
sdd1.index[2] = 0x200000;
sdd1.index[3] = 0x300000;
sdd1_enable = 0x00;
xfer_enable = 0x00;
for(int i=0;i<8;i++) {
sdd1.active[i] = false;
mmc[0] = 0 << 20;
mmc[1] = 1 << 20;
mmc[2] = 2 << 20;
mmc[3] = 3 << 20;
for(unsigned i = 0; i < 8; i++) {
dma[i].addr = 0;
dma[i].size = 0;
}
sdd1.dma_active = false;
buffer.ready = false;
bus.map(Bus::MapDirect, 0xc0, 0xff, 0x0000, 0xffff, *this);
}
uint32 SDD1::offset(uint32 addr) {
uint8 b = (addr >> 16) & 0xff;
if(b <= 0xbf)return 0;
uint8 SDD1::mmio_read(unsigned addr) {
addr &= 0xffff;
b -= 0xc0; //b = 0x00-0x3f
b >>= 4; //b = 0-3
b &= 3; //bitmask
return sdd1.index[b] + (addr & 0x0fffff);
}
uint8 SDD1::mmio_read(uint16 addr) {
switch(addr) {
//>>20 == 0x100000 == 1mb
case 0x4804:return (sdd1.index[0] >> 20) & 7;
case 0x4805:return (sdd1.index[1] >> 20) & 7;
case 0x4806:return (sdd1.index[2] >> 20) & 7;
case 0x4807:return (sdd1.index[3] >> 20) & 7;
if((addr & 0x4380) == 0x4300) {
return cpu_mmio[addr & 0x7f]->mmio_read(addr);
}
return r_cpu->regs.mdr;
switch(addr) {
case 0x4804: return (mmc[0] >> 20) & 7;
case 0x4805: return (mmc[1] >> 20) & 7;
case 0x4806: return (mmc[2] >> 20) & 7;
case 0x4807: return (mmc[3] >> 20) & 7;
}
return cpu.regs.mdr;
}
void SDD1::mmio_write(uint16 addr, uint8 data) {
switch(addr) {
case 0x4801:
for(int i = 0; i < 8; i++) {
sdd1.active[i] = !!(data & (1 << i));
void SDD1::mmio_write(unsigned addr, uint8 data) {
addr &= 0xffff;
if((addr & 0x4380) == 0x4300) {
unsigned channel = (addr >> 4) & 7;
switch(addr & 15) {
case 2: dma[channel].addr = (dma[channel].addr & 0xffff00) + (data << 0); break;
case 3: dma[channel].addr = (dma[channel].addr & 0xff00ff) + (data << 8); break;
case 4: dma[channel].addr = (dma[channel].addr & 0x00ffff) + (data << 16); break;
case 5: dma[channel].size = (dma[channel].size & 0xff00) + (data << 0); break;
case 6: dma[channel].size = (dma[channel].size & 0x00ff) + (data << 8); break;
}
break;
//<<20 == 0x100000 == 1mb
case 0x4804:sdd1.index[0] = (data & 7) << 20;break;
case 0x4805:sdd1.index[1] = (data & 7) << 20;break;
case 0x4806:sdd1.index[2] = (data & 7) << 20;break;
case 0x4807:sdd1.index[3] = (data & 7) << 20;break;
return cpu_mmio[addr & 0x7f]->mmio_write(addr, data);
}
switch(addr) {
case 0x4800: sdd1_enable = data; break;
case 0x4801: xfer_enable = data; break;
case 0x4804: mmc[0] = (data & 7) << 20; break;
case 0x4805: mmc[1] = (data & 7) << 20; break;
case 0x4806: mmc[2] = (data & 7) << 20; break;
case 0x4807: mmc[3] = (data & 7) << 20; break;
}
}
void SDD1::dma_begin(uint8 channel, uint32 addr, uint16 length) {
if(sdd1.active[channel] == true) {
sdd1.active[channel] = false;
sdd1.dma_active = true;
sdd1.buffer_index = 0;
sdd1.buffer_size = length;
sdd1emu.decompress(addr, (length) ? length : 65536, sdd1.buffer);
}
//SDD1::read() is mapped to $[c0-ff]:[0000-ffff]
//the design is meant to be as close to the hardware design as possible, thus this code
//avoids adding S-DD1 hooks inside S-CPU::DMA emulation.
//
//the real S-DD1 cannot see $420b (DMA enable) writes, as they are not placed on the bus.
//however, $43x0-$43xf writes (DMAx channel settings) most likely do appear on the bus.
//the S-DD1 also requires fixed addresses for transfers, which wouldn't be necessary if
//it could see $420b writes (eg it would know when the transfer should begin.)
//
//the hardware needs a way to distinguish program code after $4801 writes from DMA
//decompression that follows soon after.
//
//the only plausible design for hardware would be for the S-DD1 to spy on DMAx settings,
//and begin spooling decompression on writes to $4801 that activate a channel. after that,
//it feeds decompressed data only when the ROM read address matches the DMA channel address.
//
//the actual S-DD1 transfer can occur on any channel, but it is most likely limited to
//one transfer per $420b write (for spooling purposes). however, this is not known for certain.
uint8 SDD1::read(unsigned addr) {
if(sdd1_enable & xfer_enable) {
//at least one channel has S-DD1 decompression enabled ...
for(unsigned i = 0; i < 8; i++) {
if(sdd1_enable & xfer_enable & (1 << i)) {
//S-DD1 always uses fixed transfer mode, so address will not change during transfer
if(addr == dma[i].addr) {
if(!buffer.ready) {
//first byte read for channel performs full decompression.
//this really should stream byte-by-byte, but it's not necessary since the size is known
buffer.offset = 0;
buffer.size = dma[i].size ? dma[i].size : 65536;
//sdd1emu calls this function; it needs to access uncompressed data;
//so temporarily disable decompression mode for decompress() call.
uint8 temp = sdd1_enable;
sdd1_enable = false;
sdd1emu.decompress(addr, buffer.size, buffer.data);
sdd1_enable = temp;
buffer.ready = true;
}
//fetch a decompressed byte; once buffer is depleted, disable channel and invalidate buffer
uint8 data = buffer.data[(uint16)buffer.offset++];
if(buffer.offset >= buffer.size) {
buffer.ready = false;
xfer_enable &= ~(1 << i);
}
return data;
} //address matched
} //channel enabled
} //channel loop
} //S-DD1 decompressor enabled
//S-DD1 decompression mode inactive; return ROM data
return memory::cartrom.read(mmc[(addr >> 20) & 3] + (addr & 0x0fffff));
}
bool SDD1::dma_active() {
return sdd1.dma_active;
void SDD1::write(unsigned addr, uint8 data) {
}
uint8 SDD1::dma_read() {
if(--sdd1.buffer_size == 0) {
sdd1.dma_active = false;
}
//sdd1.buffer[] is 65536 bytes, and sdd1.buffer_index
//is of type uint16, so no buffer overflow is possible
return sdd1.buffer[sdd1.buffer_index++];
SDD1::SDD1() {
buffer.data = new uint8[65536];
}
SDD1::SDD1() {}
SDD1::~SDD1() {
delete[] buffer.data;
}

View File

@@ -1,32 +0,0 @@
#include "sdd1emu.h"
class SDD1 : public MMIO {
public:
SDD1emu sdd1emu;
struct {
uint32 index[4]; //memory mapping registers
uint8 buffer[65536]; //pointer to decompressed S-DD1 data,
//max. DMA length is 65536
uint16 buffer_index; //DMA read index into S-DD1 decompression buffer
uint16 buffer_size;
bool active[8]; //true when DMA channel should pass through S-DD1
bool dma_active;
} sdd1;
void init();
void enable();
void power();
void reset();
uint32 offset(uint32 addr);
void dma_begin(uint8 channel, uint32 addr, uint16 length);
bool dma_active();
uint8 dma_read();
uint8 mmio_read (uint16 addr);
void mmio_write(uint16 addr, uint8 data);
SDD1();
};
extern SDD1 *sdd1;

40
src/chip/sdd1/sdd1.hpp Normal file
View File

@@ -0,0 +1,40 @@
#include "sdd1emu.hpp"
class SDD1 : public MMIO, public Memory {
public:
void init();
void enable();
void power();
void reset();
uint8 mmio_read(unsigned addr);
void mmio_write(unsigned addr, uint8 data);
uint8 read(unsigned addr);
void write(unsigned addr, uint8 data);
SDD1();
~SDD1();
private:
MMIO *cpu_mmio[0x80]; //bus spying hooks to glean information for struct dma[]
uint8 sdd1_enable; //channel bit-mask
uint8 xfer_enable; //channel bit-mask
unsigned mmc[4]; //memory map controller ROM indices
struct {
unsigned addr; //$43x2-$43x4 -- DMA transfer address
uint16 size; //$43x5-$43x6 -- DMA transfer size
} dma[8];
SDD1emu sdd1emu;
struct {
uint8 *data; //pointer to decompressed S-DD1 data (65536 bytes)
uint16 offset; //read index into S-DD1 decompression buffer
unsigned size; //length of data buffer; reads decrement counter, set ready to false at 0
bool ready; //true when data[] is valid; false to invoke sdd1emu.decompress()
} buffer;
};
extern SDD1 sdd1;

View File

@@ -1,3 +1,5 @@
#ifdef SDD1_CPP
/************************************************************************
S-DD1'algorithm emulation code
@@ -28,7 +30,7 @@ understood.
************************************************************************/
#define SDD1_read(__addr) (r_mem->read(__addr))
#define SDD1_read(__addr) (sdd1.read(__addr))
////////////////////////////////////////////////////
@@ -445,3 +447,5 @@ SDD1emu::SDD1emu() :
}
///////////////////////////////////////////////////////////
#endif

511
src/chip/spc7110/decomp.cpp Normal file
View File

@@ -0,0 +1,511 @@
#ifdef SPC7110_CPP
uint8 SPC7110Decomp::read() {
if(decomp_buffer_length == 0) {
//decompress at least (decomp_buffer_size / 2) bytes to the buffer
switch(decomp_mode) {
case 0: mode0(false); break;
case 1: mode1(false); break;
case 2: mode2(false); break;
default: return 0x00;
}
}
uint8 data = decomp_buffer[decomp_buffer_rdoffset++];
decomp_buffer_rdoffset &= decomp_buffer_size - 1;
decomp_buffer_length--;
return data;
}
void SPC7110Decomp::write(uint8 data) {
decomp_buffer[decomp_buffer_wroffset++] = data;
decomp_buffer_wroffset &= decomp_buffer_size - 1;
decomp_buffer_length++;
}
uint8 SPC7110Decomp::dataread() {
unsigned size = memory::cartrom.size() - 0x100000;
while(decomp_offset >= size) decomp_offset -= size;
return memory::cartrom.read(0x100000 + decomp_offset++);
}
void SPC7110Decomp::init(unsigned mode, unsigned offset, unsigned index) {
decomp_mode = mode;
decomp_offset = offset;
decomp_buffer_rdoffset = 0;
decomp_buffer_wroffset = 0;
decomp_buffer_length = 0;
//reset context states
for(unsigned i = 0; i < 32; i++) {
context[i].index = 0;
context[i].invert = 0;
}
switch(decomp_mode) {
case 0: mode0(true); break;
case 1: mode1(true); break;
case 2: mode2(true); break;
}
//decompress up to requested output data index
while(index--) read();
}
//
void SPC7110Decomp::mode0(bool init) {
static uint8 val, in, span;
static int out, inverts, lps, in_count;
if(init == true) {
out = inverts = lps = 0;
span = 0xff;
val = dataread();
in = dataread();
in_count = 8;
return;
}
while(decomp_buffer_length < (decomp_buffer_size >> 1)) {
for(unsigned bit = 0; bit < 8; bit++) {
//get context
uint8 mask = (1 << (bit & 3)) - 1;
uint8 con = mask + ((inverts & mask) ^ (lps & mask));
if(bit > 3) con += 15;
//get prob and mps
unsigned prob = probability(con);
unsigned mps = (((out >> 15) & 1) ^ context[con].invert);
//get bit
unsigned flag_lps;
if(val <= span - prob) { //mps
span = span - prob;
out = (out << 1) + mps;
flag_lps = 0;
} else { //lps
val = val - (span - (prob - 1));
span = prob - 1;
out = (out << 1) + 1 - mps;
flag_lps = 1;
}
//renormalize
unsigned shift = 0;
while(span < 0x7f) {
shift++;
span = (span << 1) + 1;
val = (val << 1) + (in >> 7);
in <<= 1;
if(--in_count == 0) {
in = dataread();
in_count = 8;
}
}
//update processing info
lps = (lps << 1) + flag_lps;
inverts = (inverts << 1) + context[con].invert;
//update context state
if(flag_lps & toggle_invert(con)) context[con].invert ^= 1;
if(flag_lps) context[con].index = next_lps(con);
else if(shift) context[con].index = next_mps(con);
}
//save byte
write(out);
}
}
void SPC7110Decomp::mode1(bool init) {
static int pixelorder[4], realorder[4];
static uint8 in, val, span;
static int out, inverts, lps, in_count;
if(init == true) {
for(unsigned i = 0; i < 4; i++) pixelorder[i] = i;
out = inverts = lps = 0;
span = 0xff;
val = dataread();
in = dataread();
in_count = 8;
return;
}
while(decomp_buffer_length < (decomp_buffer_size >> 1)) {
for(unsigned pixel = 0; pixel < 8; pixel++) {
//get first symbol context
unsigned a = ((out >> (1 * 2)) & 3);
unsigned b = ((out >> (7 * 2)) & 3);
unsigned c = ((out >> (8 * 2)) & 3);
unsigned con = (a == b) ? (b != c) : (b == c) ? 2 : 4 - (a == c);
//update pixel order
unsigned m, n;
for(m = 0; m < 4; m++) if(pixelorder[m] == a) break;
for(n = m; n > 0; n--) pixelorder[n] = pixelorder[n - 1];
pixelorder[0] = a;
//calculate the real pixel order
for(m = 0; m < 4; m++) realorder[m] = pixelorder[m];
//rotate reference pixel c value to top
for(m = 0; m < 4; m++) if(realorder[m] == c) break;
for(n = m; n > 0; n--) realorder[n] = realorder[n - 1];
realorder[0] = c;
//rotate reference pixel b value to top
for(m = 0; m < 4; m++) if(realorder[m] == b) break;
for(n = m; n > 0; n--) realorder[n] = realorder[n - 1];
realorder[0] = b;
//rotate reference pixel a value to top
for(m = 0; m < 4; m++) if(realorder[m] == a) break;
for(n = m; n > 0; n--) realorder[n] = realorder[n - 1];
realorder[0] = a;
//get 2 symbols
for(unsigned bit = 0; bit < 2; bit++) {
//get prob
unsigned prob = probability(con);
//get symbol
unsigned flag_lps;
if(val <= span - prob) { //mps
span = span - prob;
flag_lps = 0;
} else { //lps
val = val - (span - (prob - 1));
span = prob - 1;
flag_lps = 1;
}
//renormalize
unsigned shift = 0;
while(span < 0x7f) {
shift++;
span = (span << 1) + 1;
val = (val << 1) + (in >> 7);
in <<= 1;
if(--in_count == 0) {
in = dataread();
in_count = 8;
}
}
//update processing info
lps = (lps << 1) + flag_lps;
inverts = (inverts << 1) + context[con].invert;
//update context state
if(flag_lps & toggle_invert(con)) context[con].invert ^= 1;
if(flag_lps) context[con].index = next_lps(con);
else if(shift) context[con].index = next_mps(con);
//get next context
con = 5 + (con << 1) + ((lps ^ inverts) & 1);
}
//get pixel
b = realorder[(lps ^ inverts) & 3];
out = (out << 2) + b;
}
//turn pixel data into bitplanes
unsigned data = morton_2x8(out);
write(data >> 8);
write(data >> 0);
}
}
void SPC7110Decomp::mode2(bool init) {
static int pixelorder[16], realorder[16];
static uint8 bitplanebuffer[16], buffer_index;
static uint8 in, val, span;
static int out0, out1, inverts, lps, in_count;
if(init == true) {
for(unsigned i = 0; i < 16; i++) pixelorder[i] = i;
buffer_index = 0;
out0 = out1 = inverts = lps = 0;
span = 0xff;
val = dataread();
in = dataread();
in_count = 8;
return;
}
while(decomp_buffer_length < (decomp_buffer_size >> 1)) {
for(unsigned pixel = 0; pixel < 8; pixel++) {
//get first symbol context
unsigned a = ((out0 >> (0 * 4)) & 15);
unsigned b = ((out0 >> (7 * 4)) & 15);
unsigned c = ((out1 >> (0 * 4)) & 15);
unsigned con = 0;
unsigned refcon = (a == b) ? (b != c) : (b == c) ? 2 : 4 - (a == c);
//update pixel order
unsigned m, n;
for(m = 0; m < 16; m++) if(pixelorder[m] == a) break;
for(n = m; n > 0; n--) pixelorder[n] = pixelorder[n - 1];
pixelorder[0] = a;
//calculate the real pixel order
for(m = 0; m < 16; m++) realorder[m] = pixelorder[m];
//rotate reference pixel c value to top
for(m = 0; m < 16; m++) if(realorder[m] == c) break;
for(n = m; n > 0; n--) realorder[n] = realorder[n - 1];
realorder[0] = c;
//rotate reference pixel b value to top
for(m = 0; m < 16; m++) if(realorder[m] == b) break;
for(n = m; n > 0; n--) realorder[n] = realorder[n - 1];
realorder[0] = b;
//rotate reference pixel a value to top
for(m = 0; m < 16; m++) if(realorder[m] == a) break;
for(n = m; n > 0; n--) realorder[n] = realorder[n - 1];
realorder[0] = a;
//get 4 symbols
for(unsigned bit = 0; bit < 4; bit++) {
//get prob
unsigned prob = probability(con);
//get symbol
unsigned flag_lps;
if(val <= span - prob) { //mps
span = span - prob;
flag_lps = 0;
} else { //lps
val = val - (span - (prob - 1));
span = prob - 1;
flag_lps = 1;
}
//renormalize
unsigned shift = 0;
while(span < 0x7f) {
shift++;
span = (span << 1) + 1;
val = (val << 1) + (in >> 7);
in <<= 1;
if(--in_count == 0) {
in = dataread();
in_count = 8;
}
}
//update processing info
lps = (lps << 1) + flag_lps;
unsigned invertbit = context[con].invert;
inverts = (inverts << 1) + invertbit;
//update context state
if(flag_lps & toggle_invert(con)) context[con].invert ^= 1;
if(flag_lps) context[con].index = next_lps(con);
else if(shift) context[con].index = next_mps(con);
//get next context
con = mode2_context_table[con][flag_lps ^ invertbit] + (con == 1 ? refcon : 0);
}
//get pixel
b = realorder[(lps ^ inverts) & 0x0f];
out1 = (out1 << 4) + ((out0 >> 28) & 0x0f);
out0 = (out0 << 4) + b;
}
//convert pixel data into bitplanes
unsigned data = morton_4x8(out0);
write(data >> 24);
write(data >> 16);
bitplanebuffer[buffer_index++] = data >> 8;
bitplanebuffer[buffer_index++] = data >> 0;
if(buffer_index == 16) {
for(unsigned i = 0; i < 16; i++) write(bitplanebuffer[i]);
buffer_index = 0;
}
}
}
//
const uint8 SPC7110Decomp::evolution_table[53][4] = {
//{ prob, nextlps, nextmps, toggle invert },
{ 0x5a, 1, 1, 1 },
{ 0x25, 6, 2, 0 },
{ 0x11, 8, 3, 0 },
{ 0x08, 10, 4, 0 },
{ 0x03, 12, 5, 0 },
{ 0x01, 15, 5, 0 },
{ 0x5a, 7, 7, 1 },
{ 0x3f, 19, 8, 0 },
{ 0x2c, 21, 9, 0 },
{ 0x20, 22, 10, 0 },
{ 0x17, 23, 11, 0 },
{ 0x11, 25, 12, 0 },
{ 0x0c, 26, 13, 0 },
{ 0x09, 28, 14, 0 },
{ 0x07, 29, 15, 0 },
{ 0x05, 31, 16, 0 },
{ 0x04, 32, 17, 0 },
{ 0x03, 34, 18, 0 },
{ 0x02, 35, 5, 0 },
{ 0x5a, 20, 20, 1 },
{ 0x48, 39, 21, 0 },
{ 0x3a, 40, 22, 0 },
{ 0x2e, 42, 23, 0 },
{ 0x26, 44, 24, 0 },
{ 0x1f, 45, 25, 0 },
{ 0x19, 46, 26, 0 },
{ 0x15, 25, 27, 0 },
{ 0x11, 26, 28, 0 },
{ 0x0e, 26, 29, 0 },
{ 0x0b, 27, 30, 0 },
{ 0x09, 28, 31, 0 },
{ 0x08, 29, 32, 0 },
{ 0x07, 30, 33, 0 },
{ 0x05, 31, 34, 0 },
{ 0x04, 33, 35, 0 },
{ 0x04, 33, 36, 0 },
{ 0x03, 34, 37, 0 },
{ 0x02, 35, 38, 0 },
{ 0x02, 36, 5, 0 },
{ 0x58, 39, 40, 1 },
{ 0x4d, 47, 41, 0 },
{ 0x43, 48, 42, 0 },
{ 0x3b, 49, 43, 0 },
{ 0x34, 50, 44, 0 },
{ 0x2e, 51, 45, 0 },
{ 0x29, 44, 46, 0 },
{ 0x25, 45, 24, 0 },
{ 0x56, 47, 48, 1 },
{ 0x4f, 47, 49, 0 },
{ 0x47, 48, 50, 0 },
{ 0x41, 49, 51, 0 },
{ 0x3c, 50, 52, 0 },
{ 0x37, 51, 43, 0 },
};
const uint8 SPC7110Decomp::mode2_context_table[32][2] = {
//{ next 0, next 1 },
{ 1, 2 },
{ 3, 8 },
{ 13, 14 },
{ 15, 16 },
{ 17, 18 },
{ 19, 20 },
{ 21, 22 },
{ 23, 24 },
{ 25, 26 },
{ 25, 26 },
{ 25, 26 },
{ 25, 26 },
{ 25, 26 },
{ 27, 28 },
{ 29, 30 },
{ 31, 31 },
{ 31, 31 },
{ 31, 31 },
{ 31, 31 },
{ 31, 31 },
{ 31, 31 },
{ 31, 31 },
{ 31, 31 },
{ 31, 31 },
{ 31, 31 },
{ 31, 31 },
{ 31, 31 },
{ 31, 31 },
{ 31, 31 },
{ 31, 31 },
{ 31, 31 },
{ 31, 31 },
};
uint8 SPC7110Decomp::probability (unsigned n) { return evolution_table[context[n].index][0]; }
uint8 SPC7110Decomp::next_lps (unsigned n) { return evolution_table[context[n].index][1]; }
uint8 SPC7110Decomp::next_mps (unsigned n) { return evolution_table[context[n].index][2]; }
bool SPC7110Decomp::toggle_invert(unsigned n) { return evolution_table[context[n].index][3]; }
unsigned SPC7110Decomp::morton_2x8(unsigned data) {
//reverse morton lookup: de-interleave two 8-bit values
//15, 13, 11, 9, 7, 5, 3, 1 -> 15- 8
//14, 12, 10, 8, 6, 4, 2, 0 -> 7- 0
return morton16[0][(data >> 0) & 255] + morton16[1][(data >> 8) & 255];
}
unsigned SPC7110Decomp::morton_4x8(unsigned data) {
//reverse morton lookup: de-interleave four 8-bit values
//31, 27, 23, 19, 15, 11, 7, 3 -> 31-24
//30, 26, 22, 18, 14, 10, 6, 2 -> 23-16
//29, 25, 21, 17, 13, 9, 5, 1 -> 15- 8
//28, 24, 20, 16, 12, 8, 4, 0 -> 7- 0
return morton32[0][(data >> 0) & 255] + morton32[1][(data >> 8) & 255]
+ morton32[2][(data >> 16) & 255] + morton32[3][(data >> 24) & 255];
}
//
void SPC7110Decomp::reset() {
//mode 3 is invalid; this is treated as a special case to always return 0x00
//set to mode 3 so that reading decomp port before starting first decomp will return 0x00
decomp_mode = 3;
decomp_buffer_rdoffset = 0;
decomp_buffer_wroffset = 0;
decomp_buffer_length = 0;
}
SPC7110Decomp::SPC7110Decomp() {
decomp_buffer = new uint8_t[decomp_buffer_size];
reset();
//initialize reverse morton lookup tables
for(unsigned i = 0; i < 256; i++) {
#define map(x, y) (((i >> x) & 1) << y)
//2x8-bit
morton16[1][i] = map(7, 15) + map(6, 7) + map(5, 14) + map(4, 6)
+ map(3, 13) + map(2, 5) + map(1, 12) + map(0, 4);
morton16[0][i] = map(7, 11) + map(6, 3) + map(5, 10) + map(4, 2)
+ map(3, 9) + map(2, 1) + map(1, 8) + map(0, 0);
//4x8-bit
morton32[3][i] = map(7, 31) + map(6, 23) + map(5, 15) + map(4, 7)
+ map(3, 30) + map(2, 22) + map(1, 14) + map(0, 6);
morton32[2][i] = map(7, 29) + map(6, 21) + map(5, 13) + map(4, 5)
+ map(3, 28) + map(2, 20) + map(1, 12) + map(0, 4);
morton32[1][i] = map(7, 27) + map(6, 19) + map(5, 11) + map(4, 3)
+ map(3, 26) + map(2, 18) + map(1, 10) + map(0, 2);
morton32[0][i] = map(7, 25) + map(6, 17) + map(5, 9) + map(4, 1)
+ map(3, 24) + map(2, 16) + map(1, 8) + map(0, 0);
#undef map
}
}
SPC7110Decomp::~SPC7110Decomp() {
delete[] decomp_buffer;
}
#endif

View File

@@ -0,0 +1,45 @@
class SPC7110Decomp {
public:
uint8 read();
void init(unsigned mode, unsigned offset, unsigned index);
void reset();
SPC7110Decomp();
~SPC7110Decomp();
private:
unsigned decomp_mode;
unsigned decomp_offset;
//read() will spool chunks half the size of decomp_buffer_size
enum { decomp_buffer_size = 64 }; //must be >= 64, and must be a power of two
uint8 *decomp_buffer;
unsigned decomp_buffer_rdoffset;
unsigned decomp_buffer_wroffset;
unsigned decomp_buffer_length;
void write(uint8 data);
uint8 dataread();
void mode0(bool init);
void mode1(bool init);
void mode2(bool init);
static const uint8 evolution_table[53][4];
static const uint8 mode2_context_table[32][2];
struct ContextState {
uint8 index;
uint8 invert;
} context[32];
uint8 probability(unsigned n);
uint8 next_lps(unsigned n);
uint8 next_mps(unsigned n);
bool toggle_invert(unsigned n);
unsigned morton16[2][256];
unsigned morton32[4][256];
unsigned morton_2x8(unsigned data);
unsigned morton_4x8(unsigned data);
};

View File

@@ -0,0 +1,672 @@
#include <../base.hpp>
#include <../cart/cart.hpp>
#define SPC7110_CPP
#include "spc7110.hpp"
#include "decomp.cpp"
const unsigned SPC7110::months[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
void SPC7110::init() {}
void SPC7110::enable() {
uint16_t limit = (cartridge.info.spc7110rtc ? 0x4842 : 0x483f);
for(uint16_t i = 0x4800; i <= limit; i++) memory::mmio.map(i, *this);
}
void SPC7110::power() {
reset();
}
void SPC7110::reset() {
r4801 = 0x00;
r4802 = 0x00;
r4803 = 0x00;
r4804 = 0x00;
r4805 = 0x00;
r4806 = 0x00;
r4807 = 0x00;
r4808 = 0x00;
r4809 = 0x00;
r480a = 0x00;
r480b = 0x00;
r480c = 0x00;
decomp.reset();
r4811 = 0x00;
r4812 = 0x00;
r4813 = 0x00;
r4814 = 0x00;
r4815 = 0x00;
r4816 = 0x00;
r4817 = 0x00;
r4818 = 0x00;
r481x = 0x00;
r4814_latch = false;
r4815_latch = false;
r4820 = 0x00;
r4821 = 0x00;
r4822 = 0x00;
r4823 = 0x00;
r4824 = 0x00;
r4825 = 0x00;
r4826 = 0x00;
r4827 = 0x00;
r4828 = 0x00;
r4829 = 0x00;
r482a = 0x00;
r482b = 0x00;
r482c = 0x00;
r482d = 0x00;
r482e = 0x00;
r482f = 0x00;
r4830 = 0x00;
mmio_write(0x4831, 0);
mmio_write(0x4832, 1);
mmio_write(0x4833, 2);
r4834 = 0x00;
r4840 = 0x00;
r4841 = 0x00;
r4842 = 0x00;
if(cartridge.info.spc7110rtc) {
rtc_state = RTCS_Inactive;
rtc_mode = RTCM_Linear;
rtc_index = 0;
}
}
unsigned SPC7110::datarom_addr(unsigned addr) {
unsigned size = memory::cartrom.size() - 0x100000;
while(addr >= size) addr -= size;
return addr + 0x100000;
}
unsigned SPC7110::data_pointer() { return r4811 + (r4812 << 8) + (r4813 << 16); }
unsigned SPC7110::data_adjust() { return r4814 + (r4815 << 8); }
unsigned SPC7110::data_increment() { return r4816 + (r4817 << 8); }
void SPC7110::set_data_pointer(unsigned addr) { r4811 = addr; r4812 = addr >> 8; r4813 = addr >> 16; }
void SPC7110::set_data_adjust(unsigned addr) { r4814 = addr; r4815 = addr >> 8; }
void SPC7110::update_time(int offset) {
time_t rtc_time
= (memory::cartrtc.read(16) << 0)
| (memory::cartrtc.read(17) << 8)
| (memory::cartrtc.read(18) << 16)
| (memory::cartrtc.read(19) << 24);
time_t current_time = time(0);
//sizeof(time_t) is platform-dependent; though memory::cartrtc needs to be platform-agnostic.
//yet platforms with 32-bit signed time_t will overflow every ~68 years. handle this by
//accounting for overflow at the cost of 1-bit precision (to catch underflow). this will allow
//memory::cartrtc timestamp to remain valid for up to ~34 years from the last update, even if
//time_t overflows. calculation should be valid regardless of number representation, time_t size,
//or whether time_t is signed or unsigned.
time_t diff
= (current_time >= rtc_time)
? (current_time - rtc_time)
: (std::numeric_limits<time_t>::max() - rtc_time + current_time + 1); //compensate for overflow
if(diff > std::numeric_limits<time_t>::max() / 2) diff = 0; //compensate for underflow
bool update = true;
if(memory::cartrtc.read(13) & 1) update = false; //do not update if CR0 timer disable flag is set
if(memory::cartrtc.read(15) & 3) update = false; //do not update if CR2 timer disable flags are set
if(diff > 0 && update == true) {
unsigned second = memory::cartrtc.read( 0) + memory::cartrtc.read( 1) * 10;
unsigned minute = memory::cartrtc.read( 2) + memory::cartrtc.read( 3) * 10;
unsigned hour = memory::cartrtc.read( 4) + memory::cartrtc.read( 5) * 10;
unsigned day = memory::cartrtc.read( 6) + memory::cartrtc.read( 7) * 10;
unsigned month = memory::cartrtc.read( 8) + memory::cartrtc.read( 9) * 10;
unsigned year = memory::cartrtc.read(10) + memory::cartrtc.read(11) * 10;
unsigned weekday = memory::cartrtc.read(12);
day--;
month--;
year += (year >= 90) ? 1900 : 2000; //range = 1990-2089
second += diff;
while(second >= 60) {
second -= 60;
minute++;
if(minute < 60) continue;
minute = 0;
hour++;
if(hour < 24) continue;
hour = 0;
day++;
weekday = (weekday + 1) % 7;
unsigned days = months[month % 12];
if(days == 28) {
bool leapyear = false;
if((year % 4) == 0) {
leapyear = true;
if((year % 100) == 0 && (year % 400) != 0) leapyear = false;
}
if(leapyear) days++;
}
if(day < days) continue;
day = 0;
month++;
if(month < 12) continue;
month = 0;
year++;
}
day++;
month++;
year %= 100;
memory::cartrtc.write( 0, second % 10);
memory::cartrtc.write( 1, second / 10);
memory::cartrtc.write( 2, minute % 10);
memory::cartrtc.write( 3, minute / 10);
memory::cartrtc.write( 4, hour % 10);
memory::cartrtc.write( 5, hour / 10);
memory::cartrtc.write( 6, day % 10);
memory::cartrtc.write( 7, day / 10);
memory::cartrtc.write( 8, month % 10);
memory::cartrtc.write( 9, month / 10);
memory::cartrtc.write(10, year % 10);
memory::cartrtc.write(11, (year / 10) % 10);
memory::cartrtc.write(12, weekday % 7);
}
memory::cartrtc.write(16, current_time >> 0);
memory::cartrtc.write(17, current_time >> 8);
memory::cartrtc.write(18, current_time >> 16);
memory::cartrtc.write(19, current_time >> 24);
}
uint8 SPC7110::mmio_read(unsigned addr) {
addr &= 0xffff;
switch(addr) {
//==================
//decompression unit
//==================
case 0x4800: {
uint16 counter = (r4809 + (r480a << 8));
counter--;
r4809 = counter;
r480a = counter >> 8;
return decomp.read();
}
case 0x4801: return r4801;
case 0x4802: return r4802;
case 0x4803: return r4803;
case 0x4804: return r4804;
case 0x4805: return r4805;
case 0x4806: return r4806;
case 0x4807: return r4807;
case 0x4808: return r4808;
case 0x4809: return r4809;
case 0x480a: return r480a;
case 0x480b: return r480b;
case 0x480c: {
uint8 status = r480c;
r480c &= 0x7f;
return status;
}
//==============
//data port unit
//==============
case 0x4810: {
if(r481x != 0x07) return 0x00;
unsigned addr = data_pointer();
unsigned adjust = data_adjust();
if(r4818 & 8) adjust = (int16)adjust; //16-bit sign extend
unsigned adjustaddr = addr;
if(r4818 & 2) {
adjustaddr += adjust;
set_data_adjust(adjust + 1);
}
uint8 data = memory::cartrom.read(datarom_addr(adjustaddr));
if(!(r4818 & 2)) {
unsigned increment = (r4818 & 1) ? data_increment() : 1;
if(r4818 & 4) increment = (int16)increment; //16-bit sign extend
if((r4818 & 16) == 0) {
set_data_pointer(addr + increment);
} else {
set_data_adjust(adjust + increment);
}
}
return data;
}
case 0x4811: return r4811;
case 0x4812: return r4812;
case 0x4813: return r4813;
case 0x4814: return r4814;
case 0x4815: return r4815;
case 0x4816: return r4816;
case 0x4817: return r4817;
case 0x4818: return r4818;
case 0x481a: {
if(r481x != 0x07) return 0x00;
unsigned addr = data_pointer();
unsigned adjust = data_adjust();
if(r4818 & 8) adjust = (int16)adjust; //16-bit sign extend
uint8 data = memory::cartrom.read(datarom_addr(addr + adjust));
if((r4818 & 0x60) == 0x60) {
if((r4818 & 16) == 0) {
set_data_pointer(addr + adjust);
} else {
set_data_adjust(adjust + adjust);
}
}
return data;
}
//=========
//math unit
//=========
case 0x4820: return r4820;
case 0x4821: return r4821;
case 0x4822: return r4822;
case 0x4823: return r4823;
case 0x4824: return r4824;
case 0x4825: return r4825;
case 0x4826: return r4826;
case 0x4827: return r4827;
case 0x4828: return r4828;
case 0x4829: return r4829;
case 0x482a: return r482a;
case 0x482b: return r482b;
case 0x482c: return r482c;
case 0x482d: return r482d;
case 0x482e: return r482e;
case 0x482f: {
uint8 status = r482f;
r482f &= 0x7f;
return status;
}
//===================
//memory mapping unit
//===================
case 0x4830: return r4830;
case 0x4831: return r4831;
case 0x4832: return r4832;
case 0x4833: return r4833;
case 0x4834: return r4834;
//====================
//real-time clock unit
//====================
case 0x4840: return r4840;
case 0x4841: {
if(rtc_state == RTCS_Inactive || rtc_state == RTCS_ModeSelect) return 0x00;
r4842 = 0x80;
uint8 data = memory::cartrtc.read(rtc_index);
rtc_index = (rtc_index + 1) & 15;
return data;
}
case 0x4842: {
uint8 status = r4842;
r4842 &= 0x7f;
return status;
}
}
return cpu.regs.mdr;
}
void SPC7110::mmio_write(unsigned addr, uint8 data) {
addr &= 0xffff;
switch(addr) {
//==================
//decompression unit
//==================
case 0x4801: r4801 = data; break;
case 0x4802: r4802 = data; break;
case 0x4803: r4803 = data; break;
case 0x4804: r4804 = data; break;
case 0x4805: r4805 = data; break;
case 0x4806: {
r4806 = data;
unsigned table = (r4801 + (r4802 << 8) + (r4803 << 16));
unsigned index = (r4804 << 2);
unsigned length = (r4809 + (r480a << 8));
unsigned addr = datarom_addr(table + index);
unsigned mode = (memory::cartrom.read(addr + 0));
unsigned offset = (memory::cartrom.read(addr + 1) << 16)
+ (memory::cartrom.read(addr + 2) << 8)
+ (memory::cartrom.read(addr + 3) << 0);
decomp.init(mode, offset, (r4805 + (r4806 << 8)) << mode);
r480c = 0x80;
} break;
case 0x4807: r4807 = data; break;
case 0x4808: r4808 = data; break;
case 0x4809: r4809 = data; break;
case 0x480a: r480a = data; break;
case 0x480b: r480b = data; break;
//==============
//data port unit
//==============
case 0x4811: r4811 = data; r481x |= 0x01; break;
case 0x4812: r4812 = data; r481x |= 0x02; break;
case 0x4813: r4813 = data; r481x |= 0x04; break;
case 0x4814: {
r4814 = data;
r4814_latch = true;
if(!r4815_latch) break;
if(!(r4818 & 2)) break;
if(r4818 & 0x10) break;
if((r4818 & 0x60) == 0x20) {
unsigned increment = data_adjust() & 0xff;
if(r4818 & 8) increment = (int8)increment; //8-bit sign extend
set_data_pointer(data_pointer() + increment);
} else if((r4818 & 0x60) == 0x40) {
unsigned increment = data_adjust();
if(r4818 & 8) increment = (int16)increment; //16-bit sign extend
set_data_pointer(data_pointer() + increment);
}
} break;
case 0x4815: {
r4815 = data;
r4815_latch = true;
if(!r4814_latch) break;
if(!(r4818 & 2)) break;
if(r4818 & 0x10) break;
if((r4818 & 0x60) == 0x20) {
unsigned increment = data_adjust() & 0xff;
if(r4818 & 8) increment = (int8)increment; //8-bit sign extend
set_data_pointer(data_pointer() + increment);
} else if((r4818 & 0x60) == 0x40) {
unsigned increment = data_adjust();
if(r4818 & 8) increment = (int16)increment; //16-bit sign extend
set_data_pointer(data_pointer() + increment);
}
} break;
case 0x4816: r4816 = data; break;
case 0x4817: r4817 = data; break;
case 0x4818: {
if(r481x != 0x07) break;
r4818 = data;
r4814_latch = r4815_latch = false;
} break;
//=========
//math unit
//=========
case 0x4820: r4820 = data; break;
case 0x4821: r4821 = data; break;
case 0x4822: r4822 = data; break;
case 0x4823: r4823 = data; break;
case 0x4824: r4824 = data; break;
case 0x4825: {
r4825 = data;
if(r482e & 1) {
//signed 16-bit x 16-bit multiplication
int16 r0 = (int16)(r4824 + (r4825 << 8));
int16 r1 = (int16)(r4820 + (r4821 << 8));
signed result = r0 * r1;
r4828 = result;
r4829 = result >> 8;
r482a = result >> 16;
r482b = result >> 24;
} else {
//unsigned 16-bit x 16-bit multiplication
uint16 r0 = (uint16)(r4824 + (r4825 << 8));
uint16 r1 = (uint16)(r4820 + (r4821 << 8));
unsigned result = r0 * r1;
r4828 = result;
r4829 = result >> 8;
r482a = result >> 16;
r482b = result >> 24;
}
r482f = 0x80;
} break;
case 0x4826: r4826 = data; break;
case 0x4827: {
r4827 = data;
if(r482e & 1) {
//signed 32-bit x 16-bit division
int32 dividend = (int32)(r4820 + (r4821 << 8) + (r4822 << 16) + (r4823 << 24));
int16 divisor = (int16)(r4826 + (r4827 << 8));
int32 quotient;
int16 remainder;
if(divisor) {
quotient = (int32)(dividend / divisor);
remainder = (int32)(dividend % divisor);
} else {
//illegal division by zero
quotient = 0;
remainder = dividend & 0xffff;
}
r4828 = quotient;
r4829 = quotient >> 8;
r482a = quotient >> 16;
r482b = quotient >> 24;
r482c = remainder;
r482d = remainder >> 8;
} else {
//unsigned 32-bit x 16-bit division
uint32 dividend = (uint32)(r4820 + (r4821 << 8) + (r4822 << 16) + (r4823 << 24));
uint16 divisor = (uint16)(r4826 + (r4827 << 8));
uint32 quotient;
uint16 remainder;
if(divisor) {
quotient = (uint32)(dividend / divisor);
remainder = (uint16)(dividend % divisor);
} else {
//illegal division by zero
quotient = 0;
remainder = dividend & 0xffff;
}
r4828 = quotient;
r4829 = quotient >> 8;
r482a = quotient >> 16;
r482b = quotient >> 24;
r482c = remainder;
r482d = remainder >> 8;
}
r482f = 0x80;
} break;
case 0x482e: {
//reset math unit
r4820 = r4821 = r4822 = r4823 = 0;
r4824 = r4825 = r4826 = r4827 = 0;
r4828 = r4829 = r482a = r482b = 0;
r482c = r482d = 0;
r482e = data;
} break;
//===================
//memory mapping unit
//===================
case 0x4830: r4830 = data; break;
case 0x4831: {
r4831 = data;
dx_offset = datarom_addr((data & 7) * 0x100000);
} break;
case 0x4832: {
r4832 = data;
ex_offset = datarom_addr((data & 7) * 0x100000);
} break;
case 0x4833: {
r4833 = data;
fx_offset = datarom_addr((data & 7) * 0x100000);
} break;
case 0x4834: r4834 = data; break;
//====================
//real-time clock unit
//====================
case 0x4840: {
r4840 = data;
if(!(r4840 & 1)) {
//disable RTC
rtc_state = RTCS_Inactive;
update_time();
} else {
//enable RTC
r4842 = 0x80;
rtc_state = RTCS_ModeSelect;
}
} break;
case 0x4841: {
r4841 = data;
switch(rtc_state) {
case RTCS_ModeSelect: {
if(data == RTCM_Linear || data == RTCM_Indexed) {
r4842 = 0x80;
rtc_state = RTCS_IndexSelect;
rtc_mode = (RTC_Mode)data;
rtc_index = 0;
}
} break;
case RTCS_IndexSelect: {
r4842 = 0x80;
rtc_index = data & 15;
if(rtc_mode == RTCM_Linear) rtc_state = RTCS_Write;
} break;
case RTCS_Write: {
r4842 = 0x80;
//control register 0
if(rtc_index == 13) {
//increment second counter
if(data & 2) update_time(+1);
//round minute counter
if(data & 8) {
update_time();
unsigned second = memory::cartrtc.read( 0) + memory::cartrtc.read( 1) * 10;
//clear seconds
memory::cartrtc.write(0, 0);
memory::cartrtc.write(1, 0);
if(second >= 30) update_time(+60);
}
}
//control register 2
if(rtc_index == 15) {
//disable timer and clear second counter
if((data & 1) && !(memory::cartrtc.read(15) & 1)) {
update_time();
//clear seconds
memory::cartrtc.write(0, 0);
memory::cartrtc.write(1, 0);
}
//disable timer
if((data & 2) && !(memory::cartrtc.read(15) & 2)) {
update_time();
}
}
memory::cartrtc.write(rtc_index, data & 15);
rtc_index = (rtc_index + 1) & 15;
} break;
} //switch(rtc_state)
} break;
}
}
uint8 SPC7110::read(unsigned addr) {
//$[00-0f|80-8f]:[8000-ffff], $[c0-cf]:[0000-ffff] mapped directly to memory::cartrom
if((addr & 0xffe000) == 0x006000 || (addr & 0xffe000) == 0x306000) {
//$[00|30]:[6000-7fff]
return memory::cartram.read(addr & 0x1fff);
}
if((addr & 0xff0000) == 0x500000) {
//$[50]:[0000-ffff]
return mmio_read(0x4800);
}
if((addr & 0xf00000) == 0xd00000) {
//$[d0-df]:[0000-ffff]
return memory::cartrom.read(dx_offset + (addr & 0x0fffff));
}
if((addr & 0xf00000) == 0xe00000) {
//$[e0-ef]:[0000-ffff]
return memory::cartrom.read(ex_offset + (addr & 0x0fffff));
}
if((addr & 0xf00000) == 0xf00000) {
//$[f0-ff]:[0000-ffff]
return memory::cartrom.read(fx_offset + (addr & 0x0fffff));
}
return cpu.regs.mdr;
}
void SPC7110::write(unsigned addr, uint8 data) {
if((addr & 0xffe000) == 0x006000 || (addr & 0xffe000) == 0x306000) {
//$[00|30]:[6000-7fff]
if(r4830 & 0x80) memory::cartram.write(addr & 0x1fff, data);
return;
}
}
SPC7110::SPC7110() {
}

View File

@@ -0,0 +1,133 @@
/*****
* SPC7110 emulator - version 0.03 (2008-08-10)
* Copyright (c) 2008, byuu and neviksti
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* The software is provided "as is" and the author disclaims all warranties
* with regard to this software including all implied warranties of
* merchantibility and fitness, in no event shall the author be liable for
* any special, direct, indirect, or consequential damages or any damages
* whatsoever resulting from loss of use, data or profits, whether in an
* action of contract, negligence or other tortious action, arising out of
* or in connection with the use or performance of this software.
*****/
#include "decomp.hpp"
class SPC7110 : public MMIO, public Memory {
public:
void init();
void enable();
void power();
void reset();
unsigned datarom_addr(unsigned addr);
unsigned data_pointer();
unsigned data_adjust();
unsigned data_increment();
void set_data_pointer(unsigned addr);
void set_data_adjust(unsigned addr);
void update_time(int offset = 0);
time_t create_time();
uint8 mmio_read (unsigned addr);
void mmio_write(unsigned addr, uint8 data);
uint8 read (unsigned addr);
void write(unsigned addr, uint8 data);
//spc7110decomp
void decomp_init();
uint8 decomp_read();
SPC7110();
private:
//==================
//decompression unit
//==================
uint8 r4801; //compression table low
uint8 r4802; //compression table high
uint8 r4803; //compression table bank
uint8 r4804; //compression table index
uint8 r4805; //decompression buffer index low
uint8 r4806; //decompression buffer index high
uint8 r4807; //???
uint8 r4808; //???
uint8 r4809; //compression length low
uint8 r480a; //compression length high
uint8 r480b; //decompression control register
uint8 r480c; //decompression status
SPC7110Decomp decomp;
//==============
//data port unit
//==============
uint8 r4811; //data pointer low
uint8 r4812; //data pointer high
uint8 r4813; //data pointer bank
uint8 r4814; //data adjust low
uint8 r4815; //data adjust high
uint8 r4816; //data increment low
uint8 r4817; //data increment high
uint8 r4818; //data port control register
uint8 r481x;
bool r4814_latch;
bool r4815_latch;
//=========
//math unit
//=========
uint8 r4820; //16-bit multiplicand B0, 32-bit dividend B0
uint8 r4821; //16-bit multiplicand B1, 32-bit dividend B1
uint8 r4822; //32-bit dividend B2
uint8 r4823; //32-bit dividend B3
uint8 r4824; //16-bit multiplier B0
uint8 r4825; //16-bit multiplier B1
uint8 r4826; //16-bit divisor B0
uint8 r4827; //16-bit divisor B1
uint8 r4828; //32-bit product B0, 32-bit quotient B0
uint8 r4829; //32-bit product B1, 32-bit quotient B1
uint8 r482a; //32-bit product B2, 32-bit quotient B2
uint8 r482b; //32-bit product B3, 32-bit quotient B3
uint8 r482c; //16-bit remainder B0
uint8 r482d; //16-bit remainder B1
uint8 r482e; //math control register
uint8 r482f; //math status
//===================
//memory mapping unit
//===================
uint8 r4830; //SRAM write enable
uint8 r4831; //$[d0-df]:[0000-ffff] mapping
uint8 r4832; //$[e0-ef]:[0000-ffff] mapping
uint8 r4833; //$[f0-ff]:[0000-ffff] mapping
uint8 r4834; //???
unsigned dx_offset;
unsigned ex_offset;
unsigned fx_offset;
//====================
//real-time clock unit
//====================
uint8 r4840; //RTC latch
uint8 r4841; //RTC index/data port
uint8 r4842; //RTC status
enum RTC_State { RTCS_Inactive, RTCS_ModeSelect, RTCS_IndexSelect, RTCS_Write } rtc_state;
enum RTC_Mode { RTCM_Linear = 0x03, RTCM_Indexed = 0x0c } rtc_mode;
unsigned rtc_index;
static const unsigned months[12];
};
extern SPC7110 spc7110;

View File

@@ -1,191 +1,226 @@
/*
S-RTC chip emulation
Used by Hudson Soft in Dai Kaijuu Monogatari II and Far East of Eden Zero.
Currently, only the former is supported by bsnes.
Original S-RTC emulation code via John Weidman/SNES9x
Rewritten for compatibility with bsnes via byuu
The S-RTC is a real-time clock chip that was added to the above two carts
to allow the games to maintain the current time, even when the game was not
powered on. Thus allowing special events at certain times, and on certain
dates. Hudson Soft called this the PLG (Player's Life Gameplay System).
This chip is a special case to the term 'emulation' itself.
There are a few different ways to go about emulating this chip, and each
result in a different style of emulation.
The first is to simply return the current PC system time when the S-RTC is
read from. This emulates the original S-RTC in the sense that it always
returns the true current time, ignoring the speed that the SNES itself is
running at. The downside to this method is that you lose the ability to set
the time to whatever you choose inside the game itself. It will always return
the true time, regardless. This can be overcome by changing the PC system time,
which actually adds a greater degree of control over event timing, very useful
for emulation. It also has a timeshifting flaw discussed below.
The second is to run the S-RTC relative to the SNES speed. This means that
if the emulator is sped up (via fast forward key, frameskipping, etc), or
slowed down (via slowdown key, system bottlenecking, etc); the time increments
slower, thus ~60 frames on the SNES equal one second. Without this, timeshifting
will occur between the S-RTC and the real SNES.
The third and final method is to save a copy of the local system time when the
S-RTC is initially set, and compare the current system time against this value
when setting the S-RTC time. This overcomes the first methods' shortcoming of
not allowing the player to set the time in-game, however a new problem arises.
You now have to save the time when the RTC was initially set to both savestates
and to save-game data. This would require an extra file, or the breaking of
perhaps the only standard format (.srm savegame backups) in the entire SNES
emulation scene. You also give up the control of being able to override the
RTC clock at will via the PC system time outside of emulation.
The first method has another advantage over the third: Dai Kaijuu Monogatari II
only allows dates in the range of the years 1996-2199. The first method gets
around this limitation. But who knows, maybe it will break something in the
game if the date exceeds 2199... I guess we'll worry about that in two hundred
years from now.
For my implementation, I chose to go with the first method. Both for simplicity
and because I did not wish to create a new method for saving the system time
whenever the RTC is set.
*/
#include "../../base.h"
SRTC *srtc;
void SRTC::set_time() {
time_t rawtime;
tm *t;
::time(&rawtime);
t = localtime(&rawtime);
//see srtc.h for format of srtc.data[]
srtc.data[0] = t->tm_sec % 10;
srtc.data[1] = t->tm_sec / 10;
srtc.data[2] = t->tm_min % 10;
srtc.data[3] = t->tm_min / 10;
srtc.data[4] = t->tm_hour % 10;
srtc.data[5] = t->tm_hour / 10;
srtc.data[6] = t->tm_mday % 10;
srtc.data[7] = t->tm_mday / 10;
srtc.data[8] = t->tm_mon + 1;
srtc.data[9] = t->tm_year % 10;
srtc.data[10] = (t->tm_year / 10) % 10;
srtc.data[11] = 9 + (t->tm_year / 100);
srtc.data[12] = t->tm_wday;
}
void SRTC::init() {}
void SRTC::enable() {
r_mem->set_mmio_mapper(0x2800, this);
r_mem->set_mmio_mapper(0x2801, this);
}
void SRTC::power() {
memset(&srtc, 0, sizeof(srtc));
reset();
}
void SRTC::reset() {
srtc.index = -1;
srtc.mode = SRTC_READ;
}
uint8 SRTC::mmio_read(uint16 addr) {
switch(addr) {
case 0x2800: {
if(srtc.mode == SRTC_READ) {
if(srtc.index < 0) {
set_time();
srtc.index++;
return 0x0f; //send start message
} else if(srtc.index > MAX_SRTC_INDEX) {
srtc.index = -1;
return 0x0f; //send finished message
} else {
return srtc.data[srtc.index++];
}
} else {
return 0x00;
}
} break;
case 0x2801: {
} break;
}
return r_cpu->regs.mdr;
}
//Please see notes above about the implementation of the S-RTC
//Writes are stored the srtc.data[] array, but they are ignored
//as reads will refresh the data array with the current system
//time. The write method is only here for the sake of faux
//emulation of the real hardware.
void SRTC::mmio_write(uint16 addr, uint8 data) {
switch(addr) {
case 0x2800: {
} break;
case 0x2801: {
data &= 0x0f; //only the low four bits are used
if(data >= 0x0d) {
switch(data) {
case 0x0d:
srtc.mode = SRTC_READ;
srtc.index = -1;
break;
case 0x0e:
srtc.mode = SRTC_COMMAND;
break;
case 0x0f:
//unknown behaviour
break;
}
return;
}
if(srtc.mode == SRTC_WRITE) {
if(srtc.index >= 0 && srtc.index < MAX_SRTC_INDEX) {
srtc.data[srtc.index++] = data;
if(srtc.index == MAX_SRTC_INDEX) {
//all S-RTC data has been loaded by program
srtc.data[srtc.index++] = 0x00; //day_of_week
}
}
} else if(srtc.mode == SRTC_COMMAND) {
switch(data) {
case SRTC_COMMAND_CLEAR:
memset(srtc.data, 0, MAX_SRTC_INDEX + 1);
srtc.index = -1;
srtc.mode = SRTC_READY;
break;
case SRTC_COMMAND_WRITE:
srtc.index = 0;
srtc.mode = SRTC_WRITE;
break;
default:
//unknown behaviour
srtc.mode = SRTC_READY;
break;
}
} else {
if(srtc.mode == SRTC_READ) {
//ignore writes while in read mode
} else if(srtc.mode == SRTC_READY) {
//unknown behaviour
}
}
} break;
}
}
SRTC::SRTC() {}
#include <../base.hpp>
#include <../cart/cart.hpp>
#include "srtc.hpp"
const unsigned SRTC::months[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
void SRTC::init() {
}
void SRTC::enable() {
memory::mmio.map(0x2800, *this);
memory::mmio.map(0x2801, *this);
}
void SRTC::power() {
reset();
}
void SRTC::reset() {
rtc_mode = RTCM_Read;
rtc_index = -1;
update_time();
}
void SRTC::update_time() {
time_t rtc_time
= (memory::cartrtc.read(16) << 0)
| (memory::cartrtc.read(17) << 8)
| (memory::cartrtc.read(18) << 16)
| (memory::cartrtc.read(19) << 24);
time_t current_time = time(0);
//sizeof(time_t) is platform-dependent; though memory::cartrtc needs to be platform-agnostic.
//yet platforms with 32-bit signed time_t will overflow every ~68 years. handle this by
//accounting for overflow at the cost of 1-bit precision (to catch underflow). this will allow
//memory::cartrtc timestamp to remain valid for up to ~34 years from the last update, even if
//time_t overflows. calculation should be valid regardless of number representation, time_t size,
//or whether time_t is signed or unsigned.
time_t diff
= (current_time >= rtc_time)
? (current_time - rtc_time)
: (std::numeric_limits<time_t>::max() - rtc_time + current_time + 1); //compensate for overflow
if(diff > std::numeric_limits<time_t>::max() / 2) diff = 0; //compensate for underflow
if(diff > 0) {
unsigned second = memory::cartrtc.read( 0) + memory::cartrtc.read( 1) * 10;
unsigned minute = memory::cartrtc.read( 2) + memory::cartrtc.read( 3) * 10;
unsigned hour = memory::cartrtc.read( 4) + memory::cartrtc.read( 5) * 10;
unsigned day = memory::cartrtc.read( 6) + memory::cartrtc.read( 7) * 10;
unsigned month = memory::cartrtc.read( 8);
unsigned year = memory::cartrtc.read( 9) + memory::cartrtc.read(10) * 10 + memory::cartrtc.read(11) * 100;
unsigned weekday = memory::cartrtc.read(12);
day--;
month--;
year += 1000;
second += diff;
while(second >= 60) {
second -= 60;
minute++;
if(minute < 60) continue;
minute = 0;
hour++;
if(hour < 24) continue;
hour = 0;
day++;
weekday = (weekday + 1) % 7;
unsigned days = months[month % 12];
if(days == 28) {
bool leapyear = false;
if((year % 4) == 0) {
leapyear = true;
if((year % 100) == 0 && (year % 400) != 0) leapyear = false;
}
if(leapyear) days++;
}
if(day < days) continue;
day = 0;
month++;
if(month < 12) continue;
month = 0;
year++;
}
day++;
month++;
year -= 1000;
memory::cartrtc.write( 0, second % 10);
memory::cartrtc.write( 1, second / 10);
memory::cartrtc.write( 2, minute % 10);
memory::cartrtc.write( 3, minute / 10);
memory::cartrtc.write( 4, hour % 10);
memory::cartrtc.write( 5, hour / 10);
memory::cartrtc.write( 6, day % 10);
memory::cartrtc.write( 7, day / 10);
memory::cartrtc.write( 8, month);
memory::cartrtc.write( 9, year % 10);
memory::cartrtc.write(10, (year / 10) % 10);
memory::cartrtc.write(11, year / 100);
memory::cartrtc.write(12, weekday % 7);
}
memory::cartrtc.write(16, current_time >> 0);
memory::cartrtc.write(17, current_time >> 8);
memory::cartrtc.write(18, current_time >> 16);
memory::cartrtc.write(19, current_time >> 24);
}
//returns day of week for specified date
//eg 0 = Sunday, 1 = Monday, ... 6 = Saturday
//usage: weekday(2008, 1, 1) returns weekday of January 1st, 2008
unsigned SRTC::weekday(unsigned year, unsigned month, unsigned day) {
unsigned y = 1900, m = 1; //epoch is 1900-01-01
unsigned sum = 0; //number of days passed since epoch
year = max(1900, year);
month = max(1, min(12, month));
day = max(1, min(31, day));
while(y < year) {
bool leapyear = false;
if((y % 4) == 0) {
leapyear = true;
if((y % 100) == 0 && (y % 400) != 0) leapyear = false;
}
sum += leapyear ? 366 : 365;
y++;
}
while(m < month) {
unsigned days = months[m - 1];
if(days == 28) {
bool leapyear = false;
if((y % 4) == 0) {
leapyear = true;
if((y % 100) == 0 && (y % 400) != 0) leapyear = false;
}
if(leapyear) days++;
}
sum += days;
m++;
}
sum += day - 1;
return (sum + 1) % 7; //1900-01-01 was a Monday
}
uint8 SRTC::mmio_read(unsigned addr) {
addr &= 0xffff;
if(addr == 0x2800) {
if(rtc_mode != RTCM_Read) return 0x00;
if(rtc_index < 0) {
update_time();
rtc_index++;
return 0x0f;
} else if(rtc_index > 12) {
rtc_index = -1;
return 0x0f;
} else {
return memory::cartrtc.read(rtc_index++);
}
}
return cpu.regs.mdr;
}
void SRTC::mmio_write(unsigned addr, uint8 data) {
addr &= 0xffff;
if(addr == 0x2801) {
data &= 0x0f; //only the low four bits are used
if(data == 0x0d) {
rtc_mode = RTCM_Read;
rtc_index = -1;
return;
}
if(data == 0x0e) {
rtc_mode = RTCM_Command;
return;
}
if(data == 0x0f) return; //unknown behavior
if(rtc_mode == RTCM_Write) {
if(rtc_index >= 0 && rtc_index < 12) {
memory::cartrtc.write(rtc_index++, data);
if(rtc_index == 12) {
//day of week is automatically calculated and written
unsigned day = memory::cartrtc.read( 6) + memory::cartrtc.read( 7) * 10;
unsigned month = memory::cartrtc.read( 8);
unsigned year = memory::cartrtc.read( 9) + memory::cartrtc.read(10) * 10 + memory::cartrtc.read(11) * 100;
year += 1000;
memory::cartrtc.write(rtc_index++, weekday(year, month, day));
}
}
} else if(rtc_mode == RTCM_Command) {
if(data == 0) {
rtc_mode = RTCM_Write;
rtc_index = 0;
} else if(data == 4) {
rtc_mode = RTCM_Ready;
rtc_index = -1;
for(unsigned i = 0; i < 13; i++) memory::cartrtc.write(i, 0);
} else {
//unknown behavior
rtc_mode = RTCM_Ready;
}
}
}
}
SRTC::SRTC() {
}

View File

@@ -1,52 +0,0 @@
class SRTC : public MMIO {
public:
enum { MAX_SRTC_INDEX = 0x0c };
enum {
SRTC_READ = 0,
SRTC_WRITE,
SRTC_COMMAND,
SRTC_READY
};
enum {
SRTC_COMMAND_WRITE = 0,
SRTC_COMMAND_CLEAR = 4
};
/******************************
[srtc.data structure]
Index Description Range
----- ----------- -----
0 Seconds low 0-9
1 Seconds high 0-5
2 Minutes low 0-9
3 Minutes high 0-5
4 Hour low 0-9
5 Hour high 0-2
6 Day low 0-9
7 Day high 0-3
8 Month 1-12
9 Year ones 0-9
10 Year tens 0-9
11 Year hundreds 9-11 (9=19xx, 10=20xx, 11=21xx)
12 Day of week 0-6 (0=Sunday, ...)
******************************/
struct {
int8 index;
uint8 mode;
uint8 data[MAX_SRTC_INDEX + 1];
} srtc;
void set_time();
void init();
void enable();
void power();
void reset();
uint8 mmio_read (uint16 addr);
void mmio_write(uint16 addr, uint8 data);
SRTC();
};
extern SRTC *srtc;

22
src/chip/srtc/srtc.hpp Normal file
View File

@@ -0,0 +1,22 @@
class SRTC : public MMIO {
public:
void update_time();
unsigned weekday(unsigned year, unsigned month, unsigned day);
void init();
void enable();
void power();
void reset();
uint8 mmio_read (unsigned addr);
void mmio_write(unsigned addr, uint8 data);
SRTC();
private:
static const unsigned months[12];
enum RTC_Mode { RTCM_Ready, RTCM_Command, RTCM_Read, RTCM_Write } rtc_mode;
signed rtc_index;
};
extern SRTC srtc;

87
src/chip/st010/st010.cpp Normal file
View File

@@ -0,0 +1,87 @@
#include <../base.hpp>
#define ST010_CPP
#include "st010.hpp"
#include "st010_data.hpp"
#include "st010_op.cpp"
int16 ST010::sin(int16 theta) {
return sin_table[(theta >> 8) & 0xff];
}
int16 ST010::cos(int16 theta) {
return sin_table[((theta + 0x4000) >> 8) & 0xff];
}
uint8 ST010::readb(uint16 addr) {
return ram[addr & 0xfff];
}
uint16 ST010::readw(uint16 addr) {
return (readb(addr + 0) << 0) |
(readb(addr + 1) << 8);
}
uint32 ST010::readd(uint16 addr) {
return (readb(addr + 0) << 0) |
(readb(addr + 1) << 8) |
(readb(addr + 2) << 16) |
(readb(addr + 3) << 24);
}
void ST010::writeb(uint16 addr, uint8 data) {
ram[addr & 0xfff] = data;
}
void ST010::writew(uint16 addr, uint16 data) {
writeb(addr + 0, data);
writeb(addr + 1, data >> 8);
}
void ST010::writed(uint16 addr, uint32 data) {
writeb(addr + 0, data);
writeb(addr + 1, data >> 8);
writeb(addr + 2, data >> 16);
writeb(addr + 3, data >> 24);
}
//
void ST010::init() {
}
void ST010::enable() {
}
void ST010::power() {
reset();
}
void ST010::reset() {
memset(ram, 0x00, sizeof ram);
}
//
uint8 ST010::read(unsigned addr) {
return readb(addr);
}
void ST010::write(unsigned addr, uint8 data) {
writeb(addr, data);
if((addr & 0xfff) == 0x0021 && (data & 0x80)) {
switch(ram[0x0020]) {
case 0x01: op_01(); break;
case 0x02: op_02(); break;
case 0x03: op_03(); break;
case 0x04: op_04(); break;
case 0x05: op_05(); break;
case 0x06: op_06(); break;
case 0x07: op_07(); break;
case 0x08: op_08(); break;
}
ram[0x0021] &= ~0x80;
}
}

42
src/chip/st010/st010.hpp Normal file
View File

@@ -0,0 +1,42 @@
class ST010 : public Memory {
public:
void init();
void enable();
void power();
void reset();
uint8 read (unsigned addr);
void write(unsigned addr, uint8 data);
private:
uint8 ram[0x1000];
static const int16 sin_table[256];
static const int16 mode7_scale[176];
static const uint8 arctan[32][32];
//interfaces to sin table
int16 sin(int16 theta);
int16 cos(int16 theta);
//interfaces to ram buffer
uint8 readb (uint16 addr);
uint16 readw (uint16 addr);
uint32 readd (uint16 addr);
void writeb(uint16 addr, uint8 data);
void writew(uint16 addr, uint16 data);
void writed(uint16 addr, uint32 data);
//opcodes
void op_01();
void op_02();
void op_03();
void op_04();
void op_05();
void op_06();
void op_07();
void op_08();
void op_01(int16 x0, int16 y0, int16 &x1, int16 &y1, int16 &quadrant, int16 &theta);
};
extern ST010 st010;

View File

@@ -0,0 +1,126 @@
const int16 ST010::sin_table[256] = {
0x0000, 0x0324, 0x0648, 0x096a, 0x0c8c, 0x0fab, 0x12c8, 0x15e2,
0x18f9, 0x1c0b, 0x1f1a, 0x2223, 0x2528, 0x2826, 0x2b1f, 0x2e11,
0x30fb, 0x33df, 0x36ba, 0x398c, 0x3c56, 0x3f17, 0x41ce, 0x447a,
0x471c, 0x49b4, 0x4c3f, 0x4ebf, 0x5133, 0x539b, 0x55f5, 0x5842,
0x5a82, 0x5cb3, 0x5ed7, 0x60eb, 0x62f1, 0x64e8, 0x66cf, 0x68a6,
0x6a6d, 0x6c23, 0x6dc9, 0x6f5e, 0x70e2, 0x7254, 0x73b5, 0x7504,
0x7641, 0x776b, 0x7884, 0x7989, 0x7a7c, 0x7b5c, 0x7c29, 0x7ce3,
0x7d89, 0x7e1d, 0x7e9c, 0x7f09, 0x7f61, 0x7fa6, 0x7fd8, 0x7ff5,
0x7fff, 0x7ff5, 0x7fd8, 0x7fa6, 0x7f61, 0x7f09, 0x7e9c, 0x7e1d,
0x7d89, 0x7ce3, 0x7c29, 0x7b5c, 0x7a7c, 0x7989, 0x7884, 0x776b,
0x7641, 0x7504, 0x73b5, 0x7254, 0x70e2, 0x6f5e, 0x6dc9, 0x6c23,
0x6a6d, 0x68a6, 0x66cf, 0x64e8, 0x62f1, 0x60eb, 0x5ed7, 0x5cb3,
0x5a82, 0x5842, 0x55f5, 0x539b, 0x5133, 0x4ebf, 0x4c3f, 0x49b4,
0x471c, 0x447a, 0x41ce, 0x3f17, 0x3c56, 0x398c, 0x36ba, 0x33df,
0x30fb, 0x2e11, 0x2b1f, 0x2826, 0x2528, 0x2223, 0x1f1a, 0x1c0b,
0x18f8, 0x15e2, 0x12c8, 0x0fab, 0x0c8c, 0x096a, 0x0648, 0x0324,
0x0000, -0x0324, -0x0648, -0x096b, -0x0c8c, -0x0fab, -0x12c8, -0x15e2,
-0x18f9, -0x1c0b, -0x1f1a, -0x2223, -0x2528, -0x2826, -0x2b1f, -0x2e11,
-0x30fb, -0x33df, -0x36ba, -0x398d, -0x3c56, -0x3f17, -0x41ce, -0x447a,
-0x471c, -0x49b4, -0x4c3f, -0x4ebf, -0x5133, -0x539b, -0x55f5, -0x5842,
-0x5a82, -0x5cb3, -0x5ed7, -0x60ec, -0x62f1, -0x64e8, -0x66cf, -0x68a6,
-0x6a6d, -0x6c23, -0x6dc9, -0x6f5e, -0x70e2, -0x7254, -0x73b5, -0x7504,
-0x7641, -0x776b, -0x7884, -0x7989, -0x7a7c, -0x7b5c, -0x7c29, -0x7ce3,
-0x7d89, -0x7e1d, -0x7e9c, -0x7f09, -0x7f61, -0x7fa6, -0x7fd8, -0x7ff5,
-0x7fff, -0x7ff5, -0x7fd8, -0x7fa6, -0x7f61, -0x7f09, -0x7e9c, -0x7e1d,
-0x7d89, -0x7ce3, -0x7c29, -0x7b5c, -0x7a7c, -0x7989, -0x7883, -0x776b,
-0x7641, -0x7504, -0x73b5, -0x7254, -0x70e2, -0x6f5e, -0x6dc9, -0x6c23,
-0x6a6d, -0x68a6, -0x66cf, -0x64e8, -0x62f1, -0x60eb, -0x5ed7, -0x5cb3,
-0x5a82, -0x5842, -0x55f5, -0x539a, -0x5133, -0x4ebf, -0x4c3f, -0x49b3,
-0x471c, -0x447a, -0x41cd, -0x3f17, -0x3c56, -0x398c, -0x36b9, -0x33de,
-0x30fb, -0x2e10, -0x2b1f, -0x2826, -0x2527, -0x2223, -0x1f19, -0x1c0b,
-0x18f8, -0x15e2, -0x12c8, -0x0fab, -0x0c8b, -0x096a, -0x0647, -0x0324
};
const int16 ST010::mode7_scale[176] = {
0x0380, 0x0325, 0x02da, 0x029c, 0x0268, 0x023b, 0x0215, 0x01f3,
0x01d5, 0x01bb, 0x01a3, 0x018e, 0x017b, 0x016a, 0x015a, 0x014b,
0x013e, 0x0132, 0x0126, 0x011c, 0x0112, 0x0109, 0x0100, 0x00f8,
0x00f0, 0x00e9, 0x00e3, 0x00dc, 0x00d6, 0x00d1, 0x00cb, 0x00c6,
0x00c1, 0x00bd, 0x00b8, 0x00b4, 0x00b0, 0x00ac, 0x00a8, 0x00a5,
0x00a2, 0x009e, 0x009b, 0x0098, 0x0095, 0x0093, 0x0090, 0x008d,
0x008b, 0x0088, 0x0086, 0x0084, 0x0082, 0x0080, 0x007e, 0x007c,
0x007a, 0x0078, 0x0076, 0x0074, 0x0073, 0x0071, 0x006f, 0x006e,
0x006c, 0x006b, 0x0069, 0x0068, 0x0067, 0x0065, 0x0064, 0x0063,
0x0062, 0x0060, 0x005f, 0x005e, 0x005d, 0x005c, 0x005b, 0x005a,
0x0059, 0x0058, 0x0057, 0x0056, 0x0055, 0x0054, 0x0053, 0x0052,
0x0051, 0x0051, 0x0050, 0x004f, 0x004e, 0x004d, 0x004d, 0x004c,
0x004b, 0x004b, 0x004a, 0x0049, 0x0048, 0x0048, 0x0047, 0x0047,
0x0046, 0x0045, 0x0045, 0x0044, 0x0044, 0x0043, 0x0042, 0x0042,
0x0041, 0x0041, 0x0040, 0x0040, 0x003f, 0x003f, 0x003e, 0x003e,
0x003d, 0x003d, 0x003c, 0x003c, 0x003b, 0x003b, 0x003a, 0x003a,
0x003a, 0x0039, 0x0039, 0x0038, 0x0038, 0x0038, 0x0037, 0x0037,
0x0036, 0x0036, 0x0036, 0x0035, 0x0035, 0x0035, 0x0034, 0x0034,
0x0034, 0x0033, 0x0033, 0x0033, 0x0032, 0x0032, 0x0032, 0x0031,
0x0031, 0x0031, 0x0030, 0x0030, 0x0030, 0x0030, 0x002f, 0x002f,
0x002f, 0x002e, 0x002e, 0x002e, 0x002e, 0x002d, 0x002d, 0x002d,
0x002d, 0x002c, 0x002c, 0x002c, 0x002c, 0x002b, 0x002b, 0x002b
};
const uint8 ST010::arctan[32][32] = {
{ 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80 },
{ 0x80, 0xa0, 0xad, 0xb3, 0xb6, 0xb8, 0xb9, 0xba, 0xbb, 0xbb, 0xbc, 0xbc, 0xbd, 0xbd, 0xbd, 0xbd,
0xbd, 0xbe, 0xbe, 0xbe, 0xbe, 0xbe, 0xbe, 0xbe, 0xbe, 0xbe, 0xbe, 0xbe, 0xbf, 0xbf, 0xbf, 0xbf },
{ 0x80, 0x93, 0xa0, 0xa8, 0xad, 0xb0, 0xb3, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xb9, 0xba, 0xba, 0xbb,
0xbb, 0xbb, 0xbb, 0xbc, 0xbc, 0xbc, 0xbc, 0xbc, 0xbd, 0xbd, 0xbd, 0xbd, 0xbd, 0xbd, 0xbd, 0xbd },
{ 0x80, 0x8d, 0x98, 0xa0, 0xa6, 0xaa, 0xad, 0xb0, 0xb1, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb7, 0xb8,
0xb8, 0xb9, 0xb9, 0xba, 0xba, 0xba, 0xba, 0xbb, 0xbb, 0xbb, 0xbb, 0xbb, 0xbc, 0xbc, 0xbc, 0xbc },
{ 0x80, 0x8a, 0x93, 0x9a, 0xa0, 0xa5, 0xa8, 0xab, 0xad, 0xaf, 0xb0, 0xb2, 0xb3, 0xb4, 0xb5, 0xb5,
0xb6, 0xb7, 0xb7, 0xb8, 0xb8, 0xb8, 0xb9, 0xb9, 0xb9, 0xba, 0xba, 0xba, 0xba, 0xba, 0xbb, 0xbb },
{ 0x80, 0x88, 0x90, 0x96, 0x9b, 0xa0, 0xa4, 0xa7, 0xa9, 0xab, 0xad, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3,
0xb4, 0xb4, 0xb5, 0xb6, 0xb6, 0xb6, 0xb7, 0xb7, 0xb8, 0xb8, 0xb8, 0xb9, 0xb9, 0xb9, 0xb9, 0xb9 },
{ 0x80, 0x87, 0x8d, 0x93, 0x98, 0x9c, 0xa0, 0xa3, 0xa6, 0xa8, 0xaa, 0xac, 0xad, 0xae, 0xb0, 0xb0,
0xb1, 0xb2, 0xb3, 0xb4, 0xb4, 0xb5, 0xb5, 0xb6, 0xb6, 0xb6, 0xb7, 0xb7, 0xb7, 0xb8, 0xb8, 0xb8 },
{ 0x80, 0x86, 0x8b, 0x90, 0x95, 0x99, 0x9d, 0xa0, 0xa3, 0xa5, 0xa7, 0xa9, 0xaa, 0xac, 0xad, 0xae,
0xaf, 0xb0, 0xb1, 0xb2, 0xb2, 0xb3, 0xb3, 0xb4, 0xb4, 0xb5, 0xb5, 0xb6, 0xb6, 0xb6, 0xb7, 0xb7 },
{ 0x80, 0x85, 0x8a, 0x8f, 0x93, 0x97, 0x9a, 0x9d, 0xa0, 0xa2, 0xa5, 0xa6, 0xa8, 0xaa, 0xab, 0xac,
0xad, 0xae, 0xaf, 0xb0, 0xb0, 0xb1, 0xb2, 0xb2, 0xb3, 0xb3, 0xb4, 0xb4, 0xb5, 0xb5, 0xb5, 0xb5 },
{ 0x80, 0x85, 0x89, 0x8d, 0x91, 0x95, 0x98, 0x9b, 0x9e, 0xa0, 0xa0, 0xa4, 0xa6, 0xa7, 0xa9, 0xaa,
0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb0, 0xb1, 0xb1, 0xb2, 0xb2, 0xb3, 0xb3, 0xb4, 0xb4, 0xb4 },
{ 0x80, 0x84, 0x88, 0x8c, 0x90, 0x93, 0x96, 0x99, 0x9b, 0x9e, 0xa0, 0xa2, 0xa4, 0xa5, 0xa7, 0xa8,
0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xaf, 0xb0, 0xb0, 0xb1, 0xb2, 0xb2, 0xb2, 0xb3, 0xb3 },
{ 0x80, 0x84, 0x87, 0x8b, 0x8e, 0x91, 0x94, 0x97, 0x9a, 0x9c, 0x9e, 0xa0, 0xa2, 0xa3, 0xa5, 0xa6,
0xa7, 0xa9, 0xaa, 0xab, 0xac, 0xac, 0xad, 0xae, 0xae, 0xaf, 0xb0, 0xb0, 0xb1, 0xb1, 0xb2, 0xb2 },
{ 0x80, 0x83, 0x87, 0x8a, 0x8d, 0x90, 0x93, 0x96, 0x98, 0x9a, 0x9c, 0x9e, 0xa0, 0xa2, 0xa3, 0xa5,
0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xac, 0xad, 0xae, 0xae, 0xaf, 0xb0, 0xb0, 0xb0, 0xb1 },
{ 0x80, 0x83, 0x86, 0x89, 0x8c, 0x8f, 0x92, 0x94, 0x96, 0x99, 0x9b, 0x9d, 0x9e, 0xa0, 0xa2, 0xa3,
0xa4, 0xa5, 0xa7, 0xa8, 0xa9, 0xa9, 0xaa, 0xab, 0xac, 0xac, 0xad, 0xae, 0xae, 0xaf, 0xaf, 0xb0 },
{ 0x80, 0x83, 0x86, 0x89, 0x8b, 0x8e, 0x90, 0x93, 0x95, 0x97, 0x99, 0x9b, 0x9d, 0x9e, 0xa0, 0xa1,
0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xaa, 0xab, 0xac, 0xad, 0xad, 0xae, 0xae, 0xaf },
{ 0x80, 0x83, 0x85, 0x88, 0x8b, 0x8d, 0x90, 0x92, 0x94, 0x96, 0x98, 0x9a, 0x9b, 0x9d, 0x9f, 0xa0,
0xa1, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa8, 0xa9, 0xaa, 0xab, 0xab, 0xac, 0xad, 0xad, 0xae },
{ 0x80, 0x83, 0x85, 0x88, 0x8a, 0x8c, 0x8f, 0x91, 0x93, 0x95, 0x97, 0x99, 0x9a, 0x9c, 0x9d, 0x9f,
0xa0, 0xa1, 0xa2, 0xa3, 0xa5, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xaa, 0xab, 0xab, 0xac, 0xad },
{ 0x80, 0x82, 0x85, 0x87, 0x89, 0x8c, 0x8e, 0x90, 0x92, 0x94, 0x96, 0x97, 0x99, 0x9b, 0x9c, 0x9d,
0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa8, 0xa9, 0xaa, 0xaa, 0xab, 0xac },
{ 0x80, 0x82, 0x85, 0x87, 0x89, 0x8b, 0x8d, 0x8f, 0x91, 0x93, 0x95, 0x96, 0x98, 0x99, 0x9b, 0x9c,
0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa7, 0xa8, 0xa9, 0xa9, 0xaa, 0xab },
{ 0x80, 0x82, 0x84, 0x86, 0x88, 0x8a, 0x8c, 0x8e, 0x90, 0x92, 0x94, 0x95, 0x97, 0x98, 0x9a, 0x9b,
0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa6, 0xa7, 0xa8, 0xa8, 0xa9, 0xaa },
{ 0x80, 0x82, 0x84, 0x86, 0x88, 0x8a, 0x8c, 0x8e, 0x90, 0x91, 0x93, 0x94, 0x96, 0x97, 0x99, 0x9a,
0x9b, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa5, 0xa6, 0xa7, 0xa7, 0xa8, 0xa9 },
{ 0x80, 0x82, 0x84, 0x86, 0x88, 0x8a, 0x8b, 0x8d, 0x8f, 0x90, 0x92, 0x94, 0x95, 0x97, 0x98, 0x99,
0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa4, 0xa5, 0xa6, 0xa6, 0xa7, 0xa8 },
{ 0x80, 0x82, 0x84, 0x86, 0x87, 0x89, 0x8b, 0x8d, 0x8e, 0x90, 0x91, 0x93, 0x94, 0x96, 0x97, 0x98,
0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa3, 0xa4, 0xa5, 0xa6, 0xa6, 0xa7 },
{ 0x80, 0x82, 0x84, 0x85, 0x87, 0x89, 0x8a, 0x8c, 0x8e, 0x8f, 0x91, 0x92, 0x94, 0x95, 0x96, 0x98,
0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa2, 0xa3, 0xa4, 0xa5, 0xa5, 0xa6 },
{ 0x80, 0x82, 0x83, 0x85, 0x87, 0x88, 0x8a, 0x8c, 0x8d, 0x8f, 0x90, 0x92, 0x93, 0x94, 0x96, 0x97,
0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa2, 0xa3, 0xa4, 0xa5, 0xa5 },
{ 0x80, 0x82, 0x83, 0x85, 0x86, 0x88, 0x8a, 0x8b, 0x8d, 0x8e, 0x90, 0x91, 0x92, 0x94, 0x95, 0x96,
0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa2, 0xa3, 0xa4, 0xa4 },
{ 0x80, 0x82, 0x83, 0x85, 0x86, 0x88, 0x89, 0x8b, 0x8c, 0x8e, 0x8f, 0x90, 0x92, 0x93, 0x94, 0x95,
0x96, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa2, 0xa3, 0xa4 },
{ 0x80, 0x82, 0x83, 0x85, 0x86, 0x87, 0x89, 0x8a, 0x8c, 0x8d, 0x8e, 0x90, 0x91, 0x92, 0x93, 0x95,
0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9e, 0x9f, 0xa0, 0xa1, 0xa1, 0xa2, 0xa3 },
{ 0x80, 0x81, 0x83, 0x84, 0x86, 0x87, 0x89, 0x8a, 0x8b, 0x8d, 0x8e, 0x8f, 0x90, 0x92, 0x93, 0x94,
0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9e, 0x9f, 0xa0, 0xa1, 0xa1, 0xa2 },
{ 0x80, 0x81, 0x83, 0x84, 0x86, 0x87, 0x88, 0x8a, 0x8b, 0x8c, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93,
0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0x9f, 0xa0, 0xa1, 0xa1 },
{ 0x80, 0x81, 0x83, 0x84, 0x85, 0x87, 0x88, 0x89, 0x8b, 0x8c, 0x8d, 0x8e, 0x90, 0x91, 0x92, 0x93,
0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0x9f, 0xa0, 0xa1 },
{ 0x80, 0x81, 0x83, 0x84, 0x85, 0x87, 0x88, 0x89, 0x8a, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92,
0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9c, 0x9d, 0x9e, 0x9f, 0x9f, 0xa0 }
};

261
src/chip/st010/st010_op.cpp Normal file
View File

@@ -0,0 +1,261 @@
#ifdef ST010_CPP
//ST-010 emulation code - Copyright (C) 2003 The Dumper, Matthew Kendora, Overload, Feather
//bsnes port - Copyright (C) 2007 byuu
void ST010::op_01(int16 x0, int16 y0, int16 &x1, int16 &y1, int16 &quadrant, int16 &theta) {
if((x0 < 0) && (y0 < 0)) {
x1 = -x0;
y1 = -y0;
quadrant = -0x8000;
} else if(x0 < 0) {
x1 = y0;
y1 = -x0;
quadrant = -0x4000;
} else if(y0 < 0) {
x1 = -y0;
y1 = x0;
quadrant = 0x4000;
} else {
x1 = x0;
y1 = y0;
quadrant = 0x0000;
}
while((x1 > 0x1f) || (y1 > 0x1f)) {
if(x1 > 1) { x1 >>= 1; }
if(y1 > 1) { y1 >>= 1; }
}
if(y1 == 0) { quadrant += 0x4000; }
theta = (arctan[y1][x1] << 8) ^ quadrant;
}
//
void ST010::op_01() {
int16 x0 = readw(0x0000);
int16 y0 = readw(0x0002);
int16 x1, y1, quadrant, theta;
op_01(x0, y0, x1, y1, quadrant, theta);
writew(0x0000, x1);
writew(0x0002, y1);
writew(0x0004, quadrant);
//writew(0x0006, y0); //Overload's docs note this write occurs, SNES9x disagrees
writew(0x0010, theta);
}
void ST010::op_02() {
int16 positions = readw(0x0024);
uint16 *places = (uint16*)(ram + 0x0040);
uint16 *drivers = (uint16*)(ram + 0x0080);
bool sorted;
uint16 temp;
if(positions > 1) {
do {
sorted = true;
for(int i = 0; i < positions - 1; i++) {
if(places[i] < places[i + 1]) {
temp = places[i + 1];
places[i + 1] = places[i];
places[i] = temp;
temp = drivers[i + 1];
drivers[i + 1] = drivers[i];
drivers[i] = temp;
sorted = false;
}
}
positions--;
} while(!sorted);
}
}
void ST010::op_03() {
int16 x0 = readw(0x0000);
int16 y0 = readw(0x0002);
int16 multiplier = readw(0x0004);
int32 x1, y1;
x1 = x0 * multiplier << 1;
y1 = y0 * multiplier << 1;
writed(0x0010, x1);
writed(0x0014, y1);
}
void ST010::op_04() {
int16 x = readw(0x0000);
int16 y = readw(0x0002);
int16 square;
//calculate the vector length of (x,y)
square = (int16)sqrt((double)(y * y + x * x));
writew(0x0010, square);
}
void ST010::op_05() {
int32 dx, dy;
int16 a1, b1, c1;
uint16 o1;
bool wrap = false;
//target (x,y) coordinates
int16 ypos_max = readw(0x00c0);
int16 xpos_max = readw(0x00c2);
//current coordinates and direction
int32 ypos = readd(0x00c4);
int32 xpos = readd(0x00c8);
uint16 rot = readw(0x00cc);
//physics
uint16 speed = readw(0x00d4);
uint16 accel = readw(0x00d6);
uint16 speed_max = readw(0x00d8);
//special condition acknowledgement
int16 system = readw(0x00da);
int16 flags = readw(0x00dc);
//new target coordinates
int16 ypos_new = readw(0x00de);
int16 xpos_new = readw(0x00e0);
//mask upper bit
xpos_new &= 0x7fff;
//get the current distance
dx = xpos_max - (xpos >> 16);
dy = ypos_max - (ypos >> 16);
//quirk: clear and move in9
writew(0x00d2, 0xffff);
writew(0x00da, 0x0000);
//grab the target angle
op_01(dy, dx, a1, b1, c1, (int16&)o1);
//check for wrapping
if(abs(o1 - rot) > 0x8000) {
o1 += 0x8000;
rot += 0x8000;
wrap = true;
}
uint16 old_speed = speed;
//special case
if(abs(o1 - rot) == 0x8000) {
speed = 0x100;
}
//slow down for sharp curves
else if(abs(o1 - rot) >= 0x1000) {
uint32 slow = abs(o1 - rot);
slow >>= 4; //scaling
speed -= slow;
}
//otherwise accelerate
else {
speed += accel;
if(speed > speed_max) {
speed = speed_max; //clip speed
}
}
//prevent negative/positive overflow
if(abs(old_speed - speed) > 0x8000) {
if(old_speed < speed) { speed = 0; }
else speed = 0xff00;
}
//adjust direction by so many degrees
//be careful of negative adjustments
if((o1 > rot && (o1 - rot) > 0x80) || (o1 < rot && (rot - o1) >= 0x80)) {
if(o1 < rot) { rot -= 0x280; }
else if(o1 > rot) { rot += 0x280; }
}
//turn of wrapping
if(wrap) { rot -= 0x8000; }
//now check the distances (store for later)
dx = (xpos_max << 16) - xpos;
dy = (ypos_max << 16) - ypos;
dx >>= 16;
dy >>= 16;
//if we're in so many units of the target, signal it
if((system && (dy <= 6 && dy >= -8) && (dx <= 126 && dx >= -128)) || (!system && (dx <= 6 && dx >= -8) && (dy <= 126 && dy >= -128))) {
//announce our new destination and flag it
xpos_max = xpos_new & 0x7fff;
ypos_max = ypos_new;
flags |= 0x08;
}
//update position
xpos -= (cos(rot) * 0x400 >> 15) * (speed >> 8) << 1;
ypos -= (sin(rot) * 0x400 >> 15) * (speed >> 8) << 1;
//quirk: mask upper byte
xpos &= 0x1fffffff;
ypos &= 0x1fffffff;
writew(0x00c0, ypos_max);
writew(0x00c2, xpos_max);
writed(0x00c4, ypos);
writed(0x00c8, xpos);
writew(0x00cc, rot);
writew(0x00d4, speed);
writew(0x00dc, flags);
}
void ST010::op_06() {
int16 multiplicand = readw(0x0000);
int16 multiplier = readw(0x0002);
int32 product;
product = multiplicand * multiplier << 1;
writed(0x0010, product);
}
void ST010::op_07() {
int16 theta = readw(0x0000);
int16 data;
for(int i = 0, offset = 0; i < 176; i++) {
data = mode7_scale[i] * cos(theta) >> 15;
writew(0x00f0 + offset, data);
writew(0x0510 + offset, data);
data = mode7_scale[i] * sin(theta) >> 15;
writew(0x0250 + offset, data);
if(data) { data = ~data; }
writew(0x03b0 + offset, data);
offset += 2;
}
}
void ST010::op_08() {
int16 x0 = readw(0x0000);
int16 y0 = readw(0x0002);
int16 theta = readw(0x0004);
int16 x1, y1;
x1 = (y0 * sin(theta) >> 15) + (x0 * cos(theta) >> 15);
y1 = (y0 * cos(theta) >> 15) - (x0 * sin(theta) >> 15);
writew(0x0010, x1);
writew(0x0012, y1);
}
#endif

View File

@@ -1 +1 @@
@make PLATFORM=win-visualc-lui clean
@mingw32-make platform=win compiler=mingw32-gcc clean

View File

@@ -1,2 +1 @@
#!/bin/sh
make PLATFORM=x-gcc-lui clean
make platform=x compiler=gcc clean

View File

@@ -1,107 +0,0 @@
Config config_file;
namespace config {
string file_updatepath(const char *req_file, const char *req_path) {
string file(req_file);
replace(file, "\\", "/");
if(!req_path || strlen(req_path) == 0) { return file; }
string path(req_path);
replace(path, "\\", "/");
if(!strend(path, "/")) { strcat(path, "/"); }
if(strbegin(path, "./")) {
strltrim(path, "./");
string temp;
strcpy(temp, config::path.base);
strcat(temp, path);
strcpy(path, temp);
}
stringarray part;
split(part, "/", file);
strcat(path, part[count(part) - 1]);
return path;
}
StringSetting Path::base(0, "fs.base_path",
"Path that bsnes resides in", "");
StringSetting Path::rom(&config_file, "path.rom",
"Default path to look for ROM files in (\"\" = use default directory)", "");
StringSetting Path::save(&config_file, "path.save",
"Default path for all save RAM and cheat files (\"\" = use current directory)", "");
StringSetting Path::bios(&config_file, "path.bios",
"Path where BIOS file(s) are located\n"
"Supported BIOS files:\n"
"stbios.bin - Bandai Sufami Turbo"
"", "./bios");
StringSetting Path::save_ext(&config_file, "path.save_ext",
"Extension to be used for all save RAM files", "srm");
IntegerSetting SNES::gamma_ramp(&config_file, "snes.colorfilter.gamma_ramp",
"Use precalculated TV-style gamma ramp", IntegerSetting::Boolean, true);
IntegerSetting SNES::sepia(&config_file, "snes.colorfilter.sepia",
"Convert color to sepia tone", IntegerSetting::Boolean, false);
IntegerSetting SNES::grayscale(&config_file, "snes.colorfilter.grayscale",
"Convert color to grayscale tone", IntegerSetting::Boolean, false);
IntegerSetting SNES::invert(&config_file, "snes.colorfilter.invert",
"Invert output image colors", IntegerSetting::Boolean, false);
IntegerSetting SNES::contrast(&config_file, "snes.colorfilter.contrast",
"Contrast", IntegerSetting::Decimal, 0);
IntegerSetting SNES::brightness(&config_file, "snes.colorfilter.brightness",
"Brightness", IntegerSetting::Decimal, 0);
IntegerSetting SNES::gamma(&config_file, "snes.colorfilter.gamma",
"Gamma", IntegerSetting::Decimal, 80);
IntegerSetting SNES::ntsc_merge_fields(&config_file, "snes.ntsc_merge_fields",
"Merge fields in NTSC video filter\n"
"Set to true if using filter at any refresh rate other than 60hz\n"
"", IntegerSetting::Boolean, true);
IntegerSetting SNES::mute(&config_file, "snes.mute", "Mutes SNES audio output when enabled",
IntegerSetting::Boolean, false);
IntegerSetting SNES::controller_port0(&config_file, "snes.controller_port_1",
"Controller attached to SNES port 1", IntegerSetting::Decimal, ::SNES::DEVICEID_JOYPAD1);
IntegerSetting SNES::controller_port1(&config_file, "snes.controller_port_2",
"Controller attached to SNES port 2", IntegerSetting::Decimal, ::SNES::DEVICEID_JOYPAD2);
IntegerSetting CPU::ntsc_clock_rate(&config_file, "cpu.ntsc_clock_rate",
"NTSC S-CPU clock rate (in hz)", IntegerSetting::Decimal, 21477272);
IntegerSetting CPU::pal_clock_rate(&config_file, "cpu.pal_clock_rate",
"PAL S-CPU clock rate (in hz)", IntegerSetting::Decimal, 21281370);
IntegerSetting CPU::hdma_enable(0, "cpu.hdma_enable",
"Enable HDMA effects", IntegerSetting::Boolean, true);
IntegerSetting SMP::ntsc_clock_rate(&config_file, "smp.ntsc_clock_rate",
"NTSC S-SMP clock rate (in hz)", IntegerSetting::Decimal, 24606720);
IntegerSetting SMP::pal_clock_rate(&config_file, "smp.pal_clock_rate",
"PAL S-SMP clock rate (in hz)", IntegerSetting::Decimal, 24606720);
IntegerSetting PPU::Hack::render_scanline_position(&config_file, "ppu.hack.render_scanline_position",
"Approximate HCLOCK position to render at for scanline-based renderers",
IntegerSetting::Decimal, 512);
IntegerSetting PPU::Hack::obj_cache(&config_file, "ppu.hack.obj_cache",
"Cache OAM OBJ attributes one scanline before rendering\n"
"This is technically closer to the actual operation of the SNES,\n"
"but can cause problems in some games if enabled",
IntegerSetting::Boolean, false);
IntegerSetting PPU::opt_enable(0, "ppu.opt_enable", "Enable offset-per-tile effects", IntegerSetting::Boolean, true);
IntegerSetting PPU::bg1_pri0_enable(0, "ppu.bg1_pri0_enable", "Enable BG1 Priority 0", IntegerSetting::Boolean, true);
IntegerSetting PPU::bg1_pri1_enable(0, "ppu.bg1_pri1_enable", "Enable BG1 Priority 1", IntegerSetting::Boolean, true);
IntegerSetting PPU::bg2_pri0_enable(0, "ppu.bg2_pri0_enable", "Enable BG2 Priority 0", IntegerSetting::Boolean, true);
IntegerSetting PPU::bg2_pri1_enable(0, "ppu.bg2_pri1_enable", "Enable BG2 Priority 1", IntegerSetting::Boolean, true);
IntegerSetting PPU::bg3_pri0_enable(0, "ppu.bg3_pri0_enable", "Enable BG3 Priority 0", IntegerSetting::Boolean, true);
IntegerSetting PPU::bg3_pri1_enable(0, "ppu.bg3_pri1_enable", "Enable BG3 Priority 1", IntegerSetting::Boolean, true);
IntegerSetting PPU::bg4_pri0_enable(0, "ppu.bg4_pri0_enable", "Enable BG4 Priority 0", IntegerSetting::Boolean, true);
IntegerSetting PPU::bg4_pri1_enable(0, "ppu.bg4_pri1_enable", "Enable BG4 Priority 1", IntegerSetting::Boolean, true);
IntegerSetting PPU::oam_pri0_enable(0, "ppu.oam_pri0_enable", "Enable OAM Priority 0", IntegerSetting::Boolean, true);
IntegerSetting PPU::oam_pri1_enable(0, "ppu.oam_pri1_enable", "Enable OAM Priority 1", IntegerSetting::Boolean, true);
IntegerSetting PPU::oam_pri2_enable(0, "ppu.oam_pri2_enable", "Enable OAM Priority 2", IntegerSetting::Boolean, true);
IntegerSetting PPU::oam_pri3_enable(0, "ppu.oam_pri3_enable", "Enable OAM Priority 3", IntegerSetting::Boolean, true);
};

View File

@@ -1,44 +0,0 @@
extern Config config_file;
namespace config {
string file_updatepath(const char *, const char *);
extern struct Path {
static StringSetting base, rom, save, bios;
static StringSetting save_ext;
} path;
extern struct SNES {
static IntegerSetting gamma_ramp, sepia, grayscale, invert, contrast, brightness, gamma;
static IntegerSetting ntsc_merge_fields;
static IntegerSetting mute;
static IntegerSetting controller_port0;
static IntegerSetting controller_port1;
} snes;
extern struct CPU {
static IntegerSetting ntsc_clock_rate, pal_clock_rate;
static IntegerSetting hdma_enable;
} cpu;
extern struct SMP {
static IntegerSetting ntsc_clock_rate, pal_clock_rate;
} smp;
extern struct PPU {
struct Hack {
static IntegerSetting render_scanline_position;
static IntegerSetting obj_cache;
} hack;
static IntegerSetting opt_enable;
static IntegerSetting bg1_pri0_enable, bg1_pri1_enable;
static IntegerSetting bg2_pri0_enable, bg2_pri1_enable;
static IntegerSetting bg3_pri0_enable, bg3_pri1_enable;
static IntegerSetting bg4_pri0_enable, bg4_pri1_enable;
static IntegerSetting oam_pri0_enable, oam_pri1_enable;
static IntegerSetting oam_pri2_enable, oam_pri3_enable;
} ppu;
};

View File

@@ -1,8 +1,10 @@
#include "../base.h"
#include <../base.hpp>
#define CPU_CPP
#include "dcpu.cpp"
CPU::CPU() {
cpu_version = 1;
cpu_version = 2;
}
CPU::~CPU() {

View File

@@ -1,92 +0,0 @@
#include "cpuregs.h"
class CPU : public MMIO {
public:
virtual void enter() = 0;
public:
//CPU version number
//* 1 and 2 are known
//* reported by $4210
//* affects DRAM refresh behavior
uint8 cpu_version;
//timing
virtual uint16 vcounter() = 0;
virtual uint16 hcounter() = 0;
virtual uint16 hclock() = 0;
virtual bool interlace() = 0;
virtual bool interlace_field() = 0;
virtual bool overscan() = 0;
virtual uint16 region_scanlines() = 0;
virtual void set_interlace(bool r) = 0;
virtual void set_overscan (bool r) = 0;
CPURegs regs;
virtual uint8 port_read (uint8 port) = 0;
virtual void port_write(uint8 port, uint8 value) = 0;
enum {
FLAG_N = 0x80, FLAG_V = 0x40,
FLAG_M = 0x20, FLAG_X = 0x10,
FLAG_D = 0x08, FLAG_I = 0x04,
FLAG_Z = 0x02, FLAG_C = 0x01
};
virtual uint8 pio_status() = 0;
virtual void scanline() = 0;
virtual void frame() = 0;
virtual void power() = 0;
virtual void reset() = 0;
/*****
* in opcode-based CPU emulators, the main emulation routine
* will only be able to call the disassemble_opcode() function
* on clean opcode edges. but with cycle-based CPU emulators,
* the CPU may be in the middle of executing an opcode when the
* emulator (e.g. debugger) wants to disassemble an opcode. this
* would mean that important registers may not reflect what they
* did at the start of the opcode (especially regs.pc), so in
* cycle-based emulators, this function should be overridden to
* reflect whether or not an opcode has only been partially
* executed. if not, the debugger should abort attempts to skip,
* disable, or disassemble the current opcode.
*****/
virtual bool in_opcode() { return false; }
/*****
* opcode disassembler
*****/
enum {
OPTYPE_DP = 0, //dp
OPTYPE_DPX, //dp,x
OPTYPE_DPY, //dp,y
OPTYPE_IDP, //(dp)
OPTYPE_IDPX, //(dp,x)
OPTYPE_IDPY, //(dp),y
OPTYPE_ILDP, //[dp]
OPTYPE_ILDPY, //[dp],y
OPTYPE_ADDR, //addr
OPTYPE_ADDRX, //addr,x
OPTYPE_ADDRY, //addr,y
OPTYPE_IADDRX, //(addr,x)
OPTYPE_ILADDR, //[addr]
OPTYPE_LONG, //long
OPTYPE_LONGX, //long, x
OPTYPE_SR, //sr,s
OPTYPE_ISRY, //(sr,s),y
OPTYPE_ADDR_PC, //pbr:addr
OPTYPE_IADDR_PC, //pbr:(addr)
OPTYPE_RELB, //relb
OPTYPE_RELW, //relw
};
void disassemble_opcode(char *output);
uint8 dreadb(uint32 addr);
uint16 dreadw(uint32 addr);
uint32 dreadl(uint32 addr);
uint32 decode(uint8 offset_type, uint32 addr);
uint8 opcode_length();
CPU();
virtual ~CPU();
};

74
src/cpu/cpu.hpp Normal file
View File

@@ -0,0 +1,74 @@
class CPU : public MMIO {
public:
virtual void enter() = 0;
//CPU version number
//* 1 and 2 are known
//* reported by $4210
//* affects timing (DRAM refresh, HDMA init, etc)
uint8 cpu_version;
virtual uint8 pio() = 0;
virtual bool joylatch() = 0;
virtual uint8 port_read(uint8 port) = 0;
virtual void port_write(uint8 port, uint8 value) = 0;
#include "cpuregs.hpp"
regs_t regs;
virtual void scanline() = 0;
virtual void power() = 0;
virtual void reset() = 0;
/*****
* in opcode-based CPU emulators, the main emulation routine
* will only be able to call the disassemble_opcode() function
* on clean opcode edges. but with cycle-based CPU emulators,
* the CPU may be in the middle of executing an opcode when the
* emulator (e.g. debugger) wants to disassemble an opcode. this
* would mean that important registers may not reflect what they
* did at the start of the opcode (especially regs.pc), so in
* cycle-based emulators, this function should be overridden to
* reflect whether or not an opcode has only been partially
* executed. if not, the debugger should abort attempts to skip,
* disable, or disassemble the current opcode.
*****/
virtual bool in_opcode() { return false; }
/*****
* opcode disassembler
*****/
enum {
OPTYPE_DP = 0, //dp
OPTYPE_DPX, //dp,x
OPTYPE_DPY, //dp,y
OPTYPE_IDP, //(dp)
OPTYPE_IDPX, //(dp,x)
OPTYPE_IDPY, //(dp),y
OPTYPE_ILDP, //[dp]
OPTYPE_ILDPY, //[dp],y
OPTYPE_ADDR, //addr
OPTYPE_ADDRX, //addr,x
OPTYPE_ADDRY, //addr,y
OPTYPE_IADDRX, //(addr,x)
OPTYPE_ILADDR, //[addr]
OPTYPE_LONG, //long
OPTYPE_LONGX, //long, x
OPTYPE_SR, //sr,s
OPTYPE_ISRY, //(sr,s),y
OPTYPE_ADDR_PC, //pbr:addr
OPTYPE_IADDR_PC, //pbr:(addr)
OPTYPE_RELB, //relb
OPTYPE_RELW, //relw
};
void disassemble_opcode(char *output);
uint8 dreadb(uint32 addr);
uint16 dreadw(uint32 addr);
uint32 dreadl(uint32 addr);
uint32 decode(uint8 offset_type, uint32 addr);
uint8 opcode_length();
CPU();
virtual ~CPU();
};

View File

@@ -1,75 +0,0 @@
class CPURegFlags {
public:
union {
uint8 data;
struct {
bool order_msb8(n:1, v:1, m:1, x:1, d:1, i:1, z:1, c:1);
};
};
inline operator unsigned() const { return data; }
template<typename T> inline unsigned operator = (const T i) { data = i; return data; }
template<typename T> inline unsigned operator |= (const T i) { data |= i; return data; }
template<typename T> inline unsigned operator ^= (const T i) { data ^= i; return data; }
template<typename T> inline unsigned operator &= (const T i) { data &= i; return data; }
CPURegFlags() : data(0) {}
};
class CPUReg16 {
public:
union {
uint16 w;
struct { uint8 order_lsb2(l, h); };
};
inline operator unsigned() const { return w; }
template<typename T> inline unsigned operator = (const T i) { w = i; return w; }
template<typename T> inline unsigned operator |= (const T i) { w |= i; return w; }
template<typename T> inline unsigned operator ^= (const T i) { w ^= i; return w; }
template<typename T> inline unsigned operator &= (const T i) { w &= i; return w; }
template<typename T> inline unsigned operator <<= (const T i) { w <<= i; return w; }
template<typename T> inline unsigned operator >>= (const T i) { w >>= i; return w; }
template<typename T> inline unsigned operator += (const T i) { w += i; return w; }
template<typename T> inline unsigned operator -= (const T i) { w -= i; return w; }
template<typename T> inline unsigned operator *= (const T i) { w *= i; return w; }
template<typename T> inline unsigned operator /= (const T i) { w /= i; return w; }
template<typename T> inline unsigned operator %= (const T i) { w %= i; return w; }
CPUReg16() : w(0) {}
};
class CPUReg24 {
public:
union {
uint32 d;
struct { uint16 order_lsb2(w, wh); };
struct { uint8 order_lsb4(l, h, b, bh); };
};
inline operator unsigned() const { return d; }
template<typename T> inline unsigned operator = (const T i) { d = uclip<24>(i); return d; }
template<typename T> inline unsigned operator |= (const T i) { d = uclip<24>(d | i); return d; }
template<typename T> inline unsigned operator ^= (const T i) { d = uclip<24>(d ^ i); return d; }
template<typename T> inline unsigned operator &= (const T i) { d = uclip<24>(d & i); return d; }
template<typename T> inline unsigned operator <<= (const T i) { d = uclip<24>(d << i); return d; }
template<typename T> inline unsigned operator >>= (const T i) { d = uclip<24>(d >> i); return d; }
template<typename T> inline unsigned operator += (const T i) { d = uclip<24>(d + i); return d; }
template<typename T> inline unsigned operator -= (const T i) { d = uclip<24>(d - i); return d; }
template<typename T> inline unsigned operator *= (const T i) { d = uclip<24>(d * i); return d; }
template<typename T> inline unsigned operator /= (const T i) { d = uclip<24>(d / i); return d; }
template<typename T> inline unsigned operator %= (const T i) { d = uclip<24>(d % i); return d; }
CPUReg24() : d(0) {}
};
class CPURegs {
public:
CPUReg24 pc;
CPUReg16 a, x, y, s, d;
CPURegFlags p;
uint8 db;
uint8 mdr;
bool e;
CPURegs() : db(0), mdr(0x00), e(false) {}
};

74
src/cpu/cpuregs.hpp Normal file
View File

@@ -0,0 +1,74 @@
struct flag_t {
bool n, v, m, x, d, i, z, c;
inline operator unsigned() const {
return (n << 7) + (v << 6) + (m << 5) + (x << 4)
+ (d << 3) + (i << 2) + (z << 1) + (c << 0);
}
inline unsigned operator=(uint8_t data) {
n = data & 0x80; v = data & 0x40; m = data & 0x20; x = data & 0x10;
d = data & 0x08; i = data & 0x04; z = data & 0x02; c = data & 0x01;
return data;
}
inline unsigned operator|=(unsigned data) { return operator=(operator unsigned() | data); }
inline unsigned operator^=(unsigned data) { return operator=(operator unsigned() ^ data); }
inline unsigned operator&=(unsigned data) { return operator=(operator unsigned() & data); }
flag_t() : n(0), v(0), m(0), x(0), d(0), i(0), z(0), c(0) {}
};
struct reg16_t {
union {
uint16 w;
struct { uint8 order_lsb2(l, h); };
};
inline operator unsigned() const { return w; }
inline unsigned operator = (unsigned i) { return w = i; }
inline unsigned operator |= (unsigned i) { return w |= i; }
inline unsigned operator ^= (unsigned i) { return w ^= i; }
inline unsigned operator &= (unsigned i) { return w &= i; }
inline unsigned operator <<= (unsigned i) { return w <<= i; }
inline unsigned operator >>= (unsigned i) { return w >>= i; }
inline unsigned operator += (unsigned i) { return w += i; }
inline unsigned operator -= (unsigned i) { return w -= i; }
inline unsigned operator *= (unsigned i) { return w *= i; }
inline unsigned operator /= (unsigned i) { return w /= i; }
inline unsigned operator %= (unsigned i) { return w %= i; }
reg16_t() : w(0) {}
};
struct reg24_t {
union {
uint32 d;
struct { uint16 order_lsb2(w, wh); };
struct { uint8 order_lsb4(l, h, b, bh); };
};
inline operator unsigned() const { return d; }
inline unsigned operator = (unsigned i) { return d = uclip<24>(i); }
inline unsigned operator |= (unsigned i) { return d = uclip<24>(d | i); }
inline unsigned operator ^= (unsigned i) { return d = uclip<24>(d ^ i); }
inline unsigned operator &= (unsigned i) { return d = uclip<24>(d & i); }
inline unsigned operator <<= (unsigned i) { return d = uclip<24>(d << i); }
inline unsigned operator >>= (unsigned i) { return d = uclip<24>(d >> i); }
inline unsigned operator += (unsigned i) { return d = uclip<24>(d + i); }
inline unsigned operator -= (unsigned i) { return d = uclip<24>(d - i); }
inline unsigned operator *= (unsigned i) { return d = uclip<24>(d * i); }
inline unsigned operator /= (unsigned i) { return d = uclip<24>(d / i); }
inline unsigned operator %= (unsigned i) { return d = uclip<24>(d % i); }
reg24_t() : d(0) {}
};
struct regs_t {
reg24_t pc;
reg16_t a, x, y, s, d;
flag_t p;
uint8_t db, mdr;
bool e;
regs_t() : db(0), mdr(0), e(false) {}
};

View File

@@ -1,21 +1,23 @@
#ifdef CPU_CPP
uint8 CPU::dreadb(uint32 addr) {
if((addr & 0x40ffff) >= 0x2000 && (addr & 0x40ffff) <= 0x5fff) {
//$[00-3f|80-bf]:[2000-5fff]
//do not read MMIO registers within debugger
//$[00-3f|80-bf]:[2000-5fff]
//do not read MMIO registers within debugger
return 0x00;
}
return r_mem->read(addr);
return bus.read(addr);
}
uint16 CPU::dreadw(uint32 addr) {
uint16 r;
uint16 r;
r = dreadb((addr + 0) & 0xffffff) << 0;
r |= dreadb((addr + 1) & 0xffffff) << 8;
return r;
}
uint32 CPU::dreadl(uint32 addr) {
uint32 r;
uint32 r;
r = dreadb((addr + 0) & 0xffffff) << 0;
r |= dreadb((addr + 1) & 0xffffff) << 8;
r |= dreadb((addr + 2) & 0xffffff) << 16;
@@ -23,87 +25,89 @@ uint32 r;
}
uint32 CPU::decode(uint8 offset_type, uint32 addr) {
uint32 r = 0;
uint32 r = 0;
switch(offset_type) {
case OPTYPE_DP:
r = (regs.d + (addr & 0xffff)) & 0xffff;
break;
case OPTYPE_DPX:
r = (regs.d + regs.x + (addr & 0xffff)) & 0xffff;
break;
case OPTYPE_DPY:
r = (regs.d + regs.y + (addr & 0xffff)) & 0xffff;
break;
case OPTYPE_IDP:
addr = (regs.d + (addr & 0xffff)) & 0xffff;
r = (regs.db << 16) + dreadw(addr);
break;
case OPTYPE_IDPX:
addr = (regs.d + regs.x + (addr & 0xffff)) & 0xffff;
r = (regs.db << 16) + dreadw(addr);
break;
case OPTYPE_IDPY:
addr = (regs.d + (addr & 0xffff)) & 0xffff;
r = (regs.db << 16) + dreadw(addr) + regs.y;
break;
case OPTYPE_ILDP:
addr = (regs.d + (addr & 0xffff)) & 0xffff;
r = dreadl(addr);
break;
case OPTYPE_ILDPY:
addr = (regs.d + (addr & 0xffff)) & 0xffff;
r = dreadl(addr) + regs.y;
break;
case OPTYPE_ADDR:
r = (regs.db << 16) + (addr & 0xffff);
break;
case OPTYPE_ADDR_PC:
r = (regs.pc.b << 16) + (addr & 0xffff);
break;
case OPTYPE_ADDRX:
r = (regs.db << 16) + (addr & 0xffff) + regs.x;
break;
case OPTYPE_ADDRY:
r = (regs.db << 16) + (addr & 0xffff) + regs.y;
break;
case OPTYPE_IADDR_PC:
r = (regs.pc.b << 16) + (addr & 0xffff);
break;
case OPTYPE_IADDRX:
r = (regs.pc.b << 16) + ((addr + regs.x) & 0xffff);
break;
case OPTYPE_ILADDR:
r = addr;
break;
case OPTYPE_LONG:
r = addr;
break;
case OPTYPE_LONGX:
r = (addr + regs.x);
break;
case OPTYPE_SR:
r = (regs.s + (addr & 0xff)) & 0xffff;
break;
case OPTYPE_ISRY:
addr = (regs.s + (addr & 0xff)) & 0xffff;
r = (regs.db << 16) + dreadw(addr) + regs.y;
break;
case OPTYPE_RELB:
r = (regs.pc.b << 16) + ((regs.pc.w + 2) & 0xffff);
r += int8(addr);
break;
case OPTYPE_RELW:
r = (regs.pc.b << 16) + ((regs.pc.w + 3) & 0xffff);
r += int16(addr);
break;
case OPTYPE_DP:
r = (regs.d + (addr & 0xffff)) & 0xffff;
break;
case OPTYPE_DPX:
r = (regs.d + regs.x + (addr & 0xffff)) & 0xffff;
break;
case OPTYPE_DPY:
r = (regs.d + regs.y + (addr & 0xffff)) & 0xffff;
break;
case OPTYPE_IDP:
addr = (regs.d + (addr & 0xffff)) & 0xffff;
r = (regs.db << 16) + dreadw(addr);
break;
case OPTYPE_IDPX:
addr = (regs.d + regs.x + (addr & 0xffff)) & 0xffff;
r = (regs.db << 16) + dreadw(addr);
break;
case OPTYPE_IDPY:
addr = (regs.d + (addr & 0xffff)) & 0xffff;
r = (regs.db << 16) + dreadw(addr) + regs.y;
break;
case OPTYPE_ILDP:
addr = (regs.d + (addr & 0xffff)) & 0xffff;
r = dreadl(addr);
break;
case OPTYPE_ILDPY:
addr = (regs.d + (addr & 0xffff)) & 0xffff;
r = dreadl(addr) + regs.y;
break;
case OPTYPE_ADDR:
r = (regs.db << 16) + (addr & 0xffff);
break;
case OPTYPE_ADDR_PC:
r = (regs.pc.b << 16) + (addr & 0xffff);
break;
case OPTYPE_ADDRX:
r = (regs.db << 16) + (addr & 0xffff) + regs.x;
break;
case OPTYPE_ADDRY:
r = (regs.db << 16) + (addr & 0xffff) + regs.y;
break;
case OPTYPE_IADDR_PC:
r = (regs.pc.b << 16) + (addr & 0xffff);
break;
case OPTYPE_IADDRX:
r = (regs.pc.b << 16) + ((addr + regs.x) & 0xffff);
break;
case OPTYPE_ILADDR:
r = addr;
break;
case OPTYPE_LONG:
r = addr;
break;
case OPTYPE_LONGX:
r = (addr + regs.x);
break;
case OPTYPE_SR:
r = (regs.s + (addr & 0xff)) & 0xffff;
break;
case OPTYPE_ISRY:
addr = (regs.s + (addr & 0xff)) & 0xffff;
r = (regs.db << 16) + dreadw(addr) + regs.y;
break;
case OPTYPE_RELB:
r = (regs.pc.b << 16) + ((regs.pc.w + 2) & 0xffff);
r += int8(addr);
break;
case OPTYPE_RELW:
r = (regs.pc.b << 16) + ((regs.pc.w + 3) & 0xffff);
r += int16(addr);
break;
}
return(r & 0xffffff);
}
void CPU::disassemble_opcode(char *output) {
static CPUReg24 pc;
char t[256];
char *s = output;
static reg24_t pc;
char t[256];
char *s = output;
if(in_opcode() == true) {
strcpy(s, "?????? <CPU within opcode>");
@@ -111,365 +115,369 @@ char *s = output;
}
pc.d = regs.pc.d;
sprintf(s, "%0.6x ", uint32(pc.d));
sprintf(s, "%.6x ", (uint32)pc.d);
uint8 op = dreadb(pc.d); pc.w++;
uint8 op0 = dreadb(pc.d); pc.w++;
uint8 op1 = dreadb(pc.d); pc.w++;
uint8 op2 = dreadb(pc.d);
uint8 op = dreadb(pc.d); pc.w++;
uint8 op0 = dreadb(pc.d); pc.w++;
uint8 op1 = dreadb(pc.d); pc.w++;
uint8 op2 = dreadb(pc.d);
#define op8 ((op0))
#define op16 ((op0) | (op1 << 8))
#define op24 ((op0) | (op1 << 8) | (op2 << 16))
#define a8 (regs.e || regs.p.m)
#define x8 (regs.e || regs.p.x)
#define op8 ((op0))
#define op16 ((op0) | (op1 << 8))
#define op24 ((op0) | (op1 << 8) | (op2 << 16))
#define a8 (regs.e || regs.p.m)
#define x8 (regs.e || regs.p.x)
switch(op) {
case 0x00: sprintf(t, "brk #$%0.2x ", op8); break;
case 0x01: sprintf(t, "ora ($%0.2x,x) [$%0.6x]", op8, decode(OPTYPE_IDPX, op8)); break;
case 0x02: sprintf(t, "cop #$%0.2x ", op8); break;
case 0x03: sprintf(t, "ora $%0.2x,s [$%0.6x]", op8, decode(OPTYPE_SR, op8)); break;
case 0x04: sprintf(t, "tsb $%0.2x [$%0.6x]", op8, decode(OPTYPE_DP, op8)); break;
case 0x05: sprintf(t, "ora $%0.2x [$%0.6x]", op8, decode(OPTYPE_DP, op8)); break;
case 0x06: sprintf(t, "asl $%0.2x [$%0.6x]", op8, decode(OPTYPE_DP, op8)); break;
case 0x07: sprintf(t, "ora [$%0.2x] [$%0.6x]", op8, decode(OPTYPE_ILDP, op8)); break;
case 0x08: sprintf(t, "php "); break;
case 0x09: if(a8)sprintf(t, "ora #$%0.2x ", op8);
else sprintf(t, "ora #$%0.4x ", op16); break;
case 0x0a: sprintf(t, "asl a "); break;
case 0x0b: sprintf(t, "phd "); break;
case 0x0c: sprintf(t, "tsb $%0.4x [$%0.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0x0d: sprintf(t, "ora $%0.4x [$%0.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0x0e: sprintf(t, "asl $%0.4x [$%0.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0x0f: sprintf(t, "ora $%0.6x [$%0.6x]", op24, decode(OPTYPE_LONG, op24)); break;
case 0x10: sprintf(t, "bpl $%0.4x [$%0.6x]", uint16(decode(OPTYPE_RELB, op8)), decode(OPTYPE_RELB, op8)); break;
case 0x11: sprintf(t, "ora ($%0.2x),y [$%0.6x]", op8, decode(OPTYPE_IDPY, op8)); break;
case 0x12: sprintf(t, "ora ($%0.2x) [$%0.6x]", op8, decode(OPTYPE_IDP, op8)); break;
case 0x13: sprintf(t, "ora ($%0.2x,s),y [$%0.6x]", op8, decode(OPTYPE_ISRY, op8)); break;
case 0x14: sprintf(t, "trb $%0.2x [$%0.6x]", op8, decode(OPTYPE_DP, op8)); break;
case 0x15: sprintf(t, "ora $%0.2x,x [$%0.6x]", op8, decode(OPTYPE_DPX, op8)); break;
case 0x16: sprintf(t, "asl $%0.2x,x [$%0.6x]", op8, decode(OPTYPE_DPX, op8)); break;
case 0x17: sprintf(t, "ora [$%0.2x],y [$%0.6x]", op8, decode(OPTYPE_ILDPY, op8)); break;
case 0x18: sprintf(t, "clc "); break;
case 0x19: sprintf(t, "ora $%0.4x,y [$%0.6x]", op16, decode(OPTYPE_ADDRY, op16)); break;
case 0x1a: sprintf(t, "inc "); break;
case 0x1b: sprintf(t, "tcs "); break;
case 0x1c: sprintf(t, "trb $%0.4x [$%0.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0x1d: sprintf(t, "ora $%0.4x,x [$%0.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
case 0x1e: sprintf(t, "asl $%0.4x,x [$%0.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
case 0x1f: sprintf(t, "ora $%0.6x,x [$%0.6x]", op24, decode(OPTYPE_LONGX, op24)); break;
case 0x20: sprintf(t, "jsr $%0.4x [$%0.6x]", op16, decode(OPTYPE_ADDR_PC, op16)); break;
case 0x21: sprintf(t, "and ($%0.2x,x) [$%0.6x]", op8, decode(OPTYPE_IDPX, op8)); break;
case 0x22: sprintf(t, "jsl $%0.6x [$%0.6x]", op24, decode(OPTYPE_LONG, op24)); break;
case 0x23: sprintf(t, "and $%0.2x,s [$%0.6x]", op8, decode(OPTYPE_SR, op8)); break;
case 0x24: sprintf(t, "bit $%0.2x [$%0.6x]", op8, decode(OPTYPE_DP, op8)); break;
case 0x25: sprintf(t, "and $%0.2x [$%0.6x]", op8, decode(OPTYPE_DP, op8)); break;
case 0x26: sprintf(t, "rol $%0.2x [$%0.6x]", op8, decode(OPTYPE_DP, op8)); break;
case 0x27: sprintf(t, "and [$%0.2x] [$%0.6x]", op8, decode(OPTYPE_ILDP, op8)); break;
case 0x28: sprintf(t, "plp "); break;
case 0x29: if(a8)sprintf(t, "and #$%0.2x ", op8);
else sprintf(t, "and #$%0.4x ", op16); break;
case 0x2a: sprintf(t, "rol a "); break;
case 0x2b: sprintf(t, "pld "); break;
case 0x2c: sprintf(t, "bit $%0.4x [$%0.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0x2d: sprintf(t, "and $%0.4x [$%0.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0x2e: sprintf(t, "rol $%0.4x [$%0.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0x2f: sprintf(t, "and $%0.6x [$%0.6x]", op24, decode(OPTYPE_LONG, op24)); break;
case 0x30: sprintf(t, "bmi $%0.4x [$%0.6x]", uint16(decode(OPTYPE_RELB, op8)), decode(OPTYPE_RELB, op8)); break;
case 0x31: sprintf(t, "and ($%0.2x),y [$%0.6x]", op8, decode(OPTYPE_IDPY, op8)); break;
case 0x32: sprintf(t, "and ($%0.2x) [$%0.6x]", op8, decode(OPTYPE_IDP, op8)); break;
case 0x33: sprintf(t, "and ($%0.2x,s),y [$%0.6x]", op8, decode(OPTYPE_ISRY, op8)); break;
case 0x34: sprintf(t, "bit $%0.2x,x [$%0.6x]", op8, decode(OPTYPE_DPX, op8)); break;
case 0x35: sprintf(t, "and $%0.2x,x [$%0.6x]", op8, decode(OPTYPE_DPX, op8)); break;
case 0x36: sprintf(t, "rol $%0.2x,x [$%0.6x]", op8, decode(OPTYPE_DPX, op8)); break;
case 0x37: sprintf(t, "and [$%0.2x],y [$%0.6x]", op8, decode(OPTYPE_ILDPY, op8)); break;
case 0x38: sprintf(t, "sec "); break;
case 0x39: sprintf(t, "and $%0.4x,y [$%0.6x]", op16, decode(OPTYPE_ADDRY, op16)); break;
case 0x3a: sprintf(t, "dec "); break;
case 0x3b: sprintf(t, "tsc "); break;
case 0x3c: sprintf(t, "bit $%0.4x,x [$%0.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
case 0x3d: sprintf(t, "and $%0.4x,x [$%0.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
case 0x3e: sprintf(t, "rol $%0.4x,x [$%0.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
case 0x3f: sprintf(t, "and $%0.6x,x [$%0.6x]", op24, decode(OPTYPE_LONGX, op24)); break;
case 0x40: sprintf(t, "rti "); break;
case 0x41: sprintf(t, "eor ($%0.2x,x) [$%0.6x]", op8, decode(OPTYPE_IDPX, op8)); break;
case 0x42: sprintf(t, "wdm "); break;
case 0x43: sprintf(t, "eor $%0.2x,s [$%0.6x]", op8, decode(OPTYPE_SR, op8)); break;
case 0x44: sprintf(t, "mvp $%0.2x,$%0.2x ", op1, op8); break;
case 0x45: sprintf(t, "eor $%0.2x [$%0.6x]", op8, decode(OPTYPE_DP, op8)); break;
case 0x46: sprintf(t, "lsr $%0.2x [$%0.6x]", op8, decode(OPTYPE_DP, op8)); break;
case 0x47: sprintf(t, "eor [$%0.2x] [$%0.6x]", op8, decode(OPTYPE_ILDP, op8)); break;
case 0x48: sprintf(t, "pha "); break;
case 0x49: if(a8)sprintf(t, "eor #$%0.2x ", op8);
else sprintf(t, "eor #$%0.4x ", op16); break;
case 0x4a: sprintf(t, "lsr a "); break;
case 0x4b: sprintf(t, "phk "); break;
case 0x4c: sprintf(t, "jmp $%0.4x [$%0.6x]", op16, decode(OPTYPE_ADDR_PC, op16)); break;
case 0x4d: sprintf(t, "eor $%0.4x [$%0.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0x4e: sprintf(t, "lsr $%0.4x [$%0.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0x4f: sprintf(t, "eor $%0.6x [$%0.6x]", op24, decode(OPTYPE_LONG, op24)); break;
case 0x50: sprintf(t, "bvc $%0.4x [$%0.6x]", uint16(decode(OPTYPE_RELB, op8)), decode(OPTYPE_RELB, op8)); break;
case 0x51: sprintf(t, "eor ($%0.2x),y [$%0.6x]", op8, decode(OPTYPE_IDPY, op8)); break;
case 0x52: sprintf(t, "eor ($%0.2x) [$%0.6x]", op8, decode(OPTYPE_IDP, op8)); break;
case 0x53: sprintf(t, "eor ($%0.2x,s),y [$%0.6x]", op8, decode(OPTYPE_ISRY, op8)); break;
case 0x54: sprintf(t, "mvn $%0.2x,$%0.2x ", op1, op8); break;
case 0x55: sprintf(t, "eor $%0.2x,x [$%0.6x]", op8, decode(OPTYPE_DPX, op8)); break;
case 0x56: sprintf(t, "lsr $%0.2x,x [$%0.6x]", op8, decode(OPTYPE_DPX, op8)); break;
case 0x57: sprintf(t, "eor [$%0.2x],y [$%0.6x]", op8, decode(OPTYPE_ILDPY, op8)); break;
case 0x58: sprintf(t, "cli "); break;
case 0x59: sprintf(t, "eor $%0.4x,y [$%0.6x]", op16, decode(OPTYPE_ADDRY, op16)); break;
case 0x5a: sprintf(t, "phy "); break;
case 0x5b: sprintf(t, "tcd "); break;
case 0x5c: sprintf(t, "jml $%0.6x [$%0.6x]", op24, decode(OPTYPE_LONG, op24)); break;
case 0x5d: sprintf(t, "eor $%0.4x,x [$%0.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
case 0x5e: sprintf(t, "lsr $%0.4x,x [$%0.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
case 0x5f: sprintf(t, "eor $%0.6x,x [$%0.6x]", op24, decode(OPTYPE_LONGX, op24)); break;
case 0x60: sprintf(t, "rts "); break;
case 0x61: sprintf(t, "adc ($%0.2x,x) [$%0.6x]", op8, decode(OPTYPE_IDPX, op8)); break;
case 0x62: sprintf(t, "per $%0.4x [$%0.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0x63: sprintf(t, "adc $%0.2x,s [$%0.6x]", op8, decode(OPTYPE_SR, op8)); break;
case 0x64: sprintf(t, "stz $%0.2x [$%0.6x]", op8, decode(OPTYPE_DP, op8)); break;
case 0x65: sprintf(t, "adc $%0.2x [$%0.6x]", op8, decode(OPTYPE_DP, op8)); break;
case 0x66: sprintf(t, "ror $%0.2x [$%0.6x]", op8, decode(OPTYPE_DP, op8)); break;
case 0x67: sprintf(t, "adc [$%0.2x] [$%0.6x]", op8, decode(OPTYPE_ILDP, op8)); break;
case 0x68: sprintf(t, "pla "); break;
case 0x69: if(a8)sprintf(t, "adc #$%0.2x ", op8);
else sprintf(t, "adc #$%0.4x ", op16); break;
case 0x6a: sprintf(t, "ror a "); break;
case 0x6b: sprintf(t, "rtl "); break;
case 0x6c: sprintf(t, "jmp ($%0.4x) [$%0.6x]", op16, decode(OPTYPE_IADDR_PC, op16)); break;
case 0x6d: sprintf(t, "adc $%0.4x [$%0.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0x6e: sprintf(t, "ror $%0.4x [$%0.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0x6f: sprintf(t, "adc $%0.6x [$%0.6x]", op24, decode(OPTYPE_LONG, op24)); break;
case 0x70: sprintf(t, "bvs $%0.4x [$%0.6x]", uint16(decode(OPTYPE_RELB, op8)), decode(OPTYPE_RELB, op8)); break;
case 0x71: sprintf(t, "adc ($%0.2x),y [$%0.6x]", op8, decode(OPTYPE_IDPY, op8)); break;
case 0x72: sprintf(t, "adc ($%0.2x) [$%0.6x]", op8, decode(OPTYPE_IDP, op8)); break;
case 0x73: sprintf(t, "adc ($%0.2x,s),y [$%0.6x]", op8, decode(OPTYPE_ISRY, op8)); break;
case 0x74: sprintf(t, "stz $%0.2x,x [$%0.6x]", op8, decode(OPTYPE_DPX, op8)); break;
case 0x75: sprintf(t, "adc $%0.2x,x [$%0.6x]", op8, decode(OPTYPE_DPX, op8)); break;
case 0x76: sprintf(t, "ror $%0.2x,x [$%0.6x]", op8, decode(OPTYPE_DPX, op8)); break;
case 0x77: sprintf(t, "adc [$%0.2x],y [$%0.6x]", op8, decode(OPTYPE_ILDPY, op8)); break;
case 0x78: sprintf(t, "sei "); break;
case 0x79: sprintf(t, "adc $%0.4x,y [$%0.6x]", op16, decode(OPTYPE_ADDRY, op16)); break;
case 0x7a: sprintf(t, "ply "); break;
case 0x7b: sprintf(t, "tdc "); break;
case 0x7c: sprintf(t, "jmp ($%0.4x,x) [$%0.6x]", op16, decode(OPTYPE_IADDRX, op16)); break;
case 0x7d: sprintf(t, "adc $%0.4x,x [$%0.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
case 0x7e: sprintf(t, "ror $%0.4x,x [$%0.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
case 0x7f: sprintf(t, "adc $%0.6x,x [$%0.6x]", op24, decode(OPTYPE_LONGX, op24)); break;
case 0x80: sprintf(t, "bra $%0.4x [$%0.6x]", uint16(decode(OPTYPE_RELB, op8)), decode(OPTYPE_RELB, op8)); break;
case 0x81: sprintf(t, "sta ($%0.2x,x) [$%0.6x]", op8, decode(OPTYPE_IDPX, op8)); break;
case 0x82: sprintf(t, "brl $%0.4x [$%0.6x]", uint16(decode(OPTYPE_RELW, op16)), decode(OPTYPE_RELW, op16)); break;
case 0x83: sprintf(t, "sta $%0.2x,s [$%0.6x]", op8, decode(OPTYPE_SR, op8)); break;
case 0x84: sprintf(t, "sty $%0.2x [$%0.6x]", op8, decode(OPTYPE_DP, op8)); break;
case 0x85: sprintf(t, "sta $%0.2x [$%0.6x]", op8, decode(OPTYPE_DP, op8)); break;
case 0x86: sprintf(t, "stx $%0.2x [$%0.6x]", op8, decode(OPTYPE_DP, op8)); break;
case 0x87: sprintf(t, "sta [$%0.2x] [$%0.6x]", op8, decode(OPTYPE_ILDP, op8)); break;
case 0x88: sprintf(t, "dey "); break;
case 0x89: if(a8)sprintf(t, "bit #$%0.2x ", op8);
else sprintf(t, "bit #$%0.4x ", op16); break;
case 0x8a: sprintf(t, "txa "); break;
case 0x8b: sprintf(t, "phb "); break;
case 0x8c: sprintf(t, "sty $%0.4x [$%0.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0x8d: sprintf(t, "sta $%0.4x [$%0.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0x8e: sprintf(t, "stx $%0.4x [$%0.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0x8f: sprintf(t, "sta $%0.6x [$%0.6x]", op24, decode(OPTYPE_LONG, op24)); break;
case 0x90: sprintf(t, "bcc $%0.4x [$%0.6x]", uint16(decode(OPTYPE_RELB, op8)), decode(OPTYPE_RELB, op8)); break;
case 0x91: sprintf(t, "sta ($%0.2x),y [$%0.6x]", op8, decode(OPTYPE_IDPY, op8)); break;
case 0x92: sprintf(t, "sta ($%0.2x) [$%0.6x]", op8, decode(OPTYPE_IDP, op8)); break;
case 0x93: sprintf(t, "sta ($%0.2x,s),y [$%0.6x]", op8, decode(OPTYPE_ISRY, op8)); break;
case 0x94: sprintf(t, "sty $%0.2x,x [$%0.6x]", op8, decode(OPTYPE_DPX, op8)); break;
case 0x95: sprintf(t, "sta $%0.2x,x [$%0.6x]", op8, decode(OPTYPE_DPX, op8)); break;
case 0x96: sprintf(t, "stx $%0.2x,y [$%0.6x]", op8, decode(OPTYPE_DPY, op8)); break;
case 0x97: sprintf(t, "sta [$%0.2x],y [$%0.6x]", op8, decode(OPTYPE_ILDPY, op8)); break;
case 0x98: sprintf(t, "tya "); break;
case 0x99: sprintf(t, "sta $%0.4x,y [$%0.6x]", op16, decode(OPTYPE_ADDRY, op16)); break;
case 0x9a: sprintf(t, "txs "); break;
case 0x9b: sprintf(t, "txy "); break;
case 0x9c: sprintf(t, "stz $%0.4x [$%0.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0x9d: sprintf(t, "sta $%0.4x,x [$%0.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
case 0x9e: sprintf(t, "stz $%0.4x,x [$%0.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
case 0x9f: sprintf(t, "sta $%0.6x,x [$%0.6x]", op24, decode(OPTYPE_LONGX, op24)); break;
case 0xa0: if(x8)sprintf(t, "ldy #$%0.2x ", op8);
else sprintf(t, "ldy #$%0.4x ", op16); break;
case 0xa1: sprintf(t, "lda ($%0.2x,x) [$%0.6x]", op8, decode(OPTYPE_IDPX, op8)); break;
case 0xa2: if(x8)sprintf(t, "ldx #$%0.2x ", op8);
else sprintf(t, "ldx #$%0.4x ", op16); break;
case 0xa3: sprintf(t, "lda $%0.2x,s [$%0.6x]", op8, decode(OPTYPE_SR, op8)); break;
case 0xa4: sprintf(t, "ldy $%0.2x [$%0.6x]", op8, decode(OPTYPE_DP, op8)); break;
case 0xa5: sprintf(t, "lda $%0.2x [$%0.6x]", op8, decode(OPTYPE_DP, op8)); break;
case 0xa6: sprintf(t, "ldx $%0.2x [$%0.6x]", op8, decode(OPTYPE_DP, op8)); break;
case 0xa7: sprintf(t, "lda [$%0.2x] [$%0.6x]", op8, decode(OPTYPE_ILDP, op8)); break;
case 0xa8: sprintf(t, "tay "); break;
case 0xa9: if(a8)sprintf(t, "lda #$%0.2x ", op8);
else sprintf(t, "lda #$%0.4x ", op16); break;
case 0xaa: sprintf(t, "tax "); break;
case 0xab: sprintf(t, "plb "); break;
case 0xac: sprintf(t, "ldy $%0.4x [$%0.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0xad: sprintf(t, "lda $%0.4x [$%0.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0xae: sprintf(t, "ldx $%0.4x [$%0.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0xaf: sprintf(t, "lda $%0.6x [$%0.6x]", op24, decode(OPTYPE_LONG, op24)); break;
case 0xb0: sprintf(t, "bcs $%0.4x [$%0.6x]", uint16(decode(OPTYPE_RELB, op8)), decode(OPTYPE_RELB, op8)); break;
case 0xb1: sprintf(t, "lda ($%0.2x),y [$%0.6x]", op8, decode(OPTYPE_IDPY, op8)); break;
case 0xb2: sprintf(t, "lda ($%0.2x) [$%0.6x]", op8, decode(OPTYPE_IDP, op8)); break;
case 0xb3: sprintf(t, "lda ($%0.2x,s),y [$%0.6x]", op8, decode(OPTYPE_ISRY, op8)); break;
case 0xb4: sprintf(t, "ldy $%0.2x,x [$%0.6x]", op8, decode(OPTYPE_DPX, op8)); break;
case 0xb5: sprintf(t, "lda $%0.2x,x [$%0.6x]", op8, decode(OPTYPE_DPX, op8)); break;
case 0xb6: sprintf(t, "ldx $%0.2x,y [$%0.6x]", op8, decode(OPTYPE_DPY, op8)); break;
case 0xb7: sprintf(t, "lda [$%0.2x],y [$%0.6x]", op8, decode(OPTYPE_ILDPY, op8)); break;
case 0xb8: sprintf(t, "clv "); break;
case 0xb9: sprintf(t, "lda $%0.4x,y [$%0.6x]", op16, decode(OPTYPE_ADDRY, op16)); break;
case 0xba: sprintf(t, "tsx "); break;
case 0xbb: sprintf(t, "tyx "); break;
case 0xbc: sprintf(t, "ldy $%0.4x,x [$%0.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
case 0xbd: sprintf(t, "lda $%0.4x,x [$%0.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
case 0xbe: sprintf(t, "ldx $%0.4x,y [$%0.6x]", op16, decode(OPTYPE_ADDRY, op16)); break;
case 0xbf: sprintf(t, "lda $%0.6x,x [$%0.6x]", op24, decode(OPTYPE_LONGX, op24)); break;
case 0xc0: if(x8)sprintf(t, "cpy #$%0.2x ", op8);
else sprintf(t, "cpy #$%0.4x ", op16); break;
case 0xc1: sprintf(t, "cmp ($%0.2x,x) [$%0.6x]", op8, decode(OPTYPE_IDPX, op8)); break;
case 0xc2: sprintf(t, "rep #$%0.2x ", op8); break;
case 0xc3: sprintf(t, "cmp $%0.2x,s [$%0.6x]", op8, decode(OPTYPE_SR, op8)); break;
case 0xc4: sprintf(t, "cpy $%0.2x [$%0.6x]", op8, decode(OPTYPE_DP, op8)); break;
case 0xc5: sprintf(t, "cmp $%0.2x [$%0.6x]", op8, decode(OPTYPE_DP, op8)); break;
case 0xc6: sprintf(t, "dec $%0.2x [$%0.6x]", op8, decode(OPTYPE_DP, op8)); break;
case 0xc7: sprintf(t, "cmp [$%0.2x] [$%0.6x]", op8, decode(OPTYPE_ILDP, op8)); break;
case 0xc8: sprintf(t, "iny "); break;
case 0xc9: if(a8)sprintf(t, "cmp #$%0.2x ", op8);
else sprintf(t, "cmp #$%0.4x ", op16); break;
case 0xca: sprintf(t, "dex "); break;
case 0xcb: sprintf(t, "wai "); break;
case 0xcc: sprintf(t, "cpy $%0.4x [$%0.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0xcd: sprintf(t, "cmp $%0.4x [$%0.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0xce: sprintf(t, "dec $%0.4x [$%0.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0xcf: sprintf(t, "cmp $%0.6x [$%0.6x]", op24, decode(OPTYPE_LONG, op24)); break;
case 0xd0: sprintf(t, "bne $%0.4x [$%0.6x]", uint16(decode(OPTYPE_RELB, op8)), decode(OPTYPE_RELB, op8)); break;
case 0xd1: sprintf(t, "cmp ($%0.2x),y [$%0.6x]", op8, decode(OPTYPE_IDPY, op8)); break;
case 0xd2: sprintf(t, "cmp ($%0.2x) [$%0.6x]", op8, decode(OPTYPE_IDP, op8)); break;
case 0xd3: sprintf(t, "cmp ($%0.2x,s),y [$%0.6x]", op8, decode(OPTYPE_ISRY, op8)); break;
case 0xd4: sprintf(t, "pei ($%0.2x) [$%0.6x]", op8, decode(OPTYPE_IDP, op8)); break;
case 0xd5: sprintf(t, "cmp $%0.2x,x [$%0.6x]", op8, decode(OPTYPE_DPX, op8)); break;
case 0xd6: sprintf(t, "dec $%0.2x,x [$%0.6x]", op8, decode(OPTYPE_DPX, op8)); break;
case 0xd7: sprintf(t, "cmp [$%0.2x],y [$%0.6x]", op8, decode(OPTYPE_ILDPY, op8)); break;
case 0xd8: sprintf(t, "cld "); break;
case 0xd9: sprintf(t, "cmp $%0.4x,y [$%0.6x]", op16, decode(OPTYPE_ADDRY, op16)); break;
case 0xda: sprintf(t, "phx "); break;
case 0xdb: sprintf(t, "stp "); break;
case 0xdc: sprintf(t, "jmp [$%0.4x] [$%0.6x]", op16, decode(OPTYPE_ILADDR, op16)); break;
case 0xdd: sprintf(t, "cmp $%0.4x,x [$%0.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
case 0xde: sprintf(t, "dec $%0.4x,x [$%0.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
case 0xdf: sprintf(t, "cmp $%0.6x,x [$%0.6x]", op24, decode(OPTYPE_LONGX, op24)); break;
case 0xe0: if(x8)sprintf(t, "cpx #$%0.2x ", op8);
else sprintf(t, "cpx #$%0.4x ", op16); break;
case 0xe1: sprintf(t, "sbc ($%0.2x,x) [$%0.6x]", op8, decode(OPTYPE_IDPX, op8)); break;
case 0xe2: sprintf(t, "sep #$%0.2x ", op8); break;
case 0xe3: sprintf(t, "sbc $%0.2x,s [$%0.6x]", op8, decode(OPTYPE_SR, op8)); break;
case 0xe4: sprintf(t, "cpx $%0.2x [$%0.6x]", op8, decode(OPTYPE_DP, op8)); break;
case 0xe5: sprintf(t, "sbc $%0.2x [$%0.6x]", op8, decode(OPTYPE_DP, op8)); break;
case 0xe6: sprintf(t, "inc $%0.2x [$%0.6x]", op8, decode(OPTYPE_DP, op8)); break;
case 0xe7: sprintf(t, "sbc [$%0.2x] [$%0.6x]", op8, decode(OPTYPE_ILDP, op8)); break;
case 0xe8: sprintf(t, "inx "); break;
case 0xe9: if(a8)sprintf(t, "sbc #$%0.2x ", op8);
else sprintf(t, "sbc #$%0.4x ", op16); break;
case 0xea: sprintf(t, "nop "); break;
case 0xeb: sprintf(t, "xba "); break;
case 0xec: sprintf(t, "cpx $%0.4x [$%0.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0xed: sprintf(t, "sbc $%0.4x [$%0.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0xee: sprintf(t, "inc $%0.4x [$%0.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0xef: sprintf(t, "sbc $%0.6x [$%0.6x]", op24, decode(OPTYPE_LONG, op24)); break;
case 0xf0: sprintf(t, "beq $%0.4x [$%0.6x]", uint16(decode(OPTYPE_RELB, op8)), decode(OPTYPE_RELB, op8)); break;
case 0xf1: sprintf(t, "sbc ($%0.2x),y [$%0.6x]", op8, decode(OPTYPE_IDPY, op8)); break;
case 0xf2: sprintf(t, "sbc ($%0.2x) [$%0.6x]", op8, decode(OPTYPE_IDP, op8)); break;
case 0xf3: sprintf(t, "sbc ($%0.2x,s),y [$%0.6x]", op8, decode(OPTYPE_ISRY, op8)); break;
case 0xf4: sprintf(t, "pea $%0.4x [$%0.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0xf5: sprintf(t, "sbc $%0.2x,x [$%0.6x]", op8, decode(OPTYPE_DPX, op8)); break;
case 0xf6: sprintf(t, "inc $%0.2x,x [$%0.6x]", op8, decode(OPTYPE_DPX, op8)); break;
case 0xf7: sprintf(t, "sbc [$%0.2x],y [$%0.6x]", op8, decode(OPTYPE_ILDPY, op8)); break;
case 0xf8: sprintf(t, "sed "); break;
case 0xf9: sprintf(t, "sbc $%0.4x,y [$%0.6x]", op16, decode(OPTYPE_ADDRY, op16)); break;
case 0xfa: sprintf(t, "plx "); break;
case 0xfb: sprintf(t, "xce "); break;
case 0xfc: sprintf(t, "jsr ($%0.4x,x) [$%0.6x]", op16, decode(OPTYPE_IADDRX, op16)); break;
case 0xfd: sprintf(t, "sbc $%0.4x,x [$%0.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
case 0xfe: sprintf(t, "inc $%0.4x,x [$%0.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
case 0xff: sprintf(t, "sbc $%0.6x,x [$%0.6x]", op24, decode(OPTYPE_LONGX, op24)); break;
case 0x00: sprintf(t, "brk #$%.2x ", op8); break;
case 0x01: sprintf(t, "ora ($%.2x,x) [$%.6x]", op8, decode(OPTYPE_IDPX, op8)); break;
case 0x02: sprintf(t, "cop #$%.2x ", op8); break;
case 0x03: sprintf(t, "ora $%.2x,s [$%.6x]", op8, decode(OPTYPE_SR, op8)); break;
case 0x04: sprintf(t, "tsb $%.2x [$%.6x]", op8, decode(OPTYPE_DP, op8)); break;
case 0x05: sprintf(t, "ora $%.2x [$%.6x]", op8, decode(OPTYPE_DP, op8)); break;
case 0x06: sprintf(t, "asl $%.2x [$%.6x]", op8, decode(OPTYPE_DP, op8)); break;
case 0x07: sprintf(t, "ora [$%.2x] [$%.6x]", op8, decode(OPTYPE_ILDP, op8)); break;
case 0x08: sprintf(t, "php "); break;
case 0x09: if(a8)sprintf(t, "ora #$%.2x ", op8);
else sprintf(t, "ora #$%.4x ", op16); break;
case 0x0a: sprintf(t, "asl a "); break;
case 0x0b: sprintf(t, "phd "); break;
case 0x0c: sprintf(t, "tsb $%.4x [$%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0x0d: sprintf(t, "ora $%.4x [$%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0x0e: sprintf(t, "asl $%.4x [$%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0x0f: sprintf(t, "ora $%.6x [$%.6x]", op24, decode(OPTYPE_LONG, op24)); break;
case 0x10: sprintf(t, "bpl $%.4x [$%.6x]", uint16(decode(OPTYPE_RELB, op8)), decode(OPTYPE_RELB, op8)); break;
case 0x11: sprintf(t, "ora ($%.2x),y [$%.6x]", op8, decode(OPTYPE_IDPY, op8)); break;
case 0x12: sprintf(t, "ora ($%.2x) [$%.6x]", op8, decode(OPTYPE_IDP, op8)); break;
case 0x13: sprintf(t, "ora ($%.2x,s),y [$%.6x]", op8, decode(OPTYPE_ISRY, op8)); break;
case 0x14: sprintf(t, "trb $%.2x [$%.6x]", op8, decode(OPTYPE_DP, op8)); break;
case 0x15: sprintf(t, "ora $%.2x,x [$%.6x]", op8, decode(OPTYPE_DPX, op8)); break;
case 0x16: sprintf(t, "asl $%.2x,x [$%.6x]", op8, decode(OPTYPE_DPX, op8)); break;
case 0x17: sprintf(t, "ora [$%.2x],y [$%.6x]", op8, decode(OPTYPE_ILDPY, op8)); break;
case 0x18: sprintf(t, "clc "); break;
case 0x19: sprintf(t, "ora $%.4x,y [$%.6x]", op16, decode(OPTYPE_ADDRY, op16)); break;
case 0x1a: sprintf(t, "inc "); break;
case 0x1b: sprintf(t, "tcs "); break;
case 0x1c: sprintf(t, "trb $%.4x [$%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0x1d: sprintf(t, "ora $%.4x,x [$%.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
case 0x1e: sprintf(t, "asl $%.4x,x [$%.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
case 0x1f: sprintf(t, "ora $%.6x,x [$%.6x]", op24, decode(OPTYPE_LONGX, op24)); break;
case 0x20: sprintf(t, "jsr $%.4x [$%.6x]", op16, decode(OPTYPE_ADDR_PC, op16)); break;
case 0x21: sprintf(t, "and ($%.2x,x) [$%.6x]", op8, decode(OPTYPE_IDPX, op8)); break;
case 0x22: sprintf(t, "jsl $%.6x [$%.6x]", op24, decode(OPTYPE_LONG, op24)); break;
case 0x23: sprintf(t, "and $%.2x,s [$%.6x]", op8, decode(OPTYPE_SR, op8)); break;
case 0x24: sprintf(t, "bit $%.2x [$%.6x]", op8, decode(OPTYPE_DP, op8)); break;
case 0x25: sprintf(t, "and $%.2x [$%.6x]", op8, decode(OPTYPE_DP, op8)); break;
case 0x26: sprintf(t, "rol $%.2x [$%.6x]", op8, decode(OPTYPE_DP, op8)); break;
case 0x27: sprintf(t, "and [$%.2x] [$%.6x]", op8, decode(OPTYPE_ILDP, op8)); break;
case 0x28: sprintf(t, "plp "); break;
case 0x29: if(a8)sprintf(t, "and #$%.2x ", op8);
else sprintf(t, "and #$%.4x ", op16); break;
case 0x2a: sprintf(t, "rol a "); break;
case 0x2b: sprintf(t, "pld "); break;
case 0x2c: sprintf(t, "bit $%.4x [$%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0x2d: sprintf(t, "and $%.4x [$%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0x2e: sprintf(t, "rol $%.4x [$%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0x2f: sprintf(t, "and $%.6x [$%.6x]", op24, decode(OPTYPE_LONG, op24)); break;
case 0x30: sprintf(t, "bmi $%.4x [$%.6x]", uint16(decode(OPTYPE_RELB, op8)), decode(OPTYPE_RELB, op8)); break;
case 0x31: sprintf(t, "and ($%.2x),y [$%.6x]", op8, decode(OPTYPE_IDPY, op8)); break;
case 0x32: sprintf(t, "and ($%.2x) [$%.6x]", op8, decode(OPTYPE_IDP, op8)); break;
case 0x33: sprintf(t, "and ($%.2x,s),y [$%.6x]", op8, decode(OPTYPE_ISRY, op8)); break;
case 0x34: sprintf(t, "bit $%.2x,x [$%.6x]", op8, decode(OPTYPE_DPX, op8)); break;
case 0x35: sprintf(t, "and $%.2x,x [$%.6x]", op8, decode(OPTYPE_DPX, op8)); break;
case 0x36: sprintf(t, "rol $%.2x,x [$%.6x]", op8, decode(OPTYPE_DPX, op8)); break;
case 0x37: sprintf(t, "and [$%.2x],y [$%.6x]", op8, decode(OPTYPE_ILDPY, op8)); break;
case 0x38: sprintf(t, "sec "); break;
case 0x39: sprintf(t, "and $%.4x,y [$%.6x]", op16, decode(OPTYPE_ADDRY, op16)); break;
case 0x3a: sprintf(t, "dec "); break;
case 0x3b: sprintf(t, "tsc "); break;
case 0x3c: sprintf(t, "bit $%.4x,x [$%.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
case 0x3d: sprintf(t, "and $%.4x,x [$%.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
case 0x3e: sprintf(t, "rol $%.4x,x [$%.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
case 0x3f: sprintf(t, "and $%.6x,x [$%.6x]", op24, decode(OPTYPE_LONGX, op24)); break;
case 0x40: sprintf(t, "rti "); break;
case 0x41: sprintf(t, "eor ($%.2x,x) [$%.6x]", op8, decode(OPTYPE_IDPX, op8)); break;
case 0x42: sprintf(t, "wdm "); break;
case 0x43: sprintf(t, "eor $%.2x,s [$%.6x]", op8, decode(OPTYPE_SR, op8)); break;
case 0x44: sprintf(t, "mvp $%.2x,$%.2x ", op1, op8); break;
case 0x45: sprintf(t, "eor $%.2x [$%.6x]", op8, decode(OPTYPE_DP, op8)); break;
case 0x46: sprintf(t, "lsr $%.2x [$%.6x]", op8, decode(OPTYPE_DP, op8)); break;
case 0x47: sprintf(t, "eor [$%.2x] [$%.6x]", op8, decode(OPTYPE_ILDP, op8)); break;
case 0x48: sprintf(t, "pha "); break;
case 0x49: if(a8)sprintf(t, "eor #$%.2x ", op8);
else sprintf(t, "eor #$%.4x ", op16); break;
case 0x4a: sprintf(t, "lsr a "); break;
case 0x4b: sprintf(t, "phk "); break;
case 0x4c: sprintf(t, "jmp $%.4x [$%.6x]", op16, decode(OPTYPE_ADDR_PC, op16)); break;
case 0x4d: sprintf(t, "eor $%.4x [$%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0x4e: sprintf(t, "lsr $%.4x [$%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0x4f: sprintf(t, "eor $%.6x [$%.6x]", op24, decode(OPTYPE_LONG, op24)); break;
case 0x50: sprintf(t, "bvc $%.4x [$%.6x]", uint16(decode(OPTYPE_RELB, op8)), decode(OPTYPE_RELB, op8)); break;
case 0x51: sprintf(t, "eor ($%.2x),y [$%.6x]", op8, decode(OPTYPE_IDPY, op8)); break;
case 0x52: sprintf(t, "eor ($%.2x) [$%.6x]", op8, decode(OPTYPE_IDP, op8)); break;
case 0x53: sprintf(t, "eor ($%.2x,s),y [$%.6x]", op8, decode(OPTYPE_ISRY, op8)); break;
case 0x54: sprintf(t, "mvn $%.2x,$%.2x ", op1, op8); break;
case 0x55: sprintf(t, "eor $%.2x,x [$%.6x]", op8, decode(OPTYPE_DPX, op8)); break;
case 0x56: sprintf(t, "lsr $%.2x,x [$%.6x]", op8, decode(OPTYPE_DPX, op8)); break;
case 0x57: sprintf(t, "eor [$%.2x],y [$%.6x]", op8, decode(OPTYPE_ILDPY, op8)); break;
case 0x58: sprintf(t, "cli "); break;
case 0x59: sprintf(t, "eor $%.4x,y [$%.6x]", op16, decode(OPTYPE_ADDRY, op16)); break;
case 0x5a: sprintf(t, "phy "); break;
case 0x5b: sprintf(t, "tcd "); break;
case 0x5c: sprintf(t, "jml $%.6x [$%.6x]", op24, decode(OPTYPE_LONG, op24)); break;
case 0x5d: sprintf(t, "eor $%.4x,x [$%.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
case 0x5e: sprintf(t, "lsr $%.4x,x [$%.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
case 0x5f: sprintf(t, "eor $%.6x,x [$%.6x]", op24, decode(OPTYPE_LONGX, op24)); break;
case 0x60: sprintf(t, "rts "); break;
case 0x61: sprintf(t, "adc ($%.2x,x) [$%.6x]", op8, decode(OPTYPE_IDPX, op8)); break;
case 0x62: sprintf(t, "per $%.4x [$%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0x63: sprintf(t, "adc $%.2x,s [$%.6x]", op8, decode(OPTYPE_SR, op8)); break;
case 0x64: sprintf(t, "stz $%.2x [$%.6x]", op8, decode(OPTYPE_DP, op8)); break;
case 0x65: sprintf(t, "adc $%.2x [$%.6x]", op8, decode(OPTYPE_DP, op8)); break;
case 0x66: sprintf(t, "ror $%.2x [$%.6x]", op8, decode(OPTYPE_DP, op8)); break;
case 0x67: sprintf(t, "adc [$%.2x] [$%.6x]", op8, decode(OPTYPE_ILDP, op8)); break;
case 0x68: sprintf(t, "pla "); break;
case 0x69: if(a8)sprintf(t, "adc #$%.2x ", op8);
else sprintf(t, "adc #$%.4x ", op16); break;
case 0x6a: sprintf(t, "ror a "); break;
case 0x6b: sprintf(t, "rtl "); break;
case 0x6c: sprintf(t, "jmp ($%.4x) [$%.6x]", op16, decode(OPTYPE_IADDR_PC, op16)); break;
case 0x6d: sprintf(t, "adc $%.4x [$%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0x6e: sprintf(t, "ror $%.4x [$%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0x6f: sprintf(t, "adc $%.6x [$%.6x]", op24, decode(OPTYPE_LONG, op24)); break;
case 0x70: sprintf(t, "bvs $%.4x [$%.6x]", uint16(decode(OPTYPE_RELB, op8)), decode(OPTYPE_RELB, op8)); break;
case 0x71: sprintf(t, "adc ($%.2x),y [$%.6x]", op8, decode(OPTYPE_IDPY, op8)); break;
case 0x72: sprintf(t, "adc ($%.2x) [$%.6x]", op8, decode(OPTYPE_IDP, op8)); break;
case 0x73: sprintf(t, "adc ($%.2x,s),y [$%.6x]", op8, decode(OPTYPE_ISRY, op8)); break;
case 0x74: sprintf(t, "stz $%.2x,x [$%.6x]", op8, decode(OPTYPE_DPX, op8)); break;
case 0x75: sprintf(t, "adc $%.2x,x [$%.6x]", op8, decode(OPTYPE_DPX, op8)); break;
case 0x76: sprintf(t, "ror $%.2x,x [$%.6x]", op8, decode(OPTYPE_DPX, op8)); break;
case 0x77: sprintf(t, "adc [$%.2x],y [$%.6x]", op8, decode(OPTYPE_ILDPY, op8)); break;
case 0x78: sprintf(t, "sei "); break;
case 0x79: sprintf(t, "adc $%.4x,y [$%.6x]", op16, decode(OPTYPE_ADDRY, op16)); break;
case 0x7a: sprintf(t, "ply "); break;
case 0x7b: sprintf(t, "tdc "); break;
case 0x7c: sprintf(t, "jmp ($%.4x,x) [$%.6x]", op16, decode(OPTYPE_IADDRX, op16)); break;
case 0x7d: sprintf(t, "adc $%.4x,x [$%.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
case 0x7e: sprintf(t, "ror $%.4x,x [$%.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
case 0x7f: sprintf(t, "adc $%.6x,x [$%.6x]", op24, decode(OPTYPE_LONGX, op24)); break;
case 0x80: sprintf(t, "bra $%.4x [$%.6x]", uint16(decode(OPTYPE_RELB, op8)), decode(OPTYPE_RELB, op8)); break;
case 0x81: sprintf(t, "sta ($%.2x,x) [$%.6x]", op8, decode(OPTYPE_IDPX, op8)); break;
case 0x82: sprintf(t, "brl $%.4x [$%.6x]", uint16(decode(OPTYPE_RELW, op16)), decode(OPTYPE_RELW, op16)); break;
case 0x83: sprintf(t, "sta $%.2x,s [$%.6x]", op8, decode(OPTYPE_SR, op8)); break;
case 0x84: sprintf(t, "sty $%.2x [$%.6x]", op8, decode(OPTYPE_DP, op8)); break;
case 0x85: sprintf(t, "sta $%.2x [$%.6x]", op8, decode(OPTYPE_DP, op8)); break;
case 0x86: sprintf(t, "stx $%.2x [$%.6x]", op8, decode(OPTYPE_DP, op8)); break;
case 0x87: sprintf(t, "sta [$%.2x] [$%.6x]", op8, decode(OPTYPE_ILDP, op8)); break;
case 0x88: sprintf(t, "dey "); break;
case 0x89: if(a8)sprintf(t, "bit #$%.2x ", op8);
else sprintf(t, "bit #$%.4x ", op16); break;
case 0x8a: sprintf(t, "txa "); break;
case 0x8b: sprintf(t, "phb "); break;
case 0x8c: sprintf(t, "sty $%.4x [$%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0x8d: sprintf(t, "sta $%.4x [$%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0x8e: sprintf(t, "stx $%.4x [$%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0x8f: sprintf(t, "sta $%.6x [$%.6x]", op24, decode(OPTYPE_LONG, op24)); break;
case 0x90: sprintf(t, "bcc $%.4x [$%.6x]", uint16(decode(OPTYPE_RELB, op8)), decode(OPTYPE_RELB, op8)); break;
case 0x91: sprintf(t, "sta ($%.2x),y [$%.6x]", op8, decode(OPTYPE_IDPY, op8)); break;
case 0x92: sprintf(t, "sta ($%.2x) [$%.6x]", op8, decode(OPTYPE_IDP, op8)); break;
case 0x93: sprintf(t, "sta ($%.2x,s),y [$%.6x]", op8, decode(OPTYPE_ISRY, op8)); break;
case 0x94: sprintf(t, "sty $%.2x,x [$%.6x]", op8, decode(OPTYPE_DPX, op8)); break;
case 0x95: sprintf(t, "sta $%.2x,x [$%.6x]", op8, decode(OPTYPE_DPX, op8)); break;
case 0x96: sprintf(t, "stx $%.2x,y [$%.6x]", op8, decode(OPTYPE_DPY, op8)); break;
case 0x97: sprintf(t, "sta [$%.2x],y [$%.6x]", op8, decode(OPTYPE_ILDPY, op8)); break;
case 0x98: sprintf(t, "tya "); break;
case 0x99: sprintf(t, "sta $%.4x,y [$%.6x]", op16, decode(OPTYPE_ADDRY, op16)); break;
case 0x9a: sprintf(t, "txs "); break;
case 0x9b: sprintf(t, "txy "); break;
case 0x9c: sprintf(t, "stz $%.4x [$%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0x9d: sprintf(t, "sta $%.4x,x [$%.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
case 0x9e: sprintf(t, "stz $%.4x,x [$%.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
case 0x9f: sprintf(t, "sta $%.6x,x [$%.6x]", op24, decode(OPTYPE_LONGX, op24)); break;
case 0xa0: if(x8)sprintf(t, "ldy #$%.2x ", op8);
else sprintf(t, "ldy #$%.4x ", op16); break;
case 0xa1: sprintf(t, "lda ($%.2x,x) [$%.6x]", op8, decode(OPTYPE_IDPX, op8)); break;
case 0xa2: if(x8)sprintf(t, "ldx #$%.2x ", op8);
else sprintf(t, "ldx #$%.4x ", op16); break;
case 0xa3: sprintf(t, "lda $%.2x,s [$%.6x]", op8, decode(OPTYPE_SR, op8)); break;
case 0xa4: sprintf(t, "ldy $%.2x [$%.6x]", op8, decode(OPTYPE_DP, op8)); break;
case 0xa5: sprintf(t, "lda $%.2x [$%.6x]", op8, decode(OPTYPE_DP, op8)); break;
case 0xa6: sprintf(t, "ldx $%.2x [$%.6x]", op8, decode(OPTYPE_DP, op8)); break;
case 0xa7: sprintf(t, "lda [$%.2x] [$%.6x]", op8, decode(OPTYPE_ILDP, op8)); break;
case 0xa8: sprintf(t, "tay "); break;
case 0xa9: if(a8)sprintf(t, "lda #$%.2x ", op8);
else sprintf(t, "lda #$%.4x ", op16); break;
case 0xaa: sprintf(t, "tax "); break;
case 0xab: sprintf(t, "plb "); break;
case 0xac: sprintf(t, "ldy $%.4x [$%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0xad: sprintf(t, "lda $%.4x [$%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0xae: sprintf(t, "ldx $%.4x [$%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0xaf: sprintf(t, "lda $%.6x [$%.6x]", op24, decode(OPTYPE_LONG, op24)); break;
case 0xb0: sprintf(t, "bcs $%.4x [$%.6x]", uint16(decode(OPTYPE_RELB, op8)), decode(OPTYPE_RELB, op8)); break;
case 0xb1: sprintf(t, "lda ($%.2x),y [$%.6x]", op8, decode(OPTYPE_IDPY, op8)); break;
case 0xb2: sprintf(t, "lda ($%.2x) [$%.6x]", op8, decode(OPTYPE_IDP, op8)); break;
case 0xb3: sprintf(t, "lda ($%.2x,s),y [$%.6x]", op8, decode(OPTYPE_ISRY, op8)); break;
case 0xb4: sprintf(t, "ldy $%.2x,x [$%.6x]", op8, decode(OPTYPE_DPX, op8)); break;
case 0xb5: sprintf(t, "lda $%.2x,x [$%.6x]", op8, decode(OPTYPE_DPX, op8)); break;
case 0xb6: sprintf(t, "ldx $%.2x,y [$%.6x]", op8, decode(OPTYPE_DPY, op8)); break;
case 0xb7: sprintf(t, "lda [$%.2x],y [$%.6x]", op8, decode(OPTYPE_ILDPY, op8)); break;
case 0xb8: sprintf(t, "clv "); break;
case 0xb9: sprintf(t, "lda $%.4x,y [$%.6x]", op16, decode(OPTYPE_ADDRY, op16)); break;
case 0xba: sprintf(t, "tsx "); break;
case 0xbb: sprintf(t, "tyx "); break;
case 0xbc: sprintf(t, "ldy $%.4x,x [$%.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
case 0xbd: sprintf(t, "lda $%.4x,x [$%.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
case 0xbe: sprintf(t, "ldx $%.4x,y [$%.6x]", op16, decode(OPTYPE_ADDRY, op16)); break;
case 0xbf: sprintf(t, "lda $%.6x,x [$%.6x]", op24, decode(OPTYPE_LONGX, op24)); break;
case 0xc0: if(x8)sprintf(t, "cpy #$%.2x ", op8);
else sprintf(t, "cpy #$%.4x ", op16); break;
case 0xc1: sprintf(t, "cmp ($%.2x,x) [$%.6x]", op8, decode(OPTYPE_IDPX, op8)); break;
case 0xc2: sprintf(t, "rep #$%.2x ", op8); break;
case 0xc3: sprintf(t, "cmp $%.2x,s [$%.6x]", op8, decode(OPTYPE_SR, op8)); break;
case 0xc4: sprintf(t, "cpy $%.2x [$%.6x]", op8, decode(OPTYPE_DP, op8)); break;
case 0xc5: sprintf(t, "cmp $%.2x [$%.6x]", op8, decode(OPTYPE_DP, op8)); break;
case 0xc6: sprintf(t, "dec $%.2x [$%.6x]", op8, decode(OPTYPE_DP, op8)); break;
case 0xc7: sprintf(t, "cmp [$%.2x] [$%.6x]", op8, decode(OPTYPE_ILDP, op8)); break;
case 0xc8: sprintf(t, "iny "); break;
case 0xc9: if(a8)sprintf(t, "cmp #$%.2x ", op8);
else sprintf(t, "cmp #$%.4x ", op16); break;
case 0xca: sprintf(t, "dex "); break;
case 0xcb: sprintf(t, "wai "); break;
case 0xcc: sprintf(t, "cpy $%.4x [$%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0xcd: sprintf(t, "cmp $%.4x [$%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0xce: sprintf(t, "dec $%.4x [$%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0xcf: sprintf(t, "cmp $%.6x [$%.6x]", op24, decode(OPTYPE_LONG, op24)); break;
case 0xd0: sprintf(t, "bne $%.4x [$%.6x]", uint16(decode(OPTYPE_RELB, op8)), decode(OPTYPE_RELB, op8)); break;
case 0xd1: sprintf(t, "cmp ($%.2x),y [$%.6x]", op8, decode(OPTYPE_IDPY, op8)); break;
case 0xd2: sprintf(t, "cmp ($%.2x) [$%.6x]", op8, decode(OPTYPE_IDP, op8)); break;
case 0xd3: sprintf(t, "cmp ($%.2x,s),y [$%.6x]", op8, decode(OPTYPE_ISRY, op8)); break;
case 0xd4: sprintf(t, "pei ($%.2x) [$%.6x]", op8, decode(OPTYPE_IDP, op8)); break;
case 0xd5: sprintf(t, "cmp $%.2x,x [$%.6x]", op8, decode(OPTYPE_DPX, op8)); break;
case 0xd6: sprintf(t, "dec $%.2x,x [$%.6x]", op8, decode(OPTYPE_DPX, op8)); break;
case 0xd7: sprintf(t, "cmp [$%.2x],y [$%.6x]", op8, decode(OPTYPE_ILDPY, op8)); break;
case 0xd8: sprintf(t, "cld "); break;
case 0xd9: sprintf(t, "cmp $%.4x,y [$%.6x]", op16, decode(OPTYPE_ADDRY, op16)); break;
case 0xda: sprintf(t, "phx "); break;
case 0xdb: sprintf(t, "stp "); break;
case 0xdc: sprintf(t, "jmp [$%.4x] [$%.6x]", op16, decode(OPTYPE_ILADDR, op16)); break;
case 0xdd: sprintf(t, "cmp $%.4x,x [$%.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
case 0xde: sprintf(t, "dec $%.4x,x [$%.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
case 0xdf: sprintf(t, "cmp $%.6x,x [$%.6x]", op24, decode(OPTYPE_LONGX, op24)); break;
case 0xe0: if(x8)sprintf(t, "cpx #$%.2x ", op8);
else sprintf(t, "cpx #$%.4x ", op16); break;
case 0xe1: sprintf(t, "sbc ($%.2x,x) [$%.6x]", op8, decode(OPTYPE_IDPX, op8)); break;
case 0xe2: sprintf(t, "sep #$%.2x ", op8); break;
case 0xe3: sprintf(t, "sbc $%.2x,s [$%.6x]", op8, decode(OPTYPE_SR, op8)); break;
case 0xe4: sprintf(t, "cpx $%.2x [$%.6x]", op8, decode(OPTYPE_DP, op8)); break;
case 0xe5: sprintf(t, "sbc $%.2x [$%.6x]", op8, decode(OPTYPE_DP, op8)); break;
case 0xe6: sprintf(t, "inc $%.2x [$%.6x]", op8, decode(OPTYPE_DP, op8)); break;
case 0xe7: sprintf(t, "sbc [$%.2x] [$%.6x]", op8, decode(OPTYPE_ILDP, op8)); break;
case 0xe8: sprintf(t, "inx "); break;
case 0xe9: if(a8)sprintf(t, "sbc #$%.2x ", op8);
else sprintf(t, "sbc #$%.4x ", op16); break;
case 0xea: sprintf(t, "nop "); break;
case 0xeb: sprintf(t, "xba "); break;
case 0xec: sprintf(t, "cpx $%.4x [$%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0xed: sprintf(t, "sbc $%.4x [$%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0xee: sprintf(t, "inc $%.4x [$%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0xef: sprintf(t, "sbc $%.6x [$%.6x]", op24, decode(OPTYPE_LONG, op24)); break;
case 0xf0: sprintf(t, "beq $%.4x [$%.6x]", uint16(decode(OPTYPE_RELB, op8)), decode(OPTYPE_RELB, op8)); break;
case 0xf1: sprintf(t, "sbc ($%.2x),y [$%.6x]", op8, decode(OPTYPE_IDPY, op8)); break;
case 0xf2: sprintf(t, "sbc ($%.2x) [$%.6x]", op8, decode(OPTYPE_IDP, op8)); break;
case 0xf3: sprintf(t, "sbc ($%.2x,s),y [$%.6x]", op8, decode(OPTYPE_ISRY, op8)); break;
case 0xf4: sprintf(t, "pea $%.4x [$%.6x]", op16, decode(OPTYPE_ADDR, op16)); break;
case 0xf5: sprintf(t, "sbc $%.2x,x [$%.6x]", op8, decode(OPTYPE_DPX, op8)); break;
case 0xf6: sprintf(t, "inc $%.2x,x [$%.6x]", op8, decode(OPTYPE_DPX, op8)); break;
case 0xf7: sprintf(t, "sbc [$%.2x],y [$%.6x]", op8, decode(OPTYPE_ILDPY, op8)); break;
case 0xf8: sprintf(t, "sed "); break;
case 0xf9: sprintf(t, "sbc $%.4x,y [$%.6x]", op16, decode(OPTYPE_ADDRY, op16)); break;
case 0xfa: sprintf(t, "plx "); break;
case 0xfb: sprintf(t, "xce "); break;
case 0xfc: sprintf(t, "jsr ($%.4x,x) [$%.6x]", op16, decode(OPTYPE_IADDRX, op16)); break;
case 0xfd: sprintf(t, "sbc $%.4x,x [$%.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
case 0xfe: sprintf(t, "inc $%.4x,x [$%.6x]", op16, decode(OPTYPE_ADDRX, op16)); break;
case 0xff: sprintf(t, "sbc $%.6x,x [$%.6x]", op24, decode(OPTYPE_LONGX, op24)); break;
}
#undef op8
#undef op16
#undef op24
#undef a8
#undef x8
#undef op8
#undef op16
#undef op24
#undef a8
#undef x8
strcat(s, t);
strcat(s, " ");
sprintf(t, "A:%0.4x X:%0.4x Y:%0.4x S:%0.4x D:%0.4x DB:%0.2x ",
sprintf(t, "A:%.4x X:%.4x Y:%.4x S:%.4x D:%.4x DB:%.2x ",
regs.a.w, regs.x.w, regs.y.w, regs.s.w, regs.d.w, regs.db);
strcat(s, t);
if(regs.e) {
sprintf(t, "%c%c%c%c%c%c%c%c",
(regs.p.n) ? 'N' : 'n', (regs.p.v) ? 'V' : 'v',
(regs.p.m) ? '1' : '0', (regs.p.x) ? 'B' : 'b',
(regs.p.d) ? 'D' : 'd', (regs.p.i) ? 'I' : 'i',
(regs.p.z) ? 'Z' : 'z', (regs.p.c) ? 'C' : 'c');
regs.p.n ? 'N' : 'n', regs.p.v ? 'V' : 'v',
regs.p.m ? '1' : '0', regs.p.x ? 'B' : 'b',
regs.p.d ? 'D' : 'd', regs.p.i ? 'I' : 'i',
regs.p.z ? 'Z' : 'z', regs.p.c ? 'C' : 'c');
} else {
sprintf(t, "%c%c%c%c%c%c%c%c",
(regs.p.n) ? 'N' : 'n', (regs.p.v) ? 'V' : 'v',
(regs.p.m) ? 'M' : 'm', (regs.p.x) ? 'X' : 'x',
(regs.p.d) ? 'D' : 'd', (regs.p.i) ? 'I' : 'i',
(regs.p.z) ? 'Z' : 'z', (regs.p.c) ? 'C' : 'c');
regs.p.n ? 'N' : 'n', regs.p.v ? 'V' : 'v',
regs.p.m ? 'M' : 'm', regs.p.x ? 'X' : 'x',
regs.p.d ? 'D' : 'd', regs.p.i ? 'I' : 'i',
regs.p.z ? 'Z' : 'z', regs.p.c ? 'C' : 'c');
}
strcat(s, t);
strcat(s, " ");
sprintf(t, "V:%3d H:%4d", vcounter(), hclock());
sprintf(t, "V:%3d H:%4d", ppu.vcounter(), ppu.hcounter());
strcat(s, t);
}
/*****
* opcode_length() retrieves the length of the next opcode
* to be executed. It is used by the debugger to step over,
* disable and proceed cpu opcodes.
*
* 5 and 6 are special cases, 5 is used for #consts based on
* the A register size, 6 for the X/Y register size. the
* rest are literal sizes. There's no need to test for
* emulation mode, as regs.p.m/regs.p.x should *always* be
* set in emulation mode.
*****/
//opcode_length() retrieves the length of the next opcode
//to be executed. It is used by the debugger to step over,
//disable and proceed cpu opcodes.
//
//5 and 6 are special cases, 5 is used for #consts based on
//the A register size, 6 for the X/Y register size. the
//rest are literal sizes. There's no need to test for
//emulation mode, as regs.p.m/regs.p.x should *always* be
//set in emulation mode.
uint8 CPU::opcode_length() {
uint8 op, len;
static uint8 op_len_tbl[256] = {
//0,1,2,3, 4,5,6,7, 8,9,a,b, c,d,e,f
uint8 op, len;
static uint8 op_len_tbl[256] = {
//0,1,2,3, 4,5,6,7, 8,9,a,b, c,d,e,f
2,2,2,2, 2,2,2,2, 1,5,1,1, 3,3,3,4, //0x0n
2,2,2,2, 2,2,2,2, 1,3,1,1, 3,3,3,4, //0x1n
3,2,4,2, 2,2,2,2, 1,5,1,1, 3,3,3,4, //0x2n
2,2,2,2, 2,2,2,2, 1,3,1,1, 3,3,3,4, //0x3n
2,2,2,2, 2,2,2,2, 1,5,1,1, 3,3,3,4, //0x0n
2,2,2,2, 2,2,2,2, 1,3,1,1, 3,3,3,4, //0x1n
3,2,4,2, 2,2,2,2, 1,5,1,1, 3,3,3,4, //0x2n
2,2,2,2, 2,2,2,2, 1,3,1,1, 3,3,3,4, //0x3n
1,2,2,2, 3,2,2,2, 1,5,1,1, 3,3,3,4, //0x4n
2,2,2,2, 3,2,2,2, 1,3,1,1, 4,3,3,4, //0x5n
1,2,3,2, 2,2,2,2, 1,5,1,1, 3,3,3,4, //0x6n
2,2,2,2, 2,2,2,2, 1,3,1,1, 3,3,3,4, //0x7n
1,2,2,2, 3,2,2,2, 1,5,1,1, 3,3,3,4, //0x4n
2,2,2,2, 3,2,2,2, 1,3,1,1, 4,3,3,4, //0x5n
1,2,3,2, 2,2,2,2, 1,5,1,1, 3,3,3,4, //0x6n
2,2,2,2, 2,2,2,2, 1,3,1,1, 3,3,3,4, //0x7n
2,2,3,2, 2,2,2,2, 1,5,1,1, 3,3,3,4, //0x8n
2,2,2,2, 2,2,2,2, 1,3,1,1, 3,3,3,4, //0x9n
6,2,6,2, 2,2,2,2, 1,5,1,1, 3,3,3,4, //0xan
2,2,2,2, 2,2,2,2, 1,3,1,1, 3,3,3,4, //0xbn
2,2,3,2, 2,2,2,2, 1,5,1,1, 3,3,3,4, //0x8n
2,2,2,2, 2,2,2,2, 1,3,1,1, 3,3,3,4, //0x9n
6,2,6,2, 2,2,2,2, 1,5,1,1, 3,3,3,4, //0xan
2,2,2,2, 2,2,2,2, 1,3,1,1, 3,3,3,4, //0xbn
6,2,2,2, 2,2,2,2, 1,5,1,1, 3,3,3,4, //0xcn
2,2,2,2, 2,2,2,2, 1,3,1,1, 3,3,3,4, //0xdn
6,2,2,2, 2,2,2,2, 1,5,1,1, 3,3,3,4, //0xen
2,2,2,2, 3,2,2,2, 1,3,1,1, 3,3,3,4 //0xfn
};
6,2,2,2, 2,2,2,2, 1,5,1,1, 3,3,3,4, //0xcn
2,2,2,2, 2,2,2,2, 1,3,1,1, 3,3,3,4, //0xdn
6,2,2,2, 2,2,2,2, 1,5,1,1, 3,3,3,4, //0xen
2,2,2,2, 3,2,2,2, 1,3,1,1, 3,3,3,4 //0xfn
};
if(in_opcode() == true) {
return 0;
}
op = dreadb(regs.pc.d);
len = op_len_tbl[op];
if(len == 5)return (regs.e || regs.p.m) ? 2 : 3;
if(len == 6)return (regs.e || regs.p.x) ? 2 : 3;
if(len == 5) return (regs.e || regs.p.m) ? 2 : 3;
if(len == 6) return (regs.e || regs.p.x) ? 2 : 3;
return len;
}
#endif //ifdef CPU_CPP

View File

@@ -1,3 +0,0 @@
cl /nologo /O2 scpugen.cpp
@pause
@del *.obj

4
src/cpu/scpu/core/cc.sh Normal file
View File

@@ -0,0 +1,4 @@
g++ -c scpugen.cpp -I../../../lib
g++ -c ../../../lib/nall/string.cpp -I../../../lib
g++ -o scpugen scpugen.o string.o
rm *.o

View File

@@ -1 +0,0 @@
@del *.exe

View File

@@ -0,0 +1 @@
rm scpugen

View File

@@ -1,20 +1,23 @@
#ifdef SCPU_CPP
#include "opfn.cpp"
#include "op_read.cpp"
#include "op_write.cpp"
#include "op_rmw.cpp"
#include "op_pc.cpp"
#include "op_misc.cpp"
void sCPU::enter() {
initialize:
//initial latch values for $213c/$213d
//[x]0035 : [y]0000 (53.0 -> 212) [lda $2137]
//[x]0038 : [y]0000 (56.5 -> 226) [nop : lda $2137]
add_clocks(186);
void sCPU::enter() { loop:
if(event.irq) {
event.irq = false;
if(status.nmi_pending == true) {
loop:
if(status.interrupt_pending) {
status.interrupt_pending = false;
if(status.nmi_pending) {
status.nmi_pending = false;
event.irq_vector = (regs.e == false) ? 0xffea : 0xfffa;
} else if(status.irq_pending == true) {
status.interrupt_vector = (regs.e == false ? 0xffea : 0xfffa);
} else if(status.irq_pending) {
status.irq_pending = false;
event.irq_vector = (regs.e == false) ? 0xffee : 0xfffe;
status.interrupt_vector = (regs.e == false ? 0xffee : 0xfffe);
}
op_irq();
}
@@ -22,7 +25,13 @@ void sCPU::enter() { loop:
tracer.trace_cpuop(); //traces CPU opcode (only if tracer is enabled)
status.in_opcode = true;
(this->*optbl[op_readpc()])();
switch(op_readpc()) {
#include "op_read.cpp"
#include "op_write.cpp"
#include "op_rmw.cpp"
#include "op_pc.cpp"
#include "op_misc.cpp"
}
status.in_opcode = false;
goto loop;
@@ -31,20 +40,35 @@ void sCPU::enter() { loop:
void sCPU::op_irq() {
op_read(regs.pc.d);
op_io();
if(!regs.e)op_writestack(regs.pc.b);
if(!regs.e) op_writestack(regs.pc.b);
op_writestack(regs.pc.h);
op_writestack(regs.pc.l);
op_writestack(regs.e ? (regs.p & ~0x10) : regs.p);
rd.l = op_read(event.irq_vector + 0);
rd.l = op_read(status.interrupt_vector + 0);
regs.pc.b = 0x00;
regs.p.i = 1;
regs.p.d = 0;
rd.h = op_read(event.irq_vector + 1);
rd.h = op_read(status.interrupt_vector + 1);
regs.pc.w = rd.w;
}
//immediate, 2-cycle opcodes with I/O cycle will become bus read
//when an IRQ is to be triggered immediately after opcode completion
//this affects the following opcodes:
// clc, cld, cli, clv, sec, sed, sei,
// tax, tay, txa, txy, tya, tyx,
// tcd, tcs, tdc, tsc, tsx, txs,
// inc, inx, iny, dec, dex, dey,
// asl, lsr, rol, ror, nop, xce.
alwaysinline void sCPU::op_io_irq() {
if(status.interrupt_pending) {
//IRQ pending, modify I/O cycle to bus read cycle, do not increment PC
op_read(regs.pc.d);
} else {
op_io();
}
}
//
alwaysinline void sCPU::op_io_cond2() {
if(regs.d.l != 0x00) {
op_io();
@@ -62,3 +86,5 @@ alwaysinline void sCPU::op_io_cond6(uint16 addr) {
op_io();
}
}
#endif

View File

@@ -1,57 +0,0 @@
void (sCPU::*optbl[256])();
CPUReg24 aa, rd;
uint8 dp, sp;
void op_irq();
inline bool in_opcode() { return status.in_opcode; }
//op_read
void op_adc_b();
void op_adc_w();
void op_and_b();
void op_and_w();
void op_bit_b();
void op_bit_w();
void op_cmp_b();
void op_cmp_w();
void op_cpx_b();
void op_cpx_w();
void op_cpy_b();
void op_cpy_w();
void op_eor_b();
void op_eor_w();
void op_lda_b();
void op_lda_w();
void op_ldx_b();
void op_ldx_w();
void op_ldy_b();
void op_ldy_w();
void op_ora_b();
void op_ora_w();
void op_sbc_b();
void op_sbc_w();
//op_rmw
void op_inc_b();
void op_inc_w();
void op_dec_b();
void op_dec_w();
void op_asl_b();
void op_asl_w();
void op_lsr_b();
void op_lsr_w();
void op_rol_b();
void op_rol_w();
void op_ror_b();
void op_ror_w();
void op_trb_b();
void op_trb_w();
void op_tsb_b();
void op_tsb_w();
void op_io_cond2();
void op_io_cond4(uint16 x, uint16 y);
void op_io_cond6(uint16 addr);
#include "op.h"

View File

@@ -0,0 +1,54 @@
reg24_t aa, rd;
uint8_t dp, sp;
void op_irq();
inline bool in_opcode() { return status.in_opcode; }
//op_read
void op_adc_b();
void op_adc_w();
void op_and_b();
void op_and_w();
void op_bit_b();
void op_bit_w();
void op_cmp_b();
void op_cmp_w();
void op_cpx_b();
void op_cpx_w();
void op_cpy_b();
void op_cpy_w();
void op_eor_b();
void op_eor_w();
void op_lda_b();
void op_lda_w();
void op_ldx_b();
void op_ldx_w();
void op_ldy_b();
void op_ldy_w();
void op_ora_b();
void op_ora_w();
void op_sbc_b();
void op_sbc_w();
//op_rmw
void op_inc_b();
void op_inc_w();
void op_dec_b();
void op_dec_w();
void op_asl_b();
void op_asl_w();
void op_lsr_b();
void op_lsr_w();
void op_rol_b();
void op_rol_w();
void op_ror_b();
void op_ror_w();
void op_trb_b();
void op_trb_w();
void op_tsb_b();
void op_tsb_w();
void op_io_irq();
void op_io_cond2();
void op_io_cond4(uint16 x, uint16 y);
void op_io_cond6(uint16 addr);

View File

@@ -1,256 +0,0 @@
void op_adc_const();
void op_and_const();
void op_cmp_const();
void op_cpx_const();
void op_cpy_const();
void op_eor_const();
void op_lda_const();
void op_ldx_const();
void op_ldy_const();
void op_ora_const();
void op_sbc_const();
void op_adc_addr();
void op_and_addr();
void op_bit_addr();
void op_cmp_addr();
void op_cpx_addr();
void op_cpy_addr();
void op_eor_addr();
void op_lda_addr();
void op_ldx_addr();
void op_ldy_addr();
void op_ora_addr();
void op_sbc_addr();
void op_adc_addrx();
void op_and_addrx();
void op_bit_addrx();
void op_cmp_addrx();
void op_eor_addrx();
void op_lda_addrx();
void op_ldy_addrx();
void op_ora_addrx();
void op_sbc_addrx();
void op_adc_addry();
void op_and_addry();
void op_cmp_addry();
void op_eor_addry();
void op_lda_addry();
void op_ldx_addry();
void op_ora_addry();
void op_sbc_addry();
void op_adc_long();
void op_and_long();
void op_cmp_long();
void op_eor_long();
void op_lda_long();
void op_ora_long();
void op_sbc_long();
void op_adc_longx();
void op_and_longx();
void op_cmp_longx();
void op_eor_longx();
void op_lda_longx();
void op_ora_longx();
void op_sbc_longx();
void op_adc_dp();
void op_and_dp();
void op_bit_dp();
void op_cmp_dp();
void op_cpx_dp();
void op_cpy_dp();
void op_eor_dp();
void op_lda_dp();
void op_ldx_dp();
void op_ldy_dp();
void op_ora_dp();
void op_sbc_dp();
void op_adc_dpx();
void op_and_dpx();
void op_bit_dpx();
void op_cmp_dpx();
void op_eor_dpx();
void op_lda_dpx();
void op_ldy_dpx();
void op_ora_dpx();
void op_sbc_dpx();
void op_ldx_dpy();
void op_adc_idp();
void op_and_idp();
void op_cmp_idp();
void op_eor_idp();
void op_lda_idp();
void op_ora_idp();
void op_sbc_idp();
void op_adc_idpx();
void op_and_idpx();
void op_cmp_idpx();
void op_eor_idpx();
void op_lda_idpx();
void op_ora_idpx();
void op_sbc_idpx();
void op_adc_idpy();
void op_and_idpy();
void op_cmp_idpy();
void op_eor_idpy();
void op_lda_idpy();
void op_ora_idpy();
void op_sbc_idpy();
void op_adc_ildp();
void op_and_ildp();
void op_cmp_ildp();
void op_eor_ildp();
void op_lda_ildp();
void op_ora_ildp();
void op_sbc_ildp();
void op_adc_ildpy();
void op_and_ildpy();
void op_cmp_ildpy();
void op_eor_ildpy();
void op_lda_ildpy();
void op_ora_ildpy();
void op_sbc_ildpy();
void op_adc_sr();
void op_and_sr();
void op_cmp_sr();
void op_eor_sr();
void op_lda_sr();
void op_ora_sr();
void op_sbc_sr();
void op_adc_isry();
void op_and_isry();
void op_cmp_isry();
void op_eor_isry();
void op_lda_isry();
void op_ora_isry();
void op_sbc_isry();
void op_bit_const();
void op_sta_addr();
void op_stx_addr();
void op_sty_addr();
void op_stz_addr();
void op_sta_addrx();
void op_stz_addrx();
void op_sta_addry();
void op_sta_long();
void op_sta_longx();
void op_sta_dp();
void op_stx_dp();
void op_sty_dp();
void op_stz_dp();
void op_sta_dpx();
void op_sty_dpx();
void op_stz_dpx();
void op_stx_dpy();
void op_sta_idp();
void op_sta_ildp();
void op_sta_idpx();
void op_sta_idpy();
void op_sta_ildpy();
void op_sta_sr();
void op_sta_isry();
void op_inc();
void op_inx();
void op_iny();
void op_dec();
void op_dex();
void op_dey();
void op_asl();
void op_lsr();
void op_rol();
void op_ror();
void op_inc_addr();
void op_dec_addr();
void op_asl_addr();
void op_lsr_addr();
void op_rol_addr();
void op_ror_addr();
void op_trb_addr();
void op_tsb_addr();
void op_inc_addrx();
void op_dec_addrx();
void op_asl_addrx();
void op_lsr_addrx();
void op_rol_addrx();
void op_ror_addrx();
void op_inc_dp();
void op_dec_dp();
void op_asl_dp();
void op_lsr_dp();
void op_rol_dp();
void op_ror_dp();
void op_trb_dp();
void op_tsb_dp();
void op_inc_dpx();
void op_dec_dpx();
void op_asl_dpx();
void op_lsr_dpx();
void op_rol_dpx();
void op_ror_dpx();
void op_bcc();
void op_bcs();
void op_bne();
void op_beq();
void op_bpl();
void op_bmi();
void op_bvc();
void op_bvs();
void op_bra();
void op_brl();
void op_jmp_addr();
void op_jmp_long();
void op_jmp_iaddr();
void op_jmp_iaddrx();
void op_jmp_iladdr();
void op_jsr_addr();
void op_jsr_long();
void op_jsr_iaddrx();
void op_rti();
void op_rts();
void op_rtl();
void op_nop();
void op_wdm();
void op_xba();
void op_mvn();
void op_mvp();
void op_brk();
void op_cop();
void op_stp();
void op_wai();
void op_xce();
void op_clc();
void op_cld();
void op_cli();
void op_clv();
void op_sec();
void op_sed();
void op_sei();
void op_rep();
void op_sep();
void op_tax();
void op_tay();
void op_txa();
void op_txy();
void op_tya();
void op_tyx();
void op_tcd();
void op_tcs();
void op_tdc();
void op_tsc();
void op_tsx();
void op_txs();
void op_pha();
void op_phx();
void op_phy();
void op_phd();
void op_phb();
void op_phk();
void op_php();
void op_pla();
void op_plx();
void op_ply();
void op_pld();
void op_plb();
void op_plp();
void op_pea();
void op_pei();
void op_per();

View File

@@ -1,6 +1,6 @@
nop(0xea) {
1:last_cycle();
op_io();
1:last_cycle();
op_io_irq();
}
wdm(0x42) {
@@ -36,36 +36,35 @@ mvp(0x44, --) {
}
6:last_cycle();
op_io();
if(regs.a.w--)regs.pc.w -= 3;
if(regs.a.w--) regs.pc.w -= 3;
}
brk(0x00, 0xfffe, 0xffff, 0xffe6, 0xffe7),
cop(0x02, 0xfff4, 0xfff5, 0xffe4, 0xffe5) {
1:op_readpc();
2:if(!regs.e)op_writestack(regs.pc.b);
2:if(!regs.e) op_writestack(regs.pc.b);
3:op_writestack(regs.pc.h);
4:op_writestack(regs.pc.l);
5:op_writestack(regs.p);
6:rd.l = op_readlong((regs.e) ? $1 : $3);
6:rd.l = op_readlong(regs.e ? $1 : $3);
regs.pc.b = 0x00;
regs.p.i = 1;
regs.p.d = 0;
7:last_cycle();
rd.h = op_readlong((regs.e) ? $2 : $4);
rd.h = op_readlong(regs.e ? $2 : $4);
regs.pc.w = rd.w;
}
stp(0xdb) {
1:op_io();
2:last_cycle();
while(1) { op_io(); }
while(true) op_io();
}
wai(0xcb) {
//last_cycle() will set event.wai to false
//once an NMI / IRQ edge is reached
1:event.wai = true;
while(event.wai) {
//last_cycle() will clear status.wai_lock once an NMI / IRQ edge is reached
1:status.wai_lock = true;
while(status.wai_lock) {
last_cycle();
op_io();
}
@@ -73,9 +72,9 @@ wai(0xcb) {
}
xce(0xfb) {
1:last_cycle();
op_io();
bool carry = regs.p.c;
1:last_cycle();
op_io_irq();
bool carry = regs.p.c;
regs.p.c = regs.e;
regs.e = carry;
if(regs.e) {
@@ -96,7 +95,7 @@ sec(0x38, regs.p.c = 1),
sed(0xf8, regs.p.d = 1),
sei(0x78, regs.p.i = 1) {
1:last_cycle();
op_io();
op_io_irq();
$1;
}
@@ -106,7 +105,7 @@ sep(0xe2, |=) {
2:last_cycle();
op_io();
regs.p $1 rd.l;
if(regs.e)regs.p |= 0x30;
if(regs.e) regs.p |= 0x30;
if(regs.p.x) {
regs.x.h = 0x00;
regs.y.h = 0x00;
@@ -120,7 +119,7 @@ txy(0x9b, regs.p.x, y, x),
tya(0x98, regs.p.m, a, y),
tyx(0xbb, regs.p.x, x, y) {
1:last_cycle();
op_io();
op_io_irq();
if($1) {
regs.$2.l = regs.$3.l;
regs.p.n = !!(regs.$2.l & 0x80);
@@ -134,7 +133,7 @@ tyx(0xbb, regs.p.x, x, y) {
tcd(0x5b) {
1:last_cycle();
op_io();
op_io_irq();
regs.d.w = regs.a.w;
regs.p.n = !!(regs.d.w & 0x8000);
regs.p.z = (regs.d.w == 0);
@@ -142,14 +141,14 @@ tcd(0x5b) {
tcs(0x1b) {
1:last_cycle();
op_io();
op_io_irq();
regs.s.w = regs.a.w;
if(regs.e)regs.s.h = 0x01;
if(regs.e) regs.s.h = 0x01;
}
tdc(0x7b) {
1:last_cycle();
op_io();
op_io_irq();
regs.a.w = regs.d.w;
regs.p.n = !!(regs.a.w & 0x8000);
regs.p.z = (regs.a.w == 0);
@@ -157,7 +156,7 @@ tdc(0x7b) {
tsc(0x3b) {
1:last_cycle();
op_io();
op_io_irq();
regs.a.w = regs.s.w;
if(regs.e) {
regs.p.n = !!(regs.a.l & 0x80);
@@ -170,7 +169,7 @@ tsc(0x3b) {
tsx(0xba) {
1:last_cycle();
op_io();
op_io_irq();
if(regs.p.x) {
regs.x.l = regs.s.l;
regs.p.n = !!(regs.x.l & 0x80);
@@ -184,7 +183,7 @@ tsx(0xba) {
txs(0x9a) {
1:last_cycle();
op_io();
op_io_irq();
if(regs.e) {
regs.s.l = regs.x.l;
} else {
@@ -206,7 +205,7 @@ phd(0x0b) {
2:op_writestackn(regs.d.h);
3:last_cycle();
op_writestackn(regs.d.l);
if(regs.e)regs.s.h = 0x01;
if(regs.e) regs.s.h = 0x01;
}
phb(0x8b, regs.db),
@@ -243,7 +242,7 @@ pld(0x2b) {
regs.d.h = op_readstackn();
regs.p.n = !!(regs.d.w & 0x8000);
regs.p.z = (regs.d.w == 0);
if(regs.e)regs.s.h = 0x01;
if(regs.e) regs.s.h = 0x01;
}
plb(0xab) {
@@ -260,7 +259,7 @@ plp(0x28) {
2:op_io();
3:last_cycle();
regs.p = op_readstack();
if(regs.e)regs.p |= 0x30;
if(regs.e) regs.p |= 0x30;
if(regs.p.x) {
regs.x.h = 0x00;
regs.y.h = 0x00;
@@ -273,7 +272,7 @@ pea(0xf4) {
3:op_writestackn(aa.h);
4:last_cycle();
op_writestackn(aa.l);
if(regs.e)regs.s.h = 0x01;
if(regs.e) regs.s.h = 0x01;
}
pei(0xd4) {
@@ -284,7 +283,7 @@ pei(0xd4) {
5:op_writestackn(aa.h);
6:last_cycle();
op_writestackn(aa.l);
if(regs.e)regs.s.h = 0x01;
if(regs.e) regs.s.h = 0x01;
}
per(0x62) {
@@ -295,5 +294,5 @@ per(0x62) {
4:op_writestackn(rd.h);
5:last_cycle();
op_writestackn(rd.l);
if(regs.e)regs.s.h = 0x01;
if(regs.e) regs.s.h = 0x01;
}

View File

@@ -1,14 +1,19 @@
void sCPU::op_nop() {
#ifdef SCPU_CPP
//nop
case 0xea: {
last_cycle();
op_io();
}
op_io_irq();
} break;
void sCPU::op_wdm() {
//wdm
case 0x42: {
last_cycle();
op_readpc();
}
} break;
void sCPU::op_xba() {
//xba
case 0xeb: {
op_io();
last_cycle();
op_io();
@@ -17,9 +22,10 @@ void sCPU::op_xba() {
regs.a.l ^= regs.a.h;
regs.p.n = !!(regs.a.l & 0x80);
regs.p.z = (regs.a.l == 0);
}
} break;
void sCPU::op_mvn() {
//mvn
case 0x54: {
dp = op_readpc();
sp = op_readpc();
regs.db = dp;
@@ -35,10 +41,11 @@ void sCPU::op_mvn() {
}
last_cycle();
op_io();
if(regs.a.w--)regs.pc.w -= 3;
}
if(regs.a.w--) regs.pc.w -= 3;
} break;
void sCPU::op_mvp() {
//mvp
case 0x44: {
dp = op_readpc();
sp = op_readpc();
regs.db = dp;
@@ -54,60 +61,64 @@ void sCPU::op_mvp() {
}
last_cycle();
op_io();
if(regs.a.w--)regs.pc.w -= 3;
}
if(regs.a.w--) regs.pc.w -= 3;
} break;
void sCPU::op_brk() {
//brk
case 0x00: {
op_readpc();
if(!regs.e)op_writestack(regs.pc.b);
if(!regs.e) op_writestack(regs.pc.b);
op_writestack(regs.pc.h);
op_writestack(regs.pc.l);
op_writestack(regs.p);
rd.l = op_readlong((regs.e) ? 0xfffe : 0xffe6);
rd.l = op_readlong(regs.e ? 0xfffe : 0xffe6);
regs.pc.b = 0x00;
regs.p.i = 1;
regs.p.d = 0;
last_cycle();
rd.h = op_readlong((regs.e) ? 0xffff : 0xffe7);
rd.h = op_readlong(regs.e ? 0xffff : 0xffe7);
regs.pc.w = rd.w;
}
} break;
void sCPU::op_cop() {
//cop
case 0x02: {
op_readpc();
if(!regs.e)op_writestack(regs.pc.b);
if(!regs.e) op_writestack(regs.pc.b);
op_writestack(regs.pc.h);
op_writestack(regs.pc.l);
op_writestack(regs.p);
rd.l = op_readlong((regs.e) ? 0xfff4 : 0xffe4);
rd.l = op_readlong(regs.e ? 0xfff4 : 0xffe4);
regs.pc.b = 0x00;
regs.p.i = 1;
regs.p.d = 0;
last_cycle();
rd.h = op_readlong((regs.e) ? 0xfff5 : 0xffe5);
rd.h = op_readlong(regs.e ? 0xfff5 : 0xffe5);
regs.pc.w = rd.w;
}
} break;
void sCPU::op_stp() {
//stp
case 0xdb: {
op_io();
last_cycle();
while(1) { op_io(); }
}
while(true) op_io();
} break;
void sCPU::op_wai() {
//last_cycle() will set event.wai to false
//once an NMI / IRQ edge is reached
event.wai = true;
while(event.wai) {
//wai
case 0xcb: {
//last_cycle() will clear status.wai_lock once an NMI / IRQ edge is reached
status.wai_lock = true;
while(status.wai_lock) {
last_cycle();
op_io();
}
op_io();
}
} break;
void sCPU::op_xce() {
//xce
case 0xfb: {
last_cycle();
op_io();
bool carry = regs.p.c;
op_io_irq();
bool carry = regs.p.c;
regs.p.c = regs.e;
regs.e = carry;
if(regs.e) {
@@ -118,77 +129,87 @@ bool carry = regs.p.c;
regs.x.h = 0x00;
regs.y.h = 0x00;
}
}
} break;
void sCPU::op_clc() {
//clc
case 0x18: {
last_cycle();
op_io();
op_io_irq();
regs.p.c = 0;
}
} break;
void sCPU::op_cld() {
//cld
case 0xd8: {
last_cycle();
op_io();
op_io_irq();
regs.p.d = 0;
}
} break;
void sCPU::op_cli() {
//cli
case 0x58: {
last_cycle();
op_io();
op_io_irq();
regs.p.i = 0;
}
} break;
void sCPU::op_clv() {
//clv
case 0xb8: {
last_cycle();
op_io();
op_io_irq();
regs.p.v = 0;
}
} break;
void sCPU::op_sec() {
//sec
case 0x38: {
last_cycle();
op_io();
op_io_irq();
regs.p.c = 1;
}
} break;
void sCPU::op_sed() {
//sed
case 0xf8: {
last_cycle();
op_io();
op_io_irq();
regs.p.d = 1;
}
} break;
void sCPU::op_sei() {
//sei
case 0x78: {
last_cycle();
op_io();
op_io_irq();
regs.p.i = 1;
}
} break;
void sCPU::op_rep() {
//rep
case 0xc2: {
rd.l = op_readpc();
last_cycle();
op_io();
regs.p &=~ rd.l;
if(regs.e)regs.p |= 0x30;
if(regs.e) regs.p |= 0x30;
if(regs.p.x) {
regs.x.h = 0x00;
regs.y.h = 0x00;
}
}
} break;
void sCPU::op_sep() {
//sep
case 0xe2: {
rd.l = op_readpc();
last_cycle();
op_io();
regs.p |= rd.l;
if(regs.e)regs.p |= 0x30;
if(regs.e) regs.p |= 0x30;
if(regs.p.x) {
regs.x.h = 0x00;
regs.y.h = 0x00;
}
}
} break;
void sCPU::op_tax() {
//tax
case 0xaa: {
last_cycle();
op_io();
op_io_irq();
if(regs.p.x) {
regs.x.l = regs.a.l;
regs.p.n = !!(regs.x.l & 0x80);
@@ -198,11 +219,12 @@ void sCPU::op_tax() {
regs.p.n = !!(regs.x.w & 0x8000);
regs.p.z = (regs.x.w == 0);
}
}
} break;
void sCPU::op_tay() {
//tay
case 0xa8: {
last_cycle();
op_io();
op_io_irq();
if(regs.p.x) {
regs.y.l = regs.a.l;
regs.p.n = !!(regs.y.l & 0x80);
@@ -212,11 +234,12 @@ void sCPU::op_tay() {
regs.p.n = !!(regs.y.w & 0x8000);
regs.p.z = (regs.y.w == 0);
}
}
} break;
void sCPU::op_txa() {
//txa
case 0x8a: {
last_cycle();
op_io();
op_io_irq();
if(regs.p.m) {
regs.a.l = regs.x.l;
regs.p.n = !!(regs.a.l & 0x80);
@@ -226,11 +249,12 @@ void sCPU::op_txa() {
regs.p.n = !!(regs.a.w & 0x8000);
regs.p.z = (regs.a.w == 0);
}
}
} break;
void sCPU::op_txy() {
//txy
case 0x9b: {
last_cycle();
op_io();
op_io_irq();
if(regs.p.x) {
regs.y.l = regs.x.l;
regs.p.n = !!(regs.y.l & 0x80);
@@ -240,11 +264,12 @@ void sCPU::op_txy() {
regs.p.n = !!(regs.y.w & 0x8000);
regs.p.z = (regs.y.w == 0);
}
}
} break;
void sCPU::op_tya() {
//tya
case 0x98: {
last_cycle();
op_io();
op_io_irq();
if(regs.p.m) {
regs.a.l = regs.y.l;
regs.p.n = !!(regs.a.l & 0x80);
@@ -254,11 +279,12 @@ void sCPU::op_tya() {
regs.p.n = !!(regs.a.w & 0x8000);
regs.p.z = (regs.a.w == 0);
}
}
} break;
void sCPU::op_tyx() {
//tyx
case 0xbb: {
last_cycle();
op_io();
op_io_irq();
if(regs.p.x) {
regs.x.l = regs.y.l;
regs.p.n = !!(regs.x.l & 0x80);
@@ -268,34 +294,38 @@ void sCPU::op_tyx() {
regs.p.n = !!(regs.x.w & 0x8000);
regs.p.z = (regs.x.w == 0);
}
}
} break;
void sCPU::op_tcd() {
//tcd
case 0x5b: {
last_cycle();
op_io();
op_io_irq();
regs.d.w = regs.a.w;
regs.p.n = !!(regs.d.w & 0x8000);
regs.p.z = (regs.d.w == 0);
}
} break;
void sCPU::op_tcs() {
//tcs
case 0x1b: {
last_cycle();
op_io();
op_io_irq();
regs.s.w = regs.a.w;
if(regs.e)regs.s.h = 0x01;
}
if(regs.e) regs.s.h = 0x01;
} break;
void sCPU::op_tdc() {
//tdc
case 0x7b: {
last_cycle();
op_io();
op_io_irq();
regs.a.w = regs.d.w;
regs.p.n = !!(regs.a.w & 0x8000);
regs.p.z = (regs.a.w == 0);
}
} break;
void sCPU::op_tsc() {
//tsc
case 0x3b: {
last_cycle();
op_io();
op_io_irq();
regs.a.w = regs.s.w;
if(regs.e) {
regs.p.n = !!(regs.a.l & 0x80);
@@ -304,11 +334,12 @@ void sCPU::op_tsc() {
regs.p.n = !!(regs.a.w & 0x8000);
regs.p.z = (regs.a.w == 0);
}
}
} break;
void sCPU::op_tsx() {
//tsx
case 0xba: {
last_cycle();
op_io();
op_io_irq();
if(regs.p.x) {
regs.x.l = regs.s.l;
regs.p.n = !!(regs.x.l & 0x80);
@@ -318,66 +349,75 @@ void sCPU::op_tsx() {
regs.p.n = !!(regs.x.w & 0x8000);
regs.p.z = (regs.x.w == 0);
}
}
} break;
void sCPU::op_txs() {
//txs
case 0x9a: {
last_cycle();
op_io();
op_io_irq();
if(regs.e) {
regs.s.l = regs.x.l;
} else {
regs.s.w = regs.x.w;
}
}
} break;
void sCPU::op_pha() {
//pha
case 0x48: {
op_io();
if(!regs.p.m)op_writestack(regs.a.h);
last_cycle();
op_writestack(regs.a.l);
}
} break;
void sCPU::op_phx() {
//phx
case 0xda: {
op_io();
if(!regs.p.x)op_writestack(regs.x.h);
last_cycle();
op_writestack(regs.x.l);
}
} break;
void sCPU::op_phy() {
//phy
case 0x5a: {
op_io();
if(!regs.p.x)op_writestack(regs.y.h);
last_cycle();
op_writestack(regs.y.l);
}
} break;
void sCPU::op_phd() {
//phd
case 0x0b: {
op_io();
op_writestackn(regs.d.h);
last_cycle();
op_writestackn(regs.d.l);
if(regs.e)regs.s.h = 0x01;
}
if(regs.e) regs.s.h = 0x01;
} break;
void sCPU::op_phb() {
//phb
case 0x8b: {
op_io();
last_cycle();
op_writestack(regs.db);
}
} break;
void sCPU::op_phk() {
//phk
case 0x4b: {
op_io();
last_cycle();
op_writestack(regs.pc.b);
}
} break;
void sCPU::op_php() {
//php
case 0x08: {
op_io();
last_cycle();
op_writestack(regs.p);
}
} break;
void sCPU::op_pla() {
//pla
case 0x68: {
op_io();
op_io();
if(regs.p.m)last_cycle();
@@ -385,15 +425,16 @@ void sCPU::op_pla() {
if(regs.p.m) {
regs.p.n = !!(regs.a.l & 0x80);
regs.p.z = (regs.a.l == 0);
return;
break;
}
last_cycle();
regs.a.h = op_readstack();
regs.p.n = !!(regs.a.w & 0x8000);
regs.p.z = (regs.a.w == 0);
}
} break;
void sCPU::op_plx() {
//plx
case 0xfa: {
op_io();
op_io();
if(regs.p.x)last_cycle();
@@ -401,15 +442,16 @@ void sCPU::op_plx() {
if(regs.p.x) {
regs.p.n = !!(regs.x.l & 0x80);
regs.p.z = (regs.x.l == 0);
return;
break;
}
last_cycle();
regs.x.h = op_readstack();
regs.p.n = !!(regs.x.w & 0x8000);
regs.p.z = (regs.x.w == 0);
}
} break;
void sCPU::op_ply() {
//ply
case 0x7a: {
op_io();
op_io();
if(regs.p.x)last_cycle();
@@ -417,15 +459,16 @@ void sCPU::op_ply() {
if(regs.p.x) {
regs.p.n = !!(regs.y.l & 0x80);
regs.p.z = (regs.y.l == 0);
return;
break;
}
last_cycle();
regs.y.h = op_readstack();
regs.p.n = !!(regs.y.w & 0x8000);
regs.p.z = (regs.y.w == 0);
}
} break;
void sCPU::op_pld() {
//pld
case 0x2b: {
op_io();
op_io();
regs.d.l = op_readstackn();
@@ -433,40 +476,44 @@ void sCPU::op_pld() {
regs.d.h = op_readstackn();
regs.p.n = !!(regs.d.w & 0x8000);
regs.p.z = (regs.d.w == 0);
if(regs.e)regs.s.h = 0x01;
}
if(regs.e) regs.s.h = 0x01;
} break;
void sCPU::op_plb() {
//plb
case 0xab: {
op_io();
op_io();
last_cycle();
regs.db = op_readstack();
regs.p.n = !!(regs.db & 0x80);
regs.p.z = (regs.db == 0);
}
} break;
void sCPU::op_plp() {
//plp
case 0x28: {
op_io();
op_io();
last_cycle();
regs.p = op_readstack();
if(regs.e)regs.p |= 0x30;
if(regs.e) regs.p |= 0x30;
if(regs.p.x) {
regs.x.h = 0x00;
regs.y.h = 0x00;
}
}
} break;
void sCPU::op_pea() {
//pea
case 0xf4: {
aa.l = op_readpc();
aa.h = op_readpc();
op_writestackn(aa.h);
last_cycle();
op_writestackn(aa.l);
if(regs.e)regs.s.h = 0x01;
}
if(regs.e) regs.s.h = 0x01;
} break;
void sCPU::op_pei() {
//pei
case 0xd4: {
dp = op_readpc();
op_io_cond2();
aa.l = op_readdp(dp);
@@ -474,10 +521,11 @@ void sCPU::op_pei() {
op_writestackn(aa.h);
last_cycle();
op_writestackn(aa.l);
if(regs.e)regs.s.h = 0x01;
}
if(regs.e) regs.s.h = 0x01;
} break;
void sCPU::op_per() {
//per
case 0x62: {
aa.l = op_readpc();
aa.h = op_readpc();
op_io();
@@ -485,6 +533,7 @@ void sCPU::op_per() {
op_writestackn(rd.h);
last_cycle();
op_writestackn(rd.l);
if(regs.e)regs.s.h = 0x01;
}
if(regs.e) regs.s.h = 0x01;
} break;
#endif

View File

@@ -6,7 +6,7 @@ bpl(0x10, !regs.p.n),
bmi(0x30, regs.p.n),
bvc(0x50, !regs.p.v),
bvs(0x70, regs.p.v) {
1:if(!$1)last_cycle();
1:if(!$1) last_cycle();
rd.l = op_readpc();
if($1) {
aa.w = regs.pc.d + (int8)rd.l;
@@ -102,7 +102,7 @@ jsr_long(0x22) {
7:last_cycle();
op_writestackn(regs.pc.l);
regs.pc.d = aa.d & 0xffffff;
if(regs.e)regs.s.h = 0x01;
if(regs.e) regs.s.h = 0x01;
}
jsr_iaddrx(0xfc) {
@@ -115,20 +115,20 @@ jsr_iaddrx(0xfc) {
7:last_cycle();
rd.h = op_readpbr(aa.w + regs.x.w + 1);
regs.pc.w = rd.w;
if(regs.e)regs.s.h = 0x01;
if(regs.e) regs.s.h = 0x01;
}
rti(0x40) {
1:op_io();
2:op_io();
3:regs.p = op_readstack();
if(regs.e)regs.p |= 0x30;
if(regs.e) regs.p |= 0x30;
if(regs.p.x) {
regs.x.h = 0x00;
regs.y.h = 0x00;
}
4:rd.l = op_readstack();
5:if(regs.e)last_cycle();
5:if(regs.e) last_cycle();
rd.h = op_readstack();
if(regs.e) {
regs.pc.w = rd.w;
@@ -159,5 +159,5 @@ rtl(0x6b) {
rd.b = op_readstackn();
regs.pc.d = rd.d & 0xffffff;
regs.pc.w++;
if(regs.e)regs.s.h = 0x01;
if(regs.e) regs.s.h = 0x01;
}

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