Filewatcher File Search
FTP Search
  
Directory (beta)
  
Content Search (beta)
   
pkg://atitvout-0.4-4.src.rpm:39909/atitvout-0.4.tar.gz  info  downloads

atitvout/0042755000175000001440000000000007541431362012332 5ustar  lennartusersatitvout/lrmi-0.6/0042755000175000001440000000000007541431362013576 5ustar  lennartusersatitvout/lrmi-0.6/pic/0042755000175000001440000000000007541431362014351 5ustar  lennartusersatitvout/lrmi-0.6/lrmi.h0100644000175000001440000000320106555453130014702 0ustar  lennartusers/*
Linux Real Mode Interface - A library of DPMI-like functions for Linux.

Copyright (C) 1998 by Josh Vanderhoof

You are free to distribute and modify this file, as long as you
do not remove this copyright notice and clearly label modified
versions as being modified.

This software has NO WARRANTY.  Use it at your own risk.
*/

#ifndef LRMI_H
#define LRMI_H

struct LRMI_regs
	{
	unsigned int edi;
	unsigned int esi;
	unsigned int ebp;
	unsigned int reserved;
	unsigned int ebx;
	unsigned int edx;
	unsigned int ecx;
	unsigned int eax;
	unsigned short int flags;
	unsigned short int es;
	unsigned short int ds;
	unsigned short int fs;
	unsigned short int gs;
	unsigned short int ip;
	unsigned short int cs;
	unsigned short int sp;
	unsigned short int ss;
	};


#ifndef LRMI_PREFIX
#define LRMI_PREFIX LRMI_
#endif

#define LRMI_CONCAT2(a, b) 	a ## b
#define LRMI_CONCAT(a, b) 	LRMI_CONCAT2(a, b)
#define LRMI_MAKENAME(a) 	LRMI_CONCAT(LRMI_PREFIX, a)

/*
 Initialize
 returns 1 if sucessful, 0 for failure
*/
#define LRMI_init LRMI_MAKENAME(init)
int
LRMI_init(void);

/*
 Simulate a 16 bit far call
 returns 1 if sucessful, 0 for failure
*/
#define LRMI_call LRMI_MAKENAME(call)
int
LRMI_call(struct LRMI_regs *r);

/*
 Simulate a 16 bit interrupt
 returns 1 if sucessful, 0 for failure
*/
#define LRMI_int LRMI_MAKENAME(int)
int
LRMI_int(int interrupt, struct LRMI_regs *r);

/*
 Allocate real mode memory
 The returned block is paragraph (16 byte) aligned
*/
#define LRMI_alloc_real LRMI_MAKENAME(alloc_real)
void *
LRMI_alloc_real(int size);

/*
 Free real mode memory
*/
#define LRMI_free_real LRMI_MAKENAME(free_real)
void
LRMI_free_real(void *m);

#endif
atitvout/lrmi-0.6/vbe.h0100644000175000001440000000530507415431346014523 0ustar  lennartusers/*
Copyright (C) 1996 by Josh Vanderhoof

You are free to distribute and modify this file, as long as you
do not remove this copyright notice and clearly label modified
versions as being modified.

This software has NO WARRANTY.  Use it at your own risk.
*/

#ifndef _VBE_H
#define _VBE_H

/* structures for vbe 2.0 */

struct vbe_info_block
	{
	char vbe_signature[4];
	short vbe_version;
	unsigned short oem_string_off;
	unsigned short oem_string_seg;
	int capabilities;
	unsigned short video_mode_list_off;
	unsigned short video_mode_list_seg;
	short total_memory;
	short oem_software_rev;
	unsigned short oem_vendor_name_off;
	unsigned short oem_vendor_name_seg;
	unsigned short oem_product_name_off;
	unsigned short oem_product_name_seg;
	unsigned short oem_product_rev_off;
	unsigned short oem_product_rev_seg;
	char reserved[222];
	char oem_data[256];
	} __attribute__ ((packed));

#define VBE_ATTR_MODE_SUPPORTED 	(1 << 0)
#define VBE_ATTR_TTY 	(1 << 2)
#define VBE_ATTR_COLOR 	(1 << 3)
#define VBE_ATTR_GRAPHICS 	(1 << 4)
#define VBE_ATTR_NOT_VGA 	(1 << 5)
#define VBE_ATTR_NOT_WINDOWED 	(1 << 6)
#define VBE_ATTR_LINEAR 	(1 << 7)

#define VBE_WIN_RELOCATABLE 	(1 << 0)
#define VBE_WIN_READABLE 	(1 << 1)
#define VBE_WIN_WRITEABLE 	(1 << 2)

#define VBE_MODEL_TEXT 	0
#define VBE_MODEL_CGA 	1
#define VBE_MODEL_HERCULES 	2
#define VBE_MODEL_PLANAR 	3
#define VBE_MODEL_PACKED 	4
#define VBE_MODEL_256 	5
#define VBE_MODEL_RGB 	6
#define VBE_MODEL_YUV 	7

struct vbe_mode_info_block
	{
	unsigned short mode_attributes;
	unsigned char win_a_attributes;
	unsigned char win_b_attributes;
	unsigned short win_granularity;
	unsigned short win_size;
	unsigned short win_a_segment;
	unsigned short win_b_segment;
	unsigned short win_func_ptr_off;
	unsigned short win_func_ptr_seg;
	unsigned short bytes_per_scanline;
	unsigned short x_resolution;
	unsigned short y_resolution;
	unsigned char x_char_size;
	unsigned char y_char_size;
	unsigned char number_of_planes;
	unsigned char bits_per_pixel;
	unsigned char number_of_banks;
	unsigned char memory_model;
	unsigned char bank_size;
	unsigned char number_of_image_pages;
	unsigned char res1;
	unsigned char red_mask_size;
	unsigned char red_field_position;
	unsigned char green_mask_size;
	unsigned char green_field_position;
	unsigned char blue_mask_size;
	unsigned char blue_field_position;
	unsigned char rsvd_mask_size;
	unsigned char rsvd_field_position;
	unsigned char direct_color_mode_info;
	unsigned int phys_base_ptr;
	unsigned int offscreen_mem_offset;
	unsigned short offscreen_mem_size;
	unsigned char res2[206];
	} __attribute__ ((packed));

struct vbe_palette_entry
	{
	unsigned char blue;
	unsigned char green;
	unsigned char red;
	unsigned char align;
	} __attribute__ ((packed));

#endif
atitvout/lrmi-0.6/lrmi.c0100644000175000001440000004036406600504246014704 0ustar  lennartusers/*
Linux Real Mode Interface - A library of DPMI-like functions for Linux.

Copyright (C) 1998 by Josh Vanderhoof

You are free to distribute and modify this file, as long as you
do not remove this copyright notice and clearly label modified
versions as being modified.

This software has NO WARRANTY.  Use it at your own risk.
*/

#include <stdio.h>
#include <string.h>
#include <asm/vm86.h>

#ifdef USE_LIBC_VM86
#include <sys/vm86.h>
#endif

#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <unistd.h>
#include <fcntl.h>

#include "lrmi.h"

#define REAL_MEM_BASE 	((void *)0x10000)
#define REAL_MEM_SIZE 	0x10000
#define REAL_MEM_BLOCKS 	0x100

struct mem_block
	{
	unsigned int size : 20;
	unsigned int free : 1;
	};

static struct
	{
	int ready;
	int count;
	struct mem_block blocks[REAL_MEM_BLOCKS];
	} mem_info = { 0 };

static int
real_mem_init(void)
	{
	void *m;
	int fd_zero;

	if (mem_info.ready)
		return 1;

	fd_zero = open("/dev/zero", O_RDONLY);
	if (fd_zero == -1)
		{
		perror("open /dev/zero");
		return 0;
		}

	m = mmap((void *)REAL_MEM_BASE, REAL_MEM_SIZE,
	 PROT_READ | PROT_WRITE | PROT_EXEC,
	 MAP_FIXED | MAP_PRIVATE, fd_zero, 0);

	if (m == (void *)-1)
		{
		perror("mmap /dev/zero");
		close(fd_zero);
		return 0;
		}

	mem_info.ready = 1;
	mem_info.count = 1;
	mem_info.blocks[0].size = REAL_MEM_SIZE;
	mem_info.blocks[0].free = 1;

	return 1;
	}


static void
insert_block(int i)
	{
	memmove(
	 mem_info.blocks + i + 1,
	 mem_info.blocks + i,
	 (mem_info.count - i) * sizeof(struct mem_block));

	mem_info.count++;
	}

static void
delete_block(int i)
	{
	mem_info.count--;

	memmove(
	 mem_info.blocks + i,
	 mem_info.blocks + i + 1,
	 (mem_info.count - i) * sizeof(struct mem_block));
	}

void *
LRMI_alloc_real(int size)
	{
	int i;
	char *r = (char *)REAL_MEM_BASE;

	if (!mem_info.ready)
		return NULL;

	if (mem_info.count == REAL_MEM_BLOCKS)
		return NULL;

	size = (size + 15) & ~15;

	for (i = 0; i < mem_info.count; i++)
		{
		if (mem_info.blocks[i].free && size < mem_info.blocks[i].size)
			{
			insert_block(i);

			mem_info.blocks[i].size = size;
			mem_info.blocks[i].free = 0;
			mem_info.blocks[i + 1].size -= size;

			return (void *)r;
			}

		r += mem_info.blocks[i].size;
		}

	return NULL;
	}


void
LRMI_free_real(void *m)
	{
	int i;
	char *r = (char *)REAL_MEM_BASE;

	if (!mem_info.ready)
		return;

	i = 0;
	while (m != (void *)r)
		{
		r += mem_info.blocks[i].size;
		i++;
		if (i == mem_info.count)
			return;
		}

	mem_info.blocks[i].free = 1;

	if (i + 1 < mem_info.count && mem_info.blocks[i + 1].free)
		{
		mem_info.blocks[i].size += mem_info.blocks[i + 1].size;
		delete_block(i + 1);
		}

	if (i - 1 >= 0 && mem_info.blocks[i - 1].free)
		{
		mem_info.blocks[i - 1].size += mem_info.blocks[i].size;
		delete_block(i);
		}
	}


#define DEFAULT_VM86_FLAGS 	(IF_MASK | IOPL_MASK)
#define DEFAULT_STACK_SIZE 	0x1000
#define RETURN_TO_32_INT 	255

static struct
	{
	int ready;
	unsigned short ret_seg, ret_off;
	unsigned short stack_seg, stack_off;
	struct vm86_struct vm;
	} context = { 0 };


static inline void
set_bit(unsigned int bit, void *array)
	{
	unsigned char *a = array;

	a[bit / 8] |= (1 << (bit % 8));
	}


static inline unsigned int
get_int_seg(int i)
	{
	return *(unsigned short *)(i * 4 + 2);
	}


static inline unsigned int
get_int_off(int i)
	{
	return *(unsigned short *)(i * 4);
	}


