Compare commits

..

19 Commits
v033 ... v036

Author SHA1 Message Date
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
199 changed files with 4334 additions and 3185 deletions

View File

@@ -53,22 +53,19 @@ 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 decompressor, author: NSRT Team, license: GPL (*)
JMA decompressor, author: NSRT Team, license: GPL*
NTSC filter, author: blargg, license: LGPL
zlib decompressor, license: zlib license
(*) bsnes has received an exemption from the copyright holder to use this work.
(* bsnes has received an exemption from the copyright holder to use this work.)
The software also includes works which have been released to the public domain,
which are not bound to any licensing agreements. Below is a complete list of all
such software.
libco, author: byuu
libui, author: byuu
OBC-1 emu, author: byuu
S-DD1 decompressor, author: Andreas Naive
SPC7110 decompressor, author: neviksti
S-RTC emu, author: byuu
Any software listed above as exemptions may be relicensed individually from
bsnes under their respective terms. However, no bsnes licensed portions can be

View File

@@ -1,10 +1,11 @@
bsnes
Version: 0.033
Version: 0.036
Author: byuu
========
General:
========
bsnes is a Super Nintendo / Super Famicom emulator that began on
October 14th, 2004.
@@ -16,6 +17,7 @@ Please see license.txt for important licensing information.
==============
Configuration:
==============
bsnes has two configuration files: bsnes.cfg, for program settings; and
locale.cfg, for localization.
@@ -36,11 +38,13 @@ If you wish to have multiple configuration profiles for the same user, you will
need to make copies of the bsnes executable, and use each one in single-user
mode.
==================
Known Limitations:
==================
====================
Known Limitation(s):
====================
S-CPU
- Multiply / divide register delays not implemented
- "Glitch" when reading joypad registers during auto polling not implemented
S-PPU
- Uses scanline-based renderer. This is very inaccurate, but few (if any)
@@ -56,9 +60,20 @@ Hardware Bugs
- S-CPU.r1 HDMA crashing bug not emulated
- S-CPU<>S-SMP communication bus conflicts not emulated
===============
Known Issue(s):
===============
On Windows, attempting to load a ZIP, GZ or JMA compressed archive with
non-ANSI characters in the filename will fail. This is because Windows
requires UTF-16 encoding, but these libraries only work with UTF-8.
Note that loading uncompressed images (SMC, SFC, etc) with non-ANSI characters
works properly on all platforms.
=====================
Unsupported Hardware:
=====================
SA-1
Coprocessor used in many popular games, including:
- Dragon Ball Z Hyper Dimension
@@ -84,10 +99,18 @@ SETA RISC CPU used by Quick-move Shogi Match with Nidan Rank-holder Morita 2
Super Gameboy
Cartridge passthrough used for playing Gameboy games
========================
Unsupported Controllers:
========================
==========================
Unsupported Controller(s):
==========================
Mouse
Super Scope
Justifier
Multitap (4-port and 5-port)
=============
Contributors:
=============
Andreas Naive, anomie, blargg, DMV27, FitzRoy, GIGO, Jonas Quinn, kode54, krom,
mudlord, Nach, neviksti, Overload, RedDwarf, Richard Bannister, tetsuo55, TRAC,
zones

View File

