Forums

Sega Master System / Mark III / Game Gear
SG-1000 / SC-3000 / SF-7000 / OMV
Home - Forums - Games - Scans - Maps - Cheats - Credits
Music - Videos - Development - Hacks - Translations - Homebrew

View topic - Battleships: My first piece of software

Reply to topic
Author Message
  • Joined: 30 Jun 2005
  • Posts: 51
  • Location: Denmark
Reply with quote
Battleships: My first piece of software
Post Posted: Thu Aug 11, 2011 5:40 pm
Last edited by Killer Bean 2 on Sun Aug 14, 2011 12:38 pm; edited 3 times in total
A few years ago I read Maxim's programming tutorial and started dreaming about making some sort of software for the Master System. Maxim's tutorial is really great (seriously, it's awesome!), but my understanding of electronics and assembly at the time was lackluster to say the least.

Since then I finished my education as a electronics mechanic, and half a year ago I started an education towards electronics engineering. The basic knowledge I have gained has made me confidente enough to finally start making a somewhat functional game for the Master System. Basically it's just Maxim's tutorial fleshed out to a simple version of the old classic Battleships. But I have to start somewhere :)

It's far from finished. But since most of the time I don't have a clue, what I'm doing, I figured I'd let the pros have a look at it before it gets too messy. I'm sure there's a lot of my code (if not all of it) that can be done much more elegantly. If any of you guys will take a quick look at my code and maybe give me some tips and tricks to make it better I'd appreciate it immensely. I know it's a headache to read other people's code, especially when it's bad ;)

For instance I'm doing a bit of multiplication/division using loops, and I got a feeling it's better to use shifting?

So far the game lets you place your ships, places its own ships and lets you shoot at them. The game also shoots at your ships, but the "AI" is still non-existing :D

When the player or the CPU wins, the game just resets.



Assembled using WLA DX. ConTEXT project file included.

EDIT: I forgot to remove the SMS file. Now it's just the source:

EDIT2: New version:
battle_007.png (4.05 KB)
Attachment fairy
battle_007.png
battleships.zip (13.26 KB)

  View user's profile Send private message Visit poster's website
  • Joined: 03 Aug 2011
  • Posts: 39
  • Location: NW England
Reply with quote
Post Posted: Fri Aug 12, 2011 10:28 pm
Killer Bean 2 wrote
A few years ago I read Maxim's programming tutorial and started dreaming about making some sort of software for the Master System. Maxim's tutorial is really great (seriously, it's awesome!), but my understanding of electronics and assembly at the time was lackluster to say the least.


Have to agree with you there, I'm new to the SMS and Maxim's tutorial has helped me a great deal in getting started.

Killer Bean 2 wrote
Since then I finished my education as a electronics mechanic, and half a year ago I started an education towards electronics engineering. The basic knowledge I have gained has made me confidente enough to finally start making a somewhat functional game for the Master System. Basically it's just Maxim's tutorial fleshed out to a simple version of the old classic Battleships. But I have to start somewhere :)


Very nice for a first attempt at something on the SMS.

I'm in a similar boat to yourself, and currently working on a simple version of a game (gotta walk before you can run as they say) - though it's still early days yet - only started on it this week - probably have something to show in a week or two.

Killer Bean 2 wrote
It's far from finished. But since most of the time I don't have a clue, what I'm doing, I figured I'd let the pros have a look at it before it gets too messy. I'm sure there's a lot of my code (if not all of it) that can be done much more elegantly. If any of you guys will take a quick look at my code and maybe give me som tips and tricks to make it better I'd appreciate it immensely. I know it's a headache to read other people's code, especially when it's bad ;)


I haven't looked at your code yet, just assembled and ran the ROM to play a few games. If I feel I can offer any feedback I will, though like you say "the pros" on here are going to be your best source of feedback.

Killer Bean 2 wrote
For instance I'm doing a bit of multiplication/division using loops, and I got a feeling it's better to use shifting?


