Although the origin of the alcabala is unclear, and it may have dated back to the era of Muslim rule, it is known that in 1342 Alfonso XI of Castile convinced the Cortes Generales (the equivalent of a parliament) to make it a royal duty for Castile. Originally the tax was specified to run for three years. However, reality might have been a more complicated story. For example, a 19th-century Spanish legal dictionary says that in 1341 it was conceded to Alfonso for three years to defray the costs of the Siege of Algeciras (1342-1344), extended in 1345 to maintain the costs of frontier castles, further extended in 1349 for the siege of Gibraltar and in 1388 for the war with Portugal, finally becoming perpetual in 1393.