BIOS interrupt _int86 - c

I'm trying out some old code frome the book "Black art of 3d game programming". I know it is outdated but I started reading it and it's kind of fun and interesting. I downloaded the OpenWatcom C Compiler and made a new DOS Project in order to get this old code even compiled. I already compiled on piece of code where Videomode int13h is set and then I was able to draw pixels to the screen. But this was done with a C function called _setvideomode(). In the following example the videomode is set via the _int86 function which makes the interrupt call and the prototype should be in bios.h, but OpenWatcom says: No prototype found for function _int86. I am stuck now and don't know what to do ;) Here is the code:
void setGraphxMode(int mode){
union REGS inregs,outregs;
inregs.h.ah = 0;
inregs.h.al = (unsigned char)mode;
_int86(0x10,&inregs,&outregs);
}
int main(){
return 0;
}
Would appreciate any advise on this and yes I know: Graphics are done via DirectX or OpenGL these days. This is just for learning purpose! Thank you :)

Under OpenWatcom the call you are looking for is int386 I believe:
int386(0x10, &inregs, &outregs);

Related

What does the Serial method do? [Arduino]

I'm translating a program about an RFM Hopper Transmission from Arduino to C, but I'm stuck with the method Serial, since I don't exactly know what it does.
It only appears in the following line, inside the main of the program.
Serial.begin(115200);
I've searched online through the documentation of Arduino and only understand that it's used for comunication between the Arduino board and the other devices.
If cannot use it in my C program though, what am I missing?
https://www.arduino.cc/reference/en/language/functions/communication/serial/
If I can explain anything with more detail from my project please feel free to ask.
Serial is an object, predefined in the Arduino environment, which is in C++ (not C )
To use it, you should call Serial.begin(<baud>); in the setup() function of the Arduino environment, then you can use any method of Serial or the underlying base class
Stream

Sprintf and float values on serial port IAR

I've the following snippet of code which I'm compiling on my IAR workbench.
// global declaration
float fval = 3.14f;
uint8_t uartTxBuffer [100];
void function(void)
{
memset(uartTxBuffer,'\0',sizeof(uartTxBuffer);
sprintf(uartTxBuffer,"\n\r Value is %f",fval);
UartWrite(uart, uartTxBuffer,strlen(uartTxBuffer));
}
The output is
Value is %f // and not 3.14
Can someone explain me what is the issue in my code?
Is it the Uartwrite function or am I making some mistake in using the C language?
I've tried the same code using printf on Keil MDK and it outputs the correct value on the serial terminal. So is this an IDE issue?
Can someone guide me here?
After a brief research this came up
https://www.iar.com/support/tech-notes/general/problems-with-printf-floating-point-f-on-arm/
The problem seems to be the byte alignment of the Stack Pointer.
Set a breakpoint on the sprintf() call and check the value of the stack pointer in the debugger.
Most of the answers I found are related to FreeRTOS ( which I don't know if you are using it):
sprintf breaking under new FreeRTOS
sprintf %f corrupts stack
sprintf in FreeRTOS
A common solution is to resort to
a third party library called printf-stdarg.c that provides a tiny print/sprintf/printf implementation for use in cases where the libraries that come with the compiler are just too big for small embedded use
I hope this might help

How can I use sound and nosound function in code blocks

I have used sound and no sound function in turbo C++, but I cannot get it to work in code blocks compiler.
Program:
int main()
{
sound();
delay();
nosound();
return 0;
}
I have added definition for delay and it's working in other programs.
When I am compiling this code I am getting error as ::undefined reference to sound and no sound.
How can I make this work? Or is there a different solution I should use?
You can use "Beep" function which is in windows.h header file.
In Beep function you have to give 2 parameters , first is for frequency and second is duration in milliseconds.
You can '\a' which gives alert sound, '\a' should be placed in printf.
I'm doing this right now! But i'm using C, dunno if for C++ is the same.
The only thing i know is that you have to include the library dos.h to make it work.
the function is Beep(soundfrequency,delay);
give it a try with Beep(2000,2000);
Good luck :)

System calls not working in Atmel AVR Studio (with ASF)

I am not getting answers on the AVR Freaks forum and wonder if someone here could help me.
The answer might lie in this SO question, but I am not sure why it would be necessary.
Basically, I have my fist ever Atmel project (AVR studio 6, UC3 processor). The code compiles and links and I can load it to the Atmel board and step through in the debugger.
However, when I try to step over (or run until a breakpoint on the line after) a (valid) call to sprintf(), malloc() or memcpy() (there may be more, which I have not yet discovered), the IDE never returns to the next line of my code, just seeming to hang, or run forever.
[Note] Compiler optimization is off
Do I need to set some linker options (e.g link static (which I tried & it didn't help)? Or build with some library?
What confuses me is that the code compilers and links - what is being linked when I call these standard functions? If I need something else I would expect a compiler or linker error, but get none - so why won't my code run?
Sorry for such a stupid n00nb question, but it is my first micro-controller project.
I discovered that the CPU on my board is an Engineering Sample and not supported by Atmel Studio without a new io.h file.
I sort of figured that out from this question: http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=106652
Sorry to have troubled you.
what is being linked when I call these standard functions?
The AVR-libc, the implementation of the C standard library ported to the AVR platform.
so why won't my code run?
Compiler errors and runtime errors are not even related. Both of these lines are valid C and they compile, however, on most systems, I'd expect them to dump core:
int x = 1 / 0;
*(int *)0 = 41;
So it might be either:
a bug in the standard library (very unlikely), or
a bug in the online debugger (very unlikely), or
maybe you just expect something that is not supposed to happen?
Instead of trying to step over, what happens if you set a breakpoint at next line after the line you want to step over?
Also, does the operation change if you turn off compiler optimization?

Getting Started in C

I know there are many tutorials out there for getting started in C. However Its hard for me to apply the knowledge. The way I've always started out in languages is by writing scripts. Of course C is not a scripting language.
My question isn't so much about learning C as much as it is about how to get started applying C. Great I can write a temperature converter or a text-based rpg. Maybe its because in python I just write up the code in somefile.py and chmod +x somefile.py && somefile.py . I do not really have an equivalent process for C. Every time I read about C its a different compiling process with different flags. Can someone just give me some definite direction on best ways to apply C when you already work with higher-level dynamic scripting languages?
Btw. .. I'm asking about C and not C++.
I usually am on either OpenSuse 11 or Ubuntu 9.04 . "What compiler do i use" is part of the problem. In python there is no choice its just "python somefile.py" same with php or ruby. I didn't know there were choices.
write w.c
#include <stdio.h>
int main(int argc, char *argv[]) {
int i;
for (i = 0; i < argc; ++i) {
printf("Param %d is '%s'\n", i, argv[i]);
}
return 0;
}
and compile with
gcc -Wall -o w w.c
run
./w
As rogeriopvl wrote in a comment, the compilation process is really simple. Just write up the code in somefile.c and
gcc -o somefile somefile.c && ./somefile
(if you're using GCC, and if not, your compiler of choice can probably be invoked similarly) Unless/until you start getting into more complicated projects, it's barely any more complicated than a scripting language. (Well... okay, you may need to link some libraries, once you get beyond the basics. But still, not a huge deal.)
In fact, I did write myself a little shell script that allows me to use C as a scripting language. But the process for setting it up is a little more complicated than what you may want to get into at this stage - it's simpler to just run the compiler each time. Still, if you're interested, I can look up the directions (for Linux) and put them here.
C code needs to be compiled before the program can be run. The exact process is different depending on which platform and compiler you are working on.
For the most part, using an IDE (such as Visual studio, Eclipse, MonoDevelop, and a bunch of others) will do the nasty work for you so that you just have to press a button or click an icon. Download one of these
I asked myself this question when I was learning C. The problem here, if I can say this is a problem, is that C can be used in a broad range of applications and in a broad range of environments, which one with its own IDEs or compilers and libraries. Some examples where you can use C for real staff.
Embedded software. In this case you will probably use some lib.
Network programming (take a look at this book.
Device driver development.
Libraries (both for Linux/Windows and other OSs)
Well this list is endless.
O don't know if I help you with this question. If you give more details about what are you interested in, could be helpful
Good luck
The best advice I can give here is find a topic you're interested in, see if you can make a program to do what you want/assist in doing what you want/adding functionality to the interest of choice, and start coding.
This gives the bonus of doing something you're interested in, and at the same time making something that directly influences it. It should give the motivation to keep steaming onward with the learning process.
I'm working with C a lot at the moment with Linux Kernel modules and am relatively new to C. I've found this rewarding which I think is what's important for this sort of hobby 'temperature converter or a text-based rpg' type programming.
I also struggle finding an application of programming skills. Balance of challenge and reward is important I think.

Resources