Adding modding folder with a hacked build.

This commit is contained in:
ml
2026-09-26 08:53:08 +02:00
parent cdb960dc71
commit c91080aba7
755 changed files with 50424 additions and 0 deletions
@@ -0,0 +1,26 @@
package numbers
// ToBinaryCodedDecimal converts given integer value to a 4-digit BCD value.
func ToBinaryCodedDecimal(value uint16) (bcd uint16) {
factors := []uint16{1000, 100, 10, 1}
value %= 10000
for _, factor := range factors {
bcd = (bcd << 4) | (value / factor)
value %= factor
}
return
}
// FromBinaryCodedDecimal converts given 4-digit BCD value into an integer.
func FromBinaryCodedDecimal(bcd uint16) (value uint16) {
factors := []uint16{1, 10, 100, 1000}
for _, factor := range factors {
value += (bcd & 0xF) * factor
bcd >>= 4
}
return
}
@@ -0,0 +1,37 @@
package numbers_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/inkyblackness/hacked/ss1/content/numbers"
)
func TestBinaryCodedDecimal(t *testing.T) {
tt := []struct {
int uint16
bcd uint16
}{
{int: 0, bcd: 0x0000},
{int: 1, bcd: 0x0001},
{int: 20, bcd: 0x0020},
{int: 300, bcd: 0x0300},
{int: 4000, bcd: 0x4000},
{int: 50000, bcd: 0x0000},
{int: 9999, bcd: 0x9999},
{int: 451, bcd: 0x0451},
}
for _, tc := range tt {
toBCD := numbers.ToBinaryCodedDecimal(tc.int)
assert.Equal(t, tc.bcd, toBCD, "Wrong result converting to BCD for %d", tc.int)
fromBCD := numbers.FromBinaryCodedDecimal(tc.bcd)
if tc.int <= 9999 {
assert.Equal(t, tc.int, fromBCD, "Wrong result converting from BCD for %d", tc.int)
} else {
assert.Equal(t, uint16(0), fromBCD, "Wrong result converting from BCD for %d", tc.int)
}
}
}