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.
Kronos

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

Post by Kronos »

Coming back full circle.....does anyone still code on that old workhorse of an 8bit machine here? If you do what do you use (presumably in an emulator)?

The reason I ask this is there's a game that was never made for the C64 I really want to bring into the world once and for all. Whilst it isn't particularly complex or stressful on the old VIC=II chip it definately won't be possible in C64 basic without machine code hooks, and machine code is NOT something I am particularly good at (and that's even accounting for the fact I know all the C64 memory locations/registers needed thanks to the bare bones of a language called C64 Commodore Basic)

I was initially thinking of using Laser Basic/Basic Lightning to start with (I wrote something like GEOS Paint in Laser Basic with mouse pointer and pull down menus blah blah in my long lost youth in the late 80s) just because it would atleast give some quick results and inspire me to improve it/do it properly. However this package is as rare as rocking-horse shit encrusted in hen's teeth!!

Actually one part that is going to be very tricky for me is sample playback coding, but this I would like to include in the game for sure as it's in the Atari 5200 version of the game and the C64 can play samples nicely (I shall blissfully ignore the fact that I have no idea how to rip the samples from the coin-op OR the Atari .ATR images aswell as I type this)

Why do I want to do this almost impossible [for me] task? Erm....same reason some guy has spent 8 years coding up Space Harrier for the Atari XL/XE machines, it's a hole that needs to be plugged in the C64 catalogue :) I shall blog my pathetic attempts too for you all to laugh at my lameness! Any pointers appreciated. It's going to be machine code isn't it, I can feel it! Rats!

PS I'm not mentioning the game specifically because some half decent/ex coder will go away and write it in about 2 days probably and destroy my bid for limited immortality!!
User avatar
thalamus
Baaaaaaa!
Baaaaaaa!
Posts: 5325
Joined: Mon Jun 30, 2003 10:15 am 0
Yahoo Messenger: thelizard_uk@yahoo.com
Location: Canada
Contact:

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

Post by thalamus »

Muttley had a really nice little development environment set up, which allowed everything to be written and compiled on the PC then tested in an Emulator.

I'm sure he'll be along any moment now... :)

