gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
gbdk-lib/examples/gb/mbc5_rumble/src/mbc5_rumble.h
1 #ifndef _MBC5_RUMBLE_H
2 #define _MBC5_RUMBLE_H
3
4 #include <gbdk/platform.h>
5 #include <stdint.h>
6
7 #define RUMBLE_FRAMES(N) (N + 1u)
8 #define RUMBLE_COUNT_1_SEC RUMBLE_FRAMES(60u)
9 #define RUMBLE_COUNT_HALF_SEC RUMBLE_FRAMES(30u)
10 #define RUMBLE_COUNT_QUARTER_SEC RUMBLE_FRAMES(15u)
11 #define RUMBLE_COUNT_EIGHTH_SEC RUMBLE_FRAMES(7u)
12 #define RUMBLE_COUNT_DONE 0u
13
14
15 // MAX uses an always on duty cycle.
16 // The others use the various waveforms below
17 //
18 // Using shorter on/off cycling makes
19 // the rumble feel less "lumpy" than longer
20 // contiguous on-off square waves with
21 // the same amount of total on-time frames.
22 // // The counter increments once per frame
23 // // ("Y" = on, "-" = off)
24 // // Bit 76543210 7 6 5 4 3 2 1 0
25 #define RUMBLE_DUTY_MASK_MAX (0b11111111u) // YYYYYYYY |¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|
26 #define RUMBLE_DUTY_MASK_HI (0b00000011u) // YYY-YYY- |¯¯¯¯¯|_|¯¯¯¯¯|_|
27 #define RUMBLE_DUTY_MASK_MED (0b00000010u) // YY--YY-- |¯¯¯|___|¯¯¯|___|
28 #define RUMBLE_DUTY_MASK_LOW (0b00000001u) // Y-Y-Y-Y- |¯|_|¯|_|¯|_|¯|_|
29
30 #define RUMBLE_INTENSITY_MAX 3u
31 #define RUMBLE_INTENSITY_HI 2u
32 #define RUMBLE_INTENSITY_MED 1u
33 #define RUMBLE_INTENSITY_LOW 0u
34 #define RUMBLE_INTENSITY_MIN (RUMBLE_INTENSITY_LOW)
35
36 #define MBC_RAM_BANK_0 0u
37
38 #define MBC_RUMBLE_BIT_ON 0b00001000u
39 #define MBC_RUMBLE_BIT_OFF 0b00000000u
40 #define MBC5_RUMBLE_ON SWITCH_RAM_MBC5(MBC_RAM_BANK_0 | MBC_RUMBLE_BIT_ON)
41 #define MBC5_RUMBLE_OFF SWITCH_RAM_MBC5(MBC_RAM_BANK_0 | MBC_RUMBLE_BIT_OFF)
42
43
44 void rumble_start(uint8_t duration);
45 void rumble_cancel(void);
46
47 void rumble_intensity_set(uint8_t duty_cycle);
48 uint8_t rumble_intensity_increase(void);
49 uint8_t rumble_intensity_decrease(void);
50
51 void rumble_update(void);
52
53 #endif // _MBC5_RUMBLE_H
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.