| 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: bios.cpp,v 1.78 2009-10-10 13:26:46 h-a-l-9000 Exp $ */ |
| 20 |
|
| 21 |
#include "dosbox.h" |
| 22 |
#include "mem.h" |
| 23 |
#include "bios.h" |
| 24 |
#include "regs.h" |
| 25 |
#include "cpu.h" |
| 26 |
#include "callback.h" |
| 27 |
#include "inout.h" |
| 28 |
#include "pic.h" |
| 29 |
#include "hardware.h" |
| 30 |
#include "joystick.h" |
| 31 |
#include "mouse.h" |
| 32 |
#include "setup.h" |
| 33 |
#include "serialport.h" |
| 34 |
|
| 35 |
|
| 36 |
/* if mem_systems 0 then size_extended is reported as the real size else |
| 37 |
* zero is reported. ems and xms can increase or decrease the other_memsystems |
| 38 |
* counter using the BIOS_ZeroExtendedSize call */ |
| 39 |
static Bit16u size_extended; |
| 40 |
static Bits other_memsystems=0; |
| 41 |
void CMOS_SetRegister(Bitu regNr, Bit8u val); //For setting equipment word |
| 42 |
|
| 43 |
static Bitu INT70_Handler(void) { |
| 44 |
/* Acknowledge irq with cmos */ |
| 45 |
IO_Write(0x70,0xc); |
| 46 |
IO_Read(0x71); |
| 47 |
if (mem_readb(BIOS_WAIT_FLAG_ACTIVE)) { |
| 48 |
Bit32u count=mem_readd(BIOS_WAIT_FLAG_COUNT); |
| 49 |
if (count>997) { |
| 50 |
mem_writed(BIOS_WAIT_FLAG_COUNT,count-997); |
| 51 |
} else { |
| 52 |
mem_writed(BIOS_WAIT_FLAG_COUNT,0); |
| 53 |
PhysPt where=Real2Phys(mem_readd(BIOS_WAIT_FLAG_POINTER)); |
| 54 |
mem_writeb(where,mem_readb(where)|0x80); |
| 55 |
mem_writeb(BIOS_WAIT_FLAG_ACTIVE,0); |
| 56 |
mem_writed(BIOS_WAIT_FLAG_POINTER,RealMake(0,BIOS_WAIT_FLAG_TEMP)); |
| 57 |
IO_Write(0x70,0xb); |
| 58 |
IO_Write(0x71,IO_Read(0x71)&~0x40); |
| 59 |
} |
| 60 |
} |
| 61 |
/* Signal EOI to both pics */ |
| 62 |
IO_Write(0xa0,0x20); |
| 63 |
IO_Write(0x20,0x20); |
| 64 |
return 0; |
| 65 |
} |
| 66 |
|
| 67 |
CALLBACK_HandlerObject* tandy_DAC_callback[2]; |
| 68 |
static struct { |
| 69 |
Bit16u port; |
| 70 |
Bit8u irq; |
| 71 |
Bit8u dma; |
| 72 |
} tandy_sb; |
| 73 |
static struct { |
| 74 |
Bit16u port; |
| 75 |
Bit8u irq; |
| 76 |
Bit8u dma; |
| 77 |
} tandy_dac; |
| 78 |
|
| 79 |
static bool Tandy_InitializeSB() { |
| 80 |
/* see if soundblaster module available and at what port/IRQ/DMA */ |
| 81 |
Bitu sbport, sbirq, sbdma; |
| 82 |
if (SB_Get_Address(sbport, sbirq, sbdma)) { |
| 83 |
tandy_sb.port=(Bit16u)(sbport&0xffff); |
| 84 |
tandy_sb.irq =(Bit8u)(sbirq&0xff); |
| 85 |
tandy_sb.dma =(Bit8u)(sbdma&0xff); |
| 86 |
return true; |
| 87 |
} else { |
| 88 |
/* no soundblaster accessible, disable Tandy DAC */ |
| 89 |
tandy_sb.port=0; |
| 90 |
return false; |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
static bool Tandy_InitializeTS() { |
| 95 |
/* see if Tandy DAC module available and at what port/IRQ/DMA */ |
| 96 |
Bitu tsport, tsirq, tsdma; |
| 97 |
if (TS_Get_Address(tsport, tsirq, tsdma)) { |
| 98 |
tandy_dac.port=(Bit16u)(tsport&0xffff); |
| 99 |
tandy_dac.irq =(Bit8u)(tsirq&0xff); |
| 100 |
tandy_dac.dma =(Bit8u)(tsdma&0xff); |
| 101 |
return true; |
| 102 |
} else { |
| 103 |
/* no Tandy DAC accessible */ |
| 104 |
tandy_dac.port=0; |
| 105 |
return false; |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
/* check if Tandy DAC is still playing */ |
| 110 |
static bool Tandy_TransferInProgress(void) { |
| 111 |
if (real_readw(0x40,0xd0)) return true; /* not yet done */ |
| 112 |
if (real_readb(0x40,0xd4)==0xff) return false; /* still in init-state */ |
| 113 |
|
| 114 |
Bit8u tandy_dma = 1; |
| 115 |
if (tandy_sb.port) tandy_dma = tandy_sb.dma; |
| 116 |
else if (tandy_dac.port) tandy_dma = tandy_dac.dma; |
| 117 |
|
| 118 |
IO_Write(0x0c,0x00); |
| 119 |
Bit16u datalen=(Bit8u)(IO_ReadB(tandy_dma*2+1)&0xff); |
| 120 |
datalen|=(IO_ReadB(tandy_dma*2+1)<<8); |
| 121 |
if (datalen==0xffff) return false; /* no DMA transfer */ |
| 122 |
else if ((datalen<0x10) && (real_readb(0x40,0xd4)==0x0f) && (real_readw(0x40,0xd2)==0x1c)) { |
| 123 |
/* stop already requested */ |
| 124 |
return false; |
| 125 |
} |
| 126 |
return true; |
| 127 |
} |
| 128 |
|
| 129 |
static void Tandy_SetupTransfer(PhysPt bufpt,bool isplayback) { |
| 130 |
Bitu length=real_readw(0x40,0xd0); |
| 131 |
if (length==0) return; /* nothing to do... */ |
| 132 |
|
| 133 |
if ((tandy_sb.port==0) && (tandy_dac.port==0)) return; |
| 134 |
|
| 135 |
Bit8u tandy_irq = 7; |
| 136 |
if (tandy_sb.port) tandy_irq = tandy_sb.irq; |
| 137 |
else if (tandy_dac.port) tandy_irq = tandy_dac.irq; |
| 138 |
Bit8u tandy_irq_vector = tandy_irq; |
| 139 |
if (tandy_irq_vector<8) tandy_irq_vector += 8; |
| 140 |
else tandy_irq_vector += (0x70-8); |
| 141 |
|
| 142 |
/* revector IRQ-handler if necessary */ |
| 143 |
RealPt current_irq=RealGetVec(tandy_irq_vector); |
| 144 |
if (current_irq!=tandy_DAC_callback[0]->Get_RealPointer()) { |
| 145 |
real_writed(0x40,0xd6,current_irq); |
| 146 |
RealSetVec(tandy_irq_vector,tandy_DAC_callback[0]->Get_RealPointer()); |
| 147 |
} |
| 148 |
|
| 149 |
Bit8u tandy_dma = 1; |
| 150 |
if (tandy_sb.port) tandy_dma = tandy_sb.dma; |
| 151 |
else if (tandy_dac.port) tandy_dma = tandy_dac.dma; |
| 152 |
|
| 153 |
if (tandy_sb.port) { |
| 154 |
IO_Write(tandy_sb.port+0xc,0xd0); /* stop DMA transfer */ |
| 155 |
IO_Write(0x21,IO_Read(0x21)&(~(1<<tandy_irq))); /* unmask IRQ */ |
| 156 |
IO_Write(tandy_sb.port+0xc,0xd1); /* turn speaker on */ |
| 157 |
} else { |
| 158 |
IO_Write(tandy_dac.port,IO_Read(tandy_dac.port)&0x60); /* disable DAC */ |
| 159 |
IO_Write(0x21,IO_Read(0x21)&(~(1<<tandy_irq))); /* unmask IRQ */ |
| 160 |
} |
| 161 |
|
| 162 |
IO_Write(0x0a,0x04|tandy_dma); /* mask DMA channel */ |
| 163 |
IO_Write(0x0c,0x00); /* clear DMA flipflop */ |
| 164 |
if (isplayback) IO_Write(0x0b,0x48|tandy_dma); |
| 165 |
else IO_Write(0x0b,0x44|tandy_dma); |
| 166 |
/* set physical address of buffer */ |
| 167 |
Bit8u bufpage=(Bit8u)((bufpt>>16)&0xff); |
| 168 |
IO_Write(tandy_dma*2,(Bit8u)(bufpt&0xff)); |
| 169 |
IO_Write(tandy_dma*2,(Bit8u)((bufpt>>8)&0xff)); |
| 170 |
switch (tandy_dma) { |
| 171 |
case 0: IO_Write(0x87,bufpage); break; |
| 172 |
case 1: IO_Write(0x83,bufpage); break; |
| 173 |
case 2: IO_Write(0x81,bufpage); break; |
| 174 |
case 3: IO_Write(0x82,bufpage); break; |
| 175 |
} |
| 176 |
real_writeb(0x40,0xd4,bufpage); |
| 177 |
|
| 178 |
/* calculate transfer size (respects segment boundaries) */ |
| 179 |
Bit32u tlength=length; |
| 180 |
if (tlength+(bufpt&0xffff)>0x10000) tlength=0x10000-(bufpt&0xffff); |
| 181 |
real_writew(0x40,0xd0,(Bit16u)(length-tlength)); /* remaining buffer length */ |
| 182 |
tlength--; |
| 183 |
|
| 184 |
/* set transfer size */ |
| 185 |
IO_Write(tandy_dma*2+1,(Bit8u)(tlength&0xff)); |
| 186 |
IO_Write(tandy_dma*2+1,(Bit8u)((tlength>>8)&0xff)); |
| 187 |
|
| 188 |
Bit16u delay=(Bit16u)(real_readw(0x40,0xd2)&0xfff); |
| 189 |
Bit8u amplitude=(Bit8u)((real_readw(0x40,0xd2)>>13)&0x7); |
| 190 |
if (tandy_sb.port) { |
| 191 |
IO_Write(0x0a,tandy_dma); /* enable DMA channel */ |
| 192 |
/* set frequency */ |
| 193 |
IO_Write(tandy_sb.port+0xc,0x40); |
| 194 |
IO_Write(tandy_sb.port+0xc,256-delay*100/358); |
| 195 |
/* set playback type to 8bit */ |
| 196 |
if (isplayback) IO_Write(tandy_sb.port+0xc,0x14); |
| 197 |
else IO_Write(tandy_sb.port+0xc,0x24); |
| 198 |
/* set transfer size */ |
| 199 |
IO_Write(tandy_sb.port+0xc,(Bit8u)(tlength&0xff)); |
| 200 |
IO_Write(tandy_sb.port+0xc,(Bit8u)((tlength>>8)&0xff)); |
| 201 |
} else { |
| 202 |
if (isplayback) IO_Write(tandy_dac.port,(IO_Read(tandy_dac.port)&0x7c) | 0x03); |
| 203 |
else IO_Write(tandy_dac.port,(IO_Read(tandy_dac.port)&0x7c) | 0x02); |
| 204 |
IO_Write(tandy_dac.port+2,(Bit8u)(delay&0xff)); |
| 205 |
IO_Write(tandy_dac.port+3,(Bit8u)(((delay>>8)&0xf) | (amplitude<<5))); |
| 206 |
if (isplayback) IO_Write(tandy_dac.port,(IO_Read(tandy_dac.port)&0x7c) | 0x1f); |
| 207 |
else IO_Write(tandy_dac.port,(IO_Read(tandy_dac.port)&0x7c) | 0x1e); |
| 208 |
IO_Write(0x0a,tandy_dma); /* enable DMA channel */ |
| 209 |
} |
| 210 |
|
| 211 |
if (!isplayback) { |
| 212 |
/* mark transfer as recording operation */ |
| 213 |
real_writew(0x40,0xd2,(Bit16u)(delay|0x1000)); |
| 214 |
} |
| 215 |
} |
| 216 |
|
| 217 |
static Bitu IRQ_TandyDAC(void) { |
| 218 |
if (tandy_dac.port) { |
| 219 |
IO_Read(tandy_dac.port); |
| 220 |
} |
| 221 |
if (real_readw(0x40,0xd0)) { /* play/record next buffer */ |
| 222 |
/* acknowledge IRQ */ |
| 223 |
IO_Write(0x20,0x20); |
| 224 |
if (tandy_sb.port) { |
| 225 |
IO_Read(tandy_sb.port+0xe); |
| 226 |
} |
| 227 |
|
| 228 |
/* buffer starts at the next page */ |
| 229 |
Bit8u npage=real_readb(0x40,0xd4)+1; |
| 230 |
real_writeb(0x40,0xd4,npage); |
| 231 |
|
| 232 |
Bitu rb=real_readb(0x40,0xd3); |
| 233 |
if (rb&0x10) { |
| 234 |
/* start recording */ |
| 235 |
real_writeb(0x40,0xd3,rb&0xef); |
| 236 |
Tandy_SetupTransfer(npage<<16,false); |
| 237 |
} else { |
| 238 |
/* start playback */ |
| 239 |
Tandy_SetupTransfer(npage<<16,true); |
| 240 |
} |
| 241 |
} else { /* playing/recording is finished */ |
| 242 |
Bit8u tandy_irq = 7; |
| 243 |
if (tandy_sb.port) tandy_irq = tandy_sb.irq; |
| 244 |
else if (tandy_dac.port) tandy_irq = tandy_dac.irq; |
| 245 |
Bit8u tandy_irq_vector = tandy_irq; |
| 246 |
if (tandy_irq_vector<8) tandy_irq_vector += 8; |
| 247 |
else tandy_irq_vector += (0x70-8); |
| 248 |
|
| 249 |
RealSetVec(tandy_irq_vector,real_readd(0x40,0xd6)); |
| 250 |
|
| 251 |
/* turn off speaker and acknowledge soundblaster IRQ */ |
| 252 |
if (tandy_sb.port) { |
| 253 |
IO_Write(tandy_sb.port+0xc,0xd3); |
| 254 |
IO_Read(tandy_sb.port+0xe); |
| 255 |
} |
| 256 |
|
| 257 |
/* issue BIOS tandy sound device busy callout */ |
| 258 |
SegSet16(cs, RealSeg(tandy_DAC_callback[1]->Get_RealPointer())); |
| 259 |
reg_ip = RealOff(tandy_DAC_callback[1]->Get_RealPointer()); |
| 260 |
} |
| 261 |
return CBRET_NONE; |
| 262 |
} |
| 263 |
|
| 264 |
static void TandyDAC_Handler(Bit8u tfunction) { |
| 265 |
if ((!tandy_sb.port) && (!tandy_dac.port)) return; |
| 266 |
switch (tfunction) { |
| 267 |
case 0x81: /* Tandy sound system check */ |
| 268 |
if (tandy_dac.port) { |
| 269 |
reg_ax=tandy_dac.port; |
| 270 |
} else { |
| 271 |
reg_ax=0xc4; |
| 272 |
} |
| 273 |
CALLBACK_SCF(Tandy_TransferInProgress()); |
| 274 |
break; |
| 275 |
case 0x82: /* Tandy sound system start recording */ |
| 276 |
case 0x83: /* Tandy sound system start playback */ |
| 277 |
if (Tandy_TransferInProgress()) { |
| 278 |
/* cannot play yet as the last transfer isn't finished yet */ |
| 279 |
reg_ah=0x00; |
| 280 |
CALLBACK_SCF(true); |
| 281 |
break; |
| 282 |
} |
| 283 |
/* store buffer length */ |
| 284 |
real_writew(0x40,0xd0,reg_cx); |
| 285 |
/* store delay and volume */ |
| 286 |
real_writew(0x40,0xd2,(reg_dx&0xfff)|((reg_al&7)<<13)); |
| 287 |
Tandy_SetupTransfer(PhysMake(SegValue(es),reg_bx),reg_ah==0x83); |
| 288 |
reg_ah=0x00; |
| 289 |
CALLBACK_SCF(false); |
| 290 |
break; |
| 291 |
case 0x84: /* Tandy sound system stop playing */ |
| 292 |
reg_ah=0x00; |
| 293 |
|
| 294 |
/* setup for a small buffer with silence */ |
| 295 |
real_writew(0x40,0xd0,0x0a); |
| 296 |
real_writew(0x40,0xd2,0x1c); |
| 297 |
Tandy_SetupTransfer(PhysMake(0xf000,0xa084),true); |
| 298 |
CALLBACK_SCF(false); |
| 299 |
break; |
| 300 |
case 0x85: /* Tandy sound system reset */ |
| 301 |
if (tandy_dac.port) { |
| 302 |
IO_Write(tandy_dac.port,(Bit8u)(IO_Read(tandy_dac.port)&0xe0)); |
| 303 |
} |
| 304 |
reg_ah=0x00; |
| 305 |
CALLBACK_SCF(false); |
| 306 |
break; |
| 307 |
} |
| 308 |
} |
| 309 |
|
| 310 |
static Bitu INT1A_Handler(void) { |
| 311 |
switch (reg_ah) { |
| 312 |
case 0x00: /* Get System time */ |
| 313 |
{ |
| 314 |
Bit32u ticks=mem_readd(BIOS_TIMER); |
| 315 |
reg_al=0; /* Midnight never passes :) */ |
| 316 |
reg_cx=(Bit16u)(ticks >> 16); |
| 317 |
reg_dx=(Bit16u)(ticks & 0xffff); |
| 318 |
break; |
| 319 |
} |
| 320 |
case 0x01: /* Set System time */ |
| 321 |
mem_writed(BIOS_TIMER,(reg_cx<<16)|reg_dx); |
| 322 |
break; |
| 323 |
case 0x02: /* GET REAL-TIME CLOCK TIME (AT,XT286,PS) */ |
| 324 |
IO_Write(0x70,0x04); //Hours |
| 325 |
reg_ch=IO_Read(0x71); |
| 326 |
IO_Write(0x70,0x02); //Minutes |
| 327 |
reg_cl=IO_Read(0x71); |
| 328 |
IO_Write(0x70,0x00); //Seconds |
| 329 |
reg_dh=IO_Read(0x71); |
| 330 |
reg_dl=0; //Daylight saving disabled |
| 331 |
CALLBACK_SCF(false); |
| 332 |
break; |
| 333 |
case 0x04: /* GET REAL-TIME ClOCK DATE (AT,XT286,PS) */ |
| 334 |
IO_Write(0x70,0x32); //Centuries |
| 335 |
reg_ch=IO_Read(0x71); |
| 336 |
IO_Write(0x70,0x09); //Years |
| 337 |
reg_cl=IO_Read(0x71); |
| 338 |
IO_Write(0x70,0x08); //Months |
| 339 |
reg_dh=IO_Read(0x71); |
| 340 |
IO_Write(0x70,0x07); //Days |
| 341 |
reg_dl=IO_Read(0x71); |
| 342 |
CALLBACK_SCF(false); |
| 343 |
break; |
| 344 |
case 0x80: /* Pcjr Setup Sound Multiplexer */ |
| 345 |
LOG(LOG_BIOS,LOG_ERROR)("INT1A:80:Setup tandy sound multiplexer to %d",reg_al); |
| 346 |
break; |
| 347 |
case 0x81: /* Tandy sound system check */ |
| 348 |
case 0x82: /* Tandy sound system start recording */ |
| 349 |
case 0x83: /* Tandy sound system start playback */ |
| 350 |
case 0x84: /* Tandy sound system stop playing */ |
| 351 |
case 0x85: /* Tandy sound system reset */ |
| 352 |
TandyDAC_Handler(reg_ah); |
| 353 |
break; |
| 354 |
case 0xb1: /* PCI Bios Calls */ |
| 355 |
LOG(LOG_BIOS,LOG_ERROR)("INT1A:PCI bios call %2X",reg_al); |
| 356 |
CALLBACK_SCF(true); |
| 357 |
break; |
| 358 |
default: |
| 359 |
LOG(LOG_BIOS,LOG_ERROR)("INT1A:Undefined call %2X",reg_ah); |
| 360 |
} |
| 361 |
return CBRET_NONE; |
| 362 |
} |
| 363 |
|
| 364 |
static Bitu INT11_Handler(void) { |
| 365 |
reg_ax=mem_readw(BIOS_CONFIGURATION); |
| 366 |
return CBRET_NONE; |
| 367 |
} |
| 368 |
/* |
| 369 |
* Define the following define to 1 if you want dosbox to check |
| 370 |
* the system time every 5 seconds and adjust 1/2 a second to sync them. |
| 371 |
*/ |
| 372 |
#ifndef DOSBOX_CLOCKSYNC |
| 373 |
#define DOSBOX_CLOCKSYNC 0 |
| 374 |
#endif |
| 375 |
static Bitu INT8_Handler(void) { |
| 376 |
/* Increase the bios tick counter */ |
| 377 |
Bit32u value = mem_readd(BIOS_TIMER) + 1; |
| 378 |
#if DOSBOX_CLOCKSYNC |
| 379 |
static bool check = false; |
| 380 |
if((value %50)==0) { |
| 381 |
if(((value %100)==0) && check) { |
| 382 |
check = false; |
| 383 |
time_t curtime;struct tm *loctime; |
| 384 |
curtime = time (NULL);loctime = localtime (&curtime); |
| 385 |
Bit32u ticksnu = (Bit32u)((loctime->tm_hour*3600+loctime->tm_min*60+loctime->tm_sec)*(float)PIT_TICK_RATE/65536.0); |
| 386 |
Bit32s bios = value;Bit32s tn = ticksnu; |
| 387 |
Bit32s diff = tn - bios; |
| 388 |
if(diff>0) { |
| 389 |
if(diff < 18) { diff = 0; } else diff = 9; |
| 390 |
} else { |
| 391 |
if(diff > -18) { diff = 0; } else diff = -9; |
| 392 |
} |
| 393 |
|
| 394 |
value += diff; |
| 395 |
} else if((value%100)==50) check = true; |
| 396 |
} |
| 397 |
#endif |
| 398 |
mem_writed(BIOS_TIMER,value); |
| 399 |
|
| 400 |
/* decrease floppy motor timer */ |
| 401 |
Bit8u val = mem_readb(BIOS_DISK_MOTOR_TIMEOUT); |
| 402 |
if (val) mem_writeb(BIOS_DISK_MOTOR_TIMEOUT,val-1); |
| 403 |
/* and running drive */ |
| 404 |
mem_writeb(BIOS_DRIVE_RUNNING,mem_readb(BIOS_DRIVE_RUNNING) & 0xF0); |
| 405 |
return CBRET_NONE; |
| 406 |
} |
| 407 |
#undef DOSBOX_CLOCKSYNC |
| 408 |
|
| 409 |
static Bitu INT1C_Handler(void) { |
| 410 |
return CBRET_NONE; |
| 411 |
} |
| 412 |
|
| 413 |
static Bitu INT12_Handler(void) { |
| 414 |
reg_ax=mem_readw(BIOS_MEMORY_SIZE); |
| 415 |
return CBRET_NONE; |
| 416 |
} |
| 417 |
|
| 418 |
static Bitu INT17_Handler(void) { |
| 419 |
LOG(LOG_BIOS,LOG_NORMAL)("INT17:Function %X",reg_ah); |
| 420 |
switch(reg_ah) { |
| 421 |
case 0x00: /* PRINTER: Write Character */ |
| 422 |
reg_ah=1; /* Report a timeout */ |
| 423 |
break; |
| 424 |
case 0x01: /* PRINTER: Initialize port */ |
| 425 |
break; |
| 426 |
case 0x02: /* PRINTER: Get Status */ |
| 427 |
reg_ah=0; |
| 428 |
break; |
| 429 |
case 0x20: /* Some sort of printerdriver install check*/ |
| 430 |
break; |
| 431 |
default: |
| 432 |
E_Exit("Unhandled INT 17 call %2X",reg_ah); |
| 433 |
}; |
| 434 |
return CBRET_NONE; |
| 435 |
} |
| 436 |
|
| 437 |
static Bit8u INT14_Wait(Bit16u port, Bit8u mask, Bit8u timeout) { |
| 438 |
double starttime = PIC_FullIndex(); |
| 439 |
double timeout_f = timeout * 1000.0; |
| 440 |
Bit8u retval; |
| 441 |
while (((retval = IO_ReadB(port)) & mask) != mask) { |
| 442 |
if (starttime < (PIC_FullIndex() - timeout_f)) { |
| 443 |
retval |= 0x80; |
| 444 |
break; |
| 445 |
} |
| 446 |
CALLBACK_Idle(); |
| 447 |
} |
| 448 |
return retval; |
| 449 |
} |
| 450 |
|
| 451 |
static Bitu INT14_Handler(void) { |
| 452 |
if (reg_ah > 0x3 || reg_dx > 0x3) { // 0-3 serial port functions |
| 453 |
// and no more than 4 serial ports |
| 454 |
LOG_MSG("BIOS INT14: Unhandled call AH=%2X DX=%4x",reg_ah,reg_dx); |
| 455 |
return CBRET_NONE; |
| 456 |
} |
| 457 |
|
| 458 |
Bit16u port = real_readw(0x40,reg_dx*2); // DX is always port number |
| 459 |
Bit8u timeout = mem_readb(BIOS_COM1_TIMEOUT + reg_dx); |
| 460 |
if (port==0) { |
| 461 |
LOG(LOG_BIOS,LOG_NORMAL)("BIOS INT14: port %d does not exist.",reg_dx); |
| 462 |
return CBRET_NONE; |
| 463 |
} |
| 464 |
switch (reg_ah) { |
| 465 |
case 0x00: { |
| 466 |
// Initialize port |
| 467 |
// Parameters: Return: |
| 468 |
// AL: port parameters AL: modem status |
| 469 |
// AH: line status |
| 470 |
|
| 471 |
// set baud rate |
| 472 |
Bitu baudrate = 9600; |
| 473 |
Bit16u baudresult; |
| 474 |
Bitu rawbaud=reg_al>>5; |
| 475 |
|
| 476 |
if (rawbaud==0){ baudrate=110;} |
| 477 |
else if (rawbaud==1){ baudrate=150;} |
| 478 |
else if (rawbaud==2){ baudrate=300;} |
| 479 |
else if (rawbaud==3){ baudrate=600;} |
| 480 |
else if (rawbaud==4){ baudrate=1200;} |
| 481 |
else if (rawbaud==5){ baudrate=2400;} |
| 482 |
else if (rawbaud==6){ baudrate=4800;} |
| 483 |
else if (rawbaud==7){ baudrate=9600;} |
| 484 |
|
| 485 |
baudresult = (Bit16u)(115200 / baudrate); |
| 486 |
|
| 487 |
IO_WriteB(port+3, 0x80); // enable divider access |
| 488 |
IO_WriteB(port, (Bit8u)baudresult&0xff); |
| 489 |
IO_WriteB(port+1, (Bit8u)(baudresult>>8)); |
| 490 |
|
| 491 |
// set line parameters, disable divider access |
| 492 |
IO_WriteB(port+3, reg_al&0x1F); // LCR |
| 493 |
|
| 494 |
// disable interrupts |
| 495 |
IO_WriteB(port+1, 0); // IER |
| 496 |
|
| 497 |
// get result |
| 498 |
reg_ah=(Bit8u)(IO_ReadB(port+5)&0xff); |
| 499 |
reg_al=(Bit8u)(IO_ReadB(port+6)&0xff); |
| 500 |
CALLBACK_SCF(false); |
| 501 |
break; |
| 502 |
} |
| 503 |
case 0x01: { // Transmit character |
| 504 |
// Parameters: Return: |
| 505 |
// AL: character AL: unchanged |
| 506 |
// AH: 0x01 AH: line status from just before the char was sent |
| 507 |
// (0x80 | unpredicted) in case of timeout |
| 508 |
// [undoc] (0x80 | line status) in case of tx timeout |
| 509 |
// [undoc] (0x80 | modem status) in case of dsr/cts timeout |
| 510 |
|
| 511 |
// set DTR & RTS on |
| 512 |
IO_WriteB(port+4,0x3); |
| 513 |
|
| 514 |
// wait for DSR & CTS |
| 515 |
reg_ah = INT14_Wait(port+6, 0x30, timeout); |
| 516 |
if (!(reg_ah & 0x80)) { |
| 517 |
// wait for TX buffer empty |
| 518 |
reg_ah = INT14_Wait(port+5, 0x20, timeout); |
| 519 |
if (!(reg_ah & 0x80)) { |
| 520 |
// fianlly send the character |
| 521 |
IO_WriteB(port,reg_al); |
| 522 |
} |
| 523 |
} // else timed out |
| 524 |
CALLBACK_SCF(false); |
| 525 |
break; |
| 526 |
} |
| 527 |
case 0x02: // Read character |
| 528 |
// Parameters: Return: |
| 529 |
// AH: 0x02 AL: received character |
| 530 |
// [undoc] will be trashed in case of timeout |
| 531 |
// AH: (line status & 0x1E) in case of success |
| 532 |
// (0x80 | unpredicted) in case of timeout |
| 533 |
// [undoc] (0x80 | line status) in case of rx timeout |
| 534 |
// [undoc] (0x80 | modem status) in case of dsr timeout |
| 535 |
|
| 536 |
// set DTR on |
| 537 |
IO_WriteB(port+4,0x1); |
| 538 |
|
| 539 |
// wait for DSR |
| 540 |
reg_ah = INT14_Wait(port+6, 0x20, timeout); |
| 541 |
if (!(reg_ah & 0x80)) { |
| 542 |
// wait for character to arrive |
| 543 |
reg_ah = INT14_Wait(port+5, 0x01, timeout); |
| 544 |
if (!(reg_ah & 0x80)) { |
| 545 |
reg_ah &= 0x1E; |
| 546 |
reg_al = IO_ReadB(port); |
| 547 |
} |
| 548 |
} |
| 549 |
CALLBACK_SCF(false); |
| 550 |
break; |
| 551 |
case 0x03: // get status |
| 552 |
reg_ah=(Bit8u)(IO_ReadB(port+5)&0xff); |
| 553 |
reg_al=(Bit8u)(IO_ReadB(port+6)&0xff); |
| 554 |
CALLBACK_SCF(false); |
| 555 |
break; |
| 556 |
|
| 557 |
} |
| 558 |
return CBRET_NONE; |
| 559 |
} |
| 560 |
|
| 561 |
static Bitu INT15_Handler(void) { |
| 562 |
static Bit16u biosConfigSeg=0; |
| 563 |
switch (reg_ah) { |
| 564 |
case 0x06: |
| •565 |
LOG(LOG_BIOS,LOG_NORMAL)("INT15 Unknown Function 6"); |
| 566 |
break; |
| 567 |
case 0xC0: /* Get Configuration*/ |
| 568 |
{ |
| 569 |
if (biosConfigSeg==0) biosConfigSeg = DOS_GetMemory(1); //We have 16 bytes |
| 570 |
PhysPt data = PhysMake(biosConfigSeg,0); |
| 571 |
mem_writew(data,8); // 8 Bytes following |
| 572 |
if (IS_TANDY_ARCH) { |
| 573 |
if (machine==MCH_TANDY) { |
| 574 |
// Model ID (Tandy) |
| 575 |
mem_writeb(data+2,0xFF); |
| 576 |
} else { |
| 577 |
// Model ID (PCJR) |
| 578 |
mem_writeb(data+2,0xFD); |
| 579 |
} |
| 580 |
mem_writeb(data+3,0x0A); // Submodel ID |
| 581 |
mem_writeb(data+4,0x10); // Bios Revision |
| 582 |
/* Tandy doesn't have a 2nd PIC, left as is for now */ |
| 583 |
mem_writeb(data+5,(1<<6)|(1<<5)|(1<<4)); // Feature Byte 1 |
| 584 |
} else { |
| 585 |
mem_writeb(data+2,0xFC); // Model ID (PC) |
| 586 |
mem_writeb(data+3,0x00); // Submodel ID |
| 587 |
mem_writeb(data+4,0x01); // Bios Revision |
| 588 |
mem_writeb(data+5,(1<<6)|(1<<5)|(1<<4)); // Feature Byte 1 |
| 589 |
} |
| 590 |
mem_writeb(data+6,(1<<6)); // Feature Byte 2 |
| 591 |
mem_writeb(data+7,0); // Feature Byte 3 |
| 592 |
mem_writeb(data+8,0); // Feature Byte 4 |
| 593 |
mem_writeb(data+9,0); // Feature Byte 5 |
| 594 |
CPU_SetSegGeneral(es,biosConfigSeg); |
| 595 |
reg_bx = 0; |
| 596 |
reg_ah = 0; |
| 597 |
CALLBACK_SCF(false); |
| 598 |
}; break; |
| 599 |
case 0x4f: /* BIOS - Keyboard intercept */ |
| 600 |
/* Carry should be set but let's just set it just in case */ |
| 601 |
CALLBACK_SCF(true); |
| 602 |
break; |
| 603 |
case 0x83: /* BIOS - SET EVENT WAIT INTERVAL */ |
| 604 |
{ |
| 605 |
if(reg_al == 0x01) { /* Cancel it */ |
| 606 |
mem_writeb(BIOS_WAIT_FLAG_ACTIVE,0); |
| 607 |
IO_Write(0x70,0xb); |
| 608 |
IO_Write(0x71,IO_Read(0x71)&~0x40); |
| 609 |
CALLBACK_SCF(false); |
| 610 |
break; |
| 611 |
} |
| 612 |
if (mem_readb(BIOS_WAIT_FLAG_ACTIVE)) { |
| 613 |
reg_ah=0x80; |
| 614 |
CALLBACK_SCF(true); |
| 615 |
break; |
| 616 |
} |
| 617 |
Bit32u count=(reg_cx<<16)|reg_dx; |
| 618 |
mem_writed(BIOS_WAIT_FLAG_POINTER,RealMake(SegValue(es),reg_bx)); |
| 619 |
mem_writed(BIOS_WAIT_FLAG_COUNT,count); |
| 620 |
mem_writeb(BIOS_WAIT_FLAG_ACTIVE,1); |
| 621 |
/* Reprogram RTC to start */ |
| 622 |
IO_Write(0x70,0xb); |
| 623 |
IO_Write(0x71,IO_Read(0x71)|0x40); |
| 624 |
CALLBACK_SCF(false); |
| 625 |
} |
| 626 |
break; |
| 627 |
case 0x84: /* BIOS - JOYSTICK SUPPORT (XT after 11/8/82,AT,XT286,PS) */ |
| 628 |
if (reg_dx == 0x0000) { |
| 629 |
// Get Joystick button status |
| 630 |
if (JOYSTICK_IsEnabled(0) || JOYSTICK_IsEnabled(1)) { |
| 631 |
reg_al = IO_ReadB(0x201)&0xf0; |
| 632 |
CALLBACK_SCF(false); |
| 633 |
} else { |
| 634 |
// dos values |
| 635 |
reg_ax = 0x00f0; reg_dx = 0x0201; |
| 636 |
CALLBACK_SCF(true); |
| 637 |
} |
| 638 |
} else if (reg_dx == 0x0001) { |
| 639 |
if (JOYSTICK_IsEnabled(0)) { |
| 640 |
reg_ax = (Bit16u)(JOYSTICK_GetMove_X(0)*127+128); |
| 641 |
reg_bx = (Bit16u)(JOYSTICK_GetMove_Y(0)*127+128); |
| 642 |
if(JOYSTICK_IsEnabled(1)) { |
| 643 |
reg_cx = (Bit16u)(JOYSTICK_GetMove_X(1)*127+128); |
| 644 |
reg_dx = (Bit16u)(JOYSTICK_GetMove_Y(1)*127+128); |
| 645 |
} |
| 646 |
else { |
| 647 |
reg_cx = reg_dx = 0; |
| 648 |
} |
| 649 |
CALLBACK_SCF(false); |
| 650 |
} else if (JOYSTICK_IsEnabled(1)) { |
| 651 |
reg_ax = reg_bx = 0; |
| 652 |
reg_cx = (Bit16u)(JOYSTICK_GetMove_X(1)*127+128); |
| 653 |
reg_dx = (Bit16u)(JOYSTICK_GetMove_Y(1)*127+128); |
| 654 |
CALLBACK_SCF(false); |
| 655 |
} else { |
| 656 |
reg_ax = reg_bx = reg_cx = reg_dx = 0; |
| 657 |
CALLBACK_SCF(true); |
| 658 |
} |
| 659 |
} else { |
| 660 |
LOG(LOG_BIOS,LOG_ERROR)("INT15:84:Unknown Bios Joystick functionality."); |
| 661 |
} |
| 662 |
break; |
| 663 |
case 0x86: /* BIOS - WAIT (AT,PS) */ |
| 664 |
{ |
| 665 |
if (mem_readb(BIOS_WAIT_FLAG_ACTIVE)) { |
| 666 |
reg_ah=0x83; |
| 667 |
CALLBACK_SCF(true); |
| 668 |
break; |
| 669 |
} |
| 670 |
Bit32u count=(reg_cx<<16)|reg_dx; |
| 671 |
mem_writed(BIOS_WAIT_FLAG_POINTER,RealMake(0,BIOS_WAIT_FLAG_TEMP)); |
| 672 |
mem_writed(BIOS_WAIT_FLAG_COUNT,count); |
| 673 |
mem_writeb(BIOS_WAIT_FLAG_ACTIVE,1); |
| 674 |
/* Reprogram RTC to start */ |
| 675 |
IO_Write(0x70,0xb); |
| 676 |
IO_Write(0x71,IO_Read(0x71)|0x40); |
| 677 |
while (mem_readd(BIOS_WAIT_FLAG_COUNT)) { |
| 678 |
CALLBACK_Idle(); |
| 679 |
} |
| 680 |
CALLBACK_SCF(false); |
| 681 |
} |
| 682 |
case 0x87: /* Copy extended memory */ |
| 683 |
{ |
| 684 |
bool enabled = MEM_A20_Enabled(); |
| 685 |
MEM_A20_Enable(true); |
| 686 |
Bitu bytes = reg_cx * 2; |
| 687 |
PhysPt data = SegPhys(es)+reg_si; |
| 688 |
PhysPt source = (mem_readd(data+0x12) & 0x00FFFFFF) + (mem_readb(data+0x16)<<24); |
| 689 |
PhysPt dest = (mem_readd(data+0x1A) & 0x00FFFFFF) + (mem_readb(data+0x1E)<<24); |
| 690 |
MEM_BlockCopy(dest,source,bytes); |
| 691 |
reg_ax = 0x00; |
| 692 |
MEM_A20_Enable(enabled); |
| 693 |
CALLBACK_SCF(false); |
| 694 |
break; |
| 695 |
} |
| 696 |
case 0x88: /* SYSTEM - GET EXTENDED MEMORY SIZE (286+) */ |
| 697 |
reg_ax=other_memsystems?0:size_extended; |
| 698 |
LOG(LOG_BIOS,LOG_NORMAL)("INT15:Function 0x88 Remaining %04X kb",reg_ax); |
| 699 |
CALLBACK_SCF(false); |
| 700 |
break; |
| 701 |
case 0x89: /* SYSTEM - SWITCH TO PROTECTED MODE */ |
| 702 |
{ |
| 703 |
IO_Write(0x20,0x10);IO_Write(0x21,reg_bh);IO_Write(0x21,0); |
| 704 |
IO_Write(0xA0,0x10);IO_Write(0xA1,reg_bl);IO_Write(0xA1,0); |
| 705 |
MEM_A20_Enable(true); |
| 706 |
PhysPt table=SegPhys(es)+reg_si; |
| 707 |
CPU_LGDT(mem_readw(table+0x8),mem_readd(table+0x8+0x2) & 0xFFFFFF); |
| 708 |
CPU_LIDT(mem_readw(table+0x10),mem_readd(table+0x10+0x2) & 0xFFFFFF); |
| 709 |
CPU_SET_CRX(0,CPU_GET_CRX(0)|1); |
| 710 |
CPU_SetSegGeneral(ds,0x18); |
| 711 |
CPU_SetSegGeneral(es,0x20); |
| 712 |
CPU_SetSegGeneral(ss,0x28); |
| 713 |
reg_sp+=6; //Clear stack of interrupt frame |
| 714 |
CPU_SetFlags(0,FMASK_ALL); |
| 715 |
reg_ax=0; |
| 716 |
CPU_JMP(false,0x30,reg_cx,0); |
| 717 |
} |
| 718 |
break; |
| 719 |
case 0x90: /* OS HOOK - DEVICE BUSY */ |
| 720 |
CALLBACK_SCF(false); |
| 721 |
reg_ah=0; |
| 722 |
break; |
| 723 |
case 0x91: /* OS HOOK - DEVICE POST */ |
| 724 |
CALLBACK_SCF(false); |
| 725 |
reg_ah=0; |
| 726 |
break; |
| 727 |
case 0xc2: /* BIOS PS2 Pointing Device Support */ |
| 728 |
switch (reg_al) { |
| 729 |
case 0x00: // enable/disable |
| 730 |
if (reg_bh==0) { // disable |
| 731 |
Mouse_SetPS2State(false); |
| 732 |
reg_ah=0; |
| 733 |
CALLBACK_SCF(false); |
| 734 |
} else if (reg_bh==0x01) { //enable |
| 735 |
if (!Mouse_SetPS2State(true)) { |
| 736 |
reg_ah=5; |
| 737 |
CALLBACK_SCF(true); |
| 738 |
break; |
| 739 |
} |
| 740 |
reg_ah=0; |
| 741 |
CALLBACK_SCF(false); |
| 742 |
} else { |
| 743 |
CALLBACK_SCF(true); |
| 744 |
reg_ah=1; |
| 745 |
} |
| 746 |
break; |
| 747 |
case 0x01: // reset |
| 748 |
reg_bx=0x00aa; // mouse |
| 749 |
// fall through |
| 750 |
case 0x05: // initialize |
| 751 |
Mouse_SetPS2State(false); |
| 752 |
CALLBACK_SCF(false); |
| 753 |
reg_ah=0; |
| 754 |
break; |
| 755 |
case 0x02: // set sampling rate |
| 756 |
case 0x03: // set resolution |
| 757 |
CALLBACK_SCF(false); |
| 758 |
reg_ah=0; |
| 759 |
break; |
| 760 |
case 0x04: // get type |
| 761 |
reg_bh=0; // ID |
| 762 |
CALLBACK_SCF(false); |
| 763 |
reg_ah=0; |
| 764 |
break; |
| 765 |
case 0x06: // extended commands |
| 766 |
if ((reg_bh==0x01) || (reg_bh==0x02)) { |
| 767 |
CALLBACK_SCF(false); |
| 768 |
reg_ah=0; |
| 769 |
} else { |
| 770 |
CALLBACK_SCF(true); |
| 771 |
reg_ah=1; |
| 772 |
} |
| 773 |
break; |
| 774 |
case 0x07: // set callback |
| 775 |
Mouse_ChangePS2Callback(SegValue(es),reg_bx); |
| 776 |
CALLBACK_SCF(false); |
| 777 |
reg_ah=0; |
| 778 |
break; |
| 779 |
default: |
| 780 |
CALLBACK_SCF(true); |
| 781 |
reg_ah=1; |
| 782 |
break; |
| 783 |
} |
| 784 |
break; |
| 785 |
case 0xc3: /* set carry flag so BorlandRTM doesn't assume a VECTRA/PS2 */ |
| 786 |
reg_ah=0x86; |
| 787 |
CALLBACK_SCF(true); |
| 788 |
break; |
| 789 |
case 0xc4: /* BIOS POS Programm option Select */ |
| 790 |
LOG(LOG_BIOS,LOG_NORMAL)("INT15:Function %X called, bios mouse not supported",reg_ah); |
| 791 |
CALLBACK_SCF(true); |
| 792 |
break; |
| 793 |
default: |
| 794 |
LOG(LOG_BIOS,LOG_ERROR)("INT15:Unknown call %4X",reg_ax); |
| 795 |
reg_ah=0x86; |
| 796 |
CALLBACK_SCF(true); |
| 797 |
if ((IS_EGAVGA_ARCH) || (machine==MCH_CGA)) { |
| 798 |
/* relict from comparisons, as int15 exits with a retf2 instead of an iret */ |
| 799 |
CALLBACK_SZF(false); |
| 800 |
} |
| 801 |
} |
| 802 |
return CBRET_NONE; |
| 803 |
} |
| 804 |
|
| 805 |
static Bitu Reboot_Handler(void) { |
| 806 |
// switch to text mode, notify user (let's hope INT10 still works) |
| 807 |
const char* const text = "\n\n Reboot requested, quitting now."; |
| 808 |
reg_ax = 0; |
| 809 |
CALLBACK_RunRealInt(0x10); |
| 810 |
reg_ah = 0xe; |
| 811 |
reg_bx = 0; |
| 812 |
for(Bitu i = 0; i < strlen(text);i++) { |
| 813 |
reg_al = text[i]; |
| 814 |
CALLBACK_RunRealInt(0x10); |
| 815 |
} |
| 816 |
LOG_MSG(text); |
| 817 |
double start = PIC_FullIndex(); |
| 818 |
while((PIC_FullIndex()-start)<3000) CALLBACK_Idle(); |
| 819 |
throw 1; |
| 820 |
return CBRET_NONE; |
| 821 |
} |
| 822 |
|
| 823 |
void BIOS_ZeroExtendedSize(bool in) { |
| 824 |
if(in) other_memsystems++; |
| 825 |
else other_memsystems--; |
| 826 |
if(other_memsystems < 0) other_memsystems=0; |
| 827 |
} |
| 828 |
|
| 829 |
void BIOS_SetupKeyboard(void); |
| 830 |
void BIOS_SetupDisks(void); |
| 831 |
|
| 832 |
class BIOS:public Module_base{ |
| 833 |
private: |
| 834 |
CALLBACK_HandlerObject callback[11]; |
| 835 |
public: |
| 836 |
BIOS(Section* configuration):Module_base(configuration){ |
| 837 |
/* tandy DAC can be requested in tandy_sound.cpp by initializing this field */ |
| 838 |
bool use_tandyDAC=(real_readb(0x40,0xd4)==0xff); |
| 839 |
|
| 840 |
/* Clear the Bios Data Area (0x400-0x5ff, 0x600- is accounted to DOS) */ |
| 841 |
for (Bit16u i=0;i<0x200;i++) real_writeb(0x40,i,0); |
| 842 |
|
| 843 |
/* Setup all the interrupt handlers the bios controls */ |
| 844 |
|
| 845 |
/* INT 8 Clock IRQ Handler */ |
| 846 |
Bitu call_irq0=CALLBACK_Allocate(); |
| 847 |
CALLBACK_Setup(call_irq0,INT8_Handler,CB_IRQ0,Real2Phys(BIOS_DEFAULT_IRQ0_LOCATION),"IRQ 0 Clock"); |
| 848 |
RealSetVec(0x08,BIOS_DEFAULT_IRQ0_LOCATION); |
| 849 |
// pseudocode for CB_IRQ0: |
| 850 |
// callback INT8_Handler |
| 851 |
// push ax,dx,ds |
| 852 |
// int 0x1c |
| 853 |
// cli |
| 854 |
// pop ds,dx |
| 855 |
// mov al, 0x20 |
| 856 |
// out 0x20, al |
| 857 |
// pop ax |
| 858 |
// iret |
| 859 |
|
| 860 |
mem_writed(BIOS_TIMER,0); //Calculate the correct time |
| 861 |
|
| 862 |
/* INT 11 Get equipment list */ |
| 863 |
callback[1].Install(&INT11_Handler,CB_IRET,"Int 11 Equipment"); |
| 864 |
callback[1].Set_RealVec(0x11); |
| 865 |
|
| 866 |
/* INT 12 Memory Size default at 640 kb */ |
| 867 |
callback[2].Install(&INT12_Handler,CB_IRET,"Int 12 Memory"); |
| 868 |
callback[2].Set_RealVec(0x12); |
| 869 |
if (IS_TANDY_ARCH) { |
| 870 |
/* reduce reported memory size for the Tandy (32k graphics memory |
| 871 |
at the end of the conventional 640k) */ |
| 872 |
if (machine==MCH_TANDY) mem_writew(BIOS_MEMORY_SIZE,608); |
| 873 |
else mem_writew(BIOS_MEMORY_SIZE,640); |
| 874 |
mem_writew(BIOS_TRUE_MEMORY_SIZE,640); |
| 875 |
} else mem_writew(BIOS_MEMORY_SIZE,640); |
| 876 |
|
| 877 |
/* INT 13 Bios Disk Support */ |
| 878 |
BIOS_SetupDisks(); |
| 879 |
|
| 880 |
/* INT 14 Serial Ports */ |
| 881 |
callback[3].Install(&INT14_Handler,CB_IRET_STI,"Int 14 COM-port"); |
| 882 |
callback[3].Set_RealVec(0x14); |
| 883 |
|
| 884 |
/* INT 15 Misc Calls */ |
| 885 |
callback[4].Install(&INT15_Handler,CB_IRET,"Int 15 Bios"); |
| 886 |
callback[4].Set_RealVec(0x15); |
| 887 |
|
| 888 |
/* INT 16 Keyboard handled in another file */ |
| 889 |
BIOS_SetupKeyboard(); |
| 890 |
|
| 891 |
/* INT 17 Printer Routines */ |
| 892 |
callback[5].Install(&INT17_Handler,CB_IRET_STI,"Int 17 Printer"); |
| 893 |
callback[5].Set_RealVec(0x17); |
| 894 |
|
| 895 |
/* INT 1A TIME and some other functions */ |
| 896 |
callback[6].Install(&INT1A_Handler,CB_IRET_STI,"Int 1a Time"); |
| 897 |
callback[6].Set_RealVec(0x1A); |
| 898 |
|
| 899 |
/* INT 1C System Timer tick called from INT 8 */ |
| 900 |
callback[7].Install(&INT1C_Handler,CB_IRET,"Int 1c Timer"); |
| 901 |
callback[7].Set_RealVec(0x1C); |
| 902 |
|
| 903 |
/* IRQ 8 RTC Handler */ |
| 904 |
callback[8].Install(&INT70_Handler,CB_IRET,"Int 70 RTC"); |
| 905 |
callback[8].Set_RealVec(0x70); |
| 906 |
|
| 907 |
/* Irq 9 rerouted to irq 2 */ |
| 908 |
callback[9].Install(NULL,CB_IRQ9,"irq 9 bios"); |
| 909 |
callback[9].Set_RealVec(0x71); |
| 910 |
|
| 911 |
/* Reboot */ |
| 912 |
callback[10].Install(&Reboot_Handler,CB_IRET,"reboot"); |
| 913 |
callback[10].Set_RealVec(0x18); |
| 914 |
RealPt rptr = callback[10].Get_RealPointer(); |
| 915 |
RealSetVec(0x19,rptr); |
| 916 |
// set system BIOS entry point too |
| 917 |
phys_writeb(0xFFFF0,0xEA); // FARJMP |
| 918 |
phys_writew(0xFFFF1,RealOff(rptr)); // offset |
| 919 |
phys_writew(0xFFFF3,RealSeg(rptr)); // segment |
| 920 |
|
| 921 |
/* Irq 2 */ |
| 922 |
Bitu call_irq2=CALLBACK_Allocate(); |
| 923 |
CALLBACK_Setup(call_irq2,NULL,CB_IRET_EOI_PIC1,Real2Phys(BIOS_DEFAULT_IRQ2_LOCATION),"irq 2 bios"); |
| 924 |
RealSetVec(0x0a,BIOS_DEFAULT_IRQ2_LOCATION); |
| 925 |
|
| 926 |
/* Some hardcoded vectors */ |
| 927 |
phys_writeb(Real2Phys(BIOS_DEFAULT_HANDLER_LOCATION),0xcf); /* bios default interrupt vector location -> IRET */ |
| 928 |
phys_writew(Real2Phys(RealGetVec(0x12))+0x12,0x20); //Hack for Jurresic |
| 929 |
|
| 930 |
if (machine==MCH_TANDY) phys_writeb(0xffffe,0xff) ; /* Tandy model */ |
| 931 |
else if (machine==MCH_PCJR) phys_writeb(0xffffe,0xfd); /* PCJr model */ |
| 932 |
else phys_writeb(0xffffe,0xfc); /* PC */ |
| 933 |
|
| 934 |
// System BIOS identification |
| 935 |
const char* const b_type = |
| 936 |
"IBM COMPATIBLE 486 BIOS COPYRIGHT The DOSBox Team."; |
| 937 |
for(Bitu i = 0; i < strlen(b_type); i++) phys_writeb(0xfe00e + i,b_type[i]); |
| 938 |
|
| 939 |
// System BIOS version |
| 940 |
const char* const b_vers = |
| 941 |
"DOSBox FakeBIOS v1.0"; |
| 942 |
for(Bitu i = 0; i < strlen(b_vers); i++) phys_writeb(0xfe061+i,b_vers[i]); |
| 943 |
|
| 944 |
// write system BIOS date |
| 945 |
const char* const b_date = "01/01/92"; |
| 946 |
for(Bitu i = 0; i < strlen(b_date); i++) phys_writeb(0xffff5+i,b_date[i]); |
| 947 |
phys_writeb(0xfffff,0x55); // signature |
| 948 |
|
| 949 |
tandy_sb.port=0; |
| 950 |
tandy_dac.port=0; |
| 951 |
if (use_tandyDAC) { |
| 952 |
/* tandy DAC sound requested, see if soundblaster device is available */ |
| 953 |
Bitu tandy_dac_type = 0; |
| 954 |
if (Tandy_InitializeSB()) { |
| 955 |
tandy_dac_type = 1; |
| 956 |
} else if (Tandy_InitializeTS()) { |
| 957 |
tandy_dac_type = 2; |
| 958 |
} |
| 959 |
if (tandy_dac_type) { |
| 960 |
real_writew(0x40,0xd0,0x0000); |
| 961 |
real_writew(0x40,0xd2,0x0000); |
| 962 |
real_writeb(0x40,0xd4,0xff); /* tandy DAC init value */ |
| 963 |
real_writed(0x40,0xd6,0x00000000); |
| 964 |
/* install the DAC callback handler */ |
| 965 |
tandy_DAC_callback[0]=new CALLBACK_HandlerObject(); |
| 966 |
tandy_DAC_callback[1]=new CALLBACK_HandlerObject(); |
| 967 |
tandy_DAC_callback[0]->Install(&IRQ_TandyDAC,CB_IRET,"Tandy DAC IRQ"); |
| 968 |
tandy_DAC_callback[1]->Install(NULL,CB_TDE_IRET,"Tandy DAC end transfer"); |
| 969 |
// pseudocode for CB_TDE_IRET: |
| 970 |
// push ax |
| 971 |
// mov ax, 0x91fb |
| 972 |
// int 15 |
| 973 |
// cli |
| 974 |
// mov al, 0x20 |
| 975 |
// out 0x20, al |
| 976 |
// pop ax |
| 977 |
// iret |
| 978 |
|
| 979 |
Bit8u tandy_irq = 7; |
| 980 |
if (tandy_dac_type==1) tandy_irq = tandy_sb.irq; |
| 981 |
else if (tandy_dac_type==2) tandy_irq = tandy_dac.irq; |
| 982 |
Bit8u tandy_irq_vector = tandy_irq; |
| 983 |
if (tandy_irq_vector<8) tandy_irq_vector += 8; |
| 984 |
else tandy_irq_vector += (0x70-8); |
| 985 |
|
| 986 |
RealPt current_irq=RealGetVec(tandy_irq_vector); |
| 987 |
real_writed(0x40,0xd6,current_irq); |
| 988 |
for (Bit16u i=0; i<0x10; i++) phys_writeb(PhysMake(0xf000,0xa084+i),0x80); |
| 989 |
} else real_writeb(0x40,0xd4,0x00); |
| 990 |
} |
| 991 |
|
| 992 |
/* Setup some stuff in 0x40 bios segment */ |
| 993 |
|
| 994 |
// port timeouts |
| 995 |
// always 1 second even if the port does not exist |
| 996 |
mem_writeb(BIOS_LPT1_TIMEOUT,1); |
| 997 |
mem_writeb(BIOS_LPT2_TIMEOUT,1); |
| 998 |
mem_writeb(BIOS_LPT3_TIMEOUT,1); |
| 999 |
mem_writeb(BIOS_COM1_TIMEOUT,1); |
| 1000 |
mem_writeb(BIOS_COM2_TIMEOUT,1); |
| 1001 |
mem_writeb(BIOS_COM3_TIMEOUT,1); |
| 1002 |
mem_writeb(BIOS_COM4_TIMEOUT,1); |
| 1003 |
|
| 1004 |
/* detect parallel ports */ |
| 1005 |
Bitu ppindex=0; // number of lpt ports |
| 1006 |
if ((IO_Read(0x378)!=0xff)|(IO_Read(0x379)!=0xff)) { |
| 1007 |
// this is our LPT1 |
| 1008 |
mem_writew(BIOS_ADDRESS_LPT1,0x378); |
| 1009 |
ppindex++; |
| 1010 |
if((IO_Read(0x278)!=0xff)|(IO_Read(0x279)!=0xff)) { |
| 1011 |
// this is our LPT2 |
| 1012 |
mem_writew(BIOS_ADDRESS_LPT2,0x278); |
| 1013 |
ppindex++; |
| 1014 |
if((IO_Read(0x3bc)!=0xff)|(IO_Read(0x3be)!=0xff)) { |
| 1015 |
// this is our LPT3 |
| 1016 |
mem_writew(BIOS_ADDRESS_LPT3,0x3bc); |
| 1017 |
ppindex++; |
| 1018 |
} |
| 1019 |
} else if((IO_Read(0x3bc)!=0xff)|(IO_Read(0x3be)!=0xff)) { |
| 1020 |
// this is our LPT2 |
| 1021 |
mem_writew(BIOS_ADDRESS_LPT2,0x3bc); |
| 1022 |
ppindex++; |
| 1023 |
} |
| 1024 |
} else if((IO_Read(0x3bc)!=0xff)|(IO_Read(0x3be)!=0xff)) { |
| 1025 |
// this is our LPT1 |
| 1026 |
mem_writew(BIOS_ADDRESS_LPT1,0x3bc); |
| 1027 |
ppindex++; |
| 1028 |
if((IO_Read(0x278)!=0xff)|(IO_Read(0x279)!=0xff)) { |
| 1029 |
// this is our LPT2 |
| 1030 |
mem_writew(BIOS_ADDRESS_LPT2,0x278); |
| 1031 |
ppindex++; |
| 1032 |
} |
| 1033 |
} else if((IO_Read(0x278)!=0xff)|(IO_Read(0x279)!=0xff)) { |
| 1034 |
// this is our LPT1 |
| 1035 |
mem_writew(BIOS_ADDRESS_LPT1,0x278); |
| 1036 |
ppindex++; |
| 1037 |
} |
| 1038 |
|
| 1039 |
/* Setup equipment list */ |
| 1040 |
// look http://www.bioscentral.com/misc/bda.htm |
| 1041 |
|
| 1042 |
//Bit16u config=0x4400; //1 Floppy, 2 serial and 1 parallel |
| 1043 |
Bit16u config = 0x0; |
| 1044 |
|
| 1045 |
// set number of parallel ports |
| 1046 |
// if(ppindex == 0) config |= 0x8000; // looks like 0 ports are not specified |
| 1047 |
//else if(ppindex == 1) config |= 0x0000; |
| 1048 |
if(ppindex == 2) config |= 0x4000; |
| 1049 |
else config |= 0xc000; // 3 ports |
| 1050 |
#if (C_FPU) |
| 1051 |
//FPU |
| 1052 |
config|=0x2; |
| 1053 |
#endif |
| 1054 |
switch (machine) { |
| 1055 |
case MCH_HERC: |
| 1056 |
//Startup monochrome |
| 1057 |
config|=0x30; |
| 1058 |
break; |
| 1059 |
case EGAVGA_ARCH_CASE: |
| 1060 |
case MCH_CGA: |
| 1061 |
case TANDY_ARCH_CASE: |
| 1062 |
//Startup 80x25 color |
| 1063 |
config|=0x20; |
| 1064 |
break; |
| 1065 |
default: |
| 1066 |
//EGA VGA |
| 1067 |
config|=0; |
| 1068 |
break; |
| 1069 |
} |
| 1070 |
// PS2 mouse |
| 1071 |
config |= 0x04; |
| 1072 |
// Gameport |
| 1073 |
config |= 0x1000; |
| 1074 |
mem_writew(BIOS_CONFIGURATION,config); |
| 1075 |
CMOS_SetRegister(0x14,(Bit8u)(config&0xff)); //Should be updated on changes |
| 1076 |
/* Setup extended memory size */ |
| 1077 |
IO_Write(0x70,0x30); |
| 1078 |
size_extended=IO_Read(0x71); |
| 1079 |
IO_Write(0x70,0x31); |
| 1080 |
size_extended|=(IO_Read(0x71) << 8); |
| 1081 |
} |
| 1082 |
~BIOS(){ |
| 1083 |
/* abort DAC playing */ |
| 1084 |
if (tandy_sb.port) { |
| 1085 |
IO_Write(tandy_sb.port+0xc,0xd3); |
| 1086 |
IO_Write(tandy_sb.port+0xc,0xd0); |
| 1087 |
} |
| 1088 |
real_writeb(0x40,0xd4,0x00); |
| 1089 |
if (tandy_DAC_callback[0]) { |
| 1090 |
Bit32u orig_vector=real_readd(0x40,0xd6); |
| 1091 |
if (orig_vector==tandy_DAC_callback[0]->Get_RealPointer()) { |
| 1092 |
/* set IRQ vector to old value */ |
| 1093 |
Bit8u tandy_irq = 7; |
| 1094 |
if (tandy_sb.port) tandy_irq = tandy_sb.irq; |
| 1095 |
else if (tandy_dac.port) tandy_irq = tandy_dac.irq; |
| 1096 |
Bit8u tandy_irq_vector = tandy_irq; |
| 1097 |
if (tandy_irq_vector<8) tandy_irq_vector += 8; |
| 1098 |
else tandy_irq_vector += (0x70-8); |
| 1099 |
|
| 1100 |
RealSetVec(tandy_irq_vector,real_readd(0x40,0xd6)); |
| 1101 |
real_writed(0x40,0xd6,0x00000000); |
| 1102 |
} |
| 1103 |
delete tandy_DAC_callback[0]; |
| 1104 |
delete tandy_DAC_callback[1]; |
| 1105 |
tandy_DAC_callback[0]=NULL; |
| 1106 |
tandy_DAC_callback[1]=NULL; |
| 1107 |
} |
| 1108 |
} |
| 1109 |
}; |
| 1110 |
|
| 1111 |
// set com port data in bios data area |
| 1112 |
// parameter: array of 4 com port base addresses, 0 = none |
| 1113 |
void BIOS_SetComPorts(Bit16u baseaddr[]) { |
| 1114 |
Bit16u portcount=0; |
| 1115 |
Bit16u equipmentword; |
| 1116 |
for(Bitu i = 0; i < 4; i++) { |
| 1117 |
if(baseaddr[i]!=0) portcount++; |
| 1118 |
if(i==0) mem_writew(BIOS_BASE_ADDRESS_COM1,baseaddr[i]); |
| 1119 |
else if(i==1) mem_writew(BIOS_BASE_ADDRESS_COM2,baseaddr[i]); |
| 1120 |
else if(i==2) mem_writew(BIOS_BASE_ADDRESS_COM3,baseaddr[i]); |
| 1121 |
else mem_writew(BIOS_BASE_ADDRESS_COM4,baseaddr[i]); |
| 1122 |
} |
| 1123 |
// set equipment word |
| 1124 |
equipmentword = mem_readw(BIOS_CONFIGURATION); |
| 1125 |
equipmentword &= (~0x0E00); |
| 1126 |
equipmentword |= (portcount << 9); |
| 1127 |
mem_writew(BIOS_CONFIGURATION,equipmentword); |
| 1128 |
CMOS_SetRegister(0x14,(Bit8u)(equipmentword&0xff)); //Should be updated on changes |
| 1129 |
} |
| 1130 |
|
| 1131 |
|
| 1132 |
static BIOS* test; |
| 1133 |
|
| 1134 |
void BIOS_Destroy(Section* /*sec*/){ |
| 1135 |
delete test; |
| 1136 |
} |
| 1137 |
|
| 1138 |
void BIOS_Init(Section* sec) { |
| 1139 |
test = new BIOS(sec); |
| 1140 |
sec->AddDestroyFunction(&BIOS_Destroy,false); |
| 1141 |
} |