Author Topic: Useless but so mandatory: Tetris in a Digispark?  (Read 5730 times)

RC Navy

  • Jr. Member
  • **
  • Posts: 54
  • When you like, even too much, it is not enough!
Useless but so mandatory: Tetris in a Digispark?
« on: May 08, 2013, 01:42:54 pm »
Hi,

Since I'm still stuck for my current project (waiting for my 433MHz RF link modules), I decided as a playtime to make the port the famous vintage TETRIS game for arduino. For now, it works fine in a arduino UNO through serial port at 115200 bauds: the children love it!



The principle consists in using ANSI escape sequences to locate the caracters and to color them in an ANSI-capable terminal such as minicom (under Linux).It may be possible to use Teraterm (Windows), but I didn't tested it. This means the arduino only sends ASCII characters to the PC and only receives ASCII characters such as 'K', 'J', 'L' ... from the PC. So, operation is very basic.
The arduino is the heart of the Tetris game and the PC is the GUI (ANSI Terminal).

Now, my question for the USB experts: with the current USB implementation in the Digispark, is it possible to redirect the data stream in an ANSI terminal?
Or, shall it implement the USB CDC class in order to present to the PC a virtual serial port? Is it doable?
In fact, I don't know if Tetris will fit in the Digispark program memory. Thus, before working on size optimisation, I prefer to know if USB will be usable for this usage.
Or, is there another way to achieve this?

Thanks for your attention,

RC Navy.
« Last Edit: May 10, 2013, 03:48:56 am by RC Navy »

Bluebie

  • Sr. Member
  • ****
  • Posts: 486
Re: Useless but so mandatory: Tetris in a Digispark?
« Reply #1 on: May 09, 2013, 04:50:12 pm »
The ruby digiterm application provided by the digiusb rubygem does definitely support ansi - you just need to pass in the --raw option for now. Maybe it should detect escape sequences and automatically enable raw mode when they're encountered? I don't know if the digispark-provided C-based digiusb apps can do this. It would sure be interesting if there were a way to rig up a digiterm instance or anything else along those lines as a fake serial port that random software could use without noticing. I've thought it might work if the digiterm created a named pipe and connected that across, but I don't yet know what would happen when the software tries to configure that named pipe - setting baud rate and such. Does anyone know? can this be done without doing a kernel extension?


As for the other stuff, there's no reason the digispark couldn't implement the CDC protocol and expose a real USB serial port (it'd become a fake dialup modem essentially). The digispark is only a low speed device, so it cannot strictly comply with the USB spec, and their are doubtlessly some operating systems that would choke on it (I think more recent versions of windows can get a bit unhappy) but I don't really care about windows. I keep thinking I should make a digiserial library, but I've been busy with other things.





Bluebie

  • Sr. Member
  • ****
  • Posts: 486
Re: Useless but so mandatory: Tetris in a Digispark?
« Reply #2 on: May 09, 2013, 04:54:06 pm »
It looks like the 'socat' program in linux can bind a named pipe to a tty device, so that should make it fairly straight forward to implement. Interesting! Perhaps it would be possible to make a daemon which connects digisparks to named pipes for debugging and stuff on linux and mac!

RC Navy

  • Jr. Member
  • **
  • Posts: 54
  • When you like, even too much, it is not enough!
Re: Useless but so mandatory: Tetris in a Digispark?
« Reply #3 on: May 10, 2013, 04:21:30 am »
Hi Bluebie,
Quote
The ruby digiterm application provided by the digiusb rubygem does definitely support ansi - you just need to pass in the --raw option for now.
This does the trick! The X/Y location and the colors are working properly!

See screenshot below after invoking rubygem with the --raw switch:


Note: to properly display the rectangles, the terminal shall be set to use "Occidental IBM850" charset.

Extract of my test code:
Code: [Select]
int X, Y, Color;

    DigiUSB.print(F("\x1B["));DigiUSB.print(X);DigiUSB.print(F(";"));
    DigiUSB.print(Y);DigiUSB.print(F("H\x1B[3"));DigiUSB.print(Color%8);DigiUSB.print(F("m\xdB\xdB")); // %8 since ANSI Color goes from 0 to 7
    X++;Y++;Color++;

The ANSI escape sequences are described here: http://en.wikipedia.org/wiki/ANSI_escape_code

Now, I know it's technically doable. The only obstacle to port Tetris to Digispark is RAM and program memories of the Digispark! In last resort, I will use EEPROM to store constant strings....

Bluebie, many thanks for your help, and glad it gave you some other ideas with pipes and socat.

RC Navy.