keirf / flashfloppy

Floppy drive emulator for Gotek hardware
Other
1.35k stars 195 forks source link

Quickdisk firmware on Sharp MZ-800 issue #364

Closed ysblokje closed 4 years ago

ysblokje commented 4 years ago

I wired everything up according to the wiki and the machine is sure there is a drive there. I can format the drive (but does it?) and ask for a listing of files.

When I try to actually save information to disk I see the LED displays

And repeat.

When it's done saving it comes back with the error message "QD: Unformat err". Again if I ask for a listing, no error message appears and no file.

I would love to see this work on my machine but I have no idea where to even start to debug this. I did enable the logging firmware.

ysblokje commented 4 years ago

My config

## FF.CFG: Example FlashFloppy Configuration File

# Place in the root folder or FF/ subfolder of your USB drive.
# NOTE: If FF/ exists, IMG.CFG must reside there, not the root folder.

# Uncommented lines below are the default settings.
# Uncommented options cannot be overridden by settings in other config files.

##
## DRIVE EMULATION

# Floppy-drive interface mode
# shugart: P2=DSKCHG, P34=RDY
# ibmpc: P2=unused, P34=DSKCHG
# ibmpc-hdout: P2=HD_OUT, P34=DSKCHG (not generally needed: prefer 'ibmpc')
# akai-s950: P2=HD_OUT, P34=RDY (Akai S950)
# amiga: P2=DSKCHG, P34=DRIVE_ID (not generally needed: prefer 'shugart')
# jc: JC closed: ibmpc, JC open: shugart
interface = jc

# Host platform: Improves image-format detection for generic types such as IMG
# acorn: Acorn ADFS
# akai: Akai (S01, S20, S950), Korg, SC Prophet 3000
# casio: Casio (FZ-1)
# dec: DEC (RX33, RX50)
# ensoniq: Ensoniq (ASR, TS, etc)
# fluke: Fluke 9100
# gem: General Music (S2, S3)
# ibm-3174: IBM 3174 Establishment Controller
# kaypro: Kaypro
# memotech: Memotech
# msx: MSX
# nascom: Nascom
# pc98: NEC PC-98
# pc-dos: PC DOS Format (geometry determined from Bios Parameter Block)
# tandy-coco: Tandy Color Computer (CoCo)
# ti99: TI-99/4A
# uknc: UKNC / DVK Soviet PDP-11
# unspecified: Common default geometries (including IBM PC)
host = unspecified

# Pins 2 & 34 output (drive->host) manual configuration
# auto: Auto-configure from interface= setting
# nc: Unused/No Connection [eg. if pin is an input (host->drive) on your host]
# low: Always 0 volts (0v)
# high: Always 5 volts (5v)
# rdy: Drive ready (Ready = 0v)
# nrdy: Logical complement of above
# dens: Density mode (High Density = 0v)
# ndens: Logical complement of above
# chg: Disk changed (Changed = 0v)
# nchg: Logical complement of above
# Values: auto, nc, low, high, rdy, nrdy, dens, ndens, chg, nchg
pin02 = auto
pin34 = auto

# Forcibly write-protect images, or respect the FAT read-only attribute?
# Values: yes | no
write-protect = no

# Filter glitches in the SIDE-select signal shorter than N microseconds
# Values: 0 <= N <= 255
side-select-glitch-filter = 0

# Rotational offset of disk after a track change
# instant: No rotation during track change
# realtime: Emulate rotation of disk while track is changing
# Values: instant | realtime
track-change = instant

# Rotational offset of disk after draining a write to Flash
# instant: No rotation
# realtime: Disk rotates in real time during drain
# eot: Disk rotates to (near) end of track
# Values: instant | realtime | eot
write-drain = instant

# Index pulses suppressed when RDATA and WDATA inactive?
# Values: yes | no
index-suppression = yes

# Milliseconds from head-step start to RDATA active.
# Values: 0 <= N <= 255
head-settle-ms = 12

# Milliseconds delay from motor-on to drive ready.
# On a standard unmodified Gotek the motor signal is not connected and a
# non-default value here will have no effect. Most systems and software do
# not care about correct motor behaviour, and default (ignore) works fine.
# Values: ignore | 0 <= N <= 1000
motor-delay = ignore

