Skip to content

Commit 7127b41

Browse files
committed
Small refactor of player status drawing
1 parent 873cdce commit 7127b41

File tree

3 files changed

+51
-30
lines changed

3 files changed

+51
-30
lines changed

src/lib/engine.c

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ static void sub_176A();
386386
static void sub_19C7(uint8_t val, uint16_t di);
387387
static void sub_1A10();
388388
static void sub_1A72();
389-
static void sub_1ABD(uint8_t val);
389+
static void draw_player_status(uint8_t val);
390390
static void sub_1BF8(uint8_t color, uint8_t y_adjust);
391391
static void sub_1C70(unsigned char *src_ptr);
392392
static void sub_280E();
@@ -3652,7 +3652,7 @@ static void op_7D(void)
36523652
}
36533653

36543654
// 0x1BE6
3655-
static void sub_1BE6(int counter)
3655+
static void append_spaces(int counter)
36563656
{
36573657
counter -= draw_point.x;
36583658
if (counter <= 0)
@@ -3678,7 +3678,7 @@ static void advance_cursor(void)
36783678
al += draw_rect.x;
36793679
cpu.ax = (cpu.ax & 0xFF00) | al;
36803680

3681-
sub_1BE6(al);
3681+
append_spaces(al);
36823682
}
36833683

36843684
// 0x1DCA
@@ -4084,7 +4084,7 @@ static void sub_1A72()
40844084
val = 0x01;
40854085
}
40864086
al = val;
4087-
sub_1ABD(al);
4087+
draw_player_status(al);
40884088
set_game_state(__func__, 0x18 + counter, 0xFF);
40894089
}
40904090
counter--;
@@ -4099,7 +4099,7 @@ static void sub_1A72()
40994099

41004100
// 0x1ABD
41014101
// input will be 0x01 or 0x10
4102-
static void sub_1ABD(uint8_t val)
4102+
static void draw_player_status(uint8_t val)
41034103
{
41044104
uint8_t al, ah, bl;
41054105
uint16_t fill_color; // 3713
@@ -4113,7 +4113,7 @@ static void sub_1ABD(uint8_t val)
41134113

41144114
ui_set_background(cpu.ax);
41154115

4116-
bl = game_state.unknown[0x6];
4116+
bl = game_state.unknown[0x6]; // current character
41174117
al = bl;
41184118
al = al << 4;
41194119
al += 0x20;
@@ -4130,6 +4130,8 @@ static void sub_1ABD(uint8_t val)
41304130

41314131
al = game_state.unknown[6];
41324132
if (al >= game_state.unknown[31]) {
4133+
// Since this character is not in the game, we just draw a blank 15 line square.
4134+
41334135
// 1AF6
41344136
fill_color = byte_1BE5; // color ?
41354137
al = draw_point.y;
@@ -4150,6 +4152,8 @@ static void sub_1ABD(uint8_t val)
41504152
return;
41514153
}
41524154

4155+
// We now have a player.
4156+
41534157
// 1B22
41544158
al = 0xC;
41554159
cpu.ax = (cpu.ax & 0xFF00) | al;
@@ -4169,17 +4173,21 @@ static void sub_1ABD(uint8_t val)
41694173
al = al >> 1;
41704174
al = al + 0x1B + carry; // adc al, 0x1B
41714175
cpu.ax = (cpu.ax & 0xFF00) | al;
4172-
sub_1BE6(al);
4176+
4177+
// Center name, with spaces before and after.
4178+
append_spaces(al);
41734179
write_character_name();
41744180
al = 0x27;
41754181
cpu.ax = (cpu.ax & 0xFF00) | al;
4176-
sub_1BE6(al);
4182+
append_spaces(al);
4183+
41774184
di = c960 + (player_base_offset - 0xC960);
41784185
al = di[0x4C];
41794186

41804187
si = 3;
41814188

41824189
// 1B4A
4190+
// look for statuses "dead, stunned, poisoned, or chained"
41834191
int found = 0;
41844192
while (si >= 0) {
41854193
uint8_t si_val = get_1BC1_table(si);
@@ -4190,23 +4198,27 @@ static void sub_1ABD(uint8_t val)
41904198
si--;
41914199
}
41924200

4201+
// character is in normal status.
41934202
if (found == 0) {
4194-
// 1B53 (not found)
4195-
uint8_t dl = 2; // health
4196-
cpu.bx = 0x14;
4203+
// 1B53 (abnormal status not found)
4204+
uint8_t dl = 2; // health (red)
4205+
cpu.bx = 0x14; // Player record offset
41974206
al = 8;
41984207
cpu.ax = (cpu.ax & 0xFF00) | al;
41994208
sub_1BF8(dl, al);
4209+
42004210
// 0x1B5D
4201-
dl = 3; // stun
4202-
cpu.bx = 0x18;
4211+
dl = 3; // stun (green)
4212+
cpu.bx = 0x18; // Player record offset
42034213
al = 0x0B;
42044214
cpu.ax = (cpu.ax & 0xFF00) | al;
42054215
sub_1BF8(dl, al);
4206-
dl = 4; // magic
4207-
cpu.bx = 0x1C;
4216+
4217+
dl = 4; // magic power (blue)
4218+
cpu.bx = 0x1C; // Player record offset
42084219
al = 0x0E;
42094220
sub_1BF8(dl, al);
4221+
42104222
al = byte_1BE5;
42114223
fill_color = al;
42124224
g_linenum--;
@@ -4219,25 +4231,25 @@ static void sub_1ABD(uint8_t val)
42194231
reset_ui_background();
42204232
return;
42214233
}
4234+
4235+
// Not in normal status, so indicate that.
42224236
// 1B95
42234237
draw_point.y += 8;
42244238
draw_point.x = 0x1B;
42254239

42264240
al = data_1BC5[si];
4227-
sub_1BE6(al);
4241+
append_spaces(al);
42284242

42294243
unsigned char data_1BAA[] = { 0x54, 0x82, 0x00 }; // "is "
42304244
sub_1C70(data_1BAA);
42314245
// 1BAD
42324246

42334247
extract_string(str_table_status[si], 0, handle_byte_callback);
42344248
al = 0x27;
4235-
sub_1BE6(0x27);
4249+
append_spaces(0x27);
42364250
reset_ui_background();
42374251
}
42384252

4239-
4240-
42414253
// 0x2CF5
42424254
// Get timer ticks?
42434255
static void sub_2CF5()
@@ -6033,7 +6045,7 @@ static void op_96()
60336045

60346046
ui_draw_string();
60356047
al = draw_rect.w;
6036-
sub_1BE6(al);
6048+
append_spaces(al);
60376049
}
60386050

60396051
// 0x42FB
@@ -6490,12 +6502,13 @@ void run_engine()
64906502
free(data_D760);
64916503
}
64926504

6493-
static int sub_1C57()
6505+
// Extracts player record value and stores it in word_11C0.
6506+
static int sub_1C57(uint16_t offset)
64946507
{
64956508
unsigned char *c960 = get_player_data_base();
64966509

6497-
cpu.ax = c960[player_base_offset - 0xC960 + cpu.bx];
6498-
cpu.ax += (c960[player_base_offset - 0xC960 + 1 + cpu.bx]) << 8;
6510+
cpu.ax = c960[player_base_offset - 0xC960 + offset];
6511+
cpu.ax += (c960[player_base_offset - 0xC960 + 1 + offset]) << 8;
64996512

65006513
word_11C0 = cpu.ax;
65016514
return cpu.ax;
@@ -6576,11 +6589,12 @@ static void sub_11CE()
65766589
}
65776590
}
65786591

6592+
// 0x1C49
65796593
static void sub_1C49(uint16_t fill_color)
65806594
{
6581-
g_linenum++;
6582-
ui_draw_solid_color(fill_color, word_36C0, word_36C2, g_linenum);
6583-
g_linenum--;
6595+
// Does this order matter? It seems more natural to draw lines from top
6596+
// to bottom, but this matches how the game did it.
6597+
ui_draw_solid_color(fill_color, word_36C0, word_36C2, g_linenum + 1);
65846598
ui_draw_solid_color(fill_color, word_36C0, word_36C2, g_linenum);
65856599
}
65866600

@@ -6591,13 +6605,13 @@ static void sub_1BF8(uint8_t color, uint8_t y_adjust)
65916605
fill_color = color;
65926606
cpu.ax = draw_point.y + y_adjust;
65936607
g_linenum = cpu.ax; // line number
6594-
if (sub_1C57() != 0) {
6595-
cpu.bx += 2;
6608+
if (sub_1C57(cpu.bx) != 0) {
6609+
cpu.bx += 2; // now check max?
65966610
push_word(cpu.bx);
65976611
word_11C2 = 0x17;
65986612
sub_11A0(0);
65996613
cpu.bx = pop_word();
6600-
if (sub_1C57() != 0) {
6614+
if (sub_1C57(cpu.bx) != 0) {
66016615
sub_11CE();
66026616
cpu.ax = word_11C6;
66036617
cpu.ax++;

src/lib/player.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ struct player_record {
237237
struct spell_info spells; // 0x3C -> 0x44
238238

239239
unsigned char unknown[8]; // 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B
240-
unsigned char status; // bitfield (0 = Ok, 1 = dead, 2 = chained, 4 = poisoned) 0x4C
240+
unsigned char status; // bitfield (0 = Ok, 1 = dead, 2 = chained, 4 = poisoned, 8 = stunned) 0x4C
241241
unsigned char unknown_byte; // always 0 ? 0x4D
242242
unsigned char gender; // 0 = male, 1 = female // 0x4E
243243
unsigned short level; // 0x4F-0x50

src/lib/ui.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ static struct rect_dimension rect_dimensions[] = {
8888
};
8989

9090
// 0x3797
91+
// Indexes into the palette, in 16/256 color mode, the following
92+
// are the colors:
93+
// 00 = Black
94+
// FF = White
95+
// CC = Red
96+
// AA = Green
97+
// 99 = Blue
9198
static unsigned char color_data[] = {
9299
0x00, 0xFF, 0xCC, 0xAA, 0x99
93100
};

0 commit comments

Comments
 (0)