-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|427|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
SoCoder -> Blogs Home -> Blogs


 
cyangames
Created : 16 May 2017
 

My Journey into NES Development

AKA Ryan learns Assembly OMG!

So, time for that big final step into assembly.

I've not really managed to get a good grip on ASM before and last years experience with the Atari 2600 was fairly nightmarish, but the NES, it seems, might be slightly more friendly. Hardware sprites and all sorts of things going on.

It's going to be a big journey this one I think. but so far I have a sprite...moving...on the screeen!

Wooo! Roll on joypad input!


 

Comments


Wednesday, 17 May 2017, 03:37
Jayenkai
Oooooh!
Wednesday, 17 May 2017, 03:56
spinal
I always wanted to do nes dev. never bothered though. I wish you success!
Wednesday, 17 May 2017, 09:18
cyangames
Thanks Spinal, If my code is looking reasonable by the end of it I'll post it here with comments 'n' stuff

I'm going to attempt to port my old OUYA game Invasion VS onto the system. I've figured out how to access the background layer late last night and have been tinkering with pixels since then, albeit mostly in photoshop. But it gives me a good target to aim at!

As it's my first try I'll be sticking with mapper 0 and not scrolling the screen, the nice thing about Invasion VS was tat it was a pretty simple but playable game back in the day so should be a good on to port over first.

Here's those images I mentioned earlier:





Back to transferring them pixels for me now!
Wednesday, 17 May 2017, 16:28
cyangames
So, learning about nametables today and the odd colour mapping that goes on with the backgrounds. It compares oddly to the gameboy color which has so many more options.

Firstly, you are limited to 4 palettes, not the bonutiful 8 that I've been used to of late, which can be worked around but yeah, is a tad limiting.

Secondly, background colour maps aren't based on a per tile basis, it's each group of 2 x 2 tiles instead. Which changes how things can display, at least without hacking sprites over the top of it anyhoo!

Today has been more about learning the tools I'll need to use to get things on the screen as opposed to much more ASM but it's proven handy to know the limits of the hardware a bit more.
Friday, 19 May 2017, 02:13
cyangames
Getting there with the title screen. So far it seems to be just sequential access per tile only, which is a little odd, just firing a stream of data to a single memory address. I'm wandering exactly how you change set background tiles in an X,Y fashion.

But, I've written up a two stage loop and got the equivalent of a while loop running in a subroutine, so, it's getting there. But, as expected, it's a slow process.

Hopefully tonight I'll get the hang of strobing the joypad (sounds kinky XD) then maybe generate a sound effect over the weekend?


Friday, 19 May 2017, 03:14
Jayenkai
Sounds awfully complicated, but I imagine that using raw assembly helps balance any significant speed issues.

You're just going to have to learn to update your backgrounds in a very specific order
Friday, 19 May 2017, 05:42
cyangames
Yeah, it's a little odd, it's like gameboy programming but harder

My head is still adjusting to ASM and I think there was a way to skip scanlines by setting the PPU to increment by 32 instead of just 1. That would give a way to update via X and Y.

Maybe tonight XD
Friday, 19 May 2017, 07:10
rockford
Good luck fella
Sunday, 21 May 2017, 15:49
cyangames
Had a bit more of a play around with it tonight, got joypad input working in a little way, just so you can select options then press start to go to what will probably be the game screen.



I still need to get something down to store the last joypad state into a single byte so I can detect keypresses nicely and hopefully safely!
Sunday, 21 May 2017, 16:13
Jayenkai
Awesome!
Looks like you're picking it up nice and fast.

Get that Cartridge Maker lined up!!!!
Sunday, 21 May 2017, 16:38
cyangames
It's coming along. But there's still so much to learn. I reckon it could be done in a few weeks though, fingers crossed!

Game Screen Bkg Tomorrow night. that's the aim for the moment.
Monday, 22 May 2017, 08:33
cyangames
Thinking up pseudo random number generators now.....omg
Monday, 22 May 2017, 09:18
Jayenkai
Could you get away with something like Millisecs() Mod Max?
Monday, 22 May 2017, 17:04
cyangames
I'm going for something a little more simple (I think)

Loading up the A reigster with a value,
Adding the current frame number to it which I'm stoing in a seperate memory address
Adding the players X co-ordinate
Rotating the values left by one.

Each frame, it's not exactly linear randomness but it'll do and is slightly influencable by the player in-game I guess...

Also, here's a lil progress GIF


Tuesday, 23 May 2017, 00:36
Jayenkai
Should suffice. Game-random doesn't need to be perfect. As long as it feels random, that's good enough.
Tuesday, 23 May 2017, 01:53
cyangames
That's the hopes!

