An Exceptional BASIC Computer

BASIC

Since [Dan] has started using microcontrollers, he’s been absolutely fascinated by the fact these chips are essentially low performance computers. Once he caught wind of TinyBASIC, he decided he would have a go at creating a simple, tiny computer that’s very simple to the old, tiny, 8-bit computers of yore.

The computer is built on an Arduino shield, using TinyBASIC, the TVout library, and the PS/2 keyboard library. After piecing together a little bit of code, the Arduino IDE alerted [Dan] to the fact the TVout and PS/2 libraries were incompatible with each other. This inspired [Dan] to use the ATMega328P as a coprocessor running the TVout library, and using the capacious ATMega1284P as the home of TinyBASIC and the PS/2 library.

A circuit was put together in Fritzing using minimal components, and a PCB milled out of copper board. After the board was tinned, [Dan] had a beautiful minimalist retro computer with nearly 14kB of RAM free and an RCA display.

Future versions of the build will probably be based around the Arduino Mega, allowing for a TV resolution of 720×480. Also on tap are an SD card slot, LEDs, pots, and possibly even headers for I2C and SPI.

Comments

  1. Aztraph says:

    now all it needs is an audio in for a tape recorder to load a program, I believe I have an old version of prince of persia around here somewhere. Cool!

  2. thoriumbr says:

    He can write a x86 emulator in BASIC, and install DOS 1.0, and run Prince of Persia on top of that.
    I once saw a guy running Ubuntu on top of a Atmega168, so it’s feasible… And a monumental waste of time…

  3. James says:

    “Future versions of the build will probably be based around the Arduino Mega, allowing for a TV resolution of 720×480.”

    Hmm.. I doubt that. 720×480, even with 1 bit per pixel, would need about 42KB or RAM in the best case, when the Arduino Mega only has 4KB of SRAM.

    Worse, the horizontal resolution of 720 pixels would require a much faster CPU frequency than the 16MHz the Arduino Mega runs on.

    So, this is impossible without some kind of additional display circuitry.

    • James says:

      By the way, I’m talking about a framebuffer approach as used by TVOut. If you use some kind of custom tile-based system, you can lower the memory requirements, but you would still be limited by the 16MHz to create that 720px resolution.

      • Torque says:

        Well he could use two ATMega1284P’s, with one dedicated to TVOut duty while running at 20 Mhz with a external crystal.
        It’ll be a kludgy way of doing it and most likely also not increasing the resolution THAT much, but then he’d have a good reason to make it a single-board device.

        • James says:

          It won’t even get close: the TVOut library uses a resolution of 128×96: 720×480 would use roughly 28 times more memory, and need to run at around 100MHz.

          • cr0sh says:

            The thing is though, if he went with the 2560, he could expand the SRAM externally by quite a bit (Rugged Circuits sells such an expander, for instance) – easily enough for a larger frame buffer.

          • James says:

            But this makes no difference to the 16MHz speed limitation. My reason for starting that paragraph with “Worse, ..”

    • rj says:

      a “TV resolution of 720×480″ means 480i, and 720 pixels means BT.601 means 13.5MHz pixel clock. Totally doable.

      BUT interlacing a video source that doesn’t support at least 3-4bpp of luma to reduce flicker causes so much pain that IMNSHO it’s a waste of your time. Go with progressive scan, you’ll make everyone happier.

      • James says:

        Totally doable? With a 16MHz Arduino Mega: go try it then ;) I’m not sure you know what you’re talking about: you need a few (say 5 or 6) clock cycles per pixel, at least if you use the TVOut library, and if you roll your own it will be similar (imagine, you need an instruction to pull the pixel from memory, one to push it to the GPIO pin, and then some additional processing). So good luck :) There’s a reason the TVOut is limited to 128×96, and it’s not just memory (also speed).

        • rj says:

          I’ve already done 12 to 14MHz dot clocks on a PIC18: Surely an atmega would be as capable.
          Yeah, you’re not doing much else while you’re drawing it, and yes, you’ll need to replace the 16MHz clock source with a 13.5 MHz one. Those remain doable…

          But, yes, that’s not within whatever overhead the arduino environment imposes.

  4. lja says:

    The libraries were “incompatible”, so he used a whole second CPU instead of fixing the bugs in the existing libraries?

    • Trui says:

      I imagine the TVout library uses a lot of CPU cycles and places strict demands on the timing. Even if this could be combined with PS/2, it wouldn’t leave many CPU cycles for the BASIC interpreter. In that case, using a dedicated chip for TVout is probably a good idea.

      • lja says:

        Ah, I hadn’t thought about that one. Good point.

      • bleullama says:

        Similarly, TinyBasic (Plus) has very little spare room for your programs, let alone video display handling and PS2 support (although I wanted to add PS2 support at some point) (I am the one who turned TinyBasic into TinyBasicPlus, to add in better Arduino/AVR support.

        You may want to check out my other project, BLuB, https://github.com/BleuLlama/BLuB which was designed from the ground up to take as little footprint as possible. This lets it run with a decent amount of space even on an ATmega 168 part!

        • bleullama says:

          I have been working on my own TinyBasicPlus/BLuB based computer using a Commodore 64 keyboard for input, and a standalone display using a 1.8″ LCD. Writeup to come sooner or later… ;)

  5. gregkennedy says:

    Yeah, this is the first thing I thought of when I saw TVOut and PS/2 Arduino libraries. Good to see someone carry this over the goal line.

  6. Xark says:

    Very neat!

    You can actually do TVout and PS/2 keyboard read on one AVR chip. The trick is to use the AVR UART XCK external clock pin as PS/2 clock on the AVR8 chips (as opposed to bit-banging PS/2 with pin-change interrupt [bad with TVout]). Then you can read the PS/2 keyboard with the same chip scanning TVout (you poll for PS/2 key in HBLANK, very similar to how polledserial works with TVout). One bummer is that the XCK line is only brought out on Arduino Uno (it is not brought out on Arduino Mega 2560 or Leonardo/Micro [where it is used as "fake" serial LED]). Also, unless the chip has multiple UARTs, it can’t do serial and PS/2 keyboard at the same time (and I had to “flip a switch” to disable keyboard and allow bootloader upload via serial with 328p).

    Here is a picture http://imgur.com/a/JO4Cq where you can see I was typing (poorly) on PS/2 keyboard in the top screen (also re-wrote TVout for character graphics – better for low-memory systems like 328). I should polish this code up and release it…

  7. Osgeld says:

    if you look in on the google code for tv out there is a lib to use a ps2 keyboard on the com port using polling, I did it for my 1284 + tv out + tiny basic make up, works great

    http://code.google.com/p/arduino-tvout/issues/detail?id=38#c17

    if I ever get around finishing it I have TB mostly setup with all the drawing functions of TV out and SD card storage as well… come on weekend heh

  8. thoquz says:

    Check out the Tellymate shield (http://www.batsocks.co.uk/products/Other/TellyMate.htm)
    for TV display, the software and schematics are opensource.

  9. timbo says:

    The board looks sweet in all silver !

  10. Dan says:

    Hi guys, I’m Dan the creator of this shield and I have actually created a new BASIC computer based on a single ATmega 1284P and it has a RCA resolution of 720×480. This system is entirely stand alone and does not require an Arduino to work. It also allows the TVout library to work with a PS/2 keyboard (using a different PS/2 library). It can be found on Hackaday Projects here:

    http://hackaday.io/project/766

    • Xark says:

      Hmm, with your link I get “It seems that this project does not exist anymore”.

    • James says:

      720×480 straight from the 1284P? With 20MHz? I doubt it. No wonder the link is not working.

      • Dan says:

        Sorry about the link, I’m moving the project to instructables. After reading the comment by James (above) I am skeptical as to wether the TVout library is actually generating 720×480. I am starting TVout using the following:
        TV.begin(PAL, 720, 480);
        which works fine on both the 1284P and the Arduin Mega (it appears to require around 8KB for the video buffer). I do not have a TV which shows RCA resolution but one of them does show 576i PAL when I connect my single chip computer. If anyone would offer any information on this I would appreciate this.

        • James says:

          Hey Dan, thanks for clearing it up! So, setting it up like that (with x=720) does not mean it will actually render it that way, see the source:

          https://code.google.com/p/arduino-tvout/source/browse/video_gen.cpp

          The “render_setup” method is called with x = (720/8) (so your x input to the begin() method divided by 8). Based on the following calculation, your width is defined:

          unsigned char rmethod = (_TIME_ACTIVE*_CYCLES_PER_US)/(display.hres*8);

          With that value, it will choose one of the render methods (based on the number of cycles per pixel). So you can calculate the actual width in your case.

          • Dan says:

            Hi James, thank for your help explaining the TVout setup procedure :). I am running the 1284P at 16MHz so I will try to calculate the actual generated resolution.

          • Dan says:

            Hi James, I’ve also updated my instructable to inform readers it is not possible to generate the resolution of 720×480 using the Arduino mega.

  11. Sjamaan says:

    just use a DUE…

  12. vu2aeo says:

    That looks just superb!!

  13. Galane says:

    BASIC is an excellent tool for teaching algebra, especially the concept of variables. BASIC is an easy way to show students that algebra can actually *do stuff*.

    But except for the time in the 80’s and early 90’s when I wrote BASIC programs on CP/M and a TI-99/4A, I haven’t used algebra.

    • Greenaum says:

      True, writing BASIC since the first time I got my hands on a computer, around age 7, had me well prepped mentally for algebra. “Ah! It’s just like variables!”.

      That said, C’s style of evaluating things is more algebra-like than BASIC’s, variables in BASIC just sit there holding values, in algebra they imply values, and that implies doing some calculation.

      But yep, probably starting off kids with BASIC (or even LOGO to start off with) will give them a great start in maths, science, engineering, and especially computing. I’ve always felt like the master of any computer I’m in front of, not someone begging it for services the way Windows trains most people to feel.

      I think old-fashioned procedural BASIC probably has a place in education, even though it was only ever used for a few years in the early 80s, for most kids. Either get out the old 8-bits again, or create some simple dialect on a PC with things like sprites and sounds available as ordinary commands, so kids could produce something and feel powerful, help each other, and feel rewarded for gaining knowledge.

      The Atari ST and Amiga had STOS and AMOS in the early 90s. Some commercial games (and a whole lot of shareware) were written with those. They’re as I described, old-fashioned simple BASIC with sprite and sound functions. No messing around with longwords or memory addresses or any of the other C-style rubbish that found it’s way into later BASICs.

      Not that C-style stuff doesn’t have a place, but that place is in C.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 96,679 other followers