<commit_before>// Copyright 2011-2012 <NAME>. See licence.txt distributed with this file.

package org.javatari.atari.network;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.javatari.atari.cartridge.Cartridge;
import org.javatari.atari.console.Console;
import org.javatari.atari.console.savestate.ConsoleState;
import org.javatari.atari.console.savestate.SaveStateMedia;
import org.javatari.atari.controls.ConsoleControlsSocket;
import org.javatari.atari.controls.ConsoleControls.Control;
import org.javatari.general.board.ClockDriven;


public final class ClientConsole extends Console implements ClockDriven {

	public ClientConsole(RemoteReceiver receiver) {
		super();
		setupReceiver(receiver);
	}

	public RemoteReceiver remoteReceiver() {
		return remoteReceiver;
	}

	@Override
	public synchronized void go() {
		// Clock is controlled remotely, but signal unpause to unblock clock pulses
		isPaused = false;
	}
	
	@Override
	public synchronized void pause() {
		// Clock is controlled remotely, but signal pause to block clock pulses
		isPaused = true;
	}
	
	@Override
	public void extendedPowerOff() {
		try {
			remoteReceiver.disconnect();
		} catch (IOException e) {
			// Ignore
		}
		super.extendedPowerOff();
	}
	
	@Override
	protected void mainClockCreate() {
		// Ignore, the clock is controlled remotely
	}

	@Override
	protected void mainClockAdjustToNormal() {
		// Ignore, the clock is controlled remotely
	}

	@Override
	protected void mainClockAdjustToFast() {
		// Ignore, the clock is controlled remotely
	}

	@Override
	protected void mainClockDestroy() {
		// Ignore, the clock is controlled remotely
	}

	@Override
	protected void socketsCreate() {
		controlsSocket = new ClientConsoleControlsSocketAdapter();
		controlsSocket.addForwardedInput(new ConsoleControlsInputAdapter());
		controlsSocket.addForwardedInput(tia);
		controlsSocket.addForwardedInput(pia);
		cartridgeSocket = new ClientConsoleCartridgeSocketAdapter();
		saveStateSocket = new ClientConsoleSaveStateSocketAdapter();
	}

	@Override
	public void clockPulse() {
		// Block clock pulses until Console is unpaused (go) or turned off	TODO Verify
		while(isPaused && powerOn) try {
			Thread.sleep(1000/60);
		} catch (InterruptedException e) {}

		synchronized(this) {
			tia.clockPulse();
		}
	}

	@Override
	protected void cycleCartridgeFormat() {
		// Ignore, the new Cartridge state will come from the Server
	}

	@Override
	protected void powerFry() {
		// Ignore, the new RAM state will come from the Server
	}

	void connected() {
		showOSD("Connected to Player 1 Server", true);
	}<commit_msg>Version 3.40 in progress<commit_after>// Copyright 2011-2012 <NAME>. See licence.txt distributed with this file.

package org.javatari.atari.network;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.javatari.atari.cartridge.Cartridge;
import org.javatari.atari.console.Console;
import org.javatari.atari.console.savestate.ConsoleState;
import org.javatari.atari.console.savestate.SaveStateMedia;
import org.javatari.atari.controls.ConsoleControlsSocket;
import org.javatari.atari.controls.ConsoleControls.Control;
import org.javatari.general.board.ClockDriven;


public final class ClientConsole extends Console implements ClockDriven {

	public ClientConsole(RemoteReceiver receiver) {
		super();
		setupReceiver(receiver);
	}

	public RemoteReceiver remoteReceiver() {
		return remoteReceiver;
	}

	@Override
	public synchronized void go() {
		// Clock is controlled remotely, but signal unpause to unblock clock pulses
		isPaused = false;
	}
	
	@Override
	public synchronized void pause() {
		// Clock is controlled remotely, but signal pause to block clock pulses
		isPaused = true;
	}
	
	@Override
	public void extendedPowerOff() {
		try {
			remoteReceiver.disconnect();
		} catch (IOException e) {
			// Ignore
		}
		super.extendedPowerOff();
	}
	
	@Override
	protected void mainClockCreate() {
		// Ignore, the clock is controlled remotely
	}

	@Override
	protected void mainClockAdjustToNormal() {
		// Ignore, the clock is controlled remotely
	}

	@Override
	protected void mainClockAdjustToFast() {
		// Ignore, the clock is controlled remotely
	}

	@Override
	protected void mainClockDestroy() {
		// Ignore, the clock is controlled remotely
	}

	@Override
	protected void socketsCreate() {
		controlsSocket = new ClientConsoleControlsSocketAdapter();
		controlsSocket.addForwardedInput(new ConsoleControlsInputAdapter());
		controlsSocket.addForwardedInput(tia);
		controlsSocket.addForwardedInput(pia);
		cartridgeSocket = new ClientConsoleCartridgeSocketAdapter();
		saveStateSocket = new ClientConsoleSaveStateSocketAdapter();
	}

	@Override
	public void clockPulse() {
		// Block clock pulses until Console is unpaused (go) is turned off
		// Important while Screen is dettached in Applet mode,
		// so no indeterministic behavior is introduced while the Screen is off!
		while(isPaused && powerOn) try {
			Thread.sleep(1000/120);		// Half a frame
		} catch (InterruptedException e) {}

		synchronized(this) {
			tia.clockPulse();
		}
	}

	@Override
	protected void cycleCartridgeFormat() {
		// Ignore, the new Cartridge state will come from the Server
	}

	@Override
	protected void powerFry() {
		// Ignore, the new RAM state will come from the Server
	}

	void connected() {
		showOSD("Connected to Player 1 Server", true);
	}
{'fraction_non_alphanumeric': 0.09027904431880357, 'fraction_numerical': 0.006200984862301659, 'mean_word_length': 4.500501504513541, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5626302', 'n_tokens_mistral': 1790, 'n_tokens_neox': 1599, 'n_words': 459}