Reputation: 91
First of all I would like to tell you all that I did a lot of research on Google and elsewhere but to no avail.
I want to know how do I go on about making a text editor in turbo c++ without windows API. I started making it some time back in turbo c++ and I also learned how to include mouse using int86() function and I implemented that. But time and again I am getting stuck on something or the other. Like right now I am stuck how do I Highlight and Select the text for right clicking.
Secondly I also learned how to access video memory (however fake or old it may be these days) to have better control over the text.
Also for the text input I am using a large array as I have little knowledge about using Link Lists for such large text input and manipulating it.
Note: I do not want to use any other IDE or any API for it due to purely educational reasons.
Please guide me on how to get this thing go on further till completion. I am willing to learn all additional things to complete it.
PS: This is Not a homework. Just for learning purposes.
Upvotes: 2
Views: 2101
Reputation: 28141
As what I remember, you set video mode by setting the AX (ah:al) register and calling INT 10h see this.
Then the pixel map is accessed at memory address 0xA000. If you select a video mode f.e. 320x200 with 256 color palette, you can set RGB color palet by writing the color index to port 0x3C8 and then write Red value to 0x3C9, write Green value to 0x3C9 and write Blue value to 0x3C9.
// select mode 320x200
asm {
mov ah, 0
mov al, 13
int 10h
}
// set red background (color index 0)
asm {
mov dx, 0x3c8
mov al, 0
out dx, al
mov dx, 0x3c9
mov al, 0xff
out dx, al
mov al, 0x00
out dx, al
out dx, al
}
Instead of asm you can also use outportb
and inportb
// Set color with index 5 in color palette with outportb:
outportb(0x3c8, 5); // color with index 5
outportb(0x3c9, 0xFF); // red channel value
outportb(0x3c9, 0x00); // green channel value
outportb(0x3c9, 0x00); // blue channel value
Change video mode in C, might be something like this:
union REGS regs;
regs.w.ax = 13;
int86(0x10, ®s, ®s);
C pointer to graphical pixel map:
volatile unsigned char *pixmap = (volatile unsigned char *)0xA000;
// Write a pixel with color index 5 to X:10 Y:25 in 320x200x256 video mode:
pixmap[10 + 25 * 320] = 5;
C pointer to text map:
volatile char *charmap = (volatile char *)0xB800;
// Write hello world in text-mode
int offset = 0;
charmap[offset++] = 'H';
charmap[offset++] = 'e';
charmap[offset++] = 'l';
charmap[offset++] = 'l';
charmap[offset++] = 'o';
charmap[offset++] = ' ';
charmap[offset++] = 'w';
charmap[offset++] = 'o';
charmap[offset++] = 'r';
charmap[offset++] = 'l';
charmap[offset++] = 'd';
Note that all of this stuff asumes you are in DOS mode and I didn't test it. In Windows this will fail and give you segmentation faults or memory access errors...
Upvotes: 3