This repository has been archived by the owner on Oct 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.asm
executable file
·580 lines (521 loc) · 15.2 KB
/
main.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
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
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
; ===========================================================================
; +-----------------------------------------------------------------+
; | MARSIANO ENGINE |
; | |
; | A game engine that can be cross-ported to: |
; | Sega Genesis, Sega CD, Sega 32X, Sega CD32X and Sega Pico |
; +-----------------------------------------------------------------+
; ====================================================================
; ----------------------------------------------------------------
; USER SETTINGS
; ----------------------------------------------------------------
; --------------------------------------------------------
; 68000 RAM SIZES
;
; MAX_SysCode, MAX_UserCode and MAX_RamSndData
; are used only in Sega CD, Sega 32X and
; Sega CD32X
; For the stock Genesis (OR Pico) these sections
; are free to use ONLY if you want your game
; to be playable ONLY on stock Genesis or Pico.
;
; Starting from MAX_MdGlobal it the RAM should be
; located after $FF8000
;
; ** MAKE SURE IT DOESN'T REACH $FFFC00 IF YOU WANT TO
; RUN THIS ON SEGA CD AND CD32X **
; $FFFD00 is reserved for SegaCD/SegaCD32X, the
; STACK a7 point starts from here also.
; --------------------------------------------------------
MAX_SysCode equ $1800 ; ** CD/32X/CD32X ONLY
MAX_UserCode equ $2000 ; ** CD/32X/CD32X ONLY
MAX_RamSndData equ $4000 ; ** CD/32X/CD32X ONLY
MAX_MdGlobal equ $0800 ; USER Global variables
MAX_ScrnBuff equ $2800 ; RAM section for Current screen
MAX_MdVideo equ $2000 ;
MAX_MdSystem equ $0500 ;
MAX_MdOther equ $1000 ; System-specific stuff goes here
; ====================================================================
!org 0 ; Start at 0
cpu 68000 ; Current CPU is 68k, gets changed later.
padding off ; Dont pad dc.b
listing purecode ; Want listing file, but only the final code in expanded macros
supmode on ; Supervisor mode 68k
dottedstructs off ; If needed
page 0
; ====================================================================
; ----------------------------------------------------------------
; Includes
; ----------------------------------------------------------------
include "macros.asm" ; Assembler macros
include "system/shared.asm" ; Shared Genesis/32X/CD32X variables
include "system/mcd/shared.asm" ; Shared Sega CD variables
include "system/md/map.asm" ; Genesis hardware map
include "system/mars/map.asm" ; 32X hardware map (SH2 area)
include "system/md/ram.asm" ; Genesis RAM sections
include "game/global.asm" ; Global user variables on the Genesis side.
; ====================================================================
; ----------------------------------------------------------------
; Init procedures
; ----------------------------------------------------------------
; ---------------------------------------------
; SEGA 32X
; ---------------------------------------------
if MARS
include "system/head_mars.asm" ; 32X header
lea ($880000+Md_SysCode),a0 ; Transfer SYSTEM subs
lea (RAM_SystemCode),a1 ; At the TOP of RAM
move.w #((Md_SysCode_e-Md_SysCode))-1,d0
.copy_1:
move.b (a0)+,(a1)+
dbf d0,.copy_1
lea ($880000+Md_JumpCode),a0 ; Transfer SCREEN-JUMP code
lea (RAM_ScreenJump),a1 ; At the BOTTOM of RAM
move.w #((Md_JumpCode_e-Md_JumpCode))-1,d0
.copy_2:
move.b (a0)+,(a1)+
dbf d0,.copy_2
jsr (Sound_init).l ; Init Sound driver FIRST
jsr (Video_init).l ; **** Video
jsr (System_Init).l ; **** Values
move.w #0,(RAM_Glbl_Scrn).w ; Start at screen 0
jmp (Md_ReadModes).l ; Jump to SCREENJUMP section
; ---------------------------------------------
; SEGA CD and CD32X
;
; This one is tricky.
; ---------------------------------------------
elseif MCD|MARSCD
include "system/head_mcd.asm" ; Sega CD header
mcdin_top:
lea Md_SysCode(pc),a0 ; Transfer SYSTEM subs
lea (RAM_SystemCode),a1 ; At TOP of RAM
move.w #((Md_SysCode_e-Md_SysCode))-1,d0
.copy_1:
move.b (a0)+,(a1)+
dbf d0,.copy_1
lea Md_JumpCode(pc),a0 ; Transfer SCREEN-JUMP code
lea (RAM_ScreenJump),a1 ; At BOTTOM of RAM
move.w #((Md_JumpCode_e-Md_JumpCode))-1,d0
.copy_2:
move.b (a0)+,(a1)+
dbf d0,.copy_2
if MARSCD
include "system/mcd/marscd.asm"
endif
lea file_worddata(pc),a0 ; SCD: Load default databank
jsr (System_McdTrnsfr_WRAM).l ; to WORDRAM
jsr (Sound_init).l ; Init Sound driver FIRST (MUST BE STOPPED)
jsr (Video_init).l ; **** Video
jsr (System_Init).l ; **** Values
lea file_gematrks(pc),a0 ; Transfer GEMA tracks and instr
lea (RAM_ExSoundData),a1 ; This will overwrite the stuff
move.w #MAX_RamSndData,d0 ; after the label mcdin_end
jsr (System_McdTrnsfr_RAM).l
move.w #0,(RAM_Glbl_Scrn).w ; Start at screen 0
jmp (Md_ReadModes).l ; Jump to SCREENJUMP section
file_worddata: dc.b "DATABNK0.BIN",0
align 2
file_gematrks: dc.b "GEMATRKS.BIN",0
align 2
mcdin_end:
phase $FFFF2000+(mcdin_end-mcdin_top)
Z80_CODE: include "sound/gema_zdrv.asm" ; Called once
Z80_CODE_END:
dephase
; ---------------------------------------------
; SEGA PICO
;
; This recycles the MD's routines.
; ---------------------------------------------
elseif PICO
include "system/head_pico.asm" ; Pico header
jsr (Sound_init).l ; Init Sound driver FIRST
jsr (Video_init).l ; **** Video
jsr (System_Init).l ; **** Values
move.w #0,(RAM_Glbl_Scrn).w ; Start at screen 0
bra.w Md_ReadModes ; Go to SCREENJUMP section
; ---------------------------------------------
; MD
; ---------------------------------------------
else
include "system/head_md.asm" ; Genesis header
jsr (Sound_init).l ; Init Sound driver FIRST
jsr (Video_init).l ; **** Video
jsr (System_Init).l ; **** Values
move.w #0,(RAM_Glbl_Scrn).w ; Start at screen 0
bra.w Md_ReadModes ; Go to SCREENJUMP section
; ---------------------------------------------
endif
; ====================================================================
; --------------------------------------------------------
; SYSTEM and SCREEN-JUMP codes
;
; MD and PICO: Normal ROM locations
; CD/32X/CD32X: Loaded in RAM
; --------------------------------------------------------
; ---------------------------------------------
; TOP-RAM Genesis system routines
; ---------------------------------------------
Md_SysCode:
if MCD|MARS|MARSCD
phase RAM_SystemCode
endif
; ---------------------------------------------
include "sound/gema.asm"
include "system/md/video.asm"
include "system/md/system.asm"
include "system/mars/md_dreq.asm" ; Tested on HW, works.
; ---------------------------------------------
if MCD|MARS|MARSCD
.end:
erreport "RAM TOP-CODE SUBS",(.end-RAM_SystemCode),MAX_SysCode
dephase
endif
Md_SysCode_e:
align 2
; ---------------------------------------------
; JUMP code for switching screen modes
; ---------------------------------------------
Md_JumpCode:
if MCD|MARS|MARSCD ; $FF0000
phase RAM_ScreenJump
mdjumpcode_s:
endif
; ---------------------------------------------
; Read screen modes
;
; MD/PICO:
; Direct ROM jump
;
; SEGA 32X:
; 880000+ jump
;
; SEGACD/CD32X:
; Read file from disc, transfer to RAM or
; WordRAM and jump there.
; ---------------------------------------------
Md_ReadModes:
moveq #0,d0
move.w (RAM_Glbl_Scrn).w,d0
and.w #%1111,d0 ; <-- [USER] CURRENT LIMIT
if MCD|MARSCD
lsl.w #4,d0 ; * $10
lea .pick_boot(pc),a0 ; LEA the filename
jsr (System_GrabRamCode).l
elseif MARS
lsl.w #2,d0 ; * 4
move.l .pick_boot(pc,d0.w),d0 ; d0 - ROM location $880000+
jsr (System_GrabRamCode).l
else
lsl.w #2,d0 ; * 4
move.l .pick_boot(pc,d0.w),d0 ; Location to JUMP to.
move.l d0,a0
jsr (a0)
endif
bra.s Md_ReadModes ; Loop on RTS
.pick_boot:
; size $10
if MCD|MARSCD
dc.b "SCREEN00.BIN"
dc.l 0
dc.b "SCREEN00.BIN"
dc.l 0
dc.b "SCREEN00.BIN"
dc.l 0
dc.b "SCREEN00.BIN"
dc.l 0
; size 4
else
dc.l Md_Screen00
dc.l Md_Screen00
dc.l Md_Screen00
dc.l Md_Screen00
endif
; ---------------------------------------------
if MCD|MARS|MARSCD
mdjumpcode_e:
erreport "RAM JUMP-CODE SUBS",(mdjumpcode_e-mdjumpcode_s),$180
dephase
endif
Md_JumpCode_e:
align 2
; ====================================================================
; --------------------------------------------------------
; Misc. stuff FOR CARTRIDGE ONLY:
;
; Genesis, Sega 32X and Pico
; --------------------------------------------------------
if MCD|MARSCD=0
if MARS
phase $880000+*
endif
Z80_CODE: include "sound/gema_zdrv.asm" ; Called once
Z80_CODE_END:
endif
if MCD|MARS|MARSCD
dephase
endif
; ===========================================================================
; ----------------------------------------------------------------
; GAME DATA for ALL Cartridge and Disc
; ----------------------------------------------------------------
; --------------------------------------------------------
; SEGA CD / SEGA CD32X ISO header
; --------------------------------------------------------
if MCD|MARSCD
align $8000 ; Pad to $8000
binclude "system/mcd/fshead.bin" ; <-- common ISO head
iso_setfs 0,IsoFileList,IsoFileList_e ; TWO COPIES
iso_setfs 1,IsoFileList,IsoFileList_e
IsoFileList: iso_file "MARSCODE.BIN",MARS_RAMDATA,MARS_RAMDATA_E
iso_file "DATABNK0.BIN",MCD_DBANK0,MCD_DBANK0_e
iso_file "GEMATRKS.BIN",MCD_GEMATRKS,MCD_GEMATRKS_e
iso_file "SCREEN00.BIN",Md_Screen00,Md_Screen00_e
align $800
IsoFileList_e:
endif
; ====================================================================
; --------------------------------------------------------
; Screen modes
; --------------------------------------------------------
if MCD|MARSCD
align $800 ; CD Sector align
elseif MARS
phase $880000+* ; 32X ROM def-location
endif
Md_Screen00:
; if MARS
;
; endif
if MCD|MARSCD|MARS
dephase
phase RAM_UserCode
endif
cscrn0_s:
include "game/screen_0.asm"
cscrn0_e:
if MARS
dephase
elseif MCD|MARSCD
dephase
align $800
endif
Md_Screen00_e:
if MCD|MARS|MARSCD
report "SCREEN 0 code",cscrn0_e-cscrn0_s,MAX_UserCode
endif
; ====================================================================
; --------------------------------------------------------
; GEMA SOUND DRIVER DATA:
; Tracks and Instruments
;
; MD: Normal ROM area
; MCD: Loaded to RAM from disc (Z80 CAN read from RAM)
; 32X: At the $880000+ area
; CD32X: Same as CD
; Pico: N/A
;
; DAC samples are stored externally depending
; of the system.
; 32X: PWM can be on both ROM and SDRAM
; but to keep cross-compatible with CD32X use
; SDRAM only, use small samples to save space.
; --------------------------------------------------------
if MCD|MARSCD
align $800
endif
MCD_GEMATRKS:
if MARS
phase $880000+*
elseif MCD|MARSCD
phase RAM_ExSoundData
endif
gemacd_report:
include "sound/tracks.asm" ; GEMA: Track data
include "sound/instr.asm" ; GEMA: FM instruments
gemacd_report_e:
if MARS
dephase
elseif MCD|MARSCD
align $800
dephase
MCD_GEMATRKS_e:
report "MCD GEMA TRACKS/INS",gemacd_report_e-gemacd_report,MAX_RamSndData
endif
; ====================================================================
; ----------------------------------------------------------------
; 68K DATA BANKs
;
; SEGA CD:
; BANKS are stored in WORD-RAM pieces
; limited to 256KB 2M or 128KB 1M/1M
; ** THESE CANNOT BE USED IF USING ASIC STAMPS **
;
; SEGA 32X:
; BANKS are limited to 1MB, only 4 banks can be used
; ----------------------------------------------------------------
; ---------------------------------------------
; DEFAULT BANK
;
; CD/CD32X:
; $200000 256KB WORD-RAM
;
; 32X:
; $900000 1MB (This is BANK 0)
; ---------------------------------------------
MCD_DBANK0:
if MARS
phase $900000+* ; ** Currently this one only.
elseif MCD|MARSCD
phase sysmcd_wram
endif
mdbank0:
include "game/data/md_bank0.asm" ; <-- 68K ONLY bank data
mdbank0_e:
include "sound/smpl_dac.asm" ; (MCD/CD32X ONLY) GEMA: DAC samples
; if MARS
; org $100000-4 ; Fill this bank and
; dc.b "BNK0" ; add a tag at the end
; dephase
if MCD|MARSCD
include "game/data/md_dma.asm" ; SEGA CD / CD32X ONLY.
endif
if MARS|MCD|MARSCD
mdbank0_cd_e:
dephase
align $800
MCD_DBANK0_e:
endif
if MARS
report "68K DEFAULT BANK (900000)",mdbank0_e-mdbank0,$100000
elseif MCD|MARSCD
report "68K DEFAULT BANK (WORDRAM)",mdbank0_cd_e-mdbank0,$40000
endif
; ---------------------------------------------
; BANK 1
; ---------------------------------------------
; phase $900000
; include "game/data/md_bank1.asm"
; dephase
; org $200000-4
; dc.b "BNK1"
; ---------------------------------------------
; BANK 2
; ---------------------------------------------
; phase $900000
; include "game/data/md_bank2.asm"
; dephase
; org $300000-4
; dc.b "BNK2"
; ---------------------------------------------
; BANK 3
; ---------------------------------------------
; phase $900000
; include "game/data/md_bank3.asm"
; dephase
; org $400000-4
; dc.b "BNK3"
; ====================================================================
; ----------------------------------------------------------------
; 32X Cartridge DMA data: Requires RV bit set to 1, BANK-free
; ----------------------------------------------------------------
align $8000
if MCD|MARSCD=0
include "game/data/md_dma.asm"
endif
; ====================================================================
; ----------------------------------------------------------------
; 32X ONLY
;
; SH2 code and ROM data
;
; ** MARSCD: Loads to WORD-RAM
; ----------------------------------------------------------------
if MCD|MARSCD
align $800
elseif MARS
align 4
endif
MARS_RAMDATA:
if MARS|MARSCD
include "system/mars/code.asm"
cpu 68000
padding off
dephase
endif
if MCD|MARSCD
align $800
endif
MARS_RAMDATA_E:
align 4
; ====================================================================
; --------------------------------------------------------
; SH2's ROM-only stuff
; This section will be gone if RV bit is set to 1
; --------------------------------------------------------
if MARS
phase CS1+*
align 4
; include "sound/smpl_pwm_rom.asm" ; GEMA: PWM samples
include "game/data/mars_rom.asm"
dephase
endif
; ====================================================================
; ---------------------------------------------
; End
; ---------------------------------------------
lea ($FFFFC176).w,a0
lea ($A10003).l,a1
bsr.s loc_3410
lea ($A10005).l,a1
loc_3410: ; CODE XREF: ROM:00003406p
move.w #$100,($A11100).l
move.b #0,(a1)
nop
nop
nop
move.b (a1),d1
nop
nop
nop
move.b #$40,(a1) ; '@'
asl.w #2,d1
move.w d1,d2
move.b (a1),d0
andi.w #$30,d2 ; '0'
beq.w loc_3440
move.w #$FF,d1
loc_3440: ; CODE XREF: ROM:00003438j
andi.w #$3F,d0 ; '?'
andi.w #$C0,d1 ; 'À'
or.w d1,d0
not.w d0
movea.l ($FFFFFE38).w,a1
move.b d0,d1
andi.b #$8F,d0
bclr #6,d1
beq.s loc_345E
or.b (a1),d0
loc_345E: ; CODE XREF: ROM:0000345Aj
bclr #5,d1
beq.s loc_3468
or.b 1(a1),d0
loc_3468:
bclr #4,d1
beq.s loc_3472
or.b 2(a1),d0
loc_3472:
eor.b d0,(a0)
move.b (a0),d1
move.b d0,(a0)+
and.w d1,d0
move.b d0,(a0)+
move.w #0,($A11100).l
rts
ROM_END:
if MCD|MARSCD
rompad $300000 ; Pad the ISO file
else
align $8000 ; Pad the Cartridge
endif