Skip to content

Commit 1432b7d

Browse files
committed
initial
1 parent fc3b239 commit 1432b7d

19 files changed

+13551
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
images/
2+
13
# Compiled Object files
24
*.slo
35
*.lo

Makefile

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
PROCESSOR_FAMILY := lm4f
2+
BOARD := lplm4f120h5qr
3+
# watch the CPU execute
4+
#LOCAL_CPPFLAGS := -DCPU_DEBUG
5+
CXXFLAGS := -fno-operator-names
6+
7+
include energia.mk

config.h

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#ifndef __CONFIG_H__
2+
#define __CONFIG_H__
3+
4+
#define P1_START 0x16 // 1
5+
#define P2_START 0x1e // 2
6+
#define COIN 0x26 // 3
7+
8+
#define KEY_LEFT 0x33 // H
9+
#define KEY_RIGHT 0x4b // L
10+
#define KEY_UP 0x42 // K
11+
#define KEY_DOWN 0x3b // J
12+
//#define KEY_LEFT PS2_LEFTARROW
13+
//#define KEY_RIGHT PS2_RIGHTARROW
14+
//#define KEY_UP PS2_UPARROW
15+
//#define KEY_DOWN PS2_DOWNARROW
16+
17+
#define PAUSE 0x29 // space
18+
#define ROTATE 0x2d // r
19+
20+
#endif

display.cpp

+138
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
#include <Energia.h>
2+
#include <UTFT.h>
3+
#include <r65emu.h>
4+
5+
#include "display.h"
6+
7+
#include "roms/rom5e.h" // tiles
8+
#include "roms/rom5f.h" // sprites
9+
#include "roms/rom82s123_7f.h" // colours
10+
#include "roms/rom82s126_4a.h" // palette
11+
12+
void Display::begin() {
13+
UTFTDisplay::begin(VGA_BLACK, VGA_WHITE, portrait);
14+
clear();
15+
_xoff = (_dx - DISPLAY_WIDTH) / 2;
16+
_yoff = (_dy - DISPLAY_HEIGHT) / 2;
17+
}
18+
19+
void Display::update() {
20+
draw_tiles();
21+
}
22+
23+
static void get_tile_palette(palette_entry &p, byte index) {
24+
index <<= 2;
25+
p.set_colour(colours[palette[index ]], 0);
26+
p.set_colour(colours[palette[index+1]], 1);
27+
p.set_colour(colours[palette[index+2]], 2);
28+
p.set_colour(colours[palette[index+3]], 3);
29+
}
30+
31+
void Display::draw_sprite_slice(palette_entry &p, byte *cdata, int offset, int x, int y) {
32+
offset *= 32;
33+
for (int n = 7; n >= 0; n--) // 8 columns
34+
for (int m = 3; m >= 0; m--) { // 4 rows
35+
colour &c = p.colours[cdata[offset]];
36+
utft.setColor(c.red, c.green, c.blue);
37+
// FIXME: investigate this
38+
if (_dx <= (x+n)) {
39+
//Serial.print("x offscreen: ");
40+
//Serial.println(x+n);
41+
continue;
42+
}
43+
if (_dy <= (y+m)) {
44+
//Serial.print("y offscreen: ");
45+
//Serial.println(y+m);
46+
continue;
47+
}
48+
49+
utft.drawPixel(x+n, y+m);
50+
offset++;
51+
}
52+
}
53+
54+
void Display::draw_tile(word a, int x, int y) {
55+
byte tile = _tiles[a];
56+
byte character[64];
57+
for (unsigned i = 0; i < 16; i++) {
58+
byte b = tiles[tile*16 + i];
59+
character[i*4 ] = (b & 0x01) | ((b >> 3) & 0x02);
60+
character[i*4+1] = ((b >> 1) & 0x01) | ((b >> 4) & 0x02);
61+
character[i*4+2] = ((b >> 2) & 0x01) | ((b >> 5) & 0x02);
62+
character[i*4+3] = ((b >> 3) & 0x01) | ((b >> 6) & 0x02);
63+
}
64+
65+
palette_entry p;
66+
get_tile_palette(p, _tiles[a + 0x0400]);
67+
68+
draw_sprite_slice(p, character, 0, x, y+4);
69+
draw_sprite_slice(p, character, 1, x, y);
70+
}
71+
72+
void Display::_set(word a, byte b) {
73+
if (_tiles[a] != b) {
74+
_tiles[a] = b;
75+
int x, y;
76+
if (a >= 0x02 && a < 0x1e) {
77+
x = 27 - a+0x02;
78+
y = 34;
79+
} else if (a >= 0x22 && a < 0x3e) {
80+
x = 27 - a+0x22;
81+
y = 35;
82+
} else if (a >= 0x40 && a < 0x3c0) {
83+
word o = a - 0x40;
84+
x = 27 - o / 0x20;
85+
y = 2 + o % 0x20;
86+
} else if (a >= 0x3c2 && a < 0x3e0) {
87+
x = 27 - a+0x3c2;
88+
y = 0;
89+
} else if (a >= 0x3e2 && a < 0x400) {
90+
x = 27 - a+0x3e2;
91+
y = 1;
92+
} else
93+
return;
94+
draw_tile(a, 8*x + _xoff, 8*y + _yoff);
95+
}
96+
}
97+
98+
void Display::set_sprite(int n, byte sx, byte sy) {
99+
int x = DISPLAY_WIDTH - sx + 15 + _xoff;
100+
int y = DISPLAY_HEIGHT - sy - 16 + _yoff;
101+
byte sir = _mem[0x4ff0 + n*2];
102+
103+
/*
104+
Serial.print("sprite ");
105+
Serial.print(n);
106+
Serial.print(" ");
107+
Serial.print(sir);
108+
Serial.print(" ");
109+
Serial.print(sx);
110+
Serial.print(", ");
111+
Serial.println(sy);
112+
*/
113+
114+
byte character[256];
115+
word si = 64*(sir >> 2);
116+
for (unsigned i = 0; i < 64; i++) {
117+
byte b = sprites[si + i];
118+
character[i*4 ] = (b & 0x01) | ((b >> 3) & 0x02);
119+
character[i*4+1] = ((b >> 1) & 0x01) | ((b >> 4) & 0x02);
120+
character[i*4+2] = ((b >> 2) & 0x01) | ((b >> 5) & 0x02);
121+
character[i*4+3] = ((b >> 3) & 0x01) | ((b >> 6) & 0x02);
122+
}
123+
124+
palette_entry p;
125+
get_tile_palette(p, _mem[0x4ff1 + n*2]);
126+
127+
draw_sprite_slice(p, character, 0, x+8, y+12);
128+
draw_sprite_slice(p, character, 1, x+8, y);
129+
draw_sprite_slice(p, character, 2, x+8, y+4);
130+
draw_sprite_slice(p, character, 3, x+8, y+8);
131+
132+
draw_sprite_slice(p, character, 4, x, y+12);
133+
draw_sprite_slice(p, character, 5, x, y);
134+
draw_sprite_slice(p, character, 6, x, y+4);
135+
draw_sprite_slice(p, character, 7, x, y+8);
136+
137+
// FIXME rotation
138+
}

