Emuforums.com

Go Back   Emuforums.com > General Discussion > Web development / Programming
Home Register Downloads FAQ Members List Calendar Arcade Mark Forums Read

WON'T YOU JOIN US?
You are not a registered member and
are viewing this site as a guest.
Registration is simple and FREE.
Join this CrowdGather community today.
Registration offers the following perks:

» Less advertising throughout
» Post and participate in discussions
» Network with other forum members
» Free private messaging

join

Reply
 
Thread Tools Display Modes
Old February 19th, 2012, 08:41   #341
blueshogun96
Last Xbox Emu Author
 
blueshogun96's Avatar
 
Join Date: Jun 2004
Location: Seattle, WA, USA
Posts: 5,843
Quote:
Originally Posted by cottonvibes View Post
why would you use c++ features like templates, but still use ancient and unsafe c-strings instead of c++ strings ><
Depends on what you call safe. Call me old fashioned, but I see little benefit of using std::string over char*. I value minimal overhead and thread safety.
__________________

Official Website of Shogun3D's RyuAwai!

Shogun3D Game Development Blog

Zengjük a Dalt: Manliest Song Ever!
blueshogun96 is offline   Reply With Quote

Advertisement [Remove Advertisement]
Old February 19th, 2012, 10:34   #342
cottonvibes
You're already dead...
 
cottonvibes's Avatar
 
Join Date: Sep 2007
Location: Planet Vegeta
Posts: 5,385
c-strings are mostly unsafe for buffer overruns and needing to manage the memory yourself (leading to dangling pointers and other problems); in an attempt to make operations on them safer, there are functions like strcpy_s instead of the unsafe strcpy which you are repetitively using.

there are plenty of benefits of std::string which are apparent to anyone who is used to working with them: automatic memory management, simple initialization, copying with "=" operator, appending with "+=" operator, and comparisons with "==" and "!=" operators are some of the benefits. and any sane implementation has an O(1) time .c_str() member function which gives you the c-string if you need to use it.

the additional overhead of std::string opposed to c-strings is negligible in the majority of cases where you need to use strings.

std::string is not perfect however, its still missing many useful functions which i believe it should have by default. such as functions to append other basic types like integers/floats/doubles, as well as simple ways to format them. many other languages have strings behave like this by default, but c++ still doesn't :/
__________________

"It was, of course, a lie what you read about my religious convictions, a lie which is being systematically repeated. I do not believe in a personal God and I have never denied this but have expressed it clearly. If something is in me which can be called religious then it is the unbounded admiration for the structure of the world so far as our science can reveal it." - Albert Einstein
check out my blog
cottonvibes is offline   Reply With Quote
Old February 20th, 2012, 00:03   #343
-Ashe-
Registered User
 
-Ashe-'s Avatar
 
Join Date: Oct 2011
Posts: 189
Quote:
Originally Posted by cottonvibes View Post
such as functions to append other basic types like integers/floats/doubles, as well as simple ways to format them
Well there's stringstream and istream_iterator's to do just that...
edit: also not sure what would be intimidating about the class above, it's just a wrapper around IO completion ports (might as well directly use boost.asio)
-Ashe- is offline   Reply With Quote
Old February 20th, 2012, 00:53   #344
cottonvibes
You're already dead...
 
cottonvibes's Avatar
 
Join Date: Sep 2007
Location: Planet Vegeta
Posts: 5,385
Quote:
Originally Posted by -Ashe- View Post
Well there's stringstream and istream_iterator's to do just that...
stringstream is pretty ugly.
and my point was that such operations should be built-in to string's functionality.
i.e. in most highlevel languages you can do something along the lines of:
Code:
int i = 100;
double d = 7.7;
string s = "the answers are: ";
string a = s + i + " and " + d;
println(a);
it is possible with global operator overloading to get a similar affect, but this should be done for you imo.
c++ code that needs to do such things needs to use an additional stringstream object, or many people go back and use c-string functions to do the necessary task to avoid using stringstream.

imo any high-level language should have very quick-to-use and powerful string operations built-in to the language or standard lib, because they're so commonly used.
__________________

"It was, of course, a lie what you read about my religious convictions, a lie which is being systematically repeated. I do not believe in a personal God and I have never denied this but have expressed it clearly. If something is in me which can be called religious then it is the unbounded admiration for the structure of the world so far as our science can reveal it." - Albert Einstein
check out my blog
cottonvibes is offline   Reply With Quote
Old February 20th, 2012, 13:57   #345
-Ashe-
Registered User
 
-Ashe-'s Avatar
 
Join Date: Oct 2011
Posts: 189
Probably, never been a fan of string(or io)streams... then again I rarely need that kind of feature
-Ashe- is offline   Reply With Quote
Old June 15th, 2012, 07:16   #346
raksmey1309
បងស្រលាញ់អូន!
 
raksmey1309's Avatar
 
Join Date: Jul 2005
Location: ព្រះរាជាណាចក្រកម្ពុជា
Posts: 4,107
I am bore today write this for fun =.-

Code:
#include <iostream>
#include <string>
#include <sstream>
#define ai "=love"
#define plus "+"

using namespace std;
	
	string input1;
	string input2;

string love (string otani, string lin) {
	
	string getOtani=otani;
	string getLin=lin;

	while(input1=="otani",input2=="lin"){

	return (getOtani+plus+getLin+ai);
	}

}

int main() {
	

	string result;

	cout << "Input your first word here:";

	getline (cin,input1);

	cout << endl <<"Input your second word here:";

	getline (cin,input2);

	cout << endl <<love(input1, input2);

	cin.get();

	return 0;
}
__________________
I am the keyblade that, hopefully, will unlock your heart someday.

Proud to be Asian, proud to be Cambodian.
CPU: intel Core i7 3770 - GPU: nVidia GTX 660
M/B: Asrock Extreme 4M - RAM: DDR3 8GB bus 1600 MHz
HDD: 3TB SATA 3 7200rpm - Windows 7 64bits SP1
raksmey1309 is offline   Reply With Quote
Old June 15th, 2012, 11:11   #347
refraction
PCSX2 Coder
 
refraction's Avatar
 
Join Date: Jan 2004
Location: Plymouth, UK
Posts: 10,037
thats a love ly piece of code! :P
__________________

http://www.pcsx2.net
Intel i7 920 @ 3.4Ghz, POV GTX 570 1.3Gb, 1.8Tb HD space, 6Gb OCZ Reaper PC3-14400 Triple Channel
Dont PM me for help, use the forums, thats what its for!


My Chip16 Emulator RefChip16 http://code.google.com/p/refchip16/
refraction is offline   Reply With Quote
Old June 30th, 2012, 21:39   #348
@ruantec
Crazy GFX coder
 
@ruantec's Avatar
 
Join Date: Nov 2002
Location: Dominican Republic/Austria
Posts: 8,096
Quote:
Originally Posted by refraction View Post
thats a love ly piece of code! :P
Meh... it reminds me that i'll have to code C++ in my new job that starts this september

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

Here one of the interfaces i wrote today for @ES plugin mechanism. Nothing fancy just interfaces that @ES core offers to deal with assemblies loaded dynamically from the plugins/extension folders. My goal is to offer those as open source so that people can extend or modify @ES look and capabilities.

1. App.Config obviously:

Code:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <runtime>
    <legacyUnhandledExceptionPolicy enabled="1"/>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <probing privatePath="Libraries;Plugins\Extensions;Plugins\Emulation" />
    </assemblyBinding>
  </runtime>
</configuration>
Set the paths to scan for possible assemblies. I added the plugins and extensions folder for testing porpuses but they aren't necessary since i offer interfaces to deal with them when the user load them.

2. Player interface to handle audio/video player plugins.
Code:
using System;
using System.Collections;
using AES_Core.Common;

namespace AES_Core.Interfaces
{
    /// <summary>
    /// Base interface of @ES players
    /// </summary>
    public interface IPlayer
    {
        //Base properties
        bool Shuffle { get; set; }
        bool Replay { get; set; }
        IEnumerable Playlist { get; set; }
        Enumerators.PluginType Type { get; }
        Version Version { get; }
        string Author { get; }

        //Base  methods
        void Initialize();
        void Play();
        void Pause();
        void Stop();
        void Next();
        void Previous();
        void Volume(int value);
        void Position(int value);
        void LoadFile(string file);
    }
}
3. Player class of @ES audio plugin:
Code:
using System;
using System.Collections;
using System.Reflection;
using AES_Core.Common;
using AES_Core.Interfaces;

namespace AES_Audio
{
    public class AudioPlayer : IPlayer
    {
        private string currentFile;
        /// <summary>
        /// Get or Set shuffle flag
        /// </summary>
        public bool Shuffle { get; set; }
        /// <summary>
        /// Get or Set replay flag
        /// </summary>
        public bool Replay { get; set; }
        /// <summary>
        /// Get or Set playlist
        /// </summary>
        public IEnumerable Playlist { get; set; }
        /// <summary>
        /// Get type of the plugin
        /// </summary>
        public Enumerators.PluginType Type
        {
            get { return Enumerators.PluginType.Audio; }
        }
        /// <summary>
        /// Get version of the plugin
        /// </summary>
        public Version Version
        {
            get { return Assembly.GetCallingAssembly().GetName().Version; }
        }
        /// <summary>
        /// Get author of the plugin
        /// </summary>
        public string Author
        {
            get { return "@ruantec"; }
        }
        /// <summary>
        /// Initialize any necessary components
        /// </summary>
        public void Initialize()
        {
            
        }
        /// <summary>
        /// Play selected file
        /// </summary>
        public void Play()
        {
            
        }
        /// <summary>
        /// Pause selected file
        /// </summary>
        public void Pause()
        {
            
        }
        /// <summary>
        /// Stop selected file
        /// </summary>
        public void Stop()
        {
            
        }
        /// <summary>
        /// Play next file
        /// </summary>
        public void Next()
        {
            
        }
        /// <summary>
        /// Play previous file
        /// </summary>
        public void Previous()
        {
            
        }
        /// <summary>
        /// Set volume value
        /// </summary>
        /// <param name="value">Value to set</param>
        public void Volume(int value)
        {
            
        }
        /// <summary>
        /// Set position value
        /// </summary>
        /// <param name="value">Value to set</param>
        public void Position(int value)
        {
            
        }
        /// <summary>
        /// Load/Play the file given
        /// </summary>
        /// <param name="file">File to use</param>
        public void LoadFile(string file)
        {
            currentFile = file;
        }
    }
}
4. Since i'm using MVVM coding pattern here is my ViewModel base class:
Code:
using System.ComponentModel;
using System.Windows.Input;
using AES_Core.Commands;

namespace AES_Core.ViewModelHandling
{
    /// <summary>
    /// Represents the base of every viewmodel
    /// </summary>
    public abstract class ViewModelBase : INotifyPropertyChanged
    {
        private ICommand homeCommand;
        private ICommand controlsCommand;
        /// <summary>
        /// Get or Set the command to return to the main layer
        /// </summary>
        public ICommand HomeCommand
        {
            get { return homeCommand ?? (homeCommand = new DelegateCommand(Home) { MouseGesture = MouseAction.LeftClick }); }
            set { homeCommand = value; }
        }
        /// <summary>
        /// Get or Set command to switch to the controls layer
        /// </summary>
        public ICommand ControlsCommand
        {
            get { return controlsCommand ?? (controlsCommand = new DelegateCommand(ShowControls) { MouseGesture = MouseAction.LeftClick }); }
            set { controlsCommand = value; }
        }
        /// <summary>
        /// Event trigger when a property has changed
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;
        /// <summary>
        /// Invoke property name using our trigger
        /// </summary>
        /// <param name="propertyName">Name of the property</param>
        /// <param name="sender"></param>
        public void InvokePropertyChanged(string propertyName, object sender = null)
        {
            if (sender == null) sender = this;
            if (PropertyChanged != null) PropertyChanged(sender, new PropertyChangedEventArgs(propertyName));
        }
        /// <summary>
        /// Return to the main layer
        /// </summary>
        private void Home()
        {
            InvokePropertyChanged("SwitchToHome");
        }
        /// <summary>
        /// Switch to the screen controls
        /// </summary>
        public void ShowControls()
        {
            InvokePropertyChanged("SwitchToControls");
        }
    }
}
Result:
__________________


Current development tools:

Visual C++.net, Visual C#.net
Visual VB.net, Visual Webdeveloper.net
Bloodshed Dev C++, Borland C++
Visual Basic 6

Last edited by @ruantec; June 30th, 2012 at 21:54..
@ruantec is online now   Reply With Quote
Old October 27th, 2012, 10:51   #349
blueshogun96
Last Xbox Emu Author
 
blueshogun96's Avatar
 
Join Date: Jun 2004
Location: Seattle, WA, USA
Posts: 5,843
Been slaving away over my flagship game, RyuAwai, for a long time and ended up putting majority of things emu related on halt because of it. Some people have compared it to games like Bug Princess, and even Panzer Dragoon, which is a major compliment, be'll see how it fares in the real world market soon, I hope.

I wrote this timing code to handle streaming audio in a seperate thread since some PCs don't like the fact that I was doing it in the main thread. Works pretty well, in fact, works better than Microsoft said it would (considering it uses timeSetEvent).

timing.h
Code:
#pragma once


