Skip to content

Commit c226811

Browse files
committed
simplify pushdown logic
1 parent 2308a96 commit c226811

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

tests/src/pushdown.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pub fn test() {
55

66
for pushdown in 2..15 {
77
[0..1000, 24500..25500, 60000..65536].into_iter().for_each(|range| {
8+
// [0..65535].into_iter().for_each(|range| {
89
for score in range {
910
score::set(&mut emu, score);
1011

@@ -22,24 +23,22 @@ pub fn test() {
2223
}
2324

2425
// reference implementation - tested against the original game
25-
// may seem weird - designed to be translated to assembly
2626
fn pushdown_impl(pushdown: u8, score: u16) -> u16 {
2727
let ones = score % 10;
2828
let hundredths = score % 100;
29-
let mut newscore = ones as u8 + (pushdown - 1);
30-
if newscore & 0xF > 9 {
31-
newscore += 6;
32-
}
33-
34-
let low = (newscore & 0xF) as u16;
35-
let high = ((newscore & 0xF0) / 16 * 10) as u16;
3629

37-
let mut newscore = high + (hundredths - ones);
38-
let nextscore = newscore + low;
30+
let mut added = ones + (pushdown as u16 - 1);
3931

40-
if nextscore <= 100 {
41-
newscore = nextscore;
32+
if added & 0xF > 9 {
33+
added += 6;
4234
}
4335

44-
newscore - hundredths
36+
let low = added & 0xF;
37+
let high = (added >> 4) * 10;
38+
39+
if high + low + hundredths - ones <= 100 {
40+
high + low - ones
41+
} else {
42+
high - ones
43+
}
4544
}

0 commit comments

Comments
 (0)