Prev: 30300 Up: Map Next: 33000
32768: Multiply
Used by the routines at Update_Heading and Rotate_Coordinates.
Signed A*DE, scaled by 128. The result is in HL.
Input
A Multiplier
DE Multiplicand
Output
HL Product divided by 128
Multiply 32768 LD B,0 Set the sign to 0 in B.
32770 BIT 7,A Jump to Multiply_0 if the multiplier is positive.
32772 JR Z,Multiply_0
32774 NEG Negate the multiplier.
32776 INC B Increment the sign by one.
Multiply_0 32777 LD C,A Copy the multiplier to C.
32778 BIT 7,D Jump to Multiply_1 if the multiplicand is positive.
32780 JR Z,Multiply_1
32782 LD A,D Negate the multiplicand.
32783 CPL
32784 LD D,A
32785 LD A,E
32786 CPL
32787 LD E,A
32788 INC DE
32789 DEC B Decrease the sign by one.
Multiply_1 32790 LD A,B Stash the sign in AF'.
32791 EX AF,AF'
32792 XOR A Clear the 24-bit accumulator.
32793 LD B,A
32794 LD HL,0
Multiply the absolute values using bits 6-0 of the multiplier.
32797 BIT 6,C Jump to Multiply_2 if bit 6 of the multiplier is reset.
32799 JR Z,Multiply_2
32801 ADD HL,DE Add the multiplicand to the 24-bit accumulator.
32802 ADC A,B
Multiply_2 32803 ADD HL,HL Shift the 24-bit accumulator left.
32804 RLA
32805 BIT 5,C Jump to Multiply_3 if bit 5 of the multiplier is reset.
32807 JR Z,Multiply_3
32809 ADD HL,DE Add the multiplicand to the 24-bit accumulator.
32810 ADC A,B
Multiply_3 32811 ADD HL,HL Shift the 24-bit accumulator left.
32812 RLA
32813 BIT 4,C Jump to Multiply_4 if bit 4 of the multiplier is reset.
32815 JR Z,Multiply_4
32817 ADD HL,DE Add the multiplicand to the 24-bit accumulator.
32818 ADC A,B
Multiply_4 32819 ADD HL,HL Shift the 24-bit accumulator left.
32820 RLA
32821 BIT 3,C Jump to Multiply_5 if bit 3 of the multiplier is reset.
32823 JR Z,Multiply_5
32825 ADD HL,DE Add the multiplicand to the 24-bit accumulator.
32826 ADC A,B
Multiply_5 32827 ADD HL,HL Shift the 24-bit accumulator left.
32828 RLA
32829 BIT 2,C Jump to Multiply_6 if bit 2 of the multiplier is reset.
32831 JR Z,Multiply_6
32833 ADD HL,DE Add the multiplicand to the 24-bit accumulator.
32834 ADC A,B
Multiply_6 32835 ADD HL,HL Shift the 24-bit accumulator left.
32836 RLA
32837 BIT 1,C Jump to Multiply_7 if bit 1 of the multiplier is reset.
32839 JR Z,Multiply_7
32841 ADD HL,DE Add the multiplicand to the 24-bit accumulator.
32842 ADC A,B
Multiply_7 32843 ADD HL,HL Shift the 24-bit accumulator left.
32844 RLA
32845 BIT 0,C Jump to Multiply_8 if bit 0 of the multiplier is reset.
32847 JR Z,Multiply_8
32849 ADD HL,DE Add the multiplicand to the 24-bit accumulator.
32850 ADC A,B
Multiply_8 32851 ADD HL,HL Shift the 24-bit accumulator left.
32852 RLA
32853 BIT 7,L Test bit 7 of the low byte.
32855 LD L,H Take the high word of the 24-bit accumulator.
32856 LD H,A
32857 JR Z,Multiply_9 Jump to Multiply_9 if that bit was reset.
32859 INC HL Increment the product by one.
Multiply_9 32860 EX AF,AF' Restore the sign from AF'.
32861 AND A Jump to Multiply_10 if the sign is positive.
32862 JR Z,Multiply_10
32864 LD A,L Negate the product.
32865 CPL
32866 LD L,A
32867 LD A,H
32868 CPL
32869 LD H,A
32870 INC HL
Multiply_10 32871 RET Return.
32872 NOP
32873 NOP
32874 NOP
32875 RST 56
32876 AND B
32877 JP NC,Find_Empty_Slot_76
32880 CALL Z,Reprint_Status_7
32883 CALL 41157
32886 OUT (207),A
32888 ADD A,212
32890 RST 16
32891 POP BC
32892 JP NC,41157
32895 CP B
32896 OR H
32897 NOP
32898 NOP
32899 NOP
This entry point is used by the routine at Rotate_Coordinates.
Multiply_11 32900 LD HL,60928
32903 LD B,0
32905 AND A
32906 JP P,Multiply_12
32909 NEG
32911 INC B
Multiply_12 32912 LD (HL),A
32913 LD A,E
32914 AND A
32915 JP P,Multiply_13
32918 NEG
32920 DEC B
Multiply_13 32921 RLD
32923 LD L,(HL)
32924 LD H,237
32926 LD E,(HL)
32927 LD L,A
32928 LD D,(HL)
32929 LD HL,60928
32932 RLD
32934 LD C,(HL)
32935 LD H,237
32937 LD L,A
32938 LD A,(HL)
32939 LD L,C
32940 ADD A,(HL)
32941 LD HL,60928
32944 LD (HL),A
32945 XOR A
32946 RLD
32948 LD L,(HL)
32949 LD H,A
32950 ADD HL,DE
32951 ADD HL,HL
32952 BIT 7,L
32954 LD L,H
32955 LD H,0
32957 JR Z,Multiply_14
32959 INC HL
Multiply_14 32960 LD A,B
32961 AND A
32962 JR Z,Multiply_15
32964 LD A,L
32965 CPL
32966 LD L,A
32967 LD A,H
32968 CPL
32969 LD H,A
32970 INC HL
Multiply_15 32971 RET
32972 INC B
32973 BIT 7,D
32975 JR Z,Multiply_16
32977 LD A,D
32978 CPL
32979 LD D,A
32980 LD A,E
32981 CPL
32982 LD E,A
32983 INC DE
32984 DEC B
Multiply_16 32985 LD A,B
32986 EX AF,AF'
32987 LD A,0
32989 SRL H
32991 RR L
32993 RR A
32995 LD (60928),A
32998 LD A,L
32999 LD L,H
Prev: 30300 Up: Map Next: 33000