It is currently Sun Sep 23, 2018 2:34 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 275 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6 ... 19  Next
Author Message
PostPosted: Sun Jun 24, 2018 6:14 pm 
Online
User avatar

Joined: Fri May 08, 2015 7:17 pm
Posts: 2266
Location: DIGDUG
Quote:
Is it a separate engine, like the Address? Or is it a form of abilities like RAM or DATA styles?

Like how does the register of A X Y [and P Z ] works? Or they work as a special form of variables like, a temporary placement of " A = X + Y" until the new replacement happens like "STA" or "LDA"?


these registers exist inside the CPU.

It holds a value, 8 bits each.

This value can be whatever your program wants it to be. As a temporary variable. As an address (pointer). As a counter.

And when I say temporary, I mean very very briefly. As the program runs the A register will change values hundreds of times a second, depending on what the program is doing.

Quote:
like the A represent the stages of Mario Bros. your in, X represent your health, and Y represent your Mario life?


Ok, let's say you've chosen RAM address 31 to hold the health of Mario. Let's say Mario gets injured, so his health goes down 1. You can decrease the value of 31 by loading it into the A register and subtracting 1, then storing it again at RAM 31.

LDA 31 ;load from 31
SEC ;set the carry flag, for subtraction
SBC #1 ;subtract 1
STA 31 ;store to 31

(There is another way to do this, but I chose to use the A register for example)

The health only is used by A for a brief moment, then A goes on to do other things.

_________________
nesdoug.com -- blog/tutorial on programming for the NES


Top
 Profile  
 
PostPosted: Sun Jun 24, 2018 7:19 pm 
Offline

Joined: Sun Jun 17, 2018 6:41 pm
Posts: 118
dougeff wrote:
Quote:
Is it a separate engine, like the Address? Or is it a form of abilities like RAM or DATA styles?

Like how does the register of A X Y [and P Z ] works? Or they work as a special form of variables like, a temporary placement of " A = X + Y" until the new replacement happens like "STA" or "LDA"?


these registers exist inside the CPU.

It holds a value, 8 bits each.

This value can be whatever your program wants it to be. As a temporary variable. As an address (pointer). As a counter.

And when I say temporary, I mean very very briefly. As the program runs the A register will change values hundreds of times a second, depending on what the program is doing.

Quote:
like the A represent the stages of Mario Bros. your in, X represent your health, and Y represent your Mario life?


Ok, let's say you've chosen RAM address 31 to hold the health of Mario. Let's say Mario gets injured, so his health goes down 1. You can decrease the value of 31 by loading it into the A register and subtracting 1, then storing it again at RAM 31.

LDA 31 ;load from 31
SEC ;set the carry flag, for subtraction
SBC #1 ;subtract 1
STA 31 ;store to 31

(There is another way to do this, but I chose to use the A register for example)

The health only is used by A for a brief moment, then A goes on to do other things.


Is register is inside everything programming-wise? Or it's selective?

So it's the same as:

JOE = 10

ROB = 5

JUMP = JOE + ROB

IF JOE == ROB
GOTO @NAME

???

Or is it pretty much the same, except the difference is the NES CPU can only do 3 to 5 variables instead of infinite? I learn this kind of program styles in SmileBASIC.


Top
 Profile  
 
PostPosted: Sun Jun 24, 2018 7:27 pm 
Offline
User avatar

Joined: Thu Apr 23, 2009 11:21 pm
Posts: 927
Location: cypress, texas
DocWaluigean wrote:
Thanks for PDF!

But this is what I don't understand.

Is it a separate engine, like the Address? Or is it a form of abilities like RAM or DATA styles?

Like how does the register of A X Y [and P Z ] works? Or they work as a special form of variables like, a temporary placement of " A = X + Y" until the new replacement happens like "STA" or "LDA"?
I don't like to say this much, but can you explain like if I'm in Elementary School to help me understand about register? [It's very owned variables, like no other regular variables can use?]

Or it's like a "magic effects" but in programming, like the A represent the stages of Mario Bros. your in, X represent your health, and Y represent your Mario life?
I'm sorry I can't explain registers to you in elementary school logic because I didn't learn about registers until college. But, I can try. :)

The processing chip that the NES uses is called the 2A03. The 2A03 is a special type of the 6502 processing chip. (For instance, it doesn't have the b flag in its status register and its d flag is pointless too, but those aren't important now.) The three 6502 registers I'm attempting to explain are A, X, and Y. Each of the registers are created with 8 bits. Every bit comes from a transistor. If a bit's transistor holds an electrical charge, the bit is set and that translates into a 1. Otherwise, the bit's transistor lacks an electrical charge then the bit is clear and so we have a 0. Ever hear of computers being all 1s and 0s? :) The numeral system Binary is an easy, but lengthy way, of telling the NES's 2A03's A register what to hold. If your program tells the NES: lda #%00000001 that will set bit0 of register A and clear register A's bits 1 through 7.
Bits in a register are named | bit7 | bit6 | bit5 | bit4 | bit3 | bit2 | bit1| bit0 |. Yes, that's right to left, but use it enough an you'll get used to it. :) There are two other ways of describing the value, you want loaded into register A, to the assembler: Hexidecimal and Decimal.

Before you click on this link read the paragraph sections above carefully. https://betterexplained.com/articles/numbers-and-bases/

Now I will close by saying that the three 8bit-wide registers A, X, and Y are located on the NES's 2A03 processing chip. There is the simplest way I can fully explain a register. Perhaps someone else can help you more. :)


Top
 Profile  
 
PostPosted: Sun Jun 24, 2018 7:59 pm 
Offline

Joined: Sun Jun 17, 2018 6:41 pm
Posts: 118
unregistered wrote:
DocWaluigean wrote:
Thanks for PDF!

But this is what I don't understand.

Is it a separate engine, like the Address? Or is it a form of abilities like RAM or DATA styles?

Like how does the register of A X Y [and P Z ] works? Or they work as a special form of variables like, a temporary placement of " A = X + Y" until the new replacement happens like "STA" or "LDA"?
I don't like to say this much, but can you explain like if I'm in Elementary School to help me understand about register? [It's very owned variables, like no other regular variables can use?]

Or it's like a "magic effects" but in programming, like the A represent the stages of Mario Bros. your in, X represent your health, and Y represent your Mario life?
I'm sorry I can't explain registers to you in elementary school logic because I didn't learn about registers until college. But, I can try. :)

The processing chip that the NES uses is called the 2A03. The 2A03 is a special type of the 6502 processing chip. (For instance, it doesn't have the b flag in its status register and its d flag is pointless too, but those aren't important now.) The three 6502 registers I'm attempting to explain are A, X, and Y. Each of the registers are created with 8 bits. Every bit comes from a transistor. If a bit's transistor holds an electrical charge, the bit is set and that translates into a 1. Otherwise, the bit's transistor lacks an electrical charge then the bit is clear and so we have a 0. Ever hear of computers being all 1s and 0s? :) The numeral system Binary is an easy, but lengthy way, of telling the NES's 2A03's A register what to hold. If your program tells the NES: lda #%00000001 that will set bit0 of register A and clear register A's bits 1 through 7.
Bits in a register are named | bit7 | bit6 | bit5 | bit4 | bit3 | bit2 | bit1| bit0 |. Yes, that's right to left, but use it enough an you'll get used to it. :) There are two other ways of describing the value, you want loaded into register A, to the assembler: Hexidecimal and Decimal.

Before you click on this link read the paragraph sections above carefully. https://betterexplained.com/articles/numbers-and-bases/

Now I will close by saying that the three 8bit-wide registers A, X, and Y are located on the NES's 2A03 processing chip. There is the simplest way I can fully explain a register. Perhaps someone else can help you more. :)


I thought 2A03 is primary used for default sound and audio creations engine inside NES.

So it's just an on and off switch like 0s and 1s? What is the differences or limitations compare to other engine like PS2 or PC or C#?


Top
 Profile  
 
PostPosted: Sun Jun 24, 2018 10:34 pm 
Offline
User avatar

Joined: Tue Jun 24, 2008 8:38 pm
Posts: 1955
Location: Fukuoka, Japan
I think you current issue right now is that before getting into understanding the nes you will need first to understand what is the 6502 and how to use it with assembler. Without that knowledge it will make it difficult to get to the interesting stuff, which is programming a game for the nes.

I did a quick search regarding some basic tutorial about 6502 and this page seems quite interesting:

http://skilldrick.github.io/easy6502/

It is a tutorial that allows to test online some assembler and see the result with their simulated machine. The concept is interesting since you can see the results right away and don't need to worry about how to use any compilers, linkers, nes architecture etc and can just focus on studying the 6502. I think this page will help you get a step further to programming for the nes. Once you understand about registers (A is the accumulator, X/Y are the index) and basic addressing, the nerdy nights should be a lot easier to follow.


Top
 Profile  
 
PostPosted: Sun Jun 24, 2018 11:33 pm 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10814
Location: Rio de Janeiro - Brazil
Yeah, it can be hard to learn everything at once: 6502 assembly, the NES architecture, the iNES file format, game logic... If you're feeling overwhelmed, starting out with pure 6502 assembly like Banshaku suggested is a good alternative.

When I first tried to learn 6502 assembly some 20 years ago I too was confused as hell... registers and status flags made no sense to my brain, which was only familiar with BASIC and Pascal. I was able to make a couple of NES demos with a bit of animation but it was a lot of trial and error, so I kinda gave up on that. It wasn't until I tried this 6502 simulator that everything finally made sense to me. I tried all the instructions and watched how they affected the processor's status, and once I understood what all the instructions did, I was able to code a few subroutines that performed actual tasks, such as multiply 2 numbers and return the result. That way I got the hang of how to use those simple instructions to perform more complex tasks, and felt ready to learn more about the NES architecture and everything else.


Top
 Profile  
 
PostPosted: Mon Jun 25, 2018 4:20 am 
Online
User avatar

Joined: Fri May 08, 2015 7:17 pm
Posts: 2266
Location: DIGDUG
Quote:
JOE = 10
ROB = 5
JUMP = JOE + ROB
IF JOE == ROB
GOTO @NAME


In Assembly, JOE, ROB, and JUMP could be RAM address, and @NAME is a label that the assembler will give a value to at assembly time. (Omitting some assembly directives to make it easier)

LDA #10 ;load A with 10
STA JOE ;store it to JOE
LDA #5 ;load A with 5
STA ROB ;store it to ROB
LDA JOE ;load A with JOE
CLC ;clear the carry flag, for addition
ADC ROB ;add ROB to A
STA JUMP ;store the result to JUMP
LDA ROB ;load A with ROB
CMP JOE ;compare A with JOE
BEQ @NAME ;branch to the label @NAME if equal

_________________
nesdoug.com -- blog/tutorial on programming for the NES


Top
 Profile  
 
PostPosted: Mon Jun 25, 2018 10:03 am 
Offline

Joined: Sun Jun 17, 2018 6:41 pm
Posts: 118
tokumaru wrote:
Yeah, it can be hard to learn everything at once: 6502 assembly, the NES architecture, the iNES file format, game logic... If you're feeling overwhelmed, starting out with pure 6502 assembly like Banshaku suggested is a good alternative.

When I first tried to learn 6502 assembly some 20 years ago I too was confused as hell... registers and status flags made no sense to my brain, which was only familiar with BASIC and Pascal. I was able to make a couple of NES demos with a bit of animation but it was a lot of trial and error, so I kinda gave up on that. It wasn't until I tried this 6502 simulator that everything finally made sense to me. I tried all the instructions and watched how they affected the processor's status, and once I understood what all the instructions did, I was able to code a few subroutines that performed actual tasks, such as multiply 2 numbers and return the result. That way I got the hang of how to use those simple instructions to perform more complex tasks, and felt ready to learn more about the NES architecture and everything else.


I'll try the 6502 Simulator, do I put the .nes or the .asm in it?


Top
 Profile  
 
PostPosted: Mon Jun 25, 2018 10:21 am 
Offline

Joined: Sun Jun 17, 2018 6:41 pm
Posts: 118
dougeff wrote:
Quote:
JOE = 10
ROB = 5
JUMP = JOE + ROB
IF JOE == ROB
GOTO @NAME


In Assembly, JOE, ROB, and JUMP could be RAM address, and @NAME is a label that the assembler will give a value to at assembly time. (Omitting some assembly directives to make it easier)

LDA #10 ;load A with 10
STA JOE ;store it to JOE
LDA #5 ;load A with 5
STA ROB ;store it to ROB
LDA JOE ;load A with JOE
CLC ;clear the carry flag, for addition
ADC ROB ;add ROB to A
STA JUMP ;store the result to JUMP
LDA ROB ;load A with ROB
CMP JOE ;compare A with JOE
BEQ @NAME ;branch to the label @NAME if equal


I'm starting to get it little.

So it would be "store #10 to JOE, confirming it into variable like JOE = 10"?

What about X and Y? So the A X and Y is like "three same variables, only purpose is to keep organized in human mentalities on which one is more important than others or certain things"???

My thoughts:

DIM ROOM

BED = 100
LAMP = 10

END ROOM

'===

DIM MAN

TIRE = 0
STR = 0
LVLSTR = STR + 1
HEALTH = 20

IF HEALTH == TIRE
GOTO @GAMEOVER

==================

.[[dim?]] $0001
ROOM:

LDA #100 ; Meaning? : Load as in "put" # 100 into variable / register A
STA BED ; Store the variable / Register A, which is stated as # 100 [like A = 100] into BED, which now turns into " BED = 100 " but in style of #100

LDA #10 ; in style of " A = 10 "
STA LAMP ; in style of "LAMP = 10"

ENA ROOM ; [End ROOM?????]

[[org. /dim.???]] $0002

MAN:

LDX #0
LDY #0

STX TIRE
STY STR

INC STR ; [[ INC X??? ]]

[[I'm a little fuzzed afterward about IF THEN part.]]


Top
 Profile  
 
PostPosted: Mon Jun 25, 2018 11:57 am 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10814
Location: Rio de Janeiro - Brazil
DocWaluigean wrote:
I'll try the 6502 Simulator, do I put the .nes or the .asm in it?

NES code won't work, because this emulates just the 6502 (and a rudimentary I/O system). It can load ASM files, but since each assembler is different, code written for other assemblers won't work on it without modifications. It has an integrated editor, so you'd normally type code in the program itself rather than in a separate text editor.

Banshaku's suggestion is probably a better place to start if you want an accompanying tutorial.


Top
 Profile  
 
PostPosted: Mon Jun 25, 2018 12:34 pm 
Offline
User avatar

Joined: Thu Apr 23, 2009 11:21 pm
Posts: 927
Location: cypress, texas
DocWaluigean wrote:
unregistered wrote:
DocWaluigean wrote:
Thanks for PDF!

But this is what I don't understand.

Is it a separate engine, like the Address? Or is it a form of abilities like RAM or DATA styles?

Like how does the register of A X Y [and P Z ] works? Or they work as a special form of variables like, a temporary placement of " A = X + Y" until the new replacement happens like "STA" or "LDA"?
I don't like to say this much, but can you explain like if I'm in Elementary School to help me understand about register? [It's very owned variables, like no other regular variables can use?]

Or it's like a "magic effects" but in programming, like the A represent the stages of Mario Bros. your in, X represent your health, and Y represent your Mario life?
I'm sorry I can't explain registers to you in elementary school logic because I didn't learn about registers until college. But, I can try. :)

The processing chip that the NES uses is called the 2A03. The 2A03 is a special type of the 6502 processing chip. (For instance, it doesn't have the b flag in its status register and its d flag is pointless too, but those aren't important now.) The three 6502 registers I'm attempting to explain are A, X, and Y. Each of the registers are created with 8 bits. Every bit comes from a transistor. If a bit's transistor holds an electrical charge, the bit is set and that translates into a 1. Otherwise, the bit's transistor lacks an electrical charge then the bit is clear and so we have a 0. Ever hear of computers being all 1s and 0s? :) The numeral system Binary is an easy, but lengthy way, of telling the NES's 2A03's A register what to hold. If your program tells the NES: lda #%00000001 that will set bit0 of register A and clear register A's bits 1 through 7.
Bits in a register are named | bit7 | bit6 | bit5 | bit4 | bit3 | bit2 | bit1| bit0 |. Yes, that's right to left, but use it enough an you'll get used to it. :) There are two other ways of describing the value, you want loaded into register A, to the assembler: Hexidecimal and Decimal.

Before you click on this link read the paragraph sections above carefully. https://betterexplained.com/articles/numbers-and-bases/

Now I will close by saying that the three 8bit-wide registers A, X, and Y are located on the NES's 2A03 processing chip. There is the simplest way I can fully explain a register. Perhaps someone else can help you more. :)


I thought 2A03 is primary used for default sound and audio creations engine inside NES.
The 2A03 does include an APU (Audio Processing Unit) for default sound and audio creations, but the 2A03's meat and potatoes is its 6502 processing architecture.

DocWaluigean wrote:
So it's just an on and off switch like 0s and 1s?
Yes, registers on the NES are just groups of 8 "on and off" switches.

DocWaluigean wrote:
What is the differences or limitations compare to other engine like PS2 or PC or C#?
I've never programmed on the PS2, but every computer (i.e. PS2 or PC) has at least one processing chip that contains a number of registers. After you write a program in BASIC you have to "compile" it in order to run your program. A compiler takes your programming code (i.e. BASIC code) and translates it into assembly language that's able to run on the processing chip(s) that your compiler is working with and then into 1s and 0s so that it can be run on whatever computer-type-machine you compile it on. Some of those 1s and 0s are fed into registers that are within whatever processing chip(s) your computer-type-machine uses. C# is a programming language that needs to be translated by a compiler.

The NES is different, for me, because I try to write code for the NES using assembly language. Assembly language is already assembly language; it doesn't need to be translated by a compiler. Assembly language does, however, need to be assembled into 1s and 0s by an assembler. But, assembling is much more precise than compiling because:
1.) a compiler translates programming code (i.e. BASIC code) into assembly language
2.) and assembly language gets to skip the inefficient compiler translation process entirely.

Hope that helps you understand how the 2A03 compares with "PS2 or PC or C#". :)


edit.

edit2: fixed all of my mispellings of machine (was "machiene", sorry :oops: )

final edit: You asked for elementary school teaching so here is a translation of:
Quote:
2.) and assembly language gets to skip the inefficient compiler translation process entirely.
Using a compiler to translate programming code (i.e. programming languages such as BASIC or C or C++ or C#) *can* create a much slower and larger program than if you spent the time needed to understand and make wise use of the assembly language that runs on the processing chip(s) in the machine you are trying to program for. :)

I just read that some compilers try to focus on things like speed or for the generated program being useable on many different kinds of machines. Compilers create 1s and 0s based on what they are focusing on. I don't know anything about using compilers to create NES games, I'm sorry. :(


Last edited by unregistered on Mon Jun 25, 2018 3:41 pm, edited 2 times in total.

Top
 Profile  
 
PostPosted: Mon Jun 25, 2018 2:05 pm 
Offline

Joined: Sun Jun 17, 2018 6:41 pm
Posts: 118
So judging by what I wrote, did it look alright by using A X Y register examples? Or I did the wrong way of examples of A X Y Register?


Top
 Profile  
 
PostPosted: Mon Jun 25, 2018 5:08 pm 
Offline
User avatar

Joined: Sun Sep 19, 2004 9:28 pm
Posts: 3606
Location: Mountain View, CA
DocWaluigean wrote:
TIRE = 0
STR = 0
...
LDX #0
LDY #0

STX TIRE
STY STR

INC STR ; [[ INC X??? ]]


ldx #0 means load a value of 0 into the X index register. Same goes for ldy #0 but into the Y index register.

stx TIRE means store (write) the current X index register value into the memory location represented by TIRE. If TIRE was declared as being equivalent to memory location $1234, then this would become stx $1234 (in English: write value 0 to memory location $1234).

But in your code, you've said TIRE = 0, which essentially means TIRE = $00 or TIRE = $0000 (there's of a difference between these two, sort of, but don't worry about that right now), so in this case the result would be stx 0, which is the same as stx $00 (in English: write value 0 to memory location $0000).

Same situation for sty STR but with the Y index register, etc..

Then, in the same code, you also say STR = 0. So now literally TIRE and STR both refer to memory location 0. This is probably not what you want (see below).

inc STR increments the value at memory location STR by 1. So this is the same as inc $00 basically. Under the hood, the CPU does the equivalent of "read value from memory location $00, increment it by one, write it back to memory location $00" (but without using a register). You could do the exact same yourself in code by doing something like: lda STR clc adc #1 sta STR.

I believe when you wrote TIRE = 0 and STR = 0, you were thinking "how can I pre-assign a value of a variable", because that's what other programming languages let you do -- they hide what goes on under the hood, instructions that are generated internally by the compiler or interpreter. In assembly language, these are called EQUates, which is why you can say something like TIRE = 0 or TIRE EQU 0 -- they mean the same thing. Equates are only expanded at assemble time, not at run-time. Understanding the difference is important!

Equates can be used in many different ways, not just as "memory locations". They can be used as literal values, or even pre-calculated values. I'll give an example below.

It just so happens that on the NES, memory location $00 happens to be RAM (in fact, it's something called zero page, but that's still advanced so ignore that for now). RAM on the NES ranges from memory locations $0000 to $07FF (so that's 2KBytes).

If you wanted to give all of your variables their own unique memory locations, you'd do something like this:

Code:
TIRE  = $00    ; Memory location $00
STR   = $01    ; Memory location $01
MAN   = $02    ; Memory location $02
SNAKE = MAN+1  ; Memory location $03

; Initialise all the above variables to 0
lda #0
sta TIRE
sta STR
sta MAN
sta SNAKE

; Increment MAN by 1 (MAN now contains value 1)
inc MAN

; Load the literal address of SNAKE into the accumulator, i.e. lda #$03
lda #SNAKE


The last line will probably confuse you. Note the # (hash mark). It indicates what's called an "immediate value" (a.k.a. literal value). This is how you tell the assembler what kind of access method to use, a.k.a. addressing mode. Here's a better way to demonstrate it with regards to what I said. Note the difference between the lda lines:

Code:
MYVAR = $1e

lda MYVAR   ; Load the contents of memory location $1E into the accumulator (i.e. A = whatever memory location $1e contains)
lda #MYVAR  ; Load literal value $1e into the accumulator (i.e. A = $1e)

These literally become the following lines:
Code:
lda $1e
lda #$1e

...and as such, the assembler assembles these into two completely different results: lda $1e assembles into bytes a5 1e, while lda #$1e assembles into bytes a9 1e. See the difference? The instructions are identical (lda), but the opcodes (due to addressing modes) differ. The former addressing mode is called "zero page addressing", while the latter is called "immediate addressing". That's how the CPU knows what to do with each subsequent byte (operand).

That's probably enough for one day. Real-time comparisons are a whole other subject (e.g. trying to do if HEALTH == TIRE, but in 6502). I think understanding the above is more important, as well as understanding addressing modes (there are several, and many limitations! Some instructions can only use certain addressing modes or certain registers, for example).

Edit: lots of them.


Top
 Profile  
 
PostPosted: Mon Jun 25, 2018 5:59 pm 
Offline
User avatar

Joined: Thu Apr 23, 2009 11:21 pm
Posts: 927
Location: cypress, texas
^
DocWaluigean wrote:
I'm starting to get it little.

So it would be "store #10 to JOE, confirming it into variable like JOE = 10"?
Yes. :)

DocWaluigean wrote:
My thoughts:

DIM ROOM

BED = 100
LAMP = 10

END ROOM

'===

DIM MAN

TIRE = 0
STR = 0
LVLSTR = STR + 1
HEALTH = 20

IF HEALTH == TIRE
GOTO @GAMEOVER

==================

.[[dim?]] $0001
ROOM:

LDA #100 ; Meaning? : Load as in "put" # 100 into variable / register A
STA BED ; Store the variable / Register A, which is stated as # 100 [like A = 100] into BED, which now turns into " BED = 100 " but in style of #100

LDA #10 ; in style of " A = 10 "
STA LAMP ; in style of "LAMP = 10"

ENA ROOM ; [End ROOM?????]
Code:
;I haven't a clue what "DIM" is... but here is what I think you want (in asm6 format)

; iNES header
.byte "NES", $1a

; Number of PRG-ROM blocks
.byte $02 ;2 16kb blocks (32kb from $8000 to $FFFF)

; Number of CHR-ROM blocks
.byte $01 ;1 8kb space for character graphics (when using Mapper #00)

; ROM control bytes: Vertical mirroring, no PRG-RAM, no trainer, Mapper #00
.byte %00000001, $00

; Filler
.byte $00, $00, $00, $00, $00, $00, $00, $00

.enum $0000 ;declare names for variables starting at beginning of the zeropage (location $0000)
BED .dsb 1 ;BED is now at location $0000
LAMP .dsb 1 ;LAMP is now at location $0001
.ende ;ends this variable declaration section

.org $C000 ;start code following at location $C000
reset: ;code that runs when the power button is pressed (or when the game is loaded) and each time your game is reset
sei ;sets interrupt flag
cld ;clears decimal flag because decimal mode on the NES is pointless (a feature of the 2A03)
; Wait two VBLANKS.
- bit $2002
  bpl -

; Clear out RAM.
  lda $00
  ldy $00
- sty $000, y
  sty $100, y
  ;usually, RAM page 2 is used for the display list to be copied to OAM.  OAM needs to be initialized to $EF-$FF, not 0, or you'll get a bunch of garbage sprites at (0, 0).
  sta $300, y
  sta $400, y
  sta $500, y
  sta $600, y
  sta $700, y
  iny
  bne -

- bit $2002
  bpl -

rti ;end reset


MainLoop:
jsr ROOM
jmp MainLoop

ROOM:
lda #100 ;yes, this loads the A register with #100 (A = #100)
sta BED ;$0000 = #100

lda #10
sta LAMP ; $0001 = #10

rts ;ends function ROOM

vblank:
rti ;ends vblank

nmi:
rti ;ends nmi


.pad $FFFA ; <will fill all the ROM from the byte (a byte is 8 bits of info) after NMI's rti up to $FFFA with 00s.
.word vblank, reset, irq ;these 3 words (a word is 16 bits of info) will close your program and cause the NES to know where to find your vblank, reset, and nmi code.

; CHR-ROM
.include "your4kb_backgroundFile.chr"
.include "your4kb_spritesFile.chr"
This program will just constantly jsr ROOM over and over. Could be made faster if you copied the contents of ROOM (everything between ROOM: and its rts and pasted them in place of jsr ROOM because jsr and rts each take 6 cycles and are pointtless because your NES file is really empty right now.
When you have more experience:
1.) look at http://wiki.nesdev.com/w/index.php/INES to read more about the iNES header at the top
2.) look at http://wiki.nesdev.com/w/index.php/Mapper to maybe choose a different mapper; you are using mapper 000 http://wiki.nesdev.com/w/index.php?title=INES_Mapper_000

I don't have time to use your second part but for the most part it looked ok to me. :) Hope this helps your NES journey. :)


Top
 Profile  
 
PostPosted: Tue Jun 26, 2018 9:17 am 
Offline
User avatar

Joined: Thu Apr 23, 2009 11:21 pm
Posts: 927
Location: cypress, texas
^Notes about code in my previous post:
1.) It's untested.
2.) The two chr files .incbin'ed at the end are pointless, right now, because that section of code doesn't have functions that draws the background and that draws the sprites. Just put them there so you would know where to place them when you get around to needing them.
3.) I don't think the Simulator that tokumaru recommends allows .include or .incbin so just comment those lines. Comments usually start with ; and the rest of the line following a ; isn't assembled. If you comment the two .incbin lines maybe you could add .pad $12000, to the end, to fill that 8kb ($10000 to $12000) with 0s. That may help the Simulator, I don't know. :oops: When using the Simulator you should also probably replace the "nameless" - lables, those only work with asm6, I think.
4.) That code is written in asm6 format.
5.) You could try running that code, after assembling into a .nes file with asm6, in the Mesen emulator and click Options>Preferences then click the box at the bottom next to "Enable developer mode". After doing that, click Debug>"Memory Tools" and then, in the window that opens, the upper left corner should constantly be red because byte $0000 and byte $0001 are constantly being written to. The latest Mesen can be found here: https://ci.appveyor.com/project/Sour/mesen/build/artifacts. :)

Sour's Mesen thread: http://forums.nesdev.com/viewtopic.php?f=3&t=13844

edit: about #3, just commenting those .incbin lines should be enough. When you get around to using them add labels before each file and then you can implement Sprite DMA. But, don't worry about that now. Sprite DMA isn't being used and so just commenting those two .incbin lines should work excellently and you don't need the .pad $12000, I think. :)

edit2: Those two .include should be .incbin because chr files are binary files, not text files . Sorry, I made some mistakes while trying to help you. :oops:

final edit. :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 275 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6 ... 19  Next

All times are UTC - 7 hours


Who is online

Users browsing this forum: Google Adsense [Bot] and 5 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