-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hardware.h
1142 lines (995 loc) · 41.8 KB
/
Hardware.h
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
#ifndef __HARDWARE_H__
#define __HARDWARE_H__
#define MEM16(addr) ((uint16_t *)(addr))
#define ARRAY8(addr) ((uint8_t *)(addr))
#define ARRAY16(addr) ((uint16_t *)(addr))
#define ARRAY32(addr) ((uint32_t *)(addr))
#define SARRAY32(addr) ((int32_t *)(addr))
#define REG8(addr) (*(volatile uint8_t *)(addr))
#define REG16(addr) (*(volatile uint16_t *)(addr))
#define REG32(addr) (*(volatile uint32_t *)(addr))
#define SREG32(addr) (*(volatile int32_t *)(addr))
#define REG64(addr) (*(volatile uint64_t *)(addr))
#define SREG64(addr) (*(volatile int64_t *)(addr))
#define REGPTR(addr) (*(volatile void **)(addr))
#define REGCPTR(addr) (*(volatile const void **)(addr))
#ifdef ARM9
#define ARM9_MEM16(addr) MEM16(addr)
#define ARM9_ARRAY8(addr) ARRAY8(addr)
#define ARM9_ARRAY16(addr) ARRAY16(addr)
#define ARM9_ARRAY32(addr) ARRAY32(addr)
#define ARM9_SARRAY32(addr) SARRAY32(addr)
#define ARM9_REG8(addr) REG8(addr)
#define ARM9_REG16(addr) REG16(addr)
#define ARM9_REG32(addr) REG32(addr)
#define ARM9_SREG32(addr) SREG32(addr)
#define ARM9_REG64(addr) REG64(addr)
#define ARM9_SREG64(addr) SREG64(addr)
#define ARM9_REGPTR(addr) REGPTR(addr)
#else
#define ARM9_MEM16(addr) (This_memory_region_is_not_available_on_ARM7)
#define ARM9_ARRAY8(addr) (This_memory_region_is_not_available_on_ARM7)
#define ARM9_ARRAY16(addr) (This_memory_region_is_not_available_on_ARM7)
#define ARM9_ARRAY32(addr) (This_memory_region_is_not_available_on_ARM7)
#define ARM9_SARRAY32(addr) (This_memory_region_is_not_available_on_ARM7)
#define ARM9_REG8(addr) (This_register_is_not_available_on_ARM7)
#define ARM9_REG16(addr) (This_register_is_not_available_on_ARM7)
#define ARM9_REG32(addr) (This_register_is_not_available_on_ARM7)
#define ARM9_SREG32(addr) (This_register_is_not_available_on_ARM7)
#define ARM9_REG64(addr) (This_register_is_not_available_on_ARM7)
#define ARM9_SREG64(addr) (This_register_is_not_available_on_ARM7)
#define ARM9_REGPTR(addr) (This_register_is_not_available_on_ARM7)
#endif
#ifdef ARM7
#define ARM7_MEM16(addr) MEM16(addr)
#define ARM7_REG8(addr) REG8(addr)
#define ARM7_REG16(addr) REG16(addr)
#define ARM7_REG32(addr) REG32(addr)
#define ARM7_REGPTR(addr) REGPTR(addr)
#else
#define ARM7_MEM16(addr) (This_memory_region_is_not_available_on_ARM9)
#define ARM7_REG8(addr) (This_register_is_not_available_on_ARM9)
#define ARM7_REG16(addr) (This_register_is_not_available_on_ARM9)
#define ARM7_REG32(addr) (This_register_is_not_available_on_ARM9)
#define ARM7_REGPTR(addr) (This_register_is_not_available_on_ARM9)
#endif
//
// Memory regions
//
#ifdef VRAM_A
#undef VRAM_A
#undef VRAM_B
#endif
#define PALRAM_A ARM9_MEM16(0x05000000)
#define PALRAM_OBJ_A ARM9_MEM16(0x05000200)
#define PALRAM_B ARM9_MEM16(0x05000400)
#define PALRAM_OBJ_B ARM9_MEM16(0x05000600)
#define VRAM_A ARM9_MEM16(0x06000000)
#define VRAM_B ARM9_MEM16(0x06200000)
#define VRAM_OBJ_A ARM9_MEM16(0x06400000)
#define VRAM_OBJ_B ARM9_MEM16(0x06600000)
#define OAM_A ARM9_MEM16(0x07000000)
#define OAM_B ARM9_MEM16(0x7000400)
#define VRAM_A_OFFS_0K ARM9_MEM16(0x06000000)
#define VRAM_A_OFFS_2K ARM9_MEM16(0x06000800)
#define VRAM_A_OFFS_4K ARM9_MEM16(0x06001000)
#define VRAM_A_OFFS_6K ARM9_MEM16(0x06001800)
#define VRAM_A_OFFS_8K ARM9_MEM16(0x06002000)
#define VRAM_A_OFFS_10K ARM9_MEM16(0x06002800)
#define VRAM_A_OFFS_12K ARM9_MEM16(0x06003000)
#define VRAM_A_OFFS_14K ARM9_MEM16(0x06003800)
#define VRAM_A_OFFS_16K ARM9_MEM16(0x06004000)
#define VRAM_A_OFFS_18K ARM9_MEM16(0x06004800)
#define VRAM_A_OFFS_20K ARM9_MEM16(0x06005000)
#define VRAM_A_OFFS_22K ARM9_MEM16(0x06005800)
#define VRAM_A_OFFS_24K ARM9_MEM16(0x06006000)
#define VRAM_A_OFFS_26K ARM9_MEM16(0x06006800)
#define VRAM_A_OFFS_28K ARM9_MEM16(0x06007000)
#define VRAM_A_OFFS_30K ARM9_MEM16(0x06007800)
#define VRAM_A_OFFS_32K ARM9_MEM16(0x06008000)
#define VRAM_A_OFFS_34K ARM9_MEM16(0x06008800)
#define VRAM_A_OFFS_36K ARM9_MEM16(0x06009000)
#define VRAM_A_OFFS_38K ARM9_MEM16(0x06009800)
#define VRAM_A_OFFS_40K ARM9_MEM16(0x0600a000)
#define VRAM_A_OFFS_42K ARM9_MEM16(0x0600a800)
#define VRAM_A_OFFS_44K ARM9_MEM16(0x0600b000)
#define VRAM_A_OFFS_46K ARM9_MEM16(0x0600b800)
#define VRAM_A_OFFS_48K ARM9_MEM16(0x0600c000)
#define VRAM_A_OFFS_50K ARM9_MEM16(0x0600c800)
#define VRAM_A_OFFS_52K ARM9_MEM16(0x0600d000)
#define VRAM_A_OFFS_55K ARM9_MEM16(0x0600d800)
#define VRAM_A_OFFS_56K ARM9_MEM16(0x0600e000)
#define VRAM_A_OFFS_58K ARM9_MEM16(0x0600e800)
#define VRAM_A_OFFS_60K ARM9_MEM16(0x0600f000)
#define VRAM_A_OFFS_62K ARM9_MEM16(0x0600f800)
#define VRAM_A_OFFS_64K ARM9_MEM16(0x06010000)
#define VRAM_A_OFFS_80K ARM9_MEM16(0x06014000)
#define VRAM_A_OFFS_96K ARM9_MEM16(0x06018000)
#define VRAM_A_OFFS_112K ARM9_MEM16(0x0601c000)
#define VRAM_A_OFFS_128K ARM9_MEM16(0x06020000)
#define VRAM_A_OFFS_144K ARM9_MEM16(0x06024000)
#define VRAM_A_OFFS_160K ARM9_MEM16(0x06028000)
#define VRAM_A_OFFS_176K ARM9_MEM16(0x0602c000)
#define VRAM_A_OFFS_192K ARM9_MEM16(0x06030000)
#define VRAM_A_OFFS_208K ARM9_MEM16(0x06034000)
#define VRAM_A_OFFS_224K ARM9_MEM16(0x06038000)
#define VRAM_A_OFFS_240K ARM9_MEM16(0x0603c000)
#define VRAM_A_OFFS_256K ARM9_MEM16(0x06040000)
#define VRAM_A_OFFS_272K ARM9_MEM16(0x06044000)
#define VRAM_A_OFFS_288K ARM9_MEM16(0x06048000)
#define VRAM_A_OFFS_304K ARM9_MEM16(0x0604c000)
#define VRAM_A_OFFS_320K ARM9_MEM16(0x06050000)
#define VRAM_A_OFFS_336K ARM9_MEM16(0x06054000)
#define VRAM_A_OFFS_352K ARM9_MEM16(0x06058000)
#define VRAM_A_OFFS_368K ARM9_MEM16(0x0605c000)
#define VRAM_A_OFFS_384K ARM9_MEM16(0x06060000)
#define VRAM_A_OFFS_400K ARM9_MEM16(0x06064000)
#define VRAM_A_OFFS_416K ARM9_MEM16(0x06068000)
#define VRAM_A_OFFS_432K ARM9_MEM16(0x0606c000)
#define VRAM_A_OFFS_448K ARM9_MEM16(0x06070000)
#define VRAM_A_OFFS_464K ARM9_MEM16(0x06074000)
#define VRAM_A_OFFS_480K ARM9_MEM16(0x06078000)
#define VRAM_A_OFFS_496K ARM9_MEM16(0x0607c000)
#define VRAM_B_OFFS_0K ARM9_MEM16(0x06200000)
#define VRAM_B_OFFS_2K ARM9_MEM16(0x06200800)
#define VRAM_B_OFFS_4K ARM9_MEM16(0x06201000)
#define VRAM_B_OFFS_6K ARM9_MEM16(0x06201800)
#define VRAM_B_OFFS_8K ARM9_MEM16(0x06202000)
#define VRAM_B_OFFS_10K ARM9_MEM16(0x06202800)
#define VRAM_B_OFFS_12K ARM9_MEM16(0x06203000)
#define VRAM_B_OFFS_14K ARM9_MEM16(0x06203800)
#define VRAM_B_OFFS_16K ARM9_MEM16(0x06204000)
#define VRAM_B_OFFS_18K ARM9_MEM16(0x06204800)
#define VRAM_B_OFFS_20K ARM9_MEM16(0x06205000)
#define VRAM_B_OFFS_22K ARM9_MEM16(0x06205800)
#define VRAM_B_OFFS_24K ARM9_MEM16(0x06206000)
#define VRAM_B_OFFS_26K ARM9_MEM16(0x06206800)
#define VRAM_B_OFFS_28K ARM9_MEM16(0x06207000)
#define VRAM_B_OFFS_30K ARM9_MEM16(0x06207800)
#define VRAM_B_OFFS_32K ARM9_MEM16(0x06208000)
#define VRAM_B_OFFS_34K ARM9_MEM16(0x06208800)
#define VRAM_B_OFFS_36K ARM9_MEM16(0x06209000)
#define VRAM_B_OFFS_38K ARM9_MEM16(0x06209800)
#define VRAM_B_OFFS_40K ARM9_MEM16(0x0620a000)
#define VRAM_B_OFFS_42K ARM9_MEM16(0x0620a800)
#define VRAM_B_OFFS_44K ARM9_MEM16(0x0620b000)
#define VRAM_B_OFFS_46K ARM9_MEM16(0x0620b800)
#define VRAM_B_OFFS_48K ARM9_MEM16(0x0620c000)
#define VRAM_B_OFFS_50K ARM9_MEM16(0x0620c800)
#define VRAM_B_OFFS_52K ARM9_MEM16(0x0620d000)
#define VRAM_B_OFFS_55K ARM9_MEM16(0x0620d800)
#define VRAM_B_OFFS_56K ARM9_MEM16(0x0620e000)
#define VRAM_B_OFFS_58K ARM9_MEM16(0x0620e800)
#define VRAM_B_OFFS_60K ARM9_MEM16(0x0620f000)
#define VRAM_B_OFFS_62K ARM9_MEM16(0x0620f800)
#define VRAM_B_OFFS_64K ARM9_MEM16(0x06210000)
#define VRAM_B_OFFS_80K ARM9_MEM16(0x06214000)
#define VRAM_B_OFFS_96K ARM9_MEM16(0x06218000)
#define VRAM_B_OFFS_112K ARM9_MEM16(0x0621c000)
#define VRAM_B_OFFS_128K ARM9_MEM16(0x06220000)
#define VRAM_B_OFFS_144K ARM9_MEM16(0x06224000)
#define VRAM_B_OFFS_160K ARM9_MEM16(0x06228000)
#define VRAM_B_OFFS_176K ARM9_MEM16(0x0622c000)
#define VRAM_B_OFFS_192K ARM9_MEM16(0x06230000)
#define VRAM_B_OFFS_208K ARM9_MEM16(0x06234000)
#define VRAM_B_OFFS_224K ARM9_MEM16(0x06238000)
#define VRAM_B_OFFS_240K ARM9_MEM16(0x0623c000)
#define VRAM_B_OFFS_256K ARM9_MEM16(0x06240000)
#define VRAM_B_OFFS_272K ARM9_MEM16(0x06244000)
#define VRAM_B_OFFS_288K ARM9_MEM16(0x06248000)
#define VRAM_B_OFFS_304K ARM9_MEM16(0x0624c000)
#define VRAM_B_OFFS_320K ARM9_MEM16(0x06250000)
#define VRAM_B_OFFS_336K ARM9_MEM16(0x06254000)
#define VRAM_B_OFFS_352K ARM9_MEM16(0x06258000)
#define VRAM_B_OFFS_368K ARM9_MEM16(0x0625c000)
#define VRAM_B_OFFS_384K ARM9_MEM16(0x06260000)
#define VRAM_B_OFFS_400K ARM9_MEM16(0x06264000)
#define VRAM_B_OFFS_416K ARM9_MEM16(0x06268000)
#define VRAM_B_OFFS_432K ARM9_MEM16(0x0626c000)
#define VRAM_B_OFFS_448K ARM9_MEM16(0x06270000)
#define VRAM_B_OFFS_464K ARM9_MEM16(0x06274000)
#define VRAM_B_OFFS_480K ARM9_MEM16(0x06278000)
#define VRAM_B_OFFS_496K ARM9_MEM16(0x0627c000)
#define VRAM_LCDC_A ARM9_MEM16(0x6800000)
#define VRAM_LCDC_B ARM9_MEM16(0x6820000)
#define VRAM_LCDC_C ARM9_MEM16(0x6840000)
#define VRAM_LCDC_D ARM9_MEM16(0x6860000)
#define VRAM_LCDC_E ARM9_MEM16(0x6880000)
#define VRAM_LCDC_F ARM9_MEM16(0x6890000)
#define VRAM_LCDC_G ARM9_MEM16(0x6894000)
#define VRAM_LCDC_H ARM9_MEM16(0x6898000)
#define VRAM_LCDC_I ARM9_MEM16(0x68a0000)
#define VRAM_LCDC_OFFS(offs) ARM9_MEM16(0x6800000+(offs))
#define VRAM_LCDC_OFFS_K(offs) ARM9_MEM16(0x6800000+(offs)*1024)
//
// Video (ARM9)
//
// Display control
#define DISPCNT_A ARM9_REG32(0x04000000)
#define DISPCNT_B ARM9_REG32(0x04001000)
#define DISPCNT_MODE_0 (0<<0)
#define DISPCNT_MODE_1 (1<<0)
#define DISPCNT_MODE_2 (2<<0)
#define DISPCNT_MODE_3 (3<<0)
#define DISPCNT_MODE_4 (4<<0)
#define DISPCNT_MODE_5 (5<<0)
#define DISPCNT_MODE_6 (6<<0) // Engine A only
#define DISPCNT_MODE_MASK (7<<0)
#define DISPCNT_3D (1<<3) // Engine A only
#define DISPCNT_OBJ_MAPPING_2D (0<<4)
#define DISPCNT_OBJ_MAPPING_1D (1<<4)
#define DISPCNT_BMOBJ_MAPPING_2D_128 (0<<5)
#define DISPCNT_BMOBJ_MAPPING_2D_256 (1<<5)
#define DISPCNT_BMOBJ_MAPPING_1D (2<<5)
#define DISPCNT_BLANK (1<<7)
#define DISPCNT_BG0_ON (1<<8)
#define DISPCNT_BG1_ON (1<<9)
#define DISPCNT_BG2_ON (1<<10)
#define DISPCNT_BG3_ON (1<<11)
#define DISPCNT_OBJ_ON (1<<12)
#define DISPCNT_WINDOW_0_ON (1<<13)
#define DISPCNT_WINDOW_1_ON (1<<14)
#define DISPCNT_OBJ_WINDOW_ON (1<<15)
#define DISPCNT_OFF (0<<16)
#define DISPCNT_ON (1<<16)
#define DISPCNT_VRAM (2<<16) // Engine A only
#define DISPCNT_FIFO (3<<16) // Engine A only
#define DISPCNT_VRAM_BLOCK_0 (0<<18)
#define DISPCNT_VRAM_BLOCK_1 (1<<18)
#define DISPCNT_VRAM_BLOCK_2 (2<<18)
#define DISPCNT_VRAM_BLOCK_3 (3<<18)
#define DISPCNT_OBJ_1D_SIZE_32K (0<<20)
#define DISPCNT_OBJ_1D_SIZE_64K (1<<20)
#define DISPCNT_OBJ_1D_SIZE_128K (2<<20)
#define DISPCNT_OBJ_1D_SIZE_256K (3<<20)
#define DISPCNT_BMOBJ_1D_SIZE_128K (0<<22)
#define DISPCNT_BMOBJ_1D_SIZE_256K (1<<22)
#define DISPCNT_OBJ_HBLANK (1<<23)
#define DISPCNT_CHAR_BASE(n) (((n)&7)<<24)
#define DISPCNT_CHAR_BASE_0K DISPCNT_CHAR_BASE(0)
#define DISPCNT_CHAR_BASE_64K DISPCNT_CHAR_BASE(1)
#define DISPCNT_CHAR_BASE_128K DISPCNT_CHAR_BASE(2)
#define DISPCNT_CHAR_BASE_192K DISPCNT_CHAR_BASE(3)
#define DISPCNT_CHAR_BASE_256K DISPCNT_CHAR_BASE(4)
#define DISPCNT_CHAR_BASE_320K DISPCNT_CHAR_BASE(5)
#define DISPCNT_CHAR_BASE_384K DISPCNT_CHAR_BASE(6)
#define DISPCNT_CHAR_BASE_448K DISPCNT_CHAR_BASE(7)
#define DISPCNT_SCREEN_BASE(n) (((n)&7)<<27)
#define DISPCNT_SCREEN_BASE_0K DISPCNT_SCREEN_BASE(0)
#define DISPCNT_SCREEN_BASE_64K DISPCNT_SCREEN_BASE(1)
#define DISPCNT_SCREEN_BASE_128K DISPCNT_SCREEN_BASE(2)
#define DISPCNT_SCREEN_BASE_192K DISPCNT_SCREEN_BASE(3)
#define DISPCNT_SCREEN_BASE_256K DISPCNT_SCREEN_BASE(4)
#define DISPCNT_SCREEN_BASE_320K DISPCNT_SCREEN_BASE(5)
#define DISPCNT_SCREEN_BASE_384K DISPCNT_SCREEN_BASE(6)
#define DISPCNT_SCREEN_BASE_448K DISPCNT_SCREEN_BASE(7)
#define DISPCNT_OBJ_EXT_PALETTE (1<<31)
#define DISPCNT_BG_EXT_PALETTE (1<<30)
// Interrupts and status
#define DISPSTAT ARM9_REG16(0x04000004)
#define VCOUNT ARM9_REG16(0x04000006)
#define DISPSTAT_VBLANK (1<<0)
#define DISPSTAT_HBLANK (1<<1)
#define DISPSTAT_VCOUNT (1<<2)
#define DISPSTAT_VBLANK_IRQ (1<<3)
#define DISPSTAT_HBLANK_IRQ (1<<4)
#define DISPSTAT_VCOUNT_IRQ (1<<5)
// BG control
#define BG0CNT_A ARM9_REG16(0x04000008)
#define BG1CNT_A ARM9_REG16(0x0400000a)
#define BG2CNT_A ARM9_REG16(0x0400000c)
#define BG3CNT_A ARM9_REG16(0x0400000e)
#define BG0CNT_B ARM9_REG16(0x04001008)
#define BG1CNT_B ARM9_REG16(0x0400100a)
#define BG2CNT_B ARM9_REG16(0x0400100c)
#define BG3CNT_B ARM9_REG16(0x0400100e)
#define BGxCNT_PRIORITY_0 (0<<0)
#define BGxCNT_PRIORITY_1 (1<<0)
#define BGxCNT_PRIORITY_2 (2<<0)
#define BGxCNT_PRIORITY_3 (3<<0)
#define BGxCNT_PRIORITY_MASK (3<<0)
#define BGxCNT_CHAR_BASE(n) (((n)&0xf)<<2)
#define BGxCNT_CHAR_BASE_0K BGxCNT_CHAR_BASE(0)
#define BGxCNT_CHAR_BASE_16K BGxCNT_CHAR_BASE(1)
#define BGxCNT_CHAR_BASE_32K BGxCNT_CHAR_BASE(2)
#define BGxCNT_CHAR_BASE_48K BGxCNT_CHAR_BASE(3)
#define BGxCNT_CHAR_BASE_64K BGxCNT_CHAR_BASE(4)
#define BGxCNT_CHAR_BASE_80K BGxCNT_CHAR_BASE(5)
#define BGxCNT_CHAR_BASE_96K BGxCNT_CHAR_BASE(6)
#define BGxCNT_CHAR_BASE_112K BGxCNT_CHAR_BASE(7)
#define BGxCNT_CHAR_BASE_128K BGxCNT_CHAR_BASE(8)
#define BGxCNT_CHAR_BASE_144K BGxCNT_CHAR_BASE(9)
#define BGxCNT_CHAR_BASE_160K BGxCNT_CHAR_BASE(10)
#define BGxCNT_CHAR_BASE_176K BGxCNT_CHAR_BASE(11)
#define BGxCNT_CHAR_BASE_192K BGxCNT_CHAR_BASE(12)
#define BGxCNT_CHAR_BASE_208K BGxCNT_CHAR_BASE(13)
#define BGxCNT_CHAR_BASE_224K BGxCNT_CHAR_BASE(14)
#define BGxCNT_CHAR_BASE_240K BGxCNT_CHAR_BASE(15)
#define BGxCNT_MOSAIC (1<<6)
#define BGxCNT_TEXT_16_COLOURS (0<<7)
#define BGxCNT_TEXT_256_COLOURS (1<<7)
#define BGxCNT_EXTENDED_TILES 0x00
#define BGxCNT_EXTENDED_BITMAP_8 0x80
#define BGxCNT_EXTENDED_BITMAP_16 0x84
#define BGxCNT_SCREEN_BASE(n) (((n)&0x1f)<<8)
#define BGxCNT_TILE_BASE_0K BGxCNT_SCREEN_BASE(0)
#define BGxCNT_TILE_BASE_2K BGxCNT_SCREEN_BASE(1)
#define BGxCNT_TILE_BASE_4K BGxCNT_SCREEN_BASE(2)
#define BGxCNT_TILE_BASE_6K BGxCNT_SCREEN_BASE(3)
#define BGxCNT_TILE_BASE_8K BGxCNT_SCREEN_BASE(4)
#define BGxCNT_TILE_BASE_10K BGxCNT_SCREEN_BASE(5)
#define BGxCNT_TILE_BASE_12K BGxCNT_SCREEN_BASE(6)
#define BGxCNT_TILE_BASE_14K BGxCNT_SCREEN_BASE(7)
#define BGxCNT_TILE_BASE_16K BGxCNT_SCREEN_BASE(8)
#define BGxCNT_TILE_BASE_18K BGxCNT_SCREEN_BASE(9)
#define BGxCNT_TILE_BASE_20K BGxCNT_SCREEN_BASE(10)
#define BGxCNT_TILE_BASE_22K BGxCNT_SCREEN_BASE(11)
#define BGxCNT_TILE_BASE_24K BGxCNT_SCREEN_BASE(12)
#define BGxCNT_TILE_BASE_26K BGxCNT_SCREEN_BASE(13)
#define BGxCNT_TILE_BASE_28K BGxCNT_SCREEN_BASE(14)
#define BGxCNT_TILE_BASE_30K BGxCNT_SCREEN_BASE(15)
#define BGxCNT_TILE_BASE_32K BGxCNT_SCREEN_BASE(16)
#define BGxCNT_TILE_BASE_34K BGxCNT_SCREEN_BASE(17)
#define BGxCNT_TILE_BASE_36K BGxCNT_SCREEN_BASE(18)
#define BGxCNT_TILE_BASE_38K BGxCNT_SCREEN_BASE(19)
#define BGxCNT_TILE_BASE_40K BGxCNT_SCREEN_BASE(20)
#define BGxCNT_TILE_BASE_42K BGxCNT_SCREEN_BASE(21)
#define BGxCNT_TILE_BASE_44K BGxCNT_SCREEN_BASE(22)
#define BGxCNT_TILE_BASE_46K BGxCNT_SCREEN_BASE(23)
#define BGxCNT_TILE_BASE_48K BGxCNT_SCREEN_BASE(24)
#define BGxCNT_TILE_BASE_50K BGxCNT_SCREEN_BASE(25)
#define BGxCNT_TILE_BASE_52K BGxCNT_SCREEN_BASE(26)
#define BGxCNT_TILE_BASE_54K BGxCNT_SCREEN_BASE(27)
#define BGxCNT_TILE_BASE_56K BGxCNT_SCREEN_BASE(28)
#define BGxCNT_TILE_BASE_58K BGxCNT_SCREEN_BASE(29)
#define BGxCNT_TILE_BASE_60K BGxCNT_SCREEN_BASE(30)
#define BGxCNT_TILE_BASE_62K BGxCNT_SCREEN_BASE(31)
#define BGxCNT_BITMAP_BASE_0K BGxCNT_SCREEN_BASE(0)
#define BGxCNT_BITMAP_BASE_16K BGxCNT_SCREEN_BASE(1)
#define BGxCNT_BITMAP_BASE_32K BGxCNT_SCREEN_BASE(2)
#define BGxCNT_BITMAP_BASE_48K BGxCNT_SCREEN_BASE(3)
#define BGxCNT_BITMAP_BASE_64K BGxCNT_SCREEN_BASE(4)
#define BGxCNT_BITMAP_BASE_80K BGxCNT_SCREEN_BASE(5)
#define BGxCNT_BITMAP_BASE_96K BGxCNT_SCREEN_BASE(6)
#define BGxCNT_BITMAP_BASE_112K BGxCNT_SCREEN_BASE(7)
#define BGxCNT_BITMAP_BASE_128K BGxCNT_SCREEN_BASE(8)
#define BGxCNT_BITMAP_BASE_144K BGxCNT_SCREEN_BASE(9)
#define BGxCNT_BITMAP_BASE_160K BGxCNT_SCREEN_BASE(10)
#define BGxCNT_BITMAP_BASE_176K BGxCNT_SCREEN_BASE(11)
#define BGxCNT_BITMAP_BASE_192K BGxCNT_SCREEN_BASE(12)
#define BGxCNT_BITMAP_BASE_208K BGxCNT_SCREEN_BASE(13)
#define BGxCNT_BITMAP_BASE_224K BGxCNT_SCREEN_BASE(14)
#define BGxCNT_BITMAP_BASE_240K BGxCNT_SCREEN_BASE(15)
#define BGxCNT_BITMAP_BASE_256K BGxCNT_SCREEN_BASE(16)
#define BGxCNT_BITMAP_BASE_272K BGxCNT_SCREEN_BASE(17)
#define BGxCNT_BITMAP_BASE_288K BGxCNT_SCREEN_BASE(18)
#define BGxCNT_BITMAP_BASE_304K BGxCNT_SCREEN_BASE(19)
#define BGxCNT_BITMAP_BASE_320K BGxCNT_SCREEN_BASE(20)
#define BGxCNT_BITMAP_BASE_336K BGxCNT_SCREEN_BASE(21)
#define BGxCNT_BITMAP_BASE_352K BGxCNT_SCREEN_BASE(22)
#define BGxCNT_BITMAP_BASE_368K BGxCNT_SCREEN_BASE(23)
#define BGxCNT_BITMAP_BASE_384K BGxCNT_SCREEN_BASE(24)
#define BGxCNT_BITMAP_BASE_400K BGxCNT_SCREEN_BASE(25)
#define BGxCNT_BITMAP_BASE_416K BGxCNT_SCREEN_BASE(26)
#define BGxCNT_BITMAP_BASE_432K BGxCNT_SCREEN_BASE(27)
#define BGxCNT_BITMAP_BASE_448K BGxCNT_SCREEN_BASE(28)
#define BGxCNT_BITMAP_BASE_464K BGxCNT_SCREEN_BASE(29)
#define BGxCNT_BITMAP_BASE_480K BGxCNT_SCREEN_BASE(30)
#define BGxCNT_BITMAP_BASE_496K BGxCNT_SCREEN_BASE(31)
#define BGxCNT_OVERFLOW_TRANSPARENT (0<<13)
#define BGxCNT_OVERFLOW_WRAP (1<<13)
#define BGxCNT_ALTERNATE_PALETTE_SLOT (1<<13) // BG0 and BG1 only
#define BGxCNT_TEXT_SIZE_256x256 (0<<14)
#define BGxCNT_TEXT_SIZE_512x256 (1<<14)
#define BGxCNT_TEXT_SIZE_256x512 (2<<14)
#define BGxCNT_TEXT_SIZE_512x512 (3<<14)
#define BGxCNT_AFFINE_SIZE_128x128 (0<<14)
#define BGxCNT_AFFINE_SIZE_256x256 (1<<14)
#define BGxCNT_AFFINE_SIZE_512x512 (2<<14)
#define BGxCNT_AFFINE_SIZE_1024x1024 (3<<14)
#define BGxCNT_BITMAP_SIZE_128x128 (0<<14)
#define BGxCNT_BITMAP_SIZE_256x256 (1<<14)
#define BGxCNT_BITMAP_SIZE_512x256 (2<<14)
#define BGxCNT_BITMAP_SIZE_512x512 (3<<14)
#define BGxCNT_LARGE_SIZE_512x1024 (0<<14)
#define BGxCNT_LARGE_SIZE_1024x512 (1<<14)
// BG scrolling
#define BG0HOFS_A ARM9_REG16(0x04000010)
#define BG0VOFS_A ARM9_REG16(0x04000012)
#define BG1HOFS_A ARM9_REG16(0x04000014)
#define BG1VOFS_A ARM9_REG16(0x04000016)
#define BG2HOFS_A ARM9_REG16(0x04000018)
#define BG2VOFS_A ARM9_REG16(0x0400001a)
#define BG3HOFS_A ARM9_REG16(0x0400001c)
#define BG3VOFS_A ARM9_REG16(0x0400001e)
#define BG0HOFS_B ARM9_REG16(0x04001010)
#define BG0VOFS_B ARM9_REG16(0x04001012)
#define BG1HOFS_B ARM9_REG16(0x04001014)
#define BG1VOFS_B ARM9_REG16(0x04001016)
#define BG2HOFS_B ARM9_REG16(0x04001018)
#define BG2VOFS_B ARM9_REG16(0x0400101a)
#define BG3HOFS_B ARM9_REG16(0x0400101c)
#define BG3VOFS_B ARM9_REG16(0x0400101e)
// BG rotation and scaling
#define BG2PA_A ARM9_REG16(0x04000020)
#define BG2PB_A ARM9_REG16(0x04000022)
#define BG2PC_A ARM9_REG16(0x04000024)
#define BG2PD_A ARM9_REG16(0x04000026)
#define BG2X_L_A ARM9_REG16(0x04000028)
#define BG2X_H_A ARM9_REG16(0x0400002a)
#define BG2Y_L_A ARM9_REG16(0x0400002c)
#define BG2Y_H_A ARM9_REG16(0x0400002e)
#define BG2X_A ARM9_REG32(0x04000028)
#define BG2Y_A ARM9_REG32(0x0400002C)
#define BG2PA_B ARM9_REG16(0x04001020)
#define BG2PB_B ARM9_REG16(0x04001022)
#define BG2PC_B ARM9_REG16(0x04001024)
#define BG2PD_B ARM9_REG16(0x04001026)
#define BG2X_L_B ARM9_REG16(0x04001028)
#define BG2X_H_B ARM9_REG16(0x0400102a)
#define BG2Y_L_B ARM9_REG16(0x0400102c)
#define BG2Y_H_B ARM9_REG16(0x0400102e)
#define BG2X_B ARM9_REG32(0x04001028)
#define BG2Y_B ARM9_REG32(0x0400102C)
#define BG3PA_A ARM9_REG16(0x04000030)
#define BG3PB_A ARM9_REG16(0x04000032)
#define BG3PC_A ARM9_REG16(0x04000034)
#define BG3PD_A ARM9_REG16(0x04000036)
#define BG3X_L_A ARM9_REG16(0x04000038)
#define BG3X_H_A ARM9_REG16(0x0400003a)
#define BG3Y_L_A ARM9_REG16(0x0400003c)
#define BG3Y_H_A ARM9_REG16(0x0400003e)
#define BG3X_A ARM9_REG32(0x04000038)
#define BG3Y_A ARM9_REG32(0x0400003C)
#define BG3PA_B ARM9_REG16(0x04001030)
#define BG3PB_B ARM9_REG16(0x04001032)
#define BG3PC_B ARM9_REG16(0x04001034)
#define BG3PD_B ARM9_REG16(0x04001036)
#define BG3X_L_B ARM9_REG16(0x04001038)
#define BG3X_H_B ARM9_REG16(0x0400103a)
#define BG3Y_L_B ARM9_REG16(0x0400103c)
#define BG3Y_H_B ARM9_REG16(0x0400103e)
#define BG3X_B ARM9_REG32(0x04001038)
#define BG3Y_B ARM9_REG32(0x0400103C)
#define WIN0H_A ARM9_REG16(0x04000040)
#define WIN1H_A ARM9_REG16(0x04000042)
#define WIN0V_A ARM9_REG16(0x04000044)
#define WIN1V_A ARM9_REG16(0x04000046)
#define WININ_A ARM9_REG16(0x04000048)
#define WINOUT_A ARM9_REG16(0x0400004a)
#define WIN0H_B ARM9_REG16(0x04001040)
#define WIN1H_B ARM9_REG16(0x04001042)
#define WIN0V_B ARM9_REG16(0x04001044)
#define WIN1V_B ARM9_REG16(0x04001046)
#define WININ_B ARM9_REG16(0x04001048)
#define WINOUT_B ARM9_REG16(0x0400104a)
#define WININ_WIN0_BG0 (1<<0)
#define WININ_WIN0_BG1 (1<<1)
#define WININ_WIN0_BG2 (1<<2)
#define WININ_WIN0_BG3 (1<<3)
#define WININ_WIN0_OBJ (1<<4)
#define WININ_WIN0_COLOUR (1<<5)
#define WININ_WIN1_BG0 (1<<8)
#define WININ_WIN1_BG1 (1<<9)
#define WININ_WIN1_BG2 (1<<10)
#define WININ_WIN1_BG3 (1<<11)
#define WININ_WIN1_OBJ (1<<12)
#define WININ_WIN1_COLOUR (1<<13)
#define WINOUT_WIN0_BG0 (1<<0)
#define WINOUT_WIN0_BG1 (1<<1)
#define WINOUT_WIN0_BG2 (1<<2)
#define WINOUT_WIN0_BG3 (1<<3)
#define WINOUT_WIN0_OBJ (1<<4)
#define WINOUT_WIN0_COLOUR (1<<5)
#define WINOUT_WIN1_BG0 (1<<8)
#define WINOUT_WIN1_BG1 (1<<9)
#define WINOUT_WIN1_BG2 (1<<10)
#define WINOUT_WIN1_BG3 (1<<11)
#define WINOUT_WIN1_OBJ (1<<12)
#define WINOUT_WIN1_COLOUR (1<<13)
#define MOSAIC_A ARM9_REG16(0x0400004c)
#define MOSAIC_B ARM9_REG16(0x0400104c)
#define MOSAIC_BG_H_SIZE(n) ((n-1)&0x0f)
#define MOSAIC_BG_V_SIZE(n) (((n-1)&0x0f)<<4)
#define MOSAIC_OBJ_H_SIZE(n) (((n-1)&0x0f)<<8)
#define MOSAIC_OBJ_V_SIZE(n) (((n-1)&0x0f)<<12)
#define MOSAIC_BG_SIZE(n) (((n-1)&0x0f)*0x11)
#define MOSAIC_OBJ_SIZE(n) (((n-1)&0x0f)*0x1100)
#define MOSAIC_SIZE(n) (((n-1)&0x0f)*0x1111)
#define BLDCNT_A ARM9_REG16(0x04000050)
#define BLDALPHA_A ARM9_REG16(0x04000052)
#define BLDY_A ARM9_REG16(0x04000054)
#define BLDCNT_B ARM9_REG16(0x04001050)
#define BLDALPHA_B ARM9_REG16(0x04001052)
#define BLDY_B ARM9_REG16(0x04001054)
#define BLDCNT_SRC_A_BG0 (1<<0)
#define BLDCNT_SRC_A_BG1 (1<<1)
#define BLDCNT_SRC_A_BG2 (1<<2)
#define BLDCNT_SRC_A_BG3 (1<<3)
#define BLDCNT_SRC_A_OBJ (1<<4)
#define BLDCNT_SRC_A_BD (1<<5)
#define BLDCNT_SRC_A_ALL_BG (15<<5)
#define BLDCNT_SRC_A_ALL (63<<5)
#define BLDCNT_EFFECT_NONE (0<<6)
#define BLDCNT_EFFECT_ALPHA (1<<6)
#define BLDCNT_EFFECT_BRIGHTEN (2<<6)
#define BLDCNT_EFFECT_DARKEN (3<<6)
#define BLDCNT_SRC_B_BG0 (1<<8)
#define BLDCNT_SRC_B_BG1 (1<<9)
#define BLDCNT_SRC_B_BG2 (1<<10)
#define BLDCNT_SRC_B_BG3 (1<<11)
#define BLDCNT_SRC_B_OBJ (1<<12)
#define BLDCNT_SRC_B_BD (1<<13)
#define BLDCNT_SRC_B_ALL_BG (15<<13)
#define BLDCNT_SRC_B_ALL (63<<13)
#define BLDALPHA_EVA(n) (((n)&0x1f)<<0)
#define BLDALPHA_EVB(n) (((n)&0x1f)<<8)
#define DISP3DCNT ARM9_REG16(0x4000060)
#define DISPCAPCNT ARM9_REG32(0x4000064)
#define DISPCAPCNT_EVA(n) (((n)&0x1f)<<0)
#define DISPCAPCNT_EVB(n) (((n)&0x1f)<<8)
#define DISPCAPCNT_WRITE_VRAM_A (0<<16)
#define DISPCAPCNT_WRITE_VRAM_B (1<<16)
#define DISPCAPCNT_WRITE_VRAM_C (2<<16)
#define DISPCAPCNT_WRITE_VRAM_D (3<<16)
#define DISPCAPCNT_WRITE_OFFS_0K (0<<18)
#define DISPCAPCNT_WRITE_OFFS_32K (1<<18)
#define DISPCAPCNT_WRITE_OFFS_64K (2<<18)
#define DISPCAPCNT_WRITE_OFFS_96K (3<<18)
#define DISPCAPCNT_SIZE_128x128 (0<<20)
#define DISPCAPCNT_SIZE_256x64 (1<<20)
#define DISPCAPCNT_SIZE_256x128 (2<<20)
#define DISPCAPCNT_SIZE_256x192 (3<<20)
#define DISPCAPCNT_SRC_A_SCREEN (0<<24)
#define DISPCAPCNT_SRC_A_3D (1<<24)
#define DISPCAPCNT_SRC_B_VRAM (0<<25)
#define DISPCAPCNT_SRC_B_FIFO (1<<25)
#define DISPCAPCNT_READ_OFFS_0K (0<<26)
#define DISPCAPCNT_READ_OFFS_32K (1<<26)
#define DISPCAPCNT_READ_OFFS_64K (2<<26)
#define DISPCAPCNT_READ_OFFS_96K (3<<26)
#define DISPCAPCNT_SRC_A (0<<29)
#define DISPCAPCNT_SRC_B (1<<29)
#define DISPCAPCNT_SRC_A_B (2<<29)
#define DISPCAPCNT_ENABLE (1<<31)
#define DISP_MMEM_FIFO ARM9_REG32(0x4000068)
#define MASTER_BRIGHT_A ARM9_REG16(0x400006c)
#define MASTER_BRIGHT_B ARM9_REG16(0x400106c)
#define LOVE_COLOURED_MASTER_BRIGHT_A MASTER_BRIGHT_A
#define LOVE_COLOURED_MASTER_BRIGHT_B MASTER_BRIGHT_B
#define MASTER_BRIGHT_FACTOR(n) (((n)&0x1f)*0x101)
#define MASTER_BRIGHT_DISABLE 0
#define MASTER_BRIGHT_UP (1<<14)
#define MASTER_BRIGHT_DOWN (2<<14)
//
// OAM attributes
//
#define OBJ_0_Y(y) ((y)&0xff)
#define OBJ_0_ROTSCALE (1<<8)
#define OBJ_0_DISABLE (2<<8)
#define OBJ_0_ROTSCALE_DOUBLE (3<<8)
#define OBJ_0_TRANSPARENT (1<<10)
#define OBJ_0_WINDOW (2<<10)
#define OBJ_0_BITMAP (3<<10)
#define OBJ_0_MOSAIC (1<<12)
#define OBJ_0_16_COLOURS (0<<13)
#define OBJ_0_256_COLOURS (1<<13)
#define OBJ_0_SQUARE (0<<14)
#define OBJ_0_HORIZONTAL (1<<14)
#define OBJ_0_VERTICAL (2<<14)
#define OBJ_0_SIZE_8x8 OBJ_0_SQUARE
#define OBJ_0_SIZE_16x16 OBJ_0_SQUARE
#define OBJ_0_SIZE_32x32 OBJ_0_SQUARE
#define OBJ_0_SIZE_64x64 OBJ_0_SQUARE
#define OBJ_0_SIZE_16x8 OBJ_0_HORIZONTAL
#define OBJ_0_SIZE_32x8 OBJ_0_HORIZONTAL
#define OBJ_0_SIZE_32x16 OBJ_0_HORIZONTAL
#define OBJ_0_SIZE_64x32 OBJ_0_HORIZONTAL
#define OBJ_0_SIZE_8x16 OBJ_0_VERTICAL
#define OBJ_0_SIZE_8x32 OBJ_0_VERTICAL
#define OBJ_0_SIZE_16x32 OBJ_0_VERTICAL
#define OBJ_0_SIZE_32x64 OBJ_0_VERTICAL
#define OBJ_1_X(x) ((x)&0x1ff)
#define OBJ_1_ROTSCALE_PARAMS(n) (((n)&0x1f)<<9)
#define OBJ_1_HORIZ_FLIP (1<<12)
#define OBJ_1_VERT_FLIP (1<<13)
#define OBJ_1_SIZE_0 (0<<14)
#define OBJ_1_SIZE_1 (1<<14)
#define OBJ_1_SIZE_2 (2<<14)
#define OBJ_1_SIZE_3 (3<<14)
#define OBJ_1_SIZE_8x8 OBJ_1_SIZE_0
#define OBJ_1_SIZE_16x16 OBJ_1_SIZE_1
#define OBJ_1_SIZE_32x32 OBJ_1_SIZE_2
#define OBJ_1_SIZE_64x64 OBJ_1_SIZE_3
#define OBJ_1_SIZE_16x8 OBJ_1_SIZE_0
#define OBJ_1_SIZE_32x8 OBJ_1_SIZE_1
#define OBJ_1_SIZE_32x16 OBJ_1_SIZE_2
#define OBJ_1_SIZE_64x32 OBJ_1_SIZE_3
#define OBJ_1_SIZE_8x16 OBJ_1_SIZE_0
#define OBJ_1_SIZE_8x32 OBJ_1_SIZE_1
#define OBJ_1_SIZE_16x32 OBJ_1_SIZE_2
#define OBJ_1_SIZE_32x64 OBJ_1_SIZE_3
#define OBJ_2_CHAR(x) ((x)&0x3ff)
#define OBJ_2_PRIORITY_0 (0<<10)
#define OBJ_2_PRIORITY_1 (1<<10)
#define OBJ_2_PRIORITY_2 (2<<10)
#define OBJ_2_PRIORITY_3 (3<<10)
#define OBJ_2_PALETTE(n) (((n)&0x0f)<<12)
#define OBJ_2_ALPHA(n) OBJ_2_PALETTE(n)
// DMA
#define DMA0SAD REGCPTR(0x40000b0)
#define DMA0DAD REGPTR(0x40000b4)
#define DMA0CNT REG32(0x40000b8)
#define DMA1SAD REGCPTR(0x40000bc)
#define DMA1DAD REGPTR(0x40000c0)
#define DMA1CNT REG32(0x40000c4)
#define DMA2SAD REGCPTR(0x40000c8)
#define DMA2DAD REGPTR(0x40000cc)
#define DMA2CNT REG32(0x40000d0)
#define DMA3SAD REGCPTR(0x40000d4)
#define DMA3DAD REGPTR(0x40000d8)
#define DMA3CNT REG32(0x40000dc)
#define DMAxCNT_DEST_INC (0<<21)
#define DMAxCNT_DEST_DEC (1<<21)
#define DMAxCNT_DEST_FIX (2<<21)
#define DMAxCNT_DEST_INC_RELOAD (3<<21)
#define DMAxCNT_SRC_INC (0<<23)
#define DMAxCNT_SRC_DEC (1<<23)
#define DMAxCNT_SRC_FIX (2<<23)
#define DMAxCNT_REPEAT (1<<25)
#define DMAxCNT_16_BIT (0<<26)
#define DMAxCNT_32_BIT (1<<26)
#define DMAxCNT_START_NOW (0<<27)
#define DMAxCNT_START_CARD (5<<27)
#define DMAxCNT_START_VBLANK (1<<27)
#ifdef ARM9
#define DMAxCNT_START_HBLANK (2<<27)
#define DMAxCNT_START_FIFO (7<<27)
//#define DMAxCNT_DISP_FIFO (4<<27) // what?
#endif
#define DMAxCNT_END_IRQ (1<<30)
#define DMAxCNT_ENABLE (1<<31)
//
// Timers
//
#define TM0CNT_L REG16(0x4000100)
#define TM0CNT_H REG16(0x4000102)
#define TM1CNT_L REG16(0x4000104)
#define TM1CNT_H REG16(0x4000106)
#define TM2CNT_L REG16(0x4000108)
#define TM2CNT_H REG16(0x400010a)
#define TM3CNT_L REG16(0x400010c)
#define TM3CNT_H REG16(0x400010e)
#define TMxCNT_H_DIV_1 0
#define TMxCNT_H_DIV_64 1
#define TMxCNT_H_DIV_256 2
#define TMxCNT_H_DIV_1024 3
#define TMxCNT_H_COUNT_UP (1<<2)
#define TMxCNT_H_IRQ_ENABLE (1<<6)
#define TMxCNT_H_START (1<<7)
//
// Other hardware
//
#define KEYINPUT REG16(0x4000130)
#define KEYCNT REG16(0x4000132)
#define KEYINPUT_A (1<<0)
#define KEYINPUT_B (1<<1)
#define KEYINPUT_SELECT (1<<2)
#define KEYINPUT_START (1<<3)
#define KEYINPUT_RIGHT (1<<4)
#define KEYINPUT_LEFT (1<<5)
#define KEYINPUT_UP (1<<6)
#define KEYINPUT_DOWN (1<<7)
#define KEYINPUT_R (1<<8)
#define KEYINPUT_L (1<<9)
#define KEYINPUT_X (1<<0) // NOTE: untested
#define KEYINPUT_Y (1<<1)
//
// Memory control
//
#define VRAMCNT_A ARM9_REG8(0x4000240)
#define VRAMCNT_B ARM9_REG8(0x4000241)
#define VRAMCNT_C ARM9_REG8(0x4000242)
#define VRAMCNT_D ARM9_REG8(0x4000243)
#define VRAMCNT_E ARM9_REG8(0x4000244)
#define VRAMCNT_F ARM9_REG8(0x4000245)
#define VRAMCNT_G ARM9_REG8(0x4000246)
#define VRAMCNT_H ARM9_REG8(0x4000248)
#define VRAMCNT_I ARM9_REG8(0x4000249)
#define VRAMCNT_OFFSET_0 (0<<3)
#define VRAMCNT_OFFSET_1 (1<<3)
#define VRAMCNT_OFFSET_2 (2<<3)
#define VRAMCNT_OFFSET_3 (3<<3)
#define VRAMCNT_DISABLE (0<<7)
#define VRAMCNT_ENABLE (1<<7)
#define VRAMCNT_A_LCDC (0|VRAMCNT_ENABLE)
#define VRAMCNT_A_BG_VRAM_A (1|VRAMCNT_OFFSET_0|VRAMCNT_ENABLE)
#define VRAMCNT_A_BG_VRAM_A_OFFS_0K (1|VRAMCNT_OFFSET_0|VRAMCNT_ENABLE)
#define VRAMCNT_A_BG_VRAM_A_OFFS_128K (1|VRAMCNT_OFFSET_1|VRAMCNT_ENABLE)
#define VRAMCNT_A_BG_VRAM_A_OFFS_256K (1|VRAMCNT_OFFSET_2|VRAMCNT_ENABLE)
#define VRAMCNT_A_BG_VRAM_A_OFFS_384K (1|VRAMCNT_OFFSET_3|VRAMCNT_ENABLE)
#define VRAMCNT_A_OBJ_VRAM_A (2|VRAMCNT_OFFSET_0|VRAMCNT_ENABLE)
#define VRAMCNT_A_OBJ_VRAM_A_OFFS_0K (2|VRAMCNT_OFFSET_0|VRAMCNT_ENABLE)
#define VRAMCNT_A_OBJ_VRAM_A_OFFS_128K (2|VRAMCNT_OFFSET_1|VRAMCNT_ENABLE)
#define VRAMCNT_A_TEXTURE (3|VRAMCNT_OFFSET_0|VRAMCNT_ENABLE)
#define VRAMCNT_A_TEXTURE_OFFS_0K (3|VRAMCNT_OFFSET_0|VRAMCNT_ENABLE)
#define VRAMCNT_A_TEXTURE_OFFS_128K (3|VRAMCNT_OFFSET_1|VRAMCNT_ENABLE)
#define VRAMCNT_A_TEXTURE_OFFS_256K (3|VRAMCNT_OFFSET_2|VRAMCNT_ENABLE)
#define VRAMCNT_A_TEXTURE_OFFS_384K (3|VRAMCNT_OFFSET_3|VRAMCNT_ENABLE)
#define VRAMCNT_B_LCDC (0|VRAMCNT_ENABLE)
#define VRAMCNT_B_BG_VRAM_A (1|VRAMCNT_OFFSET_0|VRAMCNT_ENABLE)
#define VRAMCNT_B_BG_VRAM_A_OFFS_0K (1|VRAMCNT_OFFSET_0|VRAMCNT_ENABLE)
#define VRAMCNT_B_BG_VRAM_A_OFFS_128K (1|VRAMCNT_OFFSET_1|VRAMCNT_ENABLE)
#define VRAMCNT_B_BG_VRAM_A_OFFS_256K (1|VRAMCNT_OFFSET_2|VRAMCNT_ENABLE)
#define VRAMCNT_B_BG_VRAM_A_OFFS_384K (1|VRAMCNT_OFFSET_3|VRAMCNT_ENABLE)
#define VRAMCNT_B_OBJ_VRAM_A (2|VRAMCNT_OFFSET_0|VRAMCNT_ENABLE)
#define VRAMCNT_B_OBJ_VRAM_A_OFFS_0K (2|VRAMCNT_OFFSET_0|VRAMCNT_ENABLE)
#define VRAMCNT_B_OBJ_VRAM_A_OFFS_128K (2|VRAMCNT_OFFSET_1|VRAMCNT_ENABLE)
#define VRAMCNT_B_TEXTURE (3|VRAMCNT_OFFSET_1|VRAMCNT_ENABLE)
#define VRAMCNT_B_TEXTURE_OFFS_0K (3|VRAMCNT_OFFSET_0|VRAMCNT_ENABLE)
#define VRAMCNT_B_TEXTURE_OFFS_128K (3|VRAMCNT_OFFSET_1|VRAMCNT_ENABLE)
#define VRAMCNT_B_TEXTURE_OFFS_256K (3|VRAMCNT_OFFSET_2|VRAMCNT_ENABLE)
#define VRAMCNT_B_TEXTURE_OFFS_384K (3|VRAMCNT_OFFSET_3|VRAMCNT_ENABLE)
#define VRAMCNT_C_LCDC (0|VRAMCNT_ENABLE)
#define VRAMCNT_C_BG_VRAM_A (1|VRAMCNT_OFFSET_0|VRAMCNT_ENABLE)
#define VRAMCNT_C_BG_VRAM_A_OFFS_0K (1|VRAMCNT_OFFSET_0|VRAMCNT_ENABLE)
#define VRAMCNT_C_BG_VRAM_A_OFFS_128K (1|VRAMCNT_OFFSET_1|VRAMCNT_ENABLE)
#define VRAMCNT_C_BG_VRAM_A_OFFS_256K (1|VRAMCNT_OFFSET_2|VRAMCNT_ENABLE)
#define VRAMCNT_C_BG_VRAM_A_OFFS_384K (1|VRAMCNT_OFFSET_3|VRAMCNT_ENABLE)
#define VRAMCNT_C_ARM7 (2|VRAMCNT_OFFSET_0|VRAMCNT_ENABLE)
#define VRAMCNT_C_ARM7_OFFS_0K (2|VRAMCNT_OFFSET_0|VRAMCNT_ENABLE)
#define VRAMCNT_C_ARM7_OFFS_128K (2|VRAMCNT_OFFSET_1|VRAMCNT_ENABLE)
#define VRAMCNT_C_TEXTURE (3|VRAMCNT_OFFSET_2|VRAMCNT_ENABLE)
#define VRAMCNT_C_TEXTURE_OFFS_0K (3|VRAMCNT_OFFSET_0|VRAMCNT_ENABLE)
#define VRAMCNT_C_TEXTURE_OFFS_128K (3|VRAMCNT_OFFSET_1|VRAMCNT_ENABLE)
#define VRAMCNT_C_TEXTURE_OFFS_256K (3|VRAMCNT_OFFSET_2|VRAMCNT_ENABLE)
#define VRAMCNT_C_TEXTURE_OFFS_384K (3|VRAMCNT_OFFSET_3|VRAMCNT_ENABLE)
#define VRAMCNT_C_BG_VRAM_B (4|VRAMCNT_ENABLE)
#define VRAMCNT_D_LCDC (0|VRAMCNT_ENABLE)
#define VRAMCNT_D_BG_VRAM_A (1|VRAMCNT_OFFSET_0|VRAMCNT_ENABLE)
#define VRAMCNT_D_BG_VRAM_A_OFFS_0K (1|VRAMCNT_OFFSET_0|VRAMCNT_ENABLE)
#define VRAMCNT_D_BG_VRAM_A_OFFS_128K (1|VRAMCNT_OFFSET_1|VRAMCNT_ENABLE)
#define VRAMCNT_D_BG_VRAM_A_OFFS_256K (1|VRAMCNT_OFFSET_2|VRAMCNT_ENABLE)
#define VRAMCNT_D_BG_VRAM_A_OFFS_384K (1|VRAMCNT_OFFSET_3|VRAMCNT_ENABLE)
#define VRAMCNT_D_ARM7 (2|VRAMCNT_OFFSET_0|VRAMCNT_ENABLE)
#define VRAMCNT_D_ARM7_OFFS_0K (2|VRAMCNT_OFFSET_0|VRAMCNT_ENABLE)
#define VRAMCNT_D_ARM7_OFFS_128K (2|VRAMCNT_OFFSET_1|VRAMCNT_ENABLE)
#define VRAMCNT_D_TEXTURE (3|VRAMCNT_OFFSET_3|VRAMCNT_ENABLE)
#define VRAMCNT_D_TEXTURE_OFFS_0K (3|VRAMCNT_OFFSET_0|VRAMCNT_ENABLE)
#define VRAMCNT_D_TEXTURE_OFFS_128K (3|VRAMCNT_OFFSET_1|VRAMCNT_ENABLE)
#define VRAMCNT_D_TEXTURE_OFFS_256K (3|VRAMCNT_OFFSET_2|VRAMCNT_ENABLE)
#define VRAMCNT_D_TEXTURE_OFFS_384K (3|VRAMCNT_OFFSET_3|VRAMCNT_ENABLE)
#define VRAMCNT_D_OBJ_VRAM_B (4|VRAMCNT_ENABLE)
#define VRAMCNT_E_LCDC (0|VRAMCNT_ENABLE)
#define VRAMCNT_E_BG_VRAM_A (1|VRAMCNT_ENABLE)
#define VRAMCNT_E_OBJ_VRAM_A (2|VRAMCNT_ENABLE)
#define VRAMCNT_E_TEXTURE_PALETTE (3|VRAMCNT_ENABLE)
#define VRAMCNT_E_BG_EXT_PALETTE_A (4|VRAMCNT_ENABLE)
#define VRAMCNT_F_LCDC (0|VRAMCNT_ENABLE)
#define VRAMCNT_F_BG_VRAM_A (1|VRAMCNT_OFFSET_0|VRAMCNT_ENABLE)
#define VRAMCNT_F_BG_VRAM_A_OFFS_0K (1|VRAMCNT_OFFSET_0|VRAMCNT_ENABLE)
#define VRAMCNT_F_BG_VRAM_A_OFFS_16K (1|VRAMCNT_OFFSET_1|VRAMCNT_ENABLE)
#define VRAMCNT_F_BG_VRAM_A_OFFS_64K (1|VRAMCNT_OFFSET_2|VRAMCNT_ENABLE)
#define VRAMCNT_F_BG_VRAM_A_OFFS_80K (1|VRAMCNT_OFFSET_3|VRAMCNT_ENABLE)
#define VRAMCNT_F_OBJ_VRAM_A (2|VRAMCNT_OFFSET_0|VRAMCNT_ENABLE)
#define VRAMCNT_F_OBJ_VRAM_A_OFFS_0K (2|VRAMCNT_OFFSET_0|VRAMCNT_ENABLE)
#define VRAMCNT_F_OBJ_VRAM_A_OFFS_16K (2|VRAMCNT_OFFSET_1|VRAMCNT_ENABLE)
#define VRAMCNT_F_OBJ_VRAM_A_OFFS_64K (2|VRAMCNT_OFFSET_2|VRAMCNT_ENABLE)
#define VRAMCNT_F_OBJ_VRAM_A_OFFS_80K (2|VRAMCNT_OFFSET_3|VRAMCNT_ENABLE)
#define VRAMCNT_F_TEXTURE_PALETTE (3|VRAMCNT_OFFSET_0|VRAMCNT_ENABLE)
#define VRAMCNT_F_TEXTURE_PALETTE_SLOT_0 (3|VRAMCNT_OFFSET_0|VRAMCNT_ENABLE)
#define VRAMCNT_F_TEXTURE_PALETTE_SLOT_1 (3|VRAMCNT_OFFSET_1|VRAMCNT_ENABLE)
#define VRAMCNT_F_TEXTURE_PALETTE_SLOT_4 (3|VRAMCNT_OFFSET_2|VRAMCNT_ENABLE)
#define VRAMCNT_F_TEXTURE_PALETTE_SLOT_5 (3|VRAMCNT_OFFSET_3|VRAMCNT_ENABLE)
#define VRAMCNT_F_BG_EXT_PALETTE_A (4|VRAMCNT_OFFSET_0|VRAMCNT_ENABLE)
#define VRAMCNT_F_BG_EXT_PALETTE_A_SLOTS_0_1 (4|VRAMCNT_OFFSET_0|VRAMCNT_ENABLE)
#define VRAMCNT_F_BG_EXT_PALETTE_A_SLOTS_2_3 (4|VRAMCNT_OFFSET_1|VRAMCNT_ENABLE)
#define VRAMCNT_F_OBJ_EXT_PALETTE_A (5|VRAMCNT_OFFSET_0|VRAMCNT_ENABLE)
#define VRAMCNT_G_LCDC (0|VRAMCNT_ENABLE)
#define VRAMCNT_G_BG_VRAM_A (1|VRAMCNT_OFFSET_0|VRAMCNT_ENABLE)
#define VRAMCNT_G_BG_VRAM_A_OFFS_0K (1|VRAMCNT_OFFSET_0|VRAMCNT_ENABLE)
#define VRAMCNT_G_BG_VRAM_A_OFFS_16K (1|VRAMCNT_OFFSET_1|VRAMCNT_ENABLE)
#define VRAMCNT_G_BG_VRAM_A_OFFS_64K (1|VRAMCNT_OFFSET_2|VRAMCNT_ENABLE)
#define VRAMCNT_G_BG_VRAM_A_OFFS_80K (1|VRAMCNT_OFFSET_3|VRAMCNT_ENABLE)
#define VRAMCNT_G_OBJ_VRAM_A (2|VRAMCNT_OFFSET_0|VRAMCNT_ENABLE)
#define VRAMCNT_G_OBJ_VRAM_A_OFFS_0K (2|VRAMCNT_OFFSET_0|VRAMCNT_ENABLE)
#define VRAMCNT_G_OBJ_VRAM_A_OFFS_16K (2|VRAMCNT_OFFSET_1|VRAMCNT_ENABLE)
#define VRAMCNT_G_OBJ_VRAM_A_OFFS_64K (2|VRAMCNT_OFFSET_2|VRAMCNT_ENABLE)
#define VRAMCNT_G_OBJ_VRAM_A_OFFS_80K (2|VRAMCNT_OFFSET_3|VRAMCNT_ENABLE)
#define VRAMCNT_G_TEXTURE_PALETTE (3|VRAMCNT_OFFSET_0|VRAMCNT_ENABLE)
#define VRAMCNT_G_TEXTURE_PALETTE_SLOT_0 (3|VRAMCNT_OFFSET_0|VRAMCNT_ENABLE)
#define VRAMCNT_G_TEXTURE_PALETTE_SLOT_1 (3|VRAMCNT_OFFSET_1|VRAMCNT_ENABLE)
#define VRAMCNT_G_TEXTURE_PALETTE_SLOT_4 (3|VRAMCNT_OFFSET_2|VRAMCNT_ENABLE)
#define VRAMCNT_G_TEXTURE_PALETTE_SLOT_5 (3|VRAMCNT_OFFSET_3|VRAMCNT_ENABLE)
#define VRAMCNT_G_BG_EXT_PALETTE_A (4|VRAMCNT_OFFSET_0|VRAMCNT_ENABLE)
#define VRAMCNT_G_BG_EXT_PALETTE_A_SLOTS_0_1 (4|VRAMCNT_OFFSET_0|VRAMCNT_ENABLE)
#define VRAMCNT_G_BG_EXT_PALETTE_A_SLOTS_2_3 (4|VRAMCNT_OFFSET_1|VRAMCNT_ENABLE)
#define VRAMCNT_G_OBJ_EXT_PALETTE_A (5|VRAMCNT_OFFSET_0|VRAMCNT_ENABLE)
#define VRAMCNT_H_LCDC (0|VRAMCNT_ENABLE)
#define VRAMCNT_H_BG_VRAM_B (1|VRAMCNT_ENABLE)
#define VRAMCNT_H_BG_EXT_PALETTE_B (2|VRAMCNT_ENABLE)
#define VRAMCNT_I_LCDC (0|VRAMCNT_ENABLE)
#define VRAMCNT_I_BG_VRAM_B_OFFS_32K (1|VRAMCNT_ENABLE)
#define VRAMCNT_I_OBJ_VRAM_B (2|VRAMCNT_ENABLE)
#define VRAMCNT_I_OBJ_EXT_PALETTE_B (3|VRAMCNT_ENABLE)
#define WRAMCNT ARM9_REG8(0x4000247)
#define WRAMSTAT ARM7_REG8(0x4000247)
#define WRAMCNT_ARM9_ALL (0<<0)
#define WRAMCNT_ARM7_FIRST_HALF (1<<0)
#define WRAMCNT_ARM9_FIRST_HALF (2<<0)
#define WRAMCNT_ARM7_ALL (3<<0)
//
// Math co-processor
//
#define DIVCNT ARM9_REG16(0x04000280)
#define DIV_NUMER_64 ARM9_SREG64(0x04000290)
#define DIV_NUMER_32 ARM9_SREG32(0x04000290)
#define DIV_DENOM_64 ARM9_SREG64(0x04000298)
#define DIV_DENOM_32 ARM9_SREG32(0x04000298)
#define DIV_RESULT_64 ARM9_SREG64(0x040002a0)
#define DIV_RESULT_32 ARM9_SREG32(0x040002a0)
#define DIVREM_RESULT_64 ARM9_SREG64(0x040002a8)
#define DIVREM_RESULT_32 ARM9_SREG32(0x040002a8)
#define DIVCNT_MODE_32_32 (0<<0)
#define DIVCNT_MODE_64_32 (1<<0)
#define DIVCNT_MODE_64_64 (2<<0)
#define DIVCNT_BY_ZERO (1<<14)
#define DIVCNT_BUSY (1<<15)
#define SQRTCNT ARM9_REG16(0x040002b0)
#define SQRT_RESULT ARM9_REG32(0x040002b4)
#define SQRT_PARAM_64 ARM9_REG64(0x040002b8)
#define SQRT_PARAM_32 ARM9_REG32(0x040002b8)
#define SQRTCNT_MODE_32 (0<<0)
#define SQRTCNT_MODE_64 (1<<0)
#define SQRTCNT_BUSY (1<<15)
//
// Power management
//
#define POSTFLG REG8(0x4000300)
#define HALTCNT ARM7_REG8(0x4000301)
#define HALTCNT_NORMAL (0<<6)
#define HALTCNT_GBA (1<<6)
#define HALTCNT_HALT (2<<6)
#define HALTCNT_SLEEP (3<<6)
#define POWCNT1 ARM9_REG16(0x4000304)
#define POWCNT1_LCDS (1<<0)
#define POWCNT1_2D_ENGINE_A (1<<1)
#define POWCNT1_3D_RENDERING_ENGINE (1<<2)
#define POWCNT1_3D_GEOMETRY_ENGINE (1<<3)
#define POWCNT1_2D_ENGINE_B (1<<9)
#define POWCNT1_DISPLAY_SWAP (1<<15)
#define POWCNT1_ALL_2D (POWCNT1_LCDS|POWCNT1_2D_ENGINE_A|POWCNT1_2D_ENGINE_B)
#define POWCNT1_ALL (POWCNT1_ALL_2D|POWCNT1_3D_RENDERING_ENGINE|POWCNT1_3D_GEOMETRY_ENGINE)
#define POWCNT1_ALL_SWAP (POWCNT1_ALL|POWCNT1_DISPLAY_SWAP)
#define POWCNT2 ARM7_REG16(0x4000304)
#define POWCNT2_SOUND (1<<0)
#define POWCNT2_WIFI (1<<0)
#define POWCNT2_ALL (POWCNT2_SOUND|POWCNT2_WIFI)
//
// 3D Engine
//
#define RDLINES_COUNT ARM9_REG8(0x4000320)
#define EDGE_COLOR ARM9_ARRAY16(0x4000330)
#define ALPHA_TEST_REF ARM9_REG8(0x4000340)
#define CLEAR_COLOR ARM9_REG32(0x4000350)