;=================================================================
; [SPRITES.INC] -- A sprite initialization routine and a sprite
;                  priority set routine.
;=================================================================


; Sprite buffer ($0400-$061F)
.DEFINE SPRBUF1 $0400 ; +512
.DEFINE SPRBUF2 $0600 ; +32

.DEFINE SX        $00
.DEFINE SY        $01
.DEFINE SFRAME    $02
.DEFINE SPRIORITY $03
.DEFINE SX1        $04
.DEFINE SY1        $05
.DEFINE SFRAME1    $06
.DEFINE SPRIORITY1 $07
.DEFINE SX2        $08
.DEFINE SY2        $09
.DEFINE SFRAME2    $0A
.DEFINE SPRIORITY2 $0B
.DEFINE SX3        $0C
.DEFINE SY3        $0D
.DEFINE SFRAME3    $0E
.DEFINE SPRIORITY3 $0F
.DEFINE SX4        $10
.DEFINE SY4        $11
.DEFINE SFRAME4    $12
.DEFINE SPRIORITY4 $13
.DEFINE SX5        $14
.DEFINE SY5        $15
.DEFINE SFRAME5    $16
.DEFINE SPRIORITY5 $17
.DEFINE SX6        $18
.DEFINE SY6        $19
.DEFINE SFRAME6    $1A
.DEFINE SPRIORITY6 $1B
.DEFINE SX7        $1C
.DEFINE SY7        $1D
.DEFINE SFRAME7    $1E
.DEFINE SPRIORITY7 $1F
.DEFINE SX8        $20
.DEFINE SY8        $21
.DEFINE SFRAME8    $22
.DEFINE SPRIORITY8 $23
.DEFINE SX9        $24
.DEFINE SY9        $25
.DEFINE SFRAME9    $26
.DEFINE SPRIORITY9 $27
.DEFINE SX10        $28
.DEFINE SY10        $29
.DEFINE SFRAME10    $2A
.DEFINE SPRIORITY10 $2B
.DEFINE SX11        $2C
.DEFINE SY11        $2D
.DEFINE SFRAME11    $2E
.DEFINE SPRIORITY11 $2F
.DEFINE SX12        $30
.DEFINE SY12        $31
.DEFINE SFRAME12    $32
.DEFINE SPRIORITY12 $33
.DEFINE SX13        $34
.DEFINE SY13        $35
.DEFINE SFRAME13    $36
.DEFINE SPRIORITY13 $37
.DEFINE SX14        $38
.DEFINE SY14        $39
.DEFINE SFRAME14    $3A
.DEFINE SPRIORITY14 $3B
.DEFINE SX15        $3C
.DEFINE SY15        $3D
.DEFINE SFRAME15    $3E
.DEFINE SPRIORITY15 $3F
.DEFINE SX16        $40
.DEFINE SY16        $41
.DEFINE SFRAME16    $42
.DEFINE SPRIORITY16 $43
.DEFINE SX17        $44
.DEFINE SY17        $45
.DEFINE SFRAME17    $46
.DEFINE SPRIORITY17 $47
.DEFINE SX18        $48
.DEFINE SY18        $49
.DEFINE SFRAME18    $4A
.DEFINE SPRIORITY18 $4B
.DEFINE SX19        $4C
.DEFINE SY19        $4D
.DEFINE SFRAME19    $4E
.DEFINE SPRIORITY19 $4F
.DEFINE SX20        $50
.DEFINE SY20        $51
.DEFINE SFRAME20    $52
.DEFINE SPRIORITY20 $53
.DEFINE SX21        $54
.DEFINE SY21        $55
.DEFINE SFRAME21    $56
.DEFINE SPRIORITY21 $57
.DEFINE SX22        $58
.DEFINE SY22        $59
.DEFINE SFRAME22    $5A
.DEFINE SPRIORITY22 $5B
.DEFINE SX23        $5C
.DEFINE SY23        $5D
.DEFINE SFRAME23    $5E
.DEFINE SPRIORITY23 $5F
.DEFINE SX24        $60
.DEFINE SY24        $61
.DEFINE SFRAME24    $62
.DEFINE SPRIORITY24 $63
.DEFINE SX25        $64
.DEFINE SY25        $65
.DEFINE SFRAME25    $66
.DEFINE SPRIORITY25 $67
.DEFINE SX26        $68
.DEFINE SY26        $69
.DEFINE SFRAME26    $6A
.DEFINE SPRIORITY26 $6B
.DEFINE SX27        $6C
.DEFINE SY27        $6D
.DEFINE SFRAME27    $6E
.DEFINE SPRIORITY27 $6F
.DEFINE SX28        $70
.DEFINE SY28        $71
.DEFINE SFRAME28    $72
.DEFINE SPRIORITY28 $73
.DEFINE SX29        $74
.DEFINE SY29        $75
.DEFINE SFRAME29    $76
.DEFINE SPRIORITY29 $77
.DEFINE SX30        $78
.DEFINE SY30        $79
.DEFINE SFRAME30    $7A
.DEFINE SPRIORITY30 $7B
.DEFINE SX31        $7C
.DEFINE SY31        $7D
.DEFINE SFRAME31    $7E
.DEFINE SPRIORITY31 $7F
.DEFINE SX32        $80
.DEFINE SY32        $81
.DEFINE SFRAME32    $82
.DEFINE SPRIORITY32 $83
.DEFINE SX33        $84
.DEFINE SY33        $85
.DEFINE SFRAME33    $86
.DEFINE SPRIORITY33 $87
.DEFINE SX34        $88
.DEFINE SY34        $89
.DEFINE SFRAME34    $8A
.DEFINE SPRIORITY34 $8B
.DEFINE SX35        $8C
.DEFINE SY35        $8D
.DEFINE SFRAME35    $8E
.DEFINE SPRIORITY35 $8F
.DEFINE SX36        $90
.DEFINE SY36        $91
.DEFINE SFRAME36    $92
.DEFINE SPRIORITY36 $93
.DEFINE SX37        $94
.DEFINE SY37        $95
.DEFINE SFRAME37    $96
.DEFINE SPRIORITY37 $97
.DEFINE SX38        $98
.DEFINE SY38        $99
.DEFINE SFRAME38    $9A
.DEFINE SPRIORITY38 $9B
.DEFINE SX39        $9C
.DEFINE SY39        $9D
.DEFINE SFRAME39    $9E
.DEFINE SPRIORITY39 $9F
.DEFINE SX40        $A0
.DEFINE SY40        $A1
.DEFINE SFRAME40    $A2
.DEFINE SPRIORITY40 $A3
.DEFINE SX41        $A4
.DEFINE SY41        $A5
.DEFINE SFRAME41    $A6
.DEFINE SPRIORITY41 $A7
.DEFINE SX42        $A8
.DEFINE SY42        $A9
.DEFINE SFRAME42    $AA
.DEFINE SPRIORITY42 $AB
.DEFINE SX43        $AC
.DEFINE SY43        $AD
.DEFINE SFRAME43    $AE
.DEFINE SPRIORITY43 $AF
.DEFINE SX44        $B0
.DEFINE SY44        $B1
.DEFINE SFRAME44    $B2
.DEFINE SPRIORITY44 $B3
.DEFINE SX45        $B4
.DEFINE SY45        $B5
.DEFINE SFRAME45    $B6
.DEFINE SPRIORITY45 $B7
.DEFINE SX46        $B8
.DEFINE SY46        $B9
.DEFINE SFRAME46    $BA
.DEFINE SPRIORITY46 $BB
.DEFINE SX47        $BC
.DEFINE SY47        $BD
.DEFINE SFRAME47    $BE
.DEFINE SPRIORITY47 $BF
.DEFINE SX48        $C0
.DEFINE SY48        $C1
.DEFINE SFRAME48    $C2
.DEFINE SPRIORITY48 $C3
.DEFINE SX49        $C4
.DEFINE SY49        $C5
.DEFINE SFRAME49    $C6
.DEFINE SPRIORITY49 $C7
.DEFINE SX50        $C8
.DEFINE SY50        $C9
.DEFINE SFRAME50    $CA
.DEFINE SPRIORITY50 $CB
.DEFINE SX51        $CC
.DEFINE SY51        $CD
.DEFINE SFRAME51    $CE
.DEFINE SPRIORITY51 $CF
.DEFINE SX52        $D0
.DEFINE SY52        $D1
.DEFINE SFRAME52    $D2
.DEFINE SPRIORITY52 $D3
.DEFINE SX53        $D4
.DEFINE SY53        $D5
.DEFINE SFRAME53    $D6
.DEFINE SPRIORITY53 $D7
.DEFINE SX54        $D8
.DEFINE SY54        $D9
.DEFINE SFRAME54    $DA
.DEFINE SPRIORITY54 $DB
.DEFINE SX55        $DC
.DEFINE SY55        $DD
.DEFINE SFRAME55    $DE
.DEFINE SPRIORITY55 $DF
.DEFINE SX56        $E0
.DEFINE SY56        $E1
.DEFINE SFRAME56    $E2
.DEFINE SPRIORITY56 $E3
.DEFINE SX57        $E4
.DEFINE SY57        $E5
.DEFINE SFRAME57    $E6
.DEFINE SPRIORITY57 $E7
.DEFINE SX58        $E8
.DEFINE SY58        $E9
.DEFINE SFRAME58    $EA
.DEFINE SPRIORITY58 $EB
.DEFINE SX59        $EC
.DEFINE SY59        $ED
.DEFINE SFRAME59    $EE
.DEFINE SPRIORITY59 $EF
.DEFINE SX60        $F0
.DEFINE SY60        $F1
.DEFINE SFRAME60    $F2
.DEFINE SPRIORITY60 $F3
.DEFINE SX61        $F4
.DEFINE SY61        $F5
.DEFINE SFRAME61    $F6
.DEFINE SPRIORITY61 $F7
.DEFINE SX62        $F8
.DEFINE SY62        $F9
.DEFINE SFRAME62    $FA
.DEFINE SPRIORITY62 $FB
.DEFINE SX63        $FC
.DEFINE SY63        $FD
.DEFINE SFRAME63    $FE
.DEFINE SPRIORITY63 $FF

.DEFINE SX64        $100
.DEFINE SY64        $101
.DEFINE SFRAME64    $102
.DEFINE SPRIORITY64 $103

.DEFINE SX65        $104
.DEFINE SY65        $105
.DEFINE SFRAME65    $106
.DEFINE SPRIORITY65 $107

.DEFINE SX66        $108
.DEFINE SY66        $109
.DEFINE SFRAME66    $10A
.DEFINE SPRIORITY66 $10B

.DEFINE SX67        $10C
.DEFINE SY67        $10D
.DEFINE SFRAME67    $10E
.DEFINE SPRIORITY67 $10F

.DEFINE SX68        $110
.DEFINE SY68        $111
.DEFINE SFRAME68    $112
.DEFINE SPRIORITY68 $113

.DEFINE SX69        $114
.DEFINE SY69        $115
.DEFINE SFRAME69    $116
.DEFINE SPRIORITY69 $117

.DEFINE SX70        $118
.DEFINE SY70        $119
.DEFINE SFRAME70    $11A
.DEFINE SPRIORITY70 $11B

.DEFINE SX71        $11C
.DEFINE SY71        $11D
.DEFINE SFRAME71    $11E
.DEFINE SPRIORITY71 $11F

.DEFINE SX72        $120
.DEFINE SY72        $121
.DEFINE SFRAME72    $122
.DEFINE SPRIORITY72 $123

