lemsop 0.7a

Discuss other PoP1 related things here.
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5746
Joined: April 9th, 2009, 10:58 pm

Re: lemsop 0.7a

Post by Norbert »

Short update on the work in progress.
Recently added a guards screen.
Image
Spoiler: show
(Online backup.)

Code: Select all

GPL3+ licensed

----------
#define MAX_GUARDS 37
----------
int iActiveGuard;
----------
int arGuardR[MAX_GUARDS + 2];
int arGuardG[MAX_GUARDS + 2];
int arGuardB[MAX_GUARDS + 2];
int arGuardGameLevel[MAX_GUARDS + 2];
int arGuardHP[MAX_GUARDS + 2];
int arGuardDir[MAX_GUARDS + 2];
int arGuardMove[MAX_GUARDS + 2];
----------
static const int iOffsetGuardTable = 0x6CAD;
----------
SDL_Texture *imgguards;
----------
void ColorRect (int iX, int iY, int iW, int iH, int iR, int iG, int iB);
void Guards (void);
void ShowGuards (void);
----------
	iActiveGuard = 0;
----------
	lseek (iFd, iOffsetGuardTable, SEEK_SET);
	for (iLoopGuard = 0; iLoopGuard <= MAX_GUARDS; iLoopGuard++)
	{
		read (iFd, sRead, 1);
		arGuardR[iLoopGuard] = 0;
		arGuardG[iLoopGuard] = 0;
		arGuardB[iLoopGuard] = 0;
		if (sRead[0] & (1 << 0)) { arGuardR[iLoopGuard]+= 1; }
		if (sRead[0] & (1 << 1)) { arGuardR[iLoopGuard]+= 2; }
		if (sRead[0] & (1 << 2)) { arGuardG[iLoopGuard]+= 1; }
		if (sRead[0] & (1 << 3)) { arGuardG[iLoopGuard]+= 2; }
		if (sRead[0] & (1 << 4)) { arGuardB[iLoopGuard]+= 1; }
		if (sRead[0] & (1 << 5)) { arGuardB[iLoopGuard]+= 2; }
		read (iFd, sRead, 1);
		arGuardGameLevel[iLoopGuard] = sRead[0];
		read (iFd, sRead, 1);
		arGuardHP[iLoopGuard] = 0;
		if (sRead[0] & (1 << 0)) { arGuardHP[iLoopGuard]+=1; }
		if (sRead[0] & (1 << 1)) { arGuardHP[iLoopGuard]+=2; }
		if (sRead[0] & (1 << 2)) { arGuardHP[iLoopGuard]+=4; }
		if (sRead[0] & (1 << 3)) { arGuardHP[iLoopGuard]+=8; }
		arGuardDir[iLoopGuard] = 0;
		if (sRead[0] & (1 << 6)) { arGuardDir[iLoopGuard]+=1; }
		arGuardMove[iLoopGuard] = 0;
		if (sRead[0] & (1 << 7)) { arGuardMove[iLoopGuard]+=1; }
		if (iDebug == 1)
		{
			printf ("[ INFO ] Guard %i: Color:R%i/G%i/B%i GLevel:%i HP:%i Dir:%i"
				" Move:%i\n", iLoopGuard, arGuardR[iLoopGuard], arGuardG[iLoopGuard],
				arGuardB[iLoopGuard], arGuardGameLevel[iLoopGuard],
				arGuardHP[iLoopGuard], arGuardDir[iLoopGuard],
				arGuardMove[iLoopGuard]);
		}
	}
----------
	PreLoad (PNG_VARIOUS, "guards.png", &imgguards);
----------
						case SDLK_g: /*** guards ***/
							Guards();
							break;
----------
          case 0x64: /*** guard ***/
            if (arGuardDir[iByte1] == 1)
              { cDir = 'r'; } else { cDir = 'l'; }
----------
      case 0x64: /*** guard ***/
        snprintf (arTextB1[0], MAX_TEXT, "%s", "# (\"g\" to edit)");
