GDR Forum Index
Podcast Podcast
Dev Dev Logs
Search Search
RSS RSS
Register Register
Log in Log in
Reply to topic GDR Forum Index -> Game Developer's Refuge -> The Commodore 64 (6502 and Friends) Page 1, 2, 3, 4  Next
View previous topic :: View next topic  
Author Message
PoV
Moderator

Joined: 21 Aug 2005
Posts: 10666
Location: Canadia
PostPosted: Fri Oct 31, 2014 9:54 am    Post subject: The Commodore 64 (6502 and Friends) Reply with quote


_________________
Mike Kasprzak
'eh whatever. I used to make AAA and Indie games | Ludum Dare | Blog | Tweetar


Edited by PoV on Fri Nov 28, 2014 7:30 pm; edited 1 time
View user's profile Send private message
0xDB
Developer

Joined: 26 Dec 2005
Posts: 1637
Location: Your consciousness.
PostPosted: Sat Nov 01, 2014 3:16 am    Post subject: Reply with quote

Watched, loved and stored for future reference.
_________________
0xDB
View user's profile Send private message Visit poster's website
Sirocco
Moderator

Joined: 19 Aug 2005
Posts: 9365
Location: Not Finland
PostPosted: Sat Nov 01, 2014 5:28 am    Post subject: Reply with quote

I'm still tempted to do a C64 intro... or something.
_________________
NoOP / Reyn Time -- The $ is screwing everyone these days. (0xDB)
View user's profile Send private message Visit poster's website
0xDB
Developer

Joined: 26 Dec 2005
Posts: 1637
Location: Your consciousness.
PostPosted: Sat Nov 01, 2014 5:47 am    Post subject: Reply with quote

An Introduction to Programming C-64 Demos

Same here. Wish I could split myself and work on multiple things at the same time.
_________________
0xDB
View user's profile Send private message Visit poster's website
0xDB
Developer

Joined: 26 Dec 2005
Posts: 1637
Location: Your consciousness.
PostPosted: Sat Nov 01, 2014 8:00 am    Post subject: Reply with quote

Preparations...

(replacement) machine:
VICE Emulator
(can also create empty .d64 disk image files and has a fancy c1541 commandline utility to write the .prg output from cc65 (or any file) to a disk image)

programming tools:
Turbo Assembler
cc65 (6502 C compiler) (used to write PETSCII paint 0.5 (0.4 was written in BASIC))

programming docs:
Project 64 (memory maps, service manual, prog refs, etc.) (that info was invaluable throughout the creation of PETSCII paint)

...armed with these, following the aforelinked Intro To Programming C-64 Demos should be a walk in the park.
_________________
0xDB
View user's profile Send private message Visit poster's website
PoV
Moderator

Joined: 21 Aug 2005
Posts: 10666
Location: Canadia
PostPosted: Sat Nov 01, 2014 9:12 am    Post subject: Reply with quote

Good ol cc65. I used to use a variant of SDCC for GameBoy development (and a straight-up assembler too), but at the time it was a buggy.

http://sdcc.sourceforge.net/

I've wanted to try cc65 for years, since it targets both the C64 and NES. That's the one nice thing: both systems have the same CPU.

I still think its kinda unfortunate they never added SNES support (6502 with 24bit addressing), but I guess the 6502 had a wide enough family of devices to be 'enough work'.

http://code.google.com/p/snes-sdk/

This guy used to make the BEST emulator/debuggers:

http://problemkaputt.de/

He still releases DOS ports, the maniac.
_________________
Mike Kasprzak
'eh whatever. I used to make AAA and Indie games | Ludum Dare | Blog | Tweetar
View user's profile Send private message
0xDB
Developer

Joined: 26 Dec 2005
Posts: 1637
Location: Your consciousness.
PostPosted: Sat Nov 01, 2014 11:53 am    Post subject: Reply with quote

The problemkaputt URL looks very familiar... (yeah... visited that recently when I looked up info on the PPU in the NES for the NESlike palette generator in Refugee Lib).

