Prev: 765C Up: Map Next: 80E8
8000: Multiply
Used by the routines at Update_Heading and Rotate_Coordinates.
Signed A*DE, scaled by 80. The result is in HL.
Input
A Multiplier
DE Multiplicand
Output
HL Product divided by 80
Multiply 8000 LD B,$00 Set the sign to 00 in B.
8002 BIT 7,A Jump to Multiply_0 if the multiplier is positive.
8004 JR Z,Multiply_0
8006 NEG Negate the multiplier.
8008 INC B Increment the sign by one.
Multiply_0 8009 LD C,A Copy the multiplier to C.
800A BIT 7,D Jump to Multiply_1 if the multiplicand is positive.
800C JR Z,Multiply_1
800E LD A,D Negate the multiplicand.
800F CPL
8010 LD D,A
8011 LD A,E
8012 CPL
8013 LD E,A
8014 INC DE
8015 DEC B Decrease the sign by one.
Multiply_1 8016 LD A,B Stash the sign in AF'.
8017 EX AF,AF'
8018 XOR A Clear the 24-bit accumulator.
8019 LD B,A
801A LD HL,$0000
Multiply the absolute values using bits 6-0 of the multiplier.
801D BIT 6,C Jump to Multiply_2 if bit 6 of the multiplier is reset.
801F JR Z,Multiply_2
8021 ADD HL,DE Add the multiplicand to the 24-bit accumulator.
8022 ADC A,B
Multiply_2 8023 ADD HL,HL Shift the 24-bit accumulator left.
8024 RLA
8025 BIT 5,C Jump to Multiply_3 if bit 5 of the multiplier is reset.
8027 JR Z,Multiply_3
8029 ADD HL,DE Add the multiplicand to the 24-bit accumulator.
802A ADC A,B
Multiply_3 802B ADD HL,HL Shift the 24-bit accumulator left.
802C RLA
802D BIT 4,C Jump to Multiply_4 if bit 4 of the multiplier is reset.
802F JR Z,Multiply_4
8031 ADD HL,DE Add the multiplicand to the 24-bit accumulator.
8032 ADC A,B
Multiply_4 8033 ADD HL,HL Shift the 24-bit accumulator left.
8034 RLA
8035 BIT 3,C Jump to Multiply_5 if bit 3 of the multiplier is reset.
8037 JR Z,Multiply_5
8039 ADD HL,DE Add the multiplicand to the 24-bit accumulator.
803A ADC A,B
Multiply_5 803B ADD HL,HL Shift the 24-bit accumulator left.
803C RLA
803D BIT 2,C Jump to Multiply_6 if bit 2 of the multiplier is reset.
803F JR Z,Multiply_6
8041 ADD HL,DE Add the multiplicand to the 24-bit accumulator.
8042 ADC A,B
Multiply_6 8043 ADD HL,HL Shift the 24-bit accumulator left.
8044 RLA
8045 BIT 1,C Jump to Multiply_7 if bit 1 of the multiplier is reset.
8047 JR Z,Multiply_7
8049 ADD HL,DE Add the multiplicand to the 24-bit accumulator.
804A ADC A,B
Multiply_7 804B ADD HL,HL Shift the 24-bit accumulator left.
804C RLA
804D BIT 0,C Jump to Multiply_8 if bit 0 of the multiplier is reset.
804F JR Z,Multiply_8
8051 ADD HL,DE Add the multiplicand to the 24-bit accumulator.
8052 ADC A,B
Multiply_8 8053 ADD HL,HL Shift the 24-bit accumulator left.
8054 RLA
8055 BIT 7,L Test bit 7 of the low byte.
8057 LD L,H Take the high word of the 24-bit accumulator.
8058 LD H,A
8059 JR Z,Multiply_9 Jump to Multiply_9 if that bit was reset.
805B INC HL Increment the product by one.
Multiply_9 805C EX AF,AF' Restore the sign from AF'.
805D AND A Jump to Multiply_10 if the sign is positive.
805E JR Z,Multiply_10
8060 LD A,L Negate the product.
8061 CPL
8062 LD L,A
8063 LD A,H
8064 CPL
8065 LD H,A
8066 INC HL
Multiply_10 8067 RET Return.
8068 NOP
8069 NOP
806A NOP
806B RST $38
806C AND B
806D JP NC,Find_Empty_Slot_76
8070 CALL Z,Reprint_Status_7
8073 CALL $A0C5
8076 OUT ($CF),A
8078 ADD A,$D4
807A RST $10
807B POP BC
807C JP NC,$A0C5
807F CP B
8080 OR H
8081 NOP
8082 NOP
8083 NOP
This entry point is used by the routine at Rotate_Coordinates.
Multiply_11 8084 LD HL,$EE00
8087 LD B,$00
8089 AND A
808A JP P,Multiply_12
808D NEG
808F INC B
Multiply_12 8090 LD (HL),A
8091 LD A,E
8092 AND A
8093 JP P,Multiply_13
8096 NEG
8098 DEC B
Multiply_13 8099 RLD
809B LD L,(HL)
809C LD H,$ED
809E LD E,(HL)
809F LD L,A
80A0 LD D,(HL)
80A1 LD HL,$EE00
80A4 RLD
80A6 LD C,(HL)
80A7 LD H,$ED
80A9 LD L,A
80AA LD A,(HL)
80AB LD L,C
80AC ADD A,(HL)
80AD LD HL,$EE00
80B0 LD (HL),A
80B1 XOR A
80B2 RLD
80B4 LD L,(HL)
80B5 LD H,A
80B6 ADD HL,DE
80B7 ADD HL,HL
80B8 BIT 7,L
80BA LD L,H
80BB LD H,$00
80BD JR Z,Multiply_14
80BF INC HL
Multiply_14 80C0 LD A,B
80C1 AND A
80C2 JR Z,Multiply_15
80C4 LD A,L
80C5 CPL
80C6 LD L,A
80C7 LD A,H
80C8 CPL
80C9 LD H,A
80CA INC HL
Multiply_15 80CB RET
80CC INC B
80CD BIT 7,D
80CF JR Z,Multiply_16
80D1 LD A,D
80D2 CPL
80D3 LD D,A
80D4 LD A,E
80D5 CPL
80D6 LD E,A
80D7 INC DE
80D8 DEC B
Multiply_16 80D9 LD A,B
80DA EX AF,AF'
80DB LD A,$00
80DD SRL H
80DF RR L
80E1 RR A
80E3 LD ($EE00),A
80E6 LD A,L
80E7 LD L,H
Prev: 765C Up: Map Next: 80E8