Navigation X
ALERT
Click here to register with a few steps and explore all our cool stuff we have to offer!



   2412

Help with C# implementation of ASM - SBC.

by Cups - 08 June, 2019 - 02:52 PM
This post is by a banned member (Cups) - Unhide
Cups  
Registered
103
Posts
17
Threads
#1
So I'm implementing a gameboy CPU in C# to make an emulator. And I need someone good in ASM to check an implementation I make which I have a doubt on.

The OPCODE 0x9F translates to instruction SBC (source here http://www.pastraiser.com/cpu/gameboy/ga...codes.html) so substract with carry.

I just need someone to check my implementation, like @MeSvAk cause apparently he knows ASM.

Right now I have this made :

Code:
/// <summary>
       /// Substract n + carry flag from A.
       /// </summary>
       /// <param name="r1">n</param>
       private static void sbc(byte r1)
       {
           // TODO Double check this implementation
           uint substractResult = (uint)Gameboy.Cpu.Registers.A - r1 - Convert.ToUInt32(Gameboy.Cpu.Registers.F.C);

           // Set zero flag if result is 0.
           Gameboy.Cpu.Registers.F.Z = ((byte)substractResult) == 0;

           // Set half-carry flag if no borrow from bit 4. IM UNSURE ABOUT THIS. This should mean if result is 0b0001_0000, we have a carry, but is it really how to implement it?
           Gameboy.Cpu.Registers.F.H = ((Gameboy.Cpu.Registers.A ^ r1 ^ substractResult) & 0x10) != 0;

           // Set the carry flag if no borrow at all 0b0001_0000_0000 (so more than 8 bits)
           Gameboy.Cpu.Registers.F.C = ((substractResult & 0x100) != 0);
           
           // The substract flag is set as we performed a sub op.
           Gameboy.Cpu.Registers.F.N = true;
       }
Whoever trades his freedom for his safety deserves neither.


I may have coded Axenta, vapor and some other useless shit nobody uses  Fiesta

[Image: 0e55a4ca011af062b46453a9cb4e7954.png]
[Image: 2d7b72d34b6d12c37b8a03fb828c24ee.png]



This post is by a banned member (MeSvAk) - Unhide
MeSvAk  
Registered
4.007
Posts
3.395
Threads
#2
i never tried it with c# tbh but tried it with java like 2 years ago and about 3 months ago there was a person who created a similar shit
which is this guy https://github.com/trekawek/coffee-gb/tr...ffeegb/cpu

But its written in java i can translate it to c# if u didnt get it

just give a quick brief shit so basically for writing an emulator you needa consider 1- cpu ( timing and .....) 2- memory

and dont forget you needa write diff script for each of them seemingly in this script that tbh i m a bit confused about what u written there cuase you cannot bind them without importing them

APprently this is the case you working on
}

public OpcodeBuilder proceedIf(String condition) {
ops.add(new Op() {
@override
public boolean proceed(Registers registers) {
switch (condition) {
case "NZ":
return !registers.getFlags().isZ();

case "Z":
return registers.getFlags().isZ();

case "NC":
return !registers.getFlags().isC();

case "C":
return registers.getFlags().isC();
}


And as a reminder you needa mention the the value of bit u going to use and what is z is it below z<8 bits or ......
This post is by a banned member (Cups) - Unhide
Cups  
Registered
103
Posts
17
Threads
#3
No, I understand everything about the emulator but I just need someone to check the implementation of the half carry flag
Whoever trades his freedom for his safety deserves neither.


I may have coded Axenta, vapor and some other useless shit nobody uses  Fiesta

[Image: 0e55a4ca011af062b46453a9cb4e7954.png]
[Image: 2d7b72d34b6d12c37b8a03fb828c24ee.png]




Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
or
Sign in
Already have an account? Sign in here.


Forum Jump:


Users browsing this thread: 1 Guest(s)