Me (Stanislav Stankov) growing up

Assembler snake

Compiler used: http://www.emu8086.com/

Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
name "snake"

; създай snake.com
org     100h;

jmp     start

; ------ константи ------
; клавишни кодове на bios
KEY_LEFT        equ 4bh
KEY_RIGHT   equ 4dh
KEY_UP          equ 48h
KEY_DOWN    equ 50h
KEY_ESC     equ 1bh
KEY_SPC     equ 39h

; константи отнасящи се до змията
SNAKE_BODY_COLOR    equ 0eh
SNAKE_BODY_CHAR equ '*'
SNAKE_BODY_SIZE     equ 7

; координати на змията, посока от главата към опашката
snake dw SNAKE_BODY_SIZE dup(0)

; последен елемент от змията
tail        dw ?

; накъде е насочена змията при начално стартиране
cur_dir db KEY_RIGHT

wait_time   dw 0

; начално съощение към потребителя, първият ред е празен, защото през него минава змията
; $ се обозначава края на съобщението
msg db "======================", 0dh, 0ah
        db "=========Snake=========", 0dh, 0ah
        db "    Правила на играта:", 0dх, 0ah
        db "    Змията се управлява от клавишите за посока", 0dh, 0ah
        db "    ESC спира играта", 0dh, 0ah
        db "======================", 0dh, 0ah
        db "======================$", 0dh, 0ah


; ------ КОД ------

start:
; Изписване на начално съощение с координати (DS:DX)
mov     dx, offset msg
mov     ah, 9
int         21h


; скриване на курсора
mov     ah, 1
mov     ch, 2bh
mov     cl, 0bh
int         10h


game_loop:
        ; Избиране на страница, VIDEO MODE
        mov     al, 00h
        mov     ah, 05h
        int         10h
       
        ; хващане на новата глава на змията
        mov     dx, snake[0]
       
        ; преместване на курсора на позиция (dl, dh);
        ; DH - red
        ; DL - kolona
        mov     ah, 02h
        int         10h
       
        ; Принтиране върху екрана на SNAKE_BODY_CHAR, на позицията на курсора:
        ; AL - char - a, знака който ще отпечатва
        ; BL - cvqt
        ; CX - колко пъти да повтори знака
        mov     al, SNAKE_BODY_CHAR
        mov     ah, 09h
        mov     bl, SNAKE_BODY_COLOR
        mov     cx, 1
        int         10h
       
        ; хващаме опашката
        mov     ax, snake[SNAKE_BODY_SIZE * 2 - 2]
        mov     tail, ax
       
        ; извикване на процедурата move_snake
        call        move_snake
       
        ; премества курсора на позиция (dl, dh) -> позицията на опашката (tail)
        ; DH - red
        ; DL - kolona
        mov     ah, 02h
        mov     dx, tail
        int         10h
       
        ; слага ' ' на позицията на курсора (сриваме старата опашка)
        ; DH - red
        ; DL - kolona
        mov     al, ' '
        mov     ah, 09h
        mov     cx, 1
        int         10h
   
    check_for_key:
        ; проверява дали има клавишен код в буфера на клавиетурата
        mov     ah, 01h
        int         16h
       
        jz      no_key
       
        ; приверява дали е натиснат клавиетурен клавиш
        ; AH - BIOS kod
        ; AL - ASCII char
        mov     ah, 00h
        int         16h
       
        ; проверява дали последно хванатия клавиш е бил ESC, ако да, се препраща към stop_game
        cmp     al, KEY_ESC
        je          stop_game
       
        ; хваща се последният натиснат клавиш, като посока
        mov     cur_dir, ah
   
    no_key:
        ; ако няма хванат клавиш изчаква малко време преди да провери отново
       
        mov     ah, 00h
        int         1ah
       
        cmp     dx, wait_time
        jb          check_for_key
       
        add     dx, 4
        mov     wait_time, dx

