From 90d6d74f99cad3f06b2596e1a77f6d53cfc27446 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Strohh=C3=A4cker?= Date: Sun, 4 Dec 2005 21:17:29 +0000 Subject: [PATCH] add PCJr-compatible keyboard layer; add support for PCJr cartridges Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@2402 --- src/dos/dos_programs.cpp | 81 ++++++++++++++++++++------------------ src/hardware/keyboard.cpp | 5 ++- src/hardware/pic.cpp | 17 ++++++-- src/ints/bios.cpp | 12 +++++- src/ints/bios_keyboard.cpp | 22 ++++++++++- 5 files changed, 91 insertions(+), 46 deletions(-) diff --git a/src/dos/dos_programs.cpp b/src/dos/dos_programs.cpp index b7a94690..423ace13 100644 --- a/src/dos/dos_programs.cpp +++ b/src/dos/dos_programs.cpp @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: dos_programs.cpp,v 1.47 2005-11-28 16:12:30 qbix79 Exp $ */ +/* $Id: dos_programs.cpp,v 1.48 2005-12-04 21:17:28 c2woody Exp $ */ #include #include @@ -440,49 +440,53 @@ public: return; } - WriteOut(MSG_Get("PROGRAM_BOOT_BOOT"), drive); - bootSector bootarea; imageDiskList[drive-65]->Read_Sector(0,0,1,(Bit8u *)&bootarea); - for(i=0;i<512;i++) real_writeb(0, 0x7c00 + i, bootarea.rawdata[i]); + if ((bootarea.rawdata[0]==0x50) && (bootarea.rawdata[1]==0x43) && (bootarea.rawdata[2]==0x6a) && (bootarea.rawdata[3]==0x72)) { + if (machine!=MCH_PCJR) WriteOut(MSG_Get("PROGRAM_BOOT_CART_WO_PCJR")); + else { + Bit8u rombuf[65536]; + fseek(usefile,0x200L, SEEK_SET); + fread(rombuf, 1, rombytesize-0x200, usefile); + fclose(usefile); - + /* write cartridge data into ROM */ + Bit16u romseg=0xe000; + if ((rombuf[7]==0x42) && (rombuf[8]==0x41) && (rombuf[9]==0x53) && (rombuf[10]==0x49)) { + /* BASIC rom, doesn't work though */ + romseg=0xf600; + } + for(i=0;i @@ -47,6 +47,7 @@ struct PIC_Controller { bool special; bool auto_eoi; bool rotate_on_auto_eoi; + bool single; bool request_issr; Bit8u vector_base; }; @@ -79,11 +80,11 @@ static void write_command(Bitu port,Bitu val,Bitu iolen) { static Bit16u IRQ_priority_table[16] = { 0,1,2,8,9,10,11,12,13,14,15,3,4,5,6,7 }; if (GCC_UNLIKELY(val&0x10)) { // ICW1 issued - if (val&0x02) E_Exit("PIC: single mode not handled"); // (would have to skip ICW3) if (val&0x04) E_Exit("PIC: 4 byte interval not handled"); if (val&0x08) E_Exit("PIC: level triggered mode not handled"); if (val&0xe0) E_Exit("PIC: 8080/8085 mode not handled"); - pic->icw_index=1; // next is ICW3 + pic->single=val&0x02; + pic->icw_index=1; // next is ICW2 pic->icw_words=2 + (val&0x01); // =3 if ICW4 needed } else if (GCC_UNLIKELY(val&0x08)) { // OCW3 issued if (val&0x04) E_Exit("PIC: poll command not handled"); @@ -160,6 +161,10 @@ static void write_data(Bitu port,Bitu val,Bitu iolen) { else PIC_IRQCheck&=~(1 << (i+irq_base)); } } + if (machine==MCH_PCJR) { + /* irq6 cannot be disabled as it serves as pseudo-NMI */ + irqs[6].masked=false; + } if(irqs[2].masked != old_irq2_mask) { /* Irq 2 mask has changed recheck second pic */ for(i=8;i<=15;i++) { @@ -178,6 +183,7 @@ static void write_data(Bitu port,Bitu val,Bitu iolen) { irqs[i+irq_base].vector=(val&0xf8)+i; }; if(pic->icw_index++ >= pic->icw_words) pic->icw_index=0; + else if(pic->single) pic->icw_index=3; /* skip ICW3 in single mode */ break; case 2: /* icw 3 */ LOG(LOG_PIC,LOG_NORMAL)("%d:ICW 3 %X",port==0x21 ? 0 : 1,val); @@ -525,6 +531,7 @@ public: pics[i].rotate_on_auto_eoi=false; pics[i].request_issr=false; pics[i].special=false; + pics[i].single=false; pics[i].icw_index=0; pics[i].icw_words=0; } @@ -542,6 +549,10 @@ public: irqs[1].masked=false; /* Enable Keyboard IRQ */ irqs[2].masked=false; /* Enable second pic */ irqs[8].masked=false; /* Enable RTC IRQ */ + if (machine==MCH_PCJR) { + /* Enable IRQ6 (replacement for the NMI for PCJr) */ + irqs[6].masked=false; + } ReadHandler[0].Install(0x20,read_command,IO_MB); ReadHandler[1].Install(0x21,read_data,IO_MB); WriteHandler[0].Install(0x20,write_command,IO_MB); diff --git a/src/ints/bios.cpp b/src/ints/bios.cpp index 76f8191f..a07aeb1d 100644 --- a/src/ints/bios.cpp +++ b/src/ints/bios.cpp @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: bios.cpp,v 1.52 2005-12-02 13:10:18 c2woody Exp $ */ +/* $Id: bios.cpp,v 1.53 2005-12-04 21:17:29 c2woody Exp $ */ #include "dosbox.h" #include "mem.h" @@ -789,6 +789,13 @@ void BIOS_ZeroExtendedSize(bool in) { if(other_memsystems < 0) other_memsystems=0; } +#define RAM_REFRESH_DELAY 16.7f + +static void RAMRefresh_Event(Bitu val) { + PIC_ActivateIRQ(5); + PIC_AddEvent(RAMRefresh_Event,RAM_REFRESH_DELAY); +} + void BIOS_SetupKeyboard(void); void BIOS_SetupDisks(void); @@ -964,7 +971,8 @@ public: IO_Write(0x70,0x30); size_extended=IO_Read(0x71); IO_Write(0x70,0x31); - size_extended|=(IO_Read(0x71) << 8); + size_extended|=(IO_Read(0x71) << 8); + if (machine==MCH_PCJR) PIC_AddEvent(RAMRefresh_Event,RAM_REFRESH_DELAY); } ~BIOS(){ /* abort DAC playing */ diff --git a/src/ints/bios_keyboard.cpp b/src/ints/bios_keyboard.cpp index 2928ded1..341c969d 100644 --- a/src/ints/bios_keyboard.cpp +++ b/src/ints/bios_keyboard.cpp @@ -25,7 +25,7 @@ #include "inout.h" -static Bitu call_int16,call_irq1; +static Bitu call_int16,call_irq1,call_irq6; /* Nice table from BOCHS i should feel bad for ripping this */ #define none 0 @@ -438,6 +438,21 @@ irq1_return: return CBRET_NONE; } +static bool pcjr_extended_key=false; + +static Bitu IRQ6_Handler(void) { + Bit8u scancode=IO_Read(0x60); + Bit16u old_ax=reg_ax; + if (pcjr_extended_key) reg_ax=scancode<<8; + else reg_al=scancode; + pcjr_extended_key=(scancode==0xe0); + /* call the real keyboard IRQ now, with the scancode in AL */ + CALLBACK_RunRealInt(0x09); + reg_ax=old_ax; + IO_Write(0x20,0x20); + return CBRET_NONE; +} + /* check whether key combination is enhanced or not, translate key if necessary */ static bool IsEnhancedKey(Bit16u &key) { @@ -592,6 +607,11 @@ void BIOS_SetupKeyboard(void) { RealSetVec(0x16,CALLBACK_RealPointer(call_int16)); CALLBACK_Setup(call_irq1,&IRQ1_Handler,CB_IRET,"keyboard irq"); RealSetVec(0x9,CALLBACK_RealPointer(call_irq1)); + if (machine==MCH_PCJR) { + call_irq6=CALLBACK_Allocate(); + CALLBACK_Setup(call_irq6,&IRQ6_Handler,CB_IRET,"PCJr kb irq"); + RealSetVec(0x0e,CALLBACK_RealPointer(call_irq6)); + } /* bring the all port operations outside the callback */ phys_writeb(CB_BASE+(call_irq1<<4)+0x00,(Bit8u)0x50); // push ax