Advertisement
Cremulus

Basil's floppy Z80 coprocessor (modified)

Aug 25th, 2023
1,499
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.                         ORG #15B0                       ; Put this after the previous version in the EPROM, to save an erase
  2.  
  3.                         zeusemulate "CPM"               ; Just a vanilla Z80 model with RAM at zero
  4.  
  5. ; The ParaSys PIO ports
  6. ParaAD                  equ %0 xxxxx 0 0                ;
  7. ParaBD                  equ %0 xxxxx 0 1                ;
  8. ParaAK                  equ %0 xxxxx 1 0                ;
  9. ParaBK                  equ %0 xxxxx 1 1                ;
  10.  
  11. ; The WD1772 ports
  12. FDCstatus               EQU #C0                         ;
  13. FDCcomm                 EQU #C0                         ;
  14. ;
  15. FDCtrack                EQU #C1                         ;
  16. ;
  17. FDCsector               EQU #C2                         ;
  18. ;
  19. FDCdata                 EQU #C3                         ;
  20. ;
  21. FDCdrive                EQU #C4                         ;
  22. ;
  23. FDCflags                EQU #C4                         ;
  24. ;
  25. cRestore                EQU %0000 0000                  ;
  26. cSeek                   EQU %0001 0000                  ;
  27. cStepIn                 EQU %0101 0000                  ;
  28. cStepOut                EQU %0111 0000                  ;
  29. cReadSec                EQU %1000 1000                  ;
  30. cWriteSec               EQU %1010 1010                  ;
  31. cReadAddr               EQU %1100 0000                  ;
  32. cReadTrack              EQU %1110 0000                  ;
  33. cWriteTrack             EQU %1111 0010                  ;
  34. ;
  35. bPrecomp                EQU 1                           ;
  36. ;
  37. errUW                   EQU #20                         ;
  38. errUC                   EQU #21                         ;
  39. errIDN                  EQU #12                         ;
  40. errIT                   EQU #23                         ;
  41. ;
  42. MotDel                  EQU 25000                       ;
  43. ;
  44. dSelOr                  EQU 0                           ;
  45. dSelAnd                 EQU 1                           ;
  46.                         ;
  47. dcStepRate              EQU 2                           ;
  48.                         ;
  49. dcTrack                 EQU 3                           ;
  50.                         ;
  51. dPrecomp                EQU 4                           ;
  52. ;
  53. iPhase                  EQU WindowA + 0                 ;
  54. iCommand                EQU WindowA + 1                 ;
  55. iDrive                  EQU WindowA + 2                 ;
  56. iTrack                  EQU WindowA + 3                 ;
  57. iWind                   EQU WindowA + 4                 ;
  58. iError                  EQU WindowA + 5                 ;
  59. iSector                 EQU WindowA + 6                 ;
  60. ;
  61. nCommands               EQU 16                          ;
  62. ;
  63. WindowA                 EQU #C000                       ;
  64. WindowB                 EQU #D000                       ;
  65. WindowC                 EQU #E000                       ;
  66. WindowD                 EQU #F000                       ;
  67.  
  68. ; ParaSys Interface stuff
  69. bmPara_SS               equ %0000 0 0 0 1               ;
  70. bmPara_MS               equ %0000 0 0 1 0               ;
  71. bmPara_RESET            equ %0000 0 1 0 0               ;
  72. bmPara_EXTRA            equ %0000 1 0 0 0               ;
  73.  
  74. ; ParaSys file commands
  75. PS8_ReadFileBlock       equ $10                         ;
  76. PS8_WriteFileBlock      equ $11                         ;
  77. PS8_SendFilename        equ $12                         ;
  78.  
  79. YeStart                 JR Start                        ;
  80.                         ;
  81.                         DEFS 3,#FF                      ;
  82.                         ;
  83. Start                   LD SP,#C000                     ;
  84.                         DI                              ;
  85.                         ;
  86.                         XOR A                           ;
  87.                         LD I,A                          ;
  88.                         ;
  89.                         CALL InitDrives                 ;
  90.                         ;
  91.                         CALL InitPort                   ;
  92.                         ;
  93.                         CALL ClearStatus                ;
  94.                         ;
  95.                         call Ext_InitParaPort           ; Setup ParaSys
  96.  
  97. Loop                    mPS_SetStrobeDirns()            ; Make sure the port pins are driven correctly
  98.                         mPS_RESET_H()                   ; Take the reset line high
  99.                         mPS_MS_H()                      ; And make sure the master strobe is high
  100.                         mPS_Extra_L()                   ; Take the EXTRA data line low again
  101.  
  102. LoopFastWait            LD A,(iPhase)                   ;
  103.                         CP #02                          ;
  104.                         JR NZ LoopFastWait              ;
  105.                         ;
  106.                         CALL Execute                    ;
  107.                         ;
  108.                         JR NC Loop1                     ;
  109.                         ;
  110.                         LD (iError),A                   ;
  111.                         ;
  112. Loop1                   LD HL,iPhase                    ;
  113.                         LD (HL),3                       ;
  114.                         ;
  115.                         JR Loop                         ;
  116. ;
  117. Execute                 XOR A                           ;
  118.                         LD (iError),A                   ;
  119.                         ;
  120.                         LD A,(iCommand)                 ;
  121.                         LD B,A                          ;
  122.                         CP nCommands                    ;
  123.                         CCF                             ;
  124.                         LD A,errUC                      ;
  125.                         RET C                           ;
  126.                         ;
  127.                         LD A,B                          ;
  128.                         ADD A,A                         ;
  129.                         LD L,A                          ;
  130.                         LD H,0                          ;
  131.                         ;
  132.                         LD DE,JumpTable                 ;
  133.                         ADD HL,DE                       ;
  134.                         ;
  135.                         LD A,(HL)                       ;
  136.                         INC HL                          ;
  137.                         LD H,(HL)                       ;
  138.                         LD L,A                          ;
  139.                         ;
  140. CallHL                  JP (HL)                         ;
  141. ;
  142. CallIY                  JP (IY)                         ;
  143. ;
  144. JumpTable               DEFW TrackRead                  ;
  145.                         DEFW TrackWrite                 ;
  146.                         ;
  147.                         DEFW ShortRead                  ;
  148.                         DEFW ShortWrite                 ;
  149.                         ;
  150.                         DEFW FormatTrack                ;
  151.                         DEFW FormatDisc                 ;
  152.                         ;
  153.                         DEFW EntireRead                 ;
  154.                         DEFW EntireWrite                ;
  155.                         ;
  156.                         DEFW SectRead                   ;
  157.                         DEFW SectWrite                  ;
  158.                         ;
  159.                         DEFW WindowB                    ;
  160.                         DEFW WindowC                    ;
  161.                         DEFW WindowD                    ;
  162.  
  163.                         dw Ext_SendFilename             ;
  164.                         dw Reset                        ;
  165.  
  166.                         DEFW 0                          ;
  167.  
  168. Reset                   di                              ;
  169.                         jp 0                            ;
  170.  
  171. ClearStatus             LD HL,#C000                     ;
  172.                         LD DE,#C001                     ;
  173.                         LD BC,#FF                       ;
  174.                         LD (HL),0                       ;
  175.                         LDIR                            ;
  176.                         RET                             ;
  177. ;
  178. CalcWind                LD A,(iWind)                    ;
  179.                         LD HL,#D000                     ;
  180.                         OR A                            ;
  181.                         RET Z                           ;
  182.                         ;
  183.                         LD HL,#E000                     ;
  184.                         DEC A                           ;
  185.                         RET Z                           ;
  186.                         ;
  187.                         LD HL,#F000                     ;
  188.                         DEC A                           ;
  189.                         RET Z                           ;
  190.                         ;
  191.                         SCF                             ;
  192.                         LD A,errUW                      ;
  193.                         RET                             ;
  194. ;
  195. GetTrack                LD A,(iDrive)                   ;
  196.                         LD B,A                          ;
  197.                         CP 4                            ;
  198.                         CCF                             ;
  199.                         LD A,errIDN                     ;
  200.                         RET C                           ;
  201.                         ;
  202.                         LD A,B                          ;
  203.                         OR A                            ;
  204.                         CALL Z SelectA                  ;
  205.                         DEC A                           ;
  206.                         CALL Z SelectB                  ;
  207.                         DEC A                           ;
  208.                         CALL Z SelectC                  ;
  209.                         DEC A                           ;
  210.                         CALL Z SelectD                  ;
  211.                         ;
  212.                         CALL StartMotor                 ;
  213.                         ;
  214.                         LD A,(iTrack)                   ;
  215.                         CALL Seek                       ;
  216.                         RET                             ;
  217. ;
  218. TrackRead               ld a,(iDrive)                   ; Is this D0?
  219.                         or a                            ;
  220.                         jp nz Ext_TrackRead             ; No, try the external
  221.  
  222.                         CALL GetTrack                   ;
  223.                         RET C                           ;
  224.                         ;
  225.                         CALL CalcWind                   ;
  226.                         RET C                           ;
  227.                         ;
  228.                         CALL Read4K                     ;
  229.                         ;
  230.                         RET                             ;
  231. ;
  232. TrackWrite              ld a,(iDrive)                   ; Is this D0?
  233.                         or a                            ;
  234.                         jp nz Ext_TrackWrite            ; No, try the external
  235.  
  236.                         CALL GetTrack                   ;
  237.                         RET C                           ;
  238.                         ;
  239.                         CALL CalcWind                   ;
  240.                         RET C                           ;
  241.                         ;
  242.                         CALL Write4K                    ;
  243.                         ;
  244.                         RET                             ;
  245. ;
  246. ShortRead               CALL GetTrack                   ;
  247.                         RET C                           ;
  248.                         ;
  249.                         CALL CalcWind                   ;
  250.                         RET C                           ;
  251.                         ;
  252.                         JP ReadShort                    ;
  253. ;
  254. SectRead                CALL GetTrack                   ;
  255.                         RET C                           ;
  256.                         ;
  257.                         CALL CalcWind                   ;
  258.                         RET C                           ;
  259.                         ;
  260.                         JP SectorRead                   ;
  261. ;
  262. ShortWrite              CALL GetTrack                   ;
  263.                         RET C                           ;
  264.                         ;
  265.                         CALL CalcWind                   ;
  266.                         RET C                           ;
  267.                         ;
  268.                         JP WriteShort                   ;
  269. ;
  270. SectWrite               CALL GetTrack                   ;
  271.                         RET C                           ;
  272.                         ;
  273.                         CALL CalcWind                   ;
  274.                         RET C                           ;
  275.                         ;
  276.                         JP SectorWrite                  ;
  277. ;
  278. EntireRead              CALL GetTrack                   ;
  279.                         RET C                           ;
  280.                         ;
  281.                         CALL CalcWind                   ;
  282.                         RET C                           ;
  283.                         ;
  284.                         JP ReadTrack                    ;
  285. ;
  286. EntireWrite             CALL GetTrack                   ;
  287.                         RET C                           ;
  288.                         ;
  289.                         CALL CalcWind                   ;
  290.                         RET C                           ;
  291.                         ;
  292.                         JP WriteTrack                   ;
  293. ;
  294. FormatTrack             CALL GetTrack                   ;
  295.                         RET C                           ;
  296.                         ;
  297.                         LD A,(iTrack)                   ;
  298.                         LD B,A                          ;
  299.                         ;
  300.                         RLCA                            ;
  301.                         AND #01                         ;
  302.                         LD E,A                          ;
  303.                         ;
  304.                         LD A,B                          ;
  305.                         AND #7F                         ;
  306.                         LD D,A                          ;
  307.                         ;
  308.                         LD IX,FormatWS                  ;
  309.                         CALL FormatData                 ;
  310.                         RET C                           ;
  311.                         ;
  312.                         LD HL,FormatWS                  ;
  313.                         JP WriteTrack                   ;
  314. ;
  315. FormatDisc              LD A,0                          ;
  316.                         LD (iTrack),A                   ;
  317.                         ;
  318. FormatDisc1             CALL FormatTrack                ;
  319.                         RET C                           ;
  320.                         ;
  321.                         LD A,(iTrack)                   ;
  322.                         RLCA                            ;
  323.                         INC A                           ;
  324.                         CP 160                          ;
  325.                         JR Z FDexit                     ;
  326.                         RRCA                            ;
  327.                         LD (iTrack),A                   ;
  328.                         ;
  329.                         JR FormatDisc1                  ;
  330. ;
  331. FDexit                  OR A                            ;
  332.                         RET                             ;
  333. ;
  334. FormatData              PUSH IX                         ;
  335.                         PUSH BC                         ;
  336.                         PUSH AF                         ;
  337.                         ;
  338.                         LD HL,TrackDefnA                ;
  339.                         LD C,1                          ;
  340.                         ;
  341.                         CALL GenDataStr                 ;
  342.                         ;
  343. FDlp                    LD HL,TrackDefnB                ;
  344.                         CALL GenDataStr                 ;
  345.                         ;
  346.                         LD A,C                          ;
  347.                         CP 6                            ;
  348.                         JR NZ FDlp                      ;
  349.                         ;
  350.                         POP AF                          ;
  351.                         POP BC                          ;
  352.                         POP IX                          ;
  353.                         RET                             ;
  354. ;
  355. GenDataStr              LD A,(HL)                       ;
  356.                         INC A                           ;
  357.                         RET Z                           ;
  358.                         ;
  359.                         DEC A                           ;
  360.                         LD B,A                          ;
  361.                         INC HL                          ;
  362.                         LD A,(HL)                       ;
  363.                         ;
  364.                         CP #F3                          ;
  365.                         JR NC GDS1                      ;
  366.                         ;
  367.                         CP #F0                          ;
  368.                         JR C GDS1                       ;
  369.                         ;
  370.                         LD A,D                          ;
  371.                         JR Z GDS1                       ;
  372.                         ;
  373.                         LD A,(HL)                       ;
  374.                         CP #F1                          ;
  375.                         ;
  376.                         LD A,E                          ;
  377.                         JR Z GDS1                       ;
  378.                         ;
  379.                         LD A,C                          ;
  380.                         INC C                           ;
  381.                         ;
  382. GDS1                    INC HL                          ;
  383.                         ;
  384. GDSlp                   LD (IX),A                       ;
  385.                         INC IX                          ;
  386.                         DJNZ GDSlp                      ;
  387.                         ;
  388.                         JR GenDataStr                   ;
  389. ;
  390. ReadShortI              LD A,1                          ;
  391.                         JP ReadSec                      ;
  392. ;
  393. SectorReadI             LD A,(iSector)                  ;
  394.                         JP ReadSec                      ;
  395. ;
  396. Read4KI                 LD A,2                          ;
  397.                         CALL ReadSec                    ;
  398.                         RET C                           ;
  399.                         ;
  400.                         LD A,3                          ;
  401.                         CALL ReadSec                    ;
  402.                         RET C                           ;
  403.                         ;
  404.                         LD A,4                          ;
  405.                         CALL ReadSec                    ;
  406.                         RET C                           ;
  407.                         ;
  408.                         LD A,5                          ;
  409.                         CALL ReadSec                    ;
  410.                         RET                             ;
  411. ;
  412. WriteShortI             LD A,1                          ;
  413.                         CALL WriteSec                   ;
  414.                         RET C                           ;
  415.                         ;
  416. VeriShortI              LD A,1                          ;
  417.                         JP VeriSec                      ;
  418. ;
  419. SectorWriteI            LD A,(iSector)                  ;
  420.                         CALL WriteSec                   ;
  421.                         RET C                           ;
  422.                         ;
  423. SectorVeriI             LD A,(iSector)                  ;
  424.                         JP VeriSec                      ;
  425. ;
  426. Write4KI                LD A,2                          ;
  427.                         CALL WriteSec                   ;
  428.                         RET C                           ;
  429.                         ;
  430.                         LD A,3                          ;
  431.                         CALL WriteSec                   ;
  432.                         RET C                           ;
  433.                         ;
  434.                         LD A,4                          ;
  435.                         CALL WriteSec                   ;
  436.                         RET C                           ;
  437.                         ;
  438.                         LD A,5                          ;
  439.                         CALL WriteSec                   ;
  440.                         RET C                           ;
  441.                         ;
  442. Veri4KI                 LD A,2                          ;
  443.                         CALL VeriSec                    ;
  444.                         RET C                           ;
  445.                         ;
  446.                         LD A,3                          ;
  447.                         CALL VeriSec                    ;
  448.                         RET C                           ;
  449.                         ;
  450.                         LD A,4                          ;
  451.                         CALL VeriSec                    ;
  452.                         RET C                           ;
  453.                         ;
  454.                         LD A,5                          ;
  455.                         CALL VeriSec                    ;
  456.                         ;
  457.                         RET                             ;
  458. ;
  459. WriteTrackI             CALL PauseTR                    ;
  460.                         ;
  461.                         LD A,cWriteTrack                ;
  462.                         ;
  463.                         CALL DoPrecomp                  ;
  464.                         ;
  465.                         OUT (FDCcomm),A                 ;
  466.                         ;
  467.                         CALL WriteData                  ;
  468.                         ;
  469.                         IN A,(FDCstatus)                ;
  470.                         AND #44                         ;
  471.                         SCF                             ;
  472.                         RET NZ                          ;
  473.                         ;
  474.                         CALL VeriShortI                 ;
  475.                         RET C                           ;
  476.                         ;
  477.                         CALL Veri4KI                    ;
  478.                         ;
  479.                         RET                             ;
  480. ;
  481. ReadTrackI              CALL PauseTR                    ;
  482.                         ;
  483.                         LD A,cReadTrack                 ;
  484.                         ;
  485.                         CALL DoPrecomp                  ;
  486.                         ;
  487.                         OUT (FDCcomm),A                 ;
  488.                         ;
  489.                         CALL ReadData                   ;
  490.                         ;
  491.                         IN A,(FDCstatus)                ;
  492.                         AND #14                         ;
  493.                         SCF                             ;
  494.                         RET NZ                          ;
  495.                         ;
  496.                         OR A                            ;
  497.                         RET                             ;
  498. ;
  499. ReadShort               LD IY,ReadShortI                ;
  500.                         JR Repeat                       ;
  501. ;
  502. Read4K                  LD IY,Read4KI                   ;
  503.                         JR Repeat                       ;
  504. ;
  505. SectorRead              LD IY,SectorReadI               ;
  506.                         JR Repeat                       ;
  507. ;
  508. WriteShort              LD IY,WriteShortI               ;
  509.                         JR Repeat                       ;
  510. ;
  511. Write4K                 LD IY,Write4KI                  ;
  512.                         JR Repeat                       ;
  513. ;
  514. SectorWrite             LD IY,SectorWriteI              ;
  515.                         JR Repeat                       ;
  516. ;
  517. WriteTrack              LD IY,WriteTrackI               ;
  518.                         JR Repeat                       ;
  519. ;
  520. ReadTrack               LD IY,ReadTrackI                ;
  521.                         JR Repeat                       ;
  522. ;
  523. Repeat                  LD (DataTemp),HL                ;
  524.                         LD B,4                          ;
  525.                         ;
  526. rRTlp                   LD HL,(DataTemp)                ;
  527.                         CALL CallIY                     ;
  528.                         RET NC                          ;
  529.                         ;
  530.                         DJNZ rRTlp                      ;
  531.                         ;
  532.                         RET                             ;
  533. ;
  534. ReadSec                 CALL PauseTR                    ;
  535.                         ;
  536.                         OUT (FDCsector),A               ;
  537.                         ;
  538.                         LD A,cReadSec                   ;
  539.                         OUT (FDCcomm),A                 ;
  540.                         ;
  541.                         CALL ReadData                   ;
  542.                         ;
  543.                         IN A,(FDCstatus)                ;
  544.                         AND #1C                         ;
  545.                         RET Z                           ;
  546.                         ;
  547.                         SCF                             ;
  548.                         RET                             ;
  549. ;
  550. VeriSec                 CALL PauseTR                    ;
  551.                         ;
  552.                         OUT (FDCsector),A               ;
  553.                         ;
  554.                         LD A,cReadSec                   ;
  555.                         OUT (FDCcomm),A                 ;
  556.                         ;
  557.                         CALL VeriData                   ;
  558.                         ;
  559.                         IN A,(FDCstatus)                ;
  560.                         AND #1C                         ;
  561.                         RET Z                           ;
  562.                         ;
  563.                         SCF                             ;
  564.                         RET                             ;
  565. ;
  566. WriteSec                CALL PauseTR                    ;
  567.                         ;
  568.                         OUT (FDCsector),A               ;
  569.                         ;
  570.                         LD A,cWriteSec                  ;
  571.                         ;
  572.                         CALL DoPrecomp                  ;
  573.                         ;
  574.                         OUT (FDCcomm),A                 ;
  575.                         ;
  576.                         CALL WriteData                  ;
  577.                         ;
  578.                         IN A,(FDCstatus)                ;
  579.                         AND #5C                         ;
  580.                         RET Z                           ;
  581.                         ;
  582.                         SCF                             ;
  583.                         RET                             ;
  584. ;
  585. ReadData                IN A,(FDCflags)                 ;
  586.                         OR A                            ;
  587.                         JR Z ReadData                   ;
  588.                         ;
  589.                         RET M                           ;
  590.                         ;
  591.                         IN A,(FDCdata)                  ;
  592.                         LD (HL),A                       ;
  593.                         INC HL                          ;
  594.                         JP ReadData                     ;
  595. ;
  596. VeriData                IN A,(FDCflags)                 ;
  597.                         OR A                            ;
  598.                         JR Z VeriData                   ;
  599.                         ;
  600.                         RET M                           ;
  601.                         ;
  602.                         IN A,(FDCdata)                  ;
  603.                         JP VeriData                     ;
  604. ;
  605. WriteData               IN A,(FDCflags)                 ;
  606.                         OR A                            ;
  607.                         JR Z WriteData                  ;
  608.                         ;
  609.                         RET M                           ;
  610.                         ;
  611.                         LD A,(HL)                       ;
  612.                         OUT (FDCdata),A                 ;
  613.                         INC HL                          ;
  614.                         JP WriteData                    ;
  615. ;
  616. StartMotor              IN A,(FDCstatus)                ;
  617.                         BIT 7,A                         ;
  618.                         RET NZ                          ;
  619.                         ;
  620.                         LD A,#D8                        ;
  621.                         OUT (FDCcomm),A                 ;
  622.                         ;
  623.                         CALL PauseTR                    ;
  624.                         ;
  625.                         LD A,#D0                        ;
  626.                         OUT (FDCcomm),A                 ;
  627.                         ;
  628.                         CALL PauseTR                    ;
  629.                         ;
  630.                         LD HL,MotDel                    ;
  631. SMlp                    CALL Delay                      ;
  632.                         DEC HL                          ;
  633.                         LD A,L                          ;
  634.                         OR H                            ;
  635.                         JR NZ SMlp                      ;
  636.                         ;
  637.                         RET                             ;
  638. ;
  639. PauseTR                 CALL Delay                      ;
  640.                         ;
  641. WaitTR                  PUSH AF                         ;
  642. WaitTRlp                IN A,(FDCstatus)                ;
  643.                         BIT 0,A                         ;
  644.                         JR NZ WaitTRlp                  ;
  645.                         POP AF                          ;
  646.                         ;
  647. Delay                   PUSH IX                         ;
  648.                         POP IX                          ;
  649.                         PUSH IX                         ;
  650.                         POP IX                          ;
  651.                         PUSH IX                         ;
  652.                         POP IX                          ;
  653.                         PUSH IX                         ;
  654.                         POP IX                          ;
  655.                         PUSH IX                         ;
  656.                         POP IX                          ;
  657.                         PUSH IX                         ;
  658.                         POP IX                          ;
  659.                         PUSH IX                         ;
  660.                         POP IX                          ;
  661.                         PUSH IX                         ;
  662.                         POP IX                          ;
  663.                         RET                             ;
  664. ;
  665. DoPrecomp               PUSH BC                         ;
  666.                         ;
  667.                         LD B,A                          ;
  668.                         ;
  669.                         IN A,(FDCtrack)                 ;
  670.                         CP (IX+dPrecomp)                ;
  671.                         ;
  672.                         LD A,B                          ;
  673.                         ;
  674.                         POP BC                          ;
  675.                         ;
  676.                         RET C                           ;
  677.                         ;
  678.                         RES bPrecomp,A                  ;
  679.                         ;
  680.                         RET                             ;
  681. ;
  682. Seek                    PUSH IX                         ;
  683.                         PUSH AF                         ;
  684.                         ;
  685.                         CALL WaitTR                     ;
  686.                         ;
  687.                         BIT 7,A                         ;
  688.                         CALL NZ SideSel1                ;
  689.                         CALL Z SideSel0                 ;
  690.                         ;
  691.                         LD IX,(pCurDrive)               ;
  692.                         ;
  693.                         AND #7F                         ;
  694.                         JR Z SeekTRZ                    ;
  695.                         ;
  696.                         INC (IX+dcTrack)                ;
  697.                         CALL Z initcT                   ;
  698.                         DEC (IX+dcTrack)                ;
  699.                         ;
  700.                         CP 80                           ;
  701.                         JR NC Seekf                     ;
  702.                         ;
  703.                         OUT (FDCdata),A                 ;
  704.                         ;
  705.                         LD (IX+dcTrack),A               ;
  706.                         ;
  707.                         LD A,(IX+dcStepRate)            ;
  708.                         AND %0000 0011                  ;
  709.                         OR cSeek                        ;
  710.                         OUT (FDCcomm),A                 ;
  711.                         ;
  712.                         POP AF                          ;
  713.                         POP IX                          ;
  714.                         RET                             ;
  715. ;
  716. SeekTRZ                 LD A,(IX+dcStepRate)            ;
  717.                         AND %0000 0011                  ;
  718.                         OR cRestore                     ;
  719.                         OUT (FDCcomm),A                 ;
  720.                         ;
  721.                         LD (IX+dcTrack),0               ;
  722.                         ;
  723.                         POP AF                          ;
  724.                         POP IX                          ;
  725.                         RET                             ;
  726. ;
  727. initcT                  PUSH AF                         ;
  728.                         ;
  729.                         LD A,(IX+dcStepRate)            ;
  730.                         AND %0000 0011                  ;
  731.                         OR cRestore                     ;
  732.                         OUT (FDCcomm),A                 ;
  733.                         ;
  734.                         LD (IX+dcTrack),1               ;
  735.                         ;
  736.                         CALL PauseTR                    ;
  737.                         ;
  738.                         POP AF                          ;
  739.                         RET                             ;
  740. ;
  741. Seekf                   POP AF                          ;
  742.                         POP IX                          ;
  743.                         ;
  744.                         LD A,errIT                      ;
  745.                         SCF                             ;
  746.                         RET                             ;
  747. ;
  748. InitPort                LD A,#9F                        ;
  749.                         LD (DiscPort),A                 ;
  750.                         ;
  751.                         OUT (FDCdrive),A                ;
  752.                         ;
  753.                         RET                             ;
  754. ;
  755. SideSel0                PUSH BC                         ;
  756.                         ;
  757.                         LD BC,#10FF                     ;
  758.                         ;
  759.                         JP ModPort                      ;
  760. ;
  761. SideSel1                PUSH BC                         ;
  762.                         ;
  763.                         LD BC,#10EF                     ;
  764.                         ;
  765. ModPort                 PUSH AF                         ;
  766.                         ;
  767.                         LD A,(DiscPort)                 ;
  768.                         OR B                            ;
  769.                         AND C                           ;
  770.                         LD (DiscPort),A                 ;
  771.                         ;
  772.                         OUT (FDCdrive),A                ;
  773.                         ;
  774.                         POP AF                          ;
  775.                         POP BC                          ;
  776.                         RET                             ;
  777. ;
  778. SelectA                 PUSH IX                         ;
  779.                         ;
  780.                         LD IX,DriveA                    ;
  781.                         ;
  782. ModDrive                PUSH AF                         ;
  783.                         ;
  784.                         LD A,(DiscPort)                 ;
  785.                         ;
  786.                         OR (IX+dSelOr)                  ;
  787.                         AND (IX+dSelAnd)                ;
  788.                         ;
  789.                         LD (DiscPort),A                 ;
  790.                         ;
  791.                         OUT (FDCdrive),A                ;
  792.                         ;
  793.                         LD (pCurDrive),IX               ;
  794.                         ;
  795.                         LD A,(IX+dcTrack)               ;
  796.                         OUT (FDCtrack),A                ;
  797.                         ;
  798.                         POP AF                          ;
  799.                         POP IX                          ;
  800.                         RET                             ;
  801. ;
  802. SelectB                 PUSH IX                         ;
  803.                         ;
  804.                         LD IX,DriveB                    ;
  805.                         ;
  806.                         JP ModDrive                     ;
  807. ;
  808. SelectC                 PUSH IX                         ;
  809.                         ;
  810.                         LD IX,DriveC                    ;
  811.                         ;
  812.                         JP ModDrive                     ;
  813. ;
  814. SelectD                 PUSH IX                         ;
  815.                         ;
  816.                         LD IX,DriveD                    ;
  817.                         ;
  818.                         JP ModDrive                     ;
  819. ;
  820. InitDrives              LD HL,DriveData                 ;
  821.                         LD DE,DriveA                    ;
  822.                         LD BC,20                        ;
  823.                         LDIR                            ;
  824.                         RET                             ;
  825. ;
  826. DriveData               DEFB #0F,#FE                    ; Select
  827.                         DEFB 1                          ; StepRate
  828.                         DEFB #FF                        ; cTrack
  829.                         DEFB 43                         ; Precomp
  830.                         ;
  831.                         DEFB #0F,#FD                    ; Select
  832.                         DEFB 1                          ; StepRate
  833.                         DEFB #FF                        ; cTrack
  834.                         DEFB 43                         ; Precomp
  835.                         ;
  836.                         DEFB #0F,#FB                    ; Select
  837.                         DEFB 1                          ; StepRate
  838.                         DEFB #FF                        ; cTrack
  839.                         DEFB 43                         ; Precomp
  840.                         ;
  841.                         DEFB #0F,#F7                    ; Select
  842.                         DEFB 1                          ; StepRate
  843.                         DEFB #FF                        ; cTrack
  844.                         DEFB 43                         ; Precomp
  845. ;
  846. TrackDefnA              DEFB 80,#4E                     ;
  847.                         DEFB 12,#00                     ;
  848.                         DEFB 3,#F6                      ;
  849.                         DEFB 1,#FC                      ;
  850.                         ;
  851.                         DEFB 50,#4E                     ;
  852.                         DEFB 12,#00                     ;
  853.                         DEFB 3,#F5                      ;
  854.                         DEFB 1,#FE                      ;
  855.                         DEFB 1,#F0                      ; Track
  856.                         DEFB 1,#F1                      ; Side
  857.                         DEFB 1,#F2                      ; Sector
  858.                         DEFB 1,#01                      ;
  859.                         DEFB 1,#F7                      ;
  860.                         DEFB 22,#4E                     ;
  861.                         DEFB 12,#00                     ;
  862.                         DEFB 3,#F5                      ;
  863.                         DEFB 1,#FB                      ;
  864.                         ;
  865.                         DEFB 0,#24                      ; Header Data
  866.                         ;
  867.                         DEFB 1,#F7                      ;
  868.                         DEFB 80,#4E                     ;
  869.                         DEFB 0,#4E                      ;
  870.                         ;
  871. TrackDefnB              DEFB 12,#00                     ;
  872.                         DEFB 3,#F5                      ;
  873.                         DEFB 1,#FE                      ;
  874.                         DEFB 1,#F0                      ; Track
  875.                         DEFB 1,#F1                      ; Side
  876.                         DEFB 1,#F2                      ; Sector
  877.                         DEFB 1,#03                      ;
  878.                         DEFB 1,#F7                      ;
  879.                         DEFB 22,#4E                     ;
  880.                         DEFB 12,#00                     ;
  881.                         DEFB 3,#F5                      ;
  882.                         DEFB 1,#FB                      ;
  883.                         ;
  884.                         DEFB 0,#24                      ; Sector Data
  885.                         DEFB 0,#24                      ; Sector Data
  886.                         DEFB 0,#24                      ; Sector Data
  887.                         DEFB 0,#24                      ; Sector Data
  888.                         ;
  889.                         DEFB 1,#F7                      ;
  890.                         DEFB 80,#4E                     ;
  891.                         DEFB 0,#4E                      ;
  892.                         ;
  893.                         DEFB #FF                        ;
  894.  
  895. ; New external drive support
  896.  
  897. Ext_InitParaPort        ld a,$00                        ; Set the data line states to low
  898.                         out (ParaAD),a                  ;
  899.  
  900.                         mMakeParaData_OUT()             ;
  901.  
  902.                         ld a,bmPara_MS or bmPara_RESET  ; These high, all others low
  903.                         out (ParaBD),a                  ;
  904.  
  905.                         mPS_SetStrobeDirns()            ;
  906.                         ret                             ;
  907.  
  908. ; We have to restore a logical track number. For historic reasons "iTrack" has the top bit as a "side" and bits 6..0 as cylinder
  909. ; So, the mapping of logical blocks 0..3 is iTrack values of $00,$80,$01,$81 (etc) which this converts back to logical blocks
  910. ; We just rotate it back into place to get consecutive blocks in the file
  911. Ext_GetTrack            ld a,(iTrack)                   ; [side] [0 .. $7F]
  912.                         rlca                            ;
  913.                         ld (Ext_Track),a                ; Save [0 .. $7F][side]
  914.  
  915.                         or a                            ; NC
  916.                         ret                             ;
  917.  
  918. ; Read a track
  919.  
  920. Ext_TrackRead           call Ext_GetTrack               ;
  921.                         ret c                           ;
  922.  
  923.                         CALL CalcWind                   ; To HL
  924.                         RET C                           ;
  925.  
  926.                         jp Ext_Read4K                   ;
  927.  
  928. ; Write a track
  929.  
  930. Ext_TrackWrite          call Ext_GetTrack               ;
  931.                         ret c                           ;
  932.  
  933.                         call CalcWind                   ; To HL
  934.                         ret c                           ;
  935.  
  936.                         jp Ext_Write4K                  ;
  937.  
  938. ; We want to read a track to (hl)
  939. Ext_Read4K              ld a,0                          ; Part 0
  940.  
  941.                         ; Read the next part
  942.  
  943. Ext_R4K_Lp              ld (Ext_Part),a                 ;
  944.  
  945.                         mPS_Extra_H()                   ; Take the EXTRA data line high
  946.  
  947.                         ld a,PS8_ReadFileBlock          ; Send the get command
  948.                         call WriteByte                  ; Send this byte
  949.  
  950.                         mPS_Extra_L()                   ; Take the EXTRA data line low again
  951.  
  952.                         ld a,(iDrive)                   ; Drive
  953.                         call WriteByte                  ; Send this byte
  954.                         ld a,(Ext_Track)                ; Track
  955.                         call WriteByte                  ; Send this byte
  956.                         ld a,(Ext_Part)                 ; Part
  957.                         call WriteByte                  ; Send this byte
  958.  
  959.                         ld b,32                         ; This many pairs of bytes in a part
  960.                         call ReadMultiplePairs_HL       ;
  961.  
  962.                         ; Now, is there another part?
  963.  
  964.                         ld a,(Ext_Part)                 ; Next part
  965.                         inc a                           ;
  966.  
  967.                         cp $40                          ; Done?
  968.                         jp nz Ext_R4K_Lp                ; No, loop
  969.  
  970.                         or a                            ; NC
  971.                         ret                             ; Done
  972.  
  973. ; We want to write a track from (hl)
  974. Ext_Write4K             ld a,0                          ; Part 0
  975.  
  976.                         ; Write the next part
  977.  
  978. Ext_W4K_Lp              ld (Ext_Part),a                 ;
  979.  
  980.                         mPS_Extra_H()                   ; Take the EXTRA data line high
  981.  
  982.                         ld a,PS8_WriteFileBlock         ; Send the put command
  983.                         call WriteByte                  ; Send this byte
  984.  
  985.                         mPS_Extra_L()                   ; Take the EXTRA data line low again
  986.  
  987.                         ld a,(iDrive)                   ; Drive
  988.                         call WriteByte                  ; Send this byte
  989.                         ld a,(Ext_Track)                ; Track
  990.                         call WriteByte                  ; Send this byte
  991.                         ld a,(Ext_Part)                 ; Part
  992.                         call WriteByte                  ; Send this byte
  993.  
  994.                         ld b,32                         ; This many pairs of bytes in a part
  995.                         call WriteMultiplePairs_HL      ;
  996.  
  997.                         ; Now, is there another part?
  998.  
  999.                         ld a,(Ext_Part)                 ; Next part
  1000.                         inc a                           ;
  1001.  
  1002.                         cp $40                          ; Done?
  1003.                         jp nz Ext_W4K_Lp                ; No, loop
  1004.  
  1005.                         or a                            ; NC
  1006.                         ret                             ; Done
  1007.  
  1008. ; We want to send a filename
  1009. Ext_SendFilename        call CalcWind                   ; Where from? -> (hl)
  1010.                         ret c                           ;
  1011.  
  1012.                         mPS_Extra_H()                   ; Take the EXTRA data line high
  1013.  
  1014.                         ld a,PS8_SendFilename           ; Send the command
  1015.                         call WriteByte                  ; Send this byte
  1016.  
  1017.                         mPS_Extra_L()                   ; Take the EXTRA data line low again
  1018.  
  1019.                         ld a,(iDrive)                   ; Drive
  1020.                         call WriteByte                  ; Send this byte
  1021.  
  1022.                         ; Send the string
  1023.  
  1024. Ext_SF_Lp               ld a,(hl)                       ; Next character
  1025.                         inc hl                          ;
  1026.  
  1027.                         call WriteByte                  ; Write one
  1028.  
  1029.                         or a                            ; Done?
  1030.                         jr nz Ext_SF_Lp                 ; No, loop
  1031.  
  1032.                         ret                             ; Done
  1033.  
  1034. ; Write AL
  1035. WriteByte               ld c,a                          ; Save the data
  1036.  
  1037.                         mPS_MS_H()                      ; MS high
  1038.  
  1039.                         mWaitForSS_H()                  ; Wait for the slave strobe to go high
  1040.  
  1041.                         ld a,c                          ; Get the data
  1042.                         out (ParaAD),a                  ;
  1043.                         mMakeParaData_OUT()             ; Make it an output
  1044.  
  1045.                         mParaSettleDelay()              ; Delay a bit
  1046.  
  1047.                         mPS_MS_L()                      ; MS low
  1048.  
  1049.                         mWaitForSS_L()                  ; Wait for the slave strobe to go low
  1050.  
  1051.                         mPS_MS_H()                      ; MS high
  1052.  
  1053.                         ld a,c                          ; Restore the byte
  1054.                         ret                             ;
  1055.  
  1056. ; Use both strobe edges to write a pair of bytes x b
  1057. WriteMultiplePairs_HL   mPS_MS_H()                      ; MS high
  1058.  
  1059.                         mMakeParaData_OUT()             ; Make it an output
  1060.  
  1061. WMP_HL_Lp               mWaitForSS_H()                  ; Wait for the slave strobe to go high
  1062.  
  1063.                         ld a,(hl)                       ; Get the data
  1064.                         out (ParaAD),a                  ;
  1065.  
  1066.                         inc hl                          ; ++ and delay
  1067.  
  1068.                         mPS_MS_L()                      ; MS low
  1069.                         mWaitForSS_L()                  ; Wait for the slave strobe to go low
  1070.  
  1071.                         ld a,(hl)                       ; Get the data
  1072.                         out (ParaAD),a                  ;
  1073.  
  1074.                         inc hl                          ; ++ and delay
  1075.  
  1076.                         mPS_MS_H()                      ; MS high
  1077.                         djnz WMP_HL_Lp                  ; Loop
  1078.  
  1079.                         ret                             ;
  1080.  
  1081. ; Read AL
  1082. ReadByte                mPS_MS_H()                      ; MS high
  1083.  
  1084.                         mWaitForSS_H()                  ; Wait for the slave strobe to go high
  1085.  
  1086.                         mMakeParaData_IN()              ; Make it an input
  1087.  
  1088.                         mPS_MS_L()                      ; MS low
  1089.  
  1090.                         mWaitForSS_L()                  ; Wait for the slave strobe to go low
  1091.  
  1092.                         mParaSettleDelay()              ; Delay a bit
  1093.                         in a,(ParaAD)                   ; Read the data
  1094.                         ld c,a                          ; Save it
  1095.  
  1096.                         mPS_MS_H()                      ; MS high
  1097.  
  1098. ;                        mWaitForSS_H()                  ; Wait for the slave strobe to go high
  1099.  
  1100.                         ld a,c                          ; Get the data
  1101.                         ret                             ; Done
  1102.  
  1103. ; Use both strobe edges to read a pair of bytes x b
  1104. ReadMultiplePairs_HL    mPS_MS_H()                      ; MS high
  1105.                         mWaitForSS_H()                  ; Wait for the slave strobe to go high
  1106.  
  1107.                         mMakeParaData_IN()              ; Make it an input
  1108.  
  1109. RMP_HL_Lp               mPS_MS_L()                      ; MS low
  1110.                         mWaitForSS_L()                  ; Wait for the slave strobe to go low
  1111.  
  1112.                         mParaSettleDelay()              ; Delay a bit
  1113.                         in a,(ParaAD)                   ; Read the data
  1114.                         ld c,a                          ; Save it
  1115.  
  1116.                         mPS_MS_H()                      ; MS high
  1117.                         mWaitForSS_H()                  ; Wait for the slave strobe to go high
  1118.  
  1119.                         ld (hl),c                       ; Store it (and delay)
  1120.                         inc hl                          ;
  1121.  
  1122.                         in a,(ParaAD)                   ; Read the data
  1123.  
  1124.                         ld (hl),a                       ; Store it
  1125.                         inc hl                          ;
  1126.  
  1127.                         djnz RMP_HL_Lp                  ; Loop
  1128.                         ret                             ;
  1129.  
  1130. ; Macros - BE CAREFUL! These shouldn't alter any register but AF
  1131.  
  1132. mMakeParaData_OUT       macro()                         ;
  1133.                           ld a,$FF                      ;
  1134.                           out (ParaAK),a                ;
  1135.                           xor a                         ;
  1136.                           out (ParaAK),a                ;
  1137.                           mend                          ;
  1138.  
  1139. mParaSettleDelay        macro()                         ;
  1140.                           nop                           ;
  1141.                           mend                          ;
  1142.  
  1143. mMakeParaData_IN        macro()                         ;
  1144.                           ld a,$FF                      ;
  1145.                           out (ParaAK),a                ;
  1146.                           out (ParaAK),a                ;
  1147.                           mend                          ;
  1148.  
  1149. ; Set the strobe directions
  1150.  
  1151. mPS_SetStrobeDirns      macro()
  1152.                           ld a,$FF                      ;
  1153.                           out (ParaBK),a                ;
  1154.                           ld a,bmPara_SS                ; Only this one is an input
  1155.                           out (ParaBK),a                ;
  1156.                           mend
  1157.  
  1158. mWaitForSS_H            macro()                         ;
  1159. Lp                        in a,(ParaBD)                 ;
  1160.                           and a,bmPara_SS               ;
  1161.                           jp z Lp                       ;
  1162.                           mend                          ;
  1163.  
  1164. mWaitForSS_L            macro()                         ;
  1165. Lp                        in a,(ParaBD)                 ;
  1166.                           and a,bmPara_SS               ;
  1167.                           jp nz Lp                      ;
  1168.                           mend                          ;
  1169.  
  1170. mPS_MS_L                macro()                         ;
  1171.                           in a,(ParaBD)                 ;
  1172.                           and a,bmPara_MS xor $FF       ;
  1173.                           out (ParaBD),a                ;
  1174.                           mend                          ;
  1175.  
  1176. mPS_MS_H                macro()                         ;
  1177.                           in a,(ParaBD)                 ;
  1178.                           or a,bmPara_MS                ;
  1179.                           out (ParaBD),a                ;
  1180.                           mend                          ;
  1181.  
  1182. mPS_RESET_L             macro()                         ;
  1183.                           in a,(ParaBD)                 ;
  1184.                           and a,bmPara_RESET xor $FF    ;
  1185.                           out (ParaBD),a                ;
  1186.                           mend                          ;
  1187.  
  1188. mPS_RESET_H             macro()                         ;
  1189.                           in a,(ParaBD)                 ;
  1190.                           or a,bmPara_RESET             ;
  1191.                           out (ParaBD),a                ;
  1192.                           mend                          ;
  1193.  
  1194. mPS_Extra_L             macro()                         ;
  1195.                           in a,(ParaBD)                 ;
  1196.                           and a,bmPara_EXTRA xor $FF    ;
  1197.                           out (ParaBD),a                ;
  1198.                           mend                          ;
  1199.  
  1200. mPS_Extra_H             macro()                         ;
  1201.                           in a,(ParaBD)                 ;
  1202.                           or a,bmPara_EXTRA             ;
  1203.                           out (ParaBD),a                ;
  1204.                           mend                          ;
  1205.  
  1206. YeEnd                   equ *                           ;
  1207.  
  1208.                         ORG #4000                       ;
  1209.  
  1210. Ext_Track               ds 1                            ;
  1211. Ext_Part                ds 1                            ;
  1212.  
  1213. DriveA                  DEFS 5                          ;
  1214.                         ;
  1215. DriveB                  DEFS 5                          ;
  1216.  
  1217. DriveC                  DEFS 5                          ;
  1218.                         ;
  1219. DriveD                  DEFS 5                          ;
  1220.  
  1221. DiscPort                DEFS 1                          ;
  1222.  
  1223. pCurDrive               DEFS 2                          ;
  1224.  
  1225. DataTemp                DEFS 2                          ;
  1226.  
  1227. cPrecompBit             DEFS 1                          ;
  1228.  
  1229. FormatWS                DEFS #1B00                      ;
  1230.  
  1231.                         output_para YeStart,YeEnd-YeStart;
  1232.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement