Forum Rule: Always post complete source code & details to reproduce any issue!
Page 1 of 6 1 2 3 ... LastLast
Results 1 to 25 of 145

Thread: Commodore C64 Emulation on a Teensy 3.6 Microcontroller

  1. #1
    Moderator Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    4,347

    Commodore C64 Emulation on a Teensy 3.6 Microcontroller



    https://github.com/FrankBoesing/Teensy64

    Features



    • Supports Commodore Serial IEC Bus
    • For ILI9341 SPI Display
    • USB-Keyboards (wireless too)
    • 31kHz reSID Audio emulation
    • Audio Line-Out
    • Compatible to SD2IEC (real drives not tested so far)
    • Simple drive emulation included (load "whatever.prg" or load "$" )
    • Supports original joysticks
    • very small
    • Hotkeys (e.g. "LOAD "$":LIST)


    About
    Code:
     10 PRINT "HELLO WORLD";    
     20 GOTO 10
    Some time ago, 2015, someone in the PJRC forum asked me if it was possible to emulate the C64's SID chip on the Teensy 3.2. Since I had already had experience with the porting of audio codecs (mp3/aac/flac), I came up with the idea to search for a "finished" emulator and found the very good reSID. This is also used by VICE. The porting wasn't that difficult, but I've optimized some parts of it to better match the Teensy and its audio library. It is even possible to emulate a second reSID for stereo operation. Unfortunately, current reSID versions require a lot of RAM, so I had to switch to an older version - which is not necessarily worse. Soon the wish for a SID-Player came up and a little later the Teensy 3.6 was announced. With 256KB RAM, more than enough flash, SD slot and 180 MHz it seemed possible to emulate a complete C64. But before that, other hurdles had to be overcome. There was no way to control a display fast enough. However, the T3.6 has a fast SPI interface, which can be supplied via a DMA channel. The first display that crossed my mind was the well-known ILI9341, which had already done a good job for the T3.2. Some time before, a user in the forum had noticed that you can overclock its SPi interface drastically. After some attempts I had a working video player - even before the official release of Teensy 3.6. Paul Stoffregen thankfully provided me with an early pre-release version. After many preliminary considerations and deviations I came to the conclusion that the T3.6 should be capable of a C64 emulation. Unfortunately I forgot almost everything about the C64, and I had to and still have to learn everything anew and read a lot of technical details. I must admit that I have underestimated the VIC (the video chip of the C64) enormously. But that was a good thing, otherwise I would never have started this project. In the meantime I have rewritten the code for the VIC four times.

    In the beginning my goal was to make emulation good enough for "Boulder Dash" and other of my old favorite games. This goal has been achieved and I have the ambition to make some demos executable. "Teensy64" is compatible enough to play many games and other programs like the original. For the serial floppy interface the SID sound emulation has to be switched off during the accesses, because reSID requires a lot of computing time. Since the C64 operates this interface "in software" with the CPU and the signal lines have to be controlled more or less exactly in time, I couldn't find a way to keep the sound active even after many ideas and attempts. However, a 1541 floppy disk drive that had been bought extra second-hand was damaged after a short time. It was just too old. After some searching I found the "SD2IEC" project. It seems to be a good replacement and emulates the floppy drive wonderfully. SD2IEC can be connected to the interface of the board and works great. My plan is to port the SD2IEC software to Teensy 3.6 and integrate it into "Teensy64". I'm not sure if that's possible yet. There is also a way to work with the Teensy64 without an external drive. I patched the emulated ROM a little bit and misused the device ID 1. The following commands are available:


    • Load "$" - loads the directory (display as known with the command "LIST")
    • Load "whatever. prg" - Loads the program from the Teensy SD card.
    • Save "whatever. prg" - Saves the program.


    Other commands such as "open" are currently NOT supported for Device 1. Disk-Containers like "D64" are not supported by this simple patch.
    Access is ALWAYS made to a subdirectory "/C64/", which must be present on the SD card.

    Thanks to Bill Greiman for his SdFat library with long file names. The C64 was able to support file names of 16 characters length in the 80's when Microsoft only supported 8+3 characters.
    There are many more TODOs I would like to tackle little by little. The emulated VIC does not yet support the BA signal, and the emulated 6150 processor does not yet know it; -) Therefore there are some inaccuracies in the processor cycles. For example, the VIC can pause the processor or allow write access only. The latter has not yet been implemented. There's still work to be done on the internal timing of the sprites - so "Democoder"tricks like sprite stretching don't work. Also "xFLI" and "DMA Delay" is not yet possible. All things that the developers of the C64 didn't foresee at that time but were discovered by "hackers". Furthermore, only the PAL mode works satisfactorily - but this is only because I haven't found an NTSC program yet!

    Working "Demo VIC Tricks":

    - Open Borders (top/bottom)
    - FLD-Flexible Line Distance



    This project is "Open Source" and everyone is invited to work on it.


    Click image for larger version. 

