Skip to content

Commit

Permalink
Fix Handle
Browse files Browse the repository at this point in the history
  • Loading branch information
reenigne committed Feb 21, 2012
1 parent ef9299d commit 7b98e44
Show file tree
Hide file tree
Showing 74 changed files with 1,305 additions and 1,118 deletions.
18 changes: 8 additions & 10 deletions 4to8/4to8.cpp
Expand Up @@ -2,18 +2,16 @@

int main()
{
File inFile("/t/projects/emulation/pc/ibm5150.net/f/fire/fire.ech");
FileHandle in(inFile);
in.openRead();
File outFile("fire.raw");
FileHandle out(outFile);
out.openWrite();
Array<Byte> four;
FileHandle in =
File("/t/projects/emulation/pc/ibm5150.net/f/fire/fire.ech").
openRead();
FileHandle out = File("fire.raw").openWrite();

int s = in.size();
four.allocate(s);
Array<Byte> four(s);
in.read(&four[0], s);
Array<Byte> eight;
eight.allocate(s*2);

Array<Byte> eight(s*2);
for (int i = 0; i < s; ++i) {
eight[i*2] = (four[i]>>4) * 0x11;
eight[i*2+1] = (four[i] & 0xf) * 0x11;
Expand Down
10 changes: 4 additions & 6 deletions 8088/8088.cpp
Expand Up @@ -769,7 +769,7 @@ typedef DisassemblerTemplate<void> Disassembler;
template<class T> class Intel8088Template : public Component
{
public:
Intel8088Template(Simulator* simulator, Handle* console, int stopAtCycle)
Intel8088Template(Simulator* simulator, int stopAtCycle)
: _flagsData(0x0002), // ?
_state(stateFetch),
_ip(0),
Expand All @@ -785,7 +785,6 @@ template<class T> class Intel8088Template : public Component
_abandonFetch(false),
_useIO(false),
_halted(false),
_console(console),
_wait(0),
_newInstruction(true),
_newIP(0),
Expand Down Expand Up @@ -904,7 +903,7 @@ template<class T> class Intel8088Template : public Component
}
line += _flags.text();
_newInstruction = false;
_console->write(line + "\n");
console.write(line + "\n");
++_cycle;
if (_halted || _cycle == _stopAtCycle)
_simulator->halt();
Expand Down Expand Up @@ -2992,7 +2991,6 @@ stateLoadD, stateLoadD, stateMisc, stateMisc};
int _rep;
bool _useIO;
bool _halted;
Handle* _console;
bool _newInstruction;
UInt16 _newIP;
ISA8BitBus* _bus;
Expand Down Expand Up @@ -3038,7 +3036,7 @@ class Program : public ProgramBase
void run()
{
if (_arguments.count() < 2) {
_console.write("Syntax: " + _arguments[0] +
console.write("Syntax: " + _arguments[0] +
" <config file name>\n");
return;
}
Expand Down Expand Up @@ -3101,7 +3099,7 @@ class Program : public ProgramBase
String stopSaveState = config.get<String>("stopSaveState");

Simulator simulator;
Intel8088 cpu(&simulator, &_console, stopAtCycle);
Intel8088 cpu(&simulator, stopAtCycle);
cpu.setBus(&bus);
simulator.addComponent(&bus);
simulator.addComponent(&cpu);
Expand Down
8 changes: 4 additions & 4 deletions 8088/arduino_keyboard/keyboard/keyboard.cpp
Expand Up @@ -4,9 +4,9 @@
class Program : public ProgramBase
{
public:
int run()
void run()
{
_com.set(CreateFile(
_com = Handle::Auto(CreateFile(
L"COM3",
GENERIC_READ | GENERIC_WRITE,
0, // must be opened with exclusive-access
Expand Down Expand Up @@ -56,7 +56,7 @@ class Program : public ProgramBase
KeyboardWindow window(kwp);

window.show(_nCmdShow);
return pumpMessages();
pumpMessages();
}
private:
template<class Base> class KeyboardWindow : public Base
Expand Down Expand Up @@ -219,5 +219,5 @@ class Program : public ProgramBase
_com.write<Byte>(value);
}

AutoHandle _com;
Handle _com;
};
14 changes: 7 additions & 7 deletions 8088/arduino_keyboard/run/run.cpp
Expand Up @@ -8,7 +8,7 @@ class Program : public ProgramBase
void run()
{
if (_arguments.count() == 1) {
_console.write("Usage: run [-c] <name of file to send>\n");
console.write("Usage: run [-c] <name of file to send>\n");
return;
}
int fileNameArgument = 1;
Expand All @@ -21,7 +21,7 @@ class Program : public ProgramBase
String data = File(fileName).contents();
int l = data.length();

_com.set(CreateFile(
_com = Handle::Auto(CreateFile(
L"COM3",
GENERIC_READ | GENERIC_WRITE,
0, // must be opened with exclusive-access
Expand Down Expand Up @@ -95,7 +95,7 @@ class Program : public ProgramBase
// When running a .com file, we need the instruction pointer to start
// at 0x100. We do this by prepending 0x100 NOP bytes at the beginning.
// In DOS this area would contain the Program Segment Prefix structure.
_console.write(hex(l) + "\n");
console.write(hex(l) + "\n");
Byte checkSum = 0;
if (comFile) {
addLength(l + 0x100);
Expand All @@ -110,13 +110,13 @@ class Program : public ProgramBase
addByte(data[i]); // Send data byte
checkSum += data[i];
if ((i & 0xff) == 0)
_console.write(".");
console.write(".");
}
addByte(checkSum);
flush();
IF_ZERO_THROW(FlushFileBuffers(_com));

_console.write("Upload complete.\n");
console.write("Upload complete.\n");
// Dump bytes from COM port to stdout until we receive ^Z
//thread.join();
}
Expand All @@ -136,7 +136,7 @@ class Program : public ProgramBase
c = _program->_com.tryReadByte();
if (c == 26 || c == -1)
break;
_program->_console.write<Byte>(c);
console.write<Byte>(c);
} while (true);
} while (c != 26);
}
Expand Down Expand Up @@ -180,7 +180,7 @@ class Program : public ProgramBase
_com.write<Byte>(value);
}

AutoHandle _com;
Handle _com;
Byte _buffer[0xff];
int _bufferCount;

Expand Down
17 changes: 9 additions & 8 deletions 8088/arduino_keyboard/send/send.cpp
Expand Up @@ -8,19 +8,19 @@ class Program : public ProgramBase
void run()
{
if (_arguments.count() == 1) {
_console.write("Usage: send <name of file to send>\n");
return;
console.write("Usage: send <name of file to send>\n");
return 0;
}
String fileName = _arguments[1];
String data = File(fileName).contents();
int l = data.length();
if (l > 0x400) {
_console.write("Error: " + fileName + " is " + l +
console.write("Error: " + fileName + " is " + l +
" bytes (must be less than 1024).\n");
return;
return 0;
}

_com.set(CreateFile(
_com = Handle::Auto(CreateFile(
L"COM3",
GENERIC_READ | GENERIC_WRITE,
0, // must be opened with exclusive-access
Expand Down Expand Up @@ -72,8 +72,9 @@ class Program : public ProgramBase
sendByte(l >> 8); // Send high byte of length
for (int i = 0; i < l; ++i)
sendByte(data[i]); // Send program byte
_console.write("Send complete.\n");
console.write("Send complete.\n");
thread.join();
return 0;
}
private:
class ReaderThread : public Thread
Expand All @@ -90,7 +91,7 @@ class Program : public ProgramBase
int c = _program->_com.read<Byte>();
if (c == 26)
break;
_program->_console.write<Byte>(c);
console.write<Byte>(c);
}
} while (true);
}
Expand All @@ -106,5 +107,5 @@ class Program : public ProgramBase
_com.write<Byte>(value);
}

AutoHandle _com;
Handle _com;
};
23 changes: 12 additions & 11 deletions 8088/demo/cga/attribute_clash/attribute_clash.cpp
Expand Up @@ -6,6 +6,7 @@
#include "alfe/thread.h"
#include "alfe/bitmap.h"
#include "alfe/config_file.h"
#include "alfe/bitmap_png.h"

typedef Vector3<int> YIQ;

Expand Down Expand Up @@ -124,8 +125,8 @@ class AttributeClashImage : public Image
private:
ColourSpace _c;
};
Bitmap<SRGB> srgbInputOriginal;
srgbInputOriginal.load(File(inputPictureFileName));
Bitmap<SRGB> srgbInputOriginal =
PNGFileFormat().load(inputPictureFileName);
Bitmap<Vector3<float> > linearInput(srgbInputOriginal.size());
srgbInputOriginal.convert(linearInput, ConvertSRGBToLinear());
Bitmap<Vector3<float> > linearScaled(_inputSize);
Expand Down Expand Up @@ -225,7 +226,7 @@ class AttributeClashImage : public Image
// _srgbOutput[p] = _srgbOutput[6];
// _perceptualOutput[p] = _colourSpace.fromSrgb(_srgbOutput[p]);
// Colour c;
// if ((Vector(x, y) - _compositeOffset).inside(_pictureSize)) {
// if ((Vector(x, y) - _compositeOffset).inside(_outputSize)) {
// c = _colourSpace.fromSrgb(SRGB(
// srgbRow[ip], srgbRow[ip + 1], srgbRow[ip + 2]));
// ip += 3;
Expand All @@ -238,8 +239,8 @@ class AttributeClashImage : public Image
// }
// }
//
// for (int y = 0; y < _pictureSize.y; ++y)
// for (int x = 0; x < _pictureSize.x; ++x) {
// for (int y = 0; y < _outputSize.y; ++y)
// for (int x = 0; x < _outputSize.x; ++x) {
// int col = (y/8)*40 + (x/16);
// int ch;
// int at;
Expand All @@ -259,7 +260,7 @@ class AttributeClashImage : public Image
// ++fg;
// at = fg + (bg << 4);
// }
// int o = (y*_pictureSize.x + x)/8;
// int o = (y*_outputSize.x + x)/8;
// _dataOutput[o*2] = ch;
// _dataOutput[o*2 + 1] = at;
// _position = Vector((x/8)*8, y);
Expand Down Expand Up @@ -579,7 +580,7 @@ class AttributeClashImage : public Image
// }
// }
// int character = _characters[bestPattern];
// int p = (_position.y*_pictureSize.x + _position.x)/(_hres ? 4 : 8);
// int p = (_position.y*_outputSize.x + _position.x)/(_hres ? 4 : 8);
// if (character != _dataOutput[p] || bestAt != _dataOutput[p + 1]) {
// _changed = true;
// _dataOutput[p] = character;
Expand Down Expand Up @@ -700,13 +701,13 @@ class AttributeClashImage : public Image
class Program : public ProgramBase
{
public:
int run()
void run()
{
if (_arguments.count() == 1) {
NullTerminatedWideString s
("Usage: attribute_clash <config file path>\n");
MessageBox(NULL, s, L"Error", MB_OK | MB_ICONERROR);
return 0;
return;
}

ConfigFile config;
Expand Down Expand Up @@ -735,7 +736,7 @@ class Program : public ProgramBase
config.addOption("inputPicture", Type::string);
config.addOption("outputNTSC", Type::string);
config.addOption("outputComposite", Type::string);
config.addOption("outputRGB", Type::string);
config.addOption("outputDigital", Type::string);
config.addOption("outputData", Type::string);
config.addOption("compositeTarget", Type::boolean);
config.addOption("hres", Type::boolean);
Expand All @@ -759,6 +760,6 @@ class Program : public ProgramBase
AnimatedWindow window(awp);

window.show(_nCmdShow);
return pumpMessages();
pumpMessages();
}
};
@@ -1,4 +1,4 @@
cgaRomFile = "/t/projects/emulation/pc/5788005.u33";
cgaRomFile = "/t/projects/emulation/pc/roms/5788005.u33";
inputPicture = "/t/colorful_rose_cropped.png";
outputNTSC = "/t/rose_hres_composite_50.ntsc";
outputComposite = "/t/rose_hres_composite_50.png";
Expand Down
2 changes: 1 addition & 1 deletion 8088/demo/cga/attribute_clash/rose_lres_composite.config
@@ -1,4 +1,4 @@
cgaRomFile = "/t/projects/emulation/pc/5788005.u33";
cgaRomFile = "/t/projects/emulation/pc/roms/5788005.u33";
inputPicture = "/t/pictures/reenigne/colorful_rose_cropped.png";
outputNTSC = "/t/rose_lres_composite.ntsc";
outputComposite = "/t/rose_lres_composite.png";
Expand Down
2 changes: 1 addition & 1 deletion 8088/demo/cga/attribute_clash/rose_lres_digital.config
@@ -1,4 +1,4 @@
cgaRomFile = "/t/projects/emulation/pc/5788005.u33";
cgaRomFile = "/t/projects/emulation/pc/roms/5788005.u33";
inputPicture = "/t/pictures/reenigne/colorful_rose_cropped.png";
outputNTSC = "/t/rose_lres_composite.ntsc";
outputComposite = "/t/rose_lres_composite.png";
Expand Down
3 changes: 1 addition & 2 deletions 8088/demo/cga/raster/raster.cpp
Expand Up @@ -7,7 +7,7 @@ int barColours[barWidth] = {4, 6, 14, 15, 11, 9, 1};
class Program : public ProgramBase
{
public:
int run()
void run()
{
int barY[nBars];
FILE* out = fopen("raster.raw", "wb");
Expand All @@ -20,6 +20,5 @@ class Program : public ProgramBase
}
}
fclose(out);
return 0;
}
};
12 changes: 6 additions & 6 deletions 8088/dos/bin_to_hex/bin_to_hex.cpp
Expand Up @@ -7,26 +7,26 @@ class Program : public ProgramBase
void run()
{
if (_arguments.count() == 1) {
_console.write("Usage: bin_to_hex <name of file>\n");
console.write("Usage: bin_to_hex <name of file>\n");
return;
}
String fileName = _arguments[1];
String data = File(fileName).contents();
int l = data.length();

// Write length bytes
_console.write(" .byte " + hex(l & 0xff, 2) + ", " + hex(l >> 8, 2) +
console.write(" .byte " + hex(l & 0xff, 2) + ", " + hex(l >> 8, 2) +
"\n");

for (int i = 0; i < l; ++i) {
int c = i & 7;
if (c == 0)
_console.write(" .byte ");
_console.write(hex(data[i], 2));
console.write(" .byte ");
console.write(hex(data[i], 2));
if (c < 7 && i < l - 1)
_console.write(", ");
console.write(", ");
else
_console.write("\n");
console.write("\n");
}
}
};
11 changes: 4 additions & 7 deletions 8088/hd/decode/decode.cpp
Expand Up @@ -4,14 +4,11 @@
class Program : public ProgramBase
{
public:
void run()
int run()
{
File input("capture.txt");
String inputData = input.contents();
FileHandle outputStatus(File("status.txt"));
outputStatus.openWrite();
FileHandle outputData(File("hd.dat"));
outputData.openWrite();
String inputData = File("capture.txt").contents();
FileHandle outputStatus = File("status.txt").openWrite();
FileHandle outputData = File("hd.dat").openWrite();
int i = 7*64 + 24;
int fails = 0;
do {
Expand Down

0 comments on commit 7b98e44

Please sign in to comment.