Jump to content
IGNORED

Question for those who help build bB


jbs30000

Recommended Posts

Would this be possible to ad to the language, or would it be too complicated or not work right?

 

bB lets you use variables - var[index 1], var[index 2], etc...

bB lets you set or unset individual bits - var{0}, var{1}, etc...

 

Would it be possible to combine the two so that you could have something like this?

 

dim Counter=a

dim myvar=b

 

for Counter=0 to 5

myvar[Counter]{0}=1

next

Link to comment
Share on other sites

Would this be possible to ad to the language, or would it be too complicated or not work right?

 

bB lets you use variables - var[index 1], var[index 2], etc...

bB lets you set or unset individual bits - var{0}, var{1}, etc...

 

Would it be possible to combine the two so that you could have something like this?

 

dim Counter=a

dim myvar=b

 

for Counter=0 to 5

myvar[Counter]{0}=1

next

Fred (batari) is the only person who works on the compiler, so this is really a question for him to answer, but...

 

It's certainly possible to do that in assembly. You could either do it with inline assembly, or you could write a macro to do it. As far as whether it's possible to modify the compiler to "add it to the language"-- yes, it's possible, but the compiler would need to be changed to recognize that kind of statement when it's scanning and parsing a line, so it can compile the statement correctly. I suppose the thing to look for would be a right square bracket followed by a left curly bracket, with or without any spaces between them-- ]{, or ] {, etc. And the parser would probably have to look for that case before looking for [] and {} by themselves.

 

Here's how these cases are currently compiled:

 

.L04 ;  myvar[counter] = 1

   	LDA #1
   	LDX counter
   	STA myvar,x

.L04 ;  myvar{0} = 1

   	LDA myvar
   	ORA #1
   	STA myvar

.L04 ;  myvar[counter]{0} = 1

   	LDA #1
   	LDX counter]{0
   	STA myvar,x

You can see the problem in the LDX line-- the compiler is treating this like a simple array statement, and is trying to load the X register with counter]{0.

 

Here's how to do it in assembly:

 

.L04 ;  myvar[counter]{0} = 1

   	LDX counter
   	LDA myvar,x
   	ORA #1
   	STA myvar,x

However, it would look different if you were turning a different bit on, or if you were turning a bit off instead of on. And there's also the question of whether you're going to be testing array bits in an if statement.

 

It would be up to Fred to decide if this sort of thing will ever be incorporated into the compiler, but I could probably write a couple of macros to do it in the meantime.

 

Michael

 

 

 

Link to comment
Share on other sites

A macro would be a good idea if it's possible. It would be less work than adding the functionality to the compiler.

 

I was going to ask about something slightly more complex, but it dawned on me that I can put in the bB code and examine the asm output myself. But anyway, if you could figure out a macro, that would be great. Thank you.

Link to comment
Share on other sites

A macro would be a good idea if it's possible. It would be less work than adding the functionality to the compiler.

 

I was going to ask about something slightly more complex, but it dawned on me that I can put in the bB code and examine the asm output myself. But anyway, if you could figure out a macro, that would be great. Thank you.

I was able to create a macro for setting a bit:

 

  def POKE_arraybit=callmacro setarraybit
  macro setarraybit
  asm
.variable SET {1}
.index	SET {2}
.bit  	SET {3}
.value	SET {4}
  LDX .index
  LDA .variable,X
  IF {4}==#0
 	AND #(255-(1<<.bit))
  ELSE
 	ORA #(1<<.bit)
  ENDIF
  STA .variable,X
end
end

You can modify the macro name and/or def variable name to suit your preferences. To use it, pass the name of the variable array, the element you want to change, the bit you want to change, and what you want to set the bit to, separated by spaces:

 

  dim counter=a
  dim myvar=b

  for counter=0 to 5
 	POKE_arraybit myvar counter 0 1
 	rem equivalent of myvar[counter]{0}=1
  next

I'm not sure about the PEEK version-- especially when used in an if statement, or in a complex expression. I *can* do a PEEK version that will store the result in another variable, though-- the equivalent of var=myvar[counter]{bit}. Then you could use the other variable in an if, or in a complex expression.

 

Michael

Link to comment
Share on other sites

Thank you for the code. I have one more question. I put the following code in a test program and got the asm. Although I'm very familiar with Intel asm, and somewhat familiar with 6502 asm, I don't fully understand the asm generated.

I'll put the basic code, along with the asm code and my comments on whether I understand what's going on or not.

 

bB

w000{0}=r001{7}

 

asm

lda r001 - Load the accumulator with the contents of r001

and #128 - AND that value with 128

php - Push the processor status onto the stack - why?

lda w000 - Load the accumulator with the contents of w000 - w000 is write only, that probably won't work

and #254 - AND that value with 254

plp - Pop the processor status - why?

.byte.b $f0, $02 - Don't know what this does.

or #1 - OR the accumulator with 1

sta w000 - Store the accumulator value in w000

 

Anyway, if you could tell me what the php and plp do and what f0 02 does I'd appreciate it. Thank you.

Link to comment
Share on other sites

Thank you for the code. I have one more question. I put the following code in a test program and got the asm. Although I'm very familiar with Intel asm, and somewhat familiar with 6502 asm, I don't fully understand the asm generated.

I'll put the basic code, along with the asm code and my comments on whether I understand what's going on or not.

 

bB

w000{0}=r001{7}

 

asm

lda r001 - Load the accumulator with the contents of r001

and #128 - AND that value with 128

php - Push the processor status onto the stack - why?

lda w000 - Load the accumulator with the contents of w000 - w000 is write only, that probably won't work

and #254 - AND that value with 254

plp - Pop the processor status - why?

.byte.b $f0, $02 - Don't know what this does.

or #1 - OR the accumulator with 1

sta w000 - Store the accumulator value in w000

 

Anyway, if you could tell me what the php and plp do and what f0 02 does I'd appreciate it. Thank you.

I thought sooner or later someone would find this code and wonder about it. I intended to clean it up eventually.

 

The php/plp is done so the flags will be preserved for the branch below (the .byte $F0, $02 is really a BEQ *+2 or something (it should branch past the ORA instruction.)

 

You are right that the LDA w000 will not work, but this isn't really a bug in bB. Any bit manipulation requires reading the contents, modifying them and writing them back, which you can't do with write-only variables. bB has no way of knowing that it's dealing with read- or write-only variables, and I'm not sure if it's wise to treat w### and r### in a special way since users will probably dim them to something else, which defeats any special treatment.

 

If you want to use individual bits in write-only variables, you will need to do something like this:

 

temp1=r000

temp1{0}=r001{7}

w000=temp1

 

This will copy the read-only to a normal read/write variable, where it can be modified. Then, it's copied back to the write portion.

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