#!/usr/bin/env python3 from collections import defaultdict map = { 0: 'slow', 1: 'fast', 2: 'mid', 3: 'slow', 4: 'mid', 5: 'fast', 6: 'mid', 7: 'slow' } def next_seed(seed): low = seed & 0xFF low_result = low * 5 high = (seed >> 8) & 0xFF high_result = (high * 5) & 0xFF result = (low_result & 0xFF) + ((low_result & 0xFF00) + (high_result << 8) + 0x0100) real_result = result + 0x11 + (1 if result > 0xFFFF else 0) return real_result & 0xFFFF def test(): seed = 0 seeds = [] while seed not in seeds: seeds.append(seed) seed = next_seed(seed) assert len(seeds) == 2280, len(seeds) def get_phantoon_pattern(seed): seed1 = next_seed(seed) seed2 = next_seed(seed1) return seed1 & 1, seed2 & 7 if 1: cnt = defaultdict(lambda: defaultdict(int)) seeds = [] seed = 0 while seed not in seeds: seeds.append(seed) dir, pat = get_phantoon_pattern(seed) cnt[dir][map[pat]] += 1 seed = next_seed(seed) assert len(seeds) == 2280 print('- left') for pat in ['slow', 'mid', 'fast']: print(pat, '=', (cnt[0][pat] / len(seeds)) * 100) print('- right') for pat in ['slow', 'mid', 'fast']: print(pat, '=', (cnt[1][pat] / len(seeds)) * 100) # 225 $80:8111 E2 20 SEP #$20 # 226 $80:8113 AD E5 05 LDA $05E5 [$7E:05E5] ;\ # 227 $80:8116 8D 02 42 STA $4202 [$7E:4202] ;} Random number low byte # 228 $80:8119 A9 05 LDA #$05 ;\ # 229 $80:811B 8D 03 42 STA $4203 [$7E:4203] ;} * 5 # 230 $80:811E EA NOP ; Waste cycles for multiplication # 231 $80:811F C2 20 REP #$20 ;\ # 232 $80:8121 AD 16 42 LDA $4216 [$7E:4216] ;} Push 16-bit result RN_low * 5 # 233 $80:8124 48 PHA ;/ # 234 $80:8125 E2 20 SEP #$20 # 235 $80:8127 AD E6 05 LDA $05E6 [$7E:05E6] ;\ # 236 $80:812A 8D 02 42 STA $4202 [$7E:4202] ;} RN_high # 237 $80:812D A9 05 LDA #$05 ;\ # 238 $80:812F 8D 03 42 STA $4203 [$7E:4203] ;} * 5 # 239 $80:8132 EB XBA ;\ # 240 $80:8133 EA NOP ;} Waste cycles for multiplication # 241 $80:8134 AD 16 42 LDA $4216 [$7E:4216] ; 8-bit result RN_high * 5 # 242 $80:8137 38 SEC ;\ # 243 $80:8138 63 02 ADC $02,s [$7E:1FFB] ;} Sum with 1 to the high byte of pushed value # 244 $80:813A 83 02 STA $02,s [$7E:1FFB] ;/ # 245 $80:813C C2 20 REP #$20 ;\ # 246 $80:813E 68 PLA ;} 16-bit result # 247 $80:813F 69 11 00 ADC #$0011 ; Further add 0x11 # 248 $80:8142 8D E5 05 STA $05E5 [$7E:05E5] ; Store back to RAM # 249 $80:8145 6B RTL