English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Asm / Hardware

 
 
Thread Tools
Old 16 February 2022, 02:47   #1
Muzza
Registered User
 
Muzza's Avatar
 
Join Date: Sep 2019
Location: Sydney
Posts: 357
Trackdisk, DSKRDY, WinUAE

Hi,

I've been using the trackdisk ASM code from the Solid Gold source code for a while, but I've been implementing swapping floppies and have ran into a problem.

Here is the loading process:
Disk in df0. Bootblock loads, game starts. Trackdisk code turns on the drive motor, loads everything for section 1 of the game, turns off the drive motor.
I press fire to skip section 1, Trackdisk code again turns on the drive motor, loads everything for section 2, turns off the drive motor.

This works fine normally, but in WinUAE v4.9.1, if I wait for section 1 to finish loading, then press F12 to bring up the menu, and exit the menu without making any changes, then the loading for section 2 will fail because the code ends up in an endless loop waiting for DSKRDY after trying to turn on the drive motor.

I discovered this because I was using F12 to insert a second disk into DF1, but then I've found the problem arises even if I do nothing in the F12 menu.


If I do Shift+F12 then type C, WinUAE shows that the drive motor is on "DEBUG: drive 0 motor on cylinder 53 sel yes ro mfmpos 62913/101344" but the program acts as though it did not receive the DSKRDY bit.


The Motor On routine looks like this:
Code:
; Wait for DSKRDY
    macro    WAIT_DSKRDY
.\@:    btst    #DSKRDY,(a2)
    bne    .\@
    endm


td_motoron:
; Turn the drive's motor on and wait until rotating at full speed.
; The drive stays selected.
; a2 = CIAAPRA
; a3 = CIABPRB

    tst.b    MotorOn
    bne    .1            ; already running

    bclr    #DSKMOTOR,(a3)
    nop
    moveq    #0,d0
    move.b    DriveSel,d0 ; <-- sets #DSKSEL0
    bclr    d0,(a3)
    WAIT_DSKRDY  ; <----- gets stuck here
    st    MotorOn

.1:    rts
On my real Amiga, I tried inserting a disk into DF1 to reproduce, but it doesn't happen. Although it does crash if I insert a disk into DF1 whilst it is still loading from DF0, so there are probably some issues with code robustness.

I tried a slightly different motor on routine that I got from the bare-metal Amiga programming book. Same thing though. That routine looks like this:
Code:
; a2 = CIAAPRA
; a3 = CIABPRB
    move.b        #$77,(a3)    ; clear DSKMOTOR + DSKSEL0 CIAB PRB
.again
    btst.b        #DSKTRACK0,(a2)    ; goes low when on position 0
    beq.b        .OnZero            ; reached position 0?
    bsr            DiskStep        ; move head one step (down)
    bra            .again            ; keep stepping until on position 0
.OnZero
.NotReady
    btst        #DSKRDY,(a2)    ; goes low when drive is ready
    bne            .NotReady
    st            MotorOn            ; mark motor as on
Elsewhere in the trackdisk code, I did notice something that looked wrong to me. Solid Gold has this:
Code:
td_step:
; Step a track into selected direction.
; a2 = CIAAPRA
; a3 = CIABPRB

    moveq    #STEPDELAY,d0
    bsr    td_delay
    bclr    #DSKSTEP,(a3)
    nop
    bset    #DSKSTEP,(a3)
    rts

td_delay:
; Wait for ca. count * 64us.
; d0.w = count
; a0 and a1 are reserved!

.1:    move.b    VHPOSR,d1
.2:    cmp.b    VHPOSR,d1
    beq    .2
    subq.w    #1,d0
    bne    .1
    rts
But should it not be this?
Code:
td_step:
; Step a track into selected direction.
; a2 = CIAAPRA
; a3 = CIABPRB
    bclr    #DSKSTEP,(a3)
    nop
    moveq    #STEPDELAY,d0
    bsr        td_delay
    bset    #DSKSTEP,(a3)
    rts
