Anyone still coding the Commodore 64 (real or emulated)?

Coders forum. Discuss techniques, swap code snippets, ask for help etc. relating to all forms of software development.
User avatar
KlaxonCow
Baaaaaaa!
Baaaaaaa!
Posts: 8447
Joined: Fri Dec 13, 2002 3:46 am 0
Location: A large grassy field.

Re: Anyone still coding the Commodore 64 (real or emulated)?

Post by KlaxonCow »

Dio wrote:Spectrum was 3.5andabitMHz though, so it was still quite a bit faster.
Ah, yes, sorry, you're quite right about that.

I did actually know that but, for some odd reason, 2MHz got stuck in my brain. I think I'm confusing the Spectrum running nearly twice as fast as the C64 "in real terms", for it being twice the hertz. Maybe. Something like that.

Anyway, however it is that I managed to confuse myself over the numbers, the underlying point was that the Spectrum's CPU was actually faster than the C64, but what the C64 lacked in CPU was more than compensated for by the peripheral chips. Especially the SID - nothing came anywhere near Commodore's audio chips for a good long while.

And compared to "colour clash" monochrome character graphics and tinny little beep noises on the Spectrum, it might have had more "oomph" in its engine, but what could you really use it for, when the methods of output were so limited?

(If you know what I mean - I'm not trying to knock the Spectrum there, as it was a nice little machine. I suppose what I'm really saying is that it's a pain in the arse that Commodore didn't have the 3.5andabitMHz CPU instead, as it could have been exploited to good cosmetic effect, thanks to all the raster tricks you could play with the VIC-II. Getting more colours and sprites on-screen using FLI-like / multiplexing tricks. Having plenty of CPU left over, while doing all that, playing software-mixed samples and, well, you get the point, I'm sure. Commodore gave us very "exploitable" chips that extra CPU is very handy in ways beyond simply doing more floating point operations per second.)
"Words ought to be a little wild - for they are assaults of thought on the unthinking."
- John Maynard Keynes
Kronos

Re: Anyone still coding the Commodore 64 (real or emulated)?

Post by Kronos »

Thanks for all the advice, was quite suprised it got to the second page in one day :)

I should point out my Assembler skills are practically non existent, I mean I have done the most basic bit of assembler code you could possibly imagine after reading a [very slim] book (which I still have). I have no notion of interrupt coding yet, or rasters etc so this will be a bit of a slow startup for sure. Doing things like game logic could be interesting indeed as I think in BASIC but need to implement such conditions/loops in Assembler for the first time eek.

Also, it may indeed be the case that I need to do all the game characters via software, I don't think 8 sprites are enough mind. Collisions should be ok as unless the sprite is over colour zero then your dead so that's something. I could limit the baddies to 6 on screen at a time, but then still have them shooting at you. Hmmm this would be easier with just sprite dammit.

And thanks for the code samples to everyone contributing. I was going to try starting off on VICE just to test out some bits of assembler, which I will post the results of no matter how bad they turn out in a diary somewhere. Was a bit worried about critical timings but then will probably release it oneday as just a D64 or something anyway.
User avatar
tufty
Sheepie Whore
Sheepie Whore
Posts: 12525
Joined: Fri Jan 07, 2005 4:52 pm 0
Location: French Alps

Re: Anyone still coding the Commodore 64 (real or emulated)?

Post by tufty »

silent_unicorn wrote:Thanks for all the advice, was quite suprised it got to the second page in one day :)

I should point out my Assembler skills are practically non existent, I mean I have done the most basic bit of assembler code you could possibly imagine after reading a [very slim] book (which I still have).
Getting your head around the syntax and instruction set of the 6502 is easy. Getting your head around how to use it to full effect is something else entirely, and something best done whilst poring over other people's (hopefully commented) code[1]. Don't be afraid of the game loop stuff, that's the easy part, it's the bits you *really* need assembler for that need the most work.

6502.org is a good place for example code, too, the majority of their example code is "bite sized"...

Simon

