flat assembler
Message board for the users of flat assembler.

flat assembler > DOS > How to use EMS memory or DOS Extenders ?

Goto page Previous  1, 2, 3
Author
Thread Post new topic Reply to topic
A$M



Joined: 29 Feb 2012
Posts: 94
About pointers in interruptions: when I use the code:
Code:
        mov ax, 9
        mov bx, 0
        mov cx, 0
        mov dx, cursor
        int 33h                   ; This changes the mouse cursor    

FASM returns the error (obvious, I know how protected mode works):
Quote:
Error: invalid use of symbol.

But when I use this code:
Code:
        mov ax, 9
        mov bx, 0
        mov cx, 0
        mov edx, cursor
        int 33h                   ; This changes the mouse cursor    

FASM does not return error, but results in a strange cursor. Suggestions?
Post 09 Feb 2013, 16:24
View user's profile Send private message Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 518
Location: Munich
A$M wrote:

Code:
        mov ax, 9
        mov bx, 0
        mov cx, 0
        mov edx, cursor
        int 33h                   ; This changes the mouse cursor    

FASM does not return error, but results in a strange cursor. Suggestions?


It would help to post a full working example, not just a small piece of code.
How is ES register set and how is cursor defined ?
Post 09 Feb 2013, 22:49
View user's profile Send private message Send e-mail Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Why are you making life hard Confused , i told you a simple way to do what you want.
Example;
Code:
;=========================================================;
; hello world!                                   06/12/05 ;
;---------------------------------------------------------;
; By Dex4u.                                               ;
;                                                         ;
; Here is a simple "hello world" program.                 ;
; for Dos2x, using the calltable functions.               ;
; To assemble in Dos2x, use fasm as follows               ;
; A:\run fasm.dex hello.asm hello.dex                     ;
;=========================================================;
use32
        ORG   0x400000          ; where our program is loaded to
        jmp   start             ; jump to the start of program.
        db    'DEX3'            ; We check for this, to make shore it a valid Dos2x file.

msg1:   db 'Hello world! ',13,10,'$'
msg2:   db 'Press anykey to return to command.com ',13,10,'$'

 ;----------------------------------------------------;
 ; Start of program.                                  ;
 ;----------------------------------------------------;

start:
        mov   ax,18h            ; set ax to nonlinear base
        mov   ds,ax             ; add them to ds
        mov   es,ax             ; and es.
 ;----------------------------------------------------;
 ; Get int21h address.                                ;
 ;----------------------------------------------------;
        mov   eax,21h
        int   21h
        jc    Int21hError
        mov   dword[Int21h],eax
 ;----------------------------------------------------;
 ; Get calltable address.                             ;
 ;----------------------------------------------------;
        mov     edi,Functions                         ; fill the function table
        mov     al,0                                  ; so we have some usefull functions
        mov     ah,0x0a
        int     50h
 ;----------------------------------------------------;
 ; Try print string.                                  ;
 ;----------------------------------------------------;
        ; print string 1       
        mov   edx,msg1          ; this point's to our string.
        mov   ah,09h            ; function number
        call  dword[Int21h]     ; this call dos function.

        ; print string 2
        mov   edx,msg2          ; this point's to our string.
        mov   ah,09h            ; function number
        call  dword[Int21h]     ; this call dos function.

        ; wait for keypress function.
        mov   ah,07h            ; function number
        call  dword[Int21h]     ; this call the print function.
        
Int21hError:
        ret                     ; This returns to the CLI/GUI

 ;----------------------------------------------------;
 ; Data.                                              ;
 ;----------------------------------------------------;

Int21h     dd 0
include 'Dex.inc'                                     ; Here is where we include our "Dex.inc" file    

You can call them like any other 16bit dos functions.
Your program is loaded to 4MB your free to used any memory from theres to top of ram.
It got a fasm port with ide and high res graphics, game examples
You can test it in a emulator like gemu

http://www.dex-os.com/Dos2x/dos2x.img

This example is running on top of freedos, but it runs on any dos.

It runs much faster on real PC.


Last edited by Dex4u on 09 Feb 2013, 23:06; edited 1 time in total
Post 09 Feb 2013, 22:55
View user's profile Send private message Reply with quote
ACP



Joined: 23 Sep 2006
Posts: 203
Check your definition of cursor and spelling.

BTW: there is a great book you might want to grab to learn about programming with DOS Extenders and it is surprisingly still in print: http://www.bookdepository.com/DOS-Windows-Protected-Mode-Al-Williams/9780201632187

Quote:

NO. PE->PX


Just to clarify this cryptic description. 32bit Dos Extenders today use Windows PE file format - some with additional features like internal executable file compression (WDOSX case) use their own file format to handle those. Basically over the time Dos Extenders were using different file format including NE for example (earlier most Dos Extenders were using their own file formats which were not compatible with each other) - hence you've got stubs for running the Dos Extender or using separate loader like RUN386 in case of PharLap 386|Dos Extender. Since DOS loader from INT 21h AH=4Bh does not know how to handle other files than COM and MZ 16bit EXE executable you need a stub and/or loader to handle loading DOS Extended application into memory and run it switching to protected mode before executing first instruction of the executable. This also means your linker must be able to produce correct executable so it can be handle by the stub and/or loader correctly.
Post 09 Feb 2013, 23:03
View user's profile Send private message Reply with quote
A$M