I'm a bit lost now, so any thoughts or hint would be appreciated, thanks.
Muzza is offline  
Old 16 February 2022, 04:50   #2
Muzza
Registered User
 
Muzza's Avatar
 
Join Date: Sep 2019
Location: Sydney
Posts: 357
Hmm, I've just found that whilst it is in an endless loop waiting for DSKRDY, you can press F12, eject DF0, resume the game, F12, re-insert DF0, resume game, and the DSKRDY signal is sent and the game loads.
Muzza is offline  
Old 16 February 2022, 04:58   #3
Muzza
Registered User
 
Muzza's Avatar
 
Join Date: Sep 2019
Location: Sydney
Posts: 357
Another question - as I mentioned above, I also experience corruption if I insert a disk in DF1 whilst loading from DF0 (but it works if I insert DF1 when not currently loading). This appears to happen on both WinUAE and my real hardware. The TrackRead routine throws up sector errors and then disk DMA errors. What exactly happens in the system when a disk is inserted? Is there something I'm supposed to catch and handle? Is some state invalidated somewhere? This is after a system-takeover obviously.

Last edited by Muzza; 16 February 2022 at 05:24.
Muzza is offline  
Old 16 February 2022, 08:57   #4
a/b
Registered User
 
Join Date: Jun 2016
Location: europe
Posts: 1,039
Quote:
Originally Posted by Muzza View Post
But should it not be this?
You can see it as wait on previous step to finish, because you have to wait longer when you are done moving the heads (settle time 18ms vs. step 3ms).
a/b is offline  
Old 16 February 2022, 09:35   #5
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,473
I add that the movement of the head is activated when a quick pulse is received on DSKSTEP (of at least 1 us, i.e. a clr and immediate set of the bit, thanks to CIA E clock).
Your code does nothing but create a very long pulse and no wait for a initial settle or step timing.
ross is offline  
Old 16 February 2022, 10:00   #6
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 3,230
Note that DSKRDY is not supported on all drives anyhow, so the above code is not robust by any means. What the Os trackdisk.device does is that the wait on DSKRDY times out after some 100 ms. The motor stepping also seems to be off, the code should guarantee a minimal pulse width.
Thomas Richter is offline  
Old 16 February 2022, 10:07   #7
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,473
Quote:
Originally Posted by Muzza View Post
Another question - as I mentioned above, I also experience corruption if I insert a disk in DF1 whilst loading from DF0 (but it works if I insert DF1 when not currently loading). This appears to happen on both WinUAE and my real hardware. The TrackRead routine throws up sector errors and then disk DMA errors. What exactly happens in the system when a disk is inserted? Is there something I'm supposed to catch and handle? Is some state invalidated somewhere? This is after a system-takeover obviously.
Maybe both motor are on during the DMA reading?
ross is offline  
Old 16 February 2022, 13:47   #8
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,498
The Solid Gold trackdisk code certainly has a few bugs, which were fixed in later games. You find the last version of it in the Trap Runner "Black Strawberry Cake" code: https://server.owl.de/~frank/BlkStberries.lha

Indeed, support for drives without /RDY signal was missing in Solid Gold. I fixed that in a 2017 patch for Solid Gold V1.3:
Code:
frank@nerthus cvs diff -u -r1.2 -r1.3 trackdisk.asm
Index: trackdisk.asm
===================================================================
RCS file: /usr/src/cvs/SolidGold/trackdisk.asm,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- trackdisk.asm       27 Dec 2013 17:46:01 -0000      1.2
+++ trackdisk.asm       5 Nov 2017 10:06:36 -0000       1.3
@@ -3,7 +3,7 @@
 * Define TDWRITE to include support for writing blocks (reading them first).
 * Define TDFORMAT to include support for writing/formatting whole tracks.
 *
-* Written by Frank Wille in 2013.
+* Written by Frank Wille in 2013, 2017.
 *
 * I, the copyright holder of this work, hereby release it into the
 * public domain. This applies worldwide.
@@ -60,12 +60,6 @@
 WRITESUPPORT   set     1
                endif

