Jump to content
IGNORED

Need help assembling bank switched code


tep392

Recommended Posts

Hi all,

 

I'm looking for some help on assembly directive's for bank switched code. I'm currently using MADS. The game will be built on a 144k cart that has a 16k rom fixed at $4000 and a 128k banked rom were banks 0-6 are switched at $8000 and bank 7 is fixed at $c000. I have code in each bank and need to make subroutine calls between the fixed and switched banks. The code would look something like this.

 

org $4000

fixed code and data in 16k rom

 

org $8000

bank0 code and data

 

org $8000

bank 1 code and data

 

org $8000

remaining banks filled with $ff

 

org $c000

fixed bank 7 code and data

 

If I try to assemble this, I'll get "can't fill from higher memory" errors when bank 1 is assembled. Can this be done with MADS or do I need to use a different assembler?

 

Perry

Link to comment
Share on other sites

I'm not familiar with MADS, nor am I familiar with Atari 7800 programming, but in general you can't have code that uses the same physical addresses, such as

 

  org $8000

  org $8000

  org $8000

 

When writing bank-switched games for the Atari 2600 with the DASM assembler, the normal procedure is to code the ORG addresses so they define a continuous and contiguous set of ROM banks. Note that for this purpose you can start with an ORG of $0000 if you want because the ORG addresses will define the memory within the finished ROM image file, but for the 2600 it's common to start with ORG $1000. So if you wanted to assemble a 16K ROM for the 2600, made up of four 4K banks, you could use ORG addresses like this:

 

  ORG $0000

  ORG $1000

  ORG $2000

  ORG $3000

 

When it's compiled, the ROM file will be a 16K file with no "gaps" between the banks.

 

But then you need to use RORG to relocate the code in each bank so the addresses fall within the proper area of the address space, like this:

 

  ORG $0000
  RORG $9000

  ORG $1000
  RORG $B000

  ORG $2000
  RORG $D000

  ORG $3000
  RORG $F000

 

Those aren't the only RORG addresses that would work for the 2600-- you could also use RORG $1000, RORG $3000, RORG $5000, and RORG $7000, for example.

 

For the addresses you listed, I would suggest something like this, or some equivalent with a different starting address:

 

  ORG $0000
  RORG $4000
; fixed code and data in 16k rom

  ORG $4000
  RORG $8000
; bank0 code and data

  ORG $8000
  RORG $8000
; bank 1 code and data

  ORG $C000
  RORG $8000
; remaining banks filled with $ff

  ORG $10000
  RORG $8000
; remaining banks filled with $ff

  ORG $14000
  RORG $8000
; remaining banks filled with $ff

  ORG $18000
  RORG $8000
; remaining banks filled with $ff

  ORG $1C000
  RORG $8000
; remaining banks filled with $ff

  ORG $20000
  RORG $C000
; fixed bank 7 code and data

 

The ORG addresses would give you a 144K ROM image file, but the RORG addresses would control what addresses are used inside each bank.

Link to comment
Share on other sites

If I remember correctly, in MADS you can use ORG A,B

Where A is the address it assembles to and B is the address it is assumed to be running from (I think it's that way around).

 

I've not used Mads to recursively create banks as in your case but have used it to have code that loads in one location but is intended to run at another.

It'd be a bit of a kludgy workaround but you could use the ORG A,B method to generate a banked cart image.

 

Also note that Mads will usually generate an executable for the 8-bit computer which you don't want for carts - ideally you want a raw binary (optionally prefixed with the headers needed for some emulation filetypes)

 

 

Alternatively you could use AtAsm - it has the .bank directive which allows easy creation of banked binaries - but of course it's usually easier to stick with what you started out with.

Link to comment
Share on other sites

I figured it out. Thanks for the help! ORG A,B almost worked, but gave me an error when I exceeded 0xFFFF. I was able to make it work by turning the FILL option off and on between each bank. This stopped the "can't fill from higher memory" error.

 

;Start of Bank1

org $8000

opt h-f+ ;turn on fill

 

;End of Bank1

org $bffe

.byte $01 ;this causes assembler to fill to end of bank

opt h-f- ;turns off fill

 

;Start of Bank2

org $8000

opt h-f+

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...