/*--------------------------------------------------------------------------*/ void mtarch_start(struct mtarch_thread *thread, void (* function)(void *data), void *data) { memset(thread->cpustack, 0, sizeof(thread->cpustack)); memset(thread->cstack, 0, sizeof(thread->cstack)); /* Copy current zero page content as template. */ mtarch_asm_threadzp = thread->zp; mtarch_asm_start(); /* Create a CPU stack frame with the appropriate values. */ thread->cpustack[MTARCH_CPUSTACKSIZE - 2] = ((unsigned short)function) / 0x100; /* high byte of return address */ thread->cpustack[MTARCH_CPUSTACKSIZE - 3] = ((unsigned short)function) % 0x100; /* low byte of return address */ thread->cpustack[MTARCH_CPUSTACKSIZE - 4] = 0x21; /* processor flags */ thread->cpustack[MTARCH_CPUSTACKSIZE - 5] = /* a register */ thread->cpustack[MTARCH_CPUSTACKSIZE - 6] = /* x register */ thread->cpustack[MTARCH_CPUSTACKSIZE - 7] = 0x00; /* y register */ thread->spreg = MTARCH_CPUSTACKSIZE - 8; /* Setup the C stack with the data pointer. */ thread->cstack[MTARCH_CSTACKSIZE - 2] = ((unsigned short)data) / 0x100; /* high byte of data pointer */ thread->cstack[MTARCH_CSTACKSIZE - 3] = ((unsigned short)data) % 0x100; /* low byte of data pointer */ /* Setup the C stack pointer. */ thread->zp[1] = ((size_t)&thread->cstack[MTARCH_CSTACKSIZE - 3]) / 0x100; /* high byte of C stack pointer */ thread->zp[0] = ((size_t)&thread->cstack[MTARCH_CSTACKSIZE - 3]) % 0x100; /* low byte of C stack pointer */ }
/*--------------------------------------------------------------------------*/ void mtarch_start(struct mtarch_thread *thread, void (* function)(void *data), void *data) { memset(thread->cpustack, 0, sizeof(thread->cpustack)); memset(thread->cstack, 0, sizeof(thread->cstack)); /* Create a CPU stack frame with the appropriate values... */ thread->cpustack[MTARCH_CPUSTACKSIZE - 2] = ((unsigned short)function) >> 8; /* high byte of return address. */ thread->cpustack[MTARCH_CPUSTACKSIZE - 3] = ((unsigned short)function) & 0xff; /* low byte of return address. */ thread->cpustack[MTARCH_CPUSTACKSIZE - 4] = 0x21; /* processor flags. */ thread->cpustack[MTARCH_CPUSTACKSIZE - 5] = /* a register */ thread->cpustack[MTARCH_CPUSTACKSIZE - 6] = /* x register */ thread->cpustack[MTARCH_CPUSTACKSIZE - 7] = 0; /* y register */ thread->spreg = MTARCH_CPUSTACKSIZE - 8; /* Setup the C stack with the data pointer. */ thread->sp = &thread->cstack[MTARCH_CSTACKSIZE - 1]; mtarch_asm_threadzp = &(thread->zp); mtarch_asm_start(); }