Author Topic: WARNING! usb8x crossing  (Read 8992 times)

0 Members and 1 Guest are viewing this topic.

Offline quasi_Phthalo

  • LV3 Member (Next: 100)
  • ***
  • Posts: 90
  • Rating: +1/-1
    • View Profile
WARNING! usb8x crossing
« on: June 25, 2010, 11:40:56 pm »
the setting:
I have braved the caverns of attempting to write an asm program that uses usb8x's msd driver to interface with a flash drive. I've managed to retrieve file handle to the file i want and read many correct bytes from it.  :)
the issue:
BUT, after a certain amount of time (the same every time), the data i am reading comes out as garbage. first the 'organized' kind of garbage that has patterns so it's obvious that it is actually data, just not the data i intended to read. then, comes some entirely random garbage. eventually, it runs across the correct data again after a while, but then it relapses again.  ???

what is going on? is the file handle being corrupted? is the driver not reading from the correct place?
i'm checking for the carry flag after each read and i'm checking that bc (# bytes read) = # bytes i told it to read

help! i'm drowing! thanks

Offline mapar007

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 550
  • Rating: +28/-5
  • The Great Mata Mata
    • View Profile
Re: WARNING! usb8x crossing
« Reply #1 on: June 26, 2010, 06:29:53 am »
I think the msd driver from usb8x is outdated. The MSD8x driver should do better.

Also, could you post code please? It might just be some stupid register corruption, you never know. (and Linus' Law: 'given enough eyeballs, all bugs are shallow')

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55942
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: WARNING! usb8x crossing
« Reply #2 on: June 26, 2010, 01:02:35 pm »
This is a bit off-topic but what is the difference between USB8x and MSD8x anyway?
« Last Edit: June 26, 2010, 01:02:54 pm by DJ Omnimaga »
Now active at https://discord.gg/cuZcfcF (CodeWalrus server)

Offline quasi_Phthalo

  • LV3 Member (Next: 100)
  • ***
  • Posts: 90
  • Rating: +1/-1
    • View Profile
Re: WARNING! usb8x crossing
« Reply #3 on: June 26, 2010, 01:35:16 pm »
wait, I always thought that MSD8x was just a GUI for the msd driver in USB8x. I don't think it has a driver of its own because because it won't run without USB8x.

well here's the section of code after a proper initialization:
Code: [Select]
#define numFrames 6360
#define fileName "/bwmov.bin",0
b_call(_RunIndicOff)
ld hl,sName
ld de,fileHandle
u_call(uDOS_openFile)
jp c,NoFile
NextFrame:
ld hl,fileHandle
ld de,plotSScreen
ld bc,768
u_call(uDOS_fileRead)
jp c,FileReadError
ld hl,768
sbc hl,bc
ld a,l
cp 0
jp nz,FileReadError
ld a,h
cp 0
jp nz,FileReadError
b_call(_GrBufCpy)
b_call(_GetCSC)
cp skClear
jp z,Exit
ld de,(FramesLeft)
dec de
ld (FramesLeft),de
ld a,e
cp 0
jr nz,NextFrame
ld a,d
cp 0
jr nz,NextFrame
jr Exit

FramesLeft: ;not static
.dw numFrames

sName:
.db fileName
fileHandle is located 128 bytes into the statVars (how big is statVars anyway?)
NoFile and FileReadError just clean up and exit the program

Offline quasi_Phthalo

  • LV3 Member (Next: 100)
  • ***
  • Posts: 90
  • Rating: +1/-1
    • View Profile
Re: WARNING! usb8x crossing
« Reply #4 on: June 26, 2010, 07:26:13 pm »
i realize that, per forum rules, i still need to wait 8 more minutes to make the 6 hour threshold so i can double post, but this is an important update:

there apparently is some corruption of the seek pointer! I altered the program to keep track of its own seek offset an reset the pointer between each read and it works almost* flawlessly! (the file is very large, so the seek pointer update time gets longer a n d  l o n  g  e   r  .  .    ., so its impractical) I really shouldn't have to do that though. the file read U_CALL should take care of that, right? Here's the new code:
Code: [Select]
#define numFrames 6360
#define fileName "/bwmov.bin",0
b_call(_RunIndicOff)
ld hl,sName
ld de,fileHandle
u_call(uDOS_openFile)
jp c,NoFile
NextFrame:
ld bc,fileHandle
ld hl,(SeekPointer)
ld de,(SeekPointer+2)
push hl
push de
u_call(uDOS_fileSeek)
pop de
pop hl
ld bc,768
add hl,bc
jr nc,_noCarry
inc de
_noCarry:
ld (SeekPointer),hl
ld (SeekPointer+2),de
ld hl,fileHandle
ld de,plotSScreen
ld bc,768
u_call(uDOS_fileRead)
jp c,FileReadError
ld hl,768
sbc hl,bc
ld a,l
cp 0
jp nz,FileReadError
ld a,h
cp 0
jp nz,FileReadError
b_call(_GrBufCpy)
b_call(_GetCSC)
cp skClear
jp z,Exit
ld de,(FramesLeft)
dec de
ld (FramesLeft),de
ld a,e
cp 0
jr nz,NextFrame
ld a,d
cp 0
jr nz,NextFrame
jr Exit

SeekPointer: ;not static
.dw 0,0

FramesLeft: ;not static
.dw numFrames

sName:
.db fileName
*even with the seek pointer corrected, the data is randomly garbage on some scattered reads. i have a hunch that these are the places where the seek pointer gets corrupted in the first place, perhaps?
« Last Edit: June 26, 2010, 07:27:07 pm by quasi_Phthalo »

SirCmpwn

  • Guest
Re: WARNING! usb8x crossing
« Reply #5 on: June 26, 2010, 07:27:57 pm »
We are a bit more lax for regular posters and Omnimaga veterans, but you have 35 posts and have been here less than a month.  Would 8 minutes have killed you?  There is also a button called "modify" up there just begging to be pressed.
Either way, try not to do it again.

Offline BrandonW

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 115
  • Rating: +38/-1
    • View Profile
Re: WARNING! usb8x crossing
« Reply #6 on: June 26, 2010, 07:30:08 pm »
msd8x is just an interface to the MSD driver in usb8x. The MSD driver is only in usb8x. There was a time when the driver was in msd8x itself, but it has since been shifted and integrated into usb8x itself.

So msd8x is just the interface (and it uses the extra RAM pages, which is why it doesn't work on newer 84+/SEs -- the MSD driver itself still works on those models).

As far as what you're seeing, I would check and make sure you're not using the same area of memory more than once (using more of statVars than you should be, for example -- 531 bytes). I've driven myself insane more times than I can count because of strange memory corruption issues because of things like that.

SirCmpwn

  • Guest
Re: WARNING! usb8x crossing
« Reply #7 on: June 26, 2010, 07:31:18 pm »
So msd8x is just the interface (and it uses the extra RAM pages, which is why it doesn't work on newer 84+/SEs -- the MSD driver itself still works on those models).

I have a newer 84+ without the extra pages and msd8x works fine for me, with the exception of the occasional garbled text.

Offline BrandonW

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 115
  • Rating: +38/-1
    • View Profile
Re: WARNING! usb8x crossing
« Reply #8 on: June 26, 2010, 07:34:23 pm »
It's sheer luck that it works on your newer 84+.

When I find the time, I'll rework it to not use the extra RAM pages.

usb8x itself is also long overdue for an update.

SirCmpwn

  • Guest
Re: WARNING! usb8x crossing
« Reply #9 on: June 26, 2010, 07:35:58 pm »
Yep, so we can mess around with Blue8x, like I've asked for several times :)

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: WARNING! usb8x crossing
« Reply #10 on: June 26, 2010, 07:40:11 pm »
It's sheer luck that it works on your newer 84+.

When I find the time, I'll rework it to not use the extra RAM pages.

usb8x itself is also long overdue for an update.

Update == FAT32? :)
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline quasi_Phthalo

  • LV3 Member (Next: 100)
  • ***
  • Posts: 90
  • Rating: +1/-1
    • View Profile
Re: WARNING! usb8x crossing
« Reply #11 on: June 26, 2010, 08:08:06 pm »
SirCmpwn: did 8 minutes kill you? well, let's get back on topic, shall we?

Brandon, I've relocated the file handle (and the USBDriverCall and the USBDriverBuf each) to some (isolated) memory inside the program where it couldn't possibly be corrupted accidentally, nor could they corrupt each other, but the same thing happened. Exact same garbage and everything, so I know it's not that.
Am I missing some error checking?
Is there a safe limit on the maximum number of bytes read at once?

(oh, yes, side note, FAT32 would be helpful because WINDOWS DOESN'T LET YOU PARTITION REMOVABLE MEDIA!)

SirCmpwn

  • Guest
Re: WARNING! usb8x crossing
« Reply #12 on: June 26, 2010, 08:10:03 pm »
SirCmpwn: did 8 minutes kill you? well, let's get back on topic, shall we?
Excuse you?

Also, FAT32 would be a nice feature, although I would just reformat it as FAT.

Offline quasi_Phthalo

  • LV3 Member (Next: 100)
  • ***
  • Posts: 90
  • Rating: +1/-1
    • View Profile
Re: WARNING! usb8x crossing
« Reply #13 on: June 26, 2010, 08:12:39 pm »
Quote
I would just reformat it as FAT
can't if its over 4gb because windows won't let you partition it

Quote
Quote from: quasi_Phthalo on Today at 08:08:06 PM
SirCmpwn: did 8 minutes kill you? well, let's get back on topic, shall we?
Excuse you?
i meant no disrespect. voice inflection is lost in typing: i was taking the matter lightly
« Last Edit: June 26, 2010, 08:14:53 pm by quasi_Phthalo »

Offline BrandonW

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 115
  • Rating: +38/-1
    • View Profile
Re: WARNING! usb8x crossing
« Reply #14 on: June 26, 2010, 08:14:21 pm »
SirCmpwn: did 8 minutes kill you? well, let's get back on topic, shall we?

Brandon, I've relocated the file handle (and the USBDriverCall and the USBDriverBuf each) to some (isolated) memory inside the program where it couldn't possibly be corrupted accidentally, nor could they corrupt each other, but the same thing happened. Exact same garbage and everything, so I know it's not that.
Am I missing some error checking?
Is there a safe limit on the maximum number of bytes read at once?

(oh, yes, side note, FAT32 would be helpful because WINDOWS DOESN'T LET YOU PARTITION REMOVABLE MEDIA!)

I think Windows actually will let you, it's just that all but the first partition will be inaccessible. I'm really not at all sure what happens with usb8x if you place a FAT16 primary partition at the very end of the drive.

I attempted to hack in FAT32 support long ago but failed. It would require a from-scratch rewrite of all the code, which probably needs to happen anyway.

Yep, so we can mess around with Blue8x, like I've asked for several times :)

I don't remember you asking for that, but yeah, that's the main priority for getting an update out.