[Coco] noob question

William Astle lost at l-w.ca
Wed Nov 8 11:50:21 EST 2017


On 2017-11-08 09:20 AM, Mathieu Bouchard wrote:
> I doubt it... but as nearly all cases of using a GUI library, there's an 
> infinite loop called a "runloop" that watches for incoming events and 
> distributes them around. The problem with ColorBASIC in this case, is 
> that there are no function pointers nor anything similar enough to that, 
> the only thing that vaguely looks like it are ON ERR GOTO, ON BRK GOTO, 
> and they are not extensible to user-defined events, so you couldn't 
> write a ColorBASIC lib that takes registrations for keys or mouse and 
> GOSUB at will. (IIRC, ColorBASIC doesn't support variable line numbers 
> in ON GOSUB, does it ?)
> 
> Other languages might be different. With asm you can easily have some 
> kind of function pointers and JSR to the contents of a register or RAM 
> variable.

No, Color Basic doesn't support line numbers in variables. It also turns 
out that patching it to do so causes a lot of knock on effects.

To do it right, you also need local variables (stack frames) for 
functions. Color Basic also doesn't have that though you could 
potentially fake it with some degree of success using an array as a 
stack and a variable to serve as a stack pointer. But if you're going to 
do that, you're probably better off going for ASM or another environment.

UI type things are a very good fit for event driven architectures which 
is why most GUI toolkits use some sort of event system. You are right 
about the implementation in those toolkits, though. There is always a 
"main loop" that waits for events to happen and then dispatches them in 
some manner. Whether that's a non-blocking "process events" call that 
needs a manual loop or a blocking event loop, there has to be one somewhere.

It's actually pretty easy to implement such a main loop in ASM once you 
wrap your head around the necessary concepts. It's also pretty easy in C 
(and by extension, it should be pretty easy with CMOC assuming it 
supports function pointers which I haven't checked into).


More information about the Coco mailing list