Exemplo n.º 1
0
// Handle events
func process(ch chan leggo.Event) {
	for {
		e := <-ch

		kind, code := e.Type, e.Keycode

		fmt.Printf("got event: %d,%d\n", kind, code)

		if kind == leggo.EVENT_KEY_DOWN {
			switch code {
			case leggo.KEY_ESCAPE:
				fmt.Printf("Exiting\n")
				os.Exit(0)
			case leggo.KEY_DOWN:
				fmt.Printf("mode = %d\n", mode)
				mode += 1
			case leggo.KEY_UP:
				fmt.Printf("mode = %d\n", mode)
				mode -= 1
			case leggo.KEY_SPACE:
				fmt.Printf("FPS = %f\n", leggo.FPS())
			}
		}
	}
}
Exemplo n.º 2
0
// Start emulation
func (deck *ControlDeck) Start() {
    if deck.ShowGui {
        leggo.LeggoMain(func() { deck.PPU.Run() },
            // Handle keystrokes from GUI
            func (ch chan leggo.Event) {
                for {
                    e := <-ch
                    pressed := e.Type == leggo.EVENT_KEY_DOWN
                    switch e.Type {
                    case leggo.EVENT_KEY_DOWN, leggo.EVENT_KEY_UP:
                        switch e.Keycode {
                        case leggo.KEY_ESCAPE, leggo.KEY_Q: os.Exit(0)
                        case leggo.KEY_F: 
                            fmt.Printf("display FPS = %f\n", leggo.FPS())
                            fmt.Printf("PPU FPS = %f\n", deck.PPU.FPS)

                        // TODO: custom controller keyboard key mapping; refactor all this
                        case leggo.KEY_ALT, leggo.KEY_ALTGR:
                            deck.IO.SetButtonState(0, io2a03.BUTTON_A, pressed)
                        case leggo.KEY_LSHIFT, leggo.KEY_RSHIFT:
                            deck.IO.SetButtonState(0, io2a03.BUTTON_B, pressed)
                        case leggo.KEY_TAB:
                            deck.IO.SetButtonState(0, io2a03.BUTTON_SELECT, pressed)
                        case leggo.KEY_ENTER:   
                            deck.IO.SetButtonState(0, io2a03.BUTTON_START, pressed)
                        case leggo.KEY_LEFT:
                            deck.IO.SetButtonState(0, io2a03.BUTTON_LEFT, pressed)
                        case leggo.KEY_RIGHT:
                            deck.IO.SetButtonState(0, io2a03.BUTTON_RIGHT, pressed)
                        case leggo.KEY_UP:
                            deck.IO.SetButtonState(0, io2a03.BUTTON_UP, pressed)
                        case leggo.KEY_DOWN:
                            deck.IO.SetButtonState(0, io2a03.BUTTON_DOWN, pressed)
                        }
                    }
                }
            })

    } else {
        deck.PPU.Run()
    }
}