1 /*         ______   ___    ___
2  *        /\  _  \ /\_ \  /\_ \
3  *        \ \ \L\ \\//\ \ \//\ \      __     __   _ __   ___
4  *         \ \  __ \ \ \ \  \ \ \   /'__`\ /'_ `\/\`'__\/ __`\
5  *          \ \ \/\ \ \_\ \_ \_\ \_/\  __//\ \L\ \ \ \//\ \L\ \
6  *           \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/
7  *            \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/
8  *                                           /\____/
9  *                                           \_/__/
10  *
11  *      Some definitions for internal use by the DOS library code.
12  *
13  *      By Shawn Hargreaves.
14  *
15  *      See readme.txt for copyright information.
16  */
17 
18 
19 #ifndef AINTDOS_H
20 #define AINTDOS_H
21 
22 #ifndef ALLEGRO_H
23    #error must include allegro.h first
24 #endif
25 
26 #ifndef ALLEGRO_DOS
27    #error bad include
28 #endif
29 
30 #ifdef __cplusplus
31    extern "C" {
32 #endif
33 
34 
35 /* macros to enable and disable interrupts */
36 #if defined ALLEGRO_GCC
37 
38    #define DISABLE()    asm volatile ("cli")
39    #define ENABLE()     asm volatile ("sti")
40 
41 #elif defined ALLEGRO_WATCOM
42 
43    void DISABLE(void);
44    void ENABLE(void);
45 
46    #pragma aux DISABLE  = "cli";
47    #pragma aux ENABLE   = "sti";
48 
49 #else
50 
51    #define DISABLE()    asm { cli }
52    #define ENABLE()     asm { sti }
53 
54 #endif
55 
56 
57 AL_INLINE(void, _enter_critical, (void),
58 {
59    /* check if windows is running */
60    if ((os_type == OSTYPE_WIN3)  || (os_type == OSTYPE_WIN95) ||
61        (os_type == OSTYPE_WIN98) || (os_type == OSTYPE_WINME) ||
62        (os_type == OSTYPE_WINNT) || (os_type == OSTYPE_WIN2000)) {
63       __dpmi_regs r;
64       r.x.ax = 0x1681;
65       __dpmi_int(0x2F, &r);
66    }
67 
68    DISABLE();
69 })
70 
71 
72 AL_INLINE(void, _exit_critical, (void),
73 {
74    /* check if windows is running */
75    if ((os_type == OSTYPE_WIN3)  || (os_type == OSTYPE_WIN95) ||
76        (os_type == OSTYPE_WIN98) || (os_type == OSTYPE_WINME) ||
77        (os_type == OSTYPE_WINNT) || (os_type == OSTYPE_WIN2000)) {
78       __dpmi_regs r;
79       r.x.ax = 0x1682;
80       __dpmi_int(0x2F, &r);
81    }
82 
83    ENABLE();
84 })
85 
86 
87 /* interrupt hander stuff */
88 AL_FUNC(void, _dos_irq_init, (void));
89 AL_FUNC(void, _dos_irq_exit, (void));
90 
91 #define _map_irq(irq)   (((irq)>7) ? ((irq)+104) : ((irq)+8))
92 
93 AL_FUNC(int, _install_irq, (int num, AL_METHOD(int, handler, (void))));
94 AL_FUNC(void, _remove_irq, (int num));
95 AL_FUNC(void, _restore_irq, (int irq));
96 AL_FUNC(void, _enable_irq, (int irq));
97 AL_FUNC(void, _disable_irq, (int irq));
98 
99 #define _eoi(irq) { outportb(0x20, 0x20); if ((irq)>7) outportb(0xA0, 0x20); }
100 
101 typedef struct _IRQ_HANDLER
102 {
103    AL_METHOD(int, handler, (void));    /* our C handler */
104    int number;                         /* irq number */
105 
106    #ifdef ALLEGRO_DJGPP
107       __dpmi_paddr old_vector;         /* original protected mode vector */
108    #else
109       void (__interrupt __far *old_vector)();
110    #endif
111 } _IRQ_HANDLER;
112 
113 
114 /* sound lib stuff */
115 AL_VAR(int, _fm_port);
116 AL_VAR(int, _mpu_port);
117 AL_VAR(int, _mpu_irq);
118 
119 
120 /* DPMI memory mapping routines */
121 AL_FUNC(int, _create_physical_mapping, (unsigned long *linear, int *segment, unsigned long physaddr, int size));
122 AL_FUNC(void, _remove_physical_mapping, (unsigned long *linear, int *segment));
123 AL_FUNC(int, _create_linear_mapping, (unsigned long *linear, unsigned long physaddr, int size));
124 AL_FUNC(void, _remove_linear_mapping, (unsigned long *linear));
125 AL_FUNC(int, _create_selector, (int *segment, unsigned long linear, int size));
126 AL_FUNC(void, _remove_selector, (int *segment));
127 AL_FUNC(void, _unlock_dpmi_data, (void *addr, int size));
128 
129 
130 /* bank switching routines (these use a non-C calling convention on i386!) */
131 AL_FUNC(void, _vesa_window_1, (void));
132 AL_FUNC(void, _vesa_window_1_end, (void));
133 
134 AL_FUNC(void, _vesa_window_2, (void));
135 AL_FUNC(void, _vesa_window_2_end, (void));
136 
137 AL_FUNC(void, _vesa_pm_window_1, (void));
138 AL_FUNC(void, _vesa_pm_window_1_end, (void));
139 
140 AL_FUNC(void, _vesa_pm_window_2, (void));
141 AL_FUNC(void, _vesa_pm_window_2_end, (void));
142 
143 AL_FUNC(void, _vesa_pm_es_window_1, (void));
144 AL_FUNC(void, _vesa_pm_es_window_1_end, (void));
145 
146 AL_FUNC(void, _vesa_pm_es_window_2, (void));
147 AL_FUNC(void, _vesa_pm_es_window_2_end, (void));
148 
149 
150 /* stuff for the VESA driver */
151 AL_VAR(__dpmi_regs, _dpmi_reg);
152 
153 AL_VAR(int, _window_2_offset);
154 
155 AL_VAR(int, _mmio_segment);
156 
157 AL_FUNCPTR(void, _pm_vesa_switcher, (void));
158 AL_FUNCPTR(void, _pm_vesa_scroller, (void));
159 AL_FUNCPTR(void, _pm_vesa_palette, (void));
160 
161 
162 AL_FUNC(int, _sb_read_dsp_version, (void));
163 AL_FUNC(int, _sb_reset_dsp, (int data));
164 AL_FUNC(void, _sb_voice, (int state));
165 AL_FUNC(int, _sb_set_mixer, (int digi_volume, int midi_volume));
166 
167 AL_FUNC(void, _mpu_poll, (void));
168 
169 AL_FUNC(int, _dma_allocate_mem, (int bytes, int *sel, unsigned long *phys));
170 AL_FUNC(void, _dma_start, (int channel, unsigned long addr, int size, int auto_init, int input));
171 AL_FUNC(void, _dma_stop, (int channel));
172 AL_FUNC(unsigned long, _dma_todo, (int channel));
173 AL_FUNC(void, _dma_lock_mem, (void));
174 
175 
176 
177 #ifdef __cplusplus
178    }
179 #endif
180 
181 /* VGA register access helpers */
182 #include "allegro/internal/aintvga.h"
183 
184 #endif          /* ifndef AINTDOS_H */
185