static inline void
pushw(unsigned short i)
	{
	struct vm86_regs *r = &context.vm.regs;
	r->esp -= 2;
	*(unsigned short *)(((unsigned int)r->ss << 4) + r->esp) = i;
	}


int
LRMI_init(void)
	{
	void *m;
	int fd_mem;

	if (context.ready)
		return 1;

	if (!real_mem_init())
		return 0;

	/*
	 Map the Interrupt Vectors (0x0 - 0x400) + BIOS data (0x400 - 0x502)
	 and the ROM (0xa0000 - 0x100000)
	*/
	fd_mem = open("/dev/mem", O_RDWR);

	if (fd_mem == -1)
		{
		perror("open /dev/mem");
		return 0;
		}

	m = mmap((void *)0, 0x502,
	 PROT_READ | PROT_WRITE | PROT_EXEC,
	 MAP_FIXED | MAP_PRIVATE, fd_mem, 0);

	if (m == (void *)-1)
		{
		perror("mmap /dev/mem");
		return 0;
		}

	m = mmap((void *)0xa0000, 0x100000 - 0xa0000,
	 PROT_READ | PROT_WRITE,
	 MAP_FIXED | MAP_SHARED, fd_mem, 0xa0000);

	if (m == (void *)-1)
		{
		perror("mmap /dev/mem");
		return 0;
		}


	/*
	 Allocate a stack
	*/
	m = LRMI_alloc_real(DEFAULT_STACK_SIZE);

	context.stack_seg = (unsigned int)m >> 4;
	context.stack_off = DEFAULT_STACK_SIZE;

	/*
	 Allocate the return to 32 bit routine
	*/
	m = LRMI_alloc_real(2);

	context.ret_seg = (unsigned int)m >> 4;
	context.ret_off = (unsigned int)m & 0xf;

	((unsigned char *)m)[0] = 0xcd; 	/* int opcode */
	((unsigned char *)m)[1] = RETURN_TO_32_INT;

	memset(&context.vm, 0, sizeof(context.vm));

	/*
	 Enable kernel emulation of all ints except RETURN_TO_32_INT
	*/
	memset(&context.vm.int_revectored, 0, sizeof(context.vm.int_revectored));
	set_bit(RETURN_TO_32_INT, &context.vm.int_revectored);

	context.ready = 1;

	return 1;
	}


static void
set_regs(struct LRMI_regs *r)
	{
	context.vm.regs.edi = r->edi;
	context.vm.regs.esi = r->esi;
	context.vm.regs.ebp = r->ebp;
	context.vm.regs.ebx = r->ebx;
	context.vm.regs.edx = r->edx;
	context.vm.regs.ecx = r->ecx;
	context.vm.regs.eax = r->eax;
	context.vm.regs.eflags = DEFAULT_VM86_FLAGS;
	context.vm.regs.es = r->es;
	context.vm.regs.ds = r->ds;
	context.vm.regs.fs = r->fs;
	context.vm.regs.gs = r->gs;
	}


static void
get_regs(struct LRMI_regs *r)
	{
	r->edi = context.vm.regs.edi;
	r->esi = context.vm.regs.esi;
	r->ebp = context.vm.regs.ebp;
	r->ebx = context.vm.regs.ebx;
	r->edx = context.vm.regs.edx;
	r->ecx = context.vm.regs.ecx;
	r->eax = context.vm.regs.eax;
	r->flags = context.vm.regs.eflags;
	r->es = context.vm.regs.es;
	r->ds = context.vm.regs.ds;
	r->fs = context.vm.regs.fs;
	r->gs = context.vm.regs.gs;
	}

#define DIRECTION_FLAG 	(1 << 10)

static void
em_ins(int size)
	{
	unsigned int edx, edi;

	edx = context.vm.regs.edx & 0xffff;
	edi = context.vm.regs.edi & 0xffff;
	edi += (unsigned int)context.vm.regs.ds << 4;

	if (context.vm.regs.eflags & DIRECTION_FLAG)
		{
		if (size == 4)
			asm volatile ("std; insl; cld"
			 : "=D" (edi) : "d" (edx), "0" (edi));
		else if (size == 2)
			asm volatile ("std; insw; cld"
			 : "=D" (edi) : "d" (edx), "0" (edi));
		else
			asm volatile ("std; insb; cld"
			 : "=D" (edi) : "d" (edx), "0" (edi));
		}
	else
		{
		if (size == 4)
			asm volatile ("cld; insl"
			 : "=D" (edi) : "d" (edx), "0" (edi));
		else if (size == 2)
			asm volatile ("cld; insw"
			 : "=D" (edi) : "d" (edx), "0" (edi));
		else
			asm volatile ("cld; insb"
			 : "=D" (edi) : "d" (edx), "0" (edi));
		}

	edi -= (unsigned int)context.vm.regs.ds << 4;

	context.vm.regs.edi &= 0xffff0000;
	context.vm.regs.edi |= edi & 0xffff;
	}

static void
em_rep_ins(int size)
	{
	unsigned int ecx, edx, edi;

	ecx = context.vm.regs.ecx & 0xffff;
	edx = context.vm.regs.edx & 0xffff;
	edi = context.vm.regs.edi & 0xffff;
	edi += (unsigned int)context.vm.regs.ds << 4;

	if (context.vm.regs.eflags & DIRECTION_FLAG)
		{
		if (size == 4)
			asm volatile ("std; rep; insl; cld"
			 : "=D" (edi), "=c" (ecx)
			 : "d" (edx), "0" (edi), "1" (ecx));
		else if (size == 2)
			asm volatile ("std; rep; insw; cld"
			 : "=D" (edi), "=c" (ecx)
			 : "d" (edx), "0" (edi), "1" (ecx));
		else
			asm volatile ("std; rep; insb; cld"
			 : "=D" (edi), "=c" (ecx)
			 : "d" (edx), "0" (edi), "1" (ecx));
		}
	else
		{
		if (size == 4)
			asm volatile ("cld; rep; insl"
			 : "=D" (edi), "=c" (ecx)
			 : "d" (edx), "0" (edi), "1" (ecx));
		else if (size == 2)
			asm volatile ("cld; rep; insw"
			 : "=D" (edi), "=c" (ecx)
			 : "d" (edx), "0" (edi), "1" (ecx));
		else
			asm volatile ("cld; rep; insb"
			 : "=D" (edi), "=c" (ecx)
			 : "d" (edx), "0" (edi), "1" (ecx));
		}

	edi -= (unsigned int)context.vm.regs.ds << 4;

	context.vm.regs.edi &= 0xffff0000;
	context.vm.regs.edi |= edi & 0xffff;

	context.vm.regs.ecx &= 0xffff0000;
	context.vm.regs.ecx |= ecx & 0xffff;
	}

static void
em_outs(int size)
	{
	unsigned int edx, esi;

	edx = context.vm.regs.edx & 0xffff;
	esi = context.vm.regs.esi & 0xffff;
	esi += (unsigned int)context.vm.regs.ds << 4;

	if (context.vm.regs.eflags & DIRECTION_FLAG)
		{
		if (size == 4)
			asm volatile ("std; outsl; cld"
			 : "=S" (esi) : "d" (edx), "0" (esi));
		else if (size == 2)
			asm volatile ("std; outsw; cld"
			 : "=S" (esi) : "d" (edx), "0" (esi));
		else
			asm volatile ("std; outsb; cld"
			 : "=S" (esi) : "d" (edx), "0" (esi));
		}
	else
		{
		if (size == 4)
			asm volatile ("cld; outsl"
			 : "=S" (esi) : "d" (edx), "0" (esi));
		else if (size == 2)
			asm volatile ("cld; outsw"
			 : "=S" (esi) : "d" (edx), "0" (esi));
		else
			asm volatile ("cld; outsb"
			 : "=S" (esi) : "d" (edx), "0" (esi));
		}

	esi -= (unsigned int)context.vm.regs.ds << 4;

	context.vm.regs.esi &= 0xffff0000;
	context.vm.regs.esi |= esi & 0xffff;
	}

static void
em_rep_outs(int size)
	{
	unsigned int ecx, edx, esi;

	ecx = context.vm.regs.ecx & 0xffff;
	edx = context.vm.regs.edx & 0xffff;
	esi = context.vm.regs.esi & 0xffff;
	esi += (unsigned int)context.vm.regs.ds << 4;

	if (context.vm.regs.eflags & DIRECTION_FLAG)
		{
		if (size == 4)
			asm volatile ("std; rep; outsl; cld"
			 : "=S" (esi), "=c" (ecx)
			 : "d" (edx), "0" (esi), "1" (ecx));
		else if (size == 2)
			asm volatile ("std; rep; outsw; cld"
			 : "=S" (esi), "=c" (ecx)
			 : "d" (edx), "0" (esi), "1" (ecx));
		else
			asm volatile ("std; rep; outsb; cld"
			 : "=S" (esi), "=c" (ecx)
			 : "d" (edx), "0" (esi), "1" (ecx));
		}
	else
		{
		if (size == 4)
			asm volatile ("cld; rep; outsl"
			 : "=S" (esi), "=c" (ecx)
			 : "d" (edx), "0" (esi), "1" (ecx));
		else if (size == 2)
			asm volatile ("cld; rep; outsw"
			 : "=S" (esi), "=c" (ecx)
			 : "d" (edx), "0" (esi), "1" (ecx));
		else
			asm volatile ("cld; rep; outsb"
			 : "=S" (esi), "=c" (ecx)
			 : "d" (edx), "0" (esi), "1" (ecx));
		}

	esi -= (unsigned int)context.vm.regs.ds << 4;

	context.vm.regs.esi &= 0xffff0000;
	context.vm.regs.esi |= esi & 0xffff;

	context.vm.regs.ecx &= 0xffff0000;
	context.vm.regs.ecx |= ecx & 0xffff;
	}

static void
em_inb(void)
	{
	asm volatile ("inb (%w1), %b0"
	 : "=a" (context.vm.regs.eax)
	 : "d" (context.vm.regs.edx), "0" (context.vm.regs.eax));
	}

static void
em_inw(void)
	{
	asm volatile ("inw (%w1), %w0"
	 : "=a" (context.vm.regs.eax)
	 : "d" (context.vm.regs.edx), "0" (context.vm.regs.eax));
	}

static void
em_inl(void)
	{
	asm volatile ("inl (%w1), %0"
	 : "=a" (context.vm.regs.eax)
	 : "d" (context.vm.regs.edx));
	}

static void
em_outb(void)
	{
	asm volatile ("outb %b0, (%w1)"
	 : : "a" (context.vm.regs.eax),
	 "d" (context.vm.regs.edx));
	}

static void
em_outw(void)
	{
	asm volatile ("outw %w0, (%w1)"
	 : : "a" (context.vm.regs.eax),
	 "d" (context.vm.regs.edx));
	}

static void
em_outl(void)
	{
	asm volatile ("outl %0, (%w1)"
	 : : "a" (context.vm.regs.eax),
	 "d" (context.vm.regs.edx));
	}

