﻿#include "../inc/Memory.h"

DWord	g_codeSpace[CODE_SIZE];
SDWord	g_dataSpace[DATA_SIZE];
Registers reg;

void throwMemoryException(DWord i, DWord j) {
	printError("**** ERROR code: 0x%08lx with arg. 0x%08lx at PC=0x%08lx ****\r\n", i, j, getPC());
	saveMemory(FILE_DATA_OUT, &g_dataSpace, sizeof(g_dataSpace));
	saveMemory(FILE_REG_OUT, &reg, sizeof(reg));
	exit(-1);
}

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wtype-limits"
bool isCodeAddressInRange(Address addr) {
	if (addr < CODE_BASE && addr > CODE_TOP)
		return false;
	return true;
}

bool isDataAddressInRange(Address addr) {
	if (addr < DATA_BASE && addr > DATA_TOP)
		return false;
	return true;
}
#pragma GCC diagnostic pop

DWord loadCodeWord(Address addr) {
	if (!isCodeAddressInRange(addr))
		throwMemoryException(OUT_OF_CODE_MEMORY_SPACE_ERROR, addr);
	addr -= CODE_BASE;
	return g_codeSpace[addr / 4];
}

SDWord loadDataWord(Address addr) {
	if (!isDataAddressInRange(addr))
		throwMemoryException(OUT_OF_DATA_MEMORY_SPACE_ERROR, addr);
	addr -= DATA_BASE;
	return g_dataSpace[addr / 4];
}

void storeDataWord(Address addr, SDWord val) {
	if (!isDataAddressInRange(addr))
		throwMemoryException(OUT_OF_DATA_MEMORY_SPACE_ERROR, addr);
	addr -= DATA_BASE;
	g_dataSpace[addr / 4] = val;
}

Address getPC() {
	return reg.PC;
}

void setPC(Address addr) {
	reg.PC = addr;
}

void incPC() {
	if (reg.PC == CODE_TOP)
		throwMemoryException(INSTRUCTION_POINTER_OVERFLOW, reg.PC);
	reg.PC += 4;
}

SDWord getRegister(Byte n) {
	if (n == 0)			// x0 is always set to 0
		return (SDWord)0;
	if (n > REGISTERS_NO)
		throwMemoryException(INVALID_REGISTER_GET, n);
	return reg.rX[n];
}

void setRegister(Byte n, SDWord value) {
	if (n == 0)			// x0 cannot be changed
		return;
	if (n > REGISTERS_NO)
		throwMemoryException(INVALID_REGISTER_SET, n);
	reg.rX[n] = value;
}

Byte getRS1() {
	return (loadCodeWord(getPC()) & 0x000F8000) >> 15;
}

Byte getRS2() {
	return (loadCodeWord(getPC()) & 0x01F00000) >> 20;
}

Byte getRD() {
	return (loadCodeWord(getPC()) & 0x00000F80) >> 7;
}

DWord ord(uint8_t from, uint8_t length, uint8_t to) {
	if (length < 1)
		length = 1;
	return ((loadCodeWord(getPC()) >> from) & ((1 << length) - 1)) << to;
}

DWord ordSign(uint8_t from, uint8_t length, uint8_t to) {
	if (length < 1)
		length = 1;
	return ( ((loadCodeWord(getPC()) >> from)	&	((1 << (length - 1)) - 1))	<< to) \
		 - ( ((loadCodeWord(getPC()) >> from) 	&	 (1 << (length - 1))	)	<< to);
}

Byte getOpCode(DWord comm) {
	return comm & 0x0000007F;
}

Byte getFunct3(DWord comm) {
	return (comm & 0x00007000) >> 12;
}

Byte getFunct7(DWord comm) {
	return (comm & 0xFE000000) >> 25;
}Practice Coding with the exercise "Timer for Clash of Code"
You have to implement a version of the timer in Clash of Code. The timer changes based on players joining.
The timer starts at 5:00 and runs towards 0:00.
where t is current time in seconds and p is the number of players in the room.
* If the result is under 0:00, set it to 0:00.
instead of starting the game.
When the timer starts there is one player (the one who started the clash).
Output the time stamp at which the game starts in the format m:ss.
If no one joined, output 'NO GAME'.
The time stamps in the input are always in the right order (no invalid inputs).What is Gout?
Gout occurs when crystals of uric acid, a normal component of blood serum, precipitates on the articular cartilage of joints, on tendons, and in the surrounding tissues. It is characterized by sudden, unexpected, burning pain, as well as swelling, redness, warmth, and stiffness in the affected joint.
What do patients take to treat Gout and its symptoms?
Commonly prescribed and frequently used treatments
These charts show data from Gout patients' latest treatment evaluations
Who has Gout at PatientsLikeMe?
- 156 patients have this condition
- 11 New patients joined this month
- 37 say Gout is their primary condition
These charts show data from Gout patients who have completed their condition historyHey Ladies, once again, it’s time for the Ruth Beals Cup Regatta, our only all-women at the helm race. Oh yeah, you can have guys on the boat if you want.
So leave Saturday, October 10th, open for this big event and start planning. The first gun will sound at 9:30 am, and we will use PHRF scoring. This is a long-distance race, like last year, on Lake Pleasant.
Brooke Miller, on her Santana 20 – Magnum, will be the defending champion. This race has been a growing event, so we are looking for a great turn out this year. We owe it to Ruth Beals, she was and is the heart and soul of this yacht club. We would not be here if it wasn’t for her vision and all the great volunteers this club has.
I’m looking forward to seeing you all out there! If you have any questions, please contact me.
I don't think there will be a "rework", just because I don't see it as necessary. If you look at how Microsoft has been simplifying (arguable) Windows 10 and "Xbox" as platforms, I think it will be more of a plug and play situation, with lower end hardware looking like what we saw in the presentation. At the same time, what do I know from the outside of development? Thanks for the source. 

Side note, I don't think we will see the situation that played out with Black Ops 3 on the 360, if that's what people fear. I believe the Xbone OG is capable of running Infinite, just not to the fidelity of the XboxSX.Taku Morikawa was born in 1974 in Kanagawa, in Japan. He has a degree of the University of Aoyama Gaukin, where he graduated in Economics in 1997. In 2000 he joined the Japanese group Fast Retailing, where has developed most of his career. The executive has held through several positions in the group like director of sales, general director of Russia and South Asia and finally vice president of Fast Retailing and general manager of Uniqlo Europe.This building has been remodeled and looks great and ready to go. Property is located right behind Pep Boys and next to Merritt Island High.Property features New landscaping, New front doors, 3 of the 5 bathrooms have beenremodeled, Freshly Textured and painted walls, 4 Brand New Lighted box signs, 5 new ac units, the roof in great shape, re-sealed and stripped parking lot, New exterior Paint and more.
The Commercial property located at 119 Mustang Way, Merritt Island, FL 32953 is currently for sale. 119 Mustang Way, Merritt Island is listed for $725,000. This property has approximately 8,000 square feet, and Lot Size of approximately 0.59 Acres. If the property located at 119 Mustang Way, Merritt Island, FL isn't what you're looking for, search Florida commercial real estate to see other properties for sale or lease in Merritt Island.It is