-; Wait for DSKRDY
-       macro   WAIT_DSKRDY
-.\@:   btst    #DSKRDY,(a2)
-       bne     .\@
-       endm
-

 ; from memory.asm
        xref    alloc_chipmem
@@ -641,14 +635,12 @@
        movem.l d2-d3/a2,-(sp)
        move.l  MFMbuffer(a4),a0
        addq.l  #2,a0                   ; make room to restore missed SYNC
+       move.w  #$4000,DSKLEN(a6)

        ;-----------------------------------------------------
        ; Disk read DMA fetches a whole track into the buffer
        ;-----------------------------------------------------

-       WAIT_DSKRDY
-       move.w  #$4000,DSKLEN(a6)
-
        ; select MFM encoding and enable synchronization word (DSKSYNC)
        move.w  #$7200,ADKCON(a6)
        move.w  #$8500,ADKCON(a6)
@@ -995,7 +987,6 @@
        btst    #DSKPROT,(a2)
        beq     .err_wprot

-       WAIT_DSKRDY
        move.w  #$4000,DSKLEN(a6)

        ; set MFM precompensation, disable WORDSYNC
@@ -1187,7 +1178,7 @@
 ; a3 = CIABPRB

        tst.b   MotorOn(a4)
-       bne     .1                      ; already running
+       bne     .2                      ; already running

        bclr    #DSKMOTOR,(a3)
        nop
@@ -1195,10 +1186,20 @@
        move.b  DriveSel(a4),d0
        bclr    d0,(a3)

-       WAIT_DSKRDY
+       move.l  d2,a0
+
+       moveq   #100-1,d2               ; timeout after ~500ms
+.1:    moveq   #78,d0
+       bsr     td_delay                ; ~5ms
+       btst    #DSKRDY,(a2)
+       dbeq    d2,.1
+
+       ; Pretend the motor is running after 500ms, even when /RDY never
+       ; became low. Might be a PC-drive or an Amiga Technologies drive.
        st      MotorOn(a4)
+       move.l  a0,d2

-.1:    rts
+.2:    rts


 ;---------------------------------------------------------------------------
Quote:
Originally Posted by Thomas Richter View Post
The motor stepping also seems to be off, the code should guarantee a minimal pulse width.
Should be ok, as accessing CIA registers guarantees the minimal delay.

Quote:
Originally Posted by ross View Post
Maybe both motor are on during the DMA reading?
I don't really remember, but I may have fixed something there. The last version of trackdisk.asm (from Black Strawberries) shows a new
motor_off_all
routine, which is called when selecting a new drive.
phx is offline  
Old 16 February 2022, 17:04   #9
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,514
Quote:
Originally Posted by Muzza View Post
This works fine normally, but in WinUAE v4.9.1, if I wait for section 1 to finish loading, then press F12 to bring up the menu, and exit the menu without making any changes
Did it start in 4.9.1 or some older version? I can't see anything obvious where GUI would affect disk state.
Toni Wilen is offline  
Old 16 February 2022, 22:30   #10
Muzza
Registered User
 
Muzza's Avatar
 
Join Date: Sep 2019
Location: Sydney
Posts: 357
Thanks for the replies, I'm looking into it more today.

Quote:
Originally Posted by phx View Post
The Solid Gold trackdisk code certainly has a few bugs, which were fixed in later games. You find the last version of it in the Trap Runner "Black Strawberry Cake" code: https://server.owl.de/~frank/BlkStberries.lha
This could be very useful, thanks. I should add a thanks for releasing the Solid Gold source code as it was an invaluable reference when I first started 68k/Amiga programming.

Quote:
Originally Posted by Toni Wilen View Post
Did it start in 4.9.1 or some older version? I can't see anything obvious where GUI would affect disk state.
I'd noticed it in older versions too, pre 4.9, but hadn't spent the time to track what exactly was happening.
Muzza is offline  
Old 16 February 2022, 23:35   #11
Muzza
Registered User
 
Muzza's Avatar
 