Not looked at the source yet so ....

Killer Bean 2 wrote
So far the game lets you place your ships, places its own ships and lets you shoot at them. The game also shoots at your ships, but the "AI" is still non-existing :D


What you have appeared to be working reasonably well during the few goes I had - so you have a good working prototype to build upon.

Killer Bean 2 wrote
When the player or the CPU wins, the game just resets.


Yay I won :)

Killer Bean 2 wrote
Assembled using WLA DX. ConTEXT project file included.


Assembled and ran fine with my similar setup - no probs :)

----------------------------------------------------------------------------------------------

Keep up the good work, I hope you get some more feedback from other members soon and your project goes on to newer / a final build in the future.



Regards


Richard
  View user's profile Send private message
  • Joined: 30 Jun 2005
  • Posts: 51
  • Location: Denmark
Reply with quote
Post Posted: Fri Aug 12, 2011 10:40 pm
Sket wrote


Keep up the good work, I hope you get some more feedback from other members soon and your project goes on to newer / a final build in the future.



Regards


Richard


Thanks! :)

I'm hoping I can have the game done in time for next year's coding competition.
  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 08 Jul 2001
  • Posts: 8644
  • Location: Paris, France
Reply with quote
Post Posted: Sat Aug 13, 2011 9:51 am
I won!

Its nice, has a nice clean layout has well.
In the rules of Battleships are you supposed to know which ship you hit ?

I suggest you don't worry too much about the quality and speed of your code. And yours seems reasonnably commented which is a plus :) Your game is only better when the features shows, so try to think in term of how do you want to improve the game and if there's a specific hurdle we can discuss it ihmo.

Some suggestions if you want to finish up
- Make active cursor animate/blink
- Add music using MOD2PSG2 library for a change?
- Add messages or a way to distinguish from placement phase to attack phase, it would add a nice touch into the game. Maybe a banner that cover the screen with a drum roll music. That would be a bit challenging to implement!
- Add win/lose messages

Extra
- Animate the successful and failed shots. The key is to find the right balance so that it feels visually nice but not long (nothing worse than being forced to wait for repetitive animations).

Otherwise it looks like you are close to completion. I wonder what will be your next game :-)
  View user's profile Send private message Visit poster's website
  • Joined: 30 Jun 2005
  • Posts: 51
  • Location: Denmark
Reply with quote
Post Posted: Sat Aug 13, 2011 3:00 pm
Bock wrote

In the rules of Battleships are you supposed to know which ship you hit ?


No, you're right. Total brainfart. I'll have to change that :D

Bock wrote

I suggest you don't worry too much about the quality and speed of your code. And yours seems reasonnably commented which is a plus :) Your game is only better when the features shows, so try to think in term of how do you want to improve the game and if there's a specific hurdle we can discuss it ihmo.


I think you're right. The code isn't timing critical in any way, and the functions are not very hungry for clock cycles. I really don't have to worry about the speed. I'm just an obsessive perfectionist, and I'd hate to get too many bad programming habits to begin with ;)

If I hit a wall at some point, I'll put this tread to good use :)

Bock wrote

Some suggestions if you want to finish up
- Make active cursor animate/blink
- Add music using MOD2PSG2 library for a change?
- Add messages or a way to distinguish from placement phase to attack phase, it would add a nice touch into the game. Maybe a banner that cover the screen with a drum roll music. That would be a bit challenging to implement!
- Add win/lose messages

Extra
- Animate the successful and failed shots. The key is to find the right balance so that it feels visually nice but not long (nothing worse than being forced to wait for repetitive animations).


Great suggestions! I think I'll implement most of it.
But first I want to make the "AI" a little smarter, and maybe let the player change the difficulty in a menu.

Bock wrote

I wonder what will be your next game :-)


Me too :D

Maybe something a little more original.
  View user's profile Send private message Visit poster's website
  • Joined: 30 Jun 2005
  • Posts: 51
  • Location: Denmark
