; Constants
EXECBASE=4

; Intuition flags
CUSTOMSCREEN=$f
CUSTOMBITMAP=$40

; Exec function offsets
OPENLIBRARY=-552
CLOSELIBRARY=-414

; Intuition function offsets
OPENSCREEN=-198
CLOSESCREEN=-66

; Graphics function offsets
LOADRGB4=-192

; Hardware registers
CIAPRA=$bfe001

 SECTION code,CODE

; Open and initialize
 move.l (EXECBASE).w,a6
 move.l #IntuitionName,a1
 moveq #33,d0
 jsr OPENLIBRARY(a6)
 move.l d0,IntuitionBase
 beq Exit

 move.l (EXECBASE).w,a6
 move.l #GraphicsName,a1
 moveq #33,d0
 jsr OPENLIBRARY(a6)
 move.l d0,GfxBase
 beq.s CloseIntuition

; Open the screen
 move.l IntuitionBase,a6
 move.l #NewScreen,a0
 jsr OPENSCREEN(a6)
 move.l d0,ScreenPtr
 beq.s CloseIntuition
 add.l #44,d0 ;ScreenPtr + 44 = ViewPortPtr

; Load the palette
 move.l d0,a0
 move.l #sample.data+16000,a1
 moveq #4,d0
 move.l GfxBase,a6
 jsr LOADRGB4(a6)

; Wait for mouse button
MouseButUp
 btst.b #6,(CIAPRA).l
 bne.s MouseButUp

; Close and exit
CloseHexes

 move.l IntuitionBase,a6
 move.l ScreenPtr,a0
 jsr CLOSESCREEN(a6)

CloseGraphics
 move.l (EXECBASE).w,a6
 move.l GfxBase,a1
 jsr CLOSELIBRARY(a6)

CloseIntuition
 move.l (EXECBASE).w,a6
 move.l IntuitionBase,a1
 jsr CLOSELIBRARY(a6)

Exit
 moveq #0,d0
 rts

; PC relative data
IntuitionBase ds.l 1
GfxBase ds.l 1
ScreenPtr ds.l 1

; Initialized data
 SECTION data,DATA

NewScreen
 dc.w 0,0
 dc.w 320,200
 dc.w 2
 dc.b 1,0
 dc.w 0
 dc.w CUSTOMSCREEN+CUSTOMBITMAP
 dc.l 0
 dc.l 0
 dc.l 0
 dc.l sample.dataBMap

sample.dataBMap:
 dc.w 40 ;BytesPerRow
 dc.w 200 ;Rows
 dc.b 0 ;Flags
 dc.b 2 ;Depth
 dc.w 0 ;Pad
 dc.l sample.data+0
 dc.l sample.data+8000
 ds.l 6 ;Unused planes

;Palette offset=16000

IntuitionName dc.b 'intuition.library',0
GraphicsName dc.b 'graphics.library',0

; Initialized chip data
 SECTION data_c,DATA_C

sample.data INCBIN sample.data
