hi guys
i've written an bare OS and now im trying to go a little furthur and create a very simple GUI for it .
but i have no idea how to create such a thing .
my os is running in text_mode though i can change to some other mode but it will couse some problems as i've written nearly all the nessecary libraries of c myself (couse i didn't have them for direct developing ) and by doing this it will be no longer possible to write characters on the screen . i got to write a VGA driver then .

anyway ... i found a tutorial and did some of thigs to create a bitmap based simple gui :

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
unsigned char *dbl_buffer;
unsigned char *VGA = (unsigned char *)0xA0000000L;

typedef struct tagBITMAP              /* the structure for a bitmap. */
{
    unsigned int width;
    unsigned int height;
    unsigned char *data;
} BITMAP;
BITMAP BITMAP1;

typedef struct tagRECT
{
    long x1;
    long y1;
    long x2;
    long y2;
} RECT;

void init_dbl_buffer(void)
{
    dbl_buffer = (unsigned char *) malloc (640 * 480);
    if (dbl_buffer == NULL)
    {
    printf("Not enough memory for double buffer.\n");
    getchar();
    /*exit(1);*/
    return;
    }
}

void update_screen(void)
{
    #ifdef VERTICAL_RETRACE
      while ((inportb(0x3DA) & 0x08));
      while (!(inportb(0x3DA) & 0x08));
    #endif
    memcpy(VGA, dbl_buffer, (unsigned int)(640 * 480));
}

void setpixel (BITMAP *bmp, int x, int y, unsigned char color)
{
    bmp->data[y * bmp->width + x];
}

/* Draws a filled in rectangle IN A BITMAP. To fill a full bitmap call as
drawrect (&bmp, 0, 0, bmp.width, bmp.height, color); */
void drawrect(BITMAP *bmp, unsigned short x, unsigned short y,
                     unsigned short x2, unsigned short y2,
                     unsigned char color)
{
    unsigned short tx, ty, screen_offset = 1, bitmap_offset = 1;
    for (ty = y; ty < bmp->height; ty++)
    {
    memcpy(&dbl_buffer[screen_offset], &bmp->data[bitmap_offset], bmp->width);

    bitmap_offset += bmp->width;
    screen_offset += 640;
    }
}


int main()
{
    unsigned char key;
    do
    {
        key = 0;
        if (getch()) key = getch();

        /* You must clear the double buffer every time to avoid evil messes
            (go ahead and try without this, you will see) */
        memset (&dbl_buffer, 0, 640 * 480);

        /* DRAW ALL BITMAPS AND DO GUI CODE HERE */

        /* Draws the double buffer */
        update_screen();

    } while (key != 27);    /* keep going until escape */
}

now i wanna know how should i show some bitmaps on the screen ? how to add them ?

thanks ,

I think you will find that much of what you are looking for can be more readily found at the OSDev.org wiki and forums than here. There is a great deal of specialized information on hobbyist operating system development, and they can offer more detailed advice.