Reply with quote
Post Posted: Sun Aug 14, 2011 12:10 pm
I have now made a separate placement phase like Bock suggested :)



I have also made the striking anonymous like it should be.


battle_010.png (2.95 KB)
Attachment fairy
battle_010.png
battle_011.png (1.25 KB)
Attachment fairy
battle_011.png

  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 08 Jul 2001
  • Posts: 8644
  • Location: Paris, France
Reply with quote
Post Posted: Sun Aug 14, 2011 12:20 pm
But the striking shouldn't be anonymous on your own side - you should see the ship there :)

About the placement phase, I was about to suggest maybe try to make the whole thing and phrasing more exciting, more thrilling.. But in a way I can appreciate how your game looks like an early "straight-to-the-point" point without bell and whistle. That too has a charm in its own so maybe in this context your placement screen is perfect :)
  View user's profile Send private message Visit poster's website
  • Joined: 30 Jun 2005
  • Posts: 51
  • Location: Denmark
Reply with quote
Post Posted: Sun Aug 14, 2011 12:52 pm
Bock wrote
But the striking shouldn't be anonymous on your own side - you should see the ship there :)


I know. I need to fix that. Luckily a rewrite of one of my test functions should do the trick :)

Bock wrote

About the placement phase, I was about to suggest maybe try to make the whole thing and phrasing more exciting, more thrilling.. But in a way I can appreciate how your game looks like an early "straight-to-the-point" point without bell and whistle. That too has a charm in its own so maybe in this context your placement screen is perfect :)


I admit, it doesn't do the hardware justice i any way. But I don't want to bite off more than I can chew ;)

EDIT: Fixed :D
battleships.zip (13.5 KB)

  View user's profile Send private message Visit poster's website
  • Joined: 30 Jun 2005
  • Posts: 51
  • Location: Denmark
Reply with quote
Post Posted: Thu Aug 18, 2011 1:59 pm
I've made a "final" version of the game (for now). Basically I'm abandoning the project. The purpose of the whole thing was to explore the fundamentals of SMS programming, and I think it has served it's pursose just fine :)

Now I'll concentrate on small-scale experimentation with scolling, sprite animation, logic tables and stuff like that.

Or maybe I'll just make another simple game and try to improve on the fun factor :D
battleships_final.zip (12.48 KB)
The final version... (?)

  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 08 Jul 2001
  • Posts: 8644
  • Location: Paris, France
Reply with quote
Post Posted: Thu Aug 18, 2011 2:23 pm
Great! I'll try it shortly.
If that's the final version we'll add it to the Homebrew section as well :)
  View user's profile Send private message Visit poster's website
  • Joined: 30 Jun 2005
  • Posts: 51
  • Location: Denmark
Reply with quote
Post Posted: Thu Aug 18, 2011 3:22 pm
Bock wrote
If that's the final version we'll add it to the Homebrew section as well :)


Cool :)

It would be a nice way to "close a chapter".
Also great motivation for making better games, since it's crappyness defines my legacy until I do :D
  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14687
  • Location: London
Reply with quote
Post Posted: Thu Aug 18, 2011 4:32 pm
I see this compile warning:

MEM_INSERT: 2. write into $0067 (old: $45, new: $21).

That seems bad...

Also, your SDSC versions are a bit funny (all are 1.2). Was that intended?
  View user's profile Send private message Visit poster's website
  • Joined: 30 Jun 2005
  • Posts: 51
  • Location: Denmark
Reply with quote
Post Posted: Thu Aug 18, 2011 5:53 pm
Maxim wrote
I see this compile warning:

MEM_INSERT: 2. write into $0067 (old: $45, new: $21).

That seems bad...


Lol! Didn't know those were warnings :D

Don't know what those warnings mean. Has it something to do with the banking setup?

Maxim wrote
Also, your SDSC versions are a bit funny (all are 1.2). Was that intended?


