Initial. Don't... just don't ask.

This commit is contained in:
Ryan McGrath 2011-02-24 00:22:00 -08:00
commit 00bae13bba
586 changed files with 129057 additions and 0 deletions

41
lrmi-0.9/Makefile Normal file
View file

@ -0,0 +1,41 @@
CFLAGS ?= -g -Wall
sources = lrmi.c
objects = lrmi.o
all = vbetest mode3 vga_reset vbemodeinfo dosint
%.o: %.c
$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<
all: $(all)
vbetest: vbetest.c lrmi.o
$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $^
mode3: mode3.c lrmi.o
$(CC) $(CFLAGS) -o $@ $^
dosint: dosint.c lrmi.o
$(CC) $(CFLAGS) -o $@ $^
vbemodeinfo: vbemodeinfo.c lrmi.o
$(CC) $(CFLAGS) -o $@ $^
vga_reset: vga_reset.c lrmi.o
$(CC) $(CFLAGS) -o $@ $^
install: mode3 vga_reset
install mode3 /sbin
install vga_reset /sbin
.PHONY: clean
clean:
rm -f $(objects) $(all) core regs-out *.bak
.PHONY: distclean
distclean: clean
rm -f .depend
.PHONY: depend
depend: $(sources)
-$(CC) -M $(CPPFLAGS) $^ >.depend

34
lrmi-0.9/Makefile.bsd Normal file
View file

@ -0,0 +1,34 @@
CFLAGS = -g -Wall
RANLIB = ranlib
OS != uname -s
sources = lrmi.c lrmi.h
objects = lrmi.o
pic_objects = lrmi.lo
all = liblrmi.a liblrmi.so vbetest
.if ${OS}=="NetBSD" || ${OS}=="OpenBSD"
libs= -li386
.endif
all: $(all)
.c.o:
$(CC) -c $(CPPFLAGS) $(CFLAGS) -o ${.TARGET} ${.IMPSRC}
.SUFFIXES: .lo
.c.lo:
$(CC) -c $(CPPFLAGS) $(CFLAGS) -fPIC -o ${.TARGET} ${.IMPSRC}
liblrmi.a: $(objects)
$(AR) -r ${.TARGET} ${.ALLSRC}
$(RANLIB) ${.TARGET}
liblrmi.so: $(pic_objects)
$(CC) $(CPPFLAGS) $(CFLAGS) -fPIC -shared -o ${.TARGET} ${.ALLSRC} ${libs}
vbetest: vbetest.o liblrmi.a
$(CC) $(CPPFLAGS) $(CFLAGS) -o ${.TARGET} ${.ALLSRC} ${libs}
.PHONY: clean
clean:
rm -f $(objects) $(pic_objects) vbetest.o $(all) *.core

56
lrmi-0.9/Makefile.lrmi Normal file
View file

@ -0,0 +1,56 @@
LIBDIR ?= /usr/local/lib
INCDIR ?= /usr/local/include
CFLAGS = -g -Wall
sources = lrmi.c
objects = lrmi.o
pic_objects = lrmi.lo
all = liblrmi.a liblrmi.so vbetest
MAJOR = 0
MINOR = 9
VERSION = $(MAJOR).$(MINOR)
LIBNAME = liblrmi
%.o: %.c
$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<
%.lo: %.c
$(CC) -c $(CPPFLAGS) $(CFLAGS) -fPIC -o $@ $<
all: $(all)
liblrmi.a: $(objects)
$(AR) -rs $@ $^
liblrmi.so: $(pic_objects)
# $(CC) $(CPPFLAGS) $(CFLAGS) -fPIC -shared -o $@ $^
$(CC) $(CPPFLAGS) $(CFLAGS) -Wl,-soname,$(LIBNAME).so.$(MAJOR) -fPIC -shared -o $(LIBNAME).so.$(VERSION) $^
ln -sf $(LIBNAME).so.$(VERSION) $(LIBNAME).so.$(MAJOR)
ln -sf $(LIBNAME).so.$(MAJOR) $(LIBNAME).so
vbetest: vbetest.c liblrmi.a
$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $^
install:
mkdir -p $(LIBDIR)
install -m 755 -s -p $(LIBNAME).so.$(VERSION) $(LIBDIR)/$(LIBNAME).so.$(VERSION)
rm -f $(LIBDIR)/$(LIBNAME).so
ln -sf $(LIBNAME).so.$(VERSION) $(LIBDIR)/$(LIBNAME).so.$(MAJOR)
ln -sf $(LIBNAME).so.$(MAJOR) $(LIBDIR)/$(LIBNAME).so
install -m 644 -s -p lrmi.h $(INCDIR)/lrmi.h
-ldconfig
.PHONY: clean
clean:
rm -f $(objects) $(pic_objects) $(all) core
rm -f liblrmi.so liblrmi.so.$(MAJOR) liblrmi.so.$(VERSION)
.PHONY: distclean
distclean: clean
rm -f .depend
.PHONY: depend
depend: $(sources)
-$(CC) -M $(CPPFLAGS) $^ >.depend

19
lrmi-0.9/README Normal file
View file

@ -0,0 +1,19 @@
This is a modified version of lrmi-0.9 package.
The original is available at http://sourceforge.net/projects/lrmi
Programs included are:
vbetest - show available modes, and test a mode.
vbegetmodeinfo - show information about a vbe mode.
mode3 - set mode using vesa bios. It can usually restore text mode after
svgalib leaves a non-working text-mode.
vga_reset - call real mode c000:0003, which should be the video card's
initialization routine. Should work in some cases when mode3 fails to
restore text mode.
get-edid - Use vbe call to get monitor's edid information.

39
lrmi-0.9/README.lrmi Normal file
View file

@ -0,0 +1,39 @@
Linux Real Mode Interface
=========================
1, Goal
This library provides a DPMI like interface under Linux and *BSD systems
using vm86. There is also some VBE (VESA Bios Extension) interface utility
called vbetest.
2, Supported systems
Only under x86:
* Linux 2.2 and above
* FreeBSD
* NetBSD
* OpenBSD
3, License
Look into the individual source files.
4, Authors
Josh Vanderhoof
* original author
Dmitry Frolov
* FreeBSD/NetBSD support
Alex Beregszaszi
* merged MPlayer, MPlayerXP, svgalib and LRMI versions
* OpenBSD support
Oleg I. Vdovikin <vdovikin@jscc.ru>
* pthread fixes
Peter Kosinar <goober@ksp.sk>
* pthread fixes

54
lrmi-0.9/dosint.c Normal file
View file

@ -0,0 +1,54 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/io.h>
#include "lrmi.h"
unsigned char * edid = NULL;
int read_edid()
{
int i;
struct LRMI_regs regs;
if (!LRMI_init()) {
return -1;
}
edid = LRMI_alloc_real(128);
if ( edid == NULL )
{
return -1;
}
memset(edid, 0xed, 128);
memset(&regs, 0, sizeof(regs));
regs.es = (unsigned int)edid >> 4;
regs.edi = 0;
regs.eax = 0x4f15;
regs.ebx = 0x01;
ioperm(0,0x400,1);
iopl(3);
LRMI_int( 0x10, &regs );
iopl(0);
ioperm(0,0x400,0);
if(*edid || *(edid+7)) return -2;
for(i=1;i<=6;i++) if(*(edid+i)!=0xff) return -2;
return regs.eax;
}
int main ( int argc, char *argv[])
{
read_edid();
fwrite(edid,128,1,stdout);
return 0;
}

2
lrmi-0.9/get-edid Executable file
View file

@ -0,0 +1,2 @@
#!/bin/sh
./dosint 0x10 0x4f15 0x0001 0x80

1043
lrmi-0.9/lrmi.c Normal file

File diff suppressed because it is too large Load diff

108
lrmi-0.9/lrmi.h Normal file
View file

@ -0,0 +1,108 @@
/*
Linux Real Mode Interface - A library of DPMI-like functions for Linux.
Copyright (C) 1998 by Josh Vanderhoof
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL JOSH VANDERHOOF BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef LRMI_H
#define LRMI_H
#if defined(__i386__) && (defined(__linux__) || defined(__NetBSD__) \
|| defined(__FreeBSD__) || defined(__OpenBSD__))
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)
/*
Package version (high 16bit = major, low 16bit minor)
*/
#define LRMI_version 0x0009 /* 0.9 */
/*
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);
#else /* (__linux__ || __NetBSD__ || __FreeBSD__) && __i386__ */
#warning "LRMI is not supported on your system!"
#endif
#endif

53
lrmi-0.9/mode3.c Normal file
View file

