From 2bd748fccd62ff8268d8f7e606f542f491fcb7d6 Mon Sep 17 00:00:00 2001 From: Bradford Lamson-Scribner Date: Sat, 30 May 2020 11:13:35 -0600 Subject: [PATCH] docs: update some funcs with light docs --- internal/vm/cpu.go | 4 ++-- internal/vm/vm.go | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/internal/vm/cpu.go b/internal/vm/cpu.go index affdc2e..dd03aed 100644 --- a/internal/vm/cpu.go +++ b/internal/vm/cpu.go @@ -68,7 +68,7 @@ const ( flagCarry uint8 = 0B_00000001 ) -// StackBottom represents the bottom address +// StackBottom represents the start of the stack const StackBottom uint16 = 0x0100 // 256 // Mos6502 TODO: docs @@ -81,7 +81,7 @@ type Mos6502 struct { ps uint8 // register - processor status } -// newCPU TODO: docs +// newCPU initializes and returns a new Mos6502 CPU func newCPU() *Mos6502 { return &Mos6502{ sp: 0xFF, diff --git a/internal/vm/vm.go b/internal/vm/vm.go index 8e8e404..b0fd353 100644 --- a/internal/vm/vm.go +++ b/internal/vm/vm.go @@ -36,11 +36,13 @@ func (a *Appleone) step() { } } -func (a *Appleone) pushWordToStack(data byte) { - a.mem[StackBottom+uint16(a.cpu.sp)] = data +// pushWordToStack pushes the given word (byte) into memory and sets the new stack pointer +func (a *Appleone) pushWordToStack(b byte) { + a.mem[StackBottom+uint16(a.cpu.sp)] = b 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) { h := uint8((data >> 8) & 0xFF) l := uint8(data & 0xFF) @@ -48,11 +50,13 @@ func (a *Appleone) pushDWordToStack(data uint16) { a.pushWordToStack(l) } +// popStackWord sets the new stack pointer and returns the appropriate byte in memory func (a *Appleone) popStackWord() uint8 { a.cpu.sp = uint8((uint16(a.cpu.sp) + 1) & 0xFF) 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 { l := a.popStackWord() h := a.popStackWord()