static int
emulate(void)
	{
	unsigned char *insn;
	struct
		{
		unsigned int size : 1;
		unsigned int rep : 1;
		} prefix = { 0, 0 };
	int i = 0;

	insn = (unsigned char *)((unsigned int)context.vm.regs.cs << 4);
	insn += context.vm.regs.eip;

	while (1)
		{
		if (insn[i] == 0x66)
			{
			prefix.size = 1 - prefix.size;
			i++;
			}
		else if (insn[i] == 0xf3)
			{
			prefix.rep = 1;
			i++;
			}
		else if (insn[i] == 0xf0 || insn[i] == 0xf2
		 || insn[i] == 0x26 || insn[i] == 0x2e
		 || insn[i] == 0x36 || insn[i] == 0x3e
		 || insn[i] == 0x64 || insn[i] == 0x65
		 || insn[i] == 0x67)
			{
			/* these prefixes are just ignored */
			i++;
			}
		else if (insn[i] == 0x6c)
			{
			if (prefix.rep)
				em_rep_ins(1);
			else
				em_ins(1);
			i++;
			break;
			}
		else if (insn[i] == 0x6d)
			{
			if (prefix.rep)
				{
				if (prefix.size)
					em_rep_ins(4);
				else
					em_rep_ins(2);
				}
			else
				{
				if (prefix.size)
					em_ins(4);
				else
					em_ins(2);
				}
			i++;
			break;
			}
		else if (insn[i] == 0x6e)
			{
			if (prefix.rep)
				em_rep_outs(1);
			else
				em_outs(1);
			i++;
			break;
			}
		else if (insn[i] == 0x6f)
			{
			if (prefix.rep)
				{
				if (prefix.size)
					em_rep_outs(4);
				else
					em_rep_outs(2);
				}
			else
				{
				if (prefix.size)
					em_outs(4);
				else
					em_outs(2);
				}
			i++;
			break;
			}
		else if (insn[i] == 0xec)
			{
			em_inb();
			i++;
			break;
			}
		else if (insn[i] == 0xed)
			{
			if (prefix.size)
				em_inl();
			else
				em_inw();
			i++;
			break;
			}
		else if (insn[i] == 0xee)
			{
			em_outb();
			i++;
			break;
			}
		else if (insn[i] == 0xef)
			{
			if (prefix.size)
				em_outl();
			else
				em_outw();

			i++;
			break;
			}
		else
			return 0;
		}

	context.vm.regs.eip += i;
	return 1;
	}


/*
 I don't know how to make sure I get the right vm86() from libc.
 The one I want is syscall # 113 (vm86old() in libc 5, vm86() in glibc)
 which should be declared as "int vm86(struct vm86_struct *);" in
 <sys/vm86.h>.

 This just does syscall 113 with inline asm, which should work
 for both libc's (I hope).
*/
#if !defined(USE_LIBC_VM86)
static int
lrmi_vm86(struct vm86_struct *vm)
	{
	int r;
#ifdef __PIC__
	asm volatile (
	 "pushl %%ebx\n\t"
	 "movl %2, %%ebx\n\t"
	 "int $0x80\n\t"
	 "popl %%ebx"
	 : "=a" (r)
	 : "0" (113), "r" (vm));
#else
	asm volatile (
	 "int $0x80"
	 : "=a" (r)
	 : "0" (113), "b" (vm));
#endif
	return r;
	}
#else
#define lrmi_vm86 vm86
#endif


static void
debug_info(int vret)
	{
	int i;
	unsigned char *p;

	fputs("vm86() failed\n", stderr);
	fprintf(stderr, "return = 0x%x\n", vret);
	fprintf(stderr, "eax = 0x%08lx\n", context.vm.regs.eax);
	fprintf(stderr, "ebx = 0x%08lx\n", context.vm.regs.ebx);
	fprintf(stderr, "ecx = 0x%08lx\n", context.vm.regs.ecx);
	fprintf(stderr, "edx = 0x%08lx\n", context.vm.regs.edx);
	fprintf(stderr, "esi = 0x%08lx\n", context.vm.regs.esi);
	fprintf(stderr, "edi = 0x%08lx\n", context.vm.regs.edi);
	fprintf(stderr, "ebp = 0x%08lx\n", context.vm.regs.ebp);
	fprintf(stderr, "eip = 0x%08lx\n", context.vm.regs.eip);
	fprintf(stderr, "cs  = 0x%04x\n", context.vm.regs.cs);
	fprintf(stderr, "esp = 0x%08lx\n", context.vm.regs.esp);
	fprintf(stderr, "ss  = 0x%04x\n", context.vm.regs.ss);
	fprintf(stderr, "ds  = 0x%04x\n", context.vm.regs.ds);
	fprintf(stderr, "es  = 0x%04x\n", context.vm.regs.es);
	fprintf(stderr, "fs  = 0x%04x\n", context.vm.regs.fs);
	fprintf(stderr, "gs  = 0x%04x\n", context.vm.regs.gs);
	fprintf(stderr, "eflags  = 0x%08lx\n", context.vm.regs.eflags);

	fputs("cs:ip = [ ", stderr);

	p = (unsigned char *)((context.vm.regs.cs << 4) + (context.vm.regs.eip & 0xffff));

	for (i = 0; i < 16; ++i)
		fprintf(stderr, "%02x ", (unsigned int)p[i]);

	fputs("]\n", stderr);
	}


static int
run_vm86(void)
	{
	unsigned int vret;

	while (1)
		{
		vret = lrmi_vm86(&context.vm);

		if (VM86_TYPE(vret) == VM86_INTx)
			{
			unsigned int v = VM86_ARG(vret);

			if (v == RETURN_TO_32_INT)
				return 1;

			pushw(context.vm.regs.eflags);
			pushw(context.vm.regs.cs);
			pushw(context.vm.regs.eip);

			context.vm.regs.cs = get_int_seg(v);
			context.vm.regs.eip = get_int_off(v);
			context.vm.regs.eflags &= ~(VIF_MASK | TF_MASK);

			continue;
			}

		if (VM86_TYPE(vret) != VM86_UNKNOWN)
			break;

		if (!emulate())
			break;
		}

	debug_info(vret);

	return 0;
	}


int
LRMI_call(struct LRMI_regs *r)
	{
	unsigned int vret;

	memset(&context.vm.regs, 0, sizeof(context.vm.regs));

	set_regs(r);

	context.vm.regs.cs = r->cs;
	context.vm.regs.eip = r->ip;

	if (r->ss == 0 && r->sp == 0)
		{
		context.vm.regs.ss = context.stack_seg;
		context.vm.regs.esp = context.stack_off;
		}
	else
		{
		context.vm.regs.ss = r->ss;
		context.vm.regs.esp = r->sp;
		}

	pushw(context.ret_seg);
	pushw(context.ret_off);

	vret = run_vm86();

	get_regs(r);

	return vret;
	}


int
LRMI_int(int i, struct LRMI_regs *r)
	{
	unsigned int vret;
	unsigned int seg, off;

	seg = get_int_seg(i);
	off = get_int_off(i);

	/*
	 If the interrupt is in regular memory, it's probably
	 still pointing at a dos TSR (which is now gone).
	*/
	if (seg < 0xa000 || (seg << 4) + off >= 0x100000)
		{
		fprintf(stderr, "Int 0x%x is not in rom (%04x:%04x)\n", i, seg, off);
		return 0;
		}

	memset(&context.vm.regs, 0, sizeof(context.vm.regs));

	set_regs(r);

	context.vm.regs.cs = seg;
	context.vm.regs.eip = off;

	if (r->ss == 0 && r->sp == 0)
		{
		context.vm.regs.ss = context.stack_seg;
		context.vm.regs.esp = context.stack_off;
		}
	else
		{
		context.vm.regs.ss = r->ss;
		context.vm.regs.esp = r->sp;
		}

	pushw(DEFAULT_VM86_FLAGS);
	pushw(context.ret_seg);
	pushw(context.ret_off);

	vret = run_vm86();

	get_regs(r);

	return vret;
	}

atitvout/lrmi-0.6/Makefile0100644000175000001440000000114606514256717015243 0ustar  lennartusersCFLAGS = -g -Wall

sources = lrmi.c
objects = lrmi.o
pic_objects = pic/lrmi.o
all = liblrmi.a liblrmi.so vbetest

%.o: %.c
	$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<

pic/%.o: %.c
	$(CC) -c $(CPPFLAGS) $(CFLAGS) -fPIC -o $@ $<

all: $(all)

liblrmi.a: $(objects)
	$(AR) -rs $@ $^

liblrmi.so: $(pic_objects)
	$(CC) $(CPPFLAGS) $(CFLAGS) -fPIC -shared -o $@ $^

vbetest: vbetest.c liblrmi.a
	$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $^

.PHONY: clean
clean:
	rm -f $(objects) $(pic_objects) $(all) core

.PHONY: distclean
distclean: clean
	rm -f .depend

.PHONY: depend
depend: $(sources)
	-$(CC) -M $(CPPFLAGS) $^ >.depend
atitvout/lrmi-0.6/vbetest.c0100644000175000001440000001630506557734570015433 0ustar  lennartusers/*
List the available VESA graphics modes.

This program is in the public domain.
*/

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/kd.h>
#include <sys/stat.h>

#include "lrmi.h"
#include "vbe.h"

struct
	{
	struct vbe_info_block *info;
	struct vbe_mode_info_block *mode;
	char *win; 	/* this doesn't point directly at the window, see update_window() */
	int win_low, win_high;
	} vbe;

void *
save_state(void)
	{
	struct LRMI_regs r;
	void *buffer;

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

	r.eax = 0x4f04;
	r.ecx = 0xf; 	/* all states */
	r.edx = 0; 	/* get buffer size */

	if (!LRMI_int(0x10, &r))
		{
		fprintf(stderr, "Can't get video state buffer size (vm86 failure)\n");
		return NULL;
		}

	if ((r.eax & 0xffff) != 0x4f)
		{
		fprintf(stderr, "Get video state buffer size failed\n");
		return NULL;
		}

	buffer = LRMI_alloc_real((r.ebx & 0xffff) * 64);

	if (buffer == NULL)
		{
		fprintf(stderr, "Can't allocate video state buffer\n");
		return NULL;
		}

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

	r.eax = 0x4f04;
	r.ecx = 0xf; 	/* all states */
	r.edx = 1; 	/* save state */
	r.es = (unsigned int)buffer >> 4;
	r.ebx = (unsigned int)buffer & 0xf;

	if (!LRMI_int(0x10, &r))
		{
		fprintf(stderr, "Can't save video state (vm86 failure)\n");
		return NULL;
		}

	if ((r.eax & 0xffff) != 0x4f)
		{
		fprintf(stderr, "Save video state failed\n");
		return NULL;
		}

	return buffer;
	}

