-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.cpp
55 lines (49 loc) · 1.46 KB
/
functions.cpp
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
#include "main.h"
#define sprintf(format, ...) AnsiString().sprintf((format), __VA_ARGS__)
// OTHER FUNCTIONS
void fn_Log(UnicodeString text){
if(frsMain->chk_DebugInfo->Checked)
frsMain->DebugInfo->Lines->Add(text);
}
// SNES ADDRESSING FUNCTIONS
int addr2pc(int addr){
if(addr >= 0x400000)
return addr - 0x400000;
int bank = (addr & 0xFF0000) >> 16;
int absolute = (addr & 0x00FFFF);
int abs_corrected = absolute - 0x8000 * (1 - bank % 2);
return (bank << 15) | abs_corrected;
//return ((addr & 0xff0000) >> 1) | (addr & 0x7FFF);
}
int addr2snes(int addr){
int bank = (addr & 0xFF0000) * 2 + (addr & 0x008000) * 2;
int absolute = addr & 0x00FFFF;
int abs_corrected = absolute + 0x008000 - (absolute & 0x008000);
return bank | abs_corrected;
}
int dickbutt2snes(int addr){
return addr2snes(addr2pc(addr));
}
bool checkcrossbank(int addr, int size){
//fn_Log(addr2snes(addr + size) - addr2snes(addr));
return (addr2snes(addr) & 0xFF0000) >> 16 != (addr2snes(addr + size) & 0xFF0000) >> 16;
}
// ADDRESS FUNCTIONS
unsigned short u8(char *value){
return *(((unsigned short*) value));
}
unsigned short u16(char *value){
return *(((unsigned short*) value));
}
unsigned int u24(char *value){
return *(((unsigned int*) value)) & 0xffffff;
}
unsigned int u32(char *value){
return *(((unsigned int*) value));
}
char * int2bytes(unsigned int value, int size){
char * bytes = new char[size];
for(int x = 0; x < size; x++)
bytes[x] = (value >> (x * 8));
return bytes;
}