Resources
Volume Number: | | 1
|
Issue Number: | | 7
|
Column Tag: | | Assembly required
|
Using the Common Resources
By Frank Alviani
Resources are the most mystifying of all the Mac technology, mainly because they are undocumented, and not usually found on other computers. The purpose of resources are to seperate text, icons, fonts, menu items and dialogs from the executable source code of a program where they can be easily changed without re-compilation. With the resource editor and other tools, this opens up a world of user customized programs. The user literally changes the program resources to his own tastes. This makes for an exciting possibility in software adaptation that has yet to be fully explored. In the meantime, programmers still must struggle to make use of resources effectively.
A big problem is not having adequate documentation of the format of each resource in terms of a binary file specification; exactly how many bytes and in what format each resource item is specified. While the RMaker provides an easy way to assembly resources, it does little to explain their internal format. The Apple Assembler has the ability to compile resources directly, offering an alternative to the RMaker utility. All that is lacking is the correct assembler source code format of each resource. Now Frank Alviani has filled this omission gap by providing us with the assembler format of all the major resources. This information should go a long way toward improving the resource void. We encourage others to help in this area by sending in articles or information on resources to help improve our understanding of this vital Mac concept. [David E. Smith, Editor]
Linker or RMaker
The big advantage to using the linker rather than the RMaker is flexability. You can control every detail - type style, etc. To balance this, linking is significantly longer and certain RMaker capabilities simply dont exist - linking in picture resources, for example. With RMover, those disadvantages are pretty small, however.
Only the reasonably common resources are documented here (mostly those in volume 1 of IM). I didnt include the Font resource defs, since nobody in their right minds would do a font in assembler (I had to do 2 in assembler for a DEC Pro system when I wrote a custom screen manager and I KNOW how bad that is!!). While there are probably others that arent included, Ive had no use for them.
The few notes regard (1) The correction to the control type field in the Control resource, and (2) an explanation of the enabling mask field in the Menu resource. These are naturally confusing since IM is wrong or silent on the matters.
I decided to take this approach to building a prototypes file, rather than use macros, because (a) A typical macro call would be too big to fit on a line, and I am somewhat fussy about the appearance of my code (I have enough trouble without messy code confusing me further...) (b) I include explanatory comments on each line, so I dont have to keep referring to reference material for each field. Disk space is virtually free, so why not?
;
;Resource Prototypes for Assembler usage
;
;Frank Alviani
;
;More verbose than macros, but easier to copy & fill in...
;
;NOTES -
;
;ALL resources using local labels (labels starting with @) must
;be bracketed by regular labels; local labels can be re-used only
;if the duplicates are separated by regular labels. This applies
;even if no warning appears in the resource prototype!
;
;These are arranged roughly alphabetically, altho the DLOG/ALRT/DITL
;are grouped together at the end.
;
;In general # represents a numeric field normally filled in.
;The name and attribute fields on the RESOURCE line are optional.
;
;The idea is to have this in one editor window, and to copy to the
;resource file being built as needed. This will hopefully speed the
;process, and give flexability the RMaker doesnt.
;
;There are some additional explanatory comments with various resources.
;
;Some of this is copied from MacTutor 1/4.
;RESOURCE ATTRIBUTES
SYSREF EQU 128
SYSHEAP EQU 64
PURGABLEEQU 32
LOCKED EQU 16
PROTECTED EQU 8
PRELOAD EQU 4
CHANGED EQU 2
;RESOURCE FILE ATTRIBUTES
READONLYEQU 128
COMPACT EQU 64
MAPCHANGEDEQU 32
;DITL TYPE EQUATES
BUTTON EQU 4
CHKBOX EQU 5
RADIO EQU 6
RESCTL EQU 7
;
STATEXT EQU 8
EDITEXT EQU 16
ICONITM EQU 32
QDPICT EQU 64
USERITM EQU 0
;
DISABLE EQU 128
;WINDOW TYPES
DOCBOX EQU 0 ;standard document window
ALERT EQU 1 ;alert
PLAIN EQU 2 ;plain
PLAINSHDEQU 3 ;plain with shadow
NOGROWDOC EQU 4 ;document window w/o grow box
ROUNDBOXEQU 16 ;rounded-corner window (see IM for setting corner radius..)
;CONTROL TYPES
CBUTTON EQU 0 ;simple button
CCHKBOX EQU 1 ;check box
CRADIO EQU 2 ;radio button
USEWFNT EQU 8 ;add to above to use windows fonts
CSCROLL EQU 16 ;scroll bar
; IDENTIFICATION resource - needed for Finder to locate Icon
RESOURCE WCA1 0 IDENTIFICATION
DC.B AA1-@1
@1:DC.B Ver. 0.1 3/31/85
AA1:
;BUNDLE resource
.ALIGN 2
RESOURCE BNDL ### name [(attr)]
DC.L WCA1 ;signature
DC.W 0,1 ;data (doesnt change)
DC.L ICN# ;icon mappings
DC.W 0 ;number of mappings - 1
DC.W 0,128 ;map 0 to icon 128
DC.L FREF ;FREF mappings
DC.W 0 ;number of mappings - 1
DC.W 0,128 ;map 0 to fref 128
;CONTROL resource
;
;NOTE - although the assembler definition of this claims that the
;control type field is a long word, IT LIES. Control type is a 16-bit
;field!!
.ALIGN 2
RESOURCE CNTL ### name [(attr)]
DC.W # ;top
DC.W # ;left
DC.W # ;bottom
DC.W # ;right
DC.W # ;initial value
DC.W 0 ;visible (T/F)
DC.W # ;max value
DC.W # ;min value
DC.W # ;control type
DC.L 0 ;refCon
DC.B @2-@1 ;title length (at least 1)
@1:DC.B xxx ;title
@2:
;CURSOR resource
.ALIGN 2
RESOURCE CURS ### name [(attr)]
DC.L #,# ;1st 8 bytes of cursor
DC.L #,# ;2nd 8 bytes
DC.L #,# ;3rd 8 bytes
DC.L #,# ;4th 8 bytes
DC.L #,# ;1st 8 bytes of mask
DC.L #,# ;2nd 8 bytes
DC.L #,# ;3rd 8 bytes
DC.L #,# ;4th 8 bytes
DC.W #,# ;h,v of hot spot
;FREF resource
RESOURCE FREF ### name [(attr)]
DC.B APPL,0,0,0
;ICN# resource
.ALIGN 2
RESOURCE ICN# ### name [(attr)]
;thered usually be an include here...
;MENU resource
;
;NOTE - the enable field: bits are number right to left 0-15. Bit
;1 is the first menu item. A 0 bit in the mask disables that item.
;I havent tried it, but I think turning off bit 0 of the mask
;disables the entire menu..
.ALIGN 2
RESOURCE MENU ### name [(attr)]
lbl: DC.W1 ;MENU ID
DC.W 0 ;width holder
DC.W 0 ;height holder
DC.L 0 ;std menu pro holder
DC.L $1FF;enable all items
DC.B @2-@1 ;title length (in bytes)
@1:DC.B 20;title (this is the apple)
@2:
;MENU ITEM resource
DC.B # ;item length
DC.B xxx ;menu item
DC.B 0 ;no icon
DC.B 0 ;keyboard equivalent
DC.B 0 ;marking character
DC.B 0 ;style of items text
DC.B 0 ;END OF MENU ITEMS
;PATTERN stuff
.ALIGN 2
RESOURCE PAT ### name [(attr)]
DC.L #,# ;1st, 2nd 4 bytes of pattern
.ALIGN 2
RESOURCE PAT# ### name [(attr)]
DC.W # ;# of patterns
DC.L #,# ;1st, 2nd 4 bytes of pattern #1
;STRING resource
.ALIGN 2
RESOURCE STR ### name [(attr)]
DC.B @2-@1 ;text length
@1:DC.B xxx ;text
@2:
;STRING LIST resource
.ALIGN 2
RESOURCE STR# ### name [(attr)]
DC.W # ;count of strings
DC.B @2-@1 ;text length - string #1
@1:DC.B xxx ;text
@2:
label: ;REQUIRED REGULAR LABEL HERE!
;WINDOW resource
.ALIGN 2
RESOURCE WIND ### name [(attr)]
DC.W # ;top
DC.W # ;left
DC.W # ;bottom
DC.W # ;right
DC.W # ;window type
DC.W # ;visible (T/F)
DC.W # ;draw goAway (T/F)
DC.L 0 ;refCon (available)
DC.B @2-@1 ;title length
@1:DC.B xxx ;title
@2:
; -- Dialog / Alert / DITL are grouped together --
;DIALOG resource
.ALIGN 2
RESOURCE DLOG ### name [(attr)]
DC.W # ;top
DC.W # ;left
DC.W # ;bottom
DC.W # ;right
DC.W # ;window type
DC.B # ;visible (T/F)
DC.B 0 ;IGNORED
DC.B # ;goAway flag (T=has close box)
DC.B 0 ;IGNORED
DC.L 0 ;refCon
DC.W # ;ID of DITL list
DC.B @2-@1 ;text length
@1:DC.B xxx ;text
@2:
;ALERT resource
.ALIGN 2
RESOURCE ALRT ### name [(attr)]
DC.W # ;top
DC.W # ;left
DC.W # ;bottom
DC.W # ;right
DC.W # ;resource ID of DITL list
DC.W # ;stages (see IM for details..)
;DITL resource
.ALIGN 2
RESOURCE DITL ### name [(attr)]
DC.W # ;# of items - 1
lbl: DC.L0 ;handle holder
DC.W # ;top
DC.W # ;left
DC.W # ;bottom
DC.W # ;right
DC.B type;item-type
DC.B @2-@1 ;item length (MUST BE EVEN)
@1:DC.B xxx ;item
@2:
; items must be even length
; item types are as follows
; control item - control-item + 4
; button0
;check box1
;radio button 2
;resource 3
;
;static text8
;edit text16
;icon item32
;quickdraw pict 64
;user item0
;
; disable item - item + 128
; system icons
;stop 0
;note 1
;alert 2