My dad used to work with you at Microsoft back in the day, and said you were smart when he recommend your channel. I think that was an understatement! Thanks for a great video. I bought your book this weekend and it should be arriving any day. Excited to give it a read!
FOUND IT! Line 59! At first, I thought your bit manipulation macro was the culprit, but I could find nothing wrong with it. I typed up you code in Turbo C 3.0 for DOS, and ran witrh much the same result as your own. I proceded to exchange your macro code for my own Turbo Pascal version, that does the same in reverse order, but that *also* was to no avail. (of course I ported the Turbo Pascal code). Now I could put the code into Visual Studo 2022, and here it ran *just* fine. THEN - as I spent WAY too many hours looking at the issue the wrong way around, I saved *all* the primes found by your code to disk, and the same for my correct 9592 primes from my Turbo Pascal implementation, and compared the result. Sure enough, a few primes was missing, but from strange places in between many others. I isolated the first prime as 3083 by help of my trusty UltraEdit 9.20b, and found that this was mmissing as currentFactor just hit 257 in value, and in line 107, this number is multiplied by itself, yielding 66,049 - just over the 65,536 limit of an UNSIGNED INTEGER on yours and mine platforms. This also explains why the code ran on Windows in Visual Studo 2022. Changing the declaration of currentFactor on line 59 from a uint to a ulong - ét voila! Thanks for the challenge and the opportunity for an old-school, these days much neglected code review!
XD when he said to find the bug and put it in the comments I knew I could count on the answer being there. Thank you for checking open source code for bugs.
It was a fun challenge to once again debug code like we did 30 years ago. However, I was, and am, convinced the bug was put there purposely, and would only be a bug on older machines. Never the less, it was a blast to try and remember how to check for errors the old way, and use my labs vintage equipment for just that. Monday was a day off where I live, and it was raining cats and dogs all day. Perfect for a challenge. Good times!
@@modrobert Just checked my Kernighan and Richie "The C Programming Language" rev. 1 from '78, and the *unsigned long* datatype is referenced multiple places with a 32 bit precision on the PDP-11, IBM 370 and Interdata 8/32. On the Honeywell 6000, the precision is 36 bits. On page 34, the book states: "The intent is that *short* and *long* should provide different lengths of integers where practical; *int* will normally reflect the most"natural" length for a particular machine. As you can see (ed: from the table of precisions on the page in the book), each compiler is free to interpret *short* and *long* as appropriate for its own hardware. About all you should count on is that *short* is no longer than *long*"
Nice work! I've written some code with CC65 for the Atari 8-bit computers and it is very cool to be able to write C for the 6502. 6502 assembly is fine but man does having a C compiler really take the edge off, especially when it comes to writing a decent sized program, it's night and day to have a decent high level language to work in. It really does open up a world possibilities for getting some useful work out of these older machines. Great to see a new target!
I still write a fair bit of 6502 assembler code, maintaining a 'monster' which is now almost 60k of hand written assembler. As it has to run from rom, and needs to take care of 3 different bank switching schemes (c128 mmu, cartridge/expansion rom and some 'private' cartridge ram), it would require a major overhaul of the c128 target for cc65 (which might be a good idea anyway, as its support for the c128 mmu is.. primitive).
@@HAGSLAB There is a new release pending, but have to finish some changes to the UI code, which I'm not really getting to. There are essentially 2 versions of it, and a derived diagnostics rom. One version is for use with the UII+ cartridge (this is also the most complete version, as it can make use of extra UII+ features for the C128), and a 'standalone' version. Its all based on a single source tree, just 3 different build targets (and the joys of keeping everything working with different features and memory layouts)
I found this a brilliant video Dave about porting CC65 to the KIM1. Thanks very much. I started coding in C (Hisoft-C) on the ZX Spectrum in 1984, before learning it at university after Pascal.
CC65 is great, I've used it for years on the Atari 8-bit and Lynx. I'm sure they will accept the beginnings of this target support in the project, and once in there, hopefully more people will take up filling it out. It's a community project (CC65) and relies on many people doing small improvements to the libraries. Unfortunately the main compiler/assembler/linker author retired from the project a while ago (Ulrich Bassewitz), so that side of the project hasn't had much support lately. It would be really great to see someone help out on that front!
Thanks for this, I've been looking at implementing CC65 for my homebrew 6502 for a while, but even using C64 as an example, I still couldn't quite work it out. Seeing the exact changes/additions you made in a pull request has given me new hope on my little project. You rule dude.
Always fun playing around with vintage computer hardware. You did a good job getting the CC65 compiler working on such an old machine. Some years ago I had a similar but not quite as involved project where I worked out how to get a GCC compiler running on an SGI IRIX computer. I documented the process and put it up on my website. I received feedback and questions from various places around the world. The biggest surprise came when I received a comment from a person working at Woods Hole Oceanographic Institution. I don't know if I still have that message as an older copy of my email program corrupted some of the folders containing saved mail.
It is so much more complex to understand how computers work today, love looking at these older machines where everything can be understood. Feel I missed out in the days when this was more possible…. not giving up my iPhone though. 🤪 Dave you are doing an awesome job educating me!!
My uncle got me into coding many moons ago. He used to have his Sinclair spectrum ZX81 managing his heating system! My tinkering has always been playing with graphics and games.
The Sinclair ZX Spectrum and the Sinclair ZX81 are two different computers. The ZX81 came out in 1981, and the ZX Spectrum in 1982. Main differences are the ZX81 only had 1K RAM (expandable to 16K with a "RAM Pack"), mono display with only upper case text and graphics character set, no sound, flat membrane keyboard. The ZX Spectrum had 16K/48K, colour, 256x192 graphics resolution, beeping speaker sound, rubber keys. Both computers used the Zilog Z80 processor.
@@satchice9102 indeed, I do recall. I was just excited when I typed that! Ha! He used the ZX81 to do the heating and also developed a couple of games we used to play. I had the ZX Spectrum 48k myself, then the 128+ with the drive, but managed to brick it with some experimental tinkering. That was an urgent setting summer!
Appreciate these back to basics deep dives. With 15+ years and kicking as a developer, it is always good to remind one self on what major building blocks one relies upon on a day to day basis. Keep the flow going Dave! :) //Returning viewer
My first C compiler on PC was the Mark Williams C Compiler. My first Unix Box was DUAL System 83/20 (Motorola MC 680000) running version 6 (latter version 7). My first PC-XT uses 2 boxes: the hard disk was in a separate box.
I don't remember what my first C compiler was, I tried out so many, but my favorite was definitely LCC. The lcc-win32 suite of tools that Jacob Navia wrote, expanding on the work that, of all sources, came from Microsoft Research, was great. If you use Windows you can actually still get it and a 64-bit version at that. These days I pretty much exclusively use GCC since I don't use Windows anymore.
That is fantastic to have a c compiler for Kim. Also showing how set up a board support package. This is the same as what you need for gcc. The connection to gcc makes this video very valuable. I should break out my board and give it a try. How much space does printf take? I setup gcc for the MCP555 and printf was taking around 12K. To do simple c++ I remember only having to provide new(). That can be really simple if you never plan to delete. Back in the day I got an assembler for and ran on Kim. I had one of those Don Lancaster TTY boards and two S-100 memory boards. I started a crude set of routines save data to a floppy. I was just happy to record something and abandoned it after getting my 6809 system working. That had OS9 with c and later color graphics. Anyhow, thanks for the video.
I was expecting a C compiler for the platform to be something ancient that used K&R C not the more familiar ANSI C. But an open source project no doubt is being used by the people who developed it so they'd want something more modern to work with.
Fun thing. Recently I've written a chess program for KIM-1 using 909 bytes for data and code segment. I did in 6502 assembler under my own online KIM-1 emulator, code also worked on a real KIM (btw tested by the guy you bought your KIM from). What is interesting now is to see whether cc65 would generate bigger or smaller code if I feed my C prototype into it.
cc65‘s malloc isn't the most efficient in the world, but then again 6502 machines aren't fast with lots of ram to manage anyhow. Also malloc and free aren't magical. I've implemented them myself in about 100 lines of C code total.
@@AbAb-th5qe It’s true, but some embedded projects (Rockbox comes to mind) don’t allow you to use a heap. There’s reasons there (multiple tenants in a constrained space) and I’ve done a fair bit of work with Rust’s no_std mode without an allocator. It’s interesting they bothered at all.
Awesome video Dave! I've been using CC65 a bit as well (I have a few videos on my channel) and I love to be able to use C to program my Commodore 64 (and my own C64 emulator). This walkthrough of adding a supported target is very interesting. I've had to poke around the cfg and crt0 files myself to get a program I wrote for the C64 compiled and linked into a binary compatible with the C64 cartridge format. I've burned that to a ROM and built a cartridge for my C64. Really ineteresting and fun learning experiment.
uC compilers remain limited in new features. These days, it is very easy to use all the latest features of e.g. c++2b. I find the c++ constexpr stuff especially helpful with microcontollers to automatically generate lookup tables. Just generate llvm code with clang (-emit-llvm) and then use the llvm c-backend (llvm-cbe) to generate simple c-code. This can then be compiled with any minimal c-compiler. This also has the advantage of using all the latest IR code optimizations of both clang and llvm, and the uC compiler essentially only needs to use a simple peephole optimizer for the final compilation step. Possibly only limited more advanced stuff as for-loop reversal.
In the late 1970s I could not find a compiler. In early 1980s I could only find a Compiler called Turbo Pascal 1.0 for about. 59.00. Other Compilers costed 1000s
Yeah, and isn't it great how in that regard things have gotten so much better. Now you can get dozens of compilers for free, thousands if you include every language.
@@DavesGarage Well, that puts the 'B' in bios for sure. Creating a buffering, dynamically auto repeating keyboard driver on a device that you could only poll and didn't have any hardware debounce was a learning curve back in the day. Course Old and wiser I bet You and I could do that in our sleep now.
Great video, one thing that sounded so off for me, was "Will be reading the source off Tape. I only used Tape on the big metal mainframes at work back in the day, my PC always had a hard drive, while my first computer i did splurged and got a floppy instead of a tape drive :) No HD at that time :)
So, I actually ran this on a few machines... On my Mac Pro 6,1 2013 ("TrashCan") with the 12-core Xeon ED5-2697 v2 @ 2.70Ghz, I got 70,813 iterations on an average of 5. This machine is running Windows 10 and Visual Studio 2022 On the Amiga 4000d with the Cyberstorm MKII 68060@50Mhz, the SAS Lattice 6 compiler got me 151 iterations *every* time I ran the test. Turbo C++ 3.0 in DOS on a Digital Venturis Pentium 200MMX workstation yielded 257 iterations on average. This puts the Amiga in a rather favorable light, Mhz to Mhz, but compiler optimations are surely at play also. Turbo C++ (all Borlands Turbo products actually) still amazes me with the DOS IDE; so many features and options, in so little a footprint. Lattice on Amiga is an awsome compiler put into context of the time, but the editor was and still is... less than stellar.
KIM-1? I was hacking Z80 assembly on my TRS-80 back then. Sadly, no C. I had an Apple I, but the my first C complier that I ran on a computer I owned was on the Kaypro under CP/M in 1982. This all made me a fan of Z80 and I never did much with 6502 or other Motorola assembly.
i recently came across your channel, i enjoy every bit of your antics and stories, i am the only person i know who still uses the old task manager to this day in my current daily OS driver, as long as it works i will continue using it over the new designs ;) quick question for you can you shade some light behind the scenes on MS adopting/embracing XML after it was obviously moot?
@@lucidmoses Believe it or not, I still occasionally use Watcom C in a commercial capacity, a real favourite for its tight accurate 16 bit DOS code. :-) But mention of MS C gives me nightmare flashbacks about v7(?) which used to complain entirely randomly 'No space left on device', an error which then magically disappears on the next compile!
hi Dave, thank you this video, I enjoyed it a lot! just one quesiton, why did you select CC65 instead of SDCC? It seems to me like SDCC has more optimizations available...
This may be wrong place to ask this, if so I apologize. I started following because of the Drag Race series (I thought it was really cool to see languages to head to head!) but I'm not sure where this stands. I looked at the Playlist but some of them have Drag Race and some don't. Is the series over? Is it a series that's gonna take a long time (like years) to complete? Are languages still being added and newer implementations of the tests being run? Where does python (my favorite language) place in all this (I know it's relatively slow). Just looking for an update on where all this stands. Thanks! :)
Hey dave: If are in silicon valley, there is somebody I can introduce that will likely be an interesting friend. Although historically he was an Apple employee.
Declaring variables before code reminds me of good old Turbo Pascal days :) The last language I did something substantial in was PHP - if I wanted to use a variable, I just used it without declaring (and wondered why my code is not working, since PHP will treat a typo in a variable as a new one :D)
And you'll need a header describing the offsets which need change. One of the first programs I encountered which implements this, and actually has the relocating code built-in, is Commodore's IEEE-488 driver for the C64 which came as rom with the interface, but would copy itself to ram, so it could move to the $c000 range, and provided a documented relocation function for when you wanted it somewhere else.
@@netdudeuk No, it uses a generic function which figures out where it currently is in memory, copies the code to the desired location, and uses a table with offsets in the code which need change. One little trick I learned from the code is how to have code detect on what address it is currently in ram (write a rts to a 'safe' location, jsr to it, and check the stack for the return address). And hence, it could relocate itself to arbitrary addresses.
Dear Dave - please kindly obtain an s-100 bus machine (like an 8800) and a 'Cromemco Dazzler' - because it's apparently the worlds first colour video adapter - and the freaking Altair can display bitmapped graphics (videos are here on youtube) - however, it lacks many good demos - I bet you could write a great one :P
Check the Western Design Center website - they have a variety of development tools for the '02 and '816, which includes assemblers and C compilers for the 6502 variants and the 65C816. I haven't used the C compiler, but there is documentation for it. You have to register with an email address to download the tools package but can only download once (?) with that email address, so save the download somewhere in case you ever replace your PC. The documentation on using the stuff in the package is marginal at best, but if you dig deep enough, you can use it.
CC65 is nice, to just write C code and it runs on 6502, but it produces bad code. The size of the "executable" is many times more what will be compared to the same in pure Asm. There are newer better alternatives, like KickC or llvm. If you know other languages, there are quite nice options. P65Pas (Pascal for 6502) produces quite optimized code. Prog8 is doing fantastic job.
Please, more cc65 exploration. It really does not matter which platform... ANY platform. :-). Most of the "cc65 community _documentation_" is actually lies within all the platform communities (apple2, C64 etc), who have stepped up to fill the vacuum left by the official project's ivory tower.
thx for the video. I'm thinking about getting back to my custom cpu and maybe add some ram to it... =D (would need the extra ram before I could implement a loader, and really wouldn't look forward to manually loading any machine language of more than 16 bytes, through the switches. ) have a great day!
I would literally die to be your neighbor and would gladly arrive with a cold 12 pack on Friday afternoons to spend hours in the shop learning software from you.
Apart from its name, I can't remember this thing... Maybe I was too busy mastering the Z80 and, after a while, playing with CP/M. Or I'm just getting old.
Please note that some idiots tries to pass for some UA-camr with some clouts to bring them on WhatsApp and scam them... So if you see a different UA-cam account trying to up you on WhatsApp, don't. Signal it as spam, and block the account.
I think because it is a well known algorithm with a known output, so it can be checked, and it is what Dave has been using in his Software language drag races. 🙂
So if I'm following this right cc65 compiles code for 6502 machines but it runs on Linux or windows, not 6502 machines. Am I the only one that thinks this is weird?
Nope. It is perfectly normal to have a powerful computer compile code for a smaller less powerful processor. That is how the majority of the low level programming is done. It is called cross compiling. The phone you are using did not compile its own code, a powerful X86_64 machine did, most probably running Linux. Most of the code running on microprocessors was compiled on x86 machines. Almost all the code for arm is cross compiled. The code running on your microwave, phone, fridge, washing machines, cars was written and compiled on X86 machines. Most processors aren't even powerful of running a compiler on them. They are severely limited in both RAM and ROM.
All these observations are true and I think nothing of building Arduino code on a windows laptop. But the part of me that's forever 12 years old and staying up half the night writing stupid programs on a commodore 64 hooked up to a black and white tv is really disappointed that this isn't the gateway to assembly language power without learning assembly language that I always hoped for.
My dad used to work with you at Microsoft back in the day, and said you were smart when he recommend your channel. I think that was an understatement! Thanks for a great video. I bought your book this weekend and it should be arriving any day. Excited to give it a read!
Just a sweet comment from an obviously awesome kid
Just tested it on my online KIM-1 emulator, works like a charm! Thank you so much for putting time and effort!
Two retro computers sitting next to a sink with running 💦, living on the edge Dave
FOUND IT! Line 59!
At first, I thought your bit manipulation macro was the culprit, but I could find nothing wrong with it. I typed up you code in Turbo C 3.0 for DOS, and ran witrh much the same result as your own. I proceded to exchange your macro code for my own Turbo Pascal version, that does the same in reverse order, but that *also* was to no avail. (of course I ported the Turbo Pascal code). Now I could put the code into Visual Studo 2022, and here it ran *just* fine.
THEN - as I spent WAY too many hours looking at the issue the wrong way around, I saved *all* the primes found by your code to disk, and the same for my correct 9592 primes from my Turbo Pascal implementation, and compared the result. Sure enough, a few primes was missing, but from strange places in between many others. I isolated the first prime as 3083 by help of my trusty UltraEdit 9.20b, and found that this was mmissing as currentFactor just hit 257 in value, and in line 107, this number is multiplied by itself, yielding 66,049 - just over the 65,536 limit of an UNSIGNED INTEGER on yours and mine platforms. This also explains why the code ran on Windows in Visual Studo 2022.
Changing the declaration of currentFactor on line 59 from a uint to a ulong - ét voila!
Thanks for the challenge and the opportunity for an old-school, these days much neglected code review!
XD when he said to find the bug and put it in the comments I knew I could count on the answer being there. Thank you for checking open source code for bugs.
It was a fun challenge to once again debug code like we did 30 years ago. However, I was, and am, convinced the bug was put there purposely, and would only be a bug on older machines. Never the less, it was a blast to try and remember how to check for errors the old way, and use my labs vintage equipment for just that. Monday was a day off where I live, and it was raining cats and dogs all day. Perfect for a challenge. Good times!
Does his C standard library code support ulong?
@@modrobert Just checked my Kernighan and Richie "The C Programming Language" rev. 1 from '78, and the *unsigned long* datatype is referenced multiple places with a 32 bit precision on the PDP-11, IBM 370 and Interdata 8/32. On the Honeywell 6000, the precision is 36 bits.
On page 34, the book states:
"The intent is that *short* and *long* should provide different lengths of integers where practical; *int* will normally reflect the most"natural" length for a particular machine. As you can see (ed: from the table of precisions on the page in the book), each compiler is free to interpret *short* and *long* as appropriate for its own hardware. About all you should count on is that *short* is no longer than *long*"
Nice work! I've written some code with CC65 for the Atari 8-bit computers and it is very cool to be able to write C for the 6502. 6502 assembly is fine but man does having a C compiler really take the edge off, especially when it comes to writing a decent sized program, it's night and day to have a decent high level language to work in. It really does open up a world possibilities for getting some useful work out of these older machines. Great to see a new target!
I still write a fair bit of 6502 assembler code, maintaining a 'monster' which is now almost 60k of hand written assembler. As it has to run from rom, and needs to take care of 3 different bank switching schemes (c128 mmu, cartridge/expansion rom and some 'private' cartridge ram), it would require a major overhaul of the c128 target for cc65 (which might be a good idea anyway, as its support for the c128 mmu is.. primitive).
@@c128stuff Now I'm really interested in knowing what this monster is and what it does 😅
@@HAGSLAB c128 device manager. Should be easy to find with google or such..
@@c128stuff Thank you for replying, I will check it out.
@@HAGSLAB There is a new release pending, but have to finish some changes to the UI code, which I'm not really getting to.
There are essentially 2 versions of it, and a derived diagnostics rom. One version is for use with the UII+ cartridge (this is also the most complete version, as it can make use of extra UII+ features for the C128), and a 'standalone' version.
Its all based on a single source tree, just 3 different build targets (and the joys of keeping everything working with different features and memory layouts)
This is great, I could watch you implement the rest of the standard library too! Thank you!
Don't they have a bunch of agnostic code for it?
I found this a brilliant video Dave about porting CC65 to the KIM1. Thanks very much. I started coding in C (Hisoft-C) on the ZX Spectrum in 1984, before learning it at university after Pascal.
I'm always fascinated by older equipment like this. I'm thoroughly amazed how much could be done on so little.
Great video Dave. So satisfying seeing old hardware still making magic
CC65 is great, I've used it for years on the Atari 8-bit and Lynx. I'm sure they will accept the beginnings of this target support in the project, and once in there, hopefully more people will take up filling it out. It's a community project (CC65) and relies on many people doing small improvements to the libraries. Unfortunately the main compiler/assembler/linker author retired from the project a while ago (Ulrich Bassewitz), so that side of the project hasn't had much support lately. It would be really great to see someone help out on that front!
This is pretty awesome - as in awe inspiring! Keep up the great work with this and thanks for sharing.
I understand hardly a word, but I liked every second.
Thanks for this, I've been looking at implementing CC65 for my homebrew 6502 for a while, but even using C64 as an example, I still couldn't quite work it out. Seeing the exact changes/additions you made in a pull request has given me new hope on my little project. You rule dude.
Always fun playing around with vintage computer hardware. You did a good job getting the CC65 compiler working on such an old machine. Some years ago I had a similar but not quite as involved project where I worked out how to get a GCC compiler running on an SGI IRIX computer. I documented the process and put it up on my website. I received feedback and questions from various places around the world. The biggest surprise came when I received a comment from a person working at Woods Hole Oceanographic Institution. I don't know if I still have that message as an older copy of my email program corrupted some of the folders containing saved mail.
It is so much more complex to understand how computers work today, love looking at these older machines where everything can be understood. Feel I missed out in the days when this was more possible…. not giving up my iPhone though. 🤪
Dave you are doing an awesome job educating me!!
Computers were definitely more fun when you could picture how it all worked in your mind and not as an overview.
love the cc65! congrats on the awesome contrib, bet someone will port some games to the kim with that setup... :-)
My uncle got me into coding many moons ago. He used to have his Sinclair spectrum ZX81 managing his heating system! My tinkering has always been playing with graphics and games.
The Sinclair ZX Spectrum and the Sinclair ZX81 are two different computers. The ZX81 came out in 1981, and the ZX Spectrum in 1982. Main differences are the ZX81 only had 1K RAM (expandable to 16K with a "RAM Pack"), mono display with only upper case text and graphics character set, no sound, flat membrane keyboard. The ZX Spectrum had 16K/48K, colour, 256x192 graphics resolution, beeping speaker sound, rubber keys. Both computers used the Zilog Z80 processor.
@@satchice9102 indeed, I do recall. I was just excited when I typed that! Ha! He used the ZX81 to do the heating and also developed a couple of games we used to play. I had the ZX Spectrum 48k myself, then the 128+ with the drive, but managed to brick it with some experimental tinkering. That was an urgent setting summer!
Appreciate these back to basics deep dives. With 15+ years and kicking as a developer, it is always good to remind one self on what major building blocks one relies upon on a day to day basis. Keep the flow going Dave! :)
//Returning viewer
Dave, bro this is insane. Lol I still loved every minute.
My first C compiler on PC was the Mark Williams C Compiler. My first Unix Box was DUAL System 83/20 (Motorola MC 680000) running version 6 (latter version 7). My first PC-XT uses 2 boxes: the hard disk was in a separate box.
I don't remember what my first C compiler was, I tried out so many, but my favorite was definitely LCC. The lcc-win32 suite of tools that Jacob Navia wrote, expanding on the work that, of all sources, came from Microsoft Research, was great. If you use Windows you can actually still get it and a 64-bit version at that. These days I pretty much exclusively use GCC since I don't use Windows anymore.
Memories from the old days. It was a beautiful time
Great vid again.. Ninja level!
Hope to see a breakdown of the compiler evolution, to LLVM and the CONIO implementation for MinGW/Dev-C++.
Love this channel - especially when there is code!
Great video Dave!
Thanks so much! i didnt know cc65 was a thing, now i'm going to have to try and get it to work on the BBC Master 128!
That is fantastic to have a c compiler for Kim. Also showing how set up a board support package. This is the same as what you need for gcc. The connection to gcc makes this video very valuable.
I should break out my board and give it a try. How much space does printf take? I setup gcc for the MCP555 and printf was taking around 12K.
To do simple c++ I remember only having to provide new(). That can be really simple if you never plan to delete.
Back in the day I got an assembler for and ran on Kim. I had one of those Don Lancaster TTY boards and two S-100 memory boards. I started a crude set of routines save data to a floppy. I was just happy to record something and abandoned it after getting my 6809 system working. That had OS9 with c and later color graphics.
Anyhow, thanks for the video.
Thanks for adding to CC65
You bet
Very interesting. My head hurts, but I found it really interesting! Thanks!
You sir, are an artist.
This was so facinating
never knew the kim had expansion cards, thought it was a trainer board. Used Aztec C on my Apple 2+ years ago. Having a hard disk really helped.
*Notice how dave didn't even make the CPU from discrete components. That maybe explains some of why there wasn't a search function in task manager...*
Absolute mad lad, I love it.
Awesome. Such a delight!
wow. deep dive stuff. love it. know enough to follow it without being able to do it.
I was expecting a C compiler for the platform to be something ancient that used K&R C not the more familiar ANSI C. But an open source project no doubt is being used by the people who developed it so they'd want something more modern to work with.
I started with an 8088 with MS DOS 2.0. Started programming with BASICA.
I do agree about static collections. I dont keep stuff unless i use it for something even if its testing hardware.
Fun thing. Recently I've written a chess program for KIM-1 using 909 bytes for data and code segment.
I did in 6502 assembler under my own online KIM-1 emulator, code also worked on a real KIM (btw tested by the
guy you bought your KIM from). What is interesting now is to see whether cc65 would generate bigger or smaller code if I feed my C prototype into it.
I’m kind of amazed CC65 supports a heap. I didn’t expect to see malloc() there at all.
cc65‘s malloc isn't the most efficient in the world, but then again 6502 machines aren't fast with lots of ram to manage anyhow. Also malloc and free aren't magical. I've implemented them myself in about 100 lines of C code total.
@@AbAb-th5qe It’s true, but some embedded projects (Rockbox comes to mind) don’t allow you to use a heap. There’s reasons there (multiple tenants in a constrained space) and I’ve done a fair bit of work with Rust’s no_std mode without an allocator. It’s interesting they bothered at all.
@@RandomInsano2 Well CC65 is a C compiler and those functions are specified as part of the C89 standard, so they're kind of required.
Awesome video Dave! I've been using CC65 a bit as well (I have a few videos on my channel) and I love to be able to use C to program my Commodore 64 (and my own C64 emulator). This walkthrough of adding a supported target is very interesting. I've had to poke around the cfg and crt0 files myself to get a program I wrote for the C64 compiled and linked into a binary compatible with the C64 cartridge format. I've burned that to a ROM and built a cartridge for my C64. Really ineteresting and fun learning experiment.
"Simple printf()" is quite the oxymoron 😂
uC compilers remain limited in new features. These days, it is very easy to use all the latest features of e.g. c++2b. I find the c++ constexpr stuff especially helpful with microcontollers to automatically generate lookup tables. Just generate llvm code with clang (-emit-llvm) and then use the llvm c-backend (llvm-cbe) to generate simple c-code. This can then be compiled with any minimal c-compiler. This also has the advantage of using all the latest IR code optimizations of both clang and llvm, and the uC compiler essentially only needs to use a simple peephole optimizer for the final compilation step. Possibly only limited more advanced stuff as for-loop reversal.
That VT220 is cleaner than the ones I used when they were new.
In the late 1970s I could not find a compiler. In early 1980s I could only find a Compiler called Turbo Pascal 1.0 for about. 59.00. Other Compilers costed 1000s
Yeah, and isn't it great how in that regard things have gotten so much better. Now you can get dozens of compilers for free, thousands if you include every language.
Back in the day we ported FORTH to a TRS-80. Was a bit more involved as we couldn't use many of the bios routines.
Well, the KIM only has about 4 bios routines in total!
@@DavesGarage Well, that puts the 'B' in bios for sure.
Creating a buffering, dynamically auto repeating keyboard driver on a device that you could only poll and didn't have any hardware debounce was a learning curve back in the day. Course Old and wiser I bet You and I could do that in our sleep now.
I heard you giggle @ "loadt and dumpt" 🤣
I hope your final episode on this is you getting it to run Doom!
Great video, one thing that sounded so off for me, was "Will be reading the source off Tape. I only used Tape on the big metal mainframes at work back in the day, my PC always had a hard drive, while my first computer i did splurged and got a floppy instead of a tape drive :) No HD at that time :)
The 65816 was a plug in upgrade for Apple 3. Any C compiler for 65816?
So, I actually ran this on a few machines...
On my Mac Pro 6,1 2013 ("TrashCan") with the 12-core Xeon ED5-2697 v2 @ 2.70Ghz, I got 70,813 iterations on an average of 5. This machine is running Windows 10 and Visual Studio 2022
On the Amiga 4000d with the Cyberstorm MKII 68060@50Mhz, the SAS Lattice 6 compiler got me 151 iterations *every* time I ran the test.
Turbo C++ 3.0 in DOS on a Digital Venturis Pentium 200MMX workstation yielded 257 iterations on average.
This puts the Amiga in a rather favorable light, Mhz to Mhz, but compiler optimations are surely at play also.
Turbo C++ (all Borlands Turbo products actually) still amazes me with the DOS IDE; so many features and options, in so little a footprint. Lattice on Amiga is an awsome compiler put into context of the time, but the editor was and still is... less than stellar.
What about gcc-6502 Toolchain should produce very fast machine code for the KIM.
KIM-1? I was hacking Z80 assembly on my TRS-80 back then. Sadly, no C. I had an Apple I, but the my first C complier that I ran on a computer I owned was on the Kaypro under CP/M in 1982. This all made me a fan of Z80 and I never did much with 6502 or other Motorola assembly.
i recently came across your channel, i enjoy every bit of your antics and stories, i am the only person i know who still uses the old task manager to this day in my current daily OS driver, as long as it works i will continue using it over the new designs ;)
quick question for you can you shade some light behind the scenes on MS adopting/embracing XML after it was obviously moot?
Used to use the lattice C compiler
Yes, I remember Lattice, Watcom, MS C, Turbo C. I don't know if anyone did it before them but that debugger in Turbo C was a game changer.
Me too! I still have the manuals, actually, in a box!
@@DavesGarage Is it just for x86 or can generate code for 68k and z80?
@@lucidmoses Believe it or not, I still occasionally use Watcom C in a commercial capacity, a real favourite for its tight accurate 16 bit DOS code. :-) But mention of MS C gives me nightmare flashbacks about v7(?) which used to complain entirely randomly 'No space left on device', an error which then magically disappears on the next compile!
DeSmet C compiler 🤣
hi Dave, thank you this video, I enjoyed it a lot! just one quesiton, why did you select CC65 instead of SDCC? It seems to me like SDCC has more optimizations available...
I'm not familiar with SDCC, I'll have to look into it!
Should make a kim-1 variant called OB-1.
This may be wrong place to ask this, if so I apologize. I started following because of the Drag Race series (I thought it was really cool to see languages to head to head!) but I'm not sure where this stands. I looked at the Playlist but some of them have Drag Race and some don't. Is the series over? Is it a series that's gonna take a long time (like years) to complete? Are languages still being added and newer implementations of the tests being run? Where does python (my favorite language) place in all this (I know it's relatively slow). Just looking for an update on where all this stands. Thanks! :)
Hey dave: If are in silicon valley, there is somebody I can introduce that will likely be an interesting friend. Although historically he was an Apple employee.
Why is dave seemingly often in the list when I search OCD level software engineering topics? Yes, subscribed...but still...
Declaring variables before code reminds me of good old Turbo Pascal days :) The last language I did something substantial in was PHP - if I wanted to use a variable, I just used it without declaring (and wondered why my code is not working, since PHP will treat a typo in a variable as a new one :D)
Check out Turbo Rascal (TRSE).
@@MattKasdorf I’ve seen it, but I found it a bit hard to use :) (and I forgot quite a bit of TP)
Super neat man
I love this stuff!!!
I was kidnapped before birth and made born on the wrong Country. You're making the experiments with computer I had dream; thank you
Very nice 👍!
You can do relocatable code for the 6502, but you'd need to write a relocating loader for the binary code of course.
And you'll need a header describing the offsets which need change. One of the first programs I encountered which implements this, and actually has the relocating code built-in, is Commodore's IEEE-488 driver for the C64 which came as rom with the interface, but would copy itself to ram, so it could move to the $c000 range, and provided a documented relocation function for when you wanted it somewhere else.
@@c128stuff Wouldn't they have pre-assembled the block of code that gets relocated to run at that address ?
@@netdudeuk No, it uses a generic function which figures out where it currently is in memory, copies the code to the desired location, and uses a table with offsets in the code which need change. One little trick I learned from the code is how to have code detect on what address it is currently in ram (write a rts to a 'safe' location, jsr to it, and check the stack for the return address).
And hence, it could relocate itself to arbitrary addresses.
@@c128stuff thanks for the explanation.
Self modifying code was a completely normal thing to do with the 6502.
I recall there was DECUS C for PDP-11. It was hell to try to port DECUS C to PC/MSDOS.
Do you mean C projects written in the DECUS C variant, or the compiler itself?
The square-root algorithm looks funnily simple. I always thought those have some more mathematical trickery behind them.
Dear Dave - please kindly obtain an s-100 bus machine (like an 8800) and a 'Cromemco Dazzler' - because it's apparently the worlds first colour video adapter - and the freaking Altair can display bitmapped graphics (videos are here on youtube) - however, it lacks many good demos - I bet you could write a great one :P
I have one of those. Never had much luck with the dazzler, though.
Related to CC65 for the 6502, is there any current C compiler available for the 65816 or the currently-produced W65C816?
Check the Western Design Center website - they have a variety of development tools for the '02 and '816, which includes assemblers and C compilers for the 6502 variants and the 65C816. I haven't used the C compiler, but there is documentation for it. You have to register with an email address to download the tools package but can only download once (?) with that email address, so save the download somewhere in case you ever replace your PC. The documentation on using the stuff in the package is marginal at best, but if you dig deep enough, you can use it.
That was fun!
hey guys be nice, he is here for the likes so push that button!!!
No implementation for humpt?
CC65 is nice, to just write C code and it runs on 6502, but it produces bad code. The size of the "executable" is many times more what will be compared to the same in pure Asm. There are newer better alternatives, like KickC or llvm. If you know other languages, there are quite nice options. P65Pas (Pascal for 6502) produces quite optimized code. Prog8 is doing fantastic job.
Please, more cc65 exploration. It really does not matter which platform... ANY platform. :-). Most of the "cc65 community _documentation_" is actually lies within all the platform communities (apple2, C64 etc), who have stepped up to fill the vacuum left by the official project's ivory tower.
How much power do those retro machines use --- like the one you use for clock ?
Lol, saving bytes. I would not have made it as a developer back in the day. Nowadays, we just spin up more containers.
Got it. Thanks. 🤣
Nice!
@4:20 .. no it isn't. Either that or I am also unconventional. Wsl2 is the best thing in Windows since pinball.
I think the main thing that makes it unconventional is the fact that he's using a Linux command line but then building the compiler for Windows.
Next up - a disk interface for the Kim-1? It has the PIA's so you should be able to interface it to a Pi or Arduino...
I grew up with DOS based IDEs then windows
thx for the video. I'm thinking about getting back to my custom cpu and maybe add some ram to it... =D (would need the extra ram before I could implement a loader, and really wouldn't look forward to manually loading any machine language of more than 16 bytes, through the switches. ) have a great day!
I guess you got the tint straightened out?
I would literally die to be your neighbor and would gladly arrive with a cold 12 pack on Friday afternoons to spend hours in the shop learning software from you.
I suspect your literal death would somewhat curtail your enjoyment of the beer and programming sessions...
More Dave, More better
Apart from its name, I can't remember this thing... Maybe I was too busy mastering the Z80 and, after a while, playing with CP/M. Or I'm just getting old.
Please note that some idiots tries to pass for some UA-camr with some clouts to bring them on WhatsApp and scam them...
So if you see a different UA-cam account trying to up you on WhatsApp, don't. Signal it as spam, and block the account.
6502 code can be written moveable, it just takes more effort.
Are you sure it's not some bad bits in memory, rather than a bug? Maybe there's some bits that have physically decayed and won't hold a '1' anymore.
Pretty sure. Also, bad memory tends to lead to varying results on each iteration
loadt dumpt sat on a wall
I have a lot of growing up to do
👍
It's hard to imagine programming before stack overflow.
Us old-timers call this "inheritance via Copy/Paste" :-)
@@stevejohnson1685 in *my* lab, mastering copy/paste is called a “Certification in Microsoft OLE2 with RPC-extensions”… 😆
Copypasta the sqrt function from Stack Overflow - proper modern coding transported to the 8-bit age!
Like!
Why the primes?
I think because it is a well known algorithm with a known output, so it can be checked, and it is what Dave has been using in his Software language drag races. 🙂
So if I'm following this right cc65 compiles code for 6502 machines but it runs on Linux or windows, not 6502 machines. Am I the only one that thinks this is weird?
Nope. It is perfectly normal to have a powerful computer compile code for a smaller less powerful processor. That is how the majority of the low level programming is done.
It is called cross compiling. The phone you are using did not compile its own code, a powerful X86_64 machine did, most probably running Linux.
Most of the code running on microprocessors was compiled on x86 machines. Almost all the code for arm is cross compiled.
The code running on your microwave, phone, fridge, washing machines, cars was written and compiled on X86 machines.
Most processors aren't even powerful of running a compiler on them. They are severely limited in both RAM and ROM.
Cross-compilation was nothing new even back in the days of the 6502. Microsoft used cross-assemblers.
Well, even if it could compile itself, would the binary fit in 64K?
@@DavesGarage C compilers that run do natively exist but I'm not sure any are C89... ;p
All these observations are true and I think nothing of building Arduino code on a windows laptop. But the part of me that's forever 12 years old and staying up half the night writing stupid programs on a commodore 64 hooked up to a black and white tv is really disappointed that this isn't the gateway to assembly language power without learning assembly language that I always hoped for.
I wish you can document your knowledge to videos
I thought that's kind of what I was doing! ;-)
@@DavesGarage sure is, just that I wish all your precious experiences can be fully recorded in the form of videos one day~ it is very interesting
C on an 8-bit platform
Can it run doom? Somehow? (Sorry).
@tripplefives
How?!
The commodore 64, ok you got that supercpu, but that would be choppy with some monochrome stuff.