mrr@amanpt1.zone1.com (Mark Rinfret) (01/10/89)
I've just recently started exploring INIT's and didn't get very far before I ran into a snag. When the following small init program is run, it gets a System Error 10 (line F emulator trap) on the InitWindows call. As you can see, I have commented out subsequent portions of the code. I discovered that the InitWindows call was failing by first commenting out everything between the BEGIN/END and incrementally turning statements back on. Hopefully I've provided enough info here. I added a 'sysz' resource, thinking there might be a heap space problem, but playing with various sizes (up to 64K) did no good. This problem is only the tip of a much bigger iceberg, but my inability to solve it has left me quite annoyed. I have all five volumes of Inside Macintosh, plus the revised edition of Macintosh Revealed, yet I feel that there is "some other documentation" (just ordered all tech notes) that would help me with this. Can anyone give me any clues? Thanks. UNIT InitUnit; INTERFACE USES {$LOAD StdLib.load} MemTypes, Quickdraw, OSIntf, ToolIntf, PackIntf {$LOAD} ; PROCEDURE InitMain; IMPLEMENTATION PROCEDURE InitMain; CONST SHIFT_KEY = 56; VAR keys: KeyMap; myQDVars: RECORD { Can't have globals, so we use this... } private: PACKED ARRAY [0..75] OF Char; randSeed: LongInt; screenBits: BitMap; Arrow: Cursor; dkGray: Pattern; ltGray: Pattern; gray: Pattern; black: Pattern; white: Pattern; thePort: GrafPtr; END; result: INTEGER; BEGIN { InitMain } GetKeys(keys); IF NOT keys[SHIFT_KEY] THEN BEGIN InitGraf(@myQDVars.thePort); InitFonts; InitWindows; {InitMenus;} {TEInit;} {InitDialogs(NIL);} {result := CautionAlert(256, NIL);} END; END; { InitMain } END. { InitUnit } -- < Mark R. Rinfret, mrr@amanpt1.ZONE1.COM | ...rayssd!galaxia!amanpt1!mrr > < HyperView Systems Corp. Home: 401-846-7639 > < 28 Jacome Way Work: 401-849-9390 x301 > < Middletown, RI 02840 Hypermedia R Us! >
parent@Apple.COM (Sean Parent) (01/13/89)
In article <541@amanpt1.zone1.com>, mrr@amanpt1.zone1.com (Mark Rinfret) writes: > > I've just recently started exploring INIT's and didn't get very far before > I ran into a snag. When the following small init program is run, it gets > a System Error 10 (line F emulator trap) on the InitWindows call. As you can ... > VAR > keys: KeyMap; > myQDVars: RECORD { Can't have globals, so we use this... } > private: PACKED ARRAY [0..75] OF Char; > randSeed: LongInt; > screenBits: BitMap; > Arrow: Cursor; > dkGray: Pattern; > ltGray: Pattern; > gray: Pattern; > black: Pattern; > white: Pattern; > thePort: GrafPtr; > END; Your variables are in the wrong order (I think) thePort needs to come first. > BEGIN { InitMain } > GetKeys(keys); > IF NOT keys[SHIFT_KEY] THEN BEGIN > InitGraf(@myQDVars.thePort); > InitFonts; > InitWindows; You need to set up A5 correctly with some code that would look like this. oldCurrentA5:= CurrentA5; Handle(CurrentA5Add)^:= @newA5; {CurrentA5Add is a const with the address of the low memory global CurrentA5} newA5:= @myQDVars.thePort; oldA5:= SetA5(LongInt(@newA5)); Then call InitGraf. (newA5, oldA5, and oldCurrentA5 are variables). You will also need to restore this stuff on your way out. (Always be neet and tidy). oldA5:= SetA5(oldA5); Handle(CurrentA5Add)^:= oldCurrentA5; You will also need to set DeskHook to nil and restore it on the way out if you are going to use the Window Manager. (DeskHook is another low memory global) This is needed on all machines except the Mac II (which already clears DeskHook but it would not hurt to do it anyway). WARNING - You are treading on dangerous ground. None of the above is garanteed to work in the future. I am providing this information because I have seen to many INITs that handle it poorly and cause all kinds of problems today. NOTE - Poping up an alert at start-up time is ugly. Calling InitWindows clears the screen and all the nice ShowInit Icons. It would be a little more cosmetic if you patched GNE or SystemTask to pop up the Alert after the machine is fully started (this may not provide the information at the proper time to the user though). Sean
jrk@s1.sys.uea.ac.uk (Richard Kennaway) (01/14/89)
In article <23872@apple.Apple.COM> parent@Apple.COM (Sean Parent) writes: >In article <541@amanpt1.zone1.com>, mrr@amanpt1.zone1.com (Mark Rinfret) writes: >> >> I've just recently started exploring INIT's and didn't get very far before >> I ran into a snag. When the following small init program is run, it gets >> a System Error 10 (line F emulator trap) on the InitWindows call. As you can errr, a what? >You need to set up A5 correctly with some code that would look like this. Boggle!! This is totally over my head. I would like to write some INITs and VBQ tasks and cdevs and so on, but Inside Mac tells me next to nothing about them. Neither do the MPW or Lightspeed C manuals. What do I need to read? I do know how to write ordinary applications. (But I'm not interested in anything that would require learning assembler.) -- Richard Kennaway SYS, University of East Anglia, Norwich, U.K. uucp: ...mcvax!ukc!uea-sys!jrk Janet: kennaway@uk.ac.uea.sys
parent@Apple.COM (Sean Parent) (01/17/89)
In article <316@s1.sys.uea.ac.uk>, jrk@s1.sys.uea.ac.uk (Richard Kennaway) writes: > In article <23872@apple.Apple.COM> parent@Apple.COM (Sean Parent) writes: > >In <541@amanpt1.zone1.com>, mrr@amanpt1.zone1.com (Mark Rinfret) writes: > >> > >> I've just recently started exploring INIT's and didn't get very far before > >> I ran into a snag. When the following small init program is run, it gets > >> a System Error (line F emulator trap) on the InitWindows call. As you can > >You need to set up A5 correctly with some code that would look like this. > Boggle!! > > This is totally over my head. I would like to write some INITs and VBQ tasks > and cdevs and so on, but Inside Mac tells me next to nothing about them. > Neither do the MPW or Lightspeed C manuals. What do I need to read? I do > know how to write ordinary applications. (But I'm not interested in anything > that would require learning assembler.) Sorry, Writting INITs and VBL tasks and the like require a good understanding of how the system operates. I know learning assembly can be a pain (68K is better than most) but nothing will aid you more in these areas then a good debugger and a strong understanding of 68K. As recommended reading (asside from the Motorola 68K manual) try reading Scott Knaster's book "How to Write Macintosh Software" (Hayden Press, I think). This book is a good introduction to how the Mac internals work and provides a lot of debugging tips. As to the code from my previouse post. A5 is a 68K register that the Mac uses to reference QD globals. It is set up to point to a pointer to thePort. Bellow the Port are the other QD globals. DeskHook is a variable stored in low memory that the system (specificaly the window manager) uses to draw the DeskTop on non Mac IIs and I believe it has a few other uses as well. If it is set to nil then the Mac will just draw the DeskTop gray otherwise it will call the routine pointed to by DeskHook to draw the DeskTop. The value of DeskHook at Init time is not defined. I hope this gives you a little more information. Learning the Mac is not easy but it can be fun. Sean