Zach Posted November 27, 2006 Share Posted November 27, 2006 I’ve been working on a kernel where I want to clear bit 2 of VBLANK, but A, X, and Y are all being used for other purposes. I figured out a couple ways to accomplish this, use PHP and make sure the last value loaded was non-zero, or use SHX VBLANK - #OFFSET, Y. Both approaches have pros and cons. What I’m wondering is whether it is a good idea to use SHX? Searching the forums for the SHX, I found that supercat had some ideas for using it (actually similar to the use I am describing). On the other hand, Thomas mentioned that $9E is unstable, and sure enough, that opcode is SHX. Any thoughts? Quote Link to comment Share on other sites More sharing options...
+batari Posted November 27, 2006 Share Posted November 27, 2006 I’ve been working on a kernel where I want to clear bit 2 of VBLANK, but A, X, and Y are all being used for other purposes. I figured out a couple ways to accomplish this, use PHP and make sure the last value loaded was non-zero, or use SHX VBLANK - #OFFSET, Y. Both approaches have pros and cons. What I’m wondering is whether it is a good idea to use SHX? Searching the forums for the SHX, I found that supercat had some ideas for using it (actually similar to the use I am describing). On the other hand, Thomas mentioned that $9E is unstable, and sure enough, that opcode is SHX. Any thoughts? I thought the only "unstable" opcodes were those that can jam the CPU, (all $x2 except $A2) and ANE and LXA, as they involve an AND with a constant of unknown value. My impression of opcodes like $9E is that they are stable, but unusual. Other unusual instructions are SHS, SHA, SHY, LAS, ANC, ARR, ASR, ANE, LXA, and SBX. Personally, the problem I see with SHX is that it's anded with PCH+1 and indexed with Y, so it seems quite troublesome to use it. Quote Link to comment Share on other sites More sharing options...
+batari Posted November 28, 2006 Share Posted November 28, 2006 I’ve been working on a kernel where I want to clear bit 2 of VBLANK, but A, X, and Y are all being used for other purposes. I figured out a couple ways to accomplish this, use PHP and make sure the last value loaded was non-zero, or use SHX VBLANK - #OFFSET, Y. Both approaches have pros and cons. What I’m wondering is whether it is a good idea to use SHX? Searching the forums for the SHX, I found that supercat had some ideas for using it (actually similar to the use I am describing). On the other hand, Thomas mentioned that $9E is unstable, and sure enough, that opcode is SHX. Any thoughts? I thought the only "unstable" opcodes were those that can jam the CPU, (all $x2 except $A2) and ANE and LXA, as they involve an AND with a constant of unknown value. My impression of opcodes like $9E is that they are stable, but unusual. Other unusual instructions are SHS, SHA, SHY, LAS, ANC, ARR, ASR, ANE, LXA, and SBX. Personally, the problem I see with SHX is that it's anded with PCH+1 and indexed with Y, so it seems quite troublesome to use it. More research indicates that apparently SHA, SHS, SHX and SHY sometimes don't get anded with PCH+1, and if the index crosses a page boundary, it isn't handled properly. Those problems aren't necessarily fatal. Quote Link to comment Share on other sites More sharing options...
Zach Posted November 28, 2006 Author Share Posted November 28, 2006 More research indicates that apparently SHA, SHS, SHX and SHY sometimes don't get anded with PCH+1, and if the index crosses a page boundary, it isn't handled properly. Those problems aren't necessarily fatal. Thanks Fred, unless Y is 0 or 1, I would have to cross a page boundary to reach VBLANK. So it seems that I should not use SHX for this purpose. No problem, I'll just use PHP. Quote Link to comment Share on other sites More sharing options...
+batari Posted November 28, 2006 Share Posted November 28, 2006 (edited) More research indicates that apparently SHA, SHS, SHX and SHY sometimes don't get anded with PCH+1, and if the index crosses a page boundary, it isn't handled properly. Those problems aren't necessarily fatal. Thanks Fred, unless Y is 0 or 1, I would have to cross a page boundary to reach VBLANK. So it seems that I should not use SHX for this purpose. No problem, I'll just use PHP. You could use the TIA mirror of VBLANK at $41, which would give you more usable Y values. I'm not sure if that's enough, though. Edited November 28, 2006 by batari Quote Link to comment Share on other sites More sharing options...
Zach Posted November 30, 2006 Author Share Posted November 30, 2006 (edited) You could use the TIA mirror of VBLANK at $41, which would give you more usable Y values. I'm not sure if that's enough, though. That's a good point, but it still limits the possible values of Y. FWIW, I did test the SHX version of my kernel on a 4 switch system, and it looks good so far. I used the instruction SHX $FFC7,Y when Y=3A and X=06, and it did indeed clear VBLANK. Since bit 1 of X is 1, the bitwise AND with (FF+1) must have worked, even though the page boundary was crossed. Maybe we would get different results on different systems. I guess SHX is not thoroughly understood, and it'll be safer to use PHP. Besides I haven't found anything useful to do with the 2 cycles I save in my kernel. (SHX takes 5 cycles, PHP takes 7 when you account for resetting the SP.) Edited December 3, 2006 by Zach Quote Link to comment Share on other sites More sharing options...
+batari Posted December 1, 2006 Share Posted December 1, 2006 You could use the TIA mirror of VBLANK at $41, which would give you more usable Y values. I'm not sure if that's enough, though. That's a good point, but it still limits the possible values of Y. FWIW, I did test the SHX version of my kernel on a 4 switch system, and it looks good so far. I used the instruction SHX $FFC7,Y when Y=3A and X=06, and it did indeed clear VBLANK. Since bit 2 of X is 1, the bitwise AND with (FF+1) must have worked, even though the page boundary was crossed. Maybe we would get different results on different systems. I guess SHX is not thoroughly understood, and it'll be safer to use PHP. Besides I haven't found anything useful to do with the 2 cycles I save in my kernel. (SHX takes 5 cycles, PHP takes 7 when you account for resetting the SP.) The only documentation I've seen about SHX says that, for instance, if X=$06 and you do SHX $FFC7,Y the actual bank where the value gets stored in a page-wrapping condition will be either $00 or $06, but since $06 happens to contain a TIA mirror, it should work just the same. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.