-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMain.s
448 lines (295 loc) · 11.9 KB
/
Main.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
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
FNAME "msx-wings.rom" ; output file
START_ADDR_MEGAROM_PAGE: equ 0x8000
PAGE_SIZE: equ 0x4000 ; 16kB
Seg_P8000_SW: equ 0x7000 ; Segment switch for page 0x8000-0xBFFF (ASCII 16k Mapper, same for 8k Mapper)
DEBUG: equ 255 ; defines debug mode, value is irrelevant (comment it out for production version)
; Compilation address
org 0x4000, 0x7fff ; 0x8000 can be also used here if Rom size is 16kB or less.
; Common
INCLUDE "Include/RomHeader.s"
; code to force ASCII16 mapper auto detection on openMSX (not working)
; https://www.msx.org/forum/msx-talk/development/how-to-create-a-long-rom-file?page=2#comment-456529
;db 0x32, 0, 0x70, 0x32, 0xFF, 0x77
; ld (7000h),a
; ld (77ffh),a
INCLUDE "Include/MsxBios.s"
INCLUDE "Include/MsxConstants.s"
INCLUDE "Include/CommonRoutines.s"
INCLUDE "Include/CommonRoutines_SC11.s"
INCLUDE "Include/CommonRoutines_SC5.s"
INCLUDE "Include/dzx0_standard.asm"
; INCLUDES from msxlib:
include "include/msxlib/asm.asm"
; -----------------------------------------------------------------------------
; Replayer routines
; PT3-based implementation
include "include/replayer_pt3.asm"
; ayFX REPLAYER v1.31
include "include/ayFX-ROM.tniasm.asm"
; -----------------------------------------------------------------------------
; Game
INCLUDE "HTIMI_Hook.s"
INCLUDE "InitVram.s"
INCLUDE "Update_SPRATR.s"
;INCLUDE "BlitSPRATR.s"
INCLUDE "InitVariables/InitVariables_GameStart.s"
INCLUDE "InitVariables/InitVariables_LevelStart.s"
INCLUDE "InitVariables/InitVariables_PlayerStart.s"
INCLUDE "Scroll.s"
INCLUDE "ReadInput.s"
INCLUDE "PaletteCycling.s"
INCLUDE "GameLogic/CommonLogic.s"
INCLUDE "GameLogic/GameLogic.s"
INCLUDE "GameLogic/PlayerLogic.s"
INCLUDE "GameLogic/PlayerBombLogic.s"
INCLUDE "GameLogic/PlayerShotLogic/PlayerShot_Init.s"
INCLUDE "GameLogic/PlayerShotLogic/PlayerShot_Reset.s"
INCLUDE "GameLogic/PlayerShotLogic/PlayerShot_Logic.s"
INCLUDE "GameLogic/EnemyLogic/Enemy_Init.s"
INCLUDE "GameLogic/EnemyLogic/Enemy_Reset.s"
INCLUDE "GameLogic/EnemyLogic/Enemy_Logic.s"
INCLUDE "GameLogic/BigEnemyLogic/BigEnemy_Init.s"
INCLUDE "GameLogic/BigEnemyLogic/BigEnemy_Reset.s"
INCLUDE "GameLogic/BigEnemyLogic/BigEnemy_Logic.s"
INCLUDE "GameLogic/BigEnemyLogic/UpdateBigEnemiesPatterns.s"
INCLUDE "GameLogic/EnemyShotLogic/EnemyShot_Init.s"
INCLUDE "GameLogic/EnemyShotLogic/EnemyShot_Reset.s"
INCLUDE "GameLogic/EnemyShotLogic/EnemyShot_Logic.s"
INCLUDE "GameLogic/ItemLogic/Item_Init.s"
INCLUDE "GameLogic/ItemLogic/Item_Reset.s"
INCLUDE "GameLogic/ItemLogic/Item_Logic.s"
INCLUDE "GameLogic/ItemLogic/ItemAnimation.s"
INCLUDE "GameLogic/GroundTargetLogic/GroundTarget_Init.s"
INCLUDE "GameLogic/GroundTargetLogic/GroundTarget_Reset.s"
INCLUDE "GameLogic/GroundTargetLogic/GroundTarget_Logic.s"
; INCLUDE "GameLogic/BossLogic/Boss_Init.s"
; INCLUDE "GameLogic/BossLogic/Boss_Reset.s"
; INCLUDE "GameLogic/BossLogic/Boss_Logic.s"
INCLUDE "Data/LevelData/LoadLevel.s"
; INCLUDE "LevelData/Level_1.s" ; moved to a MegaROM page
; INCLUDE "EnemyData/EnemyData_1.s" ; moved to a MegaROM page
; INCLUDE "EnemyData/EnemyShotData.s" ; moved to a MegaROM page
INCLUDE "Sound/Sfx/PlaySfx.s"
INCLUDE "Sound/Music/PlayMusic.s"
INCLUDE "Animations/PauseAnimation/PauseAnimation.s" ; 623 bytes ; candidate to be moved to CODE_TO_BE_RELOCATED_MEGAROM_PAGE
INCLUDE "Animations/LevelTitleAnimation/LevelTitleAnimation.s" ; 437 bytes ; candidate to be moved to CODE_TO_BE_RELOCATED_MEGAROM_PAGE
INCLUDE "Animations/LevelTitleAnimation/Data.s" ; 125 bytes ; candidate to be moved to CODE_TO_BE_RELOCATED_MEGAROM_PAGE
; INCLUDE "Animations/StageClearAnimation/StageClearAnimation.s" ; 905 bytes ; ; moved to MegaROM page, to be relocated to RAM later
;INCLUDE "Animations/StageClearAnimation/SPRATR_Data.s" ; moved to a MegaROM page
;INCLUDE "Graphics/Sprites/StageClearAnimation/StageClearAnimation.s" ; moved to a MegaROM page
INCLUDE "Animations/GameOverAnimation/GameOverAnimation.s" ; 347 bytes ; candidate to be moved to CODE_TO_BE_RELOCATED_MEGAROM_PAGE
; INCLUDE "Animations/GameOverAnimation/GameOverAnimation_Data.s" ; moved to a MegaROM page
INCLUDE "DebugMessage.s"
; INCLUDE "Graphics/Sprites/Fonts/FontsTest.s" ; 353 bytes ; commented out to save space
INCLUDE "Graphics/Sprites/Fonts/Fonts_CommonRoutines.s"
INCLUDE "Graphics/Sprites/Fonts/Fonts_Constants.s"
; moved to MegaROM page, to be relocated to RAM later
; INCLUDE "TitleScreen/TitleScreen.s" ; 759 bytes
; INCLUDE "TitleScreen/Data.s" ; 79 bytes
; INCLUDE "ChooseInputScreen/ChooseInputScreen.s"
; Assets
INCLUDE "Graphics/Sprites/SpritePalettes.s"
; INCLUDE "Graphics/Sprites/SpritePatterns.s" ; moved to a MegaROM page
SpriteColors_start:
INCLUDE "Graphics/Sprites/SpriteColors.s"
SpriteColors_size: equ $ - SpriteColors_start ; 0x3d0 = 976 bytes (it is not easy to move to a MegaROM page cos it is referenced in many places)
; INCLUDE "Graphics/Sprites/Fonts/Fonts.s" ; moved to a MegaROM page
; INCLUDE "Graphics/Bitmaps/GroundTargetDestroyed.s" ; moved to a MegaROM page
; background bitmaps are on MegaRomPages.s
INCLUDE "Relocated_Code_Callers.s"
; --- Megarom subroutine
; Input:
; A: MegaROM page number (1-255)
Set_and_Save_MegaROM_Page:
ld (Current_MegaROM_Page), a
ld (Seg_P8000_SW), a
ret
Execute:
; init interrupt mode and stack pointer (in case the ROM isn't the first thing to be loaded)
di ; disable interrupts
im 1 ; interrupt mode 1
ld sp, (BIOS_HIMEM) ; init SP
; call BIOS_DISSCR
call ClearRam
; PSG: silence
call BIOS_GICINI
; set MegaROM page for SFX data
ld a, SFX_MEGAROM_PAGE
; ld (Seg_P8000_SW), a
call Set_and_Save_MegaROM_Page
; Initializes the replayer
call REPLAYER.RESET
; disable keyboard click
xor a
ld (BIOS_CLIKSW), a ; Key Press Click Switch 0:Off 1:On (1B/RW)
; 0 = MSX 1
; 1 = MSX 2
; 2 = MSX 2+
; 3 = MSX turbo R
ld a, (MSXID3)
cp 2
ld hl, STRING_MSX_2_PLUS_OR_ABOVE_REQUIRED
call c, DebugMessage
call EnableRomPage2
; enable page 1
ld a, 1
ld (Seg_P8000_SW), a
; call ClearRam
; install the interrupt routine
di
ld a, 0xc3 ; opcode for "JP nn"
ld (HTIMI), a
ld hl, HOOK
ld (HTIMI + 1), hl
ei
; ; set MegaROM page for SFX data
; ld a, SFX_MEGAROM_PAGE
; ld (Seg_P8000_SW), a
; ; call Set_and_Save_MegaROM_Page
; ; Starts the music
; ld a, 1 ; index of music on SONG_TABLE
; call REPLAYER.PLAY ; param a: liiiiiii, where l (MSB) is the loop flag (0 = loop), and iiiiiii is the 0-based song index (0, 1, 2...)
; ; restore previous MegaROM page
; ld a, (Current_MegaROM_Page)
; ld (Seg_P8000_SW), a
; call TitleScreen_RAM_Code ; comment it out for debug
; call ChooseInputScreen_RAM_Code ; comment it out for debug
; call HowToPlayScreen_RAM_Code ; comment it out for debug
call InitVram
; ---------------------
; ; fonts test
; call BIOS_ENASCR
; call TestFonts_8x8 ; [debug]
; call TestFonts_8x16 ; [debug]
; call TestFonts_16x16 ; [debug]
; jp $
; ---------------------
; call ClearRam
call InitVariables_GameStart
; Levels 1-4 use slow enemy bullets
; Levels 5-8 use fast enemy bullets
; 1: Tokyo
; 2: USSR
; 3: Japan classic
; 4: Jungle
; 5: NY
; 6: Paris
; 7: Sidney
; 8: Mexico
ld a, 1 ; level number (1-8)
ld (CurrentLevelNumber), a
call LoadLevel
.gameLoop:
ld hl, BIOS_JIFFY ; (v-blank sync)
ld a, (hl)
.waitVBlank:
cp (hl)
jr z, .waitVBlank
IFDEF DEBUG
; Save Jiffy to check if previous frame ended
ld a, (hl)
ld (CurrentJiffy), a
ENDIF
IFDEF DEBUG
; Start profiling a frame with in a,(2dh), end with out (2dh),a.
in a, (2dh)
ENDIF
IFDEF DEBUG
ld a, 4 ; Border color
ld (BIOS_BDRCLR), a
call BIOS_CHGCLR ; Change Screen Color
ENDIF
call ExecuteScroll
; call Update_SPRATR_Buffer
; call BlitSPRATR
call PaletteCycling
IFDEF DEBUG
ld a, 7 ; Border color
ld (BIOS_BDRCLR), a
call BIOS_CHGCLR ; Change Screen Color
ENDIF
call ReadInput
call GameLogic
; --------------------------------------
; old
;call Update_SPRATR_Buffer ; 3791 cycles
;call BlitSPRATR ; 2360 cycles
; = 6151 cycles
; new
call Update_SPRATR ; 3766 cycles (2385 cycles saved)
; --------------------------------------
IFDEF DEBUG
ld a, 8 ; Border color
ld (BIOS_BDRCLR), a
call BIOS_CHGCLR ; Change Screen Color
ENDIF
IFDEF DEBUG
; Checks if main loop takes more than one frame to run
ld a, (BIOS_JIFFY)
ld b, a
ld a, (CurrentJiffy)
cp b
call nz, .frameSkip
ENDIF
IFDEF DEBUG
; Start profiling a frame with in a,(2dh), end with out (2dh),a.
out (2dh) ,a
ENDIF
jp .gameLoop
.frameSkip:
ld hl, FramesSkipped
inc (hl)
ret
STRING_MSX_2_PLUS_OR_ABOVE_REQUIRED: db "MSX 2+ or above required.", 0
End:
; InitialSpriteAttributes:
; ; Y, X, Pattern, Reserved
; ; ----------- player plane
; ; sprites 0 and 1
; db PLAYER_INITIAL_Y, PLAYER_INITIAL_X, PLAYER_SPR_PAT_0_NUMBER, 0
; db PLAYER_INITIAL_Y, PLAYER_INITIAL_X, PLAYER_SPR_PAT_1_NUMBER, 0
; ; sprites 2 and 3
; db PLAYER_INITIAL_Y + 16, PLAYER_INITIAL_X, PLAYER_SPR_PAT_2_NUMBER, 0
; db PLAYER_INITIAL_Y + 16, PLAYER_INITIAL_X, PLAYER_SPR_PAT_3_NUMBER, 0
; ; ; ----------- player shots
; ; ; sprites 4, 5 and 6
; ; db 192, 255, EMPTY_SPR_PAT_NUMBER, 0
; ; db 192, 255, EMPTY_SPR_PAT_NUMBER, 0
; ; db 192, 255, EMPTY_SPR_PAT_NUMBER, 0
; ; ----------- enemy planes
; ; ; TODO: enemy pattern number should be loaded on Enemy_Init
; ; ; sprites 7 and 8
; ; db 0, 0, ENEMY_SPR_PAT_0_NUMBER, 0
; ; db 0, 0, ENEMY_SPR_PAT_1_NUMBER, 0
; ; ; sprites 9 and 10
; ; db 192, 255, ENEMY_SPR_PAT_0_NUMBER, 0
; ; db 192, 255, ENEMY_SPR_PAT_1_NUMBER, 0
; ; ; sprites 11 and 12
; ; db 192, 255, ENEMY_SPR_PAT_0_NUMBER, 0
; ; db 192, 255, ENEMY_SPR_PAT_1_NUMBER, 0
; ; ; sprites 13 and 14
; ; db 30, 0, ENEMY_SPR_PAT_0_NUMBER, 0
; ; db 30, 0, ENEMY_SPR_PAT_1_NUMBER, 0
; ; ; sprites 15 and 16
; ; db 60, 0, ENEMY_SPR_PAT_0_NUMBER, 0
; ; db 60, 0, ENEMY_SPR_PAT_1_NUMBER, 0
; ; ; sprites 17 and 18
; ; db 90, 0, ENEMY_SPR_PAT_0_NUMBER, 0
; ; db 90, 0, ENEMY_SPR_PAT_1_NUMBER, 0
; ; hide all sprites from here onwards
; db 216, 0, 0, 0
; .size: equ $ - InitialSpriteAttributes
; db "End ROM started at 0x4000"
PAGE_0x4000_size: equ $ - 0x4000 ; 0x3BED bytes (aprox 1000 bytes free)
ds PAGE_SIZE - ($ - 0x4000), 255 ; Fill the unused area with 0xFF
; MegaROM pages at 0x8000
INCLUDE "MegaRomPages.s"
; RAM
org 0xc000, 0xe5ff ; for machines with 16kb of RAM (use it if you need 16kb RAM, will crash on 8kb machines, such as the Casio PV-7)
; 0xc000 = 49152
; 0xe5ff = 58879
; max available = 9727 bytes
RamStart:
INCLUDE "Variables.s"
RamEnd:
Ram_size: equ $ - RamStart ; used: 0x1AB5 (6837 bytes)