Date: Fri, 2 May 1997 22:30:26 -0500
From: Scott Lahteine <slur@world.std.com>
To: Multiple recipients of <list-fantasm@mail.tau.it>
Subject: Re: The General Thread
>>classes. Information hiding means basically that you have very
few
>>globals, and ideally none. Obviously this idea is very foreign
to asm
>>lovers.
>I think you may be wrong Scott. Most assembly language programmers
are more
>than aware of high level practices. Indeed, I'm sure you'll agree that
low
>level programmers generally make excellent high level programmers because
>they know what the compiler is going to do for any given circumstance.
Sorry, by "foreign," I merely meant that most low-level programmers wouldn't wish for it as part of their working environment.
I have noted a growing angst among many programmers I confer with about their language choices. I for one long for the simplicity of BASIC, the speed and flexibility of ASM, and the abstraction of OOP. And if we could make our code instantly portable and re-usable that would be a plus too!
The thing about Assembly, as we know from using it, is that it remains low-level only so much as we're in the early or intensive stages of design. First we write low-level direct-to-screen kinds of code where we need it, and from then on refer to this object.
The thing is, in assembly, as in C and BASIC, we refer constantly to procedures. OOP refers to objects. An Assembly programmer might decide to make his design object-oriented and name routines according to their object instead of their function, but such weird approaches would be rare.
Essentially, the only thing that distinguishes ASM from a higher-level language is a lack of standardized calling conventions. That is, we always refer explicitly to our subroutines, and they always refer explicitly to whatever data they need at the time. (Jump and data table exceptions noted.)
I have a friend who once wrote a simple text-conversion program to turn structured ASM into plain ASM before assembling it. This would be like an optional upper-level third pass in the assembler. It can also be fairly compared to a C compiler that produces assembly code that can actually be assembled.
So, why not as a first project, those of us who are interested in creating such a structured approach, try putting aseembly data and subroutines into a formal structure and see what comes out? I'd love to play with some of these ideas and see what you all come up with as well.
Later we could IRC or Hotline about it.
-------------------------------------------------
Scott Lahteine <mailto:slur@world.std.com>
<http://world.std.com/~slur/>
"No Universe is perfect which leaves no room for improvement."
-------------------------------------------------
Date: Sat, 3 May 1997 03:44:12 +0000
From: brollo@cableol.co.uk
To: Multiple recipients of <list-fantasm@mail.tau.it>
Subject: Re: News from the Tower 16 Apr '97
>If it's a "goer" then I want Allan's permission to rip
his native fire code
>and Brollo's to use the parallel add (I'll use it anyway, but it's polite
>to ask) :-)
No need to ask, I'm quite happy for anyone to use it without permission. I have much more ambititious things than fire algorithms. So consider the code in the public domain and anyone can use it as they wish. Though of course I'd appreciate mentions in the credits and being told where I might get copies of any work done with the algorithm. Otherwise have good fun and I look forward to seeing any results.
brollo
Date: Sat, 3 May 1997 00:48:14 -0400
From: Stuart Ball <lightsoft@compuserve.com>
To: Multiple recipients of <list-fantasm@mail.tau.it>
Subject: Info: Fantasm-list archives
For your information:
Archives from the Fantasm-list Nov '96 through May 2nd '97 have been placed
on the Lightsoft WWW pages.
The archive will be maintained on a regular basis in the future.
Lightsoft 0544030597GMT.
From: Ajay Nath <AjayNath@compuserve.com>
To: Multiple recipients of <list-fantasm@mail.tau.it>
Subject: ppc optimizations
how many people out there take the time or know hot to optimize ppc asm code?
i have been browsing thru "Optimizing PowerPC Code" by Gary Kacmarcik & have found it to be an excellent book. It has a lot of info about the ppc & optimizations.
has anyone for example thrown "nop" instructions into their code to prevent stalls?
i.e. - something like
lwz r3,therect+top(sp)
nop
cmpwi r3,20
nop
beq somewhere
the above example is made up, i don't even know if having the nops in there helps smooth out the pipeline (i.e. avoid a situation where instruction #2 depends on the result of instruction #1)
the book above suggests certain situations where separating instructions will improve performance. This stuff is something a compiler is good at but when I try to do it the code comes out looking really weird (hard to follow) & I have no way of knowing if i am doing any good.
any thoughts?
Date: Thu, 8 May 1997 22:23:11 -0800
From: Kevin Avila <kevin@cache-computing.com>
To: Multiple recipients of <list-fantasm@mail.tau.it>
Subject: Re: ppc optimizations
>the book above suggests certain situations where separating instructions
>will improve performance. This stuff is something a compiler is good
at but
>when I try to do it the code comes out looking really weird (hard to
>follow) & I have no way of knowing if i am doing any good.
>
>any thoughts?
I have also read the book. I found that if you put a nop after a branch or a system call that helps. After evertline of code however I think might actually just slow it down.
----------------------------------------
Kevin Avila http://www.cache-computing.com
kevin@cache-computing.com
Date: Fri, 9 May 1997 11:18:22 -0400
From: Ajay Nath <AjayNath@compuserve.com>
To: Multiple recipients of <list-fantasm@mail.tau.it>
Subject: Re: ppc optimizations
Kevin said:
<< I found that if you put a nop after a branch or a system call that
helps. After evertline of code however I think might actually just slow
it down.>>
Why put a nop AFTER a branch instruction? It would never get executed since you are branching away from it.
I would never put nops between every instruction...just between ones where the second instruction depended on the result of the first, i.e.:
lwz r3,therect+top(sp)
nop
cmpwi r3,20
nop
beq somewhere
Also I typically exit procedures with these instructions:
mtlr r0
blr
Well according to "Optimizing PowerPC Code" there are 3 wasted cycles in this code since the last instruction has to wait for LR to be updated!
A better way for me to code would be to use:
mtlr r0
; restore some registers
blr
assuming that I could do this.
Date: Fri, 9 May 1997 11:11:41 -0800
From: Kevin Avila <kevin@cache-computing.com>
To: Multiple recipients of <list-fantasm@mail.tau.it>
Subject: Re: ppc optimizations
>Well according to "Optimizing PowerPC Code" there are 3
wasted cycles in
>this code since the last instruction has to wait for LR to be updated!
>
>A better way for me to code would be to use:
>
> mtlr r0
> ; restore some registers
> blr
>
>assuming that I could do this.
I'm sure you can, but I think that if you write a large program the code might get a little confusing with register functions inbetween others. If you really want to get down to the nitty-gritty of using every CPU cycle, try disabling inturputs. That will not only speed up the CPU, but your code was well.
----------------------------------------
Kevin Avila http://www.cache-computing.com
kevin@cache-computing.com
Date: Fri, 9 May 1997 13:19:09 -0500
From: Andy Clayton <bali@ccwf.cc.utexas.edu>
To: Multiple recipients of <list-fantasm@mail.tau.it>
Subject: Re: ppc optimizations
>has anyone for example thrown "nop" instructions into their
code to prevent
>stalls?
>
>i.e. - something like
>
> lwz r3,therect+top(sp)
> nop
> cmpwi r3,20
> nop
> beq somewhere
>
>the above example is made up, i don't even know if having the nops in
there
>helps smooth out the pipeline (i.e. avoid a situation where instruction
#2
>depends on the result of instruction #1)
I don't know much about the PPC specifically, but from what I do know about architecture, I can make some guesses...
Putting those nops in there won't speed up the pipeline any - when the pipeline stalls, it puts those in automatically. All you are doing is manually doing the job it would have done anyway. I don't think that the processor loses any extra time (other than the nop cycles) when it has to insert nops.. Am I wrong? Anyone know more about this?
What would speed it up, though, is if you put useful instructions in those spots that don't depend on r3 or mess with the operands of those instructions at all. For example, take independent instructions from before that lwz and put them between the lwz and the cmpwi. Doing this would take the same amount of cycles as putting the nops in, but at least you would be getting work done.
As for putting a nop after a branch, I'm not completely sure about the
PPC, but I assume it has some kind of instruction prefetching for its pipeline.
So if code looked like this:
<bra> Target
<inst1>
<inst2>
...
Target: <inst9>
The pipeline would look something like this (again, I don't know what
the PPC stages are, but this will illustrate the concept)
Stages:
Cycle: Fetch Decode Execute WriteBack
1 <bra>
2 <inst1> <bra>
3 <inst9> <nop> <bra>
4 <inst10> <inst9> <nop> <bra>
Since a majority of code is linearly executed, the pipeline fetches instructions in sequential order. So after the <bra> is fetched, the <inst1> is fetched. However, when <bra> is being decoded, it figures out that <inst1> should not be the next instruction executed, rather the branch target, <inst9>. So <inst1> has to be replaced with a nop, and there is now one spot in the pipeline that is wasted (called the branch delay cycle).
This branch delay cycle can sometimes be eliminated if you put an instruction that you WANT to execute in <inst1>'s place. I'm not sure how you signal to the processor that it's OK to run it, but if you can, then instead of wasting time with that nop, you can execute a useful instruction in its place.
So you can't do much about eliminating the actual pipeline delay cycles for either of the above situations, but you can fix it so that you get work done instead of nop'ing, and this will reduce the overall run time.
Hope that makes sense,
Andy Clayton
p.s. I hope all of that is not just completely wrong.. I don't know
how the PPC does stuff. Does anyone know if it takes any more time for
the processor to insert those nops in the pipeline? If it does take time,
then I guess manually inserting the nops would help after all. The info
taught in computer architecture classes says it doesn't, but we all know
how well school reflects the real world... :)
Date: Fri, 9 May 97 11:47:11 -0700
From: James Hague <jhague@dadgum.com>
To: Multiple recipients of <list-fantasm@mail.tau.it>
Subject: Re: ppc optimizations
>Putting those nops in there won't speed up the pipeline any - when
the
>pipeline stalls, it puts those in automatically. All you are doing
is
>manually doing the job it would have done anyway. I don't think that
the
>processor loses any extra time (other than the nop cycles) when it has
to
>insert nops.. Am I wrong? Anyone know more about this?
There are two drawbacks to manually inserting nops:
1. They make your code bigger, so more cache loads will be required during
the execution of your program.
2. The nop instructions must be fetched by the processor, adding extra traffic.
There _is_ a weird case in one of the examples in the 601 User's Manual where manually inserting a nop actually helps. But, man, it's a weird case and I'm still not sure I completely understand it...
James
Date: Sat, 10 May 1997 10:39:42 -0400
From: Ajay Nath <AjayNath@compuserve.com>
To: Multiple recipients of <list-fantasm@mail.tau.it>
Subject: Re: ppc optimizations
>> If you really want to get down to the nitty-gritty of using every CPU cycle, try disabling inturputs.<<
This might be a cheap way to speed up my scrolling code! How do I do
this on the PPC? Got an example?
Date: Sat, 10 May 1997 23:16:55 +0000
From: brollo@cableol.co.uk
To: Multiple recipients of <list-fantasm@mail.tau.it>
Subject: Re: ppc optimizations
If there is one book that I would have to reccomend on PPC optimizations, it is CWG or the Compiler Writer's Guide by Steve Hoxey and others. It contains some fascinating snippets of code that are like magic or poetry when it comes to writing assembler code. I copied some of the wonderful examples and they are listed below for you to peruse. The book is available in England and presumably throughout the world for about =A35 or $7. I found it much betters than the two best books that I have bought about writing for the PPC have been the PowerPC 601 Microprocessor User's Manual for its depth (esp. chapter ten's detailed instructions listings) and Compiler Writer's Guide for these numerous useful bits of code and helpful insights.
Here are the examples then:
& =3D AND
^ =3D XOR
//SGN(r3) (x > 0) ? 1 : ((x < 0) ? -1 : 0 )
srawi r4,r3,31 // x >> 31
neg r5,r3 // -x
rlwinm r5,r5,01,31,31 // t =3D (unsigned) -x >>
31 // (=x > 0) ? 1 : 0
or r6,r4,r5 // sign(x) =3D (x >> 31)
| t
//ISGN(r3,r4) (y < 0) ? -ABS(x) : ABS(x)
xor r5,r4,r3 // x ^ y
srawi r5,r5,31 // t =3D (x ^ y) >> 31
xor r6,r3,r5 // x ^ t
sub r6,r6,r5 // (x ^ t) - t
//SWAP(r3,r4)
xor r3,r3,r4 // r3 =3D x ^ y
xor r4,r4,r3 // r4 =3D y ^ (x ^ y) =3D x
xor r3,r3,r4 // r3 =3D (x ^ y) ^ x =3D y
//CLEARLSB
subi r4,r3,01 // x - 1
and r4,r3,r4 // x & (x - 1)
//PREDICATE (x =3D y) ? 1 : 0
sub r5,r4,r3 // x - y
cntlzw r4,r3 // nlz(x - y), (r3 =3D 0) ? 32
: =<32
rlwinm r4,r4,05,31,31 // nlz(x - y) >> 5
//ROUNDUP TO 2^n MULTIPLE
addi r4,r3,(2^n - 1) // increment to next multiple
rlwinm r4,r4,0,0,31 - n // clear lower bits
//CNTTWZ count trailing zeros
addi r4,r3,-1 // x - 1
andc r4,r4,r3 // =ACx & (x - 1)
cntlzw r4,r4 // t =3D nlz(=ACx & (x -
1))
subfic r4,r4,32 // ntz(x) =3D 32 - t
//COMPARE =3D/0, r3>/1, r3</-1
subf r5,r4,r3 // r3 - r4
subfc r6,r3,r4 // r4 - r3 + ((r4 - r3) ?
//BOOLEANs
//BOOLEANs
// =3D0 (r3 =3D 0) ? 1 : 0
cntlzw r4,r3 // nlz(x), (r3 =3D 0) ? 32 :
<32
rlwinm r4,r4,26,00,00 // nlz(x) << 26<0
(r3 < 0) ? 1 : 0 <=3D0 (r3 <=3D 0) ? 1 : 0
addi r4,r3,-1 // so zero goes to -1, MSB
=3D 1
or r4,r4,r3 // take in special case of most
negative number
// >0
(r3<=3D 0) ? 0 : 1
addi r4,r3,-1 // so zero goes to -1, MSB =3D
1
or r4,r4,r3 // take in special case of most
negative number
// >=3D0 (r3 < 0) ? 0 : 1
// r3 < r4 (r3 < r4) ? 1 : 0
subfc r5,r4,r3 // r5 =3D r3 - r4
// r3 > r4 (r3 > r4) ? 1 : 0
subf r5,r3,r4 // r5 =3D r4 - r3
// r3 =3D r4 (r3 > r4) ? 1 : 0
subf r5,r4,r3 // r5 =3D r3 - r4
Date: Sat, 10 May 1997 23:15:10 -0800
From: Kevin Avila <kevin@cache-computing.com>
To: Multiple recipients of <list-fantasm@mail.tau.it>
Subject: Re: ppc optimizations
>This might be a cheap way to speed up my scrolling code! How do I
do this
>on the PPC? Got an example?
All I have is a C-example. If I am correct you need to enter supervisor mode to use these (but mabye not) I don't know YEt how to enter supervisor mode on the PPC, but i'm almost there.
static long setToSevenCode[]
= {0x0007C0700, 0x04E750000}; // or.w
#$0700, sr / rts
static long setToZeroCode[] = {0x0027CF8FF, 0x04E750000}; // and.w
#$F8FF, sr / rts
// turn interrupts off
void TurnInterruptsOff(void)
{
CallUniversalProc((UniversalProcPtr)setToSevenCode, kPascalStackBased);
}
// turn interrupts on
void TurnInterruptsOn(void)
{
CallUniversalProc((UniversalProcPtr)setToZeroCode, kPascalStackBased);
}
----------------------------------------
Kevin Avila http://www.cache-computing.com
kevin@cache-computing.com
Date: Sun, 11 May 1997 03:16:01 -0400
From: Stuart Ball <lightsoft@compuserve.com>
To: Multiple recipients of <list-fantasm@mail.tau.it>
Subject: Re: ppc optimizations
Kev wrote:
> All I have is a C-example. If I am correct you need to enter
>supervisor mode to use these (but mabye not) I don't know YEt how to
>enter supervisor mode on the PPC, but i'm almost there.
Here's my two pennies worth.
What you described there is moving either the classical 0x2700 (All off) or 0x2000 (All on) into the emulated 68k status register i.e. all on or all off and wiping all the cc flags. The Mac normally runs with 0x20 in the upper byte of the emulated SR (amazingly - we've always said that was a "bad" move by Apple, running the OS in supervisor mode that is. 0x00 would be 68k user mode). Before switching off all ints it is most important to save the old value and restore it when one is finished (like running a whole game or demo). On the ST for example one would get quite adept at toggling bits in this register trying to catch the HBL whilst trying to keep everything else running, ummm, but I digress...
On a PowerMac this will not disable all interupts, just the core emulated interupt handler. For example the decrementer will still be clocking away. You have to get into the native priviledged mode before you can do what you like (as you should be able to imo) such as killing all external interupts (msr 48[16] is the external interupt enable flag. 0=off).
Use mfmsr to read and mtmsr to write this register, you'll get a warning from Fant about you need to be in priv mode to use this instruction :-) but that's ok.
Now, the only way afaik to get into to true blue native priv mode is via the emulator. You put some values in some registers (current thinking it's one of the emulator designers birth dates) and then execute a 68k "reset" instruction.
The specific code can be found in the MkLinux booter in the 68k portion (init) towards the end. Resedit with code editor should show up the reset instruction nicely, then it's copy time.
The quickest way of testing this is to create a little frag and replace the MkLinux booter frag with your own. Stuff a Debugger call, or a stdx r1,r2,r3 (my prefered option) at the start, and hopefully as the MKlinux booter is executed, you'll drop into your frag in priv. mode. I would be extremly suprised if Macsbug immediately threw you back into user mode, although it is something you should be prepared for if at first it does not appear to be working. If this were the case, it would be time for some serious email to Apple methinks.
This info is garnered from csmp*, not that I lurk a lot you understand :-)
If anybody does get a chance to try this, maybe it would be nice to post results back to this list, and I'm sure the guys on csmp* would appreciate it as well, as I have seen no concrete evidence that any of this works yet. I'm sure a lot of people would like to know precisely how to do it.
Right, I'm going to try sending this again, before MacCIM crashes again.
Stu.
I'd just like to add that the 601 user manual can be downloaded for free in PDF formata from the motorola PPC page (http://www.mot.com/SPS/PowerPC/) & the IBM compiler authors guide is available for $1 in the US & is readable (but not downloadable) in HTML format on the web at http://www.chips.ibm.com/products/ppc/.
Enjoy!
Date: Sun, 11 May 1997 11:42:50 -0800
From: Kevin Avila <kevin@cache-computing.com>
To: Multiple recipients of <list-fantasm@mail.tau.it>
Subject: Re: ppc optimizations
>On a PowerMac this will not disable all interupts, just the core
emulated
>interupt handler.
oh. okey.
>email to Apple methinks.
It was time for that about 10 years ago. :) Anyway, for some reson the 68K RESET inst locks up my PowerTower 180, however it does work on my PowerBook 5300. Here is the important from MkBooter
movea.l #'Gary',a0
movea.l #$05051956,a1
move.l #$0000C000,d0
moveq #$00,d2
reset
move.l sp,-(sp)
7<gen> d3
So to get into supervisor mode, you need to move the name 'Gary' in a0 (look at the code in the 'Gary' resource in the ROM,k it's quite interesting.) Then move '$05051956' into a1 (which BTW, his Gary's birthday) then you got the 'RESET' function that most likley moves '$0000C000' into the MSR. What you do next is calll an illegal opcode that SOULD switch your machine into supervisor mode.
Incase you have not relized that Fantasm will not compile the opcode '7<gen> d3' so just replace that with 'dc.w $FE03,$67FC'
If anyone actually get into supervisor mode on other then a PowerBook 5300cs, let me know.
----------------------------------------
Kevin Avila http://www.cache-computing.com
kevin@cache-computing.com
Date: Sun, 11 May 1997 22:28:37 +0200
From: Allan Lund Jensen <maccoder@post6.tele.dk>
To: Multiple recipients of <list-fantasm@mail.tau.it>
Subject: Re: ppc optimizations
Ajay Nath wrote:
> This might be a cheap way to speed up my scrolling code! How do I do
this
> on the PPC? Got an example?
If your scroller needs some extra speed, I would think there are other
alternatives to be tried first. How do you do it now? SpriteWorld uses a
pretty clever method of scrolling (although a bit messy). The method is
explained in the docs for Spriteworld.
There are less complicated methods (although more memory hungry), and it
should be possible to get a fairly zippy scroller up and running, especially
in PPC.
I assume youre using some variation of the tile-based scroller, and there are a great many ways to arrange one of those.
Kevin Avila wrote:
> So to get into supervisor mode, you need to move the name 'Gary' in
a0
> (look at the code in the 'Gary' resource in the ROM,k it's quite
> interesting.) Then move '$05051956' into a1 (which BTW, his Gary's
> birthday)
Of course! I was just saying to myself the other day Allan, you ought to move Gary into a0, and then move his birthday into a1, that will probably dump you into supervisor mode. I knew it! Assembler is *so* easy! So how do you get out of supervisor mode? Garys favorite colour, divided by his shoesize in a3?
BTW, I ought to warn you that the church frowns upon this way of coding. Dangerously close to black magic, they say ;)
Dont doubt youre telling the truth Kevin, but this seemed to be slightly bizarre, to say the least. Oh, and whos Gary (he said, displaying his complete ignorance of famous apple employees)?
Allan
Date: Sun, 11 May 1997 19:07:49 -0400
From: Stuart Ball <lightsoft@compuserve.com>
To: Multiple recipients of <list-fantasm@mail.tau.it>
Subject: Re: ppc optimizations
Kev is correct.
I have the same code here in all it's glory, just tidying Kevs up a bit:
move.w #0x2700,sr
move.l #"Gary",a0
move.l #0x05051956,a1
move.l #0xc000,d0
clr.l d2
reset
move.l a7,-(sp)
wait:
dc.w 0xfe03
beq.s wait
This works as long as you don't try to single step the reset instruction which will drive Macsbug completely insane :-) I do not know what the line-f instruction does, but obviously one has to wait .
Before this code there's a long list of instructions moving what appears to be various parameters.
As to Allans how to get back to user mode, just clear the priv bit. Once in priv mode you have complete control, but hey, at least if you crash there you'll do it in complete style.
As to scrolling, there is indeed a fast way of scrolling without using too much memory, but it's quite a bit of work.
Stu.
>easy! So how do you get out of supervisor mode? Gary=92s favorite
colour,
>divided by his shoesize in a3?
Well, once your in, you can get out with the 'rfi' opcode or you can just use 'mtmsr' to get the PR bit set back to 1. However, I have heard some horror stories on the MacOS's reaction of comming out of supervisor mode. So be warrened. :)
>Don=92t doubt you=92re telling the truth Kevin, but this seemed to
be
>slightly bizarre, to say the least. Oh, and who=92s Gary (he said,
>displaying his complete ignorance of famous apple employees)?
Gary is the author of the 68K emulator. For some strange reson all the cool PPC stuff needs to be done thought the emulator. hmm.
----------------------------------------
Kevin Avila http://www.cache-computing.com
kevin@cache-computing.com
Date: Mon, 12 May 1997 11:05:10 -0400
From: Ajay Nath <AjayNath@compuserve.com>
To: Multiple recipients of <list-fantasm@mail.tau.it>
Subject: Re: ppc optimizations
>>
If your scroller needs some extra speed, I would think there are other alternatives
to be tried first. How do you do it now?
<<
Actually my scrolling code is very zippy now...it doesn't use copybits to update the screen contents smoothly either so it doesn't use lots of memory for that. It is really trivial & based somewhat upon code from "Elements of C++ Macintosh Programming" by Dan Weston. (Yes he is the Weston who wrote the 2 greatest mac 68K assembly language books).
U will all get to see the results of the code in a week or so when I
post my source & little app to the Fantasm web page. The last thing
i have to implement is "Cut" & then my app will be complete!
Hurrah!
Date: Sat, 17 May 1997 22:55:35 -0800
From: Kevin Avila <kevin@cache-computing.com>
To: Multiple recipients of <list-fantasm@mail.tau.it>
Subject: BeOS
I just got my BeOS DR9 today. It is sooooo cool. Mutch better then DR8. What has been everyones experince with the BeOS? I have altready started to write a plug-in for the upcomming Anvil product, the framework is done, but I think it will be a few more beta releases of Anvil before I can do some serious work on it.
----------------------------------------
Kevin Avila http://www.cache-computing.com
kevin@cache-computing.com
Date: Sun, 1 Jun 1997 20:55:15 -0400
From: Stuart Ball <lightsoft@compuserve.com>
To: Multiple recipients of <list-fantasm@mail.tau.it>
Subject: News from the Tower - 2nd June 97.
The following items have been uploaded to the Lightsoft WWW pages in the
last week:
1). PF419 update.
2). Stuchat22 - Timing. MOD's.
3). Urltility V1.02. Auth: Ajay Nath.
A complete and useful application for managing URL's. Complete project includes
all source. Covers application framework, native callbacks, Apple events,
window and dialog drivers/filters, application launching, list handling
etc. Highly recommended download for all users, irrespective of experience.
Requires PowerFantasm. PPC only. 70k.
Many thanks and kudos to Ajay for providing the source for all to examine.
4). Survey #2. (This should really be called "Questionnaire #2" but nobody can spell that "Q" word).
------------
With the impending vacation season just about to start, a little reminder for those of us connected to the Fant mailing list.
If you use email autoresponder software, please do one of the following before you go away:
a). UNSUBSCRIBE from the list and resubscribe on your return.
b). Use filtering to not autorespond to email from list-fantasm@mail.tau.it.
c). Not respond to any email with "Precedence: Bulk" in the headers.
Carrying out one of these actions will prevent you annoying a lot of people.
Thank you.
Lightsoft
0150GMT 02Jun97.
Date: Wed, 4 Jun 1997 22:49:54 -0400
From: Ajay Nath <AjayNath@compuserve.com>
To: Multiple recipients of <list-fantasm@mail.tau.it>
Subject: Alpha chip!
I've been reading about DECs Alpha processor. This chip is already working at 300MHz in "Personal Workstations" & is a 64 bit architecture chip! I think there are even 400 MHz systems shippingz! Anyhow, I was reading the PDF file version of the "Alpha Architecture Handbook" & on page 19 came across this surprising sentences.
1) It is not a 32 bit architecture that was later expanded to 64 bits.
2) ...there are no implementation specific pipeline timing hazards, no load-delay
slots & no branch delay slots.
The more I read about this chip the more I like it...I think.
There is no condition codes register, instead conditional branch instructions can test for zero/ nonzero, negative/ positive or odd or even. Seems weird not to have a condition codes register.
I haven't gotten to play with one of these machines but a cousin of mine who has says that they are wicked fast but are hampered by the fact that they run either Digital Unix or Windows NT...neither of which are suited or meant for personal computer use yet. The other problem is of course that Digital is the company behind it & they do a poor job of promoting their products. They are suing Intel now tho for some kind of copyright infringement from the Pentium Pro!
I wonder what the mac might have been had it moved to this chip instead of the PowerPC!
Any thoughts on this chip?
Date: Thu, 5 Jun 1997 04:45:24 -0400
From: Stuart Ball <lightsoft@compuserve.com>
To: Multiple recipients of <list-fantasm@mail.tau.it>
Subject: Alpha chip!
Ajay wrote:
>I've been reading about DECs Alpha processor. This chip is already working
>at 300MHz in "Personal Workstations" & is a 64 bit architecture
chip! I
>think there are even 400 MHz systems shippingz! Anyhow, I was reading
the
>PDF file version of the "Alpha Architecture Handbook" &
on page 19 came
>across this surprising sentences.
>
>1) It is not a 32 bit architecture that was later expanded to 64 bits.
Neither is PowerPC, it's a 64 design downgraded to 32 bit for 01,02,03 and 04 processors. The 620 is the first 64 bit implementation.
>2) ...there are no implementation specific pipeline timing hazards,
no
>load-delay slots & no branch delay slots.
>
>The more I read about this chip the more I like it...I think.
>There is no condition codes register, instead conditional branch
>instructions can test for zero/ nonzero, negative/ positive or odd or
even.
>Seems weird not to have a condition codes register.
>I haven't gotten to play with one of these machines but a cousin
of mine
>who has says that they are wicked fast but are hampered by the fact
that
>they run either Digital Unix or Windows NT...neither of which are suited
or
>meant for personal computer use yet. The other problem is of course
that
>Digital is the company behind it & they do a poor job of promoting
their
>products. They are suing Intel now tho for some kind of copyright
>infringement from the Pentium Pro!
>I wonder what the mac might have been had it moved to this chip instead
of
>the PowerPC!
Slower, hotter and far more expensive.
Generally they are used in groups of at least 4 to get anywhere near the speed of even a decent mini computer. And then an OS that can schedule instructions is needed to get a decent throughput. Coupled with the inherent atomicity problems of shared memory and multiple cache architectures, efficiency drops off spectacularly. 64 alphas on one farm is not uncommon in high end process blocks.
I've seen a PDP 11/04 (not fast by any stretch of the imagination!) replaced by eight Alphas at rather a high cost.
Stu.
Hi guys,
Before I start, let me just say that as of now Im in complete denial about tomorrow where Ill have to face the dread of a C++ examination. Ive nearly succeeded in convincing myself that I actually understand everything about binary trees written in C++, and with a little luck Ill convince myself that templates and polymorfs arent a problem either. By tonight I expect to reach the point of playing solitaire with the undestanding that if I can complete three games in a row Ill pass tomorrow for sure ... basically Im finished.
Sorry, had to get that off my chest.
Anyways, what are you doing for your summer vacation? I imagine that some on the list-server are venturing forth into the unknown with a white camper and a backback. Some might even be going on a authentic vacation to Crete, Tenerife or, dare I say it, Wonderful Copenhagen (dont bother, the prices are too high and the weather sucks ... well, it blows mainly).
But for those lucky few who have absolutely no money, a Mac and a copy of PowerFantasm, you can actually do something slightly productive.
You see, while browsing through one of those neat computer/console magazines (Edge, I think it was) I saw an ad for a competition. It said something like: Write a game and win fabolous prizes. Not exactly, but close enough.
Surprisingly the competition is open for Mac-owners, too. Ordinarily I wouldnt be interested in something like that, but since the first prize is $200.000, I figured it might be worth a moment or two of my spare time. Heck, for $200.000 I would skydive naked over Paris while whistling the theme from Dynasty. Apparently you arent expected to write a sequal to Quake. Last years winner made something that looked like a spin-off from Tetris ... as did the runnerups. I suppose that they are mainly interested in original ideas?
The game doesnt have to include great graphics, or even sound. Just a good idea, put into code. Now I rate my chances slightly below that of a snowballs chance in hell, but as I said ... $200.000. So Ive signed up. And if youve got nothing better to do, maybe you should too? If nothing else youll end up with a Public Domain/Shareware game in the end, and thats nice too, isnt it?
As an added bonus, its a japanese competition, so any text in the game can be in either english or japanese. So, if youre a bit rusty on the finer points of japanese grammar, you might want to brush it up a bit (or see Shogun again) or go for the english language. The webpage also shows that english probably isnt one of their major skills (even worse than mine), so if nothing else you english-speaking people might get a kick out of reading it, just for that.
There are other prizes too, ranging from $25.000 to $10.000, I think. Now, I dont know what the dollar is worth right now, but I imagine that $200.000 (or even $10.000) might be enough for a night on the town as long as you stay away from drinks with umbrellas and straws.
So, if you, as any normal programmer, are scared to go outside and face the true nemesis of programming: sunlight, I think this might be worth a week or two of your time. As far as I remember the space game accompanying Powerfantasm was made in 24 hours, and although originality probably wasnt its strongest point, it certainly showed it was possible.
The address for the competition is (youll have to sign up (its free)):
Look under competition, natch.
I hasten to add, that I have absolutely nothing to do with these guys, so this certainly isnt an ad. I just thought it might be nice to wave the flag for mac-assembler in this slightly unconventional way. So although this could sound like one of those moronic newsgroup mails (Make tons of money in fifteen minutes), it actually isnt; and I would think youll have to invest a bit more time than fifteen minutes. As soon as exams are over, Im starting. With any luck, Ill finish it, too.
The closing date is late november, this year. If any of you guys win, a picture of your new car would a) make me cry like a baby b) be greatly appreciated.
In any of you choose to enter: good luck.
In closing, I just want to ask if any of you guys are, or know of, any telepatic C++-programmers. My exam is in little less than 20 hours, so any help you can offer (be it occult or otherwise) would be greatly appreciated (Ive thought about faking a heart-attack, but the prospect of recieving the kiss of life from my 40-year old C++-teacher, Freddy, doesnt exactly thrill me).
Sorry for the long text, which is just part of my scheme to forget all about my C++ exam ... with very little success, I might add.
In any case, have a nice summer ...oh, and a nice exam, too.
Im off to play solitaire.
Allan
Stu pointed out something that might be misunderstood.
Apparently anyone in the land of the free, good ol' US of A, could get the impression that the main prize was only $200, since the . in $200.000 means $200 and 0 cents in USA.
Well, the grand prize is $200000. And the runnerup prizes are, as far as I recall, $25000 and $10000 (there's $400000 in prizes). A nice chunk of change to anyone I should think.
So you really should be able to afford that car. I can see that $200 wouldnt get you much besides a bicycle. Or is it bike? No, that's a motorcycle....
American is a tricky language to master. I apologize ;)
Allan
Date: Mon, 9 Jun 97 13:04:14 -0700
From: Steve Cunningham <synthman@loop.com>
To: Multiple recipients of <list-fantasm@mail.tau.it>
Subject: [off topic] Re: Here's an idea...
On 6/9/97 10:04 AM, Allan Lund Jensen made the following insightful observation:
>Apparently anyone in the land of the free, good ol' US of A, could
get
>the impression that the main prize was only $200, since the . in
>$200.000 means $200 and 0 cents in USA.
Actually, Allan, two hundred dollars and no cents US would be $200.00.
The third decimal place was a bit confusing; thanks for the clarification!
>So you really should be able to afford that car. I can see that $200
>wouldnt get you much besides a bicycle. Or is it bike? No, that's a
>motorcycle....
Bike *could well* be a bicycle. Or a motorcycle, usually of Japanese origin and designed for dirt riding. As in dirt bike. Motorcycle is usually a street bike, and a Harley is a Harley. Then of course there1s a cycle, but let1s not go there ;-)
American lesson over; time to crawl back into my cubby.
>American is a tricky language to master. I apologize ;)
C++ is far trickier, but then you knew that....
Best,
Steve
--------------------------------------------------------------
Steve Cunningham Professional Marketing Geek
synthman@loop.com Voice mail: 800-207-0781
A complex system that works is invariably found
to have evolved from a simpler system that works.
I've have a kinda neat feature request. The story goes like this:
In my dissassembler MacNosy I am used to see conditional branches like this:
bc IF_NOT,cr0_EQ,some_where
but when I tried to do the same Fantasm (naturally) complained. The way
to
do it as it is detailed in the 601 reference manual from Motorola is
(appearently) to replace all those IF,IF_NOT thingies with numbers which
to
me seems like a more flawed approach.
Wouldn't it be nice if Fantasm would let you use the above form instead of the numbers and the Fantasm would auto-substitute with the correct number so that they would be legal? What do others think?
Maybe there is a way to do that now, I don't know. I'm kinda new to Fantasm, see.
/Per Hjeltman
--
"I program, therefore I am."
Do you believe in Macintosh? Please check out:
<http://www.evangelist.macaddict.com/>
>If you want to use cr0 (the default integer flags), there's no need
to
>write it, as in:
> bne label
>is the same as
> bne cr0,label
>is the same as
> bc 4,2,label
What I fail to understand is how "bne label" translates into "bc 4,2,label". Yes, there's a table in the 601 Reference but I don't understand it!
For example, here's how the 601 Ref. explains it:
001zy Branch if the condition is FALSE
How do I interpret 001zy into 4?
And how does 2 translate into cr0?
And why doesn't Fantasm syntax colour "bcl" - it IS a branch,
right?
Thanks for any help, I'm really puzzled right now.
/Per Hjeltman
--
"I program, therefore I am."
Do you believe in Macintosh? Please check out:
<http://www.evangelist.macaddict.com/>
Date: Mon, 16 Jun 97 08:34:03 -0700
From: James Hague <jhague@dadgum.com>
To: Multiple recipients of <list-fantasm@mail.tau.it>
Subject: Re: Feauture request - what do you think?
>For example, here's how the 601 Ref. explains it:
>001zy Branch if the condition is FALSE
>
>How do I interpret 001zy into 4?
>And how does 2 translate into cr0?
>And why doesn't Fantasm syntax colour "bcl" - it IS a branch,
right?
The "z" bit must always be zero. The "y" bit is the branch prediction bit; setting it to one reverses the normal behavior. "00100" in binary is 4.
As for the cr0, realize that the branch instructions actually specify
a _bit_ in the condition register, not an entire field like cr0 or cr1.
The condition register really looks like this:
bit 0 | bit 4 | | v v 0123 0123 0123 0123 0123 ... cr0 cr1 cr2 cr3 cr4 ...
So, cr0 represents bits 0-3 of the condition register, cr1 represents bits 4-7, etc. Within a field, the bits are broken down like this:
bit 0 = less than
bit 1 = greater than
bit 2 = equal
bit 3 = summary overflow (rarely used)
So, in your example, the "2" means bit 2, or "the equality bit of cr0." To use cr1 instead, the value would be 6.
Tricky? Somewhat. But fortunately you can use the short forms most of the time.
--James
I'm very intrested in exception vectors and how to modify them for you own dirty deeds. ;-)
Maybe someone knows where to go for further reading on this topic?
/Per Hjeltman
--
"I program, therefore I am."
Do you believe in Macintosh? Please check out:
<http://www.evangelist.macaddict.com/>
Date: Wed, 18 Jun 1997 18:28:02 -0700
From: Kevin Avila <kevin@cache-computing.com>
To: Multiple recipients of <list-fantasm@mail.tau.it>
Subject: Re: Info on how to modify exception vectory, anyone?
>I'm very intrested in exception vectors and how to modify them for
you own
>dirty deeds. ;-)
>
>Maybe someone knows where to go for further reading on this topic?
Again, I think you need to be in supervisor mode to do this, however
I may be wrong because I did see a C source on Apple's ftp servers a few
months ago.
Date: Thu, 19 Jun 1997 01:44:21 -0400
From: Stuart Ball <lightsoft@compuserve.com>
To: Multiple recipients of <list-fantasm@mail.tau.it>
Subject: Re: Info on how to modify exception vectors...
Per wrote:
>>I'm very intrested in exception vectors and how to modify them for
you own
>>dirty deeds. ;-)
>>
>>Maybe someone knows where to go for further reading on this topic?
Kev wrote:
> Again, I think you need to be in supervisor mode to do this, however
I may
>be wrong because I did see a C source on Apple's ftp servers a few months
>ago.
Here's some info. I found on a newsgroup a while back from Kees Stapel that may be helpful...
<<<Exeptions are mapped in ROM to addresses fff0xx00 (MSR(EP) = 1). The exeption handlers save sp to sprg1, lr to sprg2 and then jump to an address in a vector table. The address of the vector table is in sprg3. The vector table is in RAM,in an area close to the top of physical RAM, that IS mapped with logical memory.
The vector table can be accessed at logical address 5fffe420 and at address 68ffe420 (the physical address of the table is 17de420 on my computer with 1800000 bytes RAM). Since these addresses are so close to 60000000 and 69000000 I don't expect they depend on the amount of RAM in the computer.
This all makes getting in and out of privileged mode fairly easy. Just put the (physical) address of your supervisor routine at 5fffe450 (the offset of the system call exeption vector from the start of the table is 30), execute 'sc' and before returning to user mode with 'rfi' restore lr and sp from sprg2 and sprg1 respectivily.>>>
Stu.
>Per wrote:
>>>I'm very intrested in exception vectors and how to modify them
for you own
>>>dirty deeds. ;-)
>>>
>>>Maybe someone knows where to go for further reading on this
topic?
Stu wrote:
>Here's some info. I found on a newsgroup a while back from Kees Stapel
that
>may be helpful...
<snipped a description from Kees Stapel>
Kees, well as a matter of fact I mailed him on the matter and he sent me some code to try. Unfortunately what he does appearently only works on some machines, like his 601 based system.
If anybody is interested in the code (it's NOT the same he posted to the newsgroup) give me a holler.
Maybe I could do it with 68k code? In that case it would be easy! A call to _DebugUtil with the selector 8 in D0 generates the trap....EnterSupervisorMode (really!). I tried it too, after stepping over the trap the 'S' bit in the SR was set. That's a good sign. ;-)
/Per Hjeltman
Date: Thu, 19 Jun 1997 12:14:00 -0700
From: Kevin Avila <kevin@cache-computing.com>
To: Multiple recipients of <list-fantasm@mail.tau.it>
Subject: Re: Info on how to modify exception vectors...
>Kees, well as a matter of fact I mailed him on the matter and he
sent me
>some code to try. Unfortunately what he does appearently only works
on some
>machines, like his 601 based system.
>
>If anybody is interested in the code (it's NOT the same he posted to
the
>newsgroup) give me a holler.
>
>Maybe I could do it with 68k code? In that case it would be easy! A
call to
>_DebugUtil with the selector 8 in D0 generates the
>trap....EnterSupervisorMode (really!). I tried it too, after stepping
over
>the trap the 'S' bit in the SR was set. That's a good sign. ;-)
If you could send the code to me, that would be great. Because if I
am not mistaken the ROM addresses for sc calls are actually at 4 differant
places (depending on your motherboard). Now EnterSupervisorMode will get
you into supervisor mode on 68K machines, however, try it on PowerPC and
all you get is a bus error. :)
Dear List members
I am a registered user of Powerfant since last year. Despite various attempts it just doesn't want to click into place and I don't seem to be able to get any further. I suppose it does not help that I don't have a PowerMac as most of the examples for PF are for PPC.
Are there any helpful souls on this list who would let me have a look at their source code of a game (for 68k) or anything else that might help me to get going. Hand on my heart that I won't disclose any code or info to anybody else - I just want to learn assembler what I regard as the "Rolls Royce" of programing laguages :-)
Any help will be very much appreciated.
Thank you
Thomas
On Wed, Jun 25, 1997 7:50 PM, Thomas Hartmann <mailto:scope@ndirect.co.uk> wrote:
>Dear List members
>I am a registered user of Powerfant since last year.
>Despite various attempts it just doesn't want to click into place and
I
>don't seem to be able to get any further.
I know the feeling, I am there with you. Any help to you is help to me :)
>I suppose it does not help that I don't have a PowerMac as most of
the
>examples for PF are for PPC.
>Are there any helpful souls on this list who would let me have a look
at
>their source code of a game (for 68k) or anything else that might help
me
>to get going. Hand on my heart that I won't disclose any code or info
to
>anybody else - I just want to learn assembler what I regard as the "Rolls
>Royce" of programing laguages :-)
I know a little about resources and various MacOS issues... if there is dialogue on this list and I can help then I will. I too am on a 68K...
>Any help will be very much appreciated.
>Thank you
>Thomas
>PS: Is it OK to ask boring beginner questions on this list?
It'd be nice. I probably should go try and re-read the PFantasm documentation. I have a 68030 reference manual I borrowed (I'm on a 040 actually) but it is way too technical for me, but I could look stuff up I guess :)
Jinx_tigr
(aka Chris Johnson)
PS: Is it OK to ask boring beginner questions on this list?
> I know the feeling, I am there with you. Any help to you
is help
>to me :)
>
> I know a little about resources and various MacOS issues...
if there is
>dialogue on this list and I can help then I will. I too am on a 68K...
Good to hear that I am not alone with problems. Nice one Chris :-)
> I probably should go try and re-read the PFantasm
>documentation. I have a 68030 reference manual I borrowed (I'm on a
040
>actually) but it is way too technical for me, but I could look stuff
up I
>guess :)
Yes, but even after reading the manual there are still a lot of questions. I know how time consuming it can be to write a manual especially a beginners guide and I lift my hat to Lightsoft for their attemps- the only problem with the beginners guide which one gets with Powerfant is that after the first chapters it dives into the deep end of assembler - and I am lost.
How have you guys ever managed to get to grips with it. Please let an outsider in :-)
Regards
Thomas
Date: Wed, 25 Jun 97 20:44:35 -0700
From: James Hague <jhague@dadgum.com>
To: Multiple recipients of <list-fantasm@mail.tau.it>
Subject: Re: Please help a beginner
Thomas Hartmann wrote:
>How have you guys ever managed to get to grips with it. Please let an
>outsider in :-)
PowerFant is at least the fifth such system I've used, and I already knew 6502, 65816, 8086, SH2, and 68K assembler before coming to it. But your message brings back memories of the difficult times I had when I first started learning assembly.
The first assembly I ever did was back on the Atari 800 in 1983. And, man, was I confused. I waded through a pretty good introductory book, but it only covered basic topics. My first attempts at writing fancier assembly programs were disasters, and it took me a long time to get going. What really jumpstarted and inspired me were the assembly listings they used to print in a magazine called ANALOG Computing. I learned countless tricks from reading those listings.
The best thing to do, IMO, is to look at as much assembly source as possible--really dig into it. There's some great stuff at the Lightsoft web site. I'd love to see more, but everyone gets very secretive about their code these days :-) The URL manager is a nice little PowerPC program. I picked up a couple of things from it, even having written bunches of PPC before seeing it. Admittedly, the Mac is a more complex system than the old 8-bitters!
Good luck!
--
James Hague
Dadgum Games
http://www.dadgum.com
Date: Wed, 25 Jun 1997 21:06:34 -0700
From: Kevin Avila <kevin@cache-computing.com>
To: Multiple recipients of <list-fantasm@mail.tau.it>
Subject: Re: Please help a beginner
>Good luck!
Thats about all I can say to you as well. I seem to have total forgot 68K assembly and have totaly focused on PowerPC. So, if someone on this list does remember 68K assembly and would like to help we write a few bootstrap files for my OS kernel, please mail me. :)
Kevin Avila http://www.cache-computing.com
kevin@cache-computing.com
Date: Thu, 26 Jun 1997 04:11:24 -0400
From: Scott Lahteine <slur@world.std.com>
To: Multiple recipients of <list-fantasm@mail.tau.it>
Subject: Re: Please help a beginner
>I am a registered user of Powerfant since last year.
>Despite various attempts it just doesn't want to click into place and
I
>don't seem to be able to get any further.
I can send you some 68K code I wrote for the Amiga awhile ago. It's pretty well documented, and some of it translates well to the Mac environment. (Just ignore any references to "coppers," "blitters," and the like....) There are little routines - like handling linked lists - which you might find very useful. RSVP to my Email and I'll attach it to you in a Stuffit archive.
Among other things, it covers data structures, keeping linked lists of "objects," and doing various housekeeping tasks. There's also a conversion "shell," for writing CLI commands to do various file-conversions. The shell code is very Amiga-specific, but the code that plugs into it is completely generic. It should be pretty easy to understand the basic structure and grok what's going on.
I think that assembler - whether PPC or assembler - is easiest to understand once you have a good understanding of Structures, which are at the heart of every branch of programming. Get a handle on binary math, boolean math, hexadecimal (and other numeric bases), flag registers, and loops, and you're golden. Then you just plug into the hardware and go....
If you're looking to do MacOS GUI stuff, creating windows and all that, get a hold of (or create) a pile of macros that mirror the C calls for Toolbox routines. It'll save you endless hours eventually.
A good reference for 680x0 assembler is "68000 Assembly Language Programming," by Leventhal, Kane, et. al., available from McGraw Hill. There are lots of references, but I find this one to be the most concise. It provides simple comprehensive examples of 68K instructions in their natural habitat, and includes an indispensible at-a-glance reference section you'll turn to again and again to look up LINK and UNLK.
Cheers!
-------------------------------------------------
Scott Lahteine <mailto:slur@world.std.com>
<http://world.std.com/~slur/>
"No Universe is perfect which leaves no room for improvement."
-------------------------------------------------
Hi Chaps,
Ref. beginners assembly language, specially with regard to 68k assembly
language, I can strongly sympathise with all that has been said.
I would suggest you try the following.
First, pick a simple idea you want to produce as a program and scribble down an outline. Don't go overboard here - keep it simple. A classic would be printing "Hello world" in a window and then waiting for some user input, say a mouse click or a keypress.
Break the program down into it's various constituent "logical"
bits as follows.
1. Initialise.
2. Do the work.
3. Wait for input.
4. Tidy up and quit.
Now study the PF reference manual and pick a few useful 68k instructions.
You will need the move instructions, some maths and some stack stuff as
a bare minimum. In particular study the difference between the various sizes
of operands - i.e. byte, word and long, 8 16 and 32 bits respectively.
These basic instructions can do most of the useful work. It's handy to know
stuff such as the bcd maths instructions, but you won't need them for everyday
work.
Next learn the basic adressing modes - immediate data, pc relative and
address register indirect with offset are the main ones, viz:
move.l #20,d0 *moves the number 20 into d0 affecting all 32 bits
of the register
**Fantasm will optimise this to a moveq instruction if the optimiser is
on.
move.w #20,d0 *moves the number 20 into d0, affecting the lower
16 bits only.
move.b #20,d0 *moves the number 20 into d0, affecting the lower
8 bits only
lea my_string(pc),a0 *a0 points to my_string
move.l 32(a0),d0 *move all 32 bits at a0+32 into d0.
Next you need to be able to decode the headers so you can call "traps". On your disks is a folder called "Mac trap calls". In here are some 97 files detailing most Macintosh OS calls as C headers. Details of how to decode these for assembly language use are included in the PF docs, but for completeness here's an example:
pascal WindowPtr GetNewCWindow(short windowID,void *wStorage,WindowPtr
behind)
= 0xAA46;
This call, GetnewCWindow will get a window from a resource and open it on the screen. It's coded in 68k as:
CLR.L -(SP) *space for the return parameter, in this case
a WindowPtr which is a long
MOVE.W #128,-(SP) *Resource ID of our window - 128. word=short
move.l #0,-(sp) *pointer to where record will go, in this
case zero means we don't want it. Pointers are always longs.
move.l #-1,-(SP) *behind which window? -1=none.
DC.W 0xaa46 *The trap number - a word.
move.l (sp)+,d0 *get the new window ptr which is needed
to talk to this window.
This code will get the window you have defined (with Resedit) in you application with an ID of 128 and return a reference to it in d0.
If you have included the file MAC_TRAPS_68k.def into your source then rather than "dc.w 0xaa46" you can "dc.w _GetNewCWindow" which makes things more readable. I would suggest you make this file a "globinc" so in all your files you can use it.
You will need to use _ShowWindow to display the window if not marked as visible in the resource, _SetPort to set the graphics drawing port and _MoveTo to set printing coordinates.
Now you can use _DrawString to draw into it (takes a pstring). Then use _Button in a loop to read the mouse button.
Drawstring looks like this:
pea my_string(pc) *where my_string is defined as a pascal
type string, viz: my_string: pstring "Hello"
dc.w _DrawString
Button looks like this in 68K:
wait_for_button:
clr.b -(sp) *for the mouse button, returns a byte
dc.w _Button
tst.b (sp)+ *Test the return value
beq wait_for_button *if zero, do it again.
**The beq will become a beq.s if the optimiser is on.
Note, in the above getnewwindow call, for speed, the code:
move.l #0,-(sp)
move.l #-1,-(sp)
can be replaced with
pea 0,-(sp)
pea -1,-((sp)
which saves a few bytes and runs faster.
When you have cracked the idea behind OS calls, I would suggest you get onto Apples Dev site and download as many Inside Macs as you need (free download), but as a bare minimum Toolbox essentials and More toolbox along with Memory, Files and Imaging with quickdraw.
Also, it is well worth printing out some of the mac trap files such as
files, memory, quickdraw, windows etc. Put them in a ring binder - I found
it invaluable when I started on the Mac.
After a while you'll get to know them pretty much off by heart.
You may also want to invest in Think Reference (available from Mactech I believe?) or the Macintosh Assistant Toolbox from Apple (US$90 ish). You still need the files to decode the trap number, but these are useful for finding some of the more obscure calls.
A good tip is to use MacsBug. Put in a "debug" directive at the start of your program and then follow it through in MacsBug - you can spot when things go awry.
Another - start with Build mode. Don't use the stand alone mode of Fantasm, it's not worth the grief in the long run. The idea behind Build and global and external labels can take a while to "sink in".
You should find that having cracked a simple program, things will then move more quickly.
Finally, do post your questions to this list. Doesn't matter how silly they sound.
With regard to specific code examples, just "state the nature of your emergency" and I'm sure something will pop up.
I hope this message doesn't sound too patronising; it's not intended to be.
Stu.
Yep, here comes a stupid question.
How do I do one of these 'StandardGetFile' dialogs in PPC assembly? This is really easy in C but to do it in assembly turned out to be a real pain.
1) In the C equivalent I got my FileFilterUPP by calling NewFileFilterProc() but as it turns out, in assembly 'NewRoutineDescriptor' gets called instead. Well, I can't figure out how to set the parameters for NRD correcly. Well I do know how to make a normal one but how do I do one that I can use with StandardGetFile()?
2) In my C equiv. I did this:
SFTypeList mySFTypeList;
mySFTypeList[0] = 'APPL'
How would that translate into assembly?
3) How do I set up my Reply record? It's got tons of fields!
And (finally) is there any way to use CodeWarrior C and PowerFantasm assembly together? I really don't want to wait for Fanta_C to come.
/Per Hjeltman
--
"Assembly language programmer - masochist with a smile!"
Do you believe in Macintosh? Please check out:
<http://www.evangelist.macaddict.com/>
Date: Thu, 26 Jun 1997 15:44:00 -0400 (EDT)
From: Figaro Tea <humphret@lurch.winthrop.edu>
To: Multiple recipients of <list-fantasm@mail.tau.it>
Subject: Re: Please help a beginner
I had a horrible time starting out too, I honestly can't remember what made it finally click though.
There's two things to learn here though: assembly and MacOS; since you need to know how to write in a language to learn the OS, it's probably best to learn assembly first. A few questions first though. Are you totally new to assembly, i.e. do you know about the 4 fields for an instruction? Do you know about stacks? I'll probably start from the very beginning--since this list is now archived, maybe somebody will read it later and learn assembly.
One thing I found helpful when first starting out was learning how to enter and exit my program--for awhile, *all* my programs ended in system errors. Basically, the first line of code executed is the start of your program. It doesn't need to be labeled "Main" or anything like that. If you're using Fantasm's Build mode, which you should, then the first file assembled contains the start of your program.
Fantasm, not assembly, has a requirement that you have at least one globally defined label. So, even though I said that you don't have to call the first line "Main", you might desire to do so in order to please Fantasm.
Your program can end in various ways--a system error being the most undesirable. Usually it ends with an 'rts' instruction. When the processor sees this instruction it quits your program. (It actually does more than this, but for right now this is what it does.) Your program may end in a system error if you just let it end at the last line, so always end it with an 'rts' instruction.
So the simplest program you could make would look something like this:
Main: rts ;end program
global Main
This program lives only to die, i.e. that's all it does.
If you're totally new to assembly I'll go into the structure of an instruction.
Each assembly instruction is always only one line long. This line is always divided into 4 fields which are separated by white space (spaces, tabs). I'll discuss the fields below.
1st Field) This the label for the instrucion. This is commonly used as a reference for other instructions. The colon that ends the label isn't required to be there, but you'll find useful to always suffix your labels with it. The label is an optional field, although this doesn't mean you should ignore it. Don't forget to put a tab or a space in this field if you don't intend to use it--notice in the second line of the program above I use tabs to fill in the label field, instead of typing in one.
2nd Field) The instruction field. This field is, of course, required--if it weren't there you wouldn't have an instruction! Instructions in this field can be the instructions actually used by the processor, 'rts'; used by the assembler, 'global'; or custom-made instructions, commonly known as macros and no, there wasn't a macro listed in the program.
The instructions used by the processor are what you'll probably use the most and they comprise the bulk of your program. Instructions for the assembler are known as directives. The assembler knows the instruction is its own by the pure fact that it isn't a processor instruction, not to complex really. I'll discuss macros some other time, since they're custom-instructions you can do without them. Note, you might also see this refered to as the opcode field, it's an OPeration CODE.
3rd Field) Operand Field. Many instructions need data to work on, and this is where you put that data. Think of it like this, when you add numbers you have to have the instruction, the plus sign +, and you have the data for the instruction, the numbers. So this: 2+2, would be this in assembly:
add 2,2
If you use the HP brand of graphing calculators then you'd recognize this as reverse-polish notation: issue the instruction and then the data. It might be a pain now, but you'll come to appreciate it--actually makes more sense doing it this way the more you think about. Notice that each individual data element is separated by a comma and not a space, remember that spaces separate instruction fields and not data elements. If an instruction doesn't need any data, like the 'rts' instruction, then you can of course leave it blank.
4th Field) Comments. This field is the comment field. I'm not exactly sure if Fantasm automatically recognizes this as a comment field, but it's customary to begin this field with a comment character. Comments in assembly begin with either a semicolon (;), or an asterick (*). Anything after this character is ignored. Comments do not bleed over to the next line, so when you press return the comment is done. (Actually, when you press return the entire instruction is done, regardless of what fields you have left to fill in) You can make the entire line be a comment by simply making the first character a comment character. (As a personal preference, when I make the entire line a comment I use the asterick, I use the semicolon when I want to add a comment after an instruction--I don't have to hold down the shift key so it's a little faster:)
Because assembly instructions are rather cryptic at times, you might want to comment each line of your code--versus other languages, you'd be surprised at how soon you forget what a piece of code does. This is just my own personal preference however, and you'll probably develop your own commenting style. If you do comment, I recommend you make it something informative: don't say "adding 2 and 2", say "adding 2 to player 2's score".
Since I don't know what skill level you're at in assembly, I'll stop here. If you want me to continue on then I will.
..._Tim_...
--=[Until you believe something, there is nothing to be proven]=--
http://www.winthrop.edu/~humphret
zzhumphreyt@winthrop.edu
Date: Thu, 26 Jun 1997 12:56:59 -0700
From: Kevin Avila <kevin@cache-computing.com>
To: Multiple recipients of <list-fantasm@mail.tau.it>
Subject: Re: StandardGetFile and Fantasm?
>2) In my C equiv. I did this:
>
>SFTypeList mySFTypeList;
>mySFTypeList[0] = 'APPL'
Okey this is all off the top of my head so it might be wrong, or perhaps even another way to do it, but here is how I do it. Okey in C SFTypeList is defined as:
typedef OSType SFTypeList[4];
so in your golabls file you want to put
mySFTypeList: rs.l 4
and then in C you use:
mySFTypeList[0] = 'APPL'
...but in assembly you want to use
li r20,0x0000
mr r24,r20
lis r21,'PL'
ori r21,r21,'AP'
mr r20,r21
lwz r21,mySFTypeList(rtoc)
slwi r24,r24,2
add r21,r21,r24
stw r20,(r21)
I think thats how it's done, but who know this code might start a war. ;)
----------------------------------------
Kevin Avila http://www.cache-computing.com
kevin@cache-computing.com
Date: Thu, 26 Jun 1997 18:48:58 -0400
From: Ajay Nath <AjayNath@compuserve.com>
To: Multiple recipients of <list-fantasm@mail.tau.it>
Subject: StandardGetFile and Fantasm?
>> How do I do one of these 'StandardGetFile' dialogs in PPC assembly?
I hate to toot my own horn but if you download the code to "Urltility" you will find lots of PPC code...some of which shows how to set up a dialogfilterproc & use it with the dialog manager...it also shows how to call StandardGetFile