Prev: 53924 Up: Map Next: 53997
53933: Scale The Roll
Used by the routine at GetRandomNumber.
Mixes the seed at 41015 with the counter at 41017 and scales A down to the limit in C.
ScaleTheRoll 53933 PUSH IX Keep the record and the count, copy the roll into C, and go to ScaleTheRoll_Advance if bit 7 is clear.
53935 PUSH BC
53936 LD C,A
53937 SLA A
53939 JR NC,ScaleTheRoll_Advance
53941 LD A,255 Take 255 for the count.
ScaleTheRoll_Advance 53943 LD B,A Use the value in A as the count.
ScaleTheRoll_Count 53944 LD IX,41017 Jump to ScaleTheRoll_ObjectAttributeFlag if the count has not reached zero.
53948 INC (IX+1)
53951 JR NZ,ScaleTheRoll_ObjectAttributeFlag
53953 INC (IX+0) Add one to the high byte of the counter at 41017.
ScaleTheRoll_ObjectAttributeFlag 53956 LD IX,(41017) Point IX at 41017 and read the random seed (41015).
53960 LD A,(41015)
53963 ADC A,(IX+0) Add the seed byte.
53966 ADD IX,DE Add the offset to the seed pointer, mix in the next seed byte and keep the pointer.
53968 XOR (IX+1)
53971 PUSH HL
53972 LD HL,41015 Use the random seed (41015).
53975 CP (HL) Jump back to ScaleTheRoll_Count if the mixed seed matches the seed at 41015.
53976 POP HL
53977 JR Z,ScaleTheRoll_Count
53979 LD (41015),A Record the random seed.
ScaleTheRoll_Loop 53982 CP B Jump ahead to ScaleTheRoll_Continue if the first value is below the second.
53983 JR C,ScaleTheRoll_Continue
53985 JR Z,ScaleTheRoll_Continue Go to ScaleTheRoll_Continue if the first value equals the second.
53987 SRL A Shift the roll down and test it again from ScaleTheRoll_Loop.
53989 JP ScaleTheRoll_Loop
Return.
ScaleTheRoll_Continue 53992 SUB C Take away the other byte.
53993 POP BC Restore the saved count and the saved character record from the stack.
53994 POP IX
53996 RET Return.
View the equivalent code in;
Prev: 53924 Up: Map Next: 53997