Just wrote my first C64 assembly-language program (then used cc65 to turn it into an executable).

The first obstacle I stumbled upon was that the "Intro To..." page linked earlier did not explain how to turn the assembly language code into an executable which the C64(or emulator) could run from BASIC, by typeing "RUN" as usual instead of having to type SYS <startadress>.

For "RUN" to work as usual, one has to add a little stub code to the assembly language program which will create the BASIC "10 SYS <startadress>" code at the beginning of itself.

This can be complicated ( http://www.pouet.net/topic.php?which=6541 ) or easy ( http://www.cc65.org/snapshot-doc/c64-4.html ).

I opted for the easy way and used cc65.

Putting my step by step instructions(for a Windows environment) here for anyone interested and for myself for next week or next month when I will have forgotten all this stuff again:

1.) grabbed cc65 snapshot (from http://sourceforge.net/projects/cc65/ )
(was already a bit hard to find as most of the links on cc65.org seem broken)

2.) extracted the snapshot zip to some dir (refered to as "C:/CC65/" here)

3.) created a batch file "setenv.bat" containing these lines:
Code:
set CC65_INC=C:/CC65/include/
set LD65_LIB=C:/CC65/lib/
set LD65_CFG=C:/CC65/cfg/
set PATH=%PATH%;"C:\CC65\bin\";

4.) created a folder for development files (refered to as "C:/mysrc/" here)
and placed the "setenv.bat" into that folder.

5.) created another batch file "asm2prg.bat" in my src folder containing this line:
Code:
cl65 -o %1.prg -u __EXEHDR__ -t c64 -C c64-asm.cfg %1.s

6.) created a file "borderflash.s" with these lines (from the "Intro To..." page) inside the dev dir
Code:
loop: inc $d020 ; increment $d020
      jmp loop  ; jump to label loop

7.) ran "cmd", changed into my src dir, ran the setenv.bat, then ran "asm2prg borderflash"
Then started the VICE emulator and ran the generated "borderflash.prg" via the "Autostart..." from the "File" pulldown menu (a next step will be to use the c1541 commandline utility (comes with VICE) to put the .prg file on a proper .d64 disk image first).

Note how in step 6.) I removed the "* = $ 1000" line from the source code given in the "Intro To..." page as the cc65 instructions said setting a changed start address makes no sense when using the command for adding the BASIC SYS header as in that case the program will be loaded to the BASIC start address.
_________________
0xDB
View user's profile Send private message Visit poster's website
PoV
Moderator

Joined: 21 Aug 2005
Posts: 10666
Location: Canadia
PostPosted: Sat Nov 01, 2014 7:47 pm    Post subject: Reply with quote


_________________
Mike Kasprzak
'eh whatever. I used to make AAA and Indie games | Ludum Dare | Blog | Tweetar
View user's profile Send private message
0xDB
Developer

Joined: 26 Dec 2005
Posts: 1637
Location: Your consciousness.
PostPosted: Mon Nov 03, 2014 1:51 am    Post subject: Reply with quote

No! I will not get away from the internet! The internet is my teacher, my connection to the world, it came to me, my own, my love... my... precioussssssss.

improved setenv.bat (includes path to vice emulator for the x64 and the c1541 disk image utility):
Code:
set CC65_INC=C:/CC65/include/
set LD65_LIB=C:/CC65/lib/
set LD65_CFG=C:/CC65/cfg/
set PATH=%PATH%;"C:\CC65\bin\";"C:\EMULATOR\C64\WinVICE-2.4-x64\"


improved asm2prg.bat (for automatic disk image creation and autostarting emulator for testing):
Code:
cl65 -o %1.prg -u __EXEHDR__ -t c64 -C c64-asm.cfg %1.s
c1541 -format %1,00 d64 %1.d64 -write %1.prg
x64 %1.d64

This removes a bunch of unnecessary mouse movements&clicks in the build&test cycle. :)
_________________
0xDB
View user's profile Send private message Visit poster's website
PoV
Moderator

