Commodore 64 (C64) Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Coding a Tetris clone as an ASM learning experiment
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Commodore 64 (C64) Forum Index -> Scene
View previous topic :: View next topic  
Author Message
cjauvin
Newbie


Joined: 23 Jun 2012
Posts: 29
Location: Canada

PostPosted: Wed Jun 27, 2012 8:41 pm    Post subject: Coding a Tetris clone as an ASM learning experiment Reply with quote

Hi all,

I already discussed about it (to ask questions, mainly) in a couple of
previous threads, but I wanted to create a new one to say that I
(mostly) succeeded in creating a stripped down (but decent) version of
Tetris. I did it first for fun, but also to finally, properly learn
C64 ASM, after a hiatus of about 25 years!

It is such an interesting (and humbling) experiment in itself, when
you're used to modern high-level languages (I'm primarily a Python
coder), to go back to the bare metal, once in a while.

I also want to thank the many C64 wizards who kindly answered my
questions, and made great suggestions. Without them, the Jim
Butterfield book and a couple of other great online resources, this
would simply have been impossible. I cannot help thinking about what
this retrospectively implies for the poor 11-yo boy that I was, with
limited English skills and a single dated and obscure ML book from the
local library.. The King's Quest clone I dreamt about was farther than
I thought I guess!

Although the game is playable, it totally lacks finish (as well as an
important aspect: colors!). I will need to take a break from my coding
spree for a while, but if someone feels like stepping in and improving
it, it would be very cool. The code repo is there:

https://github.com/cjauvin/tetris-c64

I really don't know about its ASM qualities (it might contain some
rather suboptimal, or even really stupid stuff), but I'm quite proud
of its clarity at least. At a little less than 1K sloc, I
think it's readable and relatively understandable (it's generously
commented anyway).

Finally, I plan to write about the whole process, but I don't know
yet exactly how and what.


Last edited by cjauvin on Fri Jul 06, 2012 12:58 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
Wayne / Art Ravers
Groupie
Groupie


Joined: 30 Jun 2012
Age: 41
Posts: 230
Location: West Yorkshire

PostPosted: Fri Jul 06, 2012 12:29 am    Post subject: Re: Coding a Tetris clone as an ASM learning experiment Reply with quote

Hiya Wayne here, Just came online and joined up yesterday and posted a question and then browsing around came across this - OH MY GOSH, Fate or what? I am wanting a Coder to do a TETRIS / DR MARIO Clone for the C64, I have done some Nice Graphics, Perhaps you might consider teaming up with me to do this game? Hope Iam not being a pest, Hope you can help :->

[edited by TNT: unnecessary quote removed]
_________________
o o Art Ravers - 1992 Onward...
>
U
Back to top
View user's profile Send private message
hjustin
Newbie


Joined: 06 Jul 2012
Posts: 2

PostPosted: Fri Jul 06, 2012 3:05 am    Post subject: Reply with quote

Hello!

First time posting (after years of lurking). I would be interested in reading about your experience throughout the learning process.

I was 12 when I bought my VIC-20 and 14 when my parents gave me a C64 and 1541 for Christmas. I so desperately wanted to program my own Bard's Tale but in a small town with a tiny library and no one to push me in the right direction, I never made any progress. I never could wrap my head around even the more complicated Basic programming routines.

Now, some 25 years later I'm still trying to understand all this, and I would still love to write that game. Baby steps. I have the Butterfield book (and a lot of others) and I'm trying to sort out all the possible development options (cross assemblers, etc.).

There's a huge thread over on Sleeping Elephant in which a fellow name Ghislain goes through the whole process of building an Ultima-style game on the VIC-20. Early on he says he's not very good with machine language programming. I can only grin when I read this. Really? You read about all these amazing programmers...John Carmack and Burger Heinemen and how they were programming Apples and Ataris when they were teenagers...and I'm still struggling with this at the age of 40.

I often wonder if I'm simply not smart enough to learn this stuff. But dang if I don't keep trying.

Thanks for posting. I'll be looking through this forum for your other threads and look forward to hearing more about your exploits. No doubt it will be helpful and inspirational.
Back to top
View user's profile Send private message
cjauvin
Newbie


Joined: 23 Jun 2012
Posts: 29
Location: Canada

PostPosted: Fri Jul 06, 2012 4:24 pm    Post subject: Reply with quote

