-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathantic.c
4229 lines (3903 loc) · 138 KB
/
antic.c
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
/*
* antic.c - ANTIC chip emulation
*
* Copyright (C) 1995-1998 David Firth
* Copyright (C) 1998-2008 Atari800 development team (see DOC/CREDITS)
*
* This file is part of the Atari800 emulator project which emulates
* the Atari 400, 800, 800XL, 130XE, and 5200 8-bit computers.
*
* Atari800 is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Atari800 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Atari800; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "config.h"
#include <string.h>
#include "antic.h"
#include "atari.h"
#include "cpu.h"
#include "gtia.h"
#include "log.h"
#include "memory.h"
#include "pokey.h"
#include "util.h"
#if !defined(BASIC) && !defined(CURSES_BASIC)
#include "input.h"
#include "screen.h"
#endif
#ifndef BASIC
#include "statesav.h"
#endif
#ifdef NEW_CYCLE_EXACT
#include "cycle_map.h"
#endif
#define LCHOP 3 /* do not build leftmost 0..3 characters in wide mode */
#define RCHOP 3 /* do not build rightmost 0..3 characters in wide mode */
int ANTIC_break_ypos = 999;
#if !defined(BASIC) && !defined(CURSES_BASIC)
static int gtia_bug_active = FALSE; /* The GTIA bug mode is active */
#endif
#ifdef NEW_CYCLE_EXACT
static void draw_partial_scanline(int l,int r);
static void update_scanline_chbase(void);
static void update_scanline_invert(void);
static void update_scanline_blank(void);
const int *ANTIC_cpu2antic_ptr;
const int *ANTIC_antic2cpu_ptr;
int ANTIC_delayed_wsync = 0;
static int dmactl_changed = 0;
static UBYTE delayed_DMACTL;
static int draw_antic_ptr_changed = 0;
static UBYTE need_load;
static int dmactl_bug_chdata;
#ifndef NO_GTIA11_DELAY
/* the position in the ring buffer where the last change before */
/* the previous line occurred to PRIOR */
static int prevline_prior_pos = 0;
/* the position in the ring buffer where the last change before */
/* the current line occurred to PRIOR */
static int curline_prior_pos = 0;
/* the current position in the ring buffer where the most recent */
/* change to PRIOR occurred */
int ANTIC_prior_curpos = 0;
/* ring buffer to hold the previous values of PRIOR */
UBYTE ANTIC_prior_val_buf[ANTIC_PRIOR_BUF_SIZE];
/* can be negative, leave as signed ints */
/* ring buffer to hold the positions where PRIOR changed */
int ANTIC_prior_pos_buf[ANTIC_PRIOR_BUF_SIZE];
#endif /* NO_GTIA11_DELAY */
#endif /* NEW_CYCLE_EXACT */
/* Video memory access is hidden behind these macros. It allows to track dirty video memory
to improve video system performance */
#ifdef DIRTYRECT
static UWORD *scratchUWordPtr;
static UWORD scratchUWord;
static ULONG *scratchULongPtr;
static ULONG scratchULong;
static UBYTE *scratchUBytePtr;
static UBYTE scratchUByte;
#ifdef NODIRTYCOMPARE
#define WRITE_VIDEO(ptr, val) \
do { \
scratchUWordPtr = (ptr); \
Screen_dirty[((ULONG) scratchUWordPtr - (ULONG) Screen_atari) >> 3] = 1; \
*scratchUWordPtr = (val); \
} while (0);
#define WRITE_VIDEO_LONG(ptr, val) \
do { \
scratchULongPtr = (ptr); \
Screen_dirty[((ULONG) scratchULongPtr - (ULONG) Screen_atari) >> 3] = 1; \
*scratchULongPtr = (val); \
} while (0)
#define WRITE_VIDEO_BYTE(ptr, val) \
do { \
scratchUBytePtr = (ptr); \
Screen_dirty[((ULONG) scratchUBytePtr - (ULONG) Screen_atari) >> 3] = 1; \
*scratchUBytePtr = (val); \
} while (0)
#define FILL_VIDEO(ptr, val, size) \
do { \
scratchUBytePtr = (UBYTE*) (ptr); \
scratchULong = (ULONG) (size); \
memset(Screen_dirty + (((ULONG) scratchUBytePtr - (ULONG) Screen_atari) >> 3), 1, scratchULong >> 3); \
memset(scratchUBytePtr, (val), scratchULong); \
} while (0)
#else /* NODIRTYCOMPARE not defined: */
#define WRITE_VIDEO(ptr, val) \
do { \
scratchUWordPtr = (ptr); \
scratchUWord = (val); \
if (*scratchUWordPtr != scratchUWord) { \
Screen_dirty[((ULONG) scratchUWordPtr - (ULONG) Screen_atari) >> 3] = 1; \
*scratchUWordPtr = scratchUWord; \
} \
} while (0)
#define WRITE_VIDEO_LONG(ptr, val) \
do { \
scratchULongPtr = (ptr); \
scratchULong = (val); \
if (*scratchULongPtr != scratchULong) { \
Screen_dirty[((ULONG) scratchULongPtr - (ULONG) Screen_atari) >> 3] = 1; \
*scratchULongPtr = scratchULong; \
} \
} while (0)
#define WRITE_VIDEO_BYTE(ptr, val) \
do { \
scratchUBytePtr = (ptr); \
scratchUByte = (val); \
if (*scratchUBytePtr != scratchUByte) { \
Screen_dirty[((ULONG) scratchUBytePtr - (ULONG) Screen_atari) >> 3] = 1; \
*scratchUBytePtr = scratchUByte; \
} \
} while (0)
static UBYTE *scratchFillLimit;
#define FILL_VIDEO(ptr, val, size) \
do { \
scratchUBytePtr = (UBYTE *) (ptr); \
scratchUByte = (UBYTE) (val); \
scratchFillLimit = scratchUBytePtr + (size); \
for (; scratchUBytePtr < scratchFillLimit; scratchUBytePtr++) { \
if (*scratchUBytePtr != scratchUByte) { \
Screen_dirty[((ULONG) scratchUBytePtr - (ULONG) Screen_atari) >> 3] = 1; \
*scratchUBytePtr = scratchUByte; \
} \
} \
} while (0)
#endif /* NODIRTYCOMPARE */
#else /* DIRTYRECT not defined: */
#define WRITE_VIDEO(ptr, val) (*(ptr) = val)
#define WRITE_VIDEO_LONG(ptr, val) (*(ptr) = val)
#define WRITE_VIDEO_BYTE(ptr, val) (*(ptr) = val)
#define FILL_VIDEO(ptr, val, size) memset(ptr, val, size)
#endif /* DIRTYRECT */
#define READ_VIDEO_LONG(ptr) (*(ptr))
void ANTIC_VideoMemset(UBYTE *ptr, UBYTE val, ULONG size)
{
FILL_VIDEO(ptr, val, size);
}
void ANTIC_VideoPutByte(UBYTE *ptr, UBYTE val)
{
WRITE_VIDEO_BYTE(ptr, val);
}
/* Memory access helpers----------------------------------------------------- */
/* Some optimizations result in unaligned 32-bit accesses. These macros have
been introduced for machines that don't allow unaligned memory accesses. */
#ifdef DIRTYRECT
/* STAT_UNALIGNED_WORDS doesn't work with DIRTYRECT */
#define WRITE_VIDEO_LONG_UNALIGNED WRITE_VIDEO_LONG
#else
#define WRITE_VIDEO_LONG_UNALIGNED(ptr, val) UNALIGNED_PUT_LONG((ptr), (val), Screen_atari_write_long_stat)
#endif
#ifdef WORDS_UNALIGNED_OK
#define IS_ZERO_ULONG(x) (! UNALIGNED_GET_LONG(x, pm_scanline_read_long_stat))
#define DO_GTIA_BYTE(p, l, x) { \
WRITE_VIDEO_LONG_UNALIGNED((ULONG *) (p), (l)[(x) >> 4]); \
WRITE_VIDEO_LONG_UNALIGNED((ULONG *) (p) + 1, (l)[(x) & 0xf]); \
}
#else /* WORDS_UNALIGNED_OK */
#define IS_ZERO_ULONG(x) (!((const UBYTE *)(x))[0] && !((const UBYTE *)(x))[1] && !((const UBYTE *)(x))[2] && !((const UBYTE *)(x))[3])
#define DO_GTIA_BYTE(p, l, x) { \
WRITE_VIDEO((UWORD *) (p), (UWORD) ((l)[(x) >> 4])); \
WRITE_VIDEO((UWORD *) (p) + 1, (UWORD) ((l)[(x) >> 4])); \
WRITE_VIDEO((UWORD *) (p) + 2, (UWORD) ((l)[(x) & 0xf])); \
WRITE_VIDEO((UWORD *) (p) + 3, (UWORD) ((l)[(x) & 0xf])); \
}
#endif /* WORDS_UNALIGNED_OK */
/* ANTIC Registers --------------------------------------------------------- */
UBYTE ANTIC_DMACTL;
UBYTE ANTIC_CHACTL;
UWORD ANTIC_dlist;
UBYTE ANTIC_HSCROL;
UBYTE ANTIC_VSCROL;
UBYTE ANTIC_PMBASE;
UBYTE ANTIC_CHBASE;
UBYTE ANTIC_NMIEN;
UBYTE ANTIC_NMIST;
/* ANTIC Memory ------------------------------------------------------------ */
#if !defined(BASIC) && !defined(CURSES_BASIC)
static UBYTE antic_memory[52];
#define ANTIC_margin 4
/* It's number of bytes in antic_memory, which are never loaded, but may be
read in wide playfield mode. These bytes are uninitialized, because on
real computer there's some kind of 'garbage'. Possibly 1 is enough, but
4 bytes surely won't cause negative indexes. :) */
/* Screen -----------------------------------------------------------------
Define screen as ULONG to ensure that it is Longword aligned.
This allows special optimisations under certain conditions.
------------------------------------------------------------------------ */
static UWORD *scrn_ptr;
#endif /* !defined(BASIC) && !defined(CURSES_BASIC) */
/* Separate access to XE extended memory ----------------------------------- */
/* It's available in 130 XE and 320 KB Compy Shop.
Note: during ANTIC access to extended memory in Compy Shop Self Test
is disabled. It is unknown if this is true for real 130 XE. If not,
then some extra code has to be added to:
- check if selftest_enabled is set
- check if the address is in range 0x5000..0x57ff
- if both conditions are true, then access memory instead of ANTIC_xe_ptr */
/* Pointer to 16 KB seen by ANTIC in 0x4000-0x7fff.
If it's the same what the CPU sees (and what's in MEMORY_mem[0x4000..0x7fff],
then NULL. */
const UBYTE *ANTIC_xe_ptr = NULL;
/* ANTIC Timing --------------------------------------------------------------
NOTE: this information was written before NEW_CYCLE_EXACT was introduced!
I've introduced global variable ANTIC_xpos, which contains current number of cycle
in a line. This simplifies ANTIC/CPU timing much. The CPU_GO() function which
emulates CPU is now void and is called with ANTIC_xpos limit, below which CPU can go.
All strange variables holding 'unused cycles', 'DMA cycles', 'allocated cycles'
etc. are removed. Simply whenever ANTIC fetches a byte, it takes single cycle,
which can be done now with ANTIC_xpos++. There's only one exception: in text modes
2-5 ANTIC takes more bytes than cycles, because it does less than ANTIC_DMAR refresh
cycles.
Now emulation is really screenline-oriented. We do ANTIC_ypos++ after a line,
not inside it.
This simplified diagram shows when what is done in a line:
MDPPPPDD..............(------R/S/F------)..........
^ ^ ^ ^ ^ ^ ^ ^ ---> time/xpos
0 | NMIST_C NMI_C SCR_C WSYNC_C|LINE_C
VSCON_C VSCOF_C
M - fetch Missiles
D - fetch DL
P - fetch Players
S - fetch Screen
F - fetch Font (in text modes)
R - refresh Memory (ANTIC_DMAR cycles)
Only Memory Refresh happens in every line, other tasks are optional.
Below are exact diagrams for some non-scrolled modes:
11111111111111
11111111112222222222333333333344444444445555555555666666666677777777778888888888999999999900000000001111
012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123
/--------------------------narrow------------------------------\
/----------------------------------normal--------------------------------------\
/-------------------------------------------wide--------------------------------------------\
blank line:
MDPPPPDD.................R...R...R...R...R...R...R...R...R........................................................
mode 8,9:
MDPPPPDD....S.......S....R..SR...R..SR...R..SR...R..SR...R..S.......S.......S.......S.......S.......S.............
mode a,b,c:
MDPPPPDD....S...S...S...SR..SR..SR..SR..SR..SR..SR..SR..SR..S...S...S...S...S...S...S...S...S...S...S...S.........
mode d,e,f:
MDPPPPDD....S.S.S.S.S.S.SRS.SRS.SRS.SRS.SRS.SRS.SRS.SRS.SRS.S.S.S.S.S.S.S.S.S.S.S.S.S.S.S.S.S.S.S.S.S.S.S.........
Notes:
* At the beginning of a line fetched are:
- a byte of Missiles
- a byte of DL (instruction)
- four bytes of Players
- two bytes of DL argument (jump or screen address)
The emulator, however, fetches them all continuously.
* Refresh cycles and Screen/Font fetches have been tested for some modes (see above).
This is for making the emulator more accurate, able to change colour registers,
sprite positions or GTIA modes during scanline. These modes are the most commonly used
with those effects.
Currently this isn't implemented, and all R/S/F cycles are fetched continuously in *all* modes
(however, right number of cycles is taken in every mode, basing on screen width and HSCROL).
There are a few constants representing following events:
* VSCON_C - in first VSC line dctr is loaded with VSCROL
* ANTIC_NMIST_C - NMIST is updated (set to 0x9f on DLI, set to 0x5f on VBLKI)
* ANTIC_NMI_C - If NMIEN permits, NMI interrupt is generated
* SCR_C - We draw whole line of screen. On a real computer you can change
ANTIC/GTIA registers while displaying screen, however this emulator
isn't that accurate.
* ANTIC_WSYNC_C - ANTIC holds CPU until this moment, when WSYNC is written
* VSCOF_C - in last VSC line dctr is compared with VSCROL
* ANTIC_LINE_C - simply end of line (this used to be called CPUL)
All constants are determined by tests on real Atari computer. It is assumed,
that ANTIC registers are read with LDA, LDX, LDY and written with STA, STX,
STY, all in absolute addressing mode. All these instructions last 4 cycles
and perform read/write operation in last cycle. The CPU emulation should
correctly emulate WSYNC and add cycles for current instruction BEFORE
executing it. That's why VSCOF_C > ANTIC_LINE_C is correct.
How WSYNC is now implemented:
* On writing WSYNC:
- if ANTIC_xpos <= ANTIC_WSYNC_C && ANTIC_xpos_limit >= ANTIC_WSYNC_C,
we only change ANTIC_xpos to ANTIC_WSYNC_C - that's all
- otherwise we set ANTIC_wsync_halt and change ANTIC_xpos to ANTIC_xpos_limit causing CPU_GO()
to return
* At the beginning of CPU_GO() (CPU emulation), when ANTIC_wsync_halt is set:
- if ANTIC_xpos_limit < ANTIC_WSYNC_C we return
- else we set ANTIC_xpos to ANTIC_WSYNC_C, reset ANTIC_wsync_halt and emulate some cycles
We don't emulate ANTIC_NMIST_C, ANTIC_NMI_C and SCR_C if it is unnecessary.
These are all cases:
* Common overscreen line
Nothing happens except that ANTIC gets ANTIC_DMAR cycles:
ANTIC_xpos += ANTIC_DMAR; GOEOL;
* First overscreen line - start of vertical blank
- CPU goes until ANTIC_NMIST_C
- ANTIC sets NMIST to 0x5f
if (ANTIC_NMIEN & 0x40) {
- CPU goes until ANTIC_NMI_C
- ANTIC forces NMI
}
- ANTIC gets ANTIC_DMAR cycles
- CPU goes until ANTIC_LINE_C
* Screen line without DLI
- ANTIC fetches DL and P/MG
- CPU goes until SCR_C
- ANTIC draws whole line fetching Screen/Font and refreshing memory
- CPU goes until ANTIC_LINE_C
* Screen line with DLI
- ANTIC fetches DL and P/MG
- CPU goes until ANTIC_NMIST_C
- ANTIC sets NMIST to 0x9f
if (ANTIC_NMIEN & 0x80) {
- CPU goes until ANTIC_NMI_C
- ANTIC forces NMI
}
- CPU goes until SCR_C
- ANTIC draws line with ANTIC_DMAR
- CPU goes until ANTIC_LINE_C
-------------------------------------------------------------------------- */
#define VSCON_C 1
#define SCR_C 28
#define VSCOF_C 112
unsigned int ANTIC_screenline_cpu_clock = 0;
#ifdef NEW_CYCLE_EXACT
#define UPDATE_DMACTL do{if (dmactl_changed) { \
dmactl_changed = 0; \
ANTIC_PutByte(ANTIC_OFFSET_DMACTL, delayed_DMACTL); \
} \
if (draw_antic_ptr_changed) { \
draw_antic_ptr_changed = 0; \
draw_antic_ptr = saved_draw_antic_ptr; \
}}while(0)
#else
#define UPDATE_DMACTL do{}while(0)
#endif /* NEW_CYCLE_EXACT */
#define UPDATE_GTIA_BUG /* update GTIA if it was in bug mode */\
do{if(gtia_bug_active) {\
/* restore draw_antic_ptr for multi-line modes*/\
draw_antic_ptr = draw_antic_table[GTIA_PRIOR >> 6][anticmode];\
gtia_bug_active = FALSE;\
}}while(0)
#define GOEOL_CYCLE_EXACT CPU_GO(ANTIC_antic2cpu_ptr[ANTIC_LINE_C]); \
ANTIC_xpos = ANTIC_cpu2antic_ptr[ANTIC_xpos]; \
ANTIC_xpos -= ANTIC_LINE_C; \
ANTIC_screenline_cpu_clock += ANTIC_LINE_C; \
ANTIC_ypos++; \
GTIA_UpdatePmplColls();
#define GOEOL CPU_GO(ANTIC_LINE_C); ANTIC_xpos -= ANTIC_LINE_C; ANTIC_screenline_cpu_clock += ANTIC_LINE_C; UPDATE_DMACTL; ANTIC_ypos++; UPDATE_GTIA_BUG
#define OVERSCREEN_LINE ANTIC_xpos += ANTIC_DMAR; GOEOL
int ANTIC_xpos = 0;
int ANTIC_xpos_limit;
int ANTIC_wsync_halt = FALSE;
int ANTIC_ypos; /* Line number - lines 8..247 are on screen */
/* Timing in first line of modes 2-5
In these modes ANTIC takes more bytes than cycles. Despite this, it would be
possible that SCR_C + cycles_taken > ANTIC_WSYNC_C. To avoid this we must take some
cycles before SCR_C. before_cycles contains number of them, while extra_cycles
contains difference between bytes taken and cycles taken plus before_cycles. */
#define BEFORE_CYCLES (SCR_C - 28)
/* It's number of cycles taken before SCR_C for not scrolled, narrow playfield.
It wasn't tested, but should be ok. ;) */
/* Light pen support ------------------------------------------------------- */
static UBYTE PENH;
static UBYTE PENV;
UBYTE ANTIC_PENH_input = 0x00;
UBYTE ANTIC_PENV_input = 0xff;
#ifndef BASIC
/* Internal ANTIC registers ------------------------------------------------ */
static UWORD screenaddr; /* Screen Pointer */
static UBYTE IR; /* Instruction Register */
static UBYTE anticmode; /* Antic mode */
static UBYTE dctr; /* Delta Counter */
static UBYTE lastline; /* dctr limit */
static UBYTE need_dl; /* boolean: fetch DL next line */
static UBYTE vscrol_off; /* boolean: displaying line ending VSC */
#endif
#if !defined(BASIC) && !defined(CURSES_BASIC)
/* Pre-computed values for improved performance ---------------------------- */
#define NORMAL0 0 /* modes 2,3,4,5,0xd,0xe,0xf */
#define NORMAL1 1 /* modes 6,7,0xa,0xb,0xc */
#define NORMAL2 2 /* modes 8,9 */
#define SCROLL0 3 /* modes 2,3,4,5,0xd,0xe,0xf with HSC */
#define SCROLL1 4 /* modes 6,7,0xa,0xb,0xc with HSC */
#define SCROLL2 5 /* modes 8,9 with HSC */
static int md; /* current mode NORMAL0..SCROLL2 */
/* tables for modes NORMAL0..SCROLL2 */
static int chars_read[6];
static int chars_displayed[6];
static int x_min[6];
static int ch_offset[6];
static int load_cycles[6];
static int font_cycles[6];
static int before_cycles[6];
static int extra_cycles[6];
/* border parameters for current display width */
static int left_border_chars;
static int right_border_start;
#ifdef NEW_CYCLE_EXACT
static int left_border_start = LCHOP * 4;
static int right_border_end = (48 - RCHOP) * 4;
#define LBORDER_START left_border_start
#define RBORDER_END right_border_end
#else
#define LBORDER_START (LCHOP * 4)
#define RBORDER_END ((48 - RCHOP) * 4)
#endif /* NEW_CYCLE_EXACT */
/* set with CHBASE *and* CHACTL - bits 0..2 set if flip on */
static UWORD chbase_20; /* CHBASE for 20 character mode */
/* set with CHACTL */
static UBYTE invert_mask;
static int blank_mask;
/* A scanline of AN0 and AN1 signals as transmitted from ANTIC to GTIA.
In every byte, bit 0 is AN0 and bit 1 is AN1 */
static UBYTE an_scanline[Screen_WIDTH / 2 + 8];
/* lookup tables */
static UBYTE blank_lookup[256];
static UWORD lookup2[256];
ULONG ANTIC_lookup_gtia9[16];
ULONG ANTIC_lookup_gtia11[16];
static UBYTE playfield_lookup[257];
static UBYTE mode_e_an_lookup[256];
/* Colour lookup table
This single table replaces 4 previously used: cl_word, cur_prior,
prior_table and pf_colls. It should be treated as a two-dimensional table,
with playfield colours in rows and PMG colours in columns:
no_PMG PM0 PM1 PM01 PM2 PM3 PM23 PM023 PM123 PM0123 PM25 PM35 PM235 colls ... ...
BAK
...
HI2
HI3
PF0
PF1
PF2
PF3
The table contains word value (lsb = msb) of colour to be drawn.
The table is being updated taking current PRIOR setting into consideration.
'...' represent two unused columns and single unused row.
HI2 and HI3 are used only if colour_translation_table is being used.
They're colours of hi-res pixels on PF2 and PF3 respectively (PF2 is
default background for hi-res, PF3 is PM5).
Columns PM023, PM123 and PM0123 are used when PRIOR & 0xf equals any
of 5,7,0xc,0xd,0xe,0xf. The columns represent PM0, PM1 and PM01 respectively
covered by PM2 and/or PM3. This is to handle black colour on PF2 and PF3.
Columns PM25, PM35 and PM235 are used when PRIOR & 0x1f equals any
of 0x10,0x1a,0x1c,0x1e. The columns represent PM2, PM3 and PM23
respectively covered by PM5. This to handle colour on PF0 and PF1:
PF3 if (PRIOR & 0x1f) == 0x10, PF0 or PF1 otherwise.
Additional column 'colls' holds collisions of playfields with PMG. */
UWORD ANTIC_cl[128];
#define C_PM0 0x01
#define C_PM1 0x02
#define C_PM01 0x03
#define C_PM2 0x04
#define C_PM3 0x05
#define C_PM23 0x06
#define C_PM023 0x07
#define C_PM123 0x08
#define C_PM0123 0x09
#define C_PM25 0x0a
#define C_PM35 0x0b
#define C_PM235 0x0c
#define C_COLLS 0x0d
#define C_BAK 0x00
#define C_HI2 0x20
#define C_HI3 0x30
#define C_PF0 0x40
#define C_PF1 0x50
#define C_PF2 0x60
#define C_PF3 0x70
#define C_BLACK (C_PF3 | C_PM25)
/* these are byte-offsets in the table, so left shift for indexing word table
has been avoided */
#define COLOUR(x) (*(UWORD *) ((UBYTE *) ANTIC_cl + (x) ))
#define L_PM0 (2 * C_PM0)
#define L_PM1 (2 * C_PM1)
#define L_PM01 (2 * C_PM01)
#define L_PM2 (2 * C_PM2)
#define L_PM3 (2 * C_PM3)
#define L_PM23 (2 * C_PM23)
#define L_PM023 (2 * C_PM023)
#define L_PM123 (2 * C_PM123)
#define L_PM0123 (2 * C_PM0123)
#define L_PM25 (2 * C_PM25)
#define L_PM35 (2 * C_PM35)
#define L_PM235 (2 * C_PM235)
#define L_COLLS (2 * C_COLLS)
#define L_BAK (2 * C_BAK)
#define L_HI2 (2 * C_HI2)
#define L_HI3 (2 * C_HI3)
#define L_PF0 (2 * C_PF0)
#define L_PF1 (2 * C_PF1)
#define L_PF2 (2 * C_PF2)
#define L_PF3 (2 * C_PF3)
#define L_BLACK (2 * C_BLACK)
/* Blank areas optimizations
Routines for most graphics modes take advantage of fact, that often
large areas of screen are background colour. If it is possible, 8 pixels
of background are drawn at once - with two longs or four words, if
the platform doesn't allow unaligned long access.
Artifacting also uses unaligned long access if it's supported. */
#ifdef WORDS_UNALIGNED_OK
#define INIT_BACKGROUND_6 ULONG background = ANTIC_cl[C_PF2] | (((ULONG) ANTIC_cl[C_PF2]) << 16);
#define INIT_BACKGROUND_8 ULONG background = ANTIC_lookup_gtia9[0];
#define DRAW_BACKGROUND(colreg) { \
WRITE_VIDEO_LONG_UNALIGNED((ULONG *) ptr, background); \
WRITE_VIDEO_LONG_UNALIGNED(((ULONG *) ptr) + 1, background); \
ptr += 4; \
}
#define DRAW_ARTIF { \
WRITE_VIDEO_LONG_UNALIGNED((ULONG *) ptr, art_curtable[(UBYTE) (screendata_tally >> 10)]); \
WRITE_VIDEO_LONG_UNALIGNED(((ULONG *) ptr) + 1, art_curtable[(UBYTE) (screendata_tally >> 6)]); \
ptr += 4; \
}
#else
#define INIT_BACKGROUND_6
#define INIT_BACKGROUND_8
#define DRAW_BACKGROUND(colreg) {\
WRITE_VIDEO(ptr, ANTIC_cl[colreg]); \
WRITE_VIDEO(ptr + 1, ANTIC_cl[colreg]); \
WRITE_VIDEO(ptr + 2, ANTIC_cl[colreg]); \
WRITE_VIDEO(ptr + 3, ANTIC_cl[colreg]); \
ptr += 4;\
}
#define DRAW_ARTIF {\
WRITE_VIDEO(ptr++, ((UWORD *) art_curtable)[(screendata_tally & 0x03fc00) >> 9]); \
WRITE_VIDEO(ptr++, ((UWORD *) art_curtable)[((screendata_tally & 0x03fc00) >> 9) + 1]); \
WRITE_VIDEO(ptr++, ((UWORD *) art_curtable)[(screendata_tally & 0x003fc0) >> 5]); \
WRITE_VIDEO(ptr++, ((UWORD *) art_curtable)[((screendata_tally & 0x003fc0) >> 5) + 1]); \
}
#endif /* WORDS_UNALIGNED_OK */
#define DRAW_ARTIF_NEW {\
WRITE_VIDEO(ptr++, art_lookup_new[(screendata_tally & 0x03f000) >> 12]); \
WRITE_VIDEO(ptr++, art_lookup_new[(screendata_tally & 0x00fc00) >> 10]); \
WRITE_VIDEO(ptr++, art_lookup_new[(screendata_tally & 0x003f00) >> 8]); \
WRITE_VIDEO(ptr++, art_lookup_new[(screendata_tally & 0x000fc0) >> 6]); \
}
/* Hi-res modes optimizations
Now hi-res modes are drawn with words, not bytes. Endianess defaults
to little-endian. WORDS_BIGENDIAN should be defined when compiling on
a big-endian machine. */
#ifdef WORDS_BIGENDIAN
#define BYTE0_MASK 0xff00
#define BYTE1_MASK 0x00ff
#define HIRES_MASK_01 0xfff0
#define HIRES_MASK_10 0xf0ff
#define HIRES_LUM_01 0x000f
#define HIRES_LUM_10 0x0f00
#else
#define BYTE0_MASK 0x00ff
#define BYTE1_MASK 0xff00
#define HIRES_MASK_01 0xf0ff
#define HIRES_MASK_10 0xfff0
#define HIRES_LUM_01 0x0f00
#define HIRES_LUM_10 0x000f
#endif
static UWORD hires_lookup_n[128];
static UWORD hires_lookup_m[128];
#define hires_norm(x) hires_lookup_n[(x) >> 1]
#define hires_mask(x) hires_lookup_m[(x) >> 1]
#ifndef USE_COLOUR_TRANSLATION_TABLE
int ANTIC_artif_new = FALSE; /* New type of artifacting */
UWORD ANTIC_hires_lookup_l[128]; /* accessed in gtia.c */
#define hires_lum(x) ANTIC_hires_lookup_l[(x) >> 1]
#endif
/* Player/Missile Graphics ------------------------------------------------- */
#define PF0PM (*(UBYTE *) &ANTIC_cl[C_PF0 | C_COLLS])
#define PF1PM (*(UBYTE *) &ANTIC_cl[C_PF1 | C_COLLS])
#define PF2PM (*(UBYTE *) &ANTIC_cl[C_PF2 | C_COLLS])
#define PF3PM (*(UBYTE *) &ANTIC_cl[C_PF3 | C_COLLS])
#define PF_COLLS(x) (((UBYTE *) &ANTIC_cl)[(x) + L_COLLS])
static int singleline;
int ANTIC_player_dma_enabled;
int ANTIC_player_gra_enabled;
int ANTIC_missile_dma_enabled;
int ANTIC_missile_gra_enabled;
int ANTIC_player_flickering;
int ANTIC_missile_flickering;
static UWORD pmbase_s;
static UWORD pmbase_d;
/* PMG lookup tables */
static UBYTE pm_lookup_table[20][256];
/* current PMG lookup table */
static const UBYTE *pm_lookup_ptr;
#define PL_00 0 /* 0x00,0x01,0x02,0x03,0x04,0x06,0x08,0x09,0x0a,0x0b */
#define PL_05 1 /* 0x05,0x07,0x0c,0x0d,0x0e,0x0f */
#define PL_10 2 /* 0x10,0x1a */
#define PL_11 3 /* 0x11,0x18,0x19 */
#define PL_12 4 /* 0x12 */
#define PL_13 5 /* 0x13,0x1b */
#define PL_14 6 /* 0x14,0x16 */
#define PL_15 7 /* 0x15,0x17,0x1d,0x1f */
#define PL_1c 8 /* 0x1c */
#define PL_1e 9 /* 0x1e */
#define PL_20 10 /* 0x20,0x21,0x22,0x23,0x24,0x26,0x28,0x29,0x2a,0x2b */
#define PL_25 11 /* 0x25,0x27,0x2c,0x2d,0x2e,0x2f */
#define PL_30 12 /* 0x30,0x3a */
#define PL_31 13 /* 0x31,0x38,0x39 */
#define PL_32 14 /* 0x32 */
#define PL_33 15 /* 0x33,0x3b */
#define PL_34 16 /* 0x34,0x36 */
#define PL_35 17 /* 0x35,0x37,0x3d,0x3f */
#define PL_3c 18 /* 0x3c */
#define PL_3e 19 /* 0x3e */
static const UBYTE prior_to_pm_lookup[64] = {
PL_00, PL_00, PL_00, PL_00, PL_00, PL_05, PL_00, PL_05,
PL_00, PL_00, PL_00, PL_00, PL_05, PL_05, PL_05, PL_05,
PL_10, PL_11, PL_12, PL_13, PL_14, PL_15, PL_14, PL_15,
PL_11, PL_11, PL_10, PL_13, PL_1c, PL_15, PL_1e, PL_15,
PL_20, PL_20, PL_20, PL_20, PL_20, PL_25, PL_20, PL_25,
PL_20, PL_20, PL_20, PL_20, PL_25, PL_25, PL_25, PL_25,
PL_30, PL_31, PL_32, PL_33, PL_34, PL_35, PL_34, PL_35,
PL_31, PL_31, PL_30, PL_33, PL_3c, PL_35, PL_3e, PL_35
};
static void init_pm_lookup(void)
{
static const UBYTE pm_lookup_template[10][16] = {
/* PL_20 */
{ L_BAK, L_PM0, L_PM1, L_PM01, L_PM2, L_PM0, L_PM1, L_PM01,
L_PM3, L_PM0, L_PM1, L_PM01, L_PM23, L_PM0, L_PM1, L_PM01 },
/* PL_25 */
{ L_BAK, L_PM0, L_PM1, L_PM01, L_PM2, L_PM023, L_PM123, L_PM0123,
L_PM3, L_PM023, L_PM123, L_PM0123, L_PM23, L_PM023, L_PM123, L_PM0123 },
/* PL_30 */
{ L_PF3, L_PM0, L_PM1, L_PM01, L_PM25, L_PM0, L_PM1, L_PM01,
L_PM35, L_PM0, L_PM1, L_PM01, L_PM235, L_PM0, L_PM1, L_PM01 },
/* PL_31 */
{ L_PF3, L_PM0, L_PM1, L_PM01, L_PM2, L_PM0, L_PM1, L_PM01,
L_PM3, L_PM0, L_PM1, L_PM01, L_PM23, L_PM0, L_PM1, L_PM01 },
/* PL_32 */
{ L_PF3, L_PM0, L_PM1, L_PM01, L_PF3, L_PM0, L_PM1, L_PM01,
L_PF3, L_PM0, L_PM1, L_PM01, L_PF3, L_PM0, L_PM1, L_PM01 },
/* PL_33 */
{ L_PF3, L_PM0, L_PM1, L_PM01, L_BLACK, L_PM0, L_PM1, L_PM01,
L_BLACK, L_PM0, L_PM1, L_PM01, L_BLACK, L_PM0, L_PM1, L_PM01 },
/* PL_34 */
{ L_PF3, L_PF3, L_PF3, L_PF3, L_PF3, L_PF3, L_PF3, L_PF3,
L_PF3, L_PF3, L_PF3, L_PF3, L_PF3, L_PF3, L_PF3, L_PF3 },
/* PL_35 */
{ L_PF3, L_PF3, L_PF3, L_PF3, L_BLACK, L_BLACK, L_BLACK, L_BLACK,
L_BLACK, L_BLACK, L_BLACK, L_BLACK, L_BLACK, L_BLACK, L_BLACK, L_BLACK },
/* PL_3c */
{ L_PF3, L_PF3, L_PF3, L_PF3, L_PM25, L_PM25, L_PM25, L_PM25,
L_PM25, L_PM25, L_PM25, L_PM25, L_PM25, L_PM25, L_PM25, L_PM25 },
/* PL_3e */
{ L_PF3, L_PF3, L_PF3, L_PF3, L_PM25, L_BLACK, L_BLACK, L_BLACK,
L_PM25, L_BLACK, L_BLACK, L_BLACK, L_PM25, L_BLACK, L_BLACK, L_BLACK }
};
static const UBYTE multi_to_normal[] = {
L_BAK,
L_PM0, L_PM1, L_PM0,
L_PM2, L_PM3, L_PM2,
L_PM023, L_PM123, L_PM023,
L_PM25, L_PM35, L_PM25
};
int i;
int j;
UBYTE temp;
for (i = 0; i <= 1; i++)
for (j = 0; j <= 255; j++) {
pm_lookup_table[i + 10][j] = temp = pm_lookup_template[i][(j & 0xf) | (j >> 4)];
pm_lookup_table[i][j] = temp <= L_PM235 ? multi_to_normal[temp >> 1] : temp;
}
for (; i <= 9; i++) {
for (j = 0; j <= 15; j++) {
pm_lookup_table[i + 10][j] = temp = pm_lookup_template[i < 7 ? 0 : 1][j];
pm_lookup_table[i][j] = temp <= L_PM235 ? multi_to_normal[temp >> 1] : temp;
}
for (; j <= 255; j++) {
pm_lookup_table[i + 10][j] = temp = pm_lookup_template[i][j & 0xf];
pm_lookup_table[i][j] = temp <= L_PM235 ? multi_to_normal[temp >> 1] : temp;
}
}
}
static const UBYTE hold_missiles_tab[16] = {
0x00,0x03,0x0c,0x0f,0x30,0x33,0x3c,0x3f,
0xc0,0xc3,0xcc,0xcf,0xf0,0xf3,0xfc,0xff};
static void pmg_dma(void)
{
/* VDELAY bit set == GTIA ignores PMG DMA in even lines */
if (ANTIC_player_dma_enabled) {
if (ANTIC_player_gra_enabled) {
const UBYTE *base;
if (singleline) {
if (ANTIC_xe_ptr != NULL && pmbase_s < 0x8000 && pmbase_s >= 0x4000)
base = ANTIC_xe_ptr + pmbase_s - 0x4000 + ANTIC_ypos;
else
base = MEMORY_mem + pmbase_s + ANTIC_ypos;
if (ANTIC_ypos & 1) {
GTIA_GRAFP0 = base[0x400];
GTIA_GRAFP1 = base[0x500];
GTIA_GRAFP2 = base[0x600];
GTIA_GRAFP3 = base[0x700];
}
else {
if ((GTIA_VDELAY & 0x10) == 0)
GTIA_GRAFP0 = base[0x400];
if ((GTIA_VDELAY & 0x20) == 0)
GTIA_GRAFP1 = base[0x500];
if ((GTIA_VDELAY & 0x40) == 0)
GTIA_GRAFP2 = base[0x600];
if ((GTIA_VDELAY & 0x80) == 0)
GTIA_GRAFP3 = base[0x700];
}
}
else {
if (ANTIC_xe_ptr != NULL && pmbase_d < 0x8000 && pmbase_d >= 0x4000)
base = ANTIC_xe_ptr + (pmbase_d - 0x4000) + (ANTIC_ypos >> 1);
else
base = MEMORY_mem + pmbase_d + (ANTIC_ypos >> 1);
if (ANTIC_ypos & 1) {
GTIA_GRAFP0 = base[0x200];
GTIA_GRAFP1 = base[0x280];
GTIA_GRAFP2 = base[0x300];
GTIA_GRAFP3 = base[0x380];
}
else {
if ((GTIA_VDELAY & 0x10) == 0)
GTIA_GRAFP0 = base[0x200];
if ((GTIA_VDELAY & 0x20) == 0)
GTIA_GRAFP1 = base[0x280];
if ((GTIA_VDELAY & 0x40) == 0)
GTIA_GRAFP2 = base[0x300];
if ((GTIA_VDELAY & 0x80) == 0)
GTIA_GRAFP3 = base[0x380];
}
}
}
ANTIC_xpos += 4;
}
if (ANTIC_missile_dma_enabled) {
if (ANTIC_missile_gra_enabled) {
UBYTE data;
if (ANTIC_xe_ptr != NULL && pmbase_s < 0x8000 && pmbase_s >= 0x4000)
data = ANTIC_xe_ptr[singleline ? pmbase_s + ANTIC_ypos + 0x300 - 0x4000 : pmbase_d + (ANTIC_ypos >> 1) + 0x180 - 0x4000];
else
data = MEMORY_dGetByte(singleline ? pmbase_s + ANTIC_ypos + 0x300 : pmbase_d + (ANTIC_ypos >> 1) + 0x180);
/* in odd lines load all missiles, in even only those, for which VDELAY bit is zero */
GTIA_GRAFM = ANTIC_ypos & 1 ? data : ((GTIA_GRAFM ^ data) & hold_missiles_tab[GTIA_VDELAY & 0xf]) ^ data;
}
ANTIC_xpos++;
}
}
/* Artifacting ------------------------------------------------------------ */
int ANTIC_artif_mode;
static UWORD art_lookup_new[64];
static UWORD art_colour1_new;
static UWORD art_colour2_new;
static ULONG art_lookup_normal[256];
static ULONG art_lookup_reverse[256];
static ULONG art_bkmask_normal[256];
static ULONG art_lummask_normal[256];
static ULONG art_bkmask_reverse[256];
static ULONG art_lummask_reverse[256];
static ULONG *art_curtable = art_lookup_normal;
static ULONG *art_curbkmask = art_bkmask_normal;
static ULONG *art_curlummask = art_lummask_normal;
static UWORD art_normal_colpf1_save;
static UWORD art_normal_colpf2_save;
static UWORD art_reverse_colpf1_save;
static UWORD art_reverse_colpf2_save;
static void setup_art_colours(void)
{
static UWORD *art_colpf1_save = &art_normal_colpf1_save;
static UWORD *art_colpf2_save = &art_normal_colpf2_save;
UWORD curlum = ANTIC_cl[C_PF1] & 0x0f0f;
if (curlum != *art_colpf1_save || ANTIC_cl[C_PF2] != *art_colpf2_save) {
if (curlum < (ANTIC_cl[C_PF2] & 0x0f0f)) {
art_colpf1_save = &art_reverse_colpf1_save;
art_colpf2_save = &art_reverse_colpf2_save;
art_curtable = art_lookup_reverse;
art_curlummask = art_lummask_reverse;
art_curbkmask = art_bkmask_reverse;
}
else {
art_colpf1_save = &art_normal_colpf1_save;
art_colpf2_save = &art_normal_colpf2_save;
art_curtable = art_lookup_normal;
art_curlummask = art_lummask_normal;
art_curbkmask = art_bkmask_normal;
}
if (curlum ^ *art_colpf1_save) {
int i;
ULONG new_colour = curlum ^ *art_colpf1_save;
new_colour |= new_colour << 16;
*art_colpf1_save = curlum;
for (i = 0; i <= 255; i++)
art_curtable[i] ^= art_curlummask[i] & new_colour;
}
if (ANTIC_cl[C_PF2] ^ *art_colpf2_save) {
int i;
ULONG new_colour = ANTIC_cl[C_PF2] ^ *art_colpf2_save;
new_colour |= new_colour << 16;
*art_colpf2_save = ANTIC_cl[C_PF2];
for (i = 0; i <= 255; i++)
art_curtable[i] ^= art_curbkmask[i] & new_colour;
}
}
}
#endif /* !defined(BASIC) && !defined(CURSES_BASIC) */
/* Initialization ---------------------------------------------------------- */
int ANTIC_Initialise(int *argc, char *argv[])
{
#if !defined(BASIC) && !defined(CURSES_BASIC)
int i, j;
for (i = j = 1; i < *argc; i++) {
int i_a = (i + 1 < *argc); /* is argument available? */
int a_m = FALSE; /* error, argument missing! */
if (strcmp(argv[i], "-artif") == 0) {
if (i_a) {
ANTIC_artif_mode = Util_sscandec(argv[++i]);
if (ANTIC_artif_mode < 0 || ANTIC_artif_mode > 4) {
Log_print("Invalid artifacting mode, using default.");
ANTIC_artif_mode = 0;
}
}
else a_m = TRUE;
}
else {
if (strcmp(argv[i], "-help") == 0) {
Log_print("\t-artif <num> Set artifacting mode 0-4 (0 = disable)");
}
argv[j++] = argv[i];
}
if (a_m) {
Log_print("Missing argument for '%s'", argv[i]);
return FALSE;
}
}
*argc = j;
ANTIC_UpdateArtifacting();
playfield_lookup[0x00] = L_BAK;
playfield_lookup[0x40] = L_PF0;
playfield_lookup[0x80] = L_PF1;
playfield_lookup[0xc0] = L_PF2;
playfield_lookup[0x100] = L_PF3;
blank_lookup[0x80] = blank_lookup[0xa0] = blank_lookup[0xc0] = blank_lookup[0xe0] = 0x00;
hires_mask(0x00) = 0xffff;
#ifdef USE_COLOUR_TRANSLATION_TABLE
hires_mask(0x40) = BYTE0_MASK;
hires_mask(0x80) = BYTE1_MASK;
hires_mask(0xc0) = 0;
#else
hires_mask(0x40) = HIRES_MASK_01;
hires_mask(0x80) = HIRES_MASK_10;
hires_mask(0xc0) = 0xf0f0;
hires_lum(0x00) = hires_lum(0x40) = hires_lum(0x80) = hires_lum(0xc0) = 0;
#endif
init_pm_lookup();
mode_e_an_lookup[0] = 0;
mode_e_an_lookup[1] = mode_e_an_lookup[4] = mode_e_an_lookup[0x10] = mode_e_an_lookup[0x40] = 0;
mode_e_an_lookup[2] = mode_e_an_lookup[8] = mode_e_an_lookup[0x20] = mode_e_an_lookup[0x80] = 1;