; вечен интервал
jmp     game_loop

stop_game:
    ; показва курсора черен
    mov     ah, 1
    mov     ch, 0bh
    mov     cl, 0bh
    int         10h
   
ret

; --------------------
; Процедури
; --------------------

; move_snake, създава анимация, като премества
; всяка част от тялото на змията една позиция напред,
; като изтрива опашката после <- това става в главната програма.
; Идеята е последната част се изтрива, а другите части се преместват:
; част0[ i ] -> част[ i + 1 ]
move_snake proc near
    mov     ax, 40h
    mov     es, ax
   
    ; DI, взема позицията на опашката
    mov     di, SNAKE_BODY_SIZE * 2 - 2
   
    ; премества всички части на змията
    mov     cx, SNAKE_BODY_SIZE - 1
    move_array:
        mov     ax, snake[di - 2]
        mov     snake[di], ax
        sub     di, 2
       
    ; върти докато di = 0
    loop  move_array
   
    cmp cur_dir, KEY_LEFT
        je      move_left
       
    cmp cur_dir, KEY_RIGHT
        je      move_right
   
    cmp cur_dir, KEY_UP
        je      move_up
   
    cmp cur_dir, KEY_DOWN
        je      move_down
   
    jmp     end_move
   
    move_left:
        mov     al, b.snake[0]
        dec     al
        mov     b.snake[0], al
        cmp     al, -1
            jne     end_move
        mov     al, es:[4ah]
        dec     al
        mov     b.snake[0], al
        jmp     end_move
   
    move_right:
        mov     al, b.snake[0]
        inc     al
        mov     b.snake[0], al
        cmp     al, es:[4ah]
            jb      end_move
        mov     b.snake[0], 0
        jmp     end_move
   
    move_up:
        mov     al, b.snake[1]
        dec     al
        mov     b.snake[1], al
        cmp     al, -1
            jne     end_move
        mov     al, es:[84h]
        mov     b.snake[1], al
        jmp     end_move
   
    move_down:
        mov     al, b.snake[1]
        inc     al
        mov     b.snake[1], al
        cmp     al, es:[84h]
            jbe     end_move
        mov     b.snake[1], 0
        jmp     end_move
   
    end_move:
ret

move_snake endp






snake example zip

thanks to : snake.asm
more code examples at : assembler source code

Time Display

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/**
 * Convert netStream.time (or seconds) into String format HH:MM:SS
 * @param   seconds
 * @return formated string HH:MM:SS
 */

public static function formatTime(time:Number):String {
    if (time < 0 || isNaN(time)) {
        return "00:00";
    }
   
    const hours:Number = Math.floor(time / 3600 % 24);
    const minutes:Number = Math.floor(time / 60 % 60);
    const seconds:Number = Math.floor(time % 60);
   
    const hString:String = hours < 10? "0" + hours: "" + hours;
    const mString:String = minutes < 10? "0" + minutes: "" + minutes;
    const sString:String = seconds < 10? "0" + seconds: "" + seconds;
   
    return hours > 0 ? hString + ":" + mString + ":" + sString : mString + ":" + sString;
}

Example:

1
2
3
4
5
6
7
8
trace(formatTime(103));
//01:43

trace(formatTime(3));
//00:03

trace(formatTime(3653));
//01:00:53

Email RegExp

Email check if is valid with regular expression.

1
2
3
4
var email_re:RegExp = /^\s*[\w\-\+_]+(\.[\w\-\+_]+)*\@[\w\-\+_]+\.[\w\-\+_]+(\.[\w\-\+_]+)*\s*$/;
if (!email_re.test(_email_ctti.text)) {
    //Missing field/Invalid email;
}

Post PHP vars without form

You have to have cURL enabled. Take a look

