Alex_Hot (stranger
)
2002/07/04 21:31
|
CamelForth multitasking facilities
|
| |
I tried to use multitasking for monitoring of data stack by ".S" word, which work as another task.
And I have failed, certainly. Next I read, that different tasks use different data stacks, ets...
But any way, is it possible to transfer values between stacks of different tasks?
|
garrylancaster (stranger
)
2002/07/05 02:55
|
|
It's not really possible to examine the stacks of other tasks, because even though I could tell you how to find where the stack is, it would also contain different items depending upon when the task was suspended (with a PAUSE, during EKEY or MS etc).
If you want to try an example, here is an idea for an exercise: create a task that displays a clock in a window (in the top-right corner?) and updates it whenever the minute changes. You can use the ANS standard word TIME&DATE to get the time (assuming you have a real-time clock chip).
When using multitasking/multiprogramming in Forth, there are two usual ways to pass data between tasks:
1. Don't (no communication!)
2. Use VARIABLEs/VALUEs
For the clock example, there is no need to pass any data.
As another example, I wrote a text/graphics adventure system for the Z88 in CamelForth. This uses a separate task to draw the pictures, while the rest of the adventure continues. The only communication is when starting the task: a picture address is stored into a variable, then the task is started, which takes the address from the variable and starts drawing the picture. No further communication is needed, because the picture task will STOP when it has finished. The main program doesn't know (or care) if this has happened (but it could find out by checking if the task was AWAKE?), because it simply sets the same task to draw a new picture when required, or stops it if the game finishes.
--
Garry Lancaster
http://www.z88forever.org.uk/zxplus3e/
http://www.z88forever.org.uk/
|
Alex_Goryachev (Sprinter Team)
2002/07/10 20:05
|
|
There is interesting effect when two active windows place at the same part of screen. Sometimes a task from the first window print in the another window during scrolling.
---
PETERS PLUS LTD
|
Alex_Hot (stranger
)
2002/07/10 20:20
|
|
BTW if the second (in your example) window contain task of cleaning window (PAGE word) this effect will be more seldom. Why?
|
garrylancaster (stranger
)
2002/07/11 15:28
|
|
This is to be expected; it's not a good idea to have overlapping windows. If you want two tasks to use the same screen area, just use the same window.
--
Garry Lancaster
http://www.z88forever.org.uk/zxplus3e/
http://www.z88forever.org.uk/
|
Alex_Hot (stranger
)
2002/07/15 19:39
|
|
I ported the Sokoban game using ANS sources. It was not a difficult. I did some changes for more comfortable playing.
But I have a problem with usage of multitasking and windows after compile an EXE program
During usage a game in interpreter mode all is ok. Three tasks work in different windows (Rules of the game, game screen and time window).
But when I execute EXE program of this game all windows has fullscreen size with defoult attributes.
Usage/unusage of CINIT was not a solution. It's same result.
BTW v4.01 not cleaning a screen after starting.
|
garrylancaster (newbie)
2002/07/15 19:56
|
|
It sounds like you have defined your windows during compilation of the program. Since all windows are set to the full screen when CamelForth starts, you must make sure that you define them in a word executed at initialisation, probably by the word that is set to (COLD). See the notes at the end of saveexe.txt.
The behaviour of v4.01 is so that it's easy to make command-line programs. If you don't like that, try this (from save-exe documentation):
' CAMEL IS (COLD)
S" camel.exe" SAVE-EXE
If you still have trouble, email me your sources and I will try to tell you what you are doing wrong ;-)
--
Garry Lancaster
http://www.z88forever.org.uk/zxplus3e/
http://www.z88forever.org.uk/
|
Alex_Hot (stranger
)
2002/07/16 20:02
|
|
Thanks for the help! Sokoban works correctly now. I hope you will see it soon.
|
Alex_Hot (stranger
)
2002/07/18 20:28 Attachment
|
|
I see Sokoban in Download page now. Well, I hope it will be not a best variant of this cool game on the Sprinter. ;)
I attached an image of one maze from the game. It's not a screenshot, certainly, but it like maze image on the Sprinter screen.
There are several changes in this variant of the game.
A special window for the maze image.It means Play without scroll of the game screen after each step (as in GForth on PC).
Clock window, which will work if your Sprinter has RTC CMOS chip.
Another wall image.
Another control keys.
Separated levels files. You can change, add,delete it in text editor.
Choice of start level of the game.
|
Alex_Hot (stranger
)
2002/07/18 21:16
|
|
Some unrealized features in the Sokoban.
1. Changing of the Soko symbol (@) and boxes ($).
2. I couldn't made an again choice of level during the game without exit.
3. Usage of a text mode 40x32 with special font.
4. Choice of levels files before game start.
|
garrylancaster (newbie)
2002/07/23 01:07
|
|
Congratulations on the Sokoban conversion - it works really well! I hope you will update it to work with graphics when the next version of CamelForth is released ;)
Just a few comments about the use of windows and tasks...
First, you only really need to define one task (the "C" task for TIMES). RULES only does one thing and then stops, so can just be used after defining window 1 in GAME. Also, SOKOBAN is already running as the main task in GAME, and so shouldn't be running as another task as well (this means you have two SOKOBANs running together, which might do unexpected things!!)
Secondly, the TIMES task is using window 0, since when you do TASK! that was the active window. It would be better to either move the code directly after the definition of window 3 in game, eg:
: GAME
.....
.....
3 WINDOW 11 ATTRIB
66 27 10 3 S" " OPENPOPUP
['] TIMES C TASK!
.....
.....
;
Alternatively, redefine TIMES so that it selects window 3, eg:
: TIMES
3 WINDOW
BEGIN .... PAUSE AGAIN ;
By doing this, you will no longer need to use AT-XY (or always use 0 0 AT-XY to get to the top left of window 3).
--
Garry Lancaster
http://www.z88forever.org.uk/zxplus3e/
http://www.z88forever.org.uk/
|
Alex_Hot (stranger
)
2002/07/25 00:33
|
|
Thank you Garry! This is our result! Your help was very useful. :)
So, task (for example TIMES) may be connected to the any already defined window using WINDOW into the redefinition of TIMES word.
And first definition of TIMES before definition of GAME (in your example) mast be like
: TIMES ;
as reserving this word, isn't it?
|
garrylancaster (newbie)
2002/07/25 16:13
|
|
> So, task (for example TIMES) may be connected to the any
> already defined window using WINDOW into the redefinition
> of TIMES word.
You don't need to actually define a window (using OPENPOPUP etc) to set the window for a task. The task will either use the current window when TASK! is executed, or it can be specified using WINDOW.
Example 1 (no WINDOW or OPENPOPUP etc used before):
: TIMES BEGIN .... AGAIN ;
' TIMES C TASK!
Task C will use window 0.
Example 2:
: TIMES BEGIN ... AGAIN ;
3 WINDOW
' TIMES C TASK!
0 WINDOW
Task C will use window 3.
Example 3:
: TIMES 5 WINDOW BEGIN ... AGAIN ;
4 WINDOW
' TIMES C TASK!
Task C will start with window 4, but immediately changes to window 5. So, it uses window 5.
> And first definition of TIMES before definition of GAME (in
> your example) mast be like
>
> : TIMES ;
>
> as reserving this word, isn't it?
I don't understand this! Why do you want to define TIMES twice?
--
Garry Lancaster
http://www.z88forever.org.uk/zxplus3e/
http://www.z88forever.org.uk/
|
Alex_Hot (stranger
)
2002/07/27 01:21
|
|
> I don't understand this! Why do you want to define TIMES twice?
I saw your example... :)
Ok. I think, I see my problem. I need info about sequence of definition of a task.
So, is my sequence right?
1. Definition of window.
1 WINDOW 31 ATTRIB
5 5 20 20 S" " OPENPOPUP
2. Definition of TEST word.
: TEST 1 WINDOW BEGIN ... AGAIN PAUSE ;
3. Definition of TEST word as task.
' TEST TASK!
If it is right sequences, can I use some other sequences of definition of a task?
|
garrylancaster (newbie)
2002/07/28 00:44
|
|
I probably haven't explained this very clearly! Let's start again ;)
1. CamelForth has 8 windows altogether, number 0-7. These always exist, and you can re-define them at any time using OPENPOPUP etc.
2. Each task has it's own "current window number". It *doesn't* have it's own windows, though; these are shared between all tasks. To set the "current window number" of the running task, use eg 3 WINDOW to set it to 3.
So, if you have your TIMES example running, so it is showing a clock in window 3, try typing the following:
3 WINDOW 0 0 10 3 S" " OPENWINDOW 0 WINDOW
You will see that TIMES outputs its clock to the redefined window at the top left.
So, you can see that when you define the window and when you define the task are not really connected. (Of course, if you WAKE the task before the window it uses is defined, there will be some unexpected results!)
I think the confusion has arisen because I pointed out that when you define a task with TASK! then the new task will use the current window. For example, if you type 3 WINDOW, then from now on any tasks defined with TASK! will also have 3 as their "current window number". Of course, if you include a WINDOW command in the task itself, that will change it.
--
Garry Lancaster
http://www.z88forever.org.uk/zxplus3e/
http://www.z88forever.org.uk/
|
Alex_Hot (stranger
)
2002/08/12 19:19
|
|
Oops! Tasks and windows are not really connected! It was a problem, yes. Thank you very much!
|
Shaos (enthusiast)
2002/10/16 09:19
|
|
Hello!
I have troubles with emulations your programs (programs made by CamelForth). When SPRINT emulate Sokoban work stopped in moment of keyboard waiting (after Level? prompt). Analize trace of processor don't give me any solutions. So, please, tell me HOW you ask keyboard?
Alexander Shabarshin (shaos@mail.ru)
http://www.shaos.ru
|
garrylancaster (journeyman)
2002/10/16 15:41
|
Re: CamelForth multitasking facilities
[re: Shaos] |
| |
Hi,
In single-tasking mode, CamelForth uses the DSS WAITKEY function. In multi-tasking mode, it uses the DSS SCANKEY function.
I think Sokoban runs multitasking, so the SCANKEY function is the one you want.
Garry
--
Garry Lancaster
http://www.z88forever.org.uk/zxplus3e/
http://www.z88forever.org.uk/
|
Shaos (enthusiast)
2002/10/16 16:02
|
|
> I think Sokoban runs multitasking, so the SCANKEY function is the one you want.
I analize full trace (20 Mb) from start to "Level?" message and cycling and I don't found WAITKEY and SCANKEY calls :(
Program simply make cycle inside #CB14 - #E57F with sofisticated code without any calls to DSS or BIOS...
Alexander Shabarshin (shaos@mail.ru)
http://www.shaos.ru
|
garrylancaster (journeyman)
2002/10/16 17:14
|
Re: CamelForth multitasking facilities
[re: Shaos] |
| |
> > I think Sokoban runs multitasking, so the SCANKEY
> > function is the one you want.
> I analize full trace (20 Mb) from start to "Level?" message
> and cycling and I don't found WAITKEY and SCANKEY
> calls :(
> Program simply make cycle inside #CB14 - #E57F with
> sofisticated code without any calls to DSS or BIOS...
Here is the code used for multitasking keyboard reading. If you search through memory for the string "CEMIT" you will find this code just before it:
;Z EKEYM -- u get event code from standard input (multi version)
nohead EKEYM,docolon
.ekeym_start
defw PAUSE ; allow other tasks to run
defw ekeym_test
.ekeym_test
push bc ; stack TOS
push iy ; save registers
push ix
ld c,DSS_SCANKEY
rst DSS
pop ix
pop iy
jr nz,mgotakey
pop bc
ld de,ekeym_start
next
.mgotakey
ld a,e
and a
jr nz,mrealkey
ld c,d
ld b,1 ; BC=event
jr mgotevent
.mrealkey
ld c,e
ld b,0 ; BC=key
.mgotevent
jp EXIT ; exit the colon definition
--
Garry Lancaster
http://www.z88forever.org.uk/zxplus3e/
http://www.z88forever.org.uk/
|