/* Timer structure */
struct timer_t
{
	UINT timer_id;			/* Timer's ID */
	UINT delay;				/* Delay (in milliseconds) */
	UINT param;				/* Function parameter */
	char name[32];			/* An optional name for this timer */
	LPTIMECALLBACK func;	/* Callback to timer */
};


/* Timing functions */
int init_timing_system();
void uninit_timing_system();
int create_timer( struct timer_t* timer, UINT event_type );
void kill_timer( struct timer_t* timer );
timing.c
Code:
#include "platform.h"
#include "timing.h"



int init_timing_system()
{
	TIMECAPS tcaps;
	MMRESULT error = 0;

	/* Get the system's timer capabilities */
	error = timeGetDevCaps( &tcaps, sizeof( TIMECAPS ) );
	if( error )
		return 0;

	/* Use the most accurate timing resolution possible */
	error = timeBeginPeriod( tcaps.wPeriodMin );
	if( error )
		return 0;

	return 1;
}

void uninit_timing_system()
{
	TIMECAPS tcaps;
	MMRESULT error = 0;

	/* Get the system's timer capabilities, one more time. */
	error = timeGetDevCaps( &tcaps, sizeof( TIMECAPS ) );

	/* If we fail, just use the default value. If not, use the same value
	   we used to initialize the timer system. */
	if( error )
		timeEndPeriod(1);
	else
		timeEndPeriod( tcaps.wPeriodMin );
}

int create_timer( struct timer_t* timer, UINT event_type )
{
	/* Sanity checks (saftey first) */
	
	if( !timer )
		return 0;

	if( !timer->func )
		return 0;

	/* Create the actual timer procedure */
	timer->timer_id = timeSetEvent( timer->delay, 0,
		timer->func, timer->param, event_type );
	if( !timer->timer_id )
		return 0;

	return 1;
}

void kill_timer( struct timer_t* timer )
{
	/* Sanity checks (saftey first) */
	if( !timer )
		return;

	/* Stop the timer procedure */
	timeKillEvent( timer->timer_id );
}
As always, before using it, make sure you understand how timeSet/KillEvent works. Just set the timer_t::delay to the time (in milliseconds) you want the thread to be called, and set timer_t::func to point to your function, and there you go!
__________________

Official Website of Shogun3D's RyuAwai!

Shogun3D Game Development Blog

Zengjük a Dalt: Manliest Song Ever!
blueshogun96 is offline   Reply With Quote
Old December 9th, 2012, 20:49   #350
@ruantec
Crazy GFX coder
 
@ruantec's Avatar
 
Join Date: Nov 2002
Location: Dominican Republic/Austria
Posts: 8,096
There are no words to express my love for C# and WPF. I wrote today some UI templates which is pretty much similar to C++ templates but for UI.

XAML Code:
Code:
<!--Dynamic item drag definition-->
        <DataTemplate x:Key="TemplateDrag" DataType="{x:Type ContentControl}">
            <Grid AllowDrop="True">
                <Border BorderThickness="0.3" BorderBrush="#4CCFCFCF"/>
                <Grid Height="Auto">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="65"/>
                        <ColumnDefinition Width="50*"/>
                        <ColumnDefinition Width="20*"/>
                    </Grid.ColumnDefinitions>
                    <Viewbox Grid.Column="0" Stretch="Uniform">
                        <Grid>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="14*"/>
                                    <ColumnDefinition Width="76*"/>
                                </Grid.ColumnDefinitions>
                                <Image x:Name="img_cover" Grid.Column="1" Stretch="UniformToFill" HorizontalAlignment="Left" Height="56" Width="56" Source="{Binding ImageUrl, Converter={StaticResource coverConverter}}"/>
                            </Grid>
                            <Image x:Name="img_cover_Over" Stretch="Uniform" Width="69.5" Height="Auto" HorizontalAlignment="Left" Source="{Binding DefaultCase}"/>
                        </Grid>
                    </Viewbox>
                    <Grid Grid.Column="1">
                        <Label x:Name="l_track" HorizontalAlignment="Left" VerticalAlignment="Top" Foreground="#FFC3C3C3" FontSize="12" Background="#00000000" Content="{Binding Track}" />
                        <Label x:Name="l_title" HorizontalAlignment="Left" VerticalAlignment="Center" Foreground="#FFF1F1F1" FontSize="12" Background="#00000000" Content="{Binding Title}"/>
                        <Label x:Name="l_album" HorizontalAlignment="Left" VerticalAlignment="Bottom" Foreground="#FFC3C3C3" FontSize="12" Content="{Binding Album}"/>
                    </Grid>
                    <Grid Grid.Column="2">
                        <Label x:Name="l_time" HorizontalAlignment="Right" VerticalAlignment="Stretch" Foreground="#FFC3C3C3" FontSize="12" Content="{Binding TotalTime}"/>
                        <Label x:Name="l_format" HorizontalAlignment="Right" VerticalAlignment="Bottom" Foreground="#FFC3C3C3" FontSize="12" FontStyle="Italic" Content="{Binding Format}"/>
                    </Grid>
                </Grid>
            </Grid>
        </DataTemplate>
        <!--Dynamic item definition-->
        <ControlTemplate x:Key="ItemDefinition" TargetType="{x:Type ContentControl}">
            <Grid>
                <Border BorderThickness="0.3" BorderBrush="#4CCFCFCF"/>
                <Grid Height="Auto">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="65"/>
                        <ColumnDefinition Width="50*"/>
                        <ColumnDefinition Width="20*"/>
                    </Grid.ColumnDefinitions>
                    <Viewbox Grid.Column="0" Stretch="Uniform">
                        <Grid>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="14*"/>
                                    <ColumnDefinition Width="76*"/>
                                </Grid.ColumnDefinitions>
                            	<Image x:Name="img_cover" Grid.Column="1" Stretch="UniformToFill" HorizontalAlignment="Left" Height="56" Width="56" Source="{Binding ImageUrl, Converter={StaticResource coverConverter}}"/>
                            </Grid>
                            <Image x:Name="img_cover_Over" Stretch="Uniform" Width="69.5" Height="Auto" HorizontalAlignment="Left" Source="{Binding DefaultCase}"/>
                        </Grid>
                    </Viewbox>
                    <Grid Grid.Column="1">
                        <Label x:Name="l_track" HorizontalAlignment="Left" VerticalAlignment="Top" Foreground="#FFC3C3C3" FontSize="12" Background="#00000000" Content="Stream" />
                        <Label x:Name="l_title" HorizontalAlignment="Left" VerticalAlignment="Center" Foreground="#FFF1F1F1" FontSize="12" Background="#00000000" Content="{Binding Title}"/>
                        <Label x:Name="l_album" HorizontalAlignment="Left" VerticalAlignment="Bottom" Foreground="#FFC3C3C3" FontSize="12" Content="@ruantec cloud music"/>
                    </Grid>
                    <Grid Grid.Column="2">
                        <Label x:Name="l_time" HorizontalAlignment="Right" VerticalAlignment="Stretch" Foreground="#FFC3C3C3" FontSize="12" Content="{Binding TotalTime}"/>
                        <Label x:Name="l_format" HorizontalAlignment="Right" VerticalAlignment="Bottom" Foreground="#FFC3C3C3" FontSize="12" FontStyle="Italic" Content="{Binding Format}"/>
                    </Grid>
                </Grid>
            </Grid>
        </ControlTemplate>
        <!--Dynamic Playlist definition-->
        <ControlTemplate x:Key="PlaylistDefinition" TargetType="{x:Type ContentControl}">
            <Grid Background="Transparent" Name="PlaylistControl" Drop="PlaylistControlDrop">
                <Border BorderThickness="0.3" BorderBrush="#4CCFCFCF"/>
                <Grid Height="Auto">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="45"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Image x:Name="img_cover_Over" Margin="2" Grid.Column="0" Stretch="Uniform" HorizontalAlignment="Left" Source="{Binding ConverterParameter=playlist.png, Converter={StaticResource resourceConverter}}"/>
                    <Grid Grid.Column="1">
                        <Grid>
                            <TextBox I****TestVisible="{Binding I****Test}" 
                                Text="{Binding Name, Mode=TwoWay, 
                                UpdateSourceTrigger=PropertyChanged}" 
                                HorizontalAlignment="Left"
                                VerticalAlignment="Center"
                                Foreground="#FFF1F1F1" 
                                FontSize="11" 
                                Background="Transparent" 
                                BorderThickness="{Binding EditorThickNess}" 
                                Margin="3,-5,0,0">
                                <TextBox.InputBindings>
                                    <KeyBinding Key="Enter" Command="{Binding EditCompleteCommand}"/>
                                    <KeyBinding Key="Escape" Command="{Binding EditCompleteCommand}"/>
                                </TextBox.InputBindings>
                            </TextBox>
                            <Viewbox Height="10" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,5,7,0" ToolTip="{Binding ConverterParameter=39, Converter={StaticResource converter}}">
                                <Grid Background="Transparent"
                                    Behaviours:MouseEventBehaviour.ClickCommand="{Binding EditCommand}" 
                                    Behaviours:MouseEventBehaviour.ClickState="MouseLeft">
                                    <Grid Width="48" Height="48" Visibility="Collapsed" />
                                    <Path Data="M4.0236244,39.052L40.165103,39.052C40.450301,39.052 40.681998,39.283888 40.681998,39.569201 40.681998,39.853109 40.450301,40.084997 40.165103,40.084997L4.0236244,40.084997C3.7397775,40.084997 3.5079999,39.853109 3.508,39.569201 3.5079999,39.283888 3.7397775,39.052 4.0236244,39.052z M1.4660637,29.870001L4.6666819,32.565367 7.862,35.26193 3.9297002,36.685066 0,38.107 0.72917366,33.9897z M18.590957,6.6210001L27.38,14.024666 12.187496,32.056002 3.4010005,24.651047z M27.067681,0.0002617836C28.355897,0.012507915 29.647309,0.45489883 30.707934,1.3482051 33.134921,3.3910286 33.444808,7.0237912 31.400603,9.4456298L29.49709,11.706 20.711001,4.302387 22.612012,2.0420456C23.760415,0.67982674,25.411407,-0.015483379,27.067681,0.0002617836z" Stretch="Uniform" Fill="#FFFFFFFF" Width="46" Height="46" Margin="0,0,0,0" RenderTransformOrigin="0.5,0.5">
                                        <Path.RenderTransform>
                                            <TransformGroup>
                                                <TransformGroup.Children>
                                                    <RotateTransform Angle="0" />
                                                    <ScaleTransform ScaleX="-1" ScaleY="1" />
                                                </TransformGroup.Children>
                                            </TransformGroup>
                                        </Path.RenderTransform>
                                    </Path>
                                </Grid>
                            </Viewbox>
                        </Grid>
                        <StackPanel Orientation="Horizontal">
                            <Label x:Name="l_title" HorizontalAlignment="Left" VerticalAlignment="Bottom" Foreground="#FFC3C3C3" FontSize="11" Content="Items:"/>
                            <Label x:Name="l_items" HorizontalAlignment="Left" VerticalAlignment="Bottom" Foreground="#FFC3C3C3" FontSize="11" Content="{Binding ItemCount}"/>
                        </StackPanel>
                    </Grid>
                </Grid>
            </Grid>
        </ControlTemplate>
C# Item ViewModel Code:
Code:
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Input;
using AES_ViewModelHandler.ViewModelHandling;

namespace AES_ViewModelHandler.FileHandling
{
    public class PlaylistItem : ViewModelBase
    {
        private string _name;
        private int _itemCount;
        private ObservableList<object> _files;
        private const string ITEMLISTBEGIN = "<Plalist>";
        private const string ITEMLISTEND = "</Plalist>";
        private const string ITEMBEGIN = "<Item>";
        private const string ITEMEND = "</Item>";
        private bool _i****Test;
        private int _editorThickness;

        private ICommand _editCompleteCommand;
        private ICommand _editCommand;

        public string InternalGuid { get; set; }

        public ICommand EditCommand
        {
            get { return _editCommand ?? (_editCommand = new DelegateCommand(EditStart) { MouseGesture = MouseAction.LeftClick }); }
            set { _editCommand = value; }
        }

        public ICommand EditCompleteCommand
        {
            get { return _editCompleteCommand ?? (_editCompleteCommand = new DelegateCommand(EditComplete) { MouseGesture = MouseAction.LeftClick }); }
            set { _editCompleteCommand = value; }
        }

        public int EditorThickNess
        {
            get { return _editorThickness; }
            set { _editorThickness = value; InvokePropertyChanged("EditorThickNess"); }
        }

        public bool I****Test
        {
            get { return _i****Test; }
            set { _i****Test = value; InvokePropertyChanged("I****Test"); }
        }

        /// <summary>
        /// Get or Set the name of the custom playlist
        /// </summary>
        public string Name
        {
            get { return _name; }
            set { _name = value; InvokePropertyChanged("Name"); }
        }

        /// <summary>
        /// Get or Set the count of the custom playlist items
        /// </summary>
        public int ItemCount
        {
            get { return _itemCount; }
            set { _itemCount = value; InvokePropertyChanged("ItemCount"); }
        }

        /// <summary>
        /// Get or Set the collection of items in our custom playlist
        /// </summary>
        public ObservableList<object> Files
        {
            get { return _files; }
            set { _files = value; InvokePropertyChanged("Files"); }
        }

        /// <summary>
        /// Constructor
        /// </summary>
        public PlaylistItem()
        {
            Files = new ObservableList<object>();
        }

