{"url":"https://api.github.com/repos/stella-emu/stella/issues/97","repository_url":"https://api.github.com/repos/stella-emu/stella","labels_url":"https://api.github.com/repos/stella-emu/stella/issues/97/labels{/name}","comments_url":"https://api.github.com/repos/stella-emu/stella/issues/97/comments","events_url":"https://api.github.com/repos/stella-emu/stella/issues/97/events","html_url":"https://github.com/stella-emu/stella/issues/97","id":209986293,"node_id":"MDU6SXNzdWUyMDk5ODYyOTM=","number":97,"title":"Revisit the 'mystery constant' in M6532.cxx","user":{"login":"DirtyHairy","id":2444224,"node_id":"MDQ6VXNlcjI0NDQyMjQ=","avatar_url":"https://avatars.githubusercontent.com/u/2444224?v=4","gravatar_id":"","url":"https://api.github.com/users/DirtyHairy","html_url":"https://github.com/DirtyHairy","followers_url":"https://api.github.com/users/DirtyHairy/followers","following_url":"https://api.github.com/users/DirtyHairy/following{/other_user}","gists_url":"https://api.github.com/users/DirtyHairy/gists{/gist_id}","starred_url":"https://api.github.com/users/DirtyHairy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DirtyHairy/subscriptions","organizations_url":"https://api.github.com/users/DirtyHairy/orgs","repos_url":"https://api.github.com/users/DirtyHairy/repos","events_url":"https://api.github.com/users/DirtyHairy/events{/privacy}","received_events_url":"https://api.github.com/users/DirtyHairy/received_events","type":"User","user_view_type":"public","site_admin":false},"labels":[{"id":453306380,"node_id":"MDU6TGFiZWw0NTMzMDYzODA=","url":"https://api.github.com/repos/stella-emu/stella/labels/enhancement","name":"enhancement","color":"84b6eb","default":true,"description":null,"archived_at":null,"archived_by":null},{"id":489151886,"node_id":"MDU6TGFiZWw0ODkxNTE4ODY=","url":"https://api.github.com/repos/stella-emu/stella/labels/affects%206502.ts","name":"affects 6502.ts","color":"e08080","default":false,"description":null,"archived_at":null,"archived_by":null},{"id":497208665,"node_id":"MDU6TGFiZWw0OTcyMDg2NjU=","url":"https://api.github.com/repos/stella-emu/stella/labels/needs%20research","name":"needs research","color":"f9d0c4","default":false,"description":null,"archived_at":null,"archived_by":null}],"state":"closed","locked":false,"assignees":[],"milestone":null,"comments":45,"created_at":"2017-02-24T08:21:48Z","updated_at":"2017-03-14T22:43:01Z","closed_at":"2017-03-14T22:42:48Z","assignee":null,"author_association":"MEMBER","issue_field_values":[],"type":null,"active_lock_reason":null,"sub_issues_summary":{"total":0,"completed":0,"percent_completed":0},"issue_dependencies_summary":{"blocked_by":0,"total_blocked_by":0,"blocking":0,"total_blocking":0},"body":"According to commit history, the 'mystery constant' from Z26 was reintroduced to fix a hang in Mr. Roboto, while a simple comparision `timer >= 0` is all that should be necessary.\r\n\r\n      if(!(timer & 0x40000))\r\n      {\r\n        // Return at 'divide by TIMxT' interval rate\r\n        return (timer >> myIntervalShift) & 0xff;\r\n      }\r\n\r\nWhile working on fixing the remaining bugs in the 6502.ts RIOT implementation, I have made an interesting observation: while I promptly got the hang after the intro screen in 6502.ts (it is fixed now), I cannot reproduce it in Stella by changing the code to `timer >= 0` anymore!\r\n\r\nAnalysis suggests that RSYNC actually was the culprit and that our new RSYNC fixes the issues, while the old code above is more of a band aid to avoid the side effects :smirk: What happens is the following: after the title screen, Mr. Roboto writes to TIM64T, then goes through the canonical write-zero-to-everything-in-page-zero loop, supposedly from the original Bezerk code. In this init loop, RSYNC is anadvertedly hit and, if implemented correclty, fast-forwards the TIA playfield counter. Further down the lane, the code does a WSYNC, and the number of cycles that is skipped depends on the preceeding RSYNC. The hang is then caused by a loop that polls INTIM until it is zero. At this point, the counter will have wrapped and be counting down each cycle --- if timing is off, it will never read zero, and the game hangs :8ball:\r\n\r\nThe old implementation gets out of this situation by switching back to counting in TIM64T mode after bit 18 of `timer` flips again --- in this mode, the zero value is held for 64 cycles, which is long enough to escape the loop. With the new RSYNC simulation, timing works out in the right way, and the loop exits naturally.\r\n\r\n@sa666666 , do you have any other examples of ROMs that failed with `timer > 0`? If my assumptions are correct, these should work now, too, and we can remove the cludge (which I strongly suspect differs from real hardware after bit 18 flips for the second time).","closed_by":{"login":"DirtyHairy","id":2444224,"node_id":"MDQ6VXNlcjI0NDQyMjQ=","avatar_url":"https://avatars.githubusercontent.com/u/2444224?v=4","gravatar_id":"","url":"https://api.github.com/users/DirtyHairy","html_url":"https://github.com/DirtyHairy","followers_url":"https://api.github.com/users/DirtyHairy/followers","following_url":"https://api.github.com/users/DirtyHairy/following{/other_user}","gists_url":"https://api.github.com/users/DirtyHairy/gists{/gist_id}","starred_url":"https://api.github.com/users/DirtyHairy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DirtyHairy/subscriptions","organizations_url":"https://api.github.com/users/DirtyHairy/orgs","repos_url":"https://api.github.com/users/DirtyHairy/repos","events_url":"https://api.github.com/users/DirtyHairy/events{/privacy}","received_events_url":"https://api.github.com/users/DirtyHairy/received_events","type":"User","user_view_type":"public","site_admin":false},"reactions":{"url":"https://api.github.com/repos/stella-emu/stella/issues/97/reactions","total_count":0,"+1":0,"-1":0,"laugh":0,"hooray":0,"confused":0,"heart":0,"rocket":0,"eyes":0},"timeline_url":"https://api.github.com/repos/stella-emu/stella/issues/97/timeline","performed_via_github_app":null,"state_reason":"completed","pinned_comment":null}