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

  • SEARCH
  • Home
  • 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 8738153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:40:51+00:00 2026-06-13T10:40:51+00:00

I am looking at a Javascript emulator of a NES to try and understand

  • 0

I am looking at a Javascript emulator of a NES to try and understand how it works.

On this line:

    addr = this.load(opaddr+2);

The opcode is incremented by two. However, the documentation (see appendix E) I’m reading says:

Zero page addressing uses a single operand which serves as a pointer
to an address in zero page ($0000-$00FF) where the data to be operated
on can be found. By using zero page addressing, only one byte is
needed for the operand, so the instruction is shorter and, therefore,
faster to execute than with addressing modes which take two operands.
An example of a zero page instruction is AND $12.

So if the operand’s argument is only one byte, shouldn’t it appear directly after it, and be + 1 instead of + 2? Why +2?

This is how I think it works, which may be incorrect. Suppose our memory looks like:

-------------------------
| 0 | 1 | 2 | 3 | 4 | 5 | <- index
-------------------------
| a | b | c | d | e | f | <- memory
-------------------------
  ^  
   \ 
     PC

and our PC is 0, pointing to a. For this cycle, we say that the opcode:

var pc= 0; //for example's sake
var opcode= memory[pc]; //a

So shouldn’t the first operand be the next slot, i.e. b?

var first_operand = memory[pc + 1]; //b
  • 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-13T10:40:52+00:00Added an answer on June 13, 2026 at 10:40 am

    Your analysis appears to be correct at first glance but since the emulator works there must be something else going on.

    The relevant code is as follows :

        var opinf = this.opdata[this.nes.mmap.load(this.REG_PC+1)];
        var cycleCount = (opinf>>24);
        var cycleAdd = 0;
    
        // Find address mode:
        var addrMode = (opinf >> 8) & 0xFF;
    
        // Increment PC by number of op bytes:
        var opaddr = this.REG_PC;
        this.REG_PC += ((opinf >> 16) & 0xFF);
    
        var addr = 0;
        switch(addrMode){
            case 0:{
                // Zero Page mode. Use the address given after the opcode, 
                // but without high byte.
                addr = this.load(opaddr+2);
                break;
    

    Note how on the first line shown, the memory access to get the instruction information is at address REG_PC+1. So the PC actually points to the byte preceding the opcode being executed and so the operands start at that address + 2. The opcode itself is encoded as the lower 8 bytes of opinf and used in the execute switch a page or so below the code segment shown.

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

Sidebar

Related Questions

I'm looking for Javascript code for letting the user draw a line (on an
I'm looking for a javascript datepicker like this one : http://code.google.com/p/mobiscroll/ but I want
I have just started looking at javascript so hopefully this will be something simple.
i looking javascript editor for php code, include tab support and php code highlight
I am looking for javascript code which will give me 1st date of the
To debug some JavaScript code, I am looking for JavaScript code (preferably just js,
I'm looking for a javascript that allow me to: 1- Create a link: [a
I'm looking for some Javascript jedi-master to assist in creating a function that adds
I was looking in the javascript reference manual on the indexOf page at developer.mozilla.org
I'm looking for a javascript diff algorithm implementation or library, which has been tested

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.