Previously I had only used my IRQHack64 to load files from the SD card. I now wanted to turn to the transfer functions, enabled by the 6 pins sticking out of the cartridge.
The transfer is something that potentially brings the cart to a whole new level. With this port it's possible to send a file over the serial and the C64 runs it automatically.
Just to make this clear, IRQHack64 is not a substitute for a C64 serial port, it doesn't connect a modem, internet or MIDI. Your PC communicates with the Arduino inside the cart, and the Arduino+EPROM work their magic with the C64.
But as the Arduino inside the cart is not limited by C64 hardware speeds, the files move at a nice 57600 rate, and they move over to C64 even faster.
I have postponed testing his because firstly I knew it would probably be a chore, as the IRQHack64 software is not very clearly documented. All the sources have been made available, but there's no overall comprehensive guide for what the cart is supposed to do and how.
Also, the Arduino code, the EPROM code and the irqhack64.prg need to have compatible versions or the cartridge likely won't work.
Connecting the PC to the cart using an FTDI board |
Converting the IRQHackSend
I used the IRQHack64Turbo project as a starting point for examining what the software is supposed to do. At least after compiling the Arduino source I get a working cartridge that plays nice with the current EPROM and the menu program.
The IRQHackSend in the Tools folder is a separate software for sending files from the PC end. It was simple enough to adapt to Processing.
The program opens a 57600 connection to the Arduino inside the IRQHack64, sends the "1" character which tells the Arduino at that end to start receiving. After this the Processing source sends the file length bytes, two header bytes and data bytes just as the original source does, with suitable delays here and there.
Immediately I got my software to talk with the cart, as the IRQHack transmits the menu and other responses over the serial. Using single character commands over the connection, the C64 can be reset with or without the cartridge, the cart menu software can be triggered remotely from the serial and so on. This remote control-reset was a nice bonus. So far so good.
However, using the file transfer mode was not a success, as the resulting bytes were often garbage. For a while I thought the serial transfer was to blame, and I spent hours messing around with the Arduino source.
The Obvious Solution
Umm, it turns out there is a speed toggle that apparently affects how the memory write works. The cart might have even have worked out of the box (not that it came with a box), but I could have changed that accidentally. The serial was not to blame at all, at least with these small file sizes.
The source seems to indicate it's possible to change the speed through the time-based button press interface using more than 5 seconds pressing. The source is also where I found this feature even exists.
I changed the Arduino source so I could send the speed toggle through a serial command, so I could be more sure that it has been received. After that, the serial-transferred files & memory writes started working!
Below is a Processing source for sending a file over to the IRQHack cartridge, using the FTDI board as a serial port.
import processing.serial.*;
Serial myPort;
void setup()
{
int port = -1;
for(int i=0;i<Serial.list().length;i++){
String stn = Serial.list()[i];
println (i+":"+stn);
if(stn.indexOf("USB0")>=0)port=i;
}
if(port>=0){
String portName = Serial.list()[port];
println (portName);
myPort = new Serial(this, portName, 57600);}
else{
println("NO USB found");
}
}
void waiter(int amount){
for(int i = 0;i<amount/10;i++){
if (myPort.available() > 0)print (char(myPort.read()));
delay(10);
}
}
void keyPressed(){
int k=key;
if(k=='1')send_file("myfile.prg"); // send this file
if(k=='r')myPort.write('3'); // reset c64
if(k=='c')myPort.write('4'); // reset c64 nocart
if(k=='d')myPort.write('2'); // enter dir menu remotely
}
void send_file(String fname)
{
myPort.write('1'); // "type" the Receive prog command at Irqhack's menu via serial
byte prgdata[] = loadBytes(fname);
waiter(250); // 250*10 millis, original delay(2500) millis
byte low = (byte)(prgdata.length % 256);
byte high = (byte)(prgdata.length / 256);
myPort.write((low)); // write length to receiving end
myPort.write((high));
for(int i=0;i<2;i++){ // write prg header
myPort.write(char(prgdata[i]));
if((i%32) == 0)delay(10);
}
for(int i=2;i<prgdata.length;i++){ // write actual data
myPort.write(char(prgdata[i]));
if((i%32) == 0)delay(10);
}
// we're done here
waiter(1000);
}
void draw()
{
if (myPort.available() > 0) print (char(myPort.read()));
}
The program reads all incoming characters and prints them on the console. Pressing '1' will send a file myfile.prg over the serial, if it exists. R and C keys resets the C64 and D makes the IRQhack enter the file selector menu. If there's no Arduino source change, there's no point sending a 'speed toggle' command.
Now that I already made the work on Processing, I modded the PETSCII editor to save & upload the exported prg through a keypress, so I can do PETSCII graphics on PC screen and experiment with results on the C64 screen.
After reducing the pre-delay in my sending routine to 250ms, it takes about a second to transmit the 2K PETSCII prg, so I can do it as often as I like. This was initially at 2000ms. It may be that different C64 units need a slightly different delay.
I've worked on it a bit more for my own setup. |
This is still a great improvement over the SD card switch-a-roo between PC and C64. This feels like a real professional Commodore 64 graphics workstation!
Not so fast
I came across problems when transferring some small scene demo and game programs that would normally run from the SD card. Although size is not the only cause, it seems larger files (20K+) are more likely to fail.
I have to stress there is no randomness here, trying to send the same file repeatedly does not help, nor do the small straightforward files really ever fail to send.
*
To extend my review of IRQHack64, I'd now say the serial transfer/remote features are a very nice addition to a developer's toolbox, but it doesn't add much value to a casual user or game player.
For the above purposes, sending simple & short files repeatedly, the cartridge transfer functions still performs fine. For longer files and demo/game collecting it is better to move them on the SD card anyway, from where they can be run more reliably.
The cart receives a file and run it, although it would be in some situations more useful to send memory areas to C64 without resetting or running any code, for example overwriting portions of the graphics memory. But, without changing the EPROM code this situation probably can't be changed.