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 6380537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:16:49+00:00 2026-05-25T02:16:49+00:00

On Gameboy Z80, exactly how does the LD HL,(SP+e) operation affect H and C

  • 0

On Gameboy Z80, exactly how does the LD HL,(SP+e) operation affect H and C flags? (Half-carry + carry)

Reference: http://www.devrs.com/gb/files/opcodes.html

  • 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-05-25T02:16:50+00:00Added an answer on May 25, 2026 at 2:16 am

    I realise this is an old question but I had a similar problem a while ago and would just like to add my solution as there is absolutely no documentation or open-source emulator that does it correctly to my knowledge. Took me some actual debugging on a real gameboy to find the solution.

    For both 16bit SP + s8 (signed immediate) operations:

    the carry flag is set if there’s an overflow from the 7th to 8th bit.

    the half carry flag is set if there’s an overflow from the 3rd into the 4th bit.

    I found it easier to do the behaviour separately for both a positive and negative signed immediate (Lua):

    local D8 = self:Read(self.PC+1)
    local S8 = ((D8&127)-(D8&128))
    local SP = self.SP + S8 
    
    if S8 >= 0 then
        self.Cf = ( (self.SP & 0xFF) + ( S8 ) ) > 0xFF
        self.Hf = ( (self.SP & 0xF) + ( S8 & 0xF ) ) > 0xF
    else
        self.Cf = (SP & 0xFF) <= (self.SP & 0xFF)
        self.Hf = (SP & 0xF) <= (self.SP & 0xF)
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The Game Boy Z80 CPU has a half-carry flag, and I can't seem to
Does anyone have a reference or source about how GameBoy Color roms are laid
I want to create a Gameboy emulator which runs directly from the exe file,
I am writing a game for gameboy advance and I am implementing basic AI
I'm writing a gameboy emulator, and am struggling with making sure opcodes are emulated
I'm currently developing an emulator for the good old GameBoy and I'm facing some
I am working on a gameboy project for a class asignment. I was told,
Is there a way to program for gameboy?
In assembly, when they say immediate data is that signed or unsigned?? I'm writing
So I've got a SQL query I'd like to duplicate in rails: select g.*

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.