I built the whole thing with your tutorial as the supporting structure. I never intended for it to be more than just a bit of experimentation and some useless code. I forgot all about the version number. That was just copy/pasted (*blushes*).
  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14687
  • Location: London
Reply with quote
Post Posted: Thu Aug 18, 2011 7:20 pm
I'll take a look, but the MEM_INSERT is almost certainly a problem. It's a warning because it can't tell if you did it on purpose, e.g. patching over some data.

I was going to post the earlier versions too, I may just assign arbitrary version numbers (0.8, 0.9, 1.0) so it makes sense. It might be nice for archaeologists one day to see the changes between versions.
  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14687
  • Location: London
Reply with quote
Post Posted: Thu Aug 18, 2011 7:51 pm
Ah, here we go...

.org $0066
;==============================================================
; Pause button handler
;==============================================================
    ; Do nothing
    retn

.org $0038
;==============================================================
; Vblank/Hblank interrupt handler
;==============================================================
...


;==============================================================
; Main program
;==============================================================
Main:
...


The .org $0038 means "output everything from this point on starting at address $0038". Since you already put the "retn" at $0066, it will write over that. The fix is to reorder it so the NMI handler comes between the vblank handler and Main, so Main is assembled from $0068. There will be a gap between the two interrupt handlers, but it's not a big deal.

If you use .sections, this problem becomes almost impossible to have, and there's other benefits too, so I recommend using them in future.

I'll shortly add it here:

http://www.smspower.org/Homebrew/Battleships-SMS

with the fix.
  View user's profile Send private message Visit poster's website
  • Joined: 30 Jun 2005
  • Posts: 51
  • Location: Denmark
Reply with quote
Post Posted: Thu Aug 18, 2011 10:19 pm
Maxim wrote
The .org $0038 means "output everything from this point on starting at address $0038". Since you already put the "retn" at $0066, it will write over that. The fix is to reorder it so the NMI handler comes between the vblank handler and Main, so Main is assembled from $0068. There will be a gap between the two interrupt handlers, but it's not a big deal.


I never thought of testing the pause button, since it wasn't suppose to do anything. But now I see, that it gives you a game breaking bug. Thanks for spotting that!

Maxim you rock! :)

Maxim wrote

If you use .sections, this problem becomes almost impossible to have, and there's other benefits too, so I recommend using them in future.


I'll try to remember that :)

Maxim wrote

I'll shortly add it here:

http://www.smspower.org/Homebrew/Battleships-SMS

with the fix.


Awesome! If you want to, you can just change the SDSC version to 1.0 or something like that.

And thanks for the feedback/bug hunting! :)

EDIT: Fixed a stupid typo...
  View user's profile Send private message Visit poster's website
  • Joined: 30 Jun 2005
  • Posts: 51
  • Location: Denmark
Reply with quote
Post Posted: Thu Aug 25, 2011 2:02 pm
I know I said, that I wouldn't do any further work on this game. But after playing a little with BMP2Tile, I simply had to make some graphical improvements :)




battle_012.png (2.1 KB)
Attachment fairy
battle_012.png
battle_013.png (3.55 KB)
Attachment fairy
battle_013.png
battleships_v1.1.zip (12.79 KB)

  View user's profile Send private message Visit poster's website
  • Joined: 03 Aug 2011
  • Posts: 39
  • Location: NW England
Reply with quote
Post Posted: Thu Aug 25, 2011 2:16 pm
Nice update on the visuals Killer - the use of the extra colour makes a world of difference :)

Re: BMP2Tile = godsend what more can I say !


Richard / Sket
  View user's profile Send private message
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14687
  • Location: London
Reply with quote
Post Posted: Thu Aug 25, 2011 4:12 pm
I compiled and uploaded here:

http://www.smspower.org/Homebrew/Battleships-SMS

...but I didn't make new screenshots yet.
  View user's profile Send private message Visit poster's website
  • Joined: 30 Jun 2005
  • Posts: 51
  • Location: Denmark