[1] Doesn't necesarily need to be for your platform of choice, either, as long as it's the same processor and you know how to ignore the machine-specific parts, and don't assume because it's been published that it's necessarily the "best" or "only" way of solving a given problem.
"massive retard™", "full of shit™", "tiny bitch™", "retarted™", "a bit of a one trick pony™", "petty™", "simple minded idealistic twat™", "miserable humourless fucker™"
User avatar
Dio
Sheepie Whore
Sheepie Whore
Posts: 18887
Joined: Mon May 31, 2004 1:08 pm 0
Location: Newcastle UK

Re: Anyone still coding the Commodore 64 (real or emulated)?

Post by Dio »

KlaxonCow wrote:And compared to "colour clash" monochrome character graphics and tinny little beep noises on the Spectrum, it might have had more "oomph" in its engine, but what could you really use it for, when the methods of output were so limited?
See the aforementioned comment on Elite :). The C64 has other compromises instead of course - the horrible 160-wide resolution in multicolour modes probably being the worst, and of course because of the speed of the CPU it could only update around half as much of the display per frame. And, of course, it was twice as expensive.
what I'm really saying is that it's a pain in the arse that Commodore didn't have the 3.5andabitMHz CPU instead, as it could have been exploited to good cosmetic effect, thanks to all the raster tricks you could play with the VIC-II.
Well, it could have used a 2MHz 6502 like the BBC, but I suspect the reason was penny-pinching on the CPU and custom chips - they would both have had to be specced twice as fast (the BBC had to use an odd technique in which the CPU dynamically downclocked whenever it hit a custom chip).
User avatar
Dio
Sheepie Whore
Sheepie Whore
Posts: 18887
Joined: Mon May 31, 2004 1:08 pm 0
Location: Newcastle UK

Re: Anyone still coding the Commodore 64 (real or emulated)?

Post by Dio »

tufty wrote:[1] Doesn't necesarily need to be for your platform of choice, either, as long as it's the same processor and you know how to ignore the machine-specific parts, and don't assume because it's been published that it's necessarily the "best" or "only" way of solving a given problem.
There are several well-commented Atari VCS listings out there (Combat and Asteroids for two), and they're good study because they're both small (2K / 4K) and typically very tight because of the nature of the VCS hardware. Might require a bit of a readup on the Stella though.
User avatar
Istar
Baaaaaa!
Baaaaaa!
Posts: 4869
Joined: Mon Apr 22, 2002 4:42 pm 0
Location: London, UK.

Re: Anyone still coding the Commodore 64 (real or emulated)?

Post by Istar »

Agreed. For the 6502 newbie, the added complication of getting your head around cycle-perfect timing to ensure your vertical synch stays, well, synched ( :lol: ) could be a step too far to begin with.

Hell, I've been 6502-coding since 1982, and Stella-coding since 2004, and I still fuck it up sometimes. ;)

But the sheer unadulterated joy inherent in knowing your code is (a) controlling the electron gun, and (b) a working VCS program, is matchless.
User avatar
KlaxonCow
Baaaaaaa!
Baaaaaaa!
Posts: 8447
Joined: Fri Dec 13, 2002 3:46 am 0
Location: A large grassy field.

Re: Anyone still coding the Commodore 64 (real or emulated)?

Post by KlaxonCow »

Dio wrote:
KlaxonCow wrote:And compared to "colour clash" monochrome character graphics and tinny little beep noises on the Spectrum, it might have had more "oomph" in its engine, but what could you really use it for, when the methods of output were so limited?
See the aforementioned comment on Elite :). The C64 has other compromises instead of course - the horrible 160-wide resolution in multicolour modes probably being the worst, and of course because of the speed of the CPU it could only update around half as much of the display per frame. And, of course, it was twice as expensive.
what I'm really saying is that it's a pain in the arse that Commodore didn't have the 3.5andabitMHz CPU instead, as it could have been exploited to good cosmetic effect, thanks to all the raster tricks you could play with the VIC-II.
Well, it could have used a 2MHz 6502 like the BBC, but I suspect the reason was penny-pinching on the CPU and custom chips - they would both have had to be specced twice as fast (the BBC had to use an odd technique in which the CPU dynamically downclocked whenever it hit a custom chip).
Yes, I agree on all points.

Of course, the reason why it was the way it was, is because of the economics, as you mention, and Tramiel wanting to do the whole "cheap computing for the masses" thing - which, in the long run, was absolutely the right thing to do, in "for the benefit of the human race" terms - as upping the clock on the CPU would have meant upping the clock on everything else (or implementing some elaborate scheme to handle having the various components running at different speeds - as with the BBC's "downclocking" thing). All of which would just have inflated the price - possibly by a little too much that it falls outside the price range of the "target consumer" and you lose the market and all the rest of it.

I understand why. But it's just a programmer's lament to moan about the technical compromises. The "if only" considering how much better the graphics would have been if Commodore has chosen simply to use double the RAM in multicolour mode instead. Or, talking about playing samples, as we were, imagine if the SID had had 3 independent volume controls for each voice, instead of one overall volume control.

As a low-level programmer who likes to bend the metal, I'd have much preferred - from a technical perspective - a fast CPU and exposed hardware. You know, the Archimedes principle - "give me a place to stand, and I will move the Earth".

Sometimes, I'm actually pissed off with the hardware guys because they try to make this all singing and all dancing chip which has "helpers" here and clever built-in functions there. Fuck that - give me shitloads of fast Turing machines and I'll work out how to get them singing and dancing to the right tune.

Perhaps I was the only one but I was kind of annoyed by 3D graphics cards initially - dubbing them "Quake accelerators" - because they were just too "fire and forget" for my tastes (and calling them "3D accelerators" when they only accelerated textured mapped polygons but not voxels, not raytracing, etc. was a misnomer I didn't like much either - again, I understand that it's just "marketing" and none of this means I wouldn't make full use of them, but, still, it's technically a misnomer as far as I'm concerned).

I'm now warming back up to them since "shaders" were introduced and the buggers have become properly programmable. Although, I still would prefer it, if they were just an exposed array of coprocessors, with some nice built-in matrix and trigonometric instructions. Because then they could be equally useful to accelerate ray-tracing and voxels and other types of 3D. Heck, you could even "abuse" them and exploit their processing power for things besides graphics. I mean, in a sense, isn't it a bit stupidly wasteful to have hardware with such immense processing power sitting around doing much of nothing most of the time, just waiting for you to run a computer game?

Again, I do appreciate all the economic reasons that lay behind these things. But, to a programmer, the thought of shitloads of processing power just sitting there doing much of nothing most of the time - well, it's like dropping Casanova into "the harem of a thousand willing beauties" and then telling him "don't touch!". WTF?!? You have got to be kidding me! :lol: :wink:

The C64 was the machine that proves it.

You're not supposed to be able to play samples at all. Nor should you be able to have more than 8 sprites on-screen at once. Nor should it be capable of displaying more than so many colours in certain graphics modes. Commodore hardware is still unique in allowing the ability to actually display different graphics modes on the same screen simultaneously.

There are C64 demos which regularly feature the supposedly impossible. Such as bump mapping. On an 8-bit. And folks still keep trying to push it further all the time, nearly two decades after the damn thing should have died.

All made possible because the VIC's internals were exposed and a programmer could reach into it with the CPU and mess around with it. Because Commodore were very programmer-friendly, making much effort to supply manuals that taught programming and exposed nearly every nitty-gritty detail about the machine you could think of. And, you know, has any machine been "hacked" far beyond its stated "on paper" capabilities than the C64 has been?

Actually, as I write this, I just hit "preview" and can see Istar's comment about "controlling the electron gun". Yes, that's exactly it. Give me a superfast CPU and then access to the electron gun and access to the speaker cone. The less bullshit in the way, the better! :wink: :D
"Words ought to be a little wild - for they are assaults of thought on the unthinking."
- John Maynard Keynes
User avatar
Istar
Baaaaaa!
Baaaaaa!
Posts: 4869
Joined: Mon Apr 22, 2002 4:42 pm 0
Location: London, UK.

Re: Anyone still coding the Commodore 64 (real or emulated)?

Post by Istar »

KlaxonCow wrote:I mean, in a sense, isn't it a bit stupidly wasteful to have hardware with such immense processing power sitting around doing much of nothing most of the time, just waiting for you to run a computer game?
I'm sure I read (possibly linked from YY) about a project to open-up GPUs to general-purpose algorithmic problem solving. Someone help me out and repost the linky. ;)
KlaxonCow wrote:And, you know, has any machine been "hacked" far beyond its stated "on paper" capabilities than the C64 has been?
I'd have to say the ST comes close. Some of the stuff The Lost Boys, Carebears / The Union, and Inner Circle were doing with the YM and Shifter by the end of 1992 was simply staggering.

Also, looking at what 4Mat et al does with an unexpanded VIC20 these days is ... well, the word 'impossible' comes to mind. And yet there it is.
User avatar
tufty
Sheepie Whore
Sheepie Whore
Posts: 12525
Joined: Fri Jan 07, 2005 4:52 pm 0
Location: French Alps

Re: Anyone still coding the Commodore 64 (real or emulated)?

Post by tufty »

KlaxonCow wrote:Heck, you could even "abuse" them and exploit their processing power for things besides graphics.
You can

Simon
"massive retard™", "full of shit™", "tiny bitch™", "retarted™", "a bit of a one trick pony™", "petty™", "simple minded idealistic twat™", "miserable humourless fucker™"
User avatar
sack
Baaaaaaa!
Baaaaaaa!
Posts: 7077
Joined: Fri May 10, 2002 4:13 pm 0
XBL Gamertag: evilgopher
PSN: sixFiveOhTwo
Location: Rijswijk, The Netherlands
Contact:

Re: Anyone still coding the Commodore 64 (real or emulated)?

Post by sack »

I dunno... I think the C64 had a nice balance. The wheels weren't great by modern standards but at least you didn't have to reinvent them every time. It gave you a set of building blocks to play with and the rest was down to imagination and skill (something I hope to have one day :) ).

Had the C64 been stripped down to VCS levels it would've been inaccessible, thousands in the industry may not have had their start in computing and the C64 would've been nothing more than a footnote in history alongside the aquarius.
User avatar
Dio
Sheepie Whore
Sheepie Whore
Posts: 18887
Joined: Mon May 31, 2004 1:08 pm 0
Location: Newcastle UK

Re: Anyone still coding the Commodore 64 (real or emulated)?

Post by Dio »

KlaxonCow wrote:You're not supposed to be able to play samples at all. Nor should you be able to have more than 8 sprites on-screen at once. Nor should it be capable of displaying more than so many colours in certain graphics modes. Commodore hardware is still unique in allowing the ability to actually display different graphics modes on the same screen simultaneously.
ST could do multimode screens (although it did only have two to choose from) - The Pawn is a fairly early commercial ST game that does this, for example. I think the Atari 400/800 series could as well, and it had display lists to do it automatically rather than under interrupt control.

Actually from the reading I've been doing on the C64 the ST's video chip is reasonably similar in some of the ways you can abuse it (border removal, that sort of thing).

Looks like the C64 is much easier to emulate though because the timing's less flexible (scan lines aren't all the same length on the ST if you start really flipping the bits around).

And even a Spectrum could play samples ;). Badly.
User avatar
Istar
Baaaaaa!
Baaaaaa!
Posts: 4869
Joined: Mon Apr 22, 2002 4:42 pm 0
Location: London, UK.

Re: Anyone still coding the Commodore 64 (real or emulated)?

Post by Istar »

Dio wrote:Actually from the reading I've been doing on the C64 the ST's video chip is reasonably similar in some of the ways you can abuse it (border removal, that sort of thing).

Looks like the C64 is much easier to emulate though because the timing's less flexible (scan lines aren't all the same length on the ST if you start really flipping the bits around).
Yeah, both Shifter and VIC-I/VIC-II are highly complex and highly configurable instances of video interface logic, designed by different people but sharing the same objective - to translate a chunk of memory into a synchronised raster signal.

Not sure about your comment regarding the ST scan line length, unless you're referring to the mode-switch and [v|h]blank-sync techniques used to open the borders, and thus make each line longer in terms of addressable colour changes during the scan...?

But then, didn't the C64 do much the same with the FLI technique?

Note: how ironic it is that in both cases, the best exploitation of the capabilities of the graphics generator hardware came once the CPU could be synchronised to the electron gun position - exactly what the VCS does. The only difference is the fact that the 6502 can't do as many colour changes per scan as the 68000. 8)
User avatar
Dio
Sheepie Whore
Sheepie Whore
Posts: 18887
Joined: Mon May 31, 2004 1:08 pm 0
Location: Newcastle UK