        /// <summary>
        /// Add a new item to our collection and update the item count
        /// </summary>
        /// <param name="item"></param>
        public void AddNewItem(object item)
        {
            Files.Add(item);
            ItemCount = Files.Count;
        }

        /// <summary>
        /// Remove a specified item from the file collection
        /// </summary>
        /// <param name="item"></param>
        public void DeleteFile(object item)
        {
            if (Files == null) return;
            Files.Remove(item);
            SavePlaylist();
            ItemCount = Files.Count;
        }

        /// <summary>
        /// Save the current playlist to the determined path
        /// </summary>
        public void SavePlaylist()
        {
            var sBuilder = new StringBuilder();
            //Create file text header which contains the internal name of the playlist
            sBuilder.AppendLine(string.Format("InternalName|{0}", Name));
            sBuilder.AppendLine(string.Format("InternalGuid|{0}", InternalGuid));
            sBuilder.AppendLine(ITEMLISTBEGIN);
            foreach (var file in Files)
            {
                sBuilder.AppendLine(string.Format("\t{0}", ITEMBEGIN));
                var properties = file.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public)
                                                                    .Where(ø => ø.CanRead && ø.CanWrite)
                                                                    //.Where(ø => ø.PropertyType == typeof(string))
                                                                    //.Where(ø => ø.GetGetMethod(true).IsPublic)
                                                                    .Where(ø => ø.GetSetMethod(true).IsPublic);

                foreach (var property in properties)
                {
                    var value = property.GetValue(file, null) as string;
                    sBuilder.AppendLine(string.Format("\t\t{0}|{1}", property.Name, value));
                }
                sBuilder.AppendLine(string.Format("\t{0}", ITEMEND));
            }
            sBuilder.AppendLine(ITEMLISTEND);

            File.WriteAllText(string.Format(@"{0}\Playlists\Custom\CloudLists\{1}.@cl", AppDomain.CurrentDomain.BaseDirectory, InternalGuid), sBuilder.ToString());
        }

        public void LoadPlaylist(Type type, string file, bool isStream = false)
        {
            if(!File.Exists(file)) return;
            var fileText = File.ReadAllText(file);
            //Set name
            Name = fileText.Split(new[] { "InternalName|" }, StringSplitOptions.None)[1].Split('\n')[0].Trim();
            var items = Regex.Split(fileText, ITEMBEGIN);
            if (!items.Any()) return;
            for (var i = 1; i < items.Count(); i++)
            {
                var obj = Activator.CreateInstance(type);
                var properties = obj.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public)
                    .Where(ø => ø.CanRead && ø.CanWrite)
                    //.Where(ø => ø.PropertyType == typeof(string))
                    //.Where(ø => ø.GetGetMethod(true).IsPublic)
                    //.Where(ø => ø.PropertyType == typeof(Nullable<>))
                    .Where(ø => ø.GetSetMethod(true).IsPublic);

                foreach (var property in properties)
                {
                    var itemProperties = items[i].Split('\n');
                    foreach (var propertyValue in itemProperties.Where(itemProperty => itemProperty.Trim().Split('|')[0] == property.Name).Select(itemProperty => itemProperty.Trim().Split('|')[1]))
                    {
                        if(property.Name == "IsStream")
                            property.SetValue(obj, isStream, null);
                        else if (!string.IsNullOrEmpty(propertyValue))
                        {
                            property.SetValue(obj, propertyValue, null);
                        }
                    }
                }
                AddNewItem(obj);
            }
        }

        private void EditComplete()
        {
            I****Test = false;
            EditorThickNess = 0;
            SavePlaylist();
        }

        private void EditStart()
        {
            if(I****Test)
            {
                EditComplete();
            }
            else
            {
                I****Test = true;
                EditorThickNess = 1;
            }
        }
    }
}
Voila!!!! i can add/Remove/Change items in my class and have my code fully separated from the UI. The UI itself deside how items are going to be displayed... is just so awesome that no words can explain my love for it. Wish my 8-10 hours at work were as awesome when it Comes to coding design as it is with my program.

Here the result:


Here the drag template when re-positioning/dragging a element around:


The playlist and list are one and the same template. However they use different item templates according to the type given. The code doesn't know about the UI yet the UI works perfectly with the code. In fact the C# code doesn't even know what's a button or a TextBox. As you can see in the first pic even items are editable

I can drool all over the place about the Beauty of C# and WPF. I may not agree with many MS moves or with there stuff in General but if there are things they did got right then is C# and WPF. To me the best Tools for application coding that exist right now but as everything in this world they aren't perfect.
__________________


Current development tools:

Visual C++.net, Visual C#.net
Visual VB.net, Visual Webdeveloper.net
Bloodshed Dev C++, Borland C++
Visual Basic 6

Last edited by @ruantec; December 11th, 2012 at 11:16..
@ruantec is online now   Reply With Quote
Old December 9th, 2012, 22:03   #351
miker00lz
Registered User
 
Join Date: Nov 2010
Location: St. Louis, MO USA
Posts: 44
Thought I'd share the 6502 CPU emulation code (plain C) from my NES emulator. It's GPLv2, so feel free to use it in a project if you'd like. You just need to provide it with memory read/write external functions, whose prototypes look like this:

Code:
uint8_t read6502(uint16_t address);
void write6502(uint16_t address, uint8_t value);
You can also use it's void hookexternal(void *funcptr) function, feed it a pointer of a void function that takes no arguments and the emulator will call it after every instruction it executes. I use it to drive the audio emulation code in my NES emu. If you ever want to make it stop doing the callbacks, just call hookexternal again but pass NULL to it.

Other than that, all you need to do is call reset6502() and then begin executing with exec6502(uint64_t tickcount) or step6502()

6502.h header file:
Code:
//6502 defines
#define UNDOCUMENTED //when this is defined, undocumented opcodes are handled.
                     //otherwise, they're simply treated as NOPs.

#define NES_CPU      //when this is defined, the binary-coded decimal (BCD)
                     //status flag is not honored by ADC and SBC. the 2A03
                     //CPU in the Nintendo Entertainment System does not
                     //support BCD operation.

#define FLAG_CARRY     0x01
#define FLAG_ZERO      0x02
#define FLAG_INTERRUPT 0x04
#define FLAG_DECIMAL   0x08
#define FLAG_BREAK     0x10
#define FLAG_CONSTANT  0x20
#define FLAG_OVERFLOW  0x40
#define FLAG_SIGN      0x80

#define BASE_STACK     0x100

#define saveaccum(n) a = (uint8_t)(n)


//flag modifier macros
#define setcarry() status |= FLAG_CARRY
#define clearcarry() status &= (~FLAG_CARRY)
#define setzero() status |= FLAG_ZERO
#define clearzero() status &= (~FLAG_ZERO)
#define setinterrupt() status |= FLAG_INTERRUPT
#define clearinterrupt() status &= (~FLAG_INTERRUPT)
#define setdecimal() status |= FLAG_DECIMAL
#define cleardecimal() status &= (~FLAG_DECIMAL)
#define setbreak() status |= FLAG_BREAK
#define clearbreak() status &= (~FLAG_BREAK)
#define setoverflow() status |= FLAG_OVERFLOW
#define clearoverflow() status &= (~FLAG_OVERFLOW)
#define setsign() status |= FLAG_SIGN
#define clearsign() status &= (~FLAG_SIGN)


//flag calculation macros
#define zerocalc(n) {\
    if ((n) & 0x00FF) clearzero();\
        else setzero();\
}

#define signcalc(n) {\
    if ((n) & 0x0080) setsign();\
        else clearsign();\
}

#define carrycalc(n) {\
    if ((n) & 0xFF00) setcarry();\
        else clearcarry();\
}

#define overflowcalc(n, m, o) { /* n = result, m = accumulator, o = memory */ \
    if (((n) ^ (uint16_t)(m)) & ((n) ^ (o)) & 0x0080) setoverflow();\
        else clearoverflow();\
}

6502.c main code:
Code:
/* MoarNES source - 6502.c

   This open-source software is (c)2010-2012 Mike Chambers, and is released
   under the terms of the GNU GPL v2 license.

   This is my implementation of a MOS Technology 6502 CPU emulator. The
   NES technically has a Ricoh 2A03, not a true 6502, however it is nearly
   identical to it.

   The differences are small:
     - The 2A03 does not support binary-coded decimal (BCD) arithmetic.
	 - It has the audio processor built into it.

   The audio emulation is, however, handled in APU.c.
*/

#include "config.h"
#include <stdio.h>
#include <malloc.h>
#include <stdint.h>
#include "6502.h"

//externally supplied functions
extern uint8_t read6502(uint16_t address);
extern void write6502(uint16_t address, uint8_t value);

//6502 CPU registers
uint16_t pc;
uint8_t sp, a, x, y, status;


//helper variables
uint64_t instructions = 0; //keep track of total instructions executed
uint64_t clockticks6502 = 0, clockgoal6502 = 0;
uint16_t oldpc, ea, reladdr, value, result;
uint8_t opcode, oldstatus;

//a few general functions used by various other functions
void push16(uint16_t pushval) {
    write6502(BASE_STACK + sp, (pushval >> 8) & 0xFF);
    write6502(BASE_STACK + ((sp - 1) & 0xFF), pushval & 0xFF);
    sp -= 2;
}

void push8(uint8_t pushval) {
    write6502(BASE_STACK + sp--, pushval);
}

uint16_t pull16() {
    uint16_t temp16;
    temp16 = read6502(BASE_STACK + ((sp + 1) & 0xFF)) | ((uint16_t)read6502(BASE_STACK + ((sp + 2) & 0xFF)) << 8);
    sp += 2;
    return(temp16);
}

uint8_t pull8() {
    return (read6502(BASE_STACK + ++sp));
}

void reset6502() {
    pc = (uint16_t)read6502(0xFFFC) | ((uint16_t)read6502(0xFFFD) << 8);
    a = 0;
    x = 0;
    y = 0;
    sp = 0xFF;
    status |= FLAG_CONSTANT;
}


static void (*addrtable[256])();
static void (*optable[256])();
uint8_t penaltyop, penaltyaddr;

//addressing mode functions, calculates effective addresses
static void imp() { //implied
}

static void acc() { //accumulator
}

static void imm() { //immediate
    ea = pc++;
}

static void zp() { //zero-page
    ea = (uint16_t)read6502((uint16_t)pc++);
}

static void zpx() { //zero-page,X
    ea = ((uint16_t)read6502((uint16_t)pc++) + (uint16_t)x) & 0xFF; //zero-page wraparound
}

static void zpy() { //zero-page,Y
    ea = ((uint16_t)read6502((uint16_t)pc++) + (uint16_t)y) & 0xFF; //zero-page wraparound
}

static void rel() { //relative for branch ops (8-bit immediate value, sign-extended)
    reladdr = (uint16_t)read6502(pc++);
    if (reladdr & 0x80) reladdr |= 0xFF00;
}

static void abso() { //absolute
    ea = (uint16_t)read6502(pc) | ((uint16_t)read6502(pc+1) << 8);
    pc += 2;
}

static void absx() { //absolute,X
    uint16_t startpage;
    ea = ((uint16_t)read6502(pc) | ((uint16_t)read6502(pc+1) << 8));
    startpage = ea & 0xFF00;
    ea += (uint16_t)x;

    if (startpage != (ea & 0xFF00)) { //one cycle penlty for page-crossing on some opcodes
        penaltyaddr = 1;
    }

    pc += 2;
}

static void absy() { //absolute,Y
    uint16_t startpage;
    ea = ((uint16_t)read6502(pc) | ((uint16_t)read6502(pc+1) << 8));
    startpage = ea & 0xFF00;
    ea += (uint16_t)y;

    if (startpage != (ea & 0xFF00)) { //one cycle penlty for page-crossing on some opcodes
        penaltyaddr = 1;
    }

    pc += 2;
}

static void ind() { //indirect
    uint16_t eahelp, eahelp2;
    eahelp = (uint16_t)read6502(pc) | (uint16_t)((uint16_t)read6502(pc+1) << 8);
    eahelp2 = (eahelp & 0xFF00) | ((eahelp + 1) & 0x00FF); //replicate 6502 page-boundary wraparound bug
    ea = (uint16_t)read6502(eahelp) | ((uint16_t)read6502(eahelp2) << 8);
    pc += 2;
}

static void indx() { // (indirect,X)
    uint16_t eahelp;
    eahelp = (uint16_t)(((uint16_t)read6502(pc++) + (uint16_t)x) & 0xFF); //zero-page wraparound for table pointer
    ea = (uint16_t)read6502(eahelp & 0x00FF) | ((uint16_t)read6502((eahelp+1) & 0x00FF) << 8);
}

static void indy() { // (indirect),Y
    uint16_t eahelp, eahelp2, startpage;
    eahelp = (uint16_t)read6502(pc++);
    eahelp2 = (eahelp & 0xFF00) | ((eahelp + 1) & 0x00FF); //zero-page wraparound
    ea = (uint16_t)read6502(eahelp) | ((uint16_t)read6502(eahelp2) << 8);
    startpage = ea & 0xFF00;
    ea += (uint16_t)y;

    if (startpage != (ea & 0xFF00)) { //one cycle penlty for page-crossing on some opcodes
        penaltyaddr = 1;
    }
}

static uint16_t getvalue() {
    if (addrtable[opcode] == acc) return((uint16_t)a);
        else return((uint16_t)read6502(ea));
}

static uint16_t getvalue16() {
    return((uint16_t)read6502(ea) | ((uint16_t)read6502(ea+1) << 8));
}

static void putvalue(uint16_t saveval) {
    if (addrtable[opcode] == acc) a = (uint8_t)(saveval & 0x00FF);
        else write6502(ea, (saveval & 0x00FF));
}


//instruction handler functions
static void adc() {
    penaltyop = 1;
    value = getvalue();
    result = (uint16_t)a + value + (uint16_t)(status & FLAG_CARRY);

    #ifndef NES_CPU
    if (status & FLAG_DECIMAL) {
        clearcarry();
        
        if ((a & 0x0F) > 0x09) {
            a += 0x06;
        }
        if ((a & 0xF0) > 0x90) {
            a += 0x60;
            setcarry();
        }
        
        clockticks6502++;
    }
    #endif
   
    carrycalc(result);
    zerocalc(result);
    overflowcalc(result, a, value);
    signcalc(result);

	saveaccum(result);
}

static void and() {
    penaltyop = 1;
    value = getvalue();
    result = (uint16_t)a & value;
   
    zerocalc(result);
    signcalc(result);
   
    saveaccum(result);
}

static void asl() {
    value = getvalue();
    result = value << 1;

    carrycalc(result);
    zerocalc(result);
    signcalc(result);
   
    putvalue(result);
}

static void bcc() {
    if ((status & FLAG_CARRY) == 0) {
        oldpc = pc;
        pc += reladdr;
        if ((oldpc & 0xFF00) != (pc & 0xFF00)) clockticks6502 += 2; //check if jump crossed a page boundary
            else clockticks6502++;
    }
}

static void bcs() {
    if ((status & FLAG_CARRY) == FLAG_CARRY) {
        oldpc = pc;
        pc += reladdr;
        if ((oldpc & 0xFF00) != (pc & 0xFF00)) clockticks6502 += 2; //check if jump crossed a page boundary
            else clockticks6502++;
    }
}

static void beq() {
    if ((status & FLAG_ZERO) == FLAG_ZERO) {
        oldpc = pc;
        pc += reladdr;
        if ((oldpc & 0xFF00) != (pc & 0xFF00)) clockticks6502 += 2; //check if jump crossed a page boundary
            else clockticks6502++;
    }
}

static void bit() {
    value = getvalue();
    result = (uint16_t)a & value;
   
    zerocalc(result);
    status = (status & 0x3F) | (uint8_t)(value & 0xC0);
}

static void bmi() {
    if ((status & FLAG_SIGN) == FLAG_SIGN) {
        oldpc = pc;
        pc += reladdr;
        if ((oldpc & 0xFF00) != (pc & 0xFF00)) clockticks6502 += 2; //check if jump crossed a page boundary
            else clockticks6502++;
    }
}

static void bne() {
    if ((status & FLAG_ZERO) == 0) {
        oldpc = pc;
        pc += reladdr;
        if ((oldpc & 0xFF00) != (pc & 0xFF00)) clockticks6502 += 2; //check if jump crossed a page boundary
            else clockticks6502++;
    }
}

static void bpl() {
    if ((status & FLAG_SIGN) == 0) {
        oldpc = pc;
        pc += reladdr;
        if ((oldpc & 0xFF00) != (pc & 0xFF00)) clockticks6502 += 2; //check if jump crossed a page boundary
            else clockticks6502++;
    }
}

static void brk() {
    pc++;
    push16(pc); //push next instruction address onto stack
    push8(status | FLAG_BREAK); //push CPU status OR'd with break flag to stack
    setinterrupt(); //set interrupt flag
    pc = (uint16_t)read6502(0xFFFE) | ((uint16_t)read6502(0xFFFF) << 8);
}

static void bvc() {
    if ((status & FLAG_OVERFLOW) == 0) {
        oldpc = pc;
        pc += reladdr;
        if ((oldpc & 0xFF00) != (pc & 0xFF00)) clockticks6502 += 2; //check if jump crossed a page boundary
            else clockticks6502++;
    }
}

static void bvs() {
    if ((status & FLAG_OVERFLOW) == FLAG_OVERFLOW) {
        oldpc = pc;
        pc += reladdr;
        if ((oldpc & 0xFF00) != (pc & 0xFF00)) clockticks6502 += 2; //check if jump crossed a page boundary
            else clockticks6502++;
    }
}

static void clc() {
    clearcarry();
}

static void cld() {
    cleardecimal();
}

static void cli() {
    clearinterrupt();
}

static void clv() {
    clearoverflow();
}

static void cmp() {
    penaltyop = 1;
    value = getvalue();
    result = (uint16_t)a - value;
   
    if (a >= (uint8_t)(value & 0x00FF)) setcarry();
        else clearcarry();
    if (a == (uint8_t)(value & 0x00FF)) setzero();
        else clearzero();
    signcalc(result);
}

static void cpx() {
    value = getvalue();
    result = (uint16_t)x - value;
   
    if (x >= (uint8_t)(value & 0x00FF)) setcarry();
        else clearcarry();
    if (x == (uint8_t)(value & 0x00FF)) setzero();
        else clearzero();
    signcalc(result);
}

static void cpy() {
    value = getvalue();
    result = (uint16_t)y - value;
   
    if (y >= (uint8_t)(value & 0x00FF)) setcarry();
        else clearcarry();
    if (y == (uint8_t)(value & 0x00FF)) setzero();
        else clearzero();
    signcalc(result);
}

static void dec() {
    value = getvalue();
    result = value - 1;
   
    zerocalc(result);
    signcalc(result);
   
    putvalue(result);
}

static void dex() {
    x--;
   
    zerocalc(x);
    signcalc(x);
}

static void dey() {
    y--;
   
    zerocalc(y);
    signcalc(y);
}

static void eor() {
    penaltyop = 1;
    value = getvalue();
    result = (uint16_t)a ^ value;
   
    zerocalc(result);
    signcalc(result);
   
    saveaccum(result);
}

static void inc() {
    value = getvalue();
    result = value + 1;
   
    zerocalc(result);
    signcalc(result);
   
    putvalue(result);
}

static void inx() {
    x++;
   
    zerocalc(x);
    signcalc(x);
}

static void iny() {
    y++;
   
    zerocalc(y);
    signcalc(y);
}

static void jmp() {
    pc = ea;
}

static void jsr() {
    push16(pc - 1);
    pc = ea;
}

static void lda() {
    penaltyop = 1;
    value = getvalue();
    a = (uint8_t)(value & 0x00FF);
   
    zerocalc(a);
    signcalc(a);
}

static void ldx() {
    penaltyop = 1;
    value = getvalue();
    x = (uint8_t)(value & 0x00FF);
   
    zerocalc(x);
    signcalc(x);
}

static void ldy() {
    penaltyop = 1;
    value = getvalue();
    y = (uint8_t)(value & 0x00FF);
   
    zerocalc(y);
    signcalc(y);
}

static void lsr() {
    value = getvalue();
    result = value >> 1;
   
    if (value & 1) setcarry();
        else clearcarry();
    zerocalc(result);
    signcalc(result);
   
    putvalue(result);
}

static void nop() {
    switch (opcode) {
        case 0x1C:
        case 0x3C:
        case 0x5C:
        case 0x7C:
        case 0xDC:
        case 0xFC:
            penaltyop = 1;
            break;
    }
}

static void ora() {
    penaltyop = 1;
    value = getvalue();
    result = (uint16_t)a | value;
   
    zerocalc(result);
    signcalc(result);
   
    saveaccum(result);
}

static void pha() {
    push8(a);
}

static void php() {
    push8(status | FLAG_BREAK);
}

static void pla() {
    a = pull8();
   
    zerocalc(a);
    signcalc(a);
}

static void plp() {
    status = pull8() | FLAG_CONSTANT;
}

static void rol() {
    value = getvalue();
    result = (value << 1) | (status & FLAG_CARRY);
   
    carrycalc(result);
    zerocalc(result);
    signcalc(result);
   
    putvalue(result);
}

static void ror() {
    value = getvalue();
    result = (value >> 1) | ((status & FLAG_CARRY) << 7);
   
    if (value & 1) setcarry();
        else clearcarry();
    zerocalc(result);
    signcalc(result);
   
    putvalue(result);
}

static void rti() {
    status = pull8();
    value = pull16();
    pc = value;
}

static void rts() {
    value = pull16();
    pc = value + 1;
}

static void sbc() {
    penaltyop = 1;
    value = getvalue() ^ 0x00FF;
    result = (uint16_t)a + value + (uint16_t)(status & FLAG_CARRY);

    #ifndef NES_CPU
    if (status & FLAG_DECIMAL) {
        clearcarry();
        
        a -= 0x66;
        if ((a & 0x0F) > 0x09) {
            a += 0x06;
        }
        if ((a & 0xF0) > 0x90) {
            a += 0x60;
            setcarry();
        }
        
        clockticks6502++;
    }
    #endif

    carrycalc(result);
    zerocalc(result);
    overflowcalc(result, a, value);
    signcalc(result);
   
    saveaccum(result);
}

static void sec() {
    setcarry();
}

static void sed() {
    setdecimal();
}

static void sei() {
    setinterrupt();
}

static void sta() {
    putvalue(a);
}

static void stx() {
    putvalue(x);
}

static void sty() {
    putvalue(y);
}

static void tax() {
    x = a;
   
    zerocalc(x);
    signcalc(x);
}

static void tay() {
    y = a;
   
    zerocalc(y);
    signcalc(y);
}

static void tsx() {
    x = sp;
   
    zerocalc(x);
    signcalc(x);
}

static void txa() {
    a = x;
   
    zerocalc(a);
    signcalc(a);
}

static void txs() {
    sp = x;
}

static void tya() {
    a = y;
   
    zerocalc(a);
    signcalc(a);
}

//undocumented instructions
#ifdef UNDOCUMENTED
    static void lax() {
        lda();
        ldx();
    }

    static void sax() {
        sta();
        stx();
        putvalue(a & x);
        if (penaltyop && penaltyaddr) clockticks6502--;
    }

    static void dcp() {
        dec();
        cmp();
        if (penaltyop && penaltyaddr) clockticks6502--;
    }

    static void isb() {
        inc();
        sbc();
        if (penaltyop && penaltyaddr) clockticks6502--;
    }

    static void slo() {
        asl();
        ora();
        if (penaltyop && penaltyaddr) clockticks6502--;
    }

    static void rla() {
        rol();
        and();
        if (penaltyop && penaltyaddr) clockticks6502--;
    }

    static void sre() {
        lsr();
        eor();
        if (penaltyop && penaltyaddr) clockticks6502--;
    }

    static void rra() {
        ror();
        adc();
        if (penaltyop && penaltyaddr) clockticks6502--;
    }
#else
    #define lax nop
    #define sax nop
    #define dcp nop
    #define isb nop
    #define slo nop
    #define rla nop
    #define sre nop
    #define rra nop
#endif


static void (*addrtable[256])() = {
/*        |  0  |  1  |  2  |  3  |  4  |  5  |  6  |  7  |  8  |  9  |  A  |  B  |  C  |  D  |  E  |  F  |     */
/* 0 */     imp, indx,  imp, indx,   zp,   zp,   zp,   zp,  imp,  imm,  acc,  imm, abso, abso, abso, abso, /* 0 */
/* 1 */     rel, indy,  imp, indy,  zpx,  zpx,  zpx,  zpx,  imp, absy,  imp, absy, absx, absx, absx, absx, /* 1 */
/* 2 */    abso, indx,  imp, indx,   zp,   zp,   zp,   zp,  imp,  imm,  acc,  imm, abso, abso, abso, abso, /* 2 */
/* 3 */     rel, indy,  imp, indy,  zpx,  zpx,  zpx,  zpx,  imp, absy,  imp, absy, absx, absx, absx, absx, /* 3 */
/* 4 */     imp, indx,  imp, indx,   zp,   zp,   zp,   zp,  imp,  imm,  acc,  imm, abso, abso, abso, abso, /* 4 */
/* 5 */     rel, indy,  imp, indy,  zpx,  zpx,  zpx,  zpx,  imp, absy,  imp, absy, absx, absx, absx, absx, /* 5 */
/* 6 */     imp, indx,  imp, indx,   zp,   zp,   zp,   zp,  imp,  imm,  acc,  imm,  ind, abso, abso, abso, /* 6 */
/* 7 */     rel, indy,  imp, indy,  zpx,  zpx,  zpx,  zpx,  imp, absy,  imp, absy, absx, absx, absx, absx, /* 7 */
/* 8 */     imm, indx,  imm, indx,   zp,   zp,   zp,   zp,  imp,  imm,  imp,  imm, abso, abso, abso, abso, /* 8 */
/* 9 */     rel, indy,  imp, indy,  zpx,  zpx,  zpy,  zpy,  imp, absy,  imp, absy, absx, absx, absy, absy, /* 9 */
/* A */     imm, indx,  imm, indx,   zp,   zp,   zp,   zp,  imp,  imm,  imp,  imm, abso, abso, abso, abso, /* A */
/* B */     rel, indy,  imp, indy,  zpx,  zpx,  zpy,  zpy,  imp, absy,  imp, absy, absx, absx, absy, absy, /* B */
/* C */     imm, indx,  imm, indx,   zp,   zp,   zp,   zp,  imp,  imm,  imp,  imm, abso, abso, abso, abso, /* C */
/* D */     rel, indy,  imp, indy,  zpx,  zpx,  zpx,  zpx,  imp, absy,  imp, absy, absx, absx, absx, absx, /* D */
/* E */     imm, indx,  imm, indx,   zp,   zp,   zp,   zp,  imp,  imm,  imp,  imm, abso, abso, abso, abso, /* E */
/* F */     rel, indy,  imp, indy,  zpx,  zpx,  zpx,  zpx,  imp, absy,  imp, absy, absx, absx, absx, absx  /* F */
};

