Re: [Freedos-devel] Linking asm with C

2023-01-14 Thread Ralf Quint

On 1/13/2023 12:49 PM, Knedlik wrote:

I’m trying to learn graphics programming in DOS. It’s really hard to get 
resources on this topic...

I think you are trying to run before you can walk. Try to program in DOS 
first. Things are a bit different than programming in today's multi-GB 
GUI environments, but it ain't THAT difficult either.



Ralf




___
Freedos-devel mailing list
Freedos-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freedos-devel


Re: [Freedos-devel] Linking asm with C

2023-01-14 Thread Ralf Quint

On 1/13/2023 8:33 AM, Knedlik wrote:

void clearScreen(char color) {
 int i;
 for (i = 0xa000; i < 0xfa00; i++) {
 char* byte = i;
 *byte = color;
 }
}


What the hell are you trying to do here? Seriously, it doesn't help just 
to blindly follow some tutorial without trying to understand what you 
are doing.


First of all, your addresses are all wrong, you are simply writing where 
you shouldn't. If you want to program in DOS and directly access 
hardware (in this case RAM) like this, you need to understand how the 
segment:offset concept of the 8086 CPU works.


While 0xA000 is the start of the graphics *segment*, the normalized 
*address* would be 0xA (0xA000:0x in segment offset notation), 
the end of the video RAM for MCGA mode would be segment 0xBFFF, with the 
last byte of that video RAM segment being at normalized address 0xB 
(0xB000:0x).


As you actually never set any segment in your code, assuming that you 
are using the default small memory model, you are just blasting 0xFF 
bytes at random addresses in your current data segment...



Ralf

___
Freedos-devel mailing list
Freedos-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freedos-devel


Re: [Freedos-devel] Linking asm with C

2023-01-13 Thread Robert Riebisch
Hi Knedlik,

> I’m trying to learn graphics programming in DOS. It’s really hard to get 
> resources on this topic...

Fixing a few broken links on my page
, you get this:

256-Color VGA Programming in C
http://www.brackeen.com/vga/

Graphics Programming Black Book | Dr Dobb's
https://www.drdobbs.com/parallel/graphics-programming-black-book/184404919

VGA programming lessons (assembly and Pascal language)
http://joco.homeserver.hu/vgalessons/

Graphics Programming using Assembly
http://web.archive.org/web/20170923065919/www.ronthomas.plus.com/Downloads.html

The Graphics Programming Series
http://web.archive.org/web/20140326002251/www.nondot.org/sabre/graphpro/

Plus:
Books update (Game Engine Black Books: Wolfenstein 3D & DOOM)
https://fabiensanglard.net/three_books_update/

Cheers,
Robert
-- 
BTTR Software   https://www.bttr-software.de/
DOS ain't dead  https://www.bttr-software.de/forum/

___
Freedos-devel mailing list
Freedos-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freedos-devel


Re: [Freedos-devel] Linking asm with C

2023-01-13 Thread Knedlik
I’m trying to learn graphics programming in DOS. It’s really hard to get 
resources on this topic...

___
Freedos-devel mailing list
Freedos-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freedos-devel


Re: [Freedos-devel] Linking asm with C

2023-01-13 Thread Danilo Pecher
If you are comfortable programming in Pascal, stay with it. In fact
Turbo-Pascal has pretty much the best integration of inline assembler
of all the languages I encountered in 30 years. And in general, just
don't follow tutorials blindly, collect your own experience. Maybe it
would help if you told us what exactly you are attempting to do.

On Fri, 13 Jan 2023 at 20:10, Knedlik  wrote:
>
> To be honest, I’m just following a tutorial that said it’s better to do it in 
> asm - but it’s in Pascal, so I’m translating it into C.
>
>
>
> ___
> Freedos-devel mailing list
> Freedos-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/freedos-devel


___
Freedos-devel mailing list
Freedos-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freedos-devel


Re: [Freedos-devel] Linking asm with C

2023-01-13 Thread Steve Nickolas

On Fri, 13 Jan 2023, Knedlik wrote:

To be honest, I’m just following a tutorial that said it’s better to do 
it in asm - but it’s in Pascal, so I’m translating it into C.


Only reason you'd want to use ASM rather than C is to try to optimize it 
beyond what the compiler can do.


-uso.___
Freedos-devel mailing list
Freedos-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freedos-devel


Re: [Freedos-devel] Linking asm with C

2023-01-13 Thread Knedlik
To be honest, I’m just following a tutorial that said it’s better to do it in 
asm - but it’s in Pascal, so I’m translating it into C.



