crunch@well.UUCP (John Draper) (04/17/86)
< choomp chomp - drooolllll!! > I got permission from Jim Goodnough from Manx to publish the following information. Manx C has some problems when spawning tasks. It appears that the A4 register is improperly set. Below is some code that you need to add to get multi-tasking to work properly. Before calling the "AddTask" function, it is necessary to call the sava4() function which is listed below. Then, in your Task, you need to call geta4(). The code below can be included in your source or be seperately compiled and linked into your program. ----------------- cut here ---------------- /*==================================================================== Get and Save A4 Regs to fix a manx bug =====================================================================*/ #asm a4sav dc.l 0 public _sava4 _sava4 lea a4sav,a0 move.l a4,(a0) rts public _geta4 _geta4 move.l a4sav,a4 rts #endasm Another problem with the Manx system is in the debug program. It is not possible to set a breakpoint in a separate task. The "db" program will only call the "guru". Manx also doesn't have a "kprintf" function, so using intermediate print statements to debug code is a royal pain. Jim cooked up a "kprintf" routine, and it's listed below. The "kprintf" function only works if you connect an external terminal to the serial port or another computer. Then all your debug diagnostic printing can take place on the external computer. I use the Macintosh as an external computer and use the ImageWriter cable connected to the serial port on the Amiga. I use MacTerminal because it has an extra large capture buffer and send all my debug messages over to the Mac screen. It works very well. I also hacked up the "avail.c" program and modified it to use "kprintf" so I can keep track of memory allocations so I can make sure I release it when done. It works very well and painlessly. My only problem seems to be that I forget to cast the sizeof's to (long)'s. Which really messes things up. The "kprintf" code is listed below. ----------------- cut here ----------------- /* * This is a debug library which interacts directly with the Serial * port. * * Functions are: * kprintf(fmt, arg1, arg2,....); * kputchar(char); * kputs(string); */ kprintf(fmt, args) char *fmt; int args; { int kputchar(); return(format(kputchar, fmt, &args)); } kputs(str) char *str; { while (*str) kputchar(*str++); kputchar('\n'); } #asm public _LVORawPutChar public _kputchar _kputchar move.l 4,a6 move.w 4(sp),d0 ;make the 'w' an 'l' if using c32.lib cmp.b #$a,d0 bne.s .1 jsr _LVORawPutChar(a6) move.l #$d,d0 .1 jmp _LVORawPutChar(a6) #endasm -------------- cut here ---------------- I hope this makes your programming effort easier. It sure has made it better for me. Regards: John Draper Programmers Network ( A programmers Guild) "The place where we all live and learn" .....ihnp4!ptsfa!well!crunch