----------
/*****************************************************************************/
void ColorRect (int iX, int iY, int iW, int iH, int iR, int iG, int iB)
/*****************************************************************************/
{
	SDL_Rect rect;

	rect.x = iX * iScale;
	rect.y = iY * iScale;
	rect.w = iW * iScale;
	rect.h = iH * iScale;
	SDL_SetRenderDrawColor (ascreen, iR, iG, iB, SDL_ALPHA_OPAQUE);
	SDL_RenderFillRect (ascreen, &rect);
}
/*****************************************************************************/
void Guards (void)
/*****************************************************************************/
{
	int iGuards;
	SDL_Event event;
	int iChecked;

	iGuards = 1;

	PlaySound ("wav/popup.wav");
	ShowGuards();
	while (iGuards == 1)
	{
		while (SDL_PollEvent (&event))
		{
			if (MapEvents (event) == 0)
			switch (event.type)
			{
				case SDL_CONTROLLERBUTTONDOWN:
					/*** Nothing for now. ***/
					break;
				case SDL_CONTROLLERBUTTONUP:
					switch (event.cbutton.button)
					{
						case SDL_CONTROLLER_BUTTON_A:
							iGuards = 0; break;
					}
					break;
				case SDL_KEYDOWN:
					switch (event.key.keysym.sym)
					{
						case SDLK_KP_ENTER:
						case SDLK_RETURN:
						case SDLK_SPACE:
						case SDLK_o:
							iGuards = 0; break;
						case SDLK_LEFT:
							if ((event.key.keysym.mod & KMOD_LSHIFT) ||
								(event.key.keysym.mod & KMOD_RSHIFT))
							{
								if (iActiveGuard > 0)
								{
									iActiveGuard--;
									PlaySound ("wav/plus_minus.wav");
								}
							} else if ((event.key.keysym.mod & KMOD_LCTRL) ||
								(event.key.keysym.mod & KMOD_RCTRL))
							{
								if (iActiveGuard > 0)
								{
									iActiveGuard-=10;
									if (iActiveGuard < 0) { iActiveGuard = 0; }
									PlaySound ("wav/plus_minus.wav");
								}
							}
							break;
						case SDLK_RIGHT:
							if ((event.key.keysym.mod & KMOD_LSHIFT) ||
								(event.key.keysym.mod & KMOD_RSHIFT))
							{
								if (iActiveGuard < MAX_GUARDS)
								{
									iActiveGuard++;
									PlaySound ("wav/plus_minus.wav");
								}
							} else if ((event.key.keysym.mod & KMOD_LCTRL) ||
								(event.key.keysym.mod & KMOD_RCTRL))
							{
								if (iActiveGuard < MAX_GUARDS)
								{
									iActiveGuard+=10;
									if (iActiveGuard > MAX_GUARDS)
										{ iActiveGuard = MAX_GUARDS; }
									PlaySound ("wav/plus_minus.wav");
								}
							}
							break;
						case SDLK_r: /*** Red. ***/
							arGuardR[iActiveGuard]++;
							if (arGuardR[iActiveGuard] == 4)
								{ arGuardR[iActiveGuard] = 0; }
							PlaySound ("wav/check_box.wav");
							iChanged++;
							break;
						case SDLK_g: /*** Green. ***/
							arGuardG[iActiveGuard]++;
							if (arGuardG[iActiveGuard] == 4)
								{ arGuardG[iActiveGuard] = 0; }
							PlaySound ("wav/check_box.wav");
							iChanged++;
							break;
						case SDLK_b: /*** Blue. ***/
							arGuardB[iActiveGuard]++;
							if (arGuardB[iActiveGuard] == 4)
								{ arGuardB[iActiveGuard] = 0; }
							PlaySound ("wav/check_box.wav");
							iChanged++;
							break;
						case SDLK_l: /*** Game level. ***/
							arGuardGameLevel[iActiveGuard]++;
							if (arGuardGameLevel[iActiveGuard] == 15)
								{ arGuardGameLevel[iActiveGuard] = 1; }
							PlaySound ("wav/check_box.wav");
							iChanged++;
							break;
						case SDLK_h: /*** Hit points. ***/
							arGuardHP[iActiveGuard]++;
							if (arGuardHP[iActiveGuard] == 16)
								{ arGuardHP[iActiveGuard] = 0; }
							PlaySound ("wav/check_box.wav");
							iChanged++;
							break;
						case SDLK_d: /*** Direction. ***/
							if (arGuardDir[iActiveGuard] == 0)
								{ arGuardDir[iActiveGuard] = 1; }
									else { arGuardDir[iActiveGuard] = 0; }
							PlaySound ("wav/check_box.wav");
							iChanged++;
							break;
						case SDLK_m: /*** Move to prince. ***/
							if (arGuardMove[iActiveGuard] == 0)
								{ arGuardMove[iActiveGuard] = 1; }
									else { arGuardMove[iActiveGuard] = 0; }
							PlaySound ("wav/check_box.wav");
							iChanged++;
							break;
					}
					ShowGuards();
					break;
				case SDL_MOUSEMOTION:
					iXPos = event.motion.x;
					iYPos = event.motion.y;
					ShowGuards();
					break;
				case SDL_MOUSEBUTTONDOWN:
					if (event.button.button == 1)
					{
						if (InArea (460, 410, 460 + 85, 410 + 32) == 1) /*** OK ***/
							{ iOKOn = 1; }
					}
					ShowGuards();
					break;
				case SDL_MOUSEBUTTONUP:
					iOKOn = 0;
					iChecked = 0;
					if (event.button.button == 1)
					{
						if (InArea (460, 410, 460 + 85, 410 + 32) == 1) /*** OK ***/
							{ iGuards = 0; }

						/*** Edit this guard. ***/
						PlusMinus (&iActiveGuard, 127, 29, 0, MAX_GUARDS, -10, 1);
						PlusMinus (&iActiveGuard, 142, 29, 0, MAX_GUARDS, -1, 1);
						PlusMinus (&iActiveGuard, 212, 29, 0, MAX_GUARDS, +1, 1);
						PlusMinus (&iActiveGuard, 227, 29, 0, MAX_GUARDS, +10, 1);

						/*** Red. ***/
						if (InArea (130, 81, 130 + 14, 81 + 14) == 1)
							{ arGuardR[iActiveGuard] = 0; iChecked = 1; }
						if (InArea (145, 81, 145 + 14, 81 + 14) == 1)
							{ arGuardR[iActiveGuard] = 1; iChecked = 1; }
						if (InArea (160, 81, 160 + 14, 81 + 14) == 1)
							{ arGuardR[iActiveGuard] = 2; iChecked = 1; }
						if (InArea (175, 81, 175 + 14, 81 + 14) == 1)
							{ arGuardR[iActiveGuard] = 3; iChecked = 1; }

						/*** Green. ***/
						if (InArea (274, 81, 274 + 14, 81 + 14) == 1)
							{ arGuardG[iActiveGuard] = 0; iChecked = 1; }
						if (InArea (289, 81, 289 + 14, 81 + 14) == 1)
							{ arGuardG[iActiveGuard] = 1; iChecked = 1; }
						if (InArea (304, 81, 304 + 14, 81 + 14) == 1)
							{ arGuardG[iActiveGuard] = 2; iChecked = 1; }
						if (InArea (319, 81, 319 + 14, 81 + 14) == 1)
							{ arGuardG[iActiveGuard] = 3; iChecked = 1; }

						/*** Blue. ***/
						if (InArea (403, 81, 403 + 14, 81 + 14) == 1)
							{ arGuardB[iActiveGuard] = 0; iChecked = 1; }
						if (InArea (418, 81, 418 + 14, 81 + 14) == 1)
							{ arGuardB[iActiveGuard] = 1; iChecked = 1; }
						if (InArea (433, 81, 433 + 14, 81 + 14) == 1)
							{ arGuardB[iActiveGuard] = 2; iChecked = 1; }
						if (InArea (448, 81, 448 + 14, 81 + 14) == 1)
							{ arGuardB[iActiveGuard] = 3; iChecked = 1; }

						/*** Game level. ***/
						if (InArea (117, 121, 117 + 14, 121 + 14) == 1)
							{ arGuardGameLevel[iActiveGuard] = 1; iChecked = 1; }
						if (InArea (132, 121, 132 + 14, 121 + 14) == 1)
							{ arGuardGameLevel[iActiveGuard] = 2; iChecked = 1; }
						if (InArea (147, 121, 147 + 14, 121 + 14) == 1)
							{ arGuardGameLevel[iActiveGuard] = 3; iChecked = 1; }
						if (InArea (162, 121, 162 + 14, 121 + 14) == 1)
							{ arGuardGameLevel[iActiveGuard] = 4; iChecked = 1; }
						if (InArea (177, 121, 177 + 14, 121 + 14) == 1)
							{ arGuardGameLevel[iActiveGuard] = 5; iChecked = 1; }
						if (InArea (192, 121, 192 + 14, 121 + 14) == 1)
							{ arGuardGameLevel[iActiveGuard] = 6; iChecked = 1; }
						if (InArea (207, 121, 207 + 14, 121 + 14) == 1)
							{ arGuardGameLevel[iActiveGuard] = 7; iChecked = 1; }
						if (InArea (222, 121, 222 + 14, 121 + 14) == 1)
							{ arGuardGameLevel[iActiveGuard] = 8; iChecked = 1; }
						if (InArea (237, 121, 237 + 14, 121 + 14) == 1)
							{ arGuardGameLevel[iActiveGuard] = 9; iChecked = 1; }
						if (InArea (252, 121, 252 + 14, 121 + 14) == 1)
							{ arGuardGameLevel[iActiveGuard] = 10; iChecked = 1; }
						if (InArea (267, 121, 267 + 14, 121 + 14) == 1)
							{ arGuardGameLevel[iActiveGuard] = 11; iChecked = 1; }
						if (InArea (282, 121, 282 + 14, 121 + 14) == 1)
							{ arGuardGameLevel[iActiveGuard] = 12; iChecked = 1; }
						if (InArea (297, 121, 297 + 14, 121 + 14) == 1)
							{ arGuardGameLevel[iActiveGuard] = 13; iChecked = 1; }
						if (InArea (312, 121, 312 + 14, 121 + 14) == 1)
							{ arGuardGameLevel[iActiveGuard] = 14; iChecked = 1; }

						/*** Hit points. ***/
						if (InArea (97, 162, 97 + 14, 162 + 14) == 1)
							{ arGuardHP[iActiveGuard] = 0; iChecked = 1; }
						if (InArea (112, 162, 112 + 14, 162 + 14) == 1)
							{ arGuardHP[iActiveGuard] = 1; iChecked = 1; }
						if (InArea (127, 162, 127 + 14, 162 + 14) == 1)
							{ arGuardHP[iActiveGuard] = 2; iChecked = 1; }
						if (InArea (142, 162, 142 + 14, 162 + 14) == 1)
							{ arGuardHP[iActiveGuard] = 3; iChecked = 1; }
						if (InArea (157, 162, 157 + 14, 162 + 14) == 1)
							{ arGuardHP[iActiveGuard] = 4; iChecked = 1; }
						if (InArea (172, 162, 172 + 14, 162 + 14) == 1)
							{ arGuardHP[iActiveGuard] = 5; iChecked = 1; }
						if (InArea (187, 162, 187 + 14, 162 + 14) == 1)
							{ arGuardHP[iActiveGuard] = 6; iChecked = 1; }
						if (InArea (202, 162, 202 + 14, 162 + 14) == 1)
							{ arGuardHP[iActiveGuard] = 7; iChecked = 1; }
						if (InArea (217, 162, 217 + 14, 162 + 14) == 1)
							{ arGuardHP[iActiveGuard] = 8; iChecked = 1; }
						if (InArea (232, 162, 232 + 14, 162 + 14) == 1)
							{ arGuardHP[iActiveGuard] = 9; iChecked = 1; }
						if (InArea (247, 162, 247 + 14, 162 + 14) == 1)
							{ arGuardHP[iActiveGuard] = 10; iChecked = 1; }
						if (InArea (262, 162, 262 + 14, 162 + 14) == 1)
							{ arGuardHP[iActiveGuard] = 11; iChecked = 1; }
						if (InArea (277, 162, 277 + 14, 162 + 14) == 1)
							{ arGuardHP[iActiveGuard] = 12; iChecked = 1; }
						if (InArea (292, 162, 292 + 14, 162 + 14) == 1)
							{ arGuardHP[iActiveGuard] = 13; iChecked = 1; }
						if (InArea (307, 162, 307 + 14, 162 + 14) == 1)
							{ arGuardHP[iActiveGuard] = 14; iChecked = 1; }
						if (InArea (322, 162, 322 + 14, 162 + 14) == 1)
							{ arGuardHP[iActiveGuard] = 15; iChecked = 1; }

						/*** Direction. ***/
						if (InArea (96, 203, 96 + 14, 203 + 14) == 1)
							{ arGuardDir[iActiveGuard] = 0; iChecked = 1; }
						if (InArea (111, 203, 111 + 14, 203 + 14) == 1)
							{ arGuardDir[iActiveGuard] = 1; iChecked = 1; }

						/*** Move to prince. ***/
						if (InArea (139, 244, 139 + 14, 244 + 14) == 1)
							{ arGuardMove[iActiveGuard] = 0; iChecked = 1; }
						if (InArea (154, 244, 154 + 14, 244 + 14) == 1)
							{ arGuardMove[iActiveGuard] = 1; iChecked = 1; }
					}
					if (iChecked == 1)
					{
						PlaySound ("wav/check_box.wav");
						iChanged++;
					}
					ShowGuards();
					break;
				case SDL_WINDOWEVENT:
					switch (event.window.event)
					{
						case SDL_WINDOWEVENT_EXPOSED:
							ShowGuards(); break;
						case SDL_WINDOWEVENT_CLOSE:
							Quit(); break;
						case SDL_WINDOWEVENT_FOCUS_GAINED:
							iActiveWindowID = iWindowID; break;
					}
					break;
				case SDL_QUIT:
					Quit(); break;
			}
		}

		/*** prevent CPU eating ***/
		gamespeed = REFRESH;
		while ((SDL_GetTicks() - looptime) < gamespeed)
		{
			SDL_Delay (10);
		}
		looptime = SDL_GetTicks();
	}
	PlaySound ("wav/popup_close.wav");
	ShowScreen (iScreen);
}
/*****************************************************************************/
void ShowGuards (void)
/*****************************************************************************/
{
	int iX;
	int iR, iG, iB;

	/*** background ***/
	ShowImage (imgguards, 0, 0, "imgguards", ascreen, iScale, 1);

	/*** OK ***/
	switch (iOKOn)
	{
		case 0: /*** off ***/
			ShowImage (imgok[1], 460, 410, "imgok[1]", ascreen, iScale, 1); break;
		case 1: /*** on ***/
			ShowImage (imgok[2], 460, 410, "imgok[2]", ascreen, iScale, 1); break;
	}

	/*** Edit this guard. ***/
	CenterNumber (ascreen, iActiveGuard, 155, 29, color_bl, 0);

	/*** Red. ***/
	switch (arGuardR[iActiveGuard])
	{
		case 0: iX = 130; break;
		case 1: iX = 145; break;
		case 2: iX = 160; break;
		case 3: iX = 175; break;
		default: iX = 130; break; /*** Fallback. ***/
	}
	ShowImage (imgselg, iX, 81, "imgselg", ascreen, iScale, 1);

	/*** Green. ***/
	switch (arGuardG[iActiveGuard])
	{
		case 0: iX = 274; break;
		case 1: iX = 289; break;
		case 2: iX = 304; break;
		case 3: iX = 319; break;
		default: iX = 274; break; /*** Fallback. ***/
	}
	ShowImage (imgselg, iX, 81, "imgselg", ascreen, iScale, 1);

	/*** Blue. ***/
	switch (arGuardB[iActiveGuard])
	{
		case 0: iX = 403; break;
		case 1: iX = 418; break;
		case 2: iX = 433; break;
		case 3: iX = 448; break;
		default: iX = 403; break; /*** Fallback. ***/
	}
	ShowImage (imgselg, iX, 81, "imgselg", ascreen, iScale, 1);

	/*** Approximate(!) color. ***/
	iR = (arGuardR[iActiveGuard] * 255) / 3;
	iG = (arGuardG[iActiveGuard] * 255) / 3;
	iB = (arGuardB[iActiveGuard] * 255) / 3;
	ColorRect (494, 66, 41, 29, iR, iG, iB);

	/*** Game level. ***/
	switch (arGuardGameLevel[iActiveGuard])
	{
		case 1: iX = 117; break;
		case 2: iX = 132; break;
		case 3: iX = 147; break;
		case 4: iX = 162; break;
		case 5: iX = 177; break;
		case 6: iX = 192; break;
		case 7: iX = 207; break;
		case 8: iX = 222; break;
		case 9: iX = 237; break;
		case 10: iX = 252; break;
		case 11: iX = 267; break;
		case 12: iX = 282; break;
		case 13: iX = 297; break;
		case 14: iX = 312; break;
		default: iX = 117; break; /*** Fallback. ***/
	}
	ShowImage (imgselg, iX, 121, "imgselg", ascreen, iScale, 1);

	/*** Hit points. ***/
	switch (arGuardHP[iActiveGuard])
	{
		case 0: iX = 97; break;
		case 1: iX = 112; break;
		case 2: iX = 127; break;
		case 3: iX = 142; break;
		case 4: iX = 157; break;
		case 5: iX = 172; break;
		case 6: iX = 187; break;
		case 7: iX = 202; break;
		case 8: iX = 217; break;
		case 9: iX = 232; break;
		case 10: iX = 247; break;
		case 11: iX = 262; break;
		case 12: iX = 277; break;
		case 13: iX = 292; break;
		case 14: iX = 307; break;
		case 15: iX = 322; break;
		default: iX = 97; break; /*** Fallback. ***/
	}
	ShowImage (imgselg, iX, 162, "imgselg", ascreen, iScale, 1);

	/*** Direction. ***/
	switch (arGuardDir[iActiveGuard])
	{
		case 0: iX = 96; break;
		case 1: iX = 111; break;
		default: iX = 96; break; /*** Fallback. ***/
	}
	ShowImage (imgselg, iX, 203, "imgselg", ascreen, iScale, 1);

	/*** Move to prince. ***/
	switch (arGuardMove[iActiveGuard])
	{
		case 0: iX = 139; break;
		case 1: iX = 154; break;
		default: iX = 139; break; /*** Fallback. ***/
	}
	ShowImage (imgselg, iX, 244, "imgselg", ascreen, iScale, 1);

	/*** refresh screen ***/
	SDL_RenderPresent (ascreen);
}
/*****************************************************************************/
----------
future34.png
salvadorc17
Calif
Calif
Posts: 553
Joined: August 27th, 2011, 2:04 am