@ -0,0 +1,53 @@
/*
Set mode to VESA mode 3 (80x25 text mode)
*/
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <sys/io.h>
#include <sys/kd.h>
#include <sys/stat.h>
#include "lrmi.h"
void set_vesa_mode(int mode){
struct LRMI_regs r;
memset(&r, 0, sizeof(r));
r.eax = 0x4f02;
r.ebx = mode;
if (!LRMI_int(0x10, &r))
{
fprintf(stderr, "Can't set video mode (vm86 failure)\n");
}
}
int main(int argc, char *argv[]){
int i;
if((argc>1)&&(!strcmp(argv[1],"-h"))){
printf("Usage: mode3 [ modenum [ font ] ]\n"
"\n"
"uses VESA bios to set video mode to modenum (3 by default)\n"
"if font is given, uses setfont to change the screen font\n\n");
return 0;
};
if (!LRMI_init())
return 1;
ioperm(0, 0x400, 1);
iopl(3);
i=3;
if(argc>1){
sscanf(argv[1],"%i",&i);
if((i<=0))i=3;
};
set_vesa_mode(i);
if(argc>2){
execlp("setfont",argv[2],NULL);
return 1;
};
return 0;
}

95
lrmi-0.9/vbe.h Normal file
View file

@ -0,0 +1,95 @@
/*
This file is in the public domain.
*/
#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

133
lrmi-0.9/vbemodeinfo.c Normal file
View file

@ -0,0 +1,133 @@
/*
List the available VESA graphics and text modes.
This program is in the public domain.
*/
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <sys/io.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;
} vbe;
int
main(int argc, char *argv[]) {
struct LRMI_regs r;
int mode;
if((argc!=2)||((mode=atoi(argv[1]))==0)){
printf("usage: vbemodeinfo <mode>\n"
"where <mode> is a vesa mode numder.\n"
"use vbetest to list available modes\n\n");
return 0;
};
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);
/*
Allow read/write to all IO ports
*/
ioperm(0, 0x400 , 1);
iopl(3);
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));
memset(&r, 0, sizeof(r));
r.eax = 0x4f01;
r.ecx = mode;
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;
}
printf("mode %i\n",mode);
printf ("mode_attributes = %i\n", vbe.mode->mode_attributes);
printf ("win_a_attributes = %i\n", vbe.mode->win_a_attributes);
printf ("win_b_attributes = %i\n", vbe.mode->win_b_attributes);
printf ("win_granularity = %i\n", vbe.mode->win_granularity);
printf ("win_size = %i\n", vbe.mode->win_size);
printf ("win_a_segment = %i\n", vbe.mode->win_a_segment);
printf ("win_b_segment = %i\n", vbe.mode->win_b_segment);
printf ("win_func_ptr_off = %i\n", vbe.mode->win_func_ptr_off);
printf ("win_func_ptr_seg = %i\n", vbe.mode->win_func_ptr_seg);
printf ("bytes_per_scanline = %i\n", vbe.mode->bytes_per_scanline);
printf ("x_resolution = %i\n", vbe.mode->x_resolution);
printf ("y_resolution = %i\n", vbe.mode->y_resolution);
printf ("x_char_size = %i\n", vbe.mode->x_char_size);
printf ("y_char_size = %i\n", vbe.mode->y_char_size);
printf ("number_of_planes = %i\n", vbe.mode->number_of_planes);
printf ("bits_per_pixel = %i\n", vbe.mode->bits_per_pixel);
printf ("number_of_banks = %i\n", vbe.mode->number_of_banks);
printf ("memory_model = %i\n", vbe.mode->memory_model);
printf ("bank_size = %i\n", vbe.mode->bank_size);
printf ("number_of_image_pages = %i\n", vbe.mode->number_of_image_pages);
printf ("res1 = %i\n", vbe.mode->res1);
printf ("red_mask_size = %i\n", vbe.mode->red_mask_size);
printf ("red_field_position = %i\n", vbe.mode->red_field_position);
printf ("green_mask_size = %i\n", vbe.mode->green_mask_size);
printf ("green_field_position = %i\n", vbe.mode->green_field_position);
printf ("blue_mask_size = %i\n", vbe.mode->blue_mask_size);
printf ("blue_field_position = %i\n", vbe.mode->blue_field_position);
printf ("rsvd_mask_size = %i\n", vbe.mode->rsvd_mask_size);
printf ("rsvd_field_position = %i\n", vbe.mode->rsvd_field_position);
printf ("direct_color_mode_info = %i\n", vbe.mode->direct_color_mode_info);
printf ("phys_base_ptr = %i\n", vbe.mode->phys_base_ptr);
printf ("offscreen_mem_offset = %i\n", vbe.mode->offscreen_mem_offset);
printf ("offscreen_mem_size = %i\n", vbe.mode->offscreen_mem_size);
LRMI_free_real(vbe.info);
return 0;
}

450
lrmi-0.9/vbetest.c Normal file
View file

@ -0,0 +1,450 @@
/*
List the available VESA graphics modes.
This program is in the public domain.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
#if defined(__linux__)
#include <sys/io.h>
#include <sys/kd.h>
#include <sys/stat.h>
#elif defined(__NetBSD__) || defined(__OpenBSD__)
#include <time.h>
#include <dev/wscons/wsconsio.h>
#include <machine/sysarch.h>
#elif defined(__FreeBSD__)
#include <machine/console.h>
#include <machine/sysarch.h>
#endif
#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;
static char *run_command = NULL;
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(int n)
{
void *state;
#if defined(__linux__)
struct stat stat;
#elif defined(__NetBSD__) || defined(__OpenBSD__)
struct wsdisplay_fbinfo wsi;
#elif defined(__FreeBSD__)
struct vid_info vi;
#endif
if (n == -1) {
printf("Type a mode number, or 'q' to quit - ");
if (scanf("%d", &n) != 1)
return;
}
#if defined(__linux__)
if (fstat(0, &stat) != 0) {
fprintf(stderr, "Can't stat() stdin\n");
return;
}
if ((stat.st_rdev & 0xff00) != 0x400
|| (stat.st_rdev & 0xff) > 63)
#elif defined(__NetBSD__) || defined(__OpenBSD__)
if (ioctl(0, WSDISPLAYIO_GINFO, &wsi) == -1)
#elif defined(__FreeBSD__)
memset(&vi, 0, sizeof(vi));
vi.size = sizeof(vi);
if (ioctl(0, CONS_GETINFO, &vi) == -1)
#endif
{
fprintf(stderr, "To switch video modes, "
"this program must be run from the console\n");
return;
}
printf("setting mode %d\n", n);
#if defined(__linux__) || defined(__FreeBSD__)
ioctl(0, KDSETMODE, KD_GRAPHICS);
#elif defined(__NetBSD__) || defined(__OpenBSD__)
ioctl(0, WSDISPLAYIO_SMODE, WSDISPLAYIO_MODE_MAPPED);
#endif
state = save_state();
if (state == NULL)
return;
set_mode(n);
system(run_command);
sleep(5);
text_mode();
restore_state(state);
#if defined(__linux__) || defined(__FreeBSD__)
ioctl(0, KDSETMODE, KD_TEXT);
#elif defined(__NetBSD__) || defined(__OpenBSD__)
ioctl(0, WSDISPLAYIO_SMODE, WSDISPLAYIO_MODE_EMUL);
#endif
}
void
usage_and_quit(int error)
{
fputs("Usage: vbetest [-m mode] [-c command]\n",
error ? stderr : stdout);
exit(error);
}
int
main(int argc, char *argv[])
{
struct LRMI_regs r;
short int *mode_list;
int i, mode = -1;
#if defined(__NetBSD__) || defined(__OpenBSD__)
unsigned long iomap[32];
#endif
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-c") == 0) {
i++;
if (i == argc)
usage_and_quit(1);
run_command = argv[i];
} else if (strcmp(argv[i], "-m") == 0) {
char *e;
i++;
if (i == argc)
usage_and_quit(1);
mode = strtol(argv[i], &e, 10);
if (e == argv[i])
usage_and_quit(1);
} else
usage_and_quit(1);
}
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
*/
#if defined(__linux__)
ioperm(0, 1024, 1);
iopl(3);
#elif defined(__NetBSD__) || defined(__OpenBSD__)
memset(&iomap[0], 0xff, sizeof(iomap));
i386_set_ioperm(iomap);
i386_iopl(3);
#elif defined(__FreeBSD__)
i386_set_ioperm(0, 0x10000, 1);
#endif
#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(mode);
return 0;
}

25
lrmi-0.9/vga_reset.c Normal file
View file

@ -0,0 +1,25 @@
/*
Call real mode c0003
*/
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/io.h>
#include "lrmi.h"
int main(int argc, char *argv[]){
struct LRMI_regs r;
if (!LRMI_init())
return 1;
ioperm(0, 0x400, 1);
iopl(3);
memset(&r,0,sizeof(r));
r.ip=3;
r.cs=0xc000;
LRMI_call(&r);
return 0;
}