Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2019 Ole Friis Østergaard
Copyright (c) 2019-2022 Ole Friis Østergaard and Tina Wuest

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Please note!

This is a purely experimental branch integrating the MOS 6502 emulator from
https://github.com/wuest/livestream-6502-emu into `sidtool`.

# Sidtool

Convert Commodore 64 SID music in the form of `.sid` files into other formats!
Expand Down
46 changes: 37 additions & 9 deletions bin/sidtool
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env ruby
require 'sidtool'
require 'mos6510'
require 'optparse'

DEFAULT_FRAMES_TO_PROCESS = 15000
Expand Down Expand Up @@ -55,28 +54,57 @@ if show_info
puts "Songs: #{sid_file.songs} (start song: #{sid_file.start_song})"
end

def jsr(cpu, address, accumulator_value=0)
cpu.set_register_A(accumulator_value)
cpu.set_register_Y(0)
#cpu.set_register_P(0) What is register P?
cpu.set_register_S(255)
cpu.set_register_PC(address)
cpu.stack_S_push(0)
cpu.stack_S_push(0)
while (cpu.register_PC > 1)
cpu.clock
end
end

if output_file
load_address = sid_file.data[0] + (sid_file.data[1] << 8)
bus = Mos6502::TH8::Bus.new
cpu = ::MOS6502.new(bus)

# Map the SID to the address space
sid_mapping = bus.attach('SID', 0xD400, 0xD7FF)
sid = Sidtool::Sid.new
cpu = Mos6510::Cpu.new(sid: sid)
sid_mapping.set_read { |offset| 0 }
sid_mapping.set_write { |offset, byte| sid.poke(offset, byte) }

# Map some RAM to the rest of the address space
ram = bus.attach('RAM', 0x0000, 0xFFFF)
ram.alloc(0x10000)
ram.set_read { |offset| @mem[offset] }
ram.set_write { |offset, byte| @mem[offset] = (byte & 0xff) }

cpu.load(sid_file.data[2..-1], from: load_address)
cpu.start
load_address = sid_file.data[0] + (sid_file.data[1] << 8)

sid_file.data[2..-1].each_with_index do |byte, index|
ram.write(load_address + index, byte)
end

play_address = sid_file.play_address
if play_address == 0
cpu.jsr sid_file.init_address
play_address = (cpu.peek(0x0315) << 8) + cpu.peek(0x0314)
jsr(cpu, sid_file.init_address)
play_address = (ram.read(0x0315) << 8) + ram.read(0x0314)
STDERR.puts "New play address #{play_address}"
end

cpu.jsr sid_file.init_address, song - 1
jsr(cpu, sid_file.init_address, song - 1)

frames.times do
cpu.jsr play_address
jsr(cpu, play_address)
sid.finish_frame
Sidtool::STATE.current_frame += 1
if Sidtool::STATE.current_frame % 1000 == 0
puts "Frame #{Sidtool::STATE.current_frame}"
end
end

sid.stop!
Expand Down
3 changes: 3 additions & 0 deletions lib/sidtool.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
require 'sidtool/version'
require_relative 'sidtool/mos6502/th8.rb' # For Bus
require_relative 'sidtool/mos6502/cpudsl'
require_relative 'sidtool/mos6502/cpu6502'

module Sidtool
require 'sidtool/file_reader'
Expand Down
5 changes: 5 additions & 0 deletions lib/sidtool/mos6502/cpu.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Mos6502
class Cpu

end
end
Loading