DOS Programming - detecting if Win 3.x is open

Getting old software/games running on older hardware.

DOS Programming - detecting if Win 3.x is open

Postby BeginnerGuy » 2018-1-11 @ 16:44

Helllooo once more,

I think I'm going to finally just open a thread for myself about my engine and game development and maybe some nice people will follow along with the issues I come across and maybe offer solutions instead of continually asking questions with a new thread, but for now.. one more. (Which subforum would be proper for my active game/engine development anyway?? )

Problem:
I've been changing my engine's temporal synchronization system over from using vertical retrace (vsync) to reprogramming the system timer (0x43 - 8253 control register) and now realize that if I try to test reprogramming it through a command prompt launched through WFW 3.11, it doesn't change at all. The only reason I'm even doing it this way is because I write all code on a linux box and compile it straight through the network using MS C/C++ on my 486 (networked using WFW)

Anyway, is there any place in memory I can look for a flag bit that will tell me whether or not windows is running? I'm guessing windows locks the CPU down into protected mode, a topic which I badly need a course on.

I used the dos command _outp to put the timer in mode 2 then two more _outp calls to write the low and hi bytes (in that order), which works fine in dos. Problem is, according to msdn for _outp:

"The functions return the data output. There is no error return. ". So I'm not sure how to error check and return an error doing this.

In the mean time i grabbed the book "Advanced M. S.-DOS Programming: The Microsoft Guide for Assembly Language and C. Programmers" hoping it will steer me in the right direction.
Sup. I like computers. Are you a computer?
User avatar
BeginnerGuy
Member
 
Posts: 467
Joined: 2016-12-19 @ 08:32
Location: North Carolina, US

Re: DOS Programming - detecting if Win 3.x is open

Postby K1n9_Duk3 » 2018-1-11 @ 23:24

Try disabling the interrupts while reprogramming the timer, like this:

Code: Select all
_disable;
_outp(...);
_outp(...);
_outp(...);
_enable;

This should help in case the multitasking/task switching is messing with your code. But it's also possible that Windows is redirecting the ports, wich means you won't be able to reprogram the timer anyway.
User avatar
K1n9_Duk3
Newbie
 
Posts: 53
Joined: 2016-9-30 @ 11:07

Re: DOS Programming - detecting if Win 3.x is open

Postby Gered » 2018-1-11 @ 23:54

I'm not sure if there's a better way, but I know you can check for the presence of Windows (and get the version) with interrupt 0x2f. Here's a quick program I threw together (I compiled with Watcom, might need to adjust a little bit if you use something else):

Code: Select all
#include <stdio.h>
#include <dos.h>

int main(int argc, char *argv[]) {
    union REGS r;
    int major, minor;

    r.w.ax = 0x1600;
    int386(0x2f, &r, &r);

    if (r.h.al == 0) {
        printf("Not running Windows.\n");
        return 0;
    }

    if (r.h.al == 1) {
        printf("Running Windows 2.x?\n");
        return 1;
    }

    printf("Running Windows 3.x or later\n");
    major = r.h.al;
    minor = r.h.ah;

    printf("Windows version = %d.%d\n", major, minor);

    return 0;
}


I haven't tested on this on anything but MS-DOS 6.2 and Windows 3.1, but I believe this should work on other versions.

I think I'm going to finally just open a thread for myself about my engine and game development and maybe some nice people will follow along with the issues I come across and maybe offer solutions instead of continually asking questions with a new thread, but for now.. one more. (Which subforum would be proper for my active game/engine development anyway?? )


Yeah, I was kind of wondering if some kind of "Programming" subforum might be a nice addition. Not sure if we have enough people interested in that here, but who knows, the very presence of such a forum might inspire others to start writing code for their retro PCs. :)
486DX2-66/16MB/S3 Trio32 VLB/SBPro2/GUS
P233 MMX/64MB/Voodoo2/AWE64
Duron 800/256MB/Savage4 Pro/SBLive (IN PROGRESS)
User avatar
Gered
Newbie
 
Posts: 99
Joined: 2017-6-23 @ 22:31
Location: Toronto, Canada

Re: DOS Programming - detecting if Win 3.x is open

Postby Plasma » 2018-1-12 @ 03:33

Unless you need PC/XT compatibility, I recommend leaving the timer alone and hooking int 70h (RTC) instead. This is available on AT+ computers and runs at 1024 hz, and can be used in all versions of Windows.

