8080-Emulator  0.1
An Intel 8080 emulator for Space Invaders
Classes | Macros | Functions
space.h File Reference

File containing #defines for spaceinvaders wrapper. More...

#include "cpu_8080.h"
#include <SDL2/SDL.h>
#include <SDL2/SDL_timer.h>
Include dependency graph for space.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  invaders_window
 invader window struct which keeps track of all the window related state including the SDL components and timers More...
 
struct  port_IO
 Imaginary external Ports used to communicate with the player and hardware. More...
 

Macros

#define ALIGNED_PREFIX   (1<<16) /** Prefix to get 16bit aligned memory */
 
#define ROM_OFFSET   0x0 /** offset to load the ROM **/
 
#define VRAM_OFFSET   0x2400 /** Location of VRAM **/
 
#define VRAM_SIZE   0x1C00 /** Size of VRAM **/
 
#define VRAM_DELAY   0x9 /** 112 Hz for 1000 ms */
 
#define half_1   0x2 /** Pending Intt to Call RST 1 */
 
#define full_2   0x4 /** Pending Intt to Call RST 2 */
 
#define WINDOW_WIDTH   (256) /** Window Width, later rotated */
 
#define WINDOW_HEIGHT   (224) /** Window Height, later rotated */
 
#define GREEN_PIXEL   0xFF00 /** RGB888 GREEN Value */
 
#define BLACK_PIXEL   0x0 /** RGB888 Black Value */
 
#define CREDIT_COIN   SDLK_c
 
#define P1_START   SDLK_RETURN
 
#define P2_START   SDLK_s
 
#define P1_LEFT   SDLK_LEFT
 
#define P1_RIGHT   SDLK_RIGHT
 
#define P1_SHOOT   SDLK_UP
 
#define P2_LEFT   SDLK_a
 
#define P2_RIGHT   SDLK_d
 
#define P2_SHOOT   SDLK_w
 

Functions

int copy_invaders_rom (char *path, cpu_state *cpu)
 Copies the invaders ROM into the correct memory locations. The way memory is mapped is documented at: http://www.emutalk.net/threads/38177-Space-Invaders. More...
 
uint8_t space_IN (uint8_t port)
 Space_IN, IN instruction function callback. Handles all the IN PORT instruction IO. More...
 
void space_OUT (uint8_t port, uint8_t data)
 Space_OUT, data to write callback. More...
 
void process_key_event (SDL_KeyboardEvent key_event)
 processes a key_event by setting the IO_Ports in order to pass the input into the CPU state More...
 
void set_pixel (uint32_t *pixels, uint32_t x, uint32_t y, uint8_t state)
 Set the pixel object to a static value. More...
 
void render_vram (cpu_state *cpu, uint32_t *pixels)
 Renders the Vram into the surface Pixel. More...
 
uint32_t update_vram_cb (uint32_t interval, UNUSED void *param)
 callback which is triggered when scan line reaches 1/2 of the display, or at 120Hz More...
 
invaders_windowinit_game_window ()
 Initializes the SDL game window. More...
 
void destroy_game_window (invaders_window *game_window)
 Destorys the game window object. More...
 
void process_SDL_event (cpu_state *cpu, invaders_window *game_window)
 Process the incoming SDL event. Called whenever a new event is seen during the polling process. More...
 

Detailed Description

File containing #defines for spaceinvaders wrapper.

Author
Pranay Garg (prana.nosp@m.yga@.nosp@m.andre.nosp@m.w.cm.nosp@m.u.edu)
Version
0.1
Date
2021-01-14

Macro Definition Documentation

◆ CREDIT_COIN

#define CREDIT_COIN   SDLK_c

Key Mapping TODO

Function Documentation

◆ copy_invaders_rom()

int copy_invaders_rom ( char *  path,
cpu_state cpu 
)

Copies the invaders ROM into the correct memory locations. The way memory is mapped is documented at: http://www.emutalk.net/threads/38177-Space-Invaders.

Parameters
pathto the folder containing the ROM
cpupointer to the CPU instance executing the ROM
Returns
int -1 if fail, array of file descriptors if pass

◆ destroy_game_window()

void destroy_game_window ( invaders_window game_window)

Destorys the game window object.

Parameters
game_window

◆ init_game_window()

invaders_window* init_game_window ( )

Initializes the SDL game window.

Returns
invaders_window* pointer to the game window object

◆ process_key_event()

void process_key_event ( SDL_KeyboardEvent  key_event)

processes a key_event by setting the IO_Ports in order to pass the input into the CPU state

Parameters
key_eventthe key event being pressed/released

◆ process_SDL_event()

void process_SDL_event ( cpu_state cpu,
invaders_window game_window 
)

Process the incoming SDL event. Called whenever a new event is seen during the polling process.

Parameters
cputo modify using the event
game_windowrelating to the generated event

◆ render_vram()

void render_vram ( cpu_state cpu,
uint32_t *  pixels 
)

Renders the Vram into the surface Pixel.

Parameters
cpucpu emulating the game
pixelsunderlying uint32_t[] pointer for the SDL surface

◆ set_pixel()

void set_pixel ( uint32_t *  pixels,
uint32_t  x,
uint32_t  y,
uint8_t  state 
)

Set the pixel object to a static value.

Parameters
pixelsunderlying uint32_t[] pointer for the SDL surface
xindex to update
yindex to update
state0 for OFF, 1 for ON

◆ space_IN()

uint8_t space_IN ( uint8_t  port)

Space_IN, IN instruction function callback. Handles all the IN PORT instruction IO.

Note
Intercept READs on port and handles according to Spec
Parameters
portPORT to read/write
Returns
uint8_t Data Read

◆ space_OUT()

void space_OUT ( uint8_t  port,
uint8_t  data 
)

Space_OUT, data to write callback.

Note
Handles the write according to the callback behaviour
Parameters
portPORT to read/write
dataData to write

◆ update_vram_cb()

uint32_t update_vram_cb ( uint32_t  interval,
UNUSED void *  param 
)

callback which is triggered when scan line reaches 1/2 of the display, or at 120Hz

Parameters
intervalInterval to trigger at
paramNULL
Returns
uint32_t Interval