BeebAsm

handy tools that can assist in the development of new software
User avatar
ctr
Posts: 259
Joined: Wed Jul 16, 2014 3:53 pm
Contact:

Re: BeebAsm

Post by ctr »

VectorEyes wrote: Tue Jul 06, 2021 12:29 am It assembles and runs Evil Influences fine.

Now to take a look at all this lovely new functionality! Thanks for all the changes.
Thank you.
lovebug wrote: Sun Jul 11, 2021 10:27 pm heres a small bit of code and the listing it generates [...]
I've opened an enhancement request as a reminder of this.

Also, there's a small bug in beebasm where the hex constant &ffffffff is not equal to the binary constant %11111111111111111111111111111111. The former is 4294967295 but the latter -1. Additionally, longer binary constants are silently truncated to 32 bits. The fix makes both constants positive and checks the length of binary constants. I mention this because it could be a breaking change for someone.
julie_m
Posts: 587
Joined: Wed Jul 24, 2019 9:53 pm
Location: Derby, UK
Contact:

Re: BeebAsm

Post by julie_m »

I don't know if this is worth adding to the manual, but here's how to create code, such as a jump table, that always ends on a page boundary:

Code: Select all

ORG &7B00
._begin

.real_wibble
    LDX #wibble_msg MOD 256
    LDY #wibble_msg DIV 256
    JMP real_sayXY
.real_blah
    LDX #blah_msg MOD 256
    LDY #blah_msg DIV 256
.real_sayXY
    STX &70
    STY &71
    LDY #0
._sayXY1
    LDA (&70),Y
    INY
    JSR &FFE3
    CMP #32
    BCS _sayXY1
    RTS

.wibble_msg
    EQUS "WIBBLE": EQUB 13
.blah_msg
    EQUS "BLAH": EQUB 13

._real_end              \  first location after end of code

ALIGN &100              \  now P% is on page boundary
GUARD P%                \  don't allow any more code after here
CLEAR _real_end,P%      \  clear from real end of code as far as
                        \  new origin
ORG P%-9                \  wind back origin 3 locations for each
                        \  entry in jump table

.sayXY
    JMP real_sayXY
.wibble
    JMP real_wibble
.blah
    JMP real_blah
._end                   \  this will be on a page boundary

SAVE "M.POC1", _begin, _end
This allows you to have predictable entry points at the end of a page; which is nice, if you want your code to butt up against the bottom of screen memory and as far away as possible from BASIC.

This is where the magic happens:

Code: Select all

._real_end              \  first location after end of code

ALIGN &100              \  now P% is on page boundary
GUARD P%                \  don't allow any more code after here
CLEAR _real_end,P%      \  clear from real end of code as far as
                        \  new origin
ORG P%-9                \  wind back origin 3 locations for each
                        \  entry in jump table

.sayXY
We assign a label at the real end of the code, align the origin to a page boundary, mark the area from the end of the code to the page boundary as clear, then move the origin back just enough to make room for the jump table, parameter block or whatever we want to exist at the end of a page. Here it's just a table of entry points, but you could easily have a block of read/writable locations for passing parameters back and forth.
User avatar
ctr
Posts: 259
Joined: Wed Jul 16, 2014 3:53 pm
Contact:

Re: BeebAsm

Post by ctr »

julie_m wrote: Sun Jul 25, 2021 12:37 pm I don't know if this is worth adding to the manual, but here's how to create code, such as a jump table, that always ends on a page boundary:
Cheers. beebasm has an examples directory which has mostly been a dumping ground for test cases useful to the developers. These have been moved into a test directory now (along with some code to run them) so the examples directory can contain actually useful examples.

Do you do github? You could create a pull request to add your example or I can do it if you prefer.
julie_m
Posts: 587
Joined: Wed Jul 24, 2019 9:53 pm
Location: Derby, UK
Contact:

Re: BeebAsm

Post by julie_m »