@@ -133,7 +133,7 @@ obj/bsnesrc.$(obj): ui/bsnes.rc; windres ui/bsnes.rc obj/bsnesrc.$(obj)
### libraries ###
#################
obj/ruby.$(obj): lib/ruby/ruby.cpp lib/ruby/*
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`))

View File

@@ -1,4 +1,4 @@
#define BSNES_VERSION "0.033"
#define BSNES_VERSION "0.036"
#define BSNES_TITLE "bsnes v" BSNES_VERSION
#define BUSCORE sBus
@@ -24,6 +24,7 @@
#include <nall/bit.hpp>
#include <nall/config.hpp>
#include <nall/detect.hpp>
#include <nall/file.hpp>
#include <nall/function.hpp>
#include <nall/modulo.hpp>
#include <nall/new.hpp>
@@ -39,18 +40,11 @@ using namespace nall;
//platform-specific global functions
void alert(const char*, ...);
void dprintf(const char*, ...);
void dprintf(uint, const char*, ...);
namespace source {
enum {
none = 0,
debug,
cpu,
ppu,
smp,
dsp,
bus,
};
};
#include "interface.h"
//helper: disable access to FILE, when possible (GZIP / JMA require it)
//reason: Windows fopen() does not support UTF-8 filenames; use nall::file instead.
#if !defined(GZIP_SUPPORT) && !defined(JMA_SUPPORT)
#define FILE FILE_deprecated
#endif

View File

@@ -38,6 +38,7 @@ void Cartridge::load_begin(CartridgeType cart_type) {
stB.rom_size = stB.ram_size = 0;
info.type = cart_type;
info.patched = false;
info.bsxbase = false;
info.bsxcart = false;
@@ -64,7 +65,6 @@ void Cartridge::load_begin(CartridgeType cart_type) {
info.header_index = 0xffc0;
info.mapper = LoROM;
info.name[0] = 0;
info.region = NTSC;
info.rom_size = 0;
@@ -89,7 +89,7 @@ void Cartridge::load_end() {
memory::stBrom.write_protect(true);
memory::stBram.write_protect(false);
if(fexists(get_cheat_filename(cart.fn, "cht"))) {
if(file::exists(get_cheat_filename(cart.fn, "cht"))) {
cheat.clear();
cheat.load(cheatfn);
}
@@ -122,7 +122,7 @@ bool Cartridge::unload() {
char fn[PATH_MAX];
strcpy(fn, cart.fn);
modify_extension(fn, "cht");
if(cheat.count() > 0 || fexists(get_cheat_filename(cart.fn, "cht"))) {
if(cheat.count() > 0 || file::exists(get_cheat_filename(cart.fn, "cht"))) {
cheat.save(cheatfn);
cheat.clear();
}

View File

@@ -18,8 +18,7 @@ public:
VERSION = 0x1b,
ICKSUM = 0x1c,
CKSUM = 0x1e,
RESL = 0x3c,
RESH = 0x3d,
RESETV = 0x3c,
};
enum Region {
@@ -70,7 +69,7 @@ public:
uint32 crc32;
char filename[PATH_MAX * 4];
char name[128];
bool patched;
Region region;
MemoryMapper mapper;
@@ -120,6 +119,7 @@ public:
void load_end();
bool unload();
unsigned score_header(unsigned);
void find_header();
void read_header();
void read_extended_header();

View File

@@ -1,27 +1,27 @@
#ifdef CART_CPP
#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
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;
#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
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")
@@ -47,36 +47,38 @@ char* Cartridge::get_base_filename(char *filename) {
break;
}
}
}
char* Cartridge::get_path_filename(char *filename, const char *path, const char *source, const char *extension) {
strcpy(filename, source);
for(char *p = filename; *p; p++) { if(*p == '\\') *p = '/'; }
return filename;
}
char* Cartridge::get_path_filename(char *filename, const char *path, const char *source, const char *extension) {
strcpy(filename, source);
for(char *p = filename; *p; p++) { if(*p == '\\') *p = '/'; }
modify_extension(filename, extension);
//override path with user-specified folder, if one was defined
//override path with user-specified folder, if one was defined
if(*path) {
lstring part;
split(part, "/", filename);
string fn = path;
if(strend(fn, "/") == false) strcat(fn, "/");
strcat(fn, part[count(part) - 1]);
strcpy(filename, fn);
//resolve relative path, if found
if(strbegin(fn, "./") == true) {
ltrim(fn, "./");
strcpy(filename, config::path.base);
strcat(filename, fn);
}
}
return filename;
lstring part;
split(part, "/", filename);
string fn = path;
if(strend(fn, "/") == false) strcat(fn, "/");
strcat(fn, part[count(part) - 1]);
strcpy(filename, fn);
//resolve relative path, if found
if(strbegin(fn, "./") == true) {
ltrim(fn, "./");
strcpy(filename, config::path.base);
strcat(filename, fn);
}
}
return filename;
}
char* Cartridge::get_patch_filename(const char *source, const char *extension) {
return get_path_filename(patchfn, config::path.patch, source, extension);
}
}
char* Cartridge::get_save_filename(const char *source, const char *extension) {
return get_path_filename(savefn, config::path.save, source, extension);
@@ -85,63 +87,65 @@ char* Cartridge::get_save_filename(const char *source, const char *extension) {
char* Cartridge::get_cheat_filename(const char *source, const char *extension) {
return get_path_filename(cheatfn, config::path.cheat, source, extension);
}
bool Cartridge::load_file(const char *fn, uint8 *&data, uint &size, CompressionMode compression) {
dprintf("* Loading \"%s\" ...", fn);
if(fexists(fn) == false) return false;
bool Cartridge::load_file(const char *fn, uint8 *&data, uint &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, config::file.autodetect_type);
switch(filetype) {
switch(filetype) {
default:
dprintf("* Warning: filetype detected as unsupported compression type.");
dprintf("* Will attempt to load as uncompressed file -- may fail.");
case Reader::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::GZIP: {
GZReader gf(fn);
if(!gf.ready()) {
alert("Error loading image file (%s)!", fn);
return false;
}
size = gf.size();
data = gf.read();
} break;
case Reader::ZIP: {
ZipReader zf(fn);
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) {
alert("Error loading image file (%s)!", fn);
return false;
}
} break;
#endif
}
return true;
dprintf("* Will attempt to load as uncompressed file -- may fail.");
case Reader::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::GZIP: {
GZReader gf(fn);
if(!gf.ready()) {
alert("Error loading image file (%s)!", fn);
return false;
}
size = gf.size();
data = gf.read();
} break;
case Reader::ZIP: {
ZipReader zf(fn);
if(!zf.ready()) {
alert("Error loading image file (%s)!", fn);
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) {
alert("Error loading image file (%s)!", fn);
return false;
}
} break;
#endif
}
return true;
}
bool Cartridge::apply_patch(const uint8_t *pdata, const unsigned psize, uint8_t *&data, unsigned &size) {
@@ -157,23 +161,23 @@ bool Cartridge::apply_patch(const uint8_t *pdata, const unsigned psize, uint8_t
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);
} else {
dprintf("* Warning: patch application failed!");
}
if(outdata) delete[] outdata;
}
return apply;
}
bool Cartridge::save_file(const char *fn, uint8 *data, uint size) {
FILE *fp = fopen(fn, "wb");
if(!fp) return false;
fwrite(data, 1, size, fp);
fclose(fp);
file fp;
if(!fp.open(fn, file::mode_write)) return false;
fp.write(data, size);
fp.close();
return true;
}
}
#endif //ifdef CART_CPP

View File

@@ -5,6 +5,7 @@ void Cartridge::read_header() {
uint index = info.header_index;
uint8 mapper = rom[index + MAPPER];
uint8 rom_type = rom[index + ROM_TYPE];
uint8 rom_size = rom[index + ROM_SIZE];
uint8 company = rom[index + COMPANY];
uint8 region = rom[index + REGION] & 0x7f;
@@ -99,13 +100,14 @@ void Cartridge::read_header() {
info.obc1 = true;
}
if(mapper == 0x30 && rom_type == 0xf6) {
//TODO: both ST010 and ST011 share the same mapper + rom_type.
//need way to determine which is which.
//for now, default to supported ST010.
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;
}
@@ -118,70 +120,95 @@ void Cartridge::read_header() {
//0, 1, 13 = NTSC; 2 - 12 = PAL
info.region = (region <= 1 || region >= 13) ? NTSC : PAL;
}
memcpy(&info.name, &rom[info.header_index + CART_NAME], 21);
info.name[21] = 0;
trim(info.name);
unsigned Cartridge::score_header(unsigned addr) {
if(cart.rom_size < addr + 64) return 0; //image too small to contain header at this location?
uint8 *rom = cart.rom;
int score = 0;
//convert undisplayable characters (half-width katakana, etc) to '?' characters
for(int i = 0; i < 21; i++) {
if(info.name[i] & 0x80) info.name[i] = '?';
}
uint16 resetvector = rom[addr + RESETV] | (rom[addr + RESETV + 1] << 8);
uint16 checksum = rom[addr + CKSUM] | (rom[addr + CKSUM + 1] << 8);
uint16 ichecksum = rom[addr + ICKSUM] | (rom[addr + ICKSUM + 1] << 8);
//always display something
if(!info.name[0]) strcpy(info.name, "(untitled)");
uint8 resetop = rom[(addr & ~0x7fff) | (resetvector & 0x7fff)]; //first opcode executed upon reset
uint8 mapper = rom[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 + ichecksum) == 0xffff && (checksum != 0) && (ichecksum != 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(rom[addr + COMPANY] == 0x33) score += 2; //0x33 indicates extended header
if(rom[addr + ROM_TYPE] < 0x08) score++;
if(rom[addr + ROM_SIZE] < 0x10) score++;
if(rom[addr + RAM_SIZE] < 0x08) score++;
if(rom[addr + REGION] < 14) score++;
if(score < 0) score = 0;
return score;
}
void Cartridge::find_header() {
int32 score_lo = 0, score_hi = 0, score_ex = 0;
uint8_t *rom = cart.rom;
if(cart.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 + COMPANY] < 3) score_lo++;
if(rom[0xffc0 + COMPANY] < 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(cart.rom_size < 0x401000) {
score_ex = 0;
} else {
if(rom[0x7fc0 + MAPPER] == 0x32) score_lo++;
else score_ex += 12;
}
unsigned score_lo = score_header(0x007fc0);
unsigned score_hi = score_header(0x00ffc0);
unsigned score_ex = score_header(0x40ffc0);
if(score_ex) score_ex += 4; //favor ExHiROM on images > 32mbits
if(score_lo >= score_hi && score_lo >= score_ex) {
info.header_index = 0x007fc0;

View File

@@ -23,6 +23,7 @@ void Cartridge::load_cart_normal(const char *filename) {
if(load_file(get_patch_filename(cart.fn, "ups"), data, size, CompressionInspect) == true) {
apply_patch(data, size, cart.rom, cart.rom_size);
delete[] data;
info.patched = true;
}
info.crc32 = crc32_calculate(cart.rom, cart.rom_size);

View File

@@ -147,7 +147,7 @@ bool Cheat::read(uint32 addr, uint8 &data) {
* 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 < cheat_count; i++) {
@@ -295,15 +295,15 @@ bool Cheat::load(const char *fn) {
}
bool Cheat::save(const char *fn) {
FILE *fp = fopen(fn, "wb");
if(!fp) return false;
file fp;
if(!fp.open(fn, file::mode_write)) return false;
for(unsigned i = 0; i < cheat_count; i++) {
fprintf(fp, "%9s = %8s, \"%s\"\r\n",
index[i].code,
index[i].enabled ? "enabled" : "disabled",
index[i].desc);
fp.print(string()
<< index[i].code << " = "
<< (index[i].enabled ? "enabled" : "disabled") << ", \""
<< index[i].desc << "\"\r\n");
}
fclose(fp);
fp.close();
return true;
}

View File

@@ -1,697 +0,0 @@
const uint8_t SPC7110Codec::EvolutionTable[53][4] = {
//prob, nextlps, nextmps, toggle invert
{0x5a, 1, 1,1}, //0 l,m
{0x25, 6, 2,0}, //1 l,m
{0x11, 8, 3,0}, //2 l,m
{0x08, 10, 4,0}, //3 ,m
{0x03, 12, 5,0}, //4 ,m
{0x01, 15, 5,0}, //5 ,m
{0x5a, 7, 7,1}, //6 l,
{0x3f, 19, 8,0}, //7 l,m
{0x2c, 21, 9,0}, //8 l,m
{0x20, 22, 10,0}, //9 ,m
{0x17, 23, 11,0}, //10 ,m
{0x11, 25, 12,0}, //11 ,m
{0x0c, 26, 13,0}, //12 ,m
{0x09, 28, 14,0}, //13 ,m
{0x07, 29, 15,0}, //14 ,m
{0x05, 31, 16,0}, //15 ,m
{0x04, 32, 17,0}, //16 ,m
{0x03, 34, 18,0}, //17 ,m
{0x02, 35, 5,0}, //18 ,m
{0x5a, 20, 20,1}, //19 l,m
{0x48, 39, 21,0}, //20 l,m
{0x3a, 40, 22,0}, //21 l,m
{0x2e, 42, 23,0}, //22 l,m
{0x26, 44, 24,0}, //23 l,m
{0x1f, 45, 25,0}, //24 l,m
{0x19, 46, 26,0}, //25 l,m
{0x15, 25, 27,0}, //26 l,m
{0x11, 26, 28,0}, //27 l,m
{0x0e, 26, 29,0}, //28 l,m
{0x0b, 27, 30,0}, //29 ,m
{0x09, 28, 31,0}, //30 ,m
{0x08, 29, 32,0}, //31 l,m
{0x07, 30, 33,0}, //32 l,m
{0x05, 31, 34,0}, //33 l,m <--- changed lps
{0x04, 33, 35,0}, //34 ,m ... this is NOT skipped
{0x04, 33, 36,0}, //35 ,m
{0x03, 34, 37,0}, //36 ,m
{0x02, 35, 38,0}, //37 ,m ... this is NOT skipped
{0x02, 36, 5,0}, //38 ,m
{0x58, 39, 40,1}, //39 l,m
{0x4d, 47, 41,0}, //40 l,m
{0x43, 48, 42,0}, //41 ,m
{0x3b, 49, 43,0}, //42 ,m
{0x34, 50, 44,0}, //43 l,m
{0x2e, 51, 45,0}, //44 l,m
{0x29, 44, 46,0}, //45 l,m
{0x25, 45, 24,0}, //46 ,m
{0x56, 47, 48,1}, //47 l,m
{0x4f, 47, 49,0}, //48 l,m
{0x47, 48, 50,0}, //49 l,m
{0x41, 49, 51,0}, //50 l,m
{0x3c, 50, 52,0}, //51 l,m
{0x37, 51, 43,0} //52 ,m
};
const uint8_t SPC7110Codec::Mode2ContextTable[32][4] = {
// "bit" = (lps^invert)
//next_0, use ref pixel, next_1, use ref pixel
// if use ref pixel, then add on the 0-4 bell number grouping
{1, 0, 2, 0}, //0
{3, 1, 8, 1}, //1 prev bit 0
{13,0, 14,0}, //2 prev bit 1
{15,0, 16,0}, //3 prev bit 00
{17,0, 18,0}, //4
{19,0, 20,0}, //5
{21,0, 22,0}, //6
{23,0, 24,0}, //7
{25,0, 26,0}, //8 prev bit 01
{25,0, 26,0}, //9
{25,0, 26,0}, //10
{25,0, 26,0}, //11
{25,0, 26,0}, //12
{27,0, 28,0}, //13 prev bit 10
{29,0, 30,0}, //14 prev bit 11
{31,0, 31,0}, //15 000 ref group 0
{31,0, 31,0}, //16 001 ref group 0
{31,0, 31,0}, //17 000 ref group 1
{31,0, 31,0}, //18 001 ref group 1
{31,0, 31,0}, //19 000 ref group 2
{31,0, 31,0}, //20 001 ref group 2
{31,0, 31,0}, //21 000 ref group 3
{31,0, 31,0}, //22 001 ref group 3
{31,0, 31,0}, //23 000 ref group 4
{31,0, 31,0}, //24 001 ref group 4
{31,0, 31,0}, //25 010
{31,0, 31,0}, //26 011
{31,0, 31,0}, //27 100
{31,0, 31,0}, //28 101
{31,0, 31,0}, //29 110
{31,0, 31,0}, //30 111
{31,0, 31,0} //31 -- used as a trap for testing purposes --
};
#define PROB(x) EvolutionTable[Contexts[x].index][0]
#define NEXT_LPS(x) EvolutionTable[Contexts[x].index][1]
#define NEXT_MPS(x) EvolutionTable[Contexts[x].index][2]
#define TOGGLE_INVERT(x) EvolutionTable[Contexts[x].index][3]
#define BIT(x,y) ((x>>y)&1)
void SPC7110Codec::decomp_mode0(int len) {
uint8_t *datain = buffer;
uint8_t *dataout = output;
static const unsigned NUM_CONTEXTS = 30;
uint8 top,val;
uint8 con,mps,prob;
uint8 flag_lps,shift,mask;
int out=0;
int inverts=0;
int lps=0;
unsigned char in;
int in_count;
int i,bit;
//setup
top=0xFF;
val=*datain;
datain++;
in=*datain;
datain++;
in_count=8;
//reset context states
for(i=0;i<NUM_CONTEXTS;i++)
{
Contexts[i].index=0;
Contexts[i].invert=0;
}
for(i=0;i<len;i++)
{
if(i==-1800)
{
int k;
printf("\nEvolution table:\n");
//for(k=0;k<53;k++)
//printf(" %d,%d //%d\n",SeenEvolution[k][0],SeenEvolution[k][1],k);
}
for(bit=0;bit<8;bit++)
{
//get context
mask = (1<<(bit&3)) - 1;
con = mask + ((inverts&mask)^(lps&mask));
if(bit>3)
con+=15;
//get PROB and MPS
prob = PROB(con);
mps = (BIT(out,15) ^ Contexts[con].invert);
if(i>=15 && i<=18 && 0)
printf("byte %d bit %d: val=%.2X top=%.2X prob=%.2X mps=%d con=%d state=%d\n",
i,bit,val,top,prob,mps,con,Contexts[con].index);
//get bit
if (val <= top-prob)
{
//mps
top = top - prob;
out = (out << 1) + mps;
flag_lps=0;
}
else
{
//lps
val = val - (top - (prob - 1));
top = prob - 1;
out = (out << 1) + 1-mps;
flag_lps=1;
}
// renormalize
shift=0;
while(top<0x7F) // NOTE: not 0x80, it's a strange border case
{
shift++;
top = (top<<1)+1;
val = (val<<1)+(in>>7);
in = (in<<1);
if(--in_count==0)
{
in=*datain;
datain++;
in_count=8;
}
}
//update processing info
lps = (lps<<1) + flag_lps;
inverts = (inverts<<1) + Contexts[con].invert;
//update context state
if(flag_lps & TOGGLE_INVERT(con))
Contexts[con].invert ^= 1;
if(flag_lps)
{
//SeenEvolution[Contexts[con].index][0]=1;
Contexts[con].index = NEXT_LPS(con);
}
else if(shift)
{
//SeenEvolution[Contexts[con].index][1]=1;
Contexts[con].index = NEXT_MPS(con);
}
}
//save byte
*dataout = (out & 0xFF);
dataout++;
}
}
void SPC7110Codec::decomp_mode1(int len) {
uint8_t *datain = buffer;
uint8_t *dataout = output;
static const unsigned NUM_CONTEXTS = 15;
int pixelorder[4]={0,1,2,3};
int realorder[4];
int a,b,c;
int m,n;
uint8 top,val;
uint8 con,prob;
uint8 flag_lps,shift;
int out=0;
int inverts=0;
int lps=0;
unsigned char in;
int in_count;
int in_len=0;
int i,j,pixel;
//setup
top=0xFF;
val=datain[in_len++];
in=datain[in_len++];
in_count=8;
//reset context states
for(i=0;i<NUM_CONTEXTS;i++)
{
Contexts[i].index=0;
Contexts[i].invert=0;
}
for(i=0;i<len;i+=2)
{
if(i!=0)
{
//turn pixel data into bitplanes
//and save as output
*dataout = (BIT(out,15)<<7) + (BIT(out,13)<<6) + (BIT(out,11)<<5) + (BIT(out,9)<<4)
+ (BIT(out,7)<<3) + (BIT(out,5)<<2) + (BIT(out,3)<<1) + BIT(out,1);
dataout++;
*dataout = (BIT(out,14)<<7) + (BIT(out,12)<<6) + (BIT(out,10)<<5) + (BIT(out,8)<<4)
+ (BIT(out,6)<<3) + (BIT(out,4)<<2) + (BIT(out,2)<<1) + BIT(out,0);
dataout++;
}
for(pixel=0;pixel<8;pixel++)
{
//get first symbol context
a = ((out >> (1*2)) & 0x3);
b = ((out >> (7*2)) & 0x3);
c = ((out >> (8*2)) & 0x3);
if(a==b && b==c)
con=0;
else if (a==b && b!=c)
con=1;
else if (a!=b && b==c)
con=2;
else if (a==c && b!=c)
con=3;
else
con=4;
//update pixel order
for(m=0;m<4;m++)
if(pixelorder[m]==a)
break;
for(n=m;n>0;n--)
{
j=pixelorder[n-1];
pixelorder[n-1]=pixelorder[n];
pixelorder[n]=j;
}
//get PROB
prob = PROB(con);
//get symbol
if (val <= top-prob)
{
//mps
top = top - prob;
flag_lps=0;
}
else
{
//lps
val = val - (top - (prob - 1));
top = prob - 1;
flag_lps=1;
}
// renormalize
shift=0;
while(top<0x7F)
{
shift++;
top = (top<<1)+1;
val = (val<<1)+(in>>7);
in = (in<<1);
if(--in_count==0)
{
in=datain[in_len++];
in_count=8;
}
}
//update processing info
lps = (lps<<1) + flag_lps;
inverts = (inverts<<1) + Contexts[con].invert;
//update context state
if(flag_lps & TOGGLE_INVERT(con))
Contexts[con].invert ^= 1;
if(flag_lps)
Contexts[con].index = NEXT_LPS(con);
else if(shift)
Contexts[con].index = NEXT_MPS(con);
//get context of second symbol
con = 5 + con*2 + ((lps^inverts)&1);
//get PROB
prob = PROB(con);
//get symbol
if (val <= top-prob)
{
//mps
top = top - prob;
flag_lps=0;
}
else
{
//lps
val = val - (top - (prob - 1));
top = prob - 1;
flag_lps=1;
}
// renormalize
shift=0;
while(top<0x7F)
{
shift++;
top = (top<<1)+1;
val = (val<<1)+(in>>7);
in = (in<<1);
if(--in_count==0)
{
in=datain[in_len++];
in_count=8;
}
}
//calculate the real pixel order
for(m=0;m<4;m++)
realorder[m]=pixelorder[m];
//shift refence pixel c value to top
for(m=0;m<4;m++)
if(realorder[m]==c)
break;
for(n=m;n>0;n--)
{
j=realorder[n-1];
realorder[n-1]=realorder[n];
realorder[n]=j;
}
//shift refence pixel b value to top
for(m=0;m<4;m++)
if(realorder[m]==b)
break;
for(n=m;n>0;n--)
{
j=realorder[n-1];
realorder[n-1]=realorder[n];
realorder[n]=j;
}
//shift refence pixel a value to top
for(m=0;m<4;m++)
if(realorder[m]==a)
break;
for(n=m;n>0;n--)
{
j=realorder[n-1];
realorder[n-1]=realorder[n];
realorder[n]=j;
}
//update processing info
lps = (lps<<1) + flag_lps;
inverts = (inverts<<1) + Contexts[con].invert;
//update context state
if(flag_lps & TOGGLE_INVERT(con))
Contexts[con].invert ^= 1;
if(flag_lps)
Contexts[con].index = NEXT_LPS(con);
else if(shift)
Contexts[con].index = NEXT_MPS(con);
//get pixel
b=realorder[(lps^inverts)&3];
out = (out<<2) + b;
}
}
//turn pixel data into bitplanes
//and save as output.. BUT don't save second byte unless asked to
*dataout = (BIT(out,15)<<7) + (BIT(out,13)<<6) + (BIT(out,11)<<5) + (BIT(out,9)<<4)
+ (BIT(out,7)<<3) + (BIT(out,5)<<2) + (BIT(out,3)<<1) + BIT(out,1);
dataout++;
if((len&1)==0)
{
*dataout = (BIT(out,14)<<7) + (BIT(out,12)<<6) + (BIT(out,10)<<5) + (BIT(out,8)<<4)
+ (BIT(out,6)<<3) + (BIT(out,4)<<2) + (BIT(out,2)<<1) + BIT(out,0);
dataout++;
}
if(in_count==8)
in_len--;
//printf("Used %d bytes of input.\n",in_len);
//return in_len;
}
void SPC7110Codec::decomp_mode2(int len) {
uint8_t *datain = buffer;
uint8_t *dataout = output;
static const unsigned NUM_CONTEXTS = 32;
int pixelorder[16]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
int realorder[16];
int a,b,c;
int m,n;
uint8 bitplanebuffer[16];
uint8 buf_idx=0;
uint8 top,val,prob;
uint8 con,refcon;
uint8 flag_lps,invertbit,shift;
int out=0;
int out2=0;
int inverts=0;
int lps=0;
unsigned char in;
int in_count;
int in_len=0;
int i,j,pixel,bit;
//setup
top=0xFF;
val=datain[in_len++];
in=datain[in_len++];
in_count=8;
//reset context states
for(i=0;i<NUM_CONTEXTS;i++)
{
Contexts[i].index=0;
Contexts[i].invert=0;
}
for(i=0;i<len;i+=2)
{
for(pixel=0;pixel<8;pixel++)
{
//get first symbol context
a = ((out >> (0*4)) & 0x0F);
b = ((out >> (7*4)) & 0x0F);
c = ((out2>> (0*4)) & 0x0F);
if(a==b && b==c)
refcon=0;
else if (a==b && b!=c)
refcon=1;
else if (a!=b && b==c)
refcon=2;
else if (a==c && b!=c)
refcon=3;
else
refcon=4;
con=0;
//update pixel order
for(m=0;m<16;m++)
if(pixelorder[m]==a)
break;
for(n=m;n>0;n--)
{
j=pixelorder[n-1];
pixelorder[n-1]=pixelorder[n];
pixelorder[n]=j;
}
//calculate the real pixel order
for(m=0;m<16;m++)
realorder[m]=pixelorder[m];
//shift refence pixel c value to top
for(m=0;m<16;m++)
if(realorder[m]==c)
break;
for(n=m;n>0;n--)
{
j=realorder[n-1];
realorder[n-1]=realorder[n];
realorder[n]=j;
}
//shift refence pixel b value to top
for(m=0;m<16;m++)
if(realorder[m]==b)
break;
for(n=m;n>0;n--)
{
j=realorder[n-1];
realorder[n-1]=realorder[n];
realorder[n]=j;
}
//shift refence pixel a value to top
for(m=0;m<16;m++)
if(realorder[m]==a)
break;
for(n=m;n>0;n--)
{
j=realorder[n-1];
realorder[n-1]=realorder[n];
realorder[n]=j;
}
//get 4 symbols
for(bit=0;bit<4;bit++)
{
//get PROB
prob = PROB(con);
//get symbol
if (val <= top-prob)
{
//mps
top = top - prob;
flag_lps=0;
}
else
{
//lps
val = val - (top - (prob - 1));
top = prob - 1;
flag_lps=1;
}
// renormalize
shift=0;
while(top<0x7F)
{
shift++;
top = (top<<1)+1;
val = (val<<1)+(in>>7);
in = (in<<1);
if(--in_count==0)
{
in=datain[in_len++];
in_count=8;
}
}
//update processing info
lps = (lps<<1) + flag_lps;
invertbit = Contexts[con].invert;
inverts = (inverts<<1) + Contexts[con].invert;
//update context state
if(flag_lps & TOGGLE_INVERT(con))
Contexts[con].invert ^= 1;
if(flag_lps)
Contexts[con].index = NEXT_LPS(con);
else if(shift)
Contexts[con].index = NEXT_MPS(con);
//get next context
if(Mode2ContextTable[con][2*(flag_lps^invertbit)+1])
con=Mode2ContextTable[con][2*(flag_lps^invertbit)]+refcon;
else
con=Mode2ContextTable[con][2*(flag_lps^invertbit)];
}
//get pixel
b=realorder[(lps^inverts)&0x0F];
out2 = (out2<<4) + ((out>>28)&0x0F);
out = (out<<4) + b;
}
//cludge to convert pixel data into bitplanes and respect len parameter for output buf
*dataout = (BIT(out,31)<<7) + (BIT(out,27)<<6) + (BIT(out,23)<<5) + (BIT(out,19)<<4)
+ (BIT(out,15)<<3) + (BIT(out,11)<<2) + (BIT(out,7)<<1) + BIT(out,3);
dataout++;
if((i+1)<len)
{
*dataout = (BIT(out,30)<<7) + (BIT(out,26)<<6) + (BIT(out,22)<<5) + (BIT(out,18)<<4)
+ (BIT(out,14)<<3) + (BIT(out,10)<<2) + (BIT(out,6)<<1) + BIT(out,2);
dataout++;
}
bitplanebuffer[buf_idx++] =
(BIT(out,29)<<7) + (BIT(out,25)<<6) + (BIT(out,21)<<5) + (BIT(out,17)<<4)
+ (BIT(out,13)<<3) + (BIT(out,9)<<2) + (BIT(out,5)<<1) + BIT(out,1);
bitplanebuffer[buf_idx++] =
(BIT(out,28)<<7) + (BIT(out,24)<<6) + (BIT(out,20)<<5) + (BIT(out,16)<<4)
+ (BIT(out,12)<<3) + (BIT(out,8)<<2) + (BIT(out,4)<<1) + BIT(out,0);
if(buf_idx==16)
{
for(m=0;m<16 && i+2<len;m++,i++)
{
*dataout = bitplanebuffer[m];
dataout++;
}
buf_idx=0;
}
}
if(in_count==8)
in_len--;
//printf("Used %d bytes of input.\n",in_len);
//return in_len;
}
#undef PROB
#undef NEXT_LPS
#undef NEXT_MPS
#undef TOGGLE_INVERT
#undef BIT
SPC7110Codec::SPC7110Codec() {
buffer = new(zeromemory) uint8_t[65536];
output = new(zeromemory) uint8_t[65536];
}
SPC7110Codec::~SPC7110Codec() {
delete[] buffer;
delete[] output;
}

View File

@@ -1,20 +0,0 @@
class SPC7110Codec {
public:
uint8_t *buffer;
uint8_t *output;
void decomp_mode0(int len);
void decomp_mode1(int len);
void decomp_mode2(int len);
SPC7110Codec();
~SPC7110Codec();
private:
static const uint8_t EvolutionTable[53][4];
static const uint8_t Mode2ContextTable[32][4];
struct ContextState {
uint8_t index;
uint8_t invert;
} Contexts[32];
};

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

45
src/chip/spc7110/decomp.h Normal file
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

@@ -1,7 +1,7 @@
#include "../../base.h"
#define SPC7110_CPP
#include "codec.cpp"
#include "decomp.cpp"
const unsigned SPC7110::months[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
@@ -30,9 +30,7 @@ void SPC7110::reset() {
r480b = 0x00;
r480c = 0x00;
memset(codec.output, 0, 65536);
memset(codec.buffer, 0, 65536);
decomp_offset = 0;
decomp.reset();
r4811 = 0x00;
r4812 = 0x00;
@@ -189,7 +187,7 @@ uint8 SPC7110::mmio_read(uint addr) {
counter--;
r4809 = counter;
r480a = counter >> 8;
return codec.output[(decomp_offset++) & 0xffff];
return decomp.read();
}
case 0x4801: return r4801;
case 0x4802: return r4802;
@@ -213,7 +211,7 @@ uint8 SPC7110::mmio_read(uint addr) {
//==============
case 0x4810: {
if(r481x != 0x1f) return 0x00;
if(r481x != 0x07) return 0x00;
unsigned addr = data_pointer();
unsigned adjust = data_adjust();
@@ -248,7 +246,7 @@ uint8 SPC7110::mmio_read(uint addr) {
case 0x4817: return r4817;
case 0x4818: return r4818;
case 0x481a: {
if(r481x != 0x1f) return 0x00;
if(r481x != 0x07) return 0x00;
unsigned addr = data_pointer();
unsigned adjust = data_adjust();
@@ -349,27 +347,7 @@ void SPC7110::mmio_write(uint addr, uint8 data) {
+ (memory::cartrom.read(addr + 2) << 8)
+ (memory::cartrom.read(addr + 3) << 0);
//this can technically be 65536, but it has never been observed higher than 32768 ...
//really need a way to determine both compressed and decompressed lengths, though.
static const unsigned max_length = 32768;
offset = datarom_addr(offset);
for(unsigned i = 0; i < max_length; i++) codec.buffer[i] = memory::cartrom.read(offset + i);
#if 0
printf("decompression: 4805=$%0.2x,4806=$%0.2x,4807=$%0.2x,4808=$%0.2x,480b=$%0.2x\n",
r4805, r4806, r4807, r4808, r480b);
printf("table=$%0.6x,index=%3d,length=%5d,mode=%d,offset=$%0.6x\n",
table, r4804, length, mode, offset);
#endif
switch(mode) {
case 0: codec.decomp_mode0(max_length); break;
case 1: codec.decomp_mode1(max_length); break;
case 2: codec.decomp_mode2(max_length); break;
}
decomp_offset = (r4805 + (r4806 << 8)) << mode;
decomp.init(mode, offset, (r4805 + (r4806 << 8)) << mode);
r480c = 0x80;
} break;
@@ -388,7 +366,6 @@ void SPC7110::mmio_write(uint addr, uint8 data) {
case 0x4813: r4813 = data; r481x |= 0x04; break;
case 0x4814: {
r4814 = data;
r481x |= 0x08;
r4814_latch = true;
if(!r4815_latch) break;
if(!(r4818 & 2)) break;
@@ -406,7 +383,6 @@ void SPC7110::mmio_write(uint addr, uint8 data) {
} break;
case 0x4815: {
r4815 = data;
r481x |= 0x10;
r4815_latch = true;
if(!r4814_latch) break;
if(!(r4818 & 2)) break;
@@ -425,7 +401,7 @@ void SPC7110::mmio_write(uint addr, uint8 data) {
case 0x4816: r4816 = data; break;
case 0x4817: r4817 = data; break;
case 0x4818: {
if(r481x != 0x1f) break;
if(r481x != 0x07) break;
r4818 = data;
r4814_latch = r4815_latch = false;
@@ -640,26 +616,18 @@ void SPC7110::mmio_write(uint addr, uint8 data) {
}
uint8 SPC7110::read(uint 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 & 0x708000) == 0x008000) {
//$[00-0f|80-8f]:[8000-ffff]
return memory::cartrom.read(addr & 0x0fffff);
}
if((addr & 0xff0000) == 0x500000) {
//$[50]:[0000-ffff]
return mmio_read(0x4800);
}
if((addr & 0xf00000) == 0xc00000) {
//$[c0-cf]:[0000-ffff]
return memory::cartrom.read(addr & 0x0fffff);
}
if((addr & 0xf00000) == 0xd00000) {
//$[d0-df]:[0000-ffff]
return memory::cartrom.read(dx_offset + (addr & 0x0fffff));

View File

@@ -1,5 +1,5 @@
/*****
* SPC7110 emulator - version 0.1 (2008-07-19)
* 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
@@ -15,7 +15,7 @@
* or in connection with the use or performance of this software.
*****/
#include "codec.h"
#include "decomp.h"
class SPC7110 : public MMIO, public Memory {
public:
@@ -41,6 +41,10 @@ public:
uint8 read (uint addr);
void write(uint addr, uint8 data);
//spc7110decomp
void decomp_init();
uint8 decomp_read();
SPC7110();
private:
@@ -60,8 +64,7 @@ private:
uint8 r480b; //decompression control register
uint8 r480c; //decompression status
SPC7110Codec codec;
uint16 decomp_offset;
SPC7110Decomp decomp;
//==============
//data port unit

View File

@@ -58,15 +58,15 @@ string_setting Path::cheat(config(), "path.cheat",
string_setting Path::bsx(config(), "path.bsx", "", "");
string_setting Path::st(config(), "path.st", "", "");
integral_setting SNES::controller_port0(config(), "snes.controller_port_1",
"Controller attached to SNES port 1", integral_setting::decimal, ::SNES::Input::DeviceIDJoypad1);
integral_setting SNES::controller_port1(config(), "snes.controller_port_2",
"Controller attached to SNES port 2", integral_setting::decimal, ::SNES::Input::DeviceIDJoypad2);
integral_setting SNES::controller_port1(config(), "snes.controller_port1",
"Controller attached to SNES port 1", integral_setting::decimal, ::SNES::Input::DeviceJoypad);
integral_setting SNES::controller_port2(config(), "snes.controller_port2",
"Controller attached to SNES port 2", integral_setting::decimal, ::SNES::Input::DeviceJoypad);
integral_setting CPU::ntsc_clock_rate(config(), "cpu.ntsc_clock_rate",
"NTSC S-CPU clock rate (in hz)", integral_setting::decimal, 21477272);
integral_setting CPU::pal_clock_rate(config(), "cpu.pal_clock_rate",
"PAL S-CPU clock rate (in hz)", integral_setting::decimal, 21281370);
"PAL S-CPU clock rate (in hz)", integral_setting::decimal, 21281370);
integral_setting CPU::wram_init_value(config(), "cpu.wram_init_value",
"Value to initialize 128k WRAM to upon power cycle.\n"
"Note that on real hardware, this value is undefined; meaning it can vary\n"
@@ -81,13 +81,10 @@ integral_setting CPU::wram_init_value(config(), "cpu.wram_init_value",
"which do not properly initialize WRAM upon power cycle.\n",
integral_setting::hex, 0x55);
integral_setting CPU::hdma_enable("cpu.hdma_enable",
"Enable HDMA effects", integral_setting::boolean, true);
integral_setting SMP::ntsc_clock_rate(config(), "smp.ntsc_clock_rate",
"NTSC S-SMP clock rate (in hz)", integral_setting::decimal, 24606720);
"NTSC S-SMP clock rate (in hz)", integral_setting::decimal, 32040 * 768);
integral_setting SMP::pal_clock_rate(config(), "smp.pal_clock_rate",
"PAL S-SMP clock rate (in hz)", integral_setting::decimal, 24606720);
"PAL S-SMP clock rate (in hz)", integral_setting::decimal, 32040 * 768);
integral_setting PPU::Hack::render_scanline_position(config(), "ppu.hack.render_scanline_position",
"Approximate HCLOCK position to render at for scanline-based renderers",

View File

@@ -15,14 +15,13 @@ extern struct Path {
} path;
extern struct SNES {
static integral_setting controller_port0;
static integral_setting controller_port1;
static integral_setting controller_port2;
} snes;
extern struct CPU {
static integral_setting ntsc_clock_rate, pal_clock_rate;
static integral_setting wram_init_value;
static integral_setting hdma_enable;
} cpu;
extern struct SMP {

View File

@@ -4,7 +4,7 @@
#include "dcpu.cpp"
CPU::CPU() {
cpu_version = 1;
cpu_version = 2;
}
CPU::~CPU() {

View File

@@ -15,7 +15,8 @@ public:
virtual uint16 hcounter() = 0;
virtual uint16 hdot() = 0;
virtual uint8 pio_status() = 0;
virtual uint8 pio() = 0;
virtual bool joylatch() = 0;
virtual uint8 port_read(uint8 port) = 0;
virtual void port_write(uint8 port, uint8 value) = 0;

View File

@@ -5,52 +5,51 @@ void sCPU::dma_add_clocks(uint clocks) {
add_clocks(clocks);
}
/*****
* used by both DMA and HDMA
*
* DMA address bus A cannot read from or write to the following addresses :
* $[00-3f|80-bf]:43[00-7f] <DMA control registers>
* $[00-3f|80-bf]:420b <DMA enable register>
* $[00-3f|80-bf]:420c <HDMA enable register>
*
* WRAM<>WRAM transfers via $2180 are also illegal
*****/
bool sCPU::dma_addr_valid(uint32 abus) {
//reads from B-bus or S-CPU registers are invalid
if((abus & 0x40ff00) == 0x2100) return false; //$[00-3f|80-bf]:[2100-21ff]
if((abus & 0x40fe00) == 0x4000) return false; //$[00-3f|80-bf]:[4000-41ff]
if((abus & 0x40ffe0) == 0x4200) return false; //$[00-3f|80-bf]:[4200-421f]
if((abus & 0x40ff80) == 0x4300) return false; //$[00-3f|80-bf]:[4300-437f]
return true;
}
uint8 sCPU::dma_read(uint32 abus) {
if(dma_addr_valid(abus) == false) return 0x00; //does not return S-CPU MDR
return bus.read(abus);
}
void sCPU::dma_transfer(bool direction, uint8 bbus, uint32 abus) {
if(direction == 0) {
//a->b transfer (to $21xx)
if(bbus == 0x80 && ((abus & 0xfe0000) == 0x7e0000 || (abus & 0x40e000) == 0x0000)) {
//illegal WRAM->WRAM transfer
//illegal WRAM->WRAM transfer (bus conflict)
//read most likely occurs; no write occurs
//read is irrelevant, as it has no observable effect on emulation
} else if((abus & 0x40ff00) == 0x2100 || (abus & 0x40ff80) == 0x4300
|| (abus & 0x40ffff) == 0x420b || (abus & 0x40ffff) == 0x420c) {
//illegal register access
bus.write(0x2100 | bbus, regs.mdr); //TODO: verify if MDR is written here
//read is irrelevent, as it cannot be observed by software
dma_add_clocks(8);
} else {
//valid transfer
bus.write(0x2100 | bbus, bus.read(abus));
dma_add_clocks(4);
uint8 data = dma_read(abus);
dma_add_clocks(4);
bus.write(0x2100 | bbus, data);
}
} else {
//b->a transfer (from $21xx)
if(bbus == 0x80 && ((abus & 0xfe0000) == 0x7e0000 || (abus & 0x40e000) == 0x0000)) {
//illegal WRAM->WRAM transfer
//illegal WRAM->WRAM transfer (bus conflict)
//no read occurs; write does occur
//does not write MDR as expected
//TODO: 0x00 was observed on hardware; verify if other values are possible
bus.write(abus, 0x00);
} else if((abus & 0x40ff00) == 0x2100 || (abus & 0x40ff80) == 0x4300
|| (abus & 0x40ffff) == 0x420b || (abus & 0x40ffff) == 0x420c) {
//illegal register access
bus.write(abus, regs.mdr); //TODO: verify if MDR is written here
dma_add_clocks(8);
bus.write(abus, 0x00); //does not write S-CPU MDR
} else {
//valid transfer
bus.write(abus, bus.read(0x2100 | bbus));
dma_add_clocks(4);
uint8 data = bus.read(0x2100 | bbus);
dma_add_clocks(4);
if(dma_addr_valid(abus) == true) {
bus.write(abus, data);
}
}
}
//each byte *always* consumes 8 clocks, even if transfer is invalid and no read and/or write occurs
dma_add_clocks(8);
cycle_edge();
}
@@ -120,10 +119,22 @@ inline void sCPU::dma_write(uint8 i, uint8 index) {
}
}
uint8 sCPU::dma_enabled_channels() {
uint8 r = 0;
for(unsigned i = 0; i < 8; i++) {
if(channel[i].dma_enabled) r++;
}
return r;
}
void sCPU::dma_run() {
for(int i = 0; i < 8; i++) {
dma_add_clocks(8);
cycle_edge();
for(unsigned i = 0; i < 8; i++) {
if(channel[i].dma_enabled == false) continue;
dma_add_clocks(8);
cycle_edge();
if(cartridge.info.sdd1 == true) {
sdd1.dma_begin(i, (channel[i].srcbank << 16) | (channel[i].srcaddr), channel[i].xfersize);
@@ -138,7 +149,7 @@ void sCPU::dma_run() {
channel[i].xfersize, channel[i].xfersize ? channel[i].xfersize : 65536);
}
uint index = 0;
unsigned index = 0;
do {
dma_write(i, dma_bbus(i, index++));
} while(channel[i].dma_enabled && channel[i].xfersize);
@@ -158,7 +169,7 @@ inline bool sCPU::hdma_active(uint8 i) {
}
inline bool sCPU::hdma_active_after(uint8 i) {
for(int n = i + 1; n < 8; n++) {
for(unsigned n = i + 1; n < 8; n++) {
if(hdma_active(n) == true) return true;
}
return false;
@@ -166,7 +177,7 @@ inline bool sCPU::hdma_active_after(uint8 i) {
inline uint8 sCPU::hdma_enabled_channels() {
uint8 r = 0;
for(int i = 0; i < 8; i++) {
for(unsigned i = 0; i < 8; i++) {
if(channel[i].hdma_enabled) r++;
}
return r;
@@ -174,55 +185,57 @@ inline uint8 sCPU::hdma_enabled_channels() {
inline uint8 sCPU::hdma_active_channels() {
uint8 r = 0;
for(int i = 0; i < 8; i++) {
for(unsigned i = 0; i < 8; i++) {
if(hdma_active(i) == true) r++;
}
return r;
}
void sCPU::hdma_update(uint8 i) {
channel[i].hdma_line_counter = bus.read(hdma_addr(i));
channel[i].hdma_line_counter = dma_read(hdma_addr(i));
dma_add_clocks(8);
channel[i].hdma_completed = (channel[i].hdma_line_counter == 0);
channel[i].hdma_do_transfer = !channel[i].hdma_completed;
if(channel[i].hdma_indirect) {
channel[i].hdma_iaddr = bus.read(hdma_addr(i)) << 8;
channel[i].hdma_iaddr = dma_read(hdma_addr(i)) << 8;
dma_add_clocks(8);
if(!channel[i].hdma_completed || hdma_active_after(i)) {
channel[i].hdma_iaddr >>= 8;
channel[i].hdma_iaddr |= bus.read(hdma_addr(i)) << 8;
channel[i].hdma_iaddr |= dma_read(hdma_addr(i)) << 8;
dma_add_clocks(8);
}
}
}
void sCPU::hdma_run() {
static uint8 hdma_xferlen[8] = { 1, 2, 2, 4, 4, 4, 2, 4 };
for(int i = 0; i < 8; i++) {
dma_add_clocks(8);
for(unsigned i = 0; i < 8; i++) {
if(hdma_active(i) == false) continue;
channel[i].dma_enabled = false; //HDMA run during DMA will stop DMA mid-transfer
dma_add_clocks(8);
if(channel[i].hdma_do_transfer) {
int xferlen = hdma_xferlen[channel[i].xfermode];
for(int index = 0; index < xferlen; index++) {
if(bool(config::cpu.hdma_enable) == true) {
dma_transfer(channel[i].direction, dma_bbus(i, index),
!channel[i].hdma_indirect ? hdma_addr(i) : hdma_iaddr(i));
} else {
dma_add_clocks(8);
cycle_edge();
}
static const unsigned transfer_length[8] = { 1, 2, 2, 4, 4, 4, 2, 4 };
unsigned length = transfer_length[channel[i].xfermode];
for(unsigned index = 0; index < length; index++) {
unsigned addr = !channel[i].hdma_indirect ? hdma_addr(i) : hdma_iaddr(i);
dma_transfer(channel[i].direction, dma_bbus(i, index), addr);
}
}
}
for(unsigned i = 0; i < 8; i++) {
if(hdma_active(i) == false) continue;
channel[i].hdma_line_counter--;
channel[i].hdma_do_transfer = bool(channel[i].hdma_line_counter & 0x80);
if((channel[i].hdma_line_counter & 0x7f) == 0) {
hdma_update(i);
} else {
dma_add_clocks(8);
}
}
@@ -230,15 +243,17 @@ void sCPU::hdma_run() {
}
void sCPU::hdma_init_reset() {
for(int i = 0; i < 8; i++) {
for(unsigned i = 0; i < 8; i++) {
channel[i].hdma_completed = false;
channel[i].hdma_do_transfer = false;
}
}
void sCPU::hdma_init() {
for(int i = 0; i < 8; i++) {
if(!channel[i].hdma_enabled)continue;
dma_add_clocks(8);
for(unsigned i = 0; i < 8; i++) {
if(!channel[i].hdma_enabled) continue;
channel[i].dma_enabled = false; //HDMA init during DMA will stop DMA mid-transfer
channel[i].hdma_addr = channel[i].srcaddr;
@@ -253,7 +268,7 @@ void sCPU::hdma_init() {
*****/
void sCPU::dma_power() {
for(int i = 0; i < 8; i++) {
for(unsigned i = 0; i < 8; i++) {
channel[i].dmap = 0xff;
channel[i].direction = 1;
channel[i].hdma_indirect = true;
@@ -277,7 +292,7 @@ void sCPU::dma_power() {
}
void sCPU::dma_reset() {
for(int i = 0; i < 8; i++) {
for(unsigned i = 0; i < 8; i++) {
channel[i].dma_enabled = false;
channel[i].hdma_enabled = false;

View File

@@ -46,6 +46,8 @@
} channel[8];
void dma_add_clocks(uint clocks);
bool dma_addr_valid(uint32 abus);
uint8 dma_read(uint32 abus);
void dma_transfer(bool direction, uint8 bbus, uint32 abus);
uint8 dma_bbus(uint8 i, uint8 index);
@@ -56,6 +58,7 @@
void dma_transfertobusb(uint8 i, uint8 bbus);
void dma_transfertobusa(uint8 i, uint8 bbus);
void dma_write(uint8 i, uint8 index);
uint8 dma_enabled_channels();
void dma_run();
bool hdma_active(uint8 i);

View File

@@ -1,8 +1,7 @@
#ifdef SCPU_CPP
uint8 sCPU::pio_status() {
return status.pio;
}
uint8 sCPU::pio() { return status.pio; }
bool sCPU::joylatch() { return status.joypad_strobe_latch; }
//WMDATA
uint8 sCPU::mmio_r2180() {
@@ -55,7 +54,7 @@ void sCPU::mmio_w4016(uint8 data) {
//realtime or buffered status of joypadN.b
uint8 sCPU::mmio_r4016() {
uint8 r = regs.mdr & 0xfc;
r |= (uint8)snes.input.port_read(0);
r |= snes.input.port_read(0) & 3;
return r;
}
@@ -65,7 +64,7 @@ uint8 sCPU::mmio_r4016() {
//1-0 = Joypad serial data
uint8 sCPU::mmio_r4017() {
uint8 r = (regs.mdr & 0xe0) | 0x1c;
r |= (uint8)snes.input.port_read(1);
r |= snes.input.port_read(1) & 3;
return r;
}
@@ -143,19 +142,16 @@ void sCPU::mmio_w420a(uint8 data) {
//DMAEN
void sCPU::mmio_w420b(uint8 data) {
for(int i = 0; i < 8; i++) {
channel[i].dma_enabled = !!(data & (1 << i));
}
if(data) {
status.dma_state = DMASTATE_DMASYNC;
status.dma_pending = true;
for(unsigned i = 0; i < 8; i++) {
channel[i].dma_enabled = data & (1 << i);
}
if(data) status.dma_pending = true;
}
//HDMAEN
void sCPU::mmio_w420c(uint8 data) {
for(int i = 0; i < 8; i++) {
channel[i].hdma_enabled = !!(data & (1 << i));
for(unsigned i = 0; i < 8; i++) {
channel[i].hdma_enabled = data & (1 << i);
}
}

View File

@@ -3,7 +3,8 @@
uint8 mmio_read(uint addr);
void mmio_write(uint addr, uint8 data);
uint8 pio_status();
uint8 pio();
bool joylatch();
uint8 mmio_r2180();
uint8 mmio_r4016();

View File

@@ -15,13 +15,13 @@ public:
} event;
struct {
uint nmi_hold;
uint irq_hold;
unsigned nmi_hold;
unsigned irq_hold;
uint nmi_fire;
uint irq_fire;
uint irq_delay;
uint hw_math;
unsigned nmi_fire;
unsigned irq_fire;
unsigned irq_delay;
unsigned hw_math;
alwaysinline void set(uint &ctr, uint clocks) {
if(clocks >= ctr) { ctr = clocks; }
@@ -36,55 +36,50 @@ public:
}
} counter;
enum {
DMASTATE_INACTIVE,
DMASTATE_DMASYNC,
DMASTATE_RUN,
DMASTATE_CPUSYNC,
};
enum DMA_State { DMA_Inactive, DMA_Run, DMA_CPUsync };
struct {
//core
uint8 opcode;
bool in_opcode;
uint8 opcode;
bool in_opcode;
uint clock_count;
unsigned clock_count;
//timing
uint16 vcounter, hcounter;
uint16 field_lines, line_clocks;
bool line_rendered;
bool line_rendered;
uint16 line_render_position;
bool dram_refreshed;
bool dram_refreshed;
uint16 dram_refresh_position;
bool hdmainit_triggered;
bool hdmainit_triggered;
uint16 hdmainit_trigger_position;
bool hdma_triggered;
bool hdma_triggered;
uint16 irq_delay;
bool nmi_valid;
bool nmi_line;
bool nmi_transition;
bool nmi_pending;
bool nmi_valid;
bool nmi_line;
bool nmi_transition;
bool nmi_pending;
uint16 virq_trigger_pos, hirq_trigger_pos;
bool irq_valid;
bool irq_line;
bool irq_transition;
bool irq_pending;
bool irq_valid;
bool irq_line;
bool irq_transition;
bool irq_pending;
//dma
uint dma_counter;
uint dma_clocks;
uint dma_state;
bool dma_pending;
bool hdma_pending;
bool hdmainit_pending;
unsigned dma_counter;
unsigned dma_clocks;
bool dma_pending;
bool hdma_pending;
bool hdma_mode; //0 = init, 1 = run
DMA_State dma_state;
//mmio
@@ -92,20 +87,20 @@ public:
uint32 wram_addr;
//$4016-$4017
bool joypad_strobe_latch;
bool joypad_strobe_latch;
uint32 joypad1_bits;
uint32 joypad2_bits;
//$4200
bool nmi_enabled;
bool hirq_enabled, virq_enabled;
bool auto_joypad_poll;
bool nmi_enabled;
bool hirq_enabled, virq_enabled;
bool auto_joypad_poll;
//$4201
uint8 pio;
uint8 pio;
//$4202-$4203
uint8 mul_a, mul_b;
uint8 mul_a, mul_b;
//$4204-$4206
uint16 div_a;
@@ -119,10 +114,10 @@ public:
uint16 r4216;
//$4218-$421f
uint8 joy1l, joy1h;
uint8 joy2l, joy2h;
uint8 joy3l, joy3h;
uint8 joy4l, joy4h;
uint8 joy1l, joy1h;
uint8 joy2l, joy2h;
uint8 joy3l, joy3h;
uint8 joy4l, joy4h;
} status;
void power();

View File

@@ -1,10 +1,15 @@
#ifdef SCPU_CPP
void sCPU::run_auto_joypad_poll() {
uint16_t joy1 = 0, joy2 = 0;
uint16 joy1 = 0, joy2 = 0, joy3 = 0, joy4 = 0;
for(unsigned i = 0; i < 16; i++) {
joy1 |= (uint16_t)snes.input.port_read(0) ? (0x8000 >> i) : 0;
joy2 |= (uint16_t)snes.input.port_read(1) ? (0x8000 >> i) : 0;
uint8 port0 = snes.input.port_read(0);
uint8 port1 = snes.input.port_read(1);
joy1 |= (port0 & 1) ? (0x8000 >> i) : 0;
joy2 |= (port1 & 1) ? (0x8000 >> i) : 0;
joy3 |= (port0 & 2) ? (0x8000 >> i) : 0;
joy4 |= (port1 & 2) ? (0x8000 >> i) : 0;
}
status.joy1l = joy1;
@@ -13,11 +18,11 @@ void sCPU::run_auto_joypad_poll() {
status.joy2l = joy2;
status.joy2h = joy2 >> 8;
status.joy3l = 0x00;
status.joy3h = 0x00;
status.joy3l = joy3;
status.joy3h = joy3 >> 8;
status.joy4l = 0x00;
status.joy4h = 0x00;
status.joy4l = joy4;
status.joy4h = joy4 >> 8;
}
#endif //ifdef SCPU_CPP

View File

@@ -1,9 +1,4 @@
#ifdef SCPU_CPP
#define ntsc_color_burst_phase_shift_scanline() ( \
snes.region() == SNES::NTSC && status.vcounter == 240 && \
ppu.interlace() == false && ppu.field() == 1 \
)
#include "irq.cpp"
#include "joypad.cpp"
@@ -22,6 +17,12 @@ uint sCPU::dma_counter() { return (status.dma_counter + status.hcounter) & 7; }
* Dot 323 range = { 1292, 1294, 1296 }
* Dot 327 range = { 1310, 1312, 1314 }
*****/
#define ntsc_color_burst_phase_shift_scanline() ( \
snes.region() == SNES::NTSC && status.vcounter == 240 && \
ppu.interlace() == false && ppu.field() == 1 \
)
uint16 sCPU::hdot() {
if(ntsc_color_burst_phase_shift_scanline() == true) return (status.hcounter >> 2);
return (status.hcounter - ((status.hcounter > 1292) << 1) - ((status.hcounter > 1310) << 1)) >> 2;
@@ -55,15 +56,7 @@ void sCPU::scanline() {
//dram refresh occurs once every scanline
status.dram_refreshed = false;
if(cpu_version == 2) {
if(ntsc_color_burst_phase_shift_scanline() == false) {
if(status.dram_refresh_position == 534) {
status.dram_refresh_position = 538;
} else {
status.dram_refresh_position = 534;
}
}
}
if(cpu_version == 2) status.dram_refresh_position = 530 + 8 - dma_counter();
//hdma triggers once every visible scanline
status.line_rendered = false;
@@ -86,8 +79,7 @@ void sCPU::frame() {
status.vcounter = 0;
status.field_lines = (snes.region() == SNES::NTSC ? 525 : 625) >> 1;
//interlaced even fields have one extra scanline
//(263+262=525 NTSC, 313+312=625 PAL)
//interlaced even fields have one extra scanline (263+262=525 NTSC, 313+312=625 PAL)
if(ppu.interlace() == true && ppu.field() == 0) status.field_lines++;
status.hdmainit_triggered = false;
@@ -101,20 +93,19 @@ void sCPU::frame() {
/*****
* precycle_edge()
*
* Used for DMA/HDMA bus synchronization
* Used for H/DMA bus synchronization
*****/
alwaysinline void sCPU::precycle_edge() {
if(status.dma_state == DMASTATE_CPUSYNC) {
status.dma_state = DMASTATE_INACTIVE;
uint n = status.clock_count - (status.dma_clocks % status.clock_count);
add_clocks(n ? n : status.clock_count);
void sCPU::precycle_edge() {
if(status.dma_state == DMA_CPUsync) {
add_clocks(status.clock_count - (status.dma_clocks % status.clock_count));
status.dma_state = DMA_Inactive;
}
}
/*****
* cycle_edge()
*
* Used to test for HDMA, which can trigger on the edge of every opcode cycle.
* Used to test for H/DMA, which can trigger on the edge of every opcode cycle.
*****/
void sCPU::cycle_edge() {
if(status.line_rendered == false) {
@@ -129,47 +120,55 @@ void sCPU::cycle_edge() {
status.hdmainit_triggered = true;
hdma_init_reset();
if(hdma_enabled_channels()) {
if(status.dma_state == DMASTATE_INACTIVE) {
status.dma_state = DMASTATE_DMASYNC;
status.hdmainit_pending = true;
} else {
hdma_init();
}
status.hdma_pending = true;
status.hdma_mode = 0;
}
}
}
if(status.hdma_triggered == false) {
if(status.hcounter >= 1106) {
if(status.hcounter >= 1104) {
status.hdma_triggered = true;
if(hdma_active_channels()) {
if(status.dma_state == DMASTATE_INACTIVE) {
status.dma_state = DMASTATE_DMASYNC;
status.hdma_pending = true;
} else {
hdma_run();
}
status.hdma_pending = true;
status.hdma_mode = 1;
}
}
}
switch(status.dma_state) {
case DMASTATE_INACTIVE: break;
case DMASTATE_DMASYNC: {
status.dma_state = DMASTATE_RUN;
} break;
case DMASTATE_RUN: {
status.dma_state = DMASTATE_CPUSYNC;
status.dma_clocks = 8 - dma_counter() + 8;
add_clocks(status.dma_clocks);
if(status.hdmainit_pending) { hdma_init(); status.hdmainit_pending = false; }
if(status.hdma_pending) { hdma_run(); status.hdma_pending = false; }
if(status.dma_pending) { dma_run(); status.dma_pending = false; }
} break;
}
//H/DMA pending && DMA inactive?
//.. Run one full CPU cycle
//.. HDMA pending && HDMA enabled ? DMA sync + HDMA run
//.. DMA pending && DMA enabled ? DMA sync + DMA run
//.... HDMA during DMA && HDMA enabled ? DMA sync + HDMA run
//.. Run one bus CPU cycle
//.. CPU sync
if(status.dma_state == DMA_Run) {
if(status.hdma_pending) {
status.hdma_pending = false;
if(hdma_enabled_channels()) {
dma_add_clocks(8 - dma_counter()); //DMA sync
status.hdma_mode == 0 ? hdma_init() : hdma_run();
if(!dma_enabled_channels()) status.dma_state = DMA_CPUsync;
}
}
if(status.dma_pending) {
status.dma_pending = false;
if(dma_enabled_channels()) {
dma_add_clocks(8 - dma_counter()); //DMA sync
dma_run();
status.dma_state = DMA_CPUsync;
}
}
}
if(status.dma_state == DMA_Inactive) {
if(status.dma_pending || status.hdma_pending) {
status.dma_clocks = 0;
status.dma_state = DMA_Run;
}
}
}
@@ -212,7 +211,7 @@ void sCPU::timing_reset() {
status.line_clocks = 1364;
status.line_rendered = false;
status.line_render_position = min(1112U, (uint)config::ppu.hack.render_scanline_position);
status.line_render_position = min(1112U, (unsigned)config::ppu.hack.render_scanline_position);
status.dram_refreshed = false;
status.dram_refresh_position = (cpu_version == 1) ? 530 : 538;
@@ -236,11 +235,12 @@ void sCPU::timing_reset() {
update_interrupts();
status.dma_counter = 0;
status.dma_state = DMASTATE_INACTIVE;
status.dma_pending = false;
status.hdma_pending = false;
status.hdmainit_pending = false;
status.dma_counter = 0;
status.dma_clocks = 0;
status.dma_pending = false;
status.hdma_pending = false;
status.hdma_mode = 0;
status.dma_state = DMA_Inactive;
history.reset();

View File

@@ -2,7 +2,7 @@
void sDSP::brr_decode(voice_t &v) {
//state.t_brr_byte = ram[v.brr_addr + v.brr_offset] cached from previous clock cycle
int nybbles = (state.t_brr_byte << 8) + ram[(uint16)(v.brr_addr + v.brr_offset + 1)];
int nybbles = (state.t_brr_byte << 8) + memory::apuram[(uint16)(v.brr_addr + v.brr_offset + 1)];
const int filter = (state.t_brr_header >> 2) & 3;
const int scale = (state.t_brr_header >> 4);

View File

@@ -12,17 +12,19 @@ int sDSP::echo_output(bool channel) {
}
void sDSP::echo_read(bool channel) {
uint8 *in = &ram[state.t_echo_ptr + channel * 2];
int s = (int16)((in[1] << 8) + in[0]);
unsigned addr = state.t_echo_ptr + channel * 2;
uint8 lo = memory::apuram[(uint16)(addr + 0)];
uint8 hi = memory::apuram[(uint16)(addr + 1)];
int s = (int16)((hi << 8) + lo);
state.echo_hist[channel].write(state.echo_hist_pos, s >> 1);
}
void sDSP::echo_write(bool channel) {
if(!(state.t_echo_disabled & 0x20)) {
uint8 *out = &ram[state.t_echo_ptr + channel * 2];
unsigned addr = state.t_echo_ptr + channel * 2;
int s = state.t_echo_out[channel];
out[0] = (uint8)(s);
out[1] = (uint8)(s >> 8);
memory::apuram[(uint16)(addr + 0)] = s;
memory::apuram[(uint16)(addr + 1)] = s >> 8;
}
state.t_echo_out[channel] = 0;

View File

@@ -249,8 +249,6 @@ void sDSP::write(uint8 addr, uint8 data) {
/* initialization */
void sDSP::power() {
ram = (uint8*)smp.get_spcram_handle(); //TODO: move to sMemory
memset(&state.regs, 0, sizeof state.regs);
state.echo_hist_pos = 0;
state.every_other_sample = false;

View File

@@ -12,9 +12,6 @@ public:
~sDSP();
private:
//external
uint8 *ram;
//USE_STATE_MACHINE variable
unsigned phase_index;

View File

@@ -22,9 +22,11 @@ void sDSP::voice_1(voice_t &v) {
void sDSP::voice_2(voice_t &v) {
//read sample pointer (ignored if not needed)
const uint8 *entry = &ram[state.t_dir_addr];
if(!v.kon_delay) entry += 2;
state.t_brr_next_addr = (entry[1] << 8) + entry[0];
uint16 addr = state.t_dir_addr;
if(!v.kon_delay) addr += 2;
uint8 lo = memory::apuram[(uint16)(addr + 0)];
uint8 hi = memory::apuram[(uint16)(addr + 1)];
state.t_brr_next_addr = ((hi << 8) + lo);
state.t_adsr0 = VREG(adsr0);
@@ -43,8 +45,8 @@ void sDSP::voice_3a(voice_t &v) {
}
void sDSP::voice_3b(voice_t &v) {
state.t_brr_byte = ram[(uint16)(v.brr_addr + v.brr_offset)];
state.t_brr_header = ram[(uint16)(v.brr_addr)];
state.t_brr_byte = memory::apuram[(uint16)(v.brr_addr + v.brr_offset)];
state.t_brr_header = memory::apuram[(uint16)(v.brr_addr)];
}
void sDSP::voice_3c(voice_t &v) {

View File

@@ -1,24 +1,24 @@
/*
bbase : version 0.14 ~byuu (2008-04-16)
bbase : version 0.15 ~byuu (2008-09-14)
license: public domain
*/
#ifndef BBASE_H
#define BBASE_H
#include <nall/stdint.hpp>
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;
typedef unsigned int uint;
#include <algorithm>
using std::min;
#define BBASE_H
#include <nall/stdint.hpp>
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;
typedef unsigned int uint;
#include <algorithm>
using std::min;
using std::max;
#include <assert.h>
@@ -41,7 +41,7 @@ using std::max;
#endif
#if defined(_MSC_VER)
//disable libc deprecation warnings in MSVC 2k5+
//disable libc deprecation warnings in MSVC 2k5+
#pragma warning(disable:4996)
#define NOMINMAX
@@ -52,17 +52,10 @@ using std::max;
#if defined(_MSC_VER) || defined(__MINGW32__)
#define getcwd _getcwd
#define ftruncate _chsize
#define mkdir _mkdir
#define putenv _putenv
#define rmdir _rmdir
#define vsnprintf _vsnprintf
#define vsnprintf _vsnprintf
#define usleep(n) Sleep(n / 1000)
static char *realpath(const char *file_name, char *resolved_name) {
return _fullpath(resolved_name, file_name, PATH_MAX);
}
#else
#define mkdir(path) (mkdir)(path, 0755);
#endif
/*****
@@ -87,22 +80,29 @@ using std::max;
* OS localization
*****/
//userpath(output) retrieves path to user's home folder
//output must be at least as large as PATH_MAX
#if defined(_MSC_VER) || defined(__MINGW32__)
static char *userpath(char *output) {
strcpy(output, "."); //failsafe
SHGetFolderPath(0, CSIDL_APPDATA | CSIDL_FLAG_CREATE, 0, 0, output);
static char* realpath(const char *file_name, char *resolved_name) {
wchar_t filename[PATH_MAX] = L"";
_wfullpath(filename, utf16(file_name), PATH_MAX);
strcpy(resolved_name, utf8(filename));
return resolved_name;
}
static char* userpath(char *output) {
wchar_t path[PATH_MAX] = L"."; //failsafe
SHGetFolderPathW(0, CSIDL_APPDATA | CSIDL_FLAG_CREATE, 0, 0, path);
strcpy(output, utf8(path));
return output;
}
#define mkdir(path) _wmkdir(utf16(path))
#else
static char *userpath(char *output) {
static char* userpath(char *output) {
strcpy(output, "."); //failsafe
struct passwd *userinfo = getpwuid(getuid());
if(userinfo) { strcpy(output, userinfo->pw_dir); }
return output;
}
#define mkdir(path) (mkdir)(path, 0755);
#endif
template<int min, int max, typename T> inline T minmax(const T x) {
@@ -113,93 +113,48 @@ template<int min, int max, typename T> inline T minmax(const T x) {
* endian wrappers
*****/
#ifndef ARCH_MSB
//little-endian: uint8[] { 0x01, 0x02, 0x03, 0x04 } == 0x04030201
#define order_lsb2(a,b) a,b
#define order_lsb3(a,b,c) a,b,c
#define order_lsb4(a,b,c,d) a,b,c,d
#define order_lsb5(a,b,c,d,e) a,b,c,d,e
#define order_lsb6(a,b,c,d,e,f) a,b,c,d,e,f
#define order_lsb7(a,b,c,d,e,f,g) a,b,c,d,e,f,g
#define order_lsb8(a,b,c,d,e,f,g,h) a,b,c,d,e,f,g,h
#define order_msb2(a,b) b,a
#define order_msb3(a,b,c) c,b,a
#define order_msb4(a,b,c,d) d,c,b,a
#define order_msb5(a,b,c,d,e) e,d,c,b,a
#define order_msb6(a,b,c,d,e,f) f,e,d,c,b,a
#define order_msb7(a,b,c,d,e,f,g) g,f,e,d,c,b,a
#define order_msb8(a,b,c,d,e,f,g,h) h,g,f,e,d,c,b,a
#else
//big-endian: uint8[] { 0x01, 0x02, 0x03, 0x04 } == 0x01020304
#define order_lsb2(a,b) b,a
#define order_lsb3(a,b,c) c,b,a
#define order_lsb4(a,b,c,d) d,c,b,a
#define order_lsb5(a,b,c,d,e) e,d,c,b,a
#define order_lsb6(a,b,c,d,e,f) f,e,d,c,b,a
#define order_lsb7(a,b,c,d,e,f,g) g,f,e,d,c,b,a
#define order_lsb8(a,b,c,d,e,f,g,h) h,g,f,e,d,c,b,a
#define order_msb2(a,b) a,b
#define order_msb3(a,b,c) a,b,c
#define order_msb4(a,b,c,d) a,b,c,d
#define order_msb5(a,b,c,d,e) a,b,c,d,e
#define order_msb6(a,b,c,d,e,f) a,b,c,d,e,f
#define order_msb7(a,b,c,d,e,f,g) a,b,c,d,e,f,g
#define order_msb8(a,b,c,d,e,f,g,h) a,b,c,d,e,f,g,h
#ifndef ARCH_MSB
//little-endian: uint8[] { 0x01, 0x02, 0x03, 0x04 } == 0x04030201
#define order_lsb2(a,b) a,b
#define order_lsb3(a,b,c) a,b,c
#define order_lsb4(a,b,c,d) a,b,c,d
#define order_lsb5(a,b,c,d,e) a,b,c,d,e
#define order_lsb6(a,b,c,d,e,f) a,b,c,d,e,f
#define order_lsb7(a,b,c,d,e,f,g) a,b,c,d,e,f,g
#define order_lsb8(a,b,c,d,e,f,g,h) a,b,c,d,e,f,g,h
#define order_msb2(a,b) b,a
#define order_msb3(a,b,c) c,b,a
#define order_msb4(a,b,c,d) d,c,b,a
#define order_msb5(a,b,c,d,e) e,d,c,b,a
#define order_msb6(a,b,c,d,e,f) f,e,d,c,b,a
#define order_msb7(a,b,c,d,e,f,g) g,f,e,d,c,b,a
#define order_msb8(a,b,c,d,e,f,g,h) h,g,f,e,d,c,b,a
#else
//big-endian: uint8[] { 0x01, 0x02, 0x03, 0x04 } == 0x01020304
#define order_lsb2(a,b) b,a
#define order_lsb3(a,b,c) c,b,a
#define order_lsb4(a,b,c,d) d,c,b,a
#define order_lsb5(a,b,c,d,e) e,d,c,b,a
#define order_lsb6(a,b,c,d,e,f) f,e,d,c,b,a
#define order_lsb7(a,b,c,d,e,f,g) g,f,e,d,c,b,a
#define order_lsb8(a,b,c,d,e,f,g,h) h,g,f,e,d,c,b,a
#define order_msb2(a,b) a,b
#define order_msb3(a,b,c) a,b,c
#define order_msb4(a,b,c,d) a,b,c,d
#define order_msb5(a,b,c,d,e) a,b,c,d,e
#define order_msb6(a,b,c,d,e,f) a,b,c,d,e,f
#define order_msb7(a,b,c,d,e,f,g) a,b,c,d,e,f,g
#define order_msb8(a,b,c,d,e,f,g,h) a,b,c,d,e,f,g,h
#endif
/*****
* libc extensions
*****/
//pseudo-random number generator
static unsigned prng() {
static unsigned n = 0;
return n = (n >> 1) ^ (((n & 1) - 1) & 0xedb88320);
}
static uint64 fget(FILE *fp, unsigned length = 1) {
uint64 data = 0;
for(unsigned i = 0; i < length; i++) {
data |= fgetc(fp) << (i << 3);
}
return data;
}
static void fput(FILE *fp, uint64 data, unsigned length = 1) {
for(unsigned i = 0; i < length; i++) {
fputc(data >> (i << 3), fp);
}
}
static bool fexists(const char *fn) {
FILE *fp = fopen(fn, "rb");
if(!fp) return false;
fclose(fp);
fp = 0;
return true;
}
static unsigned fsize(FILE *fp) {
if(!fp) return 0;
unsigned pos = ftell(fp);
fseek(fp, 0, SEEK_END);
unsigned size = ftell(fp);
fseek(fp, pos, SEEK_SET);
return size;
}
static unsigned fsize(const char *fn) {
FILE *fp = fopen(fn, "rb");
if(!fp) return 0;
fseek(fp, 0, SEEK_END);
unsigned size = ftell(fp);
fclose(fp);
fp = 0;
return size;
}
static int fresize(FILE *fp, long size) {
return ftruncate(fileno(fp), size);
}
#endif //ifndef BBASE_H

View File

@@ -1,6 +0,0 @@
mingw32-g++ -c test/test.cpp -I. -I../
mingw32-g++ -c hiro.cpp -I. -I../
mingw32-g++ -c ../nall/string.cpp -I. -I../
mingw32-g++ test.o hiro.o string.o -o test_app.exe -lkernel32 -luser32 -lgdi32 -ladvapi32 -lcomctl32 -lcomdlg32
@pause
@del *.o

View File

@@ -1,6 +0,0 @@
clear
g++ -c test/test.cpp -I. -I../
g++ -c hiro.cpp `pkg-config --cflags gtk+-2.0` -I. -I../
g++ -c ../nall/string.cpp -I. -I../
g++ test.o hiro.o string.o -o test_app `pkg-config --libs gtk+-2.0` -lXtst
rm *.o

View File

@@ -1,8 +1,8 @@
void hiro_pbutton_tick(pButton *p) {
if(p->self.on_tick) p->self.on_tick(Event(Event::Tick, 0, &p->self));
if(p->self.on_tick) p->self.on_tick(event_t(event_t::Tick, 0, &p->self));
}
void pButton::create(uint style, uint width, uint height, const char *text) {
void pButton::create(unsigned style, unsigned width, unsigned height, const char *text) {
button = gtk_button_new_with_label(text ? text : "");
set_default_font(button);
gtk_widget_set_size_request(button, width, height);

View File

@@ -1,7 +1,7 @@
class pButton : public pFormControl {
public:
Button &self;
void create(uint style, uint width, uint height, const char *text = "");
void create(unsigned style, unsigned width, unsigned height, const char *text = "");
void set_text(const char *text = "");
pButton(Button&);

View File

@@ -1,8 +1,8 @@
void hiro_pcanvas_expose(pCanvas *p) {
uint32_t *f = p->fbuffer;
uint32_t *r = p->rbuffer;
for(uint y = p->canvas->allocation.height; y; y--) {
for(uint x = p->canvas->allocation.width; x; x--) {
for(unsigned y = p->canvas->allocation.height; y; y--) {
for(unsigned x = p->canvas->allocation.width; x; x--) {
uint32_t p = *f++;
*r++ = ((p << 16) & 0xff0000) + (p & 0x00ff00) + ((p >> 16) & 0x0000ff);
}
@@ -14,7 +14,7 @@ void hiro_pcanvas_expose(pCanvas *p) {
GDK_RGB_DITHER_NONE, (guchar*)p->rbuffer, p->bpitch);
}
void pCanvas::create(uint style, uint width, uint height) {
void pCanvas::create(unsigned style, unsigned width, unsigned height) {
canvas = gtk_drawing_area_new();
resize(width, height);
GdkColor color;
@@ -54,7 +54,7 @@ pCanvas::~pCanvas() {
/* internal */
void pCanvas::resize(uint width, uint height) {
void pCanvas::resize(unsigned width, unsigned height) {
if(fbuffer) free(fbuffer);
if(rbuffer) free(rbuffer);

View File

@@ -1,6 +1,6 @@
class pCanvas : public pFormControl {
public:
void create(uint style, uint width, uint height);
void create(unsigned style, unsigned width, unsigned height);
void redraw();
uint32_t* buffer();
@@ -13,7 +13,7 @@ public:
//GTK+ RGB drawing function draws in xBGR format, so two buffers are needed ...
uint32_t *fbuffer; //one for the xRGB image
uint32_t *rbuffer; //one for the xBGR image
uint bpitch;
void resize(uint width, uint height);
unsigned bpitch;
void resize(unsigned width, unsigned height);
GtkWidget* gtk_handle();
};

View File

@@ -1,8 +1,8 @@
void hiro_pcheckbox_tick(pCheckbox *p) {
if(!p->locked && p->self.on_tick) p->self.on_tick(Event(Event::Tick, p->checked(), &p->self));
if(!p->locked && p->self.on_tick) p->self.on_tick(event_t(event_t::Tick, p->checked(), &p->self));
}
void pCheckbox::create(uint style, uint width, uint height, const char *text) {
void pCheckbox::create(unsigned style, unsigned width, unsigned height, const char *text) {
checkbox = gtk_check_button_new_with_label(text ? text : "");
set_default_font(checkbox);
gtk_widget_set_size_request(checkbox, width, height);

View File

@@ -1,6 +1,6 @@
class pCheckbox : public pFormControl {
public:
void create(uint style, uint width, uint height, const char *text = "");
void create(unsigned style, unsigned width, unsigned height, const char *text = "");
void set_text(const char *text = "");
void check(bool state = true);
void uncheck();

View File

@@ -1,8 +1,8 @@
void hiro_pcombobox_change(pCombobox *p) {
if(p->self.on_change) p->self.on_change(Event(Event::Change, p->get_selection(), &p->self));
if(p->self.on_change) p->self.on_change(event_t(event_t::Change, p->get_selection(), &p->self));
}
void pCombobox::create(uint style, uint width, uint height, const char *text) {
void pCombobox::create(unsigned style, unsigned width, unsigned height, const char *text) {
combobox = gtk_combo_box_new_text();
set_default_font(combobox);
gtk_widget_set_size_request(combobox, width, height);

View File

@@ -1,6 +1,6 @@
class pCombobox : public pFormControl {
public:
void create(uint style, uint width, uint height, const char *text = "");
void create(unsigned style, unsigned width, unsigned height, const char *text = "");
void add_item(const char *text);
int get_selection();
void set_selection(int index);
@@ -11,6 +11,6 @@ public:
/* internal */
GtkWidget *combobox;
uint counter;
unsigned counter;
GtkWidget* gtk_handle();
};

View File

@@ -1,4 +1,4 @@
void pEditbox::create(uint style, uint width, uint height, const char *text) {
void pEditbox::create(unsigned style, unsigned width, unsigned height, const char *text) {
multiline = bool(style & Editbox::Multiline);
if(multiline == false) {
@@ -38,7 +38,7 @@ void pEditbox::set_text(const char *text) {
}
}
uint pEditbox::get_text(char *text, uint length) {
unsigned pEditbox::get_text(char *text, unsigned length) {
if(multiline == false) {
const char *temp = gtk_entry_get_text(GTK_ENTRY(editbox));
return strlcpy(text, temp ? temp : "", length);

View File

@@ -1,8 +1,8 @@
class pEditbox : public pFormControl {
public:
Editbox &self;
void create(uint style, uint width, uint height, const char *text = "");
uint get_text(char *text, uint length = -1U);
void create(unsigned style, unsigned width, unsigned height, const char *text = "");
unsigned get_text(char *text, unsigned length = -1U);
void set_text(const char *text = "");
pEditbox(Editbox&);

View File

@@ -1,4 +1,4 @@
void pFormControl::resize(uint width, uint height) {
void pFormControl::resize(unsigned width, unsigned height) {
gtk_widget_set_size_request(gtk_handle(), width, height);
}

View File

@@ -1,6 +1,6 @@
class pFormControl : public pWidget {
public:
virtual void resize(uint width, uint height);
virtual void resize(unsigned width, unsigned height);
void focus();
bool focused();
void enable(bool = true);

View File

@@ -1,4 +1,4 @@
void pFrame::create(uint style, uint width, uint height, const char *text) {
void pFrame::create(unsigned style, unsigned width, unsigned height, const char *text) {
frame = gtk_frame_new(text ? text : "");
set_default_font(frame);
gtk_widget_set_size_request(frame, width, height);

View File

@@ -1,7 +1,7 @@
class pFrame : public pFormControl {
public:
Frame &self;
void create(uint style, uint width, uint height, const char *text = "");
void create(unsigned style, unsigned width, unsigned height, const char *text = "");
void set_text(const char *text = "");
pFrame(Frame&);

View File

@@ -158,11 +158,11 @@ bool pHiro::file_save(Window *focus, char *filename, const char *path, const cha
return strcmp(filename, ""); //return true if filename exists
}
uint pHiro::screen_width() {
unsigned pHiro::screen_width() {
return gdk_screen_width();
}
uint pHiro::screen_height() {
unsigned pHiro::screen_height() {
return gdk_screen_height();
}

View File

@@ -43,8 +43,8 @@ public:
bool file_open(Window *focus, char *filename, const char *path = "", const char *filter = "");
bool file_save(Window *focus, char *filename, const char *path = "", const char *filter = "");
uint screen_width();
uint screen_height();
unsigned screen_width();
unsigned screen_height();
void enable_screensaver();
void disable_screensaver();
@@ -62,7 +62,7 @@ public:
void set_default_path(const char*);
bool is_screensaver_enabled;
void screensaver_tick();
uint16_t translate_key(uint key);
uint16_t translate_key(unsigned key);
};
pHiro& phiro();

View File

@@ -1,4 +1,4 @@
uint16_t pHiro::translate_key(uint key) {
uint16_t pHiro::translate_key(unsigned key) {
switch(key) {
case GDK_Escape: return keyboard::escape;

View File

@@ -1,4 +1,4 @@
void pLabel::create(uint style, uint width, uint height, const char *text) {
void pLabel::create(unsigned style, unsigned width, unsigned height, const char *text) {
label = gtk_label_new(text ? text : "");
set_default_font(label);
gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);

View File

@@ -1,7 +1,7 @@
class pLabel : public pFormControl {
public:
Label &self;
void create(uint style, uint width, uint height, const char *text = "");
void create(unsigned style, unsigned width, unsigned height, const char *text = "");
void set_text(const char *text = "");
pLabel(Label&);

View File

@@ -1,13 +1,13 @@
void hiro_plistbox_change(pListbox *p) {
if(p->listbox_selection == p->get_selection()) return;
if(p->self.on_change) p->self.on_change(Event(Event::Change, p->listbox_selection = p->get_selection(), &p->self));
if(p->self.on_change) p->self.on_change(event_t(event_t::Change, p->listbox_selection = p->get_selection(), &p->self));
}
void hiro_plistbox_activate(pListbox *p) {
if(p->self.on_activate) p->self.on_activate(Event(Event::Activate, p->listbox_selection = p->get_selection(), &p->self));
if(p->self.on_activate) p->self.on_activate(event_t(event_t::Activate, p->listbox_selection = p->get_selection(), &p->self));
}
void pListbox::create(uint style, uint width, uint height, const char *columns, const char *text) {
void pListbox::create(unsigned style, unsigned width, unsigned height, const char *columns, const char *text) {
bool header = style & Listbox::Header;
GtkPolicyType hscroll = (style & Listbox::HorizontalScrollAlways) ? GTK_POLICY_ALWAYS :
(style & Listbox::HorizontalScrollNever) ? GTK_POLICY_NEVER :
@@ -24,7 +24,7 @@ void pListbox::create(uint style, uint width, uint height, const char *columns,
split(list, "\t", columns);
GType *v = (GType*)malloc(count(list) * sizeof(GType));
for(uint i = 0; i < count(list); i++) v[i] = G_TYPE_STRING;
for(unsigned i = 0; i < count(list); i++) v[i] = G_TYPE_STRING;
store = gtk_list_store_newv(count(list), v);
free(v);
@@ -37,7 +37,7 @@ void pListbox::create(uint style, uint width, uint height, const char *columns,
//alternate colors for each listbox entry if there are multiple columns ...
gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(listbox), count(list) >= 2 ? true : false);
for(uint i = 0; i < count(list); i++) {
for(unsigned i = 0; i < count(list); i++) {
renderer = gtk_cell_renderer_text_new();
column = gtk_tree_view_column_new_with_attributes(list[i], renderer, "text", i, (void*)0);
column_list[column_list.size()] = column;
@@ -46,7 +46,7 @@ void pListbox::create(uint style, uint width, uint height, const char *columns,
if(text && *text) {
split(list, "\n", text);
for(uint i = 0; i < count(list); i++) add_item(list[i]);
for(unsigned i = 0; i < count(list); i++) add_item(list[i]);
}
gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(listbox), header);
@@ -62,7 +62,7 @@ void pListbox::autosize_columns() {
gtk_tree_view_columns_autosize(GTK_TREE_VIEW(listbox));
}
void pListbox::set_column_width(uint column, uint width) {
void pListbox::set_column_width(unsigned column, unsigned width) {
gtk_tree_view_column_set_min_width(column_list[column], width);
gtk_tree_view_column_set_max_width(column_list[column], width);
}
@@ -71,14 +71,14 @@ void pListbox::add_item(const char *text) {
lstring list;
split(list, "\t", text);
gtk_list_store_append(store, &iter);
for(uint i = 0; i < count(list); i++) {
for(unsigned i = 0; i < count(list); i++) {
gtk_list_store_set(store, &iter, i, list[i](), -1);
}
}
void pListbox::set_item(uint index, const char *text) {
void pListbox::set_item(unsigned index, const char *text) {
GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(listbox));
for(uint i = 0; i <= index; i++) {
for(unsigned i = 0; i <= index; i++) {
i == 0 ?
gtk_tree_model_get_iter_first(model, &iter) :
gtk_tree_model_iter_next(model, &iter);
@@ -86,7 +86,7 @@ GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(listbox));
lstring list;
split(list, "\t", text);
for(uint i = 0; i < count(list); i++) {
for(unsigned i = 0; i < count(list); i++) {
gtk_list_store_set(store, &iter, i, list[i](), -1);
}
}
@@ -96,7 +96,7 @@ GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(listbox)
GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(listbox));
if(gtk_tree_model_get_iter_first(model, &iter) == false) { return -1; }
if(gtk_tree_selection_iter_is_selected(selection, &iter) == true) { return 0; }
for(uint i = 1; i < 100000; i++) {
for(unsigned i = 1; i < 100000; i++) {
if(gtk_tree_model_iter_next(model, &iter) == false) { return -1; }
if(gtk_tree_selection_iter_is_selected(selection, &iter) == true) { return i; }
}
@@ -111,12 +111,12 @@ GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(listbox));
if(index < 0) { goto end; }
if(gtk_tree_model_get_iter_first(model, &iter) == false) { goto end; }
if(index == 0) { gtk_tree_selection_select_iter(selection, &iter); goto end; }
for(uint i = 1; i < 100000; i++) {
for(unsigned i = 1; i < 100000; i++) {
if(gtk_tree_model_iter_next(model, &iter) == false) { goto end; }
if(index == i) { gtk_tree_selection_select_iter(selection, &iter); goto end; }
}
end:
if(current != index) ;//{ owner->message(Message::Changed, (uintptr_t)this); }
if(current != index); //{ owner->message(Message::Changed, (uintptr_t)this); }
}
void pListbox::reset() {

View File

@@ -1,10 +1,10 @@
class pListbox : public pFormControl {
public:
void create(uint style, uint width, uint height, const char *columns = "", const char *text = "");
void create(unsigned style, unsigned width, unsigned height, const char *columns = "", const char *text = "");
void autosize_columns();
void set_column_width(uint column, uint width);
void set_column_width(unsigned column, unsigned width);
void add_item(const char *text);
void set_item(uint index, const char *text);
void set_item(unsigned index, const char *text);
int get_selection();
void set_selection(int index);
void reset();

View File

@@ -1,5 +1,5 @@
void hiro_pmenucheckitem_tick(pMenuCheckItem *p) {
if(!p->locked && p->self.on_tick) p->self.on_tick(Event(Event::Tick, p->checked(), &p->self));
if(!p->locked && p->self.on_tick) p->self.on_tick(event_t(event_t::Tick, p->checked(), &p->self));
}
void pMenuCheckItem::create(const char *text) {

View File

@@ -1,5 +1,5 @@
void hiro_pmenuitem_tick(pMenuItem *p) {
if(p->self.on_tick) p->self.on_tick(Event(Event::Tick, 0, &p->self));
if(p->self.on_tick) p->self.on_tick(event_t(event_t::Tick, 0, &p->self));
}
void pMenuItem::create(const char *text) {

View File

@@ -1,7 +1,7 @@
void hiro_pmenuradioitem_tick(pMenuRadioItem *p) {
//GTK+ sends two messages: one for the activated radio item,
//and one for the deactivated radio item. ignore the latter.
if(!p->locked && p->checked() && p->self.on_tick) p->self.on_tick(Event(Event::Tick, 0, &p->self));
if(!p->locked && p->checked() && p->self.on_tick) p->self.on_tick(event_t(event_t::Tick, 0, &p->self));
}
void pMenuRadioItem::create(MenuRadioItemGroup &group, const char *text) {

View File

@@ -1,15 +1,15 @@
void pProgressbar::create(uint style, uint width, uint height) {
void pProgressbar::create(unsigned style, unsigned width, unsigned height) {
progressbar = gtk_progress_bar_new();
gtk_widget_set_size_request(progressbar, width, height);
gtk_widget_show(progressbar);
}
uint pProgressbar::get_progress() {
uint progress = (uint)(gtk_progress_bar_get_fraction(GTK_PROGRESS_BAR(progressbar)) * 100.0);
unsigned pProgressbar::get_progress() {
unsigned progress = (unsigned)(gtk_progress_bar_get_fraction(GTK_PROGRESS_BAR(progressbar)) * 100.0);
return max(0U, min(progress, 100U));
}
void pProgressbar::set_progress(uint progress) {
void pProgressbar::set_progress(unsigned progress) {
progress = max(0U, min(progress, 100U));
gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progressbar), (double)progress / 100.0);
}

View File

@@ -1,9 +1,9 @@
class pProgressbar : public pFormControl {
public:
Progressbar &self;
void create(uint style, uint width, uint height);
uint get_progress();
void set_progress(uint progress);
void create(unsigned style, unsigned width, unsigned height);
unsigned get_progress();
void set_progress(unsigned progress);
pProgressbar(Progressbar&);

View File

@@ -1,10 +1,10 @@
void hiro_pradiobox_tick(pRadiobox *p) {
//GTK+ sends two messages: one for the activated radiobox,
//and one for the deactivated radiobox. ignore the latter.
if(!p->locked && p->checked() && p->self.on_tick) p->self.on_tick(Event(Event::Tick, 0, &p->self));
if(!p->locked && p->checked() && p->self.on_tick) p->self.on_tick(event_t(event_t::Tick, 0, &p->self));
}
void pRadiobox::create(RadioboxGroup &group, uint style, uint width, uint height, const char *text) {
void pRadiobox::create(RadioboxGroup &group, unsigned style, unsigned width, unsigned height, const char *text) {
if(group.size() == 0 || group[0] == &self) {
radiobox = gtk_radio_button_new_with_label(0, text ? text : "");
} else {

View File

@@ -1,6 +1,6 @@
class pRadiobox : public pFormControl {
public:
void create(RadioboxGroup &group, uint style, uint width, uint height, const char *text = "");
void create(RadioboxGroup &group, unsigned style, unsigned width, unsigned height, const char *text = "");
void set_text(const char *text = "");
void check();
bool checked();

View File

@@ -1,9 +1,9 @@
void hiro_pslider_change(pSlider *p) {
if(p->slider_position == p->get_position()) return;
if(p->self.on_change) p->self.on_change(Event(Event::Change, p->slider_position = p->get_position(), &p->self));
if(p->self.on_change) p->self.on_change(event_t(event_t::Change, p->slider_position = p->get_position(), &p->self));
}
void pSlider::create(uint style, uint width, uint height, uint length) {
void pSlider::create(unsigned style, unsigned width, unsigned height, unsigned length) {
if(length < 1) length = 1;
if(style & Slider::Vertical) {
slider = gtk_vscale_new_with_range(0, length - 1, 1);
@@ -16,11 +16,11 @@ void pSlider::create(uint style, uint width, uint height, uint length) {
g_signal_connect_swapped(G_OBJECT(slider), "value-changed", G_CALLBACK(hiro_pslider_change), (gpointer)this);
}
uint pSlider::get_position() {
return (uint)gtk_range_get_value(GTK_RANGE(slider));
unsigned pSlider::get_position() {
return (unsigned)gtk_range_get_value(GTK_RANGE(slider));
}
void pSlider::set_position(uint position) {
void pSlider::set_position(unsigned position) {
gtk_range_set_value(GTK_RANGE(slider), position);
}

View File

@@ -1,14 +1,14 @@
class pSlider : public pFormControl {
public:
void create(uint style, uint width, uint height, uint length);
uint get_position();
void set_position(uint position);
void create(unsigned style, unsigned width, unsigned height, unsigned length);
unsigned get_position();
void set_position(unsigned position);
Slider &self;
pSlider(Slider&);
/* internal */
GtkWidget *slider;
uint slider_position;
unsigned slider_position;
GtkWidget* gtk_handle();
};

View File

@@ -1,5 +1,5 @@
static gint hiro_pwindow_close(pWindow *p) {
uintptr_t r = p->self.on_close ? p->self.on_close(Event(Event::Close, 0, &p->self)) : true;
uintptr_t r = p->self.on_close ? p->self.on_close(event_t(event_t::Close, 0, &p->self)) : true;
return !bool(r);
}
@@ -25,16 +25,16 @@ static gboolean hiro_pwindow_expose(pWindow *p) {
}
static gint hiro_pwindow_keydown(GtkWidget *w, GdkEventKey *key, pWindow *p) {
if(p && p->self.on_keydown) p->self.on_keydown(Event(Event::KeyDown, phiro().translate_key(key->keyval), &p->self));
if(p && p->self.on_keydown) p->self.on_keydown(event_t(event_t::KeyDown, phiro().translate_key(key->keyval), &p->self));
return FALSE;
}
static gint hiro_pwindow_keyup(GtkWidget *w, GdkEventKey *key, pWindow *p) {
if(p && p->self.on_keyup) p->self.on_keyup(Event(Event::KeyUp, phiro().translate_key(key->keyval), &p->self));
if(p && p->self.on_keyup) p->self.on_keyup(event_t(event_t::KeyUp, phiro().translate_key(key->keyval), &p->self));
return FALSE;
}
void pWindow::create(uint style, uint width, uint height, const char *text) {
void pWindow::create(unsigned style, unsigned width, unsigned height, const char *text) {
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_set_colormap(window, phiro().colormap);
@@ -81,12 +81,12 @@ void pWindow::close() {
gtk_widget_destroy(window);
}
void pWindow::move(uint x, uint y) {
void pWindow::move(unsigned x, unsigned y) {
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_NONE);
gtk_window_move(GTK_WINDOW(window), x, y);
}
void pWindow::resize(uint width, uint height) {
void pWindow::resize(unsigned width, unsigned height) {
gtk_widget_set_size_request(formcontainer, width, height);
state.width = width;
state.height = height;
@@ -132,14 +132,14 @@ void pWindow::unfullscreen() {
//is unreliable, as it will usually report the previous window size.
//therefore, calculate it manually by using state information.
uint pWindow::get_width() {
unsigned pWindow::get_width() {
if(state.is_fullscreen == false) return state.width;
return gdk_screen_width();
}
uint pWindow::get_height() {
unsigned pWindow::get_height() {
if(state.is_fullscreen == false) return state.height;
uint height = gdk_screen_height();
unsigned height = gdk_screen_height();
//do not include menubar height in client area height
if(menu.visible()) {
@@ -198,7 +198,7 @@ void pWindow::set_text(const char *text) {
gtk_window_set_title(GTK_WINDOW(window), text ? text : "");
}
void pWindow::attach(Window &window, uint x, uint y) {
void pWindow::attach(Window &window, unsigned x, unsigned y) {
window.p.owner = this;
//GTK+ does not support attaching a window to another window,
@@ -216,15 +216,15 @@ void pWindow::attach(MenuGroup &menugroup) {
gtk_widget_show(menubar);
}
void pWindow::attach(FormControl &formcontrol, uint x, uint y) {
void pWindow::attach(FormControl &formcontrol, unsigned x, unsigned y) {
gtk_fixed_put(GTK_FIXED(formcontainer), formcontrol.p.gtk_handle(), x, y);
}
void pWindow::move(Window &window, uint x, uint y) {
void pWindow::move(Window &window, unsigned x, unsigned y) {
gtk_fixed_move(GTK_FIXED(formcontainer), window.p.gtk_handle(), x, y);
}
void pWindow::move(FormControl &formcontrol, uint x, uint y) {
void pWindow::move(FormControl &formcontrol, unsigned x, unsigned y) {
gtk_fixed_move(GTK_FIXED(formcontainer), formcontrol.p.gtk_handle(), x, y);
}

View File

@@ -1,24 +1,24 @@
class pWindow : public pWidget {
public:
void create(uint style, uint width, uint height, const char *text = "");
void create(unsigned style, unsigned width, unsigned height, const char *text = "");
void close();
void move(uint x, uint y);
void resize(uint width, uint height);
void move(unsigned x, unsigned y);
void resize(unsigned width, unsigned height);
void focus();
bool focused();
void fullscreen();
void unfullscreen();
uint get_width();
uint get_height();
unsigned get_width();
unsigned get_height();
void set_opacity(uint8_t opacity);
void set_background_color(uint8_t r, uint8_t g, uint8_t b);
void set_icon(unsigned width, unsigned height, const uint32_t *data);
void set_text(const char *text = "");
void attach(Window &window, uint x, uint y);
void attach(Window &window, unsigned x, unsigned y);
void attach(MenuGroup &menugroup);
void attach(FormControl &formcontrol, uint x, uint y);
void move(Window &window, uint x, uint y);
void move(FormControl &formcontrol, uint x, uint y);
void attach(FormControl &formcontrol, unsigned x, unsigned y);
void move(Window &window, unsigned x, unsigned y);
void move(FormControl &formcontrol, unsigned x, unsigned y);
class Statusbar {
public:
@@ -55,9 +55,9 @@ public:
GtkWidget* gtk_handle();
struct {
bool is_fullscreen;
uint width;
uint height;
uint alpha;
unsigned width;
unsigned height;
unsigned alpha;
} state;
void menu_show(bool = true);

View File

@@ -18,8 +18,8 @@ bool Hiro::pending() { return p.pending(); }
bool Hiro::folder_select(Window *focus, char *filename, const char *path) { return p.folder_select(focus, filename, path); }
bool Hiro::file_open(Window *focus, char *filename, const char *path, const char *filter) { return p.file_open(focus, filename, path, filter); }
bool Hiro::file_save(Window *focus, char *filename, const char *path, const char *filter) { return p.file_save(focus, filename, path, filter); }
uint Hiro::screen_width() { return p.screen_width(); }
uint Hiro::screen_height() { return p.screen_height(); }
unsigned Hiro::screen_width() { return p.screen_width(); }
unsigned Hiro::screen_height() { return p.screen_height(); }
void Hiro::enable_screensaver() { p.enable_screensaver(); }
void Hiro::disable_screensaver() { p.disable_screensaver(); }
Hiro& Hiro::handle() { static Hiro hiro; return hiro; }
@@ -39,25 +39,25 @@ Widget::~Widget() { delete &p; }
/* Widget -> Window */
void Window::create(uint style, uint width, uint height, const char *text) { p.create(style, width, height, text); }
void Window::create(unsigned style, unsigned width, unsigned height, const char *text) { p.create(style, width, height, text); }
void Window::close() { p.close(); }
void Window::move(uint x, uint y) { p.move(x, y); }
void Window::resize(uint width, uint height) { p.resize(width, height); }
void Window::move(unsigned x, unsigned y) { p.move(x, y); }
void Window::resize(unsigned width, unsigned height) { p.resize(width, height); }
void Window::focus() { p.focus(); }
bool Window::focused() { return p.focused(); }
void Window::fullscreen() { p.fullscreen(); }
void Window::unfullscreen() { p.unfullscreen(); }
uint Window::get_width() { return p.get_width(); }
uint Window::get_height() { return p.get_height(); }
unsigned Window::get_width() { return p.get_width(); }
unsigned Window::get_height() { return p.get_height(); }
void Window::set_opacity(uint8_t opacity) { p.set_opacity(opacity); }
void Window::set_background_color(uint8_t r, uint8_t g, uint8_t b) { p.set_background_color(r, g, b); }
void Window::set_icon(unsigned width, unsigned height, const uint32_t *data) { p.set_icon(width, height, data); }
void Window::set_text(const char *text) { p.set_text(text); }
void Window::attach(Window &window, uint x, uint y) { p.attach(window, x, y); }
void Window::attach(Window &window, unsigned x, unsigned y) { p.attach(window, x, y); }
void Window::attach(MenuGroup &menugroup) { p.attach(menugroup); }
void Window::attach(FormControl &formcontrol, uint x, uint y) { p.attach(formcontrol, x, y); }
void Window::move(Window &window, uint x, uint y) { p.move(window, x, y); }
void Window::move(FormControl &formcontrol, uint x, uint y) { p.move(formcontrol, x, y); }
void Window::attach(FormControl &formcontrol, unsigned x, unsigned y) { p.attach(formcontrol, x, y); }
void Window::move(Window &window, unsigned x, unsigned y) { p.move(window, x, y); }
void Window::move(FormControl &formcontrol, unsigned x, unsigned y) { p.move(formcontrol, x, y); }
void Window::Menubar::show(bool state) { p.menu.show(state); }
void Window::Menubar::hide() { p.menu.hide(); }
@@ -139,7 +139,7 @@ MenuSeparator::MenuSeparator() :
/* Widget -> FormControl */
void FormControl::resize(uint width, uint height) { p.resize(width, height); }
void FormControl::resize(unsigned width, unsigned height) { p.resize(width, height); }
void FormControl::focus() { p.focus(); }
bool FormControl::focused() { return p.focused(); }
void FormControl::enable(bool state) { p.enable(state); }
@@ -156,7 +156,7 @@ FormControl::FormControl(pFormControl &p_) :
/* Widget -> FormControl -> Frame */
void Frame::create(uint style, uint width, uint height, const char *text) { p.create(style, width, height, text); }
void Frame::create(unsigned style, unsigned width, unsigned height, const char *text) { p.create(style, width, height, text); }
void Frame::set_text(const char *text) { p.set_text(text); }
Frame::Frame() :
base_from_member<pFrame&>(*new pFrame(*this)),
@@ -165,7 +165,7 @@ Frame::Frame() :
/* Widget -> FormControl -> Canvas */
void Canvas::create(uint style, uint width, uint height) { p.create(style, width, height); }
void Canvas::create(unsigned style, unsigned width, unsigned height) { p.create(style, width, height); }
void Canvas::redraw() { p.redraw(); }
uint32_t* Canvas::buffer() { return p.buffer(); }
Canvas::Canvas() :
@@ -175,7 +175,7 @@ Canvas::Canvas() :
/* Widget -> FormControl -> Label */
void Label::create(uint style, uint width, uint height, const char *text) { p.create(style, width, height, text); }
void Label::create(unsigned style, unsigned width, unsigned height, const char *text) { p.create(style, width, height, text); }
void Label::set_text(const char *text) { p.set_text(text); }
Label::Label() :
base_from_member<pLabel&>(*new pLabel(*this)),
@@ -184,7 +184,7 @@ Label::Label() :
/* Widget -> FormControl -> Button */
void Button::create(uint style, uint width, uint height, const char *text) { p.create(style, width, height, text); }
void Button::create(unsigned style, unsigned width, unsigned height, const char *text) { p.create(style, width, height, text); }
void Button::set_text(const char *text) { p.set_text(text); }
Button::Button() :
base_from_member<pButton&>(*new pButton(*this)),
@@ -193,7 +193,7 @@ Button::Button() :
/* Widget -> FormControl -> Checkbox */
void Checkbox::create(uint style, uint width, uint height, const char *text) { p.create(style, width, height, text); }
void Checkbox::create(unsigned style, unsigned width, unsigned height, const char *text) { p.create(style, width, height, text); }
void Checkbox::set_text(const char *text) { p.set_text(text); }
void Checkbox::check(bool state) { state ? p.check() : p.uncheck(); }
void Checkbox::uncheck() { p.uncheck(); }
@@ -205,7 +205,7 @@ Checkbox::Checkbox() :
/* Widget -> FormControl -> Radiobox */
void Radiobox::create(RadioboxGroup &group, uint style, uint width, uint height, const char *text) { p.create(group, style, width, height, text); }
void Radiobox::create(RadioboxGroup &group, unsigned style, unsigned width, unsigned height, const char *text) { p.create(group, style, width, height, text); }
void Radiobox::set_text(const char *text) { p.set_text(text); }
void Radiobox::check() { p.check(); }
bool Radiobox::checked() { return p.checked(); }
@@ -216,8 +216,8 @@ Radiobox::Radiobox() :
/* Widget -> FormControl -> Editbox */
void Editbox::create(uint style, uint width, uint height, const char *text) { p.create(style, width, height, text); }
uint Editbox::get_text(char *text, uint length) { return p.get_text(text, length); }
void Editbox::create(unsigned style, unsigned width, unsigned height, const char *text) { p.create(style, width, height, text); }
unsigned Editbox::get_text(char *text, unsigned length) { return p.get_text(text, length); }
void Editbox::set_text(const char *text) { p.set_text(text); }
Editbox::Editbox() :
base_from_member<pEditbox&>(*new pEditbox(*this)),
@@ -226,11 +226,11 @@ Editbox::Editbox() :
/* Widget -> FormControl -> Listbox */
void Listbox::create(uint style, uint width, uint height, const char *columns, const char *text) { p.create(style, width, height, columns, text); }
void Listbox::create(unsigned style, unsigned width, unsigned height, const char *columns, const char *text) { p.create(style, width, height, columns, text); }
void Listbox::autosize_columns() { p.autosize_columns(); }
void Listbox::set_column_width(uint column, uint width) { p.set_column_width(column, width); }
void Listbox::set_column_width(unsigned column, unsigned width) { p.set_column_width(column, width); }
void Listbox::add_item(const char *text) { p.add_item(text); }
void Listbox::set_item(uint index, const char *text) { p.set_item(index, text); }
void Listbox::set_item(unsigned index, const char *text) { p.set_item(index, text); }
int Listbox::get_selection() { return p.get_selection(); }
void Listbox::set_selection(int index) { p.set_selection(index); }
void Listbox::reset() { p.reset(); }
@@ -241,7 +241,7 @@ Listbox::Listbox() :
/* Widget -> FormControl -> Combobox */
void Combobox::create(uint style, uint width, uint height, const char *text) { p.create(style, width, height, text); }
void Combobox::create(unsigned style, unsigned width, unsigned height, const char *text) { p.create(style, width, height, text); }
void Combobox::add_item(const char *text) { p.add_item(text); }
int Combobox::get_selection() { return p.get_selection(); }
void Combobox::set_selection(int index) { p.set_selection(index); }
@@ -253,9 +253,9 @@ Combobox::Combobox() :
/* Widget -> FormControl -> Progressbar */
void Progressbar::create(uint style, uint width, uint height) { p.create(style, width, height); }
uint Progressbar::get_progress() { return p.get_progress(); }
void Progressbar::set_progress(uint progress) { p.set_progress(progress); }
void Progressbar::create(unsigned style, unsigned width, unsigned height) { p.create(style, width, height); }
unsigned Progressbar::get_progress() { return p.get_progress(); }
void Progressbar::set_progress(unsigned progress) { p.set_progress(progress); }
Progressbar::Progressbar() :
base_from_member<pProgressbar&>(*new pProgressbar(*this)),
FormControl(base_from_member<pProgressbar&>::value),
@@ -263,9 +263,9 @@ Progressbar::Progressbar() :
/* Widget -> FormControl -> Slider */
void Slider::create(uint style, uint width, uint height, uint length) { p.create(style, width, height, length); }
uint Slider::get_position() { return p.get_position(); }
void Slider::set_position(uint position) { p.set_position(position); }
void Slider::create(unsigned style, unsigned width, unsigned height, unsigned length) { p.create(style, width, height, length); }
unsigned Slider::get_position() { return p.get_position(); }
void Slider::set_position(unsigned position) { p.set_position(position); }
Slider::Slider() :
base_from_member<pSlider&>(*new pSlider(*this)),
FormControl(base_from_member<pSlider&>::value),

View File

@@ -1,6 +1,6 @@
/*
hiro
version: 0.005 (2008-05-25)
version: 0.006 (2008-08-12)
author: byuu
license: public domain
*/
@@ -15,7 +15,6 @@
#include <nall/stdint.hpp>
#include <nall/string.hpp>
#include <nall/utility.hpp>
typedef unsigned int uint;
namespace libhiro {
@@ -89,8 +88,8 @@ class Widget;
typedef nall::array<MenuRadioItem*> MenuRadioItemGroup;
typedef nall::array<Radiobox*> RadioboxGroup;
struct Event {
enum Type {
struct event_t {
enum type_t {
Close,
Block,
KeyDown,
@@ -102,7 +101,7 @@ struct Event {
uintptr_t param;
Widget *widget;
Event(Type type_, uintptr_t param_ = 0, Widget *widget_ = 0) :
event_t(type_t type_, uintptr_t param_ = 0, Widget *widget_ = 0) :
type(type_), param(param_), widget(widget_) {}
};
@@ -117,8 +116,8 @@ public:
bool file_open(Window *focus, char *filename, const char *path = "", const char *filter = "");
bool file_save(Window *focus, char *filename, const char *path = "", const char *filter = "");
uint screen_width();
uint screen_height();
unsigned screen_width();
unsigned screen_height();
void enable_screensaver();
void disable_screensaver();
@@ -182,26 +181,26 @@ public:
AutoCenter = 1 << 1,
};
void create(uint style, uint width, uint height, const char *text = "");
void create(unsigned style, unsigned width, unsigned height, const char *text = "");
void close();
void move(uint x, uint y);
void resize(uint width, uint height);
void move(unsigned x, unsigned y);
void resize(unsigned width, unsigned height);
void focus();
bool focused();
void fullscreen();
void unfullscreen();
uint get_width();
uint get_height();
unsigned get_width();
unsigned get_height();
void set_opacity(uint8_t opacity);
void set_background_color(uint8_t r, uint8_t g, uint8_t b);
void set_icon(unsigned width, unsigned height, const uint32_t *data);
void set_status_text(const char *text = "");
void set_text(const char *text = "");
void attach(Window &window, uint x, uint y);
void attach(Window &window, unsigned x, unsigned y);
void attach(MenuGroup &menugroup);
void attach(FormControl &formcontrol, uint x, uint y);
void move(Window &window, uint x, uint y);
void move(FormControl &formcontrol, uint x, uint y);
void attach(FormControl &formcontrol, unsigned x, unsigned y);
void move(Window &window, unsigned x, unsigned y);
void move(FormControl &formcontrol, unsigned x, unsigned y);
class Menubar {
public:
@@ -224,10 +223,10 @@ public:
Statusbar(pWindow&);
} status;
nall::function<uintptr_t (Event)> on_close;
nall::function<uintptr_t (Event)> on_block;
nall::function<uintptr_t (Event)> on_keydown;
nall::function<uintptr_t (Event)> on_keyup;
nall::function<uintptr_t (event_t)> on_close;
nall::function<uintptr_t (event_t)> on_block;
nall::function<uintptr_t (event_t)> on_keydown;
nall::function<uintptr_t (event_t)> on_keyup;
Window();
@@ -268,7 +267,7 @@ public:
MenuItem& create(const char *text);
MenuItem();
nall::function<uintptr_t (Event)> on_tick;
nall::function<uintptr_t (event_t)> on_tick;
private:
pFriends;
@@ -283,7 +282,7 @@ public:
bool checked();
MenuCheckItem();
nall::function<uintptr_t (Event)> on_tick;
nall::function<uintptr_t (event_t)> on_tick;
private:
pFriends;
@@ -297,7 +296,7 @@ public:
bool checked();
MenuRadioItem();
nall::function<uintptr_t (Event)> on_tick;
nall::function<uintptr_t (event_t)> on_tick;
private:
pFriends;
@@ -316,7 +315,7 @@ private:
class FormControl : private nall::base_from_member<pFormControl&>, public Widget {
public:
void resize(uint width, uint height);
void resize(unsigned width, unsigned height);
void focus();
bool focused();
void enable(bool = true);
@@ -335,7 +334,7 @@ private:
class Frame : private nall::base_from_member<pFrame&>, public FormControl {
public:
void create(uint style, uint width, uint height, const char *text = "");
void create(unsigned style, unsigned width, unsigned height, const char *text = "");
void set_text(const char *text = "");
Frame();
@@ -347,7 +346,7 @@ private:
class Canvas : private nall::base_from_member<pCanvas&>, public FormControl {
public:
void create(uint style, uint width, uint height);
void create(unsigned style, unsigned width, unsigned height);
void redraw();
uint32_t* buffer();
@@ -360,7 +359,7 @@ private:
class Label : private nall::base_from_member<pLabel&>, public FormControl {
public:
void create(uint style, uint width, uint height, const char *text = "");
void create(unsigned style, unsigned width, unsigned height, const char *text = "");
void set_text(const char *text = "");
Label();
@@ -372,10 +371,10 @@ private:
class Button : private nall::base_from_member<pButton&>, public FormControl {
public:
void create(uint style, uint width, uint height, const char *text = "");
void create(unsigned style, unsigned width, unsigned height, const char *text = "");
void set_text(const char *text = "");
nall::function<uintptr_t (Event)> on_tick;
nall::function<uintptr_t (event_t)> on_tick;
Button();
@@ -386,13 +385,13 @@ private:
class Checkbox : private nall::base_from_member<pCheckbox&>, public FormControl {
public:
void create(uint style, uint width, uint height, const char *text = "");
void create(unsigned style, unsigned width, unsigned height, const char *text = "");
void set_text(const char *text = "");
void check(bool = true);
void uncheck();
bool checked();
nall::function<uintptr_t (Event)> on_tick;
nall::function<uintptr_t (event_t)> on_tick;
Checkbox();
@@ -403,12 +402,12 @@ private:
class Radiobox : private nall::base_from_member<pRadiobox&>, public FormControl {
public:
void create(RadioboxGroup &group, uint style, uint width, uint height, const char *text = "");
void create(RadioboxGroup &group, unsigned style, unsigned width, unsigned height, const char *text = "");
void set_text(const char *text = "");
void check();
bool checked();
nall::function<uintptr_t (Event)> on_tick;
nall::function<uintptr_t (event_t)> on_tick;
Radiobox();
@@ -432,8 +431,8 @@ public:
VerticalScrollNever = 1 << 6,
};
void create(uint style, uint width, uint height, const char *text = "");
uint get_text(char *text, uint length = -1U);
void create(unsigned style, unsigned width, unsigned height, const char *text = "");
unsigned get_text(char *text, unsigned length = -1U);
void set_text(const char *text = "");
Editbox();
@@ -457,17 +456,17 @@ public:
VerticalScrollNever = 1 << 5,
};
void create(uint style, uint width, uint height, const char *columns = "", const char *text = "");
void create(unsigned style, unsigned width, unsigned height, const char *columns = "", const char *text = "");
void autosize_columns();
void set_column_width(uint column, uint width);
void set_column_width(unsigned column, unsigned width);
void add_item(const char *text);
void set_item(uint index, const char *text);
void set_item(unsigned index, const char *text);
int get_selection();
void set_selection(int index);
void reset();
nall::function<uintptr_t (Event)> on_change;
nall::function<uintptr_t (Event)> on_activate;
nall::function<uintptr_t (event_t)> on_change;
nall::function<uintptr_t (event_t)> on_activate;
Listbox();
@@ -478,13 +477,13 @@ private:
class Combobox : private nall::base_from_member<pCombobox&>, public FormControl {
public:
void create(uint style, uint width, uint height, const char *text = "");
void create(unsigned style, unsigned width, unsigned height, const char *text = "");
void add_item(const char *text);
int get_selection();
void set_selection(int index);
void reset();
nall::function<uintptr_t (Event)> on_change;
nall::function<uintptr_t (event_t)> on_change;
Combobox();
@@ -495,9 +494,9 @@ private:
class Progressbar : private nall::base_from_member<pProgressbar&>, public FormControl {
public:
void create(uint style, uint width, uint height);
uint get_progress();
void set_progress(uint progress);
void create(unsigned style, unsigned width, unsigned height);
unsigned get_progress();
void set_progress(unsigned progress);
Progressbar();
@@ -513,11 +512,11 @@ public:
Vertical = 1 << 1,
};
void create(uint style, uint width, uint height, uint length);
uint get_position();
void set_position(uint position);
void create(unsigned style, unsigned width, unsigned height, unsigned length);
unsigned get_position();
void set_position(unsigned position);
nall::function<uintptr_t (Event)> on_change;
nall::function<uintptr_t (event_t)> on_change;
Slider();

View File

@@ -1,237 +0,0 @@
#include "../hiro.h"
using namespace libhiro;
#include <nall/algorithm.hpp>
using nall::min;
using nall::max;
bool kill_ = false;
uint32_t windowicon[16 * 16] = {
0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000,
0xff000000, 0xffffffff, 0x00000000, 0xffffffff, 0x00000000, 0xffffffff, 0x00000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000,
0xff000000, 0xffffffff, 0x00000000, 0xffffffff, 0x00000000, 0xffffffff, 0x00000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000,
0xff000000, 0xffffffff, 0xffffffff, 0xffffffff, 0x00000000, 0xffffffff, 0x00000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000,
0xff000000, 0xffffffff, 0x00000000, 0xffffffff, 0x00000000, 0xffffffff, 0x00000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000,
0xff000000, 0xffffffff, 0x00000000, 0xffffffff, 0x00000000, 0xffffffff, 0x00000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000,
0xff000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000,
0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000,
0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000,
0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000,
0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000,
0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000,
0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000,
0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000,
0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000,
0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000,
};
class SubWindow : public Window {
public:
Button button;
uintptr_t tick(Event) {
hide();
}
void setup() {
create(0, 595, 80);
button.create(0, 595, 80, "SubWindow (click to hide)");
button.on_tick = bind(&SubWindow::tick, this);
attach(button, 0, 0);
}
} subwindow;
class MainWindow : public Window {
public:
MenuGroup menu_file;
MenuGroup menu_file_disk;
MenuItem menu_file_disk_load;
MenuItem menu_file_disk_save;
MenuSeparator menu_file_separator;
MenuItem menu_file_exit;
MenuGroup menu_help;
MenuCheckItem menu_help_check1, menu_help_check2;
MenuSeparator menu_help_separator1;
MenuRadioItem menu_help_radio1, menu_help_radio2, menu_help_radio3;
MenuSeparator menu_help_separator2;
MenuItem menu_help_about;
Label label;
Editbox editbox, editbox_multi;
Button button_ok;
Button button_exit;
Checkbox check1, check2;
Radiobox radio1, radio2;
Progressbar progress;
Combobox combobox;
Listbox listbox;
Slider hslider, vslider;
Frame frame;
Canvas canvas;
uintptr_t change(Event e) {
printf("change(%d)\n", (uint)e.param);
}
uintptr_t activate(Event e) {
printf("activate(%d)\n", (uint)e.param);
}
uintptr_t tick(Event e) {
printf("tick(%d)\n", e.param);
if(e.widget == &button_ok) {
char t[4096];
editbox.get_text(t, 4096);
printf("'%s'\n", t);
}
if(e.widget == &menu_file_disk_load) {
char t[4096] = "";
hiro().file_open(0, t, "", "Source files\t*.cpp,*.h\nAll Files\t*.*");
printf("'%s'\n", t);
}
if(e.widget == &menu_file_disk_save) {
char t[4096] = "";
hiro().file_save(0, t, "", "Source files\t*.cpp,*.h\nAll Files\t*.*");
printf("'%s'\n", t);
}
}
uintptr_t keydown(Event e) {
static bool fs = false;
if(e.param == nall::keyboard::f11) {
fs = !fs;
fs ? fullscreen() : unfullscreen();
printf("%d -> %4d, %4d\n", fs, get_width(), get_height());
} else if(e.param == nall::keyboard::escape) {
menu.show(!menu.visible());
}
}
uintptr_t close(Event) {
printf("close()\n");
return kill_ = true;
}
void setup() {
create(Window::AutoCenter, 605, 320, "hiro test application");
//set_opacity(224);
//set_background_color(0, 0, 0);
set_icon(16, 16, windowicon);
attach(menu_file.create("File"));
menu_file.attach(menu_file_disk.create("Disk"));
menu_file_disk.attach(menu_file_disk_load.create("Load ..."));
menu_file_disk.attach(menu_file_disk_save.create("Save ..."));
menu_file.attach(menu_file_separator.create());
menu_file.attach(menu_file_exit.create("Exit"));
attach(menu_help.create("Help"));
menu_help.attach(menu_help_check1.create("Check 1"));
menu_help.attach(menu_help_check2.create("Check 2"));
menu_help.attach(menu_help_separator1.create());
{ MenuRadioItemGroup group;
group.add(&menu_help_radio1);
group.add(&menu_help_radio2);
group.add(&menu_help_radio3);
menu_help.attach(menu_help_radio1.create(group, "Radio 1"));
menu_help.attach(menu_help_radio2.create(group, "Radio 2"));
menu_help.attach(menu_help_radio3.create(group, "Radio 3"));
} menu_help.attach(menu_help_separator2.create());
menu_help.attach(menu_help_about.create("About ..."));
menu_help_about.disable();
label.create(0, 200, 35, "hiro test application\n~ byuu");
editbox.create(0, 200, 25);
button_ok.create(0, 100, 30, "Ok");
button_exit.create(0, 100, 30, "Exit");
editbox_multi.create(Editbox::Multiline | Editbox::VerticalScrollAlways, 200, 95);
check1.create(0, 100, 20, "Check 1");
check2.create(0, 100, 20, "Check 2");
{ RadioboxGroup group;
group.add(&radio1);
group.add(&radio2);
radio1.create(group, 0, 100, 20, "Radio 1");
radio2.create(group, 0, 100, 20, "Radio 2");
} progress.create(0, 200, 30);
progress.set_progress(50);
combobox.create(0, 200, 30);
combobox.add_item("Option 1");
combobox.add_item("Option 2");
combobox.add_item("Option 3");
listbox.create(Listbox::Header | Listbox::VerticalScrollAlways, 200, 100, "Name\tValue");
listbox.add_item("a\ttrue");
listbox.add_item("b\tfalse");
hslider.create(Slider::Horizontal, 425, 25, 10);
vslider.create(Slider::Vertical, 25, 200, 10);
frame.create(0, 155, 225, "Canvas:");
canvas.create(0, 135, 195);
for(uint y = 0; y < 195; y++) {
uint32_t *p = canvas.buffer() + y * 135;
for(uint x = 0; x < 135; x++) {
double dx = 128.0 / 135.0 * double(x);
double dy = 128.0 / 195.0 * double(y);
uint32_t c = uint32_t(dx) + uint32_t(dy);
*p++ = (max(0U, min(c, 255U)) ^ 0xff) << 16;
}
}
status.show();
status.set_text("Statusbar");
on_close = bind(&MainWindow::close, this);
on_keydown = bind(&MainWindow::keydown, this);
menu_file_disk_load.on_tick =
menu_file_disk_save.on_tick = bind(&MainWindow::tick, this);
menu_file_exit.on_tick = on_close;
menu_help_check1.on_tick = menu_help_check2.on_tick =
menu_help_radio1.on_tick = menu_help_radio2.on_tick =
menu_help_radio3.on_tick = bind(&MainWindow::tick, this);
menu_help_about.on_tick = bind(&MainWindow::tick, this);
button_ok.on_tick = bind(&MainWindow::tick, this);
button_exit.on_tick = bind(&MainWindow::close, this);
check1.on_tick = check2.on_tick =
radio1.on_tick = radio2.on_tick = bind(&MainWindow::tick, this);
combobox.on_change = bind(&MainWindow::change, this);
listbox.on_change = bind(&MainWindow::change, this);
listbox.on_activate = bind(&MainWindow::activate, this);
hslider.on_change = bind(&MainWindow::change, this);
vslider.on_change = bind(&MainWindow::change, this);
attach(label, 5, 5);
attach(editbox, 5, 40);
attach(button_ok, 5, 70);
attach(button_exit, 105, 70);
attach(editbox_multi, 210, 5);
attach(check1, 5, 105);
attach(check2, 105, 105);
attach(radio1, 5, 125);
attach(radio2, 105, 125);
attach(progress, 5, 145);
attach(combobox, 5, 175);
attach(listbox, 210, 105);
attach(hslider, 5, 205);
attach(vslider, 415, 5);
attach(frame, 445, 5);
attach(canvas, 455, 25);
attach(subwindow, 5, 235);
}
} window;
int main() {
hiro().init();
hiro().disable_screensaver();
subwindow.setup();
window.setup();
window.show();
window.check1.check();
while(kill_ == false) hiro().run();
hiro().term();
return 0;
}

View File

@@ -1,4 +1,4 @@
void pButton::create(uint style, uint width, uint height, const char *text) {
void pButton::create(unsigned style, unsigned width, unsigned height, const char *text) {
hwnd = CreateWindow(L"BUTTON", utf16(text), WS_CHILD | WS_TABSTOP | WS_VISIBLE,
0, 0, width, height,
phiro().default_hwnd, (HMENU)instance, GetModuleHandle(0), 0);

View File

@@ -1,7 +1,7 @@
class pButton : public pFormControl {
public:
Button &self;
void create(uint style, uint width, uint height, const char *text = "");
void create(unsigned style, unsigned width, unsigned height, const char *text = "");
void set_text(const char *text = "");
pButton(Button&);

View File

@@ -1,4 +1,4 @@
void pCanvas::create(uint style, uint width, uint height) {
void pCanvas::create(unsigned style, unsigned width, unsigned height) {
hwnd = CreateWindow(L"hiro_window", L"", WS_CHILD,
0, 0, width, height,
phiro().default_hwnd, (HMENU)instance, GetModuleHandle(0), 0);
@@ -35,7 +35,7 @@ pCanvas::~pCanvas() {
/* internal */
void pCanvas::resize(uint width, uint height) {
void pCanvas::resize(unsigned width, unsigned height) {
if(ibuffer) free(ibuffer);
ipitch = width * sizeof(uint32_t);

View File

@@ -1,6 +1,6 @@
class pCanvas : public pFormControl {
public:
void create(uint style, uint width, uint height);
void create(unsigned style, unsigned width, unsigned height);
void redraw();
uint32_t* buffer();
@@ -11,6 +11,6 @@ public:
/* internal */
BITMAPINFO bmi;
uint32_t *ibuffer;
uint ipitch, iwidth, iheight;
void resize(uint width, uint height);
unsigned ipitch, iwidth, iheight;
void resize(unsigned width, unsigned height);
};

View File

@@ -1,4 +1,4 @@
void pCheckbox::create(uint style, uint width, uint height, const char *text) {
void pCheckbox::create(unsigned style, unsigned width, unsigned height, const char *text) {
hwnd = CreateWindow(L"BUTTON", utf16(text), WS_CHILD | WS_TABSTOP | WS_VISIBLE | BS_CHECKBOX,
0, 0, width, height,
phiro().default_hwnd, (HMENU)instance, GetModuleHandle(0), 0);

View File

@@ -1,6 +1,6 @@
class pCheckbox : public pFormControl {
public:
void create(uint style, uint width, uint height, const char *text = "");
void create(unsigned style, unsigned width, unsigned height, const char *text = "");
void set_text(const char *text = "");
void check(bool state = true);
void uncheck();

View File

@@ -1,4 +1,4 @@
void pCombobox::create(uint style, uint width, uint height, const char *text) {
void pCombobox::create(unsigned style, unsigned width, unsigned height, const char *text) {
hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, L"COMBOBOX", L"",
WS_CHILD | WS_TABSTOP | WS_VISIBLE | CBS_DROPDOWNLIST | CBS_HASSTRINGS,
0, 0, width, 200,

View File

@@ -1,7 +1,7 @@
class pCombobox : public pFormControl {
public:
Combobox &self;
void create(uint style, uint width, uint height, const char *text = "");
void create(unsigned style, unsigned width, unsigned height, const char *text = "");
void add_item(const char *text);
int get_selection();
void set_selection(int index);

View File

@@ -1,12 +1,12 @@
void pEditbox::create(uint style, uint width, uint height, const char *text) {
void pEditbox::create(unsigned style, unsigned width, unsigned height, const char *text) {
bool multiline = style & Editbox::Multiline;
bool readonly = style & Editbox::Readonly;
uint vscroll = (style & Editbox::VerticalScrollAlways) ? WS_VSCROLL :
(style & Editbox::VerticalScrollNever) ? 0 :
ES_AUTOVSCROLL;
uint hscroll = (style & Editbox::HorizontalScrollAlways) ? WS_HSCROLL :
(style & Editbox::HorizontalScrollNever) ? 0 :
ES_AUTOHSCROLL;
bool readonly = style & Editbox::Readonly;
unsigned vscroll = (style & Editbox::VerticalScrollAlways) ? WS_VSCROLL :
(style & Editbox::VerticalScrollNever) ? 0 :
ES_AUTOVSCROLL;
unsigned hscroll = (style & Editbox::HorizontalScrollAlways) ? WS_HSCROLL :
(style & Editbox::HorizontalScrollNever) ? 0 :
ES_AUTOHSCROLL;
hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, L"EDIT", L"",
WS_CHILD | WS_VISIBLE | vscroll | hscroll |
@@ -25,10 +25,11 @@ void pEditbox::set_text(const char *text) {
SetWindowText(hwnd, utf16(temp));
}
uint pEditbox::get_text(char *text, uint length) {
wchar_t buffer[length * 2 + 1];
GetWindowText(hwnd, buffer, length * 2);
unsigned pEditbox::get_text(char *text, unsigned length) {
wchar_t *buffer = new wchar_t[length + 1];
GetWindowText(hwnd, buffer, length);
string temp = (const char*)utf8(buffer);
delete[] buffer;
replace(temp, "\r", "");
strlcpy(text, temp, length);
return strlen(text);

View File

@@ -1,8 +1,8 @@
class pEditbox : public pFormControl {
public:
Editbox &self;
void create(uint style, uint width, uint height, const char *text = "");
uint get_text(char *text, uint length = -1U);
void create(unsigned style, unsigned width, unsigned height, const char *text = "");
unsigned get_text(char *text, unsigned length = -1U);
void set_text(const char *text = "");
pEditbox(Editbox&);

View File

@@ -1,4 +1,4 @@
void pFormControl::resize(uint width, uint height) {
void pFormControl::resize(unsigned width, unsigned height) {
SetWindowPos(hwnd, 0, 0, 0, width, height, SWP_NOZORDER | SWP_NOMOVE);
}

View File

@@ -1,6 +1,6 @@
class pFormControl : public pWidget {
public:
virtual void resize(uint width, uint height);
virtual void resize(unsigned width, unsigned height);
void focus();
bool focused();
void enable(bool = true);

View File

@@ -1,4 +1,4 @@
void pFrame::create(uint style, uint width, uint height, const char *text) {
void pFrame::create(unsigned style, unsigned width, unsigned height, const char *text) {
hwnd = CreateWindow(L"BUTTON", utf16(text), WS_CHILD | WS_VISIBLE | BS_GROUPBOX,
0, 0, width, height,
phiro().default_hwnd, (HMENU)instance, GetModuleHandle(0), 0);

View File

@@ -1,7 +1,7 @@
class pFrame : public pFormControl {
public:
Frame &self;
void create(uint style, uint width, uint height, const char *text = "");
void create(unsigned style, unsigned width, unsigned height, const char *text = "");
void set_text(const char *text = "");
pFrame(Frame&);

View File

@@ -4,11 +4,14 @@
using nall::min;
using nall::max;
#include <nall/utf8.hpp>
using nall::utf8;
using nall::utf16;
namespace libhiro {
LRESULT CALLBACK phiro_wndproc(HWND, UINT, WPARAM, LPARAM);
#include "utf.cpp"
#include "keymap.cpp"
#include "widget.cpp"
#include "window.cpp"
@@ -200,11 +203,11 @@ bool pHiro::file_save(Window *focus, char *filename, const char *path, const cha
return result;
}
uint pHiro::screen_width() {
unsigned pHiro::screen_width() {
return GetSystemMetrics(SM_CXSCREEN);
}
uint pHiro::screen_height() {
unsigned pHiro::screen_height() {
return GetSystemMetrics(SM_CYSCREEN);
}
@@ -230,7 +233,7 @@ pHiro& phiro() {
/* internal */
HFONT pHiro::create_font(const char *name, uint size) {
HFONT pHiro::create_font(const char *name, unsigned size) {
return CreateFont(
-(size * 96.0 / 72.0 + 0.5), //96 = DPI
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -238,9 +241,9 @@ HFONT pHiro::create_font(const char *name, uint size) {
);
}
Widget* pHiro::get_widget(uint instance) {
Widget* pHiro::get_widget(unsigned instance) {
Widget *widget = 0;
for(uint i = 0; i < widget_list.size(); i++) {
for(unsigned i = 0; i < widget_list.size(); i++) {
if(widget_list[i]->p.instance != instance) continue;
widget = widget_list[i];
break;
@@ -274,26 +277,26 @@ LRESULT pHiro::wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
case WM_CLOSE: {
if(!p || p->self.type != Widget::WindowType) break;
Window &w = ((pWindow*)p)->self;
if(w.on_close) return (bool)w.on_close(Event(Event::Close, 0, &w));
if(w.on_close) return (bool)w.on_close(event_t(event_t::Close, 0, &w));
return TRUE; //true = destroy window
} break;
case WM_ENTERMENULOOP: {
if(!p || p->self.type != Widget::WindowType) break;
Window &w = ((pWindow*)p)->self;
if(w.on_block) w.on_block(Event(Event::Block, 0, &w));
if(w.on_block) w.on_block(event_t(event_t::Block, 0, &w));
} break;
case WM_KEYDOWN: {
if(!p || p->self.type != Widget::WindowType) break;
Window &w = ((pWindow*)p)->self;
if(w.on_keydown) w.on_keydown(Event(Event::KeyDown, translate_key(wparam), &w));
if(w.on_keydown) w.on_keydown(event_t(event_t::KeyDown, translate_key(wparam), &w));
} break;
case WM_KEYUP: {
if(!p || p->self.type != Widget::WindowType) break;
Window &w = ((pWindow*)p)->self;
if(w.on_keyup) w.on_keyup(Event(Event::KeyUp, translate_key(wparam), &w));
if(w.on_keyup) w.on_keyup(event_t(event_t::KeyUp, translate_key(wparam), &w));
} break;
case WM_ERASEBKGND: {
@@ -322,39 +325,39 @@ LRESULT pHiro::wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
switch(widget->type) {
case Widget::MenuItemType: {
MenuItem &w = (MenuItem&)*widget;
if(w.on_tick) w.on_tick(Event(Event::Tick, 0, &w));
if(w.on_tick) w.on_tick(event_t(event_t::Tick, 0, &w));
} break;
case Widget::MenuCheckItemType: {
MenuCheckItem &w = (MenuCheckItem&)*widget;
w.check(!w.checked()); //invert check state
if(w.on_tick) w.on_tick(Event(Event::Tick, w.checked(), &w));
if(w.on_tick) w.on_tick(event_t(event_t::Tick, w.checked(), &w));
} break;
case Widget::MenuRadioItemType: {
MenuRadioItem &w = (MenuRadioItem&)*widget;
bool checked = w.checked();
w.check();
if(!checked && w.on_tick) w.on_tick(Event(Event::Tick, w.checked(), &w));
if(!checked && w.on_tick) w.on_tick(event_t(event_t::Tick, w.checked(), &w));
} break;
case Widget::ButtonType: {
Button &w = (Button&)*widget;
if(w.on_tick) w.on_tick(Event(Event::Tick, 0, &w));
if(w.on_tick) w.on_tick(event_t(event_t::Tick, 0, &w));
} break;
case Widget::CheckboxType: {
Checkbox &w = (Checkbox&)*widget;
w.check(!w.checked()); //invert check state
if(w.on_tick) w.on_tick(Event(Event::Tick, w.checked(), &w));
if(w.on_tick) w.on_tick(event_t(event_t::Tick, w.checked(), &w));
} break;
case Widget::RadioboxType: {
Radiobox &w = (Radiobox&)*widget;
bool checked = w.checked();
w.check();
if(!checked && w.on_tick) w.on_tick(Event(Event::Tick, w.checked(), &w));
if(!checked && w.on_tick) w.on_tick(event_t(event_t::Tick, w.checked(), &w));
} break;
case Widget::ComboboxType: {
Combobox &combobox = (Combobox&)*widget;
if(HIWORD(wparam) == CBN_SELCHANGE) {
if(combobox.p.combobox_selection == combobox.get_selection()) break;
if(combobox.on_change) combobox.on_change(Event(Event::Change, combobox.p.combobox_selection = combobox.get_selection(), &combobox));
if(combobox.on_change) combobox.on_change(event_t(event_t::Change, combobox.p.combobox_selection = combobox.get_selection(), &combobox));
}
} break;
}
@@ -369,7 +372,7 @@ LRESULT pHiro::wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
case Widget::SliderType: {
Slider &slider = (Slider&)*widget;
if(slider.p.slider_position == slider.get_position()) break;
if(slider.on_change) slider.on_change(Event(Event::Change, slider.p.slider_position = slider.get_position(), &slider));
if(slider.on_change) slider.on_change(event_t(event_t::Change, slider.p.slider_position = slider.get_position(), &slider));
} break;
}
} break;
@@ -386,9 +389,9 @@ LRESULT pHiro::wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
&& ListView_GetItemState(listbox.p.hwnd, ((LPNMLISTVIEW)lparam)->iItem, LVIS_FOCUSED)
&& ListView_GetItemState(listbox.p.hwnd, ((LPNMLISTVIEW)lparam)->iItem, LVIS_SELECTED)
) {
if(listbox.on_change) listbox.on_change(Event(Event::Change, listbox.get_selection(), &listbox));
if(listbox.on_change) listbox.on_change(event_t(event_t::Change, listbox.get_selection(), &listbox));
} else if(((LPNMHDR)lparam)->code == LVN_ITEMACTIVATE) {
if(listbox.on_activate) listbox.on_activate(Event(Event::Activate, listbox.get_selection(), &listbox));
if(listbox.on_activate) listbox.on_activate(event_t(event_t::Activate, listbox.get_selection(), &listbox));
}
} break;
}

View File

@@ -51,8 +51,8 @@ public:
bool file_open(Window *focus, char *filename, const char *path = "", const char *filter = "");
bool file_save(Window *focus, char *filename, const char *path = "", const char *filter = "");
uint screen_width();
uint screen_height();
unsigned screen_width();
unsigned screen_height();
void enable_screensaver();
void disable_screensaver();
@@ -66,12 +66,12 @@ public:
HWND default_hwnd; //default parent window for all windowless controls
HFONT default_font; //default font for all controls
HBRUSH black_brush; //used for Canvas background
HFONT create_font(const char *name, uint size);
HFONT create_font(const char *name, unsigned size);
array<Widget*> widget_list;
Widget* get_widget(uint instance);
Widget* get_widget(unsigned instance);
LRESULT wndproc(HWND, UINT, WPARAM, LPARAM);
uint16_t translate_key(uint key);
uint16_t translate_key(unsigned key);
};
pHiro& phiro();

View File

@@ -1,4 +1,4 @@
uint16_t pHiro::translate_key(uint key) {
uint16_t pHiro::translate_key(unsigned key) {
switch(key) {
case VK_ESCAPE: return keyboard::escape;

View File

@@ -1,4 +1,4 @@
void pLabel::create(uint style, uint width, uint height, const char *text) {
void pLabel::create(unsigned style, unsigned width, unsigned height, const char *text) {
hwnd = CreateWindow(L"STATIC", utf16(text), WS_CHILD | WS_VISIBLE,
0, 0, width, height,
phiro().default_hwnd, (HMENU)instance, GetModuleHandle(0), 0);

View File

@@ -1,7 +1,7 @@
class pLabel : public pFormControl {
public:
Label &self;
void create(uint style, uint width, uint height, const char *text = "");
void create(unsigned style, unsigned width, unsigned height, const char *text = "");
void set_text(const char *text = "");
pLabel(Label&);

View File

@@ -1,4 +1,4 @@
void pListbox::create(uint style, uint width, uint height, const char *columns, const char *text) {
void pListbox::create(unsigned style, unsigned width, unsigned height, const char *columns, const char *text) {
bool header = style & Listbox::Header;
unsigned hscroll = (style & Listbox::HorizontalScrollAlways) ? WS_HSCROLL :
(style & Listbox::HorizontalScrollNever) ? 0 :
@@ -41,7 +41,7 @@ void pListbox::autosize_columns() {
}
}
void pListbox::set_column_width(uint column, uint width) {
void pListbox::set_column_width(unsigned column, unsigned width) {
ListView_SetColumnWidth(hwnd, column, width);
}
@@ -63,7 +63,7 @@ void pListbox::add_item(const char *text) {
}
}
void pListbox::set_item(uint index, const char *text) {
void pListbox::set_item(unsigned index, const char *text) {
lstring list;
split(list, "\t", text ? text : "");
for(unsigned i = 0; i < count(list); i++) {

View File

@@ -1,11 +1,11 @@
class pListbox : public pFormControl {
public:
Listbox &self;
void create(uint style, uint width, uint height, const char *columns = "", const char *text = "");
void create(unsigned style, unsigned width, unsigned height, const char *columns = "", const char *text = "");
void autosize_columns();
void set_column_width(uint column, uint width);
void set_column_width(unsigned column, unsigned width);
void add_item(const char *text);
void set_item(uint index, const char *text);
void set_item(unsigned index, const char *text);
int get_selection();
void set_selection(int index);
void reset();
@@ -13,5 +13,5 @@ public:
pListbox(Listbox&);
/* internal */
uint column_count;
unsigned column_count;
};

View File

@@ -6,7 +6,7 @@ void pMenuGroup::create(const char *text_) {
void pMenuGroup::attach(MenuControl &menucontrol) {
switch(menucontrol.type) {
case Widget::MenuGroupType: {
AppendMenu(group, MF_STRING | MF_POPUP, (uint)((MenuGroup&)menucontrol).p.group, utf16(menucontrol.p.text));
AppendMenu(group, MF_STRING | MF_POPUP, (unsigned)((MenuGroup&)menucontrol).p.group, utf16(menucontrol.p.text));
} break;
case Widget::MenuItemType:

View File

@@ -5,7 +5,7 @@ void pMenuRadioItem::create(MenuRadioItemGroup &group_, const char *text_) {
}
void pMenuRadioItem::check() {
for(uint i = 0; i < group.size(); i++) {
for(unsigned i = 0; i < group.size(); i++) {
CheckMenuItem(parent, group[i]->p.instance, (group[i] == &self) ? MF_CHECKED : MF_UNCHECKED);
}
}

View File

@@ -1,4 +1,4 @@
void pProgressbar::create(uint style, uint width, uint height) {
void pProgressbar::create(unsigned style, unsigned width, unsigned height) {
hwnd = CreateWindow(PROGRESS_CLASS, L"", WS_CHILD | WS_VISIBLE | PBS_SMOOTH,
0, 0, width, height,
phiro().default_hwnd, (HMENU)instance, GetModuleHandle(0), 0);
@@ -6,12 +6,12 @@ void pProgressbar::create(uint style, uint width, uint height) {
SendMessage(hwnd, PBM_SETSTEP, MAKEWPARAM(1, 0), 0);
}
uint pProgressbar::get_progress() {
uint progress = SendMessage(hwnd, PBM_GETPOS, 0, 0);
unsigned pProgressbar::get_progress() {
unsigned progress = SendMessage(hwnd, PBM_GETPOS, 0, 0);
return max(0U, min(progress, 100U));
}
void pProgressbar::set_progress(uint progress) {
void pProgressbar::set_progress(unsigned progress) {
progress = max(0U, min(progress, 100U));
SendMessage(hwnd, PBM_SETPOS, (WPARAM)progress, 0);
}

View File

@@ -1,9 +1,9 @@
class pProgressbar : public pFormControl {
public:
Progressbar &self;
void create(uint style, uint width, uint height);
uint get_progress();
void set_progress(uint progress);
void create(unsigned style, unsigned width, unsigned height);
unsigned get_progress();
void set_progress(unsigned progress);
pProgressbar(Progressbar&);
};

View File

@@ -1,4 +1,4 @@
void pRadiobox::create(RadioboxGroup &group_, uint style, uint width, uint height, const char *text) {
void pRadiobox::create(RadioboxGroup &group_, unsigned style, unsigned width, unsigned height, const char *text) {
group = group_;
hwnd = CreateWindow(L"BUTTON", utf16(text), WS_CHILD | WS_TABSTOP | WS_VISIBLE | BS_RADIOBUTTON,
0, 0, width, height, phiro().default_hwnd, (HMENU)instance, GetModuleHandle(0), 0);
@@ -11,7 +11,7 @@ void pRadiobox::set_text(const char *text) {
}
void pRadiobox::check() {
for(uint i = 0; i < group.size(); i++) {
for(unsigned i = 0; i < group.size(); i++) {
SendMessage(group[i]->p.hwnd, BM_SETCHECK, (WPARAM)(group[i] == &self), 0);
}
}

View File

@@ -1,6 +1,6 @@
class pRadiobox : public pFormControl {
public:
void create(RadioboxGroup &group, uint style, uint width, uint height, const char *text = "");
void create(RadioboxGroup &group, unsigned style, unsigned width, unsigned height, const char *text = "");
void set_text(const char *text = "");
void check();
bool checked();

View File

@@ -1,4 +1,4 @@
void pSlider::create(uint style, uint width, uint height, uint length) {
void pSlider::create(unsigned style, unsigned width, unsigned height, unsigned length) {
if(length < 1) length = 1;
hwnd = CreateWindow(TRACKBAR_CLASS, L"",
@@ -11,11 +11,11 @@ void pSlider::create(uint style, uint width, uint height, uint length) {
SendMessage(hwnd, TBM_SETPOS, (WPARAM)true, (LPARAM)0);
}
uint pSlider::get_position() {
unsigned pSlider::get_position() {
return SendMessage(hwnd, TBM_GETPOS, 0, 0);
}
void pSlider::set_position(uint position) {
void pSlider::set_position(unsigned position) {
SendMessage(hwnd, TBM_SETPOS, (WPARAM)true, (LPARAM)(slider_position = position));
}

View File

@@ -1,12 +1,12 @@
class pSlider : public pFormControl {
public:
Slider &self;
void create(uint style, uint width, uint height, uint length);
uint get_position();
void set_position(uint position);
void create(unsigned style, unsigned width, unsigned height, unsigned length);
unsigned get_position();
void set_position(unsigned position);
pSlider(Slider&);
/* internal */
uint slider_position;
unsigned slider_position;
};

View File

@@ -24,4 +24,4 @@ pWidget::~pWidget() {
//100 is the standard start index for control IDs in the Windows API
//avoids duplicate IDs when they are not explicitly set (and are thus 0)
uint pWidget::instance_counter = 100;
unsigned pWidget::instance_counter = 100;

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