By the way, I think I should have spelled it OS_GBPB. I always get this
wrong. Think 'heeby-jeeby'.
> ^ shouldn't that be static int? Wouldn't the const imply that the buffer
> never changes
The buffer doesn't change. It's its contents that change. I will try
removing the const.
> Sounds like rdir_buf is being re-used
The same code worked fine when compiled with Norcroft. With other stuff
omitted the code is:
#include sys.h
where sys.h contains:
extern int rdir(const char *dir, const int *buf, int offset);
followed by:
static int rdir_iter (lua_State *L);
#define RDIR_BUFLEN 256
static const int rdir_buf[RDIR_BUFLEN/sizeof(int)];
static int rdir_read (lua_State *L) {
lua_pushinteger(L,0); /* start */
lua_pushstring(L,lua_tostring(L,1));
lua_pushcclosure(L,&rdir_iter,2);
return 1;
}
static int rdir_iter (lua_State *L) {
int n;
int offset = (int) lua_tointeger(L,lua_upvalueindex(1));
const char * dir = lua_tostring(L,lua_upvalueindex(2));
n = rdir(dir,rdir_buf,offset);
if (n == -1) {
lua_pushnil(L);
return 1;
}
else {
lua_pushinteger(L, n);
lua_replace(L, lua_upvalueindex(1)); /* new offset */
lua_pushstring(L, (char *)(&rdir_buf[6])); /* name */
lua_pushinteger(L, rdir_buf[5]); /* filetype */
return 2;
}
}
and where rdir is defined in sys.s by:
.global rdir
.set BUFLEN, 256
rdir:
stmfd sp!,{r1-r6,r14}
mov r6,#0 @ no wild card
mov r5,#BUFLEN @ bufferlength
mov r4,r2 @ offset
mov r3,#1 @ number of items
mov r2,r1 @ buffer
mov r1,r0 @ directory name
mov r0,#12
swi 0x2000c @ XOS_GBPB
movvs r3,#0
cmp r3,#1
moveq r0,r4 @ next offset
mvnne r0,#0 @ -1 if no more
ldmfd sp!,{r1-r6,pc}
.type rdir %function
.size rdir, .-rdir
I am pretty sure that there is nothing wrong with rdir. After all,
the names are getting returned OK. Every time rdir is called from
within rdir_iter the buffer rdir_buf gets overwritten by the SWI.
That is how it is supposed to work. Nothing else messes with it.
You can forget about rdir_read; that is just the top level of the
C code called by RiscLua's riscos.dir function. The pages 2-70
and 2-71 in the PRMs explain what OS_GBPB is supposed to be doing.
Why are the filetypes coming out as zero, rather than some other value?
It has to be something trivial that I am not seeing. Actually, it does
not really matter; if I cut out the filetype part and just had the name
returned, that would be quite adequate for practical purposes. But then
I would still be left wondering why this code is not doing what is wanted.
--
Gavin Wraith (gavin@wra1th.plus.com)
Home page: http://www.wra1th.plus.com/
_______________________________________________
GCCSDK mailing list gcc@gccsdk.riscos.info
Bugzilla: http://www.riscos.info/bugzilla/index.cgi
List Info: http://www.riscos.info/mailman/listinfo/gcc
Main Page: http://www.riscos.info/index.php/GCCSDK
No comments:
Post a Comment