Prev: A5D2 Up: Map Next: A64F
A5D5: Update Prices
Used by the routine at CreateTownObjects.
Called every frame, but only does anything when the low byte of the frame counter is BD so once every 256 frames. It picks one of the three amounts on the telegram at random: the fine, the price of a horse or the price of a bullet. If the telegram has finished typing it chooses a new price from a table and retypes that line. The higher the level, the more prices the table offers, so prices tend to rise as the game goes on.
UpdatePrices A5D5 LD HL,($A216) Fetch the frame counter.
A5D8 LD A,L Copy its low byte into A.
A5D9 ADD A,$43 Add 43 which gives zero only when the low byte is BD.
A5DB RET NZ Return unless it is.
A5DC LD A,($A218) Fetch a random number.
A5DF AND %00000011 Keep bits 0 and 1.
A5E1 JR Z,UpdatePrices_Fine Jump to UpdatePrices_Fine to change the fine if the number is zero.
A5E3 DEC A Jump to UpdatePrices_HorsePrice to change the price of a horse if the number is one.
A5E4 JR Z,UpdatePrices_HorsePrice
Change the price of a bullet.
A5E6 CALL CheckTelegramComplete Check whether the telegram has finished typing.
A5E9 RET NZ Return if it has not.
A5EA XOR A Write 00 to TelegramLines to start typing the bullet line again.
A5EB LD ($A830),A
A5EE LD HL,$A25F Point HL at BulletPrice_HighByte.
A5F1 LD DE,$A83D Point DE at TelegramLines_BulletDigits.
A5F4 EXX Keep both in the alternate registers.
A5F5 LD HL,$A65F Point HL at BulletPrices.
Choose a new price from the table at HL, using more of the table as the level goes up.
UpdatePrices_ChooseNewPrice A5F8 LD A,($A260) Fetch the level.
A5FB CP $06 Jump to UpdatePrices_TestLevelThirteen if the level is six or more.
A5FD JR NC,UpdatePrices_TestLevelThirteen
A5FF LD A,$02 Allow the first two prices.
A601 JR UpdatePrices_StoreAllowed Jump to UpdatePrices_StoreAllowed.
UpdatePrices_TestLevelThirteen A603 CP $0D Jump to UpdatePrices_AllowEight if the level is thirteen or more.
A605 JR NC,UpdatePrices_AllowEight
A607 LD A,$04 Allow the first four prices.
A609 JR UpdatePrices_StoreAllowed Jump to UpdatePrices_StoreAllowed.
UpdatePrices_AllowEight A60B LD A,$08 Allow all eight prices.
UpdatePrices_StoreAllowed A60D LD C,A Copy the number of prices that are allowed into C.
A60E LD A,($A219) Fetch a random number.
A611 AND %00001111 Keep a number between 00 and 0F.
UpdatePrices_ChooseNewPriceLoop A613 CP C Jump to UpdatePrices_ReadPrice once the number is less than the number of prices allowed.
A614 JR C,UpdatePrices_ReadPrice
A616 SUB C Otherwise subtract the number of prices allowed.
A617 JR UpdatePrices_ChooseNewPriceLoop Loop back to UpdatePrices_ChooseNewPriceLoop.
UpdatePrices_ReadPrice A619 ADD A,A Double the number to get an offset into the table of words.
A61A LD E,A Copy the offset into E.
A61B LD D,$00 Clear D.
A61D ADD HL,DE Point HL at the chosen price.
A61E LD C,(HL) Fetch the low byte of the price.
A61F INC HL Move on to the high byte.
A620 LD B,(HL) Fetch the high byte of the price.
A621 PUSH BC Stash the price on the stack.
A622 EXX Bring back the address of the price and the digits.
A623 POP BC Fetch the new price into BC.
A624 JP ResetBulletPrice_SetPrice Store the new price, convert it to text and start typing the line again.
Change the fine.
UpdatePrices_Fine A627 CALL CheckTelegramComplete Check whether the telegram has finished typing.
A62A RET NZ Return if it has not.
A62B XOR A Write 00 to A854 to start typing the fine line again.
A62C LD ($A854),A
A62F LD HL,$A25B Point HL at Fine_HighByte.
A632 LD DE,$A861 Point DE at TelegramLines_FineDigits.
A635 EXX Keep both in the alternate registers.
A636 LD HL,$A67F Point HL at FineAmounts.
A639 JR UpdatePrices_ChooseNewPrice Jump to UpdatePrices_ChooseNewPrice.
Change the price of a horse.
UpdatePrices_HorsePrice A63B CALL CheckTelegramComplete Check whether the telegram has finished typing.
A63E RET NZ Return if it has not.
A63F XOR A Write 00 to A842 to start typing the horse line again.
A640 LD ($A842),A
A643 LD HL,$A25D Point HL at HorsePrice_HighByte.
A646 LD DE,$A84F Point DE at TelegramLines_HorseDigits.
A649 EXX Keep both in the alternate registers.
A64A LD HL,$A66F Point HL at HorsePrices.
A64D JR UpdatePrices_ChooseNewPrice Jump to UpdatePrices_ChooseNewPrice.
Prev: A5D2 Up: Map Next: A64F