Moved to iPhoneOS.tk

Written By Akki On Tuesday, March 17, 2009

Join us here on

Share and Enjoy:
  • del.icio.us
  • StumbleUpon
  • Digg
  • Sphinn
  • Facebook
  • Mixx
  • Reddit
  • Technorati
  • IndianPad
  • YahooMyWeb

Sarat's iPod : Upgrade from 1.1.4 to 2.2.1 and JailBreak

Written By Akki On Wednesday, March 11, 2009

This was seems less tedious task, as it is

I thought putting just few hours will be enough (Frankly speaking)
But it does not seem like that ..
Competibility issues of FW(FirmWare), with the tools
Now, I have alomost every tools available for Mac and Windows, on my Mac and PC desktop.
right now 5 to 6 restore IPSWs
:)
I have used latest version of Pwnage tool, QuickPwn(Mac) and QuickPwn(win), date is 11th March 2009.
Now just got QuickPwn 2.0 from my Brother, which is old and should support the FW 1.1.4.
Lets See ....
Sad as i opened the app, it was the same..
now looking over the the net if i see earlier version of QuickPwn :|

Using the WinPwn 2.5 Beta
After an hour or more after writing the above line, nothing happened, absolutely NOTHING...
at last I m feeling that neither any restore nor any tool will, until I m upgrading to FW 2.0, TTF (Thats The F*CK) it is not available.. at least I can say no direct link, no RapidShare link, NO weblink.. I m able to find to find on the torrent only, and in the torrent also it is almost dying stage. I have added 4 diffrent torrents, one is now working good....
SO it shows this file is critical...
finished above para 6:00 AM 12 March 2009..
Waiting for the FW 2.0 to get download ... Lets see That is working or not, if that is not working I will must say that One should give $9.95 to apple and purchase the update...
If I m successfull, I will say your many many hours of work, As I m going to hit 10th hours or working on the same issue...

1:12 PM 12 March 09
Volia.... I got FW 2.0 on the ipod touch...
aaaah at last ...ufffff
this was the problem...
So guys if you are on 1.1.4 FirmaWare and want to upgrade on 2.x.x or want to come to the series 2.o, you need 2.0 FW ( As it is paid ) hahhaha
Anyways
Now I m on FW 2.0..
getting ready for 2.2.1 hahahhah...


4:01 PM
ahhh but great apps are not taking 2.0
but that is not an issue i have offcial 2.2.1 updates i will take them

4:37 PM 12 March 2009
After having the FW 2.0, I cant update with IPSW 2.2.1, reason is still unknown, but not so long.
The final plan is to have update through iTune.. hehehee...

3:24 AM 13 March 2009
The myth about the iPod generation cleared completly.. I guess, Now I have all the FirmWare for iPod touch 1G,
Again I restored iPod Touch with FW 2.0..
Now going to upgrade to 2.0.1 Let see if that is successfull..
Waiting for my IBM Thinkpad to reboot, I have all the FirmWare in that :)

3:33 AM 13 MAR 09
I have 2.o on my iPod very much.
I have 2 way to upgrade it till 2.2.1, either via iTunes or manual.
iTunes is again on network dependent as it does not store the partial downloads.
I m again and again getting the network error.

4:30 AM Mar 09
Updating to FW 2.0.2,
Lets see what is waiting for me...
YAHOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
We did it again, hahahhahaaaa

4:33 AM Mar 09
Now Heading to update with 2.2.1 5h11 THE LATEST UPDATE ....
Let see what is the next...
4:36 updating now ... Clenched my teeth together...
WOW ... revolving Gear is changed as a rounded Progress Bar...
4:39 Verifying the updated software..
I guess we are going to hit again...
But still we have not got through.. :)
oye lucky, lucky oye
we are super duper hit, paape.. :) :D

Now the Risky part comes, Pwning the iPod touch...

At last iPod is jailBroken...
It was a tedious Job any...
It is having 2.2.1 and jailbroken, but not yet ready for Mobile installation.
Let a mobile installation another post... ;)
At last but not the least, many many thanks to Sarat for providing his iPod Touch...



Share and Enjoy:
  • del.icio.us
  • StumbleUpon
  • Digg
  • Sphinn
  • Facebook
  • Mixx
  • Reddit
  • Technorati
  • IndianPad
  • YahooMyWeb

FIrst Attempt to JailBreak iPod touch

Written By Akki On Tuesday, March 10, 2009

Here was a task to Jailbreak the iPod touch having FW 1.1.4
The very first attempt was failed
I need to restore the FW with the same version 1.1.4..
Right now downloading the FW 2.2.1
Pwnage tool was failed to jailbreak it although it was the latest version..
Now looking for QuickPwn's latest version.
Let see what happens..

Share and Enjoy:
  • del.icio.us
  • StumbleUpon
  • Digg
  • Sphinn
  • Facebook
  • Mixx
  • Reddit
  • Technorati
  • IndianPad
  • YahooMyWeb

here is How to get cracked iPA's on iPhone/iPod Touch

Written By Akki On Wednesday, March 4, 2009



After you have jailbroken your ipod touch 2.x what you wanna do is 

1.Log into WinSCP (windows) or Cyberduck (Mac) 
If you don't know how to do this -

Code:
http://www.youtube.com/watch?v=YtfjDHfqXWQ

2.Create a folder called Documents in /var/mobile/ and set permission to 777
3.Create a folder called Documents in the /Applications folder and set permissions to 777
4.Now go to root /System/Library/PrivateFrameworks/Mobile Installation.framework 
5.Replace the MobileInstallation file and set the permissions 775 for the file 
6.Reboot your iPhone/iPod Touch-IMPORTANT! 
7.Download cracked Games and Apps. 
8.Download at least one App from t he App Store(Free or Paid) 
IMPORTANT: Otherwise you will get an error! (Only need to do this once] 
9.Double click on the cracked .ipa you downloaded, and iTunes Should Open And Then Just Sync your iPhone/iPod Touch and enjoy! 

You Set Permission by right clicking and choosing properties, you wont miss it 
HERE IS THE MOBILEINSTALLATION FILE: 
Code:
http://rapidshare.com/files/148053500/MobileInstallation.rar

Enjoy Very Happy 

Share and Enjoy:
  • del.icio.us
  • StumbleUpon
  • Digg
  • Sphinn
  • Facebook
  • Mixx
  • Reddit
  • Technorati
  • IndianPad
  • YahooMyWeb

Install cracked ipa's using iTunes

Written By Akki On Sunday, March 1, 2009

Install cracked ipa's using iTunes. Change your Mobile Installation File without computer support.

1. Go to your pawned iPhone, open Cydia.



2. Go to Manage and choose Sources



3. Press the Edit Button and then the Add button



4. Add the following sources:

