LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 12-06-2003, 01:35 PM   #1
lloyd_smart
LQ Newbie
 
Registered: Dec 2003
Posts: 24

Rep: Reputation: 15
Unhappy C For Dummies and BIOS in Linux


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.
 
Old 12-06-2003, 05:19 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,536

Rep: Reputation: 148Reputation: 148
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.
 
Old 12-07-2003, 05:33 AM   #3
lloyd_smart
LQ Newbie
 
Registered: Dec 2003
Posts: 24

Original Poster
Rep: Reputation: 15
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!
 
Old 12-07-2003, 09:47 AM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,397

Rep: Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963
you would just use outb() to write data to the port.
 
Old 12-10-2003, 12:48 PM   #5
lloyd_smart
LQ Newbie
 
Registered: Dec 2003
Posts: 24

Original Poster
Rep: Reputation: 15
Great! How do I use that? Sorry if I'm acting like a complete newbie, but that's coz I am.
 
Old 12-10-2003, 03:02 PM   #6
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,536

Rep: Reputation: 148Reputation: 148
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.
 
Old 12-11-2003, 06:46 AM   #7
yuray
Member
 
Registered: Apr 2003
Location: Russia, Khotkovo
Distribution: Debian
Posts: 146

Rep: Reputation: 15
"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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Linux For Dummies AnthonyB Linux - Software 9 11-26-2005 09:03 AM
Headsup, Linux Programming for Dummies available cheap.. Garp Programming 0 10-05-2005 04:33 AM
SUSE Linux 9.3 for Dummies (For Dummies S.) samuelmp Suse/Novell 11 08-01-2005 01:42 PM
need Bios driver to exec custom on board bios code wmain Linux - Software 0 09-03-2004 08:32 AM
old BIOS (1992) won't detect my cdrom drive; BIOS says: neither IDE prots enabled carbono Linux - Hardware 5 05-18-2004 11:07 AM


All times are GMT -5. The time now is 12:53 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration