Skip to content

Commit

Permalink
yar
Browse files Browse the repository at this point in the history
  • Loading branch information
xubiod committed Feb 27, 2024
1 parent e6a4c20 commit 8ed005f
Showing 7 changed files with 56 additions and 0 deletions.
12 changes: 12 additions & 0 deletions cpu/set_arithmetic.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package cpu

// The implementation of the add with carry.
//
// This will change flags in the Core it's run in.
func (c *Core) adc_impl(middle byte) {
if c.Features.DecimalModeImplemented && c.Flags&FLAG_DECIMAL > 0 {
c.adc_impl_decimal(middle)
@@ -39,6 +42,9 @@ func (c *Core) adc_impl(middle byte) {
}
}

// The implementation of the add with carry using BCD.
//
// This will change flags in the Core it's run in.
func (c *Core) adc_impl_decimal(middle byte) {
var u1 = uint16(c.A)
var u2 = uint16(middle)
@@ -92,6 +98,9 @@ func (c *Core) adc_impl_decimal(middle byte) {
}
}

// The implementation of the subtract with borrow.
//
// This will change flags in the Core it's run in.
func (c *Core) sbc_impl(middle byte) {
if c.Features.DecimalModeImplemented && c.Flags&FLAG_DECIMAL > 0 {
c.sbc_impl_decimal(middle)
@@ -133,6 +142,9 @@ func (c *Core) sbc_impl(middle byte) {
}
}

// The implementation of the subtract with borrow using BCD.
//
// This will change flags in the Core it's run in.
func (c *Core) sbc_impl_decimal(middle byte) {
var u1 = uint16(c.A)
var u2 = uint16(middle)
4 changes: 4 additions & 0 deletions cpu/set_branch.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package cpu

// Takes a unsigned 8 bit integer and mangles it into a signed 8 bit integer.
//
// The result is converted into a unsigned short to add to the program counter
// by the caller.
func branchVal(i uint8) (o uint16) {
m := int8(i & 0x7F)
if i&0b10000000 > 0 {
7 changes: 7 additions & 0 deletions cpu/set_comparetest.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package cpu

// This is the implementation of what the `CMP`, `CPX`, and `CPY` instructions
// do.
//
// This will change the flags in the Core it's run in.
func (c *Core) cmp_impl(what, with byte) {
if what == with {
c.Flags = c.Flags & ^FLAG_NEGATIVE
@@ -16,6 +20,9 @@ func (c *Core) cmp_impl(what, with byte) {
}
}

// This is the implementation of what the `BIT` instruction does.
//
// This will change the flags in the Core it's run in.
func (c *Core) bit_impl(with byte) {
var r = c.A & with

8 changes: 8 additions & 0 deletions cpu/set_incdec.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package cpu

// The implementation of the increment instructions.
//
// This will change the flags of the of the Core it's run in, and will change the
// value at the pointer passed into it.
func (c *Core) inc_impl(where *byte) {
*where++

@@ -18,6 +22,10 @@ func (c *Core) inc_impl(where *byte) {
}
}

// The implementation of the decrement instructions.
//
// This will change the flags of the of the Core it's run in, and will change the
// value at the pointer passed into it.
func (c *Core) dec_impl(where *byte) {
*where--

4 changes: 4 additions & 0 deletions cpu/set_load.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package cpu

// This is the implementation of the load instructions.
//
// This will change the flags of the Core it's run in, and will change the value
// at the pointer passed into it.
func (c *Core) ld_impl(to *byte, store byte) {
*to = store

9 changes: 9 additions & 0 deletions cpu/set_logic.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package cpu

// This is the implementation of the AND instructions.
//
// This will change the flags of the Core it's run in.
func (c *Core) and_impl(with byte) {
c.A = c.A & with

@@ -16,6 +19,9 @@ func (c *Core) and_impl(with byte) {
}
}

// This is the implementation of the ORA instructions.
//
// This will change the flags of the Core it's run in.
func (c *Core) ora_impl(with byte) {
c.A = c.A | with

@@ -32,6 +38,9 @@ func (c *Core) ora_impl(with byte) {
}
}

// This is the implementation of the EOR instructions.
//
// This will change the flags of the Core it's run in.
func (c *Core) eor_impl(with byte) {
c.A = c.A ^ with

12 changes: 12 additions & 0 deletions cpu/set_shiftrot.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package cpu

// This is the implementation of the ASL instructions.
//
// This will change the flags of the Core it's run in.
func (c *Core) asl_impl(loc *byte) {
var shouldCarry = *loc & 0x80

@@ -24,6 +27,9 @@ func (c *Core) asl_impl(loc *byte) {
}
}

// This is the implementation of the LSR instructions.
//
// This will change the flags of the Core it's run in.
func (c *Core) lsr_impl(loc *byte) {
var shouldCarry = *loc & 0x01

@@ -48,6 +54,9 @@ func (c *Core) lsr_impl(loc *byte) {
}
}

// This is the implementation of the ROL instructions.
//
// This will change the flags of the Core it's run in.
func (c *Core) rol_impl(loc *byte) {
var futureCarry = *loc & 0b10000000

@@ -72,6 +81,9 @@ func (c *Core) rol_impl(loc *byte) {
}
}

// This is the implementation of the ROR instructions.
//
// This will change the flags of the Core it's run in.
func (c *Core) ror_impl(loc *byte) {
var futureCarry = *loc & 0b00000001

0 comments on commit 8ed005f

Please sign in to comment.