ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi. This is my first post on this forum, and I'm a bit of a 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.
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.
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,®s,®s);
}
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.
"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?"
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.