Routines
| Prev: A37D | Up: Map | Next: A476 |
A419: Print an amount of money
|
HL = a sum in the packed form the parser makes (DB67). Prints it the old way: '£n' if there are pounds, then shillings and pence as 's/d', 's/-' or 'dD'. Divides with A476 and prints digits with A490. 30 pence prints as '2/6', 36 as '3/-', 240 as '£1'.
How it works:
1. Take away the marker bit and convert the packed sum to pence, then print a space.
2. Pounds = pence / 240. If there are any, print the pound sign and the number. Stop if nothing is left; otherwise print a space.
3. Shillings = what is left / 12. If there are none, print the pence and 'D.' (as in '6D.').
4. Otherwise print the shillings, a stroke, and the pence, or '-' for none, as in '2/6' or '1/-'.
|
||||||||||||
| A419 | PUSH BC | Save BC on the stack | ||||||||||
| A41A | RES 7,H | Clear bit 7 of H - Unpack the sum: HL = total pence (seven bits a byte, marker bit dropped) | ||||||||||
| A41C | SLA L | Shift L left (double it) | ||||||||||
| A41E | SRL H | Shift H right (halve it) | ||||||||||
| A420 | RR L | Rotate L right through the carry | ||||||||||
| A422 | LD A,$20 | Load A with $20 - A space | ||||||||||
| A424 | CALL $A9B7 | Call the routine "Print character A, a word at a time (word wrap)" (A9B7) | ||||||||||
| A427 | LD DE,$00F0 | Load DE with $00F0 - Pounds = pence / 240 (A476) | ||||||||||
| A42A | CALL $A476 | Call the routine "Divide HL by DE: A = quotient, HL = remainder" (A476) | ||||||||||
| A42D | AND A | Test A for zero (this leaves A as it was and clears carry) | ||||||||||
| A42E | JR Z,$A442 | If A is zero, skip ahead to A442 | ||||||||||
| A430 | LD B,A | Copy A into B | ||||||||||
| A431 | LD A,$60 | Load A with $60 - Any: the pound sign (character $60 in the Spectrum's set) and the pounds | ||||||||||
| A433 | CALL $A9B7 | Call the routine "Print character A, a word at a time (word wrap)" (A9B7) | ||||||||||
| A436 | CALL $A490 | Call the routine "Print the number B (0-255) in decimal" (A490) | ||||||||||
| A439 | LD A,L | Copy L into A - Nothing left: done | ||||||||||
| A43A | OR H | Set in A the bits that are set in H | ||||||||||
| A43B | JR Z,$A467 | If the result is zero, jump on to A467 | ||||||||||
| A43D | LD A,$20 | Load A with $20 | ||||||||||
| A43F | CALL $A9B7 | Call the routine "Print character A, a word at a time (word wrap)" (A9B7) | ||||||||||
| A442 | LD DE,$000C | Load DE with $000C - Shillings = what is left / 12 | ||||||||||
| A445 | CALL $A476 | Call the routine "Divide HL by DE: A = quotient, HL = remainder" (A476) | ||||||||||
| A448 | AND A | Test A for zero (this leaves A as it was and clears carry) | ||||||||||
| A449 | JR Z,$A469 | None: just the pence and 'D.' (A469), as in '6D.' | ||||||||||
| A44B | LD B,A | Copy A into B - The shillings, a stroke, and the pence - or '-' for none: '2/6', '1/-' | ||||||||||
| A44C | CALL $A490 | Call the routine "Print the number B (0-255) in decimal" (A490) | ||||||||||
| A44F | LD A,$2F | Load A with $2F | ||||||||||
| A451 | CALL $A9B7 | Call the routine "Print character A, a word at a time (word wrap)" (A9B7) | ||||||||||
| A454 | LD A,L | Copy L into A | ||||||||||
| A455 | AND A | Test A for zero (this leaves A as it was and clears carry) | ||||||||||
| A456 | LD B,A | Copy A into B | ||||||||||
| A457 | JR Z,$A45E | If A is zero, skip ahead to A45E | ||||||||||
| A459 | CALL $A490 | Call the routine "Print the number B (0-255) in decimal" (A490) | ||||||||||
| A45C | JR $A467 | Skip ahead to A467 | ||||||||||
| A45E | LD A,$2D | Load A with $2D | ||||||||||
| A460 | CALL $A9B7 | Call the routine "Print character A, a word at a time (word wrap)" (A9B7) | ||||||||||
| A463 | XOR A | Clear A to zero (and the carry flag) - ($A026 = 0) | ||||||||||
| A464 | LD ($A026),A | Store A in $A026 in "Game variables" | ||||||||||
| A467 | POP BC | Restore BC from the stack | ||||||||||
| A468 | RET | Return to the caller | ||||||||||
| A469 | LD B,L | Copy L into B | ||||||||||
| A46A | CALL $A490 | Call the routine "Print the number B (0-255) in decimal" (A490) | ||||||||||
| A46D | LD A,$44 | Load A with $44 | ||||||||||
| A46F | CALL $A9B7 | Call the routine "Print character A, a word at a time (word wrap)" (A9B7) | ||||||||||
| A472 | LD A,$2E | Load A with $2E | ||||||||||
| A474 | JR $A460 | Go back to A460 | ||||||||||
| Prev: A37D | Up: Map | Next: A476 |