Page 1 of 1

int86() C command

Posted: Sun Jan 31, 2021 9:54 am
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

}

Re: int86() C command

Posted: Sun Jan 31, 2021 10:02 am
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.

Re: int86() C command

Posted: Sun Jan 31, 2021 12:13 pm
by kzinti
Well you can if you implement int86() :P

Re: int86() C command

Posted: Sun Jan 31, 2021 12:30 pm
by nullplan
kzinti wrote:Well you can if you implement int86() :P
And have a BIOS interface (or CSM in UEFI mode).

Re: int86() C command

Posted: Tue Feb 02, 2021 8:29 pm
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);
}

Re: int86() C command

Posted: Tue Feb 16, 2021 5:15 am
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

Re: int86() C command

Posted: Tue Feb 16, 2021 7:47 am
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

Re: int86() C command

Posted: Fri Feb 19, 2021 4:47 pm
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.