/*************************************************************** * vt100 - terminal emulator - initialization * * 860823 DBW - Integrated and rewrote lots of code * v2.0 860809 DBW - Major rewrite * v1.1 860720 DBW - Switches, 80 cols, colors, bug fixes * v1.0 860712 DBW - First version released * ***************************************************************/ #define MODULE_INIT 1 #include "vt100.h" extern char *malloc(); void InitDefaults(argc,argv) int argc; char **argv; { FILE *fd; char line[256],scr[32],delim,macro[256],c0,*ptr; int i,j,k; if (((argc > 1) && (fd=fopen(argv[1],"r")) != 0) || (fd=fopen("vt100.init","r")) != 0 || (fd=fopen("c:vt100.init","r")) != 0) { while (fgets(line,256,fd) != 0) { if ((c0 = line[0]) == '#') continue; if ((c0|' ') == 'e') break; switch (c0|' ') { case 'b': if ((line[1]|' ') == 'o') { /* bold color */ if (sscanf(line,"%s %x",scr,&i) == 2) p_bold = i; break; } if ((line[1]|' ') != 'a') break; switch(line[2]|' ') { /* baud rate */ case 'u': if (sscanf(line,"%s %d",scr,&i) == 2) p_baud = i; break; /* background */ case 'c': if (sscanf(line,"%s %x",scr,&i) == 2) p_background = i; break; } break; /* screen type */ case 's': if (sscanf(line,"%s %s",scr,scr) == 2) { if ((scr[0]|' ') == 'w') p_screen = 0; else p_screen = 1; } break; /* number of lines */ case 'l': if (sscanf(line,"%s %d",scr,&i) == 2) p_lines = i; break; /* screen depth */ case 'd': if (sscanf(line,"%s %d",scr,&i) == 2) p_depth = i; break; /* cursor color */ case 'c': if (sscanf(line,"%s %x",scr,&i) == 2) p_cursor = i; break; /* interlace type */ case 'i': if (sscanf(line,"%s %s",scr,scr) == 2) { if ((scr[1]|' ') == 'n') p_interlace = 1; else p_interlace = 0; } break; case 'f': switch (line[1]|' ') { /* foreground color */ case 'o': if (sscanf(line,"%s %x",scr,&i) == 2) p_foreground = i; break; /* function key */ default: if (sscanf(&line[1],"%d",&i) != 1) break; if (i < 1 || i > 10) break; delim = 0; for (j=2; line[j] != 0 && (line[j] == ' ' || line[j] == '\t'); j++) ; if (line[j] == 0) { if (c0 == 'f') p_f[i-1] = NULL; else p_F[i-1] = NULL; break; } delim = line[j]; k = 0; macro[0] = 0; while (line[++j] != delim) { if (line[j] == 0) { if (fgets(line,256,fd) == 0) { line[0] = delim; line[1] = 0; } j = -1; continue; } if (line[j] == '^' && line[++j] != '^') macro[k++] = (line[j]|' ') - 0x60; else if (line[j] != '\n') macro[k++] = line[j]; macro[k] = 0; } ptr = malloc(k+1); if (c0 == 'f') p_f[i-1] = ptr; else p_F[i-1] = ptr; strcpy(ptr,macro); break; } break; case 'm': if (sscanf(line,"%s %s",scr,scr) == 2) { if ((scr[0]|' ') == 'i') p_mode = 0; else p_mode = 1; } break; case 'x': if (sscanf(line,"%s %s",scr,scr) == 2) { if ((scr[0]|' ') == 'd') p_xon = 0; else p_xon = 1; } break; } } fclose(fd); } /* Now set up all the screen info as necessary */ if (p_interlace == 0) { if (p_lines > 24) p_lines = 24; MINY = 14; NewWindow.Height = (long)((p_lines*8)+8); } else { if (p_lines > 48) p_lines = 48; MINY = 16; NewScreen.ViewModes |= LACE; NewWindow.Height = (long)((p_lines*8)+10); } NewWindow.MinHeight = NewWindow.Height; NewWindow.MaxHeight = NewWindow.Height; NewWindow.TopEdge = 3L; MAXY = ((p_lines-1)*8) + MINY; top = MINY; bot = MAXY; savx = MINX; savy = MINY; if (p_screen == 1) { if (p_depth > 2) p_depth = 2; if (p_depth < 1) p_depth = 1; NewScreen.Depth = (long)p_depth; NewScreen.Height = (long)((p_lines*8)+15); if (p_interlace == 1) NewScreen.TopEdge = (long)(402 - NewScreen.Height); else NewScreen.TopEdge = 0L; } else { p_depth = 2L; NewWindow.TopEdge = 0L; NewWindow.Screen = NULL; NewWindow.Type = WBENCHSCREEN; } } void InitDevs() { USHORT colors[4]; IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", INTUITION_REV); if( IntuitionBase == NULL ) { puts("can't open intuition\n"); exit(TRUE); } GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",GRAPHICS_REV); if( GfxBase == NULL ) { puts("can't open graphics library\n"); exit(TRUE); } if (p_screen == 1) { if ((myscreen = (struct Screen *)OpenScreen(&NewScreen)) == NULL) { puts("can't open screen!!\n"); exit(TRUE); } NewWindow.Screen = myscreen; } if(( mywindow = (struct Window *)OpenWindow(&NewWindow) ) == NULL) { puts("cant open window\n"); if (p_screen != 0) CloseScreen( myscreen ); exit(TRUE); } myviewport = (struct ViewPort *)ViewPortAddress(mywindow); if (p_screen != 0) { colors[0] = p_background; colors[1] = p_foreground; colors[2] = p_bold; colors[3] = p_cursor; if (p_depth == 1) LoadRGB4(myviewport,(struct ColorMap *)colors,2L); else LoadRGB4(myviewport,(struct ColorMap *)colors,4L); } Read_Request = (struct IOExtSer *) AllocMem((long)sizeof(*Read_Request),MEMF_PUBLIC|MEMF_CLEAR); Read_Request->io_SerFlags = SERF_SHARED | SERF_XDISABLED; Read_Request->IOSer.io_Message.mn_ReplyPort = CreatePort("Read_RS",0); if(OpenDevice(SERIALNAME,NULL,Read_Request,NULL)) { puts("Cant open Read device\n"); CloseWindow( mywindow ); if (p_screen != 0) CloseScreen( myscreen ); DeletePort(Read_Request->IOSer.io_Message.mn_ReplyPort); FreeMem(Read_Request,(long)sizeof(*Read_Request)); exit(TRUE); } Read_Request->IOSer.io_Command = CMD_READ; Read_Request->IOSer.io_Length = 1; Read_Request->IOSer.io_Data = (APTR) &rs_in[0]; Write_Request = (struct IOExtSer *) AllocMem((long)sizeof(*Write_Request),MEMF_PUBLIC|MEMF_CLEAR); Write_Request->io_SerFlags = SERF_SHARED | SERF_XDISABLED; Write_Request->IOSer.io_Message.mn_ReplyPort = CreatePort("Write_RS",0); if(OpenDevice(SERIALNAME,NULL,Write_Request,NULL)) { puts("Cant open Write device\n"); CloseDevice(Read_Request); DeletePort(Read_Request->IOSer.io_Message.mn_ReplyPort); FreeMem(Read_Request,(long)sizeof(*Read_Request)); DeletePort(Write_Request->IOSer.io_Message.mn_ReplyPort); FreeMem(Write_Request,(long)sizeof(*Write_Request)); CloseWindow( mywindow ); if (p_screen != 0) CloseScreen( myscreen ); exit(TRUE); } Write_Request->IOSer.io_Command = CMD_WRITE; Write_Request->IOSer.io_Length = 1; Write_Request->IOSer.io_Data = (APTR) &rs_out[0]; Read_Request->io_SerFlags = SERF_SHARED | SERF_XDISABLED; Read_Request->io_Baud = p_baud; Read_Request->io_ReadLen = 8; Read_Request->io_WriteLen = 8; Read_Request->io_CtlChar = 1L; Read_Request->io_RBufLen = 2048; Read_Request->IOSer.io_Command = SDCMD_SETPARAMS; DoIO(Read_Request); Read_Request->IOSer.io_Command = CMD_READ; Timer_Port = CreatePort("Timer Port",0); Script_Timer_Port = CreatePort("Timer Port",0); if (OpenDevice(TIMERNAME, UNIT_VBLANK, (char *) &Timer, 0) || OpenDevice(TIMERNAME, UNIT_VBLANK, (char *) &Script_Timer, 0)) { puts("can't open timer device"); DeletePort(Timer_Port); DeletePort(Script_Timer_Port); CloseDevice(Read_Request); DeletePort(Read_Request->IOSer.io_Message.mn_ReplyPort); FreeMem(Read_Request,(long)sizeof(*Read_Request)); CloseDevice(Write_Request); DeletePort(Write_Request->IOSer.io_Message.mn_ReplyPort); FreeMem(Write_Request,(long)sizeof(*Write_Request)); CloseWindow( mywindow ); if (p_screen != 0) CloseScreen( myscreen ); exit(TRUE); } Timer.tr_node.io_Message.mn_ReplyPort = Timer_Port; Timer.tr_node.io_Command = TR_ADDREQUEST; Timer.tr_node.io_Flags = 0; Timer.tr_node.io_Error = 0; Script_Timer.tr_node.io_Message.mn_ReplyPort = Script_Timer_Port; Script_Timer.tr_node.io_Command = TR_ADDREQUEST; Script_Timer.tr_node.io_Flags = 0; Script_Timer.tr_node.io_Error = 0; } /*****************************************************************/ /* The following function initializes the structure arrays */ /* needed to provide the File menu topic. */ /*****************************************************************/ void InitFileItems() { int n; /* initialize each menu item and IntuiText with loop */ for( n=0; n