flat assembler
Message board for the users of flat assembler.

Index > High Level Languages > Calling interrupts in VC++

Author
Thread Post new topic Reply to topic
nvictor



Joined: 17 Feb 2007
Posts: 31
nvictor 30 Mar 2007, 22:41
The writing of a simple ASCII text mode program turns into a nightmare. Before suggesting me to look at Windows API -- which I resisted to do because I'm a newbie at c++ --, here is the story.

It started with a nice algorithm, a listing of functions to be written, and me realizing that there is no standard way to set the cursor's position or to clear the screen. Since I know assembler, I thought I could have used my old asm codes in inline assembler blocks. Windows decided otherwise. This is what he -- or she; to please some -- said: Access violation reading location 0xffffffff.

I've deciphered the mysterious phrase into a simpler one: I can't call bios interrupts in Windows. Backward compatibility: nice but what's the point of not allowing access to bios interrupts?

This is what I've got so far:

Code:
#include <iostream>
#include <stdlib.h> // for system function
using namespace std;

typedef unsigned short WORD; // defining word type

void ClearScreen(WORD upper_left, WORD lower_right);

int main()
{
    // bottom right position on a 80x25 text screen.
    WORD upper_left = 0;
    WORD lower_right = (24*16)+78;

    cout << "Filling" << endl;
    cout << " the screen" << endl;
    cout << "  with some" << endl;
    cout << "  dummy text." << endl;
    
    // pause
    system("PAUSE");

    // calling assembler function
    ClearScreen(upper_left, lower_right);

    cout << "Cursor is not reset!" << endl;

    return 0;
}

/* Clear a screen -- 80x25 text -- with current attribute.            *
 * with arguments, upper left and lower right locations                  *
 * upper_left  : (row1 * 16) + col1 because CH is row1 and CL is col1 *
 * lower_right : (row2 * 16) + col2 because DH is row2 and DL is col2 */
void ClearScreen(WORD upper_left, WORD lower_right)
{
    __asm {
        mov    ah, 08h                        ; request get current attribute
        int 10h                            ; and
        mov bh, ah                        ; move it to bh

        mov ax, 0600h                    ; scroll screen with attribute,
                                        ; al = numbers of row; 00 is fullscreen
        mov cx, upper_left                ; upper left location
        mov dx, lower_right                ; lower right location
        int 10h            
    }
}    


Will a miracle save me from learning Windows API?[/code]
Post 30 Mar 2007, 22:41
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1905
DOS386 30 Mar 2007, 23:53
Quote:
Will a miracle save me from learning Windows API?


Use DOS Laughing

Code:
    __asm {
       mov    ah, 08h                        ; request get current attribute
       int 10h                            ; and
       mov bh, ah                        ; move it to bh
       mov ax, 0600h                    ; scroll screen with attribute,
                                       ; al = numbers of row; 00 is fullscreen
       mov cx, upper_left                ; upper left location
       mov dx, lower_right                ; lower right location
       int 10h            
    } 
    


BIOS INT's do work in 16-bit RM DOS code, with some care also in
DPMI code, but NEVER in Windaube code Laughing

http://board.flatassembler.net/topic.php?t=6633

What compiler do you use ? Some >10 years old versions (having DOS
target) might help Laughing

_________________
Bug Nr.: 12345

Title: Hello World program compiles to 100 KB !!!

Status: Closed: NOT a Bug
Post 30 Mar 2007, 23:53
View user's profile Send private message Reply with quote
nvictor



Joined: 17 Feb 2007
Posts: 31
nvictor 30 Mar 2007, 23:59
My program should work under windows. Does that mean that the only way is to learn the WIn32 API ??
Post 30 Mar 2007, 23:59
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1905
DOS386 31 Mar 2007, 00:05
YES. Shocked

_________________
Bug Nr.: 12345

Title: Hello World program compiles to 100 KB !!!

Status: Closed: NOT a Bug
Post 31 Mar 2007, 00:05
View user's profile Send private message Reply with quote
nvictor



Joined: 17 Feb 2007
Posts: 31
nvictor 31 Mar 2007, 14:15
No pain. No gain.
Post 31 Mar 2007, 14:15
View user's profile Send private message Reply with quote
Filter



Joined: 08 Oct 2006
Posts: 67
Filter 17 Apr 2007, 12:16
http://msdn2.microsoft.com/en-us/library/ms682073.aspx

You don't have to learn the whole windows api to control the console window just these functions should get you where you are going.

SetConsoleCursorPosition and SetConsoleCursorInfo should get you what you need.
Post 17 Apr 2007, 12:16
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 17 Apr 2007, 12:30
if you don't want to learn API, you can use some library which uses API and provides different interface
Post 17 Apr 2007, 12:30
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 618
cod3b453 01 May 2007, 19:31
There's a cheat using system("cls"), but i've never used it...
Post 01 May 2007, 19:31
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
f0dder 02 May 2007, 22:55
If you don't want to learn anything new, quit programming.

No, you can't call the 16bit DOS/BIOS interrupts from 32bit mode, thanks whatever_deity MS for not following the typical DPMI-extended-dos-interrupts style. APIs are easier to lookup, and with PlatformSDK everything becomes easy when you learn how to find a suitable "entrypoint" for researching.

system("cls") is an ugly hack. filter has already given you two entrypoints to MSDN/PlatformSDK, from where it should be really easy to dig up the rest of the info you need. I'll give you another hint: WriteConsoleOutput.
Post 02 May 2007, 22:55
View user's profile Send private message Visit poster's website Reply with quote
Goplat



Joined: 15 Sep 2006
Posts: 181
Goplat 02 May 2007, 23:15
WriteConsoleOutput could clear the screen but you'd have to first allocate a buffer depending on how big the screen is, fill it up with the character/attribute you want, call the function, then free it. It's easier to use FillConsoleOutputAttribute and FillConsoleOutputCharacter.
Post 02 May 2007, 23:15
View user's profile Send private message Reply with quote
penguinglx



Joined: 05 Aug 2007
Posts: 10
penguinglx 23 Aug 2007, 06:41
U should take a look at IA32 System Programming Paper released by intel + DPMI

then maybe u want to read WIn95 Programming Secrets book

that way might help u some
Post 23 Aug 2007, 06:41
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.