___
Freedos-devel mailing list
Freedos-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freedos-devel


Re: [Freedos-devel] Linking asm with C

2023-01-13 Thread Danilo Pecher
Accepting the danger of sounding somewhat arrogant, but you seem to
lack some basic knowledge of system programming. Are  you sure you
need assembler programming in the first place? Everything you've set
out so far is perfectly doable in C.

On Fri, 13 Jan 2023 at 17:35, Knedlik  wrote:
>
> Okay, this is just weird.
> I can’t for the love of god figure out why this is throwing the divide by 
> zero interrupt.
>
> void setMCGA() {
> _asm {
> mov al, 0x13
> int 0x10
> ret
> }
> }
>
> void setText() {
> _asm {
> mov al, 0x03
> int 0x10
> ret
> }
> }
>
> void clearScreen(char color) {
> int i;
> for (i = 0xa000; i < 0xfa00; i++) {
> char* byte = i;
> *byte = color;
> }
> }
>
> int main(int argc, char** argv) {
> setMCGA();
> clearScreen(255);
> getchar();
> setText();
> return 0;
> }
>
>
>
> ___
> Freedos-devel mailing list
> Freedos-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/freedos-devel


___
Freedos-devel mailing list
Freedos-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freedos-devel


Re: [Freedos-devel] Linking asm with C

2023-01-13 Thread Steve Nickolas

On Fri, 13 Jan 2023, Knedlik wrote:


void clearScreen(char color) {
   int i;
   for (i = 0xa000; i < 0xfa00; i++) {
   char* byte = i;
   *byte = color;
   }
}


This is completely wrong.  Mode 0x13, right?

void clearScreen (char color)
{
 char far *screen;
 unsigned int i;

 screen=MK_FP(0xA000, 0x);
 for (i=0; i<64000; i++) screen[i]=color;
}

-uso.


___
Freedos-devel mailing list
Freedos-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freedos-devel


Re: [Freedos-devel] Linking asm with C

2023-01-13 Thread Louis Santillan
OpenWatcom uses ``, `union REGS` type, and `int86()` when using
a DOS Real Mode Memory Model.

See:
Page 405 - 
https://web.archive.org/web/20220507185907/http://ftp.openwatcom.org/manuals/current/clib.pdf
https://web.archive.org/web/20201112024837/http://www3.telus.net/alexander_russell/course/chapter_1.htm
https://github.com/balintkissdev/awesome-dos
https://web.archive.org/web/2020162212/http://www.ctyme.com/rbrown.htm

On Fri, Jan 13, 2023 at 9:06 AM tom ehlert  wrote:
>
>
> > Okay, this is just weird.
> > I can’t for the love of god figure out why this is throwing the divide by 
> > zero interrupt.
>
> a) learn to use a debugger. single step  this stuff. you will likely see
> that 'ret' is not a good idea in inline assembly in general.
>
> also
>
>WDIS graphic.obj > graphic.txt
>
> shows you why some instructions in inline assembly are usually
> forbidden.
>
>
> b) don't use assembly for this.
>
> #include 
>
>  int setMCGA() {
>   _REGS r;
>
>   r.h.ah = 0x13;
>   _int86(0x10, , );
>
>   if (r.flags & _CARRY)
>  {
>  printf("setting MCGA failed because %x\n", r.h.al);
>  return 1;
>  }
> return 0;
>  }
>
> does the same, works with every compiler around and avoids this
> trouble.
>
>
> last not least,
>
> INT 10 - VIDEO - SET VIDEO MODE
> AH = 00h
> AL = desired video mode (see #00010)
>
>
>
>
>
>
> > void setMCGA() {
> > _asm {
> > mov al, 0x13
> > int 0x10
> > ret
> > }
> > }
>
> > void setText() {
> > _asm {
> > mov al, 0x03
> > int 0x10
> > ret
> > }
> > }
>
> > void clearScreen(char color) {
> > int i;
> > for (i = 0xa000; i < 0xfa00; i++) {
> > char* byte = i;
> > *byte = color;
> > }
> > }
>
> > int main(int argc, char** argv) {
> > setMCGA();
> > clearScreen(255);
> > getchar();
> > setText();
> > return 0;
> > }
>
>
>
> > ___
> > Freedos-devel mailing list
> > Freedos-devel@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/freedos-devel
>
>
>
>
>
> Mit freundlichen Grüßen / with kind regards
> Tom Ehlert
> +49-15151898538
>
>
>
> ___
> Freedos-devel mailing list
> Freedos-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/freedos-devel


___
Freedos-devel mailing list
Freedos-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freedos-devel


Re: [Freedos-devel] Linking asm with C

2023-01-13 Thread tom ehlert

> Okay, this is just weird.
> I can’t for the love of god figure out why this is throwing the divide by 
> zero interrupt.

a) learn to use a debugger. single step  this stuff. you will likely see
that 'ret' is not a good idea in inline assembly in general.

