Does FreeBasic use Dos Interrupt 16h for inkey$ ?

DOS specific questions.
lassar
Posts: 300
Joined: Jan 17, 2006 1:35
Contact:

Does FreeBasic use Dos Interrupt 16h for inkey$ ?

Postby lassar » Jul 12, 2013 5:45

Does FreeBasic use Dos Interrupt 16h for inkey$, OR does it use it's own keyboard routine.

I was looking in the freebasic source code, and couldn't find out what it uses in the Inkey routine.

Where in the source code is dos inkey function?

I am thinking of using GFX_NULL in a screen function to get max speed out of freebasic.

Which would be faster , Dos Interrupt 16h or a custom keyboard routine, so I would not have to go from
protected mode to real mode to get the key. (using dosbox emulator)
marcov
Posts: 2793
Joined: Jun 16, 2005 9:45
Location: Eindhoven, NL
Contact:

Re: Does FreeBasic use Dos Interrupt 16h for inkey$ ?

Postby marcov » Jul 12, 2013 7:47

IIRC in emulated environments interrupts are generally faster since they can be hooked by the emulator, while hardware port emulation is expensive.

Admitted, that is from programs running on DV/X and win3.x in years of yore. How Dosbox really reacts can only be tested by euh, testing.
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Re: Does FreeBasic use Dos Interrupt 16h for inkey$ ?

Postby MichaelW » Jul 12, 2013 11:21

For a DOS console it looks like the RTL is calling the CRT, basically _conio_kbhit and getch(), see src\rtlib\dos\io_inkey.c.

For fbgfx it looks like an interrupt handler is used to maintain an integral key buffer, see src\gfxlib2\gfx_inkey.c.
rugxulo
Posts: 216
Joined: Jun 30, 2006 5:31
Location: Usono (aka, USA)
Contact:

Re: Does FreeBasic use Dos Interrupt 16h for inkey$ ?

Postby rugxulo » Jul 15, 2013 5:51

I've not much experience in the low-level details, so I'm not entirely sure. (Ask on news://comp.os.msdos.djgpp , CWS still hangs around there. He can give a much more precise answer than probably anybody else alive.) But for sure, if you want fastest speed, don't use DOSBox at all! Use something like DOSEMU or NTVDM (V86 mode) or VirtualBox (VT-X) or even preferably raw boot into native DOS (RUFUS?).

Read the DPMI spec (see here for online version or here for download). That's the official source since DJGPP v2 is explicitly using DPMI.

I'm not 100% sure of the details, but BIOS interrupts are reflected verbatim (if no low address translation is needed). Whether this goes to V86 or real mode depends on the DPMI host (and presumably you could just load EMM386 if you always wanted to go to V86 mode, but that may slow down or prevent other rare things, and I don't know if ring 3 is "always" slower than ring 0 or exactly what you want here).

I think by design CWSDPMI always goes to real mode (if possible, if EMM386 not loaded). I don't think this should be much of a penalty at all, it's still pretty darn fast. But again, who knows how much raw speed you're trying to achieve. Read the docs (or sources) for various other servers (HDPMI32, WDOSX, D3X) to see what they do. But if you're just "generally" wanting faster speed, it's probably unnecessary. Find the biggest bottleneck, which undoubtedly here is DOSBox's full software emulation (unless your target machine is non-x86, then you probably have few other choices).

Again, there is no perfect answer as it depends on what specific environment you're running under, esp. which DPMI host, what (incomplete?) version of DPMI you're trying to run under, what ring you're running under, whether other things are permitted or not (virtual memory? raw port access? non-standard 4 MB pages?), cpu or peripheral issues, etc.
lassar
Posts: 300
Joined: Jan 17, 2006 1:35
Contact:

Re: Does FreeBasic use Dos Interrupt 16h for inkey$ ?

Postby lassar » Jul 15, 2013 13:08

My target environment is a dos emulator used by mobile devices.

have done a lot to speed up dos freebasic.

1.I do direct vesa. This causes freebasic to think it's in screen 0. And thus no screen buffer updates.

2. I use setmouse, so that the mouse cursor is not visible. This reduces cpu load by not showing a mouse cursor.

3. I hijack the mouse handler, and use my own mouse handler.

I really wonder, if it's worth the trouble, to use GFX_NULL, and do my own keyboard handler.
rugxulo
Posts: 216
Joined: Jun 30, 2006 5:31
Location: Usono (aka, USA)
Contact:

Re: Does FreeBasic use Dos Interrupt 16h for inkey$ ?

Postby rugxulo » Jul 16, 2013 18:36

lassar wrote:My target environment is a dos emulator used by mobile devices.


Specifically, which machines? Which OS? Which emulator? (I assume you mean one of the many DOSBox forks for Android.) I have "aDOSBox" on my Android 3.2 (Honeycomb) Tegra 2 tablet, but it's dirt slow, and thus I never use it. (I don't think it's multithreaded either. I'm no snob, all of that is beyond me, but I'm just saying ... it's presumably slower than other tools by default. Though newer SDL in some cases "may"?? offload sound support to a different thread, dunno for sure.)

Honestly, such machines seem to me to be more "consumer"-only oriented, thus I don't think they majorly care how tedious or hard (or even impossible) it is to develop for. I personally don't really do anything with it because of that despite a very small curiosity. (I did install SL4A and Brexx, but I never use it. It's just not very comfortable to me. And various desktop-hosted Android cross-compilers like GCC just seemed like confusing overkill, as always.)

I don't wish to discourage you, but I'm not sure targeting a very very slow DOS VM is the best way to go. Of course overall I'm sympathetic :-) , but it seems harder than it should be. Well, I guess no matter what you use, you're at the mercy of your environment and tools.

A naive suggestion would be to explore other options, perhaps "fbc -gen gcc", for better speed. Well, even quasi-portable C isn't guaranteed to be fast. (I don't really know or like Java, but at least Dalvik has a JIT these days. Even FreePascal has some partial [native] Android support in trunk, I think.)

