Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

What sort of help do you need?

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

You have Derby configured to work with your development tools, right? That probably means that it is going through JDBC, which makes for a nicely standard API. OK, then. What do you need help with?

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Good points, to be sure, but I was hoping to hear from the OP about their reasons.

Actually, my assumption was that the OP didn't know SQL, and had done all the data access iteratively in DAO or ADO, but I wanted to know if that was the case or not. Since the OP said "I'm not porting them to SQL", I wasn't sure if that meant any SQL or just MS SQL Server. I would in the latter case recommend an open-source option such as SQLite or MySQL, and see if those were suitable choices.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

No, it isn't possible in C (it can be done in C++, using operator overloading, but it would require you to write the overloaded operator function). The solution is to write a function that acts similarly, by walking through the list a fixed number of nodes.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

If you don't mind me asking, why is it you can't (or won't) shift to a different DBMS? Access itself is a SQL RDBMS, if a very limited one; it should not be difficult to port the data, at the very least, over to MS SQL, and relatively easy to go to most other RDBMSes like MySQL. I assume that you have a reason that you won't, but I am curious what that reason is.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

I see. That's an unfortunately common problem, and frankly, the best solution is to walk out of the course, making sure the instructor knows why you are getting out. You aren't going to learn anything useful in it if the professor insists on using obsolete technology. However, it is disgusting common for IT departments (and in the cases of India and Pakistan, entire national university systems) to standardize on that particular antique software, so you may not have to option.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Before we begin, let us make on thing clear: we won't do the work for you. Period. We are here to help you learn, not help you get a good grade you didn't earn. We will give advice, and help you solve problems, but we will not help you cheat.

Well, let's start by you showing us what you have done so far. Have you gotten any code written at all yet? Do you know, for example, how to print a simple message to the screen? If not, you might start there:

std::cout << "This is a simple multi-line message" << std::endl
          << "much like you would need for your menu" << std::endl
          << "you can keep chaining the '<<' operators" << std::endl
          << "like this to show the whole message," << std::endl
          << "with the 'endl' manipulator marking" << std::endl
          << "where the lines should end." << std::endl;

BTW, what C++ compiler are you using? It may help us give more specific advice.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

While Slavi's answer is indeed a good starting point, I think we could help some more as well if you could give us some more information. Let's start with a few pertinent questions:

  • What operating system is this going to run on?
  • What database engine are you using (e.g., SqlLite, MS Access, MS-SQL, MySql, Postgres, Oracle, etc)?
  • What programming language (aside from SQL, which is nearly universal in DBMS querying) will you be using?
  • What are the Business Rules for the organization? Do you have enough information about the NPO to define the BRs?
  • What are the entities you need to have store and retrieve information about, and how are they related? What are the relevant attributes of the entities?
  • What relations - that is to say, tables - can you make to model the entities?

The starting point in most database design is defining a set of business rules, that is to say, a semi-formal description of what the organization is, what the structure of it is, and what it does. For example, some years ago I wrote the following business rules for a company I was designing a web site and database for:

Business Rules for MJTB

0) The primary business of MJTB is the processing of PURCHASE ORDERS from CUSTOMERS.
1) A PURCHASE ORDER is an agreement between MJTB and a CUSTOMER to exchange one or more ITEMS for an amount of money …

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

MIB? Can you be a bit more specific? As this disambiguation page implies, there are several possible meanings for that acronym.

In any case, the really necessary questions are:

  • How many keys do you expect to use?
  • Can all of the configuration data fit in memory at one time?
  • Will you need to read from the configuration file more than once?
  • Will the data be updated or changed during the program run?
  • Will you need to write out to the file at any point?
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

There are plenty of things about VS that have caused me headhaches before, to be sure, but most of them weren't bugs per se. What problemas are you having?

