Debian Codegraph @

src/dos/dos_misc.cpp

raw
1 /*
2 * Copyright (C) 2002-2010 The DOSBox Team
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19 /* $Id: dos_misc.cpp,v 1.24 2009-09-25 20:51:21 qbix79 Exp $ */
20
21 #include "dosbox.h"
22 #include "callback.h"
23 #include "mem.h"
24 #include "regs.h"
25 #include "dos_inc.h"
26 #include <list>
27
28
29 static Bitu call_int2f,call_int2a;
30
31 static std::list<MultiplexHandler*> Multiplex;
32 typedef std::list<MultiplexHandler*>::iterator Multiplex_it;
33
34 void DOS_AddMultiplexHandler(MultiplexHandler * handler) {
35 Multiplex.push_front(handler);
36 }
37
38 void DOS_DelMultiplexHandler(MultiplexHandler * handler) {
39 for(Multiplex_it it =Multiplex.begin();it != Multiplex.end();it++) {
40 if(*it == handler) {
41 Multiplex.erase(it);
42 return;
43 }
44 }
45 }
46
47 static Bitu INT2F_Handler(void) {
48 for(Multiplex_it it = Multiplex.begin();it != Multiplex.end();it++)
49 if( (*it)() ) return CBRET_NONE;
50
51 LOG(LOG_DOSMISC,LOG_ERROR)("DOS:Multiplex Unhandled call %4X",reg_ax);
52 return CBRET_NONE;
53 }
54
55
56 static Bitu INT2A_Handler(void) {
57 return CBRET_NONE;
58 }
59
60 static bool DOS_MultiplexFunctions(void) {
61 switch (reg_ax) {
62 case 0x1216: /* GET ADDRESS OF SYSTEM FILE TABLE ENTRY */
63 // reg_bx is a system file table entry, should coincide with
64 // the file handle so just use that
65 LOG(LOG_DOSMISC,LOG_ERROR)("Some BAD filetable call used bx=%X",reg_bx);
66 if(reg_bx <= DOS_FILES) CALLBACK_SCF(false);
67 else CALLBACK_SCF(true);
68 if (reg_bx<16) {
69 RealPt sftrealpt=mem_readd(Real2Phys(dos_infoblock.GetPointer())+4);
70 PhysPt sftptr=Real2Phys(sftrealpt);
71 Bitu sftofs=0x06+reg_bx*0x3b;
72
73 if (Files[reg_bx]) mem_writeb(sftptr+sftofs,Files[reg_bx]->refCtr);
74 else mem_writeb(sftptr+sftofs,0);
75
76 if (!Files[reg_bx]) return true;
77
78 Bit32u handle=RealHandle(reg_bx);
79 if (handle>=DOS_FILES) {
80 mem_writew(sftptr+sftofs+0x02,0x02); // file open mode
81 mem_writeb(sftptr+sftofs+0x04,0x00); // file attribute
82 mem_writew(sftptr+sftofs+0x05,Files[reg_bx]->GetInformation()); // device info word
83 mem_writed(sftptr+sftofs+0x07,0); // device driver header
84 mem_writew(sftptr+sftofs+0x0d,0); // packed time
85 mem_writew(sftptr+sftofs+0x0f,0); // packed date
86 mem_writew(sftptr+sftofs+0x11,0); // size
87 mem_writew(sftptr+sftofs+0x15,0); // current position
88 } else {
89 Bit8u drive=Files[reg_bx]->GetDrive();
90
91 mem_writew(sftptr+sftofs+0x02,(Bit16u)(Files[reg_bx]->flags&3)); // file open mode
92 mem_writeb(sftptr+sftofs+0x04,(Bit8u)(Files[reg_bx]->attr)); // file attribute
93 mem_writew(sftptr+sftofs+0x05,0x40|drive); // device info word
94 mem_writed(sftptr+sftofs+0x07,RealMake(dos.tables.dpb,drive)); // dpb of the drive
95 mem_writew(sftptr+sftofs+0x0d,Files[reg_bx]->time); // packed file time
96 mem_writew(sftptr+sftofs+0x0f,Files[reg_bx]->date); // packed file date
97 Bit32u curpos=0;
98 Files[reg_bx]->Seek(&curpos,DOS_SEEK_CUR);
99 Bit32u endpos=0;
100 Files[reg_bx]->Seek(&endpos,DOS_SEEK_END);
101 mem_writed(sftptr+sftofs+0x11,endpos); // size
102 mem_writed(sftptr+sftofs+0x15,curpos); // current position
103 Files[reg_bx]->Seek(&curpos,DOS_SEEK_SET);
104 }
105
106 // fill in filename in fcb style
107 // (space-padded name (8 chars)+space-padded extension (3 chars))
108 const char* filename=(const char*)Files[reg_bx]->GetName();
109 if (strrchr(filename,'\\')) filename=strrchr(filename,'\\')+1;
110 if (strrchr(filename,'/')) filename=strrchr(filename,'/')+1;
111 if (!filename) return true;
112 const char* dotpos=strrchr(filename,'.');
113 if (dotpos) {
114 dotpos++;
115 size_t nlen=strlen(filename);
116 size_t extlen=strlen(dotpos);
117 Bits nmelen=(Bits)nlen-(Bits)extlen;
118 if (nmelen<1) return true;
119 nlen-=(extlen+1);
120
121 if (nlen>8) nlen=8;
122 size_t i;
123
124 for (i=0; i<nlen; i++)
125 mem_writeb((PhysPt)(sftptr+sftofs+0x20+i),filename[i]);
126 for (i=nlen; i<8; i++)
127 mem_writeb((PhysPt)(sftptr+sftofs+0x20+i),' ');
128
129 if (extlen>3) extlen=3;
130 for (i=0; i<extlen; i++)
131 mem_writeb((PhysPt)(sftptr+sftofs+0x28+i),dotpos[i]);
132 for (i=extlen; i<3; i++)
133 mem_writeb((PhysPt)(sftptr+sftofs+0x28+i),' ');
134 } else {
135 size_t i;
136 size_t nlen=strlen(filename);
137 if (nlen>8) nlen=8;
138 for (i=0; i<nlen; i++)
139 mem_writeb((PhysPt)(sftptr+sftofs+0x20+i),filename[i]);
140 for (i=nlen; i<11; i++)
141 mem_writeb((PhysPt)(sftptr+sftofs+0x20+i),' ');
142 }
143
144 SegSet16(es,RealSeg(sftrealpt));
145 reg_di=RealOff(sftrealpt+sftofs);
146 reg_ax=0xc000;
147
148 }
149 return true;
150 case 0x1607:
151 if (reg_bx == 0x15) {
152 switch (reg_cx) {
153 case 0x0000: // query instance
154 reg_cx = 0x0001;
155 reg_dx = 0x50; // dos driver segment
156 SegSet16(es,0x50); // patch table seg
157 reg_bx = 0x60; // patch table ofs
158 return true;
159 case 0x0001: // set patches
160 reg_ax = 0xb97c;
161 reg_bx = (reg_dx & 0x16);
162 reg_dx = 0xa2ab;
163 return true;
164 case 0x0003: // get size of data struc
165 if (reg_dx==0x0001) {
166 // CDS size requested
167 reg_ax = 0xb97c;
168 reg_dx = 0xa2ab;
169 reg_cx = 0x000e; // size
170 }
171 return true;
172 case 0x0004: // instanced data
173 reg_dx = 0; // none
174 return true;
175 case 0x0005: // get device driver size
176 reg_ax = 0;
177 reg_dx = 0;
178 return true;
179 default:
180 return false;
181 }
182 }
183 else if (reg_bx == 0x18) return true; // idle callout
184 else return false;
185 case 0x1680: /* RELEASE CURRENT VIRTUAL MACHINE TIME-SLICE */
186 //TODO Maybe do some idling but could screw up other systems :)
187 return true; //So no warning in the debugger anymore
188 case 0x1689: /* Kernel IDLE CALL */
189 case 0x168f: /* Close awareness crap */
190 /* Removing warning */
191 return true;
192 case 0x4a01: /* Query free hma space */
193 case 0x4a02: /* ALLOCATE HMA SPACE */
194 LOG(LOG_DOSMISC,LOG_WARN)("INT 2f:4a HMA. DOSBox reports none available.");
195 reg_bx=0; //number of bytes available in HMA or amount successfully allocated
196 //ESDI=ffff:ffff Location of HMA/Allocated memory
197 SegSet16(es,0xffff);
198 reg_di=0xffff;
199 return true;
200 }
201
202 return false;
203 }
204
205 void DOS_SetupMisc(void) {
206 /* Setup the dos multiplex interrupt */
207 call_int2f=CALLBACK_Allocate();
208 CALLBACK_Setup(call_int2f,&INT2F_Handler,CB_IRET,"DOS Int 2f");
209 RealSetVec(0x2f,CALLBACK_RealPointer(call_int2f));
210 DOS_AddMultiplexHandler(DOS_MultiplexFunctions);
211 /* Setup the dos network interrupt */
212 call_int2a=CALLBACK_Allocate();
213 CALLBACK_Setup(call_int2a,&INT2A_Handler,CB_IRET,"DOS Int 2a");
214 RealSetVec(0x2A,CALLBACK_RealPointer(call_int2a));
215 }