Jump to content
IGNORED

Pieces of Programming


orion1052003

Recommended Posts

I made a chessboard on screen with several lines of HCHAR statements. Karsten shortened it up to one line. When I ran the program with the new line in place of the old ones, it still gave the same result, and much faster. In order to understand the line, I tried to evaluate it on paper like the computer might do it. I did not check the result to see if it works out to my many previous lines, which I figure it must to work. Trying to see if I got the idea or not first.

 

90 !DRAW SQUARES
100 FOR R=0 TO 7::FOR C=(R AND 1) TO 7 STEP 2::FOR I=1 TO 3::CALL HCHAR(R*3+I,C*3+1,96,3)::NEXT I::NEXT C::NEXT R

 

R=0 TO 7

 

C=(R AND 1) TO 7 STEP 2

 

I=1 TO 3

 

H(R*3+I,C*3+I,96,3)

 

NEXT I

NEXT C

NEXT R

 

R----------C------------------C C C C

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

0 AND 1=0 TO 7 STEP 2--0 2 4 6

1 AND 1=1 TO 7 STEP 2--1 3 5 7

2 AND 1=0 TO 7 STEP 2--0 2 4 6

3 AND 1=1 TO 7 STEP 2--1 3 5 7

4 AND 1=0 TO 7 STEP 2--0 2 4 6

5 AND 1=1 TO 7 STEP 2--1 3 5 7

6 AND 1=0 TO 7 STEP 2--0 2 4 6

7 AND 1=1 TO 7 STEP 2--1 3 5 7

 

FOR R=0 TO 7 FOR I=1 TO 3 NEXT I NEXT R

 

call char 24 statements 3 statements 8 times = 3 * 8 = 24

 

But with C, 8 more statements during each increment of R, leading to 96 HCHAR statements. Only 1-24 and the last number 96 are printed here.

 

 

CALL HCHAR(0*3+1,0*3+1,96,3) = 1,1,96,3

CALL HCHAR(0*3+2,0*3+1,96,3) = 2,1,96,3

CALL HCHAR(0*3+3,0*3+1,96,3) = 3,1,96,3

CALL HCHAR(0*3+1,2*3+1,96,3) = 1,7,96,3

CALL HCHAR(0*3+2,2*3+1,96,3) = 2,7,96,3

CALL HCHAR(0*3+3,2*3+1,96,3) = 3,7,96,3

CALL HCHAR(0*3+1,4*3+1,96,3) = 1,13,96,3

CALL HCHAR(0*3+2,4*3+1,96,3) = 2,13,96,3

CALL HCHAR(0*3+3,4*3+1,96,3) = 3,13,96,3

CALL HCHAR(0*3+1,6*3+1,96,3) = 1,19,96,3

CALL HCHAR(0*3+2,6*3+1,96,3) = 2,19,96,3

CALL HCHAR(0*3+3,6*3+1,96,3) = 3,19,96,3

CALL HCHAR(1*3+1,1*3+1,96,3) = 4,4,96,3

CALL HCHAR(1*3+2,1*3+1,96,3) = 5,4,96,3

CALL HCHAR(1*3+3,1*3+1,96,3) = 6,4,96,3

CALL HCHAR(1*3+1,3*3+1,96,3) = 4,10,96,3

CALL HCHAR(1*3+2,3*3+1,96,3) = 5,10,96,3

CALL HCHAR(1*3+3,3*3+1,96,3) = 6,10,96,3

CALL HCHAR(1*3+1,5*3+1,96,3) = 4,16,96,3

CALL HCHAR(1*3+2,5*3+1,96,3) = 5,16,96,3

CALL HCHAR(1*3+3,5*3+1,96,3) = 6,16,96,3

CALL HCHAR(1*3+1,7*3+1,96,3) = 4,22,96,3

CALL HCHAR(1*3+2,7*3+1,96,3) = 5,22,96,3

CALL HCHAR(1*3+3,7*3+1,96,3) = 6,22,96,3

 