display.h

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#ifndef __DISPLAY_H__
2+
#define __DISPLAY_H__
3+
4+
#define DISPLAY_WIDTH 224
5+
#define DISPLAY_HEIGHT 288
6+
7+
class colour {
8+
public:
9+
byte red, green, blue;
10+
11+
void set(byte r, byte g, byte b) {
12+
red = r; green = g; blue = b;
13+
}
14+
};
15+
16+
class palette_entry {
17+
public:
18+
colour colours[4];
19+
20+
void set_colour(byte c, int i) {
21+
byte r = 0, g = 0, b = 0;
22+
if (c != 0) {
23+
r = (c & 0x01)*0x21 + ((c >> 1) & 0x01)*0x47 + ((c >> 2) & 0x01)*0x97;
24+
g = ((c >> 3) & 0x01)*0x21 + ((c >> 4) & 0x01)*0x47 + ((c >> 5) & 0x01)*0x97;
25+
b = ((c >> 6) & 0x01)*0x51 + ((c >> 7) & 0x01)*0xae;
26+
}
27+
colours[i].set(r, g, b);
28+
}
29+
};
30+
31+
class Display: public UTFTDisplay, public Memory::Device {
32+
public:
33+
Display(Memory &mem): Memory::Device(sizeof(_tiles)), _mem(mem) {}
34+
35+
virtual void operator=(byte b) { _set(_acc, b); }
36+
virtual operator byte() { return _tiles[_acc]; }
37+
38+
void begin();
39+
void update();
40+
41+
void set_sprite(int n, byte sx, byte sy);
42+
private:
43+
void _set(word a, byte b);
44+
void draw_tiles();
45+
void draw_tile(word addr, int x, int y);
46+
void draw_sprite_slice(palette_entry &p, byte *c, int o, int x, int y);
47+
48+
unsigned _xoff, _yoff;
49+
byte _tiles[2048];
50+
Memory &_mem;
51+
};
52+
53+
#endif

docs/PacmanEmulation.pdf

1.91 MB
Binary file not shown.

0 commit comments

Comments
 (0)