-
Notifications
You must be signed in to change notification settings - Fork 0
/
sid.c
executable file
·64 lines (46 loc) · 1.38 KB
/
sid.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
* Copyright (c) 2020 Erwin Rol <[email protected]
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "sid.h"
#include "c64.h"
#include "hal.h"
#include "hw_reg_access.h"
#include "SID_PLAYER_hw_platform.h"
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
void sid_poke(uint16_t reg, uint8_t val)
{
HW_set_32bit_reg((addr_t)SID_BRIDGE_0 + 0xC000 + (reg * 4), val);
}
bool sid_load_from_memory(const uint8_t* data, size_t size, struct sid_info *info)
{
if (!data || !size || !info)
return false;
unsigned char data_file_offset;
data_file_offset = data[7];
info->load_addr = data[8]<<8;
info->load_addr|= data[9];
info->init_addr = data[10]<<8;
info->init_addr|= data[11];
info->play_addr = data[12]<<8;
info->play_addr|= data[13];
info->subsongs = data[0xf]-1;
info->start_song = data[0x11]-1;
info->load_addr = data[data_file_offset];
info->load_addr|= data[data_file_offset + 1] << 8;
info->speed = data[0x15];
c64_memset(0, 0, 64 * 1024);
c64_memcpy(info->load_addr, &data[data_file_offset+2], size-(data_file_offset+2));
strcpy(info->title, (const char*)&data[0x16]);
strcpy(info->author, (const char*)&data[0x36]);
strcpy(info->released, (const char*)&data[0x56]);
if (info->play_addr == 0)
{
c64_cpu_jsr(info->init_addr, 0);
info->play_addr = (c64_getmem(0x0315) << 8) | c64_getmem(0x0314);
}
return true;
}