Jump to content
IGNORED

Having problems adding ASM routine into Batari Basic


bs4

Recommended Posts

Greetings! I've been studying and learning more and more every day, coding on VCS is awesome!

However, there are a few things I'm having issues with.

 

In this post, I would like to ask help for adding ASM routines into the Batari BASIC source.

 

I've been playing around with making digitized samples using the excellent utility wav2atari.pl.

 

I can compile the ASM source I create from command line using DASM with no problem as you can see below.

The TEST.BIN plays perfectly and sounds excellent! (I am seriously impressed by the quality!!! WOW!!!)

 

C:\BATARI\HELLO SAMPLE\HelloWorld>\BATARI\dasm.exe TEST.ASM -f3 -oTEST.BIN

Complete.

C:\BATARI\HELLO SAMPLE\HelloWorld>

 

The issue I'm having is when I try to insert the code into Batari Basic source.

 

The way I understand it is you're simply supposed to use the asm tag and end at the end.

Like this:

 

set romsize=32k
asm
include "HelloWorld/test.asm"
end

 

I've tried a million different ways but every time I get "Origin Reverse-indexed" error during compile:

 

Compile started at 3/14/2015 3:58:52 PM
Compiling C:\BATARI\HELLO SAMPLE\MAIN.bas
segment: CODE 1000 vs current org: f45d

HelloWorld/test.asm (38): error: Origin Reverse-indexed.

Errors were encountered during assembly.
2600 Basic compilation completed.
Compilation completed at 3/14/2015 3:58:52 PM
view output file:///C:/BATARI/HELLO SAMPLE/bin
Post compilation files deleted

Obviously, the source is good else it would not compile using DASM from command line.

 

What am I missing? Thanks for anyone who can help!

Edited by bs4
Link to comment
Share on other sites

The way I understand it is you're simply supposed to use the asm tag and end at the end.

I don't see that on the bB page:

 

randomterrain.com/atari-2600-memories-batari-basic-commands.html#assembly

 

randomterrain.com/atari-2600-memories-batari-basic-commands.html#includesfile

 

randomterrain.com/atari-2600-memories-batari-basic-commands.html#inline

 

Looks like you are mixing things that shouldn't mix, if I'm reading the bB page correctly.

Link to comment
Share on other sites

That's not going to work because the asm file is defining the physical(ROM) location of the code which is not compatible with the asm the basic source is being transformed into.

 

You could try trimming the test.asm file so it doesn't have any seg or org statements, but even then I think you're going to run into problems with what you're trying to do. In order to get this working you would probably need a very good understanding of assembly programming.

 

There is also a good chance that the generated test.asm is going to corrupt the state of the bB code. So even if you get it to compile it will likely crash.

Link to comment
Share on other sites

ZackAttack: Okay then is there a way to get digitized samples into Batari Basic without needing a "very good

understanding of assembly" ? 8)

 

Random Terrain: Using asm tag, inserting asm code, then ending with end works with all the example code

I've played with. Such as "titlescreen_demo.bas" and others.

I have already been using this exact format to make title screens, how can it be wrong?

(I have already written programs that are mostly basic but use asm rutines.)

Edited by bs4
Link to comment
Share on other sites

Random Terrain: Using asm tag, inserting asm code, then ending with end works with all the example code

I've played with. Such as "titlescreen_demo.bas" and others.

I have already been using this exact format to make title screens, how can it be wrong?

(I have already written programs that are mostly basic but use asm rutines.)

I guess batari forgot to put an example showing that on the bB page or maybe it's there and I can't find it. I see it in the titlescreen stuff, like you mentioned, though:

 

 

1. You need to add an "include" statement in the empty bank where you want to store your titlescreen. In this example we use bank 2

 

   bank 2
   asm
   include "titlescreen/asm/titlescreen.asm"
end
Link to comment
Share on other sites

randomTerrain: It's right there on the link you post -

asm
ldx #47
lda #0
playfieldclear
sta playfield,x
dex
bne playfieldclear
end

 

The whole function of the asm tag is to allow you to insert asm code into the basic code.

 

Are you misunderstanding what I mean?

 

You use the asm tag, you insert your asm code then you put end at the end.

This is the only way I have ever seen asm routines put into Batari.

 

Now... If the ASM code is over writing parts of memory it shouldn't, that's a different issue of course. 8)

Hopefully Zack can help me on that.

Edited by bs4
Link to comment
Share on other sites

randomTerrain: It's right there on the link you post -

asm

ldx #47

lda #0

playfieldclear

sta playfield,x

dex

bne playfieldclear

end

 

The whole function of the asm tag is to allow you to insert asm code into the basic code.

 

Are you misunderstanding what I mean?

 

I knew you could put actual code between asm and end, but I didn't know/remember that you could put a file between asm and end.

Link to comment
Share on other sites

Random Terrain: All "including" something does is "include" the source from the ASM file into the BASIC source.

 

I have tried not even using the include anyhow and directly just putting the full source into the

BASIC source so that it's a huge file with all source and no includes... I get the exact same error.

 

My issue has nothing to do with using the include function.

 

I think Zack is correct - Memory is being over written.

 

ZackAttack: Here is my source. You should be able to compile it by using dasm TEST.ASM -f3 -oTEST.BIN.

 

As for my basic source, I have tried a million different ways - If you can find ANY way in basic to include

this ASM it would rock! 8) I assume memory is going to have to be allocated and shifted somehow.

Maybe if you know what location the ASM loads into, we can tell BASIC to load somewhere else?

Or change the ASM code to load somewhere BASIC doesn't?

 

I am sure this is going to help many people because I have the work flow figured out and if we can

get this to work then anyone should be able to put digitized audio into their code.

 

P.S. The sample that plays is a clip of me saying "Copyright" from years ago that I riped off an audio CD

I made, it's only for example purposes. (I just needed a quick sample!)

TEST.ASM

TEST.BIN

Edited by bs4
Link to comment
Share on other sites

 

I knew you could put actual code between asm and end, but I didn't know/remember that you could put a file between asm and end.

I think you're overlooking the fact that dasm recognizes include so the following is actually a line of asm technically.

include "HelloWorld/test.asm"

I assume dasm is what is actually performing the step of loading that file and inserting it's contents inline.

Link to comment
Share on other sites

I think you're overlooking the fact that dasm recognizes include so the following is actually a line of asm technically.

include "HelloWorld/test.asm"

I assume dasm is what is actually performing the step of loading that file and inserting it's contents inline.

 

 

One example that adds to the confusion is that "include fixed_point_math.asm" is supposed to go at the beginning of a program and it doesn't have asm and end wrapped around it. We have include, includesfile, and inline that are for various jobs and the bB page telling us things like this:

 

"With the include command, bB will place the module where it sees fit, typically in the first bank. If you want to have more control over where the modules go, you can use an includes file or the inline command."

 

And this:

"The include command must typically precede all other commands (at the beginning of your program, before anything else)."

 

But if we can ignore that and stick include between asm and end anywhere in a program, the bB page needs to be updated.

Link to comment
Share on other sites

 

 

One example that adds to the confusion is that "include fixed_point_math.asm" is supposed to go at the beginning of a program and it doesn't have asm and end wrapped around it. We have include, includesfile, and inline that are for various jobs and the bB page telling us things like this:

 

"With the include command, bB will place the module where it sees fit, typically in the first bank. If you want to have more control over where the modules go, you can use an includes file or the inline command."

 

And this:

"The include command must typically precede all other commands (at the beginning of your program, before anything else)."

 

But if we can ignore that and stick include between asm and end anywhere in a program, the bB page needs to be updated.

I think the bB page is correct as it is now. An include statement inside the asm statement is a completely separate thing from what I can tell.

  • Like 1
Link to comment
Share on other sites

ZackAttack: Dude you are awesome! That is exactly what I needed!

 

YES! Including this in the BB library would be awesome!

Including it into Visual Batari would rock too, like if there was an editor.

 

For anyone who wants to know how to make it work now, here is my workflow:

 

A - Use Soundforge or some other audio editor to save out whatever audio you want into a

