Nathan Campos 23 Junior Poster

Ok, i'm going to try!

Nathan Campos 23 Junior Poster

I've read a tutorial of installing zlib, but i've already installed it correct at the first time, but if i use -Lzlib , i got the same errors if i didn't putted it.

Thanks!

Nathan Campos 23 Junior Poster

Only one comment about your post, please use the code tags as the signature of Sky Diploma!

Thanks!

Nathan Campos 23 Junior Poster

Only one comment for you codeguru_2009: please put the code highlighting in your code, using this tags: [ code=asm ] ... [ /code=asm ], without spaces, it's just to for the best comprehension of the code.

Thanks!

Nathan Campos 23 Junior Poster

Hello,
I'm learning Ruby, and i want to know how to compress files using Ruby.

Thanks,
Nathan Paulino Campos

Nathan Campos 23 Junior Poster

If i try to compile by the command g++ comp.cpp -o comp -lzlib i'm getting this errors:

ubuntu@eeepc:~$ g++ comp.cpp -o comp -lzlib
/usr/bin/ld: cannot find -lzlib
collect2: ld returned 1 exit status
ubuntu@eeepc:~$

Thanks,
Nathan Paulino Campos

Nathan Campos 23 Junior Poster

If i put #include "zlib.h" the errors are the same.

Nathan Campos 23 Junior Poster

Hello,
I'm learning C++ and i was trying to use the zlib, but i'm getting some errors when trying to compile my little project. Here is the code:

#include <string>
#include <stdexcept>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <zlib.h>
using namespace std;

std::string compress_string(const std::string& str,
                            int compressionlevel = Z_BEST_COMPRESSION)
{
    z_stream zs;                        // z_stream is zlib's control structure
    memset(&zs, 0, sizeof(zs));

    if (deflateInit(&zs, compressionlevel) != Z_OK)
        throw(std::runtime_error("deflateInit failed while compressing."));

    zs.next_in = (Bytef*)str.data();
    zs.avail_in = str.size();           // set the z_stream's input

    int ret;
    char outbuffer[32768];
    std::string outstring;

    // retrieve the compressed bytes blockwise
    do {
        zs.next_out = reinterpret_cast<Bytef*>(outbuffer);
        zs.avail_out = sizeof(outbuffer);

        ret = deflate(&zs, Z_FINISH);

        if (outstring.size() < zs.total_out) {
            // append the block to the output string
            outstring.append(outbuffer,
                             zs.total_out - outstring.size());
        }
    } while (ret == Z_OK);

    deflateEnd(&zs);

    if (ret != Z_STREAM_END) {          // an error occurred that was not EOF
        std::ostringstream oss;
        oss << "Exception during zlib compression: (" << ret << ") " << zs.msg;
        throw(std::runtime_error(oss.str()));
    }

    return outstring;
}

int main(int argc, char* argv[])
{
    std::string allinput;

    while (std::cin.good())     // read all input from cin
    {
        char inbuffer[32768];
        std::cin.read(inbuffer, sizeof(inbuffer));
        allinput.append(inbuffer, std::cin.gcount());
    }
        std::string cstr = compress_string( allinput );

        std::cerr << "Deflated data: "
                  << allinput.size() << " -> " << cstr.size()
                  << " (" << std::setprecision(1) << std::fixed
                  << ( (1.0 - (float)cstr.size() / (float)allinput.size()) * 100.0)
                  << "% saved).\n";

        std::cout << cstr;
}

And here is my compiling log:

