8
8
* See COPYING file in the top-level directory.
9
9
*/
10
10
11
+ #include <assert.h>
11
12
#include "pico_int.h"
12
13
#include "memory.h"
14
+ #include "state.h"
13
15
14
16
#include "sound/ym2612.h"
15
17
#include "sound/sn76496.h"
@@ -1327,7 +1329,7 @@ static int ym2612_write_local(u32 a, u32 d, int is_from_z80)
1327
1329
//elprintf(EL_STATUS, "%03i dac w %08x z80 %i", cycles, d, is_from_z80);
1328
1330
if (ym2612 .dacen )
1329
1331
PsndDoDAC (cycles );
1330
- ym2612 .dacout = ((int )d - 0x80 ) << 6 ;
1332
+ ym2612 .dacout = ((int )d - 0x80 ) << DAC_SHIFT ;
1331
1333
return 0 ;
1332
1334
}
1333
1335
case 0x2b : { /* DAC Sel (YM2612) */
@@ -1374,10 +1376,11 @@ static u32 ym2612_read_local_68k(void)
1374
1376
return ym2612 .OPN .ST .status ;
1375
1377
}
1376
1378
1377
- void ym2612_pack_state (void )
1379
+ int ym2612_pack_timers (void * buf , size_t size )
1378
1380
{
1379
1381
// timers are saved as tick counts, in 16.16 int format
1380
1382
int tac , tat = 0 , tbc , tbt = 0 , busy = 0 ;
1383
+ size_t b = 0 ;
1381
1384
tac = 1024 - ym2612 .OPN .ST .TA ;
1382
1385
tbc = 256 - ym2612 .OPN .ST .TB ;
1383
1386
if (Pico .t .ym2612_busy > 0 )
@@ -1388,18 +1391,18 @@ void ym2612_pack_state(void)
1388
1391
tbt = ((Pico .t .timer_b_step - Pico .t .timer_b_next_oflow ) * ((1LL <<32 )/TIMER_B_TICK_ZCYCLES + 1 ))>>16 ;
1389
1392
elprintf (EL_YMTIMER , "save: timer a %i/%i" , tat >> 16 , tac );
1390
1393
elprintf (EL_YMTIMER , "save: timer b %i/%i" , tbt >> 16 , tbc );
1391
-
1392
- #ifdef __GP2X__
1393
- if ( PicoIn . opt & POPT_EXT_FM )
1394
- YM2612PicoStateSave2_940 ( tat , tbt );
1395
- else
1396
- #endif
1397
- YM2612PicoStateSave2 ( tat , tbt , busy ) ;
1394
+ assert ( size >= 16 );
1395
+ save_u16 ( buf , & b , ym2612 . OPN . ST . TA );
1396
+ save_u16 ( buf , & b , ym2612 . OPN . ST . TB );
1397
+ save_u32 ( buf , & b , tat );
1398
+ save_u32 ( buf , & b , tbt );
1399
+ save_u32 ( buf , & b , busy );
1400
+ return b ;
1398
1401
}
1399
1402
1400
- void ym2612_unpack_state (void )
1403
+ void ym2612_unpack_state_old (void )
1401
1404
{
1402
- int i , ret , tac , tat , tbc , tbt , busy = 0 ;
1405
+ int i , ret , tat , tbt , busy = 0 ;
1403
1406
YM2612PicoStateLoad ();
1404
1407
1405
1408
// feed all the registers and update internal state
@@ -1434,7 +1437,30 @@ void ym2612_unpack_state(void)
1434
1437
elprintf (EL_STATUS , "old ym2612 state" );
1435
1438
return ; // no saved timers
1436
1439
}
1440
+ {
1441
+ u8 tmp [16 ];
1442
+ size_t b = 0 ;
1443
+ save_u16 (tmp , & b , ym2612 .OPN .ST .TA );
1444
+ save_u16 (tmp , & b , ym2612 .OPN .ST .TB );
1445
+ save_u32 (tmp , & b , tat );
1446
+ save_u32 (tmp , & b , tbt );
1447
+ save_u32 (tmp , & b , busy );
1448
+ ym2612_unpack_timers (tmp , b );
1449
+ }
1450
+ }
1437
1451
1452
+ void ym2612_unpack_timers (const void * buf , size_t size )
1453
+ {
1454
+ int tac , tat , tbc , tbt , busy ;
1455
+ size_t b = 0 ;
1456
+ assert (size >= 16 );
1457
+ if (size < 16 )
1458
+ return ;
1459
+ ym2612 .OPN .ST .TA = load_u16 (buf , & b );
1460
+ ym2612 .OPN .ST .TB = load_u16 (buf , & b );
1461
+ tat = load_u32 (buf , & b );
1462
+ tbt = load_u32 (buf , & b );
1463
+ busy = load_u32 (buf , & b );
1438
1464
Pico .t .ym2612_busy = cycles_68k_to_z80 (busy );
1439
1465
tac = (1024 - ym2612 .OPN .ST .TA ) << 16 ;
1440
1466
tbc = (256 - ym2612 .OPN .ST .TB ) << 16 ;
0 commit comments