4.1. OpenSSH:
Code:
http://apt.saurik.com/
Don't need to add this one, it's already installed by default, just search for the app.



4.2. Erica Utilities: www.ModMyi.com



4.3. Mobile Instalation File: http://iphone.org.hk/apt/



The installation has to be made the way above, leave Mobile Installation file for last.

Restart the iPhone and install first a legit app, download a free app from the appstore [VERY IMPORTANT STEPS] and it's done! Now you can install any cracked ipa using iTunes.

Share and Enjoy:
  • del.icio.us
  • StumbleUpon
  • Digg
  • Sphinn
  • Facebook
  • Mixx
  • Reddit
  • Technorati
  • IndianPad
  • YahooMyWeb

CRACKULOUS v.9

Written By Akki On Saturday, February 7, 2009

SaladFork make Crackulous. People use Crackulous. Angel Take over. Crackulous good. We release Crackulous today.


CRACKULOUS v.9
We at Hackulous have decided to open up the beta version of Crackulous for the entire community. If you haven't already heard about Crackulous, it's an amazing application dedicated to the iPhone community to cracking apps. Crackulous was first started by SaladFork, and now the application is being developed by Angel. We've decided to release Crackulous v.9 as an Open Beta, so anyone can try it out!

Features:

* Full GUI version of xCrack! No Complications!
* Crack Applications from the App Store! Share them with the community!
* The ONLY Application of its kind!
* The most POWERFUL and EASIEST to use application!
* Crack multiple apps at one time!
* It's free! Why would we charge?

Read more at: What is Crackulous?


So where do we get it? From the Hackulous Cydia Repo of course!
http://cydia.hackulo.us


Known Bugs (Major):

* You must have at least one legitimate app from the App Store
* If any of your apps begin with a #, Crackulous will crash (Bug fix on the way)

If you have more bugs to share, tell us at: Crackulous Forum

Issues:

* If You cannot see Crackulous in the repo, restart your cydia (or your device) and have it update it's sources



Kyek's FAQ
We're getting a lot of common questions in this thread -- so I posted this on page 4, but it might be better served here in the original post smile.gif

Crackulous crashing on startup?
Many people are saying that it crashes when you have an app with a number in it. It's not necessarily numbers IN apps, it's apps that START WITH a number. This is a known bug, and it's mentioned in the original post. There should be a fix soon, so don't feel the need to delete your precious apps right away ;-). There's also a rare bug report about apps with 3 or more digits in the name causing a problem with Crackulous, but so far that's not been confirmed.

Make sure you address your crashing in the official Crackulous crashing topic.

But how do I crack apps without buying them?
You don't. Every single app that's ever been cracked has been legitimately purchased by the cracker. Part of the cracking method requires you to run the app on your iDevice before it's cracked, and the only way to do that is by buying it and downloading it legitimately. Makes you think twice before you start spamming the requests board, doesn't it? ;-)

I cracked an app but how do I get it?
Crackulous tells you exactly where to find the app once it's cracked -- all you need to do is log into your phone via SFTP (you need OpenSSH from Cydia for this). Don't know how to do that? This, my friends, is why we have a Tutorials section here at Hackulous ;-) Take some initiative and search for it!

Where do I upload the app?!?!?!?!?!1cos(0)1
If your goal is to get the app posted on Appulous (and it should be!) you'll need to upload it to a filehost. Actually, if you want your app to stick around for awhile, you'll want to upload to a few filehosts! The ones that work on Appulous are listed here. Then, if you don't already have one, register for an account at Appulo.us, verify your E-mail (see here if you have problems with that), log in, then use the "Submit an App" link at the top of Appulous.

Share and Enjoy:
  • del.icio.us
  • StumbleUpon
  • Digg
  • Sphinn
  • Facebook
  • Mixx
  • Reddit
  • Technorati
  • IndianPad
  • YahooMyWeb

How to add cracked apps to your iPhone

Written By Akki

This tutorial will show you how to install cracked .app applications on your iPhone. Although very easy and convenient, this is not the best way to add cracked apps. Given that most cracked iPhone apps are .ipa files, I recommend you have a look at guide on how to install .ipa files on your iPhone instead.

I assume that you’re on a jailbroken 2.X iPhone and that you have installed OpenSSH from Cydia.

1. Download cracked application.

2. Unzip the cracked application folder to your desktop.

3. SSH into iphone.

4. In WinSCP, navigate to /Applications.

5. Drag the cracked application folder over the /Applications folder and drop it in there.

6. Right click on the cracked application folder and change permissions to 0755 and select the box beside “set owner group and permissions recursively” (or go inside the folder, select everything, and set properties to 0755 as well), then hit ok.

7. In the /Applications folder, make a new folder called “Documents”, with a capital D. Change the permissions on the “Documents” folder you just created to 0777.

8. Navigate to /var/mobile/ and make a new folder called “Documents”, with a capital D. Change the permissions on the “Documents” folder you just created to 0777.

9. Reboot your device

Note: Some applications require you set permission to 0775. It seems to be kinda random so if 0755 doesn’t work, try 0775.

Share and Enjoy:
  • del.icio.us
  • StumbleUpon
  • Digg
  • Sphinn
  • Facebook
  • Mixx
  • Reddit
  • Technorati
  • IndianPad
  • YahooMyWeb

How to add ipa files to your iPhone

Written By Akki

Hello to you, iPhone hacker! Hello to you too, iPod Touch hacker…

So it’s not a secret anymore… many iPhone games and applications have been cracked (and still are). Basically, you can get 2 types of files. The “normal” .app file, and the cracked ipa file. We already covered the method to install .app files on your iPhone. Now here is the other method, the most popular one, to install cracked .ipa files such as games and applications on your iPhone or iPod Touch.

As a reminder, this is illegal! I do not encourage anyone to hack or crack iPhone games. Some developpers spend quite some time working on them and they don’t want to see their work ripped off. If you see an iPhone game or application that you like, download it legally through the App Store.

This method works for all firmwares from 2.0 to the current firmware available. The only thing that changes is the MobileInstallation file that you have to install. Each device (iPhone/iPod Touch) has its own MobileInstallation file for each version of the firmware. I started tracking these MobileInstallation files from iPhone 2.1. I do not have them for older firmwares and I do not have them for iPod Touch, although they might be the same as the iPhone’s. I don’t own an iPod Touch, thus I never tried this before on one but some users reported to me it worked great.

By the way, you may want to check my list of cracked iPhone games and applications.

So, how to install ipa files on an iPhone or iPod Touch?

1. You need to be on jailbroken iPhone with Cydia installed. For this, you may use QuickPwn, PwnageTool, or WinPwn. See my tutorials for on how to jailbreak your iPhone or iPod Touch using any of these tools.

2. Install OpenSSH from Cydia on your iPhone. Click on Cydia and then click Install (Sections)>Networking>OpenSSH then click Install>Confirm (if you get a running out of disk space error click “ok”).