.DEFINE SX73        $124
.DEFINE SY73        $125
.DEFINE SFRAME73    $126
.DEFINE SPRIORITY73 $127

.DEFINE SX74        $128
.DEFINE SY74        $129
.DEFINE SFRAME74    $12A
.DEFINE SPRIORITY74 $12B

.DEFINE SX75        $12C
.DEFINE SY75        $12D
.DEFINE SFRAME75    $12E
.DEFINE SPRIORITY75 $12F

.DEFINE SX76        $130
.DEFINE SY76        $131
.DEFINE SFRAME76    $132
.DEFINE SPRIORITY76 $133

.DEFINE SX77        $134
.DEFINE SY77        $135
.DEFINE SFRAME77    $136
.DEFINE SPRIORITY77 $137

.DEFINE SX78        $138
.DEFINE SY78        $139
.DEFINE SFRAME78    $13A
.DEFINE SPRIORITY78 $13B

.DEFINE SX79        $13C
.DEFINE SY79        $13D
.DEFINE SFRAME79    $13E
.DEFINE SPRIORITY79 $13F

.DEFINE SX80        $140
.DEFINE SY80        $141
.DEFINE SFRAME80    $142
.DEFINE SPRIORITY80 $143

.DEFINE SX81        $144
.DEFINE SY81        $145
.DEFINE SFRAME81    $146
.DEFINE SPRIORITY81 $147

.DEFINE SX82        $148
.DEFINE SY82        $149
.DEFINE SFRAME82    $14A
.DEFINE SPRIORITY82 $14B

.DEFINE SX83        $14C
.DEFINE SY83        $14D
.DEFINE SFRAME83    $14E
.DEFINE SPRIORITY83 $14F

.DEFINE SX84        $150
.DEFINE SY84        $151
.DEFINE SFRAME84    $152
.DEFINE SPRIORITY84 $153

.DEFINE SX85        $154
.DEFINE SY85        $155
.DEFINE SFRAME85    $156
.DEFINE SPRIORITY85 $157

