View Single Post
Old 22 November 2017, 19:09   #104
OmegaMax
Knight Of The Kingdom

OmegaMax's Avatar
 
Join Date: Feb 2016
Location: Mordroc's Castle
Posts: 135
Building off BitPlane and sprite examples
Code:
;===========================================================================
; Display 2 BitPlanes Tile and Eight Sprites with Simple Vertical Movement 
;===========================================================================

  section Tutorial,code_c
  
  move.l 4,a6                       ;Get base of exec lib
  lea gfxlib(pc),a1                 ;Address of gfxlib string to a1
  jsr OpenLib(a6)                   ;Call OpenLibrary()
  move.l d0,gfxbase                 ;Save base of graphics library
 ;-------------------------------------------------------------------------
SetupBitPlanePointers:             
  move.l #BitPlane1,d0 
  move.w d0,BitPlane0PtrL
  swap d0                   
  move.w d0,BitPlane0PtrH  
  move.l #BitPlane2,d0 
  move.w d0,BitPlane1PtrL
  swap d0                   
  move.w d0,BitPlane1PtrH 
;-------------------------------------------------------------------------  
SetupSpritePointers:  
  move.l #BoxSprite0,d0
  move.w d0,Sprite0L
  swap d0
  move.w d0,Sprite0H
  move.l #BoxSprite1,d0
  move.w d0,Sprite1L
  swap d0
  move.w d0,Sprite1H
  move.l #BoxSprite2,d0
  move.w d0,Sprite2L
  swap d0
  move.w d0,Sprite2H
  move.l #BoxSprite3,d0
  move.w d0,Sprite3L
  swap d0
  move.w d0,Sprite3H 
  move.l #BoxSprite4,d0
  move.w d0,Sprite4L
  swap d0
  move.w d0,Sprite4H
  move.l #BoxSprite5,d0
  move.w d0,Sprite5L
  swap d0
  move.w d0,Sprite5H
  move.l #BoxSprite6,d0
  move.w d0,Sprite6L
  swap d0
  move.w d0,Sprite6H
  move.l #BoxSprite7,d0
  move.w d0,Sprite7L
  swap d0
  move.w d0,Sprite7H
;------------------------------------------------------------------------- 
Draw2BitPlaneTilesToScreen:
  move.l #BitPlane1,a0
  move.l #BitPlane2,a1
  move.l #Tile1BitPlane1,a2
  move.l #Tile1BitPlane2,a3
  move.l #15,d0                      ;Tile Data Lenght
  move.l #19,d1                      ;Tiles Drawn Count   
  move.l #12,d2                      ;Rows Counter
DrawLoop:
  move.w (a2)+,(a0)
  move.w (a3)+,(a1)
  add.l #40,a0                       ;Screenwidth/8   '320/8' 
  add.l #40,a1   
  dbra d0,DrawLoop  
  sub.l #638,a0
  sub.l #638,a1                      ;
  move.l #Tile1BitPlane1,a2          ;Reset TileBitPlane1 Address Pointer
  move.l #Tile1BitPlane2,a3          ;Reset TileBitPlane2 Address Pointer
  move.l #15,d0                      ;Tile Lenght "reset tile length counter"
  dbra d1,DrawLoop 
  add.l #600,a0
  add.l #600,a1
  move.l #19,d1                      ;Tiles Drawn Count 
  dbra d2,DrawLoop 
  lea SpriteMovementDir,a2
 ;-------------------------------------------------------------------------
 ;Setup Sprite Movement Directions
 ;------------------------------------------------------------------------- 
  move.b #1,0(a2)
  move.b #2,1(a2)
  move.b #1,2(a2) 
  move.b #2,3(a2)  
  move.b #1,4(a2)  
  move.b #2,5(a2)  
  move.b #1,6(a2) 
  move.b #2,7(a2)       
  move.l #CopperList,$dff080 
mouse: 
  jsr WaitVertical
  jsr SpriteLogic
TestMouse:  
  btst #6,$bfe001                    ;Left mouse clicked?
  bne mouse                          ;No,continue loop until mouse pressed
  move.l gfxbase(pc),a1              ;Base of graphics.library to a1
  move.l 38(a1),$dff080              ;Restore old copperlist
  jsr -414(a6)                       ;Call CloseLibrary()
  moveq #0,d0   
  rts  
;-------------------------------------------------------------------------
WaitVertical:  
VWaitloop1:  
  cmp.b #255,$dff006
  bne VWaitloop1
VWaitloop2:  
  cmp.b  #255,$dff006 
  beq VWaitloop2
  rts
;-------------------------------------------------------------------------
SpriteLogic:
  lea SpritePointerTable,a0
  lea SpriteMovementDir,a2
  move.l #7,d2                         ;Number of active sprites
