Jump to content
IGNORED

Basic problem with LynxSD Assembly programming


laoo

Recommended Posts

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 by laoo
Link to comment
Share on other sites

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?

 

 

 

Link to comment
Share on other sites

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 ?

 

 

Link to comment
Share on other sites

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 by Nop90
  • Thanks 1
Link to comment
Share on other sites

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 by laoo
Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

  • 3 months later...

@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.

Link to comment
Share on other sites

  • 1 month later...

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...

Link to comment
Share on other sites

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 by laoo
Link to comment
Share on other sites

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);


 

Link to comment
Share on other sites

@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.

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 1 year later...

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 by laoo
Link to comment
Share on other sites

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...

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...