diff options
| author | spicyjpeg <thatspicyjpeg@gmail.com> | 2022-10-23 15:03:16 +0200 |
|---|---|---|
| committer | spicyjpeg <thatspicyjpeg@gmail.com> | 2022-10-23 15:03:16 +0200 |
| commit | 5f25c0bf306d316c87fca9d3fe160d6661be230d (patch) | |
| tree | 399317390f789c0a9f4a9f5a342ca8233cb1b313 /libpsn00b/include | |
| parent | b1632d7df0e840692612461a80d0e05d6a3228ed (diff) | |
| download | psn00bsdk-5f25c0bf306d316c87fca9d3fe160d6661be230d.tar.gz | |
Library bugfixes and additions, _sdk_log_inner() removal
Diffstat (limited to 'libpsn00b/include')
| -rw-r--r-- | libpsn00b/include/assert.h | 7 | ||||
| -rw-r--r-- | libpsn00b/include/psxsio.h | 14 | ||||
| -rw-r--r-- | libpsn00b/include/psxspu.h | 22 |
3 files changed, 31 insertions, 12 deletions
diff --git a/libpsn00b/include/assert.h b/libpsn00b/include/assert.h index e93c983..12212af 100644 --- a/libpsn00b/include/assert.h +++ b/libpsn00b/include/assert.h @@ -9,8 +9,9 @@ #ifndef __ASSERT_H #define __ASSERT_H +#include <stdio.h> + void _assert_abort(const char *file, int line, const char *expr); -void _sdk_log_inner(const char *fmt, ...); #ifdef NDEBUG @@ -24,9 +25,9 @@ void _sdk_log_inner(const char *fmt, ...); } #ifdef SDK_LIBRARY_NAME -#define _sdk_log(fmt, ...) _sdk_log_inner(SDK_LIBRARY_NAME ": " fmt, ##__VA_ARGS__) +#define _sdk_log(fmt, ...) printf(SDK_LIBRARY_NAME ": " fmt, ##__VA_ARGS__) #else -#define _sdk_log(fmt, ...) _sdk_log_inner(fmt, ##__VA_ARGS__) +#define _sdk_log(fmt, ...) printf(fmt, ##__VA_ARGS__) #endif #endif diff --git a/libpsn00b/include/psxsio.h b/libpsn00b/include/psxsio.h index e0cc49b..d5f7d9a 100644 --- a/libpsn00b/include/psxsio.h +++ b/libpsn00b/include/psxsio.h @@ -145,15 +145,19 @@ int SIO_ReadSync(int mode); /** * @brief Registers a function to be called whenever a byte is received. The - * received byte is appended to the RX buffer and passed as an argument to the - * callback. The callback will run in the exception handler's context, so it - * should be as fast as possible and not use any function that relies on - * interrupts in order to work. + * received byte is passed as an argument to the callback, which shall then + * return a zero value to also store the byte in the RX buffer or a non-zero + * value to drop it. This can be used to e.g. filter or validate incoming data, + * or to bypass the library's RX buffer for custom buffering purposes. + * + * The callback will run in the exception handler's context, so it should be as + * fast as possible and shall not call any function that relies on interrupts + * being enabled. * * @param func * @return Previously set callback or NULL */ -void *SIO_ReadCallback(void (*func)(uint8_t)); +void *SIO_ReadCallback(int (*func)(uint8_t)); /** * @brief Sends the given byte, or appends it to the TX buffer if the serial diff --git a/libpsn00b/include/psxspu.h b/libpsn00b/include/psxspu.h index cf78e3d..7858e88 100644 --- a/libpsn00b/include/psxspu.h +++ b/libpsn00b/include/psxspu.h @@ -73,6 +73,20 @@ typedef struct _SpuCommonAttr { SpuExtAttr cd, ext; } SpuCommonAttr; +/* Macros */ + +#define getSPUAddr(addr) ((uint16_t) (((addr) + 7) / 8)) +#define getSPUSampleRate(rate) ((uint16_t) (((rate) * (1 << 12)) / 44100)) + +#define getSPUADSR(ar, dr, sr, rr, sl) ( \ + (sl) | \ + ((dr) << 4) | \ + ((ar) << 8) | \ + ((rr) << 16) | \ + ((sr) << 22) | \ + (1 << 30) \ +) + /* "Useless" macros for official SDK compatibility */ #define SpuSetCommonMasterVolume(left, right) \ @@ -87,18 +101,18 @@ typedef struct _SpuCommonAttr { ((enable) ? (SPU_CTRL |= 0x0002) : (SPU_CTRL &= 0xfffd)) #define SpuSetReverbAddr(addr) \ - (SPU_REVERB_ADDR = ((addr) + 7) / 8) + (SPU_REVERB_ADDR = getSPUAddr(addr)) #define SpuSetIRQAddr(addr) \ - (SPU_IRQ_ADDR = ((addr) + 7) / 8) + (SPU_IRQ_ADDR = getSPUAddr(addr)) #define SpuSetVoiceVolume(ch, left, right) \ (SPU_CH_VOL_L(ch) = (left), SPU_CH_VOL_R(ch) = (right)) #define SpuSetVoicePitch(ch, pitch) \ (SPU_CH_FREQ(ch) = (pitch)) #define SpuSetVoiceStartAddr(ch, addr) \ - (SPU_CH_ADDR(ch) = ((addr) + 7) / 8) + (SPU_CH_ADDR(ch) = getSPUAddr(addr)) #define SpuSetVoiceADSR(ch, ar, dr, sr, rr, sl) \ - (SPU_CH_ADSR(ch) = ((sl)) | ((dr) << 4) | ((ar) << 8) | ((rr) << 16) | ((sr) << 22) | (1 << 30)) + (SPU_CH_ADSR(ch) = getSPUADSR(ar, dr, sr, rr, sl)) #define SpuSetKey(enable, voice_bit) \ ((enable) ? (SPU_KEY_ON = (voice_bit)) : (SPU_KEY_OFF = (voice_bit))) |
