Jump to content
IGNORED

Questions about inline asm


Atarius Maximus

Recommended Posts

I've been toying around with the inline asm option on bB, mostly to see if I could call an existing binary file from within a bB program. As an experiment, I used distella and dumped the freeway source, which is only a 2k game. I then pasted the contents of the asm file into a bB source code file, just to see if I could compile it that way and make it work. I actually did this test a few weeks ago, so I don't remember exactly what I did, but I think I did have to remove certain things from the ASM file to make it work, like the ORG statement. Anyway, Freeway did in fact load up, but there were numerous graphics glitches and the game wasn't playable.

 

My real question is, is it possible to take an existing binary file and make it work inside of a bB program? I thought it might be cool to make a menu for a bunch of 2k games into a 16k or 32k bB program and make sort of a multicart. Also, it would be cool to be able to call a binary file with music, as I have some cool music bin files created with sid2tia.

 

Also, I'd be curious if anyone has ever used any other advanced functions with inline ASM in a bB program? It might be a good way to start learning how to write a whole game in actual ASM, which would be my ultimate goal. :)

 

Has anybody ever tried this?

 

Steve

Link to comment
Share on other sites

I've been toying around with the inline asm option on bB, mostly to see if I could call an existing binary file from within a bB program.

Yes, you can do that-- but if the binary file you're calling isn't relocatable, then you'll need to modify it to change all of the "hard-coded" address references to match the new locations. Also, you'll need to make sure that any zero-page RAM usage doesn't conflict with the zero-page RAM usage of your batari Basic program (including the RAM locations that batari Basic uses for its "system variables").

 

As an experiment, I used distella and dumped the freeway source, which is only a 2k game. I then pasted the contents of the asm file into a bB source code file, just to see if I could compile it that way and make it work.

That's going to be tough to do right, because it's very unlikely that the Freeway code is relocatable. The easiest way to do it would be to modify batari Basic's includes files so that you can completely free up either the bottom 2K of the 4K cartridge area, or the top 2K. The bottom 2K would probably work best, because I think that's where 2K cartridges are usually coded, anyway-- and then the code gets mirrored in the top 2K. You'd need to modify things so that batari Basic puts its own routines (followed by your program) starting at $F800 instead of $F000-- and then the 2K game would start at $F000. To start the 2K game, you'd need to JMP or goto the address pointed to by the 2K game's startup vector. And then, to return to your batari Basic program when the 2K game ends, you'd need to find the "game over" section and goto or JMP back to your own program instead of JMPing to the 2K game's title screen or menu or whatever.

 

I actually did this test a few weeks ago, so I don't remember exactly what I did, but I think I did have to remove certain things from the ASM file to make it work, like the ORG statement. Anyway, Freeway did in fact load up, but there were numerous graphics glitches and the game wasn't playable.

That's not surprising, especially if you didn't "fix" the code to relocate all of the address references, and even more so if the game code was no longer aligned with page boundaries as it originally was.

 

My real question is, is it possible to take an existing binary file and make it work inside of a bB program?

Yes, it's possible, but more so if the code is relatively small and relocatable-- otherwise you'll have a lot of work to do to make it function correctly.

 

I thought it might be cool to make a menu for a bunch of 2k games into a 16k or 32k bB program and make sort of a multicart.

That would work best if all of the 2K games were in the lower 2K area of each bank, since the upper 2K will contain the bankswitching logic and hotspots. And you'd still need to modify the 2K games so the program control could return to your menu system.

 

Also, it would be cool to be able to call a binary file with music, as I have some cool music bin files created with sid2tia.

That might be much more easily doable.

 

Also, I'd be curious if anyone has ever used any other advanced functions with inline ASM in a bB program? It might be a good way to start learning how to write a whole game in actual ASM, which would be my ultimate goal. :)

 

Has anybody ever tried this?

 

Steve

I don't know about "advanced functions," but you're welcome to look at my Sudoku code, which was written in a combination of batari Basic and inline assembly. It might be kind of difficult to follow, since it uses E7 bankswitching. But what I did (if I remember correctly) was remove all of batari Basic's includes files, and then code my own kernel. It's kind of messy, and is unfinished, but it might give you some ideas about how to combine batari Basic code with inline assembly.

 