void
restore_state(void *buffer)
	{
	struct LRMI_regs r;

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

	r.eax = 0x4f04;
	r.ecx = 0xf; 	/* all states */
	r.edx = 2; 	/* restore state */
	r.es = (unsigned int)buffer >> 4;
	r.ebx = (unsigned int)buffer & 0xf;

	if (!LRMI_int(0x10, &r))
		{
		fprintf(stderr, "Can't restore video state (vm86 failure)\n");
		}
	else if ((r.eax & 0xffff) != 0x4f)
		{
		fprintf(stderr, "Restore video state failed\n");
		}

	LRMI_free_real(buffer);
	}

void
text_mode(void)
	{
	struct LRMI_regs r;

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

	r.eax = 3;

	if (!LRMI_int(0x10, &r))
		{
		fprintf(stderr, "Can't set text mode (vm86 failure)\n");
		}
	}

int
update_window(int address)
	{
	struct LRMI_regs r;
	int w, g;

	if (address >= vbe.win_low && address < vbe.win_high)
		return 0;

	g = vbe.mode->win_granularity * 1024;
	w = address / g;

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

	r.eax = 0x4f05;
	r.ebx = 0;
	r.edx = w;

	LRMI_int(0x10, &r);

	vbe.win_low = w * g;
	vbe.win_high = vbe.win_low + vbe.mode->win_size * 1024;

	vbe.win = (char *)(vbe.mode->win_a_segment << 4);
	vbe.win -= vbe.win_low;

	return 1;
	}

void
set_pixel(int x, int y, int r, int g, int b)
	{
	int x_res = vbe.mode->x_resolution;
	int y_res = vbe.mode->y_resolution;
	int shift_r = vbe.mode->red_field_position;
	int shift_g = vbe.mode->green_field_position;
	int shift_b = vbe.mode->blue_field_position;
	int pixel_size = (vbe.mode->bits_per_pixel + 7) / 8;
	int bpl = vbe.mode->bytes_per_scanline;
	int c, addr;

	if (x < 0 || x >= x_res || y < 0 || y >= y_res)
		return;

	r >>= 8 - vbe.mode->red_mask_size;
	g >>= 8 - vbe.mode->green_mask_size;
	b >>= 8 - vbe.mode->blue_mask_size;

	c = (r << shift_r) | (g << shift_g) | (b << shift_b);

	addr = y * bpl + (x * pixel_size);

	update_window(addr);

	memcpy(vbe.win + addr, &c, pixel_size);
	}

void
set_mode(int n)
	{
	struct LRMI_regs r;

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

	r.eax = 0x4f02;
	r.ebx = n;

	if (!LRMI_int(0x10, &r))
		{
		fprintf(stderr, "Can't set video mode (vm86 failure)\n");
		}
	else if ((r.eax & 0xffff) != 0x4f)
		{
		fprintf(stderr, "Set video mode failed\n");
		}

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

	r.eax = 0x4f01;
	r.ecx = n;
	r.es = (unsigned int)vbe.mode >> 4;
	r.edi = (unsigned int)vbe.mode & 0xf;

	if (!LRMI_int(0x10, &r))
		{
		fprintf(stderr, "Can't get mode info (vm86 failure)\n");
		return;
		}

	if ((r.eax & 0xffff) != 0x4f)
		{
		fprintf(stderr, "Get mode info failed\n");
		return;
		}

	vbe.win_low = vbe.win_high = -1;

	/*
	 Draw a colorful checkerboard
	*/
	if (vbe.mode->memory_model == VBE_MODEL_RGB)
		{
		int x_res = vbe.mode->x_resolution;
		int y_res = vbe.mode->y_resolution;
		int x, y;

		for (y = 0; y < y_res; ++y)
			{
			for (x = 0; x < x_res; ++x)
				{
				int r, g, b;
				if ((x & 16) ^ (y & 16))
					{
					r = x * 255 / x_res;
					g = y * 255 / y_res;
					b = 255 - x * 255 / x_res;
					}
				else
					{
					r = 255 - x * 255 / x_res;
					g = y * 255 / y_res;
					b = 255 - y * 255 / y_res;
					}

				set_pixel(x, y, r, g, b);
				}
			}
		}
	}

void
interactive_set_mode(void)
	{
	int n;
	void *state;
	struct stat stat;

	printf("Type a mode number, or 'q' to quit - ");

	if (scanf("%d", &n) != 1)
		return;

	if (fstat(0, &stat) != 0)
		{
		fprintf(stderr, "Can't stat() stdin\n");
		return;
		}

	if ((stat.st_rdev & 0xff00) != 0x400
	 || (stat.st_rdev & 0xff) > 63)
		{
		fprintf(stderr, "To switch video modes, "
		 "this program must be run from the console\n");
		return;
		}

	printf("setting mode %d\n", n);

	ioctl(0, KDSETMODE, KD_GRAPHICS);

	state = save_state();

	if (state == NULL)
		return;

	set_mode(n);

	sleep(5);

	text_mode();
	restore_state(state);

	ioctl(0, KDSETMODE, KD_TEXT);
	}

int
main(void)
	{
	struct LRMI_regs r;
	short int *mode_list;

	if (!LRMI_init())
		return 1;

	vbe.info = LRMI_alloc_real(sizeof(struct vbe_info_block)
	 + sizeof(struct vbe_mode_info_block));

	if (vbe.info == NULL)
		{
		fprintf(stderr, "Can't alloc real mode memory\n");
		return 1;
		}

	vbe.mode = (struct vbe_mode_info_block *)(vbe.info + 1);

#if 0
	/*
	 Allow read/write to video IO ports
	*/
	ioperm(0x2b0, 0x2df - 0x2b0, 1);
	ioperm(0x3b0, 0x3df - 0x3b0, 1);
#else
	/*
	 Allow read/write to ALL io ports
	*/
	ioperm(0, 1024, 1);
	iopl(3);
#endif

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

	r.eax = 0x4f00;
	r.es = (unsigned int)vbe.info >> 4;
	r.edi = 0;

	memcpy(vbe.info->vbe_signature, "VBE2", 4);

	if (!LRMI_int(0x10, &r))
		{
		fprintf(stderr, "Can't get VESA info (vm86 failure)\n");
		return 1;
		}

	if ((r.eax & 0xffff) != 0x4f || strncmp(vbe.info->vbe_signature, "VESA", 4) != 0)
		{
		fprintf(stderr, "No VESA bios\n");
		return 1;
		}

	printf("VBE Version %x.%x\n",
	 (int)(vbe.info->vbe_version >> 8) & 0xff,
	 (int)vbe.info->vbe_version & 0xff);

	printf("%s\n",
	 (char *)(vbe.info->oem_string_seg * 16 + vbe.info->oem_string_off));

	mode_list = (short int *)(vbe.info->video_mode_list_seg * 16 + vbe.info->video_mode_list_off);

	while (*mode_list != -1)
		{
		memset(&r, 0, sizeof(r));

		r.eax = 0x4f01;
		r.ecx = *mode_list;
		r.es = (unsigned int)vbe.mode >> 4;
		r.edi = (unsigned int)vbe.mode & 0xf;

		if (!LRMI_int(0x10, &r))
			{
			fprintf(stderr, "Can't get mode info (vm86 failure)\n");
			return 1;
			}

		if (vbe.mode->memory_model == VBE_MODEL_RGB)
			printf("[%3d] %dx%d (%d:%d:%d)\n",
			 *mode_list,
			 vbe.mode->x_resolution,
			 vbe.mode->y_resolution,
			 vbe.mode->red_mask_size,
			 vbe.mode->green_mask_size,
			 vbe.mode->blue_mask_size);
		else if (vbe.mode->memory_model == VBE_MODEL_256)
			printf("[%3d] %dx%d (256 color palette)\n",
			 *mode_list,
			 vbe.mode->x_resolution,
			 vbe.mode->y_resolution);
		else if (vbe.mode->memory_model == VBE_MODEL_PACKED)
			printf("[%3d] %dx%d (%d color palette)\n",
			 *mode_list,
			 vbe.mode->x_resolution,
			 vbe.mode->y_resolution,
			 1 << vbe.mode->bits_per_pixel);

		mode_list++;
		}

	LRMI_free_real(vbe.info);

	interactive_set_mode();

	return 0;
	}
atitvout/README0100640000175000001440000001254307541431362013206 0ustar  lennartusersatitvout 0.4 - Linux ATI TV Out Support Program
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Copyright 2002
Lennart Poettering <mz617469@poettering.de>

---------------------------------------------------------------------

This program 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.

This program 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 this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

---------------------------------------------------------------------

This utility program may be used for executing several configuration
commands for the TV Out connector of ATI Rage Mobility P/M graphics
boards under GNU/Linux on x86. It is intended primarily to enable TV
Out support after bootup and for switching the used TV standard from
NTSC to PAL.

The utility makes use of x86-VESA-BIOS-calls and thus is not portable
to other architectures like PPC: *No TV-Out on Macs with this tool*.

Please Notice
-------------

*Notice*: I do not answer any questions related to Microsoft Windows and ATI's own drivers on that OS.

*Notice*: I don't know where to get the newest ATI drivers for Windows 95, 98, ME, 2000, XP.

*Notice*: I silently ignore HTML mail.

*Notice*: I do not answer any questions related to XFree86 configuration files.

*Notice*: No, I have no "working modeline" for you.

*Notice*: No, there is no chance to get this tool to work on PPC. It's x86-only.

Usage
-----

For usage info try "atitvout help". I normally run the utility with
"atitvout pal auto". This switches to PAL for german TVs and enables
the TV out, when available.

Supported Devices
-----------------

I developed this tool on an ATI Rage Mobility P/M, but I added support
for other devices like the Radeon, the Rage 128, Mobility M3, Mobility
M4.

BUT DON'T FORGET: THE RAGE MOBILITY P/M IS THE ONLY ADAPTER ON WHICH
THE UTILITY IS KNOWN TO WORK. ON ALL OTHER ADAPTERS YOUR MILEAGE MAY
VARY.

Rage Mobility P/M and Mobility M3/M4 differ.

The PCI info of my Rage Mobility follows:

<pre>
[lennart@whiskey] ~$ /sbin/lspci -vs 1:0.0

	VGA compatible controller: ATI Technologies Inc Rage Mobility P/M AGP 2x (rev 64) (prog-if 00 [VGA])
	Subsystem: FIRST INTERNATIONAL Computer Inc: Unknown device 1730
	Flags: bus master, stepping, medium devsel, latency 66, IRQ 5
	Memory at fd000000 (32-bit, non-prefetchable) [size=16M]
	I/O ports at 2000 [size=256]
	Memory at fc100000 (32-bit, non-prefetchable) [size=4K]
	Expansion ROM at <unassigned> [disabled] [size=128K]
	Capabilities: <available only to root>

[lennart@whiskey] ~$ 
</pre>

