mirror of
https://github.com/JetSetIlly/Gopher2600.git
synced 2025-04-02 11:02:17 -04:00
- scripts now pass through input loop, allowing commands that control the emulation (like RUN or STEP) to be effective - reworked ONSTEP and ONHALT commands - added STICK0 and STICK1 commands o memory / pia - improved RAM debugging output
51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
package debugger
|
|
|
|
import (
|
|
"gopher2600/errors"
|
|
"io/ioutil"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
type debuggingScript struct {
|
|
scriptFile string
|
|
lines []string
|
|
nextLine int
|
|
}
|
|
|
|
func (dbg *Debugger) loadScript(scriptfile string) (*debuggingScript, error) {
|
|
// open script and defer closing
|
|
sf, err := os.Open(scriptfile)
|
|
if err != nil {
|
|
return nil, errors.NewFormattedError(errors.ScriptFileCannotOpen, err)
|
|
}
|
|
defer func() {
|
|
_ = sf.Close()
|
|
}()
|
|
|
|
buffer, err := ioutil.ReadAll(sf)
|
|
if err != nil {
|
|
return nil, errors.NewFormattedError(errors.ScriptFileError, err)
|
|
}
|
|
|
|
dbs := new(debuggingScript)
|
|
dbs.scriptFile = scriptfile
|
|
|
|
// convert buffer to an array of lines
|
|
dbs.lines = strings.Split(string(buffer), "\n")
|
|
|
|
return dbs, nil
|
|
}
|
|
|
|
// UserRead implements ui.UserInput interface
|
|
func (dbs *debuggingScript) UserRead(buffer []byte, prompt string, interruptChannel chan func()) (int, error) {
|
|
if dbs.nextLine > len(dbs.lines)-1 {
|
|
return -1, errors.NewFormattedError(errors.ScriptEnd, dbs.scriptFile)
|
|
}
|
|
|
|
l := len(dbs.lines[dbs.nextLine]) + 1
|
|
copy(buffer, []byte(dbs.lines[dbs.nextLine]))
|
|
dbs.nextLine++
|
|
|
|
return l, nil
|
|
}
|