elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: ¿Eres nuevo? ¿Tienes dudas acerca del funcionamiento de la comunidad? Lee las Reglas Generales


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  Leer una clase en un formulario Windows de Visual C#
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: 1 [2] 3 Ir Abajo Respuesta Imprimir
Autor Tema: Leer una clase en un formulario Windows de Visual C#  (Leído 12,673 veces)
Meta


Desconectado Desconectado

Mensajes: 3.439



Ver Perfil WWW
Re: Leer una clase en un formulario Widnows de Visual C#
« Respuesta #10 en: 10 Junio 2015, 14:13 pm »

Lo dejaré así mismo, me gusta.

Código
  1. textBox_Layout.Text = string.Format("0x{0}", VARIABLE.Layout);

Solo falta añadir los demás cuadros vacíos.


En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.817



Ver Perfil
Re: Leer una clase en un formulario Widnows de Visual C#
« Respuesta #11 en: 10 Junio 2015, 15:07 pm »

Lo dejaré así mismo, me gusta.

Código
  1. textBox_Layout.Text = string.Format("0x{0}", VARIABLE.Layout);

Pero eso que haces no tiene ningún sentido aunque te guste; "0x" es el prefijo estándar para un valor hexadecimal, pero la propiedad "Layout" devuelve un valor decimal entre 0 y 255, es decir, un Byte.

Si haces eso solo conseguirás mostrar resultados confusos en la UI.

Saludos!


« Última modificación: 10 Junio 2015, 15:09 pm por Eleкtro » En línea

Meta


Desconectado Desconectado

Mensajes: 3.439



Ver Perfil WWW
Re: Leer una clase en un formulario Windows de Visual C#
« Respuesta #12 en: 10 Junio 2015, 19:32 pm »

Haciendo pruebas o no me sale bien, algo se me escapa o C# no le gusta.

Código
  1. private void button1_Click(object sender, EventArgs e)
  2.        {
  3.  
  4.            if (openFileDialog1.ShowDialog() == DialogResult.OK)
  5.            {
  6.                SnesKit.RomDump VARIABLE = new SnesKit.RomDump(File.ReadAllBytes(openFileDialog1.FileName.ToString()));
  7.                textBox_Nombre_ruta_archivo.Text = openFileDialog1.FileName.ToString(); // Muestra la ruta del archivo.
  8.  
  9.                textBox_Name.Text = VARIABLE.Name;
  10.                //textBox_Layout.Text = string.Format("0x{0}", VARIABLE.Layout);
  11.                textBox_CartridgeType.Text = string.Format("0x{0}", VARIABLE.CartridgeType);
  12.                textBox_RomSize.Text = string.Format("0x{0}", VARIABLE.RomSize);
  13.                textBox_RamSize.Text = string.Format("0x{0}", VARIABLE.RamSize);
  14.                textBox_CountryCode.Text = string.Format("0x{0}", VARIABLE.CountryCode);
  15.                textBox_LicenseCode.Text = string.Format("0x{0}", VARIABLE.LicenseCode);
  16.                textBox_VersionNumber.Text = string.Format("0x{0}", VARIABLE.VersionNumber);
  17.                textBox_BankType.Text = VARIABLE.BankType.ToString();
  18.  
  19.  
  20.                  textBox_Layout.Text = string.Format("0x{0}", Convert.ToString(255, toBase:=16));
  21.  
  22.            }
  23.        }

Hay mucho errores.
Error   3   El término de la expresión ')' no es válido   C:\Users\Usuario\Documents\Visual Studio 2013\Projects\ROM_SNES\ROM_SNES\Form1.cs   41   96   ROM_SNES

Error   1   El término de la expresión '=' no es válido   C:\Users\Usuario\Documents\Visual Studio 2013\Projects\ROM_SNES\ROM_SNES\Form1.cs   41   93   ROM_SNES

Error   4   Se esperaba ;   C:\Users\Usuario\Documents\Visual Studio 2013\Projects\ROM_SNES\ROM_SNES\Form1.cs   41   96   ROM_SNES

Saludos.
En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.817



Ver Perfil
Re: Leer una clase en un formulario Windows de Visual C#
« Respuesta #13 en: 10 Junio 2015, 19:45 pm »

Te voy a hacer un regalito :P ...es cosa tuya traducirlo a C#, o compilar el código en una dll para no tener que traducir.

La SNES siempre me ha fascinado, bueno, tengo cierta melancolía y bastantes roms por ahí perdidas xD, en fin, me ha interesado el tema, he cogido la Class que publicaste al principio del tema, y la he extendido para mejorarla en varios aspectos, añadiendo mayor y mejor documentación, así cómo nuevas funcionalidades.



Cosas a tener en cuenta:

1. Me ha sido imposible descifrar los 13 códigos de paises que se pueden usar en una ROM de SNES, no encuentro información sobre esto en ningún lugar, solo encontré información parcial en la que se dice que '0' equivale a Japón, '1' a U.S., y bajo mis propias conclusiones '8' debe ser España.
Si alguien conoce esta información al completo, que me lo haga saber, gracias.

2. No he testeado mi Class con cientos de ROMs para comprobar que todo funciona cómo debería funcionar a las mil maravillas en todas las circunstancias posibles, pero supongo que si, ya que me he basado en las especificaciones de la cabecera de SNES, las cuales ya estaban implementados en la Class original de donde saqué la idea.
Si alguien encuentra algún error, que me lo comunique, gracias.



A continuación publico el código fuente, y abajo del todo unos ejemplos de lectura y escritura:

