' ColorBox
' This progam uses an Image structure and the Intuition DrawImage()
' command to put several copies of a 24x16-bit 8-color rectangular image
' in a window connected to an 8-color custom-screen.
CHDIR "j:structures2"
DEFLNG a-Z
LIBRARY "exec.library"
DECLARE FUNCTION AllocMem() LIBRARY
LIBRARY "intuition.library"
CHAIN MERGE "j:Structures2/StructSubs.h",9003,ALL
StructSubsReturn: ' don't forget the return labels for overlays!
ImgWidth = 24 ' define image dimensions
ImgHeight = 16
ImgDepth = 3
' The following code segment is general purpose. It determines the number
' of bytes required for a bitplane, forcing the width to be in full WORDs.
' This is the function of the macro RASSIZE() seen in some 'C' programs
' that deal with images on the Amiga. 'C' macros are not available through
' AmigaBASIC .bmap files.
IF ImgWidth/16<>ImgWidth\16 THEN ImgWidth = ((ImgWidth\16)+1)*16
PlaneBytes = ImgHeight*(ImgWidth/8&)
' Now with the proper bitplane size, we can calculate the number of bytes
' required to hold the image data:
NumBytes = PlaneBytes*ImgDepth
' We can use the STRUCT() subprogram to allocate memory for any purpose.
' Here it is used to clear and set aside Chip RAM for the image data:
STRUCT BoxData,NumBytes,"ClrPubChip"
' read and save image data as WORDs, so STEP by 2 though NumBytes:
FOR i=0 TO NumBytes-1 STEP 2
READ image%
POKEW BoxData+i,image%
NEXT i
' set up Image structure:
STRUCT BoxStrct,20&,"ClrPubFast"
WORD 0& ' LeftEdge
WORD 0& ' TopEdge
WORD ImgWidth ' Width
WORD ImgHeight ' Height
WORD ImgDepth ' Depth
APTR BoxData ' ImageData
BYTE 7& ' PlanePick
BYTE 0& ' PlaneOnOff
APTR 0& ' NextImage
' open new screen and window (no close gadget):
SCREEN 1,640,400,3,4 ' 8-color, high-res, interlaced screen
WINDOW 2,"8-Color Window",(120,100)-(540,300),23,1
RastPort = WINDOW(8)
' draw several images:
FOR j=25 TO 125 STEP 100
FOR i=25 TO 400 STEP 65
DrawImage RastPort,BoxStrct,i,j
NEXT i
NEXT j
dly = TIMER ' wait 15 seconds
WHILE TIMER - dly < 15
WEND
ender:
WINDOW CLOSE 2
SCREEN CLOSE 1
FreeMem BoxData,NumBytes ' ALWAYS DEALLOCATE RAM WHEN THROUGH!!!
FreeMem BoxStrct,20& ' (before closing libraries!)
LIBRARY CLOSE
CHDIR "/"
SYSTEM
'*************************************************************************
'**** image pixel-grid looks like:
' 000000111111222222333333
' 000000111111222222333333
' 000000111111222222333333
' 000000111111222222333333
' 000000111111222222333333
' 000000111111222222333333
' 000000111111222222333333
' 000000111111222222333333
' 444444555555666666777777
' 444444555555666666777777
' 444444555555666666777777
' 444444555555666666777777
' 444444555555666666777777
' 444444555555666666777777
' 444444555555666666777777
' 444444555555666666777777
' NOTE: large images can be brought in as overlays.
' NOTE: don't put comments on DATA statement lines!
'**** bitplane 0:
DATA &H3,&HF03F
DATA &H3,&HF03F
DATA &H3,&HF03F
DATA &H3,&HF03F
DATA &H3,&HF03F
DATA &H3,&HF03F
DATA &H3,&HF03F
DATA &H3,&HF03F
DATA &H3,&HF03F
DATA &H3,&HF03F
DATA &H3,&HF03F
DATA &H3,&HF03F
DATA &H3,&HF03F
DATA &H3,&HF03F
DATA &H3,&HF03F
DATA &H3,&HF03F
'**** bitplane 1:
DATA &H0,&HFFF
DATA &H0,&HFFF
DATA &H0,&HFFF
DATA &H0,&HFFF
DATA &H0,&HFFF
DATA &H0,&HFFF
DATA &H0,&HFFF
DATA &H0,&HFFF
DATA &H0,&HFFF
DATA &H0,&HFFF
DATA &H0,&HFFF
DATA &H0,&HFFF
DATA &H0,&HFFF
DATA &H0,&HFFF
DATA &H0,&HFFF
DATA &H0,&HFFF
'**** bitplane 2:
DATA &H0, &H0
DATA &H0, &H0
DATA &H0, &H0
DATA &H0, &H0
DATA &H0, &H0
DATA &H0, &H0
DATA &H0, &H0
DATA &H0, &H0
DATA &HFF,&HFFFF
DATA &HFF,&HFFFF
DATA &HFF,&HFFFF
DATA &HFF,&HFFFF
DATA &HFF,&HFFFF
DATA &HFF,&HFFFF
DATA &HFF,&HFFFF
DATA &HFF,&HFFFF
9002 ' start of "StructSubs.h" structure subprograms overlay file
SUB STRUCT(StrctName&,StrctSize&,MemType$) STATIC
SHARED NextStrctAdrs&
MemfPublic = 1&
MemfChip = 2&
MemfFast = 4&
MemfClear = 65536&
Type$ = UCASE$(MemType$)
IF Type$ = "CLRPUBFAST" THEN MemType& = MemfClear + MemfPublic + MemfFast
IF Type$ = "CLRPUBCHIP" THEN MemType& = MemfClear + MemfPublic + MemfChip
IF Type$ = "PUBFAST" THEN MemType& = MemfPublic + MemfFast
IF Type$ = "PUBCHIP" THEN MemType& = MemfPublic + MemfFast
IF Type$ = "CLRFAST" THEN MemType& = MemfClear + MemfFast
IF Type$ = "CLRCHIP" THEN MemType& = MemfClear + MemfChip
StrctName& = AllocMem(StrctSize&,MemType&)
NextStrctAdrs& = StrctName&
END SUB
SUB BYTE(ByteVal&) STATIC
SHARED NextStrctAdrs&
POKE NextStrctAdrs&,ByteVal&
NextStrctAdrs& = NextStrctAdrs& + 1&
END SUB
SUB WORD(WordVal&) STATIC
SHARED NextStrctAdrs&
POKEW NextStrctAdrs&,WordVal&
NextStrctAdrs& = NextStrctAdrs& + 2&
END SUB
SUB LONG(LongVal&) STATIC
SHARED NextStrctAdrs&
POKEL NextStrctAdrs&, LongVal&
NextStrctAdrs& = NextStrctAdrs& + 4&
END SUB
SUB SPTR(Text$) STATIC
SHARED NextStrctAdrs&
Text$ = Text$ + CHR$(0)
Text = SADD(Text$)
LONG Text
END SUB
SUB SUBSTRUCT(StrctSize&) STATIC
SHARED NextStrctAdrs&
FOR i=0 TO StructSize&-1
POKE NextStrctAdrs& + i, 0
NEXT i
NextStrctAdrs& = NextStrctAdrs& + StrctSize&
END SUB
SUB APTR(AdrsVal&) STATIC
LONG AdrsVal&
END SUB
' $IGNORE ON
9003 GOTO StructSubsReturn
' $IGNORE OFF
9002 ' start of "StructSubs.h" structure subprograms overlay file
SUB STRUCT(StrctName&,StrctSize&,MemType$) STATIC
SHARED NextStrctAdrs&
MemfPublic = 1&
MemfChip = 2&
MemfFast = 4&
MemfClear = 65536&
Type$ = UCASE$(MemType$)
IF Type$ = "CLRPUBFAST" THEN MemType& = MemfClear + MemfPublic + MemfFast
IF Type$ = "CLRPUBCHIP" THEN MemType& = MemfClear + MemfPublic + MemfChip
IF Type$ = "PUBFAST" THEN MemType& = MemfPublic + MemfFast
IF Type$ = "PUBCHIP" THEN MemType& = MemfPublic + MemfFast
IF Type$ = "CLRFAST" THEN MemType& = MemfClear + MemfFast
IF Type$ = "CLRCHIP" THEN MemType& = MemfClear + MemfChip
StrctName& = AllocMem(StrctSize&,MemType&)
NextStrctAdrs& = StrctName&
END SUB
SUB BYTE(ByteVal&) STATIC
SHARED NextStrctAdrs&
POKE NextStrctAdrs&,ByteVal&
NextStrctAdrs& = NextStrctAdrs& + 1&
END SUB
SUB WORD(WordVal&) STATIC
SHARED NextStrctAdrs&
POKEW NextStrctAdrs&,WordVal&
NextStrctAdrs& = NextStrctAdrs& + 2&
END SUB
SUB LONG(LongVal&) STATIC
SHARED NextStrctAdrs&
POKEL NextStrctAdrs&, LongVal&
NextStrctAdrs& = NextStrctAdrs& + 4&
END SUB
SUB SPTR(Text$) STATIC
SHARED NextStrctAdrs&
Text$ = Text$ + CHR$(0)
Text = SADD(Text$)
LONG Text
END SUB
SUB SUBSTRUCT(StrctSize&) STATIC
SHARED NextStrctAdrs&
FOR i=0 TO StructSize&-1
POKE NextStrctAdrs& + i, 0
NEXT i
NextStrctAdrs& = NextStrctAdrs& + StrctSize&
END SUB
SUB APTR(AdrsVal&) STATIC
LONG AdrsVal&
END SUB
' $IGNORE ON
9003 GOTO StructSubsReturn
' $IGNORE OFF