{"action":"created","comment":{"url":"https://api.github.com/repos/dolphin-emu/dolphin/pulls/comments/23795604","id":23795604,"diff_hunk":"@@ -301,6 +329,49 @@ static void TransferComplete(u64 userdata, int cyclesLate)\n \t}\n }\n \n+static void FinishExecuteReadCommand(u64 userdata, int cyclesLate)\n+{\n+\tDVDReadCommand command;\n+\tcommand.is_valid = false;\n+\n+\t// Because a scheduled event can't contain an entire DVDReadCommand,\n+\t// and because pointers in scheduled events do not work with savestates,\n+\t// an ID is passed instead, which is used to lookup the command in a deque\n+\tfor (auto i = read_commands_to_execute.begin(); i != read_commands_to_execute.end(); ++i)\n+\t{\n+\t\tif (i->id == userdata)\n+\t\t{\n+\t\t\tif (i != read_commands_to_execute.begin())\n+\t\t\t{\n+\t\t\t\t// This shouldn't happen, and it might not even be a\n+\t\t\t\t// problem in case it happens, but it's checked for safety\n+\t\t\t\tWARN_LOG(DVDINTERFACE, \"Read command %u was not first in deque. \"\n+\t\t\t\t         \"Are commands being executed out of order?\", userdata);\n+\t\t\t}\n+\n+\t\t\tcommand = *i;\n+\t\t\tread_commands_to_execute.erase(i);\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\n+\tif (!command.is_valid)\n+\t{\n+\t\t// This shouldn't happen, but it's checked for safety\n+\t\tERROR_LOG(DVDINTERFACE, \"No valid read command was found in deque. Read %u will fail\", userdata);\n+\t}\n+\telse\n+\t{\n+\t\t// Here is the actual disc reading\n+\t\tif (!DVDRead(command.DVD_offset, command.output_address, command.length, command.decrypt))\n+\t\t\tPanicAlertT(\"Can't read from DVD_Plugin - DVD-Interface: Fatal Error\");\n+\t}\n+\n+\t// The final step is to notify the emulated software that the command has been executed\n+\t// There isn't a ScheduleEvent_Immediate, so we use ScheduleEvent_Threadsafe_Immediate\n+\tCoreTiming::ScheduleEvent_Threadsafe_Immediate(command.callback_event_type, command.callback_userdata);","path":"Source/Core/Core/HW/DVDInterface.cpp","position":123,"original_position":123,"commit_id":"be7c451ddc126645d5b1118ff15bb06ecd352008","original_commit_id":"be7c451ddc126645d5b1118ff15bb06ecd352008","user":{"login":"magumagu","id":7026757,"avatar_url":"https://avatars.githubusercontent.com/u/7026757?v=3","gravatar_id":"","url":"https://api.github.com/users/magumagu","html_url":"https://github.com/magumagu","followers_url":"https://api.github.com/users/magumagu/followers","following_url":"https://api.github.com/users/magumagu/following{/other_user}","gists_url":"https://api.github.com/users/magumagu/gists{/gist_id}","starred_url":"https://api.github.com/users/magumagu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/magumagu/subscriptions","organizations_url":"https://api.github.com/users/magumagu/orgs","repos_url":"https://api.github.com/users/magumagu/repos","events_url":"https://api.github.com/users/magumagu/events{/privacy}","received_events_url":"https://api.github.com/users/magumagu/received_events","type":"User","site_admin":false},"body":"Why is this using a CoreTiming event as opposed to a function pointer?","created_at":"2015-01-29T19:33:17Z","updated_at":"2015-01-29T19:33:17Z","html_url":"https://github.com/dolphin-emu/dolphin/pull/1854#discussion_r23795604","pull_request_url":"https://api.github.com/repos/dolphin-emu/dolphin/pulls/1854","_links":{"self":{"href":"https://api.github.com/repos/dolphin-emu/dolphin/pulls/comments/23795604"},"html":{"href":"https://github.com/dolphin-emu/dolphin/pull/1854#discussion_r23795604"},"pull_request":{"href":"https://api.github.com/repos/dolphin-emu/dolphin/pulls/1854"}}},"pull_request":{"url":"https://api.github.com/repos/dolphin-emu/dolphin/pulls/1854","id":27046053,"html_url":"https://github.com/dolphin-emu/dolphin/pull/1854","diff_url":"https://github.com/dolphin-emu/dolphin/pull/1854.diff","patch_url":"https://github.com/dolphin-emu/dolphin/pull/1854.patch","issue_url":"https://api.github.com/repos/dolphin-emu/dolphin/issues/1854","number":1854,"state":"open","locked":false,"title":"DVDInterface: Read disc after delay, not before","user":{"login":"JosJuice","id":6716818,"avatar_url":"https://avatars.githubusercontent.com/u/6716818?v=3","gravatar_id":"","url":"https://api.github.com/users/JosJuice","html_url":"https://github.com/JosJuice","followers_url":"https://api.github.com/users/JosJuice/followers","following_url":"https://api.github.com/users/JosJuice/following{/other_user}","gists_url":"https://api.github.com/users/JosJuice/gists{/gist_id}","starred_url":"https://api.github.com/users/JosJuice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JosJuice/subscriptions","organizations_url":"https://api.github.com/users/JosJuice/orgs","repos_url":"https://api.github.com/users/JosJuice/repos","events_url":"https://api.github.com/users/JosJuice/events{/privacy}","received_events_url":"https://api.github.com/users/JosJuice/received_events","type":"User","site_admin":false},"body":"DVDInterface behavior before 4.0-4222:\r\n* Receive and parse command\r\n* Wait for a while to simulate loading times\r\n* Read data from disc image and copy to emulator memory\r\n* Reply to command\r\n\r\nDVDInterface behavior starting with 4.0-4222:\r\n* Receive and parse command\r\n* Read data from disc image and copy to emulator memory\r\n* Wait for a while to simulate loading times\r\n* Reply to command\r\n\r\nThe former is obviously more accurate, because a real console isn't able to copy all the data to RAM before it has finished reading it from the disc. I changed it in order to not make the code unnecessarily complicated when adding a few things... and games shouldn't be reading the memory that is being copied to, right? Unfortunately, Resident Evil 3 does exactly that, and plays incorrect audio starting with 4.0-2222: https://code.google.com/p/dolphin-emu/issues/detail?id=8026\r\n\r\nThe main obstacle to reverting the order things happen in is that WII_IPC_HLE only can schedule a \"reply to command\" event, not arbitrary things like \"read disc data and reply to command\" that we would need. Because of this, WII_IPC_HLE_Device_DI::IOCtl now returns false and lets DVDInterface::ExecuteCommand schedule an event instead. A second obstacle is that the scheduled event needs to know what data to read. Since DVDInterface now supports WII_IPC_HLE_Device_DI, we can't just read the hardware registers like before 4.0-4222. We can't use pointers in the event userdata either, because it would break savestates. The solution I used is a deque, where a function looks up commands based on an ID that is passed as userdata.\r\n\r\nMost of this solution is actually based on my plans for making a separate thread for disc IO. That has additional reasons for not letting WII_IPC_HLE schedule reads, mainly that it would be nice to be able to finish reads right after the disc IO thread finishes reading from the disc image, but I think this solution is OK for the current requirements too. The good thing is that most of the code in this PR can be used without any change when/if a disc IO thread is made, instead of having to write something similar again.\r\n\r\nBecause this touches WII_IPC_HLE timing, chances are that it will break stuff.","created_at":"2015-01-08T17:47:51Z","updated_at":"2015-01-29T19:33:17Z","closed_at":null,"merged_at":null,"merge_commit_sha":"00198fc3ee0fcb6d0b9e036cb5f9a6dc7890f48a","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/dolphin-emu/dolphin/pulls/1854/commits","review_comments_url":"https://api.github.com/repos/dolphin-emu/dolphin/pulls/1854/comments","review_comment_url":"https://api.github.com/repos/dolphin-emu/dolphin/pulls/comments/{number}","comments_url":"https://api.github.com/repos/dolphin-emu/dolphin/issues/1854/comments","statuses_url":"https://api.github.com/repos/dolphin-emu/dolphin/statuses/be7c451ddc126645d5b1118ff15bb06ecd352008","head":{"label":"JosJuice:read-disc-after-delay","ref":"read-disc-after-delay","sha":"be7c451ddc126645d5b1118ff15bb06ecd352008","user":{"login":"JosJuice","id":6716818,"avatar_url":"https://avatars.githubusercontent.com/u/6716818?v=3","gravatar_id":"","url":"https://api.github.com/users/JosJuice","html_url":"https://github.com/JosJuice","followers_url":"https://api.github.com/users/JosJuice/followers","following_url":"https://api.github.com/users/JosJuice/following{/other_user}","gists_url":"https://api.github.com/users/JosJuice/gists{/gist_id}","starred_url":"https://api.github.com/users/JosJuice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JosJuice/subscriptions","organizations_url":"https://api.github.com/users/JosJuice/orgs","repos_url":"https://api.github.com/users/JosJuice/repos","events_url":"https://api.github.com/users/JosJuice/events{/privacy}","received_events_url":"https://api.github.com/users/JosJuice/received_events","type":"User","site_admin":false},"repo":{"id":26057138,"name":"dolphin","full_name":"JosJuice/dolphin","owner":{"login":"JosJuice","id":6716818,"avatar_url":"https://avatars.githubusercontent.com/u/6716818?v=3","gravatar_id":"","url":"https://api.github.com/users/JosJuice","html_url":"https://github.com/JosJuice","followers_url":"https://api.github.com/users/JosJuice/followers","following_url":"https://api.github.com/users/JosJuice/following{/other_user}","gists_url":"https://api.github.com/users/JosJuice/gists{/gist_id}","starred_url":"https://api.github.com/users/JosJuice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JosJuice/subscriptions","organizations_url":"https://api.github.com/users/JosJuice/orgs","repos_url":"https://api.github.com/users/JosJuice/repos","events_url":"https://api.github.com/users/JosJuice/events{/privacy}","received_events_url":"https://api.github.com/users/JosJuice/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/JosJuice/dolphin","description":"Dolphin is a GameCube/Wii emulator, allowing you to play games for these two platforms on PC, with improvements.","fork":true,"url":"https://api.github.com/repos/JosJuice/dolphin","forks_url":"https://api.github.com/repos/JosJuice/dolphin/forks","keys_url":"https://api.github.com/repos/JosJuice/dolphin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/JosJuice/dolphin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/JosJuice/dolphin/teams","hooks_url":"https://api.github.com/repos/JosJuice/dolphin/hooks","issue_events_url":"https://api.github.com/repos/JosJuice/dolphin/issues/events{/number}","events_url":"https://api.github.com/repos/JosJuice/dolphin/events","assignees_url":"https://api.github.com/repos/JosJuice/dolphin/assignees{/user}","branches_url":"https://api.github.com/repos/JosJuice/dolphin/branches{/branch}","tags_url":"https://api.github.com/repos/JosJuice/dolphin/tags","blobs_url":"https://api.github.com/repos/JosJuice/dolphin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/JosJuice/dolphin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/JosJuice/dolphin/git/refs{/sha}","trees_url":"https://api.github.com/repos/JosJuice/dolphin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/JosJuice/dolphin/statuses/{sha}","languages_url":"https://api.github.com/repos/JosJuice/dolphin/languages","stargazers_url":"https://api.github.com/repos/JosJuice/dolphin/stargazers","contributors_url":"https://api.github.com/repos/JosJuice/dolphin/contributors","subscribers_url":"https://api.github.com/repos/JosJuice/dolphin/subscribers","subscription_url":"https://api.github.com/repos/JosJuice/dolphin/subscription","commits_url":"https://api.github.com/repos/JosJuice/dolphin/commits{/sha}","git_commits_url":"https://api.github.com/repos/JosJuice/dolphin/git/commits{/sha}","comments_url":"https://api.github.com/repos/JosJuice/dolphin/comments{/number}","issue_comment_url":"https://api.github.com/repos/JosJuice/dolphin/issues/comments/{number}","contents_url":"https://api.github.com/repos/JosJuice/dolphin/contents/{+path}","compare_url":"https://api.github.com/repos/JosJuice/dolphin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/JosJuice/dolphin/merges","archive_url":"https://api.github.com/repos/JosJuice/dolphin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/JosJuice/dolphin/downloads","issues_url":"https://api.github.com/repos/JosJuice/dolphin/issues{/number}","pulls_url":"https://api.github.com/repos/JosJuice/dolphin/pulls{/number}","milestones_url":"https://api.github.com/repos/JosJuice/dolphin/milestones{/number}","notifications_url":"https://api.github.com/repos/JosJuice/dolphin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/JosJuice/dolphin/labels{/name}","releases_url":"https://api.github.com/repos/JosJuice/dolphin/releases{/id}","created_at":"2014-11-01T17:12:40Z","updated_at":"2015-01-26T11:54:03Z","pushed_at":"2015-01-27T08:49:48Z","git_url":"git://github.com/JosJuice/dolphin.git","ssh_url":"git@github.com:JosJuice/dolphin.git","clone_url":"https://github.com/JosJuice/dolphin.git","svn_url":"https://github.com/JosJuice/dolphin","homepage":null,"size":213355,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"dolphin-emu:master","ref":"master","sha":"43605f87166cc4bc5e76cec016076aeb6103e24f","user":{"login":"dolphin-emu","id":5050316,"avatar_url":"https://avatars.githubusercontent.com/u/5050316?v=3","gravatar_id":"","url":"https://api.github.com/users/dolphin-emu","html_url":"https://github.com/dolphin-emu","followers_url":"https://api.github.com/users/dolphin-emu/followers","following_url":"https://api.github.com/users/dolphin-emu/following{/other_user}","gists_url":"https://api.github.com/users/dolphin-emu/gists{/gist_id}","starred_url":"https://api.github.com/users/dolphin-emu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dolphin-emu/subscriptions","organizations_url":"https://api.github.com/users/dolphin-emu/orgs","repos_url":"https://api.github.com/users/dolphin-emu/repos","events_url":"https://api.github.com/users/dolphin-emu/events{/privacy}","received_events_url":"https://api.github.com/users/dolphin-emu/received_events","type":"Organization","site_admin":false},"repo":{"id":11577304,"name":"dolphin","full_name":"dolphin-emu/dolphin","owner":{"login":"dolphin-emu","id":5050316,"avatar_url":"https://avatars.githubusercontent.com/u/5050316?v=3","gravatar_id":"","url":"https://api.github.com/users/dolphin-emu","html_url":"https://github.com/dolphin-emu","followers_url":"https://api.github.com/users/dolphin-emu/followers","following_url":"https://api.github.com/users/dolphin-emu/following{/other_user}","gists_url":"https://api.github.com/users/dolphin-emu/gists{/gist_id}","starred_url":"https://api.github.com/users/dolphin-emu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dolphin-emu/subscriptions","organizations_url":"https://api.github.com/users/dolphin-emu/orgs","repos_url":"https://api.github.com/users/dolphin-emu/repos","events_url":"https://api.github.com/users/dolphin-emu/events{/privacy}","received_events_url":"https://api.github.com/users/dolphin-emu/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dolphin-emu/dolphin","description":"Dolphin is a GameCube / Wii emulator, allowing you to play games for these two platforms on PC with improvements.","fork":false,"url":"https://api.github.com/repos/dolphin-emu/dolphin","forks_url":"https://api.github.com/repos/dolphin-emu/dolphin/forks","keys_url":"https://api.github.com/repos/dolphin-emu/dolphin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dolphin-emu/dolphin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dolphin-emu/dolphin/teams","hooks_url":"https://api.github.com/repos/dolphin-emu/dolphin/hooks","issue_events_url":"https://api.github.com/repos/dolphin-emu/dolphin/issues/events{/number}","events_url":"https://api.github.com/repos/dolphin-emu/dolphin/events","assignees_url":"https://api.github.com/repos/dolphin-emu/dolphin/assignees{/user}","branches_url":"https://api.github.com/repos/dolphin-emu/dolphin/branches{/branch}","tags_url":"https://api.github.com/repos/dolphin-emu/dolphin/tags","blobs_url":"https://api.github.com/repos/dolphin-emu/dolphin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dolphin-emu/dolphin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dolphin-emu/dolphin/git/refs{/sha}","trees_url":"https://api.github.com/repos/dolphin-emu/dolphin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dolphin-emu/dolphin/statuses/{sha}","languages_url":"https://api.github.com/repos/dolphin-emu/dolphin/languages","stargazers_url":"https://api.github.com/repos/dolphin-emu/dolphin/stargazers","contributors_url":"https://api.github.com/repos/dolphin-emu/dolphin/contributors","subscribers_url":"https://api.github.com/repos/dolphin-emu/dolphin/subscribers","subscription_url":"https://api.github.com/repos/dolphin-emu/dolphin/subscription","commits_url":"https://api.github.com/repos/dolphin-emu/dolphin/commits{/sha}","git_commits_url":"https://api.github.com/repos/dolphin-emu/dolphin/git/commits{/sha}","comments_url":"https://api.github.com/repos/dolphin-emu/dolphin/comments{/number}","issue_comment_url":"https://api.github.com/repos/dolphin-emu/dolphin/issues/comments/{number}","contents_url":"https://api.github.com/repos/dolphin-emu/dolphin/contents/{+path}","compare_url":"https://api.github.com/repos/dolphin-emu/dolphin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dolphin-emu/dolphin/merges","archive_url":"https://api.github.com/repos/dolphin-emu/dolphin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dolphin-emu/dolphin/downloads","issues_url":"https://api.github.com/repos/dolphin-emu/dolphin/issues{/number}","pulls_url":"https://api.github.com/repos/dolphin-emu/dolphin/pulls{/number}","milestones_url":"https://api.github.com/repos/dolphin-emu/dolphin/milestones{/number}","notifications_url":"https://api.github.com/repos/dolphin-emu/dolphin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dolphin-emu/dolphin/labels{/name}","releases_url":"https://api.github.com/repos/dolphin-emu/dolphin/releases{/id}","created_at":"2013-07-22T09:07:57Z","updated_at":"2015-01-29T15:51:18Z","pushed_at":"2015-01-29T15:51:16Z","git_url":"git://github.com/dolphin-emu/dolphin.git","ssh_url":"git@github.com:dolphin-emu/dolphin.git","clone_url":"https://github.com/dolphin-emu/dolphin.git","svn_url":"https://github.com/dolphin-emu/dolphin","homepage":"https://dolphin-emu.org/","size":270670,"stargazers_count":1008,"watchers_count":1008,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":316,"mirror_url":null,"open_issues_count":60,"forks":316,"open_issues":60,"watchers":1008,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dolphin-emu/dolphin/pulls/1854"},"html":{"href":"https://github.com/dolphin-emu/dolphin/pull/1854"},"issue":{"href":"https://api.github.com/repos/dolphin-emu/dolphin/issues/1854"},"comments":{"href":"https://api.github.com/repos/dolphin-emu/dolphin/issues/1854/comments"},"review_comments":{"href":"https://api.github.com/repos/dolphin-emu/dolphin/pulls/1854/comments"},"review_comment":{"href":"https://api.github.com/repos/dolphin-emu/dolphin/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/dolphin-emu/dolphin/pulls/1854/commits"},"statuses":{"href":"https://api.github.com/repos/dolphin-emu/dolphin/statuses/be7c451ddc126645d5b1118ff15bb06ecd352008"}}}}