-
Notifications
You must be signed in to change notification settings - Fork 0
/
barramento.rb
50 lines (46 loc) · 1.34 KB
/
barramento.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
require 'gui'
require 'memoria'
class Barramento
def initialize
end
# Solicita do barramento a leitura do dado
# no endereço address.
# Entrada:
# type - Tipo de barramento: mem (memoria), io (I/O)
# address - Endereço que deseja-se ler
# qtd - quantidade de endereços que devem ser lidos
# Retorno:
# Valor contido em address
def Barramento.read(type,address, qtd)
# Define o valor do controle
con = qtd.to_s(2).rjust(2,'0') + "01"
con = con.to_i(2).to_s
Simulador.set_value_bus(type,"con",con)
Simulador.set_value_bus(type,"end",address)
Simulador.get_clock
case type
when 'mem'
value = Memoria.get_value(address,qtd)
when 'io'
value = Simulador.get_value_grid('io',address)
end
Simulador.set_value_bus(type,"data",value)
Simulador.set_value_bus(type,"con","0")
Simulador.get_clock
return value
end
def Barramento.write(type,address,value,qtd)
con = qtd.to_s(2).rjust(2,'0') + "10"
Simulador.set_value_bus(type,"con",con.to_i(2).to_s)
Simulador.set_value_bus(type,"end",address)
Simulador.set_value_bus(type,"data",value)
Simulador.get_clock
case type
when 'mem'
Memoria.set_value(address,value,qtd)
when 'io'
Simulador.set_value_grid('io',address,value)
end
Simulador.set_value_bus(type,"con","0")
end
end