wildgoose 420 Practically a Posting Shark

Look for data not set! You should probably have a difference between a debug and release build as well. Data will be initialized differently. Also running within an I.D.E. will move code around in memory!

Also look for a memory overwrite. Writing past the end of allocated memory. Check for unhandled errors.

Single-step your code!

Ancient Dragon commented: good answer +28
wildgoose 420 Practically a Posting Shark

Have you plotted this on paper?
esi is 1st node
edx is next node
esi[0] save data
esi = edx
esi[1] save data

esi[5] save data
esi=edx
esi[6]=0 <---- mov [esi].LLNode.NodeData, 0
You're writing into index #6, which is a stack overwrite.

wildgoose 420 Practically a Posting Shark

Almost.

That's your initial get the code working step.
Then, once it works, since the text is alpha sorted, and the records are fixed size, do a binary search.

Look a record COUNT/2, Is it, above or below, Divide in 1/2 try again.

So essentially very fast command search since they're alpha sorted.

wildgoose 420 Practically a Posting Shark

There's usually hundreds of commands in a scripting language so would mean more like...

iApple = 1
iPear = 2
iCorn =3
iDog = 4
iGrape= 5

xApple db  'Apple',0
xCorn   db  'Corn',0
xDog    db  'Dog',0
xGrape  db  'Grape',0
xPear    db   'Pear',0

Food STRUCT
Id     DWORD   ?
Name   DWORD ?
     ENDS


; Alpha sorted for speed
Label FoodTable
   Food < offset xApple, iApple >
   Food < offset xCorn, iCorn >
   Food < offset  xDog, iDog >
   Food < offset  xGrape, iGrape >
   Food < offset  xPear, iPear >
LabelFoodTableEnd

Being alpha sorted, the matching command record can be found quicker.
Then use the eumerationId for a code vector table.

jhouns commented: amazing +1
wildgoose 420 Practically a Posting Shark

I think you misunderstand the syscall function. It doesn't return a four byte integer. It returns a string!
You also aren't setting $a1 to maximum number of characters to read - 1. The function returns the string with a NULL terminaton.

$a0 = buffer
$a1 = sizeof buffer - 1
$v0 = 8 Function read string.

think you meant $v0 = 5 ? Upon return $v0 contains integer read!

zmwg commented: Thank you~ +0
wildgoose 420 Practically a Posting Shark

You have a problem with the MARS library.

li $v0,1 Print integer
mov $a0,$s0 a0 is integer
syscall <--- MISSING

li $v0,10
syscall #exit

shopnobhumi commented: helpful +1
wildgoose 420 Practically a Posting Shark

Sorry, what you need is someone with a lot of free time to help you out.

First, code tags!
Second, COMMENTS! Your code is all crammed together with no comments. One has to understand fully what your code is doing before they can truly help you!

Once you fix that, and make it more clear exactly what your problem is, then help can be provided!

Salem commented: Good answer - the code is truly awful to look at. +36
wildgoose 420 Practically a Posting Shark

I don't understand your question. If you have to clear it yourself and are working in an old style Real Mode code where the BIOS services are exposed.

I'm kind of rusty at this...

mov ax,0b800h     ; Assuming text screen not graphics
  mov  es,ax
  mov di,0
  mov  cx,25*80
; mov  ax, ???
  mov al, 0               ; 0 or ' '   I forget which
  mov ah, ????        ; Attribut byte ?

Clr:   mov   es:[di],ax        ; Write text char and attribut byte
   add di,2
   dec cx
   jne Clr
wildgoose 420 Practically a Posting Shark

You aren't saying what's happening, and you aren't mentioning your toolset.

See if <buffer> is in its own segment or sitting at 0100h in the code instruction pointer path!

buffer db 10,?, 10 dup(' ')

	; Get Buffered Keyboard input
	mov dx, offset buffer
	mov ah, 0ah   ; Command Buffered Keyboard Input
	int 21h      ; DOS interrupt
          ; 0:bufsize, 1:char count, 2...N buffer

	xor bx,bx
	mov bl, buffer[1]