Código
  1. ' ***********************************************************************
  2. ' Author   : Elektro.
  3. '            Based on this 3rd party project:
  4. '            https://github.com/Zeokat/SNES-ROM-Header-Dumper-CSharp/blob/master/snes_dumper.cs
  5. ' Modified : 10-June-2015
  6. ' ***********************************************************************
  7. ' <copyright file="SnesRom.vb" company="Elektro Studios">
  8. '     Copyright (c) Elektro Studios. All rights reserved.
  9. ' </copyright>
  10. ' ***********************************************************************
  11.  
  12. #Region " Usage Examples "
  13.  
  14. ' CONTENIDO OMITIDO...
  15.  
  16. #End Region
  17.  
  18. #Region " Option Statements "
  19.  
  20. Option Strict On
  21. Option Explicit On
  22. Option Infer Off
  23.  
  24. #End Region
  25.  
  26. #Region " Imports "
  27.  
  28. Imports System.IO
  29. Imports System.Text
  30.  
  31. #End Region
  32.  
  33. Public NotInheritable Class SnesRom
  34.  
  35. #Region " Properties "
  36.  
  37.    ''' <summary>
  38.    ''' Gets the raw byte-data of the ROM file.
  39.    ''' </summary>
  40.    ''' <value>The raw byte-data of the ROM file.</value>
  41.    Public ReadOnly Property RawData As Byte()
  42.        Get
  43.            Return Me.rawDataB
  44.        End Get
  45.    End Property
  46.    ''' <summary>
  47.    ''' (backing field) The raw byte-data of the ROM file.
  48.    ''' </summary>
  49.    Private ReadOnly rawDataB As Byte()
  50.  
  51.    ''' <summary>
  52.    ''' Gets The ROM header type.
  53.    ''' </summary>
  54.    ''' <remarks>http://romhack.wikia.com/wiki/SMC_header</remarks>
  55.    ''' <value>The ROM header type.</value>
  56.    Public ReadOnly Property HeaderType As HeaderTypeEnum
  57.        Get
  58.            Return Me.headerTypeB
  59.        End Get
  60.    End Property
  61.    ''' <summary>
  62.    ''' (backing field) The ROM header type.
  63.    ''' </summary>
  64.    Private headerTypeB As HeaderTypeEnum
  65.  
  66.    ''' <summary>
  67.    ''' Gets the SNES header address location.
  68.    ''' </summary>
  69.    ''' <remarks>http://romhack.wikia.com/wiki/SNES_header</remarks>
  70.    ''' <value>The SNES header address location.</value>
  71.    Private ReadOnly Property HeaderLocation As Integer
  72.        Get
  73.            Return Me.headerLocationB
  74.        End Get
  75.    End Property
  76.    ''' <summary>
  77.    ''' (backing field) The SNES header address location.
  78.    ''' </summary>
  79.    Private headerLocationB As Integer = 33216
  80.  
  81.    ''' <summary>
  82.    ''' Gets or sets the name of the ROM, typically in ASCII.
  83.    ''' The name buffer consists in 21 characters.
  84.    ''' </summary>
  85.    ''' <remarks>http://romhack.wikia.com/wiki/SNES_header</remarks>
  86.    ''' <value>The name of the ROM.</value>
  87.    Public Property Name As String
  88.        Get
  89.            Return Me.nameB
  90.        End Get
  91.        Set(ByVal value As String)
  92.            Me.SetName(value)
  93.            Me.nameB = value
  94.        End Set
  95.    End Property
  96.    ''' <summary>
  97.    ''' (backing field) The name of the ROM.
  98.    ''' </summary>
  99.    Private nameB As String
  100.  
  101.    ''' <summary>
  102.    ''' Gets the ROM layout.
  103.    ''' The SNES ROM layout describes how the ROM banks appear in a ROM image and in the SNES address space.
  104.    ''' </summary>
  105.    ''' <remarks>http://romhack.wikia.com/wiki/SNES_ROM_layout</remarks>
  106.    ''' <value>The ROM layout.</value>
  107.    Public ReadOnly Property Layout As Byte
  108.        Get
  109.            Return Me.layoutB
  110.        End Get
  111.    End Property
  112.    ''' <summary>
  113.    ''' (backing field) The ROM layout.
  114.    ''' </summary>
  115.    Private layoutB As Byte
  116.  
  117.    ''' <summary>
  118.    ''' Gets the bank type.
  119.    ''' An image contains only LoROM banks or only HiROM banks, not both.
  120.    ''' </summary>
  121.    ''' <remarks>http://romhack.wikia.com/wiki/SNES_ROM_layout</remarks>
  122.    ''' <value>The bank type.</value>
  123.    Public ReadOnly Property BankType As BankTypeEnum
  124.        Get
  125.            Return Me.bankTypeB
  126.        End Get
  127.    End Property
  128.    ''' <summary>
  129.    ''' (backing field) The bank type.
  130.    ''' </summary>
  131.    Private bankTypeB As BankTypeEnum
  132.  
  133.    ''' <summary>
  134.    ''' Gets the cartrifge type, it can be a ROM only, or a ROM with save-RAM.
  135.    ''' </summary>
  136.    ''' <remarks>http://romhack.wikia.com/wiki/SNES_header</remarks>
  137.    ''' <value>The cartridge type.</value>
  138.    Public ReadOnly Property CartridgeType As CartridgeTypeEnum
  139.        Get
  140.            Return Me.cartridgeTypeB
  141.        End Get
  142.    End Property
  143.    ''' <summary>
  144.    ''' (backing field) The cartrifge type.
  145.    ''' </summary>
  146.    Private cartridgeTypeB As CartridgeTypeEnum
  147.  
  148.    ''' <summary>
  149.    ''' Gets the ROM size byte.
  150.    ''' </summary>
  151.    ''' <remarks>http://romhack.wikia.com/wiki/SNES_header</remarks>
  152.    ''' <value>The ROM size byte.</value>
  153.    Public ReadOnly Property RomSize As Byte
  154.        Get
  155.            Return Me.romSizeB
  156.        End Get
  157.    End Property
  158.    ''' <summary>
  159.    ''' (backing field) The ROM size byte.
  160.    ''' </summary>
  161.    Private romSizeB As Byte
  162.  
  163.    ''' <summary>
  164.    ''' Gets the RAM size byte.
  165.    ''' </summary>
  166.    ''' <remarks>http://romhack.wikia.com/wiki/SNES_header</remarks>
  167.    ''' <value>The RAM size byte.</value>
  168.    Public ReadOnly Property RamSize As Byte
  169.        Get
  170.            Return Me.ramSizeB
  171.        End Get
  172.    End Property
  173.    ''' <summary>
  174.    ''' (backing field) The ROM size byte.
  175.    ''' </summary>
  176.    Private ramSizeB As Byte
  177.  
  178.    ''' <summary>
  179.    ''' Gets or sets the country data.
  180.    ''' </summary>
  181.    ''' <remarks>http://romhack.wikia.com/wiki/SNES_header</remarks>
  182.    ''' <value>The country data.</value>
  183.    Public Property Country As CountryData
  184.        Get
  185.            Return New CountryData(Me.CountryCode)
  186.        End Get
  187.        Set(ByVal value As CountryData)
  188.            Me.SetByte(Me.startAddressCountryCode, value.Code)
  189.            Me.CountryCode = value.Code
  190.        End Set
  191.    End Property
  192.  
  193.    ''' <summary>
  194.    ''' The country code.
  195.    ''' </summary>
  196.    Private Property CountryCode As Byte
  197.  
  198.    ''' <summary>
  199.    ''' Gets or sets the license code.
  200.    ''' </summary>
  201.    ''' <remarks>http://romhack.wikia.com/wiki/SNES_header</remarks>
  202.    ''' <value>The license code.</value>
  203.    Public Property LicenseCode As Byte
  204.        Get
  205.            Return Me.licenseCodeB
  206.        End Get
  207.        Set(ByVal value As Byte)
  208.            Me.SetByte(Me.startAddressLicenseCode, value)
  209.            Me.licenseCodeB = value
  210.        End Set
  211.    End Property
  212.    ''' <summary>
  213.    ''' (backing field) The license code.
  214.    ''' </summary>
  215.    Private licenseCodeB As Byte
  216.  
  217.    ''' <summary>
  218.    ''' Gets or sets the version number.
  219.    ''' </summary>
  220.    ''' <remarks>http://romhack.wikia.com/wiki/SNES_header</remarks>
  221.    ''' <value>The version number.</value>
  222.    Public Property VersionNumber As Byte
  223.        Get
  224.            Return Me.versionNumberB
  225.        End Get
  226.        Set(ByVal value As Byte)
  227.            Me.SetByte(Me.startAddressVersionNumber, value)
  228.            Me.versionNumberB = value
  229.        End Set
  230.    End Property
  231.    ''' <summary>
  232.    ''' (backing field) The version number.
  233.    ''' </summary>
  234.    Private versionNumberB As Byte
  235.  
  236.    ''' <summary>
  237.    ''' Gets the checksum compliment.
  238.    ''' </summary>
  239.    ''' <remarks>http://romhack.wikia.com/wiki/SNES_header</remarks>
  240.    ''' <value>The checksum compliment.</value>
  241.    Public ReadOnly Property ChecksumCompliment As UShort
  242.        Get
  243.            Return Me.checksumComplimentB
  244.        End Get
  245.    End Property
  246.    ''' <summary>
  247.    ''' (backing field) The checksum compliment.
  248.    ''' </summary>
  249.    Private checksumComplimentB As UShort
  250.  
  251.    ''' <summary>
  252.    ''' Gets the checksum.
  253.    ''' </summary>
  254.    ''' <remarks>http://romhack.wikia.com/wiki/SNES_header</remarks>
  255.    ''' <value>The checksum.</value>
  256.    Public ReadOnly Property Checksum As UShort
  257.        Get
  258.            Return Me.checksumB
  259.        End Get
  260.    End Property
  261.    ''' <summary>
  262.    ''' (backing field) The checksum.
  263.    ''' </summary>
  264.    Private checksumB As UShort
  265.  
  266. #End Region
  267.  
  268. #Region " Header Addresses "
  269.  
  270.    ' ********************************************************************************************************************
  271.    ' NOTE:
  272.    ' The reason for the variables that are commented-out is just because are unused, but could be helpful in the future.
  273.    ' ********************************************************************************************************************
  274.  
  275.    ' ''' <summary>
  276.    ' ''' The start address of a Lo-ROM header.
  277.    ' ''' </summary>
  278.    'Private ReadOnly loRomHeaderAddress As UShort = 32704
  279.  
  280.    ' ''' <summary>
  281.    ' ''' The start address of a Hi-ROM header.
  282.    ' ''' </summary>
  283.    'Private ReadOnly hiRomHeaderAddress As UShort = 65472
  284.  
  285.    ''' <summary>
  286.    ''' The start address of the ROM name.
  287.    ''' </summary>
  288.    Private ReadOnly startAddressName As Integer = 0
  289.  
  290.    ''' <summary>
  291.    ''' The end address of the ROM name.
  292.    ''' </summary>
  293.    Private ReadOnly endAddressName As Integer = 20
  294.  
  295.    ''' <summary>
  296.    ''' The start address of the ROM layout.
  297.    ''' </summary>
  298.    Private ReadOnly startAddressLayout As Integer = 21
  299.  
  300.    ' ''' <summary>
  301.    ' ''' The end address of the ROM layout.
  302.    ' ''' </summary>
  303.    'Private ReadOnly endAddressLayout As Integer = 21
  304.  
  305.    ''' <summary>
  306.    ''' The start address of the ROM cartridge type.
  307.    ''' </summary>
  308.    Private ReadOnly startAddressCartridgeType As Integer = 22
  309.  
  310.    ' ''' <summary>
  311.    ' ''' The end address of the ROM cartridge type.
  312.    ' ''' </summary>
  313.    'Private ReadOnly endAddressCartridgeType As Integer = 22
  314.  
  315.    ''' <summary>
  316.    ''' The start address of the ROM size (rom).
  317.    ''' </summary>
  318.    Private ReadOnly startAddressRomSize As Integer = 23
  319.  
  320.    ' ''' <summary>
  321.    ' ''' The end address of the ROM size (rom).
  322.    ' ''' </summary>
  323.    'Private ReadOnly endAddressRomSize As Integer = 23
  324.  
  325.    ''' <summary>
  326.    ''' The start address of the ROM size (ram).
  327.    ''' </summary>
  328.    Private ReadOnly startAddressRamSize As Integer = 24
  329.  
  330.    ' ''' <summary>
  331.    ' ''' The end address of the ROM size (ram).
  332.    ' ''' </summary>
  333.    'Private ReadOnly endAddressRamSize As Integer = 24
  334.  
  335.    ''' <summary>
  336.    ''' The start address of the ROM country code.
  337.    ''' </summary>
  338.    Private ReadOnly startAddressCountryCode As Integer = 25
  339.  
  340.    ' ''' <summary>
  341.    ' ''' The end address of the ROM country code.
  342.    ' ''' </summary>
  343.    'Private ReadOnly endAddressCountryCode As Integer = 25
  344.  
  345.    ''' <summary>
  346.    ''' The start address of the ROM license code.
  347.    ''' </summary>
  348.    Private ReadOnly startAddressLicenseCode As Integer = 26
  349.  
  350.    ' ''' <summary>
  351.    ' ''' The end address of the ROM license code.
  352.    ' ''' </summary>
  353.    'Private ReadOnly endAddressLicenseCode As Integer = 26
  354.  
  355.    ''' <summary>
  356.    ''' The start address of the ROM Version Number.
  357.    ''' </summary>
  358.    Private ReadOnly startAddressVersionNumber As Integer = 27
  359.  
  360.    ' ''' <summary>
  361.    ' ''' The end address of the ROM Version Number.
  362.    ' ''' </summary>
  363.    'Private ReadOnly endAddresVersionNumber As Integer = 27
  364.  
  365.    ''' <summary>
  366.    ''' The start address of the ROM checksum compliment.
  367.    ''' </summary>
  368.    Private ReadOnly startAddressChecksumCompliment As Integer = 28
  369.  
  370.    ''' <summary>
  371.    ''' The end address of the ROM checksum compliment.
  372.    ''' </summary>
  373.    Private ReadOnly endAddressChecksumCompliment As Integer = 29
  374.  
  375.    ''' <summary>
  376.    ''' The start address of the ROM checksum.
  377.    ''' </summary>
  378.    Private ReadOnly startAddressChecksum As Integer = 30
  379.  
  380.    ''' <summary>
  381.    ''' The end address of the ROM checksum.
  382.    ''' </summary>
  383.    Private ReadOnly endAddressChecksum As Integer = 31
  384.  
  385. #End Region
  386.  
  387. #Region " Enumerations "
  388.  
  389.    ''' <summary>
  390.    ''' Specifies a SNES ROM header type.
  391.    ''' A headered ROM has SMC header and SNES header.
  392.    ''' A headerless ROM has no SMC header, but still contains a SNES header.
  393.    ''' Note that both a LoRom and HiRom images can be headered, or headerless.
  394.    ''' <remarks>http://romhack.wikia.com/wiki/SNES_header</remarks>
  395.    ''' </summary>
  396.    Public Enum HeaderTypeEnum As Integer
  397.  
  398.        ''' <summary>
  399.        ''' A headered SNES ROM.
  400.        ''' The ROM contains an SMC header, and also contains an SNES header.
  401.        ''' </summary>
  402.        Headered = 0
  403.  
  404.        ''' <summary>
  405.        ''' A headerless SNES ROM.
  406.        ''' The ROM does not contains an SMC header, but contains an SNES header.
  407.        ''' </summary>
  408.        Headerless = 1
  409.  
  410.    End Enum
  411.  
  412.    ''' <summary>
  413.    ''' Specifies a SNES ROM bank type.
  414.    ''' <remarks>http://romhack.wikia.com/wiki/SNES_ROM_layout</remarks>
  415.    ''' </summary>
  416.    Public Enum BankTypeEnum As UShort
  417.  
  418.        ''' <summary>
  419.        ''' A LoROM maps each ROM bank into the upper half (being addresses $8000 to $ffff) of each SNES bank,
  420.        ''' starting with SNES bank $00, and starting again with SNES bank $80.
  421.        ''' </summary>
  422.        LoRom = 32704US
  423.  
  424.        ''' <summary>
  425.        ''' A HiROM maps each ROM bank into the whole (being addresses $0000 to $ffff) of each SNES bank,
  426.        ''' starting with SNES bank $40, and starting again with SNES bank $80.
  427.        ''' </summary>
  428.        HiRom = 65472US
  429.  
  430.    End Enum
  431.  
  432.    ''' <summary>
  433.    ''' Specifies a SNES ROM cartridge type.
  434.    ''' <remarks>http://romhack.wikia.com/wiki/SNES_ROM_layout</remarks>
  435.    ''' </summary>
  436.    Public Enum CartridgeTypeEnum As Byte
  437.  
  438.        ''' <summary>
  439.        ''' A ROM without save-RAM.
  440.        ''' </summary>
  441.        NoSram0 = 0
  442.  
  443.        ''' <summary>
  444.        ''' A ROM without save-RAM.
  445.        ''' <remarks>I didn't fully verified this value...</remarks>
  446.        ''' </summary>
  447.        NoSram1 = 1
  448.  
  449.        ''' <summary>
  450.        ''' A ROM with save-RAM.
  451.        ''' </summary>
  452.        Sram = 2
  453.  
  454.    End Enum
  455.  
  456. #End Region
  457.  
  458. #Region " Exceptions "
  459.  
  460.    ''' <summary>
  461.    ''' Exception that is thrown when a SNES ROM has an invalid format.
  462.    ''' </summary>
  463.    <Serializable>
  464.    Public NotInheritable Class InvalidRomFormatException : Inherits Exception
  465.  
  466.        ''' <summary>
  467.        ''' Initializes a new instance of the <see cref="InvalidROMFormatException"/> class.
  468.        ''' </summary>
  469.        Public Sub New()
  470.            MyBase.New("The SNES ROM image has an invalid format.")
  471.        End Sub
  472.  
  473.        ''' <summary>
  474.        ''' Initializes a new instance of the <see cref="InvalidROMFormatException"/> class.
  475.        ''' </summary>
  476.        ''' <param name="message">The message that describes the error.</param>
  477.        Public Sub New(ByVal message As String)
  478.            MyBase.New(message)
  479.        End Sub
  480.  
  481.        ''' <summary>
  482.        ''' Initializes a new instance of the <see cref="InvalidROMFormatException"/> class.
  483.        ''' </summary>
  484.        ''' <param name="message">The message that describes the error.</param>
  485.        ''' <param name="inner">The inner exception.</param>
  486.        Public Sub New(ByVal message As String, ByVal inner As Exception)
  487.            MyBase.New(message, inner)
  488.        End Sub
  489.  
  490.    End Class
  491.  
  492. #End Region
  493.  
  494. #Region " Types "
  495.  
  496.    ''' <summary>
  497.    ''' Defines a SNES ROM country.
  498.    ''' </summary>
  499.    <Serializable>
  500.    Public NotInheritable Class CountryData
  501.  
  502. #Region " Properties "
  503.  
  504.        ''' <summary>
  505.        ''' Gets the region, which can de PAL or NTSC.
  506.        ''' </summary>
  507.        ''' <remarks>http://romhack.wikia.com/wiki/SNES_header</remarks>
  508.        ''' <value>The country code.</value>
  509.        Public ReadOnly Property Region As RegionTypeEnum
  510.            Get
  511.                Return Me.regionB
  512.            End Get
  513.        End Property
  514.        ''' <summary>
  515.        ''' (backing field) The region, which can de PAL or NTSC.
  516.        ''' </summary>
  517.        Private ReadOnly regionB As RegionTypeEnum
  518.  
  519.        ''' <summary>
  520.        ''' Gets the country code.
  521.        ''' </summary>
  522.        ''' <value>The country code.</value>
  523.        Public ReadOnly Property Code As Byte
  524.            Get
  525.                Return Me.codeB
  526.            End Get
  527.        End Property
  528.        ''' <summary>
  529.        ''' (backing field) The country code.
  530.        ''' </summary>
  531.        Private ReadOnly codeB As Byte
  532.  
  533.        ''' <summary>
  534.        ''' Gets the country name.
  535.        ''' </summary>
  536.        ''' <value>The country name.</value>
  537.        Public ReadOnly Property Name As String
  538.            Get
  539.                Return Me.nameB
  540.            End Get
  541.        End Property
  542.        ''' <summary>
  543.        ''' (backing field) The country name.
  544.        ''' </summary>
  545.        Private ReadOnly nameB As String
  546.  
  547. #End Region
  548.  
  549. #Region " Enumerations "
  550.  
  551.        ''' <summary>
  552.        ''' Specifies a SNES ROM region type.
  553.        ''' <remarks>http://romhack.wikia.com/wiki/SNES_header</remarks>
  554.        ''' </summary>
  555.        Public Enum RegionTypeEnum As Integer
  556.  
  557.            ''' <summary>
  558.            ''' A PAL SNES ROM.
  559.            ''' </summary>
  560.            Pal = 0
  561.  
  562.            ''' <summary>
  563.            ''' An NTSC SNES ROM.
  564.            ''' </summary>
  565.            Ntsc = 1
  566.  
  567.        End Enum
  568.  
  569. #End Region
  570.  
  571. #Region " Countries "
  572.  
  573.        ''' <summary>
  574.        ''' The known ROM countries, based on country code from 0 to 13, so countrycode 0 = Japan, countrycode 1 = United States, and so on...
  575.        ''' Unknown country codes are just unknown.
  576.        ''' </summary>
  577.        Private ReadOnly countryDict As New Dictionary(Of Integer, String) From
  578.            {
  579.                {0, "Japan"},
  580.                {1, "United States"},
  581.                {2, "Unknown"},
  582.                {3, "Unknown"},
  583.                {4, "Unknown"},
  584.                {5, "Unknown"},
  585.                {6, "Unknown"},
  586.                {7, "Unknown"},
  587.                {8, "Spain"},
  588.                {9, "Unknown"},
  589.                {10, "Unknown"},
  590.                {11, "Unknown"},
  591.                {12, "Unknown"},
  592.                {13, "Unknown"}
  593.            }
  594.  
  595. #End Region
  596.  
  597. #Region " Regions "
  598.  
  599.        ''' <summary>
  600.        ''' The country codes for NTSC region.
  601.        ''' <remarks>http://romhack.wikia.com/wiki/SMC_header</remarks>
  602.        ''' </summary>
  603.        Private ReadOnly ntscRegionCodes As Integer() =
  604.            {0, 1, 13}
  605.  
  606.        ''' <summary>
  607.        ''' The country codes for PAL region.
  608.        ''' <remarks>http://romhack.wikia.com/wiki/SMC_header</remarks>
  609.        ''' </summary>
  610.        Private ReadOnly palRegionCodes As Integer() =
  611.            {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}
  612.  
  613. #End Region
  614.  
  615. #Region " Constructors "
  616.  
  617.        ''' <summary>
  618.        ''' Initializes a new instance of the <see cref="CountryData"/> class.
  619.        ''' </summary>
  620.        ''' <param name="countryCode">The SNES ROM country code.</param>
  621.        ''' <exception cref="ArgumentException">Invalid country code.;countryCode</exception>
  622.        Public Sub New(ByVal countryCode As Byte)
  623.  
  624.            If Not (Me.ntscRegionCodes.Concat(Me.palRegionCodes)).Contains(countryCode) Then
  625.                Throw New ArgumentException(message:="Invalid country code.", paramName:="countryCode")
  626.  
  627.            Else
  628.                Me.codeB = countryCode
  629.                Me.nameB = Me.countryDict(countryCode)
  630.  
  631.                ' Determine region.
  632.                If Me.ntscRegionCodes.Contains(countryCode) Then
  633.                    Me.regionB = RegionTypeEnum.Ntsc
  634.  
  635.                ElseIf Me.palRegionCodes.Contains(countryCode) Then
  636.                    Me.regionB = RegionTypeEnum.Pal
  637.  
  638.                End If
  639.  
  640.            End If
  641.  
  642.        End Sub
  643.  
  644.        ''' <summary>
  645.        ''' Prevents a default instance of the <see cref="CountryData"/> class from being created.
  646.        ''' </summary>
  647.        Private Sub New()
  648.        End Sub
  649.  
  650. #End Region
  651.  
  652.    End Class
  653.  
  654. #End Region
  655.  
  656. #Region " Constructors "
  657.  
  658.    ''' <summary>
  659.    ''' Prevents a default instance of the <see cref="SnesRom"/> class from being created.
  660.    ''' </summary>
  661.    Private Sub New()
  662.    End Sub
  663.  
  664.    ''' <summary>
  665.    ''' Initializes a new instance of the <see cref="SnesRom"/> class.
  666.    ''' </summary>
  667.    ''' <param name="romFilePath">The SNES ROM file path.</param>
  668.    Public Sub New(ByVal romFilePath As String)
  669.  
  670.        Me.New(File.ReadAllBytes(romFilePath))
  671.  
  672.    End Sub
  673.  
  674.    ''' <summary>
  675.    ''' Initializes a new instance of the <see cref="SnesRom"/> class.
  676.    ''' </summary>
  677.    ''' <param name="romData">The raw byte-data of the ROM file.</param>
  678.    Public Sub New(ByVal romData As Byte())
  679.  
  680.        Me.rawDataB = romData
  681.  
  682.        Me.VerifyRomFormat()
  683.        Me.VerifyBankType()
  684.        Me.ReadHeader()
  685.  
  686.    End Sub
  687.  
  688. #End Region
  689.  
  690. #Region " Private Methods "
  691.  
  692.    ''' <summary>
  693.    ''' Reads the ROM header to retrieve the header data.
  694.    ''' </summary>
  695.    Private Sub ReadHeader()
  696.  
  697.        ' Read range of bytes.
  698.        Me.nameB = Encoding.ASCII.GetString(Me.GetBytes(Me.startAddressName, Me.endAddressName)).Trim
  699.  
  700.        ' Read single bytes.
  701.        Me.layoutB = Me.GetByte(Me.startAddressLayout)
  702.        Me.cartridgeTypeB = DirectCast(Me.GetByte(Me.startAddressCartridgeType), CartridgeTypeEnum)
  703.        Me.romSizeB = Me.GetByte(Me.startAddressRomSize)
  704.        Me.ramSizeB = Me.GetByte(Me.startAddressRamSize)
  705.        Me.CountryCode = Me.GetByte(Me.startAddressCountryCode)
  706.        Me.LicenseCode = Me.GetByte(Me.startAddressLicenseCode)
  707.        Me.VersionNumber = Me.GetByte(Me.startAddressVersionNumber)
  708.  
  709.    End Sub
  710.  
  711.    ''' <summary>
  712.    ''' Verifies the SNES ROM format.
  713.    ''' </summary>
  714.    ''' <exception cref="SnesRom.InvalidRomFormatException">The SNES ROM image has an invalid format.</exception>
  715.    Private Sub VerifyRomFormat()
  716.  
  717.        If (Me.rawDataB.Length Mod 1024 = 512) Then
  718.            Me.headerTypeB = HeaderTypeEnum.Headered
  719.  
  720.        ElseIf (Me.rawDataB.Length Mod 1024 = 0) Then
  721.            Me.headerTypeB = HeaderTypeEnum.Headerless
  722.  
  723.        Else
  724.            Throw New InvalidRomFormatException(message:="The SNES ROM image has an invalid format.")
  725.  
  726.        End If
  727.  
  728.    End Sub
  729.  
  730.    ''' <summary>
  731.    ''' Verifies the SNES ROM bank type.
  732.    ''' </summary>
  733.    ''' <exception cref="Exception">Cannot recognize the bank type.</exception>
  734.    Private Sub VerifyBankType()
  735.  
  736.        If Me.HeaderIsAt(BankTypeEnum.LoRom) Then
  737.            Me.bankTypeB = BankTypeEnum.LoRom
  738.  
  739.        ElseIf Me.HeaderIsAt(BankTypeEnum.HiRom) Then
  740.            Me.bankTypeB = BankTypeEnum.HiRom
  741.  
  742.        Else
  743.            Throw New Exception(message:="Cannot recognize the bank type.")
  744.  
  745.        End If
  746.  
  747.    End Sub
  748.  
  749.    ''' <summary>
  750.    ''' Verifies the checksum.
  751.    ''' </summary>
  752.    ''' <remarks>
  753.    ''' Offset 0x07FC0 in a headerless LoROM image (LoROM rom sin smc header)
  754.    ''' Offset 0x0FFC0 in a headerless HiROM image (HiROM rom sin smc header)
  755.    ''' </remarks>
  756.    ''' <returns><c>true</c> if checksum is ok, <c>false</c> otherwise.</returns>
  757.    Private Function VerifyChecksum() As Boolean
  758.  
  759.        If Me.HeaderType = HeaderTypeEnum.Headered Then
  760.            Me.headerLocationB += 512
  761.        End If
  762.  
  763.        Me.checksumComplimentB = BitConverter.ToUInt16(Me.GetBytes(Me.startAddressChecksumCompliment, Me.endAddressChecksumCompliment), startIndex:=0)
  764.  
  765.        Me.checksumB = BitConverter.ToUInt16(Me.GetBytes(Me.startAddressChecksum, Me.endAddressChecksum), startIndex:=0)
  766.  
  767.        Return CUShort(Me.Checksum Xor Me.ChecksumCompliment).Equals(UShort.MaxValue)
  768.  
  769.    End Function
  770.  
  771.    ''' <summary>
  772.    ''' Determines whether the ROM header is in the specified address.
  773.    ''' </summary>
  774.    ''' <param name="address">The address.</param>
  775.    ''' <returns><c>true</c> if the ROM header is in the specified address, <c>false</c> otherwise.</returns>
  776.    Private Function HeaderIsAt(ByVal address As UShort) As Boolean
  777.  
  778.        Me.headerLocationB = address
  779.        Return Me.VerifyChecksum()
  780.  
  781.    End Function
  782.  
  783.    ''' <summary>
  784.    ''' Gets the specified byte from the raw byte-data.
  785.    ''' </summary>
  786.    ''' <param name="address">The address.</param>
  787.    ''' <returns>The specified byte from the raw byte-data.</returns>
  788.    Private Function GetByte(ByVal address As Integer) As Byte
  789.  
  790.        Return Buffer.GetByte(array:=Me.RawData,
  791.                              index:=Me.HeaderLocation + address)
  792.  
  793.    End Function
  794.  
  795.    ''' <summary>
  796.    ''' Gets the specified range of bytes from the raw byte-data.
  797.    ''' </summary>
  798.    ''' <param name="from">From address.</param>
  799.    ''' <param name="to">To address.</param>
  800.    ''' <returns>The specified bytes from the raw byte-data.</returns>
  801.    Private Function GetBytes(ByVal from As Integer,
  802.                              ByVal [to] As Integer) As Byte()
  803.  
  804.        Return Me.RawData.Skip(Me.HeaderLocation + from).Take(([to] - from) + 1).ToArray()
  805.  
  806.    End Function
  807.  
  808.    ''' <summary>
  809.    ''' Replaces a single byte in the raw byte-data, with the specified data.
  810.    ''' </summary>
  811.    ''' <param name="address">the address.</param>
  812.    ''' <param name="data">The byte-data.</param>
  813.    Private Sub SetByte(ByVal address As Integer,
  814.                       ByVal data As Byte)
  815.  
  816.        Buffer.SetByte(array:=Me.rawDataB,
  817.                       index:=Me.HeaderLocation + address,
  818.                       value:=data)
  819.  
  820.    End Sub
  821.  
  822.    ''' <summary>
  823.    ''' Replaces the specified range of bytes in the raw byte-data, with the specified data.
  824.    ''' </summary>
  825.    ''' <param name="from">From address.</param>
  826.    ''' <param name="to">To address.</param>
  827.    ''' <param name="data">The byte-data.</param>
  828.    ''' <exception cref="ArgumentException">The byte-length of the specified data differs from the byte-length to be replaced;data</exception>
  829.    Private Sub SetBytes(ByVal from As Integer,
  830.                        ByVal [to] As Integer,
  831.                        ByVal data As Byte())
  832.  
  833.        If data.Length <> (([to] - from) + 1) Then
  834.            Throw New ArgumentException("The byte-length of the specified data differs from the byte-length to be replaced.", "data")
  835.  
  836.        Else
  837.            Buffer.BlockCopy(src:=data, srcOffset:=0,
  838.                             dst:=Me.rawDataB, dstOffset:=Me.HeaderLocation + from,
  839.                             count:=([to] - from) + 1)
  840.  
  841.        End If
  842.  
  843.    End Sub
  844.  
  845.    ''' <summary>
  846.    ''' Sets the ROM name.
  847.    ''' </summary>
  848.    ''' <param name="name">The ROM name.</param>
  849.    ''' <exception cref="ArgumentNullException">name</exception>
  850.    ''' <exception cref="ArgumentException">The name should contain 21 or less characters;name.</exception>
  851.    Private Sub SetName(ByVal name As String)
  852.  
  853.        Dim fixedNameLength As Integer = (Me.endAddressName - Me.startAddressName) + 1
  854.  
  855.        If String.IsNullOrEmpty(name) Then
  856.            Throw New ArgumentNullException(paramName:="name")
  857.  
  858.        ElseIf (name.Length > fixedNameLength) Then
  859.            Throw New ArgumentException(message:="The name should contain 21 or less characters.", paramName:="name")
  860.  
  861.        Else
  862.            ' fill with spaces up to 21 character length.
  863.            name = name.PadRight(totalWidth:=fixedNameLength, paddingChar:=" "c)
  864.  
  865.            Me.SetBytes(Me.startAddressName, Me.endAddressName, Encoding.ASCII.GetBytes(name))
  866.  
  867.        End If
  868.  
  869.    End Sub
  870.  
  871. #End Region
  872.  
  873. #Region " Public Methods "
  874.  
  875.    ''' <summary>
  876.    ''' Save the ROM changes to the specified file path.
  877.    ''' </summary>
  878.    ''' <param name="filePath">The ROM file path.</param>
  879.    ''' <param name="replace">
  880.    ''' If set to <c>true</c>, then replaces any existing file,
  881.    ''' otherwise, throws an <see cref="IOException"/> exception if file already exists.
  882.    ''' </param>
  883.    ''' <exception cref="IOException">The destination file already exists.</exception>
  884.    Public Sub Save(ByVal filePath As String, ByVal replace As Boolean)
  885.  
  886.        If Not replace AndAlso File.Exists(filePath) Then
  887.            Throw New IOException(message:="The destination file already exists.")
  888.  
  889.        Else
  890.            Try
  891.                File.WriteAllBytes(filePath, Me.rawDataB)
  892.  
  893.            Catch ex As Exception
  894.                Throw
  895.  
  896.            End Try
  897.  
  898.        End If
  899.  
  900.    End Sub
  901.  
  902. #End Region
  903.  
  904. End Class