@Wayne: Thanks for your interest! I certainly didn't intend for this experiment to become anything else than it is (more or less throwable code, only meant to learn something dear to my memories) but you are free to do whatever you want with the code of course (although like I said I doubt its qualities are great, given that it's my very first c64 asm program). If you need help to integrate your own stuff somehow, I cannot promise anything, but I may consider it, if you submit an interesting case.
Back to top
View user's profile Send private message Visit poster's website
cjauvin
Newbie


Joined: 23 Jun 2012
Posts: 29
Location: Canada

PostPosted: Fri Jul 06, 2012 5:18 pm    Post subject: Reply with quote

@hjustin: I can totally relate to your story. I remember desperately wanting to play these intriguing RPGs (Bard's Tale, Ultima, Wizardry, etc), but the barrier of entry for me was clearly English: I didn't have a clue of what was going on! But I wanted to play them, and I wanted to create my own even more.

About learning ML: I don't know what you do, but for my part, it certainly helps to be a programmer by trade. Of course I'm not using ML or anything as remotely low-level in my day to day computing life, but nevertheless, it certainly comes easier if you know about programming and CS beforehand. In my case, the only real contact I had with ML was during an hardware course I followed as a freshman. The course material, based on that book:

http://amzn.com/080534330X

was using a simplified hardware model, which interestingly was (I assume) closer to the C64 in complexity terms than modern chip architectures are, and which seem, quite frankly, a bit scary with their complex instruction sets and multiple registers. So although I struggled quite a bit with C64-specific issues for this learning project, the basic concepts were relatively easy to grasp. My first step was to skim rapidly through Jim Butterfield's excellent book, and I was set to go.

About writing about it: although English is not my native language (and like ASM I certainly don't master it fully), I love to write about technical stuff in it. I already wrote about many things on my blog (shameless plug here):

http://blog.christianjauv.in

but for this particular topic, I'm still hesitating about what would be the ideal form: a single, relatively high-level article? An in-depth tutorial, maybe as a series of posts? To be honest, I even considered a more audacious idea: an e-book which would teach progamming from two completely opposite perspectives: writing a Tetris clone in Python, but also.. in C64 assembler! Although original, I really don't know if such an idea would make sense, or would gather even remote interest (probably not in fact, as entry level programming tutorials are already a very crowded area).
Back to top
View user's profile Send private message Visit poster's website
hjustin
Newbie


Joined: 06 Jul 2012
Posts: 2

PostPosted: Fri Jul 06, 2012 6:56 pm    Post subject: Reply with quote

I am not a programmer by trade. I am a network engineer who occasionally is tasked with some very trivial development project. I've been in school for computer science for about a year but have yet to actually take anything other than math and English classes. It's really very frustrating but there are all these prerequisites I need.

My obstacle is that I have trouble wrapping my head around the logic required for game programming. Consider the upper left window in Bard's Tale--our window into the game world. I have no idea how one would program such a thing. I could create the graphics and the map, but how to arrive at the end result completely baffles me. Hopefully learning to do this sort of thing (and how to create solutions to problems with software) is a learnable skill. If not, I'm doomed before I even start.

However you decide to document your experience, I will be happy to read it. Certainly the technical details would be nice to read. As far as I'm concnered there are never enough good articles and tutorials for learning this stuff.
Back to top
View user's profile Send private message
Turbo240Z
Groupie in Training
Groupie in Training


Joined: 27 Apr 2012
Age: 33
Posts: 72
Location: US

PostPosted: Sat Jul 07, 2012 7:02 pm    Post subject: Reply with quote

cjauvin, Wayne, I too am at the beginning of my journey of gathering knowledge and writing a simple game. I'm a daytime C++ developer so I first tried out cc65, a 6502 compiler, which works pretty well, but it didn't take long before I ran into some of the limitations like timing, memory issues, and performance. So, I've focused my time on the machine language book from Jim Butterfield.
My hopes were to get a project similar to yours going soon, tetris, dr mario, or lumines type of game. I still play dr mario with the wife often. Wouldn't it be great to write a game that she'd enjoy, too? Have you guys seen the dr mario someone did for spectrum zx? I think it looks great
Link

_________________
Tony Fruzza

Equipment:
PAL 64G, NTSC Breadbin and 64C, 1541/1541-II, 1530, uIEC, 1701 Monitor, 1351 mouse and 1764 REU. Modded NES game pad.
Back to top
View user's profile Send private message
Turbo240Z
Groupie in Training
Groupie in Training


Joined: 27 Apr 2012
Age: 33
Posts: 72
Location: US

PostPosted: Sat Jul 07, 2012 8:34 pm    Post subject: Reply with quote

BTW the game plays pretty nice! Only very occasionally does it interpret my single key tap for left or right as two movements. But this could be in part the emulator's fault. I didn't try it out on the real machine yet.
Did you find any text editors that were of any assistance over a regular plain text editor?
_________________
Tony Fruzza

Equipment:
PAL 64G, NTSC Breadbin and 64C, 1541/1541-II, 1530, uIEC, 1701 Monitor, 1351 mouse and 1764 REU. Modded NES game pad.
Back to top
View user's profile Send private message
qaz112
Forum Junkie
Forum Junkie


Joined: 15 Feb 2003
Posts: 536
Location: Manitoba, Canada

PostPosted: Sat Jul 07, 2012 10:23 pm    Post subject: Reply with quote

Re; King's Quest--
It should be possible, it would simply take tons of disk access, but with the modern SD2IEC/EasyFlash sort of things available, an enterprising coder should be able to give it a go. I'm not that coder, mind you, but, it should be *possible*.
_________________
Proud Canuck and user of C64 systems since 1985.
Back to top
View user's profile Send private message
cjauvin
Newbie


Joined: 23 Jun 2012
Posts: 29
Location: Canada

PostPosted: Sun Jul 08, 2012 4:24 pm    Post subject: Reply with quote

Turbo240Z wrote:
BTW the game plays pretty nice! Only very occasionally does it interpret my single key tap for left or right as two movements. But this could be in part the emulator's fault. I didn't try it out on the real machine yet.

Thanks! You're right about the controls: I suspect my keyboard input logic is not optimal at this point. You're quite lucky to be able to try it out on a real machine: please tell me about it if you do, I'm curious to see how it goes.

Turbo240Z wrote:
Did you find any text editors that were of any assistance over a regular plain text editor?

I'm actually using Emacs, which has good support for "plain" ASM (if there is such a thing), although it does not recognize certain aspects of the KickAss syntax (C-style comments in particular), which makes it a bit annoying.

Thank you also for pointing out the chrout/chroot typo on my blog!
Back to top
View user's profile Send private message Visit poster's website
cjauvin
Newbie


Joined: 23 Jun 2012
Posts: 29
Location: Canada

PostPosted: Sun Jul 08, 2012 4:28 pm    Post subject: Reply with quote

qaz112 wrote:
Re; King's Quest--
It should be possible, it would simply take tons of disk access, but with the modern SD2IEC/EasyFlash sort of things available, an enterprising coder should be able to give it a go. I'm not that coder, mind you, but, it should be *possible*.

It seems that The Wizard and the Princess, a kind of KQ 0 (according to Wikipedia), had a C64 port..
Back to top
View user's profile Send private message Visit poster's website
cjauvin
Newbie


Joined: 23 Jun 2012
Posts: 29
Location: Canada

PostPosted: Sun Jul 08, 2012 4:42 pm    Post subject: Reply with quote

Turbo240Z wrote:
..I first tried out cc65, a 6502 compiler, which works pretty well, but it didn't take long before I ran into some of the limitations like timing, memory issues, and performance

At some point in my Tetris learning project, I had the opposite idea: I'd try to port my ML code to C (a kind of "manual decompiling" I guess), and try it out with cc65, just by curiosity.

As I assumed that the most intricate part would likely be the interrupt handler code, I googled for it first, but since I didn't find any definite and well documented pattern, I dropped the whole idea (I didn't search very deeply though). I still think it would be very interesting though: if someone is interested, please let me know.
Back to top
View user's profile Send private message Visit poster's website
Blinx123
Groupie in Training
Groupie in Training


Joined: 07 Jul 2012
Posts: 100

PostPosted: Sun Jul 08, 2012 5:01 pm    Post subject: Reply with quote

cjauvin wrote:
qaz112 wrote:
Re; King's Quest--
It should be possible, it would simply take tons of disk access, but with the modern SD2IEC/EasyFlash sort of things available, an enterprising coder should be able to give it a go. I'm not that coder, mind you, but, it should be *possible*.

It seems that The Wizard and the Princess, a kind of KQ 0 (according to Wikipedia), had a C64 port..

The Wizard and the Princess is a graphical text adventure, though.

There aren't any sort of player and non-player characters on the screen.

The closest thing to a King's Quest (gameplaywise) on the C64 is "The Detective Game" from 1986, I'd say.

A game like King's Quest on the C64 should definitely be in the cards, though. I really don't see why it wouldn't be possible, seeing as how Maniac Mansion and several other adventure games made it to the C64 as well.
Back to top
View user's profile Send private message
merman
Lemon64 Game Champion
Lemon64 Game Champion


Joined: 29 Jan 2003
Age: 38
Posts: 3895
Location: Skegness, UK Fave game: The Sentinel

PostPosted: Sun Jul 08, 2012 6:18 pm    Post subject: Reply with quote

Maniac Mansion and its SCUMM engine (Script Creation Utility for Maniac Mansion) started life on the C64. The Sierra engine behind King's Quest has a higher minimum spec...
_________________
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
Blinx123
Groupie in Training
Groupie in Training


Joined: 07 Jul 2012
Posts: 100

PostPosted: Sun Jul 08, 2012 6:55 pm    Post subject: Reply with quote

merman wrote:
Maniac Mansion and its SCUMM engine (Script Creation Utility for Maniac Mansion) started life on the C64. The Sierra engine behind King's Quest has a higher minimum spec...

I suspect those higher minimum specs stem from the way graphics are generated/stored?

Otherwise, I don't see how the AGI engine could've any higher end requirements than SCUMM 0.
Back to top
View user's profile Send private message
encore
Über Groupie
Über Groupie


Joined: 02 Jun 2010
Posts: 389
Location: .se

PostPosted: Sun Jul 08, 2012 7:16 pm    Post subject: Reply with quote

Blinx123 wrote:
I suspect those higher minimum specs stem from the way graphics are generated/stored?

Otherwise, I don't see how the AGI engine could've any higher end requirements than SCUMM 0.

Blinx123: enthusi wrote an interesting post about AGI in another thread regarding Leisure Suit Larry that you should read. Smile
Back to top
View user's profile Send private message Visit poster's website
Carlos
Groupie
Groupie


Joined: 08 Feb 2002
Posts: 194
Location: Spain

PostPosted: Mon Jul 09, 2012 7:01 am    Post subject: Reply with quote

cjauvin wrote:
At some point in my Tetris learning project, I had the opposite idea: I'd try to port my ML code to C (a kind of "manual decompiling" I guess), and try it out with cc65, just by curiosity.

As I assumed that the most intricate part would likely be the interrupt handler code, I googled for it first, but since I didn't find any definite and well documented pattern, I dropped the whole idea (I didn't search very deeply though). I still think it would be very interesting though: if someone is interested, please let me know.

