32 bit TSR in FreeBasic (yes, it worked, in the end)

DOS specific questions.
angros47
Posts: 2321
Joined: Jun 21, 2005 19:04

32 bit TSR in FreeBasic (yes, it worked, in the end)

Post by angros47 »

Ok, after some reading, I realized that is actually possible to make a TSR in 32 bit: an example has been made in C, and can be downloaded at http://ftp.sunet.se/mirror/archive/ftp. ... gpptsr.zip. It hasn't been updated since 2002.

I ported it under FreeBasic, and worked, at least under DosBox. You need three files:

Keep.bas

Code: Select all

' Copyright (C) 2002 Charles Sandmann (sandmann@clio.rice.edu)
'   ABSOLUTELY NO WARRANTY.  May be redistributed or copied without restriction
'   as long as copyright notice kept intact.  Hopefully I'll get this in
'   the DJGPP library someday. 

#include "dos/dpmi.bi"
#include "dos/sys/farptr.bi"
#include "dos/go32.bi"
#include "keep.bi"

sub keep(status as ubyte, size as unsigned integer)

  dim regs as __dpmi_regs 

  _farsetsel(_dos_ds)

  ' Keep size default is current PSP block size 
  if _farnspeekw(_go32_info_block.linear_address_of_original_psp - 15) <> _go32_info_block.linear_address_of_original_psp / 16 then
    ' Not a real PSP? attempt to continue 
    regs.x.dx = (_go32_info_block.size_of_transfer_buffer + 256) / 16
  else
    regs.x.dx = _farnspeekw(_go32_info_block.linear_address_of_original_psp - 13)
  end if

  ' Default is to keep PSP and transfer buffer, but the user may want to
  '   not use and release transfer buffer to decrease DOS footprint.  
  if size >= 16 andalso size < regs.x.dx then regs.x.dx = size

  regs.x.ax = &H3100 + status
  __dpmi_int(&H21, @regs)
end sub
keep.bi

Code: Select all

' Copyright (C) 2002 Charles Sandmann (sandmann@clio.rice.edu)
' ABSOLUTELY NO WARRANTY.  May be redistributed or copied without restriction
' as long as copyright notice kept intact 

declare sub keep(status as ubyte, size as unsigned integer)
and fbtsr.bas

Code: Select all

'  DJGPPTSR, Nov 1995 Charles Sandmann (sandmann@clio.rice.edu)
'  Updated Oct 2002.

'  ABSOLULTELY NO WARRANTY.  May be redistributed or copied without restriction.

'  An example of a DJGPP TSR.  This routine changes the video attribute of the
'  character in the upper right of the screen once per tick (from protected
'  mode).  The DPMI provider will be forced to stay resident after this image
'  exits.  This code also shows an undocumented way to suppress the exception
'  code loading to decrease the image footprint size.  Not optimal - you can
'  do the same thing with a single GAS file with a much smaller image.  Left 
'  as an exercise for the user.  Have fun!  

#include "crt/stdio.bi"
'#include "crt/io.bi"
#include "dos/dpmi.bi"
#include "dos/sys/farptr.bi"
#include "dos/go32.bi"
#include "dos/pc.bi"
#include "keep.bi"

'' from djgpp/include/crt0.h
#define _CRT0_FLAG_LOCK_MEMORY &h1000

'' linker "magic"
extern _crt0_startup_flags alias "_crt0_startup_flags" as integer
dim shared _crt0_startup_flags as integer = _
  _CRT0_FLAG_LOCK_MEMORY


sub int8
  dim as uinteger offset = ScreenPrimary+(2*79)+1	' Video attribute byte 
  _farsetsel(_dos_ds)
  _farnspokeb(offset,1+_farnspeekb(offset))
end sub

  dim as _go32_dpmi_seginfo pmint
   
  pmint.pm_selector = _my_cs()
  pmint.pm_offset = cast(unsigned integer,@int8)
  _go32_dpmi_chain_protected_mode_interrupt_vector(8, @pmint)
  print "Installing DJGPP TSR"


  keep(0, 16)
  end
It must be compiled with:

Code: Select all

fbc fbtsr.bas keep.bas
stubedit fbtsr.exe bufsize=4K
Without the stubedit command, the produced executable will crash. Let me know if it works. Perhaps, it can be modified and included in the dos examples.
Gablea
Posts: 1104
Joined: Apr 06, 2010 0:05
Location: Northampton, United Kingdom
Contact:

Re: 32 bit TSR in FreeBasic (yes, it worked, in the end)

Post by Gablea »

Wow it’s looks like I may be able to create the TSR for my till printers after all :)

Any ideals how I could talk to the TSR app from my main app?
angros47
Posts: 2321
Joined: Jun 21, 2005 19:04