3. Log into WinSCP. The first time you try to login you may get a connection timeout error, click retry several times (up to 20 times!) and it should work. If you still get an error, reboot your iPod/iPhone and try again.

4. Navigate to /private/var/mobile/ folder

5. Set the permission of the Applications folder to 777 (make sure reclusive is checked).

6. Stay in the /private/var/mobile/ folder.

7. Create a folder called “Documents” in the /private/var/mobile/ folder. Make sure to spell “Documents” correctly, with a capital “D”.

8. Set the permission to 777.

9. Navigate to the root level and open the /Applications folder.

10. Create a folder called “Documents” inside the /Applications folder and set permission to 777.

———Note: You will only need to create these two Documents folders once———

11. Go to /System/Library/PrivateFrameworks/MobileInstallation.framework

12. Rename the file “MobileInstallation” to “MobileInstallation.bak”

13. Download this patched MobileInstallation file from HERE. Note that you have to download the patched file for the firmware you are running. ie. if you are running 2.1, you need the MobileInstallation 2.1 patched file.

14. Place the patched file into the /System/Library/PrivateFrameworks/MobileInstallation.framework folder and set the permissions 775 for the patched MobileInstallation file. If there is some type of extension (ie .dylib), then you need to remove that extension.

15. Reboot your iPhone/iPod Touch

16. Download cracked api Games and Apps from Here.

17. Download at least one App from Apple App Store (Free or Paid). What I do is I download one app from the App Store using iTunes, then I sync my iPhone and reboot it. Then I download one app from the App Store on the iPhone and reboot the phone. THIS IS VERY IMPORTANT: Otherwise you will get an error! [Only need to do this once]

18. Drag and drop the .ipa file you downloaded into the iTunes Application library.

19. Sync your iPhone/iPod Touch and enjoy!

Errors:

The application “XXXXXXX” cannot be opened
Fix: Reboot your iPhone or iPod

0xE800001 Error:

FIX: Change usb port and reboot your iphone/ipod Touch.
If this doesn’t work try going into: Control panel->System->Device Manager->Universal Serie Bus Controller->Right click Apple Mobile Device USB Driver and update driver.

0xE800013 Error:

You get this error when you already have the app
FIX: Simply delete the .app folder that u have ssh’d and reboot.

Share and Enjoy:
  • del.icio.us
  • StumbleUpon
  • Digg
  • Sphinn
  • Facebook
  • Mixx
  • Reddit
  • Technorati
  • IndianPad
  • YahooMyWeb

Term you will hear, when looking for unlocked iPhone

Written By Akki On Friday, February 6, 2009

Baseband 101

The ‘baseband’ is the generic name given to the internal components of the iPhone that handle the phone calls and Internet access. This ‘baseband’ is a tiny and unique independent computer system that runs inside your iPhone, it is separate to the main system that handles the applications (such as email and google maps) and it talks to the main part of the phone over an internal communications network. Think of it like a cable modem or other peripheral that is attached to your home PC that needs occasional updates. When a software update is released and presented to you within iTunes the baseband is sometimes updated (to fix bugs or add new features). The 2.2.1 update for the iPhone 3G contains such an update, so running the vanilla updater straight away with iTunes will reprogram and update the baseband. This could be bad for certain people, depending on your ultimate aim.

SIM Free/SP Unlocked/Factory Unlocked iPhone 3G

This applies if you bought your iPhone 3G for $$$$$$$. This model of iPhone 3G doesn’t have an Service Provider lock (aka factory unlocked) and you are able to put any SIM card into the phone and get service. Your phone is already unlocked so you do not need to worry about baseband updates, simply upgrade to 2.2.1 using iTunes and then use QuickPwn to Pwn and Jailbreak. This will add Cydia and Installer too.

Locked iPhone 3G - Preserve Baseband

This applies if you have a locked iPhone 3G and you wish to update to 2.2.1 but preserve the iPhone’s current baseband software. Preserving the baseband will ensure that you can still use “yellowsn0w” the iPhone 3G unlock application. To upgrade your phone to 2.2.1 and preserve the state of the baseband you need to create a custom .ipsw with PwnageTool. This custom .ipsw will not contain the baseband update but of course will still give you any new stuff from 2.2.1

There are plenty of tutorials about this process on the web, but PwnageTool contains intuitive graphics and easy to follow prompts that should have you up and running in no time at all. Please note: PwnageTool is only available for Mac OS X.

Locked iPhone 3G

If you are using your iPhone with one carrier and have no interest in the possibility of an iPhone 3G unlock in the near future then just restore or upgrade to 2.2.1 using iTunes and use QuickPwn to Jailbreak and add Cydia and Installer.

iPhone 2G (1st Generation)

Update or Restore your iPhone 2G with iTunes then run QuickPwn to do the magic, ‘nuff said, you don’t need to worry about anything.

iPod Touch 1G (Original iPod Touch)


Update to 2.2.1 with iTunes and run QuickPwn.

iPod Touch 2G (New iPod Touch)


Sorry, no support at this time, but Redsn0w is being actively researched and developed.

Fixing DFU mode on 10.5.6

As noted previously OS X 10.5.6 introduced a bug that affected the use of DFU mode. with some Macs. There have been previously published hacks and techniques to fix this, but here is another method that can be used to temporarily restore DFU functionality in order to use QuickPwn or PwnageTool.

  1. You will need an account with ADC (Apple Developer Connection) this is free and takes a few minutes to sign up, you should read the terms and conditions carefully and you should only sign up if you are thinking of developing applications in the future - http://developer.apple.com/mac/
  2. Download the disk image “IOUSBFamily-315.4-log.dmg” for Mac OS X 10.5.5 Build 9F33” (yes, that is a “5” in 10.5.5 - this is a developer debug package of the USB kernel extension).
  3. Unplug non-vital USB equipment, such as external DVD writers, USB scanners, USB mass storage devices, at the most leave a Keyboard and Mouse connected.
  4. Install IOUSBFamily-315.4.1.pkg from within the disk image
  5. Reboot your system!
  6. Perform necessary DFU activity with QuickPwn or PwnageTool.
  7. Download the disk image IOUSBFamily-327.4.0-log.dmg” for Mac OS X 10.5.6 Build 9G55”
  8. Intall IOUSBFamily-327.4.0.pkg from within the disk image
  9. Reboot your system!
  10. Reattach your USB peripherals.

Share and Enjoy:
  • del.icio.us
  • StumbleUpon
  • Digg
  • Sphinn
  • Facebook
  • Mixx
  • Reddit
  • Technorati
  • IndianPad
  • YahooMyWeb

Jailbreaking your iPhone for Dummies.

Written By Akki




