File: mach64.c

package info (click to toggle)
atitvout 0.4-13
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, squeeze, stretch, wheezy
  • size: 228 kB
  • ctags: 235
  • sloc: ansic: 1,670; makefile: 119; sh: 31
file content (123 lines) | stat: -rw-r--r-- 2,598 bytes parent folder | download | duplicates (6)
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
/*
 * This file is part of atitvout. 
 *
 * asd 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.
 *
 * asd 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 atitvout; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
 */

#include <lrmi.h>
#include <stdio.h>

#include "ati.h"
#include "mach64.h"
#include "vbecall.h"

int mach64_detect_attached_displays(unsigned *tv) {
    struct LRMI_regs r;
    memset(&r, 0, sizeof(r));

    r.eax = 0xa083;
    r.ecx = 0x0700;

    if (vbe_call(&r) != 0)
        return -1;

    if (tv)
        *tv = r.ecx >> 4 & 3;
    
    return ((r.ecx & 3) ? ATI_DISPLAY_CRT : 0) | ((r.ecx >> 4 & 3) ? ATI_DISPLAY_TV : 0) | ((r.ecx & 4) ? ATI_DISPLAY_LCD : 0);
}

int mach64_get_active_displays() {
    struct LRMI_regs r;
    memset(&r, 0, sizeof(r));

    r.eax = 0xa084;
    r.ebx = 0x0000;

    if (vbe_call(&r) != 0)
        return -1;
    
    return r.ebx & 7;
}

int mach64_set_active_displays(int v) {
    struct LRMI_regs r;
    memset(&r, 0, sizeof(r));

    r.eax = 0xa084;
    r.ebx = 0x0100;
    r.ecx = v & 7;

    if (vbe_call(&r) != 0)
        return -1;

    return 0;
}

int mach64_get_tvout_config(unsigned *rev, int *freq) {
    struct LRMI_regs r;

    memset(&r, 0, sizeof(r));

    r.eax = 0xa070;
    r.ebx = 0x0000; 

    if (vbe_call(&r) != 0)
        return -1;

    if ((r.ebx & 0xFFFF) == 0)
        return (r.edx & 0xFFFF) == 0 ? ATI_TVOUT_NOTDETECTED : ATI_TVOUT_NOTSUPPORTED;

    if ((r.ecx & 0xFF)== 0)
        return ATI_TVOUT_DISABLED;
    
    if (rev)
        *rev = (r.edx >> 8) & 0xff;

    if (freq)
        *freq = (r.ecx >> 8) & 0xff;

    return ATI_TVOUT_ENABLED;
}

int mach64_get_tvout_standard() {
    struct LRMI_regs r;

    memset(&r, 0, sizeof(r));

    r.eax = 0xa071;
    r.ebx = 0x0000; 

    if (vbe_call(&r) != 0)
        return -1;

    return r.ecx & 0x00ff;
}

int mach64_set_tvout_standard(int v) {
    struct LRMI_regs r;

    memset(&r, 0, sizeof(r));

    r.eax = 0xa070;
    r.ebx = 0x0003;
    r.ecx = v & 0xFF;

    if (vbe_call(&r) != 0)
        return -1;

    return r.ecx & 0x00ff;
}