.DEFINE SX86        $158
.DEFINE SY86        $159
.DEFINE SFRAME86    $15A
.DEFINE SPRIORITY86 $15B

.DEFINE SX87        $15C
.DEFINE SY87        $15D
.DEFINE SFRAME87    $15E
.DEFINE SPRIORITY87 $15F

.DEFINE SX88        $160
.DEFINE SY88        $161
.DEFINE SFRAME88    $162
.DEFINE SPRIORITY88 $163

.DEFINE SX89        $164
.DEFINE SY89        $165
.DEFINE SFRAME89    $166
.DEFINE SPRIORITY89 $167

.DEFINE SX90        $168
.DEFINE SY90        $169
.DEFINE SFRAME90    $16A
.DEFINE SPRIORITY90 $16B

.DEFINE SX91        $16C
.DEFINE SY91        $16D
.DEFINE SFRAME91    $16E
.DEFINE SPRIORITY91 $16F

.DEFINE SX92        $170
.DEFINE SY92        $171
.DEFINE SFRAME92    $172
.DEFINE SPRIORITY92 $173

.DEFINE SX93        $174
.DEFINE SY93        $175
.DEFINE SFRAME93    $176
.DEFINE SPRIORITY93 $177

.DEFINE SX94        $178
.DEFINE SY94        $179
.DEFINE SFRAME94    $17A
.DEFINE SPRIORITY94 $17B

.DEFINE SX95        $17C
.DEFINE SY95        $17D
.DEFINE SFRAME95    $17E
.DEFINE SPRIORITY95 $17F

.DEFINE SX96        $180
.DEFINE SY96        $181
.DEFINE SFRAME96    $182
.DEFINE SPRIORITY96 $183

.DEFINE SX97        $184
.DEFINE SY97        $185
.DEFINE SFRAME97    $186
.DEFINE SPRIORITY97 $187

.DEFINE SX98        $188
.DEFINE SY98        $189
.DEFINE SFRAME98    $18A
.DEFINE SPRIORITY98 $18B

.DEFINE SX99        $18C
.DEFINE SY99        $18D
.DEFINE SFRAME99    $18E
.DEFINE SPRIORITY99 $18F

.DEFINE SX100        $190
.DEFINE SY100        $191
.DEFINE SFRAME100    $192
.DEFINE SPRIORITY100 $193

.DEFINE SX101        $194
.DEFINE SY101        $195
.DEFINE SFRAME101    $196
.DEFINE SPRIORITY101 $197

.DEFINE SX102        $198
.DEFINE SY102        $199
.DEFINE SFRAME102    $19A
.DEFINE SPRIORITY102 $19B

.DEFINE SX103        $19C
.DEFINE SY103        $19D
.DEFINE SFRAME103    $19E
.DEFINE SPRIORITY103 $19F

.DEFINE SX104        $1A0
.DEFINE SY104        $1A1
.DEFINE SFRAME104    $1A2
.DEFINE SPRIORITY104 $1A3

.DEFINE SX105        $1A4
.DEFINE SY105        $1A5
.DEFINE SFRAME105    $1A6
.DEFINE SPRIORITY105 $1A7

.DEFINE SX106        $1A8
.DEFINE SY106        $1A9
.DEFINE SFRAME106    $1AA
.DEFINE SPRIORITY106 $1AB

.DEFINE SX107        $1AC
.DEFINE SY107        $1AD
.DEFINE SFRAME107    $1AE
.DEFINE SPRIORITY107 $1AF

.DEFINE SX108        $1B0
.DEFINE SY108        $1B1
.DEFINE SFRAME108    $1B2
.DEFINE SPRIORITY108 $1B3

.DEFINE SX109        $1B4
.DEFINE SY109        $1B5
.DEFINE SFRAME109    $1B6
.DEFINE SPRIORITY109 $1B7

.DEFINE SX110        $1B8
.DEFINE SY110        $1B9
.DEFINE SFRAME110    $1BA
.DEFINE SPRIORITY110 $1BB

.DEFINE SX111        $1BC
.DEFINE SY111        $1BD
.DEFINE SFRAME111    $1BE
.DEFINE SPRIORITY111 $1BF

.DEFINE SX112        $1C0
.DEFINE SY112        $1C1
.DEFINE SFRAME112    $1C2
.DEFINE SPRIORITY112 $1C3

.DEFINE SX113        $1C4
.DEFINE SY113        $1C5
.DEFINE SFRAME113    $1C6
.DEFINE SPRIORITY113 $1C7

