my call rutine of getting single byte from cog ram long
tonyp12
Posts: 1,951
Most of the time, I simple use longs even if the data always are less than the value of 256.
But maybe you try to save space and sometimes you are simple forced to have the data as bytes.
So I come up with this routine, you set the byte you want in bytepnt before you make the call.
Then it comes back with the answer in mybyte.
It does not trash bytepnt, so it can used as a global variable in your code that you add/sub to etc.
I have not tested it, but it should work.
Any shorter routines you Prop Heads have come up with?
But maybe you try to save space and sometimes you are simple forced to have the data as bytes.
So I come up with this routine, you set the byte you want in bytepnt before you make the call.
Then it comes back with the answer in mybyte.
It does not trash bytepnt, so it can used as a global variable in your code that you add/sub to etc.
I have not tested it, but it should work.
Any shorter routines you Prop Heads have come up with?
main mov bytepnt,#3 'just an example call #getbyte movs dosomething,mybyte 'just an example ... ... jmp #main getbyte mov bytepntbuf, bytepnt 'don't trash bytepnt shr bytepntbuf,#2 'divide by 4 movs findbyte,#data 'start location of our byte table add findbyte, bytepntbuf 'add the divided-by-4 byte pointer mov bytepntbuf, bytepnt 'start with a fresh bytepointer and bytepntbuf,#%11 'keep only the 2 lower bits shl bytepntbuf,#3 'multiply by 8 findbyte mov mybyte,0-0 shr mybyte,bytepntbuf 'find the right byte from a long and mybyte,#$ff 'keep only the lower 8 bits getbyte_ret ret 'return, with answer in mybyte data byte 0,10,20,30 bytepnt res 1 mybyte res 1 bytepntbuf res 1
Comments
by using ror as movs only transfer the lower 9bits.
The shr must be 27 not 28 (30-3)
Andy
So the long used up by op-code 'call' would not cancel out the space saving.
And that your table is at least 12 bytes long.
That I can add 1 or 2 to the bytenct as my code checks for specific char etc is useful and maybe then sub 1.
Without thinking about byte boundery in a long.
Compared to this cludge I used first, were I loop the shifter from 0-to24 and reset if it hit 32 and add 1 to longcnt
Does not easy allow to look forward two bytes and then back up one.