diff --git a/bochs/bx_debug/dbg_main.cc b/bochs/bx_debug/dbg_main.cc index bb82c5e26..f22bcd6f0 100644 --- a/bochs/bx_debug/dbg_main.cc +++ b/bochs/bx_debug/dbg_main.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: dbg_main.cc,v 1.112 2008-02-15 19:03:53 sshwarts Exp $ +// $Id: dbg_main.cc,v 1.113 2008-02-15 22:05:38 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -375,8 +375,8 @@ void bx_get_command(void) } // look for first non-whitespace character - while (((*tmp_buf_ptr == ' ') || (*tmp_buf_ptr == '\t')) && - (*tmp_buf_ptr != '\n') && (*tmp_buf_ptr != 0) ) + while (((*tmp_buf_ptr == ' ') || (*tmp_buf_ptr == '\t')) && + (*tmp_buf_ptr != '\n') && (*tmp_buf_ptr != 0)) { tmp_buf_ptr++; } diff --git a/bochs/config.cc b/bochs/config.cc index 769b008d9..90c05be5b 100755 --- a/bochs/config.cc +++ b/bochs/config.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: config.cc,v 1.131 2008-02-15 19:03:52 sshwarts Exp $ +// $Id: config.cc,v 1.132 2008-02-15 22:05:37 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2002 MandrakeSoft S.A. @@ -1774,7 +1774,7 @@ static const char *get_builtin_variable(const char *varname) data[0] = 0; size = MAX_PATH; if (RegQueryValueEx(hkey, "", NULL, (LPDWORD)&type, (LPBYTE)data, - (LPDWORD)&size ) == ERROR_SUCCESS) { + (LPDWORD)&size) == ERROR_SUCCESS) { RegCloseKey(hkey); return data; } else { @@ -3047,7 +3047,7 @@ static Bit32s parse_line_formatted(const char *context, int num_params, char *pa } else { - PARSE_ERR(( "%s: directive '%s' not understood", context, params[0])); + PARSE_ERR(("%s: directive '%s' not understood", context, params[0])); } return 0; } diff --git a/bochs/cpu/cpu.cc b/bochs/cpu/cpu.cc index 78254aff9..3e704a8ad 100644 --- a/bochs/cpu/cpu.cc +++ b/bochs/cpu/cpu.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: cpu.cc,v 1.206 2008-02-02 21:46:49 sshwarts Exp $ +// $Id: cpu.cc,v 1.207 2008-02-15 22:05:39 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -531,12 +531,12 @@ unsigned BX_CPU_C::handleAsyncEvent(void) // will be processed on the next boundary. BX_CPU_THIS_PTR inhibit_mask = 0; - if ( !(BX_CPU_INTR || - BX_CPU_THIS_PTR debug_trap || - BX_HRQ || - BX_CPU_THIS_PTR get_TF() + if (!(BX_CPU_INTR || + BX_CPU_THIS_PTR debug_trap || + BX_HRQ || + BX_CPU_THIS_PTR get_TF() #if BX_X86_DEBUGGER - || (BX_CPU_THIS_PTR dr7 & 0xff) + || (BX_CPU_THIS_PTR dr7 & 0xff) #endif )) BX_CPU_THIS_PTR async_event = 0; diff --git a/bochs/cpu/cpu.h b/bochs/cpu/cpu.h index 55a8a194a..ab4c120db 100644 --- a/bochs/cpu/cpu.h +++ b/bochs/cpu/cpu.h @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: cpu.h,v 1.427 2008-02-15 19:03:53 sshwarts Exp $ +// $Id: cpu.h,v 1.428 2008-02-15 22:05:40 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -941,13 +941,13 @@ public: // for now... #define ArithmeticalFlag(flag, lfMask, eflagsBitShift) \ BX_SMF bx_bool get_##flag##Lazy(void); \ BX_SMF bx_bool getB_##flag(void) { \ - if ( (BX_CPU_THIS_PTR lf_flags_status & (lfMask)) == 0) \ + if ((BX_CPU_THIS_PTR lf_flags_status & (lfMask)) == 0) \ return (BX_CPU_THIS_PTR eflags >> eflagsBitShift) & 1; \ else \ return !!get_##flag##Lazy(); \ } \ BX_SMF bx_bool get_##flag(void) { \ - if ( (BX_CPU_THIS_PTR lf_flags_status & (lfMask)) == 0) \ + if ((BX_CPU_THIS_PTR lf_flags_status & (lfMask)) == 0) \ return BX_CPU_THIS_PTR eflags & (lfMask); \ else \ return get_##flag##Lazy(); \ @@ -966,7 +966,7 @@ public: // for now... BX_CPU_THIS_PTR eflags |= (lfMask); \ } \ BX_SMF void force_##flag(void) { \ - if ( (BX_CPU_THIS_PTR lf_flags_status & (lfMask)) != 0) { \ + if ((BX_CPU_THIS_PTR lf_flags_status & (lfMask)) != 0) { \ set_##flag(!!get_##flag##Lazy()); \ } \ } diff --git a/bochs/cpu/exception.cc b/bochs/cpu/exception.cc index 5a779d668..b8c9c7e43 100644 --- a/bochs/cpu/exception.cc +++ b/bochs/cpu/exception.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: exception.cc,v 1.100 2008-02-02 21:46:50 sshwarts Exp $ +// $Id: exception.cc,v 1.101 2008-02-15 22:05:40 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -71,7 +71,7 @@ void BX_CPU_C::long_mode_int(Bit8u vector, bx_bool is_INT, bx_bool is_error_code // interrupt vector must be within IDT table limits, // else #GP(vector number*16 + 2 + EXT) idtindex = vector*16; - if ( (idtindex + 15) > BX_CPU_THIS_PTR idtr.limit) { + if ((idtindex + 15) > BX_CPU_THIS_PTR idtr.limit) { BX_ERROR(("interrupt(long mode): vector > idtr.limit")); BX_ERROR(("IDT.limit = %04x", (unsigned) BX_CPU_THIS_PTR idtr.limit)); BX_ERROR(("IDT.base = %06x", (unsigned) BX_CPU_THIS_PTR idtr.base)); @@ -295,7 +295,7 @@ void BX_CPU_C::protected_mode_int(Bit8u vector, bx_bool is_INT, bx_bool is_error // interrupt vector must be within IDT table limits, // else #GP(vector number*8 + 2 + EXT) - if ( (vector*8 + 7) > BX_CPU_THIS_PTR idtr.limit) { + if ((vector*8 + 7) > BX_CPU_THIS_PTR idtr.limit) { BX_DEBUG(("IDT.limit = %04x", (unsigned) BX_CPU_THIS_PTR idtr.limit)); BX_DEBUG(("IDT.base = %06x", (unsigned) BX_CPU_THIS_PTR idtr.base)); BX_DEBUG(("interrupt vector must be within IDT table limits")); diff --git a/bochs/cpu/io_pro.cc b/bochs/cpu/io_pro.cc index 7d16dada0..c2218c4e9 100644 --- a/bochs/cpu/io_pro.cc +++ b/bochs/cpu/io_pro.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: io_pro.cc,v 1.28 2008-02-02 21:46:51 sshwarts Exp $ +// $Id: io_pro.cc,v 1.29 2008-02-15 22:05:40 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -132,7 +132,7 @@ bx_bool BX_CPU_C::allow_io(Bit16u addr, unsigned len) return(0); } - if ( (Bit32s) (addr/8) >= (Bit32s) (BX_CPU_THIS_PTR tr.cache.u.system.limit_scaled - io_base)) { + if ((Bit32s) (addr/8) >= (Bit32s) (BX_CPU_THIS_PTR tr.cache.u.system.limit_scaled - io_base)) { BX_ERROR(("allow_io(): IO addr %x (len %d) outside TSS IO permission map (base=%x, limit=%x) #GP(0)", addr, len, io_base, BX_CPU_THIS_PTR tr.cache.u.system.limit_scaled)); return(0); diff --git a/bochs/cpu/proc_ctrl.cc b/bochs/cpu/proc_ctrl.cc index b4b3204c1..127e01236 100644 --- a/bochs/cpu/proc_ctrl.cc +++ b/bochs/cpu/proc_ctrl.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: proc_ctrl.cc,v 1.202 2008-02-15 19:03:53 sshwarts Exp $ +// $Id: proc_ctrl.cc,v 1.203 2008-02-15 22:05:40 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -301,24 +301,24 @@ void BX_CPU_C::MOV_DdRd(bxInstruction_c *i) // Note: processor clears GD upon entering debug exception // handler, to allow access to the debug registers } - if ( (((val_32>>16) & 3)==2) || - (((val_32>>20) & 3)==2) || - (((val_32>>24) & 3)==2) || - (((val_32>>28) & 3)==2)) { + if ((((val_32>>16) & 3)==2) || + (((val_32>>20) & 3)==2) || + (((val_32>>24) & 3)==2) || + (((val_32>>28) & 3)==2)) { // IO breakpoints (10b) are not yet supported. BX_PANIC(("MOV_DdRd: write of %08x contains IO breakpoint", val_32)); } - if ( (((val_32>>18) & 3)==2) || - (((val_32>>22) & 3)==2) || - (((val_32>>26) & 3)==2) || - (((val_32>>30) & 3)==2)) { + if ((((val_32>>18) & 3)==2) || + (((val_32>>22) & 3)==2) || + (((val_32>>26) & 3)==2) || + (((val_32>>30) & 3)==2)) { // LEN0..3 contains undefined length specifier (10b) BX_PANIC(("MOV_DdRd: write of %08x contains undefined LENx", val_32)); } - if ( ((((val_32>>16) & 3)==0) && (((val_32>>18) & 3)!=0)) || - ((((val_32>>20) & 3)==0) && (((val_32>>22) & 3)!=0)) || - ((((val_32>>24) & 3)==0) && (((val_32>>26) & 3)!=0)) || - ((((val_32>>28) & 3)==0) && (((val_32>>30) & 3)!=0))) + if (((((val_32>>16) & 3)==0) && (((val_32>>18) & 3)!=0)) || + ((((val_32>>20) & 3)==0) && (((val_32>>22) & 3)!=0)) || + ((((val_32>>24) & 3)==0) && (((val_32>>26) & 3)!=0)) || + ((((val_32>>28) & 3)==0) && (((val_32>>30) & 3)!=0))) { // Instruction breakpoint with LENx not 00b (1-byte length) BX_PANIC(("MOV_DdRd: write of %08x, R/W=00b LEN!=00b", val_32)); @@ -486,28 +486,28 @@ void BX_CPU_C::MOV_DqRq(bxInstruction_c *i) // Note: processor clears GD upon entering debug exception // handler, to allow access to the debug registers } - if ( (((val_64>>16) & 3)==2) || - (((val_64>>20) & 3)==2) || - (((val_64>>24) & 3)==2) || - (((val_64>>28) & 3)==2)) + if ((((val_64>>16) & 3)==2) || + (((val_64>>20) & 3)==2) || + (((val_64>>24) & 3)==2) || + (((val_64>>28) & 3)==2)) { // IO breakpoints (10b) are not yet supported. BX_PANIC(("MOV_DqRq: write of %08x:%08x contains IO breakpoint", (Bit32u)(val_64 >> 32), (Bit32u)(val_64 & 0xFFFFFFFF))); } - if ( (((val_64>>18) & 3)==2) || - (((val_64>>22) & 3)==2) || - (((val_64>>26) & 3)==2) || - (((val_64>>30) & 3)==2)) + if ((((val_64>>18) & 3)==2) || + (((val_64>>22) & 3)==2) || + (((val_64>>26) & 3)==2) || + (((val_64>>30) & 3)==2)) { // LEN0..3 contains undefined length specifier (10b) BX_PANIC(("MOV_DqRq: write of %08x:%08x contains undefined LENx", (Bit32u)(val_64 >> 32), (Bit32u)(val_64 & 0xFFFFFFFF))); } - if ( ((((val_64>>16) & 3)==0) && (((val_64>>18) & 3)!=0)) || - ((((val_64>>20) & 3)==0) && (((val_64>>22) & 3)!=0)) || - ((((val_64>>24) & 3)==0) && (((val_64>>26) & 3)!=0)) || - ((((val_64>>28) & 3)==0) && (((val_64>>30) & 3)!=0))) + if (((((val_64>>16) & 3)==0) && (((val_64>>18) & 3)!=0)) || + ((((val_64>>20) & 3)==0) && (((val_64>>22) & 3)!=0)) || + ((((val_64>>24) & 3)==0) && (((val_64>>26) & 3)!=0)) || + ((((val_64>>28) & 3)==0) && (((val_64>>30) & 3)!=0))) { // Instruction breakpoint with LENx not 00b (1-byte length) BX_PANIC(("MOV_DqRq: write of %08x:%08x , R/W=00b LEN!=00b", diff --git a/bochs/cpu/segment_ctrl_pro.cc b/bochs/cpu/segment_ctrl_pro.cc index e43062ca6..a721f503a 100644 --- a/bochs/cpu/segment_ctrl_pro.cc +++ b/bochs/cpu/segment_ctrl_pro.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: segment_ctrl_pro.cc,v 1.81 2008-02-02 21:46:53 sshwarts Exp $ +// $Id: segment_ctrl_pro.cc,v 1.82 2008-02-15 22:05:40 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -114,11 +114,11 @@ BX_CPU_C::load_seg_reg(bx_segment_reg_t *seg, Bit16u new_value) return; } - else if ( (seg==&BX_CPU_THIS_PTR sregs[BX_SEG_REG_DS]) || - (seg==&BX_CPU_THIS_PTR sregs[BX_SEG_REG_ES]) + else if ((seg==&BX_CPU_THIS_PTR sregs[BX_SEG_REG_DS]) || + (seg==&BX_CPU_THIS_PTR sregs[BX_SEG_REG_ES]) #if BX_CPU_LEVEL >= 3 - || (seg==&BX_CPU_THIS_PTR sregs[BX_SEG_REG_FS]) || - (seg==&BX_CPU_THIS_PTR sregs[BX_SEG_REG_GS]) + || (seg==&BX_CPU_THIS_PTR sregs[BX_SEG_REG_FS]) || + (seg==&BX_CPU_THIS_PTR sregs[BX_SEG_REG_GS]) #endif ) { diff --git a/bochs/gui/amigaos.cc b/bochs/gui/amigaos.cc index db08841e5..5e876a8d8 100644 --- a/bochs/gui/amigaos.cc +++ b/bochs/gui/amigaos.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: amigaos.cc,v 1.25 2008-02-05 22:57:41 sshwarts Exp $ +// $Id: amigaos.cc,v 1.26 2008-02-15 22:05:40 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2000 MandrakeSoft S.A. @@ -23,7 +23,7 @@ // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - +///////////////////////////////////////////////////////////////////////// // Define BX_PLUGGABLE in files that can be compiled into plugins. For // platforms that require a special tag on exported symbols, BX_PLUGGABLE @@ -62,587 +62,556 @@ static ULONG screenreqfunc(struct Hook *hook, struct ScreenModeRequester *smr, U return IsCyberModeID(id); } -LONG DispatcherFunc(void) { - struct Hook *hook = (Hook *)REG_A0; - return (*(LONG(*)(struct Hook *,LONG,LONG))hook->h_SubEntry)(hook,REG_A2,REG_A1); +LONG DispatcherFunc(void) +{ + struct Hook *hook = (Hook *)REG_A0; + return (*(LONG(*)(struct Hook *,LONG,LONG))hook->h_SubEntry)(hook,REG_A2,REG_A1); } -struct InputEvent * -MyInputHandler(void) +struct InputEvent *MyInputHandler(void) { - struct InputEvent *event = (struct InputEvent *)REG_A0; + struct InputEvent *event = (struct InputEvent *)REG_A0; - if (SIM->get_param_bool(BXPN_MOUSE_ENABLED)->get()) - { - switch(event->ie_Code) - { - case IECODE_LBUTTON: - { - mouse_button_state |= 0x01; - DEV_mouse_motion(event->ie_position.ie_xy.ie_x, -event->ie_position.ie_xy.ie_y, mouse_button_state); - - return NULL; - } - - case (IECODE_LBUTTON | IECODE_UP_PREFIX): - { - mouse_button_state &= ~0x01; - DEV_mouse_motion(event->ie_position.ie_xy.ie_x, -event->ie_position.ie_xy.ie_y, mouse_button_state); - return NULL; - } - - case IECODE_RBUTTON: - { - mouse_button_state |= 0x02; - DEV_mouse_motion(event->ie_position.ie_xy.ie_x, -event->ie_position.ie_xy.ie_y, mouse_button_state); - return NULL; - } - - case (IECODE_RBUTTON | IECODE_UP_PREFIX): - { - mouse_button_state &= 0x01; - DEV_mouse_motion(event->ie_position.ie_xy.ie_x, -event->ie_position.ie_xy.ie_y, mouse_button_state); - return NULL; - } - } - - if (event->ie_Class == IECLASS_RAWMOUSE) - { - DEV_mouse_motion(event->ie_position.ie_xy.ie_x, -event->ie_position.ie_xy.ie_y, mouse_button_state); - return NULL; - } - - return (event); - } - return (event); -} - -void -setup_inputhandler(void) -{ - - static struct EmulLibEntry GATEMyInputHandler= - { - TRAP_LIB, 0, (void (*)(void))MyInputHandler - }; - - - if (inputPort=CreateMsgPort()) - { - if (inputHandler=(struct Interrupt *)AllocMem(sizeof(struct Interrupt), - MEMF_PUBLIC|MEMF_CLEAR)) - { - if (inputReqBlk=(struct IOStdReq *)CreateIORequest(inputPort, - sizeof(struct IOStdReq))) - { - if (!(input_error = OpenDevice("input.device",NULL, - (struct IORequest *)inputReqBlk,NULL))) - { - inputHandler->is_Code=(void(*)())&GATEMyInputHandler; - inputHandler->is_Data=NULL; - inputHandler->is_Node.ln_Pri=100; - inputHandler->is_Node.ln_Name=HandlerName; - inputReqBlk->io_Data=(APTR)inputHandler; - inputReqBlk->io_Command=IND_ADDHANDLER; - DoIO((struct IORequest *)inputReqBlk); - } - else - BX_PANIC(("Amiga: Could not open input.device")); - } - else - BX_PANIC(("Amiga: Could not create I/O request")); - } - else - BX_PANIC(("Amiga: Could not allocate interrupt struct memory")); - } - else - printf(("Amiga: Could not create message port")); -} - -bx_bool -open_screen(void) -{ - - ULONG id = INVALID_ID; - - char *scrmode; - struct DrawInfo *screen_drawinfo = NULL; - - struct ScreenModeRequester *smr; - - static struct EmulLibEntry GATEDispatcherFunc= - { - TRAP_LIB, 0, (void (*)(void))DispatcherFunc - }; - - struct Hook screenreqhook = { 0, 0, (ULONG(*)())&GATEDispatcherFunc, (ULONG(*)())screenreqfunc, 0 }; - - sprintf (verstr, "Bochs x86 Emulator %s", VER_STRING); - - - if (SIM->get_param_bool(BXPN_FULLSCREEN)->get()) - { - if((scrmode = SIM->get_param_string(BXPN_SCREENMODE)->getptr())) - { - id = strtoul(scrmode, NULL, 0); - if (!IsCyberModeID(id)) id = INVALID_ID; - } - - if (id == INVALID_ID) - { - if (smr = (ScreenModeRequester *)AllocAslRequestTags(ASL_ScreenModeRequest, - ASLSM_DoWidth, TRUE, - ASLSM_DoHeight, TRUE, - ASLSM_MinDepth, 8, - ASLSM_MaxDepth, 32, - ASLSM_PropertyFlags, DIPF_IS_WB, - ASLSM_PropertyMask, DIPF_IS_WB, - ASLSM_FilterFunc, (ULONG) &screenreqhook, - TAG_DONE)) - { - if (AslRequest(smr, NULL)) - { - id = smr->sm_DisplayID; - FreeAslRequest(smr); - } - else - { - FreeAslRequest(smr); - BX_PANIC(("Amiga: Can't start without a screen")); - } - } - } - - h = GetCyberIDAttr(CYBRIDATTR_HEIGHT, id); - w = GetCyberIDAttr(CYBRIDATTR_WIDTH, id); - d = GetCyberIDAttr(CYBRIDATTR_DEPTH, id); - - //sprintf(scrmode, "%d", id); - //setenv("env:bochs/screenmode", scrmode, 1); - - - screen = OpenScreenTags(NULL, - SA_Width, w, - SA_Height, h, - SA_Depth, d, - SA_Title, verstr, - SA_DisplayID, id, - SA_ShowTitle, FALSE, - SA_Type, PUBLICSCREEN, - SA_SharePens, TRUE, - TAG_DONE); - - if(!screen) - BX_PANIC(("Amiga: Couldn't open screen")); - - window = OpenWindowTags(NULL, - WA_CustomScreen,(int)screen, - WA_Width,w, - WA_Height,h, - WA_Title, verstr, - WA_IDCMP, IDCMP_RAWKEY | IDCMP_GADGETUP | IDCMP_INACTIVEWINDOW, - WA_ReportMouse, TRUE, - WA_RMBTrap, TRUE, - WA_Backdrop,TRUE, - WA_Borderless,TRUE, - WA_Activate,TRUE, - TAG_DONE); - } - else - { - pub_screen = LockPubScreen(NULL); - if (pub_screen != NULL ) - { - screen_drawinfo = GetScreenDrawInfo(pub_screen); - if ( screen_drawinfo != NULL) - { - id = GetVPModeID(&pub_screen->ViewPort); - d = GetCyberIDAttr(CYBRIDATTR_DEPTH, id); - } else { - UnlockPubScreen(NULL,pub_screen); - BX_PANIC(("Amiga: Couldn't get ScreenDrawInfo")); - } - - window = OpenWindowTags(NULL, - WA_Width,w, - WA_Height,h, - WA_Title, verstr, - WA_IDCMP, IDCMP_RAWKEY | IDCMP_GADGETUP | IDCMP_CHANGEWINDOW | IDCMP_INACTIVEWINDOW, - WA_RMBTrap, TRUE, - WA_DepthGadget, TRUE, - WA_ReportMouse, TRUE, - WA_DragBar, TRUE, - WA_Activate,TRUE, - TAG_DONE); - - UnlockPubScreen(NULL,pub_screen); - } - else - BX_PANIC(("Amiga: Couldn't lock the public screen")); - } - - if (!window) - BX_PANIC(("Amiga: Couldn't open the window")); - - if ((emptypointer = (UWORD *)AllocVec (16, MEMF_CLEAR)) == NULL) - BX_PANIC(("Amiga: Couldn't allocate memory")); - - vgafont = OpenDiskFont(&vgata); - - if (SIM->get_param_bool(BXPN_MOUSE_ENABLED)->get()) - hide_pointer(); - - if(!vgafont) - BX_PANIC(("Amiga: Couldn't open the vga font")); - - SetFont(window->RPort, vgafont); - - if (NULL == (vi = GetVisualInfo(window->WScreen, TAG_END))) - BX_PANIC(("Amiga: GetVisualInfo() failed")); - - bx_gadget_handle = CreateContext(&bx_glistptr); - - bx_bordertop = window->BorderTop; - bx_borderleft = window->BorderLeft; - bx_borderright = window->BorderRight; - bx_borderbottom = window->BorderBottom; - bx_headernext_left = bx_borderleft; - bx_headernext_right += bx_borderright; - - for (apen = 0; apen < 256; apen++) /*fill the pen map with -1 so we can know which pens to free at exit*/ - pmap[apen] = -1; - - white = ObtainBestPen(window->WScreen->ViewPort.ColorMap, 0xffffffff, 0xffffffff, 0xffffffff, NULL); - black = ObtainBestPen(window->WScreen->ViewPort.ColorMap, 0x00000000, 0x00000000, 0x00000000, NULL); - -} - - void -bx_amigaos_gui_c::specific_init(int argc, char **argv, unsigned tilewidth, unsigned tileheight, - unsigned headerbar_y) -{ - - x_tilesize = tilewidth; - y_tilesize = tileheight; - - bx_headerbar_y = headerbar_y; - - IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 39); - if (IntuitionBase == NULL) - BX_PANIC(("Amiga: Failed to open intuition.library v39 or later!")); - if (IntuitionBase->LibNode.lib_Version == 50 && IntuitionBase->LibNode.lib_Revision < 5) - BX_PANIC(("Amiga: intuition.library v50 needs to be revision 5 or higher!")); - - - GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 39); - if (GfxBase == NULL) - BX_PANIC(("Amiga: Failed to open graphics.library v39 or later!")); - - GadToolsBase = OpenLibrary("gadtools.library", 37); - if (GadToolsBase == NULL) - BX_PANIC(("Amiga: Failed to open gadtools.library v37 or later!")); - if (GadToolsBase->lib_Version == 50 && GadToolsBase->lib_Revision < 3) - BX_PANIC(("Amiga: gadtools.library v50 needs to be revision 3 or higher!")); - - CyberGfxBase = OpenLibrary("cybergraphics.library", 40); - if (CyberGfxBase == NULL) - BX_PANIC(("Amiga: Failed to open cybergraphics.library v40 or later!")); - - AslBase = OpenLibrary("asl.library", 38); - if (AslBase == NULL) - BX_PANIC(("Amiga: Failed to open asl.library v38 or later!")); - - DiskfontBase = OpenLibrary("diskfont.library", 38); - if (DiskfontBase == NULL) - BX_PANIC(("Amiga: Failed to open diskfont.library v38 or later!")); - - IFFParseBase = OpenLibrary("iffparse.library", 39); - if (IFFParseBase == NULL) - BX_PANIC(("Amiga: Failed to open iffparse.library v39 or later!")); - - open_screen(); - setup_inputhandler(); - - if (SIM->get_param_bool(BXPN_PRIVATE_COLORMAP)->get()) { - BX_ERROR(("Amiga: private_colormap option ignored.")); - } -} - - - void -bx_amigaos_gui_c::handle_events(void) -{ - void (*func) (void); - struct IntuiMessage *imsg = NULL; - struct Gadget *gad; - ULONG imCode,imClass,imQualifier; - Bit32u key_event; - - while ((imsg = (struct IntuiMessage *)GetMsg(window->UserPort))) - { - gad = (struct Gadget *)imsg->IAddress; - key_event= 0; - - imClass = imsg->Class; - imCode = imsg->Code; - imQualifier = imsg->Qualifier; - - ReplyMsg((struct Message *)imsg); - - switch (imClass) - { - case IDCMP_RAWKEY: - if (imQualifier & IEQUALIFIER_LSHIFT && imQualifier & IEQUALIFIER_CONTROL && imQualifier & IEQUALIFIER_LCOMMAND) - { - toggle_mouse_enable(); - break; - } - - if(imCode <= 101) - key_event = raw_to_bochs[imCode]; - if(imCode >= 128) - key_event = raw_to_bochs[imCode-128] | BX_KEY_RELEASED; - if(key_event) - DEV_kbd_gen_scancode(key_event); - break; - - case GADGETUP: - ((void (*)()) bx_header_gadget[gad->GadgetID]->UserData)(); - break; - - case IDCMP_INACTIVEWINDOW: - if (SIM->get_param_bool(BXPN_MOUSE_ENABLED)->get()) - toggle_mouse_enable(); - break; - - case IDCMP_CHANGEWINDOW: - if(bx_xchanged) - { - bx_amigaos_gui_c::show_headerbar(); - bx_xchanged = FALSE; - } - break; - } - } -} - - - void -bx_amigaos_gui_c::flush(void) -{ -} - - void -bx_amigaos_gui_c::clear_screen(void) -{ - if (d > 8 || !SIM->get_param_bool(BXPN_FULLSCREEN)->get()) - SetAPen(window->RPort, black); - else - SetAPen(window->RPort, 0); /*should be ok to clear with the first pen in the map*/ - RectFill(window->RPort, bx_borderleft, bx_bordertop + bx_headerbar_y, window->Width - bx_borderright - 1, window->Height - bx_borderbottom - 1); -} - - void -bx_amigaos_gui_c::text_update(Bit8u *old_text, Bit8u *new_text, - unsigned long cursor_x, unsigned long cursor_y, - bx_vga_tminfo_t tm_info) -{ -int i; -int cursori; -unsigned nchars; -char achar; -char string[80]; -int x, y; -static int previ; -unsigned int fgcolor, bgcolor; - - //current cursor position - cursori = (cursor_y * text_cols + cursor_x) * 2; - - // Number of characters on screen, variable number of rows - nchars = text_cols * text_rows; - - for (i=0; i> 4; - - if (i == cursori) /*invert the cursor block*/ - { - SetAPen(window->RPort, pmap[bgcolor]); - SetBPen(window->RPort, pmap[fgcolor]); - } - else - { - SetAPen(window->RPort, pmap[fgcolor]); - SetBPen(window->RPort, pmap[bgcolor]); - } - - - x = ((i/2) % text_cols)*window->RPort->TxWidth; - y = ((i/2) / text_cols)*window->RPort->TxHeight; - - Move(window->RPort, bx_borderleft + x, bx_bordertop + bx_headerbar_y + y + window->RPort->TxBaseline); - Text(window->RPort, &achar, 1); - } - } - - previ = cursori; - -} - - int -bx_amigaos_gui_c::get_clipboard_text(Bit8u **bytes, Bit32s *nbytes) -{ - struct IFFHandle *iff = NULL; - long err = 0; - struct ContextNode *cn; - - - if (!(iff = AllocIFF ())) - { - BX_INFO(("Amiga: Failed to allocate iff handle")); - return 0; - } - - if (!(iff->iff_Stream = (ULONG) OpenClipboard (0))) - { - BX_INFO(("Amiga: Failed to open clipboard device")); - freeiff(iff); - return 0; - } - - InitIFFasClip (iff); - - if (err = OpenIFF (iff, IFFF_READ)) - { - BX_INFO(("Amiga: Failed to open clipboard for reading")); - freeiff(iff); - return 0; - } - - if (err = StopChunk(iff, ID_FTXT, ID_CHRS)) - { - BX_INFO(("Amiga: Failed StopChunk()")); - freeiff(iff); - return 0; - } - - while(1) - { - UBYTE readbuf[1024]; - int len = 0; - - err = ParseIFF(iff, IFFPARSE_SCAN); - if(err == IFFERR_EOC) continue; - else if(err) break; - - cn = CurrentChunk(iff); - - if((cn) && (cn->cn_Type == ID_FTXT) && (cn->cn_ID == ID_CHRS)) - { - while((len = ReadChunkBytes(iff,readbuf, 1024)) > 0) - { - Bit8u *buf = new Bit8u[len]; - memcpy (buf, readbuf, len); - *bytes = buf; - *nbytes = len; - } - if(len < 0) err = len; - } - } - - if((err) && (err != IFFERR_EOF)) - { - BX_INFO(("Amiga: Failed to read from clipboard")); - freeiff(iff); - return 0; - } - - freeiff(iff); - - return 1; -} - - int -bx_amigaos_gui_c::set_clipboard_text(char *text_snapshot, Bit32u len) -{ - struct IFFHandle *iff = NULL; - long err = 0; - - BX_INFO(("Amiga: set_clipboard_text")); - - if (!(iff = AllocIFF ())) - { - BX_INFO(("Amiga: Failed to allocate iff handle")); - return 0; - } - - if (!(iff->iff_Stream = (ULONG) OpenClipboard (0))) - { - BX_INFO(("Amiga: Failed to open clipboard device")); - freeiff(iff); - return 0; - } - - InitIFFasClip (iff); - - if (err = OpenIFF (iff, IFFF_WRITE)) - { - BX_INFO(("Amiga: Failed to open clipboard for writing")); - freeiff(iff); - return 0; - } - - if(!(err = PushChunk(iff, ID_FTXT, ID_FORM, IFFSIZE_UNKNOWN))) - { - if(!(err=PushChunk(iff, 0, ID_CHRS, IFFSIZE_UNKNOWN))) - { - if(WriteChunkBytes(iff, text_snapshot, len) != len) - err = IFFERR_WRITE; - } - if(!err) err = PopChunk(iff); - } - if(!err) err = PopChunk(iff); - - if(err) - { - BX_INFO(("Amiga: Failed to write text to clipboard")); - freeiff(iff); - return 0; - } - - freeiff(iff); - - return 1; -} - - bx_bool -bx_amigaos_gui_c::palette_change(unsigned index, unsigned red, unsigned green, unsigned blue) -{ - - Bit8u *ptr; - - ptr = (Bit8u *)(cmap+index); - - ptr++; /*first 8bits are not defined in the XRGB8 entry*/ - *ptr = red; ptr++; - *ptr = green; ptr++; - *ptr = blue; - - if (d > 8 || !SIM->get_param_bool(BXPN_FULLSCREEN)->get()) + if (SIM->get_param_bool(BXPN_MOUSE_ENABLED)->get()) { - if(pmap[index] != -1) - ReleasePen(window->WScreen->ViewPort.ColorMap, pmap[index]); - pmap[index] = ObtainBestPen(window->WScreen->ViewPort.ColorMap, FULL(red), FULL(green), FULL(blue), OBP_Precision, (ULONG) PRECISION_EXACT, TAG_DONE); + switch(event->ie_Code) { + case IECODE_LBUTTON: + { + mouse_button_state |= 0x01; + DEV_mouse_motion(event->ie_position.ie_xy.ie_x, -event->ie_position.ie_xy.ie_y, mouse_button_state); + return NULL; + } + + case (IECODE_LBUTTON | IECODE_UP_PREFIX): + { + mouse_button_state &= ~0x01; + DEV_mouse_motion(event->ie_position.ie_xy.ie_x, -event->ie_position.ie_xy.ie_y, mouse_button_state); + return NULL; + } + + case IECODE_RBUTTON: + { + mouse_button_state |= 0x02; + DEV_mouse_motion(event->ie_position.ie_xy.ie_x, -event->ie_position.ie_xy.ie_y, mouse_button_state); + return NULL; + } + + case (IECODE_RBUTTON | IECODE_UP_PREFIX): + { + mouse_button_state &= 0x01; + DEV_mouse_motion(event->ie_position.ie_xy.ie_x, -event->ie_position.ie_xy.ie_y, mouse_button_state); + return NULL; + } + } + + if (event->ie_Class == IECLASS_RAWMOUSE) + { + DEV_mouse_motion(event->ie_position.ie_xy.ie_x, -event->ie_position.ie_xy.ie_y, mouse_button_state); + return NULL; + } + + return (event); + } + return (event); +} + +void setup_inputhandler(void) +{ + static struct EmulLibEntry GATEMyInputHandler = + { + TRAP_LIB, 0, (void (*)(void))MyInputHandler + }; + + + if (inputPort=CreateMsgPort()) + { + if (inputHandler=(struct Interrupt *)AllocMem(sizeof(struct Interrupt), MEMF_PUBLIC|MEMF_CLEAR)) + { + if (inputReqBlk=(struct IOStdReq *)CreateIORequest(inputPort, sizeof(struct IOStdReq))) + { + if (!(input_error = OpenDevice("input.device",NULL, (struct IORequest *)inputReqBlk, NULL))) + { + inputHandler->is_Code=(void(*)())&GATEMyInputHandler; + inputHandler->is_Data=NULL; + inputHandler->is_Node.ln_Pri=100; + inputHandler->is_Node.ln_Name=HandlerName; + inputReqBlk->io_Data=(APTR)inputHandler; + inputReqBlk->io_Command=IND_ADDHANDLER; + DoIO((struct IORequest *)inputReqBlk); + } + else + BX_PANIC(("Amiga: Could not open input.device")); + } + else + BX_PANIC(("Amiga: Could not create I/O request")); + } + else + BX_PANIC(("Amiga: Could not allocate interrupt struct memory")); + } + else + printf(("Amiga: Could not create message port")); +} + +bx_bool open_screen(void) +{ + ULONG id = INVALID_ID; + + char *scrmode; + struct DrawInfo *screen_drawinfo = NULL; + + struct ScreenModeRequester *smr; + + static struct EmulLibEntry GATEDispatcherFunc = + { + TRAP_LIB, 0, (void (*)(void))DispatcherFunc + }; + + struct Hook screenreqhook = { 0, 0, (ULONG(*)())&GATEDispatcherFunc, (ULONG(*)())screenreqfunc, 0 }; + + sprintf (verstr, "Bochs x86 Emulator %s", VER_STRING); + + if (SIM->get_param_bool(BXPN_FULLSCREEN)->get()) + { + if((scrmode = SIM->get_param_string(BXPN_SCREENMODE)->getptr())) + { + id = strtoul(scrmode, NULL, 0); + if (!IsCyberModeID(id)) id = INVALID_ID; + } + + if (id == INVALID_ID) + { + if (smr = (ScreenModeRequester *)AllocAslRequestTags(ASL_ScreenModeRequest, + ASLSM_DoWidth, TRUE, + ASLSM_DoHeight, TRUE, + ASLSM_MinDepth, 8, + ASLSM_MaxDepth, 32, + ASLSM_PropertyFlags, DIPF_IS_WB, + ASLSM_PropertyMask, DIPF_IS_WB, + ASLSM_FilterFunc, (ULONG) &screenreqhook, + TAG_DONE)) + { + if (AslRequest(smr, NULL)) + { + id = smr->sm_DisplayID; + FreeAslRequest(smr); + } + else + { + FreeAslRequest(smr); + BX_PANIC(("Amiga: Can't start without a screen")); + } + } + } + + h = GetCyberIDAttr(CYBRIDATTR_HEIGHT, id); + w = GetCyberIDAttr(CYBRIDATTR_WIDTH, id); + d = GetCyberIDAttr(CYBRIDATTR_DEPTH, id); + + //sprintf(scrmode, "%d", id); + //setenv("env:bochs/screenmode", scrmode, 1); + + + screen = OpenScreenTags(NULL, + SA_Width, w, + SA_Height, h, + SA_Depth, d, + SA_Title, verstr, + SA_DisplayID, id, + SA_ShowTitle, FALSE, + SA_Type, PUBLICSCREEN, + SA_SharePens, TRUE, + TAG_DONE); + + if(!screen) + BX_PANIC(("Amiga: Couldn't open screen")); + + window = OpenWindowTags(NULL, + WA_CustomScreen,(int)screen, + WA_Width,w, + WA_Height,h, + WA_Title, verstr, + WA_IDCMP, IDCMP_RAWKEY | IDCMP_GADGETUP | IDCMP_INACTIVEWINDOW, + WA_ReportMouse, TRUE, + WA_RMBTrap, TRUE, + WA_Backdrop,TRUE, + WA_Borderless,TRUE, + WA_Activate,TRUE, + TAG_DONE); } else { - SetRGB32(&screen->ViewPort, index, red << 24, green << 24, blue << 24); - pmap[index] = index; + pub_screen = LockPubScreen(NULL); + if (pub_screen != NULL) + { + screen_drawinfo = GetScreenDrawInfo(pub_screen); + if (screen_drawinfo != NULL) + { + id = GetVPModeID(&pub_screen->ViewPort); + d = GetCyberIDAttr(CYBRIDATTR_DEPTH, id); + } else { + UnlockPubScreen(NULL,pub_screen); + BX_PANIC(("Amiga: Couldn't get ScreenDrawInfo")); + } + + window = OpenWindowTags(NULL, + WA_Width,w, + WA_Height,h, + WA_Title, verstr, + WA_IDCMP, IDCMP_RAWKEY | IDCMP_GADGETUP | IDCMP_CHANGEWINDOW | IDCMP_INACTIVEWINDOW, + WA_RMBTrap, TRUE, + WA_DepthGadget, TRUE, + WA_ReportMouse, TRUE, + WA_DragBar, TRUE, + WA_Activate,TRUE, + TAG_DONE); + + UnlockPubScreen(NULL,pub_screen); + } + else + BX_PANIC(("Amiga: Couldn't lock the public screen")); + } + + if (!window) + BX_PANIC(("Amiga: Couldn't open the window")); + + if ((emptypointer = (UWORD *)AllocVec (16, MEMF_CLEAR)) == NULL) + BX_PANIC(("Amiga: Couldn't allocate memory")); + + vgafont = OpenDiskFont(&vgata); + + if (SIM->get_param_bool(BXPN_MOUSE_ENABLED)->get()) + hide_pointer(); + + if(!vgafont) + BX_PANIC(("Amiga: Couldn't open the vga font")); + + SetFont(window->RPort, vgafont); + + if (NULL == (vi = GetVisualInfo(window->WScreen, TAG_END))) + BX_PANIC(("Amiga: GetVisualInfo() failed")); + + bx_gadget_handle = CreateContext(&bx_glistptr); + + bx_bordertop = window->BorderTop; + bx_borderleft = window->BorderLeft; + bx_borderright = window->BorderRight; + bx_borderbottom = window->BorderBottom; + bx_headernext_left = bx_borderleft; + bx_headernext_right += bx_borderright; + + for (apen = 0; apen < 256; apen++) /*fill the pen map with -1 so we can know which pens to free at exit*/ + pmap[apen] = -1; + + white = ObtainBestPen(window->WScreen->ViewPort.ColorMap, 0xffffffff, 0xffffffff, 0xffffffff, NULL); + black = ObtainBestPen(window->WScreen->ViewPort.ColorMap, 0x00000000, 0x00000000, 0x00000000, NULL); +} + +void bx_amigaos_gui_c::specific_init(int argc, char **argv, unsigned tilewidth, unsigned tileheight, + unsigned headerbar_y) +{ + x_tilesize = tilewidth; + y_tilesize = tileheight; + + bx_headerbar_y = headerbar_y; + + IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 39); + if (IntuitionBase == NULL) + BX_PANIC(("Amiga: Failed to open intuition.library v39 or later!")); + if (IntuitionBase->LibNode.lib_Version == 50 && IntuitionBase->LibNode.lib_Revision < 5) + BX_PANIC(("Amiga: intuition.library v50 needs to be revision 5 or higher!")); + + GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 39); + if (GfxBase == NULL) + BX_PANIC(("Amiga: Failed to open graphics.library v39 or later!")); + + GadToolsBase = OpenLibrary("gadtools.library", 37); + if (GadToolsBase == NULL) + BX_PANIC(("Amiga: Failed to open gadtools.library v37 or later!")); + if (GadToolsBase->lib_Version == 50 && GadToolsBase->lib_Revision < 3) + BX_PANIC(("Amiga: gadtools.library v50 needs to be revision 3 or higher!")); + + CyberGfxBase = OpenLibrary("cybergraphics.library", 40); + if (CyberGfxBase == NULL) + BX_PANIC(("Amiga: Failed to open cybergraphics.library v40 or later!")); + + AslBase = OpenLibrary("asl.library", 38); + if (AslBase == NULL) + BX_PANIC(("Amiga: Failed to open asl.library v38 or later!")); + + DiskfontBase = OpenLibrary("diskfont.library", 38); + if (DiskfontBase == NULL) + BX_PANIC(("Amiga: Failed to open diskfont.library v38 or later!")); + + IFFParseBase = OpenLibrary("iffparse.library", 39); + if (IFFParseBase == NULL) + BX_PANIC(("Amiga: Failed to open iffparse.library v39 or later!")); + + open_screen(); + setup_inputhandler(); + + if (SIM->get_param_bool(BXPN_PRIVATE_COLORMAP)->get()) { + BX_ERROR(("Amiga: private_colormap option ignored.")); + } +} + +void bx_amigaos_gui_c::handle_events(void) +{ + void (*func) (void); + struct IntuiMessage *imsg = NULL; + struct Gadget *gad; + ULONG imCode,imClass,imQualifier; + Bit32u key_event; + + while ((imsg = (struct IntuiMessage *)GetMsg(window->UserPort))) + { + gad = (struct Gadget *)imsg->IAddress; + key_event= 0; + + imClass = imsg->Class; + imCode = imsg->Code; + imQualifier = imsg->Qualifier; + + ReplyMsg((struct Message *)imsg); + + switch (imClass) { + case IDCMP_RAWKEY: + if (imQualifier & IEQUALIFIER_LSHIFT && imQualifier & IEQUALIFIER_CONTROL && imQualifier & IEQUALIFIER_LCOMMAND) + { + toggle_mouse_enable(); + break; + } + + if(imCode <= 101) + key_event = raw_to_bochs[imCode]; + if(imCode >= 128) + key_event = raw_to_bochs[imCode-128] | BX_KEY_RELEASED; + if(key_event) + DEV_kbd_gen_scancode(key_event); + break; + + case GADGETUP: + ((void (*)()) bx_header_gadget[gad->GadgetID]->UserData)(); + break; + + case IDCMP_INACTIVEWINDOW: + if (SIM->get_param_bool(BXPN_MOUSE_ENABLED)->get()) + toggle_mouse_enable(); + break; + + case IDCMP_CHANGEWINDOW: + if(bx_xchanged) + { + bx_amigaos_gui_c::show_headerbar(); + bx_xchanged = FALSE; + } + break; + } + } +} + + +void bx_amigaos_gui_c::flush(void) { } + +void bx_amigaos_gui_c::clear_screen(void) +{ + if (d > 8 || !SIM->get_param_bool(BXPN_FULLSCREEN)->get()) + SetAPen(window->RPort, black); + else + SetAPen(window->RPort, 0); /*should be ok to clear with the first pen in the map*/ + RectFill(window->RPort, bx_borderleft, bx_bordertop + bx_headerbar_y, window->Width - bx_borderright - 1, window->Height - bx_borderbottom - 1); +} + +void bx_amigaos_gui_c::text_update(Bit8u *old_text, Bit8u *new_text, + unsigned long cursor_x, unsigned long cursor_y, + bx_vga_tminfo_t tm_info) +{ + int i; + int cursori; + unsigned nchars; + char achar; + char string[80]; + int x, y; + static int previ; + unsigned int fgcolor, bgcolor; + + //current cursor position + cursori = (cursor_y * text_cols + cursor_x) * 2; + + // Number of characters on screen, variable number of rows + nchars = text_cols * text_rows; + + for (i=0; i> 4; + + if (i == cursori) /*invert the cursor block*/ + { + SetAPen(window->RPort, pmap[bgcolor]); + SetBPen(window->RPort, pmap[fgcolor]); + } + else + { + SetAPen(window->RPort, pmap[fgcolor]); + SetBPen(window->RPort, pmap[bgcolor]); + } + + x = ((i/2) % text_cols)*window->RPort->TxWidth; + y = ((i/2) / text_cols)*window->RPort->TxHeight; + + Move(window->RPort, bx_borderleft + x, bx_bordertop + bx_headerbar_y + y + window->RPort->TxBaseline); + Text(window->RPort, &achar, 1); + } + } + + previ = cursori; + +} + +int bx_amigaos_gui_c::get_clipboard_text(Bit8u **bytes, Bit32s *nbytes) +{ + struct IFFHandle *iff = NULL; + long err = 0; + struct ContextNode *cn; + + if (!(iff = AllocIFF ())) + { + BX_INFO(("Amiga: Failed to allocate iff handle")); + return 0; + } + + if (!(iff->iff_Stream = (ULONG) OpenClipboard (0))) + { + BX_INFO(("Amiga: Failed to open clipboard device")); + freeiff(iff); + return 0; + } + + InitIFFasClip (iff); + + if (err = OpenIFF (iff, IFFF_READ)) + { + BX_INFO(("Amiga: Failed to open clipboard for reading")); + freeiff(iff); + return 0; + } + + if (err = StopChunk(iff, ID_FTXT, ID_CHRS)) + { + BX_INFO(("Amiga: Failed StopChunk()")); + freeiff(iff); + return 0; + } + + while(1) { + UBYTE readbuf[1024]; + int len = 0; + + err = ParseIFF(iff, IFFPARSE_SCAN); + if(err == IFFERR_EOC) continue; + else if(err) break; + + cn = CurrentChunk(iff); + + if((cn) && (cn->cn_Type == ID_FTXT) && (cn->cn_ID == ID_CHRS)) + { + while((len = ReadChunkBytes(iff,readbuf, 1024)) > 0) + { + Bit8u *buf = new Bit8u[len]; + memcpy (buf, readbuf, len); + *bytes = buf; + *nbytes = len; + } + if(len < 0) err = len; + } + } + + if(err && (err != IFFERR_EOF)) + { + BX_INFO(("Amiga: Failed to read from clipboard")); + freeiff(iff); + return 0; + } + + freeiff(iff); + + return 1; +} + +int bx_amigaos_gui_c::set_clipboard_text(char *text_snapshot, Bit32u len) +{ + struct IFFHandle *iff = NULL; + long err = 0; + + BX_INFO(("Amiga: set_clipboard_text")); + + if (!(iff = AllocIFF ())) + { + BX_INFO(("Amiga: Failed to allocate iff handle")); + return 0; + } + + if (!(iff->iff_Stream = (ULONG) OpenClipboard (0))) + { + BX_INFO(("Amiga: Failed to open clipboard device")); + freeiff(iff); + return 0; + } + + InitIFFasClip (iff); + + if (err = OpenIFF (iff, IFFF_WRITE)) + { + BX_INFO(("Amiga: Failed to open clipboard for writing")); + freeiff(iff); + return 0; + } + + if(!(err = PushChunk(iff, ID_FTXT, ID_FORM, IFFSIZE_UNKNOWN))) + { + if(!(err=PushChunk(iff, 0, ID_CHRS, IFFSIZE_UNKNOWN))) + { + if(WriteChunkBytes(iff, text_snapshot, len) != len) + err = IFFERR_WRITE; + } + if(!err) err = PopChunk(iff); + } + if(!err) err = PopChunk(iff); + + if(err) + { + BX_INFO(("Amiga: Failed to write text to clipboard")); + freeiff(iff); + return 0; + } + + freeiff(iff); + + return 1; +} + +bx_bool bx_amigaos_gui_c::palette_change(unsigned index, unsigned red, unsigned green, unsigned blue) +{ + Bit8u *ptr = (Bit8u *)(cmap+index); + + ptr++; /*first 8bits are not defined in the XRGB8 entry*/ + *ptr = red; ptr++; + *ptr = green; ptr++; + *ptr = blue; + + if (d > 8 || !SIM->get_param_bool(BXPN_FULLSCREEN)->get()) + { + if(pmap[index] != -1) + ReleasePen(window->WScreen->ViewPort.ColorMap, pmap[index]); + pmap[index] = ObtainBestPen(window->WScreen->ViewPort.ColorMap, FULL(red), FULL(green), FULL(blue), OBP_Precision, (ULONG) PRECISION_EXACT, TAG_DONE); + } + else + { + SetRGB32(&screen->ViewPort, index, red << 24, green << 24, blue << 24); + pmap[index] = index; } //printf("%d, %d: [%d, %d, %d]\n", pmap[index], index, red, green, blue); @@ -650,268 +619,242 @@ bx_amigaos_gui_c::palette_change(unsigned index, unsigned red, unsigned green, u return(1); } - - void -bx_amigaos_gui_c::graphics_tile_update(Bit8u *tile, unsigned x0, unsigned y0) +void bx_amigaos_gui_c::graphics_tile_update(Bit8u *tile, unsigned x0, unsigned y0) { - if (d == 8) - { - WritePixelArray(tile, 0, 0, x_tilesize, window->RPort, bx_borderleft + x0, bx_bordertop + bx_headerbar_y + y0, x_tilesize, y_tilesize, RECTFMT_LUT8); - } - else - WriteLUTPixelArray(tile, 0, 0, x_tilesize, window->RPort, cmap, bx_borderleft + x0, bx_bordertop + bx_headerbar_y + y0, x_tilesize, y_tilesize, CTABFMT_XRGB8); + if (d == 8) + WritePixelArray(tile, 0, 0, x_tilesize, window->RPort, bx_borderleft + x0, bx_bordertop + bx_headerbar_y + y0, x_tilesize, y_tilesize, RECTFMT_LUT8); + else + WriteLUTPixelArray(tile, 0, 0, x_tilesize, window->RPort, cmap, bx_borderleft + x0, bx_bordertop + bx_headerbar_y + y0, x_tilesize, y_tilesize, CTABFMT_XRGB8); } - - void -bx_amigaos_gui_c::dimension_update(unsigned x, unsigned y, unsigned fheight, unsigned fwidth, unsigned bpp) +void bx_amigaos_gui_c::dimension_update(unsigned x, unsigned y, unsigned fheight, unsigned fwidth, unsigned bpp) { - if (bpp > 8) { - BX_PANIC(("%d bpp graphics mode not supported yet", bpp)); - } - int xdiff = w - x; + if (bpp > 8) { + BX_PANIC(("%d bpp graphics mode not supported yet", bpp)); + } - if (fheight > 0) { - text_cols = x / fwidth; - text_rows = y / fheight; - if (fwidth != 8) { - x = x * 8 / fwidth; - } - if (fheight != 16) { - y = y * 16 / fheight; - } - } + int xdiff = w - x; - if (!SIM->get_param_bool(BXPN_FULLSCREEN)->get() && (x != w || y != h)) - { - ChangeWindowBox(window, window->LeftEdge, window->TopEdge, x + bx_borderleft + bx_borderright, y + bx_bordertop + bx_borderbottom + bx_headerbar_y); - w = x; - h = y; - } + if (fheight > 0) { + text_cols = x / fwidth; + text_rows = y / fheight; + if (fwidth != 8) { + x = x * 8 / fwidth; + } + if (fheight != 16) { + y = y * 16 / fheight; + } + } - /* Now we need to realign the gadgets and refresh the title bar*/ + if (!SIM->get_param_bool(BXPN_FULLSCREEN)->get() && (x != w || y != h)) + { + ChangeWindowBox(window, window->LeftEdge, window->TopEdge, x + bx_borderleft + bx_borderright, y + bx_bordertop + bx_borderbottom + bx_headerbar_y); + w = x; + h = y; + } - if(xdiff != 0) - { - int i; + /* Now we need to realign the gadgets and refresh the title bar*/ - for(i = 0; i < bx_headerbar_entries; i++) - { - if(bx_header_gadget[i]->LeftEdge + bx_header_gadget[i]->Width > bx_headernext_left) - bx_header_gadget[i]->LeftEdge -= xdiff; - } + if(xdiff != 0) + { + int i; - bx_xchanged = TRUE; + for(i = 0; i < bx_headerbar_entries; i++) + { + if(bx_header_gadget[i]->LeftEdge + bx_header_gadget[i]->Width > bx_headernext_left) + bx_header_gadget[i]->LeftEdge -= xdiff; + } - } + bx_xchanged = TRUE; + + } } - - - unsigned -bx_amigaos_gui_c::create_bitmap(const unsigned char *bmap, unsigned xdim, unsigned ydim) +unsigned bx_amigaos_gui_c::create_bitmap(const unsigned char *bmap, unsigned xdim, unsigned ydim) { + int i = 0; + Bit8u *a; - int i = 0; - Bit8u *a; + if (bx_image_entries >= BX_MAX_PIXMAPS) { + BX_PANIC(("amiga: too many pixmaps, increase BX_MAX_PIXMAPS")); + } - if (bx_image_entries >= BX_MAX_PIXMAPS) { - BX_PANIC(("amiga: too many pixmaps, increase BX_MAX_PIXMAPS")); - } + bx_header_image[bx_image_entries].LeftEdge = 0; + bx_header_image[bx_image_entries].TopEdge = 0; + bx_header_image[bx_image_entries].Width = xdim; + bx_header_image[bx_image_entries].Height = ydim; + bx_header_image[bx_image_entries].Depth = 2; + bx_header_image[bx_image_entries].ImageData = (UWORD *)bmap; + bx_header_image[bx_image_entries].NextImage = NULL; + bx_header_image[bx_image_entries].PlanePick = 0x1; + if (d > 8 || !SIM->get_param_bool(BXPN_FULLSCREEN)->get()) + bx_header_image[bx_image_entries].PlaneOnOff = 0x2; - bx_header_image[bx_image_entries].LeftEdge = 0; - bx_header_image[bx_image_entries].TopEdge = 0; - bx_header_image[bx_image_entries].Width = xdim; - bx_header_image[bx_image_entries].Height = ydim; - bx_header_image[bx_image_entries].Depth = 2; - bx_header_image[bx_image_entries].ImageData = (UWORD *)bmap; - bx_header_image[bx_image_entries].NextImage = NULL; - bx_header_image[bx_image_entries].PlanePick = 0x1; - if (d > 8 || !SIM->get_param_bool(BXPN_FULLSCREEN)->get()) - bx_header_image[bx_image_entries].PlaneOnOff = 0x2; + /*we need to reverse the bitorder for this to work*/ - /*we need to reverse the bitorder for this to work*/ + a = (Bit8u *) bx_header_image[bx_image_entries].ImageData; - a = (Bit8u *) bx_header_image[bx_image_entries].ImageData; + for(i = 0; i <= xdim*ydim/8; i++, a++) + { + *a = ((*a & 0xf0) >> 4) | ((*a & 0x0f) << 4); + *a = ((*a & 0xcc) >> 2) | ((*a & 0x33) << 2); + *a = ((*a & 0xaa) >> 1) | ((*a & 0x55) << 1); + } - for(i = 0; i <= xdim*ydim/8; i++, a++) - { - *a = ((*a & 0xf0) >> 4) | ((*a & 0x0f) << 4); - *a = ((*a & 0xcc) >> 2) | ((*a & 0x33) << 2); - *a = ((*a & 0xaa) >> 1) | ((*a & 0x55) << 1); - } +//dprintf("image data (%d), %lx\n", bx_image_entries, bmap); -// dprintf("image data (%d), %lx\n", bx_image_entries, bmap); - - bx_image_entries++; - return(bx_image_entries - 1); // return index as handle + bx_image_entries++; + return(bx_image_entries - 1); // return index as handle } - unsigned -bx_amigaos_gui_c::headerbar_bitmap(unsigned bmap_id, unsigned alignment, void (*f)(void)) +unsigned bx_amigaos_gui_c::headerbar_bitmap(unsigned bmap_id, unsigned alignment, void (*f)(void)) { - struct NewGadget ng; + struct NewGadget ng; - ng.ng_TopEdge = bx_bordertop; - ng.ng_Width = bx_header_image[bmap_id].Width; - ng.ng_Height = bx_header_image[bmap_id].Height; - ng.ng_VisualInfo = vi; - ng.ng_TextAttr = &vgata; - ng.ng_GadgetID = bx_headerbar_entries; - ng.ng_GadgetText = (UBYTE *)""; - ng.ng_Flags = 0; + ng.ng_TopEdge = bx_bordertop; + ng.ng_Width = bx_header_image[bmap_id].Width; + ng.ng_Height = bx_header_image[bmap_id].Height; + ng.ng_VisualInfo = vi; + ng.ng_TextAttr = &vgata; + ng.ng_GadgetID = bx_headerbar_entries; + ng.ng_GadgetText = (UBYTE *)""; + ng.ng_Flags = 0; + ng.ng_UserData = f; - ng.ng_UserData = f; + if (alignment == BX_GRAVITY_LEFT) + { + ng.ng_LeftEdge = bx_headernext_left; + bx_headernext_left += ng.ng_Width; + } + else + { + ng.ng_LeftEdge = window->Width - bx_headernext_right - ng.ng_Width; + bx_headernext_right += ng.ng_Width; + } - if (alignment == BX_GRAVITY_LEFT) - { - ng.ng_LeftEdge = bx_headernext_left; - bx_headernext_left += ng.ng_Width; - } - else - { - ng.ng_LeftEdge = window->Width - bx_headernext_right - ng.ng_Width; - bx_headernext_right += ng.ng_Width; - } + bx_gadget_handle = bx_header_gadget[bx_headerbar_entries] = + CreateGadget(BUTTON_KIND, bx_gadget_handle, &ng, GT_Underscore, '_', TAG_END); - bx_gadget_handle = bx_header_gadget[bx_headerbar_entries] = - CreateGadget(BUTTON_KIND, bx_gadget_handle, &ng, - GT_Underscore, '_', - TAG_END); + bx_gadget_handle->GadgetType |= GTYP_BOOLGADGET; + bx_gadget_handle->Flags |= GFLG_GADGIMAGE | GFLG_GADGHNONE; + bx_gadget_handle->GadgetRender = &bx_header_image[bmap_id]; + bx_gadget_handle->UserData = f; - bx_gadget_handle->GadgetType |= GTYP_BOOLGADGET; - bx_gadget_handle->Flags |= GFLG_GADGIMAGE | GFLG_GADGHNONE; - bx_gadget_handle->GadgetRender = &bx_header_image[bmap_id]; - bx_gadget_handle->UserData = f; - - - bx_headerbar_entries++; - return(bx_headerbar_entries - 1); + bx_headerbar_entries++; + return(bx_headerbar_entries - 1); } - - void -bx_amigaos_gui_c::show_headerbar(void) +void bx_amigaos_gui_c::show_headerbar(void) { - RemoveGList(window, bx_glistptr, bx_headerbar_entries); + RemoveGList(window, bx_glistptr, bx_headerbar_entries); - if (d > 8 || !SIM->get_param_bool(BXPN_FULLSCREEN)->get()) - SetAPen(window->RPort, white); - else - SetAPen(window->RPort, 0); - RectFill(window->RPort, bx_borderleft, bx_bordertop, window->Width - bx_borderright - 1, bx_headerbar_y + bx_bordertop - 1); + if (d > 8 || !SIM->get_param_bool(BXPN_FULLSCREEN)->get()) + SetAPen(window->RPort, white); + else + SetAPen(window->RPort, 0); + RectFill(window->RPort, bx_borderleft, bx_bordertop, window->Width - bx_borderright - 1, bx_headerbar_y + bx_bordertop - 1); - AddGList(window, bx_glistptr, ~0, bx_headerbar_entries, NULL); - RefreshGList(bx_glistptr, window, NULL, bx_headerbar_entries + 1); + AddGList(window, bx_glistptr, ~0, bx_headerbar_entries, NULL); + RefreshGList(bx_glistptr, window, NULL, bx_headerbar_entries + 1); - GT_RefreshWindow(window,NULL); + GT_RefreshWindow(window,NULL); } - - void -bx_amigaos_gui_c::replace_bitmap(unsigned hbar_id, unsigned bmap_id) +void bx_amigaos_gui_c::replace_bitmap(unsigned hbar_id, unsigned bmap_id) { - bx_header_gadget[hbar_id]->GadgetRender = &bx_header_image[bmap_id]; + bx_header_gadget[hbar_id]->GadgetRender = &bx_header_image[bmap_id]; - RefreshGList(bx_glistptr, window, NULL, bx_headerbar_entries + 1); + RefreshGList(bx_glistptr, window, NULL, bx_headerbar_entries + 1); } - void -bx_amigaos_gui_c::exit(void) +void bx_amigaos_gui_c::exit(void) { - if(window) - { + if(window) + { RemoveGList(window, bx_glistptr, bx_headerbar_entries); FreeGadgets(bx_glistptr); - FreeVec(emptypointer); + FreeVec(emptypointer); - /*Release the pens*/ - while (apen >= 0) - { - if (pmap[apen] == black) - black = -1; - if (pmap[apen] == white) - white = -1; - ReleasePen(window->WScreen->ViewPort.ColorMap, pmap[apen]); - apen--; - } - if (black != -1) - ReleasePen(window->WScreen->ViewPort.ColorMap, black); - if(white != -1) - ReleasePen(window->WScreen->ViewPort.ColorMap, white); - CloseWindow(window); + /*Release the pens*/ + while (apen >= 0) + { + if (pmap[apen] == black) + black = -1; + if (pmap[apen] == white) + white = -1; + ReleasePen(window->WScreen->ViewPort.ColorMap, pmap[apen]); + apen--; + } + if (black != -1) + ReleasePen(window->WScreen->ViewPort.ColorMap, black); + if(white != -1) + ReleasePen(window->WScreen->ViewPort.ColorMap, white); + CloseWindow(window); } - if(screen) - CloseScreen(screen); - if(CyberGfxBase) - CloseLibrary(CyberGfxBase); - if(GadToolsBase) - CloseLibrary(GadToolsBase); - if(GfxBase) - CloseLibrary((struct Library *)GfxBase); - if(IntuitionBase) - CloseLibrary((struct Library *)IntuitionBase); - if(DiskfontBase) - CloseLibrary(DiskfontBase); - if(AslBase) - CloseLibrary(AslBase); - if(IFFParseBase) - CloseLibrary(IFFParseBase); + if(screen) + CloseScreen(screen); + if(CyberGfxBase) + CloseLibrary(CyberGfxBase); + if(GadToolsBase) + CloseLibrary(GadToolsBase); + if(GfxBase) + CloseLibrary((struct Library *)GfxBase); + if(IntuitionBase) + CloseLibrary((struct Library *)IntuitionBase); + if(DiskfontBase) + CloseLibrary(DiskfontBase); + if(AslBase) + CloseLibrary(AslBase); + if(IFFParseBase) + CloseLibrary(IFFParseBase); - if(!input_error) - { - inputReqBlk->io_Data=(APTR)inputHandler; - inputReqBlk->io_Command=IND_REMHANDLER; - DoIO((struct IORequest *)inputReqBlk); - CloseDevice((struct IORequest *)inputReqBlk); - } + if(!input_error) + { + inputReqBlk->io_Data=(APTR)inputHandler; + inputReqBlk->io_Command=IND_REMHANDLER; + DoIO((struct IORequest *)inputReqBlk); + CloseDevice((struct IORequest *)inputReqBlk); + } - if(inputReqBlk) - DeleteIORequest((struct IORequest *)inputReqBlk); - if(inputHandler) - FreeMem(inputHandler,sizeof(struct Interrupt)); - if(inputPort) - DeleteMsgPort(inputPort); + if(inputReqBlk) + DeleteIORequest((struct IORequest *)inputReqBlk); + if(inputHandler) + FreeMem(inputHandler,sizeof(struct Interrupt)); + if(inputPort) + DeleteMsgPort(inputPort); } -void -show_pointer(void) +void show_pointer(void) { - ClearPointer(window); + ClearPointer(window); } -void -hide_pointer(void) +void hide_pointer(void) { - SetPointer(window, emptypointer, 1, 16, 0, 0); + SetPointer(window, emptypointer, 1, 16, 0, 0); } - void -bx_amigaos_gui_c::mouse_enabled_changed_specific (bx_bool val) +void bx_amigaos_gui_c::mouse_enabled_changed_specific (bx_bool val) { if (val) { - BX_INFO(("[AmigaOS] Mouse on")); - hide_pointer(); + BX_INFO(("[AmigaOS] Mouse on")); + hide_pointer(); } else { - BX_INFO(("[AmigaOS] Mouse off")); - show_pointer(); + BX_INFO(("[AmigaOS] Mouse off")); + show_pointer(); } } -void -freeiff(struct IFFHandle *iff) +void freeiff(struct IFFHandle *iff) { - if(iff) - { - CloseIFF (iff); - if (iff->iff_Stream) - CloseClipboard ((struct ClipboardHandle *) iff->iff_Stream); - FreeIFF (iff); - } + if(iff) { + CloseIFF (iff); + if (iff->iff_Stream) + CloseClipboard((struct ClipboardHandle *) iff->iff_Stream); + FreeIFF(iff); + } } - - #endif /* if BX_WITH_AMIGAOS */ diff --git a/bochs/gui/beos.cc b/bochs/gui/beos.cc index c6d6494a0..b5e208dbb 100644 --- a/bochs/gui/beos.cc +++ b/bochs/gui/beos.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: beos.cc,v 1.31 2008-02-05 22:57:41 sshwarts Exp $ +// $Id: beos.cc,v 1.32 2008-02-15 22:05:40 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -62,9 +62,7 @@ IMPLEMENT_GUI_PLUGIN_CODE(beos) #define LOG_THIS theGui-> -#define PAD_NEAREST(n, quantum) (( ((n) + ((quantum) - 1)) / (n) ) * (n)) - - +#define PAD_NEAREST(n, quantum) ((((n) + ((quantum) - 1)) / (n)) * (n)) class BochsApplication : public BApplication { public: @@ -213,7 +211,7 @@ bx_beos_gui_c::specific_init(int argc, char **argv, put("BGUI"); if (SIM->get_param_bool(BXPN_PRIVATE_COLORMAP)->get()) { - BX_INFO(( "BeOS: private_colormap option not handled yet.")); + BX_INFO(("BeOS: private_colormap option not handled yet.")); } x_tilesize = tilewidth; @@ -241,8 +239,8 @@ BX_INFO(("font_height = %u", (unsigned) font_height)); // XSetBackground(bx_x_display, gc, col_vals[curr_background]); curr_foreground = 1; // XSetForeground(bx_x_display, gc, col_vals[curr_foreground]); - //XGrabPointer( bx_x_display, win, True, 0, GrabModeAsync, GrabModeAsync, - // win, None, CurrentTime ); + //XGrabPointer(bx_x_display, win, True, 0, GrabModeAsync, GrabModeAsync, + // win, None, CurrentTime); //XFlush(bx_x_display); myApplication = new BochsApplication(); @@ -277,7 +275,7 @@ void bx_beos_gui_c::handle_events(void) { Bit32u key; - while ( head != tail ) { + while (head != tail) { key = deq_key_event(); DEV_kbd_gen_scancode(key); } @@ -299,7 +297,7 @@ void bx_beos_gui_c::handle_events(void) if (current != previous || mouse_button_state != newstate) { int dx = (int)(current.x - previous.x) *2; int dy = -(int)((current.y - previous.y) *2); - DEV_mouse_motion( dx, dy, newstate); + DEV_mouse_motion(dx, dy, newstate); mouse_button_state = newstate; previous = current; } @@ -334,10 +332,10 @@ void bx_beos_gui_c::text_update(Bit8u *old_text, Bit8u *new_text, nchars = text_cols * text_rows; // first draw over character at original block cursor location - if ( (prev_block_cursor_y*text_cols + prev_block_cursor_x) < nchars ) { + if ((prev_block_cursor_y*text_cols + prev_block_cursor_x) < nchars) { achar = new_text[(prev_block_cursor_y*text_cols + prev_block_cursor_x)*2]; point.Set(prev_block_cursor_x*8, prev_block_cursor_y*16 + bx_headerbar_y); - aView->DrawBitmap(vgafont[achar], point ); + aView->DrawBitmap(vgafont[achar], point); } for (i=0; iDrawBitmap(vgafont[achar], point ); + aView->DrawBitmap(vgafont[achar], point); } } @@ -362,7 +360,7 @@ void bx_beos_gui_c::text_update(Bit8u *old_text, Bit8u *new_text, achar = new_text[(cursor_y*text_cols + cursor_x)*2]; point.Set(cursor_x*8, cursor_y*16 + bx_headerbar_y); aView->set_inv_text_colors(); - aView->DrawBitmap(vgafont[achar], point ); + aView->DrawBitmap(vgafont[achar], point); aView->set_text_colors(); } @@ -841,7 +839,7 @@ void BochsView::KeyDown(const char *bytes, int32 numBytes) #if 0 case B_FUNCTION_KEY: break; msg->FindInt32("key", &key); - switch ( key ) { + switch (key) { case B_F1_KEY: break; case B_F2_KEY: break; case B_F3_KEY: break; @@ -888,7 +886,7 @@ void BochsView::KeyDown(const char *bytes, int32 numBytes) break; default: - if ( (byte >= 0x01) && (byte <= 0x1a) ) { + if ((byte >= 0x01) && (byte <= 0x1a)) { // If the above keys dont catch this case, synthesize a // Ctrl-A .. Ctrl-Z event byte -= 1; @@ -1035,7 +1033,7 @@ unsigned bx_beos_gui_c::headerbar_bitmap(unsigned bmap_id, unsigned alignment, { unsigned hb_index; - if ( (bx_headerbar_entries+1) > BX_MAX_HEADERBAR_ENTRIES ) + if ((bx_headerbar_entries+1) > BX_MAX_HEADERBAR_ENTRIES) BX_PANIC(("beos: too many headerbar entries, increase BX_MAX_HEADERBAR_ENTRIES")); bx_headerbar_entries++; @@ -1092,7 +1090,7 @@ void bx_beos_gui_c::show_headerbar(void) else xorigin = dimension_x - bx_headerbar_entry[i].xorigin; origin.Set(xorigin, 0); - aView->DrawBitmap( bx_headerbar_entry[i].bitmap, origin ); + aView->DrawBitmap(bx_headerbar_entry[i].bitmap, origin); } aView->set_text_colors(); aWindow->Unlock(); @@ -1109,7 +1107,7 @@ void headerbar_click(int x, int y) xorigin = bx_headerbar_entry[i].xorigin; else xorigin = dimension_x - bx_headerbar_entry[i].xorigin; - if ( (x>=xorigin) && (x<(xorigin+int(bx_headerbar_entry[i].xdim))) ) { + if ((x>=xorigin) && (x<(xorigin+int(bx_headerbar_entry[i].xdim)))) { bx_headerbar_entry[i].f(); return; } @@ -1123,7 +1121,7 @@ void create_vga_font(void) unsigned char *data; BRect brect(0,0, 7,15); - BX_INFO(( "BeOS: creating VGA font from bitmaps" )); + BX_INFO(("BeOS: creating VGA font from bitmaps")); // VGA font is 8wide x 16high for (unsigned c=0; c<256; c++) { diff --git a/bochs/gui/carbon.cc b/bochs/gui/carbon.cc index 3bf8eb4c5..ec854f5c6 100644 --- a/bochs/gui/carbon.cc +++ b/bochs/gui/carbon.cc @@ -1,5 +1,5 @@ //////////////////////////////////////////////////////////////////////// -// $Id: carbon.cc,v 1.37 2008-02-07 18:28:50 sshwarts Exp $ +// $Id: carbon.cc,v 1.38 2008-02-15 22:05:40 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -23,7 +23,8 @@ // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - +// +//////////////////////////////////////////////////////////////////////// // carbon.cc -- bochs GUI file for MacOS X with Carbon API // written by David Batterham @@ -458,7 +459,7 @@ pascal OSStatus CEvtHandleApplicationMenus (EventHandlerCallRef nextHandler, aboutDialog, NULL, /* can be NULL */ &index); - CFRelease( cf_version ); + CFRelease(cf_version); } break; @@ -556,7 +557,7 @@ void InitToolbox(void) 1, &appleEvent, 0, NULL); #endif - err = AEInstallEventHandler( kCoreEventClass, kAEQuitApplication, + err = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, NewAEEventHandlerUPP(QuitAppleEventHandler), 0, false); if (err != noErr) ExitToShell(); @@ -575,7 +576,7 @@ void CreateTile(void) CGrafPtr savePort; OSErr err; unsigned long p_f; - long theRowBytes = ((((long) ( vga_bpp==24?32:(((vga_bpp+1)>>1)<<1) ) * ((long) (srcTileRect.right-srcTileRect.left)) + 31) >> 5) << 2); + long theRowBytes = ((((long) (vga_bpp==24?32:(((vga_bpp+1)>>1)<<1)) * ((long) (srcTileRect.right-srcTileRect.left)) + 31) >> 5) << 2); // if (SIM->get_param_bool(BXPN_PRIVATE_COLORMAP)->get()) // { @@ -707,7 +708,7 @@ void CreateWindows(void) GetAvailableWindowPositioningBounds(GetMainDevice(), &positioningBounds); SetRect(&winRect, 0, 0, screenBounds.right, screenBounds.bottom + GetMBarHeight()); - CreateNewWindow(kPlainWindowClass, (kWindowStandardHandlerAttribute ), &winRect, &backdrop); + CreateNewWindow(kPlainWindowClass, (kWindowStandardHandlerAttribute), &winRect, &backdrop); if (backdrop == NULL) {BX_PANIC(("mac: can't create backdrop window"));} InstallWindowEventHandler(backdrop, NewEventHandlerUPP(CEvtHandleWindowBackdropUpdate), 1, &eventUpdate, NULL, NULL); @@ -782,7 +783,7 @@ void CreateWindows(void) SetWindowGroup(fullwin, fullwinGroup); SetWindowGroup(backdrop, fullwinGroup); - RepositionWindow( win, NULL, kWindowCenterOnMainScreen ); + RepositionWindow(win, NULL, kWindowCenterOnMainScreen); hidden = fullwin; @@ -880,20 +881,20 @@ OSStatus HandleKey(EventRef theEvent, Bit32u keyState) typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers); - if( status == noErr ) + if(status == noErr) { status = GetEventParameter (theEvent, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &key); - if( status == noErr ) + if(status == noErr) { // key = event->message & charCodeMask; // Let our menus process command keys - if( modifiers & cmdKey ) + if(modifiers & cmdKey) { status = eventNotHandledErr; } @@ -1052,7 +1053,7 @@ void bx_carbon_gui_c::handle_events(void) if(mouseMoved) { CGMouseDelta CGdX, CGdY; - CGGetLastMouseDelta( &CGdX, &CGdY ); + CGGetLastMouseDelta(&CGdX, &CGdY); dx = CGdX; dy = - CGdY; // Windows has an opposing grid } @@ -1279,17 +1280,17 @@ int bx_carbon_gui_c::get_clipboard_text(Bit8u **bytes, Bit32s *nbytes) Size theScrapSize; OSStatus err; - GetCurrentScrap( &theScrap ); + GetCurrentScrap(&theScrap); // Make sure there is text to paste - err= GetScrapFlavorFlags( theScrap, kScrapFlavorTypeText, &theScrapFlags); + err= GetScrapFlavorFlags(theScrap, kScrapFlavorTypeText, &theScrapFlags); if(err == noErr) { - GetScrapFlavorSize( theScrap, kScrapFlavorTypeText, &theScrapSize); + GetScrapFlavorSize(theScrap, kScrapFlavorTypeText, &theScrapSize); *nbytes = theScrapSize; *bytes = new Bit8u[1 + *nbytes]; BX_INFO (("found %d bytes on the clipboard", *nbytes)); - err= GetScrapFlavorData( theScrap, kScrapFlavorTypeText, &theScrapSize, *bytes); + err= GetScrapFlavorData(theScrap, kScrapFlavorTypeText, &theScrapSize, *bytes); BX_INFO (("first byte is 0x%02x", *bytes[0])); } else @@ -1304,14 +1305,14 @@ int bx_carbon_gui_c::set_clipboard_text(char *text_snapshot, Bit32u len) ScrapRef theScrap; // Clear out the existing clipboard - ClearCurrentScrap (); + ClearCurrentScrap(); + + GetCurrentScrap(&theScrap); + PutScrapFlavor (theScrap, kScrapFlavorTypeText, kScrapFlavorMaskNone, len, text_snapshot); - GetCurrentScrap( &theScrap ); - PutScrapFlavor ( theScrap, kScrapFlavorTypeText, kScrapFlavorMaskNone, len, text_snapshot); return 1; } - // ::PALETTE_CHANGE() // // Allocate a color in the native GUI, for this color, and put @@ -1430,7 +1431,7 @@ void bx_carbon_gui_c::graphics_tile_update(Bit8u *tile, unsigned x0, unsigned y0 BX_ERROR(("mac: UnlockPortBits returned %hd", theError)); RGBForeColor(&black); RGBBackColor(&white); - CopyBits( GetPortBitMapForCopyBits(gOffWorld), WINBITMAP(win), + CopyBits(GetPortBitMapForCopyBits(gOffWorld), WINBITMAP(win), &srcTileRect, &destRect, srcCopy, NULL); if ((theError = QDError()) != noErr) BX_ERROR(("mac: CopyBits returned %hd", theError)); @@ -1472,7 +1473,7 @@ void bx_carbon_gui_c::dimension_update(unsigned x, unsigned y, unsigned fheight, if (fheight > 0) { text_cols = x / fwidth; text_rows = y / fheight; - if( fwidth != font_width || fheight != font_height ) { + if(fwidth != font_width || fheight != font_height) { font_width = fwidth; font_height = fheight; CreateVGAFont(vga_charmap); @@ -1590,12 +1591,11 @@ unsigned bx_carbon_gui_c::headerbar_bitmap(unsigned bmap_id, unsigned alignment, info.contentType = kControlContentCIconHandle; info.u.cIconHandle = bx_cicn[bmap_id]; - CreateIconControl( toolwin, &destRect, &info, false, &(bx_tool_pixmap[hb_index].control) ); + CreateIconControl(toolwin, &destRect, &info, false, &(bx_tool_pixmap[hb_index].control)); SetControlCommandID(bx_tool_pixmap[hb_index].control, hb_index); return(hb_index); } - // ::SHOW_HEADERBAR() // // Show (redraw) the current headerbar, which is composed of @@ -1712,11 +1712,11 @@ void UpdateTools() ScrapRef theScrap; ScrapFlavorFlags theScrapFlags; - GetCurrentScrap( &theScrap ); + GetCurrentScrap(&theScrap); // If keyboard mapping is on AND there is text on the clipboard enable pasting if (SIM->get_param_bool(BXPN_KBD_USEMAPPING)->get() && - (GetScrapFlavorFlags( theScrap, kScrapFlavorTypeText, &theScrapFlags) == noErr)) + (GetScrapFlavorFlags(theScrap, kScrapFlavorTypeText, &theScrapFlags) == noErr)) { EnableMenuItem(GetMenuRef(mEdit), iPaste); EnableControl(bx_tool_pixmap[PASTE_TOOL_BUTTON].control); @@ -2047,7 +2047,7 @@ BitMap *CreateBitMap(unsigned width, unsigned height) BitMap *bm; long row_bytes; - row_bytes = (( width + 31) >> 5) << 2; + row_bytes = ((width + 31) >> 5) << 2; bm = (BitMap *)calloc(1, sizeof(BitMap)); if (bm == NULL) BX_PANIC(("mac: can't allocate memory for pixmap")); @@ -2108,12 +2108,12 @@ void bx_carbon_gui_c::mouse_enabled_changed_specific (bx_bool val) void bx_carbon_gui_c::beep_on(float frequency) { AlertSoundPlay(); - BX_INFO(( "Carbon Beep ON (frequency=%.2f)",frequency)); + BX_INFO(("Carbon Beep ON (frequency=%.2f)",frequency)); } void bx_carbon_gui_c::beep_off() { - BX_INFO(( "Carbon Beep OFF")); + BX_INFO(("Carbon Beep OFF")); } // we need to handle "ask" events so that PANICs are properly reported @@ -2129,7 +2129,7 @@ static BxEvent * CarbonSiminterfaceCallback (void *theClass, BxEvent *event) DialogItemIndex index; AlertStdCFStringAlertParamRec alertParam = {0}; - if( event->u.logmsg.prefix != NULL ) + if(event->u.logmsg.prefix != NULL) { title = CFStringCreateWithCString(NULL, event->u.logmsg.prefix, kCFStringEncodingASCII); exposition = CFStringCreateWithCString(NULL, event->u.logmsg.msg, kCFStringEncodingASCII); @@ -2159,25 +2159,25 @@ static BxEvent * CarbonSiminterfaceCallback (void *theClass, BxEvent *event) NULL, /* can be NULL */ &index); - CFRelease( title ); + CFRelease(title); - if( exposition != NULL ) + if(exposition != NULL) { - CFRelease( exposition ); + CFRelease(exposition); } // continue - if( index == kAlertStdAlertOKButton ) + if(index == kAlertStdAlertOKButton) { event->retcode = 0; } // quit - else if( index == kAlertStdAlertCancelButton ) + else if(index == kAlertStdAlertCancelButton) { event->retcode = 2; } #if 0 - if( event->u.logmsg.prefix != NULL ) + if(event->u.logmsg.prefix != NULL) { BX_INFO(("Callback log: Prefix: %s", event->u.logmsg.prefix)); } diff --git a/bochs/gui/gui.cc b/bochs/gui/gui.cc index 735cee040..e2af7b447 100644 --- a/bochs/gui/gui.cc +++ b/bochs/gui/gui.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: gui.cc,v 1.103 2008-02-05 22:57:41 sshwarts Exp $ +// $Id: gui.cc,v 1.104 2008-02-15 22:05:40 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2002 MandrakeSoft S.A. @@ -395,7 +395,7 @@ void bx_gui_c::copy_handler(void) Bit32u len; char *text_snapshot; if (make_text_snapshot (&text_snapshot, &len) < 0) { - BX_INFO(( "copy button failed, mode not implemented")); + BX_INFO(("copy button failed, mode not implemented")); return; } if (!BX_GUI_THIS set_clipboard_text(text_snapshot, len)) { @@ -460,7 +460,7 @@ void bx_gui_c::snapshot_handler(void) char *text_snapshot; Bit32u len; if (make_text_snapshot (&text_snapshot, &len) < 0) { - BX_ERROR(( "snapshot button failed, mode not implemented")); + BX_ERROR(("snapshot button failed, mode not implemented")); return; } //FIXME diff --git a/bochs/gui/keymap.cc b/bochs/gui/keymap.cc index 365330274..323aae846 100644 --- a/bochs/gui/keymap.cc +++ b/bochs/gui/keymap.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: keymap.cc,v 1.22 2008-02-05 22:57:41 sshwarts Exp $ +// $Id: keymap.cc,v 1.23 2008-02-15 22:05:40 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2002 MandrakeSoft S.A. @@ -121,7 +121,7 @@ static void init_parse_line(char *line_to_parse) // chop off newline lineptr = (unsigned char *)line_to_parse; char *nl; - if( (nl = strchr(line_to_parse,'\n')) != NULL) { + if ((nl = strchr(line_to_parse,'\n')) != NULL) { *nl = 0; } } diff --git a/bochs/gui/macintosh.cc b/bochs/gui/macintosh.cc index c75519314..d54388536 100644 --- a/bochs/gui/macintosh.cc +++ b/bochs/gui/macintosh.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: macintosh.cc,v 1.28 2008-02-05 22:57:41 sshwarts Exp $ +// $Id: macintosh.cc,v 1.29 2008-02-15 22:05:40 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -23,7 +23,7 @@ // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - +///////////////////////////////////////////////////////////////////////// // macintosh.cc -- bochs GUI file for the Macintosh // written by David Batterham @@ -193,71 +193,72 @@ unsigned char reverse_bitorder(unsigned char); //it is needed for os 8.x with appearance managaer void FixWindow(void) { - RgnHandle wStruct; - Region *wRgn; - CWindowRecord *thing; - Rect wRect; - RgnHandle tStruct; - Region *tRgn; - Rect tRect; - short MinVal; + RgnHandle wStruct; + Region *wRgn; + CWindowRecord *thing; + Rect wRect; + RgnHandle tStruct; + Region *tRgn; + Rect tRect; + short MinVal; - thing = (CWindowRecord *)win; - wStruct = thing->strucRgn; - wRgn = (Region *)*wStruct; - wRect = wRgn->rgnBBox; + thing = (CWindowRecord *)win; + wStruct = thing->strucRgn; + wRgn = (Region *)*wStruct; + wRect = wRgn->rgnBBox; - thing = (CWindowRecord *)toolwin; - tStruct = thing->strucRgn; - tRgn = (Region *)*tStruct; - tRect = tRgn->rgnBBox; + thing = (CWindowRecord *)toolwin; + tStruct = thing->strucRgn; + tRgn = (Region *)*tStruct; + tRect = tRgn->rgnBBox; - if (wRect.left < 2) - { - gLeft = gLeft + (2 - wRect.left); - } + if (wRect.left < 2) + { + gLeft = gLeft + (2 - wRect.left); + } - MinVal = tRect.bottom+2; -// MinVal = MinVal + GetMBarHeight(); + MinVal = tRect.bottom+2; +//MinVal = MinVal + GetMBarHeight(); - if (wRect.top < MinVal) - { -// gMinTop = gMinTop + (MinVal - wRect.top); - gMaxTop = gMaxTop + (MinVal - wRect.top); - } + if (wRect.top < MinVal) + { +// gMinTop = gMinTop + (MinVal - wRect.top); + gMaxTop = gMaxTop + (MinVal - wRect.top); + } - MoveWindow(win, gLeft, gMaxTop, false); + MoveWindow(win, gLeft, gMaxTop, false); } void MacPanic(void) { - StopAlert(200, NULL); + StopAlert(200, NULL); } void InitToolbox(void) { - InitGraf(&qd.thePort); - InitWindows(); - InitMenus(); - InitDialogs(nil); - InitCursor(); - MaxApplZone(); - // Initialise the toolbox + InitGraf(&qd.thePort); + InitWindows(); + InitMenus(); + InitDialogs(nil); + InitCursor(); + MaxApplZone(); + // Initialise the toolbox } void CreateTile(void) { - GDHandle saveDevice; - CGrafPtr savePort; - OSErr err; - unsigned long p_f; - long theRowBytes = ((((long) ( vga_bpp==24?32:(((vga_bpp+1)>>1)<<1) ) * ((long) (srcTileRect.right-srcTileRect.left)) + 31) >> 5) << 2); + GDHandle saveDevice; + CGrafPtr savePort; + OSErr err; + unsigned long p_f; + long theRowBytes = ((((long) (vga_bpp==24?32:(((vga_bpp+1)>>1)<<1)) * ((long) (srcTileRect.right-srcTileRect.left)) + 31) >> 5) << 2); - // if (SIM->get_param_bool(BXPN_PRIVATE_COLORMAP)->get()) - // { - GetGWorld(&savePort, &saveDevice); - switch(vga_bpp) - { +//if (SIM->get_param_bool(BXPN_PRIVATE_COLORMAP)->get()) +//{ + + GetGWorld(&savePort, &saveDevice); + switch(vga_bpp) + { case 1: p_f = k1MonochromePixelFormat; break; @@ -282,59 +283,60 @@ void CreateTile(void) case 32: p_f = k32ARGBPixelFormat;//k32BGRAPixelFormat; break; + } + + BX_ASSERT((gMyBuffer = (Ptr)malloc(theRowBytes * (srcTileRect.bottom - srcTileRect.top))) != NULL); + err = QTNewGWorldFromPtr(&gOffWorld, p_f, + &srcTileRect, vga_bpp>8 ? NULL : gCTable, NULL, keepLocal, gMyBuffer, theRowBytes); + if (err != noErr || gOffWorld == NULL) + BX_PANIC(("mac: can't create gOffWorld; err=%hd", err)); + + SetGWorld(gOffWorld, NULL); + RGBForeColor(&black); + RGBBackColor(&white); + + gTile = GetGWorldPixMap(gOffWorld); + + if (gTile != NULL) + { + NoPurgePixels(gTile); + if (!LockPixels(gTile)) + BX_ERROR(("mac: can't LockPixels gTile")); + if ((**gTile).pixelType != RGBDirect && (**gTile).pmTable != gCTable) + { + DisposeCTable(gCTable); + gCTable = (**gTile).pmTable; } - BX_ASSERT((gMyBuffer = (Ptr)malloc(theRowBytes * (srcTileRect.bottom - srcTileRect.top))) != NULL); - err = QTNewGWorldFromPtr(&gOffWorld, p_f, - &srcTileRect, vga_bpp>8 ? NULL : gCTable, NULL, keepLocal, gMyBuffer, theRowBytes); - if (err != noErr || gOffWorld == NULL) - BX_PANIC(("mac: can't create gOffWorld; err=%hd", err)); + (**gCTable).ctFlags |= 0x4000; //use palette manager indexes + CTabChanged(gCTable); + } + else + BX_PANIC(("mac: can't create gTile")); - SetGWorld(gOffWorld, NULL); - RGBForeColor(&black); - RGBBackColor(&white); + SetGWorld(savePort, saveDevice); - gTile = GetGWorldPixMap(gOffWorld); - - if (gTile != NULL) - { - NoPurgePixels(gTile); - if (!LockPixels(gTile)) - BX_ERROR(("mac: can't LockPixels gTile")); - if ((**gTile).pixelType != RGBDirect && (**gTile).pmTable != gCTable) - { - DisposeCTable(gCTable); - gCTable = (**gTile).pmTable; - } - - (**gCTable).ctFlags |= 0x4000; //use palette manager indexes - CTabChanged(gCTable); - } - else - BX_PANIC(("mac: can't create gTile")); - - SetGWorld(savePort, saveDevice); - /* } - else - { - gOffWorld = NULL; - gTile = CreatePixMap(0, 0, srcTileRect.right, srcTileRect.bottom, 8, gCTable); - if (gTile == NULL) - BX_PANIC(("mac: can't create gTile")); - }*/ +/*} + else + { + gOffWorld = NULL; + gTile = CreatePixMap(0, 0, srcTileRect.right, srcTileRect.bottom, 8, gCTable); + if (gTile == NULL) + BX_PANIC(("mac: can't create gTile")); +}*/ } void CreateMenus(void) { - Handle menu; + Handle menu; - menu = GetNewMBar(rMBarID); // get our menus from resource + menu = GetNewMBar(rMBarID); // get our menus from resource if (menu != nil) { - SetMenuBar(menu); - DisposeHandle(menu); - AppendResMenu(GetMenuHandle(mApple ), 'DRVR'); // add apple menu items - DrawMenuBar(); + SetMenuBar(menu); + DisposeHandle(menu); + AppendResMenu(GetMenuHandle(mApple), 'DRVR'); // add apple menu items + DrawMenuBar(); } else BX_PANIC(("can't create menu")); @@ -342,46 +344,46 @@ void CreateMenus(void) void CreateWindows(void) { - int l, t, r, b; - Rect winRect; + int l, t, r, b; + Rect winRect; - SetRect(&winRect, 0, 0, qd.screenBits.bounds.right, qd.screenBits.bounds.bottom); - backdrop = NewWindow(NULL, &winRect, "\p", false, plainDBox, (WindowPtr)-1, false, 0); + SetRect(&winRect, 0, 0, qd.screenBits.bounds.right, qd.screenBits.bounds.bottom); + backdrop = NewWindow(NULL, &winRect, "\p", false, plainDBox, (WindowPtr)-1, false, 0); - width = 640; - height = 480; - gLeft = 4; - gMinTop = 44; - gMaxTop = 44 + gheaderbar_y; + width = 640; + height = 480; + gLeft = 4; + gMinTop = 44; + gMaxTop = 44 + gheaderbar_y; - l = (qd.screenBits.bounds.right - width)/2; - r = l + width; - t = (qd.screenBits.bounds.bottom - height)/2; - b = t + height; + l = (qd.screenBits.bounds.right - width)/2; + r = l + width; + t = (qd.screenBits.bounds.bottom - height)/2; + b = t + height; - SetRect(&winRect, 0, 20, qd.screenBits.bounds.right, 22+gheaderbar_y); - toolwin = NewCWindow(NULL, &winRect, "\pMacBochs 586", true, floatProc, - (WindowPtr)-1, false, 0); - if (toolwin == NULL) - BX_PANIC(("mac: can't create tool window")); - // Create a moveable tool window for the "headerbar" + SetRect(&winRect, 0, 20, qd.screenBits.bounds.right, 22+gheaderbar_y); + toolwin = NewCWindow(NULL, &winRect, "\pMacBochs 586", true, floatProc, + (WindowPtr)-1, false, 0); + if (toolwin == NULL) + BX_PANIC(("mac: can't create tool window")); + // Create a moveable tool window for the "headerbar" - SetRect(&winRect, l, t, r, b); - fullwin = NewCWindow(NULL, &winRect, "\p", false, plainDBox, (WindowPtr)-1, false, 1); + SetRect(&winRect, l, t, r, b); + fullwin = NewCWindow(NULL, &winRect, "\p", false, plainDBox, (WindowPtr)-1, false, 1); - SetRect(&winRect, gLeft, gMaxTop, gLeft+width, gMaxTop+height); - win = NewCWindow(NULL, &winRect, "\pMacBochs 586", true, documentProc, - (WindowPtr)-1, true, 1); - if (win == NULL) - BX_PANIC(("mac: can't create emulator window")); + SetRect(&winRect, gLeft, gMaxTop, gLeft+width, gMaxTop+height); + win = NewCWindow(NULL, &winRect, "\pMacBochs 586", true, documentProc, + (WindowPtr)-1, true, 1); + if (win == NULL) + BX_PANIC(("mac: can't create emulator window")); - FixWindow(); + FixWindow(); - hidden = fullwin; + hidden = fullwin; - HiliteWindow(win, true); + HiliteWindow(win, true); - SetPort(win); + SetPort(win); } // ::SPECIFIC_INIT() @@ -400,44 +402,42 @@ void CreateWindows(void) // always assumes the width of the current VGA mode width, but // it's height is defined by this parameter. -void bx_macintosh_gui_c::specific_init(int argc, char **argv, unsigned tilewidth, unsigned tileheight, - unsigned headerbar_y) +void bx_macintosh_gui_c::specific_init(int argc, char **argv, unsigned tilewidth, unsigned tileheight, unsigned headerbar_y) { - put("MGUI"); - InitToolbox(); + put("MGUI"); + InitToolbox(); - //SouixWin = FrontWindow(); + //SouixWin = FrontWindow(); - atexit(MacPanic); + atexit(MacPanic); - gheaderbar_y = headerbar_y; + gheaderbar_y = headerbar_y; - CreateKeyMap(); + CreateKeyMap(); - gCTable = GetCTable(128); + gCTable = GetCTable(128); BX_ASSERT (gCTable != NULL); CTabChanged(gCTable); //(*gCTable)->ctSeed = GetCTSeed(); - SetRect(&srcTextRect, 0, 0, FONT_WIDTH, FONT_HEIGHT); - SetRect(&srcTileRect, 0, 0, tilewidth, tileheight); + SetRect(&srcTextRect, 0, 0, FONT_WIDTH, FONT_HEIGHT); + SetRect(&srcTileRect, 0, 0, tilewidth, tileheight); - CreateMenus(); - CreateVGAFont(); - CreateTile(); - CreateWindows(); + CreateMenus(); + CreateVGAFont(); + CreateTile(); + CreateWindows(); - GetMouse(&prevPt); - SetEventMask(everyEvent); + GetMouse(&prevPt); + SetEventMask(everyEvent); - SIOUXSettings.setupmenus = false; - SIOUXSettings.autocloseonquit = true; - SIOUXSettings.asktosaveonclose = false; - SIOUXSettings.standalone = false; + SIOUXSettings.setupmenus = false; + SIOUXSettings.autocloseonquit = true; + SIOUXSettings.asktosaveonclose = false; + SIOUXSettings.standalone = false; - UNUSED(argc); - UNUSED(argv); - - //HideWindow(SouixWin); + UNUSED(argc); + UNUSED(argv); + //HideWindow(SouixWin); } // HandleKey() @@ -448,48 +448,49 @@ BX_CPP_INLINE void HandleKey(EventRecord *event, Bit32u keyState) { UInt32 key; UInt32 trans; - static UInt32 transState = 0; + static UInt32 transState = 0; - key = event->message & charCodeMask; + key = event->message & charCodeMask; - if (event->modifiers & cmdKey) - { - HandleMenuChoice(MenuKey(key)); - } -// else if (FrontWindow() == SouixWin) -// { -// SIOUXHandleOneEvent(event); -// } - else - { -/* if (event->modifiers & shiftKey) - DEV_kbd_gen_scancode(BX_KEY_SHIFT_L | keyState); - if (event->modifiers & controlKey) - DEV_kbd_gen_scancode(BX_KEY_CTRL_L | keyState); - if (event->modifiers & optionKey) - DEV_kbd_gen_scancode(BX_KEY_ALT_L | keyState);*/ + if (event->modifiers & cmdKey) + { + HandleMenuChoice(MenuKey(key)); + } +//else if (FrontWindow() == SouixWin) +//{ +// SIOUXHandleOneEvent(event); +//} + else + { +/* if (event->modifiers & shiftKey) + DEV_kbd_gen_scancode(BX_KEY_SHIFT_L | keyState); + if (event->modifiers & controlKey) + DEV_kbd_gen_scancode(BX_KEY_CTRL_L | keyState); + if (event->modifiers & optionKey) + DEV_kbd_gen_scancode(BX_KEY_ALT_L | keyState);*/ - key = (event->message & keyCodeMask) >> 8; + key = (event->message & keyCodeMask) >> 8; - trans = KeyTranslate(KCHR, key, &transState); - if ((trans == BX_KEY_PRINT) && ((oldMods & optionKey) || (oldMods & rightOptionKey))) - trans = BX_KEY_ALT_SYSREQ; - if ((trans == BX_KEY_PAUSE) && ((oldMods & controlKey) || (oldMods & rightControlKey))) - trans = BX_KEY_CTRL_BREAK; - // KeyTranslate maps Mac virtual key codes to any type of character code - // you like (in this case, Bochs key codes). Much nicer than a huge switch - // statement! + trans = KeyTranslate(KCHR, key, &transState); + if ((trans == BX_KEY_PRINT) && ((oldMods & optionKey) || (oldMods & rightOptionKey))) + trans = BX_KEY_ALT_SYSREQ; + if ((trans == BX_KEY_PAUSE) && ((oldMods & controlKey) || (oldMods & rightControlKey))) + trans = BX_KEY_CTRL_BREAK; - if (trans > 0) - DEV_kbd_gen_scancode(trans | keyState); + // KeyTranslate maps Mac virtual key codes to any type of character code + // you like (in this case, Bochs key codes). Much nicer than a huge switch + // statement! -/* if (event->modifiers & shiftKey) - DEV_kbd_gen_scancode(BX_KEY_SHIFT_L | BX_KEY_RELEASED); - if (event->modifiers & controlKey) - DEV_kbd_gen_scancode(BX_KEY_CTRL_L | BX_KEY_RELEASED); - if (event->modifiers & optionKey) - DEV_kbd_gen_scancode(BX_KEY_ALT_L | BX_KEY_RELEASED);*/ - } + if (trans > 0) + DEV_kbd_gen_scancode(trans | keyState); + +/* if (event->modifiers & shiftKey) + DEV_kbd_gen_scancode(BX_KEY_SHIFT_L | BX_KEY_RELEASED); + if (event->modifiers & controlKey) + DEV_kbd_gen_scancode(BX_KEY_CTRL_L | BX_KEY_RELEASED); + if (event->modifiers & optionKey) + DEV_kbd_gen_scancode(BX_KEY_ALT_L | BX_KEY_RELEASED);*/ + } } // HandleToolClick() @@ -498,35 +499,35 @@ BX_CPP_INLINE void HandleKey(EventRecord *event, Bit32u keyState) BX_CPP_INLINE void HandleToolClick(Point where) { - unsigned i; - int xorigin; - Rect bounds; + unsigned i; + int xorigin; + Rect bounds; - SetPort(toolwin); - GlobalToLocal(&where); - for (i=0; iportRect.right - bx_tool_pixmap[i].xorigin; - SetRect(&bounds, xorigin, 0, xorigin+32, 32); - if (PtInRect(where, &bounds)) - bx_tool_pixmap[i].f(); - } - theGui->show_headerbar(); + SetPort(toolwin); + GlobalToLocal(&where); + for (i=0; iportRect.right - bx_tool_pixmap[i].xorigin; + SetRect(&bounds, xorigin, 0, xorigin+32, 32); + if (PtInRect(where, &bounds)) + bx_tool_pixmap[i].f(); + } + theGui->show_headerbar(); } BX_CPP_INLINE void ResetPointer(void) { #if 0 - CursorDevice *theMouse; - if (true) - { - theMouse = NULL; - CrsrDevNextDevice(&theMouse); - CrsrDevMoveTo(theMouse, (long)scrCenter.h, (long)scrCenter.v); - } + CursorDevice *theMouse; + if (true) + { + theMouse = NULL; + CrsrDevNextDevice(&theMouse); + CrsrDevMoveTo(theMouse, (long)scrCenter.h, (long)scrCenter.v); + } #endif #define MouseCur 0x082C @@ -534,10 +535,10 @@ BX_CPP_INLINE void ResetPointer(void) #define MouseNew 0x08CE #define MouseAttached 0x08CF - *(Point *)MouseCur = scrCenter; - *(Point *)MouseTemp = scrCenter; - *(Ptr)MouseNew = *(Ptr)MouseAttached; - //*(char *)CrsrNew = 0xFF; + *(Point *)MouseCur = scrCenter; + *(Point *)MouseTemp = scrCenter; + *(Ptr)MouseNew = *(Ptr)MouseAttached; + //*(char *)CrsrNew = 0xFF; } // HandleClick() @@ -547,187 +548,187 @@ BX_CPP_INLINE void ResetPointer(void) void HandleMenuChoice(long menuChoice) { - OSErr err = noErr; - short item, menu, i; - short daRefNum; - Rect bounds; - Str255 daName; - WindowRef newWindow; - DialogPtr theDlog; + OSErr err = noErr; + short item, menu, i; + short daRefNum; + Rect bounds; + Str255 daName; + WindowRef newWindow; + DialogPtr theDlog; - item = LoWord(menuChoice); - menu = HiWord(menuChoice); + item = LoWord(menuChoice); + menu = HiWord(menuChoice); - switch(menu) { - case mApple: - switch(item) - { - case iAbout: - theDlog = GetNewDialog(128, NULL, (WindowPtr)-1); - ModalDialog(NULL, &i); - DisposeDialog(theDlog); - break; + switch(menu) { + case mApple: + switch(item) { + case iAbout: + theDlog = GetNewDialog(128, NULL, (WindowPtr)-1); + ModalDialog(NULL, &i); + DisposeDialog(theDlog); + break; - default: - GetMenuItemText(GetMenuHandle(mApple), item, daName); - daRefNum = OpenDeskAcc( daName ); - break; - } - break; + default: + GetMenuItemText(GetMenuHandle(mApple), item, daName); + daRefNum = OpenDeskAcc(daName); + break; + } + break; - case mFile: - switch(item) - { - case iQuit: - BX_PANIC(("User terminated")); - break; + case mFile: + switch(item) { + case iQuit: + BX_PANIC(("User terminated")); + break; - default: - break; - } - break; + default: + break; + } + break; - case mBochs: - switch(item) - { - case iFloppy: - DiskEject(1); - break; - case iCursor: - if (cursorVisible) - HidePointer(); - else - ShowPointer(); - break; - case iTool: - if (IsWindowVisible(toolwin)) - HideTools(); - else - ShowTools(); - break; - case iMenuBar: - if (menubarVisible) - HideMenubar(); - else - ShowMenubar(); - break; - case iFullScreen: - if (cursorVisible || IsWindowVisible(toolwin) || menubarVisible) - { - if (cursorVisible) - HidePointer(); - if (menubarVisible) - HideMenubar(); - if (IsWindowVisible(toolwin)) - HideTools(); - } - else - { - if (!cursorVisible) - ShowPointer(); - if (!menubarVisible) - ShowMenubar(); - if (!IsWindowVisible(toolwin)) - ShowTools(); - } - break; - case iConsole: - if (IsWindowVisible(SouixWin)) - HideConsole(); - else - ShowConsole(); - break; - case iSnapshot: - //the following will break if snapshot is not last bitmap button instantiated - bx_tool_pixmap[toolPixMaps-1].f(); - break; - } + case mBochs: + switch(item) { + case iFloppy: + DiskEject(1); + break; - default: - break; + case iCursor: + if (cursorVisible) + HidePointer(); + else + ShowPointer(); + break; - } + case iTool: + if (IsWindowVisible(toolwin)) + HideTools(); + else + ShowTools(); + break; - HiliteMenu(0); + case iMenuBar: + if (menubarVisible) + HideMenubar(); + else + ShowMenubar(); + break; + + case iFullScreen: + if (cursorVisible || IsWindowVisible(toolwin) || menubarVisible) + { + if (cursorVisible) + HidePointer(); + if (menubarVisible) + HideMenubar(); + if (IsWindowVisible(toolwin)) + HideTools(); + } + else + { + if (!cursorVisible) + ShowPointer(); + if (!menubarVisible) + ShowMenubar(); + if (!IsWindowVisible(toolwin)) + ShowTools(); + } + break; + + case iConsole: + if (IsWindowVisible(SouixWin)) + HideConsole(); + else + ShowConsole(); + break; + + case iSnapshot: + // the following will break if snapshot is not last bitmap button instantiated + bx_tool_pixmap[toolPixMaps-1].f(); + break; + } + + default: + break; + } + + HiliteMenu(0); } BX_CPP_INLINE void HandleClick(EventRecord *event) { - short part; - WindowPtr whichWindow; - Rect dRect; + short part; + WindowPtr whichWindow; + Rect dRect; - part = FindWindow(event->where, &whichWindow); + part = FindWindow(event->where, &whichWindow); - switch(part) - { - case inContent: - if (whichWindow == win) - { - if (win != FrontWindow()) - SelectWindow(win); - if (event->modifiers & cmdKey) - mouse_button_state |= 0x02; - else - mouse_button_state |= 0x01; - } - else if (whichWindow == toolwin) - { - HiliteWindow(win, true); - HandleToolClick(event->where); - } - else if (whichWindow == backdrop) - { - SelectWindow(win); - } - else if (whichWindow == SouixWin) - { - SelectWindow(SouixWin); - } - break; + switch(part) + { + case inContent: + if (whichWindow == win) + { + if (win != FrontWindow()) + SelectWindow(win); + if (event->modifiers & cmdKey) + mouse_button_state |= 0x02; + else + mouse_button_state |= 0x01; + } + else if (whichWindow == toolwin) + { + HiliteWindow(win, true); + HandleToolClick(event->where); + } + else if (whichWindow == backdrop) + { + SelectWindow(win); + } + else if (whichWindow == SouixWin) + { + SelectWindow(SouixWin); + } + break; - case inDrag: - dRect = qd.screenBits.bounds; - if (IsWindowVisible(toolwin)) - dRect.top = gMaxTop; - DragWindow(whichWindow, event->where, &dRect); - break; + case inDrag: + dRect = qd.screenBits.bounds; + if (IsWindowVisible(toolwin)) + dRect.top = gMaxTop; + DragWindow(whichWindow, event->where, &dRect); + break; - case inMenuBar: - HandleMenuChoice(MenuSelect(event->where)); - break; - } + case inMenuBar: + HandleMenuChoice(MenuSelect(event->where)); + break; + } } void UpdateWindow(WindowPtr window) { - GrafPtr oldPort; - Rect box; + GrafPtr oldPort; + Rect box; - GetPort(&oldPort); + GetPort(&oldPort); - SetPort(window); - BeginUpdate(window); + SetPort(window); + BeginUpdate(window); - if (window == win) - { - box = window->portRect; - DEV_vga_redraw_area(box.left, box.top, box.right, box.bottom); - } - else if (window == backdrop) - { - box = window->portRect; - FillRect(&box, &qd.black); - } - else if (window == toolwin) - { - theGui->show_headerbar(); - } - else - { - } - EndUpdate(window); - SetPort(oldPort); + if (window == win) + { + box = window->portRect; + DEV_vga_redraw_area(box.left, box.top, box.right, box.bottom); + } + else if (window == backdrop) + { + box = window->portRect; + FillRect(&box, &qd.black); + } + else if (window == toolwin) + { + theGui->show_headerbar(); + } + + EndUpdate(window); + SetPort(oldPort); } // ::HANDLE_EVENTS() @@ -738,59 +739,59 @@ void UpdateWindow(WindowPtr window) void bx_macintosh_gui_c::handle_events(void) { - EventRecord event; - Point mousePt; - int dx, dy; - int oldMods1=0; + EventRecord event; + Point mousePt; + int dx, dy; + int oldMods1=0; EventModifiers newMods; - unsigned curstate; - GrafPtr oldport; + unsigned curstate; + GrafPtr oldport; - curstate = mouse_button_state; //so we can compare the old and the new mouse state + curstate = mouse_button_state; //so we can compare the old and the new mouse state - if (WaitNextEvent(everyEvent, &event, SLEEP_TIME, NULL)) - { - switch(event.what) - { - case nullEvent: - break; + if (WaitNextEvent(everyEvent, &event, SLEEP_TIME, NULL)) + { + switch(event.what) + { + case nullEvent: + break; - case mouseDown: - HandleClick(&event); - break; + case mouseDown: + HandleClick(&event); + break; - case mouseUp: - if (event.modifiers & cmdKey) - mouse_button_state &= ~0x02; - else - mouse_button_state &= ~0x01; - break; + case mouseUp: + if (event.modifiers & cmdKey) + mouse_button_state &= ~0x02; + else + mouse_button_state &= ~0x01; + break; - case keyDown: - case autoKey: - oldMods1 = event.modifiers; - HandleKey(&event, BX_KEY_PRESSED); - break; + case keyDown: + case autoKey: + oldMods1 = event.modifiers; + HandleKey(&event, BX_KEY_PRESSED); + break; - case keyUp: - event.modifiers = oldMods1; - HandleKey(&event, BX_KEY_RELEASED); - break; + case keyUp: + event.modifiers = oldMods1; + HandleKey(&event, BX_KEY_RELEASED); + break; - case updateEvt: - if ((WindowPtr)event.message == SouixWin) - SIOUXHandleOneEvent(&event); - else - UpdateWindow((WindowPtr)event.message); - break; + case updateEvt: + if ((WindowPtr)event.message == SouixWin) + SIOUXHandleOneEvent(&event); + else + UpdateWindow((WindowPtr)event.message); + break; - case diskEvt: - floppyA_handler(); + case diskEvt: + floppyA_handler(); - default: - break; - } - } + default: + break; + } + } else if (oldMods != (newMods = (event.modifiers & 0xfe00))) { if ((newMods ^ oldMods) & shiftKey) @@ -810,35 +811,33 @@ void bx_macintosh_gui_c::handle_events(void) oldMods = newMods; } - GetPort(&oldport); - SetPort(win); - - GetMouse(&mousePt); + GetPort(&oldport); + SetPort(win); + GetMouse(&mousePt); //if mouse has moved, or button has changed state - if ((!EqualPt(mousePt, prevPt)) || (curstate != mouse_button_state)) - { - dx = mousePt.h - prevPt.h; - dy = prevPt.v - mousePt.v; + if ((!EqualPt(mousePt, prevPt)) || (curstate != mouse_button_state)) + { + dx = mousePt.h - prevPt.h; + dy = prevPt.v - mousePt.v; - DEV_mouse_motion(dx, dy, mouse_button_state); + DEV_mouse_motion(dx, dy, mouse_button_state); - if (!cursorVisible) - { - SetPt(&scrCenter, 320, 240); - LocalToGlobal(&scrCenter); - ResetPointer(); //next getmouse should be 320, 240 - SetPt(&mousePt, 320, 240); - } - } + if (!cursorVisible) + { + SetPt(&scrCenter, 320, 240); + LocalToGlobal(&scrCenter); + ResetPointer(); //next getmouse should be 320, 240 + SetPt(&mousePt, 320, 240); + } + } - prevPt = mousePt; + prevPt = mousePt; - SetPort(oldport); + SetPort(oldport); } - // ::FLUSH() // // Called periodically, requesting that the gui code flush all pending @@ -846,11 +845,10 @@ void bx_macintosh_gui_c::handle_events(void) void bx_macintosh_gui_c::flush(void) { - // an opportunity to make the Window Manager happy. - // not needed on the macintosh.... + // an opportunity to make the Window Manager happy. + // not needed on the macintosh.... } - // ::CLEAR_SCREEN() // // Called to request that the VGA region is cleared. Don't @@ -858,16 +856,14 @@ void bx_macintosh_gui_c::flush(void) void bx_macintosh_gui_c::clear_screen(void) { - SetPort(win); + SetPort(win); - RGBForeColor(&black); - RGBBackColor(&white); + RGBForeColor(&black); + RGBBackColor(&white); - FillRect(&win->portRect, &qd.black); + FillRect(&win->portRect, &qd.black); } - - // ::TEXT_UPDATE() // // Called in a VGA text mode, to update the screen with @@ -891,91 +887,86 @@ void bx_macintosh_gui_c::text_update(Bit8u *old_text, Bit8u *new_text, unsigned long cursor_x, unsigned long cursor_y, bx_vga_tminfo_t tm_info) { - int i; - unsigned char achar; - int x, y; - static int previ; - int cursori; - Rect destRect; - RGBColor fgColor, bgColor; - GrafPtr oldPort; - unsigned nchars; - OSErr theError; + int i; + unsigned char achar; + int x, y; + static int previ; + int cursori; + Rect destRect; + RGBColor fgColor, bgColor; + GrafPtr oldPort; + unsigned nchars; + OSErr theError; - GetPort(&oldPort); + GetPort(&oldPort); - SetPort(win); + SetPort(win); - //current cursor position - cursori = (cursor_y * text_cols + cursor_x) * 2; + //current cursor position + cursori = (cursor_y * text_cols + cursor_x) * 2; - // Number of characters on screen, variable number of rows - nchars = text_cols * text_rows; + // Number of characters on screen, variable number of rows + nchars = text_cols * text_rows; - for (i=0; i> 4].rgb; +// fgColor = (**gCTable).ctTable[new_text[i+1] & 0x0F].rgb; +// bgColor = (**gCTable).ctTable[(new_text[i+1] & 0xF0) >> 4].rgb; -// RGBForeColor(&fgColor); -// RGBBackColor(&bgColor); +// RGBForeColor(&fgColor); +// RGBBackColor(&bgColor); - if (SIM->get_param_bool(BXPN_PRIVATE_COLORMAP)->get()) - { - PmForeColor(new_text[i+1] & 0x0F); - PmBackColor((new_text[i+1] & 0xF0) >> 4); - } - else - { - fgColor = (**gCTable).ctTable[new_text[i+1] & 0x0F].rgb; - bgColor = (**gCTable).ctTable[(new_text[i+1] & 0xF0) >> 4].rgb; + if (SIM->get_param_bool(BXPN_PRIVATE_COLORMAP)->get()) + { + PmForeColor(new_text[i+1] & 0x0F); + PmBackColor((new_text[i+1] & 0xF0) >> 4); + } + else + { + fgColor = (**gCTable).ctTable[new_text[i+1] & 0x0F].rgb; + bgColor = (**gCTable).ctTable[(new_text[i+1] & 0xF0) >> 4].rgb; - RGBForeColor(&fgColor); - RGBBackColor(&bgColor); - } + RGBForeColor(&fgColor); + RGBBackColor(&bgColor); + } - x = ((i/2) % text_cols)*FONT_WIDTH; - y = ((i/2) / text_cols)*FONT_HEIGHT; + x = ((i/2) % text_cols)*FONT_WIDTH; + y = ((i/2) / text_cols)*FONT_HEIGHT; - SetRect(&destRect, x, y, - x+FONT_WIDTH, y+FONT_HEIGHT); + SetRect(&destRect, x, y, x+FONT_WIDTH, y+FONT_HEIGHT); - CopyBits( vgafont[achar], &WINBITMAP(win), + CopyBits(vgafont[achar], &WINBITMAP(win), &srcTextRect, &destRect, srcCopy, NULL); - if ((theError = QDError()) != noErr) - BX_ERROR(("mac: CopyBits returned %hd", theError)); + if ((theError = QDError()) != noErr) + BX_ERROR(("mac: CopyBits returned %hd", theError)); - if (i == cursori) //invert the current cursor block - { - InvertRect(&destRect); - } + if (i == cursori) //invert the current cursor block + { + InvertRect(&destRect); + } + } + } - } - } + //previous cursor position + previ = cursori; -//previous cursor position - previ = cursori; - - SetPort(oldPort); + SetPort(oldPort); } - int -bx_macintosh_gui_c::get_clipboard_text(Bit8u **bytes, Bit32s *nbytes) +int bx_macintosh_gui_c::get_clipboard_text(Bit8u **bytes, Bit32s *nbytes) { return 0; } - int -bx_macintosh_gui_c::set_clipboard_text(char *text_snapshot, Bit32u len) +int bx_macintosh_gui_c::set_clipboard_text(char *text_snapshot, Bit32u len) { return 0; } - // ::PALETTE_CHANGE() // // Allocate a color in the native GUI, for this color, and put @@ -985,51 +976,53 @@ bx_macintosh_gui_c::set_clipboard_text(char *text_snapshot, Bit32u len) bx_bool bx_macintosh_gui_c::palette_change(unsigned index, unsigned red, unsigned green, unsigned blue) { - PaletteHandle thePal, oldpal; - GDHandle saveDevice; - CGrafPtr savePort; + PaletteHandle thePal, oldpal; + GDHandle saveDevice; + CGrafPtr savePort; GrafPtr oldPort; -/* if (gOffWorld != NULL) //(SIM->get_param_bool(BXPN_PRIVATE_COLORMAP)->get()) +/*if (gOffWorld != NULL) //(SIM->get_param_bool(BXPN_PRIVATE_COLORMAP)->get()) { GetGWorld(&savePort, &saveDevice); SetGWorld(gOffWorld, NULL); }*/ + if ((**gTile).pixelType != RGBDirect) { GetPort(&oldPort); SetPort(win); - (**gCTable).ctTable[index].value = index; - (**gCTable).ctTable[index].rgb.red = (red << 8); - (**gCTable).ctTable[index].rgb.green = (green << 8); - (**gCTable).ctTable[index].rgb.blue = (blue << 8); + (**gCTable).ctTable[index].value = index; + (**gCTable).ctTable[index].rgb.red = (red << 8); + (**gCTable).ctTable[index].rgb.green = (green << 8); + (**gCTable).ctTable[index].rgb.blue = (blue << 8); - SetEntries(index, index, (**gCTable).ctTable); + SetEntries(index, index, (**gCTable).ctTable); - CTabChanged(gCTable); + CTabChanged(gCTable); SetPort(oldPort); } -/* if (gOffWorld != NULL) //(SIM->get_param_bool(BXPN_PRIVATE_COLORMAP)->get()) + +/*if (gOffWorld != NULL) //(SIM->get_param_bool(BXPN_PRIVATE_COLORMAP)->get()) SetGWorld(savePort, saveDevice);*/ + if (SIM->get_param_bool(BXPN_PRIVATE_COLORMAP)->get()) { + thePal = NewPalette(index, gCTable, pmTolerant, 0x5000); + oldpal = GetPalette(win); - thePal = NewPalette(index, gCTable, pmTolerant, 0x5000); - oldpal = GetPalette(win); + SetPalette(win, thePal, false); + SetPalette(fullwin, thePal, false); + SetPalette(hidden, thePal, false); - SetPalette(win, thePal, false); - SetPalette(fullwin, thePal, false); - SetPalette(hidden, thePal, false); return(1); } return((**gTile).pixelType != RGBDirect); } - // ::GRAPHICS_TILE_UPDATE() // // Called to request that a tile of graphics be drawn to the @@ -1047,20 +1040,20 @@ bx_bool bx_macintosh_gui_c::palette_change(unsigned index, unsigned red, unsigne void bx_macintosh_gui_c::graphics_tile_update(Bit8u *tile, unsigned x0, unsigned y0) { - Rect destRect; - OSErr theError; - Ptr theBaseAddr; - GrafPtr oldPort; -/* GDHandle saveDevice; - CGrafPtr savePort; + Rect destRect; + OSErr theError; + Ptr theBaseAddr; + GrafPtr oldPort; +/*GDHandle saveDevice; + CGrafPtr savePort; - GetGWorld(&savePort, &saveDevice); + GetGWorld(&savePort, &saveDevice); - SetGWorld(gOffWorld, NULL); */ - GetPort(&oldPort); - SetPort(win); - destRect = srcTileRect; - OffsetRect(&destRect, x0, y0); + SetGWorld(gOffWorld, NULL); */ + GetPort(&oldPort); + SetPort(win); + destRect = srcTileRect; + OffsetRect(&destRect, x0, y0); //(**gTile).baseAddr = (Ptr)tile; if ((theBaseAddr = GetPixBaseAddr(gTile)) == NULL) @@ -1083,17 +1076,15 @@ void bx_macintosh_gui_c::graphics_tile_update(Bit8u *tile, unsigned x0, unsigned BlockMoveData(tile, theBaseAddr, (srcTileRect.bottom-srcTileRect.top) * GetPixRowBytes(gTile)); RGBForeColor(&black); RGBBackColor(&white); - CopyBits( GetPortBitMapForCopyBits(gOffWorld), &WINBITMAP(win), + CopyBits(GetPortBitMapForCopyBits(gOffWorld), &WINBITMAP(win), &srcTileRect, &destRect, srcCopy, NULL); if ((theError = QDError()) != noErr) BX_ERROR(("mac: CopyBits returned %hd", theError)); SetPort(oldPort); -// SetGWorld(savePort, saveDevice); +//SetGWorld(savePort, saveDevice); } - - // ::DIMENSION_UPDATE() // // Called when the VGA mode changes it's X,Y dimensions. @@ -1109,7 +1100,7 @@ void bx_macintosh_gui_c::graphics_tile_update(Bit8u *tile, unsigned x0, unsigned void bx_macintosh_gui_c::dimension_update(unsigned x, unsigned y, unsigned fheight, unsigned fwidth, unsigned bpp) { if ((bpp != 1) && (bpp != 2) && (bpp != 4) && (bpp != 8) && (bpp != 15) && (bpp != 16) && (bpp != 24) && (bpp != 32)) { - BX_PANIC(("%d bpp graphics mode not supported yet", bpp)); + BX_PANIC(("%d bpp graphics mode not supported yet", bpp)); } if (bpp != vga_bpp) { @@ -1121,30 +1112,30 @@ void bx_macintosh_gui_c::dimension_update(unsigned x, unsigned y, unsigned fheig CreateTile(); } if (fheight > 0) { - text_cols = x / fwidth; - text_rows = y / fheight; - if (fwidth != 8) { - x = x * 8 / fwidth; - } - if (fheight != 16) { - y = y * 16 / fheight; - } + text_cols = x / fwidth; + text_rows = y / fheight; + if (fwidth != 8) { + x = x * 8 / fwidth; + } + if (fheight != 16) { + y = y * 16 / fheight; + } + } + + if (x != width || y != height) + { + SizeWindow(win, x, y, false); + SizeWindow(fullwin, x, y, false); + SizeWindow(hidden, x, y, false); + width = x; + height = y; } - if (x != width || y != height) - { - SizeWindow(win, x, y, false); - SizeWindow(fullwin, x, y, false); - SizeWindow(hidden, x, y, false); - width = x; - height = y; - } host_xres = x; host_yres = y; host_bpp = bpp; } - // ::CREATE_BITMAP() // // Create a monochrome bitmap of size 'xdim' by 'ydim', which will @@ -1160,19 +1151,18 @@ void bx_macintosh_gui_c::dimension_update(unsigned x, unsigned y, unsigned fheig unsigned bx_macintosh_gui_c::create_bitmap(const unsigned char *bmap, unsigned xdim, unsigned ydim) { - unsigned i; - unsigned char *data; - long row_bytes, bytecount; + unsigned i; + unsigned char *data; + long row_bytes, bytecount; - bx_cicn[numPixMaps] = GetCIcon(numPixMaps+128); + bx_cicn[numPixMaps] = GetCIcon(numPixMaps+128); BX_ASSERT(bx_cicn[numPixMaps]); - numPixMaps++; + numPixMaps++; - return(numPixMaps-1); + return(numPixMaps-1); } - // ::HEADERBAR_BITMAP() // // Called to install a bitmap in the bochs headerbar (toolbar). @@ -1186,33 +1176,32 @@ unsigned bx_macintosh_gui_c::create_bitmap(const unsigned char *bmap, unsigned x unsigned bx_macintosh_gui_c::headerbar_bitmap(unsigned bmap_id, unsigned alignment, void (*f)(void)) { - unsigned hb_index; + unsigned hb_index; - toolPixMaps++; - hb_index = toolPixMaps-1; -// bx_tool_pixmap[hb_index].pm = bx_pixmap[bmap_id]; - bx_tool_pixmap[hb_index].cicn = bx_cicn[bmap_id]; - bx_tool_pixmap[hb_index].alignment = alignment; - bx_tool_pixmap[hb_index].f = f; + toolPixMaps++; + hb_index = toolPixMaps-1; +//bx_tool_pixmap[hb_index].pm = bx_pixmap[bmap_id]; + bx_tool_pixmap[hb_index].cicn = bx_cicn[bmap_id]; + bx_tool_pixmap[hb_index].alignment = alignment; + bx_tool_pixmap[hb_index].f = f; - if (alignment == BX_GRAVITY_LEFT) - { - bx_tool_pixmap[hb_index].xorigin = bx_bitmap_left_xorigin; - bx_tool_pixmap[hb_index].yorigin = 0; -// bx_bitmap_left_xorigin += (**bx_pixmap[bmap_id]).bounds.right; - bx_bitmap_left_xorigin += 34; - } - else - { -// bx_bitmap_right_xorigin += (**bx_pixmap[bmap_id]).bounds.right; - bx_bitmap_right_xorigin += 34; - bx_tool_pixmap[hb_index].xorigin = bx_bitmap_right_xorigin; - bx_tool_pixmap[hb_index].yorigin = 0; - } - return(hb_index); + if (alignment == BX_GRAVITY_LEFT) + { + bx_tool_pixmap[hb_index].xorigin = bx_bitmap_left_xorigin; + bx_tool_pixmap[hb_index].yorigin = 0; +// bx_bitmap_left_xorigin += (**bx_pixmap[bmap_id]).bounds.right; + bx_bitmap_left_xorigin += 34; + } + else + { +// bx_bitmap_right_xorigin += (**bx_pixmap[bmap_id]).bounds.right; + bx_bitmap_right_xorigin += 34; + bx_tool_pixmap[hb_index].xorigin = bx_bitmap_right_xorigin; + bx_tool_pixmap[hb_index].yorigin = 0; + } + return(hb_index); } - // ::SHOW_HEADERBAR() // // Show (redraw) the current headerbar, which is composed of @@ -1220,29 +1209,28 @@ unsigned bx_macintosh_gui_c::headerbar_bitmap(unsigned bmap_id, unsigned alignme void bx_macintosh_gui_c::show_headerbar(void) { - Rect destRect; - int i, xorigin; + Rect destRect; + int i, xorigin; - SetPort(toolwin); - RGBForeColor(&medGrey); - FillRect(&toolwin->portRect, &qd.black); - for (i=0; iportRect.right - bx_tool_pixmap[i].xorigin; + SetPort(toolwin); + RGBForeColor(&medGrey); + FillRect(&toolwin->portRect, &qd.black); + for (i=0; iportRect.right - bx_tool_pixmap[i].xorigin; - SetRect(&destRect, xorigin, 0, xorigin+32, 32); + SetRect(&destRect, xorigin, 0, xorigin+32, 32); - //changed, simply plot the cicn for that button, in the prescribed rectangle - PlotCIcon(&destRect, bx_tool_pixmap[i].cicn); - } - RGBForeColor(&black); + //changed, simply plot the cicn for that button, in the prescribed rectangle + PlotCIcon(&destRect, bx_tool_pixmap[i].cicn); + } + RGBForeColor(&black); } - // ::REPLACE_BITMAP() // // Replace the bitmap installed in the headerbar ID slot 'hbar_id', @@ -1258,12 +1246,11 @@ void bx_macintosh_gui_c::show_headerbar(void) void bx_macintosh_gui_c::replace_bitmap(unsigned hbar_id, unsigned bmap_id) { -// bx_tool_pixmap[hbar_id].pm = bx_pixmap[bmap_id]; - bx_tool_pixmap[hbar_id].cicn = bx_cicn[bmap_id]; - show_headerbar(); +//bx_tool_pixmap[hbar_id].pm = bx_pixmap[bmap_id]; + bx_tool_pixmap[hbar_id].cicn = bx_cicn[bmap_id]; + show_headerbar(); } - // ::EXIT() // // Called before bochs terminates, to allow for a graceful @@ -1271,32 +1258,32 @@ void bx_macintosh_gui_c::replace_bitmap(unsigned hbar_id, unsigned bmap_id) void bx_macintosh_gui_c::exit(void) { - if (!menubarVisible) - ShowMenubar(); // Make the menubar visible again - InitCursor(); + if (!menubarVisible) + ShowMenubar(); // Make the menubar visible again + InitCursor(); } #if 0 void bx_macintosh_gui_c::snapshot_handler(void) { - PicHandle ScreenShot; - long val; + PicHandle ScreenShot; + long val; - SetPort(win); + SetPort(win); - ScreenShot = OpenPicture(&win->portRect); + ScreenShot = OpenPicture(&win->portRect); - CopyBits(&win->portBits, &win->portBits, &win->portRect, &win->portRect, srcCopy, NULL); + CopyBits(&win->portBits, &win->portBits, &win->portRect, &win->portRect, srcCopy, NULL); - ClosePicture(); + ClosePicture(); - val = ZeroScrap(); + val = ZeroScrap(); - HLock((Handle)ScreenShot); - PutScrap(GetHandleSize((Handle)ScreenShot), 'PICT', *ScreenShot); - HUnlock((Handle)ScreenShot); + HLock((Handle)ScreenShot); + PutScrap(GetHandleSize((Handle)ScreenShot), 'PICT', *ScreenShot); + HUnlock((Handle)ScreenShot); - KillPicture(ScreenShot); + KillPicture(ScreenShot); } #endif @@ -1306,11 +1293,11 @@ void bx_macintosh_gui_c::snapshot_handler(void) void UpdateRgn(RgnHandle rgn) { - WindowPtr window; + WindowPtr window; - window = FrontWindow(); - PaintBehind(window, rgn); - CalcVisBehind(window, rgn); + window = FrontWindow(); + PaintBehind(window, rgn); + CalcVisBehind(window, rgn); } // HidePointer() @@ -1319,15 +1306,15 @@ void UpdateRgn(RgnHandle rgn) void HidePointer() { - HiliteMenu(0); - HideCursor(); - SetPort(win); - SetPt(&scrCenter, 320, 240); - LocalToGlobal(&scrCenter); - ResetPointer(); - GetMouse(&prevPt); - cursorVisible = false; - CheckItem(GetMenuHandle(mBochs), iCursor, false); + HiliteMenu(0); + HideCursor(); + SetPort(win); + SetPt(&scrCenter, 320, 240); + LocalToGlobal(&scrCenter); + ResetPointer(); + GetMouse(&prevPt); + cursorVisible = false; + CheckItem(GetMenuHandle(mBochs), iCursor, false); } // ShowPointer() @@ -1336,9 +1323,9 @@ void HidePointer() void ShowPointer() { - InitCursor(); - cursorVisible = true; - CheckItem(GetMenuHandle(mBochs), iCursor, true); + InitCursor(); + cursorVisible = true; + CheckItem(GetMenuHandle(mBochs), iCursor, true); } // HideTools() @@ -1347,17 +1334,17 @@ void ShowPointer() void HideTools() { - HideWindow(toolwin); - if (menubarVisible) - { - MoveWindow(win, gLeft, gMinTop, false); - } - else - { - MoveWindow(hidden, gLeft, gMinTop, false); - } - CheckItem(GetMenuHandle(mBochs), iTool, false); - HiliteWindow(win, true); + HideWindow(toolwin); + if (menubarVisible) + { + MoveWindow(win, gLeft, gMinTop, false); + } + else + { + MoveWindow(hidden, gLeft, gMinTop, false); + } + CheckItem(GetMenuHandle(mBochs), iTool, false); + HiliteWindow(win, true); } // ShowTools() @@ -1366,21 +1353,21 @@ void HideTools() void ShowTools() { - if (menubarVisible) - { - MoveWindow(win, gLeft, gMaxTop, false); - } - else - { - MoveWindow(hidden, gLeft, gMaxTop, false); - } - ShowWindow(toolwin); - BringToFront(toolwin); - SelectWindow(toolwin); - HiliteWindow(win, true); -// theGui->show_headerbar(); - CheckItem(GetMenuHandle(mBochs), iTool, true); - HiliteWindow(win, true); + if (menubarVisible) + { + MoveWindow(win, gLeft, gMaxTop, false); + } + else + { + MoveWindow(hidden, gLeft, gMaxTop, false); + } + ShowWindow(toolwin); + BringToFront(toolwin); + SelectWindow(toolwin); + HiliteWindow(win, true); +//theGui->show_headerbar(); + CheckItem(GetMenuHandle(mBochs), iTool, true); + HiliteWindow(win, true); } // HideMenubar() @@ -1389,35 +1376,35 @@ void ShowTools() void HideMenubar() { - Rect mBarRect; - RgnHandle grayRgn; + Rect mBarRect; + RgnHandle grayRgn; - grayRgn = LMGetGrayRgn(); - gOldMBarHeight = GetMBarHeight(); - LMSetMBarHeight(0); - mBarRgn = NewRgn(); - mBarRect = qd.screenBits.bounds; - mBarRect.bottom = mBarRect.top + gOldMBarHeight; - RectRgn(mBarRgn, &mBarRect); - UnionRgn(grayRgn, mBarRgn, grayRgn); - UpdateRgn(mBarRgn); + grayRgn = LMGetGrayRgn(); + gOldMBarHeight = GetMBarHeight(); + LMSetMBarHeight(0); + mBarRgn = NewRgn(); + mBarRect = qd.screenBits.bounds; + mBarRect.bottom = mBarRect.top + gOldMBarHeight; + RectRgn(mBarRgn, &mBarRect); + UnionRgn(grayRgn, mBarRgn, grayRgn); + UpdateRgn(mBarRgn); - cnrRgn = NewRgn(); - RectRgn(cnrRgn, &qd.screenBits.bounds); - DiffRgn(cnrRgn, grayRgn, cnrRgn); - UnionRgn(grayRgn, cnrRgn, grayRgn); - UpdateRgn(mBarRgn); + cnrRgn = NewRgn(); + RectRgn(cnrRgn, &qd.screenBits.bounds); + DiffRgn(cnrRgn, grayRgn, cnrRgn); + UnionRgn(grayRgn, cnrRgn, grayRgn); + UpdateRgn(mBarRgn); - HideWindow(win); - ShowWindow(backdrop); - SelectWindow(backdrop); - hidden = win; - win = fullwin; - ShowWindow(win); + HideWindow(win); + ShowWindow(backdrop); + SelectWindow(backdrop); + hidden = win; + win = fullwin; + ShowWindow(win); - SelectWindow(win); - menubarVisible = false; - CheckItem(GetMenuHandle(mBochs), iMenuBar, false); + SelectWindow(win); + menubarVisible = false; + CheckItem(GetMenuHandle(mBochs), iMenuBar, false); } // ShowMenubar() @@ -1426,45 +1413,45 @@ void HideMenubar() void ShowMenubar() { - RgnHandle grayRgn; - GrafPtr savePort; + RgnHandle grayRgn; + GrafPtr savePort; - grayRgn = LMGetGrayRgn(); - LMSetMBarHeight(gOldMBarHeight); - DiffRgn(grayRgn, mBarRgn, grayRgn); - DisposeRgn(mBarRgn); - DrawMenuBar(); + grayRgn = LMGetGrayRgn(); + LMSetMBarHeight(gOldMBarHeight); + DiffRgn(grayRgn, mBarRgn, grayRgn); + DisposeRgn(mBarRgn); + DrawMenuBar(); - GetPort(&savePort); - SetPort(LMGetWMgrPort()); - SetClip(cnrRgn); - FillRgn(cnrRgn, &qd.black); - SetPort(savePort); - DiffRgn(grayRgn, cnrRgn, grayRgn); - DisposeRgn(cnrRgn); + GetPort(&savePort); + SetPort(LMGetWMgrPort()); + SetClip(cnrRgn); + FillRgn(cnrRgn, &qd.black); + SetPort(savePort); + DiffRgn(grayRgn, cnrRgn, grayRgn); + DisposeRgn(cnrRgn); - HideWindow(backdrop); - win = hidden; - hidden = fullwin; - HideWindow(hidden); - ShowWindow(win); - HiliteWindow(win, true); + HideWindow(backdrop); + win = hidden; + hidden = fullwin; + HideWindow(hidden); + ShowWindow(win); + HiliteWindow(win, true); - menubarVisible = true; - CheckItem(GetMenuHandle(mBochs), iMenuBar, true); + menubarVisible = true; + CheckItem(GetMenuHandle(mBochs), iMenuBar, true); } void HideConsole() { - HideWindow(SouixWin); - CheckItem(GetMenuHandle(mBochs), iConsole, false); + HideWindow(SouixWin); + CheckItem(GetMenuHandle(mBochs), iConsole, false); } void ShowConsole() { - ShowWindow(SouixWin); - SelectWindow(SouixWin); - CheckItem(GetMenuHandle(mBochs), iConsole, true); + ShowWindow(SouixWin); + SelectWindow(SouixWin); + CheckItem(GetMenuHandle(mBochs), iConsole, true); } // CreateKeyMap() @@ -1473,149 +1460,146 @@ void ShowConsole() void CreateKeyMap(void) { - const unsigned char KCHRHeader [258] = { - 0, - 1 - }; + const unsigned char KCHRHeader [258] = { 0, 1 }; - const unsigned char KCHRTable [130] = { - 0, - 1, - BX_KEY_A, - BX_KEY_S, - BX_KEY_D, - BX_KEY_F, - BX_KEY_H, - BX_KEY_G, - BX_KEY_Z, - BX_KEY_X, - BX_KEY_C, - BX_KEY_V, - BX_KEY_LEFT_BACKSLASH, - BX_KEY_B, - BX_KEY_Q, - BX_KEY_W, - BX_KEY_E, - BX_KEY_R, - BX_KEY_Y, - BX_KEY_T, - BX_KEY_1, - BX_KEY_2, - BX_KEY_3, - BX_KEY_4, - BX_KEY_6, - BX_KEY_5, - BX_KEY_EQUALS, - BX_KEY_9, - BX_KEY_7, - BX_KEY_MINUS, - BX_KEY_8, - BX_KEY_0, - BX_KEY_RIGHT_BRACKET, - BX_KEY_O, - BX_KEY_U, - BX_KEY_LEFT_BRACKET, - BX_KEY_I, - BX_KEY_P, - BX_KEY_ENTER, - BX_KEY_L, - BX_KEY_J, - BX_KEY_SINGLE_QUOTE, - BX_KEY_K, - BX_KEY_SEMICOLON, - BX_KEY_BACKSLASH, - BX_KEY_COMMA, - BX_KEY_SLASH, - BX_KEY_N, - BX_KEY_M, - BX_KEY_PERIOD, - BX_KEY_TAB, - BX_KEY_SPACE, - BX_KEY_GRAVE, - BX_KEY_BACKSPACE, - BX_KEY_KP_ENTER, - BX_KEY_ESC, - 0, // 0x36 (record button) - 0, // 0x37 (cmd key) - 0, // 0x38 (left shift) - 0, // 0x39 (caps lock) - 0, // 0x3A (left option/alt) - 0, // 0x3B (left ctrl) - 0, // 0x3C (right shift) - 0, // 0x3D (right option/alt) - 0, // 0x3E (right ctrl) - 0, // 0x3F (fn key -- laptops) - 0, // 0x40 + const unsigned char KCHRTable [130] = { + 0, + 1, + BX_KEY_A, + BX_KEY_S, + BX_KEY_D, + BX_KEY_F, + BX_KEY_H, + BX_KEY_G, + BX_KEY_Z, + BX_KEY_X, + BX_KEY_C, + BX_KEY_V, + BX_KEY_LEFT_BACKSLASH, + BX_KEY_B, + BX_KEY_Q, + BX_KEY_W, + BX_KEY_E, + BX_KEY_R, + BX_KEY_Y, + BX_KEY_T, + BX_KEY_1, + BX_KEY_2, + BX_KEY_3, + BX_KEY_4, + BX_KEY_6, + BX_KEY_5, + BX_KEY_EQUALS, + BX_KEY_9, + BX_KEY_7, + BX_KEY_MINUS, + BX_KEY_8, + BX_KEY_0, + BX_KEY_RIGHT_BRACKET, + BX_KEY_O, + BX_KEY_U, + BX_KEY_LEFT_BRACKET, + BX_KEY_I, + BX_KEY_P, + BX_KEY_ENTER, + BX_KEY_L, + BX_KEY_J, + BX_KEY_SINGLE_QUOTE, + BX_KEY_K, + BX_KEY_SEMICOLON, + BX_KEY_BACKSLASH, + BX_KEY_COMMA, + BX_KEY_SLASH, + BX_KEY_N, + BX_KEY_M, + BX_KEY_PERIOD, + BX_KEY_TAB, + BX_KEY_SPACE, + BX_KEY_GRAVE, + BX_KEY_BACKSPACE, + BX_KEY_KP_ENTER, + BX_KEY_ESC, + 0, // 0x36 (record button) + 0, // 0x37 (cmd key) + 0, // 0x38 (left shift) + 0, // 0x39 (caps lock) + 0, // 0x3A (left option/alt) + 0, // 0x3B (left ctrl) + 0, // 0x3C (right shift) + 0, // 0x3D (right option/alt) + 0, // 0x3E (right ctrl) + 0, // 0x3F (fn key -- laptops) + 0, // 0x40 BX_KEY_KP_DELETE, // KP_PERIOD - 0, // 0x42 (move right/multiply) - BX_KEY_KP_MULTIPLY, - 0, // 0x44 - BX_KEY_KP_ADD, - 0, // 0x46 (move left/add) + 0, // 0x42 (move right/multiply) + BX_KEY_KP_MULTIPLY, + 0, // 0x44 + BX_KEY_KP_ADD, + 0, // 0x46 (move left/add) BX_KEY_NUM_LOCK, - 0, // 0x48 (move down/equals) - 0, // 0x49 - 0, // 0x4A - BX_KEY_KP_DIVIDE, - BX_KEY_KP_ENTER, - 0, // 0x4D (move up/divide) - BX_KEY_KP_SUBTRACT, - 0, // 0x4F - 0, // 0x50 + 0, // 0x48 (move down/equals) + 0, // 0x49 + 0, // 0x4A + BX_KEY_KP_DIVIDE, + BX_KEY_KP_ENTER, + 0, // 0x4D (move up/divide) + BX_KEY_KP_SUBTRACT, + 0, // 0x4F + 0, // 0x50 BX_KEY_EQUALS, // 0x51 (kp equals) BX_KEY_KP_INSERT, // 0x52 (kp 0) BX_KEY_KP_END, // 0x53 (kp 1) - BX_KEY_KP_DOWN, // 0x54 (kp 2) + BX_KEY_KP_DOWN, // 0x54 (kp 2) BX_KEY_KP_PAGE_DOWN, // 0x55 (kp 3) - BX_KEY_KP_LEFT, // 0x56 (kp 4) - BX_KEY_KP_5, - BX_KEY_KP_RIGHT, // 0x58 (kp 6) + BX_KEY_KP_LEFT, // 0x56 (kp 4) + BX_KEY_KP_5, + BX_KEY_KP_RIGHT, // 0x58 (kp 6) BX_KEY_KP_HOME, // 0x59 (kp 7) - 0, // 0x5A - BX_KEY_KP_UP, // 0x5B (kp 8) + 0, // 0x5A + BX_KEY_KP_UP, // 0x5B (kp 8) BX_KEY_KP_PAGE_UP, // 0x5C (kp 9) - 0, // 0x5D - 0, // 0x5E - 0, // 0x5F - BX_KEY_F5, - BX_KEY_F6, - BX_KEY_F7, - BX_KEY_F3, - BX_KEY_F8, - BX_KEY_F9, - 0, // 0x66 - BX_KEY_F11, - 0, // 0x68 + 0, // 0x5D + 0, // 0x5E + 0, // 0x5F + BX_KEY_F5, + BX_KEY_F6, + BX_KEY_F7, + BX_KEY_F3, + BX_KEY_F8, + BX_KEY_F9, + 0, // 0x66 + BX_KEY_F11, + 0, // 0x68 BX_KEY_PRINT, // 0x69 (print screen) - 0, // 0x6A + 0, // 0x6A BX_KEY_SCRL_LOCK, // 0x6B (scroll lock) - 0, // 0x6C - BX_KEY_F10, - BX_KEY_MENU, // 0x6E - BX_KEY_F12, - 0, // 0x70 + 0, // 0x6C + BX_KEY_F10, + BX_KEY_MENU, // 0x6E + BX_KEY_F12, + 0, // 0x70 BX_KEY_PAUSE, // 0x71 (pause) - BX_KEY_INSERT, - BX_KEY_HOME, - BX_KEY_PAGE_UP, - BX_KEY_DELETE, - BX_KEY_F4, - BX_KEY_END, - BX_KEY_F2, - BX_KEY_PAGE_DOWN, - BX_KEY_F1, - BX_KEY_LEFT, - BX_KEY_RIGHT, - BX_KEY_DOWN, - BX_KEY_UP - }; + BX_KEY_INSERT, + BX_KEY_HOME, + BX_KEY_PAGE_UP, + BX_KEY_DELETE, + BX_KEY_F4, + BX_KEY_END, + BX_KEY_F2, + BX_KEY_PAGE_DOWN, + BX_KEY_F1, + BX_KEY_LEFT, + BX_KEY_RIGHT, + BX_KEY_DOWN, + BX_KEY_UP + }; - KCHR = NewPtrClear(390); - if (KCHR == NULL) - BX_PANIC(("mac: can't allocate memory for key map")); + KCHR = NewPtrClear(390); + if (KCHR == NULL) + BX_PANIC(("mac: can't allocate memory for key map")); - BlockMove(KCHRHeader, KCHR, sizeof(KCHRHeader)); - BlockMove(KCHRTable, Ptr(KCHR + sizeof(KCHRHeader)), sizeof(KCHRTable)); + BlockMove(KCHRHeader, KCHR, sizeof(KCHRHeader)); + BlockMove(KCHRTable, Ptr(KCHR + sizeof(KCHRHeader)), sizeof(KCHRTable)); } // CreateVGAFont() @@ -1624,25 +1608,26 @@ void CreateKeyMap(void) void CreateVGAFont(void) { - int i, x; - unsigned char *fontData, curPixel; - long row_bytes, bytecount; + int i, x; + unsigned char *fontData, curPixel; + long row_bytes, bytecount; - for (i=0; i<256; i++) - { - vgafont[i] = CreateBitMap(FONT_WIDTH, FONT_HEIGHT); - row_bytes = (*(vgafont[i])).rowBytes; - bytecount = row_bytes * FONT_HEIGHT; - fontData = (unsigned char *)NewPtrClear(bytecount); + for (i=0; i<256; i++) + { + vgafont[i] = CreateBitMap(FONT_WIDTH, FONT_HEIGHT); + row_bytes = (*(vgafont[i])).rowBytes; + bytecount = row_bytes * FONT_HEIGHT; + fontData = (unsigned char *)NewPtrClear(bytecount); - for (x=0; x<16; x++) - { - //curPixel = ~(bx_vgafont[i].data[x]); - curPixel = (bx_vgafont[i].data[x]); - fontData[x*row_bytes] = reverse_bitorder(curPixel); - } - vgafont[i]->baseAddr = Ptr(fontData); - } + for (x=0; x<16; x++) + { + //curPixel = ~(bx_vgafont[i].data[x]); + curPixel = (bx_vgafont[i].data[x]); + fontData[x*row_bytes] = reverse_bitorder(curPixel); + } + + vgafont[i]->baseAddr = Ptr(fontData); + } } // CreateBitMap() @@ -1651,19 +1636,19 @@ void CreateVGAFont(void) BitMap *CreateBitMap(unsigned width, unsigned height) { - BitMap *bm; - long row_bytes; + BitMap *bm; + long row_bytes; - row_bytes = (( width + 31) >> 5) << 2; - bm = (BitMap *)calloc(1, sizeof(BitMap)); - if (bm == NULL) - BX_PANIC(("mac: can't allocate memory for pixmap")); - SetRect(&bm->bounds, 0, 0, width, height); - bm->rowBytes = row_bytes; - // Quickdraw allocates a new color table by default, but we want to - // use one we created earlier. + row_bytes = ((width + 31) >> 5) << 2; + bm = (BitMap *)calloc(1, sizeof(BitMap)); + if (bm == NULL) + BX_PANIC(("mac: can't allocate memory for pixmap")); + SetRect(&bm->bounds, 0, 0, width, height); + bm->rowBytes = row_bytes; + // Quickdraw allocates a new color table by default, but we want to + // use one we created earlier. - return bm; + return bm; } // CreatePixMap() @@ -1673,43 +1658,43 @@ BitMap *CreateBitMap(unsigned width, unsigned height) PixMapHandle CreatePixMap(unsigned left, unsigned top, unsigned width, unsigned height, unsigned depth, CTabHandle clut) { - PixMapHandle pm; - long row_bytes; + PixMapHandle pm; + long row_bytes; - row_bytes = (((long) depth * ((long) width) + 31) >> 5) << 2; - pm = NewPixMap(); - if (pm == NULL) - BX_PANIC(("mac: can't allocate memory for pixmap")); - (**pm).bounds.left = left; - (**pm).bounds.top = top; - (**pm).bounds.right = left+width; - (**pm).bounds.bottom = top+height; - (**pm).pixelSize = depth; - (**pm).rowBytes = row_bytes | 0x8000; + row_bytes = (((long) depth * ((long) width) + 31) >> 5) << 2; + pm = NewPixMap(); + if (pm == NULL) + BX_PANIC(("mac: can't allocate memory for pixmap")); + (**pm).bounds.left = left; + (**pm).bounds.top = top; + (**pm).bounds.right = left+width; + (**pm).bounds.bottom = top+height; + (**pm).pixelSize = depth; + (**pm).rowBytes = row_bytes | 0x8000; DisposeCTable((**pm).pmTable); (**pm).pmTable = clut; // Quickdraw allocates a new color table by default, but we want to // use one we created earlier. - return pm; + return pm; } unsigned char reverse_bitorder(unsigned char b) { - unsigned char ret=0; + unsigned char ret=0; - for (unsigned i=0; i<8; i++) - { - ret |= (b & 0x01) << (7-i); - b >>= 1; - } + for (unsigned i=0; i<8; i++) + { + ret |= (b & 0x01) << (7-i); + b >>= 1; + } - return(ret); + return(ret); } - void -bx_macintosh_gui_c::mouse_enabled_changed_specific (bx_bool val) +void bx_macintosh_gui_c::mouse_enabled_changed_specific (bx_bool val) { } + #endif /* if BX_WITH_MACOS */ diff --git a/bochs/gui/rfb.cc b/bochs/gui/rfb.cc index aed5b8898..6b39c8e40 100644 --- a/bochs/gui/rfb.cc +++ b/bochs/gui/rfb.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: rfb.cc,v 1.55 2008-02-05 22:57:41 sshwarts Exp $ +// $Id: rfb.cc,v 1.56 2008-02-15 22:05:40 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2000 Psyon.Org! @@ -360,18 +360,18 @@ void ServerThreadInit(void *indata) #ifdef WIN32 SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_IDLE); if(!InitWinsock()) { - BX_PANIC(( "could not initialize winsock.")); + BX_PANIC(("could not initialize winsock.")); goto end_of_thread; } #endif sServer = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if(sServer == -1) { - BX_PANIC(( "could not create socket." )); + BX_PANIC(("could not create socket.")); goto end_of_thread; } if (setsockopt(sServer, SOL_SOCKET, SO_REUSEADDR, (const char *)&one, sizeof(int)) == -1) { - BX_PANIC(( "could not set socket option." )); + BX_PANIC(("could not set socket option.")); goto end_of_thread; } @@ -381,11 +381,11 @@ void ServerThreadInit(void *indata) sai.sin_port = htons(rfbPort); BX_INFO (("Trying port %d", rfbPort)); if(bind(sServer, (struct sockaddr *)&sai, sizeof(sai)) == -1) { - BX_INFO(( "Could not bind socket.")); + BX_INFO(("Could not bind socket.")); continue; } if(listen(sServer, SOMAXCONN) == -1) { - BX_INFO(( "Could not listen on socket.")); + BX_INFO(("Could not listen on socket.")); continue; } // success @@ -722,7 +722,7 @@ void bx_rfb_gui_c::text_update(Bit8u *old_text, Bit8u *new_text, unsigned long c } // first invalidate character at previous and new cursor location - if ( (rfbCursorY < text_rows) && (rfbCursorX < text_cols) ) { + if ((rfbCursorY < text_rows) && (rfbCursorX < text_cols)) { curs = rfbCursorY * tm_info.line_offset + rfbCursorX * 2; old_text[curs] = ~new_text[curs]; } @@ -1730,7 +1730,7 @@ void rfbMouseMove(int x, int y, int bmask) xorigin = rfbHeaderbarBitmaps[i].xorigin; else xorigin = rfbWindowX - rfbHeaderbarBitmaps[i].xorigin; - if ( (x>=xorigin) && (x<(xorigin+int(rfbBitmaps[rfbHeaderbarBitmaps[i].index].xdim))) ) { + if ((x>=xorigin) && (x<(xorigin+int(rfbBitmaps[rfbHeaderbarBitmaps[i].index].xdim)))) { rfbHeaderbarBitmaps[i].f(); return; } diff --git a/bochs/gui/sdl.cc b/bochs/gui/sdl.cc index f737ad119..a4ef99327 100644 --- a/bochs/gui/sdl.cc +++ b/bochs/gui/sdl.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: sdl.cc,v 1.72 2008-02-05 22:57:41 sshwarts Exp $ +// $Id: sdl.cc,v 1.73 2008-02-15 22:05:40 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2002 MandrakeSoft S.A. @@ -23,6 +23,7 @@ // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +///////////////////////////////////////////////////////////////////////// #define _MULTI_THREAD @@ -214,6 +215,7 @@ void switch_to_fullscreen(void) 0xff000000 #endif ); + SDL_BlitSurface(sdl_screen,&src,tmp,&dst); SDL_UpdateRect(tmp,0,0,res_x,res_y); SDL_FreeSurface(sdl_screen); @@ -314,8 +316,7 @@ void bx_sdl_gui_c::specific_init( dimension_update(640,480); SDL_EnableKeyRepeat(250,50); - SDL_WM_SetCaption(BOCHS_WINDOW_NAME, - "Bochs" ); + SDL_WM_SetCaption(BOCHS_WINDOW_NAME, "Bochs"); SDL_WarpMouse(half_res_x, half_res_y); // load keymap for sdl @@ -352,7 +353,7 @@ void sdl_set_status_text(int element, const char *text, bx_bool active) int x, xleft, xsize; statusitem_active[element] = active; - if( !sdl_screen ) return; + if(!sdl_screen) return; disp = sdl_screen->pitch/4; xleft = statusitem_pos[element] + 2; xsize = statusitem_pos[element+1] - xleft - 1; @@ -370,9 +371,9 @@ void sdl_set_status_text(int element, const char *text, bx_bool active) do { *buf++ = bgcolor; - } while( --colsleft ); + } while(--colsleft); buf = buf_row + disp; - } while( --rowsleft ); + } while(--rowsleft); if ((element > 0) && (strlen(text) > 4)) { textlen = 4; } else { @@ -391,14 +392,14 @@ void sdl_set_status_text(int element, const char *text, bx_bool active) colsleft = 8; do { - if( (font_row & 0x80) != 0x00 ) + if((font_row & 0x80) != 0x00) *buf++ = fgcolor; else buf++; font_row <<= 1; - } while( --colsleft ); + } while(--colsleft); buf += (disp - 8); - } while( --rowsleft ); + } while(--rowsleft); buf = buf_row + 8; x++; } while (--textlen); @@ -468,7 +469,7 @@ void bx_sdl_gui_c::text_update( buf_row = (Uint32 *)sdl_fullscreen->pixels; } // first invalidate character at previous and new cursor location - if ( (prev_cursor_y < text_rows) && (prev_cursor_x < text_cols) ) { + if ((prev_cursor_y < text_rows) && (prev_cursor_x < text_cols)) { curs = prev_cursor_y * tm_info.line_offset + prev_cursor_x * 2; old_text[curs] = ~new_text[curs]; } @@ -543,7 +544,7 @@ void bx_sdl_gui_c::text_update( } // check if char needs to be updated if(forceUpdate || (old_text[0] != new_text[0]) - || (old_text[1] != new_text[1]) ) + || (old_text[1] != new_text[1])) { // Get Foreground/Background pixel colors @@ -586,23 +587,23 @@ void bx_sdl_gui_c::text_update( font_row <<= h_panning; } fontpixels = cfwidth; - if( (invert) && (fontline >= tm_info.cs_start) && (fontline <= tm_info.cs_end) ) + if ((invert) && (fontline >= tm_info.cs_start) && (fontline <= tm_info.cs_end)) mask = 0x100; else mask = 0x00; do { - if( (font_row & 0x100) == mask ) + if ((font_row & 0x100) == mask) *buf = bgcolor; else *buf = fgcolor; buf++; font_row <<= 1; - } while( --fontpixels ); + } while(--fontpixels); buf -= cfwidth; buf += disp; fontline++; - } while( --fontrows ); + } while(--fontrows); // restore output buffer ptr to start of this char buf = buf_char; @@ -617,7 +618,7 @@ void bx_sdl_gui_c::text_update( x++; // process one entire horizontal row - } while( --hchars ); + } while(--hchars); // go to next character row location buf_row += disp * cfheight; @@ -637,35 +638,30 @@ void bx_sdl_gui_c::text_update( cs_y++; y++; } - } while( --rows ); + } while(--rows); h_panning = tm_info.h_panning; prev_cursor_x = cursor_x; prev_cursor_y = cursor_y; } - int -bx_sdl_gui_c::get_clipboard_text(Bit8u **bytes, Bit32s *nbytes) +int bx_sdl_gui_c::get_clipboard_text(Bit8u **bytes, Bit32s *nbytes) { return 0; } - int -bx_sdl_gui_c::set_clipboard_text(char *text_snapshot, Bit32u len) +int bx_sdl_gui_c::set_clipboard_text(char *text_snapshot, Bit32u len) { return 0; } - -void bx_sdl_gui_c::graphics_tile_update( - Bit8u *snapshot, - unsigned x, - unsigned y) +void bx_sdl_gui_c::graphics_tile_update(Bit8u *snapshot, + unsigned x, unsigned y) { Uint32 *buf, disp; Uint32 *buf_row; int i,j; - if( sdl_screen ) + if(sdl_screen) { disp = sdl_screen->pitch/4; buf = (Uint32 *)sdl_screen->pixels + (headerbar_height+y)*disp + x; @@ -677,10 +673,10 @@ void bx_sdl_gui_c::graphics_tile_update( } i = tileheight; - if( i + y > res_y ) i = res_y - y; + if(i + y > res_y) i = res_y - y; // FIXME - if( i<=0 ) return; + if(i<=0) return; switch (vga_bpp) { @@ -692,9 +688,9 @@ void bx_sdl_gui_c::graphics_tile_update( do { *buf++ = palette[*snapshot++]; - } while( --j ); + } while(--j); buf = buf_row + disp; - } while( --i); + } while(--i); break; default: BX_PANIC(("%u bpp modes handled by new graphics API", vga_bpp)); @@ -943,23 +939,22 @@ static Bit32u sdl_sym_to_bx_key (SDLKey sym) } } - void bx_sdl_gui_c::handle_events(void) { Bit32u key_event; Bit8u mouse_state; int wheel_status; - while( SDL_PollEvent(&sdl_event) ) + while(SDL_PollEvent(&sdl_event)) { wheel_status = 0; - switch( sdl_event.type ) + switch(sdl_event.type) { case SDL_VIDEOEXPOSE: - if( sdl_fullscreen_toggle == 0 ) - SDL_UpdateRect( sdl_screen, 0,0, res_x, res_y+headerbar_height+statusbar_height ); + if(sdl_fullscreen_toggle == 0) + SDL_UpdateRect(sdl_screen, 0,0, res_x, res_y+headerbar_height+statusbar_height); else - SDL_UpdateRect( sdl_screen, 0,headerbar_height, res_x, res_y ); + SDL_UpdateRect(sdl_screen, 0,headerbar_height, res_x, res_y); break; case SDL_MOUSEMOTION: @@ -994,11 +989,11 @@ void bx_sdl_gui_c::handle_events(void) break; case SDL_MOUSEBUTTONDOWN: - if( (sdl_event.button.button == SDL_BUTTON_MIDDLE) + if((sdl_event.button.button == SDL_BUTTON_MIDDLE) && ((SDL_GetModState() & KMOD_CTRL) > 0) - && (sdl_fullscreen_toggle == 0) ) + && (sdl_fullscreen_toggle == 0)) { - if( sdl_grab == 0 ) + if(sdl_grab == 0) { SDL_ShowCursor(0); SDL_WM_GrabInput(SDL_GRAB_ON); @@ -1035,7 +1030,7 @@ void bx_sdl_gui_c::handle_events(void) ((mouse_state>>1)&0x02) | ((mouse_state<<1)&0x04) ; // filter out middle button if not fullscreen - if( sdl_fullscreen_toggle == 0 ) + if(sdl_fullscreen_toggle == 0) new_mousebuttons &= 0x07; // send motion information DEV_mouse_motion_ext( @@ -1052,11 +1047,11 @@ void bx_sdl_gui_c::handle_events(void) case SDL_KEYDOWN: // Windows/Fullscreen toggle-check - if( sdl_event.key.keysym.sym == SDLK_SCROLLOCK ) + if(sdl_event.key.keysym.sym == SDLK_SCROLLOCK) { -// SDL_WM_ToggleFullScreen( sdl_screen ); +// SDL_WM_ToggleFullScreen(sdl_screen); sdl_fullscreen_toggle = ~sdl_fullscreen_toggle; - if( sdl_fullscreen_toggle == 0 ) + if(sdl_fullscreen_toggle == 0) switch_to_windowed(); else switch_to_fullscreen(); @@ -1066,7 +1061,7 @@ void bx_sdl_gui_c::handle_events(void) } // convert sym->bochs code - if( sdl_event.key.keysym.sym > SDLK_LAST ) break; + if (sdl_event.key.keysym.sym > SDLK_LAST) break; if (!SIM->get_param_bool(BXPN_KBD_USEMAPPING)->get()) { key_event = sdl_sym_to_bx_key (sdl_event.key.keysym.sym); BX_DEBUG (("keypress scancode=%d, sym=%d, bx_key = %d", sdl_event.key.keysym.scancode, sdl_event.key.keysym.sym, key_event)); @@ -1081,18 +1076,18 @@ void bx_sdl_gui_c::handle_events(void) } key_event = entry->baseKey; } - if( key_event == BX_KEY_UNHANDLED ) break; - DEV_kbd_gen_scancode( key_event ); + if (key_event == BX_KEY_UNHANDLED) break; + DEV_kbd_gen_scancode( key_event); if ((key_event == BX_KEY_NUM_LOCK) || (key_event == BX_KEY_CAPS_LOCK)) { - DEV_kbd_gen_scancode( key_event | BX_KEY_RELEASED ); + DEV_kbd_gen_scancode(key_event | BX_KEY_RELEASED); } break; case SDL_KEYUP: // filter out release of Windows/Fullscreen toggle and unsupported keys - if( (sdl_event.key.keysym.sym != SDLK_SCROLLOCK) - && (sdl_event.key.keysym.sym < SDLK_LAST )) + if ((sdl_event.key.keysym.sym != SDLK_SCROLLOCK) + && (sdl_event.key.keysym.sym < SDLK_LAST)) { // convert sym->bochs code if (!SIM->get_param_bool(BXPN_KBD_USEMAPPING)->get()) { @@ -1108,11 +1103,11 @@ void bx_sdl_gui_c::handle_events(void) } key_event = entry->baseKey; } - if( key_event == BX_KEY_UNHANDLED ) break; + if (key_event == BX_KEY_UNHANDLED) break; if ((key_event == BX_KEY_NUM_LOCK) || (key_event == BX_KEY_CAPS_LOCK)) { - DEV_kbd_gen_scancode( key_event ); + DEV_kbd_gen_scancode(key_event); } - DEV_kbd_gen_scancode( key_event | BX_KEY_RELEASED ); + DEV_kbd_gen_scancode(key_event | BX_KEY_RELEASED); } break; @@ -1129,17 +1124,14 @@ void bx_sdl_gui_c::handle_events(void) #endif } - - void bx_sdl_gui_c::flush(void) { - if( sdl_screen ) - SDL_UpdateRect( sdl_screen,0,0,res_x,res_y+headerbar_height ); + if(sdl_screen) + SDL_UpdateRect(sdl_screen,0,0,res_x,res_y+headerbar_height); else - SDL_UpdateRect( sdl_fullscreen,0,0,res_x,res_y); + SDL_UpdateRect(sdl_fullscreen,0,0,res_x,res_y); } - void bx_sdl_gui_c::clear_screen(void) { int i = res_y, j; @@ -1147,15 +1139,15 @@ void bx_sdl_gui_c::clear_screen(void) Uint32 *buf, *buf_row; Uint32 disp; - if( sdl_screen ) + if(sdl_screen) { - color = SDL_MapRGB( sdl_screen->format, 0,0,0 ); + color = SDL_MapRGB(sdl_screen->format, 0,0,0); disp = sdl_screen->pitch/4; buf = (Uint32 *)sdl_screen->pixels + headerbar_height*disp; } - else if( sdl_fullscreen ) + else if(sdl_fullscreen) { - color = SDL_MapRGB( sdl_fullscreen->format, 0,0,0 ); + color = SDL_MapRGB(sdl_fullscreen->format, 0,0, 0); disp = sdl_fullscreen->pitch/4; buf = (Uint32 *)sdl_fullscreen->pixels; } @@ -1165,18 +1157,16 @@ void bx_sdl_gui_c::clear_screen(void) { buf_row = buf; j = res_x; - while( j-- ) *buf++ = color; + while(j--) *buf++ = color; buf = buf_row + disp; - } while( --i ); + } while(--i); - if( sdl_screen ) + if(sdl_screen) SDL_UpdateRect(sdl_screen,0,0,res_x,res_y+headerbar_height); else SDL_UpdateRect(sdl_fullscreen,0,0,res_x,res_y); } - - bx_bool bx_sdl_gui_c::palette_change( unsigned index, unsigned red, @@ -1187,17 +1177,16 @@ bx_bool bx_sdl_gui_c::palette_change( unsigned char palgreen = green & 0xFF; unsigned char palblue = blue & 0xFF; - if( index > 255 ) return 0; + if(index > 255) return 0; - if( sdl_screen ) - palette[index] = SDL_MapRGB( sdl_screen->format, palred, palgreen, palblue ); - else if( sdl_fullscreen ) - palette[index] = SDL_MapRGB( sdl_fullscreen->format, palred, palgreen, palblue ); + if(sdl_screen) + palette[index] = SDL_MapRGB(sdl_screen->format, palred, palgreen, palblue); + else if(sdl_fullscreen) + palette[index] = SDL_MapRGB(sdl_fullscreen->format, palred, palgreen, palblue); return 1; } - void bx_sdl_gui_c::dimension_update( unsigned x, unsigned y, @@ -1212,7 +1201,7 @@ void bx_sdl_gui_c::dimension_update( { BX_PANIC(("%d bpp graphics mode not supported", bpp)); } - if( fheight > 0 ) + if(fheight > 0) { fontheight = fheight; fontwidth = fwidth; @@ -1220,23 +1209,23 @@ void bx_sdl_gui_c::dimension_update( text_rows = y / fontheight; } - if( (x == res_x) && (y == res_y )) return; + if((x == res_x) && (y == res_y)) return; - if( sdl_screen ) + if(sdl_screen) { - SDL_FreeSurface( sdl_screen ); + SDL_FreeSurface(sdl_screen); sdl_screen = NULL; } - if( sdl_fullscreen ) + if(sdl_fullscreen) { - SDL_FreeSurface( sdl_fullscreen ); + SDL_FreeSurface(sdl_fullscreen); sdl_fullscreen = NULL; } - if( sdl_fullscreen_toggle == 0 ) + if(sdl_fullscreen_toggle == 0) { - sdl_screen = SDL_SetVideoMode( x, y+headerbar_height+statusbar_height, 32, SDL_SWSURFACE ); - if( !sdl_screen ) + sdl_screen = SDL_SetVideoMode(x, y+headerbar_height+statusbar_height, 32, SDL_SWSURFACE); + if(!sdl_screen) { LOG_THIS setonoff(LOGLEV_PANIC, ACT_FATAL); BX_PANIC (("Unable to set requested videomode: %ix%i: %s",x,y,SDL_GetError())); @@ -1245,17 +1234,17 @@ void bx_sdl_gui_c::dimension_update( sdl_screen->format, BX_HEADERBAR_FG_RED, BX_HEADERBAR_FG_GREEN, - BX_HEADERBAR_FG_BLUE ); + BX_HEADERBAR_FG_BLUE); headerbar_bg = SDL_MapRGB( sdl_screen->format, BX_HEADERBAR_BG_RED, BX_HEADERBAR_BG_GREEN, - BX_HEADERBAR_BG_BLUE ); + BX_HEADERBAR_BG_BLUE); } else { - sdl_fullscreen = SDL_SetVideoMode( x, y, 32, SDL_HWSURFACE|SDL_FULLSCREEN ); - if( !sdl_fullscreen ) + sdl_fullscreen = SDL_SetVideoMode(x, y, 32, SDL_HWSURFACE|SDL_FULLSCREEN); + if(!sdl_fullscreen) { LOG_THIS setonoff(LOGLEV_PANIC, ACT_FATAL); BX_PANIC (("Unable to set requested videomode: %ix%i: %s",x,y,SDL_GetError())); @@ -1268,11 +1257,8 @@ void bx_sdl_gui_c::dimension_update( bx_gui->show_headerbar(); } - -unsigned bx_sdl_gui_c::create_bitmap( - const unsigned char *bmap, - unsigned xdim, - unsigned ydim) +unsigned bx_sdl_gui_c::create_bitmap(const unsigned char *bmap, + unsigned xdim, unsigned ydim) { bitmaps *tmp = new bitmaps; Uint32 *buf, *buf_row; @@ -1301,7 +1287,7 @@ unsigned bx_sdl_gui_c::create_bitmap( 0x00000000 #endif ); - if( !tmp->surface ) + if(!tmp->surface) { delete tmp; bx_gui->exit(); @@ -1328,25 +1314,24 @@ unsigned bx_sdl_gui_c::create_bitmap( pixels = *bmap++; for(unsigned i=0;i<8;i++) { - if( (pixels & 0x01) == 0 ) + if((pixels & 0x01) == 0) *buf++ = headerbar_bg; else *buf++ = headerbar_fg; pixels = pixels >> 1; } - } while( --xdim ); + } while(--xdim); buf = buf_row + disp; - } while( --ydim ); + } while(--ydim); SDL_UpdateRect( tmp->surface, 0, 0, tmp->src.w, - tmp->src.h ); + tmp->src.h); sdl_bitmaps[n_sdl_bitmaps] = tmp; return n_sdl_bitmaps++; } - unsigned bx_sdl_gui_c::headerbar_bitmap( unsigned bmap_id, unsigned alignment, @@ -1354,9 +1339,9 @@ unsigned bx_sdl_gui_c::headerbar_bitmap( { unsigned hb_index; - if( bmap_id >= (unsigned)n_sdl_bitmaps ) return 0; + if(bmap_id >= (unsigned)n_sdl_bitmaps) return 0; - if ( (bx_headerbar_entries+1) > BX_MAX_HEADERBAR_ENTRIES ) + if ((bx_headerbar_entries+1) > BX_MAX_HEADERBAR_ENTRIES) BX_PANIC(("too many headerbar entries, increase BX_MAX_HEADERBAR_ENTRIES")); bx_headerbar_entries++; @@ -1388,7 +1373,7 @@ void bx_sdl_gui_c::replace_bitmap( sdl_bitmaps[old_id]->dst.x = -1; hb_entry[hbar_id].bmp_id = bmap_id; sdl_bitmaps[bmap_id]->dst.x = hb_dst.x; - if( sdl_bitmaps[bmap_id]->dst.x != -1 ) + if(sdl_bitmaps[bmap_id]->dst.x != -1) { if (hb_entry[hbar_id].alignment == BX_GRAVITY_RIGHT) { hb_dst.x = res_x - hb_dst.x; @@ -1403,11 +1388,10 @@ void bx_sdl_gui_c::replace_bitmap( hb_dst.x, sdl_bitmaps[bmap_id]->dst.y, sdl_bitmaps[bmap_id]->src.w, - sdl_bitmaps[bmap_id]->src.h ); + sdl_bitmaps[bmap_id]->src.h); } } - void bx_sdl_gui_c::show_headerbar(void) { Uint32 *buf; @@ -1419,7 +1403,7 @@ void bx_sdl_gui_c::show_headerbar(void) unsigned current_bmp, pos_x; SDL_Rect hb_dst; - if( !sdl_screen ) return; + if(!sdl_screen) return; disp = sdl_screen->pitch/4; buf = (Uint32 *)sdl_screen->pixels; @@ -1431,16 +1415,16 @@ void bx_sdl_gui_c::show_headerbar(void) do { *buf++ = headerbar_bg; - } while( --colsleft ); + } while(--colsleft); buf = buf_row + disp; - } while( --rowsleft ); + } while(--rowsleft); SDL_UpdateRect( sdl_screen, 0,0,res_x,headerbar_height); // go thru the bitmaps and display the active ones - while( bitmapscount-- ) + while(bitmapscount--) { current_bmp = hb_entry[bitmapscount].bmp_id; - if( sdl_bitmaps[current_bmp]->dst.x != -1 ) + if(sdl_bitmaps[current_bmp]->dst.x != -1) { hb_dst = sdl_bitmaps[current_bmp]->dst; if (hb_entry[bitmapscount].alignment == BX_GRAVITY_RIGHT) { @@ -1456,7 +1440,7 @@ void bx_sdl_gui_c::show_headerbar(void) hb_dst.x, sdl_bitmaps[current_bmp]->dst.y, sdl_bitmaps[current_bmp]->src.w, - sdl_bitmaps[current_bmp]->src.h ); + sdl_bitmaps[current_bmp]->src.h); } } // draw statusbar background @@ -1480,9 +1464,9 @@ void bx_sdl_gui_c::show_headerbar(void) *buf++ = headerbar_bg; } pos_x++; - } while( --colsleft ); + } while(--colsleft); buf = buf_row + disp; - } while( --rowsleft ); + } while(--rowsleft); SDL_UpdateRect( sdl_screen, 0,res_y+headerbar_height,res_x,statusbar_height); for (unsigned i=0; idst.x; else xorigin = res_x - sdl_bitmaps[hb_entry[i].bmp_id]->dst.x; - if ( (x>=xorigin) && (x<(xorigin+xdim)) ) { + if ( (x>=xorigin) && (x<(xorigin+xdim))) { hb_entry[i].f(); return; - } } + } } void bx_sdl_gui_c::exit(void) { - if( sdl_screen ) + if(sdl_screen) SDL_FreeSurface(sdl_screen); - if( sdl_fullscreen ) + if(sdl_fullscreen) SDL_FreeSurface(sdl_fullscreen); - while( n_sdl_bitmaps ) + while(n_sdl_bitmaps) { - SDL_FreeSurface( sdl_bitmaps[n_sdl_bitmaps-1]->surface ); + SDL_FreeSurface(sdl_bitmaps[n_sdl_bitmaps-1]->surface); n_sdl_bitmaps--; } } diff --git a/bochs/gui/svga.cc b/bochs/gui/svga.cc index 12a274cda..e06958571 100644 --- a/bochs/gui/svga.cc +++ b/bochs/gui/svga.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: svga.cc,v 1.15 2008-02-07 18:28:50 sshwarts Exp $ +// $Id: svga.cc,v 1.16 2008-02-15 22:05:40 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // This library is free software; you can redistribute it and/or @@ -105,7 +105,7 @@ void bx_svga_gui_c::specific_init( tilewidth = x_tilesize; tileheight = y_tilesize; - if(vga_init() != 0 ) + if(vga_init() != 0) { LOG_THIS setonoff(LOGLEV_PANIC, ACT_FATAL); BX_PANIC (("Unable to initialize SVGAlib")); @@ -454,7 +454,7 @@ bx_bool bx_svga_gui_c::palette_change( unsigned green, unsigned blue) { - if( index > 255 ) return 0; + if(index > 255) return 0; // without VGA_CLUT8 extension we have only 6 bits for each r,g,b value if (!clut8 && (red > 63 || green > 63 || blue > 63)) { @@ -481,7 +481,7 @@ void bx_svga_gui_c::dimension_update( if (bpp > 8) { BX_PANIC(("%d bpp graphics mode not supported yet", bpp)); } - if( fheight > 0 ) + if(fheight > 0) { text_cols = x / fwidth; text_rows = y / fheight; @@ -492,7 +492,7 @@ void bx_svga_gui_c::dimension_update( fontwidth = 8; } - if( (x == res_x) && (y == res_y )) return; + if ((x == res_x) && (y == res_y)) return; if (x == 640 && y == 480) { newmode = G640x480x256; diff --git a/bochs/gui/win32.cc b/bochs/gui/win32.cc index 0f7e77b7a..0ac91fe98 100644 --- a/bochs/gui/win32.cc +++ b/bochs/gui/win32.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: win32.cc,v 1.117 2008-02-05 22:57:41 sshwarts Exp $ +// $Id: win32.cc,v 1.118 2008-02-15 22:05:40 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2002 MandrakeSoft S.A. @@ -23,6 +23,7 @@ // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +///////////////////////////////////////////////////////////////////////// // Much of this file was written by: // David Ross @@ -343,20 +344,20 @@ Bit32u win32_to_bx_key[2][0x100] = 0, 0, /* 0x70 - 0x7f */ - 0, /* Todo: "Katakana" key ( ibm 133 ) for Japanese 106 keyboard */ + 0, /* Todo: "Katakana" key (ibm 133) for Japanese 106 keyboard */ 0, 0, - 0, /* Todo: "Ro" key ( ibm 56 ) for Japanese 106 keyboard */ + 0, /* Todo: "Ro" key (ibm 56) for Japanese 106 keyboard */ 0, 0, 0, 0, 0, - 0, /* Todo: "convert" key ( ibm 132 ) for Japanese 106 keyboard */ + 0, /* Todo: "convert" key (ibm 132) for Japanese 106 keyboard */ 0, - 0, /* Todo: "non-convert" key ( ibm 131 ) for Japanese 106 keyboard */ + 0, /* Todo: "non-convert" key (ibm 131) for Japanese 106 keyboard */ 0, - 0, /* Todo: "Yen" key ( ibm 14 ) for Japanese 106 keyboard */ + 0, /* Todo: "Yen" key (ibm 14) for Japanese 106 keyboard */ 0, 0, }, @@ -491,65 +492,65 @@ Bit32u win32_to_bx_key[2][0x100] = void bx_signal_handler(int); #endif -static void processMouseXY( int x, int y, int z, int windows_state, int implied_state_change) +static void processMouseXY(int x, int y, int z, int windows_state, int implied_state_change) { int bx_state; int old_bx_state; - EnterCriticalSection( &stInfo.mouseCS); - bx_state=( ( windows_state & MK_LBUTTON) ? 1 : 0 ) + ( ( windows_state & MK_RBUTTON) ? 2 : 0) + - ( ( windows_state & MK_MBUTTON) ? 4 : 0); + EnterCriticalSection(&stInfo.mouseCS); + bx_state=((windows_state & MK_LBUTTON) ? 1 : 0) + ((windows_state & MK_RBUTTON) ? 2 : 0) + + ((windows_state & MK_MBUTTON) ? 4 : 0); old_bx_state=bx_state ^ implied_state_change; - if ( old_bx_state!=mouse_button_state) + if (old_bx_state!=mouse_button_state) { /* Make up for missing message */ - BX_INFO(( "&&&missing mouse state change")); - EnterCriticalSection( &stInfo.keyCS); + BX_INFO(("&&&missing mouse state change")); + EnterCriticalSection(&stInfo.keyCS); enq_mouse_event(); mouse_button_state=old_bx_state; - enq_key_event( mouse_button_state, MOUSE_PRESSED); - LeaveCriticalSection( &stInfo.keyCS); + enq_key_event(mouse_button_state, MOUSE_PRESSED); + LeaveCriticalSection(&stInfo.keyCS); } ms_ydelta=ms_savedy-y; ms_xdelta=x-ms_savedx; ms_zdelta=z; ms_lastx=x; ms_lasty=y; - if ( bx_state!=mouse_button_state) + if (bx_state!=mouse_button_state) { - EnterCriticalSection( &stInfo.keyCS); + EnterCriticalSection(&stInfo.keyCS); enq_mouse_event(); mouse_button_state=bx_state; - enq_key_event( mouse_button_state, MOUSE_PRESSED); - LeaveCriticalSection( &stInfo.keyCS); + enq_key_event(mouse_button_state, MOUSE_PRESSED); + LeaveCriticalSection(&stInfo.keyCS); } - LeaveCriticalSection( &stInfo.mouseCS); + LeaveCriticalSection(&stInfo.mouseCS); } static void resetDelta() { - EnterCriticalSection( &stInfo.mouseCS); + EnterCriticalSection(&stInfo.mouseCS); ms_savedx=ms_lastx; ms_savedy=ms_lasty; ms_ydelta=ms_xdelta=ms_zdelta=0; - LeaveCriticalSection( &stInfo.mouseCS); + LeaveCriticalSection(&stInfo.mouseCS); } static void cursorWarped() { - EnterCriticalSection( &stInfo.mouseCS); - EnterCriticalSection( &stInfo.keyCS); + EnterCriticalSection(&stInfo.mouseCS); + EnterCriticalSection(&stInfo.keyCS); enq_mouse_event(); - LeaveCriticalSection( &stInfo.keyCS); + LeaveCriticalSection(&stInfo.keyCS); ms_lastx=stretched_x/2; ms_lasty=stretched_y/2; ms_savedx=ms_lastx; ms_savedy=ms_lasty; - LeaveCriticalSection( &stInfo.mouseCS); + LeaveCriticalSection(&stInfo.mouseCS); } // GUI thread must be dead/done in order to call terminateEmul -void terminateEmul(int reason) { - +void terminateEmul(int reason) +{ // We know that Critical Sections were inited when x_tilesize has been set // See bx_win32_gui_c::specific_init if (x_tilesize != 0) { @@ -562,7 +563,7 @@ void terminateEmul(int reason) { if (MemoryDC) DeleteDC (MemoryDC); if (MemoryBitmap) DeleteObject (MemoryBitmap); - if ( bitmap_info) delete[] (char*)bitmap_info; + if (bitmap_info) delete[] (char*)bitmap_info; for (unsigned b=0; bkey_event; - if ( key==MOUSE_MOTION) + if (key==MOUSE_MOTION) { - DEV_mouse_motion_ext( queue_event->mouse_x, + DEV_mouse_motion_ext(queue_event->mouse_x, queue_event->mouse_y, queue_event->mouse_z, queue_event->mouse_button_state); } // Check for mouse buttons first - else if ( key & MOUSE_PRESSED) { - DEV_mouse_motion_ext( 0, 0, 0, LOWORD(key)); + else if (key & MOUSE_PRESSED) { + DEV_mouse_motion_ext(0, 0, 0, LOWORD(key)); } else if (key & HEADERBAR_CLICKED) { headerbar_click(LOWORD(key)); @@ -1446,25 +1450,26 @@ void bx_win32_gui_c::handle_events(void) { // Called periodically, requesting that the gui code flush all pending // screen update requests. -void bx_win32_gui_c::flush(void) { - EnterCriticalSection( &stInfo.drawCS); +void bx_win32_gui_c::flush(void) +{ + EnterCriticalSection(&stInfo.drawCS); if (updated_area_valid) { // slight bugfix updated_area.right++; updated_area.bottom++; - InvalidateRect( stInfo.simWnd, &updated_area, FALSE); + InvalidateRect(stInfo.simWnd, &updated_area, FALSE); updated_area_valid = FALSE; } - LeaveCriticalSection( &stInfo.drawCS); + LeaveCriticalSection(&stInfo.drawCS); } - // ::CLEAR_SCREEN() // // Called to request that the VGA region is cleared. Don't // clear the area that defines the headerbar. -void bx_win32_gui_c::clear_screen(void) { +void bx_win32_gui_c::clear_screen(void) +{ HGDIOBJ oldObj; if (!stInfo.UIinited) return; @@ -1744,8 +1749,7 @@ void bx_win32_gui_c::text_update(Bit8u *old_text, Bit8u *new_text, LeaveCriticalSection(&stInfo.drawCS); } - int -bx_win32_gui_c::get_clipboard_text(Bit8u **bytes, Bit32s *nbytes) +int bx_win32_gui_c::get_clipboard_text(Bit8u **bytes, Bit32s *nbytes) { if (OpenClipboard(stInfo.simWnd)) { HGLOBAL hg = GetClipboardData(CF_TEXT); @@ -1766,8 +1770,7 @@ bx_win32_gui_c::get_clipboard_text(Bit8u **bytes, Bit32s *nbytes) } } - int -bx_win32_gui_c::set_clipboard_text(char *text_snapshot, Bit32u len) +int bx_win32_gui_c::set_clipboard_text(char *text_snapshot, Bit32u len) { if (OpenClipboard(stInfo.simWnd)) { HANDLE hMem = GlobalAlloc(GMEM_ZEROINIT, len); @@ -1822,7 +1825,8 @@ bx_bool bx_win32_gui_c::palette_change(unsigned index, unsigned red, // note: origin of tile and of window based on (0,0) being in the upper // left of the window. -void bx_win32_gui_c::graphics_tile_update(Bit8u *tile, unsigned x0, unsigned y0) { +void bx_win32_gui_c::graphics_tile_update(Bit8u *tile, unsigned x0, unsigned y0) +{ HDC hdc; HGDIOBJ oldObj; @@ -1831,7 +1835,7 @@ void bx_win32_gui_c::graphics_tile_update(Bit8u *tile, unsigned x0, unsigned y0) oldObj = SelectObject(MemoryDC, MemoryBitmap); - StretchDIBits( MemoryDC, x0, y0, x_tilesize, y_tilesize, 0, 0, + StretchDIBits(MemoryDC, x0, y0, x_tilesize, y_tilesize, 0, 0, x_tilesize, y_tilesize, tile, bitmap_info, DIB_RGB_COLORS, SRCCOPY); SelectObject(MemoryDC, oldObj); @@ -1888,7 +1892,7 @@ void bx_win32_gui_c::dimension_update(unsigned x, unsigned y, unsigned fheight, #endif } - if ( x==dimension_x && y==dimension_y && bpp==current_bpp) + if (x==dimension_x && y==dimension_y && bpp==current_bpp) return; dimension_x = x; dimension_y = y; @@ -1952,7 +1956,8 @@ void bx_win32_gui_c::dimension_update(unsigned x, unsigned y, unsigned fheight, // ydim: y dimension of bitmap unsigned bx_win32_gui_c::create_bitmap(const unsigned char *bmap, unsigned xdim, - unsigned ydim) { + unsigned ydim) +{ unsigned char *data; TBADDBITMAP tbab; @@ -1997,11 +2002,12 @@ unsigned bx_win32_gui_c::create_bitmap(const unsigned char *bmap, unsigned xdim, // the boundaries of this bitmap. unsigned bx_win32_gui_c::headerbar_bitmap(unsigned bmap_id, unsigned alignment, - void (*f)(void)) { + void (*f)(void)) +{ unsigned hb_index; TBBUTTON tbb[1]; - if ( (bx_headerbar_entries+1) > BX_MAX_HEADERBAR_ENTRIES ) + if ((bx_headerbar_entries+1) > BX_MAX_HEADERBAR_ENTRIES) terminateEmul(EXIT_HEADER_BITMAP_ERROR); bx_headerbar_entries++; @@ -2085,7 +2091,8 @@ void bx_win32_gui_c::replace_bitmap(unsigned hbar_id, unsigned bmap_id) // // Called before bochs terminates, to allow for a graceful // exit from the native GUI mechanism. -void bx_win32_gui_c::exit(void) { +void bx_win32_gui_c::exit(void) +{ printf("# In bx_win32_gui_c::exit(void)!\n"); // kill thread first... @@ -2098,7 +2105,8 @@ void bx_win32_gui_c::exit(void) { } -void create_vga_font(void) { +void create_vga_font(void) +{ unsigned char data[64]; // VGA font is 8 or 9 wide and up to 32 high @@ -2113,7 +2121,8 @@ void create_vga_font(void) { } -unsigned char reverse_bitorder(unsigned char b) { +unsigned char reverse_bitorder(unsigned char b) +{ unsigned char ret=0; for (unsigned i=0; i<8; i++) { @@ -2134,7 +2143,8 @@ COLORREF GetColorRef(unsigned char attr) void DrawBitmap(HDC hdc, HBITMAP hBitmap, int xStart, int yStart, int width, - int height, int fcol, int frow, DWORD dwRop, unsigned char cColor) { + int height, int fcol, int frow, DWORD dwRop, unsigned char cColor) +{ BITMAP bm; HDC hdcMem; POINT ptSize, ptOrg; @@ -2172,7 +2182,8 @@ void DrawBitmap(HDC hdc, HBITMAP hBitmap, int xStart, int yStart, int width, } -void updateUpdated(int x1, int y1, int x2, int y2) { +void updateUpdated(int x1, int y1, int x2, int y2) +{ x1*=stretch_factor; x2*=stretch_factor; if (!updated_area_valid) { @@ -2252,7 +2263,8 @@ void bx_win32_gui_c::show_ips(Bit32u ips_count) #if BX_USE_WINDOWS_FONTS void DrawChar (HDC hdc, unsigned char c, int xStart, int yStart, - unsigned char cColor, int cs_start, int cs_end) { + unsigned char cColor, int cs_start, int cs_end) +{ HDC hdcMem; POINT ptSize, ptOrg; HGDIOBJ oldObj; diff --git a/bochs/gui/wx.cc b/bochs/gui/wx.cc index 93867ab83..bb03bbca7 100644 --- a/bochs/gui/wx.cc +++ b/bochs/gui/wx.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////// -// $Id: wx.cc,v 1.93 2008-02-05 22:57:41 sshwarts Exp $ +// $Id: wx.cc,v 1.94 2008-02-15 22:05:40 sshwarts Exp $ ///////////////////////////////////////////////////////////////// // // wxWidgets VGA display for Bochs. wx.cc implements a custom @@ -27,10 +27,6 @@ // ///////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////// -// includes -////////////////////////////////////////////////////////////// - // Define BX_PLUGGABLE in files that can be compiled into plugins. For // platforms that require a special tag on exported symbols, BX_PLUGGABLE // is used to know when we are exporting symbols and when we are importing. @@ -239,7 +235,7 @@ void MyPanel::OnMouse(wxMouseEvent& event) } ) - if (event.MiddleDown () && event.ControlDown ()) { + if (event.MiddleDown() && event.ControlDown()) { ToggleMouse (false); return; } @@ -249,9 +245,9 @@ void MyPanel::OnMouse(wxMouseEvent& event) // process buttons and motion together Bit32u buttons; - buttons = event.LeftIsDown () ? 1 : 0; - buttons |= event.RightIsDown () ? 2 : 0; - buttons |= event.MiddleIsDown () ? 4 : 0; + buttons = event.LeftIsDown() ? 1 : 0; + buttons |= event.RightIsDown() ? 2 : 0; + buttons |= event.MiddleIsDown() ? 4 : 0; if (x==mouseSavedX && y==mouseSavedY && !event.IsButton ()) { // nothing happened. This could have been generated by the WarpPointer. return; @@ -282,8 +278,7 @@ void MyPanel::OnMouse(wxMouseEvent& event) // will move the cursor to (mouseSavedX, mouseSavedY). } -void -MyPanel::MyRefresh () +void MyPanel::MyRefresh () { IFDBG_VGA (wxLogDebug (wxT ("set needRefresh=true"))); needRefresh = true; @@ -310,10 +305,8 @@ void MyPanel::OnKeyUp(wxKeyEvent& event) } } - /// copied right out of gui/x.cc -static char -wxAsciiKey[0x5f] = { +static char wxAsciiKey[0x5f] = { // !"#$%&' BX_KEY_SPACE, BX_KEY_1, @@ -437,8 +430,7 @@ wxAsciiKey[0x5f] = { }; // copied from gui/win32.cc -Bit32u -wxMSW_to_bx_key[0x59] = { +Bit32u wxMSW_to_bx_key[0x59] = { /* 0x00 - 0x0f */ 0, BX_KEY_ESC, @@ -544,8 +536,7 @@ wxMSW_to_bx_key[0x59] = { #endif // MS Windows specific key mapping, which uses wxKeyEvent::m_rawCode & 2. -bx_bool -MyPanel::fillBxKeyEvent_MSW (wxKeyEvent& wxev, BxKeyEvent& bxev, bx_bool release) +bx_bool MyPanel::fillBxKeyEvent_MSW (wxKeyEvent& wxev, BxKeyEvent& bxev, bx_bool release) { #if defined(wxHAS_RAW_KEY_CODES) && defined(__WXMSW__) IFDBG_KEY(wxLogDebug (wxT ("fillBxKeyEvent_MSW. key code %d, raw codes %d %d", wxev.m_keyCode, wxev.m_rawCode, wxev.m_rawFlags))); @@ -572,8 +563,7 @@ MyPanel::fillBxKeyEvent_MSW (wxKeyEvent& wxev, BxKeyEvent& bxev, bx_bool release #endif // GTK specific key mapping, which uses wxKeyEvent::m_rawCode. -bx_bool -MyPanel::fillBxKeyEvent_GTK (wxKeyEvent& wxev, BxKeyEvent& bxev, bx_bool release) +bx_bool MyPanel::fillBxKeyEvent_GTK (wxKeyEvent& wxev, BxKeyEvent& bxev, bx_bool release) { #if defined (wxHAS_RAW_KEY_CODES) && defined(__WXGTK__) IFDBG_KEY(wxLogDebug (wxT ("fillBxKeyEvent_GTK. key code %ld, raw codes %d %d", wxev.m_keyCode, wxev.m_rawCode, wxev.m_rawFlags))); @@ -729,14 +719,14 @@ MyPanel::fillBxKeyEvent_GTK (wxKeyEvent& wxev, BxKeyEvent& bxev, bx_bool release #endif default: - wxLogError(wxT ("fillBxKeyEvent_GTK(): keysym %x unhandled!"), (unsigned) keysym ); + wxLogError(wxT("fillBxKeyEvent_GTK(): keysym %x unhandled!"), (unsigned) keysym); return BX_KEY_UNHANDLED; } } else { /* use mapping */ BXKeyEntry *entry = bx_keymap.findHostKey (keysym); if (!entry) { - BX_ERROR(( "fillBxKeyEvent_GTK(): keysym %x unhandled!", (unsigned) keysym )); + BX_ERROR(("fillBxKeyEvent_GTK(): keysym %x unhandled!", (unsigned) keysym)); return BX_KEY_UNHANDLED; } key_event = entry->baseKey; @@ -749,8 +739,7 @@ MyPanel::fillBxKeyEvent_GTK (wxKeyEvent& wxev, BxKeyEvent& bxev, bx_bool release #endif } -bx_bool -MyPanel::fillBxKeyEvent (wxKeyEvent& wxev, BxKeyEvent& bxev, bx_bool release) +bx_bool MyPanel::fillBxKeyEvent (wxKeyEvent& wxev, BxKeyEvent& bxev, bx_bool release) { // Use raw codes if they are available. Raw codes are a nonstandard addition // to the wxWidgets library. At present, the only way to use the "RAW_CODES" @@ -873,13 +862,11 @@ MyPanel::fillBxKeyEvent (wxKeyEvent& wxev, BxKeyEvent& bxev, bx_bool release) return true; } - ////////////////////////////////////////////////////////////// // fill in methods of bx_gui ////////////////////////////////////////////////////////////// - void -bx_wx_gui_c::specific_init(int argc, char **argv, unsigned tilewidth, unsigned tileheight, +void bx_wx_gui_c::specific_init(int argc, char **argv, unsigned tilewidth, unsigned tileheight, unsigned headerbar_y) { int b,i,j; @@ -1051,10 +1038,9 @@ void bx_wx_gui_c::handle_events(void) num_events = 0; } -void -bx_wx_gui_c::statusbar_setitem(int element, bx_bool active) +void bx_wx_gui_c::statusbar_setitem(int element, bx_bool active) { -#if defined( __WXMSW__) +#if defined(__WXMSW__) char status_text[10]; #endif @@ -1062,7 +1048,7 @@ bx_wx_gui_c::statusbar_setitem(int element, bx_bool active) if (element < 0) { for (unsigned i = 0; i < statusitem_count; i++) { if (active) { -#if defined( __WXMSW__) +#if defined(__WXMSW__) status_text[0] = 9; strcpy(status_text+1, statusitem_text[i]); theFrame->SetStatusText(status_text, i+1); @@ -1075,7 +1061,7 @@ bx_wx_gui_c::statusbar_setitem(int element, bx_bool active) } } else if ((unsigned)element < statusitem_count) { if (active) { -#if defined( __WXMSW__) +#if defined(__WXMSW__) status_text[0] = 9; strcpy(status_text+1, statusitem_text[element]); theFrame->SetStatusText(status_text, element+1); @@ -1095,19 +1081,16 @@ bx_wx_gui_c::statusbar_setitem(int element, bx_bool active) // Called periodically, requesting that the gui code flush all pending // screen update requests. - void -bx_wx_gui_c::flush(void) +void bx_wx_gui_c::flush(void) { } - // ::CLEAR_SCREEN() // // Called to request that the VGA region is cleared. Don't // clear the area that defines the headerbar. - void -bx_wx_gui_c::clear_screen(void) +void bx_wx_gui_c::clear_screen(void) { IFDBG_VGA(wxLogDebug (wxT ("MyPanel::clear_screen trying to get lock. wxScreen=%p", wxScreen))); wxCriticalSectionLocker lock(wxScreen_lock); @@ -1116,8 +1099,7 @@ bx_wx_gui_c::clear_screen(void) thePanel->MyRefresh (); } -static void -UpdateScreen(unsigned char *newBits, int x, int y, int width, int height) +static void UpdateScreen(unsigned char *newBits, int x, int y, int width, int height) { IFDBG_VGA(wxLogDebug (wxT ("MyPanel::UpdateScreen trying to get lock. wxScreen=%p", wxScreen))); wxCriticalSectionLocker lock(wxScreen_lock); @@ -1147,8 +1129,7 @@ UpdateScreen(unsigned char *newBits, int x, int y, int width, int height) } } -static void -DrawBochsBitmap(int x, int y, int width, int height, char *bmap, char color, int fontx, int fonty, bx_bool gfxchar) +static void DrawBochsBitmap(int x, int y, int width, int height, char *bmap, char color, int fontx, int fonty, bx_bool gfxchar) { static unsigned char newBits[9 * 32]; unsigned char mask; @@ -1368,10 +1349,9 @@ void bx_wx_gui_c::text_update(Bit8u *old_text, Bit8u *new_text, wxCursorX = cursor_x; wxCursorY = cursor_y; - thePanel->MyRefresh (); + thePanel->MyRefresh(); } - // ::PALETTE_CHANGE() // // Allocate a color in the native GUI, for this color, and put @@ -1379,8 +1359,7 @@ void bx_wx_gui_c::text_update(Bit8u *old_text, Bit8u *new_text, // returns: 0=no screen update needed (color map change has direct effect) // 1=screen update needed (redraw using current colormap) - bx_bool -bx_wx_gui_c::palette_change(unsigned index, unsigned red, unsigned green, unsigned blue) +bx_bool bx_wx_gui_c::palette_change(unsigned index, unsigned red, unsigned green, unsigned blue) { IFDBG_VGA(wxLogDebug (wxT ("palette_change"))); wxBochsPalette[index].red = red; @@ -1409,11 +1388,10 @@ void bx_wx_gui_c::graphics_tile_update(Bit8u *tile, unsigned x0, unsigned y0) { IFDBG_VGA (wxLogDebug (wxT ("graphics_tile_update"))); UpdateScreen(tile, x0, y0, wxTileX, wxTileY); - thePanel->MyRefresh (); + thePanel->MyRefresh(); } - bx_svga_tileinfo_t * -bx_wx_gui_c::graphics_tile_info(bx_svga_tileinfo_t *info) +bx_svga_tileinfo_t *bx_wx_gui_c::graphics_tile_info(bx_svga_tileinfo_t *info) { if (!info) { info = (bx_svga_tileinfo_t *)malloc(sizeof(bx_svga_tileinfo_t)); @@ -1434,10 +1412,9 @@ bx_wx_gui_c::graphics_tile_info(bx_svga_tileinfo_t *info) info->is_little_endian = 1; return info; -}; +} - Bit8u * -bx_wx_gui_c::graphics_tile_get(unsigned x0, unsigned y0, +Bit8u *bx_wx_gui_c::graphics_tile_get(unsigned x0, unsigned y0, unsigned *w, unsigned *h) { if (x0+wxTileX > (unsigned)wxScreenX) { @@ -1457,8 +1434,7 @@ bx_wx_gui_c::graphics_tile_get(unsigned x0, unsigned y0, return (Bit8u *)wxScreen + y0 * wxScreenX * 3 + x0 * 3; } - void -bx_wx_gui_c::graphics_tile_update_in_place(unsigned x0, unsigned y0, +void bx_wx_gui_c::graphics_tile_update_in_place(unsigned x0, unsigned y0, unsigned w, unsigned h) { thePanel->MyRefresh(); @@ -1532,8 +1508,7 @@ void bx_wx_gui_c::dimension_update(unsigned x, unsigned y, unsigned fheight, uns // xdim: x dimension of bitmap // ydim: y dimension of bitmap - unsigned -bx_wx_gui_c::create_bitmap(const unsigned char *bmap, unsigned xdim, unsigned ydim) +unsigned bx_wx_gui_c::create_bitmap(const unsigned char *bmap, unsigned xdim, unsigned ydim) { UNUSED(bmap); UNUSED(xdim); @@ -1556,8 +1531,7 @@ bx_wx_gui_c::create_bitmap(const unsigned char *bmap, unsigned xdim, unsigned yd // f: a 'C' function pointer to callback when the mouse is clicked in // the boundaries of this bitmap. - unsigned -bx_wx_gui_c::headerbar_bitmap(unsigned bmap_id, unsigned alignment, void (*f)(void)) +unsigned bx_wx_gui_c::headerbar_bitmap(unsigned bmap_id, unsigned alignment, void (*f)(void)) { UNUSED(bmap_id); UNUSED(alignment); @@ -1565,18 +1539,15 @@ bx_wx_gui_c::headerbar_bitmap(unsigned bmap_id, unsigned alignment, void (*f)(vo return(0); } - // ::SHOW_HEADERBAR() // // Show (redraw) the current headerbar, which is composed of // currently installed bitmaps. - void -bx_wx_gui_c::show_headerbar(void) +void bx_wx_gui_c::show_headerbar(void) { } - // ::REPLACE_BITMAP() // // Replace the bitmap installed in the headerbar ID slot 'hbar_id', @@ -1613,9 +1584,7 @@ void bx_wx_gui_c::mouse_enabled_changed_specific(bx_bool val) mouse_captured = val; } - - int -bx_wx_gui_c::get_clipboard_text(Bit8u **bytes, Bit32s *nbytes) +int bx_wx_gui_c::get_clipboard_text(Bit8u **bytes, Bit32s *nbytes) { int ret = 0; wxMutexGuiEnter(); @@ -1641,8 +1610,7 @@ bx_wx_gui_c::get_clipboard_text(Bit8u **bytes, Bit32s *nbytes) return ret; } - int -bx_wx_gui_c::set_clipboard_text(char *text_snapshot, Bit32u len) +int bx_wx_gui_c::set_clipboard_text(char *text_snapshot, Bit32u len) { wxMutexGuiEnter(); int ret = 0; diff --git a/bochs/gui/wxdialog.cc b/bochs/gui/wxdialog.cc index a571193dc..aaad07a00 100644 --- a/bochs/gui/wxdialog.cc +++ b/bochs/gui/wxdialog.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////// -// $Id: wxdialog.cc,v 1.104 2008-02-05 22:57:41 sshwarts Exp $ +// $Id: wxdialog.cc,v 1.105 2008-02-15 22:05:40 sshwarts Exp $ ///////////////////////////////////////////////////////////////// // Define BX_PLUGGABLE in files that can be compiled into plugins. For @@ -148,7 +148,7 @@ void LogMsgAskDialog::OnEvent(wxCommandEvent& event) void LogMsgAskDialog::ShowHelp() { - wxMessageBox(MSG_NO_HELP, MSG_NO_HELP_CAPTION, wxOK | wxICON_ERROR, this ); + wxMessageBox(MSG_NO_HELP, MSG_NO_HELP_CAPTION, wxOK | wxICON_ERROR, this); } ////////////////////////////////////////////////////////////////////// @@ -383,10 +383,9 @@ void FloppyConfigDialog::OnEvent(wxCommandEvent& event) void FloppyConfigDialog::ShowHelp() { - wxMessageBox(MSG_NO_HELP, MSG_NO_HELP_CAPTION, wxOK | wxICON_ERROR, this ); + wxMessageBox(MSG_NO_HELP, MSG_NO_HELP_CAPTION, wxOK | wxICON_ERROR, this); } - ////////////////////////////////////////////////////////////////////// // AdvancedLogOptionsDialog implementation ////////////////////////////////////////////////////////////////////// @@ -629,10 +628,9 @@ void AdvancedLogOptionsDialog::OnEvent(wxCommandEvent& event) void AdvancedLogOptionsDialog::ShowHelp() { - wxMessageBox(MSG_NO_HELP, MSG_NO_HELP_CAPTION, wxOK | wxICON_ERROR, this ); + wxMessageBox(MSG_NO_HELP, MSG_NO_HELP_CAPTION, wxOK | wxICON_ERROR, this); } - #if BX_DEBUGGER ////////////////////////////////////////////////////////////////////// // DebugLogDialog implementation @@ -1153,18 +1151,18 @@ bool ParamDialog::CopyGuiToParam() n = GetTextCtrlInt(pstr->u.text, &valid, true, complaint); } if ((n < nump->get_min()) || (n > nump->get_max())) { - wxMessageBox(wxT("Numerical parameter out of range"), wxT("Error"), wxOK | wxICON_ERROR, this ); + wxMessageBox(wxT("Numerical parameter out of range"), wxT("Error"), wxOK | wxICON_ERROR, this); return false; } if (n != nump->get()) nump->set(n); break; - } + } case BXT_PARAM_ENUM: { bx_param_enum_c *enump = (bx_param_enum_c*) pstr->param; - int value = pstr->u.choice->GetSelection () + enump->get_min (); + int value = pstr->u.choice->GetSelection () + enump->get_min(); if (value != enump->get ()) enump->set (value); break; - } + } case BXT_PARAM_STRING: { bx_param_string_c *stringp = (bx_param_string_c*) pstr->param; char buf[1024]; @@ -1185,7 +1183,7 @@ bool ParamDialog::CopyGuiToParam() buf[i] = n; p+=2; } else { - wxMessageBox(wxT("Illegal raw byte format"), wxT("Error"), wxOK | wxICON_ERROR, this ); + wxMessageBox(wxT("Illegal raw byte format"), wxT("Error"), wxOK | wxICON_ERROR, this); return false; } } @@ -1195,7 +1193,7 @@ bool ParamDialog::CopyGuiToParam() buf[sizeof(buf)-1] = 0; if (!stringp->equals (buf)) stringp->set (buf); break; - } + } case BXT_LIST: break; default: @@ -1497,9 +1495,9 @@ void ParamDialog::OnEvent(wxCommandEvent& event) } } -void ParamDialog::ShowHelp () +void ParamDialog::ShowHelp() { - wxMessageBox(MSG_NO_HELP, MSG_NO_HELP_CAPTION, wxOK | wxICON_ERROR, this ); + wxMessageBox(MSG_NO_HELP, MSG_NO_HELP_CAPTION, wxOK | wxICON_ERROR, this); } ///////////////////////////////////////////////////////////////// @@ -1616,8 +1614,7 @@ CpuRegistersDialog::CpuRegistersDialog( AddButton(ID_Close, BTNLABEL_CLOSE); } -void -CpuRegistersDialog::AddFlag(bx_param_c *param) +void CpuRegistersDialog::AddFlag(bx_param_c *param) { if (param == NULL) { wxLogDebug(wxT("AddFlag on undefined param")); @@ -1627,8 +1624,7 @@ CpuRegistersDialog::AddFlag(bx_param_c *param) flagptr[nflags++] = param; } -void -CpuRegistersDialog::Init() +void CpuRegistersDialog::Init() { int i; for (i=0; iEnable (!simRunning); @@ -1665,8 +1660,7 @@ CpuRegistersDialog::stateChanged (bool simRunning) #endif } -void -CpuRegistersDialog::CopyParamToGui () +void CpuRegistersDialog::CopyParamToGui () { ParamDialog::CopyParamToGui (); #if BX_DEBUGGER @@ -1701,8 +1695,7 @@ CpuRegistersDialog::CopyParamToGui () // times, with each click it should call bx_dbg_stepN_command(1) in the // simulator thread. When it returns, it goes back to // -void -CpuRegistersDialog::OnEvent(wxCommandEvent& event) +void CpuRegistersDialog::OnEvent(wxCommandEvent& event) { int id = event.GetId (); switch (id) { @@ -1766,7 +1759,8 @@ LogOptionsDialog::LogOptionsDialog( } } -void LogOptionsDialog::SetAction(int evtype, int a) { +void LogOptionsDialog::SetAction(int evtype, int a) +{ // find the choice whose client data matches "a". int *ptr; //wxLogDebug ("SetAction type=%d a=%d", evtype, a); @@ -1784,7 +1778,8 @@ void LogOptionsDialog::SetAction(int evtype, int a) { wxLogDebug(wxT("SetAction type=%d a=%d not found"), evtype, a); } -int LogOptionsDialog::GetAction(int evtype) { +int LogOptionsDialog::GetAction(int evtype) +{ int sel = action[evtype]->GetSelection(); int *ptrToChoice = (int*)action[evtype]->GetClientData(sel); wxASSERT(ptrToChoice != NULL); @@ -1810,8 +1805,7 @@ void ChangeStaticText (wxSizer *sizer, wxStaticText *win, wxString newtext) // CreateImage produces a disk image. It's in the utility function // area because it's used by both floppy and hard disk image creation. -bool -CreateImage (int harddisk, int sectors, const char *filename) +bool CreateImage (int harddisk, int sectors, const char *filename) { if (sectors<1) { wxMessageBox(wxT("The disk size is invalid."), wxT("Invalid Size"), wxOK | wxICON_ERROR); @@ -1844,7 +1838,8 @@ CreateImage (int harddisk, int sectors, const char *filename) return true; } -void SetTextCtrl(wxTextCtrl *ctrl, const char *format, int val) { +void SetTextCtrl(wxTextCtrl *ctrl, const char *format, int val) +{ wxString tmp; tmp.Printf(wxString(format, wxConvUTF8), val); ctrl->SetValue(tmp); @@ -1865,13 +1860,14 @@ int GetTextCtrlInt (wxTextCtrl *ctrl, } if (valid) *valid = false; if (complain) { - wxMessageBox(complaint, wxT("Invalid"), wxOK | wxICON_ERROR ); + wxMessageBox(complaint, wxT("Invalid"), wxOK | wxICON_ERROR); ctrl->SetFocus(); } return -1; } -bool BrowseTextCtrl(wxTextCtrl *text, wxString prompt, long style) { +bool BrowseTextCtrl(wxTextCtrl *text, wxString prompt, long style) +{ // try to configure the dialog to show hidden files wxConfigBase::Get() ->Write(wxT("/wxWidgets/wxFileDialog/ShowHidden"), true); wxFileDialog *fdialog = new wxFileDialog (text->GetParent(), prompt, wxT(""), text->GetValue(), wxT("*.*"), style); diff --git a/bochs/gui/wxmain.cc b/bochs/gui/wxmain.cc index 8105f55ac..a97681f56 100644 --- a/bochs/gui/wxmain.cc +++ b/bochs/gui/wxmain.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////// -// $Id: wxmain.cc,v 1.155 2008-02-05 22:57:41 sshwarts Exp $ +// $Id: wxmain.cc,v 1.156 2008-02-15 22:05:40 sshwarts Exp $ ///////////////////////////////////////////////////////////////// // // wxmain.cc implements the wxWidgets frame, toolbar, menus, and dialogs. @@ -33,10 +33,6 @@ // ////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////// -// includes -////////////////////////////////////////////////////////////////////// - // Define BX_PLUGGABLE in files that can be compiled into plugins. For // platforms that require a special tag on exported symbols, BX_PLUGGABLE // is used to know when we are exporting symbols and when we are importing. @@ -268,8 +264,7 @@ int MyApp::OnExit() } // these are only called when the simthread is not running. -BxEvent * -MyApp::DefaultCallback(void *thisptr, BxEvent *event) +BxEvent *MyApp::DefaultCallback(void *thisptr, BxEvent *event) { wxLogDebug(wxT("DefaultCallback: event type %d"), event->type); event->retcode = -1; // default return code @@ -284,7 +279,7 @@ MyApp::DefaultCallback(void *thisptr, BxEvent *event) // gui closing down, do something simple and nongraphical. fprintf(stderr, "%s\n", (const char *)text.mb_str(wxConvUTF8)); } else { - wxMessageBox(text, wxT("Error"), wxOK | wxICON_ERROR ); + wxMessageBox(text, wxT("Error"), wxOK | wxICON_ERROR); // maybe I can make OnLogMsg display something that looks appropriate. // theFrame->OnLogMsg(event); } @@ -680,7 +675,7 @@ void MyFrame::OnEditBoot(wxCommandEvent& WXUNUSED(event)) } if (bootDevices == 0) { wxMessageBox(wxT("All the possible boot devices are disabled right now!\nYou must enable the first floppy drive, a hard drive, or a CD-ROM."), - wxT("None enabled"), wxOK | wxICON_ERROR, this ); + wxT("None enabled"), wxOK | wxICON_ERROR, this); return; } ParamDialog dlg(this, -1); @@ -833,7 +828,7 @@ void MyFrame::OnShowKeyboard(wxCommandEvent& WXUNUSED(event)) if (list_size == 0) { // if params not initialized yet, then give up wxMessageBox(wxT("Cannot show the debugger window until the simulation has begun."), - wxT("Sim not running"), wxOK | wxICON_ERROR, this ); + wxT("Sim not running"), wxOK | wxICON_ERROR, this); return; } if (showKbd == NULL) { @@ -855,8 +850,7 @@ void MyFrame::OnDebugLog(wxCommandEvent& WXUNUSED(event)) showDebugLog->Show(TRUE); } -void -MyFrame::DebugBreak() +void MyFrame::DebugBreak() { if (debugCommand) { delete [] debugCommand; @@ -867,16 +861,14 @@ MyFrame::DebugBreak() SIM->debug_break(); } -void -MyFrame::DebugCommand(wxString cmd) +void MyFrame::DebugCommand(wxString cmd) { char buf[1024]; safeWxStrcpy(buf, cmd, sizeof(buf)); DebugCommand(buf); } -void -MyFrame::DebugCommand(const char *cmd) +void MyFrame::DebugCommand(const char *cmd) { wxLogDebug(wxT("debugger command: %s"), cmd); wxASSERT(showDebugLog != NULL); @@ -913,7 +905,7 @@ void MyFrame::OnQuit(wxCommandEvent& event) bx_user_quit = 1; if (!sim_thread) { // no simulation thread is running. Just close the window. - Close( TRUE ); + Close(TRUE); } else { SIM->set_notify_callback(&MyApp::DefaultCallback, this); // ask the simulator to stop. When it stops it will close this frame. @@ -927,7 +919,7 @@ void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) wxString str(wxT("Bochs x86 Emulator version ")); str += wxString(VER_STRING, wxConvUTF8); str += wxT(" (wxWidgets port)"); - wxMessageBox(str, wxT("About Bochs"), wxOK | wxICON_INFORMATION, this ); + wxMessageBox(str, wxT("About Bochs"), wxOK | wxICON_INFORMATION, this); } // update the menu items, status bar, etc. @@ -1090,14 +1082,13 @@ void MyFrame::OnKillSim(wxCommandEvent& WXUNUSED(event)) } } -void -MyFrame::OnSimThreadExit() { +void MyFrame::OnSimThreadExit() +{ wxCriticalSectionLocker lock(sim_thread_lock); sim_thread = NULL; } -int -MyFrame::HandleAskParamString(bx_param_string_c *param) +int MyFrame::HandleAskParamString(bx_param_string_c *param) { wxLogDebug(wxT("HandleAskParamString start")); bx_param_num_c *opt = param->get_options(); @@ -1159,8 +1150,7 @@ MyFrame::HandleAskParamString(bx_param_string_c *param) // Returns 1 if the user chose a value and the param was modified. // Returns 0 if the user cancelled. // Returns -1 if the gui doesn't know how to ask for that param. -int -MyFrame::HandleAskParam(BxEvent *event) +int MyFrame::HandleAskParam(BxEvent *event) { wxASSERT(event->type == BX_SYNC_EVT_ASK_PARAM); @@ -1183,7 +1173,7 @@ MyFrame::HandleAskParam(BxEvent *event) wxString msg; msg.Printf(wxT("ask param for parameter type %d is not implemented in wxWidgets"), param->get_type()); - wxMessageBox(msg, wxT("not implemented"), wxOK | wxICON_ERROR, this ); + wxMessageBox(msg, wxT("not implemented"), wxOK | wxICON_ERROR, this); return -1; } } @@ -1193,8 +1183,7 @@ MyFrame::HandleAskParam(BxEvent *event) // This is called from the wxWidgets GUI thread, when a Sim2CI event // is found. (It got there via wxPostEvent in SiminterfaceCallback2, which is // executed in the simulator Thread.) -void -MyFrame::OnSim2CIEvent(wxCommandEvent& event) +void MyFrame::OnSim2CIEvent(wxCommandEvent& event) { IFDBG_EVENT(wxLogDebug(wxT("received a bochs event in the GUI thread"))); BxEvent *be = (BxEvent *) event.GetEventObject(); @@ -1260,7 +1249,8 @@ MyFrame::OnSim2CIEvent(wxCommandEvent& event) delete be; } -void MyFrame::OnLogMsg(BxEvent *be) { +void MyFrame::OnLogMsg(BxEvent *be) +{ wxLogDebug(wxT("log msg: level=%d, prefix='%s', msg='%s'"), be->u.logmsg.level, be->u.logmsg.prefix, @@ -1294,8 +1284,7 @@ void MyFrame::OnLogMsg(BxEvent *be) { sim_thread->SendSyncResponse(be); // only for case #2 } -bool -MyFrame::editFloppyValidate(FloppyConfigDialog *dialog) +bool MyFrame::editFloppyValidate(FloppyConfigDialog *dialog) { // haven't done anything with this 'feature' return true; @@ -1364,7 +1353,7 @@ void MyFrame::editFirstCdrom() bx_param_c *firstcd = SIM->get_first_cdrom(); if (!firstcd) { wxMessageBox(wxT("No CDROM drive is enabled. Use Edit:ATA to set one up."), - wxT("No CDROM"), wxOK | wxICON_ERROR, this ); + wxT("No CDROM"), wxOK | wxICON_ERROR, this); return; } ParamDialog dlg(this, -1); @@ -1426,14 +1415,16 @@ void MyFrame::OnToolbarClick(wxCommandEvent& event) } // warning: This can be called from the simulator thread!!! -bool MyFrame::WantRefresh() { +bool MyFrame::WantRefresh() +{ bool anyShowing = false; if (showCpu!=NULL && showCpu->IsShowing()) anyShowing = true; if (showKbd!=NULL && showKbd->IsShowing()) anyShowing = true; return anyShowing; } -void MyFrame::RefreshDialogs() { +void MyFrame::RefreshDialogs() +{ if (showCpu!=NULL && showCpu->IsShowing()) showCpu->CopyParamToGui(); if (showKbd!=NULL && showKbd->IsShowing()) showKbd->CopyParamToGui(); } @@ -1442,8 +1433,7 @@ void MyFrame::RefreshDialogs() { // Simulation Thread ////////////////////////////////////////////////////////////////////// -void * -SimThread::Entry(void) +void *SimThread::Entry(void) { // run all the rest of the Bochs simulator code. This function will // run forever, unless a "kill_bochs_request" is issued. The shutdown @@ -1486,8 +1476,7 @@ SimThread::Entry(void) return NULL; } -void -SimThread::OnExit() +void SimThread::OnExit() { // notify the MyFrame that the bochs thread has died. I can't adjust // the sim_thread directly because it's private. @@ -1504,8 +1493,7 @@ SimThread::OnExit() // function when it needs to contact the gui. It will always be // called with a pointer to the SimThread as the first argument, and // it will be called from the simulator thread, not the GUI thread. -BxEvent * -SimThread::SiminterfaceCallback(void *thisptr, BxEvent *event) +BxEvent *SimThread::SiminterfaceCallback(void *thisptr, BxEvent *event) { SimThread *me = (SimThread *)thisptr; // call the normal non-static method now that we know the this pointer. @@ -1517,8 +1505,7 @@ SimThread::SiminterfaceCallback(void *thisptr, BxEvent *event) // thread safe. Most events are handled by packaging up the event // in a wxEvent of some kind, and posting it to the GUI thread for // processing. -BxEvent * -SimThread::SiminterfaceCallback2(BxEvent *event) +BxEvent *SimThread::SiminterfaceCallback2(BxEvent *event) { // wxLogDebug(wxT("SiminterfaceCallback with event type=%d"), (int)event->type); event->retcode = 0; // default return code @@ -1581,8 +1568,7 @@ SimThread::SiminterfaceCallback2(BxEvent *event) } } -void -SimThread::ClearSyncResponse() +void SimThread::ClearSyncResponse() { wxCriticalSectionLocker lock(sim2gui_mailbox_lock); if (sim2gui_mailbox != NULL) { @@ -1591,8 +1577,7 @@ SimThread::ClearSyncResponse() sim2gui_mailbox = NULL; } -void -SimThread::SendSyncResponse(BxEvent *event) +void SimThread::SendSyncResponse(BxEvent *event) { wxCriticalSectionLocker lock(sim2gui_mailbox_lock); if (sim2gui_mailbox != NULL) { @@ -1601,8 +1586,7 @@ SimThread::SendSyncResponse(BxEvent *event) sim2gui_mailbox = event; } -BxEvent * -SimThread::GetSyncResponse() +BxEvent *SimThread::GetSyncResponse() { wxCriticalSectionLocker lock(sim2gui_mailbox_lock); BxEvent *event = sim2gui_mailbox; @@ -1613,8 +1597,7 @@ SimThread::GetSyncResponse() /////////////////////////////////////////////////////////////////// // utility /////////////////////////////////////////////////////////////////// -void -safeWxStrcpy(char *dest, wxString src, int destlen) +void safeWxStrcpy(char *dest, wxString src, int destlen) { wxString tmp(src); strncpy(dest, tmp.mb_str(wxConvUTF8), destlen); diff --git a/bochs/gui/x.cc b/bochs/gui/x.cc index c6649456a..9e24f21fc 100644 --- a/bochs/gui/x.cc +++ b/bochs/gui/x.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: x.cc,v 1.111 2008-02-05 22:57:41 sshwarts Exp $ +// $Id: x.cc,v 1.112 2008-02-15 22:05:40 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2002 MandrakeSoft S.A. @@ -291,11 +291,10 @@ Bit32u ascii_to_key_event[0x5f] = { BX_KEY_BACKSLASH, BX_KEY_RIGHT_BRACKET, BX_KEY_GRAVE - }; +}; extern Bit8u graphics_snapshot[32 * 1024]; - static void create_internal_vga_font(void); static void xkeypress(KeySym keysym, int press_release); // extern "C" void select_visual(void); @@ -349,11 +348,9 @@ test_alloc_colors (Colormap cmap, Bit32u n_tries) { return (n_allocated == n_tries); } -bx_x_gui_c::bx_x_gui_c () { -} +bx_x_gui_c::bx_x_gui_c () {} - void -bx_x_gui_c::specific_init(int argc, char **argv, unsigned tilewidth, unsigned tileheight, +void bx_x_gui_c::specific_init(int argc, char **argv, unsigned tilewidth, unsigned tileheight, unsigned headerbar_y) { unsigned i; @@ -385,7 +382,7 @@ bx_x_gui_c::specific_init(int argc, char **argv, unsigned tilewidth, unsigned ti progname = argv[0]; /* connect to X server */ - if ( (bx_x_display=XOpenDisplay(display_name)) == NULL ) + if ((bx_x_display=XOpenDisplay(display_name)) == NULL) { BX_PANIC(("%s: cannot connect to X server %s", progname, XDisplayName(display_name))); @@ -399,7 +396,6 @@ bx_x_gui_c::specific_init(int argc, char **argv, unsigned tilewidth, unsigned ti */ x = y = 0; - // Temporary values so we can create the window font_width = 8; font_height = 16; @@ -448,7 +444,7 @@ bx_x_gui_c::specific_init(int argc, char **argv, unsigned tilewidth, unsigned ti if (XAllocColorCells(bx_x_display, default_cmap, False, plane_masks_return, 0, col_vals, MAX_VGA_COLORS) == 0) { BX_PANIC(("XAllocColorCells returns error. Maybe your screen does not support a private colormap?")); - } + } win_attr.colormap = default_cmap; XChangeWindowAttributes(bx_x_display, win, CWColormap, &win_attr); @@ -461,26 +457,25 @@ bx_x_gui_c::specific_init(int argc, char **argv, unsigned tilewidth, unsigned ti color.red = 0xffff; color.green = 0xffff; color.blue = 0xffff; - } + } else { color.red = 0; color.green = 0; color.blue = 0; - } - XStoreColor(bx_x_display, default_cmap, &color); } + XStoreColor(bx_x_display, default_cmap, &color); } + } // convenience variables which hold the black & white color indeces black_pixel = col_vals[0]; white_pixel = col_vals[15]; BX_INFO(("font %u wide x %u high, display depth = %d", - (unsigned) font_width, (unsigned) font_height, default_depth)); + (unsigned) font_width, (unsigned) font_height, default_depth)); //select_visual(); - /* Get available icon sizes from Window manager */ #if BX_HAVE_XPM_H @@ -551,8 +546,7 @@ bx_x_gui_c::specific_init(int argc, char **argv, unsigned tilewidth, unsigned ti /* Select event types wanted */ XSelectInput(bx_x_display, win, ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | StructureNotifyMask | PointerMotionMask | - EnterWindowMask | LeaveWindowMask ); - + EnterWindowMask | LeaveWindowMask); /* Create default Graphics Context */ gc = XCreateGC(bx_x_display, win, valuemask, &values); @@ -577,14 +571,13 @@ bx_x_gui_c::specific_init(int argc, char **argv, unsigned tilewidth, unsigned ti while (1) { XNextEvent(bx_x_display, &report); if (report.type == MapNotify) break; - } + } BX_DEBUG(("MapNotify found.")); // Create the VGA font create_internal_vga_font(); - -{ + { char *imagedata; ximage = XCreateImage(bx_x_display, default_visual, @@ -594,7 +587,7 @@ bx_x_gui_c::specific_init(int argc, char **argv, unsigned tilewidth, unsigned ti NULL, // malloc() space after x_tilesize, y_tilesize, // x & y size of image 32, // # bits of padding - 0 ); // bytes_per_line, let X11 calculate + 0); // bytes_per_line, let X11 calculate if (!ximage) BX_PANIC(("vga: couldn't XCreateImage()")); @@ -602,14 +595,14 @@ bx_x_gui_c::specific_init(int argc, char **argv, unsigned tilewidth, unsigned ti imWide = ximage->bytes_per_line; imBPP = ximage->bits_per_pixel; - imagedata = (char *) malloc( (size_t) (ximage->bytes_per_line * y_tilesize) ); + imagedata = (char *) malloc((size_t) (ximage->bytes_per_line * y_tilesize)); if (!imagedata) BX_PANIC(("imagedata: malloc returned error")); ximage->data = imagedata; if (imBPP < imDepth) { BX_PANIC(("vga_x: bits_per_pixel < depth ?")); - } + } for (i=0; i<12; i++) bx_statusitem_active[i] = 0; switch (imBPP) { @@ -629,15 +622,14 @@ bx_x_gui_c::specific_init(int argc, char **argv, unsigned tilewidth, unsigned ti strcpy(bx_status_info_text, "CTRL + 3rd button enables mouse"); x_init_done = true; -} + } curr_background = 0; XSetBackground(bx_x_display, gc, col_vals[curr_background]); curr_foreground = 1; XSetForeground(bx_x_display, gc, col_vals[curr_foreground]); - //XGrabPointer( bx_x_display, win, True, 0, GrabModeAsync, GrabModeAsync, - // win, None, CurrentTime ); - +//XGrabPointer(bx_x_display, win, True, 0, GrabModeAsync, GrabModeAsync, +// win, None, CurrentTime); XFlush(bx_x_display); @@ -655,8 +647,7 @@ bx_x_gui_c::specific_init(int argc, char **argv, unsigned tilewidth, unsigned ti dialog_caps |= BX_GUI_DLG_USER; } - void -set_status_text(int element, const char *text, bx_bool active) +void set_status_text(int element, const char *text, bx_bool active) { int xleft, xsize, sb_ypos; @@ -687,8 +678,7 @@ set_status_text(int element, const char *text, bx_bool active) } } - void -bx_x_gui_c::statusbar_setitem(int element, bx_bool active) +void bx_x_gui_c::statusbar_setitem(int element, bx_bool active) { if (element < 0) { for (unsigned i = 0; i < statusitem_count; i++) { @@ -703,8 +693,7 @@ bx_x_gui_c::statusbar_setitem(int element, bx_bool active) // can change because of a gui event such as clicking on the mouse-enable // bitmap or pressing the middle button, or from the configuration interface. // In all those cases, setting the parameter value will get you here. - void -bx_x_gui_c::mouse_enabled_changed_specific (bx_bool val) +void bx_x_gui_c::mouse_enabled_changed_specific (bx_bool val) { BX_DEBUG (("mouse_enabled=%d, x11 specific code", val?1:0)); if (val) { @@ -726,8 +715,7 @@ bx_x_gui_c::mouse_enabled_changed_specific (bx_bool val) #endif } - void -create_internal_vga_font(void) +void create_internal_vga_font(void) { // Default values font_width=8; @@ -741,8 +729,7 @@ create_internal_vga_font(void) } } - void -bx_x_gui_c::handle_events(void) +void bx_x_gui_c::handle_events(void) { XEvent report; XKeyEvent *key_event; @@ -754,14 +741,12 @@ bx_x_gui_c::handle_events(void) bx_bool mouse_update; int y, height; - XPointerMovedEvent *pointer_event; XEnterWindowEvent *enter_event; XLeaveWindowEvent *leave_event; XButtonEvent *button_event; XExposeEvent *expose_event; - //current_x = -1; //current_y = -1; mouse_update = 0; @@ -777,8 +762,8 @@ bx_x_gui_c::handle_events(void) y = expose_event->y - BX_HEADER_BAR_Y; height = expose_event->height; if (y < 0) { - height += y; - y = 0; + height += y; + y = 0; } DEV_vga_redraw_area( @@ -805,23 +790,23 @@ bx_x_gui_c::handle_events(void) case ButtonPress: button_event = (XButtonEvent *) &report; - BX_DEBUG(("xxx: buttonpress")); + BX_DEBUG(("xxx: buttonpress")); if (button_event->y < BX_HEADER_BAR_Y) { - BX_DEBUG(("xxx: in headerbar")); + BX_DEBUG(("xxx: in headerbar")); if (mouse_update) { - BX_DEBUG(("xxx: mouse_update=1")); + BX_DEBUG(("xxx: mouse_update=1")); send_keyboard_mouse_status(); mouse_update = 0; - } + } prev_x = current_x = -1; prev_y = current_y = -1; headerbar_click(button_event->x, button_event->y); break; - } + } current_x = button_event->x; current_y = button_event->y; mouse_update = 1; - BX_DEBUG(("xxx: x,y=(%d,%d)", current_x, current_y)); + BX_DEBUG(("xxx: x,y=(%d,%d)", current_x, current_y)); switch (button_event->button) { case Button1: mouse_button_state |= 0x01; @@ -829,7 +814,7 @@ bx_x_gui_c::handle_events(void) mouse_update = 0; break; case Button2: - if (CTRL_pressed) { + if (CTRL_pressed) { toggle_mouse_enable(); } else { mouse_button_state |= 0x04; @@ -842,7 +827,7 @@ bx_x_gui_c::handle_events(void) send_keyboard_mouse_status(); mouse_update = 0; break; - } + } break; case ButtonRelease: @@ -851,12 +836,12 @@ bx_x_gui_c::handle_events(void) if (mouse_update) { send_keyboard_mouse_status(); mouse_update = 0; - } + } prev_x = current_x = -1; prev_y = current_y = -1; // ignore, in headerbar area break; - } + } current_x = button_event->x; current_y = button_event->y; mouse_update = 1; @@ -886,7 +871,7 @@ bx_x_gui_c::handle_events(void) send_keyboard_mouse_status(); mouse_update = 0; break; - } + } break; case KeyPress: @@ -954,12 +939,10 @@ bx_x_gui_c::handle_events(void) #endif } - - void -send_keyboard_mouse_status(void) +void send_keyboard_mouse_status(void) { - BX_DEBUG(("XXX: prev=(%d,%d) curr=(%d,%d)", - prev_x, prev_y, current_x, current_y)); + BX_DEBUG(("XXX: prev=(%d,%d) curr=(%d,%d)", + prev_x, prev_y, current_x, current_y)); if (((prev_x!=-1) && (current_x!=-1) && (prev_y!=-1) && (current_y!=-1)) || (current_z != 0)) { @@ -975,38 +958,34 @@ send_keyboard_mouse_status(void) //if (warped) { // prev_x = current_x = -1; // prev_y = current_y = -1; - // } + //} //else { prev_x = current_x; prev_y = current_y; - // } - } + //} + } else { - if ( (current_x!=-1) && (current_y!=-1)) { + if ((current_x!=-1) && (current_y!=-1)) { prev_x = current_x; prev_y = current_y; - } + } else { prev_x = current_x = -1; prev_y = current_y = -1; - } } + } } - void -bx_x_gui_c::flush(void) +void bx_x_gui_c::flush(void) { if (bx_x_display) XFlush(bx_x_display); } - - void -xkeypress(KeySym keysym, int press_release) +void xkeypress(KeySym keysym, int press_release) { Bit32u key_event; - if ((keysym == XK_Control_L) || (keysym == XK_Control_R)) { CTRL_pressed = !press_release; } @@ -1019,7 +998,7 @@ xkeypress(KeySym keysym, int press_release) // are in consequtive order. if ((keysym >= XK_space) && (keysym <= XK_asciitilde)) { key_event = ascii_to_key_event[keysym - XK_space]; - } + } else switch (keysym) { case XK_KP_1: #ifdef XK_KP_End @@ -1153,20 +1132,20 @@ xkeypress(KeySym keysym, int press_release) case XK_Page_Down: key_event = BX_KEY_PAGE_DOWN; break; default: - BX_ERROR(( "xkeypress(): keysym %x unhandled!", (unsigned) keysym )); + BX_ERROR(("xkeypress(): keysym %x unhandled!", (unsigned) keysym)); return; break; - } } + } else { - /* use mapping */ - BXKeyEntry *entry = bx_keymap.findHostKey (keysym); - if (!entry) { - BX_ERROR(( "xkeypress(): keysym %x unhandled!", (unsigned) keysym )); - return; - } - key_event = entry->baseKey; - } + /* use mapping */ + BXKeyEntry *entry = bx_keymap.findHostKey (keysym); + if (!entry) { + BX_ERROR(("xkeypress(): keysym %x unhandled!", (unsigned) keysym)); + return; + } + key_event = entry->baseKey; + } if (press_release) key_event |= BX_KEY_RELEASED; @@ -1174,13 +1153,11 @@ xkeypress(KeySym keysym, int press_release) DEV_kbd_gen_scancode(key_event); } - void bx_x_gui_c::clear_screen(void) { XClearArea(bx_x_display, win, 0, bx_headerbar_y, dimension_x, dimension_y, 0); } - void bx_x_gui_c::text_update(Bit8u *old_text, Bit8u *new_text, unsigned long cursor_x, unsigned long cursor_y, bx_vga_tminfo_t tm_info) @@ -1250,7 +1227,7 @@ void bx_x_gui_c::text_update(Bit8u *old_text, Bit8u *new_text, } // first invalidate character at previous and new cursor location - if ( (prev_cursor_y < text_rows) && (prev_cursor_x < text_cols) ) { + if ((prev_cursor_y < text_rows) && (prev_cursor_x < text_cols)) { curs = prev_cursor_y * tm_info.line_offset + prev_cursor_x * 2; old_text[curs] = ~new_text[curs]; } @@ -1328,8 +1305,8 @@ void bx_x_gui_c::text_update(Bit8u *old_text, Bit8u *new_text, font_col = 0; cfwidth = font_width; } - if ( forceUpdate || (old_text[0] != new_text[0]) - || (old_text[1] != new_text[1]) ) { + if (forceUpdate || (old_text[0] != new_text[0]) + || (old_text[1] != new_text[1])) { cChar = new_text[0]; new_foreground = new_text[1] & 0x0f; @@ -1423,7 +1400,6 @@ int bx_x_gui_c::set_clipboard_text(char *text_snapshot, Bit32u len) return 1; } - void bx_x_gui_c::graphics_tile_update(Bit8u *tile, unsigned x0, unsigned y0) { unsigned x, y, y_size; @@ -1451,11 +1427,11 @@ void bx_x_gui_c::graphics_tile_update(Bit8u *tile, unsigned x0, unsigned y0) if (ximage->byte_order == LSBFirst) { ximage->data[offset + 0] = b0; ximage->data[offset + 1] = b1; - } + } else { // MSBFirst ximage->data[offset + 0] = b1; ximage->data[offset + 1] = b0; - } + } break; case 24: // 24 bits per pixel offset = imWide*y + 3*x; @@ -1466,12 +1442,12 @@ void bx_x_gui_c::graphics_tile_update(Bit8u *tile, unsigned x0, unsigned y0) ximage->data[offset + 0] = b0; ximage->data[offset + 1] = b1; ximage->data[offset + 2] = b2; - } + } else { // MSBFirst ximage->data[offset + 0] = b2; ximage->data[offset + 1] = b1; ximage->data[offset + 2] = b0; - } + } break; case 32: // 32 bits per pixel offset = imWide*y + 4*x; @@ -1484,33 +1460,32 @@ void bx_x_gui_c::graphics_tile_update(Bit8u *tile, unsigned x0, unsigned y0) ximage->data[offset + 1] = b1; ximage->data[offset + 2] = b2; ximage->data[offset + 3] = b3; - } + } else { // MSBFirst ximage->data[offset + 0] = b3; ximage->data[offset + 1] = b2; ximage->data[offset + 2] = b1; ximage->data[offset + 3] = b0; - } + } break; default: BX_PANIC(("X_graphics_tile_update: bits_per_pixel %u not implemented", (unsigned) imBPP)); return; - } } } + } break; default: BX_PANIC(("X_graphics_tile_update: bits_per_pixel %u handled by new graphics API", (unsigned) vga_bpp)); return; - } + } XPutImage(bx_x_display, win, gc, ximage, 0, 0, x0, y0+bx_headerbar_y, x_tilesize, y_size); } - bx_svga_tileinfo_t * -bx_x_gui_c::graphics_tile_info(bx_svga_tileinfo_t *info) +bx_svga_tileinfo_t *bx_x_gui_c::graphics_tile_info(bx_svga_tileinfo_t *info) { if (!info) { info = (bx_svga_tileinfo_t *)malloc(sizeof(bx_svga_tileinfo_t)); @@ -1586,8 +1561,7 @@ bx_x_gui_c::graphics_tile_info(bx_svga_tileinfo_t *info) return info; } - Bit8u * -bx_x_gui_c::graphics_tile_get(unsigned x0, unsigned y0, +Bit8u *bx_x_gui_c::graphics_tile_get(unsigned x0, unsigned y0, unsigned *w, unsigned *h) { if (x0+x_tilesize > dimension_x) { @@ -1607,16 +1581,14 @@ bx_x_gui_c::graphics_tile_get(unsigned x0, unsigned y0, return (Bit8u *)ximage->data + ximage->xoffset*ximage->bits_per_pixel/8; } - void -bx_x_gui_c::graphics_tile_update_in_place(unsigned x0, unsigned y0, +void bx_x_gui_c::graphics_tile_update_in_place(unsigned x0, unsigned y0, unsigned w, unsigned h) { XPutImage(bx_x_display, win, gc, ximage, 0, 0, x0, y0+bx_headerbar_y, w, h); } - bx_bool -bx_x_gui_c::palette_change(unsigned index, unsigned red, unsigned green, unsigned blue) +bx_bool bx_x_gui_c::palette_change(unsigned index, unsigned red, unsigned green, unsigned blue) { // returns: 0=no screen update needed (color map change has direct effect) // 1=screen updated needed (redraw using current colormap) @@ -1631,18 +1603,16 @@ bx_x_gui_c::palette_change(unsigned index, unsigned red, unsigned green, unsigne color.pixel = index; XStoreColor(bx_x_display, default_cmap, &color); return(0); // no screen update needed - } + } else { XAllocColor(bx_x_display, DefaultColormap(bx_x_display, bx_x_screen_num), &color); col_vals[index] = color.pixel; return(1); // screen update needed - } + } } - - void -bx_x_gui_c::dimension_update(unsigned x, unsigned y, unsigned fheight, unsigned fwidth, unsigned bpp) +void bx_x_gui_c::dimension_update(unsigned x, unsigned y, unsigned fheight, unsigned fwidth, unsigned bpp) { if ((bpp == 8) || (bpp == 15) || (bpp == 16) || (bpp == 24) || (bpp == 32)) { vga_bpp = bpp; @@ -1655,25 +1625,23 @@ bx_x_gui_c::dimension_update(unsigned x, unsigned y, unsigned fheight, unsigned text_cols = x / font_width; text_rows = y / font_height; } - if ( (x != dimension_x) || (y != dimension_y) ) { + if ((x != dimension_x) || (y != dimension_y)) { XSizeHints hints; long supplied_return; - if ( XGetWMNormalHints(bx_x_display, win, &hints, &supplied_return) && - supplied_return & PMaxSize ) { + if (XGetWMNormalHints(bx_x_display, win, &hints, &supplied_return) && + supplied_return & PMaxSize) { hints.max_width = hints.min_width = x; hints.max_height = hints.min_height = y+bx_headerbar_y+bx_statusbar_y; XSetWMNormalHints(bx_x_display, win, &hints); - } + } XResizeWindow(bx_x_display, win, x, y+bx_headerbar_y+bx_statusbar_y); dimension_x = x; dimension_y = y; } } - - void -bx_x_gui_c::show_headerbar(void) +void bx_x_gui_c::show_headerbar(void) { unsigned xorigin; int xleft, xright, sb_ypos; @@ -1689,16 +1657,16 @@ bx_x_gui_c::show_headerbar(void) if (bx_headerbar_entry[i].alignment == BX_GRAVITY_LEFT) { xorigin = bx_headerbar_entry[i].xorigin; xleft += bx_headerbar_entry[i].xdim; - } + } else { xorigin = dimension_x - bx_headerbar_entry[i].xorigin; xright = xorigin; - } + } if (xright < xleft) break; XCopyPlane(bx_x_display, bx_headerbar_entry[i].bitmap, win, gc_headerbar, 0,0, bx_headerbar_entry[i].xdim, bx_headerbar_entry[i].ydim, xorigin, 0, 1); - } + } for (unsigned i=0; i<12; i++) { xleft = bx_statusitem_pos[i]; if (i > 0) { @@ -1713,13 +1681,11 @@ bx_x_gui_c::show_headerbar(void) } } - - unsigned -bx_x_gui_c::create_bitmap(const unsigned char *bmap, unsigned xdim, unsigned ydim) +unsigned bx_x_gui_c::create_bitmap(const unsigned char *bmap, unsigned xdim, unsigned ydim) { if (bx_bitmap_entries >= BX_MAX_PIXMAPS) { BX_PANIC(("x: too many pixmaps, increase BX_MAX_PIXMAPS")); - } + } bx_bitmaps[bx_bitmap_entries].bmap = XCreateBitmapFromData(bx_x_display, win, (const char *) bmap, xdim, ydim); @@ -1727,18 +1693,16 @@ bx_x_gui_c::create_bitmap(const unsigned char *bmap, unsigned xdim, unsigned ydi bx_bitmaps[bx_bitmap_entries].ydim = ydim; if (!bx_bitmaps[bx_bitmap_entries].bmap) { BX_PANIC(("x: could not create bitmap")); - } + } bx_bitmap_entries++; return(bx_bitmap_entries-1); // return index as handle } - - unsigned -bx_x_gui_c::headerbar_bitmap(unsigned bmap_id, unsigned alignment, void (*f)(void)) +unsigned bx_x_gui_c::headerbar_bitmap(unsigned bmap_id, unsigned alignment, void (*f)(void)) { unsigned hb_index; - if ( (bx_headerbar_entries+1) > BX_MAX_HEADERBAR_ENTRIES ) + if ((bx_headerbar_entries+1) > BX_MAX_HEADERBAR_ENTRIES) BX_PANIC(("x: too many headerbar entries, increase BX_MAX_HEADERBAR_ENTRIES")); bx_headerbar_entries++; @@ -1753,17 +1717,16 @@ bx_x_gui_c::headerbar_bitmap(unsigned bmap_id, unsigned alignment, void (*f)(voi bx_headerbar_entry[hb_index].xorigin = bx_bitmap_left_xorigin; bx_headerbar_entry[hb_index].yorigin = 0; bx_bitmap_left_xorigin += bx_bitmaps[bmap_id].xdim; - } + } else { // BX_GRAVITY_RIGHT bx_bitmap_right_xorigin += bx_bitmaps[bmap_id].xdim; bx_headerbar_entry[hb_index].xorigin = bx_bitmap_right_xorigin; bx_headerbar_entry[hb_index].yorigin = 0; - } + } return(hb_index); } - void -bx_x_gui_c::replace_bitmap(unsigned hbar_id, unsigned bmap_id) +void bx_x_gui_c::replace_bitmap(unsigned hbar_id, unsigned bmap_id) { unsigned xorigin; @@ -1778,9 +1741,7 @@ bx_x_gui_c::replace_bitmap(unsigned hbar_id, unsigned bmap_id) xorigin, 0, 1); } - - void -headerbar_click(int x, int y) +void headerbar_click(int x, int y) { int xorigin; @@ -1791,87 +1752,87 @@ headerbar_click(int x, int y) xorigin = bx_headerbar_entry[i].xorigin; else xorigin = dimension_x - bx_headerbar_entry[i].xorigin; - if ( (x>=xorigin) && (x<(xorigin+int(bx_headerbar_entry[i].xdim))) ) { + if ((x>=xorigin) && (x<(xorigin+int(bx_headerbar_entry[i].xdim)))) { bx_headerbar_entry[i].f(); return; - } } + } } - void -bx_x_gui_c::exit(void) +void bx_x_gui_c::exit(void) { if (!x_init_done) return; // Delete the font bitmaps for (int i=0; i<256; i++) { //if (vgafont[i] != NULL) - XFreePixmap(bx_x_display,vgafont[i]); + XFreePixmap(bx_x_display,vgafont[i]); } if (bx_x_display) XCloseDisplay (bx_x_display); - BX_INFO(("Exit.")); + + BX_INFO(("Exit")); } static void warp_cursor (int dx, int dy) { - if (SIM->get_param_bool(BXPN_MOUSE_ENABLED)->get() && - (warp_dx || warp_dy || dx || dy) - ) { - warp_dx = dx; - warp_dy = dy; - XWarpPointer(bx_x_display, None, None, 0, 0, 0, 0, dx, dy); - } + if (SIM->get_param_bool(BXPN_MOUSE_ENABLED)->get() && + (warp_dx || warp_dy || dx || dy) + ) { + warp_dx = dx; + warp_dy = dy; + XWarpPointer(bx_x_display, None, None, 0, 0, 0, 0, dx, dy); + } } -static void disable_cursor () +static void disable_cursor() { - static Cursor cursor; - static unsigned cursor_created = 0; + static Cursor cursor; + static unsigned cursor_created = 0; - static int shape_width = 16, - shape_height = 16, - mask_width = 16, - mask_height = 16; + static int shape_width = 16, + shape_height = 16, + mask_width = 16, + mask_height = 16; - static Bit32u shape_bits[(16*16)/32] = { - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - }; - static Bit32u mask_bits[(16*16)/32] = { - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - }; + static Bit32u shape_bits[(16*16)/32] = { + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + }; + static Bit32u mask_bits[(16*16)/32] = { + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + }; - if (!cursor_created) { - Pixmap shape, mask; - XColor white, black; - shape = XCreatePixmapFromBitmapData(bx_x_display, - RootWindow(bx_x_display,bx_x_screen_num), - (char*)shape_bits, - shape_width, - shape_height, - 1, 0, 1); - mask = XCreatePixmapFromBitmapData(bx_x_display, - RootWindow(bx_x_display,bx_x_screen_num), - (char*)mask_bits, - mask_width, - mask_height, - 1, 0, 1); - XParseColor(bx_x_display, default_cmap, "black", &black); - XParseColor(bx_x_display, default_cmap, "white", &white); - cursor = XCreatePixmapCursor(bx_x_display, shape, mask, - &white, &black, 1, 1); - cursor_created = 1; - } + if (!cursor_created) { + Pixmap shape, mask; + XColor white, black; + shape = XCreatePixmapFromBitmapData(bx_x_display, + RootWindow(bx_x_display,bx_x_screen_num), + (char*)shape_bits, + shape_width, + shape_height, + 1, 0, 1); + mask = XCreatePixmapFromBitmapData(bx_x_display, + RootWindow(bx_x_display,bx_x_screen_num), + (char*)mask_bits, + mask_width, + mask_height, + 1, 0, 1); + XParseColor(bx_x_display, default_cmap, "black", &black); + XParseColor(bx_x_display, default_cmap, "white", &white); + cursor = XCreatePixmapCursor(bx_x_display, shape, mask, + &white, &black, 1, 1); + cursor_created = 1; + } - XDefineCursor(bx_x_display, win, cursor); + XDefineCursor(bx_x_display, win, cursor); } -static void enable_cursor () +static void enable_cursor() { - XUndefineCursor(bx_x_display, win); + XUndefineCursor(bx_x_display, win); } /* convertStringToXKeysym is a keymap callback @@ -1882,14 +1843,14 @@ static void enable_cursor () */ static Bit32u convertStringToXKeysym (const char *string) { - if (strncmp ("XK_", string, 3) != 0) - return BX_KEYMAP_UNKNOWN; - KeySym keysym=XStringToKeysym(string+3); + if (strncmp ("XK_", string, 3) != 0) + return BX_KEYMAP_UNKNOWN; + KeySym keysym=XStringToKeysym(string+3); - // failure, return unknown - if(keysym==NoSymbol) return BX_KEYMAP_UNKNOWN; + // failure, return unknown + if(keysym==NoSymbol) return BX_KEYMAP_UNKNOWN; - return((Bit32u)keysym); + return((Bit32u)keysym); } #if BX_USE_IDLE_HACK @@ -1911,38 +1872,38 @@ static Bit32u convertStringToXKeysym (const char *string) * (adopted from mozilla/gfx/src/xprint/xprintutil_printtofile.c#XNextEventTimeout()) */ static -Bool XPeekEventTimeout( Display *display, XEvent *event_return, struct timeval *timeout ) +Bool XPeekEventTimeout(Display *display, XEvent *event_return, struct timeval *timeout) { - int res; - fd_set readfds; - int display_fd = XConnectionNumber(display); + int res; + fd_set readfds; + int display_fd = XConnectionNumber(display); - /* small shortcut... */ - if( timeout == NULL ) - { + /* small shortcut... */ + if(timeout == NULL) + { XPeekEvent(display, event_return); return(True); - } + } - FD_ZERO(&readfds); - FD_SET(display_fd, &readfds); + FD_ZERO(&readfds); + FD_SET(display_fd, &readfds); - /* Note/bug: In the case of internal X events (like used to trigger callbacks - * registered by XpGetDocumentData()&co.) select() will return with "new info" - * - but XNextEvent() below processes these _internal_ events silently - and - * will block if there are no other non-internal events. - * The workaround here is to check with XEventsQueued() if there are non-internal - * events queued - if not select() will be called again - unfortunately we use - * the old timeout here instead of the "remaining" time... (this only would hurt - * if the timeout would be really long - but for current use with values below - * 1/2 secs it does not hurt... =:-) - */ - while( XEventsQueued(display, QueuedAfterFlush) == 0 ) + /* Note/bug: In the case of internal X events (like used to trigger callbacks + * registered by XpGetDocumentData()&co.) select() will return with "new info" + * - but XNextEvent() below processes these _internal_ events silently - and + * will block if there are no other non-internal events. + * The workaround here is to check with XEventsQueued() if there are non-internal + * events queued - if not select() will be called again - unfortunately we use + * the old timeout here instead of the "remaining" time... (this only would hurt + * if the timeout would be really long - but for current use with values below + * 1/2 secs it does not hurt... =:-) + */ + while(XEventsQueued(display, QueuedAfterFlush) == 0) + { + res = select(display_fd+1, &readfds, NULL, NULL, timeout); + + switch(res) { - res = select(display_fd+1, &readfds, NULL, NULL, timeout); - - switch(res) - { case -1: /* select() error - should not happen */ if (errno == EINTR) break; // caused e.g. by alarm(3) @@ -1951,14 +1912,15 @@ Bool XPeekEventTimeout( Display *display, XEvent *event_return, struct timeval * case 0: /* timeout */ return(False); - } } + } - XPeekEvent(display, event_return); - return(True); + XPeekEvent(display, event_return); + return(True); } -void bx_x_gui_c::sim_is_idle () { +void bx_x_gui_c::sim_is_idle() +{ XEvent dummy; struct timeval timeout; timeout.tv_sec = 0; @@ -1969,12 +1931,12 @@ void bx_x_gui_c::sim_is_idle () { void bx_x_gui_c::beep_on(float frequency) { - BX_INFO(( "X11 Beep ON (frequency=%.2f)",frequency)); + BX_INFO(("X11 Beep ON (frequency=%.2f)",frequency)); } void bx_x_gui_c::beep_off() { - BX_INFO(( "X11 Beep OFF")); + BX_INFO(("X11 Beep OFF")); } void bx_x_gui_c::get_capabilities(Bit16u *xres, Bit16u *yres, Bit16u *bpp) @@ -2301,8 +2263,7 @@ int x11_string_dialog(bx_param_string_c *param) return control; } -BxEvent * -x11_notify_callback (void *unused, BxEvent *event) +BxEvent *x11_notify_callback (void *unused, BxEvent *event) { int opts; bx_param_c *param; diff --git a/bochs/iodev/biosdev.cc b/bochs/iodev/biosdev.cc index a29cc3272..50402fb00 100644 --- a/bochs/iodev/biosdev.cc +++ b/bochs/iodev/biosdev.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: biosdev.cc,v 1.12 2008-01-26 22:24:00 sshwarts Exp $ +// $Id: biosdev.cc,v 1.13 2008-02-15 22:05:41 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2002 MandrakeSoft S.A. @@ -154,7 +154,7 @@ void bx_biosdev_c::write(Bit32u address, Bit32u value, unsigned io_len) BX_BIOS_THIS s.bios_message[BX_BIOS_THIS s.bios_message_i] = (Bit8u) value; BX_BIOS_THIS s.bios_message_i ++; - if ( BX_BIOS_THIS s.bios_message_i >= BX_BIOS_MESSAGE_SIZE ) { + if (BX_BIOS_THIS s.bios_message_i >= BX_BIOS_MESSAGE_SIZE) { BX_BIOS_THIS s.bios_message[ BX_BIOS_MESSAGE_SIZE - 1] = 0; BX_BIOS_THIS s.bios_message_i = 0; if (address==0x403) @@ -201,7 +201,7 @@ void bx_biosdev_c::write(Bit32u address, Bit32u value, unsigned io_len) BX_BIOS_THIS s.vgabios_message[BX_BIOS_THIS s.vgabios_message_i] = (Bit8u) value; BX_BIOS_THIS s.vgabios_message_i ++; - if ( BX_BIOS_THIS s.vgabios_message_i >= BX_BIOS_MESSAGE_SIZE ) { + if (BX_BIOS_THIS s.vgabios_message_i >= BX_BIOS_MESSAGE_SIZE) { BX_BIOS_THIS s.vgabios_message[ BX_BIOS_MESSAGE_SIZE - 1] = 0; BX_BIOS_THIS s.vgabios_message_i = 0; if (address==0x503) diff --git a/bochs/iodev/busmouse.cc b/bochs/iodev/busmouse.cc index 033d8aad8..59259864d 100644 --- a/bochs/iodev/busmouse.cc +++ b/bochs/iodev/busmouse.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: busmouse.cc,v 1.8 2008-01-26 22:24:00 sshwarts Exp $ +// $Id: busmouse.cc,v 1.9 2008-02-15 22:05:41 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2004 MandrakeSoft S.A. @@ -70,7 +70,7 @@ bx_busm_c::~bx_busm_c() void bx_busm_c::init(void) { - BX_DEBUG(("Init $Id: busmouse.cc,v 1.8 2008-01-26 22:24:00 sshwarts Exp $")); + BX_DEBUG(("Init $Id: busmouse.cc,v 1.9 2008-02-15 22:05:41 sshwarts Exp $")); DEV_register_irq(BUS_MOUSE_IRQ, "Bus Mouse"); @@ -275,9 +275,9 @@ void bx_busm_c::write(Bit32u address, Bit32u value, unsigned io_len) void bx_busm_c::bus_mouse_enq(int delta_x, int delta_y, int delta_z, unsigned button_state) { // scale down the motion - if ( (delta_x < -1) || (delta_x > 1) ) + if ((delta_x < -1) || (delta_x > 1)) delta_x /= 2; - if ( (delta_y < -1) || (delta_y > 1) ) + if ((delta_y < -1) || (delta_y > 1)) delta_y /= 2; if(delta_x>127) delta_x=127; diff --git a/bochs/iodev/cdrom.cc b/bochs/iodev/cdrom.cc index 3b79f30b8..af3d756be 100644 --- a/bochs/iodev/cdrom.cc +++ b/bochs/iodev/cdrom.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: cdrom.cc,v 1.90 2008-01-26 22:24:00 sshwarts Exp $ +// $Id: cdrom.cc,v 1.91 2008-02-15 22:05:41 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2002 MandrakeSoft S.A. @@ -23,7 +23,7 @@ // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - +///////////////////////////////////////////////////////////////////////// // These are the low-level CDROM functions which are called // from 'harddrv.cc'. They effect the OS specific functionality @@ -111,7 +111,7 @@ extern "C" { #include #include #include -#if defined (__GNUC__) && ( __GNUC__ >= 4 ) +#if defined (__GNUC__) && (__GNUC__ >= 4) #include #else #include @@ -136,37 +136,37 @@ extern "C" { // however there seems to be some dissagreement in // the definition of CDTOC.length struct _CDMSF { - u_char minute; - u_char second; - u_char frame; + u_char minute; + u_char second; + u_char frame; }; -#define MSF_TO_LBA(msf) \ - (((((msf).minute * 60UL) + (msf).second) * 75UL) + (msf).frame - 150) +#define MSF_TO_LBA(msf) \ + (((((msf).minute * 60UL) + (msf).second) * 75UL) + (msf).frame - 150) struct _CDTOC_Desc { - u_char session; - u_char ctrl_adr; /* typed to be machine and compiler independent */ - u_char tno; - u_char point; - struct _CDMSF address; - u_char zero; - struct _CDMSF p; + u_char session; + u_char ctrl_adr; /* typed to be machine and compiler independent */ + u_char tno; + u_char point; + struct _CDMSF address; + u_char zero; + struct _CDMSF p; }; struct _CDTOC { - u_short length; /* in native cpu endian */ - u_char first_session; - u_char last_session; - struct _CDTOC_Desc trackdesc[1]; + u_short length; /* in native cpu endian */ + u_char first_session; + u_char last_session; + struct _CDTOC_Desc trackdesc[1]; }; -static kern_return_t FindEjectableCDMedia( io_iterator_t *mediaIterator, mach_port_t *masterPort ); -static kern_return_t GetDeviceFilePath( io_iterator_t mediaIterator, char *deviceFilePath, CFIndex maxPathSize ); -//int OpenDrive( const char *deviceFilePath ); -static struct _CDTOC * ReadTOC( const char * devpath ); +static kern_return_t FindEjectableCDMedia(io_iterator_t *mediaIterator, mach_port_t *masterPort); +static kern_return_t GetDeviceFilePath(io_iterator_t mediaIterator, char *deviceFilePath, CFIndex maxPathSize); +//int OpenDrive(const char *deviceFilePath); +static struct _CDTOC *ReadTOC(const char *devpath); -static char CDDevicePath[ MAXPATHLEN ]; +static char CDDevicePath[MAXPATHLEN]; #define BX_CD_FRAMESIZE 2048 #define CD_FRAMESIZE 2048 @@ -250,185 +250,176 @@ typedef struct _CDROM_TOC_SESSION_DATA { #include #ifdef __APPLE__ -static kern_return_t FindEjectableCDMedia( io_iterator_t *mediaIterator, - mach_port_t *masterPort ) +static kern_return_t FindEjectableCDMedia(io_iterator_t *mediaIterator, + mach_port_t *masterPort) { - kern_return_t kernResult; + kern_return_t kernResult; CFMutableDictionaryRef classesToMatch; - kernResult = IOMasterPort( bootstrap_port, masterPort ); - if ( kernResult != KERN_SUCCESS ) - { - fprintf ( stderr, "IOMasterPort returned %d\n", kernResult ); + kernResult = IOMasterPort(bootstrap_port, masterPort); + if (kernResult != KERN_SUCCESS) + { + fprintf (stderr, "IOMasterPort returned %d\n", kernResult); return kernResult; - } + } // CD media are instances of class kIOCDMediaClass. - classesToMatch = IOServiceMatching( kIOCDMediaClass ); - if ( classesToMatch == NULL ) - fprintf ( stderr, "IOServiceMatching returned a NULL dictionary.\n" ); + classesToMatch = IOServiceMatching(kIOCDMediaClass); + if (classesToMatch == NULL) + fprintf (stderr, "IOServiceMatching returned a NULL dictionary.\n"); else - { - // Each IOMedia object has a property with key kIOMediaEjectableKey - // which is true if the media is indeed ejectable. So add property - // to CFDictionary for matching. - CFDictionarySetValue( classesToMatch, - CFSTR( kIOMediaEjectableKey ), kCFBooleanTrue ); - } - kernResult = IOServiceGetMatchingServices( *masterPort, - classesToMatch, mediaIterator ); - if ( (kernResult != KERN_SUCCESS) || (*mediaIterator == NULL) ) - fprintf( stderr, "No ejectable CD media found.\n kernResult = %d\n", kernResult ); + { + // Each IOMedia object has a property with key kIOMediaEjectableKey + // which is true if the media is indeed ejectable. So add property + // to CFDictionary for matching. + CFDictionarySetValue(classesToMatch, + CFSTR(kIOMediaEjectableKey), kCFBooleanTrue); + } + kernResult = IOServiceGetMatchingServices(*masterPort, + classesToMatch, mediaIterator); + if ((kernResult != KERN_SUCCESS) || (*mediaIterator == NULL)) + fprintf(stderr, "No ejectable CD media found.\n kernResult = %d\n", kernResult); return kernResult; } - -static kern_return_t GetDeviceFilePath( io_iterator_t mediaIterator, - char *deviceFilePath, CFIndex maxPathSize ) +static kern_return_t GetDeviceFilePath(io_iterator_t mediaIterator, + char *deviceFilePath, CFIndex maxPathSize) { io_object_t nextMedia; kern_return_t kernResult = KERN_FAILURE; - nextMedia = IOIteratorNext( mediaIterator ); - if ( nextMedia == NULL ) - { + nextMedia = IOIteratorNext(mediaIterator); + if (nextMedia == NULL) + { *deviceFilePath = '\0'; - } + } else - { - CFTypeRef deviceFilePathAsCFString; - deviceFilePathAsCFString = IORegistryEntryCreateCFProperty( - nextMedia, CFSTR( kIOBSDNameKey ), - kCFAllocatorDefault, 0 ); + { + CFTypeRef deviceFilePathAsCFString; + deviceFilePathAsCFString = IORegistryEntryCreateCFProperty(nextMedia, CFSTR(kIOBSDNameKey), + kCFAllocatorDefault, 0); *deviceFilePath = '\0'; - if ( deviceFilePathAsCFString ) - { - size_t devPathLength = strlen( _PATH_DEV ); - strcpy( deviceFilePath, _PATH_DEV ); - if ( CFStringGetCString( (const __CFString *) deviceFilePathAsCFString, - deviceFilePath + devPathLength, - maxPathSize - devPathLength, - kCFStringEncodingASCII ) ) - { - // fprintf( stderr, "BSD path: %s\n", deviceFilePath ); + if (deviceFilePathAsCFString) + { + size_t devPathLength = strlen(_PATH_DEV); + strcpy(deviceFilePath, _PATH_DEV); + if (CFStringGetCString((const __CFString *) deviceFilePathAsCFString, + deviceFilePath + devPathLength, + maxPathSize - devPathLength, + kCFStringEncodingASCII)) + { + // fprintf(stderr, "BSD path: %s\n", deviceFilePath); kernResult = KERN_SUCCESS; - } - CFRelease( deviceFilePathAsCFString ); - } - } - IOObjectRelease( nextMedia ); + } + CFRelease(deviceFilePathAsCFString); + } + } + + IOObjectRelease(nextMedia); return kernResult; } - -static int OpenDrive( const char *deviceFilePath ) +static int OpenDrive(const char *deviceFilePath) { - - int fileDescriptor; - - fileDescriptor = open( deviceFilePath, O_RDONLY ); - if ( fileDescriptor == -1 ) - fprintf( stderr, "Error %d opening device %s.\n", errno, deviceFilePath ); + int fileDescriptor = open(deviceFilePath, O_RDONLY); + if (fileDescriptor == -1) + fprintf(stderr, "Error %d opening device %s.\n", errno, deviceFilePath); return fileDescriptor; - } -static struct _CDTOC * ReadTOC( const char * devpath ) { - +static struct _CDTOC * ReadTOC(const char *devpath) +{ struct _CDTOC * toc_p = NULL; io_iterator_t iterator = 0; io_registry_entry_t service = 0; CFDictionaryRef properties = 0; CFDataRef data = 0; mach_port_t port = 0; - char * devname; + char *devname; - if (( devname = strrchr( devpath, '/' )) != NULL ) { + if ((devname = strrchr(devpath, '/')) != NULL) { ++devname; } else { devname = (char *) devpath; } - if ( IOMasterPort(bootstrap_port, &port ) != KERN_SUCCESS ) { - fprintf( stderr, "IOMasterPort failed\n" ); + if (IOMasterPort(bootstrap_port, &port) != KERN_SUCCESS) { + fprintf(stderr, "IOMasterPort failed\n"); goto Exit; } - if ( IOServiceGetMatchingServices( port, IOBSDNameMatching( port, 0, devname ), - &iterator ) != KERN_SUCCESS ) { - fprintf( stderr, "IOServiceGetMatchingServices failed\n" ); + if (IOServiceGetMatchingServices(port, IOBSDNameMatching(port, 0, devname), + &iterator) != KERN_SUCCESS) { + fprintf(stderr, "IOServiceGetMatchingServices failed\n"); goto Exit; } - service = IOIteratorNext( iterator ); + service = IOIteratorNext(iterator); - IOObjectRelease( iterator ); + IOObjectRelease(iterator); iterator = 0; - while ( service && !IOObjectConformsTo( service, "IOCDMedia" )) { - if ( IORegistryEntryGetParentIterator( service, kIOServicePlane, - &iterator ) != KERN_SUCCESS ) { - fprintf( stderr, "IORegistryEntryGetParentIterator failed\n" ); + while (service && !IOObjectConformsTo(service, "IOCDMedia")) { + if (IORegistryEntryGetParentIterator(service, kIOServicePlane, + &iterator) != KERN_SUCCESS) + { + fprintf(stderr, "IORegistryEntryGetParentIterator failed\n"); goto Exit; } - IOObjectRelease( service ); - service = IOIteratorNext( iterator ); - IOObjectRelease( iterator ); - + IOObjectRelease(service); + service = IOIteratorNext(iterator); + IOObjectRelease(iterator); } - if ( service == NULL ) { - fprintf( stderr, "CD media not found\n" ); + if (service == NULL) { + fprintf(stderr, "CD media not found\n"); goto Exit; } - if ( IORegistryEntryCreateCFProperties( service, (__CFDictionary **) &properties, - kCFAllocatorDefault, - kNilOptions ) != KERN_SUCCESS ) { - fprintf( stderr, "IORegistryEntryGetParentIterator failed\n" ); + if (IORegistryEntryCreateCFProperties(service, (__CFDictionary **) &properties, + kCFAllocatorDefault, + kNilOptions) != KERN_SUCCESS) + { + fprintf(stderr, "IORegistryEntryGetParentIterator failed\n"); goto Exit; } - data = (CFDataRef) CFDictionaryGetValue( properties, CFSTR(kIOCDMediaTOCKey) ); - if ( data == NULL ) { - fprintf( stderr, "CFDictionaryGetValue failed\n" ); + data = (CFDataRef) CFDictionaryGetValue(properties, CFSTR(kIOCDMediaTOCKey)); + if (data == NULL) { + fprintf(stderr, "CFDictionaryGetValue failed\n"); goto Exit; } else { - CFRange range; CFIndex buflen; - buflen = CFDataGetLength( data ) + 1; - range = CFRangeMake( 0, buflen ); - toc_p = (struct _CDTOC *) malloc( buflen ); - if ( toc_p == NULL ) { - fprintf( stderr, "Out of memory\n" ); + buflen = CFDataGetLength(data) + 1; + range = CFRangeMake(0, buflen); + toc_p = (struct _CDTOC *) malloc(buflen); + if (toc_p == NULL) { + fprintf(stderr, "Out of memory\n"); goto Exit; } else { - CFDataGetBytes( data, range, (unsigned char *) toc_p ); + CFDataGetBytes(data, range, (unsigned char *) toc_p); } /* - fprintf( stderr, "Table of contents\n length %d first %d last %d\n", - toc_p->length, toc_p->first_session, toc_p->last_session ); + fprintf(stderr, "Table of contents\n length %d first %d last %d\n", + toc_p->length, toc_p->first_session, toc_p->last_session); */ - CFRelease( properties ); - + CFRelease(properties); } +Exit: - Exit: - - if ( service ) { - IOObjectRelease( service ); + if (service) { + IOObjectRelease(service); } return toc_p; - } #endif @@ -436,76 +427,76 @@ static struct _CDTOC * ReadTOC( const char * devpath ) { bool ReadCDSector(unsigned int hid, unsigned int tid, unsigned int lun, unsigned long frame, unsigned char *buf, int bufsize) { - HANDLE hEventSRB; - SRB_ExecSCSICmd srb; - DWORD dwStatus; + HANDLE hEventSRB; + SRB_ExecSCSICmd srb; + DWORD dwStatus; - hEventSRB = CreateEvent(NULL, TRUE, FALSE, NULL); - - memset(&srb,0,sizeof(SRB_ExecSCSICmd)); - srb.SRB_Cmd = SC_EXEC_SCSI_CMD; - srb.SRB_HaId = hid; - srb.SRB_Target = tid; - srb.SRB_Lun = lun; - srb.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY; - srb.SRB_SenseLen = SENSE_LEN; - srb.SRB_PostProc = hEventSRB; - srb.SRB_BufPointer = buf; - srb.SRB_BufLen = bufsize; - srb.SRB_CDBLen = 10; - srb.CDBByte[0] = SCSI_READ10; - srb.CDBByte[2] = (unsigned char) (frame>>24); - srb.CDBByte[3] = (unsigned char) (frame>>16); - srb.CDBByte[4] = (unsigned char) (frame>>8); - srb.CDBByte[5] = (unsigned char) (frame); - srb.CDBByte[7] = 0; - srb.CDBByte[8] = 1; /* read 1 frames */ + hEventSRB = CreateEvent(NULL, TRUE, FALSE, NULL); + + memset(&srb,0,sizeof(SRB_ExecSCSICmd)); + srb.SRB_Cmd = SC_EXEC_SCSI_CMD; + srb.SRB_HaId = hid; + srb.SRB_Target = tid; + srb.SRB_Lun = lun; + srb.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY; + srb.SRB_SenseLen = SENSE_LEN; + srb.SRB_PostProc = hEventSRB; + srb.SRB_BufPointer = buf; + srb.SRB_BufLen = bufsize; + srb.SRB_CDBLen = 10; + srb.CDBByte[0] = SCSI_READ10; + srb.CDBByte[2] = (unsigned char) (frame>>24); + srb.CDBByte[3] = (unsigned char) (frame>>16); + srb.CDBByte[4] = (unsigned char) (frame>>8); + srb.CDBByte[5] = (unsigned char) (frame); + srb.CDBByte[7] = 0; + srb.CDBByte[8] = 1; /* read 1 frames */ - ResetEvent(hEventSRB); - dwStatus = SendASPI32Command((SRB *)&srb); - if(dwStatus == SS_PENDING) { - WaitForSingleObject(hEventSRB, 100000); - } - CloseHandle(hEventSRB); - return (srb.SRB_TargStat == STATUS_GOOD); + ResetEvent(hEventSRB); + dwStatus = SendASPI32Command((SRB *)&srb); + if(dwStatus == SS_PENDING) { + WaitForSingleObject(hEventSRB, 100000); + } + CloseHandle(hEventSRB); + return (srb.SRB_TargStat == STATUS_GOOD); } int GetCDCapacity(unsigned int hid, unsigned int tid, unsigned int lun) { - HANDLE hEventSRB; - SRB_ExecSCSICmd srb; - DWORD dwStatus; - unsigned char buf[8]; + HANDLE hEventSRB; + SRB_ExecSCSICmd srb; + DWORD dwStatus; + unsigned char buf[8]; - hEventSRB = CreateEvent(NULL, TRUE, FALSE, NULL); - - memset(&buf, 0, sizeof(buf)); - memset(&srb,0,sizeof(SRB_ExecSCSICmd)); - srb.SRB_Cmd = SC_EXEC_SCSI_CMD; - srb.SRB_HaId = hid; - srb.SRB_Target = tid; - srb.SRB_Lun = lun; - srb.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY; - srb.SRB_SenseLen = SENSE_LEN; - srb.SRB_PostProc = hEventSRB; - srb.SRB_BufPointer = (unsigned char *)buf; - srb.SRB_BufLen = 8; - srb.SRB_CDBLen = 10; - srb.CDBByte[0] = SCSI_READCDCAP; - srb.CDBByte[2] = 0; - srb.CDBByte[3] = 0; - srb.CDBByte[4] = 0; - srb.CDBByte[5] = 0; - srb.CDBByte[8] = 0; + hEventSRB = CreateEvent(NULL, TRUE, FALSE, NULL); + + memset(&buf, 0, sizeof(buf)); + memset(&srb,0,sizeof(SRB_ExecSCSICmd)); + srb.SRB_Cmd = SC_EXEC_SCSI_CMD; + srb.SRB_HaId = hid; + srb.SRB_Target = tid; + srb.SRB_Lun = lun; + srb.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY; + srb.SRB_SenseLen = SENSE_LEN; + srb.SRB_PostProc = hEventSRB; + srb.SRB_BufPointer = (unsigned char *)buf; + srb.SRB_BufLen = 8; + srb.SRB_CDBLen = 10; + srb.CDBByte[0] = SCSI_READCDCAP; + srb.CDBByte[2] = 0; + srb.CDBByte[3] = 0; + srb.CDBByte[4] = 0; + srb.CDBByte[5] = 0; + srb.CDBByte[8] = 0; - ResetEvent(hEventSRB); - dwStatus = SendASPI32Command((SRB *)&srb); - if(dwStatus == SS_PENDING) { - WaitForSingleObject(hEventSRB, 100000); - } + ResetEvent(hEventSRB); + dwStatus = SendASPI32Command((SRB *)&srb); + if(dwStatus == SS_PENDING) { + WaitForSingleObject(hEventSRB, 100000); + } - CloseHandle(hEventSRB); - return ((buf[0] << 24) + (buf[1] << 16) + (buf[2] << 8) + buf[3]) * ((buf[4] << 24) + (buf[5] << 16) + (buf[6] << 8) + buf[7]); + CloseHandle(hEventSRB); + return ((buf[0] << 24) + (buf[1] << 16) + (buf[2] << 8) + buf[3]) * ((buf[4] << 24) + (buf[5] << 16) + (buf[6] << 8) + buf[7]); } #endif @@ -532,7 +523,7 @@ cdrom_interface::cdrom_interface(char *dev) void cdrom_interface::init(void) { - BX_DEBUG(("Init $Id: cdrom.cc,v 1.90 2008-01-26 22:24:00 sshwarts Exp $")); + BX_DEBUG(("Init $Id: cdrom.cc,v 1.91 2008-02-15 22:05:41 sshwarts Exp $")); BX_INFO(("file = '%s'",path)); } @@ -561,7 +552,7 @@ cdrom_interface::insert_cdrom(char *dev) BX_INFO (("load cdrom with path=%s", path)); #ifdef WIN32 char drive[256]; - if ( (path[1] == ':') && (strlen(path) == 2) ) + if ((path[1] == ':') && (strlen(path) == 2)) { if(osinfo.dwPlatformId == VER_PLATFORM_WIN32_NT) { // Use direct device access under windows NT/2k/XP @@ -592,9 +583,9 @@ cdrom_interface::insert_cdrom(char *dev) if (!hASPI) { hASPI = LoadLibrary("WNASPI32.DLL"); if (hASPI) { - SendASPI32Command = (DWORD(*)(LPSRB))GetProcAddress( hASPI, "SendASPI32Command" ); - GetASPI32DLLVersion = (DWORD(*)(void))GetProcAddress( hASPI, "GetASPI32DLLVersion" ); - GetASPI32SupportInfo = (DWORD(*)(void))GetProcAddress( hASPI, "GetASPI32SupportInfo" ); + SendASPI32Command = (DWORD(*)(LPSRB))GetProcAddress(hASPI, "SendASPI32Command"); + GetASPI32DLLVersion = (DWORD(*)(void))GetProcAddress(hASPI, "GetASPI32DLLVersion"); + GetASPI32SupportInfo = (DWORD(*)(void))GetProcAddress(hASPI, "GetASPI32SupportInfo"); d = GetASPI32DLLVersion(); BX_INFO(("WNASPI32.DLL version %d.%02d initialized", d & 0xff, (d >> 8) & 0xff)); } else { @@ -657,28 +648,27 @@ cdrom_interface::insert_cdrom(char *dev) io_iterator_t mediaIterator; kern_return_t kernResult; - BX_INFO(( "Insert CDROM" )); + BX_INFO(("Insert CDROM")); - kernResult = FindEjectableCDMedia( &mediaIterator, &masterPort ); - if ( kernResult != KERN_SUCCESS ) { - BX_INFO (("Unable to find CDROM")); + kernResult = FindEjectableCDMedia(&mediaIterator, &masterPort); + if (kernResult != KERN_SUCCESS) { + BX_INFO(("Unable to find CDROM")); return 0; } - kernResult = GetDeviceFilePath( mediaIterator, CDDevicePath, sizeof( CDDevicePath ) ); - if ( kernResult != KERN_SUCCESS ) { - BX_INFO (("Unable to get CDROM device file path" )); + kernResult = GetDeviceFilePath(mediaIterator, CDDevicePath, sizeof(CDDevicePath)); + if (kernResult != KERN_SUCCESS) { + BX_INFO(("Unable to get CDROM device file path")); return 0; } // Here a cdrom was found so see if we can read from it. // At this point a failure will result in panic. - if ( strlen( CDDevicePath ) ) { + if (strlen(CDDevicePath)) { fd = open(CDDevicePath, O_RDONLY); } } - else - { + else { fd = open(path, O_RDONLY); } #else @@ -686,7 +676,7 @@ cdrom_interface::insert_cdrom(char *dev) fd = open(path, O_RDONLY); #endif if (fd < 0) { - BX_ERROR(( "open cd failed for %s: %s", path, strerror(errno))); + BX_ERROR(("open cd failed for %s: %s", path, strerror(errno))); return 0; } #ifndef WIN32 @@ -718,11 +708,11 @@ cdrom_interface::start_cdrom() if (fd >= 0) { #if defined(__NetBSD__) || defined(__NetBSD_kernel__) if (ioctl (fd, CDIOCSTART) < 0) - BX_DEBUG(( "start_cdrom: start returns error: %s", strerror (errno) )); + BX_DEBUG(("start_cdrom: start returns error: %s", strerror (errno))); return 1; #else - BX_INFO(("start_cdrom: your OS is not supported yet.")); - return 0; // OS not supported yet, return 0 always. + BX_INFO(("start_cdrom: your OS is not supported yet")); + return 0; // OS not supported yet, return 0 always #endif } return 0; @@ -738,7 +728,7 @@ cdrom_interface::eject_cdrom() #if (defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)) (void) ioctl (fd, CDIOCALLOW); if (ioctl (fd, CDIOCEJECT) < 0) - BX_DEBUG(( "eject_cdrom: eject returns error." )); + BX_DEBUG(("eject_cdrom: eject returns error")); #endif #ifdef WIN32 @@ -1091,7 +1081,7 @@ cdrom_interface::read_toc(Bit8u* buf, int* length, bx_bool msf, int start_track, #if 1 { - struct _CDTOC * toc = ReadTOC( CDDevicePath ); + struct _CDTOC *toc = ReadTOC(CDDevicePath); if ((start_track > toc->last_session) && (start_track != 0xaa)) return 0; @@ -1153,18 +1143,16 @@ cdrom_interface::read_toc(Bit8u* buf, int* length, bx_bool msf, int start_track, return 1; } #else - BX_INFO(( "Read TOC - Not Implemented" )); + BX_INFO(("Read TOC - Not Implemented")); return 0; #endif #else - BX_INFO(("read_toc: your OS is not supported yet.")); + BX_INFO(("read_toc: your OS is not supported yet")); return 0; // OS not supported yet, return 0 always. #endif } - - Bit32u -cdrom_interface::capacity() +Bit32u cdrom_interface::capacity() { // Return CD-ROM capacity. I believe you want to return // the number of blocks of capacity the actual media has. @@ -1195,7 +1183,7 @@ cdrom_interface::capacity() BX_PANIC(("cdrom: capacity: file not open.")); } - if( fstat(fd, &buf) != 0 ) + if(fstat(fd, &buf) != 0) BX_PANIC(("cdrom: capacity: stat() failed.")); return(buf.st_size); @@ -1211,7 +1199,7 @@ cdrom_interface::capacity() if (ioctl(fd, DIOCGDINFO, &lp) < 0) BX_PANIC(("cdrom: ioctl(DIOCGDINFO) failed")); - BX_DEBUG(( "capacity: %u", lp.d_secperunit )); + BX_DEBUG(("capacity: %u", lp.d_secperunit)); return(lp.d_secperunit); } #elif defined(__linux__) @@ -1300,7 +1288,7 @@ cdrom_interface::capacity() if (rte.data[i].control & 4) { /* data track */ num_sectors = ntohl(rte.data[i + 1].addr.lba) - ntohl(rte.data[i].addr.lba); - BX_INFO(( "cdrom: Data track %d, length %d", + BX_INFO(("cdrom: Data track %d, length %d", rte.data[i].track, num_sectors)); break; } @@ -1330,7 +1318,7 @@ cdrom_interface::capacity() ULARGE_INTEGER FreeBytesForCaller; ULARGE_INTEGER TotalNumOfBytes; ULARGE_INTEGER TotalFreeBytes; - GetDiskFreeSpaceEx( path, &FreeBytesForCaller, &TotalNumOfBytes, &TotalFreeBytes); + GetDiskFreeSpaceEx(path, &FreeBytesForCaller, &TotalNumOfBytes, &TotalFreeBytes); return (Bit32u)(TotalNumOfBytes.QuadPart / 2048); } } @@ -1345,17 +1333,17 @@ cdrom_interface::capacity() // Return CD-ROM capacity. I believe you want to return // the number of bytes of capacity the actual media has. - BX_INFO(( "Capacity" )); + BX_INFO(("Capacity")); - struct _CDTOC * toc = ReadTOC( CDDevicePath ); + struct _CDTOC *toc = ReadTOC(CDDevicePath); - if ( toc == NULL ) { - BX_PANIC(( "capacity: Failed to read toc" )); + if (toc == NULL) { + BX_PANIC(("capacity: Failed to read toc")); } - size_t toc_entries = ( toc->length - 2 ) / sizeof( struct _CDTOC_Desc ); + size_t toc_entries = (toc->length - 2) / sizeof(struct _CDTOC_Desc); - BX_DEBUG(( "reading %d toc entries\n", toc_entries )); + BX_DEBUG(("reading %d toc entries\n", toc_entries)); int start_sector = -1; int data_track = -1; @@ -1364,32 +1352,32 @@ cdrom_interface::capacity() // get the address of the immediately previous (or following depending // on how you look at it). The difference in the sector numbers // is returned as the sized of the data track. - for ( int i=toc_entries - 1; i>=0; i-- ) { - BX_DEBUG(( "session %d ctl_adr %d tno %d point %d lba %d z %d p lba %d\n", + for (int i=toc_entries - 1; i>=0; i--) { + BX_DEBUG(("session %d ctl_adr %d tno %d point %d lba %d z %d p lba %d\n", (int)toc->trackdesc[i].session, (int)toc->trackdesc[i].ctrl_adr, (int)toc->trackdesc[i].tno, (int)toc->trackdesc[i].point, - MSF_TO_LBA( toc->trackdesc[i].address ), + MSF_TO_LBA(toc->trackdesc[i].address), (int)toc->trackdesc[i].zero, - MSF_TO_LBA(toc->trackdesc[i].p ))); + MSF_TO_LBA(toc->trackdesc[i].p))); - if ( start_sector != -1 ) { + if (start_sector != -1) { start_sector = MSF_TO_LBA(toc->trackdesc[i].p) - start_sector; break; } if ((toc->trackdesc[i].ctrl_adr >> 4) != 1) continue; - if ( toc->trackdesc[i].ctrl_adr & 0x04 ) { + if (toc->trackdesc[i].ctrl_adr & 0x04) { data_track = toc->trackdesc[i].point; start_sector = MSF_TO_LBA(toc->trackdesc[i].p); } } - free( toc ); + free(toc); - if ( start_sector == -1 ) { + if (start_sector == -1) { start_sector = 0; } @@ -1398,7 +1386,7 @@ cdrom_interface::capacity() return start_sector; } #else - BX_ERROR(( "capacity: your OS is not supported yet." )); + BX_ERROR(("capacity: your OS is not supported yet")); return(0); #endif } diff --git a/bochs/iodev/cmos.cc b/bochs/iodev/cmos.cc index ff577c105..802536299 100644 --- a/bochs/iodev/cmos.cc +++ b/bochs/iodev/cmos.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: cmos.cc,v 1.63 2008-01-26 22:24:00 sshwarts Exp $ +// $Id: cmos.cc,v 1.64 2008-02-15 22:05:41 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2002 MandrakeSoft S.A. @@ -140,7 +140,7 @@ bx_cmos_c::~bx_cmos_c(void) void bx_cmos_c::init(void) { - BX_DEBUG(("Init $Id: cmos.cc,v 1.63 2008-01-26 22:24:00 sshwarts Exp $")); + BX_DEBUG(("Init $Id: cmos.cc,v 1.64 2008-02-15 22:05:41 sshwarts Exp $")); // CMOS RAM & RTC DEV_register_ioread_handler(this, read_handler, 0x0070, "CMOS RAM", 1); @@ -519,11 +519,11 @@ void bx_cmos_c::write(Bit32u address, Bit32u value, unsigned io_len) unsigned prev_CRB; prev_CRB = BX_CMOS_THIS s.reg[REG_STAT_B]; BX_CMOS_THIS s.reg[REG_STAT_B] = value; - if ( (prev_CRB & 0x02) != (value & 0x02) ) { + if ((prev_CRB & 0x02) != (value & 0x02)) { BX_CMOS_THIS s.rtc_mode_12hour = ((value & 0x02) == 0); update_clock(); } - if ( (prev_CRB & 0x04) != (value & 0x04) ) { + if ((prev_CRB & 0x04) != (value & 0x04)) { BX_CMOS_THIS s.rtc_mode_binary = ((value & 0x04) != 0); update_clock(); } diff --git a/bochs/iodev/devices.cc b/bochs/iodev/devices.cc index eb54a99c3..e6365e2f0 100644 --- a/bochs/iodev/devices.cc +++ b/bochs/iodev/devices.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: devices.cc,v 1.119 2008-01-26 22:24:00 sshwarts Exp $ +// $Id: devices.cc,v 1.120 2008-02-15 22:05:42 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2002 MandrakeSoft S.A. @@ -122,7 +122,7 @@ void bx_devices_c::init(BX_MEM_C *newmem) unsigned i; const char def_name[] = "Default"; - BX_DEBUG(("Init $Id: devices.cc,v 1.119 2008-01-26 22:24:00 sshwarts Exp $")); + BX_DEBUG(("Init $Id: devices.cc,v 1.120 2008-02-15 22:05:42 sshwarts Exp $")); mem = newmem; /* set no-default handlers, will be overwritten by the real default handler */ @@ -302,16 +302,16 @@ void bx_devices_c::init(BX_MEM_C *newmem) DEV_cmos_set_reg(0x15, (Bit8u) BASE_MEMORY_IN_K); DEV_cmos_set_reg(0x16, (Bit8u) (BASE_MEMORY_IN_K >> 8)); - DEV_cmos_set_reg(0x17, (Bit8u) (extended_memory_in_k & 0xff) ); - DEV_cmos_set_reg(0x18, (Bit8u) ((extended_memory_in_k >> 8) & 0xff) ); - DEV_cmos_set_reg(0x30, (Bit8u) (extended_memory_in_k & 0xff) ); - DEV_cmos_set_reg(0x31, (Bit8u) ((extended_memory_in_k >> 8) & 0xff) ); + DEV_cmos_set_reg(0x17, (Bit8u) (extended_memory_in_k & 0xff)); + DEV_cmos_set_reg(0x18, (Bit8u) ((extended_memory_in_k >> 8) & 0xff)); + DEV_cmos_set_reg(0x30, (Bit8u) (extended_memory_in_k & 0xff)); + DEV_cmos_set_reg(0x31, (Bit8u) ((extended_memory_in_k >> 8) & 0xff)); Bit32u extended_memory_in_64k = mem->get_memory_in_k() > 16384 ? (mem->get_memory_in_k() - 16384) / 64 : 0; if (extended_memory_in_64k > 0xffff) extended_memory_in_64k = 0xffff; - DEV_cmos_set_reg(0x34, (Bit8u) (extended_memory_in_64k & 0xff) ); - DEV_cmos_set_reg(0x35, (Bit8u) ((extended_memory_in_64k >> 8) & 0xff) ); + DEV_cmos_set_reg(0x34, (Bit8u) (extended_memory_in_64k & 0xff)); + DEV_cmos_set_reg(0x35, (Bit8u) ((extended_memory_in_64k >> 8) & 0xff)); if (timer_handle != BX_NULL_TIMER_HANDLE) { timer_handle = bx_pc_system.register_timer(this, timer_handler, @@ -467,7 +467,7 @@ void bx_devices_c::port92_write(Bit32u address, Bit32u value, unsigned io_len) BX_DEBUG(("port92h write of %02x partially supported!!!", (unsigned) value)); BX_DEBUG(("A20: set_enable_a20() called")); - BX_SET_ENABLE_A20( (value & 0x02) >> 1 ); + BX_SET_ENABLE_A20((value & 0x02) >> 1); BX_DEBUG(("A20: now %u", (unsigned) BX_GET_ENABLE_A20())); if (value & 0x01) { /* high speed reset */ BX_INFO(("iowrite to port0x92 : reset resquested")); diff --git a/bochs/iodev/dma.cc b/bochs/iodev/dma.cc index 9e77296dd..7898c7b81 100644 --- a/bochs/iodev/dma.cc +++ b/bochs/iodev/dma.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: dma.cc,v 1.45 2008-01-26 22:24:01 sshwarts Exp $ +// $Id: dma.cc,v 1.46 2008-02-15 22:05:42 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2002 MandrakeSoft S.A. @@ -23,8 +23,7 @@ // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - +///////////////////////////////////////////////////////////////////////// // Define BX_PLUGGABLE in files that can be compiled into plugins. For // platforms that require a special tag on exported symbols, BX_PLUGGABLE @@ -123,7 +122,7 @@ unsigned bx_dma_c::get_TC(void) void bx_dma_c::init(void) { unsigned c, i, j; - BX_DEBUG(("Init $Id: dma.cc,v 1.45 2008-01-26 22:24:01 sshwarts Exp $")); + BX_DEBUG(("Init $Id: dma.cc,v 1.46 2008-02-15 22:05:42 sshwarts Exp $")); /* 8237 DMA controller */ @@ -379,7 +378,7 @@ bx_dma_c::write(Bit32u address, Bit32u value, unsigned io_len) Bit8u channel; if (io_len > 1) { - if ( (io_len == 2) && (address == 0x0b) ) { + if ((io_len == 2) && (address == 0x0b)) { #if BX_USE_DMA_SMF BX_DMA_THIS write_handler(NULL, address, value & 0xff, 1); BX_DMA_THIS write_handler(NULL, address+1, value >> 8, 1); @@ -617,11 +616,13 @@ void bx_dma_c::set_DRQ(unsigned channel, bx_bool val) BX_DMA_THIS s[ma_sl].status_reg |= (1 << (channel+4)); - if ( (BX_DMA_THIS s[ma_sl].chan[channel].mode.mode_type != DMA_MODE_SINGLE) && - (BX_DMA_THIS s[ma_sl].chan[channel].mode.mode_type != DMA_MODE_DEMAND) && - (BX_DMA_THIS s[ma_sl].chan[channel].mode.mode_type != DMA_MODE_CASCADE) ) + if ((BX_DMA_THIS s[ma_sl].chan[channel].mode.mode_type != DMA_MODE_SINGLE) && + (BX_DMA_THIS s[ma_sl].chan[channel].mode.mode_type != DMA_MODE_DEMAND) && + (BX_DMA_THIS s[ma_sl].chan[channel].mode.mode_type != DMA_MODE_CASCADE)) + { BX_PANIC(("set_DRQ: mode_type(%02x) not handled", (unsigned) BX_DMA_THIS s[ma_sl].chan[channel].mode.mode_type)); + } dma_base = (BX_DMA_THIS s[ma_sl].chan[channel].page_reg << 16) | (BX_DMA_THIS s[ma_sl].chan[channel].base_address << ma_sl); @@ -630,7 +631,7 @@ void bx_dma_c::set_DRQ(unsigned channel, bx_bool val) } else { dma_roof = dma_base - (BX_DMA_THIS s[ma_sl].chan[channel].base_count << ma_sl); } - if ( (dma_base & (0x7fff0000 << ma_sl)) != (dma_roof & (0x7fff0000 << ma_sl)) ) { + if ((dma_base & (0x7fff0000 << ma_sl)) != (dma_roof & (0x7fff0000 << ma_sl))) { BX_INFO(("dma_base = %08x", (unsigned) dma_base)); BX_INFO(("dma_base_count = %08x", (unsigned) BX_DMA_THIS s[ma_sl].chan[channel].base_count)); BX_INFO(("dma_roof = %08x", (unsigned) dma_roof)); @@ -659,8 +660,8 @@ void bx_dma_c::control_HRQ(bx_bool ma_sl) } // find highest priority channel for (channel=0; channel<4; channel++) { - if ( (BX_DMA_THIS s[ma_sl].status_reg & (1 << (channel+4))) && - (BX_DMA_THIS s[ma_sl].mask[channel]==0) ) { + if ((BX_DMA_THIS s[ma_sl].status_reg & (1 << (channel+4))) && + (BX_DMA_THIS s[ma_sl].mask[channel]==0)) { if (ma_sl) { // assert Hold ReQuest line to CPU bx_pc_system.set_HRQ(1); @@ -683,8 +684,8 @@ void bx_dma_c::raise_HLDA(void) BX_DMA_THIS HLDA = 1; // find highest priority channel for (channel=0; channel<4; channel++) { - if ( (BX_DMA_THIS s[1].status_reg & (1 << (channel+4))) && - (BX_DMA_THIS s[1].mask[channel]==0) ) { + if ((BX_DMA_THIS s[1].status_reg & (1 << (channel+4))) && + (BX_DMA_THIS s[1].mask[channel]==0)) { ma_sl = 1; break; } @@ -692,8 +693,8 @@ void bx_dma_c::raise_HLDA(void) if (channel == 0) { // master cascade channel BX_DMA_THIS s[1].DACK[0] = 1; for (channel=0; channel<4; channel++) { - if ( (BX_DMA_THIS s[0].status_reg & (1 << (channel+4))) && - (BX_DMA_THIS s[0].mask[channel]==0) ) { + if ((BX_DMA_THIS s[0].status_reg & (1 << (channel+4))) && + (BX_DMA_THIS s[0].mask[channel]==0)) { ma_sl = 0; break; } diff --git a/bochs/iodev/dma.h b/bochs/iodev/dma.h index aa5bbafda..af951abeb 100644 --- a/bochs/iodev/dma.h +++ b/bochs/iodev/dma.h @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: dma.h,v 1.21 2007-09-28 19:51:59 sshwarts Exp $ +// $Id: dma.h,v 1.22 2008-02-15 22:05:42 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2002 MandrakeSoft S.A. @@ -64,8 +64,8 @@ private: static Bit32u read_handler(void *this_ptr, Bit32u address, unsigned io_len); static void write_handler(void *this_ptr, Bit32u address, Bit32u value, unsigned io_len); #if !BX_USE_DMA_SMF - Bit32u read( Bit32u address, unsigned io_len) BX_CPP_AttrRegparmN(2); - void write(Bit32u address, Bit32u value, unsigned io_len) BX_CPP_AttrRegparmN(3); + Bit32u read (Bit32u address, unsigned io_len) BX_CPP_AttrRegparmN(2); + void write(Bit32u address, Bit32u value, unsigned io_len) BX_CPP_AttrRegparmN(3); #endif BX_DMA_SMF void control_HRQ(bx_bool ma_sl); BX_DMA_SMF void reset_controller(unsigned num); diff --git a/bochs/iodev/eth.cc b/bochs/iodev/eth.cc index e01a5fb38..319ec33ba 100644 --- a/bochs/iodev/eth.cc +++ b/bochs/iodev/eth.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: eth.cc,v 1.25 2008-01-26 22:24:01 sshwarts Exp $ +// $Id: eth.cc,v 1.26 2008-02-15 22:05:42 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -168,19 +168,19 @@ extern "C" { #define LOG_THIS bx_devices.pluginNE2kDevice-> // This is a utility script used for tuntap or ethertap -int execute_script( char* scriptname, char* arg1 ) +int execute_script(char* scriptname, char* arg1) { int pid,status; if (!(pid=fork())) { char filename[BX_PATHNAME_LEN]; - if ( scriptname[0]=='/' ) { - strcpy (filename, scriptname); + if (scriptname[0]=='/') { + strcpy(filename, scriptname); } else { - getcwd (filename, BX_PATHNAME_LEN); - strcat (filename, "/"); - strcat (filename, scriptname); + getcwd(filename, BX_PATHNAME_LEN); + strcat(filename, "/"); + strcat(filename, scriptname); } // execute the script diff --git a/bochs/iodev/eth_packetmaker.cc b/bochs/iodev/eth_packetmaker.cc index 3d3b26ac9..557e04ea8 100644 --- a/bochs/iodev/eth_packetmaker.cc +++ b/bochs/iodev/eth_packetmaker.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: eth_packetmaker.cc,v 1.15 2008-01-26 22:24:01 sshwarts Exp $ +// $Id: eth_packetmaker.cc,v 1.16 2008-02-15 22:05:42 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Define BX_PLUGGABLE in files that can be compiled into plugins. For @@ -14,25 +14,27 @@ #include "eth_packetmaker.h" - bx_bool sendable(const eth_packet& outpacket) { //FINISH ME! return 0; } -Bit32u eth_IPmaker::datalen(const eth_packet& outpacket) { +Bit32u eth_IPmaker::datalen(const eth_packet& outpacket) +{ Bit32u out; out=((outpacket.buf[16]<<8)+outpacket.buf[17])-(4*(0xF & outpacket.buf[14])); return out; } -const Bit8u * eth_IPmaker::datagram(const eth_packet& outpacket) { - const Bit8u * out; +const Bit8u *eth_IPmaker::datagram(const eth_packet& outpacket) +{ + const Bit8u *out; out=outpacket.buf+14+(4*(0xF & outpacket.buf[14])); return out; } -Bit32u eth_IPmaker::build_packet_header(Bit32u source, Bit32u dest, Bit8u protocol, Bit32u datalen) { +Bit32u eth_IPmaker::build_packet_header(Bit32u source, Bit32u dest, Bit8u protocol, Bit32u datalen) +{ Bit32u temp; Bit32u i; memcpy(pending.buf,internal_mac,6); @@ -73,49 +75,51 @@ Bit32u eth_IPmaker::build_packet_header(Bit32u source, Bit32u dest, Bit8u protoc return(34); } -Bit8u eth_IPmaker::protocol(const eth_packet& outpacket) { +Bit8u eth_IPmaker::protocol(const eth_packet& outpacket) +{ return (*(outpacket.buf+23) & 0xff); } -Bit32u eth_IPmaker::source(const eth_packet& outpacket) { - Bit32u out; - out=0xFF & *(outpacket.buf+26); +Bit32u eth_IPmaker::source(const eth_packet& outpacket) +{ + Bit32u out=0xFF & *(outpacket.buf+26); out=(out<<8) | (0xFF & *(outpacket.buf+27)); out=(out<<8) | (0xFF & *(outpacket.buf+28)); out=(out<<8) | (0xFF & *(outpacket.buf+29)); return out; } -Bit32u eth_IPmaker::destination(const eth_packet& outpacket) { - Bit32u out; - out=0xFF & *(outpacket.buf+30); +Bit32u eth_IPmaker::destination(const eth_packet& outpacket) +{ + Bit32u out=0xFF & *(outpacket.buf+30); out=(out<<8) | (0xFF & *(outpacket.buf+31)); out=(out<<8) | (0xFF & *(outpacket.buf+32)); out=(out<<8) | (0xFF & *(outpacket.buf+33)); return out; } -void eth_IPmaker::init(void) { +void eth_IPmaker::init(void) +{ is_pending=0; } -void -eth_ETHmaker::init(void) { +void eth_ETHmaker::init(void) +{ arper.init(); } -bx_bool -eth_ETHmaker::getpacket(eth_packet& inpacket) { +bx_bool eth_ETHmaker::getpacket(eth_packet& inpacket) +{ return arper.getpacket(inpacket); } -bx_bool -eth_ETHmaker::ishandler(const eth_packet& outpacket) { +bx_bool eth_ETHmaker::ishandler(const eth_packet& outpacket) +{ if((outpacket.len>=60) && ( (!memcmp(outpacket.buf, external_mac, 6)) - || (!memcmp(outpacket.buf, broadcast_macaddr, 6)) ) && + || (!memcmp(outpacket.buf, broadcast_macaddr, 6))) && ( (!memcmp(outpacket.buf+12, ethtype_arp, 2)) || - (!memcmp(outpacket.buf+12, ethtype_ip, 2)) ) && + (!memcmp(outpacket.buf+12, ethtype_ip, 2))) && (outpacket.len=60) && (!memcmp(outpacket.buf+12, ethtype_arp, 2)) && (outpacket.lenrx_timer_index = @@ -269,8 +268,7 @@ bx_tap_pktmover_c::bx_tap_pktmover_c(const char *netif, #endif } -void -bx_tap_pktmover_c::sendpkt(void *buf, unsigned io_len) +void bx_tap_pktmover_c::sendpkt(void *buf, unsigned io_len) { Bit8u txbuf[BX_PACKET_BUFSIZE]; txbuf[0] = 0; @@ -310,13 +308,13 @@ bx_tap_pktmover_c::sendpkt(void *buf, unsigned io_len) #endif } -void bx_tap_pktmover_c::rx_timer_handler (void *this_ptr) +void bx_tap_pktmover_c::rx_timer_handler(void *this_ptr) { bx_tap_pktmover_c *class_ptr = (bx_tap_pktmover_c *) this_ptr; class_ptr->rx_timer(); } -void bx_tap_pktmover_c::rx_timer () +void bx_tap_pktmover_c::rx_timer() { int nbytes; Bit8u buf[BX_PACKET_BUFSIZE]; diff --git a/bochs/iodev/eth_tuntap.cc b/bochs/iodev/eth_tuntap.cc index 195dfb378..26ef8ea1e 100644 --- a/bochs/iodev/eth_tuntap.cc +++ b/bochs/iodev/eth_tuntap.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: eth_tuntap.cc,v 1.27 2008-01-26 22:24:01 sshwarts Exp $ +// $Id: eth_tuntap.cc,v 1.28 2008-02-15 22:05:42 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -23,6 +23,8 @@ // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +///////////////////////////////////////////////////////////////////////// // eth_tuntap.cc - TUN/TAP interface by Renzo Davoli @@ -133,28 +135,28 @@ bx_tuntap_pktmover_c::bx_tuntap_pktmover_c(const char *netif, // check if the TUN/TAP devices is running, and turn on ARP. This is based // on code from the Mac-On-Linux project. http://http://www.maconlinux.org/ - int sock = socket( AF_INET, SOCK_DGRAM, 0 ); + int sock = socket(AF_INET, SOCK_DGRAM, 0); if (sock < 0) { BX_PANIC (("socket creation: %s", strerror(errno))); return; } struct ifreq ifr; - memset( &ifr, 0, sizeof(ifr) ); - strncpy( ifr.ifr_name, netif, sizeof(ifr.ifr_name) ); - if( ioctl( sock, SIOCGIFFLAGS, &ifr ) < 0 ){ + memset(&ifr, 0, sizeof(ifr)); + strncpy(ifr.ifr_name, netif, sizeof(ifr.ifr_name)); + if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0) { BX_PANIC (("SIOCGIFFLAGS on %s: %s", netif, strerror (errno))); close(sock); return; } - if( !(ifr.ifr_flags & IFF_RUNNING ) ){ + if (!(ifr.ifr_flags & IFF_RUNNING)) { BX_PANIC (("%s device is not running", netif)); close(sock); return; } - if( (ifr.ifr_flags & IFF_NOARP ) ){ + if ((ifr.ifr_flags & IFF_NOARP)) { BX_INFO (("turn on ARP for %s device", netif)); ifr.ifr_flags &= ~IFF_NOARP; - if( ioctl( sock, SIOCSIFFLAGS, &ifr ) < 0 ) { + if (ioctl(sock, SIOCSIFFLAGS, &ifr) < 0) { BX_PANIC (("SIOCSIFFLAGS: %s", strerror(errno))); close(sock); return; @@ -168,28 +170,27 @@ bx_tuntap_pktmover_c::bx_tuntap_pktmover_c(const char *netif, strcpy(intname,netif); fd=tun_alloc(intname); if (fd < 0) { - BX_PANIC (("open failed on %s: %s", netif, strerror (errno))); + BX_PANIC(("open failed on %s: %s", netif, strerror (errno))); return; } /* set O_ASYNC flag so that we can poll with read() */ - if ((flags = fcntl( fd, F_GETFL)) < 0) { + if ((flags = fcntl(fd, F_GETFL)) < 0) { BX_PANIC (("getflags on tun device: %s", strerror (errno))); } flags |= O_NONBLOCK; - if (fcntl( fd, F_SETFL, flags ) < 0) { - BX_PANIC (("set tun device flags: %s", strerror (errno))); + if (fcntl(fd, F_SETFL, flags) < 0) { + BX_PANIC(("set tun device flags: %s", strerror (errno))); } - BX_INFO (("eth_tuntap: opened %s device", netif)); + BX_INFO(("eth_tuntap: opened %s device", netif)); /* Execute the configuration script */ - if((script != NULL) - &&(strcmp(script, "") != 0) - &&(strcmp(script, "none") != 0)) { + if((script != NULL) && (strcmp(script, "") != 0) && (strcmp(script, "none") != 0)) + { if (execute_script(script, intname) < 0) BX_ERROR (("execute script '%s' on %s failed", script, intname)); - } + } // Start the rx poll this->rx_timer_index = @@ -228,8 +229,7 @@ bx_tuntap_pktmover_c::bx_tuntap_pktmover_c(const char *netif, #endif } -void -bx_tuntap_pktmover_c::sendpkt(void *buf, unsigned io_len) +void bx_tuntap_pktmover_c::sendpkt(void *buf, unsigned io_len) { #ifdef __APPLE__ //FIXME unsigned int size = write (fd, (char*)buf+14, io_len-14); @@ -359,7 +359,6 @@ void bx_tuntap_pktmover_c::rx_timer () (*rxh)(rxarg, rxbuf, nbytes); } - int tun_alloc(char *dev) { struct ifreq ifr; @@ -369,10 +368,10 @@ int tun_alloc(char *dev) // split name into device:ifname if applicable, to allow for opening // persistent tuntap devices for (ifname = dev; *ifname; ifname++) { - if (*ifname == ':') { - *(ifname++) = '\0'; - break; - } + if (*ifname == ':') { + *(ifname++) = '\0'; + break; + } } if ((fd = open(dev, O_RDWR)) < 0) return -1; @@ -393,7 +392,7 @@ int tun_alloc(char *dev) strncpy(dev, ifr.ifr_name, IFNAMSIZ); dev[IFNAMSIZ-1]=0; - ioctl( fd, TUNSETNOCSUM, 1 ); + ioctl(fd, TUNSETNOCSUM, 1); #endif return fd; diff --git a/bochs/iodev/eth_vde.cc b/bochs/iodev/eth_vde.cc index 6ea9455b7..04d75d5ea 100644 --- a/bochs/iodev/eth_vde.cc +++ b/bochs/iodev/eth_vde.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: eth_vde.cc,v 1.14 2008-01-26 22:24:01 sshwarts Exp $ +// $Id: eth_vde.cc,v 1.15 2008-02-15 22:05:42 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2003 Renzo Davoli @@ -17,6 +17,8 @@ // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +///////////////////////////////////////////////////////////////////////// // eth_vde.cc - Virtual Distributed Ethernet interface by Renzo Davoli // @@ -127,23 +129,22 @@ bx_vde_pktmover_c::bx_vde_pktmover_c(const char *netif, } /* set O_ASYNC flag so that we can poll with read() */ - if ((flags = fcntl( fd, F_GETFL)) < 0) { + if ((flags = fcntl(fd, F_GETFL)) < 0) { BX_PANIC (("getflags on vde device: %s", strerror (errno))); } flags |= O_NONBLOCK; - if (fcntl( fd, F_SETFL, flags ) < 0) { + if (fcntl(fd, F_SETFL, flags) < 0) { BX_PANIC (("set vde device flags: %s", strerror (errno))); } - BX_INFO (("eth_vde: opened %s device", netif)); + BX_INFO(("eth_vde: opened %s device", netif)); /* Execute the configuration script */ - if((script != NULL) - &&(strcmp(script, "") != 0) - &&(strcmp(script, "none") != 0)) { + if((script != NULL) && (strcmp(script, "") != 0) && (strcmp(script, "none") != 0)) + { if (execute_script(script, intname) < 0) BX_ERROR (("execute script '%s' on %s failed", script, intname)); - } + } // Start the rx poll this->rx_timer_index = @@ -181,8 +182,7 @@ bx_vde_pktmover_c::bx_vde_pktmover_c(const char *netif, #endif } -void -bx_vde_pktmover_c::sendpkt(void *buf, unsigned io_len) +void bx_vde_pktmover_c::sendpkt(void *buf, unsigned io_len) { unsigned int size; //size = write (fd, buf, io_len); @@ -273,68 +273,69 @@ void bx_vde_pktmover_c::rx_timer () #define REQ_NEW_CONTROL 0 struct request_v3 { - Bit32u magic; - Bit32u version; - //enum request_type type; - int type; - struct sockaddr_un sock; + Bit32u magic; + Bit32u version; + //enum request_type type; + int type; + struct sockaddr_un sock; }; static int send_fd(char *name, int fddata, struct sockaddr_un *datasock, int group) { - int pid = getpid(); - struct request_v3 req; - int fdctl; - struct sockaddr_un sock; - if((fdctl = socket(AF_UNIX, SOCK_STREAM, 0)) < 0){ - perror("socket"); - return(-1); - } - sock.sun_family = AF_UNIX; - snprintf(sock.sun_path, sizeof(sock.sun_path), "%s", name); - if(connect(fdctl, (struct sockaddr *) &sock, sizeof(sock))){ - perror("connect"); - return(-1); - } - req.magic=SWITCH_MAGIC; - req.version=3; - req.type=((int)REQ_NEW_CONTROL)+((group > 0)?((geteuid()<<8) + group) << 8:0); - req.sock.sun_family=AF_UNIX; - memset(req.sock.sun_path, 0, sizeof(req.sock.sun_path)); - sprintf(&req.sock.sun_path[1], "%5d", pid); - if(bind(fddata, (struct sockaddr *) &req.sock, sizeof(req.sock)) < 0){ - perror("bind"); - return(-1); - } - if (send(fdctl,&req,sizeof(req),0) < 0) { - perror("send"); - return(-1); - } - if (recv(fdctl,datasock,sizeof(struct sockaddr_un),0)<0) { - perror("recv"); - return(-1); - } - return fdctl; + int pid = getpid(); + struct request_v3 req; + int fdctl; + struct sockaddr_un sock; + + if((fdctl = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { + perror("socket"); + return(-1); + } + sock.sun_family = AF_UNIX; + snprintf(sock.sun_path, sizeof(sock.sun_path), "%s", name); + if(connect(fdctl, (struct sockaddr *) &sock, sizeof(sock))) { + perror("connect"); + return(-1); + } + + req.magic=SWITCH_MAGIC; + req.version=3; + req.type=((int)REQ_NEW_CONTROL)+((group > 0)?((geteuid()<<8) + group) << 8:0); + req.sock.sun_family=AF_UNIX; + memset(req.sock.sun_path, 0, sizeof(req.sock.sun_path)); + sprintf(&req.sock.sun_path[1], "%5d", pid); + + if(bind(fddata, (struct sockaddr *) &req.sock, sizeof(req.sock)) < 0) { + perror("bind"); + return(-1); + } + if (send(fdctl,&req,sizeof(req),0) < 0) { + perror("send"); + return(-1); + } + if (recv(fdctl,datasock,sizeof(struct sockaddr_un),0) < 0) { + perror("recv"); + return(-1); + } + return fdctl; } int vde_alloc(char *dev, int *fdp, struct sockaddr_un *pdataout) { - //struct ifreq ifr; - //int err; - int fd, fddata; + //struct ifreq ifr; + //int err; + int fd, fddata; - if((fddata = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0){ - return -1; - } + if ((fddata = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0) + return -1; + if ((fd = send_fd(dev, fddata, pdataout, 0)) < 0) + return -1; - if( (fd = send_fd(dev, fddata, pdataout, 0)) < 0 ) - return -1; + //memset(&ifr, 0, sizeof(ifr)); + *fdp=fddata; - //memset(&ifr, 0, sizeof(ifr)); - *fdp=fddata; - - return fd; + return fd; } #endif /* if BX_NETWORKING && defined HAVE_VDE */ diff --git a/bochs/iodev/floppy.cc b/bochs/iodev/floppy.cc index d4e39c14d..6efe697ac 100644 --- a/bochs/iodev/floppy.cc +++ b/bochs/iodev/floppy.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: floppy.cc,v 1.109 2008-01-26 22:24:01 sshwarts Exp $ +// $Id: floppy.cc,v 1.110 2008-02-15 22:05:42 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2002 MandrakeSoft S.A. @@ -24,6 +24,8 @@ // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // +///////////////////////////////////////////////////////////////////////// + // // Floppy Disk Controller Docs: // Intel 82077A Data sheet @@ -139,7 +141,7 @@ void bx_floppy_ctrl_c::init(void) { Bit8u i; - BX_DEBUG(("Init $Id: floppy.cc,v 1.109 2008-01-26 22:24:01 sshwarts Exp $")); + BX_DEBUG(("Init $Id: floppy.cc,v 1.110 2008-02-15 22:05:42 sshwarts Exp $")); DEV_dma_register_8bit_channel(2, dma_read, dma_write, "Floppy Drive"); DEV_register_irq(6, "Floppy Drive"); for (unsigned addr=0x03F2; addr<=0x03F7; addr++) { @@ -324,7 +326,7 @@ void bx_floppy_ctrl_c::init(void) if (BX_FD_THIS s.floppy_timer_index == BX_NULL_TIMER_HANDLE) { BX_FD_THIS s.floppy_timer_index = - bx_pc_system.register_timer( this, timer_handler, 250, 0, 0, "floppy"); + bx_pc_system.register_timer(this, timer_handler, 250, 0, 0, "floppy"); } /* phase out s.non_dma in favor of using FD_MS_NDMA, more like hardware */ BX_FD_THIS s.main_status_reg &= ~FD_MS_NDMA; // enable DMA from start @@ -450,7 +452,7 @@ Bit32u bx_floppy_ctrl_c::read_handler(void *this_ptr, Bit32u address, unsigned i #if !BX_USE_FD_SMF bx_floppy_ctrl_c *class_ptr = (bx_floppy_ctrl_c *) this_ptr; - return( class_ptr->read(address, io_len) ); + return class_ptr->read(address, io_len); } /* reads from the floppy io ports */ @@ -496,7 +498,7 @@ Bit32u bx_floppy_ctrl_c::read(Bit32u address, unsigned io_len) case 0x3F3: // Tape Drive Register drive = BX_FD_THIS s.DOR & 0x03; if (BX_FD_THIS s.media_present[drive]) { - switch ( BX_FD_THIS s.media[drive].type) { + switch (BX_FD_THIS s.media[drive].type) { case BX_FLOPPY_160K: case BX_FLOPPY_180K: case BX_FLOPPY_320K: @@ -861,11 +863,11 @@ void bx_floppy_ctrl_c::floppy_command(void) return; case 0x13: // Configure - BX_DEBUG(("configure (eis = 0x%02x)", BX_FD_THIS s.command[2] & 0x40 )); - BX_DEBUG(("configure (efifo = 0x%02x)", BX_FD_THIS s.command[2] & 0x20 )); - BX_DEBUG(("configure (no poll = 0x%02x)", BX_FD_THIS s.command[2] & 0x10 )); - BX_DEBUG(("configure (fifothr = 0x%02x)", BX_FD_THIS s.command[2] & 0x0f )); - BX_DEBUG(("configure (pretrk = 0x%02x)", BX_FD_THIS s.command[3] )); + BX_DEBUG(("configure (eis = 0x%02x)", BX_FD_THIS s.command[2] & 0x40)); + BX_DEBUG(("configure (efifo = 0x%02x)", BX_FD_THIS s.command[2] & 0x20)); + BX_DEBUG(("configure (no poll = 0x%02x)", BX_FD_THIS s.command[2] & 0x10)); + BX_DEBUG(("configure (fifothr = 0x%02x)", BX_FD_THIS s.command[2] & 0x0f)); + BX_DEBUG(("configure (pretrk = 0x%02x)", BX_FD_THIS s.command[3])); BX_FD_THIS s.config = BX_FD_THIS s.command[2]; BX_FD_THIS s.pretrk = BX_FD_THIS s.command[3]; enter_idle_phase(); @@ -962,7 +964,7 @@ void bx_floppy_ctrl_c::floppy_command(void) case 0x45: // write normal data, MT=0 case 0xc5: // write normal data, MT=1 BX_FD_THIS s.multi_track = (BX_FD_THIS s.command[0] >> 7); - if ( (BX_FD_THIS s.DOR & 0x08) == 0 ) + if ((BX_FD_THIS s.DOR & 0x08) == 0) BX_PANIC(("read/write command with DMA and int disabled")); drive = BX_FD_THIS s.command[1] & 0x03; BX_FD_THIS s.DOR &= 0xfc; @@ -1000,7 +1002,7 @@ void bx_floppy_ctrl_c::floppy_command(void) return; } - if ( BX_FD_THIS s.media_present[drive] == 0 ) { + if (BX_FD_THIS s.media_present[drive] == 0) { BX_INFO(("attempt to read/write sector %u with media not present", (unsigned) sector)); return; // Hang controller } @@ -1009,7 +1011,7 @@ void bx_floppy_ctrl_c::floppy_command(void) BX_PANIC(("read/write command: sector size %d not supported", 128<= BX_FD_THIS s.media[drive].tracks ) { + if (cylinder >= BX_FD_THIS s.media[drive].tracks) { BX_PANIC(("io: norm r/w parms out of range: sec#%02xh cyl#%02xh eot#%02xh head#%02xh", (unsigned) sector, (unsigned) cylinder, (unsigned) eot, (unsigned) head)); @@ -1511,7 +1513,7 @@ unsigned bx_floppy_ctrl_c::set_media_status(unsigned drive, unsigned status) if (status == 0) { // eject floppy if (BX_FD_THIS s.media[drive].fd >= 0) { - close( BX_FD_THIS s.media[drive].fd ); + close(BX_FD_THIS s.media[drive].fd); BX_FD_THIS s.media[drive].fd = -1; } BX_FD_THIS s.media_present[drive] = 0; @@ -1621,7 +1623,7 @@ bx_bool bx_floppy_ctrl_c::evaluate_media(Bit8u devtype, Bit8u type, char *path, if (strcmp(SIM->get_param_string(BXPN_FLOPPYA_PATH)->getptr(), SuperDrive)) #endif #ifdef WIN32 - if ( (isalpha(path[0])) && (path[1] == ':') && (strlen(path) == 2) ) { + if ((isalpha(path[0])) && (path[1] == ':') && (strlen(path) == 2)) { raw_floppy = 1; wsprintf(sTemp, "\\\\.\\%s", path); hFile = CreateFile(sTemp, GENERIC_READ, FILE_SHARE_WRITE, NULL, @@ -1680,7 +1682,7 @@ bx_bool bx_floppy_ctrl_c::evaluate_media(Bit8u devtype, Bit8u type, char *path, // Don't open the handle if using Win95 style direct access if (!media->raw_floppy_win95) { if (media->fd < 0) { - BX_INFO(( "tried to open '%s' read/write: %s",path,strerror(errno) )); + BX_INFO(("tried to open '%s' read/write: %s",path,strerror(errno))); // try opening the file read-only media->write_protected = 1; #ifdef macintosh @@ -1698,7 +1700,7 @@ bx_bool bx_floppy_ctrl_c::evaluate_media(Bit8u devtype, Bit8u type, char *path, #endif if (media->fd < 0) { // failed to open read-only too - BX_INFO(( "tried to open '%s' read only: %s",path,strerror(errno) )); + BX_INFO(("tried to open '%s' read only: %s",path,strerror(errno))); media->type = type; return(0); } @@ -1727,7 +1729,7 @@ bx_bool bx_floppy_ctrl_c::evaluate_media(Bit8u devtype, Bit8u type, char *path, return(0); } - if ( S_ISREG(stat_buf.st_mode) ) { + if (S_ISREG(stat_buf.st_mode)) { // regular file switch (type) { // use CMOS reserved types @@ -1786,7 +1788,7 @@ bx_bool bx_floppy_ctrl_c::evaluate_media(Bit8u devtype, Bit8u type, char *path, return (media->sectors > 0); // success } - else if ( S_ISCHR(stat_buf.st_mode) + else if (S_ISCHR(stat_buf.st_mode) #if BX_WITH_MACOS == 0 #ifdef S_ISBLK || S_ISBLK(stat_buf.st_mode) diff --git a/bochs/iodev/guest2host.cc b/bochs/iodev/guest2host.cc index 3bf44f725..55a5b2799 100644 --- a/bochs/iodev/guest2host.cc +++ b/bochs/iodev/guest2host.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: guest2host.cc,v 1.15 2006-03-07 18:16:40 sshwarts Exp $ +// $Id: guest2host.cc,v 1.16 2008-02-15 22:05:42 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -23,8 +23,7 @@ // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - +///////////////////////////////////////////////////////////////////////// #include "iodev.h" #define LOG_THIS bx_g2h. @@ -50,7 +49,7 @@ bx_g2h_c::~bx_g2h_c() void bx_g2h_c::init(void) { - BX_DEBUG(("Init $Id: guest2host.cc,v 1.15 2006-03-07 18:16:40 sshwarts Exp $")); + BX_DEBUG(("Init $Id: guest2host.cc,v 1.16 2008-02-15 22:05:42 sshwarts Exp $")); // Reserve a dword port for this interface for (Bit32u addr=BX_G2H_PORT; addr<=(BX_G2H_PORT+3); addr++) { bx_devices.register_io_read_handler(&bx_g2h, @@ -83,8 +82,8 @@ unsigned bx_g2h_c::acquire_channel(bx_g2h_callback_t f) unsigned bx_g2h_c::deacquire_channel(unsigned channel) { - if ( (channel >= BX_MAX_G2H_CHANNELS) || - (bx_g2h.s.callback[channel].used==0) ) + if ((channel >= BX_MAX_G2H_CHANNELS) || + (bx_g2h.s.callback[channel].used==0)) { BX_PANIC(("g2h: attempt to deacquire channel %u: not acquired", channel)); } @@ -119,7 +118,7 @@ void bx_g2h_c::outp_handler(void *this_ptr, Bit32u addr, Bit32u val32, unsigned if (io_len != 4) BX_PANIC(("g2h: IO write not dword.")); - if ( (bx_g2h.s.packet_count==0) && (val32!=BX_G2H_MAGIC) ) { + if ((bx_g2h.s.packet_count==0) && (val32!=BX_G2H_MAGIC)) { BX_INFO(("g2h: IO W: Not magic header.")); return; } diff --git a/bochs/iodev/harddrv.cc b/bochs/iodev/harddrv.cc index ce025cac0..2e4cad625 100644 --- a/bochs/iodev/harddrv.cc +++ b/bochs/iodev/harddrv.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: harddrv.cc,v 1.207 2008-02-07 20:43:13 sshwarts Exp $ +// $Id: harddrv.cc,v 1.208 2008-02-15 22:05:42 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2002 MandrakeSoft S.A. @@ -23,13 +23,12 @@ // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +///////////////////////////////////////////////////////////////////////// // Useful docs: // AT Attachment with Packet Interface // working draft by T13 at www.t13.org - - // Define BX_PLUGGABLE in files that can be compiled into plugins. For // platforms that require a special tag on exported symbols, BX_PLUGGABLE // is used to know when we are exporting symbols and when we are importing. @@ -174,7 +173,7 @@ void bx_hard_drive_c::init(void) char ata_name[20]; bx_list_c *base; - BX_DEBUG(("Init $Id: harddrv.cc,v 1.207 2008-02-07 20:43:13 sshwarts Exp $")); + BX_DEBUG(("Init $Id: harddrv.cc,v 1.208 2008-02-15 22:05:42 sshwarts Exp $")); for (channel=0; channelget_param_num("irq", base)->get(); // Coherency check - if ( (BX_HD_THIS channels[channel].ioaddr1 == 0) || - (BX_HD_THIS channels[channel].ioaddr2 == 0) || - (BX_HD_THIS channels[channel].irq == 0) ) { + if ((BX_HD_THIS channels[channel].ioaddr1 == 0) || + (BX_HD_THIS channels[channel].ioaddr2 == 0) || + (BX_HD_THIS channels[channel].irq == 0)) + { BX_PANIC(("incoherency for ata channel %d: io1=0x%x, io2=%x, irq=%d", channel, BX_HD_THIS channels[channel].ioaddr1, @@ -288,7 +288,7 @@ void bx_hard_drive_c::init(void) } if (SIM->get_param_enum("type", base)->get() == BX_ATA_DEVICE_DISK) { - BX_DEBUG(( "Hard-Disk on target %d/%d",channel,device)); + BX_DEBUG(("Hard-Disk on target %d/%d",channel,device)); BX_HD_THIS channels[channel].drives[device].device_type = IDE_DISK; sprintf(sbtext, "HD:%d-%s", channel, device?"S":"M"); BX_HD_THIS channels[channel].drives[device].statusbar_id = @@ -450,7 +450,7 @@ void bx_hard_drive_c::init(void) BX_PANIC(("ata%d-%d image doesn't support geometry detection", channel, device)); } } else if (SIM->get_param_enum("type", base)->get() == BX_ATA_DEVICE_CDROM) { - BX_DEBUG(( "CDROM on target %d/%d",channel,device)); + BX_DEBUG(("CDROM on target %d/%d",channel,device)); BX_HD_THIS channels[channel].drives[device].device_type = IDE_CDROM; BX_HD_THIS channels[channel].drives[device].cdrom.locked = 0; BX_HD_THIS channels[channel].drives[device].sense.sense_key = SENSE_NONE; @@ -491,13 +491,13 @@ void bx_hard_drive_c::init(void) if (SIM->get_param_enum("status", base)->get() == BX_INSERTED) { if (BX_HD_THIS channels[channel].drives[device].cdrom.cd->insert_cdrom()) { - BX_INFO(( "Media present in CD-ROM drive")); + BX_INFO(("Media present in CD-ROM drive")); BX_HD_THIS channels[channel].drives[device].cdrom.ready = 1; Bit32u capacity = BX_HD_THIS channels[channel].drives[device].cdrom.cd->capacity(); BX_HD_THIS channels[channel].drives[device].cdrom.capacity = capacity; BX_INFO(("Capacity is %d sectors (%.2f MB)", capacity, (float)capacity / 512.0)); } else { - BX_INFO(( "Could not locate CD-ROM, continuing with media not present")); + BX_INFO(("Could not locate CD-ROM, continuing with media not present")); BX_HD_THIS channels[channel].drives[device].cdrom.ready = 0; SIM->get_param_enum("status", base)->set(BX_EJECTED); } @@ -505,7 +505,7 @@ void bx_hard_drive_c::init(void) else #endif { - BX_INFO(( "Media not present in CD-ROM drive" )); + BX_INFO(("Media not present in CD-ROM drive")); BX_HD_THIS channels[channel].drives[device].cdrom.ready = 0; } } @@ -640,8 +640,7 @@ void bx_hard_drive_c::init(void) BX_INFO(("Using boot sequence %s, %s, %s", SIM->get_param_enum(BXPN_BOOTDRIVE1)->get_selected(), SIM->get_param_enum(BXPN_BOOTDRIVE2)->get_selected(), - SIM->get_param_enum(BXPN_BOOTDRIVE3)->get_selected() - )); + SIM->get_param_enum(BXPN_BOOTDRIVE3)->get_selected())); DEV_cmos_set_reg(0x3d, SIM->get_param_enum(BXPN_BOOTDRIVE1)->get() | (SIM->get_param_enum(BXPN_BOOTDRIVE2)->get() << 4)); @@ -735,7 +734,7 @@ void bx_hard_drive_c::iolight_timer() for (unsigned device=0; device<2; device++) { if (BX_HD_THIS channels[channel].drives[device].iolight_counter > 0) { if (--BX_HD_THIS channels[channel].drives[device].iolight_counter) - bx_pc_system.activate_timer( BX_HD_THIS iolight_timer_index, 100000, 0 ); + bx_pc_system.activate_timer(BX_HD_THIS iolight_timer_index, 100000, 0); else bx_gui->statusbar_setitem(BX_HD_THIS channels[channel].drives[device].statusbar_id, 0); } @@ -941,7 +940,7 @@ Bit32u bx_hard_drive_c::read(Bit32u address, unsigned io_len) if (!BX_SELECTED_DRIVE(channel).iolight_counter) bx_gui->statusbar_setitem(BX_SELECTED_DRIVE(channel).statusbar_id, 1); BX_SELECTED_DRIVE(channel).iolight_counter = 5; - bx_pc_system.activate_timer( BX_HD_THIS iolight_timer_index, 100000, 0 ); + bx_pc_system.activate_timer(BX_HD_THIS iolight_timer_index, 100000, 0); if (!BX_SELECTED_DRIVE(channel).cdrom.cd->read_block(BX_SELECTED_CONTROLLER(channel).buffer, BX_SELECTED_DRIVE(channel).cdrom.next_lba, BX_SELECTED_CONTROLLER(channel).buffer_size)) @@ -1289,7 +1288,7 @@ void bx_hard_drive_c::write(Bit32u address, Bit32u value, unsigned io_len) quantumsMax = (BX_SELECTED_CONTROLLER(channel).buffer_size - BX_SELECTED_CONTROLLER(channel).buffer_index) / io_len; - if ( quantumsMax == 0) + if (quantumsMax == 0) BX_PANIC(("IO write(0x%04x): not enough space for write", address)); DEV_bulk_io_quantum_transferred() = DEV_bulk_io_quantum_requested(); @@ -2039,7 +2038,7 @@ void bx_hard_drive_c::write(Bit32u address, Bit32u value, unsigned io_len) // b4: DRV // b3..0 HD3..HD0 { - if ( (value & 0xa0) != 0xa0 ) // 1x1xxxxx + if ((value & 0xa0) != 0xa0) // 1x1xxxxx BX_DEBUG(("IO write 0x%04x (%02x): not 1x1xxxxxb", address, (unsigned) value)); Bit32u drvsel = BX_HD_THIS channels[channel].drive_select = (value >> 4) & 0x01; WRITE_HEAD_NO(channel,value & 0xf); @@ -2064,7 +2063,7 @@ void bx_hard_drive_c::write(Bit32u address, Bit32u value, unsigned io_len) BX_ERROR(("ata%d: command 0x%02x sent, controller BSY bit set", channel, value)); break; } - if ( (value & 0xf0) == 0x10 ) + if ((value & 0xf0) == 0x10) value = 0x10; BX_SELECTED_CONTROLLER(channel).status.err = 0; switch (value) { @@ -3310,7 +3309,7 @@ unsigned bx_hard_drive_c::get_cd_media_status(Bit32u handle) Bit8u channel = handle / 2; Bit8u device = handle % 2; - return( BX_HD_THIS channels[channel].drives[device].cdrom.ready ); + return BX_HD_THIS channels[channel].drives[device].cdrom.ready; } unsigned bx_hard_drive_c::set_cd_media_status(Bit32u handle, unsigned status) @@ -3318,7 +3317,7 @@ unsigned bx_hard_drive_c::set_cd_media_status(Bit32u handle, unsigned status) char ata_name[20]; BX_DEBUG (("set_cd_media_status handle=%d status=%d", handle, status)); - if ( handle >= BX_MAX_ATA_CHANNEL*2 ) return 0; + if (handle >= BX_MAX_ATA_CHANNEL*2) return 0; Bit8u channel = handle / 2; Bit8u device = handle % 2; @@ -3346,7 +3345,7 @@ unsigned bx_hard_drive_c::set_cd_media_status(Bit32u handle, unsigned status) // insert cdrom #ifdef LOWLEVEL_CDROM if (BX_HD_THIS channels[channel].drives[device].cdrom.cd->insert_cdrom(SIM->get_param_string("path", base)->getptr())) { - BX_INFO(( "Media present in CD-ROM drive")); + BX_INFO(("Media present in CD-ROM drive")); BX_HD_THIS channels[channel].drives[device].cdrom.ready = 1; Bit32u capacity = BX_HD_THIS channels[channel].drives[device].cdrom.cd->capacity(); BX_HD_THIS channels[channel].drives[device].cdrom.capacity = capacity; @@ -3360,7 +3359,7 @@ unsigned bx_hard_drive_c::set_cd_media_status(Bit32u handle, unsigned status) else #endif { - BX_INFO(( "Could not locate CD-ROM, continuing with media not present")); + BX_INFO(("Could not locate CD-ROM, continuing with media not present")); BX_HD_THIS channels[channel].drives[device].cdrom.ready = 0; SIM->get_param_enum("status", base)->set(BX_EJECTED); } @@ -3398,7 +3397,7 @@ bx_bool bx_hard_drive_c::bmdma_read_sector(Bit8u channel, Bit8u *buffer, Bit32u if (!BX_SELECTED_DRIVE(channel).iolight_counter) bx_gui->statusbar_setitem(BX_SELECTED_DRIVE(channel).statusbar_id, 1); BX_SELECTED_DRIVE(channel).iolight_counter = 5; - bx_pc_system.activate_timer( BX_HD_THIS iolight_timer_index, 100000, 0 ); + bx_pc_system.activate_timer(BX_HD_THIS iolight_timer_index, 100000, 0); if (!BX_SELECTED_DRIVE(channel).cdrom.cd->read_block(buffer, BX_SELECTED_DRIVE(channel).cdrom.next_lba, BX_SELECTED_CONTROLLER(channel).buffer_size)) { diff --git a/bochs/iodev/hdimage.cc b/bochs/iodev/hdimage.cc index de4761057..c9c6b7f6d 100644 --- a/bochs/iodev/hdimage.cc +++ b/bochs/iodev/hdimage.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: hdimage.cc,v 1.15 2008-02-05 22:57:42 sshwarts Exp $ +// $Id: hdimage.cc,v 1.16 2008-02-15 22:05:42 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2002 MandrakeSoft S.A. @@ -205,7 +205,7 @@ void concat_image_t::close() Bit64s concat_image_t::lseek(Bit64s offset, int whence) { if ((offset % 512) != 0) - BX_PANIC( ("lseek HD with offset not multiple of 512")); + BX_PANIC(("lseek HD with offset not multiple of 512")); BX_DEBUG(("concat_image_t.lseek(%d)", whence)); // is this offset in this disk image? if (offset < thismin) { @@ -252,7 +252,7 @@ ssize_t concat_image_t::read(void* buf, size_t count) // This can be supported pretty easily, but needs additional checks for // end of a partial image. if (!seek_was_last_op) - BX_PANIC( ("no seek before read")); + BX_PANIC(("no seek before read")); return ::read(fd, (char*) buf, count); } @@ -263,7 +263,7 @@ ssize_t concat_image_t::write(const void* buf, size_t count) // This can be supported pretty easily, but needs additional checks for // end of a partial image. if (!seek_was_last_op) - BX_PANIC( ("no seek before write")); + BX_PANIC(("no seek before write")); return ::write(fd, (char*) buf, count); } @@ -480,9 +480,9 @@ Bit64s sparse_image_t::lseek(Bit64s offset, int whence) //showpagetable(pagetable, header.numpages); if ((offset % 512) != 0) - BX_PANIC( ("lseek HD with offset not multiple of 512")); + BX_PANIC(("lseek HD with offset not multiple of 512")); if (whence != SEEK_SET) - BX_PANIC( ("lseek HD with whence not SEEK_SET")); + BX_PANIC(("lseek HD with whence not SEEK_SET")); BX_DEBUG(("sparse_image_t.lseek(%d)", whence)); @@ -1098,11 +1098,11 @@ Bit64u redolog_t::get_size() Bit64s redolog_t::lseek(Bit64s offset, int whence) { if ((offset % 512) != 0) { - BX_PANIC( ("redolog : lseek HD with offset not multiple of 512")); + BX_PANIC(("redolog : lseek HD with offset not multiple of 512")); return -1; } if (whence != SEEK_SET) { - BX_PANIC( ("redolog : lseek HD with whence not SEEK_SET")); + BX_PANIC(("redolog : lseek HD with whence not SEEK_SET")); return -1; } if (offset > (Bit64s)dtoh64(header.specific.disk)) @@ -1124,7 +1124,7 @@ ssize_t redolog_t::read(void* buf, size_t count) Bit64s bloc_offset, bitmap_offset; if (count != 512) - BX_PANIC( ("redolog : read HD with count not 512")); + BX_PANIC(("redolog : read HD with count not 512")); BX_DEBUG(("redolog : reading index %d, mapping to %d", extent_index, dtoh32(catalog[extent_index]))); @@ -1151,7 +1151,7 @@ ssize_t redolog_t::read(void* buf, size_t count) return 0; } - if ( ((bitmap[extent_offset/8] >> (extent_offset%8)) & 0x01) == 0x00 ) + if (((bitmap[extent_offset/8] >> (extent_offset%8)) & 0x01) == 0x00) { BX_DEBUG(("read not in redolog")); @@ -1172,7 +1172,7 @@ ssize_t redolog_t::write(const void* buf, size_t count) bx_bool update_catalog = 0; if (count != 512) - BX_PANIC( ("redolog : write HD with count not 512")); + BX_PANIC(("redolog : write HD with count not 512")); BX_DEBUG(("redolog : writing index %d, mapping to %d", extent_index, dtoh32(catalog[extent_index]))); if (dtoh32(catalog[extent_index]) == REDOLOG_PAGE_NOT_ALLOCATED) @@ -1233,7 +1233,7 @@ ssize_t redolog_t::write(const void* buf, size_t count) } // If bloc does not belong to extent yet - if ( ((bitmap[extent_offset/8] >> (extent_offset%8)) & 0x01) == 0x00 ) + if (((bitmap[extent_offset/8] >> (extent_offset%8)) & 0x01) == 0x00) { bitmap[extent_offset/8] |= 1 << (extent_offset%8); ::lseek(fd, (off_t)bitmap_offset, SEEK_SET); @@ -1326,15 +1326,15 @@ int undoable_image_t::open(const char* pathname) hd_size = ro_disk->hd_size; // if redolog name was set - if ( redolog_name != NULL) { - if ( strcmp(redolog_name, "") != 0 ) { + if (redolog_name != NULL) { + if (strcmp(redolog_name, "") != 0) { logname = (char*)malloc(strlen(redolog_name) + 1); strcpy(logname, redolog_name); } } // Otherwise we make up the redolog filename from the pathname - if ( logname == NULL) { + if (logname == NULL) { logname = (char*)malloc(strlen(pathname) + UNDOABLE_REDOLOG_EXTENSION_LENGTH + 1); sprintf(logname, "%s%s", pathname, UNDOABLE_REDOLOG_EXTENSION); } @@ -1420,8 +1420,8 @@ int volatile_image_t::open(const char* pathname) hd_size = ro_disk->hd_size; // if redolog name was set - if ( redolog_name != NULL) { - if ( strcmp(redolog_name, "") != 0 ) { + if (redolog_name != NULL) { + if (strcmp(redolog_name, "") != 0) { logname = redolog_name; } } @@ -1586,15 +1586,15 @@ int z_undoable_image_t::open(const char* pathname) return -1; // If redolog name was set - if ( redolog_name != NULL) { - if ( strcmp(redolog_name, "") != 0) { + if (redolog_name != NULL) { + if (strcmp(redolog_name, "") != 0) { logname = (char*)malloc(strlen(redolog_name) + 1); strcpy (logname, redolog_name); } } // Otherwise we make up the redolog filename from the pathname - if ( logname == NULL) { + if (logname == NULL) { logname = (char*)malloc(strlen(pathname) + UNDOABLE_REDOLOG_EXTENSION_LENGTH + 1); sprintf (logname, "%s%s", pathname, UNDOABLE_REDOLOG_EXTENSION); } @@ -1677,7 +1677,7 @@ int z_volatile_image_t::open(const char* pathname) // if redolog name was set if (redolog_name != NULL) { - if (strcmp(redolog_name, "") !=0 ) { + if (strcmp(redolog_name, "") != 0) { logname = redolog_name; } } diff --git a/bochs/iodev/iodebug.cc b/bochs/iodev/iodebug.cc index 676ff6d14..a24b5be4b 100644 --- a/bochs/iodev/iodebug.cc +++ b/bochs/iodev/iodebug.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: iodebug.cc,v 1.24 2008-02-15 19:03:54 sshwarts Exp $ +// $Id: iodebug.cc,v 1.25 2008-02-15 22:05:42 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// #include "bochs.h" @@ -292,8 +292,8 @@ void bx_iodebug_c::add_range(Bit32u addr_start, Bit32u addr_end) { for(unsigned i=0;ipanic("%s called in %s stub. you must not have loaded the %s plugin", #dev, #method, #dev ) + pluginlog->panic("%s called in %s stub. you must not have loaded the %s plugin", #dev, #method, #dev) ////////////////////////////////////////////////////////////////////// class BOCHSAPI bx_keyb_stub_c : public bx_devmodel_c { @@ -405,13 +405,13 @@ public: bx_bool register_io_write_handler(void *this_ptr, bx_write_handler_t f, Bit32u addr, const char *name, Bit8u mask); bx_bool unregister_io_write_handler(void *this_ptr, bx_write_handler_t f, - Bit32u addr, Bit8u mask ); + Bit32u addr, Bit8u mask); bx_bool register_io_read_handler_range(void *this_ptr, bx_read_handler_t f, Bit32u begin_addr, Bit32u end_addr, const char *name, Bit8u mask); bx_bool register_io_write_handler_range(void *this_ptr, bx_write_handler_t f, Bit32u begin_addr, Bit32u end_addr, - const char *name, Bit8u mask ); + const char *name, Bit8u mask); bx_bool unregister_io_read_handler_range(void *this_ptr, bx_read_handler_t f, Bit32u begin, Bit32u end, Bit8u mask); bx_bool unregister_io_write_handler_range(void *this_ptr, bx_write_handler_t f, @@ -598,8 +598,8 @@ private: #endif /* NO_DEVICE_INCLUDES */ -#if ( BX_PROVIDE_DEVICE_MODELS==1 ) -BOCHSAPI extern bx_devices_c bx_devices; +#if BX_PROVIDE_DEVICE_MODELS +BOCHSAPI extern bx_devices_c bx_devices; #endif #endif /* IODEV_H */ diff --git a/bochs/iodev/keyboard.cc b/bochs/iodev/keyboard.cc index f46df5a1b..aeba54a16 100644 --- a/bochs/iodev/keyboard.cc +++ b/bochs/iodev/keyboard.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: keyboard.cc,v 1.132 2008-01-26 22:24:02 sshwarts Exp $ +// $Id: keyboard.cc,v 1.133 2008-02-15 22:05:42 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2002 MandrakeSoft S.A. @@ -23,7 +23,7 @@ // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - +///////////////////////////////////////////////////////////////////////// // Now features proper implementation of keyboard opcodes 0xF4 to 0xF6 // Silently ignores PS/2 keyboard extensions (0xF7 to 0xFD) @@ -126,7 +126,7 @@ void bx_keyb_c::resetinternals(bx_bool powerup) void bx_keyb_c::init(void) { - BX_DEBUG(("Init $Id: keyboard.cc,v 1.132 2008-01-26 22:24:02 sshwarts Exp $")); + BX_DEBUG(("Init $Id: keyboard.cc,v 1.133 2008-02-15 22:05:42 sshwarts Exp $")); Bit32u i; DEV_register_irq(1, "8042 Keyboard controller"); @@ -140,7 +140,7 @@ void bx_keyb_c::init(void) 0x0060, "8042 Keyboard controller", 1); DEV_register_iowrite_handler(this, write_handler, 0x0064, "8042 Keyboard controller", 1); - BX_KEY_THIS timer_handle = bx_pc_system.register_timer( this, timer_handler, + BX_KEY_THIS timer_handle = bx_pc_system.register_timer(this, timer_handler, SIM->get_param_num(BXPN_KBD_SERIAL_DELAY)->get(), 1, 1, "8042 Keyboard controller"); @@ -544,7 +544,7 @@ void bx_keyb_c::write(Bit32u address, Bit32u value, unsigned io_len) else if (BX_KEY_THIS s.kbd_controller.allow_irq1 && BX_KEY_THIS s.kbd_controller.outb) BX_KEY_THIS s.kbd_controller.irq1_requested = 1; - BX_DEBUG(( " allow_irq12 set to %u", + BX_DEBUG((" allow_irq12 set to %u", (unsigned) BX_KEY_THIS s.kbd_controller.allow_irq12)); if (!scan_convert) BX_INFO(("keyboard: scan convert turned off")); @@ -559,7 +559,7 @@ void bx_keyb_c::write(Bit32u address, Bit32u value, unsigned io_len) BX_SET_ENABLE_A20((value & 0x02) != 0); if (!(value & 0x01)) { BX_INFO(("write output port : processor reset requested!")); - bx_pc_system.Reset( BX_RESET_SOFTWARE); + bx_pc_system.Reset(BX_RESET_SOFTWARE); } break; case 0xd4: // Write to mouse @@ -1086,14 +1086,14 @@ void bx_keyb_c::kbd_ctrl_to_kbd(Bit8u value) if (BX_KEY_THIS s.kbd_controller.expecting_scancodes_set) { BX_KEY_THIS s.kbd_controller.expecting_scancodes_set = 0; - if( value != 0 ) { - if( value<4 ) { + if(value != 0) { + if(value < 4) { BX_KEY_THIS s.kbd_controller.current_scancodes_set = (value-1); BX_INFO(("Switched to scancode set %d", (unsigned) BX_KEY_THIS s.kbd_controller.current_scancodes_set + 1)); kbd_enQ(0xFA); } else { - BX_ERROR(("Received scancodes set out of range: %d", value )); + BX_ERROR(("Received scancodes set out of range: %d", value)); kbd_enQ(0xFF); // send ERROR } } else { @@ -1222,11 +1222,11 @@ unsigned bx_keyb_c::periodic(Bit32u usec_delta) { /* static int multiple=0; */ static unsigned count_before_paste=0; - Bit8u retval; + Bit8u retval; - UNUSED( usec_delta ); + UNUSED(usec_delta); - if (BX_KEY_THIS s.kbd_controller.kbd_clock_enabled ) { + if (BX_KEY_THIS s.kbd_controller.kbd_clock_enabled) { if(++count_before_paste>=BX_KEY_THIS pastedelay) { // after the paste delay, consider adding moving more chars // from the paste buffer to the keyboard buffer. @@ -1555,7 +1555,7 @@ void bx_keyb_c::create_mouse_packet(bool force_enq) b1 = (button_state & 0x0f) | 0x08; // bit3 always set - if ( (delta_x>=0) && (delta_x<=255) ) { + if ((delta_x>=0) && (delta_x<=255)) { b2 = (Bit8u) delta_x; BX_KEY_THIS s.mouse.delayed_dx-=delta_x; } @@ -1574,7 +1574,7 @@ void bx_keyb_c::create_mouse_packet(bool force_enq) BX_KEY_THIS s.mouse.delayed_dx+=256; } - if ( (delta_y>=0) && (delta_y<=255) ) { + if ((delta_y>=0) && (delta_y<=255)) { b3 = (Bit8u) delta_y; BX_KEY_THIS s.mouse.delayed_dy-=delta_y; } @@ -1654,7 +1654,7 @@ void bx_keyb_c::mouse_motion(int delta_x, int delta_y, int delta_z, unsigned but #endif // don't generate interrupts if we are in remote mode. - if ( BX_KEY_THIS s.mouse.mode == MOUSE_MODE_REMOTE) + if (BX_KEY_THIS s.mouse.mode == MOUSE_MODE_REMOTE) // is there any point in doing any work if we don't act on the result // so go home. return; @@ -1677,7 +1677,7 @@ void bx_keyb_c::mouse_motion(int delta_x, int delta_y, int delta_z, unsigned but BX_DEBUG(("[mouse] Dx=%d Dy=%d Dz=%d", delta_x, delta_y, delta_z)); #endif /* ifdef VERBOSE_KBD_DEBUG */ - if( (delta_x==0) && (delta_y==0) && (delta_z==0) && (BX_KEY_THIS s.mouse.button_status == (button_state & 0x7) ) ) { + if ((delta_x==0) && (delta_y==0) && (delta_z==0) && (BX_KEY_THIS s.mouse.button_status == (button_state & 0x7))) { BX_DEBUG(("Ignoring useless mouse_motion call:")); BX_DEBUG(("This should be fixed in the gui code.")); return; diff --git a/bochs/iodev/keyboard.h b/bochs/iodev/keyboard.h index b4ea50a95..e5bc12f0c 100644 --- a/bochs/iodev/keyboard.h +++ b/bochs/iodev/keyboard.h @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: keyboard.h,v 1.41 2008-01-26 22:24:02 sshwarts Exp $ +// $Id: keyboard.h,v 1.42 2008-02-15 22:05:43 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -24,11 +24,9 @@ // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - #ifndef _PCKEY_H #define _PCKEY_H - #define BX_KBD_ELEMENTS 16 #define BX_MOUSE_BUFF_SIZE 48 @@ -69,14 +67,14 @@ private: BX_KEY_SMF Bit8u get_kbd_enable(void); BX_KEY_SMF void service_paste_buf (); BX_KEY_SMF void create_mouse_packet(bool force_enq); - BX_KEY_SMF unsigned periodic( Bit32u usec_delta ); + BX_KEY_SMF unsigned periodic(Bit32u usec_delta); static Bit32u read_handler(void *this_ptr, Bit32u address, unsigned io_len); static void write_handler(void *this_ptr, Bit32u address, Bit32u value, unsigned io_len); #if !BX_USE_KEY_SMF - void write(Bit32u address, Bit32u value, unsigned io_len); - Bit32u read(Bit32u address, unsigned io_len); + void write(Bit32u address, Bit32u value, unsigned io_len); + Bit32u read(Bit32u address, unsigned io_len); #endif struct { diff --git a/bochs/iodev/ne2k.cc b/bochs/iodev/ne2k.cc index 95aee5d55..46de1bbda 100644 --- a/bochs/iodev/ne2k.cc +++ b/bochs/iodev/ne2k.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: ne2k.cc,v 1.96 2008-01-26 22:24:02 sshwarts Exp $ +// $Id: ne2k.cc,v 1.97 2008-02-15 22:05:43 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2002 MandrakeSoft S.A. @@ -23,6 +23,7 @@ // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +///////////////////////////////////////////////////////////////////////// // Peter Grehan (grehan@iprg.nokia.com) coded the initial version of this // NE2000/ether stuff. @@ -1129,7 +1130,7 @@ Bit32u bx_ne2k_c::read_handler(void *this_ptr, Bit32u address, unsigned io_len) #if !BX_USE_NE2K_SMF bx_ne2k_c *class_ptr = (bx_ne2k_c *) this_ptr; - return( class_ptr->read(address, io_len) ); + return class_ptr->read(address, io_len); } Bit32u bx_ne2k_c::read(Bit32u address, unsigned io_len) @@ -1401,7 +1402,7 @@ void bx_ne2k_c::init(void) char devname[16]; bx_list_c *base; - BX_DEBUG(("Init $Id: ne2k.cc,v 1.96 2008-01-26 22:24:02 sshwarts Exp $")); + BX_DEBUG(("Init $Id: ne2k.cc,v 1.97 2008-02-15 22:05:43 sshwarts Exp $")); // Read in values from config interface base = (bx_list_c*) SIM->get_param(BXPN_NE2K); diff --git a/bochs/iodev/pcipnic.cc b/bochs/iodev/pcipnic.cc index 894b4bf56..8b8be8845 100644 --- a/bochs/iodev/pcipnic.cc +++ b/bochs/iodev/pcipnic.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: pcipnic.cc,v 1.26 2008-01-26 22:24:02 sshwarts Exp $ +// $Id: pcipnic.cc,v 1.27 2008-02-15 22:05:43 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2003 Fen Systems Ltd. @@ -18,6 +18,7 @@ // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +///////////////////////////////////////////////////////////////////////// // Define BX_PLUGGABLE in files that can be compiled into plugins. For // platforms that require a special tag on exported symbols, BX_PLUGGABLE @@ -211,19 +212,19 @@ Bit32u bx_pcipnic_c::read(Bit32u address, unsigned io_len) offset = address - BX_PNIC_THIS s.base_ioaddr; switch (offset) { - case PNIC_REG_STAT : + case PNIC_REG_STAT: val = BX_PNIC_THIS s.rStatus; break; - case PNIC_REG_LEN : + case PNIC_REG_LEN: val = BX_PNIC_THIS s.rLength; break; - case PNIC_REG_DATA : - if ( BX_PNIC_THIS s.rDataCursor >= BX_PNIC_THIS s.rLength ) + case PNIC_REG_DATA: + if (BX_PNIC_THIS s.rDataCursor >= BX_PNIC_THIS s.rLength) BX_PANIC(("PNIC read at %u, beyond end of data register array", BX_PNIC_THIS s.rDataCursor)); - val = BX_PNIC_THIS s.rData[BX_PNIC_THIS s.rDataCursor ++]; + val = BX_PNIC_THIS s.rData[BX_PNIC_THIS s.rDataCursor++]; break; default : @@ -260,24 +261,24 @@ void bx_pcipnic_c::write(Bit32u address, Bit32u value, unsigned io_len) offset = address - BX_PNIC_THIS s.base_ioaddr; switch (offset) { - case PNIC_REG_CMD : + case PNIC_REG_CMD: BX_PNIC_THIS s.rCmd = value; BX_PNIC_THIS exec_command(); break; - case PNIC_REG_LEN : - if ( value > PNIC_DATA_SIZE ) + case PNIC_REG_LEN: + if (value > PNIC_DATA_SIZE) BX_PANIC(("PNIC bad length %u written to length register, max is %u", value, PNIC_DATA_SIZE)); BX_PNIC_THIS s.rLength = value; BX_PNIC_THIS s.rDataCursor = 0; break; - case PNIC_REG_DATA : - if ( BX_PNIC_THIS s.rDataCursor >= BX_PNIC_THIS s.rLength ) + case PNIC_REG_DATA: + if (BX_PNIC_THIS s.rDataCursor >= BX_PNIC_THIS s.rLength) BX_PANIC(("PNIC write at %u, beyond end of data register array", BX_PNIC_THIS s.rDataCursor)); - BX_PNIC_THIS s.rData[BX_PNIC_THIS s.rDataCursor ++] = value; + BX_PNIC_THIS s.rData[BX_PNIC_THIS s.rDataCursor++] = value; break; default: @@ -427,37 +428,37 @@ void bx_pcipnic_c::exec_command(void) Bit16u status = PNIC_STATUS_UNKNOWN_CMD; Bit16u olength = 0; - if ( ilength != BX_PNIC_THIS s.rDataCursor ) + if (ilength != BX_PNIC_THIS s.rDataCursor) BX_PANIC(("PNIC command issued with incomplete data (should be %u, is %u)", - ilength, BX_PNIC_THIS s.rDataCursor )); + ilength, BX_PNIC_THIS s.rDataCursor)); - switch ( command ) { - case PNIC_CMD_NOOP : + switch (command) { + case PNIC_CMD_NOOP: status = PNIC_STATUS_OK; break; - case PNIC_CMD_API_VER : + case PNIC_CMD_API_VER: Bit16u api_version; api_version = PNIC_API_VERSION; olength = sizeof(api_version); - memcpy ( data, &api_version, sizeof(api_version) ); + memcpy (data, &api_version, sizeof(api_version)); status = PNIC_STATUS_OK; break; - case PNIC_CMD_READ_MAC : - olength = sizeof ( BX_PNIC_THIS s.macaddr ); - memcpy ( data, BX_PNIC_THIS s.macaddr, olength ); + case PNIC_CMD_READ_MAC: + olength = sizeof (BX_PNIC_THIS s.macaddr); + memcpy (data, BX_PNIC_THIS s.macaddr, olength); status = PNIC_STATUS_OK; break; - case PNIC_CMD_RESET : + case PNIC_CMD_RESET: /* Flush the receive queue */ BX_PNIC_THIS s.recvQueueLength = 0; status = PNIC_STATUS_OK; break; - case PNIC_CMD_XMIT : + case PNIC_CMD_XMIT: BX_PNIC_THIS ethdev->sendpkt(data, ilength); if (BX_PNIC_THIS s.irqEnabled) { set_irq_level(1); @@ -465,35 +466,35 @@ void bx_pcipnic_c::exec_command(void) status = PNIC_STATUS_OK; break; - case PNIC_CMD_RECV : - if ( BX_PNIC_THIS s.recvQueueLength > 0 ) { - int idx = ( BX_PNIC_THIS s.recvIndex - BX_PNIC_THIS s.recvQueueLength - + PNIC_RECV_RINGS ) % PNIC_RECV_RINGS; + case PNIC_CMD_RECV: + if (BX_PNIC_THIS s.recvQueueLength > 0) { + int idx = (BX_PNIC_THIS s.recvIndex - BX_PNIC_THIS s.recvQueueLength + + PNIC_RECV_RINGS) % PNIC_RECV_RINGS; olength = BX_PNIC_THIS s.recvRingLength[idx]; - memcpy ( data, BX_PNIC_THIS s.recvRing[idx], olength ); - BX_PNIC_THIS s.recvQueueLength --; + memcpy (data, BX_PNIC_THIS s.recvRing[idx], olength); + BX_PNIC_THIS s.recvQueueLength--; } - if ( ! BX_PNIC_THIS s.recvQueueLength ) { + if (! BX_PNIC_THIS s.recvQueueLength) { set_irq_level(0); } status = PNIC_STATUS_OK; break; - case PNIC_CMD_RECV_QLEN : + case PNIC_CMD_RECV_QLEN: Bit16u qlen; qlen = BX_PNIC_THIS s.recvQueueLength; olength = sizeof(qlen); - memcpy ( data, &qlen, sizeof(qlen) ); + memcpy (data, &qlen, sizeof(qlen)); status = PNIC_STATUS_OK; break; - case PNIC_CMD_MASK_IRQ : + case PNIC_CMD_MASK_IRQ: Bit8u enabled; enabled = *((Bit8u*)data); BX_PNIC_THIS s.irqEnabled = enabled; - if ( enabled && BX_PNIC_THIS s.recvQueueLength ) { + if (enabled && BX_PNIC_THIS s.recvQueueLength) { set_irq_level(1); } else { set_irq_level(0); @@ -501,16 +502,15 @@ void bx_pcipnic_c::exec_command(void) status = PNIC_STATUS_OK; break; - case PNIC_CMD_FORCE_IRQ : + case PNIC_CMD_FORCE_IRQ: set_irq_level(1); status = PNIC_STATUS_OK; break; default: - BX_ERROR(("Unknown PNIC command %x (data length %u)", command, ilength )); + BX_ERROR(("Unknown PNIC command %x (data length %u)", command, ilength)); status = PNIC_STATUS_UNKNOWN_CMD; break; - } // Set registers @@ -519,7 +519,6 @@ void bx_pcipnic_c::exec_command(void) BX_PNIC_THIS s.rDataCursor = 0; } - /* * Callback from the eth system driver when a frame has arrived */ @@ -540,26 +539,26 @@ void bx_pcipnic_c::rx_handler(void *arg, const void *buf, unsigned len) void bx_pcipnic_c::rx_frame(const void *buf, unsigned io_len) { // Check packet length - if ( io_len > PNIC_DATA_SIZE ) { - BX_PANIC ( ( "PNIC receive: data size %u exceeded buffer size %u", - io_len, PNIC_DATA_SIZE ) ); + if (io_len > PNIC_DATA_SIZE) { + BX_PANIC(("PNIC receive: data size %u exceeded buffer size %u", + io_len, PNIC_DATA_SIZE)); // Truncate if user continues io_len = PNIC_DATA_SIZE; } // Check receive ring is not full - if ( BX_PNIC_THIS s.recvQueueLength == PNIC_RECV_RINGS ) { - BX_ERROR ( ( "PNIC receive: receive ring full, discarding packet" ) ); + if (BX_PNIC_THIS s.recvQueueLength == PNIC_RECV_RINGS) { + BX_ERROR(("PNIC receive: receive ring full, discarding packet")); return; } // Copy data to receive ring and record length - memcpy ( BX_PNIC_THIS s.recvRing[ BX_PNIC_THIS s.recvIndex ], buf, io_len ); - BX_PNIC_THIS s.recvRingLength[ BX_PNIC_THIS s.recvIndex ] = io_len; + memcpy (BX_PNIC_THIS s.recvRing[BX_PNIC_THIS s.recvIndex], buf, io_len); + BX_PNIC_THIS s.recvRingLength[BX_PNIC_THIS s.recvIndex] = io_len; // Move to next ring entry - BX_PNIC_THIS s.recvIndex = ( BX_PNIC_THIS s.recvIndex + 1) % PNIC_RECV_RINGS; - BX_PNIC_THIS s.recvQueueLength ++; + BX_PNIC_THIS s.recvIndex = (BX_PNIC_THIS s.recvIndex + 1) % PNIC_RECV_RINGS; + BX_PNIC_THIS s.recvQueueLength++; // Generate interrupt if enabled - if ( BX_PNIC_THIS s.irqEnabled ) { + if (BX_PNIC_THIS s.irqEnabled) { set_irq_level(1); } } diff --git a/bochs/iodev/pic.cc b/bochs/iodev/pic.cc index 7eeef413f..07d2a701c 100644 --- a/bochs/iodev/pic.cc +++ b/bochs/iodev/pic.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: pic.cc,v 1.48 2008-01-26 22:24:02 sshwarts Exp $ +// $Id: pic.cc,v 1.49 2008-02-15 22:05:43 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2002 MandrakeSoft S.A. @@ -23,7 +23,7 @@ // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - +///////////////////////////////////////////////////////////////////////// // Define BX_PLUGGABLE in files that can be compiled into plugins. For // platforms that require a special tag on exported symbols, BX_PLUGGABLE @@ -270,7 +270,7 @@ void bx_pic_c::write(Bit32u address, Bit32u value, unsigned io_len) case 0x20: if (value & 0x10) { /* initialization command 1 */ BX_DEBUG(("master: init command 1 found")); - BX_DEBUG((" requires 4 = %u", (unsigned) (value & 0x01) )); + BX_DEBUG((" requires 4 = %u", (unsigned) (value & 0x01))); BX_DEBUG((" cascade mode: [0=cascade,1=single] %u", (unsigned) ((value & 0x02) >> 1))); BX_PIC_THIS s.master_pic.init.in_init = 1; @@ -295,7 +295,7 @@ void bx_pic_c::write(Bit32u address, Bit32u value, unsigned io_len) return; } - if ( (value & 0x18) == 0x08 ) { /* OCW3 */ + if ((value & 0x18) == 0x08) { /* OCW3 */ Bit8u special_mask, poll, read_op; special_mask = (value & 0x60) >> 5; @@ -445,7 +445,7 @@ void bx_pic_c::write(Bit32u address, Bit32u value, unsigned io_len) if (value & 0x10) { /* initialization command 1 */ BX_DEBUG(("slave: init command 1 found")); BX_DEBUG((" requires 4 = %u", - (unsigned) (value & 0x01) )); + (unsigned) (value & 0x01))); BX_DEBUG((" cascade mode: [0=cascade,1=single] %u", (unsigned) ((value & 0x02) >> 1))); BX_PIC_THIS s.slave_pic.init.in_init = 1; @@ -470,7 +470,7 @@ void bx_pic_c::write(Bit32u address, Bit32u value, unsigned io_len) return; } - if ( (value & 0x18) == 0x08 ) { /* OCW3 */ + if ((value & 0x18) == 0x08) { /* OCW3 */ Bit8u special_mask, poll, read_op; special_mask = (value & 0x60) >> 5; @@ -721,13 +721,13 @@ void bx_pic_c::service_master_pic(void) isr = BX_PIC_THIS s.master_pic.isr; if (isr) { max_irq = highest_priority; - while ( (isr & (1 << max_irq)) == 0) { + while ((isr & (1 << max_irq)) == 0) { max_irq++; if(max_irq > 7) max_irq = 0; } - if (max_irq == highest_priority ) return; /* Highest priority interrupt in-service, - * no other priorities allowed */ + if (max_irq == highest_priority) return; /* Highest priority interrupt in-service, + * no other priorities allowed */ if (max_irq > 7) BX_PANIC(("error in service_master_pic()")); } else @@ -735,13 +735,13 @@ void bx_pic_c::service_master_pic(void) } /* now, see if there are any higher priority requests */ - if ((unmasked_requests = (BX_PIC_THIS s.master_pic.irr & ~BX_PIC_THIS s.master_pic.imr)) ) { + if ((unmasked_requests = (BX_PIC_THIS s.master_pic.irr & ~BX_PIC_THIS s.master_pic.imr))) { irq = highest_priority; do { /* for special mode, since we're looking at all IRQ's, skip if * current IRQ is already in-service */ - if ( ! (BX_PIC_THIS s.master_pic.special_mask && ((BX_PIC_THIS s.master_pic.isr >> irq) & 0x01)) ) { + if (! (BX_PIC_THIS s.master_pic.special_mask && ((BX_PIC_THIS s.master_pic.isr >> irq) & 0x01))) { if (unmasked_requests & (1 << irq)) { BX_DEBUG(("signalling IRQ(%u)", (unsigned) irq)); BX_PIC_THIS s.master_pic.INT = 1; @@ -782,13 +782,13 @@ void bx_pic_c::service_slave_pic(void) isr = BX_PIC_THIS s.slave_pic.isr; if (isr) { max_irq = highest_priority; - while ( (isr & (1 << max_irq)) == 0) { + while ((isr & (1 << max_irq)) == 0) { max_irq++; if(max_irq > 7) max_irq = 0; } - if (max_irq == highest_priority ) return; /* Highest priority interrupt in-service, - * no other priorities allowed */ + if (max_irq == highest_priority) return; /* Highest priority interrupt in-service, + * no other priorities allowed */ if (max_irq > 7) BX_PANIC(("error in service_master_pic()")); } else @@ -796,13 +796,13 @@ void bx_pic_c::service_slave_pic(void) } /* now, see if there are any higher priority requests */ - if ((unmasked_requests = (BX_PIC_THIS s.slave_pic.irr & ~BX_PIC_THIS s.slave_pic.imr)) ) { + if ((unmasked_requests = (BX_PIC_THIS s.slave_pic.irr & ~BX_PIC_THIS s.slave_pic.imr))) { irq = highest_priority; do { /* for special mode, since we're looking at all IRQ's, skip if * current IRQ is already in-service */ - if ( ! (BX_PIC_THIS s.slave_pic.special_mask && ((BX_PIC_THIS s.slave_pic.isr >> irq) & 0x01)) ) { + if (! (BX_PIC_THIS s.slave_pic.special_mask && ((BX_PIC_THIS s.slave_pic.isr >> irq) & 0x01))) { if (unmasked_requests & (1 << irq)) { BX_DEBUG(("slave: signalling IRQ(%u)", (unsigned) 8 + irq)); diff --git a/bochs/iodev/pit82c54.cc b/bochs/iodev/pit82c54.cc index a375c41e5..3741f853e 100644 --- a/bochs/iodev/pit82c54.cc +++ b/bochs/iodev/pit82c54.cc @@ -1,7 +1,7 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: pit82c54.cc,v 1.31 2008-01-26 22:24:02 sshwarts Exp $ +// $Id: pit82c54.cc,v 1.32 2008-02-15 22:05:43 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// -// + /* * Emulator of an Intel 8254/82C54 Programmable Interval Timer. * Greg Alexander @@ -44,7 +44,7 @@ void pit_82C54::print_counter(counter_type &thisctr) void pit_82C54::print_cnum(Bit8u cnum) { - if(cnum>MAX_COUNTER) { + if (cnum>MAX_COUNTER) { BX_ERROR(("Bad counter index to print_cnum")); } else { print_counter(counter[cnum]); @@ -53,39 +53,39 @@ void pit_82C54::print_cnum(Bit8u cnum) void pit_82C54::latch_counter(counter_type &thisctr) { - if(thisctr.count_LSB_latched || thisctr.count_MSB_latched) { + if (thisctr.count_LSB_latched || thisctr.count_MSB_latched) { //Do nothing because previous latch has not been read.; } else { switch(thisctr.read_state) { case MSByte: - thisctr.outlatch=thisctr.count & 0xFFFF; - thisctr.count_MSB_latched=1; - break; + thisctr.outlatch=thisctr.count & 0xFFFF; + thisctr.count_MSB_latched=1; + break; case LSByte: - thisctr.outlatch=thisctr.count & 0xFFFF; - thisctr.count_LSB_latched=1; - break; + thisctr.outlatch=thisctr.count & 0xFFFF; + thisctr.count_LSB_latched=1; + break; case LSByte_multiple: - thisctr.outlatch=thisctr.count & 0xFFFF; - thisctr.count_LSB_latched=1; - thisctr.count_MSB_latched=1; - break; + thisctr.outlatch=thisctr.count & 0xFFFF; + thisctr.count_LSB_latched=1; + thisctr.count_MSB_latched=1; + break; case MSByte_multiple: - if(!(seen_problems & UNL_2P_READ)) { -// seen_problems|=UNL_2P_READ; - BX_ERROR(("Unknown behavior when latching during 2-part read.")); - BX_ERROR((" This message will not be repeated.")); - } - //I guess latching and resetting to LSB first makes sense; - BX_DEBUG(("Setting read_state to LSB_mult")); - thisctr.read_state=LSByte_multiple; - thisctr.outlatch=thisctr.count & 0xFFFF; - thisctr.count_LSB_latched=1; - thisctr.count_MSB_latched=1; - break; + if (!(seen_problems & UNL_2P_READ)) { +// seen_problems|=UNL_2P_READ; + BX_ERROR(("Unknown behavior when latching during 2-part read.")); + BX_ERROR((" This message will not be repeated.")); + } + //I guess latching and resetting to LSB first makes sense; + BX_DEBUG(("Setting read_state to LSB_mult")); + thisctr.read_state=LSByte_multiple; + thisctr.outlatch=thisctr.count & 0xFFFF; + thisctr.count_LSB_latched=1; + thisctr.count_MSB_latched=1; + break; default: - BX_ERROR(("Unknown read mode found during latch command.")); - break; + BX_ERROR(("Unknown read mode found during latch command.")); + break; } } } @@ -110,7 +110,7 @@ pit_82C54::set_count (counter_type &thisctr, Bit32u data) void BX_CPP_AttrRegparmN(1) pit_82C54::set_count_to_binary(counter_type &thisctr) { - if(thisctr.bcd_mode) { + if (thisctr.bcd_mode) { thisctr.count= (((thisctr.count_binary/1)%10)<<0) | (((thisctr.count_binary/10)%10)<<4) | @@ -124,7 +124,7 @@ pit_82C54::set_count_to_binary(counter_type &thisctr) void BX_CPP_AttrRegparmN(1) pit_82C54::set_binary_to_count(counter_type &thisctr) { - if(thisctr.bcd_mode) { + if (thisctr.bcd_mode) { thisctr.count_binary= (1*((thisctr.count>>0)&0xF)) + (10*((thisctr.count>>4)&0xF)) + @@ -138,8 +138,8 @@ pit_82C54::set_binary_to_count(counter_type &thisctr) void BX_CPP_AttrRegparmN(1) pit_82C54::decrement (counter_type &thisctr) { - if(!thisctr.count) { - if(thisctr.bcd_mode) { + if (!thisctr.count) { + if (thisctr.bcd_mode) { thisctr.count=0x9999; thisctr.count_binary=9999; } else { @@ -226,7 +226,7 @@ void BX_CPP_AttrRegparmN(2) pit_82C54::decrement_multiple(counter_type &thisctr, Bit32u cycles) { while(cycles>0) { - if(cycles<=thisctr.count_binary) { + if (cycles<=thisctr.count_binary) { thisctr.count_binary-=cycles; cycles-=cycles; set_count_to_binary(thisctr); @@ -241,77 +241,77 @@ pit_82C54::decrement_multiple(counter_type &thisctr, Bit32u cycles) void pit_82C54::clock_multiple(Bit8u cnum, Bit32u cycles) { - if(cnum>MAX_COUNTER) { + if (cnum>MAX_COUNTER) { BX_ERROR(("Counter number too high in clock")); } else { counter_type &thisctr = counter[cnum]; while(cycles>0) { - if(thisctr.next_change_time==0) { - if(thisctr.count_written) { - switch(thisctr.mode) { - case 0: - if(thisctr.GATE && (thisctr.write_state!=MSByte_multiple)) { - decrement_multiple(thisctr, cycles); - } - break; - case 1: - decrement_multiple(thisctr, cycles); - break; - case 2: - if( (!thisctr.first_pass) && thisctr.GATE ) { - decrement_multiple(thisctr, cycles); - } - break; - case 3: - if( (!thisctr.first_pass) && thisctr.GATE ) { - decrement_multiple(thisctr, 2*cycles); - } - break; - case 4: - if(thisctr.GATE) { - decrement_multiple(thisctr, cycles); - } - break; - case 5: - decrement_multiple(thisctr, cycles); - break; - default: - break; - } - } - cycles-=cycles; + if (thisctr.next_change_time==0) { + if (thisctr.count_written) { + switch(thisctr.mode) { + case 0: + if (thisctr.GATE && (thisctr.write_state!=MSByte_multiple)) { + decrement_multiple(thisctr, cycles); + } + break; + case 1: + decrement_multiple(thisctr, cycles); + break; + case 2: + if (!thisctr.first_pass && thisctr.GATE) { + decrement_multiple(thisctr, cycles); + } + break; + case 3: + if (!thisctr.first_pass && thisctr.GATE) { + decrement_multiple(thisctr, 2*cycles); + } + break; + case 4: + if (thisctr.GATE) { + decrement_multiple(thisctr, cycles); + } + break; + case 5: + decrement_multiple(thisctr, cycles); + break; + default: + break; + } + } + cycles-=cycles; } else { - switch(thisctr.mode) { - case 0: - case 1: - case 2: - case 4: - case 5: - if( thisctr.next_change_time > cycles ) { - decrement_multiple(thisctr,cycles); - thisctr.next_change_time-=cycles; - cycles-=cycles; - } else { - decrement_multiple(thisctr,(thisctr.next_change_time-1)); - cycles-=thisctr.next_change_time; - clock(cnum); - } - break; - case 3: - if( thisctr.next_change_time > cycles ) { - decrement_multiple(thisctr,cycles*2); - thisctr.next_change_time-=cycles; - cycles-=cycles; - } else { - decrement_multiple(thisctr,(thisctr.next_change_time-1)*2); - cycles-=thisctr.next_change_time; - clock(cnum); - } - break; - default: - cycles-=cycles; - break; - } + switch(thisctr.mode) { + case 0: + case 1: + case 2: + case 4: + case 5: + if (thisctr.next_change_time > cycles) { + decrement_multiple(thisctr,cycles); + thisctr.next_change_time-=cycles; + cycles-=cycles; + } else { + decrement_multiple(thisctr,(thisctr.next_change_time-1)); + cycles-=thisctr.next_change_time; + clock(cnum); + } + break; + case 3: + if (thisctr.next_change_time > cycles) { + decrement_multiple(thisctr,cycles*2); + thisctr.next_change_time-=cycles; + cycles-=cycles; + } else { + decrement_multiple(thisctr,(thisctr.next_change_time-1)*2); + cycles-=thisctr.next_change_time; + clock(cnum); + } + break; + default: + cycles-=cycles; + break; + } } } #if 0 @@ -323,257 +323,257 @@ void pit_82C54::clock_multiple(Bit8u cnum, Bit32u cycles) void BX_CPP_AttrRegparmN(1) pit_82C54::clock(Bit8u cnum) { - if(cnum>MAX_COUNTER) { + if (cnum>MAX_COUNTER) { BX_ERROR(("Counter number too high in clock")); } else { counter_type &thisctr = counter[cnum]; switch(thisctr.mode) { case 0: - if(thisctr.count_written) { - if(thisctr.null_count) { - set_count(thisctr, thisctr.inlatch); - if(thisctr.GATE) { - if(thisctr.count_binary==0) { - thisctr.next_change_time=1; + if (thisctr.count_written) { + if (thisctr.null_count) { + set_count(thisctr, thisctr.inlatch); + if (thisctr.GATE) { + if (thisctr.count_binary==0) { + thisctr.next_change_time=1; } else { - thisctr.next_change_time=thisctr.count_binary & 0xFFFF; - } - } else { - thisctr.next_change_time=0; - } - thisctr.null_count=0; - } else { - if(thisctr.GATE && (thisctr.write_state!=MSByte_multiple)) { - decrement(thisctr); - if(!thisctr.OUTpin) { - thisctr.next_change_time=thisctr.count_binary & 0xFFFF; - if(!thisctr.count) { - set_OUT(thisctr,1); - } - } else { - thisctr.next_change_time=0; - } - } else { - thisctr.next_change_time=0; //if the clock isn't moving. - } - } - } else { - thisctr.next_change_time=0; //default to 0. - } - thisctr.triggerGATE=0; - break; + thisctr.next_change_time=thisctr.count_binary & 0xFFFF; + } + } else { + thisctr.next_change_time=0; + } + thisctr.null_count=0; + } else { + if (thisctr.GATE && (thisctr.write_state!=MSByte_multiple)) { + decrement(thisctr); + if (!thisctr.OUTpin) { + thisctr.next_change_time=thisctr.count_binary & 0xFFFF; + if (!thisctr.count) { + set_OUT(thisctr,1); + } + } else { + thisctr.next_change_time=0; + } + } else { + thisctr.next_change_time=0; //if the clock isn't moving. + } + } + } else { + thisctr.next_change_time=0; //default to 0. + } + thisctr.triggerGATE=0; + break; case 1: - if(thisctr.count_written) { - if(thisctr.triggerGATE) { - set_count(thisctr, thisctr.inlatch); - if(thisctr.count_binary==0) { + if (thisctr.count_written) { + if (thisctr.triggerGATE) { + set_count(thisctr, thisctr.inlatch); + if (thisctr.count_binary==0) { thisctr.next_change_time=1; } else { thisctr.next_change_time=thisctr.count_binary & 0xFFFF; } - thisctr.null_count=0; - set_OUT(thisctr,0); - if(thisctr.write_state==MSByte_multiple) { - BX_ERROR(("Undefined behavior when loading a half loaded count.")); - } - } else { - decrement(thisctr); - if(!thisctr.OUTpin) { - if(thisctr.count_binary==0) { - thisctr.next_change_time=1; + thisctr.null_count=0; + set_OUT(thisctr,0); + if (thisctr.write_state==MSByte_multiple) { + BX_ERROR(("Undefined behavior when loading a half loaded count.")); + } + } else { + decrement(thisctr); + if (!thisctr.OUTpin) { + if (thisctr.count_binary==0) { + thisctr.next_change_time=1; } else { - thisctr.next_change_time=thisctr.count_binary & 0xFFFF; - } - if(thisctr.count==0) { - set_OUT(thisctr,1); - } - } else { - thisctr.next_change_time=0; - } - } - } else { - thisctr.next_change_time=0; //default to 0. - } - thisctr.triggerGATE=0; - break; + thisctr.next_change_time=thisctr.count_binary & 0xFFFF; + } + if (thisctr.count==0) { + set_OUT(thisctr,1); + } + } else { + thisctr.next_change_time=0; + } + } + } else { + thisctr.next_change_time=0; //default to 0. + } + thisctr.triggerGATE=0; + break; case 2: - if(thisctr.count_written) { - if(thisctr.triggerGATE || thisctr.first_pass) { - set_count(thisctr, thisctr.inlatch); - thisctr.next_change_time=(thisctr.count_binary-1) & 0xFFFF; - thisctr.null_count=0; - if(thisctr.inlatch==1) { - BX_ERROR(("ERROR: count of 1 is invalid in pit mode 2.")); - } - if(!thisctr.OUTpin) { - set_OUT(thisctr,1); - } - if(thisctr.write_state==MSByte_multiple) { - BX_ERROR(("Undefined behavior when loading a half loaded count.")); - } - thisctr.first_pass=0; - } else { - if(thisctr.GATE) { - decrement(thisctr); - thisctr.next_change_time=(thisctr.count_binary-1) & 0xFFFF; - if(thisctr.count==1) { - thisctr.next_change_time=1; - set_OUT(thisctr,0); - thisctr.first_pass=1; - } - } else { - thisctr.next_change_time=0; - } - } - } else { - thisctr.next_change_time=0; - } - thisctr.triggerGATE=0; - break; + if (thisctr.count_written) { + if (thisctr.triggerGATE || thisctr.first_pass) { + set_count(thisctr, thisctr.inlatch); + thisctr.next_change_time=(thisctr.count_binary-1) & 0xFFFF; + thisctr.null_count=0; + if (thisctr.inlatch==1) { + BX_ERROR(("ERROR: count of 1 is invalid in pit mode 2.")); + } + if (!thisctr.OUTpin) { + set_OUT(thisctr,1); + } + if (thisctr.write_state==MSByte_multiple) { + BX_ERROR(("Undefined behavior when loading a half loaded count.")); + } + thisctr.first_pass=0; + } else { + if (thisctr.GATE) { + decrement(thisctr); + thisctr.next_change_time=(thisctr.count_binary-1) & 0xFFFF; + if (thisctr.count==1) { + thisctr.next_change_time=1; + set_OUT(thisctr,0); + thisctr.first_pass=1; + } + } else { + thisctr.next_change_time=0; + } + } + } else { + thisctr.next_change_time=0; + } + thisctr.triggerGATE=0; + break; case 3: - if(thisctr.count_written) { - if( (thisctr.triggerGATE || thisctr.first_pass - || thisctr.state_bit_2) && thisctr.GATE ) { - set_count(thisctr, thisctr.inlatch & 0xFFFE); - thisctr.state_bit_1=thisctr.inlatch & 0x1; - if( (!thisctr.OUTpin) || (!(thisctr.state_bit_1))) { - if(((thisctr.count_binary/2)-1)==0) { + if (thisctr.count_written) { + if ((thisctr.triggerGATE || thisctr.first_pass + || thisctr.state_bit_2) && thisctr.GATE) { + set_count(thisctr, thisctr.inlatch & 0xFFFE); + thisctr.state_bit_1=thisctr.inlatch & 0x1; + if (!thisctr.OUTpin || !thisctr.state_bit_1) { + if (((thisctr.count_binary/2)-1)==0) { thisctr.next_change_time=1; } else { - thisctr.next_change_time=((thisctr.count_binary/2)-1) & 0xFFFF; + thisctr.next_change_time=((thisctr.count_binary/2)-1) & 0xFFFF; } - } else { - if((thisctr.count_binary/2)==0) { + } else { + if ((thisctr.count_binary/2)==0) { thisctr.next_change_time=1; } else { - thisctr.next_change_time=(thisctr.count_binary/2) & 0xFFFF; + thisctr.next_change_time=(thisctr.count_binary/2) & 0xFFFF; } - } - thisctr.null_count=0; - if(thisctr.inlatch==1) { - BX_ERROR(("Count of 1 is invalid in pit mode 3.")); - } - if(!thisctr.OUTpin) { - set_OUT(thisctr,1); - } else if(thisctr.OUTpin && !thisctr.first_pass) { - set_OUT(thisctr,0); - } - if(thisctr.write_state==MSByte_multiple) { - BX_ERROR(("Undefined behavior when loading a half loaded count.")); - } - thisctr.state_bit_2=0; - thisctr.first_pass=0; - } else { - if(thisctr.GATE) { - decrement(thisctr); - decrement(thisctr); - if( (!thisctr.OUTpin) || (!(thisctr.state_bit_1))) { - thisctr.next_change_time=((thisctr.count_binary/2)-1) & 0xFFFF; - } else { - thisctr.next_change_time=(thisctr.count_binary/2) & 0xFFFF; - } - if(thisctr.count==0) { - thisctr.state_bit_2=1; - thisctr.next_change_time=1; - } - if( (thisctr.count==2) && - ( (!thisctr.OUTpin) || (!(thisctr.state_bit_1))) - ) { - thisctr.state_bit_2=1; - thisctr.next_change_time=1; - } - } else { - thisctr.next_change_time=0; - } - } - } else { - thisctr.next_change_time=0; - } - thisctr.triggerGATE=0; - break; + } + thisctr.null_count=0; + if (thisctr.inlatch==1) { + BX_ERROR(("Count of 1 is invalid in pit mode 3.")); + } + if (!thisctr.OUTpin) { + set_OUT(thisctr,1); + } else if (thisctr.OUTpin && !thisctr.first_pass) { + set_OUT(thisctr,0); + } + if (thisctr.write_state==MSByte_multiple) { + BX_ERROR(("Undefined behavior when loading a half loaded count.")); + } + thisctr.state_bit_2=0; + thisctr.first_pass=0; + } else { + if (thisctr.GATE) { + decrement(thisctr); + decrement(thisctr); + if (!thisctr.OUTpin || !thisctr.state_bit_1) { + thisctr.next_change_time=((thisctr.count_binary/2)-1) & 0xFFFF; + } else { + thisctr.next_change_time=(thisctr.count_binary/2) & 0xFFFF; + } + if (thisctr.count==0) { + thisctr.state_bit_2=1; + thisctr.next_change_time=1; + } + if ((thisctr.count==2) && + (!thisctr.OUTpin || !thisctr.state_bit_1)) + { + thisctr.state_bit_2=1; + thisctr.next_change_time=1; + } + } else { + thisctr.next_change_time=0; + } + } + } else { + thisctr.next_change_time=0; + } + thisctr.triggerGATE=0; + break; case 4: - if(thisctr.count_written) { - if(!thisctr.OUTpin) { - set_OUT(thisctr,1); - } - if(thisctr.null_count) { - set_count(thisctr, thisctr.inlatch); - if(thisctr.GATE) { - if(thisctr.count_binary==0) { - thisctr.next_change_time=1; - } else { - thisctr.next_change_time=thisctr.count_binary & 0xFFFF; - } - } else { - thisctr.next_change_time=0; - } - thisctr.null_count=0; - if(thisctr.write_state==MSByte_multiple) { - BX_ERROR(("Undefined behavior when loading a half loaded count.")); - } - thisctr.first_pass=1; - } else { - if(thisctr.GATE) { - decrement(thisctr); - if(thisctr.first_pass) { - thisctr.next_change_time=thisctr.count_binary & 0xFFFF; - if(!thisctr.count) { - set_OUT(thisctr,0); - thisctr.next_change_time=1; - thisctr.first_pass=0; - } - } else { - thisctr.next_change_time=0; - } - } else { - thisctr.next_change_time=0; - } - } - } else { - thisctr.next_change_time=0; - } - thisctr.triggerGATE=0; - break; + if (thisctr.count_written) { + if (!thisctr.OUTpin) { + set_OUT(thisctr,1); + } + if (thisctr.null_count) { + set_count(thisctr, thisctr.inlatch); + if (thisctr.GATE) { + if (thisctr.count_binary==0) { + thisctr.next_change_time=1; + } else { + thisctr.next_change_time=thisctr.count_binary & 0xFFFF; + } + } else { + thisctr.next_change_time=0; + } + thisctr.null_count=0; + if (thisctr.write_state==MSByte_multiple) { + BX_ERROR(("Undefined behavior when loading a half loaded count.")); + } + thisctr.first_pass=1; + } else { + if (thisctr.GATE) { + decrement(thisctr); + if (thisctr.first_pass) { + thisctr.next_change_time=thisctr.count_binary & 0xFFFF; + if (!thisctr.count) { + set_OUT(thisctr,0); + thisctr.next_change_time=1; + thisctr.first_pass=0; + } + } else { + thisctr.next_change_time=0; + } + } else { + thisctr.next_change_time=0; + } + } + } else { + thisctr.next_change_time=0; + } + thisctr.triggerGATE=0; + break; case 5: - if(thisctr.count_written) { - if(!thisctr.OUTpin) { - set_OUT(thisctr,1); - } - if(thisctr.triggerGATE) { - set_count(thisctr, thisctr.inlatch); - if(thisctr.count_binary==0) { - thisctr.next_change_time=1; - } else { + if (thisctr.count_written) { + if (!thisctr.OUTpin) { + set_OUT(thisctr,1); + } + if (thisctr.triggerGATE) { + set_count(thisctr, thisctr.inlatch); + if (thisctr.count_binary==0) { + thisctr.next_change_time=1; + } else { thisctr.next_change_time=thisctr.count_binary & 0xFFFF; } - thisctr.null_count=0; - if(thisctr.write_state==MSByte_multiple) { - BX_ERROR(("Undefined behavior when loading a half loaded count.")); - } - thisctr.first_pass=1; - } else { - decrement(thisctr); - if(thisctr.first_pass) { - thisctr.next_change_time=thisctr.count_binary & 0xFFFF; - if(!thisctr.count) { - set_OUT(thisctr,0); - thisctr.next_change_time=1; - thisctr.first_pass=0; - } - } else { - thisctr.next_change_time=0; - } - } - } else { - thisctr.next_change_time=0; - } - thisctr.triggerGATE=0; - break; + thisctr.null_count=0; + if (thisctr.write_state==MSByte_multiple) { + BX_ERROR(("Undefined behavior when loading a half loaded count.")); + } + thisctr.first_pass=1; + } else { + decrement(thisctr); + if (thisctr.first_pass) { + thisctr.next_change_time=thisctr.count_binary & 0xFFFF; + if (!thisctr.count) { + set_OUT(thisctr,0); + thisctr.next_change_time=1; + thisctr.first_pass=0; + } + } else { + thisctr.next_change_time=0; + } + } + } else { + thisctr.next_change_time=0; + } + thisctr.triggerGATE=0; + break; default: - BX_ERROR(("Mode not implemented.")); - thisctr.next_change_time=0; - thisctr.triggerGATE=0; - break; + BX_ERROR(("Mode not implemented.")); + thisctr.next_change_time=0; + thisctr.triggerGATE=0; + break; } } } @@ -588,9 +588,9 @@ void pit_82C54::clock_all(Bit32u cycles) Bit8u pit_82C54::read(Bit8u address) { - if(address>MAX_ADDRESS) { + if (address>MAX_ADDRESS) { BX_ERROR(("Counter address incorrect in data read.")); - } else if(address==CONTROL_ADDRESS) { + } else if (address==CONTROL_ADDRESS) { BX_DEBUG(("PIT Read: Control Word Register.")); //Read from control word register; /* This might be okay. If so, 0 seems the most logical @@ -602,51 +602,51 @@ Bit8u pit_82C54::read(Bit8u address) //Read from a counter; BX_DEBUG(("PIT Read: Counter %d.",address)); counter_type &thisctr=counter[address]; - if(thisctr.status_latched) { - //Latched Status Read; - if(thisctr.count_MSB_latched && - (thisctr.read_state==MSByte_multiple) ) { - BX_ERROR(("Undefined output when status latched and count half read.")); - } else { - thisctr.status_latched=0; - return thisctr.status_latch; - } + if (thisctr.status_latched) { + //Latched Status Read; + if (thisctr.count_MSB_latched && + (thisctr.read_state==MSByte_multiple)) { + BX_ERROR(("Undefined output when status latched and count half read.")); + } else { + thisctr.status_latched=0; + return thisctr.status_latch; + } } else { - //Latched Count Read; - if(thisctr.count_LSB_latched) { - //Read Least Significant Byte; - if(thisctr.read_state==LSByte_multiple) { - BX_DEBUG(("Setting read_state to MSB_mult")); - thisctr.read_state=MSByte_multiple; - } - thisctr.count_LSB_latched=0; - return (thisctr.outlatch & 0xFF); - } else if(thisctr.count_MSB_latched) { - //Read Most Significant Byte; - if(thisctr.read_state==MSByte_multiple) { - BX_DEBUG(("Setting read_state to LSB_mult")); - thisctr.read_state=LSByte_multiple; - } - thisctr.count_MSB_latched=0; - return ((thisctr.outlatch>>8) & 0xFF); - } else { - //Unlatched Count Read; - if(!(thisctr.read_state & 0x1)) { - //Read Least Significant Byte; - if(thisctr.read_state==LSByte_multiple) { - thisctr.read_state=MSByte_multiple; - BX_DEBUG(("Setting read_state to MSB_mult")); - } - return (thisctr.count & 0xFF); - } else { - //Read Most Significant Byte; - if(thisctr.read_state==MSByte_multiple) { - BX_DEBUG(("Setting read_state to LSB_mult")); - thisctr.read_state=LSByte_multiple; - } - return ((thisctr.count>>8) & 0xFF); - } - } + //Latched Count Read; + if (thisctr.count_LSB_latched) { + //Read Least Significant Byte; + if (thisctr.read_state==LSByte_multiple) { + BX_DEBUG(("Setting read_state to MSB_mult")); + thisctr.read_state=MSByte_multiple; + } + thisctr.count_LSB_latched=0; + return (thisctr.outlatch & 0xFF); + } else if (thisctr.count_MSB_latched) { + //Read Most Significant Byte; + if (thisctr.read_state==MSByte_multiple) { + BX_DEBUG(("Setting read_state to LSB_mult")); + thisctr.read_state=LSByte_multiple; + } + thisctr.count_MSB_latched=0; + return ((thisctr.outlatch>>8) & 0xFF); + } else { + //Unlatched Count Read; + if (!(thisctr.read_state & 0x1)) { + //Read Least Significant Byte; + if (thisctr.read_state==LSByte_multiple) { + thisctr.read_state=MSByte_multiple; + BX_DEBUG(("Setting read_state to MSB_mult")); + } + return (thisctr.count & 0xFF); + } else { + //Read Most Significant Byte; + if (thisctr.read_state==MSByte_multiple) { + BX_DEBUG(("Setting read_state to LSB_mult")); + thisctr.read_state=LSByte_multiple; + } + return ((thisctr.count>>8) & 0xFF); + } + } } } @@ -656,9 +656,9 @@ Bit8u pit_82C54::read(Bit8u address) void pit_82C54::write(Bit8u address, Bit8u data) { - if(address>MAX_ADDRESS) { + if (address>MAX_ADDRESS) { BX_ERROR(("Counter address incorrect in data write.")); - } else if(address==CONTROL_ADDRESS) { + } else if (address==CONTROL_ADDRESS) { Bit8u SC, RW, M, BCD; controlword=data; BX_DEBUG(("Control Word Write.")); @@ -666,82 +666,81 @@ void pit_82C54::write(Bit8u address, Bit8u data) RW = (controlword>>4) & 0x3; M = (controlword>>1) & 0x7; BCD = controlword & 0x1; - if(SC == 3) { - //READ_BACK command; - int i; - BX_DEBUG(("READ_BACK command.")); - for(i=0;i<=MAX_COUNTER;i++) { - if((M>>i) & 0x1) { - //If we are using this counter; - counter_type &thisctr=counter[i]; - if(!((controlword>>5) & 1)) { - //Latch Count; - latch_counter(thisctr); - } - if(!((controlword>>4) & 1)) { - //Latch Status; - if(thisctr.status_latched) { - //Do nothing because latched status has not been read.; - } else { - thisctr.status_latch= - ((thisctr.OUTpin & 0x1) << 7) | - ((thisctr.null_count & 0x1) << 6) | - ((thisctr.rw_mode & 0x3) << 4) | - ((thisctr.mode & 0x7) << 1) | - (thisctr.bcd_mode&0x1) - ; - thisctr.status_latched=1; - } - } - } - } + if (SC == 3) { + //READ_BACK command; + int i; + BX_DEBUG(("READ_BACK command.")); + for(i=0;i<=MAX_COUNTER;i++) { + if ((M>>i) & 0x1) { + //If we are using this counter; + counter_type &thisctr=counter[i]; + if (!((controlword>>5) & 1)) { + //Latch Count; + latch_counter(thisctr); + } + if (!((controlword>>4) & 1)) { + //Latch Status; + if (thisctr.status_latched) { + //Do nothing because latched status has not been read.; + } else { + thisctr.status_latch= + ((thisctr.OUTpin & 0x1) << 7) | + ((thisctr.null_count & 0x1) << 6) | + ((thisctr.rw_mode & 0x3) << 4) | + ((thisctr.mode & 0x7) << 1) | + (thisctr.bcd_mode&0x1); + thisctr.status_latched=1; + } + } + } + } } else { - counter_type &thisctr = counter[SC]; - if(!RW) { - //Counter Latch command; - BX_DEBUG(("Counter Latch command. SC=%d",SC)); - latch_counter(thisctr); - } else { - //Counter Program Command; - BX_DEBUG(("Counter Program command. SC=%d, RW=%d, M=%d, BCD=%d",SC,RW,M,BCD)); - thisctr.null_count=1; - thisctr.count_LSB_latched=0; - thisctr.count_MSB_latched=0; - thisctr.status_latched=0; - thisctr.inlatch=0; - thisctr.count_written=0; - thisctr.first_pass=1; - thisctr.rw_mode=RW; - thisctr.bcd_mode=(BCD > 0); - thisctr.mode=M; - switch(RW) { - case 0x1: - BX_DEBUG(("Setting read_state to LSB")); - thisctr.read_state=LSByte; - thisctr.write_state=LSByte; - break; - case 0x2: - BX_DEBUG(("Setting read_state to MSB")); - thisctr.read_state=MSByte; - thisctr.write_state=MSByte; - break; - case 0x3: - BX_DEBUG(("Setting read_state to LSB_mult")); - thisctr.read_state=LSByte_multiple; - thisctr.write_state=LSByte_multiple; - break; - default: - BX_ERROR(("RW field invalid in control word write.")); - break; - } - //All modes except mode 0 have initial output of 1.; - if(M) { - set_OUT(thisctr, 1); - } else { - set_OUT(thisctr, 0); - } - thisctr.next_change_time=0; - } + counter_type &thisctr = counter[SC]; + if (!RW) { + //Counter Latch command; + BX_DEBUG(("Counter Latch command. SC=%d",SC)); + latch_counter(thisctr); + } else { + //Counter Program Command; + BX_DEBUG(("Counter Program command. SC=%d, RW=%d, M=%d, BCD=%d",SC,RW,M,BCD)); + thisctr.null_count=1; + thisctr.count_LSB_latched=0; + thisctr.count_MSB_latched=0; + thisctr.status_latched=0; + thisctr.inlatch=0; + thisctr.count_written=0; + thisctr.first_pass=1; + thisctr.rw_mode=RW; + thisctr.bcd_mode=(BCD > 0); + thisctr.mode=M; + switch(RW) { + case 0x1: + BX_DEBUG(("Setting read_state to LSB")); + thisctr.read_state=LSByte; + thisctr.write_state=LSByte; + break; + case 0x2: + BX_DEBUG(("Setting read_state to MSB")); + thisctr.read_state=MSByte; + thisctr.write_state=MSByte; + break; + case 0x3: + BX_DEBUG(("Setting read_state to LSB_mult")); + thisctr.read_state=LSByte_multiple; + thisctr.write_state=LSByte_multiple; + break; + default: + BX_ERROR(("RW field invalid in control word write.")); + break; + } + //All modes except mode 0 have initial output of 1.; + if (M) { + set_OUT(thisctr, 1); + } else { + set_OUT(thisctr, 0); + } + thisctr.next_change_time=0; + } } } else { //Write to counter initial value. @@ -749,60 +748,60 @@ void pit_82C54::write(Bit8u address, Bit8u data) BX_DEBUG(("Write Initial Count: counter=%d, count=%d",address,data)); switch(thisctr.write_state) { case LSByte_multiple: - thisctr.inlatch=(thisctr.inlatch & (0xFF<<8)) | data; - thisctr.write_state=MSByte_multiple; - break; + thisctr.inlatch=(thisctr.inlatch & (0xFF<<8)) | data; + thisctr.write_state=MSByte_multiple; + break; case LSByte: - thisctr.inlatch=(thisctr.inlatch & (0xFF<<8)) | data; - thisctr.null_count=1; - thisctr.count_written=1; - break; + thisctr.inlatch=(thisctr.inlatch & (0xFF<<8)) | data; + thisctr.null_count=1; + thisctr.count_written=1; + break; case MSByte_multiple: - thisctr.write_state=LSByte_multiple; + thisctr.write_state=LSByte_multiple; case MSByte: //shared between MSB_multiple and MSByte - thisctr.inlatch=(thisctr.inlatch & 0xFF) | (data<<8); - thisctr.null_count=1; - thisctr.count_written=1; - break; + thisctr.inlatch=(thisctr.inlatch & 0xFF) | (data<<8); + thisctr.null_count=1; + thisctr.count_written=1; + break; default: - BX_ERROR(("write counter in invalid write state.")); - break; + BX_ERROR(("write counter in invalid write state.")); + break; } switch(thisctr.mode) { case 0: - if(thisctr.write_state==MSByte_multiple) { - set_OUT(thisctr,0); - } - thisctr.next_change_time=1; - break; + if (thisctr.write_state==MSByte_multiple) { + set_OUT(thisctr,0); + } + thisctr.next_change_time=1; + break; case 1: - if(thisctr.triggerGATE) { //for initial writes, if already saw trigger. - thisctr.next_change_time=1; - } //Otherwise, no change. - break; + if (thisctr.triggerGATE) { //for initial writes, if already saw trigger. + thisctr.next_change_time=1; + } //Otherwise, no change. + break; case 6: case 2: - thisctr.next_change_time=1; //FIXME: this could be loosened. - break; + thisctr.next_change_time=1; //FIXME: this could be loosened. + break; case 7: case 3: - thisctr.next_change_time=1; //FIXME: this could be loosened. - break; + thisctr.next_change_time=1; //FIXME: this could be loosened. + break; case 4: - thisctr.next_change_time=1; - break; + thisctr.next_change_time=1; + break; case 5: - if(thisctr.triggerGATE) { //for initial writes, if already saw trigger. - thisctr.next_change_time=1; - } //Otherwise, no change. - break; + if (thisctr.triggerGATE) { //for initial writes, if already saw trigger. + thisctr.next_change_time=1; + } //Otherwise, no change. + break; } } } void pit_82C54::set_GATE(Bit8u cnum, bx_bool data) { - if(cnum>MAX_COUNTER) { + if (cnum>MAX_COUNTER) { BX_ERROR(("Counter number incorrect in 82C54 set_GATE")); } else { counter_type &thisctr = counter[cnum]; @@ -813,86 +812,86 @@ void pit_82C54::set_GATE(Bit8u cnum, bx_bool data) thisctr.triggerGATE=1; } switch(thisctr.mode) { - case 0: - if(data && thisctr.count_written) { - if(thisctr.null_count) { - thisctr.next_change_time=1; - } else { - if( (!thisctr.OUTpin) && - (thisctr.write_state!=MSByte_multiple) - ) { - if(thisctr.count_binary==0) { - thisctr.next_change_time=1; + case 0: + if (data && thisctr.count_written) { + if (thisctr.null_count) { + thisctr.next_change_time=1; + } else { + if ((!thisctr.OUTpin) && + (thisctr.write_state!=MSByte_multiple)) + { + if (thisctr.count_binary==0) { + thisctr.next_change_time=1; } else { - thisctr.next_change_time=thisctr.count_binary & 0xFFFF; - } - } else { - thisctr.next_change_time=0; - } - } - } else { - if(thisctr.null_count) { - thisctr.next_change_time=1; - } else { - thisctr.next_change_time=0; - } - } - break; - case 1: - if(data && thisctr.count_written) { //only triggers cause a change. - thisctr.next_change_time=1; - } - break; - case 2: - if(!data) { - set_OUT(thisctr,1); - thisctr.next_change_time=0; - } else { - if(thisctr.count_written) { - thisctr.next_change_time=1; - } else { - thisctr.next_change_time=0; - } - } - break; - case 3: - if(!data) { - set_OUT(thisctr,1); - thisctr.first_pass=1; - thisctr.next_change_time=0; - } else { - if(thisctr.count_written) { - thisctr.next_change_time=1; - } else { - thisctr.next_change_time=0; - } - } - break; - case 4: - if(!thisctr.OUTpin || thisctr.null_count) { - thisctr.next_change_time=1; - } else { - if(data && thisctr.count_written) { - if(thisctr.first_pass) { - if(thisctr.count_binary==0) { - thisctr.next_change_time=1; + thisctr.next_change_time=thisctr.count_binary & 0xFFFF; + } + } else { + thisctr.next_change_time=0; + } + } + } else { + if (thisctr.null_count) { + thisctr.next_change_time=1; + } else { + thisctr.next_change_time=0; + } + } + break; + case 1: + if (data && thisctr.count_written) { //only triggers cause a change. + thisctr.next_change_time=1; + } + break; + case 2: + if (!data) { + set_OUT(thisctr,1); + thisctr.next_change_time=0; + } else { + if (thisctr.count_written) { + thisctr.next_change_time=1; + } else { + thisctr.next_change_time=0; + } + } + break; + case 3: + if (!data) { + set_OUT(thisctr,1); + thisctr.first_pass=1; + thisctr.next_change_time=0; + } else { + if (thisctr.count_written) { + thisctr.next_change_time=1; + } else { + thisctr.next_change_time=0; + } + } + break; + case 4: + if (!thisctr.OUTpin || thisctr.null_count) { + thisctr.next_change_time=1; + } else { + if (data && thisctr.count_written) { + if (thisctr.first_pass) { + if (thisctr.count_binary==0) { + thisctr.next_change_time=1; } else { - thisctr.next_change_time=thisctr.count_binary & 0xFFFF; - } - } else { - thisctr.next_change_time=0; - } - } else { - thisctr.next_change_time=0; - } - } - break; - case 5: - if(data && thisctr.count_written) { //only triggers cause a change. - thisctr.next_change_time=1; - } - break; - default: + thisctr.next_change_time=thisctr.count_binary & 0xFFFF; + } + } else { + thisctr.next_change_time=0; + } + } else { + thisctr.next_change_time=0; + } + } + break; + case 5: + if (data && thisctr.count_written) { //only triggers cause a change. + thisctr.next_change_time=1; + } + break; + default: break; } } @@ -901,7 +900,7 @@ void pit_82C54::set_GATE(Bit8u cnum, bx_bool data) bx_bool pit_82C54::read_OUT(Bit8u cnum) { - if(cnum>MAX_COUNTER) { + if (cnum>MAX_COUNTER) { BX_ERROR(("Counter number incorrect in 82C54 read_OUT")); return 0; } @@ -911,7 +910,7 @@ bx_bool pit_82C54::read_OUT(Bit8u cnum) bx_bool pit_82C54::read_GATE(Bit8u cnum) { - if(cnum>MAX_COUNTER) { + if (cnum>MAX_COUNTER) { BX_ERROR(("Counter number incorrect in 82C54 read_GATE")); return 0; } @@ -921,7 +920,7 @@ bx_bool pit_82C54::read_GATE(Bit8u cnum) Bit32u pit_82C54::get_clock_event_time(Bit8u cnum) { - if(cnum>MAX_COUNTER) { + if (cnum>MAX_COUNTER) { BX_ERROR(("Counter number incorrect in 82C54 read_GATE")); return 0; } @@ -937,9 +936,9 @@ Bit32u pit_82C54::get_next_event_time(void) Bit32u time2=get_clock_event_time(2); out=time0; - if(time1 && (time1> 1) & 0x01; - if ( BX_PIT_THIS s.speaker_data_on ) { + if (BX_PIT_THIS s.speaker_data_on) { DEV_speaker_beep_on((float)(1193180.0 / this->get_timer(2))); } else { DEV_speaker_beep_off(); @@ -327,18 +325,16 @@ void bx_pit_c::write(Bit32u address, Bit32u dvalue, unsigned io_len) (unsigned) address, (unsigned) value)); } - if(time_passed || - (BX_PIT_THIS s.last_next_event_time - != BX_PIT_THIS s.timer.get_next_event_time()) - ) { - BX_DEBUG(("pit: RESETting timer.")); + if(time_passed || (BX_PIT_THIS s.last_next_event_time != BX_PIT_THIS s.timer.get_next_event_time())) + { + BX_DEBUG(("pit: RESETting timer")); bx_virt_timer.deactivate_timer(BX_PIT_THIS s.timer_handle[0]); - BX_DEBUG(("deactivated timer.")); + BX_DEBUG(("deactivated timer")); if(BX_PIT_THIS s.timer.get_next_event_time()) { bx_virt_timer.activate_timer(BX_PIT_THIS s.timer_handle[0], (Bit32u)BX_MAX(1,TICKS_TO_USEC(BX_PIT_THIS s.timer.get_next_event_time())), 0); - BX_DEBUG(("activated timer.")); + BX_DEBUG(("activated timer")); } BX_PIT_THIS s.last_next_event_time = BX_PIT_THIS s.timer.get_next_event_time(); } diff --git a/bochs/iodev/pit_wrap.h b/bochs/iodev/pit_wrap.h index 0010d0819..60c4fa5f1 100644 --- a/bochs/iodev/pit_wrap.h +++ b/bochs/iodev/pit_wrap.h @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: pit_wrap.h,v 1.27 2007-09-28 19:52:05 sshwarts Exp $ +// $Id: pit_wrap.h,v 1.28 2008-02-15 22:05:43 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -78,9 +78,9 @@ private: static void timer_handler(void *this_ptr); BX_PIT_SMF void handle_timer(); - BX_PIT_SMF void write_count_reg( Bit8u value, unsigned timerid ); - BX_PIT_SMF Bit8u read_counter( unsigned timerid ); - BX_PIT_SMF void latch( unsigned timerid ); + BX_PIT_SMF void write_count_reg(Bit8u value, unsigned timerid); + BX_PIT_SMF Bit8u read_counter(unsigned timerid); + BX_PIT_SMF void latch(unsigned timerid); BX_PIT_SMF void set_GATE(unsigned pit_id, unsigned value); BX_PIT_SMF void start(unsigned timerid); diff --git a/bochs/iodev/sb16.cc b/bochs/iodev/sb16.cc index bbdad918b..80482bfe9 100644 --- a/bochs/iodev/sb16.cc +++ b/bochs/iodev/sb16.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: sb16.cc,v 1.56 2008-01-26 22:24:02 sshwarts Exp $ +// $Id: sb16.cc,v 1.57 2008-02-15 22:05:43 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2002 MandrakeSoft S.A. @@ -23,6 +23,8 @@ // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +///////////////////////////////////////////////////////////////////////// // This file (SB16.CC) written and donated by Josef Drexler @@ -135,7 +137,7 @@ void bx_sb16_c::init(void) bx_list_c *base; base = (bx_list_c*) SIM->get_param(BXPN_SB16); - if ( (strlen(SIM->get_param_string("logfile", base)->getptr()) < 1) ) + if ((strlen(SIM->get_param_string("logfile", base)->getptr()) < 1)) SIM->get_param_num("loglevel", base)->set(0); if (SIM->get_param_num("loglevel", base)->get() > 0) @@ -162,8 +164,8 @@ void bx_sb16_c::init(void) BX_SB16_THIS wavemode = 0; } - if ( (BX_SB16_THIS midimode == 2) || - (BX_SB16_THIS midimode == 3) ) + if ((BX_SB16_THIS midimode == 2) || + (BX_SB16_THIS midimode == 3)) { MIDIDATA = fopen(SIM->get_param_string("midifile", base)->getptr(),"wb"); if (MIDIDATA == NULL) @@ -176,8 +178,8 @@ void bx_sb16_c::init(void) initmidifile(); } - if ( (BX_SB16_THIS wavemode == 2) || - (BX_SB16_THIS wavemode == 3) ) + if ((BX_SB16_THIS wavemode == 2) || + (BX_SB16_THIS wavemode == 3)) { WAVEDATA = fopen(SIM->get_param_string("wavefile", base)->getptr(),"wb"); if (WAVEDATA == NULL) @@ -209,14 +211,14 @@ void bx_sb16_c::init(void) // allocate the FIFO buffers - except for the MPUMIDICMD buffer // these sizes are generous, 16 or 8 would probably be sufficient - MPU.datain.init( (int) 64); // the input - MPU.dataout.init( (int) 64); // and output - MPU.cmd.init( (int) 64); // and command buffers - MPU.midicmd.init( (int) 256); // and the midi command buffer (note- large SYSEX'es have to fit!) - DSP.datain.init( (int) 64); // the DSP input - DSP.dataout.init( (int) 64); // and output buffers - EMUL.datain.init( (int) 64); // the emulator ports - EMUL.dataout.init( (int) 64); // for changing emulator settings + MPU.datain.init((int) 64); // the input + MPU.dataout.init((int) 64); // and output + MPU.cmd.init((int) 64); // and command buffers + MPU.midicmd.init((int) 256); // and the midi command buffer (note- large SYSEX'es have to fit!) + DSP.datain.init((int) 64); // the DSP input + DSP.dataout.init((int) 64); // and output buffers + EMUL.datain.init((int) 64); // the emulator ports + EMUL.dataout.init((int) 64); // for changing emulator settings // reset all parts of the hardware by // triggering their reset functions @@ -302,7 +304,7 @@ void bx_sb16_c::init(void) } writelog(MIDILOG(4), "Timers initialized, midi %d, dma %d, opl %d", - MPU.timer_handle, DSP.timer_handle, OPL.timer_handle ); + MPU.timer_handle, DSP.timer_handle, OPL.timer_handle); MPU.current_timer = 0; // init runtime parameters @@ -464,10 +466,10 @@ void bx_sb16_c::dsp_dmatimer(void *this_ptr) // However, don't do this if the next byte/word will fill up the // output buffer and the output functions are not ready yet. - if ( (BX_SB16_THIS wavemode != 1) || - ( (This->dsp.dma.chunkindex + 1 < BX_SOUND_OUTPUT_WAVEPACKETSIZE) && - (This->dsp.dma.count > 0) ) || - (This->output->waveready() == BX_SOUND_OUTPUT_OK) ) { + if ((BX_SB16_THIS wavemode != 1) || + ((This->dsp.dma.chunkindex + 1 < BX_SOUND_OUTPUT_WAVEPACKETSIZE) && + (This->dsp.dma.count > 0)) || + (This->output->waveready() == BX_SOUND_OUTPUT_OK)) { if ((DSP.dma.bits == 8) || (BX_SB16_DMAH == 0)) { DEV_dma_set_drq(BX_SB16_DMAL, 1); } else { @@ -809,14 +811,14 @@ void bx_sb16_c::dsp_datawrite(Bit32u value) // set samplerate for output case 0x42: // 1,2: hi(frq) lo(frq) - DSP.datain.getw1( &(DSP.dma.samplerate) ); - DSP.dma.timeconstant = 65536 - (Bit32u) 256000000 / (Bit32u) DSP.dma.samplerate ; + DSP.datain.getw1(&(DSP.dma.samplerate)); + DSP.dma.timeconstant = 65536 - (Bit32u) 256000000 / (Bit32u) DSP.dma.samplerate; break; // set block length case 0x48: // 1,2: lo(blk len) hi(blk len) - DSP.datain.getw( &(DSP.dma.blocklength) ); + DSP.datain.getw(&(DSP.dma.blocklength)); break; // 4-bit comp'd, normal DAC DMA, no ref byte @@ -992,7 +994,7 @@ void bx_sb16_c::dsp_datawrite(Bit32u value) // read speaker on/off (out ff=on, 00=off) case 0xd8: // none, o1: speaker; ff/00 - DSP.dataout.put( (DSP.speaker == 1)?0xff:0x00); + DSP.dataout.put((DSP.speaker == 1)?0xff:0x00); break; // stop 16 bit auto DMA @@ -1102,23 +1104,23 @@ void bx_sb16_c::dsp_dma(Bit8u command, Bit8u mode, Bit16u length, Bit8u comp) writelog(WAVELOG(4), "DMA initialized. Cmd %02x, mode %02x, length %d, comp %d", command, mode, length, comp); - if ( (command >> 4) == 0xb ) // 0xb? = 16 bit DMA + if ((command >> 4) == 0xb) // 0xb? = 16 bit DMA { DSP.dma.bits = 16; DSP.dma.bps = 2; } - else // 0xc? = 8 bit DMA + else // 0xc? = 8 bit DMA { DSP.dma.bits = 8; DSP.dma.bps = 1; } // Prevent division by zero in some instances - if ( DSP.dma.samplerate == 0 ) + if (DSP.dma.samplerate == 0) DSP.dma.samplerate= 10752; command &= 0x0f; DSP.dma.output = 1 - (command >> 3); // 1=output, 0=input - DSP.dma.mode = 1 + ( (command >> 2) & 1); // 0=none, 1=normal, 2=auto + DSP.dma.mode = 1 + ((command >> 2) & 1); // 0=none, 1=normal, 2=auto DSP.dma.fifo = (command >> 1) & 1; // ? not sure what this is DSP.dma.stereo = (mode >> 5) & 1; @@ -1149,7 +1151,7 @@ void bx_sb16_c::dsp_dma(Bit8u command, Bit8u mode, Bit16u length, Bit8u comp) (DSP.dma.highspeed == 1)?"highspeed":"normal speed", sampledatarate, DSP.dma.timer); - DSP.dma.format = DSP.dma.issigned | ( (comp & 7) << 1) | ( (comp & 8) << 4); + DSP.dma.format = DSP.dma.issigned | ((comp & 7) << 1) | ((comp & 8) << 4); // write the output to the device/file if (DSP.dma.output == 1) @@ -1271,7 +1273,7 @@ void bx_sb16_c::dsp_getwavepacket() byteA = byteB; for (int i = 0; i < BX_SOUND_OUTPUT_WAVEPACKETSIZE; i++) - DSP.dma.chunk[i] = ( (i & 1) == 0) ? byteA : byteB; + DSP.dma.chunk[i] = ((i & 1) == 0) ? byteA : byteB; DSP.dma.chunkcount = BX_SOUND_OUTPUT_WAVEPACKETSIZE; DSP.dma.chunkindex = 0; @@ -1292,7 +1294,7 @@ void bx_sb16_c::dsp_sendwavepacket() Bit8u temparray[12] = { DSP.dma.samplerate & 0xff, DSP.dma.samplerate >> 8, 0, 0, DSP.dma.bits, DSP.dma.stereo + 1, 0, 0, 0, 0, 0, 0 }; - switch ( (DSP.dma.format >> 1) & 7) + switch ((DSP.dma.format >> 1) & 7) { case 2: temparray[7] = 3; @@ -1338,7 +1340,7 @@ void bx_sb16_c::dsp_dmadone() { writelog(WAVELOG(4), "DMA transfer done, triggering IRQ"); - if ( (DSP.dma.output == 1) && (DSP.dma.mode != 2) ) + if ((DSP.dma.output == 1) && (DSP.dma.mode != 2)) { dsp_sendwavepacket(); // flush the output @@ -1725,9 +1727,9 @@ Bit32u bx_sb16_c::mpu_status() { Bit32u result = 0; - if ( (MPU.datain.full() == 1) || - ( (BX_SB16_THIS midimode == 1) && - (BX_SB16_OUTPUT->midiready() == BX_SOUND_OUTPUT_ERR) ) ) + if ((MPU.datain.full() == 1) || + ((BX_SB16_THIS midimode == 1) && + (BX_SB16_OUTPUT->midiready() == BX_SOUND_OUTPUT_ERR))) result |= 0x40; // output not ready if (MPU.dataout.empty() == 1) result |= 0x80; // no input available @@ -1747,7 +1749,7 @@ void bx_sb16_c::mpu_command(Bit32u value) if (MPU.cmd.hascommand() == 1) // already a command pending, abort that one { if ((MPU.cmd.currentcommand() != value) || - (MPU.cmd.commanddone() == 0) ) + (MPU.cmd.commanddone() == 0)) // it's a different command, or the old one isn't done yet, abort it { MPU.cmd.clearcommand(); @@ -1761,7 +1763,7 @@ void bx_sb16_c::mpu_command(Bit32u value) if (MPU.cmd.hascommand() == 0) // no command pending, set one up { bytesneeded = 0; - if ( (value >> 4) == 14) bytesneeded = 1; + if ((value >> 4) == 14) bytesneeded = 1; MPU.cmd.newcommand(value, bytesneeded); } @@ -1869,7 +1871,7 @@ void bx_sb16_c::mpu_datawrite(Bit32u value) if (MPU.cmd.commanddone() == 1) BX_SB16_THIS mpu_command(MPU.cmd.currentcommand()); } - else if ( (MPU.uartmode == 0) && (MPU.singlecommand == 0) ) + else if ((MPU.uartmode == 0) && (MPU.singlecommand == 0)) { // Hm? No UART mode, but still data? Maybe should send it // to the command port... Only SBMPU401.EXE does this... @@ -1907,7 +1909,7 @@ void bx_sb16_c::mpu_mididata(Bit32u value) { writelog(MIDILOG(3), "Midi command %02x incomplete, has %d of %d bytes.", MPU.midicmd.currentcommand(), MPU.midicmd.bytes(), - MPU.midicmd.commandbytes() ); + MPU.midicmd.commandbytes()); // write as much as we can. Should we do this? processmidicommand(0); // clear the pending command @@ -1918,7 +1920,7 @@ void bx_sb16_c::mpu_mididata(Bit32u value) // find the number of arguments to the command static const signed eventlength[] = { 2, 2, 2, 2, 1, 1, 2, 255}; // note - length 255 commands have unknown length - MPU.midicmd.newcommand(value, eventlength[ (value & 0x70) >> 4 ]); + MPU.midicmd.newcommand(value, eventlength[(value & 0x70) >> 4]); } else // no command, just arguments to the old command { @@ -1935,7 +1937,7 @@ void bx_sb16_c::mpu_mididata(Bit32u value) { // the command is complete, process it writelog(MIDILOG(5), "Midi command %02x complete, has %d bytes.", - MPU.midicmd.currentcommand(), MPU.midicmd.bytes() ); + MPU.midicmd.currentcommand(), MPU.midicmd.bytes()); processmidicommand(0); // and remove the command from the buffer MPU.midicmd.clearcommand(); @@ -2123,7 +2125,7 @@ void bx_sb16_c::emul_write(Bit32u value) case 9: // enter specific OPL2/3 mode EMUL.dataout.get(&value8); writelog(4, "Entering OPL2/3 mode %d", value8); - opl_entermode( (bx_sb16_fm_mode) value8); + opl_entermode((bx_sb16_fm_mode) value8); break; case 10: // check emulator present EMUL.datain.put(0x55); @@ -2225,7 +2227,7 @@ void bx_sb16_c::opl_entermode(bx_sb16_fm_mode newmode) // ch: 0 1 2 3 4 5 6 7 8 // op1: 0 1 2 6 7 8 12 13 14 // op2: 3 4 5 9 10 11 15 16 17 - OPL.chan[i].opnum[0] = i + ( (int) (i / 3) ) * 3; + OPL.chan[i].opnum[0] = i + ((int) (i / 3)) * 3; OPL.chan[i].opnum[1] = OPL.chan[i].opnum[0] + 3; } @@ -2242,12 +2244,12 @@ void bx_sb16_c::opl_entermode(bx_sb16_fm_mode newmode) void bx_sb16_c::opl_timerevent() { for (int i=0; i<4; i++) { - if ((OPL.tmask[i/2] & (1 << (i % 2)) ) != 0) + if ((OPL.tmask[i/2] & (1 << (i % 2))) != 0) { // only running timers if ((OPL.timer[i]--) == 0) { // overflow occured, set flags accordingly OPL.timer[i] = OPL.timerinit[i]; // reset the counter - if ((OPL.tmask[i/2] >> (6 - (i % 2)) ) == 0) // set flags only if unmasked + if ((OPL.tmask[i/2] >> (6 - (i % 2))) == 0) // set flags only if unmasked { writelog(WAVELOG(5), "OPL Timer Interrupt: Chip %d, Timer %d", i/2, 1 << (i % 2)); OPL.tflag[i/2] |= 1 << (6 - (i % 2)); // set the overflow flag @@ -2288,8 +2290,8 @@ void bx_sb16_c::opl_data(Bit32u value, int chipid) // first find out operator and/or channel numbers // case 0x20 ... 0x95: includes too many ports, but that is harmless // case 0xe0 ... 0xf5: - if ( ((index>=0x20) && (index<=0x95)) || - ((index>=0xe0) && (index<=0xf5)) ) { + if (((index>=0x20) && (index<=0x95)) || + ((index>=0xe0) && (index<=0xf5))) { // operator access // find the operator number. 0..17 on chip 1, 18..35 on chip 2 @@ -2313,7 +2315,7 @@ void bx_sb16_c::opl_data(Bit32u value, int chipid) opernum += BX_SB16_FM_NOP / 2; // find out the channel number, and which of the channel's operators this is - channum = opernum % 3 + ( (int) (opernum / 6) ) * 3; + channum = opernum % 3 + ((int) (opernum / 6)) * 3; subopnum = 0; if ((opernum % 6) > 2) // second operator @@ -2331,7 +2333,7 @@ void bx_sb16_c::opl_data(Bit32u value, int chipid) writelog(MIDILOG(5), "Is Channel %d, Oper %d, Subop %d", channum, opernum, subopnum); } - else if ( (index>=0xa0) && (index<=0xc8) ) { + else if ((index>=0xa0) && (index<=0xc8)) { // channel access channum = index & 0x0f; if (OPL.chan[channum].nop == 0) @@ -2346,7 +2348,7 @@ break_here: // WSEnable and Test Register case 0x01: OPL.wsenable[chipid] = (value >> 5) & 1; - if ( (value & 0x1f) != 0) + if ((value & 0x1f) != 0) writelog(MIDILOG(3), "Warning: Test Register set to %02x", value & 0x1f); break; @@ -2360,7 +2362,7 @@ break_here: // if OPL2: timer masks // if OPL3: 4-operator modes case 0x04: - if ( (chipid == 0) || (OPL.mode == dual) ) + if ((chipid == 0) || (OPL.mode == dual)) opl_settimermask(value, chipid); else opl_set4opmode(value & 0x3f); @@ -2370,7 +2372,7 @@ break_here: case 0x05: if (chipid == 1) { - if ( (value & 1) != 0) + if ((value & 1) != 0) opl_entermode(opl3); else opl_entermode(single); @@ -2627,7 +2629,7 @@ void bx_sb16_c::opl_set4opmode(int new4opmode) channel1 = i + (i / 3) * 6; channel2 = channel1 + 3; - if ( ( (new4opmode >> i) & 1) != 0) + if (((new4opmode >> i) & 1) != 0) { // enable 4-op mode opl_keyonoff(channel1, 0); opl_keyonoff(channel2, 0); @@ -2670,13 +2672,13 @@ void bx_sb16_c::opl_settimermask(int value, int chipid) if ((value & 0x03) != 0) // yes, it's different. Start or stop? { writelog(MIDILOG(5), "Starting timers"); - bx_pc_system.activate_timer( OPL.timer_handle, 0, 1); + bx_pc_system.activate_timer(OPL.timer_handle, 0, 1); OPL.timer_running = 1; } else { writelog(MIDILOG(5), "Stopping timers"); - bx_pc_system.deactivate_timer( OPL.timer_handle ); + bx_pc_system.deactivate_timer(OPL.timer_handle); OPL.timer_running = 0; } } @@ -2788,7 +2790,7 @@ void bx_sb16_c::opl_setfreq(int channel) // this is a reasonable approximation for keyfreq /= 1.059463 // (that value is 2**(1/12), which is the difference between two keys) - while ( (keyfreq -= ( (keyfreq * 1000) / 17817) ) > freqC) + while ((keyfreq -= ((keyfreq * 1000) / 17817)) > freqC) keynum++; } else { @@ -2820,7 +2822,7 @@ void bx_sb16_c::opl_keyonoff(int channel, bx_bool onoff) if (OPL.chan[channel].midichan == 0xff) { for (i=0; i<16; i++) - if (((OPL.midichannels >> i) & 1 ) != 0) + if (((OPL.midichannels >> i) & 1) != 0) { OPL.chan[channel].midichan = i; OPL.midichannels &= ~(1 << i); // mark channel as used @@ -2961,7 +2963,7 @@ void bx_sb16_c::processmidicommand(bx_bool force) channel = MPU.midicmd.currentcommand() & 0xf; // we need to log bank changes and program changes - if ( (MPU.midicmd.currentcommand() >> 4) == 0xc) + if ((MPU.midicmd.currentcommand() >> 4) == 0xc) { // a program change value = MPU.midicmd.peek(0); writelog(MIDILOG(1), "* ProgramChange channel %d to %d", @@ -2969,7 +2971,7 @@ void bx_sb16_c::processmidicommand(bx_bool force) MPU.program[channel] = value; needremap = 1; } - else if ( (MPU.midicmd.currentcommand() >> 4) == 0xb) + else if ((MPU.midicmd.currentcommand() >> 4) == 0xb) { // a control change, could be a bank change if (MPU.midicmd.peek(0) == 0) { // bank select MSB @@ -2993,7 +2995,7 @@ void bx_sb16_c::processmidicommand(bx_bool force) Bit8u temparray[256]; i = 0; while (MPU.midicmd.empty() == 0) - MPU.midicmd.get( &(temparray[i++]) ); + MPU.midicmd.get(&(temparray[i++])); writemidicommand(MPU.midicmd.currentcommand(), i, temparray); @@ -3024,32 +3026,32 @@ void bx_sb16_c::midiremapprogram(int channel) for(int i = 0; i < EMUL.remaps; i++) { - if (( (EMUL.remaplist[i].oldbankmsb == bankmsb) || - (EMUL.remaplist[i].oldbankmsb == 0xff) ) && - ( (EMUL.remaplist[i].oldbanklsb == banklsb) || - (EMUL.remaplist[i].oldbanklsb == 0xff) ) && - ( (EMUL.remaplist[i].oldprogch == program) || - (EMUL.remaplist[i].oldprogch == 0xff) ) ) + if (((EMUL.remaplist[i].oldbankmsb == bankmsb) || + (EMUL.remaplist[i].oldbankmsb == 0xff)) && + ((EMUL.remaplist[i].oldbanklsb == banklsb) || + (EMUL.remaplist[i].oldbanklsb == 0xff)) && + ((EMUL.remaplist[i].oldprogch == program) || + (EMUL.remaplist[i].oldprogch == 0xff))) { writelog(5, "Remapping instrument for channel %d", channel); - if ( (EMUL.remaplist[i].newbankmsb != bankmsb) && - (EMUL.remaplist[i].newbankmsb != 0xff) ) + if ((EMUL.remaplist[i].newbankmsb != bankmsb) && + (EMUL.remaplist[i].newbankmsb != 0xff)) { // write control change bank msb MPU.bankmsb[channel] = EMUL.remaplist[i].newbankmsb; commandbytes[0] = 0; commandbytes[1] = EMUL.remaplist[i].newbankmsb; writemidicommand(0xb0 | channel, 2, commandbytes); } - if ( (EMUL.remaplist[i].newbanklsb != banklsb) && - (EMUL.remaplist[i].newbanklsb != 0xff) ) + if ((EMUL.remaplist[i].newbanklsb != banklsb) && + (EMUL.remaplist[i].newbanklsb != 0xff)) { // write control change bank lsb MPU.banklsb[channel] = EMUL.remaplist[i].newbanklsb; commandbytes[0] = 32; commandbytes[1] = EMUL.remaplist[i].newbanklsb; writemidicommand(0xb0 | channel, 2, commandbytes); } - if ( (EMUL.remaplist[i].newprogch != program) && - (EMUL.remaplist[i].newprogch != 0xff) ) + if ((EMUL.remaplist[i].newprogch != program) && + (EMUL.remaplist[i].newprogch != 0xff)) { // write program change MPU.program[channel] = EMUL.remaplist[i].newprogch; commandbytes[0] = EMUL.remaplist[i].newprogch; @@ -3059,7 +3061,6 @@ void bx_sb16_c::midiremapprogram(int channel) } } - // convert a number into a delta time coded value int bx_sb16_c::converttodeltatime(Bit32u deltatime, Bit8u value[4]) { @@ -3091,12 +3092,11 @@ int bx_sb16_c::converttodeltatime(Bit32u deltatime, Bit8u value[4]) void bx_sb16_c::writedeltatime(Bit32u deltatime) { Bit8u outbytes[4]; - int count,i; - count = converttodeltatime(deltatime, outbytes); + int count = converttodeltatime(deltatime, outbytes); - for (i=0; i 0) fwrite(header, 1, headerlen, WAVEDATA); if (datalen > 0) @@ -3532,9 +3532,9 @@ bx_bool bx_sb16_buffer::puts(char *data, ...) while (string[index] != 0) { - if (put( (Bit8u) string[index]) == 0) + if (put((Bit8u) string[index]) == 0) return 0; // buffer full - index++; + index++; } return 1; } @@ -3558,8 +3558,8 @@ bx_bool bx_sb16_buffer::get(Bit8u *data) { // Buffer is empty. Still, if it was initialized, return // the last byte again. - if ( length > 0 ) - (*data) = buffer[ (tail - 1) % length ]; + if (length > 0) + (*data) = buffer[ (tail - 1) % length ]; return 0; // buffer empty } @@ -3587,7 +3587,7 @@ bx_bool bx_sb16_buffer::getw(Bit16u *data) get(&dummy); *data = (Bit16u) dummy; get(&dummy); - *data |= ( (Bit16u) dummy ) << 8; + *data |= ((Bit16u) dummy) << 8; return 1; } @@ -3600,14 +3600,14 @@ bx_bool bx_sb16_buffer::getw1(Bit16u *data) if (bytes() == 1) { get(&dummy); - *data = ( (Bit16u) dummy ) << 8; + *data = ((Bit16u) dummy) << 8; } else dummy = 0; return 0; } get(&dummy); - *data = ( (Bit16u) dummy ) << 8; + *data = ((Bit16u) dummy) << 8; get(&dummy); *data |= (Bit16u) dummy; return 1; diff --git a/bochs/iodev/scsipt.h b/bochs/iodev/scsipt.h index 50a67db2e..ceea1beaa 100644 --- a/bochs/iodev/scsipt.h +++ b/bochs/iodev/scsipt.h @@ -1,10 +1,10 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: scsipt.h,v 1.4 2002-09-16 16:58:36 bdenney Exp $ +// $Id: scsipt.h,v 1.5 2008-02-15 22:05:43 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // // iodev/scsipt.h -// $Id: scsipt.h,v 1.4 2002-09-16 16:58:36 bdenney Exp $ +// $Id: scsipt.h,v 1.5 2008-02-15 22:05:43 sshwarts Exp $ // // This file was copied from ... ? // @@ -128,7 +128,7 @@ typedef struct { /* * Standard IOCTL define */ -#define CTL_CODE( DevType, Function, Method, Access ) ( \ +#define CTL_CODE(DevType, Function, Method, Access) ( \ ((DevType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \ ) diff --git a/bochs/iodev/serial.cc b/bochs/iodev/serial.cc index 1fdd74416..8755c1dbb 100644 --- a/bochs/iodev/serial.cc +++ b/bochs/iodev/serial.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: serial.cc,v 1.80 2008-01-26 22:24:02 sshwarts Exp $ +// $Id: serial.cc,v 1.81 2008-02-15 22:05:43 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2004 MandrakeSoft S.A. @@ -23,7 +23,7 @@ // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - +///////////////////////////////////////////////////////////////////////// // Peter Grehan (grehan@iprg.nokia.com) coded the original version of this // serial emulation. He implemented a single 8250, and allow terminal @@ -31,7 +31,6 @@ // The current version emulates up to 4 UART 16550A with FIFO. Terminal // input/output now works on some more platforms. - // Define BX_PLUGGABLE in files that can be compiled into plugins. For // platforms that require a special tag on exported symbols, BX_PLUGGABLE // is used to know when we are exporting symbols and when we are importing. @@ -530,21 +529,18 @@ bx_serial_c::raise_interrupt(Bit8u port, int type) } } - // static IO port read callback handler - // redirects to non-static class handler to avoid virtual functions +// static IO port read callback handler +// redirects to non-static class handler to avoid virtual functions - Bit32u -bx_serial_c::read_handler(void *this_ptr, Bit32u address, unsigned io_len) +Bit32u bx_serial_c::read_handler(void *this_ptr, Bit32u address, unsigned io_len) { #if !BX_USE_SER_SMF bx_serial_c *class_ptr = (bx_serial_c *) this_ptr; - return( class_ptr->read(address, io_len) ); + return class_ptr->read(address, io_len); } - - Bit32u -bx_serial_c::read(Bit32u address, unsigned io_len) +Bit32u bx_serial_c::read(Bit32u address, unsigned io_len) { #else UNUSED(this_ptr); @@ -1337,7 +1333,7 @@ bx_serial_c::rx_timer(void) int data; if ((data_ready = BX_SER_THIS s[port].raw->ready_receive())) { data = BX_SER_THIS s[port].raw->receive(); - if (data < 0 ) { + if (data < 0) { data_ready = 0; switch (data) { case RAW_EVENT_BREAK: @@ -1460,9 +1456,9 @@ bx_serial_c::serial_mouse_enq(int delta_x, int delta_y, int delta_z, unsigned bu return; // scale down the motion - if ( (delta_x < -1) || (delta_x > 1) ) + if ((delta_x < -1) || (delta_x > 1)) delta_x /= 2; - if ( (delta_y < -1) || (delta_y > 1) ) + if ((delta_y < -1) || (delta_y > 1)) delta_y /= 2; if(delta_x>127) delta_x=127; diff --git a/bochs/iodev/slowdown_timer.cc b/bochs/iodev/slowdown_timer.cc index 93a58a2b4..083c1fbf6 100644 --- a/bochs/iodev/slowdown_timer.cc +++ b/bochs/iodev/slowdown_timer.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: slowdown_timer.cc,v 1.27 2007-09-28 19:52:06 sshwarts Exp $ +// $Id: slowdown_timer.cc,v 1.28 2008-02-15 22:05:43 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2002 MandrakeSoft S.A. @@ -24,6 +24,7 @@ // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // +///////////////////////////////////////////////////////////////////////// #include "bochs.h" #include "slowdown_timer.h" @@ -63,7 +64,7 @@ void bx_slowdown_timer_c::init(void) { // Return early if slowdown timer not selected if ((SIM->get_param_enum(BXPN_CLOCK_SYNC)->get() != BX_CLOCK_SYNC_SLOWDOWN) && - (SIM->get_param_enum(BXPN_CLOCK_SYNC)->get() != BX_CLOCK_SYNC_BOTH) ) + (SIM->get_param_enum(BXPN_CLOCK_SYNC)->get() != BX_CLOCK_SYNC_BOTH)) return; BX_INFO(("using 'slowdown' timer synchronization method")); diff --git a/bochs/iodev/soundlnx.cc b/bochs/iodev/soundlnx.cc index 7cf301390..0a90aef99 100644 --- a/bochs/iodev/soundlnx.cc +++ b/bochs/iodev/soundlnx.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: soundlnx.cc,v 1.12 2008-01-26 22:24:02 sshwarts Exp $ +// $Id: soundlnx.cc,v 1.13 2008-02-15 22:05:43 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -23,10 +23,10 @@ // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +///////////////////////////////////////////////////////////////////////// // This file (SOUNDLNX.CC) written and donated by Josef Drexler - #define NO_DEVICE_INCLUDES #include "iodev.h" #define BX_SOUNDLOW @@ -69,17 +69,17 @@ int bx_sound_linux_c::midiready() int bx_sound_linux_c::openmidioutput(char *device) { - if ( (device == NULL) || (strlen(device) < 1) ) + if ((device == NULL) || (strlen(device) < 1)) return BX_SOUND_OUTPUT_ERR; midi = fopen(device,"w"); if (midi == NULL) - { - WRITELOG( MIDILOG(2), "Couldn't open midi output device %s: %s.", - device, strerror(errno)); + { + WRITELOG(MIDILOG(2), "Couldn't open midi output device %s: %s.", + device, strerror(errno)); return BX_SOUND_OUTPUT_ERR; - } + } return BX_SOUND_OUTPUT_OK; } @@ -88,7 +88,6 @@ int bx_sound_linux_c::openmidioutput(char *device) int bx_sound_linux_c::sendmidicommand(int delta, int command, int length, Bit8u data[]) { UNUSED(delta); - // BX_PANIC(("Sendmidicommand!!"); fputc(command, midi); fwrite(data, 1, length, midi); @@ -128,16 +127,16 @@ int bx_sound_linux_c::startwaveplayback(int frequency, int bits, int stereo, int int fmt, ret; int signeddata = format & 1; - if ( (wavedevice == NULL) || (strlen(wavedevice) < 1) ) + if ((wavedevice == NULL) || (strlen(wavedevice) < 1)) return BX_SOUND_OUTPUT_ERR; if (wave == -1) wave = open(wavedevice, O_WRONLY); else - if ( (frequency == oldfreq) && - (bits == oldbits) && - (stereo == oldstereo) && - (format == oldformat) ) + if ((frequency == oldfreq) && + (bits == oldbits) && + (stereo == oldstereo) && + (format == oldformat)) return BX_SOUND_OUTPUT_OK; // nothing to do oldfreq = frequency; @@ -164,53 +163,51 @@ int bx_sound_linux_c::startwaveplayback(int frequency, int bits, int stereo, int // set frequency etc. ret = ioctl(wave, SNDCTL_DSP_RESET); if (ret != 0) - WRITELOG( WAVELOG(4), "ioctl(SNDCTL_DSP_RESET): %s", strerror(errno)); + WRITELOG(WAVELOG(4), "ioctl(SNDCTL_DSP_RESET): %s", strerror(errno)); /* ret = ioctl(wave, SNDCTL_DSP_SETFRAGMENT, &fragment); if (ret != 0) - WRITELOG( WAVELOG(4), "ioctl(SNDCTL_DSP_SETFRAGMENT, %d): %s", - fragment, strerror(errno)); + WRITELOG(WAVELOG(4), "ioctl(SNDCTL_DSP_SETFRAGMENT, %d): %s", + fragment, strerror(errno)); */ ret = ioctl(wave, SNDCTL_DSP_SETFMT, &fmt); if (ret != 0) // abort if the format is unknown, to avoid playing noise - { - WRITELOG( WAVELOG(4), "ioctl(SNDCTL_DSP_SETFMT, %d): %s", - fmt, strerror(errno)); + { + WRITELOG(WAVELOG(4), "ioctl(SNDCTL_DSP_SETFMT, %d): %s", + fmt, strerror(errno)); return BX_SOUND_OUTPUT_ERR; - } + } ret = ioctl(wave, SNDCTL_DSP_STEREO, &stereo); if (ret != 0) - WRITELOG( WAVELOG(4), "ioctl(SNDCTL_DSP_STEREO, %d): %s", - stereo, strerror(errno)); + WRITELOG(WAVELOG(4), "ioctl(SNDCTL_DSP_STEREO, %d): %s", + stereo, strerror(errno)); ret = ioctl(wave, SNDCTL_DSP_SPEED, &frequency); if (ret != 0) - WRITELOG( WAVELOG(4), "ioctl(SNDCTL_DSP_SPEED, %d): %s", - frequency, strerror(errno)); + WRITELOG(WAVELOG(4), "ioctl(SNDCTL_DSP_SPEED, %d): %s", + frequency, strerror(errno)); - // ioctl(wave, SNDCTL_DSP_GETBLKSIZE, &fragment); - // WRITELOG( WAVELOG(4), "current output block size is %d", fragment); + // ioctl(wave, SNDCTL_DSP_GETBLKSIZE, &fragment); + // WRITELOG(WAVELOG(4), "current output block size is %d", fragment); return BX_SOUND_OUTPUT_OK; } int bx_sound_linux_c::sendwavepacket(int length, Bit8u data[]) { - int ret; - - ret = write(wave, data, length); + int ret = write(wave, data, length); return BX_SOUND_OUTPUT_OK; } int bx_sound_linux_c::stopwaveplayback() { - // ioctl(wave, SNDCTL_DSP_SYNC); - // close(wave); - // wave = -1; + // ioctl(wave, SNDCTL_DSP_SYNC); + // close(wave); + // wave = -1; return BX_SOUND_OUTPUT_OK; } @@ -221,10 +218,10 @@ int bx_sound_linux_c::closewaveoutput() delete(wavedevice); if (wave != -1) - { + { close(wave); wave = -1; - } + } wavedevice = NULL; diff --git a/bochs/iodev/soundosx.cc b/bochs/iodev/soundosx.cc index fe181608c..fca260f99 100644 --- a/bochs/iodev/soundosx.cc +++ b/bochs/iodev/soundosx.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: soundosx.cc,v 1.8 2008-01-26 22:24:02 sshwarts Exp $ +// $Id: soundosx.cc,v 1.9 2008-02-15 22:05:43 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // This file (SOUNDOSX.CC) written and donated by Brian Huffman @@ -126,14 +126,14 @@ int bx_sound_osx_c::openmidioutput(char *device) // Start playing AUGraphStart (MidiGraph); #endif - WRITELOG( WAVELOG(4), "openmidioutput(%s)", device); + WRITELOG(WAVELOG(4), "openmidioutput(%s)", device); MidiOpen = 1; return BX_SOUND_OUTPUT_OK; } int bx_sound_osx_c::sendmidicommand(int delta, int command, int length, Bit8u data[]) { - WRITELOG( WAVELOG(5), "sendmidicommand(%i,%02x,%i)", delta, command, length); + WRITELOG(WAVELOG(5), "sendmidicommand(%i,%02x,%i)", delta, command, length); if (!MidiOpen) return BX_SOUND_OUTPUT_ERR; #ifdef BX_SOUND_OSX_use_converter @@ -151,7 +151,7 @@ int bx_sound_osx_c::sendmidicommand(int delta, int command, int length, Bit8u da int bx_sound_osx_c::closemidioutput() { - WRITELOG( WAVELOG(4), "closemidioutput()"); + WRITELOG(WAVELOG(4), "closemidioutput()"); MidiOpen = 0; #ifdef BX_SOUND_OSX_use_converter AUGraphStop (MidiGraph); @@ -176,7 +176,7 @@ int bx_sound_osx_c::openwaveoutput(char *device) { OSStatus err; - WRITELOG( WAVELOG(4), "openwaveoutput(%s)", device); + WRITELOG(WAVELOG(4), "openwaveoutput(%s)", device); // open the default output unit #ifdef BX_SOUND_OSX_use_quicktime @@ -208,7 +208,7 @@ int bx_sound_osx_c::startwaveplayback(int frequency, int bits, int stereo, int f UInt32 formatSize = sizeof(AudioStreamBasicDescription); #endif - WRITELOG( WAVELOG(4), "startwaveplayback(%d, %d, %d, %x)", frequency, bits, stereo, format); + WRITELOG(WAVELOG(4), "startwaveplayback(%d, %d, %d, %x)", frequency, bits, stereo, format); #ifdef BX_SOUND_OSX_use_quicktime WaveInfo.samplePtr = NULL; @@ -228,10 +228,10 @@ int bx_sound_osx_c::startwaveplayback(int frequency, int bits, int stereo, int f #endif #ifdef BX_SOUND_OSX_use_converter - if ( (frequency == oldfreq) && + if ((frequency == oldfreq) && (bits == oldbits) && (stereo == oldstereo) && - (format == oldformat) ) + (format == oldformat)) return BX_SOUND_OUTPUT_OK; // nothing to do oldfreq = frequency; @@ -299,7 +299,7 @@ int bx_sound_osx_c::sendwavepacket(int length, Bit8u data[]) SndCommand mySndCommand; #endif - WRITELOG( WAVELOG(4), "sendwavepacket(%d, %p), head=%u", length, data, head); + WRITELOG(WAVELOG(4), "sendwavepacket(%d, %p), head=%u", length, data, head); // sanity check if ((!WaveOpen) || (head - tail >= BX_SOUND_OSX_NBUF)) @@ -380,7 +380,7 @@ OSStatus MyACInputProc (AudioConverterRef inAudioConverter, void bx_sound_osx_c::nextbuffer (int *outDataSize, void **outData) { - WRITELOG( WAVELOG(4), "nextbuffer(), tail=%u", tail); + WRITELOG(WAVELOG(4), "nextbuffer(), tail=%u", tail); if (head - tail <= 0) { *outData = NULL; *outDataSize = 0; diff --git a/bochs/iodev/soundwin.cc b/bochs/iodev/soundwin.cc index 87e124ed0..f4acaedd1 100644 --- a/bochs/iodev/soundwin.cc +++ b/bochs/iodev/soundwin.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: soundwin.cc,v 1.19 2008-01-26 22:24:02 sshwarts Exp $ +// $Id: soundwin.cc,v 1.20 2008-02-15 22:05:43 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -23,6 +23,7 @@ // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +///////////////////////////////////////////////////////////////////////// // This file (SOUNDWIN.CC) written and donated by Josef Drexler @@ -57,12 +58,12 @@ bx_sound_windows_c::bx_sound_windows_c(bx_sb16_c *sb16) // BX_SOUND_WINDOWS_NBUF wave header and buffers, all aligned // on a 16-byte boundary -#define ALIGN(size) ( (size + 15) & ~15 ) +#define ALIGN(size) ((size + 15) & ~15) #define size ALIGN(sizeof(MIDIHDR)) \ - + ALIGN(sizeof(WAVEHDR)) \ - + ALIGN(BX_SOUND_WINDOWS_MAXSYSEXLEN) * BX_SOUND_WINDOWS_NBUF \ - + ALIGN(BX_SOUND_OUTPUT_WAVEPACKETSIZE) * BX_SOUND_WINDOWS_NBUF + + ALIGN(sizeof(WAVEHDR)) \ + + ALIGN(BX_SOUND_WINDOWS_MAXSYSEXLEN) * BX_SOUND_WINDOWS_NBUF \ + + ALIGN(BX_SOUND_OUTPUT_WAVEPACKETSIZE) * BX_SOUND_WINDOWS_NBUF DataHandle = GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, size); DataPointer = (Bit8u*) GlobalLock(DataHandle); @@ -127,11 +128,11 @@ int bx_sound_windows_c::openmidioutput(char *device) MidiOpen = 0; - UINT ret = midiOutOpen( &MidiOut, deviceid, 0, 0, CALLBACK_NULL); + UINT ret = midiOutOpen(&MidiOut, deviceid, 0, 0, CALLBACK_NULL); if (ret == 0) MidiOpen = 1; - WRITELOG( MIDILOG(4), "midiOutOpen() = %d, MidiOpen: %d", ret, MidiOpen); + WRITELOG(MIDILOG(4), "midiOutOpen() = %d, MidiOpen: %d", ret, MidiOpen); return (MidiOpen == 1) ? BX_SOUND_OUTPUT_OK : BX_SOUND_OUTPUT_ERR; } @@ -143,33 +144,33 @@ int bx_sound_windows_c::sendmidicommand(int delta, int command, int length, Bit8 if (MidiOpen != 1) return BX_SOUND_OUTPUT_ERR; - if ( (command == 0xf0) || (command == 0xf7) || (length > 3) ) - { - WRITELOG( WAVELOG(5), "SYSEX started, length %d", length); - ismidiready = 0; // until the buffer is done - memcpy(MidiData, data, length); - MidiHeader->lpData = MidiData; - MidiHeader->dwBufferLength = BX_SOUND_WINDOWS_MAXSYSEXLEN; - MidiHeader->dwBytesRecorded = 0; - MidiHeader->dwUser = 0; - MidiHeader->dwFlags = 0; - ret = midiOutPrepareHeader(MidiOut, MidiHeader, sizeof(*MidiHeader)); - if (ret != 0) - WRITELOG( MIDILOG(2), "midiOutPrepareHeader() = %d", ret); - ret = midiOutLongMsg(MidiOut, MidiHeader, sizeof(*MidiHeader)); - if (ret != 0) - WRITELOG( MIDILOG(2), "midiOutLongMsg() = %d", ret); - } + if ((command == 0xf0) || (command == 0xf7) || (length > 3)) + { + WRITELOG(WAVELOG(5), "SYSEX started, length %d", length); + ismidiready = 0; // until the buffer is done + memcpy(MidiData, data, length); + MidiHeader->lpData = MidiData; + MidiHeader->dwBufferLength = BX_SOUND_WINDOWS_MAXSYSEXLEN; + MidiHeader->dwBytesRecorded = 0; + MidiHeader->dwUser = 0; + MidiHeader->dwFlags = 0; + ret = midiOutPrepareHeader(MidiOut, MidiHeader, sizeof(*MidiHeader)); + if (ret != 0) + WRITELOG(MIDILOG(2), "midiOutPrepareHeader() = %d", ret); + ret = midiOutLongMsg(MidiOut, MidiHeader, sizeof(*MidiHeader)); + if (ret != 0) + WRITELOG(MIDILOG(2), "midiOutLongMsg() = %d", ret); + } else - { - DWORD msg = command; + { + DWORD msg = command; - for (int i = 0; ilpData = WaveData[bufnum]; + WaveHeader[bufnum]->dwBufferLength = length[bufnum]; + WaveHeader[bufnum]->dwBytesRecorded = length[bufnum]; + WaveHeader[bufnum]->dwUser = 0; + WaveHeader[bufnum]->dwFlags = 0; + WaveHeader[bufnum]->dwLoops = 1; + + ret = waveOutPrepareHeader(WaveOut, WaveHeader[bufnum], sizeof(*WaveHeader[bufnum])); + if (ret != 0) { - WRITELOG( WAVELOG(5), "Playing buffer %d", bufnum); - - // prepare the wave header - WaveHeader[bufnum]->lpData = WaveData[bufnum]; - WaveHeader[bufnum]->dwBufferLength = length[bufnum]; - WaveHeader[bufnum]->dwBytesRecorded = length[bufnum]; - WaveHeader[bufnum]->dwUser = 0; - WaveHeader[bufnum]->dwFlags = 0; - WaveHeader[bufnum]->dwLoops = 1; - - ret = waveOutPrepareHeader(WaveOut, WaveHeader[bufnum], sizeof(*WaveHeader[bufnum])); - if (ret != 0) - { - WRITELOG( WAVELOG(2), "waveOutPrepareHeader = %d", ret); - return BX_SOUND_OUTPUT_ERR; - } - - ret = waveOutWrite(WaveOut, WaveHeader[bufnum], sizeof(*WaveHeader[bufnum])); - if (ret != 0) - { - char errormsg[4*MAXERRORLENGTH+1]; - waveOutGetErrorTextA(ret, errormsg, 4*MAXERRORLENGTH+1); - WRITELOG( WAVELOG(5), "waveOutWrite: %s", errormsg); - } + WRITELOG(WAVELOG(2), "waveOutPrepareHeader = %d", ret); + return BX_SOUND_OUTPUT_ERR; } - return BX_SOUND_OUTPUT_OK; + + ret = waveOutWrite(WaveOut, WaveHeader[bufnum], sizeof(*WaveHeader[bufnum])); + if (ret != 0) + { + char errormsg[4*MAXERRORLENGTH+1]; + waveOutGetErrorTextA(ret, errormsg, 4*MAXERRORLENGTH+1); + WRITELOG(WAVELOG(5), "waveOutWrite: %s", errormsg); + } + } + + return BX_SOUND_OUTPUT_OK; } int bx_sound_windows_c::startwaveplayback(int frequency, int bits, int stereo, int format) { - // UINT ret; - - WRITELOG( WAVELOG(4), "startwaveplayback(%d, %d, %d, %x)", frequency, bits, stereo, format); + WRITELOG(WAVELOG(4), "startwaveplayback(%d, %d, %d, %x)", frequency, bits, stereo, format); #ifdef usewaveOut // check if any of the properties have changed - if ( (WaveInfo.frequency != frequency) || - (WaveInfo.bits != bits) || - (WaveInfo.stereo != stereo) || - (WaveInfo.format != format) ) - { - needreopen = 1; + if ((WaveInfo.frequency != frequency) || + (WaveInfo.bits != bits) || + (WaveInfo.stereo != stereo) || + (WaveInfo.format != format)) + { + needreopen = 1; - // store the current settings to be used by sendwavepacket() - WaveInfo.frequency = frequency; - WaveInfo.bits = bits; - WaveInfo.stereo = stereo; - WaveInfo.format = format; - } + // store the current settings to be used by sendwavepacket() + WaveInfo.frequency = frequency; + WaveInfo.bits = bits; + WaveInfo.stereo = stereo; + WaveInfo.format = format; + } #endif #ifdef usesndPlaySnd @@ -392,7 +389,7 @@ int bx_sound_windows_c::sendwavepacket(int length, Bit8u data[]) UINT ret; #endif - WRITELOG( WAVELOG(4), "sendwavepacket(%d, %p)", length, data); + WRITELOG(WAVELOG(4), "sendwavepacket(%d, %p)", length, data); #ifdef usewaveOut bufnum = head; @@ -404,25 +401,24 @@ int bx_sound_windows_c::sendwavepacket(int length, Bit8u data[]) bufnum++; bufnum &= BX_SOUND_WINDOWS_NMASK; - if ( ( (bufnum + 1) & BX_SOUND_WINDOWS_NMASK) == tailfull ) - { // this should not actually happen! - WRITELOG( WAVELOG(2), "Output buffer overflow! Not played. Iswaveready was %d", iswaveready); - iswaveready = 0; // stop the output for a while - return BX_SOUND_OUTPUT_ERR; - } + if (((bufnum + 1) & BX_SOUND_WINDOWS_NMASK) == tailfull) + { // this should not actually happen! + WRITELOG(WAVELOG(2), "Output buffer overflow! Not played. Iswaveready was %d", iswaveready); + iswaveready = 0; // stop the output for a while + return BX_SOUND_OUTPUT_ERR; + } head = bufnum; // check if more buffers are available, otherwise stall the emulator - if ( ( (bufnum + 2) & BX_SOUND_WINDOWS_NMASK) == tailfull ) - { - WRITELOG( WAVELOG(5), "Buffer status: Head %d, TailFull %d, TailPlay %d. Stall.", - head, tailfull, tailplay); - iswaveready = 0; - } + if (((bufnum + 2) & BX_SOUND_WINDOWS_NMASK) == tailfull) + { + WRITELOG(WAVELOG(5), "Buffer status: Head %d, TailFull %d, TailPlay %d. Stall.", + head, tailfull, tailplay); + iswaveready = 0; + } playnextbuffer(); - #endif #ifdef usesndPlaySnd @@ -431,13 +427,13 @@ int bx_sound_windows_c::sendwavepacket(int length, Bit8u data[]) header->length = length + 36; header->chnk2len = length; - memcpy( &(header->data), data, length); + memcpy(&(header->data), data, length); - ret = sndPlaySoundA( (LPCSTR) header, SND_SYNC | SND_MEMORY ); + ret = sndPlaySoundA((LPCSTR) header, SND_SYNC | SND_MEMORY); if (ret != 0) - { - WRITELOG( WAVELOG(3), "sndPlaySoundA: %d", ret); - } + { + WRITELOG(WAVELOG(3), "sndPlaySoundA: %d", ret); + } #endif return BX_SOUND_OUTPUT_OK; @@ -445,14 +441,14 @@ int bx_sound_windows_c::sendwavepacket(int length, Bit8u data[]) int bx_sound_windows_c::stopwaveplayback() { - WRITELOG( WAVELOG(4), "stopwaveplayback()"); + WRITELOG(WAVELOG(4), "stopwaveplayback()"); #ifdef usewaveOut // this is handled by checkwaveready() when closing #endif #ifdef usesndPlaySnd - sndPlaySoundA( NULL, SND_ASYNC | SND_MEMORY ); + sndPlaySoundA(NULL, SND_ASYNC | SND_MEMORY); WaveOpen = 0; #endif @@ -462,25 +458,23 @@ int bx_sound_windows_c::stopwaveplayback() int bx_sound_windows_c::closewaveoutput() { -// int bufnum; - - WRITELOG( WAVELOG(4), "closewaveoutput"); + WRITELOG(WAVELOG(4), "closewaveoutput"); #ifdef usewaveOut if (WaveOpen == 1) - { - waveOutReset(WaveOut); + { + waveOutReset(WaveOut); - // let checkwaveready() clean up the buffers - checkwaveready(); + // let checkwaveready() clean up the buffers + checkwaveready(); - waveOutClose(WaveOut); + waveOutClose(WaveOut); - head = 0; - tailfull = 0; - tailplay = 0; - needreopen = 0; - } + head = 0; + tailfull = 0; + tailplay = 0; + needreopen = 0; + } #endif return BX_SOUND_OUTPUT_OK; @@ -490,12 +484,12 @@ void bx_sound_windows_c::checkmidiready() { UINT ret; - if ( (MidiHeader->dwFlags & WHDR_DONE) != 0) - { - WRITELOG( MIDILOG(5), "SYSEX message done, midi ready again."); - ret = midiOutUnprepareHeader( MidiOut, MidiHeader, sizeof(*MidiHeader)); - ismidiready = 1; - } + if ((MidiHeader->dwFlags & WHDR_DONE) != 0) + { + WRITELOG(MIDILOG(5), "SYSEX message done, midi ready again."); + ret = midiOutUnprepareHeader(MidiOut, MidiHeader, sizeof(*MidiHeader)); + ismidiready = 1; + } } void bx_sound_windows_c::checkwaveready() { @@ -503,25 +497,23 @@ void bx_sound_windows_c::checkwaveready() UINT ret; // clean up all finished buffers and mark them as available - for (bufnum=tailfull; - (bufnum != tailplay) && - ( (WaveHeader[bufnum]->dwFlags & WHDR_DONE) != 0); - bufnum++, bufnum &= BX_SOUND_WINDOWS_NMASK) - { - WRITELOG( WAVELOG(5), "Buffer %d done.", bufnum); - - ret = waveOutUnprepareHeader(WaveOut, WaveHeader[bufnum], sizeof(*WaveHeader[bufnum])); - } + for (bufnum=tailfull; (bufnum != tailplay) && + ((WaveHeader[bufnum]->dwFlags & WHDR_DONE) != 0); + bufnum++, bufnum &= BX_SOUND_WINDOWS_NMASK) + { + WRITELOG(WAVELOG(5), "Buffer %d done.", bufnum); + ret = waveOutUnprepareHeader(WaveOut, WaveHeader[bufnum], sizeof(*WaveHeader[bufnum])); + } tailfull = bufnum; // enable gathering data if a buffer is available - if ( ( (head + 2) & BX_SOUND_WINDOWS_NMASK) != tailfull ) - { - WRITELOG( WAVELOG(5), "Buffer status: Head %d, TailFull %d, TailPlay %d. Ready.", - head, tailfull, tailplay); - iswaveready = 1; - } + if (((head + 2) & BX_SOUND_WINDOWS_NMASK) != tailfull) + { + WRITELOG(WAVELOG(5), "Buffer status: Head %d, TailFull %d, TailPlay %d. Ready.", + head, tailfull, tailplay); + iswaveready = 1; + } } #endif // defined(WIN32) diff --git a/bochs/iodev/unmapped.cc b/bochs/iodev/unmapped.cc index 516b6cf58..1f8138c9b 100644 --- a/bochs/iodev/unmapped.cc +++ b/bochs/iodev/unmapped.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: unmapped.cc,v 1.26 2008-01-29 17:34:52 sshwarts Exp $ +// $Id: unmapped.cc,v 1.27 2008-02-15 22:05:43 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -23,9 +23,9 @@ // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// ///////////////////////////////////////////////////////////////////////// - // Define BX_PLUGGABLE in files that can be compiled into plugins. For // platforms that require a special tag on exported symbols, BX_PLUGGABLE // is used to know when we are exporting symbols and when we are importing. @@ -263,7 +263,7 @@ void bx_unmapped_c::write(Bit32u address, Bit32u value, unsigned io_len) case 0xfedc: bx_dbg.debugger = (value > 0); - BX_DEBUG(( "DEBUGGER = %u", (unsigned) bx_dbg.debugger)); + BX_DEBUG(("DEBUGGER = %u", (unsigned) bx_dbg.debugger)); break; default: diff --git a/bochs/iodev/vga.cc b/bochs/iodev/vga.cc index f0dc2e1a9..cc421a991 100644 --- a/bochs/iodev/vga.cc +++ b/bochs/iodev/vga.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: vga.cc,v 1.150 2008-01-28 21:52:09 vruppert Exp $ +// $Id: vga.cc,v 1.151 2008-02-15 22:05:43 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2002 MandrakeSoft S.A. @@ -23,7 +23,7 @@ // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - +///////////////////////////////////////////////////////////////////////// // Define BX_PLUGGABLE in files that can be compiled into plugins. For // platforms that require a special tag on exported symbols, BX_PLUGGABLE @@ -34,7 +34,6 @@ #define LOG_THIS theVga-> -// (mch) #define VGA_TRACE_FEATURE // Only reference the array if the tile numbers are within the bounds @@ -266,7 +265,7 @@ void bx_vga_c::init(void) bx_gui->init(argc, argv, BX_VGA_THIS s.x_tilesize, BX_VGA_THIS s.y_tilesize); for (i = 1; i < (unsigned)argc; i++) { - if ( argv[i] != NULL ) + if (argv[i] != NULL) { free(argv[i]); argv[i] = NULL; @@ -565,7 +564,7 @@ void bx_vga_c::determine_screen_dimensions(unsigned *piHeight, unsigned *piWidth { int ai[0x20]; int i,h,v; - for ( i = 0 ; i < 0x20 ; i++ ) + for (i = 0 ; i < 0x20 ; i++) ai[i] = BX_VGA_THIS s.CRTC.reg[i]; h = (ai[1] + 1) * 8; @@ -576,7 +575,7 @@ void bx_vga_c::determine_screen_dimensions(unsigned *piHeight, unsigned *piWidth *piWidth = 640; *piHeight = 480; - if ( BX_VGA_THIS s.CRTC.reg[6] == 0xBF ) + if (BX_VGA_THIS s.CRTC.reg[6] == 0xBF) { if (BX_VGA_THIS s.CRTC.reg[23] == 0xA3 && BX_VGA_THIS s.CRTC.reg[20] == 0x40 && @@ -654,26 +653,26 @@ Bit32u bx_vga_c::read(Bit32u address, unsigned io_len) ret16 |= (bx_vga_c::read(address+1, 1) << 8; #endif RETURN(ret16); - } + } #ifdef __OS2__ - if ( bx_options.videomode == BX_VIDEO_DIRECT ) + if (bx_options.videomode == BX_VIDEO_DIRECT) { return _inp(address); } #endif #if !defined(VGA_TRACE_FEATURE) - BX_DEBUG(("io read from 0x%04x", (unsigned) address)); + BX_DEBUG(("io read from 0x%04x", (unsigned) address)); #endif - if ( (address >= 0x03b0) && (address <= 0x03bf) && - (BX_VGA_THIS s.misc_output.color_emulation) ) { - RETURN(0xff); + if ((address >= 0x03b0) && (address <= 0x03bf) && + (BX_VGA_THIS s.misc_output.color_emulation)) { + RETURN(0xff); } - if ( (address >= 0x03d0) && (address <= 0x03df) && - (BX_VGA_THIS s.misc_output.color_emulation==0) ) { - RETURN(0xff); + if ((address >= 0x03d0) && (address <= 0x03df) && + (BX_VGA_THIS s.misc_output.color_emulation==0)) { + RETURN(0xff); } switch (address) { @@ -690,7 +689,7 @@ Bit32u bx_vga_c::read(Bit32u address, unsigned io_len) // using 72 Hz vertical frequency usec = bx_pc_system.time_usec(); - switch ( ( BX_VGA_THIS s.misc_output.vert_sync_pol << 1) | BX_VGA_THIS s.misc_output.horiz_sync_pol ) + switch ((BX_VGA_THIS s.misc_output.vert_sync_pol << 1) | BX_VGA_THIS s.misc_output.horiz_sync_pol) { case 0: vertres = 200; break; case 1: vertres = 400; break; @@ -810,7 +809,7 @@ Bit32u bx_vga_c::read(Bit32u address, unsigned io_len) BX_DEBUG(("io read 0x3c5: index %u unhandled", (unsigned) BX_VGA_THIS s.sequencer.index)); RETURN(0); - } + } break; case 0x03c6: /* PEL mask ??? */ @@ -895,7 +894,7 @@ Bit32u bx_vga_c::read(Bit32u address, unsigned io_len) case 5: /* Mode */ retval = ((BX_VGA_THIS s.graphics_ctrl.shift_reg & 0x03) << 5) | - ((BX_VGA_THIS s.graphics_ctrl.odd_even & 0x01 ) << 4) | + ((BX_VGA_THIS s.graphics_ctrl.odd_even & 0x01) << 4) | ((BX_VGA_THIS s.graphics_ctrl.read_mode & 0x01) << 3) | ((BX_VGA_THIS s.graphics_ctrl.write_mode & 0x03) << 0); @@ -906,7 +905,7 @@ Bit32u bx_vga_c::read(Bit32u address, unsigned io_len) break; case 6: /* Miscellaneous */ retval = - ((BX_VGA_THIS s.graphics_ctrl.memory_mapping & 0x03 ) << 2) | + ((BX_VGA_THIS s.graphics_ctrl.memory_mapping & 0x03) << 2) | ((BX_VGA_THIS s.graphics_ctrl.odd_even & 0x01) << 1) | ((BX_VGA_THIS s.graphics_ctrl.graphics_alpha & 0x01) << 0); RETURN(retval); @@ -947,13 +946,13 @@ Bit32u bx_vga_c::read(Bit32u address, unsigned io_len) } #if defined(VGA_TRACE_FEATURE) - read_return: - if (io_len == 1) { - BX_DEBUG(("8-bit read from 0x%04x = 0x%02x", (unsigned) address, ret)); - } else { - BX_DEBUG(("16-bit read from 0x%04x = 0x%04x", (unsigned) address, ret)); - } - return ret; +read_return: + if (io_len == 1) { + BX_DEBUG(("8-bit read from 0x%04x = 0x%02x", (unsigned) address, ret)); + } else { + BX_DEBUG(("16-bit read from 0x%04x = 0x%04x", (unsigned) address, ret)); + } + return ret; #endif } #if defined(VGA_TRACE_FEATURE) @@ -994,16 +993,16 @@ void bx_vga_c::write(Bit32u address, Bit32u value, unsigned io_len, bx_bool no_l #if defined(VGA_TRACE_FEATURE) if (!no_log) - switch (io_len) { - case 1: - BX_DEBUG(("8-bit write to %04x = %02x", (unsigned)address, (unsigned)value)); - break; - case 2: - BX_DEBUG(("16-bit write to %04x = %04x", (unsigned)address, (unsigned)value)); - break; - default: - BX_PANIC(("Weird VGA write size")); - } + switch (io_len) { + case 1: + BX_DEBUG(("8-bit write to %04x = %02x", (unsigned)address, (unsigned)value)); + break; + case 2: + BX_DEBUG(("16-bit write to %04x = %04x", (unsigned)address, (unsigned)value)); + break; + default: + BX_PANIC(("Weird VGA write size")); + } #else if (io_len == 1) { BX_DEBUG(("io write to 0x%04x = 0x%02x", (unsigned) address, @@ -1023,18 +1022,18 @@ void bx_vga_c::write(Bit32u address, Bit32u value, unsigned io_len, bx_bool no_l } #ifdef __OS2__ - if ( bx_options.videomode == BX_VIDEO_DIRECT ) + if (bx_options.videomode == BX_VIDEO_DIRECT) { _outp(address,value); return; } #endif - if ( (address >= 0x03b0) && (address <= 0x03bf) && - (BX_VGA_THIS s.misc_output.color_emulation) ) + if ((address >= 0x03b0) && (address <= 0x03bf) && + (BX_VGA_THIS s.misc_output.color_emulation)) return; - if ( (address >= 0x03d0) && (address <= 0x03df) && - (BX_VGA_THIS s.misc_output.color_emulation==0) ) + if ((address >= 0x03d0) && (address <= 0x03df) && + (BX_VGA_THIS s.misc_output.color_emulation==0)) return; switch (address) { @@ -1878,8 +1877,7 @@ void bx_vga_c::update(void) BX_VGA_THIS s.last_bpp = 8; } - switch ( BX_VGA_THIS s.graphics_ctrl.shift_reg ) { - + switch (BX_VGA_THIS s.graphics_ctrl.shift_reg) { case 0: Bit8u attribute, palette_reg_val, DAC_regno; unsigned long line_compare; @@ -2035,7 +2033,7 @@ void bx_vga_c::update(void) // (format for VGA mode 13 hex) case 3: // FIXME: is this really the same ??? - if ( BX_VGA_THIS s.sequencer.chain_four ) { + if (BX_VGA_THIS s.sequencer.chain_four) { unsigned long pixely, pixelx, plane; if (BX_VGA_THIS s.misc_output.select_high_bank != 1) @@ -2054,14 +2052,14 @@ void bx_vga_c::update(void) (pixely * BX_VGA_THIS s.line_offset) + (pixelx & ~0x03); color = BX_VGA_THIS s.memory[byte_offset]; BX_VGA_THIS s.tile[r*X_TILESIZE + c] = color; - } } + } SET_TILE_UPDATED (xti, yti, 0); bx_gui->graphics_tile_update(BX_VGA_THIS s.tile, xc, yc); - } } } } + } else { // chain_four == 0, modeX unsigned long pixely, pixelx, plane; @@ -2080,24 +2078,24 @@ void bx_vga_c::update(void) + (pixelx >> 2); color = BX_VGA_THIS s.memory[start_addr + byte_offset]; BX_VGA_THIS s.tile[r*X_TILESIZE + c] = color; - } } + } SET_TILE_UPDATED (xti, yti, 0); bx_gui->graphics_tile_update(BX_VGA_THIS s.tile, xc, yc); - } - } + } } - } + } + } break; // case 2 default: BX_PANIC(("update: shift_reg == %u", (unsigned) - BX_VGA_THIS s.graphics_ctrl.shift_reg )); - } + BX_VGA_THIS s.graphics_ctrl.shift_reg)); + } BX_VGA_THIS s.vga_mem_updated = 0; return; - } + } else { // text mode unsigned long start_address; @@ -2275,7 +2273,7 @@ Bit8u bx_vga_c::mem_read(Bit32u addr) offset = addr & 0x1FFFF; } - if ( BX_VGA_THIS s.sequencer.chain_four ) { + if (BX_VGA_THIS s.sequencer.chain_four) { // Mode 13h: 320 x 200 256 color mode: chained pixel representation return BX_VGA_THIS s.memory[(offset & ~0x03) + (offset % 4)*65536]; } @@ -2382,7 +2380,7 @@ void bx_vga_c::mem_write(Bit32u addr, Bit8u value) #endif #if defined(VGA_TRACE_FEATURE) -// BX_DEBUG(("8-bit memory write to %08x = %02x", addr, value)); +//BX_DEBUG(("8-bit memory write to %08x = %02x", addr, value)); #endif #ifdef __OS2__ @@ -2413,7 +2411,7 @@ void bx_vga_c::mem_write(Bit32u addr, Bit8u value) break; default: // 0xA0000 .. 0xBFFFF offset = addr - 0xA0000; - } + } start_addr = (BX_VGA_THIS s.CRTC.reg[0x0c] << 8) | BX_VGA_THIS s.CRTC.reg[0x0d]; @@ -2463,15 +2461,14 @@ void bx_vga_c::mem_write(Bit32u addr, Bit8u value) } return; /* CGA 320x200x4 / 640x200x2 end */ - } + } else if (BX_VGA_THIS s.graphics_ctrl.memory_mapping != 1) { - BX_PANIC(("mem_write: graphics: mapping = %u", (unsigned) BX_VGA_THIS s.graphics_ctrl.memory_mapping)); return; - } + } - if ( BX_VGA_THIS s.sequencer.chain_four ) { + if (BX_VGA_THIS s.sequencer.chain_four) { unsigned x_tileno, y_tileno; // 320 x 200 256 color mode: chained pixel representation @@ -2624,7 +2621,7 @@ void bx_vga_c::mem_write(Bit32u addr, Bit8u value) break; case 1: /* write mode 1 */ - for (i=0; i<4; i++ ) { + for (i=0; i<4; i++) { new_val[i] = BX_VGA_THIS s.graphics_ctrl.latch[i]; } break; @@ -2856,8 +2853,8 @@ void bx_vga_c::dump_status(void) (unsigned) BX_VGA_THIS s.misc_output.horiz_sync_pol); dbg_printf("s.misc_output.vert_sync_pol = %u ", (unsigned) BX_VGA_THIS s.misc_output.vert_sync_pol); - switch ( (BX_VGA_THIS s.misc_output.vert_sync_pol << 1) | - BX_VGA_THIS s.misc_output.horiz_sync_pol ) { + switch ((BX_VGA_THIS s.misc_output.vert_sync_pol << 1) | + BX_VGA_THIS s.misc_output.horiz_sync_pol) { case 1: dbg_printf("(400 lines)\n"); break; case 2: dbg_printf("(350 lines)\n"); break; case 3: dbg_printf("(480 lines)\n"); break; @@ -3045,8 +3042,7 @@ Bit32u bx_vga_c::vbe_read_handler(void *this_ptr, Bit32u address, unsigned io_le { #if !BX_USE_VGA_SMF bx_vga_c *class_ptr = (bx_vga_c *) this_ptr; - - return( class_ptr->vbe_read(address, io_len) ); + return class_ptr->vbe_read(address, io_len); } Bit32u bx_vga_c::vbe_read(Bit32u address, unsigned io_len) @@ -3187,11 +3183,11 @@ Bit32u bx_vga_c::vbe_write(Bit32u address, Bit32u value, unsigned io_len) { case VBE_DISPI_INDEX_ID: // Display Interface ID check { - if ( (value == VBE_DISPI_ID0) || - (value == VBE_DISPI_ID1) || - (value == VBE_DISPI_ID2) || - (value == VBE_DISPI_ID3) || - (value == VBE_DISPI_ID4) ) + if ((value == VBE_DISPI_ID0) || + (value == VBE_DISPI_ID1) || + (value == VBE_DISPI_ID2) || + (value == VBE_DISPI_ID3) || + (value == VBE_DISPI_ID4)) { // allow backwards compatible with previous dispi bioses BX_VGA_THIS s.vbe_cur_dispi=value; diff --git a/bochs/iodev/virt_timer.cc b/bochs/iodev/virt_timer.cc index a68b91695..5e9df7a47 100644 --- a/bochs/iodev/virt_timer.cc +++ b/bochs/iodev/virt_timer.cc @@ -1,5 +1,5 @@ //////////////////////////////////////////////////////////////////////// -// $Id: virt_timer.cc,v 1.36 2008-01-26 22:24:03 sshwarts Exp $ +// $Id: virt_timer.cc,v 1.37 2008-02-15 22:05:43 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2002 MandrakeSoft S.A. @@ -23,6 +23,7 @@ // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +//////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////// // @@ -127,8 +128,8 @@ bx_virt_timer_c bx_virt_timer; //Conversion between emulated useconds and optionally realtime ticks. -#define TICKS_TO_USEC(a) ( ((a)*usec_per_second)/ticks_per_second ) -#define USEC_TO_TICKS(a) ( ((a)*ticks_per_second)/usec_per_second ) +#define TICKS_TO_USEC(a) (((a)*usec_per_second)/ticks_per_second) +#define USEC_TO_TICKS(a) (((a)*ticks_per_second)/usec_per_second) bx_virt_timer_c::bx_virt_timer_c() { @@ -390,8 +391,8 @@ void bx_virt_timer_c::setup(void) void bx_virt_timer_c::init(void) { - if ( (SIM->get_param_enum(BXPN_CLOCK_SYNC)->get()!=BX_CLOCK_SYNC_REALTIME) - && (SIM->get_param_enum(BXPN_CLOCK_SYNC)->get()!=BX_CLOCK_SYNC_BOTH) ) + if ((SIM->get_param_enum(BXPN_CLOCK_SYNC)->get()!=BX_CLOCK_SYNC_REALTIME) && + (SIM->get_param_enum(BXPN_CLOCK_SYNC)->get()!=BX_CLOCK_SYNC_BOTH)) virtual_timers_realtime = 0; else virtual_timers_realtime = 1; diff --git a/bochs/iodev/virt_timer.h b/bochs/iodev/virt_timer.h index e2613dfae..b498f001e 100644 --- a/bochs/iodev/virt_timer.h +++ b/bochs/iodev/virt_timer.h @@ -1,5 +1,5 @@ //////////////////////////////////////////////////////////////////////// -// $Id: virt_timer.h,v 1.14 2007-09-28 19:52:08 sshwarts Exp $ +// $Id: virt_timer.h,v 1.15 2008-02-15 22:05:43 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2002 MandrakeSoft S.A. @@ -34,9 +34,7 @@ #define BX_MAX_VIRTUAL_TIME (0x7fffffff) -class bx_virt_timer_c : public logfunctions -{ - +class bx_virt_timer_c : public logfunctions { private: struct { @@ -122,21 +120,21 @@ public: //Register a timer handler to go off after a given interval. //Register a timer handler to go off with a periodic interval. - int register_timer( void *this_ptr, bx_timer_handler_t handler, + int register_timer(void *this_ptr, bx_timer_handler_t handler, Bit32u useconds, bx_bool continuous, bx_bool active, const char *id); //unregister a previously registered timer. bx_bool unregisterTimer(unsigned timerID); - void start_timers(void); + void start_timers(void); //activate a deactivated but registered timer. - void activate_timer( unsigned timer_index, Bit32u useconds, - bx_bool continuous ); + void activate_timer(unsigned timer_index, Bit32u useconds, + bx_bool continuous); //deactivate (but don't unregister) a currently registered timer. - void deactivate_timer( unsigned timer_index ); + void deactivate_timer(unsigned timer_index); //Timer handler passed to pc_system diff --git a/bochs/logio.cc b/bochs/logio.cc index 7c64805a7..61a5455a3 100644 --- a/bochs/logio.cc +++ b/bochs/logio.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: logio.cc,v 1.66 2008-02-15 19:03:53 sshwarts Exp $ +// $Id: logio.cc,v 1.67 2008-02-15 22:05:37 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -161,7 +161,7 @@ void iofunctions::set_log_prefix(const char* prefix) strcpy(logprefix, prefix); } -// iofunctions::out( class, level, prefix, fmt, ap) +// iofunctions::out(class, level, prefix, fmt, ap) // DO NOT nest out() from ::info() and the like. // fmt and ap retained for direct printinf from iofunctions only! diff --git a/bochs/main.cc b/bochs/main.cc index ec8142fae..e7268b83f 100644 --- a/bochs/main.cc +++ b/bochs/main.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: main.cc,v 1.373 2008-02-15 19:03:53 sshwarts Exp $ +// $Id: main.cc,v 1.374 2008-02-15 22:05:37 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2002 MandrakeSoft S.A. @@ -185,7 +185,7 @@ static void carbonFatalDialog(const char *error, const char *exposition) cfExposition, /* can be NULL */ &alertParam, /* can be NULL */ &alertDialog); - RunStandardAlert( alertDialog, NULL, &index); + RunStandardAlert(alertDialog, NULL, &index); // Cleanup CFRelease(cfError); if(cfExposition != NULL) { CFRelease(cfExposition); } @@ -429,7 +429,7 @@ int RedirectIOToConsole() // redirect unbuffered STDERR to the console lStdHandle = (long)GetStdHandle(STD_ERROR_HANDLE); hConHandle = _open_osfhandle(lStdHandle, _O_TEXT); - fp = _fdopen( hConHandle, "w" ); + fp = _fdopen(hConHandle, "w"); *stderr = *fp; setvbuf(stderr, NULL, _IONBF, 0); return 1; @@ -654,7 +654,7 @@ int bx_init_main(int argc, char *argv[]) // our plugins into true frameworks and bundles either mainBundle = CFBundleGetMainBundle(); BX_ASSERT(mainBundle != NULL); - libDir = CFBundleCopyAuxiliaryExecutableURL( mainBundle, CFSTR("lib")); + libDir = CFBundleCopyAuxiliaryExecutableURL(mainBundle, CFSTR("lib")); BX_ASSERT(libDir != NULL); // translate this to a unix style full path if(!CFURLGetFileSystemRepresentation(libDir, true, (UInt8 *)libDirPath, MAXPATHLEN)) diff --git a/bochs/memory/misc_mem.cc b/bochs/memory/misc_mem.cc index 7c2ad2306..0dba4e096 100644 --- a/bochs/memory/misc_mem.cc +++ b/bochs/memory/misc_mem.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: misc_mem.cc,v 1.109 2008-02-03 20:27:06 sshwarts Exp $ +// $Id: misc_mem.cc,v 1.110 2008-02-15 22:05:43 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2002 MandrakeSoft S.A. @@ -90,7 +90,7 @@ void BX_MEM_C::init_memory(Bit32u memsize) { unsigned idx; - BX_DEBUG(("Init $Id: misc_mem.cc,v 1.109 2008-02-03 20:27:06 sshwarts Exp $")); + BX_DEBUG(("Init $Id: misc_mem.cc,v 1.110 2008-02-15 22:05:43 sshwarts Exp $")); alloc_vector_aligned(memsize+ BIOSROMSZ + EXROMSIZE + 4096, BX_MEM_VECTOR_ALIGN); BX_MEM_THIS len = memsize; @@ -187,13 +187,13 @@ void BX_MEM_C::load_ROM(const char *path, bx_phy_address romaddress, Bit8u type) if (*path == '\0') { if (type == 2) { - BX_PANIC(( "ROM: Optional ROM image undefined")); + BX_PANIC(("ROM: Optional ROM image undefined")); } else if (type == 1) { - BX_PANIC(( "ROM: VGA BIOS image undefined")); + BX_PANIC(("ROM: VGA BIOS image undefined")); } else { - BX_PANIC(( "ROM: System BIOS image undefined")); + BX_PANIC(("ROM: System BIOS image undefined")); } return; } @@ -205,20 +205,20 @@ void BX_MEM_C::load_ROM(const char *path, bx_phy_address romaddress, Bit8u type) ); if (fd < 0) { if (type < 2) { - BX_PANIC(( "ROM: couldn't open ROM image file '%s'.", path)); + BX_PANIC(("ROM: couldn't open ROM image file '%s'.", path)); } else { - BX_ERROR(( "ROM: couldn't open ROM image file '%s'.", path)); + BX_ERROR(("ROM: couldn't open ROM image file '%s'.", path)); } return; } ret = fstat(fd, &stat_buf); if (ret) { if (type < 2) { - BX_PANIC(( "ROM: couldn't stat ROM image file '%s'.", path)); + BX_PANIC(("ROM: couldn't stat ROM image file '%s'.", path)); } else { - BX_ERROR(( "ROM: couldn't stat ROM image file '%s'.", path)); + BX_ERROR(("ROM: couldn't stat ROM image file '%s'.", path)); } return; } @@ -289,7 +289,7 @@ void BX_MEM_C::load_ROM(const char *path, bx_phy_address romaddress, Bit8u type) while (size > 0) { ret = read(fd, (bx_ptr_t) &BX_MEM_THIS rom[offset], size); if (ret <= 0) { - BX_PANIC(( "ROM: read failed on BIOS image: '%s'",path)); + BX_PANIC(("ROM: read failed on BIOS image: '%s'",path)); } size -= ret; offset += ret; @@ -304,9 +304,9 @@ void BX_MEM_C::load_ROM(const char *path, bx_phy_address romaddress, Bit8u type) } if (checksum != 0) { if (type == 1) { - BX_PANIC(( "ROM: checksum error in VGABIOS image: '%s'", path)); + BX_PANIC(("ROM: checksum error in VGABIOS image: '%s'", path)); } else if (is_bochs_bios) { - BX_ERROR(( "ROM: checksum error in BIOS image: '%s'", path)); + BX_ERROR(("ROM: checksum error in BIOS image: '%s'", path)); } } } @@ -323,7 +323,7 @@ void BX_MEM_C::load_RAM(const char *path, bx_phy_address ramaddress, Bit8u type) unsigned long size, offset; if (*path == '\0') { - BX_PANIC(( "RAM: Optional RAM image undefined")); + BX_PANIC(("RAM: Optional RAM image undefined")); return; } // read in RAM BIOS image file @@ -333,12 +333,12 @@ void BX_MEM_C::load_RAM(const char *path, bx_phy_address ramaddress, Bit8u type) #endif ); if (fd < 0) { - BX_PANIC(( "RAM: couldn't open RAM image file '%s'.", path)); + BX_PANIC(("RAM: couldn't open RAM image file '%s'.", path)); return; } ret = fstat(fd, &stat_buf); if (ret) { - BX_PANIC(( "RAM: couldn't stat RAM image file '%s'.", path)); + BX_PANIC(("RAM: couldn't stat RAM image file '%s'.", path)); return; } @@ -348,7 +348,7 @@ void BX_MEM_C::load_RAM(const char *path, bx_phy_address ramaddress, Bit8u type) while (size > 0) { ret = read(fd, (bx_ptr_t) &BX_MEM_THIS vector[offset], size); if (ret <= 0) { - BX_PANIC(( "RAM: read failed on RAM image: '%s'",path)); + BX_PANIC(("RAM: read failed on RAM image: '%s'",path)); } size -= ret; offset += ret; @@ -362,7 +362,7 @@ void BX_MEM_C::load_RAM(const char *path, bx_phy_address ramaddress, Bit8u type) #endif // #if BX_PROVIDE_CPU_MEMORY -#if ( BX_DEBUGGER || BX_DISASM || BX_GDBSTUB) +#if (BX_DEBUGGER || BX_DISASM || BX_GDBSTUB) bx_bool BX_MEM_C::dbg_fetch_mem(BX_CPU_C *cpu, bx_phy_address addr, unsigned len, Bit8u *buf) { bx_bool ret = 1; @@ -576,7 +576,7 @@ Bit8u *BX_MEM_C::getHostMemAddr(BX_CPU_C *cpu, bx_phy_address a20Addr, unsigned } else { - return( (Bit8u *) &BX_MEM_THIS rom[(a20Addr & EXROM_MASK) + BIOSROMSZ]); + return((Bit8u *) &BX_MEM_THIS rom[(a20Addr & EXROM_MASK) + BIOSROMSZ]); } } else if (a20Addr >= (bx_phy_address)~BIOS_MASK) diff --git a/bochs/pc_system.cc b/bochs/pc_system.cc index e6de49942..798f221cd 100644 --- a/bochs/pc_system.cc +++ b/bochs/pc_system.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: pc_system.cc,v 1.68 2007-11-01 18:03:48 sshwarts Exp $ +// $Id: pc_system.cc,v 1.69 2008-02-15 22:05:38 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2002 MandrakeSoft S.A. @@ -258,7 +258,7 @@ void bx_pc_system_c::register_state(void) // Bochs internal timer delivery framework features // ================================================ -int bx_pc_system_c::register_timer( void *this_ptr, void (*funct)(void *), +int bx_pc_system_c::register_timer(void *this_ptr, void (*funct)(void *), Bit32u useconds, bx_bool continuous, bx_bool active, const char *id) { // Convert useconds to number of ticks. diff --git a/bochs/plugin.cc b/bochs/plugin.cc index 00b7f2069..a70ba9e58 100644 --- a/bochs/plugin.cc +++ b/bochs/plugin.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: plugin.cc,v 1.24 2008-02-05 22:57:40 sshwarts Exp $ +// $Id: plugin.cc,v 1.25 2008-02-15 22:05:38 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // This file defines the plugin and plugin-device registration functions and @@ -34,7 +34,7 @@ void (*pluginRegisterIRQ)(unsigned irq, const char* name) = 0; void (*pluginUnregisterIRQ)(unsigned irq, const char* name) = 0; void (*pluginSetHRQ)(unsigned val) = 0; -void (*pluginSetHRQHackCallback)( void (*callback)(void) ) = 0; +void (*pluginSetHRQHackCallback)(void (*callback)(void)) = 0; int (*pluginRegisterIOReadHandler)(void *thisPtr, ioReadHandler_t callback, unsigned base, const char *name, Bit8u mask) = 0; @@ -108,7 +108,7 @@ builtinSetHRQ(unsigned val) } static void -builtinSetHRQHackCallback( void (*callback)(void) ) +builtinSetHRQHackCallback(void (*callback)(void)) { #if 0 pluginlog->panic("builtinSetHRQHackCallback called, no plugin loaded?"); @@ -122,7 +122,7 @@ builtinRegisterIOReadHandler(void *thisPtr, ioReadHandler_t callback, unsigned base, const char *name, Bit8u mask) { int ret; - BX_ASSERT (mask<8); + BX_ASSERT(mask<8); ret = bx_devices.register_io_read_handler (thisPtr, callback, base, name, mask); pluginlog->ldebug("plugin %s registered I/O read address at %04x", name, base); return ret; @@ -133,7 +133,7 @@ builtinRegisterIOWriteHandler(void *thisPtr, ioWriteHandler_t callback, unsigned base, const char *name, Bit8u mask) { int ret; - BX_ASSERT (mask<8); + BX_ASSERT(mask<8); ret = bx_devices.register_io_write_handler (thisPtr, callback, base, name, mask); pluginlog->ldebug("plugin %s registered I/O write address at %04x", name, base); return ret; @@ -144,7 +144,7 @@ builtinUnregisterIOReadHandler(void *thisPtr, ioReadHandler_t callback, unsigned base, Bit8u mask) { int ret; - BX_ASSERT (mask<8); + BX_ASSERT(mask<8); ret = bx_devices.unregister_io_read_handler (thisPtr, callback, base, mask); pluginlog->ldebug("plugin unregistered I/O read address at %04x", base); return ret; @@ -155,7 +155,7 @@ builtinUnregisterIOWriteHandler(void *thisPtr, ioWriteHandler_t callback, unsigned base, Bit8u mask) { int ret; - BX_ASSERT (mask<8); + BX_ASSERT(mask<8); ret = bx_devices.unregister_io_write_handler (thisPtr, callback, base, mask); pluginlog->ldebug("plugin unregistered I/O write address at %04x", base); return ret; @@ -166,7 +166,7 @@ builtinRegisterIOReadHandlerRange(void *thisPtr, ioReadHandler_t callback, unsigned base, unsigned end, const char *name, Bit8u mask) { int ret; - BX_ASSERT (mask<8); + BX_ASSERT(mask<8); ret = bx_devices.register_io_read_handler_range (thisPtr, callback, base, end, name, mask); pluginlog->ldebug("plugin %s registered I/O read addresses %04x to %04x", name, base, end); return ret; @@ -177,7 +177,7 @@ builtinRegisterIOWriteHandlerRange(void *thisPtr, ioWriteHandler_t callback, unsigned base, unsigned end, const char *name, Bit8u mask) { int ret; - BX_ASSERT (mask<8); + BX_ASSERT(mask<8); ret = bx_devices.register_io_write_handler_range (thisPtr, callback, base, end, name, mask); pluginlog->ldebug("plugin %s registered I/O write addresses %04x to %04x", name, base, end); return ret; @@ -188,7 +188,7 @@ builtinUnregisterIOReadHandlerRange(void *thisPtr, ioReadHandler_t callback, unsigned begin, unsigned end, Bit8u mask) { int ret; - BX_ASSERT (mask<8); + BX_ASSERT(mask<8); ret = bx_devices.unregister_io_read_handler_range (thisPtr, callback, begin, end, mask); pluginlog->ldebug("plugin unregistered I/O read addresses %04x to %04x", begin, end); return ret; @@ -199,7 +199,7 @@ builtinUnregisterIOWriteHandlerRange(void *thisPtr, ioWriteHandler_t callback, unsigned begin, unsigned end, Bit8u mask) { int ret; - BX_ASSERT (mask<8); + BX_ASSERT(mask<8); ret = bx_devices.unregister_io_write_handler_range (thisPtr, callback, begin, end, mask); pluginlog->ldebug("plugin unregistered I/O write addresses %04x to %04x", begin, end); return ret; @@ -209,7 +209,7 @@ builtinUnregisterIOWriteHandlerRange(void *thisPtr, ioWriteHandler_t callback, builtinRegisterDefaultIOReadHandler(void *thisPtr, ioReadHandler_t callback, const char *name, Bit8u mask) { - BX_ASSERT (mask<8); + BX_ASSERT(mask<8); bx_devices.register_default_io_read_handler (thisPtr, callback, name, mask); pluginlog->ldebug("plugin %s registered default I/O read ", name); return 0; @@ -219,7 +219,7 @@ builtinRegisterDefaultIOReadHandler(void *thisPtr, ioReadHandler_t callback, builtinRegisterDefaultIOWriteHandler(void *thisPtr, ioWriteHandler_t callback, const char *name, Bit8u mask) { - BX_ASSERT (mask<8); + BX_ASSERT(mask<8); bx_devices.register_default_io_write_handler (thisPtr, callback, name, mask); pluginlog->ldebug("plugin %s registered default I/O write ", name); return 0; @@ -247,195 +247,181 @@ builtinActivateTimer(unsigned id, Bit32u usec, bx_bool continuous) /* Plugin initialization / deinitialization */ /************************************************************************/ - void -plugin_init_all (void) +void plugin_init_all (void) { - plugin_t *plugin; + plugin_t *plugin; - pluginlog->info("Initializing plugins"); + pluginlog->info("Initializing plugins"); - for (plugin = plugins; plugin; plugin = plugin->next) + for (plugin = plugins; plugin; plugin = plugin->next) + { + char *arg_ptr = plugin->args; + + /* process the command line */ + plugin->argc = 0; + while (plugin->argc < MAX_ARGC) { - char *arg_ptr = plugin->args; + while (*arg_ptr && isspace (*arg_ptr)) + arg_ptr++; - /* process the command line */ - plugin->argc = 0; - while (plugin->argc < MAX_ARGC) - { - while (*arg_ptr && isspace (*arg_ptr)) - arg_ptr++; + if (!*arg_ptr) break; + plugin->argv[plugin->argc++] = arg_ptr; - if (!*arg_ptr) - break; - plugin->argv[plugin->argc++] = arg_ptr; + while (*arg_ptr && !isspace (*arg_ptr)) + arg_ptr++; - while (*arg_ptr && !isspace (*arg_ptr)) - arg_ptr++; - - if (!*arg_ptr) - break; - *arg_ptr++ = '\0'; - } - - /* initialize the plugin */ - if (plugin->plugin_init (plugin, plugin->type, plugin->argc, plugin->argv)) - { - pluginlog->panic("Plugin initialization failed for %s", plugin->name); - plugin_abort(); - } - - plugin->initialized = 1; + if (!*arg_ptr) break; + *arg_ptr++ = '\0'; } - return; + /* initialize the plugin */ + if (plugin->plugin_init (plugin, plugin->type, plugin->argc, plugin->argv)) + { + pluginlog->panic("Plugin initialization failed for %s", plugin->name); + plugin_abort(); + } + + plugin->initialized = 1; + } } -void -plugin_init_one(plugin_t *plugin) +void plugin_init_one(plugin_t *plugin) { - char *arg_ptr = plugin->args; + char *arg_ptr = plugin->args; - /* process the command line */ - plugin->argc = 0; - while (plugin->argc < MAX_ARGC) - { - while (*arg_ptr && isspace (*arg_ptr)) - arg_ptr++; + /* process the command line */ + plugin->argc = 0; + while (plugin->argc < MAX_ARGC) + { + while (*arg_ptr && isspace (*arg_ptr)) + arg_ptr++; - if (!*arg_ptr) - break; - plugin->argv[plugin->argc++] = arg_ptr; + if (!*arg_ptr) break; + plugin->argv[plugin->argc++] = arg_ptr; - while (*arg_ptr && !isspace (*arg_ptr)) - arg_ptr++; + while (*arg_ptr && !isspace (*arg_ptr)) + arg_ptr++; - if (!*arg_ptr) - break; - *arg_ptr++ = '\0'; - } + if (!*arg_ptr) break; + *arg_ptr++ = '\0'; + } - /* initialize the plugin */ - if (plugin->plugin_init (plugin, plugin->type, plugin->argc, plugin->argv)) - { - pluginlog->info("Plugin initialization failed for %s", plugin->name); - plugin_abort(); - } + /* initialize the plugin */ + if (plugin->plugin_init (plugin, plugin->type, plugin->argc, plugin->argv)) + { + pluginlog->info("Plugin initialization failed for %s", plugin->name); + plugin_abort(); + } - plugin->initialized = 1; + plugin->initialized = 1; } plugin_t *plugin_unload(plugin_t *plugin) { - plugin_t *dead_plug; + plugin_t *dead_plug; - if (plugin->initialized) - plugin->plugin_fini(); + if (plugin->initialized) + plugin->plugin_fini(); - lt_dlclose(plugin->handle); - delete [] plugin->name; + lt_dlclose(plugin->handle); + delete [] plugin->name; - dead_plug = plugin; - plugin = plugin->next; - free(dead_plug); + dead_plug = plugin; + plugin = plugin->next; + free(dead_plug); - return plugin; + return plugin; } - void plugin_fini_all (void) { - plugin_t *plugin; + plugin_t *plugin; - for (plugin = plugins; plugin; plugin = plugin_unload(plugin)); - - return; + for (plugin = plugins; plugin; plugin = plugin_unload(plugin)); } void plugin_load(char *name, char *args, plugintype_t type) { - plugin_t *plugin; + plugin_t *plugin; - plugin = (plugin_t *)malloc (sizeof(plugin_t)); - if (!plugin) - { - BX_PANIC(("malloc plugin_t failed")); - } + plugin = (plugin_t *)malloc (sizeof(plugin_t)); + if (!plugin) + { + BX_PANIC(("malloc plugin_t failed")); + } - plugin->type = type; - plugin->name = name; - plugin->args = args; - plugin->initialized = 0; + plugin->type = type; + plugin->name = name; + plugin->args = args; + plugin->initialized = 0; - char plugin_filename[BX_PATHNAME_LEN], buf[BX_PATHNAME_LEN]; - sprintf(buf, PLUGIN_FILENAME_FORMAT, name); - sprintf(plugin_filename, "%s%s", PLUGIN_PATH, buf); + char plugin_filename[BX_PATHNAME_LEN], buf[BX_PATHNAME_LEN]; + sprintf(buf, PLUGIN_FILENAME_FORMAT, name); + sprintf(plugin_filename, "%s%s", PLUGIN_PATH, buf); - // Set context so that any devices that the plugin registers will - // be able to see which plugin created them. The registration will - // be called from either dlopen (global constructors) or plugin_init. - BX_ASSERT (current_plugin_context == NULL); - current_plugin_context = plugin; - plugin->handle = lt_dlopen (plugin_filename); - BX_INFO (("lt_dlhandle is %p", plugin->handle)); - if (!plugin->handle) - { - current_plugin_context = NULL; - BX_PANIC (("dlopen failed for module '%s': %s", name, lt_dlerror ())); - free (plugin); - return; - } - - sprintf(buf, PLUGIN_INIT_FMT_STRING, name); - plugin->plugin_init = - (int (*)(struct _plugin_t *, enum plugintype_t, int, char *[])) /* monster typecast */ - lt_dlsym (plugin->handle, buf); - if (plugin->plugin_init == NULL) { - pluginlog->panic("could not find plugin_init: %s", lt_dlerror ()); - plugin_abort (); - } - - sprintf(buf, PLUGIN_FINI_FMT_STRING, name); - plugin->plugin_fini = (void (*)(void)) lt_dlsym (plugin->handle, buf); - if (plugin->plugin_init == NULL) { - pluginlog->panic("could not find plugin_fini: %s", lt_dlerror ()); - plugin_abort (); - } - pluginlog->info("loaded plugin %s",plugin_filename); - - - /* Insert plugin at the _end_ of the plugin linked list. */ - plugin->next = NULL; - - if (!plugins) - { - /* Empty list, this become the first entry. */ - plugins = plugin; - } - else - { - /* Non-empty list. Add to end. */ - plugin_t *temp = plugins; - - while (temp->next) - temp = temp->next; - - temp->next = plugin; - } - - plugin_init_one(plugin); - - // check that context didn't change. This should only happen if we - // need a reentrant plugin_load. - BX_ASSERT (current_plugin_context == plugin); + // Set context so that any devices that the plugin registers will + // be able to see which plugin created them. The registration will + // be called from either dlopen (global constructors) or plugin_init. + BX_ASSERT(current_plugin_context == NULL); + current_plugin_context = plugin; + plugin->handle = lt_dlopen (plugin_filename); + BX_INFO(("lt_dlhandle is %p", plugin->handle)); + if (!plugin->handle) + { current_plugin_context = NULL; - + BX_PANIC(("dlopen failed for module '%s': %s", name, lt_dlerror ())); + free (plugin); return; + } + + sprintf(buf, PLUGIN_INIT_FMT_STRING, name); + plugin->plugin_init = + (int (*)(struct _plugin_t *, enum plugintype_t, int, char *[])) /* monster typecast */ + lt_dlsym (plugin->handle, buf); + if (plugin->plugin_init == NULL) { + pluginlog->panic("could not find plugin_init: %s", lt_dlerror ()); + plugin_abort (); + } + + sprintf(buf, PLUGIN_FINI_FMT_STRING, name); + plugin->plugin_fini = (void (*)(void)) lt_dlsym (plugin->handle, buf); + if (plugin->plugin_init == NULL) { + pluginlog->panic("could not find plugin_fini: %s", lt_dlerror ()); + plugin_abort(); + } + pluginlog->info("loaded plugin %s",plugin_filename); + + /* Insert plugin at the _end_ of the plugin linked list. */ + plugin->next = NULL; + + if (!plugins) + { + /* Empty list, this become the first entry. */ + plugins = plugin; + } + else + { + /* Non-empty list. Add to end. */ + plugin_t *temp = plugins; + + while (temp->next) + temp = temp->next; + + temp->next = plugin; + } + + plugin_init_one(plugin); + + // check that context didn't change. This should only happen if we + // need a reentrant plugin_load. + BX_ASSERT(current_plugin_context == plugin); + current_plugin_context = NULL; } void plugin_abort(void) { - pluginlog->panic("plugin load aborted"); + pluginlog->panic("plugin load aborted"); } #endif /* end of #if BX_PLUGINS */ @@ -490,50 +476,48 @@ plugin_startup(void) void pluginRegisterDeviceDevmodel(plugin_t *plugin, plugintype_t type, bx_devmodel_c *devmodel, const char *name) { - device_t *device; + device_t *device; - device = (device_t *)malloc (sizeof (device_t)); - if (!device) - { - pluginlog->panic("can't allocate device_t"); - } + device = (device_t *)malloc (sizeof (device_t)); + if (!device) + { + pluginlog->panic("can't allocate device_t"); + } - device->name = name; - BX_ASSERT (devmodel != NULL); - device->devmodel = devmodel; - device->plugin = plugin; // this can be NULL - device->next = NULL; + device->name = name; + BX_ASSERT(devmodel != NULL); + device->devmodel = devmodel; + device->plugin = plugin; // this can be NULL + device->next = NULL; - // Don't add every kind of device to the list. - switch (type) { - case PLUGTYPE_CORE: - // Core devices are present whether or not we are using plugins, so - // they are managed by the same code in iodev/devices.cc whether - // plugins are on or off. - free(device); - return; // Do not add core devices to the devices list. - case PLUGTYPE_OPTIONAL: - case PLUGTYPE_USER: - default: - // The plugin system will manage optional and user devices only. - break; - } + // Don't add every kind of device to the list. + switch (type) { + case PLUGTYPE_CORE: + // Core devices are present whether or not we are using plugins, so + // they are managed by the same code in iodev/devices.cc whether + // plugins are on or off. + free(device); + return; // Do not add core devices to the devices list. + case PLUGTYPE_OPTIONAL: + case PLUGTYPE_USER: + default: + // The plugin system will manage optional and user devices only. + break; + } - if (!devices) - { - /* Empty list, this become the first entry. */ - devices = device; - } - else - { - /* Non-empty list. Add to end. */ - device_t *temp = devices; + if (!devices) { + /* Empty list, this become the first entry. */ + devices = device; + } + else { + /* Non-empty list. Add to end. */ + device_t *temp = devices; - while (temp->next) - temp = temp->next; + while (temp->next) + temp = temp->next; - temp->next = device; - } + temp->next = device; + } } /************************************************************************/ @@ -542,14 +526,14 @@ void pluginRegisterDeviceDevmodel(plugin_t *plugin, plugintype_t type, bx_devmod bx_bool pluginDevicePresent(char *name) { - device_t *device; + device_t *device; - for (device = devices; device; device = device->next) - { - if (strcmp(device->name,name)==0) return true; - } + for (device = devices; device; device = device->next) + { + if (strcmp(device->name,name)==0) return true; + } - return false; + return false; } #if BX_PLUGINS @@ -592,20 +576,20 @@ void bx_unload_plugin(const char *name) void bx_init_plugins() { - device_t *device; + device_t *device; - // two loops - for (device = devices; device; device = device->next) - { - pluginlog->info("init_mem of '%s' plugin device by virtual method",device->name); - device->devmodel->init_mem(BX_MEM(0)); - } + // two loops + for (device = devices; device; device = device->next) + { + pluginlog->info("init_mem of '%s' plugin device by virtual method",device->name); + device->devmodel->init_mem(BX_MEM(0)); + } - for (device = devices; device; device = device->next) - { - pluginlog->info("init_dev of '%s' plugin device by virtual method",device->name); - device->devmodel->init(); - } + for (device = devices; device; device = device->next) + { + pluginlog->info("init_dev of '%s' plugin device by virtual method",device->name); + device->devmodel->init(); + } } /**************************************************************************/ @@ -614,12 +598,12 @@ void bx_init_plugins() void bx_reset_plugins(unsigned signal) { - device_t *device; - for (device = devices; device; device = device->next) - { - pluginlog->info("reset of '%s' plugin device by virtual method",device->name); - device->devmodel->reset(signal); - } + device_t *device; + for (device = devices; device; device = device->next) + { + pluginlog->info("reset of '%s' plugin device by virtual method",device->name); + device->devmodel->reset(signal); + } } /*******************************************************/ @@ -642,7 +626,7 @@ void bx_unload_plugins() next = device->next; free(device); device = next; - }; + } devices = NULL; } @@ -652,12 +636,12 @@ void bx_unload_plugins() void bx_plugins_register_state() { - device_t *device; - for (device = devices; device; device = device->next) - { - pluginlog->info("register state of '%s' plugin device by virtual method",device->name); - device->devmodel->register_state(); - } + device_t *device; + for (device = devices; device; device = device->next) + { + pluginlog->info("register state of '%s' plugin device by virtual method",device->name); + device->devmodel->register_state(); + } } /***************************************************************************/ @@ -666,11 +650,11 @@ void bx_plugins_register_state() void bx_plugins_after_restore_state() { - device_t *device; - for (device = devices; device; device = device->next) - { - device->devmodel->after_restore_state(); - } + device_t *device; + for (device = devices; device; device = device->next) + { + device->devmodel->after_restore_state(); + } } } diff --git a/bochs/plugin.h b/bochs/plugin.h index 2f0eac7da..c286de91c 100644 --- a/bochs/plugin.h +++ b/bochs/plugin.h @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: plugin.h,v 1.61 2008-02-05 22:57:40 sshwarts Exp $ +// $Id: plugin.h,v 1.62 2008-02-15 22:05:38 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // This file provides macros and types needed for plugins. It is based on @@ -315,24 +315,24 @@ BOCHSAPI extern void (* pluginVGASetUpdateInterval)(unsigned); BOCHSAPI extern Bit8u (* pluginVGAGetActlPaletteIdx)(Bit8u index); /* === Timer stuff === */ -BOCHSAPI extern int (*pluginRegisterTimer)(void *this_ptr, void (*funct)(void *), +BOCHSAPI extern int (*pluginRegisterTimer)(void *this_ptr, void (*funct)(void *), Bit32u useconds, bx_bool continuous, bx_bool active, const char *name); -BOCHSAPI extern void (*pluginActivateTimer)(unsigned id, Bit32u usec, bx_bool continuous); -BOCHSAPI extern void (*pluginDeactivateTimer)(unsigned id); +BOCHSAPI extern void (*pluginActivateTimer)(unsigned id, Bit32u usec, bx_bool continuous); +BOCHSAPI extern void (*pluginDeactivateTimer)(unsigned id); /* === HRQ stuff === */ -BOCHSAPI extern void (*pluginSetHRQ)(unsigned val); -BOCHSAPI extern void (*pluginSetHRQHackCallback)( void (*callback)(void) ); +BOCHSAPI extern void (*pluginSetHRQ)(unsigned val); +BOCHSAPI extern void (*pluginSetHRQHackCallback)(void (*callback)(void)); /* === PCI stuff === */ -BOCHSAPI extern bx_bool (*pluginRegisterPCIDevice)(void *this_ptr, +BOCHSAPI extern bx_bool (*pluginRegisterPCIDevice)(void *this_ptr, Bit32u (*bx_pci_read_handler)(void *, Bit8u, unsigned), void(*bx_pci_write_handler)(void *, Bit8u, Bit32u, unsigned), Bit8u *devfunc, const char *name, const char *descr); -BOCHSAPI extern Bit8u (*pluginRd_memType)(Bit32u addr); -BOCHSAPI extern Bit8u (*pluginWr_memType)(Bit32u addr); +BOCHSAPI extern Bit8u (*pluginRd_memType)(Bit32u addr); +BOCHSAPI extern Bit8u (*pluginWr_memType)(Bit32u addr); void plugin_abort(void); @@ -341,8 +341,8 @@ extern void bx_unload_plugin(const char *name); extern void bx_init_plugins(void); extern void bx_reset_plugins(unsigned); extern void bx_unload_plugins(void); -extern void bx_plugins_register_state(); -extern void bx_plugins_after_restore_state(); +extern void bx_plugins_register_state(void); +extern void bx_plugins_after_restore_state(void); // every plugin must define these, within the extern"C" block, so that // a non-mangled function symbol is available in the shared library.