The program should work at least on those graphics cards which share
the same PCI info with mine. My card is built into a laptop from
Aldi/Medion. (http://www.stud.uni-hamburg.de/users/lennart/aldi/)

Notes
-----

When using the ati driver of XFree 4.1 you should rerun this utility
always after having changed the screen resolution with C-A-+ or
C-A--. Otherwise the displays may go nuts.

As ATI denied to supply me with documentation about the TV Out
interface of their cards and I do not have a ATI Radeon or Rage 128 I
cannot fix my utility so that it works correctly on all these
devices. Thus the support for these devices is rather limited and may
be broken. Please try to run 'test.sh' and have an eye an all your
attached displays, if you experience failures. For better support on
non-Mobility-P/M-devices you need to fix the utility yourself.

Not all ATI adapters support all of these commands. Please try them
all before complaining.

Most cards do not allow to activate non attached displays. All calls
to atitvout will fail if you try to enable displays which do not show
up in 'atitvout detect'.

Not all adapters seem to support simultaneously using TV and LCD/CRT
from within Linux. Thus 'lt' (resp. 'ct') may fail, while 'l' (resp. 'c')
and 't' succeed. In this case 'auto' will fail too. In fact 'auto'
works only on very few adapters.

Development
-----------

Development was done under Debian GNU Linux Sid for i386 from January
2002. The used machine was a Medion 9580-F laptop with an ATI Rage
Mobility P/M graphics board.

Installation
------------

Run "make" for compiling the program. You might want to install it
permanently on your system by issuing "make install" as root. This
installs the atitvout executable to /usr/local/sbin/. For removing this
installation you might want to try "make deinstall" as root.

Internet
--------

You may find up to date releases of this utility on
	http://www.stud.uni-hamburg.de/users/lennart/projects/atitvout/

You may download this release from
	http://www.stud.uni-hamburg.de/users/lennart/projects/atitvout/atitvout-0.4.tar.gz

Thanks go to
------------

Leif Delgass for supplying me with information about ATI VBE calls

Nick Kurshev for a Radeon/R128 related patch

Stefan Raspl for a ATI Mobility Radeon related patch

Josh Vanderhoof for developing LRMI

---------------------------------------------------------------------

Lennart Poettering <mz617469@poettering.de>, 2002
atitvout/Makefile0100644000175000001440000000223507541431017013764 0ustar  lennartusersVERSION=0.4
CFLAGS=-Wall -O2 -g -DVERSION=\"$(VERSION)\" -I./lrmi-0.6
OBJS=atitvout.o ati.o vbeinfo.o vbecall.o mach64.o radeon.o
TAR=atitvout-$(VERSION).tar.gz
BINARY=atitvout
PACKAGE=atitvout

all: $(BINARY)

$(BINARY): $(OBJS)
	make -C lrmi-0.6
	$(CC) $(OBJS) lrmi-0.6/liblrmi.a -o $(BINARY)

strip: $(BINARY)
	@du -h $(BINARY)
	strip -s $(BINARY)
	@du -h $(BINARY)

clean:
	rm -f *.o $(BINARY) *~ README index.html *.tar.gz test.out
	make -C lrmi-0.6 clean

install: strip
	install -g root -o root -m 555 $(BINARY) /usr/local/sbin

deinstall:
	rm -f /usr/local/sbin/$(BINARY)

README: README.in
	sed s/VERSION/$(VERSION)/ < README.in > README

index.html: README
	txt2html -t "$(PACKAGE) $(VERSION)" < README > index.html

html: index.html

$(TAR): clean README
	tar -C.. --exclude=$(PACKAGE)/$(TAR) -czvf $(TAR) $(PACKAGE)

tar: $(TAR)

web: $(TAR) README
	cp README $(TAR) ../../homepage/lennart/projects/$(PACKAGE)/ && $(MAKE) -C ../../homepage/lennart/projects/$(PACKAGE)

upload: web
	$(MAKE) -C ../../homepage/lennart upload

emacs:
	emacs Makefile README.in *.h *.c &

test: $(BINARY)
	./test.sh

.PHONY: test emacs upload web tar html deinstall install clean strip all
atitvout/atitvout.c0100640000175000001440000002455407541431344014356 0ustar  lennartusers/*
 * 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 <stdio.h>
#include <sys/io.h>
#include <string.h>
#include <assert.h>


#include <lrmi.h>
#include <vbe.h>

#include "vbeinfo.h"
#include "ati.h"
#include "mach64.h"
#include "radeon.h"

#ifndef VERSION
#define VERSION "?.?"
#endif

char* basename(char* fn) {
    char *c;
    if (!fn)
        return "atitvout";
    
    if ((c = strrchr(fn, '/')))
        return c+1;

    return fn;
}

int radeon = 0;

void help(char *fn) {
    char *c = basename(fn);
    
    printf("%s %s :: ATI Rage/Radeon TV Out configuration program\n"
           "    Lennart Poettering <mz617469@poettering.de> 2001,2002\n"
           "    http://www.stud.uni-hamburg.de/users/lennart/projects/atitvout/\n"
           "    Licensed under the GNU General Public License, \n"
           "         http://www.gnu.org/licenses/gpl.html#SEC1\n\n"
           "Supported commands:\n"
           "    help: Shows this help.\n"
           "    vbe: Show some information about the VESA BIOS Extension (VBE).\n"
           "    tvout: Shows some information about the TV Out connector.\n"
           "    standard: Shows some information about the used TV standard.\n"
           "    pal*: Sets PAL mode.\n"
           "    ntsc*: Sets NTSC mode.\n"
           "    detect: Shows a list of attached displays.\n"
           "    active: Shows a list of all active displays.\n"
           "    auto: Activates all attached displays, deactivates all others.\n"
           "    off: Deactives all displays.\n"
           "    l,c,t,lc,lt,ct,lct: Activates the specified display, deactivates all\n"
           "                        others. (l = LCD; c = CRT; t = TV)\n\n"
           "Use the flags -f and -r for forcing Rage Mobility/Rage LT resp. Radeon/R128 mode.\n"
           "* Not available on Radeon/Rage 128.\n\n"
           "You may specifiy more than one command on the command line. An example:\n\n"
           "    %s pal auto\n\n"
           "This command line automatically enables an attached TV and sets it to PAL mode.\n\n"
           "PLEASE NOTE: When using the ati driver of XFree 4.1 you should rerun this\n"
           "utility always after having changed the screen resolution with C-A-+ or C-A--.\n"
           "Otherwise the displays may go nuts.\n\n"
           "PLEASE NOTE: Not all ATI adapters support all of these commands. Please try them\n"
           "all before complaining.\n\n"
           "PLEASE NOTE: Most cards do not allow to activate non attached displays. All calls\n"
           "to atitvout will fail if you try to enable displays which do not show up in\n"
           "'%s detect'.\n\n"
           "PLEASE NOTE: Not all adapters seem to support simultaneously using TV and LCD from\n"
           "within Linux. Thus 'lt' may fail, while 'l' and 't' succeed. In this case 'auto'\n"
           "will fail too. In fact 'auto' works only on very few adapters.\n",
           c, VERSION, c, c);
}

int main(int argc, char* argv[]) {
    int r;
    char **c = argv+1;
    char oem[256];
    int vh, vl;

    if (argc <= 1) {
        help(argv[0]);
        return 0;
    }
    
    ioperm(0, 1024, 1);
    iopl(3);

    if (!LRMI_init()) {
        fprintf(stderr, "Could not initialise LRMI.\n");
        return 1;
    }

    if (vbe_info(&vh, &vl, oem, sizeof(oem)) != 0)
        return 2;
    
    if (strcmp(argv[1], "-f") == 0) {
        radeon = 0;
        fprintf(stderr, "Forcing Rage Mobility/Rage 3D Pro LT mode\n");
    } else if (strcmp(argv[1], "-r") == 0) {
        radeon = 1;
        fprintf(stderr, "Forcing Radeon/Rage 128 mode\n");
    } else {
        if (strncmp(oem, "ATI MACH64", 10) == 0)
            radeon = 0;
        else if (strncmp(oem, "ATI RAGE128", 11) == 0)
            radeon = 1;
        /* Note: Also it's possible to have here 'RG6' for first radeons */
        else if (strstr(oem, "RADEON") != 0)
            radeon = 1;
        else {
            fprintf(stderr, "Failed to detect adapter type.\nUse either -f or -r for forcing either Rage Mobility/Rage 3D Pro LT or Radeon/Rage 128 mode.");
            return 2;
        }
    }

    for (; argc > 1; argc--, c++) {
        int standard = -1;
        int display = -1;
        char *a = *c;
        
        assert(a);

        if (strcmp(a, "detect") == 0) {
            unsigned tv;
            
            if(!radeon) {
                if ((r = mach64_detect_attached_displays(&tv)) < 0)
                    return 3;
            } else {
                if ((r = radeon_detect_attached_displays(&tv)) < 0)
                    return 3;
            }

            if (r == 0)
                printf("No display is attached.\n");
            else {
                if (r & ATI_DISPLAY_CRT) printf("CRT is attached.\n");
                if (r & ATI_DISPLAY_LCD) printf("LCD is attached.\n");
                if (r & ATI_DISPLAY_TV) {
                    if (tv & ATI_TV_COMPOSITE) printf("TV is attached via Composite.\n");
                    if (tv & ATI_TV_SVIDEO) printf("TV is attached via S-Video.\n");
                }
            }
        } else if (strcmp(a, "vbe") == 0) {
            printf("VBE Version: %d.%d\n", vh, vl);
            printf("VBE OEM Identification: %s\n", oem);
            
        } else if (!radeon && strcmp(a, "auto") == 0) {
            unsigned tv;

            if ((r = mach64_detect_attached_displays(&tv)) < 0)
                return 3;
            
            mach64_set_active_displays(ATI_DISPLAY_LCD);

            display = r & 0x7;
        } else if (radeon && strcmp(a, "auto") == 0) {
            unsigned tv;
            
            if ((r = radeon_detect_attached_displays(&tv)) < 0)
                return 3;
            
            radeon_set_active_displays(ATI_DISPLAY_CRT);

            display = ATI_DISPLAY_CRT | ((r & 3) != 0 ? ATI_DISPLAY_TV : 0);
        } else if (strcmp(a, "active") == 0) {
            if (!radeon) {
                if ((r = mach64_get_active_displays()) < 0)
                    return 6;
            } else {
                if ((r = radeon_get_active_displays()) < 0)
                    return 6;
            }
                
            if (r == 0)
                printf("No display is active.\n");
            else {
                if (r & ATI_DISPLAY_LCD) printf("LCD is active.\n");
                if (r & ATI_DISPLAY_CRT) printf("CRT is active.\n");
                if (r & ATI_DISPLAY_TV) printf("TV is active.\n");
                if (r & ATI_DISPLAY_AUTOSWITCH) printf("Autoswitch is active.\n");
            }
        } else if (strcmp(a, "tvout") == 0) {
            unsigned rev, freq;

            if (!radeon) {
                if ((r = mach64_get_tvout_config(&rev, &freq)) < 0)
                    return 7;
            } else {
                if ((r = radeon_get_tvout_config(&rev, &freq)) < 0)
                    return 7;
            }
            
            
            switch (r) {
                case ATI_TVOUT_NOTDETECTED:
                    printf("No TV Out detected.\n");
                    break;
                case ATI_TVOUT_NOTSUPPORTED:
                    printf("TV Out not supported.\n");
                    break;
                case ATI_TVOUT_DISABLED:
                    printf("TV Out is disabled.\n");
                    break;
                case ATI_TVOUT_ENABLED:
                    printf("TV Out is enabled.\n");
                    if (!radeon)
                        printf("TV Out subsystem release is %d.\n", rev);
                    printf("Reference frequency is %2.5f Hz\n", TVOUT_REFFREQ(freq));
                    break;
                default:
                    printf("Unknown TV Out config.\n");
                    break;
            }
        } else if (strcmp(a, "standard") == 0) {
            if (!radeon) {
                if ((r = mach64_get_tvout_standard()) < 0)
                    return 8;
            } else {
                if ((r = radeon_get_tvout_standard()) < 0)
                    return 8;
            }
            
            printf("Current standard is %s.\n", TVOUT_STANDARD_NAME(r));
        } else if (strcmp(a, "help") == 0 || strcmp(a, "--help") == 0 || strcmp(a, "-h") == 0)
            help(argv[0]);
        else if (strcmp(a, "ntsc") == 0) 
            standard = ATI_TVOUT_STANDARD_NTSC;
        else if (strcmp(a, "ntscj") == 0) 
            standard = ATI_TVOUT_STANDARD_NTSCJ;
        else if (strcmp(a, "pal") == 0)
            standard = ATI_TVOUT_STANDARD_PAL;
        else if (strcmp(a, "pal60") == 0)
            standard = ATI_TVOUT_STANDARD_PAL60;
        else if (strcmp(a, "palm") == 0)
            standard = ATI_TVOUT_STANDARD_PALM;
        else if (strcmp(a, "off") == 0)
            display = 0;
        else if (strcmp(a, "-f") != 0 && strcmp(a, "-r") != 0) {
            char *p;

            display = 0;

            for (p = a; *p; p++)
                if (*p == 'c')
                    display |= ATI_DISPLAY_CRT;
                else if (*p == 't')
                    display |= ATI_DISPLAY_TV;
                else if (*p == 'l')
                    display |= ATI_DISPLAY_LCD;
                else {
                    fprintf(stderr, "Unknown command: %s\n", a);
                    return 9;
                }
        }

        if (standard != -1) {
            if (!radeon) {
                if (mach64_set_tvout_standard(standard) < 0)
                    return 10;
            } else {
                if (radeon_set_tvout_standard(standard) < 0)
                    return 10;
            }
        }
        
        if (display != -1) {
            if (!radeon) {
                if (mach64_set_active_displays(display) < 0)
                    return 11;
            } else {
                if (radeon_set_active_displays(display) < 0)
                    return 11;
            }
        }
    }

    return 0;
}
atitvout/radeon.c0100644000175000001440000001027407541431006013740 0ustar  lennartusers/*
 * 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 "radeon.h"
#include "vbecall.h"

// This call seems to do more than just detect attached TVs: it
// enables all those displays which have been enabled with the last
// call to radeon_set_active_displays()
int radeon_detect_attached_displays(unsigned *tv) {
    int retval,tv_out;
    struct LRMI_regs r;
    memset(&r, 0, sizeof(r));

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

    if (vbe_call(&r) != 0)
        return -1;
    retval = 0;
    tv_out = ((r.ecx>>8)&0xFF);
    /* FIXME: doc says that tvout info is returned in CH
       but CH on my Radeon VE is always 0. But such info
       is present in high part of CL !!! */
    if(!tv_out && (r.ecx>>4)&0xF) tv_out = (r.ecx>>4)&0xF;
    if(tv_out)
    {
        *tv = tv_out;
        retval |= ATI_DISPLAY_TV;
    }
