def __enter__(self): self.t = termbox.Termbox() self.t.__enter__() self.x = 0 self.y = 0 self.width = min(self.t.width(), 80) self.clear() return self
def __init__(self): random.seed(a=time.perf_counter()) self._tb = termbox.Termbox() self._ticks = 0 self._max_ticks = 65535 self._score = Score(self._tb) self._pad_l = Paddle(self._tb, 'l', 9) self._pad_r = Paddle(self._tb, 'r', 9) self._ball = Ball(self._tb) self._stopped = True self._paused = True self._pause_str = 'PAUSE'
def main(): mode, args = parse_args() with termbox.Termbox() as t: torun = { 'r': random_dots, 'd': debug_draw_line, 'l': line_control, 'a': run_app, 'rl': LinesScreenSaver, 'i': image_viewer, 'I': tc_image_viewer, 'q': qube, 't': test, 'c': circle, }.get(mode, lambda x: print('unknown mode')) if isinstance(torun, type) and issubclass(torun, App): torun(t).run_loop() else: if args: torun(t, args=args) else: torun(t) pass
# viewplane is a class that behaves like termbox but is virtual. # The window exists in memory and needs to be displayed in a real # termbox to be seen. # Viewplanes are useful for scrolling windows, configurable layouts # and similar things. from termbox_util import viewplane # A virtual viewplane that can be displayed. vp=viewplane(11,5) # Get a set of utils to do things with it. vptb = termbox_util(vp) # Use a real termbox window tbinst. with termbox.Termbox() as tbinst: event = "no_event" # Put something in the virtual viewplane vptb.addstr(3,2,"Hello") vptb.border() i=0 # Get some utilities to run over the real window tb = termbox_util(tbinst) # This adds a persistent view of the virtual viewplane in the physical viewplane # With the _window version, it can be a view of only part of the viewplane # Parameters are : vp,width,height,srcx,srcy,viewx,viewy,active pid1 = tb.add_persistent_viewplane_window(vp,11,5,0,0,4,8)
h = t.height() c = i palette = [ termbox.DEFAULT, termbox.BLACK, termbox.RED, termbox.GREEN, termbox.YELLOW, termbox.BLUE, termbox.MAGENTA, termbox.CYAN, termbox.WHITE ] for x in range(w): t.change_cell(x, h - 1, ord(u' '), termbox.BLACK, palette[c]) t.change_cell(x, h - 2, ord(u' '), termbox.BLACK, palette[c]) c += 1 if c > 7: c = 0 with termbox.Termbox() as t: sb = SelectBox(t, choices, 0) t.clear() sb.draw() t.present() i = 0 run_app = True while run_app: event_here = t.poll_event() while event_here: (type, ch, key, mod, w, h, x, y) = event_here if type == termbox.EVENT_KEY and key == termbox.KEY_ESC: run_app = False if type == termbox.EVENT_KEY: if key == termbox.KEY_ARROW_DOWN: sb.move_down()
async def __aenter__(self): self.tb = termbox.Termbox() for fd in self.tb.poll_fds(): await self._group.spawn(self._watch(fd)) return self
import pygame.time import termbox from user_input.input_handler import InputHandler from Item import DamageItem from game_map.game_map import GameMap from scene_manager import SCENE_MANAGER from game_state_manager import GAME_STATE_MANAGER, GameState from fight_manager import FIGHT_MANAGER from ActionTree import ActionTree # from Inventory import Inventory # CONSTATN INITIALIZATION pygame.init() last_frame_time = 0 tb = termbox.Termbox() input_handler = InputHandler() game_map = GameMap('./game_map/game_map.csv') SCENE_MANAGER['MainMenu'](game_map) # inventory = Inventory(5, 10) # inventory.add_item(DamageItem(500)) #SCENE_MANAGER['FightScene'](inventory) current_game_state = GAME_STATE_MANAGER['CurrentState'] def update_fight(): if FIGHT_MANAGER['CurrentFight'].is_battle_over() == True: if FIGHT_MANAGER['CurrentFight'].get_player_inventory().get_health( ) > 0: FIGHT_MANAGER['CurrentFight'] = None
def dbg6502(object_code, symbol_table): memory_selected = True disassembly_selected = False observer_selected = False event = "no_event_yet" # Use a real termbox window tbinst. with termbox.Termbox() as tb: # The things we seen in the main view are composed # in virtual viewplanes which are placed within # the physical termbox view tbtu = termbox_util(tb) tbtu.clear() # Compute some positions maxx, maxy = tbtu.getmaxxy() memorywindowheight = maxy - 12 rightwidth = maxx - leftwidth # A viewplane to hold the command information vp_commands = viewplane(width=maxx + 1, height=4) vptu_commands = termbox_util(vp_commands) draw_commands_view(vptu_commands) # A viewplane to hold the register state vp_registers = viewplane(width=leftwidth, height=4) vptu_registers = termbox_util(vp_registers) draw_registers_view(vptu_registers, 0, 0, 0, 0, 0x100, 0) # A viewplane to hold the action view vp_action = viewplane(width=leftwidth, height=4) vptu_action = termbox_util(vp_action) draw_action_view(vptu_action, "Nothing Yet") # A Viewplane to hold the goto input vp_goto = viewplane(width=28, height=3) vptu_goto = termbox_util(vp_goto) draw_goto_view(vp_goto, vptu_goto, "") # A viewplane to hold the register state vp_observer = viewplane(width=maxx + 1 - leftwidth, height=8) vptu_observer = termbox_util(vp_observer) draw_observer_view(vptu_observer, observer_selected, "no_event") # Since we have a sliding memory view but want a box around the # visible window, we will have a two deep hierarchy - the outer # with the border and the inner, set inside with the scrolling # view. # A viewplane to hold the inner memory view, 8 bytes per line * 8192 = 64k vp_memory_inner = viewplane(width=leftwidth - 2, height=8192) vptu_memory_inner = termbox_util(vp_memory_inner) draw_memory_inner_view(vptu_memory_inner, object_code) # The outer to hold the border and the innner vp_memory_outer = viewplane(width=leftwidth, height=memorywindowheight) vptu_memory_outer = termbox_util(vp_memory_outer) draw_memory_outer_view(vptu_memory_outer, memory_selected) # Add the views as persistent views in the terminal view pvid_commands = tbtu.add_persistent_viewplane(vp_commands, 0, 0) pvid_registers = tbtu.add_persistent_viewplane(vp_registers, 0, 4) pvid_action = tbtu.add_persistent_viewplane(vp_action, 0, 8) pvid_observer = tbtu.add_persistent_viewplane(vp_observer, leftwidth, 4) #pvid_goto = tbtu.add_persistent_viewplane(vp_goto,10,10) # Goto window is only visible when taking goto input. Hide it. #tbtu.deactivate_persistent_vp(pvid_goto) # The memory view is a window into the viewplane since the # viewplane has the whole of memory laid out in. # Parameters are : vp,width,height,srcx,srcy,viewx,viewy,active pvid_memory_outer = tbtu.add_persistent_viewplane( vp_memory_outer, 0, 12) # Put the inner memory view in the outer memory view pvid_memory_inner = vptu_memory_outer.add_persistent_viewplane_window( vp_memory_inner, leftwidth - 2, memorywindowheight - 2, 0, 0, 1, 1, True) # The disassembly view vp_disassembly_inner = viewplane(width=maxx + 1 - leftwidth - 2, height=100) vptu_disassembly_inner = termbox_util(vp_disassembly_inner) s.pc = 0 draw_disassembly_inner_view(vptu_disassembly_inner, object_code) # The outer to hold the border and the innner vp_disassembly_outer = viewplane(width=maxx + 1 - leftwidth, height=maxy - 12) vptu_disassembly_outer = termbox_util(vp_disassembly_outer) draw_disassembly_outer_view(vptu_disassembly_outer, disassembly_selected) # The disassembly view is a window into the viewplane since the # viewplane has a lot of listing laid out in. # Parameters are : vp,width,height,srcx,srcy,viewx,viewy,active pvid_disassembly_outer = tbtu.add_persistent_viewplane( vp_disassembly_outer, leftwidth, 12) # Put the inner memory view in the outer memory view pvid_disassembly_inner = vptu_disassembly_outer.add_persistent_viewplane_window( vp_disassembly_inner, (maxx - leftwidth - 2), maxy - 14, 0, 0, 1, 1, True) # The main loop # Listen for keypresses and do what is asked # Quit when esc is pressed memaddr = 0 while True: #Refresh the screen (cpdl, dc) = draw_disassembly_inner_view(vptu_disassembly_inner, object_code) #draw_memory_inner_view(vptu_memory_inner, object_code) vptu_memory_outer.present() # Compute where to place the disassembly in memory new_srcx = 0 if cpdl > 0: new_srcy = cpdl - 10 if new_srcy < 0: new_srcy = 0 else: new_srcy = 0 vptu_disassembly_outer.move_persistent_viewplane_window( pvid_memory_inner, new_srcx, new_srcy) #vptu_disassembly_outer.addstr(20,0,"cpdl="+str(cpdl)+" len="+str(dc)+" ") vptu_disassembly_outer.present() draw_registers_view(vptu_registers, s.pc, s.a, s.x, s.y, s.sp, s.cc) draw_observer_view(vptu_observer, observer_selected, event) tbtu.present() # Get a keypress event = tb.poll_event() # untangle it's fields (type, ch, key, mod, w, h, x, y) = event ## Go to an edit box if the user presses 'e' #if type==termbox.EVENT_KEY and ch=='e': # content=el.edit(el_validator,max_width=10) #vptu_observer.addstr(1,2,str(event)) # Exit when escape pressed. if type == termbox.EVENT_KEY and key == termbox.KEY_ESC: return event if type == termbox.EVENT_KEY and key == termbox_util.key_tab: # Rotate through selecting one of the three windows if memory_selected: memory_selected = False observer_selected = True disassembly_selected = False elif observer_selected: memory_selected = False observer_selected = False disassembly_selected = True elif disassembly_selected: memory_selected = True observer_selected = False disassembly_selected = False else: memory_selected = False observer_selected = True disassembly_selected = False draw_memory_outer_view(vptu_memory_outer, memory_selected) draw_disassembly_outer_view(vptu_disassembly_outer, disassembly_selected) draw_observer_view(vptu_observer, observer_selected, event) # When r is pressed, sent a reset to the simulator elif type == termbox.EVENT_KEY and (ch == 'r' or ch == 'r'): s.reset() vptu_action.addstr(1, 1, "RESET ") draw_memory_inner_view(vptu_memory_inner, object_code) # When i is pressed, sent an irq to the simulator elif type == termbox.EVENT_KEY and (ch == 'I' or ch == 'i'): s.irq() vptu_action.addstr(1, 1, "IRQ ") draw_memory_inner_view(vptu_memory_inner, object_code) # When n is pressed, sent an NMI to the simulator elif type == termbox.EVENT_KEY and (ch == 'N' or ch == 'n'): s.reset() vptu_action.addstr(1, 1, "NMI ") draw_memory_inner_view(vptu_memory_inner, object_code) # When g is pressed, input a goto address elif type == termbox.EVENT_KEY and (ch == 'G' or ch == 'g'): #s.reset() tbtu.draw_viewplane(vp_goto, 10, 10) tb.present() #tbtu.activate_persistent_vp(pvid_goto) el = termbox_editableline(tb, tbtu, 26, 11, 5) tb.present() thetext = el.edit(hex_validator, contents="", max_width=4) #tbtu.deactivate_persistent_vp(pvid_goto) if len(thetext) > 0: thetext = "0x" + thetext addr = int(eval(thetext)) if addr < 0x10000: s.pc = addr # When s is pressed, execute one instruction elif type == termbox.EVENT_KEY and ch == 's': distxt, _ = dis.disassemble_line(s.pc) (action, addr) = s.execute() vptu_action.addstr(1, 1, distxt.ljust(leftwidth - 2)) draw_registers_view(vptu_registers, s.pc, s.a, s.x, s.y, s.sp, s.cc) draw_disassembly_inner_view(vptu_disassembly_inner, object_code) # simulator indicated it tried to run uninitialized memory if action == "weeds": vptu_action.addstr( 1, 2, "In unitialized mem ".ljust(leftwidth - 2)) # Memory changed so update that part of the memory view # Back up a bit in case we are in a multi byte stack op elif action == "w": startline = addr / 8 startline -= 1 endline = startline + 2 vptu_action.addstr( 1, 2, ("modified %04x=%02x " % (addr, object_code[addr])).ljust(leftwidth - 2)) draw_memory_inner_view_partial(vptu_memory_inner, startline, endline, object_code) vptu_memory_outer.present() elif action == "stack": startline = 0x100 endline = 0x200 vptu_action.addstr(1, 2, "modified stack ".ljust(leftwidth - 2)) draw_memory_inner_view_partial(vptu_memory_inner, startline, endline, object_code) vptu_memory_outer.present() elif action == "not_instruction": vptu_action.addstr( 1, 2, "Not an instruction ".ljust(leftwidth - 2)) else: vptu_action.addstr(1, 2, " ".ljust(leftwidth - 2)) # Move memory window with the mouse wheel elif type == termbox.EVENT_KEY and key == termbox_util.TB_KEY_ARROW_UP: #elif type==termbox.EVENT_KEY and ch=='i': memaddr -= 8 if memaddr < 0: memaddr = 0 new_srcy = memaddr / 8 new_srcx = 0 vptu_memory_outer.move_persistent_viewplane_window( pvid_memory_inner, new_srcx, new_srcy) # Move memory window with the mouse wheel #elif type==termbox.EVENT_KEY and key==termbox_util.TB_KEY_ARROW_UP: elif type == termbox.EVENT_KEY and ch == 'o': memaddr -= 8 * 32 if memaddr < 0: memaddr = 0 new_srcy = memaddr / 8 new_srcx = 0 vptu_memory_outer.move_persistent_viewplane_window( pvid_memory_inner, new_srcx, new_srcy) elif type == termbox.EVENT_KEY and key == termbox_util.TB_KEY_ARROW_DOWN: #elif type==termbox.EVENT_KEY and ch=='k': memaddr += 8 line = memaddr / 8 if (line + memorywindowheight - 2) < 8192: memaddr = memaddr % 65536 new_srcy = line new_srcx = 0 vptu_memory_outer.move_persistent_viewplane_window( pvid_memory_inner, new_srcx, new_srcy) #elif type==termbox.EVENT_KEY and key==termbox_util.TB_KEY_MOUSE_WHEEL_DOWN: elif type == termbox.EVENT_KEY and ch == 'l': memaddr += 8 * 32 line = memaddr / 8 if (line + memorywindowheight - 2) < 8192: memaddr = memaddr % 65536 new_srcy = line new_srcx = 0 vptu_memory_outer.move_persistent_viewplane_window( pvid_memory_inner, new_srcx, new_srcy)