|
19 | 19 | #include <stdlib.h> |
20 | 20 | #include <string.h> |
21 | 21 | #include <stdbool.h> |
| 22 | +#include <assert.h> |
22 | 23 |
|
23 | 24 | #include "compress.h" |
24 | 25 | #include "engine.h" |
@@ -387,7 +388,7 @@ static void sub_19C7(uint8_t val, uint16_t di); |
387 | 388 | static void sub_1A10(); |
388 | 389 | static void sub_1A72(); |
389 | 390 | static void draw_player_status(uint8_t val); |
390 | | -static void sub_1BF8(uint8_t color, uint8_t y_adjust); |
| 391 | +static void draw_player_stat(uint8_t color, uint8_t y_adjust, uint16_t player_record_offset); |
391 | 392 | static void sub_1C70(unsigned char *src_ptr); |
392 | 393 | static void sub_280E(); |
393 | 394 | static void sub_28B0(uint16_t flags, unsigned char *src_ptr, const unsigned char *base); |
@@ -4202,22 +4203,19 @@ static void draw_player_status(uint8_t val) |
4202 | 4203 | if (found == 0) { |
4203 | 4204 | // 1B53 (abnormal status not found) |
4204 | 4205 | uint8_t dl = 2; // health (red) |
4205 | | - cpu.bx = 0x14; // Player record offset |
4206 | 4206 | al = 8; |
4207 | 4207 | cpu.ax = (cpu.ax & 0xFF00) | al; |
4208 | | - sub_1BF8(dl, al); |
| 4208 | + draw_player_stat(dl, al, 0x14); |
4209 | 4209 |
|
4210 | 4210 | // 0x1B5D |
4211 | 4211 | dl = 3; // stun (green) |
4212 | | - cpu.bx = 0x18; // Player record offset |
4213 | 4212 | al = 0x0B; |
4214 | 4213 | cpu.ax = (cpu.ax & 0xFF00) | al; |
4215 | | - sub_1BF8(dl, al); |
| 4214 | + draw_player_stat(dl, al, 0x18); |
4216 | 4215 |
|
4217 | 4216 | dl = 4; // magic power (blue) |
4218 | | - cpu.bx = 0x1C; // Player record offset |
4219 | 4217 | al = 0x0E; |
4220 | | - sub_1BF8(dl, al); |
| 4218 | + draw_player_stat(dl, al, 0x1C); |
4221 | 4219 |
|
4222 | 4220 | al = byte_1BE5; |
4223 | 4221 | fill_color = al; |
@@ -6503,17 +6501,22 @@ void run_engine() |
6503 | 6501 | } |
6504 | 6502 |
|
6505 | 6503 | // Extracts player record value and stores it in word_11C0. |
6506 | | -static int sub_1C57(uint16_t offset) |
| 6504 | +// 0x1C57 |
| 6505 | +static uint16_t get_player_record(uint16_t offset) |
6507 | 6506 | { |
6508 | 6507 | unsigned char *c960 = get_player_data_base(); |
6509 | 6508 |
|
6510 | | - cpu.ax = c960[player_base_offset - 0xC960 + offset]; |
6511 | | - cpu.ax += (c960[player_base_offset - 0xC960 + 1 + offset]) << 8; |
| 6509 | + uint16_t val = c960[player_base_offset - 0xC960 + offset]; |
| 6510 | + val += (c960[player_base_offset - 0xC960 + 1 + offset]) << 8; |
6512 | 6511 |
|
6513 | | - word_11C0 = cpu.ax; |
6514 | | - return cpu.ax; |
| 6512 | + word_11C0 = val; |
| 6513 | + |
| 6514 | + return val; |
6515 | 6515 | } |
6516 | 6516 |
|
| 6517 | +// Inputs: 11C0, 11C2, 11C4 |
| 6518 | +// Side effects: |
| 6519 | +// sets 11C4, 11C6, and 11C8 |
6517 | 6520 | static void sub_11A0(int set_11C4) |
6518 | 6521 | { |
6519 | 6522 | uint32_t result; |
@@ -6592,25 +6595,26 @@ static void sub_11CE() |
6592 | 6595 | } |
6593 | 6596 | } |
6594 | 6597 |
|
6595 | | -static void sub_1BF8(uint8_t color, uint8_t y_adjust) |
| 6598 | +// 0x1BF8 |
| 6599 | +static void draw_player_stat(uint8_t color, uint8_t y_adjust, uint16_t player_record_offset) |
6596 | 6600 | { |
6597 | 6601 | uint16_t fill_color; |
6598 | 6602 |
|
6599 | 6603 | fill_color = color; |
6600 | 6604 | cpu.ax = draw_point.y + y_adjust; |
6601 | 6605 | g_linenum = cpu.ax; // line number |
6602 | | - if (sub_1C57(cpu.bx) != 0) { |
6603 | | - cpu.bx += 2; // now check max? |
6604 | | - push_word(cpu.bx); |
6605 | | - word_11C2 = 0x17; // max percentage? |
6606 | | - sub_11A0(0); |
6607 | | - cpu.bx = pop_word(); |
6608 | | - if (sub_1C57(cpu.bx) != 0) { |
6609 | | - // Calculate percentage of 0x17 that ratio is. |
6610 | | - sub_11CE(); |
6611 | | - cpu.ax = word_11C6; |
6612 | | - cpu.ax++; |
6613 | | - } |
| 6606 | + |
| 6607 | + uint16_t cur_val = get_player_record(player_record_offset); |
| 6608 | + uint16_t max_val = get_player_record(player_record_offset + 2); |
| 6609 | + |
| 6610 | + cpu.ax = cur_val; |
| 6611 | + |
| 6612 | + // Calculate ratio |
| 6613 | + if (cur_val != 0 && max_val != 0) { |
| 6614 | + assert(cur_val <= max_val); |
| 6615 | + |
| 6616 | + cpu.ax = (cur_val * 23) / max_val; |
| 6617 | + cpu.ax++; |
6614 | 6618 | } |
6615 | 6619 |
|
6616 | 6620 | // Draw color portion of status bar. |
|
0 commit comments