I'm programming the for the 256 color VGA in C. The screen size I have is 320*200 so based on that assumption I made my plot pixel function as follows:
我用C编程为256色VGA。我的屏幕尺寸是320 * 200所以基于这个假设我制作了我的绘图像素功能如下:
void plot_pixel(int x, int y, byte color){
int offset;
offset = (y<<8) + (y<<6) + x;
VGA[offset]=color;
}
I always translate the x, y coordinates of my screen to an offset of video memory. What I'm struggling to achieve is to do the opposite. I would like to send a function the video offset and return to me an array with the 2 integers corresponding to the x and y coordinates:
我总是将屏幕的x,y坐标转换为视频内存的偏移量。我正在努力实现的目标是做相反的事情。我想发送一个函数视频偏移并返回给我一个数组,其中2个整数对应于x和y坐标:
get_xy(int offset){
...
}
However, I still cannot find a way to translate a single number into two values.
但是,我仍然找不到将单个数字转换为两个值的方法。
Can anyone help me achieve this?
谁能帮我实现这个目标?
1 个解决方案
#1
2
Simple reverse the math. Best to use unsigned
types.
简单地逆转数学。最好使用无符号类型。
y = offset/((1<<8) + (1<<6));
x = offset%((1<<8) + (1<<6));
#1
2
Simple reverse the math. Best to use unsigned
types.
简单地逆转数学。最好使用无符号类型。
y = offset/((1<<8) + (1<<6));
x = offset%((1<<8) + (1<<6));