Jump to content
IGNORED

Stupid question I probably shouldn't be asking...


Dragnerok X

Recommended Posts

By the way, if you ever have a long series of ifs that contain similar ands or ors (&& or ||), you can almost always simplify (and optimize) them by taking out the similar portions and making them separate ifs, and have it jump over the other ifs if the condition isn't met (e.g., all of your original ifs had "if t = 1," so use "if t <> 1" to jump over the other ifs). And once you start simplifying in these ways, you can generally end up with something even simpler-- the way you can take a very complicated equation, start to simplify it in different ways, with each simplification giving rise to further possible simplifications, until you end up with something that looks much simpler than the original and yet says exactly the same thing!

 

Michael

Statements with || are handled quite inefficiently, so this is indeed true for them. The next release of bB should handle these more efficiently.

 

Statements with &&, however, are fairly efficient and recoding may or may not save any space. If it does save space it will likely just be a few bytes.

Link to comment
Share on other sites

  if t = 1 && a = 1 && e = 0 then v = 1
  if t = 1 && a = 2 && e = 0 then v = 2
  if t = 1 && a = 3 && e = 0 then v = 3
  if t = 1 && a = 4 && e = 0 then v = 4 
  if t = 1 && a = 5 && e = 0 then v = 5
  if t = 1 && a = 6 && e = 0 then v = 6 
  if t = 1 && a = 7 && e = 0 then v = 7
  if t = 1 && a = 8 && e = 0 then v = 8
  if t = 1 && a = 9 && e = 0 then v = 9
  if t = 1 && a = 10 && e = 0 then v = 10
  if t = 1 && a = 11 && e = 0 then v = 11
  if t = 1 && a = 12 && e = 0 then v = 12
  if t = 1 && a = 13 && e = 0 then v = 13
  if t = 1 && a = 14 && e = 0 then v = 14
  if t = 1 && a = 15 && e = 0 then v = 15
  if t = 1 && a = 16 && e = 0 then v = 16 
  if t = 1 && a = 1 && e = 1 then v = 9
  if t = 1 && a = 2 && e = 1 then v = 10
  if t = 1 && a = 3 && e = 1 then v = 11
  if t = 1 && a = 4 && e = 1 then v = 12
  if t = 1 && a = 5 && e = 1 then v = 13
  if t = 1 && a = 6 && e = 1 then v = 14
  if t = 1 && a = 7 && e = 1 then v = 15
  if t = 1 && a = 8 && e = 1 then v = 16
  if t = 1 && a = 9 && e = 1 then v = 1
  if t = 1 && a = 10 && e = 1 then v = 2
  if t = 1 && a = 11 && e = 1 then v = 3
  if t = 1 && a = 12 && e = 1 then v = 4
  if t = 1 && a = 13 && e = 1 then v = 5
  if t = 1 && a = 14 && e = 1 then v = 6
  if t = 1 && a = 15 && e = 1 then v = 7
  if t = 1 && a = 16 && e = 1 then v = 8 

 

Yikes.

 if t<>1  then goto skip_te
 if e>1 then goto skip_te
 a=a-1
 if a > 15 then goto skip_te_inc
 v=a
 if e-1 then v=v ^ 8
 v=v+1
skip_te_inc:
 a=a+1
skip_te:

Link to comment
Share on other sites

  if t = 1 && a = 1 && e = 0 then v = 1
  if t = 1 && a = 2 && e = 0 then v = 2
  if t = 1 && a = 3 && e = 0 then v = 3
  if t = 1 && a = 4 && e = 0 then v = 4 
  if t = 1 && a = 5 && e = 0 then v = 5
  if t = 1 && a = 6 && e = 0 then v = 6 
  if t = 1 && a = 7 && e = 0 then v = 7
  if t = 1 && a = 8 && e = 0 then v = 8
  if t = 1 && a = 9 && e = 0 then v = 9
  if t = 1 && a = 10 && e = 0 then v = 10
  if t = 1 && a = 11 && e = 0 then v = 11
  if t = 1 && a = 12 && e = 0 then v = 12
  if t = 1 && a = 13 && e = 0 then v = 13
  if t = 1 && a = 14 && e = 0 then v = 14
  if t = 1 && a = 15 && e = 0 then v = 15
  if t = 1 && a = 16 && e = 0 then v = 16 
  if t = 1 && a = 1 && e = 1 then v = 9
  if t = 1 && a = 2 && e = 1 then v = 10
  if t = 1 && a = 3 && e = 1 then v = 11
  if t = 1 && a = 4 && e = 1 then v = 12
  if t = 1 && a = 5 && e = 1 then v = 13
  if t = 1 && a = 6 && e = 1 then v = 14
  if t = 1 && a = 7 && e = 1 then v = 15
  if t = 1 && a = 8 && e = 1 then v = 16
  if t = 1 && a = 9 && e = 1 then v = 1
  if t = 1 && a = 10 && e = 1 then v = 2
  if t = 1 && a = 11 && e = 1 then v = 3
  if t = 1 && a = 12 && e = 1 then v = 4
  if t = 1 && a = 13 && e = 1 then v = 5
  if t = 1 && a = 14 && e = 1 then v = 6
  if t = 1 && a = 15 && e = 1 then v = 7
  if t = 1 && a = 16 && e = 1 then v = 8 

 