Ejemplo para leer los datos de una ROM:
Código
  1. Dim romDump As New SnesRom("C:\ROM.smc")
  2. ' Or...
  3. ' Dim romDump As New SnesRom(File.ReadAllBytes("C:\ROM.smc"))
  4.  
  5. Dim sb As New StringBuilder
  6. With sb
  7.    .AppendLine(String.Format("Name...............: {0}", romDump.Name))
  8.    .AppendLine(String.Format("Bank Type..........: {0}", romDump.BankType.ToString))
  9.    .AppendLine(String.Format("Cartridge Type.....: {0}", romDump.CartridgeType.ToString.ToUpper))
  10.    .AppendLine(String.Format("Checksum...........: {0}", romDump.Checksum.ToString))
  11.    .AppendLine(String.Format("Checksum Compliment: {0}", romDump.ChecksumCompliment.ToString))
  12.    .AppendLine(String.Format("Country Region.....: {0}", romDump.Country.Region.ToString.ToUpper))
  13.    .AppendLine(String.Format("Country Code.......: {0}", romDump.Country.Code.ToString))
  14.    .AppendLine(String.Format("Country Name.......: {0}", romDump.Country.Name))
  15.    .AppendLine(String.Format("Header Type........: {0}", romDump.HeaderType.ToString))
  16.    .AppendLine(String.Format("Layout.............: {0}", romDump.Layout.ToString))
  17.    .AppendLine(String.Format("License Code.......: {0}", romDump.LicenseCode.ToString))
  18.    .AppendLine(String.Format("RAM Size...........: {0}", romDump.RamSize.ToString))
  19.    .AppendLine(String.Format("ROM Size...........: {0}", romDump.RomSize.ToString))
  20.    .AppendLine(String.Format("Version Number.....: {0}", romDump.VersionNumber.ToString))
  21. End With
  22.  
  23. Clipboard.SetText(sb.ToString) : MessageBox.Show(sb.ToString)

