Atlas - SDL_dos.h

Home / ext / SDL / src / core / dos Lines: 3 | Size: 5358 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2026 Sam Lantinga <[email protected]> 4 5 This software is provided 'as-is', without any express or implied 6 warranty. In no event will the authors be held liable for any damages 7 arising from the use of this software. 8 9 Permission is granted to anyone to use this software for any purpose, 10 including commercial applications, and to alter it and redistribute it 11 freely, subject to the following restrictions: 12 13 1. The origin of this software must not be misrepresented; you must not 14 claim that you wrote the original software. If you use this software 15 in a product, an acknowledgment in the product documentation would be 16 appreciated but is not required. 17 2. Altered source versions must be plainly marked as such, and must not be 18 misrepresented as being the original software. 19 3. This notice may not be removed or altered from any source distribution. 20*/ 21 22#include "SDL_internal.h" 23 24#ifndef SDL_dos_h_ 25#define SDL_dos_h_ 26 27#include <sys/farptr.h> 28 29// our MS-DOS port depends on the "fat DS" trick. djgpp docs try to warn you 30// away from this, but if it was good enough for Quake 1, it's good enough 31// for us! 32#include <sys/nearptr.h> 33 34// We are obviously a 32-bit protected mode (DPMI) program. 35#include <dpmi.h> 36 37// this is djgpp-specific. 38#include <go32.h> 39 40// this is DOS PC stuff, like interrupts and Intel i/o ports. 41#include <pc.h> 42 43// 8259 PIC (Programmable Interrupt Controller) ports and commands 44#define PIC1_COMMAND 0x20 // master PIC command port 45#define PIC1_DATA 0x21 // master PIC data (mask) port 46#define PIC2_COMMAND 0xA0 // slave PIC command port 47#define PIC2_DATA 0xA1 // slave PIC data (mask) port 48#define PIC_EOI 0x20 // end-of-interrupt command 49 50// Lock a range of code so it won't be paged out during interrupts. 51// Usage: DOS_LockCode(function_name, function_end_label) 52// The function_end_label must be defined immediately after the function. 53#define DOS_LockCode(start, end) \ 54 _go32_dpmi_lock_code((void *)(start), (char *)(end) - (char *)(start)) 55 56// Lock a range of data so it won't be paged out during interrupts. 57#define DOS_LockData(var, size) \ 58 _go32_dpmi_lock_data((void *)&(var), (size)) 59 60// Lock a single variable. 61#define DOS_LockVariable(var) \ 62 DOS_LockData(var, sizeof(var)) 63 64// Set up for C function definitions, even when using C++ 65#ifdef __cplusplus 66extern "C" { 67#endif 68 69// This uses the "fat DS" trick to convert a physical address to a valid 70// C pointer usable from protected mode. 71SDL_FORCE_INLINE void *DOS_PhysicalToLinear(const Uint32 physical) 72{ 73 __djgpp_nearptr_enable(); // We need to re-enable this for large applications to work. 74 return (void *)(physical + __djgpp_conventional_base); 75} 76 77SDL_FORCE_INLINE Uint32 DOS_LinearToPhysical(void *linear) 78{ 79 return ((Uint32)linear) - __djgpp_conventional_base; 80} 81 82SDL_FORCE_INLINE int DOS_IRQToVector(int irq) 83{ 84 return irq + ((irq > 7) ? 104 : 8); 85} 86 87SDL_FORCE_INLINE void DOS_DisableInterrupts(void) 88{ 89 __asm__ __volatile__("cli\n"); 90} 91 92SDL_FORCE_INLINE void DOS_EnableInterrupts(void) 93{ 94 __asm__ __volatile__("sti\n"); 95} 96 97// Grab a single byte from a segment:offset. 98SDL_FORCE_INLINE Uint8 DOS_PeekUint8(const Uint32 segoffset) 99{ 100 return (Uint8)_farpeekb(_dos_ds, ((segoffset & 0xFFFF0000) >> 12) + (segoffset & 0xFFFF)); 101} 102 103// Grab a single 16-bit word from a segment:offset. 104SDL_FORCE_INLINE Uint16 DOS_PeekUint16(const Uint32 segoffset) 105{ 106 return (Uint16)_farpeekw(_dos_ds, ((segoffset & 0xFFFF0000) >> 12) + (segoffset & 0xFFFF)); 107} 108 109// Grab a single 32-bit dword from a segment:offset. 110SDL_FORCE_INLINE Uint32 DOS_PeekUint32(const Uint32 segoffset) 111{ 112 return (Uint32)_farpeekl(_dos_ds, ((segoffset & 0xFFFF0000) >> 12) + (segoffset & 0xFFFF)); 113} 114 115SDL_FORCE_INLINE void DOS_EndOfInterrupt(int irq) 116{ 117 if (irq > 7) { 118 outportb(PIC2_COMMAND, PIC_EOI); 119 } 120 outportb(PIC1_COMMAND, PIC_EOI); 121} 122 123// Allocate memory under the 640k line; various real mode services and DMA transfers need this. 124// malloc() returns data above 640k because we're a protected mode, 32-bit process, so this is 125// only for specific needs. 126extern void *DOS_AllocateConventionalMemory(const int len, _go32_dpmi_seginfo *seginfo); 127 128// Allocate conventional memory suitable for DMA transfers. 129extern void *DOS_AllocateDMAMemory(const int len, _go32_dpmi_seginfo *seginfo); 130 131// Free conventional (or DMA, which _is_ conventional) memory. 132extern void DOS_FreeConventionalMemory(_go32_dpmi_seginfo *seginfo); 133 134// Get a SDL_malloc'd copy of a null-terminated string located at a real-mode segment:offset. This makes no promises about character encoding. 135char *DOS_GetFarPtrCString(const Uint32 segoffset); 136 137typedef void (*DOS_InterruptHookFn)(void); 138typedef struct DOS_InterruptHook 139{ 140 DOS_InterruptHookFn fn; 141 int irq; 142 int interrupt_vector; // this is the _vector_ number, not the IRQ number! 143 _go32_dpmi_seginfo irq_handler_seginfo; 144 _go32_dpmi_seginfo original_irq_handler_seginfo; 145 146} DOS_InterruptHook; 147 148void DOS_HookInterrupt(int irq, DOS_InterruptHookFn fn, DOS_InterruptHook *hook); // `irq` is the IRQ number, not the interrupt vector number! 149void DOS_UnhookInterrupt(DOS_InterruptHook *hook, bool disable_interrupt); 150 151// Ends C function definitions when using C++ 152#ifdef __cplusplus 153} 154#endif 155 156#endif // SDL_dos_h_ 157
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.