4bit, 8000hz mono WAV file.

B - Make sure PERL is installed and use wav2atari.pl to generate the text data from the WAV you created.

C - Simply cut & paste the audio data it creates over the audio data in Zack's voice.asm file.

(I have found that I need to truncate it after PAGE 9, anything beyond that crashes, probably because memory.)

D - Run the basic program and point your include to your modified ASM file

E - PROFIT!!! 8)

 

AMAZING! Thank you so very much!

 

P.S. - My next question is about bank switching I think. Why doesn't this source work?

It compiles, plays the sample, then sits at a black screen.

 

If I remove the "gosub PlayRecording bank3" line then the title screen shows and all works as before

but obviously, it doesn't play the audio sample. If I include it, it plays the sample but then sits there.

 

I have a feeling I'm not telling it to switch back to bank1 (which I assume the main code is at) ?

 

I'm trying to put TITLESCREEN in BANK 2 and the audio sample in BANK 3.

So that it plays a sample then goes to titlescreen. I would love to play the sample DURING

the title screen but I didn't know if that would work and am just trying to get it to compile first.

 

I can tell they're going there because it shows. And I can get either to work but not both.

3845 bytes of ROM space left in bank 1
2022 bytes of ROM space left in bank 2
1223 bytes of ROM space left in bank 3

I'm including the basic source and titlescreen.asm. Voice.asm is the same as above.

SOURCE_Title.bas

titlescreen.asm

Edited by bs4
Link to comment
Share on other sites

That is how I got speech into my FLAPPY batari Basic program.

And I don't know that much about assembly.

 

You need to look at and modify the .asm file, then include file.asm will compile.

the top of the .asm code is assigning names to ram memory locations. The only ones needed are the pointerhi and pointerlo

Those you would name the same but as two variables at the start of your bB program like: pointerhi=a: pointerlo=b

Then you can cut all the top out about ds 1 locations, clearing ram, setup, down to what you need - the pointers.

The label names of the "sections" need to have periods in front of them like:

.SampleLoop

(code)

BNE .SampleLoop

...

RTS

...

.Delay

(code)

... .Delay

 

align 256

 

(your sound data)

 

all those labels in the .asm file have to have periods in front of them.

Semicolons ; <- are like REM and not compiled

To return from asm land back into bB code you need to find where in the assembly code to break out of then I used the assembly

RTS or one assembly code that means return.

 

This routine does nothing to handle a stable screen so your tv will roll or your display will lose sync, this was fine for the death doh! sound sample at the end of FLAPPY.

In our Robotron hack to Dr. Who someone smarter than I rewrote the speech routine so even though there is a blank screen, the line count stays at 262. That's too advanced for me at the moment, and isn't in the version posted here at this time.

Link to comment
Share on other sites

Ok, try this one. You can get rid of ALL of the dim statements because I changed the routine to use stack memory instead. I moved the data to the beginning of the asm file. Make sure it is included first in the bank before everything else. There is room for up to 15 pages (3840 bytes) of data. Just make sure to modify the CMP at the bottom (see code below) if you use less than 15 pages. I didn't address the scanline count though. That's going to be too time consuming and I need to get back to work on sonic.

CMP (#>HelloStart + 15) ;<--- Change this if using less than 15 pages

voice.asm

Link to comment
Share on other sites

ZackAttack: Once again, kudos man!

 

After I nuked the dim statements from my basic source and included the new voice.asm file you created,

everything worked flawlessly! The sample plays, then my game starts! 8)

 

Random Terrain: I understand your confusion and I think I can clarify.

 

Take C for example. Most C programs use STDIO.H (Standard I/O).

 

They usually have # include <stdio.h> at the beginning because almost everything uses STDIO.

It contains SCANF and PRINTF and all the basic text manipulation and "standard input and output"

commands you need. I assume "include fixed_point_math.asm" is the same.

