{"action":"created","issue":{"url":"https://api.github.com/repos/xqemu/xqemu/issues/92","repository_url":"https://api.github.com/repos/xqemu/xqemu","labels_url":"https://api.github.com/repos/xqemu/xqemu/issues/92/labels{/name}","comments_url":"https://api.github.com/repos/xqemu/xqemu/issues/92/comments","events_url":"https://api.github.com/repos/xqemu/xqemu/issues/92/events","html_url":"https://github.com/xqemu/xqemu/pull/92","id":344235778,"node_id":"MDExOlB1bGxSZXF1ZXN0MjAzNjc5ODk5","number":92,"title":"Implement support for APU DSP Memory access (fix EP, add GP)","user":{"login":"JayFoxRox","id":360330,"node_id":"MDQ6VXNlcjM2MDMzMA==","avatar_url":"https://avatars1.githubusercontent.com/u/360330?v=4","gravatar_id":"","url":"https://api.github.com/users/JayFoxRox","html_url":"https://github.com/JayFoxRox","followers_url":"https://api.github.com/users/JayFoxRox/followers","following_url":"https://api.github.com/users/JayFoxRox/following{/other_user}","gists_url":"https://api.github.com/users/JayFoxRox/gists{/gist_id}","starred_url":"https://api.github.com/users/JayFoxRox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JayFoxRox/subscriptions","organizations_url":"https://api.github.com/users/JayFoxRox/orgs","repos_url":"https://api.github.com/users/JayFoxRox/repos","events_url":"https://api.github.com/users/JayFoxRox/events{/privacy}","received_events_url":"https://api.github.com/users/JayFoxRox/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-07-24T23:12:35Z","updated_at":"2018-07-25T07:01:51Z","closed_at":null,"author_association":"MEMBER","pull_request":{"url":"https://api.github.com/repos/xqemu/xqemu/pulls/92","html_url":"https://github.com/xqemu/xqemu/pull/92","diff_url":"https://github.com/xqemu/xqemu/pull/92.diff","patch_url":"https://github.com/xqemu/xqemu/pull/92.patch"},"body":"This is required to read-back results of MCPX APU DSP calculations more easily, so without this change, debugging the DSP from the outside is a lot harder.\r\n\r\nThis is code from 2017, but it has gotten a lot of additional unit testing and research on actual hardware the past weeks.\r\n\r\nOnce this patch is applied, we can use xboxpy and my existing dsp-homebrew script to send custom code to the DSP. This allows us to verify instruction behaviour, as the script also works with a real Xbox.\r\n\r\nI was unsure about the DSP memory sizes, but then decided to confirm them:\r\n\r\n<details><summary>I have written a program to measure the DSP data memory sizes (Click to unfold)</summary><br>\r\n\r\nHere is the code for measuring Y-Memory size:\r\n\r\n```\r\nstart\r\n  move y:$<address>, a0\r\n  move a0, x:$000000\r\n  jmp start\r\n```\r\n\r\nWhere `<address>` was raised using a step-size.\r\nI then wrote a random value to `y:$<address>` using the CPU and checked if it appeared in `x:$000000`. I did this for 2 random values per `<address>`. When any of these checks failed, the previous `<address>` was reverted and a smaller step-size was used.\r\n\r\nFor measuring the size of X-Memory instead of Y-Memory I have simply swapped `x:` and `y:` (and respective lookups on the CPU).\r\nFor measuring the size of the MIXBUF, I set a higher start offset (0x1400) in X-Memory and re-ran the same program as before for measuring X-Size. Strangely, I got 0x7E0 words here. The last 0x20 words were not accessible. See known problem below.\r\n\r\n</details>   <details><summary>I also wrote a program to measure the DSP program memory size (Click to unfold)</summary>\r\n\r\nHere is the code for measuring P-Memory size:\r\n\r\n```\r\nstart\r\n  move y:$000000, a0\r\n  <nops>\r\n  move a0, x:$000000\r\n  jmp start\r\n```\r\n\r\nWhere `<nops>` is an increasing number of `nop` instructions. By raising the number of `nop` instructions, the write to `x:$000000` will eventually be outside of program memory. This will result in either the value in `y:$000000` not updating or the Xbox crashing.\r\nKeep in mind that the other instructions take up some memory (6 words) so the number of `nop` instructions (1 word each) is not the same as the program memory size.\r\n</details><br>\r\n\r\n[The results of these tests have been added to XboxDevWiki](http://xboxdevwiki.net/DSP#Memory_Size).\r\n\r\nAccording to existing code, the last 0x400 words of GP X-Memory (so, offset 0xC00) should be MIXBUF. My tests could not confirm this behaviour. I have observed MIXBUF at `x:$001400`, 0x380 words (See problem regarding size below).\r\nI assume that DirectSound uses the last 0x400 words of X-Memory RAM for the DMA from the actual MIXBUF; but X-Memory RAM has no relation to MIXBUF in hardware.\r\n\r\n### Known problems\r\n\r\n#### Only 32 bit access works\r\n\r\nAlso see #91.\r\n\r\nThis might cause trouble in games, so this PR should be tested with a handful of games.\r\nI did not test a single game yet.\r\n\r\n#### MIXBUF size not known\r\n\r\nI was unable to access the last 0x20 words of MIXBUF with my unit test.\r\n\r\nI assume this might have to do with VP or EP having control and overwriting my data. I still assume a size of 0x400 bytes, not 0x380; so I implemented 0x400 in XQEMU, but documented 0x380 for now. To be fair, I was surprised that I had write access to MIXBUF at all, as I had assumed the VP would instantly overwrite data.\r\n\r\n#### EP and GP use the same memory map in XQEMU\r\n\r\nMemory size defines are used by both DSP instances, so we use the same memory map for GP and EP.\r\n\r\nThis is not so much a problem with this PR, but XQEMU in general. This even means that the EP currently has MIXBUF access which is not possible on real hardware.\r\n\r\nI'll create an issue after merge. I did not fix it here because it leads to design decisions and what we have works (our EP is just more powerful than on real hardware).\r\n\r\n---\r\n\r\nThis patch *could* fix bugs in the following games:\r\n\r\n* Top Gear RPM Tuning\r\n* Grand Theft Auto: San Andreas\r\n\r\nThese games previously ran into the following issue in dsp_cpu: `assert(address < DSP_XRAM_SIZE);`.\r\n\r\nHowever, I did not test those games because it's not the motivation for this patch: I just want to be able to debug the DSP.\r\n\r\n---\r\n\r\nIf you want to [test this PR with my DSP homebrew](https://github.com/JayFoxRox/xbox-tools/tree/master/python-scripts): nxdk-rdt still does not support `CALL` in master yet (meaning it can't remote control the DSP using existing code).\r\nYou will need to look for nxdk-rdt and xboxpy PRs to work around this.\r\nTesting using XBDM should work fine."},"comment":{"url":"https://api.github.com/repos/xqemu/xqemu/issues/comments/407654758","html_url":"https://github.com/xqemu/xqemu/pull/92#issuecomment-407654758","issue_url":"https://api.github.com/repos/xqemu/xqemu/issues/92","id":407654758,"node_id":"MDEyOklzc3VlQ29tbWVudDQwNzY1NDc1OA==","user":{"login":"gandalfthewhite19890404","id":24764335,"node_id":"MDQ6VXNlcjI0NzY0MzM1","avatar_url":"https://avatars3.githubusercontent.com/u/24764335?v=4","gravatar_id":"","url":"https://api.github.com/users/gandalfthewhite19890404","html_url":"https://github.com/gandalfthewhite19890404","followers_url":"https://api.github.com/users/gandalfthewhite19890404/followers","following_url":"https://api.github.com/users/gandalfthewhite19890404/following{/other_user}","gists_url":"https://api.github.com/users/gandalfthewhite19890404/gists{/gist_id}","starred_url":"https://api.github.com/users/gandalfthewhite19890404/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gandalfthewhite19890404/subscriptions","organizations_url":"https://api.github.com/users/gandalfthewhite19890404/orgs","repos_url":"https://api.github.com/users/gandalfthewhite19890404/repos","events_url":"https://api.github.com/users/gandalfthewhite19890404/events{/privacy}","received_events_url":"https://api.github.com/users/gandalfthewhite19890404/received_events","type":"User","site_admin":false},"created_at":"2018-07-25T07:01:51Z","updated_at":"2018-07-25T07:01:51Z","author_association":"NONE","body":"Here is screenshot with this PR:\r\nhttps://cdn.discordapp.com/attachments/430847916857622539/471565766299222016/unknown.png"}}
{"actor":{"display_login":"gandalfthewhite19890404"}}