http://www.cc65.org/faq.php#IntHandlers
Back to top
View user's profile Send private message
Turbo240Z
Groupie in Training
Groupie in Training


Joined: 27 Apr 2012
Age: 33
Posts: 72
Location: US

PostPosted: Mon Jul 09, 2012 8:15 pm    Post subject: Reply with quote

cjauvin wrote:
You're right about the controls: I suspect my keyboard input logic is not optimal at this point. You're quite lucky to be able to try it out on a real machine: please tell me about it if you do, I'm curious to see how it goes.

I loaded it up on my NTSC machine. The double keyboard press on a single tap still happens, and occasionally you'll notice the pieces will seemingly bounce off of the bottom before landing. I'm guessing a glitch with the screen flipping? I was going to look into modding your version a bit, but I'm not too familiar with some of the syntax that Kick Assembler uses.

Here is what I had worked on with cc65:
https://github.com/Turbo240Z/C64sprites


Link


I believe CBM command uses cc65

What's next, hopefully an entry into RGCD? Smile
_________________
Tony Fruzza

Equipment:
PAL 64G, NTSC Breadbin and 64C, 1541/1541-II, 1530, uIEC, 1701 Monitor, 1351 mouse and 1764 REU. Modded NES game pad.
Back to top
View user's profile Send private message
mrsid
C64 Enthusiast
C64 Enthusiast


