JNIEXPORT jint JNICALL Java_uk_org_cardboardbox_wonderdroid_WonderSwan__1execute_1frame(JNIEnv *env, jclass obj, jboolean skip, jboolean audio, jobject framebuffer, jshortArray audiobuffer) { // execute the active frame cycles uint16_t* fb = (uint16_t*) (*env)->GetDirectBufferAddress(env, framebuffer); while (wsExecuteLine(fb, skip) < 144) {}; // grab the audio if we want it jint samples = 0; if(audio){ int16_t* ab = (int16_t*) (*env)->GetShortArrayElements(env, audiobuffer, NULL); samples = (jint) wswan_soundflush(ab); (*env)->ReleaseShortArrayElements(env, audiobuffer, ab, 0); } else { wswan_soundclear(); } // execute the vblank section while (wsExecuteLine(NULL, FALSE) != 0) {} // return the number of new audio samples return samples; }
static void Emulate(EmulateSpecStruct *espec) { espec->DisplayRect.x = 0; espec->DisplayRect.y = 0; espec->DisplayRect.w = 224; espec->DisplayRect.h = 144; if(espec->VideoFormatChanged) WSwan_SetPixelFormat(espec->surface->format); if(espec->SoundFormatChanged) WSwan_SetSoundRate(espec->SoundRate); uint16 butt_data = chee[0] | (chee[1] << 8); WSButtonStatus = butt_data; MDFNMP_ApplyPeriodicCheats(); while(!wsExecuteLine(espec->surface, espec->skip)) { } espec->SoundBufSize = WSwan_SoundFlush(espec->SoundBuf, espec->SoundBufMaxSize); espec->MasterCycles = v30mz_timestamp; v30mz_timestamp = 0; if(IsWSR) { bool needreload = FALSE; static uint16 last; Player_Draw(espec->surface, &espec->DisplayRect, WSRCurrentSong, espec->SoundBuf, espec->SoundBufSize); if((WSButtonStatus & 0x02) && !(last & 0x02)) { WSRCurrentSong++; needreload = 1; } if((WSButtonStatus & 0x08) && !(last & 0x08)) { WSRCurrentSong--; needreload = 1; } if((WSButtonStatus & 0x100) && !(last & 0x100)) needreload = 1; if((WSButtonStatus & 0x01) && !(last & 0x01)) { WSRCurrentSong += 10; needreload = 1; } if((WSButtonStatus & 0x04) && !(last & 0x04)) { WSRCurrentSong -= 10; needreload = 1; } last = WSButtonStatus; if(needreload) Reset(); } }