Mercurial > vba-clojure
comparison src/gb/GB.cpp @ 92:1ff2c546f5ad
added tick(), which allows one to step through each opcode of gameboy
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sun, 11 Mar 2012 19:07:31 -0500 |
parents | d7c38ce83421 |
children | 4c60ebca1a9d |
comparison
equal
deleted
inserted
replaced
91:613353b7e012 | 92:1ff2c546f5ad |
---|---|
13 #include "gbSound.h" | 13 #include "gbSound.h" |
14 #include "../common/unzip.h" | 14 #include "../common/unzip.h" |
15 #include "../common/Util.h" | 15 #include "../common/Util.h" |
16 #include "../common/System.h" | 16 #include "../common/System.h" |
17 #include "../common/movie.h" | 17 #include "../common/movie.h" |
18 #include "../common/vbalua.h" | 18 // #include "../common/vbalua.h" |
19 | 19 |
20 #ifdef __GNUC__ | 20 #ifdef __GNUC__ |
21 #define _stricmp strcasecmp | 21 #define _stricmp strcasecmp |
22 #endif | 22 #endif |
23 | 23 |
1278 } | 1278 } |
1279 | 1279 |
1280 void gbWriteMemory(register u16 address, register u8 value) | 1280 void gbWriteMemory(register u16 address, register u8 value) |
1281 { | 1281 { |
1282 gbWriteMemoryWrapped(address, value); | 1282 gbWriteMemoryWrapped(address, value); |
1283 CallRegisteredLuaMemHook(address, 1, value, LUAMEMHOOK_WRITE); | 1283 //CallRegisteredLuaMemHook(address, 1, value, LUAMEMHOOK_WRITE); |
1284 } | 1284 } |
1285 | 1285 |
1286 u8 gbReadMemory(register u16 address) | 1286 u8 gbReadMemory(register u16 address) |
1287 { | 1287 { |
1288 if (gbCheatMap[address]) | 1288 if (gbCheatMap[address]) |
3162 gbReset(); | 3162 gbReset(); |
3163 | 3163 |
3164 return true; | 3164 return true; |
3165 } | 3165 } |
3166 | 3166 |
3167 void gbEmulate(int ticksToStop) | 3167 int gbEmulate(int ticksToStop) |
3168 { | 3168 { |
3169 int rlm_count = 0; | |
3169 //printf("RLM: Inside the GB!\n"); | 3170 //printf("RLM: Inside the GB!\n"); |
3170 gbRegister tempRegister; | 3171 gbRegister tempRegister; |
3171 u8 tempValue; | 3172 u8 tempValue; |
3172 s8 offset; | 3173 s8 offset; |
3173 | 3174 |
3230 //printf("RLM: after Lua functions\n"); | 3231 //printf("RLM: after Lua functions\n"); |
3231 newFrame = false; | 3232 newFrame = false; |
3232 } | 3233 } |
3233 | 3234 |
3234 | 3235 |
3235 for (;; ) | 3236 //for (;; ) |
3236 { | 3237 // { |
3237 #ifndef FINAL_VERSION | 3238 #ifndef FINAL_VERSION |
3238 if (systemDebug) | 3239 if (systemDebug) |
3239 { | 3240 { |
3240 if (!(IFF & 0x80)) | 3241 if (!(IFF & 0x80)) |
3241 { | 3242 { |
3274 clockTicks = soundTicks; | 3275 clockTicks = soundTicks; |
3275 } | 3276 } |
3276 else | 3277 else |
3277 { | 3278 { |
3278 opcode = gbReadOpcode(PC.W); | 3279 opcode = gbReadOpcode(PC.W); |
3279 CallRegisteredLuaMemHook(PC.W, 1, opcode, LUAMEMHOOK_EXEC); | 3280 //printf("RLM: calling mem Hook ; %07d\n", rlm_count++); |
3281 //CallRegisteredLuaMemHook(PC.W, 1, opcode, LUAMEMHOOK_EXEC); | |
3280 PC.W++; | 3282 PC.W++; |
3281 | 3283 |
3282 if (IFF & 0x100) | 3284 if (IFF & 0x100) |
3283 { | 3285 { |
3284 IFF &= 0xff; | 3286 IFF &= 0xff; |
3302 #include "gbCodes.h" | 3304 #include "gbCodes.h" |
3303 } | 3305 } |
3304 } | 3306 } |
3305 | 3307 |
3306 if (!emulating) | 3308 if (!emulating) |
3307 return; | 3309 return 1; |
3308 | 3310 |
3309 if (gbDmaTicks) | 3311 if (gbDmaTicks) |
3310 { | 3312 { |
3311 clockTicks += gbDmaTicks; | 3313 clockTicks += gbDmaTicks; |
3312 gbDmaTicks = 0; | 3314 gbDmaTicks = 0; |
3772 if (IFF & 0x01) | 3774 if (IFF & 0x01) |
3773 { | 3775 { |
3774 if ((gbInterrupt & 1) && (register_IE & 1)) | 3776 if ((gbInterrupt & 1) && (register_IE & 1)) |
3775 { | 3777 { |
3776 gbVblank_interrupt(); | 3778 gbVblank_interrupt(); |
3777 continue; | 3779 return newFrame; |
3778 } | 3780 } |
3779 | 3781 |
3780 if ((gbInterrupt & 2) && (register_IE & 2)) | 3782 if ((gbInterrupt & 2) && (register_IE & 2)) |
3781 { | 3783 { |
3782 gbLcd_interrupt(); | 3784 gbLcd_interrupt(); |
3783 continue; | 3785 return newFrame; |
3784 } | 3786 } |
3785 | 3787 |
3786 if ((gbInterrupt & 4) && (register_IE & 4)) | 3788 if ((gbInterrupt & 4) && (register_IE & 4)) |
3787 { | 3789 { |
3788 gbTimer_interrupt(); | 3790 gbTimer_interrupt(); |
3789 continue; | 3791 return newFrame; |
3790 } | 3792 } |
3791 | 3793 |
3792 if ((gbInterrupt & 8) && (register_IE & 8)) | 3794 if ((gbInterrupt & 8) && (register_IE & 8)) |
3793 { | 3795 { |
3794 gbSerial_interrupt(); | 3796 gbSerial_interrupt(); |
3795 continue; | 3797 return newFrame; |
3796 } | 3798 } |
3797 | 3799 |
3798 if ((gbInterrupt & 16) && (register_IE & 16)) | 3800 if ((gbInterrupt & 16) && (register_IE & 16)) |
3799 { | 3801 { |
3800 gbJoypad_interrupt(); | 3802 gbJoypad_interrupt(); |
3801 continue; | 3803 return newFrame; |
3802 } | 3804 } |
3803 } | 3805 } |
3804 } | 3806 } |
3805 else | 3807 else |
3806 { | 3808 { |
3812 | 3814 |
3813 if (useOldFrameTiming) | 3815 if (useOldFrameTiming) |
3814 { | 3816 { |
3815 // old timing code | 3817 // old timing code |
3816 if (ticksToStop > 0) | 3818 if (ticksToStop > 0) |
3817 continue; | 3819 return newFrame; |
3818 } | 3820 } |
3819 else | 3821 else |
3820 { | 3822 { |
3821 if (!newFrame && (register_LCDC & 0x80) != 0) | 3823 if (!newFrame && (register_LCDC & 0x80) != 0) |
3822 continue; | 3824 return newFrame; |
3823 } | 3825 } |
3824 | 3826 |
3825 if (!(register_LCDC & 0x80)) | 3827 if (!(register_LCDC & 0x80)) |
3826 { | 3828 { |
3827 if (!useOldFrameTiming) | 3829 if (!useOldFrameTiming) |
3860 #endif | 3862 #endif |
3861 } | 3863 } |
3862 } | 3864 } |
3863 | 3865 |
3864 // makes sure frames are really divided across input sampling boundaries which occur at a constant rate | 3866 // makes sure frames are really divided across input sampling boundaries which occur at a constant rate |
3865 if (newFrame || useOldFrameTiming) | 3867 //if (newFrame || useOldFrameTiming) |
3866 { | 3868 // { |
3867 /// extern void VBAOnEnteringFrameBoundary(); | 3869 /// extern void VBAOnEnteringFrameBoundary(); |
3868 /// VBAOnEnteringFrameBoundary(); | 3870 /// VBAOnEnteringFrameBoundary(); |
3869 | 3871 |
3870 break; | 3872 // break; |
3871 } | 3873 // } |
3872 } | 3874 // RLM removing for loop } |
3875 return newFrame; | |
3873 } | 3876 } |
3874 | 3877 |
3875 | 3878 |
3876 | 3879 |
3877 //RLM: | 3880 //RLM: |
3962 gbReadSaveState, | 3965 gbReadSaveState, |
3963 // emuWriteState | 3966 // emuWriteState |
3964 gbWriteSaveState, | 3967 gbWriteSaveState, |
3965 // emuReadStateFromStream | 3968 // emuReadStateFromStream |
3966 gbReadSaveStateFromStream, | 3969 gbReadSaveStateFromStream, |
3967 // emuWriteStateToStream | 3970 // emuwritestatetostream |
3968 gbWriteSaveStateToStream, | 3971 gbWriteSaveStateToStream, |
3969 // emuReadMemState | 3972 // emuReadMemState |
3970 gbReadMemSaveState, | 3973 gbReadMemSaveState, |
3971 // emuWriteMemState | 3974 // emuWriteMemState |
3972 gbWriteMemSaveState, | 3975 gbWriteMemSaveState, |