1
2
3
4
5
6
7
8
9
<?php
    $email = $_POST['email'];
   
    $ch = curl_init('http://www.aweber.com/scripts/addlead.pl');
    curl_setopt ($ch, CURLOPT_POST, 1);
    curl_setopt ($ch, CURLOPT_POSTFIELDS, "from=".$email."&name=somename&meta_web_form_id=1829234431&meta_split_id=&unit=rm101-sign-up&redirect=http://www.aweber.com/form/thankyou_vo.html&meta_redirect_onlist=&meta_adtracking=&meta_message=1&meta_required=from&meta_forward_vars=0");
    curl_exec ($ch);
    curl_close ($ch);
?>

Adobe Flash CS3 ACE Exam paper

So its little to late to show off, but just want to show you guys.
certified expert
Adobe Certified Expert in Flash CS 3

adobe flash cs3 ACE Exam

Flash video Player Snapshot

Hi I have recently working on saving different format images from flash. My previous work on this script was: Image Encode with Flash and PHP. Here you can create snapshots from video source.

Example

In this example you can save exported images also in your computer. I like this example more, because you can get different images, not boring same image again.

Screenshots:
snapshot file 1
snapshot file 2
snapshot file 3

Custom Flash Video Player

I created easy to functionality to extend player. Here is the link:
video player

You pass total of 4 flash variables:

1
2
3
4
5
var flashvars = {};
flashvars.videoURL = "running man.mp4";
flashvars.autoPlay = 0;
flashvars.isImage = 1;
flashvars.imageURL = "RunningMan.jpg";

I’m using swfobject ot embed it in page. So lets say little more about variables:
videoURL is link to video location;
autoPlay is flag, if = 1, then video will start automatically playing. If = 0, then will stay stopped until play button is clicked;
isImage is flag, if = 1, them you have to pass image location to imageURL variable, to be loaded.If = 0, then no image is loaded;
isImage is image location;

Note: autoPlay and isImage cannot be 1 at the same time! Player will throw error. Also please use 0 or 1 for flags, not false or true.

Image Encode with Flash and PHP

hi, this is a little project to save export/save images from flash.

This application allow you to see how to export in different image formats like: png, jpg and bmp.

I create class ImageCreator, whit it it’s this easy create images on server. You call the class like this:

1
2
var imagecreator:ImageCreator = new ImageCreator(image_spr, ImageCreator.EXPORT_TYPE_PNG, name);
imagecreator.addEventListener(ImageCreator.EVENT_COMPLETE_SAVING, completeWritingEvent);

