Help with writing a 'daemon' routine

GFA BASIC-related articles in here please

Moderators: exxos, simonsunnyboy, Mug UK, Zorro 2, Moderator Team

Dal
Administrator
Administrator
Posts: 4079
Joined: Tue Jan 18, 2011 12:31 am
Location: Cheltenham, UK
Contact:

Help with writing a 'daemon' routine

Postby Dal » Mon Mar 11, 2013 4:02 pm

I think I'm going to become a bit of a pest! Sorry :oops:

I'd like to understand the best approach for writing a daemon as part of a bigger application. Specifically, I would like a process which performs a send/receive request at least every 1/10 seconds (preferably faster). This process must be running continuously in the background while the application is running and responding to user interaction or commands within a script file.

Some examples of the more fundamental things I would like to implement:
1. Basic commands like setting/reseting an output line.
2. Timed commands - setting an output line only for a specified amount of time (in 1/10 second increments or faster).
3. Keeping an output line set until an arbitrary number of pulses have been received on a specified input line.
4. Kicking off an arbitrary processes as soon as a specific input state is detected.

I imagine I need to read up on some game coding techniques. It would be useful if anyone could give me some ideas on specific things I should be studying or perhaps point me in the direction of some sample code I can digest?

Many thanks!
TT030: 4MB/16MB + Crazy Dots, Mega"SST" 12, MegaSTE, STE: Desktopper case, IDE interface, UltraSatan (8GB + 512Mb) + HXC floppy emulator. Plus some STE's/STFM's

User avatar
simonsunnyboy
Moderator
Moderator
Posts: 4858
Joined: Wed Oct 23, 2002 4:36 pm
Location: Friedrichshafen, Germany
Contact:

Re: Help with writing a 'daemon' routine

Postby simonsunnyboy » Mon Mar 11, 2013 4:42 pm

I have never seen a GFABASIC program attempting such but good luck on your quest!

You could try if the EVERY xxx GOSUB yyy commands do help you.

My experience from cooperative multitasking like this on embedded procesors, suggests that you should structure your parallel thread as a statemachine and try keeping states small.
Simon Sunnyboy/Paradize - http://paradize.atari.org/ - STOT: http://www.npoi.de/stot/

Stay cool, stay Atari!

1x2600jr, 1x1040STFm, 1x1040STE 4MB+TOS2.06+SatanDisk, 1xF030 14MB+FPU+NetUS-Bee

Jabber: simonsunnyboy@atari-jabber.org

Dal
Administrator
Administrator
Posts: 4079
Joined: Tue Jan 18, 2011 12:31 am
Location: Cheltenham, UK
Contact:

Re: Help with writing a 'daemon' routine

Postby Dal » Mon Mar 11, 2013 4:45 pm

Maybe I'm being too ambitious and I really need to do it in assembler and tie a routine to a timer perhaps?
TT030: 4MB/16MB + Crazy Dots, Mega"SST" 12, MegaSTE, STE: Desktopper case, IDE interface, UltraSatan (8GB + 512Mb) + HXC floppy emulator. Plus some STE's/STFM's

User avatar
simonsunnyboy
Moderator
Moderator
Posts: 4858
Joined: Wed Oct 23, 2002 4:36 pm
Location: Friedrichshafen, Germany
Contact:

Re: Help with writing a 'daemon' routine

Postby simonsunnyboy » Mon Mar 11, 2013 5:01 pm

The EVERY constructs do exactly this, they tie you to the 200Hz Timer C of the TOS and allow you to execute a custom procedure.
I think this is even a feature of the AES that is utilized by GFABASIC here. I might be wrong.

I only used this with slow intervals in the past, such as a game state update every 60 seconds or so. Therefor I can't tell for fast behaviour.
All in all I think using GFABASIC for controlling realtime systems is a big challenge. If you insist on doing this with an Atari instead of a microcontroller, using C or plain assembly language is likely to be the best choice.
Simon Sunnyboy/Paradize - http://paradize.atari.org/ - STOT: http://www.npoi.de/stot/