Ok, so you see these *.ipa files on this and other trackers and want to know how to get them on your iPhone without having to be a Unix command line expert. There are tons of tutorials on YouTube, but I'd say 90% of them are poorly done and outdated with old Unix commands for setting permissions and creating directories. Bleh! Rolling Eyes

First you'll need to Jailbreak your iPhone. First worry that comes up for noobs is "Will it ruin my iPhone, void the warranty, and piss Steve Jobs off?" Rolling Eyes

The short answer is no. You can always reformat your phone and go back to the normal firmware. When you hear the "scary" brick term, it just means some app locked up the phone and now they have to reformat it back to normal.

To Jailbreak your iPhone (rather easy process), visit:

http://blog.iphone-dev.org/

Get the QuickPwn software for your firmware. As of this writing it was 2.1. The app will tell you with cartoons and movies EXACTLY what to do. A complete idiot could do it in about four minutes.

To put on [k]'d apps with the ipa extension, do this step (only need to do once. Also notice there there are no complicated Unix commands you have to enter.)

  1. Make sure you've installed at least one free app from iTunes. It somehow preps the iPhone for more apps.
  2. Run QuickPwn on your iPhone if you haven't already.
  3. Open Cydia on your device and let it download its stuff. If this is your first time running Cydia, it will download a bunch of updates and restart a couple of times.
  4. Tap on Manage and go to Sources.
  5. Tap Edit. Tap Add. Type in "http://www.iphone.org.hk/apt/" into the text box. Tap on Add Source.
  6. Let it do its thing and when you get back to Cydia tap on Search.
  7. Find and install Link Identity Editor.
  8. Find and install MobileInstallation Patch.
  9. Restart your device. (hold the top power button down for 5 seconds) Congratulations, you can now sync unsigned IPA packages to your device.
  10. Now simply double click any *.ipa file and iTunes will boot up and add it to your library so that it will sync.


Where to get [k]'d IPA files:

Bittorrent Trackers:

  1. Demonoid's Iphone Section
  2. Weekly archives of the most popular apps on the AppleStore Great way to download the best apps quickly to get started

By the way, you can get IPA files directly from these websites rather than bittorrent.

  1. http://www.megaupload.com/?f=TQ2I5VP6Good
  2. http://iparepo.com/No download links yet...
  3. http://appulo.us/appdb/Looks really good. RSS Feed for any new apps that get added to Appulo.us[/ur]
  4. http://www.themonkeysball.com/ Site destroyed by Apple's lawyers... oh well
  5. http://themobileapps.com/ Site has not been updated for a couple of months
  6. http://www.4shared.com/dir/8492007/8d1e19ab/sharing.htmlOct 1 - Site is down
  7. http://www.freewebs.com/iauzy/crackedipas.htmDec 9 - Site shut down
  8. http://www.sendspace.com/folder/l1rq06


Piratebay will often have large archives of them.

In addition, two things that I love about a Jailbroken phone:

PdaNet - Free tethering -- use AT&T's internet connection for free on your laptop!
Adblock for Safari. - You'll need Cyberduck (free) but it's an easy drag and drop step.

If you have any links or criticisms of this post, please reply here.

New!PdaNet is now crippleware after two weeks. To get the full version of many jailbroken apps do this:
1. Open Cydia and Add Source: http://xsellize.com/cydia/
2. Install PdaNet 1.4.0 from the source you just added.
3. You now have PdaNet 1.4.0 cracked Very Happy

In general, any information on warezing Jailbroken apps can be found here:
http://www.xsellize.com/forumdisplay.php?f=47

Installing cracked apps directly on to your iPhone without having to use a computer

Share and Enjoy:
  • del.icio.us
  • StumbleUpon
  • Digg
  • Sphinn
  • Facebook
  • Mixx
  • Reddit
  • Technorati
  • IndianPad
  • YahooMyWeb

Tutorial 42 - Pointers

Written By Akki On Friday, November 16, 2007

Tutorial 42 - Pointers

Pointers

Ah, the wonderful world of pointers! Have you ever read about them or heard about them? The cause of programmer's nightmares all around the world. Even if PPL allow you to live without them, you still can use them to expand the power of your programs.

Lets start with string pointers. Strings in PPL are stored pretty much like any other strings in other programming languages. Each byte represents a character. If you define a string, you can later on access its pointer value and go to a specific character by adding a value to it.

s$ = "HELLO WORLD";
i$ = &s$ + 3;
ShowMessage(@i$);

The following code will display "LO WORLD" in a dialog. The value of variable i$ will be the pointer location of s$ in memory plus the value 3. Now i$ is a simple numerical variable, nothing more. We need to convert it back into a string. The @ operator is used to convert a numerical value into memory content.

Share and Enjoy:
  • del.icio.us
  • StumbleUpon
  • Digg
  • Sphinn
  • Facebook
  • Mixx
  • Reddit
  • Technorati
  • IndianPad
  • YahooMyWeb

Tutorial 41 - The physic engine

Written By Akki

Tutorial 41 - The physic engine

The physic engine

Our world is made of physic, everything is physic! Gravity pushes every object to the ground, every step we take involves friction with the surface our shoes come in contact with, wind blows and pushes leaves around and balls bounces from the ground and walls with different elasticity. When applied to a game, physics can add more realism and can add possibilities you thought were too hard to code. PPL comes with a 2D automated physic engine. When I say automated I mean it, you only need to set the mass of a sprite, set the global gravity and the physic will take care of pushing the object down. Objects can bounce back and forth by simply assigning an elasticity value. The physic is far from an advanced one that supports object deformation on collision and such but it can do a very good job simplifying your life while developing your game.
Lets first start by reviewing the principal functions used by the physic engine:

SetSpriteMass(Sprite$, Mass);

The mass is a percentage value that is compared to the other sprites with physic. A sprite with 0.5 mass will weight half the weight of a sprite with a mass of 1.0.

SetSpriteElasticity(Sprite$, Elasticity);

The elasticity value is a percentage compared to the other sprites. The bigger the value the more rebound will be applied when the sprite collides with another sprite.

SetSpriteFriction(Sprite$, Friction);

The friction is the amount of friction in percentage applied to reduce the movement speed of the sprite when it collides with another sprite.

SetGravity(Gravity);

This function will set the global gravity of the sprite engine, the value of the gravity is applied to the sprites movement speed each cycle. Default gravity is around 0.1.

SetFriction(Friction);

Set the global friction that is applied to sprite's movement speed each cycle. The default friction value is 0.00025.

There are options that need to be activated for the physic engine to consider moving the objects around. The first one is the SO_KINETIC to active the physic engine on the sprite itself. The second one is the SO_BOUNCE, it will make the sprite bounce around from other sprites. The bounce force is calculated based on the Elasticity of the sprite. Sprites must have the SO_COLLIDECHECK option set to them for bouncing to occur. You can have your sprites bounce from the screen edges by setting the SO_BORDER option. Most of the sprites you will want to bounce around will be of oval shape, you will want to set the SO_OVAL option for the physic engine to bounce the sprite like a real oval shaped object.