Joined: 27 Jan 2003
Age: 38
Posts: 809
Location: Netherlands

PostPosted: Mon Jul 09, 2012 9:20 pm    Post subject: Reply with quote

You're not seriously using VirtualC64? Smile
Back to top
View user's profile Send private message
Turbo240Z
Groupie in Training
Groupie in Training


Joined: 27 Apr 2012
Age: 33
Posts: 72
Location: US

PostPosted: Mon Jul 09, 2012 9:27 pm    Post subject: Reply with quote

mrsid wrote:
You're not seriously using VirtualC64? Smile

Heh, I'm now using Vice. The download link for the cocoa intel mac version was broken. I think it may still be, but after some searching I found it, so at the time VirtualC64 was the only thing I could grab that ran under Lion.
_________________
Tony Fruzza

Equipment:
PAL 64G, NTSC Breadbin and 64C, 1541/1541-II, 1530, uIEC, 1701 Monitor, 1351 mouse and 1764 REU. Modded NES game pad.
Back to top
View user's profile Send private message
Wayne / Art Ravers
Groupie
Groupie


Joined: 30 Jun 2012
Age: 41
Posts: 230
Location: West Yorkshire

PostPosted: Tue Jul 10, 2012 12:15 am    Post subject: Tetris! Dr Mario! Reply with quote