Reply with quote
Post Posted: Mon Nov 28, 2011 2:06 pm
Last edited by Killer Bean 2 on Fri Oct 12, 2018 8:31 pm; edited 1 time in total
Maxim wrote
Ah, here we go...

.org $0066
;==============================================================
; Pause button handler
;==============================================================
    ; Do nothing
    retn

.org $0038
;==============================================================
; Vblank/Hblank interrupt handler
;==============================================================
...


;==============================================================
; Main program
;==============================================================
Main:
...


The .org $0038 means "output everything from this point on starting at address $0038". Since you already put the "retn" at $0066, it will write over that. The fix is to reorder it so the NMI handler comes between the vblank handler and Main, so Main is assembled from $0068. There will be a gap between the two interrupt handlers, but it's not a big deal.

If you use .sections, this problem becomes almost impossible to have, and there's other benefits too, so I recommend using them in future.


I want to be sure I understand how .sections work before I start making my next piece of software :)

So, another way of fixing the problem would be to do something like this?:


.org $0066
;==============================================================
; Pause button handler
;==============================================================
.section "PauseButtonHandler" force
    ; Do nothing
    retn
.ends

.org $0038
;==============================================================
; Vblank/Hblank interrupt handler
;==============================================================
.section "VBlankInteruptHandler" force
...
.ends

;==============================================================
; Main program
;==============================================================
.section "Main" free
Main:
...
.ends


And then devide all the rest of my code into other .sections?
  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14687
  • Location: London
Reply with quote
Post Posted: Mon Nov 28, 2011 2:38 pm
I usually try to put the .orgs in order, as it's also the order they'll appear in the output; I think the "free" modifier means it doesn't matter, though (and it is the default if not specified). But yes, that's about it; you also need a .bank specifier so WLA DX knows what relocation may happen.
  View user's profile Send private message Visit poster's website
  • Joined: 18 Dec 2009
  • Posts: 114
  • Location: Norway
Reply with quote
Post Posted: Fri Dec 02, 2011 1:34 pm
In RetroCopy sometimes the crosses I make when playing against the CPU don't show. They are there, but I can't see them.
  View user's profile Send private message Visit poster's website
  • Joined: 30 Jun 2005
  • Posts: 51
  • Location: Denmark
Reply with quote
Post Posted: Mon Dec 05, 2011 9:50 pm
Only the crosses(misses) and not the hits? Does the the "miss" sound play when you strike? Does the score system still work like it's supposed to?

I never encountered this glitch when i tested it in Meka and on real hardware. I'd like to think that it's RetroCopy that's not as accurate as they claim. But it's more likely that I've made some stupid little mistake in my code :)
  View user's profile Send private message Visit poster's website
  • Joined: 18 Dec 2009
  • Posts: 114
  • Location: Norway
Reply with quote
Post Posted: Wed Dec 07, 2011 1:39 pm
Yes, everythings works as it's supposed to - I hear the miss-sound and they "are" there, except I don't see them. I think only the misses, yeah. I can test some more. And like I said, it only happens a few times. Most of the crosses I see.
  View user's profile Send private message Visit poster's website
  • Joined: 21 Jul 2005
  • Posts: 412
  • Location: GBG
Reply with quote
Post Posted: Wed Dec 07, 2011 2:19 pm
Is RetroCopy running in NTSC mode when this happens?
  View user's profile Send private message Visit poster's website
  • Joined: 30 Jun 2005
  • Posts: 51
  • Location: Denmark
Reply with quote
Post Posted: Tue Dec 13, 2011 3:37 pm
I think I know what's wrong. I have not been taking the VDP delay into account. I guess the VDP writes f¤¤ks up now and then or clashes with the Hblank interrupt. I'd might try to fix it sometime, but it's not very high on my to-do list :)
  View user's profile Send private message Visit poster's website
Reply to topic



Back to the top of this page

Back to SMS Power!