Resultado de ejecución de la lectura de una ROM:
Código:
Name...............: THE LEGEND OF ZELDA
Bank Type..........: LoRom
Cartridge Type.....: SRAM
Checksum...........: 44813
Checksum Compliment: 20722
Country Region.....: NTSC
Country Code.......: 1
Country Name.......: United States
Header Type........: Headered
Layout.............: 32
License Code.......: 1
RAM Size...........: 3
ROM Size...........: 10
Version Number.....: 0

Ejemplo para modificar una ROM:
Código
  1. Dim romDump As New SnesRom("C:\ROM.smc")
  2. ' Or...
  3. ' Dim romDump As New SnesRom(File.ReadAllBytes("C:\Rom.smc"))
  4.  
  5. With romDump
  6.    .Name = "Elektrozoider"
  7.    .Country = New SnesRom.CountryData(countryCode:=8) ' Spain.
  8.    .VersionNumber = CByte(3)
  9.    .Save("C:\Hacked.smc", replace:=True)
  10. End With
En línea

Meta


Desconectado Desconectado

Mensajes: 3.439



Ver Perfil WWW
Re: Leer una clase en un formulario Windows de Visual C#
« Respuesta #14 en: 10 Junio 2015, 20:08 pm »

Hola:

Fuerte código. ;)