Event ImageCreator.EVENT_COMPLETE_SAVING, will be dispatched when image is correctly saved on your server.
This is ImageCreator Class

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package com.stanislavstankov.images {
    import com.adobe.images.*;
    import flash.display.BitmapData;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.EventDispatcher;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.net.URLRequestMethod;
    import flash.net.URLVariables;
    import flash.utils.ByteArray;
   
    public final class ImageCreator extends EventDispatcher {
       
        public static const EVENT_COMPLETE_SAVING:String = "eventCompleteSaving";
       
        public static const EXPORT_TYPE_JPG:int = 0;
        public static const EXPORT_TYPE_PNG:int = 1;
        public static const EXPORT_TYPE_BMP:int = 2;
       
        private const _FOLDER_FILE:String = "http://projects.stanislavstankov.com/imageEncoder/php";
        private const _PHP_FILE:String = "/imgEncoder.php";
       
       
        private var _filename:String;
       
        /*------------------------------------
            Constructor
        ------------------------------------*/

        /**
         * ImageCreator will create image on the server where the php file is.
         * Event EVENT_COMPLETE_SAVING, will be dispatched when image is created on server.
         * Also there is one get propert filepath, that will return the path where the image is saved.
         * @param   Dispaly object - sprite or moviclip that will be exported for image
         * @param   type of image that will be saved
         * @param   name of the file
         * @param   background color if transperent, leave it 0. If you need background change the value. It is ARGB type.
         */

        public function ImageCreator($displayObjectExport_:Sprite, $exportType_:int, $name_:String, $fillColorARGB_:uint = 0x0):void {
            var transperentFlag:Boolean = false;
            if ($exportType_ == EXPORT_TYPE_PNG) {
                transperentFlag = true;
            }
           
            const bmpdata:BitmapData = new BitmapData($displayObjectExport_.width, $displayObjectExport_.height, transperentFlag, $fillColorARGB_);
            bmpdata.draw($displayObjectExport_);
           
            createImage(bmpdata, $exportType_, $name_);
        }
        /*------------------------------------
            Public methods
        ------------------------------------*/

       
        public function get filepath():String {
            return _filename;
        }
       
       
        /*------------------------------------
            Private methods
        ------------------------------------*/

       
        private function createImage($bmpdata_:BitmapData, $exportType_:int, $name_:String):void {
            var byteArray:ByteArray;
            var contentType:String;
           
            switch ($exportType_) {
                case EXPORT_TYPE_JPG:
                    var jpgencode:JPGEncoder = new JPGEncoder(100);
                    byteArray = jpgencode.encode($bmpdata_);
                    contentType = 'image/jpg';
                    $name_ += ".jpg";
                break;
                case EXPORT_TYPE_PNG:
                    byteArray = PNGEncoder.encode($bmpdata_);
                    contentType = 'image/png';
                    $name_ += ".png";
                break;
                case EXPORT_TYPE_BMP:
                    byteArray = BMPEncoder.encode($bmpdata_);
                    contentType = 'image/bmp';
                    $name_ += ".bmp";
                break;
                default:
               
                break;
            }
           
            const request:URLRequest = new URLRequest(_FOLDER_FILE + _PHP_FILE + "?name=" + $name_);
            request.contentType = contentType;
            request.method = URLRequestMethod.POST;
            request.data = byteArray;
           
            const loader:URLLoader = new URLLoader(request);
            loader.addEventListener(Event.COMPLETE, loadResultHandler);
        }
       
       
        /*------------------------------------
            Event Functions
        ------------------------------------*/

       
        private function loadResultHandler(info:Event):void {
            info.target.removeEventListener(Event.COMPLETE, loadResultHandler);
            var urlvars:URLVariables = new URLVariables(info.target.data);
            _filename = _FOLDER_FILE + "/" + urlvars.filename;
           
            dispatchEvent(new Event(EVENT_COMPLETE_SAVING));
        }
       
       
    }
}

PHP imgEncoder.php file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
if (isset($GLOBALS["HTTP_RAW_POST_DATA"])) {
    //$fullFilePath = dirname(__FILE__) . "/" . $_GET['name'];
    $fullFilePath = $_GET['name'];
   
    $handle = fopen($fullFilePath,"w");
    fwrite($handle, $GLOBALS["HTTP_RAW_POST_DATA"]);
    fclose($handle);
   
    echo "result=1&filename=" . $fullFilePath;
} else {
    echo 'result=0';
}
?>

Source file here

Edit 14.09.2009
Flash video Player Snapshot

Top 10 Free Resources for Background Patterns and Textures for Web Designers

Quite often we stumble on to a blog that looks bland, in dire need of some color, a little bit of character, these sites maybe aren’t very familiar with blog design, let alone CSS. The simplest way to freshen up a site is with a new theme or to do a little CSS tweaking with your current theme. You could be surprised with the results. In this article I will show you the best resources for backgrounds and textures.

go to full blog post

ActionScript 3. Resources

Hi here is resources of ActionScript 3 libraries.

From Adobe Labs

The Adobe Developer Rel

ations team is releasing a set of free and open ActionScript 3.0 APIs to help developers get started building Flex 2.0 applications. These libraries are of beta quality and we have released them as-is under this license. Adobe does not support them.

  1. corelib
  2. FlexUnit
  3. Flickr
  4. Mappr
  5. RSS and Atom libraries
  6. Odeo
  7. YouTube