danwinslow Posted September 3, 2015 Author Share Posted September 3, 2015 That's the joy of 6502. Code is never "definitive". This thread continues to deliver. That's really true about 6502...it's something about the balance between limitations and capability that is just at a perfect point. I have noticed that the pleasures of many endeavors are based on the limitations, and not the capabilities. If it's too easy, its not interesting, and if it's too hard it's not interesting either. 1 Quote Link to comment Share on other sites More sharing options...
Irgendwer Posted September 3, 2015 Share Posted September 3, 2015 (edited) Could you elaborate these three things ? I think he means something like ldx offsetInTable stx lowByteOfTable lda table,x lowByteOfTable = * -2 to have a two byte offset access. Normally it is faster (and ROM compatible) to separate hi and low bytes to different tables, but this is not an option for jump-addresses. Edited September 3, 2015 by Irgendwer 2 Quote Link to comment Share on other sites More sharing options...
NorthWay Posted September 3, 2015 Share Posted September 3, 2015 (edited) Could you elaborate these three things ? WordTable equ $1000 ;page aligned WordPtr equ $f0 lda >#WordTable ;init sta WordPtr+1 ;init ldy byteindex sty WordPtr lda (WordPtr),y ;y+y == 2*y iny lda (WordPtr),y ;second byte of word Or a SMC variation. But this makes more sense on a cpu that can do word accesses. The next one is more primitive ldx IndexByte lda JumpOffset,x ;4? sta JumpSMC+1 ;4? JumpSMC: jmp JumpLabel ;3 cnop 0,256 ;page align JumpLabel: jmp byte0 ;3 jmp byte1 ... jmp byte85 JumpOffset: dc .b 0*3 dc.b 1*3 dc.b 2*3 ... dc.b 85*3 byte0: ; code for index 0 starts here Which is a byte-size indexed jump in 14 cycles. For the full 0-255 range it takes 19 cycles SMC (20 using non-SMC stack). For the sorting in Tyger Tyger it is basically a massive cheat that looks a little bit like this lda Y_position lsr tax txs loop: pla bmi loop then stuff your sort index on the stack with a pha The idea is to just search for free slots on the stack where you can insert your array index and hope that things gets reasonably in order, and when you are done you can pop the stack and easily get your objects. Kind of a bucket sort? Insertion sort? Radix sort? Very much a case of "good enough". See thread that uses it here: http://www.lemon64.com/forum/viewtopic.php?t=5839 I guess you have seen Linus' loader info. For reference Linus' own page on it http://www.linusakesson.net/programming/gcr-decoding/index.php Edited September 3, 2015 by NorthWay 1 Quote Link to comment Share on other sites More sharing options...
popmilo Posted September 3, 2015 Share Posted September 3, 2015 Cool trick with "doubling by indexing"! Never thought of using that for reaching two byte tables. Funny considering I've used it in a more general case of using "indexing for adding". Table at AA00 and LDA AABB,x for calculating f(BB+x). Must admit my jump table approaches were at least 3 cycles slower Will remember that for when it's needed. Thanks for reminding us on that stack based sprite sorting method. Found more info here: http://www.c64.com/interviews/hughes.html "Basically, all the Y split positions were indexed directly into to stack memory. I could then easily do a quick insertion sort by setting the point of insertion into the stack pointer and then pushing the position in the list – the stack magically took care of the rest." And yeah 1541 loader is also a great example of 6502 coding. 1 Quote Link to comment Share on other sites More sharing options...
danwinslow Posted September 3, 2015 Author Share Posted September 3, 2015 hah, that Tyger Tyger thing is cool. 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.