News for hackers. Stuff that matters.
Re:C64 Power C Tutorial by phendrenad2 on Tuesday June 11, 2019 @01:52PM (#20157764)
There's something magical about writing code in C for these old 8-bit and 16-bit CPUs. You really feel like you're in control. You can inspect the assembly output and actually understand it. You can do inline assembler to optimize critical sections. 32-bit CPUs lose some of that magic, because the instructions sets are usually much more complex. However, RISC ISAs like RISC-V are still plenty of fun...
Re:C64 Power C Tutorial by 0815test on Tuesday June 11, 2019 @02:41PM (#20158276)
> There's something magical about writing code in C for these old 8-bit and 16-bit CPUs.

Eh, I'm not sure I would agree, about the 6502 specifically. It's a pretty bad match to C since e.g. it doesn't have a relocatable stack and common pointer-based operations are quite clunky despite the provision for several address modes. FORTRAN-like languages really do match quite a bit better. In a different way, so does FORTH.

Also, plenty of people did have fun writing assembly code for the MC68k, which is a 32-bit CISC architecture. It's really only x86 (and maybe VAX) that tends to be a bit clunkier.

Re:C64 Power C Tutorial by klodolph on Tuesday June 11, 2019 @02:52PM (#20158372)
Having written 6502 assembly but not targeted 6502 with C, I tentatively agree, but if you can fit your program in a 256 byte stack, things should be... mostly fine? Except for the fact that you want to do pointer indirections through the zero page. Clunky!

Personally if I'm going to have fun writing assembly for a project like this, I'm not too picky about the particular architecture.

Re:C64 Power C Tutorial by sehugg on Tuesday June 11, 2019 @07:00PM (#20160289)
The dominant C compiler (CC65) has a separate stack for parameters and local variables, and keeps SP as a pointer in zero-page. This is a nice general approach that allows for deep stacks, recursion, and lots of locals, but isn't very efficient.

Newer experimental 6502 languages either forbid recursion (cowgol) or limit parameters passed to functions (C02), but I can see a language using a hybrid of stack and zero page to keep locals and parameters.

The drawback of high-level programming on the 6502 is you are always looking for ways to make it better... :)

Re:C64 Power C Tutorial by ddingus on Tuesday June 11, 2019 @03:07PM (#20158509)
It is clunky, but the instructions are fast. Always thought that was an interesting trade off.
Re:C64 Power C Tutorial by klodolph on Tuesday June 11, 2019 @03:19PM (#20158631)
They’re fast, but you’re not using them well if you’re writing C, because the compiler is not good at putting things like local variables, function arguments, or globals in the zero page. It’s only 256 bytes and you can’t easily share.

So for 6502 I would rather not be writing C.

Re:C64 Power C Tutorial by ddingus on Wednesday June 12, 2019 @01:19PM (#20166993)
Nor would I.

Check out PLASMA. That is being used to develop the game lawless legends. It's pretty damn impressive.

Re:C64 Power C Tutorial by pjmlp on Tuesday June 11, 2019 @03:04PM (#20158481)
As someone that started coding back when those systems were modern, if you want to be in control learn Assembly.
Re:C64 Power C Tutorial by bane on Tuesday June 11, 2019 @11:29PM (#20161545)
IIR, C wasn't even available for most of these systems as they probably didn't have the local resources to compile their own code.
Re:C64 Power C Tutorial by pjmlp on Wednesday June 12, 2019 @01:12AM (#20161940)
On what concerns the Spectrum range, there were some pseudo C compilers that you could type in, but there were basically toys given the 48KB space.

With the 128KB +3A model you could use CP/M, which had a better compiler available, still a pseudo C toy compiler versus the real thing on UNIX.

We only used such compilers for homework assignments.

Re:C64 Power C Tutorial by AnimalMuppet on Tuesday June 11, 2019 @06:38PM (#20160143)
Kids these days. If you want real control, learn to move the patch cords. Otherwise, you're stuck with only one set of opcodes.

;-)

(No, I never worked on such a system... but my mother did.)

Re:C64 Power C Tutorial by leggomylibro on Tuesday June 11, 2019 @04:45PM (#20159360)
The MSP430 is a fun way to get back to that sort of simplicity with a fairly modern chip; it's a 16-bit processor with a focus on power efficiency. They've got a GCC toolchain and a port of the Processing IDE ('Arduino') called Energia:

https://energia.nu/

Also, some of the newer ones have small amounts of nonvolatile FRAM instead of separate SRAM and Flash banks.

Re:C64 Power C Tutorial by Koshkin on Tuesday June 11, 2019 @07:06PM (#20160325)
... and it is a lot more fun when the toolchain runs on the target itself. With microcontrollers it's hardly possible (but see RetroBSD), but not needing a workstation to service an otherwise self-contained little machine somehow feels special.
Re:C64 Power C Tutorial by tech2 on Tuesday June 11, 2019 @05:07PM (#20159552)
I found MIPS (R3000), SPARC, and MC68k about the right size for an ISA. Things like PIC (and similar microcontrollers) and older 8bit CPU like the 6502 and Z80 always felt a little limiting to me. I think those (MIPS etc.) were also a great point for higher-level (C, etc.) languages to be useful/interesting.

I guess each to their own though.

Re:C64 Power C Tutorial by vardump on Wednesday June 12, 2019 @02:01AM (#20162116)
> You can inspect the assembly output and actually understand it. You can do inline assembler to optimize critical sections. ...

You can really do this on any modern platform as well. It just takes a bit of effort. Understanding performance characteristics can be an order of magnitude harder, though.

Re:C64 Power C Tutorial by NikkiA on Tuesday June 11, 2019 @06:52PM (#20160228)
What OP is attempting to do is actually not really something that was done 'in the day'. By the time games developers were shifting from writing in ASM the idea of development 'on the hardware' was largely disappearing, and most dev studios had low-end minicomputers or (16-bit, mostly) workstations running cross-compilers or cross-assemblers. Most indie devs, of that era, were sticking with ASM - it didn't help that the native compilers were often outrageously expensive for an individual to purchase.

That said, I understand the allure of trying to work 'native', and it's a mistake/trap I often fall into myself.

Re:C64 Power C Tutorial by TazeTSchnitzel on Tuesday June 11, 2019 @03:43PM (#20158861)
The 6502 only has 66 extremely simple instructions, and it's slow enough C is a disadvantage and you would need to learn 6502 assembly to know how to write good C code anyway, so I don't see the point in avoiding it. I started writing a Famicom game for the fun of it, and the ISA is very easy to pick up because of it's so tiny and uncomplicated.
Re:C64 Power C Tutorial by jmull on Tuesday June 11, 2019 @04:31PM (#20159249)
Yes. But OP will learn (hopefully) and that's the fun of it.

Anyway, for the C64 many of your "APIs" -- especially for games -- are accessed by peeking and poking memory-mapped locations, careful usage of the zero-page, etc. C doesn't help you with that stuff but assembly loves it.

If you aren't in there counting cycles you are leaving so much on the table, and there just isn't that much table!

Re:C64 Power C Tutorial by wyld_one on Tuesday June 11, 2019 @07:35PM (#20160487)
Interesting, when you mentioned Power C I thought you meant this: http://www.mixsoftware.com/product/powerc.htm

The book for it was very nice as well. Best bang for the buck at the time. Could only compile code up to x286, not 386 CPUs

Re:C64 Power C Tutorial by djmips on Wednesday June 12, 2019 @02:05AM (#20162142)
Another thing to look at and try for the C64 is KickC. It's modern and being worked on. It's not true C and that's not it's intent. The intent is to produce efficient code for the 6502 and C64.

https://gitlab.com/camelot/kickc

Re:C64 Power C Tutorial by aidenn0 on Tuesday June 11, 2019 @05:08PM (#20159557)
Is this related to Mix Software's "Power C" for DOS? That was the first C compiler I ever used.
Re:C64 Power C Tutorial by NikkiA on Wednesday June 12, 2019 @07:23AM (#20163450)
Nope, this is ProLine's Power C, as seen here:

https://www.c64-wiki.com/wiki/Power_C

(the ALL CAPS code example with some really horrific variable and function names is a nice touch of the 80s)