;	mov buffer[bx+2], '$'
	mov buffer[bx+1], '$'    ; Replace carriage return with terminator

	mov dx, offset buffer + 2
	mov ah,09
	int 21h
;;;;	ret

	mov ah,4ch
	int 21h
Nick Evan commented: Nice to see someone with knowledge of ASM +27
wildgoose 420 Practically a Posting Shark

I realize English isn't your primary language but you need to try better as your request is not clear!

You covered up your code so we can no longer see it!
DOS used a '$' terminator so if you're trying to reference an ASCII string
'0123456789$'
It thinks you're trying to assemble commands?

I don't use EMU8086 but I believe the edit is only for source commands. It is not the DOS debugger (debug.exe)

Normally it is like the following:

org $100
   mov ah,9
   mov dx,msg    ; Print string$
   int 21h            ; DOS Interrupt

   int 20h           ; DOS terminate

msg:   db    '0123456789$'
Nathan Campos commented: Thanks Very Much! +1
wildgoose 420 Practically a Posting Shark

Yes, $v0 $v zero $vo is a mistake!

There are many languages out there. Some companies build applications using Java. Some C, Pascal, Visual Basic, Basic, Fortran, Cobol (though fewer and fewer), Some using C++. Some whom don't despise Microsoft use C#. And others!

But I'd have to say C++ is the primary language for the past few years. It has problems but they too difficult.

"As the Ogor said, An Ogor is like an onion. They have Layers!"

Wel so do Object Oriented Languages like C++.

I recommend you work on your debugging skills. And yes, take a C++ class. There are lots of people almost always on hand to jump in and help you out, as long as you post code you attempted. And learn to debug! It is a tad irritating when a poster could have solved their own problem if they only ran the debugger and looked at what the code was doing! Next session classes starts in a week or two. Sign up for the class and buy the book now and start experimenting from page 1.

And there's a biggy. You may have noticed that I would go away for awhile, come back, review the latest code drop and find things to change! Programming to some is a chore. Programming to some is an art form. The idea is to polish.

Read up on the Japanese method of Kaizen. Quality throught thousands of changes!

Nick Evan commented: You should get a medal for this thread :) +28
tux4life commented: Agree with niek_e :) +21
wildgoose 420 Practically a Posting Shark

Since this is no longer a school project I went in and cleaned top to bottom. You need to finish at bottom where indicated.
Review each section of code and understand how it works!

.data # variable declarations follow this line
iSAFE: 1
iCHASM: 2
iTRAP: 3
iDESTINATION: 4

maze: .space 144 # 9x9 stored in a 16x9 buffer 
robot_x: .word 0
robot_y: .word 0
robot_m_x: .word 0
robot_m_y: .word 0
robot_state: .word 0
robot_instructions: .space 64

# Robot State Message Table
MsgRobotTbl:		
		.word		MsgRS1
		.word		MsgRS2
		.word		MsgRS3
		.word		MsgRS4
		.word		MsgRS5
MsgFailsDestination: .asciiz "Robot fails to reach Destination\n"

MsgRS1: .asciiz "Robot is at a safe place\n" 
MsgRS2: .asciiz "Robot falls into Chasm\n"
MsgRS3: .asciiz "Robot falls into the trap\n"
MsgRS4: .asciiz "Robot reaches Destination\n"
MsgRS5: .asciiz "Robot fails to reach Destination\n"
MsgFinal:	.asciiz "Robot final location X: "
MsgY:		.asciiz " Y: "
MsgCR:		.asciiz "\n"
MsgRobotState:  .asciiz  "Robot State: \n"
MsgFallenChasm:  .asciiz  "Robot has fallen into a chasm\n"
MsgFallenTrap:   .asciiz  "Robot has fallen into a trap\n"
MsgReachedDestination:  .asciiz  "Robot has reached Destination\n"
MsgSafePlace:    .asciiz  "Robot is at a safe place\n"
MsgFallsChasm:	.asciiz   "Robot falls into Chasm\n"
MsgFallsTrap:   .asciiz   "Robot falls into the trap\n"
MsgReachesDestination: .asciiz "Robot reaches Destination\n"

.text # CODE SECTION OF ASM FILE

#main:
	li $v0,30 			# Get time
	syscall 			# CMD: Get Time
		# $a0 = lower 32-bits, $a1=upper 32-bits

		# Seed RNG (Random Number Generator)
	move $a1,$a0 		# get lower 32-bit time as seed
	li $a0,0 			# Rng#0
	syscall 			# CMD: Seed …
Salem commented: Phew!, what a marathon thread!, that's dedication. +36
wildgoose 420 Practically a Posting Shark

bool gFlag = true;

Event sets flag to false, and causes thread to fall out of loop!
Simple but effective!


// while (true){

while ( gFlag ){

Don't sleep your thread so long.

If you need 1000ms timing then

int nSnooze = 1000;

while ( gFlag )
{
     Sleep(25);
     nSnooze -= 25;
    if (nSnooze > 0)
    {
        continue;
    }

     nSnooze = 1000;
     DoSomething();
}
toucan commented: A simple and elegant solution that I made use of. +2
wildgoose 420 Practically a Posting Shark

good luck however if the server was written properly, the client is merely a playback. It can only request things of the server and its the servers job to validate a message, detect an invalid message, then log it and notify a service rep about a possible violation of rules!

Schoorsteen commented: You've been very helpful. +1
wildgoose 420 Practically a Posting Shark

I think you're all missing the point. Sockets doesn't send immediately.

Send Packet 5
Send Packet 8
Send Packet 7

It won't necessarily arrive as three packets 5 then 8 then 7 bytes in length.
It may arrive as 2 packets 5+8=13 and 7
or 5 and 15
or a single packet 20 bytes long!
The packet is sent on an interval basis, not immediately so sometimes packets get combined as a single packet of multiple messages!

So instead!

void filter( char* packet, uint nPacketLen )
{
    while (nPacketLen)
    {
         while ((*packet != 0) && nPacketLen)
        {
	cout << "(" << int(*packet) << ")";
               packet++;
               nPacketLen--
       }
        cout << endl;
   }
}
wildgoose 420 Practically a Posting Shark

Good for you. Stay on Honors Science and Math all the way through High School, get your Calculus and Physics wrapped up so you can slide right into a University Engineering program. You'll then need to decide to go Computer Science, or Computer Engineering, or other Enginnering fields such as Electronics. If your school has a Robotics Club such as Vex, join it! It will help puff up your University admissions.

Game programmers really don't use .NET, we use GNU for Sony, and the .NET Visual Studio but not .NET architecture. That is more for system application development.

Being very very good is semi-job security in game development, but there's always someone better. While you're bogged down writing a game to get out the door, technology advances and then you're behind trying to catch up. You have to resort to leap frogging technolgy waves to technology waves.

What I'm trying to say is having a Bachelors degree from an Academic University more doors will be open to you throughout your life. Don't jump school early to get into games because 15 or so years later you'll look up and find it difficult to try to go back to school and finish your degree. There is stigma attached to Academic degrees versus I.T. degrees. Game Development vs Engineering.

DangerDev commented: nice answer +3
wildgoose 420 Practically a Posting Shark

Do you carry a cell phone?
Do you own a microwave oven?
Do you have a game console?
Do you have a television set?
Do you own an automobile?
etcetera
There you go!

Salem commented: That's where it's at :) +36
wildgoose 420 Practically a Posting Shark

While driving into work I realized I had a bug.

// strrev( q+j, i )
strrev( q+j, i-j )

Hiroshe commented: Your dedicated to the right solution. +4
wildgoose 420 Practically a Posting Shark

It's on main().
0 means successful.
else error!

no1zson commented: thanks +3
wildgoose 420 Practically a Posting Shark

these are only some of your problems!


You don't want 11 pointers, you want 11 tallies!

//     int *arrayptr [11];
    int arrayptr [11];

Shouldn't you pre-clear your tallies?

//    for (control = 0; control < 12; control++) 
//       arrayptr[control] = &timesrolled[control];
   for (control = 0; control < 11; control++)
           arrayptr[control] = 0;

So you're using two seven sided dice?
Change your...

//                 die1 = rand()%7;   // 0...6
//                 die2 = rand()%7;
                 die1 = rand()%6;   // 0...5
                 die2 = rand()%6;   // 0...5
                total = die1 + die2;  // 0...10
//               *ptr[total - 2]++;
                 *ptr[ total ]++;
patrick k commented: Very helpful post. Helped me understand where my mistakes were. +1
wildgoose 420 Practically a Posting Shark

Looks like a 32 byte hash.

But sknake is more likely correct!

wildgoose 420 Practically a Posting Shark

This definitely sounds like a homework assignment!
Key here is you said lottery game.

So sounds like you need a card shuffle algorithm for a deck of 49 cards, but you're only going to draw the first five cards.

So assuming 49 balls in the deck!
char balls[49];
Now initialize so that they're sequential.

0,1,2,3 .....      46,47,48
[0][1][2][3] ....   [46][47][48]

Now run the shuffle.

For i = 0 to 49-1 step 1        // Shuffle the deck
     nBall = i + (rand() % (49-i));
     tmp = balls[i];                 // swap index with randomized index
     balls[i] = balls[ nBall ];
     balls[ nBall ] = tmp
end for

Now you have a shuffled deck.
To deal

for i = 0 i < 5
     TheBall is balls[i]
end for

Technically, you need to only shufle the first five balls, but shuffle the entire deck anyway!

Sky Diploma commented: Nice Explaination. I guess I learned something new. +6
kvprajapati commented: Nice explanation. +10
wildgoose 420 Practically a Posting Shark

Another way to think of this, look at the index of a book. A book about animals. So in the Index lookup bears. Bears is on page 32.

If you go to page 32 you see the topic Bears.

The index in the back of the book is the label. The page number is the pointer at that label.

yellowSnow commented: That's a good little analogy. +1
wildgoose 420 Practically a Posting Shark

We don't need to give you only. Cruise the posts and pick out a few you like!
And then do them yourself!

wildgoose 420 Practically a Posting Shark

Shouldn't you buy the Code Composer Studio IDE from Texas Instruments for their MSP430 processor? (Or atleast download their evaluation version available on their website?)

Or look into the GCC ToolChain?

jephthah commented: insightful. you also, at this moment, have 420 posts. +14
wildgoose 420 Practically a Posting Shark

Your key delay is too short 50/1000 = 20/second
Should be around 200. Use a 5

You need edge triggering.

swLast = getbits

loop:
sw = getbits
swEdge = sw ^ swLast
swLast = sw;

So now, a button JUST down, or button JUST up will have their bit in swEdge set.

So for button down

So for button down
swD = swEdge & ~sw
if (swD & 1) then 1st button just pressed

if (swD & 2) then 2nd button just pressed


So for button up
swU = swEdge & sw
if (swU & 1) then 1st button just released

if (swU & 2) then 2nd button just released


So does that help?

jephthah commented: nice job +14
wildgoose 420 Practically a Posting Shark

Of course it doesn't work. You were suppose to analyze what I did, review your code, and single-step, etc. and make appropriate changes! One typically doesn't learn by being handed the answer. They typically need to be nudged into the correct direction so they can hopefully find the answer themselves!

Did you analyze what putpix does? If you had you would have seen that it uses bx for the offset calculation for the 256 color pixel write. You were using the BIOS call before, but now you are writing directly to memory.

What two registers are you passing in? AND what registers are pixel write using?

What processor are you using? This may be 16-bit 8086 code but are you running on a modern day Pentium type or an old 8086 through 80486? If a newer computer then using the old shifting for the multiplication is a mistake! On the older processors multiple shifts waas MUCH faster then a multiply. But on the newer processors it is quite the reverse of that!

I don't like heavy macros like you're using because of this kind of mistake. YOU DO NOT NEED TO KEEP RESETTING ES to the Video segment!!! You aren't using it anywhere else, so set it at your code initialization, and not in the write for each pixel!

Second, You aren't calling a function to plot each pixel so why are you using real X and real Y for each pixel write?

How …

wildgoose 420 Practically a Posting Shark

So you have no electronics background so you're looking for off the shelf components so as to build your project. You want to do sensor monitoring but keep focusing on a camera, which you really don't need. You in essence need to detect existence of a vehicle. The camera will be good for detecting motion. Have you investigated various security equipment available? Get an Ultrasonic detector and hook it up to a GPIO board, which is linked to your PC. The GPIO board can monitor multiple sensors, not just one. The only electronics required then would be wiring the harnesses. Though you could build an electronic circuit using a PIC but you can find the embedded board. Try www.digikey.com or www.mouser.com or a company like that!

wildgoose 420 Practically a Posting Shark

If the multi-threaded script controls multiple threads simultaneously then the answer is yes.

For example if I want to write a program designed to crunch data and turn it from one form into another, but I still want to be able to use the computer to run other applications then I'll only task up to 1/2 or 3/4 the machine with the task to do using worker threads. Or I'll just task one thread with the crunch application. But if I want to use every computing cycle I can on the task then I'll launch an appropriate number of worker threads. Available CPU after that is typically around 0%.

Even if you think this kind of task will only be run light (meaning one thread) you should write it multi-threaded so that you can flip a soft switch to crank it up, or slow it down, just in case you need to run a GUI or something. It won't be very responsive acknowledging the slowdown however! You'll find that you will still need to insert micro-naps into each workers thread in your multi-threaded code so that they'll work well among themselves!

shadwickman commented: Great knowledge of architecture and design +4
wildgoose 420 Practically a Posting Shark

You need to analyze one record of data for maximum bit requirements each field.
And need to know exactly what data ranges are stored in the floating-point.

llemes4011 commented: Thanks for all your help, I'm sorry I don't understand it better >.< +1
wildgoose 420 Practically a Posting Shark

What Tux4Life said!

But would make sense to store the string size so future strlen() requests of your string in class only needs to return the value. Not look it up!

MyString::MyString(const char* s)
{
        stringSize = strlen(s);
        szString = new char[ stringSize + 1];
        strcpy ( szString, s );
}
tux4life commented: Yes that would be better :) +13
wildgoose 420 Practically a Posting Shark

Okay looked at your BMP loader and noticed a big problem. I went into one of my full blown BMP loaders and twiddled yours specific to 24-bit RGB bitmaps.

Problem #1 - you were treating header data as pixel data!
Problem #2 - BGR vs RGB
Problem #3 - You had to hardcode your bitmap resolution instead of using the values set int the bitmap.

This is more like a hack but it'll fix your bitmap issue!

Note that I left your width, height, and depth to be passed in to the function but I actually ignore them as they are read from the file itself!

//
//	BMP version 3.x header
//

#pragma	pack(1)
typedef struct Bmp3XHead_Type
{
	unsigned short	ImageFileType;			// File Identifier (always 0)

	unsigned int	FileSize;				// Size of files in bytes
	unsigned short	Reserved[2];
	unsigned int	ImageDataOffset;			// Start of image data offset
} Bmp3XHead;
#pragma pack()



//
//	BMP version 3.x informational header
//

#pragma	pack(1)
typedef struct Bmp3XInfo_Type
{
	unsigned int	HeaderSize;		// Size of this header
	unsigned int	Width;			// Width of image
	unsigned int	Height;			// Height of bitmap in scanlines
	unsigned short	Planes;			// # of color planes
	unsigned short	Depth;			// # of bits per pixel
	unsigned int	Compression;		// Type of compression
	unsigned int	ImageSize;		// Size of bitmap in bytes
	unsigned int	HRes;			// Horizontal Resolution in pixels/meter
	unsigned int	VRes;			// Vertical Resolution in pixels/meter
	unsigned int	nColor;			// # of …
orangejuice2005 commented: Thank you, thank you thank you! +2
wildgoose 420 Practically a Posting Shark

Looks good. But in actual development you would return a value. Needing to return 2nd to Nth values would involve passing pointers or dereferencing.

Something to keep in mind about dereferencing. From the calling function's viewpoint you don't realize that you're actually passing the pointer and not the value, unless you remember that's the way it works. Always a good idea to put a comment referring to passing the reference on the function call!

Cloneminds commented: Thanks for your help! +1
wildgoose 420 Practically a Posting Shark

BOOM! That's a technical term!

Your pointer needs to be pointing at real data!

int  *k, v;
       k = &v;            // k now points to the address of {v}.
       *k=10;           // So we are now storing the value
                            // reference by k, meaning v is now equal to 10.
jephthah commented: correct +12
wildgoose 420 Practically a Posting Shark

A long time ago in a far away land there was a castle the peasants called the crt. It was great but soon it was too small for the growing hordes of dots and so the king called to the lands for workers to make his kingdom larger and thus came for the pix'ies. They waved their wands and rows upon rows of individual dots came forth. This too wasn't enough as other kingdoms sprouted forth with their castles and soon there was war between the castles all trying to make bigger castles. Some kingdoms were destroyed others were anew. The workers in the new castles were too slow and so the vp's came forth and build machines that worked together to make the workers work faster. But it still wasn't fast enough so the Kings keep pushing their workers to build faster and faster machines.

Salem commented: Excellent! +36
wildgoose 420 Practically a Posting Shark
char *extract(int *pos, char *array)

static   char output[11] = {0};
  int max = (*pos) + 10, count = 0;

     // Need a terminator detection or will overrun the buffer
    // on last 10 character run if fewer then 10 chars!
   while(( 0 != array[*pos] ) && (*pos < max)) 
  {
    output[count] = array[*pos];
    count++; 
   (*pos)++;
  }

  return output;
}

NOTE: It makes code ugly by continuosly using contents of pointer
(*pos) for an integer.
instead copy the integer to a local variable and copy back the solution.

unsigned int nCnt = *pos;

           use nCnt

*pos = nCnt;
Hiroshe commented: Lot's of help. Thanks +2
wildgoose 420 Practically a Posting Shark

Also only doing divisor by 2 is not valid because a number may be divisable by 2 but not by another even number.

How about 198 % 2 okay, then 198 % 4 ?

Hiroshe commented: Thanks =) +2
wildgoose 420 Practically a Posting Shark

Alternatively how about each name in your list has a dynamic array of file offsets! Parse the file once and collect the file positions and store them in each's offset list. When done parsing, use list to find the string in the file.

Use a fixed size like 100 or some other number to 'grow' the list when it becomes full, and maintain an insertion count. When the list becomes full, grow the list, copy the list, and continue on!

wildgoose 420 Practically a Posting Shark

#include <crtdbg.h>


// Add this to the termination code!

#ifndef NDEBUG
_CrtDumpMemoryLeaks( );
#endif

wildgoose 420 Practically a Posting Shark

You'r entering goals as strings but you aren't comparing the integer values of those strings.

tux4life commented: Indeed :) +9
wildgoose 420 Practically a Posting Shark

Oh, gotta run, but finally!

float foperand1 = 0.0725f;
float foperand2 = 0.075f;
float foperand3 = 0.0775f;

The constant float is a double unless a (f) is appended! Thus you have a compiler error of precision loss. Also ALWAYS insert a leading zero, never a (.) by itself. It can get lost!

Ancient Dragon commented: good advice -- and you are right about %i +36
wildgoose 420 Practically a Posting Shark

As a rule of thumb keep code on separate lines. There is no executable savings and concatenating the lines hides problems such as in your case!

"%i" Hmm! I'll have to look that one up. May be compiler specific!

jephthah commented: good advice +11