SpriteLogicLoop:
  move.l (a0)+,a1 
  bsr TestSpriteDirection
  add.l #1,a2                          ;Add 1 for next sprite direction 
  dbra d2,SpriteLogicLoop             
  rts
;-------------------------------------------------------------------------
TestSpriteDirection:
  cmp.b #1,(a2)
  beq MoveDown
  cmp.b #2,(a2)
  beq MoveUp
  rts
MoveUp:
  cmp.b #44,0(a1)                       
  bne MoveUpContinue
  move.b #1,(a2)
  rts  
MoveUpContinue: 
  sub.b #1,0(a1)                         ;Subtract 1 Sprite Y Position Start
  sub.b #1,2(a1)                         ;Subtract 1 Sprite Y Position End
  rts
MoveDown:
  cmp.b #252,2(a1)
  bne MoveDownContinue
  move.b #2,(a2)                        
  rts
MoveDownContinue:   
  add.b #1,0(a1)                         ;Add 1 Sprite Y Position Start    
  add.b #1,2(a1)                         ;Add 1 Sprite Y Position End
  rts
;-------------------------------------------------------------------------
SpritePointerTable:
 dc.l BoxSprite0
 dc.l BoxSprite1
 dc.l BoxSprite2
 dc.l BoxSprite3 
 dc.l BoxSprite4
 dc.l BoxSprite5
 dc.l BoxSprite6
 dc.l BoxSprite7
;=========================================================================== 
CopperList:    
  dc.w $008e,$2c81,$0090,$3fc1    ; Setting up display,
  dc.w $0092,$0038,$0094,$00d0    ; modulo and so on 
  dc.w $0102,$0000,$0104,$0020    ;Sprite Priority"On" infront of Playfield
  dc.w $0106,$0000,$0108,$0000   
  dc.w $010a,$0000
;------------------------------------------------------------------------- 
;SpritePointers 
;-------------------------------------------------------------------------
  dc.w SpritePointer0H           ;$0120
Sprite0H:
  dc.w $0
  dc.w SpritePointer0L           ;$0122
Sprite0L:
  dc.w $0
;-------------------------------------------------------------------------  
  dc.w SpritePointer1H           ;$0124
Sprite1H:
  dc.w $0
  dc.w SpritePointer1L           ;$0126
Sprite1L:
  dc.w $0
;-------------------------------------------------------------------------
  dc.w SpritePointer2H           ;$0128
Sprite2H:
  dc.w $0
  dc.w SpritePointer2L           ;$012a
Sprite2L:
  dc.w $0
;-------------------------------------------------------------------------
  dc.w SpritePointer3H           ;$012c
Sprite3H:
  dc.w $0
  dc.w SpritePointer3L           ;$012e
Sprite3L:
  dc.w $0
;-------------------------------------------------------------------------
  dc.w SpritePointer4H           ;$0130
Sprite4H:
  dc.w $0
  dc.w SpritePointer4L           ;$0132
Sprite4L:
  dc.w $0
;-------------------------------------------------------------------------
  dc.w SpritePointer5H           ;$0134
Sprite5H:
  dc.w $0
  dc.w SpritePointer5L           ;$0136
Sprite5L:
  dc.w $0
;-------------------------------------------------------------------------
  dc.w SpritePointer6H           ;$0138
Sprite6H:
  dc.w $0
  dc.w SpritePointer6L           ;$013a
Sprite6L:
  dc.w $0
;-------------------------------------------------------------------------
  dc.w SpritePointer7H           ;$013c
Sprite7H:
  dc.w $0
  dc.w SpritePointer7L           ;$013e
Sprite7L:
  dc.w $0
;------------------------------------------------------------------------- 
; Setting up the colors
;-------------------------------------------------------------------------   
  dc.w BitPlaneColor0,$0000,BitPlaneColor1,$0a00
  dc.w BitPlaneColor2,$0700,BitPlaneColor3,$0f48
  dc.w Sprite0_1Color1,$00a0                     ;Sprites 0 & 1 color 1
  dc.w Sprite0_1Color2,$0080                     ;Sprites 0 & 1 color 2 
  dc.w Sprite0_1Color3,$0050                     ;Sprites 0 & 1 color 3
  dc.w Sprite2_3Color1,$0a0a                     ;Sprites 2 & 3 color 1
  dc.w Sprite2_3Color2,$0808                     ;Sprites 2 & 3 color 2 
  dc.w Sprite2_3Color3,$0505                     ;Sprites 2 & 3 color 3
  dc.w Sprite4_5Color1,$000f                     ;Sprites 4 & 5 color 1
  dc.w Sprite4_5Color2,$000a                     ;Sprites 4 & 5 color 2 
  dc.w Sprite4_5Color3,$0008                     ;Sprites 4 & 5 color 3
  dc.w Sprite6_7Color1,$0aa0                     ;Sprites 6 & 7 color 1
  dc.w Sprite6_7Color2,$0880                     ;Sprites 6 & 7 color 2 
  dc.w Sprite6_7Color3,$0550                     ;Sprites 6 & 7 color 3