Lets review the bounce.ppl demo that comes with PPL. This demo involves 5 basketball balls bouncing around from the screen edges and from each other. In this example we create 5 sprites with the basketball ball image and the we set the options of each sprite to oval shape, collision checking, pixel checking and border collision check.

// Set global gravity.
SetGravity(0.1);
// Set global friction.
SetFriction(0.005);

i$ = 0;
while (i$ < 5)
// Load ball sprite from disk.
s$ = loadsprite(AppPath$ + "ball.bmp", G_RGB(255, 0, 255), 1, 0, NULL);

// Activate pixel perfect collision detection.
AddSpriteOption(s$, SO_OVAL | SO_CHECKCOLLIDE | SO_PIXELCHECK | SO_BORDER | SO_KINETIC);

// Make the balls collide and never go over another.
SetSpriteCollide(s$, "BALL");
SetSpriteId(s$, "BALL");

repeat
MoveSprite(s$, random(g_width - 40), random(64));
ProcessSprites(1, 0);
until (Collide(s$, SpriteX(s$), SpriteY(s$), nx$, ny$) == NULL);

// Set ball elasticity.
SetSpriteElasticity(s$, 0.01);

// Set some friction when the balls collide.
SetSpriteFriction(s$, 0.01);

// Set sprite's weight.
SetSpriteMass(s$, 0.5);

// Set the maximum velocity to 10 pixels.
SetSpriteVelLimits(s$, 0, 10);

i$++;
end;

Share and Enjoy:
  • del.icio.us
  • StumbleUpon
  • Digg
  • Sphinn
  • Facebook
  • Mixx
  • Reddit
  • Technorati
  • IndianPad
  • YahooMyWeb

Tutorial 40 - Form Options Quick Reference

Written By Akki

Tutorial 40 - Form Options Quick Reference

Form Options Quick Reference (by Brad Manske)

Each of the options are listed below along with the effect that it has on the form.

Dialog Form
Default: Off
When selected, the form will be created using a call to NewDlg to create the window. If not selected, then NewForm will be used to create the window if it is full screen, DefaultForm is selected in styles and there are no extended styles. If these conditions are not met, then the NewFormEx function will be used to create the window.

Generate Library
Default: Off
When selected, the form will create PPL source code that can be included in with a larger project. If not selected, the form will have a WinMain function indicating the entry point for the project. It is possible to create a stand alone program in a single form file with this option deselected.

Simplified Event Handling
Default: On
When selected, PPL will route the windows messages to the correct handler functions. If not selected, then the more traditional case table type logic is needed to decode and process the messages sent to the handler functions.

Extended Event Code
Default: On
When selected, PPL will include code in the Simplified Event Handlers to do some of the more
common decoding of the windows messages. If not selected, the code will be left off. To find the included code look in SWAPI.PPL for the #define for HandleEventParms.

Use Namespace
Default: On
When selected, the form will include the #NameSpace command in the generated PPL code. This will force global variables and controls into their own namespace to avoid items named the same on multiple forms. If not selected, then all global variables and controls will be placed into the global NameSpace.

Share and Enjoy:
  • del.icio.us
  • StumbleUpon
  • Digg
  • Sphinn
  • Facebook
  • Mixx
  • Reddit
  • Technorati
  • IndianPad
  • YahooMyWeb

Tutorial 39 - PPL Assembler

Written By Akki

Tutorial 39 - PPL Assembler

PASM from the Beginning (by Brad Manske)

"PASM can wait till after 1.0" was my reaction when I heard the plans to include a cross platform assembler with PPL. While it was not a lot of code, the complexity was way up there. So that it could run on multiple processors it had to be a virtual processor that was compiled to. There were 36 addressing modes for 22 assembly instructions that would potentially compile to a series of instructions for 2 different processors. The project required complex and intimate knowledge of the processors and the testing challenge was not going to be easy.

My earliest e-mail on this project (that I kept) is dated the 20th of March 2004. We had already worked together for almost 2 years when the topic came up. There is no backing down from a complex technical challenge, so even though the pressure to release 1.0 was high, PASM went forward. This article will introduce you to PASM and it just may be the raw speed boost your code needs. I will start off with some explanation for the people who have not had much exposure to assembly language. Assembly is a text representation of the 1s and 0s that the computer actually executes. For example:

X$ = 10;

This would be an instruction to move the value 10 into the variable X$:

move x, 10

Sound simple? Well, yes, if the processor supports moving a value into memory without going through a register first. And if the value fits in a 32 bit register (Windows CE requires a 32 bit processor). And, etc...

This is the reason that PASM uses a virtual processor internally. We couldn't guarantee that these conditions would be met for each processor since all of the code written for PASM must run on all of our supported platforms.

The PASM virtual processor is made up of 4 general purpose registers named R0, R1, R2 and R3. There are more specialized registers like the Stack Pointer (SP) and the Stack Frame (SF). The Arithmetic and Logic unit of our processor is a simplified RISC (Reduced Instruction Set Computing) like design. The instruction set consists of about 22 different assembly operations. This isn't much compared to the hundreds of instructions supported by some processors, but there are 36 addressing modes to offset the simplicity of the instruction set.Here is a quick look at the MOV instruction and the addressing modes that it supports. For 32 bit values:

mov Register, Value move from Value to Register
mov Absolute, Value move from Value to Absolute address
mov [Register], Value move from Value to Indexed Register
mov [Absolute], Value move from Value to Indexed Absolute address
mov Register, Register move from Register to Register
mov Register, [Register] move from Indexed Register to Register
mov [Register], Register move from Register to Indexed Register
mov [Register], [Register] move from Indexed Register to Indexed Register
mov Absolute, Register move from Register to Absolute address
mov [Absolute], Register move from Register to Indexed Absolute address
mov Register, [Register+offset] move from Index+Offset Register to Register
mov [Register+offset], Register move from Register to Index+Offset Register
mov [Register+offset], [Register+offset] move from Index+Offset Register to Index+Offset Register
mov Absolute+offset, Register move from Register to Absolute+Offset address
mov Absolute+offset, Value move from Value to Absolute+Offset address
mov [Absolute+offset], Register move from Register to Index+Offset Absolute address
mov [Absolute+offset], Value move from Value to Index+Offset Absolute address
mov [Register+offset], Value move from Value to Index+Offset Register

MOV also supports a size modifier for 8 bits (byte) and 16 bit (word) values:

mov size Register, Register move size from Register to Register
mov size Register, [Register] move size from Indexed Register to Register
mov size [Register], Register move size from Register to Indexed Register
mov size [Register], [Register] move size from Indexed Register to Indexed Register
mov size Absolute, Register move size from Register to Absolute address
mov size Absolute, Value move size from Value to Absolute address
mov size [Absolute], Register move size from Register to Indexed Absolute address
mov size [Absolute], Value move size from Value to Indexed Absolute address
mov size Register, Value move size from Value to Register
mov size [Register], Value move size from Value to Indexed Register
mov size Register, [Register+offset] move size from Index+Offset Register to Register
mov size [Register+offset], Register move size from Register to Index+Offset Register
mov size [Register+offset], [Register+offset] move size from Index+Offset Register to Index+Offset Register
mov size Absolute+offset, Register move size from Register to Absolute+Offset address
mov size Absolute+offset, Value move size from Value to Absolute+Offset address
mov size [Absolute+offset], Register move size from Register to Index+Offset Absolute address
mov size [Absolute+offset], Value move size from Value to Index+Offset Absolute address
mov size [Register+offset], Value move size from Value to Index+Offset Register

A few quick note about the notation above. The brackets [] above mean that the value of the expression inside the brackets is the memory location that will be operated on. Register is a register R0 to R3 or one of the special registers. Absolute, is a number representing a specific memory location. Offset an integer value that allows you to adjust the value of the memory address operated on without the need to modify the base.
Here is a very simple example:

#include "console.ppl"

func WinMain;
InitConsole;
ShowConsole;

new(startVal$, tint);
new(endVal$, tint);

StartVal$ = 0;
EndVal$ = 0;

asmCall$ = asm(1024, );

callasm(asmCall$, 20, 30);

writeln("Test "+ startVal$ + ", "+ endVal$);

freeasm(asmCall$);

free(startVal$, endVal$);

return(true);
end;


If you read my previous articles, you know that I'm a fan of using the console for my examples, so it should be no surprise that I first include the console. Next I declare some variables in the PPL memory space outside of PASM. Next is the assembly code followed by the CallASM instruction. Some values are written and the assembly code and variables are freed. When compiled, the call to ASM takes 2 arguments the first being the size of the byte buffer that holds the assembled code and the second is the string of assembly instructions. The buffer is specified in bytes and a multiplier is used on the buffer size depending on what you are doing.

For example, by running your code under debug, it is possible to step through and break on assembly instructions. In order to do this, extra machine code instructions are inserted to support doing this so the buffer must be expanded. It also means that your code will execute slower under debug than it will in run mode. The buffer is created at run time and the assembler runs against the 2nd argument which is the text with all of the assembly instructions. So keep in mind that if you make a change to the assembly code, any errors will not be found until run time. It also means if you plan on using the assembler you may want
to place your ASM instructions at startup and keep them for the duration of the program so that the code is not reassembled during the execution of your program when you really need the speed.

The CallASM instruction invokes the code created in the buffer by the ASM command. CallASM can take additional arguments that will be passed into the assembly code as parameters. The parameters are placed into an AARGS$ array and the size of the array is placed into AARGSCOUNT$. Each of the parameters are treated as a 4 byte (32 bit) value. So the value of 20 is at [AARGS$] and the value of 30 is at [AARGS$+4].

The line ":main" above indicates the entry point to your assembly code. This is a label and is used as the target in jump instructions. The line "#DEASM" above instructs the ASM instruction place the actual assembly instruction for your processor to be placed into the DebugLog file. This does take extra time, so it shouldn't be used in production programs. The #debugoff pragma can be used to disable this for the entire project. Here is a simple example when using #DEASM. The 2 lines from above:

mov StartVal$, 1
mov EndVal$, 2

On Intel processors are translated into:

mov edi, D45B28h(STARTVAL$)
mov [edi], 01h
mov edi, D45B98h(ENDVAL$)
mov [edi], 02h


On Arm processors are translated into:

ldr r9, 34C9B0h(STARTVAL$)
ldr r10, #01h
str r10, [r9]
str r10, #01h
ldr r9, 34CA40h(ENDVAL$)
ldr r10, #02h
str r10, [r9]
str r10, #02h

The lines from the PASM example above:

savesp
pplpush [AARGSCOUNT$]
ppl showmessage


Show an example of saving the position on the stack pushing some arguments onto the stack where ppl can get to it then calling a PPL function. Here is another example:

savesp
pplpushstr tstStr1$
pplpushstr tstStr2$
pplpushstr tstStr3$
ppl concat
pplpull


In this example, the stack pointer is saved, all of the required arguments are placed onto the stack and the PPL concat function is called to concatenate the strings together. The stack is restored to its previous state after the PPL call, then the address of the new string is pulled from the stack. The new string is created in a new memory space that the garbage collector will automatically clean up from. I'll leave you with one more example. This example demonstrates the usage of Jump instructions and the use of an assembly procedure. The entry point is at ":main". It tests the number of arguments passed into the assembly code to see if there is only one. In this case there is only one so the value of 20 is passed to the function "!asmCalc". As in high level code, the string in parenthesis becomes a variable for the function. The "Var FinSum" instructions declares a local var for use within the function. The function then calculates the Fibonacci series on the number passed to it adding all of the numbers from n + (n-1) + ... + 2 + 1.

#include "console.ppl"

func WinMain;
InitConsole;
ShowConsole;

new(startVal$, tint);
new(endVal$, tint);

asmFib$ = asm(1024, );

t$ = tick;

callasm(asmFib$, 20);

writeln("Fibbon("+ startVal$ + ")="+ endVal$ + " time =" + (tick - t$));

freeasm(asmFib$);

free(startVal$, endVal$);

return(true);
end;


Play with PASM a while and let us know what you think in the Forums. In the next newsletter, I will address some more advanced examples.

Share and Enjoy:
  • del.icio.us
  • StumbleUpon
  • Digg
  • Sphinn
  • Facebook
  • Mixx
  • Reddit
  • Technorati
  • IndianPad
  • YahooMyWeb

Tutorial 38 - Encryption strings easily.

Written By Akki

Tutorial 38 - Encryption strings easily.

Encrypting strings in PPL.

What if you want to protect a file from sneaky eyes? The best solution is to encrypt the file using a very strong password that only you know about. PPL comes with a nice function called Encrypt() that can do this for you very easily.

s$ = "HELLO WORLD!";
Encrypt(s$, -1, "MYKEY", True);
ShowMessage(s$);
Encrypt(s$, -1, "MYKEY", False);
ShowMessage(s$);

In the following example we encrypt the string “HELLO WORLD!” using an encryption algorythm that uses the key “MYKEY” to encode the result string. The last parameter of the Encryt() function specify if we are encrypting or decrypting the string, true means encryt and false means decrypt. It is always a good idea idea never to leave a key as a regular string in your code even though the .ppc file that PPL generates is encrypted and compressed, it can be easier for a hacker to decode. Try to build your key string using code with mathematical code if possible.

