System - access directly to DOS ROM and direct programming of VG 93.

Eldorado #02
Greetings, dear readers and editors,
magazine tori "Eldorado"! It's great that
we finally have our own in Yaroslavl
electronic magazine.  Of course the guys still
I need to work on myself, but the first steps
were clearly on the level. I was especially pleased
music. Well, I said thank you, and now about
a little mistake that crept into
first article "System":                  
                                          
                                          
Yes:                                     
                                          
zag  LD   C,5                      
          LD  DE,(23796)               
          RET                            
                                          
It should be:                              
                                          
zag  LD  C,5                      
          LD  DE,(23796)               
          JP  #3D13                    
                                          
                                          
I would also like to note that the given
naya in the first issue "Eldorado"  article
"System"  was clearly intended for beginners
nayushchih.  And this means that it was necessary
clearly tell you HOW to stuff the received
loader in the first BASIC drain, if TASM
keeps his resident there!  Do some work.
Personally, I emulate using DEFB and DEFW
BASIC operators. I can share.        
                                          
                                          
Now to the point.  Actually, I would like
continue the topic of bootloaders and talk
about accessing the DOS ROM directly and about
direct programming VG 93.Generally speaking about programming VG 93 and
work with the disk without using systems -
DOS variables have been said and written
a lot. The most detailed, in my opinion,
information was published in the third edition
books "ZXSpectrum for users and pro-
grammarians" (ZXSpectrum & TR-DOS) N.Rodio-
nova and A. Larchenko. But the presentation of information
in this and similar publications there are several
a little dry. And the listings of DOS subroutines or
are not given at all or are not commented on.   
                                          
In short, next I will try the most accessible
but also clearly talk about VG 93 and relying on
the information presented to tell about some
many DOS subroutines.                  
                                          
Here and further: VG93 - mm KR1818VG93;   
OS - operating system (BASIC, etc.);
DOS - disk operating system;      
                                          
                                          
Let's start with the fact that VG-shka is for you (and forprocessor) - just a few ports.
Sent a number to one port, to another port
another number, sent the co-code to the third port
cunts; look - there’s a light on the disk drive
lights up, and the disk is already spinning, and if
read something from the fourth port,
then maybe something will even be read.
                                          
                                          
Several extremely important ones should be noted
things:                                    
                                          
1.  DOS ROM, and with it the VG registers
(ports) are turned on only when you
any command is filled in at the address
#3D00 - #ЗDFF (15616 - 15871). In OS ROM
there is a character generator and transmit
him control just like that yet no one (glory
God) didn't think of it. The DOS ROM is disabled
(and with it the VG9Z ports) when performing
any command at an address greater than
#ЗFFF (16383), that is, in RAM.             
                                          
2.  From paragraph 1. it follows that to control the VG
is possible only with DOS subroutines, and in order
it is necessary to do itstudy well.
                                          
3.  From items 1. and 2. it follows that
we need to contact the parts of DOS we need
in some special, perverted way. About
We'll talk about this a little later.        
                                          
And here are those same register-ports of VG93:       
                                          
╔═════════╦═══ ════════════════╦══════════╗
║ Address ║ Register name ║ Access ║
╠═════════╬══════════ ═════════╬══════════╣
║#1F (31) ║ Reg. commands ║ Record ║
║#1F (31) ║ Reg. states ║ Reading ║
║#3F (63) ║ Reg. tracks ║ Read/Write ║
║#5F (95) ║ Reg. sectors ║ Read/Write ║
║#7F (127)║ Reg. Data ║ Read/Write ║
╚═════════╩══════════ ═════════╩══════════╝
                                          
And this (^) is not quite a VG register, but it’s for us
no difference.                              
                                          
╔═════════╦═══ ════════════════╦══════════╗
║#FF (255)║ System Register ║ Read/Write ║
╚═════════╩══════════ ═════════╩══════════╝
                                          
Address -port number.                      
                                          
Access is what you can do with it (read/
zap. these are read and write respectively). 
                                          
