
    gS                     6    d dl  ddlZddlmZ  G d d      Zy)   )*    N)	Stopwatchc                   h    e Zd Zg dZdddgfdedefdZd Zd Zd Z	d	 Z
defd
Zd ZddZddZy)Core)@)   r   r   )r   =      )r         )D   r      )   r   ^   )   r   (   )      r   )      r   )\   /   r   )   E   r   )   J   r   )r   G   .   )r   A   f   )r   r   r   r   r   r   r!   )r   r   r   )r   w      )!   U   r#   )   7      )   r      )r#   )   P   )r#   "   r   )   2   r   )   b   r   )5   r   r   )r      r   )r      r%   )r         )r$   r$   r$   	   r8   r8   r7   r#   r#   r#   )      r#   )i      r#   )   r   r#   )r#   r      )r#   a      )r#      3   )r#      r   )r(          )         )+      r2   )   rK      )r      r#   )r   r   r      rP   rP   rO   r9   )r
      r#   )      r#   )      r)   )r#         )r#   rU   rR   )r#      r   )r#      r
   )r#      rD   )r;         )r
         )r=      rT   )r5   r#   rQ   )   r`   r`      rb   rb   ra   Ncartcontrollersc                    d | _         t               | _        t        d      D cg c]  }d c}| _        d| _        d| _        t        d      5 }t        j                  |      | _
        d d d        d| j                  j                         v r| j                  d   }|t        u rut        |d      5 }|j                         }d d d        g | _        t        dt        |      d      D ]/  }| j                  j!                  ||   ||dz      ||d	z      f       1 n|| _        nt"        j$                  | _        d | _        d d g| _        t+        | j                        | _        t.        j1                  | j,                        | _        | j.                  | j.                  j,                  _        t3        | j.                        | _        t6        j9                  | j4                        | _        |d   | j;                  |d          |d   | j;                  |d   d
       || j=                  |       y y c c}w # 1 sw Y   xY w# 1 sw Y   xY w)Nc                       y N rh       #d:\Programming\nes 3\engine\core.py<lambda>zCore.__init__.<locals>.<lambda>   s    Tri   @   r   r   zconfig.jsonpalleterb      player)	interruptr   	stopwatchrangefps_listfps_ptrfpsopenjsonloadconfigkeysstrreadpalettelenappendr   DEFAULT_PALETTErc   rd   FrameframeppuPPUBusbuscpuCPUattach_controllerattach_cart)selfrc   rd   ifpals         rj   __init__zCore.__init__   s   !DN[DN %b	*1Q*DMDLDH	m	 !IIaLdk! DKK$$&&KK	"c	#t_ 	#	q#c(A&A
,,

s1vs1Q3xQqS:
; ' ))dlDId|Dt||$DJwwtzz"DHDHHNN488}DHwwtxx DH1~!
[^,1~!
[^A6
t G +! !	 	s   	H1H61I6I Ic                 P    | j                   j                  | j                         y N)frame_interrupt)r   reset_and_runcore_interruptr   s    rj   runzCore.runG   s    HH4+>+>?ri   c                 P    | j                   j                  | j                         y r   )r   r   r   r   s    rj   run_without_resetzCore.run_without_resetJ   s    HHLL!4!4L5ri   c                     | j                   j                          | j                  j                          | j                  j                          y rg   )r   resetr   r   r   s    rj   r   z
Core.resetM   s,    HHNNHHNNHHNNri   c                    | j                   j                  | j                  d       | j                          | j                  j                         | j                  | j                  <   | j                  dz   dz  | _        dt        | j                        z  | _	        | j                   j                  | j                         y )NT)	new_framer   ?   rl   )r   renderr   rs   rt   laprv   rw   sumrx   updater   s    rj   r   zCore.core_interruptR   s    JJdhh$/NN"&.."4"4"6DMM$,,<<!#b(DLC&&DHJJdhhri   c                 H    || _         | j                  j                  |       y rg   )rc   r   r   )r   rc   s     rj   r   zCore.attach_cartZ   s    DIHHri   c                 F    d | _         | j                  j                          y rg   )rc   r   detach_cartr   s    rj   r   zCore.detach_cart^   s    DIHHri   c                 \    || j                   |<   | j                  j                  ||       y Nrq   )rd   r   r   )r   
controllerrr   s      rj   r   zCore.attach_controllerb   s)    )DVHHz&9ri   c                 Z    d | j                   |<   | j                  j                  |       y r   )rd   r   detach_controller)r   rr   s     rj   r   zCore.detach_controllerf   s'    #DVHHf-ri   )r   )__name__
__module____qualname__r   Cart
Controllerr   r   r   r   r   r   r   r   r   rh   ri   rj   r   r      sX    /& #'4, )4 )Z )V@6
 d :.ri   r   ) rz   engine.stopwatchr   r   rh   ri   rj   <module>r      s      &a. a.ri   