TGB1718 Posted December 13, 2020 Share Posted December 13, 2020 I'm opening a screen (Antic mode 1) using a combination of cc65 and ca65 modules. Initially I tried _graphics(17) and wrote a text string to the screen using CIO in a .s module channel #6, this didn't produce anything on the screen. I decided to open the screen in the assembler module, so closed #6, then opened channel 6, then using channel 6 wrote to the screen again using channel 6 and it works fine. Here's the problem, I need to reserve some memory at the top of RAM, so did the usual get the value of location 106 ($6A), subtracted 14 from the value and stored the value back to 106. Then I opened the screen and now the text does not appear on screen as before. I have tried all sorts of different values to reserve, but it appears that any lowering of RAM prevents the output to the screen. I wrote a small routing in MAC/65 to test the code and it works fine with or without the RAM reduction. So my question:- is there something I'm not aware of that cc65/ca65 needs to prevent this from happening, doesn't really make sense that it doesn't work when the only difference is the lowering of RAMTOP. Any help appreciated void main(void) { POKE(RAMTOP,PEEK(RAMTOP)-14); INDEX=gr7; opench(); // GRAPHICS 17 OPEN printscreen2(); while(1); } this is the ca65 open routine .proc _opench: near .code LDA #CLOSE ; close channel first STA ICCOM,X JSR CIOV LDX #$60 LDA #OPEN STA ICCOM,X LDA # <_NAME STA ICBAL,X LDA # >_NAME STA ICBAH,X LDA #$0C ; RW STA ICAX1,X LDY _INDEX LDA MODE,Y ; GR.7/GR.8 STA ICAX2,X JSR CIOV STY _retcode RTS .endproc MODE: .BYTE 1,2 _INDEX: .BYTE 0 _NAME: .BYTE "S:\n" and the print module _print6: LDX #$60 ; channel 6 opened by _graphics statement LDA _POINTER STA ICBAL,X LDA _POINTER+1 STA ICBAH,X LDA #PUTREC STA ICCOM,X LDA #40 ; Max line length STA ICBLL,X LDA #0 STA ICBLH,X JSR CIOV STY _retcode RTS .endproc _retcode: .byte 0 ; return code _BUFF: .res 50 ; line buffer _POINTER: .word 0 Quote Link to comment Share on other sites More sharing options...
sanny Posted December 13, 2020 Share Posted December 13, 2020 > I have tried all sorts of different values to reserve, but it appears that any lowering of RAM prevents the output to the screen. How did you reserve the memory? Quote Link to comment Share on other sites More sharing options...
baktra Posted December 13, 2020 Share Posted December 13, 2020 Hello, you should know that the _graphics() function returns the actual IOCB number used to open the S: device. It is not guaranteed to be IOCB #6 (like in Atari BASIC) To reserve a piece of memory, you will need to use your own ld65 linker configuration file. Changing RAMTOP is of course honored by the Atari OS and Atari BASIC, but not by the C runtime library. For more details, refer to the atari.cfg linker configuration file (look for the RESERVED_MEMORY symbol), and to the cc65-source/libsrc/atari/crt0.s to see how important memory layout related pointers are initialized before your main() starts. And of course here to see the description of the memory layout. 2 1 Quote Link to comment Share on other sites More sharing options...
TGB1718 Posted December 13, 2020 Author Share Posted December 13, 2020 @baktra thanks for the info, I'll look into it Quote Link to comment Share on other sites More sharing options...
TGB1718 Posted December 13, 2020 Author Share Posted December 13, 2020 1 hour ago, baktra said: you should know that the _graphics() function returns the actual IOCB number used to open the S: device. Sort of, it returns '3', so I used this as the channel to print to, still nothing, I did an open _graphics(1) so it had the text box and my print data went there, so I assumed there must be 2 open channels, as it returned 3, I tried 2, no joy, so I tried 1 and hey presto my text appears, not sure I could rely on that happening every time though. Still have to try the config file to reserve memory Quote Link to comment Share on other sites More sharing options...
baktra Posted December 13, 2020 Share Posted December 13, 2020 1 hour ago, TGB1718 said: Sort of, it returns '3', so I used this as the channel to print to, still nothing, I did an open _graphics(1) so it had the text box and my print data went there, so I assumed there must be 2 open channels, as it returned 3, I tried 2, no joy, so I tried 1 and hey presto my text appears, not sure I could rely on that happening every time though. Still have to try the config file to reserve memory I am sorry. I was wrong. The _graphics() function doesn't return IOCB number but a file descriptor (fd). Therefore printing should be done as follows: #include <atari.h> #include <unistd.h> int main() { int fd = _graphics(2); write(fd,"hello",5); while(1); return 0; } 1 Quote Link to comment Share on other sites More sharing options...
sanny Posted December 14, 2020 Share Posted December 14, 2020 On 12/13/2020 at 5:27 PM, baktra said: To reserve a piece of memory, you will need to use your own ld65 linker configuration file. Not really. You can use cl65 -t atari -Wl "-D__RESERVED_MEMORY__=0x2000" ... 1 Quote Link to comment Share on other sites More sharing options...
sanny Posted December 14, 2020 Share Posted December 14, 2020 I suggest to read the documentation: https://cc65.github.io/doc/atari.html Quote Link to comment Share on other sites More sharing options...
TGB1718 Posted December 14, 2020 Author Share Posted December 14, 2020 @sanny thank you, I was looking at the config file, but was having a bit of trouble making sense of it as the examples didn't really cover what I wanted, this may be a better way Quote Link to comment Share on other sites More sharing options...
Mariano DM Posted November 25, 2023 Share Posted November 25, 2023 On 12/13/2020 at 8:27 AM, baktra said: you should know that the _graphics() function returns the actual IOCB number used to open the S: device. It is not guaranteed to be IOCB #6 (like in Atari BASIC) I see the reason in your example, I ended up storing the IOCB in a location, there is a routine for getting the iocb from descriptor: ;setscreen fd - file descriptor for screen .proc __setscreen jsr fdtoiocb sta SIOCB rts .endproc SIOCB: .byte $00 that means either to drag it as parameter or call as a set method: int fd = _graphics(8); _setscreen(fd); I wonder if this is needed at all or cc65 can just guarantee channel 6 Quote Link to comment Share on other sites More sharing options...
sanny Posted November 25, 2023 Share Posted November 25, 2023 cc65 uses the first free IOCB. 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.