Re: lemsop 0.7a

Post by salvadorc17 »

This could allow editing game gear, i prefer how that emulated version works than master system
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5746
Joined: April 9th, 2009, 10:58 pm

Re: lemsop 0.7a

Post by Norbert »

salvadorc17 wrote: March 29th, 2020, 9:57 pm This could allow editing game gear, i prefer how that emulated version works than master system
Maybe some day.
salvadorc17
Calif
Calif
Posts: 553
Joined: August 27th, 2011, 2:04 am

Re: lemsop 0.7a

Post by salvadorc17 »

Norbert wrote: March 30th, 2020, 3:08 pm
Maybe some day.

I suppose this has same level structured, do you have level format of master system ,maybe can try myself.
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5746
Joined: April 9th, 2009, 10:58 pm

Re: lemsop 0.7a

Post by Norbert »

salvadorc17 wrote: March 30th, 2020, 11:52 pmdo you have level format of master system
https://www.princed.org/wiki/SEGA_Master_System_format
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5746
Joined: April 9th, 2009, 10:58 pm

Re: lemsop 0.7a

Post by Norbert »

Getting closer.
I've now also managed to replace the button bytes, that were presented (separately) to the user, with "room" and "elem".
In other words, LoadLevel() now looks up the relevant elements that buttons point to.
Last but not least, I will try to fully tackle saving in the coming weeks.
My plan is to release v0.8b early (2?) May.
Locked