Con estas dos Web he intentado traducirloa C# y me dice:
http://www.developerfusion.com/tools/convert/vb-to-csharp/?batchId=37f5bff7-8541-40f9-aa53-a9e112a0aac2
Citar
An error occured converting your code, probably due to a syntax error: -- line 577 col 84: "{" expected

En esta otra Web me dice.
http://converter.telerik.com/
Citar
CONVERSION ERROR: Code could not be converted. Details:

-- line 577 col 84: "{" expected

Please check for any errors in the original code and try again.


Muy pero que muy, muy, muy y muy buen trabajo.

Lo del código del país, lo poco he encontra está aquí.
http://romhack.wikia.com/wiki/SNES_header
http://romhack.wikia.com/wiki/SMC_header

No se si el código del país con teléfonos tiene algo que ver.
http://personas.entel.cl/PortalPersonas/appmanager/entelpcs/personas?_nfpb=true&_pageLabel=P4400216791251672510516

Esto no tiene nada que ver, pero puede dar ideas para algo.
http://www.elotrolado.net/hilo_acerca-de-los-codigos-de-los-juegos-de-super-nintendo_999526

Más datos referente a código de país de la ROM.
http://es.wikipedia.org/wiki/Imagen_ROM

Seguiré buscando...

Por cierto, para leer SmcHeader, no lo tenía en public, ajjajajajaa. Ahora si lo lee.
Código
  1. textBox_SmcHeader.Text = VARIABLE.SmcHeader ? "True" : "False";

