[comp.sys.apple2] List Manager Question

bclark@pro-harvest.cts.com (Brian Clark) (01/23/91)

Okay, can somebody help me out here with a problem on the List Manager...
I've got a list of members that are not standard strings and I want use
the SortList2 call, passing it a comparePtr to my own routine.  I'm
working in ORCA/C not assembly, and would like to code the comparision
function in C and use the asm{} statement to do a sec or clc instruction.
I've tried this, but can't get it to work right.  What happens is that it
just reverses the entire list, not sorting it.  Which leaves me to believe
that the carry flag always gets set when the function returns, regardless
of what I set it to durring the functions execution.  Is there any way to
do this? Heres what I got now:

#pragma databank  1
#pragma toolparms 1
pascal void sort_members (MemRec *memberA, MemRec *memberB)
{
   if (strcmp(memberA -> memPtr -> name, memberB -> memPtr -> name) < 0) {
       /* memberA is less than memberB */
       asm { clc };
   }
   else {
       /* memberA is greater than or equal to memberB */
       asm { sec };
   };
}
#pragma toolparms 0
#pragma databank  0


And on different question, I've got a custom routine coded in C to draw
the members. This routine works great, and I've done similar routines in
other programs without problems. The question is: Is this running on luck
or is it guaranteed to work okay. What I'm refering to is that on page
11-5 of toolbox reference volume 1, it shows that it pushes the 3 things
on the stack and a 3 byte return address (why isn't it 4 bytes anyways?),
will this be taken care of for me, or does C take 4 bytes off stack and
its messing up the stack without somehow messing up my program?  Heres
what I bascially got:

#pragma databank  1
#pragma toolparms 1
pascal void draw_member (Rect *rec, MemRec *member, ListCtlRecHndl lhand)
{
    /* does all the stuff needed to draw the member here... */
}
#pragma toolparms 0
#pragma databank  0

 ___________________________________________________________________
|                  |||                                              |
|   Brian Clark    |||  \    ProLine:  bclark@pro-harvest           |
|------------------|-|--=>  InterNet:  bclark@pro-harvest.cts.com   |
| "][gs Forever!!" |||  /       UUCP:  crash!pro-harvest!bclark     |
|__________________|||______________________________________________|

dlyons@Apple.COM (David A. Lyons) (01/28/91)

In article <7157@crash.cts.com> bclark@pro-harvest.cts.com (Brian Clark) writes:
>Okay, can somebody help me out here with a problem on the List Manager...
>I've got a list of members that are not standard strings and I want use
>the SortList2 call, passing it a comparePtr to my own routine.  I'm
>working in ORCA/C not assembly, and would like to code the comparision
>function in C and use the asm{} statement to do a sec or clc instruction.

Apparently the stack-cleanup code ORCA/C is generating does not preserve your
carry flag setting (not surprising).

You need to write an assembly "shell" around your comparison procedure,
so that you pass the shell routine to SortList2, and the shell routine
calls your real procedure and then sets the carry flag based on (say) an
integer value returned from the real procedure.

I don't know whether you can do this all from ORCA/C or not; you could
definitely do it by linking in an assembly routine.  (The trick is to
get ORCA/C *not* to generate stack-cleaup code around your routine.) 
-- 
David A. Lyons, Apple Computer, Inc.      |   DAL Systems
Apple II System Software Engineer         |   P.O. Box 875
America Online: Dave Lyons                |   Cupertino, CA 95015-0875
GEnie: D.LYONS2 or DAVE.LYONS         CompuServe: 72177,3233
Internet/BITNET:  dlyons@apple.com    UUCP:  ...!ames!apple!dlyons
   
My opinions are my own, not Apple's.

dlyons@Apple.COM (David A. Lyons) (01/28/91)

In article <7157@crash.cts.com> bclark@pro-harvest.cts.com (Brian Clark) writes:
>[...] The question is: Is this running on luck
>or is it guaranteed to work okay. What I'm refering to is that on page
>11-5 of toolbox reference volume 1, it shows that it pushes the 3 things
>on the stack and a 3 byte return address (why isn't it 4 bytes anyways?),
>will this be taken care of for me, or does C take 4 bytes off stack and
>its messing up the stack without somehow messing up my program?

Whoops, forgot to answer this part in my last message.  RTL addresses are
always 3 bytes, and C knows that.  No problem.
-- 
David A. Lyons, Apple Computer, Inc.      |   DAL Systems
Apple II System Software Engineer         |   P.O. Box 875
America Online: Dave Lyons                |   Cupertino, CA 95015-0875
GEnie: D.LYONS2 or DAVE.LYONS         CompuServe: 72177,3233
Internet/BITNET:  dlyons@apple.com    UUCP:  ...!ames!apple!dlyons
   
My opinions are my own, not Apple's.