Joined: 29 Feb 2012
Posts: 94
Well... The menu of my game (it works at 16bit mode with some changes).

PS: Notice that the cursor bits is absolutely right in the source code, that is, I'm pointing at the wrong place, probably...


Description: CRAZY!'s menu
Download
Filename: CRAZY!.rar
Filesize: 112.77 KB
Downloaded: 73 Time(s)

Post 10 Feb 2013, 13:00
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1904
> used the Mcrosoft (R) Incremental Linker Version 5.12.8078 and it worked

Maybe JAWALINK would do it too ... but why not format PE ???

> mov dx, cursor
> obvious, I know how protected mode works

NO. You can't pass addresses in 16-bit registers to 16-bit stuff from 32-bit PM code.

> FASM does not return error, but results in a strange cursor. Suggestions?

Disassemble the binary.
Post 11 Feb 2013, 05:07
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3172
Location: Denmark
DOS386 wrote:
NO. You can't pass addresses in 16-bit registers to 16-bit stuff from 32-bit PM code.

Do keep in mind that (some) DOS extenders handles this (by copying to/from a low-memory allocated buffer) for certain known DOS/BIOS APIs.

_________________
Image - carpe noctem
Post 11 Feb 2013, 16:19
View user's profile Send private message Visit poster's website Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1904
> (by copying to/from a low-memory allocated buffer) for certain known DOS/BIOS

Right ... but then it must be EDX, not DX ... if the example still doesn't work, then COFF or ES register can be the problem:

Japheth wrote:

> 33 ax=0009h define graphics cursor ES:E/DX
Post 12 Feb 2013, 07:26
View user's profile Send private message Reply with quote
A$M



Joined: 29 Feb 2012
Posts: 94
Quote:
33 ax=0009h define graphics cursor ES:E/DX

Well... ES:E/DX? ES is probably right and EDX is pointing for cursor.

I don't know what's wrong!!! Crying or Very sad
Post 13 Feb 2013, 12:35
View user's profile Send private message Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 518
Location: Munich
It would help to post a full working example, not just a small piece of code.

Please source only, no zip, no rar, maybe partly. Wink
Post 13 Feb 2013, 20:37
View user's profile Send private message Send e-mail Reply with quote
freecrac



Joined: 19 Oct 2011
Posts: 117
Location: Germany Hamburg
A$M wrote:
Can anyone write a hello world in "unreal mode"? Rolling Eyes

No problem with the 16 bit unrealmode. With DOS we can use int 21h, AH=9, DS:DX= Pointer of the string(terminated with a $(24h)). With using the Teletype output, AH=0Eh, AL = Character, BH = Page Number, BL = Color with int 10h we can print ASCII by ASCII to the textscreen. =>Same like in the real mode. But for some high grafikmodes using the LFB we have to self drawing all characters, if there is no Teletype output support aviable.
Code:
;--------------------------------------
T9  DB 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ;
    DB 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ;
    DB 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ;
    DB 0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0 ;   **
    DB 0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0 ;   ********
    DB 0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0 ;   **********
    DB 0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0 ;   ***********
    DB 0,0,0,1,1,0,0,0,0,0,0,1,1,1,0,0 ;   **      ***
    DB 0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0 ;          ****
    DB 0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0 ;      ********
    DB 0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0 ;    **********
    DB 0,0,0,1,1,1,1,1,0,0,0,1,1,1,0,0 ;   *****   ***
    DB 0,0,0,1,1,1,0,0,0,0,0,1,1,1,0,0 ;   ***     ***
    DB 0,0,0,1,1,1,0,0,0,0,0,1,1,1,0,0 ;   ***     ***
    DB 0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0 ;   ************
    DB 0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0 ;    ***********
;--------------------------------------     

Dirk
Post 14 Feb 2013, 09:19
View user's profile Send private message Send e-mail Reply with quote
freecrac



Joined: 19 Oct 2011
Posts: 117
Location: Germany Hamburg
A$M wrote:
About pointers in interruptions: when I use the code:
Code:
        mov ax, 9
        mov bx, 0
        mov cx, 0
        mov dx, cursor
        int 33h                   ; This changes the mouse cursor    

FASM returns the error (obvious, I know how protected mode works):
Quote:
Error: invalid use of symbol.

But when I use this code:
Code:
        mov ax, 9
        mov bx, 0
        mov cx, 0
        mov edx, cursor
        int 33h                   ; This changes the mouse cursor    

FASM does not return error, but results in a strange cursor. Suggestions?


Which mousedriver and which mouse do you use?

...

I like to use the PS2-Mousehandler from the BIOS for my Unrealmode-Applications and it works similar to the opensource Cutemouse-driver for DOS, but without using a driver. The main-routine of my applications draw the mouse-pointer to the screen.
So i can use any size and color depth of a mouse-pointer that i want to use, example using a free-form select picture with erased background colours recorded from my webcam:Image

