Subject: Re: [stella] some little 6502 questions From: Nick S Bensema <nickb@xxxxxxxxxxxx> Date: Fri, 28 Mar 1997 11:15:57 -0700 (MST) |
>Thought my 6502 is good enough for what I'm doing, I'm not a guru and there >are some things that I would like to do in a more efficient way, if >possible. So, if you can help me... Off the top of my head... >...and a better way to check when A is between two values (#amin <= A < #amax): > > (...) > > CMP #amin > BCC outrange ; I don't like... > CMP #amax > BCS outrange ; ...all this jumping... > > (..do what is needed when A is in range..) > > JMP done ; ...isn't there an alternative? > >outrange: > > (..things to do when A is out of range..) > >done: > > (...) If you have two separate, mutually exclusive things to do depending on whether A is in-range, that looks about right, though off the top of my head: CMP #amin ;+2 = (2) BCC OutRange ;+2 = (4) (If branch, +3 = (5)) CMP #amax ;+2 = (6) BCS OutRange ;+2 = (8) (If branch, +3 = (9)) DO_INRANGE_STUFF ;+X = (8+x) Arrives here in 8 cycles JMP done ;+3 = (11+X) OutRange DO_OUTRANGE_STUFF ;+Y = (5+Y or 9+Y) Done ETC Now it all fits in a small section of the screen and still makes sense, as long as you don't look at the cycle counts. I used X and Y to represent the values of the omitted mystery code represented here by the "DO_INRANGE_STUFF" and "DO_OUTRANGE_STUFF" instructions. The act of deciding whether to go to InRange added to the the jump past OutRange takes up 11 cycles, not bad. It'll take 10 cycles if you find a way to substitute JMP with an unconditional branch, i.e. immediately after an LDA #0 and STA, a BEQ would do the trick because the CPU still has the #0 in its head. OutRange is even better; the CPU takes only 5 or 9 cycles to decide to go there. Adding up the bytes really quick, the mandatory amount of code you'll need to have is 11 bytes, or 10 if you replace JMP with a branch. Keep in mind you'll need a few more cycles, and possibly more bytes if you use other addressing modes for the CMP instructions, but lucky for you CMP is a versatile instruction, so you can store the ranges in memory, assign different ranges to different players at the same time, or whatever else you can think of without much trouble. Not too shabby. Not all 6502 can be even that elegant; with all the limitations. -- Archives available at http://www.biglist.com/lists/stella/archives/ E-mail UNSUBSCRIBE in the body to stella-request@xxxxxxxxxxx to be removed.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[stella] some little 6502 questions, Piero Cavina | Thread | [stella] archiving binaries and fil, Glenn Saunders |
Re: [stella] another demo (don't sa, Piero Cavina | Date | Re: [stella] another demo (don't sa, Glenn Saunders |
Month |