Translate java to Blitzmax

Started by Baggey, February 16, 2024, 07:57:24

Previous topic - Next topic

Baggey

Not sure were to put this but i want to understand a line of Java explained in BlitzMax.

I have a line of code in java which im trying to understand or need translated into Blitzmax. As i have no idea of java im struggling with learning it. So im asking for someones experience/help with it.

F = (result & 0x10000 ? FLAG_C : 0) | overflowAddTable[lookup >> 4] | ((result >> 8) & (FLAG_3 | FLAG_5 | FLAG_S)) | halfcarryAddTable[lookup & 0x07] | ((result & 0xffff) ? 0 : FLAG_Z);
This bit here (result & 0x10000 ? FLAG_C : 0)   Am i right in understanding this as If (result & $1000) then F=FLAG_C else F=0
also,
(result & 0xffff) ? 0 : FLAG_Z) would be If (result & $FFFF) then F=0 else F=FLAG_Z

I see the use of | ie, oring Bits, so i need something to do with bits of the Flags.

Anyone who knows Java or understands the above care to explain more whats happening? :-\

Im trying to get an Adc16() operation altering the correct flags?

Thankyou in advance Baggey
Running a PC that just Aint fast enough!? i7 4Ghz Quad core 24GB ram 1TB SSD and NVIDIA Quadro K620 . DID Technology stop! Or have we been assimulated!

ZX Spectrum 48k, C64, ORIC Atmos 48K, Enterprise 128K, The SID chip. Im Misunderstood!

Derron

yes, the conditional (or ternary) operator "x ? y : z" is the same as "if x then y else z".

Regarding "|" you need to ensure that whatever you shift around and combine - has a "length" (amount of bits). Especially if the values are of different types (shifting bits of a byte which you add to an int...).


bye
Ron

Baggey

Wonderful don't you just love it when you have a programming problem and you cant see the wood through the tree's'
Ive been going around in circles with this. DOUBLE CHECK YOUR BITS

Checking for a Carry in a Z80 machine code instruction can have devastating effects with just 1 bit wrong out of 100,000's of codes :-\

I just realized If (result & $1000) then F=FLAG_C else F=0 Is missing a 0 which isnt testing for an overflow of the carry.

It should be If (result & $10000) then F=FLAG_C else F=0 8)

Baggey
Running a PC that just Aint fast enough!? i7 4Ghz Quad core 24GB ram 1TB SSD and NVIDIA Quadro K620 . DID Technology stop! Or have we been assimulated!

ZX Spectrum 48k, C64, ORIC Atmos 48K, Enterprise 128K, The SID chip. Im Misunderstood!

col

I wouldn't even try to remember the bits for this exact reason  :o
You have FLAG_C so why not have constants for the bits too?

[pseudo code]
' somewhere you have a list of all flag bits
Const FLAG_C_BIT = $10000


' do a check for a flag
If (result & FLAG_C_BIT) F=FLAG_C.....
https://github.com/davecamp

"When you observe the world through social media, you lose your faith in it."

TomToad

Not really.  The results of (result & 0x10000 ? FLAG_C : 0) and ((result & 0xffff) ? 0 : FLAG_Z) are not assigned to F directly, but ORed with the rest of the expression.  You could break down the equation like so:
If (result & 0x10000) Then F = FLAG_C Else F = 0
F = F | overflowAddTable[lookup >> 4] | ((result >> 8 ) & (FLAG_3 | FLAG_5 | FLAG_S)) | halfcarryAddTable[lookup & 0x07]
If Not (result & 0xffff) Then F = F | FLAG_Z
Note the Not in the last line, and no Else.  That is because FLAG_Z is ORed only if none of the lower 16 bits of result are set.  If any are set, then doing an OR with 0 results in no change to F.
Another way to deal with it is to use a bit of math, since True casts to 1 and False casts to 0.
F = (((result & 0x10000) <> 0) * FLAG_C) | overflowAddTable[lookup >> 4] | ((result >> 8 ) & (FLAG_3 | FLAG_5 | FLAG_S)) | halfcarryAddTable[lookup & 0x07] | (((result & 0xffff) = 0) * FLAG_Z)
------------------------------------------------
8 rabbits equals 1 rabbyte.