Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifdef __FB_JS__
- #cmdline "-s gui -Wl '--embed-file rom --embed-file romboot'"
- #endif
- #include "Sameboy.bi"
- #include "fbgfx.bi"
- #ifdef __FB_WIN32__
- #include "windows.bi"
- #include "win\mmsystem.bi"
- #include "MyTDT\minisnd.bas"
- TimeBeginPeriod(1)
- #include "MyTDT\GfxResize.bas"
- #define UseResize
- #endif
- 'static shared as uint32_t bitmap(256*224-1)
- 'GB_random_set_enabled(false);
- dim as GB_gameboy_t ptr pgb
- #define _romboot "romboot/"
- '#define perror(_s) printf(!"Error: '%s'\n",_s): sleep
- const sFilename = "rom/Silver.gbc" 'PokeBlue-II - 2xSPD.gb"
- 'const sFilename = "G:\BackupH\FromData\Emu\GBC\GBC_bgb\Roms\PokeBlue-II - 2xSPD.gb"
- private function rgb_encode cdecl (gb as GB_gameboy_t ptr, r as uint8_t, g as uint8_t,b as uint8_t) as uint32_t
- return rgb(r,g,b)
- end function
- 'pgb = GB_init( GB_alloc() , GB_MODEL_DMG_B ) : GB_load_boot_rom(pgb, _romboot "dmg_boot.bin")
- pgb = GB_init( GB_alloc() , GB_MODEL_SGB2 ) : GB_load_boot_rom(pgb, _romboot "sgb2_boot.bin")
- 'pgb = GB_init( GB_alloc() , GB_MODEL_CGB_E ) : GB_load_boot_rom(pgb, _romboot "cgb_boot.bin")
- 'pgb = GB_init( GB_alloc() , GB_MODEL_CGB_E ) : GB_load_boot_rom(pgb, _romboot "cgb_boot.bin")
- 'pgb = GB_init( GB_alloc() , GB_MODEL_GBP_A ) : GB_load_boot_rom(pgb, _romboot "cgb_boot.bin")
- GB_set_border_mode(pgb, GB_BORDER_ALWAYS)
- 'var ScrWid = GB_get_screen_width(pgb) , ScrHei = GB_get_screen_height(pgb)
- const ScrWid = 256 , ScrHei = 224
- #ifdef UseResize
- gfx.PreResize()
- #endif
- screenres ScrWid,ScrHei,32
- #ifdef UseResize
- gfx.Resize(ScrWid*2,ScrHei*2)
- #endif
- 'GB_set_vblank_callback(pgb, (GB_vblank_callback_t) vblank);
- GB_set_pixels_output(pgb, screenptr)
- GB_set_rgb_encode_callback(pgb, @rgb_encode)
- 'GB_set_log_callback(&gb, log_callback)
- 'GB_set_async_input_callback(pgb, async_input_callback);
- GB_set_color_correction_mode(pgb, GB_COLOR_CORRECTION_EMULATE_HARDWARE)
- 'GB_set_rtc_mode(&gb, GB_RTC_MODE_ACCURATE);
- GB_set_emulate_joypad_bouncing(pgb, false) '// Adds too much noise
- GB_set_rewind_length(pgb,0)
- if GB_load_rom(pgb, sFilename) then perror("Failed to load ROM"): end 1
- dim as byte running = true
- dim as long frames = 0
- dim as uint64_t lltime = 0
- scope 'try to grab SGB border
- const ChkPix = 256*((224-144)\2)
- dim as ulong lTest(ChkPix-1), N, DiffIn,DiffOut
- line(0,0)-(256,224),-1,bf : sleep 50,1
- dim as double dTmr = timer
- screenlock : GB_run_frame(pgb)
- memcpy( @lTest(0) , screenptr+(((224*256)-ChkPix)*4) , ChkPix*4 )
- GB_set_turbo_mode( pgb , true , false )
- GB_set_rendering_disabled( pgb , true )
- for N = 0 to 599
- GB_run_frame(pgb)
- if N=300 then GB_set_rendering_disabled( pgb , false )
- if N>300 andalso memcmp( @lTest(0) , screenptr+(((224*256)-ChkPix)*4) , ChkPix*4 ) then
- memcpy( @lTest(0) , screenptr+(((224*256)-ChkPix)*4) , ChkPix*4 )
- DiffIn += 1 : DiffOut = 0
- elseif DiffIn then
- DiffOut += 1 ': DiffIn = 0
- if DiffOut = 10 then exit for
- end if
- 'screenunlock : sleep 1,1 : screenlock
- next N
- 'printf(!"%i\n",N)
- GB_set_turbo_mode( pgb , false , false )
- GB_set_rendering_disabled( pgb , false )
- GB_switch_model_and_reset( pgb , GB_MODEL_CGB_E ) : GB_load_boot_rom(pgb, _romboot "cgb_boot.bin")
- 'GB_switch_model_and_reset( pgb , GB_MODEL_DMG_B ) : GB_load_boot_rom(pgb, _romboot "dmg_boot.bin")
- if N = 600 then GB_run_frame(pgb)
- GB_set_border_mode(pgb, GB_BORDER_NEVER)
- line ((256-160)\2,(224-144)\2)-step(159,143),-1,bf
- screenunlock
- 'printf(!"%f\n",(timer-dTMR)*1000)
- 'printf("%i ",GB_is_cgb_in_cgb_mode(pgb))
- end scope
- dim shared as long iFrameSkip=0+1
- dim as fb.image ptr pScr = ImageCreate(160,144)
- GB_set_pixels_output(pgb, cast(any ptr,pScr+1))
- function iScanToGameboy( iCode as long ) as long
- select case iCode
- case fb.SC_A , fb.SC_RIGHT : return GB_KEY_RIGHT
- case fb.SC_D , fb.SC_LEFT : return GB_KEY_LEFT
- case fb.SC_W , fb.SC_UP : return GB_KEY_UP
- case fb.SC_S , fb.SC_DOWN : return GB_KEY_DOWN
- case fb.SC_Q , fb.SC_SPACE : return GB_KEY_A
- case fb.SC_E , fb.SC_CONTROL : return GB_KEY_B
- case fb.SC_Z , fb.SC_ENTER: return GB_KEY_START
- case fb.SC_X , fb.SC_LSHIFT , fb.SC_RSHIFT : return GB_KEY_SELECT
- end select
- return -1
- end function
- sub handle_buttons cdecl ( gb as GB_gameboy_t ptr )
- dim as fb.event e
- while screenevent( @e )
- select case e.type
- Case fb.EVENT_KEY_PRESS
- select case e.ascii
- case asc("+") : if iFrameSkip < (9+1) then iFrameSkip += 1
- case asc("-") : if iFrameSkip > (0+1) then iFrameSkip -= 1
- end select
- var iCode = iScanToGameboy( e.scancode )
- if iCode >= 0 then GB_set_key_state( gb , iCode , true )
- Case fb.EVENT_KEY_RELEASE
- var iCode = iScanToGameboy( e.scancode )
- if iCode >= 0 then GB_set_key_state( gb , iCode , false )
- end select
- wend
- end sub
- const AudioFreq = 44100
- static shared as WaveOutStruct ptr pAudio
- pAudio = AudioOpen( AudioFreq , 16 , 2 , 2 )
- sub EmitAudioSample cdecl (pgb as GB_gameboy_t ptr, sample as GB_sample_t)
- const cBlkSam = AudioFreq\10
- static as GB_sample_t tSample(cBlkSam*16-1)
- static as long iCnt : tSample(iCnt) = sample : iCnt += 1
- if iCnt >= cBlkSam then
- if AudioWrite( pAudio , @tSample(0) , cBlkSam*sizeof(GB_sample_t) ) < 0 then
- iCnt -= 2
- else
- iCnt = 0
- end if
- end if
- end sub
- GB_set_update_input_hint_callback( pgb , @handle_buttons )
- GB_set_turbo_mode( pgb , true , false )
- GB_apu_set_sample_callback( pgb , @EmitAudioSample )
- GB_set_sample_rate( pgb , AudioFreq )
- GB_set_highpass_filter_mode( pgb , GB_HIGHPASS_ACCURATE )
- var dSpeed = 1/(GB_get_usual_frame_rate(pgb))
- var bBorder = 0
- dim as double dFPS,dFpsAmount,dTMR
- dim as long iSkip
- dFPS = timer
- while (running)
- if iSkip=0 then GB_set_rendering_disabled( pgb , true )
- if iSkip>=(iFrameSkip-1) then GB_set_rendering_disabled( pgb , false ) : iSkip = -1
- lltime += GB_run_frame(pgb)
- frames += 1 : iSkip += 1
- if iSkip=0 then 'iSkip>=iFrameSkip then
- put( (256-160)\2 , (224-144)\2 ),pScr,pset
- var dTimer = timer
- if abs(dTimer-dTMR) > 1 then dTMR = dTimer
- var dTemp = dTimer-dFPS
- if dTemp >= .25 then
- dFpsAmount = 100*((dSpeed*frames)/dTemp)
- dFPS = dTimer : frames = 0
- dim as zstring*32 zTemp = any
- sprintf(zTemp,"%3.1f%% ",dFpsAmount)
- locate 1,1 : print zTemp
- end if
- #if 0
- sleep 0,1
- #else
- if multikey(fb.SC_BACKSPACE)=0 then
- while (timer-dTMR) < dSpeed
- sleep 1,1
- wend
- dTMR += dSpeed
- else
- dTMR = timer
- end if
- #endif
- end if
- wend
- screenunlock
- GB_free(pgb)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement