-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathScroll.s
355 lines (276 loc) · 10.7 KB
/
Scroll.s
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
BYTES_PER_LINE: equ 256 ; screen 11
;BYTES_PER_LINE: equ 128 ; screen 5
ADDR_LAST_LINE_OF_PAGE: equ 0x8000 + (63 * 256)
; Input:
; A: number of MegaROM page for first page after first screen
InitVariablesForScroll:
; initialize variables for scrolling on last line of the next page
;ld a, 13
ld (CurrentMegaROMPage), a
ld hl, ADDR_LAST_LINE_OF_PAGE
ld (CurrentAddrLineScroll), hl
ld hl, 255 * 256
ld (CurrentVRAMAddrLineScroll), hl
; VerticalScroll: byte
xor a
ld (VerticalScroll), a
ld b, a ; data
ld c, 23 ; register #
call BIOS_WRTVDP
; VerticalScroll: word
; ld hl, 0
; ld (VerticalScroll), hl
ret
; Input:
; A: number of MegaROM page for last page of first screen
LoadFirstScreen:
; --------- Load first screen
push af
dec a
call InitVariablesForScroll
pop af
push af
; -- Load top part of first image on top 64 lines
;ld a, 14
; ld (Seg_P8000_SW), a
call Set_and_Save_MegaROM_Page
; write to VRAM bitmap area
ld hl, START_ADDR_MEGAROM_PAGE ; ImageData_14 ; RAM address (source)
ld de, NAMTBL + (0 * (256 * 64)) ; VRAM address (destiny)
ld bc, PAGE_SIZE ; ImageData_14.size ; Block length
call BIOS_LDIRVM ; Block transfer to VRAM from memory
pop af
inc a
push af
; -- Load middle part of first image on middle 64 lines
;ld a, 15
; ld (Seg_P8000_SW), a
call Set_and_Save_MegaROM_Page
; write to VRAM bitmap area
ld hl, START_ADDR_MEGAROM_PAGE ; ImageData_15 ; RAM address (source)
ld de, NAMTBL + (1 * (256 * 64)) ; VRAM address (destiny)
ld bc, PAGE_SIZE ; ImageData_15.size ; Block length
call BIOS_LDIRVM ; Block transfer to VRAM from memory
pop af
inc a
push af
; -- Load bottom part of first image on last 64 lines
;ld a, 16
; ld (Seg_P8000_SW), a
call Set_and_Save_MegaROM_Page
; write to VRAM bitmap area
ld hl, START_ADDR_MEGAROM_PAGE ; ImageData_16 ; RAM address (source)
ld de, NAMTBL + (2 * (256 * 64)) ; VRAM address (destiny)
ld bc, PAGE_SIZE ; ImageData_16.size ; Block length
call BIOS_LDIRVM ; Block transfer to VRAM from memory
pop af
ret
SCROLL_FULL_SPEED: equ 0000 0000 b
SCROLL_HALF_SPEED: equ 0000 0001 b
SCROLL_ONE_FOURTH_SPEED: equ 0000 0011 b
SCROLL_SPEED: equ SCROLL_ONE_FOURTH_SPEED
ExecuteScroll:
; speed scroll (scroll only on even frames or on all frames, or at 1/4 of frames)
ld a, (BIOS_JIFFY) ; get only low byte of JIFFY
and SCROLL_SPEED
ret nz
IFDEF DEBUG
; Start profiling a section with in a,(2ch), end with out (2ch),a. ID in A.
xor a
in a, (2ch)
ENDIF
; load next line from bitmap on the last line of virtual screen (256 lines)
; that will be the next to be shown on top of screen
ld a, (CurrentMegaROMPage)
; ld (Seg_P8000_SW), a
call Set_and_Save_MegaROM_Page
; old (slow)
; ld hl, (CurrentAddrLineScroll) ; RAM address (source)
; ld de, (CurrentVRAMAddrLineScroll) ; VRAM address (destiny)
; ld bc, 256 ; Block length
; call BIOS_LDIRVM ; Block transfer to VRAM from memory
; new (optimized) OTIR = 23 cycles/byte = 256x23 = 5888 cycles/frame ; OUTI = 18 cycles/byte = 256x18 = 4608 cycles/frame
ld a, 0000 0000 b
ld hl, (CurrentVRAMAddrLineScroll) ; VRAM address (destiny)
call SetVdp_Write
; unrolled OUTIs
ld hl, (CurrentAddrLineScroll) ; RAM address (source)
ld c, PORT_0
ld d, 8
.loopOUTI:
; 32x OUTI
call OUTI_x32
; outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi
; outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi outi
dec d
jp nz, .loopOUTI
; TODO: use VDP command to gain speed (HMMC copies data from your ram to the vram)
; info: HMMC VDP command currently is not working, check msx-tests POC
;
; ld hl, LMMM_Parameters
; call Execute_VDP_LMMM ; Logical move CPU to VRAM (copies data from your ram to the vram)
; update vars
ld de, (CurrentVRAMAddrLineScroll)
dec d ; de = de - 256
ld hl, (CurrentAddrLineScroll)
dec h ; hl = hl - 256
ld a, h
cp 0x80 - 1 ; 0x7fff
jp z, .decPage
jp .dontDecPage
.decPage:
; if (CurrentMegaROMPage == CurrentLevelLastScreen) stopScroll
ld a, (CurrentLevelLastScreen)
ld b, a
ld a, (CurrentMegaROMPage)
cp b
jp z, .stopScroll
; if (CurrentMegaROMPage == 1) stopScroll
dec a
jp z, .stopScroll
ld (CurrentMegaROMPage), a
ld hl, ADDR_LAST_LINE_OF_PAGE
.dontDecPage:
ld (CurrentAddrLineScroll), hl
ld (CurrentVRAMAddrLineScroll), de
; -------------- do vertical scroll
; VerticalScroll: word
; ld hl, (VerticalScroll)
; dec hl
; ld (VerticalScroll), hl
; ld b, l ; data
; VerticalScroll: byte
ld hl, VerticalScroll
dec (hl)
ld b, (hl) ; data
ld c, 23 ; register #
call BIOS_WRTVDP
ld hl, Screen_Y_Origin
dec (hl)
call AdjustSprites_Y
IFDEF DEBUG
; Start profiling a section with in a,(2ch), end with out (2ch),a. ID in A.
xor a
out (2ch), a
ENDIF
ret
.stopScroll:
call StageClearAnimation_RAM_Code
call NextLevel
ret
AdjustSprites_Y:
; adjust Y position of sprites to compensate scroll
ld hl, Player_Y
dec (hl) ; call .adjustSprite
; player shots are so fast that they don't need such a small adjust (let's save some CPU cycles!)
; ld hl, PlayerShot_0_Struct + 2
; call .adjustSprite
; ld hl, PlayerShot_1_Struct + 2
; call .adjustSprite
; ld hl, PlayerShot_2_Struct + 2
; call .adjustSprite
; TODO: if (EnemyMode == ENEMY_MODE_SMALL_ENEMIES)
ld hl, Enemy_0_Struct + 2 ; Y
dec (hl) ; call .adjustSprite
ld hl, Enemy_0_Struct + 11 ; Y1
dec (hl) ; call .adjustSprite
ld hl, Enemy_1_Struct + 2
dec (hl) ; call .adjustSprite
ld hl, Enemy_1_Struct + 11
dec (hl) ; call .adjustSprite
ld hl, Enemy_2_Struct + 2
dec (hl) ; call .adjustSprite
ld hl, Enemy_2_Struct + 11
dec (hl) ; call .adjustSprite
ld hl, Enemy_3_Struct + 2
dec (hl) ; call .adjustSprite
ld hl, Enemy_3_Struct + 11
dec (hl) ; call .adjustSprite
ld hl, Enemy_4_Struct + 2
dec (hl) ; call .adjustSprite
ld hl, Enemy_4_Struct + 11
dec (hl) ; call .adjustSprite
ld hl, Enemy_5_Struct + 2
dec (hl) ; call .adjustSprite
ld hl, Enemy_5_Struct + 11
dec (hl) ; call .adjustSprite
ld hl, Enemy_6_Struct + 2
dec (hl) ; call .adjustSprite
ld hl, Enemy_6_Struct + 11
dec (hl) ; call .adjustSprite
; adjust all Ys of Big Enemies
ld hl, BigEnemy_0_Struct + 2 ; Y
dec (hl) ; call .adjustSprite
ld hl, BigEnemy_0_Struct + 9 ; Y1
dec (hl) ; call .adjustSprite
ld hl, BigEnemy_0_Struct + 11 ; Y2
dec (hl) ; call .adjustSprite
ld hl, BigEnemy_0_Struct + 13 ; Y3
dec (hl) ; call .adjustSprite
ld hl, BigEnemy_0_Struct + 15 ; Y4
dec (hl) ; call .adjustSprite
ld hl, BigEnemy_0_Struct + 17 ; Y5
dec (hl) ; call .adjustSprite
ld hl, BigEnemy_0_Struct + 19 ; Y6
dec (hl) ; call .adjustSprite
ld hl, BigEnemy_1_Struct + 2 ; Y
dec (hl) ; call .adjustSprite
ld hl, BigEnemy_1_Struct + 9 ; Y1
dec (hl) ; call .adjustSprite
ld hl, BigEnemy_1_Struct + 11 ; Y2
dec (hl) ; call .adjustSprite
ld hl, BigEnemy_1_Struct + 13 ; Y3
dec (hl) ; call .adjustSprite
ld hl, BigEnemy_1_Struct + 15 ; Y4
dec (hl) ; call .adjustSprite
ld hl, BigEnemy_1_Struct + 17 ; Y5
dec (hl) ; call .adjustSprite
ld hl, BigEnemy_1_Struct + 19 ; Y6
dec (hl) ; call .adjustSprite
ld hl, EnemyShot_0_Struct + 2
dec (hl) ; call .adjustSprite
ld hl, EnemyShot_1_Struct + 2
dec (hl) ; call .adjustSprite
ld hl, EnemyShot_2_Struct + 2
dec (hl) ; call .adjustSprite
ld hl, EnemyShot_3_Struct + 2
dec (hl) ; call .adjustSprite
ld hl, EnemyShot_4_Struct + 2
dec (hl) ; call .adjustSprite
ld hl, EnemyShot_5_Struct + 2
dec (hl) ; call .adjustSprite
ld hl, EnemyShot_6_Struct + 2
dec (hl) ; call .adjustSprite
ld hl, Item_0_Struct + 2
dec (hl) ; call .adjustSprite
; ld hl, Item_0_Struct + 11 ; y1 isn't used for items
; call .adjustSprite
ld hl, Item_1_Struct + 2
dec (hl) ; call .adjustSprite
ld hl, Item_2_Struct + 2
dec (hl) ; call .adjustSprite
ld hl, Item_3_Struct + 2
dec (hl) ; call .adjustSprite
ld hl, Item_4_Struct + 2
dec (hl) ; call .adjustSprite
ld hl, Item_5_Struct + 2
dec (hl) ; call .adjustSprite
ld hl, Item_6_Struct + 2
dec (hl) ; call .adjustSprite
ld hl, GroundTarget_Sprite.Y
dec (hl) ; call .adjustSprite
ret
; .adjustSprite:
; ; CAUTION: Adjust is only working when the objects are moving on 1px or 3px increments on Y coord (don't know why)
; ; TODO: if this routine has only one instruction,
; ; substitute the call by the instruction itself saving 18 (call) + 11 (ret) = 29 cycles per object (!), aprox 900 cycles, pretty good optimization
; dec (hl)
; ; ld a, (hl)
; ; dec a
; ; ; commented out because it was causing bug
; ; ;cp 216 ; avoid value 216 (hide all sprites)
; ; ;jp nz, .continue
; ; ;ld a, 215
; ; .continue:
; ; ld (hl), a
; ret