Wing Commander II
Reconstructed Win32 source (1996)
Toggle main menu visibility
Loading...
Searching...
No Matches
vpalloc.c
Go to the documentation of this file.
1
/*
2
* Viewport buffer allocation.
3
*
4
* Retail object 0x45CA50-0x45CCAF (link order; see docs/ORDER.md). The
5
* DOS release's vpalloc module holds the size and allocation routines;
6
* the Win32 port puts its display-mode diagnostic in front of them.
7
*/
8
#include "
game.h
"
9
10
/* Function start: 0x45CA50 */
11
void
LogDisplayMode
(
const
char
*mode)
12
{
13
SystemDebugPrintf
(
"display_mode == '%s'\n"
, mode);
14
ClearDebugPauseFlags
();
15
PumpMessagesDuringWait
();
16
exit(1);
17
}
18
19
short
AllocateViewport
(
Viewport
*viewport,
short
clearColour,
short
flags);
20
void
ClearViewport
(
Viewport
*viewport,
short
colour);
21
22
/* Function start: 0x45CA80 */
23
short
CalcRectangleArea
(
const
Viewport
*viewport)
24
{
25
if
(
g_nSpacePaletteFadeMode
!= 0x13)
26
LogDisplayMode
(
"not MCGA"
);
27
return
(
short
)((viewport->
bottom
- viewport->
top
+ 1) *
28
(viewport->
right
- viewport->
left
+ 1));
29
}
30
31
/* Function start: 0x45CAD2 */
32
short
AllocateViewport
(
Viewport
*viewport,
33
short
clearColour,
short
flags)
34
{
35
unsigned
short
y;
36
unsigned
short
height;
37
unsigned
short
pixelOffset;
38
unsigned
char
*buffer;
39
unsigned
short
firstRow;
40
unsigned
short
width;
41
unsigned
short
left;
42
43
height = viewport->
bottom
- viewport->
top
+ 1;
44
width = viewport->
right
- viewport->
left
+ 1;
45
left = viewport->
left
;
46
firstRow = viewport->
top
;
47
g_nAllocateViewportCalls
++;
48
if
(
g_nSpacePaletteFadeMode
!= 0x13)
49
LogDisplayMode
(
"not MCGA"
);
50
viewport->
allocation
=
AllocateTaggedMemory
(
51
width * height, (
unsigned
short
)(flags + 2));
52
g_apViewportAllocations
[
53
g_nViewportAllocationCount
++] = viewport->
allocation
;
54
buffer = viewport->
allocation
;
55
if
(buffer == 0)
56
return
0;
57
viewport->
pixels
= buffer;
58
pixelOffset = 0;
59
60
viewport->
rowOffsets
=
AllocateTaggedMemory
(
61
(firstRow + height + 2) * 2, 0);
62
if
(viewport->
rowOffsets
== 0) {
63
if
(
g_nSpacePaletteFadeMode
!= 0x13)
64
ReleasePacketHandle
(viewport->
allocation
);
65
return
0;
66
}
67
68
for
(y = 0; y < height + 2; y++) {
69
(&viewport->
rowOffsets
[firstRow])[y] = pixelOffset - left;
70
pixelOffset += width;
71
}
72
if
(clearColour != -1)
73
ClearViewport
(viewport, clearColour);
74
return
1;
75
}
76
77
/* Linker commons defined here. LINK lays a unit's commons out by the
78
* identifiers' hash keys, so these spellings follow the original addresses. */
79
int
g_nAllocateViewportCalls
;
/* 0x005c8dc4 */
PumpMessagesDuringWait
char PumpMessagesDuringWait(void)
Definition
console.cpp:46
AllocateViewport
short AllocateViewport(Viewport *viewport, short clearColour, short flags)
Definition
vpalloc.c:32
AllocateTaggedMemory
void * AllocateTaggedMemory(unsigned int size, short flags)
Definition
memapi.c:92
ClearDebugPauseFlags
void ClearDebugPauseFlags(void)
Definition
console.cpp:82
ClearViewport
void ClearViewport(Viewport *viewport, short colour)
Definition
gr.c:1027
ReleasePacketHandle
void ReleasePacketHandle(void *handle)
Definition
memapi.c:108
LogDisplayMode
void LogDisplayMode(const char *mode)
Definition
vpalloc.c:11
SystemDebugPrintf
void SystemDebugPrintf(const char *format,...)
Definition
console.cpp:30
CalcRectangleArea
short CalcRectangleArea(const Viewport *viewport)
Definition
vpalloc.c:23
game.h
Shared Win32 declarations, types and library interfaces.
g_nAllocateViewportCalls
int g_nAllocateViewportCalls
Definition
vpalloc.c:79
g_apViewportAllocations
unsigned char * g_apViewportAllocations[128]
Definition
vpfree.c:52
g_nSpacePaletteFadeMode
short g_nSpacePaletteFadeMode
Definition
palalloc.c:8
g_nViewportAllocationCount
int g_nViewportAllocationCount
Definition
vpfree.c:51
Viewport
Definition
game.h:149
Viewport::pixels
unsigned char * pixels
Definition
game.h:150
Viewport::right
short right
Definition
game.h:154
Viewport::bottom
short bottom
Definition
game.h:155
Viewport::allocation
unsigned char * allocation
Definition
game.h:156
Viewport::rowOffsets
unsigned short * rowOffsets
Definition
game.h:151
Viewport::left
short left
Definition
game.h:152
Viewport::top
short top
Definition
game.h:153
src
vpalloc.c
Generated by
1.18.0