Feedback wanted on my first NES project-a simple Hello World

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
mattjustice
Posts: 3
Joined: Mon Aug 26, 2019 3:59 pm

Feedback wanted on my first NES project-a simple Hello World

Post by mattjustice » Mon Aug 26, 2019 4:04 pm

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!

User avatar
pubby
Posts: 550
Joined: Thu Mar 31, 2016 11:15 am

Re: Feedback wanted on my first NES project-a simple Hello W

Post by pubby » Mon Aug 26, 2019 4:47 pm

Good work.

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

Code: Select all

    ldx ship_x
    inx
    stx ship_x
You can use INC instruction instead.

Code: Select all

    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: Select all

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.

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

Re: Feedback wanted on my first NES project-a simple Hello W

Post by mattjustice » Tue Aug 27, 2019 4:15 am

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 ... e9cb363a74. If you have a chance to review, let me know if that is generally what you had in mind. Thanks!

User avatar
pubby
Posts: 550
Joined: Thu Mar 31, 2016 11:15 am

Re: Feedback wanted on my first NES project-a simple Hello W

Post by pubby » Tue Aug 27, 2019 10:00 am

Yeah you did the table thing perfectly :beer: :)

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

Re: Feedback wanted on my first NES project-a simple Hello W

Post by mattjustice » Tue Aug 27, 2019 10:17 am

Great; thanks again for your help! I like the lookup table approach.

Post Reply