Turbo240Z wrote:
My hopes were to get a project similar to yours going soon, tetris, dr mario, or lumines type of game. I still play dr mario with the wife often. Wouldn't it be great to write a game that she'd enjoy, too? Have you guys seen the dr mario someone did for spectrum zx? I think it looks great

Wayne Says - Hello! Very Happy
Excellent! If you do decide to go ahead with a C64 Version please contact Merman on here he has my C64 Dr Mario Stylee Graphics, And dont forget to Credit Me and Andrew, Maybe we could submit it to Psytronik Software for Release? Smile
Best Wishes Wayne
_________________
o o Art Ravers - 1992 Onward...
>
U
Back to top
View user's profile Send private message
mrsid
C64 Enthusiast
C64 Enthusiast


Joined: 27 Jan 2003
Age: 38
Posts: 809
Location: Netherlands

PostPosted: Tue Jul 10, 2012 6:11 am    Post subject: Reply with quote

cjauvin wrote:
http://blog.christianjauv.in

That's a nice read. But please don't link to viceteam.org but rather to vice-emu.sourceforge.net. Otherwise Google will never learn what is to current VICE page.
Back to top
View user's profile Send private message
merman
Lemon64 Game Champion
Lemon64 Game Champion


Joined: 29 Jan 2003
Age: 38
Posts: 3895
Location: Skegness, UK Fave game: The Sentinel

PostPosted: Wed Jul 11, 2012 4:12 pm    Post subject: Reply with quote

OK, here are some background designs for PILLZ - Wayne was inspired by Dr. Mario. Rather than a block, Dr Mario throws in two-colour pills. The aim is to match the colours with the germs (also in different colours) to create a line of four or more, which then disappears. In Pillz you have to get a set number of pillz in a row, which then disappear.









The idea would be to have a sprite enemy at the top of the screen throwing things in. When you have cleared the screen, the sprite enemy "dies" and the level is complete. Among the enemies are a frog, alien, mobile phone and a man-eating plant...
_________________
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
PeteD
Forum Junkie
Forum Junkie


Joined: 13 Aug 2009
Age: 44
Posts: 422

PostPosted: Wed Jul 11, 2012 5:46 pm    Post subject: Reply with quote

@Wayne, what happens to the "pillz" in those images when you flip them 90 degrees? You seem to have done them as multicolour to get a bit of shading on them but the shading will obviously then be twice the size when they're horizontal instead of vertical..
_________________
Back to top
View user's profile Send private message
Wayne / Art Ravers
Groupie
Groupie


Joined: 30 Jun 2012
Age: 41
Posts: 230
Location: West Yorkshire

PostPosted: Wed Jul 11, 2012 10:49 pm    Post subject: Reply with quote

Hiya, Yes you are Absolutely right, The Graphics are all done with Multi Colour Character Mode, done of course in the Legendary Firebird Graphic Editor... The Way I did it is when you flip them 90 Degrees you get Two Characters Side By Side like this - "@@" I did my best to make the Pillz look Vertically like they do Horizontally, God it was easier to Draw than it was to explain and it was Hard to Draw LOL! Laughing
Hope the Graphics are ok, this was one of my earlier Projects I drew Graphics on. Let me know what you think...
I would Loooooooooooooooooooooove to do some more work on this and get the begger finished... Smile
_________________
o o Art Ravers - 1992 Onward...
>
U
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Commodore 64 (C64) Forum Index -> Scene All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Tip: Get C64 Forever for super-comfy C64 emulation with pre-installed games, demos and other goodies!


Powered by phpBB © 2001, 2005 phpBB Group