vol Posted April 28, 2021 Share Posted April 28, 2021 I am not able to make my program to send its data to a file via redirection. My code is very simple. I put it into a file named hello.asm: move.l #helloworld,-(A7) move #9,-(A7) trap #1 addq.l #6,A7 move #0,-(A7) trap #1 helloworld: dc.b "Hello, World!",$d,$a,0 I compile it into hello.tos by vasm: vasmm68k_mot -m68000 -Ftos -align -o hello.tos -L hello.lst -nosym hello It works fine from CLI (emucon2 or gulam) but I failed to redirect the program output to a file. hello >file doesn't work. Is it possible to write a TOS program which output can be redirected like for CLI utilities or under MS-DOS? There is a way because CLI utilities work with redirection, for instance dir > file or ls > file work fine under emucon2 or gulam respectively. Quote Link to comment Share on other sites More sharing options...
ggn Posted April 28, 2021 Share Posted April 28, 2021 I had a look at how the old C libraries did this (in my case I looked at Sozobon C). They seem to be outputting each string character using Bconout(): move.w ch,-(sp) move.w #2,-(sp) move.w #$03,-(sp) trap #13 addq.l #6,sp "2" is the output device, the console. Try outputting a single character using this and see if redirection works. If it does, you can use this to print each character. For more info on Bconout, have a look at reference books like the Atari Compendium. Hope this helps. 1 Quote Link to comment Share on other sites More sharing options...
ParanoidLittleMan Posted April 28, 2021 Share Posted April 28, 2021 I checked in Atari ST ProfiBuch. Bconout has no option for output to file. Available: Parallel port. Serial port. Console. MIDI, IKBD chip. And actually, for me would be surprise if it would redirect to file, because that's different story than sending single byte . And Atari ST people just don't use console, what is not part of TOS too. There are such programs, and not popular. And since you want to output whole text to file, I think that best solution is to simply use file write function of memory segment. So, usual Open File - trap #1 $3D, Write file - trap #1 $40, Close file. By write you need to give memory address of start and length. Just 3 calls instead 1, still peace of cake. And if it is of use can add at start selection - to screen or to file ? Output to file has benefit of avoiding screen operations during CPU performance test. Here mean those calculation related tons of zyphers. I would make it so: output to both - of used setting(s), final result. 1 Quote Link to comment Share on other sites More sharing options...
moulinaie Posted April 28, 2021 Share Posted April 28, 2021 Hi, You can write a program that will read the command line. If it is empty, then it displays on the screen. If there is something, it is supposed to be a filename and the programe creates/writes/closes this file instead of using the standard output. You would call it this way: hello (output to screen) hello mytext.txt (output to file mytext.txt) And as suggested by @ParanoidLittleMan, your program can use the same routines for display or save to file. Only the start would be different. Guillaume. 1 Quote Link to comment Share on other sites More sharing options...
ParanoidLittleMan Posted April 28, 2021 Share Posted April 28, 2021 Yep, if it should create different file names for output, then use extension TTP (TOS takes parameters) - what will open text input before start - so like command line. Input appears in base page of running APP . 1 Quote Link to comment Share on other sites More sharing options...
moulinaie Posted April 28, 2021 Share Posted April 28, 2021 Hello, This is the HELLO WORLD adapted for output to screen or to a file. Attached you'll find the source code and the TTP program. If you leave the parameter box empty, then it displays on the screen and waits for a key. If you write a filename as the parameter (such as OUTPUT.TXT), it will create it and write to it. Back to desktop without key press. OUTPUT "redirect.ttp" move.l 4(sp),a0 ; basepage lea 128(a0),a3 ; the command line move.l $18(a0),a1 add.l $1c(a0),a1 ; end address of my used space add.l #$200,a1 ; room for the stack move.l a1,sp ; stack ! sub.l a0,a1 move.l a1,-(sp) move.l a0,-(sp) clr.w -(sp) move #$4a,-(sp) trap #1 ; MSHRINK, reduce space lea 12(sp),sp moveq #0,d0 move.b (a3)+,d0 ; command line length beq.s no_file ; if zero, then no filename specified clr.b 0(a3,d0.w) ; else, make sure that the command line ends with zero clr -(sp) ; standard attribute pea (a3) ; the name in the command line move #60,-(sp) ; fcreate trap #1 addq.l #8,sp move d0,handle ; saves the handle bmi.s no_file ; if negative, then creation has failed ! move d0,-(sp) ; my file move #1,-(sp) ; standard output handle move #70,-(sp) ; fforce -> redirect standard output to my file! trap #1 addq.l #6,sp st mode bra.s common no_file: sf mode common: pea text(pc) ; my text move.l #text_end-text,-(sp) ; number of bytes move #1,-(sp) ; standard output move #64,-(sp) ; fwrite trap #1 lea 12(sp),sp tst.b mode ; display to the screen? beq.s no_file2 ; yes! so just wait for a key and quit move handle,-(sp) ; else, my file move #62,-(sp) ; fclose trap #1 addq.l #4,sp bra.s common_end ; don't wait for a key, just quit no_file2: move.l #$20002,-(sp) ; wait for a key trap #13 addq.l #4,sp common_end: clr -(sp) trap #1 ; pterm, back to TOS data text: dc.b "Hello World !" text_end: even bss mode: ds.w 1 ; MSB = 0 for screen, FF for file handle: ds.w 1 even end Guillaume. redirect.zip 1 Quote Link to comment Share on other sites More sharing options...
vol Posted April 28, 2021 Author Share Posted April 28, 2021 (edited) Thank you very much. However it is an unexpected surprise for me that the Atari ST OS doesn't have a standard shell. Modern OS (Microsoft Windows, Mac OS, Linux, ...) have a wide variety of shells... TOS is so similar to MS-DOS that it was difficult to imagine that they officially ignored shells completely. I have just checked Bconout - it doesn't work with redirection. Gulam doc claims that this shell supports redirection but it also has a disclaimer Note that because of TOS and compiler peculiarities, not all external commands will behave as above. I couldn't make the redirection to work for external commands under Gulam. I have checked maybe about dozen other shells and some of them are claimed as supporting redirection. But no-one actually works. What a strange impediment! Edited April 28, 2021 by vol Quote Link to comment Share on other sites More sharing options...
moulinaie Posted April 28, 2021 Share Posted April 28, 2021 41 minutes ago, vol said: I have just checked Bconout - it doesn't work with redirection. So you have to use FWRITE ! Guillaume. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.