Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9038351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:28:04+00:00 2026-06-16T09:28:04+00:00

My work on a 6502 emulator is continuing. I’ve run into some quirks with

  • 0

My work on a 6502 emulator is continuing. I’ve run into some quirks with the embedded processor emulation wherein I need to load a 6502 binary file in an array starting at 0x1000.

Of course, loading a file is easy. But the offset part is isn’t. In C, I can do it easily.

Here’s the code for loading a file I’m using right now:

  def loadbinary(filename)
    @prog = File.open(filen, "rb") { |io| io.read }
    @imagesize = @prog.size
  end

If the load is loaded at 0x1000, the preceding space can be empty (before 0x1000).

Any ideas?

For anyone interesting, this is for the 6502.rb project I have on GitHub

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T09:28:06+00:00Added an answer on June 16, 2026 at 9:28 am

    You’ll probably need to allocate an array of n bytes, where n is the size of addressable RAM you want to emulate. From there you can start storing your data read in from the file into “RAM”.

    This is what I’d start with:

    def loadbinary(filename)
      @prog = File.read(filename, 'rb')
      @imagesize = @prog.bytesize
    end
    
    RAM_SIZE = 1024 * 64
    RAM = Array.new(RAM_SIZE)
    
    loadbinary('/path/to/foo')
    RAM[0x1000, @imagesize] = @prog.bytes.to_a
    

    Note: You can’t use String.size to get the length of the string, because it allows for multibyte characters. Instead, to get the number of bytes, you need bytesize, which, according to the documentation:

    Returns the length of str in bytes.

    Similarly, we can’t try to convert @prog into an array using split('') because that allows for multibyte characters too. Instead, we can get the bytes and turn that into an array. It could be done using unpack or bytes.to_a.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I work on win7 and need to allocate 2 buffers using malloc ,each of
We work with some very large databases (300Gb - 1Tb). Tables can contain from
Work on C#, in one of my application I need to get the SQL
Work on C#.In my application several time need to select\collect datafrom DB.Fro this task
At work we run vista for all the laptop. I dont like it very
To work with Xuggler you need xuggle-xuggler-5.4.jar . According to the people who made
I work with Cocos2d. This CocosDention not have the property that i need. Maybe
My work has over 24 pages in Latex. I need only the abstract and
I work as a ERP programmer, mostly with MS SQL and some kind of
I work on an Android app, what should simply post some information about the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.