Yikes.

 

What's even scarrier about it is that when I started I was 100 bytes in the negative, now I have 1200 bytes to spare! ;)

Edited by Dragnerok X
Link to comment
Share on other sites

What's even scarrier about it is that when I started I was 100 bytes in the negative, now I have 1200 bytes to spare! ;)

You can save a few more by changing lines like these:

 

  b = b + 1
  if b = 16 then b = b - 16
  c = c + 1
  if c = 7 then c = c - 7
  d = d + 1
  if d = 2 then d = d - 2

to lines like these:

 

  b = b + 1
  if b = 16 then b = 0
  c = c + 1
  if c = 7 then c = 0
  d = d + 1
  if d = 2 then d = 0

I made those changes, plus some others, and now there's 938 bytes free in bank 1, and 1313 bytes free in bank 2.

 

Michael

combat_DX.bas

Combat_DX.bas.bin

Edited by SeaGtGruff
Link to comment
Share on other sites

  b = b + 1
  if b = 16 then b = b - 16
  c = c + 1
  if c = 7 then c = c - 7
  d = d + 1
  if d = 2 then d = d - 2

or...

 b = b & 15
 b = b + 1
 c = c + 1
 if c = 7 then c = 0
 d = d ^ 1

Shouldn't that be

  b = b + 1
  b = b & 15

And the d thing I don't understand. Anything to the power of 1 is itself, so d won't change-- or isn't the caret used for exponentiation in bB? Shouldn't it be

 

  d = d + 1
  d = d & 1

Michael

Link to comment
Share on other sites

And the d thing I don't understand. Anything to the power of 1 is itself, so d won't change-- or isn't the caret used for exponentiation in bB? Shouldn't it be

The caret is used for exclusive OR. bB doesn't support exponentiation, and I personally can't see any need for it in the language. I know that other Basics use it for exponentiation, But C uses the caret, and I had already settled on &&, ||, & and | just like C uses for its other operators.

 

The reason I used C-style operators in the first place is that they are much easier to parse than keywords like AND, OR and XOR, and AFAIK, most classic Basics that I've used don't even have bitwise operators.

Link to comment
Share on other sites

And the d thing I don't understand. Anything to the power of 1 is itself, so d won't change-- or isn't the caret used for exponentiation in bB? Shouldn't it be

The caret is used for exclusive OR. bB doesn't support exponentiation, and I personally can't see any need for it in the language. I know that other Basics use it for exponentiation, But C uses the caret, and I had already settled on &&, ||, & and | just like C uses for its other operators.

 

The reason I used C-style operators in the first place is that they are much easier to parse than keywords like AND, OR and XOR, and AFAIK, most classic Basics that I've used don't even have bitwise operators.

 

Ah ha! I knew it it isn't Basic at all is it! It's compiled, it uses C operators.... hmmmm. I think you'd better change your name to Catari. :D

Link to comment
Share on other sites

The reason I used C-style operators in the first place is that they are much easier to parse than keywords like AND, OR and XOR, and AFAIK, most classic Basics that I've used don't even have bitwise operators.

I'm pretty sure Commodore computers implemented those as bitwise operators. I'll powerup the old VIC tonight to confirm it.

Link to comment
Share on other sites

Ah ha! I knew it it isn't Basic at all is it! It's compiled, it uses C operators.... hmmmm. I think you'd better change your name to Catari. :D

Maybe batari BasiC would be more appropriate...
I'm pretty sure Commodore computers implemented those as bitwise operators. I'll powerup the old VIC tonight to confirm it.
You could be right about CBM Basic, but I am pretty sure that Apple II Basic interpreted them as logical operators even in an assignment, i.e. A=(1 AND 2) should make A=1, not A=0. Edited by batari
Link to comment
Share on other sites

What's even scarrier about it is that when I started I was 100 bytes in the negative, now I have 1200 bytes to spare! ;)

You can save a few more by changing lines like these:

 

  b = b + 1
  if b = 16 then b = b - 16
  c = c + 1
  if c = 7 then c = c - 7
  d = d + 1
  if d = 2 then d = d - 2

to lines like these:

 

  b = b + 1
  if b = 16 then b = 0
  c = c + 1
  if c = 7 then c = 0
  d = d + 1
  if d = 2 then d = 0

