Amiga Machine Code Letter IV - More Code

Amiga Machine Code - Letter IV

We have reached Letter IV of the Amiga Machine Code course.

This post is about the code examples found in Letter IV. I won’t go into details, as you can look them up in the letter.

We start with program example 0402, which sets up a program using one bitplane and also allocates space for it.

; Letter IV mc0402
start:
move.w #$01a0,$dff096 ; DMACON disable bitplane, copper, sprite

move.w #$1200,$dff100 ; BPLCON0 enable 1 bitplane, color burst
move.w #$0000,$dff102 ; BPLCON1 (scroll)
move.w #$0000,$dff104 ; BPLCON2 (video)
move.w #0,$dff108     ; BPL1MOD
move.w #0,$dff10a     ; BPL2MOD
move.w #$2c81,$dff08e ; DIWSTRT top right corner ($81,$2c)
move.w #$f4c1,$dff090 ; DIWSTOP enable PAL trick
move.w #$38c1,$dff090 ; DIWSTOP buttom left corner ($1c1,$12c)
move.w #$0038,$dff092 ; DDFSTRT
move.w #$00d0,$dff094 ; DDFSTOP

lea.l screen,a1 ; address of screen into a1
lea.l bplcop,a2 ; address of bplcop into a2
move.l a1,d1
move.w d1,6(a2) ; first halve d1 into addr a2 points to + 6 words
swap d1         ; swap data register halves
move.w d1,2(a2) ; first halve d1 into addr a2 points to + 2 words

lea.l copper,a1   ; address of copper into a1
move.l a1,$dff080 ; COP1LCH, move long, no need for COP1LCL

move.w #$8180,$dff096 ; DMACON enable bitplane, copper

wait:
btst #6,$bfe001 ; test left mouse button
bne wait        ; if not pressed go to wait

move.w  #$0080,$dff096	; restablish DMA's and copper
move.l  $4,a6
move.l  156(a6),a1
move.l  38(a1),$dff080
move.w  #$80a0,$dff096
rts

copper:
dc.w $2c01,$fffe ; wait($01,$2c)
dc.w $0100,$1200 ; move to BPLCON0 enable 1 bitplane, color burst

bplcop:
dc.w $00e0,$0000 ; move to BPL1PTH
dc.w $00e2,$0000 ; move to BPL1PTL

dc.w $0180,$0000 ; move to COLOR00 black
dc.w $0182,$0ff0 ; move to COLOR01 yellow

dc.w $ffdf,$fffe ; wait($df,$ff) enable wait > $ff horiz
dc.w $2c01,$fffe ; wait($01,$12c)
dc.w $0100,$0200 ; move to BPLCON0 disable bitplane
                 ; needed to support older PAL chips.
dc.w $ffff,$fffe ; end of copper

screen:
blk.b 10240,0 ; allocate block of bytes and set to 0

Notice the place were we swap register d1. It’s actually an example of self-modifying code. It will set the bitplane 1 pointer BPL1PTH and BPL1PTL in the copper list to the address of the screen. Kind of neat 😃

The program just draws a black screen, since we do not do anything in the screen area. Letter IV encourage you to experiment by adding points and lines to the screen. E.g. this code will add a pixel.

screen:
dc.b $80
blk.b 10240,0

Letter IV mentions a Disk 1 that contains a file called “SCREEN”. This file contains an image that should be loaded into the screen buffer. In Seka you do that like this.

SEKA>ri
FILENAME>brev4/screen
BEGIN>screen
END>

The begin part is an address in memory - just use the screen label. Let’s try it! 😃

Arcus

Let’s try with five bitplanes

We are now ready for images with more colors and their own color table.

; Letter IV mc0403
start:
move.w #$01a0,$dff096 ; DMACON disable bitplane, copper, sprite

move.w #$5200,$dff100 ; BPLCON0 enable 5 bitplanes, color burst
move.w #0,$dff102     ; BPLCON1 (scroll)
move.w #0,$dff104     ; BPLCON2 (video)
move.w #0,$dff108     ; BPL1MOD
move.w #0,$dff10a     ; BPL2MOD