Share and Enjoy:
  • del.icio.us
  • StumbleUpon
  • Digg
  • Sphinn
  • Facebook
  • Mixx
  • Reddit
  • Technorati
  • IndianPad
  • YahooMyWeb

Tutorial 37 - Compressing strings in PPL.

Written By Akki

Tutorial 37 - Compressing strings in PPL.

Compressing strings.

The Pro version of PPL comes fully loaded with different compression and decompression methods from two simple functions: Compress() and UnCompress(). Here are the different compression methods supported by PPL:

_RLE

RLE, or Run Length Encoding, is a very simple method for lossless compression. It simply replaces repeated bytes with a short description of which byte to repeat, and how many times to repeat it.

Though simple and obviously very inefficient fore general purpose compression, it can be very useful at times (it is used in JPEG compression, for instance).

_HUFFMAN

Huffman encoding is one of the best methods for lossless compression. It replaces each symbol with an alternate binary representation, whose length is determined by the frequency of the particular symbol.

Common symbols are represented by few bits, while uncommon symbols are represented by many bits.

The Huffman algorithm is optimal in the sense that changing any of the binary codings of any of the symbols will result in a less compact representation. However, it does not deal with the ordering or repetition of symbols or sequences of symbols.

_LZ

There are many different variants of the Lempel-Ziv compression scheme. The Basic Compression Library has a fairly straight forward implementation of the LZ77 algorithm (Lempel-Ziv, 1977) that performs very well, while the source code should be quite easy to follow. The LZ coder can be used for general purpose compression, and performs exceptionally well for compressing text. It can also be used in combination with the provided RLE and Huffman coders (in the order: RLE, LZ, Huffman) to gain some extra compression in most situations.

Lets take the following code:

in$ = LoadStr(AppPath$+ “MyFile.txt”, insize$);
New(out$, insize$ * 2);
outsize$ = Compress(_RLE, in$, out$, insize$);


This code will load file MyFile.txt into variable in$, return the size in bytes in variable insize$. We then need to create an output buffer that is at least equal or preferably greater that the original input buffer. We then apply the RLE compression method to in$ and outputting the result in the out$ variable returning the new size of the out$ variable in outsize$.

You can then decompress the out$ buffer to a new newin$ buffer with the following:

New(newin$, outsize$ * 2);
newinsize$ = Compress(_RLE, out$, newinsize$, outsize$);

Share and Enjoy:
  • del.icio.us
  • StumbleUpon
  • Digg
  • Sphinn
  • Facebook
  • Mixx
  • Reddit
  • Technorati
  • IndianPad
  • YahooMyWeb

Tutorial 36 - Regular Expressions in PPL

Written By Akki

Tutorial 36 - Regular Expressions in PPL

Regular Expressions (Regex):

From www.regular-expressions.info:

“A regular expression (regex or regexp for short) is a special text string for describing a search pattern. You can think of regular expressions as wildcards on steroids. You are probably familiar with wildcard notations such as *.txt to find all text files in a file manager. The regex equivalent is .*\.txt . But you can do much more with regular expressions. In a text editor like EditPad Pro or a specialized text processing tool like PowerGREP, you could use the regular expression \b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]\b to search for an email address. Any email address, to be exact. A very similar regular expression (replace the first \b with ^ and the last one with $) can be used by a programmer to check if the user entered a properly formatted email address. In just one line of code, whether that code is written in Perl, PHP, Java, a .NET language or a multitude of other languages.”

PPL supports a variety of expressions like:

\Quote the next metacharacter
^ Match the beginning of the string
. Match any character
$ Match the end of the string
| Alternation
() Grouping (creates a capture)
[] Character class

==GREEDY CLOSURES==

* Match 0 or more times
+ Match 1 or more times
? Match 1 or 0 times
Match at least n times
Match at least n but not more than m times

==ESCAPE CHARACTERS==

\t tab (HT, TAB)
\n newline (LF, NL)
\r return (CR)
\f form feed (FF)

==PREDEFINED CLASSES==

\l lowercase next char
\u uppercase next char
\a letters
\A non letters
\w alphanimeric [0-9a-zA-Z]
\W non alphanimeric
\s space
\S non space
\d digits
\D non nondigits
\x exadecimal digits
\X non exadecimal digits
\c control charactrs
\C non control charactrs
\p punctation
\P non punctation

To search a string using regular expression in PPL you will use the Search() function. You can also make sure that the string is an exact match of the regular expression you are providing with the Match() function.

Let's take the following example:

string$ = "Bill Clinton";
expr$ = "^(Bill|George|Renald) (Clinton|Bush|Reagan)$";
Search(expr$, string$, b$, e$);
ShowMessage(b$ + "," + e$);

The expr$ variable contains an expression that says, if the first word is either Bill, George or Renald and that the string ends with Clinton, Bush or Reagan, we have a match. “Bill Clinton” will be the beginning of our result string, b$ and “” will be our ending string e$.

i$ = 0;
while(i$ <= subexpcount - 1)
subexp(string$, i$, begin$, len$);
ShowMessage("SubExp " + i$ + " = " + begin$ + "," + len$);
i$++;
end;

In the previous example, we check each sub expression to see what matched in the string string$ and where it started and how many characters the sub expression took from string$.
Sub expression 0 will return “Bill Clinton” for a length of 12 because it do the whole expression. Sub expression 1 will return “Bill Clinton” but for 4 characters only, the first sub expression “^(Bill|George|Renald)” is analyzed. Sub expression 2 will return “Clinton” for 7 characters, the second sub expression “(Clinton|Bush|Reagan)$” is analyzed.

Share and Enjoy:
  • del.icio.us
  • StumbleUpon
  • Digg
  • Sphinn
  • Facebook
  • Mixx
  • Reddit
  • Technorati
  • IndianPad
  • YahooMyWeb
Written By Akki

Tutorial 36 - Regular Expressions in PPL

Regular Expressions (Regex):

From www.regular-expressions.info:

“A regular expression (regex or regexp for short) is a special text string for describing a search pattern. You can think of regular expressions as wildcards on steroids. You are probably familiar with wildcard notations such as *.txt to find all text files in a file manager. The regex equivalent is .*\.txt . But you can do much more with regular expressions. In a text editor like EditPad Pro or a specialized text processing tool like PowerGREP, you could use the regular expression \b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]\b to search for an email address. Any email address, to be exact. A very similar regular expression (replace the first \b with ^ and the last one with $) can be used by a programmer to check if the user entered a properly formatted email address. In just one line of code, whether that code is written in Perl, PHP, Java, a .NET language or a multitude of other languages.”

PPL supports a variety of expressions like:

\Quote the next metacharacter
^ Match the beginning of the string
. Match any character
$ Match the end of the string
| Alternation
() Grouping (creates a capture)
[] Character class

==GREEDY CLOSURES==