Joined: 21 Aug 2005
Posts: 10666
Location: Canadia
PostPosted: Mon Nov 03, 2014 2:20 am    Post subject: Reply with quote

I think I might let myself play with the C64 on Ludum Dare weekend. Depends if I have energy or not. Else, over Xmas.

Gotta treat myself with some fun-dev (but I am enjoying LD-dev).
_________________
Mike Kasprzak
'eh whatever. I used to make AAA and Indie games | Ludum Dare | Blog | Tweetar
View user's profile Send private message
PoV
Moderator

Joined: 21 Aug 2005
Posts: 10666
Location: Canadia
PostPosted: Mon Nov 03, 2014 2:47 am    Post subject: Reply with quote

Did a little bit of doc reading. Seems the assembler included in cc65 DOES support the 65C816 CPU (I.e. SNES' variant of the 6502 with 24bit addressing).

The unconfirmed: not sure if the C compiler part supports 65C816 output. Documentation makes no mention of it, just the compiler switch that WOULD cause it to work. Would have to check the source code (or un the program) to find out.

Really, it shouldn't be hard. It just means you have to emit 24bit addresses and set the mode at the top of the generated src.

EDIT: I don't have confirmation yet, but from what I've seen, setting 65C816 mode should be a legal command line option to cc65.
_________________
Mike Kasprzak
'eh whatever. I used to make AAA and Indie games | Ludum Dare | Blog | Tweetar
View user's profile Send private message
PoV
Moderator

Joined: 21 Aug 2005
Posts: 10666
Location: Canadia
PostPosted: Wed Nov 19, 2014 6:23 am    Post subject: Reply with quote

Not directly C64, but here's Ben Heck creating a 6502 based main-board for a computer.






_________________
Mike Kasprzak
'eh whatever. I used to make AAA and Indie games | Ludum Dare | Blog | Tweetar


Edited by PoV on Mon Nov 24, 2014 9:46 am; edited 1 time
View user's profile Send private message
PoV
Moderator

Joined: 21 Aug 2005
Posts: 10666
Location: Canadia
PostPosted: Wed Nov 19, 2014 8:55 am    Post subject: Reply with quote

Also not C64, but Ben Heck rips apart a ZX Spectrum and rebuilds it.






_________________
Mike Kasprzak
'eh whatever. I used to make AAA and Indie games | Ludum Dare | Blog | Tweetar
View user's profile Send private message
0xDB
Developer

Joined: 26 Dec 2005
Posts: 1637
Location: Your consciousness.
PostPosted: Sat Nov 22, 2014 2:12 am    Post subject: Reply with quote

http://style64.org/c64-truetype

Looks great in a terminal, especially with blinking cursor enabled:

_________________
0xDB
View user's profile Send private message Visit poster's website
PoV
Moderator

Joined: 21 Aug 2005
Posts: 10666
Location: Canadia
PostPosted: Mon Nov 24, 2014 9:45 am    Post subject: Reply with quote

Oh hey, it's almost Ludum Dare time, and I said I would play with the C64.

I've added the final part of Ben Heck's Apple-from-scratch video. Again, it's not C64, but it's cool to see how someone would make a C64 era computer from scratch.
_________________
Mike Kasprzak
'eh whatever. I used to make AAA and Indie games | Ludum Dare | Blog | Tweetar
View user's profile Send private message
anarky
Member

Joined: 10 Nov 2014
Posts: 27
Location: Brisbane, Australia
PostPosted: Tue Nov 25, 2014 7:31 pm    Post subject: Reply with quote

I've been after the ROM of "Co & Co". Has anyone found it ever?

>anarky - Click here for system requirements.
_________________
I wonder if anyone has noticed the unique thing about my posts.

Screwing with your reality since 1981.
View user's profile Send private message Visit poster's website
0xDB
Developer

Joined: 26 Dec 2005
Posts: 1637
Location: Your consciousness.
PostPosted: Wed Nov 26, 2014 12:31 am    Post subject: Reply with quote

anarky wrote:
I've been after the ROM of "Co & Co". Has anyone found it ever?
This? http://www.gamebase64.com/game.php?id=1537&d=45 (Never heard of it before but google seemed to just "know" it.)
_________________
0xDB
View user's profile Send private message Visit poster's website
anarky
Member

Joined: 10 Nov 2014
Posts: 27
Location: Brisbane, Australia
PostPosted: Wed Nov 26, 2014 2:05 pm    Post subject: Reply with quote

Hey, yes! Awesome! Thank you!

>anarky - Download this song.
_________________
I wonder if anyone has noticed the unique thing about my posts.

Screwing with your reality since 1981.
View user's profile Send private message Visit poster's website
0xDB
Developer

Joined: 26 Dec 2005
Posts: 1637
Location: Your consciousness.
PostPosted: Thu Nov 27, 2014 5:55 am    Post subject: Reply with quote

One is glad to be of service.

Meanwhile... still haven't continued to look into C64 assembly programming any deeper but while I'm busy configuring my Arch Linux system, today I found a moment to port the earlier build/test batch file to a bash script. :)

requirements (for Arch Linux, other Linux variants probably have similar packages):
1) https://aur.archlinux.org/packages/cc65-git/ (earlier versions do not seem to include or know how to utilize the necessary c64-asm.cfg file)
2) https://aur.archlinux.org/packages/vice-gtkglext/ (or any other vice variant (for disk image file creation and emulation))

asm2prg.sh
Code:
#!/bin/bash
# script for building C64 assembler code and running it in emulation

# define paths
CFG_PATH=/usr/share/cc65/cfg
LIB_PATH=/usr/share/cc65/lib

# make executable prg from assembly source
cl65 --cfg-path $CFG_PATH --lib-path $LIB_PATH -o $1.prg -u __EXEHDR__ -t c64 -C c64-asm.cfg $1.s
# create disk image file and write executable prg to disk image file
c1541 -format $1,00 d64 $1.d64 -write $1.prg
# autorun the disk image file in vice c64 emulator
x64 $1.d64

_________________
0xDB
View user's profile Send private message Visit poster's website
PoV
Moderator

Joined: 21 Aug 2005
Posts: 10666
Location: Canadia
PostPosted: Thu Nov 27, 2014 4:31 pm    Post subject: Reply with quote

Cool. I'm hoping to start playing with the C64 soon (Ludum Dare is 8 days away). :)
_________________
Mike Kasprzak
'eh whatever. I used to make AAA and Indie games | Ludum Dare | Blog | Tweetar
View user's profile Send private message
PoV
Moderator

Joined: 21 Aug 2005
Posts: 10666
Location: Canadia
PostPosted: Fri Nov 28, 2014 2:47 pm    Post subject: Reply with quote



Code:
cc65 -t c64 main.c
cl65 -o main.prg -t c64 main.s
x64 main.prg

The extra code is because CC65 by default starts in lower case mode. That Poke stuff resets it back to upper case. Could have just written the address directly, but Poke! POKE!

Using CC65 to compile, and Vice to run, on Ubuntu.

Setup was mostly straightforward.

- Did a 'git clone' of the CC65 repository, followed by a 'make' and a 'sudo make avail' to create symlinks.
- Installed VICE from the Software Center. Unfortunately what's not mentioned is you have to download and put Commodore 64 ROM images in '~/.vice/C64'. Images can be found either in the Windows version or through other various searching. Should be 4 files under that C64 folder.
_________________
Mike Kasprzak
'eh whatever. I used to make AAA and Indie games | Ludum Dare | Blog | Tweetar
View user's profile Send private message
PoV
Moderator

Joined: 21 Aug 2005
Posts: 10666
Location: Canadia
PostPosted: Fri Nov 28, 2014 3:17 pm    Post subject: Reply with quote

Replicated your border flash test program in C (but I only do it for a few seconds).



Code:
cl65 -t c64 -o main.prg main.c