Re: Anyone still coding the Commodore 64 (real or emulated)?

Post by Dio »

Istar wrote:Not sure about your comment regarding the ST scan line length, unless you're referring to the mode-switch and [v|h]blank-sync techniques used to open the borders, and thus make each line longer in terms of addressable colour changes during the scan...?
60Hz lines are 508 cycles, 50Hz lines are 512 cycles. It means I can't do a simple (cycle % cycles_per_line) to work out where the raster gun is at any one time - I have to process every register write and adjust the line lengths accordingly, and there's no fixed frame time either.
Note: how ironic it is that in both cases, the best exploitation of the capabilities of the graphics generator hardware came once the CPU could be synchronised to the electron gun position - exactly what the VCS does. The only difference is the fact that the 6502 can't do as many colour changes per scan as the 68000. 8)
The VCS has it relatively easy because of the WSYNC reg though. Although in theory stop #$2100 should be able to do the same on the ST, it doesn't quite work - there's a 12-cycle jitter, not to mention the pending issue.
User avatar
Istar
Baaaaaa!
Baaaaaa!
Posts: 4869
Joined: Mon Apr 22, 2002 4:42 pm 0
Location: London, UK.

Re: Anyone still coding the Commodore 64 (real or emulated)?

Post by Istar »

Dio wrote:60Hz lines are 508 cycles, 50Hz lines are 512 cycles. It means I can't do a simple (cycle % cycles_per_line) to work out where the raster gun is at any one time - I have to process every register write and adjust the line lengths accordingly, and there's no fixed frame time either.
Yah, from an emulation point of view it can be a bit of a bugger. But then I guess that's dependant on how your emulation core works; it sounds like you're emulating the observed behaviour of Shifter/Glue, rather than the actual logic...? Please excuse any evident ignorance, I'm new(ish) to full-system emulation, having slipped into it when getting a cycle-perfect 6502 core running for a completely different reason... ;)

The way my 6502 system works is to emulate the logic of the chip itself (including the incidental - and accidental - glitches in the instruction-decode logic giving rise to undocumented opcodes) and also, depending on the environment the 6502 is in, the logic of the support chips (e.g. VIC-I/VIA in the VIC20 configuration, ANTIC/POKEY in the 400/800 configuration, etc).

So far I'm finding that tying these individual emulations together is working - in the sense that these cores are running and doing their thing, and then I kind of incidentally get the CPU to read a set of instructions (just the Commodore Kernal ROM so far) to make things happen...
User avatar
Dio
Sheepie Whore
Sheepie Whore
Posts: 18887
Joined: Mon May 31, 2004 1:08 pm 0
Location: Newcastle UK

Re: Anyone still coding the Commodore 64 (real or emulated)?

Post by Dio »

I tried to do an 'exact' emulation of the shifter, but the timing turned into spaghetti too quickly - it wasn't going to be maintainable, and the internal documentation on the ST shifter is a bit limited too, which was going to be an issue as well in the longer run.

In the end, I got much cleaner and more accurate emulation by taking the line emulator I already had, making it flushable and patching it with special cases. The main reason I'd been looking at the frame video was because it was flushable and theoretically faster because it didn't need a per-line timer event (which in turn limits the maximum cycle count for a 68k run and so increases the bookkeeping overhead), but in the worst case it's not actually any better so I decided it didn't matter, and I was able to make the line emulator flushable.

It's still cycle accurate - before any register write to the video hardware I flush the video emulation to that cycle (which is second nature after I'd done some sound stuff - and got the VCS working, where everything has to be very precisely timed!).

I haven't gone down the internal logic route for the 6502 - I didn't know there was enough documentation of the instruction decode to make this possible (where did you get it?). At the moment I've not got any undocumented opcodes implemented, although I have the documentation on them.

The system is only partly cycle granular; the basic unit of work is the instruction, although the cycle count at which a custom chip receives a read or write or an event occurs is correct in any uniprocessor system. MultiCPU is a very different kettle of fish and I need to do some more work on that.

Again, once I've got it working I can make it flushable and that should keep the timing in order.
Post Reply