Wimp_Poll in task window?
Simon Willcocks (1499) 513 posts |
I just noticed that programs can call Wimp_Poll without first calling Wimp_Initialise. (s.Wimp01) Can someone please explain to me when that might be appropriate? What it’s for? Presumably when you know you’ll be running in a TaskWindow… |
David J. Ruck (33) 1635 posts |
The TaskWindow module creates a WIMP task for the program to run in, but you should not call Wimp_Poll yourself. |
Rick Murray (539) 13840 posts |
Does it even actually work if you’re not a known Wimp task? Maybe it’s just an omission? |
Simon Willcocks (1499) 513 posts |
It’s not checked (along with many other Wimp SWIs marked with an ‘x’ in Wimp01. I wondered if anyone used it to perform a sleep in a TaskWindow or something like that. I have a feeling it’s going to come back and bite me at some point. |
Rick Murray (539) 13840 posts |
Did you actually ever try it? DIM block% 255 SYS "Wimp_Poll", 0, block% TO event% PRINT "The returned Wimp event is ";event% The application effectively vanishes at the point of calling Wimp_Poll, the last line is never printed. I’ve not looked to see what is going on, but I’m suspecting that there may be several issues with swapping out a task that has no task handle… |
Rick Murray (539) 13840 posts |
And here? Nothing gets printed. Clearly the current application is aborted hard. #include <stdio.h> #include <stdlib.h> #include "kernel.h" _kernel_swi_regs r; char block[256]; void byebye(void) { printf("atexit() called.\n"); return; } int main(void) { atexit(byebye); r.r[0] = 0; r.r[1] = (int)block; _kernel_swi(0x400C7 /* Wimp_Poll */, &r, &r); printf("Returned event code is %d\n", r.r[0]); return 0; } So, I think that not requiring there to be an active task is either an oversight, or there’s some weird optimisation to be had by not checking (and people will learn quickly that it doesn’t work like that ;) ). |
Rick Murray (539) 13840 posts |
Oddly enough, this code works from within ShellCLI. But it is very precarious. As long as no other task has input focus, you can press ESC to end. But if another task has input, that no longer works and trying it will probably kill the other task (I just killed NetSurf by pressing ESC with the caret in the writeable for this forum). In short, it’s probably like one of those edge cases in BASIC. That you can doesn’t mean you should. Plus, it’s not a big hardship to call Init, then whatever (Poll,SendMessage,or just nothing) and then CloseDown right afterwards. My OLED module does that in order to trick the Wimp into not flashing up the CommandWindow as the module starts up because the Wimp is looking for VDU output, it is not looking at where that output is going (it’s going to a sprite, not the screen).
UpCall #6 – works like a PollWord (task will sleep until word is non-zero). |
Simon Willcocks (1499) 513 posts |
OK, I will assume someone just wanted to save a couple of clock cycles on frequently called SWIs. Fingers crossed. |