However, I am curious: how are you booting this operating system - did you roll your own bootloader, or use an off-the-shelf multiboot loader such as GRUB? Is it a 16-bit, 32-bit, or 64-bit OS (I am assuming 16-bit from the code given)? What toolchain (assembler, linker, C compiler, raw data loader, etc) are you using? What source code control are you using (e.g., Subversion, git, Mercurial)? How did you design the kernel, and what type of kernel is it? What filesystem and executable format are you using? Are you running on a hardware testbed, or using an emulator (e.g., Bochs or virtualizer (e.g., VirtualBox) to test run the system while you develop it? What is your host system (e.g., Windows, Linux. MacOS)? Did you really write a full suite of C system libraries (including, Eris help us, a version of <conio.h>), or did you use an hooked library such as PDCLib to connect to your system calls? What form do your system calls take - software interrupts, call gates, SYSENTER/SYSEXIT? What method of memory management are you using, and have you established virtual memory and paging?

Edited 1 Year Ago by Schol-R-LEA

i'll send you my files .
and if anybody else is interest maybe we can upload the os and discuss its problem and maybe develope it . just to learn how to develop an OS its very usefull way to learn about OS's .

Ah, OK, thank you for sharing the files.

I would, however, recommend that you get your code under source control and into a public repository ASAP, both to ensure that the code is secure and to facilitate cooperative work on the project. I personally have moved most of my projects to GithHub, which is free for open-source projects, but a site such as SourceForge or Heroku should be equally suitable (though Heroku is more focused on SaaS enterprise projects). Use whichever SCM you feel most comfortable with; if you haven't used one before, I can give you advice on how to do so.

thanks , actually i haven't used one before .
i'd be thankfull if you can show me the way .

Certainly. As I said, I use git for most of my SCM these days, so I'd recommend that, though I am aware that (like all software systems) it has its flaws. Others might recommend something different, like Mercurial or Bazaar, but I'll go with what I know for now. I'll also recommend GitHub for your offsite repo, for much the same reason. The GitHub user docs cover all of this quite well, but I'll go over it briefly for you now; I recommend you read through it, and the linked docs, at least once in toto before you go ahead with anything.

The first step is to make sure you have a suitable SSH public and private key pair. Chances are you already have done this for other things, but if you need to do it now, then what you need to do is run ssh-keygen and enter a suitable passphrase, one which you will remember yourself but which others are unlikely to guess at. Unlike most passwords, the pass phrase can have spaces in it. It can and should be fairly long, at least five or six actual words. You would then run ssh-add /path/to/your/key to register the key. The GitHub documentation on SSH keys gives more detail about how this should be done.

Nex you need to get the git software, whivch fortunately isn't a major dificulty on most Linux distros. From what you said earlier, I assume you are using a Debian based distro such as Ubuntu or ElementaryOS. You should be able to use apt-get install git-core to pick up the main installation. This page, while a bit dated, covers the installation options in more detail, but for the most part it is all straightforward.

Once you have it installed, you want to set up your user configuration. This is detailed in the page referenced above, but it really boils down to two commands:

git config --global user.name "NewUser"
git config --global user.email newuser@example.com

Where your name and email would go in the appropriate locations.

You should then create an account on GitHub. Again, the GitHub documentation is the best source of information on this, but really at this stage this isn't very different from how you create a user account for any other site.

Once you have your user account set up, you need to create the GitHub repository for the project. The repo creation process is pretty straightforward: you select the + button on your GitHub user page, select 'new repository', and fill in the name, description, and other pertinent details about the project. Since you'll be sharing this code with others, you presumably want to select a public repo rather than a private one, especially since public ones are free of charge (if you want a private repo, the fee starts at $7.95 USD per month for five private projects and goes up from there).

You'll also want to choose a license for the code - even for just a hobby project, you probably want some kind of protection in case someone takes your code and then claims that you stole it from them, an unlikely but possible occurrence. The Creative Commons Attribution-ShareAlike license is a good choice if you don't know which to use, though given that you used code from a tutorial to get started, you may have to put it under that tutorial's licensing, or at least give license attribution for that part of it. You might want to read this wiki page before making your decision on which license to use.

Now you need to make a local copy of the (for now empty) repo on your development machine. To do this, you would first go to the repository, and go down to the right hand side where, just below 'Settings', it has a textbox which says something like

git@github.com:MyUserName/MyProject.git

Make sure it is set to 'SSH' to ensure you have the correct URI for the next stage.

Copy this, and go to your terminal. Create a new working folder - do not try to use the folder your code is in now - and cd to it. There, enter git clone and the repository source, like this:

git clone git@github.com:MyUserName/MyProject.git

You might want to practice with someone's existing repo to make sure you can do this correctly; if you want you can use my Suntiger Algol compiler to test with.

now cd into the local repo itself, and run

git remote add origin git@github.com:MyUserName/MyProject.git

This gives te name 'origin' to the remote repo; you can use whatever single word name you want, but 'origin' is a common convention.

Finally, we add your existing code to the new repo. As I said, you need to clone the repo into a different directory than the existing one, or it won't clone it properly and it could mangle you existing code. Now that you have the local copy, however, you can simply copy the existing code into the new directory. Once this is done, you would need to add a .gitignore file to ensure that you don't copy junk files, backup files, etc., to the repo itself, so open up a text file and create a configuration file by that name with the following data:

*~
#*#
*.bak
*.o
*.sh

Add to this list the globs for whatever kinds of files you don't want to add to the repo, then save the file to the top directory of the local repo.

Now is the moment of truth: adding, committing, and pushing the files to the repo. At the top directory of the local repo, run

git add .

followed by

git commit -m "Initially populating the repo."

and at last,

git push origin master

This last command should send the files up to the remote repo. Go back to GitHub and make sure your code is now appearing in the repo.

This article has been dead for over six months. Start a new discussion instead.