Voy acabar los demás. Y la parte que quiero guardar, es la del título del juego, para poner información.

Saludos.
« Última modificación: 10 Junio 2015, 20:10 pm por Meta » En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.817



Ver Perfil
Re: Leer una clase en un formulario Windows de Visual C#
« Respuesta #15 en: 10 Junio 2015, 20:25 pm »

he intentado traducirloa C# y me dice:

El motor/librería NRefactory que utilizan practicamente todos los traductores, es bastante estricto con los saltos de linea en ciertas partes, los cuales si que están permitidos en la IDE.

Debes escribir el bracket despues del keyword From.

Es decir, de esto:
Citar
Código
  1.        Private ReadOnly countryDict As New Dictionary(Of Integer, String) From
  2.            {
  3.                {0, "Japan"},
  4.                {1, "United States"},
  5.                {2, "Unknown"},
  6.                {3, "Unknown"},
  7.                {4, "Unknown"},
  8.                {5, "Unknown"},
  9.                {6, "Unknown"},
  10.                {7, "Unknown"},
  11.                {8, "Spain"},
  12.                {9, "Unknown"},
  13.                {10, "Unknown"},
  14.                {11, "Unknown"},
  15.                {12, "Unknown"},
  16.                {13, "Unknown"}
  17.            }

