Ejemplo n.º 1
0
Archivo: mameql.c Proyecto: z88dk/z88dk
int mameql_exec(char *target)
{
    char    filename[FILENAME_MAX+1];
    struct  stat binname_sb;
    FILE   *fpin;
    FILE   *fpout;
    int     i,c;
    
    if ( help )
        return -1;

    if ( binname == NULL ) {
        return -1;
    }

    if ( outfile == NULL ) {
        strcpy(filename,binname);
        suffix_change(filename,".ql");
    } else {
        strcpy(filename,outfile);
    }

    if ( description == NULL ) {
         description = binname;
    }

    if ((origin == -1) && ((crtfile == NULL) || ((origin = get_org_addr(crtfile)) == -1))) {
        origin = 0;
    }
    if ( exec == -1 ) {
        exec = origin;
    }
    
    if ( stat(binname, &binname_sb) < 0 ||
         ( (fpin=fopen_bin(binname, NULL) ) == NULL )) {
        exit_log(1,"Can't open input file %s\n",binname);
    }
    
    if ( ( fpout = fopen(binname, "rb")) == NULL ) {
        exit_log(1,"Can't open input file %s\n", binname);
    }
    
    if ( ( fpout = fopen(filename, "wb")) == NULL ) {
        exit_log(1,"Can't open output file %s\n", filename);
    }

    /* Header */
    writebyte(0xfd, fpout);
    writebyte(0x00, fpout);
    writebyte(0x80, fpout);
    writebyte(0x00, fpout);
    writebyte(0x00, fpout);
    writebyte(0xf9, fpout);
    writebyte(0x01, fpout);	// Varies, what is it?

    /* Write the program name */
    for ( i = 0; i < strlen(description); i++ ) {
        writebyte(description[i], fpout);
    }
    // Description terminator 
    writebyte(0x1a, fpout);
    // Exec address
    writeword(exec, fpout);
    // Start address
    writeword(origin, fpout);
    // End address
    writeword(origin + binname_sb.st_size - 1, fpout);

    for ( i = 0; i < binname_sb.st_size; i++) {
        c = getc(fpin);
        writebyte(c,fpout);
    }    
    fclose(fpin);
    fclose(fpout);
    
    return 0;
}
Ejemplo n.º 2
0
int enterprise_exec(char *target)
{
    char    filename[FILENAME_MAX+1];
    FILE   *fpin;
    FILE   *fpout;
    int     len;
    int     c,i;

    if ( help )
        return -1;

    if ( binname == NULL ) {
        return -1;
    }

    if ( outfile == NULL ) {
        strcpy(filename,binname);
        suffix_change(filename, extfile);
    } else {
        strcpy(filename,outfile);
    }

	if ( (fpin=fopen_bin(binname, NULL) ) == NULL ) {
        fprintf(stderr,"Can't open input file %s\n",binname);
        myexit(NULL,1);
    }

 

    if (fseek(fpin,0,SEEK_END)) {
        fprintf(stderr,"Couldn't determine size of file\n");
        fclose(fpin);
        myexit(NULL,1);
    }

    len=ftell(fpin);

    fseek(fpin,0L,SEEK_SET);

    if ( (fpout=fopen(filename,"wb") ) == NULL ) {
        fclose(fpin);
        myexit("Can't open output file\n",1);
    }

    writebyte(0,fpout);
    writebyte(5,fpout);
    writeword(len,fpout);
	for	(i=1;i<=12;i++)
		writebyte(0,fpout);

    for ( i = 0; i < len; i++) {
        c = getc(fpin);
        writebyte(c,fpout);
    }


    fclose(fpin);
    fclose(fpout);

    return 0;
}
Ejemplo n.º 3
0
Archivo: msx.c Proyecto: z88dk/z88dk
int msx_exec(char* target)
{
    char filename[FILENAME_MAX + 1];
    char wavfile[FILENAME_MAX + 1];
    FILE *fpin, *fpout;
    char name[11];
    int c;
    int i;
    int pos;
    int len;

    if (help)
        return -1;

    if (binname == NULL || (!dumb && (crtfile == NULL && origin == -1))) {
        return -1;
    }

    if (origin != -1) {
        pos = origin;
    } else {
        if ((pos = get_org_addr(crtfile)) == -1) {
            myexit("Could not find parameter ZORG (not z88dk compiled?)\n", 1);
        }
    }

    if (loud) {
        msx_h_lvl = 0xFd;
        msx_l_lvl = 2;
    } else {
        msx_h_lvl = 0xe0;
        msx_l_lvl = 0x20;
    }

    if (dumb) {
        strcpy(filename, binname);
    } else {

        if (outfile == NULL) {
            strcpy(filename, binname);
            if (fmsx)
                suffix_change(filename, ".cas");
            else
                suffix_change(filename, ".msx");
        } else {
            strcpy(filename, outfile);
        }

        if ((fpin = fopen_bin(binname, crtfile)) == NULL) {
            printf("Can't open input file %s\n", binname);
            exit(1);
        }

        /*
	 *        Now we try to determine the size of the file
	 *        to be converted
	 */
        if (fseek(fpin, 0, SEEK_END)) {
            printf("Couldn't determine size of file\n");
            fclose(fpin);
            exit(1);
        }

        len = ftell(fpin);

        fseek(fpin, 0L, SEEK_SET);

        if ((fpout = fopen(filename, "wb")) == NULL) {
            printf("Can't open output file\n");
            exit(1);
        }

        /* Write out the header file */

        if (fmsx) {

            /* Block identifier in a CAS file */
            for (i = 0; i < 8; i++)
                fputc(blockid[i], fpout);

            for (i = 0; i < 10; i++)
                fputc(0xd0, fpout);

            /* Deal with the filename */
            if (strlen(binname) >= 6) {
                strncpy(name, binname, 6);
            } else {
                strcpy(name, binname);
                strncat(name, "      ", 6 - strlen(binname));
            }
            for (i = 0; i < 6; i++)
                writebyte(name[i], fpout);

            /* Block identifier in a CAS file */
            for (i = 0; i < 8; i++)
                fputc(blockid[i], fpout);

        } else
            fputc(254, fpout);

        writeword(pos, fpout); /* Start Address */
        writeword(pos + len + 1, fpout); /* End Address */
        writeword(pos, fpout); /* Call Address */

        /* We append the binary file */

        for (i = 0; i < len; i++) {
            c = getc(fpin);
            writebyte(c, fpout);
        }

        if (fmsx) {
            writeword(0, fpout);
        }

        fclose(fpin);
        fclose(fpout);
    }

    if ( disk ) {
        return fat_write_file_to_image("msxbasic", "raw", NULL, filename, NULL, NULL);
    }

    /* ***************************************** */
    /*  Now, if requested, create the audio file */
    /* ***************************************** */
    if ((audio) || (fast) || (loud)) {
        if ((fpin = fopen(filename, "rb")) == NULL) {
            fprintf(stderr, "Can't open file %s for wave conversion\n", filename);
            myexit(NULL, 1);
        }

        if (fseek(fpin, 0, SEEK_END)) {
            fclose(fpin);
            myexit("Couldn't determine size of file\n", 1);
        }
        len = ftell(fpin);
        fseek(fpin, 0, SEEK_SET);

        strcpy(wavfile, filename);

        suffix_change(wavfile, ".RAW");

        if ((fpout = fopen(wavfile, "wb")) == NULL) {
            fprintf(stderr, "Can't open output raw audio file %s\n", wavfile);
            myexit(NULL, 1);
        }

        /* leading silence and tone*/
        for (i = 0; i < 0x3000; i++)
            fputc(0x80, fpout);
        for (i = 0; (i < 8000); i++)
            msx_bit(fpout, 1);

        /* Skip the block id bytes  */
        if (fmsx) {
            for (i = 0; (i < 8); i++)
                c = getc(fpin);
            len -= 8;

            /* Copy the header */
            if (dumb)
                printf("\nInfo: Program Name found in header: ");
            for (i = 0; (i < 16); i++) {
                c = getc(fpin);
                if (dumb && i > 10 && i < 17)
                    printf("%c", c);
                msx_rawout(fpout, c);
            }

            len -= 16;
        }

        /* leading silence and tone*/
        for (i = 0; i < 0x8000; i++)
            fputc(0, fpout);
        for (i = 0; (i < 2000); i++)
            msx_bit(fpout, 1);

        /* Skip the block id bytes  */
        if (fmsx) {
            for (i = 0; (i < 8); i++)
                c = getc(fpin);
            len -= 8;
        }

        /* program block */
        if (len > 0) {
            for (i = 0; i < len; i++) {
                c = getc(fpin);
                msx_rawout(fpout, c);
            }
        }

        fclose(fpin);
        fclose(fpout);

        /* Now complete with the WAV header */
        raw2wav(wavfile);

    } /* END of WAV CONVERSION BLOCK */

    return 0;
}
Ejemplo n.º 4
0
//this reads in the funky grid, ignoring the material properties at the 
//end of the file, those are now read from frict.data in Read_data()
void Read_grid(int myid, int numprocs, HashTable** NodeTable, ElementsHashTable** ElemTable, MatProps* matprops_ptr,
               OutLine* outline_ptr)
{
    int Node_Num, Elem_Num;
    
    int NODE_TABLE_SIZE = 400000;
    
    //char  filename[14] = "lsh4800xx.inp";
    char filename[14] = "funkyxxxx.inp";
    //unsigned min_key[KEYLENGTH];
    //unsigned max_key[KEYLENGTH];
    double doublekeyrange[2];
    double XRange[2];
    double YRange[2];
    unsigned key[KEYLENGTH];
    double coord[DIMENSION];
    double height;
    Node* NodeP;
    int i, j, k;
    
    // read in nodal data
    sprintf(filename, "funky%04d.inp", myid);
    FILE* fp;
    
    fp = fopen_bin(filename, "r");
    if(!fp)
    {
        printf("Can't open file for %d \n", myid);
        exit(0);
    }
    
    int version, DoublesFromFloats;
    freadI(fp, &version);
    
    switch (version)
    {
        case 20061109:
            DoublesFromFloats = 1;
            break;
        case 20061110:
            DoublesFromFloats = 0;
            break;
        default:
            printf("Read_data() does not recognize binary funkyxxxx.inp version %d\n", version);
            exit(1);
            break;
    }
    
    freadI(fp, &Node_Num);
    
    if(DoublesFromFloats)
    {
        for(i = 0; i < KEYLENGTH; i++)
            freadF2D(fp, &(doublekeyrange[i]));
        
        freadF2D(fp, &(XRange[0]));  //min x
        freadF2D(fp, &(XRange[1]));  //max x
        freadF2D(fp, &(YRange[0]));  //min y
        freadF2D(fp, &(YRange[1]));
    } //max y
    else
    {
        for(i = 0; i < KEYLENGTH; i++)
            freadD(fp, &(doublekeyrange[i]));
        
        freadD(fp, &(XRange[0]));  //min x
        freadD(fp, &(XRange[1]));  //max x
        freadD(fp, &(YRange[0]));  //min y
        freadD(fp, &(YRange[1]));
    } //max y
    
    double xminmax[2], yminmax[2];
    for(i = 0; i < 2; i++)
    {
        XRange[i] = XRange[i] / matprops_ptr->LENGTH_SCALE;
        xminmax[i] = XRange[i];
    }
    for(i = 0; i < 2; i++)
    {
        YRange[i] = YRange[i] / matprops_ptr->LENGTH_SCALE;
        yminmax[i] = YRange[i];
    }
    
    *NodeTable = new HashTable(doublekeyrange, NODE_TABLE_SIZE, XRange, YRange);
    
    for(i = 0; i < Node_Num; i++)
    {
        for(j = 0; j < KEYLENGTH; j++)
            freadU(fp, &(key[j]));
        
        if(DoublesFromFloats)
            for(j = 0; j < DIMENSION; j++)
                freadF2D(fp, &(coord[j]));
        else
            for(j = 0; j < DIMENSION; j++)
                freadD(fp, &(coord[j]));
        
        for(j = 0; j < 2; j++)
            coord[j] = coord[j] / matprops_ptr->LENGTH_SCALE;
        NodeP = new Node(key, coord, matprops_ptr);
        (*NodeTable)->add(key, NodeP);
    }
    (*NodeTable)->print0();
    //done reading in node data
    //start reading in element data
    
    int EL_TABLE_SIZE = 100000;
    
    //char  filename[14] = "lsh4800xx.inp";
    int material, elm_loc[2];
    unsigned opposite_brother[2];
    
    Element* Quad9P;
    float* value = new float[2];
    BC* baddress[4];
    void* p;
    int* assocp;/*--*/
    unsigned* keyP;
    
    unsigned nodes[9][2];
    unsigned neigh[4][2];
    int neighbor_proc[4];
    
    int temp2;
    int interflag;
    
    freadI(fp, &Elem_Num);  //--number of the elements assigned to the proc
           
    *ElemTable = new ElementsHashTable(doublekeyrange, EL_TABLE_SIZE, XRange, YRange, *NodeTable);
    for(int ielem = 0; ielem < Elem_Num; ielem++)
    {
        
        for(j = 0; j < 9; j++)
            for(k = 0; k < KEYLENGTH; k++)
                freadU(fp, &(nodes[j][k]));
        
        interflag = 0;  //---switch for interface
        for(j = 0; j < 4; j++)
        {
            
            freadI(fp, &(neighbor_proc[j]));  //--read the neighbor info
                   
            if(neighbor_proc[j] != -1)  //--if there is neighbor(-1 means the edge is bound)
            {
                if(neighbor_proc[j] != myid) //--the neighbor belongs to other proc
                    interflag = 1; //--switch is used for avoiding nominating neighbor twice
                            
                for(k = 0; k < KEYLENGTH; k++)
                    freadU(fp, &(neigh[j][k])); //--read the left parts of the key
            }
            
            else
                //--there is no neighbor 
                for(k = 0; k < KEYLENGTH; k++)
                    neigh[j][k] = 0;
        }
        
        BC* bcptr = 0;
        int bcf = 0;
        
        //.....the essential boundary conditions....
        
        for(j = 0; j < 4; j++)
        {
            freadI(fp, &temp2);
            
            if(temp2 != -1) //--there is bound constraint
            {
                if(!bcf)
                    bcptr = new BC();
                bcptr->type[j] = 1; //--intialize type
                        
                /* "value" is a FLOAT so DON'T use freadD when DoublesFromFloats
                 is false (and obviously don't use freadD when it's true 
                 either) */
                for(k = 0; k < 2; k++)
                    freadF(fp, &(bcptr->value[j][0][k])); //--j: edge number
                           
                bcf = 1;
            }
        }
        
        //.....the natural boundary conditions.....
        for(j = 0; j < 4; j++)
        {
            
            freadI(fp, &temp2);
            
            if(temp2 != -1) //--there is bound constraint
            {
                if(!bcf)
                    bcptr = new BC();
                if(bcptr->type[j] == 0)
                    bcptr->type[j] = 2; //--intialize type
                else
                    bcptr->type[j] = 3; //--intialize type
                            
                /* "value" is a FLOAT so DON'T use freadD when DoublesFromFloats
                 is false (and obviously don't use freadD when it's true 
                 either) */
                for(k = 0; k < 2; k++)
                    freadF(fp, &(bcptr->value[j][1][k])); //--j: edge number
                           
                bcf = 1;
            }
        }
        
        freadI(fp, &(elm_loc[0]));
        freadI(fp, &(elm_loc[1]));
        freadU(fp, &(opposite_brother[0]));
        freadU(fp, &(opposite_brother[1]));
        freadI(fp, &material);
        double pile_height = 0.0;
        
        if(!bcf)
            bcptr = NULL; //--this element is not on the bound
        Quad9P = (*ElemTable)->generateElement(nodes, neigh, neighbor_proc, bcptr, material, elm_loc, pile_height, myid,
                             opposite_brother);
        (*ElemTable)->add(nodes[8], Quad9P);
        Quad9P->find_positive_x_side(*NodeTable);
        Quad9P->calculate_dx(*NodeTable);
    }
    (*ElemTable)->print0();
    /************************************************************/
    /* need to change this so that smallest cell size is chosen */
    /* based on cube root of volume with failsafe for a minimum */
    /* of 2 cells across smallest pile/flux source axis instead */
    /* of basing it on just the smallest pile/flux source axis  */
    /* which is what we're doing now, will need to print out a  */
    /* warning that the calculation may be slow when the        */
    /* failsafe is activated                                    */
    /************************************************************/

    double dx[2] =
    { *(Quad9P->get_dx() + 0), *(Quad9P->get_dx() + 1) };
    double DX = dx[0];
    if(dx[0] < dx[1])
        DX = dx[1];
    
    REFINE_LEVEL = Quad9P->get_gen()
            + ceil(log(DX * (matprops_ptr->number_of_cells_across_axis) / (matprops_ptr->smallest_axis)) / log(2.0));
    
    //(mdj)2007-04-12 if(REFINE_LEVEL<3) REFINE_LEVEL=3;
    if(REFINE_LEVEL < 0)
        REFINE_LEVEL = 0;
    
    //set the nodal type information
    Element *EmTemp;
    Node *NdTemp;
    int inode;
    int num_buck = (*ElemTable)->get_no_of_buckets();
    HashEntryPtr* buck = (*ElemTable)->getbucketptr();
    for(int i = 0; i < num_buck; i++)
        if(*(buck + i))
        {
            
            HashEntryPtr currentPtr = *(buck + i);
            while (currentPtr)
            {
                
                EmTemp = (Element*) (currentPtr->value);
                currentPtr = currentPtr->next;
                assert(EmTemp);
                
                EmTemp->put_myprocess(myid);
                
                NdTemp = (Node*) (*NodeTable)->lookup(EmTemp->pass_key());
                assert(NdTemp);
                NdTemp->putinfo(BUBBLE);
                
                for(inode = 0; inode < 4; inode++)
                {
                    NdTemp = (Node*) (*NodeTable)->lookup(EmTemp->getNode() + inode * KEYLENGTH);
                    assert(NdTemp);
                    NdTemp->putinfo(CORNER);
                }
                
                for(inode = 4; inode < 8; inode++)
                {
                    NdTemp = (Node*) (*NodeTable)->lookup(EmTemp->getNode() + inode * KEYLENGTH);
                    assert(NdTemp);
                    NdTemp->putinfo(SIDE);
                }
            }
        }
    
#ifdef MAX_DEPTH_MAP
    outline_ptr->init(Quad9P->get_dx(), REFINE_LEVEL - Quad9P->get_gen(), xminmax, yminmax);
#endif
    
    delete[] value;
}