;-------------------------------------------------------------------------     
  dc.w $0100,$2200                           ;2 Bitplanes,Color Burst
;-------------------------------------------------------------------------  
BitPlanePointers: 
;------------------------------------------------------------------------- 
  dc.w BitPlane0PointerH
BitPlane0PtrH:  
  dc.w $0000
  dc.w BitPlane0PointerL
BitPlane0PtrL:  
  dc.w $0000  
  dc.w BitPlane1PointerH
BitPlane1PtrH:  
  dc.w $0000
  dc.w BitPlane1PointerL
BitPlane1PtrL:  
  dc.w $0000                          
  dc.w $ffff,$fffe
;-----------------------------------------------
Tile1BitPlane1:
;BitPlane1  
  dc.w %0000000011111111
  dc.w %0000000011111111
  dc.w %0000000011111111
  dc.w %0000000011111111
  dc.w %0000000011111111 
  dc.w %0000000011111111 
  dc.w %0000000011111111
  dc.w %0000000011111111
  dc.w %1111111111111111
  dc.w %1111111111111111
  dc.w %1111111111111111
  dc.w %1111111111111111
  dc.w %1111111111111111 
  dc.w %1111111111111111 
  dc.w %1111111111111111
  dc.w %1111111111111111
Tile1BitPlane2:
;BitPlane2 
  dc.w %1111111100000000
  dc.w %1111111100000000
  dc.w %1111111100000000
  dc.w %1111111100000000
  dc.w %1111111100000000 
  dc.w %1111111100000000 
  dc.w %1111111100000000
  dc.w %1111111100000000
  dc.w %0000000011111111
  dc.w %0000000011111111
  dc.w %0000000011111111
  dc.w %0000000011111111
  dc.w %0000000011111111 
  dc.w %0000000011111111 
  dc.w %0000000011111111
  dc.w %0000000011111111
;-----------------------------------------------
BoxSprite0:
  dc.b 160                                   ;Sprite Y Position Start
  dc.b 100                                   ;Sprite X Position Start 
  dc.b 177                                   ;Sprite Y Position End
  dc.b 0
  dc.w %1111111111111111,%0000000000000000
  dc.w %1111111111111111,%0000000000000000 
  dc.w %1100000000000011,%0011111111111100
  dc.w %1100000000000011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100000000000011,%0011111111111100
  dc.w %1100000000000011,%0011111111111100
  dc.w %1111111111111111,%0000000000000000
  dc.w %1111111111111111,%0000000000000000
  dc.w 0,0                                 ;End of the sprite.
;-----------------------------------------------
BoxSprite1:
  dc.b 160                                   ;Sprite Y Position Start
  dc.b 110                                   ;Sprite X Position Start 
  dc.b 177                                   ;Sprite Y Position End
  dc.b 0
  dc.w %1111111111111111,%0000000000000000
  dc.w %1111111111111111,%0000000000000000 
  dc.w %1100000000000011,%0011111111111100
  dc.w %1100000000000011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100000000000011,%0011111111111100
  dc.w %1100000000000011,%0011111111111100
  dc.w %1111111111111111,%0000000000000000
  dc.w %1111111111111111,%0000000000000000
  dc.w 0,0                                 ;End of the sprite.

;-----------------------------------------------
BoxSprite2:
  dc.b 120                                   ;Sprite Y Position Start
  dc.b 120                                   ;Sprite X Position Start 
  dc.b 137                                   ;Sprite Y Position End
  dc.b 0
  dc.w %1111111111111111,%0000000000000000
  dc.w %1111111111111111,%0000000000000000 
  dc.w %1100000000000011,%0011111111111100
  dc.w %1100000000000011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100000000000011,%0011111111111100
  dc.w %1100000000000011,%0011111111111100
  dc.w %1111111111111111,%0000000000000000
  dc.w %1111111111111111,%0000000000000000
  dc.w 0,0                                 ;End of the sprite.
;-----------------------------------------------
BoxSprite3:
  dc.b 150                                   ;Sprite Y Position Start
  dc.b 130                                   ;Sprite X Position Start 
  dc.b 167                                   ;Sprite Y Position End
  dc.b 0
  dc.w %1111111111111111,%0000000000000000
  dc.w %1111111111111111,%0000000000000000 
  dc.w %1100000000000011,%0011111111111100
  dc.w %1100000000000011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100000000000011,%0011111111111100
  dc.w %1100000000000011,%0011111111111100
  dc.w %1111111111111111,%0000000000000000
  dc.w %1111111111111111,%0000000000000000
  dc.w 0,0                                 ;End of the sprite.