/*
  Note: Here we can return more precise info:
  cl = 0 - no CRT connected
  cl = 1 - monochrome CRT is connected
  cl = 2 - color monitor is connected
*/
    if (r.ecx&0xFF) retval |= ATI_DISPLAY_CRT;
    if ((r.ebx&0xFF) == 1) retval |= ATI_DISPLAY_LCD;
    return retval;
}

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

    r.eax = 0xa015;
    r.ecx = 0x0000;

    if (vbe_call(&r) != 0)
        return -1;
    
    return ((r.ecx & 1) ? ATI_DISPLAY_CRT : 0) |
        ((r.ecx & 2) ? ATI_DISPLAY_TV : 0) |
        ((r.ecx & 4) ? ATI_DISPLAY_LCD : 0) |
        ((r.ecx & 8) ? ATI_DISPLAY_AUTOSWITCH : 0);
}

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

    r.eax = 0xa015;
    r.ecx = 0x0100;

    if (v & ATI_DISPLAY_CRT) r.ecx |= 1;
    if (v & ATI_DISPLAY_TV) r.ecx |= 2;
    if (v & ATI_DISPLAY_LCD) r.ecx |= 4;
    if (v & ATI_DISPLAY_AUTOSWITCH) r.ecx |= 8;

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

int radeon_get_tvout_config(unsigned *rev, int *freq) {
    struct LRMI_regs r;
    memset(&r, 0, sizeof(r));

    r.eax = 0xA017;
    r.edi = 0x00;

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

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

    if (freq)
        *freq = r.ecx & 0xff;
    
    if (r.edx & 0x3)
        printf("TVOut chip is detected but not supported in BIOS\n");
    else if (r.edx & 0x1)
        printf("TVOut chip is detected and supported in BIOS\n");
    else
        printf("no TVOut chip is detected\n");
    
    return ATI_TVOUT_ENABLED;
}

int radeon_get_tvout_standard() {
    struct LRMI_regs r;
    memset(&r, 0, sizeof(r));
    
    r.eax = 0xa016;
    r.ecx = 0x0000;
    
    if (vbe_call(&r) != 0)
        return -1;
/*
  ch = current active standard value
  1 - ntsc
  2 - pal
  3 - palm
  4 - pal60
  5 - ntscj
  6 - scartrgb

  cl = mask of standards supported on the fly    
  0x01 - ntsc
  0x02 - pal
  0x04 - palm
  0x08 - pal60
  0x10 - ntscj
  0x20 - scartrgb
*/
    printf("Can set on the fly:\n");
    if (r.ecx & 0x01) printf(" ntsc\n");
    if (r.ecx & 0x02) printf(" pal\n");
    if (r.ecx & 0x04) printf(" palm\n");
    if (r.ecx & 0x08) printf(" pal60\n");
    if (r.ecx & 0x10) printf(" ntscj\n");
    if (r.ecx & 0x20) printf(" scartrgb\n");
    
    return ((r.ecx >> 8) & 0xff)-1;
}

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

    r.eax = 0xa016;
/*
  cl = new standard value
  1 - ntsc
  2 - pal
  3 - palm
  4 - pal60
  5 - ntscj
  6 - scartrgb
*/
    r.ecx = 0x0100|((v+1)&0xFF);

    if (vbe_call(&r) != 0)
        return -1;
    
    return 0; /* always no error */
}
atitvout/COPYING0100644000175000001440000004311007415633734013366 0ustar  lennartusers		    GNU GENERAL PUBLIC LICENSE
		       Version 2, June 1991

 Copyright (C) 1989, 1991 Free Software Foundation, Inc.
     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 Everyone is permitted to copy and distribute verbatim copies
 of this license document, but changing it is not allowed.

			    Preamble

  The licenses for most software are designed to take away your
freedom to share and change it.  By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users.  This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it.  (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.)  You can apply it to
your programs, too.

  When we speak of free software, we are referring to freedom, not
price.  Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.

  To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.

  For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have.  You must make sure that they, too, receive or can get the
source code.  And you must show them these terms so they know their
rights.

  We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.

  Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software.  If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.

  Finally, any free program is threatened constantly by software
patents.  We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary.  To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.

  The precise terms and conditions for copying, distribution and
modification follow.

		    GNU GENERAL PUBLIC LICENSE
   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

  0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License.  The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language.  (Hereinafter, translation is included without limitation in
the term "modification".)  Each licensee is addressed as "you".

Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope.  The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.

  1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.

You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.

  2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:

    a) You must cause the modified files to carry prominent notices
    stating that you changed the files and the date of any change.

    b) You must cause any work that you distribute or publish, that in
    whole or in part contains or is derived from the Program or any
    part thereof, to be licensed as a whole at no charge to all third
    parties under the terms of this License.

    c) If the modified program normally reads commands interactively
    when run, you must cause it, when started running for such
    interactive use in the most ordinary way, to print or display an
    announcement including an appropriate copyright notice and a
    notice that there is no warranty (or else, saying that you provide
    a warranty) and that users may redistribute the program under
    these conditions, and telling the user how to view a copy of this
    License.  (Exception: if the Program itself is interactive but
    does not normally print such an announcement, your work based on
    the Program is not required to print an announcement.)

These requirements apply to the modified work as a whole.  If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works.  But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.

Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.

In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.

  3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:

    a) Accompany it with the complete corresponding machine-readable
    source code, which must be distributed under the terms of Sections
    1 and 2 above on a medium customarily used for software interchange; or,

    b) Accompany it with a written offer, valid for at least three
    years, to give any third party, for a charge no more than your
    cost of physically performing source distribution, a complete
    machine-readable copy of the corresponding source code, to be
    distributed under the terms of Sections 1 and 2 above on a medium
    customarily used for software interchange; or,

    c) Accompany it with the information you received as to the offer
    to distribute corresponding source code.  (This alternative is
    allowed only for noncommercial distribution and only if you
    received the program in object code or executable form with such
    an offer, in accord with Subsection b above.)

The source code for a work means the preferred form of the work for
making modifications to it.  For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable.  However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.

If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.

  4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License.  Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.

  5. You are not required to accept this License, since you have not
signed it.  However, nothing else grants you permission to modify or
distribute the Program or its derivative works.  These actions are
prohibited by law if you do not accept this License.  Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.

  6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions.  You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.

  7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License.  If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all.  For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.

If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.

It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices.  Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.

This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.

  8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded.  In such case, this License incorporates
the limitation as if written in the body of this License.

  9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time.  Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.

Each version is given a distinguishing version number.  If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation.  If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.

  10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission.  For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this.  Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.

			    NO WARRANTY

  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.

  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.

		     END OF TERMS AND CONDITIONS

	    How to Apply These Terms to Your New Programs

  If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.

  To do so, attach the following notices to the program.  It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.

    <one line to give the program's name and a brief idea of what it does.>
    Copyright (C) <year>  <name of author>

    This program 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.

    This program 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 this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


Also add information on how to contact you by electronic and paper mail.

If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:

    Gnomovision version 69, Copyright (C) year  name of author
    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
    This is free software, and you are welcome to redistribute it
    under certain conditions; type `show c' for details.

The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License.  Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.

You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary.  Here is a sample; alter the names:

  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
  `Gnomovision' (which makes passes at compilers) written by James Hacker.

  <signature of Ty Coon>, 1 April 1989
  Ty Coon, President of Vice