static void (*optable[256])() = {
/*        |  0  |  1  |  2  |  3  |  4  |  5  |  6  |  7  |  8  |  9  |  A  |  B  |  C  |  D  |  E  |  F  |      */
/* 0 */      brk,  ora,  nop,  slo,  nop,  ora,  asl,  slo,  php,  ora,  asl,  nop,  nop,  ora,  asl,  slo, /* 0 */
/* 1 */      bpl,  ora,  nop,  slo,  nop,  ora,  asl,  slo,  clc,  ora,  nop,  slo,  nop,  ora,  asl,  slo, /* 1 */
/* 2 */      jsr,  and,  nop,  rla,  bit,  and,  rol,  rla,  plp,  and,  rol,  nop,  bit,  and,  rol,  rla, /* 2 */
/* 3 */      bmi,  and,  nop,  rla,  nop,  and,  rol,  rla,  sec,  and,  nop,  rla,  nop,  and,  rol,  rla, /* 3 */
/* 4 */      rti,  eor,  nop,  sre,  nop,  eor,  lsr,  sre,  pha,  eor,  lsr,  nop,  jmp,  eor,  lsr,  sre, /* 4 */
/* 5 */      bvc,  eor,  nop,  sre,  nop,  eor,  lsr,  sre,  cli,  eor,  nop,  sre,  nop,  eor,  lsr,  sre, /* 5 */
/* 6 */      rts,  adc,  nop,  rra,  nop,  adc,  ror,  rra,  pla,  adc,  ror,  nop,  jmp,  adc,  ror,  rra, /* 6 */
/* 7 */      bvs,  adc,  nop,  rra,  nop,  adc,  ror,  rra,  sei,  adc,  nop,  rra,  nop,  adc,  ror,  rra, /* 7 */
/* 8 */      nop,  sta,  nop,  sax,  sty,  sta,  stx,  sax,  dey,  nop,  txa,  nop,  sty,  sta,  stx,  sax, /* 8 */
/* 9 */      bcc,  sta,  nop,  nop,  sty,  sta,  stx,  sax,  tya,  sta,  txs,  nop,  nop,  sta,  nop,  nop, /* 9 */
/* A */      ldy,  lda,  ldx,  lax,  ldy,  lda,  ldx,  lax,  tay,  lda,  tax,  nop,  ldy,  lda,  ldx,  lax, /* A */
/* B */      bcs,  lda,  nop,  lax,  ldy,  lda,  ldx,  lax,  clv,  lda,  tsx,  lax,  ldy,  lda,  ldx,  lax, /* B */
/* C */      cpy,  cmp,  nop,  dcp,  cpy,  cmp,  dec,  dcp,  iny,  cmp,  dex,  nop,  cpy,  cmp,  dec,  dcp, /* C */
/* D */      bne,  cmp,  nop,  dcp,  nop,  cmp,  dec,  dcp,  cld,  cmp,  nop,  dcp,  nop,  cmp,  dec,  dcp, /* D */
/* E */      cpx,  sbc,  nop,  isb,  cpx,  sbc,  inc,  isb,  inx,  sbc,  nop,  sbc,  cpx,  sbc,  inc,  isb, /* E */
/* F */      beq,  sbc,  nop,  isb,  nop,  sbc,  inc,  isb,  sed,  sbc,  nop,  isb,  nop,  sbc,  inc,  isb  /* F */
};

static const uint32_t ticktable[256] = {
/*        |  0  |  1  |  2  |  3  |  4  |  5  |  6  |  7  |  8  |  9  |  A  |  B  |  C  |  D  |  E  |  F  |     */
/* 0 */      7,    6,    2,    8,    3,    3,    5,    5,    3,    2,    2,    2,    4,    4,    6,    6,  /* 0 */
/* 1 */      2,    5,    2,    8,    4,    4,    6,    6,    2,    4,    2,    7,    4,    4,    7,    7,  /* 1 */
/* 2 */      6,    6,    2,    8,    3,    3,    5,    5,    4,    2,    2,    2,    4,    4,    6,    6,  /* 2 */
/* 3 */      2,    5,    2,    8,    4,    4,    6,    6,    2,    4,    2,    7,    4,    4,    7,    7,  /* 3 */
/* 4 */      6,    6,    2,    8,    3,    3,    5,    5,    3,    2,    2,    2,    3,    4,    6,    6,  /* 4 */
/* 5 */      2,    5,    2,    8,    4,    4,    6,    6,    2,    4,    2,    7,    4,    4,    7,    7,  /* 5 */
/* 6 */      6,    6,    2,    8,    3,    3,    5,    5,    4,    2,    2,    2,    5,    4,    6,    6,  /* 6 */
/* 7 */      2,    5,    2,    8,    4,    4,    6,    6,    2,    4,    2,    7,    4,    4,    7,    7,  /* 7 */
/* 8 */      2,    6,    2,    6,    3,    3,    3,    3,    2,    2,    2,    2,    4,    4,    4,    4,  /* 8 */
/* 9 */      2,    6,    2,    6,    4,    4,    4,    4,    2,    5,    2,    5,    5,    5,    5,    5,  /* 9 */
/* A */      2,    6,    2,    6,    3,    3,    3,    3,    2,    2,    2,    2,    4,    4,    4,    4,  /* A */
/* B */      2,    5,    2,    5,    4,    4,    4,    4,    2,    4,    2,    4,    4,    4,    4,    4,  /* B */
/* C */      2,    6,    2,    8,    3,    3,    5,    5,    2,    2,    2,    2,    4,    4,    6,    6,  /* C */
/* D */      2,    5,    2,    8,    4,    4,    6,    6,    2,    4,    2,    7,    4,    4,    7,    7,  /* D */
/* E */      2,    6,    2,    8,    3,    3,    5,    5,    2,    2,    2,    2,    4,    4,    6,    6,  /* E */
/* F */      2,    5,    2,    8,    4,    4,    6,    6,    2,    4,    2,    7,    4,    4,    7,    7   /* F */
};


void nmi6502() {
    push16(pc);
    push8(status);
    status |= FLAG_INTERRUPT;
    pc = (uint16_t)read6502(0xFFFA) | ((uint16_t)read6502(0xFFFB) << 8);
}

void irq6502() {
	if ((status & FLAG_INTERRUPT) == FLAG_INTERRUPT) return; //abort if interrupts are inhibited
    push16(pc);
    push8(status);
    status |= FLAG_INTERRUPT;
    pc = (uint16_t)read6502(0xFFFE) | ((uint16_t)read6502(0xFFFF) << 8);
}

uint8_t callexternal = 0;
void (*loopexternal)();
uint8_t showdump = 0;

uint64_t exec6502(uint64_t tickcount) {
	uint64_t startticks;
    clockgoal6502 += tickcount;
   
	startticks = clockticks6502;
    while (clockticks6502 < clockgoal6502) {
        opcode = read6502(pc++);
        status |= FLAG_CONSTANT;

        penaltyop = 0;
        penaltyaddr = 0;

        (*addrtable[opcode])();
        (*optable[opcode])();
        clockticks6502 += ticktable[opcode];
		if (penaltyop && penaltyaddr) clockticks6502++;

        instructions++;

        if (callexternal) (*loopexternal)();
    }
	
	return(clockticks6502 - startticks);
}

void step6502() {
    opcode = read6502(pc++);
    status |= FLAG_CONSTANT;

    penaltyop = 0;
    penaltyaddr = 0;

    (*addrtable[opcode])();
    (*optable[opcode])();
    clockticks6502 += ticktable[opcode];
    //if (penaltyop && penaltyaddr) clockticks6502++;
    clockgoal6502 = clockticks6502;

    instructions++;

    if (callexternal) (*loopexternal)();
}

void hookexternal(void *funcptr) {
    if (funcptr != (void *)NULL) {
        loopexternal = funcptr;
        callexternal = 1;
    } else callexternal = 0;
}

uint16_t getPC() {
	return(pc);
}

uint64_t getclockticks() {
	return(clockticks6502);
}
It's not the fastest in the world, but fast enough and I think it's very easy to read/understand/use. It should completely portable to any architecture without changes.

Last edited by miker00lz; December 9th, 2012 at 22:22..
miker00lz is offline   Reply With Quote
Old December 9th, 2012, 22:24   #352
@ruantec
Crazy GFX coder
 
@ruantec's Avatar
 
Join Date: Nov 2002
Location: Dominican Republic/Austria
Posts: 8,096
Nice code you got there miker00lz. Seems quite easy to read and understand
__________________


Current development tools:

Visual C++.net, Visual C#.net
Visual VB.net, Visual Webdeveloper.net
Bloodshed Dev C++, Borland C++
Visual Basic 6
@ruantec is online now   Reply With Quote
Old December 10th, 2012, 20:11   #353
@ruantec
Crazy GFX coder
 
@ruantec's Avatar
 
Join Date: Nov 2002
Location: Dominican Republic/Austria
Posts: 8,096
Here is an update to my previous code. I wrote the code quite quick this Weekend and obviously the code needed some optimizations. To do that i wrote a new Interface in order to handle different Kind of item objects.

Interface(IParsable):
Code:
namespace AES_ViewModelHandler.Interfaces
{
    /// <summary>
    /// Interface responsible to parse Media files
    /// </summary>
    public interface IParsable
    {
        object ParseFromText(string textToParse, bool isStream);
        bool IsStream { get; set; }
    }
}
Since i implemented a new Interface my item classes must now use that Interface and parse the objects themselves so that the Playlist can load and save any Kind of class properties to my custom list.

Here my AudioFile class implementing the IParsable interface:
Code:
using System.Linq;
using System.Reflection;
using AES_ViewModelHandler.Interfaces;
using AES_ViewModelHandler.ViewModelHandling;
using System;

namespace AES_ViewModelHandler.FileHandling
{
    /// <summary>
    /// Audio file information class
    /// Contains all the necessary information of a Audio media file
    /// </summary>
    public class AudioFile : ViewModelBase, IParsable
    {
        public string File { get; set; }
        public string ImageUrl { get; set; }
        public string Path { get; set; }
        public string Title { get; set; }
        public string Artist { get; set; }
        public string Album { get; set; }
        public string AlbumArtist { get; set; }
        public string FirstGenre { get; set; }
        public string FirstComposer { get; set; }
        public string Grouping { get; set; }
        public string Track { get; set; }
        public string Format { get; set; }
        public string TotalTime { get; set; }
        public string Comments { get; set; }
        public string Lyrics { get; set; }
        public int? Disc { get; set; }
        public int? Year { get; set; }
        public DateTime? LastWriteUTC { get; set; }
        public DateTime? AddedDate { get; set; }
        public bool IsStream { get; set; }

        public object ParseFromText(string itemText, bool isStream)
        {
            var obj = new AudioFile {IsStream = isStream};

            var properties = obj.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public)
                    .Where(ø => ø.CanRead && ø.CanWrite)
                    .Where(ø => ø.GetSetMethod(true).IsPublic).ToList();

            var itemProperties = itemText.Split('\n');

            // Parse properties
            foreach (var property in properties.Where(property => itemText.Contains(property.Name)))
            {
                var propertyValue = itemProperties.First(p => p.Trim().StartsWith(property.Name)).Split('|')[1].Replace("\r", string.Empty);
                // Parse string properties
                if(property.PropertyType == typeof(string))
                {
                    property.SetValue(obj, propertyValue, null);

                    continue;
                }

                // Parse datetime properties
                if (property.PropertyType == typeof(DateTime?))
                {
                    DateTime dValue;
                    DateTime.TryParse(propertyValue, out dValue);
                    if (dValue != DateTime.MinValue)
                        property.SetValue(obj, dValue, null);

                    continue;
                }

                // Parse integer properties
                if(property.PropertyType == typeof(int?))
                {
                    int iValue;
                    int.TryParse(propertyValue, out iValue);
                    if(iValue != 0)
                        property.SetValue(obj, iValue, null);
                }
            }
            return obj;
        }
    }
}
Here my updated LoadPlaylist method which load any class objects out of my playlist format:
Code:
public void LoadPlaylist(Type type, string file, bool isStream = false)
        {
            if(!File.Exists(file)) return;
            var fileText = File.ReadAllText(file);
            //Set internal name of the file
            Name = fileText.Split(new[] { "InternalName|" }, StringSplitOptions.None)[1].Split('\n')[0].Trim();
            var items = Regex.Split(fileText, ITEMBEGIN);
            if (!items.Any()) return;
            for (var i = 1; i < items.Count(); i++)
            {
                var obj = Activator.CreateInstance(type) as IParsable;
                if (obj == null) continue;
                AddNewItem(obj.ParseFromText(items[i], isStream));
            }
        }
Last but not least the write method to write any class object to my list format:
Code:
/// <summary>
        /// Save the current playlist to the determined path
        /// </summary>
        public void SavePlaylist()
        {
            var sBuilder = new StringBuilder();
            //Create file text header which contains the internal name of the playlist
            sBuilder.AppendLine(string.Format("InternalName|{0}", Name));
            sBuilder.AppendLine(string.Format("InternalGuid|{0}", InternalGuid));
            sBuilder.AppendLine(ITEMLISTBEGIN);
            foreach (var file in Files)
            {
                sBuilder.AppendLine(string.Format("\t{0}", ITEMBEGIN));
                var properties = file.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public)
                                                                    .Where(ø => ø.CanRead && ø.CanWrite)
                                                                    .Where(ø => ø.GetSetMethod(true).IsPublic);

                foreach (var property in properties)
                {
                    var value = property.GetValue(file, null);
                    sBuilder.AppendLine(string.Format("\t\t{0}|{1}", property.Name, value ?? string.Empty));
                }
                sBuilder.AppendLine(string.Format("\t{0}", ITEMEND));
            }
            sBuilder.AppendLine(ITEMLISTEND);

            File.WriteAllText(string.Format(@"{0}\Playlists\Custom\{2}\{1}.@cl", AppDomain.CurrentDomain.BaseDirectory, InternalGuid, WorkingFolder), sBuilder.ToString());
        }
Here a Playlist sample so that you can see the result of the code above:
Code:
InternalName|Joel music
InternalGuid|ab1abd5b-d756-477d-ba5c-0007cb189119
<Plalist>
	<Item>
		File|D:\Albums\Various\Naul - 바람기억.mp3
		ImageUrl|
		Path|D:\Albums\Various
		Title|Naul - 바람기억
		Artist|
		Album|Various
		AlbumArtist|
		FirstGenre|
		FirstComposer|
		Grouping|
		Track|Track 1
		Format|MP3
		TotalTime|05:08
		Comments|
		Lyrics|
		Disc|
		Year|
		LastWriteUTC|23.10.2012 21:35:05
		AddedDate|29.10.2012 19:05:03
		IsStream|False
		DefaultCase|file:///C:/Users/aruantec/Documents/AES_GrayMoon/AES_GrayMoon/bin/Release//Data/GUI/case.png
		HomeCommand|AES_ViewModelHandler.ViewModelHandling.DelegateCommand
	</Item>
	<Item>
		File|D:\Albums\Various\Kc And Jojo - All My Life.mp3
		DefaultCase|file:///C:/Users/aruantec/Documents/AES_GrayMoon/AES_GrayMoon/bin/Release//Data/GUI/case.png
		Track|Track 1
		Title|All My Life
		Album|Various
		TotalTime|05:14
		Format|MP3
		ImageUrl|
		Path|D:\Albums\Various
		Artist|
		AlbumArtist|K-Ci & JoJo
		FirstGenre|Other
		FirstComposer|
		Grouping|
		Comments|
		Lyrics|
		Disc|
		Year|
		LastWriteUTC|04.10.2012 19:33:58
		AddedDate|17.10.2012 22:14:20
		IsStream|False
		HomeCommand|AES_ViewModelHandler.ViewModelHandling.DelegateCommand
	</Item>
	<Item>
		File|D:\Albums\1999 - Millennium\1999 - Millennium\07 - Don't Wanna Lose You Now.flac
		DefaultCase|file:///C:/Users/aruantec/Documents/AES_GrayMoon/AES_GrayMoon/bin/Release//Data/GUI/case.png
		Track|Track 7
		Title|Don't Wanna Lose You Now
		Album|Millennium
		TotalTime|03:55
		Format|FLAC
		ImageUrl|
		Path|D:\Albums\1999 - Millennium\1999 - Millennium
		Artist|Backstreet Boys
		AlbumArtist|
		FirstGenre|Pop
		FirstComposer|
		Grouping|
		Comments|
		Lyrics|
		Disc|
		Year|1999
		LastWriteUTC|09.05.2011 19:35:40
		AddedDate|11.09.2012 12:31:14
		IsStream|False
		HomeCommand|AES_ViewModelHandler.ViewModelHandling.DelegateCommand
	</Item>
	<Item>
		File|D:\Albums\Boys Over Flower\Boys Over Flowers CD2\A'ST1 - 아쉬운 마음인 걸.mp3
		DefaultCase|file:///C:/Users/aruantec/Documents/AES_GrayMoon/AES_GrayMoon/bin/Release//Data/GUI/case.png
		Track|Track 2
		Title|아쉬운 마음인 걸
		Album|꽃보다 남자 OST (II)�
		TotalTime|03:05
		Format|MP3
		ImageUrl|
		Path|D:\Albums\Boys Over Flower\Boys Over Flowers CD2
		Artist|A'ST1
		AlbumArtist|
		FirstGenre|148
		FirstComposer|
		Grouping|
		Comments|
		Lyrics|
		Disc|1
		Year|2009
		LastWriteUTC|04.08.2010 21:35:16
		AddedDate|11.09.2012 12:31:35
		IsStream|False
		HomeCommand|AES_ViewModelHandler.ViewModelHandling.DelegateCommand
	</Item>
	<Item>
		File|D:\Albums\Shinee\SHINee - The First Album Repackage (AMIGO)\05 Replay.mp3
		DefaultCase|file:///C:/Users/aruantec/Documents/AES_GrayMoon/AES_GrayMoon/bin/Release//Data/GUI/case.png
		Track|Track 5
		Title|누난 너무 예뻐 (Replay)
		Album|SHINee The First Album[Repackage] 아.미.고(AMIGO)
		TotalTime|03:34
		Format|MP3
		ImageUrl|
		Path|D:\Albums\Shinee\SHINee - The First Album Repackage (AMIGO)
		Artist|샤이니
		AlbumArtist|샤이니(SHINee)
		FirstGenre|댄스
		FirstComposer|
		Grouping|
		Comments|
		Lyrics|
		Disc|
		Year|2008
		LastWriteUTC|10.12.2009 20:12:46
		AddedDate|11.09.2012 12:32:23
		IsStream|False
		HomeCommand|AES_ViewModelHandler.ViewModelHandling.DelegateCommand
	</Item>
	<Item>
		File|D:\Albums\Shinee\SHINee - The First Album Repackage (AMIGO)\08 One For Me.mp3
		DefaultCase|file:///C:/Users/aruantec/Documents/AES_GrayMoon/AES_GrayMoon/bin/Release//Data/GUI/case.png
		Track|Track 8
		Title|그녀가 헤어졌다 (One for me)
		Album|SHINee The First Album[Repackage] 아.미.고(AMIGO)
		TotalTime|03:26
		Format|MP3
		ImageUrl|
		Path|D:\Albums\Shinee\SHINee - The First Album Repackage (AMIGO)
		Artist|샤이니
		AlbumArtist|샤이니(SHINee)
		FirstGenre|Pop
		FirstComposer|
		Grouping|
		Comments|
		Lyrics|
		Disc|
		Year|2008
		LastWriteUTC|15.10.2011 21:15:18
		AddedDate|11.09.2012 12:32:23
		IsStream|False
		HomeCommand|AES_ViewModelHandler.ViewModelHandling.DelegateCommand
	</Item>
	<Item>
		File|D:\Albums\SS501\05 Stand By Me (iHoneyJoo.com).mp3
		DefaultCase|file:///C:/Users/aruantec/Documents/AES_GrayMoon/AES_GrayMoon/bin/Release//Data/GUI/case.png
		Track|Track 5
		Title|Stand By Me
		Album|Vol.1 - S.T 01 NOW
		TotalTime|03:26
		Format|MP3
		ImageUrl|
		Path|D:\Albums\SS501
		Artist|SS501
		AlbumArtist|SS501
		FirstGenre|KPop
		FirstComposer|
		Grouping|
		Comments|
		Lyrics|
		Disc|
		Year|2006
		LastWriteUTC|04.04.2011 20:08:31
		AddedDate|11.09.2012 12:32:25
		IsStream|False
		HomeCommand|AES_ViewModelHandler.ViewModelHandling.DelegateCommand
	</Item>
	<Item>
		File|D:\Albums\SS501\10 Confession (Clumsy Proposal) (iHoneyJoo.com).mp3
		DefaultCase|file:///C:/Users/aruantec/Documents/AES_GrayMoon/AES_GrayMoon/bin/Release//Data/GUI/case.png
		Track|Track 10
		Title|Confession (Clumsy Proposal)
		Album|Vol.1 - S.T 01 NOW
		TotalTime|03:50
		Format|MP3
		ImageUrl|
		Path|D:\Albums\SS501
		Artist|SS501
		AlbumArtist|SS501
		FirstGenre|KPop
		FirstComposer|
		Grouping|
		Comments|
		Lyrics|
		Disc|
		Year|2006
		LastWriteUTC|04.04.2011 20:08:32
		AddedDate|11.09.2012 12:32:26
		IsStream|False
		HomeCommand|AES_ViewModelHandler.ViewModelHandling.DelegateCommand
	</Item>
	<Item>
		File|D:\Albums\You're Beautiful OST\01 여전히.mp3
		DefaultCase|file:///C:/Users/aruantec/Documents/AES_GrayMoon/AES_GrayMoon/bin/Release//Data/GUI/case.png
		Track|Track 1
		Title|여전히
		Album|미남이시네요 OST
		TotalTime|03:48
		Format|MP3
		ImageUrl|
		Path|D:\Albums\You're Beautiful OST
		Artist|이홍기
		AlbumArtist|Various
		FirstGenre|Other
		FirstComposer|
		Grouping|
		Comments|
		Lyrics|
		Disc|
		Year|2009
		LastWriteUTC|14.10.2009 11:33:08
		AddedDate|11.09.2012 12:32:32
		IsStream|False
		HomeCommand|AES_ViewModelHandler.ViewModelHandling.DelegateCommand
	</Item>
	<Item>
		File|D:\Albums\You're Beautiful OST\11 여전히 - Ver.Bossa .mp3
		DefaultCase|file:///C:/Users/aruantec/Documents/AES_GrayMoon/AES_GrayMoon/bin/Release//Data/GUI/case.png
		Track|Track 11
		Title|여전히 - Ver.Bossa
		Album|미남이시네요 OST
		TotalTime|02:08
		Format|MP3
		ImageUrl|
		Path|D:\Albums\You're Beautiful OST
		Artist|Various
		AlbumArtist|Various
		FirstGenre|Other
		FirstComposer|
		Grouping|
		Comments|
		Lyrics|
		Disc|
		Year|2009
		LastWriteUTC|14.10.2009 11:37:54
		AddedDate|11.09.2012 12:32:32
		IsStream|False
		HomeCommand|AES_ViewModelHandler.ViewModelHandling.DelegateCommand
	</Item>
	<Item>
		File|D:\Albums\Wednesday_Happy Train New Artist Project Vol. 001\03 니가 아닌데 (Vocal 한국 of Wednesday).mp3
		DefaultCase|file:///C:/Users/aruantec/Documents/AES_GrayMoon/AES_GrayMoon/bin/Release//Data/GUI/case.png
		Track|Track 3
		Title|니가 아닌데 (Vocal 한국 of Wednesday) �
		Album|HAPPY TRAIN New Artist Project Vol. 001
		TotalTime|03:14
		Format|MP3
		ImageUrl|
		Path|D:\Albums\Wednesday_Happy Train New Artist Project Vol. 001
		Artist|웬즈데이(Wednesday�
		AlbumArtist|
		FirstGenre|Other
		FirstComposer|
		Grouping|
		Comments|
		Lyrics|
		Disc|
		Year|2010
		LastWriteUTC|04.02.2011 10:51:03
		AddedDate|11.09.2012 12:32:30
		IsStream|False
		HomeCommand|AES_ViewModelHandler.ViewModelHandling.DelegateCommand
	</Item>
</Plalist>
Awesome isn't? i can read/write/create classes on the fly without knowing what's there properties in a playlist no matter what type of object it is. In this way i can handle playlists for Audio, Video, Custom list, Emulators, Settings or every single class i create dynamically in my code.
__________________


Current development tools:

Visual C++.net, Visual C#.net
Visual VB.net, Visual Webdeveloper.net
Bloodshed Dev C++, Borland C++
Visual Basic 6

Last edited by @ruantec; December 11th, 2012 at 11:18..
@ruantec is online now   Reply With Quote
Old December 11th, 2012, 04:07   #354
raksmey1309
បងស្រលាញ់អូន!
 
raksmey1309's Avatar
 
Join Date: Jul 2005
Location: ព្រះរាជាណាចក្រកម្ពុជា
Posts: 4,107
+1
__________________
I am the keyblade that, hopefully, will unlock your heart someday.

Proud to be Asian, proud to be Cambodian.
CPU: intel Core i7 3770 - GPU: nVidia GTX 660
M/B: Asrock Extreme 4M - RAM: DDR3 8GB bus 1600 MHz
HDD: 3TB SATA 3 7200rpm - Windows 7 64bits SP1
raksmey1309 is offline   Reply With Quote
Old December 20th, 2012, 04:13   #355
haxatax
Registered User
 
haxatax's Avatar
 
Join Date: Oct 2012
Posts: 169
Code:
SECTION .text
global  _GetUnpackerSize
global  _GetUnpackerPointer
 _GetUnpackerSize:
    mov eax, unpacker_end - unpacker_start
    ret
_GetUnpackerPointer:
    mov eax, unpacker_start
	ret

unpacker_start:
push ebp
mov ebp,esp
sub esp,30h ; <- Allocating local variable space

pushad ; <- Save our registers onto the stack

xor eax,eax
inc eax
mov edi,[ebp+10h] ; <- Function accessing parameter (pvWorkMem)
mov [ebp-14h],eax ; <- Function zeroing local variable
mov [ebp-1Ch],eax ; <- Etc...
mov [ebp-18h],eax
mov [ebp-28h],eax
mov eax,400h
xor edx,edx
mov ecx,30736h
rep stosd
mov eax,[ebp+0Ch]
push 5
mov [ebp-8],eax
mov [ebp-10h],edx
mov [ebp-1],dl
mov [ebp-0Ch],edx
mov [ebp+0Ch],edx
or eax,0FFFFFFFFh
pop ecx
@loc_401041:
mov esi,[ebp-8]
mov edx,[ebp+0Ch]
movzx esi,byte[esi]
shl edx,8
or edx,esi
inc dword[ebp-8]
dec ecx
mov [ebp+0Ch],edx
jnz @loc_401041
@loc_401058:
mov esi,[ebp-10h]
mov ecx,[ebp-0Ch]
mov edx,[ebp+10h]
and esi,3
shl ecx,4
add ecx,esi
cmp eax,1000000h
lea edi,[edx+ecx*4]
jnb @loc_40108A
mov edx,[ebp-8]
mov ecx,[ebp+0Ch]
movzx edx,byte[edx]
shl ecx,8
or ecx,edx
shl eax,8
inc dword[ebp-8]
mov [ebp+0Ch],ecx
@loc_40108A:
mov ecx,[edi]
mov ebx,eax
shr ebx,0Bh
imul ebx,ecx
cmp [ebp+0Ch],ebx
jnb @loc_401207
mov esi,800h
sub esi,ecx
shr esi,5
add esi,ecx
movzx ecx,byte[ebp-1]
imul ecx,0C00h
xor edx,edx
mov [edi],esi
mov esi,[ebp+10h]
inc edx
cmp dword[ebp-0Ch],7
lea ecx,[ecx+esi+1CD8h]
mov eax,ebx
mov [ebp-20h],ecx
jl @loc_401170
mov ecx,[ebp-10h]
sub ecx,[ebp-14h]
mov esi,[ebp+8]
movzx ecx,byte[ecx+esi]
mov [ebp-24h],ecx
@loc_4010E1:
shl dword[ebp-24h],1
mov esi,[ebp-24h]
mov edi,[ebp-20h]
and esi,100h
cmp eax,1000000h
lea ecx,[esi+edx]
lea ecx,[edi+ecx*4+400h]
mov [ebp-2Ch],ecx
jnb @loc_40111B
mov ebx,[ebp-8]
mov edi,[ebp+0Ch]
movzx ebx,byte[ebx]
shl edi,8
or edi,ebx
shl eax,8
inc dword[ebp-8]
mov [ebp+0Ch],edi
@loc_40111B:
mov ecx,[ecx]
mov edi,eax
shr edi,0Bh
imul edi,ecx
cmp [ebp+0Ch],edi
jnb @loc_401149
mov eax,edi
mov edi,800h
sub edi,ecx
shr edi,5
add edi,ecx
mov ecx,[ebp-2Ch]
add edx,edx
test esi,esi
mov [ecx],edi
jnz @loc_4011C9
jmp @loc_401162
@loc_401149:
sub [ebp+0Ch],edi
sub eax,edi
mov edi,ecx
shr edi,5
sub ecx,edi
test esi,esi
mov edi,[ebp-2Ch]
mov [edi],ecx
lea edx,[edx+edx+1]
jz @loc_4011C9
@loc_401162:
cmp edx,100h
jl @loc_4010E1
jmp @loc_4011D1
@loc_401170:
cmp eax,1000000h
mov ecx,[ebp-20h]
lea edi,[ecx+edx*4]
jnb @loc_401194
mov esi,[ebp-8]
mov ecx,[ebp+0Ch]
movzx esi,byte[esi]
shl ecx,8
or ecx,esi
shl eax,8
inc dword[ebp-8]
mov [ebp+0Ch],ecx
@loc_401194:
mov ecx,[edi]
mov esi,eax
shr esi,0Bh
imul esi,ecx
cmp [ebp+0Ch],esi
jnb @loc_4011B7
mov eax,esi
mov esi,800h
sub esi,ecx
shr esi,5
add esi,ecx
mov [edi],esi
add edx,edx
jmp @loc_4011C9
@loc_4011B7:
sub [ebp+0Ch],esi
sub eax,esi
mov esi,ecx
shr esi,5
sub ecx,esi
mov [edi],ecx
lea edx,[edx+edx+1]
@loc_4011C9:
cmp edx,100h
jl @loc_401170
@loc_4011D1:
mov esi,[ebp-10h]
mov ecx,[ebp+8]
inc dword[ebp-10h]
cmp dword[ebp-0Ch],4
mov [ebp-1],dl
mov [esi+ecx],dl
jge @loc_4011EF
and dword[ebp-0Ch],0
jmp @loc_401058
@loc_4011EF:
cmp dword[ebp-0Ch],0Ah
jge @loc_4011FE
sub dword[ebp-0Ch],3
jmp @loc_401058
@loc_4011FE:
sub dword[ebp-0Ch],6
jmp @loc_401058
@loc_401207:
sub [ebp+0Ch],ebx
mov edx,ecx
shr edx,5
sub ecx,edx
mov edx,[ebp-0Ch]
sub eax,ebx
cmp eax,1000000h
mov [edi],ecx
mov ecx,[ebp+10h]
lea edx,[ecx+edx*4+300h]
jnb @loc_401240
mov edi,[ebp-8]
mov ecx,[ebp+0Ch]
movzx edi,byte[edi]
shl ecx,8
or ecx,edi
shl eax,8
inc dword[ebp-8]
mov [ebp+0Ch],ecx
@loc_401240:
mov ecx,[edx]
mov edi,eax
shr edi,0Bh
imul edi,ecx
cmp [ebp+0Ch],edi
jnb @loc_401292
mov eax,edi
mov edi,800h
sub edi,ecx
shr edi,5
add edi,ecx
cmp dword[ebp-0Ch],7
mov ecx,[ebp-18h]
mov [ebp-28h],ecx
mov ecx,[ebp-1Ch]
mov [ebp-18h],ecx
mov ecx,[ebp-14h]
mov [edx],edi
mov [ebp-1Ch],ecx
jge @loc_40127D
and dword[ebp-0Ch],0
jmp @loc_401284
@loc_40127D:
mov dword[ebp-0Ch],3
@loc_401284:
mov ecx,[ebp+10h]
add ecx,0CC8h
jmp @loc_40147B
@loc_401292:
sub [ebp+0Ch],edi
sub eax,edi
mov edi,ecx
shr edi,5
sub ecx,edi
cmp eax,1000000h
mov [edx],ecx
mov ecx,[ebp-0Ch]
mov edx,[ebp+10h]
lea edi,[edx+ecx*4+330h]
jnb @loc_4012CB
mov edx,[ebp-8]
mov ecx,[ebp+0Ch]
movzx edx,byte[edx]
shl ecx,8
or ecx,edx
shl eax,8
inc dword[ebp-8]
mov [ebp+0Ch],ecx
@loc_4012CB:
mov ecx,[edi]
mov edx,eax
shr edx,0Bh
imul edx,ecx
cmp [ebp+0Ch],edx
jnb @loc_40137F
mov ebx,800h
sub ebx,ecx
shr ebx,5
add ebx,ecx
mov ecx,[ebp-0Ch]
add ecx,0Fh
shl ecx,4
mov [edi],ebx
mov edi,[ebp+10h]
add ecx,esi
cmp edx,1000000h
mov eax,edx
lea edi,[edi+ecx*4]
jnb @loc_401320
mov ecx,[ebp+0Ch]
shl edx,8
mov eax,edx
mov edx,[ebp-8]
movzx edx,byte[edx]
shl ecx,8
or ecx,edx
inc dword[ebp-8]
mov [ebp+0Ch],ecx
@loc_401320:
mov ecx,[edi]
mov edx,eax
shr edx,0Bh
imul edx,ecx
cmp [ebp+0Ch],edx
jnb @loc_40136C
mov esi,[ebp-10h]
mov eax,edx
mov edx,800h
sub edx,ecx
shr edx,5
add edx,ecx
xor ecx,ecx
cmp dword[ebp-0Ch],7
mov [edi],edx
mov edx,[ebp+8]
setnl cl
lea ecx,[ecx+ecx+9]
mov [ebp-0Ch],ecx
mov ecx,[ebp-10h]
sub ecx,[ebp-14h]
inc dword[ebp-10h]
mov cl,[ecx+edx]
mov [ebp-1],cl
mov [esi+edx],cl
jmp @loc_401058
@loc_40136C:
sub [ebp+0Ch],edx
sub eax,edx
mov edx,ecx
shr edx,5
sub ecx,edx
mov [edi],ecx
jmp @loc_40145F
@loc_40137F:
sub [ebp+0Ch],edx
sub eax,edx
mov edx,ecx
shr edx,5
sub ecx,edx
cmp eax,1000000h
mov edx,[ebp+10h]
mov [edi],ecx
mov ecx,[ebp-0Ch]
lea edx,[edx+ecx*4+360h]
jnb @loc_4013B8
mov edi,[ebp-8]
mov ecx,[ebp+0Ch]
movzx edi,byte[edi]
shl ecx,8
or ecx,edi
shl eax,8
inc dword[ebp-8]
mov [ebp+0Ch],ecx
@loc_4013B8:
mov ecx,[edx]
mov edi,eax
shr edi,0Bh
imul edi,ecx
cmp [ebp+0Ch],edi
jnb @loc_4013DC
mov eax,edi
mov edi,800h
sub edi,ecx
shr edi,5
add edi,ecx
mov ecx,[ebp-1Ch]
mov [edx],edi
jmp @loc_401456
@loc_4013DC:
sub [ebp+0Ch],edi
sub eax,edi
mov edi,ecx
shr edi,5
sub ecx,edi
cmp eax,1000000h
mov [edx],ecx
mov ecx,[ebp-0Ch]
mov edx,[ebp+10h]
lea edx,[edx+ecx*4+390h]
jnb @loc_401415
mov edi,[ebp-8]
mov ecx,[ebp+0Ch]
movzx edi,byte[edi]
shl ecx,8
or ecx,edi
shl eax,8
inc dword[ebp-8]
mov [ebp+0Ch],ecx
@loc_401415:
mov ecx,[edx]
mov edi,eax
shr edi,0Bh
imul edi,ecx
cmp [ebp+0Ch],edi
jnb @loc_401439
mov eax,edi
mov edi,800h
sub edi,ecx
shr edi,5
add edi,ecx
mov ecx,[ebp-18h]
mov [edx],edi
jmp @loc_401450
@loc_401439:
sub [ebp+0Ch],edi
sub eax,edi
mov edi,ecx
shr edi,5
sub ecx,edi
mov [edx],ecx
mov edx,[ebp-18h]
mov ecx,[ebp-28h]
mov [ebp-28h],edx
@loc_401450:
mov edx,[ebp-1Ch]
mov [ebp-18h],edx
@loc_401456:
mov edx,[ebp-14h]
mov [ebp-1Ch],edx
mov [ebp-14h],ecx
@loc_40145F:
xor ecx,ecx
cmp dword[ebp-0Ch],7
setnl cl
dec ecx
and ecx,0FFFFFFFDh
add ecx,0Bh
mov [ebp-0Ch],ecx
mov ecx,[ebp+10h]
add ecx,14D0h
@loc_40147B:
cmp eax,1000000h
jnb @loc_401499
mov edi,[ebp-8]
mov edx,[ebp+0Ch]
movzx edi,byte[edi]
shl edx,8
or edx,edi
shl eax,8
inc dword[ebp-8]
mov [ebp+0Ch],edx
@loc_401499:
mov edx,[ecx]
mov edi,eax
shr edi,0Bh
imul edi,edx
cmp [ebp+0Ch],edi
jnb @loc_4014C5
mov eax,edi
mov edi,800h
sub edi,edx
shr edi,5
add edi,edx
shl esi,5
and dword[ebp-24h],0
mov [ecx],edi
lea ecx,[esi+ecx+8]
jmp @loc_401523
@loc_4014C5:
sub [ebp+0Ch],edi
sub eax,edi
mov edi,edx
shr edi,5
sub edx,edi
cmp eax,1000000h
mov [ecx],edx
jnb @loc_4014F1
mov edi,[ebp-8]
mov edx,[ebp+0Ch]
movzx edi,byte[edi]
shl edx,8
or edx,edi
shl eax,8
inc dword[ebp-8]
mov [ebp+0Ch],edx
@loc_4014F1:
mov edx,[ecx+4]
mov edi,eax
shr edi,0Bh
imul edi,edx
cmp [ebp+0Ch],edi
jnb @loc_40152C
mov eax,edi
mov edi,800h
sub edi,edx
shr edi,5
add edi,edx
shl esi,5
mov [ecx+4],edi
lea ecx,[esi+ecx+208h]
mov dword[ebp-24h],8
@loc_401523:
mov dword[ebp-20h],3
jmp @loc_40154F
@loc_40152C:
sub [ebp+0Ch],edi
mov esi,edx
shr esi,5
sub edx,esi
sub eax,edi
mov [ecx+4],edx
add ecx,408h
mov dword[ebp-24h],10h
mov dword[ebp-20h],8
@loc_40154F:
mov edx,[ebp-20h]
xor ebx,ebx
mov [ebp-2Ch],edx
inc ebx
@loc_401558:
cmp eax,1000000h
jnb @loc_401576
mov esi,[ebp-8]
mov edx,[ebp+0Ch]
movzx esi,byte[esi]
shl edx,8
or edx,esi
shl eax,8
inc dword[ebp-8]
mov [ebp+0Ch],edx
@loc_401576:
mov edx,[ecx+ebx*4]
mov esi,eax
shr esi,0Bh
imul esi,edx
cmp [ebp+0Ch],esi
jnb @loc_40159B
mov eax,esi
mov esi,800h
sub esi,edx
shr esi,5
add esi,edx
mov [ecx+ebx*4],esi
add ebx,ebx
jmp @loc_4015AE
@loc_40159B:
sub [ebp+0Ch],esi
sub eax,esi
mov esi,edx
shr esi,5
sub edx,esi
mov [ecx+ebx*4],edx
lea ebx,[ebx+ebx+1]
@loc_4015AE:
dec dword[ebp-2Ch]
jnz @loc_401558
mov ecx,[ebp-20h]
xor edx,edx
inc edx
mov esi,edx
shl esi,cl
mov ecx,[ebp-24h]
sub ecx,esi
add ebx,ecx
cmp dword[ebp-0Ch],4
mov [ebp-30h],ebx
jge @loc_401765
add dword[ebp-0Ch],7
cmp ebx,4
jge @loc_4015DE
mov ecx,ebx
jmp @loc_4015E1
@loc_4015DE:
push 3
pop ecx
@loc_4015E1:
mov esi,[ebp+10h]
shl ecx,8
lea edi,[ecx+esi+6C0h]
mov dword[ebp-2Ch],6
@loc_4015F5:
cmp eax,1000000h
jnb @loc_401613
mov esi,[ebp-8]
mov ecx,[ebp+0Ch]
movzx esi,byte[esi]
shl ecx,8
or ecx,esi
shl eax,8
inc dword[ebp-8]
mov [ebp+0Ch],ecx
@loc_401613:
mov ecx,[edi+edx*4]
mov esi,eax
shr esi,0Bh
imul esi,ecx
cmp [ebp+0Ch],esi
jnb @loc_401638
mov eax,esi
mov esi,800h
sub esi,ecx
shr esi,5
add esi,ecx
mov [edi+edx*4],esi
add edx,edx
jmp @loc_40164B
@loc_401638:
sub [ebp+0Ch],esi
sub eax,esi
mov esi,ecx
shr esi,5
sub ecx,esi
mov [edi+edx*4],ecx
lea edx,[edx+edx+1]
@loc_40164B:
dec dword[ebp-2Ch]
jnz @loc_4015F5
sub edx,40h
cmp edx,4
mov edi,edx
jl @loc_401736
mov ecx,edx
sar ecx,1
and edi,1
dec ecx
or edi,2
cmp edx,0Eh
mov [ebp-14h],ecx
jge @loc_401683
shl edi,cl
mov ecx,edi
sub ecx,edx
mov edx,[ebp+10h]
lea ebx,[edx+ecx*4+0ABCh]
jmp @loc_4016C9
@loc_401683:
sub ecx,4
@loc_401686:
cmp eax,1000000h
jnb @loc_4016A4
mov esi,[ebp-8]
mov edx,[ebp+0Ch]
movzx esi,byte[esi]
shl edx,8
or edx,esi
shl eax,8
inc dword[ebp-8]
mov [ebp+0Ch],edx
@loc_4016A4:
shr eax,1
add edi,edi
cmp [ebp+0Ch],eax
jb @loc_4016B3
sub [ebp+0Ch],eax
or edi,1
@loc_4016B3:
dec ecx
jnz @loc_401686
mov ebx,[ebp+10h]
add ebx,0C88h
shl edi,4
mov dword[ebp-14h],4
@loc_4016C9:
xor ecx,ecx
inc ecx
mov [ebp-20h],ebx
mov [ebp-24h],ecx
@loc_4016D2:
cmp eax,1000000h
jnb @loc_4016F0
mov esi,[ebp-8]
mov edx,[ebp+0Ch]
movzx esi,byte[esi]
shl edx,8
or edx,esi
shl eax,8
inc dword[ebp-8]
mov [ebp+0Ch],edx
@loc_4016F0:
mov edx,[ebx+ecx*4]
mov esi,eax
shr esi,0Bh
imul esi,edx
cmp [ebp+0Ch],esi
jnb @loc_401715
mov eax,esi
mov esi,800h
sub esi,edx
shr esi,5
add esi,edx
mov [ebx+ecx*4],esi
add ecx,ecx
jmp @loc_40172E
@loc_401715:
sub [ebp+0Ch],esi
mov ebx,[ebp-20h]
sub eax,esi
mov esi,edx
shr esi,5
sub edx,esi
or edi,[ebp-24h]
mov [ebx+ecx*4],edx
lea ecx,[ecx+ecx+1]
@loc_40172E:
shl dword[ebp-24h],1
dec dword[ebp-14h]
jnz @loc_4016D2
@loc_401736:
inc edi
mov [ebp-14h],edi
jz @loc_40176A
mov ebx,[ebp-30h]
@loc_40173F:
mov ecx,[ebp-10h]
inc ebx
sub ecx,edi
inc ebx
add ecx,[ebp+8]
@loc_401749:
mov dl,[ecx]
mov esi,[ebp-10h]
mov edi,[ebp+8]
dec ebx
inc dword[ebp-10h]
inc ecx
test ebx,ebx
mov [ebp-1],dl
mov [esi+edi],dl
jnz @loc_401749
jmp @loc_401058
@loc_401765:
mov edi,[ebp-14h]
jmp @loc_40173F
@loc_40176A:
popad
mov eax,[ebp-10h]
leave
retn 0Ch
unpacker_end:
retn
LZMA depacker in x86 assembly. Used in my personal UPX replacement/DRM.
haxatax is offline   Reply With Quote
Old December 20th, 2012, 21:01   #356
-Ashe-
Registered User
 
-Ashe-'s Avatar
 
Join Date: Oct 2011
Posts: 189
Quite readable
-Ashe- is offline   Reply With Quote
Old December 21st, 2012, 08:38   #357
bram64
Registered User
 
Join Date: Dec 2003
Posts: 77
The lack of sensible labels makes me think this is disassembled code?
bram64 is offline   Reply With Quote
Old December 21st, 2012, 09:13   #358
haxatax
Registered User
 
haxatax's Avatar
 
Join Date: Oct 2012
Posts: 169
Yes, disassembled from a handcoded LZMA implementation in C then modded some more.
haxatax is offline   Reply With Quote
Old December 21st, 2012, 11:49   #359
blueshogun96
Last Xbox Emu Author
 
blueshogun96's Avatar
 
Join Date: Jun 2004
Location: Seattle, WA, USA
Posts: 5,843
A C-based linked list. Works rather well and always gets the job done for me.

linkedlist.h
Code:
#pragma once

#ifdef __cplusplus
extern "C" {
#endif

/* Linked list structure */
struct node_t
{
	void* data;
	struct node_t* next;
};

/* Add a node at the beginning of the list */
void list_add_beginning( struct node_t** head, void* data );
/* Add list node to the end */
void list_add_end( struct node_t** head, void* data );
/* Add a new node at a specific position */
void list_add_at( struct node_t** head, void* data, int loc );
/* Returns the number of elements in the list */
int list_length( struct node_t** head );
/* Delete a node from the list */
int list_delete( struct node_t** head, void* data );
/* Deletes a node from the given position */
int link_delete_loc( struct node_t** head, int loc );
/* Deletes every node in the list */
void list_clear( struct node_t** head );
/* Retrieve data from the selected node */
void* list_get_node_data( struct node_t** head, int loc );
/* Node deletion callback */
void set_deletion_callback( void (*func)(void*) );

#ifdef __cplusplus
}
#endif
linkedlist.c
Code:
#include <stdio.h>
//#include <malloc.h>
#include "linkedlist.h"


/* linked list head */
//struct node_t* head = NULL;

/* Deletion callback function */
void (*delete_func)(void*);


/* Add a node at the beginning of the list */
void list_add_beginning( struct node_t** head, void* data )
{
	struct node_t* temp;

	temp = ( struct node_t* ) malloc( sizeof( struct node_t ) );
	temp->data = data;

	if( head == NULL )
	{
		(*head) = temp;
		(*head)->next = NULL;
	}
	else
	{
		temp->next = (*head);
		(*head) = temp;
	}
}

/* Add list node to the end */
void list_add_end( struct node_t** head, void* data )
{
	struct node_t* temp1;
	struct node_t* temp2;

	temp1 = (struct node_t*) malloc( sizeof( struct node_t ) );
	temp1->data = data;

	temp2 = (*head);

	if( (*head) == NULL )
	{
		(*head) = temp1;
		(*head)->next = NULL;
	}
	else
	{
		while( temp2->next != NULL )
			temp2 = temp2->next;

		temp1->next = NULL;
		temp2->next = temp1;
	}
}

/* Add a new node at a specific position */
void list_add_at( struct node_t** head, void* data, int loc )
{
	int i;
	struct node_t *temp, *prev_ptr, *cur_ptr;

	cur_ptr = (*head);

	if( loc > (list_length( head )+1) || loc <= 0 )
	{
	}
	else
	{
		if( loc == 1 )
		{
			list_add_beginning(head, data);
		}
		else
		{
			for( i = 1; i < loc; i++ )
			{
				prev_ptr = cur_ptr;
				cur_ptr = cur_ptr->next;
			}

			temp = (struct node_t*) malloc( sizeof( struct node_t ) );
			temp->data = data;

			prev_ptr->next = temp;
			temp->next = cur_ptr;
		}
	}
}


/* Returns the number of elements in the list */
int list_length( struct node_t** head )
{
	struct node_t* cur_ptr;
	int count= 0;

	cur_ptr = (*head);

	while( cur_ptr != NULL )
	{
		cur_ptr = cur_ptr->next;
		count++;
	}

	return count;
}


/* Delete a node from the list */
int list_delete( struct node_t** head, void* data )
{
	struct node_t *prev_ptr, *cur_ptr;

	cur_ptr = (*head);

	while( cur_ptr != NULL )
	{
		if( cur_ptr->data == data )
		{
			if( cur_ptr == (*head) )
			{
				(*head) = cur_ptr->next;
				if( delete_func ) delete_func( cur_ptr->data );
				free( cur_ptr );
				return 1;
			}
			else
			{
				prev_ptr->next = cur_ptr->next;
				if( delete_func ) delete_func( cur_ptr->data );
				free( cur_ptr );
				return 1;
			}
		}
		else
		{
			prev_ptr = cur_ptr;
			cur_ptr = cur_ptr->next;
		}
	}

	return 0;
}

/* Deletes a node from the given position */
int link_delete_loc( struct node_t** head, int loc )
{
	struct node_t *prev_ptr, *cur_ptr;
	int i;

	cur_ptr = (*head);

	if( loc > list_length( head ) || loc <= 0 )
	{
	}
	else
	{
		if( loc == 1 )
		{
			(*head) = cur_ptr->next;
			if( delete_func ) delete_func( cur_ptr->data );
			free(cur_ptr);
			return 1;
		}
		else
		{
			for( i = 1; i < loc; i++ )
			{
				prev_ptr = cur_ptr;
				cur_ptr = cur_ptr->next;
			}

			prev_ptr->next = cur_ptr->next;
			if( delete_func ) delete_func( cur_ptr->data );
			free(cur_ptr);
		}
	}

	return 0;
}

/* Deletes every node in the list */
void list_clear( struct node_t** head )
{
	struct node_t* cur_ptr, *temp;

	cur_ptr = (*head);

	while( cur_ptr )
	{
		temp = cur_ptr->next;
		if( delete_func ) delete_func( cur_ptr->data );
		free(cur_ptr);
		cur_ptr = temp;
	}
    
    (*head) = NULL;
}

/* Retrieve data from the selected node */
void* list_get_node_data( struct node_t** head, int loc )
{
	struct node_t* cur_ptr;
	int i = 1;

	cur_ptr = (*head);

	if( loc < 1 )
		return NULL;

	while( i < loc )
	{
		cur_ptr = cur_ptr->next;
		i++;
	}
    
    if( !cur_ptr )
        return NULL;
	
	return cur_ptr->data;
}
		
/* Node deletion callback */
void set_deletion_callback( void (*func)(void*) )
{
	delete_func = func;
}
Hopefully it becomes of use to someone out there.
__________________

Official Website of Shogun3D's RyuAwai!

Shogun3D Game Development Blog

Zengjük a Dalt: Manliest Song Ever!
blueshogun96 is offline   Reply With Quote
Old December 21st, 2012, 13:29   #360
-Ashe-
Registered User
 
-Ashe-'s Avatar
 
Join Date: Oct 2011
Posts: 189
You use 1-based indices?
-Ashe- is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT +1. The time now is 23:26.

© 2006 - 2012 Emu Forums | About Emu Forums | Advertisers | Investors | Legal | A member of the Crowdgather Forum Community


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.