.DEFINE SX114        $1C8
.DEFINE SY114        $1C9
.DEFINE SFRAME114    $1CA
.DEFINE SPRIORITY114 $1CB

.DEFINE SX115        $1CC
.DEFINE SY115        $1CD
.DEFINE SFRAME115    $1CE
.DEFINE SPRIORITY115 $1CF

.DEFINE SX116        $1D0
.DEFINE SY116        $1D1
.DEFINE SFRAME116    $1D2
.DEFINE SPRIORITY116 $1D3

.DEFINE SX117        $1D4
.DEFINE SY117        $1D5
.DEFINE SFRAME117    $1D6
.DEFINE SPRIORITY117 $1D7

.DEFINE SX118        $1D8
.DEFINE SY118        $1D9
.DEFINE SFRAME118    $1DA
.DEFINE SPRIORITY118 $1DB

.DEFINE SX119        $1DC
.DEFINE SY119        $1DD
.DEFINE SFRAME119    $1DE
.DEFINE SPRIORITY119 $1DF

.DEFINE SX120        $1E0
.DEFINE SY120        $1E1
.DEFINE SFRAME120    $1E2
.DEFINE SPRIORITY120 $1E3

.DEFINE SX121        $1E4
.DEFINE SY121        $1E5
.DEFINE SFRAME121    $1E6
.DEFINE SPRIORITY121 $1E7

.DEFINE SX122        $1E8
.DEFINE SY122        $1E9
.DEFINE SFRAME122    $1EA
.DEFINE SPRIORITY122 $1EB

.DEFINE SX123        $1EC
.DEFINE SY123        $1ED
.DEFINE SFRAME123    $1EE
.DEFINE SPRIORITY123 $1EF

.DEFINE SX124        $1F0
.DEFINE SY124        $1F1
.DEFINE SFRAME124    $1F2
.DEFINE SPRIORITY124 $1F3

.DEFINE SX125        $1F4
.DEFINE SY125        $1F5
.DEFINE SFRAME125    $1F6
.DEFINE SPRIORITY125 $1F7

.DEFINE SX126        $1F8
.DEFINE SY126        $1F9
.DEFINE SFRAME126    $1FA
.DEFINE SPRIORITY126 $1FB

.DEFINE SX127        $1FC
.DEFINE SY127        $1FD
.DEFINE SFRAME127    $1FE
.DEFINE SPRIORITY127 $1FF


;=================================================================


.BANK 0 SLOT 0
.SECTION "initsprcode"

INIT_SPRITES:
    php
    rep   #$30                      ; A/mem=X/Y=16bits
    ldx   #$0000
    lda   #$5555
_INSPR_CLR:
    sta   SPRBUF2, X                ; All sprites off screen
    inx
    inx
    cpx   #$0020
    bne   _INSPR_CLR
    plp
    rts

.ENDS


;=================================================================


.BANK 0 SLOT 0
.SECTION "initSprPrior"

SPRITEZ_PRIOR30
    pha
    lda #$30

    sta SPRBUF1+SPRIORITY
    sta SPRBUF1+SPRIORITY1
    sta SPRBUF1+SPRIORITY2
    sta SPRBUF1+SPRIORITY3
    sta SPRBUF1+SPRIORITY4
    sta SPRBUF1+SPRIORITY5
    sta SPRBUF1+SPRIORITY6
    sta SPRBUF1+SPRIORITY7
    sta SPRBUF1+SPRIORITY8
    sta SPRBUF1+SPRIORITY9
    sta SPRBUF1+SPRIORITY10
    sta SPRBUF1+SPRIORITY11
    sta SPRBUF1+SPRIORITY12
    sta SPRBUF1+SPRIORITY13
    sta SPRBUF1+SPRIORITY14
    sta SPRBUF1+SPRIORITY15
    sta SPRBUF1+SPRIORITY16
    sta SPRBUF1+SPRIORITY17
    sta SPRBUF1+SPRIORITY18
    sta SPRBUF1+SPRIORITY19
    sta SPRBUF1+SPRIORITY20
    sta SPRBUF1+SPRIORITY21
    sta SPRBUF1+SPRIORITY22
    sta SPRBUF1+SPRIORITY23
    sta SPRBUF1+SPRIORITY24
    sta SPRBUF1+SPRIORITY25
    sta SPRBUF1+SPRIORITY26
    sta SPRBUF1+SPRIORITY27
    sta SPRBUF1+SPRIORITY28
    sta SPRBUF1+SPRIORITY29
    sta SPRBUF1+SPRIORITY30
    sta SPRBUF1+SPRIORITY31

    pla
    rts

.ENDS
