flat assembler
Message board for the users of flat assembler.

Index > DOS > what is the problem with this code it doesn't open file.

Author
Thread Post new topic Reply to topic
Muhammad ibtisam abdullah



Joined: 15 Apr 2010
Posts: 6
Muhammad ibtisam abdullah 17 Apr 2010, 10:53
Code:
org 100h
use16
mov di,fn
read:
 mov ah,01
 int 21h
cmp al,13
 je ent
 stosb
 jmp read
ent: mov al,0
       stosb


mov ax,3501h
mov dx,fn
int 21h
xchg bx,ax

fn db 128 dup (?)
    

it does not open file although file exists.
Post 17 Apr 2010, 10:53
View user's profile Send private message Reply with quote
ManOfSteel



Joined: 02 Feb 2005
Posts: 1154
ManOfSteel 17 Apr 2010, 14:32
How about you use this to open the file and exit properly with this (before the buffer).
Post 17 Apr 2010, 14:32
View user's profile Send private message Reply with quote
rCX



Joined: 29 Jul 2007
Posts: 172
Location: Maryland, USA
rCX 17 Apr 2010, 14:45
I happen to have this example demonstrating what ManOfSteel said

open.asm
Code:
org 100h
use16

MaxFileSize = 256

;Open the file.
mov ah,3Dh
mov al,00h                ;Open file as read only
mov dx,FileName              ;dx = file name
int 21h                      ;returns: ax = file handle

;Read its text.
mov bx,ax              ;bx = file handle
mov ah,3Fh
mov cx,MaxFileSize   ;cx = max number of bytes to read
mov dx,FileData            ;dx = place to put text
int 21h                      ;returns: ax = ActualFileSize

;"$" terminate text.
mov di,ax            ;di = ActualFileSize
add di,FileData         ;di = FileData + Actual File Size
mov al,"$"               ;al = "$" terminator
stosb

;Print text.
mov ah,9h
mov dx,FileData
int 21h

;End the program and close all files.
mov ah,4Ch
mov al,00h         ;return 0 to DOS
int 21h

FileName db "test.txt",0
FileData db MaxFileSize+1 dup (?)    


test.txt
Code:
Hello, World!    


Remember, Ralf Brown's interrupt list is your friend Smile
Post 17 Apr 2010, 14:45
View user's profile Send private message Reply with quote
ring0



Joined: 14 Mar 2005
Posts: 15
Location: Australia
ring0 21 Apr 2010, 00:04
Thankyou ManOfSteel and rCX. I have a question concerning the use of this type of code under Windows.

I have an old DOS game. It has the ability to save and load the state of play. I run this game under WindowsXP on a FAT32 partition. The filenames in use are all 8.3 and everything works normally.

Since this is a DOS game it occurs to me that the game code will use DOS INT 0x21 for the file operations. I understand that Windows can trap and redirect interrupts.

Now, in relation to my work I sometimes have the need to open a data file, make a few changes to the raw data and resave the file for processing by some windows application.

So to my question: Can I reliably use a simple com file with int 0x21 and execute it under Windows to accomplish this type of task? What are the issues surrounding this approach? e.g. are there particular functions that should be avoided?
Post 21 Apr 2010, 00:04
View user's profile Send private message Reply with quote
ManOfSteel



Joined: 02 Feb 2005
Posts: 1154
ManOfSteel 21 Apr 2010, 00:20
I haven't coded for MSDOS in years, and for frequent (or rather infrequent) use I stopped at Windows 2000 due to my machines' low specs, so I don't really know for sure how XP and later behave with MSDOS programs. But on all older systems I've never had any problem running my old MSDOS programs or 15 years old programs (and games) and I expect XP to be very similar to 2000 in that area.

So is your work related to this game or what, because if you're using Windows, then why not also code for it using its API?
Post 21 Apr 2010, 00:20
View user's profile Send private message Reply with quote
ring0



Joined: 14 Mar 2005
Posts: 15
Location: Australia
ring0 21 Apr 2010, 22:52
The game is not related to my work. The scenario is:

I want to be able to write a small application very quickly to make some changes to a data file. The computers at work do use XP so yes I could use the Windows API but that would require a bit of learning on my part. So I was asking is it possible to just throw it together as a DOS com and run that under windows - I guess I will just give it a try. Thanks.
Post 21 Apr 2010, 22:52
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 22 Apr 2010, 04:51
ring0 wrote:
…I could use the Windows API but that would require a bit of learning on my part.
If you're familiar with standard C library, MSVCRT can be used for I/O with ease. 16-bit code (especially real-mode) becoming unsupported in the later Windows (though you can use emulator/VM to run it).
Post 22 Apr 2010, 04:51
View user's profile Send private message Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 22 Apr 2010, 21:06
ring0, you should have no problem on 32-bit Windows, but it's 64-bit that won't allow DOS at all. Well, and since you're talking about games, Vista and 7 don't allow DOS graphics at all, so yeah, you will need DOSBox.

It might actually be easier to just use C or Pascal or some other HLL that can be easily compiled for whatever platform (including Windows) in this case.
Post 22 Apr 2010, 21:06
View user's profile Send private message Visit poster's website 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.