also

   WDIS graphic.obj > graphic.txt

shows you why some instructions in inline assembly are usually
forbidden.


b) don't use assembly for this.

#include 

 int setMCGA() {
  _REGS r;

  r.h.ah = 0x13;
  _int86(0x10, , );

  if (r.flags & _CARRY)
 {
 printf("setting MCGA failed because %x\n", r.h.al);
 return 1;
 }
return 0;
 }

does the same, works with every compiler around and avoids this
trouble.


last not least,

INT 10 - VIDEO - SET VIDEO MODE
AH = 00h
AL = desired video mode (see #00010)






> void setMCGA() {
> _asm {
> mov al, 0x13
> int 0x10
> ret
> }
> }

> void setText() {
> _asm {
> mov al, 0x03
> int 0x10
> ret
> }
> }

> void clearScreen(char color) {
> int i;
> for (i = 0xa000; i < 0xfa00; i++) {
> char* byte = i;
> *byte = color;
> }
> }

> int main(int argc, char** argv) {
> setMCGA();
> clearScreen(255);
> getchar();
> setText();
> return 0;
> }



> ___
> Freedos-devel mailing list
> Freedos-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/freedos-devel





Mit freundlichen Grüßen / with kind regards
Tom Ehlert
+49-15151898538



___
Freedos-devel mailing list
Freedos-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freedos-devel


Re: [Freedos-devel] Linking asm with C

2023-01-13 Thread E. Auer


hi! if you are using a protected mode model,
it may be impossible to call int 10 directly
and you may have to use dpmi for that.

all compilers for DOS offer ways to call BIOS
and other interrupts directly from C, which
is a lot more foolproof than using ASM here.

the next problem is whether you should use
RET here, that may be something C does for
you and it may be something more complex
than just calling RET, e.g. also preparing
and clearing up the stack before and after
the ASM part. you can try without the RET.

C compilers have various opinions about
whether and which registers you are allowed
to change, but int ax=0x0013 probably is
safe, changing only AX, as far as I remember.

Note that you write mov al,0x13, which
means you do NOT specify what AH should
be. this is a BAD idea. AH could be any
arbitrary value at that moment, so you
could be triggering any VGA BIOS int 10
thing instead of the one you intended.

Finally, your clear screen confuses the
graphics RAM segment 0xa000 with absolute
address 0xa and relative offsets of
0 to 0xfa00 within that. It will depend
A LOT on which compiler and memory model
you use what the PROPER way to do this
will be for you. I can only tell that
the style you use right know is NOT okay
and will just overwrite data and crash.

Regards, Eric




I can’t for the love of god figure out why this is throwing the divide
by zero interrupt.

void setMCGA() {
_asm {
mov al, 0x13
int 0x10
ret
}
}

void setText() {
_asm {
mov al, 0x03
int 0x10
ret
}
}

void clearScreen(char color) {
int i;
for (i = 0xa000; i < 0xfa00; i++) {
char* byte = i;
*byte = color;
}
}

int main(int argc, char** argv) {
setMCGA();
clearScreen(255);
getchar();
setText();
return 0;
}



___
Freedos-devel mailing list
Freedos-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freedos-devel


Re: [Freedos-devel] Linking asm with C

2023-01-13 Thread Knedlik
Okay, this is just weird.
I can’t for the love of god figure out why this is throwing the divide by zero 
interrupt.

void setMCGA() {
_asm {
mov al, 0x13
int 0x10
ret
}
}

void setText() {
_asm {
mov al, 0x03
int 0x10
ret
}
}

void clearScreen(char color) {
int i;
for (i = 0xa000; i < 0xfa00; i++) {
char* byte = i;
*byte = color;
}
}

int main(int argc, char** argv) {
setMCGA();
clearScreen(255);
getchar();
setText();
return 0;
}



___
Freedos-devel mailing list
Freedos-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freedos-devel


Re: [Freedos-devel] Linking asm with C

2023-01-13 Thread Mercury Thirteen via Freedos-devel
Watcom's Debugger is amazing for that. You can single-step your code, set 
breakpoints, monitor variable names, everything. It'll even work (albeit a 
little less robustly) on applications not made in Watcom C.




Sent with Proton Mail secure email.

--- Original Message ---
On Friday, January 13th, 2023 at 10:22 AM, Knedlik  
wrote:


> I think I’ll stick to inline assembly.
> Now onto solving my divide by zero problem which I managed to create somehow. 
> Help there would be appreciated as well, even if getting a bit off topic. 
> Mainly knowledge on how to debug on dos will be appreciated.
> 
> 
> 
> ___
> Freedos-devel mailing list
> Freedos-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/freedos-devel


___
Freedos-devel mailing list
Freedos-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freedos-devel


Re: [Freedos-devel] Linking asm with C

2023-01-13 Thread Knedlik
I think I’ll stick to inline assembly.
Now onto solving my divide by zero problem which I managed to create somehow. 
Help there would be appreciated as well, even if getting a bit off topic. 
Mainly knowledge on how to debug on dos will be appreciated.



___
Freedos-devel mailing list
Freedos-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freedos-devel


Re: [Freedos-devel] Linking asm with C

2023-01-13 Thread Steve Nickolas

On Fri, 13 Jan 2023, Knedlik wrote:

To be fair, I myself am not sure about this. It’s the default options, 
so I would assume the watcom linker and whatever memory model open 
watcom is using.


The default for OpenWatcom is the small model.

I happen to know how to do this only for the specific usage case of "void 
function, takes void" and the specific combination of the 32-bit compiler 
and NASM.  You'll probably have to do more research to figure out the 
specifics for the 16-bit compiler and how to send parameters.


With the specific combination of WCL386 and NASM you do this in NASM:

  cpu   386
  bits  32
segment   _TEXT public align=4 class=CODE USE32
global_asmentry

_asmentry:

And in C, you declare it "extern void cdecl asmentry(void);"

-uso.___
Freedos-devel mailing list
Freedos-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freedos-devel


Re: [Freedos-devel] Linking asm with C

2023-01-13 Thread Knedlik
To be fair, I myself am not sure about this. It’s the default options, so I 
would assume the watcom linker and whatever memory model open watcom is using.



___
Freedos-devel mailing list
Freedos-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freedos-devel


Re: [Freedos-devel] Linking asm with C

2023-01-13 Thread Danilo Pecher
Oh dear, if you really want an answer for that, you need to give more
infos, like which linker are you using, which memory model?

On Thu, 12 Jan 2023 at 20:45, Knedlik  wrote:
>
> Hello,
> I’m currently trying to make a function in a separate assembly file, but I’m 
> having problems linking it with a C program. Are there any guides that show 
> how to do this?
> Thanks in advance,
> -Knedlik
>
> ___
> Freedos-devel mailing list
> Freedos-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/freedos-devel


___
Freedos-devel mailing list
Freedos-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freedos-devel


Re: [Freedos-devel] Linking asm with C

2023-01-13 Thread tom ehlert
> I’m currently trying to make a function in a separate assembly
> file, but I’m having problems linking it with a C program.

it always helps to take the time to describe the problem you are
facing, like


what compiler, assembler, linker

WHAT KIND OF PROBLEMS

Tom



___
Freedos-devel mailing list
Freedos-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freedos-devel


Re: [Freedos-devel] Linking asm with C

2023-01-12 Thread Louis Santillan
The tools you are using do matter.  Which C Compiler, which Assembler,
which Linker?

On Thu, Jan 12, 2023 at 3:39 PM Ralf Quint  wrote:
>
> On 1/12/2023 11:43 AM, Knedlik wrote:
> > Hello,
> > I’m currently trying to make a function in a separate assembly file, but 
> > I’m having problems linking it with a C program. Are there any guides that 
> > show how to do this?
> > Thanks in advance,
>
> Yes, follow the documentation of your C compiler for this, also
> considering the memory model (of the C compiler) you are writing your
> assembly routines for.
>
> Beside that, your question is just way to ambiguous to give you any
> further information/hints...
>
>
> Ralf
>
>
>
>
> ___
> Freedos-devel mailing list
> Freedos-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/freedos-devel


___
Freedos-devel mailing list
Freedos-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freedos-devel


Re: [Freedos-devel] Linking asm with C

2023-01-12 Thread Ralf Quint

On 1/12/2023 11:43 AM, Knedlik wrote:

Hello,
I’m currently trying to make a function in a separate assembly file, but I’m 
having problems linking it with a C program. Are there any guides that show how 
to do this?
Thanks in advance,


Yes, follow the documentation of your C compiler for this, also 
considering the memory model (of the C compiler) you are writing your 
assembly routines for.


Beside that, your question is just way to ambiguous to give you any 
further information/hints...



Ralf




___
Freedos-devel mailing list
Freedos-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freedos-devel