Hello,
Can anyone translate me this 68k code into C (or ppc asm..)
putreg(REG_D1, 0); do { *bw = *(UWORD *)((UBYTE *)*plane-- + offset) >> shift; putreg(REG_A0, (long)bw); __emit(0xE4D0); /* ROXR.W (A0) */ __emit(0xE351); /* ROXL.W #1,D1 */ ++bw; } while (--d > 0);
The first one seems a simply shift? or i ame wrong?
Well, it is not a "simple" shift because the bit which is shifted out on the right is moved into the X status bit. The second instruction shifts to the left and the new LSB is not just 0 but becomes the value of the X bit.
One could translate this into
X = (*A0) & 1; (*A0) >>= 1;
D1 = (D1 << 1) | X;
or a bit optimised
D1 = (D1 << 1) | ((*A0) & 1);
(*A0) >>= 1;
unlucky it doesn't seems works as expected.. at least seeing the original 68k version..
But maybe could be this one the problem.
I've used your code in this way:
Is this right? That instruction seems to have a post increment.
And also. Is this correct to use the code in that way? (also for the original post)
You still have difficulties understanding the difference between BWord and *BWord, haven't you?
Firstly, the original code moves BWord into A0 and then modifies A0 in a loop but it never moves the modified A0 back to BWord. This means you should not modify BWord in your code.
And secondly (A0)+ means that it accesses the address to which A0 points and then increments A0. The increment should be translated into A0++ and not into (*A0)++ like you do.
damned copy & paste.. i didn't spot the missing "*"...
so it will became
is this correct? (i didn't test it.. i'm at work..)
but is the increment needed or not? from your words "This means you should not modify BWord in your code." i understand that i shouldn't touch it. But if so.. when the increment is done?
This code:
turned into C should be:
all seems working correctly.. but i think there is this function that is needed even if i've used the ReadPixel from gfx library.. but it seems not correct:
my ReadPix is:
But the pixel read from the program seems wrong..
Since the assembler code is done as a data array a very simple, although not so efficient solution would be to just call the m68k emulator on it like so:
uh.. just tried.. i get a DSI when the function is called. And the stack trace points to 68k code.
Well from a quick look at the assembler code this should be a suitable C replacement:
It's not identical in that the assembler code handles the bitplanes in the opposite order but the end result should be the same.
ok mate.. line 9 was: res |= (1 << *plane) but it works.. like the other soultion (EmulateTags). I've found the problem of the DSI...my error..
So now i'm 100% sure that ReadPix function works because i can see the color under mouse position and is the correct one..
So the problem is for sure in that other file. And so in the that two functions. Your function seems to work correctly but this one:
seems always wrong..
@afxgroup
That line 9 should have been "res |= (1 << i);". I've fixed it in the post above. While working on the code I changed around the names of the variables and simply forgot to change it in this one line.
Just a thought, where does the bitmap come from that is passed to ReadPix()? The function as it is now will only work with a planar bitmap and will DSI and return completely wrong results if passed a chunky bitmap.
100% C version of this code:
should be:
Yes the funcion is called only when there is a planar bitmap.