|
|
| version 1.60, 2004/03/19 00:30:00 | version 1.76, 2005/05/20 13:59:46 |
|---|---|
| Line 8 | Line 8 |
| #include "biosmem.h" | #include "biosmem.h" |
| #include "sxsibios.h" | #include "sxsibios.h" |
| #include "lio.h" | #include "lio.h" |
| #include "vram.h" | |
| #include "fddfile.h" | #include "fddfile.h" |
| #include "fdd_mtr.h" | #include "fdd_mtr.h" |
| #include "fdfmt.h" | #include "fdfmt.h" |
| Line 19 | Line 20 |
| #define BIOS_SIMULATE | #define BIOS_SIMULATE |
| BOOL biosrom = FALSE; | |
| static const char neccheck[] = "Copyright (C) 1983 by NEC Corporation"; | static const char neccheck[] = "Copyright (C) 1983 by NEC Corporation"; |
| typedef struct { | typedef struct { |
| Line 57 const IODATA *pterm; | Line 56 const IODATA *pterm; |
| gdc_biosreset(); | gdc_biosreset(); |
| p = iodata; | p = iodata; |
| pterm = iodata + (sizeof(iodata) / sizeof(IODATA)); | pterm = iodata + NELEMENTS(iodata); |
| while(p < pterm) { | while(p < pterm) { |
| iocore_out8(p->port, p->data); | iocore_out8(p->port, p->data); |
| p++; | p++; |
| Line 66 const IODATA *pterm; | Line 65 const IODATA *pterm; |
| static void bios_memclear(void) { | static void bios_memclear(void) { |
| ZeroMemory(mem + 0x400, 0xa0000 - 0x400); | ZeroMemory(mem, 0xa0000); |
| ZeroMemory(mem + 0x100000, 0x10000); | ZeroMemory(mem + 0x100000, 0x10000); |
| if (CPU_EXTMEM) { | if (CPU_EXTMEM) { |
| ZeroMemory(CPU_EXTMEM, CPU_EXTMEMSIZE); | ZeroMemory(CPU_EXTMEM, CPU_EXTMEMSIZE); |
| Line 76 static void bios_memclear(void) { | Line 75 static void bios_memclear(void) { |
| ZeroMemory(mem + VRAM0_E, 0x08000); | ZeroMemory(mem + VRAM0_E, 0x08000); |
| ZeroMemory(mem + VRAM1_B, 0x18000); | ZeroMemory(mem + VRAM1_B, 0x18000); |
| ZeroMemory(mem + VRAM1_E, 0x08000); | ZeroMemory(mem + VRAM1_E, 0x08000); |
| #if defined(SUPPORT_PC9821) | |
| ZeroMemory(vramex, sizeof(vramex)); | |
| #endif | |
| } | } |
| static void bios_reinitbyswitch(void) { | static void bios_reinitbyswitch(void) { |
| BYTE prxcrt; | UINT8 prxcrt; |
| BYTE prxdupd; | UINT8 prxdupd; |
| BYTE biosflag; | UINT8 biosflag; |
| UINT8 extmem; | |
| UINT8 boot; | UINT8 boot; |
| if (!(np2cfg.dipsw[2] & 0x80)) { | if (!(np2cfg.dipsw[2] & 0x80)) { |
| Line 130 static void bios_reinitbyswitch(void) { | Line 133 static void bios_reinitbyswitch(void) { |
| biosflag |= 0x40; | biosflag |= 0x40; |
| } | } |
| mem[MEMB_BIOS_FLAG1] = biosflag; | mem[MEMB_BIOS_FLAG1] = biosflag; |
| mem[MEMB_EXPMMSZ] = (BYTE)(pccore.extmem << 3); | extmem = pccore.extmem; |
| extmem = min(extmem, 14); | |
| mem[MEMB_EXPMMSZ] = (UINT8)(extmem << 3); | |
| if (pccore.extmem >= 15) { | |
| mem[0x0594] = pccore.extmem - 15; | |
| } | |
| mem[MEMB_CRT_RASTER] = 0x0f; | mem[MEMB_CRT_RASTER] = 0x0f; |
| // FDD initialize | // FDD initialize |
| Line 145 static void bios_reinitbyswitch(void) { | Line 153 static void bios_reinitbyswitch(void) { |
| fddbios_equip(0, TRUE); | fddbios_equip(0, TRUE); |
| mem[MEMB_BIOS_FLAG0] &= ~0x02; | mem[MEMB_BIOS_FLAG0] &= ~0x02; |
| } | } |
| mem[MEMB_F2HD_MODE] = 0xff; | |
| mem[MEMB_F2DD_MODE] = 0xff; | mem[MEMB_F2DD_MODE] = 0xff; |
| #if defined(SUPPORT_CRT31KHZ) | #if defined(SUPPORT_CRT31KHZ) |
| mem[MEMB_CRT_BIOS] = 0x80; | mem[MEMB_CRT_BIOS] |= 0x80; |
| #endif | #endif |
| #if defined(SUPPORT_PC9821) | #if defined(SUPPORT_PC9821) |
| mem[MEMB_CRT_BIOS] |= 0x04; // 05/02/03 | |
| mem[0x45c] = 0x40; | mem[0x45c] = 0x40; |
| #endif | #endif |
| Line 188 static void bios_screeninit(void) { | Line 198 static void bios_screeninit(void) { |
| bios0x18_0a(al); | bios0x18_0a(al); |
| } | } |
| static void setbiosseed(UINT8 *ptr, UINT size, UINT seedpos) { | |
| UINT8 x; | |
| UINT8 y; | |
| UINT i; | |
| x = 0; | |
| y = 0; | |
| for (i=0; i<size; i+=2) { | |
| x += ptr[i + 0]; | |
| y += ptr[i + 1]; | |
| } | |
| ptr[seedpos + 0] -= x; | |
| ptr[seedpos + 1] -= y; | |
| } | |
| void bios_initialize(void) { | void bios_initialize(void) { |
| char path[MAX_PATH]; | BOOL biosrom; |
| OEMCHAR path[MAX_PATH]; | |
| FILEH fh; | FILEH fh; |
| UINT i; | UINT i; |
| UINT32 tmp; | UINT32 tmp; |
| UINT pos; | UINT pos; |
| biosrom = FALSE; | biosrom = FALSE; |
| getbiospath(path, str_biosrom, sizeof(path)); | getbiospath(path, str_biosrom, NELEMENTS(path)); |
| fh = file_open_rb(path); | fh = file_open_rb(path); |
| if (fh != FILEH_INVALID) { | if (fh != FILEH_INVALID) { |
| biosrom = (file_read(fh, mem + 0x0e8000, 0x18000) == 0x18000); | biosrom = (file_read(fh, mem + 0x0e8000, 0x18000) == 0x18000); |
| Line 206 void bios_initialize(void) { | Line 232 void bios_initialize(void) { |
| } | } |
| if (biosrom) { | if (biosrom) { |
| TRACEOUT(("load bios.rom")); | TRACEOUT(("load bios.rom")); |
| pccore.rom |= PCROM_BIOS; | |
| // PnP BIOSを潰す | // PnP BIOSを潰す |
| for (i=0; i<0x10000; i+=0x10) { | for (i=0; i<0x10000; i+=0x10) { |
| tmp = LOADINTELDWORD(mem + 0xf0000 + i); | tmp = LOADINTELDWORD(mem + 0xf0000 + i); |
| if (tmp == 0x506e5024) { | if (tmp == 0x506e5024) { |
| TRACEOUT(("found PnP BIOS at %.5x", 0xf0000 + i)); | TRACEOUT(("found PnP BIOS at %.5x", 0xf0000 + i)); |
| STOREINTELDWORD(mem + 0xf0000 + i, 0x32504e24); | mem[0xf0000 + i] = 0x6e; |
| mem[0xf0002 + i] = 0x24; | |
| break; | |
| } | } |
| } | } |
| } | } |
| else { | else { |
| CopyMemory(mem + 0x0e8000, nosyscode, sizeof(nosyscode)); | CopyMemory(mem + 0x0e8000, nosyscode, sizeof(nosyscode)); |
| if ((!biosrom) && (!(pccore.model & PCMODEL_EPSON))) { | |
| CopyMemory(mem + 0xe8dd8, neccheck, 0x25); | |
| pos = LOADINTELWORD(itfrom + 2); | |
| CopyMemory(mem + 0xf538e, itfrom + pos, 0x27); | |
| } | |
| setbiosseed(mem + 0x0e8000, 0x10000, 0xb1f0); | |
| } | } |
| #if defined(SUPPORT_PC9821) | #if defined(SUPPORT_PC9821) |
| getbiospath(path, "bios9821.rom", sizeof(path)); | getbiospath(path, OEMTEXT("bios9821.rom"), sizeof(path)); |
| fh = file_open_rb(path); | fh = file_open_rb(path); |
| if (fh != FILEH_INVALID) { | if (fh != FILEH_INVALID) { |
| if (file_read(fh, mem + 0x0d8000, 0x2000) == 0x2000) { | if (file_read(fh, mem + 0x0d8000, 0x2000) == 0x2000) { |
| Line 230 void bios_initialize(void) { | Line 265 void bios_initialize(void) { |
| } | } |
| file_close(fh); | file_close(fh); |
| } | } |
| #if defined(BIOS_SIMULATE) | |
| mem[0xf8e80] = 0x98; | |
| mem[0xf8e81] = 0x21; | |
| mem[0xf8e82] = 0x1f; | |
| mem[0xf8e83] = 0x20; // Model Number? | |
| mem[0xf8e84] = 0x2c; | |
| mem[0xf8e85] = 0xb0; | |
| // mem[0xf8eaf] = 0x21; // <- これって何だっけ? | |
| #endif | |
| #endif | #endif |
| #if defined(BIOS_SIMULATE) | #if defined(BIOS_SIMULATE) |
| Line 252 void bios_initialize(void) { | Line 297 void bios_initialize(void) { |
| mem[0xffff0] = 0xea; | mem[0xffff0] = 0xea; |
| STOREINTELDWORD(mem + 0xffff1, 0xfd800000); | STOREINTELDWORD(mem + 0xffff1, 0xfd800000); |
| if ((!biosrom) && (!(pccore.model & PCMODEL_EPSON))) { | CopyMemory(mem + 0x0fd800 + 0x0e00, keytable[0], 0x300); |
| CopyMemory(mem + 0xe8dd8, neccheck, 0x25); | |
| pos = LOADINTELWORD(itfrom + 2); | |
| CopyMemory(mem + 0xf538e, itfrom + pos, 0x27); | |
| } | |
| CopyMemory(mem + 0x0fde00, keytable[0], 0x300); | |
| CopyMemory(mem + ITF_ADRS, itfrom, sizeof(itfrom)); | CopyMemory(mem + ITF_ADRS, itfrom, sizeof(itfrom)); |
| mem[ITF_ADRS + 0x7ff0] = 0xea; | mem[ITF_ADRS + 0x7ff0] = 0xea; |
| Line 269 void bios_initialize(void) { | Line 308 void bios_initialize(void) { |
| else if ((pccore.model & PCMODELMASK) == PCMODEL_VM) { | else if ((pccore.model & PCMODELMASK) == PCMODEL_VM) { |
| mem[ITF_ADRS + 0x7ff1] = 0x08; | mem[ITF_ADRS + 0x7ff1] = 0x08; |
| } | } |
| setbiosseed(mem + 0x0f8000, 0x08000, 0x7ffe); | |
| #else | #else |
| fh = file_open_c("itf.rom"); | fh = file_open_c("itf.rom"); |
| if (fh != FILEH_INVALID) { | if (fh != FILEH_INVALID) { |
| Line 296 static void bios_itfcall(void) { | Line 336 static void bios_itfcall(void) { |
| if (!np2cfg.ITF_WORK) { | if (!np2cfg.ITF_WORK) { |
| for (i=0; i<8; i++) { | for (i=0; i<8; i++) { |
| mem[MEMB_MSW + (i*4)] = msw_default[i]; | mem[MEMX_MSW + (i*4)] = msw_default[i]; |
| } | } |
| CPU_FLAGL |= C_FLAG; | CPU_FLAGL |= C_FLAG; |
| } | } |
| Line 324 UINT MEMCALL biosfunc(UINT32 adrs) { | Line 364 UINT MEMCALL biosfunc(UINT32 adrs) { |
| // TRACEOUT(("biosfunc(%x)", adrs)); | // TRACEOUT(("biosfunc(%x)", adrs)); |
| #if defined(CPUCORE_IA32) && defined(TRACE) | #if defined(CPUCORE_IA32) && defined(TRACE) |
| if (CPU_STAT_PAGING) { | if (CPU_STAT_PAGING) { |
| UINT32 pde = i286_memoryread_d(CPU_STAT_PDE_BASE); | UINT32 pde = MEMP_READ32(CPU_STAT_PDE_BASE); |
| if (!(pde & CPU_PDE_PRESENT)) { | if (!(pde & CPU_PDE_PRESENT)) { |
| TRACEOUT(("page0: PTE not present")); | TRACEOUT(("page0: PTE not present")); |
| } | } |
| else { | else { |
| UINT32 pte = i286_memoryread_d(pde & CPU_PDE_BASEADDR_MASK); | UINT32 pte = MEMP_READ32(pde & CPU_PDE_BASEADDR_MASK); |
| if (!(pte & CPU_PTE_PRESENT)) { | if (!(pte & CPU_PTE_PRESENT)) { |
| TRACEOUT(("page0: not present")); | TRACEOUT(("page0: not present")); |
| } | } |
| Line 346 UINT MEMCALL biosfunc(UINT32 adrs) { | Line 386 UINT MEMCALL biosfunc(UINT32 adrs) { |
| return(1); | return(1); |
| case BIOS_BASE + BIOSOFST_INIT: // ブート | case BIOS_BASE + BIOSOFST_INIT: // ブート |
| #if 1 // for RanceII | |
| bios_memclear(); | |
| #endif | |
| bios_vectorset(); | |
| #if 1 | |
| bios0x09_init(); | |
| #endif | |
| bios_reinitbyswitch(); | bios_reinitbyswitch(); |
| bios_vectorset(); | bios_vectorset(); |
| bios_screeninit(); | bios_screeninit(); |
| Line 357 UINT MEMCALL biosfunc(UINT32 adrs) { | Line 404 UINT MEMCALL biosfunc(UINT32 adrs) { |
| return(1); | return(1); |
| case BIOS_BASE + BIOSOFST_09: | case BIOS_BASE + BIOSOFST_09: |
| CPU_REMCLOCK -= 300; | CPU_REMCLOCK -= 500; |
| bios0x09(); | bios0x09(); |
| return(1); | return(1); |
| Line 389 UINT MEMCALL biosfunc(UINT32 adrs) { | Line 436 UINT MEMCALL biosfunc(UINT32 adrs) { |
| case BIOS_BASE + BIOSOFST_CMT: | case BIOS_BASE + BIOSOFST_CMT: |
| CPU_REMCLOCK -= 200; | CPU_REMCLOCK -= 200; |
| bios0x1a_cmt(); | bios0x1a_cmt(); |
| return(1); | return(0); // return(1); |
| case BIOS_BASE + BIOSOFST_PRT: | case BIOS_BASE + BIOSOFST_PRT: |
| CPU_REMCLOCK -= 200; | CPU_REMCLOCK -= 200; |
| Line 414 UINT MEMCALL biosfunc(UINT32 adrs) { | Line 461 UINT MEMCALL biosfunc(UINT32 adrs) { |
| case BIOS_BASE + BIOSOFST_WAIT: | case BIOS_BASE + BIOSOFST_WAIT: |
| CPU_STI; | CPU_STI; |
| if (fddmtr.busy) { | return(bios0x1b_wait()); // ver0.78 |
| CPU_IP--; | |
| CPU_REMCLOCK = -1; | |
| } | |
| else { | |
| if (fdc.chgreg & 1) { | |
| if (!(mem[0x0055e] & (0x01 << fdc.us))) { | |
| CPU_IP--; | |
| CPU_REMCLOCK -= 1000; | |
| } | |
| } | |
| else { | |
| if (!(mem[0x0055f] & (0x10 << fdc.us))) { | |
| CPU_IP--; | |
| CPU_REMCLOCK -= 1000; | |
| } | |
| } | |
| } | |
| return(1); | |
| case 0xfffe8: // ブートストラップロード | case 0xfffe8: // ブートストラップロード |
| CPU_REMCLOCK -= 2000; | CPU_REMCLOCK -= 2000; |
| Line 451 UINT MEMCALL biosfunc(UINT32 adrs) { | Line 480 UINT MEMCALL biosfunc(UINT32 adrs) { |
| return(0); | return(0); |
| } | } |
| if ((adrs >= 0xf9a00) && (adrs < 0x0f9a44)) { | if ((adrs >= 0xf9950) && (adrs <= 0x0f9990) && (!(adrs & 3))) { |
| if (!(adrs & 3)) { | CPU_REMCLOCK -= 500; |
| CPU_REMCLOCK -= 500; | bios_lio((REG8)((adrs - 0xf9950) >> 2)); |
| bios_lio((REG8)((adrs - 0xf9a00) >> 2)); | } |
| } | else if (adrs == 0xf9994) { |
| else { | if (nevent_iswork(NEVENT_GDCSLAVE)) { |
| if (nevent_iswork(NEVENT_GDCSLAVE)) { | CPU_IP--; |
| CPU_IP--; | CPU_REMCLOCK = -1; |
| CPU_REMCLOCK = -1; | return(1); |
| return(1); | |
| } | |
| } | } |
| return(0); | |
| } | } |
| return(0); | return(0); |
| } | } |