A esto otro:
Código
  1.        Private ReadOnly countryDict As New Dictionary(Of Integer, String) From {
  2.                {0, "Japan"},
  3.                {1, "United States"},
  4.                {2, "Unknown"},
  5.                {3, "Unknown"},
  6.                {4, "Unknown"},
  7.                {5, "Unknown"},
  8.                {6, "Unknown"},
  9.                {7, "Unknown"},
  10.                {8, "Spain"},
  11.                {9, "Unknown"},
  12.                {10, "Unknown"},
  13.                {11, "Unknown"},
  14.                {12, "Unknown"},
  15.                {13, "Unknown"}
  16.            }



Muy pero que muy, muy, muy y muy buen trabajo.

Gracias. Alguien debería donarme unos eurillos a mi paypal :silbar:.

Saludos!
« Última modificación: 10 Junio 2015, 20:33 pm por Eleкtro » En línea

Meta


Desconectado Desconectado

Mensajes: 3.439



Ver Perfil WWW
Re: Leer una clase en un formulario Windows de Visual C#
« Respuesta #16 en: 10 Junio 2015, 21:38 pm »

Hola:

Hice esto rápido, ya lo puliré.
Código
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. using System.IO; // No olvidar.
  12.  
  13. namespace ROM_SNES
  14. {
  15.    public partial class Form1 : Form
  16.    {
  17.        public Form1()
  18.        {
  19.            InitializeComponent();
  20.        }
  21.  
  22.        private void button1_Click(object sender, EventArgs e)
  23.        {
  24.  
  25.            if (openFileDialog1.ShowDialog() == DialogResult.OK)
  26.            {
  27.                FileInfo Archivo = new FileInfo(openFileDialog1.FileName);
  28.                SnesKit.RomDump VARIABLE = new SnesKit.RomDump(File.ReadAllBytes(openFileDialog1.FileName.ToString()));
  29.                textBox_Nombre_ruta_archivo.Text = openFileDialog1.FileName.ToString(); // Muestra la ruta del archivo.
  30.                textBox_Name.Text = VARIABLE.Name;
  31.                textBox_Layout.Text = string.Format("{0:X}", VARIABLE.Layout);
  32.                textBox_CartridgeType.Text = string.Format("{0:X}", VARIABLE.CartridgeType);
  33.                textBox_RomSize.Text = string.Format("{0:X}", VARIABLE.RomSize);
  34.                textBox_RamSize.Text = string.Format("{0:X}", VARIABLE.RamSize);
  35.                textBox_CountryCode.Text = string.Format("{0:X}", VARIABLE.CountryCode);
  36.                textBox_LicenseCode.Text = string.Format("{0:X}", VARIABLE.LicenseCode);
  37.                textBox_VersionNumber.Text = string.Format("{0:X}", VARIABLE.VersionNumber);
  38.                textBox_BankType.Text = VARIABLE.BankType.ToString();
  39.                textBox_Checksum.Text = string.Format("{0:X}", VARIABLE.Checksum);
  40.                textBox_ChecksumCompliment.Text = string.Format("{0:X}", VARIABLE.ChecksumCompliment);
  41.                textBox_SmcHeader.Text = VARIABLE.SmcHeader ? "True" : "False";
  42.                textBox_HeaderLocation.Text = string.Format("{0:X}", VARIABLE.HeaderLocation);
  43.                textBox_MB.Text = string.Format("{0:N0}", (Archivo.Length / 1024f) / 1024f); // Resultado 4 MB.
  44.                textBox_KB.Text = string.Format("{0:N0}", (Archivo.Length / 1024f)); // 4.907 KB.
  45.                textBox_Bytes.Text = string.Format("{0:N0}", Archivo.Length); // 4.194.816 B o Bytes.
  46.                textBox_Mbit.Text = string.Format("{0:N0}", ((Archivo.Length / 1024f) / 1024f) * 8); // Mega bits.
  47.            }
  48.        }
  49.    }
  50. }
  51.  

Había que poner variables en public para que me hiciera caso, el que no logro es el textbox addr, no se como poner esa variable en public.

Muestro la imagen de abajo.



1) Como puedes ver arriba, en el Cuadro 3 azul, en el textBox en MB pone 4. ¿Cómo hago que se vea el subfijo de esta manera?

En vez de 4 MB que muestre 4.00 MB.

2) En el Cuadro 4 amarillo, en el textBox "Nombre del archivo". Cuando abro un archivo en el botón "Arbrir archivo" en eltextBox "Ruta del archivo" se ve la ruta y el nombre del archivo. En el textBox "Nombre del archivo". ¿Cómo hago para que vea su nombre?

He estado mirando los formatos y no me sale.

Saludos.
En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.817



Ver Perfil
Re: Leer una clase en un formulario Windows de Visual C#
« Respuesta #17 en: 10 Junio 2015, 22:23 pm »


1)¿Cómo hago que se vea el subfijo de esta manera?
En vez de 4 MB que muestre 4.00 MB.

Debes usar la extensión ToString para convertir el valor numérico (repito, numérico, no String) a String, dándole el formato númerico al string, donde debes usar un formato que añada una precisión de 2 decimales.

Código
  1. 4.ToString("formato específico")

Es muy sencillo lo que quieres hacer, lee aquí para conocer la sintaxis del formato numérico, no te costará nada encontrar los caracteres que debes para el formato que necesitas darle:
Custom Numeric Format Strings - MSDN



2) En el Cuadro 4 amarillo, en el textBox "Nombre del archivo". Cuando abro un archivo en el botón "Arbrir archivo" en eltextBox "Ruta del archivo" se ve la ruta y el nombre del archivo. En el textBox "Nombre del archivo". ¿Cómo hago para que vea su nombre?

Lee los métodos de la Class System.IO.Path, tiene un método para devolver el nombre de archivo de una ruta de archivo. Esto tampoco tiene pérdida.
Path Methods (System.IO) - MSDN

PD: De todas formas no creo que te costase nada buscar en Google "C# get filename" antes de preguntarlo... seguro que saldran miles de resultados por que es muy básico.

Saludos!
« Última modificación: 10 Junio 2015, 22:27 pm por Eleкtro » En línea

Meta


Desconectado Desconectado

Mensajes: 3.439



Ver Perfil WWW
Re: Leer una clase en un formulario Windows de Visual C#
« Respuesta #18 en: 11 Junio 2015, 09:55 am »

Hola:

Hay algo de aquí que no me cuadra.
http://romhack.wikia.com/wiki/SNES_header

