Compare commits

...
177 Commits
Author SHA1 Message Date
Luke Usher 1e6e9fd36e ares v141 2024-11-04 10:19:26 +00:00
Fernap 8111bf3163 Fix for SA-1 side DMA to BWRAM banks 0x41+ (#1687)
DDA was incorrectly capped at 16 bits instead of 24, making DMAs to
BWRAM banks 0x41-43 be sent to the corresponding spot in 0x40 instead.
See [the corresponding bug in
bsnes](https://github.com/bsnes-emu/bsnes/issues/309) for some more
context.
2024-11-02 14:26:09 +00:00
jcm c287c1b225 build: macOS back-compatibility fixes (#1682)
While checking out minimum requirements for the new build system, found
a couple small issues worth fixing:

* librashader was not operable on systems pre-macOS 12 with a linker
issue; it can be resolved by setting a minimum deployment target; here
we do that by setting an environment variable on CI.
* While investigating this, I found that librashader's minimum required
macOS seems to be 10.15; this is because `glslang` seems to require
macOS 10.15.
* It wasn't possible to build the Metal driver because of the older SDK
lacking some definitions; however, we can fall back to the
`__MAC_OS_X_VERSION_MAX_ALLOWED` compile definition which we do here.
* Not sure if building on these older systems should really be
considered "supported", but since the fix here was simple enough it
seems fine to throw it in.

paraLLEl-RDP and MoltenVK seem to have [a lot of
issues](https://github.com/user-attachments/assets/088879a9-9153-4b05-a207-212cfac7f831)
on my older system's GeForce 650M. I was able to compile debug MoltenVK
locally, but Xcode GPU capture just hung, so I was unable to figure out
what was going on. Either a driver issue or a MoltenVK issue seems like
the probable culprit. In any case, performance wasn't really good enough
to make me want to investigate further. Other cores seem to work well.

Tested [on my fork's
CI](https://github.com/jcm93/ares/actions/runs/11554703214) to make sure
everything still works.
2024-10-28 15:30:08 +00:00
Giovanni Bajo 863593ed7f n64: remove call to epilogue function from the jit (#1663) 2024-10-28 11:44:11 +00:00
Giovanni Bajo c20d405006 n64: add unusual warning when using CACHE on uncached addresses (#1678)
The CACHE opcode does not work correctly when the specified virtual
address is in an uncached segment. The exact hardware behavior has not
been reversed yet (we know for instance that when doing cache
invalidation, some other cacheline is invalidated instead, but we do not
know the relation yet).

Nonetheless, the behavior is really obscure and all usages should be
considered bugs. Add a debug unusual warning for now (mainly to help
developers, as this is a known instance where Ares doesn't yet follow
hardware behavior).
2024-10-28 11:43:17 +00:00
png183 e1e1bedb2d gba: selectively synchronize CPU and APU, and add option to disable pixel accuracy (#1679)
Similarly to how the S-CPU and S-SMP are handled in the SFC core, it's
possible to run the GBA CPU and APU more asychronously as long as
synchronization is performed on FIFO or APU I/O accesses. From my
testing on Linux, this performs comparably to the performance profile
but without the accuracy downsides, so the performance/accuracy profiles
have been removed (the more accurate behaviour is now always used).

This PR also adds an option to disable pixel accuracy in the GBA core in
exchange for ~10-15% performance benefits, and makes some small PPU
timing improvements that were not feasible to implement in the
performance profile.
2024-10-28 11:43:07 +00:00
Chase Meadors 9f060c769b Allow arbitrary and possibly unaligned writes to RDRAM through gdb (#1639)
We want to allow arbitrary writes through the GDB server to the RDRAM
area. This was done in #1620, but that version has a subtle issue where
the server will still refuse to write or change writes that happen to be
of size `Byte|Half|Word|Dual` if the addressed is not aligned to that
size.
This PR fixes the issue by checking if the write is to RDRAM first,
allowing arbitrary and possibly unaligned writes. Otherwise, the write
is handled through the normal machinery where these issues may be
semantically important.
2024-10-27 15:14:30 +00:00
remutro e7f9af4bbd [N64] allow for pak swapping on controller port 1 (#1672)
This pull request allows for all pak swapping on controller port 1 only.
It also enables support for the transfer pak for the 64DD which was
previously missing.

It is being added for port 1 only now because there is additional work
to manage all the different saves, and gameboy games/saves with the
transfer pak which is a larger effort, and Luke is currently looking
into modifying settings in a more complete manner. So other ports can be
added later. For most people, being able to swap for the first
controller is likely good enough.

This pull request doesn't change any of the current initialization logic
regarding default pak selection that already existed.
2024-10-26 07:53:52 +01:00
jcm 65c34c2ea4 nall: Namespace noinline macro (#1674)
This is a change spun off from continuing build system work.

There, we've found that precompiling the `ares/ares.hpp` header can
speed up compile times for the emulator cores by 30-35%. Doing so,
however, leads to a few collisions:

* Several files in parallel-rdp use the `Hash` type, which variously
resolves to a `Hash` in its own namespace as well as nall's namespace.
* Also in the N64 core, nall's `noinline` macro conflicts with similar
definitions present in `xxhash`.

For parallel-rdp, we can simply skip precompiled headers for the
conflicting files; parallel-rdp does not use anything in the
`ares/ares.hpp` header, so including it there is unnecessary anyway.

This change resolves the second set of collisions by putting nall's
noinline preprocessor macro into its own namespace.

There are many macros remaining that are not namespaced. I did not
proceed in namespacing them for this PR, because there are a lot of
them, and it would be a fairly significant code style change that
probably merits further discussion (not to mention, it will be a decent
amount of work). However, in this instance, there is (or will be) a
material benefit that probably trumps the minor style issue.
2024-10-26 07:53:36 +01:00
png183 9babe6a02b gba: OBJ timing improvements (#1676)
Implements a couple improvements to OBJ-related timings:

- OBJs are now rendered one scanline in advance, as on hardware
- OBJ palette RAM accesses are now performed in `PPU::Objects::run`
rather than `PPU::Objects::scanline`, bringing OBJ PRAM access timings
closer to matching hardware
2024-10-26 07:53:20 +01:00
png183 7e5292cd16 gba: horizontal mosaic fixes (#1669)
Addresses an off-by-one error with BG mosaic, and fixes an oversight in
how OBJ mosaic was handled at x=0.
2024-10-22 11:32:42 +01:00
remutro a8274cd127 [N64] Add support for 40 Winks (Aftermarket) and support for additional supported regions (#1666)
40 Winks was released aftermarket on physical media, and support has
been added for this (does NOT include prototypes). The US version was
tested, but was unable to test the EU release (game Id and pak options
should be the same and should theoretically work).

Additionally, looks like ares was missing some region descriptions, so
these have been added as well based on info located at:
https://n64brew.dev/wiki/ROM_Header#Advanced_Homebrew_ROM_Header
2024-10-18 11:11:07 +01:00
Giovanni Bajo d99b0a3725 n64: use different GDB signals for different exceptions (#1667)
When debugging homebrew with gdb, it might be annoying if gdb stops at
exceptions that are correctly handled by the running application. This
is a bit hard to know so, besides providing some (debatable) default, we
need a way to selectively ignore specific exceptions.

This commit generates different GDB signals for different families of
exceptions. The mapping between MIPS exceptions and UNIX signals is
completely arbitrary; it tries to "sort of" match the meaning of the
exception where possible, and otherwise just use a random signal.

The GDB client can configure which signals should be logged, which
should cause the application to stop, and which should be ignored, using
the "handle" command.

By default, we want to ignore exceptions generated by interrupts (as
those are normally handled by the application) and those handled by the
operating system (like the COP1 exception which both libultra and
libdragon use to speed up context switching). To do so, we assign to
them signals that are ignored by default by gdb (SIGWINCH and SIGURG
respectively).
2024-10-16 06:32:31 +01:00
Luke Usher e43f3f75f7 add ymfm to update-subtrees script 2024-10-08 11:48:21 +01:00
Luke Usher f894a85253 Merge commit '09fbcc4e65efe68eefc6d4f502fd92cb9ee310b4' 2024-10-08 11:33:31 +01:00
Luke Usher 09fbcc4e65 Squashed 'thirdparty/ymfm/' changes from d641a80631..d334ab1a95
d334ab1a95 Fix left-shift signed overflows (UB) (#62)
434e793dc4 Assert that only valid timer numbers are passed to engine_timer_expired().
16e1d4281a Use snprintf instead of sprintf to fix #59. Use std::array for operators to remove the need for array_size.
4e654a3e8f Add virtual destructors to all base abstract classes, to prevent memory leaks (#55)
1a5cc66cb6 Keyon all ops on CSM mode (#56)

git-subtree-dir: thirdparty/ymfm
git-subtree-split: d334ab1a957351ce2a0aa2777b8c704664be3189
2024-10-08 11:33:31 +01:00
Luke Usher 73d90e6e7c Merge commit '38dd6defa99bb03aa5e4dc2fc1f492b2e85aa10c' 2024-10-08 11:33:15 +01:00
Luke Usher 38dd6defa9 Squashed 'thirdparty/slang-shaders/' changes from ec1b855638..263a54c414
263a54c414 Update crt-ntsc-sharp presets (#642)

git-subtree-dir: thirdparty/slang-shaders
git-subtree-split: 263a54c414681b45fd9428143a8320f4024a99ab
2024-10-08 11:33:15 +01:00
Luke Usher 030488aba7 Merge commit 'b2175473f0476248724ba73bb80b71a1c669797d' 2024-10-08 11:33:01 +01:00
Luke Usher b2175473f0 Squashed 'thirdparty/librashader/' changes from 4abd48eb24..cbdbdafecd
cbdbdafecd chore: Release
ffcb8ba1d1 doc: Update BROKEN_SHADERS.md
941275199b build: unpin cc
525c311844 cli: allow raw-id for spirv output
2fe66d958f reflect: put vars to end with running link pass to fix naga ordering
ed8bf637a9 cli: size_of not in prelude
7555bb9024 build: make librashader-reflect features-table more consistent
562e1e5f18 doc(msrv): bump msrv to 1.78
13b44e1639 cargo: revert lockfile version
240aae1bcf chore: Release
95a489ee12 cli(render): allow specifying output dimensions

git-subtree-dir: thirdparty/librashader
git-subtree-split: cbdbdafecdfd6113ef1cdc15e0a4140b46420f0b
2024-10-08 11:33:01 +01:00
Luke Usher bc2a54800f fix sljit after update 2024-10-05 12:56:24 +01:00
Stefan Schlosser 6e182d8542 thirdparty/librashader: activate runtimes in librashader_ld.h 2024-10-05 12:37:24 +01:00
jcm 38f64fa70c ruby/metal: Update to librashader ABI 2 (#1)
We elect to just remove all usage of libra_viewport_t for Metal, since the current rendering path conforms better to recommended Metal patterns than passing the drawable texture directly to librashader would.
2024-10-05 12:34:08 +01:00
Stefan Schlosser 7eb1b28671 ruby/opengl: adapt to librashader ABI 2
The libra_gl_init_context function has been removed. The OpenGL loader used to
create the filter chain, previously passed to libra_gl_init_context, is now
passed as a parameter to the libra_gl_filter_chain_create function.

The libra_output_framebuffer_gl_t and libra_source_image_gl_t structs have been
replaced with libra_image_gl_t.

The position of the viewport parameter in libra_gl_filter_chain_frame has moved
to after the output parameter, and its type has changed from libra_viewport_t to
libra_viewport_t *.

In order to retain the behaviour in ABI 1, output holds the width and height of
the previously used viewport and the viewport itself is removed and replaced
with NULL in the call to _libra.gl_filter_chain_frame.
2024-10-05 12:34:01 +01:00
Stefan Schlosser 42c16831b7 thirdparty/librashader: update SONAME of librashader.so in build-librashader.sh 2024-10-05 12:33:31 +01:00
Luke Usher 5982fa8ae3 Squashed 'thirdparty/slang-shaders/' changes from 693c632bdd..ec1b855638
ec1b855638 Add RF-nes presets to crt-royale-fast folder (#640)
a8e35920c5 Update crt-geom.slang (#639)
901441a496 Update crt-royale-fast and several presets (#638)
33876b3578 ensure testPattern() always has a return condition
5ab3c76109 update patchy-ntsc shaders and presets (#637)
edd2dd3f77 fix some errors identified by librashader scan (#636)
630fe655fe fix mudlord-pal-vhs
49c77cab02 remove another conflicting pass from preset
e1f7c6cc0e remove broken/unused pass from preset
0e29397870 add small, colored border shader (#635)
4ef678cab0 fix bad path
bd0ea94fc8 fix/update glow-trails shaders and presets (#634)
0dd9204791 Update crt-royale-fast and its presets (#633)
24f9468e2e Add crt-royale-pvm-shmup preset (#632)
0a305b879e Update crt-royale-fast and add new presets (#631)
1b2ad364b7 Add edgeNpixels shader (#630)
b9e012f25c Patchy NTSC - Bunch of last minute improvements (#629)
4cf85d3147 New NTSC shader by PlainOldPants (#627)
ef68606c0e Add edge1pixel shader (#628)
0cededfa7f ntsc-simple update to glsl version (#626)
811bb31cdb port tiny_ntsc (#625)
ef702029d8 Fix color clipping in crt-hyllian (#624)
b6b55c3995 Update crt-hyllian (#623)
26e9882eb2 Update crt-hyllian (#622)
b3d795acb9 Add crt-royale-ntsc-composite-fast preset (#620)
111fcedc3b Add crt-royale-fast shaders (#619)
b327343b77 Fix a 7-year old bug in crt-royale-bloom-approx.h (#618)
679a3321c1 Update crt-geom-mini.slang (#617)
f65a4bce69 Sync to koko-aio 1.9.30 (#616)
7d6751a07c update crt-guest to latest (#614)
05a41341be Fix input TF bug & large refactoring; Add box filter AA (#613)
5e702cfdc6 Added flat trinitron TV filters (#611)
1c6f2cd834 Add zfast_crt_geo shader (#612)
46b96cbd39 update crt-geom-mini to glsl version (#610)
959de2bb2e Reverted texture optimizations as they are breaking rendering. (#609)
23f90e3b27 crt-geom-mini update from glsl, crt-pocket fix clamp error (#607)
3796d44482 Update geom.slang (#606)
89dfd9bbd0 Add Geom shader (#605)

git-subtree-dir: thirdparty/slang-shaders
git-subtree-split: ec1b8556388317258376467c1561ecb91a06a466
2024-10-05 12:32:59 +01:00
Luke Usher 5f435345f1 Merge commit '5982fa8ae35f801150b06b8db273b628ea0f7cd9' 2024-10-05 12:32:59 +01:00
Luke Usher 8343f8136c Merge commit '4dcba4224027a101e7d4e21d23ada1f08e7baf2c' 2024-10-05 12:32:27 +01:00
Luke Usher 4dcba42240 Squashed 'thirdparty/librashader/' changes from fff80df5a0..4abd48eb24
4abd48eb24 capi(presets): support `d3d9_hlsl` VID-DRV
0007bd6d98 doc: update preset_ctx_set_runtime doc
72c72dafa0 capi(d3d12): remove unintentional IMAGE_TYPE infix for LIBRA_D3D12_IMAGE_TYPE
0fde712f3c doc: update librashader::reflect docs
2323b18710 capi(ld): add `LIBRA_RUNTIME_D3D9` define commented out
5978f95f76 reflect: make `ShaderPassArtifact` simpler as `PassResource` already includes the source data
3ee5e66c0d presets: make naming more consistent
f189468f6d ci: don't build cli for windows 7
fc47fb4c5a doc: typo
fc7739d9ab ci: update github actions
4a8a9ee444 chore: Release
756cbe63d9 cli: fix cli Cargo.toml
796b03b42b test: rework tests to work with ShaderPresetPack
742a1c8658 dep: update glslang
7c03a7e3fe doc(pack): reword doc on `ShaderPresetPack`
4ba6effc2f rt(mtl): fix test
32c99d9f4a rt: implement filter chain loading in terms of pack
75b70cc0e6 cli: add `pack` command to create a preset pack
828464c351 rt(image): helper to load image from shaderpack `TextureBuffer`
c19593e289 pack: implement shader pack library to preload resources from disk
1bbbd784d8 preset: make ShaderPassConfig and TextureConfig type aliases to PathReference
4273a833e8 pack: add librashader-pack
f14f45b3b1 rt: separate out meta information for textures
859d16e64e rt: separate out meta information to its own struct
b395b94a40 doc(abi2): add migration details for `libra_source_image_d3d12_t` layout
90a9ee754d doc: fix migration api typo
34b50059ca doc(d3d12,vk): clear up language for barriers
7a13136f9a capi(d3d12): allow d3d12 to optionally use a resource handle with chain-managed descriptors
0cb3880d7f rt(d3d12): allow construction of D3D12InputImage without a descriptor handle
c526b7043a capi(d3d12): change the layout so that descriptor is first in libra_source_image_d3d12_t
33d95ac399 rt(d3d12): allow creating input view without a CPU handle
40691cc406 rt(d3d12): allow creating output view from a resource ref
3c20c83bc9 rt(d3d12): use InterfaceRef for D3D12InputImage to avoid refcount for input image
b123f63a6e doc(reflect): fix link
4285ad2bd1 rt(d3d12): allow a pipeline to be available for multiple formats without recompilation
c57e502b78 rt(d3d12): make images with OwnedFramebuffer provenance use ManuallyDrop
7edff0ae35 rt(d3d12): allow manually specifying the strategy to get a manuallydrop for luts
dedde05c83 rt(d3d12): move update subresources to lut
7d483f2e08 rt(d3d9): take viewport by reference to avoid AddRef/Release
7b7fd99b92 rt(d3d11): take viewport by reference to avoid AddRef/Release
28931ae50a rt(d3d12): update d3d12-descriptor-heap
2fe7702957 rt(d3d11): avoid QueryInterface in GetSize
a5c8fcf4f8 doc: missing period
629070ea2f ci: build cli
da53c3df59 cli(render): make frame inclusive to ensure correct feedback and history behaviour
84e78f4e48 cli(render): add ability to specify frame options
91f8089277 cli(render): add ability to specify params and passes enabled
3993f57271 doc(cli): document CLI
55ff7a93f2 cli: rename librashader-test -> librashader-cli
227757a221 cli: parse transpile versions
a72a593029 reflect: allow indexed and non-indexed semantics to be serialized and deserialized as strings
1537c1bcd7 cli: ensure shaders are validated before compile
5573f13227 test: add CLI with multiple functions
bac09ad2a3 reflect: allow validation of shaders without reflecting against semantics
31ece05246 reflect: allow more reflection objects to be serializable
5ede061975 preprocess: allow shadersource to be serializable with serde
1676150858 presets: allow presets to be serializable with serde
eeda0d02d0 test: make RenderTest trait object safe
f7a938a00d deps: update dependencies
6394b28d40 deps: update dependencies
443fa20d22 test: clean up imports and features
5c726efe21 test(d3d12): Add D3D12 render test
d33c2a84b2 test(d3d9): Add Direct3D 9 render test
5a35a2bd1e test(render): reenable cache
41034330a7 test(mtl): Add Metal render test
a7836923d7 test: split test harnesses into features
20039b9347 test: abstract test framework
799d409ddb test(gl): Add OpenGL render test
79513a301e test(vk): Add Vulkan render test
6de2de8d12 test(wgpu): Add WGPU render test
2904a2ac10 test(d3d11): Add D3D11 triangle test to image
341fbceb82 rt(d3d12): derive clone on D3D12InputImage
c54747d398 deps: update dependencies
3888b56c83 rt(d3d9): accept input image by reference
b0df631651 rt(d3d9): load LUTS as BGRA8
dbfa822f7c rt(d3d9): disable alpha blending
e7fe96520e rt(gl): ensure framebuffers are bound
97ad0d64bf rt(gl): make FilterChain::load_from argument order consistent with other runtimes
feaebc5f44 fmt(gl): cargo fmt
ef35e2a620 presets: rename to_hashmap -> into_hashmap
987e967269 doc(capi): add error doc for infallible error
c3469520f9 examples(d3d11): fix d3d11 examples
45b98a2bdd rt(gl): use array_init instead of manually doing it with MaybeUninit
2ee9eca854 ci: ignore .DS_Store
59937aced5 fmt: cargo fmt
e4eed34c10 capi: const qualify chain in `_filter_chain_get_param` and `_filter_chain_get_active_pass_count`"
7abd679bd7 doc: add migration docs
41353ac9c4 rt(gl): remove need for explicit external FBO object
4d790e7a7b doc: update ABI versions in version.rs and readme
aeb0a16cfb rt(vk): allow specifying the queue to use
16108838b1 rt(d3d11): remove unneeded transmutes
7cfbca7755 rt(wgpu): remove unnecessary output move
8467e5cd97 rt(mtl): remove unnecessary output move
1e33b4cc03 capi: make viewport optional, defaulting to a viewport that is the entire size of the render target
eb53699590 capi(include): update headers
0cbf8024a7 build: update soname
7e354a56a1 capi: upgrade cbindgen to fix syn bug
0a87bcc657 rt: respect viewport extents when rendering
f0a7970b44 rt: add viewport extent separate from output texture dimensions
e7e6ed8fb8 capi: remove _internal_alloc from libra_preset_param_list_t
61fdaeea14 capi(gl): update to take opengl context in constructor
2552d4321b capi(gl): set output in libra_output_image_gl_t, not viewport
eaf939c861 capi(vk): set output in libra_output_image_vk_t, not viewport
14abb0362b capi(d3d12): set output in libra_output_image_d3d12_t, not viewport
e064f8d0be capi(d3d12): remove ignored fields from libra_source_image_d3d12_t
f18c22a95a capi(d3d11): take ManuallyDrop<ID3D11ShaderResourceView> directly in libra_d3d11_filter_chain_t
763c05755d rt: mark error types as non_exhaustive
e6d23f1d8f doc: update opengl example
2f9df143cf deps: consolidate and update dependencies
1bdadaa449 rt(gl): port to OpenGL runtime to glow
77b957bf5e reflect: stop adding null bytes to uniform names
1e0727f89d chore: Release
60d2c3f177 chore: Release
72a98272f3 doc(capi): document all C API members
7d0b135710 rt(mtl): remove unused 'pass lifetime
4ba5aefafc capi: don't export wrap_ok macro
6edfaed91f test: update slang-shaders
cd877d7883 build: respect CARGO env in build script
d56d92ea0f test: update slang-shaders
f49e3b58d8 doc(capi): fix rotation integer docs
1f4f1b6c12 capi: Fix Metal error message, function header
57f2dabf0c reflect: fix `CurrentSubFrame` being parsed as `TotalSubFrames`
81840a9e9c reflect: insert alias semantics for shader name through pragma
87e0405675 presets: properly trim shader name if given through pragma
e0c97f77b4 build: nicer build script messages
6e60dd6fa0 test: update slang-shaders
d55d0e4839 rt(mtl): use f32::MAX for lodMaxClamp
6cdd9247de presets: trim aliases and shader parameter names
cbe6510f76 preprocess: the step argument is optional according to slang-shaders spec
d6f8950bdc rt: only draw last pass twice if the last pass is needed as feedback
0fe5bbd57b rt: do reflection to see if the final pass is needed as feedback
eace595ebb chore: Release
66561ad2ed doc: fix header image
05d48841ad doc: update docs for stable build instructions
927740433c build: remove unneeded image dependency
316e92dc09 build: allow building stable with --stable flag
e930f90a9c capi: allow building on stable by gating #[doc] comments
2f988d5b1d rt: add stable feature to build ShaderPassArtifacts via Box<dyn CompileReflectShader>
e0a5c90103 reflect: implement stable FromCompilation
4cc3c875bf reflect: allow compilation of boxed trait objects
805854b94b reflect: simplify FromCompilation output signature
c291d9d85f capi: remove dependency on `try_blocks`
8b2ff57ee8 reflect: replace `let_chains` with `Option::filter`
3d9139b4e0 rt(d3d11): replace `let_chains` with stable alternatives
b432a1e02d rt(d3d12): replace `let_chains` with stable alternatives
ab9ab6fe68 rt(gl): use `Option::filter` instead of `let_chains`
0ba4c482b3 rt(vk): use `Option::filter` instead of `let_chains`
57f9a13ee7 rt(wgpu): use `Option::filter` instead of `let_chains`
2661effab4 chore: Release
02288554b9 rt(mtl): fix history buffer off-by-one by buffering the history read.
98d8d91c66 capi: undo const qualification of chain in `_filter_chain_get_param` and `_filter_chain_get_active_pass_count`
6f5b342c1b build: fix dev-dependencies on non-apple
bec0482513 ci: trigger ci
e24beede0b rt(mtl): draw final pass to output targets
22b2118e97 rt(mtl): don't resize if the requested format differs from optimal format
856f69113d rt(mtl): don't make mipmapper for history if not needed
477d0ae67c rt(wgpu): draw final pass to output targets
e68da7b984 rt(gl): draw final pass to output targets
666588ef0d rt(vk): draw final pass to output targets
336f540ce9 rt(d3d9): draw final pass to output targets
894d19eb81 rt(d3d12): draw final pass to output targets
1bf5d7efca rt(d3d11): draw final pass to output targets
c9205bc922 rt(mtl): remove internal_frame_count
cebc7a939a rt(mtl): fix faulty history but only copying one mipmap slice of texture
fe48fd03a5 test(mtl): update the metal test
50580cfc3b chore: Release
075a2981e1 rt(gl): fix `glShaderSource` going past the buffer
a7dd40a79f ci: allow c_str_literals to maintain a lower MSRV
fd8d6f6ab8 chore: Release
c5fdffa6aa dep: update cargo.lock
090e268c4a doc: improve docs
8856a78eb8 api: expose `FastHashMap` and `ShortString`
ec3add1616 rt(params): rename get_parameter -> parameter_value
f83fd1e98f ci: debug is broken on windows 7
c3033cfbbf reflect: port to spirv-cross2
820fb69328 reflect: remove get_prefix from get_texture_semantic/get_unique_semantic
c9a6411394 deps: consolidate and update dependencies
40a56bf165 reflect/preprocess/presets: use SmallString where it makes sense
c447e40583 rt: redesign parameters to be thread-safe across FFI using arcswap and atomicusize
ae76bf9cc1 rt(d3d12): pull out descriptor heap implementation into its own crate
e934f175ef rt(d3d12): stop leaking transition barriers
2e7c3b3273 rt(d3d12): use gpu_allocator instead of CreateCommittedResource
e90c27ebbd rt(vk): use manuallydrop for VulkanBuffer rather than Option
8fb5d48a1e chore: Release
b7fd3bc507 runtime: fix image swizzle for remainder
af05cc5bd8 ci: build for windows 7
2f0a3356d9 rel([email protected]): doc fix
0efaf2b8a0 doc: fix docsrs build on macos
436d1fe3cd chore: Release
0ce11bac71 doc: promote d3d9 to secondary support
bc269c270c rt(d3d9): remove backtrace from Direct3DError
db3d5d05a6 presets: use crate for extract_if with fully qualified syntax to avoid name collision with unstable std
1957f576ca reflect: further improve link i/o pass by ensuring that the output SPIR-V is valid according to Vulkan 1.0 semantics
5560c1ed09 runtime: use a more efficient swizzling implementation without array_chunks_mut
f8c055524b doc(readme): document shader pre-linkage
fee92113f1 ci: remove PR full test
45c3c876f4 reflect: remove explicit compile function in favour of TryFrom
28f5674a80 presets: remove rustc 1.74 compatibility
bffad12ea2 doc(presets): add docstring for ContextItem::key
321e30a0f1 capi: extend config_struct macro to handle overrides
9b40c10466 reflect: improve inout link algorithm
cd14bca23a Revert "reflect: improve inout link algorithm"
1ac78695c6 reflect: improve inout link algorithm
d1e49b7eb4 rt(d3d9): search "global" namespace for register assignments
5ef0055e05 rt(d3d9): fix vertex assignments accidentally searching fragment
1c6581d737 rt(d3d9): set colorwritemask to all
ac66b1b6f6 style: fix warnings
977975f4c7 doc: document naga reflect
3b9514ad38 doc: allow wgpu doc on apple
899fb50da6 chore: Release
162226ce44 ci: don't build locally
039fdfd41a ci: update OBS build platform
e13bb88df2 doc: update MSRV due to naga
7b375658c5 dep: update cargo.lock
3fb6e3843e dep: update to windows 0.58
3cda5b706d rt(d3d12): get rid of size in inputview
4d6793d305 rt(d3d11): get rid of input/output view wrappers
35f499f5e1 wgpu: enable pipeline caching
6ce711db26 ci: don't build Arch
d4b4366836 dep: update ash to 0.38
c646086df4 dep: update wgpu
f6cf642e50 chore: Release
98958dfb5e dep: update rustc_hash
b5d523e9f3 rt(mtl): move icrate definitions to objc2-metal
5e9ce1207c Revert "ci: temporarily remove deny-deprecated on ctypes to unblock ares"
1b0574c140 presets: show file name and details on io error
b84e104212 capi: fix malformed vulkan include

git-subtree-dir: thirdparty/librashader
git-subtree-split: 4abd48eb244e15ca40307f28fce0061627ff0143
2024-10-05 12:31:45 +01:00
Luke Usher 81d5cdba32 Merge commit '5151003fa4331d3a4473c32e6c7b4ebcd59e29ba' 2024-10-05 12:31:42 +01:00
Luke Usher 5151003fa4 Squashed 'thirdparty/libchdr/' changes from aa34b14191..aaca599e18
aaca599e18 Merge pull request #130 from notaz/release_lzma_init_buffers
2099836c2b release lzma init buffers
9b6ff6c3c2 Merge pull request #128 from scribam/zstd-legacy
85dd19217a Merge pull request #129 from scribam/arm-neon
71e57f533d lzma: extends neon support when hwcap is not available
a6c474ddee zstd: disable legacy support

git-subtree-dir: thirdparty/libchdr
git-subtree-split: aaca599e18e43933fc193bd1b715c368c306208b
2024-10-05 12:31:42 +01:00
Luke Usher c6a838d6ee Merge commit '349f1d281c29a3af9f2814399028e0e7bc829c96' 2024-10-05 12:31:38 +01:00
Luke Usher 349f1d281c Squashed 'thirdparty/sljit/' changes from c2e49625e4..f6326087b3
f6326087b3 Improve op flags operation on x86
2a79c59737 Fix sign conversion warning on Windows arm64 (#270)
7a6ceb3e03 Fix examples (#269)
2c105e2461 Fixed a compare logical case on s390x
4c4802dd4c Emit brk #0xf000 for breakpoint opcode on arm64 (#267)
3b9c0c8925 Enable public usage of SLJIT_LOCALS_OFFSET (#264)
4dd388a736 loongarch: add memory fence & support tmp register for atomic (#263)
8c089bd584 Implement m,emory fence
d21a5448f6 Fix compiler warning
f9f512c080 Support tmp register for atomic
883118537c Add action (#259)
8099661b54 Add SLJIT_ATOMIC_USE_LS/CAS support to LoongArch (#261)
728db2007a riscv: only enable SIMD if supported by toolchain (#260)
8727735933 Bitmanipulation instructions on RISC-V (#258)
c85dd1dd97 Rework sljit_emit_enter argument passing
3e5568bfcc Add more tmp reg tests
bd056ab1df Add control flags to atomic operations
ee8861243f loongarch: Implement ll/sc support for atomic operations (#254)
d3a10d1986 x86: avoid SIGILL in CPUs with AVX but without AVX2 (#256)
460f02a1b8 x86: check for extended function availability before using (#255)
0a74f16bea x86: improve execute_cpuid() portability (#251)
7b0fd86bd5 test: avoid leaking compiler on early exit (#253)
31cfa2fef2 Add shuffle support for LoongArch (#252)
06a5bafd7c Initial implementation of riscv simd
5ad2541117 x86: improve execute_get_xcr0_low() portability (#250)
6128486813 Implement atomic store on ppc and mips
fcade55c27 Update atomic on s390x
8bcd711708 Rework atomic load/store
bd221f0e86 Support non-overlaping vector registers

git-subtree-dir: thirdparty/sljit
git-subtree-split: f6326087b3404efb07c6d3deed97b3c3b8098c0c
2024-10-05 12:31:38 +01:00
Cheesemeister3k cac4aab301 #1485 [SNES] NTT Data Keypad (#1660)
Test equipment used: NTT Data Keypad, Raphnet ADAP-2XSNES-USB_V2 and
test32.sfc, Analogue Super Nt.
2024-10-05 12:25:28 +01:00
Factor 5911338cac Add support for 256KB of SRAM for SNES (#1616)
256KB of SRAM is possible on hardware and many hacks use it (Super
Metroid Practice ROM, Super Mario Bros. Maker, etc.). It could be
implemented in Ares in many ways, but I limited the ramSize to 1-8 with
a wrap-around as values higher than 8 wrap-around when used (9 is the
same as 1, 10 is the same as 2, etc. verified by
[kandowontu](https://github.com/kandowontu)).
2024-10-05 12:25:16 +01:00
png183 c0af33d4ce gba: improve SIO register handling (#1662)
Implements the following changes:

- Bits 8-11 of SIOCNT should be read/write
- Mode specified by SIOCNT uses 2 bits rather than 1
- Lower 3 bits of JOYCNT are cleared when 1's are written
2024-10-05 12:22:31 +01:00
hackgrid ea77623238 desktop-ui: enable loading rom folders from the cmd line (#1656)
Needs to merge #1654 first.

Enables loading folders instead files from cmd line.
Removes loading firmware files from rom folders in sfc mia (firmware
data would be loaded twice, db hashes would not match anymore).
2024-10-01 16:10:54 +01:00
png183 033752679f gba: add 2-cycle IRQ synchronizer and improve halted CPU timings (#1651)
Adds a 2-cycle synchronizer delay to IRQs. Unhalting the CPU also
appears to be delayed by 2 cycles.

The GBA CPU core currently steps in increments of 16 cycles when halted
or stopped to reduce emulation overhead. Since this optimization can
cause unhalt timings to be off by a few cycles, this PR reduces the step
size for halt mode and removes the optimization for stop mode.
Performance impact should be minimal in cases where performance is a
concern.
2024-09-26 14:23:54 +01:00
jcm 025fc6450a hiro/cocoa: Add bounds checking for table view context menus (#1650)
Right-clicking in a table view beyond the bounds of the defined rows in
the table would crash previously.
2024-09-25 09:57:13 +01:00
jcm d6858ad821 ruby/metal: Emit librashader shader creation errors (#1647)
Displaying errors from librashader shader loads in Metal will make
librashader debugging easier.
2024-09-18 18:34:10 +01:00
png183 0b46609e95 gba: add latches to DISPCNT background enable, object enable, and force blank bits (#1643)
Clearing the force blank bit or setting the background/object enable
bits in DISPCNT should only take effect after 3 scanlines.
2024-09-17 14:32:18 +01:00
jcm b5a8edc5d0 Address possible use of uninitialized variables (#1646)
Minor code cleanup. clang reports that it's possible under some
circumstances these variables are uninitialized when used.

Overall motivation is to utilize some stricter compiler settings in the
future and error on `-Wuninitialized`.
2024-09-17 14:32:07 +01:00
invertego 757a7dd670 Merge commit '950573df14f9307b7eaff4600370d76057aae466' into update_parallel_rdp 2024-09-15 05:27:45 -07:00
invertego 950573df14 Squashed 'ares/n64/vulkan/parallel-rdp/' changes from 7e5ad30b8..d1cc912c5
d1cc912c5 Update to 1f69c762be68feb9fcd5276d75acc6e5a6160a19
1a8cbce2f Update to fe5becd13638873db90d46e7ba7d48255971f82a
353ab9d38 Update to a2b0e8503ba525d70c61bccbe59c87d14daf89a6

git-subtree-dir: ares/n64/vulkan/parallel-rdp
git-subtree-split: d1cc912c5c47abaf9b6b155d3cd15255df65cf5b
2024-09-15 05:27:26 -07:00
Giovanni Bajo f43da416fd n64: refactor devirtualize and memory ops, force JIT only with instruction cache (#1635)
This change contains a large refactoring with no functional changes,
plus a small functional change that will help speeding up the JIT.

The refactoring allows CPU::devirtualize to return all the information
regarding the memory access. This in turn allows to simplify all memory
ops (which contained lots of duplicated code) to use devirtualize,
reducing code duplication.

The functional change is that we now use JIT only when running code from
icache (which is 99.9999% of the times). Running code without icache is
extremely slow on real hardware and only happens in specific situations
(eg: during boot when RDRAM is not initialized). By limiting the JIT to
run from icache, we open the door to implement proper icache support in
the JIT and finish remove the instruction epilogue with its slow
"instruction cache stepper" (which in addition to being slow, is also
inaccurate and make us fail cache test ROMs).
2024-09-08 13:45:09 +01:00
18f45ddc85 n64: add support for multi-byte writes to gdb (#1620)
Currently, gdb hooks in n64 doesn't allow for large sizes of writes
because it wouldn't be obvious which data size use on the bus. While
this is true, it doesn't really matter for RDRAM where all data sizes
work in the obvious, correct way. So relax the constraint to allow
writing large portions of RDRAM with a single gdb command.

Co-authored-by: Chase Meadors <[email protected]>
Co-authored-by: Luke Usher <[email protected]>
2024-09-03 09:49:40 +01:00
Giovanni Bajo 7135646c44 Update parallelRDP and MoltenVK (#1634) 2024-09-03 09:49:25 +01:00
invertegoandGiovanni Bajo 4ab8472a53 n64: fix instruction tracing with recompiler (#1629)
Co-authored-by: Giovanni Bajo <[email protected]>
2024-09-02 14:08:56 +01:00
Screwtapello a47e793b57 Stage resources into the output directory on Linux. (#1627)
Originally, to run ares on Linux after building it, you'd `make install`
which copied everything into the right places in your home directory.
Windows and macOS don't have the same traditions about installing apps,
so on those platforms the makefile staged a "portable" installation in
the output directory.

Since then, `make install` was modified to install ares system-wide.
It's possible to use it to install ares into your home directory, but a
bit overkill. For consistency, let's also stage a "portable"
installation in the output directory on Linux and the BSDs, so it's
easier to test on those platforms.
2024-09-02 11:36:41 +01:00
invertego 1ffb4f6d5a n64: use devirtualize for code block lookup (#1630)
Essentially a revert of fbaf7d8118

This optimization was found to compromise correctness due to the lack of
alignment checks. If something like this proves truly beneficial for
performance, we can bring it back.
2024-09-02 11:35:45 +01:00
remutro aa350116d4 Add option to enable TMSS boot rom for Mega Drive (#1632)
If you like to slow down booting into your game and want to read the
same old text each time on the Mega Drive, the option is yours now! This
is available as a choice in Settings > Options now. By default, this
will not be enabled (same behavior as existed prior to this PR). You
don't need to specify anything in the firmware section, ares had the
plumbing in place all along, it was just hardcoded to not load the tmss
boot rom.
2024-09-02 11:35:07 +01:00
png183 e8a5579cb7 gba: latch IE and IF values for 1 cycle, and improve stop mode emulation (#1631)
Improved interrupt timings, and made sure stop mode exits only once the
requested keypad input is registered.
2024-09-01 09:00:28 +01:00
Screwtapello f091fcfacd Fix detection of the Sufami Turbo base cartridge. (#1628)
The Sufami Turbo base cartridge is listed in the Super Famicom verified
dump database, so it did not use the heuristics. It turns out the
heuristic detection wouldn't have worked anyway - although the game's
header does contain the serial A9PJ, the heuristic revision() method
does not report that serial at all.

Meanwhile, the serial A9PJ is *also* used by the game Bishoujo Senshi
Sailor Moon SuperS - Fuwafuwa Panic, so loading this game would prompt
for Sufami Turbo mini-cartridges even though the game could not make use
of them.

I have used mia to generated heuristic manifests for every SNES/SFC game
in the No-Intro set, and the only difference introduced by this change
is that the Sufami Turbo base cartridge is now detected as having Sufami
Turbo slots, and Fuwafuwa Panic is not.

It took me a little messing around to find a syntax for comparing an
`array_view<u8>` that the compiler would accept; if there's some more
concise or idiomatic way to do it, please let me know.

Of the other emulators I surveyed, bsnes works just like ares did,
MesenS doesn't seem to support the Sufami Turbo, and snes9x uses a
slightly stricter check than I implemented:


https://github.com/snes9xgit/snes9x/blob/85591435763dede7ef111aab8070cdf2d5a7da49/memmap.cpp#L1016-L1023
2024-08-29 12:22:43 +01:00
Luke Usher fa9d350a66 md: sync more regularly when emulating 32X
Fixes a hang in Knuckles Chaotix at the cost of performance.

Needs further investigation.
2024-08-28 16:16:41 +01:00
Luke Usher 5ff5df0e2e version 140 2024-08-27 17:37:58 +01:00
png183 efb7f61f04 gba: add graphics viewer support (#1626)
Adds GBA support to the ares graphics viewer. Supports viewing VRAM
contents as Mode 3/4/5 bitmaps, or as 4bpp/8bpp tiles.
2024-08-25 10:06:06 +01:00
remutro 3cd82c8cfe Correct misspelling of interpreter (#1625)
Interpreter was spelled incorrectly in the option name, and the setting
name stored in the settings.bml file.
2024-08-23 17:26:04 +01:00
jcm ace4115c86 build: Check for clang in diagnostic pragmas (#1624)
MSVC build logs are complaining [very
loudly](https://github.com/ares-emulator/ares/actions/runs/10524248801/job/29160592080#step:10:835)
about unknown pragmas.

Only clang complains about these code areas currently, so for now, just
put these diagnostic pragmas behind a check for clang. If MSVC pragmas
end up being a good idea, could look into compiler-agnostic pragma
macros, but that doesn't seem necessary at present.
2024-08-23 15:58:48 +01:00
invertego 31ca4552ea build: fix cl build break (#1623) 2024-08-23 11:33:36 +01:00
invertego 873aded84b m32x, n64, ps1: add "force interpreter" option (#1622) 2024-08-23 11:03:39 +01:00
png183andinvertego 4dc46976ef build, n64: fix build (#1619)
Removed `__VA_ARGS__` from line 6 of interpreter.cpp, since it appears
to be unused and was causing compiler issues. Tested on Ubuntu with g++
and clang++ with both interpreter and recompiler running a default build
of n64-systemtest.

---------

Co-authored-by: invertego <[email protected]>
2024-08-23 00:23:07 -07:00
jcm 156603ceff hiro: Remove last clipsToBounds use (#1618)
Amends https://github.com/ares-emulator/ares/pull/1610
2024-08-22 14:02:57 +01:00
invertegoandGiovanni Bajo 12f0d04709 n64: remove branch state machine from epilogue (#1598)
This will bloat generated code in the short term, but some of that can
be elided with future optimizations.

Passes [n64-systemtest](https://github.com/lemmy-64/n64-systemtest) with
both the interpreter and recompiler.

---------

Co-authored-by: Giovanni Bajo <[email protected]>
2024-08-22 08:25:04 +01:00
jcm 693447d0e0 hiro/cocoa: Always draw in view bounds instead of dirtyRect (#1610)
A better fix for the problem discussed in
https://github.com/ares-emulator/ares/pull/1412.

Also unbreaks CI.

Changing `clipsToBounds` was fine, but the property isn't exposed on
older SDKs (that are still used by ares to maintain backwards
compatibility), and exposing it manually when building with an older SDK
was not great practice (and may have just been a noop anyway).

Instead, we should just not draw on the dirtyRect, when we intend to
draw on the view's `bounds`. Apple's documentation on this subject is
pretty thin on the ground, not to mention contradictory, especially
pre-macOS 14. But it seems pretty clear that in any case, a view's
`bounds` will always be the area we intend to draw on, while the view's
`dirtyRect` may or may not be. So here we make every element in hiro's
Cocoa implementation that does manual drawing always draw using
`bounds`.
2024-08-22 08:24:41 +01:00
png183 27719b391b gba: use separate latches per DMA channel (#1617)
Each DMA channel should have its own latch rather than sharing a latched
value. It's also possible to read open bus values into the latches.
2024-08-22 08:24:03 +01:00
png183 3455da48df gba: reload timer value after tick (#1614)
If a timer gets enabled while its value is 0xffff, it's possible for the
timer to overflow before its reload value is applied. Passes alyosha's
[timer-disable.gba](https://github.com/alyosha-tas/gba-tests/blob/master/timer/timer_disable.gba)
test ROM.
2024-08-21 09:13:15 +01:00
jcm dac6a2069f nall/arithmetic: ignore -Winfinite-recursion warning in square() (#1605)
More code cleanup for the new build system along with
https://github.com/ares-emulator/ares/pull/1602,
https://github.com/ares-emulator/ares/pull/1603, and
https://github.com/ares-emulator/ares/pull/1604.

This one is fairly mysterious. clang thinks that all paths through this
particular signature of the `square()` function call itself. This area
of nall is a mass of templating and operator overloads, and figuring out
exactly what's going on here would be a good one to unravel for a
large-brained, C++-enjoying individual.

For now, just ignore this warning locally so that we can compile the
rest of ares while still warning about infinite recursion elsewhere.
2024-08-18 04:12:51 +01:00
jcm 39174a2a79 Enforce newlines at end-of-file (#1604)
Enforce newlines at end-of-file in the codebase.

While every modern compiler is able to deal with not having EOF
newlines, it is still a good idea to enforce this.

ParaLLEl-RDP has a few files without EOF newlines, so I surrounded the
n64 Vulkan `include` with a diagnostic pragma to ignore it. This avoids
having to deal with compiler errors if ParaLLEl-RDP is updated, pending
newlines added upstream.
2024-08-18 04:12:18 +01:00
jcm 23e322fd57 hiro/cocoa: Fixes and code cleanup (#1603)
Fixes several issues and compiler warnings with hiro's Cocoa
implementation. Among them:

* We were technically declaring `clipsToBounds` incorrectly; properties
in subclasses aren't correct and can conflict with the system version;
rather, implement it as an instance method.
* Fix some non-strict pointer aliasing in menu-separator.cpp;
* Remove a couple blatant unused variables from desktop.cpp and
monitor.cpp;
* Fix an instance passing nil to a function that requires a non-null
argument in popup-menu.cpp;
* Some ancient C functions in Cocoa don't pass -Wwritable-strings; for
now, just surround the function that uses them with a clang diagnostic
pragma.

In C++ land:
* Various C++ functions were `override`s but were not declared as such.

Lastly, the second commit:
* In Objective-C, you declare subclasses in the `@interface` header, but
not in the implementation. hiro was including the superclasses in the
`@implementation` block, which isn't correct. For some reason, clang was
only erroring on one instance of this, but we go ahead and fix it
everywhere.
2024-08-18 04:12:01 +01:00
Adrian Siekierka 5c0c1fb4aa ws: implement cartridge SRAM open bus, clean up I/O port logic (#1607)
Also saves about 500KB of unnecessary memory use. Ouch!

I/O port open bus is not fully implemented.
2024-08-18 04:11:25 +01:00
png183 c27a62b624 gba: fix controls when screen is rotated (#1609)
Fixes a bug where D-pad controls were inverted when the screen is
rotated 90 or 270 degrees.
2024-08-18 04:10:06 +01:00
jcm 9c93735045 ruby: Remove unused OpenGL functions (#1602)
Removes apparently dead, unused functions in the OpenGL backend.

### Context

Work continues on the new build system. Among its goals are to start
compiling ares with stricter settings, where applicable, to increase
code quality. This includes removing unused functions, to satisfy
`-Wunused-function`.
2024-08-16 16:28:42 +01:00
Stefan Schlosser 9e03af99d9 nall: accept target-triples below i686 for x86 architecture (#1600)
Some systems report target-triples below i686, although they target i686
in reality. One such system is FreeBSD since version 13.0. It reports
i386 but targets i686. Without accepting target-triples below i686 such
systems can't compile ares on the x86 architecture.
2024-08-16 16:28:31 +01:00
png183 eec5104909 gba: prevent DMAs from interrupting ROM accesses (#1601)
Fixes some timing issues where DMAs were running 1 cycle too early
2024-08-16 10:09:09 +01:00
Luke Usher 00a67f1671 ps1: fix crash when display surface wraps around the framebuffer 2024-08-15 16:24:30 +01:00
png183 a76847dbd6 gba: prefetcher should halt only once DMA accesses ROM (#1597)
Currently, the prefetcher halts whenever DMAs are running. However, on
hardware the prefetcher is able to keep running until DMA accesses
cartridge ROM. This PR implements said behaviour, allowing ares to fully
pass the mGBA test suite timing tests as shown below:

![2020](https://github.com/user-attachments/assets/bbf8fd3b-c1a1-45f8-b623-8b0bc8d7784d)
2024-08-09 18:39:54 +01:00
remutro f209d544b0 Add missing serialized fields to N64 save state (#1573)
Added missing serialized fields to N64 save state, one in AI and one in
PI (both added in same commit).

Scanned the other sections looking for other missing fields so we don't
need to invalidate save states frequently and I didn't spot others that
were missing right now.
2024-08-09 14:43:43 +01:00
invertego 5453fe084a n64: (rsp/recompiler) clear r0 only when necessary (#1581) 2024-08-09 14:43:31 +01:00
曾耿森 426fb79639 feat(fc): add new new input device zapper for fc (#1592) 2024-08-09 14:43:21 +01:00
png183 33c645a441 gba: improve DMA timings (#1596)
The 2 DMA idle cycles currently processed before running a DMA channel
should instead run for 1 cycle when DMAs start, and 1 cycle when the
DMAs have all finished.
2024-08-09 14:35:01 +01:00
Luke Usher ba9a291784 ruby: fix compilation of OSS driver on Linux systems
Most (all?) linux implementations lack AFMT_S24_LE and AFMT_S32_LE
2024-08-08 13:35:53 +01:00
Stefan Schlosser 9fb67ba7a7 ruby: improve OSS audio backend (#1593)
The OSS audio backend was very limited in its capabilities and its error
handling. Essentially it supported only the initial parameters for
channels, format and frequency, e.g. 48000Hz 16bit stereo. If the audio
device didn't support these parameters, the backend would keep using the
initial values although OSS had probably adjusted the parameters to
supported values. Be aware, there are possible configurations for the
system and the audio devices which don't support the above mentioned
standard values, e.g. on FreeBSD it's possible to configure an audio
device to only accept 96000Hz 32bit 7.1 surround sound.

Now the OSS backend takes the changed parameters for channels, format
and frequency into account, updates the resampler accordingly and feeds
the audio data into the audio device with the right format.
2024-08-07 10:12:08 +01:00
invertego 54794f86d9 thirdparty: fix typos in lzma object names (#1594) 2024-08-07 10:11:35 +01:00
Adrian Siekierka 7f43d0658e v30mz: fix IP on interrupt fired when prefixes being used with non-pr… (#1591)
…efix instructions

Once again, found with a test (`80186_interrupts` in my ws-test-suite).
2024-08-04 14:05:27 +01:00
Adrian Siekierka 0d24374019 v30mz: fix instruction prefix handling (#1590)
It appears the datasheet was not entirely conclusive with regard to how
the CPU handles chains of more than 7 consecutive instruction prefixes;
in addition, Ares was incorrectly using the *first* rather than *last*
segment override in the chain.

This doesn't affect well-formed code (duplicate instruction prefixes
should never happen, nor should more than one segment override), but
brings Ares up from 2/7 to 7/7 in
[ws-test-suite](https://github.com/asiekierka/ws-test-suite)'s new
`mono/cpu/prefixes` test.
2024-08-04 13:45:54 +01:00
Adrian Siekierka 78a5e584b5 v30mz: fix DAS overflow flag emulation (#1589)
oops, typo
2024-08-03 12:38:09 +01:00
Stefan Schlosser ffe97222a1 hiro: remove QT5 deprecation warnings (#1586)
Replace deprecated elements with suggested replacements.

QApplication::hasPendingEvents() and QWidget::paintEngine() are still in
use, their replacement is way out of scope for this PR.
2024-08-01 11:21:54 +01:00
Stefan Schlosser 71e5f89f8b desktop-ui: increase height of SettingsWindow to unhide Supersampling option in QT5 builds (#1587)
The Superampling option in the Video category isn't visible in QT5
builds, the settings window is too small. Therefore increase the height
of the window by 20 to unhide the setting. This also gives the setting a
little bit more distance to the bottom edge in GTK3 builds.
2024-08-01 11:21:42 +01:00
png183 cac454a6a9 gba: reset prefetch buffer on ROM accesses from DMA (#1584)
Addresses todo item from #1377
2024-07-31 14:45:56 +01:00
invertego 6c8265577c n64: update audio stream frequency after loading state (#1583) 2024-07-30 11:16:19 +01:00
tykkiman 401aab6d64 n64: clear r0 only when it was written to (#1580)
Currently a per-instruction epilogue is needed to make sure the
read-only register r0 stays as the value 0. To improve performance of
the generated code, we'd like to move this operation to be done only
when needed.

This commit solves the above problem in two ways: simple instructions
are never emitted if their destination register is r0, and more complex
instructions now emit a clear operation right after. This way exceptions
are still thrown when needed.
2024-07-29 18:06:01 +01:00
png183 c0fb9ba815 arm7tdmi: improve ldm/stm edge case handling (#1582)
Address some edge cases of LDM/STM instructions (also affects Thumb mode
PUSH/POP):
- Using an empty register list will cause R15 to still be accessed, but
the base register will be modified as if all 16 registers were accessed
- Writeback does not occur in LDM if the base register is in the
register list
2024-07-28 15:18:09 +01:00
bachimus 356208f312 ps1: Fix Dragon Ball GT Final Bout (fix found by @LukeUsher) (#1579) 2024-07-26 11:20:34 +01:00
png183 fbf10d14fc arm7tdmi: fix reading SPSR in user and system modes (#1578)
In user and system modes, attempting to read SPSR should instead read
CPSR.
2024-07-26 11:18:40 +01:00
Stefan Schlosser 723d8a8cd4 nall: respect prefix for sharedData location on Linux/BSD (#1575)
The hardcoded `/usr/share` for the sharedData location doesn't respect
the given prefix, e.g. `~/.local` or `/usr/local`. This results in the
emulator not finding the shaders or databases in case the emulator is
not installed under `/usr` and the files are not found in the
application or user data directory.

Now the build script defines a preprocessor constant `ARES_PREFIX` which
is set to the requested prefix. With the help of the C preprocessor
stringize operator, this prefix is then used as the root of the
sharedData location.

Fixes https://github.com/ares-emulator/ares/issues/1179
2024-07-24 12:59:49 +01:00
Stefan Schlosser 6eedb9399b Improve FreeBSD compatibility (#1574)
These commits improve the compatibility with FreeBSD. Among some
cosmetic changes is a commit to unbreak the build on FreeBSD and two
commits adding an audio and an input backend to FreeBSD builds.

There's still a change needed to make ares completely buildable on
FreeBSD:
use of `CLOCK_MONOTONIC` in
`ares/n64/vulkan/parallel-rdp/util/timer.cpp`, see
https://github.com/Themaister/Granite/pull/135. This change will
propagate to ares if/when Granite upstream merges the PR, parallel-rdp
adopts the updated Granite and ares updates its parallel-rdp.
2024-07-24 12:58:20 +01:00
invertego 36f821f5ac ci: set windows image to windows-latest (#1563)
This reverts commit 762a2302f7.
2024-07-15 04:16:20 +01:00
png183 3bbfde5e9b arm7tdmi, gba: prevent debugger from advancing GBA CPU clock (#1564)
Provides a getDebugger function for the ARM debugger to read memory
without advancing CPU state, fixing a bug where GBA core CPU timings
were impacted by debugger use.
2024-07-15 04:15:07 +01:00
invertego b8e355b218 build: detect cl target architecture (#1562)
Automatically detect the (clang-)cl target architecture instead of
assuming amd64. Note that -print-target-triple is now used in favor of
-dumpmachine for all versions of clang. This option has been around for
ages in the regular clang driver but is only supported by clang-cl as of
LLVM 18, which isn't yet available via the Visual Studio installer but
is available through a standalone installer on GitHub.

This commit also adds a compiler flag to the command line when targeting
arm64 with cl to work around an optimizer bug.
2024-07-10 11:45:06 +01:00
jcmandjcm c34ed82fa3 build: Allow building on Make 3.81 (#1556)
On versions of make prior to 3.82, pattern matching rules are applied in
the order they were first defined, as opposed to the probably-desired
order of most specific to least specific. In ares, `nall`'s pattern
matching rule comes fairly early on and is thus used to build most of
ares. The parallel-rdp build code in ares defines its own pattern
matching rule, which caused building with 3.81 to not work since the
more specific rule is not used, and the less specific rule cannot be
applied successfully.

For other fun reasons, macOS still ships with make 3.81 (released in
2006).

This PR just allows building on macOS's stock `make`, which means a bit
less effort in building, as well as easier integration with IDEs (in my
testing so far, what few IDEs on macOS support direct Make integration,
seem to require or expect the stock toolchain).

There may be slightly more elegant ways to do this, but this pattern
conforms with how object paths are defined for other third party
dependencies around ares.

Eventually™, if ares migrates to CMake, there could much better cross
platform build tool integration (generating Xcode or other OS project
files as desired, for example). Until that point, it is convenient to
support the stock toolchain on all operating systems if possible.

Co-authored-by: jcm <[email protected]>
2024-07-08 10:08:28 +01:00
invertego 3de728fa3b fc: add prg ram to uxrom and cnrom mappers (#1557)
Some homebrew/aftermarket software calls for UXROM w/ PRG (NV)RAM. The
licensed title Hayauchi Super Igo pairs CNROM with SRAM.
2024-07-08 10:08:21 +01:00
invertego 2b0738ec56 fc: implement sachen-0037/tengen-800008 mapper (#1558)
Fixes #1031
2024-07-08 10:07:55 +01:00
invertego 79e25f30bf fc: implement tengen rambo-1 mappers (#1555)
Fixes #1308 and #1311
2024-07-07 12:01:00 +01:00
invertego 5bf09dac13 fc: implement camerica/codemasters mappers (#1554)
Fixes #1312
2024-07-07 12:00:34 +01:00
invertego b4fafd9028 fc, ng, sg: add missing cart ram serialization (#1552)
Add missing serialization for the following boards.

fc
- HVC-NROM
- SUNSOFT-1
- SUNSOFT-2
- SUNSOFT-3

ng
- cmc50_jockeygp

sg
- Taiwan-A
- Taiwan-B
2024-07-05 23:47:23 +01:00
jcmandjcm 21f730968b ruby: Use cleaner OpenGL render pattern, misc. CGL fixes (#1543)
### OpenGL rendering (all platforms)

- librashader specifies that the output viewport should be the same size
as the output framebuffer texture. This was not the case for the OpenGL
render code.
* Previously, librashader under OpenGL would render onto an intermediate
framebuffer sized to the "output" size (the entire window view size),
rather than the "target" size (the final composited size of the game
area within the output area). The `libra_viewport_t` would be sized to
the target size, but the underlying buffer would be larger.
* Now, we size the intermediate framebuffer to the "target" size, let
librashader render onto it with a `libra_viewport_t` that matches that
size. In the final pass we sample this buffer within an area of the
"output"-sized buffer as appropriate.

This prior behavior would lead to scaling issues with shaders in the
Metal backend. The same issues did not seem to be obviously present in
OpenGL in my testing, but we should nevertheless probably fix this in
case it is causing any of the subtle issues with shaders that have been
reported, and also in case something breaks in the future as a result of
not following this recommendation.

(The above is also unrelated to the scaling issues addressed by
https://github.com/ares-emulator/ares/pull/1508)

### CGL fix-ups (macOS)

- Backports the native fullscreen and monitor selection options to
OpenGL, and removes unnecessary custom window code from the OpenGL
driver.
- Removes a seemingly unnecessary output call from `reshape` that would
cause flickering during resizes.

This has been tested on macOS but should probably be tested on other
platforms as well to make sure nothing breaks.

Co-authored-by: jcm <[email protected]>
2024-06-21 11:02:59 +01:00
Dragorn421 6cd4470562 Enforce the "C" locale for LC_NUMERIC (fix #1526) (#1542)
Fixes #1526

The default locale in a C program is the "C" locale ( POSIX
https://pubs.opengroup.org/onlinepubs/9699919799/functions/setlocale.html
, C89 standard ), which we want for string-number formatting and parsing

gtk (
https://gitlab.gnome.org/GNOME/gtk/-/blob/a274a5ff4b2a2f9cf9731cdddbb456a0758fcbcc/gtk/gtkmain.c#L435
) and Qt ( 5
https://codebrowser.dev/qt5/qtbase/src/corelib/kernel/qcoreapplication.cpp.html#597
, 6
https://codebrowser.dev/qt6/qtbase/src/corelib/kernel/qcoreapplication.cpp.html#613
) set the locale from the environment variables instead. (by passing ""
as the locale, cf `setlocale`)

This PR sets the locale for `LC_NUMERIC` back to "C" with `setlocale`
after initializing gtk/Qt

I tested this with gtk, saw no problem in the GUI with a rom named
`/home/dragorn421/Desktop/c'est la fête/rom de noël __ やあ!.z64`

Qt codepath is not tested
2024-06-21 10:49:27 +01:00
Luke Usher 393ba03358 pce: prefer Arcade Card for Japan Region
The Arcade Card was always supported, but it was non-obvious that it could be selected; and System Card 3.0 was autodetected, so let's fix that.
2024-06-20 19:10:44 +01:00
Luke Usher 9159438401 ares v139 2024-06-19 17:15:03 +01:00
Luke Usher 3372230021 nall: set numeric locale to "C" at startup 2024-06-19 17:11:58 +01:00
remutro 8c4af6ac4c Add hash to manifest for remaining cartridge based systems (#1536)
This originally added the N64, but after inspecting remaining
cartridge/card/fixed ROM based systems I have also added the additional
four so that hash is available in manifest. This should complete adding
this info for these types of consoles.

N64
Gameboy Advance
MyVision
SG-1000
Sufami-Turbo
2024-06-17 19:38:31 +01:00
Luke Usher b5ee4124e1 nall: enforce "C" locale for toReal/fromReal 2024-06-16 09:40:32 +01:00
remutro 4dbd6fad37 Accept unh extension for unheadered NES roms (#1535)
No-Intro uses the unh extension for un-headered NES roms. Accept this as
a valid extension for the famicom core.
2024-06-16 08:15:44 +01:00
曾耿森 a876f4479d fix(mia): fix all mc-acc game type (#1532) 2024-06-15 22:02:00 +01:00
remutro afa3f08f8c Add sha256 hash to manifest for 2600 and CV (#1533)
Testing some games on Coleco Vision & Atari 2600 and noticed that the
SHA256 ROM hash was missing from the manifest for these two, which I
have now added.
2024-06-15 22:01:47 +01:00
曾耿森 371d6eeaa8 fix(mc-acc): fix mc-acc irq timing (#1531) 2024-06-15 22:01:27 +01:00
Luke Usher e1a940cafa Squashed 'thirdparty/slang-shaders/' changes from 1265cf159..693c632bd
693c632bd Add ray traced curvature shader (#604)
e5b20b142 add licences (#603)
573b339c9 add safe-120 BFI shaders and update motion interpolation for 120 FPS (#599)
ecdbd7b27 Merge pull request #602 from Hyllian/master
44de01372 Add mixed-res preset hooks

git-subtree-dir: thirdparty/slang-shaders
git-subtree-split: 693c632bddc9f8b7aad43d215c487ccc97b5129e
2024-06-15 21:58:58 +01:00
Luke Usher 7c4a36a482 Merge commit 'e1a940cafafc70d06804eb02794fcc06610f68a0' 2024-06-15 21:58:58 +01:00
Luke Usher bea295a915 Squashed 'thirdparty/librashader/' changes from d7665cac9..fff80df5a
fff80df5a ci: temporarily remove deny-deprecated on ctypes to unblock ares
875968d09 dep: update spirv_cross
fa48b936b rt: cap texture scaling to [1, 16384]
0a9fa1685 rt: update for new TAIT scope rules
d558c6e50 dep: update image dependency
48d91dfe5 dep: update image dependency

git-subtree-dir: thirdparty/librashader
git-subtree-split: fff80df5a024346d9409089e8965e323c6ab6698
2024-06-15 21:58:38 +01:00
Luke Usher db1d29ebcf Merge commit 'bea295a915cf9deec71a8ae60b05342a2e63adac' 2024-06-15 21:58:38 +01:00
Luke Usher 54845f6194 Merge commit '7c7d2c2155a4a018794345442b4b4ae6dc3d9449' 2024-06-15 21:58:34 +01:00
Luke Usher 7c7d2c2155 Squashed 'thirdparty/libchdr/' changes from 07a564abe..aa34b1419
aa34b1419 Merge pull request #126 from rtissera/stdint-types
5a39b158a Use standard types from stdint.h / cstdint
84ddc0293 Merge pull request #125 from irixxxx/master
e62ac5995 fix (U)INT types
0b5a86fe0 fix 7ztypes

git-subtree-dir: thirdparty/libchdr
git-subtree-split: aa34b14191f66797b1a64da6539a8d8004497fab
2024-06-15 21:58:33 +01:00
Luke Usher edb88e2e3a Squashed 'thirdparty/sljit/' changes from 1e0579727..c2e49625e
c2e49625e Fix incorrect argument order in x86 sljit_emit_simd_lane_mov
68bb7c7cc Support shuffle on s390x
b3f492960 Support simd shuffle operation

git-subtree-dir: thirdparty/sljit
git-subtree-split: c2e49625e4be2f1e62263044527fe83cce88d2f2
2024-06-15 21:58:25 +01:00
Luke Usher ac75269342 Merge commit 'edb88e2e3ad9bc2e3906af460c427a3b278332fa' 2024-06-15 21:58:25 +01:00
Luke Usher bfc9636403 Squashed 'ares/n64/vulkan/parallel-rdp/' changes from e8a425fab..7e5ad30b8
7e5ad30b8 Update to 43bc31642cc70d04adb828a285e68cdbde7110a9.
0f5d4b328 Update to 2549779edc659cd7f732b1e7fe6e6608ceea487d.

git-subtree-dir: ares/n64/vulkan/parallel-rdp
git-subtree-split: 7e5ad30b8c6e5b863c117997c459441649da9bc7
2024-06-15 21:58:17 +01:00
Luke Usher c6ca36e447 Merge commit 'bfc9636403036d59481741bae3d77d6209aee554' 2024-06-15 21:58:17 +01:00
曾耿森 4e97f23446 feat(fc): add board support TXC-22211A/C(132/173) (#1530)
add TXC-22211A
  add TXC-22211C
  fix TXC-22211B mirror
  pass issue #755 
  pass issue #756
2024-06-14 18:22:47 +01:00
Luke Usher d7dfae7a7a md: emit silence on PWM if uninitialized 2024-06-14 14:15:08 +01:00
Luke Usher 62f1512d44 md: determine 32x clock by 3x m68k clock
md: determine 32x clock by 3x m68k clock
2024-06-14 14:15:08 +01:00
Luke Usher e6481d975e md: determine PWM divisor from configured cycle rate 2024-06-14 14:15:08 +01:00
Luke Usher 61a94f025e md: 32x frequency differs PAL vs NTSC 2024-06-14 14:15:08 +01:00
曾耿森 d76e79076f fix(fc): fix mmc3 board (#1529)
1. fix game Mickey's Safari in Letterland (USA)
2. fix game Incredible Crash Dummies, The (USA)
2024-06-14 12:59:30 +01:00
曾耿森 a574410a03 feat(fc): add new board TXC-22211B(Mapper 172) (#1527)
pass issue #755
2024-06-13 20:09:55 +01:00
曾耿森 dc97c814a3 feat(fc): add new board support (225/255) (#1523)
pass issue #753
pass issue #754
2024-06-12 16:28:52 +01:00
曾耿森 9325b04b23 add board unl-bmc-31-in-1 (mapper 229) (#1521)
add board unl-bmc-31-in-1 (mapper 229)
pass issue #752
2024-06-11 17:23:33 +01:00
Luke Usher 762a2302f7 ci: set windows image to windows-2019
Attempting to workaround broken clang in windows-latest (2022)
2024-06-11 10:26:18 +01:00
曾耿森 2b6346df6e feat(fc): add new board support (#1520)
1. add the board unl-sachen-74ls374n support mapper id = 150 & mapper id
= 243
2. merge Famicom NTSCJ and NTSCU to NTSC
3. pass the issue #282
2024-06-11 09:47:17 +01:00
png183 587aa20dcc gba: improve video capture DMA (#1519)
Video capture DMAs should run only if the mode was enabled on scanline
162 of the previous frame, and should clear the DMA enable bit once
complete.
2024-06-10 08:26:22 +01:00
John Tur 4615a9f4b7 Fix cl build break (#1517)
Fix build break caused by #1515. Let's see what CI says...
2024-06-10 08:26:10 +01:00
曾耿森 fc7cdb57f7 Refactor fc ppu (#1518)
1. pass mmc3/3-a12_clocking.nes
2. refactor the ppu/var and ppu/scroll
3. fix ppu var and scroll read/write($2005/$2006/$2007)
4. inc serialization to v144
5. fix the color generator
6. fix the game Burai Fighter (USA)
7. pass issue #151
2024-06-08 18:29:51 +01:00
John Tur 0a8f25e7d8 Support default device in WASAPI driver (#1515)
The WASAPI sound driver now supports a "Default" audio output device:
<img
src="https://github.com/ares-emulator/ares/assets/27514983/fbf358d6-41e7-478d-8a76-fc86790d7774"
width="650" />

This uses the [Automatic Stream
Routing](https://learn.microsoft.com/en-us/windows/win32/coreaudio/automatic-stream-routing)
API that was introduced in Windows 10. A runtime check was added to
ensure that the feature does not appear on older versions of Windows.

I did some limited testing and found the feature to work without issues.

Closes https://github.com/ares-emulator/ares/issues/1514
2024-06-07 10:48:42 +01:00
Giovanni Bajo f3cdf203c3 n64: poll gdb more frequently (#1512)
Currently, gdb is polled once per frame, which seems enough for
interactive usage. Some ROM hacks would like to use the gdb interface to
provide additional emulation-only features such as online multiplayer,
but that requires a faster turnaround.

A quick solution is to poll gdb more frequently within the n64 core.
This patch does that once per screen line, approximately. Notice that
the poll is only scheduled and run if there is a gdb client connected so
it should not cause any performance impact on normal users.
2024-06-07 10:48:05 +01:00
Luke Usher 76615ce847 Squashed 'thirdparty/slang-shaders/' changes from 6cb93ce1b..1265cf159
1265cf159 Merge pull request #601 from Hyllian/master
d96718591 Add mixed-res-crt-hyllian preset
407a45729 Merge pull request #600 from Hyllian/master
8583cfee2 Update mixed-res shaders

git-subtree-dir: thirdparty/slang-shaders
git-subtree-split: 1265cf159d63253ab8978c7f9e63048e9d791e8c
2024-06-03 17:49:42 +01:00
Luke Usher 5e04d6d31b Merge commit '76615ce847483d1c158a06d513331325236819af' 2024-06-03 17:49:42 +01:00
Luke Usher 2d81319a2f Squashed 'thirdparty/sljit/' changes from a7066fdb1..1e0579727
1e0579727 Fix constant pool bug on arm32 (#249)

git-subtree-dir: thirdparty/sljit
git-subtree-split: 1e0579727f5805f0e34cca6b5e0c841dd92ebfb0
2024-06-03 17:49:25 +01:00
Luke Usher 4b3b8b9f5b Merge commit '2d81319a2f0115eec97620a389715eddde7c13fa' 2024-06-03 17:49:25 +01:00
Luke Usher 36df7ab00f Merge commit '47d6d256876d6cab7c16bd6e04c657b976339e51' 2024-06-03 17:49:04 +01:00
Luke Usher 47d6d25687 Squashed 'ares/n64/vulkan/parallel-rdp/' changes from ff3b858dd..e8a425fab
e8a425fab Update to ffc0d865836eb2f90c85e4694e4cfe363be908e6.
aba102d24 Update to e564cbc01a49d2d94d90e60cc5c2f406d9ac4aad.

git-subtree-dir: ares/n64/vulkan/parallel-rdp
git-subtree-split: e8a425fabc3a25d1855d5f217c6857e5e9bf1af2
2024-06-03 17:48:34 +01:00
jcmandjcm 117f4f7b4e UI: Initialize all video options correctly on driver settings update (#1513)
Just a small fix to account for the new video settings in Metal; the
threaded renderer, native fullscreen behavior and color space option.
These options were not fully persistent because the `videoDriverUpdate`
function (run on startup, among other times) did not account for them.
They would be set correctly in `settings.bml` and the settings object,
but would never actually be set correctly on the driver struct.

Co-authored-by: jcm <[email protected]>
2024-06-03 11:09:17 +01:00
Adrian Siekierka c23a3f736d ws, m93lcx6: improve EEPROM emulation accuracy (#1509)
* The behaviour of bits 0-3 and 7 in the control/status port were a
complete guess and had no reflection in hardware testing. They have been
adjusted to match hardware.
* The EEPROM interface always writes and reads out 16 bits to/from the
EEPROM, including the initial zeroes in the command value. The M93LCx6
code has been updated to support this case in line with the datasheet.
* The read and write data port have been separated. This was a detail
which every community documentation in existence got wrong, so no
worries about that one ^^
* Internal EEPROM protection has been implemented.
* The handling of invalid control commands (more than one bit set) has
been fixed.
* Emulation of the 93C46-family internal EEPROM on SPHINX in ASWAN mode
has been implemented. In particular, this fixes running any mono
WonderSwan game which takes advantage of the internal EEPROM on the
WonderSwan Color system's compatibility mode.

All of these changes pass the relevant tests in
[ws-test-suite](https://github.com/asiekierka/ws-test-suite)
(mono/eeprom/internal.ws) both as a WonderSwan and a WonderSwan Color.
This isn't 100% accurate (particularly, timing is not reflected; but
there are also some questions about more edge case-y behaviour), but
it's much closer.
2024-05-30 14:19:44 +01:00
jcmandjcm dd25ac4f72 n64: fix macOS build (#1507)
The paraLLEl-RDP build was broken on macOS because of a change from
February to Granite in regarding platform ifdefs for pthreads.

A PR that applies a fix has been opened
[upstream](https://github.com/Themaister/Granite/pull/131), but until an
upstream fix lands, this PR will unbreak the build for ares without
needing to roll back the recent paraLLEl-RDP update entirely.

Co-authored-by: jcm <[email protected]>
2024-05-28 15:02:15 +01:00
Luke Usher 804e6699a4 fix build after updating deps 2024-05-27 10:22:16 +01:00
Luke Usher c2dede6c85 Squashed 'thirdparty/slang-shaders/' changes from 1c0a4ccbd..6cb93ce1b
6cb93ce1b koko-aio hotfix4 (#597)
6e3cc4c11 Merge pull request #598 from keylimesoda/patch-1
36c6c7bf7 Update curvature.h
56d13de9b Sync to koko-aio 1.9.20-hotfix3 (#596)
9c930380c fixed undefined function in warp_koko() (#593)
8bdee83e3 Merge pull request #594 from Hyllian/master
37cce2aa7 Update mixed-res shaders.
ba6f00b5c Merge pull request #592 from HyperspaceMadness/master
e931b7a10 Mega Bezel V1.17.2_2024-05-18 Update of Mega Bezel with fixed paths and removed failing wildcard testers. Added an additional independent DREZ preset
7b4baaa11 Merge pull request #591 from Hyllian/master
ed50f0475 Add deblur-luma shaders
99d1bfe3b Merge pull request #590 from kokoko3k/master
0a741ee7a sync to koko-aio 1.9.20
8724e92bd Merge pull request #589 from Hyllian/master
879dcd27f Add bilateral-2p shaders
5fbd61058 Merge pull request #588 from Hyllian/master
d5a089f77 Add bilateral shader from guest.r
4968a5294 fix NSO-gbc-color.slang
7fc92d726 Merge pull request #587 from Hyllian/master
97c7ed71c Add crt-royale-downsample preset and LUTs
699402877 Merge pull request #586 from Hyllian/master
729ab1767 Update super-xbr and mixed-res shaders
3378d0160 Fishcu/pixel aa xform (#585)
f047ae72a Merge pull request #584 from Hyllian/master
096f95adc Update dilation shader
7aff4e6cc Merge pull request #583 from fishcu/fishcu/rename-includes-to-inc
31caee64d Rename files that are included but no proper shader on their own to .inc
0eb12c628 Fishcu/authentic gbc (#582)
67a1ee78e Merge pull request #581 from Hyllian/master
c562d89ec Update film-grain.slang
4de167851 Merge pull request #580 from Hyllian/master
96713a17f Add film-grain shader
e77c37fe5 Merge pull request #579 from kokoko3k/master
d49bab8d0 Add autocrop-koko shader
ca2c0223c Merge pull request #578 from Hyllian/master
71d3618ba Add crt-royale-smooth preset
2f8af209b Merge pull request #577 from Hyllian/master
40f5d882c Add n64 3-point and relief shaders
7984c9953 Merge pull request #576 from Hyllian/master
594d9a2fc Add lanczos2-5-taps
ee403bcdd Merge pull request #575 from Hyllian/master
e8287f250 Add mixed-res shaders
341aac7b7 Add 2xsal-level2-xbr shader and presets (#573)
9f2c20102 Merge pull request #572 from Hyllian/master
c342a69e3 Merge pull request #567 from mattakins/master
2e3f25c34 Add NEDI-Hybrid shaders
d7e15b9c0 Merge pull request #571 from fishcu/fishcu/minor-fixes
932d2a630 Merge pull request #570 from HyperspaceMadness/master
b5bf043b1 Change default param
5831505f0 Minor fixes found during GLSL porting of code
155e471ca Updated gameboy preset names based on feedback
b6b379281 Added drez and improved print-resolution
05414f65e Merge pull request #568 from Hyllian/master
0135078c3 Update NEDI shaders
2ac8ca7c1 Update ddt.slang
6bfb9df4d Added gameboy-advance preset
eab71b6be Added gameboy-pocket-high-contrast
69c282123 Added gameboy-color-white-bg preset for gameboy shader
f7cf08900 Restored gameboy shader Blending Mode default to 0
dd228b941 Merge pull request #566 from Hyllian/master
7b0a142a1 Add cheap-sharpen shader
2a7c19b6b Merge pull request #565 from Hyllian/master
68d982035 Add bicubic-5-taps and hermite shaders
93c954798 Merge pull request #564 from Hyllian/master
28fb09f79 Add b-spline-4-taps and catmull-rom-5-taps

git-subtree-dir: thirdparty/slang-shaders
git-subtree-split: 6cb93ce1be67b314a96f5e346befb2b58b63eb04
2024-05-27 10:05:10 +01:00
Luke Usher 6cabb5d118 Merge commit 'c2dede6c851c20e50398e724966394235221bb70' 2024-05-27 10:05:10 +01:00
Luke Usher 5c92d877c8 Squashed 'thirdparty/librashader/' changes from e8ffd8fdf3..d7665cac9b
d7665cac9b Update wgpu

git-subtree-dir: thirdparty/librashader
git-subtree-split: d7665cac9b7a9761290a1b76bd59d39205497326
2024-05-27 10:04:45 +01:00
Luke Usher 9db8decbd6 Merge commit '5c92d877c8850f0e37ca03405392530f2ba0a314' 2024-05-27 10:04:45 +01:00
Luke Usher 0ef0a3e3a7 Squashed 'thirdparty/libchdr/' changes from 5c598c2df3..07a564abe4
07a564abe4 Merge pull request #124 from rtissera/revert-libretro-changes
d1fe3009c8 Revert "Merge libretro stuff, bump to 0.3 version"
b5603a577b Merge pull request #123 from rtissera/merge-libretro-stuff
56b08d53f8 Merge libretro stuff, bump to 0.3 version
86b272076d Merge pull request #122 from scribam/zstd-disable-shared
a4fa03bba9 zstd: disable shared lib
67c96ef582 Merge pull request #121 from scribam/zstd-1.5.6
45c53ae969 deps: update zstd to version 1.5.6
f8f2f8bf77 Merge pull request #120 from scribam/bsd
d93a99ced9 cmake: remove "-Wl,--no-undefined" on OpenBSD
d670e6833c ci :add GitHub Actions for BSD
2d315cad12 Merge pull request #119 from scribam/lzma-24.05
715f33792f deps: lzma compatibility changes for switch and vita platforms
25543a5214 deps: bump LZMA SDK to 24.05 and build with asm optimizations
0841ba38ee Merge pull request #116 from notaz/missing_auxv
6c739c2f67 handle more platforms that lack getauxval/AT_HWCAP

git-subtree-dir: thirdparty/libchdr
git-subtree-split: 07a564abe462f1aece58c794a3c2a6fed688afea
2024-05-27 10:04:39 +01:00
Luke Usher dbb3b85bb3 Merge commit '0ef0a3e3a7eb717224d885b3d1e135076c360c89' 2024-05-27 10:04:39 +01:00
Luke Usher c94794e959 Squashed 'thirdparty/sljit/' changes from 5420f8bee8..a7066fdb10
a7066fdb10 Improve fop2 with single precision opcode on x86
daf33c9165 Fix TMP_REG2 usage fault in sljit_emit_simd_lane_mov for LoongArch (#248)
cb9b068274 Improve op_flags on s390x
d86e6cbf6c Implement LoongArch LSX and LASX SIMD Support (#247)
9017d72988 Allow forcing VEX prefix on x86
79256319d6 Add temporary register support to ijump
db3ca5014f msan fixup (#245)
ad89dd8ecd Fix locking region in sjlit_malloc_exec (#244)
bbeafb0ff4 Add temporary register support to select on LoongArch (#243)
5aeae2a2af Add temporary register support to select on s390x
56dbde07b0 Add xgetbv feature detection support on x86
d2374c2043 Add compare to temporary register tests
b67fc5c5eb Add temporary register support to select
14622914aa Split sljit_p to sljit_up/sp variants
42ac81c053 Fix LoongArch floating point select tests (#242)
36c6047c78 Add floating point select tests
eef5fceee3 Add simd lane mov temporary tests
c6ce9a3749 Add float conversion temporary tests
277093d3d0 Add simd temporary tests
9827eb7e00 Fix build on older macOS (#240)
19e2693245 Fix LoongArch binary temporary tests (#239)
af736af648 Add binary temporary tests on s390x
2ea42b1924 Add binary temporary tests
3d66db5ac4 Absolute jumps / fast calls should not modifiy SLJIT_TMP_DEST_REG
f9869a6810 Fix LoongArch float temporary tests (#238)
9737b3c943 Add float temporary set tests
4fd70d341d Add float temporary tests
8629fad57d Fix RISCV temporary register use
b0fd8cd2c3 Add memory temporary tests
958e8d7bcc Support addmul on LoongArch64 (#237)
c4769cbc4a Support addmul on s390x
6b8503dadc Support addmul on x86, arm, riscv, ppc, mips
c1ae218f51 Add multiplcation tests with temporary register support
a78d9ded50 Fix failing tests on ARM, PPC
120c6efc44 Add more temporary register tests
4e34ed5fb0 Improve temporary register support
46f12a2c46 Fix leaks (#236)
40eff81472 Update create compiler and generate code arguments
bf9bf14961 Support recent changes on LoongArch64 (#235)

git-subtree-dir: thirdparty/sljit
git-subtree-split: a7066fdb10a915dacd5ec39f10b4048002c7b748
2024-05-27 10:04:35 +01:00
Luke Usher 2abc056d06 Merge commit 'c94794e9599911d2bd0c22c07adb30ca127f5adf' 2024-05-27 10:04:35 +01:00
Luke Usher 9664144d1b Squashed 'ares/n64/vulkan/parallel-rdp/' changes from 37bf2967e3..ff3b858dd3
ff3b858dd3 Update to 16d3a27eab1af53021bf6a49807e5e0720862bd3.
7cdcaa3db9 Update to d7746d1f999ba1507f4d2fd8fade77ee3cbb5425.

git-subtree-dir: ares/n64/vulkan/parallel-rdp
git-subtree-split: ff3b858dd3a7ca27bd7c91fc894a7acd13fc0bcf
2024-05-27 10:04:30 +01:00
Luke Usher f31d209883 Merge commit '9664144d1bf2986191b54e97f712c6516ae15672' 2024-05-27 10:04:30 +01:00
png183 21209edad6 gba: synchronize CPU with other components more frequently (#1506)
Reduces the synchronization interval between the GBA CPU and other
components from 64 to 16 cycles, which significantly improves PPU
timings in the performance profile. These PPU timing improvements can be
observed in
[status-irq-dma.gba](https://github.com/nba-emu/hw-test/tree/master/ppu/status-irq-dma),
which now frequently gets results within a few cycles of the correct
values in situations which were previously off by dozens of cycles.
While this does impact performance by ~5-10%, in my testing this is
still faster than versions from before [commit
b145f0f](https://github.com/ares-emulator/ares/commit/b145f0f000c4e0ddedf25a62cdcfe713deea1f6a).
2024-05-26 07:04:53 +01:00
png183 8f3261e870 gba: improve BIOS open bus edge case handling (#1504)
This PR improves handling of BIOS open bus edge cases that previously
were handled incorrectly, such as unaligned 8-bit and 16-bit accesses,
and cases where the last value read from BIOS was not a 32-bit value.
2024-05-21 11:50:24 +01:00
thekovic a65bf18645 nall: fix Wcast-user-defined warning (#1494)
Compiling with GCC 14.1 in MSYS2 caused a lot of warnings of the
`-Wcast-user-defined` variety. This PR adresses that.

Note: This PR does not address
https://github.com/ares-emulator/ares/issues/1399 . Those warnings
happen at the link stage, they don't seem to be GCC-only (since issue OP
also reports them with clang), and they don't appear at lower
optimization settings (I tested `build=debug` and `build=stable` which
compiled cleanly).
2024-05-18 16:56:32 +01:00
Derek "Turtle" Roe a327e9b953 Fix some inconsistent formatting in the N64 database (#1496)
Just fixed up a few inconsistent formatting issues in the N64 database
while I was taking a peek 😄
2024-05-18 16:56:18 +01:00
曾耿森 672e81572c fix(ppu): fix some ppu bug and pass some tests (#1493)
1. fix read OAMDATA($2004)
2. fix write OAMDATA($2004)
3. refactor struct OAM access operator[]
4. remove some unused variable in ppu.io
5. spriteEvaluation.oamMainCounter is reference oamAddress
6. fix ppu sprite evaluation in pre-rederer line
7. inc fc serialization version to v143
8. pass blargg_apu_2005.07.30/09.reset_timing.nes
9. pass dmc_dma_during_read4/dma_4016_read.nes
10. pass sprdma_and_dmc_dma/sprdma_and_dmc_dma.nes
11. pass sprdma_and_dmc_dma/sprdma_and_dmc_dma_512.nes
2024-05-18 16:17:25 +01:00
曾耿森 deb1cf6d79 fix(ppu): fix some bug and pass test power_up_palette.nes (#1500)
pass blargg_ppu_tests_2005.09.15b/power_up_palette.nes
pass "Hello World" PPU test:
https://github.com/PeterLemon/NES/tree/master/HelloWorld

In https://forums.nesdev.org/viewtopic.php?t=567#top,

blargg say: "The power-up values of the palette are what my test program
reads back after powering the NES. I have one of the older units that
shows a green screen (I think newer front-loading ones had a gray
screen). These values probably vary slightly from one console to the
next."

Palette at power-up
0x09,0x01,0x00,0x01,
0x00,0x02,0x02,0x0D,
0x08,0x10,0x08,0x24,
0x00,0x00,0x04,0x2C,
0x09,0x01,0x34,0x03,
0x00,0x04,0x00,0x14,
0x08,0x3A,0x00,0x02,
0x00,0x20,0x2C,0x08,

To read/write a cgram, it needs to and 0x03, not 0x13

In https://www.nesdev.org/wiki/PPU_palettes#Memory_Map

$3F00	Universal background color
$3F10	Mirror of universal background color

$3F04	Normally unused color 1
$3F14	Mirror of unused color 1

$3F08	Normally unused color 2
$3F18	Mirror of unused color 2

$3F0C	Normally unused color 3
$3F1C	Mirror of unused color 3
2024-05-18 16:16:30 +01:00
remutro 70f833957e Resize target buffer when IPS patch extends beyond original source size (#1501)
For IPS patches that extend the original ROM beyond its initial size, we
will now resize the target buffer when patches extend the size of the
original.

Originally found testing out the Shin Megami Tensei patch by Orden
(https://www.romhacking.net/translations/2616/), which will now work
correctly.
2024-05-18 16:16:11 +01:00
曾耿森 8b5e30dad9 feat(fc-ppu): pass some ppu test (#1490)
1. pass sprite_overflow_tests/1.Basics.nes
2. pass sprite_overflow_tests/2.Details.nes
3. pass sprite_overflow_tests/3.Timing.nes
4. pass sprite_overflow_tests/4.Obscure.nes
5. pass sprite_overflow_tests/5.Emulator.nes

6. fix cpu serialization bug (miss oddCycle)
7. inc the fc serialization version
2024-05-11 21:39:04 +01:00
png183 9fb9dd59ba gba: latch timer register writes for 1 cycle (#1489)
Latches writes to timer registers for 1 cycle. This fixes common
off-by-one errors with precise timer use, which for example positively
impacts the test cases in #154.
2024-05-11 21:38:28 +01:00
jcmandjcm 67fc9ea81b ruby: Various Mac driver settings fix-ups (#1486)
This PR applies several minor fixes and improvements to macOS driver
settings and the driver settings pane.

#### Remove the "exclusive mode" video option on macOS.

* There is no real notion of exclusive presentation on macOS beyond what
already exists in normal fullscreen. If an application is covering the
screen and no other application or window is visible, the system
automatically switches to a "direct" presentation mode that optimizes
for single-application presentation performance. There is not a good
reason to show this option on macOS, even disabled.
* By contrast, it is possible (though not implemented by ares) to enter
exclusive mode on the audio device with CoreAudio, so leave that option
there, just disabled.
#### Add a "use native fullscreen" option on macOS.
* There are various good reasons to prefer either native platform
fullscreen behavior, or a custom borderless windowed fullscreen. Rather
than guess what the user wants, offer an option.
* If unchecked, make the window title bar enlarge the window rather than
fullscreen it, so we don't mix behaviors.
#### Implement fullscreen monitor selection behavior for Metal, and
correctly enumerate the user's monitor names.
* Fullscreen display on the selected monitor in the settings pane was
previously not implemented on macOS. This implementation only works if
"Use native fullscreen" is disabled, since the macOS fullscreen idiom
doesn't feature selecting a specific display.
* Additionally, the old function to retrieve the monitor's localized
name did not work reliably on newer macOS versions. Use the modern
property `localizedName` on NSScreen for macOS versions above 10.15, and
fall back to the old implementation otherwise.
* Implementing this meant adding a `uintptr` handle to the NSScreen
instance in the `Monitor` struct in ruby that uses a bridged cast to
interface with Objective-C. I would have preferred not to do this, but I
didn't see another good way to handle getting the `NSScreen` instance
that didn't involve a serious refactor.
#### (all platforms) Disable monitor selection if the video driver's
`hasMonitor()` is false.
* Just a minor fixup; the existing behavior is that the dropdown list
can be navigated and selected, but the selection does not persist. It
makes more sense to just disable it if the driver doesn't support it.

Co-authored-by: jcm <[email protected]>
2024-05-05 16:11:35 +01:00
shinra-electric 4f834bd506 CI: Update cache and checkout to v4 (#1478)
- Updates `checkout` from v2 to v4
- Updates `cache` from v3 to v4

Reasons for change: 
- Checkout@v2 runs on node 12, which has been
[discontinued](https://github.blog/changelog/2023-06-13-github-actions-all-actions-will-run-on-node16-instead-of-node12-by-default/)
- Checkout@v3 runs on node 16 and has also reached its [end of
life](https://github.blog/changelog/2023-09-22-github-actions-transitioning-from-node-16-to-node-20/),
so skip it entirely.
- Cache@v3 runs on node 16 as well, so update to v4 for the same reason.

Testing: 
- Ensure CI passes
- Check that warnings regarding `checkout` and `cache` are gone
2024-05-04 09:33:58 +01:00
曾耿森 785c148768 fix(fc): fix fc dma interrupt (#1476)
pass cpu_interrupts_v2/4-irq_and_dma.nes
2024-05-03 11:14:08 +01:00
png183 cfda608bc2 gba: improve VRAM mirroring in bitmap background modes (#1475)
Blocks accesses to the mirrored region at VRAM addresses 0x18000 to
0x1bfff when in background modes 3-5, as described
[here](https://github.com/nba-emu/hw-test/tree/master/ppu/vram-mirror).
2024-05-03 11:14:02 +01:00
shinra-electric f94e053767 CI: Update upload-artifact and download-artifact to use v4 (#1472)
- v2 will be unavailable from the end of June 2024
- v4 can be up to 98% faster than previous versions according to
[Github's
notification](https://github.blog/changelog/2024-04-16-deprecation-notice-v3-of-the-artifact-actions/)

This PR only changes the version number, and I'm submitting it to see if
it works.
It is possible that further changes are necessary, as there were some
[breaking
changes](https://github.com/actions/upload-artifact?tab=readme-ov-file#breaking-changes),
but I don't think any of them apply to ares.

Testing: 
- See if CI passes
- See if warnings regarding using v2 of `upload-artifact` and
`download-artifact` are gone (There will still be other warnings
regarding `checkout` and `cache`)
- (Optional) Compare times for the tasks using `upload-artifact` and
`download-artifact` with previous CI runs
2024-05-03 11:13:55 +01:00
remutro 6e8bcd9bda Disable run ahead for 64DD, fixes load failures (#1474)
Turns out the problem some folks experienced trying to load 64DD games
was due to run ahead not being disabled by default. An exception for
this system has been added.
2024-05-02 19:18:18 +01:00
2058 changed files with 139103 additions and 103352 deletions

No files matched your search

+8 -5
View File
@@ -90,7 +90,7 @@ jobs:
keychain-name: ares-macos-keychain
keychain-password: ${{ secrets.MACOS_KEYCHAIN_PASSWORD }}
- name: Checkout source code
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Install Windows Dependencies
if: runner.os == 'Windows'
run: |
@@ -111,7 +111,7 @@ jobs:
fi
- name: "macOS: recover MoltenVK cache"
if: runner.os == 'macOS'
uses: actions/cache@v3
uses: actions/cache@v4
env:
cache-name: moltenvk
with:
@@ -122,9 +122,11 @@ jobs:
run: |
if [ $ImageOS == "macos14" ]; then
sudo xcode-select -s /Applications/Xcode_15.2.app/Contents/Developer
export MACOSX_DEPLOYMENT_TARGET=10.13
echo "Set Xcode version to 15.2 for macos-latest build."
elif [ $ImageOS == "macos12" ]; then
sudo xcode-select -s /Applications/Xcode_13.4.app/Contents/Developer
export MACOSX_DEPLOYMENT_TARGET=10.9
echo "Set Xcode version to 13.4 for macos-compat build."
fi
brew install make ninja cmake
@@ -140,6 +142,7 @@ jobs:
pushd thirdparty/MoltenVK
./build-moltenvk.sh
popd
export MACOSX_DEPLOYMENT_TARGET=10.15
pushd thirdparty/librashader
./build-librashader.sh
popd
@@ -181,7 +184,7 @@ jobs:
MACOS_NOTARIZATION_PASSWORD: ${{ secrets.MACOS_NOTARIZATION_PASSWORD }}
MACOS_NOTARIZATION_TEAMID: ${{ secrets.MACOS_NOTARIZATION_TEAMID }}
- name: Upload
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.program }}-${{ matrix.platform.name }}
path: desktop-ui/out/*
@@ -193,11 +196,11 @@ jobs:
needs:
- build
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
path: 'src'
- name: Download Artifacts
uses: actions/download-artifact@v2
uses: actions/download-artifact@v4
with:
path: 'bin'
- name: Package Artifacts
+1 -1
View File
@@ -93,4 +93,4 @@ auto RIOT::readPortB() -> n8 {
auto RIOT::writePortB(n8 data) -> void {
port[1].data = data;
}
}
+1 -1
View File
@@ -44,4 +44,4 @@ auto RIOT::power(bool reset) -> void {
tvType = 1;
}
}
}
+1 -1
View File
@@ -47,4 +47,4 @@ struct RIOT : Thread {
n1 tvTypeLatch;
};
extern RIOT riot;
extern RIOT riot;
+1 -1
View File
@@ -20,4 +20,4 @@ auto RIOT::serialize(serializer& s) -> void {
s(rightDifficultyLatch);
s(tvType);
s(tvTypeLatch);
}
}
+1 -1
View File
@@ -61,4 +61,4 @@ auto TIA::AudioChannel::phase1() -> u8 {
}
return pulseCounter.bit(0) * volume;
}
}
+1 -1
View File
@@ -140,4 +140,4 @@ auto TIA::resmp(n1 index, n8 data) -> void {
auto TIA::resbl() -> void {
ball.reset();
}
}
+1 -1
View File
@@ -85,4 +85,4 @@ auto TIA::runMissile(n8 x, n1 index) -> n1 {
return 0;
}
*/
*/
+1 -1
View File
@@ -7,4 +7,4 @@ auto TIA::runPlayfield(n8 x) -> n1 {
}
return playfield.pixel;
}
}
+1 -1
View File
@@ -93,4 +93,4 @@ auto TIA::serialize(serializer& s) -> void {
s(audio[n].control);
s(audio[n].frequency);
}
}
}
+1 -1
View File
@@ -152,4 +152,4 @@ auto TIA::power(bool reset) -> void {
volume[15] = 0;
}
}
}
+1 -1
View File
@@ -172,4 +172,4 @@ struct TIA : Thread {
f64 volume[16];
};
extern TIA tia;
extern TIA tia;
+1 -1
View File
@@ -43,4 +43,4 @@ auto TIA::WriteQueue::QueueItem::commit() -> void {
case 0x2b: tia.hmclr(); return; // HMCLR
}
debug(unimplemented, "[TIA] writeQueue: ",hex(address), " = ", hex(data));
}
}
+1 -1
View File
@@ -10,7 +10,7 @@ Platform* platform = nullptr;
bool _runAhead = false;
const string Name = "ares";
const string Version = "138";
const string Version = "141";
const string Copyright = "ares team, Near";
const string License = "ISC";
const string LicenseURI = "https://opensource.org/licenses/ISC";
@@ -165,6 +165,8 @@ auto M93LCx6::ShiftRegister::read() -> n1 {
}
auto M93LCx6::ShiftRegister::write(n1 bit) -> void {
// wait for start bit
if(!bit && !count) return;
value <<= 1;
value.bit(0) = bit;
count++;
+1 -1
View File
@@ -69,4 +69,4 @@ namespace ares {
s(state.portB);
s(state.portC);
}
}
}
+2 -1
View File
@@ -32,4 +32,5 @@ namespace ares {
n8 portC;
} state;
};
}
}
@@ -20,6 +20,7 @@ struct ARM7TDMI {
virtual auto step(u32 clocks) -> void = 0;
virtual auto sleep() -> void = 0;
virtual auto get(u32 mode, n32 address) -> n32 = 0;
virtual auto getDebugger(u32 mode, n32 address) -> n32 { return get(mode, address); }
virtual auto set(u32 mode, n32 address, n32 word) -> void = 0;
//arm7tdmi.cpp
@@ -17,12 +17,12 @@ auto ARM7TDMI::disassembleInstruction(maybe<n32> pc, maybe<boolean> thumb) -> st
_pc = pc();
if(!thumb()) {
n32 opcode = read(Word | Nonsequential, _pc & ~3);
n32 opcode = getDebugger(Word | Nonsequential, _pc & ~3);
n12 index = (opcode & 0x0ff00000) >> 16 | (opcode & 0x000000f0) >> 4;
_c = _conditions[opcode >> 28];
return pad(armDisassemble[index](opcode), -40);
} else {
n16 opcode = read(Half | Nonsequential, _pc & ~1);
n16 opcode = getDebugger(Half | Nonsequential, _pc & ~1);
return pad(thumbDisassemble[opcode](), -40);
}
}
@@ -121,7 +121,7 @@ auto ARM7TDMI::armDisassembleDataRegisterShift
auto ARM7TDMI::armDisassembleLoadImmediate
(n8 immediate, n1 half, n4 d, n4 n, n1 writeback, n1 up, n1 pre) -> string {
string data;
if(n == 15) data = {" =0x", hex(read((half ? Half : Byte) | Nonsequential,
if(n == 15) data = {" =0x", hex(getDebugger((half ? Half : Byte) | Nonsequential,
_pc + 8 + (up ? +immediate : -immediate)), half ? 4L : 2L)};
return {"ldr", _c, half ? "sh" : "sb", " ",
@@ -150,7 +150,7 @@ auto ARM7TDMI::armDisassembleMemorySwap
auto ARM7TDMI::armDisassembleMoveHalfImmediate
(n8 immediate, n4 d, n4 n, n1 mode, n1 writeback, n1 up, n1 pre) -> string {
string data;
if(n == 15) data = {" =0x", hex(read(Half | Nonsequential, _pc + (up ? +immediate : -immediate)), 4L)};
if(n == 15) data = {" =0x", hex(getDebugger(Half | Nonsequential, _pc + (up ? +immediate : -immediate)), 4L)};
return {mode ? "ldr" : "str", _c, "h ",
_r[d], ",[", _r[n],
@@ -173,7 +173,7 @@ auto ARM7TDMI::armDisassembleMoveHalfRegister
auto ARM7TDMI::armDisassembleMoveImmediateOffset
(n12 immediate, n4 d, n4 n, n1 mode, n1 writeback, n1 byte, n1 up, n1 pre) -> string {
string data;
if(n == 15) data = {" =0x", hex(read((byte ? Byte : Word) | Nonsequential,
if(n == 15) data = {" =0x", hex(getDebugger((byte ? Byte : Word) | Nonsequential,
_pc + 8 + (up ? +immediate : -immediate)), byte ? 2L : 4L)};
return {mode ? "ldr" : "str", _c, byte ? "b" : "", " ", _r[d], ",[", _r[n],
pre == 0 ? "]" : "",
@@ -308,7 +308,7 @@ auto ARM7TDMI::thumbDisassembleBranchExchange
auto ARM7TDMI::thumbDisassembleBranchFarPrefix
(i11 displacementHi) -> string {
n11 displacementLo = read(Half | Nonsequential, (_pc & ~1) + 2);
n11 displacementLo = getDebugger(Half | Nonsequential, (_pc & ~1) + 2);
i22 displacement = displacementHi << 11 | displacementLo << 0;
n32 address = _pc + 4 + displacement * 2;
return {"bl 0x", hex(address, 8L)};
@@ -340,7 +340,7 @@ auto ARM7TDMI::thumbDisassembleImmediate
auto ARM7TDMI::thumbDisassembleLoadLiteral
(n8 displacement, n3 d) -> string {
n32 address = ((_pc + 4) & ~3) + (displacement << 2);
n32 data = read(Word | Nonsequential, address);
n32 data = getDebugger(Word | Nonsequential, address);
return {"ldr ", _r[d], ",[pc,#0x", hex(address, 8L), "] =0x", hex(data, 8L)};
}
@@ -182,14 +182,15 @@ auto ARM7TDMI::armInstructionMoveImmediateOffset
auto ARM7TDMI::armInstructionMoveMultiple
(n16 list, n4 n, n1 mode, n1 writeback, n1 type, n1 up, n1 pre) -> void {
n32 rn = r(n);
n32 bitCount = list ? bit::count(list) : 16;
if(pre == 0 && up == 1) rn = rn + 0; //IA
if(pre == 1 && up == 1) rn = rn + 4; //IB
if(pre == 1 && up == 0) rn = rn - bit::count(list) * 4 + 0; //DB
if(pre == 0 && up == 0) rn = rn - bit::count(list) * 4 + 4; //DA
if(pre == 1 && up == 0) rn = rn - bitCount * 4 + 0; //DB
if(pre == 0 && up == 0) rn = rn - bitCount * 4 + 4; //DA
if(writeback && mode == 1) {
if(up == 1) r(n) = r(n) + bit::count(list) * 4; //IA,IB
if(up == 0) r(n) = r(n) - bit::count(list) * 4; //DA,DB
if(writeback && mode == 1 && !list.bit(n)) {
if(up == 1) r(n) = r(n) + bitCount * 4; //IA,IB
if(up == 0) r(n) = r(n) - bitCount * 4; //DA,DB
}
auto cpsrMode = cpsr().m;
@@ -199,12 +200,17 @@ auto ARM7TDMI::armInstructionMoveMultiple
if(usr) cpsr().m = PSR::USR;
u32 sequential = Nonsequential;
for(u32 m : range(16)) {
if(!list.bit(m)) continue;
if(mode == 1) r(m) = read(Word | sequential, rn);
if(mode == 0) write(Word | sequential, rn, r(m) + (m == 15 ? 4 : 0));
rn += 4;
sequential = Sequential;
if(!list) {
if(mode == 1) r(15) = read(Word | sequential, rn);
if(mode == 0) write(Word | sequential, rn, r(15) + 4);
} else {
for(u32 m : range(16)) {
if(!list.bit(m)) continue;
if(mode == 1) r(m) = read(Word | sequential, rn);
if(mode == 0) write(Word | sequential, rn, r(m) + (m == 15 ? 4 : 0));
rn += 4;
sequential = Sequential;
}
}
if(usr) cpsr().m = cpsrMode;
@@ -219,8 +225,8 @@ auto ARM7TDMI::armInstructionMoveMultiple
}
if(writeback && mode == 0) {
if(up == 1) r(n) = r(n) + bit::count(list) * 4; //IA,IB
if(up == 0) r(n) = r(n) - bit::count(list) * 4; //DA,DB
if(up == 1) r(n) = r(n) + bitCount * 4; //IA,IB
if(up == 0) r(n) = r(n) - bitCount * 4; //DA,DB
}
}
@@ -249,8 +255,7 @@ auto ARM7TDMI::armInstructionMoveRegisterOffset
auto ARM7TDMI::armInstructionMoveToRegisterFromStatus
(n4 d, n1 mode) -> void {
if(mode && (cpsr().m == PSR::USR || cpsr().m == PSR::SYS)) return;
r(d) = mode ? spsr() : cpsr();
r(d) = (mode && cpsr().m != PSR::USR && cpsr().m != PSR::SYS) ? spsr() : cpsr();
}
auto ARM7TDMI::armInstructionMoveToStatusFromImmediate
@@ -125,23 +125,29 @@ auto ARM7TDMI::thumbInstructionMoveHalfImmediate
auto ARM7TDMI::thumbInstructionMoveMultiple
(n8 list, n3 n, n1 mode) -> void {
n32 rn = r(n);
n32 bitCount = list ? bit::count(list) : 16;
if(mode == 1 && !list.bit(n)) r(n) = r(n) + bitCount * 4;
u32 sequential = Nonsequential;
for(u32 m : range(8)) {
if(!list.bit(m)) continue;
switch(mode) {
case 0: write(Word | sequential, rn, r(m)); break; //STMIA
case 1: r(m) = read(Word | sequential, rn); break; //LDMIA
if(!list) {
if(mode == 1) r(15) = read(Word | sequential, rn);
if(mode == 0) write(Word | sequential, rn, r(15) + 2);
} else {
for(u32 m : range(8)) {
if(!list.bit(m)) continue;
if(mode == 1) r(m) = read(Word | sequential, rn); //LDMIA
if(mode == 0) write(Word | sequential, rn, r(m)); //STMIA
rn += 4;
sequential = Sequential;
}
rn += 4;
sequential = Sequential;
}
if(mode == 0 || !list.bit(n)) r(n) = rn;
if(mode == 1) {
if(mode) {
idle();
} else {
pipeline.nonsequential = true;
r(n) = r(n) + bitCount * 4;
}
}
@@ -191,37 +197,35 @@ auto ARM7TDMI::thumbInstructionSoftwareInterrupt
auto ARM7TDMI::thumbInstructionStackMultiple
(n8 list, n1 lrpc, n1 mode) -> void {
n32 sp;
switch(mode) {
case 0: sp = r(13) - (bit::count(list) + lrpc) * 4; break; //PUSH
case 1: sp = r(13); //POP
}
n32 sp = r(13);
n32 bitCount = (list | lrpc) ? (bit::count(list) + lrpc) : 16;
if(mode == 1) r(13) = r(13) + bitCount * 4; //POP
if(mode == 0) sp = sp - bitCount * 4 + 0; //PUSH
u32 sequential = Nonsequential;
for(u32 m : range(8)) {
if(!list.bit(m)) continue;
switch(mode) {
case 0: write(Word | sequential, sp, r(m)); break; //PUSH
case 1: r(m) = read(Word | sequential, sp); break; //POP
if(bitCount == 16) {
if(mode == 1) r(15) = read(Word | sequential, sp); //POP
if(mode == 0) write(Word | sequential, sp, r(15) + 2); //PUSH
} else {
for(u32 m : range(8)) {
if(!list.bit(m)) continue;
if(mode == 1) r(m) = read(Word | sequential, sp); //POP
if(mode == 0) write(Word | sequential, sp, r(m)); //PUSH
sp += 4;
sequential = Sequential;
}
sp += 4;
sequential = Sequential;
}
if(lrpc) {
switch(mode) {
case 0: write(Word | sequential, sp, r(14)); break; //PUSH
case 1: r(15) = read(Word | sequential, sp); break; //POP
}
if(mode == 1) r(15) = read(Word | sequential, sp); //POP
if(mode == 0) write(Word | sequential, sp, r(14)); //PUSH
sp += 4;
}
if(mode == 1) {
if(mode) {
idle();
r(13) = r(13) + (bit::count(list) + lrpc) * 4; //POP
} else {
pipeline.nonsequential = true;
r(13) = r(13) - (bit::count(list) + lrpc) * 4; //PUSH
r(13) = r(13) - bitCount * 4; //PUSH
}
}
+2 -2
View File
@@ -75,8 +75,8 @@ struct GSU {
auto serialize(serializer&) -> void;
//disassembler.cpp
noinline auto disassembleInstruction() -> string;
noinline auto disassembleContext() -> string;
NALL_NOINLINE auto disassembleInstruction() -> string;
NALL_NOINLINE auto disassembleContext() -> string;
auto disassembleOpcode(char* output) -> void;
auto disassembleALT0(char* output) -> void;
+2 -2
View File
@@ -111,8 +111,8 @@ struct HG51B {
auto writeRegister(n7 address, n24 data) -> void;
//disassembler.cpp
noinline auto disassembleInstruction(maybe<n15> pb = {}, maybe<n8> pc = {}) -> string;
noinline auto disassembleContext() -> string;
NALL_NOINLINE auto disassembleInstruction(maybe<n15> pb = {}, maybe<n8> pc = {}) -> string;
NALL_NOINLINE auto disassembleContext() -> string;
protected:
struct Registers {
+2 -2
View File
@@ -124,8 +124,8 @@ struct I8080 {
auto serialize(serializer&) -> void;
//disassembler.cpp
noinline auto disassembleInstruction(maybe<n16> pc = {}) -> string;
noinline auto disassembleContext() -> string;
NALL_NOINLINE auto disassembleInstruction(maybe<n16> pc = {}) -> string;
NALL_NOINLINE auto disassembleContext() -> string;
auto disassemble(n16 pc, n8 prefix, n8 code) -> string;
+2 -2
View File
@@ -156,8 +156,8 @@ struct MOS6502 {
auto serialize(serializer&) -> void;
//disassembler.cpp
noinline auto disassembleInstruction(maybe<n16> pc = {}) -> string;
noinline auto disassembleContext() -> string;
NALL_NOINLINE auto disassembleInstruction(maybe<n16> pc = {}) -> string;
NALL_NOINLINE auto disassembleContext() -> string;
struct PR {
bool c; //carry
+2 -4
View File
@@ -14,7 +14,7 @@ auto SH2::delaySlot(u32 pc) -> void {
}
auto SH2::instruction() -> void {
if constexpr(Accuracy::Interpreter) {
if(Accuracy::Interpreter || !recompiler.enabled) {
step(1);
exceptionHandler();
if constexpr(Accuracy::AddressErrors) {
@@ -26,9 +26,7 @@ auto SH2::instruction() -> void {
instructionPrologue(opcode);
execute(opcode);
instructionEpilogue();
}
if constexpr(Accuracy::Recompiler) {
} else {
exceptionHandler();
// Recompiled blocks may be very small, negating the impact
@@ -513,19 +513,19 @@ auto SH2::MOVI(u32 i, u32 n) -> void {
}
//MOV.W @(disp,PC),Rn
noinline auto SH2::MOVWI(u32 d, u32 n) -> void {
NALL_NOINLINE auto SH2::MOVWI(u32 d, u32 n) -> void {
u32 pc = inDelaySlot() ? PPC - 2 : PC;
R[n] = (s16)readWord(pc + d * 2);
}
//MOV.L @(disp,PC),Rn
noinline auto SH2::MOVLI(u32 d, u32 n) -> void {
NALL_NOINLINE auto SH2::MOVLI(u32 d, u32 n) -> void {
u32 pc = inDelaySlot() ? PPC - 2 : PC;
R[n] = readLong((pc & ~3) + d * 4);
}
//MOVA @(disp,PC),R0
noinline auto SH2::MOVA(u32 d) -> void {
NALL_NOINLINE auto SH2::MOVA(u32 d) -> void {
u32 pc = inDelaySlot() ? PPC - 2 : PC;
R[0] = (pc & ~3) + d * 4;
}
+1
View File
@@ -300,6 +300,7 @@ struct SH2 {
static auto mask(u8 address, u8 size) -> u64;
bool enabled = false;
bool callInstructionPrologue = false;
bool inDelaySlot;
u32 generation;
+2 -2
View File
@@ -29,8 +29,8 @@ struct SM83 {
//disassembler.cpp
virtual auto readDebugger(n16 address) -> n8 { return 0; }
noinline auto disassembleInstruction(maybe<n16> pc = {}) -> string;
noinline auto disassembleContext() -> string;
NALL_NOINLINE auto disassembleInstruction(maybe<n16> pc = {}) -> string;
NALL_NOINLINE auto disassembleContext() -> string;
//memory.cpp
auto operand() -> n8;
+3 -3
View File
@@ -117,9 +117,9 @@ struct SPC700 {
auto serialize(serializer&) -> void;
//disassembler.cpp
noinline auto disassembleInstruction(n16 address, n1 p) -> string;
noinline auto disassembleInstruction() -> string;
noinline auto disassembleContext() -> string;
NALL_NOINLINE auto disassembleInstruction(n16 address, n1 p) -> string;
NALL_NOINLINE auto disassembleInstruction() -> string;
NALL_NOINLINE auto disassembleContext() -> string;
struct Flags {
bool c; //carry
@@ -1,4 +1,4 @@
noinline auto TLCS900H::disassembleInstruction() -> string {
NALL_NOINLINE auto TLCS900H::disassembleInstruction() -> string {
string output;
auto pc = load(PC);
@@ -636,7 +636,7 @@ noinline auto TLCS900H::disassembleInstruction() -> string {
return pad(output, -48);
}
noinline auto TLCS900H::disassembleContext() -> string {
NALL_NOINLINE auto TLCS900H::disassembleContext() -> string {
string output;
output.append("XWA:", hex(r.xwa[RFP].l.l0, 8L), " ");
output.append("XBC:", hex(r.xbc[RFP].l.l0, 8L), " ");
@@ -25,8 +25,8 @@ struct uPD96050 {
auto writeDP(n12 address, n8 data) -> void;
//disassembler.cpp
noinline auto disassembleInstruction(maybe<n14> ip = {}) -> string;
noinline auto disassembleContext() -> string;
NALL_NOINLINE auto disassembleInstruction(maybe<n14> ip = {}) -> string;
NALL_NOINLINE auto disassembleContext() -> string;
enum class Revision : u32 { uPD7725, uPD96050 } revision;
n24 programROM[16384];
+12 -5
View File
@@ -1,3 +1,10 @@
auto V30MZ::prefixFlush() -> void {
prefix.count = 0;
prefix.lock = 0;
prefix.repeat = 0;
prefix.segment = 0;
}
auto V30MZ::interrupt(u8 vector, InterruptSource source) -> bool {
if(source == InterruptSource::INT) wait(32);
else if (source == InterruptSource::NMI) wait(26);
@@ -5,15 +12,15 @@ auto V30MZ::interrupt(u8 vector, InterruptSource source) -> bool {
state.halt = 0;
state.poll = 1;
state.prefix = 0;
//if an IRQ fires during a rep string instruction;
//flush prefix queue and seek back to first prefix.
//this allows the transfer to resume after the IRQ.
if(repeat()) {
PC -= prefixes.size();
prefixes.flush();
if(state.prefix) {
state.prefix = 0;
PC -= prefix.count;
}
prefixFlush();
auto pc = read<Word>(0x0000, vector * 4 + 0);
auto ps = read<Word>(0x0000, vector * 4 + 2);
@@ -309,7 +316,7 @@ auto V30MZ::instruction() -> void {
op(0xff, Group4MemImm<Word>)
}
if(!state.prefix) prefixes.flush();
if(!state.prefix) prefixFlush();
if(PSW.BRK) interrupt(1, InterruptSource::SingleStep);
}
@@ -14,7 +14,7 @@ auto V30MZ::instructionDecimalAdjust(bool negate) -> void {
al = AL;
AL += negate ? -0x60 : 0x60;
PSW.CY = 1;
if(negate) PSW.V |= (al ^ 0x06) & (al ^ AL) & 0x80; // undefined
if(negate) PSW.V |= (al ^ 0x60) & (al ^ AL) & 0x80; // undefined
else PSW.V |= (AL ^ al) & (AL ^ 0x60) & 0x80; // undefined
} else {
PSW.CY = 0;
@@ -1,21 +1,21 @@
auto V30MZ::instructionSegment(n16 segment) -> void {
if(prefixes.full()) prefixes.read(0);
prefixes.write(opcode);
prefix.segment = opcode;
prefix.count++;
state.prefix = 1;
state.poll = 0;
}
auto V30MZ::instructionRepeat() -> void {
if(prefixes.full()) prefixes.read(0);
prefixes.write(opcode);
prefix.repeat = opcode;
prefix.count++;
wait(4);
state.prefix = 1;
state.poll = 0;
}
auto V30MZ::instructionLock() -> void {
if(prefixes.full()) prefixes.read(0);
prefixes.write(opcode);
prefix.lock = opcode;
prefix.count++;
state.prefix = 1;
state.poll = 0;
}
@@ -1,11 +1,11 @@
template<u32 size> auto V30MZ::instructionInString() -> void {
wait(3);
if(!repeat() || CW) {
if(!prefix.repeat || CW) {
auto data = in<size>(DW);
write<size>(DS1, IY, data);
IY += PSW.DIR ? -size : size;
if(!repeat() || !--CW) return;
if(!prefix.repeat || !--CW) return;
state.prefix = 1;
PC--;
@@ -15,12 +15,12 @@ template<u32 size> auto V30MZ::instructionInString() -> void {
template<u32 size> auto V30MZ::instructionOutString() -> void {
wait(3);
if(!repeat() || CW) {
if(!prefix.repeat || CW) {
auto data = read<size>(segment(DS0), IX);
out<size>(DW, data);
IX += PSW.DIR ? -size : size;
if(!repeat() || !--CW) return;
if(!prefix.repeat || !--CW) return;
state.prefix = 1;
PC--;
@@ -30,13 +30,13 @@ template<u32 size> auto V30MZ::instructionOutString() -> void {
template<u32 size> auto V30MZ::instructionMoveString() -> void {
wait(3);
if(!repeat() || CW) {
if(!prefix.repeat || CW) {
auto data = read<size>(segment(DS0), IX);
write<size>(DS1, IY, data);
IX += PSW.DIR ? -size : size;
IY += PSW.DIR ? -size : size;
if(!repeat() || !--CW) return;
if(!prefix.repeat || !--CW) return;
state.prefix = 1;
PC--;
@@ -46,16 +46,16 @@ template<u32 size> auto V30MZ::instructionMoveString() -> void {
template<u32 size> auto V30MZ::instructionCompareString() -> void {
wait(4);
if(!repeat() || CW) {
if(!prefix.repeat || CW) {
auto x = read<size>(segment(DS0), IX);
auto y = read<size>(DS1, IY);
IX += PSW.DIR ? -size : size;
IY += PSW.DIR ? -size : size;
SUB<size>(x, y);
if(!repeat() || !--CW) return;
if(repeat() == RepeatWhileZeroLo && PSW.Z == 1) return;
if(repeat() == RepeatWhileZeroHi && PSW.Z == 0) return;
if(!prefix.repeat || !--CW) return;
if(prefix.repeat == RepeatWhileZeroLo && PSW.Z == 1) return;
if(prefix.repeat == RepeatWhileZeroHi && PSW.Z == 0) return;
state.prefix = 1;
PC--;
@@ -65,11 +65,11 @@ template<u32 size> auto V30MZ::instructionCompareString() -> void {
template<u32 size> auto V30MZ::instructionStoreString() -> void {
wait(2);
if(!repeat() || CW) {
if(!prefix.repeat || CW) {
write<size>(DS1, IY, getAccumulator<size>());
IY += PSW.DIR ? -size : size;
if(!repeat() || !--CW) return;
if(!prefix.repeat || !--CW) return;
state.prefix = 1;
PC--;
@@ -79,11 +79,11 @@ template<u32 size> auto V30MZ::instructionStoreString() -> void {
template<u32 size> auto V30MZ::instructionLoadString() -> void {
wait(2);
if(!repeat() || CW) {
if(!prefix.repeat || CW) {
setAccumulator<size>(read<size>(segment(DS0), IX));
IX += PSW.DIR ? -size : size;
if(!repeat() || !--CW) return;
if(!prefix.repeat || !--CW) return;
state.prefix = 1;
PC--;
@@ -93,15 +93,15 @@ template<u32 size> auto V30MZ::instructionLoadString() -> void {
template<u32 size> auto V30MZ::instructionScanString() -> void {
wait(3);
if(!repeat() || CW) {
if(!prefix.repeat || CW) {
auto x = getAccumulator<size>();
auto y = read<size>(DS1, IY);
IY += PSW.DIR ? -size : size;
SUB<size>(x, y);
if(!repeat() || !--CW) return;
if(repeat() == RepeatWhileZeroLo && PSW.Z == 1) return;
if(repeat() == RepeatWhileZeroHi && PSW.Z == 0) return;
if(!prefix.repeat || !--CW) return;
if(prefix.repeat == RepeatWhileZeroLo && PSW.Z == 1) return;
if(prefix.repeat == RepeatWhileZeroHi && PSW.Z == 0) return;
state.prefix = 1;
PC--;
+4 -14
View File
@@ -1,18 +1,8 @@
auto V30MZ::repeat() -> u8 {
for(auto prefix : prefixes) {
if(prefix == RepeatWhileZeroLo) return prefix;
if(prefix == RepeatWhileZeroHi) return prefix;
}
return 0;
}
auto V30MZ::segment(u16 segment) -> u16 {
for(auto prefix : prefixes) {
if(prefix == SegmentOverrideDS1) return DS1;
if(prefix == SegmentOverridePS ) return PS;
if(prefix == SegmentOverrideSS ) return SS;
if(prefix == SegmentOverrideDS0) return DS0;
}
if(prefix.segment == SegmentOverrideDS1) return DS1;
if(prefix.segment == SegmentOverridePS ) return PS;
if(prefix.segment == SegmentOverrideSS ) return SS;
if(prefix.segment == SegmentOverrideDS0) return DS0;
return segment;
}
@@ -4,7 +4,11 @@ auto V30MZ::serialize(serializer& s) -> void {
s(state.prefix);
s(opcode);
s(prefixes);
s(prefix.count);
s(prefix.lock);
s(prefix.repeat);
s(prefix.segment);
s(modrm.mod);
s(modrm.reg);
+1 -1
View File
@@ -28,7 +28,7 @@ auto V30MZ::power() -> void {
state.prefix = 0;
opcode = 0;
prefixes.flush();
prefixFlush();
modrm.mod = 0;
modrm.reg = 0;
modrm.mem = 0;
+7 -1
View File
@@ -39,6 +39,7 @@ struct V30MZ {
auto power() -> void;
//instruction.cpp
auto prefixFlush() -> void;
auto interrupt(u8 vector) -> bool;
auto nonMaskableInterrupt() -> bool;
auto instruction() -> void;
@@ -242,7 +243,12 @@ struct V30MZ {
} state;
u8 opcode;
queue<u8[7]> prefixes;
struct Prefix {
u16 count;
u8 lock;
u8 repeat;
u8 segment;
} prefix;
struct ModRM {
u2 mod;
@@ -235,9 +235,9 @@ struct WDC65816 {
auto serialize(serializer&) -> void;
//disassembler.cpp
noinline auto disassembleInstruction(n24 address, bool e, bool m, bool x) -> string;
noinline auto disassembleInstruction() -> string;
noinline auto disassembleContext(maybe<bool> e = {}) -> string;
NALL_NOINLINE auto disassembleInstruction(n24 address, bool e, bool m, bool x) -> string;
NALL_NOINLINE auto disassembleInstruction() -> string;
NALL_NOINLINE auto disassembleContext(maybe<bool> e = {}) -> string;
struct f8 {
bool c = 0; //carry
+2 -2
View File
@@ -211,8 +211,8 @@ struct Z80 {
auto serialize(serializer&) -> void;
//disassembler.cpp
noinline auto disassembleInstruction(maybe<n16> pc = {}) -> string;
noinline auto disassembleContext() -> string;
NALL_NOINLINE auto disassembleInstruction(maybe<n16> pc = {}) -> string;
NALL_NOINLINE auto disassembleContext() -> string;
auto disassemble(n16 pc, n8 prefix, n8 code) -> string;
auto disassembleCB(n16 pc, n8 prefix, n8 code) -> string;
+3 -1
View File
@@ -148,13 +148,14 @@ struct APU : Thread {
auto clock() -> n8;
auto power(bool reset) -> void;
auto setDMABuffer(n8 data) -> void;
auto dmaAddress() -> n16 const { return 0x8000 | readAddress; }
//serialization.cpp
auto serialize(serializer&) -> void;
n16 lengthCounter;
n16 periodCounter;
n16 dmaDelayCounter;
n1 irqPending;
n4 period;
n1 irqEnable;
@@ -168,6 +169,7 @@ struct APU : Thread {
n8 dmaBuffer;
n1 sampleValid;
n8 sample;
n8 dmaDelayCounter;
} dmc;
struct FrameCounter {
+26 -34
View File
@@ -2,44 +2,19 @@ auto APU::DMC::start() -> void {
if(lengthCounter == 0) {
readAddress = 0x4000 + (addressLatch << 6);
lengthCounter = (lengthLatch << 4) + 1;
if (!dmaBufferValid)
dmaDelayCounter = periodCounter & 1 ? 2 : 3;
}
}
auto APU::DMC::stop() -> void {
lengthCounter = 0;
dmaDelayCounter = 0;
cpu.rdyLine(1);
cpu.rdyAddress(false);
}
auto APU::DMC::clock() -> n8 {
n8 result = dacLatch;
if(dmaDelayCounter > 0) {
dmaDelayCounter--;
if(dmaDelayCounter == 1) {
cpu.rdyAddress(true, 0x8000 | readAddress);
} else if(dmaDelayCounter == 0) {
cpu.rdyLine(1);
cpu.rdyAddress(false);
dmaBuffer = cpu.io.openBus;
dmaBufferValid = true;
lengthCounter--;
readAddress++;
if(lengthCounter == 0) {
if(loopMode) {
start();
} else if(irqEnable) {
irqPending = true;
apu.setIRQ();
}
}
}
}
if(--periodCounter == 0) {
if(sampleValid) {
s32 delta = (((sample >> bitCounter) & 1) << 2) - 2;
@@ -52,6 +27,9 @@ auto APU::DMC::clock() -> n8 {
sampleValid = true;
sample = dmaBuffer;
dmaBufferValid = false;
if (lengthCounter > 0)
cpu.dmcDMAPending();
} else {
sampleValid = false;
}
@@ -60,10 +38,8 @@ auto APU::DMC::clock() -> n8 {
periodCounter = Region::PAL() ? dmcPeriodTablePAL[period] : dmcPeriodTableNTSC[period];
}
if(lengthCounter > 0 && !dmaBufferValid && dmaDelayCounter == 0) {
cpu.rdyLine(0);
dmaDelayCounter = 4;
}
if (dmaDelayCounter > 0 && --dmaDelayCounter == 0)
cpu.dmcDMAPending();
return result;
}
@@ -71,8 +47,7 @@ auto APU::DMC::clock() -> n8 {
auto APU::DMC::power(bool reset) -> void {
lengthCounter = 0;
periodCounter = Region::PAL() ? dmcPeriodTablePAL[0] : dmcPeriodTableNTSC[0];
dmaDelayCounter = 0;
irqPending = 0;
irqPending = false;
period = 0;
irqEnable = 0;
loopMode = 0;
@@ -86,3 +61,20 @@ auto APU::DMC::power(bool reset) -> void {
sampleValid = 0;
sample = 0;
}
auto APU::DMC::setDMABuffer(n8 data) -> void {
dmaBuffer = data;
dmaBufferValid = true;
lengthCounter--;
readAddress++;
if (lengthCounter == 0) {
if (loopMode) {
readAddress = 0x4000 + (addressLatch << 6);
lengthCounter = (lengthLatch << 4) + 1;
} else if (irqEnable) {
irqPending = true;
apu.setIRQ();
}
}
}
+2 -2
View File
@@ -59,8 +59,8 @@ auto APU::FrameCounter::power(bool reset) -> void {
counter = getPeriod();
odd = true;
delay = true;
delayCounter = 1;
delay = false;
delayCounter = 0;
}
auto APU::FrameCounter::write(n8 data) -> void {
+1 -1
View File
@@ -70,7 +70,6 @@ auto APU::Noise::serialize(serializer& s) -> void {
auto APU::DMC::serialize(serializer& s) -> void {
s(lengthCounter);
s(periodCounter);
s(dmaDelayCounter);
s(irqPending);
s(period);
s(irqEnable);
@@ -84,6 +83,7 @@ auto APU::DMC::serialize(serializer& s) -> void {
s(dmaBuffer);
s(sampleValid);
s(sample);
s(dmaDelayCounter);
}
auto APU::FrameCounter::serialize(serializer& s) -> void {
+15
View File
@@ -8,6 +8,7 @@ namespace Board {
#include "bandai-karaoke.cpp"
#include "bandai-lz93d50.cpp"
#include "bandai-oeka.cpp"
#include "camerica-bf909x.cpp"
#include "colordreams-74x377.cpp"
#include "gtrom.cpp"
#include "jaleco-jf05.cpp"
@@ -54,8 +55,14 @@ namespace Board {
#include "taito-tc0690.cpp"
#include "taito-x1-005.cpp"
#include "taito-x1-017.cpp"
#include "tengen-80003x.cpp"
#include "unrom-512.cpp"
#include "unl-bmc.cpp"
#include "unl-sachen-74ls374n.cpp"
#include "unl-sachen-sa0037.cpp"
#include "unl-txc.cpp"
auto Interface::create(string board) -> Interface* {
Interface* p = nullptr;
if(!p) p = Action53::create(board);
@@ -66,6 +73,7 @@ auto Interface::create(string board) -> Interface* {
if(!p) p = BandaiKaraoke::create(board);
if(!p) p = BandaiLZ93D50::create(board);
if(!p) p = BandaiOeka::create(board);
if(!p) p = Camerica_BF909x::create(board);
if(!p) p = ColorDreams_74x377::create(board);
if(!p) p = GTROM::create(board);
if(!p) p = HVC_AxROM::create(board);
@@ -112,7 +120,14 @@ auto Interface::create(string board) -> Interface* {
if(!p) p = TaitoTC0690::create(board);
if(!p) p = TaitoX1005::create(board);
if(!p) p = TaitoX1017::create(board);
if(!p) p = Tengen80003x::create(board);
if(!p) p = UNROM512::create(board);
if(!p) p = BMC::create(board);
if(!p) p = Sachen74LS374N::create(board);
if(!p) p = SachenSA0037::create(board);
if(!p) p = TXC::create(board);
if(!p) p = new Interface;
return p;
}
+4
View File
@@ -1,4 +1,6 @@
namespace Board {
#include "ic/jv001.hpp"
#include "ic/txc05-00002-010.hpp"
struct Interface {
VFS::Pak pak;
@@ -24,6 +26,8 @@ struct Interface {
virtual auto power() -> void {}
virtual auto ppuAddressBus(n14 address) -> void {}
virtual auto serialize(serializer&) -> void {}
protected:
@@ -0,0 +1,99 @@
struct Camerica_BF909x : Interface {
static auto create(string id) -> Interface* {
if(id == "CAMERICA-BF9093" ) return new Camerica_BF909x(Revision::CAMERICA_BF9093);
if(id == "CAMERICA-BF9096" ) return new Camerica_BF909x(Revision::CAMERICA_BF9096);
if(id == "CAMERICA-BF9096A") return new Camerica_BF909x(Revision::CAMERICA_BF9096A);
if(id == "CAMERICA-BF9097" ) return new Camerica_BF909x(Revision::CAMERICA_BF9097);
return nullptr;
}
Memory::Readable<n8> programROM;
Memory::Writable<n8> characterRAM;
enum class Revision : u32 {
CAMERICA_BF9093,
CAMERICA_BF9096,
CAMERICA_BF9096A,
CAMERICA_BF9097,
} revision;
Camerica_BF909x(Revision revision) : revision(revision) {}
auto load() -> void override {
Interface::load(programROM, "program.rom");
Interface::load(characterRAM, "character.ram");
mirror = pak->attribute("mirror") == "vertical";
}
auto save() -> void override {
Interface::save(characterRAM, "character.ram");
}
auto readPRG(n32 address, n8 data) -> n8 override {
if(address < 0x8000) return data;
n4 bank;
if(address < 0xC000) {
bank = programBank;
} else {
bank = 0x0f;
}
if(revision == Revision::CAMERICA_BF9096 || revision == Revision::CAMERICA_BF9096A) {
bank.bit(2,3) = programOuterBank;
}
return programROM.read(bank << 14 | (n14)address);
}
auto writePRG(n32 address, n8 data) -> void override {
if(address < 0x8000) return;
if(address < 0xC000) {
if(revision == Revision::CAMERICA_BF9096) {
programOuterBank = data.bit(3,4);
} else if(revision == Revision::CAMERICA_BF9096A) {
programOuterBank.bit(0) = data.bit(4);
programOuterBank.bit(1) = data.bit(3);
} else if(address < 0xA000 && revision == Revision::CAMERICA_BF9097) {
characterBank = data.bit(4);
}
} else {
programBank = data.bit(0,3);
}
}
auto addressCIRAM(n32 address) const -> n32 {
if(revision == Revision::CAMERICA_BF9097) {
return characterBank << 10 | (n10)address;
} else {
return address >> !mirror & 0x0400 | (n10)address;
}
}
auto readCHR(n32 address, n8 data) -> n8 override {
if(address & 0x2000) {
return ppu.readCIRAM(addressCIRAM(address));
}
return characterRAM.read((n13)address);
}
auto writeCHR(n32 address, n8 data) -> void override {
if(address & 0x2000) {
return ppu.writeCIRAM(addressCIRAM(address), data);
}
return characterRAM.write((n13)address, data);
}
auto power() -> void override {
}
auto serialize(serializer& s) -> void override {
s(characterRAM);
s(mirror);
s(programBank);
s(programOuterBank);
s(characterBank);
}
n1 mirror; //0 = horizontal, 1 = vertical
n4 programBank;
n2 programOuterBank;
n1 characterBank;
};
+10 -2
View File
@@ -7,6 +7,7 @@ struct HVC_CNROM : Interface {
}
Memory::Readable<n8> programROM;
Memory::Writable<n8> programRAM;
Memory::Readable<n8> characterROM;
Memory::Writable<n8> characterRAM;
@@ -20,6 +21,7 @@ struct HVC_CNROM : Interface {
auto load() -> void override {
Interface::load(programROM, "program.rom");
Interface::load(programRAM, "save.ram");
Interface::load(characterROM, "character.rom");
Interface::load(characterRAM, "character.ram");
mirror = pak->attribute("mirror") == "vertical";
@@ -27,16 +29,21 @@ struct HVC_CNROM : Interface {
}
auto save() -> void override {
Interface::save(programRAM, "save.ram");
Interface::save(characterRAM, "character.ram");
}
auto readPRG(n32 address, n8 data) -> n8 override {
if(address < 0x8000) return data;
if(address < 0x6000) return data;
if(address < 0x8000 && !programRAM) return data;
if(address < 0x8000) return programRAM.read(address);
return programROM.read((n15)address);
}
auto writePRG(n32 address, n8 data) -> void override {
if(address < 0x8000) return;
if(address < 0x6000) return;
if(address < 0x8000 && !programRAM) return;
if(address < 0x8000) return programRAM.write(address, data);
characterBank = data & programROM.read((n15)address);
characterEnable = (data == key);
}
@@ -70,6 +77,7 @@ struct HVC_CNROM : Interface {
}
auto serialize(serializer& s) -> void override {
s(programRAM);
s(characterRAM);
s(mirror);
s(key);
+1
View File
@@ -59,6 +59,7 @@ struct HVC_NROM : Interface {
}
auto serialize(serializer& s) -> void override {
s(programRAM);
s(characterRAM);
s(mirror);
}
+29 -18
View File
@@ -17,6 +17,7 @@ struct HVC_TxROM : Interface { //MMC3
if(id == "HVC-TVROM" ) return new HVC_TxROM(Revision::TVROM);
if(id == "NES-QJ" ) return new HVC_TxROM(Revision::NESQJ);
if(id == "PAL-ZZ" ) return new HVC_TxROM(Revision::PALZZ);
if(id == "MC-ACC" ) return new HVC_TxROM(Revision::MCACC);
return nullptr;
}
@@ -43,6 +44,7 @@ struct HVC_TxROM : Interface { //MMC3
TVROM,
NESQJ,
PALZZ,
MCACC,
} revision;
HVC_TxROM(Revision revision) : revision(revision) {}
@@ -65,21 +67,6 @@ struct HVC_TxROM : Interface { //MMC3
tick();
}
auto irqTest(n16 address) -> void {
if(!(characterAddress & 0x1000) && (address & 0x1000)) {
if(irqDelay == 0) {
if(irqCounter == 0) {
irqCounter = irqLatch + 1;
}
if(--irqCounter == 0) {
if(irqEnable) irqLine = 1;
}
}
irqDelay = 6;
}
characterAddress = address;
}
auto readPRG(n32 address, n8 data) -> n8 override {
if(address < 0x6000) return data;
@@ -108,7 +95,6 @@ struct HVC_TxROM : Interface { //MMC3
}
auto writePRG(n32 address, n8 data) -> void override {
if(address == 0x2006 && ++characterLatch) irqTest(data << 8);
if(address < 0x6000) return;
if(address < 0x8000) {
@@ -149,6 +135,7 @@ struct HVC_TxROM : Interface { //MMC3
break;
case 0xc001:
irqCounter = 0;
mcAccPulseCounter = 0;
break;
case 0xe000:
irqEnable = 0;
@@ -197,7 +184,6 @@ struct HVC_TxROM : Interface { //MMC3
}
auto readCHR(n32 address, n8 data) -> n8 override {
irqTest(address);
if(revision == Revision::TVROM) {
if(address < 0x2000) return characterROM.read(addressCHR(address));
address.bit(12) = 0;
@@ -223,7 +209,6 @@ struct HVC_TxROM : Interface { //MMC3
}
auto writeCHR(n32 address, n8 data) -> void override {
irqTest(address);
if(revision == Revision::TVROM) {
if(address < 0x2000) return;
address.bit(12) = 0;
@@ -245,6 +230,29 @@ struct HVC_TxROM : Interface { //MMC3
ramWritable = 1;
}
auto ppuAddressBus(n14 address) -> void override {
if (!(characterAddress & 0x1000) && (address & 0x1000)) {
bool clocking = false;
if (revision == Revision::MCACC) {
clocking = ++mcAccPulseCounter == 1;
} else {
clocking = irqDelay == 0;
irqDelay = 6;
}
if (clocking) {
if (irqCounter == 0)
irqCounter = irqLatch + 1;
if (--irqCounter == 0) {
if (irqEnable) irqLine = 1;
}
}
}
characterAddress = address;
}
auto serialize(serializer& s) -> void override {
s(programRAM);
s(characterRAM);
@@ -264,6 +272,8 @@ struct HVC_TxROM : Interface { //MMC3
s(irqLine);
s(characterLatch);
s(characterAddress);
if (revision == Revision::MCACC)
s(mcAccPulseCounter);
}
n1 characterMode;
@@ -282,4 +292,5 @@ struct HVC_TxROM : Interface { //MMC3
n1 irqLine;
n1 characterLatch;
n16 characterAddress;
n3 mcAccPulseCounter;
};
+10 -2
View File
@@ -8,6 +8,7 @@ struct HVC_UxROM : Interface {
}
Memory::Readable<n8> programROM;
Memory::Writable<n8> programRAM;
Memory::Readable<n8> characterROM;
Memory::Writable<n8> characterRAM;
@@ -22,17 +23,21 @@ struct HVC_UxROM : Interface {
auto load() -> void override {
Interface::load(programROM, "program.rom");
Interface::load(programRAM, "save.ram");
Interface::load(characterROM, "character.rom");
Interface::load(characterRAM, "character.ram");
mirror = pak->attribute("mirror") == "vertical";
}
auto save() -> void override {
Interface::save(programRAM, "save.ram");
Interface::save(characterRAM, "character.ram");
}
auto readPRG(n32 address, n8 data) -> n8 override {
if(address < 0x8000) return data;
if(address < 0x6000) return data;
if(address < 0x8000 && !programRAM) return data;
if(address < 0x8000) return programRAM.read(address);
n8 bank;
switch(address >> 14 & 1) {
case 0: bank = (revision == Revision::UNROMA ? (n8)0x00 : programBank); break;
@@ -42,7 +47,9 @@ struct HVC_UxROM : Interface {
}
auto writePRG(n32 address, n8 data) -> void override {
if(address < 0x8000) return;
if(address < 0x6000) return;
if(address < 0x8000 && !programRAM) return;
if(address < 0x8000) return programRAM.write(address, data);
programBank = data;
if(revision == Revision::UN1ROM) programBank >>= 2;
}
@@ -69,6 +76,7 @@ struct HVC_UxROM : Interface {
}
auto serialize(serializer& s) -> void override {
s(programRAM);
s(characterRAM);
s(mirror);
s(programBank);
+55
View File
@@ -0,0 +1,55 @@
#pragma once
// JV001: 136/172 136 172
// .--\/--. | .--\/--. | .--\/--.
// PPU A13 -> |01 28| -- GND | PPU A13 -> |01 28| -- GND | PPU A13 -> |01 28| -- GND
// CPU D5 <> |02 27| <- PPU R/W | CPU D5 <> |02 27| <- NC | CPU D0 <> |02 27| <- PPU R/W
// CPU D4 <> |03 26| -> Invert | CPU D4 <> |03 26| -> NC | CPU D1 <> |03 26| -> CIRAM A10
// CPU D3 <> |04 25| <- PPU A11 | CPU D3 <> |04 25| <- NC | CPU D2 <> |04 25| <- PPU A11
// CPU D2 <> |05 24| <- PPU A10 | CPU D2 <> |05 24| <- NC | CPU D3 <> |05 24| <- PPU A10
// CPU D1 <> |06 23| -> O0 | CPU D1 <> |06 23| -> NC | CPU D4 <> |06 23| -> CHR A13
// CPU D0 <> |07 22| -> O1 | CPU D0 <> |07 22| -> NC | CPU D5 <> |07 22| -> CHR A14
// CPU A0 -> |08 21| -> O2 | CPU A0 -> |08 21| -> NC | CPU A0 -> |08 21| -> NC
// CPU A1 -> |09 20| -> O3 | CPU A1 -> |09 20| -> NC | CPU A1 -> |09 20| -> NC
// CPU A8 -> |10 19| -> O4 | CPU A8 -> |10 19| -> NC | CPU A8 -> |10 19| -> NC
// M2 -> |11 18| -> O5 | M2 -> |11 18| -> NC | M2 -> |11 18| -> NC
// /ROMSEL -> |12 17| <- CHR /OE | /ROMSEL -> |12 17| <- CHR /OE | /ROMSEL -> |12 17| <- CHR /OE
// CPU R/W -> |13 16| <- CPU A13 | CPU R/W -> |13 16| <- NC | CPU R/W -> |13 16| <- CPU A13
// 5V -- |14 15| <- CPU A14 | 5V -- |14 15| <- NC | 5V -- |14 15| <- CPU A14
// '------' | '------' | '------'
struct JV001 {
auto writePRG(n16 address, n8 data) -> void {
address &= 0xe103;
switch (address) {
case 0x4100: if (increment) {
++reg.bit(0,3);
} else {
reg.bit(0,3) = in ^ (invert ? 0x0f : 0);
}
return;
case 0x4101: invert = data.bit(0);
return;
case 0x4102: reg.bit(4,5) = data.bit(4,5);
in = data.bit(0,3);
return;
case 0x4103: increment = data.bit(0);
return;
default: out.bit(0,3) = reg.bit(0,3);
out.bit(4,5) = reg.bit(4,5) ^ (invert ? 0x03 : 0);
return;
}
}
auto serialize(serializer& s) -> void {
s(reg);
s(invert);
s(in);
s(increment);
s(out);
}
n6 reg;
n1 invert;
n4 in;
n1 increment;
n6 out;
};
@@ -0,0 +1,91 @@
#pragma once
// TXC 05-00002-010
// .--\/--.
// Q2 <- |01 24| -> Q3
// Q1 <- |02 23| -> Q4
// Q0 <- |03 22| -> o3
// i1 -> |04 21| <- CPU A13 (rn)
// i0 -> |05 20| <- CPU A14 (rn)
// io2 <> |06 19| -- GND
// 5V -- |07 18| <- CPU R/W (n)
// D5 <> |08 17| <- /ROMSEL (rn)
// D4 <> |09 16| <- M2 (n)
// D2 <> |10 15| <- CPU A8 (rn)
// D1 <> |11 14| <- CPU A1 (rn)
// D0 <> |12 13| <- CPU A0 (rn)
// '------'
// 36 132 173
// .--\/--. .--\/--. .--\/--.
// NC <- |01 24| -> NC (r) PRG A15 <- |01 24| -> NC NC <- |01 24| -> NC
// (r) PRG A16 <- |02 23| -> NC (r) CHR A14 <- |02 23| -> NC *(r) CHR A15 <- |02 23| -> NC
// (r) PRG A15 <- |03 22| -> NC (r) CHR A13 <- |03 22| -> NC (r) CHR A13 <- |03 22| -> CHR A14
// GND -> |04 21| <- CPU A13 (rn) GND -> |04 21| <- CPU A13 (fr) GND -> |04 21| <- CPU A13 (fr)
// 5V -> |05 20| <- CPU A14 (rn) 5V -> |05 20| <- CPU A14 (fr) 5V -> |05 20| <- CPU A14 (fr)
// NC <> |06 19| -- GND NC <> |06 19| -- GND NC <> |06 19| <- GND
// 5V -- |07 18| <- CPU R/W (n) 5V -- |07 18| <- CPU R/W (f) 5V -- |07 18| <- CPU R/W (f)
// NC <> |08 17| <- /ROMSEL (rn) GND <> |08 17| <- /ROMSEL (fr) GND <> |08 17| <- /ROMSEL (fr)
// NC <> |09 16| <- M2 (n) (fr) CPU D3 <> |09 16| <- M2 (f) (fr) CPU D3 <> |09 16| <- M2 (f)
// NC <> |10 15| <- CPU A8 (rn) (fr) CPU D2 <> |10 15| <- CPU A8 (fr) (fr) CPU D2 <> |10 15| <- CPU A8 (fr)
// (rn) CPU D5 <> |11 14| <- CPU A1 (rn) (fr) CPU D1 <> |11 14| <- CPU A1 (fr) (fr) CPU D1 <> |11 14| <- CPU A1 (fr)
// (rn) CPU D4 <> |12 13| <- CPU A0 (rn) (fr) CPU D0 <> |12 13| <- CPU A0 (fr) (fr) CPU D0 <> |12 13| <- CPU A0 (fr)
// '------'` '------' '------'
// 173*: TXC pin 2 was routed to CHR ROM pin 1 on a 28-pin package.
// On a UVEPROM, this is A15.
// However, no games were ever released using more than 32 KiB of CHR.
// TXC 05-00002-010: 36/132/173
struct TXC05_00002_010 {
auto writePRG(n16 address, n8 data) -> void {
address &= 0xe103;
switch (address) {
case 0x4100: if (increment) {
++reg.bit(0,3);
} else {
reg.bit(0,3) = in ^ (invert ? 0x0f : 0);
}
return;
case 0x4101: invert = data.bit(0);
if (overdown) {
o3 = (invert ? io2 : i0) | data.bit(5);
} else {
io2 = invert ? i1 : i0;
o3 = io2 | data.bit(5);
}
return;
case 0x4102: reg.bit(4,5) = data.bit(4,5);
in.bit(0,2) = data.bit(0,2);
in.bit(3) = in.bit(3) ^ invert;
return;
case 0x4103: increment = data.bit(0);
return;
default: out.bit(0,3) = reg.bit(0,3);
out.bit(4) = reg.bit(4) ^ invert;
return;
}
}
auto serialize(serializer& s) -> void {
s(i0);
s(i1);
s(io2);
s(o3);
s(increment);
s(invert);
s(overdown);
s(reg);
s(in);
s(out);
}
bool overdown; // io2 is using input or output flag
// 4 pin
n1 i0, i1, io2, o3;
n1 increment;
n1 invert;
n6 reg;
n4 in;
n5 out;
};
+1
View File
@@ -65,6 +65,7 @@ struct Sunsoft1 : Interface {
}
auto serialize(serializer& s) -> void override {
s(characterRAM);
s(characterBank);
}
+1
View File
@@ -61,6 +61,7 @@ struct Sunsoft2 : Interface {
}
auto serialize(serializer& s) -> void override {
s(characterRAM);
s(programBank);
s(characterBank);
s(mirror);
+2
View File
@@ -105,6 +105,8 @@ struct Sunsoft3 : Interface {
}
auto serialize(serializer& s) -> void override {
s(programRAM);
s(characterRAM);
s(programBank);
s(characterBank);
s(mirror);
+204
View File
@@ -0,0 +1,204 @@
struct Tengen80003x : Interface { //RAMBO-1
static auto create(string id) -> Interface* {
if(id == "TENGEN-800032") return new Tengen80003x(Revision::TENGEN_800032);
if(id == "TENGEN-800037") return new Tengen80003x(Revision::TENGEN_800037);
return nullptr;
}
Memory::Readable<n8> programROM;
Memory::Readable<n8> characterROM;
enum class Revision : u32 {
TENGEN_800032,
TENGEN_800037,
} revision;
Tengen80003x(Revision revision) : revision(revision) {}
auto load() -> void override {
Interface::load(programROM, "program.rom");
Interface::load(characterROM, "character.rom");
}
auto save() -> void override {
}
auto main() -> void override {
if(irqDelay) irqDelay--;
if(irqLineDelay && --irqLineDelay == 0) irqLine = 1;
cpu.irqLine(irqLine);
if(++irqCycleCounter == 0) {
if(irqCycleMode) irqTest(1);
}
tick();
}
auto irqTest(n8 delay) -> void {
if(irqCounter == 0) {
irqCounter = irqLatch + 1;
}
if(--irqCounter == 0) {
if(irqEnable) irqLineDelay = delay;
}
}
auto readPRG(n32 address, n8 data) -> n8 override {
if(address < 0x8000) return data;
n5 bank;
switch(address >> 13 & 3) {
case 0: bank = programBank[programMode == 0 ? 0 : 2]; break;
case 1: bank = programBank[1]; break;
case 2: bank = programBank[programMode == 0 ? 2 : 0]; break;
case 3: bank = 0x1f; break;
}
address = bank << 13 | (n13)address;
return programROM.read(address);
}
auto writePRG(n32 address, n8 data) -> void override {
if(address < 0x8000) return;
switch(address & 0xe001) {
case 0x8000:
bankSelect = data.bit(0,3);
characterMode = data.bit(5);
programMode = data.bit(6);
characterInvert = data.bit(7);
break;
case 0x8001:
switch(bankSelect) {
case 0: characterBank[0] = data; break;
case 1: characterBank[1] = data; break;
case 2: characterBank[2] = data; break;
case 3: characterBank[3] = data; break;
case 4: characterBank[4] = data; break;
case 5: characterBank[5] = data; break;
case 6: programBank[0] = data; break;
case 7: programBank[1] = data; break;
case 8: characterBank[6] = data; break;
case 9: characterBank[7] = data; break;
case 15: programBank[2] = data; break;
}
break;
case 0xa000:
mirror = data.bit(0);
break;
case 0xc000:
irqLatch = data;
break;
case 0xc001:
irqCounter = 0;
irqCycleCounter = 0;
irqCycleMode = data.bit(0);
break;
case 0xe000:
irqEnable = 0;
irqLine = 0;
break;
case 0xe001:
irqEnable = 1;
break;
}
}
auto addressCHR(n32 address) const -> n32 {
address.bit(12) ^= characterInvert;
if(characterMode == 0) {
if(address <= 0x07ff) return (characterBank[0] & ~1) << 10 | (n11)address;
if(address <= 0x0fff) return (characterBank[1] & ~1) << 10 | (n11)address;
} else {
if(address <= 0x03ff) return characterBank[0] << 10 | (n10)address;
if(address <= 0x07ff) return characterBank[6] << 10 | (n10)address;
if(address <= 0x0bff) return characterBank[1] << 10 | (n10)address;
if(address <= 0x0fff) return characterBank[7] << 10 | (n10)address;
}
if(address <= 0x13ff) return characterBank[2] << 10 | (n10)address;
if(address <= 0x17ff) return characterBank[3] << 10 | (n10)address;
if(address <= 0x1bff) return characterBank[4] << 10 | (n10)address;
if(address <= 0x1fff) return characterBank[5] << 10 | (n10)address;
unreachable;
}
auto addressCIRAM(n32 address) const -> n32 {
if(revision == Revision::TENGEN_800037) {
address.bit(12) = characterInvert;
if(characterMode == 0) {
if(address <= 0x27ff) return characterBank[0].bit(7) << 10 | (n10)address;
if(address <= 0x2fff) return characterBank[1].bit(7) << 10 | (n10)address;
} else {
if(address <= 0x23ff) return characterBank[0].bit(7) << 10 | (n10)address;
if(address <= 0x27ff) return characterBank[6].bit(7) << 10 | (n10)address;
if(address <= 0x2bff) return characterBank[1].bit(7) << 10 | (n10)address;
if(address <= 0x2fff) return characterBank[7].bit(7) << 10 | (n10)address;
}
if(address <= 0x33ff) return characterBank[2].bit(7) << 10 | (n10)address;
if(address <= 0x37ff) return characterBank[3].bit(7) << 10 | (n10)address;
if(address <= 0x3bff) return characterBank[4].bit(7) << 10 | (n10)address;
if(address <= 0x3fff) return characterBank[5].bit(7) << 10 | (n10)address;
unreachable;
}
return address >> mirror & 0x0400 | (n10)address;
}
auto readCHR(n32 address, n8 data) -> n8 override {
if(address & 0x2000) return ppu.readCIRAM(addressCIRAM(address));
return characterROM.read(addressCHR(address));
}
auto writeCHR(n32 address, n8 data) -> void override {
if(address & 0x2000) return ppu.writeCIRAM(addressCIRAM(address), data);
}
auto power() -> void override {
}
auto ppuAddressBus(n14 address) -> void override {
if(!(characterAddress & 0x1000) && (address & 0x1000)) {
if(irqDelay == 0) {
if(!irqCycleMode) irqTest(3);
}
irqDelay = 6;
}
characterAddress = address;
}
auto serialize(serializer& s) -> void override {
s(characterMode);
s(characterInvert);
s(programMode);
s(bankSelect);
s(programBank);
s(characterBank);
s(mirror);
s(irqLatch);
s(irqCounter);
s(irqEnable);
s(irqDelay);
s(irqLineDelay);
s(irqLine);
s(irqCycleMode);
s(irqCycleCounter);
s(characterAddress);
}
n1 characterMode;
n1 characterInvert;
n1 programMode;
n4 bankSelect;
n5 programBank[3];
n8 characterBank[8];
n1 mirror;
n8 irqLatch;
n8 irqCounter;
n1 irqEnable;
n8 irqDelay;
n8 irqLineDelay;
n1 irqLine;
n1 irqCycleMode;
n2 irqCycleCounter;
n16 characterAddress;
};
+104
View File
@@ -0,0 +1,104 @@
struct BMC : Interface {
static auto create(string id) -> Interface* {
if (id == "UNL-BMC-32") return new BMC(Revision::BMC_32);
if (id == "UNL-BMC-128") return new BMC(Revision::BMC_128);
return nullptr;
}
Memory::Readable<n8> programROM;
Memory::Readable<n8> characterROM;
enum class Revision : u32 {
BMC_32, // 229: max 32 * 16KB PRG-ROM, 32 * 8KB CHR-ROM
BMC_128, // 225/255: max 128 * 16KB PRG-ROM, 128 * 8KB CHR-ROM
} revision;
BMC(Revision revision) : revision(revision) {}
auto load() -> void override {
Interface::load(programROM, "program.rom");
Interface::load(characterROM, "character.rom");
}
auto readPRG(n32 address, n8 data) -> n8 override {
if (address >= 0x5800 && address < 0x6000 && revision == Revision::BMC_128) {
return regs[address & 3];
}
if (address < 0x8000) return data;
if (mode == 1)
address = prgBank << 15 | (n15)address;
else
address = prgBank << 14 | (n14)address;
return programROM.read(address);
}
auto writePRG(n32 address, n8 data) -> void override {
if (address >= 0x5800 && address < 0x6000 && revision == Revision::BMC_128) {
regs[address & 3] = data;
return;
}
if (address < 0x8000) return;
update(address);
}
auto readCHR(n32 address, n8 data) -> n8 override {
if (address & 0x2000) {
address = (address >> mirror & 0x0400) | (n10)address;
return ppu.readCIRAM(address);
}
return characterROM.read(chrBank << 13 | (n13)address);
}
auto writeCHR(n32 address, n8 data) -> void override {
if (address & 0x2000) {
address = (address >> mirror & 0x0400) | (n10)address;
return ppu.writeCIRAM(address, data);
}
}
auto power() -> void override {
update(0x8000);
if (revision == Revision::BMC_128)
for (auto& reg : regs) reg = random();
}
auto serialize(serializer& s) -> void override {
s(latch);
update(latch);
if (revision == Revision::BMC_128) s(regs);
}
auto update(n16 address) -> void {
latch = address;
if (revision == Revision::BMC_32) {
mode = address.bit(1, 4) == 0;
chrBank = address.bit(0, 4);
prgBank = address.bit(0, 4);
mirror = address.bit(5);
} else {
mirror = latch.bit(13);
mode = latch.bit(12) == 0;
chrBank = latch.bit(0, 5) | latch.bit(14) << 6;
prgBank = latch.bit(6, 11) | latch.bit(14) << 6;
}
if (mode == 1)
prgBank >>= 1;
}
n16 latch;
n1 mode;
n1 mirror;
n7 chrBank;
n7 prgBank;
n4 regs[4];
};
@@ -0,0 +1,173 @@
/// 74LS374N SA-020 SA-015
/// .---V---. .---V---. .---V---.
/// R5.0 <- | 01 20 | -- Vcc PRG A15 <- | 01 20 | -- Vcc PRG A15 <- | 01 20 | -- Vcc
/// CIRAM A10 <- | 02 19 | <- CPU A8 CIRAM A10 <- | 02 19 | <- CPU A8 CIRAM A10 <- | 02 19 | <- CPU A8
/// PPU A11 -> | 03 18 | <- R/W PPU A11 -> | 03 18 | <- R/W PPU A11 -> | 03 18 | <- R/W
/// R5.1 <- | 04 17 | <- M2 PRG A16 <- | 04 17 | <- M2 PRG A16 <- | 04 17 | <- M2
/// CPU A14 -> | 05 16 | <- PPU A10 CPU A14 -> | 05 16 | <- PPU A10 CPU A14 -> | 05 16 | <- PPU A10
/// CPU A0 -> | 06 15 | <- /ROMSEL CPU A0 -> | 06 15 | <- /ROMSEL CPU A0 -> | 06 15 | <- /ROMSEL
/// CPU D0 <> | 07 14 | <> CPU D2 CPU D0 <> | 07 14 | <> CPU D2 CPU D0 <> | 07 14 | <> CPU D2 or Vcc, depending on solder pad setting
/// CPU D1 <> | 08 13 | -> R6.1 CPU D1 <> | 08 13 | -> CHR A14 CPU D1 <> | 08 13 | -> CHR A14
/// R2.0 <- | 09 12 | -> R6.0 CHR A16 <- | 09 12 | -> CHR A13 N/C <- | 09 12 | -> CHR A13
/// GND -- | 10 11 | -> R4.0 GND -- | 10 11 | -> CHR A15 GND -- | 10 11 | -> CHR A15
/// '-------' '-------' '-------'
///
/// SA-020A:
/// CHR A16 A15 A14 A13: R2.0 R4.0 R6.1 R6.0
/// PRG A16 A15: R5.1 R5.0
///
/// SA-015:
/// CHR A15 A14 A13: R4.0 R6.1 R6.0
/// PRG A16 A15: R5.1 R5.0
struct Sachen74LS374N : Interface {
static auto create(string id) -> Interface* {
if (id == "UNL-Sachen-74LS374N") return new Sachen74LS374N(Revision::SACHEN_74LS374N);
if (id == "UNL-Sachen-74LS374NA") return new Sachen74LS374N(Revision::SACHEN_74LS374NA);
return nullptr;
}
Memory::Readable<n8> programROM;
Memory::Readable<n8> characterROM;
// The circuit board has a solder pad that selects
// whether ASIC pin 14 is connected to CPU D2 or to
// Vcc. In the latter setting, the ASIC sees all
// writes as being OR'd with $04, while on reads,
// D2 is open bus. The pad setting only makes a
// difference for the game Shōgi Gakuen, which
// writes to R2 and reads from R6 to check whether
// it now holds that written value, as would be
// the case if the solder pad were in the Vcc
// position; depending on the setting, a different
// copyright tag ("Sachen" vs. "Sachen and Hacker
// International") is displayed.
Node::Setting::Boolean solderPad;
enum class Revision : u32 {
SACHEN_74LS374N,
SACHEN_74LS374NA,
} revision;
Sachen74LS374N(Revision revision) : revision(revision) {}
auto load() -> void override {
Interface::load(programROM, "program.rom");
Interface::load(characterROM, "character.rom");
if (revision == Revision::SACHEN_74LS374N) {
solderPad = cartridge.node->append<Node::Setting::Boolean>("Solder Pad", false);
}
}
auto unload() -> void override {
if (revision == Revision::SACHEN_74LS374N) {
solderPad.reset();
}
}
auto readPRG(n32 address, n8 data) -> n8 override {
if (address < 0x4100) return data;
if (address < 0x8000) {
if ((address & 0x4101) == 0x4101)
if (revision == Revision::SACHEN_74LS374N && solderPad->value())
return (data & ~0x07) | regs[select].bit(0, 1) | 0x04;
else
return (data & ~0x07) | regs[select].bit(0, 2);
return data;
}
address = prgBank << 15 | (n15)address;
data = programROM.read(address);
return data;
}
auto writePRG(n32 address, n8 data) -> void override {
if (address < 0x4100) return;
if (address < 0x8000) {
address &= 0x4101;
if (address == 0x4100) {
select = data.bit(0, 2);
} else {
if (revision == Revision::SACHEN_74LS374N && solderPad->value()) {
regs[select] = data.bit(0, 1) | 0x04;
} else {
regs[select] = data.bit(0, 2);
}
regs[select] = data.bit(0, 2);
update();
return;
}
}
}
auto readCHR(n32 address, n8 data) -> n8 override {
if (address & 0x2000) return ppu.readCIRAM(addressCIRAM(address));
return characterROM.read(chrBank << 13 | (n13)address);
}
auto writeCHR(n32 address, n8 data) -> void override {
if (address & 0x2000) return ppu.writeCIRAM(addressCIRAM(address), data);
}
auto power() -> void override {
for (n8 &reg : regs) reg = 0;
update();
}
auto serialize(serializer& s) -> void override {
s(regs);
s(select);
if (s.reading()) update();
}
auto update() -> void {
if (revision == Revision::SACHEN_74LS374N) {
chrBank = regs[4].bit(0) << 2 | regs[6].bit(0, 1);
} else {
chrBank = regs[2].bit(0) << 3 | regs[4].bit(0) << 2 | regs[6].bit(0, 1);
}
prgBank = regs[5].bit(0,1);
mirror = regs[7].bit(1,2);
}
auto addressCIRAM(n32 address) -> n32 {
switch (mirror) {
case 0:
// nametable is 0 0 0 1
if (address & 0x0c00 != 0x0c00) {
address = (n10)address;
} else {
address = 0x0400 | (n10)address;
}
break;
case 1:
// horizontal
address = (address >> 1 & 0x0400) | (n10)address;
break;
case 2:
// vertical
address = (address >> 0 & 0x0400) | (n10)address;
break;
case 3:
// single screen
address = (n10)address;
break;
}
return address;
}
n8 regs[8];
n3 select;
// 0b00 = 0 0 0 1, 0b01 = horizontal,
// 0b10 = vertical, 0b11 = single screen
n2 mirror;
n2 prgBank;
n4 chrBank;
};
@@ -0,0 +1,63 @@
struct SachenSA0037 : Interface {
static auto create(string id) -> Interface* {
if(id == "TENGEN-800008") return new SachenSA0037(Revision::TENGEN_800008);
if(id == "UNL-SA-0037" ) return new SachenSA0037(Revision::SACHEN_SA0037);
return nullptr;
}
Memory::Readable<n8> programROM;
Memory::Readable<n8> characterROM;
enum class Revision : u32 {
SACHEN_SA0037,
TENGEN_800008,
} revision;
SachenSA0037(Revision revision) : revision(revision) {}
auto load() -> void override {
Interface::load(programROM, "program.rom");
Interface::load(characterROM, "character.rom");
mirror = pak->attribute("mirror") == "vertical";
}
auto save() -> void override {
}
auto readPRG(n32 address, n8 data) -> n8 override {
if(address < 0x8000) return data;
return programROM.read(programBank << 15 | (n15)address);
}
auto writePRG(n32 address, n8 data) -> void override {
if(address < 0x8000) return;
characterBank = data.bit(0,2);
programBank = data.bit(3);
}
auto readCHR(n32 address, n8 data) -> n8 override {
if(address & 0x2000) {
address = address >> !mirror & 0x0400 | (n10)address;
return ppu.readCIRAM(address);
}
address = characterBank << 13 | (n13)address;
return characterROM.read(address);
}
auto writeCHR(n32 address, n8 data) -> void override {
if(address & 0x2000) {
address = address >> !mirror & 0x0400 | (n10)address;
return ppu.writeCIRAM(address, data);
}
}
auto serialize(serializer& s) -> void override {
s(mirror);
s(programBank);
s(characterBank);
}
n1 mirror; //0 = horizontal, 1 = vertical
n1 programBank;
n3 characterBank;
};
+134
View File
@@ -0,0 +1,134 @@
// TXC-22211A: Mapper 132
// TXC-22211B: Mapper 172
struct TXC : Interface {
static auto create(string id) -> Interface*;
enum class Revision : u32 {
TXC_22211A,
TXC_22211B,
TXC_22211C,
} revision;
TXC(Revision revision) : revision(revision) {}
Memory::Readable<n8> programROM;
Memory::Readable<n8> characterROM;
auto load() -> void override {
Interface::load(programROM, "program.rom");
Interface::load(characterROM, "character.rom");
}
};
struct TXC_22211AC : TXC {
TXC_22211AC(Revision revision) : TXC(revision) {}
auto readPRG(n32 address, n8 data) -> n8 override {
if ((address & 0xe100) == 0x4100) {
data &= 0xf0;
data.bit(0,2) = txc.reg.bit(0,2);
data.bit(3) = txc.reg.bit(4);
return data;
}
if (address < 0x8000) return data;
if (revision == Revision::TXC_22211A)
address = txc.out.bit(2) << 15 | (n15)address;
return programROM.read(address);
}
auto writePRG(n32 address, n8 data) -> void override {
if ((address & 0xe100) == 0x4100) {
txc.writePRG(address, data.bit(3) << 4 | data.bit(0,2));
}
if (address < 0x8000) return;
txc.writePRG(address, data.bit(3) << 4 | data.bit(0,2));
}
auto readCHR(n32 address, n8 data) -> n8 override {
if (address & 0x2000) return ppu.readCIRAM((n11)address);
if (revision == Revision::TXC_22211A)
address = txc.out.bit(0,1) << 13 | (n13)address;
else
address = txc.out.bit(1) << 15 | txc.o3 << 14 | txc.out.bit(0) << 13 | (n13)address;
return characterROM.read(address);
}
auto writeCHR(n32 address, n8 data) -> void override {
if (address & 0x2000) return ppu.writeCIRAM((n11)address, data);
}
auto power() -> void override {
txc = {};
txc.overdown = false;
txc.i0 = 1;
txc.i1 = 0;
}
auto serialize(serializer& s) -> void override {
s(txc);
}
TXC05_00002_010 txc;
};
struct TXC_22211B : TXC {
TXC_22211B() : TXC(Revision::TXC_22211B) {}
auto readPRG(n32 address, n8 data) -> n8 override {
if ((address & 0xe100) == 0x4100) {
n8 v = (jv001.reg.bit(4,5) ^ (jv001.invert ? 3 : 0)) << 4;
v |= jv001.reg.bit(0,3);
return data & 0xc0 | bit::reverse(v) >> 2;
}
if (address < 0x8000) return data;
return programROM.read((n15)address);
}
auto writePRG(n32 address, n8 data) -> void override {
if ((address & 0xe100) == 0x4100)
return jv001.writePRG(address, bit::reverse(data) >> 2);
if (address < 0x8000) return;
return jv001.writePRG(address, bit::reverse(data) >> 2);
}
auto readCHR(n32 address, n8 data) -> n8 override {
if (address & 0x2000) {
address = (address >> !jv001.invert & 0x0400) | (n10)address;
return ppu.readCIRAM(address);
}
return characterROM.read(jv001.out.bit(0,1) << 13 | (n13)address);
}
auto writeCHR(n32 address, n8 data) -> void override {
if (address & 0x2000) {
address = (address >> !jv001.invert & 0x0400) | (n10)address;
return ppu.writeCIRAM(address, data);
}
}
auto power() -> void override {
jv001 = {};
}
auto serialize(serializer& s) -> void override {
s(jv001);
}
JV001 jv001;
};
auto TXC::create(string id) -> Interface* {
if (id == "UNL-22211" ) return new TXC_22211AC(Revision::TXC_22211A);
if (id == "TXC-22211A") return new TXC_22211AC(Revision::TXC_22211A);
if (id == "TXC-22211B") return new TXC_22211B();
if (id == "TXC-22211C") return new TXC_22211AC(Revision::TXC_22211C);
return nullptr;
}
+4
View File
@@ -71,6 +71,10 @@ auto Cartridge::writeCHR(n32 address, n8 data) -> void {
return board->writeCHR(address, data);
}
auto Cartridge::ppuAddressBus(n14 address) -> void {
return board->ppuAddressBus(address);
}
auto Cartridge::scanline(n32 y) -> void {
return board->scanline(y);
}
+2
View File
@@ -35,6 +35,8 @@ struct Cartridge : Thread {
auto readCHR(n32 address, n8 data = 0x00) -> n8;
auto writeCHR(n32 address, n8 data) -> void;
auto ppuAddressBus(n14 address) -> void;
//scanline() is for debugging purposes only:
//boards must detect scanline edges on their own
auto scanline(n32 y) -> void;
+1
View File
@@ -4,5 +4,6 @@ namespace ares::Famicom {
#include "port.cpp"
#include "gamepad/gamepad.cpp"
#include "zapper/zapper.cpp"
}
+1
View File
@@ -31,3 +31,4 @@ struct Controller {
#include "port.hpp"
#include "gamepad/gamepad.hpp"
#include "zapper/zapper.hpp"
+2 -1
View File
@@ -11,7 +11,7 @@ auto ControllerPort::load(Node::Object parent) -> void {
port->setHotSwappable(true);
port->setAllocate([&](auto name) { return allocate(name); });
port->setDisconnect([&] { device.reset(); });
port->setSupported({"Gamepad"});
port->setSupported({"Gamepad", "Zapper"});
}
auto ControllerPort::unload() -> void {
@@ -21,6 +21,7 @@ auto ControllerPort::unload() -> void {
auto ControllerPort::allocate(string name) -> Node::Peripheral {
if(name == "Gamepad") device = new Gamepad(port);
if(name == "Zapper") device = new Zapper(port);
if(device) return device->node;
return {};
}
+83
View File
@@ -0,0 +1,83 @@
Zapper::Zapper(Node::Port port) {
node = port->append<Node::Peripheral>("Zapper");
x = node->append<Node::Input::Axis >("X");
y = node->append<Node::Input::Axis >("Y");
trigger = node->append<Node::Input::Button>("Trigger");
sprite = node->append<Node::Video::Sprite>("Crosshair");
sprite->setImage(Resource::Sprite::SuperFamicom::CrosshairGreen);
ppu.screen->attach(sprite);
}
Zapper::~Zapper() {
if(ppu.screen) ppu.screen->detach(sprite);
}
auto Zapper::data() -> n3 {
u32 next = ppu.io.ly * 283 + ppu.io.lx;
n3 result = 0b000;
platform->input(trigger);
if (trigger->value()) result.bit(2) = 1;
if (next < previous) {
platform->input(x); //-n = left, 0 = center, +n = right
platform->input(y); //-n = up, 0 = center, +n = down
if (x->value() != px || y->value() != py) {
px = x->value();
py = y->value();
cx = max(-8, min(256 + 8, px + cx));
cy = max(-8, min(240 + 8, py + cy));
sprite->setPosition(cx, cy);
sprite->setVisible(true);
nx = cx + 8;
ny = cy + 8;
}
}
previous = next;
bool offscreen = nx < 0 || ny < 0 || nx >= 256 || ny >= 240;
if (offscreen) {
result.bit(1) = 1;
return result;
}
u32 *target = ppu.screen->pixels().data();
u32 count = 0;
for(int y = ny - 8; y <= ny + 8; y++) {
if (y < 0) continue;
if (y <= ppu.io.ly - 18) continue;
if (y > ppu.io.ly) break;
for(int x = nx - 8; x <= nx + 8; x++) {
if (x < 0) continue;
if (x >= 256) break;
n32 offset = y * 283 + x;// y * 283 + x + Region::PAL() ? 18 : 16;
n64 color = ppu.color(target[offset]);
f64 brightness = 0;
brightness += ((color >> 32) & 0xffff) * 0.299;
brightness += ((color >> 16) & 0xffff) * 0.587;
brightness += ((color >> 0) & 0xffff) * 0.114;
if (brightness > 0x80)
count++;
}
}
if (count < 0x40)
result.bit(1) = 1;
return result;
}
auto Zapper::latch(n1 data) -> void {
}
auto Zapper::serialize(serializer& s) -> void {
}
+23
View File
@@ -0,0 +1,23 @@
struct Zapper : Controller {
Node::Input::Axis x;
Node::Input::Axis y;
Node::Input::Button trigger;
Node::Video::Sprite sprite;
Zapper(Node::Port);
~Zapper();
auto main() -> void;
auto data() -> n3 override;
auto latch(n1 data) -> void override;
auto serialize(serializer&) -> void override;
private:
i32 cx = 256 / 2; //x-coordinate
i32 cy = 240 / 2; //y-coordinate
i32 px = 0;
i32 py = 0;
u32 nx = 256 / 2;
u32 ny = 240 / 2;
u32 previous = 0;
};
+1
View File
@@ -34,6 +34,7 @@ auto CPU::main() -> void {
auto CPU::step(u32 clocks) -> void {
assert(clocks == rate());
io.oddCycle ^= 1;
Thread::step(clocks);
Thread::synchronize();
}
+5 -7
View File
@@ -49,15 +49,13 @@ struct CPU : MOS6502, Thread {
auto irqPending() -> bool override;
auto nmi(n16& vector) -> void override;
auto oamDMA() -> void;
auto dmcDMAPending() -> void;
auto dma(n16 address) -> void;
auto nmiLine(bool) -> void;
auto irqLine(bool) -> void;
auto apuLine(bool) -> void;
auto rdyLine(bool) -> void;
auto rdyAddress(bool valid, n16 value = 0) -> void;
//protected:
struct IO {
n1 interruptPending;
@@ -65,9 +63,9 @@ struct CPU : MOS6502, Thread {
n1 nmiLine;
n1 irqLine;
n1 apuLine;
n1 rdyLine = 1;
n1 rdyAddressValid;
n16 rdyAddressValue;
n1 oddCycle;
n1 dmcDMAPending;
n1 dmcDummyRead;
n1 oamDMAPending;
n8 oamDMAPage;
n8 openBus;
+3 -3
View File
@@ -7,9 +7,9 @@ auto CPU::serialize(serializer& s) -> void {
s(io.nmiLine);
s(io.irqLine);
s(io.apuLine);
s(io.rdyLine);
s(io.rdyAddressValid);
s(io.rdyAddressValue);
s(io.oddCycle);
s(io.dmcDMAPending);
s(io.dmcDummyRead);
s(io.oamDMAPending);
s(io.oamDMAPage);
s(io.openBus);
+63 -22
View File
@@ -1,13 +1,6 @@
auto CPU::read(n16 address) -> n8 {
if(io.oamDMAPending) {
io.oamDMAPending = 0;
read(address);
oamDMA();
}
while(io.rdyLine == 0) {
io.openBus = readBus(io.rdyAddressValid ? io.rdyAddressValue : address);
step(rate());
if(io.oamDMAPending || io.dmcDMAPending) {
dma(address);
}
io.openBus = readBus(address);
@@ -43,10 +36,67 @@ auto CPU::nmi(n16& vector) -> void {
}
}
auto CPU::oamDMA() -> void {
for(u32 n : range(256)) {
n8 data = read(io.oamDMAPage << 8 | n);
write(0x2004, data);
auto CPU::dmcDMAPending() -> void {
io.dmcDMAPending = 1;
io.dmcDummyRead = 0;
}
auto CPU::dma(n16 address) -> void {
bool oamWriteReady = false;
n8 oamCounter = 0;
bool skipDummyReads = (address == 0x4016 || address == 0x4017);
// halt read
io.openBus = readBus(address);
step(rate());
while (io.dmcDMAPending || io.oamDMAPending) {
if (io.oddCycle) {
// put_cycle
if (io.oamDMAPending && oamWriteReady) {
// oam write
writeBus(0x2004, io.openBus);
step(rate());
oamWriteReady = false;
if (++oamCounter == 0)
io.oamDMAPending = 0;
} else {
// oam (re)alignment cycle
// dmc alignment cycle
io.dmcDummyRead = 1;
if (!skipDummyReads)
io.openBus = readBus(address);
step(rate());
}
} else {
// get_cycle
if (io.dmcDMAPending && io.dmcDummyRead) {
// dmc read
io.openBus = readBus(apu.dmc.dmaAddress());
step(rate());
apu.dmc.setDMABuffer(io.openBus);
io.dmcDMAPending = 0;
} else if (io.oamDMAPending) {
if (io.dmcDMAPending)
io.dmcDummyRead = 1;
// oam read
io.openBus = readBus(io.oamDMAPage << 8 | oamCounter);
step(rate());
oamWriteReady = true;
} else {
io.dmcDummyRead = 1;
// dmc dummy read cycle
if (!skipDummyReads)
io.openBus = readBus(address);
step(rate());
}
}
}
}
@@ -65,12 +115,3 @@ auto CPU::apuLine(bool line) -> void {
//level-sensitive
io.apuLine = line;
}
auto CPU::rdyLine(bool line) -> void {
io.rdyLine = line;
}
auto CPU::rdyAddress(bool valid, n16 value) -> void {
io.rdyAddressValid = valid;
io.rdyAddressValue = value;
}
+9
View File
@@ -25,6 +25,15 @@ auto PPU::Debugger::load(Node::Object parent) -> void {
memory.oam->setWrite([&](u32 address, u8 data) -> void {
ppu.oam[address] = data;
});
memory.soam = parent->append<Node::Debugger::Memory>("PPU SOAM");
memory.soam->setSize(ppu.soam.size());
memory.soam->setRead([&](u32 address) -> u8 {
return ppu.soam[address];
});
memory.soam->setWrite([&](u32 address, u8 data) -> void {
ppu.soam[address] = data;
});
}
auto PPU::Debugger::unload() -> void {
+77 -40
View File
@@ -7,15 +7,17 @@ auto PPU::writeCIRAM(n11 address, n8 data) -> void {
}
auto PPU::readCGRAM(n5 address) -> n8 {
if((address & 0x13) == 0x10) address &= ~0x10;
if((address & 0x3) == 0x0) address &= ~0x10;
n8 data = cgram[address];
if(io.grayscale) data &= 0x30;
return data;
}
auto PPU::writeCGRAM(n5 address, n8 data) -> void {
if((address & 0x13) == 0x10) address &= ~0x10;
cgram[address] = data;
if((address & 0x3) == 0x0)
cgram[address ^ 0x10] = data;
}
auto PPU::readIO(n16 address) -> n8 {
@@ -25,35 +27,47 @@ auto PPU::readIO(n16 address) -> n8 {
//PPUSTATUS
case 2:
result.bit(5) = io.spriteOverflow;
result.bit(5) = sprite.spriteOverflow;
result.bit(6) = io.spriteZeroHit;
result.bit(7) = io.nmiFlag;
io.v.latch = 0;
scroll.latch = 0;
io.nmiHold = 0;
cpu.nmiLine(io.nmiFlag = 0);
break;
//OAMDATA
case 4:
result = oam[io.oamAddress];
result = oam[sprite.oamAddress];
if (io.ly < 240 || io.ly == vlines() - 1 ||
(Region::PAL() && io.ly >= 264 && io.ly <= vlines() - 2))
if (enable())
result = sprite.oamData;
break;
//PPUDATA
case 7:
if(enable() && (io.ly < 240 || io.ly == vlines() - 1)) break;
address = (n14)io.v.address;
if(address <= 0x1fff) {
result = io.busData;
io.busData = cartridge.readCHR(address);
} else if(address <= 0x3eff) {
result = io.busData;
io.busData = cartridge.readCHR(address);
} else if(address <= 0x3fff) {
result.bit(0, 5) = readCGRAM(address);
io.busData = cartridge.readCHR(address);
if (var.blockingRead) {
result = io.mdr;
break;
}
io.v.address += io.vramIncrement;
address = io.busAddress;
result = var.latchData;
var.latchData = cartridge.readCHR(address);
if (address >= 0x3f00)
result = readCGRAM(address) | (io.mdr & 0xc0);
if (rendering()) {
incrementVRAMAddressX();
incrementVRAMAddressY();
} else {
var.address += io.vramIncrement;
io.busAddress = var.address;
cartridge.ppuAddressBus(io.busAddress);
}
var.blockingRead = 6;
break;
}
@@ -67,7 +81,7 @@ auto PPU::writeIO(n16 address, n8 data) -> void {
//PPUCTRL
case 0:
io.t.nametable = data.bit(0,1);
scroll.nametable = data.bit(0,1);
io.vramIncrement = data.bit(2) ? 32 : 1;
io.spriteAddress = data.bit(3) ? 0x1000 : 0x0000;
io.bgAddress = data.bit(4) ? 0x1000 : 0x0000;
@@ -93,49 +107,72 @@ auto PPU::writeIO(n16 address, n8 data) -> void {
//OAMADDR
case 3:
io.oamAddress = data;
sprite.oamAddress = data;
break;
//OAMDATA
case 4:
if(io.oamAddress.bit(0,1) == 2) data.bit(2,4) = 0; //clear non-existent bits (always read back as 0)
oam[io.oamAddress++] = data;
// Writes to OAMDATA during rendering (on the pre-render
// line and the visible lines 0-239, provided either
// sprite or background rendering is enabled) do not
// modify values in OAM, but do perform a glitchy
// increment of OAMADDR, bumping only the high 6 bits
if (io.ly < 240 || io.ly == vlines() - 1 ||
(Region::PAL() && io.ly >= 264 && io.ly <= vlines() - 2)) {
if (enable()) {
++sprite.oamMainCounterIndex;
return;
}
}
// The three unimplemented bits of each sprite's byte 2
// do not exist in the PPU and always read back as 0 on
// PPU revisions that allow reading PPU OAM through
// OAMDATA ($2004)
if (sprite.oamMainCounterTiming == 2)
data.bit(2,4) = 0;
oam[sprite.oamAddress] = data;
++sprite.oamMainCounter;
break;
//PPUSCROLL
case 5:
if(io.v.latch++ == 0) {
io.v.fineX = data.bit(0,2);
io.t.tileX = data.bit(3,7);
if(scroll.latch++ == 0) {
scroll.fineX = data.bit(0,2);
scroll.tileX = data.bit(3,7);
} else {
io.t.fineY = data.bit(0,2);
io.t.tileY = data.bit(3,7);
scroll.fineY = data.bit(0,2);
scroll.tileY = data.bit(3,7);
}
break;
//PPUADDR
case 6:
if(io.v.latch++ == 0) {
io.t.addressHi = data.bit(0,5);
if(scroll.latch++ == 0) {
scroll.addressHi = data.bit(0,5);
} else {
io.t.addressLo = data.bit(0,7);
io.v.address = io.t.address;
scroll.addressLo = data.bit(0,7);
scroll.transferDelay = 3;
}
break;
//PPUDATA
case 7:
if(enable() && (io.ly < 240 || io.ly == vlines() - 1)) return;
address = (n14)io.v.address;
if(address <= 0x1fff) {
cartridge.writeCHR(address, data);
} else if(address <= 0x3eff) {
cartridge.writeCHR(address, data);
} else if(address <= 0x3fff) {
address = io.busAddress;
if (address >= 0x3f00)
writeCGRAM(address, data);
else
cartridge.writeCHR(address, data);
if (rendering()) {
incrementVRAMAddressX();
incrementVRAMAddressY();
} else {
var.address += io.vramIncrement;
io.busAddress = var.address;
cartridge.ppuAddressBus(io.busAddress);
}
io.v.address += io.vramIncrement;
break;
}
+29 -7
View File
@@ -7,18 +7,21 @@ PPU ppu;
#include "render.cpp"
#include "color.cpp"
#include "debugger.cpp"
#include "sprite.cpp"
#include "scroll.cpp"
#include "serialization.cpp"
auto PPU::load(Node::Object parent) -> void {
ciram.allocate(2048);
cgram.allocate(32);
oam.allocate(256);
soam.allocate(32);
node = parent->append<Node::Object>("PPU");
screen = node->append<Node::Video::Screen>("Screen", 282, displayHeight());
screen = node->append<Node::Video::Screen>("Screen", 283, displayHeight());
screen->colors(1 << 9, {&PPU::color, this});
screen->setSize(282, displayHeight());
screen->setSize(283, displayHeight());
screen->setScale(1.0, 1.0);
Region::PAL() ? screen->setAspect(55.0, 43.0) :screen->setAspect(8.0, 7.0);
screen->refreshRateHint(system.frequency() / rate(), 341, vlines());
@@ -35,6 +38,7 @@ auto PPU::unload() -> void {
ciram.reset();
cgram.reset();
oam.reset();
soam.reset();
}
auto PPU::main() -> void {
@@ -45,11 +49,24 @@ auto PPU::step(u32 clocks) -> void {
u32 L = vlines();
while(clocks--) {
if (var.blockingRead) --var.blockingRead;
scrollTransferDelay();
if (enable() && io.ly == L - 1)
cyclePrepareSpriteEvaluation();
if (enable() && (io.ly < 240 || (Region::PAL() && io.ly >= 264 && io.ly <= L - 2)))
cycleSpriteEvaluation();
if (enable() && (io.ly < 240 || io.ly == L - 1))
cycleScroll();
if(io.ly == 240 && io.lx == 1) io.busAddress = var.address, cartridge.ppuAddressBus(io.busAddress);
if(io.ly == 240 && io.lx == 340) io.nmiHold = 1;
if(io.ly == 241 && io.lx == 0) io.nmiFlag = io.nmiHold;
if(io.ly == 241 && io.lx == 2) cpu.nmiLine(io.nmiEnable && io.nmiFlag);
if(io.ly == L-2 && io.lx == 340) io.spriteZeroHit = 0, io.spriteOverflow = 0;
if(io.ly == L-2 && io.lx == 340) io.spriteZeroHit = 0, sprite.spriteOverflow = 0;
if(io.ly == L-2 && io.lx == 340) io.nmiHold = 0;
if(io.ly == L-1 && io.lx == 0) io.nmiFlag = io.nmiHold;
@@ -76,12 +93,12 @@ auto PPU::frame() -> void {
io.field++;
if(screen->overscan()) {
screen->setSize(282, displayHeight());
screen->setViewport(0, 0, 282, displayHeight());
screen->setSize(283, displayHeight());
screen->setViewport(0, 0, 283, displayHeight());
} else {
int x = 16;
int y = 8;
int width = 282 - 32;
int width = 283 - 33;
int height = displayHeight() - 16;
if(Region::PAL()) height -= 48;
@@ -100,11 +117,16 @@ auto PPU::power(bool reset) -> void {
if(!reset) {
ciram.fill();
cgram.fill();
oam.fill();
soam.fill();
memory::copy(cgram.data(), cgramBootValue, 32);
}
scroll = {};
var = {};
io = {};
latch = {};
sprite = {};
}
}
+90 -25
View File
@@ -4,6 +4,7 @@ struct PPU : Thread {
Memory::Writable<n8> ciram;
Memory::Writable<n8> cgram;
Memory::Writable<n8> oam;
Memory::Writable<n8> soam;
struct Debugger {
//debugger.cpp
@@ -14,6 +15,7 @@ struct PPU : Thread {
Node::Debugger::Memory ciram;
Node::Debugger::Memory cgram;
Node::Debugger::Memory oam;
Node::Debugger::Memory soam;
} memory;
} debugger;
@@ -45,10 +47,10 @@ struct PPU : Thread {
//render.cpp
auto enable() const -> bool;
auto rendering() const -> bool;
auto loadCHR(n16 address) -> n8;
auto renderPixel() -> void;
auto renderSprite() -> void;
auto renderScanline() -> void;
//color.cpp
@@ -57,28 +59,64 @@ struct PPU : Thread {
//serialization.cpp
auto serialize(serializer&) -> void;
// scroll.cpp
auto incrementVRAMAddressX() -> void;
auto incrementVRAMAddressY() -> void;
auto transferScrollX() -> void;
auto transferScrollY() -> void;
auto cycleScroll() -> void;
auto scrollTransferDelay() -> void;
// sprite.cpp
auto cycleSpriteEvaluation() -> void;
auto cyclePrepareSpriteEvaluation() -> void;
struct ScrollRegisters {
n15 data;
BitRange<15, 0, 4> tileX {&data};
BitRange<15, 5, 9> tileY {&data};
BitRange<15,10,10> nametableX{&data};
BitRange<15,11,11> nametableY{&data};
BitRange<15,12,14> fineY {&data};
n1 latch;
n3 fineX;
BitRange<15,10,11> nametable {&data};
BitRange<15, 0,14> address {&data};
BitRange<15, 0, 7> addressLo {&data};
BitRange<15, 8,14> addressHi {&data};
n8 transferDelay;
} scroll;
struct VRAMAddressRegisters {
n15 data;
BitRange<15, 0, 4> tileX {&data};
BitRange<15, 5, 9> tileY {&data};
BitRange<15,10,10> nametableX{&data};
BitRange<15,11,11> nametableY{&data};
BitRange<15,12,14> fineY {&data};
BitRange<15,10,11> nametable {&data};
BitRange<15, 0,14> address {&data};
BitRange<15, 2, 4> attrX {&data};
BitRange<15, 7, 9> attrY {&data};
n8 latchData;
n8 blockingRead;
} var;
struct IO {
n14 busAddress;
//internal
n8 mdr;
n1 field;
n16 lx;
n16 ly;
n8 busData;
struct Union {
n19 data;
BitRange<19, 0, 4> tileX {&data};
BitRange<19, 5, 9> tileY {&data};
BitRange<19,10,11> nametable {&data};
BitRange<19,10,10> nametableX{&data};
BitRange<19,11,11> nametableY{&data};
BitRange<19,12,14> fineY {&data};
BitRange<19, 0,14> address {&data};
BitRange<19, 0, 7> addressLo {&data};
BitRange<19, 8,14> addressHi {&data};
BitRange<19,15,15> latch {&data};
BitRange<19,16,18> fineX {&data};
} v, t;
n1 nmiHold;
n1 nmiFlag;
@@ -100,11 +138,7 @@ struct PPU : Thread {
n3 emphasis;
//$2002
n1 spriteOverflow;
n1 spriteZeroHit;
//$2003
n8 oamAddress;
} io;
struct OAM {
@@ -127,14 +161,45 @@ struct PPU : Thread {
n16 tiledataLo;
n16 tiledataHi;
n16 oamIterator;
n16 oamCounter;
n8 oamId[8];
OAM oam[8]; //primary
OAM soam[8]; //secondary
} latch;
struct SpriteEvaluation {
// $2002 bit5
n1 spriteOverflow;
// $2003
n8 oamAddress;
// $2004
n8 oamData;
// main oam counter (oamAddress)
BitRange<8,0,7> oamMainCounter{&oamAddress};
bool oamMainCounterOverflow;
// every sprite has 4 bytes
BitRange<8,0,1> oamMainCounterTiming{&oamAddress};
// main counter have 64 sprites
BitRange<8,2,7> oamMainCounterIndex{&oamAddress};
// secondary oam counter
n5 oamTempCounter;
bool oamTempCounterOverflow;
// every sprite has 4 bytes
BitRange<5,0,1> oamTempCounterTiming{&oamTempCounter};
// temp counter have 8 sprites
BitRange<5,2,4> oamTempCounterIndex{&oamTempCounter};
} sprite;
u32* output;
static constexpr u8 cgramBootValue[32] = {
0x09, 0x01, 0x00, 0x01, 0x00, 0x02, 0x02, 0x0D,
0x08, 0x10, 0x08, 0x24, 0x00, 0x00, 0x04, 0x2C,
0x09, 0x01, 0x34, 0x03, 0x00, 0x04, 0x00, 0x14,
0x08, 0x3A, 0x00, 0x02, 0x00, 0x20, 0x2C, 0x08,
};
};
extern PPU ppu;
+66 -89
View File
@@ -2,15 +2,25 @@ auto PPU::enable() const -> bool {
return io.bgEnable || io.spriteEnable;
}
auto PPU::rendering() const -> bool {
return enable() && (io.ly < 240 || io.ly == vlines() - 1);
}
auto PPU::loadCHR(n16 address) -> n8 {
return enable() ? cartridge.readCHR(address) : (n8)0x00;
if (enable()) {
io.busAddress = (n14)address;
cartridge.ppuAddressBus(address);
return cartridge.readCHR(address);
} else {
return 0x00;
}
}
auto PPU::renderPixel() -> void {
if(io.ly >= screen->canvasHeight()) return;
u32 x = io.lx - 1;
u32 mask = 0x8000 >> (io.v.fineX + (x & 7));
u32 mask = 0x8000 >> (scroll.fineX + (x & 7));
u32 palette = 0;
u32 objectPalette = 0;
bool objectPriority = 0;
@@ -30,99 +40,77 @@ auto PPU::renderPixel() -> void {
if(!io.bgEdgeEnable && x < 8) palette = 0;
if(io.spriteEnable)
for(i32 sprite = 7; sprite >= 0; sprite--) {
if(!io.spriteEdgeEnable && x < 8) continue;
if(latch.oam[sprite].id == 64) continue;
for(i32 sprite = 7; sprite >= 0; sprite--) {
if(!io.spriteEdgeEnable && x < 8) continue;
if(latch.oam[sprite].id == 64) continue;
u32 spriteX = x - latch.oam[sprite].x;
if(spriteX >= 8) continue;
u32 spriteX = x - latch.oam[sprite].x;
if(spriteX >= 8) continue;
if(latch.oam[sprite].attr & 0x40) spriteX ^= 7;
u32 mask = 0x80 >> spriteX;
u32 spritePalette = 0;
spritePalette |= latch.oam[sprite].tiledataLo & mask ? 1 : 0;
spritePalette |= latch.oam[sprite].tiledataHi & mask ? 2 : 0;
if(spritePalette == 0) continue;
if(latch.oam[sprite].attr & 0x40) spriteX ^= 7;
u32 mask = 0x80 >> spriteX;
u32 spritePalette = 0;
spritePalette |= latch.oam[sprite].tiledataLo & mask ? 1 : 0;
spritePalette |= latch.oam[sprite].tiledataHi & mask ? 2 : 0;
if(spritePalette == 0) continue;
if(latch.oam[sprite].id == 0 && palette && x != 255) io.spriteZeroHit = 1;
spritePalette |= (latch.oam[sprite].attr & 3) << 2;
if(latch.oam[sprite].id == 0 && palette && x != 255) io.spriteZeroHit = 1;
spritePalette |= (latch.oam[sprite].attr & 3) << 2;
objectPriority = latch.oam[sprite].attr & 0x20;
objectPalette = 16 + spritePalette;
}
objectPriority = latch.oam[sprite].attr & 0x20;
objectPalette = 16 + spritePalette;
}
if(objectPalette) {
if(palette == 0 || objectPriority == 0) palette = objectPalette;
}
if(!enable()) palette = 0;
if(Region::PAL()) {
output[(x + 18) % 282] = io.emphasis << 6 | readCGRAM(palette);
return;
u32 color = 0;
if (enable() || (n14)var.address < 0x3f00) {
color = io.emphasis << 6 | readCGRAM(palette);
} else {
color = io.emphasis << 6 | readCGRAM((n5)var.address);
}
output[(x + 15) % 282] = io.emphasis << 6 | readCGRAM(palette);
}
auto PPU::renderSprite() -> void {
if(!enable()) return;
u32 n = latch.oamIterator++;
s32 ly = io.ly == vlines() - 1 ? -1 : (s32)io.ly;
u32 y = ly - oam[n * 4 + 0];
if(y >= io.spriteHeight) return;
if(latch.oamCounter == 8) {
io.spriteOverflow = 1;
return;
}
auto& o = latch.soam[latch.oamCounter++];
o.id = n;
o.y = oam[n * 4 + 0];
o.tile = oam[n * 4 + 1];
o.attr = oam[n * 4 + 2];
o.x = oam[n * 4 + 3];
if(Region::PAL())
output[(x + 18) % 283] = color;
else
output[(x + 16) % 283] = color;
}
auto PPU::renderScanline() -> void {
if(io.ly < screen->canvasHeight()) {
output = screen->pixels().data() + io.ly * 282;
for(auto n : range(282)) output[n] = Region::PAL() ? 0x3f : (io.emphasis << 6 | readCGRAM(0));
output = screen->pixels().data() + io.ly * 283;
for (auto n : range(283))
output[n] = Region::PAL() ? 0x3f : io.emphasis << 6 | readCGRAM(0);
}
//Vblank
if(io.ly >= 240 && io.ly <= vlines() - 2) return step(341), scanline();
latch.oamIterator = 0;
latch.oamCounter = 0;
for(auto n : range(8)) latch.soam[n] = {};
// 0
step(1);
// force clear sprite counter at start of each scanline
for (auto& id : latch.oamId) id = 64;
// 1-256
for(u32 tile : range(32)) {
u32 nametable = loadCHR(0x2000 | (n12)io.v.address);
u32 tileaddr = io.bgAddress | nametable << 4 | io.v.fineY;
u32 nametable = loadCHR(0x2000 | (n12)var.address);
u32 tileaddr = io.bgAddress | nametable << 4 | var.fineY;
renderPixel();
step(1);
renderPixel();
step(1);
u32 attribute = loadCHR(0x23c0 | io.v.nametable << 10 | (io.v.tileY >> 2) << 3 | io.v.tileX >> 2);
if(io.v.tileY & 2) attribute >>= 4;
if(io.v.tileX & 2) attribute >>= 2;
u32 attribute = loadCHR(0x23c0 | var.nametable << 10 | var.attrY << 3 | var.attrX);
if(var.tileY & 2) attribute >>= 4;
if(var.tileX & 2) attribute >>= 2;
renderPixel();
step(1);
if(enable() && ++io.v.tileX == 0) io.v.nametableX++;
if(enable() && tile == 31 && ++io.v.fineY == 0 && ++io.v.tileY == 30) io.v.nametableY++, io.v.tileY = 0;
renderPixel();
renderSprite();
step(1);
u32 tiledataLo = loadCHR(tileaddr + 0);
@@ -137,7 +125,6 @@ auto PPU::renderScanline() -> void {
step(1);
renderPixel();
renderSprite();
step(1);
latch.nametable = latch.nametable << 8 | nametable;
@@ -146,22 +133,20 @@ auto PPU::renderScanline() -> void {
latch.tiledataHi = latch.tiledataHi << 8 | tiledataHi;
}
for(u32 n : range(8)) latch.oam[n] = latch.soam[n];
for(u32 n : range(8)) {
latch.oam[n].id = latch.oamId[n];
latch.oam[n].y = soam[4 * n + 0];
latch.oam[n].tile = soam[4 * n + 1];
latch.oam[n].attr = soam[4 * n + 2];
latch.oam[n].x = soam[4 * n + 3];
}
//257-320
for(u32 sprite : range(8)) {
if(enable()) io.oamAddress = 0;
u32 nametable = loadCHR(0x2000 | (n12)io.v.address);
step(1);
u32 nametable = loadCHR(0x2000 | (n12)var.address);
step(2);
if(enable() && sprite == 0) {
//258
io.v.nametableX = io.t.nametableX;
io.v.tileX = io.t.tileX;
}
step(1);
u32 attribute = loadCHR(0x23c0 | io.v.nametable << 10 | (io.v.tileY >> 2) << 3 | io.v.tileX >> 2);
u32 attribute = loadCHR(0x23c0 | var.nametable << 10 | (var.tileY >> 2) << 3 | var.tileX >> 2);
u32 tileaddr = io.spriteHeight == 8
? io.spriteAddress + latch.oam[sprite].tile * 16
: (latch.oam[sprite].tile & ~1) * 16 + (latch.oam[sprite].tile & 1) * 0x1000;
@@ -176,26 +161,18 @@ auto PPU::renderScanline() -> void {
latch.oam[sprite].tiledataHi = loadCHR(tileaddr + 8);
step(2);
if(enable() && sprite == 6 && io.ly == vlines() - 1) {
//305
io.v.address = io.t.address;
}
}
//321-336
for(u32 tile : range(2)) {
u32 nametable = loadCHR(0x2000 | (n12)io.v.address);
u32 tileaddr = io.bgAddress | nametable << 4 | io.v.fineY;
u32 nametable = loadCHR(0x2000 | (n12)var.address);
u32 tileaddr = io.bgAddress | nametable << 4 | var.fineY;
step(2);
u32 attribute = loadCHR(0x23c0 | io.v.nametable << 10 | (io.v.tileY >> 2) << 3 | io.v.tileX >> 2);
if(io.v.tileY & 2) attribute >>= 4;
if(io.v.tileX & 2) attribute >>= 2;
step(1);
if(enable() && ++io.v.tileX == 0) io.v.nametableX++;
step(1);
u32 attribute = loadCHR(0x23c0 | var.nametable << 10 | (var.tileY >> 2) << 3 | var.tileX >> 2);
if(var.tileY & 2) attribute >>= 4;
if(var.tileX & 2) attribute >>= 2;
step(2);
u32 tiledataLo = loadCHR(tileaddr + 0);
step(2);
@@ -210,12 +187,12 @@ auto PPU::renderScanline() -> void {
}
//337-338
loadCHR(0x2000 | (n12)io.v.address);
loadCHR(0x2000 | (n12)var.address);
bool skip = !Region::PAL() && enable() && io.field == 1 && io.ly == vlines() - 1;
step(2);
//339
loadCHR(0x2000 | (n12)io.v.address);
loadCHR(0x2000 | (n12)var.address);
step(1);
//340
+79
View File
@@ -0,0 +1,79 @@
auto PPU::incrementVRAMAddressX() -> void {
if (++var.tileX == 0)
var.nametableX++;
}
auto PPU::incrementVRAMAddressY() -> void {
if (++var.fineY == 0 && ++var.tileY == 30)
var.nametableY++, var.tileY = 0;
}
auto PPU::transferScrollX() -> void {
var.tileX = scroll.tileX;
var.nametableX = scroll.nametableX;
}
auto PPU::transferScrollY() -> void {
var.tileY = scroll.tileY;
var.nametableY = scroll.nametableY;
var.fineY = scroll.fineY;
}
auto PPU::cycleScroll() -> void {
if (io.lx == 0) return;
if (io.lx <= 256) {
if (io.lx & 7) return;
incrementVRAMAddressX();
if (io.lx == 256) incrementVRAMAddressY();
return;
}
if (io.lx == 257) {
transferScrollX();
return;
}
if (io.ly == vlines() - 1) {
if (io.lx >= 280 && io.lx <= 304) {
transferScrollY();
return;
}
}
if (io.lx > 320 && io.lx <= 336) {
if (io.lx & 7) return;
incrementVRAMAddressX();
return;
}
}
auto PPU::scrollTransferDelay() -> void {
if (!scroll.transferDelay || --scroll.transferDelay)
return;
bool isRendering = rendering();
bool isTransferX = isRendering && io.lx != 0 && (io.lx & 7) == 0 && (io.lx <= 256 || io.lx > 320);
bool isTransferY = isRendering && io.lx == 256;
if (isTransferX) {
scroll.tileX = var.tileX & scroll.tileX;
scroll.nametableX = var.nametableX & scroll.nametableX;
}
if (isTransferY) {
scroll.tileY = var.tileY & scroll.tileY;
scroll.nametableY = var.nametableY & scroll.nametableY;
scroll.fineY = var.fineY & scroll.fineY;
}
transferScrollX();
transferScrollY();
if (!isRendering) {
io.busAddress = var.address;
cartridge.ppuAddressBus(io.busAddress);
}
}
+17 -8
View File
@@ -3,13 +3,19 @@ auto PPU::serialize(serializer& s) -> void {
s(ciram);
s(cgram);
s(oam);
s(soam);
s(scroll.data);
s(scroll.latch);
s(scroll.fineX);
s(scroll.transferDelay);
s(var.data);
s(var.latchData);
s(var.blockingRead);
s(io.busAddress);
s(io.mdr);
s(io.field);
s(io.lx);
s(io.ly);
s(io.busData);
s(io.v.data);
s(io.t.data);
s(io.nmiHold);
s(io.nmiFlag);
s(io.vramIncrement);
@@ -24,17 +30,20 @@ auto PPU::serialize(serializer& s) -> void {
s(io.bgEnable);
s(io.spriteEnable);
s(io.emphasis);
s(io.spriteOverflow);
s(io.spriteZeroHit);
s(io.oamAddress);
s(latch.nametable);
s(latch.attribute);
s(latch.tiledataLo);
s(latch.tiledataHi);
s(latch.oamIterator);
s(latch.oamCounter);
s(latch.oamId);
for(auto& o : latch.oam) s(o);
for(auto& o : latch.soam) s(o);
s(sprite.spriteOverflow);
s(sprite.oamAddress);
s(sprite.oamData);
s(sprite.oamTempCounterOverflow);
s(sprite.oamTempCounter);
s(sprite.oamTempCounterOverflow);
}
auto PPU::OAM::serialize(serializer& s) -> void {
+107
View File
@@ -0,0 +1,107 @@
auto PPU::cycleSpriteEvaluation() -> void {
if (io.lx == 0) return;
if (io.lx <= 64) {
if ((io.lx & 1) == 1)
sprite.oamData = 0xff;
else
soam[sprite.oamTempCounter++] = sprite.oamData;
return;
}
if (io.lx <= 256) {
if ((io.lx & 1) == 1) {
sprite.oamData = oam[sprite.oamMainCounter];
return;
}
if (sprite.oamMainCounterOverflow) {
++sprite.oamMainCounterIndex;
if (sprite.oamTempCounterOverflow)
sprite.oamData = soam[sprite.oamTempCounter];
return;
}
if (sprite.oamTempCounterTiming == 0) {
s32 ly = io.ly == vlines() - 1 ? -1 : (s32)io.ly;
u32 y = ly - sprite.oamData;
if (sprite.oamTempCounterOverflow) {
sprite.oamData = soam[sprite.oamTempCounter];
if (y >= io.spriteHeight) {
if (++sprite.oamMainCounterIndex == 0)
sprite.oamMainCounterOverflow = true;
++sprite.oamMainCounterTiming;
return;
}
sprite.spriteOverflow = 1;
++sprite.oamTempCounter;
++sprite.oamMainCounterTiming;
return;
}
soam[sprite.oamTempCounter] = sprite.oamData;
if (y >= io.spriteHeight) {
if (++sprite.oamMainCounterIndex == 0)
sprite.oamMainCounterOverflow = true;
return;
}
latch.oamId[sprite.oamTempCounterIndex] = sprite.oamMainCounterIndex;
++sprite.oamTempCounter;
++sprite.oamMainCounterTiming;
} else {
if (sprite.oamTempCounterOverflow) {
sprite.oamData = soam[sprite.oamTempCounter];
++sprite.oamTempCounter;
++sprite.oamMainCounterTiming;
return;
}
soam[sprite.oamTempCounter] = sprite.oamData;
++sprite.oamTempCounter;
++sprite.oamMainCounterTiming;
if (sprite.oamTempCounterTiming == 0) {
if (++sprite.oamMainCounterIndex == 0)
sprite.oamMainCounterOverflow = true;
if (sprite.oamTempCounter == 0)
sprite.oamTempCounterOverflow = true;
}
}
return;
}
if (io.lx <= 320) {
u32 index = ((io.lx - 257) >> 3) << 2 + min((io.lx - 257) & 7, 3);
sprite.oamMainCounter = 0;
sprite.oamTempCounter = 0;
sprite.oamMainCounterOverflow = false;
sprite.oamTempCounterOverflow = false;
sprite.oamData = soam[index];
return;
}
if (io.lx <= 340) {
sprite.oamData = soam[0];
return;
}
}
auto PPU::cyclePrepareSpriteEvaluation() -> void {
// In https://www.nesdev.org/wiki/PPU_sprite_evaluation,
// Sprite evaluation does not happen on the pre-render
// scanline. Because evaluation applies to the next
// line's sprite rendering, no sprites will be rendered
// on the first scanline, and this is why there is a 1
// line offset on a sprite's Y coordinate.
if (io.lx > 0 && io.lx <= 8) {
if (sprite.oamMainCounterIndex >= 2) {
oam[io.lx - 1] = oam[(sprite.oamMainCounter & 0xf8) + io.lx - 1];
}
}
}
+1 -1
View File
@@ -1,4 +1,4 @@
static const string SerializerVersion = "v140";
static const string SerializerVersion = "v148";
auto System::serialize(bool synchronize) -> serializer {
if(synchronize) scheduler.enter(Scheduler::Mode::Synchronize);
+4 -1
View File
@@ -1,4 +1,6 @@
auto APU::readIO(n32 address) -> n8 {
cpu.synchronize(apu);
switch(address) {
//NR10
@@ -140,11 +142,12 @@ auto APU::readIO(n32 address) -> n8 {
}
if(cpu.context.dmaActive) return cpu.dmabus.data.byte(address & 3);
return cpu.pipeline.fetch.instruction.byte(address & 1);
}
auto APU::writeIO(n32 address, n8 data) -> void {
cpu.synchronize(apu);
switch(address) {
//NR10
+17 -11
View File
@@ -2,28 +2,26 @@ auto CPU::sleep() -> void {
prefetchStep(1);
}
auto CPU::get(u32 mode, n32 address) -> n32 {
template <bool UseDebugger>
inline auto CPU::getBus(u32 mode, n32 address) -> n32 {
u32 clocks = _wait(mode, address);
u32 word = pipeline.fetch.instruction;
if(context.dmaActive) word = dmabus.data;
if(address >= 0x1000'0000) {
prefetchStep(clocks);
if constexpr(!UseDebugger) prefetchStep(clocks);
} else if(address & 0x0800'0000) {
if(mode & Prefetch && wait.prefetch) {
dmaRun();
prefetchSync(address);
prefetchStep(1);
word = prefetchRead();
if(mode & Word) word |= prefetchRead() << 16;
word = prefetchRead(mode);
} else {
if(!context.dmaActive) prefetchReset(); //todo: Prefetch buffer should also be reset when DMA accesses ROM
step(clocks - 1);
if constexpr(!UseDebugger) prefetchReset();
if constexpr(!UseDebugger) step(clocks);
word = cartridge.read(mode, address);
step(1);
}
} else {
if(memory.biosSwap && address < 0x0400'0000) address ^= 0x0200'0000;
prefetchStep(clocks);
if constexpr(!UseDebugger) prefetchStep(clocks);
if(auto result = platform->cheat(address)) return *result;
if(address < 0x0200'0000) word = bios.read(mode, address);
else if(address < 0x0300'0000) word = readEWRAM(mode, address);
@@ -38,13 +36,21 @@ auto CPU::get(u32 mode, n32 address) -> n32 {
return word;
}
auto CPU::get(u32 mode, n32 address) -> n32 {
return getBus<false>(mode, address);
}
auto CPU::getDebugger(u32 mode, n32 address) -> n32 {
return getBus<true>(mode, address);
}
auto CPU::set(u32 mode, n32 address, n32 word) -> void {
u32 clocks = _wait(mode, address);
if(address >= 0x1000'0000) {
prefetchStep(clocks);
} else if(address & 0x0800'0000) {
if(!context.dmaActive) prefetchReset(); //todo: Prefetch buffer should also be reset when DMA accesses ROM
prefetchReset();
step(clocks);
cartridge.write(mode, address, word);
} else {
+55 -21
View File
@@ -30,20 +30,25 @@ auto CPU::unload() -> void {
}
auto CPU::main() -> void {
ARM7TDMI::irq = irq.ime && (irq.enable & irq.flag);
ARM7TDMI::irq = irq.synchronizer[0];
if(stopped()) {
if(!(irq.enable & irq.flag & Interrupt::Keypad)) {
Thread::step(16);
if(!keypad.conditionMet) {
stepIRQ();
Thread::step(1);
Thread::synchronize();
return;
}
Thread::step(2);
Thread::synchronize();
context.stopped = false;
}
if(halted()) {
if(!(irq.enable & irq.flag)) {
return step(16);
if(!(irq.enable[0] & irq.flag[0])) {
return step(4);
}
step(2);
context.halted = false;
}
@@ -51,14 +56,34 @@ auto CPU::main() -> void {
instruction();
}
auto CPU::dmaRun() -> void {
if(!context.dmaActive && !context.prefetchActive) {
context.dmaActive = true;
while(dma[0].run() | dma[1].run() | dma[2].run() | dma[3].run());
if(context.dmaRan) {
idle();
context.dmaRan = false;
context.dmaRomAccess = false;
}
context.dmaActive = false;
}
}
auto CPU::setInterruptFlag(u32 source) -> void {
irq.flag[1] |= source;
}
inline auto CPU::stepIRQ() -> void {
irq.synchronizer[0] = irq.synchronizer[1];
irq.synchronizer[1] = irq.ime && (irq.enable[0] & irq.flag[0]);
irq.enable[0] = irq.enable[1];
irq.flag[0] = irq.flag[1];
}
auto CPU::step(u32 clocks) -> void {
if(!clocks) return;
if(!context.dmaActive) {
context.dmaActive = true;
while(dma[0].run() | dma[1].run() | dma[2].run() | dma[3].run());
context.dmaActive = false;
}
dmaRun();
dma[0].waiting = max(0, dma[0].waiting - (s32)clocks);
dma[1].waiting = max(0, dma[1].waiting - (s32)clocks);
@@ -66,24 +91,35 @@ auto CPU::step(u32 clocks) -> void {
dma[3].waiting = max(0, dma[3].waiting - (s32)clocks);
for(auto _ : range(clocks)) {
stepIRQ();
timer[0].run();
timer[1].run();
timer[2].run();
timer[3].run();
timer[0].reloadLatch();
timer[1].reloadLatch();
timer[2].reloadLatch();
timer[3].reloadLatch();
if(context.timerLatched) {
timer[0].stepLatch();
timer[1].stepLatch();
timer[2].stepLatch();
timer[3].stepLatch();
context.timerLatched = 0;
}
context.clock++;
}
#if defined(PROFILE_PERFORMANCE)
//20% speedup by only synchronizing other components every 64 clock cycles
Thread::step(clocks);
Thread::synchronize(ppu, player);
//occasionally synchronize with APU in case CPU has not recently interacted with it
static u32 counter = 0;
counter += clocks;
if(counter < 64) return;
clocks = counter;
counter = 0;
#endif
Thread::step(clocks);
Thread::synchronize();
if(counter >= 1024) {
Thread::synchronize(apu);
counter = 0;
}
}
auto CPU::power() -> void {
@@ -104,8 +140,6 @@ auto CPU::power() -> void {
prefetch = {};
context = {};
dmabus = {};
dma[0].source.setBits(27); dma[0].latch.source.setBits(27);
dma[0].target.setBits(27); dma[0].latch.target.setBits(27);
dma[0].length.setBits(14); dma[0].latch.length.setBits(14);
+28 -9
View File
@@ -46,6 +46,9 @@ struct CPU : ARM7TDMI, Thread, IO {
auto unload() -> void;
auto main() -> void;
auto dmaRun() -> void;
auto setInterruptFlag(u32 source) -> void;
auto stepIRQ() -> void;
auto step(u32 clocks) -> void override;
auto power() -> void;
@@ -53,11 +56,13 @@ struct CPU : ARM7TDMI, Thread, IO {
auto prefetchSync(n32 address) -> void;
auto prefetchStep(u32 clocks) -> void;
auto prefetchReset() -> void;
auto prefetchRead() -> n16;
auto prefetchRead(u32 mode) -> n32;
//bus.cpp
auto sleep() -> void override;
template<bool UseDebugger> auto getBus(u32 mode, n32 address) -> n32;
auto get(u32 mode, n32 address) -> n32 override;
auto getDebugger(u32 mode, n32 address) -> n32 override;
auto set(u32 mode, n32 address, n32 word) -> void override;
auto _wait(u32 mode, n32 address) -> u32;
@@ -91,11 +96,6 @@ struct CPU : ARM7TDMI, Thread, IO {
n32 mask;
};
//DMA data bus shared between all DMA channels
struct DMABus {
n32 data;
} dmabus;
struct DMA {
//dma.cpp
auto run() -> bool;
@@ -123,11 +123,14 @@ struct CPU : ARM7TDMI, Thread, IO {
uintVN source;
uintVN target;
uintVN length;
u32 data;
} latch;
} dma[4];
struct Timer {
//timer.cpp
auto stepLatch() -> void;
auto reloadLatch() -> void;
auto run() -> void;
auto step() -> void;
@@ -142,6 +145,13 @@ struct CPU : ARM7TDMI, Thread, IO {
n1 cascade;
n1 irq;
n1 enable;
struct Latch {
n16 reload;
n8 control;
n2 reloadFlags;
n1 controlFlag;
} latch;
} timer[4];
struct Serial {
@@ -150,7 +160,8 @@ struct CPU : ARM7TDMI, Thread, IO {
n1 transferEnableReceive;
n1 transferEnableSend;
n1 startBit;
n1 transferLength;
n4 uartFlags;
n2 mode;
n1 irqEnable;
n16 data[4];
@@ -164,6 +175,8 @@ struct CPU : ARM7TDMI, Thread, IO {
n1 enable;
n1 condition;
n1 flag[10];
n1 conditionMet;
} keypad;
struct Joybus {
@@ -193,8 +206,9 @@ struct CPU : ARM7TDMI, Thread, IO {
struct IRQ {
n1 ime;
n16 enable;
n16 flag;
n1 synchronizer[2];
n16 enable[2];
n16 flag[2];
} irq;
struct Wait {
@@ -216,6 +230,7 @@ struct CPU : ARM7TDMI, Thread, IO {
struct {
auto empty() const { return addr == load; }
auto full() const { return load - addr == 16; }
auto size() const { return (load - addr) >> 1; }
n16 slot[8];
n32 addr; //read location of slot buffer
@@ -228,7 +243,11 @@ struct CPU : ARM7TDMI, Thread, IO {
n1 halted;
n1 stopped;
n1 booted; //set to true by the GBA BIOS
n1 dmaRan;
n1 dmaRomAccess;
n1 dmaActive;
n1 prefetchActive;
n1 timerLatched;
} context;
};
+9 -7
View File
@@ -2,8 +2,8 @@ inline auto CPU::DMA::run() -> bool {
if(!active || waiting) return false;
transfer();
if(irq) cpu.irq.flag |= CPU::Interrupt::DMA0 << id;
if(drq && id == 3) cpu.irq.flag |= CPU::Interrupt::Cartridge;
if(irq) cpu.setInterruptFlag(CPU::Interrupt::DMA0 << id);
if(drq && id == 3) cpu.setInterruptFlag(CPU::Interrupt::Cartridge);
return true;
}
@@ -12,8 +12,8 @@ auto CPU::DMA::transfer() -> void {
u32 mode = size ? Word : Half;
mode |= latch.length() == length() ? Nonsequential : Sequential;
if(mode & Nonsequential) {
cpu.idle();
if(!cpu.context.dmaRan) {
cpu.context.dmaRan = true;
cpu.idle();
}
@@ -23,8 +23,9 @@ auto CPU::DMA::transfer() -> void {
n32 addr = latch.source();
if(mode & Word) addr &= ~3;
if(mode & Half) addr &= ~1;
cpu.dmabus.data = cpu.get(mode, addr);
if(mode & Half) cpu.dmabus.data |= cpu.dmabus.data << 16;
if(addr & 0x0800'0000) cpu.context.dmaRomAccess = true;
latch.data = cpu.get(mode, addr);
if(mode & Half) latch.data |= latch.data << 16;
}
if(mode & Nonsequential) {
@@ -41,7 +42,8 @@ auto CPU::DMA::transfer() -> void {
n32 addr = latch.target();
if(mode & Word) addr &= ~3;
if(mode & Half) addr &= ~1;
cpu.set(mode, addr, cpu.dmabus.data);
if(addr & 0x0800'0000) cpu.context.dmaRomAccess = true;
cpu.set(mode, addr, latch.data >> (addr & 2) * 8);
}
switch(sourceMode) {
+40 -40
View File
@@ -55,8 +55,9 @@ auto CPU::readIO(n32 address) -> n8 {
| serial.startBit << 7
);
case 0x0400'0129: return (
serial.transferLength << 4
| serial.irqEnable << 6
serial.uartFlags << 0
| serial.mode << 4
| serial.irqEnable << 6
);
//SIOMLT_SEND (SIODATA8)
@@ -81,10 +82,10 @@ auto CPU::readIO(n32 address) -> n8 {
result.bit(7) = !system.controls.downLatch;
}
if(ppu.rotation->value() == "90°") {
result.bit(4) = !system.controls.downLatch;
result.bit(5) = !system.controls.upLatch;
result.bit(6) = !system.controls.rightLatch;
result.bit(7) = !system.controls.leftLatch;
result.bit(4) = !system.controls.upLatch;
result.bit(5) = !system.controls.downLatch;
result.bit(6) = !system.controls.leftLatch;
result.bit(7) = !system.controls.rightLatch;
}
if(ppu.rotation->value() == "180°") {
result.bit(4) = !system.controls.leftLatch;
@@ -93,10 +94,10 @@ auto CPU::readIO(n32 address) -> n8 {
result.bit(7) = !system.controls.upLatch;
}
if(ppu.rotation->value() == "270°") {
result.bit(4) = !system.controls.upLatch;
result.bit(5) = !system.controls.downLatch;
result.bit(6) = !system.controls.leftLatch;
result.bit(7) = !system.controls.rightLatch;
result.bit(4) = !system.controls.downLatch;
result.bit(5) = !system.controls.upLatch;
result.bit(6) = !system.controls.rightLatch;
result.bit(7) = !system.controls.leftLatch;
}
return result;
}
@@ -183,12 +184,12 @@ auto CPU::readIO(n32 address) -> n8 {
case 0x0400'015b: return 0;
//IE
case 0x0400'0200: return irq.enable.byte(0);
case 0x0400'0201: return irq.enable.byte(1);
case 0x0400'0200: return irq.enable[0].byte(0);
case 0x0400'0201: return irq.enable[0].byte(1);
//IF
case 0x0400'0202: return irq.flag.byte(0);
case 0x0400'0203: return irq.flag.byte(1);
case 0x0400'0202: return irq.flag[0].byte(0);
case 0x0400'0203: return irq.flag[0].byte(1);
//WAITCNT
case 0x0400'0204: return (
@@ -243,7 +244,6 @@ auto CPU::readIO(n32 address) -> n8 {
}
if(cpu.context.dmaActive) return cpu.dmabus.data.byte(address & 3);
return cpu.pipeline.fetch.instruction.byte(address & 1);
}
@@ -301,24 +301,23 @@ auto CPU::writeIO(n32 address, n8 data) -> void {
}
//TM0CNT_L, TM1CNT_L, TM2CNT_L, TM3CNT_L
case 0x0400'0100: case 0x0400'0104: case 0x0400'0108: case 0x0400'010c: timer().reload.byte(0) = data; return;
case 0x0400'0101: case 0x0400'0105: case 0x0400'0109: case 0x0400'010d: timer().reload.byte(1) = data; return;
case 0x0400'0100: case 0x0400'0104: case 0x0400'0108: case 0x0400'010c:
timer().latch.reload.byte(0) = data;
timer().latch.reloadFlags.bit(0) = 1;
context.timerLatched = 1;
return;
case 0x0400'0101: case 0x0400'0105: case 0x0400'0109: case 0x0400'010d:
timer().latch.reload.byte(1) = data;
timer().latch.reloadFlags.bit(1) = 1;
context.timerLatched = 1;
return;
//TM0CNT_H, TM1CNT_H, TM2CNT_H, TM3CNT_H
case 0x0400'0102: case 0x0400'0106: case 0x0400'010a: case 0x0400'010e: {
bool enable = timer().enable;
timer().frequency = data.bit(0,1);
timer().irq = data.bit(6);
timer().enable = data.bit(7);
if(address != 0x0400'0102) timer().cascade = data.bit(2);
if(!enable && timer().enable) { //0->1 transition
timer().pending = true;
}
case 0x0400'0102: case 0x0400'0106: case 0x0400'010a: case 0x0400'010e:
timer().latch.control = data;
timer().latch.controlFlag = 1;
context.timerLatched = 1;
return;
}
case 0x0400'0103: case 0x0400'0107: case 0x0400'010b: case 0x0400'010f:
return;
@@ -341,8 +340,9 @@ auto CPU::writeIO(n32 address, n8 data) -> void {
serial.startBit = data.bit(7);
return;
case 0x0400'0129:
serial.transferLength = data.bit(4);
serial.irqEnable = data.bit(6);
serial.uartFlags = data.bit(0,3);
serial.mode = data.bit(4,5);
serial.irqEnable = data.bit(6);
return;
//SIOMLT_SEND (SIODATA8)
@@ -385,10 +385,10 @@ auto CPU::writeIO(n32 address, n8 data) -> void {
//JOYCNT
case 0x0400'0140:
joybus.resetSignal = data.bit(0);
joybus.receiveComplete = data.bit(1);
joybus.sendComplete = data.bit(2);
joybus.resetIRQEnable = data.bit(6);
joybus.resetSignal &= ~data.bit(0);
joybus.receiveComplete &= ~data.bit(1);
joybus.sendComplete &= ~data.bit(2);
joybus.resetIRQEnable = data.bit(6);
return;
case 0x0400'0141: return;
case 0x0400'0142: return;
@@ -417,12 +417,12 @@ auto CPU::writeIO(n32 address, n8 data) -> void {
case 0x0400'0159: return;
//IE
case 0x0400'0200: irq.enable.byte(0) = data; return;
case 0x0400'0201: irq.enable.byte(1) = data; return;
case 0x0400'0200: irq.enable[1].byte(0) = data; return;
case 0x0400'0201: irq.enable[1].byte(1) = data; return;
//IF
case 0x0400'0202: irq.flag.byte(0) = irq.flag.byte(0) & ~data; return;
case 0x0400'0203: irq.flag.byte(1) = irq.flag.byte(1) & ~data; return;
case 0x0400'0202: irq.flag[1].byte(0) = irq.flag[1].byte(0) & ~data; return;
case 0x0400'0203: irq.flag[1].byte(1) = irq.flag[1].byte(1) & ~data; return;
//WAITCNT
case 0x0400'0204:
+6 -8
View File
@@ -1,7 +1,4 @@
auto CPU::Keypad::run() -> void {
if(!enable) return;
system.controls.poll();
const bool lookup[] = {
system.controls.a->value(),
system.controls.b->value(),
@@ -15,12 +12,13 @@ auto CPU::Keypad::run() -> void {
system.controls.l->value(),
};
bool test = condition; //0 = OR, 1 = AND
conditionMet = condition; //0 = OR, 1 = AND
for(u32 index : range(10)) {
if(!flag[index]) continue;
bool input = lookup[index];
if(condition == 0) test |= input;
if(condition == 1) test &= input;
n1 input = lookup[index];
if(condition == 0) conditionMet |= input;
if(condition == 1) conditionMet &= input;
}
if(test) cpu.irq.flag |= CPU::Interrupt::Keypad;
if(conditionMet && enable) cpu.setInterruptFlag(CPU::Interrupt::Keypad);
}
+20 -5
View File
@@ -10,7 +10,7 @@ auto CPU::prefetchSync(n32 address) -> void {
auto CPU::prefetchStep(u32 clocks) -> void {
step(clocks);
if(!wait.prefetch || context.dmaActive || (prefetch.addr == 0)) return;
if(!wait.prefetch || context.dmaRomAccess || (prefetch.addr == 0)) return;
while(!prefetch.full() && clocks--) {
if(--prefetch.wait) continue;
@@ -28,12 +28,27 @@ auto CPU::prefetchReset() -> void {
prefetch.wait = 0;
}
auto CPU::prefetchRead() -> n16 {
if(prefetch.empty()) prefetchStep(prefetch.wait);
auto CPU::prefetchRead(u32 mode) -> n32 {
//run prefetcher for 1 cycle or until buffer contains an instruction, blocking DMA
context.prefetchActive = 1;
if(prefetch.empty() && (mode & Word)) {
prefetchStep(prefetch.wait + _wait(Half | Sequential, prefetch.load + 2));
} else if(prefetch.empty() && (mode & Half)) {
prefetchStep(prefetch.wait);
} else if((prefetch.size() == 1) && (mode & Word)) {
prefetchStep(prefetch.wait);
} else {
prefetchStep(1);
}
context.prefetchActive = 0;
if(prefetch.full()) prefetch.wait = _wait(Half | Sequential, prefetch.load);
n16 half = prefetch.slot[prefetch.addr >> 1 & 7];
n32 word = prefetch.slot[prefetch.addr >> 1 & 7];
prefetch.addr += 2;
return half;
if(mode & Word) {
word |= prefetch.slot[prefetch.addr >> 1 & 7] << 16;
prefetch.addr += 2;
}
return word;
}
+15 -5
View File
@@ -5,8 +5,6 @@ auto CPU::serialize(serializer& s) -> void {
s(iwram);
s(ewram);
s(dmabus.data);
for(auto& dma : this->dma) {
s(dma.id);
s(dma.active);
@@ -31,6 +29,7 @@ auto CPU::serialize(serializer& s) -> void {
s(dma.latch.target.mask);
s(dma.latch.length.data);
s(dma.latch.length.mask);
s(dma.latch.data);
}
for(auto& timer : this->timer) {
@@ -42,6 +41,10 @@ auto CPU::serialize(serializer& s) -> void {
s(timer.cascade);
s(timer.irq);
s(timer.enable);
s(timer.latch.reload);
s(timer.latch.control);
s(timer.latch.reloadFlags);
s(timer.latch.controlFlag);
}
s(serial.shiftClockSelect);
@@ -49,7 +52,8 @@ auto CPU::serialize(serializer& s) -> void {
s(serial.transferEnableReceive);
s(serial.transferEnableSend);
s(serial.startBit);
s(serial.transferLength);
s(serial.uartFlags);
s(serial.mode);
s(serial.irqEnable);
for(auto& value : serial.data) s(value);
s(serial.data8);
@@ -57,6 +61,7 @@ auto CPU::serialize(serializer& s) -> void {
s(keypad.enable);
s(keypad.condition);
for(auto& flag : keypad.flag) s(flag);
s(keypad.conditionMet);
s(joybus.sc);
s(joybus.sd);
@@ -79,8 +84,9 @@ auto CPU::serialize(serializer& s) -> void {
s(joybus.generalFlag);
s(irq.ime);
s(irq.enable);
s(irq.flag);
for(auto& flag : irq.synchronizer) s(flag);
for(auto& flag : irq.enable) s(flag);
for(auto& flag : irq.flag) s(flag);
for(auto& flag : wait.nwait) s(flag);
for(auto& flag : wait.swait) s(flag);
@@ -103,5 +109,9 @@ auto CPU::serialize(serializer& s) -> void {
s(context.halted);
s(context.stopped);
s(context.booted);
s(context.dmaRan);
s(context.dmaRomAccess);
s(context.dmaActive);
s(context.prefetchActive);
s(context.timerLatched);
}
+34 -6
View File
@@ -1,10 +1,38 @@
inline auto CPU::Timer::run() -> void {
if(pending) {
pending = false;
if(enable) period = reload;
return;
auto CPU::Timer::stepLatch() -> void {
if(latch.reloadFlags.bit(0)) {
reload.byte(0) = latch.reload.byte(0);
latch.reloadFlags.bit(0) = 0;
}
if(latch.reloadFlags.bit(1)) {
reload.byte(1) = latch.reload.byte(1);
latch.reloadFlags.bit(1) = 0;
}
if(latch.controlFlag) {
n1 wasEnabled = enable;
frequency = latch.control.bit(0,1);
irq = latch.control.bit(6);
enable = latch.control.bit(7);
if(id != 0) cascade = latch.control.bit(2);
if(!wasEnabled && enable) { //0->1 transition
pending = true;
}
latch.controlFlag = 0;
}
}
inline auto CPU::Timer::reloadLatch() -> void {
if(pending) {
period = reload;
pending = false;
}
}
inline auto CPU::Timer::run() -> void {
if(!enable || cascade) return;
static const u32 mask[] = {0, 63, 255, 1023};
@@ -15,7 +43,7 @@ auto CPU::Timer::step() -> void {
if(++period == 0) {
period = reload;
if(irq) cpu.irq.flag |= CPU::Interrupt::Timer0 << id;
if(irq) cpu.setInterruptFlag(CPU::Interrupt::Timer0 << id);
if(apu.fifo[0].timer == id) cpu.runFIFO(0);
if(apu.fifo[1].timer == id) cpu.runFIFO(1);
+1
View File
@@ -9,6 +9,7 @@ namespace ares::GameBoyAdvance {
#include <ares/inline.hpp>
auto enumerate() -> vector<string>;
auto load(Node::System& node, string name) -> bool;
auto option(string name, string value) -> bool;
enum : u32 { //mode flags for bus read, write:
Nonsequential = 1, //N cycle
+2 -2
View File
@@ -63,7 +63,7 @@ auto Player::frame() -> void {
&& !cpu.serial.transferEnableReceive
&& cpu.serial.transferEnableSend
&& cpu.serial.startBit
&& cpu.serial.transferLength
&& cpu.serial.mode == 0x1
&& cpu.serial.irqEnable
) {
status.packet = (status.packet + 1) % 17;
@@ -86,7 +86,7 @@ auto Player::frame() -> void {
case 15: status.send = 0x30000003; break;
case 16: status.send = 0x30000003; break;
}
cpu.irq.flag |= CPU::Interrupt::Serial;
cpu.setInterruptFlag(CPU::Interrupt::Serial);
}
}
+10 -3
View File
@@ -4,13 +4,19 @@ n1 PPU::Background::IO::frame;
n5 PPU::Background::IO::mosaicWidth;
n5 PPU::Background::IO::mosaicHeight;
auto PPU::Background::setEnable(n1 status) -> void {
io.enable[3] = status;
for(auto& flag : io.enable) flag &= status;
}
auto PPU::Background::scanline(u32 y) -> void {
memory::move(io.enable, io.enable + 1, sizeof(io.enable) - 1);
mosaicOffset = 0;
}
auto PPU::Background::run(u32 x, u32 y) -> void {
output = {};
if(ppu.blank() || !io.enable) {
if(ppu.blank() || !io.enable[0]) {
mosaic = {};
return;
}
@@ -37,10 +43,11 @@ auto PPU::Background::run(u32 x, u32 y) -> void {
}
//horizontal mosaic
if(!io.mosaic || ++mosaicOffset >= 1 + io.mosaicWidth) {
mosaicOffset = 0;
if(!io.mosaic || !mosaicOffset) {
mosaicOffset = 1 + io.mosaicWidth;
mosaic = output;
}
mosaicOffset--;
}
auto PPU::Background::linear(u32 x, u32 y) -> void {
+130
View File
@@ -16,4 +16,134 @@ auto PPU::Debugger::load(Node::Object parent) -> void {
memory.pram->setWrite([&](u32 address, u8 data) -> void {
ppu.pram[address >> 1].byte(address & 1) = data;
});
graphics.tiles4bpp = parent->append<Node::Debugger::Graphics>("4 BPP Tiles");
graphics.tiles4bpp->setSize(512, 384);
graphics.tiles4bpp->setCapture([&]() -> vector<u32> {
vector<u32> output;
output.resize(512 * 384);
for(u32 tileY : range(48)) {
for(u32 tileX : range(64)) {
n32 address = tileY * 64 + tileX << 5;
for(u32 y : range(8)) {
for(u32 x : range(4)) {
n8 colors = ppu.vram[address + y * 4 + x];
n4 leftPixel = colors & 0xf;
n4 rightPixel = colors >> 4;
output[(tileY * 8 + y) * 512 + (tileX * 8 + (x << 1))] = leftPixel * 0x111111;
output[(tileY * 8 + y) * 512 + (tileX * 8 + (x << 1)) + 1] = rightPixel * 0x111111;
}
}
}
}
return output;
});
graphics.tiles8bpp = parent->append<Node::Debugger::Graphics>("8 BPP Tiles");
graphics.tiles8bpp->setSize(256, 384);
graphics.tiles8bpp->setCapture([&]() -> vector<u32> {
vector<u32> output;
output.resize(256 * 384);
for(u32 tileY : range(48)) {
for(u32 tileX : range(32)) {
n32 address = tileY * 32 + tileX << 6;
for(u32 y : range(8)) {
for(u32 x : range(8)) {
n9 color = ppu.vram[address + y * 8 + x];
if(tileY >= 32) color += 0x100; //bottom 1/3 of tile viewer uses OBJ palettes
n15 pixel = ppu.pram[color];
n8 r = pixel >> 0 & 31; r = r << 3 | r >> 2;
n8 g = pixel >> 5 & 31; g = g << 3 | g >> 2;
n8 b = pixel >> 10 & 31; b = b << 3 | b >> 2;
n8 a = 255;
output[(tileY * 8 + y) * 256 + (tileX * 8 + x)] = a << 24 | r << 16 | g << 8 | b << 0;
}
}
}
}
return output;
});
graphics.mode3 = parent->append<Node::Debugger::Graphics>("Mode 3");
graphics.mode3->setSize(240, 160);
graphics.mode3->setCapture([&]() -> vector<u32> {
vector<u32> output;
output.resize(240 * 160);
for(u32 y : range(160)) {
for(u32 x : range(240)) {
n15 pixel = ppu.vram[y * 480 + x * 2 + 1] << 8 | ppu.vram[y * 480 + x * 2] << 0;
n8 r = pixel >> 0 & 31; r = r << 3 | r >> 2;
n8 g = pixel >> 5 & 31; g = g << 3 | g >> 2;
n8 b = pixel >> 10 & 31; b = b << 3 | b >> 2;
n8 a = 255;
output[y * 240 + x] = a << 24 | r << 16 | g << 8 | b << 0;
}
}
return output;
});
graphics.mode4 = parent->append<Node::Debugger::Graphics>("Mode 4");
graphics.mode4->setSize(240, 320);
graphics.mode4->setCapture([&]() -> vector<u32> {
vector<u32> output;
output.resize(240 * 320);
for(u32 y : range(160)) {
for(u32 x : range(240)) {
n8 color = ppu.vram[y * 240 + x];
n15 pixel = ppu.pram[color];
n8 r = pixel >> 0 & 31; r = r << 3 | r >> 2;
n8 g = pixel >> 5 & 31; g = g << 3 | g >> 2;
n8 b = pixel >> 10 & 31; b = b << 3 | b >> 2;
n8 a = 255;
output[y * 240 + x] = a << 24 | r << 16 | g << 8 | b << 0;
}
}
for(u32 y : range(160)) {
for(u32 x : range(240)) {
n8 color = ppu.vram[0xa000 + y * 240 + x];
n15 pixel = ppu.pram[color];
n8 r = pixel >> 0 & 31; r = r << 3 | r >> 2;
n8 g = pixel >> 5 & 31; g = g << 3 | g >> 2;
n8 b = pixel >> 10 & 31; b = b << 3 | b >> 2;
n8 a = 255;
output[(y + 160) * 240 + x] = a << 24 | r << 16 | g << 8 | b << 0;
}
}
return output;
});
graphics.mode5 = parent->append<Node::Debugger::Graphics>("Mode 5");
graphics.mode5->setSize(160, 256);
graphics.mode5->setCapture([&]() -> vector<u32> {
vector<u32> output;
output.resize(160 * 256);
for(u32 y : range(256)) {
for(u32 x : range(160)) {
n15 pixel = ppu.vram[y * 320 + x * 2 + 1] << 8 | ppu.vram[y * 320 + x * 2] << 0;
n8 r = pixel >> 0 & 31; r = r << 3 | r >> 2;
n8 g = pixel >> 5 & 31; g = g << 3 | g >> 2;
n8 b = pixel >> 10 & 31; b = b << 3 | b >> 2;
n8 a = 255;
output[y * 160 + x] = a << 24 | r << 16 | g << 8 | b << 0;
}
}
return output;
});
}
auto PPU::Debugger::unload(Node::Object parent) -> void {
parent->remove(memory.vram);
parent->remove(memory.pram);
parent->remove(graphics.tiles4bpp);
parent->remove(graphics.tiles8bpp);
parent->remove(graphics.mode3);
parent->remove(graphics.mode4);
parent->remove(graphics.mode5);
memory.vram.reset();
memory.pram.reset();
graphics.tiles4bpp.reset();
graphics.tiles8bpp.reset();
graphics.mode3.reset();
graphics.mode4.reset();
graphics.mode5.reset();
}
+16 -16
View File
@@ -8,17 +8,17 @@ auto PPU::readIO(n32 address) -> n8 {
| Background::IO::frame << 4
| objects.io.hblank << 5
| objects.io.mapping << 6
| io.forceBlank << 7
| io.forceBlank[3] << 7
);
case 0x0400'0001: return (
bg0.io.enable << 0
| bg1.io.enable << 1
| bg2.io.enable << 2
| bg3.io.enable << 3
| objects.io.enable << 4
| window0.io.enable << 5
| window1.io.enable << 6
| window2.io.enable << 7
bg0.io.enable[3] << 0
| bg1.io.enable[3] << 1
| bg2.io.enable[3] << 2
| bg3.io.enable[3] << 3
| objects.io.enable[3] << 4
| window0.io.enable << 5
| window1.io.enable << 6
| window2.io.enable << 7
);
//GRSWP
@@ -99,7 +99,6 @@ auto PPU::readIO(n32 address) -> n8 {
}
if(cpu.context.dmaActive) return cpu.dmabus.data.byte(address & 3);
return cpu.pipeline.fetch.instruction.byte(address & 1);
}
@@ -113,14 +112,15 @@ auto PPU::writeIO(n32 address, n8 data) -> void {
Background::IO::frame = data.bit(4);
objects.io.hblank = data.bit(5);
objects.io.mapping = data.bit(6);
io.forceBlank = data.bit(7);
io.forceBlank[3] = data.bit(7);
for(auto& flag : io.forceBlank) flag |= data.bit(7);
return;
case 0x0400'0001:
bg0.io.enable = data.bit(0);
bg1.io.enable = data.bit(1);
bg2.io.enable = data.bit(2);
bg3.io.enable = data.bit(3);
objects.io.enable = data.bit(4);
bg0.setEnable(data.bit(0));
bg1.setEnable(data.bit(1));
bg2.setEnable(data.bit(2));
bg3.setEnable(data.bit(3));
objects.setEnable(data.bit(4));
window0.io.enable = data.bit(5);
window1.io.enable = data.bit(6);
window2.io.enable = data.bit(7);
+6
View File
@@ -6,6 +6,9 @@ auto PPU::readVRAM_BG(u32 mode, n32 address) -> n32 {
}
auto PPU::readVRAM(u32 mode, n32 address) -> n32 {
address &= 0x1ffff;
if(Background::IO::mode >= 3 && address < 0x1c000 && address >= 0x18000) return 0;
address &= (address & 0x10000) ? 0x17fff : 0x0ffff;
if(mode & Word) {
@@ -22,6 +25,9 @@ auto PPU::readVRAM(u32 mode, n32 address) -> n32 {
}
auto PPU::writeVRAM(u32 mode, n32 address, n32 word) -> void {
address &= 0x1ffff;
if(Background::IO::mode >= 3 && address < 0x1c000 && address >= 0x18000) return;
address &= (address & 0x10000) ? 0x17fff : 0x0ffff;
if(mode & Word) {
+20 -7
View File
@@ -1,7 +1,16 @@
auto PPU::Objects::setEnable(n1 status) -> void {
io.enable[3] = status;
for(auto& flag : io.enable) flag &= status;
}
auto PPU::Objects::scanline(u32 y) -> void {
memory::move(io.enable, io.enable + 1, sizeof(io.enable) - 1);
if(y >= 160) return;
mosaicOffset = 0;
auto& buffer = lineBuffers[y & 1];
for(auto& pixel : buffer) pixel = {};
if(ppu.blank() || !io.enable) return;
if(ppu.io.forceBlank[1] || cpu.stopped() || !io.enable[1]) return; //checks if display conditions will be met next scanline
for(auto& object : ppu.object) {
n8 py = y - object.y;
@@ -60,7 +69,7 @@ auto PPU::Objects::scanline(u32 y) -> void {
if(color) {
if(object.colors == 0) color = object.palette * 16 + color;
buffer[bx].enable = true;
buffer[bx].color = ppu.pram[256 + color];
buffer[bx].color = 256 + color;
buffer[bx].translucent = object.mode == 1;
}
}
@@ -74,26 +83,30 @@ auto PPU::Objects::scanline(u32 y) -> void {
auto PPU::Objects::run(u32 x, u32 y) -> void {
output = {};
if(ppu.blank() || !io.enable) {
if(ppu.blank() || !io.enable[0]) {
mosaic = {};
return;
}
auto& buffer = lineBuffers[y & 1];
output = buffer[x];
output.color = ppu.pram[output.color];
//horizontal mosaic
if(mosaicOffset >= 1 + io.mosaicWidth) {
mosaicOffset = 0;
if(!mosaicOffset) {
mosaicOffset = 1 + io.mosaicWidth;
mosaic = output;
} else if(!mosaic.mosaic || !output.mosaic) {
mosaic = output;
}
mosaicOffset++;
mosaicOffset--;
}
auto PPU::Objects::power() -> void {
io = {};
for(auto& pixel : buffer) pixel = {};
for(auto& buffer : lineBuffers) {
for(auto& pixel : buffer) pixel = {};
}
output = {};
mosaic = {};
mosaicOffset = 0;
Loaded 100 of 2058 files, more files were not shown because too many files have changed in this diff. Show more