# What causes the disk-change (chg) signal to reset after disk insertion?
# step: Step command received
# pa14: CHGRST (pin 1 on old Sony drives), connected to PA14 (JTCK/SWCLK)
# delay-N: Automatically after N*0.5sec (0 <= N <= 15)
chgrst = step

##
## STARTUP / INITIALISATION

# Disk image loaded or ejected at startup?
# Values: yes | no
ejected-on-startup = no

# Which image (or folder) is selected at startup?
# last: Last-selected item at power-off (recorded in IMAGE_A.CFG)
# static: Static path specified in INIT_A.CFG
# init: First item in root folder
# Values: last | static | init
image-on-startup = last

# Time in milliseconds to attempt to probe attached display.
# You may set this to 0 if you have a 2-digit LED display attached.
# Values: 0 <= N <= 65535
display-probe-ms = 3000

##
## IMAGE NAVIGATION

# Auto-select the current file after N seconds
# N=0: disable auto-select
# Values: 0 <= N <= 255
autoselect-file-secs = 2

# Auto-select the current folder after N seconds
# N=0: disable auto-select
# Values: 0 <= N <= 255
autoselect-folder-secs = 2

# Sorting of folder entries in native navigation mode.
# always: Always sort folder entries. Large folders may be truncated.
# never: Never sort folder entries, instead presenting them in FAT order.
# small: Only sort folders which are small enough to sort in full.
# Values: always | never | small
folder-sort = always

# Priority of files vs subfolders when sorting folder entries:
# folders: Folders listed before files
# files: Files listed before folders
# none: Files and folders are not differentiated
# Values: folders | files | none
sort-priority = folders

# Navigation mode for selecting images/slots
# native:  Navigate through all valid images/dirs
# indexed: Navigate through DSKA0000, DSKA0001, ...
# default: native unless overridden by HxC-compat-mode config
nav-mode = default

# When navigating slots or folder, loop at min/max?
# Values: yes | no
nav-loop = yes

# Actions of first two buttons.
#              B1     | B2     | Both
# zero:        Prev   | Next   | Slot 0
# eject:       Prev   | Next   | Eject/Insert
# rotary:      Up-dir | Select/Eject/Insert | -
# rotary-fast: Prev   | Next   | Up-dir [Prev/Next are accelerated]
# reverse:     Reverse sense of B1 and B2
# Multiple values can be separated by commas, eg twobutton-action=eject,reverse
twobutton-action = zero

# Input sensor type at the rotary-encoder inputs (pins PC10 and PC11):
#  [full | half | quarter]:
#    Rotary encoder, identified by fraction of a Gray-code cycle performed
#    per detent/click. If default value ('full') requires multiple
#    clicks/detents to move position then change to 'half' (if 2 clicks
#    per move) or 'quarter' (if 4 clicks).
#  [trackball]:
#    Blackberry-style trackball (eg. using Hall-effect sensors).
#  [buttons]:
#    Push-to-ground Prev/Next buttons.
#  [reverse]:
#    If the input is working in reverse, use this option to swap directions.
# Multiple values can be separated by commas, eg rotary=quarter,reverse
# Values: none | quarter | half | full | trackball | buttons | reverse
rotary = full

# Prefix for image names in indexed navigation mode. String can be empty ("").
indexed-prefix = "DSKA"

##
## DISPLAY

# Display Type: <type>[-rotate][-narrow]
# auto: Auto-detect (7-seg LED, LCD, OLED)
# lcd-CCxRR: CCxRR backlit LCD with I2C backpack (16<=CC<=40, 02<=RR<=04)
# oled-128xNN: 128xNN I2C OLED (NN = 32 | 64)
#  -rotate:     OLED view is rotated 180 degrees
#  -narrow[er]: OLED view is restricted to Gotek display cutout
#               (-narrow: 18 chars; -narrower: 16 chars)
#  -ztech:      ZHONGJY_TECH 2.23" 128x32 SSD1305 OLED display
# Values: auto | lcd-CCxRR | oled-128xNN[-rotate][-narrow[er]][-ztech]
display-type = auto

# OLED Font. Narrow and wide options.
# Narrower 6x13 font permits:
#  - More characters per row
#  - Use of Gotek display cutout (eg. "display-type=oled-128x32-narrow")
# Values: 6x13 | 8x16
oled-font = 6x13

# OLED contrast/brightness.
# Values: 0 <= N <= 255
oled-contrast = 143

# Text height and arrangement on LCD/OLED
# 'default', or a comma-separated list (one entry per LCD/OLED row, top down).
# Each list item is a digit plus optional height specifier: <content-row>[d]
#  content-row: '0-3' = specified content row, '7' = blank
#    0: Current image name
#    1: Status
#    2: Image/Volume info
#    3: Current subfolder name
#  height specifier: 'd' = double height (32px, OLED only; ignored for LCD)
# 'default' depends on display, eg.: oled-128x32='0,1' ; oled-128x64='3,0d,1'
# Values: [0-7][d] | default
display-order = default

# Turn an LCD or OLED display off after N seconds of inactivity
# N=0: always off; N=255: always on
# Values: 0 <= N <= 255
display-off-secs = 60

# Switch on LCD/OLED display when there is drive activity?
# yes: Trigger on track changes and disk writes
# sel: Trigger on drive select
# no:  No automatic trigger
# Values: yes | sel | no
display-on-activity = yes

# LCD/OLED long filename scroll rate in milliseconds per update
# Values: 100 <= N <= 65535
display-scroll-rate = 200

# LCD/OLED pause time at start/end of scroll, in milliseconds
# Zero means endless scroll
# Values: 0 <= N <= 65535
display-scroll-pause = 2000

# LCD/OLED long filename scroll rate during navigation (ms per update)
# Values: 0 <= N <= 65535
nav-scroll-rate = 80

# LCD/OLED long filename pause before scroll, during navigation (milliseconds)
# Values: 0 <= N <= 65535
nav-scroll-pause = 300

##
## MISCELLANEOUS

# Speaker volume for head STEP
# Values: 0 <= N <= 20
step-volume = 10

# Report the specified version number to host software
# Values: <quoted-string> ("" means report real version)
# eg. da-report-version = "v3.0.0.0"
da-report-version = ""

# Automatically extend certain types of truncated image file (SSD,DSD,TRD)?
# Values: yes | no
extend-image = yes
ysblokje commented 4 years ago

The created logfile

** FlashFloppy v3.16 for Gotek
** Keir Fraser <keir.xen@gmail.com>
** https://github.com/keirf/FlashFloppy

Build: Aug 22 2020 14:26:14
Board: Standard
Config: Flash Slot 0 (ver 2, size 69)
Interface: QuickDisk, JC=On (Roland)
I2C: Invalid bus SCL=1 SDA=0
Display: 3-Digit LED

> USBH_USR_Init
> USBH_USR_ResetDevice
> USBH_USR_DeviceAttached
> USBH_USR_ResetDevice
> USBH_USR_DeviceSpeedDetected
> Device speed: Full
> USBH_USR_DeviceDescAvailable
 VID : 0951
 PID : 1666
> USBH_USR_DeviceAddressAssigned
> USBH_USR_ConfigurationDescAvailable
> Class connected: 08 (MSC)
 Manufacturer : Kingston
 Product : DataTraveler 3.0
 Serial Number : 0C9D92C19C3CE420791E0BF8
> USBH_USR_EnumerationDone
> USBH_USR_UserInput
Cache 105 items
0:F: 'Blank.qd' 
Cache 105 items
Mode: Native
Current slot: 0/0
Name: 'Blank' Type: qd
Attr: 20 Clus: 0000000c Size: 204800
Fast Seek: 1 frags
Cache 29 items
Write 22016-26111 (4096)... 10969 us
Write 26112-30207 (4096)... 10357 us
Write 27648-31743 (4096)... 9750 us
Write 16384-20479 (4096)... 10653 us
Write 20480-24575 (4096)... 10252 us
Write 16384-20479 (4096)... 12147 us
Write 20480-24575 (4096)... 10222 us
Write 22016-26111 (4096)... 10734 us
Write 26112-30207 (4096)... 10281 us
Write 27648-31743 (4096)... 9759 us
Write 16384-20479 (4096)... 10731 us
Write 20480-24575 (4096)... 10290 us
Write 16384-20479 (4096)... 10763 us
Write 20480-24575 (4096)... 10243 us
Write 22016-26111 (4096)... 10685 us
Write 26112-30207 (4096)... 10277 us
Write 27648-31743 (4096)... 9765 us
Write 16384-20479 (4096)... 12179 us
Write 20480-24575 (4096)... 10252 us
Write 16384-20479 (4096)... 10700 us
Write 20480-24575 (4096)... 10288 us
Write 22016-26111 (4096)... 10613 us
Write 26112-30207 (4096)... 10255 us
Write 27648-31743 (4096)... 9792 us
Write 16384-20479 (4096)... 10665 us
Write 20480-24575 (4096)... 10231 us
Write 16384-20479 (4096)... 10615 us
Write 20480-24575 (4096)... 10210 us
> USBH_USR_DeviceDisconnected
> USBH_USR_DeInit
> USBH_USR_ResetDevice
> USBH_USR_DeviceAttached
> USBH_USR_ResetDevice
> USBH_USR_DeviceSpeedDetected
> Device speed: Full
> USBH_USR_DeviceDescAvailable
 VID : 0951
 PID : 1666
