You can scale the screen by using the formula
Code: Select all
scale = 128*res / 640
This means that the X values are an array of 320 4-bit values (160 bytes) and the Y is an array of 240 values.
So what is the best practice for storing the X and Y coordinates? It would need 17 bits, (9 for the X, 8 for the Y). I have been using 3 bytes, but it's incredibly annoying to have to do 16-bit maths on the X value every time there is an operation.
It would be great if there was some kind of bit-packing technique or clever shifting trick to allow for using only 2 bytes.
As an example, 8086 (16-bit) assembly has a 20-bit memory address register that only uses 3 bytes (rather than 4), since the high 4 bits set the segment, and the lower 16-bits set the offset. Only a couple of shifting operations needed.
It's obviously not the same, but it would be good to know if someone has already looked at this problem.
Some of the options I have thought of are:
- Reduce the precision of X, to use only 8 bits.
- Reduce the precision of Y, to use 7 bits
- Create two types of "drawing" functions, one where you know X will be less than 256, and another where it will be higher. I think a few older games did this.
- one subroutine, but have it "decide" if X>256 before continuing at the expense of a tiny bit of performance.
- segment the screen into two areas?
Or am I going about this the wrong way altogether?