Page 2 of 2

Re: network adapter / c compiler

Posted: Thu Dec 07, 2023 5:18 am
by mgkaiser
andmarti1424 wrote: Thu Apr 13, 2023 9:40 pm I am not an expert on this topic but have you take a look at this:

http://www.6502.org/users/andre/osa/oa1.html

?
The example you show splits the stack into 16 stacks of 16 bytes each. Very limiting.

Because you only have a 256 byte stack and cannot relocate it, multitasking is very hard on a 6502. You either need to split the stack which limits number of tasks and limits task size or you need to copy the stack on context switches which is slow.

There is a project which does preemptive multitasking on a C128 but only because the C128 MMU can relocate the stack anywhere in the memory map.

Re: network adapter / c compiler

Posted: Tue Dec 12, 2023 2:44 am
by tim1724
mgkaiser wrote: Thu Dec 07, 2023 5:18 am Because you only have a 256 byte stack and cannot relocate it, multitasking is very hard on a 6502. You either need to split the stack which limits number of tasks and limits task size or you need to copy the stack on context switches which is slow.
One of the best changes on the 65C816 was making the stack pointer 16-bit. This allowed the Apple IIGS to give each running program its own stack.

With the 65C02 I don't see multitasking as very practical, although I suppose the X16 is clocked at a high enough speed to make copying the stack on context switches not too horrible.

Re: network adapter / c compiler

Posted: Tue Dec 12, 2023 3:22 am
by BruceRMcF
tim1724 wrote: Tue Dec 12, 2023 2:44 am
mgkaiser wrote: Thu Dec 07, 2023 5:18 am Because you only have a 256 byte stack and cannot relocate it, multitasking is very hard on a 6502. You either need to split the stack which limits number of tasks and limits task size or you need to copy the stack on context switches which is slow.
One of the best changes on the 65C816 was making the stack pointer 16-bit. This allowed the Apple IIGS to give each running program its own stack.

With the 65C02 I don't see multitasking as very practical, although I suppose the X16 is clocked at a high enough speed to make copying the stack on context switches not too horrible.
It does depend on what kind of muti-tasking you are doing. For example, if you have two threads of cooperative tasks plus a watchdog, 120 bytes is ample stack for each cooperative task round robin thread and 16 ample for the watchdog. Also, whatever hardware stack space you allocate to a task in a pre-emptive multi-tasking system, the tasks are not required to use the $0100 page S index stack as a data stack ... you can use addr,X indexed stacks, and of course that can be located in the HighRAM window if you wish, which gives flexibility for a number of tasks with parsimonious use of the S indexed stack.

Re: network adapter / c compiler

Posted: Tue Dec 12, 2023 1:28 pm
by mgkaiser
Agreed and I nearly always use a software stack for parameters. But you have no choice on the call stack. JSR is going to push its return onto the processor stack. So are interrupts..

I'm actually working on cooperative multitasking, which doesn't really care about the stack. This is really just a framework to hook multiple dynamically loaded modules into a common state machine.