* Match 0 or more times
+ Match 1 or more times
? Match 1 or 0 times
Match at least n times
Match at least n but not more than m times

==ESCAPE CHARACTERS==

\t tab (HT, TAB)
\n newline (LF, NL)
\r return (CR)
\f form feed (FF)

==PREDEFINED CLASSES==

\l lowercase next char
\u uppercase next char
\a letters
\A non letters
\w alphanimeric [0-9a-zA-Z]
\W non alphanimeric
\s space
\S non space
\d digits
\D non nondigits
\x exadecimal digits
\X non exadecimal digits
\c control charactrs
\C non control charactrs
\p punctation
\P non punctation

To search a string using regular expression in PPL you will use the Search() function. You can also make sure that the string is an exact match of the regular expression you are providing with the Match() function.

Let's take the following example:

string$ = "Bill Clinton";
expr$ = "^(Bill|George|Renald) (Clinton|Bush|Reagan)$";
Search(expr$, string$, b$, e$);
ShowMessage(b$ + "," + e$);

The expr$ variable contains an expression that says, if the first word is either Bill, George or Renald and that the string ends with Clinton, Bush or Reagan, we have a match. “Bill Clinton” will be the beginning of our result string, b$ and “” will be our ending string e$.

i$ = 0;
while(i$ <= subexpcount - 1)
subexp(string$, i$, begin$, len$);
ShowMessage("SubExp " + i$ + " = " + begin$ + "," + len$);
i$++;
end;

In the previous example, we check each sub expression to see what matched in the string string$ and where it started and how many characters the sub expression took from string$.
Sub expression 0 will return “Bill Clinton” for a length of 12 because it do the whole expression. Sub expression 1 will return “Bill Clinton” but for 4 characters only, the first sub expression “^(Bill|George|Renald)” is analyzed. Sub expression 2 will return “Clinton” for 7 characters, the second sub expression “(Clinton|Bush|Reagan)$” is analyzed.

Share and Enjoy:
  • del.icio.us
  • StumbleUpon
  • Digg
  • Sphinn
  • Facebook
  • Mixx
  • Reddit
  • Technorati
  • IndianPad
  • YahooMyWeb

Tutorial 35 - Structures in Linked-Lists

Written By Akki

Tutorial 35 - Structures in Linked-Lists

Structures in Linked-Lists

Linked-lists are very powerful and can allow for very complicated data storage. Now let's see how it possible to store a different structure type inside each list node.First we need to create our list node:

List(l$);
Add(l$);

We now have one list node in l$ and our current internal pointer is placed on that first node.

We can now define the variable type like we would with any other variable:

struct(l$, “a”, “b”);
l.a$ = 10;
l.b$ = 20;

We can now add a new node and store another structure into it:

Add(l$);
struct(l$, “c”, “d”);
l.c$ = 30;
l.d$ = 40;

Now let's iterate through the list and output the structure's element values:

ForEach(l$)
if (Lpos(l$) == 0)
ShowMessage(l.a$);
ShowMessage(l.b$);
else if (Lpos(l$) == 1)
ShowMessage(l.c$);
ShowMessage(l.d$);
end;
end;


The Lpos() function returns the current pointer position of the list always starting with 0.

Imagine the possibilities offered by such flexibility.

Share and Enjoy:
  • del.icio.us
  • StumbleUpon
  • Digg
  • Sphinn
  • Facebook
  • Mixx
  • Reddit
  • Technorati
  • IndianPad
  • YahooMyWeb

Tutorial 34 - Linked-lists

Written By Akki

Tutorial 34 - Linked-lists

Linked-Lists

Finally a chance to talk about the linked-lists. You have probably heard or learnt about them in school while studying C or maybe you've read about them on the internet or a magazine.

Here is a great explanation from the great wikipedia.com:

“In computer science, a linked list is one of the fundamental data structures used in computer programming. It consists of a sequence of nodes, each containing arbitrary data fields and one or two references ("links") pointing to the next and/or previous nodes. A linked list is a self-referential datatype because it contains a pointer or link to another data of the same type. Linked lists permit insertion and removal of nodes at any point in the list in constant time, but do not allow random access.”

In PPL linked-lists variables are extremely powerful and versatile. In each node you can have a different type of variable, structures or arrays. This opens up unlimited data storage in memory that is simply unmatched.

To create a list variable, there many ways, here is how you declare a list variable and how you add nodes to it:

List(l$);
Add(l$, 1, 2, 3, 4, 5);
Add(l$, “A”, “B”, “C”, “D”);


This new linked-list variable now contains 9 nodes with different values and types. Let's see how you can move through the nodes like other languages would allow you to:

First(l$);
while (1 == 1)
ShowMessage(l$);
if (Next(l$) == false)
break;
end;
end;

Here is how we iterate through the list in reverse order:

Last(l$);
while (1 == 1)
ShowMessage(l$);
if (Prev(l$) == false)
break;
end;
end;

The First() function moves the list internal pointer to the first node, Next() moves to the next node returning true if succeeded or false is past the end of the node list. The Last() function moves the internal list pointer to the last node in the list and the Prev() function moves to the previous node.

In PPL you can use the ForEach() statement to iterate through a list, an array, a structure or a matrix type variable:

ForEach(l$)
ShowMessage(l$);
end;

ForEachRev(l$)
ShowMessage(l$);
end;

If you need to store the list node value into another variable, you can place a second variable as a target in the ForEach() statement:

ForEach(l$, v$)
ShowMessage(v$);
end;

Let's see how PPL can access nodes at random order, PPL can access list's nodes just like regular arrays:

ShowMessage(l$[0]); // display 1
ShowMessage(l$[5]); // display A

How do we go to a specific node position? Simple, by using the Goto() function. How do we know what node is the current one? Use the Lpos() function. How many nodes are in the list? Use the Count() function.

Goto(l$, 0); // Like First()
ShowMessage(LPos(l$));
Goto(l$, Count(l$)-1); // Like Last()
ShowMessage(LPos(l$));

We can also move nodes around using the Lmove() function:

Lmove(l$, 3, 1); // This moves node 3 to node 1.

You can also insert nodes using the Ins() function:

Ins(l$, 0, 0); // Insert value 0 at node 0.

To delete a node from the list, you can use the Del() function, if you want to empty the whole list, just use Empty().

First(l$); // Move to first node.
Del(l$); // Deletes first node.
Goto(l$, 5); // Goto 5th node.
Del(l$); // Deletes 5th node.
Empty(l$); // Empty the whole list of all of its nodes.

In the next tutorial we will see how you can store different variable types like arrays and structures inside a list node.

Share and Enjoy:
  • del.icio.us
  • StumbleUpon
  • Digg
  • Sphinn
  • Facebook
  • Mixx
  • Reddit
  • Technorati
  • IndianPad
  • YahooMyWeb