Re: 32 bit TSR in FreeBasic (yes, it worked, in the end)

Post by angros47 »

Unfortunately, no. Looks like not many people experimented with 32 bit TSR. Also, the TSR works using ISR subroutines: basically, when it stops, instead of clearing the memory, it remains loaded, and the ISR are still called. So, if you include the same exact ISR subroutines in your main program, you won't need to use a TSR. As I told before, FreeBasic 1.06 has also a (buggy) support to threads, so you can write a multithread program.

Documentation about making a TSR in 32 bit is very scarce, unfortunately, and most people just believe it's not possible at all. So, as you can guess, support is very, very poor.
Gablea
Posts: 1104
Joined: Apr 06, 2010 0:05
Location: Northampton, United Kingdom
Contact:

Re: 32 bit TSR in FreeBasic (yes, it worked, in the end)

Post by Gablea »

I have a feeling I’m trying to do something with the language that the creator never though about.

Most EPoS systems are done is C or C++ but I do not know that language I know FreeBASIC as well as VIsual basic.

Maybe I should just give up the idea of the Linux / DOS till system and stick with my .net version

Though I can run app in the background on Linux would that be a standard app or is that a special type of app again?
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: 32 bit TSR in FreeBasic (yes, it worked, in the end)

Post by MrSwiss »

... app in the background on Linux, would that be a standard app?
Yes, Linux is multitasking, like Windows.
DOS fails on that ... (as already many times stated!).
angros47
Posts: 2321
Joined: Jun 21, 2005 19:04

Re: 32 bit TSR in FreeBasic (yes, it worked, in the end)

Post by angros47 »

Gablea wrote:I have a feeling I’m trying to do something with the language that the creator never though about.
And I have a feeling you are right.
Most EPoS systems are done is C or C++ but I do not know that language I know FreeBASIC as well as VIsual basic.
C and C++ have exactly the same issues of FreeBasic, under dos. The issue is not with the language, it is with the operating system. FreeBasic allows to do what you want, but DOS doesn't.
Maybe I should just give up the idea of the Linux / DOS till system and stick with my .net version
Don't put Linux and DOS on the same level, perhaps DOS is not suitable for what you need, but Linux is.
Though I can run app in the background on Linux would that be a standard app or is that a special type of app again?
In Linux you can run a standard app (or more than one) in background. And several Linux distributions have the same hardware requirements than DOS with a 32 bit extender (aka the environment you are currently using). Also, I programmed under Linux, and I programmed under DOS, so trust me: programming under Linux is easier.
Gablea
Posts: 1104
Joined: Apr 06, 2010 0:05
Location: Northampton, United Kingdom
Contact:

Re: 32 bit TSR in FreeBasic (yes, it worked, in the end)

Post by Gablea »

@angros47
I have been doing a lot of digging around the net today and I think the only thing that is stopping me from moving into Linux is the following

In DOS I could set in the autoexec a line like

C:\NPoS\NPoS.exe and it would start the till software up and running but from what I’ve found in google there is so much conflicting information on how to auto start a program

If someone would be kind enough to show me how to do that then I would look at Linux again (I’ve been playing around with Debian) and I have had some good results with the tills running in Debian (but a few issues with the mysql interface as it’s seem to sometime return null results when I know the item exists)

My friend mysticshadow is working on a data interface module for me that would take any database and allow it to talk to the till software (as he has been using FreeBASIC since it started)

And yes I have managed to install Debian a till that had a fully working DOS application on it. (And with Linux I would be able to add support for the new USB scannners and scales)
angros47
Posts: 2321
Joined: Jun 21, 2005 19:04

Re: 32 bit TSR in FreeBasic (yes, it worked, in the end)

Post by angros47 »

Different distributions work in different way:
https://www.linuxquestions.org/question ... nt-177469/

http://xmodulo.com/how-to-automatically ... ebian.html

It is more complex than dos, since, being multitasking, Linux could run your program as main program, or in background: you also must authorize it as superuser (otherwise everyone could add a malware to the boot process), and you have to decide if you want to use Linux in console mode (similar to DOS) or if you want to start X-Windows and run your program inside it (something like, under dos, starting windows 3.1, and from it starting your application: autostart is a bit more complex, in that case).
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: 32 bit TSR in FreeBasic (yes, it worked, in the end)

Post by caseih »

I think the magic keywords you're going to want to search for are something along the lines of "linux auto login kiosk run application." Essentially you configure the login manager to automatically log into your POS user, and then use the $HOME/.xinitrc file to run a particular app instead of a desktop environment. The catch is do you need a window manager or not. If it's just full-screen FB graphics, then you can get away without a window manager.

As Linux distros transition to Wayland instead of X11, I'm not sure how to do it, but I am pretty sure there'll be instructions for implementing kiosks with wayland available.
Gablea
Posts: 1104
Joined: Apr 06, 2010 0:05
Location: Northampton, United Kingdom
Contact:

