-
Notifications
You must be signed in to change notification settings - Fork 28
/
aliens.asm
142 lines (118 loc) · 3.94 KB
/
aliens.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
; Troy's HBC-56 - 6502 - Invaders - Aliens
;
; Copyright (c) 2021 Troy Schrapel
;
; This code is licensed under the MIT license
;
; https://github.com/visrealm/hbc-56
;
;
INVADER1_TYPE = INVADER1
INVADER2_TYPE = INVADER2
INVADER3_TYPE = INVADER3
INVADER1_PATT = 128
INVADER2_PATT = 136
INVADER3_PATT = 144
; -----------------------------------------------------------------------------
; Aliens setup
; -----------------------------------------------------------------------------
setupAliens:
; setup alien types
lda #<INVADER1_TYPE
sta INV1_BASE_ADDR_L
lda #>INVADER1_TYPE
sta INV1_BASE_ADDR_H
lda #<INVADER2_TYPE
sta INV2_BASE_ADDR_L
lda #>INVADER2_TYPE
sta INV2_BASE_ADDR_H
lda #<INVADER3_TYPE
sta INV3_BASE_ADDR_L
lda #>INVADER3_TYPE
sta INV3_BASE_ADDR_H
; colors
+tmsSetAddrColorTable 16
ldy #INVADER_OFFSET_COLOR
lda (INV1_BASE_ADDR_L), y
+tmsPut
lda (INV2_BASE_ADDR_L), y
+tmsPut
lda (INV3_BASE_ADDR_L), y
+tmsPut
jsr aliensSetTiles0
rts
; -----------------------------------------------------------------------------
; aliensUpdateTileset: Update patterns for a single alien type
; -----------------------------------------------------------------------------
!macro aliensUpdateAlienTileset .patternIndex, .baseAddress, .offset {
+tmsSetAddrPattTable .patternIndex
+tmsSetSourceAddressIndOffset .baseAddress, .offset
+tmsSendBytes 16
}
; -----------------------------------------------------------------------------
; aliensUpdateTileset: Update patterns for all aliens
; -----------------------------------------------------------------------------
!macro aliensUpdateTileset .offset {
+aliensUpdateAlienTileset INVADER1_PATT, INV1_BASE_ADDR_L, .offset
+aliensUpdateAlienTileset INVADER2_PATT, INV2_BASE_ADDR_L, .offset
+aliensUpdateAlienTileset INVADER3_PATT, INV3_BASE_ADDR_L, .offset
}
; -----------------------------------------------------------------------------
; alienColor: Get the color for the given alien type
; -----------------------------------------------------------------------------
; Inputs:
; A: tile index
; Outputs:
; A: color
; -----------------------------------------------------------------------------
alien1Color:
lda (INV1_BASE_ADDR_L), y
+lsr4
rts
alien2Color:
lda (INV2_BASE_ADDR_L), y
+lsr4
rts
alien3Color:
lda (INV3_BASE_ADDR_L), y
+lsr4
rts
alienColor:
ldy #INVADER_OFFSET_COLOR
cmp #INVADER2_PATT
bcc alien1Color
cmp #INVADER3_PATT
bcc alien2Color
jmp alien3Color
; -----------------------------------------------------------------------------
; Alien tileset 0: Base offset
; -----------------------------------------------------------------------------
aliensSetTiles0:
+aliensUpdateTileset 0
lda #0
sta INVADER_PIXEL_OFFSET
rts
; -----------------------------------------------------------------------------
; Alien tileset 1: 2px offset
; -----------------------------------------------------------------------------
aliensSetTiles1:
+aliensUpdateTileset INVADER_OFFSET_2
lda #2
sta INVADER_PIXEL_OFFSET
rts
; -----------------------------------------------------------------------------
; Alien tileset 2: 4px offset
; -----------------------------------------------------------------------------
aliensSetTiles2:
+aliensUpdateTileset INVADER_OFFSET_4
lda #4
sta INVADER_PIXEL_OFFSET
rts
; -----------------------------------------------------------------------------
; Alien tileset 3: 6px offset
; -----------------------------------------------------------------------------
aliensSetTiles3:
+aliensUpdateTileset INVADER_OFFSET_6
lda #6
sta INVADER_PIXEL_OFFSET
rts