Donde pone:
Código
  1. ROM and RAM size bytes ($ffd7 and $ffd8) Edit
  2.  
  3. Byte $ffd7 indicates the amount of ROM in the cartridge; byte $ffd8 indicates the amount of RAM in the cartridge (excluding the RAM in the SNES system). Both bytes use the same scale.
  4.  
  5.    $00 => no RAM
  6.    $01 => $800 bytes == 2 kilobytes, amount of RAM in Super Mario World
  7.    $02 => $1000 bytes == 4 kilobytes
  8.    $03 => $2000 bytes == 8 kilobytes
  9.    $04 => $4000 bytes == 16 kilobytes
  10.    $05 => $8000 bytes == 32 kilobytes, amount of RAM in Mario Paint
  11.    $06 => $10000 bytes == 64 kilobytes
  12.    $07 => $20000 bytes == 128 kilobytes, amount of RAM in Dezaemon - Kaite Tsukutte Asoberu
  13.    $08 => $40000 bytes == 256 kilobytes, minimum for ROM
  14.    $09 => $80000 bytes == 512 kilobytes, amount of ROM in Super Mario World
  15.    $0a => $100000 bytes == 1 megabyte, amount of ROM in Mario Paint
  16.    $0b => $200000 bytes == 2 megabytes
  17.    $0c => $400000 bytes == 4 megabytes

Según tengo entendido, los valores de la ROM y la RAM son los mismos. Me pasa con cualquier juego. A mi me dan valores diferentes. Fijarse en la imagen de abajo.


¿Qué opinas?

Saludos.

En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.817



Ver Perfil
Re: Leer una clase en un formulario Windows de Visual C#
« Respuesta #19 en: 11 Junio 2015, 15:27 pm »

¿Qué opinas?

No quiero parecer arrogante, pero opino que no deberías manejar algo que no entiendes ...y encima haciendo copy/pastes.

Solo has tenido una comprensión incorrecta de las palabras que pone en esa documentación. El tamaño de la memoria de solo lectura (ROM) difiere de la memoria RAM, busca las definiciones de ambas para comprender. La wikipedia está para algo.

Primero deberías aprender lo que te falta por aprender del lenguaje, y de los conceptos que necesites aprender para llevar a cabo esa tarea (aunque yo tampoco soy ningún erudito en el entendimiento de las especificaciones del formato de los cartuchos ROM de SNES ni de la lectura y escritura de offsets), y luego ya, cuando te veas más capaz, te pones a hacer un lector de cabeceras para "X" formato.



Dicho esto, no todo iba a ser malo, he actualizado y mejorado el código fuente que publiqué en la página anterior para añadirle toda la información que faltaba (y más), gracias a las especificaciones que encontré en esta página:
http://softpixel.com/~cwright/sianse/docs/Snesrom.txt
y a esta aplicación para comprobar los resultados de mis modificaciones:
http://www.zophar.net/utilities/snesaud/snes-explorer.html

Ahora el código está mucho mejor, y con algunas funcionalidades de escritura más, aunque sigue faltando algún que otro detalle del que me cuesta encontrar documentación.

Aunque no lo vayas a usar, de todas maneras lo comparto en este hilo por si a otra persona le viene bien esta ayuda en VB.Net:

Código fuente:
http://pastebin.com/JMUEdWrK

Ejemplo de uso para la lectura:
Código
  1. Dim romDump As New SnesRom("C:\ROM.smc")
  2. ' Or...
  3. ' Dim romDump As New SnesRom(File.ReadAllBytes("C:\ROM.smc"))
  4.  
  5. Dim sb As New StringBuilder
  6. With sb
  7.    .AppendLine(String.Format("Name..................: {0}", romDump.Name))
  8.    .AppendLine(String.Format("Bank Type.............: {0}", romDump.BankType.ToString))
  9.    .AppendLine(String.Format("Cartridge Type........: {0}", romDump.CartridgeType.ToString.ToUpper.Replace("_", "/")))
  10.    .AppendLine(String.Format("Checksum..............: {0}", String.Format("0x{0}", Convert.ToString(CInt(romDump.Checksum), toBase:=16).ToUpper)))
  11.    .AppendLine(String.Format("Checksum Complement...: {0}", String.Format("0x{0}", Convert.ToString(CInt(romDump.ChecksumComplement), toBase:=16).ToUpper)))
  12.    .AppendLine(String.Format("Country Code..........: {0}", romDump.Country.Code.ToString))
  13.    .AppendLine(String.Format("Country Name..........: {0}", romDump.Country.Name))
  14.    .AppendLine(String.Format("Country Region........: {0}", romDump.Country.Region.ToString.ToUpper))
  15.    .AppendLine(String.Format("Header Type (SMC).....: {0}", romDump.HeaderType.ToString))
  16.    .AppendLine(String.Format("Layout................: {0}", romDump.Layout.ToString))
  17.    .AppendLine(String.Format("License Code/Name.....: {0}", romDump.LicenseCode.ToString))
  18.    .AppendLine(String.Format("ROM Size..............: {0} MBits", romDump.RomSize.ToString.Substring(1, romDump.RomSize.ToString.LastIndexOf("M") - 2)).Replace("_or_", "/"))
  19.    .AppendLine(String.Format("RAM Size..............: {0} KBits", romDump.RamSize.ToString.Substring(1, romDump.RamSize.ToString.LastIndexOf("K") - 2)))
  20.    .AppendLine(String.Format("Version Number........: 1.{0}", romDump.Version.ToString))
  21. End With
  22.  
  23. Clipboard.SetText(sb.ToString) : MessageBox.Show(sb.ToString)

Resultado de ejecución de la lectura:
Código:
Name..................: SUPER MARIOWORLD
Bank Type.............: LoRom
Cartridge Type........: ROM/SRAM
Checksum..............: 0xA0DA
Checksum Complement...: 0x5F25
Country Code..........: 1
Country Name..........: United States
Country Region........: NTSC
Header Type (SMC).....: Headered
Layout................: 32
License Code/Name.....: Nintendo
ROM Size..............: 8 MBits
RAM Size..............: 16 KBits
Version Number........: 1.0

Ejemplo de uso para la escritura:
Código
  1. Dim romDump As New SnesRom("C:\ROM.smc")
  2. ' Or...
  3. ' Dim romDump As New SnesRom(File.ReadAllBytes("C:\ROM.smc"))
  4.  
  5. With romDump
  6.    .Name = "Elektrocitos"
  7.    .Version = 1
  8.    .Country = New SnesRom.CountryData(countryCode:=0) ' Japan.
  9.    .LicenseCode = SnesRom.LicenseCodeEnum.Taito
  10.    .RomSize = SnesRom.ROMSizeEnum._4_Mbits
  11.    .RamSize = SnesRom.SRAMSizeEnum._256_Kbits
  12.    .Save("C:\Elektron.smc", replace:=True)
  13. End With

Saludos!
« Última modificación: 11 Junio 2015, 15:36 pm por Eleкtro » En línea

Páginas: 1 [2] 3 Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Leer Texto de un archivo TXT y pasarlo a un Formulario
Programación Visual Basic
washandwear 6 9,443 Último mensaje 1 Octubre 2006, 13:25 pm
por _Sergi_
Como acceder a controles de un formulario desde otra clase?
.NET (C#, VB.NET, ASP)
Rakzo-Fimbres 5 16,220 Último mensaje 22 Julio 2008, 21:13 pm
por Rakzo-Fimbres
comunicacion entre clase y formulario
PHP
mag55 6 6,197 Último mensaje 10 Noviembre 2009, 22:28 pm
por Kasi
Posible leer un archivo en kiloBytes con la clase RandomAccessFile
Java
cyberserver 0 2,373 Último mensaje 5 Diciembre 2009, 09:23 am
por cyberserver
Enviar datos de un formulario de una pagina JSP a una clase.
Java
h3ct0r 3 8,142 Último mensaje 22 Febrero 2011, 20:07 pm
por h3ct0r
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines