/
halleys.cpp
2296 lines (1861 loc) · 74.7 KB
/
halleys.cpp
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
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// license:BSD-3-Clause
// copyright-holders:Phil Stroffolino, Acho A. Tang
/*
Halley's Comet, 1986 Taito
Halley's Comet was created by Fukio Mitsuji (MTJ),
who also created Bubble Bobble, Rainbow Islands, Syvalion, etc.
Issues:
- Status reads from blitter RAM aren't well understood.
They probably includes both completion and collision flags.
- The blitter is missing many features, in particular certain sprites aren't
erased properly.
- It isn't known how many independent planes of graphics the blitter manages.
The starfield, for example, probably involves at least two additional planes
orthogonal to the sprites and scroll layer.
- Background tiles inside the comet have wrong coordinates.
- Score digits have wrong colors.
- Blitter functions, especially those capable of screen warping, are unoptimized.
- The starfields can probably be represented and rendered by two simple lists
instead of costly bitmaps.
- Ben Bero Beh has collision problems with the falling fireballs and a minor
priority glitch with the "Elevator Action" baddies.
- IRQ system needs a complete rewrite
- De-achoize the blitter code
* Halley's Comet's undocumented DIP switches only work if the player1 start button
is depressed during boot-up.
Special thanks to Phil Stroffolino for the creation of a solid framework,
Jarek Burczynski for adding sound and providing awesome hand-drawn schematics,
Jason MacFarlane for his continuous and selfless support. I'd never have come
all this way without the invaluable videos and screen shots sent by Jason.
To the Columbia crew and the forerunners who gave their lives to science and space exploration.
Your bravery and devotion will not be forgotten.
CPU: MC68B09EP Z80A(SOUND)
Sound: YM2149F x 4
OSC: 19.968MHz 6MHz
J1100021 sound daughterboard
Z80A 6MHz
2016
A62-13
A62-14
YM2149
YM2149
YM2149
J1100018
sw1 sw2 sw3 sw4
A62-2 A62-15
68B09EP A62-1
A62-4
2016 YM2149
2016
J1100020
4116 4116 4116 4116 MB15511
4116 4116 4116 4116
4116 4116 4116 4116
4116 4116 4116 4116
4116 4116 4116 4116 MB15512
4116 4116 4116 4116
4116 4116 4116 4116
4116 4116 4116 4116
MB15510 MB15510
2016
2016
J1100019
A62-9 A62-10
A26-13 A62-11 A62-12
A26-13 A62-5 A62-16
A26-13 A62-7 A62-8
HALLEY'S COMET
Taito 1986
Pinout and DIP switch settings
typed in by Pelle Einarsson, pelle@mensa.se
NOTE: I had to guess the meaning of some Japanese text concerning the DIP
switch settings, but I think I got it right.
* = default settings
T G
PARTS SOLDER PARTS SOLDER
---------------------------------- ---------------------------------------
GND 1 A GND GND 1 A GND
GND 2 B GND 2 B
GND 3 C GND 3 C
GND 4 D GND 4 D
Video GND 5 E Video GND Sound out+ 5 E Sound Out -
Video sync 6 F Video sync Post 6 F Post
Post 7 H Post 7 H Power on reset
Video R 8 J Video R Coin sw A 8 J Coin sw B
Video G 9 K Video G Coin counter A 9 K Coin counter B
Video B 10 L Video B Coin lockout A 10 L Coin lockout B
-5V 11 M -5V Service sw 11 M Tilt sw
-5V 12 N -5V Select 1 12 N Select 2
+12V 13 P +12V 1P up 13 P 2P up
+12V 14 R +12V 1P down 14 R 2P down
+5V 15 S +5V 1P right 15 S 2P right
+5V 16 T +5V 1P left 16 T 2P left
+5V 17 U +5V 17 U
+5V 18 V +5V 18 V
19 W
20 X
H 1P shoot 21 Y 2p shoot
-------- 1P hyperspace 22 Z 2P hyperspace
1 GND
2 GND
3 GND
4 GND
5 +5V
6 +5V
7 +5V
8 -5V
9 +13V (a typo?) DIP switch 1 Option 1-5 6
10 Post ----------------------------------------------
11 +12V (single/dual controls?) *1-way off on
12 +12V 2-way off
color test layout: (0,0) *ROT90
+------+-------+------+------+
| | | | |
| White| Blue |Green | Red | 1 (brightest)
| | | | |
+------+-------+------+------+
| | | | |
| | | | | 2
| | | | |
+------+-------+------+------+
| | | | |
| | | | | 3
| | | | |
+------+-------+------+------+
| | | | |
| | | | | 4 (darkest)
| | | | |
+------+-------+------+------+
*/
//**************************************************************************
// Compiler Directives
#include "emu.h"
#include "taitoipt.h"
#include "cpu/m6809/m6809.h"
#include "cpu/z80/z80.h"
#include "machine/gen_latch.h"
#include "machine/timer.h"
#include "sound/ay8910.h"
#include "emupal.h"
#include "screen.h"
#include "speaker.h"
namespace {
#define HALLEYS_DEBUG 0
//**************************************************************************
// Driver Constants and Variables
#define GAME_BENBEROB 0
#define GAME_HALLEYS 1
/* CAUTION: SENSITIVE VALUES */
#define SCREEN_WIDTH_L2 8
#define SCREEN_HEIGHT 256
#define VIS_MINX 0
#define VIS_MAXX 255
#define VIS_MINY 8
#define VIS_MAXY (255-8)
#define MAX_LAYERS 6
#define MAX_SPRITES 256
#define SP_2BACK 0x100
#define SP_ALPHA 0x200
#define SP_COLLD 0x300
#define BG_MONO 0x400
#define BG_RGB 0x500
#define PALETTE_SIZE 0x600
#define SCREEN_WIDTH (1 << SCREEN_WIDTH_L2)
#define SCREEN_SIZE (SCREEN_HEIGHT << SCREEN_WIDTH_L2)
#define SCREEN_BYTEWIDTH_L2 (SCREEN_WIDTH_L2 + 1)
#define SCREEN_BYTEWIDTH (1 << SCREEN_BYTEWIDTH_L2)
#define SCREEN_BYTESIZE (SCREEN_HEIGHT << SCREEN_BYTEWIDTH_L2)
#define CLIP_SKIP (VIS_MINY * SCREEN_WIDTH + VIS_MINX)
#define CLIP_W (VIS_MAXX - VIS_MINX + 1)
#define CLIP_H (VIS_MAXY - VIS_MINY + 1)
class halleys_state : public driver_device
{
public:
halleys_state(const machine_config &mconfig, device_type type, const char *tag) :
driver_device(mconfig, type, tag),
m_blitter_ram(*this, "blitter_ram"),
m_io_ram(*this, "io_ram"),
m_maincpu(*this, "maincpu"),
m_audiocpu(*this, "audiocpu"),
m_palette(*this, "palette"),
m_soundlatch(*this, "soundlatch")
{ }
void benberob(machine_config &config);
void halleys(machine_config &config);
void init_halley87();
void init_benberob();
void init_halleys();
void init_halleysp();
protected:
virtual void machine_start() override;
virtual void machine_reset() override;
virtual void video_start() override;
private:
std::unique_ptr<uint16_t[]> m_render_layer_alloc;
uint16_t *m_render_layer[MAX_LAYERS]{};
std::unique_ptr<uint8_t[]> m_gfx_plane_alloc;
uint8_t *m_gfx_plane02 = nullptr;
uint8_t *m_gfx_plane13 = nullptr;
std::unique_ptr<uint8_t[]> m_collision_list;
uint8_t *m_scrolly0 = nullptr;
uint8_t *m_scrollx0 = nullptr;
uint8_t *m_scrolly1 = nullptr;
uint8_t *m_scrollx1 = nullptr;
std::unique_ptr<uint32_t[]> m_internal_palette;
std::unique_ptr<uint32_t[]> m_alpha_table;
uint8_t *m_cpu1_base = nullptr;
std::unique_ptr<uint8_t[]> m_gfx1_base;
required_shared_ptr<uint8_t> m_blitter_ram;
required_shared_ptr<uint8_t> m_io_ram;
int m_game_id = 0;
int m_blitter_busy = 0;
int m_collision_count = 0;
int m_stars_enabled = 0;
int m_bgcolor = 0;
int m_ffcount = 0;
int m_ffhead = 0;
int m_fftail = 0;
int m_mVectorType = 0;
int m_sndnmi_mask = 0;
int m_firq_level = 0;
emu_timer *m_blitter_reset_timer = nullptr;
offs_t m_collision_detection = 0;
std::vector<uint8_t> m_paletteram;
void bgtile_w(offs_t offset, uint8_t data);
uint8_t blitter_status_r();
uint8_t blitter_r(offs_t offset);
void blitter_w(offs_t offset, uint8_t data);
uint8_t collision_id_r();
uint8_t paletteram_r(offs_t offset);
void paletteram_w(offs_t offset, uint8_t data);
uint8_t vector_r(offs_t offset);
void firq_ack_w(uint8_t data);
void soundcommand_w(uint8_t data);
uint8_t coin_lockout_r();
uint8_t io_mirror_r(offs_t offset);
void blit(int offset);
void sndnmi_msk_w(uint8_t data);
void halleys_palette(palette_device &palette);
uint32_t screen_update_halleys(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
uint32_t screen_update_benberob(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
TIMER_CALLBACK_MEMBER(blitter_reset);
TIMER_DEVICE_CALLBACK_MEMBER(halleys_scanline);
TIMER_DEVICE_CALLBACK_MEMBER(benberob_scanline);
void halleys_decode_rgb(uint32_t *r, uint32_t *g, uint32_t *b, int addr, int data);
void copy_scroll_op(bitmap_ind16 &bitmap, uint16_t *source, int sx, int sy);
void copy_scroll_xp(bitmap_ind16 &bitmap, uint16_t *source, int sx, int sy);
void copy_fixed_xp(bitmap_ind16 &bitmap, uint16_t *source);
void copy_fixed_2b(bitmap_ind16 &bitmap, uint16_t *source);
void filter_bitmap(bitmap_ind16 &bitmap, int mask);
void init_common();
required_device<cpu_device> m_maincpu;
required_device<cpu_device> m_audiocpu;
required_device<palette_device> m_palette;
required_device<generic_latch_8_device> m_soundlatch;
void halleys_map(address_map &map);
void sound_map(address_map &map);
};
//**************************************************************************
// MB1551x Blitter Functions
void halleys_state::blit(int offset)
{
/*
The render layers can be converted to standard MAME bitmaps but
I am not taking chances as long as the blitter has unknown draw
modes which may go beyond MAME's capability.
The function has grown tremendously as more features were added
and become rather difficult to maintain.
*/
// status attributes
#define ACTIVE 0x02
#define DECAY 0x10
#define RETIRE 0x80
// mode attributes
#define IGNORE_0 0x01
#define MODE_02 0x02
#define COLOR_ON 0x04
#define MIRROR_X 0x08
#define MIRROR_Y 0x10
#define MODE_40 0x40
#define GROUP 0x80
// color attributes
#define PENCOLOR 0x0f
#define BANKBIT1 0x80
// code attributes
#define COMMAND 0x0f
#define BGLAYER 0x10
#define BANKBIT0 0x40
#define PLANE 0x80
// special draw commands
#define EFX1 0x8 // draws to back??
#define HORIZBAR 0xe // draws 8-bit RGB horizontal bars
#define STARPASS1 0x3 // draws the stars
#define STARPASS2 0xd // modifies stars color
#define TILEPASS1 0x5 // draws tiles(s1: embedded 8-bit RGB, s2: bit-packed pixel data)
#define TILEPASS2 0xb // modifies tiles color/alpha
// user flags
#define FLIP_X 0x0100
#define FLIP_Y 0x0200
#define SINGLE_PEN 0x0400
#define RGB_MASK 0x0800
#define AD_HIGH 0x1000
#define SY_HIGH 0x2000
#define S1_IDLE 0x4000
#define S1_REV 0x8000
#define S2_IDLE 0x10000
#define S2_REV 0x20000
#define BACKMODE 0x40000
#define ALPHAMODE 0x80000
#define PPCD_ON 0x100000
// hard-wired defs and interfaces
#define HALLEYS_SPLIT 0xf4
#define COLLISION_PORTA 0x67
#define COLLISION_PORTB 0x8b
// short cuts
#define XMASK (SCREEN_WIDTH-1)
#define YMASK (SCREEN_HEIGHT-1)
static const uint8_t penxlat[16]={0x03,0x07,0x0b,0x0f,0x02,0x06,0x0a,0x0e,0x01,0x05,0x09,0x0d,0x00,0x04,0x08,0x0c};
static const uint8_t rgbmask[16]={0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0xff,0xff,0xff,0xff,0xff};
static const uint8_t tyremap[ 8]={ 0, 5, 9,13,16,20,24,28};
uint8_t *param, *src_base;
uint16_t *dst_base;
int stptr, mode, color, code, y, x, h, w, src1, src2;
int status, flags, group, command, bank, layer, pen0, pen1;
int yclip, xclip, src_yskip, src_xskip, dst_skip, hclip, wclip, src_dy, src_dx;
uint32_t *pal_ptr;
uint8_t *src1_ptr, *src2_ptr; // esi alias, ebx alias
uint16_t *dst_ptr; // edi alias
void *edi; // scratch
int eax, ebx, ecx, edx; // scratch
uint16_t ax; uint8_t al, ah; // partial regs
param = m_blitter_ram + offset;
#if HALLEYS_DEBUG
if (0) {
logerror("%s:[%04x]", machine().describe_context(), offset);
for (ecx=0; ecx<16; ecx++) logerror(" %02x", param[ecx]);
logerror("\n");
}
#endif
// init blitter controls
stptr = (int)param[0x2]<<8 | (int)param[0x3];
mode = (int)param[0x5];
color = (int)param[0x6];
code = (int)param[0x7];
// update sprite status
layer = (code>>3 & 2) | (code>>7 & 1);
offset >>= 4;
status = (stptr) ? m_cpu1_base[stptr] : ACTIVE;
flags = mode;
group = mode & GROUP;
command = code & COMMAND;
if (m_game_id == GAME_HALLEYS)
{
if (!layer) flags |= PPCD_ON;
if (offset >= HALLEYS_SPLIT) flags |= AD_HIGH; else
if (offset & 1) memcpy(param-0x10, param, 0x10); else group = param[0x15] & GROUP;
// HACK: force engine flame in group zero to increase collision accuracy
if (offset == 0x1a || offset == 0x1b) group = 0;
}
else if (offset & 1) memcpy(param-0x10, param, 0x10);
// init draw parameters
y = (int)param[0x8];
x = (int)param[0x9];
h = (int)param[0xa];
w = (int)param[0xb] + 1;
if (!h) return;
// translate source addresses
src1 = (int)param[0xc]<<8 | (int)param[0xd];
src2 = (int)param[0xe]<<8 | (int)param[0xf];
flags |= src1 & (S1_IDLE | S1_REV);
flags |= src2<<2 & (S2_IDLE | S2_REV);
src1 &= 0x3fff;
src2 &= 0x3fff;
bank = ((code & BANKBIT0) | (color & BANKBIT1)) << 8;
pal_ptr = m_internal_palette.get();
// the crossroad of fate
if (!(code & BGLAYER || command & 7))
{
// reject off-screen objects
if (flags & MIRROR_Y) { flags |= FLIP_Y; y -= (h - 1); }
if (flags & MIRROR_X) { flags |= FLIP_X; x -= (w - 1); }
if (y > VIS_MAXY || (y + h) <= VIS_MINY) return;
if (x > VIS_MAXX || (x + w) <= VIS_MINX) return;
// clip objects against the visible area
yclip = y; xclip = x; hclip = h; wclip = w;
src_yskip = src_xskip = 0;
if (yclip < VIS_MINY) { src_yskip = VIS_MINY - yclip; yclip = VIS_MINY; hclip -= src_yskip; }
if (yclip + hclip > VIS_MAXY+1) { hclip = VIS_MAXY+1 - yclip; }
if (xclip < VIS_MINX) { src_xskip = VIS_MINX - xclip; xclip = VIS_MINX; wclip -= src_xskip; }
if (xclip + wclip > VIS_MAXX+1) { wclip = VIS_MAXX+1 - xclip; }
dst_skip = (yclip << SCREEN_WIDTH_L2) + xclip;
// adjust orientations
eax = 0;
if (flags & (S1_REV | S2_REV)) { flags ^= FLIP_Y | FLIP_X; eax -= w * h - 8; }
if (flags & FLIP_Y)
{
eax += w * (h - 1);
src_yskip = -src_yskip;
src_dy = (flags & FLIP_X) ? -w + wclip : -w - wclip;
}
else src_dy = (flags & FLIP_X) ? w + wclip : w - wclip;
if (flags & FLIP_X)
{
eax += w - 1;
src_xskip = -src_xskip;
src_dx = -1;
}
else src_dx = 1;
// calculate entry points and loop constants
src1_ptr = m_gfx_plane02 + ((bank + src1)<<3) + eax;
src2_ptr = m_gfx_plane13 + ((bank + src2)<<3) + eax;
if (!(flags & (S1_IDLE | S2_IDLE)))
{
eax = src_yskip * w + src_xskip;
src1_ptr += eax;
src2_ptr += eax;
}
else src_dy = src_dx = 0;
dst_ptr = m_render_layer[layer] + dst_skip;
// look up pen values and set rendering flags
pen0 = code>>3 & 0x10;
pen1 = 0;
if (command == EFX1) { flags |= BACKMODE; pen0 |= SP_2BACK; }
if (src1 == src2)
{
flags |= SINGLE_PEN;
eax = (uint32_t)penxlat[color & PENCOLOR];
if (eax) pen1 = pen0 + eax;
}
else if (color & PENCOLOR) flags |= RGB_MASK;
//--------------------------------------------------------------------------
#define BLOCK_WIPE_COMMON { \
eax = wclip<<1; \
ecx = hclip; \
edi = dst_ptr; \
do { memset((uint8_t*)edi, 0, eax); edi = (uint8_t*)edi + SCREEN_BYTEWIDTH; } while (--ecx); \
}
//--------------------------------------------------------------------------
// multi-pen block or transparent blit
if ((flags & (SINGLE_PEN | RGB_MASK | COLOR_ON)) == COLOR_ON)
{
if (!(flags & IGNORE_0)) BLOCK_WIPE_COMMON
dst_ptr += wclip;
ecx = wclip = -wclip;
edx = src_dx;
if (!(flags & PPCD_ON))
{
al = ah = (uint8_t)pen0;
if (!(flags & BACKMODE))
{
do {
do {
al |= *src1_ptr;
src1_ptr += edx;
al |= *src2_ptr;
src2_ptr += edx;
if (al & 0xf) { dst_ptr[ecx] = (uint16_t)al; al = ah;}
}
while (++ecx);
ecx = wclip; src1_ptr += src_dy; src2_ptr += src_dy; dst_ptr += SCREEN_WIDTH;
}
while (--hclip);
}
else
{
do {
do {
al |= *src1_ptr;
src1_ptr += edx;
al |= *src2_ptr;
src2_ptr += edx;
if (al & 0xf) { dst_ptr[ecx] = (uint16_t)al | SP_2BACK; al = ah; }
}
while (++ecx);
ecx = wclip; src1_ptr += src_dy; src2_ptr += src_dy; dst_ptr += SCREEN_WIDTH;
}
while (--hclip);
}
return;
}
ax = 0;
if (group)
{
do {
do {
al = *src1_ptr;
src1_ptr += edx;
al |= *src2_ptr;
src2_ptr += edx;
if (al & 0xf) { dst_ptr[ecx] = (uint16_t)al | SP_COLLD; } // set collision flag on group one pixels
}
while (++ecx);
ecx = wclip; src1_ptr += src_dy; src2_ptr += src_dy; dst_ptr += SCREEN_WIDTH;
}
while (--hclip);
}
else
{
do {
do {
al = *src1_ptr;
src1_ptr += edx;
al |= *src2_ptr;
src2_ptr += edx;
if (al & 0xf) { ax |= dst_ptr[ecx]; dst_ptr[ecx] = (uint16_t)al; } // combine collision flags in ax
}
while (++ecx);
ecx = wclip; src1_ptr += src_dy; src2_ptr += src_dy; dst_ptr += SCREEN_WIDTH;
}
while (--hclip);
}
// update collision list if object collided with the other group
if (status & ACTIVE && ax & SP_COLLD)
{
m_collision_list[m_collision_count & (MAX_SPRITES-1)] = offset;
m_collision_count++;
#if HALLEYS_DEBUG
popmessage("ID:%02x CC:%3d", offset, m_collision_count);
#endif
}
} else
//--------------------------------------------------------------------------
// multi-pen, RGB masked block or transparent blit
if ((flags & (RGB_MASK | COLOR_ON)) == RGB_MASK + COLOR_ON)
{
if (!(flags & IGNORE_0)) BLOCK_WIPE_COMMON
dst_ptr += wclip;
ecx = wclip = -wclip;
al = ah = (uint8_t)pen0;
ebx = rgbmask[color & PENCOLOR] | 0xffffff00;
do {
do {
al |= *src1_ptr;
src1_ptr += src_dx;
al |= *src2_ptr;
src2_ptr += src_dx;
if (al & 0xf) { edx = (uint32_t)al; al = ah; dst_ptr[ecx] = pal_ptr[edx] & ebx; }
}
while (++ecx);
ecx = wclip; src1_ptr += src_dy; src2_ptr += src_dy; dst_ptr += SCREEN_WIDTH;
}
while (--hclip);
} else
//--------------------------------------------------------------------------
// single-pen block or transparent blit
if ((flags & (SINGLE_PEN | COLOR_ON)) == SINGLE_PEN + COLOR_ON)
{
if (!(flags & IGNORE_0)) BLOCK_WIPE_COMMON
dst_ptr += wclip;
ebx = hclip;
ecx = wclip = -wclip;
edx = src_dx;
ax = (uint16_t)pen1;
do {
do {
if (*src1_ptr) dst_ptr[ecx] = ax;
src1_ptr += edx;
}
while (++ecx);
ecx = wclip;
src1_ptr += src_dy;
dst_ptr += SCREEN_WIDTH;
}
while (--ebx);
} else
//--------------------------------------------------------------------------
// transparent wipe
if ((flags & (IGNORE_0 | COLOR_ON)) == IGNORE_0)
{
dst_ptr += wclip;
wclip = -wclip;
ecx = wclip;
edx = src_dx;
if (flags & PPCD_ON && !group)
{
// preserve collision flags when wiping group zero objects
do {
do {
al = *src1_ptr;
ah = *src2_ptr;
src1_ptr += edx;
src2_ptr += edx;
if (al | ah) dst_ptr[ecx] &= SP_COLLD;
}
while (++ecx);
ecx = wclip;
src1_ptr += src_dy;
src2_ptr += src_dy;
dst_ptr += SCREEN_WIDTH;
}
while (--hclip);
}
else
{
do {
do {
al = *src1_ptr;
ah = *src2_ptr;
src1_ptr += edx;
src2_ptr += edx;
if (al | ah) dst_ptr[ecx] = 0;
}
while (++ecx);
ecx = wclip;
src1_ptr += src_dy;
src2_ptr += src_dy;
dst_ptr += SCREEN_WIDTH;
}
while (--hclip);
}
} else
//--------------------------------------------------------------------------
// block wipe
if ((flags & (IGNORE_0 | COLOR_ON)) == 0) BLOCK_WIPE_COMMON
//--------------------------------------------------------------------------
// End of Standard Mode
return;
//--------------------------------------------------------------------------
}
#define GFX_HI 0x10000
// reject illegal blits and adjust parameters
if (command)
{
if (h > 8) return;
if (y >= 0xf8) { y -= 0xf8; flags |= SY_HIGH; } else
if (y >= 8) return;
if (command != TILEPASS1) { h <<= 5; y <<= 5; }
}
// calculate entry points and loop constants
if (flags & S1_IDLE) src_dx = 0; else src_dx = 1;
if (flags & S1_REV ) src_dx = -src_dx;
src_base = m_gfx1_base.get() + bank;
if (command == STARPASS1 || command == STARPASS2) layer = (layer & 1) + 4;
dst_base = m_render_layer[layer];
//--------------------------------------------------------------------------
#define WARP_WIPE_COMMON { \
ebx = y + h; \
ecx = (x + w - SCREEN_WIDTH) << 1; \
for (edx=y; edx<ebx; edx++) { \
dst_ptr = dst_base + ((edx & YMASK) << SCREEN_WIDTH_L2); \
if (ecx > 0) { memset(dst_ptr, 0, ecx); eax = SCREEN_WIDTH - x; } else eax = w; \
memset(dst_ptr+x, 0, eax<<1); \
} \
}
//--------------------------------------------------------------------------
// specialized block wipe
if ((flags & (IGNORE_0 | COLOR_ON)) == 0)
{
// wipe star layer when the following conditions are met:
if (!command && y == 0xff && h == 1)
{
y = 0; h = SCREEN_HEIGHT;
dst_base = m_render_layer[(layer&1)+4];
WARP_WIPE_COMMON
m_stars_enabled = ~layer & 1;
}
// wipe background and chain-wipe corresponding sprite layer when the command is zero
else
{
WARP_WIPE_COMMON
if (!command) { dst_base = m_render_layer[layer&1]; WARP_WIPE_COMMON }
}
} else
//--------------------------------------------------------------------------
// gray shaded star map with 16x16 cells
if (command == STARPASS1 && flags & COLOR_ON)
{
/*
Each star map is generated by two data sets pointed by the second source
address. The first 256-byte set has scattered bits to reflect the star
population while the second 256-byte set appears to have random values.
When the game runs the star fields are updated a small portion at a time
by a third data set containing gradient patterns which may indicate gray
shades or alpha levels.
Halley's Comet draws and clears the two star fields as if they are
independent from the backgrounds, making it a total of four scrollable
layers. However, only two pairs of scroll registers are in use and they
affect the stars and the backgrounds together - possibly afterthoughts
on the original Ben Bero Beh hardware.
This algorithm is based on speculation and deemed inaccurate.
*/
#define RORB(R,N) ( ((R>>N)|(R<<(8-N))) & 0xff )
#define C2S(X,Y,O) ( (((Y+(O>>4))&YMASK)<<SCREEN_WIDTH_L2) + ((X+(O&0xf))&XMASK) )
src2_ptr = src_base + src2 + GFX_HI;
for (yclip=y+h; y<yclip; y+=16)
for (xclip=x+w; x<xclip; x+=16)
{
edx = (uint32_t)*src2_ptr;
src2_ptr++;
if (edx)
{
ax = (uint16_t)*(src2_ptr-0x100 -1);
ebx = (uint32_t)ax;
ax |= BG_MONO;
if (edx & 0x01) { dst_base[C2S(x,y,ebx)] = ax; }
if (edx & 0x02) { ecx = RORB(ebx,1); dst_base[C2S(x,y,ecx)] = ax; }
if (edx & 0x04) { ecx = RORB(ebx,2); dst_base[C2S(x,y,ecx)] = ax; }
if (edx & 0x08) { ecx = RORB(ebx,3); dst_base[C2S(x,y,ecx)] = ax; }
if (edx & 0x10) { ecx = RORB(ebx,4); dst_base[C2S(x,y,ecx)] = ax; }
if (edx & 0x20) { ecx = RORB(ebx,5); dst_base[C2S(x,y,ecx)] = ax; }
if (edx & 0x40) { ecx = RORB(ebx,6); dst_base[C2S(x,y,ecx)] = ax; }
if (edx & 0x80) { ecx = RORB(ebx,7); dst_base[C2S(x,y,ecx)] = ax; }
}
}
m_stars_enabled = layer & 1;
#undef RORB
#undef C2S
} else
//--------------------------------------------------------------------------
// stars color modifier
if (command == STARPASS2 && flags & COLOR_ON)
{
edx = SCREEN_WIDTH - x - w;
w = -w;
ax = (uint16_t)(~src_base[src2] & 0xff);
for (yclip=y+h; y<yclip; y++)
{
edi = dst_base + ((y & YMASK) << SCREEN_WIDTH_L2);
if (edx < 0)
{
ecx = edx;
dst_ptr = (uint16_t*)edi - edx;
do { if (dst_ptr[ecx]) dst_ptr[ecx] ^= ax; } while (++ecx);
ecx = x - SCREEN_WIDTH;
} else ecx = w;
dst_ptr = (uint16_t*)edi + x - ecx;
do { if (dst_ptr[ecx]) dst_ptr[ecx] ^= ax; } while (++ecx);
}
} else
//--------------------------------------------------------------------------
// RGB 8x8 bit-packed transparent tile
if (command == TILEPASS1 && flags & COLOR_ON)
{
/*
Tile positioning in this mode is very cryptic and different from
others. The coordinate system seems banked and influenced by layer
number and whether the blit code is written to the upper or lower
off-screen area. These conditions may also imply height-doubling,
Y-flipping and draw-from-bottom attributes.
Pixel and color information is embedded but the game draws a
second pass at the same location with zeroes. In addition the
X and Y values passed to the blitter do not reflect the tiles true
locations. For example, tiles near the top or bottom of the screen
are positioned reasonably close but those in the middle are oddly
shifted toward either side. The tiles also resemble predefined
patterns but I don't know if there are supposed to be lookup tables
in ROM or hard-wired to the blitter chips.
*/
if (y & 1) x -= 8;
y = tyremap[y] << 3;
if (flags & SY_HIGH) y += 8;
if (y > 0xf8) return;
if (code & PLANE) return; /* WARNING: UNEMULATED */
if (flags & IGNORE_0) { w=8; h=8; WARP_WIPE_COMMON }
src1_ptr = src_base + src1;
dst_ptr = m_render_layer[2] + (y << SCREEN_WIDTH_L2);
src1_ptr += 8;
edx = -8;
if (x <= 0xf8)
{
dst_ptr += x;
do {
ax = (uint16_t)src1_ptr[edx];
al = src1_ptr[edx+0x10000];
ax |= BG_RGB;
if (al & 0x01) *dst_ptr = ax;
if (al & 0x02) dst_ptr[1] = ax;
if (al & 0x04) dst_ptr[2] = ax;
if (al & 0x08) dst_ptr[3] = ax;
if (al & 0x10) dst_ptr[4] = ax;
if (al & 0x20) dst_ptr[5] = ax;
if (al & 0x40) dst_ptr[6] = ax;
if (al & 0x80) dst_ptr[7] = ax;
dst_ptr += SCREEN_WIDTH;
} while (++edx);
}
else
{
#define WARPMASK ((SCREEN_WIDTH<<1)-1)
do {
ecx = x & WARPMASK;
ax = (uint16_t)src1_ptr[edx];
al = src1_ptr[edx+0x10000];
ax |= BG_RGB;
if (al & 0x01) dst_ptr[ecx] = ax;
ecx++; ecx &= WARPMASK;
if (al & 0x02) dst_ptr[ecx] = ax;
ecx++; ecx &= WARPMASK;
if (al & 0x04) dst_ptr[ecx] = ax;
ecx++; ecx &= WARPMASK;
if (al & 0x08) dst_ptr[ecx] = ax;
ecx++; ecx &= WARPMASK;
if (al & 0x10) dst_ptr[ecx] = ax;
ecx++; ecx &= WARPMASK;
if (al & 0x20) dst_ptr[ecx] = ax;
ecx++; ecx &= WARPMASK;
if (al & 0x40) dst_ptr[ecx] = ax;
ecx++; ecx &= WARPMASK;
if (al & 0x80) dst_ptr[ecx] = ax;
dst_ptr += SCREEN_WIDTH;
} while (++edx);
#undef WARPMASK
}
} else
//--------------------------------------------------------------------------
// RGB horizontal bar(foreground only)
if (command == HORIZBAR && flags & COLOR_ON && !(layer & 1))
{
#define WARP_LINE_COMMON { \
if (ecx & 1) { ecx--; *dst_ptr = (uint16_t)eax; dst_ptr++; } \
dst_ptr += ecx; ecx = -ecx; \
while (ecx) { *(uint32_t*)(dst_ptr+ecx) = eax; ecx += 2; } \
}
src1_ptr = src_base + src1;
src2_ptr = src_base + src2;
hclip = y + h;
if (!(flags & S2_IDLE))
{
// double source mode
src2_ptr += GFX_HI;
wclip = x + w;
w = 32;
}
else
{
// single source mode
if (color & 4) src1_ptr += GFX_HI;
wclip = 32;
}
for (xclip=x; xclip<wclip; xclip+=32)
{
xclip &= XMASK;
edx = xclip + w - SCREEN_WIDTH;
for (yclip=y; yclip<hclip; yclip++)
{
eax = (uint32_t)*src1_ptr;
src1_ptr += src_dx;
if (!eax) continue;