belial wrote:nitro2k01 wrote:An integer table, even 16-bit integer, is better than that float table
I bet i misunderstand you and maybe this should be discussed somewhere else, but why using an integer table? An integer table of sine values would contain exactly 3 entries {-1, 0 1}.
Oh, you need to scale it, of course. If you want an object to swing 40 pixels from side to side in a sinusoidal curve, you could pre-calculate y=int(20*sin(x)). Actually you could probably get away with calculating 10*sin(x) and multiplying the table values by 2.
Which brings me to another point... Integer multiplication and even division by 2 and multiples of 2 is cheap. It can be easily written as a shift operation. y=4*x is equivalent to y=x<<2 for example.
Another trick, which I don't think the C compiler has support for, is fixed-point arithmetic. You could for example define that in an 8-bit number, the lower two bits are the decimal part and the upper six bits are the integer part. So, for example, you could represent a number like 5.75 without rounding:
This would of course be stored in an 8-bit register as hex: $17 (Bin: 00010111)
The logic is that bits below decimal point get the values 1/2, 1/4, 1/8 etc.
Adding two of these numbers works all the same like any other number of that bit size. If you multiply two numbers fixed-point numbers however, you must realign the number. Consider that you multiply 2*3 in the notation above:
"2.00" = Bin: 0000 10.00 = Hex: $08
"3.00" = Bin: 0000 11.00 = Hex: $0C
$08 * $0C = $60
Bin: 0110 0000 = Hex: $60
Here you need to divide by 4, or as it can also be done, shift right twice, to get the correct answer:
However, when you multiply fixed-point * actual integer, you don't need the realignment step.
I think any tutorial to programming an 8-bit CPU should talk about binary numbers and 8-bit math tricks. Not as a thing that you need to go through by necessity, but as something that is actually useful. But maybe that scares people off?
Oh, and you're right that there's seems to be a lack of GB tutorial. There's one though...
http://gameboy.mongenel.com/ <- and click GBC ASMSchool
It's geared towards ASM however. Which I personally think is the way to go in the long run.
Maybe I should get my ass off the couch and actually write a tutorial myself. I've been wanting to do this for a while, but lazy and stupid in the same as being an elitist dickhead is almost a guarantee that you'll never manage to write something you're satisfied with.