source: sbliveos2/trunk/drv32/init.c@ 144

Last change on this file since 144 was 142, checked in by ktk, 25 years ago

Import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.8 KB
Line 
1/* $Id: init.c 142 2000-04-23 14:55:46Z ktk $ */
2
3//******************************************************************************
4// Init strategy handler
5//
6// Copyright 2000 Sander van Leeuwen (sandervl@xs4all.nl)
7//
8// This program is free software; you can redistribute it and/or
9// modify it under the terms of the GNU General Public License as
10// published by the Free Software Foundation; either version 2 of
11// the License, or (at your option) any later version.
12//
13// This program is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU General Public License for more details.
17//
18// You should have received a copy of the GNU General Public
19// License along with this program; if not, write to the Free
20// Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
21// USA.
22//
23//******************************************************************************
24extern "C" { // 16-bit header files are not C++ aware
25#define INCL_NOPMAPI
26#define INCL_DOSMISC
27#include <os2.h>
28}
29
30// Device support
31#include <devhelp.h>
32#include <devtype.h>
33#include <devrp.h>
34#include "devown.h"
35#include <sbversion.h>
36#include <dbgos2.h>
37#ifdef KEE
38#include <kee.h>
39#endif
40
41const char ERR_ERROR[] = "ERROR: ";
42const char ERR_LOCK[] = "\r\nUnable to lock 32 bit data & code segments, exiting...\r\r\n";
43#ifdef KEE
44const char szSBLive[] = "\r\n\r\nSoundBlaster Live! Audio Driver v"SBLIVE_VERSION" (32 Bits KEE)\r\n";
45#else
46const char szSBLive[] = "\r\n\r\nSoundBlaster Live! Audio Driver v"SBLIVE_VERSION" (32 Bits)\r\n";
47#endif
48const char szCopyRight1[]= "Copyright 1999, 2000 Creative Labs, Inc.\r\n";
49const char szCopyRight2[]= "Copyright 2000 Sander van Leeuwen (OS/2 Port)\r\n\r\n";
50
51typedef struct {
52 USHORT MsgLength;
53 WORD32 MsgPtr;
54} MSG_TABLE;
55
56extern "C" WORD32 MSG_TABLE32;
57
58//Print messages with DosWrite when init is done or has failed (see startup.asm)
59void DevSaveMessage(char __far *str, int length)
60{
61 MSG_TABLE __far *msg = (MSG_TABLE __far *)__Make48Pointer(MSG_TABLE32);
62 char __far *str16 = (char __far *)__Make48Pointer(msg->MsgPtr);
63 int i;
64
65 for(i=0;i<length;i++) {
66 str16[msg->MsgLength + i] = str[i];
67 }
68 str16[msg->MsgLength + length] = 0;
69 msg->MsgLength += length;
70
71 return;
72}
73
74//SvL: Lock our 32 bits data & code segments
75int LockSegments(void)
76{
77#ifdef KEE
78 KEEVMLock lock;
79#else
80 char lock[12];
81 ULONG PgCount;
82#endif
83 ULONG segsize;
84
85 /*
86 * Locks DGROUP into physical memory
87 */
88 //NOTE: VMLock rounds base address down to nearest page
89 // So we MUST take this into account when calculating the
90 // size of our code/data
91 segsize = OffsetFinalDS32 - ((OffsetBeginDS32) & ~0xFFF);
92 if(segsize & 0xFFF) {
93 segsize += PAGE_SIZE;
94 }
95 segsize &= ~0xFFF;
96#ifdef KEE
97 if(KernVMLock(VMDHL_LONG,
98 (PVOID)((OffsetBeginDS32) & ~0xFFF),
99 segsize,
100 &lock,
101 (KEEVMPageList*)-1,
102 0)) {
103#else
104 if(DevVMLock(VMDHL_LONG,
105 ((OffsetBeginDS32) & ~0xFFF),
106 segsize,
107 (LINEAR)-1,
108 __StackToFlat((ULONG)lock),
109 (LINEAR)__StackToFlat((ULONG)&PgCount))) {
110#endif
111 return(1);
112 }
113 /*
114 * Locks CODE32 into physical memory
115 */
116 segsize = OffsetFinalCS32 - ((OffsetBeginCS32) & ~0xFFF);
117 if(segsize & 0xFFF) {
118 segsize += PAGE_SIZE;
119 }
120 segsize &= ~0xFFF;
121#ifdef KEE
122 if(KernVMLock(VMDHL_LONG,
123 (PVOID)((OffsetBeginCS32) & ~0xFFF),
124 segsize,
125 &lock,
126 (KEEVMPageList*)-1,
127 0)) {
128#else
129 if(DevVMLock(VMDHL_LONG,
130 ((OffsetBeginCS32) & ~0xFFF),
131 segsize,
132 (LINEAR)-1,
133 __StackToFlat((ULONG)lock),
134 (LINEAR)__StackToFlat((ULONG)&PgCount))) {
135#endif
136 return(1);
137 }
138 return 0;
139}
140
141
142// Write a string of specified length
143static VOID WriteString(const char __far* str, int length)
144{
145 // Write the string
146 DevSaveMessage((char __far *)str, length);
147 return;
148}
149
150// Initialize device driver
151
152WORD32 DiscardableInit(RPInit __far* rp)
153{
154 GetTKSSBase();
155 if(LockSegments()) {
156 WriteString(ERR_ERROR, sizeof(ERR_ERROR)-1);
157 WriteString(ERR_LOCK, sizeof(ERR_LOCK)-1);
158 return RPDONE | RPERR;
159 }
160
161 rp->Out.FinalCS = 0;
162 rp->Out.FinalDS = 0;
163
164 //Do you init here:
165
166 WriteString(szSBLive, sizeof(szSBLive)-1);
167 WriteString(szCopyRight1, sizeof(szCopyRight1)-1);
168 WriteString(szCopyRight2, sizeof(szCopyRight2)-1);
169
170 // Complete the installation
171 rp->Out.FinalCS = _OffsetFinalCS16;
172 rp->Out.FinalDS = _OffsetFinalDS16;
173
174 // Confirm a successful installation
175 return RPDONE;
176}
177
178
179
180
Note: See TracBrowser for help on using the repository browser.