<commit_before>//
//  16bitDetokeniser.cpp
//  Phantasma
//
//  Created by <NAME> on 15/12/2013.
//  Copyright (c) 2013 <NAME>. All rights reserved.
//

#include "16bitDetokeniser.h"
#include <sstream>

shared_ptr<string> detokenise16bitCondition(vector <uint8_t> &tokenisedCondition)
{
	stringstream detokenisedStream;
	vector<uint8_t>::size_type bytePointer = 0;
	vector<uint8_t>::size_type sizeOfTokenisedContent = tokenisedCondition.size();

	while(bytePointer < sizeOfTokenisedContent-1)
	{
		// byte 1 = number of arguments, byte 2 = opcode
		uint8_t numberOfArguments	= tokenisedCondition[bytePointer];
		uint8_t opcode				= tokenisedCondition[bytePointer+1];
		bytePointer += 2;

		// make sure we have enough buffer left to read all the arguments
		if(bytePointer + numberOfArguments*2 > sizeOfTokenisedContent) break;

		// write out the operation
		switch(opcode)
		{
			case 0x01:	detokenisedStream << "ACTIVATED? ";		break;
			case 0x02:	detokenisedStream << "COLLIDED? ";		break;
			case 0x03:	detokenisedStream << "SHOT? ";			break;
			case 0x04:	detokenisedStream << "TIMER? ";			break;

			case 0x10:	detokenisedStream << "SETVAR ";			break;
			case 0x11:	detokenisedStream << "ADDVAR ";			break;
			case 0x12:	detokenisedStream << "SUBVAR ";			break;

			case 0x16:	detokenisedStream << "VAR=? ";			break;
			case 0x17:	detokenisedStream << "VAR>? ";			break;
			case 0x18:	detokenisedStream << "VAR<? ";			break;

			case 0x30:	detokenisedStream << "INVIS ";			break;
			case 0x31:	detokenisedStream << "VIS ";			break;
			case 0x32:	detokenisedStream << "TOGVIS ";			break;
			case 0x33:	detokenisedStream << "DESTROY ";		break;

			case 0x34:	detokenisedStream << "INVIS? ";			break;
			case 0x35:	detokenisedStream << "VIS? ";			break;
			
			case 0x36:	detokenisedStream << "MOVE ";			break;
			case 0x3a:	detokenisedStream << "MOVETO ";			break;

			case 0x40:	detokenisedStream << "IF ";				break;
			case 0x41:	detokenisedStream << "THEN ";			break;
			case 0x42:	detokenisedStream << "ELSE ";			break;
			case 0x43:	detokenisedStream << "ENDIF ";			break;
			case 0x44:	detokenisedStream << "AND ";			break;
			case 0x45:	detokenisedStream << "OR ";				break;

			case 0x50:	detokenisedStream << "STARTANIM ";		break;
			case 0x51:	detokenisedStream << "STOPANIM ";		break;

			case 0x52:	detokenisedStream << "START ";			break;
			case 0x53:	detokenisedStream << "RESTART ";		break;

			case 0x54:	detokenisedStream << "INCLUDE ";		break;

			case 0x55:	detokenisedStream << "WAITTRIG ";		break;
			case 0x56:	detokenisedStream << "TRIGANIM ";		break;

			case 0x60:	detokenisedStream << "LOOP ";			break;
			case 0x61:	detokenisedStream << "AGAIN ";			break;

			case 0x70:	detokenisedStream << "SOUND ";			break;
			case 0x71:	detokenisedStream << "SYNCSND ";		break;

			case 0x80:	detokenisedStream << "WAIT ";			break;
			case 0x81:	detokenisedStream << "DELAY ";			break;

			case 0x82:	detokenisedStream << "UPDATEI ";		break;
			case 0x83:	detokenisedStream << "PRINT ";			break;
			case 0x84:	detokenisedStream << "REDRAW ";			break;

			case 0x85:	detokenisedStream << "MODE ";			break;
			case 0x86:	detokenisedStream << "ENDGAME ";		break;

			case 0x87:	detokenisedStream << "EXECUTE ";		break;
			case 0x90:	detokenisedStream << "GOTO ";			break;

			case 0xff:	detokenisedStream << "END ";			break;

			default:
				detokenisedStream << "<UNKNOWN: " << std::hex << (int)opcode << "> " << std::dec;
			break;
		}

		// PRINT is a special case, requiring us to grab a string,
		// but everything else is uniform
		if(numberOfArguments)
		{
			// arguments are enclosed in brackets<commit_msg>Checked the manual and added a list of those symbols I’ve yet to determine the tokens for.<commit_after>//
//  16bitDetokeniser.cpp
//  Phantasma
//
//  Created by <NAME> on 15/12/2013.
//  Copyright (c) 2013 <NAME>. All rights reserved.
//

#include "16bitDetokeniser.h"
#include <sstream>

shared_ptr<string> detokenise16bitCondition(vector <uint8_t> &tokenisedCondition)
{
	stringstream detokenisedStream;
	vector<uint8_t>::size_type bytePointer = 0;
	vector<uint8_t>::size_type sizeOfTokenisedContent = tokenisedCondition.size();

	while(bytePointer < sizeOfTokenisedContent-1)
	{
		// byte 1 = number of arguments, byte 2 = opcode
		uint8_t numberOfArguments	= tokenisedCondition[bytePointer];
		uint8_t opcode				= tokenisedCondition[bytePointer+1];
		bytePointer += 2;

		// make sure we have enough buffer left to read all the arguments
		if(bytePointer + numberOfArguments*2 > sizeOfTokenisedContent) break;

		// write out the operation
		switch(opcode)
		{
			case 0x01:	detokenisedStream << "ACTIVATED? ";		break;
			case 0x02:	detokenisedStream << "COLLIDED? ";		break;
			case 0x03:	detokenisedStream << "SHOT? ";			break;
			case 0x04:	detokenisedStream << "TIMER? ";			break;

			case 0x10:	detokenisedStream << "SETVAR ";			break;
			case 0x11:	detokenisedStream << "ADDVAR ";			break;
			case 0x12:	detokenisedStream << "SUBVAR ";			break;

			case 0x16:	detokenisedStream << "VAR=? ";			break;
			case 0x17:	detokenisedStream << "VAR>? ";			break;
			case 0x18:	detokenisedStream << "VAR<? ";			break;

			case 0x30:	detokenisedStream << "INVIS ";			break;
			case 0x31:	detokenisedStream << "VIS ";			break;
			case 0x32:	detokenisedStream << "TOGVIS ";			break;
			case 0x33:	detokenisedStream << "DESTROY ";		break;

			case 0x34:	detokenisedStream << "INVIS? ";			break;
			case 0x35:	detokenisedStream << "VIS? ";			break;
			
			case 0x36:	detokenisedStream << "MOVE ";			break;
			case 0x3a:	detokenisedStream << "MOVETO ";			break;

			case 0x40:	detokenisedStream << "IF ";				break;
			case 0x41:	detokenisedStream << "THEN ";			break;
			case 0x42:	detokenisedStream << "ELSE ";			break;
			case 0x43:	detokenisedStream << "ENDIF ";			break;
			case 0x44:	detokenisedStream << "AND ";			break;
			case 0x45:	detokenisedStream << "OR ";				break;

			case 0x50:	detokenisedStream << "STARTANIM ";		break;
			case 0x51:	detokenisedStream << "STOPANIM ";		break;

			case 0x52:	detokenisedStream << "START ";			break;
			case 0x53:	detokenisedStream << "RESTART ";		break;

			case 0x54:	detokenisedStream << "INCLUDE ";		break;

			case 0x55:	detokenisedStream << "WAITTRIG ";		break;
			case 0x56:	detokenisedStream << "TRIGANIM ";		break;

			case 0x60:	detokenisedStream << "LOOP ";			break;
			case 0x61:	detokenisedStream << "AGAIN ";			break;

			case 0x70:	detokenisedStream << "SOUND ";			break;
			case 0x71:	detokenisedStream << "SYNCSND ";		break;

			case 0x80:	detokenisedStream << "WAIT ";			break;
			case 0x81:	detokenisedStream << "DELAY ";			break;

			case 0x82:	detokenisedStream << "UPDATEI ";		break;
			case 0x83:	detokenisedStream << "PRINT ";			break;
			case 0x84:	detokenisedStream << "REDRAW ";			break;

			case 0x85:	detokenisedStream << "MODE ";			break;
			case 0x86:	detokenisedStream << "ENDGAME ";		break;

			case 0x87:	detokenisedStream << "EXECUTE ";		break;
			case 0x90:	detokenisedStream << "GOTO ";			break;

			case 0xff:	detokenisedStream << "END ";			break;

			/*
				As yet undecoded:
				
					ANDV
					DESTOYED? (likely to be 0x37?)
					NOTV
					ORV
					GETXPOS, GETYPOS, GETZPOS
					REMOVE
					
			*/

			default:
				detokenisedStream << "<UNKNOWN: " << std::hex << (int)opcode << "> " << std::dec;
			break;
		}

		// PRINT is a special case, requiring us to grab a string,
		// but everything else is uniform
		if(numberOfArguments)
		{
			// arguments are enclosed in brackets
{'fraction_non_alphanumeric': 0.12444977991196479, 'fraction_numerical': 0.04361744697879152, 'mean_word_length': 3.563603164942179, 'pattern_counts': {'":': 0, '<': 223, '<?xml version=': 0, '>': 23, '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': '5183404', 'n_tokens_mistral': 3352, 'n_tokens_neox': 2742, 'n_words': 678}