Skip to content

Commit e8f0da3

Browse files
committed
Reduced compiled code size (removed some inlines, reorganized sms z80)
1 parent 4009405 commit e8f0da3

File tree

13 files changed

+983
-1086
lines changed

13 files changed

+983
-1086
lines changed

base.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ macro(rg_setup_compile_options)
2121

2222
if($ENV{ENABLE_PROFILING})
2323
# Still debating whether -fno-inline is necessary or not...
24-
component_compile_options(-DENABLE_PROFILING -fno-inline -finstrument-functions)
24+
component_compile_options(-DENABLE_PROFILING -finstrument-functions)
2525
endif()
2626

2727
if($ENV{ENABLE_DEBUGGING})

gnuboy-go/components/gnuboy/lcd.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,18 @@ static byte pix[8];
5555
int enable_window_offset_hack = 0;
5656

5757

58+
/**
59+
* Helper macros
60+
*/
61+
62+
#define priused(attr) ({un32 *a = (un32*)(attr); (int)((a[0]|a[1]|a[2]|a[3]|a[4]|a[5]|a[6]|a[7])&0x80808080);})
63+
64+
#define blendcpy(dest, src, b, cnt) { \
65+
byte *s = (src), *d = (dest), _b = (b), c = (cnt); \
66+
while(c--) *(d + c) = *(s + c) | _b; \
67+
}
68+
69+
5870
/**
5971
* Drawing routines
6072
*/
@@ -265,17 +277,6 @@ static inline void wnd_scan()
265277
}
266278
}
267279

268-
static inline void blendcpy(byte *dest, byte *src, byte b, int cnt)
269-
{
270-
while (cnt--) *(dest++) = *(src++) | b;
271-
}
272-
273-
static inline int priused(void *attr)
274-
{
275-
un32 *a = attr;
276-
return (int)((a[0]|a[1]|a[2]|a[3]|a[4]|a[5]|a[6]|a[7])&0x80808080);
277-
}
278-
279280
static inline void bg_scan_pri()
280281
{
281282
int cnt, i;

gnuboy-go/components/gnuboy/sound.c

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -55,37 +55,10 @@ struct snd snd;
5555
#define S3 (snd.ch[2])
5656
#define S4 (snd.ch[3])
5757

58-
59-
static inline void s1_freq_d(int d)
60-
{
61-
if (RATE > (d<<4)) S1.freq = 0;
62-
else S1.freq = (RATE << 17)/d;
63-
}
64-
65-
static inline void s1_freq()
66-
{
67-
s1_freq_d(2048 - (((R_NR14&7)<<8) + R_NR13));
68-
}
69-
70-
static inline void s2_freq()
71-
{
72-
int d = 2048 - (((R_NR24&7)<<8) + R_NR23);
73-
if (RATE > (d<<4)) S2.freq = 0;
74-
else S2.freq = (RATE << 17)/d;
75-
}
76-
77-
static inline void s3_freq()
78-
{
79-
int d = 2048 - (((R_NR34&7)<<8) + R_NR33);
80-
if (RATE > (d<<3)) S3.freq = 0;
81-
else S3.freq = (RATE << 21)/d;
82-
}
83-
84-
static inline void s4_freq()
85-
{
86-
S4.freq = (freqtab[R_NR43&7] >> (R_NR43 >> 4)) * RATE;
87-
if (S4.freq >> 18) S4.freq = 1<<18;
88-
}
58+
#define s1_freq() {int d = 2048 - (((R_NR14&7)<<8) + R_NR13); S1.freq = (RATE > (d<<4)) ? 0 : (RATE << 17)/d;}
59+
#define s2_freq() {int d = 2048 - (((R_NR24&7)<<8) + R_NR23); S2.freq = (RATE > (d<<4)) ? 0 : (RATE << 17)/d;}
60+
#define s3_freq() {int d = 2048 - (((R_NR34&7)<<8) + R_NR33); S3.freq = (RATE > (d<<3)) ? 0 : (RATE << 21)/d;}
61+
#define s4_freq() {S4.freq = (freqtab[R_NR43&7] >> (R_NR43 >> 4)) * RATE; if (S4.freq >> 18) S4.freq = 1<<18;}
8962

9063
void sound_dirty()
9164
{
@@ -187,7 +160,8 @@ void IRAM_ATTR sound_mix()
187160
S1.swfreq = f;
188161
R_NR13 = f;
189162
R_NR14 = (R_NR14 & 0xF8) | (f>>8);
190-
s1_freq_d(2048 - f);
163+
// s1_freq_d(2048 - f);
164+
s1_freq();
191165
}
192166
}
193167
s <<= 2;

huexpress-go/components/huexpress/engine/h6280.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
#define pull_8bit() (*(sp_base + ++reg_s))
4343
#define pull_16bit() (pull_8bit() | pull_8bit() << 8)
4444

45-
#include "h6280_opcodes.h"
45+
#include "h6280_instr.h"
4646

