org $80

Building your first 6502-based project? We'll help you get started here.
Post Reply
boriskarloff
Posts: 7
Joined: 14 Nov 2021

org $80

Post by boriskarloff »

Hi.
What does it mean at the begin of the code (atari 2600)

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

thanks
User avatar
GARTHWILSON
Forum Moderator
Posts: 8773
Joined: 30 Aug 2002
Location: Southern California
Contact:

Re: org $80

Post by GARTHWILSON »

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?
boriskarloff
Posts: 7
Joined: 14 Nov 2021

Re: org $80

Post by boriskarloff »

Thanks for the info.
hmn
Posts: 21
Joined: 07 May 2017

Re: org $80

Post by hmn »

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

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

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

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

            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
boriskarloff
Posts: 7
Joined: 14 Nov 2021

Re: org $80

Post by boriskarloff »

Thanks.
Post Reply