patjomki Posted May 1, 2016 Share Posted May 1, 2016 Hello, I try to write some data to disk. Unfortunately the data isn't written. What is wrong? org $0600EOL equ $9B ;ATASCII CODE FOR END OF LINE CHARACTEROPEN equ $03 ;TOKEN FOR OPENING A DEVICE OR FILEOWRIT equ $08 ;TOKEN FOR "OPEN FOR WRITE OPERATIONS"PUTCHR equ $0B ;TOKEN FOR "PUT CHARACTER"CLOSE equ $0C ;TOKEN FOR CLOSING A DEVICE OR FILEIOCB2 equ $20 ;OFFSET FOR IOCB NO.2ICCOM equ $0342 ;COMMAND BYTE (CONTROLS CIO OPERATIONS)ICBAL equ $0344 ;BUFFER ADDRESS (LOW BYTE)ICBAH equ $0345 ;BUFFER ADDRESS (HIGH BYTE)ICBLL equ $0348 ;BUFFER LENGTH (LOW BYTE)ICBLH equ $0349 ;BUFFER LENGTH (HIGH BYTE)ICAX1 equ $034A ;AUXILIARY BYTE NO.1ICAX2 equ $034B ;AUXILIARY BYTE NO.2CIOV equ $E456 ;CIO VECTORDEVNAM dta c "D1:HIGHSCOR.TXT",EOLTXTBUF dta "123456abc",EOL start LDX #IOCB2 ; open file LDA #OPEN STA ICCOM,X LDA <DEVNAM STA ICBAL,X LDA >DEVNAM STA ICBAH,X LDA #OWRIT ; we want to write some data to disk STA ICAX1,X LDA #0 STA ICAX2,X JSR CIOV LDA #PUTCHR ; character by character STA ICCOM,X LDA <TXTBUF STA ICBAL,X LDA >TXTBUF STA ICBAH,X LDA #$0a ; 10 bytes are planned to be written "123456abc" and EOL STA ICBLL,X LDA #0 STA ICBLH,X JSR CIOV ; finally let's write the data LDA #CLOSE ; don't forget to close the file STA ICCOM,X JSR CIOV loop jmp loop When I change devnam to <devnam dta c "S:",EOL"> everything is written fine to the screen, but obviously I want to write to disk d1: instead. Quote Link to comment Share on other sites More sharing options...
Rybags Posted May 1, 2016 Share Posted May 1, 2016 (edited) When CIOV returns to you the Y register contains the status/error code for the operation. To help debugging you could store it from each occurrence into a work area then check it over when the run is complete. Being that it's an open output to disk, the OPEN command should do some I/O to the disk. Especially if the file exists already, it should delete it before the write operation is able to start. If using emulation, turning off stuff like SIO patch and enabling IO sounds can help there. Also note of course you need a Dos loaded, or if using the D: device in the emulator, have writes enabled for it. Edited May 1, 2016 by Rybags Quote Link to comment Share on other sites More sharing options...
patjomki Posted May 1, 2016 Author Share Posted May 1, 2016 When CIOV returns to you the Y register contains the status/error code for the operation. To help debugging you could store it from each occurrence into a work area then check it over when the run is complete. Being that it's an open output to disk, the OPEN command should do some I/O to the disk. Especially if the file exists already, it should delete it before the write operation is able to start. If using emulation, turning off stuff like SIO patch and enabling IO sounds can help there. Also note of course you need a Dos loaded, or if using the D: device in the emulator, have writes enabled for it. Thanks for your reply. As with altirra and wudsn I am able to have source level debugging so I can check the Y register immediately. I am also going to try your other suggestions. I am using MyDos and as an .atr in Altirra with read/write operations enabled. In the meantime I found out that when I write a different TXTBUF for example "abcdefghi" everything is running fine. Strange. Quote Link to comment Share on other sites More sharing options...
Rybags Posted May 1, 2016 Share Posted May 1, 2016 In the code you post you don't have c" for TXTBUF so maybe it's only assembling it as a hex sequence of several bytes. But really, that shouldn't matter anyway. You're doing command $0B which is PUT CHARACTERS where you supply a bufffer address and buffer length. The EOL isn't essential either, it has no special properties when used for disk files or with that command. The Status bytes you get back should give a clue though... I get the feeling it's not a problem with your program. Quote Link to comment Share on other sites More sharing options...
flashjazzcat Posted May 1, 2016 Share Posted May 1, 2016 (edited) DTA is indeed writing out the original string as internal character codes, although according to the documentation it should default to "byte" if no type is specified. Since lowercase letters have the same ATASCII and internal codes, the alternative string is written correctly despite the lack of data type. Edited May 1, 2016 by flashjazzcat Quote Link to comment Share on other sites More sharing options...
patjomki Posted May 2, 2016 Author Share Posted May 2, 2016 (edited) The Status bytes you get back should give a clue though... I get the feeling it's not a problem with your program. Well, actually it is a combination of several things. First it was a problem of internal character code/ATASCII. Now that I corrected the code it is running fine with both Altirra/Original hardware. Unfortunately when I use the above corrected code snippet in my complete program it doesn't work on original hardware but on Altirra. So there still IS a bug in my complete programm. When I change my complete programm that I jmp to the subroutine it works on both Altirra/original hardware but not when I jmp to the subroutine at the intended moment (well, when there is a new highscore saved). Have to investigate that later when the rest of the program is finished. Edited May 2, 2016 by patjomki Quote Link to comment Share on other sites More sharing options...
Rybags Posted May 2, 2016 Share Posted May 2, 2016 The data you're passing to PUT shouldn't matter. It could equally be all zeros. OK, it seems the obvious has been overlooked. There's some glaring errors in the program. Where you're setting up addresses for DEVNAM and TXTBUF are the problem. You need # to specify immediate mode. As it is you're probably generating a z-page instruction. ie, not: LDA <DEVNAM STA ICBAL,X LDA >DEVNAM STA ICBAH,X What's needed: LDA #<DEVNAM STA ICBAL,X LDA #>DEVNAM STA ICBAH,X Quote Link to comment Share on other sites More sharing options...
flashjazzcat Posted May 2, 2016 Share Posted May 2, 2016 OK, it seems the obvious has been overlooked. There's some glaring errors in the program. Where you're setting up addresses for DEVNAM and TXTBUF are the problem. You need # to specify immediate mode. As it is you're probably generating a z-page instruction. That's the first thing I spotted but immediate mode is implied for '<' and '>' with or without the hash in MADS. 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.