Skip to content

Commit 6ca0ae2

Browse files
committed
a couple of fixes, and digitbox wraparound
1 parent 92c278a commit 6ca0ae2

File tree

4 files changed

+46
-33
lines changed

4 files changed

+46
-33
lines changed

arm9/graphics/effectinput.grit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
-gt -gB4 -m -pn16 -ftc
1+
-gt -gB4 -m -p! -ftc

arm9/source/tobkit/fxkeyboard.cpp

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,9 @@ void FXKeyboard::pleaseDraw(void) {
4343
// Event calls
4444
void FXKeyboard::penDown(u8 px, u8 py)
4545
{
46-
s16 tx, rx;
47-
tx = ntxm_clamp((px - x)/24, 0, 8 - 1);
48-
rx = (px - x) % 24;
49-
bool r = rx > 11;
50-
u8 bt_ind = (tx * 2) + (r ? 1 : 0);
46+
if (px > FXBUTTON_WIDTH * NUM_FXKEYS) return;
47+
48+
u8 bt_ind = ntxm_clamp(px / FXBUTTON_WIDTH, 0, NUM_FXKEYS-1);
5149

5250
if (fxkb_state[bt_ind] != FXBUTTON_DISABLED)
5351
fxkb_state[bt_ind] |= 0x1; // set pushed
@@ -120,6 +118,7 @@ void FXKeyboard::setCategory(u8 newcat) {
120118

121119
category = newcat;
122120

121+
useDarkTitle(false);
123122
memset(fxkb_state, FXBUTTON_NORMAL, NUM_FXKEYS);
124123
setCaption(category_captions[category]);
125124

@@ -150,9 +149,9 @@ u8 FXKeyboard::getCategory(void)
150149
return category;
151150
}
152151

153-
void FXKeyboard::setLastCmd(u8 _last_e_cmd)
152+
void FXKeyboard::setLastCmd(u8 _last_cmd)
154153
{
155-
last_cmd = _last_e_cmd;
154+
last_cmd = _last_cmd;
156155
}
157156

158157
u8 FXKeyboard::getLastCmd(void)
@@ -177,12 +176,12 @@ void FXKeyboard::drawCaption(void) {
177176

178177
drawFullBox(1, 3, width, 5, bgcolor);
179178
u16 capcol = darken_title ? theme->col_fxkeyboard_cmd_desc_disabled : theme->col_fxkeyboard_cmd_desc;
180-
drawSmallString(caption, ((NUM_FXKEYS * FXBUTTON_WIDTH) / 2) - (2 * strlen(caption)), 3, capcol); // width=(3px char+1px space) / 2
179+
drawSmallString(caption, ((NUM_FXKEYS * FXBUTTON_WIDTH) / 2) - (2 * strlen(caption)) + 4, 3, capcol); // width=(3px char+1px space) / 2
181180
}
182181

183182
void FXKeyboard::drawButtonLabel(u8 key, u8 cat, bool visible)
184183
{
185-
u8 xpos = key * 12 + 3;
184+
u8 xpos = key * FXBUTTON_WIDTH + 3;
186185
u16 col = theme->col_fxkeyboard_btn_label;
187186
u16 smallcol1 = theme->col_fxkeyboard_minilabel_x;
188187
u16 smallcol2 = theme->col_fxkeyboard_minilabel_y;
@@ -200,7 +199,7 @@ void FXKeyboard::drawButtonLabel(u8 key, u8 cat, bool visible)
200199
char small_caption[3] = {0}; // one wasted byte...noone will notice
201200

202201
if (cat == FX_CATEGORY_E)
203-
snprintf(small_caption, 3, "E%1X", fxkb_vals[key]);
202+
snprintf(small_caption, 3, "%1XX", fxkb_vals[key]);
204203
else if (cat == FX_CATEGORY_NORMAL)
205204
sprintf(small_caption, "X%s", ((labels_cat0 >> key) & 0x1) ? "Y" : "X");
206205
else
@@ -226,7 +225,6 @@ void FXKeyboard::eraseButtonLabels(void)
226225
void FXKeyboard::draw(void) {
227226
if (!isExposed()) return;
228227

229-
int row;
230228
u16 lstate, rstate;
231229

232230
/*
@@ -244,25 +242,28 @@ void FXKeyboard::draw(void) {
244242
basically this depends on the order of the tiles in
245243
effectinput.png, so dont rearrange them (˘︶˘)
246244
*/
245+
246+
int row,col;
247+
247248
for (int pair=0;pair<NUM_FXKEYS/2;++pair)
248249
{
249250
lstate=fxkb_state[pair*2];
250251
rstate=fxkb_state[pair*2+1];
251252

252-
u16 buttontiles[15]={
253+
const u16 buttontiles[15]={
253254
TILE_BLANK, TILE_LCORNER+lstate, TILE_LEDGE+lstate, TILE_LEDGE+lstate, VFLIP(TILE_LCORNER+lstate),
254255
TILE_BLANK, TILE_MID_EDGE+(3*rstate)+lstate, TILE_MID+(3*rstate)+lstate, TILE_MID+(3*rstate)+lstate, VFLIP(TILE_MID_EDGE+(3*rstate)+lstate),
255256
TILE_BLANK, TILE_EVEN_END_EDGE+rstate, TILE_EVEN_END_MID+rstate, TILE_EVEN_END_MID+rstate, VFLIP(TILE_EVEN_END_EDGE+rstate), // btm edge=y flipped top edge
256257
};
257258

258-
int abs_col=pair*3;
259+
int tile_pos_x=pair*3;
259260

260-
for (int j=0;j<3;++j)
261+
for (col=0;col<3;++col)
261262
{
262-
for (row=0;row<5;++row)
263+
for (row=0;row<FXKEYBOARD_HEIGHT_TILES;++row)
263264
{
264-
u8 pos = (row * 28) + abs_col + j;
265-
fxkb_map[pos]=buttontiles[row + (j*5)];
265+
u8 pos = (row * FXKEYBOARD_WIDTH_TILES) + tile_pos_x + col;
266+
fxkb_map[pos]=buttontiles[row + (col*FXKEYBOARD_HEIGHT_TILES)];
266267
}
267268
}
268269
}
@@ -271,24 +272,24 @@ void FXKeyboard::draw(void) {
271272
if (NUM_FXKEYS % 2 == 1)
272273
{
273274
rstate=fxkb_state[NUM_FXKEYS-1];
274-
275-
u16 oddend[10]={
275+
276+
const u16 oddend[10]={
276277
TILE_BLANK, TILE_LCORNER+rstate, TILE_LEDGE+rstate, TILE_LEDGE+rstate, VFLIP(TILE_LCORNER+rstate),
277278
TILE_BLANK, TILE_ODD_END_EDGE+rstate, TILE_ODD_END_MID+rstate, TILE_ODD_END_MID+rstate, VFLIP(TILE_ODD_END_EDGE+rstate)
278279
};
279280

280-
for (int j=0;j<2;++j)
281+
for (col=0;col<2;++col)
281282
{
282-
for (row=0;row<5;++row)
283+
for (row=0;row<FXKEYBOARD_HEIGHT_TILES;++row)
283284
{
284-
u8 pos = (row * 28) + ((NUM_FXKEYS/2)*3) + j;
285-
fxkb_map[pos]=oddend[row + (j*5)];
285+
u8 pos = (row * FXKEYBOARD_WIDTH_TILES) + ((NUM_FXKEYS/2)*3) + col;
286+
fxkb_map[pos]=oddend[row + (col*FXKEYBOARD_HEIGHT_TILES)];
286287
}
287288
}
288289
}
289290

290-
for(int py=0; py<5; ++py)
291-
memcpy(map_base + (32*(py+y/8)+(x/8)), fxkb_map + (28 * py), 28 * 2);
291+
for(int py=0; py<FXKEYBOARD_HEIGHT_TILES; ++py)
292+
memcpy(map_base + (32*(py+y/8)+(x/8)), fxkb_map + (FXKEYBOARD_WIDTH_TILES * py), FXKEYBOARD_WIDTH_TILES * 2);
292293

293294
drawButtonLabels();
294295
drawCaption();

arm9/source/tobkit/fxkeyboard.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,17 @@ limitations under the License.
1919

2020
#include "tobkit/label.h"
2121

22-
#define FXBUTTON_WIDTH 13
22+
#define FXBUTTON_WIDTH 12
2323
#define FXBUTTON_HEIGHT 27
2424

2525
#define FXKEYBOARD_WIDTH 176
2626
#define FXKEYBOARD_HEIGHT 40
2727

28+
// the fx keyboard isn't quite as wide as the piano, but we want to draw blank tiles
29+
// over where the piano was anyway
30+
#define FXKEYBOARD_WIDTH_TILES 28
31+
#define FXKEYBOARD_HEIGHT_TILES 5
32+
2833
#define FXKEYBOARD_R_OVERDRAW 48
2934
#define FXKEYBOARD_LMARGIN 2
3035
#define FXKEYBOARD_YMARGIN 12
@@ -37,15 +42,18 @@ limitations under the License.
3742
#define FX_CATEGORY_FT 2
3843
#define FX_CATEGORY_VOL 3
3944

45+
// button state, can be added to tilemap index to get tile in said state
46+
// eg TILE_LCORNER + FXBUTTON_DISABLED = TILE_LCORNER (disabled)
4047
#define FXBUTTON_NORMAL 0
4148
#define FXBUTTON_DOWN 1
4249
#define FXBUTTON_DISABLED 2
4350

51+
// Tilemap indices
52+
#define TILE_BLANK 0x0000
4453
#define TILE_LCORNER 0x0001
4554
#define TILE_MID_EDGE 0x0004
4655
#define TILE_EVEN_END_EDGE 0x000d
4756
#define TILE_ODD_END_EDGE 0x0010
48-
#define TILE_BLANK 0x0000
4957
#define TILE_LEDGE 0x0013
5058
#define TILE_MID 0x0016
5159
#define TILE_EVEN_END_MID 0x001f
@@ -81,13 +89,14 @@ namespace tobkit {
8189

8290
void setLastCmd(u8 _last_cmd);
8391
u8 getLastCmd(void);
92+
8493
private:
8594
uint16* char_base, * map_base;
8695

8796
u8 category;
8897
u8 last_cmd;
8998

90-
u16 fxkb_map[140] __attribute__((aligned(4))) = { 0 };
99+
u16 fxkb_map[FXKEYBOARD_WIDTH_TILES*FXKEYBOARD_HEIGHT_TILES] __attribute__((aligned(4))) = { 0 };
91100
u16 fxkb_pal[16];
92101
u8 fxkb_state[NUM_FXKEYS] = { 0 };
93102
u8 fxkb_vals[NUM_FXKEYS] = { 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xf };

tobkit/source/digitbox.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,19 @@ void DigitBox::penDown(u8 px, u8 py) {
8888

8989
if((px>x)&&(px<x+width/4)&&(py>y)&&(py<y+9)&&digits==2) { // top left arrow
9090
btnstate = 1;
91-
if(value<max) value+=0x10;
91+
if (value > max-0x10) value = value + 0x10 - max - 1; // wrap around if (value + 0x10) > 0xff. so 0xf0 wraps to 0x00
92+
// if (0xf2 > 0xff-0x10) value = 0xff - 0xf2 - 0x10 + 1
93+
else value+=0x10;
9294
} else if((px>x)&&(px<x+width/4)&&(py>y+9)&&(py<y+18)&&digits==2) { // bottom left arrow
9395
btnstate = 2;
94-
if(value>min) value-=0x10;
96+
if (value < 0x10) value = max - 0x10 + value + 1; // likewise wrap around downwards
97+
else value-=0x10;
9598
} else if((px>x)&&(px>x+(width/4)*3)&&(py>y)&&(py<y+9)) { // top right arrow
9699
btnstate = 3;
97-
if(value<max) value++;
100+
if(value<max) value++; else value = min;
98101
} else if((px>x)&&(px>x+(width/4)*3)&&(py>y+9)&&(py<y+18)) { // bottom right arrow
99102
btnstate = 4;
100-
if(value>min) value--;
103+
if(value>min) value--; else value = max;
101104
}
102105

103106
if(value!=oldvalue) {

0 commit comments

Comments
 (0)