Let me remind you that for us, in principle, words
"port" and "register" are synonymous.   
                                          
Command register - the code is written to it
manda, understandable to VG. The accepted command is not
slow to execute. Only entries are possible -
vat.                                     
                                          
Status register - individual bits of this
register indicate the correctness of the accepted
that team, etc. (something like a register
F in Z-80). Read only.                 
                                          
Track and sector registers - indicate
drive head position.  Are
input parameters for some commands
VG.    Read and write.  For those who
confused, let me remind you:                        
                                          
                                          
                                          
                                          
                                          
                                          
                                          
Data register - through it, or
acceptedwritable or readable
data (sometimes auxiliary). Reading
and recording.                                 
                                          
                                          
System register - when reading from it
indicates the drive is ready to accept
or issue the next byte, as well as
end of the operation. When recording - system
information (drive number, recording method
FM/MFM, side, etc.). More details:       
                                          
                                          
When reading from port #FF:                  
╔═════╦═══════ ═══════════════════════════╗
║ Bit ║ Purpose ║
╠═════╬══════════════ ════════════════════╣
║ 0-5 ║ Not of interest ║
║ 6 ║ Data request ║
║ 7 ║ End of operation ║
╚═════╩══════════════ ════════════════════╝
                                          
When recording:                               
╔═════╦═══════ ═══════════════════════════╗
║ Bit ║ Purpose ║
╠═════╬══════════════ ════════════════════╣
║ 0-1 ║ Select drive (00,01,10,11 ║
║ ║ A, B, C, D) ║
║ 2 ║Reset the microcontroller (practically)
║ ║no required) ║
║ 3 ║Blocking the HLT VG signal. For ║
║ ║ for normal operation should be 1. ║
║ 4 ║ Head selection: 0 - 1st, bottom; ║
║ ║ 1 - 2nd, top.║
║ 5 ║Recording method: ║
║ ║0 - FM frequency modulation ║
║ ║1 - MFM modified frequency║
║ ║modulation. Usually they use MFM. ║
║ 6-7 ║ Not used ║
╚═════╩══════════════ ════════════════════╝
------------------------------------------
Practical interest for us at this
stage represents reading from the system
register (port):                         
                                          
                                          
Request for data - until this
0 is written in the bit, the drive is not ready for
receive (issue) the next byte of data. After all
The processor is much faster than
VG93 and both of them transmit data much more
faster than the disk drive (the dog is running
faster than a human! Haha).                 
                                          
End of operation - well, everything is clear here: 0 in
this bit means that the current operation is
tion is not completed. It should only be noted
one very interesting point: when reading
sector controller CAM determines how many
byte will be read (regardless of
whether you want it or not). Same thing
when recordingsector(s). Think about it
moment, we will return to it later.         
                                          
                                          
Since we are talking about reading with
disk using direct VG control, then
it makes no sense (yet) to talk about everyone
VG control commands.                   
                                          
Let's look at the most necessary ones:             
                                          
(here it should be said that the VG93 teams
there are no mnemonics like assembler, so
just write the name of the team (co-group)
mand) and bitmap)                
                                          
                                          
Search - 0001hvxx. This command installs
no mag.  head on the track, the number of which is
swarm is specified in the DATA register. Assumes-
It is clear that in the TRACK register there is a number
track on which the head stands. Desire-
It is advisable (but not necessary) to perform when
parameter v=1.                            
                                          
     h = 0 - during command execution  
     the head will be raised above the disk and not
     a signal to turn on the engine will be issued 
     gateladisk drive;                    
     h = 1 - the head will be lowered in operation
     whose position and signal to turn on  
     will be issued.                         
                                          
  v - makes sense only when h=1. When 
     v = 1 track register value compared
     matches the value read from   
     disk.                               
                                          
    xx - speed of operation:   
    00 - maximum, 01.10 - intermediate  
     exact,11 - minimal.            
                                          
