What's new

Need help drawing in space invaders 8080 emulator

dboxall123

New member
Hi all,

I've recently finished my first emulator, chip 8, and decided to move onto space invaders. I've implemented all the instructions required to run space invaders (or, i guess i have, as it now enters into an infinite loop) but I can't work out how to draw. I was hoping it would be similar to how chip 8 draws, but it seems not. I've tried looking at other peoples source on github, but it seems no one comments their code for some reason, and I can't understand the description on the website i linked. Could anyone please explain to me, in clear english, how space invaders is drawn to the screen? Many thanks
 
OP
D

dboxall123

New member
I hoped something like this would work:

Code:
int offset = 0x2400;
        // i corresponds to each row
	for (int i=0; i<224; i++) {
                // there are 32 bytes per scanline
		for (int j=0; j<32; j++) {
                        // offset + j becuase sprites stored at 0x2400
			int pixel_group = memory[offset + j];
                        // shift amount for each byte
			for (int b=0; b<8; b++) {
				if ((pixel_group >> b) & 1) {
                                        //create pixels
but it doesn't seem to find any set bits. I'm not sure what I'm doing wrong
 
OP
D

dboxall123

New member
If I can't do this, is there any chance at all of managing to do nes or gameboy? I was so excited when I got the chip 8 up and running, now I'm hopelessly stuck again lol.
 

Robbbert

Active member
Moderator
When calculating the byte for memory[], you're not including i.

Try int pixel_group = memory[offset + j + i*32]; , perhaps?
 
OP
D

dboxall123

New member
Thanks for your replies guys. Yeah, I worked out where I'd gone wrong, this draws draws the writing to the screen
2WGK7KD
Code:
int offset = 0x2400;
	
	for (int y=0; y<224; y++) {
		for (int x=0; x<32; x++) {
			//printf("%d\n", (y * 32 + x));
			int pix = memory[offset + (y * 32 + x)];
			//printf("%d  ", pix);
			for (int b=0; b<8; b++) {
				if ((pix >> b) & 1) {
					Pixel p;
					p.rect.x = ((x * 8) + b) * PIXEL_SIZE;
					p.rect.y = y * PIXEL_SIZE;
					//printf("%d %d\n", p.rect.x, p.rect.y);
					p.rect.h = PIXEL_SIZE;
					p.rect.w = PIXEL_SIZE;
					SDL_SetRenderDrawColor(app.renderer, 255,255,255,255);
					SDL_RenderFillRect(app.renderer, &p.rect);
I'm stuck in an infinite loop now lol

edit: I (finally) got it running in attract mode!!!
 
Last edited:

Top