6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Nov 22, 2024 11:04 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: org $80
PostPosted: Tue Jan 25, 2022 2:25 am 
Offline

Joined: Sun Nov 14, 2021 12:53 pm
Posts: 7
Hi.
What does it mean at the begin of the code (atari 2600)

org $80
org $f000
or at the end
rorg $FFFA

thanks


Top
 Profile  
Reply with quote  
 Post subject: Re: org $80
PostPosted: Tue Jan 25, 2022 2:44 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8544
Location: Southern California
I'm not familiar with the Atari 2600; but the ORG assembler directive is short for "origin" and means that the following code will be assembled to the memory addresses starting where the ORG says. The "ORG $FFFA" at the end is to start laying down the vector bytes. The two bytes for the 16-bit address where the interrupt-service routine (ISR) for the non-maskable interrupt (NMI) go in FFFA-FFFB; the reset gets FFFC-FFFD, and the IRQ gets FFFE-FFFF. I think you'll find the 6502 primer's section called "Program-writing: Where do I start?" to be helpful, at http://wilsonminesco.com/6502primer/PgmWrite.html .

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
 Post subject: Re: org $80
PostPosted: Tue Jan 25, 2022 11:53 pm 
Offline

Joined: Sun Nov 14, 2021 12:53 pm
Posts: 7
Thanks for the info.


Top
 Profile  
Reply with quote  
 Post subject: Re: org $80
PostPosted: Thu Jan 27, 2022 5:54 pm 
Offline

Joined: Sun May 07, 2017 3:59 pm
Posts: 21
I am assuming the code samples are for DASM, as that seems to be a popular choice for 2600 coding, and it has an RORG directive.

Quote:
org $f000

As Garth said, this sets the address where the assembler will put the code, but in the case of a cross assembler like DASM, the code is not
placed in the specified RAM address, but written to a file of course.

ORG also sets the address that the assembled code thinks it is located at.

Code:
            processor 6502
            org $f000
here        jmp here        ; assembles as "jmp $f000", or "4c 00 f0" in hex

Note that nothing is output before the first actual instruction (jmp), so it does not put the jmp instruction at position $f000 in the file, but
the instruction looks like it was placed at that address (assemble with -f3 command line option to get the raw assembler output without any headers).

Quote:
org $80

This makes little sense by itself, as $80 is the start address of RAM on the 2600, and you don't assemble to a RAM address with the 2600, as the code will not not be loaded to RAM from disk like on a computer, but rather run directly from ROM (you could of course copy code from ROM to RAM at runtime, but that is another issue - see below).

"org $80" does make sense in conjunction with DASM's uninitialized segments, however:

Code:
            seg.u ram
            org $80
my_var      ds.w 1     ; reserve 1 word
another_var ds.b 3     ; reserve 3 bytes
third_var   ds.b 1     ; reserve 1 byte

This generates no code or data during assembly, and is equivalent to the following definitons:

Code:
my_var      EQU $80
another_var EQU $82
third_var   EQU $85

The advantage of using a segment is that you don't have to keep track of the individual addresses yourself.

Quote:
rorg $FFFA

This would be the "relocatable ORG" directive of DASM. It does not change where the code is placed, but it changes where the code thinks it is being placed. This is helpful for writing memory-banked code or code that is copied to it's final location at runtime.

The following example will produce an 8K ROM image (again, with the -f3 option), consisting of two identical 4K blocks:

Code:
            processor 6502
            org $1000    ; bank1 starts at file position 0, memory address $1000
bank1       jmp bank1    ; jmp $1000

            org $2000    ; bank2 continues at file at position $1000, memory address $2000
            rorg $1000   ; but code thinks it is located at $1000
bank2       jmp bank2    ; assembles as "jmp $1000", would be "jmp $2000" without the RORG
            rend
            ds.b $3000-*,$ff   ; pad to 4K boundary


Top
 Profile  
Reply with quote  
 Post subject: Re: org $80
PostPosted: Sun Jan 30, 2022 1:13 am 
Offline

Joined: Sun Nov 14, 2021 12:53 pm
Posts: 7
Thanks.


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 9 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: