Thursday, April 13, 2017

A Simple Scroll Function


Imagine you want to display a long list of items but you have a limited area to show them on screen. In that case, you have to resort to using scroll.  Let me explain in pseudo-code one way of doing it.

Length is a function that gives the number of items contained in an array of items.
In our example DisplayLength will tell us how many items will be shown on screen. Here, we have set its value to two.

DisplayLength = 2;

Index will be the variable that holds the pointer of the current item on the list. At the beginning, it will point to the first item on the list. Hence index=0;
(Note: Computer scientists always like to start counting at 0)

Index = 0; 

Scroll_Limit will tell us how far we can keep scrolling. When Index = Scroll-Limit that means that we have reached the end of our scroll capabilities and that all items have been displayed to the user.
This is how to calculate it.

Scroll_Limit = Length (List A) - DisplayLength

In our example. Scroll_Limit = (6 - 2) = 4.

Here is our list: 

LIST A   (6 items)                DISPLAY (2 items)

aaaaa 0  -> index points to first item;
bbbbb 1
ccccc 2    
ddddd 3  
eeeee 4    
fffff 5

Imagine that you want to go forward in your list by pressing the arrow down button  (while index <= scroll_Limit). Remember that in this example, Scroll_Limit=4. This would be the result.

Now to go back, say, with the press of the up arrow key. You just have to decrease the value of index.
index-=1; Remember to set the limit at 0. Allow the key to be processed only if index>0;

Output:




Tuesday, January 3, 2017

Learning C++ - Credit Card Verification

Saturday, October 22, 2016

Text Editor - From Scratch

Another Freepascal project of mine.  A text editor for console/terminals. The text interface was done in the fashion of the old <edit.com> for MS-DOS.




The cursor, the text and keyboard input, the buffer and the menus are all done from scratch. It is far from being complete. If only it was Summer again - sigh.



Friday, September 23, 2016

Color Picker - High Color 16bits

A screenshot of a program that I made that generates a random palette and creates shades for the designated color in High Color. You can find the program in my github repository.
From Wikipedia:

High color supports 15/16-bit for three RGB  colors. In 16-bit direct color, there can be 4 bits (16 possible levels) for each of the R, G, and B components, plus optionally 4 bits for alpha (transparency), enabling 4,096 (16 × 16 × 16) different colors with 16 levels of transparency. Or in some systems there can be 5 bits per color component and 1 bit of alpha (32768 colors, just fully transparent or not); or there can be 5 bits for red, 6 bits for green, and 5 bits for blue, for 65536 colors with no transparency.


Saturday, September 10, 2016

[B4A] Android Widget APP - To-Do List

I've been working on a widget for Android systems to be used as a To-Do list.
The widget can be resized and the activity to write the items for the list is transparent.

Basic4Android doesn't come with a feature to make widgets resizable but after some reading and patience I figured out the work-around:
You have to modify the XML files in the /Objects/res/layout so that the Width and Height properties are equal to "match_parent" to stretch the labels, panel etc and then make the files read-only so that B4A doesn't overwrite them. The files in the Objects/res/drawable should be read-only too. Finally, in the Objects/res/xml folder edit the file and add the line: 
android:resizeMode="horizontal|vertical" and also android:minResizeWidth="110dp".

Also, to make an activity transparent add the following line to the manifest editor:  
SetApplicationAttribute(android:theme, "@android:style/Theme.Translucent")

>>>>>>>>>>>> Link to the Source code and APK
Screen Caps:

Tuesday, August 30, 2016

ASCII TABLE - Unit Video Freepascal - Utils

I have ported my libraries to make dynamic menus in freepascal to be compatible with the RTL units of Video and Keyboard - along with a new library to display windows and save the screen buffer under them. I may add mouse support in the future.

The source code can be found here.

Another future project of mine is to port my graphic libraries to SDL 2.0 to be more platform independent.

One example is this ASCII table program with retro look:


Friday, August 19, 2016

MBR HACK - MR. ROBOT


I have managed to alter the MBR of a USB pen drive so as to display the string 'MR.ROBOT' in graphics mode while booting and then continuing with the pre-installed Linux Distro (Kali Linux) after waiting for a keypress.

Graph. Mode: (AL= 0Dh 320x200 16 colors)

MBR Dump:
Code highlighted in red is 62 bytes total.

8C C8 8E D8 8E C0 BD 4C 7D FF E5 33 ED 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 33 ED FA 8E D5 BC 00 7C FB FC 66 31 DB 66 31 C9 66 53 66 51 06 57 8E DD 8E C5 52 BE 00 7C BF 00 06 B9 00 01 F3 A5 EA 4B 06 00 00 52 B4 41 BB AA 55 31 C9 30 F6 F9 CD 13 72 16 81 FB 55 AA 75 10 83 E1 01 74 0B 66 C7 06 F1 06 B4 42 EB 15 EB 00 5A 51 B4 08 CD 13 83 E1 3F 5B 51 0F B6 C6 40 50 F7 E1 53 52 50 BB 00 7C B9 04 00 66 A1 B0 07 E8 44 00 0F 82 80 00 66 40 80 C7 02 E2 F2 66 81 3E 40 7C FB C0 78 70 75 09 FA BC EC 7B EA 44 7C 00 00 E8 83 00 4D 52 2E 52 4F 42 4F 54 20 20 20 20 20 6D 69 73 73 69 6E 67 20 6F 72 20 63 6F 72 72 75 70 74 2E 0D 0A 66 60 66 31 D2 66 03 06 F8 7B 66 13 16 FC 7B 66 52 66 50 06 53 6A 01 6A 10 89 E6 66 F7 36 E8 7B C0 E4 06 88 E1 88 C5 92 F6 36 EE 7B 88 C6 08 E1 41 B8 01 02 8A 16 F2 7B CD 13 8D 64 10 66 61 C3 E8 1E 00 4F 70 65 72 61 74 69 6E 67 20 73 79 73 74 65 6D 20 6C 6F 61 64 20 65 72 72 6F 72 2E 0D 0A 5E AC B4 0E 8A 3E 62 04 B3 07 CD 10 3C 0A 75 F1 CD 18 F4 EB FD B0 0D CD 10 B4 13 B0 01 B3 04 B9 08 00 B7 00 BD B4 7C 89 D6 B6 09 B2 10 CD 10 89 F2 30 E4 CD 16 8C C8 8E D8 8E C0 BD 0B 7C FF E5 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 BC B9 02 00 00 00 00 00 05 FF 7C 1E 00 00 80 02 01 00 17 3F E0 B0 40 00 00 00 C0 87 1D 00 00 00 C1 B1 01 3F E0 FF 00 88 1D 00 00 A5 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 AA

Output and Ascii View:                                                                                                                                                                         



Analysis:

 8C C8 8E D8 8E C0 BD 4C 7D FF E5  : Jump forward to where the code is stored (7d4f)

[Start at OFFSET 7c00] [Linux boot starts at OFFSET 7c0b]
11 bytes
                mov ax, cs            ; Where are we now?  
                                      ; Could be 0000:7c00 
                                      ; or 07c0:0000 or some other combo.
                mov ds, ax            ; Our data is here too.
                mov es, ax            ; ES:BP is the pointer to the string. 
                                      ; ES should match DS and CS.
                mov bp, 7d4f          ; Offset of our code
                jmp bp                ; Go to offset

4D 52 2E 52 4F 42 4F  : String 

[String stored at OFFSET 7cb4]
8 bytes               
                DB 'MR.ROBOT'

B0 0D CD 10 B4 13 B0 01 B3 04 B9 08 00 B7 00 BD B4 7C 89 D6 B6 09 B2 10 CD 10 89 F2 30 E4 CD 16 8C C8 8E D8 8E C0 BD 0B 7C FF E5 : Change to graph mode + Draw string on screen  + Wait for keypress + Jump backwards to 7c0b

[Code stored at OFFSET 7d4f]
43 bytes

                mov al,0d
               ; Select graph mode 320x200 16 colours
                int 10h                 ; Bios call
                mov ah,13               ; Write string function
                mov al,1                ; Write mode
                mov bl,4                ; Color red
                mov cx,8                ; String lenth. No. of bytes=8
                mov bh,0                ; Page number =0
                mov bp,7cb4             ; Point to where the string is located.
                mov si, dx              ; Temporarily store value of DX 
                                        ; to retrieve later otherwise boot will freeze.
                mov dh,9                ; Row to place the string = 9
                mov dl,10               ; Column to place the string = 10
                int 10h                 ; Bios call 
                mov dx,si               ; Recover value of DX
                xor ah,ah               ; Wait for keypress
                int 16h                 ; Keyboard interrupt
                mov ax, cs              ; Where are we now?  
                mov ds, ax              ; Our data is here too.
                mov es, ax              ; ES:BP is the pointer to the string.  
                                        ; ES should match DS and CS.
                mov bp, 7c0b            ; Offset to go back
                jmp bp                  ; Go to offset and resume linux bootload