My favorites
▼
|
Sign in
chip8-emu
A Super CHIP 48 emulator written in C#.
Project hosting will be READ-ONLY
Wednesday at 8am PST
due to brief network maintenance.
Project Home
Downloads
Wiki
Issues
Source
Checkout
|
Browse
|
Changes
|
r33
r42›
Source path:
svn
/
branches
/
Sharp8
/
Sharp8
/
Src
/
Video
/
NewVideo.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
using System;
using System.Drawing;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using Core;
namespace Video
{
public class NewVideo
{
private Device device;
private PresentParameters pp;
bool deviceLost;
CustomVertex.TransformedTextured[] vertices;
Texture texture;
VertexBuffer vb;
//DateTime time_now, time_elapsed;
// TimeSpan time_span;
//int pos_x, pos_y;
uint[,] data;
public NewVideo()
{
}
public void Dispose()
{
if (vb != null)
{
vb.Dispose();
vertices = null;
}
if (texture != null)
{
texture.Dispose();
texture = null;
}
if (device != null)
{
device.Dispose();
device = null;
}
}
public bool Init(IntPtr hWnd)
{
pp = new PresentParameters();
pp.SwapEffect = SwapEffect.Discard;
pp.Windowed = true;
pp.PresentFlag = PresentFlag.LockableBackBuffer;
pp.PresentationInterval = PresentInterval.Immediate;
pp.BackBufferCount = 1;
pp.BackBufferHeight = 32;
pp.BackBufferWidth = 64;
try
{
device = new Device(0, DeviceType.Hardware, hWnd, CreateFlags.HardwareVertexProcessing, pp);
device.DeviceReset += new EventHandler(OnDeviceReset);
texture = new Texture(device, 512, 256, 0, Usage.Dynamic, Format.X8R8G8B8, Pool.Default);
return true;
}
catch(DirectXException)
{
return false;
}
}
public void AttemptRecovery()
{
try
{
if (texture != null)
{
texture.Dispose();
texture = null;
}
device.TestCooperativeLevel();
}
catch (DeviceLostException)
{
}
catch (DeviceNotResetException)
{
try
{
device.Reset(pp);
deviceLost = false;
}
catch (DeviceLostException)
{
}
}
}
public void OnDeviceReset(object sender, EventArgs e)
{
texture = new Texture(device, 512, 256, 0, Usage.Dynamic, Format.X8R8G8B8, Pool.Default);
SetupScreen();
}
public void SetupScreen()
{
vb = new VertexBuffer(typeof(CustomVertex.TransformedTextured), 6, device, Usage.WriteOnly, CustomVertex.TransformedTextured.Format, Pool.Managed);
vertices = new CustomVertex.TransformedTextured[6];
vertices[0] = new CustomVertex.TransformedTextured(new Vector4(0.0f, 0.0f, 0.0f, 1.0f), 0.0f, 0.0f);
vertices[1] = new CustomVertex.TransformedTextured(new Vector4(511.0f, 0.0f, 0.0f, 1.0f), 1.0f, 0.0f);
vertices[2] = new CustomVertex.TransformedTextured(new Vector4(0.0f, 255.0f - 28.0f, 0.0f, 1.0f), 0.0f, 1.0f);
vertices[3] = new CustomVertex.TransformedTextured(new Vector4(511.0f, 0.0f, 0.0f, 1.0f), 1.0f, 0.0f);
vertices[4] = new CustomVertex.TransformedTextured(new Vector4(511.0f, 255.0f - 28.0f, 0.0f, 1.0f), 1.0f, 1.0f);
vertices[5] = new CustomVertex.TransformedTextured(new Vector4(0.0f, 255.0f - 28.0f, 0.0f, 1.0f), 0.0f, 1.0f);
vb.SetData(vertices, 0, LockFlags.None);
}
public void ClearScreen()
{
for (int i = 0; i < 64; i++)
for (int j = 0; j < 32; j++)
SetPixel(i, j, (uint)Color.Black.ToArgb());
UnlockScreen();
}
public void Draw()
{
data = (uint[,])texture.LockRectangle(typeof(uint), 0, LockFlags.None, new int[] { 512 + 32, 256 });
SetPixel(0, 0, (uint)Color.White.ToArgb());
SetPixel(511, 0, (uint)Color.White.ToArgb());
SetPixel(0, 255, (uint)Color.White.ToArgb());
SetPixel(511, 255, (uint)Color.White.ToArgb());
texture.UnlockRectangle(0);
Render();
}
public void Render()
{
if (deviceLost)
{
AttemptRecovery();
}
if (deviceLost)
{
return;
}
if (device != null)
{
device.Clear(ClearFlags.Target, Color.Black, 1.0f, 0);
device.BeginScene();
device.SetTexture(0, texture);
device.VertexFormat = CustomVertex.TransformedTextured.Format;
device.SetStreamSource(0, vb, 0);
device.DrawPrimitives(PrimitiveType.TriangleList, 0, 2);
device.SetTexture(0, null);
device.EndScene();
//test_drawing();
}
try
{
device.Present();
}
catch (DeviceLostException)
{
deviceLost = true;
}
catch (DeviceNotResetException)
{
}
catch (Exception)
{
}
}
public void SetPixel(int x, int y, uint colour)
{
data[y, x] = colour;
}
public uint GetPixel(int x, int y) { return data[y,x]; }
public void LockScreen()
{
data = (uint[,])texture.LockRectangle(typeof(uint), 0, LockFlags.None, new int[] { 512, 256 });
}
public void UnlockScreen()
{
texture.UnlockRectangle(0);
}
}
}
Show details
Hide details
Change log
r33
by daxtsu on Apr 16, 2009
Diff
Added Sharp8 branch. C# chip8 emu branch. :P
Go to:
/branches/Sharp8
/branches/Sharp8/Sharp8
/branches/Sharp8/Sharp8.sln
/branches/Sharp8/Sharp8/Properties
...harp8/Properties/AssemblyInfo.cs
...Properties/Resources.Designer.cs
...Sharp8/Properties/Resources.resx
.../Properties/Settings.Designer.cs
...rp8/Properties/Settings.settings
...ches/Sharp8/Sharp8/Sharp8.csproj
/branches/Sharp8/Sharp8/Src
/branches/Sharp8/Sharp8/Src/About
...8/Src/About/AboutBox.Designer.cs
...rp8/Sharp8/Src/About/AboutBox.cs
...8/Sharp8/Src/About/AboutBox.resx
/branches/Sharp8/Sharp8/Src/Core
...es/Sharp8/Sharp8/Src/Core/CPU.cs
...nches/Sharp8/Sharp8/Src/Debugger
...rc/Debugger/Debugger.Designer.cs
.../Sharp8/Src/Debugger/Debugger.cs
...harp8/Src/Debugger/Debugger.resx
...s/Sharp8/Sharp8/Src/Disassembler
...c/Disassembler/C8_Interpreter.cs
...ler/DisassemblerForm.Designer.cs
...Disassembler/DisassemblerForm.cs
...sassembler/DisassemblerForm.resx
/branches/Sharp8/Sharp8/Src/Input
...Sharp8/Sharp8/Src/Input/Input.cs
/branches/Sharp8/Sharp8/Src/Main
...Sharp8/Src/Main/InterfaceForm.cs
...c/Main/InterfaceForm.designer.cs
...arp8/Src/Main/InterfaceForm.resx
...harp8/Sharp8/Src/Main/Program.cs
/branches/Sharp8/Sharp8/Src/Video
...rp8/Sharp8/Src/Video/NewVideo.cs
...Sharp8/Sharp8/Src/Video/Video.cs
/branches/Sharp8/Sharp8/app.config
Hide comments
Show comments
Project members,
sign in
to write a code review
Older revisions
All revisions of this file
File info
Size: 6261 bytes, 200 lines
View raw file
Hosted by