BeebAsm BASIC2 assembler O% equivalent?

discussion of beeb/electron applications, languages, utils and educational s/w
cmorley
Posts: 262
Joined: Sat Jul 30, 2016 7:11 pm
Location: Oxford

BeebAsm BASIC2 assembler O% equivalent?

Postby cmorley » Sun Oct 29, 2017 11:12 am

Reading through the wiki for beebasm I can't see how you set the equivalent of the BASIC 2 assembler's O%.

P% <= ORG
O% <= ??

I am building a ROM which has code which is copied to RAM before executing. In BASIC2 assembler I'd use P% = RAM address & O% = ROM address so all the jump addresses are correct & the assembled code ends up sequentially in the ROM.

How do you do this in BeebAsm?

Thanks,
Chris

User avatar
sweh
Posts: 1847
Joined: Sat Mar 10, 2012 12:05 pm
Location: New York, New York
Contact:

Re: BeebAsm BASIC2 assembler O% equivalent?

Postby sweh » Sun Oct 29, 2017 12:38 pm

I would have that code in a separate file, compiled at the target address and then INCBIN it into the main code at the right place.

The "tips" section of the wiki page gives a hint on how this could all be done in one file (http://www.retrosoftware.co.uk/wiki/ind ... and_tricks). I've not tested but I expect the results of the first SAVE could be INCBIN'd later, and the labels defined in the first section will be available to the main code.
Rgds
Stephen

User avatar
kieranhj
Posts: 529
Joined: Sat Sep 19, 2015 10:11 pm
Location: Farnham, Surrey, UK

Re: BeebAsm BASIC2 assembler O% equivalent?

Postby kieranhj » Sun Oct 29, 2017 12:46 pm

I looked back at the relocdemo that comes with BeebAsm and it has the unsatisfactory solution of defining an OFFSET variable and then manually patching up any absolute address references. :-k

I bet this was on Rich’s to do list (and might even be a feature in one of the branches on GitHub - reminds me, again, we need to get these moved to an “official” StarDot repo.)
Bitshifters Collective | Retro Code & Demos for BBC Micro & Acorn computers | https://bitshifters.github.io/

cmorley
Posts: 262
Joined: Sat Jul 30, 2016 7:11 pm
Location: Oxford

Re: BeebAsm BASIC2 assembler O% equivalent?

Postby cmorley » Sun Oct 29, 2017 12:54 pm

Ok thanks, I will try with INCBIN.

User avatar
sweh
Posts: 1847
Joined: Sat Mar 10, 2012 12:05 pm
Location: New York, New York
Contact:

Re: BeebAsm BASIC2 assembler O% equivalent?

Postby sweh » Sun Oct 29, 2017 4:46 pm

So a "1 only" file kinda works, but it's messy. It requires some kludging
eg (no code moving done; just a proof of concept of INCBIN working)

Code: Select all

$ cat foo.asm
ORG &120

.start120
JSR p1
RTS
.p1
LDA #65
JMP &FFEE
.end120

SAVE "part1",start120,end120

ORG &3000

.start3000
LDA #65
JSR &FFEE
RTS
INCBIN "part1"
.end3000

$ beebasm -i foo.asm
foo.asm:19: error: Error opening file.

INCBIN "part1"
       ^
$ touch part1
$ beebasm -i foo.asm
foo.asm:20: error: Fatal error: the second assembler pass has generated different code to the first.

.end3000
 ^
$ beebasm -i foo.asm
$ hdump real
00000000  A9 41 20 EE FF 60 20 24 01 60 A9 41 4C EE FF      .A ..` $.`.AL..
$


So it finally worked (and we can see the JSR matches) but the path wasn't clean!

Splitting it into two separate files worked

Code: Select all

$ ls
part1.asm  part2.asm
$ beebasm -i part1.asm
$ beebasm -i part2.asm
$ hdump real
00000000  A9 41 20 EE FF 60 20 24 01 60 A9 41 4C EE FF      .A ..` $.`.AL..

But you lose any variables you may have defined for the relocatable section
Rgds
Stephen

cmorley
Posts: 262
Joined: Sat Jul 30, 2016 7:11 pm
Location: Oxford

Re: BeebAsm BASIC2 assembler O% equivalent?

Postby cmorley » Mon Oct 30, 2017 7:09 pm

Yes, not pretty.

User avatar
Rich Talbot-Watkins
Posts: 1121
Joined: Thu Jan 13, 2005 5:20 pm
Location: Palma, Mallorca

Re: BeebAsm BASIC2 assembler O% equivalent?

Postby Rich Talbot-Watkins » Mon Oct 30, 2017 8:00 pm

I added a COPYBLOCK command ages back (which is apparently in the 1.08 release, though not documented). The idea was that you could assemble a bit of code in its correct location, then use

Code: Select all

COPYBLOCK start, end, destination_addr

to relocate it to the new address.

There may be problems to do with subsequently assembling code over the original addresses (though maybe CLEAR can help with that). I used it successfully at some point to create a BeebAsm assemblable Chuckie Egg, complete with relocation code.

Maybe that can do what you need?

cmorley
Posts: 262
Joined: Sat Jul 30, 2016 7:11 pm
Location: Oxford

Re: BeebAsm BASIC2 assembler O% equivalent?

Postby cmorley » Fri Nov 03, 2017 12:18 pm

Sorry didn't see your reply until now.

Yes COPYBLOCK would work I think.

e.g.

Code: Select all

\RAM
ORG &<ram address>
.startram
[CODE]
RTS
.endram

\ROM
ORG &<rom address>
.startrom
[CODE]

\copy down to ram
LDX (endram-startram+1)
.copyloop
DEX
LDA romcopy,X
STA startram,X
BNE copuloop

JSR startram
[more CODE]
.romcopy

COPYBLOCK startram, endram, romcopy

.endrom

SAVE "rom", startrom, endrom

along these lines? I'll give it a whirl.

User avatar
Rich Talbot-Watkins
Posts: 1121
Joined: Thu Jan 13, 2005 5:20 pm
Location: Palma, Mallorca

Re: BeebAsm BASIC2 assembler O% equivalent?

Postby Rich Talbot-Watkins » Fri Nov 03, 2017 2:58 pm

cmorley wrote:along these lines? I'll give it a whirl.

Yeah I think that was pretty much the idea. It doesn't advance ORG though, so your .endrom will be in the wrong place - you'll need a SKIPTO if you want to skip over the copied block (maybe it'd be useful to have a version which copies a block to the current ORG and advances it by the right amount too).

It's a bit clumsy though. I agree that having a way of being able to specify an address offset, like O%, would be a better solution. As ever with BeebAsm, I knocked it together with much haste and little thought at the moment that I needed it!


Return to “software: other”

Who is online

Users browsing this forum: grobda and 4 guests