mirror of
https://github.com/safiire/n65.git
synced 2024-12-12 15:29:12 +00:00
Added an #assemble_string method to Assembler
This commit is contained in:
parent
da807a2056
commit
b292376fd9
@ -129,6 +129,14 @@ module N65
|
|||||||
@promises << exec_result if exec_result.is_a?(Proc)
|
@promises << exec_result if exec_result.is_a?(Proc)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Assemble the given string
|
||||||
|
def assemble_string(string)
|
||||||
|
string.split(/\n/).each do |line|
|
||||||
|
assemble_one_line(line)
|
||||||
|
end
|
||||||
|
fulfill_promises
|
||||||
|
end
|
||||||
|
|
||||||
# This will empty out our promise queue and try to fullfil operations
|
# This will empty out our promise queue and try to fullfil operations
|
||||||
# that required an undefined symbol when first encountered.
|
# that required an undefined symbol when first encountered.
|
||||||
def fulfill_promises
|
def fulfill_promises
|
||||||
|
@ -168,10 +168,7 @@ RSpec.describe(N65::SymbolTable) do
|
|||||||
ASM
|
ASM
|
||||||
end
|
end
|
||||||
|
|
||||||
before do
|
before { assembler.assemble_string(program) }
|
||||||
program.split(/\n/).each { |line| assembler.assemble_one_line(line) }
|
|
||||||
assembler.fulfill_promises
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'assigns the value of the scope main to the program counter value' do
|
it 'assigns the value of the scope main to the program counter value' do
|
||||||
expect(assembler.symbol_table.resolve_symbol('global.main')).to eq(0x8000)
|
expect(assembler.symbol_table.resolve_symbol('global.main')).to eq(0x8000)
|
||||||
@ -199,7 +196,6 @@ RSpec.describe(N65::SymbolTable) do
|
|||||||
end
|
end
|
||||||
let(:correct_binary) do
|
let(:correct_binary) do
|
||||||
[
|
[
|
||||||
0x4e, 0x45, 0x53, 0x1a, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
|
||||||
0x78, # SEI
|
0x78, # SEI
|
||||||
0xd8, # CLD
|
0xd8, # CLD
|
||||||
0xa9, 0x0, # LDA immediate 0
|
0xa9, 0x0, # LDA immediate 0
|
||||||
@ -210,12 +206,9 @@ RSpec.describe(N65::SymbolTable) do
|
|||||||
0x60 # RTS forward_symbol
|
0x60 # RTS forward_symbol
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
let(:emitted_rom) { assembler.emit_binary_rom.bytes[0...26] }
|
let(:emitted_rom) { assembler.emit_binary_rom.bytes[16...26] }
|
||||||
|
|
||||||
before do
|
before { assembler.assemble_string(program) }
|
||||||
program.split(/\n/).each { |line| assembler.assemble_one_line(line) }
|
|
||||||
assembler.fulfill_promises
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'assembles the branch to forward_symbol correctly' do
|
it 'assembles the branch to forward_symbol correctly' do
|
||||||
expect(emitted_rom).to eq(correct_binary)
|
expect(emitted_rom).to eq(correct_binary)
|
||||||
|
Loading…
Reference in New Issue
Block a user