SVGAlib

new topic     » topic index » view thread      » older message » newer message

Hello Everybody,

I've written some graphics wrappers for Euphoria Linux Release #4.
The following routines are emulated using SVGAlib.
  graphics_mode
  pixel
  get_pixel
  draw_line
  video_config

The constants are different for graphics modes than in DOS, but they are
pretty easy to figure out.

In order to run svgatest.exu you will either have be running as root, or
have set bin/exu to be setuid root.  Either way this poses a great
security risk, as any Euphoria programs run this way will have full access
rights to your system.  The vga_init function called from svga.e will give
up supervisor rights, but any program can do what they will before svga.e
is included.  My recommendation would be run exu as root, or better yet,
use sudo to run exu, ex "sudo exu svgatest.exu".  Sudo is better for
controlling who has rootly powers, and it's easier than switching to root
every time you want to run a program.  Changing exu to be setuid root is
too dangerous in my opinion, other users could write and execute euphoria
programs that wreak havoc on your system.  Gee, this sounds about as
secure as... DOS.  blink

Anyhow, you must have svgalib installed to be able to run this, get it at
http://www.svgalib.org
If you have problems with svgalib autodecting your chipset, check
/etc/vga/libvga.config and you may have to copy values from
/etc/X11/XF86Config for monitor settings and such.
Reading the svgalib and vga_init man pages might help too.


--------------------------------------------------------
-- svga.e
-- Emulating Euphoria graphics routines using SVGAlib
-- requires Euphoria Linux Release #4 and SVGAlib (www.svgalib.org)
-- Pete Eberlein <xseal at harborside.com>


global constant -- for graphics_mode()
        TEXT        = 0,                -- Compatible with VGAlib v1.2 --
        G320x200x16 = 1,
        G640x200x16 = 2,
        G640x350x16 = 3,
        G640x480x16 = 4,
        G320x200x256 = 5,
        G320x240x256 = 6,
        G320x400x256 = 7,
        G360x480x256 = 8,
        G640x480x2  = 9,

        G640x480x256 = 10,
        G800x600x256 = 11,
        G1024x768x256 = 12,

        G1280x1024x256 = 13,    -- Additional modes. --

        G320x200x32K = 14,
        G320x200x64K = 15,
        G320x200x16M = 16,
        G640x480x32K = 17,
        G640x480x64K = 18,
        G640x480x16M = 19,
        G800x600x32K = 20,
        G800x600x64K = 21,
        G800x600x16M = 22,
        G1024x768x32K = 23,
        G1024x768x64K = 24,
        G1024x768x16M = 25,
        G1280x1024x32K = 26,
        G1280x1024x64K = 27,
        G1280x1024x16M = 28,

        G800x600x16 = 29,
        G1024x768x16 = 30,
        G1280x1024x16 = 31,

        G720x348x2 = 32,                -- Hercules emulation mode --

        G320x200x16M32 = 33,    -- 32-bit per pixel modes. --
        G640x480x16M32 = 34,
        G800x600x16M32 = 35,
        G1024x768x16M32 = 36,
        G1280x1024x16M32 = 37,

        -- additional resolutions --
        G1152x864x16 = 38,
        G1152x864x256 = 39,
        G1152x864x32K = 40,
        G1152x864x64K = 41,
        G1152x864x16M = 42,
        G1152x864x16M32 = 43,

        G1600x1200x16 = 44,
        G1600x1200x256 = 45,
        G1600x1200x32K = 46,
        G1600x1200x64K = 47,
        G1600x1200x16M = 48,
        G1600x1200x16M32 = 49


include machine.e
include dll.e

procedure assert(integer bool, sequence msg)
    if bool then return end if
    puts(2, msg)
    abort(1)
end procedure

constant SVGALIB = open_dll("libvga.so")
assert(SVGALIB != 0, "could not open libvga.so\n")

constant vga_init = define_c_func(SVGALIB, "vga_init", {}, C_INT)
assert(vga_init != -1, "could not link vga_init\n")

-- It's very important that we do this before anything else because
-- vga_init gives up supervisor rights so we can't do Bad Things
if c_func(vga_init, {}) then
    abort(1)
end if
-- This will also detect the chipset and print something on the screen like:
-- Using xxxx driver, xxxxKB
-- For more information see:
--   man svgalib
--   man vga_init
--   /etc/vga/libvga.config


--
--  graphics_mode
--
constant vga_setmode = define_c_func(SVGALIB, "vga_setmode", {C_INT}, C_INT)
assert(vga_setmode != -1, "could not link vga_setmode\n")

global function graphics_mode(integer mode)
    return c_func(vga_setmode, {mode})
end function


--
--  pixel
--
constant vga_drawscansegment = define_c_proc(SVGALIB, "vga_drawscansegment",
{C_POINTER, C_INT, C_INT, C_INT})
assert(vga_drawscansegment != -1, "could not link vga_drawscansegment\n")

global procedure pixel(object data, sequence pos)
    if sequence(data) then
        pos = allocate(length(data)) & pos & length(data)
    else
        pos = allocate(1) & pos & 1
    end if
    poke(pos[1], data)
    c_proc(vga_drawscansegment, pos)
    free(pos[1])
end procedure


--
-- get_pixel
--
constant vga_getscansegment = define_c_proc(SVGALIB, "vga_getscansegment",
{C_POINTER, C_INT, C_INT, C_INT})
assert(vga_getscansegment != -1, "could not link vga_getscansegment\n")

global function get_pixel(sequence pos)
    object colors
    if length(pos) = 3 then
        pos = allocate(pos[3]) & pos
        c_proc(vga_getscansegment, pos)
        colors = peek({pos[1], pos[4]})
    else
        pos = allocate(1) & pos & 1
        c_proc(vga_getscansegment, pos)
        colors = peek(pos[1])
    end if
    free(pos[1])
    return colors
end function

--
-- draw_line
--
constant vga_drawline = define_c_proc(SVGALIB, "vga_drawline", {C_INT, C_INT,
C_INT, C_INT})
assert(vga_drawline != -1, "could not link vga_drawline\n")
constant vga_setcolor = define_c_proc(SVGALIB, "vga_setcolor", {C_INT})
assert(vga_setcolor != -1, "could not link vga_setcolor\n")

global procedure draw_line(integer color, sequence xyarray)
    integer v
    c_proc(vga_setcolor, {color})
    v = 1
    while v < length(xyarray) do
        c_proc(vga_drawline, xyarray[v] & xyarray[v+1])
        v += 1
    end while
end procedure


--
-- video_config
--
constant vga_getcurrentmode = define_c_func(SVGALIB, "vga_getcurrentmode", {},
C_INT)
constant vga_getxdim = define_c_func(SVGALIB, "vga_getxdim", {}, C_INT)
constant vga_getydim = define_c_func(SVGALIB, "vga_getydim", {}, C_INT)
constant vga_getcolors = define_c_func(SVGALIB, "vga_getcolors", {}, C_INT)
assert(vga_getcurrentmode != -1, "could not link vga_getcurrentmode\n")
assert(vga_getxdim != -1, "could not link vga_getxdim\n")
assert(vga_getydim != -1, "could not link vga_getydim\n")
assert(vga_getcolors != -1, "could not link vga_getcolors\n")

global function video_config()
    return {1,                          -- color
    c_func(vga_getcurrentmode, {}),     -- mode
    0,                                  -- text lines
    0,                                  -- text pages
    c_func(vga_getxdim, {}),            -- xdim
    c_func(vga_getydim, {}),            -- ydim
    c_func(vga_getcolors, {}),          -- #colors
    1}                                  -- pages
end function


------------------------------------------------------------
-- svgatest.exu
--

include svga.e

if graphics_mode(G320x200x256) then
    abort(1)
end if

for y = 0 to 199 do
    for x = 0 to 319 do
        pixel(xor_bits(x,y),{x,y})
    end for
end for

for x = 0 to 319 do
    draw_line(x, {{x,0},{319-x,199}})
end for

constant vc = video_config()

include get.e
if wait_key() then end if
if graphics_mode(TEXT) then end if
puts(1, "video_config: ")
? vc

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

Enjoy,
 _______  ______  _______  ______
[    _  \[    _ ][ _   _ ][    _ ]
[/| [_] |[/| [_\][/ | | \][/| [_\]
  |  ___/  |  _]    | |     |  _]
[\| [/]  [\| [_/] [\| |/] [\| [_/]
[_____]  [______] [_____] [______]
xseal at harborside.com  ICQ:13466657
http://www.harborside.com/home/x/xseal/euphoria/

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu