| 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_tables.cpp,v 1.32 2009-10-28 21:45:12 qbix79 Exp $ */ |
| 20 |
|
| 21 |
#include "dosbox.h" |
| 22 |
#include "mem.h" |
| 23 |
#include "dos_inc.h" |
| 24 |
#include "callback.h" |
| 25 |
|
| 26 |
#ifdef _MSC_VER |
| 27 |
#pragma pack(1) |
| 28 |
#endif |
| 29 |
struct DOS_TableCase { |
| 30 |
Bit16u size; |
| 31 |
Bit8u chars[256]; |
| 32 |
} |
| 33 |
GCC_ATTRIBUTE (packed); |
| 34 |
#ifdef _MSC_VER |
| 35 |
#pragma pack () |
| 36 |
#endif |
| 37 |
|
| 38 |
RealPt DOS_TableUpCase; |
| 39 |
RealPt DOS_TableLowCase; |
| 40 |
|
| 41 |
static Bitu call_casemap; |
| 42 |
|
| 43 |
static Bit16u dos_memseg=DOS_PRIVATE_SEGMENT; |
| 44 |
|
| 45 |
Bit16u DOS_GetMemory(Bit16u pages) { |
| 46 |
if ((Bitu)pages+(Bitu)dos_memseg>=DOS_PRIVATE_SEGMENT_END) { |
| 47 |
E_Exit("DOS:Not enough memory for internal tables"); |
| 48 |
} |
| 49 |
Bit16u page=dos_memseg; |
| 50 |
dos_memseg+=pages; |
| 51 |
return page; |
| 52 |
} |
| 53 |
|
| 54 |
static Bitu DOS_CaseMapFunc(void) { |
| 55 |
//LOG(LOG_DOSMISC,LOG_ERROR)("Case map routine called : %c",reg_al); |
| 56 |
return CBRET_NONE; |
| 57 |
} |
| 58 |
|
| 59 |
static Bit8u country_info[0x22] = { |
| 60 |
/* Date format */ 0x00, 0x00, |
| 61 |
/* Currencystring */ 0x24, 0x00, 0x00, 0x00, 0x00, |
| 62 |
/* Thousands sep */ 0x2c, 0x00, |
| 63 |
/* Decimal sep */ 0x2e, 0x00, |
| 64 |
/* Date sep */ 0x2d, 0x00, |
| 65 |
/* time sep */ 0x3a, 0x00, |
| 66 |
/* currency form */ 0x00, |
| 67 |
/* digits after dec */ 0x02, |
| 68 |
/* Time format */ 0x00, |
| 69 |
/* Casemap */ 0x00, 0x00, 0x00, 0x00, |
| 70 |
/* Data sep */ 0x2c, 0x00, |
| 71 |
/* Reservered 5 */ 0x00, 0x00, 0x00, 0x00, 0x00, |
| 72 |
/* Reservered 5 */ 0x00, 0x00, 0x00, 0x00, 0x00 |
| 73 |
}; |
| 74 |
|
| 75 |
void DOS_SetupTables(void) { |
| 76 |
Bit16u seg;Bitu i; |
| 77 |
dos.tables.mediaid=RealMake(DOS_GetMemory(4),0); |
| 78 |
dos.tables.tempdta=RealMake(DOS_GetMemory(4),0); |
| 79 |
dos.tables.tempdta_fcbdelete=RealMake(DOS_GetMemory(4),0); |
| 80 |
for (i=0;i<DOS_DRIVES;i++) mem_writew(Real2Phys(dos.tables.mediaid)+i*2,0); |
| 81 |
/* Create the DOS Info Block */ |
| 82 |
dos_infoblock.SetLocation(DOS_INFOBLOCK_SEG); //c2woody |
| 83 |
|
| 84 |
/* create SDA */ |
| 85 |
DOS_SDA(DOS_SDA_SEG,0).Init(); |
| 86 |
|
| 87 |
/* Some weird files >20 detection routine */ |
| 88 |
/* Possibly obselete when SFT is properly handled */ |
| 89 |
real_writed(DOS_CONSTRING_SEG,0x0a,0x204e4f43); |
| 90 |
real_writed(DOS_CONSTRING_SEG,0x1a,0x204e4f43); |
| 91 |
real_writed(DOS_CONSTRING_SEG,0x2a,0x204e4f43); |
| 92 |
|
| 93 |
/* create a CON device driver */ |
| 94 |
seg=DOS_CONDRV_SEG; |
| 95 |
real_writed(seg,0x00,0xffffffff); // next ptr |
| 96 |
real_writew(seg,0x04,0x8013); // attributes |
| 97 |
real_writed(seg,0x06,0xffffffff); // strategy routine |
| 98 |
real_writed(seg,0x0a,0x204e4f43); // driver name |
| 99 |
real_writed(seg,0x0e,0x20202020); // driver name |
| 100 |
dos_infoblock.SetDeviceChainStart(RealMake(seg,0)); |
| 101 |
|
| 102 |
/* Create a fake Current Directory Structure */ |
| 103 |
seg=DOS_CDS_SEG; |
| 104 |
real_writed(seg,0x00,0x005c3a43); |
| 105 |
dos_infoblock.SetCurDirStruct(RealMake(seg,0)); |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
/* Allocate DCBS DOUBLE BYTE CHARACTER SET LEAD-BYTE TABLE */ |
| 110 |
dos.tables.dbcs=RealMake(DOS_GetMemory(12),0); |
| 111 |
mem_writed(Real2Phys(dos.tables.dbcs),0); //empty table |
| 112 |
/* FILENAME CHARACTER TABLE */ |
| 113 |
dos.tables.filenamechar=RealMake(DOS_GetMemory(2),0); |
| 114 |
mem_writew(Real2Phys(dos.tables.filenamechar)+0x00,0x16); |
| 115 |
mem_writeb(Real2Phys(dos.tables.filenamechar)+0x02,0x01); |
| 116 |
mem_writeb(Real2Phys(dos.tables.filenamechar)+0x03,0x00); // allowed chars from |
| 117 |
mem_writeb(Real2Phys(dos.tables.filenamechar)+0x04,0xff); // ...to |
| 118 |
mem_writeb(Real2Phys(dos.tables.filenamechar)+0x05,0x00); |
| 119 |
mem_writeb(Real2Phys(dos.tables.filenamechar)+0x06,0x00); // excluded chars from |
| 120 |
mem_writeb(Real2Phys(dos.tables.filenamechar)+0x07,0x20); // ...to |
| 121 |
mem_writeb(Real2Phys(dos.tables.filenamechar)+0x08,0x02); |
| 122 |
mem_writeb(Real2Phys(dos.tables.filenamechar)+0x09,0x0e); // number of illegal separators |
| 123 |
mem_writeb(Real2Phys(dos.tables.filenamechar)+0x0a,0x2e); |
| 124 |
mem_writeb(Real2Phys(dos.tables.filenamechar)+0x0b,0x22); |
| 125 |
mem_writeb(Real2Phys(dos.tables.filenamechar)+0x0c,0x2f); |
| 126 |
mem_writeb(Real2Phys(dos.tables.filenamechar)+0x0d,0x5c); |
| 127 |
mem_writeb(Real2Phys(dos.tables.filenamechar)+0x0e,0x5b); |
| 128 |
mem_writeb(Real2Phys(dos.tables.filenamechar)+0x0f,0x5d); |
| 129 |
mem_writeb(Real2Phys(dos.tables.filenamechar)+0x10,0x3a); |
| 130 |
mem_writeb(Real2Phys(dos.tables.filenamechar)+0x11,0x7c); |
| 131 |
mem_writeb(Real2Phys(dos.tables.filenamechar)+0x12,0x3c); |
| 132 |
mem_writeb(Real2Phys(dos.tables.filenamechar)+0x13,0x3e); |
| 133 |
mem_writeb(Real2Phys(dos.tables.filenamechar)+0x14,0x2b); |
| 134 |
mem_writeb(Real2Phys(dos.tables.filenamechar)+0x15,0x3d); |
| 135 |
mem_writeb(Real2Phys(dos.tables.filenamechar)+0x16,0x3b); |
| 136 |
mem_writeb(Real2Phys(dos.tables.filenamechar)+0x17,0x2c); |
| 137 |
/* COLLATING SEQUENCE TABLE + UPCASE TABLE*/ |
| 138 |
// 256 bytes for col table, 128 for upcase, 4 for number of entries |
| 139 |
dos.tables.collatingseq=RealMake(DOS_GetMemory(25),0); |
| 140 |
mem_writew(Real2Phys(dos.tables.collatingseq),0x100); |
| 141 |
for (i=0; i<256; i++) mem_writeb(Real2Phys(dos.tables.collatingseq)+i+2,i); |
| 142 |
dos.tables.upcase=dos.tables.collatingseq+258; |
| 143 |
mem_writew(Real2Phys(dos.tables.upcase),0x80); |
| 144 |
for (i=0; i<128; i++) mem_writeb(Real2Phys(dos.tables.upcase)+i+2,0x80+i); |
| 145 |
|
| 146 |
|
| 147 |
/* Create a fake FCB SFT */ |
| 148 |
seg=DOS_GetMemory(4); |
| 149 |
real_writed(seg,0,0xffffffff); //Last File Table |
| 150 |
real_writew(seg,4,100); //File Table supports 100 files |
| 151 |
dos_infoblock.SetFCBTable(RealMake(seg,0)); |
| 152 |
|
| 153 |
/* Create a fake DPB */ |
| 154 |
dos.tables.dpb=DOS_GetMemory(2); |
| 155 |
for(Bitu d=0;d<26;d++) real_writeb(dos.tables.dpb,d,d); |
| 156 |
|
| 157 |
/* Create a fake disk buffer head */ |
| 158 |
seg=DOS_GetMemory(6); |
| 159 |
for (Bitu ct=0; ct<0x20; ct++) real_writeb(seg,ct,0); |
| 160 |
real_writew(seg,0x00,0xffff); // forward ptr |
| 161 |
real_writew(seg,0x02,0xffff); // backward ptr |
| 162 |
real_writeb(seg,0x04,0xff); // not in use |
| 163 |
real_writeb(seg,0x0a,0x01); // number of FATs |
| 164 |
real_writed(seg,0x0d,0xffffffff); // pointer to DPB |
| 165 |
dos_infoblock.SetDiskBufferHeadPt(RealMake(seg,0)); |
| 166 |
|
| 167 |
/* Set buffers to a nice value */ |
| 168 |
dos_infoblock.SetBuffers(50,50); |
| 169 |
|
| 170 |
/* case map routine INT 0x21 0x38 */ |
| 171 |
call_casemap = CALLBACK_Allocate(); |
| 172 |
CALLBACK_Setup(call_casemap,DOS_CaseMapFunc,CB_RETF,"DOS CaseMap"); |
| 173 |
/* Add it to country structure */ |
| 174 |
host_writed(country_info + 0x12, CALLBACK_RealPointer(call_casemap)); |
| 175 |
dos.tables.country=country_info; |
| 176 |
} |