void soundmng_destroy(void) { int i; SINT16 *tmp; if (soundmng.opened) { soundmng.opened = FALSE; SDL_PauseAudio(1); SDL_CloseAudio(); for (i=0; i<NSNDBUF; i++) { tmp = soundmng.buf[i]; soundmng.buf[i] = NULL; _MFREE(tmp); } #if defined(VERMOUTH_LIB) // cmvermouth_unload(); #endif } }
VEXTERN MIDIMOD VEXPORT midimod_create(UINT samprate) { UINT size; MIDIMOD ret; BRESULT r; size = sizeof(_MIDIMOD); size += sizeof(INSTRUMENT) * 128 * 2; size += sizeof(_TONECFG) * 128 * 2; ret = (MIDIMOD)_MALLOC(size, "MIDIMOD"); if (ret == NULL) { goto mmcre_err1; } ZeroMemory(ret, size); ret->samprate = samprate; ret->tone[0] = (INSTRUMENT *)(ret + 1); ret->tone[1] = ret->tone[0] + 128; ret->tonecfg[0] = (TONECFG)(ret->tone[1] + 128); ret->tonecfg[1] = ret->tonecfg[0] + 128; ret->pathtbl = listarray_new(sizeof(_PATHLIST), 16); pathadd(ret, NULL); pathadd(ret, file_getcd(str_null)); ret->namelist = listarray_new(MAX_NAME, 128); r = cfgfile_load(ret, file_timiditycfg, 0); #if defined(TIMIDITY_CFGFILE) if (r != SUCCESS) { r = cfgfile_load(ret, TIMIDITY_CFGFILE, 0); } #endif if (r != SUCCESS) { goto mmcre_err2; } midimod_lock(ret); return(ret); mmcre_err2: listarray_destroy(ret->namelist); listarray_destroy(ret->pathtbl); _MFREE(ret); mmcre_err1: return(NULL); }
FLISTH file_list1st(const char *dir, FLINFO *fli) { Str255 fname; FSSpec fss; FLHDL ret; mkstr255(fname, dir); FSMakeFSSpec(0, 0, fname, &fss); ret = (FLHDL)_MALLOC(sizeof(_FLHDL), dir); if (ret == NULL) { goto ff1_err1; } ret->pb.dirInfo.ioNamePtr = fss.name; ret->pb.dirInfo.ioVRefNum = fss.vRefNum; ret->pb.dirInfo.ioDrDirID = fss.parID; if (fss.name[0] == 0) { ret->pb.dirInfo.ioFDirIndex = -1; } else { ret->pb.dirInfo.ioFDirIndex = 0; } if (PBGetCatInfo(&ret->pb, false) != noErr) { goto ff1_err2; } if (ret->pb.hFileInfo.ioFlAttrib & 0x10) { ret->tagid = ret->pb.dirInfo.ioDrDirID; } else { ret->tagid = ret->pb.hFileInfo.ioFlParID; } ret->eoff = FALSE; ret->index = 1; if (file_listnext((FLISTH)ret, fli) == SUCCESS) { return((FLISTH)ret); } ff1_err2: _MFREE(ret); ff1_err1: return(NULL); }
void i286a_setextsize(UINT32 size) { if (CPU_EXTMEMSIZE != size) { if (CPU_EXTMEM) { _MFREE(CPU_EXTMEM); CPU_EXTMEM = NULL; } if (size) { CPU_EXTMEM = (BYTE *)_MALLOC(size + 16, "EXTMEM"); if (CPU_EXTMEM == NULL) { size = 0; } } CPU_EXTMEMSIZE = size; } i286acore.e.ems[0] = mem + 0xc0000; i286acore.e.ems[1] = mem + 0xc4000; i286acore.e.ems[2] = mem + 0xc8000; i286acore.e.ems[3] = mem + 0xcc000; }
EXTROMH extromio_open(const OEMCHAR *filename, UINT type) { EXTROMH ret; HRSRC hrsrc; HGLOBAL hg; ret = (EXTROMH)_MALLOC(sizeof(_EXTROMH), filename); if (ret == NULL) { goto erope_err1; } ret->type = type; if (type == EXTROMIO_FILE) { ret->fh = (void *)file_open_c(filename); if ((FILEH)ret->fh != FILEH_INVALID) { return(ret); } } else if (type == EXTROMIO_RES) { #if defined(OSLANG_UTF8) TCHAR tchr[MAX_PATH]; oemtotchar(tchr, NELEMENTS(tchr), filename, -1); hrsrc = FindResource(hInst, tchr, str_extrom); #else hrsrc = FindResource(hInst, filename, str_extrom); #endif if (hrsrc) { hg = LoadResource(hInst, hrsrc); ret->fh = (void *)LockResource(hg); ret->pos = 0; ret->size = SizeofResource(hInst, hrsrc); return(ret); } } _MFREE(ret); erope_err1: return(NULL); }
static void midirelease(COMMNG self) { CMMIDI midi; midi = (CMMIDI)(self + 1); if (midi->opened & CMMIDI_MIDIIN) { if (midi->opened & CMMIDI_MIDIINSTART) { /* XXX */ } close(midi->hmidiin); } if (midi->opened & CMMIDI_MIDIOUT) { waitlastexclusiveout(midi); close(midi->hmidiout); } #if defined(VERMOUTH_LIB) if (midi->opened & CMMIDI_VERMOUTH) { midiout_destroy(midi->vermouth); } #endif _MFREE(self); }
void dlgs_drawbmp(HDC hdc, UINT8 *bmp) { BMPFILE *bf; BMPINFO *bi; BMPDATA inf; HBITMAP hbmp; UINT8 *image; HDC hmdc; if (bmp == NULL) { return; } bf = (BMPFILE *)bmp; bi = (BMPINFO *)(bf + 1); if (bmpdata_getinfo(bi, &inf) != SUCCESS) { goto dsdb_err1; } hbmp = CreateDIBSection(hdc, (BITMAPINFO *)bi, DIB_RGB_COLORS, (void **)&image, NULL, 0); if (hbmp == NULL) { goto dsdb_err1; } CopyMemory(image, bmp + (LOADINTELDWORD(bf->bfOffBits)), bmpdata_getdatasize(bi)); hmdc = CreateCompatibleDC(hdc); SelectObject(hmdc, hbmp); if (inf.height < 0) { inf.height *= -1; } BitBlt(hdc, 0, 0, inf.width, inf.height, hmdc, 0, 0, SRCCOPY); DeleteDC(hmdc); DeleteObject(hbmp); dsdb_err1: _MFREE(bmp); }
void SDL_CloseAudio(void) { DWORD i; int retry = 10; if (w_ctrl.opened) { for (i=0; i<w_ctrl.slice; i++) { waveOutUnprepareHeader(w_ctrl.hwave, w_ctrl.wh + i, sizeof(WAVEHDR)); w_ctrl.wh[i].lpData = NULL; } waveOutPause(w_ctrl.hwave); waveOutReset(w_ctrl.hwave); do { if (waveOutClose(w_ctrl.hwave) == MMSYSERR_NOERROR) { _HANDLE_REM(w_ctrl.hwave); break; } Sleep(500); } while(--retry); _MFREE(w_ctrl.wh); w_ctrl.opened = FALSE; } }
UINT oemtext_sjistoutf8(char *dst, UINT dcnt, const char *src, UINT scnt) { UINT leng; UINT16 *ucs2; UINT ret; (void)scnt; leng = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, src, scnt, NULL, 0); if (leng == 0) { return(0); } ucs2 = (UINT16 *)_MALLOC(leng * sizeof(UINT16), ""); if (ucs2 == NULL) { return(0); } MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, src, scnt, (WCHAR *)ucs2, leng); if (((SINT)scnt) < 0) { leng = (UINT)-1; } ret = codecnv_ucs2toutf8(dst, dcnt, ucs2, leng); _MFREE(ucs2); return(ret); }
UINT oemtext_utf8tomb(UINT cp, char *dst, UINT dcnt, const char *src, UINT scnt) { UINT leng; wchar_t *ucs2; UINT ret; (void)scnt; leng = codecnv_utf8toucs2(NULL, 0, src, scnt); if (leng == 0) { return(0); } ucs2 = (wchar_t *)_MALLOC(leng * sizeof(wchar_t), ""); if (ucs2 == NULL) { return(0); } codecnv_utf8toucs2((UINT16 *)ucs2, leng, src, scnt); if (((SINT)scnt) < 0) { leng = (UINT)-1; } ret = WideCharToMultiByte(cp, 0, ucs2, leng, dst, dcnt, NULL, NULL); _MFREE(ucs2); return(ret); }
UINT oemtext_utf8tosjis(char *dst, UINT dcnt, const char *src, UINT scnt) { UINT leng; UINT16 *ucs2; UINT ret; (void)scnt; leng = codecnv_utf8toucs2(NULL, 0, src, scnt); if (leng == 0) { return(0); } ucs2 = (UINT16 *)_MALLOC(leng * sizeof(UINT16), ""); if (ucs2 == NULL) { return(0); } codecnv_utf8toucs2(ucs2, leng, src, scnt); if (((SINT)scnt) < 0) { leng = (UINT)-1; } ret = WideCharToMultiByte(CP_ACP, 0, (WCHAR *)ucs2, leng, dst, dcnt, NULL, NULL); _MFREE(ucs2); return(ret); }
void file_listclose(FLISTH hdl) { if (hdl) { _MFREE(hdl); } }
int sndogg_open(SMIXTRACK trk) { __OV *ov; char *buffer; UINT r; int bytes; int i; int result; ov = (__OV *)_MALLOC(sizeof(__OV), "__OV"); if (ov == NULL) { goto ovopn_next; } ZeroMemory(ov, sizeof(__OV)); r = sndmix_dataload(trk, trk->maxdatas); if ((r == (UINT)-1) || (r == 0)) { goto ovopn_next2; } buffer = ogg_sync_buffer(&ov->oy, trk->maxdatas); CopyMemory(buffer, trk->data, r); ogg_sync_wrote(&ov->oy, (int)r); if (ogg_sync_pageout(&ov->oy, &ov->og) != 1) { TRACEOUT(("Input does not appear to be an Ogg bitstream.")); goto ovopn_next2; } ogg_stream_init(&ov->os, ogg_page_serialno(&ov->og)); sndmix_datatrash(trk, (UINT)-1); vorbis_info_init(&ov->vi); vorbis_comment_init(&ov->vc); if (ogg_stream_pagein(&ov->os, &ov->og) < 0) { TRACEOUT(("Error reading first page of Ogg bitstream data.")); goto ovopn_err1; } if (ogg_stream_packetout(&ov->os, &ov->op) != 1) { TRACEOUT(("Error reading initial header packet.")); goto ovopn_err1; } if (vorbis_synthesis_headerin(&ov->vi, &ov->vc, &ov->op) < 0) { TRACEOUT(("This Ogg bitstream does not contain Vorbis audio data.")); goto ovopn_err1; } i = 0; while(i < 2) { while(i < 2) { result = ogg_sync_pageout(&ov->oy, &ov->og); if (result == 0) { break; } if (result == 1) { ogg_stream_pagein(&ov->os, &ov->og); while(i < 2) { result = ogg_stream_packetout(&ov->os, &ov->op); if (result == 0) { break; } if (result < 0) { TRACEOUT(("Corrupt secondary header. Exiting.")); goto ovopn_err1; } vorbis_synthesis_headerin(&ov->vi, &ov->vc, &ov->op); i++; } } } buffer = ogg_sync_buffer(&ov->oy, 4096); bytes = sndmix_dataread(trk, buffer, 4096); if ((bytes == 0) && (i < 2)) { TRACEOUT(("End of file before finding all Vorbis headers!")); return(SNDMIX_FAILURE); } ogg_sync_wrote(&ov->oy, bytes); } trk->snd = ov; trk->dec = (DECFN)ogg_dec; trk->decend = ogg_decend; trk->samprate = ov->vi.rate; trk->channels = ov->vi.channels; trk->block = 4096; trk->blksamp = 4096 / ov->vi.channels; trk->bit = 16; #if defined(SOUND_MOREINFO) trk->bps = 0; trk->fmt = WAVEFMT_OGG; CopyMemory(trk->info, "Ogg vorbis", 11); #endif vorbis_synthesis_init(&ov->vd, &ov->vi); vorbis_block_init(&ov->vd, &ov->vb); return(SNDMIX_SUCCESS); ovopn_err1: ogg_sync_clear(&ov->oy); _MFREE(ov); return(SNDMIX_FAILURE); ovopn_next2: _MFREE(ov); ovopn_next: return(SNDMIX_NOTSUPPORT); }
void *fontmng_create(int size, UINT type, const char *fontface) { int ptsize; int fontalign; int fontwork; int allocsize; FNTMNG ret; if (size < 0) { size = -size; } if (size < 6) { size = 6; } else if (size > 128) { size = 128; } if (size < 10) { type |= FDAT_ALIAS; } else if (size < 16) { type &= ~FDAT_BOLD; } ptsize = size; if (type & FDAT_ALIAS) { ptsize *= 2; } fontalign = sizeof(_FNTDAT) + (size * size); fontalign = (fontalign + 3) & (~3); #if defined(FONTMNG_CACHE) fontwork = fontalign * FONTMNG_CACHE; #else fontwork = fontalign; #endif allocsize = sizeof(_FNTMNG) + fontwork; ret = (FNTMNG)_MALLOC(allocsize, "font mng"); if (ret == NULL) { goto fmc_err1; } ZeroMemory(ret, allocsize); ret->fontsize = size; ret->fonttype = type; ret->ptsize = ptsize; ret->fontalign = fontalign; ret->ttf_font = TTF_OpenFont(fontname, ptsize); if (ret->ttf_font == NULL) { fprintf(stderr, "Couldn't load %d points font from %s: %s\n", ptsize, fontname, SDL_GetError()); goto fmc_err2; } return(ret); fmc_err2: _MFREE(ret); fmc_err1: (void)fontface; return(NULL); }
void cd_destroy(SXSIDEV sxsi) { _MFREE((CDINFO)sxsi->hdl); }
int SDL_OpenAudio(SDL_AudioSpec *desired, SDL_AudioSpec *obtained) { char *errorstr; DWORD type; int devs; int num; DWORD i; WAVEOUTCAPS woc; WAVEFORMATEX wfex; DWORD slice; DWORD bufsize; DWORD allocsize; WAVEHDR *wh; char *buf; HWAVEOUT hwave; errorstr = NULL; if (w_ctrl.opened) { errorstr = "Audio device is already opened"; goto soa_err1; } if (desired == NULL) { errorstr = "SDL_OpenAudio() disired = (NULL)"; goto soa_err1; } if (desired->callback == NULL) { errorstr = "SDL_OpenAudio() passed a NULL callback"; goto soa_err1; } i = desired->samples; if (i) { while(!(i & 1)) { i >>= 1; } } if (i != 1) { errorstr = "buffer size must be power of 2"; goto soa_err1; } switch(desired->freq) { case 11025: type = 0; break; case 22050: type = 2; break; case 44100: type = 4; break; default: errorstr = "unsupport out sampling rate"; goto soa_err1; } switch(desired->channels) { case 1: type++; break; case 2: break; default: errorstr = "1 (mono) and 2 (stereo) channels supported"; goto soa_err1; } type = capsfmt[type]; devs = waveOutGetNumDevs(); for (num=0; num<devs; num++) { if (waveOutGetDevCaps(num, &woc, sizeof(woc)) == MMSYSERR_NOERROR) { if (woc.dwFormats & type) { break; } } } if ((num >= devs) && (type != WAVE_FORMAT_2S16)) { for (num=0; num<devs; num++) { if (waveOutGetDevCaps(num, &woc, sizeof(woc)) == MMSYSERR_NOERROR) { if (woc.dwFormats & WAVE_FORMAT_2S16) { break; } } } } if (num >= devs) { errorstr = "unsupport sound device"; goto soa_err1; } slice = 4; bufsize = desired->samples * 2 * desired->channels; allocsize = (sizeof(WAVEHDR) + bufsize) * slice; wh = (WAVEHDR *)_MALLOC(allocsize, "waveout"); if (wh == NULL) { errorstr = "memory allocate error"; goto soa_err1; } ZeroMemory(wh, allocsize); buf = (char *)(wh + slice); for (i=0; i<slice; i++) { wh[i].lpData = buf; wh[i].dwBufferLength = bufsize; wh[i].dwUser = i; buf += bufsize; } w_ctrl.slice = slice; w_ctrl.samples = desired->samples; w_ctrl.bufsize = bufsize; w_ctrl.usercb = desired->callback; w_ctrl.userdata = desired->userdata; w_ctrl.wh = wh; ZeroMemory(&wfex, sizeof(wfex)); wfex.wFormatTag = WAVE_FORMAT_PCM; wfex.nSamplesPerSec = desired->freq; wfex.wBitsPerSample = 16; wfex.nChannels = desired->channels; wfex.nBlockAlign = wfex.nChannels * (wfex.wBitsPerSample / 8); wfex.nAvgBytesPerSec = wfex.nSamplesPerSec * wfex.nBlockAlign; #if 1 if (waveOutOpen(&hwave, num, &wfex, (DWORD)__sdl_hWnd, 0, CALLBACK_WINDOW) != MMSYSERR_NOERROR) #else if (waveOutOpen(&hwave, num, &wfex, (DWORD)hwavecb, 0, CALLBACK_FUNCTION) != MMSYSERR_NOERROR) #endif { errorstr = "waveOutOpen error"; goto soa_err2; } w_ctrl.opened = TRUE; w_ctrl.hwave = hwave; for (i=0; i<slice; i++) { waveOutPrepareHeader(hwave, wh + i, sizeof(WAVEHDR)); waveOutWrite(hwave, wh + i, sizeof(WAVEHDR)); } return(0); soa_err2: _MFREE(wh); soa_err1: if (errorstr) { __sdl_seterror(errorstr); } return(-1); }
WINLOCEX winlocex_create(HWND base, const HWND *child, UINT count) { WINLOCEX ret; HWND *list; UINT inlist; UINT i; UINT j; HWND hwnd; UINT allocsize; WLEXWND *wnd; RECT rect; UINT8 connect; WLEXWND *p; if (child == NULL) { count = 0; } ret = NULL; list = NULL; inlist = 0; if (count) { list = (HWND *)_MALLOC(count * sizeof(HWND *), "wnd list"); if (list == NULL) { goto wlecre_err1; } for (i=0; i<count; i++) { hwnd = child[i]; if ((hwnd != NULL) && (hwnd != base) && (!(GetWindowLong(hwnd, GWL_STYLE) & (WS_MAXIMIZE | WS_MINIMIZE)))) { for (j=0; j<inlist; j++) { if (list[j] == hwnd) { break; } } if (j >= inlist) { list[inlist++] = hwnd; } } } } allocsize = sizeof(_WINLOCEX) + (sizeof(WLEXWND) * inlist); ret = (WINLOCEX)_MALLOC(allocsize, "winlocex"); if (ret == NULL) { goto wlecre_err2; } ZeroMemory(ret, allocsize); wnd = (WLEXWND *)(ret + 1); if (base) { // 親と接続されてる? ret->base = base; GetWindowRect(base, &ret->rect); for (i=0; i<inlist; i++) { hwnd = list[i]; if (hwnd) { GetWindowRect(hwnd, &rect); connect = isconnect(&ret->rect, &rect); if (connect) { list[i] = NULL; wnd->hwnd = hwnd; CopyMemory(&wnd->rect, &rect, sizeof(RECT)); wnd->connect = connect; // wnd->parent = 0; wnd++; ret->count++; } } } // 子と接続されてる? p = (WLEXWND *)(ret + 1); for (i=0; i<ret->count; i++, p++) { for (j=0; j<inlist; j++) { hwnd = list[j]; if (hwnd) { GetWindowRect(hwnd, &rect); connect = isconnect(&p->rect, &rect); if (connect) { list[j] = NULL; wnd->hwnd = hwnd; CopyMemory(&wnd->rect, &rect, sizeof(RECT)); wnd->connect = connect; wnd->parent = i + 1; wnd++; ret->count++; } } } } } for (i=0; i<inlist; i++) { hwnd = list[i]; if (hwnd) { wnd->hwnd = hwnd; GetWindowRect(hwnd, &wnd->rect); wnd++; ret->count++; } } wlecre_err2: if (list) { _MFREE(list); } wlecre_err1: return(ret); }
void variant_destory(void *val) { if (val) { _MFREE(val); } }
void vramdraw_savebmp(int num, const char *dir, const char *name, int pos, const char *credit0, const char *credit1) { int i; char path[MAX_PATH]; char work[32]; BMPDATA inf; VRAMHDL vram; UINT tmp; UINT bmpsize; BMPFILE bf; BMPINFO bi; BYTE *dat; FILEH fh; if ((num < 0) || (num >= GAMECORE_MAXVRAM) || (name == NULL)) { goto vdsb_err1; } if (dir == NULL) { dir = ""; } for (i=0; i<100; i++) { milstr_ncpy(path, dir, sizeof(path)); milstr_ncat(path, name, sizeof(path)); sprintf(work, "%02u.bmp", i); milstr_ncat(path, work, sizeof(path)); if (file_attr(path) == -1) { break; } taskmng_rol(); } if (i >= 100) { goto vdsb_err1; } vram = vram_copy(gamecore.vram[num]); if (vram == NULL) { goto vdsb_err1; } creditmix(vram, pos, credit1, 0x000000); creditmix(vram, pos, credit0, 0xffffff); inf.width = vram->width; inf.height = vram->height; inf.bpp = 24; bmpdata_setinfo(&bi, &inf, TRUE); bmpsize = bmpdata_getdatasize(&bi); ZeroMemory(&bf, sizeof(bf)); bf.bfType[0] = 'B'; bf.bfType[1] = 'M'; tmp = sizeof(BMPFILE) + sizeof(BMPINFO); STOREINTELDWORD(bf.bfOffBits, tmp); tmp += bmpsize; STOREINTELDWORD(bf.bfSize, tmp); dat = bmpdata_bmp24cnv(&bi, vram); if (dat == NULL) { goto vdsb_err2; } fh = file_create(path); if (fh == FILEH_INVALID) { goto vdsb_err3; } file_write(fh, &bf, sizeof(bf)); file_write(fh, &bi, sizeof(bi)); file_write(fh, dat, bmpsize); file_close(fh); vdsb_err3: _MFREE(dat); vdsb_err2: vram_destroy(vram); vdsb_err1: return; }
UINT8 fontx1_read(const OEMCHAR *filename, UINT8 loading) { FILEH fh; UINT8 *work; OEMCHAR fname[MAX_PATH]; work = (UINT8 *)_MALLOC(306176, "x1font"); if (work == NULL) { goto frx1_err1; } file_cpyname(fname, filename, NELEMENTS(fname)); // 8dot ANKを読み込む必要はある? if (loading & FONT_ANK8) { file_cutname(fname); file_catname(fname, x1ank1name, NELEMENTS(fname)); fh = file_open_rb(fname); if (fh != FILEH_INVALID) { if (file_read(fh, work, 2048) == 2048) { loading &= ~FONT_ANK8; fontdata_ank8store(work + 0x100, 0x20, 0x60); fontdata_ank8store(work + 0x500, 0xa0, 0x40); } file_close(fh); } } // 16dot ANKを読み込む必要はあるか? if (loading & FONTLOAD_ANK) { file_cutname(fname); file_catname(fname, x1ank2name, NELEMENTS(fname)); fh = file_open_rb(fname); if (fh != FILEH_INVALID) { if (file_read(fh, work, 4096) == 4096) { // 16dot ASCIIを読む必要があるか if (loading & FONT_ANK16a) { loading &= ~FONT_ANK16a; CopyMemory(fontrom + 0x80200, work + 0x200, 0x60*16); fontdata_patch16a(); } // 16dot ANK(0x80〜)を読む必要があるか if (loading & FONT_ANK16b) { loading &= ~FONT_ANK16b; CopyMemory(fontrom + 0x80a00, work + 0xa00, 0x40*16); fontdata_patch16b(); } } file_close(fh); } } // 漢字を読み込む必要はあるか? if (loading & (FONT_KNJ1 | FONT_KNJ2)) { file_cutname(fname); file_catname(fname, x1knjname, NELEMENTS(fname)); fh = file_open_rb(fname); if (fh != FILEH_INVALID) { if (file_read(fh, work, 306176) == 306176) { // 第一水準漢字を読み込む? if (loading & FONT_KNJ1) { loading &= ~FONT_KNJ1; x1knjcpy(fontrom, work, 0x01, 0x30); fontdata_patchjis(); } // 第二水準を読む必要はある? if (loading & FONT_KNJ2) { loading &= ~FONT_KNJ2; x1knjcpy(fontrom, work, 0x31, 0x50); } } file_close(fh); } } // メモリを解放する _MFREE(work); frx1_err1: return(loading); }
static void jsrelease(COMMNG self) { _MFREE(self); }
// イメージファイルの実体を開き、各種情報構築 BRESULT setsxsidev(SXSIDEV sxsi, const OEMCHAR *path, const _CDTRK *trk, UINT trks) { FILEH fh; long totals; CDINFO cdinfo; UINT mediatype; UINT i; #ifdef TOCLOGOUT OEMCHAR logpath[MAX_PATH]; OEMCHAR logbuf[2048]; TEXTFILEH tfh; #endif // trk、trksは有効な値が設定済みなのが前提 if ((trk == NULL) || (trks == 0)) { goto sxsiope_err1; } fh = file_open_rb(path); if (fh == FILEH_INVALID) { goto sxsiope_err1; } cdinfo = (CDINFO)_MALLOC(sizeof(_CDINFO), path); if (cdinfo == NULL) { goto sxsiope_err2; } ZeroMemory(cdinfo, sizeof(_CDINFO)); cdinfo->fh = fh; trks = min(trks, NELEMENTS(cdinfo->trk) - 1); CopyMemory(cdinfo->trk, trk, trks * sizeof(_CDTRK)); #ifdef TOCLOGOUT file_cpyname(logpath, path, NELEMENTS(logpath)); file_cutext(logpath); file_catname(logpath, str_logB, NELEMENTS(logpath)); tfh = textfile_create(logpath, 0x800); if (tfh == NULL) { return(FAILURE); } TOCLOG(OEMTEXT("STR _CDTRK LOG\r\n"), 0); for (i = 0; i < trks; i++) { TOCLOG(OEMTEXT("trk[%02d]\r\n"), i); TOCLOG(OEMTEXT(" adr_ctl = 0x%02X\r\n"), cdinfo->trk[i].adr_ctl); TOCLOG(OEMTEXT(" point = %02d\r\n"), cdinfo->trk[i].point); TOCLOG(OEMTEXT(" [pos0][pos][ ] = [%18I32d]"), cdinfo->trk[i].pos0); TOCLOG(OEMTEXT("[%18I32d][ ]\r\n"), cdinfo->trk[i].pos); TOCLOG(OEMTEXT(" sec[ ][str][end] = [ ][%18I32d]"), cdinfo->trk[i].str_sec); TOCLOG(OEMTEXT("[%18I32d]\r\n"), cdinfo->trk[i].end_sec); TOCLOG(OEMTEXT(" sectors = %I32d\r\n"), cdinfo->trk[i].sectors); TOCLOG(OEMTEXT(" sector_size = %d\r\n"), cdinfo->trk[i].sector_size); TOCLOG(OEMTEXT(" sector [pregap][start][end] = [%18I32d]"), cdinfo->trk[i].pregap_sector); TOCLOG(OEMTEXT("[%18I32d]"), cdinfo->trk[i].start_sector); TOCLOG(OEMTEXT("[%18I32d]\r\n"), cdinfo->trk[i].end_sector); TOCLOG(OEMTEXT(" img_sec[pregap][start][end] = [%18I32d]"), cdinfo->trk[i].img_pregap_sec); TOCLOG(OEMTEXT("[%18I32d]"), cdinfo->trk[i].img_start_sec); TOCLOG(OEMTEXT("[%18I32d]\r\n"), cdinfo->trk[i].img_end_sec); TOCLOG(OEMTEXT(" offset [pregap][start][end] = [0x%016I64X]"), cdinfo->trk[i].pregap_offset); TOCLOG(OEMTEXT("[0x%016I64X]"), cdinfo->trk[i].start_offset); TOCLOG(OEMTEXT("[0x%016I64X]\r\n"), cdinfo->trk[i].end_offset); TOCLOG(OEMTEXT(" pregap_sectors = %I32d\r\n"), cdinfo->trk[i].pregap_sectors); TOCLOG(OEMTEXT(" track_sectors = %I32d\r\n"), cdinfo->trk[i].track_sectors); } TOCLOG(OEMTEXT("END _CDTRK LOG\r\n"), 0); textfile_close(tfh); #endif #if 1 if (sxsi->totals == -1) { totals = set_trkinfo(fh, cdinfo->trk, trks, 0); if (totals < 0) { goto sxsiope_err3; } sxsi->totals = totals; } #else totals = issec(fh, cdinfo->trk, trks); // とりあえず sxsi->read = sec2048_read; totals = issec2048(cdinfo->fh); if (totals < 0) { sxsi->read = sec2352_read; totals = issec2352(cdinfo->fh); } if (totals < 0) { sxsi->read = sec2448_read; totals = issec2448(cdinfo->fh); } if (totals < 0) { sxsi->read = sec_read; totals = issec(cdinfo->fh, cdinfo->trk, trks); } if (totals < 0) { goto sxsiope_err3; } #endif mediatype = 0; for (i = 0; i < trks; i++) { if (cdinfo->trk[i].adr_ctl == TRACK_DATA) { mediatype |= SXSIMEDIA_DATA; } else if (cdinfo->trk[i].adr_ctl == TRACK_AUDIO) { mediatype |= SXSIMEDIA_AUDIO; } } // リードアウトトラックを生成 cdinfo->trk[trks].adr_ctl = 0x10; cdinfo->trk[trks].point = 0xaa; // cdinfo->trk[trks].pos = totals; cdinfo->trk[trks].pos = sxsi->totals; cdinfo->trks = trks; file_cpyname(cdinfo->path, path, NELEMENTS(cdinfo->path)); sxsi->reopen = cd_reopen; sxsi->close = cd_close; sxsi->destroy = cd_destroy; sxsi->hdl = (INTPTR)cdinfo; // sxsi->totals = totals; sxsi->cylinders = 0; sxsi->size = 2048; sxsi->sectors = 1; sxsi->surfaces = 1; sxsi->headersize = 0; sxsi->mediatype = mediatype; #ifdef TOCLOGOUT file_cpyname(logpath, path, NELEMENTS(logpath)); file_cutext(logpath); file_catname(logpath, str_logA, NELEMENTS(logpath)); tfh = textfile_create(logpath, 0x800); if (tfh == NULL) { return(FAILURE); } TOCLOG(OEMTEXT("STR _CDTRK LOG\r\n"), 0); for (i = 0; i < trks; i++) { TOCLOG(OEMTEXT("trk[%02d]\r\n"), i); TOCLOG(OEMTEXT(" adr_ctl = 0x%02X\r\n"), cdinfo->trk[i].adr_ctl); TOCLOG(OEMTEXT(" point = %02d\r\n"), cdinfo->trk[i].point); TOCLOG(OEMTEXT(" [pos0][pos][ ] = [%18I32d]"), cdinfo->trk[i].pos0); TOCLOG(OEMTEXT("[%18I32d][ ]\r\n"), cdinfo->trk[i].pos); TOCLOG(OEMTEXT(" sec[ ][str][end] = [ ][%18I32d]"), cdinfo->trk[i].str_sec); TOCLOG(OEMTEXT("[%18I32d]\r\n"), cdinfo->trk[i].end_sec); TOCLOG(OEMTEXT(" sectors = %I32d\r\n"), cdinfo->trk[i].sectors); TOCLOG(OEMTEXT(" sector_size = %d\r\n"), cdinfo->trk[i].sector_size); TOCLOG(OEMTEXT(" sector [pregap][start][end] = [%18I32d]"), cdinfo->trk[i].pregap_sector); TOCLOG(OEMTEXT("[%18I32d]"), cdinfo->trk[i].start_sector); TOCLOG(OEMTEXT("[%18I32d]\r\n"), cdinfo->trk[i].end_sector); TOCLOG(OEMTEXT(" img_sec[pregap][start][end] = [%18I32d]"), cdinfo->trk[i].img_pregap_sec); TOCLOG(OEMTEXT("[%18I32d]"), cdinfo->trk[i].img_start_sec); TOCLOG(OEMTEXT("[%18I32d]\r\n"), cdinfo->trk[i].img_end_sec); TOCLOG(OEMTEXT(" offset [pregap][start][end] = [0x%016I64X]"), cdinfo->trk[i].pregap_offset); TOCLOG(OEMTEXT("[0x%016I64X]"), cdinfo->trk[i].start_offset); TOCLOG(OEMTEXT("[0x%016I64X]\r\n"), cdinfo->trk[i].end_offset); TOCLOG(OEMTEXT(" pregap_sectors = %I32d\r\n"), cdinfo->trk[i].pregap_sectors); TOCLOG(OEMTEXT(" track_sectors = %I32d\r\n"), cdinfo->trk[i].track_sectors); } TOCLOG(OEMTEXT("END _CDTRK LOG\r\n"), 0); textfile_close(tfh); #endif return(SUCCESS); sxsiope_err3: _MFREE(cdinfo); sxsiope_err2: file_close(fh); sxsiope_err1: return(FAILURE); }
UINT8 fontpc98_read(const OEMCHAR *filename, UINT8 loading) { FILEH fh; BMPFILE bf; BMPINFO bi; UINT8 *bmpdata; BMPDATA bd; long fptr; if (!(loading & FONTLOAD_16)) { goto fr98_err1; } // ファイルをオープン fh = file_open_rb(filename); if (fh == FILEH_INVALID) { goto fr98_err1; } // BITMAPFILEHEADER の読み込み if ((file_read(fh, &bf, sizeof(bf)) != sizeof(bf)) || (bf.bfType[0] != 'B') || (bf.bfType[1] != 'M')) { goto fr98_err2; } // BITMAPINFOHEADER の読み込み if ((file_read(fh, &bi, sizeof(bi)) != sizeof(bi)) || (bmpdata_getinfo(&bi, &bd) != SUCCESS) || (bd.width != BMPWIDTH) || (bd.height != BMPHEIGHT) || (bd.bpp != 1) || (LOADINTELDWORD(bi.biSizeImage) != BMPDATASIZE)) { goto fr98_err2; } // BITMAPデータ頭だし fptr = LOADINTELDWORD(bf.bfOffBits); if (file_seek(fh, fptr, FSEEK_SET) != fptr) { goto fr98_err2; } // メモリアロケート bmpdata = (UINT8 *)_MALLOC(BMPDATASIZE, "pc98font"); if (bmpdata == NULL) { goto fr98_err2; } // BITMAPデータの読みだし if (file_read(fh, bmpdata, BMPDATASIZE) != BMPDATASIZE) { goto fr98_err3; } // 8x16 フォント(〜0x7f)を読む必要がある? if (loading & FONT_ANK16a) { loading &= ~FONT_ANK16a; pc98ankcpy(fontrom + 0x80000, bmpdata, 0x000, 0x080); } // 8x16 フォント(0x80〜)を読む必要がある? if (loading & FONT_ANK16b) { loading &= ~FONT_ANK16b; pc98ankcpy(fontrom + 0x80800, bmpdata, 0x080, 0x100); } // 第一水準漢字を読む必要がある? if (loading & FONT_KNJ1) { loading &= ~FONT_KNJ1; pc98knjcpy(fontrom, bmpdata, 0x01, 0x30); } // 第二水準漢字を読む必要がある? if (loading & FONT_KNJ2) { loading &= ~FONT_KNJ2; pc98knjcpy(fontrom, bmpdata, 0x30, 0x56); } // 拡張漢字を読む必要がある? if (loading & FONT_KNJ3) { loading &= ~FONT_KNJ3; pc98knjcpy(fontrom, bmpdata, 0x58, 0x60); } fr98_err3: _MFREE(bmpdata); fr98_err2: file_close(fh); fr98_err1: return(loading); }
void winlocex_destroy(WINLOCEX wle) { if (wle) { _MFREE(wle); } }
UINT8 fontx68k_read(const OEMCHAR *filename, UINT8 loading) { FILEH fh; UINT8 *work; // ファイルをオープン fh = file_open_rb(filename); if (fh == FILEH_INVALID) { goto fr68_err1; } // メモリアロケート work = (UINT8 *)_MALLOC(0x3b800, "x68kfont"); if (work == NULL) { goto fr68_err2; } // CGROM.DAT の読み込み if (file_read(fh, work, 0x3b800) != 0x3b800) { goto fr68_err3; } // 8dot ANKを読む必要があるか if (loading & FONT_ANK8) { loading &= ~FONT_ANK8; fontdata_ank8store(work + 0x3a100, 0x20, 0x60); fontdata_ank8store(work + 0x3a500, 0xa0, 0x40); } // 16dot ASCIIを読む必要があるか if (loading & FONT_ANK16a) { loading &= ~FONT_ANK16a; CopyMemory(fontrom + 0x80200, work + 0x3aa00, 0x60*16); fontdata_patch16a(); } // 16dot ANK(0x80~)を読む必要があるか if (loading & FONT_ANK16b) { loading &= ~FONT_ANK16b; CopyMemory(fontrom + 0x80a00, work + 0x3b200, 0x40*16); fontdata_patch16b(); } // 第一水準漢字を読み込む? if (loading & FONT_KNJ1) { loading &= ~FONT_KNJ1; x68kknjcpy(fontrom, work, 0x01, 0x30); fontdata_patchjis(); } // 第二水準を読む必要はある? if (loading & FONT_KNJ2) { loading &= ~FONT_KNJ2; x68kknjcpy(fontrom, work, 0x30, 0x60); } fr68_err3: _MFREE(work); fr68_err2: file_close(fh); fr68_err1: return(loading); }
UINT8 fontv98_read(const OEMCHAR *filename, UINT8 loading) { FILEH fh; UINT8 *v98fnt; if (!(loading & FONTLOAD_ALL)) { goto frv_err1; } // ファイルをオープン fh = file_open_rb(filename); if (fh == FILEH_INVALID) { goto frv_err1; } v98fnt = (UINT8 *)_MALLOC(V98FILESIZE, "v98font"); if (v98fnt == NULL) { goto frv_err2; } // FONT.ROM の読み込み if (file_read(fh, v98fnt, V98FILESIZE) != V98FILESIZE) { goto frv_err3; } // 8x8 フォントを読む必要がある? if (loading & FONT_ANK8) { loading &= ~FONT_ANK8; fontdata_ank8store(v98fnt, 0, 256); } // 8x16 フォント(〜0x7f)を読む必要がある? if (loading & FONT_ANK16a) { loading &= ~FONT_ANK16a; CopyMemory(fontrom + 0x80000, v98fnt + 0x0800, 16*128); } // 8x16 フォント(0x80〜)を読む必要がある? if (loading & FONT_ANK16b) { loading &= ~FONT_ANK16b; CopyMemory(fontrom + 0x80800, v98fnt + 0x1000, 16*128); } // 第一水準漢字を読む必要がある? if (loading & FONT_KNJ1) { loading &= ~FONT_KNJ1; v98knjcpy(fontrom, v98fnt, 0x01, 0x30); } // 第二水準漢字を読む必要がある? if (loading & FONT_KNJ2) { loading &= ~FONT_KNJ2; v98knjcpy(fontrom, v98fnt, 0x30, 0x56); } // 拡張漢字を読む必要がある? if (loading & FONT_KNJ3) { loading &= ~FONT_KNJ3; v98knjcpy(fontrom, v98fnt, 0x58, 0x5d); } frv_err3: _MFREE(v98fnt); frv_err2: file_close(fh); // 後始末 frv_err1: return(loading); }
BOOL getogg_open(GETSND snd, UINT8 *ptr, UINT size) { __OV *ov; char *buffer; int bytes; int i; int result; snd->datptr = ptr; snd->datsize = size; ov = (__OV *)_MALLOC(sizeof(__OV), "__OV"); if (ov == NULL) { goto ovopn_err0; } ZeroMemory(ov, sizeof(__OV)); buffer = ogg_sync_buffer(&ov->oy, 4096); bytes = snd_read(snd, buffer, 4096); ogg_sync_wrote(&ov->oy, bytes); if (ogg_sync_pageout(&ov->oy, &ov->og) != 1) { TRACEOUT(("Input does not appear to be an Ogg bitstream.")); goto ovopn_err1; } ogg_stream_init(&ov->os, ogg_page_serialno(&ov->og)); vorbis_info_init(&ov->vi); vorbis_comment_init(&ov->vc); if (ogg_stream_pagein(&ov->os, &ov->og) < 0) { TRACEOUT(("Error reading first page of Ogg bitstream data.")); goto ovopn_err1; } if (ogg_stream_packetout(&ov->os, &ov->op) != 1) { TRACEOUT(("Error reading initial header packet.")); goto ovopn_err1; } if (vorbis_synthesis_headerin(&ov->vi, &ov->vc, &ov->op) < 0) { TRACEOUT(("This Ogg bitstream does not contain Vorbis audio data.")); goto ovopn_err1; } i = 0; while(i < 2) { while(i < 2) { result = ogg_sync_pageout(&ov->oy, &ov->og); if (result == 0) { break; } if (result == 1) { ogg_stream_pagein(&ov->os, &ov->og); while(i < 2) { result = ogg_stream_packetout(&ov->os, &ov->op); if (result == 0) { break; } if (result < 0) { TRACEOUT(("Corrupt secondary header. Exiting.")); goto ovopn_err1; } vorbis_synthesis_headerin(&ov->vi, &ov->vc, &ov->op); i++; } } } buffer = ogg_sync_buffer(&ov->oy, 4096); bytes = snd_read(snd, buffer, 4096); if ((bytes == 0) && (i < 2)) { TRACEOUT(("End of file before finding all Vorbis headers!")); return(-1); } ogg_sync_wrote(&ov->oy, bytes); } snd->snd = ov; snd->dec = (GSDEC)ogg_dec; snd->decend = ogg_decend; snd->samplingrate = ov->vi.rate; snd->channels = ov->vi.channels; snd->blocksize = 4096 * 2; snd->blocksamples = 4096 / ov->vi.channels; snd->bit = 16; vorbis_synthesis_init(&ov->vd, &ov->vi); vorbis_block_init(&ov->vd, &ov->vb); return(SUCCESS); ovopn_err1: ogg_sync_clear(&ov->oy); _MFREE(ov); ovopn_err0: return(FAILURE); }
void moviemng_play(const char *fname, SCRN_T *scrn) { static const char ext[][5] = { "", ".AVI", ".MPG", ".avi", ".mpg" }; char movie_file[MAX_PATH] = ""; char path[MAX_PATH]; struct stat st; SDL_SysWMinfo info; ARCFILEH arch; int i; UNUSED(scrn); if (!nomovie_flag) return; memset(&info, 0, sizeof(info)); info.version.major = SDL_MAJOR_VERSION; info.version.minor = SDL_MINOR_VERSION; if (SDL_GetWMInfo(&info) <= 0) return; /* * 1. とりあえずデータディレクトリから検索 */ for (i = 0; i < NELEMENTS(ext); ++i) { milstr_ncpy(path, gamecore.suf.scriptpath, sizeof(path)); milstr_ncat(path, fname, sizeof(path)); cutExtName(path); milstr_ncat(path, ext[i], sizeof(path)); if (stat(path, &st) < 0) continue; if (st.st_mode & S_IFDIR) continue; if (access(path, R_OK) < 0) continue; /* OK */ goto run; } /* * 2. アーカイブ内に存在するか確認 * (こんなあったら嫌だなぁ…) */ for (arch = NULL, i = 0; i < ARCTYPES; ++i) { arch = arcfile_open(i, fname); if (arch) break; } if (arch) { int fd; char *buf; sprintf(path, "/tmp/." APP_NAME "-%s-XXXXXXX", fname); #if defined(HAVE_MKSTEMP) || defined(__NetBSD__) fd = mkstemp(path); #else mktemp(path); fd = open(path, O_RDWR | O_CREAT | O_TRUNC, 0600); #endif if (fd >= 0) { buf = (char *)_MALLOC(arch->size, "movie temp file"); arcfile_seek(arch, arch->pos, SEEK_SET); if (arcfile_read(arch, buf, arch->size) == arch->size) { write(fd, buf, arch->size); close(fd); _MFREE(buf); milstr_ncpy(movie_file,path,sizeof(movie_file)); goto run; } close(fd); _MFREE(buf); } } return; run: inputmng_resetmouse(0); sound_term(); info.info.x11.lock_func(); movie_play(path); info.info.x11.unlock_func(); if (movie_file[0] != '\0') { unlink(movie_file); } sound_init(audio_rate); sound_play(); }
UINT8 fontpc88_read(const OEMCHAR *filename, UINT8 loading) { FILEH fh; UINT8 *work; OEMCHAR fname[MAX_PATH]; work = (UINT8 *)_MALLOC(0x20000, "pc88font"); if (work == NULL) { goto fr88_err1; } file_cpyname(fname, filename, NELEMENTS(fname)); // 第2水準以外を読む必要はある? if (loading & (FONT_ANK8 | FONTLOAD_ANK | FONT_KNJ1)) { // あったら読み込んでみる file_cutname(fname); file_catname(fname, pc88knj1name, NELEMENTS(fname)); fh = file_open_rb(fname); if (fh != FILEH_INVALID) { if (file_read(fh, work, 0x20000) == 0x20000) { // 8dot ANKを読む必要があるか if (loading & FONT_ANK8) { loading &= ~FONT_ANK8; fontdata_ank8store(work + 0x1000, 0, 256); } // 16dot ASCIIを読む必要があるか if (loading & FONT_ANK16a) { loading &= ~FONT_ANK16a; CopyMemory(fontrom + 0x80000, work + 0x0000, 16*128); } // 16dot ANK(0x80〜)を読む必要があるか if (loading & FONT_ANK16b) { loading &= ~FONT_ANK16b; CopyMemory(fontrom + 0x80800, work + 0x0800, 16*128); } // 第一水準漢字を読み込む? if (loading & FONT_KNJ1) { loading &= ~FONT_KNJ1; pc88knjcpy1(fontrom, work, 0x01, 0x30); fontdata_patchjis(); } } // クローズして セクション終わり file_close(fh); } } // 第2水準を読む必要はある? if (loading & FONT_KNJ2) { // あったら読み込んでみる file_cutname(fname); file_catname(fname, pc88knj2name, NELEMENTS(fname)); fh = file_open_rb(fname); if (fh != FILEH_INVALID) { if (file_read(fh, work, 0x20000) == 0x20000) { loading &= ~FONT_KNJ2; pc88knjcpy2(fontrom, work, 0x31, 0x56); } // クローズして セクション終わり file_close(fh); } } // ANKを読み込む必要はある? if (loading & (FONT_ANK8 | FONTLOAD_ANK)) { // あったら読み込んでみる file_cutname(fname); file_catname(fname, pc88ankname, NELEMENTS(fname)); fh = file_open_rb(fname); if (fh != FILEH_INVALID) { // 読み込んでみる if (file_read(fh, work, 0x1800) == 0x1800) { // 8dot ANKを読む必要があるか if (loading & FONT_ANK8) { loading &= ~FONT_ANK8; fontdata_ank8store(work + 0x0000, 0, 256); } // 16dot ASCIIを読む必要があるか if (loading & FONT_ANK16a) { loading &= ~FONT_ANK16a; CopyMemory(fontrom + 0x80000, work + 0x0800, 16*128); } // 16dot ANK(0x80〜)を読む必要があるか if (loading & FONT_ANK16b) { loading &= ~FONT_ANK16b; CopyMemory(fontrom + 0x80800, work + 0x1000, 16*128); } } // クローズして ANKは終わり file_close(fh); } } _MFREE(work); fr88_err1: return(loading); }
static BOOL readflags(SAVEHDL hdl, int num, UINT reg, UINT pos, UINT cnt) { SAVEISF isf; FLAGS flags; SAVEDATA dat; BYTE *ptr; int remain; int size; BMPINFO *bi; UINT bmpsize; UINT type; isf = (SAVEISF)(hdl + 1); if ((num < 0) || (num >= isf->gamesaves)) { goto sfrg_err1; } flags = &gamecore.flags; type = gamecore.sys.type; dat = saveread(isf, num); if (dat == NULL) { goto sfrg_err1; } ptr = dat->ptr + sizeof(_SYSTIME); remain = dat->size - sizeof(_SYSTIME); if (remain < 0) { goto sfrg_err2; } if (type & GAME_SAVEGRPH) { remain -= sizeof(BMPINFO); if (remain < 0) { goto sfrg_err2; } bi = (BMPINFO *)ptr; ptr += sizeof(BMPINFO); bmpsize = bmpdata_getdatasizeex(bi, FALSE); remain -= bmpsize; if (remain < 0) { goto sfrg_err2; } ptr += bmpsize; } size = 0; if (type & GAME_SAVECOM) { size += isf->commsize; } size += flags->flagsize; if (remain < (size + (int)(flags->maxval * 4))) { goto sfrg_err2; } ptr += size; remain -= size; while(cnt) { if ((reg < flags->maxval) && (pos < flags->maxval)) { flags->val[reg] = LOADINTELDWORD(ptr + (pos * 4)); } reg++; pos++; cnt--; } _MFREE(dat); return(SUCCESS); sfrg_err2: _MFREE(dat); sfrg_err1: return(FAILURE); }