I made those changes, plus some others, and now there's 938 bytes free in bank 1, and 1313 bytes free in bank 2.

 

Michael

 

Thank's for the optimization! It's MORE (*cough* *cough* ;)) than enough. Now, on to tank destruction, I suppose. Any suggestions? (perhaps on a way I could randomly position a "dead" player back on the map)

Edited by Dragnerok X
Link to comment
Share on other sites

Cool, I did not know that. I just checked Applesoft Basic and it is not.

 

What about Integer Basic?

 

Same as Applesoft.

 

I used online emulator http://www.virtualapple.org/integerhirescardgamesdisk.html Starts in applesoft but could type INT to get into integer basic loaded into the language card. Type FP to go back to Applesoft.

Edited by djmips
Link to comment
Share on other sites

Same as Applesoft.

 

I'm surprised at that. Especially in integer basic, doing the arithmetic in binary wouldn't be any harder than forcing boolean logic, though maybe people hadn't figured out the value of making "true" be -1. And I guess the use of addressible latches ("soft switches") rather than parallel latches mitigates the lack of binary operators. Even so, though, many things are a real pain without the boolean operators.

 

Does Integer Basic provide a function to read lores pixels? If not, I wonder how Little Brick Out works.

Link to comment
Share on other sites

Does Integer Basic provide a function to read lores pixels? If not, I wonder how Little Brick Out works.

 

Do these forums have a branching function, wouldn't it be cool if a subtopic like this could be more or less automatically branched into a separate forum? :ponder:

 

:) But anyways I doubt there was a function to read pixels or even one to write them. It would have come down to peeks and pokes I'm sure.

 

EDIT -> ...Was curious and I checked the Integer Basic Spec and I was wrong. For Lo-Res graphics a precursor of the commands in Applesoft were included

 

GR Sets lores graphics mode and clears screen

COLOR=x Sets lores drawing color to x

PLOT x,y Draws a dot at location x,y

HLIN x1,x2 at y Draws a horizontal line from x1,y to x2,y

VLIN y1,y2 at x Draws a vertical line from x,y1 to x,y2

SCRN(x,y) The color of the dot at location x,y.

 

http://www.landsnail.com/a2ref2.htm

Edited by djmips
Link to comment
Share on other sites

EDIT -> ...Was curious and I checked the Integer Basic Spec and I was wrong. For Lo-Res graphics a precursor of the commands in Applesoft were included

 

Okay, so scrn() would have avoided the need to use bitwise logic when doing a lo-res game like Little Brick Out. Still, I think the Commodore's machines deserve credit for allowing AND/OR to be used with integers. Back in the day my code was sometimes bloated because I hadn't realized that "X=(X and 127) or X=((not X) and 128)" could be greatly simplified as "X=(X+128) and 255" (note that CBM BASIC didn't have XOR). In any case, any of that's better than X=X+128-256*(X>=128).

Link to comment
Share on other sites

  • 3 weeks later...

Well, after much procrastinating (as you can plainly tell) I finally got my act together and started working on this game. I've got my basic "explosion then random" idea out, but, as always, it's buggier than hell.

 

Here's what I've noticed.

 

1. After ~3 shots per player, the game crashes.

 

2. When a player is being blown up, the other player's movement goes crazy.

 

3. The "random" positioning is far from random. My guess is that it's because the "random" formula is working in a pattern and when it crashes, the pattern is reset.

 

4. I'm trying to have the exploded players color-cycle, but for some reason it isn't working.

 

Still though, I think I pulled off a pretty sweet explosion sprite here. :cool:

( I took it from missile command and added a few frames )

 

Combat_DX.bas

 

Combat_DX.bas.bin

Link to comment
Share on other sites

A little bit more work and here's where I am.

 

---------------------------------------------------------------------------------------------------------------------

1. After ~3 shots per player, the game crashes.

 

2. When a player is being blown up, the other player's movement goes crazy.

 

3. The "random" positioning is far from random. My guess is that it's because the "random" formula is working in a pattern and when it crashes, the pattern is reset. (didn't work, not sure, now)

 

4. I'm trying to have the exploded players color-cycle, but for some reason it isn't working.

---------------------------------------------------------------------------------------------------------------------

 

As you can see, I've changed the kill "loops" to subroutines thus allowing me to access the code in it's entirety and fixing both the first and second bugs. The fourth I've also fixed by tying the player colors to their "animation" variable (either x or y). It looks good, but I still would like your opinion whether I should switch to it. So, which one? :ponder:

 

NEW:

Combat_DX_Flash.bin

 

OLD:

Combat_DX_White.bas.bin

 

Still, I am still stuck with how I could get this to randomize properly (it seems all the random values are too high), so any suggestions would be appreciated. This is an open boat I'm on, don't be afraid to share your comments! Well, at least of course, if you want it to turn out right.

 

;)

Edited by Dragnerok X
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...