Stay cool, stay Atari!

1x2600jr, 1x1040STFm, 1x1040STE 4MB+TOS2.06+SatanDisk, 1xF030 14MB+FPU+NetUS-Bee

Jabber: simonsunnyboy@atari-jabber.org

Dal
Administrator
Administrator
Posts: 4079
Joined: Tue Jan 18, 2011 12:31 am
Location: Cheltenham, UK
Contact:

Re: Help with writing a 'daemon' routine

Postby Dal » Mon Mar 11, 2013 5:20 pm

Thanks ssb. I'll see if EVERY will be fast enough otherwise I'll have to think again.

The Robokit software does exactly what I describe plus more, so I know it's possible. However the software has a couple of bugs and no scripting capability.

I have been in touch with Curt from Atari museum. He's having a trawl through the mainframe restore to see if the source exists.
TT030: 4MB/16MB + Crazy Dots, Mega"SST" 12, MegaSTE, STE: Desktopper case, IDE interface, UltraSatan (8GB + 512Mb) + HXC floppy emulator. Plus some STE's/STFM's

Dal
Administrator
Administrator
Posts: 4079
Joined: Tue Jan 18, 2011 12:31 am
Location: Cheltenham, UK
Contact:

Re: Help with writing a 'daemon' routine

Postby Dal » Mon Mar 11, 2013 6:18 pm

I think EVERY will work very well. The following listing gives me a live view of the input states - as I pull lines down, the RECV value changes!

Code: Select all

CLS
out%=0
in%=0
rom3%=&HFA0000
EVERY 1 GOSUB rdwr
DO
    IF inkey$="x" THEN
        END
    ENDIF
LOOP
PROCEDURE rdwr
    in%=65535-DPEEK(rom3%+(out%*2))
    PRINT AT(1,1);"RECV: ";in%;"  "
RETURN


There's more to be done and I'll no doubt have to increase the EVERY count value as things get more complex, however I think I can get some scripting going now. Thanks for the pointer SSB!
TT030: 4MB/16MB + Crazy Dots, Mega"SST" 12, MegaSTE, STE: Desktopper case, IDE interface, UltraSatan (8GB + 512Mb) + HXC floppy emulator. Plus some STE's/STFM's

Dal
Administrator
Administrator
Posts: 4079
Joined: Tue Jan 18, 2011 12:31 am
Location: Cheltenham, UK
Contact:

Re: Help with writing a 'daemon' routine

Postby Dal » Tue Mar 12, 2013 1:15 am

I now have something working. I can monitor the robokit while giving instructions. I found the input$ command would prevent my timer C stuff from running, so I wrote my own keyboard input routine by peeking FFFC02 (not sure this is the proper way but it works for what I need).

Everything works nicely in the interpreter - so long as NVDI is running, it's really zippy and gives me a live update while I bang commands into it. Without NVDI, it's pretty much useless to be honest!

I compile and link using the latest libraries and I get a PRG. Great so far, I run it up, but the Timer C stuff doesn't run at all. My keyboard rout is working fine, but that's it. I tried a simpler program which just runs an infinite loop after an EVERY command. This also suffers the same problem when it's compiled. Perhaps I'm not doing something right?

My current source is attached:
ROBOKIT4.txt
You do not have the required permissions to view the files attached to this post.
TT030: 4MB/16MB + Crazy Dots, Mega"SST" 12, MegaSTE, STE: Desktopper case, IDE interface, UltraSatan (8GB + 512Mb) + HXC floppy emulator. Plus some STE's/STFM's

User avatar
lp
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2257
Joined: Wed Nov 12, 2003 11:09 pm
Location: GFA Headquarters
Contact:

Re: Help with writing a 'daemon' routine

Postby lp » Tue Mar 12, 2013 4:11 am

