What's new

Chip 8

smcd

Active member
To load text into an edit window, read it and then SetWindowText, or SendMessage with WM_SETTEXT, or to append (in a rather hacky sort of way) you can SendMessage with EM_REPLACESEL if the cursor is at the end of the text

ShizZie said:
If this isn't what you want, I'm not really sure what you're looking for - try to rephrase the question

Code:
#include <windows.h>
#include <memory.h>
#include <stdio.h>
#include <commctrl.h>
#include <commdlg.h>

BOOL LoadFile(HWND hEdit, LPSTR pszFileName)
{
	FILE *hFile;
	BOOL bSuccess = FALSE;

	hFile == fopen("log.txt", "w");

	if(hFile != INVALID_HANDLE_VALUE)
	{

		if(1)
		{
			if(pszFileText != NULL)
			{
				DWORD dwRead;
     
				if(fprintf(hFile, "Here is the memory:\n %x ", memory);)
				{
					//pszFileText[dwFileSize] = 0; // Null terminator
					//if(SetWindowText(hEdit, pszFileText))

					bSuccess = TRUE; // It worked!
				}
				GlobalFree(pszFileText);
			}
		}

		CloseHandle(hFile);
	}

	return bSuccess;
}

Whoah shizzie, you're mixing standard C functionality with Windows in an improper way. fopen returns NULL if it fails to open the file, you shouldn't use Windows constants in instances like that. Also, what exactly is that code supposed to do? It looks like you're opening for writing, when later it looks like you're trying to read... Also you free something that is never allocated, nor is it commented that it is dynamically allocated coming into the function. Calling CloseHandle on a FILE* is improper as well, you should use fclose. Not to mention some variable names that appear in the function that aren't declared?! ^gives up trying to figure out that code^
 
Last edited:

ShizZy

Emulator Developer
Seth, I know that's really sloppy. I just hacked in what I had to his function.. didn't test it. If all he wants is to spit out the memory bin to a text file, then all that is needed is the fopen, fprintf, and fclose commands that I had in the original function.
 

secretemu

Future Emu Creator Hopefully
ok so is there something wrong it wont compile
(im using dev c++) just incase the problem is that it is ment for c++.net
 

secretemu

Future Emu Creator Hopefully
this is what i done from what you told me

#include <windows.h>
#include <memory.h>
#include <stdio.h>
#include <commctrl.h>
#include <commdlg.h>
#include "Main.h"

static char g_szClassName[] = "MyWindowClass";
static HINSTANCE g_hInst = NULL;
extern unsigned char memory;
#define IDC_MAIN_TEXT 1001

BOOL LoadFile(HWND hEdit, LPSTR pszFileName)
{
FILE *hFile;
BOOL bSuccess = FALSE;
LPSTR pszFileText;
hFile == fopen("log.txt", "w");

if(hFile != INVALID_HANDLE_VALUE)
{

if(1)
{
if(pszFileText != NULL)
{
DWORD dwRead;

if(fprintf(hFile, "Here is the memory:\n %x ", memory);)
{
//pszFileText[dwFileSize] = 0; // Null terminator
//if(SetWindowText(hEdit, pszFileText))

bSuccess = TRUE; // It worked!
}
GlobalFree(pszFileText);
}
}

CloseHandle(hFile);
}

return bSuccess;
}


here is what comes up on the compiler

C:\Dev-Cpp\main.cpp In function `BOOL LoadFile(HWND__*, CHAR*)':
29 C:\Dev-Cpp\Examples\Copy of FileEditor\Main.c parse error before ';' token
main.cpp C:\Dev-Cpp\main.cpp At global scope:
37 C:\Dev-Cpp\main.cpp syntax error before `return'
2 C:\Dev-Cpp\main.cpp:38 [Warning] no newline at end of file
C:\Dev-Cpp\Makefile.win [Build Error] [main.o] Error 1
 

smcd

Active member
This isn't the best of code but it seems to work...
Code:
BOOL LoadFileBits(HWND hEdit, char szFileName[])
{
	FILE *in;
	int i;
	int j;
	int l=0;
	int len;
	unsigned char c;
	char szBuf[9];
	in = fopen(szFileName, "rb");
	if(in == NULL)
		return FALSE;
	while((len = fread(&c, 1, 1, in))>0)
	{
		l++;
		memset(szBuf, '\0', 9);
		for(i=0,j=7;i<=7;i++,j--)
		{
			szBuf[j]=((c>>i)&0x01)?'1':'0';
		}
		SendMessage(hEdit, EM_REPLACESEL, 0, (LPARAM)szBuf);
		if(l<8)
			SendMessage(hEdit, EM_REPLACESEL, 0, (LPARAM)" ");
		else
		{
			l=0;
			SendMessage(hEdit, EM_REPLACESEL, 0, (LPARAM)"\r\n");
		}
	}
	fclose(in);
	return TRUE;
}
 

ShizZy

Emulator Developer
Ahhh, I gotcha. Why not just open it up in a binary editor then? Wouldn't that save the trouble?
 

ShizZy

Emulator Developer
Time to retire this project. If anyone's interested in the source, contact me. The only reason I didn't post it is because there are a half dozen others, and a lot of them seem to work better then mine. (though not all ;)) It's also a debug build, I didn't feel like figuring out why the release build was giving be errors. So, you need MSVC++ installed or the proper dlls to run it.
 

zenogais

New member
wow, your emulator has uh quite a few problems. It could use some debugging and the Chip8 emulation is very far from complete. But nice graphics :)
 

ShizZy

Emulator Developer
Think so? I did never finish the User Input, but most Chip8 games seem to run right. (Except Space Invaders, couldn't get past the title screen). My BCD isn't right either, so no scores. And it crashes if you try to load a second rom. Well.. okay, maybe a few glitches here and there - but it served it's purpose, which was for me to learn the concept of emulation.

Maybe I'll put a few more hours into it sometime...
 

smcd

Active member
It crashes on most games for me, and if you load a game after having loaded one, it crashes no matter if it runs the game OK the first time around or not.
 

Doomulation

?????????????????????????
secretenum I'll give you a little tip. There are tags called [ code ]. Sourround your code with them and it'll be much more readable :)
ShizZie: nice you've done an emulator. I'd say you fix those bugs and the thingies that keeps a release build, though ;) Get on it! :p
 

secretemu

Future Emu Creator Hopefully
how do i load each register

in the example file i was given this

6XKK - register[X] = KK

but how do you express that in c++

thanks ;)
 

hap

New member
Parse each opcode by masking out unneeded bits for that specific function. In this case: reg[op>>8&0xf]=op&0xff;
 
Last edited:

ChaosBlade

My Heart Chose.. Revenge.
secretemu, no offense, but i think you need to practice your programming a little before taking such a challanging task as emulation. Its not that im against asking for help, i did that many times myself, but emulation isnt your average programming task.

All in all, A little practice with the languauge and IDE and some study on computer structure issues such as bases (binary, octal, hexa-decimal etc) and bit mathmetics wont hurt.

Just trying to help (and hopefully did),

-- Chaosblade.
 

hap

New member
Cool; one of 'our' emus is going around on emulation news sites right now, as seen on emulation9.com and retrogames.com, maybe other sites too. And the lucky winner is zenogais, with NeoChip8 :D:p
 

Top