|
|
1.1 ! root 1: /*********************************************************** ! 2: * UAE - The U*nix Amiga Emulator * ! 3: * * ! 4: * UAE-Control -- Emulator Control from Inside Emulation * ! 5: * (c) 1996 Tauno Taipaleenmaki <[email protected]> * ! 6: * * ! 7: * Version 0.1 * ! 8: * * ! 9: * Requires V36 or higher. Compiled with SAS/C 6.5 * ! 10: * * ! 11: * People with KS1.3 or lower should use the command line * ! 12: * version "uaectrl" * ! 13: ***********************************************************/ ! 14: #include <proto/exec.h> ! 15: #include <proto/intuition.h> ! 16: #include <proto/gadtools.h> ! 17: #include <proto/graphics.h> ! 18: #include <proto/reqtools.h> ! 19: #include <intuition/intuition.h> ! 20: #include <libraries/reqtools.h> ! 21: #include <stdio.h> ! 22: #include <string.h> ! 23: #include "uae-control.h" ! 24: #include "uae_pragmas.h" ! 25: ! 26: #define MAX_DRV_NAME 20 ! 27: ! 28: struct Library *ReqBase; ! 29: struct Library *UaeBase; ! 30: struct Window *window; ! 31: struct Screen *scr; ! 32: struct Gadget *glist; ! 33: APTR VisInfo; ! 34: ! 35: struct UAE_CONFIG config; ! 36: ! 37: struct TextAttr topaz8 = { ! 38: ( STRPTR )"topaz.font", 8, 0x00, 0x01 }; ! 39: ! 40: struct NewWindow newwindow = { ! 41: 20,20, 400,160, 0,1, ! 42: IDCMP_CLOSEWINDOW | BUTTONIDCMP | CYCLEIDCMP | INTEGERIDCMP, ! 43: WFLG_DRAGBAR | WFLG_CLOSEGADGET | WFLG_ACTIVATE | WFLG_DEPTHGADGET, ! 44: NULL,NULL,(UBYTE *)"UAE-Control v0.1",NULL,NULL, ! 45: 0,0,0,0, CUSTOMSCREEN ! 46: }; ! 47: ! 48: int setup_window(void); ! 49: void quit_program(int error, char *text); ! 50: void print_drive_status(void); ! 51: ! 52: /************************************ ! 53: * Main program * ! 54: ************************************/ ! 55: int main() ! 56: { ! 57: int quit = 0,i; ! 58: struct IntuiMessage *msg; ! 59: struct Gadget *button; ! 60: struct StringInfo *strinfo; ! 61: char buf[257]; ! 62: UWORD koodi, msgID; ! 63: ULONG classi, number; ! 64: APTR address; ! 65: ULONG CycleTags[3]; ! 66: ! 67: CycleTags[0] = GTCY_Active; ! 68: CycleTags[1] = (ULONG)&number; ! 69: CycleTags[2] = TAG_DONE; ! 70: ! 71: ReqBase = OpenLibrary("reqtools.library",0); ! 72: if (!ReqBase) { ! 73: quit_program(1, "Reqtools.library needed!"); ! 74: return(1); ! 75: } ! 76: UaeBase = OpenLibrary("uae.library",0); ! 77: if (!UaeBase) { ! 78: UaeBase = OpenLibrary("uae.library",0); ! 79: if (!UaeBase) { ! 80: quit_program(1, "Emulator not running or uae.library not installed.\n"); ! 81: return(1); ! 82: } ! 83: } ! 84: /* Read UAE configuration */ ! 85: i = GetUaeConfig( &config ); ! 86: ! 87: i = setup_window(); ! 88: if (i == 0) { ! 89: quit_program(1, "Cannot setup a window!"); ! 90: return(1); ! 91: } ! 92: while( quit == 0 ) { ! 93: WaitPort(window->UserPort); ! 94: while( msg = (struct IntuiMessage *)GT_GetIMsg(window->UserPort)) ! 95: { ! 96: classi = msg->Class; ! 97: koodi = msg->Code; ! 98: address = msg->IAddress; ! 99: if (classi == IDCMP_GADGETUP) { ! 100: msgID = ((struct Gadget *)msg->IAddress)->GadgetID; ! 101: button = (struct Gadget *)msg->IAddress; ! 102: if (button->SpecialInfo) { ! 103: strinfo = (struct StringInfo *)button->SpecialInfo; ! 104: } ! 105: } else ! 106: msgID = msg->Code; ! 107: ! 108: GT_ReplyIMsg((struct IntuiMessage *)msg); ! 109: ! 110: switch( classi ) { ! 111: case IDCMP_CLOSEWINDOW: ! 112: quit = 1; ! 113: break; ! 114: case IDCMP_GADGETUP: ! 115: switch( msgID ) { ! 116: case GAD_EXITEMU: ! 117: ExitEmu(); ! 118: break; ! 119: case GAD_EJECT_DF0: ! 120: EjectDisk(0); ! 121: GetUaeConfig( &config ); ! 122: print_drive_status(); ! 123: break; ! 124: case GAD_EJECT_DF1: ! 125: EjectDisk(1); ! 126: GetUaeConfig( &config ); ! 127: print_drive_status(); ! 128: break; ! 129: case GAD_EJECT_DF2: ! 130: EjectDisk(2); ! 131: GetUaeConfig( &config ); ! 132: print_drive_status(); ! 133: break; ! 134: case GAD_EJECT_DF3: ! 135: EjectDisk(3); ! 136: GetUaeConfig( &config ); ! 137: print_drive_status(); ! 138: break; ! 139: case GAD_SOUND: ! 140: if (config.do_output_sound) { ! 141: DisableSound(); ! 142: } else { ! 143: EnableSound(); ! 144: } ! 145: GetUaeConfig( &config ); ! 146: break; ! 147: case GAD_JOYSTICK: ! 148: if (config.do_fake_joystick) { ! 149: DisableJoystick(); ! 150: } else { ! 151: EnableJoystick(); ! 152: } ! 153: GetUaeConfig( &config ); ! 154: break; ! 155: case GAD_FRAMERATE: ! 156: SetFrameRate( strinfo->LongInt ); ! 157: GetUaeConfig( &config ); ! 158: break; ! 159: case GAD_INSERT_DF0: ! 160: i = rtGetStringA( (UBYTE *)&buf, 255, ! 161: (UBYTE *)"Disk-file name:", ! 162: NULL, TAG_DONE); ! 163: if (i) { ! 164: InsertDisk((UBYTE *)&buf, 0); ! 165: GetUaeConfig( &config ); ! 166: print_drive_status(); ! 167: } ! 168: break; ! 169: case GAD_INSERT_DF1: ! 170: i = rtGetStringA( (UBYTE *)&buf, 255, ! 171: (UBYTE *)"Disk-file name:", ! 172: NULL, TAG_DONE); ! 173: if (i) { ! 174: InsertDisk((UBYTE *)&buf, 1); ! 175: GetUaeConfig( &config ); ! 176: print_drive_status(); ! 177: } ! 178: break; ! 179: case GAD_INSERT_DF2: ! 180: i = rtGetStringA( (UBYTE *)&buf, 255, ! 181: (UBYTE *)"Disk-file name:", ! 182: NULL, TAG_DONE); ! 183: if (i) { ! 184: InsertDisk((UBYTE *)&buf, 2); ! 185: GetUaeConfig( &config ); ! 186: print_drive_status(); ! 187: } ! 188: break; ! 189: case GAD_INSERT_DF3: ! 190: i = rtGetStringA( (UBYTE *)&buf, 255, ! 191: (UBYTE *)"Disk-file name:", ! 192: NULL, TAG_DONE); ! 193: if (i) { ! 194: InsertDisk((UBYTE *)&buf, 3); ! 195: GetUaeConfig( &config ); ! 196: print_drive_status(); ! 197: } ! 198: break; ! 199: case GAD_LANGUAGE: ! 200: number = config.keyboard; ! 201: number++; ! 202: if (number == 5) ! 203: number = 0; ! 204: ChangeLanguage( number ); ! 205: GetUaeConfig( &config ); ! 206: break; ! 207: case GAD_RESET: ! 208: ColdReboot(); ! 209: break; ! 210: case GAD_DEBUG: ! 211: DebugFunc(); ! 212: break; ! 213: default: ! 214: break; ! 215: } ! 216: break; ! 217: default: ! 218: break; ! 219: } ! 220: } ! 221: } ! 222: quit_program(0, ""); ! 223: return(0); ! 224: } ! 225: ! 226: /****************************************** ! 227: * Quits the program * ! 228: ******************************************/ ! 229: void quit_program(int error, char *text) ! 230: { ! 231: if (error > 0) { ! 232: printf(" UAE-Control v0.1\n"); ! 233: printf(" (c)1996 Tauno Taipaleenmaki\n\n"); ! 234: printf(" ERROR: %s\n", text); ! 235: } ! 236: if (scr) ! 237: UnlockPubScreen(NULL, scr); ! 238: if (window) ! 239: CloseWindow( window ); ! 240: if (VisInfo) ! 241: FreeVisualInfo( VisInfo ); ! 242: if (glist) ! 243: FreeGadgets( glist ); ! 244: if (ReqBase) ! 245: CloseLibrary( ReqBase ); ! 246: if (UaeBase) ! 247: CloseLibrary( UaeBase ); ! 248: } ! 249: ! 250: ! 251: /****************************************** ! 252: * Opens up the window & sets the gadgets * ! 253: ******************************************/ ! 254: int setup_window(void) ! 255: { ! 256: struct Gadget *g; ! 257: struct NewGadget ng; ! 258: UWORD offy; ! 259: ULONG drawtags[20]; ! 260: ! 261: static const char *keyb_langs[] = ! 262: { ! 263: "US", ! 264: "DE", ! 265: "SE", ! 266: "FR", ! 267: "IT", ! 268: NULL ! 269: }; ! 270: ! 271: scr = LockPubScreen(NULL); ! 272: if (!scr) ! 273: return(0); ! 274: ! 275: VisInfo = GetVisualInfo( scr, TAG_DONE ); ! 276: if (!VisInfo) ! 277: return(0); ! 278: ! 279: offy = scr->WBorTop + scr->RastPort.TxHeight + 1; ! 280: ! 281: /* Create buttons */ ! 282: g = CreateContext( &glist ); ! 283: if (!g) ! 284: return(0); ! 285: ! 286: ng.ng_TextAttr = &topaz8; ! 287: ng.ng_VisualInfo = VisInfo; ! 288: ng.ng_Flags = PLACETEXT_IN; ! 289: ng.ng_LeftEdge = 10; ng.ng_TopEdge = offy + 10; ! 290: ng.ng_Width = 90; ng.ng_Height = 15; ! 291: ng.ng_GadgetText = (UBYTE *)"Hard reset"; ! 292: ng.ng_GadgetID = GAD_RESET; ! 293: g = CreateGadgetA(BUTTON_KIND, g, &ng, TAG_DONE); ! 294: ! 295: ng.ng_LeftEdge = 102; ng.ng_Width = 50; ! 296: ng.ng_GadgetText = (UBYTE *)"Debug"; ! 297: ng.ng_GadgetID = GAD_DEBUG; ! 298: g = CreateGadgetA(BUTTON_KIND, g, &ng, TAG_DONE); ! 299: ! 300: ng.ng_LeftEdge = 153; ng.ng_Width = 50; ! 301: ng.ng_GadgetText = (UBYTE *)"Exit"; ! 302: ng.ng_GadgetID = GAD_EXITEMU; ! 303: g = CreateGadgetA(BUTTON_KIND, g, &ng, TAG_DONE); ! 304: ! 305: /* Eject buttons */ ! 306: ng.ng_LeftEdge = 250; ng.ng_Width = 70; ! 307: ng.ng_TopEdge = offy + 35; ! 308: ng.ng_GadgetID = GAD_EJECT_DF0; ! 309: ng.ng_GadgetText = (UBYTE *)"Eject"; ! 310: g = CreateGadgetA(BUTTON_KIND, g, &ng, TAG_DONE); ! 311: ng.ng_TopEdge = offy + 53; ! 312: ng.ng_GadgetID = GAD_EJECT_DF1; ! 313: g = CreateGadgetA(BUTTON_KIND, g, &ng, TAG_DONE); ! 314: ng.ng_TopEdge = offy + 70; ! 315: ng.ng_GadgetID = GAD_EJECT_DF2; ! 316: g = CreateGadgetA(BUTTON_KIND, g, &ng, TAG_DONE); ! 317: ng.ng_TopEdge = offy + 87; ! 318: ng.ng_GadgetID = GAD_EJECT_DF3; ! 319: g = CreateGadgetA(BUTTON_KIND, g, &ng, TAG_DONE); ! 320: ! 321: /* Insert buttons */ ! 322: ng.ng_LeftEdge = 321; ng.ng_TopEdge = offy + 35; ! 323: ng.ng_GadgetID = GAD_INSERT_DF0; ! 324: ng.ng_GadgetText = (UBYTE *)"Insert"; ! 325: g = CreateGadgetA(BUTTON_KIND, g, &ng, TAG_DONE); ! 326: ng.ng_TopEdge = offy + 53; ! 327: ng.ng_GadgetID = GAD_INSERT_DF1; ! 328: g = CreateGadgetA(BUTTON_KIND, g, &ng, TAG_DONE); ! 329: ng.ng_TopEdge = offy + 70; ! 330: ng.ng_GadgetID = GAD_INSERT_DF2; ! 331: g = CreateGadgetA(BUTTON_KIND, g, &ng, TAG_DONE); ! 332: ng.ng_TopEdge = offy + 87; ! 333: ng.ng_GadgetID = GAD_INSERT_DF3; ! 334: g = CreateGadgetA(BUTTON_KIND, g, &ng, TAG_DONE); ! 335: ! 336: /* Sound & Joystick buttons */ ! 337: ! 338: ng.ng_LeftEdge = 120; ! 339: ng.ng_TopEdge = 120; ! 340: ng.ng_GadgetID = GAD_SOUND; ! 341: ng.ng_GadgetText = (UBYTE *)"Sound"; ! 342: ng.ng_Flags = PLACETEXT_LEFT; ! 343: if (config.do_output_sound) { ! 344: drawtags[0] = GTCB_Checked; ! 345: drawtags[1] = 1; ! 346: drawtags[2] = TAG_DONE; ! 347: } else { ! 348: drawtags[0] = TAG_DONE; ! 349: } ! 350: g = CreateGadgetA(CHECKBOX_KIND, g, &ng,(struct TagItem *)&drawtags); ! 351: ! 352: ng.ng_TopEdge = 135; ! 353: ng.ng_GadgetID = GAD_JOYSTICK; ! 354: ng.ng_GadgetText = (UBYTE *)"Fake Joystick"; ! 355: if (config.do_fake_joystick) { ! 356: drawtags[0] = GTCB_Checked; ! 357: drawtags[1] = 1; ! 358: drawtags[2] = TAG_DONE; ! 359: } else { ! 360: drawtags[0] = TAG_DONE; ! 361: } ! 362: g = CreateGadgetA(CHECKBOX_KIND, g, &ng, (struct TagItem *)&drawtags); ! 363: ! 364: ng.ng_TopEdge = 130; ! 365: ng.ng_LeftEdge = 160; ! 366: ng.ng_GadgetID = GAD_LANGUAGE; ! 367: ng.ng_GadgetText = (UBYTE *)"Language"; ! 368: ng.ng_Flags = PLACETEXT_ABOVE; ! 369: drawtags[0] = GTCY_Labels; ! 370: drawtags[1] = (ULONG)keyb_langs; ! 371: drawtags[2] = GTCY_Active; ! 372: drawtags[3] = config.keyboard; ! 373: drawtags[4] = TAG_DONE; ! 374: g = CreateGadgetA(CYCLE_KIND, g, &ng, (struct TagItem *)&drawtags); ! 375: ! 376: ng.ng_TopEdge = 130; ! 377: ng.ng_LeftEdge = 250; ! 378: ng.ng_GadgetID = GAD_FRAMERATE; ! 379: ng.ng_GadgetText = (UBYTE *)"Framerate"; ! 380: ng.ng_Flags = PLACETEXT_ABOVE; ! 381: drawtags[0] = GTIN_Number; ! 382: drawtags[1] = config.framerate; ! 383: drawtags[2] = TAG_DONE; ! 384: g = CreateGadgetA(INTEGER_KIND, g, &ng, (struct TagItem *)&drawtags); ! 385: ! 386: newwindow.FirstGadget = glist; ! 387: newwindow.Screen = scr; /* Store screen ptr */ ! 388: window = OpenWindow( &newwindow ); ! 389: if (!window) ! 390: return(0); ! 391: ! 392: /* Draw texts etc... */ ! 393: Move(window->RPort, 10, offy + 35 + 10); ! 394: Text(window->RPort, (UBYTE *)"DF0:", 4); ! 395: Move(window->RPort, 10, offy + 53 + 10); ! 396: Text(window->RPort, (UBYTE *)"DF1:", 4); ! 397: Move(window->RPort, 10, offy + 70 + 10); ! 398: Text(window->RPort, (UBYTE *)"DF2:", 4); ! 399: Move(window->RPort, 10, offy + 87 + 10); ! 400: Text(window->RPort, (UBYTE *)"DF3:", 4); ! 401: ! 402: drawtags[0] = (GT_VisualInfo); ! 403: drawtags[1] = (ULONG)VisInfo; ! 404: drawtags[2] = GTBB_Recessed; ! 405: drawtags[3] = 1; ! 406: drawtags[4] = TAG_DONE; ! 407: ! 408: DrawBevelBoxA(window->RPort, 5, offy + 34, ! 409: 390, 17, (struct TagItem *)&drawtags); ! 410: DrawBevelBoxA(window->RPort, 5, offy + 52, ! 411: 390, 17, (struct TagItem *)&drawtags); ! 412: DrawBevelBoxA(window->RPort, 5, offy + 69, ! 413: 390, 17, (struct TagItem *)&drawtags); ! 414: DrawBevelBoxA(window->RPort, 5, offy + 86, ! 415: 390, 17, (struct TagItem *)&drawtags); ! 416: ! 417: print_drive_status(); ! 418: ! 419: UnlockPubScreen(NULL, scr); ! 420: return(1); ! 421: } ! 422: ! 423: void print_drive_status(void) ! 424: { ! 425: char empty[80]; ! 426: int len; ! 427: UWORD offy = scr->WBorTop + scr->RastPort.TxHeight + 1; ! 428: ! 429: for(len=0;len<80;len++) ! 430: empty[len] = ' '; ! 431: empty[79] = '\0'; ! 432: ! 433: Move(window->RPort, 42, offy + 45); ! 434: if (config.disk_in_df0) { ! 435: len = strlen( config.df0_name ); ! 436: if (len > MAX_DRV_NAME) ! 437: len = MAX_DRV_NAME; ! 438: Text(window->RPort, (UBYTE *)config.df0_name, len); ! 439: } else { ! 440: Text(window->RPort, (UBYTE *)empty, MAX_DRV_NAME); ! 441: } ! 442: ! 443: Move(window->RPort, 42, offy + 63); ! 444: if (config.disk_in_df1) { ! 445: len = strlen( config.df1_name ); ! 446: if (len > MAX_DRV_NAME) ! 447: len = MAX_DRV_NAME; ! 448: Text(window->RPort, (UBYTE *)config.df1_name, len); ! 449: } else { ! 450: Text(window->RPort, (UBYTE *)empty, MAX_DRV_NAME); ! 451: } ! 452: ! 453: Move(window->RPort, 42, offy + 80); ! 454: if (config.disk_in_df2) { ! 455: len = strlen( config.df2_name ); ! 456: if (len > MAX_DRV_NAME) ! 457: len = MAX_DRV_NAME; ! 458: Text(window->RPort, (UBYTE *)config.df2_name, len); ! 459: } else { ! 460: Text(window->RPort, (UBYTE *)empty, MAX_DRV_NAME); ! 461: } ! 462: ! 463: Move(window->RPort, 42, offy + 97); ! 464: if (config.disk_in_df3) { ! 465: len = strlen( config.df3_name ); ! 466: if (len > MAX_DRV_NAME) ! 467: len = MAX_DRV_NAME; ! 468: Text(window->RPort, (UBYTE *)config.df3_name, len); ! 469: } else { ! 470: Text(window->RPort, (UBYTE *)empty, MAX_DRV_NAME); ! 471: } ! 472: } ! 473: ! 474: ! 475:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.