EVERY and AFTER are interrupt driven in the original GFA editor. Its possible you need to add the $I+ compiler directive, I can't remember if the interrupt for EVERY and AFTER is on or off by default. In compiled apps this interrupt is optional, probably to save speed, if it is off by default it would explain why it fails compiled.

Dal
Administrator
Administrator
Posts: 4079
Joined: Tue Jan 18, 2011 12:31 am
Location: Cheltenham, UK
Contact:

Re: Help with writing a 'daemon' routine

Postby Dal » Tue Mar 12, 2013 9:09 am

I tried adding $I+ but i still get the same result. I'll try and set up an older version of GFA somewhere and see if that behaves differently.
TT030: 4MB/16MB + Crazy Dots, Mega"SST" 12, MegaSTE, STE: Desktopper case, IDE interface, UltraSatan (8GB + 512Mb) + HXC floppy emulator. Plus some STE's/STFM's

Dal
Administrator
Administrator
Posts: 4079
Joined: Tue Jan 18, 2011 12:31 am
Location: Cheltenham, UK
Contact:

Re: Help with writing a 'daemon' routine

Postby Dal » Tue Mar 12, 2013 11:43 am

Pfft!

I don't know. I tried v3.5 (loaded the listing into the 3.5 interpreter, saved as v3.5 GFA file called comp.gfa, complied and linked) - the Timer still doesn't run. I must be coding it wrong but still confused as to why it all works within the interpreter.

Can someone take a look at the code I posted perhaps? :D
TT030: 4MB/16MB + Crazy Dots, Mega"SST" 12, MegaSTE, STE: Desktopper case, IDE interface, UltraSatan (8GB + 512Mb) + HXC floppy emulator. Plus some STE's/STFM's

Dal
Administrator
Administrator
Posts: 4079
Joined: Tue Jan 18, 2011 12:31 am
Location: Cheltenham, UK
Contact:

Re: Help with writing a 'daemon' routine

Postby Dal » Tue Mar 12, 2013 5:18 pm

Thanks to LP I'm now able to compile a working executable.

It needs the following directive at the top:

Code: Select all

$I+,U+


However, the latest 3.6 compiler/linker created an executable which bombs on the STE. So I have had to use the 3.5 libraries, compiler and linker (thanks Zorro 2). I can now continue making progress.

BTW, here's the application so far:
http://youtu.be/3OyiHrpvpkg

As you can see, I have a working prompt which doesn't interrupt the live feedback from the interface. What I don't have yet is a command interpreter (next step!).
TT030: 4MB/16MB + Crazy Dots, Mega"SST" 12, MegaSTE, STE: Desktopper case, IDE interface, UltraSatan (8GB + 512Mb) + HXC floppy emulator. Plus some STE's/STFM's

User avatar
lp
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2257
Joined: Wed Nov 12, 2003 11:09 pm
Location: GFA Headquarters
Contact:

Re: Help with writing a 'daemon' routine

Postby lp » Tue Mar 12, 2013 5:58 pm

If you don't have a hard copy of the manual you can use this instead:
http://userpages.bright.net/~gfabasic/f ... abasic.hyp

The entire v3.6 editor and compiler manuals OCR'd into an ST-Guide HYPertext. When I refer to my notes, that means I looked here. At the bottom of many pages are notes and memos about oddities, bugs, hidden features, and stuff missing from the printed manuals. :wink:

User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 2058
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

Re: Help with writing a 'daemon' routine

Postby charles » Wed Mar 13, 2013 11:58 pm

using the bios 1,2 and bios 2,2 should overcome the timer issue
flags maybe good for the input too , i have somewhere on this forum a timer a handler and quartz clock freq for pulses if need so

good luck
i also have a robo kit software , but i think its in c


charlie
atari is my lifestyle,not a hobby.
HOLD ON ! ! !,
Im printing unreadable characters ...!


Social Media

     

Return to “GFA BASIC”

Who is online

Users browsing this forum: No registered users and 1 guest