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
Turbo C++ ... Segment Offset
- matias_beretta
- Member
- Posts: 101
- Joined: Mon Feb 26, 2007 3:39 pm
Turbo C++ ... Segment Offset
MatÃas Beretta
Re: Turbo C++ ... Segment Offset
Have you looked at any of the beginner printf() functions various operating system development tutorials give you?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
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:
Obviously its not portable, but then segments aren't anyway.
Regards,
John.
Code: Select all
__segment seg;
seg = 0xb800;
unsigned short int __based (seg) *dispmem;
dispmem[y * 80 + x] = ch | (attrib << 8);
Regards,
John.
- Brynet-Inc
- Member
- Posts: 2426
- Joined: Tue Oct 17, 2006 9:29 pm
- Libera.chat IRC: brynet
- Location: Canada
- Contact:
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);
I can't verify it will though, I simply used my google skills...
Good luck..
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
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.
TC3 does come with an extensive help system. You should look up the mentioned functions and headers to find the things you need.
- matias_beretta
- Member
- Posts: 101
- Joined: Mon Feb 26, 2007 3:39 pm
okay but...
int main(void)
{
unsigned int far *screen;
*screen = MK_FP(0xb800, 0)
}
ERROR!!!: Nonportable pointer conversion in function main
What does it means???
{
unsigned int far *screen;
*screen = MK_FP(0xb800, 0)
}
ERROR!!!: Nonportable pointer conversion in function main
What does it means???
MatÃas Beretta