6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Thu Nov 21, 2024 5:44 pm

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Mon May 17, 2021 6:33 pm 
Offline

Joined: Thu May 13, 2021 8:56 am
Posts: 31
Location: Hellevoetsluis-NL
Hello,
I started fig-Forth on my Pet2001 about 45 year ago.
Now I have the same fig-Forth running on a ESP32 with an SD-card aboard :wink:
Running a 6502 emulator written in C as processor.
I strubbel with the file system. It is running in ram for now from $4000-$E000 and I can save this to
the sd card. I have tried to change the sector to 512 bytes/sector en 2 block/screen.

SSIZE =512 ; sector size in bytesf (128)
NBUF =4 ; number of buffers desired in RAM (16)
; (SSIZE*NBUF >= 1024 bytes)
BMAG =2064 ; total buffer magnitude, in bytes
; expressed by SSIZE+4*NBUF (2112)

L992 .BYTE $85,"B/SC",$D2
.WORD L984 ; link to B/BUF
BSCR .WORD DOCON
.WORD 2 ; blocks to make one screen

But with no results. Is it possible to change this sector? and if yes what to changed to get it running?
The reason for this change is the amount of bytes in a file block on the sd card.

But for now I like it to play again and wold trough my old books.
Thanks for any help.
Cheers,
Jan (Hellevoetsluis,NL)


Top
 Profile  
Reply with quote  
PostPosted: Tue May 18, 2021 5:59 pm 
Offline

Joined: Wed Nov 11, 2020 10:42 pm
Posts: 104
Location: Kelowna Canada
Hi
I hesitate to reply as there are others here who are better qualified to respond, but from my perspective what you have done so far is correct. I only had NBUF=2 (and BMAG= 1032) when I implemented this for the Multicomp. Apart from that you must implement the routines that actually read and write to the SD card ( I changed that from the FIG-Forth listing eliminating -DISC and rewriting R/W to a setup for using Bios (or monitor code) to write or read the sector (block)). This does a raw read or write to the SD card and does not refer to a file system other than allowing or keeping an area exclusively for Forth to manage.
One place I made an error was in making an adjustment to DAREA to try and align this to a nice page boundary but discovered that in the code for +buf it makes a calculation so that my change messed up the buffer calculation. So ensure that DAREA=UAREA-BMAG.
I could send you a copy of my code but that might be more confusing as it is specific to my setup (using Grant Searle's Multicomp and monitor code from Daryl Rictor with code for reading and writing to the SD card interface from Maik Merten.))


Top
 Profile  
Reply with quote  
PostPosted: Wed May 19, 2021 10:22 am 
Offline

Joined: Thu May 13, 2021 8:56 am
Posts: 31
Location: Hellevoetsluis-NL
Thanks for the replay.
Have done the changes. My R/W is working wel.
When I give after a fresh start the comman n list the data is tken frombthe sd card.
But when I give n load the system is hanging.
When change back from 512 b/sector to 128 b/sector and change the other things back it works.
The reason for this exercise was look for the ability to read direct 512 bytes from the sd card with readBlock(block,buf)

I look forwards to see your source code, to see and learn.

Cheers,
Jan


Top
 Profile  
Reply with quote  
PostPosted: Wed May 19, 2021 11:43 am 
Offline

Joined: Thu May 13, 2021 8:56 am
Posts: 31
Location: Hellevoetsluis-NL
Found the problem.
When I use the ram drive a written in fig-Forth installation manual I can even
have acces to blocks of 1024 bytes without any problem. Have tested this.
I think my problem is accessing the sd card via the R/W.
Have make a file of 512*1024 byte on the sd card. I acces the screen with file.seek(blk*bytes_per_block); as position, and from there I read 1024 bytes to the buffer address.
I think thats this is going wrong, and therefore I looking for direct block acces of the sd card.
But it is hard to find a solution.

Cheers,
Jan


Top
 Profile  
Reply with quote  
PostPosted: Thu May 20, 2021 3:47 am 
Offline

Joined: Sun Apr 26, 2020 3:08 am
Posts: 357
Powersoft wrote:
Found the problem.
When I use the ram drive a written in fig-Forth installation manual I can even
have acces to blocks of 1024 bytes without any problem. Have tested this.
I think my problem is accessing the sd card via the R/W.
Have make a file of 512*1024 byte on the sd card. I acces the screen with file.seek(blk*bytes_per_block); as position, and from there I read 1024 bytes to the buffer address.
I think thats this is going wrong, and therefore I looking for direct block acces of the sd card.
But it is hard to find a solution.

Cheers,
Jan

I am not quite sure what you are doing here, but I believe the POSITION disk command requires a file to be open, whereas the direct block access does not. Open the 512k file and leave it open, then you should be able to navigate within the file with 1024 byte blocks using the POSITION command.

If you keep track of the Ref#'s, then you can also have more than one disk file on the SD card.


Top
 Profile  
Reply with quote  
PostPosted: Thu May 20, 2021 6:54 pm 
Offline

Joined: Thu May 13, 2021 8:56 am
Posts: 31
Location: Hellevoetsluis-NL
Thanks for the replay.

For the R/W I wrote the code
Code:
void RW(byte *codebuffer, int adr, int blk, int f)
{
  int bytes_per_block = 128;
  if (f==1) /* read from disk to memory */
  {
    file.seek(blk*bytes_per_block); /* position of the block */
    for (int i=0; i<bytes_per_block; i++) codebuffer[adr+i] = file.read() & 0x7f;
  }
  else /* write from disk to memory */
  {
    file.seek(blk*bytes_per_block); /* position of the block */
    for (int i=0; i<bytes_per_block; i++) file.write(codebuffer[adr+i]);
  }
}


And in the setup the code
Code:
File file;
  file = SD.open("/forth/VM.mem", "rb");


But the problem is that I open the file as "read byte, rb", but don't know how to combine open for read and write for binary file.
Please can you help me out with this?
Or do you have an example to acces the sd card for reading and writing?
I have create a file with bytes, is that correct?

Cheers,
Jan


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 13 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: