Page 1 of 1
Turbo C++ ... Segment Offset
Posted: Sun Sep 23, 2007 7:31 am
by matias_beretta
Well, I'm writing my realmode os with Turbo C++ and when I want to write to the video memory i have to:
asm push 0xb800;
asm pop es;
asm mov di, 0;
asm mov byte ptr es:[di], 'M'
asm inc di
asm mov byte ptr es:[di], 7
asm inc di
this writes M on the screen, but it is written in assembly
is there any way of accessing memory with a segment and an offset from C?
thanks
Re: Turbo C++ ... Segment Offset
Posted: Sun Sep 23, 2007 8:05 am
by raevin
matias_beretta wrote:Well, I'm writing my realmode os with Turbo C++ and when I want to write to the video memory i have to:
asm push 0xb800;
asm pop es;
asm mov di, 0;
asm mov byte ptr es:[di], 'M'
asm inc di
asm mov byte ptr es:[di], 7
asm inc di
this writes M on the screen, but it is written in assembly
is there any way of accessing memory with a segment and an offset from C?
thanks
Have you looked at any of the beginner printf() functions various operating system development tutorials give you?
Posted: Sun Sep 23, 2007 8:06 am
by JamesM
Not AFAIK. Your best bet is to go into protected mode.
Posted: Sun Sep 23, 2007 8:39 am
by jnc100
There is nothing defined in the C standard for accessing memory via segments, because segments are pretty intel-specific. There are compiler-specific extensions however. I don't know about Turbo C++, but open watcom allows something like:
Code: Select all
__segment seg;
seg = 0xb800;
unsigned short int __based (seg) *dispmem;
dispmem[y * 80 + x] = ch | (attrib << 8);
Obviously its not portable, but then segments aren't anyway.
Regards,
John.
Posted: Sun Sep 23, 2007 9:19 am
by Brynet-Inc
Code: Select all
#define MK_FP( seg, off ) \
((void far *)(((unsigned long)(seg) << 16)|(unsigned)(off)))
unsigned char far *video_mem = (char far *)MK_FP(0xB800, 0x0000);
This "might" work under "Turbo C"..
I can't verify it will though, I simply used my google skills...
Good luck..
Posted: Sun Sep 23, 2007 3:43 pm
by frank
You could create far_peek and far_poke functions in assembly.
Posted: Mon Sep 24, 2007 12:27 pm
by Combuster
IIRC Turbo C has got MK_FP and several related functions predefined in one of its headers (include dos.h / io.h?). Since TC supports far pointers (seg:off pairs), you should be able to write directly to video memory without resolving to (inline) assembly.
TC3 does come with an extensive help system. You should look up the mentioned functions and headers to find the things you need.
okay but...
Posted: Sat Oct 06, 2007 8:58 pm
by matias_beretta
int main(void)
{
unsigned int far *screen;
*screen = MK_FP(0xb800, 0)
}
ERROR!!!: Nonportable pointer conversion in function main
What does it means???