To Chris Giese

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
To Chris Giese

To Chris Giese

Post by To Chris Giese »

In osd8/video.c

This looks like an error:

....
* init VCs, with a different foreground color for each */
for(i = 0; i < _num_vcs; i++)
{
_curr_vc = _vc + i;
_curr_vc->attrib = i + 1;
_curr_vc->fb_adr = _vga_fb_adr + _vc_width * _vc_height * i;
....

shouldn't the last line read "_curr_vc->fb_adr = _vga_fb_adr + _vc_width * _vc_height * 2i" ? (since each char takes two bytes?)
Chris Giese

RE:To Chris Giese

Post by Chris Giese »

>shouldn't the last line read
>"_curr_vc->fb_adr = _vga_fb_adr + _vc_width * _vc_height * 2i"
>(since each char takes two bytes?)

Both _curr_vc->fb_adr and _vga_fb_adr are pointers to unsigned short,
which is 16 bits (2 bytes), so I don't need the factor of 2.
Reply

RE:To Chris Giese

Post by Reply »

Yes, but they are still pointers. You are adding addresses right?
So for example in the case of xres = 80 chars, yres = 25, i=1 chars you are adding 0x7D0 to 0xb8000 instead of 0xFA0, no?
Chris Giese

RE:To Chris Giese

Post by Chris Giese »

In the source code, I add 0x7D0 (80*25), but in the compiled code, the address has 0xFA0 added to it. That's just the weird way that C pointers work. If the pointer variables pointed to "unsigned long" (4 bytes each), then the multiplier would be 4 instead of 2.

C:\TMP>type test.c
int main(void) {
        static unsigned short *foo = (unsigned short *)0xDEADBEEF;
        foo += 1; /* adding 1 */
        return 0; }

C:\TMP>gcc -fomit-frame-pointer -c -O2 -Wall -W test.c

C:\TMP>ld --oformat binary -o test.bin -e0 -Ttext=0 test.o

C:\TMP>ndisasm -u test.bin

00000000  83050002000002    add dword [0x200],byte +0x2  <-- adding 2
00000007  31C0              xor eax,eax
00000009  C3                ret
        ...
00000200  EF                out dx,eax
00000201  BEADDE0000        mov esi,0xdead
Post Reply