4747
#define Int6502(Type) \
4848
{ \

huexpress-go/components/huexpress/engine/h6280_opcodes.h renamed to huexpress-go/components/huexpress/engine/h6280_instr.h

File renamed without changes.

huexpress-go/components/huexpress/engine/hard_pce.h

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,32 @@ enum _VDC_REG {
285285
/**
286286
* Inlined Memory Functions
287287
*/
288+
#if 1
289+
290+
#define Read8(addr) ({ \
291+
uint16 a = (addr); \
292+
uchar *page = PageR[a >> 13]; \
293+
(page == IOAREA) ? IO_read(a) : page[a]; \
294+
})
295+
296+
#define Write8(addr, byte) { \
297+
uint16 a = (addr), b = (byte); \
298+
uchar *page = PageW[a >> 13]; \
299+
if (page == IOAREA) IO_write(a, b); \
300+
else page[a] = b; \
301+
}
302+
303+
#define Read16(addr) ({ \
304+
uint16 a = (addr); \
305+
*((uint16*)(PageR[a >> 13] + a)); \
306+
})
307+
308+
#define Write16(addr, word) { \
309+
uint16 a = (addr), w = (word); \
310+
*((uint16*)(PageR[a >> 13] + a)) = w; \
311+
}
312+
313+
#else
288314

289315
static inline uchar
290316
Read8(uint16 addr)
@@ -320,6 +346,8 @@ Write16(uint16 addr, uint16 word)
320346
*((uint16*)(PageR[addr >> 13] + (addr))) = word;
321347
}
322348

349+
#endif
350+
323351
static inline void
324352
BankSet(uchar P, uchar V)
325353
{
@@ -330,7 +358,6 @@ BankSet(uchar P, uchar V)
330358
PageW[P] = (MemoryMapW[V] == IOAREA) ? (IOAREA) : (MemoryMapW[V] - P * 0x2000);
331359
}
332360

333-
334361
/**
335362
* Inlined HW Functions
336363
*/

huexpress-go/components/huexpress/engine/sound.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,6 @@ static uint32 rand_val[6]; // Noise seed
2828
static uint32 k[6];
2929
static uint32 r[6];
3030

31-
static inline int
32-
mseq(uint32 * rand_val)
33-
{
34-
if (*rand_val & 0x00080000) {
35-
*rand_val = ((*rand_val ^ 0x0004) << 1) + 1;
36-
return 1;
37-
} else {
38-
*rand_val <<= 1;
39-
return 0;
40-
}
41-
}
42-
4331

4432
int
4533
snd_init()
@@ -228,7 +216,14 @@ psg_update(char *buf, int ch, unsigned dwSize)
228216
k[ch] += 3000 + Np * 512;
229217

230218
if ((t = (k[ch] / (uint32) host.sound.freq)) >= 1) {
231-
r[ch] = mseq(&rand_val[ch]);
219+
// mseq
220+
if (rand_val[ch] & 0x00080000) {
221+
rand_val[ch] = ((rand_val[ch] ^ 0x0004) << 1) + 1;
222+
r[ch] = 1;
223+
} else {
224+
rand_val[ch] <<= 1;
225+
r[ch] = 0;
226+
}
232227
k[ch] -= host.sound.freq * t;
233228
}
234229

huexpress-go/components/huexpress/includes/config.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,4 @@
3131

3232
#define PCE_PATH_MAX 192
3333

34-
/* Define to `__inline__' or `__inline' if that's what the C compiler
35-
calls it, or to nothing if 'inline' is not supported under any name. */
36-
// #ifndef __cplusplus
37-
// #undef inline
38-
// #endif
34+
#define INLINE static inline __attribute__((__always_inline__))

nofrendo-go/components/nofrendo/cpu/nes6502.c

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,28 +1069,9 @@ static mem_t *mem;
10691069

10701070
#ifdef NES6502_FASTMEM
10711071

1072-
INLINE uint8 fast_readbyte(uint16 address)
1073-
{
1074-
return mem->pages[address >> MEM_PAGESHIFT][address];
1075-
}
1076-
1077-
INLINE uint16 fast_readword(uint32 address)
1078-
{
1079-
if ((address & MEM_PAGEMASK) != MEM_PAGEMASK) // Page cross
1080-
{
1081-
return PAGE_READWORD(mem->pages[address >> MEM_PAGESHIFT], address);
1082-
}
1083-
return mem_getword(address);
1084-
}
1085-
1086-
INLINE void writebyte(uint32 address, uint8 value)
1087-
{
1088-
if (address < 0x2000) {
1089-
mem->ram[address & 0x7FF] = value;
1090-
} else {
1091-
mem_putbyte(address, value);
1092-
}
1093-
}
1072+
#define fast_readbyte(a) ({uint16 _a = (a); mem->pages[_a >> MEM_PAGESHIFT][_a];})
1073+
#define fast_readword(a) ({uint16 _a = (a); ((_a & MEM_PAGEMASK) != MEM_PAGEMASK) ? PAGE_READWORD(mem->pages[_a >> MEM_PAGESHIFT], _a) : mem_getword(_a);})
1074+
#define writebyte(a, v) {uint16 _a = (a), _v = (v); if (_a < 0x2000) mem->ram[_a & 0x7FF] = _v; else mem_putbyte(_a, _v);}
10941075

10951076
#else /* !NES6502_FASTMEM */
10961077

0 commit comments

Comments
 (0)