the 10th century. Middle Ages After the devastations of the Gothic Wars, under Longobard rule a set of written regulations was established, the Consuetudines Barenses, which influenced similar written constitutions in other southern cities. Until the arrival of the Normans, Bari continued to be governed by the Longobards and Byzantines, with only occasional interruption. Throughout this period, and indeed throughout the Middle Ages, Bari served as one of the major slave depots of the Mediterranean, providing a central location for the trade in Slavic slaves. The slaves were mostly captured by Venice from Dalmatia, the Holy Roman Empire from what is now Prussia and Poland, and the Byzantines from elsewhere in the Balkans, and were generally destined for other parts of the Byzantine Empire and (most frequently) the Muslim states surrounding the Mediterranean: the Abbasid Caliphate, the Umayyad Caliphate of Córdoba, the Emirate of Sicily, and the Fatimid Caliphate (which relied on Slavs purchased at the Bari market for its legions of Sakalaba Mamluks). For 20 years, Bari was the centre of the Emirate of Bari; the city was captured by its first emirs Kalfun in 847, who had been part of the mercenary garrison installed there by Radelchis I of Benevento. The city was conquered and the emirate extinguished in 871 following five-year campaign by Emperor Louis II, assisted by a Byzantine fleet. Chris Wickham states Louis spent five years campaigning to reduce then occupy Bari, "and then only to a Byzantine/Slav naval blockade"; "Louis took the credit" for the success, adding "at least in Frankish eyes", then concludes by noting that by remaining in southern Italy long after this success, he "achieved the near-impossible: an alliance against him of the Beneventans, Salernitans, Neapolitans and Spoletans; later sources include Sawadān as well." In 885, Bari became the residence of the local Byzantine catapan, or governor. The failed revolt (1009–1011) of the Lombard nobles Melus of Bari and his brother-in-law Dattus, against the Byzantine governorate, though it was firmly repressed at the Battle of Cannae (1018), offered their Norman adventurer allies a first foothold in the region. In 1025, under the Archbishop Byzantius, Bari became attached to the see of Rome and was granted "provincial" status. In 1071, Bari was captured by Robert Guiscard, following a three-year siege. The Basilica di San Nicola was founded in 1087 to receive the relics of this saint, which were surreptitiously brought from Myra