Join Date: Sep 2019
Location: Sydney
Posts: 357
I've found that if I run WinUAE, and set up my config/floppy drive through the GUI, then run my game, I do not experience the floppy drive bug.

It only occurs if I launch WinUAE via the command line. I enabled disk logging with 'did 2' after the game loading was complete and the drive motor turned off. Shift+F12 and type C. I get:
Code:
DEBUG: drive 0 motor off cylinder 53 sel no rw mfmpos 42019/101344
DEBUG: drive 1 motor off cylinder  0 sel no ro mfmpos 32/101344
Then I resume the game with g, press F12 to bring up the GUI. The disk logging immediately outputs:
Code:
amigados read track 107
amigados read track 81
amigados read track 107
Close the GUI, Shift+F12, type C, and this time I get:
Code:
DEBUG: drive 0 motor off cylinder 53 sel no ro mfmpos 5496/101344
DEBUG: drive 1 motor off cylinder  0 sel no ro mfmpos 32/101344
The mfmpos has changed, and the log about amigados reading tracks seems odd? I'm assuming here that WinUAE is examining the floppy when the GUI first pops up. Could this be modifying its state?


The command line I'm running is:
Code:
winuae.exe -s floppy0=xxx.adf -s floppy0sound=1 -s floppy1sound=1 -s joyport0=mouse -s joyport1=joy0 -s warp=true -s blitter_cycle_exact=true -s cpu_cycle_exact=true -s cpu_memory_cycle_exact=true -s chipset=aga -r "xxx.rom" -c 4 -b 0 -F 2 -log -serlog -s cpu_model=68020 -s cpu_multiplier=4
(I've tried with WARP on and off by the way)

EDIT: My crash on inserting DF1 during loading of DF0 also goes away if I start WinUAE from the GUI instead of command line.

Last edited by Muzza; 17 February 2022 at 00:19.
Muzza is offline  
Old 17 February 2022, 19:47   #12
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,514
Quote:
Originally Posted by Muzza View Post
The command line I'm running is:
Does it happen if you only have "-s floppy0=xxx.adf" in command line? Or does it require some other parameters too?
Toni Wilen is offline  
Old 17 February 2022, 22:44   #13
Muzza
Registered User
 
Muzza's Avatar
 
Join Date: Sep 2019
Location: Sydney
Posts: 357
Quote:
Originally Posted by Toni Wilen View Post
Does it happen if you only have "-s floppy0=xxx.adf" in command line? Or does it require some other parameters too?

Yes it still happens with only -s floppy0
If I add -log, I see the amigados read track messages still when pressing F12.
If I don't add -log, I don't see the messages but subsequent disk loading still fails after the F12 menu.
Muzza is offline  
Old 17 February 2022, 22:48   #14
Muzza
Registered User
 
Muzza's Avatar
 
Join Date: Sep 2019
Location: Sydney
Posts: 357
I've got around the problem by clicking on the Floppy numbers in the status bar of WinUAE when I need to change disk. This brings up a file selector, lets me change disk and doesn't cause any problems.
If I try to change disk using the F12 menu, that is when the problem occurs.
Muzza is offline  
Old 18 February 2022, 12:41   #15
paraj
Registered User
 
paraj's Avatar
 
Join Date: Feb 2017
Location: Denmark
Posts: 1,104
I think it requires quickstart to be enabled (or maybe just that part of the config dialog to be present). Only seems to happen the very first the config dialog is brought up? (Started WinUAE with "-log -s floppy0=c:\temp\test.adf -G" and I have it configured to start on the Quickstart page).

Callstack:
Code:
winuae.exe!drive_insert(drive * drv, uae_prefs * p, int dnum, const wchar_t * fname_in, bool fake, bool forcedwriteprotect) Line 1691	C++
winuae.exe!DISK_examine_image(uae_prefs * p, int num, diskinfo * di, bool deepcheck, wchar_t * infotext) Line 5320	C++
winuae.exe!testimage(HWND__ * hDlg, int num) Line 7323	C++
winuae.exe!QuickstartDlgProc(HWND__ * hDlg, unsigned int msg, unsigned int wParam, long lParam) Line 7756	C++
[...]
user32.dll!_SendMessageW@16()	Unknown
winuae.exe!DIALOG_CreateIndirect(HINSTANCE__ * hInst, const void * dlgTemplate, HWND__ * owner, int(__stdcall*)(HWND__ *, unsigned int, unsigned int, long) dlgProc, long param, HWND__ * * modal_owner, newresource * res) Line 725	C++
winuae.exe!x_CreateDialogIndirectParam(HINSTANCE__ * hInstance, const DLGTEMPLATE * lpTemplate, HWND__ * hWndParent, int(__stdcall*)(HWND__ *, unsigned int, unsigned int, long) lpDialogFunc, long lParamInit, newresource * res) Line 748	C++
winuae.exe!updatePanel(int id, unsigned int action) Line 21229	C++
winuae.exe!DialogProc(HWND__ * hDlg, unsigned int msg, unsigned int wParam, long lParam) Line 21956	C++
[...]
user32.dll!__InternalCallWinProc@20()	Unknown
user32.dll!_SendMessageW@16()	Unknown
winuae.exe!createcontrols(HWND__ * hwnd, newresource * res) Line 460	C++
winuae.exe!DIALOG_CreateIndirect(HINSTANCE__ * hInst, const void * dlgTemplate, HWND__ * owner, int(__stdcall*)(HWND__ *, unsigned int, unsigned int, long) dlgProc, long param, HWND__ * * modal_owner, newresource * res) Line 728	C++
winuae.exe!x_CreateDialogIndirectParam(HINSTANCE__ * hInstance, const DLGTEMPLATE * lpTemplate, HWND__ * hWndParent, int(__stdcall*)(HWND__ *, unsigned int, unsigned int, long) lpDialogFunc, long lParamInit, newresource * res) Line 748	C++
winuae.exe!GetSettings(int all_options, HWND__ * hwnd) Line 22430	C++
winuae.exe!gui_display(int shortcut) Line 2364	C++
winuae.exe!inputdevice_handle_inputcode2(int monid, int code, int state, const wchar_t * s) Line 4335	C++
winuae.exe!inputdevice_handle_inputcode() Line 4681	C++
winuae.exe!inputdevice_vsync() Line 5220	C++
winuae.exe!devices_vsync_pre() Line 233	C++
winuae.exe!hsync_handler() Line 11710	C++
winuae.exe!do_cycles_slow(unsigned int cycles_to_add) Line 290	C++
winuae.exe!do_specialties(int cycles) Line 4523	C++
winuae.exe!m68k_run_jit() Line 5345	C++
winuae.exe!m68k_go(int may_quit) Line 6446	C++
winuae.exe!do_start_program() Line 1052	C++
winuae.exe!start_program() Line 1068	C++
winuae.exe!real_main2(int argc, wchar_t * * argv) Line 1208	C++
winuae.exe!real_main(int argc, wchar_t * * argv) Line 1222	C++
winuae.exe!WinMain2(HINSTANCE__ * hInstance, HINSTANCE__ * hPrevInstance, wchar_t * lpCmdLine, int nCmdShow) Line 7182	C++
winuae.exe!wWinMain(HINSTANCE__ * hInstance, HINSTANCE__ * hPrevInstance, wchar_t * lpCmdLine, int nCmdShow) Line 8071	C++
paraj is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Recently changed WinUAE folder, now getting Arabuusimiehet.WinUAE error Foebane support.WinUAE 9 09 September 2016 20:03
trackdisk.device + slow ram - not friendly with one another? MethodGit Coders. General 3 27 March 2016 16:40
trackdisk.device after system takeover alpine9000 Coders. Asm / Hardware 20 21 March 2016 09:17
PC-size floppy disk image loads as trackdisk format mark_k support.WinUAE 1 02 January 2015 20:06
Trackdisk and Diskspare exoticaga support.Other 11 09 April 2009 20:27

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 17:07.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.10316 seconds with 15 queries