/
avgdvg.cpp
1504 lines (1249 loc) · 30.4 KB
/
avgdvg.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:Mathis Rosenhauer
// thanks-to:Eric Smith, Brad Oliver, Bernd Wiebelt, Aaron Giles, Andrew Caldwell
/*************************************************************************
avgdvg.c: Atari DVG and AVG
Some parts of this code are based on the original version by Eric
Smith, Brad Oliver, Bernd Wiebelt, Aaron Giles, Andrew Caldwell
The schematics and Jed Margolin's article on Vector Generators were
very helpful in understanding the hardware.
**************************************************************************/
#include "emu.h"
#include "avgdvg.h"
#include "screen.h"
/*************************************
*
* Macros and defines
*
*************************************/
#define MASTER_CLOCK (12096000)
#define VGSLICE (10000)
#define VGVECTOR 0
#define VGCLIP 1
/*************************************
*
* Flipping
*
*************************************/
void avgdvg_device_base::apply_flipping(int &x, int &y) const
{
if (m_flip_x)
x += (m_xcenter - x) << 1;
if (m_flip_y)
y += (m_ycenter - y) << 1;
}
/*************************************
*
* Vector buffering
*
*************************************/
void avgdvg_device_base::vg_flush()
{
int cx0 = 0, cy0 = 0, cx1 = 0x5000000, cy1 = 0x5000000;
int i = 0;
while (m_vectbuf[i].status == VGCLIP)
i++;
int xs = m_vectbuf[i].x;
int ys = m_vectbuf[i].y;
for (i = 0; i < m_nvect; i++)
{
if (m_vectbuf[i].status == VGVECTOR)
{
int xe = m_vectbuf[i].x;
int ye = m_vectbuf[i].y;
int x0 = xs, y0 = ys, x1 = xe, y1 = ye;
xs = xe;
ys = ye;
if ((x0 < cx0 && x1 < cx0) || (x0 > cx1 && x1 > cx1))
continue;
if (x0 < cx0)
{
y0 += s64(cx0 - x0) * s64(y1 - y0) / (x1 - x0);
x0 = cx0;
}
else if (x0 > cx1)
{
y0 += s64(cx1 - x0) * s64(y1 - y0) / (x1 - x0);
x0 = cx1;
}
if (x1 < cx0)
{
y1 += s64(cx0 - x1) * s64(y1 - y0) / (x1 - x0);
x1 = cx0;
}
else if (x1 > cx1)
{
y1 += s64(cx1 - x1) * s64(y1 - y0) / (x1 - x0);
x1 = cx1;
}
if ((y0 < cy0 && y1 < cy0) || (y0 > cy1 && y1 > cy1))
continue;
if (y0 < cy0)
{
x0 += s64(cy0 - y0) * s64(x1 - x0) / (y1 - y0);
y0 = cy0;
}
else if (y0 > cy1)
{
x0 += s64(cy1 - y0) * s64(x1 - x0) / (y1 - y0);
y0 = cy1;
}
if (y1 < cy0)
{
x1 += s64(cy0 - y1) * s64(x1 - x0) / (y1 - y0);
y1 = cy0;
}
else if (y1 > cy1)
{
x1 += s64(cy1 - y1) * s64(x1 - x0) / (y1 - y0);
y1 = cy1;
}
m_vector->add_point(x0, y0, m_vectbuf[i].color, 0);
m_vector->add_point(x1, y1, m_vectbuf[i].color, m_vectbuf[i].intensity);
}
if (m_vectbuf[i].status == VGCLIP)
{
cx0 = m_vectbuf[i].x;
cy0 = m_vectbuf[i].y;
cx1 = m_vectbuf[i].arg1;
cy1 = m_vectbuf[i].arg2;
using std::swap;
if (cx0 > cx1)
swap(cx0, cx1);
if (cy0 > cy1)
swap(cy0, cy1);
}
}
m_nvect = 0;
}
void avgdvg_device_base::vg_add_point_buf(int x, int y, rgb_t color, int intensity)
{
if (m_nvect < MAXVECT)
{
m_vectbuf[m_nvect].status = VGVECTOR;
m_vectbuf[m_nvect].x = x;
m_vectbuf[m_nvect].y = y;
m_vectbuf[m_nvect].color = color;
m_vectbuf[m_nvect].intensity = intensity;
m_nvect++;
}
}
void avgdvg_device_base::vg_add_clip(int xmin, int ymin, int xmax, int ymax)
{
if (m_nvect < MAXVECT)
{
m_vectbuf[m_nvect].status = VGCLIP;
m_vectbuf[m_nvect].x = xmin;
m_vectbuf[m_nvect].y = ymin;
m_vectbuf[m_nvect].arg1 = xmax;
m_vectbuf[m_nvect].arg2 = ymax;
m_nvect++;
}
}
/*************************************
*
* DVG handler functions
*
*************************************/
void dvg_device::update_databus() // dvg_data
{
// DVG uses low bit of state for address
m_data = m_memspace->read_byte(m_membase + (m_pc << 1) + (m_state_latch & 1));
}
u8 dvg_device::state_addr() // dvg_state_addr
{
u8 addr = ((((m_state_latch >> 4) ^ 1) & 1) << 7) | (m_state_latch & 0xf);
if (OP3())
addr |= ((m_op & 7) << 4);
return addr;
}
int dvg_device::handler_0() // dvg_dmapush
{
if (!OP0())
{
m_sp = (m_sp + 1) & 0xf;
m_stack[m_sp & 3] = m_pc;
}
return 0;
}
int dvg_device::handler_1() // dvg_dmald
{
if (OP0())
{
m_pc = m_stack[m_sp & 3];
m_sp = (m_sp - 1) & 0xf;
}
else
{
m_pc = m_dvy;
}
return 0;
}
void dvg_device::dvg_draw_to(int x, int y, int intensity)
{
apply_flipping(x, y);
if (!((x | y) & 0x400))
vg_add_point_buf(
(m_xmin + x - 512) << 16,
(m_ymin + 512 - y) << 16,
vector_device::color111(7),
intensity << 4);
}
int dvg_device::handler_2() //dvg_gostrobe
{
int scale;
if (m_op == 0xf)
{
scale = (m_scale +
(((m_dvy & 0x800) >> 11)
| (((m_dvx & 0x800) ^ 0x800) >> 10)
| ((m_dvx & 0x800) >> 9))) & 0xf;
m_dvy &= 0xf00;
m_dvx &= 0xf00;
}
else
{
scale = (m_scale + m_op) & 0xf;
}
int fin = 0xfff - (((2 << scale) & 0x7ff) ^ 0xfff);
// Count up or down
const int dx = (m_dvx & 0x400) ? -1 : +1;
const int dy = (m_dvy & 0x400) ? -1 : +1;
// Scale factor for rate multipliers
const int mx = (m_dvx << 2) & 0xfff;
const int my = (m_dvy << 2) & 0xfff;
const int cycles = 8 * fin;
int c = 0;
while (fin--)
{
/*
* The 7497 Bit Rate Multiplier is a 6 bit counter with
* clever decoding of output bits to perform the following
* operation:
*
* fout = m/64 * fin
*
* where fin is the input frequency, fout is the output
* frequency and m is a factor at the input pins. Output
* pulses are more or less evenly spaced so we get straight
* lines. The DVG has two cascaded 7497s for each coordinate.
*/
int countx = 0;
int county = 0;
for (int bit = 0; bit < 12; bit++)
{
if ((c & ((1 << (bit+1)) - 1)) == ((1 << bit) - 1))
{
if (mx & (1 << (11 - bit)))
countx = 1;
if (my & (1 << (11 - bit)))
county = 1;
}
}
c = (c + 1) & 0xfff;
/*
* Since x- and y-counters always hold the correct count
* wrt. to each other, we can do clipping exactly like the
* hardware does. That is, as soon as any counter's bit 10
* changes to high, we finish the vector. If bit 10 changes
* from high to low, we start a new vector.
*/
if (countx)
{
// Is y valid and x entering or leaving the valid range?
if (!(m_ypos & 0x400) && ((m_xpos ^ (m_xpos + dx)) & 0x400))
{
if ((m_xpos + dx) & 0x400) // We are leaving the valid range
dvg_draw_to(m_xpos, m_ypos, m_intensity);
else // We are entering the valid range
dvg_draw_to((m_xpos + dx) & 0xfff, m_ypos, 0);
}
m_xpos = (m_xpos + dx) & 0xfff;
}
if (county)
{
if (!(m_xpos & 0x400) && ((m_ypos ^ (m_ypos + dy)) & 0x400))
{
if (!(m_xpos & 0x400))
{
if ((m_ypos + dy) & 0x400)
dvg_draw_to(m_xpos, m_ypos, m_intensity);
else
dvg_draw_to(m_xpos, (m_ypos + dy) & 0xfff, 0);
}
}
m_ypos = (m_ypos + dy) & 0xfff;
}
}
dvg_draw_to(m_xpos, m_ypos, m_intensity);
return cycles;
}
int dvg_device::handler_3() // dvg_haltstrobe
{
m_halt = OP0();
if (!OP0())
{
m_xpos = m_dvx & 0xfff;
m_ypos = m_dvy & 0xfff;
dvg_draw_to(m_xpos, m_ypos, 0);
}
return 0;
}
int dvg_device::handler_7() // dvg_latch3
{
m_dvx = (m_dvx & 0xff) | ((m_data & 0xf) << 8);
m_intensity = m_data >> 4;
return 0;
}
int dvg_device::handler_6() // dvg_latch2
{
m_dvx &= 0xf00;
if (m_op != 0xf)
m_dvx = (m_dvx & 0xf00) | m_data;
if (OP1() && OP3())
m_scale = m_intensity;
m_pc++;
return 0;
}
int dvg_device::handler_5() // dvg_latch1
{
m_dvy = (m_dvy & 0xff) | ((m_data & 0xf) << 8);
m_op = m_data >> 4;
if (m_op == 0xf)
{
m_dvx &= 0xf00;
m_dvy &= 0xf00;
}
return 0;
}
int dvg_device::handler_4() // dvg_latch0
{
m_dvy &= 0xf00;
if (m_op == 0xf)
handler_7(); //dvg_latch3
else
m_dvy = (m_dvy & 0xf00) | m_data;
m_pc++;
return 0;
}
void dvg_device::vggo() // dvg_vggo
{
m_dvy = 0;
m_op = 0;
}
void dvg_device::vgrst() // dvg_vgrst
{
m_state_latch = 0;
m_dvy = 0;
m_op = 0;
}
/********************************************************************
*
* AVG handler functions
*
* AVG is in many ways different from DVG. The only thing they have
* in common is the state machine approach. There are small
* differences among the AVGs, mostly related to color and vector
* clipping.
*
*******************************************************************/
u8 avg_device::state_addr() // avg_state_addr
{
return (((m_state_latch >> 4) ^ 1) << 7)
| (m_op << 4)
| (m_state_latch & 0xf);
}
void avg_device::update_databus() // avg_data
{
m_data = m_memspace->read_byte(m_membase + (m_pc ^ 1));
}
void avg_device::vggo() // avg_vggo
{
m_pc = 0;
m_sp = 0;
}
void avg_device::vgrst() // avg_vgrst
{
m_state_latch = 0;
m_bin_scale = 0;
m_scale = 0;
m_color = 0;
}
int avg_device::handler_0() // avg_latch0
{
m_dvy = (m_dvy & 0x1f00) | m_data;
m_pc++;
return 0;
}
int avg_device::handler_1() // avg_latch1
{
m_dvy12 = (m_data >> 4) & 1;
m_op = m_data >> 5;
m_int_latch = 0;
m_dvy = (m_dvy12 << 12) | ((m_data & 0xf) << 8);
m_dvx = 0;
m_pc++;
return 0;
}
int avg_device::handler_2() // avg_latch2
{
m_dvx = (m_dvx & 0x1f00) | m_data;
m_pc++;
return 0;
}
int avg_device::handler_3() // avg_latch3
{
m_int_latch = m_data >> 4;
m_dvx = ((m_int_latch & 1) << 12)
| ((m_data & 0xf) << 8)
| (m_dvx & 0xff);
m_pc++;
return 0;
}
int avg_device::handler_4() // avg_strobe0
{
if (OP0())
{
m_stack[m_sp & 3] = m_pc;
}
else
{
/*
* Normalization is done to get roughly constant deflection
* speeds. See Jed's essay why this is important. In addition
* to the intensity and overall time saving issues it is also
* needed to avoid accumulation of DAC errors. The X/Y DACs
* only use bits 3-12. The normalization ensures that the
* first three bits hold no important information.
*
* The circuit doesn't check for dvx=dvy=0. In this case
* shifting goes on as long as VCTR, SCALE and CNTR are
* low. We cut off after 16 shifts.
*/
int i = 0;
while ((((m_dvy ^ (m_dvy << 1)) & 0x1000) == 0)
&& (((m_dvx ^ (m_dvx << 1)) & 0x1000) == 0)
&& (i++ < 16))
{
m_dvy = (m_dvy & 0x1000) | ((m_dvy << 1) & 0x1fff);
m_dvx = (m_dvx & 0x1000) | ((m_dvx << 1) & 0x1fff);
m_timer >>= 1;
m_timer |= 0x4000 | (OP1() << 7);
}
if (OP1())
m_timer &= 0xff;
}
return 0;
}
int avg_device::avg_common_strobe1()
{
if (OP2())
{
if (OP1())
m_sp = (m_sp - 1) & 0xf;
else
m_sp = (m_sp + 1) & 0xf;
}
return 0;
}
int avg_device::handler_5() // avg_strobe1
{
if (!OP2())
{
for (int i = m_bin_scale; i > 0; i--)
{
m_timer >>= 1;
m_timer |= 0x4000 | (OP1() << 7);
}
if (OP1())
m_timer &= 0xff;
}
return avg_common_strobe1();
}
int avg_device::avg_common_strobe2()
{
if (OP2())
{
if (OP0())
{
m_pc = m_dvy << 1;
if (m_dvy == 0)
{
/*
* Tempest and Quantum keep the AVG in an endless
* loop. I.e. at one point the AVG jumps to address 0
* and starts over again. The main CPU updates vector
* RAM while AVG is running. The hardware takes care
* that the AVG doesn't read vector RAM while the CPU
* writes to it. Usually we wait until the AVG stops
* (halt flag) and then draw all vectors at once. This
* doesn't work for Tempest and Quantum so we wait for
* the jump to zero and draw vectors then.
*
* Note that this has nothing to do with the real hardware
* because for a vector monitor it is perfectly okay to
* have the AVG drawing all the time. In the emulation we
* somehow have to divide the stream of vectors into
* 'frames'.
*/
m_vector->clear_list();
vg_flush();
}
}
else
{
m_pc = m_stack[m_sp & 3];
}
}
else
{
if (m_dvy12)
{
m_scale = m_dvy & 0xff;
m_bin_scale = (m_dvy >> 8) & 7;
}
}
return 0;
}
int avg_device::handler_6() // avg_strobe2
{
if (!OP2() && !m_dvy12)
{
m_color = m_dvy & 0x7;
m_intensity = (m_dvy >> 4) & 0xf;
}
return avg_common_strobe2();
}
int avg_device::avg_common_strobe3()
{
int cycles = 0;
m_halt = OP0();
if (!OP0() && !OP2())
{
if (OP1())
{
cycles = 0x100 - (m_timer & 0xff);
}
else
{
cycles = 0x8000 - m_timer;
}
m_timer = 0;
m_xpos += ((((m_dvx >> 3) ^ m_xdac_xor) - 0x200) * cycles * (m_scale ^ 0xff)) >> 4;
m_ypos -= ((((m_dvy >> 3) ^ m_ydac_xor) - 0x200) * cycles * (m_scale ^ 0xff)) >> 4;
}
if (OP2())
{
cycles = 0x8000 - m_timer;
m_timer = 0;
m_xpos = m_xcenter;
m_ypos = m_ycenter;
vg_add_point_buf(m_xpos, m_ypos, 0, 0);
}
return cycles;
}
int avg_device::handler_7() // avg_strobe3
{
const int cycles = avg_common_strobe3();
if (!OP0() && !OP2())
{
int x = m_xpos;
int y = m_ypos;
apply_flipping(x, y);
vg_add_point_buf(
x,
y,
vector_device::color111(m_color),
(((m_int_latch >> 1) == 1) ? m_intensity : m_int_latch & 0xe) << 4);
}
return cycles;
}
/*************************************
*
* Tempest handler functions
*
*************************************/
int avg_tempest_device::handler_6() // tempest_strobe2
{
if (!OP2() && !m_dvy12)
{
// Contrary to previous documentation in MAME, Tempest does not have the m_enspkl bit.
if (m_dvy & 0x800)
m_color = m_dvy & 0xf;
else
m_intensity = (m_dvy >> 4) & 0xf;
}
return avg_common_strobe2();
}
int avg_tempest_device::handler_7() // tempest_strobe3
{
const int cycles = avg_common_strobe3();
if (!OP0() && !OP2())
{
const u8 data = m_colorram[m_color];
const u8 bit3 = BIT(~data, 3);
const u8 bit2 = BIT(~data, 2);
const u8 bit1 = BIT(~data, 1);
const u8 bit0 = BIT(~data, 0);
const u8 r = bit1 * 0xf3 + bit0 * 0x0c;
const u8 g = bit3 * 0xf3;
const u8 b = bit2 * 0xf3;
int x = m_xpos;
int y = m_ypos;
apply_flipping(x, y);
vg_add_point_buf(
y - m_ycenter + m_xcenter,
x - m_xcenter + m_ycenter,
rgb_t(r, g, b),
(((m_int_latch >> 1) == 1) ? m_intensity : m_int_latch & 0xe) << 4);
}
return cycles;
}
#if 0
void avg_tempest_device::vggo() // tempest_vggo
{
m_pc = 0;
m_sp = 0;
/*
* Tempest and Quantum trigger VGGO from time to time even though
* the VG runs in an endless loop for these games (see
* avg_common_strobe2). If we don't discard all vectors in the
* current buffer at this point, the screen starts flickering.
*/
m_nvect = 0;
}
#endif
/*************************************
*
* Mhavoc handler functions
*
*************************************/
int avg_mhavoc_device::handler_1() // mhavoc_latch1
{
// Major Havoc just has ymin clipping
if (!m_lst)
vg_add_clip(0, m_ypos, m_xmax << 16, m_ymax << 16);
m_lst = 1;
return avg_device::handler_1(); //avg_latch1()
}
int avg_mhavoc_device::handler_6() // mhavoc_strobe2
{
if (!OP2())
{
if (m_dvy12)
{
if (m_dvy & 0x800)
m_lst = 0;
}
else
{
m_color = m_dvy & 0xf;
m_intensity = (m_dvy >> 4) & 0xf;
m_map = (m_dvy >> 8) & 0x3;
if (m_dvy & 0x800)
{
m_enspkl = 1;
// sparkle LFSR bits 4,5,6 here come from alpha CPU address bus bits 0,1,2, they're not truly random.
m_spkl_shift = bitswap<4>(m_dvy, 0, 1, 2, 3) | ((machine().rand() & 0x7) << 4);
}
else
{
m_enspkl = 0;
}
// Major Havoc can do X-flipping by inverting the DAC input
if (m_dvy & 0x400)
m_xdac_xor = 0x1ff;
else
m_xdac_xor = 0x200;
}
}
return avg_common_strobe2();
}
int avg_mhavoc_device::handler_7() // mhavoc_strobe3
{
m_halt = OP0();
int cycles = 0;
if (!OP0() && !OP2())
{
if (OP1())
{
cycles = 0x100 - (m_timer & 0xff);
}
else
{
cycles = 0x8000 - m_timer;
}
m_timer = 0;
const int dx = ((((m_dvx >> 3) ^ m_xdac_xor) - 0x200) * (m_scale ^ 0xff));
const int dy = ((((m_dvy >> 3) ^ m_ydac_xor) - 0x200) * (m_scale ^ 0xff));
if (m_enspkl)
{
for (int i = 0; i < cycles / 8; i++)
{
m_xpos += dx / 2;
m_ypos -= dy / 2;
const u8 data = m_colorram[0xf + bitswap<4>(m_spkl_shift, 0, 2, 4, 6)];
const u8 bit3 = BIT(~data, 3);
const u8 bit2 = BIT(~data, 2);
const u8 bit1 = BIT(~data, 1);
const u8 bit0 = BIT(~data, 0);
const u8 r = bit3 * 0xcb + bit2 * 0x34;
const u8 g = bit1 * 0xcb;
const u8 b = bit0 * 0xcb;
int x = m_xpos;
int y = m_ypos;
apply_flipping(x, y);
vg_add_point_buf(
x,
y,
rgb_t(r, g, b),
(((m_int_latch >> 1) == 1) ? m_intensity : m_int_latch & 0xe) << 4);
m_spkl_shift = (BIT(m_spkl_shift, 6) ^ BIT(m_spkl_shift, 5) ^ 1) | (m_spkl_shift << 1);
if ((m_spkl_shift & 0x7f) == 0x7f)
m_spkl_shift = 0;
}
}
else
{
m_xpos += (dx * cycles) >> 4;
m_ypos -= (dy * cycles) >> 4;
const u8 data = m_colorram[m_color];
const u8 bit3 = BIT(~data, 3);
const u8 bit2 = BIT(~data, 2);
const u8 bit1 = BIT(~data, 1);
const u8 bit0 = BIT(~data, 0);
const u8 r = bit3 * 0xcb + bit2 * 0x34;
const u8 g = bit1 * 0xcb;
const u8 b = bit0 * 0xcb;
int x = m_xpos;
int y = m_ypos;
apply_flipping(x, y);
vg_add_point_buf(
x,
y,
rgb_t(r, g, b),
(((m_int_latch >> 1) == 1) ? m_intensity : m_int_latch & 0xe) << 4);
}
}
if (OP2())
{
cycles = 0x8000 - m_timer;
m_timer = 0;
m_xpos = m_xcenter;
m_ypos = m_ycenter;
vg_add_point_buf(m_xpos, m_ypos, 0, 0);
}
return cycles;
}
void avg_mhavoc_device::update_databus() // mhavoc_data
{
if (m_pc & 0x2000)
m_data = m_bank_region[(m_map << 13) | ((m_pc ^ 1) & 0x1fff)];
else
m_data = m_memspace->read_byte(m_membase + (m_pc ^ 1));
}
void avg_mhavoc_device::vgrst() // mhavoc_vgrst
{
avg_device::vgrst(); // avg_vgrst
m_enspkl = 0;
}
/*************************************
*
* Starwars handler functions
*
*************************************/
void avg_starwars_device::update_databus() // starwars_data
{
// Avoid interfering with the slapstic
auto dis = machine().disable_side_effects();
m_data = m_memspace->read_byte(m_membase + m_pc);
}
int avg_starwars_device::handler_6() // starwars_strobe2
{
if (!OP2() && !m_dvy12)
{
m_intensity = m_dvy & 0xff;
m_color = (m_dvy >> 8) & 0xf;
}
return avg_common_strobe2();
}
int avg_starwars_device::handler_7() // starwars_strobe3
{
const int cycles = avg_common_strobe3();
if (!OP0() && !OP2())
{
vg_add_point_buf(
m_xpos,
m_ypos,
vector_device::color111(m_color),
((m_int_latch >> 1) * m_intensity) >> 3);
}
return cycles;
}
/*************************************
*
* Quantum handler functions
*
*************************************/
void avg_quantum_device::update_databus() // quantum_data
{
m_data = m_memspace->read_word(m_membase + m_pc);
}
void avg_quantum_device::vggo() // tempest_vggo
{
m_pc = 0;
m_sp = 0;
/*
* Tempest and Quantum trigger VGGO from time to time even though
* the VG runs in an endless loop for these games (see
* avg_common_strobe2). If we don't discard all vectors in the
* current buffer at this point, the screen starts flickering.
*/
m_nvect = 0;
}
int avg_quantum_device::handler_0() // quantum_st2st3
{
/* Quantum doesn't decode latch0 or latch2 but ST2 and ST3 are fed
* into the address controller which increments the PC
*/
m_pc++;
return 0;
}
int avg_quantum_device::handler_1() // quantum_latch1
{
m_dvy = m_data & 0x1fff;
m_dvy12 = (m_data >> 12) & 1;
m_op = m_data >> 13;
m_int_latch = 0;
m_dvx = 0;
m_pc++;
return 0;
}
int avg_quantum_device::handler_2() // quantum_st2st3
{
/* Quantum doesn't decode latch0 or latch2 but ST2 and ST3 are fed
* into the address controller which increments the PC
*/
m_pc++;
return 0;
}
int avg_quantum_device::handler_3() // quantum_latch3
{
m_int_latch = m_data >> 12;
m_dvx = m_data & 0xfff;
m_pc++;
return 0;
}