Re: 32 bit TSR in FreeBasic (yes, it worked, in the end)

Post by Gablea »

I have managed so far to get to this stage with Debian

1. Install Debian in to console mode (text)
2. Auto login in a user (posuser)

Now I can run my pos app by typing ./NPoS/NPoS but on a machine that would not have a qwerty keyboard that would be hard.

Thanks for the advise on kiosk mode and the other I shall look into that.

And as I’m using FB graphics I can do away with the x11 server
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: 32 bit TSR in FreeBasic (yes, it worked, in the end)

Post by caseih »

EDIT: In my opinion it's actually easier and more robust to use X11 and do an auto login and then use a $HOME/.xinitrc script to run your POS program without a window manager. In fact I'd recommend this over the console route because it will actually be more robust. A crash will simply result in a log out and then it will restart via the login manager, but also allow the user to shut the system down. Using the console and a service, the user would have to switch consoles and then either issue a reboot or shutdown command.

But since you're not using X11 or Wayland, you are going to need to create a service to run your POS program as part of the boot process (much like autoexec.bat). On recent distros such as Debian, that use systemd, this requires making a custom service, and probably in your case a custom "target" which is the equivalent of the old System V runlevel. See this link: https://www.mauras.ch/systemd-run-it-last.html

The only thing missing from this tutorial is that they don't specify a user to run the service as, which you'll want to do (running it as root is not recommended). So if you follow the tutorial and call your service pos.service, it should look something like this:

Code: Select all

[Unit]
Description=My POS program
After=multi-user.target

[Service]
Type=simple
User=posuser #this is the user the binary should run as
Group=posgroup #this match your pos user group
ExecStart=/path/to/posbinary

[Install]
WantedBy=custom.target
I'm fairly certain this will always run your POS program on the first virtual console, and you should be able to still access the other virtual consoles to log into the system.

EDIT: there are options you can add to the service file to let systemd restart the exe when it finishes or crashes. You'll probably need to add them if you go this route.
Gablea
Posts: 1104
Joined: Apr 06, 2010 0:05
Location: Northampton, United Kingdom
Contact:

Re: 32 bit TSR in FreeBasic (yes, it worked, in the end)

Post by Gablea »

@caseih

Thank you for that i shall give it a go on my Linux PoS when I get to the office and let you know what is happening.

can the text output that is shown when linux boots up be forward to a actual comport?

I only ask as I have one system that uses a 2x 20 chr LCD display for the user and I was thinking about a way of letting the user know the system is booting (with out having a normal display on the terminal)
St_W
Posts: 1619
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: 32 bit TSR in FreeBasic (yes, it worked, in the end)

Post by St_W »

If your POS application is currently written in .NET haven't you tried to port it to Linux using Mono or .NET core? If you're using WinForms then you can even keep the UI code if you decide to go with Mono.

Rewriting your whole application from scratch in FreeBasic/C/C++ doesn't really make sense IMHO. btw there's not really a difference between those three in terms of limitations; the limiting factor on your side is just DOS.

Personally I'd stay with .NET and either try to reuse the existing UI or create a new (and platform-independent) Web-UI for it. A rewrite won't pay off.
Gablea
Posts: 1104
Joined: Apr 06, 2010 0:05
Location: Northampton, United Kingdom
Contact:

Re: 32 bit TSR in FreeBasic (yes, it worked, in the end)

Post by Gablea »

@St_W

I have looked at moving the .net app to Mono but becuase I use OPoS to communcate to the Printers, cash drawer and scanners Mono does not like it (last time I tried to port it over I had over 2,000 error messages) after looking on the Mono website they do not have full support for the VB language (C is fully support in Mono)

I have never looked at .net core (does that support VB.net as well or is just like the rest of them just supporting C)

I would not create a web version of the PoS as I do not like web applications (I like complied as they would use the services and RAM etc of the local machine and not relay to much on the server)

I do how ever use MySQL as my database engine for the PoS applications (Did use Firebird but I could never work out how to talk to that from VB.net)
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: 32 bit TSR in FreeBasic (yes, it worked, in the end)

Post by caseih »

Gablea wrote:can the text output that is shown when linux boots up be forward to a actual comport?)
Yes it can. I don't have time to google for it right now but I believe there's a kernel parameter that will push all the kernel messages to a serial port. And then there's a systemd setting to push all of its output to a serial port also. I think both things would have to be configured. While you're at it, you may want to have systemd run a login tty on a serial port, just for debugging and maintenance purposes. That way you can plug in a laptop, fire up a terminal, and log in and check things without messing with the main display, although with virtual consoles, it may not be that useful to do so.
Post Reply