It should at least almost always be a different, unpredictable value each frame.

Tonight / Tomorrow I'll be bunging on the shooting bits 'n' bobs and sorting out those attribute tables for something closer to my original photoshop file.
Thursday, 25 May 2017, 12:31
cyangames
Taken a couple of days away from it, mostly due to some crazy headaches, roll on tonight ( hopefully, so much bloody housework to do! )
Monday, 29 May 2017, 17:40
cyangames
Got an hour in tonight, I now have an okay way to trap for keys states on a previous frame, although It's not byte optimised, it should be okay for this size of a project.

I need to comment my code more!

Note to self -> get and set bits with AND and EOR....

stackoverflow.com/questions/14410401/how-do-i-set-bits-to-0-with-boolean-arithmetic
Tuesday, 30 May 2017, 17:10
cyangames
Learning more again tonight, looks like I was doing sprites in a risky way, which I wouldn't have noticed until my code was a bit larger, the vBlank Time on the NES is a lot shorter than on the gameboy and I was haphazardly updating sprites throughout the frame loop, which would be really bad news if say, the vblank loop had ended, then that would break a bunch of stuff.

So, that's all done at the start of each frame now and I have a method write values to the background at set X and Y locations in memory. Again, all being done before anything else, due to the short v-blank period.

It's showing that my randomizer is working a treat though, huzzah!


Woo! I have my round time remaining thing working now. Never thought I'd get so excited about such tiny steps but I guess learning ASM is all about tiny steps.
Wednesday, 31 May 2017, 14:15
cyangames
Collision detection GET!


Wednesday, 31 May 2017, 15:21
Jayenkai
woohoo!
Wednesday, 31 May 2017, 16:57
cyangames
Aaand because I just could not help myself now , a NES flashcart has been bought. For testing on real hardware, because that is where it's at XD

Also, now not buying anything else for the month, heheh...heh.
Friday, 02 June 2017, 07:01
rockford
Cool
Friday, 02 June 2017, 17:54
cyangames
Turned the collision routine into a sub-routine so it's a little less unwieldy, removed shots upon impact and for the first time...there's scoring!



I should probably make the CPU player move now really.
Saturday, 03 June 2017, 01:01
Jayenkai
Evil bastard just sits there, taunting you!!
Saturday, 03 June 2017, 16:00
cyangames
The green bastard is marginally more evil now tonight



Next up, actual enemies, power-ups, more collisions and, perhaps explosions?
Saturday, 03 June 2017, 16:03
Jayenkai
Lovely stuff!
Sunday, 04 June 2017, 16:46
cyangames
Aww nuts.

Just spent a while implementing a pause function, but for some reason the emulator was blacking out.

So I deleted the lines of code, re-assembled it.. then remembered my emulator was PAUSED!

D'oheth!

Ahh well, here's an image of part of the dev environment for me


Wednesday, 07 June 2017, 16:50
cyangames
So, I got my enemies spawning in tonight, and, with some cunning nametable usage they now appear to smoothly scroll in and out of view. Also, the NES Flash Cart showed up at work today, on my day off, ha! Will try to set it up and post some screenies tomorrow night though



I miss having a window layer and other things that I took for granted with Gameboy Dev! But It's cool that there's ways around it still on the NES

Still haven't even hit 3kb!
Wednesday, 07 June 2017, 16:56
Jayenkai
Amazing that the Gameboy has more functionality. I guess that they learned what functions were needed when trying to dev for the NES, and implemented those ideas into the Gameboy.
Wednesday, 07 June 2017, 17:00
cyangames
Yeah, even though it was only 5 years of a gap between the two consoles and, well, a handheld vs a standalone machine. The gameboy z80 variant processor even has native support for 16-bit numbers of sorts which is pretty cool for an 8bit machine.
Thursday, 08 June 2017, 05:31
cyangames
YAY! It has arrived! Will be digging around to find my NES and cables then tonight.
Thursday, 08 June 2017, 16:24
cyangames
Unless I end up with the house work duties all night again....Graghhhhh, but on the up side, the Everdrive Came pre-loaded with a shed load of working ROMs, which is really cool! Fingers crossed I'll be able to test it out tomorrow night instead then
Thursday, 08 June 2017, 16:29
Jayenkai
Good luck!
Don't forget the piccies!!!
Thursday, 08 June 2017, 16:40
cyangames
Will do
Friday, 09 June 2017, 02:03
cyangames
So, spent an hour under the stairs attempting to find my NES this morning. Found 2 controllers, a zapper and....No NES...The search begins again tonight!
Friday, 09 June 2017, 03:52
Jayenkai
Uhoh!!!
Friday, 09 June 2017, 16:17
rockford
Controllers without a console is NEVER a good thing

