![]() |
Routines |
| Prev: AC68 | Up: Map | Next: AC9A |
|
Used by the routines at Print_Completion_Percentage and Set_Up_Line.
Divides H multiplied by 0100 by DE, one bit at a time. The quotient has eight bits, so DE must be greater than H for the answer to be right. The quotient is built up in the shadow registers and the working is done in the main registers, so the shadow registers are not preserved.
The line drawing code uses it to find how far to move across for each pixel moved down.
|
||||||||||||||||
| Divide | AC75 | LD L,H | Copy the dividend to L. | |||||||||||||
| AC76 | LD H,$00 | Clear H. | ||||||||||||||
| AC78 | EXX | Switch to the shadow registers. | ||||||||||||||
| AC79 | LD HL,$0000 | HL'=00 (the quotient so far). | ||||||||||||||
| AC7C | LD B,$08 | B'=08 (the number of bits). | ||||||||||||||
| Divide_Loop | AC7E | EXX | Switch to the main registers. | |||||||||||||
| AC7F | SLA L | Shift the dividend left. | ||||||||||||||
| AC81 | RL H | |||||||||||||||
| AC83 | PUSH HL | |||||||||||||||
| AC84 | AND A | |||||||||||||||
| AC85 | SBC HL,DE | Try to subtract the divisor. | ||||||||||||||
| AC87 | JR C,Divide_Restore | Jump to Divide_Restore if it does not go. | ||||||||||||||
| AC89 | POP AF | Discard the stashed dividend. | ||||||||||||||
| AC8A | EXX | Switch to the shadow registers. | ||||||||||||||
| AC8B | ADD HL,HL | Shift the quotient left. | ||||||||||||||
| AC8C | INC HL | Add one for the bit. | ||||||||||||||
| Divide_Next | AC8D | DJNZ Divide_Loop | Decrease the bit counter and loop back until all eight bits have been done. | |||||||||||||
| AC8F | PUSH HL | Stash the quotient on the stack. | ||||||||||||||
| AC90 | EXX | Switch to the main registers. | ||||||||||||||
| AC91 | LD E,L | Copy the remainder to DE. | ||||||||||||||
| AC92 | LD D,H | Copy H to D. | ||||||||||||||
| AC93 | POP HL | Restore HL from the stack. | ||||||||||||||
| AC94 | RET | Restore the quotient from the stack. | ||||||||||||||
| Divide_Restore | AC95 | POP HL | Restore the stashed dividend (the subtraction is undone). | |||||||||||||
| AC96 | EXX | Switch to the shadow registers. | ||||||||||||||
| AC97 | ADD HL,HL | Shift the quotient left. | ||||||||||||||
| AC98 | JR Divide_Next | Jump to Divide_Next. | ||||||||||||||
|
View the equivalent code in;
|
||||||||||||||||
| Prev: AC68 | Up: Map | Next: AC9A |