home *** CD-ROM | disk | FTP | other *** search
- FOR BASIC PROGRAMMERS
-
- The ilbm library operates on several structures. A structure is one block
- of memory which contains various "fields". A field is simply a portion (some
- bytes) of that block of memory. One structure that the ilbm library uses is
- an ILBMFrame. This structure takes up 172 bytes of memory. These 172 bytes
- contain 94 fields. Some fields only take up 1 byte, others are 2 bytes wide
- (a WORD), or 4 bytes wide (a LONG). Certain other fields can be any number
- of bytes wide. These are STRINGS. Each field of a structure contains values
- (numbers). Sometimes these numbers form the address of some other structure.
- An address takes up 4 bytes (just like a LONG), but we'll call it APTR.
- We can further differentiate between a BYTE and UBYTE, WORD and UWORD, and
- a LONG and ULONG. The prepended U means that this field is unsigned (i.e.
- don't ever store a negative number in this field).
- Unfortunately, AmigaBasic has no facility for manipulating structures as
- such. You cannot say, "Set the iFLags field of my ILBMFrame to the value 1."
- You must treat the ILBMFrame as one block of memory, and its various fields
- as offsets from the beginning of that block of memory. You can allocate
- structures (blocks of mem) with the Exec library's AllocMem function which
- returns the start address of the mem block. Here is what an ILBMFrame would
- look like in memory.
-
- Field Name Field Size Offset from start
- ------------ ------------- -------------------
-
- The ILBMFrame starts here:
- iFlags 1 UBYTE 0
- iUserFlags 1 UBYTE 1
- iBMHD.w 2 BYTES (UWORD) 2
- iBMHD.h 2 BYTES (UWORD) 4
- iBMHD.x 2 BYTES (WORD) 6
- iBMHD.y 2 BYTES (WORD) 8
- iBMHD.nPlanes 1 UBYTE 10
- iBMHD.Masking 1 UBYTE 11
- iBMHD.Compression 1 UBYTE 12
- iBMHD.Pad 1 UBYTE 13
- iBMHD.Transparent 2 UBYTES (UWORD) 14
- iBMHD.xAspect 1 UBYTE 16
- iBMHD.yAspect 1 UBYTE 17
- iBMHD.pageWidth 2 BYTES (WORD) 18
- iBMHD.pageHeight 2 BYTES (WORD) 20
- iViewModes 4 BYTES (ULONG) 22
- iColorTable1 2 BYTES (UWORD) 26
- iColorTable2 2 BYTES (UWORD) 28
- iColorTable3 2 BYTES (UWORD) 30
- iColorTable4 2 BYTES (UWORD) 32
- iColorTable5 2 BYTES (UWORD) 34
- iColorTable6 2 BYTES (UWORD) 36
- iColorTable7 2 BYTES (UWORD) 38
- iColorTable8 2 BYTES (UWORD) 40
- iColorTable9 2 BYTES (UWORD) 42
- iColorTable10 2 BYTES (UWORD) 44
- iColorTable11 2 BYTES (UWORD) 46
- iColorTable12 2 BYTES (UWORD) 48
- iColorTable13 2 BYTES (UWORD) 50
- iColorTable14 2 BYTES (UWORD) 52
- iColorTable15 2 BYTES (UWORD) 54
- iColorTable16 2 BYTES (UWORD) 56
- iColorTable17 2 BYTES (UWORD) 58
- iColorTable18 2 BYTES (UWORD) 60
- iColorTable19 2 BYTES (UWORD) 62
- iColorTable20 2 BYTES (UWORD) 64
- iColorTable21 2 BYTES (UWORD) 66
- iColorTable22 2 BYTES (UWORD) 68
- iColorTable23 2 BYTES (UWORD) 70
- iColorTable24 2 BYTES (UWORD) 72
- iColorTable25 2 BYTES (UWORD) 74
- iColorTable26 2 BYTES (UWORD) 76
- iColorTable27 2 BYTES (UWORD) 78
- iColorTable28 2 BYTES (UWORD) 80
- iColorTable29 2 BYTES (UWORD) 82
- iColorTable30 2 BYTES (UWORD) 84
- iColorTable31 2 BYTES (UWORD) 86
- iColorTable32 2 BYTES (UWORD) 88
- iNumColors 1 UBYTE 90
- iCycleCnt 1 UBYTE 91
- iCRNG1.Pad 2 BYTES (WORD) 92
- iCRNG1.Rate 2 BYTES (WORD) 94
- iCRNG1.Active 2 BYTES (WORD) 96
- iCRNG1.Low 1 UBYTE 98
- iCRNG1.High 1 UBYTE 99
- iCRNG2.Pad 2 BYTES (WORD) 100
- iCRNG2.Rate 2 BYTES (WORD) 102
- iCRNG2.Active 2 BYTES (WORD) 104
- iCRNG2.Low 1 UBYTE 106
- iCRNG2.High 1 UBYTE 107
- iCRNG3.Pad 2 BYTES (WORD) 108
- iCRNG3.Rate 2 BYTES (WORD) 110
- iCRNG3.Active 2 BYTES (WORD) 112
- iCRNG3.Low 1 UBYTE 114
- iCRNG3.High 1 UBYTE 115
- iCRNG4.Pad 2 BYTES (WORD) 116
- iCRNG4.Rate 2 BYTES (WORD) 118
- iCRNG4.Active 2 BYTES (WORD) 120
- iCRNG4.Low 1 UBYTE 122
- iCRNG4.High 1 UBYTE 123
- iCRNG5.Pad 2 BYTES (WORD) 124
- iCRNG5.Rate 2 BYTES (WORD) 126
- iCRNG5.Active 2 BYTES (WORD) 128
- iCRNG5.Low 1 UBYTE 130
- iCRNG5.High 1 UBYTE 131
- iCRNG6.Pad 2 BYTES (WORD) 132
- iCRNG6.Rate 2 BYTES (WORD) 134
- iCRNG6.Active 2 BYTES (WORD) 136
- iCRNG6.Low 1 UBYTE 138
- iCRNG6.High 1 UBYTE 139
- iCRNG7.Pad 2 BYTES (WORD) 140
- iCRNG7.Rate 2 BYTES (WORD) 142
- iCRNG7.Active 2 BYTES (WORD) 144
- iCRNG7.Low 1 UBYTE 146
- iCRNG7.High 1 UBYTE 147
- iCRNG8.Pad 2 BYTES (WORD) 148
- iCRNG8.Rate 2 BYTES (WORD) 150
- iCRNG8.Active 2 BYTES (WORD) 152
- iCRNG8.Low 1 UBYTE 154
- iCRNG8.High 1 UBYTE 155
- iWindow 4 BYTES (APTR) 156
- iScreen 4 BYTES (APTR) 160
- iBMAP 4 BYTES (APTR) 164
- iBmSize 4 BYTES (ULONG) 168
-
- If you add up the sizes of all 94 fields, you should get 172 bytes.
-
- Now, let's say that we allocated an ILBMFrame via AllocMem as demonstrated
- in the example program, BasicILBM. We stored the returned address in a varia-
- ble called ILBMFrame.
- There are two AmigaBASIC commands that are used with structures, PEEK and
- POKE. If you want to change a field of the ILBMFrame, you must POKE a value
- to it. If you want to know what value is already stored in an ILBMFrame
- field, then you PEEK that field. For example, if we want to know what the
- ILBMFrame's iNumColors field is, we PEEK that field as follows.
-
- VALUE = PEEK(ILBMFrame+90)
-
- I had to add 90 to ILBMFrame because the iNumColors field's offset is 90
- (see above chart). Now VALUE is the number that was in the iNumColors field.
- If we want to change the number in the iNumColors field to 2, we must POKE
- the field like this:
-
- POKE ILBMFrame+90,2
-
- PEEK and POKE are used for fields that are only 1 BYTE in size (like the
- iNumColors, iFlags, etc). For fields that are 2 BYTES (WORD) in size, you
- must use POKEW and PEEKW.
-
- For LONG and APTR fields (4 BYTES in size), you must use PEEKL and POKEL.
- For example, to get the value in the iViewModes field we do the following:
-
- VALUE = PEEKL(ILBMFrame+22)
-
- Notice how I added the iViewModes field's offset to ILBMFrame.
-
- An APTR field is tricky because you can only put an address there. There are
- two BASIC commands for finding addresses of variables. If the variable is a
- string, use SADD. For all other types of variables, use VARPTR.
-
- A & appended to a variable indicates that the variable is to be a 32 bit
- value. All variables used in calls to the ilbm library must be declared as
- 32 bit values. Alternately, you can force all variables in your program to
- 32 bits by using the statement:
-
- DEFLNG a-Z
-
- This is easier than "casting" each individual variable used in lib calls,
- but is more memory intensive.
-
- Please see the documentation for the requester lib on Fish disk #203 for
- further discussion of SADD and VARPTR.
-
- There is much more to be said about this topic. Please examine the commented
- code of the enclosed BASIC example. If the code seems completely alien to you,
- then you should buy a book on advanced AmigaBASIC programming. I can't recom-
- mend one as I didn't read any. Being an assembly programmer, I was able to
- ascertain how to use these BASIC commands by studying an example on the EXTRAS
- disk.
-
- There is one ILBMFrame field that the example only briefly covers, the
- iUserFlags field. Here are the values you should POKE to enable the following
- features. To enable several features simultaneously, just add up the values
- for each.
-
- Feature Value
-
- NO_POINTER = 1 (bit # 0 - Set means no visible pointer)
- NO_TITLE_BAR = 2 (bit # 1 - Set means hide screen title)
- NO_LOAD_COLORS = 4 (bit # 2 - Set means don't change the present screen
- colors)
-
- ANIM_FILE = 128 This is is only turned on by the lib. You should
- turn it off before every load, by initializing the
- entire iUserFlags field without this enabled, or
- by turning off this one flag as demonstrated below.
-
- After returning from LoadIFFToWindow, if the iUserFlags field is > 127,
- then the image loaded was the first frame of an ANIM file.
- Each "feature" in the iUserFlags field is its own bit, so you can PEEK the
- iFlags field and use the AND and OR Basic commands to determine whether a
- feature is enabled or not. For example, let's isolate the NO_TITLE_BAR bit
- and see if its on:
-
- flag = PEEK(ILBMFrame+22) 'Get the present value
- flag = 2 AND flag '2 is the value of NO_TITLE_BAR flag
- IF flag = 2 THEN PRINT "NO_TITLE_BAR is on" 'flag = 0 if its off
-
-
- Now let's turn off the ANIM_FILE bit without affecting the other bits.
-
- flag = PEEK(ILBMFrame+22) 'Get the present value
- value = 128 'This is the value for the ANIM_FILE flag
- value = NOT value 'To turn off the ANIM_FILE we need to NOT this
- flag = value AND flag 'We just made sure that ANIM_FILE bit is off
- 'without affecting the other bits.
- POKE ILBMFrame+22,flag 'store the new iUserFlags
-
-
- Finally, let's turn on the NO_LOAD_COLORS without affecting the others.
-
- flag = PEEK(ILBMFrame+22) 'Get the present value
- value = 4 'This is the value for the NO_LOAD_COLORS flag
- flag = value OR flag 'We just turned on NO_LOAD_COLORS
- 'without affecting the other bits.
- POKE ILBMFrame+22,flag 'store the new iUserFlags
-
-
- Of course, read the enclosed Doc file fully for a complete understanding
- of the ilbm library functions.
-
- Also, the examples utilize a file selection requester which is a public
- domain library that is available on Fish Disk #203. All the documentation
- is there. In that Basic example, there are a couple things that I need to
- correct. At the label, CheckError, change the code to this:
-
- CheckError:
- IF Result <> 0 THEN GOTO GotPathname
- Result=AutoFileMessage(0&,WINDOW(7))
- INPUT "Type path:";Pathname$
- CALL ParseString(FileIO,SADD(Pathname$))
- GOTO CopyFN
-
- Also, in my comments about reading and writing files, I neglected to place
- the Basic command CALL before certain lib calls. Change them thus:
-
- CALL WaitPointer(WINDOW(7))
- CALL ClearPointer(WINDOW(7))
-
- In these same comments, I used Error as a variable name. This is a reserved
- command in AmigaBasic. Change all occurences of Error to some other variable
- name.
-
- On final note to Basic users: I gave this lib to a friend who was using
- C. Scheppner's Basic ilbm loading code in his program. Not only did the
- load procedure time decrease dramatically, but he claims that his program
- size dropped 140K mostly due to all of the variable storage required by the
- replaced basic ilbm code.
-
- Jeff Glatt
-