Jump to content

IntyBASIC Support for ROM Region Swapping?

Recommended Posts

Hi. Can you clue me in on how to swap in/out 16k of ROM from the $C100 space using IntyBASIC compiling to the JLP architecture?

I am using the $C100 section of ROM to hold an audio waveform sample, the rest of the game cartridge ROM I am using for game code and graphics and sounds (42k, its large). Once the waveform plays, I want to play a different one at a later point in the game, so a swap of some kind through IntyBASIC's JLP support I think would be the best move because playing would be transparent to the rest of the game code. Speed is not critical for the swap, just something that works.

All ideas appreciated, if I'm way off in my suppositions I'll try other avenues.


Edited by First Spear
Link to comment
Share on other sites

What you're looking for, I think, is bank switching also known as page flipping. You're not really going to 'swap' the content of a ROM region with the content of another ROM region. Rather, you will make a given page appear at a given memory range, and this is a very fast operation.


JLP supports ECS-style page flipping, which allows you to address up to ~120 K-words.


However, I don't know if/how this is implemented in IntyBasic, so I'll let the experts explain that.

Link to comment
Share on other sites

IntyBASIC should be able to handle bankswitching like I figured out how to do bankswitching in C for Colecovision(wasn't easy).


Only a theory how this would work.


poke $6ff9,1 would signal to the logic chip to switch bank. Or it reading a=peek $6ff9....


asm org $10000 will compile set your data to the upper part of the ROM chip to be swap in with C100 or d000 if you want to keep the data even.


But I would have to gather information where to place data and how the logic chip works.

Link to comment
Share on other sites

I'll describe Mattel/ECS-style page flipping, at least how it's implemented in the current as1600, etc. This is the page-flipping style JLP supports, and I imagine other hardware will support it if it wants. I believe much of this has been covered in other threads (see Groovy's links above), so I'll summarize the relevant bits here.


Note: You need a recent as1600, such as the one in the stable dev version on the jzIntv website.



The Mattel scheme divides the memory map into 4K word ranges. In the context of your question, the relevant 4K ranges are $C000 - $CFFF, $D000 - $DFFF, $E000 - $EFFF and $F000 - $FFFF.


A given 4K range can either hold flat ROM or be page flipped. A page flipped range can hold up to 16 different 4K ROM pages, numbered 0 to 15.


To flip a 4K range, you need to write the number $xA5y to location $xFFF in that range, where 'x' is the upper 4 bits of the address range, and 'y' is the page number. For example, to flip $C000 - $CFFF to page 3, you would POKE $CFFF, $CA53.


At reset, all of the paged ROM ranges flip to page #0.


If you try to flip to a ROM page that isn't there, you get "dead air" on that range of addresses. (i.e. it reads as $FFFF)


To assemble code into paged ROM, you need to use a slightly different version of the ORG directive: ORG address:page. This tells as1600 to place everything it assembles in a Mattel-style page-flipped ROM on page number 'page'. For example, ORG $C100:3 says to start assembling at $C100, page #3. If your code spills over from $CFFF to $D000, it will continue in $Dxxx page #3. It will continue in page #3 until the next ORG statement.


In the context of your use case:


You could program your audio samples in IntyBASIC with something like this:


    ' Sample #0 in page 0
    ASM ORG $C100:0
    DATA $....    ' all the audio data for sample #0 here

    ' Sample #1 in page 1
    ASM ORG $C100:1
    DATA $....    ' all the audio data for sample #1 here

    ' Sample #2 in page 2
    ASM ORG $C100:2
    DATA $....    ' all the audio data for sample #2 here


...and so on. You should only need the one ORG statement per sample even if the sample occupies $C100 - $FFFF.


To flip between audio samples:


' Page-flip in the audio data for the sample # in "sample"
' "sample" is 0..15
PageFlipSample  Procedure
                POKE $CFFF, $CA50 + sample
                POKE $DFFF, $DA50 + sample
                POKE $EFFF, $EA50 + sample
                POKE $FFFF, $FA50 + sample


That's it.


When you assemble your code, you should see lines in your .CFG file that look like this in the [mapping] section:


$3000 - $3FFF = $C000 PAGE 0
$4000 - $4FFF = $C000 PAGE 1
$5000 - $5FFF = $C000 PAGE 2
$6000 - $6FFF = $D000 PAGE 0
$7000 - $7FFF = $D000 PAGE 1
$8000 - $8FFF = $D000 PAGE 2


and so on. The exact lines you get will depend on what else is in your ROM, the actual size of your audio samples and the actual number of audio samples. But, you get the idea.


Note that the .ROM format does not support the Mattel page flipping format. You need to use BIN+CFG.

Edited by intvnut
  • Like 6
Link to comment
Share on other sites

One additional minor caveat: If you want your game to play while the ECS is attached, avoid $2000 page 1, $7000 page 0 and $E000 page 1.


In the context of your audio samples at $C100 - $FFFF, it would be sufficient to avoid putting an audio sample on page 1.

  • Like 4
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.

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.

  • Recently Browsing   0 members

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