+karri Posted November 4, 2021 Share Posted November 4, 2021 Most of my code appears to hang on various systems that lack the eeprom. I wonder if anyone has written a driver for 93c46 chip with a built-in timeout? Currently the driver waits for a handshake signal to see that the write cycle is complete. But according to the datasheet the maximum time for a write is 2ms. So I was thinking of just adding a few NOP's to delay the process slightly and skip the polling. The tick is 62.5 ns so I may need to sleep for 32000 ticks. What is the best way? Interrupt after 32000 ticks, use a timer, NOPs, listen on VBL interrupts and write one word per VBL? This could also be handled in user space. write(addr, val); delay(); if (read(addr) != val) return NO_EEPROM; return OK; Any ideas? Quote Link to comment Share on other sites More sharing options...
laoo Posted November 4, 2021 Share Posted November 4, 2021 One word per VBL should be bulletproof. And given that you won't write more than 60 words also unnoticeable for users. Quote Link to comment Share on other sites More sharing options...
+karri Posted November 4, 2021 Author Share Posted November 4, 2021 3 minutes ago, laoo said: One word per VBL should be bulletproof. And given that you won't write more than 60 words also unnoticeable for users. Makes sense. Usually I just may need to write two bytes at the end of a level (high score). Quote Link to comment Share on other sites More sharing options...
sage Posted November 4, 2021 Share Posted November 4, 2021 3 minutes ago, karri said: Makes sense. Usually I just may need to write two bytes at the end of a level (high score). just take the HBL counter Quote Link to comment Share on other sites More sharing options...
laoo Posted November 4, 2021 Share Posted November 4, 2021 Rule number one of engineering: don't over-engineer ? I just made it up, but the truth is that simplest solutions tend to be the best. Quote Link to comment Share on other sites More sharing options...
sage Posted November 4, 2021 Share Posted November 4, 2021 HLB counter tick is 100us even for the highest framerate the lynx supports. Quote Link to comment Share on other sites More sharing options...
+karri Posted November 4, 2021 Author Share Posted November 4, 2021 I might go with the cc65 clock() function. It maintains something called clock_count. It is a 3 byte data that gets incremented at every VBL. So if I just wait for the lowest byte to change twice I should be safe. Always. ... bad thinking ... It requires the game to actually use clock(). Perhaps I go with HBL after all... Quote Link to comment Share on other sites More sharing options...
+karri Posted November 4, 2021 Author Share Posted November 4, 2021 I hope this is the way to do the 2ms wait in asm. ; 2ms wait ldx #20 EE_wait1: lda HTIMCNT EE_wait2: cmp HTIMCNT beq EE_wait2 dex bpl EE_wait1 At least it compiles... On a side note I may maintain a master copy of the eeprom in RAM and if the eeprom fails I just don't care. static unsigned int eepromdata[64]; unsigned char haseeprom = 1; unsigned int eeprom_read(unsigned char pos) { if (haseeprom) { eepromdata[pos] = lynx_eeread_93c46(pos); } return eepromdata[pos]; } void eeprom_write(unsigned char pos, int val) { eepromdata[pos] = val; if (haseeprom) { lynx_eewrite_93c46(pos, val); if (val != lynx_eeread_93c46(pos)) { haseeprom = 0; } } } Quote Link to comment Share on other sites More sharing options...
+karri Posted November 4, 2021 Author Share Posted November 4, 2021 My logic was obviously flawed. I may need to poll for 20 complete cycles of horizontal scan lines instead of 20 ticks. Sigh... Quote Link to comment Share on other sites More sharing options...
laoo Posted November 4, 2021 Share Posted November 4, 2021 (edited) Yeah, a value of vcount should polled, not hcount. One line take 159 us for 60 fps refresh rate so 20 lines is 3.18 ms. You can try running it in Felix with logging on (running through lua file with logging set). It can tell about eeprom status. And you could test emulation in Felix at the same time Edited November 4, 2021 by laoo Quote Link to comment Share on other sites More sharing options...
+karri Posted November 4, 2021 Author Share Posted November 4, 2021 1 hour ago, laoo said: Yeah, a value of vcount should polled, not hcount. One line take 159 us for 60 fps refresh rate so 20 lines is 3.18 ms. You can try running it in Felix with logging on (running through lua file with logging set). It can tell about eeprom status. And you could test emulation in Felix at the same time The vcount way works ok in Mednafen and on a real Lynx with an eeprom chip. But it still freeze when it tries to read the eeprom on Felix. I am a bit new for Windows. Currently I have a Win 11 installed in my laptop but I tend to use Ubuntu over VMware. I should probably start looking for lua and compilers for running something on Win11. Currently I am running some Epic Unreal. But it is high level stuff - no code. Quote Link to comment Share on other sites More sharing options...
laoo Posted November 4, 2021 Share Posted November 4, 2021 (edited) You don't need anything. Felix has embedded lua interpteter. To "debug" in Felix you just need to create a lua file with the content: lnx = "full/path/to/image/file"; Log{ path = "full/path/to/trace/file.log" }; Run Felix for a while (with this file instead of given lnx image) and close it. You will end up with HUGE trace file in given location. Search in trace for lines with "EEPROM" text within. Edited November 4, 2021 by laoo Quote Link to comment Share on other sites More sharing options...
+karri Posted November 5, 2021 Author Share Posted November 5, 2021 My repo has an updated version of eeprom.s that waits for 20 scanlines instead of polling IODAT. The location in bitbucket.org/atarilynx/lynx.git and the file is in lynx/tools/cc65/libsrc/lynx/eeprom.s Quote Link to comment Share on other sites More sharing options...
enthusi Posted January 4, 2022 Share Posted January 4, 2022 Dear Karri, I have not yet tackled eeproms but intend to do so now Why are there so many eprom*.s files in that folder and is there a source for eeprom access code (or is that THE best document/source already?) Speaking of your branch of PCBs (of course!) Thank you very much! I have been absent from Lynx land for a while but never abandoned it, of course. Quote Link to comment Share on other sites More sharing options...
+karri Posted January 4, 2022 Author Share Posted January 4, 2022 35 minutes ago, enthusi said: Dear Karri, I have not yet tackled eeproms but intend to do so now Why are there so many eprom*.s files in that folder and is there a source for eeprom access code (or is that THE best document/source already?) Speaking of your branch of PCBs (of course!) Thank you very much! I have been absent from Lynx land for a while but never abandoned it, of course. @sage created a bunch of support files to lots of different eeproms. But currently everyone is mainly using the smallest one. 93c46 It has 16-bit words by default. And can hold 64 of them. Quote Link to comment Share on other sites More sharing options...
enthusi Posted January 17, 2022 Share Posted January 17, 2022 Ok, makes sense! Thank you for clarification.Seems quite straight forward so far. Best wishes! 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.