revert between 56095 -> 55830 in arch
[AROS.git] / arch / m68k-amiga / timer / initcustom.c
blob27c8e90268343684aa1567b3541c8cfe67796901
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
4 Desc: Detect custom chipset revisions and PAL/NTSC state
5 Lang: english
6 */
8 #define DEBUG 0
10 #include <aros/debug.h>
11 #include <aros/symbolsets.h>
12 #include <graphics/gfxbase.h>
13 #include <hardware/custom.h>
14 #include <hardware/cia.h>
16 #include <timer_platform.h>
18 static UWORD getline(void)
20 volatile struct Custom *custom = (struct Custom*)0xdff000;
21 UBYTE vposb;
22 UWORD vpos;
24 vposb = custom->vhposr >> 8;
25 while (vposb == (custom->vhposr >> 8));
26 vpos = ((custom->vposr & 7) << 8) | (custom->vhposr >> 8);
27 return vpos;
30 static UWORD gethighestline(UWORD linecnt)
32 volatile struct Custom *custom = (struct Custom*)0xdff000;
33 UBYTE vposb;
34 UWORD vpos, highest;
36 highest = 0;
37 while (linecnt-- != 0) {
38 vposb = custom->vhposr >> 8;
39 while (vposb == (custom->vhposr >> 8));
40 vposb++;
41 vpos = ((custom->vposr & 7) << 8) | vposb;
42 if (vpos > highest)
43 highest = vpos;
45 return highest;
48 void InitCustom(struct GfxBase *gfx)
50 volatile struct Custom *custom = (struct Custom*)0xdff000;
51 UWORD vposr;
52 UWORD flags = 0;
53 UWORD pos;
55 Disable();
57 custom->vposw = 0x8000;
58 custom->bplcon0 = 0x0200;
60 while(getline() != 0);
61 pos = gethighestline(400);
62 if (pos > 300)
63 flags |= PAL;
64 else
65 flags |= NTSC;
67 vposr = custom->vposr & 0x7f00;
68 if (!(vposr & 0x1000))
69 flags |= REALLY_PAL;
70 custom->fmode = 0;
72 Enable();
74 if (vposr >= 0x2200) {
75 gfx->MemType = BUS_32 | DBL_CAS;
78 gfx->DisplayFlags = flags;
80 SysBase->VBlankFrequency = (flags & PAL) ? 50 : 60;