Port overflow fixes for daily interest and dividends; pay Modern dividends per manager

Daily interest and share dividends are computed in 64 bits before the
division (ported from OpenBMH 1.0.3). In Modern each manager now receives
the dividend of his own shares instead of the original's lost booking.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
MichaelandClaude Fable 5.2 committed 2026-11-13 23:47:09 +01:00
1 parent f0979455d1
commit 9e92d07b03
10 files changed
+59 -62

No files matched your search

+12 -8
View File
@@ -662,14 +662,18 @@ void shares_and_loans(ModernState& g) {
uint32_t price = mem.u32(at);
price += ((price / 10000) * 0x19 / 10) * 10;
mem.set32(at, price);
// (a bug of the original: only the last manager's dividend is kept and it is booked
// for the manager after the last one)
int32_t dividend = 0;
for (int m = 0; m < managers; m++)
dividend = int32_t(mem.u16(::bmh::layout::Advertising_OriginalShareAdjustment_RuntimeField + uint32_t(m) * 2 + uint32_t(k) * 0x1c) *
((price * uint32_t(kShareFactor[k])) / 10000));
modern::book_money(g, managers, -dividend, true);
add32(r, size_t(managers) * kRecord + 0x870, dividend);
// Modern deviates from Classic: every manager receives the dividend of his own shares.
// (Classic keeps the original's slip: only the last manager's dividend is computed and
// it is booked for the slot after the last manager, so nobody ever receives it.)
// The price product is kept in 64 bits until the division.
const uint64_t unit_dividend = (uint64_t(price) * uint32_t(kShareFactor[k])) / 10000;
for (int m = 0; m < managers; m++) {
const uint32_t held = mem.u16(::bmh::layout::Advertising_OriginalShareAdjustment_RuntimeField + uint32_t(m) * 2 + uint32_t(k) * 0x1c);
if (held == 0) continue;
const int32_t dividend = int32_t(std::min<uint64_t>(held * unit_dividend, 0x7fffffffu));
modern::book_money(g, m, -dividend, true);
add32(r, size_t(m) * kRecord + 0x870, dividend);
}
}
for (int m = 0; m < managers; m++)
for (int l = 0; l <= managers; l++) {