This General Public License does not permit incorporating your program into
proprietary programs.  If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library.  If this is what you want to do, use the GNU Library General
Public License instead of this License.
atitvout/README.in0100640000175000001440000001255307541370010013604 0ustar  lennartusersatitvout VERSION - Linux ATI TV Out Support Program
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Copyright 2002
Lennart Poettering <mz617469@poettering.de>

---------------------------------------------------------------------

This program 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.

This program 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 this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

---------------------------------------------------------------------

This utility program may be used for executing several configuration
commands for the TV Out connector of ATI Rage Mobility P/M graphics
boards under GNU/Linux on x86. It is intended primarily to enable TV
Out support after bootup and for switching the used TV standard from
NTSC to PAL.

The utility makes use of x86-VESA-BIOS-calls and thus is not portable
to other architectures like PPC: *No TV-Out on Macs with this tool*.

Please Notice
-------------

*Notice*: I do not answer any questions related to Microsoft Windows and ATI's own drivers on that OS.

*Notice*: I don't know where to get the newest ATI drivers for Windows 95, 98, ME, 2000, XP.

*Notice*: I silently ignore HTML mail.

*Notice*: I do not answer any questions related to XFree86 configuration files.

*Notice*: No, I have no "working modeline" for you.

*Notice*: No, there is no chance to get this tool to work on PPC. It's x86-only.

Usage
-----

For usage info try "atitvout help". I normally run the utility with
"atitvout pal auto". This switches to PAL for german TVs and enables
the TV out, when available.

Supported Devices
-----------------

I developed this tool on an ATI Rage Mobility P/M, but I added support
for other devices like the Radeon, the Rage 128, Mobility M3, Mobility
M4.

BUT DON'T FORGET: THE RAGE MOBILITY P/M IS THE ONLY ADAPTER ON WHICH
THE UTILITY IS KNOWN TO WORK. ON ALL OTHER ADAPTERS YOUR MILEAGE MAY
VARY.

Rage Mobility P/M and Mobility M3/M4 differ.

The PCI info of my Rage Mobility follows:

<pre>
[lennart@whiskey] ~$ /sbin/lspci -vs 1:0.0

	VGA compatible controller: ATI Technologies Inc Rage Mobility P/M AGP 2x (rev 64) (prog-if 00 [VGA])
	Subsystem: FIRST INTERNATIONAL Computer Inc: Unknown device 1730
	Flags: bus master, stepping, medium devsel, latency 66, IRQ 5
	Memory at fd000000 (32-bit, non-prefetchable) [size=16M]
	I/O ports at 2000 [size=256]
	Memory at fc100000 (32-bit, non-prefetchable) [size=4K]
	Expansion ROM at <unassigned> [disabled] [size=128K]
	Capabilities: <available only to root>

[lennart@whiskey] ~$ 
</pre>