move.w #$1c71,$dff08e ; DIWSTRT top right corner ($71,$1c)
move.w #$f4d1,$dff090 ; DIWSTOP enable PAL trick
move.w #$48d1,$dff090 ; DIWSTOP buttom left corner ($1d1,$13C)
                      ; overscan 352x288
move.w #$0030,$dff092 ; DDFSTRT overscan
move.w #$00d8,$dff094 ; DDFSTOP overscan

lea.l screen,a1    ; address of screen into a1
move.l #$dff180,a2 ; address of COLOR00 into a2
moveq #31,d0       ; color table counter
colorloop:
move.w (a1)+,(a2)+ ; update color table
dbra d0,colorloop  ; loop over all 32 colors registers

move.l a1,d1    ; a1 now points to image data. move to d1
lea.l bplcop,a2 ; address of bplcop into a2
addq.l #2,a2    ; increment address in a2 by 2.
moveq #4,d0     ; update bitplane counter

bplloop:        ; setup bitplane pointers
swap d1         ; swap data register halves
move.w d1,(a2)  ; first halve d1 into addr a2 points to
addq.l #4,a2    ; increment address in a2 by 4.
swap d1         ; swap data register halves
move.w d1,(a2)  ; first halve d1 into addr a2 points to
addq.l #4,a2    ; increment address in a2 by 4.
add.l #12320,d1 ; increment d1 to point to next bitplane
dbra d0,bplloop ; loop over all 5 bitplanes

lea.l copper,a1   ; address of copper into a1
move.l a1,$dff080 ; COP1LCH, move long, no need for COP1LCL

move.w #$8180,$dff096 ; DMACON enable bitplane, copper

wait:
btst #6,$bfe001 ; test left mouse button
bne wait        ; if not pressed go to wait

move.w  #$0080,$dff096	; restablish DMA's and copper
move.l  $4,a6
move.l  156(a6),a1
move.l  38(a1),$dff080
move.w  #$80a0,$dff096
rts

copper:
dc.w $2c01,$fffe ; wait($01,$1c)
dc.w $0100,$1200 ; move to BPLCON0 enable 1 bitplane, color burst

bplcop:
dc.w $00e0,$0000 ; move to BPL1PTH
dc.w $00e2,$0000 ; move to BPL1PTL
dc.w $00e4,$0000 ; move to BPL2PTH
dc.w $00e6,$0000 ; move to BPL2PTL
dc.w $00e8,$0000 ; move to BPL3PTH
dc.w $00ea,$0000 ; move to BPL3PTL
dc.w $00ec,$0000 ; move to BPL4PTH
dc.w $00ee,$0000 ; move to BPL4PTL
dc.w $00f0,$0000 ; move to BPL5PTH
dc.w $00f2,$0000 ; move to BPL5PTL

dc.w $ffdf,$fffe ; wait($df,$ff) enable wait > $ff horiz
dc.w $3401,$fffe ; wait($01,$134)
dc.w $0100,$0200 ; move to BPLCON0 disable bitplane
                 ; needed to support older PAL chips.
dc.w $ffff,$fffe ; end of copper

screen:
blk.l $3c38,0 ; allocate block of bytes and set to 0

This program sets up five bitplanes and allocates space for them and for 32 color registers.

There are two loops in the program. The first loop will transfer the color palette to the color registers. The other loop will setup the bitplane pointers to point to the image data.

When you start the program, the screen will just be black. To make things more interesting, load screen2 from Disk 1 inside Seka.

SEKA>ri
FILENAME>brev4/screen2
BEGIN>screen
END>

Then run the program. Voila, a PAL test pattern emerges! 😃

Arcus PAL test pattern


Amiga Machine Code Course

Previous post: Amiga Machine Code Letter IV - DMA Revisited

Next post: Amiga Machine Code Letter V.

Mark Wrobel
Mark Wrobel
Team Lead, developer and mortgage expert