Tuesday, July 24, 2012

how to install windows without dvd drive

you can use VMWARE to install it into the boot camp parition

http://forums.macrumors.com/showthread.php?t=601414

I haven't tested it personally, but from the looks of it, the people in the forum say they were able to get it to work.  The answer is in the post by colin which is reproduced below.

=====================================

I'm working on installing Windows 7 without a DVD (broken SuperDrive here) using VMWare Fusion and the instructions provided by melchior.

I think I've figured out a way to make VMWare install Windows 7 to the Boot Camp partition.

I'll try and see if it works, and if it does I will post instructions.

Edit:

Great news, I got the Boot Camp partition to show up in VMWare Fusion when installing windows. I'm going to install it! 

Here's what I did:

Step 1: Installed VMWare, opened up the application to make sure everything worked correctly, then quit.

Step 2: I created a folder in the root of my hard drive (Macintosh HD) entitled "Virtual Machines"

Step 3: I typed the following into Terminal:

Code:
cd /Virtual\ Machines
Then..
Code:
/Library/Application\ Support/VMware\ Fusion/vmware-rawdiskCreator print /dev/disk0
A list of my computer's partitions appeared, then I typed..
Code:
/Library/Application\ Support/VMware\ Fusion/vmware-rawdiskCreator create /dev/disk0 3 windows7 ide
You can see a screenshot of Terminal after typing in these commands below.

After that, I opened up VMWare Fusion. I chose to make a new machine, I hit Continue Without Disc.

I chose Use existing virtual disk, then selected windows7.vmdk out of the Virtual Machines folder in root of Macintosh HD. 

VMWare asked me if I wanted to convert the disk into an "updated" version, I chose not to convert the disk image.

After that, I unchecked "automatically open machine when VMWare starts", then hit finish. I opened up the settings for the newly created virtual machine, and changed the disc to point to my Windows 7 ISO file.

I started the machine, and VMWare successfully recognized my Boot Camp partition and I'm installing Windows 7 onto the partition right now.


Screenshot of Terminal after typing in commands:



Update:

Setup completed successfully in VMWare and rebooted. I'm going to try and natively boot off of this, if it doesn't work I'll try winclone (I think winclone might set the partition to active when it copies the flies to the partition, that's why that "trick" causes the partition to become bootable again).

Side note: The reason why you type disk0 into Terminal instead of the actual ID of the Boot Camp partition (usually it's disk0s3) is because the VMWare Raw Disk Creator considers the Boot Camp partition a "special" partition and tags it with a 0 rather than using the usual disk0s3 stuff.

Tuesday, July 17, 2012

Attaching bram to vga

The VGA is working and as a hard coded test, I created some colorful squares
using
rgb_o <= "111" when within_range else "000";

Now it is time to use something that has the potential to change over time.

I used a BRAM to store the color values for each pixel.
Although I wasn't about to harness 8 bit color, at least I was able to get 3 bit color.

I hard coded a few colors into the bram and viola! they showed up in the screen!

below is the state machine I used to test my bram.  The purpose of this
state machine is to  add things to the BRAM and then the VGA timer would read that bram.
This snippit of code only showes how I added something new to the bram.

The screen showed 3 squares of the expected size.  However, there were some random artifacts such as dots being missing or dots being missing colored or dots being in places where they shouldn't.  I believe that
it is mainly a side effect of a poorly written process.  The snippit below was meant to be quick and dirty, so it is rather unorthodox.
--==========================================

process(clock)
constant max_val: integer := (hdisp_size*vdisp_size);
variable cnt: integer:= 0;
variable color_var: std_logic_vector(2 downto 0):= (others => '0');
type states is (init,x_sq, y_sq);
variable st: states := init;
variable x_var,y_var: integer:= 0;
variable coordinate:integer:= 0;
begin
if clock = '1' and clock'event then
case st is
when init => st := x_sq;
when x_sq =>
if x_var >= hdisp_size then st:= y_sq;
x_var := 0;
else st:= x_sq;
x_var := x_var + 1;
end if;
when y_sq =>
if y_var >= vdisp_size then st := x_sq;
y_var := 0;
else st := x_sq;
y_var := y_var +1;
end if;
when others => st:=init;
end case;
coordinate := x_var + y_var*hdisp_size;
if x_var >=0 and x_var < 15 and
y_var >= 0 and y_var < 44 then
color_var := red_c;
elsif x_var >= 20 and x_var < 300 and
y_var >= 40 and y_var < 200 then
color_var := cyan_c;
elsif x_var >= 300 and x_var < 320 and
y_var >= 200 and y_var < 240 then
color_var := green_c;
else
color_var := black_c;
end if;
end if;
write_data_s <= color_var;
write_addr_s <= conv_std_logic_vector(coordinate, write_addr_s'length);
end process;


--==========================

Next, I should try adding another Bram that will hold on to the objects.  As a small example I must use the coe file that was used to make mario.  Then I will have to use easyBMP to convert more pictures into their bram equivalent.

Sunday, July 15, 2012

quarter VGA (qVGA) 320 by 240 resolution

The default for vga is 640 by 480.  There are tons of documentation about how to get this timing correct and there are tons for larger resolutions.

However, there is hardly any mention of 320 by 240.

The reason I needed that resolution was because I needed to make a pixel matrix that would hold the color
value for each coordinate.  The pixel matrix exists in memory and unfortunately my spartan 6 doesn't have a lot of it.

The purpose of this blog entry is to document the qVGA timings that I have found through trial and error.


 hdisp_size = 320;  //This specifies the width of the screen
 hpw_size = 48; // pulse width
 hbp_size = 28; // back porch
 hfp_size = 4; //front porch

 hsync_period = 400//this specifies the number of clock ticks before going back to zero.  ie. 0 to 399


 vdisp_size = 240; // this specifies the height of the screen
 vpw_size = 1; //pulse width
 vbp_size = 15; // back porch
 vfp_size = 4; // front porch

 vsync_period =  260;// this specifies the number of clock ticks before going back to zero. ie 0 to 259

The h clock will tick every 80 ns
the v clock will tick every 63.84 us

The screen I was using was quite finicky when it came to the right pw, bp, or fp values, but after awile I started to notice a trend.

The screen should refresh 60 hz to 60.5 hz.
In reality I got 60.48 hz.

The numbers MUST conform to that timing constraint or else it will not work properly.
When the screen resolution was 640 wide, we would need to count up to 800.
At first I mirely set it to 320 wide and made it count to 800 (and increased the bp,pw,and fp to accomodate it).    This made big black margins
to appear on the left and right side of the screen

The same happened with the height.  Originaly i had it at 480 and had it count to 521.
Then I changed it to 240 and increased the bp,pw, and fp to keep the counter counting up to 521.
This made top and bottom margins.

Although it worked, i was more interested in taking over the entire screen.

The h_sync had to cycle every 32 us. which means that you have to count from 0 to 399 in 32 us.
originally would count to that number in 16us so I basically clock divided the h clk.

The v_sync had to cycle every 16640 us.  which means that you have to count from 0 to 259 in 16640 us.
I also clock divided the v_clk.


*****
important observation
******
for a long time I had been missing a margin.  I had thought my value for the fp,bp, or pw were offset.
but in reality, it was because I was sending color when I wasn't suppose to.  I tried sending the color outside of the 320*240 grid and as a result, the screen tried to adjust to fit it in.  The screen doesn't know where coordinate (0,0) is located so it will need to guess based on when it gets a color.  If this theory is true,
then it would be wise to always place a background.  A very light background.

Saturday, July 14, 2012

VGA with add shape, add image, with matrix transformations

After getting the VGA to work I've started to come up with a plan to
created a device that would show wither shapes or images to the screen.
I've decided that all the objects would exist as data on BRAM

At first I thought of using a "pixel matrix" which was a 640 by 480
std_logic_vector.  It was huge and synthesis too an extremely long
time.  I am not sure how long it would have taken because I did not
let it finish.  After 2 hours of letting it freeze and go.  I had to quit it.
If it was this complicated for the machine then it means I am doing
something really inefficient.

So then I thought of using bram.  I was hesitant because i remembered
that memory took a long time to synthesis too.  But BOY was a wrong.
It only took a few minutes to synthesize a memory of my choosing.
first I made a a bram  1 by 307200.  It worked but this method would
only allow black and white.  I tried 8 by 307200 , but unfortunately
I hit my constraint.  There wasn't enough ram in my device to do this.

Several ideas bounced around in my head.  maybe i could use some sort
of mux that would play with an FPGA object.

I scrapped that idea because it would lead to something rigid.  If I
wanted to add shapes via UART, then I would need to think of a
different plan.

The new plan was to get rid of the pixel matrix idea.  The idea was
to use opcodes to specify what shape it was or what image it was.
It would include the coordinates, the dimensions and/or some other pixel
data.  The rest of it would be generated by the fpga using a fancy
algorithm.  An algorithm that I haven't thought of at this moment.

There are two categories, shapes and images.  Images take up quite a lot of
space because each pixel needs to be accounted for.  Shapes don't take up
much space at all.  A square would probably take at most two words
to describe.

The header for both would have the same format.  The opcode would
differ in order to tell the control what it is dealing with.
Below is a pictorial version of what I am talking about:
                                 
                                   | upper left corner |
opcode | scale | rotate | x coord | y coord |
4 bit     | 3 bits | 5 bits | 10 bits   | 10 bits  |

A header would be one word and would contain the upper left corner,
the rotation factor and the scale factor.  These three pieces of information
are extremely value able and would be used in the matrix transformations.

These three pieces would have to affect the pixel data what would come
after it.  Remember how I said that a square would take as little as two
lines?  well the next line would be its pixel data.  One way i can do it
is by specifying the width and the height.  However, if I want a shape
that is more custom I would have to specify the coordinates of the points.
Here is a new idea that might be better.

What if I wanted to make a parallelogram?  The width and the height
would be used to set the dimensions of the "plate" that the shape
will be on.   The points would exist in relation to the "plate"
if it was a 10 by 10 plate then I would specify the points as if I was
drawing on a 10 by 10 grid.

ie.  a triangle on the 10 by 10 grid  p1(2, 4) p2(0,10) p3(10,10)

When I move the triangle all I have to do is move the plate.  the points
would not have to change.  They are in relation to the plate, so if the plate
moves, the points move with it.  Everything would be in relation to that
upper left corner.  So theoretically, I should be able to rotate everything
and scale it.

images would be a similar story.except that all the pixels of the image would
be considered a point.  it would be a point on the "plate".  the points
would exist in relation to the upper left corner.  The side effect is that they
take up a lot of space.

in order to deal with this i needs to separate the shapes from the
images.  the images would have a larger page and the shapes would
have a smaller page.

I believe the limit is 900000 bits  so i have to divide it up in a way that
can help share the ram.

for shapes
32*(8)*(2**6) = (wordsize)(shape _lines)(shape pages)

each word is 32 bits.  the number of lines it is allowed is 8.  the number
of pages allowed is 64.  that would take 16k bits.

for images
32*(2**10)*(2**3)  = (word size)(image_lines)(image pages)

each word is 32 bits.  The number of lines it is allowed is 1024.
The number of pages allowed is 8.  That would take about 262144 bits

======
before i forget, the line right after the header should be about the
dimension of the plate.  it will always be a rectangle.

So tell me again about how the pixel data is suppose to look like?
I have two choices

choice 1
opcode | color | relative x | relative y |
4 bits    | 8 bits | 10 bits     | 10 bits     |

choice 2
opcode |    | color |    | color |    | color |
4 bits    | 2 | 8 bits | 1| 8 bits | 1 | 8 bits |

choice two would be ideal for space saving.  It might be good
for images.  It would be as if I am naming each color of pixel
from left to right; top to bottom.

The first choice would name a spot on the plate to color.
This would be best for shapes.  but it can also be used for images.
This would be a good choice because everything would be similar
and require less components to decipher it.  it also brings ups the
possibility of shading it in a polygons.


=====
Eventually I'll have to decide  on which one to pick in order flesh everything out.

Once I have it I can start fleshing out the components that I will need in order to make this dream a reality.  Gosh, I never thought I'd be diving in to operating system concepts
just to do this.  I'm glad that i am thought.  It makes me think
as a computer scientist.  I'm glad that this very important class
is coming back up.  It lets me practice the idea of paging.

HA! maybe this is a step toward making an of run onto of the
FPGA after i get a cpu to start running on it.  I could probably use
the BOOK's code and from there I dunno I haven't thought that
far out.

vga


It is a wonderful day because I have figured out the vga timer once again.  
The problem probably had something to do with the PES clock.
The first few moments, the output would be undefined.  The
screen I tested on probably saw that undefined ness and put up
a flag that said "problem" and refused to work.  After I took
care of that problem it all started to work.  Its funny how that little 
small start of undefined signal messed everything up.

Another thing that contributed to the problem was that the h counter and
v counter were not counting at the right time.  The v counter should 
increment when ever the h counter was reset to zero.  But for some 
reason, it would increment when h counter reached 400.  

These two problems were eventually solved.  The first one was solved 
by modifying the pes_clock such that  clock_out was given its value soon
after starting up.  It used to have to wait until the process reached its 
max count before giving it a value.

The second was solved by making the the v counter count on the
falling edge of the v_clk.  Even though it gave a warning during synthesis
all I care is that it works.

Tuesday, June 26, 2012

Mixing VHDL and verilog modules

INTRO
I have successfully been able to mix both VHDL modules and Verilog modules together.  Honestly it is a lot easier then I had thought it would be.  Since I could not find detailed examples of this phenomenon, I had to experiment with how it would work out.  The examples that I found were all wrong, but they gave enough of a hint to figure it out on my own.  I'm quite sure there are many people that need to know this so if you are here, you are in a good place.

ABSTRACT
A simple Verilog top module was crafted as a 2 bit full adder.  The internal components would be a verilog one bit adder and VHDL one bit adder.  They got connected in the verilog top module and were successfully testbenched and synthesized.  Did I mention that I used a testbench written in vhdl to test the 2 bit FA verilog top module?

Also as a second pass, I created a simple VHDL top module that was crafted as a 2 bit full adder.  The internal components would ALSO be a verilog 1 bit full adder and vhdl 1 bit full adder.  They got connected in the vhdl top module and they successfully testbenched and synthesized.

CODE
Below is the code that was used to create the described 2 bit adders.  Hopefully it will demonstrate how easy it is to go from one language to the other.
=====================
-- 1 bit FA in VHDL
--------------------------------

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

entity FA_VHDL is
    Port ( A,B,CIN : in  STD_LOGIC;
           COUT,S : out  STD_LOGIC);
end FA_VHDL;
architecture Behavioral of FA_VHDL is
begin
--concurrent implementation of a 1 bit full adder.
--Statements outside of a process are considered concurrent
S <= A xor B xor CIN;
COUT <= (A and B) or (A and CIN) or (B and CIN);

--Alternative implementation with a use of sensitivity list.
--This block will only execute when the items in the sensitivity list change
-- FA : process (A,B,CIN)
-- begin
-- S <= A xor B xor CIN;
-- COUT <= (A and B) or (A and CIN) or (B and CIN);
-- end process;
end Behavioral;



=====================
--1 bit FA in verilog
--------------------------------

`timescale 1ns / 1ps
module FA_v(
A,B,CIN,
COUT,S);
//------------
input A,B,CIN;
output COUT, S;
// reg COUT,S; // uncomment if using "always block"
//----
//This makes the logic happen continuously
assign S = A ^ B ^ CIN;
assign COUT =  (A & B)  | (A & CIN) | (B & CIN);

//Alternative implementation with a use of sensitivity list.
//This "always block" will only execute when the items in the sensitivity list change
// always @ (A or B or CIN)
// begin
// S <= A ^ B ^ CIN;
// COUT <=  (A & B)  | (A & CIN) | (B & CIN);
// end
endmodule


=====================
--2 bit FA in verilog with internal components: 1 bit verilog fa and 1 bit vhdl fa
--------------------------------

`timescale 1ns / 1ps
`default_nettype none

module Verilog_2bit_adder(
A2b,B2b,CIN2b,
COUT2b,S2b
);
//define pins
input [1:0] A2b,B2b;
input CIN2b;
//define ports
output COUT2b;
output [1:0] S2b;
//Specify internal wire
wire carry_w;
FA_v verilog_full_adder(
.A    (A2b[0]), // ".A" specifies the Pin of the component. "A2b[0]" specifies the thing that is connecting to that pin
.B    (B2b[0]),
.CIN  (CIN2b),
.COUT (carry_w),
.S    (S2b[0])
); //for bit0
FA_VHDL VHDL_full_adder(
.A    (A2b[1]),
.B    (B2b[1]),
.CIN  (carry_w),
.COUT (COUT2b),
.S    (S2b[1])
);//for bit1
endmodule


=====================
--2 bit FA in VHDL with internal components: 1 bit verilog fa and 1 bit vhdl fa
--------------------------------

library ieee;
use ieee.std_logic_1164.ALL;
use ieee.numeric_std.ALL;

entity VHDL_2bit_adder is
   port ( A2b    : in    std_logic_vector (1 downto 0);
          B2b    : in    std_logic_vector (1 downto 0);
          CIN2b  : in    std_logic;
          COUT2b : out   std_logic;
          S2b    : out   std_logic_vector (1 downto 0));
end VHDL_2bit_adder;

architecture BEHAVIORAL of VHDL_2bit_adder is
   signal carry_s : std_logic;
   component FA_v
      port ( A    : in    std_logic;
             B    : in    std_logic;
             CIN  : in    std_logic;
             COUT : out   std_logic;
             S    : out   std_logic);
   end component;
 
   component FA_VHDL
      port ( A    : in    std_logic;
             B    : in    std_logic;
             CIN  : in    std_logic;
             COUT : out   std_logic;
             S    : out   std_logic);
   end component;
 
begin
   verilog_full_adder : FA_v
      port map (
               A=>A2b(0),
               B=>B2b(0),
               CIN=>CIN2b,
               COUT=>carry_s,
               S=>S2b(0)
);
 
   VHDL_full_adder : FA_VHDL
      port map (
               A=>A2b(1),
               B=>B2b(1),
               CIN=>carry_s,
               COUT=>COUT2b,
               S=>S2b(1)
);
 
end BEHAVIORAL;




=====================
--vhdl test bench
--------------------------------

-- Notes:
-- This testbench has been automatically generated using types std_logic and
-- std_logic_vector for the ports of the unit under test.  Xilinx recommends
-- that these types always be used for the top-level I/O of a design in order
-- to guarantee that the testbench will bind correctly to the post-implementation
-- simulation model.
--------------------------------------------------------------------------------
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--USE ieee.numeric_std.ALL;

ENTITY VHDL_two_bit_adder_TB IS
END VHDL_two_bit_adder_TB;

ARCHITECTURE behavior OF VHDL_two_bit_adder_TB IS
    -- Component Declaration for the Unit Under Test (UUT)
    --COMPONENT Verilog_2bit_adder --testing uncomment to test verilog
COMPONENT VHDL_2bit_adder
    PORT(
         A2b : IN  std_logic_vector(1 downto 0);
         B2b : IN  std_logic_vector(1 downto 0);
         CIN2b : IN  std_logic;
         COUT2b : OUT  std_logic;
         S2b : OUT  std_logic_vector(1 downto 0)
        );
    END COMPONENT;
   --Inputs
   signal A2b : std_logic_vector(1 downto 0) := (others => '0');
   signal B2b : std_logic_vector(1 downto 0) := (others => '0');
   signal CIN2b : std_logic := '0';

  --Outputs
   signal COUT2b : std_logic;
   signal S2b : std_logic_vector(1 downto 0);

signal clock : std_logic := '0';
   constant clock_period : time := 10 ns;

BEGIN

-- Instantiate the Unit Under Test (UUT)
--      uut: Verilog_2bit_adder PORT MAP ( --uncomment if using verilog component
        uut: VHDL_2bit_adder PORT MAP ( -- uncomment if using VHDL component
          A2b => A2b,
          B2b => B2b,
          CIN2b => CIN2b,
          COUT2b => COUT2b,
          S2b => S2b
        );

   -- Clock process definitions
   clock_process :process
   begin
clock <= '0';
wait for clock_period/2;
clock <= '1';
wait for clock_period/2;
   end process;


   -- Stimulus process
   stim_proc: process
   begin
      -- hold reset state for 100 ns.
      wait for 100 ns;
A_loop: for A in 0 to 3 loop
B_loop: for B in 0 to 3 loop
CIN_loop: for CIN in 0 to 1 loop
A2b <= conv_std_logic_vector(A, 2);
B2b <= conv_std_logic_vector(B, 2);
if CIN = 1 then
CIN2b <= '1';
else
CIN2b <= '0';
end if;
wait for clock_period;
assert (A+B+CIN = conv_integer(COUT2b&S2b)) report "This isn't right" severity error;
end loop CIN_loop;
end loop B_loop;
end loop A_loop;
      -- insert stimulus here

      wait;
   end process;

END;









Saturday, June 23, 2012

python in xcode 4



  1. Open Xcode 4.
  2. In the menu bar, click "File" → "New" → "New Project…".
  3. Select "Other" under "Mac OS X".
  4. Select "External Build System" and click "Next".
  5. Enter the product name.
  6. For the "Build Tool" field, type in /usr/local/bin/python3 for Python 3 or /usr/bin/python for Python 2 and then click "Next". Note that this assumes you have Python installed in the typical location(s). if you are unsure as to where your Python executables are enter these commands into Terminal: which python3 and which python.
  7. Choose where to save it and click "Create".
  8. In the menu bar, click "File" → "New" → "New File…".
  9. Select "Other" under "Mac OS X".
  10. Select "Empty" and click "Next".
  11. Navigate to the project folder (it will not work, otherwise), enter the name of the Python file (include the ".py" extension), and click "Save".
  12. In the menu bar, click "Product" → "Edit Scheme…".
  13. Click "Run" in the left column.
  14. In the "Info" tab, click the "Executable" field and then click "Other…".
  15. Navigate to the executable from Step 6. You may need to use ⇧⌘G to type in the directory if it is hidden.
  16. Select the executable and click "Choose".
  17. For the "Debugger" field, select "None".
  18. In the "Arguments" tab, click the "Base Expansions On" field and select the target that is named the same as your project.
  19. Click the "+" icon under "Arguments Passed On Launch". You may have to expand that section by clicking on the triangle pointing to the right.
  20. Type in $(SOURCE_ROOT)/ and then the name of the Python file you want to test. Remember, the Python program must be in the project folder. Otherwise, you will have to type out the full path (or relative path if it's in a subfolder of the project folder) here. If there are spaces anywhere in the full path, you must include quotation marks at the beginning and end of this.
  21. Click "OK".
  22. Start coding.
Note that if you open the "Utilities" panel, with the "Show the File inspector" tab active, the file type is automatically set to "Default - Python script". Feel free to look through all the file type options it has to gain an idea as to what all it is capable of doing. The method above can be applied to any interpreted language. As of right now, I have yet to figure out exactly how to get it to work with Java; then again, I haven't done too much research. Surely there is some documentation floating around on the web about all of this.
Say, "Hello, code completion, auto-indentation, and syntax highlighting." Note that it's not as advanced as it is with C, C++, or Objective-C but it is better than using IDLE in my opinion.
---------------------


original link
http://stackoverflow.com/questions/5276967/python-in-xcode-4