docs: update some funcs with light docs

This commit is contained in:
Bradford Lamson-Scribner 2020-05-30 11:13:35 -06:00
parent cdca8f735d
commit 2bd748fccd
2 changed files with 8 additions and 4 deletions

View File

@ -68,7 +68,7 @@ const (
flagCarry uint8 = 0B_00000001 flagCarry uint8 = 0B_00000001
) )
// StackBottom represents the bottom address // StackBottom represents the start of the stack
const StackBottom uint16 = 0x0100 // 256 const StackBottom uint16 = 0x0100 // 256
// Mos6502 TODO: docs // Mos6502 TODO: docs
@ -81,7 +81,7 @@ type Mos6502 struct {
ps uint8 // register - processor status ps uint8 // register - processor status
} }
// newCPU TODO: docs // newCPU initializes and returns a new Mos6502 CPU
func newCPU() *Mos6502 { func newCPU() *Mos6502 {
return &Mos6502{ return &Mos6502{
sp: 0xFF, sp: 0xFF,

View File

@ -36,11 +36,13 @@ func (a *Appleone) step() {
} }
} }
func (a *Appleone) pushWordToStack(data byte) { // pushWordToStack pushes the given word (byte) into memory and sets the new stack pointer
a.mem[StackBottom+uint16(a.cpu.sp)] = data func (a *Appleone) pushWordToStack(b byte) {
a.mem[StackBottom+uint16(a.cpu.sp)] = b
a.cpu.sp = uint8((uint16(a.cpu.sp) - 1) & 0xFF) a.cpu.sp = uint8((uint16(a.cpu.sp) - 1) & 0xFF)
} }
// pushWordToStack splits the high and low byte of the data passed in, and pushes them to the stack
func (a *Appleone) pushDWordToStack(data uint16) { func (a *Appleone) pushDWordToStack(data uint16) {
h := uint8((data >> 8) & 0xFF) h := uint8((data >> 8) & 0xFF)
l := uint8(data & 0xFF) l := uint8(data & 0xFF)
@ -48,11 +50,13 @@ func (a *Appleone) pushDWordToStack(data uint16) {
a.pushWordToStack(l) a.pushWordToStack(l)
} }
// popStackWord sets the new stack pointer and returns the appropriate byte in memory
func (a *Appleone) popStackWord() uint8 { func (a *Appleone) popStackWord() uint8 {
a.cpu.sp = uint8((uint16(a.cpu.sp) + 1) & 0xFF) a.cpu.sp = uint8((uint16(a.cpu.sp) + 1) & 0xFF)
return a.mem[StackBottom+uint16(a.cpu.sp)] return a.mem[StackBottom+uint16(a.cpu.sp)]
} }
// popStackDWord pops two stack words (a double word - uint16) off the stack
func (a *Appleone) popStackDWord() uint16 { func (a *Appleone) popStackDWord() uint16 {
l := a.popStackWord() l := a.popStackWord()
h := a.popStackWord() h := a.popStackWord()