(Just don't ask him about his starfield...)
"We don't have a great war in our generation, or a great depression, but we do, we have a great war of the spirit. We have a great revolution against the culture. The great depression is ourlives. We have a spiritual depression." - Tyler Durden
User avatar
oktup
Baaaaa!
Baaaaa!
Posts: 1027
Joined: Tue Jan 21, 2003 1:44 am 0
Location: Cumbria
Contact:

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

Post by oktup »

If you're cross-compiling there are lots of choices. As a noob coder on the C64 I found the following pretty easy to work with ...
Editor: Crimson Editor
Assembler: DASM
Emulator: VICE
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 »

Yep, I use DASM and VICE for my VIC20 6502 coding antics.

And a custom-built bit of software/hardware to squirt code direct to the VIC or PET when I want to test on the real thing. A sort of 60Hz turboloader, if you will.

EDIT: Haven't seen Crimson before - is there a syntax file for 6502? Don't see one in the list...

EDIT2: Ah, AtariAge to the rescue. Some of the undocumented opcodes have the 'wrong' mnemonics, but that's an easy fix... :D
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 »

what oktup said on the software front - but don't get too hung up about learning assembler. after all - commodore basic 2.0 is so utterly shite it's pretty much got the usability of assembler with the speed of basic. It's not so much of a jump as you might think.

Plus the atari is 6502-based as well so possibly borrowing some of the game logic and recoding the display/sound/input stuff is an option (although for a first game it might just be easier to reprogram it). someone ported one of yaks games from the vic to the atari doing that recently...
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 »

Sort of.

I've done a lot of planning on scraps of paper for this original game idea I've had, and have been reading up on C64 documentation trying to work out how (or even if) I can squeeze it into the machine. But, as yet, I've not actually written anything.

Apparently, you can play 4-bit samples on the C64 by just rapidly changing the SID's volume (register 54296, bits 0-3, giving a volume from 0-15), because the SID chip makes this little clicking noise when you change volume. Although, this doesn't work as well on the newer 8580 SID chips, compared to the original 6581, as Commodore "corrected" the clicking noise a little, so the samples are quieter on the 8580 revision.

I say "apparently" because I've not got any further investigating this than writing a BASIC program that changes the SID volume as quickly as it can. This is not remotely good enough for samples, of course, as BASIC is much too slow. But I was able to get some funny sounds emitting out of the SID this way by just changing the volume in a loop, as a very basic "proof of concept".

If you want samples playing, then I think you'll have to bite the bullet and code at least the sample playing routine in assembly. The C64 has only a 1MHz CPU and there is no pipelining on it, so individual instructions take several clock cycles to run - basically, you really do need the speed that only coding to the metal gives you.

There are SID files out there which seem to play multiple samples simultaneously - I don't know if that's just software mixing (mind you, even if it is, with 4-bits of resolution and a 1MHz CPU, that's some mighty clever coding going on) or they've worked out a way to fire up samples on each individual channel or something.

Games that had samples originally had to stand stock still - do nothing else - while playing samples, because, basically, they took up all of the CPU's time to play. Later, though, samples seem to pop up in games and demos, where some stuff still seems to be going on while it's playing. I also don't know how exactly they are doing that either. I'm slightly afraid that possibly the only way to find out is to reverse engineer a SID tune that does it - although, obviously, it'd be a damn sight easier if someone who knows how that shit works just explained it.

I haven't looked into the SID much so far, though.
"Words ought to be a little wild - for they are assaults of thought on the unthinking."
- John Maynard Keynes
4mat
Posts: 18
Joined: Fri Sep 05, 2003 9:20 pm 0

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

Post by 4mat »

Here's a bit of simple sample playback code. This assumes the sample starts at $4000, ends
at $5000 and is in 4-bit format, with the top 4-bits of each byte also containing part of the sample. (so it'll
play byte1:lowbits,highbits.. byte2:lowbits,highbits etc.) It doesn't use timers or anything so
it'll stop whatever is happening while it plays. This probably only works on an old (6581) sid. I think
there's a way to do 'sid boost' on the 8580 by setting the channel pulsewidths or something like that.
Haven't really looked into how that works.

Anyway here's the code:

Code: Select all

sei
lda #$00 ; sample start address low bits
sta $30
lda #$40 ; sample start address high bits
sta $31
lda #$50 ; sample end address high bits. 
sta $32

ldy #$00

playsample

; Play low 4-bits of the byte on volume register.
lda ($30),y
and #$0f
sta $d418

; Bit of delay for pitch.
ldx #$12
pitchdelay1
dex
bpl pitchdelay1

; Play top 4-bits of the byte on volume register.
lda ($30),y
lsr
lsr
lsr
lsr
sta $d418

; Bit more delay
ldx #$12
pitchdelay2
dex
bpl pitchdelay2

iny
bne playsample

; Check if we've reached end of sample (in this case $5000)
inc $31
lda $31
cmp $32
bne playsample
cli
rts
User avatar
merman
Sheepie Whore
Sheepie Whore
Posts: 10943
Joined: Wed Feb 16, 2005 1:44 pm 0
XBL Gamertag: merman1974
Yahoo Messenger: andrewrfisher
Location: Skegness, England
Contact:

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

Post by merman »

Yeah, it's a technique called digiboost, there's a routine in one of the C= Hacking text files somewhere...
Twitter, Xbox, Wii U and Steam - merman1974
ZZAP is back - https://www.patreon.com/zzapmagazine
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 »

sack wrote:what oktup said on the software front - but don't get too hung up about learning assembler. after all - commodore basic 2.0 is so utterly shite it's pretty much got the usability of assembler with the speed of basic. It's not so much of a jump as you might think.
Yes. Microsoft originally wrote the C64's OS and BASIC, didn't they? Which goes a long way to explaining many things about the general shite-ness of it all - and adds a little irony, in that so many folks who are now Linux kernel hackers probably got into low-level coding, thanks to Microsoft.

I also think this is why Microsoft later got obsessed with sticking "Microsoft" in front of everything - Microsoft Windows, Microsoft Word, etc. - because they actually wrote a lot of BASIC interpreters and software for various computers that actually goes uncredited. By wedging the company name as officially part of the software's title, you force folks to give you credit and a free advert - which, fair play, is actually quite an amusingly clever strategy.

Anyway, yes, the difference between the C64's BASIC and using assembler is worryingly minimal in too many places. Pretty nearly everything dealing with hardware ends up being all PEEKs and POKEs to memory mapped registers - identical in usage to what you'd do in assembly code, but just slower. No "CLS", no "PRINT AT" or anything of that nature - half the keywords of other BASICs just ain't there.

So the BASIC offers you very little and then, simply, you've got a slow CPU (even the Spectrum was clocked at 2MHz, but the C64 is half that - the advanced peripheral chips like the SID and VIC did an awful lot of work in raising the C64, as, even at the time, the CPU was not too stellar or impressive by any means). And without kicking out the KERNAL (gotta love that Commodore spelling mistake, eh?) and BASIC, half the 64KB memory is gone. Hard enough getting a decent game to fit into 64KB, let alone half that.

Everything pretty much conspires to force you towards using assembly for all but the most basic (pardon the pun) of programs.

We've come a very long way since and it's perhaps a bit too easy to forget just how far we're talking. This thing is several thousandfold less than your typical modern PC in pretty much every department (mind you, it's also a testament to how much programming standards have fallen too - thanks to ever-increasing hardware allowing us to be, well, more "lazy" about things and say previously inconceivable things like "fuck optimisation" so casually and, more over, that such a statement is genuine economic reality, not just a way of dodging the bullet to avoid doing hard work - that what you see running on a C64 doesn't "look and feel" several thousandfold worse, all things considered).

But, at the same time, it's from a much simpler age. Technically, there are only "officially" 56 instructions, almost no registers (and, as memory runs about as fast as the CPU, this doesn't really matter much), etc. - so, yes, it's assembly, but it's as unintimidating as assembly is ever going to get.

So, I concur, the C64 BASIC is so shite, you gain effectively no advantage from using it. Your code ends up being a mess of PEEKs and POKEs and GOTOs everywhere - might as well go straight to using loads and stores and unconditional branches, as the BASIC programs end up really being perilously close to "assembly using a high-level syntax and line numbers".

Thus, gaining no real advantage from BASIC, just a series of disadvantages (and some nasty ones like having half the RAM eaten up and everything running slow as buggery on a CPU that ain't exactly the speediest in the first place), then, sorry, "resistance is futile" - bite the bullet and fire up the assembler. :wink: :D
"Words ought to be a little wild - for they are assaults of thought on the unthinking."
- John Maynard Keynes
User avatar
gravy
Sheepie Whore
Sheepie Whore
Posts: 19572
Joined: Wed May 01, 2002 1:28 pm 0
Location: The Other Place

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

Post by gravy »

KlaxonCow wrote:Games that had samples originally had to stand stock still - do nothing else - while playing samples, because, basically, they took up all of the CPU's time to play. Later, though, samples seem to pop up in games and demos, where some stuff still seems to be going on while it's playing. I also don't know how exactly they are doing that either. I'm slightly afraid that possibly the only way to find out is to reverse engineer a SID tune that does it - although, obviously, it'd be a damn sight easier if someone who knows how that shit works just explained it.
You can play samples off a high frequency 6526 timer interrupt 4 bits at a time. You do lose quite a bit of CPU time servicing the interrupts but you can still make a playable game with action happening on screen while you're playing a sample. It's not tricky stuff to be honest, there's a bit of skill in making your service routine as quick as possible.
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 »

gravy wrote:You can play samples off a high frequency 6522 timer interrupt 4 bits at a time. You do lose quite a bit of CPU time servicing the interrupts but you can still make a playable game with action happening on screen while you're playing a sample. It's not tricky stuff to be honest, there's a bit of skill in making your service routine as quick as possible.
Seems logical enough.

I suppose you can also trade it off against the sample rate, anyway. Lower quality samples wouldn't need the CPU as often - though, obviously, you pay a price in sound quality (but for something as inherently "white noise" as explosion / shooting sounds in a typical shooty game, you can get away with quite drastically lower quality samples more easily, I guess, as with sounds of that nature, the roughness of the playback can be hidden in the roughness of the sample itself. If you know what I mean. Samples were typically used for drums in SID music - a similar rationale, that drums usually have a bit of a "rough" sound to them anyway).

Although, on a slightly different subject, I've just fired up VICE - inspired by this thread - and wrote a BASIC program that clears the screen by POKEing spaces into video memory inside a FOR loop.

Oh. My. God. 8O

I know I've already pointed out how slow as buggery C64 BASIC was, but it's actually even worse than I remember it being.

Drastically worse. It takes about 7 seconds to clear the screen (measured using the highly precise "one elephant, two elephant" technique :wink:). 7 fucking whole seconds to POKE a space into 1,000 memory locations!

That's beyond dire. It's just plain useless.

I re-iterate the above advice of junking BASIC with even more conviction and no hesitation after witnessing that abysmal display. Shit, you couldn't even get a text only adventure or an ASCII Rogue-alike to run at an acceptable speed. Calling C64 BASIC "total shite" I now realise was actually being kind and generous to it.

There's no way in Hades you're going to get anything remotely resembling an "action game" running in BASIC.

Abandon it. Abandon it utterly. The sooner you get that crap out of the C64's RAM, the better. :twisted:
"Words ought to be a little wild - for they are assaults of thought on the unthinking."
- John Maynard Keynes
User avatar
oktup
Baaaaa!
Baaaaa!
Posts: 1027
Joined: Tue Jan 21, 2003 1:44 am 0
Location: Cumbria
Contact:

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

Post by oktup »

Well you wouldn't POKE the whole screen in BASIC to clear it. There is a character you use to clear the screen via the PRINT command ...

Image

The inverted heart is obtained via shift-home key on a PC keyboard in VICE.
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:you've got a slow CPU (even the Spectrum was clocked at 2MHz, but the C64 is half that
An early example of the megahertz myth. 6502@1Mhz ~= Z80@2Mhz, due to the way the instructions are implemented.

That said, assembler is *the* way to go. Machine Language For Beginners, originally published in 1983, may be of help

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
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 »

Spectrum was 3.5andabitMHz though, so it was still quite a bit faster.

Very much depends on the task though - 16-bit arithmetic should be significantly faster on the Z80, I'd have thought, as will things where the working set is about the same size as the Z80's register file.

The BBC's 2MHz 6502 was much more competitive. It's one reason why the C64 version of Elite is one of the poorest ports.
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 »

oktup wrote:Well you wouldn't POKE the whole screen in BASIC to clear it. There is a character you use to clear the screen via the PRINT command ...

Image

The inverted heart is obtained via shift-home key on a PC keyboard in VICE.
Yeah, I know. You can also do cursor movements and change colours in a similar way.

That's not really the point.

Okay, let me alter it slightly and say I wanted to fill the screen with the letter "A" instead rather than spaces. Or, ultimately, to POKE up background graphics for a platform game or whatever.

The point is that POKEing to video memory like that via BASIC is too intolerably slow to do anything that useful.

The fact that I was POKEing spaces in this instance, which clears the screen, was not meant to be all that relevant. But, yes, nevertheless, I probably didn't make that particularly clear.
"Words ought to be a little wild - for they are assaults of thought on the unthinking."
- John Maynard Keynes
Post Reply