If you are having as many problems with the IDE as you say you are (and I have no reason to doubt it), you might consider working on the code in a different environment and then copying it to Visual Studio for the version you turn in to the instructor. You can do the editing in an text editor (even Notepad would be sufficient, if rather primitive; Notepad++ is a good starting place, while many coders swear by Sublime Text, and I personally use GNU Emacs quite a bit, but I'm old-fshioned that way), and use a command-line compiler like the MS C/C++ compiler that comes with Visual Studio (the shell command for it cl.exe) or the MinGW port of GCC.

Alternatively, you could get a suitable IDE, such as Pelles C or Code::Blocks, and use that.

As long as you stick to the Standard C language and avoid any extensions, you should be OK when you move it back to Visual Studio. Oh, and make sure to use the C settings and the .c extension on the source files, so that the comipler or IDE knows it should be compiled as C code and not C++.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

OK, and what do you have for it so far? Did you have any questions about it specifically?

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

This doc page may prove useful to you.

By the way does it have to say void in the brackets on int main.

No. In fact, in C++ it shouldn't have void there.

And then for every line I want to color I Put

SetConsoleTextAttribute ( h, FOREGROUND_RED | FOREGROUND_INTENSITY );

>

Before it and

SetConsoleTextAttribute ( h, wOldColorAttrs);

after.

Actually, you should be able to set the attribute once for a block of rows, and only restore the original settings at the end of that - assuming you want to go back to the previous settings at all...

Also do I have to use printf to get the text because I am currently using the cout<< method?

I would expect that either would work, actually, though I'm not sure either of them is really correct. The actual Windows API function is WriteConsole(), but I expect that the C and C++ stream I/O functions are calling that themselves.

Oh, and why are there only 3 colors is that really the limit :/

No, it isn't; you can combine the bitfields for the colors to get different shades. For example, FOREGROUND_BLUE | FOREGROUND_GREEN should give cyan text.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

I'm not sure why the compiler would work like that unless you have a really outdated/beta version.

This is a distinct possibility, actually. The original Bloodshed Dev-C++ hasn't been updated since 2005; for a current development branch, the OP should look to the Orwell fork.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

OK, assuming the key can have any arrangement of alphanumeric values, 20 x 36! is a huge range, but that doesn't rule out anything except a simple lookup table. What matters more is how many keys you can expect to have in the file. Since you describe it as a configuration file, I would assume that the number of keys wouldn't be tremendous, less than 100 most likely. A hash table with a suitable hash function should work nicely in that case.

However, that's based on the assumption that you actually meant that it is a file for configuring the program; if it is a more general sort of data file, the size would be less predictable. If you expect a really large data set, a B-tree would probably be the way to go; you would use the B-Tree to cache the data rather than keeping it all in memory at once.

Can you give more details about what it is configuring?

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Does it have to be a linked list? There are several options, really, but we'd need to know what you're goal is and what the constraints on the design are.

If it must be a linked list, the simplest solution is to have an ordered list of ordered lists. You would need two node types, one for the key/value sets and the second for the values themselves:

struct key_node 
{
    key_type key;     /* where key_type is whatever type the key is */
    struct value_node* values;
    struct key_node* next;
};

struct value_node
{
    char* value;
    struct value_node* next;
};

The insert function would search through the key_nodes for the position of the key, and if it isn't present, would create a node for it; then it would search through the values to find the location for the value, and insert it there.

Mind you, that's what you would want to do if you needed it to be a linked list. There are better alternatives which would be more efficient, at least potentially, depending on how large the data set is and how much you knew about it in advance.

For example, if you knew that the key was an integer value in a fixed range, you could use a simple lookup key. This would just be an array of the value_node type which is the size of the full range of keys. It would probably use a lot of memory, but with a fairly small range (say, less than 10000) …

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Some further questions:

  • What operating system and toolchain are you writing this for (e.g., Windows and Visual Studio, Linux and GCC, MacOS and xCode. etc.)?
  • Is this coursework for a class (I assume not, but I figured it is worth asking), a thesis or research project, or a project for an employer?
  • Are you designing the program as well as coding it, or are you working from an existing design document? Are you working as part of a team or solo?
  • What kind of simulation is it, and what are you modeling? Is the aim mainly to model the subject mathematically, or the display a simulation visually, or both? How complex is the subject to be modeled, and how many different and/or complex elements need to interact? Are the elements discrete, or do they merge or separate over the course of the simulation? Are you mainly modeling the behavior of the elements, or the relationships between them?
  • Also, to repeat NathanOliver's question, is this a console program, a graphical program, or a combination of the two? If it is a graphical program, can you write the modeling independently of the visual simulation?
  • You say you have worked in Fortran and Matlab, but you aren't familiar with C or C++, correct? Have you worked on any object-oriented designs in any other languages (e.g., Python) before? Are you familiar with general OOP principles, and are they likely to be applicable to the project? (This last question relates to some of …
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

A little history here: the original impetus for interfaces, when they were introduced in Java (circa 1992, when it was still code-named Oak) was as an end-run around multiple inheritance. Some languages, such as C++ and Smalltalk-80, allowed a class to inherit from more than one parent class; this was a very powerful but very tricky feature, one which caused many problems for those who tried to use it. It was also a nightmare to implement efficiently, as it turned inheritances from a simple tree to a potentially much more complex directed acyclic graph, which made the process of resolving method dispatch a real bear.

By the time Java came along, there was a definite dislike of multiple inheritance in much of the industry, but single inheritance presented the problem that it made for an artificially rigid hierarchy: you often were forced to repeat both the class signature and implementation details, and many logically reasonable connections couldn't be made. Java's solution was the interface: a mechanism for multiple inheritance of the class signatures, without the problems associated with multiple inheritance of the actual methods.

This turned out to have it's own problems, but it also had unforeseen advantages, so when C# was designed, they copied the Java mechanism almost exactly.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Ah, I see what's happening, now, but only due to the serendipitous fact that my code doesn't clear the screen. Because I can see the results, I can see that it is in fact inserting and deleting correctly with the change I recommended; unfortunately, this is being lost when you print it, because the menu prints a second time, overwriting what was there.

This is not an unusual symptom, and is has to do with the way scanf() works. What is actually occuring is that when scanf() reads the from the input buffer one character at a time, the characters it reads include the newline character from when you hit the Enter key. Thus, it reads the first entry in the buffer, which is the character you entered, but then on the next pass, it reads the newline rather than waiting for the next char as you expected.

The solution is to use fgets() to read in a whole line of data into a buffer (including the newline), then parse the data locally using sscanf(). That should avoid the issue entirely.

Oh, I did see one other issue: you don't re-assign the head when you call your deletion function. This causes a problem with the list possibly getting corrupted.

#include <cstdio>
#include <cstdlib>

#define BUFSIZE 128

struct node {
    int inf;
    node *next;
};

node *insert_head(node *first, int data);
node *insert_last(node *first, int data);
int is_empty(node *first);
int find_max(node *first);
int counting_el(node *first);
int print_list(node *first);
node *delete_el(node *, …
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

You are correct about ++ being the increment operator; it is commonly used in C code, but yes, it most often shows up in a for() loop.

The ary[size] = c is an assignment to a element of an array (a block of memory holding a linear collection of items of the same type), where size is an integer between zero and ARY_SIZE-1 (actually, it can be any integer, but a valid subscript is going to be in that range). ary is the name of the array, and [size] is the subscript of the array, that is, the number of the element in the array to access. So, if you have an array of five ints named foo, you would declare it as int foo[5];, so that foo[0] is the first integer in the array, foo[1] is the second, and so forth up to foo[4].

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

A few things to note before proceeding:

  • In modern C++, the headers for the standard library eliminate the '.h' extension, and the legacy C headers all begin with the letter 'c'. So the headers should now be <cstdio> and <cstdlib>.
  • The <conio.h> is not a standard header at all; it is specific to certain older DOS and Windows compilers. We generally recommend avoiding it.
  • Using system() to clear the screen is both slow and non-portable. I mention this because I am running on a Linux system, where the command to clear the screen is clear, not cls. It is best just not to use such a command in the first place, or if you must, find some solution that works better. If all else fails, put the command in a function, so you can change it easily when you port the code from one system to another.
  • I noticed that you had the C++ I/O calls in some of your comments, but used the C-style I/O calls in the actual code. Was there a particular reason for this?
  • Also, do you have the compiler and linker warnings at maximum when you build this? You should, as you'll get a number of them in this code, and you should always treat warnings as errors unless you are absolutely certain that the warning doesn't apply to your code.

Getting to the actual problems, the first one that comes up is that in the following code:

    case '4': 
        printf("Enter number: …
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

BTW, what textbook are you using? It might help us understand why you are having so much trouble with it, and if it is as bad as you say, we'll know to steer others away from it.

new2code commented: forgot to mention, i am using VS 2010. which doesnt help me at all +0
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

First off, you aren't going to be writing hard real-time applications on Windows, or on any other operating system that uses virtual memory without specific support for unswappable pages. That's the first thing to understand: if there is a possibility of a delay in response time due to paging or swap time, real time performance is simply not possible. There are specialized operating systems around that are real-time, such as Qnx or eCos, but your typical desktop OS simply isn't suited for real-time work.

The other thing to understand is that most of the things you are probably thinking of as 'real time performance', such as music players or games, aren't, at least not in a technical sense. The term 'real time' refers not to speed, but rather to reliability and precision: a hard real-time operation is defined as one which guarantees that a given action will be taken between time t and time t', without failure - it is what you need when running an aircraft's control surfaces, for example, or the timing of actions on an assembly line. Soft real-time promises best effort response in the given time window; typical examples are the response time of a printer to a print command.

Bottom line: unless you are developing for a hardware manufacturer, you are unlikely to ever do any real-time programming.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

That code will in fact work, but it isn't typical C idiom, and isn't quite what you seem to have in mind. Basically, what you are doing with this is evaluating a boolean value and assigning the result to the variable letter. It does not assign the code to the variable, just the value of the result. This isn't what you seem to have in mind.

What you are really asking for, in effect, is how to write a function in C. You have the right idea, sort of, but lack the syntax for how to do it.

In C, a function consists of a declaration, and a body. The declaration and body look like this:

<type> <name> (<parameters>)
{
    <body>
}

where <type> is the function's return type, <parameters> is a list of zero or more variable declarations, separated by commas, and <body> is the actual code. Note the curly braces around the code; that is the basic C syntax for a block of code, and is used in if() statements, for() loops, and while() loops as well. For example,

double sum_of_squares(double x, double y)
{
    double a, b;

    a = x * x;
    b = y * y;
    return a + b;
}

declares a function that takes two double values and retusn another double. For functions that don't return a value, there is a special type, void, which indicates that there is no return value.

So, for the case above, you would probably …

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

I was, with considerable effort, able to get the blue() routine working in my own second stage, but the way I write code is significantly different from your style and I will have to post the whole thing, including all the EQUates I used, to make it comprehensible. It shouldn't be too difficult to re-write it for your setup, but it make take a little work.

;;;;;;;;;;;;;;;;;
;; stagetwo.asm - second stage boot loader
;; 
;; v 0.01  Joseph Osako 3 June 2002
;; v 0.02  Joseph Osako 7 Sept 2006
;;         * restarted project, files place under source control.
;;         * Modifications for FAT12 based loader begun. 
;;
;; 

%define stage2_base 0x1000      ; the segment:offset to load 
%define stage2_offset 0x0000    ; the second stage into

VBIOS           equ 0x10        ; BIOS interrupt vector for video services
set_cursor      equ 0x02        ; set the cursor to the given x,y coordinates
get_cursor      equ 0x03
set_page_mode   equ 0x00
set_active_page equ 0x05
read_cursor     equ 0x08
write_cursor    equ 0x09
ttype           equ 0x0E        ; print character, teletype mode
set_resolution  equ 0x12
set_font        equ 0x1102
width           equ 80
height          equ 43
page_mode       equ 0x03
NULL            equ 0x00        ; end of string marker
CR          equ 0x0D        ; carriage return
LF          equ 0x0A        ; line feed 

DBIOS           equ 0x13        ; BIOS interrupt vector for disk services
disk_reset  equ 0x00        ; disk reset service
disk_read   equ 0x02        ; disk read service
tries           equ 0x03        ; number of times to attempt to access the FDD
reset_failure   equ 0x01        ; error code …
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Just to clarify to point: you have an existing source file, which contains a complete program (e.g., it has a main() function and can be compiled and run without any additional files), and you want to use a single function out of that file in another program? That explains a good deal about the confusion you are experiencing, then.

The solution is to separate the functions you want to share into a third file, with only the functions, and then create a fourth file, a header file (with the .h extension) which would contain the class declarations and function prototypes. You would then include the header - not the source file - into both the original program (sans the shared code) and the new program, as well as seeing to it that the shared file is in both builds.

So, if you had the following program:

#include <iostream>
using namespace std;

class Foo 
{
private:
    int bar;

public:
    friend ostream& operator<<(ostream& os, Foo f); 

    int baz()
    {
      // do something and return an int
    }
}    

ostream& operator<<(ostream& os, Foo f)
{
     // implement the output operator for class Foo    
}

int main() 
{
    Foo quux;

    quux.baz();
    cout << quux;

    return 0;
}    

and you wanted to use the class Foo in another program, you would remove Foo from the original program (which you really should have done in the first place for modularity's sake), and create both a header and an implementation file:

Foo.h

// this …
mike_2000_17 commented: nice +14
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Apple's documentation on Workspaces and Projects should answer most of your questions; while it is aimed mainly at Objective-C, it should be the same for all supported languages. It seems fairly straightforward: you can drag and drop a file into the 'Classes' or 'Other Sources' folder, and that should be sufficient to add the files to your build. I think. If not, the explanation here should work for adding existing files.

You might want to look at this developer's tutorial. It is a bit dated, but still mostly relevant. If that's over your level at this time, try this one, though it doesn't cover the specifc question too much.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

It was no waste of time, I assure you; this is what we are here for, after all.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

I should have specified that gotoxy and set_mode should be in the functions.asm file; I am not certain if you have the code exactly as you have shown it or not. Also, you need to have a call to set_mode in kernel.asm; you only need to call it once.

Anyway, I did see the cause of at least part of the problem: the code as it is doesn't advance the cursor during the various passes. I will try to work out a version of it that works with my own secnd stage, and get back to you about it.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

I understand if only one or two functions are used that it is impractical, but what happens if you need almost all of the functions in the other file?

That's what Makefiles, or in the case of most IDEs, project files, are for. I don't know XCode, myself, but it should have some sort of workspace/project management facility, which will handle the building, tracking and linking for you.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Unfortunately, yes, it is. This post should help explain why.

The solution is to compile the source files in such a way that they can be linked into a single program. How you would do this is going to depend on the compiler and linker (or in many cases, the IDE) you are using. In most IDEs, including Visual Studio, Code::Blocks, and Eclipse, it can be as simple as making sure that the file is in the same project with the main program source file. If you are using a command-line compiler, you can usually list multiple source and object files in the build command. For example, with gcc you can compile the file foo.cpp to a separate object file,

 g++ -Wall foo.cpp -o foo.o

(...the -o switch says to use foo.o as the output file name, while -Wall means, 'display all the warnings that come up when compiling'...)

then you can combine it with the files bar.cpp and main.cpp like so:

 g++ -Wall foo.o bar.cpp main.cpp -o program

the GCC driver program, which for C++ is g++, will automagically call the linker for you.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Oh! I forgot a fairly important detail: restoring the previous cursor location. You'll want to get the x and y value at the beginning of the function, and restore them when you are done.

blue:
    mov ah, 03h
    int 10h
    push dx        ;dh = x, dl = y

    ;; continue the code from here
    ;; until after 'jnz for_row_restore'

    call gotoxy    ; restore the original cursor position
    pop ax         ; dispose of the value on the stack

While doing this, I noticed a mistake in my gotoxy function, so let me correct that:

gotoxy:            ; here I am using the C style
    push bp        ; parameter passing, on the stack
    mov bp, sp
    mov ah, 2      ; use function 2 - go to x,y
    mov bh, 0      ; display page 0
    mov dh, [bp+4] ; y coordinate to move cursor to
    mov dl, [bp+5] ; x coordinate to move cursor to
    int 10h ; go!
    pop bp
    ret

Also, in blue, remove the second push ax and the corresponding pop. This is because (in real mode) the stack always pushes a word at a time rather than a byte at a time. Finally, the parameters are higher in memory than the base pointer, so it should have been a plus offset, not minus.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

OK, as I said earlier, there are two waya to do this. One is to read each character from the video buffer, and write it out again with the new color. The other is to draw directly to the video memory. I'm going to show you the first, because you seem to be staying in real mode for now.

But first things first: let's make sure we know what the video page mode is. You can set it with the Int 10h, AH 00h function before running your command interpreter. For argument's sake, we'll use the 80x30 VGA setting, AL 12h:

; for now, define the width and hieght as constants
width   EQU 80
height  EQU 30

set_mode:
    mov ah, 00h
    mov al, 12h
    int 10h
    ret

blue:
    mov ax, 0
    push ax          ; y coordinate
    push ax          ; x coordinate 
    call gotoxy
    pop ax           ; clean up stack
    pop ax

    mov cx, height
.for_row:
    mov dx, width
.for_col:
    mov ah, 08h
    mov bh, 0
    int 10h
    ; use the returned value of al as the character to write
    mov ah, 09h
    mov cx, 0h
    mov bl, 17h ;color
    int 10h
    dec dx
    jnz .for_col
    dec cx
    jnz for_row

    mov si, version
    call    Print
    call    newline
    mov si, copyright
    call    Print
    jmp cmd

gotoxy:              ; here I am using the C style 
    push bp          ; parameter passing, on the stack
    mov bp, sp

    mov ah, 2        ; use function 2 - go to x,y
    mov bh, 0        ; display …
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

OK, that does explain some things, but I am puzzled still. I've assembled the code in question, and wrote it out to an image file, but... well, as it is, it shouldn't work AFAICT. The fact that you aren't setting the origin to 7C00h was enough to be a showstopper when I tried to run it under Bochs 2.6, and while adding the ORG directive did get it going, it still presented other problems.

BTW, what tool did you use to write the boot sector to the disk image, and what (if any) was the command string to do it?

It looks as if you are trying to read a FAT listing to find the file KERNEL.BIN, but that's puzzling too, as you neglected to incorporate a BPB in your boot sector; without one, a FAT disk shouldn't be readable (at least not by most FAT supporting OSes). You call int 18h (ROM Basic loader) if the search for the file fails, but what PC has a ROM Basic anymore? You also seem to have some confusion about how the stack works, as indicated by the following two lines:

push    dx
pop cx

which is equivalent to

mov cx, dx

which I doubt was the intention. It also wasn't clear where you were loading the second stage to, given the presence of the label buffer.

Can you explain some of these issues? I'm still not sure what you were doing in places.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

OK, then. I assume by TASM you mean Turbo Assembler (there's more than one TASM around), probably the DOS version, correct? What version of Windows (I'm assuming it is Windows, but that's hardly going out on a ledge) are you running, and do you know if the assembler even runs (if it is Windows Vista or later, is probably won't)? Are you using something like DOSBox to run it? Are you meaning to write DOS programs, or Windows programs?

Do you need to use Turbo for the project, or can you use a modern assembler such as NASM?

Also, what have you managed to do so far yourself? Do you have any code you can show us so far? What is the final goal of the program?

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Ah, this explains a few this. OK, a few points I should make regarding the writing of a boot loader like this, before I answer your problem. You might want to look at my bootloader, which is for NASM. You should also read as much as you can from the OS Dev Wiki, to see what your code is actually doing and get an idea of what you actually want.

First off, you'll need to tell us what assembler you are using, as there are subtle differences between the different ones.

Second, you don't seem to be assembling this to be loaded at 0000:7c00h, which is where the BIOS loads the loader to; as such, it shouldn't work at all. How are you running the program? How are you writing it to the boot disk? Are you using an emulator like Bochs or QEMU to run this, or is running on live hardware?

If this is meant to be a DOS or Windows program, then the code you have is completely inappropriate for that purpose.

Assuming this is indeed meant to be a boot loader, you will need to add the line

[ORG 7c00h]

at the very beginning of the code.

Third, while you have some code for reading from the disk, you don't seem to actually be loading your command interpreter as a second stage; instead, you are including it in with the boot loader itself. Again, that shouldn't be working, …

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

The main thing that is happening is that you need to advance the coordinates as you write to them. If you are always writing to (0,0), you'll constantly overwrite what you you had previously put there.

I would add that if you do it this way, you'll need to track the horizonal width of the page to make sure you are writing to a valid location. You can get the width of the page using the 0Fh function.

Also, to change the character attributes as well as the character glyph, you need to use the 09h function, not 0Ah.

Finally, by setting CX to 1000h, you are directing it to repeat itself for 4096 characters, which will indeed overwrite the whole page. That is doubtlessly what is actually clearing the page.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Oh, and the MIT OpenCourseware site also hosts the Abelson-Sussman Lectures, which I highly recommend if you are really serious about it. You'll want to read the textbook they go to, though this is actually a newer edition than the one used in the videos. It can be a tough course to get through, but it is well worth it IMAO.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

I doubt anyone here could encapsulate a whole bachelor's degree program into a single post, or even an extended thread (though mike_2000_17 might be able to manage it :-) ) The best suggestion I can make is to look at Open Courses offered by some universities, most notably MIT. They provide a large part of their curriculum online, including their introductory courses. Their EECS program material can be found here, with the intro course videos here.

You can also try some of the free educational sites such as Khan Academy. While I have my reservations regarding the efficacy of Khan's teaching method, it does seem to be helping many people.

You are free to come here for assitance and advice, of course, but a whole BS degree is a bit much to expect from us.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Aside from the question of whether we will give you code for this outright (we won't), we would need to know what type of computer this is for, what operating system it runs, and what assembler you need to use. Every assembly language is different, and different assemblers for the same CPU type will vary in their syntax. Without knowing which one you need, we could not begin to guess what would need to be done.

Finally, direct access to the real-time clock is generally controlled by the operating system. Unless you are running an embedded system, or a minimal OS such as MS-DOS, you would probably have to rely on a system call for the timing.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

First off, no one here is going to download a ZIP file off of an unfamiliar site, sight unseen. Even if you didn't put a virus in the archive, there are too many ways one could have gotten into it. Please post your code here, using the CODE button, or else put it in someplace visible like Pastebin or a GitHub repo.

Actually, using GitHub would probably be a good idea anyway, as I am guessing you haven't been using revision control up until now. I highly recommend it - it is free (for public repos), it is easy to use, and it has loads of advantages for handling changes in your code. You'll need to download and install the client, and learn how to use it, but it isn't all that difficult.

Second, this is not a free 'do my project for me' forum. We are willing to help you, but we won't do the work for you. Show us your code in a manner acceptable to us, and we will give you what advice we can, but you will still need to carry your weight.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

First off, we don't do other people's homework for them. Second, we don't do other people's homework for them. And third, we don't do other people's homework for them. Sensing a pattern here yet?

No one here will simply hand you a solution on a silver platter. If you show us what you've done, what you've tried to do, and what problems you've had with it, then we'll be happy to help. If you have specific questions, we can answer them, or at least point you in the right direction. If you have a program with a bug you can't swat on your own, we'll be glad to assist, so long as you pay attention to the forum rules and post sensible questions in an intelligent manner that we have some reasonable hope of answering.

But just cutting and pasting an assignment into a message, without even prefacing it with something like, "I have this homework problem that I can't solve...", is likely to get you booted from the message boards here and elsewhere - if you're lucky. What happens to you if you are unlucky is... well... let's just say that this guy probably won't be trying that again, on that forum or this one.

We take this issue seriously here. Very seriously. Asking us to do homework for you is a grave breach of academic ethics on your part, and actually doing so would be an even bigger breach on …

mike_2000_17 commented: wow, just wow... +14
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

There are a number of issues with this code, but the main one is that you are trying to write out an integer with a DOS call that is for writing strings. You need to convert the value of the result to an ASCII string in order to display it with that AH 09h call (unfortunately, there isn't any DOS routine for printing an integer).

The first thing you need to do is change the result variable so that it is large enough to hold a string representation of a 16-bit integer:

result dw 5 dup(?),'$'  ; reserve 5 chars and add a dollar sign at the end

The harder part is writing the routine to convert a decimal to a string. The general algorithm, as written in Python, can be found here; writing it in TASM is left to you to do.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

If I am reading the docs right, the POV field represents the hat control, if present. The U, V, and R represent additional axes for the joystick, if the joystick has them (the R does double duty as representing a rudder pedal, if there is one). For example, the U might be used for representing Yaw on a joystick that swivels along the axis of the joystick. Very few joysticks have these extra axes, so you probably wouldn't need them, but they are present for those joysticks which support them.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Just to be clear, do you mean this?

EDIT: Looking around the web a bit more, I see that there are several simulators for the Mano machine design. Can you tell us which one you are using?

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Could you tell us what system this assembly code is for? Unlike high-level languages, every type of computer has it's own specific assembly language, so we would have to know what it is for before we could answer the question.

I know this isn't assembly for x86 (that is to say, an ordinary PC), nor is it MIPS, ARM (the types of CPUs most common in phones and other small devices), 68K, 6502, Z80 or any of the others I am at least passingly familiar with. From what I've gathered after some Googling, this looks like PDP-8 code, which probably means you'r probably using the PEP-8 emulator. Is that correct?

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

What exactly happened when you tried to use them? Can you explain what it is you are trying to accomplish, and why? How long (or short) a delay do you need, and what values did you pass to the functions?

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Depending on the version of Windows you are using, this most likely isn't going to be possible. Windows Vista and later do not support 16-bit legacy code except through virtualization or emulation. Since the Turbo C compiler is for MS-DOS (the predecessor of Windows), and the second may be for either DOS or older (16-bit) versions of Windows, it is safe to say that there is no reasonable way to do this.

I am afraid that the real solution is to bite the bullet and learn how to use a modern compiler and the Windows console API. The compiler that is closest to the Borland one is the Embarcadero C++ Builder, but that is very expensive (over $200 US for the least expensive edition), and even then it isn't all that much like the older systems. A better choice would be either Code::Blocks (which uses the GCC compiler) or Visual Studio Express, both of which are free and up to date.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

As Hiroshe said, this isn't anywhere near enough information to start helping you. You'll need to not only explain the assignment, but also show us what you have tried to do already to solve it.

Do not expect us to hand you a solution out of thin air, either. Daniweb is not a free homework solving web site; we won't do your work for you. You will need to demonstrate due diligence on your own part before anyone here will give you assistance. This is even in the rules of the site:

Do provide evidence of having done some work yourself if posting questions from school or work assignments

So, what do you need help with?

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Ah, OK, that's important information we will need in order to give an answer; however, this forum is specific to the C++ language, not FORTRAN, which would be discussed in the 'Legacy Languages' forum. Hopefully, one of the moderators will move this over to that message board sometime soon.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

OK, the answer depends on just what it is you need help with, separating your classes, or managing the project. The second would depend on your development environment, but first part is going to be the same in pretty much all cases.

First, create a new file for the class header, and another for the class methods. So, for a class Foo, you would have a header file foo.h:

#ifndef FOO_H
#define FOO_H
#include <string>

class Foo 
{
public:
    Foo();
    void bar();
    std::string baz(int flarp);
    std::string getQuux() {return quux;};
private:
    std::string quux;
};
#endif

and a source file foo.c:

#include <string>
#include "foo.h"

Foo::Foo() 
{
 // ...
}

void Foo::bar() 
{
 // ...
}

std::string Foo::baz(int flarp) 
{
 // ...
} 

The comments and elipses indicate where the body of the methods would go.

Now, you will want to note a few things about these files. First off, the #ifndef/#endif are conditional compilation directives, which in this case say, 'if FOO_H is not defined, compile this, otherwise skip to the #endif'. This specific idiom, of putting such conditionals around the body of a header, is what is know as a inclusion guard, and is used to prevent the compiler from including the same header twice in the same source file.

The other thing you'll see is what isn't there: using namespace std;. With class definitions, and header files in general, you want to avoid the using directive. Instead, I used the scope operator on …