예제 #1
0
void
setvideomode(int ax, int bx, int cx, int dx)
{
    if (g_disk_flag)
    {
        enddisk();
    }
    if (videoflag)
    {
        endvideo();
        videoflag = 0;
    }
    g_good_mode = true;
    switch (g_dot_mode)
    {
    case 0:         // text
        clear();
        /*
           touchwin(curwin);
         */
        wrefresh(curwin);
        break;
    case 11:
        startdisk();
        dotwrite = writedisk;
        dotread = readdisk;
        lineread = normalineread;
        linewrite = normaline;
        break;
    case 19:            // X window
        putprompt();
        dotwrite = writevideo;
        dotread = readvideo;
        lineread = readvideoline;
        linewrite = writevideoline;
        videoflag = 1;
        startvideo();
        setforgraphics();
        break;
    default:
        std::printf("Bad mode %d\n", g_dot_mode);
        exit(-1);
    }
    if (g_dot_mode != 0)
    {
        loaddac();
        g_and_color = g_colors - 1;
        g_box_count = 0;
    }
    g_vesa_x_res = g_screen_x_dots;
    g_vesa_y_res = g_screen_y_dots;
}
예제 #2
0
int targa_startdisk(FILE *targafp, int overhead)
{
    int i;
    if (driver_diskp()) // ditch the original file, make just the targa
    {
        enddisk();      // close the 'screen'
        setnullvideo(); // set readdot and writedot routines to do nothing
    }
    headerlength = overhead;
    fp = targafp;
    disktarga = true;
    i = common_startdisk(xdots*3, ydots, colors);
    high_offset = 100000000L; // targa not necessarily init'd to zeros

    return i;
}
예제 #3
0
int pot_startdisk()
{
    int i;
    if (driver_diskp())         // ditch the original disk file
    {
        enddisk();
    }
    else
    {
        showtempmsg("clearing 16bit pot work area");
    }
    headerlength = 0;
    disktarga = false;
    i = common_startdisk(sxdots, sydots << 1, colors);
    cleartempmsg();
    if (i == 0)
    {
        disk16bit = true;
    }

    return i;
}
예제 #4
0
int common_startdisk(long newrowsize, long newcolsize, int colors)
{
    int freemem;
    long memorysize;
    unsigned int *fwd_link = nullptr;
    long longtmp;
    unsigned int cache_size;
    BYTE *tempfar = nullptr;
    if (g_disk_flag)
    {
        enddisk();
    }
    if (driver_diskp()) // otherwise, real screen also in use, don't hit it
    {
        char buf[128];
        helptitle();
        driver_set_attr(1, 0, C_DVID_BKGRD, 24*80);  // init rest to background
        for (int i = 0; i < BOXDEPTH; ++i)
        {
            driver_set_attr(BOXROW+i, BOXCOL, C_DVID_LO, BOXWIDTH);  // init box
        }
        driver_put_string(BOXROW+2, BOXCOL+4, C_DVID_HI, "'Disk-Video' mode");
        sprintf(buf, "Screen resolution: %d x %d", sxdots, sydots);
        driver_put_string(BOXROW+4, BOXCOL+4, C_DVID_LO, buf);
        if (disktarga)
        {
            driver_put_string(-1, -1, C_DVID_LO, "  24 bit Targa");
        }
        else
        {
            driver_put_string(-1, -1, C_DVID_LO, "  Colors: ");
            sprintf(buf, "%d", colors);
            driver_put_string(-1, -1, C_DVID_LO, buf);
        }
        sprintf(buf, "Save name: %s", savename);
        driver_put_string(BOXROW+8, BOXCOL+4, C_DVID_LO, buf);
        driver_put_string(BOXROW+10, BOXCOL+4, C_DVID_LO, "Status:");
        dvid_status(0, "clearing the 'screen'");
    }
    high_offset = -1;
    seek_offset = high_offset;
    cur_offset = seek_offset;
    cur_row    = -1;
    if (disktarga)
    {
        pixelshift = 0;
    }
    else
    {
        pixelshift = 3;
        int i = 2;
        while (i < colors)
        {
            i *= i;
            --pixelshift;
        }
    }
    timetodisplay = bf_math != bf_math_type::NONE ? 10 : 1000;  // time-to-g_driver-status counter

    /* allocate cache: try for the max; leave FREEMEMk free if we can get
        that much or more; if we can't get that much leave 1/2 of whatever
        there is free; demand a certain minimum or nogo at all */
    freemem = FREEMEM;

    for (cache_size = CACHEMAX; cache_size >= CACHEMIN; --cache_size)
    {
        longtmp = ((int)cache_size < freemem) ?
                  (long)cache_size << 11 : (long)(cache_size+freemem) << 10;
        tempfar = static_cast<BYTE *>(malloc(longtmp));
        if (tempfar != nullptr)
        {
            free(tempfar);
            break;
        }
    }
    if (debugflag == debug_flags::force_disk_min_cache)
    {
        cache_size = CACHEMIN;
    }
    longtmp = (long)cache_size << 10;
    cache_start = (cache *)malloc(longtmp);
    if (cache_size == 64)
    {
        --longtmp; // safety for next line
    }
    cache_lru = cache_start;
    cache_end = cache_lru + longtmp/sizeof(*cache_start);
    membuf = (BYTE *)malloc((long)BLOCKLEN);
    if (cache_start == nullptr || membuf == nullptr)
    {
        stopmsg(STOPMSG_NONE,
            "*** insufficient free memory for cache buffers ***");
        return -1;
    }
    if (driver_diskp())
    {
        char buf[50];
        sprintf(buf, "Cache size: %dK", cache_size);
        driver_put_string(BOXROW+6, BOXCOL+4, C_DVID_LO, buf);
    }

    // preset cache to all invalid entries so we don't need free list logic
    for (int i = 0; i < HASHSIZE; ++i)
    {
        hash_ptr[i] = 0xffff; // 0xffff marks the end of a hash chain
    }
    longtmp = 100000000L;
    for (cache *ptr1 = cache_start; ptr1 < cache_end; ++ptr1)
    {
        ptr1->dirty = false;
        ptr1->lru = false;
        longtmp += BLOCKLEN;
        fwd_link = &hash_ptr[(((unsigned short)longtmp >> BLOCKSHIFT) & (HASHSIZE-1))];
        ptr1->offset = longtmp;
        ptr1->hashlink = *fwd_link;
        *fwd_link = (int)((char *)ptr1 - (char *)cache_start);
    }

    memorysize = (long)(newcolsize) * newrowsize + headerlength;
    int i = (short)memorysize & (BLOCKLEN-1);
    if (i != 0)
    {
        memorysize += BLOCKLEN - i;
    }
    memorysize >>= pixelshift;
    memorysize >>= BLOCKSHIFT;
    g_disk_flag = true;
    rowsize = (unsigned int) newrowsize;
    colsize = (unsigned int) newcolsize;

    if (disktarga)
    {
        // Retrieve the header information first
        BYTE *tmpptr;
        tmpptr = membuf;
        fseek(fp, 0L, SEEK_SET);
        for (int i = 0; i < headerlength; i++)
        {
            *tmpptr++ = (BYTE)fgetc(fp);
        }
        fclose(fp);
        dv_handle = MemoryAlloc((U16)BLOCKLEN, memorysize, DISK);
    }
    else
    {
        dv_handle = MemoryAlloc((U16)BLOCKLEN, memorysize, MEMORY);
    }
    if (dv_handle == 0)
    {
        stopmsg(STOPMSG_NONE, "*** insufficient free memory/disk space ***");
        g_good_mode = false;
        rowsize = 0;
        return -1;
    }

    if (driver_diskp())
    {
        driver_put_string(BOXROW+2, BOXCOL+23, C_DVID_LO,
                          (MemoryType(dv_handle) == DISK) ? "Using your Disk Drive" : "Using your memory");
    }

    membufptr = membuf;

    if (disktarga)
    {
        // Put header information in the file
        MoveToMemory(membuf, (U16)headerlength, 1L, 0, dv_handle);
    }
    else
    {
        for (long offset = 0; offset < memorysize; offset++)
        {
            SetMemory(0, (U16)BLOCKLEN, 1L, offset, dv_handle);
            if (driver_key_pressed())           // user interrupt
            {
                // esc to cancel, else continue
                if (stopmsg(STOPMSG_CANCEL, "Disk Video initialization interrupted:\n"))
                {
                    enddisk();
                    g_good_mode = false;
                    return -2;            // -1 == failed, -2 == cancel
                }
            }
        }
    }

    if (driver_diskp())
    {
        dvid_status(0, "");
    }
    return 0;
}