> USBH_USR_DeviceAddressAssigned
> USBH_USR_ConfigurationDescAvailable
> Class connected: 08 (MSC)
 Manufacturer : Kingston
 Product : DataTraveler 3.0
 Serial Number : 0C9D92C19C3CE420791E0BF8
> USBH_USR_EnumerationDone
> USBH_USR_UserInput
Cache 105 items
0:F: 'disk1.qd' 
Cache 105 items
Mode: Native
Current slot: 0/1
Name: 'disk1' Type: qd
Attr: 20 Clus: 0000000c Size: 204800
Fast Seek: 1 frags
Cache 29 items
Cache 105 items
Before: After: Current slot: 1/1
Name: 'disk2' Type: qd
Attr: 20 Clus: 00000022 Size: 204800
keirf commented 4 years ago

Let me have a think. I may need to send new logging firmware to see what the write stream timing looks like.

keirf commented 4 years ago

Here is a new firmware to try which includes more write logging. So please gather another logfile. You can attach it, there's no need to paste it as text into the ticket.

ff_364_1.zip

keirf commented 4 years ago

You can also attach here the failed QD file after format attempt.

ysblokje commented 4 years ago

results.zip

Ok here are my blank.qd / fflog.txt and image_a.cfg . I removed everything else and started fresh with the usb drive empty. What I do notice is that the timestamp of the blank.qd hasn't changed after the things I did.

What I did was :

ysblokje commented 4 years ago

also here's an image that has only been formatted.

onlyformatted.zip

keirf commented 4 years ago

Hmm well actually the data written to the QD image looks okay I think. The log file you gathered weirdly has no write info in it at all.... Perhaps you didn't flush the FFLOG.TXT to stick after your format/write tests?

Anyway, putting that aside, what jumpers have you tried? You should have one at MO for sure. Have you tried with and without an additional jumper at JC as well?

EDIT: Of course double check your wiring too. It's obviously at least mostly okay. You can't yet confirm the Read Data line though, for example.

ysblokje commented 4 years ago

Oh... I see that I might have made a mistake with the logging. I will redo the things I did, but switch image before ejecting the usb stick. Also I cleaned all the pins today and did some more checks. I did jumper M0 and tried the JC too. With JC jumpered it seems to work better in detecting things.

format_proper_log.zip

ysblokje commented 4 years ago

Now I have tried to write something to the image from my previous post and got the unformatted error again. failure_writing_file.zip

same as before a 0x200 byte file called TST

keirf commented 4 years ago

Weird. Stuff has definitely got written to the QD image file. The extra logging tells me that the Sharp is using the usual QD bitrate. Maybe it's a timing thing in terms of spin-up time, or size of the 'valid data window', or something.

keirf commented 4 years ago

Here's a firmware with a new Blank QD image which shrinks the 'data window' to 5.5 sec which I think is more usual for many QD drives. It also shrinks the motor spin-up time to 1 sec (previously 2 secs). So we can see if that helps. No need for logs.

ff_364_2.zip

ysblokje commented 4 years ago

Alas, no change in behaviour.

There's is one thing else to consider too. This hardware is 30-35 years old at this point. There could be other issues at play.

I have no spare hardware to try this on either.

keirf commented 4 years ago

No other ideas at the moment. It can't be anything very complex at the quickdisk drive side of things as quickdisk is dumb as a box of rocks. The electronics is very very simple. That was the attraction!

keirf commented 4 years ago

I'm not sure whether to leave this open or not. I'll leave it for now.

ysblokje commented 4 years ago