Name:	board_v01.jpg 
Views:	95 
Size:	80.8 KB 
ID:	11457
    (Old Version of board with only one joystick port soldered)
    The board is exactly the size of the display.

    Defragster, thank you very much for your help.

    IEC Levelshifter:
    This boards uses one transitor and three resistors as bi-directional levelshifter - per line. It is not very fast (about 1.2uS on falling edge) , but fast enough for the C64. It needs a bit more power (mA) than the single 1k-resistors which Commodore used in ther devices. I read somewhere, that, normally, you can attach 8 devices to the bus. With this board, I wouldn't use more than 5-6.


    How to compile:
    Teensy64 needs some special settings:

    - F_CPU = 240MHz
    - F_BUS = 120MHz
    - AUDIO_BLOCK_SAMPLES=32

    Included is a file named "defs.h" that will do all the hard work you - if you replace the platform.txt of Arduino (latest 1.39) with the one which is attached to this post.
    It will not influence your other sketches, but is not tested with MAC-OS (see commented-out line in platform.txt - if you want to try on MAC-OS, activate it)
    If you don't want to use this solution, please ask the forum for help
    The following additional libraries are needed (copy them to your personal libraries folder)

    - Teensy-reSid
    - SdFat

    Done.


    Known issues:

    -
    Attached Files Attached Files
    Last edited by Frank B; 09-11-2017 at 10:32 PM.

  2. #2
    Moderator Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    4,347
    Please help me with this list !

    Tested:
    Working alternative Roms:


    • JiffyDos

    Working Apps:


    • SEABrowse


    Working Games:


    • Boulder Dash
    • Bruce Lee
    • Choplifter
    • Commando
    • Commando 95
    • Fort Apocalypse
    • Frogs
    • GORF
    • Galaga (b&w version)
    • Galaxian
    • Dig Dug
    • Donkey Kong
    • GhostBusters (problems with "Ghostbusters hahahaah" sample at the beginning)
    • Last Ninja, The
    • Loderunner
    • Madness (from IEC only)
    • Maniac Mansion (from IEC only)
    • Mario Bro
    • PAC-MAN
    • Paperboy
    • Paradroid
    • Parallax
    • Pole Position
    • Zaxxon

    [..]

    Not Working games:

    • Bubble Bobble (does not start - why ? Can a 64er expert help?)

    [..]

    Working Demos:
    • Delirious 9
    • Radwar Party 2017 Invitation

    [..]

    Not Working Demos:
    (List will be too long)



    Others are not tested so far.
    Last edited by Frank B; 11-05-2017 at 09:50 PM.

  3. #3
    Moderator Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    4,347
    Tips & Tricks

    - The emulation runs inside a interrupt, and you can interact with it. For example, you can access the emulated RAM and all registers of the virtual c64 machine in your loop():

    Code:
    Serial.print(cpu.RAM[0xBA]); //Displays last used device
    In the "extras" folder is a C64 Memorymap.


    - There is a command to send keystrokes to the C64. Example:
    Code:
    sendString("POKE 53280,3\r");
    Just add this as last line to your setup() and see what happens..
    Or "autoload" and run a program from the SD-Card:
    Code:
    sendString("LOAD\"DIGDUG.PRG\"\r:RUN\r");
    - there is a freeware C-Compiler for the C64. (I did'nt have time to test it..)

    - See https://www.c64-wiki.com for detailed information about the 64

    - want real retro-feeling ? In vic-palette.h you can select a black&white palette, or settings for a green-display. You can choose other palettes, too, or create your own.

    - You can use the Arduino serial console to send commands to the virtual C64

    - you can RESET with CTRL+ALT+DEL

    - 2017/10/30: Added Joystickport-swap with NUMLOCK
    - 2017/10/31: Added volume adjustment with CTRL-Right and Cursor UP/DOWN

    [..] to be continued
    Last edited by Frank B; 10-31-2017 at 07:26 PM.

  4. #4
    Moderator Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    4,347
    Click image for larger version. 

Name:	Teensy64_v03_top.jpg 
Views:	184 
Size:	296.4 KB 
ID:	11469
    (click to enlarge)

    How to build:
    Use a good, clean soldering iron with not too much Watt (power) - 30 Watt are ok. Don't solder longer than a few seconds per soldering joint - if you need too, let it cool down and try again.
    Solder the lowest/smallest parts first. First, the backlight-resistor, then the other 15 resistors. After that, the audio-connector and USB - then the pinheaders (Don't forget the USB-Host pins for the Teensy), transitors and the capacitor.
    You'll need a small side cutter to shorten the female pinheaders - make sure not to cut too much by mistake! Don't worry if you loose one pin - that's normal.
    Last step: solder the big Joystick-connectors and the IEC connector.

    Double/tripple check if everything is ok, remove tin solder rests and clean the board. If you have a magnifying glass, please check that there are no unintended shorts or cold joints.

    Don't forget to solder the USB Pins to your Teensy 3.6

    Also, please take a look here: https://www.pjrc.com/soldering-pins-on-to-your-teensy/
    Last edited by Frank B; 09-27-2017 at 08:34 PM.

  5. #5
    Moderator KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    3,074
    Board looks nice!

  6. #6
    Quote Originally Posted by KurtE View Post
    Board looks nice!
    And you can soon get one Kurt, work with Frank PCB's and most parts to build 10 of them on there way to me - and I'll place a DigiKey order tomorrow to complete the kits for US addresses.

    Easy to assemble and it works!

    Frank - Re post #1 - also need F_CPU=240 MHz since the IDE defaults to 180 and that fails the F_BUS at 120 MHz.
    How to compile:
    Teensy64 needs two Settings:

    - F_BUS = 120MHz
    - AUDIO_BLOCK_SAMPLES=32
    - F_CPU = 240MHz

  7. #7
    Moderator Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    4,347
    Thanks I've added this, and a short "How to compile".
    Does it make sense to add compiled hex-files to the repro (would mean some additional work for me with every update) ? Or is it easy enough to compile ?

  8. #8
    It compiled easily enough for me with your DEFS installer. But if you made a Version_HEX for each update you would be able to try prior versions if an anomaly came up? And if somebody can't get it to build & Run they would have a known good hex if the hardware is built and soldered right.

  9. #9
    Your solder directions look good. I saw a video recently where masking tape was used to keep the part in place. I got a bottle of 90% Isopropyl Alcohol and had good results with that. A clean old toothbrush to wet and wipe the area - rather than pouring on too much. Then I SAFELY get the board somewhat warm (from a distance at first) with a hair dryer to make sure there are no trapped pockets of liquid and quickly evaporate off any excess. Look for it to be clean and inspect. Of course I had one bad joint on USB - a nice shiny blob that was only on the pin and not mated to the PCB - DOH - worse was it worked on some devices so I assumed it was a software issue when it wasn't.

  10. #10
    Moderator Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    4,347
    Yeah, it happens a lot. I have also searched many times in the wrong place for an error

  11. #11
    Moderator Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    4,347
    Added improved keyboard-scan. This fixes some problems with games that scan the keyboard-matrix with swapped in/outputs (i.e. "PAC-MAN").
    "Bruce Lee" starts now - shows the "demo" perfectly- but crashes when start... hm - there must be an other reason I guess I need help with this game - any c64 specialists here ?
    Last edited by Frank B; 09-11-2017 at 10:55 PM.

  12. #12
    Moderator Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    4,347
    Ok.. let's start a little challenge

    EDIT: SOLVED. Challenge finished.

    The first one, who can tell me what _exactly_ the problem with "Bruce Lee" is, gets an FREE Teensy64 kit (Board v.03 + parts - except display and T3.6)
    (or get money back if you purchased one)
    You'll need a 6502 disassembler and some knowlage.. Your description must include enough information for me to fix the problem. It's a compatibility problem - might be easy to identify

    I hope someone finds it, and this way I have the time for other higher priority things...
    Last edited by Frank B; 10-08-2017 at 12:49 PM.

  13. #13
    Moderator Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    4,347
    VGA-Output (still experimental)

  14. #14
    Junior Member
    Join Date
    Sep 2017
    Posts
    1
    This looks great! Is there a link I can click on to order the kit?

  15. #15
    RalphW - Send a PM to Frank for details. I just got a set of PCB's in the US - going to assemble one tonight with the parts kits complete to mail to those interested in the working ILI9341 version. Will take pics of the parts and as I have it assembled to upload soon.

  16. #16
    I got parts to make a kit - it worked - here is what it looks like - more available - just PM FrankB:
    Click image for larger version. 

Name:	20170918_205818.jpg 
Views:	91 
Size:	113.2 KB 
ID:	11567 Click image for larger version. 

Name:	20170919_015203.jpg 
Views:	75 
Size:	145.2 KB 
ID:	11568
    Click image for larger version. 

Name:	20170919_015223.jpg 
Views:	57 
Size:	139.0 KB 
ID:	11569 Click image for larger version. 

Name:	20170919_015503.jpg 
Views:	71 
Size:	151.0 KB 
ID:	11570
    Click image for larger version. 

Name:	20170919_015950.jpg 
Views:	104 
Size:	103.8 KB 
ID:	11571 Click image for larger version. 

Name:	20170919_161823.jpg 
Views:	71 
Size:	131.8 KB 
ID:	11572

  17. #17
    Senior Member
    Join Date
    Jan 2013
    Location
    San Francisco Bay Area
    Posts
    631
    That's pretty remarkable stuff!

  18. #18
    Moderator Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    4,347
    Thank you, linuxgeek.

    I have a working VGA version on a breadboard - not with USB-HOST (flicker problems), but PS2 Keyboard connector.
    Looks great on a big screen. VGA-Refresh is 60Hz, emulated PAL is 50Hz - so, due to these different frequencies, in some situations may be a bit flickering visible (have not seen this so far).
    Still some work to do - the small TFT has no visible left/right borders, so they are not yet implemented for VGA. Then, new boards are needed - will take some time. I'll make a special price for those who ordered the TFT Version so far.
    The board will be useful for other VGA-Projects (or as T3.6 board with some 5V leveshifts), too.

    Some time ago I posted a video of a experimental version: https://forum.pjrc.com/threads/45916...l=1#post153615

    GitHub update for PS/2 & VGA follows in the next days.

    Good news: A user reported that loading programs from a original disk drive works.
    Last edited by Frank B; 09-27-2017 at 08:46 PM.

  19. #19
    Junior Member
    Join Date
    Apr 2017
    Posts
    6

    compiling C64

    I am slowly making progress in compiling C64 but I am now stuck. using 1.8.4 and 1.39 I getting error "getname" no member in patches.cpp.

    commenting out the offending lines to compile further gives me a "not static member error" . I have attached the ide verbose output
    Attached Files Attached Files

  20. #20
    Moderator Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    4,347
    Quote Originally Posted by ron2way View Post
    I am slowly making progress in compiling C64 but I am now stuck. using 1.8.4 and 1.39 I getting error "getname" no member in patches.cpp.

    commenting out the offending lines to compile further gives me a "not static member error" . I have attached the ide verbose output
    Hi, looks like Bill Greimans` SdFat is not installed (?)
    https://github.com/greiman/SdFat

  21. #21
    Junior Member
    Join Date
    Apr 2017
    Posts
    6
    the library manager shows 1.03 installed and I am able to compile the sdinfo in the examples folder with ide configured for teensy 3.6 without issues

  22. #22
    Moderator Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    4,347
    Hm. You're right, I havn't seen it in your logs. Can you try to remove the std SD-lib ?
    Well, this shouldn't be needed as it works for me, but the problem is definately a confusion with these libs.
    Unfortunately, the audio-lib wants SD.h and it is not easy to override this wihout editing the audio-lib or writing an own - I don't want this..
    This is the reason, i add a "SD.h" file to the teensy64 library - this seems not to work for you.

    @Defragster: You compiled it - did you have the same problem ?

  23. #23
    I'll have to check again - but I had no such problem when I updated the readme with my steps on Win 10

  24. #24
    Moderator Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    4,347

    New Price

    I've decided to lower the price for the kit. The new price is 29 USD or 25 EUR.
    Last edited by Frank B; 10-01-2017 at 03:27 PM.

  25. #25
    Junior Member
    Join Date
    Apr 2017
    Posts
    6

    Compiling C64

    I am now down to "ctags pattern are missing" issue. I have the same error now on windows 7 and ubuntu 15.10 64 bit machine.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •