As this comes up every now and then I though I would just make a solid reference, maybe it should also go on the wiki?
now there are some cavets to the above, anything thing that looks up the Direct Page or Stack will wrap inside bank 00, fetch the value and then add the index which will then cross a bank.
so (dp),y for example
this first does D+dp and this wraps in bank 00, it will read the value, make that DBR relative and then add Y.So for the DP and Stack relative operations any modification to the DP or Stack value is wrapped in bank 00 then converted. So you have to be away of multiple potential bank crossings or wrappings. But 99.9% of the time you will keep all Stack and DP operations well within the bank, but there is also that rouge code that gives you a very large index by mistake that just so happens to be $FFFF or FFFE so it ends up reading the byte before it rather than it which is very confusing.
Code:
(abs,x) = PBR|word(Address+x) ; wraps in Program bankabs,x = (DBR|Address)+x ; crosses bankabs,y = (DBR|Address)+y ; crosses banklong,x = Address+x ; crosses bank(dp,x) = 00|word(Address+x) ; wraps in bank 00(dp),y = (DBR|word(dp))+y ; crosses bankdp,x = 00|word(Address+x) ; wraps in bank 00dp,y = 00|word(Address+y) ; wraps in bank 00[dp],y = (00|Address)+y ; crosses bankdp = 00|word(DP+offset) ; wraps in bank 00o,s = 00|stack+o ; wraps in bank 00(o,s),y = (DBR|(stack+o))+y ; crosses bank
so (dp),y for example
this first does D+dp and this wraps in bank 00, it will read the value, make that DBR relative and then add Y.
Code:
Given D = $FFFE $03 holds $FF, $04 holds $00 Y is 16bits and set to $0123DBR is $85and we perform lda ($05),yso D + 5 = $FFFE+5 = $100003 which is wrapped to 000004fetch the 16 pointer from $000003,$000004 which gives us $00FF00we then add DBR to it, so $85FF00we then add y, so $85FF00+$0123 = $860023
Statistics: Posted by Oziphantom — Sat Aug 31, 2024 11:47 pm — Replies 0 — Views 75