8080-Emulator  0.1
An Intel 8080 emulator for Space Invaders
space.h
Go to the documentation of this file.
1 
9 #ifndef SPACE_H
10 #define SPACE_H
11 
12 #include "cpu_8080.h"
13 #include <SDL2/SDL.h>
14 #include <SDL2/SDL_timer.h>
15 
16 #define ALIGNED_PREFIX (1<<16)
17 #define ROM_OFFSET 0x0
18 #define VRAM_OFFSET 0x2400
19 #define VRAM_SIZE 0x1C00
20 #define VRAM_DELAY 0x9
21 #define half_1 0x2
22 #define full_2 0x4
23 // Invaders Stuff
24 #define WINDOW_WIDTH (256)
25 #define WINDOW_HEIGHT (224)
26 #define GREEN_PIXEL 0xFF00
27 #define BLACK_PIXEL 0x0
29 
30 #define CREDIT_COIN SDLK_c
31 #define P1_START SDLK_RETURN
32 #define P2_START SDLK_s
33 #define P1_LEFT SDLK_LEFT
34 #define P1_RIGHT SDLK_RIGHT
35 #define P1_SHOOT SDLK_UP
36 #define P2_LEFT SDLK_a
37 #define P2_RIGHT SDLK_d
38 #define P2_SHOOT SDLK_w
40 
46 typedef struct {
47  SDL_Window *window;
49  SDL_Surface *surf;
50  uint32_t* pixels;
51  uint8_t quit_event;
52  SDL_Event event;
53  SDL_TimerID vram_timer;
55 
60 typedef struct {
62 
63  uint8_t port_0;
64  uint8_t port_1;
65  uint8_t port_2;
68 
69  uint8_t port_3;
70  uint8_t port_5;
72 
73  // Shift Regs
74  uint8_t shift_config;
76  union{
77  struct{
78  uint8_t y;
79  uint8_t x;
80  };
81  uint16_t hidden_reg;
82  };
83 } port_IO;
84 
93 int copy_invaders_rom(char *path, cpu_state* cpu);
94 
102 uint8_t space_IN(uint8_t port);
103 
110 void space_OUT(uint8_t port, uint8_t data);
111 
118 void process_key_event(SDL_KeyboardEvent key_event);
119 
120 // SDL Init
129 void set_pixel(uint32_t *pixels, uint32_t x, uint32_t y, uint8_t state);
130 
137 void render_vram(cpu_state *cpu, uint32_t *pixels);
138 
147 uint32_t update_vram_cb(uint32_t interval, UNUSED void *param);
148 
155 
161 void destroy_game_window(invaders_window *game_window);
162 
170 void process_SDL_event(cpu_state *cpu, invaders_window *game_window);
171 
172 #endif
This file simulates and disassembles part of 8080 processor.
#define UNUSED
Definition: cpu_8080.h:16
void set_pixel(uint32_t *pixels, uint32_t x, uint32_t y, uint8_t state)
Set the pixel object to a static value.
Definition: space.c:332
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.
Definition: space.c:251
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
Definition: space.c:179
void space_OUT(uint8_t port, uint8_t data)
Space_OUT, data to write callback.
Definition: space.c:152
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:...
Definition: space.c:101
void destroy_game_window(invaders_window *game_window)
Destorys the game window object.
Definition: space.c:369
void render_vram(cpu_state *cpu, uint32_t *pixels)
Renders the Vram into the surface Pixel.
Definition: space.c:303
uint8_t space_IN(uint8_t port)
Space_IN, IN instruction function callback. Handles all the IN PORT instruction IO.
Definition: space.c:131
invaders_window * init_game_window()
Initializes the SDL game window.
Definition: space.c:336
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
Definition: space.c:284
cpu_state: This structure keeps runtime state of all the registers in the CPU.
Definition: cpu_8080.h:63
invader window struct which keeps track of all the window related state including the SDL components ...
Definition: space.h:46
SDL_Window * window
Definition: space.h:47
uint8_t quit_event
Definition: space.h:51
SDL_Surface * surf
Definition: space.h:49
SDL_Event event
Definition: space.h:52
SDL_TimerID vram_timer
Definition: space.h:53
uint32_t * pixels
Definition: space.h:50
Imaginary external Ports used to communicate with the player and hardware.
Definition: space.h:60
uint16_t hidden_reg
Definition: space.h:81
uint8_t shift_config
Definition: space.h:74
uint8_t y
Definition: space.h:78
uint8_t port_3
Definition: space.h:69
uint8_t x
Definition: space.h:79
uint8_t port_0
Definition: space.h:63