The program should work at least on those graphics cards which share
the same PCI info with mine. My card is built into a laptop from
Aldi/Medion. (http://www.stud.uni-hamburg.de/users/lennart/aldi/)

Notes
-----

When using the ati driver of XFree 4.1 you should rerun this utility
always after having changed the screen resolution with C-A-+ or
C-A--. Otherwise the displays may go nuts.

As ATI denied to supply me with documentation about the TV Out
interface of their cards and I do not have a ATI Radeon or Rage 128 I
cannot fix my utility so that it works correctly on all these
devices. Thus the support for these devices is rather limited and may
be broken. Please try to run 'test.sh' and have an eye an all your
attached displays, if you experience failures. For better support on
non-Mobility-P/M-devices you need to fix the utility yourself.

Not all ATI adapters support all of these commands. Please try them
all before complaining.

Most cards do not allow to activate non attached displays. All calls
to atitvout will fail if you try to enable displays which do not show
up in 'atitvout detect'.

Not all adapters seem to support simultaneously using TV and LCD/CRT
from within Linux. Thus 'lt' (resp. 'ct') may fail, while 'l' (resp. 'c')
and 't' succeed. In this case 'auto' will fail too. In fact 'auto'
works only on very few adapters.

Development
-----------

Development was done under Debian GNU Linux Sid for i386 from January
2002. The used machine was a Medion 9580-F laptop with an ATI Rage
Mobility P/M graphics board.

Installation
------------

Run "make" for compiling the program. You might want to install it
permanently on your system by issuing "make install" as root. This
installs the atitvout executable to /usr/local/sbin/. For removing this
installation you might want to try "make deinstall" as root.

Internet
--------

You may find up to date releases of this utility on
	http://www.stud.uni-hamburg.de/users/lennart/projects/atitvout/

You may download this release from
	http://www.stud.uni-hamburg.de/users/lennart/projects/atitvout/atitvout-VERSION.tar.gz

Thanks go to
------------

Leif Delgass for supplying me with information about ATI VBE calls

Nick Kurshev for a Radeon/R128 related patch

Stefan Raspl for a ATI Mobility Radeon related patch

Josh Vanderhoof for developing LRMI

---------------------------------------------------------------------

Lennart Poettering <mz617469@poettering.de>, 2002
atitvout/vbeinfo.c0100644000175000001440000000406507416140206014121 0ustar  lennartusers/*
 * 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 <stdio.h>
#include <string.h>

#include <lrmi.h>
#include <vbe.h>

#include "vbeinfo.h"

int vbe_info(int *vh, int *vl, char *oe, int s) {
    struct LRMI_regs r;
    struct vbe_info_block *vib;
    
    if (!(vib = LRMI_alloc_real(sizeof(struct vbe_info_block)))) {
        fprintf(stderr, "Can't alloc real mode memory.\n");
        return -1;
    }
    
    memset(&r, 0, sizeof(r));

    r.eax = 0x4f00;
    r.es = (unsigned int) vib >> 4;
    r.edi = 0;
        
    memcpy(vib->vbe_signature, "VBE2", 4);

    if (!LRMI_int(0x10, &r)) {
        fprintf(stderr, "Can't get VESA info (vm86 failure)\n");
        LRMI_free_real(vib);
        return -2;
    }

    if ((r.eax & 0xffff) != 0x4f || strncmp(vib->vbe_signature, "VESA", 4) != 0) {
        fprintf(stderr, "No VESA bios\n");
        LRMI_free_real(vib);
        return -3;
    }

    if (vh)
        *vh = (vib->vbe_version >> 8) & 0xff;

    if (vl)
        *vl = vib->vbe_version & 0xff;

    if (oe && s) {
        int i;
        if (s > sizeof(vib->oem_data))
            s = sizeof(vib->oem_data);
        
        for (i = 0; i < s; i++)
            if (vib->oem_data[i] >= ' ' && vib->oem_data[i] < 127)
                oe[i] = vib->oem_data[i];
            else {
                oe[i] = 0;
                break;
            }
    }
    
    LRMI_free_real(vib);
    
    return 0;
}
atitvout/test.sh0100755000175000001440000000071007416343500013636 0ustar  lennartusers#!/bin/bash

testit () {
	echo "TEST: Running 'atitvout $FLAG $1' ..."
	./atitvout $FLAG $1
	echo "TEST: ... finished. Return value is $?. Please wait 3 seconds."
	echo
	sleep 3
}

testall () {
	testit vbe
	testit tvout
	testit standard
	testit pal
	testit ntsc
	testit detect
	testit active
	testit auto
	testit off
	testit l
	testit c
	testit t
	testit lc
	testit lt
	testit ct
	testit lct
}


(
	FLAG=-f
	testall
	FLAG=-r
	testall
) 2>&1 | tee test.out
atitvout/ati.c0100644000175000001440000000204507416063717013255 0ustar  lennartusers/*
 * 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"

float tvout_reffreq_table[] = {
    29.49892,
    28.63636,
    14.31818,
    27.00000};

const char* tvout_standard_table[] = {
    "NTSC",
    "PAL",
    "PAL-M",
    "PAL-60",
    "NTSC-J",
    "PAL-CN/SCART-RGB",
    "PAL-N",
    "??",
    "??",
    "SCART PAL" };

atitvout/mails0100600000175000001440000001243107451110631013337 0ustar  lennartusersFrom tool@ircninja.com Thu Jan 31 01:57:22 2002
Return-path: <tool@ircninja.com>
Envelope-to: lennart@campari.bogus
Delivery-date: Thu, 31 Jan 2002 01:57:22 +0100
Received: from campari.bogus
	([192.168.100.1] helo=localhost ident=user74902)
	by campari.bogus with esmtp (Exim 3.33 #1 (Debian))
	id 16W5XV-0004cU-00
	for <lennart@campari.bogus>; Thu, 31 Jan 2002 01:57:22 +0100
X-Envelope-From: <tool@ircninja.com>
X-Envelope-To: <lennart@poettering.de>
X-Delivery-Time: 1012438222
Received: from post.strato.de
	by localhost with POP3 (fetchmail-5.9.6)
	for lennart@campari.bogus (single-drop); Thu, 31 Jan 2002 01:57:21 +0100 (CET)
Received: from phucknut.com (ool-18bee2fd.dyn.optonline.net [24.190.226.253])
	by post.webmailer.de (8.9.3/8.8.7) with SMTP id BAA08173
	for <lennart@poettering.de>; Thu, 31 Jan 2002 01:50:22 +0100 (MET)
Received: (qmail 16176 invoked from network); 31 Jan 2002 00:50:34 -0000
Received: from unknown (HELO blah) (tool@192.168.0.1)
  by 192.168.0.1 with SMTP; 31 Jan 2002 00:50:34 -0000
Date: Wed, 30 Jan 2002 19:50:34 -0500 (EST)
From: <tool@ircninja.com>
X-Sender: tool@blah
To: Lennart Poettering <lennart@poettering.de>
Old-Subject: Re: atitvout + Rage Mobility M3
In-Reply-To: <20020130225702.GE2234@whiskey.bogus>
Message-ID: <Pine.LNX.4.21.0201301944390.16173-100000@blah>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
Subject: Re: atitvout + Rage Mobility M3
Status: RO
X-Status: A
Content-Length: 1532
Lines: 44


Actually, I've figured it out since then. :)  The tvout only works at
lower resolutions, so if I switch to 800x600 first it works
perfect.  You might want to make a note of this on the web site for
other m3 owners.  The only thing not working now is simultaneous output on
the lcd and tvout, but I can live without that. 

Thanks for writing this util, it's the only thing that was unsupported on
this laptop in linux. :)

-Kevin

On Wed, 30 Jan 2002, Lennart Poettering wrote:

> On Fri, 25.01.02 21:08, tool@ircninja.com (tool@ircninja.com) wrote:
> 
> > 
> > Hi,
> > 
> > I've been playing around with atitvout, trying to get it working with my
> > laptop (thinkpad a22p).  The detect and active commands work with -f, but
> > not much else seems to work.
> > 
> > I'm a decent C coder, so if there's anything I can do to help, let me
> > know.  I'd REALLY like to get this working. :)   I also have access to
> > some other laptops with ati chipsets, I'll let you know how it works out
> > once I try it on them.
> 
> The M3 seems to have problems with atitvout. Have you tried to run the
> test script? any success with that?
> 
> I do not see any way how you could help atitvout's development as
> there is no documentation from ati available. all you might try is to
> reverse engineer the windows driver. good luck!
> 
> lp
> 
> 
> -- 
> name { Lennart Poettering } mail { lennart@poettering.de }
> icq { 11060553 } www { http://www.poettering.de/lennart/ }
> loc { hamburg, germany } pgp { 0x1A015CC4 } hack { .phi. }
> 


From henri.valta@kemi.fi Sat Mar 23 16:14:03 2002
Return-path: <henri.valta@kemi.fi>
Envelope-to: lennart@campari.bogus
Delivery-date: Sat, 23 Mar 2002 16:14:03 +0100
Received: from campari.bogus
	([192.168.100.1] helo=localhost ident=user63562)
	by campari.bogus with esmtp (Exim 3.34 #1 (Debian))
	id 16onDX-0000lN-00
	for <lennart@campari.bogus>; Sat, 23 Mar 2002 16:14:03 +0100
X-Envelope-From: <henri.valta@kemi.fi>
X-Envelope-To: <ati@poettering.de>
X-Delivery-Time: 1016894847
Received: from post.strato.de
	by localhost with POP3 (fetchmail-5.9.8)
	for lennart@campari.bogus (single-drop); Sat, 23 Mar 2002 16:14:03 +0100 (CET)
Received: from fep08.tmt.tele.fi (hank-fep8-0.inet.fi [194.251.242.203])
	by post.webmailer.de (8.9.3/8.8.7) with ESMTP id PAA24683
	for <ati@poettering.de>; Sat, 23 Mar 2002 15:47:26 +0100 (MET)
Received: from cromos.linux-dude.com ([62.71.155.253]) by fep08.tmt.tele.fi
          (InterMail vM.5.01.03.13 201-253-122-118-113-20010918) with ESMTP
          id <20020323144726.QZFA7072.fep08.tmt.tele.fi@cromos.linux-dude.com>
          for <ati@poettering.de>; Sat, 23 Mar 2002 16:47:26 +0200
Content-Type: text/plain;
  charset="us-ascii"
From: Henri Valta <henri.valta@kemi.fi>
To: ati@poettering.de
Subject: Atitvout 0.2 with radeon works
Date: Sat, 23 Mar 2002 09:47:25 -0500
X-Mailer: KMail [version 1.4]
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Message-Id: <200203230947.25330.henri.valta@kemi.fi>
Status: RO
X-Status: A
Content-Length: 893
Lines: 36

Hi,
Atitvout works for me:) Thanks for this utility!
Card: Radeon 64 ddr vivo

Here's the output of some commands, in case you're interested:

# atitvout vbe
VBE Version: 2.0
VBE OEM Identification: ATI RAGE128

# atitvout tvout
TV Out is enabled.
Reference frequency is 27.00000 Hz
***well, it says the same whether tv out is really enabled or not

# atitvout standard
VBE call failed.
Maybe this command is not supported by your graphics adapter?
Did your parameters (if you specified some) really make sense?
Please try all other available commands before complaining!

# atitvout detect ***when tv is connected
TV is attached via Composite.

# atitvout detect ***when tv is not connected
No TV is attached.

# atitvout active
TV is active.
***this always says tv is active

commands t, ct and auto always enable both crt (50Hz) and tv out
atitvout c restores the normal crt mode

 -Henri


atitvout/vbeinfo.h0100644000175000001440000000150707416140216014125 0ustar  lennartusers#ifndef foovbeinfohfoo
#define foovbeinfohfoo

/*
 * 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.
 */

int vbe_info(int *vh, int *vl, char *oe, int s);

#endif
atitvout/radeon.h0100644000175000001440000000207007541430243013742 0ustar  lennartusers#ifndef fooradeonhfoo
#define fooradeonhfoo

/*
 * 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.
 */

// Support for Radeon and Rage 128 chips

int radeon_detect_attached_displays(unsigned *tv);
int radeon_get_active_displays();
int radeon_set_active_displays(int v);
int radeon_get_tvout_config(unsigned *rev, int *freq);
int radeon_get_tvout_standard();
int radeon_set_tvout_standard(int v);

#endif
atitvout/HARDWARE0100644000175000001440000000145007541430243013442 0ustar  lennartusersFeatures:
 
  Rage Mobility/Rage LT: 

	All functions. Some cards seem not to be able to use TV and LCD
    simultaneously. Some cards do not support TV standard switching.

  Rage 128/Radeon

    TV standard switching is supported. BIOS enables TVout
    automatically when it's connected before PC boot. Other
    things depend on BIOS implementation.
    NOTE: All changes will be activated only at the next
    set_mode call. Thus if you disable CRT output then you 
    will be able to enable it again only through TV screen
    (as usual after next set_mode call).

Compatible Hardware:

  All commands:
    ATI Technologies Inc Rage Mobility P/M AGP 2x
	ATI Technologies Inc 3D Rage LT Pro AGP-133
   
  detect & active:
    ATI Rage Mobility M3

  Fail:
    ATI Technologies Inc Rage Mobility M4 AGP
atitvout/ati.h0100644000175000001440000000331507416126170013254 0ustar  lennartusers#ifndef fooatihfoo
#define fooatihfoo

/*
 * 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.
 */

#define ATI_DISPLAY_LCD 1
#define ATI_DISPLAY_CRT 2
#define ATI_DISPLAY_TV 4
#define ATI_DISPLAY_AUTOSWITCH 8

#define ATI_TV_COMPOSITE 1
#define ATI_TV_SVIDEO 2



#define ATI_TVOUT_NOTDETECTED 0
#define ATI_TVOUT_NOTSUPPORTED 1
#define ATI_TVOUT_DISABLED 2
#define ATI_TVOUT_ENABLED 3

#define ATI_TVOUT_REFFREQ29_49892 0
#define ATI_TVOUT_REFFREQ28_63636 1
#define ATI_TVOUT_REFFREQ14_31818 2
#define ATI_TVOUT_REFFREQ27_00000 3

extern float tvout_reffreq_table[];
#define TVOUT_REFFREQ(x) ((x >= 0) && (x <= 3) ? tvout_reffreq_table[x] : 0.0)

#define ATI_TVOUT_STANDARD_NTSC 0
#define ATI_TVOUT_STANDARD_PAL 1
#define ATI_TVOUT_STANDARD_PALM 2
#define ATI_TVOUT_STANDARD_PAL60 3
#define ATI_TVOUT_STANDARD_NTSCJ 4
#define ATI_TVOUT_STANDARD_PALCN 5
#define ATI_TVOUT_STANDARD_PALN 6
#define ATI_TVOUT_STANDARD_SCARTPAL 9

extern const char* tvout_standard_table[];
#define TVOUT_STANDARD_NAME(x) ((x >= 0) && (x <= 9) ? tvout_standard_table[x] : "??")


#endif
atitvout/Makefile.orig0100644000175000001440000000223607541370021014721 0ustar  lennartusersVERSION=0.3a
CFLAGS=-Wall -O2 -g -DVERSION=\"$(VERSION)\" -I./lrmi-0.6
OBJS=atitvout.o ati.o vbeinfo.o vbecall.o mach64.o radeon.o
TAR=atitvout-$(VERSION).tar.gz
BINARY=atitvout
PACKAGE=atitvout

all: $(BINARY)

$(BINARY): $(OBJS)
	make -C lrmi-0.6
	$(CC) $(OBJS) lrmi-0.6/liblrmi.a -o $(BINARY)

strip: $(BINARY)
	@du -h $(BINARY)
	strip -s $(BINARY)
	@du -h $(BINARY)

clean:
	rm -f *.o $(BINARY) *~ README index.html *.tar.gz test.out
	make -C lrmi-0.6 clean

install: strip
	install -g root -o root -m 555 $(BINARY) /usr/local/sbin

deinstall:
	rm -f /usr/local/sbin/$(BINARY)

README: README.in
	sed s/VERSION/$(VERSION)/ < README.in > README

index.html: README
	txt2html -t "$(PACKAGE) $(VERSION)" < README > index.html

html: index.html

$(TAR): clean README
	tar -C.. --exclude=$(PACKAGE)/$(TAR) -czvf $(TAR) $(PACKAGE)

tar: $(TAR)

web: $(TAR) README
	cp README $(TAR) ../../homepage/lennart/projects/$(PACKAGE)/ && $(MAKE) -C ../../homepage/lennart/projects/$(PACKAGE)

upload: web
	$(MAKE) -C ../../homepage/lennart upload

emacs:
	emacs Makefile README.in *.h *.c &

test: $(BINARY)
	./test.sh

.PHONY: test emacs upload web tar html deinstall install clean strip all
atitvout/vbecall.h0100644000175000001440000000151407416057012014104 0ustar  lennartusers#ifndef foovbecallhfoo
#define foovbecallhfoo

/*
 * 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>

int vbe_call(struct LRMI_regs *r);

#endif
atitvout/vbecall.c0100644000175000001440000000314107416134033014074 0ustar  lennartusers/*
 * 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 <stdio.h>
#include <assert.h>

#include "vbecall.h"

int vbe_call(struct LRMI_regs *r) {

    assert(r);

#ifdef DEBUG
    fprintf(stderr, "Calling VBE with ax=0x%04x, bx=0x%04x, cx=0x%04x, dx=0x%04x.\n", r->eax & 0xFFFF, r->ebx & 0xFFFF, r->ecx & 0xFFFF, r->edx & 0xFFFF);
#endif 
    
    if (!LRMI_int(0x10, r)) {
        fprintf(stderr, "Interrupt call failed.\n");
        return -1;
    }

#ifdef DEBUG
    fprintf(stderr, "VBE call returned with ax=0x%04x, bx=0x%04x, cx=0x%04x, dx=0x%04x.\n", r->eax & 0xFFFF, r->ebx & 0xFFFF, r->ecx & 0xFFFF, r->edx & 0xFFFF);
#endif 


    
    if (r->eax & 0xff00) {
        fprintf(stderr, "VBE call failed.\nMaybe this command is not supported by your graphics adapter?\nDid your parameters (if you specified some) really make sense?\nPlease try all other available commands before complaining!\n");
        return -2;
    }

    return 0;
}
atitvout/mach64.h0100644000175000001440000000207707416063114013563 0ustar  lennartusers#ifndef foomach64hfoo
#define foomach64hfoo

/*
 * 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.
 */

// Support for Rage Mobility and 3D Rage Pro LT

int mach64_detect_attached_displays(unsigned *tv);
int mach64_get_active_displays();
int mach64_set_active_displays(int v);
int mach64_get_tvout_config(unsigned *rev, int *freq);
int mach64_get_tvout_standard();
int mach64_set_tvout_standard(int v);

#endif
atitvout/mach64.c0100644000175000001440000000504607416133157013562 0ustar  lennartusers/*
 * 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;
}