all the way till---

CALL HCHAR(7*3+3,7*3+3,96,3) = 24,24,96,3

Edited by orion1052003
Link to comment
Share on other sites

all the way till---

CALL HCHAR(7*3+3,7*3+3,96,3) = 24,24,96,3

 

The last one should of course be

CALL HCHAR(7*3+3,7*3+1,96,3) = 24,22,96,3

but otherwise you got it.

 

FOR R=0 TO 7::FOR C=(R AND 1) TO 7 STEP 2::FOR I=1 TO 3 breaks down into

 

FOR R=0 TO 7 ... 8 times

FOR C=(R AND 1) TO 7 STEP 2 ... [0, 2, 4 and 6] or [1, 3, 5 and 7] ... 4 times

FOR I=1 TO 3 ... 3 times

...

8*4*3 = 96 times

 

Try this one for a bit of fun ...

 

100 FOR R=0 TO 7
110 FOR C=(R AND 1) TO 7 STEP 2
120 FOR I=1 TO 3
! CALL HCHAR(R*3+I,C*3+1,96,3)
130 PRINT "CALL HCHAR("&STR$(R)&"*3+"&STR$(I)&","&STR$(C)&"*3+1,96,3)"
140 PRINT "= "&STR$(R*3+I)&","&STR$(C*3+1)&",96,3"
150 NEXT I
160 NEXT C
170 NEXT R

  • Like 1
Link to comment
Share on other sites

I goofed up the last one yeah...I values instead of 1. Since 1 and "i" look so similar, I accidentally wrote the whole thing out with C*3 + i instead of 1 and had to redo it. Apparently I'm starting to understand some of the relational expressions..Albert, what happens when the neutrinos start to move faster than the speed of light? See you yesterday, and thanks!

Link to comment
Share on other sites

  • 3 weeks later...

Back to relational expressions....I tried to see what numbers come up with AND. Since Karsten used AND 7 to make a pattern of 1- 7 to use in a FOR NEXT loop. Looks like some results alternate between zero and one, and a couple patterns of repeating numbers like 2,2,4,4. Maybe this results table can be used by you programmer's for reference. I also made a short program to print the results although I wish I knew how to spruce it up a bit.

 

10 !AND 1-PRINTING RESULTS OF AND WITH NUMBERS
15 CALL CLEAR
17 PRINT "THE POWER OF AND" :: PRINT
20 FOR I=0 TO 9
25 FOR J=0 TO 9
30 IF I=2 AND J=0 THEN PRINT "PRESS ANY KEY TO CONTINUE" :: LINPUT L$
40 IF I=4 AND J=0 THEN PRINT "PRESS ANY KEY TO CONTINUE" :: LINPUT L$
50 IF I=6 AND J=0 THEN PRINT "PRESS ANY KEY TO CONTINUE" :: LINPUT L$
60 IF I=8 AND J=0 THEN PRINT "PRESS ANY KEY TO CONTINUE" :: LINPUT L$
70 ! AND OPERATIONS
80 PRINT I;" AND ";J;" = ";I AND J
90 NEXT J
100 NEXT I

 

 

 

0 AND 0 = 0

0 AND 1 = 0

0 AND 2 = 0

0 AND 3 = 0

0 AND 4 = 0

0 AND 5 = 0

0 AND 6 = 0

0 AND 7 = 0

0 AND 8 = 0

0 AND 9 = 0

1 AND 0 = 0

1 AND 1 = 1

1 AND 2 = 0

1 AND 3 = 1

1 AND 4 = 0

1 AND 5 = 1

1 AND 6 = 0

1 AND 7 = 1

1 AND 8 = 0

1 AND 9 = 1

2 AND 0 = 2

2 AND 1 = 0

2 AND 2 = 2

2 AND 3 = 2

2 AND 4 = 0

2 AND 5 = 0

2 AND 6 = 2

2 AND 7 = 2

2 AND 8 = 0

2 AND 9 = 0

3 AND 0 = 0

3 AND 1 = 1

3 AND 2 = 2

3 AND 3 = 3

3 AND 4 = 0

3 AND 5 = 1

3 AND 6 = 1

3 AND 7 = 3

3 AND 8 = 0

3 AND 9 = 1

4 AND 0 = 0

4 AND 1 = 0

4 AND 2 = 0

4 AND 3 = 0

4 AND 4 = 4

4 AND 5 = 4

4 AND 6 = 4

4 AND 7 = 4

4 AND 8 = 0

4 AND 9 = 0

5 AND 0 = 0

5 AND 1 = 1

5 AND 2 = 0

5 AND 3 = 1

5 AND 4 = 4

5 AND 5 = 5

5 AND 6 = 4

5 AND 7 = 5

5 AND 8 = 0

5 AND 9 = 1

6 AND 0 = 0

6 AND 1 = 0

6 AND 2 = 2

6 AND 3 = 2

6 AND 4 = 4

6 AND 5 = 4

6 AND 6 = 6

6 AND 7 = 6

6 AND 8 = 0

6 AND 9 = 0

7 AND 0 = 0

7 AND 1 = 1

7 AND 2 = 2

7 AND 3 = 3

7 AND 4 = 4

7 AND 5 = 5

7 AND 6 = 6

7 AND 7 = 7

7 AND 8 = 0

7 AND 9 = 1

8 AND 0 = 0

8 AND 1 = 0

8 AND 2 = 0

8 AND 3 = 0

8 AND 4 = 0

8 AND 5 = 0

8 AND 6 = 0

8 AND 7 = 0

8 AND 8 = 1

8 AND 9 = 8

9 AND 0 = 0

9 AND 1 = 1

9 AND 2 = 0

9 AND 3 = 1

9 AND 4 = 0

9 AND 5 = 1

9 AND 6 = 0

9 AND 7 = 1

9 AND 8 = 8

9 AND 9 = 9

Link to comment
Share on other sites

I have a question on making title screens...If you have the "KNIGHT MOVES" screen, and you want to optimize by getting rid of a bunch of vchar statements, how would you generate the Column numbers? For example, on the 24 x 32 grid, there are 13 straight down vertical lines, each 5 characters long in the title "KNIGHT MOVES". My thought was to use typical statements for the diagonal or small parts of letters, but to try and shorten the statements for the several vertical lines that are all of the same length. Right now each vertical line has a CALL VCHAR to draw it. Maybe I could shorten this to 2 statements and a for next loop instead of 13.

 

CALL VCHAR(9,C,CHAR,5)

 

CALL VCHAR(16,C,CHAR,5)

 

Say you wanted to use a FOR loop or something, knowing all the parameter numbers would remain the same except for column..How would you come up with something to generate the column numbers?

 

The co-ordinates are 9,4 - 9,9 - 9,13 - 9,16 - 9,19 - 9,24 - 9,26 - 9, 29 - 16, 5 - 16, 10 - 16,12 - 16, 14 - and 16, 25.

post-19460-0-78405600-1335312632_thumb.jpg

Link to comment
Share on other sites

Back to relational expressions....I tried to see what numbers come up with AND. Since Karsten used AND 7 to make a pattern of 1- 7 to use in a FOR NEXT loop. Looks like some results alternate between zero and one, and a couple patterns of repeating numbers like 2,2,4,4. Maybe this results table can be used by you programmer's for reference. I also made a short program to print the results although I wish I knew how to spruce it up a bit.

 

With the logical operators, you need to think of your numbers in binary. Once you start thinking as numbers in ways other than base-10, you will find computers a lot more interesting. Once you get the basics down, I think you will find you can do a lot of this in your head.

 

The AND operator you were experimenting with makes more sense when you do the operation on the bits. The truth table for AND is pretty simple (these are single bits):

0 AND 0 = 0
0 AND 1 = 0
1 AND 0 = 0
1 AND 1 = 1

It works just like the word specifies, you "this" AND "that". One or the other won't work (because that would be an OR operation).

 

Another example, decimal on the left, binary on the right:

   8421 place value
   ====
4 = 0100
2 = 0010
   ----
0   0000

You can see pretty quickly how 4 AND 2 = 0. You just AND the columns, and since there is no column with a 1 in both numbers, the result is 0. You can also quickly see that, any numbers with bits set in the bottom two bits, when ANDed with 4, will result in 0:

0 = 0000
1 = 0001
2 = 0010
3 = 0011

Since 4 (0100) does not have bits set in the bottom two bits, all of those number will result in 0. You can also quickly see that, any number that does not have the 3rd bit set, when ANDed with 4, will result in 0.

8  = 1000
9  = 1001
10 = 1010
11 = 1011

The AND and OR operators are typically used as a "mask", to isolate and test if bits are on or off, or to set or clear specific bits.

Link to comment
Share on other sites

CALL HCHAR and VCHAR are relatively powerful commands. An alternative to building more complex layouts like the big text on the title screen is using PRINT or DISPLAY AT, if you can do with only 28 characters in width (instead of 32). DISPLAY AT only found with Extended Basic and demonstrated in the attachment below. It all depends, but I think you will find it (PRINT or DISPLAY AT) both faster, smaller and easier to maintain (edit) (than using HCHAR and VCHAR).

 

 

 

You'll notice a compressed version using only 2 DISPLAY AT will draw much faster. A bit more difficult to maintain though. You have to use PASTE XB in Classic99 because of the long programlines.

 

 

Edited by sometimes99er
Link to comment
Share on other sites

I have never used Classic 99 before. All Win99/4A so far. I wrote out those 100 AND results on a couple sheets of paper at work, and then made the little program to display them on screen. I guess ANDing the numbers was pretty easy like you say, because of the masking. I read that

Night Mission article about setting, checking, ANDing, ORing, bits to use flags in a program. I don't get it still, how to actually use flags from a byte in a program. Thanks for the KnightMoves txts. Checking em out.

Link to comment
Share on other sites

Wikipedia: Flag (computing)

 

If we isolate the use of flags to XB, then I think it's best to keep information in separate ordinary numeric variables (and/or numeric arrays). I think it's usually faster and have easier to read code.

 

One may use a string variable to store different bytes (or any other number of bits), but my experience is, it takes its share of computing power and have the internal garbage collector kick in more often (opposed to using numeric variables). Garbage collecting can halt automatic sprite motion for a brief moment.

Edited by sometimes99er
Link to comment
Share on other sites

Strings are great ways to store bytes of information and can make for some quick searches. In my BBS software I use strings to hold message base information such as who wrote a message and the message recipient. Using a combination of SEG$ and POS, you can do quite a bit with limited memory.

 

Applying this to an adventure game, one could store room locations, treasures, or other data in a string and then using POS, quickly determine where they are located. The advantage to this method is you don't need to loop through an array and can often speed up iterative searches. I bet applying the logic operations could really make for some tight code though at a loss of speed depending on their application.

 

(where the devil did the 'preview post' disappear to? Ugh)

Edited by InsaneMultitasker
Link to comment
Share on other sites

  • 5 weeks later...

Any idea why the knight character only shows up as the top half? Had this in a couple other programs, too. heh.

 

Sprites can be either 1 character or 4 characters in size. Use CALL MAGNIFY(3) to go from 1 to 4 characters. You have only defined 2 characters for the knight (line 170), setting characters 112 and 113 in line 190. If you do change the size of the sprite, then characters 114 and 115 also gets included in the sprites definition (only with 112 as reference). You have however used character 115 for other purposes (line 190 and on). You will have to make quite a few changes to go that way, - instead I chose to simply add yet another sprite to show character 113 just below the other. All you have to do is add:

 

331 CALL SPRITE(#2,113,16,HR+8,HC)

 

Simple, but then only problem is, you have to update both sprites to move the knight. With a 4 character sprite, you could have a situation where you only need to update one sprite to move the knight.

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