(It's something that adds root level functions to Batari BASIC.)

These are beginning of program "setup" type things that need to be done up front because they

contain things that the rest of the code needs to use. This is different than "more game data" code.

I assume the fixed_point_math.asm adds fixed point math, correct?

So obviously, that needs to be set up first so the rest of the program can do fixed point math.

 

Either way, "include" is simply "including" the data so where you put the "include" in your program

really depends on where you should put the data that the include carries, understand?

(Depending on what type of data the include is carrying defines where the include should be located.)

 

Because you can literately take an include file and cut/paste it into a program and not even use the

include function and it's the exact same thing.

(As I mentioned above, all "include" does is "include" the source into your program.)

Edited by bs4
Link to comment
Share on other sites

CONTROL 2015 AUDIO DEMO

 

This is something I made today to test the theory that what has been discussed above could be

expanded across multiple banks. I've heard you can make up to a 512k 2600 rom!

 

A full lenght digitized song should be doable with some creative editing.

(Doesn't Stay Frosty play digitized music DURING GAMEPLAY?)

 

Thanks to ZackAttack for giving me enough power to be dangerous.

 

Press fire at the title screen to hear the short demo.

 

Any comments welcome. 8)

CONTROL 2015.BIN

Edited by bs4
Link to comment
Share on other sites

I'm glad I was able to help. That demo is really interesting and it ran a lot longer than I expected it to.

 

If you look at the assembly you'll see that there is a fairly large delay between each update to the AUDV0 register. I wonder if the extra cycles could be used to either add another channel, support data compression, display some dancing sprites, or maybe even a combination of them. Of course that would need to be done in assembly in order to keep the timing correct.

 

I wanted to build a 512KB banking scheme for the harmony but I could find documentation on it. I ended up just creating a new custom banking scheme that can support up to 256MB. Once I complete my game and finalize the hardware I plan on making it available for others to use. That's going to be a long time from now though.

Link to comment
Share on other sites

I also entered most of the music in Stay Frosty 2 and it does play during game play. It uses one channel to generate up to 3 notes, properly in tune. It goes through a small 32 byte waveform like your digitised music, but just very tiny. That can be used to shape the note. It does good with simple waveforms like square waves, sine waves, sawtooth waves and triangle waves, also experimenting with a 32byte string of numbers, sometime the sound resembles different instruments like banjo or string or organ. (I wish we could use a larger sample than 32 bytes because then we could make music with animal noises. )

Link to comment
Share on other sites

ZackAttack: I used a very lame method to make it work. The music is not my own, it's an old song from the 80's.

But it was structured in a way clips could be repeated.

 

Basically, I'm just copying the voice.asm routine to each 4k bank and then calling it from BASIC.

So it's repeating all the player code every time more of the song plays. I realize that's very lame.

 

What would really rock is if voice.asm could be changed to read data across multiple banks so that there's

only 1 "play" routine and the banks can be filled entirely with audio data. I assume that could nuke the delay also.

 

Are sound f/x possible on channel 2 while channel 1 plays digitized audio? IMAGINE THAT!!!

Having a feature "real" song playing with f/x also playing simutaneously AND game play!!!

 

I would really love to push the 2600's audio.

I saw a "tracker" that exists for VCS and was going to start playing with it but then I got distracted when I discovered it

can actually play digitized music! It sounds hilarious and kick ass simutaneously. Who'd of ever thought it?!?!

 

P.S. - 256 MEGS?!?!?! WOW!!!

 

iesposta: Having digitized audio play while the game is going would be f<king awesome.

 

Yes, Stay Frosty 2 proves it can be done.

 

Music can be written in ways which would be compatible with the VCS's limitations and extend the apparent lenght of a song.

Like if I write a song which is 12 measures in 4/4 for example...

Let's say it's the same melody except measures 1-4 are normal, 5-8 are more intense, and 9-12 are very intense.

That way a game could be made where the music is playing but as the game becomes more intense, the music gets more intense.

(Yet the melodys all intertwine perfectly.)

 

And from a programming perspective, all you're telling it to do is something like:

 

When the game is normal, just repeat bank 2.

When it gets more intense, repeat bank 3.

When it's insane, repeat bank 4.

 

Like how Space Invaders gets more intense/faster as the invaders become fewer, ya know?

Imagine a theme song that gets more intense as the game goes on and is a real actual digitized song.

 

I assume it is possible to play samples larger than 32 bytes but the "player" will need to do what I was talking about above -

Read data across multiple banks. Basically "stream" from the banks, right? Probably need a buffer for when it switches but

I don't think any of these things are impossible.

 

Another cheat could be to make the sample data contain the song playing too fast and with too high of pitch.

Then the player could play stuff slow, which would reduce the pitch and speed to how it was intended.

That way more data could be "compressed" into the 32 byte space. This would work with synth music like I do.

It would produce distorted notes that sound unlike other 2600 music or the original song.

(I'd have to see how it sounds and then go back and alter the input and play with it but a sweet spot could be found I'm sure.)

 

Sorry for rambling, I have tons of audio ideas. I'm better musician than coder. I grew up listening to Rob Hubbard SIDs. 8)

It is insane when I think of the ramifications here. I mean, seriously - the VCS is actually more expandable than the C=64 in a way.

It's absolutely insane when you consider how far it could be taken.

Edited by bs4
Link to comment
Share on other sites

Your Origin Reverse-indexed error is due to your included assembly file having an ORG statement in it. The ORG sets the starting address for the following code, so this LDA instruction:

  ORG $F000
  LDA #$00
is located at address $F000. You can have multiple ORG statements provided each successive address is larger, such as this:

  ORG $F000
  LDA #$00

  ORG $F100
  LDX #$00

  ORG $F200
  LDY #$00
Which would put LDA at $F000, LDX at $F100 and LDY at $F200. You cannot have an ORG were the address is smaller:

 

  ORG $F000
  LDA #$00

  ORG $E100
  LDX #$00

  ORG $F300
  LDY #$00
This will cause the Origin Reverse-indexed error to be triggered when DASM encounters the ORG $E100 line.

 

The address is actually based on the current location, so this would also fail:

  ORG $F000
  LDA #$00

  ORG $F001
  LDX #$00
The reason being is the LDA #$00 instruction is located at addresses $F000 and $F001 so the current location is $F002 when ORG $F001 is encountered.

 

 

I'm not very familiar with batari BASIC, but I suspect it hides the use of ORG from you.

 

 

Stay Frosty 2's waveforms are 32 bytes because that's how DPC+ was written. The playback of DPC+ music requires you to read the DPC+ register AMPLITUDE and store it into AUDV0 on each and every scanline - not only in the kernel, but also in Overscan, Vertical Sync and Vertical Blank. It's tricky, but doable.

 

There's a modified version of DPC+ which uses a 2048 byte waveform for the 3rd waveform to support digitized voice playback in Frantic. I've been slowly working out a bus-stuffing scheme and will most likely reboot Frantic to use it. Due to that, I have this comment is in the bus-stuffing header to remind me that I want to support different waveform sizes when I work on the music support:

 

;----------------------------------------
; 3 Voice Music
;
; speculative
; WAVESIZE0
; WAVESIZE1
; WAVESIZE2
;   1 = 32 bytes
;   2 = 64 bytes
;       ...
;  64 = 2048 bytes
; 128 = 4096 bytes
;----------------------------------------
Link to comment
Share on other sites

What would really rock is if voice.asm could be changed to read data across multiple banks so that there's

only 1 "play" routine and the banks can be filled entirely with audio data. I assume that could nuke the delay also.

Each bank has to have it's own "play" routine because that banking scheme only allows a single bank to be in scope at a time and you need to access both code and data simultaneously. The routine could be enhanced to do the bank switching itself to avoid the small delay between sound clips. However, the delay I was referring to was the one that's embedded in the play routine between each sample.

 

Also, you shouldn't get too optimistic about what could be done together. It's possible to have some very impressive sound or very impressive graphics, but having both at the same time isn't all that feasible. DCP+ and assembly can be used to produce some very impressive results but then you would lose the ease and productivity of programming in bB. If that was something you wanted to pursue I'd start by checking out the asm tutorials on here and then check out the blog SpiceWare is working on about programming DCP+ in assembly.

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...