comparison m68k.cpu @ 2590:e602dbf776d8

Fix abcd and implement sbcd and nbcd in new 68K core
author Michael Pavone <pavone@retrodev.com>
date Sun, 09 Feb 2025 02:57:37 -0800
parents 0ea26288d983
children 563d05355a12
comparison
equal deleted inserted replaced
2589:6bca3c28e2ad 2590:e602dbf776d8
671 671
672 and src dregs.D dregs.D Z 672 and src dregs.D dregs.D Z
673 update_flags NZV0C0 673 update_flags NZV0C0
674 m68k_prefetch 674 m68k_prefetch
675 675
676 1100XXX100000YYY abcd_dx_dy 676 1100XXX100000YYY abcd_dy_dx
677 local lowx 16 677 local lowx_corf 8
678 local lowy 16 678 local lowy_cmp 8
679 local highx 16 679 local res 8
680 local highy 16 680 lowx_corf = dregs.X & 0xF
681 lowx = dregs.X & 0xF 681 lowy_cmp = dregs.Y & 0xF
682 lowy = dregs.Y & 0xF 682 adc lowx_corf lowy_cmp lowy_cmp
683 adc lowx lowy lowy 683 if lowy_cmp >=U 0xA
684 if lowy >=U 0xA 684 lowx_corf = 6
685 lowy += 6 685 lowy_cmp = 0x9A
686 end 686 else
687 highx = dregs.X & 0xF0 687 lowx_corf = 0
688 highy = dregs.Y & 0xF0 688 lowy_cmp = 0xA0
689 highy += highx 689 end
690 highy += lowy 690 adc dregs.Y dregs.X res 0
691 if highy >=U 0xA0 691 update_flags XC
692 dregs.X:0 = highy + 0x60 692 if cflag
693 update_flags X1C1VN 693 lowx_corf |= 0x60
694 highy &= 0xFF 694 res += lowx_corf
695 if highy 695 update_flags NV
696 update_flags Z0 696 else
697 end 697 if res >=U lowy_cmp
698 else 698 lowx_corf |= 0x60
699 dregs.X:0 = highy 699 end
700 nflag = highy & 128 700 res += lowx_corf
701 if highy 701 update_flags XCNV
702 update_flags Z0 702 end
703 end 703 if res
704 update_flags X0C0V0 704 update_flags Z0
705 end 705 end
706 dregs.X:0 = res
706 cycles 2 707 cycles 2
707 m68k_prefetch 708 m68k_prefetch
708 709
709 1100XXX100001YYY abcd_ax_ay 710 1100XXX100001YYY abcd_ay_ax
710 local lowx 32 711 local lowx_corf 8
711 local lowy 32 712 local lowy_cmp 8
713 local res 8
712 if Y = 7 714 if Y = 7
713 aregs.Y -= 2 715 aregs.Y -= 2
714 else 716 else
715 aregs.Y -= 1 717 aregs.Y -= 1
716 end 718 end
724 else 726 else
725 aregs.X -= 1 727 aregs.X -= 1
726 end 728 end
727 scratch1 = aregs.X 729 scratch1 = aregs.X
728 ocall read_8 730 ocall read_8
729 lowx = scratch1 & 0xF 731 lowx_corf = scratch1 & 0xF
730 lowy = scratch2 & 0xF 732 lowy_cmp = scratch2 & 0xF
731 scratch1 &= 0xF0 733 adc lowx_corf lowy_cmp lowy_cmp
732 scratch2 &= 0xF0 734 if lowy_cmp >=U 0xA
733 adc lowx lowy lowy 735 lowx_corf = 6
734 if lowy >=U 0xA 736 lowy_cmp = 0x9A
735 lowy += 6 737 else
736 end 738 lowx_corf = 0
737 scratch1 += scratch2 739 lowy_cmp = 0xA0
738 scratch1 += lowy 740 end
739 if scratch1 >=U 0xA0 741 adc scratch2 scratch1 res 0
740 scratch1:0 += 0x60 742 update_flags XC
741 update_flags X1C1VN 743 update_flags XC
742 else 744 if cflag
743 cmp 0 scratch1 0 745 lowx_corf |= 0x60
744 update_flags X0C0V0N 746 res += lowx_corf
745 end 747 update_flags NV
746 scratch1 &= 0xFF 748 else
747 if scratch1 749 if res >=U lowy_cmp
750 lowx_corf |= 0x60
751 end
752 res += lowx_corf
753 update_flags XCNV
754 end
755 if res
748 update_flags Z0 756 update_flags Z0
749 end 757 end
758 scratch1 = res
750 scratch2 = aregs.X 759 scratch2 = aregs.X
751 ocall write_8 760 ocall write_8
752 m68k_prefetch 761 m68k_prefetch
753 762
754 1100XXX101000YYY exg_dn_dn 763 1100XXX101000YYY exg_dn_dn
1080 status |= scratch1 1089 status |= scratch1
1081 update_sync 1090 update_sync
1082 cycles 12 #TODO: where do these occur relative to fetches 1091 cycles 12 #TODO: where do these occur relative to fetches
1083 m68k_prefetch 1092 m68k_prefetch
1084 1093
1094 1000YYY100000XXX sbcd_dx_dy
1095 local lowx_corf 8
1096 local lowy 8
1097 local res 8
1098 lowx_corf = dregs.X & 0xF
1099 lowy = dregs.Y & 0xF
1100 sbc lowx_corf lowy lowy
1101 if lowy >=U 0x10
1102 lowx_corf = 6
1103 else
1104 lowx_corf = 0
1105 end
1106 sbc dregs.X dregs.Y res 0
1107 update_flags XC
1108 if cflag
1109 lowx_corf |= 0x60
1110 res -= lowx_corf
1111 update_flags NV
1112 else
1113 res -= lowx_corf
1114 update_flags XCNV
1115 end
1116 if res
1117 update_flags Z0
1118 end
1119 dregs.Y:0 = res
1120 cycles 2
1121 m68k_prefetch
1122
1123 1000YYY100001XXX sbcd_ax_ay
1124 local lowx_corf 8
1125 local lowy 8
1126 if X = 7
1127 aregs.X -= 2
1128 else
1129 aregs.X -= 1
1130 end
1131 #predec penalty on src only
1132 cycles 2
1133 scratch1 = aregs.X
1134 ocall read_8
1135 scratch2 = scratch1
1136 if Y = 7
1137 aregs.Y -= 2
1138 else
1139 aregs.Y -= 1
1140 end
1141 scratch1 = aregs.Y
1142 ocall read_8
1143 lowy = scratch1 & 0xF
1144 lowx_corf = scratch2 & 0xF
1145 sbc lowx_corf lowy lowy
1146 if lowy >=U 0x10
1147 lowx_corf = 6
1148 else
1149 lowx_corf = 0
1150 end
1151 sbc scratch2 scratch1 scratch1 0
1152 update_flags XC
1153 if cflag
1154 lowx_corf |= 0x60
1155 scratch1:0 -= lowx_corf
1156 update_flags NV
1157 else
1158 scratch1:0 -= lowx_corf
1159 update_flags XCNV
1160 end
1161 scratch1 &= 0xFF
1162 if scratch1
1163 update_flags Z0
1164 end
1165 scratch2 = aregs.Y
1166 ocall write_8
1167 m68k_prefetch
1168
1085 1000DDD011MMMRRR divu 1169 1000DDD011MMMRRR divu
1086 invalid M 1 1170 invalid M 1
1087 invalid M 7 R 5 1171 invalid M 7 R 5
1088 invalid M 7 R 6 1172 invalid M 7 R 6
1089 invalid M 7 R 7 1173 invalid M 7 R 7
1726 invalid M 1 1810 invalid M 1
1727 invalid M 7 R 5 1811 invalid M 7 R 5
1728 invalid M 7 R 6 1812 invalid M 7 R 6
1729 invalid M 7 R 7 1813 invalid M 7 R 7
1730 m68k_fetch_src_ea M R 1 1814 m68k_fetch_src_ea M R 1
1731 mov scratch1 ccr 1815 mov src ccr
1732 cycles 8 1816 cycles 8
1733 m68k_prefetch 1817 m68k_prefetch
1734 1818
1735 0100011011MMMRRR move_to_sr 1819 0100011011MMMRRR move_to_sr
1736 invalid M 1 1820 invalid M 1
1737 invalid M 7 R 5 1821 invalid M 7 R 5
1738 invalid M 7 R 6 1822 invalid M 7 R 6
1739 invalid M 7 R 7 1823 invalid M 7 R 7
1740 #TODO: privilege violation exception if in user mode 1824 #TODO: privilege violation exception if in user mode
1741 m68k_fetch_src_ea M R 1 1825 m68k_fetch_src_ea M R 1
1742 ccr = scratch1 1826 ccr = src
1743 status = scratch1 >> 8 1827 status = src >> 8
1744 check_user_mode_swap_ssp_usp 1828 check_user_mode_swap_ssp_usp
1745 update_sync 1829 update_sync
1746 cycles 8 1830 cycles 8
1747 m68k_prefetch 1831 m68k_prefetch
1748 1832
1802 end 1886 end
1803 end 1887 end
1804 dst:Z = 0 1888 dst:Z = 0
1805 update_flags N0Z1V0C0 1889 update_flags N0Z1V0C0
1806 m68k_save_dst Z 1890 m68k_save_dst Z
1891 m68k_prefetch
1892
1893 0100100000MMMRRR nbcd
1894 local lowx_corf 8
1895 local lowy_cmp 8
1896 local res 8
1897 invalid M 1
1898 invalid M 7 R 2
1899 invalid M 7 R 3
1900 invalid M 7 R 4
1901 invalid M 7 R 5
1902 invalid M 7 R 6
1903 invalid M 7 R 7
1904 m68k_fetch_dst_ea M R 0
1905 lowx_corf = dst & 0xF
1906 lowy_cmp = 0
1907 sbc lowx_corf lowy_cmp lowy_cmp
1908 if lowy_cmp >= 0xA
1909 lowx_corf = 6
1910 lowy_cmp = 0xA6
1911 else
1912 lowx_corf = 0
1913 lowy_cmp = 0xA0
1914 end
1915 res = 0
1916 sbc dst res res
1917 update_flags XC
1918 if cflag
1919 lowx_corf |= 0x60
1920 res -= lowx_corf
1921 update_flags NV
1922 else
1923 if res >=U lowy_cmp
1924 lowx_corf |= 0x60
1925 end
1926 res -= lowx_corf
1927 update_flags XCNV
1928 end
1929 if res
1930 update_flags Z0
1931 end
1932 dst:0 = res
1933 if M = 0
1934 cycles 2
1935 end
1936 m68k_save_dst 0
1807 m68k_prefetch 1937 m68k_prefetch
1808 1938
1809 00001100ZZMMMRRR cmpi 1939 00001100ZZMMMRRR cmpi
1810 local immed 32 1940 local immed 32
1811 invalid Z 3 1941 invalid Z 3