;-----------------------------------------------
BoxSprite4:
  dc.b 160                                   ;Sprite Y Position Start
  dc.b 140                                   ;Sprite X Position Start 
  dc.b 177                                   ;Sprite Y Position End
  dc.b 0
  dc.w %1111111111111111,%0000000000000000
  dc.w %1111111111111111,%0000000000000000 
  dc.w %1100000000000011,%0011111111111100
  dc.w %1100000000000011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100000000000011,%0011111111111100
  dc.w %1100000000000011,%0011111111111100
  dc.w %1111111111111111,%0000000000000000
  dc.w %1111111111111111,%0000000000000000
  dc.w 0,0                                 ;End of the sprite.  
;-----------------------------------------------
BoxSprite5:
  dc.b 160                                   ;Sprite Y Position Start
  dc.b 150                                   ;Sprite X Position Start 
  dc.b 177                                   ;Sprite Y Position End
  dc.b 0
  dc.w %1111111111111111,%0000000000000000
  dc.w %1111111111111111,%0000000000000000 
  dc.w %1100000000000011,%0011111111111100
  dc.w %1100000000000011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100000000000011,%0011111111111100
  dc.w %1100000000000011,%0011111111111100
  dc.w %1111111111111111,%0000000000000000
  dc.w %1111111111111111,%0000000000000000
  dc.w 0,0                                 ;End of the sprite.
;-----------------------------------------------
BoxSprite6:
  dc.b 180                                   ;Sprite Y Position Start
  dc.b 160                                   ;Sprite X Position Start 
  dc.b 197                                   ;Sprite Y Position End
  dc.b 0
  dc.w %1111111111111111,%0000000000000000
  dc.w %1111111111111111,%0000000000000000 
  dc.w %1100000000000011,%0011111111111100
  dc.w %1100000000000011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100000000000011,%0011111111111100
  dc.w %1100000000000011,%0011111111111100
  dc.w %1111111111111111,%0000000000000000
  dc.w %1111111111111111,%0000000000000000
  dc.w 0,0                                 ;End of the sprite.
;-----------------------------------------------
BoxSprite7:
  dc.b 160                                   ;Sprite Y Position Start
  dc.b 170                                   ;Sprite X Position Start 
  dc.b 177                                   ;Sprite Y Position End
  dc.b 0
  dc.w %1111111111111111,%0000000000000000
  dc.w %1111111111111111,%0000000000000000 
  dc.w %1100000000000011,%0011111111111100
  dc.w %1100000000000011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100111111110011,%0011111111111100
  dc.w %1100000000000011,%0011111111111100
  dc.w %1100000000000011,%0011111111111100
  dc.w %1111111111111111,%0000000000000000
  dc.w %1111111111111111,%0000000000000000
  dc.w 0,0                                 ;End of the sprite.

;-----------------------------------------------  
;Equates
;----------------------------------------------- 
BitPlaneColor0 equ $0180
BitPlaneColor1 equ $0182
BitPlaneColor2 equ $0184
BitPlaneColor3 equ $0186
SpritePointer0H equ $0120
SpritePointer0L equ $0122
SpritePointer1H equ $0124
SpritePointer1L equ $0126
SpritePointer2H equ $0128
SpritePointer2L equ $012a
SpritePointer3H equ $012c
SpritePointer3L equ $012e
SpritePointer4H equ $0130
SpritePointer4L equ $0132
SpritePointer5H equ $0134
SpritePointer5L equ $0136
SpritePointer6H equ $0138
SpritePointer6L equ $013a
SpritePointer7H equ $013c
SpritePointer7L equ $013e
Sprite0_1Color1 equ $01a2
Sprite0_1Color2 equ $01a4
Sprite0_1Color3 equ $01a6
Sprite2_3Color1 equ $01aa
Sprite2_3Color2 equ $01ac
Sprite2_3Color3 equ $01ae
Sprite4_5Color1 equ $01b2
Sprite4_5Color2 equ $01b4
Sprite4_5Color3 equ $01b6
Sprite6_7Color1 equ $01ba
Sprite6_7Color2 equ $01bc
Sprite6_7Color3 equ $01be
BitPlane0PointerH equ $00e0
BitPlane0PointerL equ $00e2
BitPlane1PointerH equ $00e4
BitPlane1PointerL equ $00e6
NullSprite EQU $0000
;---------------------------------------------------------------
OpenLib equ -408
gfxlib:   dc.b  "graphics.library",0,0
gfxbase:  dc.l  0  
;---------------------------------------------------------------
  section blah,bss_c
;---------------------------------------------------------------
BitPlane1: ds.b 320*256/8*1
BitPlane2: ds.b 320*256/8*1
Offset ds.w 8
SpriteMovementDir ds.b 8

Last edited by OmegaMax; 24 November 2017 at 02:26.
OmegaMax is offline  
 
Page generated in 0.05687 seconds with 11 queries