_________________
Mike Kasprzak
'eh whatever. I used to make AAA and Indie games | Ludum Dare | Blog | Tweetar
View user's profile Send private message
PoV
Moderator

Joined: 21 Aug 2005
Posts: 10666
Location: Canadia
PostPosted: Fri Nov 28, 2014 3:27 pm    Post subject: Reply with quote

Optimized.



Code:
cl65 -t c64 -O -o main.prg main.c


Slightly more complicated.

Code:
L000C:  lda     $D020    ; 4
        clc              ; 2
        adc     #$01     ; 2
        sta     $D020    ; 4
        jmp     L000C    ; 3


I tried to see if I could get the complier to generate faster code, without avail.

Code:
(*(unsigned char *)0xD020)++;


Still generates the same thing (read value, clear carry, add with carry, store value, jump). That's okay though, but it's worth knowing the compiler isn't doing increment optimizations.

EDIT: Added cycle counts to the instructions. The INC version would be 6 cycles (plus jump), where this version is 12 cycles (plus jump).
_________________
Mike Kasprzak
'eh whatever. I used to make AAA and Indie games | Ludum Dare | Blog | Tweetar
View user's profile Send private message
PoV
Moderator

Joined: 21 Aug 2005
Posts: 10666
Location: Canadia
PostPosted: Fri Nov 28, 2014 6:47 pm    Post subject: Reply with quote

Found out that the developers of CC65 have provided a complete easy-to-use memory map of Commodore 64 IO Registers via some global macros. VIC for the graphics, SID for the audio, CIA1 and CIA2 for the various IO devices (gamepads).

Also did some fiddling so I could emit the faster opcode.



Code:
L0006:  inc     $D020
        jmp     L0006

_________________
Mike Kasprzak
'eh whatever. I used to make AAA and Indie games | Ludum Dare | Blog | Tweetar
View user's profile Send private message
PoV
Moderator

Joined: 21 Aug 2005
Posts: 10666
Location: Canadia
PostPosted: Fri Nov 28, 2014 6:57 pm    Post subject: Reply with quote

And the only way to go faster: Don't branch. :)



Code:
L0006:  inc     $D020  ; 6
        inc     $D020  ; 6
        inc     $D020  ; 6
        inc     $D020  ; 6
        jmp     L0006  ; 3


- C Code, 4 iterations: 60 cycles (15 each, 12+Jump)
- Asm Code, 4 iterations: 36 cycles (9 each, 6+Jump)
- This Code, 4 iterations in one: 27 cycles (6 each then a Jump)

* * *

Next thing I need to figure out is how to set up a "raster line" interrupt.

What I've read looks a bit excessive (though probably necessary), and the manual is a bit vague here.


Other notes:

- PAL C64: 63 cycles per line
- NTSC C64: 65 cycles per line (but some old ones are 64)

Bad Lines Remove 43 cycles (one per character, plus *usually* a few more... may be 42 or 41)

- PAL C64: 20 cycles per bad line
- NTSC C64: 22 cycles per bad line (or 21)

Sprites cause the VIC to eat more cycles. Up to 19 cycles if all 8 sprites are used (varies, could be 17 or 18 too, and less if fewer sprites).

Quote:
PAL: 63 cycles/312 rasterlines
old NTSC: 64 cycles/262 rasterlines
new NTSC: 65 cycles/263 rasterlines


Checking the number of rasterlines can be useful to determine what C64 you are on.


On a side note, here's an article on NES dev using CC65. http://shiru.untergrund.net/articles/programming_nes_games_in_c.htm
_________________
Mike Kasprzak
'eh whatever. I used to make AAA and Indie games | Ludum Dare | Blog | Tweetar
View user's profile Send private message
Reply to topic GDR Forum Index -> Game Developer's Refuge -> The Commodore 64 (6502 and Friends) Page 1, 2, 3, 4  Next

Use this link to get a Sign-On Bonus when you get started!

All trademarks and copyrights on this page are owned by their respective owners. All comments owned by their respective posters.
phpBB code © 2001, 2005 phpBB Group. Other message board code © Kevin Reems.