I can tell you that I fixed the belt in my quickdrive and that will in fact read and write disks.

keirf commented 4 years ago

I'd really need to get my hands on the hardware, or have someone gather a logic analyser trace on the original quickdrive using something like https://www.ebay.co.uk/itm/254626862929 (plus probably logic probe clips to attach to interesting drive signal lines).

Perhaps the drive has a slightly different pin out. Perhaps one of the signals is inverted compared with usual. Must be something minor but significant like this I guess.

keirf commented 4 years ago

I found the MZ-1F11 service manual. https://original.sharpmz.org/mz-700/download/mz1f11_sm_supplement_gb.pdf (EDIT: See also https://original.sharpmz.org/download/1f11.pdf)

Section 4 (circuit diagram) indicates the usual 10-pin QD connections at connector T-4. Which makes it all the weirder that it doesn't work.

Perhaps we should do some more logging of control signals. RESET and MOTOR are particularly interesting. I will make you a new logging firmware.

keirf commented 4 years ago

With the previous firmware (ff_364_2) did you both update the firmware and use the included new blank QD image file?

Anyhow, here is another one to try, using the logfile firmware to gather a FFLOG.TXT file. This will log any time the RESET and MOTOR signals change. Which could be interesting.

ff_364_3.zip

ysblokje commented 4 years ago

I'd really need to get my hands on the hardware, or have someone gather a logic analyser trace on the original quickdrive using something like https://www.ebay.co.uk/itm/254626862929 (plus probably logic probe clips to attach to interesting drive signal lines).

There's something I want! I will get one of those. I've got plenty of breadboard and related materials to make this into a nice workable setup.

keirf commented 4 years ago

With ff_643_3 above could you start with a fresh Blank QD, no FFLOG.TXT. Then: format, and then do the small-file write, and gather FFLOG.TXT that results?

One thing I wonder is, FlashFloppy does not start reading again immediately after a write: Reads always restart from the very start, plus we wait for the QD to travel to the start position from where the write ended. Which can take several seconds. Possibly real QDs don't behave like this. Most systems seem to tolerate it but perhaps not the Sharp?

ysblokje commented 4 years ago

I got my little analyzer today, what I will try to do is record with a real drive and then with the new firmware loaded gotek attached to the controller. First I have to look up some tutorials on how to use these things though. So don't expect them before the end of the day ;)

keirf commented 4 years ago

The Saleae software is quite straightforward, fortunately. Sampling at a rate of say 2Msa/s (500ns resolution) should be good enough. You should be able to grab all signals as there's only eight of them.

ysblokje commented 4 years ago

So here are the first 2 files on real hardware.

realqd_captures.zip

ysblokje commented 4 years ago

And here are the captures of 364_1 and 364_3 with the FFlogs.

ffcaps_log.zip

keirf commented 4 years ago

Fascinating thank you. I think the most obvious difference is that the real QD drive the Read Data remains active most of the time, even during writes (although I'm not sure the Read Data actually looks well formed during a write). But certainly Read Data is active after a write, unlike on FlashFloppy. So probably that is something to fix.

ysblokje commented 4 years ago

What surprised me was that the "read" continued when the prompt was back. So I am not sure what is going on there. On the real hardware that is.

keirf commented 4 years ago

That's the Quick drive automatically running on to end of track. It's probably too dumb to do otherwise.

keirf commented 4 years ago

Okay here's a firmware which restarts reads immediately after end of a write. Let's see if it helps.

ff_364_4.zip

ysblokje commented 4 years ago

My first test seems to be successful! Very nice indeed!

keirf commented 4 years ago

If you see some more success I will send you one final tweaked firmware to try. You can then do a clean test with that, and the included Blank QD, and if that's all good I will put in master branch for inclusion in v3.17.

ysblokje commented 4 years ago

I have just been dumping program after program on the one Image. is there a theoretical maximum? (Not that I am complaining)

keirf commented 4 years ago

I would say 60kB of storage capacity, approximately.

Let me sort you a final firmware to test...

keirf commented 4 years ago

Here you go. Not much different that 364_4.zip so should work fine. This is basically the release candidate for this fix.

ff_364_5.zip

ysblokje commented 4 years ago

I loaded up your latest version. put a BASIC interpreter on a disk, wrote a small program, saved it, removed said program from memory and reloaded it from disk and ran it. This was all a success.