It is currently Mon Sep 16, 2019 2:00 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Mon Aug 26, 2019 4:04 pm 
Offline

Joined: Mon Aug 26, 2019 3:59 pm
Posts: 3
Hi,

I'm new NES development. Last week I decided to take a shot a writing a "Hello, World" style program as a prelude to writing a real NES game. I realize there are already a bunch of starter projects, templates, and so forth out there, and those were helpful to me (Brad Smith's NES-ca65-example and Damian Yerrick's NES project template in particular - thanks guys!). I just find that starting with a blank file and typing in each statement, making sure I understand it all helps me understand better. So I chose to write my own "Hello, World."

My goals were to display a background with a text message, and display a single sprite that I could move around with the controller's D-pad. I also went for easily understandable code, not the most efficient code.

If anyone has time and interest, I'd like to hear your feedback. Given the context of what I was trying to do here, do you see anything that's problematic?

Here's the code: https://github.com/matthewjustice/hello-nes

Thanks!


Top
 Profile  
 
PostPosted: Mon Aug 26, 2019 4:47 pm 
Offline
User avatar

Joined: Thu Mar 31, 2016 11:15 am
Posts: 529
Good work.

I can only give a quick look at it. Here are some observations:

Code:
    ldx ship_x
    inx
    stx ship_x

You can use INC instruction instead.

Code:
    lda ship_orientation
check_ship_up:
    cmp #SHIP_ORIENTATION_UP
    bne check_ship_down
    ; Ship is up
    ldx #TILE_SHIP_UP_DOWN
    stx tile_number
    ldx #OAM_ATTR_PALETTE_4
    stx oam_attribs
    jmp write_oam_data


It tends to be better to use tables for this. In general, NES programming is about how efficiently you can use tables. A table based approach might look like this:

Code:
ldy ship_orientation
lda ship_sprite_table, y
sta oam, x
inx
lda ship_attr_table, y
sta oam, x


I do not see you clearing OAM in 'prepare_oam'. Typically, you'd need to move all unused sprites outside of the visible area every frame. Obviously you don't need that for this project, but in the future you will.


Top
 Profile  
 
PostPosted: Tue Aug 27, 2019 4:15 am 
Offline

Joined: Mon Aug 26, 2019 3:59 pm
Posts: 3
pubby - Thanks for taking the time to review the code and provide your feedback!

INC - Yes, good catch.

Clearing OAM - I'll keep that mind for future projects, thanks.

Tables - I'd like to understand this better. Are you recommending that I keep a table where I can quickly lookup appropriate values for OAM based on game state? For example, I know that if the ship's orientation is LEFT then I need to use tile 1 and apply the vertical flip attribute - so I could store all that in a table and avoid the comparison/branching logic at runtime. Is that the general idea?

Thanks again!

[Edit] - I tried a table-based approach, which cleaned up the code a good bit and should reduce runtime cost. Here's the change on GitHub - https://github.com/matthewjustice/hello-nes/commit/90fd58bc0d6cebf3b9e7c8b1773cd0e9cb363a74. If you have a chance to review, let me know if that is generally what you had in mind. Thanks!


Top
 Profile  
 
PostPosted: Tue Aug 27, 2019 10:00 am 
Offline
User avatar

Joined: Thu Mar 31, 2016 11:15 am
Posts: 529
Yeah you did the table thing perfectly :beer: :)


Top
 Profile  
 
PostPosted: Tue Aug 27, 2019 10:17 am 
Offline

Joined: Mon Aug 26, 2019 3:59 pm
Posts: 3
Great; thanks again for your help! I like the lookup table approach.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 3 guests


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group