User Tools

Site Tools


storing_20structures_20in_20files

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
storing_20structures_20in_20files [2024/01/12 22:23] – Added BBCSDL code richardrussellstoring_20structures_20in_20files [2024/01/12 22:46] (current) – Add generic code (e.g. for BBCTTY) richardrussell
Line 4: Line 4:
 BB4W: BB4W:
 <code bb4w> <code bb4w>
-        SYS "WriteFile", @hfile%(file%), struct{}, DIM(struct{}), ^temp%, 0+      SYS "WriteFile", @hfile%(file%), struct{}, DIM(struct{}), ^temp%, 0
 </code> </code>
 BBCSDL: BBCSDL:
 <code bb4w> <code bb4w>
-        SYS "SDL_RWwrite", @hfile%(file%), struct{}, DIM(struct{}), 1+      SYS "SDL_RWwrite", @hfile%(file%), struct{}, DIM(struct{}), 1 
 +</code> 
 +Generic (e.g. BBCTTY): 
 +<code bb4w> 
 +      DEF PROCwritestruct(F%, s{}) 
 +      LOCAL s$ : PTR(s$)=s{} : !(^s$+4)=DIM(s{}) : BPUT#F%,s$; : !(^s$+4)=0 
 +      ENDPROC
 </code> </code>
 Similarly to read an entire structure **struct{}** from the file opened on channel **file%** do the following:\\ \\  Similarly to read an entire structure **struct{}** from the file opened on channel **file%** do the following:\\ \\ 
 BB4W: BB4W:
 <code bb4w> <code bb4w>
-        SYS "ReadFile", @hfile%(file%), struct{}, DIM(struct{}), ^temp%, 0+      SYS "ReadFile", @hfile%(file%), struct{}, DIM(struct{}), ^temp%, 0
 </code> </code>
 BBCSDL: BBCSDL:
 <code bb4w> <code bb4w>
-        SYS "SDL_RWread", @hfile%(file%), struct{}, DIM(struct{}), 1+      SYS "SDL_RWread", @hfile%(file%), struct{}, DIM(struct{}), 1 
 +</code> 
 +Generic (e.g. BBCTTY): 
 +<code bb4w> 
 +      DEF PROCreadstruct(F%, s{}) 
 +      LOCAL s$ : PTR(s$)=s{} : !(^s$+4)=DIM(s{}) : s$=GET$#F% BY LENs$ : !(^s$+4)=0 
 +      ENDPROC
 </code> </code>
 It is best not to mix these statements with conventional BASIC file reads and writes, but if you do you must flush BASIC's file buffers before each of the API calls, as follows:\\ \\  It is best not to mix these statements with conventional BASIC file reads and writes, but if you do you must flush BASIC's file buffers before each of the API calls, as follows:\\ \\ 
storing_20structures_20in_20files.1705098188.txt.gz · Last modified: 2024/01/12 22:23 by richardrussell