int86() C command

Programming, for all ages and all languages.
Post Reply
User avatar
PavelChekov
Member
Member
Posts: 113
Joined: Mon Sep 21, 2020 9:51 am
Location: Aboard the Enterprise

int86() C command

Post by PavelChekov »

Can I use the following to print to my printer on an Intel64 system?:

Code: Select all

void printchar(char c){

  union REGS regs;

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

}
USS Enterprise NCC-1701,
The Final Frontier,
Space,
The Universe

Live Long And Prosper

Slava Ukraini!
Слава Україні!
nexos
Member
Member
Posts: 1078
Joined: Tue Feb 18, 2020 3:29 pm
Libera.chat IRC: nexos

Re: int86() C command

Post by nexos »

No, int86 was used on old DOS systems for C code to access the BIOS. Nowadays, the world has moved on from real mode and the BIOS.
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg
kzinti
Member
Member
Posts: 898
Joined: Mon Feb 02, 2015 7:11 pm

Re: int86() C command

Post by kzinti »

Well you can if you implement int86() :P
nullplan
Member
Member
Posts: 1767
Joined: Wed Aug 30, 2017 8:24 am

Re: int86() C command

Post by nullplan »

kzinti wrote:Well you can if you implement int86() :P
And have a BIOS interface (or CSM in UEFI mode).
Carpe diem!
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: int86() C command

Post by neon »

Hi,

If interested, int86 was the original inspiration for this function in our boot loader here. Its been a while since I wrote this type of code but IIRC it would look something like:

Code: Select all

void printchar(char c){
  REGS regs;
  _ah (regs.eax) = 0x00;
  _al (regs.eax) = c;
  _dx (regs.edx) = 0x00;
  io_services (0x17,&regs,&regs);
}
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
Thomas
Member
Member
Posts: 281
Joined: Thu Jun 04, 2009 11:12 pm

Re: int86() C command

Post by Thomas »

Hi Pavel,
That looks like legacy code and makes only sense when using real mode. ( int86 is part of the old dos turbo C++ library if I remember correctly). While you would be able to get it to work in a i64 using some sort of emulation layer ( dos box , boxed wine etc ). It is not recommended. All modern operating system provide an API for printing ( I/O ) in general. It would simply be best to use them instead.

--Thomas
User avatar
bzt
Member
Member
Posts: 1584
Joined: Thu Oct 13, 2016 4:55 pm
Contact:

Re: int86() C command

Post by bzt »

PavelCheckov wrote:Can I use the following to print to my printer on an Intel64 system?
Under special circumstances, yes. But even when you could, I wouldn't recommend it, as it would be extremely slow, plus you probably won't have Teletype video mode anyway, only pixel-based graphics on modern machines (only a few BIOS implements that and only for some video modes. Chances are that that BIOS int won't work). Check out PC Screen Font or consider using a minimalistic library such as Scalable Screen Font instead.

For printing not on screen but to somewhere else, you should use IO ports. It's not that difficult, parallel port is very easy to program in particular. However again, chances are good that your modern Intel64 machine doesn't have an LPT port in the first place...
Thomas wrote:That looks like legacy code and makes only sense when using real mode.
Not really, you could switch modes temporarily.
Thomas wrote:int86 is part of the old dos turbo C++ library if I remember correctly
Also in Minix (see source line 8861). It switches to real mode, does the BIOS call and then switches back to protmode. The caller of int86() is none the wiser. You could implement something like that in long mode too, but BIOS must exists in the first place of course (and the machine must have an LPT peripheral which is unlikely these days).

Cheers,
bzt
User avatar
PavelChekov
Member
Member
Posts: 113
Joined: Mon Sep 21, 2020 9:51 am
Location: Aboard the Enterprise

Re: int86() C command

Post by PavelChekov »

Thomas wrote:Hi Pavel,
int86 is part of the old dos turbo C++ library if I remember correctly
I like looking through old C programming books, and trying to follow the tutorials today.
USS Enterprise NCC-1701,
The Final Frontier,
Space,
The Universe

Live Long And Prosper

Slava Ukraini!
Слава Україні!
Post Reply