LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   C For Dummies and BIOS in Linux (https://www.linuxquestions.org/questions/programming-9/c-for-dummies-and-bios-in-linux-123300/)

lloyd_smart 12-06-2003 01:35 PM

C For Dummies and BIOS in Linux
 
Hi. This is my first post on this forum, and I'm a bit of a :newbie: to Linux programming. I got this book, C for dummies. It's very good so far, and I've finished volume one. All the examples are written with DOS in mind (it's quite an old book), but I've managed to get most of them to work in Debian Linux (which I'm also quite new to. Before that, I used Mac OS X. Actually, I still do on my other computer).

Anyway, I was forced to skip one chapter in the first book about DOS and BIOS calls, because they wouldn't work on Debian Linux. They required a header file called dos.h, which I didn't have. Now, in the second book, the examples make quite extensive use of these techniques, so I'd like to know how to do it on linux. I've been searching around the web a bit and on other forums, and BIOS calls seem to be a bit of a taboo. Everyone keeps insisting that there are "better ways to do it". I'm sure they have more experience than me, and are probably right, but I still want to know if it's possible because I need to learn how to do it in order to finish my book. I promise that I won't use these techniques in the future after I finish reading the book, if someone will just tell me how to do it!

Has anyone else tried C For Dummies on Linux? How did you get around the problem?

If it's actually impossible to achieve this under Debian Linux, what "other ways" are there? For example, there's a simple program that ejects a page from the printer using the printer BIOS. There's a program which uses the keyboard BIOS, and stuff about the video BIOS etc. Please help me, this is driving me mad!!! Thankyou in advance for any and all help you give me.

Mara 12-06-2003 05:19 PM

In Linux, you're not allowed to write directly to hardware, so, at the user level, you can't use BIOS.
Instead, you have the /dev/ filesystem. You can use it to make the printer thing. In the code, there are commands sent to the printer, right? What you need to do is to send exactly the same codes to the right device in /dev (you may try with /dev/printer). You open the file as any other file.

lloyd_smart 12-07-2003 05:33 AM

Okay, I haven't got to the bit about opening files yet, that comes later in the book. Here is the printer program exactly how it appears in the book, comments and all. How would I change this to work in Linux?

Code:

#include <stdio.h>
#include <dos.h>
#define PRINTER 0x17                //BIOS printer interrupt
#define LPT1 0x00                //LPT1, your first printer
#define EJECT 0x0c                //Eject page printer command

void eject();
void prnchar(char c);

void main()
{
        printf("Please ensure that your printer is on and ready to print.\n");
        printf("Press Enter:");
        getchar();

/* Now eject a page from the printer */

        eject();
}

void eject(void)
{
        prnchar(EJECT);
}

void prnchar(char c)
{
        union REGS regs;

        regs.h.ah=0x00;                        //print character function
        regs.h.al=c;                        //character to print
        regs.x.dx=LPT1;                        //printer port to print to
        int86(PRINTER,&regs,&regs);
}

Thankyou SO MUCH for all your help! :)

acid_kewpie 12-07-2003 09:47 AM

you would just use outb() to write data to the port.

lloyd_smart 12-10-2003 12:48 PM

Great! How do I use that? Sorry if I'm acting like a complete newbie, but that's coz I am.

Mara 12-10-2003 03:02 PM

If I remember correctly, it's
outb (unsigned char value, unsigned short int port)
I don't remember which port printer is. You can check it into BIOS, I think. The code (EJECT) looks like a code you can pass to it.

yuray 12-11-2003 06:46 AM

"Okay, I haven't got to the bit about opening files yet, that comes later in the book. Here is the printer program exactly how it appears in the book, comments and all. How would I change this to work in Linux?"

Please, read about opening files and return back :)


All times are GMT -5. The time now is 10:31 PM.