Skip to content

Commit beda66a

Browse files
committed
Code review clean up
- Split DOS VESA mode-setting into its own file - Replace magic numbers with named constants - Update copyright dates to 2026 - Substract time taken by other threads form delays
1 parent 97b27b3 commit beda66a

26 files changed

Lines changed: 785 additions & 640 deletions

src/audio/dos/SDL_dosaudio_sb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
Simple DirectMedia Layer
3-
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
3+
Copyright (C) 1997-2026 Sam Lantinga <slouken@libsdl.org>
44
55
This software is provided 'as-is', without any express or implied
66
warranty. In no event will the authors be held liable for any damages

src/audio/dos/SDL_dosaudio_sb.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
Simple DirectMedia Layer
3-
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
3+
Copyright (C) 1997-2026 Sam Lantinga <slouken@libsdl.org>
44
55
This software is provided 'as-is', without any express or implied
66
warranty. In no event will the authors be held liable for any damages

src/core/dos/SDL_dos.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
Simple DirectMedia Layer
3-
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
3+
Copyright (C) 1997-2026 Sam Lantinga <slouken@libsdl.org>
44
55
This software is provided 'as-is', without any express or implied
66
warranty. In no event will the authors be held liable for any damages
@@ -102,10 +102,10 @@ void DOS_HookInterrupt(int irq, DOS_InterruptHookFn fn, DOS_InterruptHook *hook)
102102

103103
// enable interrupt on the correct PIC
104104
if (irq > 7) {
105-
outportb(0xA1, inportb(0xA1) & ~(1 << (irq - 8))); // unmask on slave PIC
106-
outportb(0x21, inportb(0x21) & ~(1 << 2)); // ensure cascade (IRQ2) is unmasked
105+
outportb(PIC2_DATA, inportb(PIC2_DATA) & ~(1 << (irq - 8))); // unmask on slave PIC
106+
outportb(PIC1_DATA, inportb(PIC1_DATA) & ~(1 << 2)); // ensure cascade (IRQ2) is unmasked
107107
} else {
108-
outportb(0x21, inportb(0x21) & ~(1 << irq)); // unmask on master PIC
108+
outportb(PIC1_DATA, inportb(PIC1_DATA) & ~(1 << irq)); // unmask on master PIC
109109
}
110110
}
111111

@@ -120,9 +120,9 @@ void DOS_UnhookInterrupt(DOS_InterruptHook *hook, bool disable_interrupt)
120120

121121
if (disable_interrupt) {
122122
if (hook->irq > 7) {
123-
outportb(0xA1, inportb(0xA1) | (1 << (hook->irq - 8))); // mask on slave PIC
123+
outportb(PIC2_DATA, inportb(PIC2_DATA) | (1 << (hook->irq - 8))); // mask on slave PIC
124124
} else {
125-
outportb(0x21, inportb(0x21) | (1 << hook->irq)); // mask on master PIC
125+
outportb(PIC1_DATA, inportb(PIC1_DATA) | (1 << hook->irq)); // mask on master PIC
126126
}
127127
}
128128

src/core/dos/SDL_dos.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
Simple DirectMedia Layer
3-
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
3+
Copyright (C) 1997-2026 Sam Lantinga <slouken@libsdl.org>
44
55
This software is provided 'as-is', without any express or implied
66
warranty. In no event will the authors be held liable for any damages
@@ -40,6 +40,13 @@
4040
// this is DOS PC stuff, like interrupts and Intel i/o ports.
4141
#include <pc.h>
4242

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+
4350
// Lock a range of code so it won't be paged out during interrupts.
4451
// Usage: DOS_LockCode(function_name, function_end_label)
4552
// The function_end_label must be defined immediately after the function.
@@ -107,9 +114,9 @@ SDL_FORCE_INLINE Uint32 DOS_PeekUint32(const Uint32 segoffset)
107114
SDL_FORCE_INLINE void DOS_EndOfInterrupt(int irq)
108115
{
109116
if (irq > 7) {
110-
outportb(0xA0, 0x20); // Send EOI to slave PIC (PIC2) for IRQs 8-15
117+
outportb(PIC2_COMMAND, PIC_EOI);
111118
}
112-
outportb(0x20, 0x20); // Send EOI to master PIC (PIC1) — always needed (cascade)
119+
outportb(PIC1_COMMAND, PIC_EOI);
113120
}
114121

115122
// Allocate memory under the 640k line; various real mode services and DMA transfers need this.

src/core/dos/SDL_dos_scheduler.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
Simple DirectMedia Layer
3-
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
3+
Copyright (C) 1997-2026 Sam Lantinga <slouken@libsdl.org>
44
55
This software is provided 'as-is', without any express or implied
66
warranty. In no event will the authors be held liable for any damages

src/core/dos/SDL_dos_scheduler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
Simple DirectMedia Layer
3-
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
3+
Copyright (C) 1997-2026 Sam Lantinga <slouken@libsdl.org>
44
55
This software is provided 'as-is', without any express or implied
66
warranty. In no event will the authors be held liable for any damages

src/filesystem/dos/SDL_sysfilesystem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
Simple DirectMedia Layer
3-
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
3+
Copyright (C) 1997-2026 Sam Lantinga <slouken@libsdl.org>
44
55
This software is provided 'as-is', without any express or implied
66
warranty. In no event will the authors be held liable for any damages

src/joystick/dos/SDL_sysjoystick.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131

3232
#define GAMEPORT 0x201
3333

34+
/* Gameport status byte button bits (active low) */
35+
#define GAMEPORT_BUTTON1 0x10 /* bit 4 */
36+
#define GAMEPORT_BUTTON2 0x20 /* bit 5 */
37+
#define GAMEPORT_BUTTON3 0x40 /* bit 6 */
38+
#define GAMEPORT_BUTTON4 0x80 /* bit 7 */
39+
3440
/* Static state for detection */
3541
static bool dos_joystick_detected = false;
3642
static SDL_JoystickID dos_joystick_id = 0;
@@ -263,10 +269,10 @@ static void DOS_JoystickUpdate(SDL_Joystick *joystick)
263269

264270
/* Buttons are a passive port read (no timing loop), always safe to poll */
265271
val = inportb(GAMEPORT);
266-
SDL_SendJoystickButton(0, joystick, 0, !(val & 0x10)); /* button 1 */
267-
SDL_SendJoystickButton(0, joystick, 1, !(val & 0x20)); /* button 2 */
268-
SDL_SendJoystickButton(0, joystick, 2, !(val & 0x40)); /* button 3 */
269-
SDL_SendJoystickButton(0, joystick, 3, !(val & 0x80)); /* button 4 */
272+
SDL_SendJoystickButton(0, joystick, 0, !(val & GAMEPORT_BUTTON1));
273+
SDL_SendJoystickButton(0, joystick, 1, !(val & GAMEPORT_BUTTON2));
274+
SDL_SendJoystickButton(0, joystick, 2, !(val & GAMEPORT_BUTTON3));
275+
SDL_SendJoystickButton(0, joystick, 3, !(val & GAMEPORT_BUTTON4));
270276

271277
/* Throttle axis reads — BIOS INT 15h subfunction 1 does an internal
272278
timing loop that is very expensive. ~60 Hz is more than enough for

src/main/dos/SDL_sysmain_runapp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
Simple DirectMedia Layer
3-
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
3+
Copyright (C) 1997-2026 Sam Lantinga <slouken@libsdl.org>
44
55
This software is provided 'as-is', without any express or implied
66
warranty. In no event will the authors be held liable for any damages

src/thread/dos/SDL_sysmutex.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
Simple DirectMedia Layer
3-
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
3+
Copyright (C) 1997-2026 Sam Lantinga <slouken@libsdl.org>
44
55
This software is provided 'as-is', without any express or implied
66
warranty. In no event will the authors be held liable for any damages
@@ -28,17 +28,19 @@
2828
#include "../../core/dos/SDL_dos.h"
2929
#include "../../core/dos/SDL_dos_scheduler.h"
3030

31+
#define MUTEX_NO_OWNER -1
32+
3133
struct SDL_Mutex
3234
{
33-
volatile int owner; /* Thread ID of owner, or -1 if unlocked */
35+
volatile int owner; /* Thread ID of owner, or MUTEX_NO_OWNER if unlocked */
3436
volatile int recursive; /* Recursion count */
3537
};
3638

3739
SDL_Mutex *SDL_CreateMutex(void)
3840
{
3941
SDL_Mutex *mutex = (SDL_Mutex *)SDL_malloc(sizeof(*mutex));
4042
if (mutex) {
41-
mutex->owner = -1;
43+
mutex->owner = MUTEX_NO_OWNER;
4244
mutex->recursive = 0;
4345
}
4446
return mutex;
@@ -61,22 +63,18 @@ void SDL_LockMutex(SDL_Mutex *mutex) SDL_NO_THREAD_SAFETY_ANALYSIS
6163

6264
for (;;) {
6365
DOS_DisableInterrupts();
64-
if (mutex->owner == -1) {
65-
/* Mutex is free — acquire it */
66+
if (mutex->owner == MUTEX_NO_OWNER) {
6667
mutex->owner = tid;
6768
mutex->recursive = 1;
6869
DOS_EnableInterrupts();
6970
return;
7071
}
7172
if (mutex->owner == tid) {
72-
/* We already own it — recursive lock */
7373
mutex->recursive++;
7474
DOS_EnableInterrupts();
7575
return;
7676
}
7777
DOS_EnableInterrupts();
78-
79-
/* Contention — yield and try again */
8078
DOS_Yield();
8179
}
8280
}
@@ -90,7 +88,7 @@ bool SDL_TryLockMutex(SDL_Mutex *mutex)
9088
int tid = DOS_GetCurrentThreadID();
9189

9290
DOS_DisableInterrupts();
93-
if (mutex->owner == -1) {
91+
if (mutex->owner == MUTEX_NO_OWNER) {
9492
mutex->owner = tid;
9593
mutex->recursive = 1;
9694
DOS_EnableInterrupts();
@@ -115,7 +113,7 @@ void SDL_UnlockMutex(SDL_Mutex *mutex) SDL_NO_THREAD_SAFETY_ANALYSIS
115113
if (mutex->recursive > 1) {
116114
mutex->recursive--;
117115
} else {
118-
mutex->owner = -1;
116+
mutex->owner = MUTEX_NO_OWNER;
119117
mutex->recursive = 0;
120118
}
121119
DOS_EnableInterrupts();

0 commit comments

Comments
 (0)