
** Listing I from the PICTURE THIS machine code article.
** Written by Jolyon Ralph, © 1989 Amiga Computing.

** This will set up a 1 bitplane 320*200 pixel screen.
** NEEDS TO BE IN CHIP MEMORY.

 SECTION Scrn,CODE_C            ; Needed for DevPac 2.

OpenLib         equ -552        ; Offset for OpenLibrary.
CloseLib        equ -414        ; Offset for CloseLibrary.

diwstart        equ $8e         ; Screen hardware registers.
diwstop         equ $90
ddfstart        equ $92
ddfstop         equ $94
bplcon0         equ $100
bplcon1         equ $102
col0            equ $180
col1            equ $182
bpl1pth         equ $e0
bpl1ptl         equ $e2

** Because the copper list needs to move the address of our
** screen memory in two 16 bit words rather than one 32 bit
** long word, we must split the long word into two words
** and put them in the copper list.

 move.l #screen,d0      ; Get address of our screen memory.
 move.w d0,pl1l         ; Move the low word into the copper list.
 swap d0                ; Swap the low and high words in d0.
 move.w d0,pl1h         ; Move the high word into the copper list.

 move.l 4.w,a6          ; Get EXECBASE.
 lea gfxname(PC),a1     ; Point to 'graphics.library' string.
 moveq #0,d0            ; Ignore version number.
 jsr OpenLib(a6)        ; Open the library.
 move.l d0,a1           ; Store library address.
 move.l 38(a1),old      ; Store workbench copper address.
 move.l 4.w,a6          ; Get EXECBASE again.
 jsr CloseLib(a6)       ; Close the library.

 move.l #new,$dff080    ; Set new copper.

loop:
 btst #6,$bfe001        ; Check for left mouse button.
 bne.s loop             ; Loop until pressed.

 move.l old,$dff080     ; Restore old copper list.
 rts

new:                    ; Start of our copper list.

 dc.w diwstart,$2c81    ; Top left corner of screen.
 dc.w diwstop,$f4c1     ; Bottom right corner of screen.
 dc.w ddfstart,$38      ; Data fetch start.
 dc.w ddfstop,$d0       ; Data fetch stop.

 dc.w bplcon0,$1200     ; Set BPLCON0 to 1 bitplane lo-res.
 dc.w bplcon1,$0        ; No horizontal offset.

 dc.w col0,$0           ; Black background colour.
 dc.w col1,$fff         ; White foreground colour.

 dc.w bpl1pth           ; Bitplane high word.
pl1h
 dc.w 0

 dc.w bpl1ptl           ; Bitplane low word.
pl1l
 dc.w 0

 dc.w $ffff,$fffe       ; End copper list.

old dc.l 0

screen:  dcb.b 8000,$55 ; This is a block of 8000 bytes of
                        ; a set pattern (change dcb to blk for
                        ; the K-SEKA assembler).

gfxname dc.b "graphics.library",0

** If you have a raw picture file of 320 x 200 size in 1 bitplane
** you can replace the DCB.B 8000,$55 with an INCBIN "filename"
** command (Devpac 2 only) which will load in your graphics data
** when assembling.

** End of listing.