Code:
checkPS2:
int 11h                 ; get equipment list
test    al, 3
jz  noPS2               ; jump if PS/2-Mouse not indicated
mov     bh,3
mov     ax, 0C205h
int 15h                 ; initialize mouse, bh=datasize
jc noPS2
mov     bh,3
mov     ax, 0C203h
int 15h                 ; set mouse resolution bh
jc noPS2
mov     ax, cs
mov     es, ax
mov     bx, OFFSET PS2dummy
mov     ax, 0C207h
int 15h                 ; mouse, es:bx=ptr to handler
jc noPS2
xor     bx, bx
mov     es, bx          ; mouse, es:bx=ptr to handler
mov     ax, 0C207h
int 15h
ret

noPS2:
stc
ret

PS2dummy:
retf
;---------------------------------------------------------
enablePS2:
call disablePS2
mov    ax, cs
mov    es, ax
mov    bx, OFFSET IRQhandler
mov    ax, 0C207h       ; es:bx=ptr to handler
int 15h
mov     bh,1            ; set mouse on
mov     ax, 0C200h
int 15h
ret
;-------------------------------
disablePS2:
xor     bx, bx          ; set mouse off
mov     ax, 0C200h
int 15h
xor     bx, bx
mov     es, bx
mov     ax, 0C207h      ; es:bx=ptr to handler
int 15h
ret
;---------------------------------------------------------------------------
IRQhandler:
                assume  ds:nothing,es:nothing
cld
push    ds
push    es
pusha
mov     ax, cs
mov     ds, ax
mov     bp,sp
mov     al,[bp+24+6]    ; buttons
mov     bl,al
shl     al,3            ; CF=Y sign bit
sbb     ch,ch           ; signed extension 9->16 bit
cbw                     ; extend X sign bit
mov     al,[bp+24+4]    ; AX=X movement
mov     cl,[bp+24+2]    ; CX=Y movement
xchg    bx,ax
neg     cx              ; reverse Y movement
popa
pop     es
pop     ds
retf
    

Hint: this code is not fully complete, because additional we have to place and to add some mov-operations into this handler above for to write the values of the movement/buttons to a known/reserved ram location from where our main-routine can get those values.

With USB lagacy enable in the Mainboard-BIOS we can use an USB-Mouse like a PS2-Mouse.

Dirk
Post 14 Feb 2013, 10:15
View user's profile Send private message Send e-mail Reply with quote
ACP



Joined: 23 Sep 2006
Posts: 203
freecrac wrote:
A$M wrote:
Can anyone write a hello world in "unreal mode"? Rolling Eyes

No problem with the 16 bit unrealmode. With DOS we can use int 21h, AH=9, DS:DX= Pointer of the string(terminated with a $(24h)).


Exactly - that is the whole point and beauty of using flat real mode in first place: you use all DOS functions just like in real mode since you are in real mode from DOS perspective. in FRM you don't need all the trickery with interrupts handling in protected mode and different executable file formats like in case of typical DOS extenders. In fact FRM uses protected mode just for few instructions (with interrupts disabled) in order to setup load segment registers properly and that it switches back to real mode.

So any 16 bit real mode DOS Hello World type example works in FRM after you set it up properly.

Also keep in mind that there is important difference between FRM and unreal mode (but those naming conventions tend to be mixed up) since unreal mode supports 32bit code segments while FRM does it only for data.

Take a look at this thread: http://board.flatassembler.net/topic.php?t=11940

If you'll wait a bit I've found some of mine old TASM sources of my FRM implementation and I plan to convert it to FASM and maybe release it.
Post 14 Feb 2013, 10:49
View user's profile Send private message Reply with quote
freecrac



Joined: 19 Oct 2011
Posts: 117
Location: Germany Hamburg
ACP wrote:
Also keep in mind that there is important difference between FRM and unreal mode (but those naming conventions tend to be mixed up) since unreal mode supports 32bit code segments while FRM does it only for data.

Take a look at this thread: http://board.flatassembler.net/topic.php?t=11940

Yes the naming for those modes are different and vary from programmer to programmer. I call the FRM the 16 bit Unrealmode to make it claer that we are using the 16 bit adressmode, because only with the word "flat" we can not know about which adressmode we are using.

;-----------------

But this particular statement is not true, .....
Quote:
....where the limit for all segment registers has been set to 4G...
....because we can not increase the stack- and the code-segmentsize.

...

I like to increase only the DS-Segmentsize to minimize segment prefixes, where the Datasegmentregister points to our datasegment. Higher adddresses can be calculate shown below:
Code:
nov ebx, High address obove the first MB
xor eax, eax
mov ax, ds
shl eax, 4 
sub ebx, eax

mov si, OFFSET VALUE
mov eax, [si]    ; DS:SI; DATA-segment; Low address in the first MB
mov [ebx], eax   ; DS:EBX; High address above the first MB
    

Dirk
Post 14 Feb 2013, 11:26
View user's profile Send private message Send e-mail Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2, 3

< 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-2018, Tomasz Grysztar.

Powered by rwasa.