laoo Posted December 2, 2019 Share Posted December 2, 2019 (edited) Hi. I've got my LynxSD few days ago and I've tried to use it's API to access SD card. I program in assembly so I've manually compiled LynxSD functions from C and essentially got stuck at the very beginning. What I've done is calling LynxSD_Init: stz IODIR lda #$aa sta RCART1 And then tried to call LynxSD_OpenFile which starts from calling WriteByte which in turn has as a first statement: "while (*IODAT & AUXMASK);" compiled to: L0 lda IODAT and #$10 bne L0 Aaaaand essentially that's as far as my code goes as this loop never ends. Could some good soul point me what wrong am I doing? I think that since the library is written in C there must be some C runtime initializations essential to proper work of LynxSD library. Any ideas what initializations it might be? Edited December 2, 2019 by laoo Quote Link to comment Share on other sites More sharing options...
Nop90 Posted December 2, 2019 Share Posted December 2, 2019 In the init part you should only STZ IODIR, initializing the other value isn't needed as @SainTreported, and could create problemen on the new model of the cart next to come. But this is not a problem with the old model. this is how the c code is compiled: _AUXMASK: .byte $10 ; init stz $FD8A ; wait SD not busy before writing a byte L00C8: lda _AUXMASK and $FD8B pha pla bne L00C8 Just out of curiosity: can't understald that pha pla sequence? maybe a delay decided by the copiler? Quote Link to comment Share on other sites More sharing options...
laoo Posted December 2, 2019 Author Share Posted December 2, 2019 Thanks! It looks more or less the same and the difference must be somewhere else. Does cc65 generate full assembly listing with it's runtime initialization code, or maybe do you know where to find sources of these? 1 hour ago, Nop90 said: Just out of curiosity: can't understald that pha pla sequence? maybe a delay decided by the copiler? No. I don't think that it's something different than just sheer compiler's mindlessness ? Quote Link to comment Share on other sites More sharing options...
Nop90 Posted December 2, 2019 Share Posted December 2, 2019 (edited) compiling the c files CC65 creates .s files that are processed by AS65. I use to look at them if can't find a bug in C. You should also check if you correctly set bit 6 of the EEPROM field in the rom header. Without it the cart goes in sleep mode after loading your rom, and don't know what value could return reading from it. Since the cart chip should be an ATMEL chip, probably before setting it in sleep mode the pins are set to tri-state (I use to do this way), so you can get random values reading it. Edited December 2, 2019 by Nop90 1 Quote Link to comment Share on other sites More sharing options...
laoo Posted December 2, 2019 Author Share Posted December 2, 2019 (edited) 40 minutes ago, Nop90 said: You should also check if you correctly set bit 6 of the EEPROM field in the rom header. Without it the cart goes in sleep mode after loading your rom, and don't know what value could return reading from it. WOW ? Where do you know this from? It looks like plain magic - to set undocumented LNX header bit to prevent cartridge to go to sleep. Indeed I ignored this whole field. It will be first thing to check when I'll be back home. Thanks! EDIT: I found the 6th bit specification that it distinguishes cartridge to be a a SD cart: https://atarigamer.com/lynx/lnxhdrgen But certainly I woundn't look in that direction. Hope it will be it. Edited December 2, 2019 by laoo Quote Link to comment Share on other sites More sharing options...
laoo Posted December 2, 2019 Author Share Posted December 2, 2019 @Nop90 It was the case. After setting 6th bit of eeprom field in LNX header the loop ends. Thanks a lot for the tip! Quote Link to comment Share on other sites More sharing options...
Nop90 Posted December 2, 2019 Share Posted December 2, 2019 Welcome. This was explained some time ago when I was trying to code a Retro HQ SD driver that works on emulator or programmed carts without hanging. Previous homebrews needed to have two separate releases for SD cart and real eeprom. Quote Link to comment Share on other sites More sharing options...
Igor Posted December 3, 2019 Share Posted December 3, 2019 This header field was agreed on between @karri and RetroHQ some time back, good you found info in my LNX header tool, maybe I need to write a short tutorial on how to program with the Lynx SD cart (or ask @SainT to do it since he makes the hardware ?) Quote Link to comment Share on other sites More sharing options...
laoo Posted December 3, 2019 Author Share Posted December 3, 2019 I still have problems with loading any file, but haven't debugged it too much as we're busy with SV entry. But surely I'll try to tackle it after the party. I'll write my finding as, I presume, am the first person to try in in assembly. Quote Link to comment Share on other sites More sharing options...
laoo Posted March 9, 2020 Author Share Posted March 9, 2020 @Nop90 I'm stuck in communication with filesystem. Could you, please, share simplest possible program that can read from and/or write to a file with assembly output of CC65 that I could analyze what I'm doing wrong. It just does not work to me and I have no clue why. Quote Link to comment Share on other sites More sharing options...
Nop90 Posted March 9, 2020 Share Posted March 9, 2020 I'll do it in as soon as I have some time (in the next days), but not haveing "yet" a SD cart can't check if it works. Quote Link to comment Share on other sites More sharing options...
laoo Posted March 9, 2020 Author Share Posted March 9, 2020 @Nop90 I'll check it for you Quote Link to comment Share on other sites More sharing options...
+karri Posted April 28, 2020 Share Posted April 28, 2020 I tried to compile a SD version of On Duty but with the AtariGamer firmware I don't seem to be able to access saves at all Does anyone know what SD cart software version to use to get the saves to work? -- Edit: obviously XUMP works with the eeprom. So it is something in my sources. Edit2: case solved. Some undiciplined monkey had been messing with my code. The monkey will get fired. Edit3: I thought of releasing the full game to give something more to play. But when I now play it I remember all the bugs that have yet to be ironed out. So it will take some time... Quote Link to comment Share on other sites More sharing options...
laoo Posted April 29, 2020 Author Share Posted April 29, 2020 (edited) BTW. I see that @Nop90 is either busy or has no SD cart yet. So could anyone write simplest possible program that reads some bytes from some file? Or ideally copies few bytes from file to file? I'm stuck with using LynxSD from assembly and has no infrastructure to do it myself in cc65. I hope that reverse-engineering such program would point me in right direction. Edited April 29, 2020 by laoo Quote Link to comment Share on other sites More sharing options...
+karri Posted April 29, 2020 Share Posted April 29, 2020 1 hour ago, laoo said: BTW. I see that @Nop90 is either busy or has no SD cart yet. So could anyone write simplest possible program that reads some bytes from some file? Or ideally copies few bytes from file to file? I'm stuck with using LynxSD from assembly and has no infrastructure to do it myself in cc65. I hope that reverse-engineering such program would point me in right direction. I just compiled the C-file to asm. Hope this helps. LynxSD.sLynxSD.cLynxSD.h And a program to read the entire eeprom to memory: static const char SDSavePath[] = "/saves/onduty.sav"; if (LynxSD_OpenFile(SDSavePath) == FR_OK) { LynxSD_ReadFile((void*)&completedmissions[0], 128); LynxSD_CloseFile(); } To write the eeprom you need to use a different routine: LynxSD_WriteFile((void*)&completedmissions[0], 128); Quote Link to comment Share on other sites More sharing options...
laoo Posted April 29, 2020 Author Share Posted April 29, 2020 @karri I suspect that the problem might be somewhere in initialization. It might be that cc65 runtime might do something that is essential to LynxSD to function properly and I don't do it in my assembly. I don't remember exact place now, but my code just hangs on waiting for a byte to arrive (IIRC while checking the status of OpenFile). So what I would really need is a complete program that I would analyze and copy required initializations to my code. Quote Link to comment Share on other sites More sharing options...
+karri Posted April 29, 2020 Share Posted April 29, 2020 19 minutes ago, laoo said: @karri I suspect that the problem might be somewhere in initialization. It might be that cc65 runtime might do something that is essential to LynxSD to function properly and I don't do it in my assembly. I don't remember exact place now, but my code just hangs on waiting for a byte to arrive (IIRC while checking the status of OpenFile). So what I would really need is a complete program that I would analyze and copy required initializations to my code. There is two things I could see that will cause this. Initialize the AUDIN properly. I am doing it in my bootloader. ; ; 4. set AUDIN to output ; A9 1A lda #$1a ; audin = out, rest = out, ; ; noexp = in, cart addr = out, ext pwd = in ; 8D 8A FD sta IODIR ; ; ; 5. set AUDIN to HIGH ; A9 0B lda #$0B ; Set AUDIN high ; 85 1A sta $1a ; Save local copy to ZP ; 8D 8B FD sta IODAT The second thing is to add a timeout to the first access. FRESULT res; res = LynxSD_OpenFileTimeout (SDSavePath); if (res == FR_OK) { // There is a card with a pre-made file /saves/onduty.sav that is 128 bytes lon } This OpenFileTimeout should just poll the IPDAT bit for a certain time. If it does not change then the SD hardware is not there. You must also set the lnxhdr[60] = $41 to tell the SD cart that there is an eeprom. And also tell the emulator that there is a physical eeprom 93c46. Quote Link to comment Share on other sites More sharing options...
Nop90 Posted April 29, 2020 Share Posted April 29, 2020 10 hours ago, laoo said: BTW. I see that @Nop90 is either busy or has no SD cart yet. Sorry, I'm still waiting my SD cart, and I'm very busy too, because Italy is starting phase 2 of the Covid lockdown, with a gradual reopening of the production activities, and the workload of my job is returning at it's normal volume. Quote Link to comment Share on other sites More sharing options...
laoo Posted July 19, 2021 Author Share Posted July 19, 2021 (edited) Hi! I'm digging out the topic due to having further problems. I've got some trivial code that initializes LynxSD (simple stz IODIR), opens the file and reads some data. It works fine on LynxSD but hangs on LynxGD. Apparently it loops indefinitely while waiting for nonzero AUDIN bit in IODAT. I can't find on the forum any definitive answer about the difference in programming both. A tried to initialize IODIR with 16 and 0xa without luck. What could I be doing wrong? Edited July 19, 2021 by laoo Quote Link to comment Share on other sites More sharing options...
laoo Posted July 20, 2021 Author Share Posted July 20, 2021 Did ANYONE succeeded in reading a file from SD card in LynxGD? @Nop90 do you have any working code? Sorry for flooding but it's a bit frustrating as I can't crack it for few days now and I'm working on some project for SillyVentrure 2020+1 which is in a month from now... Quote Link to comment Share on other sites More sharing options...
thefred Posted July 20, 2021 Share Posted July 20, 2021 The LynxGD supports eeprom but only if it is listed in the header. Maybe you can go that route and then it will work with LynxGD and also Elcheapo. Elcheapo doesn't need it in the header to work but LynxGD does. Quote Link to comment Share on other sites More sharing options...
laoo Posted July 20, 2021 Author Share Posted July 20, 2021 @thefred I don't need eeprom but SD access as I'm writing software that needs to read some data from SD. I've cleared eeprom flag in the header and left only SD flag but it did not change anything. Quote Link to comment Share on other sites More sharing options...
Nop90 Posted July 20, 2021 Share Posted July 20, 2021 Let me check my old code (summer 2020), I f I remember well I was able to read the SD if the EEPROM emulation was not enabled. I asked a firmware revision enabling to use SD and EEPROM at the same time, but there was no answer. Quote Link to comment Share on other sites More sharing options...
laoo Posted July 20, 2021 Author Share Posted July 20, 2021 (edited) @Nop90 I would be grateful if you would give me a tip what you did to read files from LynxGD... Looking forward to it Edited July 20, 2021 by laoo Quote Link to comment Share on other sites More sharing options...
Igor Posted July 21, 2021 Share Posted July 21, 2021 Check the official repository for the code - https://github.com/RetroHQ/LynxGDLib It's in C but there's not all that much code really so you should be able to translate it or use the compiled .s files from CC65 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.