mode 13h

Heres sourcecode i made thats supposed to get you into mode 13h and make a 150 by 150 white square:

[code]
void setVideoMode();
void pixel(int, int, unsigned char);

int main()
{
int x=0, y=0;

setVideoMode();

for(x=0; x<150; x++)
{
for(y=0; y<150; y++)
{
pixel(x, y, 15);
}
}

return 0;
}

void setVideoMode()
{
asm mov ax,0x0013
asm int 0x10
}

void pixel(int x, int y, unsigned char Col)
{
asm mov ah, 0x0C
asm mov al, Col
asm mov cx, x
asm mov dx, y
asm mov bx, 0x01
asm int 0x10
}
[/code]

it compiles ok, and as far as i can tell, it goes into the mode for a second, but it doesnt make a sqaure, and then comes up with a blue screen saying "Fatal exception OD has occured at 66C8:0000030F. The current application will be terminated." What can I do to fix this? by the way, im using codewarrior 4.0.

Comments

  • Compile it as a 16-bit program. You don't have low-level access to the hardware, including the screen in a 32-bit OS. Also, interrupts don't do the same thing in a 32-bit OS. And for the love of God, directly access the video framebuffer, using BIOS to plot pixels is SLOW. Basically, at address 0A000:0000h is the beginning of the video framebuffer. In 320x200x8bpp, each byte corresponds to a pixel and you just move the color values you want to the corresponding pixel. Here's some C code to plot a pixel in mode 13h.

    [code]
    void pixel(int x, int y, unsigned char col){
    int o=x+y<<6+y<<8;
    ((unsigned char far *)0xA0000000)[o]=col;
    }
    [/code]

    You can convert that to assembly fairly easily.

    : Heres sourcecode i made thats supposed to get you into mode 13h and make a 150 by 150 white square:
    :
    : [code]
    : void setVideoMode();
    : void pixel(int, int, unsigned char);
    :
    : int main()
    : {
    : int x=0, y=0;
    :
    : setVideoMode();
    :
    : for(x=0; x<150; x++)
    : {
    : for(y=0; y<150; y++)
    : {
    : pixel(x, y, 15);
    : }
    : }
    :
    : return 0;
    : }
    :
    : void setVideoMode()
    : {
    : asm mov ax,0x0013
    : asm int 0x10
    : }
    :
    : void pixel(int x, int y, unsigned char Col)
    : {
    : asm mov ah, 0x0C
    : asm mov al, Col
    : asm mov cx, x
    : asm mov dx, y
    : asm mov bx, 0x01
    : asm int 0x10
    : }
    : [/code]
    :
    : it compiles ok, and as far as i can tell, it goes into the mode for a second, but it doesnt make a sqaure, and then comes up with a blue screen saying "Fatal exception OD has occured at 66C8:0000030F. The current application will be terminated." What can I do to fix this? by the way, im using codewarrior 4.0.
    :


    "No Bad Religion song can make your life complete."
    -No Direction, Bad Religion


  • two things: i have no idea how to compile it as a 16 bit program, and theres nothing in the help file about it either. second, your pixel function doesnt work, it says it needs a closing parantheses on the second line, and no matter what i try, it still says that. what can i do?

  • : two things: i have no idea how to compile it as a 16 bit program, and theres nothing in the help file about it either. second, your pixel function doesnt work, it says it needs a closing parantheses on the second line, and no matter what i try, it still says that. what can i do?
    :

    Here's two comments in reply to your two questions. First, I know that part of the pixel function works, for at least Borland C/C++ 4.5, however, it probably doesn't work for you because you have a 32-bit only compiler and it doesn't recognize the [b]far[/b] keyword, or it may be something else. There is an error in the pixel function that causes the values for the offset to be wrong, however, a) it's a runtime logic error, and b) it should still draw something.

    The calculation for the offset should be...
    [code]
    unsigned int o=x+(y<<6)+(y<<8);
    [/code]

    Secondly, as I stated in the last post, this won't work once you compile it, if you compile it for 32-bits, because in a 32-bit operating system the hardware is protected from direct access. There are a few things you can do, a) compile for a 16-bit OS, like DOS, in which case the OS can't stop you from accessing the hardware, or b) use an OS friendly way of accessing the hardware. [or c) break into ring0 and do what you want, hehe].

    An example of the first would be simply to go download a 16-bit C/C++ compiler. I think you may be able to get Borland C/C++ 4.5 for free at borland.com. If not there are plenty of others.

    An example of the second would be to use the Windows GDI functions, DirectX, OpenGL, or some graphics library to access the hardware.

    Depending on what you want to do I'd recommend one over the other. If you want to learn low-level hardware programming, go the 16-bit route, otherwise learn DirectX or OpenGL.

    "No Bad Religion song can make your life complete."
    -No Direction, Bad Religion


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories