Skip to content

Instantly share code, notes, and snippets.

@chesterbr
Created September 12, 2016 12:37
Show Gist options
  • Save chesterbr/9b44c93f12543d8078a1644a86eb8423 to your computer and use it in GitHub Desktop.
Save chesterbr/9b44c93f12543d8078a1644a86eb8423 to your computer and use it in GitHub Desktop.
[WIP] running ezbasic with Ruby2600's 6507 CPU emulator
#!/usr/bin/env ruby
require 'ruby2600'
rom_file = "/Users/chester/Downloads/ehbasic.bin"
rom_addr = 0xC000
# Initialize a CPU with 64K of memory
cpu = Ruby2600::CPU.new
memory = Array.new(64*1024) { 0 }
cpu.memory = memory
# Load the ROM file into memory
rom_contents = File.open(rom_file, "rb") { |f| f.read }.unpack('C*')
cpu.memory[rom_addr..rom_addr + rom_contents.size - 1] = rom_contents
# Point the input and output vectors to a RET instruction in the ROM
memory[0x0205] = 0x02
memory[0x0206] = 0xC1
memory[0x0207] = 0x02
memory[0x0208] = 0xC1
# Run!
cpu.pc = rom_addr
while true do
cpu.step
# Output the accumulator as a character if we jumped into the output vector
putc cpu.a.chr if cpu.pc == 0xE0ED
# TODO find which key is being currently pressed if we jump into the input vector
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment