github.com/jflude/taocp@v0.0.0-20240210234939-99f2a91af3c2/mix/go.go (about) 1 package mix 2 3 // GoButton starts the MIX computer, as described in Ex. 26, Section 1.3.1. 4 // The machine can be bootstrapped only from the card reader or paper tape. 5 func (c *Computer) GoButton() error { 6 if c.halted { 7 c.halted = false 8 c.next++ 9 return c.resume() 10 } 11 if c.BootFrom != CardReaderUnit && c.BootFrom != PaperTapeUnit { 12 return ErrInvalidUnit 13 } 14 for i := range c.Reg { 15 c.Reg[i] = 0 16 } 17 c.zeroContents() 18 c.unlockContents() 19 if _, err := c.in(0, 0, c.BootFrom, IN, 0); err != nil { 20 return err 21 } 22 c.unlockContents() 23 c.ctrl = c.Interrupts 24 c.Reg[J] = 0 25 c.Elapsed = 0 26 c.lastTick = 0 27 c.pending = nil 28 for i := range c.busyUntil { 29 c.busyUntil[i] = 0 30 } 31 c.next = 0 32 return c.resume() 33 } 34 35 func (c *Computer) resume() error { 36 for { 37 if err := c.Cycle(); err != nil { 38 return err 39 } 40 } 41 }