This is what I use to detect a Windows DOS box vs pure DOS:

Code: Select all
DetectWin   proc   near

   mov   [InWindows], 1      ; Assume Windows unless we  pass all the checks

   mov   ax, 1600h      ; Check for Win 3.x and 9x/Me
   int   2Fh
   cmp   al, 00h
   je   DetectNT
   cmp   al, 80h
   je   DetectNT
   ret

DetectNT:
   mov   ax, 71A0h      ; Check for Win NT/2K/XP
   xor   cx, cx
   int   21h
   cmp   ax, 7100h
   je   DetectOS2
   ret

DetectOS2:
   mov   ax, 4010h      ; Check for OS/2
   int   2Fh
   cmp   ax, 4010h
   je   DetectDesqView
   ret

DetectDesqView:
   mov   ax, 2B01h      ; Check for DesqView
   mov   cx, 4445h
   mov   dx, 5351h
   int   21h
   cmp   al, 0FFh
   je   InDOS
   ret

InDOS:
   mov   [InWindows], 0      ; Must be in pure DOS
   ret

DetectWin   endp
Plasma
Newbie
 
Posts: 23
Joined: 2016-12-12 @ 08:38

Re: DOS Programming - detecting if Win 3.x is open

Postby BeginnerGuy » 2018-1-12 @ 18:42

Thank you for the replies guys, I will test these out shortly.

Re: Disabling interrupts, I've tried that with inline (_asm cli) with no luck, it seems it's either changing the port or as soon as interrupts are re-enabled, changing it back. Either that or the protected mode is simply blocking me from doing it and I get no error returned.. who knows.

Re Gered & Plasma, A ha! no mention of 2fh 16xxh in this old book... thank you so much. Might I ask what reference you guys use for this?

I turned this up: http://www.oldlinux.org/Linux.old/docs/ ... t-2f-1.htm but even this has no mention of ax, 71A0h .. and i had to know which interrupt i was looking for in the first place just to turn up the link.

Plasma -- Thank you for the information on the RTC, these books I'm using are a bit more dated than needed as they were focused on programming for a common denominator which was the 286. I'll give this a shot, either way it's good to know about the multiplex interrupt..
Sup. I like computers. Are you a computer?
User avatar
BeginnerGuy
Member
 
Posts: 467
Joined: 2016-12-19 @ 08:32
Location: North Carolina, US

Re: DOS Programming - detecting if Win 3.x is open

Postby Gered » 2018-1-12 @ 21:26

I actually only knew about it as I recalled that Allegro did OS detection in allegro_init(). I don't think any of the books I have mention that interrupt either sadly. Allegro's detection also looks for Win NT, OS/2, etc as in Plasma's code.
486DX2-66/16MB/S3 Trio32 VLB/SBPro2/GUS
P233 MMX/64MB/Voodoo2/AWE64
Duron 800/256MB/Savage4 Pro/SBLive (IN PROGRESS)
User avatar
Gered
Newbie
 
Posts: 99
Joined: 2017-6-23 @ 22:31
Location: Toronto, Canada

Re: DOS Programming - detecting if Win 3.x is open

Postby Plasma » 2018-1-13 @ 03:34

BeginnerGuy wrote:Thank you for the replies guys, I will test these out shortly.

Re: Disabling interrupts, I've tried that with inline (_asm cli) with no luck, it seems it's either changing the port or as soon as interrupts are re-enabled, changing it back. Either that or the protected mode is simply blocking me from doing it and I get no error returned.. who knows.

Re Gered & Plasma, A ha! no mention of 2fh 16xxh in this old book... thank you so much. Might I ask what reference you guys use for this?

I turned this up: http://www.oldlinux.org/Linux.old/docs/ ... t-2f-1.htm but even this has no mention of ax, 71A0h .. and i had to know which interrupt i was looking for in the first place just to turn up the link.

Plasma -- Thank you for the information on the RTC, these books I'm using are a bit more dated than needed as they were focused on programming for a common denominator which was the 286. I'll give this a shot, either way it's good to know about the multiplex interrupt..


That listing is for int 2F. Int 21 ax=71A0 is documented. But I wrote that code over a decade ago so I don't remember my original source of inspiration.

The RTC interrupt should work on a 286. Just won't work on a PC/XT with an 8088.
Plasma
Newbie
 
Posts: 23
Joined: 2016-12-12 @ 08:38


Return to Software

Who is online

Users browsing this forum: No registered users and 1 guest