I've recently started using GitHub "properly" (with a proper local file structure and everything, as opposed to like a kind of glorified Pastebin) so I will certainly investigate how to do that.
User avatar
ctr
Posts: 259
Joined: Wed Jul 16, 2014 3:53 pm
Contact:

Re: BeebAsm

Post by ctr »

Nice one. We've been making updates on the "proposed-updates" branch.
julie_m
Posts: 587
Joined: Wed Jul 24, 2019 9:53 pm
Location: Derby, UK
Contact:

Re: BeebAsm

Post by julie_m »

OK ..... I have commented my example program even more thoroughly, made my own local repository and switched branches to proposed-updates ..... used git add to add my own files, and done git commit. My repo is one commit ahead. Sorry for being a n00b, but what do I do now? Either in GitHub or in Bash?
User avatar
ctr
Posts: 259
Joined: Wed Jul 16, 2014 3:53 pm
Contact:

Re: BeebAsm

Post by ctr »

You need to add your file to your own fork on github before creating a pull request. The steps are: fork stardot/beebasm on github (there's a button at the top right) to create your-github-user/beebasm; clone your-github-user/beebasm to your PC; on your PC, checkout the "proposed-updates" branch; add your new file; commit the change; push the changes back to your-github-user/beebasm on github using "git push"; create the pull request on github (click on the Pull Requests tab in your-github-user/beebasm and then the New Pull Request button).
julie_m
Posts: 587
Joined: Wed Jul 24, 2019 9:53 pm
Location: Derby, UK
Contact:

Re: BeebAsm

Post by julie_m »

OK. I think it worked! Making my own fork was the crucial bit I was missing. So if I got everything right, you should be seeing a pull request from JulieMontoya (for I am her, at least over there) wanting to add two files, `examples/jump_table_at_end.6502` with the actual code and `examples/jump_table_at_end.md` with the notes.

I guess even if it didn't work, the beauty of it is we all still have our own separate, relatively unmolested copies of everything anyway ..... :)
User avatar
lovebug
Posts: 1739
Joined: Sun Jan 31, 2021 5:07 pm
Location: Magrathea
Contact:

Re: BeebAsm

Post by lovebug »

is there any way to assign a value to constant and then reassign it again later sort of using it like a variable ?

aName = 100
aName = aName + bName
Image Image Image Image
SteveF
Posts: 1663
Joined: Fri Aug 28, 2015 9:34 pm
Contact:

Re: BeebAsm

Post by SteveF »

I don't think there is, but I could be wrong. I believe for loops and macros get their own namespace, which may allow you to work around this limitation depending on exactly what you want to achieve. Rather contrived and silly example:

Code: Select all

$ cat z.6502
macro foo xName
    aName = xName + bName
    bar
endmacro

macro bar
    print aName
endmacro

aName = 100
bName = 5
foo aName
bar
$ beebasm -do z.ssd -i z.6502
105 
100
warning: no SAVE command in source file.
Note that macro bar uses aName but sees it having two different values.
User avatar
lovebug
Posts: 1739
Joined: Sun Jan 31, 2021 5:07 pm
Location: Magrathea
Contact:

Re: BeebAsm

Post by lovebug »

thanks, i'll try some experiments
Image Image Image Image
User avatar
lovebug
Posts: 1739
Joined: Sun Jan 31, 2021 5:07 pm
Location: Magrathea
Contact:

Re: BeebAsm

Post by lovebug »

im working on some changes to ladybug and i found a strange issue with putbasic generating my Boot program
 
beebasm putbasic error.png
beebasm putbasic error 02.png
 
if I retype line 52 exactly the same into the beeb then the program runs fine
as a work around ive set E%=page+5 and so line 52 now reads ?E%=33 and that runs fine

I honestly cant see anything wrong with the generated code ? im confused that typing exactly the same line into basic and then running the program works fine

heres the source code of Boot and the generated .ssd from beebasm
 
boot.bas.txt
(6.12 KiB) Downloaded 31 times
ladybug.ssd
(36.5 KiB) Downloaded 26 times
Image Image Image Image
User avatar
lovebug
Posts: 1739
Joined: Sun Jan 31, 2021 5:07 pm
Location: Magrathea
Contact:

Re: BeebAsm

Post by lovebug »

interesting I retyped the line and saved it/*dumped it and there is a difference

the PAGE token generated by beemasm has a value of &d0 and shows as PAGE when listing the line
the PAGE token generated by typing the line into bbc basic has a value of &90 and also shows as PAGE when listing the line !!!!

whats is this madness lol, why does bbc basic have two page tokens ?????? this is very strange
Image Image Image Image
cmorley
Posts: 1867
Joined: Sat Jul 30, 2016 8:11 pm
Location: Oxford
Contact:

Re: BeebAsm

Post by cmorley »

lovebug wrote: Fri Oct 15, 2021 9:19 am interesting I retyped the line and saved it/*dumped it and there is a difference

the PAGE token generated by beemasm has a value of &d0 and shows as PAGE when listing the line
the PAGE token generated by typing the line into bbc basic has a value of &90 and also shows as PAGE when listing the line !!!!

whats is this madness lol, why does bbc basic have two page tokens ?????? this is very strange
One is an lvalue the other is an rvalue.
User avatar
lovebug
Posts: 1739
Joined: Sun Jan 31, 2021 5:07 pm
Location: Magrathea
Contact:

Re: BeebAsm

Post by lovebug »

cmorley wrote: Fri Oct 15, 2021 9:22 am
lovebug wrote: Fri Oct 15, 2021 9:19 am interesting I retyped the line and saved it/*dumped it and there is a difference

the PAGE token generated by beemasm has a value of &d0 and shows as PAGE when listing the line
the PAGE token generated by typing the line into bbc basic has a value of &90 and also shows as PAGE when listing the line !!!!

whats is this madness lol, why does bbc basic have two page tokens ?????? this is very strange
One is an lvalue the other is an rvalue.
what is an lvalue / rvalue ?

i just tried this
 
page test.png
Image Image Image Image
cmorley
Posts: 1867
Joined: Sat Jul 30, 2016 8:11 pm
Location: Oxford
Contact:

Re: BeebAsm

Post by cmorley »

An lvalue is an expression which can go on the left of an assignment. An rvalue is an expression which can go on the right side of an assignment.

It is more complicated than this in reality.

Owlet
Last edited by cmorley on Fri Oct 15, 2021 9:40 am, edited 1 time in total.
User avatar
lovebug
Posts: 1739
Joined: Sun Jan 31, 2021 5:07 pm
Location: Magrathea
Contact:

Re: BeebAsm

Post by lovebug »

doh ! that makes sense

I hope its not too complicated to fix the issue
Image Image Image Image
User avatar
sweh
Posts: 3314
Joined: Sat Mar 10, 2012 12:05 pm
Location: 07410 New Jersey
Contact:

Re: BeebAsm

Post by sweh »

Which version of beebasm are you using? A bug relating to this was fixed back in April

Code: Select all

                  Fixed tokenisation of BASIC pseudo-variables in some cases.
I don't know if this fix has made it to a published release or if it's still only in git.
Rgds
Stephen
User avatar
lovebug
Posts: 1739
Joined: Sun Jan 31, 2021 5:07 pm
Location: Magrathea
Contact:

Re: BeebAsm

Post by lovebug »

sweh wrote: Fri Oct 15, 2021 1:43 pm Which version of beebasm are you using? A bug relating to this was fixed back in April

Code: Select all

                  Fixed tokenisation of BASIC pseudo-variables in some cases.
I don't know if this fix has made it to a published release or if it's still only in git.
I just checked with beebasm --help and it reports the version as 1.09
Image Image Image Image
User avatar
lovebug
Posts: 1739
Joined: Sun Jan 31, 2021 5:07 pm
Location: Magrathea
Contact:

Re: BeebAsm

Post by lovebug »

the v1.09 i was using was the precompiled .exe

i just download the master branch of beebasm source from the official stardot github and compiled it but its the same v1.09, i tested it anyway just in case but is the same error

there are 16 branches on this so I have no idea what to follow, its very confusing
Image Image Image Image
SteveF
Posts: 1663
Joined: Fri Aug 28, 2015 9:34 pm
Contact:

Re: BeebAsm

Post by SteveF »

lovebug wrote: Fri Oct 15, 2021 8:05 pm there are 16 branches on this so I have no idea what to follow, its very confusing
It's a bit buried in all the other branches, but I think proposed-updates should have the fix for this on, along with all sorts of other cool new features - please give that a try...
User avatar
lovebug
Posts: 1739
Joined: Sun Jan 31, 2021 5:07 pm
Location: Magrathea
Contact:

Re: BeebAsm

Post by lovebug »

SteveF wrote: Fri Oct 15, 2021 11:38 pm
lovebug wrote: Fri Oct 15, 2021 8:05 pm there are 16 branches on this so I have no idea what to follow, its very confusing
It's a bit buried in all the other branches, but I think proposed-updates should have the fix for this on, along with all sorts of other cool new features - please give that a try...
thank you, I will
Image Image Image Image
User avatar
lovebug
Posts: 1739
Joined: Sun Jan 31, 2021 5:07 pm
Location: Magrathea
Contact:

Re: BeebAsm

Post by lovebug »

I compiled that branch in vs no errors but sadlly it has the same issue

took a screenshot of the version
Attachments
beebasm version 01.PNG
Image Image Image Image
SteveF
Posts: 1663
Joined: Fri Aug 28, 2015 9:34 pm
Contact:

Re: BeebAsm

Post by SteveF »

Thanks for trying that. I just gave it a go myself and I can reproduce your problem.

There's something a bit weird going on because beebasm now includes some automatic tests on the proposed-updates branch and the test case for the existing tokenisation fix is failing. However, that fix does seem to be working - maybe I somehow committed a bad test case "gold" output and no one noticed before?!

Whatever's going on with that test case, I don't think the fix I committed back in April will help you after all - that fix was about tokenising on the rhs of an "=" sign, and your problematic code has it on the lhs. If anyone who has all this BASIC tokenisation stuff straight in their head would like to take a look, please do - if not I will see if I can figure it out.

FWIW the slightly smaller test case:

Code: Select all

52?PAGE=33
fails to tokenise correctly while:

Code: Select all

52PAGE=33
is handled correctly.

Edit: You can work around this in the absence of a fix - not ideal I know - by writing:

Code: Select all

p=PAGE
?(p+5)=33
User avatar
BigEd
Posts: 6261
Joined: Sun Jan 24, 2010 10:24 am
Location: West Country
Contact:

Re: BeebAsm

Post by BigEd »

I think it's true that an indexing expression on the LHS is nontheless an r-value.
?(PAGE+50)=X
needs to evaluate PAGE+50 as if it were on a RHS, and then the ? operator uses that address as an l-value.
Y=PAGE+50
?Y=X
perhaps illustrates why that's true.

Edit: same with an array index, which is a more conventional example
Z(PAGE+50)=X
User avatar
lovebug
Posts: 1739
Joined: Sun Jan 31, 2021 5:07 pm
Location: Magrathea
Contact:

Re: BeebAsm

Post by lovebug »

yeah I did a workaround E%=PAGE+5:?E%=33 just after my first post

thanks
Image Image Image Image
SteveF
Posts: 1663
Joined: Fri Aug 28, 2015 9:34 pm
Contact:

Re: BeebAsm

Post by SteveF »

SteveF wrote: Sat Oct 16, 2021 3:13 am There's something a bit weird going on because beebasm now includes some automatic tests on the proposed-updates branch and the test case for the existing tokenisation fix is failing. However, that fix does seem to be working - maybe I somehow committed a bad test case "gold" output and no one noticed before?!
I've got no idea what's going on here because this all seems fine today. Yes, I'd had a beer last night :-) but how far wrong could I go with typing "make all" and seeing a test failure being reported!? Anyway, I'll try not to worry about this since it seems fine now,.

I've had a go at fixing the problem lovebug's reported - the fix, along with a test case, is on the ZornsLemma/lhs-token-fix branch, which is branched off proposed-updates so includes all the other changes. As always when working on the BASIC tokenising code I have this feeling I'm meddling with things beyond my understanding, but the fix does seem to work and it still correctly tokenises the Ozmoo BASIC loader so it isn't completely broken at least. Code review/test reports welcome!
User avatar
lovebug
Posts: 1739
Joined: Sun Jan 31, 2021 5:07 pm
Location: Magrathea
Contact:

Re: BeebAsm

Post by lovebug »

im trying to write a macro in beebasm for assigning zero page variables on the fly
ive done this in other assemblers but beemasm it might be impossible ?

in the past I have initialized zpVarPtr variable with 0

when the macro zpvar is called with a variable name like zpvar(counter) it does the following

1) saves the current org position in a temporary variable
2) does a org zpVarPtr
3) creates a label with the variable name supplied and skip 1 byte
4) sets zpVarPtr to the current org position ready for the next variable
5) set org back to its original value that was saved in the temporary variable

beebasm seems to have constants but no variables so this doesnt work

is there any way I can do a similar thing with beebasm ?
Image Image Image Image
User avatar
Rich Talbot-Watkins
Posts: 2054
Joined: Thu Jan 13, 2005 5:20 pm
Location: Palma, Mallorca
Contact:

Re: BeebAsm

Post by Rich Talbot-Watkins »

I think the bigger problem would be that variables defined inside a macro definition are local to that macro.

I tend to handle zp allocation something like this:

Code: Select all

ORG 0
.scrnptr  SKIP 2
.readptr  SKIP 2
.colour   SKIP 1
.posx     SKIP 1
.posy     SKIP 1

ORG &1100
.start
    ; your code here
.end

SAVE "CODE", start, end
Making symbols immutable was very much a conscious design decision with BeebAsm - it's the only way that handling forward references really makes any clear sense. The concept was always supposed to be that, regardless of the order you define things in, it will always give a consistent result. In practice, this didn't really work out, as sometimes forward references aren't allowed, macros have to be defined before they can be used, etc etc.

I have a 90% complete BeebAsm 2.0 nearly ready for release, which realises this concept much better (now forward references work everywhere, even as the IF condition, a limitation which has frequently frustrated me with the original BeebAsm). It also has string and list types, overloadable macros with parameter decorations (like ADD16 addr, #val), named scopes, named overlays, and more cool stuff. But I'm still not sure whether mutable variables will make it into the design. They seem a popular request though, so I might find a way to specify them with a slightly different syntax, which - among other things - would prevent them from being forward referenced.

I was aiming for a first release last month, but then my work got really heavy again and I had to give it a rest :(
User avatar
0xC0DE
Posts: 1300
Joined: Tue Mar 19, 2019 7:52 pm
Location: The Netherlands
Contact:

Re: BeebAsm

Post by 0xC0DE »

Rich Talbot-Watkins wrote: Sun Nov 28, 2021 6:00 pm I have a 90% complete BeebAsm 2.0 nearly ready for release
Well, that is the best thing I read all day! \:D/
0xC0DE
"I program my home computer / Beam myself into the future"
:arrow: Follow me on Twitter
:arrow: Visit my YouTube channel featuring my games and demos for Acorn Electron and BBC Micro
Post Reply

Return to “development tools”