I just don't know if a slow VM is viable except in very banal (average) instances. And, well, you're the one whining about speed, so .... good luck anyways, sorry I can't be more helpful.
marcov
Posts: 2793
Joined: Jun 16, 2005 9:45
Location: Eindhoven, NL
Contact:

Re: Does FreeBasic use Dos Interrupt 16h for inkey$ ?

Postby marcov » Jul 17, 2013 8:25

rugxulo wrote: Even FreePascal has some partial [native] Android support in trunk, I think.)


Two actually, one JVM, one native (native libs with minimal precompiled java mainprogram skeleton iirc).

But the problem seems to be that many want Android, and few are willing to work on it as a target. What is there has been sleeping for the past half year. Same as e.g. LLVM, which is also on everybodies lips.

The universal idea seems to be "it is popular, so it would be there". But superficial interest doesn't equate to developers. It's easier to find devels for retro targets as Amiga than for android.
Last edited by marcov on Jul 17, 2013 12:25, edited 1 time in total.
lassar
Posts: 300
Joined: Jan 17, 2006 1:35
Contact:

Re: Does FreeBasic use Dos Interrupt 16h for inkey$ ?

Postby lassar » Jul 17, 2013 11:16

I am getting there.

So far, In windows dosbox, I got my program working decently at 250 cycles.

I have read, that dos programs will run at a equivalent of 4000 cycles on mobile devices.

I like to have plenty of leeway. The user could be using a slow emulator on a slow mobile device.

Here's a link to my program.
Last edited by lassar on Jul 17, 2013 23:34, edited 1 time in total.
lassar
Posts: 300
Joined: Jan 17, 2006 1:35
Contact:

Re: Does FreeBasic use Dos Interrupt 16h for inkey$ ?

Postby lassar » Jul 17, 2013 23:13

I just did a hardware keyboard handler.

So to get a key, you don't have to go from protected mode to real mode and back.

No bios or dos interrupts needed.

Here's the link to the keyboard handler.
rugxulo
Posts: 216
Joined: Jun 30, 2006 5:31
Location: Usono (aka, USA)
Contact:

Re: Does FreeBasic use Dos Interrupt 16h for inkey$ ?

Postby rugxulo » Jul 21, 2013 1:41

marcov wrote:wah wah wah


I can't speak for anyone else. I'm not ragging on Android at all, it works fairly well. But ... the overall ecosystem of computing is very throwaway these days. My machine is already (!) unsupported by Lenovo, using "old" kernel 2.6.36, probably won't get more updates, has some bugs, the hardware volume button broke months ago, and you can't replace the battery manually. Plus it's not exactly got tons of RAM anyways. I GB total, but only 768 is available (thanks to graphics eating up the rest), and a lot of that is eaten up by kernel and widgets / services, etc., whatever. So I only get about 250-300 MB available, max. And Android 3.x isn't exactly latest anymore either.

At least Android is somewhat developer friendly (third-party apps, e.g. Brexx). I don't want to go on about fragmentation, but indeed there are too many competing tablets, most didn't sell well, and of course they seem to want you to endlessly buy newer versions or else sell you a crippled machine that is really only meant for buying more subscription-based services (multimedia [music, movies] is really all the masses care about). Well, also there are a lot of games, not that a touchscreen is good for gaming except very simple stuff, bad for action games needing precision.

I don't expect you care, marcov, as you always seem to say, "Let someone step up or let it die." The problem is that everything dies too quickly these days, so it's not comforting to waste time on something that will be thrown away anyways within a year or two. I know you hate DOS, but at least DOS is (dead) "stable"!

P.S. http://www.ppcompiler.org/?lng=en (ever tried? not me ... yet)
rugxulo
Posts: 216
Joined: Jun 30, 2006 5:31
Location: Usono (aka, USA)
Contact:

Re: Does FreeBasic use Dos Interrupt 16h for inkey$ ?

Postby rugxulo » Jul 21, 2013 1:52

BTW, I'm not unsympathetic to the idea of a DOS VM. I have often thought that, with DOSBox, that DOS is still a valid target a la Java/JVM (even if weaker, obviously). Of course, that's not a popular opinion, so I don't expect anyone to sympathize (and know for a fact that most don't). Just so you know, lassar, I'm not ragging on you, but it's a losing battle!

The only real problem there is that you're at a crippled speed (no JIT) and can't do any multithreading or access any modern APIs (directly, if at all). I think there was somebody who did a partial x86-to-ARM native recompiler for Android somewhere, but I don't know if it was "free/libre" or "open" or whatnot. Even on multi-core machines (and even my tablet is dual-core), I'm not sure SDL nor aDOSBox will utilize that very well, if at all. Even on desktop machines, I don't think SDL does barely anything except minimal offloading for audio (which of course is mostly useless for our average uses here).

There are actually a few x86-based Android machines (tablets, phones), but I don't guess that helps your pre-existing customers. But hey, if they're desperate for speed .... Actually, DOSBox is slow even on x86, so that's a bust too. Meh. Maybe try to find an old PoqetPC [sic] running DOS on eBay. Or not, who knows, maybe that's slower than aDOSBox (doubt it!).

P.S. I will test and respond to your email later this weekend, if I can. Not sure how much help it will be, though.

Return to “DOS”

Who is online

Users browsing this forum: No registered users and 0 guests