home *** CD-ROM | disk | FTP | other *** search
- #include <stabs.h>
- #if 0
- /*
- compiles with inline only in large data! AddTask() uses too many
- nonscratch registers :( use of assembler version is recommended
- */
- #include <exec/tasks.h>
- #include <exec/memory.h>
- #include <exec/execbase.h>
- #ifdef __GNUC__
- #define BASE_NAME *(struct ExecBase **)4
- #include <inline/exec.h>
- #else
- #include <clib/exec_protos.h>
- #endif
- #include <clib/alib_protos.h>
-
- extern struct ExecBase *SysBase;
-
- struct newMemList
- {
- struct Node nml_Node;
- UWORD nme_NumEntries;
- struct MemEntry nml_ME[2];
- };
-
- const struct newMemList MemTemplate =
- { {0,},
- 2,
- { {MEMF_CLEAR|MEMF_PUBLIC, sizeof(struct Task)},
- {MEMF_CLEAR, 0} }
- };
-
- extern inline void NewList(struct List *list)
- {
- LONG *p;
-
- list->lh_TailPred=(struct Node*)list;
- ((LONG *)list)++;
- p=(LONG *)list; *--p=(LONG)list;
- }
-
- struct Task *CreateTask(STRPTR name, LONG pri, APTR initpc, ULONG stacksize)
- {
- struct Task *newtask,*task2;
- struct newMemList nml;
- struct MemList *ml;
-
- stacksize=(stacksize+3)&~3;
- {
- long *p1,*p2;
- int i;
-
- for (p1=(long *)&nml,p2=(long*)&MemTemplate,i=7; i; *p1++=*p2++,i--) ;
- *p1=stacksize;
- }
- if (!(((unsigned int)ml=AllocEntry((struct MemList *)&nml)) & (1<<31)))
- {
- newtask=ml->ml_ME[0].me_Addr;
- newtask->tc_Node.ln_Type=NT_TASK;
- newtask->tc_Node.ln_Pri=pri;
- newtask->tc_Node.ln_Name=name;
- newtask->tc_SPReg=(APTR)((ULONG)ml->ml_ME[1].me_Addr+stacksize);
- newtask->tc_SPLower=ml->ml_ME[1].me_Addr;
- newtask->tc_SPUpper=newtask->tc_SPReg;
- NewList(&newtask->tc_MemEntry);
- AddHead(&newtask->tc_MemEntry,(struct Node *)ml);
- task2=(struct Task *)AddTask(newtask,initpc,0);
- if (SysBase->LibNode.lib_Version>36 && !task2)
- {
- FreeEntry(ml); newtask=NULL;
- }
- }
- else
- newtask=NULL;
-
- return newtask;
- }
-
- #else
- asm("
- .globl _CreateTask
-
- _CreateTask: moveml d2/d3/a2/a3/a4/a6,sp@-
- link a5,#-32
- movel a5@(12+8*4:W),d0
- addql #3,d0
- moveq #-4,d3
- andl d0,d3 | stack adjusted
- lea pc@(Lmemlist-.+2),a0
- movel sp,a1
- moveq #6,d0
- L3: movel a0@+,a1@+ | copy memlist
- dbra d0,L3
- movel d3,a1@
- movel sp,a0
- movel 4:W,a6
- jsr a6@(-222:W) | AllocEntry()
- movel d0,a2
- movel a2,d2
- bmis L2
- movel a2@(16:W),a4
- moveb #1,a4@(8:W) | ln_Type
- moveb a5@(7+8*4:W),a4@(9:W) | ln_Pri
- movel a5@(0+8*4:W),a4@(10:W) | ln_Name
- movel a2@(24:W),d0
- addl d0,d3
- movel d3,a4@(54:W) | tc_SPReg
- movel d0,a4@(58:W) | tc_SPLower
- movel d3,a4@(62:W) | tc_SPUpper
- lea a4@(74:W),a0 | tc_MemList
- movel a0,a0@(8:W)
- addql #4,a0
- movel a0,a0@-
- movel a2,a1
- jsr a6@(-240:W) | AddHead()
- movel a4,a1
- movel a5@(8+8*4:W),a2
- subal a3,a3
- jsr a6@(-282:W) | AddTask()
- cmpw #37,a6@(20:W)
- bcss L1 | kick2.0+ ?
- tstl d0
- bnes L1 | task added
- movel d2,a0
- jsr a6@(-228:W) | FreeEntry()
- L2: subal a4,a4
- L1: movel a4,d0 | new task
- unlk a5
- moveml sp@+,d2/d3/a2/a3/a4/a6
- rts
-
- Lmemlist: .long 0,0 | Succ,Pred
- .byte 0,0 | Pri,Type
- .long 0 | Name
- .word 2 | NumEntries
- .long 0x10001 | MemType
- .long 92 | Length
- .long 0x10000 | MemType
- | .long 0 | Length
-
- ");
- #endif
-
- ALIAS (DeleteTask,RemTask);
-