At least they aren't too stupidly expensive on Fleabay.
Saturday, 10 June 2017, 09:48
cyangames
Not a great day today >

Finally found the NES, yay, that's good!
Found the power adapter I bought recently, yay!

Plugged it all in, blinking light of doom
TV refuses to tune into the signal upon resetting the machine unless I fine-tune it every god damned reset
Decide, okay, lets open up the NES to sort out the pin connector, that's probably the issue here.
No screw drivers fit / are longer enough.

Head into town to purchase air duster and screwdriver.
air duster get, yay!
screwdriver get, yay. asked for standard philips screw driver, the guys insists this one should be fine.

head home in the rain, doop dee doop

the new screw driver... is long enough! But, guess what. It's the wrong size... for fucks sakes....

Load up some other cartridges, they seem to work occasionally now, at least that's something.

Everdrive Card, not even once has it loaded up or got past the blinking red LEDs.

Pretty bloomin' grumpy now and in no mood for dev stuffs... FFS...

Hoping to get the cart tested in a friends NES sometime soon to check if it works on his. Might see if he can sort my NES out also tbh assuming the everdrive is in working order. But errmerrrrgerrddd.

So, err, yeah, no pic, just frustration.
Saturday, 10 June 2017, 10:00
Jayenkai

That's a bit of a crappy day.
Hopefully the cart isn't bodged.
Saturday, 10 June 2017, 10:04
cyangames
That's what I'm hoping too, otherwise I need to send it back and open up an ebay returns and refunds case and...well. it becomes more annoying.

I've left a message for the seller to let them know I'm having a few difficulties and just want to make sure it's (not / is )that my NES is having difficulties with the cart.
Saturday, 10 June 2017, 11:31
spinal
What I remember from back in the olden days. 99% of times its poor contact with the clockout chip that causes the flashing. I remember there's a mod to completely disable the chip, simple just cut one of the legs I think. Other than that, the connector needs a damn good clean or replacement.

Usually I got my games to work by pushing down on them hard then stick 2 cassettes in the top, one in a box, one out of the box.
Sunday, 11 June 2017, 08:08
cyangames
Turns out, that yes, it was my NES, phew!



Although for some reason my controller code doesn't work on device, but it does on emulators, strange!

Either way, just glad the thing works!
Sunday, 11 June 2017, 08:43
spinal
image doesnt work
Sunday, 11 June 2017, 13:09
cyangames
Whoops, updated just now.
Sunday, 11 June 2017, 13:11
Jayenkai
Woohoo!

Odd that the controller doesn't work, though.
Sunday, 11 June 2017, 14:05
cyangames
Turns out it only works on certain even numbered requests in the program counter, at least, according to the NESDev wiki.

Really odd, I was pretty confused when I saw it and thoughtinitially...somethings up. But it runs pretty much every other commercial game without issue so my code needs some refactoring then.
Sunday, 11 June 2017, 14:57
rockford
At least it's working - to a degree
Thursday, 15 June 2017, 17:10
cyangames
Got the controller working!
Thursday, 15 June 2017, 17:47
Jayenkai
\o/yeay\o/
Wednesday, 21 June 2017, 15:36
cyangames
I think I've figured out exactly where I was going wrong with my coding thus far, which is handy news for me, frustratingly it means a fairly big rewrite, which is kinda scary as I'm still inexperienced with ASM but should result in the game being a whole lot more possible!

It's mostly with how I'm handling things in the wrong areas of code (vblank, etc) but moving it from one place to another seems risky!
Wednesday, 21 June 2017, 15:38
Jayenkai
That's one of the important things to remember when learning new languages.

You should never be afraid to scrap it all and restart from scratch, once you've built up your experience a little more.

Restarts are good!
Wednesday, 21 June 2017, 16:37
cyangames
It's pretty tough to do but yeah I'll have to do something about it sometime. I've just figured out exactly what the issue was, which was me overrunning the length of time between vblanks during when i had the screen turned off, so it never turned back on, on the actual NES, but the emulators ignored it, ha!

I reckon some re-organisation of my code should sort it out, possibly not a complete re-start after all.
Thursday, 22 June 2017, 03:17
cyangames
Aww Yeahhh baby large loading GET!


View on YouTube
Thursday, 22 June 2017, 03:58
Jayenkai
That's super awesome!!!