Coding NES Subroutines

preview_player
Показать описание
Learn all about programming subroutines in the 6502 assembly on the NES.

Code Challenge:
Submissions will be chosen from the comments through 1/22/2023 and the winner selected and pinned on 2/1/2023.

Music:
Evgeny Bardyuzha - Speed Freak
2050 - Nova
Luke Melville - After Midnight
Alchemorph - Raintown (My Love fore You) - Instrumental Version

Chapters:
0:00 Introduction
0:28 Subroutines Explained
2:07 The Stack
5:08 Using Parameters
6:49 Coding Challenge
Рекомендации по теме
Комментарии
Автор

Here's my submission for the challenge, it's my first time programming in 6502 so there might be mistakes (I'm more familiar with 68K)

;
; pickup_refill
;
; Refills player health or weapon from a pickup
;
; Parameters:
; $00: pickup type (health = 0, weapon = 1)
; $01: pickup size (small = 0, large = 1)
;
; Notes:
; - Player's health is stored at $0100
; - Player's weapon charge is stored at $0101
;
pickup_refill:
; get pickup type in X so desired player stat is at $0100, X
ldx $00
; load stat value into A
lda $0100, X

; get pickup size, add appropriate amount to A
ldy $01
beq small_pickup
; large pickup: grant 25 health/weapon
adc #15
; (intentional fall-through to add rest of value)
small_pickup:
; small pickup: grant 10 health/weapon
adc #10

; if we went over 100 health/weapon, limit to 100
cmp #100
bmi save_value
lda #100

save_value:
; store new health/weapon value
sta $0100, X

rts

aidangarvey
Автор

I love watching these thinking "one day I'll do this" knowing full well I will not....yet I will watch this kind of magnificently crafted educational lesson all day long.

AndyScott
Автор

The editing, information and quality are top notch

guillermomoreno
Автор

Holy crap this channel is underrated AF. Watched the video first, noticed the like count/views second. Both of these should be x100 at least! You just earned a sub sir.

MerrStudio
Автор

First time watching your channel. Big ups to your style!

This video is basically a course mini-lecture on teaching programming, while still being interesting to watch for those of us students who aren't doing the homework.

scottwilliams
Автор

I’m addicted to these videos. I have way too many other things going on to ever hope to have time to mess with this too but you’re subject matter presentation is next level. So much info crammed into a 15-20 min video and it doesn’t feel overwhelming. Great job man.

MrBoogerblood
Автор

You make me want to program a NES game! Really great and clear explanation so thank you!

DSage
Автор

What a great start to the year! NesHacker and Retro Game Mechanics Explained posting new videos on the same day!

ajhieb
Автор

Funny when you say 6502 assembly the first thing that comes to mind is Commodore 64 programming, but that was 10 year old me back in the day having no idea that 6502's were in just about everything by 1988. Had I been 10 years older I probably could have put all that learning to use professionally, but alas it was my gateway to x86 assembly language. I made so many inline assembly routines inside C and Pascal programs back then, back when every cycle mattered.

djrmarketing
Автор

Found your channel yesterday while looking for 6502 documentation online, and your 6502 Assembly Crash Course playlist this is part of has been unimaginably helpful to me! I've also got VS Code set up with fceux64 using your tutorial, so it is time to crank out the classic Game of Life! :D

sanderbos
Автор

I been working on super mario bros hacks on and off for a couple years and even knowing the asm i do now your videos always teach me something new. Thank you so much

ebs
Автор

あけましておめでとうございます、 NESHacker!
Kind of tied up with attempts at modern, wannabe-retro game dev right now (trying to write a better shader for simulating a high end CRT), but you have me inching closer and closer to doing a NES homebrew game jam.
Thank you for all of the valuable NES dev info!

maverick_loneshark
Автор

If your subroutine is simple/straightforward enough, you can often pass arguments in registers!

mykalimba
Автор

Omfg, last month everything I've been doing is digging info about old consoles, especially the NES and programming 6502 cpu. Planned to develop a small NES game to touch it myself for better understanding and HERE YOU ARE - THE HERO! Right in time! Many thanks for you exceptionally helpful material! Please, keep going

JustixLoL
Автор

I was waiting this so much! Love your videos!

asoundund
Автор

Just love explanation clarity, EXCELLENT VIDEO, can't wait for more! (I eddited and removed INCORRECT stuff about pushing ppu status to the stack, that I writen before to awoid confusion)

traprt
Автор

I think you're reaching a good pace/level of explanation with these last few videos... tbh I was a bit worried when inx/dex took up 3 minutes in the first one haha. Great to see the very practical example of using parameters especially.

sprobertson
Автор

Health: $00FF
Energy: $00FE
32 bytes in the zero page for subroutine parameters like you would do.
1 byte ($0000) actually used for this function. the High nybble (Bits 4 - 7) will be type, the Low nybble (Bits 0 - 3) will be the amount. This method would allow 16 types and 16 amounts in case it will be used elsewhere, however in this case it will be optimised for this challenge

refill:
lda #$F0
and $00 //Obtain the high nybble to dictate what type to add to
lsr
lsr
lsr
lsr
tax
lda #$19 //Load 25 into Accumulator. This is the small amount
pha
lda #$0F
and $00 //Obtain the low nybble to dictate what amount to add to the variable
beq skip_big_refill //If 0, then it is the small amount, otherwise add 25 to the value to get the medium amt
pla
adc #$19 //Add 25 to Accumulator, making the amount from earlier to the medium amount, 50
pha
skip_big_refill:
pla
clc
adc $FE, x //Add the corresponding variable (Health or Energy) to Accumulator
cmp #$64 // check if result is more than 100. if so, set the Accumulator to 100
bpl skip_clamp
lda #$64
skip_clamp:
sta $FE, x //finally, store the accumulator to the variable
rts

(Fair note, its been a while since ive coded 6502 asm, so my syntax might be off. dont really have a way to verify it admittedly but i hope it works)
(Edit: Forgot to shift the upper nibble parameter 4 times to the left)

repeaterlanes
Автор

I know this is an old video but i really like the format. Making the viewer do a little homework for a contest is legit awesome too. Love seeing atuff like this. Only gripe is i feel the vids are a little on the short side. Right when the itch is a out satisfied you pull the plug. Darnit. Lol

gadgetdeez
Автор

I never subscribed so fast in my life. This is incredibly well done.

tmanley