Intermediate 6502 Tutorials

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
Oziphantom
Posts: 1565
Joined: Tue Feb 07, 2017 2:03 am

Intermediate 6502 Tutorials

Post by Oziphantom »

New Tutorial series.
This is for people who want something beyond ; this is what each instruction is and how each one works. This is how you add 2 numbers etc. I'm primarily focusing on RAM rich designs, but I will mention and call out methods that benefit ROM rich and/or RAM constrained design such as the NES.

The first project/contrivance is a Fixed Windowing system.

https://youtu.be/JWYSFKPZQ8U
User avatar
zanto
Posts: 57
Joined: Sun Mar 07, 2021 11:15 pm
Location: Rio de Janeiro, Brazil

Re: Intermediate 6502 Tutorials

Post by zanto »

Cool! I'll check it out! I hope I'll be able to follow this :D There are a lot of help for the very basic 6502 stuff, which I feel like I have some understanding, but when it comes to slightly higher level stuff, either it's hard to find or it's in a way I don't really understand. I'd also love to learn some hot 6502 tips and tricks, like how to solve common problems or do stuff efficiently.
Oziphantom
Posts: 1565
Joined: Tue Feb 07, 2017 2:03 am

Re: Intermediate 6502 Tutorials

Post by Oziphantom »

Episode 2 of Intermediate 6502 https://youtu.be/5h-Tc_QYBkQ basic break down of a task and weigh options
Oziphantom
Posts: 1565
Joined: Tue Feb 07, 2017 2:03 am

Re: Intermediate 6502 Tutorials

Post by Oziphantom »

Oziphantom
Posts: 1565
Joined: Tue Feb 07, 2017 2:03 am

Re: Intermediate 6502 Tutorials

Post by Oziphantom »

Episode 4 of Immediate 6502 is ready, This time Dialogs and Widgets with Slot Allocation and Upper 3 bit branch trees. https://youtu.be/reobVBtf9QQ
Oziphantom
Posts: 1565
Joined: Tue Feb 07, 2017 2:03 am

Re: Intermediate 6502 Tutorials

Post by Oziphantom »

To help with the intermediate6502 tutorials, people asked for 64TASS series. Here is Episode 1 where I explain how it iterates anything with multiple values for you https://youtu.be/4gwOWiWhKC8
puppydrum64
Posts: 160
Joined: Sat Apr 24, 2021 7:25 am

Re: Intermediate 6502 Tutorials

Post by puppydrum64 »

So here's a topic I'm not sure how to look up because I don't really know what it's called. But the idea is this: Making text, etc. appear every X frames and space them out equally. For example I have my text box code:

Code: Select all

NMI_DRAWTEXT:
	;draw one letter per NMI.

	LDA $2002
	LDA #$21
	STA $2006
	LDA tempLetterPos
	STA $2006
	LDY textTracker
	
initText:
	;LETTERS GET DRAWN A LITTLE TOO FAST, LET'S SLOW IT DOWN!
	LDA randomTimer			;doubles as a frame counter, gets incremented at the end of every NMI
	AND #$01
	BNE doneWithText		;only draw letters every other frame. 
	
	LDA textStrings,y
	CMP #$FF
	BEQ Terminator
	STA $2007
	INY
	STY textTracker
	INC tempLetterPos
	JMP nowScrollReset
	
Terminator:
	LDY #$00
	STY textTracker
	LDA UpdateFlags
	AND #DONE_UPDATING_TEXT
	STA UpdateFlags

nowScrollReset:
	lda #$00
	sta $2005
	sta $2005

doneWithText:
Using AND #$01 works for drawing every other frame since every other number in binary ends in 1. But this doesn't really work for larger numbers. If I were to use AND #$80, either everything gets drawn immediately or there's a long wait time. #$FF works like #$01 except only once every 255 frames. Getting things to work in between seems to be difficult. I think that this topic, and timing in general, would make a good tutorial video.
Oziphantom
Posts: 1565
Joined: Tue Feb 07, 2017 2:03 am

Re: Intermediate 6502 Tutorials

Post by Oziphantom »

you can only use something that incs every frame as a power of two timer.
So

Code: Select all

LDA randomTimer
AND #%00000001 ; every 2 frames
BNE _noText 


AND #%00000011 ; every 4 frames
BNE _noText 

AND #%00000111 ; every 8 frames
BNE _noText

etc
the AND masks of the bits and then those remaining bits are only 0 1 once per each cycle of that size.

The other way is just make another timer, and

Code: Select all

dec TextTimer
bpl _noText
   lda #frameRate-1
   sta TextTimer
   jsr drawNextLetter
_noText
this lets you have any number you want, so if you wanted 60 then you can have it.
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Re: Intermediate 6502 Tutorials

Post by unregistered »

puppydrum64 wrote: Tue Jun 01, 2021 6:44 pm Using AND #$01 works for drawing every other frame since every other number in binary ends in 1. But this doesn't really work for larger numbers.
Actually that can easily work infinitely long if you keep randomTimer in a single byte, bc after #$FF, 1111 1111, comes #$00, 0000 0000.
puppydrum64
Posts: 160
Joined: Sat Apr 24, 2021 7:25 am

Re: Intermediate 6502 Tutorials

Post by puppydrum64 »

Oziphantom wrote: Wed Jun 02, 2021 1:30 am you can only use something that incs every frame as a power of two timer.
So

Code: Select all

LDA randomTimer
AND #%00000001 ; every 2 frames
BNE _noText 


AND #%00000011 ; every 4 frames
BNE _noText 

AND #%00000111 ; every 8 frames
BNE _noText

etc
the AND masks of the bits and then those remaining bits are only 0 1 once per each cycle of that size.

The other way is just make another timer, and

Code: Select all

dec TextTimer
bpl _noText
   lda #frameRate-1
   sta TextTimer
   jsr drawNextLetter
_noText
this lets you have any number you want, so if you wanted 60 then you can have it.
Derp. I knew I was having a brain fart and I couldn't remember how this was done. Funnily enough I think I've done this exact thing before.
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Re: Intermediate 6502 Tutorials

Post by unregistered »

unregistered wrote: Fri Jun 04, 2021 3:56 pm
puppydrum64 wrote: Tue Jun 01, 2021 6:44 pm Using AND #$01 works for drawing every other frame since every other number in binary ends in 1. But this doesn't really work for larger numbers.
Actually that can easily work infinitely long if you keep randomTimer in a single byte, bc after #$FF, 1111 1111, comes #$00, 0000 0000.
Even if randomTimer is used as, say, a 16bit variable, just focus your drawing-every-other-frame code by keeping focus on just randomTimer+0; bc the low byte’s bit0 will keep alternating between 0 and 1, after incrementation, regardless of randomTimer being a “low” byte. :)
Post Reply