Porting Code

Discussion about the ZBasic language including the System Library. If you're not sure where to post your message, do it here. However, do not make test posts here; that's the purpose of the Sandbox.
Post Reply
everest
Posts: 96
Joined: 31 May 2010, 9:01 AM

Porting Code

Post by everest »

Hi,

I'm trying to port over a bunch of code onto the Zbasic platform. For most of the basic things I don't have much trouble, but I am having difficulties understanding how different variable types map between languages. I see things like "word" and "sword" and I have a great deal of difficulty understanding what the corresponding variable type would be in Zbasic. The source language in this case is Basic Micro.

I'm guessing some of these things will just require me to fully understand the source language to pull this off, but I was hoping there might be a more straightfoward way to map these things over. Here's a few examples:

Code: Select all

GetSin wordtable 0, 87, 174, 261, 348, 436, 523, 610, 697, 784, 871, 958, 1045, 1132, 1218, 1305, 1391, 1478, 1564, |
				 1650, 1736, 1822, 1908, 1993, 2079, 2164, 2249, 2334, 2419, 2503, 2588, 2672, 2756, 2840, 2923, 3007, |
				 3090, 3173, 3255, 3338, 3420, 3502, 3583, 3665, 3746, 3826, 3907, 3987, 4067, 4146, 4226, 4305, 4383, |
				 4461, 4539, 4617, 4694, 4771, 4848, 4924, 4999, 5075, 5150, 5224, 5299, 5372, 5446, 5519, 5591, 5664, |
				 5735, 5807, 5877, 5948, 6018, 6087, 6156, 6225, 6293, 6360, 6427, 6494, 6560, 6626, 6691, 6755, 6819, |
				 6883, 6946, 7009, 7071, 7132, 7193, 7253, 7313, 7372, 7431, 7489, 7547, 7604, 7660, 7716, 7771, 7826, |
				 7880, 7933, 7986, 8038, 8090, 8141, 8191, 8241, 8290, 8338, 8386, 8433, 8480, 8526, 8571, 8616, 8660, |
				 8703, 8746, 8788, 8829, 8870, 8910, 8949, 8987, 9025, 9063, 9099, 9135, 9170, 9205, 9238, 9271, 9304, |
				 9335, 9366, 9396, 9426, 9455, 9483, 9510, 9537, 9563, 9588, 9612, 9636, 9659, 9681, 9702, 9723, 9743, |
				 9762, 9781, 9799, 9816, 9832, 9848, 9862, 9876, 9890, 9902, 9914, 9925, 9935, 9945, 9953, 9961, 9969, |
				 9975, 9981, 9986, 9990, 9993, 9996, 9998, 9999, 10000
This looks like an array of "word" variables. . .?

Code: Select all

BodyRotX 				var sbyte ;Global Input pitch of the body
BodyRotY				var sbyte ;Global Input rotation of the body
BodyRotZ  				var sbyte ;Global Input roll of the body
PosX					var sword ;Input position of the feet X
PosZ					var sword ;Input position of the feet Z
PosY					var sword ;Input position of the feet Y
RotationY				var sbyte ;Input for rotation of a single feet for the gait
sinA4          			var sword ;Sin buffer for BodyRotX calculations
cosA4          			var sword ;Cos buffer for BodyRotX calculations
sinB4          			var sword ;Sin buffer for BodyRotX calculations
cosB4          			var sword ;Cos buffer for BodyRotX calculations
sinG4          			var sword ;Sin buffer for BodyRotZ calculations
cosG4          			var sword ;Cos buffer for BodyRotZ calculations
TotalX					var sword ;Total X distance between the center of the body and the feet
TotalZ					var sword ;Total Z distance between the center of the body and the feet
BodyIKPosX				var sword ;Output Position X of feet with Rotation
BodyIKPosY				var sword ;Output Position Y of feet with Rotation
BodyIKPosZ				var sword ;Output Position Z of feet with Rotation
Lots in there I don't understand, sword, word, sbyte. . .? Anyways, I suspect I've bitten off way more than I can chew here, about 1000 lines of code, but hey, it never hurts to ask :) Thanks!

-Jeff
dlh
Posts: 395
Joined: 15 December 2006, 12:12 PM
Location: ~Cincinnati

Post by dlh »

I think the s stands for signed. So sbyte ranges from -127 to +128, etc. In ZBasic a word is an integer. A word ranges from 0 to 65535 and a sword from -32767 to +32768.
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

dlh wrote:I think the s stands for signed.
That is correct. So word maps to UnsignedInteger and sword maps to Integer. There is no equivalent for sbyte. If you need 8-bit signed, you can probably use the Byte type. All of the arithmetic will work correctly but you'll have to do some extra work when you want to do value-to-string or string-to-value conversions, taking care to treat bit 7 as a sign bit.
- Don Kinzer
everest
Posts: 96
Joined: 31 May 2010, 9:01 AM

Post by everest »

How about easily defining both an array, and the individual elements? for example:

Code: Select all

Dim arrayofbytes(0 to 4) As Byte = 1, 2, 3, 4, 5
Is there a way to do that?

-Jeff
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

everest wrote:Is there a way to do that?
If the data in the array doesn't change, just use a Program Memory data item:

Code: Select all

Dim arrayofbytes As ByteVectorData({1, 2, 3, 4, 5})
Note, however, that this array is 1-based.

If the data will change, you can still use the Program Memory data item for the initialization data.

Code: Select all

Dim arrayData As ByteVectorData({1, 2, 3, 4, 5})
Dim arrayOfBytes(0 to 4) as Byte

Sub Main()
  Call GetProgMem(arrayData.DataAddress, arrayOfBytes, SizeOf(arrayOfBytes))
  Dim i as Integer
  For i = 0 to 4
    Debug.Print arrayOfBytes(i); " ";
  Next i
  Debug.Print
End Sub
- Don Kinzer
Post Reply