Michael

Link to comment
Share on other sites

I've been toying around with the inline asm option on bB, mostly to see if I could call an existing binary file from within a bB program.

Yes, you can do that-- but if the binary file you're calling isn't relocatable, then you'll need to modify it to change all of the "hard-coded" address references to match the new locations. Also, you'll need to make sure that any zero-page RAM usage doesn't conflict with the zero-page RAM usage of your batari Basic program (including the RAM locations that batari Basic uses for its "system variables").

 

As an experiment, I used distella and dumped the freeway source, which is only a 2k game. I then pasted the contents of the asm file into a bB source code file, just to see if I could compile it that way and make it work.

That's going to be tough to do right, because it's very unlikely that the Freeway code is relocatable. The easiest way to do it would be to modify batari Basic's includes files so that you can completely free up either the bottom 2K of the 4K cartridge area, or the top 2K. The bottom 2K would probably work best, because I think that's where 2K cartridges are usually coded, anyway-- and then the code gets mirrored in the top 2K. You'd need to modify things so that batari Basic puts its own routines (followed by your program) starting at $F800 instead of $F000-- and then the 2K game would start at $F000. To start the 2K game, you'd need to JMP or goto the address pointed to by the 2K game's startup vector. And then, to return to your batari Basic program when the 2K game ends, you'd need to find the "game over" section and goto or JMP back to your own program instead of JMPing to the 2K game's title screen or menu or whatever.

 

I actually did this test a few weeks ago, so I don't remember exactly what I did, but I think I did have to remove certain things from the ASM file to make it work, like the ORG statement. Anyway, Freeway did in fact load up, but there were numerous graphics glitches and the game wasn't playable.

That's not surprising, especially if you didn't "fix" the code to relocate all of the address references, and even more so if the game code was no longer aligned with page boundaries as it originally was.

 

My real question is, is it possible to take an existing binary file and make it work inside of a bB program?

Yes, it's possible, but more so if the code is relatively small and relocatable-- otherwise you'll have a lot of work to do to make it function correctly.

 

I thought it might be cool to make a menu for a bunch of 2k games into a 16k or 32k bB program and make sort of a multicart.

That would work best if all of the 2K games were in the lower 2K area of each bank, since the upper 2K will contain the bankswitching logic and hotspots. And you'd still need to modify the 2K games so the program control could return to your menu system.

 

Also, it would be cool to be able to call a binary file with music, as I have some cool music bin files created with sid2tia.

That might be much more easily doable.

 

Also, I'd be curious if anyone has ever used any other advanced functions with inline ASM in a bB program? It might be a good way to start learning how to write a whole game in actual ASM, which would be my ultimate goal. :)

 

Has anybody ever tried this?

 

Steve

I don't know about "advanced functions," but you're welcome to look at my Sudoku code, which was written in a combination of batari Basic and inline assembly. It might be kind of difficult to follow, since it uses E7 bankswitching. But what I did (if I remember correctly) was remove all of batari Basic's includes files, and then code my own kernel. It's kind of messy, and is unfinished, but it might give you some ideas about how to combine batari Basic code with inline assembly.

 

Michael

 

Michael,

 

Thanks for your detailed response. It sounds like it might be possible with a lot of trial and error work.

 

Some of your instructions may be a little beyond what I currently understand how to do - but at least now I understand what it takes. I certainly understand the concept of changing the hard coded address references to match the new locations, but I don't really know how to determine what the new locations are. Also, I don't really know how to verify that there are no zero-page RAM conflicts. If there's an easy way to explain this or demostrate what you mean with a real code example that would be super, but don't worry about it if that would take too much time. I'll keep playing around with it, that's always a good way to learn. ;)

 

Steve

 

EDIT: I will take a look at your sudoku source, thanks for pointing that out. I always learn best by example rather than reading manuals, looking at other people's code is usually how I'm able to figure things out. :)

Edited by Atarius Maximus
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...