ubuntu@eeepc:~$ g++ comp.cpp -o comp
/tmp/ccTx0M9f.o: In function `compress_string(std::basic_string<char, std::char_traits<char>, …
Nathan Campos 23 Junior Poster

Hello,
I'm learning C++, and recently i was searching for an implement of the zlib, that is a library to zip and unzip files, but i found a sample code in this site, but i want to know two things, first: How i can change this code to only compress files and simplify it very much:

#include <string>
#include <stdexcept>
#include <iostream>
#include <iomanip>
#include <sstream>

#include <zlib.h>

/** Compress a STL string using zlib with given compression level and return
  * the binary data. */
std::string compress_string(const std::string& str,
                            int compressionlevel = Z_BEST_COMPRESSION)
{
    z_stream zs;                        // z_stream is zlib's control structure
    memset(&zs, 0, sizeof(zs));

    if (deflateInit(&zs, compressionlevel) != Z_OK)
        throw(std::runtime_error("deflateInit failed while compressing."));

    zs.next_in = (Bytef*)str.data();
    zs.avail_in = str.size();           // set the z_stream's input

    int ret;
    char outbuffer[32768];
    std::string outstring;

    // retrieve the compressed bytes blockwise
    do {
        zs.next_out = reinterpret_cast<Bytef*>(outbuffer);
        zs.avail_out = sizeof(outbuffer);

        ret = deflate(&zs, Z_FINISH);

        if (outstring.size() < zs.total_out) {
            // append the block to the output string
            outstring.append(outbuffer,
                             zs.total_out - outstring.size());
        }
    } while (ret == Z_OK);

    deflateEnd(&zs);

    if (ret != Z_STREAM_END) {          // an error occurred that was not EOF
        std::ostringstream oss;
        oss << "Exception during zlib compression: (" << ret << ") " << zs.msg;
        throw(std::runtime_error(oss.str()));
    }

    return outstring;
}

/** Decompress an STL string using zlib and return the original data. */
std::string decompress_string(const std::string& str)
{
    z_stream zs;                        // z_stream is zlib's control structure
    memset(&zs, 0, sizeof(zs));

    if (inflateInit(&zs) != Z_OK)
        throw(std::runtime_error("inflateInit failed while decompressing."));

    zs.next_in …
Nathan Campos 23 Junior Poster

huh, that's cool!
You explain very nice wildgoose!

Nathan Campos 23 Junior Poster

I'm only trying to bring up the rest of the OS, because it's now so much big, then i can't compile to the boot sector(510 bytes).

wildgoose, it's my OS, that i'm trying to develop!

Nathan Campos 23 Junior Poster

huh, i'm going to test!
But remember that i need to boot the first compiled file, that is in the floppy boot sector, then it boots the second compile file, that is the OS.

Thanks!

Nathan Campos 23 Junior Poster

Ok, i'm going to check this, but how i can compile only the boot file(part of my other) that can boot the OS, like in my question?

Thanks!

Nathan Campos 23 Junior Poster

Hello,
I'm developing an simple OS, as you can see in my previous posts, but now i have a file that is too big for the boot sector(510 bytes), then i want to split it in two files, one that will be in the boot sector of the floppy and the other that will be in the normal sectors of the floppy, then at the boot time i need that the file that is in the boot sector(a simple boot loader), boots the other that is in the normal sectors of the floppy, but i don't know how to do this, someone can help me!. If needed, here is my code:

[BITS 16]	     ; 16 bit code generation
[ORG 0x7C00]	 ; ORGin location is 7C00

JMP short main   ; Jump past disk description section
NOP              ; Pad out before disk description

; ------------------------------------------------------------------
; Disk description table, to make it a valid floppy
; Note: some of these values are hard-coded in the source!
; Values are those used by IBM for 1.44 MB, 3.5" diskette

OEMLabel            db "BERL OS"    ; Disk label - 8 chars
BytesPerSector      dw 512          ; Bytes per sector
SectorsPerCluster   db 1            ; Sectors per cluster
ReservedForBoot     dw 1            ; Reserved sectors for boot record
NumberOfFats        db 2            ; Number of copies of the FAT
RootDirEntries      dw 224          ; Number of entries in root dir
LogicalSectors      dw 2880         ; Number of logical sectors
MediumByte          db 0F0h         ; Medium descriptor byte
SectorsPerFat       dw 9            ; Sectors …
Nathan Campos 23 Junior Poster

huh, thanks very much!

Nathan Campos 23 Junior Poster

Xlphos link is the right place!
If you need to post a snippet post here!

Nathan Campos 23 Junior Poster

Hello,
I'm learning C++, then i want to know how i can do a convertion of an decimal number to an hexamal number, i know the calculation form to do this, but the thing that i don't know is how i can represent the remain in the formula. Here is an example of a convertion of the number 42(in decimal to hexamal):

42 : 16 = 2
Remain 10.
10 in hexamal is A.
Then 42 in hexamal is 2A

How i can do a program that knows what is tha remain, this is my question?

Thanks,
Nathan Paulino Campos

Nathan Campos 23 Junior Poster

Thanks very much!

Nathan Campos 23 Junior Poster

Thanks very much wildgoose!
You are a very nice and (the word that say that the person helps many people, because i don't know, remember that i live in Brazil).

God bless you my friend!

Nathan Campos 23 Junior Poster

huh, very interesting, i'm going to write a program like this!

Nathan Campos 23 Junior Poster

And here is the code modified:

[BITS 16]	     ; 16 bit code generation
[ORG 0x7C00]	 ; ORGin location is 7C00

JMP short main   ; Jump past disk description section
NOP              ; Pad out before disk description

; ------------------------------------------------------------------
; Disk description table, to make it a valid floppy
; Note: some of these values are hard-coded in the source!
; Values are those used by IBM for 1.44 MB, 3.5" diskette

OEMLabel            db "BERL OS"    ; Disk label - 8 chars
BytesPerSector      dw 512          ; Bytes per sector
SectorsPerCluster   db 1            ; Sectors per cluster
ReservedForBoot     dw 1            ; Reserved sectors for boot record
NumberOfFats        db 2            ; Number of copies of the FAT
RootDirEntries      dw 224          ; Number of entries in root dir
LogicalSectors      dw 2880         ; Number of logical sectors
MediumByte          db 0F0h         ; Medium descriptor byte
SectorsPerFat       dw 9            ; Sectors per FAT
SectorsPerTrack     dw 18           ; Sectors per track (36/cylinder)
Sides               dw 2            ; Number of sides/heads
HiddenSectors       dd 0            ; Number of hidden sectors
LargeSectors        dd 0            ; Number of LBA sectors
DriveNo             dw 0            ; Drive No: 0
Signature           db 41           ; Drive signature: 41 for floppy
VolumeID            dd 00000000h    ; Volume ID: any number
VolumeLabel         db "BERL OS"    ; Volume Label: any 11 chars
FileSystem          db "FAT12"      ; File system type: don't change!

; End of the disk description table
; ------------------------------------------------------------------

main:
MOV BX, 0                           ; Disable blinking.
MOV BH, 00h
MOV BL, 07h                         ; Color settings
MOV AL, 1
MOV BH, …
Nathan Campos 23 Junior Poster

Here is the log of the compiler:

C:\Users\Nathan\Desktop>nasm os.asm
os.asm:70: error: comma expected after operand 1
os.asm:71: error: comma expected after operand 1
os.asm:81: error: comma, colon or end of line expected
os.asm:82: error: comma, colon or end of line expected
os.asm:88: error: comma, colon or end of line expected
os.asm:91: error: comma, colon or end of line expected
os.asm:92: error: comma, colon or end of line expected

What is wrong?

Nathan Campos 23 Junior Poster

Thanks, but i'm getting the same errors, when i try to compile with all the fixes, remember that i'm using Nasm as compiler.

Nathan Campos 23 Junior Poster

Thanks wildgoose, i will find some more resources about it!
Thanks!

Nathan Campos 23 Junior Poster

Thanks very much!!!

Nathan Campos 23 Junior Poster

If you don't want to download the file, here is the source for:
mp3play.pp

{$MODE Delphi}

PROGRAM MP3Play;

{ A simple MP3 player
  Demonstrates use of XAudio and MIDAS.
  Platform: DOS

  Copyright (c) 1999 Udo Giacomozzi
  May be used for free use only.
}

USES
  Crt, Dos, Decode, IO;
{ Note: unit 'IO' must be *after* unit 'Decode'. This may be because MIDAS
        needs to be initialized after XAudio... }


{ Sets the default file extension if none given
    FName  - the file name to be modified
    DefExt - Default extension (format ".XXX" !!) }
function SetDefaultExt(const FName, DefExt:String):String;
var
  fp,fn,fe : String;  // file path/name/extension
begin
  FSplit(FName, fp, fn, fe);
  If fe = '' then fe := DefExt;
  Result := fp+fn+fe;
end;

{ Returns only the name (no path, no extension) of a file name
    FName  - The file name to be modified }
function GetFName(const FName:String):String;
var
  fp,fn,fe : String;  // file path/name/extension
begin
  FSplit(FName, fp, fn, fe);
  Result := fn;
end;

{ adds a leading zero if needed (1 -> '01') }
function LeadingZero(w:Word):String;
begin
  Str(w,Result);
  if w<10 then Result:='0'+Result;
end;

VAR
  InFileName    : String;
  MP3           : tMP3Player;
  Buffer        : Array[Word] of Byte;
  ToWrite       : Word;
  CurFreq       : LongInt;
  NewFreq       : LongInt;

BEGIN
  { Read commandline parameters ------------------------------------------- }
  if ParamCount<1 then
  begin
    writeln('Usage:');
    writeln('  MP3PLAY InputFile[.MP3]');
    Halt;
  end;
  InFileName  := SetDefaultExt(ParamStr(1), '.MP3');

  { Initialize audio I/O -------------------------------------------------- }

  writeln('Initializing MP3 decoder...');
  MP3 := tMP3Player.Create(InFileName);

  writeln('Initializing audio I/O routines...');
  Audio_Init;

  writeln('Starting audio output...');
  Audio_Start;

  writeln('Starting …
Nathan Campos 23 Junior Poster

Here is a sample Hello World for Narm:

;========================================================================
;  NilZone C++ Compiler 1999
;
;  File:  hello.c
;  Date:  21/Feb/2000
;  Time:  13:01:37
;========================================================================


	SECTION .text
EXTERN  __gccmain
EXTERN  printf

	SECTION .data

	SECTION .rodata

LC0	DCB "Hello World",0x0A,0x00
	
	SECTION .text

	GLOBAL	main

main:
	mov	ip, sp
	stmfd	sp!, {fp, ip, lr, pc}
	sub	fp, ip, #4
	bl	__gccmain
	ldr	r0, L4
	bl	printf
	b	L3
L4:
	DCD	LC0
L3:
	ldmea	fp, {fp, sp, pc}

	END

And here is the link to the project home page: http://www.geocities.com/SiliconValley/Hub/6461/arm/
Let's do some copies of this sites that we like and are no more maintained in Geocities, because it will be discontinued by Yahoo, i was doing some sites downloads to archive.

Thanks!

Nathan Campos 23 Junior Poster

It uses as compiler Narm, that is a port of Nasm to ARM devices.

Nathan Campos 23 Junior Poster

I heard about ARMASM, someone knows if it uses 8086 microprocessor Nasm Assembly language?

Thanks!

Nathan Campos 23 Junior Poster

And read your question about MP3 Player in Pascal, i post the source code!

Nathan Campos 23 Junior Poster

FearlessFourie, i searched in Google and i see this program, that you can download the *.zip that haves the compiled program and the sources, of version 1 and 2.

Here is the link: http://www.nova-sys.net/oldhp/mp3play.htm
I'm going to read more this code, it's very interesting.
Hope it helps and post here if it helps, please!

Now this post is really solved!

Nathan Campos 23 Junior Poster

huh, this problem is much more complex!

Nathan Campos 23 Junior Poster

If it's needed, here is the code:

[BITS 16]	     ; 16 bit code generation
[ORG 0x7C00]	 ; ORGin location is 7C00

JMP short main   ; Jump past disk description section
NOP              ; Pad out before disk description

; ------------------------------------------------------------------
; Disk description table, to make it a valid floppy
; Note: some of these values are hard-coded in the source!
; Values are those used by IBM for 1.44 MB, 3.5" diskette

OEMLabel            db "BERL OS"    ; Disk label - 8 chars
BytesPerSector      dw 512          ; Bytes per sector
SectorsPerCluster   db 1            ; Sectors per cluster
ReservedForBoot     dw 1            ; Reserved sectors for boot record
NumberOfFats        db 2            ; Number of copies of the FAT
RootDirEntries      dw 224          ; Number of entries in root dir
LogicalSectors      dw 2880         ; Number of logical sectors
MediumByte          db 0F0h         ; Medium descriptor byte
SectorsPerFat       dw 9            ; Sectors per FAT
SectorsPerTrack     dw 18           ; Sectors per track (36/cylinder)
Sides               dw 2            ; Number of sides/heads
HiddenSectors       dd 0            ; Number of hidden sectors
LargeSectors        dd 0            ; Number of LBA sectors
DriveNo             dw 0            ; Drive No: 0
Signature           db 41           ; Drive signature: 41 for floppy
VolumeID            dd 00000000h    ; Volume ID: any number
VolumeLabel         db "BERL OS"    ; Volume Label: any 11 chars
FileSystem          db "FAT12"      ; File system type: don't change!

; End of the disk description table
; ------------------------------------------------------------------

main:
MOV BX, 0                           ; Disable blinking.
MOV BH, 00h
MOV BL, 07h                         ; Color settings
MOV AL, 1
MOV …
Nathan Campos 23 Junior Poster

For those who want to develop OS's(like me) OS Dev Wiki is a good place to start.

Nathan Campos 23 Junior Poster

In my opinion, Delphi is more easy to learn and it's more flexible in OS's term, like Lazarus project, you can compile apps to Linux and Mac, Kylix just to Linux.

Nathan Campos 23 Junior Poster

It's just a test, if it solves the problem, because one person that i know(is my friend) here in Brazil, was having a a problem like this, then he do this and the problem solves.

Nathan Campos 23 Junior Poster

Hello wildgoose,
Now i'm getting this errors:
http://img253.imageshack.us/img253/3381/errorb.png
Why?

Thanks!

Nathan Campos 23 Junior Poster

Ok, i'm going to try, any thing i will post, but i know that i will not have problems, thanks!

Nathan Campos 23 Junior Poster

What is the type of DB, because you only have to search in Google for this: Delphi+Your DB Type+Tutorial

Nathan Campos 23 Junior Poster

Remove the [ ] from the string method, like this:

Verse : array[1..6] of string;
Nathan Campos 23 Junior Poster

First of all post your code like this:

Program Help_me;
uses crt;

var total : byte;
Verse : array[1..6] of string[250];
begin
clrscr;
writeln('please enter the amount of verses the song has, may not exceed 6');
readln(Total);{here I would write a small step to exclude "-", >6 and so on}
for total := 1 to total do
begin
writeln('please enter song verse here');
Writeln('do not use "enter" for next line of verse, use "." and "," to
end lines);
readln(Verse[total]); {this can only read +-150char, and if I go past 80 char and the line jumps, I can't delete the first line}
end;{and so on and so forth}
end.
Nathan Campos 23 Junior Poster

The snippets place in DaniWeb it's a good place, but i will like if we sticky a post for the beginners(like me).

Thanks!

Nathan Campos 23 Junior Poster

Huh, now i understand!

Nathan Campos 23 Junior Poster

Thanks, now it's working!

Nathan Campos 23 Junior Poster

But how i can do this?
Sorry about this simple questions, but i'm learning Assembly for OS's.

Thanks for you attention!

Nathan Campos 23 Junior Poster

Only one thing, please homeryansta, put the code in code tags with the highlighting: [ code=asm ] [ /code ] and please put better titles in your posts, because with good tittles the forums will be more organized and your chances to have a answer will grow, because of someone had the same problem, now can help you.

Thanks!

Nathan Campos 23 Junior Poster

This is C question, then it haves to be in C/C++ Forum here in DaniWeb.

Nathan Campos 23 Junior Poster

Hello xelos,
Please, surround your code with the code tags, like this: [ code=asm ] [ /code ] , but without the spaces.
This is just to understand better your code, put highlighting and be more organized.

Thanks,
Nathan Paulino Campos

Nathan Campos 23 Junior Poster

How i have to use this, like this ?:

MOV AH, 0

Thanks,
Nathan Paulino Campos

Nathan Campos 23 Junior Poster

Hello wildgoose,
Thanks for your help, now i know that INT 16h is for keyboard, but if i want to improve like, the user types: ver , then when he press enter the OS shows a message, like: ver DB "ver. 0.0.1" .

Thanks,
Nathan Paulino Campos