1 /*         ______   ___    ___
2  *        /\  _  \ /\_ \  /\_ \
3  *        \ \ \L\ \\//\ \ \//\ \      __     __   _ __   ___
4  *         \ \  __ \ \ \ \  \ \ \   /'__`\ /'_ `\/\`'__\/ __`\
5  *          \ \ \/\ \ \_\ \_ \_\ \_/\  __//\ \L\ \ \ \//\ \L\ \
6  *           \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/
7  *            \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/
8  *                                           /\____/
9  *                                           \_/__/
10  *
11  *      Helpers for accessing the VGA hardware registers.
12  *
13  *      By Shawn Hargreaves.
14  *
15  *      See readme.txt for copyright information.
16  */
17 
18 
19 #include "allegro.h"
20 
21 #ifdef ALLEGRO_GFX_HAS_VGA
22 
23 #include "allegro/internal/aintern.h"
24 #include "allegro/internal/aintvga.h"
25 
26 
27 
28 int _crtc = 0x3D4;
29 
30 
31 
32 /* _vga_regs_init:
33  *  Initialiases the VGA register access functions.
34  */
_vga_regs_init(void)35 void _vga_regs_init(void)
36 {
37    LOCK_VARIABLE(_crtc);
38 
39    if (inportb(0x3CC) & 1)
40       _crtc = 0x3D4;
41    else
42       _crtc = 0x3B4;
43 }
44 
45 
46 
47 /* _vga_vsync:
48  *  Waits for the start of a vertical retrace.
49  */
_vga_vsync(void)50 void _vga_vsync(void)
51 {
52    _vsync_out_v();
53    _vsync_in();
54 }
55 
56 
57 
58 /* _set_vga_virtual_width:
59  *  Used by various graphics drivers to adjust the virtual width of
60  *  the screen, using VGA register 0x3D4 index 0x13.
61  */
_set_vga_virtual_width(int old_width,int new_width)62 void _set_vga_virtual_width(int old_width, int new_width)
63 {
64    int width;
65 
66    if (old_width != new_width) {
67       width = _read_vga_register(_crtc, 0x13);
68       _write_vga_register(_crtc, 0x13, (width * new_width) / old_width);
69    }
70 }
71 
72 
73 
74 /* _vga_set_palette_range:
75  *  Sets part of the VGA palette.
76  */
_vga_set_palette_range(AL_CONST PALETTE p,int from,int to,int vsync)77 void _vga_set_palette_range(AL_CONST PALETTE p, int from, int to, int vsync)
78 {
79    int i;
80 
81    if (vsync)
82       _vga_vsync();
83 
84    outportb(0x3C8, from);
85 
86    for (i=from; i<=to; i++) {
87       outportb(0x3C9, p[i].r);
88       outportb(0x3C9, p[i].g);
89       outportb(0x3C9, p[i].b);
90    }
91 }
92 
93 
94 #endif /* ALLEGRO_GFX_HAS_VGA */
95