Reading  sector(s) -  1OOmsecO. Name
speaks for itself. Set sector number
is in the SECTOR register.                  
                                          
     m = 0 - read only one sector.
     m = 1 - all sectors to the end of the track.
                                          
     s - floppy side (0-bottom, 1-top)
 Has no practical significance, because
     the disk side is handled by the SYSTEM  
     register, but may come in handy (see^).
                                          
    e - if this bit is set, then inter-
     by issuing a signal to install the holo-
     wok into working position and start    
 operation is delayed by 15 ms.  
                                          
     c -check (1) or not (0) side 
     well, floppy disks during the operation (see parameter
     s). The fact is that the side of the floppy disk  
     are written down when formatting, but
     We'll talk about this next time.   
                                          
These are the two simplest operations, based on
which we will consider reading with dis-ka.                                       
Here is a simplified disk driver,
given in ZX-REVIEW 4'95 (why was it invented?
steal a bicycle?):                         
                                          
       © ALANSOFT'95                      
     SMALL DISK-DRIVER                    
Slightly alteredNicolas Viper.           
                                          
The following must be specified at the input:              
   HL = download address;                   
   DE = track, sector;                   
    B = number of sectors.                   
                                          
ORG 50000                        
DRIVER                     
 DI                     
LD IX,#2F65 ;(12133) Subroutine
 CALL DOS ;initialization.     
L1 PUSH DE ;Save DE and BC. 
 PUSH BC ;                   
 OR A ;Translate from logical 
 LD A,D ; 
 RRA ;horns to physical.
 LD C,A ; (discussed later)    
LD A,#3С ;#3С=%00111100      
 JR NC,L2 ;#2С=%00101100      
LD A,#2С ;        ^side.  
 ;                   
L2 LD IX,#2FЧD ;Setting subroutine 
 CALL DOS ; new items on the track.  
 ;(12109)            
 POP BC ; Restoring    
       POP   DE       ;  ВС и DE.         
М2     PUSH  HL       ;Сохраняем          
       PUSH  DE       ;    регистры.      
       PUSH  ВС       ;                   
       LD    IX,#2F1В ;{12059) Собственно 
       CALL  DOS      ;чтение.            
       POP   ВС       ;Восстанавливаем    
       POP   DE       ;    регистры.      
       POP   HL       ;                   
       INC   Н        ;Поскольку считаем, 
                      ;что длина сектора  
                      ;256 байт.          
       INC   E        ;Следующий сектор.  
       LD    A,15     ;15=%00001111       
       AND   E;If E=16, then E=0, 
LD E,A ;flag Z=1 and transition 
JR Z,L5 ;to the next road
DJNZ M2 ;ku, otherwise just   
 ;next sector.  
 JR EXIT ;To exit.          
L5 INC D ;Next track. 
 DJNZ L1 ;                   
EXIT EI ;                   
 RET ;Output.             
 ;                   
DOS ;On the stack - address   
                      ;return.          
       PUSH IX  ;On the stack - address   
                      ;called procedure-
 ;ry.                
       JP   #3D2F  ;(1566З) Connects-
                      ;Xia ROM DOS, and there  
located:                                
                                          
#3D2F  NOP                                
#3D30  RET.By RET control is transferred -
               to the subroutine you need
ROM DOS, and it will return to the point from where
called the "DOS" procedure.                 
                                          
Before we analyze the ones called by our
DOS procedure driver, let me remind you that
There are two ways to number tracks and
sectors:                                 
                                          
1.  Logical.We are used to it.
Tracks are numbered from zero and to 159.
Sectors are numbered: 0..15 2.  Physical. Tracks are numbered: 0..79,
but on each side. Zero logical -
this is the zero upper physical, the first lo-
gich. this is the top zero, etc.. Sectors
numbered:  1..16. This method is the most
understandable to VG and your floppy disk cruncher  
(joke).                                  
                                          
                                          
And here are the DOS procedures:                 
                                          
#2F65  Reset (restore) the controller.
Be sure to contact us when you start working!
Nothing interesting.  If you want, then I
I’ll tell you about it in future publications.   
                                          
                                          
#2FЧD Installation on a track:               
Input parameters in registers:           
                                          
 A - System information. Usually #3С or 
#2С,which corresponds to:                   
#3С - A,?, HLT allowed, upper head, MFM
#2С - the same, but with a lower head. Details
See it in the description of the system solution.  
С - Physical track number.            
 In track register - track number, on   
which the head stands.                    
#2FХD OUT (#FF),A ;installing the system
 ;information. Use
 ;
 ;disk side.  
LD A,C ;B reg. data number
 OUT (#7F),A ;of the desired track.    
 CALL #ЗDFD ;Delay           
LD A,#18 ;#18=%00011000 Ko-  
OUT (#1F),A ;mand "Search".     
M1 IN A,(#FF) ;Wait for the command 
AND #80 ;executed.       
 JR Z,M1 ;#80=%10000000      
 PUSH BC ;                   
 CALL #ЗDFD ;Another delay. 
 POP BC ;                   
 RET ;Return            
------------------------------------------
#ЗDFD LD A,#50 ;Subroutine       
W1 LD C,#FF ;delays.          
W2 DEC C ;                   
 JR NZ,W2 ;                   
 DEC A ;                   
       JR NZ,W1 ;                 
       RET ;Return            
#2F1B Reading the track.                     
                                          
Input parameters:                        
                                          
 E - logical sector number.            
HL - download address.                     
It is assumed that the head is installed on
the track from which you need to read.  
                                          
#2F1В  LD   A, E ;Was logical -   
       INC   A  ;became physical.   
       OUT  (#5F),A ;Send to register 
                      ;sectors            
       PUSH HL  ;                   
       LD    D,#14    ;#14=20 Сколько раз 
                      ;повторять, в случае
       PUSH  DE       ;ошибки.Сохраняем.  
L1     DI             ;Запрет прерываний! 
       LD    С,#7F    ;Адрес р-ра данных. 
       LD    A,#80    ;#80=%10000000 Ко-  
       OUT   (#1F),A  ;манда "чтение".    
       CALL  #ЗFE5    ;Собственно чтение. 
       POP   DE       ;Восстанавливаем ре-
       POP   HL       ;гистры.            
       IN    A,(#1F)  ;Проверка на ошибку.
       AND   #7F      ;#7F=%01111111      
       RET   Z        ;Возврат, если окей.
       DEC   D        ;Уменьшаем счетчик. 
       PUSH  HL       ;                   
       PUSH  DE       ;                   
       JR    NZ,L1    ;Повтор, если D<>0. 
#2F39  HALT           ;Повись!            
#2FЗA  ... ;                   
                      ;                   
       ...            ;                   
                      ;                   
#ЗFE5  IN    A,(#FF)  ;Ожидаем разрешения.
       AND   #С0      ;#С0=%11000000      
       JR    Z,#ЗFE5  ;                   
       RET   М        ;Возврат, если конец
                      ;См. таблицу по Сис-
                      ;темному р-ру. Флаг 
                      ;S дублирует старший
                      ;разряд р-ра.       
       INI            ;Читаем.            
                      ;INI=IN  (HL),(C)   
                      ;    INC HL         
       JR  #ЗFE5  ;Looping.      
That's all. I hope you understood most of it
presented material. If you want to continue
zheniya, then report it to the editor "El-
dorado"or Condor softpersonally.  And I would
told you about the recording (without using the system.
belt DOS), about how to make music
during loading (see "BATLECOMMAND",
"BLINKY'S","INSULT") and something else. 
                                          
The article used material from the book     
A. Larchenko and N. Rodionova                  
"ZX Specrtum & TR DOS for users and
programmers" publishing house "PETER" 1994
This publication is the best reference book for
programmer and user.              
                                          
And finally: a great human salvation
to Sir Clive Sinclair for the car that
taught usthe joys of programming.     
                                          
                                          
                                          
                                          
                      © 1995 Nicolas Viper

Share your thoughts about the article