Assets for the Nesdev Compo 2016

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
Assets for the Nesdev Compo 2016
by on (#169438)
This thread is created in case you want to share any assets for other to use in the upcoming Nesdev Compo 2016 (or anywhere else, if you grant permission).

Here's my contribution: a simple framework to create UNROMs games using cc65+neslib+famitone2. Still on the works, will update it with improvements as soon as they come. Includes shiru's Neslib and Tokumaru's lzss decompressor code and compression utilites.

Short documentation and a working example included.

You can use this as you like as long as you give credit to the involved authors (Shiru, Tokumaru, myself).

UPDATED [20160426]: Added support to put your music data for famitracker 2 in any switchable bank. A new example to showcase this feature has been included.

UPDATED [20161220]: Did some tiny fixes and added a new version of the compressor. I've ported Tokumaru's original VBscript compressor to freeBASIC. It *much* faster now, outputs source code if you need it, plus it is portable. Compiled Windows binary included.
Re: Assets for the Nesdev Compo 2016
by on (#169464)
Thanks. I was looking for a UxROM .cfg example file and yours appears to be a good one.

Regarding the contest: Is there any idea if 64KB will be the maximum ROM size again? It's not clear to me if that's a multicart limitation or a contest-imposed limitation.
Re: Assets for the Nesdev Compo 2016
by on (#169467)
The Action 53 mapper allows individual games to be 16K, 32K, 64K, 128K, or 256K. But the first two multicarts themselves have been 512K. And after about five contests (two past and three future), I plan to put together a multicart of the best 53 games that have appeared on previous multicarts (hence Action 53), and that might be limited to 2048K. So it's both: a contest-imposed limit to ensure games have enough fun-to-size ratio to be worthy of inclusion on the multicart.
Re: Assets for the Nesdev Compo 2016
by on (#169471)
64K is a nice size. I like the challenge to squeeze as much as you can in a limited space.
Re: Assets for the Nesdev Compo 2016
by on (#169479)
Will an entry be disqualified if it does not conform to this mapper specification? I am designing a UOROM game and 64KB is not going to be adequate for what I am doing.
Re: Assets for the Nesdev Compo 2016
by on (#169480)
I think there's also going to be an "anything goes" category, so you might be able to submit it there.
Re: Assets for the Nesdev Compo 2016
by on (#169481)
Freem is right. A 160K, 192K, 224K,* or 256K game may fit in the "anything goes" category even if it doesn't qualify for a prize or doesn't qualify for the larger prizes associated with a category that has a near-guaranteed slot on the multicart.


* For sizes not a power of two, I'd probably end up stuffing other games in the unused banks of your game.
Re: Assets for the Nesdev Compo 2016
by on (#169606)
I know this isn't really an asset, but it's a suggestion, and I refuse to not post it because I've spent days figuring this out. Like, I had to use a debugger and stuff.

text2data, which comes with famitone, has a function called output_close() in its source that looks like this:
Code:
void output_close(void)
{
    if(outfile) fclose(outfile);
}


Problem with it is, fclose() doesn't seem to set outfile to NULL, and the program is designed so that at exit, output_close is called. When it isn't NULL, fclose() tries to close...nothing. Bad. Errors. So make sure to change the function to...

Code:
void output_close(void)
{
    if(outfile) fclose(outfile);
    outfile = NULL;
}


It could be that no one else has ever had this problem, but I don't like wine or windows, so the existing binary is not an option for me. Also I converted the program from C++ to C, because other than some stylistic things, C++ doesn't seem to have much benefit, as the program is pure C. That's just me, though; for all I know it'd be better to use C++.
Re: Assets for the Nesdev Compo 2016
by on (#169614)
nicklausw wrote:
the program is designed so that at exit, output_close is called.

Any reason that can't be replaced with fcloseall()? (Or just removed entirely, since the CRT is supposed to close files when the program exits?)
Re: Assets for the Nesdev Compo 2016
by on (#169632)
You have an old copy. The source I have of famitone2 has that if.
Re: Assets for the Nesdev Compo 2016
by on (#169661)
mikejmoffitt wrote:
Will an entry be disqualified if it does not conform to this mapper specification? I am designing a UOROM game and 64KB is not going to be adequate for what I am doing.

As mentioned earlier, the 64KB is a limit to ensure its inclusion on the Action 53 volume associated with that compo. So it would be best to submit in the anything goes category which doesn't obligate its inclusion on the cartridge. But we may very well still be able to include it in the cartridge similar to how STREEMERZ was a larger (128KB UNROM) game included in volume 1. Bottom line is if you have a decent game you'd like included on the cartridge we'll do our best to include it within the hardware limits we set for ourselves (which we can always modify if deemed worth the cost).
Re: Assets for the Nesdev Compo 2016
by on (#170900)
I'm assuming this can (kinda?) be like a question thread, so...this question is half curiosity, half wanting to showcase what code I'm working on (visuals are an unwritten story right now).

I'm designing my comp entry to work with "objects". These objects are just used for characters: the player and enemies, so that movement is always controlled properly. It's not completely necessary, but if the game engine is simple and boring then I'll probably lose interest quickly. The system works alright so far; haven't gone very in-depth yet, but it can probably handle creating multiple objects and running their respective routines at the least.

Does anyone think this could cause too big a change in speed, though? Running the objects' code shouldn't make a problem, but I'm not sure if the same can be said about their declaration. Finding an open spot, doing the math to transfer stuff to it, all that. I'm afraid that making everything too dynamic will make my game slow to play.

If it helps describe any, the game is probably going to have tiny (8x8, one tile) 'characters' so not much math with getting 16x16 characters on screen simply because that won't happen, and collision won't get more descriptive than "these two objectsare 8 pixels away from each other, let stuff happen".
Re: Assets for the Nesdev Compo 2016
by on (#170906)
nicklausw wrote:
Does anyone think this could cause too big a change in speed, though? Running the objects' code shouldn't make a problem, but I'm not sure if the same can be said about their declaration. Finding an open spot, doing the math to transfer stuff to it, all that. I'm afraid that making everything too dynamic will make my game slow to play.

I don't think I understand what you're asking. What does it mean to "declare" an object?

If it means "create", well then creating/deleting objects is a fast operation in most implementations. If you're storing objects as a list then creating/deleting is a constant time operation and nothing more than modifying a few pointers. Arrays require a search, but they really don't take up many more cycles than lists. And besides, how many objects are you going to be creating per frame? One? Two? I doubt very many. It's not like collision or movement code which happens every frame for every object.
Re: Assets for the Nesdev Compo 2016
by on (#170908)
True, spawning of enemies in a group can be spread out over several frames, one enemy per frame. But, say, the spread gun in Contra spawns five bullet objects in one frame.
Re: Assets for the Nesdev Compo 2016
by on (#170912)
tepples wrote:
True, spawning of enemies in a group can be spread out over several frames, one enemy per frame. But, say, the spread gun in Contra spawns five bullet objects in one frame.

Unless of course you're spamming the fire button to take advantage of the spawning pattern and unleashing an onslaught of damage in a tighter range. :)


As for spawning objects, I keep an updated list of any available slots and pull the first one from the list when it's time to spawn, then decrement the list. When something dies, I increment the list and write the destroyed object's number at the top.

It's more complicated, and less useful, to keep a list of the ones that are in use. But keeping a list of the available slots makes the spawning process pretty painless.
Re: Assets for the Nesdev Compo 2016
by on (#171070)
This is silly I know, but will it work as intended for a UNROM game?

Code:
   ldx #$FF
   stx $8000 ; select last PRG bank
   inx
   stx $5000 ; mapper 028 address $00 (CHR register)
   stx $8000 ; PRG bank 0 on UNROM, CHR bank 0 on 028
   inx
   stx $5000 ; restore mapper 028 address $01 (PRG register)
   ldx $BFFF ; 0 in bank 0, high byte of IRQ vector (>$C0) in last bank

   bmi ShowQuitOptionOnTitleScreen

To save others searching through the old threads:

tepples wrote:
thefox wrote:
Just let me know what code to execute to reset to the multicart menu.

If a game is running in UNROM or 32K NROM mode, all it has to do is change the outer bank to the last bank. This can be done with the following code copied to RAM:
Code:
  ldx #$81  ; Set outer bank
  stx $5000
  ldx #$FF  ; to the last bank in the cart
  stx $8000
  jmp ($FFFC)

Re: Assets for the Nesdev Compo 2016
by on (#171071)
The easiest way to determine whether the game has been included in one of my multicarts is to compare $FFFC (the reset vector's low byte) to the expected value of the reset vector's low byte.
Code:
  lda $FFFC
  cmp #<reset
  bne ShowQuitOptionOnTitleScreen
Re: Assets for the Nesdev Compo 2016
by on (#171072)
I knew I had to be overcomplicating things. :roll:
Re: Assets for the Nesdev Compo 2016
by on (#171995)
I got a PM requesting the source to that animation-to-assembly program so here it is:

animate.cpp: http://pastebin.com/raw/7m5QnWtp
color.hpp: http://pastebin.com/raw/a9EP7KFp
runs.s: http://pastebin.com/raw/febfK0nh

I didn't bother cleaning it up, so user beware.

Here's an example frame to use as input:

Image

It's intended to be used for the type of animations found in Mario 3.
Re: Assets for the Nesdev Compo 2016
by on (#180490)
I need help.

Through this neslib-unrom I'm making a game. I managed to play music, but I can not play sound SFX.

Does anyone know how you should do? For more examples and tutorials I've seen, some of Shiru itself, not seem to work the sound.

No that's wrong.
Re: Assets for the Nesdev Compo 2016
by on (#180492)
Sent you a PM.
Re: Assets for the Nesdev Compo 2016
by on (#185171)
I've updated the original post with a new revision of my tiny "Neslib for UNROM" package. I've used it successfully to produce the UNROM version of one of my compo entries (Lala the Magical).

Hope you find it useful.
Re: Assets for the Nesdev Compo 2016
by on (#186799)
I know this is late, but maybe somebody can still use it for the Compo, or for any NES project.

This is a scanline counter sub-routine...

(Note: one scanline = 113.667 CPU cycles)

Code:
;load x with amount of scanlines to wait, should not be zero

Scanline_counter:

   ldy #11   ;2 (not included in cycle count till end)
-
   nop ; 2
   nop ; 2
   dey   ; 2
;branch not taken requires two machine cycles. Add one if the branch is taken
   bne -   ;3 (2 on last loop) =9*11-1...98

   txa ; 2 = 100
   lsr a ; 2 = 102 (set carry half of the time)
   bcc + ;2 or 3 (depending if branch taken) = 104/5
+
   nop ; 2 = 106/7
   dex   ; 2 = 108/9
   bne Scanline_counter ;3 (2 on last loop) = 111/12
      ; +2 (ldy at the top)=113/114 (as stated, one less on last loop)
      
   rts ; overhead, not counted...6
   
; short about 1 cycle every 6 lines, not counting the overhead (113.5 vs 113.667)
; examples
;ldx #6 = 5.98 scanlines
;ldx #60 = 59.90 scanlines
;ldx #240 = 239.64 scanlines
Re: Assets for the Nesdev Compo 2016
by on (#186841)
I forgot to mention... this code absolutely can not cross a page boundary. It would be best to place it exactly at the start ($8000) of the ROM, so that any expansion won't accidrntally throw off the cycle count. (By putting half of the code in one page, and the other half in another, causing branches to take an extra cycle).
Re: Assets for the Nesdev Compo 2016
by on (#187919)
Hi Nathan,

Thanks for posting this - I used it last night to figure out how to implement tokumaru's LZSS routine. It's a really nicely designed layout.

Really useful, thanks!
Re: Assets for the Nesdev Compo 2016
by on (#188050)
You're welcome. Glad somebody found it useful.