Skip to content

Commit 6ad2712

Browse files
committed
Continuing to work on status bar
1 parent 7127b41 commit 6ad2712

File tree

3 files changed

+55
-31
lines changed

3 files changed

+55
-31
lines changed

src/lib/engine.c

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4141,7 +4141,7 @@ static void draw_player_status(uint8_t val)
41414141
word_36C2 = 0x4E; // ending point
41424142

41434143
while (1) {
4144-
ui_draw_solid_color(fill_color, word_36C0, word_36C2, g_linenum);
4144+
ui_draw_horizontal_line(fill_color, word_36C0, word_36C2, g_linenum);
41454145
g_linenum++;
41464146

41474147
if ((g_linenum & 0x0F) == 0) {
@@ -4225,9 +4225,9 @@ static void draw_player_status(uint8_t val)
42254225
word_36C0 = 0x36;
42264226
word_36C2 = 0x4E;
42274227
// 0x1B87
4228-
ui_draw_solid_color(fill_color, word_36C0, word_36C2, g_linenum);
4228+
ui_draw_horizontal_line(fill_color, word_36C0, word_36C2, g_linenum);
42294229
g_linenum -= 3;
4230-
ui_draw_solid_color(fill_color, word_36C0, word_36C2, g_linenum);
4230+
ui_draw_horizontal_line(fill_color, word_36C0, word_36C2, g_linenum);
42314231
reset_ui_background();
42324232
return;
42334233
}
@@ -6532,11 +6532,14 @@ static void sub_11A0(int set_11C4)
65326532
}
65336533

65346534
// Input is 11C0, 11C6, 11C8
6535+
// Output is 11CA, 11CC
65356536
static void sub_11CE()
65366537
{
65376538
int old_carry = 0;
65386539
int carry = 0;
65396540

6541+
printf("%s (input): 0x%04X 0x%04X 0x%04X\n", __func__, word_11C0, word_11C6, word_11C8);
6542+
65406543
word_11CA = 0;
65416544
word_11CC = 0;
65426545
cpu.cx = 0x20; // 32 times.
@@ -6589,15 +6592,6 @@ static void sub_11CE()
65896592
}
65906593
}
65916594

6592-
// 0x1C49
6593-
static void sub_1C49(uint16_t fill_color)
6594-
{
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);
6598-
ui_draw_solid_color(fill_color, word_36C0, word_36C2, g_linenum);
6599-
}
6600-
66016595
static void sub_1BF8(uint8_t color, uint8_t y_adjust)
66026596
{
66036597
uint16_t fill_color;
@@ -6608,28 +6602,32 @@ static void sub_1BF8(uint8_t color, uint8_t y_adjust)
66086602
if (sub_1C57(cpu.bx) != 0) {
66096603
cpu.bx += 2; // now check max?
66106604
push_word(cpu.bx);
6611-
word_11C2 = 0x17;
6605+
word_11C2 = 0x17; // max percentage?
66126606
sub_11A0(0);
66136607
cpu.bx = pop_word();
66146608
if (sub_1C57(cpu.bx) != 0) {
6609+
// Calculate percentage of 0x17 that ratio is.
66156610
sub_11CE();
66166611
cpu.ax = word_11C6;
66176612
cpu.ax++;
66186613
}
66196614
}
6615+
6616+
// Draw color portion of status bar.
6617+
word_36C0 = 0x36;
66206618
cpu.ax += 0x36;
66216619
word_36C2 = cpu.ax;
6622-
word_36C0 = 0x36;
6623-
sub_1C49(fill_color);
6620+
ui_draw_double_horizontal_line(fill_color, word_36C0, word_36C2, g_linenum);
66246621
cpu.ax = word_36C2;
66256622
if (cpu.ax == 0x4E) {
66266623
return;
66276624
}
66286625

66296626
// 1C3A
6627+
// Draw remaining black part of status bar.
66306628
word_36C0 = cpu.ax;
66316629
word_36C2 = 0x4E;
66326630
fill_color = byte_1BE5; // color.
6633-
sub_1C49(fill_color);
6631+
ui_draw_double_horizontal_line(fill_color, word_36C0, word_36C2, g_linenum);
66346632
}
66356633

src/lib/ui.c

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -571,27 +571,44 @@ void draw_ui_piece(const struct pic_data *pic)
571571
vga_update();
572572
}
573573

574+
// 0x1C49
575+
/* Draws two horizontal lines across the frame buffer in the specified color,
576+
* from x1 -> x2 on line y, and y+1 */
577+
void ui_draw_double_horizontal_line(
578+
uint8_t color_idx,
579+
uint16_t x1, uint16_t x2,
580+
uint16_t y)
581+
{
582+
// Does this order matter? It seems more natural to draw lines from top
583+
// to bottom, but this matches how the game did it.
584+
ui_draw_horizontal_line(color_idx, x1, x2, y + 1);
585+
ui_draw_horizontal_line(color_idx, x1, x2, y);
586+
}
587+
574588
/* 0x36C8 */
575-
void ui_draw_solid_color(uint8_t color_idx, uint16_t inset,
576-
uint16_t count, uint16_t line_num)
589+
/* Draws a horizontal line across the frame buffer in the specified color,
590+
* from x1 -> x2 on line y */
591+
void ui_draw_horizontal_line(
592+
uint8_t color_idx,
593+
uint16_t x1, uint16_t x2,
594+
uint16_t y)
577595
{
578-
// early exit.
579-
if (count <= inset) {
596+
// We only support drawing left to right.
597+
if (x2 <= x1) {
580598
return;
581599
}
582-
count -= inset;
583-
count = count << 1;
600+
601+
uint16_t len = x2 - x1;
602+
len = len << 1;
584603

585604
// bx = color
586-
uint8_t color = color_data[color_idx];
587-
color = color & 0x0F;
605+
uint8_t color = color_data[color_idx] & 0x0F;
588606

589-
uint16_t fb_off = get_line_offset(line_num);
590-
inset = inset << 2;
591-
fb_off += inset;
592-
uint8_t *framebuffer = vga_memory();
607+
uint16_t fb_off = get_line_offset(y);
608+
fb_off += (x1 << 2);
593609

594-
for (uint16_t i = 0; i < count; i++) {
610+
uint8_t *framebuffer = vga_memory();
611+
for (uint16_t i = 0; i < len; i++) {
595612
framebuffer[fb_off++] = color;
596613
framebuffer[fb_off++] = color;
597614
}

src/lib/ui.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,17 @@ void sub_35A0(uint8_t piece_index);
8080
void draw_pattern(struct ui_rect *rect);
8181
void ui_set_background(uint16_t val);
8282
void ui_draw_string(void);
83-
void ui_draw_solid_color(uint8_t color, uint16_t line_num,
84-
uint16_t inset, uint16_t count);
83+
84+
void ui_draw_horizontal_line(
85+
uint8_t color_idx,
86+
uint16_t x1, uint16_t x2,
87+
uint16_t y);
88+
89+
void ui_draw_double_horizontal_line(
90+
uint8_t color_idx,
91+
uint16_t x1, uint16_t x2,
92+
uint16_t y);
93+
8594
void draw_right_pillar();
8695
void reset_ui_background();
8796

0 commit comments

Comments
 (0)