;
; +-------------------------------------------------------------------------+
; ¦     This file is generated by The Interactive Disassembler (IDA)        ¦
; ¦     Copyright (c) 2006 by DataRescue sa/nv, <ida@datarescue.com&;        ¦

; +-------------------------------------------------------------------------+
;

.686p
.mmx
.model flat


; Segment type: Regular
bdata segment at 40h public 'BIOSDATA' use16
assume cs:bdata
assume es:nothing, ss:nothing, ds:nothing, fs:nothing, gs:nothing
com_port_1 dw ?         ; Base I/O address of 1st serial I/O port
com_port_2 dw ?         ; Base I/O address of 2nd serial I/O port
com_port_3 dw ?         ; Base I/O address of 3rd serial I/O port
com_port_4 dw ?         ; Base I/O address of 4th serial I/O port
prn_port_1 dw ?         ; Base I/O address of 1st parallel I/O port
prn_port_2 dw ?         ; Base I/O address of 2nd parallel I/O port
prn_port_3 dw ?         ; Base I/O address of 3rd parallel I/O port
prn_port_4 dw ?         ; Base I/O address of 4th parallel I/O port
equip_bits dw ?         ; Equipment installed info bits
                        ; 15  14  13   12   11  10   9   8
                        ; \    /      game  \       /
                        ; # of print  port  # of RS-232
                        ; ports 0-3   used   ports 0-4
                        ;
                        ; 7   6    5    4    3   2   1   0
                        ; \   /    \    /    \   / Math  |
                        ; # of   video mode  RAM    uP  no
                        ; disk-  at boot up  00=16K    dsk
                        ; ettes  00=EGA/VGA  01=32K   driv
                        ;  1-4   01=CGA-40   10=48K   if 0
                        ; if bit 10=CGA-80   11=64K
                        ; 0 = 1  11=MDA-80   (old PCs)
                        ;
                        ; Note: bit 13=modem on PC lap-tops
                        ;       bit 2=mouse on MCA & others
manufactr_test db ?     ; Manufacturing Test Byte
                        ; bit 0 = 1 while in test mode
                        ; MCA systems use other bits
                        ;   during POST operations
base_ram_size dw ?      ; Base memory size in KBytes (0-640)
mtest_scratchpad db ?   ; [AT] {Manufacturing test scratch pad}
                        ; [Compaq Deskpro 386] previous scan code
error_codes db ?        ; [AT] {Manufacturing test scratch pad}
                        ; [PS/2 Mod 30] {BIOS control flags}
                        ; [Compaq Deskpro 386] keyclick loudness (00h-7Fh)
keybd_flags_1 db ?      ; Keyboard flag bits
                        ;   7   6   5   4    3   2   1   0
                        ; ins- cap num scrl alt ctl lef rig
                        ; sert --toggles--- --shifts down--
keybd_flags_2 db ?      ; Keyboard flag bits
                        ;    7     6     5     4
                        ; insert  caps  num  scroll
                        ; ------now depressed------
                        ;
                        ;    3     2     1     0
                        ;  pause  sys   left right
                        ;  lock request -alt-down-
keybd_alt_num db ?      ; Alt-nnn keypad workspace
keybd_q_head dw ?       ; pointer to next character in keyboard buffer
keybd_q_tail dw ?       ; pointer to first free slot in keyboard buffer
keybd_queue dw 10h dup(?) ; Keyboard circular buffer
dsk_recal_stat db ?     ; Recalibrate floppy drive bits
                        ;    3       2       1       0
                        ; drive-3 drive-2 drive-1 drive-0
                        ;
                        ; bit 7 = interrupt flag
dsk_motor_stat db ?     ; Motor running status & disk write
                        ;  bit 7=1 disk write in progress
                        ;  bits 6&5 = drive selected 0 to 3
                        ;     3       2       1       0
                        ;  drive-3 drive-2 drive-1 drive-0
                        ;  --------- 1=motor on-----------
dsk_motor_timer db ?    ; Motor timer, at 0, turn off motor
dsk_ret_code db ?       ; Controller return code
                        ;  00h = ok
                        ;  01h = bad command or parameter
                        ;  02h = can't find address mark
                        ;  03h = can't write, protected dsk
                        ;  04h = sector not found
                        ;  08h = DMA overrun
                        ;  09h = DMA attempt over 64K bound
                        ;  10h = bad CRC on disk read
                        ;  20h = controller failure
                        ;  40h = seek failure
                        ;  80h = timeout, no response
dsk_status_1 db ?       ; Status bytes-disk controller chip
                        ;  Note: 7 info bytes returned from
                        ;  controller are saved here. Refer
                        ;  to the NEC uPD 765 chip manual
                        ;  for the specific info, depending
                        ;  on the previous command issued.
dsk_status_2 db ?
dsk_status_3 db ?
dsk_status_4 db ?
dsk_status_5 db ?
dsk_status_6 db ?
dsk_status_7 db ?
video_mode db ?         ; Present display mode
video_columns dw ?      ; Number of columns
video_buf_size dw ?     ; Video buffer size in bytes
                        ;   Note: size may be rounded up to
                        ;   the nearest 2K boundary.  For
                        ;   example, 80x25 mode=4000 bytes,
                        ;   but value may be 4096.
video_pageoff dw ?      ; Video page offset of the active
                        ;   page, from start of current
                        ;   video segment.
vid_curs_pos0 dw ?      ; Cursor position page 0
                        ;   bits 15-8=row, bits 7-0=column
vid_curs_pos1 dw ?      ; Cursor position page 1
                        ;   bits 15-8=row, bits 7-0=column
vid_curs_pos2 dw ?      ; Cursor position page 2
                        ;   bits 15-8=row, bits 7-0=column
vid_curs_pos3 dw ?      ; Cursor position page 3
                        ;   bits 15-8=row, bits 7-0=column
vid_curs_pos4 dw ?      ; Cursor position page 4
                        ;   bits 15-8=row, bits 7-0=column
vid_curs_pos5 dw ?      ; Cursor position page 5
                        ;   bits 15-8=row, bits 7-0=column
vid_curs_pos6 dw ?      ; Cursor position page 6
                        ;   bits 15-8=row, bits 7-0=column
vid_curs_pos7 dw ?      ; Cursor position page 7
                        ;   bits 15-8=row, bits 7-0=column
vid_curs_mode dw ?      ; Active cursor, start & end lines
                        ;   bits 12 to 8 for starting line
                        ;   bits 4  to 0 for ending line
video_page db ?         ; Present page
video_port dw ?         ; Video controller base I/O address
video_mode_reg db ?     ; Hardware mode register bits
video_color db ?        ; Color set in CGA modes
gen_use_ptr dw ?        ; General use offset pointer
gen_use_seg dw ?        ; General use segment pointer
gen_int_occurd db ?     ; Unused interrupt occurred
                        ;   value holds the IRQ bit 7-0 of
                        ;   the interrupt that occurred
timer_low dw ?          ; Timer, low word, cnts every 55 ms
timer_high dw ?         ; Timer, high word
timer_rolled db ?       ; Timer overflowed, set to 1 when
                        ;  more than 24 hours have elapsed
keybd_break db ?        ; Bit 7 set if break key depressed
warm_boot_flag dw ?     ; Boot (reset) type
                        ;   1234h=warm boot, no memory test
                        ;   4321h=boot & save memory
hdsk_status_1 db ?      ; Hard disk status
                        ;  00h = ok
                        ;  01h = bad command or parameter
                        ;  02h = can't find address mark
                        ;  03h = can't write, protected dsk
                        ;  04h = sector not found
                        ;  05h = reset failure
                        ;  07h = activity failure
                        ;  08h = DMA overrun
                        ;  09h = DMA attempt over 64K bound
                        ;  0Ah = bad sector flag
                        ;  0Bh = removed bad track
                        ;  0Dh = wrong # of sectors, format
                        ;  0Eh = removed control data addr
                        ;         mark
                        ;  0Fh = out of limit DMA
                        ;         arbitration level
                        ;  10h = bad CRC or ECC, disk read
                        ;  11h = bad ECC corrected data
                        ;  20h = controller failure
                        ;  40h = seek failure
                        ;  80h = timeout, no response
                        ;  AAh = not ready
                        ;  BBh = error occurred, undefined
                        ;  CCh = write error, selected dsk
                        ;  E0h = error register = 0
                        ;  FFh = disk sense failure
hdsk_count db ?         ; Number of hard disk drives
hdsk_head_ctrl db ?     ; Head control (XT only)
hdsk_ctrl_port db ?     ; Hard disk control port (XT only)
prn_timeout_1 db ?      ; Countdown timer waits for printer
                        ;   to respond (printer 1)
prn_timeout_2 db ?      ; Countdown timer waits for printer
                        ;   to respond (printer 2)
prn_timeout_3 db ?      ; Countdown timer waits for printer
                        ;   to respond (printer 3)
prn_timeout_4 db ?      ; Countdown timer waits for printer
                        ;   to respond (printer 4)
rs232_timeout_1 db ?    ; Countdown timer waits for RS-232 (1)
rs232_timeout_2 db ?    ; Countdown timer waits for RS-232 (2)
rs232_timeout_3 db ?    ; Countdown timer waits for RS-232 (3)
rs232_timeout_4 db ?    ; Countdown timer waits for RS-232 (4)
keybd_begin dw ?        ; Ptr to beginning of keybd queue
keybd_end dw ?          ; Ptr to end of keyboard queue
video_rows db ?         ; Rows of characters on display - 1
video_pixels dw ?       ; Number of pixels per charactr * 8
video_options db ?      ; Display adapter options
                        ;   bit 7 = clear RAM
                        ;   bits 6,5 = memory on adapter
                        ;               00 - 64K
                        ;               01 - 128K
                        ;               10 - 192K
                        ;               11 - 256K
                        ;   bit 4 = unused
                        ;   bit 3 = 0 if EGA/VGA active
                        ;   bit 2 = wait for display enable
                        ;   bit 1 = 1 - mono monitor
                        ;         = 0 - color monitor
                        ;   bit 0 = 0 - handle cursor, CGA
video_switches db ?     ; Switch setting bits from adapter
                        ;   bits 7-4 = feature connector
                        ;   bits 3-0 = option switches
video_1_save db ?       ; Video save area 1-EGA/VGA control
                        ;   bit 7 = 200 line mode
                        ;   bits 6,5 = unused
                        ;   bit 4 = 400 line mode
                        ;   bit 3 = no palette load
                        ;   bit 2 = mono monitor
                        ;   bit 1 = gray scale
                        ;   bit 0 = unused
video_2_save db ?       ; Video save area 2
dsk_data_rate db ?      ; Last data rate for diskette
                        ;  bits 7 & 6 = 00 for 500K bit/sec
                        ;             = 01 for 300K bit/sec
                        ;             = 10 for 250K bit/sec
                        ;             = 11 for 1M bit/sec
                        ;  bits 5 & 4 = step rateRate at start of operation
                        ;  bits 3 & 2 = 00 for 500K bit/sec
                        ;             = 01 for 300K bit/sec
                        ;             = 10 for 250K bit/sec
                        ;             = 11 for 1M bit/sec
hdsk_status_2 db ?      ; Hard disk status
hdsk_error db ?         ; Hard disk error
hdsk_complete db ?      ; When the hard disk controller's
                        ;  task is complete, this byte is
                        ;  set to FFh (from interrupt 76h)
dsk_options db ?        ; Diskette controller information
                        ;  bit 6 = 1 Drv 1 type determined
                        ;      5 = 1 Drv 1 is multi-rate
                        ;      4 = 1 Drv 1 change detect
                        ;      2 = 1 Drv 0 type determined
                        ;      1 = 1 Drv 0 is multi-rate
                        ;      0 = 1 Drv 0 change detect
dsk0_media_st db ?      ; Media state for diskette drive 0
                        ;     7      6      5      4
                        ;  data xfer rate  two   media
                        ;   00=500K bit/s  step  known
                        ;   01=300K bit/s
                        ;   10=250K bit/s
                        ;   11=1M bit/sec
                        ;     3      2      1      0
                        ;  unused  -----state of drive-----
                        ;          bits floppy  drive state
                        ;          000=  360K in 360K, ?
                        ;          001=  360K in 1.2M, ?
                        ;          010=  1.2M in 1.2M, ?
                        ;          011=  360K in 360K, ok
                        ;          100=  360K in 1.2M, ok
                        ;          101=  1.2M in 1.2M, ok
                        ;          111=  720K in 720K, ok
                        ;            or 1.44M in 1.44M
                        ;         (state not used for 2.88)
dsk1_media_st db ?      ; Media state for diskette drive 1
                        ;  (see dsk0_media_st)
dsk0_start_st db ?      ; Starting state for drive 0
dsk1_start_st db ?      ; Starting state for drive 1
dsk0_cylinder db ?      ; Current track number for drive 0
dsk1_cylinder db ?      ; Current track number for drive 1
keybd_flags_3 db ?      ; Special keyboard type and mode
                        ;  bit 7 Reading ID of keyboard
                        ;      6 last char is 1st ID char
                        ;      5 force num lock
                        ;      4 101/102 key keyboard
                        ;      3 right alt key down
                        ;      2 right ctrl key down
                        ;      1 E0h hidden code last
                        ;      0 E1h hidden code last
keybd_flags_4 db ?      ; Keyboard Flags (advanced keybd)
                        ;   7      6       5     4  3 2 1 0
                        ; xmit   char   Resend  Ack      /
                        ; error was ID  Rec'd  Rec'd   LEDs
timer_waitoff dw ?      ; Ptr offset to wait done flag
timer_waitseg dw ?      ; Ptr segment to wait done flag
timer_clk_low dw ?      ; Timer low word, 1 microsecond clk
timer_clk_high dw ?     ; Timer high word
timer_clk_flag db ?     ; Timer flag 00h = post acknowledgd
                        ;            01h = busy
                        ;            80h = posted
lan_bytes db 7 dup(?)   ; Local area network bytes (7)
video_sav_tbl dd ?      ; Pointer to a save table of more
                        ; pointers for the video system
                        ;            SAVE TABLE
                        ;  offset type    pointer to
                        ;  ------ ---- --------------------
                        ;    0     dd  Video parameters
                        ;    4     dd  Parms save area
                        ;    8     dd  Alpha char set
                        ;   0Ch    dd  Graphics char set
                        ;   10h    dd  2nd save ptr table
                        ;   14h    dd  reserved (0:0)
                        ;   18h    dd  reserved (0:0)
                        ;
                        ;  2ND SAVE TABLE (from ptr above)
                        ;  offset type functions & pointers
                        ;  ------ ---- --------------------
                        ;    0     dw  Bytes in this table
                        ;    2     dd  Combination code tbl
                        ;    6     dd  2nd alpha char set
                        ;   0Ah    dd  user palette tbl
                        ;   0Eh    dd  reserved (0:0)
                        ;   12h    dd  reserved (0:0)
                        ;   16h    dd  reserved (0:0)
byte_4AC db 22h dup(?)
days_since1_80 dw ?     ; Days since 1-Jan-1980 counter
bdata ends


; Segment type: Pure data
PSP segment byte public 'DATA' use16
assume cs:PSP

loc_FF00:               ; Thanks to Ralf Brown for the following info!
int     20h             ; INT 20 instruction for CP/M CALL 0 program termination
FreeSeg dw ?            ; segment of first byte beyond memory allocated to program
byte_FF04 db ?          ; (DOS) unused filler
CPMCall5 db ?           ; CP/M CALL 5 service request (FAR CALL to absolute 000C0h)
CPM1stSegSize dw ?      ; CP/M compatibility--size of first segment for .COM files
word_FF08 dw ?          ; remainder of FAR JMP at 05h
Int22Vector dd ?        ; INT 22 termination address
Int23Vector dd ?        ; INT 23 control-Break handler address
Int24Vector dd ?        ; INT 24 critical error handler address
ParentPSPSeg dw ?       ; segment of parent PSP
JobFileTable db 14h dup(?) ; one byte per file handle, FFh=closed
EnviroBlkSeg dw ?       ; Segment of environment block
LastStack dd ?          ; proces's SS:SP on entry to last int 21h.
JFTEntries dw ?         ; the number of entries in the job file table.
JFTPtr dd ?             ; pointer to job file table
PrevPSPPtr dd ?         ; pointer to previous PSP
byte_FF3C db ?          ; DOS 4+ (DBCS) interim console flag
byte_FF3D db ?          ; (APPEND) TrueName flag
byte_FF3E db ?          ; (Novell NetWare) flag: next byte initialized if CEh (OS/2) capabilities flag
db ?                    ; (Novell NetWare) Novell task number if previous byte is CEh
db 2 dup(?)             ; DOS 5+ version to return on INT 21/AH=30h
dw ?                    ; (MSWindows3) selector of next PSP (PDB) in linked list
dw ?                    ; (MSWindows3) "PDB_Partition"
word_FF46 dw ?          ; (MSWindows3) "PDB_NextPDB"
byte_FF48 db ?          ; (MSWindows3) bit 0 set if non-Windows application (WINOLDAP)
byte_FF49 db 3 dup(?)   ; unused by DOS versions <= 6.00
dw ?                    ; (MSWindows3) "PDB_EntryStack"
db 2 dup(?)             ; unused by DOS versions <= 6.00
db 3 dup(?)             ; DOS 2+ service request (INT 21/RETF instructions)
db 2 dup(?)             ; unused in DOS versions <= 6.00
db 7 dup(?)             ; unused in DOS versions <= 6.00; can be used to make first FCB into an extended FCB
FirstDefaultFCB db 10h dup(?) ; first default FCB, filled in from first commandline argument overwrites second FCB if opened
SecondDefaultFCB db 10h dup(?) ; second default FCB, filled in from second commandline argument overwrites beginning of commandline if opened
db 4 dup(?)             ; unused
TailByte db ?           ; BYTE for length of tail, N BYTEs for the tail, followed by a BYTE containing 0Dh
aCommandLineTail db 7Fh dup(?)
PSP ends

; File Name   : D:\IDA\TC.EXE
; Format      : MS-DOS executable (EXE)
; Base Address: 1000h Range: 10000h-1F870h Loaded length: F050h
; Entry Point : 1000:C5C7

; Segment type: Pure code
seg001 segment byte public 'CODE' use16
assume cs:seg001
assume es:nothing, ss:nothing, ds:nothing, fs:nothing, gs:nothing
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    1
db    1
db    1
db    0
db    0
db    0
db    1
db    1
db    1
db    0
db    0
db    0
a0728891641 db '07/28/89   16:41'
TC_Addr1 dw 268h        ; these are the port base addresses where the transcopy board might be.
                        ; there are 8 adresses used, XX8h  XXFh
TC_Addr2 dw 2E8h
TC_Addr3 dw 368h
TC_Addr4 dw 3E8h
aSourceDrvLtr db 'A'
aTargetDrvLtr db 'B'
KeepTrkLngthFlag db 'N' ; Set by user input at first, by program later if needed.
CpyWkBitsFlag db 'N'    ; Set by user input at first, by program later if needed.
CopyXIDXFlag db 'N'     ; Set by user input at first, by program later if needed.
byte_10039 db 'N'
VerifyWrtFlag db 'N'    ; Set by user input at first, by program later if needed.
word_1003B dw 0
unk_1003D db    2
byte_1003E db 0Eh
EndOfCurrTrk dw 0       ; The offset of the end of the track currently being processed.
CurrTrackBufOfs dw 0    ; Offset of the track data for the track being processed.
byte_10043 db 2
word_10044 dw 0
db  20h
CurrentSide db 0
CurrentDrive db 0
CurrentCylinder db 0
DuplicatorPresent db 0  ; Disk duplicator present/in use?
db    0
CylndrBeingRead db 0
ClndrBeingWritten db 0
SourceDriveNumber db 0
TargetDriveNumber db 1
Cylinder db 0
CurrentHead db 0
SectorNumber db 1
SectorSize db 2
ReadLengthBytes dw 0
byte_10056 db 20h
db    0
db    0
word_10059 dw 0
byte_1005B db 0
word_1005C dw 7000h
word_1005E dw 9000h
KeepTrkLngth0 db 0      ; Keep track length option. y or n or lower # if range.
KeepTrkLngth1 db 0      ; Keep track length option. 00h or upper # if range.
CopyWkBits0 db 0        ; Copy weak bits option. y or n or lower # if range.
CopyWkBits1 db 0        ; Copy weak bits option. 00h or upper # if range.
CopyXIDX0 db 0          ; Copy across index option. y or n or lower # if range.
CopyXIDX1 db 0          ; Copy across index option. 00h or upper # if range.
byte_10066 db 0
db    0
byte_10068 db 0
byte_10069 db 0
word_1006A dw 0
db    0
db    0
VerifyWrite0 db 0       ; Verify Write option. y or n or lower # if range
byte_1006F db 0
db    0
db    0
word_10072 dw 0
TrackSkewDly1 dw 0      ; This word specifies how long to wait after index to begin
                        ; writing the track.
db    0
db    0
dword_10078 dd 0
db    0
byte_1007D db 0
DuplicatorReturn db 0   ; last return code recieved from disk duplicator
byte_1007F db 0
NumGoodDsks dw 0
NumBadDsks dw 0
word_10084 dw 7FFFh
byte_10086 db 0
BiosModelByte db 0      ; FCh=AT,FDh=PCjr,FEh=XT,FF=PC
db 0, 2
byte_1008A db 0
TrackBufSeg dw 0
TrackBufOfs dw 0
CurrTrackBufSeg db    0 ; The segment of the track data currently being processed.
db 0
word_10091 dw 0
word_10093 dw 0
byte_10095 db 0
byte_10096 db 'R'
byte_10097 db 0
DuplicatorCmdByte db 0  ; Last byte sent to disk duplicator
byte_10099 db 0
NK_SwitchUsed db 0FFh   ; Disables automatic keep track length features if 0.
byte_1009B db 0
db    0
db    0
db    0
word_1009F dw 0
word_100A1 dw 0
word_100A3 dw 0
word_100A5 dw 0
DskTekExeAttr dw 0      ; file attributes of b:disktech.exe
byte_100A9 db 0
OldInt24Seg dw 0
OldInt24Off dw 0
word_100AE dw 0
word_100B0 dw 0
C_SwitchUsed db 0
byte_100B3 db 0
CurrentOperation db 0   ; Read=r write=w analyze=a
byte_100B5 db 0
byte_100B6 db 0
byte_100B7 db 0
DMACount dw 34FFh
DiskType db 7           ; This byte and following bytes appear at offset 100h in saved image file.
                        ; 00h = Unknown
                        ; 01h = Unknown
                        ; 02h = Unknown
                        ; 03h = Unknown
                        ; 04h = Apple
                        ; 05h = FM
                        ; 06h = Unknown
                        ; 07h = MFM
                        ; 08h = Amiga
                        ; Other values unknown so far.
StartingCylinder db 0
EndingCylinder db 27h
NumberOfSides db 2
TrackIncrement db 1
TrackSkewTbl dw 100h dup(1111h) ; 1 word per track, up to 256 tracks.
                        ; Sets position of track relative to index.
                        ; Changing this value rotates the entire track but does not truncate.
TrackOffsTbl dw 100h dup(2222h) ; 1 word per track, up to 256 tracks.
                        ; Points to track start in image.
                        ; Last track before 64K boundary zero padded
                        ; so that next track starts on 64K boundary.
TrackLngthTbl dw 100h dup(3333h) ; Track length in bytes.
                        ; 1 word per track, up to 256 tracks.
                        ; Multiply by 8 to get track length in
                        ; bits as displayed on screen.
TrackTypeTable dw 100h dup(4444h) ; 2 bytes per track, up to 256 tracks.
                        ; High byte same format as DiskType, 07h=MFM, 08h=Amiga, Etc.
                        ; Low byte track options:
                        ; Bit 0 1=Keep track length.
                        ; Bit 1 1=Copy across index.
                        ; Bit 2 1=Copy weak bits.
                        ; Bit 3 1=Verify write.
                        ; Bits 4-7 Unknown options automatically set on unusual
                        ; tracks. All 0 for normal tracks.
TrackDataBuffer db 2002h dup(0) ; The actual track data being read or written goes here



_Main proc near
push    ds
push    cs
pop     ds
assume ds:seg001
mov     ah, 0Dh
int     21h             ; DOS - DISK RESET
mov     ColorMono, 0
int     11h             ; EQUIPMENT DETERMINATION
                        ; Return: AX = equipment flag bits
and     ax, 30h
cmp     ax, 30h ; '0'
jz      short loc_128DC
mov     ColorMono, 1    ; color

loc_128DC:
call    ClearScreen
push    ds
mov     ax, 0FFFFh
mov     ds, ax
assume ds:nothing
mov     bx, 0Eh
mov     al, [bx]
pop     ds
assume ds:nothing
mov     ds:BiosModelByte, al ; FCh=AT,FDh=PCjr,FEh=XT,FF=PC
mov     dl, 0
mov     dh, 1
mov     al, 0
push    ds
call    sub_1AFAC
push    ax
mov     cs:word_10093, cx
call    sub_1B12A
pop     ax
pop     ds
cmp     al, 0
jz      short loc_12910
mov     ax, MsgOffs.field_0 ; "Insufficient memory"
call    DisplayString
jmp     loc_12B02

loc_12910:              ; Set timer 0 16 bit mode.
mov     al, 36h ; '6'
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
mov     al, 0
out     40h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
out     40h, al         ; Timer 8253-5 (AT: 8254.2).
mov     ah, 19h
int     21h             ; DOS - GET DEFAULT DISK NUMBER
mov     dl, al
mov     ah, 0Eh
int     21h             ; DOS - SELECT DISK
                        ; DL = new default drive number (0 = A, 1 = B, etc.)
                        ; Return: AL = number of logical drives
dec     al
mov     ds:byte_100B6, al
int     11h             ; EQUIPMENT DETERMINATION
                        ; Return: AX = equipment flag bits
shl     ax, 1
shl     ax, 1
and     ah, 3
inc     ah
mov     ds:byte_10043, ah
mov     ds:aSourceDrvLtr, 'A'
mov     ds:aTargetDrvLtr, 'B'
cmp     ah, 1
jnz     short loc_12950
mov     ds:aTargetDrvLtr, 'A'

loc_12950:
mov     al, 'T'
call    DuplicatorCommand
mov     ds:DuplicatorReturn, al
cmp     ds:DuplicatorReturn, 0
jz      short loc_1296F
cmp     ds:word_10093, 13h
jnb     short loc_1296F
mov     ax, MsgOffs.field_2
call    DisplayString
jmp     loc_12B02

loc_1296F:
call    SetDefaultOptions
call    GetCmdLnArgs
jnb     short loc_12980
mov     ax, MsgOffs.field_2C
call    DisplayString
jmp     loc_12B02

loc_12980:
call    GetTC_Port_DMA
jnb     short loc_1298E
mov     ax, MsgOffs.field_2B
call    DisplayString
jmp     loc_12B02

loc_1298E:
cmp     ds:C_SwitchUsed, 0
jz      short loc_129A1
mov     ax, MsgOffs.field_2F
call    DisplayString
call    GetKey
call    ClearScreen

loc_129A1:
mov     ax, MsgOffs.field_0Eh
call    DisplayString
cmp     ds:DuplicatorReturn, 0FFh
jz      short loc_129C7 ; skip important message if duplicator present
cmp     ds:DuplicatorPresent, 0
jnz     short loc_129C7
mov     ax, MsgOffs.field_23
call    DisplayString
mov     ax, MsgOffs.field_2D
call    DisplayString
call    GetKey
call    sub_17BB5

loc_129C7:
mov     al, 43h ; 'C'
call    DuplicatorCommand

loc_129CC:
mov     al, 54h ; 'T'
call    DuplicatorCommand
mov     ds:DuplicatorReturn, al
call    sub_1331E
mov     dx, 400h
call    SetCursorPos
mov     ax, MsgOffs.field_14
call    DisplayString
call    DisplayDMA_Port
call    sub_12E04
jnb     short loc_12A0A
mov     ds:DuplicatorPresent, 0
cmp     al, 0FFh
jnz     short loc_129FD
mov     ax, MsgOffs.field_49
call    sub_132D3
jmp     loc_12AF1

loc_129FD:
cmp     ah, 3Ch ; '<'
jz      short loc_12A43
cmp     ah, 44h ; 'D'
jnz     short loc_129CC
jmp     loc_12AFC

loc_12A0A:
cmp     ds:DuplicatorPresent, 0
jnz     short loc_12A43
call    sub_12F2E
jnb     short loc_12A23
cmp     ah, 3Ch ; '<'
jz      short loc_12A43
cmp     ah, 44h ; 'D'
jnz     short loc_129CC
jmp     loc_12AFC

loc_12A23:
call    sub_17BBE
mov     ax, MsgOffs.field_22
call    DisplayString

loc_12A2C:
call    GetKey
cmp     ah, 3Ch ; '<'
jz      short loc_12A43
cmp     ah, 1Bh
jnz     short loc_12A3B
jmp     short loc_129CC

loc_12A3B:
cmp     ah, 44h ; 'D'
jnz     short loc_12A2C
jmp     loc_12AFC

loc_12A43:
call    SetOptionFlags
mov     ds:NumBadDsks, 0
mov     ds:NumGoodDsks, 0
cmp     ds:byte_100B7, 2
jnz     short loc_12A5E
mov     ds:DuplicatorReturn, 0

loc_12A5E:
cmp     ds:DuplicatorReturn, 0
jz      short loc_12A68
call    DispGoodBadDsks

loc_12A68:
call    ClrMessageWndw
mov     dx, 400h
call    SetCursorPos
mov     ax, MsgOffs.field_14
call    DisplayString
call    DisplayTracks   ; puts track display at bottom of screen
call    ReadWrite
mov     ds:DuplicatorPresent, 0
jnb     short loc_12A9A
cmp     al, 0
jz      short loc_12AA7
push    ax
call    sub_17BBE
mov     dx, 732h
call    SetCursorPos
pop     ax
mov     ah, 0
add     al, MsgOffs.field_12
jmp     short loc_12AEE
align 2

loc_12A9A:
call    sub_13AA7
cmp     ds:DuplicatorReturn, 0FFh
jz      short loc_12AA7
call    Beep

loc_12AA7:
mov     dx, ds:NumGoodDsks
cmp     dx, ds:word_10084
jnb     short loc_12AFC
cmp     ds:DuplicatorReturn, 0
jnz     short loc_12AE5
cmp     ds:byte_13D11, 0FFh
jnz     short loc_12AE5
cmp     ds:F_SwitchUsed, 0FFh
jnz     short loc_12AD2
mov     dx, 700h
call    SetCursorPos
mov     ax, MsgOffs.field_46
jmp     short loc_12AEE
align 2

loc_12AD2:
cmp     ds:byte_13D1C, 0FFh
jnz     short loc_12AE5
mov     dx, 700h
call    SetCursorPos
mov     ax, MsgOffs.field_47
jmp     short loc_12AEE
db 90h

loc_12AE5:
mov     dx, 732h
call    SetCursorPos
mov     ax, MsgOffs.field_F

loc_12AEE:
call    DisplayString

loc_12AF1:
call    GetKey
cmp     ah, 44h ; 'D'
jz      short loc_12AFC
jmp     loc_129CC

loc_12AFC:
call    sub_16865
call    ClearScreen

loc_12B02:
call    sub_1B12A
pop     ds
retn
_Main endp




DuplicatorCommand proc near
mov     ds:DuplicatorCmdByte, al

loc_12B0A:
call    DuplicatorVector
jnb     short loc_12B66

loc_12B0F:
push    ax
mov     dx, 400h
call    SetCursorPos
mov     ax, MsgOffs.field_14
call    DisplayString
mov     dx, 732h
call    SetCursorPos
pop     ax
push    ax
add     ax, MsgOffs.field_31
call    DisplayString
call    GetKey
call    ClrMessageWndw
cmp     al, 1Bh
pop     ax
jz      short loc_12B68
cmp     ax, 6
jnb     short loc_12B66
cmp     ax, 0
jnz     short loc_12B4F
mov     al, ds:DuplicatorCmdByte
cmp     al, 'X'
jnz     short loc_12B0A
mov     al, 'I'
call    DuplicatorVector
mov     al, 'X'
jmp     short loc_12B0A

loc_12B4F:
mov     al, 'C'
call    DuplicatorVector
jb      short loc_12B0F
mov     al, ds:DuplicatorCmdByte
cmp     al, 'X'
jnz     short loc_12B66
mov     al, 'I'
call    DuplicatorVector
mov     al, 'X'
jmp     short loc_12B0A

loc_12B66:
clc
retn

loc_12B68:
stc
retn
DuplicatorCommand endp




GetCmdLnArgs proc near
push    es
mov     ax, cs
sub     ax, 10h
mov     es, ax
assume es:PSP
mov     ds:word_10084, 7FFFh
mov     ds:DuplicatorPresent, 0
mov     ds:byte_10099, 0FFh
mov     al, es:FirstDefaultFCB
cmp     al, 0
jz      short loc_12BAB
add     al, 40h ; '@'
mov     ds:aSourceDrvLtr, al
mov     ds:aTargetDrvLtr, al
mov     al, es:SecondDefaultFCB
cmp     al, 0
jz      short loc_12B9F
add     al, 40h ; '@'
mov     ds:aTargetDrvLtr, al

loc_12B9F:
cmp     ds:DuplicatorReturn, 0
jz      short loc_12BAB
mov     ds:DuplicatorPresent, 0FFh

loc_12BAB:
mov     si, offset aCommandLineTail

loc_12BAE:
call    GetCmdlnByte
jb      short NoArgs
cmp     al, '/'         ; is it a switch?
jnz     short loc_12BAE
jmp     short loc_12BC5
align 2

loc_12BBA:
call    GetCmdlnByte
jnb     short loc_12BC5

NoArgs:
jmp     loc_12D68

loc_12BC2:
jmp     loc_12D9C

loc_12BC5:
cmp     al, '/'
jnz     short loc_12BC2
call    GetCmdlnByte
cmp     al, 'B'
jnz     short loc_12BE0
call    GetCmdlnByte
jb      short loc_12BC2
cmp     al, 'W'
jnz     short loc_12BC2
mov     ds:ColorMono, 0
jmp     short loc_12BBA

loc_12BE0:
cmp     al, 'C'
jnz     short loc_12BEB
mov     ds:C_SwitchUsed, 0FFh
jmp     short loc_12BAE

loc_12BEB:
cmp     al, '1'
jnz     short loc_12BF6
mov     ds:NumberOfSides, 1
jmp     short loc_12BBA

loc_12BF6:
cmp     al, '2'
jnz     short loc_12C01
mov     ds:NumberOfSides, 2
jmp     short loc_12BBA

loc_12C01:
cmp     al, 'W'
jnz     short loc_12C0B
mov     bx, offset CopyWkBits0
jmp     loc_12CEF

loc_12C0B:
cmp     al, 'K'
jnz     short loc_12C15
mov     bx, offset KeepTrkLngth0
jmp     loc_12CEF

loc_12C15:
cmp     al, 'A'
jnz     short loc_12C1F
mov     bx, offset CopyXIDX0
jmp     loc_12CEF

loc_12C1F:
cmp     al, 'V'
jnz     short loc_12C29
mov     bx, offset VerifyWrite0
jmp     loc_12CEF

loc_12C29:
cmp     al, 'S'
jnz     short loc_12C33
mov     bx, offset StartingCylinder
jmp     loc_12CE3

loc_12C33:
cmp     al, 'E'
jnz     short loc_12C3D
mov     bx, offset EndingCylinder
jmp     loc_12CE3

loc_12C3D:
cmp     al, 'I'
jnz     short loc_12C47
mov     bx, offset TrackIncrement
jmp     loc_12CE3

loc_12C47:
cmp     al, 'N'
jnz     short loc_12C91
call    GetCmdlnByte
jb      short loc_12CB4
cmp     al, '='
jnz     short loc_12C59
call    GetCmdlnByte
jb      short loc_12CB4

loc_12C59:
cmp     al, 'K'
jz      short loc_12C89
call    sub_12DF6
jb      short loc_12CB4
mov     ah, 0
mov     ds:word_10084, ax

loc_12C67:
call    GetCmdlnByte
jb      short loc_12CE0
call    sub_12DF6
jnb     short loc_12C74
jmp     loc_12BC5

loc_12C74:
mov     ah, 0
push    ax
mov     ax, ds:word_10084
mov     cx, 0Ah
mul     cx
mov     ds:word_10084, ax
pop     ax
add     ds:word_10084, ax
jmp     short loc_12C67

loc_12C89:
mov     ds:NK_SwitchUsed, 0
jmp     loc_12BBA

loc_12C91:
cmp     al, 'P'
jnz     short loc_12CB7
call    GetCmdlnByte
jb      short loc_12CB4
cmp     al, '1'
jb      short loc_12CB4
cmp     al, '4'
ja      short loc_12CB4
sub     al, '1'
mov     bl, al
mov     bh, 0
shl     bx, 1
mov     ax, ds:TC_Addr1[bx]
mov     ds:TC_Port_Base, ax
jmp     loc_12BBA

loc_12CB4:
jmp     loc_12D9C

loc_12CB7:
cmp     al, 'T'
jnz     short loc_12CD1
call    GetCmdlnByte
jb      short loc_12CB4
call    sub_12DEA
jb      short loc_12CB4
shl     al, 1
shl     al, 1
shl     al, 1
mov     ds:byte_10099, al
jmp     loc_12BBA

loc_12CD1:
cmp     al, 'F'
jnz     short loc_12CDD
mov     ds:F_SwitchUsed, 80h ; 'Ç'
jmp     loc_12BBA

loc_12CDD:
jmp     loc_12BAE

loc_12CE0:
jmp     loc_12D68

loc_12CE3:
call    GetCmdlnByte
jb      short loc_12CB4
cmp     al, '='
jnz     short loc_12D3F
jmp     short loc_12D3A
db 90h

loc_12CEF:
mov     byte ptr [bx], 'y'
call    GetCmdlnByte
jb      short loc_12D68
cmp     al, '='
jnz     short loc_12D00
call    GetCmdlnByte
jb      short loc_12D68

loc_12D00:
call    sub_12DEA
jnb     short loc_12D08
jmp     loc_12BC5

loc_12D08:
mov     dl, al
mov     [bx], dl
mov     [bx+1], dl
call    GetCmdlnByte
jb      short loc_12D68
call    sub_12DEA
jb      short loc_12D32
mov     cl, 4
shl     dl, cl
or      dl, al
cmp     dl, ds:byte_10096
jbe     short loc_12D28
jmp     short loc_12D9C
align 2

loc_12D28:
mov     [bx], dl
mov     [bx+1], dl
call    GetCmdlnByte
jb      short loc_12D68

loc_12D32:
cmp     al, '-'
jz      short loc_12D39

loc_12D36:
jmp     loc_12BC5

loc_12D39:
inc     bx

loc_12D3A:
call    GetCmdlnByte
jb      short loc_12D68

loc_12D3F:
call    sub_12DEA
jb      short loc_12D9C
mov     dl, al
mov     [bx], dl
call    GetCmdlnByte
jb      short loc_12D68
call    sub_12DEA
jb      short loc_12D36
mov     cl, 4
shl     dl, cl
or      dl, al
cmp     dl, ds:byte_10096
jbe     short loc_12D61
jmp     short loc_12D9C
db 90h

loc_12D61:
mov     [bx], dl
call    GetCmdlnByte
jnb     short loc_12D36

loc_12D68:
mov     al, ds:StartingCylinder
cmp     al, 28h ; '('
jbe     short loc_12D79
cmp     ds:EndingCylinder, 28h ; '('
jnz     short loc_12D79
mov     ds:EndingCylinder, al

loc_12D79:
cmp     al, ds:EndingCylinder
ja      short loc_12D9C
cmp     ds:TrackIncrement, 1
jz      short loc_12DA0
mov     al, ds:EndingCylinder
sub     al, ds:StartingCylinder
jz      short loc_12DA0
cmp     ds:TrackIncrement, 0
jz      short loc_12D9C
cmp     al, ds:TrackIncrement
ja      short loc_12DA0

loc_12D9C:
stc
jmp     short loc_12DCE
align 2

loc_12DA0:
mov     al, ds:CopyWkBits0
cmp     al, ds:byte_10096
ja      short loc_12DAF
cmp     al, ds:CopyWkBits1
ja      short loc_12D9C

loc_12DAF:
mov     al, ds:KeepTrkLngth0
cmp     al, ds:byte_10096
ja      short loc_12DBE
cmp     al, ds:KeepTrkLngth1
ja      short loc_12D9C

loc_12DBE:
mov     al, ds:CopyXIDX0
cmp     al, ds:byte_10096
ja      short loc_12DCD
cmp     al, ds:CopyXIDX1
ja      short loc_12D9C

loc_12DCD:
clc

loc_12DCE:
pop     es
assume es:nothing
retn
GetCmdLnArgs endp




GetCmdlnByte proc near
mov     al, es:[si]
inc     si
cmp     al, ' '
jz      short GetCmdlnByte
cmp     al, 'a'
jb      short loc_12DE2
cmp     al, 'z'
ja      short loc_12DE2
and     al, 0DFh

loc_12DE2:
cmp     al, 0Dh
jz      short loc_12DE8
clc
retn

loc_12DE8:
stc
retn
GetCmdlnByte endp




sub_12DEA proc near
cmp     al, 'F'
ja      short loc_12E02
cmp     al, 'A'
jb      short sub_12DF6
sub     al, '7'
clc
retn
sub_12DEA endp




sub_12DF6 proc near
cmp     al, '9'
ja      short loc_12E02
cmp     al, '0'
jb      short loc_12E02
sub     al, '0'
clc
retn

loc_12E02:
stc
retn
sub_12DF6 endp




sub_12E04 proc near
mov     ds:byte_10095, 0Dh
call    sub_1B12A
cmp     ds:DuplicatorPresent, 0
jz      short loc_12E16
jmp     loc_12ECC

loc_12E16:
mov     dx, 400h
call    SetCursorPos
mov     ax, MsgOffs.field_0B
call    DisplayString
call    ReadCursorPos
mov     ds:word_1003B, dx
mov     al, ds:aSourceDrvLtr
mov     ah, 0
push    ax
call    DisplayChar
mov     ax, MsgOffs.field_1C
call    sub_132D3
mov     dx, 744h
call    SetCursorPos
mov     al, ds:byte_1949A
mov     ds:VideoAttribute, al
mov     al, ds:byte_100B6
add     al, 'A'
call    DisplayChar
mov     al, ds:byte_1949B
mov     ds:VideoAttribute, al
mov     dx, ds:word_1003B
call    SetCursorPos
pop     ax
call    sub_17C9B
mov     ds:byte_10095, ah
jnb     short loc_12E66
jmp     loc_12F26

loc_12E66:
mov     ds:aSourceDrvLtr, al
mov     dx, ds:word_1003B
call    SetCursorPos
call    DisplayChar
cmp     ah, '<'
jz      short loc_12ECC
mov     ax, MsgOffs.field_0C
call    DisplayString
call    ReadCursorPos
mov     ds:word_1003B, dx
mov     ah, 0
mov     al, ds:aTargetDrvLtr
push    ax
call    DisplayChar
mov     ax, MsgOffs.field_1E
call    sub_132D3
mov     dx, 744h
call    SetCursorPos
mov     al, ds:byte_1949A
mov     ds:VideoAttribute, al
mov     al, ds:byte_100B6
add     al, 'A'
call    DisplayChar
mov     al, ds:byte_1949B
mov     ds:VideoAttribute, al
mov     dx, ds:word_1003B
call    SetCursorPos
pop     ax
call    sub_17C9B
jb      short loc_12F26
mov     ds:byte_10095, ah
mov     ds:aTargetDrvLtr, al
mov     dx, ds:word_1003B
call    SetCursorPos
call    DisplayChar

loc_12ECC:
mov     al, ds:aSourceDrvLtr
sub     al, 'A'
mov     ds:SourceDriveNumber, al
mov     al, ds:aTargetDrvLtr
sub     al, 'A'
mov     ds:TargetDriveNumber, al
mov     dl, ds:SourceDriveNumber
mov     dh, ds:TargetDriveNumber
mov     al, ds:DuplicatorReturn
call    sub_1AAFB
mov     ds:byte_100B7, dh
cmp     al, 0
jz      short loc_12EFC
push    ax
call    sub_1B12A
pop     ax
mov     ah, 1Bh
jmp     short loc_12F26
align 2

loc_12EFC:
mov     ds:byte_10096, 'R'
cmp     dh, 1
jnz     short loc_12F14
call    sub_1AB90
jb      short loc_12F2A
mov     al, ds:EndingCylinder
mov     ds:byte_10096, al
call    sub_1331E

loc_12F14:
mov     ah, ds:byte_10095
cmp     ah, '<'
jz      short loc_12F26
cmp     ah, 'D'
jz      short loc_12F26
mov     al, 0
clc
retn

loc_12F26:
mov     al, 1
stc
retn

loc_12F2A:
mov     al, 0FFh
stc
retn
sub_12E04 endp




sub_12F2E proc near
mov     dx, 600h
call    SetCursorPos
mov     ax, MsgOffs.field_3
call    DisplayString
call    ReadCursorPos
mov     ds:word_1003B, dx
mov     ah, 0
mov     al, ds:StartingCylinder
push    ax
call    DisplayHexTrack
mov     ax, MsgOffs.field_1E
call    sub_132D3
mov     dx, ds:word_1003B
call    SetCursorPos
pop     ax
mov     bh, ds:byte_10096
mov     bl, 0
call    sub_17CCA
jb      short loc_12FC9
mov     ds:StartingCylinder, al
mov     dx, ds:word_1003B
call    SetCursorPos
call    DisplayHexTrack
cmp     ah, 3Ch ; '<'
stc
jz      short loc_12FC9
mov     ax, MsgOffs.field_4
call    DisplayString
call    ReadCursorPos
mov     ds:word_1003B, dx
mov     ah, 0
mov     al, ds:EndingCylinder
push    ax
call    DisplayHexTrack
mov     ax, MsgOffs.field_1F
call    sub_132D3
mov     dx, 833h
call    SetCursorPos
mov     al, ds:byte_1949A
mov     ds:VideoAttribute, al
mov     al, ds:StartingCylinder
call    DisplayHexTrack
mov     dx, 933h
call    SetCursorPos
mov     al, ds:StartingCylinder
call    DisplayHexTrack
mov     al, ds:byte_1949B
mov     ds:VideoAttribute, al
mov     dx, ds:word_1003B
call    SetCursorPos
pop     ax
mov     bh, ds:byte_10096
mov     bl, ds:StartingCylinder
call    sub_17CCA

loc_12FC9:
jb      short loc_13034
mov     ds:EndingCylinder, al
mov     dx, ds:word_1003B
call    SetCursorPos
call    DisplayHexTrack
cmp     ah, 3Ch ; '<'
stc
jz      short loc_13034
mov     ax, MsgOffs.field_5
call    DisplayString
call    ReadCursorPos
mov     ds:word_1003B, dx
mov     al, 1
mov     bh, ds:EndingCylinder
sub     bh, ds:StartingCylinder
jz      short loc_13036
cmp     bh, 1
jz      short loc_13036
mov     bl, 1
mov     ah, 0
mov     al, ds:TrackIncrement
push    ax
call    DisplayHexTrack
mov     ax, MsgOffs.field_20
call    sub_132D3
mov     dx, 83Fh
call    SetCursorPos
mov     al, ds:byte_1949A
mov     ds:VideoAttribute, al
mov     al, ds:EndingCylinder
sub     al, ds:StartingCylinder
call    DisplayHexTrack
mov     al, ds:byte_1949B
mov     ds:VideoAttribute, al
mov     dx, ds:word_1003B
call    SetCursorPos
pop     ax
call    sub_17CCA

loc_13034:
jb      short loc_13074

loc_13036:
mov     ds:TrackIncrement, al
mov     dx, ds:word_1003B
call    SetCursorPos
call    DisplayHexTrack
cmp     ah, 3Ch ; '<'
jz      short loc_13074
mov     ax, MsgOffs.field_D
call    DisplayString
call    ReadCursorPos
mov     ds:word_1003B, dx
mov     al, ds:NumberOfSides
or      al, '0'
call    DisplayChar
mov     ax, MsgOffs.field_21
call    sub_132D3
mov     dx, ds:word_1003B
call    SetCursorPos
mov     ah, 0
mov     al, ds:NumberOfSides
call    sub_17C89
jnb     short loc_13077

loc_13074:
jmp     loc_13177

loc_13077:
and     al, 0Fh
mov     ds:NumberOfSides, al
mov     dx, ds:word_1003B
call    SetCursorPos
or      al, '0'
call    DisplayChar
cmp     ah, '<'
jz      short loc_13074
mov     al, 0Dh
call    DisplayChar
mov     al, 0Ah
call    DisplayChar
call    ReadCursorPos
push    dx
mov     ax, MsgOffs.field_48
call    sub_132D3
pop     dx
call    SetCursorPos
mov     ax, MsgOffs.field_6
call    DisplayString
call    ReadCursorPos
mov     ds:word_1003B, dx
mov     al, ds:KeepTrkLngth0
mov     bl, ds:KeepTrkLngth1
mov     ah, bl
push    ax
call    sub_17DF9
mov     dx, ds:word_1003B
call    SetCursorPos
pop     ax
mov     bh, ds:EndingCylinder
mov     bl, ds:StartingCylinder
call    sub_17D41
jb      short loc_13074
mov     ds:KeepTrkLngth0, al
mov     ds:KeepTrkLngth1, bl
mov     dx, ds:word_1003B
call    SetCursorPos
call    sub_17DF9
cmp     ah, '<'
jz      short loc_13074
mov     ax, MsgOffs.field_7
call    DisplayString
call    ReadCursorPos
mov     ds:word_1003B, dx
mov     al, ds:CopyWkBits0
mov     bl, ds:CopyWkBits1
mov     ah, bl
push    ax
call    sub_17DF9
mov     dx, ds:word_1003B
call    SetCursorPos
pop     ax
mov     bh, ds:EndingCylinder
mov     bl, ds:StartingCylinder
call    sub_17D41
jb      short loc_13177
mov     ds:CopyWkBits0, al
mov     ds:CopyWkBits1, bl
mov     dx, ds:word_1003B
call    SetCursorPos
call    sub_17DF9
cmp     ah, '<'
jz      short loc_13177
mov     ax, MsgOffs.field_8
call    DisplayString
call    ReadCursorPos
mov     ds:word_1003B, dx
mov     al, ds:CopyXIDX0
mov     bl, ds:CopyXIDX1
mov     ah, bl
push    ax
call    sub_17DF9
mov     dx, ds:word_1003B
call    SetCursorPos
pop     ax
mov     bh, ds:EndingCylinder
mov     bl, ds:StartingCylinder
call    sub_17D41
jb      short loc_13177
mov     ds:CopyXIDX0, al
mov     ds:CopyXIDX1, bl
mov     dx, ds:word_1003B
call    SetCursorPos
call    sub_17DF9
cmp     ah, '<'
jz      short loc_13177
jmp     short loc_13179
db 90h

loc_13177:
stc
retn

loc_13179:
mov     ax, MsgOffs.field_1
call    DisplayString
call    ReadCursorPos
mov     ds:word_1003B, dx
mov     al, ds:VerifyWrite0
mov     bl, ds:byte_1006F
mov     ah, bl
push    ax
call    sub_17DF9
mov     dx, ds:word_1003B
call    SetCursorPos
pop     ax
mov     bh, ds:EndingCylinder
mov     bl, ds:StartingCylinder
call    sub_17D41
jb      short loc_13177
mov     ds:VerifyWrite0, al
mov     ds:byte_1006F, bl
mov     dx, ds:word_1003B
call    SetCursorPos
call    sub_17DF9
cmp     ah, '<'
jz      short loc_13177
call    ClrMessageWndw
clc
retn
sub_12F2E endp



; This function presets the internal program switches from user input.

SetOptionFlags proc near
mov     ds:CurrentCylinder, 0
mov     ds:CurrentSide, 0

loc_131CD:
mov     al, ds:CurrentCylinder
mov     ds:KeepTrkLngthFlag, 'Y'
mov     ah, ds:KeepTrkLngth0
cmp     ah, 'y'
jz      short loc_131F7
mov     ds:KeepTrkLngthFlag, 'N'
cmp     ah, 'n'
jz      short loc_131F7
cmp     ah, al
ja      short loc_131F7
cmp     ds:KeepTrkLngth1, al
jb      short loc_131F7
mov     ds:KeepTrkLngthFlag, 'Y'

loc_131F7:
mov     ds:CpyWkBitsFlag, 'Y'
mov     ah, ds:CopyWkBits0
cmp     ah, 'y'
jz      short loc_1321E
mov     ds:CpyWkBitsFlag, 'N'
cmp     ah, 'n'
jz      short loc_1321E
cmp     ah, al
ja      short loc_1321E
cmp     ds:CopyWkBits1, al
jb      short loc_1321E
mov     ds:CpyWkBitsFlag, 'Y'

loc_1321E:
mov     ds:CopyXIDXFlag, 'Y'
mov     ah, ds:CopyXIDX0
cmp     ah, 'y'
jz      short loc_13245
mov     ds:CopyXIDXFlag, 'N'
cmp     ah, 'n'
jz      short loc_13245
cmp     ah, al
ja      short loc_13245
cmp     ds:CopyXIDX1, al
jb      short loc_13245
mov     ds:CopyXIDXFlag, 'Y'

loc_13245:
mov     ds:VerifyWrtFlag, 'Y'
mov     ah, ds:VerifyWrite0
cmp     ah, 'y'
jz      short loc_1326C
mov     ds:VerifyWrtFlag, 'N'
cmp     ah, 'n'
jz      short loc_1326C
cmp     ah, al
ja      short loc_1326C
cmp     ds:byte_1006F, al
jb      short loc_1326C
mov     ds:VerifyWrtFlag, 'Y'

loc_1326C:
mov     al, 0
cmp     ds:KeepTrkLngthFlag, 'N'
jz      short loc_13277
or      al, 1

loc_13277:
cmp     ds:CopyXIDXFlag, 'N'
jz      short loc_13280
or      al, 2

loc_13280:
cmp     ds:CpyWkBitsFlag, 'N'
jz      short loc_13289
or      al, 4

loc_13289:
cmp     ds:VerifyWrtFlag, 'N'
jz      short loc_13292
or      al, 8

loc_13292:
cmp     ds:byte_10039, 'N'
jz      short loc_1329B
or      al, 10h

loc_1329B:
mov     ah, 0
call    GetTrkDatOfs
cmp     ds:byte_100B7, 1
jnz     short loc_132AD
or      al, 0F7h
and     ax, ds:TrackTypeTable[bx]

loc_132AD:
mov     byte ptr ds:TrackTypeTable[bx], al
inc     ds:CurrentSide
cmp     ds:CurrentSide, 1
jnz     short loc_132BF

loc_132BC:
jmp     loc_131CD

loc_132BF:
mov     ds:CurrentSide, 0
inc     ds:CurrentCylinder
mov     al, ds:CurrentCylinder
cmp     al, ds:byte_10096
jb      short loc_132BC
clc
retn
SetOptionFlags endp




sub_132D3 proc near
push    ax
call    ClrMessageWndw
mov     dx, 700h
call    SetCursorPos
pop     ax
call    DisplayString
retn
sub_132D3 endp




ClrMessageWndw proc near
pushf
push    ax
push    dx
mov     dx, 700h
call    SetCursorPos
mov     ax, MsgOffs.field_17
call    DisplayString
pop     dx
pop     ax
popf
retn
ClrMessageWndw endp




SetDefaultOptions proc near
mov     ds:StartingCylinder, 0
mov     ds:EndingCylinder, 28h ; '('
mov     ds:TrackIncrement, 1
mov     ds:NumberOfSides, 2
mov     ds:KeepTrkLngth0, 'n'
mov     ds:CopyWkBits0, 'n'
mov     ds:CopyXIDX0, 'y'
mov     ds:VerifyWrite0, 'y'
retn
SetDefaultOptions endp




sub_1331E proc near
call    sub_17BB5
mov     ax, MsgOffs.field_B
call    DisplayString
mov     al, ds:aSourceDrvLtr
call    DisplayChar
mov     ax, MsgOffs.field_C
call    DisplayString
mov     al, ds:aTargetDrvLtr
call    DisplayChar
mov     ax, MsgOffs.field_2
call    DisplayString
mov     al, ds:StartingCylinder
call    DisplayHexTrack
mov     ax, MsgOffs.field_4
call    DisplayString
mov     al, ds:EndingCylinder
call    DisplayHexTrack
mov     ax, MsgOffs.field_5
call    DisplayString
mov     al, ds:TrackIncrement
call    DisplayHexTrack
mov     ax, MsgOffs.field_D
call    DisplayString
mov     al, ds:NumberOfSides
or      al, '0'
call    DisplayChar
mov     al, 0Dh
call    DisplayChar
mov     al, 0Ah
call    DisplayChar
mov     ax, MsgOffs.field_6
call    DisplayString
mov     al, ds:KeepTrkLngth0
mov     bl, ds:KeepTrkLngth1
call    sub_17DF9
mov     ax, MsgOffs.field_7
call    DisplayString
mov     al, ds:CopyWkBits0
mov     bl, ds:CopyWkBits1
call    sub_17DF9
mov     ax, MsgOffs.field_8
call    DisplayString
mov     al, ds:CopyXIDX0
mov     bl, ds:CopyXIDX1
call    sub_17DF9
mov     ax, MsgOffs.field_1
call    DisplayString
mov     al, ds:VerifyWrite0
mov     bl, ds:byte_1006F
call    sub_17DF9
call    sub_17BBE
mov     ax, MsgOffs.field_A
call    DisplayString
mov     dx, 400h
call    SetCursorPos
mov     ax, MsgOffs.field_14
call    DisplayString
retn
sub_1331E endp



; Performs all selected read/write operations.

ReadWrite proc near
mov     al, ds:StartingCylinder
mov     ds:CylndrBeingRead, al
mov     ds:ClndrBeingWritten, al
mov     ds:CurrentCylinder, al
mov     ds:byte_167D5, 0
mov     ds:byte_13D11, 0
mov     ds:byte_167D4, 0
mov     ds:byte_100B3, 7Eh ; '~'
call    sub_1AB42
call    sub_1685B
cmp     ds:byte_100B7, 1
jz      short loc_133FD
mov     ds:DiskType, 0FFh

loc_133FD:
mov     ds:word_15F82, 0
mov     ds:byte_13D09, 0
mov     ds:word_13D07, 0
mov     ds:byte_1007F, 0FFh
cmp     ds:DuplicatorReturn, 0
jz      short loc_1342C
mov     al, 49h ; 'I'
call    DuplicatorCommand
mov     al, 58h ; 'X'
call    DuplicatorCommand
jnb     short loc_1342C
mov     ax, 100h
jmp     loc_137D9

loc_1342C:
cmp     ds:byte_100B7, 1
jz      short loc_13448
mov     al, ds:SourceDriveNumber
call    sub_18321
call    sub_13802
call    sub_16C65
jnb     short loc_13448
mov     ax, 6           ; 6 translates to "check source disk" message.
stc
jmp     loc_137D9

loc_13448:
mov     al, ds:SourceDriveNumber
cmp     al, ds:TargetDriveNumber
jz      short loc_13489
cmp     ds:byte_100B7, 2
jz      short loc_13489
mov     al, ds:TargetDriveNumber
call    sub_18321
call    sub_13802
and     al, 40h
jz      short loc_13468
jmp     loc_136A3

loc_13468:
call    sub_16C65
jnb     short loc_13489
jmp     loc_13693

loc_13470:
cmp     ds:DuplicatorReturn, 0
jz      short loc_134BD
mov     al, 'I'
call    DuplicatorCommand
mov     al, 'X'
call    DuplicatorCommand
jnb     short loc_13489
mov     ax, 100h
jmp     loc_137D9

loc_13489:
mov     al, ds:StartingCylinder
mov     ds:CylndrBeingRead, al
mov     ds:ClndrBeingWritten, al
cmp     ds:byte_100B7, 1
jnz     short loc_134A4
mov     ds:byte_1007F, 0
call    DisplayTracks   ; puts track display at bottom of screen
jmp     loc_13658

loc_134A4:
cmp     ds:DuplicatorReturn, 0
jz      short loc_134BD
call    DisplayTracks   ; puts track display at bottom of screen
cmp     ds:byte_1007F, 0
mov     ds:byte_1007F, 0
jnz     short loc_134C6
jmp     loc_13658

loc_134BD:
mov     al, ds:StartingCylinder
mov     ds:CylndrBeingRead, al
mov     ds:ClndrBeingWritten, al

loc_134C6:
mov     ds:byte_1007D, 0
mov     al, ds:SourceDriveNumber
cmp     al, ds:TargetDriveNumber
jnz     short loc_134FC
call    sub_16F04
mov     dx, 700h
call    SetCursorPos
mov     ax, MsgOffs.field_15 ; Insert source.. press ENTER...
call    DisplayString
call    GetKey
call    ClrMessageWndw
jb      short loc_13521
mov     dl, ds:SourceDriveNumber
call    sub_16E78
and     al, 10h
jz      short loc_134FC
mov     al, ds:SourceDriveNumber
call    sub_18321

loc_134FC:
mov     ds:CurrentSide, 0
mov     al, ds:CylndrBeingRead
mov     ds:CurrentCylinder, al
call    sub_13882
call    sub_1AC37
mov     dl, ds:SourceDriveNumber
call    sub_16E78
mov     al, 6
call    sub_13A5E
call    sub_176F9

ReadCylinder:
call    CheckForEsc
jnb     short loc_13527

loc_13521:              ; 0 translates to "15spaces" message.
mov     ax, 0
jmp     loc_137C9

loc_13527:
mov     ds:CurrentSide, 0

ReadTrack:
mov     al, ds:CylndrBeingRead
mov     ds:CurrentCylinder, al
call    sub_13882
call    sub_18313

loc_13538:
mov     al, 'r'
call    UpdateTrkProgDisp
call    ReadTrack
jnb     short loc_13560
mov     al, ds:SourceDriveNumber
call    sub_18321
mov     al, ds:CylndrBeingRead
mov     ds:CurrentCylinder, al
call    sub_18313
mov     ds:byte_1007D, 0FFh
push    ds
call    MaxtMotorTimer
or      ds:dsk_ret_code, 80h ; Controller return code
                        ;  00h = ok
                        ;  01h = bad command or parameter
                        ;  02h = can't find address mark
                        ;  03h = can't write, protected dsk
                        ;  04h = sector not found
                        ;  08h = DMA overrun
                        ;  09h = DMA attempt over 64K bound
                        ;  10h = bad CRC on disk read
                        ;  20h = controller failure
                        ;  40h = seek failure
                        ;  80h = timeout, no response
pop     ds

loc_13560:
call    WrtTrkLnTbl
call    DispReadLngth
mov     al, 'a'
call    UpdateTrkProgDisp
call    AnalyzeTrack
jb      short loc_13538
mov     al, ds:CurrentCylinder
cmp     al, ds:StartingCylinder
jnz     short loc_1358E
cmp     ds:CurrentSide, 0
jnz     short loc_1358E
cmp     ds:DiskType, 0FFh
jnz     short loc_1358E
mov     ax, 9           ; 9 tranlates to "please use TCM" mesaage.
stc
jmp     loc_137D9

loc_1358E:
call    sub_1AC85
jnb     short loc_135AF
cmp     ds:byte_100B7, 2
jz      short loc_135A2
mov     ds:byte_1007F, 0FFh
jmp     short loc_13611
align 2

loc_135A2:
call    sub_1B12A
call    sub_1B18F
mov     ax, 7           ; 7 translates to "disk full" message.
stc
jmp     loc_137D9

loc_135AF:
cmp     ds:NumberOfSides, 1
jz      short ReadNextCylinder
cmp     ds:CurrentSide, 1
jz      short ReadNextCylinder
mov     ds:CurrentSide, 1
jmp     ReadTrack

ReadNextCylinder:
mov     al, ds:CylndrBeingRead
add     al, ds:TrackIncrement
mov     ds:CylndrBeingRead, al
cmp     al, ds:EndingCylinder
ja      short loc_1360E
cmp     ds:EndingCylinder, 29h ; ')'
ja      short loc_13606
cmp     al, 27h ; '''
jbe     short loc_13606
mov     bh, 0
cmp     ds:byte_100B7, 1
jz      short loc_135F4
mov     bl, ds:SourceDriveNumber
cmp     ds:byte_1009B[bx], 28h ; '('
jb      short loc_13609

loc_135F4:
cmp     ds:byte_100B7, 2
jz      short loc_13606
mov     bl, ds:TargetDriveNumber
cmp     ds:byte_1009B[bx], 28h ; '('
jb      short loc_13609

loc_13606:
jmp     ReadCylinder

loc_13609:
mov     ds:EndingCylinder, 27h ; '''

loc_1360E:
call    sub_1AD2F

loc_13611:
cmp     ds:byte_100B7, 2
jnz     short loc_13621
call    sub_1AB5D
mov     ax, 8000h
jmp     loc_137D9

loc_13621:
call    sub_16F04
mov     al, ds:SourceDriveNumber
cmp     al, ds:TargetDriveNumber
jnz     short loc_13658
call    sub_16F04
mov     dx, 700h
call    SetCursorPos
mov     ax, MsgOffs.field_16 ; Insert target disk...
call    DisplayString
call    GetKey
call    ClrMessageWndw
jnb     short loc_13647
jmp     short loc_136C0
db 90h

loc_13647:
mov     dl, ds:TargetDriveNumber
call    sub_16E78
and     al, 10h
jz      short loc_13658
mov     al, ds:TargetDriveNumber
call    sub_18321

loc_13658:
mov     ds:CurrentSide, 0
mov     al, ds:ClndrBeingWritten
mov     ds:CurrentCylinder, al
mov     ds:CurrentOperation, 'w'
call    sub_13882
call    sub_1AC63
mov     dl, ds:TargetDriveNumber
call    sub_16E78
push    ax
cmp     ds:byte_1007D, 0
jz      short loc_13689
mov     dl, ds:TargetDriveNumber
push    ds
call    MaxtMotorTimer
call    sub_16FEC
pop     ds

loc_13689:
pop     ax
and     al, 40h
jnz     short loc_136A3
call    sub_16C65
jnb     short WriteCylinder

loc_13693:
mov     al, 'I'
cmp     ds:DuplicatorReturn, 0
jnz     short loc_136AC
mov     ax, 8           ; 8 translates to "check target disk" message.
stc
jmp     loc_137D9

loc_136A3:
mov     al, 'P'
cmp     ds:DuplicatorReturn, 0
jz      short loc_136AF

loc_136AC:
jmp     loc_1373E

loc_136AF:              ; 1 translates to "target is write protected" message.
mov     ax, 1
stc
jmp     loc_137D9

WriteCylinder:
mov     ds:CurrentSide, 0

WriteTrack:
call    CheckForEsc
jnb     short loc_136C6

loc_136C0:              ; 0 translates to "15spaces" message.
mov     ax, 0
jmp     loc_137C9

loc_136C6:
mov     ds:byte_10086, 2
mov     al, ds:ClndrBeingWritten
mov     ds:CurrentCylinder, al
mov     ds:CurrentOperation, 'w'
call    sub_13882
call    sub_18313
call    sub_1ACFA
jnb     short loc_136E7
call    sub_16F04
jmp     loc_134C6

loc_136E7:
mov     ds:byte_10068, 2
mov     ds:byte_10069, '<'
mov     al, ds:ClndrBeingWritten
mov     ds:CurrentCylinder, al
mov     al, 'w'
call    UpdateTrkProgDisp
call    WriteTrack
call    DispReadLngth
call    sub_18A07
push    ax
pushf
call    DispWritLngth
popf
pop     ax
jnb     short loc_1371F
cmp     ds:DuplicatorReturn, 0
jnz     short loc_13722
cmp     al, 'K'
jz      short loc_13722
mov     al, ds:byte_194D3
jmp     short loc_13722
db 90h

loc_1371F:
mov     al, ds:byte_194D1

loc_13722:
call    UpdateTrkProgDisp
cmp     al, ds:byte_194D1
jz      short loc_1374A
cmp     al, 'K'
jz      short loc_13737
dec     ds:byte_10086
jz      short loc_13737
jmp     short loc_136E7

loc_13737:
cmp     ds:DuplicatorReturn, 0
jz      short loc_1374A

loc_1373E:
call    UpdateTrkProgDisp
inc     ds:NumBadDsks
mov     al, 'R'
jmp     short loc_13780
align 2

loc_1374A:
cmp     ds:NumberOfSides, 1
jz      short WriteNextCylinder
cmp     ds:CurrentSide, 1
jz      short WriteNextCylinder
mov     ds:CurrentSide, 1
jmp     WriteTrack

WriteNextCylinder:
mov     al, ds:ClndrBeingWritten
add     al, ds:TrackIncrement
mov     ds:ClndrBeingWritten, al
cmp     al, ds:EndingCylinder
ja      short loc_13773
jmp     WriteCylinder

loc_13773:
cmp     ds:DuplicatorReturn, 0
jz      short loc_1379F
inc     ds:NumGoodDsks
mov     al, 'A'

loc_13780:
push    ax
call    sub_16F04
call    DispGoodBadDsks
pop     ax
call    DuplicatorCommand
jnb     short loc_13793
mov     ax, 100h
jmp     short loc_137D9
db 90h

loc_13793:
mov     ax, ds:NumGoodDsks
cmp     ax, ds:word_10084
jnb     short loc_1379F
jmp     loc_13470

loc_1379F:
cmp     ds:byte_100B7, 2
jz      short loc_137AC
mov     al, ds:TargetDriveNumber
call    sub_18321

loc_137AC:
cmp     ds:byte_100B7, 1
jz      short loc_137BF
mov     al, ds:SourceDriveNumber
cmp     al, ds:TargetDriveNumber
jz      short loc_137BF
call    sub_18321

loc_137BF:
call    sub_16865
mov     ax, 100h
clc
jmp     short loc_137D9
db 90h

loc_137C9:
cmp     ds:byte_100B7, 2
jnz     short loc_137D8
push    ax
call    sub_1B12A
call    sub_1B18F
pop     ax

loc_137D8:
stc

loc_137D9:
pushf
push    ax
call    sub_16865
pop     ax
cmp     ds:DuplicatorReturn, 0
jz      short loc_137F9
cmp     ah, 1
jz      short loc_137F9
push    ax
mov     al, 'R'
call    DuplicatorCommand
inc     ds:NumBadDsks
call    DispGoodBadDsks
pop     ax

loc_137F9:
popf
push    ax
pushf
call    sub_1B12A
popf
pop     ax
retn
ReadWrite endp




sub_13802 proc near
push    ax
cmp     ah, 28h ; '('
jnb     short loc_13820
cmp     ds:EndingCylinder, 28h ; '('
jb      short loc_13820
mov     ds:EndingCylinder, 27h ; '''
mov     dx, 912h
call    SetCursorPos
mov     al, ds:EndingCylinder
call    DisplayHexTrack

loc_13820:
pop     ax
retn
sub_13802 endp



; puts track display at bottom of screen

DisplayTracks proc near
call    sub_17BBE       ; clears bottom of screen for track display
mov     ax, 10h
cmp     ds:EndingCylinder, 29h ; ')'
jbe     short loc_13832
mov     ax, MsgOffs.field_3C

loc_13832:
call    DisplayString
retn
DisplayTracks endp




DisplayDMA_Port proc near
mov     dx, 0D32h
call    SetCursorPos
mov     ax, MsgOffs.field_36
call    DisplayString
mov     dx, 0D3Fh
call    SetCursorPos
mov     al, ds:DMA_Channel
or      al, 30h
call    DisplayChar
mov     dx, 0D4Ah
call    SetCursorPos
mov     ax, ds:TC_Port_Base
call    DisplayHex
retn
DisplayDMA_Port endp




DispGoodBadDsks proc near
mov     dx, 0F32h
call    SetCursorPos
mov     ax, MsgOffs.field_39
call    DisplayString
mov     ax, ds:NumGoodDsks
call    DisplayNumDsks
mov     dx, 1032h
call    SetCursorPos
mov     ax, MsgOffs.field_3A
call    DisplayString
mov     ax, ds:NumBadDsks
call    DisplayNumDsks
retn
DispGoodBadDsks endp




sub_13882 proc near
push    ax
call    GetTrkDatOfs
mov     bx, ds:TrackTypeTable[bx]
cmp     ds:CurrentOperation, 'w'
jnz     short loc_13895
mov     ds:DiskType, bh

loc_13895:
mov     ds:KeepTrkLngthFlag, 'N'
mov     ds:CopyXIDXFlag, 'N'
mov     ds:CpyWkBitsFlag, 'N'
mov     ds:VerifyWrtFlag, 'N'
mov     al, 8
call    sub_138EE
test    bl, 1
jz      short loc_138B8
mov     ds:KeepTrkLngthFlag, 'Y'

loc_138B8:
test    bl, 2
jz      short loc_138C2
mov     ds:CopyXIDXFlag, 'Y'

loc_138C2:
test    bl, 4
jz      short loc_138CC
mov     ds:CpyWkBitsFlag, 'Y'

loc_138CC:
test    bl, 8
jz      short loc_138D6
mov     ds:VerifyWrtFlag, 'Y'

loc_138D6:
test    bl, 20h
jz      short loc_138E0
mov     al, 1
call    sub_138EE

loc_138E0:
cmp     ds:DiskType, 7
jz      short loc_138EC
mov     al, 80h ; 'Ç'
call    sub_138EE

loc_138EC:
pop     ax
retn
sub_13882 endp




sub_138EE proc near
cmp     ds:byte_10099, 0FFh
jnz     short loc_138FB
mov     ah, 0
mov     ds:word_1006A, ax
retn

loc_138FB:
mov     al, ds:byte_10099
mov     ah, 0
mov     ds:word_1006A, ax
retn
sub_138EE endp




UpdateTrkProgDisp proc near
mov     ds:CurrentOperation, al
push    ax
push    dx
mov     dh, ds:CurrentSide
add     dh, 17h
mov     dl, ds:CurrentCylinder
cmp     ds:EndingCylinder, 29h ; ')'
ja      short loc_1391E
add     dl, 8

loc_1391E:
call    SetCursorPos
mov     dx, ds:word_178F0
push    dx
mov     ds:word_178F0, 0Ch
cmp     al, 'a'
jb      short loc_13939
cmp     al, 'z'
ja      short loc_13939
and     al, 0DFh
call    sub_17AAF

loc_13939:
call    DisplayChar
call    sub_17AA6
test    ds:DiskType, 80h
jnz     short loc_13962
mov     ds:word_178F0, 0Ch
mov     dx, 1232h
call    SetCursorPos
mov     ax, MsgOffs.field_3D
call    DisplayString
mov     al, ds:DiskType
add     al, MsgOffs.field_3E
mov     ah, 0
call    DisplayString

loc_13962:
pop     dx
mov     ds:word_178F0, dx
pop     dx
pop     ax
retn
UpdateTrkProgDisp endp




CheckForEsc proc near
push    ax
mov     ah, 1
int     16h             ; KEYBOARD - CHECK BUFFER, DO NOT CLEAR
                        ; Return: ZF clear if character in buffer
                        ; AH = scan code, AL = character
                        ; ZF set if no character in buffer
jz      short loc_13981
mov     ah, 0
int     16h             ; KEYBOARD - READ CHAR FROM BUFFER, WAIT IF EMPTY
                        ; Return: AH = scan code, AL = character
cmp     ax, 0
jz      short loc_1397E
cmp     al, 1Bh
jnz     short loc_13981

loc_1397E:
stc
pop     ax
retn

loc_13981:
clc
pop     ax
retn
CheckForEsc endp



; Adds the length of the track just read to the
; track length table.

WrtTrkLnTbl proc near
push    bx
push    ax
call    GetTrkDatOfs
mov     ax, ds:ReadLengthBytes
mov     ds:TrackLngthTbl[bx], ax
pop     ax
pop     bx
retn
WrtTrkLnTbl endp



; gets the length of the current track off the list.
; Return in DX.

RdTrkLngthTbl proc near
push    bx
call    GetTrkDatOfs
mov     dx, ds:TrackLngthTbl[bx]
pop     bx
retn
RdTrkLngthTbl endp

push    ax
push    dx
mov     dl, 1Eh
mov     dh, al
call    SetCursorPos
mov     ax, MsgOffs.field_11
call    DisplayString
pop     dx
mov     ax, dx
call    DisplayHex
pop     ax
retn



DispReadLngth proc near
mov     dx, 51Eh
call    SetCursorPos
mov     ax, MsgOffs.field_11
call    DisplayString
mov     ax, ds:TrackLengthBits
shr     ax, 1
shr     ax, 1
shr     ax, 1
cmp     ds:DiskType, 0FFh
jnz     short loc_139D9
test    ds:TC_Port1Byte, 2
jz      short loc_139F3
jnz     short loc_139E5

loc_139D9:
mov     dl, ds:DiskType
and     dl, 7Fh
cmp     dl, 7
jnb     short loc_139F3

loc_139E5:
call    DisplayHex
mov     al, '.'
call    DisplayChar
mov     al, 0
call    DisplayDecByte
retn

loc_139F3:
shr     ax, 1
add     ax, 1000h
call    DisplayHex
mov     al, '.'
call    DisplayChar
mov     ax, ds:TrackLengthBits
and     al, 0Fh
call    DisplayDecByte
retn
DispReadLngth endp




DispWritLngth proc near
mov     dx, 61Eh        ; Print to the screen the written track length.
call    SetCursorPos
mov     ax, MsgOffs.field_11
call    DisplayString
mov     ax, ds:WrittenLength
shr     ax, 1
shr     ax, 1
shr     ax, 1
cmp     ds:DiskType, 0FFh
jnz     short loc_13A2E
test    ds:TC_Port1Byte, 2
jz      short loc_13A48
jnz     short loc_13A3A

loc_13A2E:
mov     dl, ds:DiskType
and     dl, 7Fh
cmp     dl, 7
jnb     short loc_13A48

loc_13A3A:
call    DisplayHex
mov     al, '.'
call    DisplayChar
mov     al, 0
call    DisplayDecByte
retn

loc_13A48:
shr     ax, 1
add     ax, 1000h
call    DisplayHex
mov     al, '.'
call    DisplayChar
mov     ax, ds:WrittenLength
and     al, 0Fh
call    DisplayDecByte
retn
DispWritLngth endp




sub_13A5E proc near
push    ax
push    dx
mov     dh, al
mov     dl, 1Eh
call    SetCursorPos
mov     ax, MsgOffs.field_12
call    DisplayString
pop     dx
pop     ax
retn
sub_13A5E endp




GetKey proc near
mov     ah, 0
int     16h             ; KEYBOARD - READ CHAR FROM BUFFER, WAIT IF EMPTY
                        ; Return: AH = scan code, AL = character
cmp     al, 61h ; 'a'
jb      short loc_13A7E
cmp     al, 'z'
ja      short loc_13A7E
and     al, 0DFh

loc_13A7E:
cmp     ah, '<'
jz      short loc_13A9D
cmp     ah, 'D'
jz      short loc_13AA1
cmp     ax, 0
jz      short loc_13AA1
cmp     al, ' '
jz      short loc_13A9D
cmp     al, 'Q'
jz      short loc_13AA1
cmp     al, 1Bh
jz      short loc_13AA3

loc_13A99:
mov     ah, al
clc
retn

loc_13A9D:
mov     al, '<'
jmp     short loc_13A99

loc_13AA1:
mov     al, 'D'

loc_13AA3:
mov     ah, al
stc
retn
GetKey endp




sub_13AA7 proc near
cmp     byte ptr ds:TrackTypeTable+1, offset unk_1D8F7
jnz     short locret_13ABD
call    GetInt24
call    sub_13ABE
call    sub_13AF3
call    sub_13AE1
call    RestoreInt24

locret_13ABD:
retn
sub_13AA7 endp




sub_13ABE proc near
mov     ds:byte_100B5, 0
mov     ah, 44h ; 'D'
mov     al, 0Eh
mov     bl, ds:TargetDriveNumber
inc     bl
int     21h             ; DOS - 2+ - IOCTL -
jb      short loc_13AD4
mov     ds:byte_100B5, al

loc_13AD4:
mov     ah, 44h ; 'D'
mov     al, 0Fh
mov     bl, ds:TargetDriveNumber
inc     bl
int     21h             ; DOS - 2+ - IOCTL -
retn
sub_13ABE endp




sub_13AE1 proc near
cmp     ds:byte_100B5, 0
jz      short locret_13AF2
mov     ah, 44h ; 'D'
mov     al, 0Fh
mov     bl, ds:byte_100B5
int     21h             ; DOS - 2+ - IOCTL -

locret_13AF2:
retn
sub_13AE1 endp




sub_13AF3 proc near
mov     ds:byte_100A9, 0
mov     al, ds:TargetDriveNumber
add     al, 41h ; 'A'
mov     byte ptr ds:aBDisktech_exe, al ; "B:DISKTECH.EXE"
mov     al, 0
call    sub_13C57
jnb     short loc_13B08

locret_13B07:
retn

loc_13B08:              ; file attributes of b:disktech.exe
mov     ds:DskTekExeAttr, cx
mov     cx, 0
mov     al, 1
call    sub_13C57
jb      short locret_13B07
mov     dx, offset aBDisktech_exe ; "B:DISKTECH.EXE"
mov     ax, 3D02h
int     21h             ; DOS - 2+ - OPEN DISK FILE WITH HANDLE
                        ; DS:DX ; ASCIZ filename
                        ; AL = access mode
                        ; 2 - read & write
jb      short loc_13B9C
mov     ds:byte_100A9, 0FFh
mov     ds:word_1009F, ax
mov     bx, ds:word_1009F
mov     ax, 5700h
int     21h             ; DOS - 2+ - GET FILE'S DATE/TIME
                        ; BX = file handle
jb      short loc_13B9C
mov     ds:word_100AE, cx
mov     ds:word_100B0, dx
mov     ds:word_100A3, 0
mov     ds:word_100A5, 0

loc_13B47:
mov     cx, ds:word_100A5
mov     dx, ds:word_100A3
mov     ax, 4200h
mov     bx, ds:word_1009F
int     21h             ; DOS - 2+ - MOVE FILE READ/WRITE POINTER (LSEEK)
                        ; AL = method: offset from beginning of file
jb      short loc_13B9C
mov     ah, 3Fh ; '?'
mov     bx, ds:word_1009F
mov     cx, 8000h
mov     dx, 0
push    ds
mov     ds, ds:TrackBufSeg
int     21h             ; DOS - 2+ - READ FROM FILE WITH HANDLE
                        ; BX = file handle, CX = number of bytes to read
                        ; DS:DX -; buffer
pop     ds
jb      short loc_13B9C
cmp     ax, 0
jz      short loc_13B9C
mov     ds:word_100A1, ax
mov     es, ds:TrackBufSeg
mov     di, 0Dh

loc_13B7F:
mov     cx, ds:word_13C6E
mov     si, offset unk_13C70

loc_13B86:
mov     al, es:[di]
inc     di
cmp     di, ds:word_100A1
jnb     short loc_13BA0
cmp     al, [si]
jz      short loc_13BAD
sub     di, ds:word_13C6E
add     di, cx
jmp     short loc_13B7F

loc_13B9C:
stc
jmp     loc_13C3C

loc_13BA0:
add     ds:word_100A3, 7C00h
adc     ds:word_100A5, 0
jmp     short loc_13B47

loc_13BAD:
inc     si
loop    loc_13B86
sub     di, 14h
cmp     byte ptr es:[di], 9Ah ; 'Ü'
jz      short loc_13BBE
add     di, 0Eh
jmp     short loc_13B7F

loc_13BBE:
mov     ds:word_13C7E, di
add     di, 160h
mov     bx, di
add     bx, 100h

loc_13BCC:
mov     cx, ds:word_13C77
mov     si, offset unk_13C79

loc_13BD3:
mov     al, es:[di]
inc     di
cmp     di, bx
jnb     short loc_13B9C
cmp     al, [si]
jz      short loc_13BE7
sub     di, ds:word_13C77
add     di, cx
jmp     short loc_13BCC

loc_13BE7:
inc     si
loop    loc_13BD3
mov     ax, di
sub     ax, ds:word_13C7E
add     ax, 8
mov     di, ds:word_13C7E
mov     byte ptr es:[di], 0E9h ; 'T'
mov     es:[di+1], ax
mov     cx, ds:word_100A5
mov     dx, ds:word_100A3
mov     ax, 4200h
mov     bx, ds:word_1009F
int     21h             ; DOS - 2+ - MOVE FILE READ/WRITE POINTER (LSEEK)
                        ; AL = method: offset from beginning of file

loc_13C10:
jb      short loc_13B9C
mov     bx, ds:word_1009F
mov     dx, 0
mov     cx, ds:word_100A1
push    ds
mov     ds, ds:TrackBufSeg
mov     ah, 40h
int     21h             ; DOS - 2+ - WRITE TO FILE WITH HANDLE
                        ; BX = file handle, CX = number of bytes to write, DS:DX -; buffer
pop     ds
jb      short loc_13C10
mov     bx, ds:word_1009F
mov     ax, 5701h
mov     cx, ds:word_100AE
mov     dx, ds:word_100B0
int     21h             ; DOS - 2+ - SET FILE'S DATE/TIME
                        ; BX = file handle, CX = time to be set
                        ; DX = date to be set
jb      short loc_13C10

loc_13C3C:
pushf
cmp     ds:byte_100A9, 0
jz      short loc_13C4C
mov     bx, ds:word_1009F
mov     ah, 3Eh
int     21h             ; DOS - 2+ - CLOSE A FILE WITH HANDLE
                        ; BX = file handle

loc_13C4C:
mov     al, 1
mov     cx, ds:DskTekExeAttr ; file attributes of b:disktech.exe
call    sub_13C57
popf
retn
sub_13AF3 endp




sub_13C57 proc near
mov     dx, offset aBDisktech_exe ; "B:DISKTECH.EXE"
mov     ah, 43h
int     21h             ; INT 21 - DOS 2+ - GET FILE ATTRIBUTES
                        ; AX = 4300h
                        ; DS:DX -; ASCIZ filename
                        ; Return: CF clear if successful
                        ; CX = file attributes (see #1285)
                        ; CF set on error
retn
sub_13C57 endp

aBDisktech_exe db 'B:DISKTECH.EXE',0
word_13C6E dw 7
unk_13C70 db 0BAh ; ¦
db    0
db    0
db  76h ; v
db    1
db  4Ah ; J
db  83h ; â
word_13C77 dw 5
unk_13C79 db  73h ; s
db    3
db 0E9h ; T
db  93h ; ô
db    0
word_13C7E dw 0



GetInt24 proc near
pushf
cli
push    es
mov     ax, 3524h
int     21h             ; DOS - 2+ - GET INTERRUPT VECTOR
                        ; AL = interrupt number
                        ; Return: ES:BX = value of interrupt vector
mov     ds:OldInt24Seg, es
mov     ds:OldInt24Off, bx
push    cs
pop     ds
assume ds:seg001
mov     dx, offset Int24Entry
mov     ax, 2524h
int     21h             ; DOS - SET INTERRUPT VECTOR
                        ; AL = interrupt number
                        ; DS:DX = new vector to be used for specified interrupt
pop     es
popf
retn
GetInt24 endp




RestoreInt24 proc near
pushf
cli
push    ds
mov     dx, OldInt24Off
mov     ds, OldInt24Seg
assume ds:nothing
mov     ax, 2524h
int     21h             ; DOS - SET INTERRUPT VECTOR
                        ; AL = interrupt number
                        ; DS:DX = new vector to be used for specified interrupt
pop     ds
popf
retn
RestoreInt24 endp


Int24Entry:             ; DOS critical error handler
mov     bp, sp
or      byte ptr [bp+1Ch], 1
pop     ax
pop     ax
pop     ax
pop     ax
pop     bx
pop     cx
pop     dx
pop     si
pop     di
pop     bp
pop     ds
pop     es
iret
db    0
db    0
db    0
db    0
db    0
db    0
word_13CC9 dw 0
word_13CCB dw 0
word_13CCD dw 0
word_13CCF dw 0
word_13CD1 dw 0
word_13CD3 dw 0
word_13CD5 dw 0
db    0
word_13CD8 dw 0
word_13CDA dw 0
db    0
db    0
db    0
db    0
word_13CE0 dw 0
word_13CE2 dw 0
db    0
db    0
db    0
db    0
CurrentTrack dw 0
db 0
byte_13CEB db 0
word_13CEC dw 0
word_13CEE dw 0
CurrTrkLngthBytes dw 0  ; length of the track being processed in bytes.
word_13CF2 dw 0
word_13CF4 dw 0
db  59h ; Y
byte_13CF7 db 0
byte_13CF8 db 0
byte_13CF9 db 0
word_13CFA dw 0
TrackLengthBits dw 0    ; The length of the track just read in bits.
TrkLnBitsHiByte dw 0    ; The high byte of the track length in bits.
WrittenLength dw 0      ; The length of the track just written
word_13D02 dw 0
byte_13D04 db 0
word_13D05 dw 0
word_13D07 dw 0
byte_13D09 db 0
word_13D0A dw 0
word_13D0C dw 0
word_13D0E dw 0
F_SwitchUsed db 0       ; Set to 80h by /f command line switch.
                        ; takes effect during writing track 27h.
byte_13D11 db 0
byte_13D12 db 0
db    0
db    0
db    0
db    0
db    0
word_13D18 dw 0
trackSkewDly2 dw 0      ; This word specifies how long to wait after index to begin
                        ; writing the track.
byte_13D1C db 0
byte_13D1D db 0
word_13D1E dw 0
unk_13D20 db    0
db    0
unk_13D22 db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
byte_13D70 db 0
word_13D71 dw 0
unk_13D73 db 0A0h ; á
db 0B0h ; ¦
db 0D0h ; -
unk_13D76 db  26h ; &
db  20h
db  13h
byte_13D79 db 0
word_13D7A dw 0
word_13D7C dw 0
word_13D7E dw 0
word_13D80 dw 0
off_13D82 dw offset loc_148BB
dw offset loc_148BB
dw offset loc_148BB
dw offset loc_148BB
dw offset loc_148C0
dw offset loc_148ED
dw offset loc_148BB
dw offset loc_14945
dw offset loc_14927
unk_13D94 db    0
db    0
db    0
db    0
db 0C5h ; +
db 0BEh ; +
db    0
word_13D9B dw 6464h
word_13D9D dw 0A70Ch
db  74h ; t
db 0A5h ; Ñ
db 0DDh ; ¦
db 0A3h ; ú
db  46h ; F
db 0A2h ; ó
db 0AFh ; »
db 0A0h ; á
db  17h
db  9Fh ; ƒ
db  80h ; Ç
db  9Dh ; ¥
db 0E9h ; T
db  9Bh ; ¢
db  51h ; Q
db  9Ah ; Ü
db 0BAh ; ¦
db  98h ; ÿ
db  23h ; #
db  97h ; ù
db  8Ch ; î
db  95h ; ò
db 0F4h ; (
db  93h ; ô
db  5Dh ; ]
db  92h ; Æ
db 0C6h ; ¦
db  90h ; É
db  2Eh ; .
db  8Fh ; Å
db  97h ; ù
db  8Dh ; ì
db    0
db  8Ch ; î
db  68h ; h
db  8Ah ; è
db 0D1h ; -
db  88h ; ê
db  3Ah ; :
db  87h ; ç
db 0A3h ; ú
db  85h ; à
db  0Ch
db  84h ; ä
db  74h ; t
db  82h ; é
db 0DDh ; ¦
db  80h ; Ç
db  46h ; F
db  7Fh ; 
db 0AFh ; »
db  7Dh ; }
db  17h
db  7Ch ; |
db  80h ; Ç
db  7Ah ; z
db 0E9h ; T
db  78h ; x
db  51h ; Q
db  77h ; w
db 0BAh ; ¦
db  75h ; u
db  23h ; #
db  74h ; t
db  8Ch ; î
db  72h ; r
unk_13DE1 db    0
db    0
unk_13DE3 db  98h ; ÿ
db    0
db  99h ; Ö
db    0
db  9Ah ; Ü
db    0
db  9Bh ; ¢
db    0
db  9Ch ; £
db    0
db  9Dh ; ¥
db    0
db  9Eh ; P
db    0
db  9Fh ; ƒ
db    0
db 0A0h ; á
db    0
db 0A1h ; í
db    0
db 0A2h ; ó
db    0
db 0A3h ; ú
db    0
db 0A4h ; ñ
db    0
db 0A5h ; Ñ
db    0
db 0A6h ; ª
db    0
db 0A7h ; º
db    0
db 0A8h ; ¿
db    0
db 0A9h ; ¬
db    0
db 0AAh ; ¬
db    0
db 0ABh ; ½
db    0
db 0ACh ; ¼
db    0
db 0ADh ; ¡
db    0
db 0AEh ; «
db    0
db 0AFh ; »
db    0
db 0B0h ; ¦
db    0
db 0B1h ; ¦
db    0
db 0B2h ; ¦
db    0
db 0B3h ; ¦
db    0
db 0B4h ; ¦
db    0
db 0B5h ; ¦
db    0
db 0B6h ; ¦
db    0
db 0B7h ; +
db    0
db 0B8h ; +
db    0
db 0B9h ; ¦
db    0
db  4Dh ; M
db    0
db  55h ; U
db    0
db  5Dh ; ]
db    0
db 0A5h ; Ñ
db    0
db 0ADh ; ¡
db    0
db 0B5h ; ¦
db    0
unk_13E33 db 0BDh ; +
unk_13E34 db    0
unk_13E35 db    0
unk_13E36 db    0
unk_13E37 db    0
unk_13E38 db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
unk_14031 db    0
db    0
unk_14033 db    0
db    0
word_14035 dw 0
unk_14037 db    0
db    0
word_14039 dw 0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
unk_1422D db    0
db    0
db    0
db    0
unk_14231 db    0
db    0
unk_14233 db    0
db    0
word_14235 dw 0
word_14237 dw 0
word_14239 dw 0
db    0
db    0
word_1423D dw 0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
unk_14431 db    0
db    0
unk_14433 db    0
db    0
word_14435 dw 0
unk_14437 db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
unk_14533 db    0
unk_14534 db    0
unk_14535 db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0



AnalyzeTrack proc near
push    bx
push    cx
push    dx
push    es
push    ds
push    si
push    di
mov     bh, 0
mov     bl, ds:byte_13D70
mov     al, byte ptr ds:unk_13D76[bx]
mov     ah, 0
mov     ds:word_13D71, ax
mov     ds:byte_1008A, 0
call    GetTrkDatOfs
mov     ds:CurrentTrack, bx
mov     ds:TrackSkewTbl[bx], 0
call    RdTrkLngthTbl
mov     ds:CurrTrkLngthBytes, dx
mov     bl, ds:CurrentDrive
mov     bh, 0
mov     al, byte ptr ds:stru_15F60.Drive0[bx]
mov     ds:byte_13D70, al
mov     es, ds:TrackBufSeg
mov     si, ds:TrackBufOfs
mov     ds:CurrTrackBufOfs, si
mov     ax, si
add     ax, ds:CurrTrkLngthBytes
mov     ds:EndOfCurrTrk, ax
add     si, 5
call    sub_14E52
cmp     ds:word_13D7E, '$'
jbe     short loc_14618
mov     ds:CpyWkBitsFlag, 'Y'

loc_14618:
mov     ax, ds:CurrTrkLngthBytes
add     ds:EndOfCurrTrk, ax
mov     si, ds:CurrTrackBufOfs
call    sub_15045
mov     si, ds:CurrTrackBufOfs
mov     ax, si
add     ax, ds:CurrTrkLngthBytes
add     ax, 20h ; ' '
mov     ds:EndOfCurrTrk, ax
call    sub_1488C
jnb     short loc_14647
cmp     si, 0FFFFh
stc
jnz     short loc_14647

loc_14641:
stc
mov     al, 0FFh
jmp     loc_14759

loc_14647:
pushf
cmp     ds:DiskType, 7
jnz     short loc_1466D
cmp     ds:CurrTrkLngthBytes, 3300h
jnb     short loc_14666
cmp     ds:byte_167D5, 0
jz      short loc_1466D

loc_1465E:
xor     ds:byte_167D5, 0FFh
popf
jmp     short loc_14641

loc_14666:
cmp     ds:byte_167D5, 0FFh
jnz     short loc_1465E

loc_1466D:
mov     ds:word_13CFA, di
mov     bx, ds:CurrentTrack
mov     al, ds:DiskType
mov     byte ptr ds:(TrackTypeTable+1)[bx], al
popf
jnb     short loc_1469E
mov     bx, ds:CurrentTrack
or      byte ptr ds:TrackTypeTable[bx], 80h
mov     si, ds:CurrTrackBufOfs
mov     ds:word_13CF2, si
mov     di, ds:CurrTrkLngthBytes
add     di, 0Ch
mov     ds:word_13CFA, di
jmp     loc_14721

loc_1469E:
cmp     ds:CopyXIDXFlag, 'Y'
jz      short loc_146B8
mov     si, ds:CurrTrackBufOfs
mov     di, ds:word_14035
add     di, ds:CurrTrkLngthBytes
add     di, 0Ch
mov     ds:word_13CFA, di

loc_146B8:
mov     ds:word_13CF2, si
mov     ax, ds:CurrTrkLngthBytes
add     ax, si
mov     ds:word_13CF4, ax
mov     es, ds:TrackBufSeg
mov     si, ds:word_13CF2
mov     ax, ds:word_13CF4
mov     ds:EndOfCurrTrk, ax
call    sub_15045
mov     si, ds:word_13CF2
call    sub_159E0
call    sub_174C6
call    sub_149B0
call    sub_1513E
cmp     ds:byte_1008A, 0
jz      short loc_146FD

loc_146EC:
mov     bx, ds:CurrentTrack
or      byte ptr ds:TrackTypeTable[bx], 40h
and     byte ptr ds:TrackTypeTable[bx], 0DFh
jmp     short loc_1471E
db 90h

loc_146FD:
mov     bx, ds:CurrentTrack
shr     bx, 1
cmp     byte ptr ds:unk_161CA[bx], 0
jz      short loc_1470D
call    sub_15013

loc_1470D:
cmp     ds:word_13D7E, '$'
ja      short loc_146EC
cmp     ds:VerifyWrtFlag, 'Y'
jnz     short loc_1471E
call    loc_18279

loc_1471E:
call    sub_14761

loc_14721:
mov     dx, ds:word_13CFA
sub     dx, ds:word_13CF2
mov     ax, 0FFh
cmp     ds:KeepTrkLngthFlag, 'Y'
jz      short loc_1473A
mov     dx, ds:CurrTrkLngthBytes
mov     ax, 240h

loc_1473A:
add     dx, ax
mov     dl, 0
mov     ds:word_13D05, dx
mov     bx, ds:CurrentTrack
mov     al, byte ptr ds:TrackTypeTable[bx]
and     al, 80h
clc
jz      short loc_14759
mov     ds:DiskType, 0FFh
mov     ds:byte_100B3, 7Eh ; '~'

loc_14759:
pop     di
pop     si
pop     ds
pop     es
pop     dx
pop     cx
pop     bx
retn
AnalyzeTrack endp




sub_14761 proc near
mov     si, ds:word_13CF4
mov     cx, 100h
cmp     ds:DiskType, 7
jnb     short loc_147AC
add     si, 4
mov     cx, 64h ; 'd'
mov     bx, 5555h
mov     ax, bx
mov     dl, al
cmp     ds:DiskType, 5
jz      short loc_1478E
mov     bx, es:[si]
mov     ax, es:[si+2]
mov     dl, es:[si+4]

loc_1478E:
cmp     si, 0FFFAh
ja      short locret_147AB
mov     es:[si], bl
mov     es:[si+1], bh
mov     es:[si+2], al
mov     es:[si+3], ah
mov     es:[si+4], dl
add     si, 5
loop    loc_1478E

locret_147AB:
retn

loc_147AC:
mov     di, 0
mov     ds:word_13CCB, 0

loc_147B5:
mov     cl, byte ptr ds:unk_13E38[di]
cmp     cl, 6
jnb     short loc_147F4
mov     bx, ds:word_14035[di]
cmp     si, bx
jbe     short loc_147F4
mov     ax, 80h ; 'Ç'
inc     cl
shl     ax, cl
add     ax, bx
add     ax, 66h ; 'f'
cmp     si, ax
jbe     short loc_147DF
cmp     ax, ds:word_13CCB
jb      short loc_147DF
mov     ds:word_13CCB, ax

loc_147DF:
add     ax, ds:CurrTrkLngthBytes
add     bx, ds:CurrTrkLngthBytes
cmp     si, bx
jbe     short loc_147F4
cmp     ax, ds:word_13CCB
jb      short loc_147F4
mov     ds:word_13CCB, ax

loc_147F4:
add     di, 4
cmp     di, ds:word_13CC9
jb      short loc_147B5
call    sub_14F1F
jnb     short locret_14860
cmp     ds:KeepTrkLngthFlag, 59h ; 'Y'
jz      short locret_14860
mov     cx, 100h
push    si
sub     si, 14h
cmp     si, ds:word_13CCB
jnb     short loc_1481A
mov     si, ds:word_13CCB

loc_1481A:
mov     ax, es:[si]
mov     bx, ax
and     bx, 180h
cmp     bx, 180h
jnz     short loc_1482D
and     al, 1Fh
or      al, 40h

loc_1482D:
pop     si
sub     si, 5
cmp     si, ds:word_13CCB
jnb     short loc_1483B
mov     si, ds:word_13CCB

loc_1483B:
test    al, 80h
jz      short $+2
cmp     es:[si], ax
jz      short loc_14845
dec     si

loc_14845:
test    al, 80h
jz      short loc_14854
test    byte ptr es:[si-1], 1
jz      short loc_14854
and     al, 1Fh
or      al, 40h

loc_14854:
mov     es:[si], ax

loc_14857:
cmp     si, 0FFFDh
ja      short locret_14860
inc     si
inc     si
loop    loc_14854

locret_14860:
retn
sub_14761 endp




sub_14861 proc near
call    sub_1AC25
mov     dx, ds:word_13D05
add     dx, si
mov     di, ds:word_13CF2
mov     ds, cs:TrackBufSeg

loc_14873:
mov     ax, [di]
mov     es:[si], ax
inc     di
inc     di
inc     si
inc     si
cmp     si, 0FFFCh
jnb     short loc_14885
cmp     si, dx
jb      short loc_14873

loc_14885:
push    cs
pop     ds
assume ds:seg001
mov     word_1AAF7, dx
retn
sub_14861 endp




sub_1488C proc near
mov     bh, 0
mov     bl, DiskType
cmp     bl, 0FFh
jnz     short loc_14899
mov     bl, 87h ; 'ç'

loc_14899:
test    bl, 80h
jz      short loc_148B3
and     bl, 7Fh
cmp     bl, byte_100B3
jnz     short loc_148B3
cmp     byte_167D5, 0
mov     byte_167D5, 0
jz      short loc_148BB

loc_148B3:
shl     bx, 1
mov     ax, off_13D82[bx]
jmp     ax

loc_148BB:
stc
mov     si, 0
retn
sub_1488C endp


loc_148C0:
mov     si, CurrTrackBufOfs
add     si, 30h ; '0'
call    sub_18603
jb      short loc_148E6
sub     si, bp
add     si, 10h
mov     DiskType, 4
mov     byte_100B3, 4

loc_148DB:
mov     di, si
add     di, CurrTrkLngthBytes
add     di, 20h ; ' '
clc
retn

loc_148E6:
mov     DiskType, 85h ; 'à'
jmp     short sub_1488C

loc_148ED:
cmp     byte_100B3, 7
jb      short loc_148FB
cmp     CurrentCylinder, 28h ; '('
jnb     short loc_148BB

loc_148FB:
mov     si, CurrTrackBufOfs
add     si, 30h ; '0'
call    sub_18591
jb      short loc_14916
mov     DiskType, 5
mov     byte_100B3, 5
sub     si, 1Ch
jmp     short loc_148DB

loc_14916:
cmp     byte_100B3, 7Eh ; '~'
jz      short loc_148BB
mov     DiskType, 87h ; 'ç'
mov     si, 0FFFFh
stc
retn

loc_14927:
mov     si, CurrTrackBufOfs
add     si, 30h ; '0'
call    sub_1856B
jb      short loc_14942
mov     DiskType, 8
mov     byte_100B3, 8
sub     si, 20h ; ' '
jmp     short loc_148DB

loc_14942:
jmp     short loc_14962
db  90h ; É

loc_14945:
cmp     byte_13CF7, 0A1h ; 'í'
jz      short loc_14954
mov     DiskType, 88h ; 'ê'
jmp     sub_1488C

loc_14954:
cmp     word_13CC9, 0
jnz     short loc_1496C
cmp     byte_100B3, 8
jz      short loc_149AB

loc_14962:
mov     DiskType, 84h ; 'ä'
mov     si, 0FFFFh
stc
retn

loc_1496C:
call    sub_14B86
jb      short loc_149AB
mov     DiskType, 7
mov     byte_100B3, 7
mov     di, 0

loc_1497E:
cmp     si, word_14235[di]
jb      short loc_1499E
add     di, 4
cmp     di, word_13CEE
jb      short loc_1497E
mov     di, word_14235
add     di, CurrTrkLngthBytes
add     di, CurrTrkLngthBytes
add     di, 12h
clc
retn

loc_1499E:
mov     di, word_14235[di]
add     di, CurrTrkLngthBytes
add     di, 12h
clc
retn

loc_149AB:
mov     si, 0
stc
retn



sub_149B0 proc near
cmp     DiskType, 7
jnz     short locret_149C1
call    sub_14AEF
jb      short locret_149C1
call    sub_149C2
jb      short $+2

locret_149C1:
retn
sub_149B0 endp




sub_149C2 proc near
mov     di, 4
mov     byte_13D1D, 0

loc_149CA:
cmp     byte ptr unk_13E34[di], 3
jz      short loc_149F9

loc_149D1:
add     di, 4
cmp     di, word_13CC9
jb      short loc_149CA
cmp     byte_13D1D, 0
jz      short loc_149F7
cmp     byte_1008A, 0
jnz     short loc_149F5
call    GetTrkDatOfs
or      TrackTypeTable[bx], 40h
mov     byte_1008A, 1

loc_149F5:
stc
retn

loc_149F7:
clc
retn

loc_149F9:
cmp     byte ptr unk_13E38[di], 2
jnz     short loc_149D1
mov     si, word ptr unk_14031[di]
add     si, 8
call    FindAddrMark
jb      short loc_149D1
call    MFMDecode
call    MFMDecode
call    MFMDecode
cmp     dl, 0FEh ; '¦'
jz      short loc_149D1
add     si, 800h
cmp     si, word_14035[di]
jb      short loc_149D1
mov     si, word_14035[di]
add     si, 8
call    FindAddrMark
jb      short loc_149D1
call    MFMDecode
call    MFMDecode
call    MFMDecode
cmp     dl, 0FEh ; '¦'
jnz     short loc_149D1
mov     si, word_14035[di]
mov     cx, word ptr unk_14037[di]
add     si, 5Ah ; 'Z'
mov     word_13CE0, 1F8h
mov     word_13D1E, 0

loc_14A55:
mov     dx, es:[si]
mov     word_13CE2, dx
add     si, 2

loc_14A5F:
mov     dx, es:[si]
add     si, 2
cmp     dx, word_13CE2
jnz     short loc_14AAE
dec     word_13CE0
jns     short loc_14A5F

loc_14A71:
cmp     word_13D1E, 0
jz      short loc_14AAB
mov     bx, 0

loc_14A7B:
shl     bx, 1
shl     bx, 1
mov     si, word ptr unk_13D20[bx]
push    bx
mov     bx, word ptr unk_13D22[bx]
mov     bh, 0
mov     ah, 0
mov     al, byte ptr unk_153B4[bx]
and     es:[si], ax
xor     ax, 0FFFFh
and     es:[si+2], ax
pop     bx
shr     bx, 1
shr     bx, 1
inc     bx
cmp     bx, word_13D1E
jb      short loc_14A7B
mov     byte_13D1D, 0FFh

loc_14AAB:
jmp     loc_149D1

loc_14AAE:
sub     si, 2
cmp     dl, byte ptr word_13CE2
jnz     short loc_14AB8
inc     si

loc_14AB8:
mov     dl, es:[si]
xor     dl, es:[si-2]
mov     cl, 0FFh

loc_14AC1:
inc     cl
shl     dl, 1
jnb     short loc_14AC1
mov     bx, word_13D1E
shl     bx, 1
shl     bx, 1
mov     word ptr unk_13D20[bx], si
mov     word ptr unk_13D22[bx], cx
inc     word_13D1E
cmp     word_13D1E, 5
ja      short loc_14AAB
add     si, 3
sub     word_13CE0, 3
js      short loc_14A71
jmp     loc_14A55
sub_149C2 endp




sub_14AEF proc near
mov     di, 4

loc_14AF2:
mov     ax, word ptr unk_13E33[di]
cmp     ax, word ptr unk_13E37[di]
jz      short loc_14B07
add     di, 4
cmp     di, word_13CC9
jb      short loc_14AF2

loc_14B05:
clc
retn

loc_14B07:
sub     di, 4
mov     si, word_14035[di]
mov     ax, word_14039[di]
sub     ax, si
cmp     ax, 1F0h
jb      short loc_14B05
add     si, 8
call    FindAddrMark
jb      short loc_14B05
call    MFMDecode
call    MFMDecode
call    MFMDecode
cmp     dl, 0FEh ; '¦'
jnz     short loc_14B05
call    FindAddrMark
jb      short loc_14B05
call    MFMDecode
call    MFMDecode
call    MFMDecode
cmp     dl, 0FEh ; '¦'
jz      short loc_14B05
mov     si, word_14035[di]
add     si, 48h ; 'H'
mov     cx, 12h

loc_14B4C:
xor     bx, bx

loc_14B4E:
mov     ax, word ptr unk_14B76[bx]
mov     es:[si], ax
inc     si
inc     si
inc     bx
inc     bx
cmp     bx, 10h
jb      short loc_14B4E
loop    loc_14B4C
cmp     byte_1008A, 0
jnz     short loc_14B74
call    GetTrkDatOfs
or      TrackTypeTable[bx], 40h
mov     byte_1008A, 1

loc_14B74:
stc
retn
sub_14AEF endp

unk_14B76 db    0
db    0
db    0
db    0
db  45h ; E
db  51h ; Q
db  45h ; E
db  51h ; Q
db  45h ; E
db  51h ; Q
db  45h ; E
db  51h ; Q
db  45h ; E
db  51h ; Q
db  45h ; E
db  51h ; Q



sub_14B86 proc near
mov     ax, word_14035
mov     word_13CCB, ax
mov     bx, ax
cmp     CurrTrkLngthBytes, 3300h
jb      short loc_14BA1
cmp     CurrTrkLngthBytes, 3480h
ja      short loc_14BA1
call    sub_14FF4

loc_14BA1:
cmp     word_13D07, 0
jz      short loc_14BC1
cmp     bx, word_13D07
jbe     short loc_14BC1
sub     bx, word_13D07
cmp     bx, 0Eh
jb      short loc_14BC1
cmp     bx, 30h ; '0'
ja      short loc_14BC1
mov     byte_13D09, 0FFh

loc_14BC1:
mov     word_13D07, ax
mov     di, 0

loc_14BC7:
and     word ptr unk_14037[di], 0FFh
mov     ax, word_14035[di]
cmp     ax, word_13CCB
jbe     short loc_14BDD
or      word ptr unk_14037[di], 8000h

loc_14BDD:
cmp     byte_13D09, 0FFh
jnz     short loc_14BF5
cmp     CurrentCylinder, 1
jz      short loc_14BF2
cmp     CurrentCylinder, 2
jnz     short loc_14BF5

loc_14BF2:
call    sub_15013

loc_14BF5:
cmp     di, 48h ; 'H'
ja      short loc_14C08
mov     cx, word ptr unk_13E35[di]
cmp     cl, 4Fh ; 'O'
ja      short loc_14C08
cmp     ch, 2
jb      short loc_14C0B

loc_14C08:
call    sub_15013

loc_14C0B:
mov     cl, byte ptr unk_13E38[di]
cmp     cl, 6
jb      short loc_14C25
cmp     cl, 9
ja      short loc_14C1F
call    sub_15013
jmp     loc_14CA2

loc_14C1F:
mov     ax, word_13CCB
jmp     short loc_14C33
db 90h

loc_14C25:
mov     ax, 80h ; 'Ç'
inc     cl
shl     ax, cl
add     ax, word_14035[di]
add     ax, 7Ch ; '|'

loc_14C33:
add     di, 4
cmp     di, word_13CC9
jnb     short loc_14C47
cmp     ax, word_13CCB
jb      short loc_14C45
mov     word_13CCB, ax

loc_14C45:
jmp     short loc_14BC7

loc_14C47:
mov     ax, CurrTrackBufOfs
add     ax, CurrTrkLngthBytes
cmp     ax, word_13CCB
jnb     short loc_14C74
mov     dx, word_13CCB
sub     dx, CurrTrkLngthBytes
mov     di, 0

loc_14C5F:
cmp     dx, word_14035[di]
jbe     short loc_14C74
and     word ptr unk_14037[di], 7FFFh
add     di, 4
cmp     di, word_13CC9
jb      short loc_14C5F

loc_14C74:
mov     di, word_13CC9
sub     di, 4
test    word ptr unk_14037[di], 8000h
jz      short loc_14C86
jmp     loc_14D06

loc_14C86:
mov     di, 0

loc_14C89:
test    word ptr unk_14037[di], 8000h
jnz     short loc_14CA9
add     di, 4
cmp     di, word_13CC9
jb      short loc_14C89
call    sub_15013
call    sub_14ECA
jnb     short loc_14CC8

loc_14CA2:
call    sub_14DA4
jnb     short loc_14CC8
jb      short loc_14D18

loc_14CA9:
cmp     di, 0
jz      short loc_14CB1
call    sub_15013

loc_14CB1:
mov     si, word_14035[di]
mov     cx, word ptr unk_14037[di]
sub     si, 4

loc_14CBC:
sub     si, 4
call    MFMDecode
cmp     dx, 0FF00h
jz      short loc_14CBC

loc_14CC8:
clc

loc_14CC9:
pushf
cmp     byte_13CF8, 0FFh
jnz     short loc_14CE3
cmp     word_13D80, 0Ah
jb      short loc_14CE3
mov     si, word_13D7C
add     si, word_13D80
sub     si, 8

loc_14CE3:
popf
pushf
cmp     KeepTrkLngthFlag, 'Y'
jnz     short loc_14D04
cmp     CopyXIDXFlag, 'Y'
jnz     short loc_14D04
push    si
mov     ax, si
add     ax, CurrTrkLngthBytes
add     ax, 20h ; ' '
mov     EndOfCurrTrk, ax
call    sub_15045
pop     si

loc_14D04:
popf
retn

loc_14D06:
mov     dx, word_13CCB
cmp     dx, CurrTrkLngthBytes
jb      short loc_14D18
mov     di, 0
jmp     short loc_14CA9

loc_14D15:
stc
jmp     short loc_14CC9

loc_14D18:
mov     si, CurrTrackBufOfs
add     si, 28h ; '('
call    FindAddrMark
jb      short loc_14D15
sub     si, 4

loc_14D27:
sub     si, 4
call    MFMDecode
cmp     dx, 0FF00h
jz      short loc_14D27
sub     si, 6
call    MFMDecode
mov     word_13CE2, dx

loc_14D3D:
cmp     si, 4
jbe     short loc_14D5F
sub     si, 4
cmp     si, CurrTrackBufOfs
jbe     short loc_14D5F
call    MFMDecode
cmp     dx, word_13CE2
jz      short loc_14D3D
mov     ax, si
sub     ax, CurrTrackBufOfs
cmp     ax, 4
ja      short loc_14D91

loc_14D5F:
mov     si, ReadLengthBytes
add     si, 6
call    MFMDecode
mov     word_13CE2, dx

loc_14D6D:
sub     si, 4
call    MFMDecode
cmp     dx, word_13CE2
jz      short loc_14D6D
cmp     dh, byte ptr word_13CE2+1
jnz     short loc_14D80
dec     si

loc_14D80:
mov     ax, si
sub     ax, 20h ; ' '
cmp     ax, word_13CCB
ja      short loc_14D91
add     si, 3
call    sub_14FF4

loc_14D91:
mov     ax, es:[si+6]
mov     es:[si+4], ax
mov     es:[si+2], ax
mov     es:[si], ax
clc
jmp     loc_14CC9
sub_14B86 endp




sub_14DA4 proc near
mov     di, 0

loc_14DA7:
mov     si, word_14035[di]
add     si, 4
call    FindAddrMark
jb      short loc_14DCF
call    MFMDecode
call    MFMDecode
call    MFMDecode
cmp     dl, 0FBh ; 'v'
jz      short loc_14E2C
cmp     dl, 0F8h ; '°'
jz      short loc_14E2C

loc_14DC6:
add     di, 4
cmp     di, word_13CC9
jb      short loc_14DA7

loc_14DCF:
mov     di, 4

loc_14DD2:
mov     cl, byte ptr unk_14037[di]
cmp     cl, byte ptr unk_14033[di]
jz      short loc_14E1F
mov     si, word_14035[di]
sub     si, 1Ch
mov     ax, es:[si]

loc_14DE6:
sub     si, 2
cmp     ax, es:[si]
jz      short loc_14DE6
add     si, 2
mov     EndOfCurrTrk, si
add     EndOfCurrTrk, 20h ; ' '
mov     di, si
sub     si, 6
call    MFMDecode
cmp     dx, 14C2h
jnz     short loc_14E1B
sub     si, 20h ; ' '
mov     ax, es:[si]

loc_14E0E:
sub     si, 2
cmp     ax, es:[si]
jz      short loc_14E0E
add     si, 2
mov     di, si

loc_14E1B:
mov     si, di
clc
retn

loc_14E1F:
add     di, 4
cmp     di, word_13CC9
jb      short loc_14DD2
call    sub_14EA2
retn

loc_14E2C:
sub     si, 0Ah

loc_14E2F:
sub     si, 4
call    MFMDecode
push    dx
and     dx, 7FFFh
cmp     dx, 7F00h
pop     dx
jz      short loc_14E2F
push    dx
sub     si, 4
call    MFMDecode
pop     cx
cmp     dx, cx
jnz     short loc_14E50
jmp     loc_14DC6

loc_14E50:
clc
retn
sub_14DA4 endp




sub_14E52 proc near
mov     bh, 0
mov     ah, 0
xor     dx, dx
xor     di, di
xor     bp, bp
mov     si, CurrTrackBufOfs
mov     cx, EndOfCurrTrk
sub     cx, si

loc_14E66:
lods    byte ptr es:[si]
mov     bl, al
cmp     al, byte_17F79[bx]
jz      short loc_14E77
mov     ah, 0
inc     dx

loc_14E73:
inc     bp
jmp     short loc_14E91
db 90h

loc_14E77:
inc     ah
cmp     ah, 1
jbe     short loc_14E73
mov     ah, 2
cmp     bp, di
jb      short loc_14E8E
mov     di, bp
mov     bp, si
sub     bp, di
mov     word_13D7C, bp

loc_14E8E:
mov     bp, 0

loc_14E91:
loop    loc_14E66
cmp     di, 0
jz      short loc_14E99
dec     di

loc_14E99:
mov     word_13D7E, dx
mov     word_13D80, di
retn
sub_14E52 endp




sub_14EA2 proc near
mov     si, CurrTrackBufOfs
add     si, 0Ah
mov     dx, CurrTrkLngthBytes
add     dx, si
add     dx, 40h ; '@'
mov     bh, 0

loc_14EB4:
mov     bl, es:[si]
mov     al, byte_17F79[bx]
cmp     al, bl
jnz     short loc_14EC6
inc     si
cmp     si, dx
jb      short loc_14EB4
stc
retn

loc_14EC6:
clc
retn
sub_14EA2 endp


loc_14EC8:
stc
retn



sub_14ECA proc near
mov     di, 0

loc_14ECD:
cmp     byte ptr unk_13E38[di], 3
jnz     short loc_14EC8
add     di, 4
cmp     di, word_13CC9
jb      short loc_14ECD
mov     si, word_14035
sub     si, 1Eh
mov     ax, es:[si]

loc_14EE7:
sub     si, 2
cmp     ax, es:[si]
jz      short loc_14EE7
sub     si, 0Ch
mov     ax, es:[si]

loc_14EF5:
sub     si, 2
cmp     ax, es:[si]
jz      short loc_14EF5
cmp     ah, es:[si+1]
jnz     short loc_14F08
dec     si
mov     ax, es:[si+2]

loc_14F08:
mov     es:[si], ax
mov     ax, si
mov     di, word_13CEE
mov     si, word ptr unk_1422D[di]
add     si, 460h
sub     si, CurrTrkLngthBytes
clc
retn
sub_14ECA endp




sub_14F1F proc near
mov     ax, EndOfCurrTrk
push    ax
push    si
mov     EndOfCurrTrk, si
add     EndOfCurrTrk, 100h
sub     si, 5
cmp     si, word_13CCB
jnb     short loc_14F3B
mov     si, word_13CCB

loc_14F3B:
mov     byte_13CF9, 0Ah

loc_14F40:
mov     cl, 7

loc_14F42:
call    MFMDecode
sub     si, 2
and     dx, 0FFFEh
cmp     dx, 904Eh
jz      short loc_14F60
dec     cl
jns     short loc_14F42
inc     si
dec     byte_13CF9
jnz     short loc_14F40
stc
jmp     short loc_14F93
align 2

loc_14F60:
mov     ch, 7
sub     ch, cl
mov     cl, ch
mov     byte_13CF9, 8
cmp     KeepTrkLngthFlag, 59h ; 'Y'
jz      short loc_14F77
mov     byte_13CF9, 0C8h ; '+'

loc_14F77:
mov     ax, 9254h
shr     ax, cl
mov     es:[si+1], al
mov     ax, 5492h
shr     ax, cl
mov     es:[si+2], al
add     si, 2
dec     byte_13CF9
jnz     short loc_14F77
clc

loc_14F93:
pushf
mov     si, word_13CF4
sub     si, 8
mov     cx, 6
mov     ax, es:[si]

loc_14FA1:
inc     si
inc     si
cmp     ax, es:[si]
jnz     short loc_14FAD
loop    loc_14FA1
jmp     short loc_14FDD
db 90h

loc_14FAD:
cmp     al, es:[si]
jnz     short loc_14FB3
inc     si

loc_14FB3:
mov     dx, si
add     si, 2
mov     ax, es:[si]
mov     cx, 6

loc_14FBE:
inc     si
inc     si
cmp     ax, es:[si]
jnz     short loc_14FDD
loop    loc_14FBE
mov     si, dx
cmp     si, word_13CCB
jbe     short loc_14FDD
mov     ax, es:[si-2]
mov     cx, 4

loc_14FD6:
mov     es:[si], ax
inc     si
inc     si
loop    loc_14FD6

loc_14FDD:
popf
pop     si
pop     ax
mov     EndOfCurrTrk, ax
retn
sub_14F1F endp




sub_14FE4 proc near
mov     KeepTrkLngthFlag, 4Eh ; 'N'
push    bx
call    GetTrkDatOfs
and     byte ptr TrackTypeTable[bx], 0FEh
pop     bx
retn
sub_14FE4 endp




sub_14FF4 proc near
cmp     NK_SwitchUsed, 0
jz      short locret_15012
cmp     CurrTrkLngthBytes, 2F00h
jb      short locret_15012
mov     KeepTrkLngthFlag, 'Y'
push    bx
call    GetTrkDatOfs
or      TrackTypeTable[bx], 1
pop     bx

locret_15012:
retn
sub_14FF4 endp




sub_15013 proc near
cmp     NK_SwitchUsed, 0
jz      short locret_15044
cmp     CurrTrkLngthBytes, 2F00h
jb      short locret_15044
mov     KeepTrkLngthFlag, 'Y'
push    bx
call    GetTrkDatOfs
or      TrackTypeTable[bx], 1
cmp     DuplicatorReturn, 0
jnz     short loc_15043
cmp     word_13D7E, 32h ; '2'
jnb     short loc_15043
or      TrackTypeTable[bx], 20h

loc_15043:
pop     bx

locret_15044:
retn
sub_15013 endp




sub_15045 proc near
mov     word_13CCD, 0FFFEh
mov     byte_13CF8, 0
mov     byte_13CF7, 0A1h ; 'í'
mov     bp, 0
mov     di, 0
mov     byte_13CEB, 0
mov     word_13CEC, 0

loc_15066:
call    FindAddrMark
jnb     short loc_1506E
jmp     loc_1511B

loc_1506E:
call    MFMDecode
mov     byte_13CEB, dl
call    MFMDecode
mov     byte_13CF7, dl
call    MFMDecode
mov     ch, 0
mov     ax, si
sub     ax, 6
cmp     byte_13CEB, 0C2h ; '-' ; C2h=index mark
jnz     short loc_15090
jmp     loc_15112

loc_15090:              ; FEh=sector ID follows
cmp     dl, 0FEh ; '¦'
jnz     short loc_15066
mov     word_14035[di], ax
mov     word ptr unk_14037[di], cx
mov     ax, si
sub     ax, word_13CEC
cmp     ax, si
jz      short loc_150B7
mov     dx, si
add     dx, 12h
cmp     dx, EndOfCurrTrk
jnb     short loc_150B7
cmp     ax, 350h
jb      short loc_150C8

loc_150B7:
mov     word_13CEC, si
mov     ds:word_14235[bp], si
mov     ds:word_14237[bp], cx
add     bp, 4

loc_150C8:
cmp     di, 0
jnz     short loc_150DD
call    RdTrkLngthTbl
add     dx, si
add     dx, 10h
mov     word_13CCD, dx
mov     EndOfCurrTrk, dx

loc_150DD:
call    MFMDecode
mov     byte ptr unk_13E35[di], dl
inc     di
call    MFMDecode
mov     byte ptr unk_13E35[di], dl
inc     di
call    MFMDecode
mov     byte ptr unk_13E35[di], dl
inc     di
call    MFMDecode
cmp     dl, 3
jb      short loc_15107
cmp     dl, 9
ja      short loc_15107
mov     byte_13CF8, 0FFh

loc_15107:
mov     byte ptr unk_13E35[di], dl
inc     di
cmp     di, 200h
jnb     short loc_1511B

loc_15112:
cmp     si, word_13CCD
jnb     short loc_1511B
jmp     loc_15066

loc_1511B:
cmp     bp, 8
jb      short loc_15135
mov     ax, word ptr ds:unk_14231[bp]
sub     ax, word_14235
sub     ax, 10h
cmp     ax, CurrTrkLngthBytes
jb      short loc_15135
sub     bp, 4

loc_15135:
mov     word_13CC9, di
mov     word_13CEE, bp
retn
sub_15045 endp




sub_1513E proc near
cmp     word_13CC9, 0
jz      short locret_15185
push    ax
push    bx
push    cx
push    dx
push    es
push    di
push    si
push    ds
mov     bx, CurrentTrack
shr     bx, 1
cmp     byte ptr unk_161CA[bx], 2
jz      short loc_15161
cmp     CpyWkBitsFlag, 'Y'
jnz     short loc_1517D

loc_15161:
mov     si, 0

loc_15164:
mov     word_13CD5, si
call    sub_15186
jnb     short loc_15170
call    sub_15242

loc_15170:
mov     si, word_13CD5
add     si, 4
cmp     si, word_13CC9
jb      short loc_15164

loc_1517D:
pop     ds
assume ds:nothing
pop     si
pop     di
pop     es
pop     dx
pop     cx
pop     bx
pop     ax

locret_15185:
retn
sub_1513E endp




sub_15186 proc near
mov     di, si
cmp     ds:word_13CC9, 28h ; '('
jbe     short loc_151AA
mov     ax, ds:word_13CC9
dec     ax
shr     ax, 1
shl     di, 1
cmp     si, ax
jbe     short loc_151AA
shr     di, 1
and     ax, 0FCh
sub     di, 4
sub     di, ax
shl     di, 1
add     di, 4

loc_151AA:
mov     ds:word_13D0C, di
mov     al, byte ptr ds:unk_13E35[di]
mov     ds:Cylinder, al
mov     al, byte ptr ds:unk_13E36[di]
mov     ds:CurrentHead, al
mov     al, byte ptr ds:unk_13E37[di]
mov     ds:SectorNumber, al
mov     al, byte ptr ds:unk_13E38[di]
mov     ds:SectorSize, al
cmp     al, 6
jbe     short loc_151D0
mov     al, 6

loc_151D0:
add     si, 4
mov     cl, al
mov     ax, 80h ; 'Ç'
shl     ax, cl
mov     ds:DMACount, ax
mov     dx, ds:word_13CF4
mov     bx, ds:word_14035[di]
add     di, 4
cmp     di, ds:word_13CC9
jb      short loc_151F7
mov     cx, dx
add     cx, ds:word_14035
jmp     short loc_151FB
db 90h

loc_151F7:
mov     cx, ds:word_14035[di]

loc_151FB:
cmp     cx, dx
jb      short loc_15201
mov     cx, dx

loc_15201:
sub     cx, bx
sub     di, 4
sub     cx, 58h ; 'X'
jns     short loc_1520D

loc_1520B:
clc
retn

loc_1520D:
cmp     cx, ax
ja      short loc_1521A
mov     ax, cx
sub     ax, 8
js      short loc_1520B
shr     ax, 1

loc_1521A:
mov     ds:word_13CCF, ax
mov     al, 46h ; 'F'
mov     bl, byte ptr ds:word_1005C+1
mov     bh, ds:byte_1005B
call    sub_17186
call    sub_1708E
and     al, 0C0h
jz      short loc_1523D
and     ah, 20h
jz      short loc_1523D
and     bl, 20h
jz      short loc_1523D
stc
retn

loc_1523D:
call    sub_1553C
clc
retn
sub_15186 endp




sub_15242 proc near
mov     al, 46h ; 'F'
mov     bl, byte ptr ds:word_1005E+1
mov     bh, ds:byte_1005B
call    sub_17186
call    sub_1708E
and     al, 0C0h
jz      short locret_15280
and     ah, 20h
jz      short locret_15280
and     bl, 20h
jz      short locret_15280
mov     bp, ds:word_1005C
mov     bx, ds:word_1005E
mov     cx, ds:word_13CCF
mov     es, ds:word_10059

loc_15270:
mov     al, es:[bp+0]
cmp     al, es:[bx]
jnz     short loc_15281
inc     bx
inc     bp
loop    loc_15270
jmp     locret_1535F

locret_15280:
retn

loc_15281:
mov     ds:byte_1008A, 1
mov     ds:word_13CD1, bp
mov     ds:word_13CD3, bx
call    sub_153BC
jb      short locret_15280
sub     bx, ds:word_1005E
shl     bx, 1
mov     ds:word_10044, bx
mov     es, ds:TrackBufSeg
mov     si, ds:word_14035[di]
add     si, 0Eh
call    FindAddrMark
call    MFMDecode
call    MFMDecode
call    MFMDecode
mov     ax, ds:word_14039[di]
sub     ax, 1Ah
sub     ax, si
shr     ax, 1
cmp     ax, ds:word_13CCF
ja      short loc_152C8
mov     ds:word_13CCF, ax

loc_152C8:
mov     ds:word_13D0A, si
add     si, ds:word_10044
mov     dx, ds:word_10044
shr     dx, 1
push    es
mov     es, ds:word_10059
mov     bx, ds:word_1005E
add     bx, ds:word_13CCF
sub     bx, 2
mov     al, es:[bx]

loc_152E9:
dec     bx
cmp     bx, ds:word_13CD3
jbe     short loc_152F5
cmp     al, es:[bx]
jz      short loc_152E9

loc_152F5:
sub     bx, ds:word_1005E
mov     ds:word_13CCD, bx
pop     es
mov     bx, ds:word_13CD3
mov     bp, ds:word_13CD1

loc_15306:
push    es
mov     es, ds:word_10059
mov     al, es:[bp+0]
cmp     al, es:[bx]
jz      short loc_15353
cmp     al, es:[bp+1]
jnz     short loc_1532E
cmp     al, es:[bp+2]
jnz     short loc_1532E

loc_15320:
inc     si
inc     si
inc     bx
inc     bp
inc     dx
cmp     al, es:[bp+0]
jz      short loc_15320
jmp     short loc_15353
align 2

loc_1532E:
pop     es
push    bx
mov     bh, 0
mov     bl, cl
mov     ah, 0
mov     di, si
add     di, ds:CurrTrkLngthBytes
mov     al, byte ptr ds:unk_153B4[bx]
and     es:[si], ax
and     es:[di], ax
xor     ax, 0FFFFh
and     es:[si+2], ax
and     es:[di+2], ax
pop     bx
push    es

loc_15353:
pop     es
assume es:nothing
inc     si
inc     si
inc     bp
inc     bx
inc     dx
cmp     dx, ds:word_13CCD
jbe     short loc_15306

locret_1535F:
retn
sub_15242 endp

xor     dx, dx
mov     si, ds:word_13D0A
shl     ds:word_13CCD, 1

loc_1536A:
mov     al, es:[si]
test    al, 0F0h
jz      short loc_15381
test    al, 78h
jz      short loc_15381
test    al, 3Ch
jz      short loc_15381
test    al, 1Eh
jz      short loc_15381
test    al, 0Fh
jnz     short loc_1538A

loc_15381:
mov     ds:byte_1008A, 1
mov     byte ptr es:[si], 0

loc_1538A:
mov     di, si
add     di, ds:CurrTrkLngthBytes
mov     al, es:[di]
test    al, 0F0h
jz      short loc_153A7
test    al, 78h
jz      short loc_153A7
test    al, 3Ch
jz      short loc_153A7
test    al, 1Eh
jz      short loc_153A7
test    al, 0Fh
jnz     short loc_153AB

loc_153A7:
mov     byte ptr es:[di], 0

loc_153AB:
inc     si
inc     dx
cmp     dx, ds:word_13CCD
jbe     short loc_1536A
retn
unk_153B4 db    0
db  80h ; Ç
db 0C0h ; +
db 0E0h ; a
db 0F0h ; =
db 0F8h ; °
db 0FCh ; n
db 0FEh ; ¦



sub_153BC proc near
push    bx
push    di
push    si
call    sub_153CE
jb      short loc_153CA
call    sub_15486
jb      short loc_153CA
clc

loc_153CA:
pop     si
pop     di
pop     bx
retn
sub_153BC endp




sub_153CE proc near
mov     si, ds:word_1005C
mov     es, ds:word_10059
assume es:nothing
mov     di, 0

loc_153D9:              ; "MegaSoft"
mov     al, byte ptr ds:aMegasoft[di]
cmp     al, 0
jz      short loc_153EC
cmp     es:[si], al
jnz     short loc_153EA
inc     di
inc     si
jmp     short loc_153D9

loc_153EA:
clc
retn

loc_153EC:
mov     es, ds:TrackBufSeg
mov     di, ds:word_13D0C
mov     si, ds:word_14035[di]
add     si, 0Eh
call    FindAddrMark
call    MFMDecode
call    MFMDecode
call    MFMDecode
add     si, 20h ; ' '
mov     ds:byte_13CF9, 4

loc_1540F:
mov     bx, 18h

loc_15412:
push    bx
call    MFMDecode
pop     bx
cmp     dx, 904Eh
jz      short loc_15426
sub     si, 2
call    sub_1846D
dec     bx
jnz     short loc_15412

loc_15426:
mov     bx, 1Eh

loc_15429:
push    bx
call    MFMDecode
pop     bx
cmp     dx, 0FF00h
jz      short loc_15445
cmp     dx, 0FFh
jnz     short loc_15440
sub     si, 2
call    sub_1846D

loc_15440:
dec     bx
jnz     short loc_15429
jmp     short loc_153EA

loc_15445:
mov     bx, 1Eh

loc_15448:
push    bx
call    MFMDecode
pop     bx
cmp     dx, 0FF00h
jnz     short loc_15458
dec     bx
jnz     short loc_15448
jmp     short loc_153EA

loc_15458:
mov     bh, 0
mov     bl, 7
sub     bl, cl
mov     al, byte ptr ds:unk_153B4[bx]
and     es:[si-2], al
mov     byte ptr es:[si-1], 0
xor     al, 0FFh
and     es:[si], al
dec     ds:byte_13CF9
jnz     short loc_1540F
mov     ds:byte_1008A, 1
stc
retn
sub_153CE endp

aMegasoft db 'MegaSoft',0



sub_15486 proc near
push    bp
mov     bp, 0
call    sub_15498
jnb     short loc_15496
mov     bp, 1
call    sub_15498
stc

loc_15496:
pop     bp
retn
sub_15486 endp




sub_15498 proc near
mov     es, ds:TrackBufSeg
mov     di, ds:word_13D0C
mov     si, ds:word_14035[di]
add     si, 0Eh
call    FindAddrMark
call    MFMDecode
call    MFMDecode
call    MFMDecode
mov     ds:byte_13CF9, 88h ; 'ê'

loc_154B8:
mov     bx, 28h ; '('

loc_154BB:
push    bx
call    MFMDecode
pop     bx
cmp     dx, 0FF00h
jz      short loc_154CB
dec     bx
jnz     short loc_154BB

loc_154C9:
clc
retn

loc_154CB:
mov     bx, 28h ; '('

loc_154CE:
push    bx
call    MFMDecode
pop     bx
cmp     dx, 0FF00h
jnz     short loc_154DE
dec     bx
jnz     short loc_154CE
jmp     short loc_154C9

loc_154DE:
mov     bx, 1Eh
sub     si, 2

loc_154E4:
push    bx
call    MFMDecode
pop     bx
cmp     dl, ds:byte_13CF9
jz      short loc_154FA
sub     si, 2
call    sub_1846D
dec     bx
jnz     short loc_154E4
jmp     short loc_154C9

loc_154FA:
cmp     bp, 0
jz      short loc_1551A
sub     si, 2
mov     bh, 0
mov     bl, 7
sub     bl, cl
mov     al, byte ptr ds:unk_153B4[bx]
and     es:[si-2], al
mov     byte ptr es:[si-1], 8
xor     al, 0FFh
and     es:[si], al

loc_1551A:
cmp     ds:byte_13CF9, 0FEh ; '¦'
jz      short loc_15534
add     ds:byte_13CF9, 11h
cmp     ds:byte_13CF9, 0FFh
jnz     short loc_154B8
mov     ds:byte_13CF9, 0FEh ; '¦'
jmp     short loc_154B8

loc_15534:
mov     ds:byte_1008A, 1
stc
retn
sub_15498 endp


locret_1553B:
retn



sub_1553C proc near
cmp     ds:Cylinder, 27h ; '''
jb      short locret_1553B
cmp     ds:SectorNumber, 1
jnz     short locret_1553B
cmp     ds:SectorSize, 2
jnz     short locret_1553B
mov     es, ds:word_10059
mov     bp, ds:word_1005C
mov     bx, offset aBtbfmEsps ; "Btbfm!Esps"
mov     cx, 80h ; 'Ç'

loc_1555F:
mov     al, [bx]
cmp     al, 0
jz      short loc_15578
dec     al
cmp     al, es:[bp+0]
jnz     short loc_15571
inc     bx
jmp     short loc_15574
db 90h

loc_15571:              ; "Btbfm!Esps"
mov     bx, offset aBtbfmEsps

loc_15574:
inc     bp
loop    loc_1555F
retn

loc_15578:
mov     ds:byte_1008A, 1
mov     ax, ds:word_13CC9
mov     ds:word_13CD5, ax
call    sub_14FE4
mov     ds:SectorNumber, 3
mov     es, ds:TrackBufSeg
mov     si, ds:word_14039
add     si, 2C5h

loc_15597:
mov     ax, 0C00h
call    RepMFM
mov     cx, 3
mov     ax, 0AA1h
call    RepMFM_Clk
mov     ax, 1FEh
call    RepMFM
mov     ah, 1
mov     al, ds:Cylinder
call    RepMFM
mov     al, ds:CurrentHead
call    RepMFM
mov     al, ds:SectorNumber
call    RepMFM
mov     ax, 101h
call    RepMFM
call    IDCRC
mov     ax, 164Eh
call    RepMFM
mov     ax, 0B00h
call    RepMFM
mov     ax, 0
mov     cx, 1
call    RepMFM_Clk
mov     cx, 3
mov     ax, 0AA1h
call    RepMFM_Clk
mov     ax, 1FBh
call    RepMFM
add     si, 268h
inc     ds:SectorNumber
cmp     ds:SectorNumber, 0Fh
jb      short loc_15597
retn
sub_1553C endp

aBtbfmEsps db 'Btbfm!Esps',0


; MFM encodes byte AL AH times at ES:SI with normal clock.

RepMFM proc near
push    ax

loc_15609:
push    ax
call    Encode_MFM_Normal
pop     ax
dec     ah
jnz     short loc_15609
pop     ax
retn
RepMFM endp



; MFM encodes byte AL with clock bits AH CX times
; at ES:SI. Used for making address marks.

RepMFM_Clk proc near
push    cx
push    ax

loc_15616:
push    cx
push    ax
call    Encode_MFM_AM
pop     ax
pop     cx
loop    loc_15616
pop     ax
pop     cx
retn
RepMFM_Clk endp



; Creates sector ID CRC at ES:SI.

IDCRC proc near
push    es
push    si
mov     ds:IDCRC_scratch+0Eh, al ; sector size
mov     al, ds:Cylinder
mov     ds:IDCRC_scratch+8, al ; cylinder
mov     al, ds:CurrentHead
mov     ds:IDCRC_scratch+0Ah, al ; head
mov     al, ds:SectorNumber
mov     ds:IDCRC_scratch+0Ch, al ; sector number
mov     ax, 10h
mov     si, offset IDCRC_scratch
push    cs
pop     es
assume es:seg001
call    CRC
pop     si
pop     es
assume es:nothing
mov     al, bh
call    Encode_MFM_Normal
mov     al, bl
call    Encode_MFM_Normal
retn
IDCRC endp

IDCRC_scratch db 0A1h, 0Ah, 0A1h, 0Ah, 0A1h, 0Ah, 0FEh ; A sector ID is placed here so a CRC can be generated.
db 0, 0, 0, 0, 0, 0, 0, 0, 0

locret_15661:
retn



sub_15662 proc near
cmp     ds:F_SwitchUsed, 80h ; 'Ç'
jnz     short locret_15661
mov     al, ds:CurrentCylinder
cmp     ds:EndingCylinder, 2Ah ; '*'
jnb     short loc_15680
cmp     al, 27h ; '''
jz      short loc_1568A
cmp     al, ds:EndingCylinder
jnz     short locret_15661
jmp     short loc_1568A
align 2

loc_15680:
cmp     al, 4Fh ; 'O'
jz      short loc_1568A
cmp     al, ds:EndingCylinder
jnz     short locret_15661

loc_1568A:
call    sub_1588A
mov     al, ds:CurrentCylinder
mov     ds:Cylinder, al
mov     ds:SectorNumber, 1
mov     al, ds:CurrentSide
mov     ds:CurrentHead, al
mov     es, ds:TrackBufSeg
xor     si, si
mov     ax, 7D4Eh
call    RepMFM
mov     ax, 0C00h
call    RepMFM
mov     cx, 3
mov     ax, 0AA1h
call    RepMFM_Clk
mov     ax, 1FEh
call    RepMFM
mov     ah, 1
mov     al, ds:CurrentCylinder
call    RepMFM
mov     al, ds:CurrentSide
call    RepMFM
mov     al, 1
call    RepMFM
mov     al, 5
call    RepMFM
call    IDCRC
mov     ax, 164Eh
call    RepMFM
mov     ax, 0C00h
call    RepMFM
mov     cx, 3
mov     ax, 0AA1h
call    RepMFM_Clk
mov     ax, 1FBh
call    RepMFM
mov     cx, 1000h

loc_156F8:
mov     al, cl
mov     ah, 1
push    cx
call    Encode_MFM_Normal
pop     cx
loop    loc_156F8
mov     ax, 155h
call    RepMFM
mov     ax, 19Ah
call    RepMFM
mov     cx, 0BB8h
mov     ax, 904Eh
call    RepMFM_Clk
cli
call    ClearTimer0
call    sub_16BAA
call    MaskDMA
call    TrackReadOn
mov     dh, ds:CurrentSide
call    SelectHead
mov     ax, 30D4h
mov     ds:DMACount, ax
mov     bx, ds:TrackBufSeg
mov     ax, ds:TrackBufOfs
mov     bl, ah
shr     bh, 1
shr     bh, 1
shr     bh, 1
shr     bh, 1
mov     al, 4Ah ; 'J'
call    SetupDMA
mov     dx, ds:TC_Port_Base

loc_1574C:
in      al, dx
and     al, 80h
jnz     short loc_1574C
jmp     short loc_15754
align 2

loc_15754:
in      al, dx
and     al, 80h
jz      short loc_15754
call    sub_168AE
mov     bl, cl
mov     bh, 0
mov     al, byte ptr ds:unk_13D73[bx]
call    WriteTC_Port4
mov     al, ds:TC_Port3Byte
or      al, 5
call    WriteTC_Port3
call    UnmaskDMA

loc_15772:
call    ReadDMAWrdCnt
mov     cx, bx

loc_15777:
call    ReadDMAWrdCnt
cmp     bx, 1800h
jbe     short loc_15791
add     bx, 40h ; '@'
cmp     bx, cx
ja      short loc_15777
mov     al, ds:TC_Port4Byte
xor     al, 1
call    WriteTC_Port4
jmp     short loc_15772

loc_15791:
mov     al, ds:TC_Port4Byte
or      al, 1

loc_15796:
call    WriteTC_Port4
call    ReadDMAWrdCnt
mov     cx, bx

loc_1579E:
call    ReadDMAWrdCnt
cmp     bx, 1000h
jbe     short loc_157B5
add     bx, 40h ; '@'
cmp     bx, cx
ja      short loc_1579E
mov     al, ds:TC_Port4Byte
xor     al, 3
jmp     short loc_15796

loc_157B5:
mov     al, ds:TC_Port4Byte
test    al, 1
jz      short loc_157BE
xor     al, 3

loc_157BE:
call    WriteTC_Port4
call    ReadDMAWrdCnt
mov     cx, bx

loc_157C6:
call    ReadDMAWrdCnt
cmp     bx, 800h
jbe     short loc_157DD
add     bx, 40h ; '@'
cmp     bx, cx
ja      short loc_157C6
mov     al, ds:TC_Port4Byte
xor     al, 1
jmp     short loc_157BE

loc_157DD:
mov     al, ds:TC_Port4Byte
or      al, 1

loc_157E2:
call    WriteTC_Port4
call    ReadDMAWrdCnt
mov     cx, bx

loc_157EA:
call    ReadDMAWrdCnt
cmp     bx, 0FFFFh
jz      short loc_15805
cmp     bx, 0
jz      short loc_15805
add     bx, 40h ; '@'
cmp     bx, cx
ja      short loc_157EA
mov     al, ds:TC_Port4Byte
xor     al, 7
jmp     short loc_157E2

loc_15805:
call    WaitForDMA
mov     al, ds:TC_Port3Byte
and     al, 0F8h
call    WriteTC_Port3
call    MaskDMA
sti
mov     dh, 80h ; 'Ç'
call    SelectHead
call    TrackReadOff
call    sub_16877
push    es
xor     ax, ax
mov     es, ax
assume es:nothing
mov     bx, 78h ; 'x'
les     bx, es:[bx]
assume es:nothing
mov     al, es:[bx+3]
mov     byte ptr es:[bx+3], 5
push    ax
push    bx
push    es
mov     bx, 5

loc_15839:
mov     ax, 401h
mov     ch, ds:CurrentCylinder
mov     cl, 1
mov     dh, ds:CurrentSide
mov     dl, ds:CurrentDrive
int     13h             ; DISK - VERIFY SECTORS
                        ; AL = number of sectors to verify, CH = track, CL = sector
                        ; DH = head, DL = drive
                        ; Return: CF set on error, AH = status
                        ; AL = number of sectors verified
jnb     short loc_15878
cmp     ah, 6
jz      short loc_15858
test    ah, 80h
jz      short loc_1585F

loc_15858:
mov     ax, 401h
int     13h             ; DISK - VERIFY SECTORS
                        ; AL = number of sectors to verify, CH = track, CL = sector
                        ; DH = head, DL = drive
                        ; Return: CF set on error, AH = status
                        ; AL = number of sectors verified
jnb     short loc_15878

loc_1585F:
test    ah, 0E0h
jnz     short loc_1586C
cmp     bx, 2
jbe     short loc_1586C
mov     bx, 2

loc_1586C:
mov     ah, 0
mov     dl, ds:CurrentDrive
int     13h             ; DISK - RESET DISK SYSTEM
                        ; DL = drive (if bit 7 is set both hard disks and floppy disks reset)
dec     bx
jnz     short loc_15839
stc

loc_15878:
pop     es
pop     bx
pop     ax
mov     es:[bx+3], al
mov     al, 0
jnb     short loc_15885
mov     al, 0FFh

loc_15885:
mov     ds:F_SwitchUsed, al
pop     es
retn
sub_15662 endp




sub_1588A proc near
pushf
cli
call    ClearTimer0
mov     cx, 4E20h

loc_15892:              ; Latch timer 0 count.
mov     al, 6           ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
mov     bl, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
mov     bh, al
mov     al, 6           ; Latch timer 0 count.
                        ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
mov     ah, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
xchg    ah, al
sub     ax, bx
cmp     ah, 0
jnz     short loc_158C6
cmp     al, 40h ; '@'
ja      short loc_158C6
mov     ds:byte_13D1C, 0FFh
popf
retn

loc_158C6:
loop    loc_15892
popf
retn
sub_1588A endp




WriteTrack proc near
call    SetDmaCount
call    GetTrkDatOfs
mov     ds:CurrentTrack, bx
mov     ax, ds:TrackTypeTable[bx]
mov     ds:DiskType, ah
mov     bl, byte ptr ds:TrackTypeTable[bx]
test    bl, 80h
jz      short loc_158EA
mov     ds:KeepTrkLngthFlag, 'N'

loc_158EA:
call    sub_15D77
cmp     ds:word_1006A, 8
jb      short loc_15903
mov     ax, ds:CurrTrkLngthBytes
mov     dx, 8
mul     dx
mov     ds:TrackLengthBits, ax
mov     ds:TrkLnBitsHiByte, dx

loc_15903:
mov     bx, ds:CurrentTrack
mov     ax, ds:TrackSkewTbl[bx]
cmp     ds:KeepTrkLngthFlag, 'Y'
jz      short $+2
mov     bl, ds:CurrentDrive
mov     bh, 0
shl     bx, 1
mov     dx, word ptr ds:stru_15F64.Drive0[bx]
mul     dx
mov     al, ah
mov     ah, dl
mov     dl, dh
mov     dh, 0
shr     dx, 1
rcr     ax, 1
shr     dx, 1
rcr     ax, 1
mov     ds:TrackSkewDly1, dx
mov     ds:word_10072, ax
mov     ds:trackSkewDly2, dx
mov     ds:word_13D18, ax
jmp     short loc_159A7
db  90h ; É
call    RdTrkLngthTbl
push    dx
mov     bl, ds:CurrentDrive
mov     bh, 0
shl     bx, 1
shl     bx, 1
mov     dx, ds:word_15F6E[bx]
mov     cx, ds:word_15F6C[bx]
shr     dx, 1
rcr     cx, 1
shr     dx, 1
rcr     cx, 1
shr     dx, 1
rcr     cx, 1
mul     cx
pop     cx
div     cx
xor     dx, dx
shl     ax, 1
rcl     dx, 1
shl     ax, 1
rcl     dx, 1
shl     ax, 1
rcl     dx, 1
mov     ds:TrackSkewDly1, dx
mov     ds:word_10072, ax
push    ax
push    dx
push    cx
mov     al, ah
mov     ah, dl
mov     dl, dh
mov     dh, 0
mov     cx, 2
sub     ds:word_10072, ax
sbb     ds:TrackSkewDly1, dx
mov     cx, 1

loc_15996:
shl     ax, 1
rcl     dx, 1
loop    loc_15996
sub     ds:word_10072, ax
sbb     ds:TrackSkewDly1, dx
pop     cx
pop     dx
pop     ax

loc_159A7:
mov     bl, ds:CurrentDrive
mov     bh, 0
shl     bx, 1
shl     bx, 1
add     ax, 1000h
adc     dx, 0
sub     ax, ds:word_15F6C[bx]
sbb     dx, ds:word_15F6E[bx]
jb      short loc_159D9
mov     ds:TrackSkewDly1, 0
mov     ds:word_10072, 0Ah
mov     ds:trackSkewDly2, 0
mov     ds:word_13D18, 0Ah

loc_159D9:
call    sub_15662
call    sub_16937
retn
WriteTrack endp




sub_159E0 proc near
cmp     ds:KeepTrkLngthFlag, 59h ; 'Y'
jnz     short loc_159EC
mov     ds:byte_13D11, 0FFh

loc_159EC:
call    GetTrkDatOfs
mov     cl, 4
shl     bx, cl
mov     bp, bx
cmp     si, ds:CurrTrkLngthBytes
jb      short loc_159FF
sub     si, ds:CurrTrkLngthBytes

loc_159FF:
mov     ds:word_13D7A, si
cmp     ds:word_13CEE, 0Ch
jnb     short loc_15A31
mov     bx, ds:CurrTrkLngthBytes
shr     bx, 1
shr     bx, 1
mov     ax, ds:CurrTrackBufOfs
add     ax, bx
mov     ds:word_14235, ax
add     ax, bx
mov     ds:word_14239, ax
mov     ax, ds:CurrTrackBufOfs
add     ax, bx
add     ax, ds:CurrTrkLngthBytes
mov     ds:word_1423D, ax
mov     ds:word_13CEE, 0Ch

loc_15A31:
cmp     ds:byte_13D1C, 0
jz      short loc_15A3E
call    sub_15D16
jmp     short loc_15A48
align 2

loc_15A3E:
mov     ds:byte_13D79, 0

loc_15A43:
push    si
call    sub_15A5E
pop     si

loc_15A48:
mov     ax, ds:word_10072
inc     ds:byte_13D79
cmp     ds:byte_13D79, 1
jb      short loc_15A43
call    GetTrkDatOfs
mov     ds:TrackSkewTbl[bx], ax
retn
sub_159E0 endp




sub_15A5E proc near
mov     ds:byte_13D12, 0
mov     ds:word_10072, 0
mov     ax, ds:TrackBufSeg
mov     al, byte ptr ds:TrackBufOfs+1
mov     bx, ax
shr     bh, 1
shr     bh, 1
shr     bh, 1
shr     bh, 1
mov     ds:word_13CDA, bx
mov     ds:word_13CD8, ax
call    SetDmaCount
shl     ax, 1
mov     ds:DMACount, ax
call    TrackReadOn
cli
call    ClearTimer0
call    SetReadspeed
mov     dh, ds:CurrentSide
call    SelectHead
mov     bx, ds:word_13CDA
mov     ax, ds:word_13CD8
mov     al, 42h ; 'B'
call    SetupDMA
mov     dx, ds:TC_Port_Base
mov     bl, ds:TC_Port3Byte
or      bl, 3

loc_15AB0:
in      al, dx
and     al, 80h
jnz     short loc_15AB0
jmp     short $+2

loc_15AB7:
in      al, dx
and     al, 80h
jz      short loc_15AB7
mov     al, bl
mov     ds:TC_Port3Byte, al
add     dx, 3
out     dx, al
sub     dx, 3

loc_15AC8:              ; Latch timer 0 count.
mov     al, 6           ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
mov     cl, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
mov     ch, al
mov     al, 6           ; Latch timer 0 count.
                        ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
mov     ah, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
xchg    ah, al
sub     ax, cx
cmp     ah, 0
jz      short loc_15AC8
neg     cx
mov     ds:word_13D0E, cx
mov     al, cs:DMA_Channel
out     0Ah, al         ; DMA controller, 8237A-5.
                        ; single mask bit register
                        ; 0-1: select channel (00=0; 01=1; 10=2; 11=3)
                        ; 2: 1=set mask for channel; 0=clear mask (enable)
mov     di, 0

loc_15B00:
mov     dx, ds:DMACurrAddrPort
mov     cx, ds:word_14235[di]

loc_15B08:
in      al, dx
jmp     short $+2
mov     bl, al
in      al, dx
mov     bh, al
cmp     bl, 0F8h ; '°'
jnb     short loc_15B49

loc_15B15:
cmp     bx, si
jnb     short loc_15B59

loc_15B19:
cmp     bx, cx
jb      short loc_15B08

loc_15B1D:              ; Latch timer 0 count.
mov     al, 6           ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
mov     dl, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
mov     dh, al
mov     al, 6           ; Latch timer 0 count.
                        ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
mov     ah, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
xchg    ah, al
sub     ax, dx
cmp     ah, 0
jz      short loc_15B1D
jmp     loc_15BF9

loc_15B49:
in      al, dx
jmp     short $+2
mov     ah, al
in      al, dx
xchg    ah, al
cmp     ax, bx
jnb     short loc_15B15
dec     bh
jmp     short loc_15B15

loc_15B59:
push    bx

loc_15B5A:              ; Latch timer 0 count.
mov     al, 6           ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
mov     bl, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
mov     bh, al
mov     al, 6           ; Latch timer 0 count.
                        ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
mov     ah, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
xchg    ah, al
sub     ax, bx
cmp     ah, 0
jz      short loc_15B5A
neg     bx
mov     ax, bx
sub     ax, ds:word_13D0E
pop     bx
mov     ds:byte_13D12, 1
push    bx
push    cx
push    dx
mov     cx, ax
mov     ax, si
mov     dx, ds:word_13D71
mul     dx
push    cx
sub     cx, ax
jnb     short loc_15BA5
neg     cx

loc_15BA5:
cmp     cx, 8000h
jb      short loc_15BB4
dec     dx
cmp     ax, 8000h
jb      short loc_15BB4
add     dx, 2

loc_15BB4:
pop     ax
push    dx
push    ax
sub     bx, si
mov     ax, ds:word_13D71
mul     bx
mov     bx, ax
pop     ax
pop     dx
sub     ax, bx
sbb     dx, 0
mov     dh, dl
mov     dl, ah
mov     ah, al
mov     al, 0
shl     ax, 1
rcl     dx, 1
shl     ax, 1
rcl     dx, 1
mov     bl, ds:CurrentDrive
mov     bh, 0
shl     bx, 1
mov     cx, word ptr ds:stru_15F64.Drive0[bx]
cmp     cx, dx
ja      short loc_15BEA
jmp     loc_15C7B

loc_15BEA:
div     cx
add     ds:word_10072, ax
pop     dx
pop     cx
pop     bx
mov     si, 0FFFFh
jmp     loc_15B19

loc_15BF9:
neg     dx
mov     ax, dx
sub     ax, ds:word_13D0E
mov     ds:word_13D0E, dx
add     ax, 1
mov     cx, ax
mov     ax, ds:word_14235[di]
cmp     di, 0
jz      short loc_15C17
sub     ax, word ptr ds:unk_14231[di]

loc_15C17:
mov     ds:word_13CCF, ax
mov     dx, ds:word_13D71
mul     dx
push    cx
sub     cx, ax
jnb     short loc_15C27
neg     cx

loc_15C27:
cmp     cx, 8000h
jb      short loc_15C36
dec     dx
cmp     ax, 8000h
jb      short loc_15C36
add     dx, 2

loc_15C36:
pop     ax
push    dx
push    ax
sub     bx, ds:word_14235[di]
cmp     bx, 1
jbe     short loc_15C4A
dec     bx
mov     ax, ds:word_13D71
mul     bx
mov     bx, ax

loc_15C4A:
pop     ax
pop     dx
sub     ax, bx
sbb     dx, 0
push    ax
push    dx
mov     bx, ds:word_13CCF
div     bx
mov     dx, ds:word_13D71
shr     dx, 1
shr     dx, 1
add     dx, ds:word_13D71
cmp     ax, dx
ja      short loc_15C79
mov     dx, ds:word_13D71
mov     bx, dx
shr     bx, 1
shr     bx, 1
sub     dx, bx
cmp     ax, dx
ja      short loc_15C83

loc_15C79:
pop     dx
pop     ax

loc_15C7B:
mov     ds:byte_13D1C, 0FFh
jmp     short loc_15CDD
db 90h

loc_15C83:
pop     dx
pop     ax
mov     dh, dl
mov     dl, ah
mov     ah, al
mov     al, 0
shl     ax, 1
rcl     dx, 1
shl     ax, 1
rcl     dx, 1
mov     bl, ds:CurrentDrive
mov     bh, 0
shl     bx, 1
mov     cx, word ptr ds:stru_15F64.Drive0[bx]
cmp     cx, dx
jbe     short loc_15C7B
div     cx
shr     di, 1
cmp     ds:byte_13D79, 0
jz      short loc_15CBF
mov     cx, 0
add     ax, word ptr ds:TrackDataBuffer[bp+di]
adc     cx, 0
shr     cx, 1
rcr     ax, 1

loc_15CBF:
mov     word ptr ds:TrackDataBuffer[bp+di], ax
shl     di, 1
cmp     ds:byte_13D12, 0
jnz     short loc_15CD1
add     ds:word_10072, ax

loc_15CD1:
add     di, 4
cmp     di, ds:word_13CEE
jnb     short loc_15CDD
jmp     loc_15B00

loc_15CDD:
call    sub_173FD
call    MaskDMA
mov     al, ds:TC_Port3Byte
and     al, 0F8h
call    WriteTC_Port3
sti
mov     al, 43h ; 'C'
mov     dh, 80h ; 'Ç'
call    SelectHead
jnb     short loc_15D0B
mov     al, ds:CurrentCylinder
push    ax
mov     al, ds:CurrentDrive
call    sub_18321
pop     ax
mov     ds:CurrentCylinder, al
call    sub_18313
mov     ds:byte_1007D, 0FFh

loc_15D0B:
call    TrackReadOff
cmp     ds:byte_13D1C, 0
jnz     short sub_15D16
retn
sub_15A5E endp




sub_15D16 proc near
mov     ax, ds:word_13D7A
call    sub_15D46
mov     ds:word_10072, ax
mov     di, 0
mov     ax, ds:word_14235
jmp     short loc_15D30
align 2

loc_15D28:
mov     ax, ds:word_14235[di]
sub     ax, word ptr ds:unk_14231[di]

loc_15D30:
call    sub_15D46
shr     di, 1
mov     word ptr ds:TrackDataBuffer[bp+di], ax
shl     di, 1
add     di, 4
cmp     di, ds:word_13CEE
jb      short loc_15D28
retn
sub_15D16 endp




sub_15D46 proc near
mov     bx, 98BAh
mul     bx
mov     bx, ds:CurrTrkLngthBytes
div     bx
retn
sub_15D46 endp

mov     bx, ds:word_13D71
mul     bx
mov     dh, dl
mov     dl, ah
mov     ah, al
mov     al, 0
shl     ax, 1
rcl     dx, 1
shl     ax, 1
rcl     dx, 1
mov     bl, ds:CurrentDrive
mov     bh, 0
shl     bx, 1
mov     cx, word ptr ds:stru_15F64.Drive0[bx]
div     cx
retn



sub_15D77 proc near
call    RdTrkLngthTbl
mov     ds:CurrTrkLngthBytes, dx
mov     ax, dx
mov     dx, 8
mul     dx
mov     ds:TrackLengthBits, ax
mov     ds:TrkLnBitsHiByte, dx
cmp     ds:KeepTrkLngthFlag, 'Y'
jz      short loc_15D9A
mov     ds:word_14435, 0FFFEh
retn

loc_15D9A:
call    sub_1AC25
mov     ds:CurrTrackBufOfs, si
mov     dx, ds:CurrTrkLngthBytes
add     dx, si
mov     ds:EndOfCurrTrk, dx
call    sub_15045
cmp     ds:word_13CEE, 0Ch
jnb     short loc_15E0B
mov     bx, ds:CurrTrkLngthBytes
shr     bx, 1
shr     bx, 1
mov     ax, ds:CurrTrackBufOfs
add     ax, bx
mov     ds:word_14235, ax
add     ax, bx
mov     ds:word_14239, ax
mov     dx, ds:CurrTrkLngthBytes
add     dx, ds:word_14235
mov     ds:word_1423D, dx
mov     ds:word_13CEE, 0Ch
call    GetTrkDatOfs
mov     cl, 4
shl     bx, cl
mov     bp, bx
mov     cx, 31Eh
mov     bx, 100h
mov     ax, ds:word_14239
sub     ax, ds:word_14235
mul     cx
div     bx
mov     word ptr ds:(TrackDataBuffer+2)[bp], ax
mov     ax, ds:word_1423D
sub     ax, ds:word_14239
mul     cx
div     bx
mov     word ptr ds:(TrackDataBuffer+4)[bp], ax

loc_15E0B:
mov     di, 4

loc_15E0E:
shr     di, 1
call    GetTrkDatOfs
mov     cl, 4
shl     bx, cl
mov     bp, bx
mov     bl, ds:CurrentDrive
mov     bh, 0
shl     bx, 1
mov     cx, word ptr ds:stru_15F64.Drive0[bx]
mov     ax, word ptr ds:TrackDataBuffer[bp+di]
mul     cx
shl     di, 1
mov     cx, ds:word_14235[di]
sub     cx, word ptr ds:unk_14231[di]
cmp     cx, dx
ja      short loc_15E3D
jmp     loc_15EC9

loc_15E3D:
mov     ds:word_13CCF, cx
div     cx
mov     bx, 2
cmp     ax, ds:word_13D9D
ja      short loc_15E66

loc_15E4C:
cmp     ax, ds:word_13D9D[bx]
ja      short loc_15E66
add     bx, 2
cmp     ds:word_13D9D[bx], 0
jnz     short loc_15E4C
sub     bx, 2
mov     ax, ds:word_13D9D[bx]
add     ax, 2

loc_15E66:
shr     di, 1
mov     cx, word ptr ds:unk_13DE1[bx]
call    sub_15F0E
mov     byte ptr ds:unk_14533[di], cl
mov     cx, word ptr ds:unk_13DE3[bx]
call    sub_15F0E
mov     byte ptr ds:unk_14534[di], cl
shl     di, 1
mov     cx, ds:word_13D9B[bx]
mov     bx, ds:word_13D9D[bx]
sub     ax, bx
sub     cx, bx
mov     bx, ds:word_13CCF
mul     bx
shl     ax, 1
rcl     dx, 1
shl     ax, 1
rcl     dx, 1
mov     cx, 65Dh
div     cx
cmp     ax, 0Ah
jbe     short loc_15EA7
sub     ax, 0Ah

loc_15EA7:
mov     cx, word ptr ds:unk_14231[di]
cmp     cx, 1Ah
jb      short loc_15EB3
sub     cx, 1Ah

loc_15EB3:
mov     word ptr ds:unk_14431[di], cx
add     cx, ax
mov     word ptr ds:unk_14433[di], cx
add     di, 4
cmp     di, ds:word_13CEE
jnb     short loc_15EC9
jmp     loc_15E0E

loc_15EC9:
mov     word ptr ds:unk_14431[di], 0FFFEh
mov     di, ds:word_13CEE
mov     ax, word ptr ds:unk_14231[di]
mov     cx, word ptr ds:unk_14233[di]
mov     bx, ds:word_14237
sub     ax, ds:word_14235
mov     dx, ax
sub     dx, ds:CurrTrkLngthBytes
cmp     dx, 3
jbe     short loc_15EFA
cmp     dx, 0FFFDh
jnb     short loc_15EFA
mov     ax, ds:CurrTrkLngthBytes
xor     bx, bx
xor     cx, cx

loc_15EFA:
mov     dx, 8
mul     dx
add     ax, bx
sub     ax, cx
sbb     dx, 0
mov     ds:TrackLengthBits, ax
mov     ds:TrkLnBitsHiByte, dx
retn
sub_15D77 endp




sub_15F0E proc near
push    ax
push    bx
mov     ax, 101h
sub     ax, cx
mov     bl, ds:DiskType
mov     bh, 0
cmp     bl, 0FFh
jnz     short loc_15F22
mov     bl, 7

loc_15F22:
and     bl, 7Fh
mov     bl, byte ptr ds:unk_13D94[bx]
mul     bl
mov     bl, 64h ; 'd'
div     bl
test    ah, 80h
jz      short loc_15F36
inc     al

loc_15F36:
mov     ah, 0
mov     cx, 101h
sub     cx, ax
pop     bx
pop     ax
retn
sub_15F0E endp

TC_Port_Base dw 268h    ; This is the base port address where the TC board is located
TC_Port0 dw 0
TC_Port1 dw 0
TC_Port2 dw 0
TC_Port3 dw 0
TC_Port4 dw 0
TC_Port5 dw 0
TC_Port6 dw 0
TC_Port7 dw 0
TC_Port3Byte db 0       ; Byte last written to TC_Port3.
TC_Port1Byte db 0       ; Byte last written to TC_Port1
TC_Port2Word dw 0       ; Word last written to TC_Port2
TC_Port4Byte db 0       ; Byte last written to TC_Port4.
TC_Port7Byte db 0       ; Byte last written to TC_Port7.
DisketteDOR db 0        ; Byte last sent to diskette digital output register.
DMAWrdCntPort dw 5      ; DMA word count port for channel in use.
DMACurrAddrPort dw 4    ; DMA current address port for channel in use.
DMAPageRegPort dw 81h   ; DMA page register port for channel in use.
DMA_Channel db 2        ; DMA channel 1 or 2
stru_15F60 struc_5F60 <0FFh, 0FFh, 0FFh, 0FFh;
stru_15F64 struc_5F64 <0;
word_15F6C dw 0
word_15F6E dw 0
dw 0
dw 0
dw 0
dw 0
dw 0
dw 0
word_15F7C dw 0
DataRate dw 0
word_15F80 dw 0
word_15F82 dw 0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
byte_15F9C db 0
FloppyCtlrPort dw 3F7h  ; R-  diskette controller DIR (Digital Input Register)
                        ; -W  configuration control register
                        ; 03F7h PC/AT/PS2, 0065h for AT&T 6300.
aOlivetti db 'OLIVETTI'
byte_15FA7 db 0
word_15FA8 dw 0
byte_15FAA db 0
OldInt0EOff dw 0
OldInt0ESeg dw 0
word_15FAF dw 0
word_15FB1 dw 0
word_15FB3 dw 0
word_15FB5 dw 0
word_15FB7 dw 0
unk_15FB9 db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
byte_161B9 db 0
byte_161BA db 0
word_161BB dw 0
unk_161BD db  9Bh ; ¢
db  9Ch ; £
db  9Dh ; ¥
db  9Eh ; P
db  9Fh ; ƒ
db 0A0h ; á
db 0A1h ; í
db 0A2h ; ó
db 0A3h ; ú
db 0A4h ; ñ
db 0A5h ; Ñ
unk_161C8 db 0A6h ; ª
db 0A7h ; º
unk_161CA db    0       ; Sector buffer here?
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
byte_161D5 db 0
db    0
byte_161D7 db 0
word_161D8 dw 0
byte_161DA db 0
word_161DB dw 0
word_161DD dw 0
db    0
byte_161E0 db 0
db    0
word_161E2 dw 0
word_161E4 dw 0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
byte_163CA db 0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
word_167CA dw 0
word_167CC dw 0
word_167CE dw 0
word_167D0 dw 0
word_167D2 dw 0
byte_167D4 db 0
byte_167D5 db 0
unk_167D6 db    9
db    9
db    9
db    9
db    9
db    8
db    8
unk_167DD db    2
db    2
db    2
db    1
db    2
db    1
db    2
unk_167E4 db  0Ch
db  0Ch
db  0Ch
db    9
db  0Ch
db    7
db  0Ah
unk_167EB db    2
db    2
db    2
db    1
db    2
db    1
db    2
unk_167F2 db  50h ; P
db  28h ; (
db  28h ; (
db  28h ; (
db  28h ; (
db  28h ; (
db  28h ; (
ReadClkTbl dw 0Ch dup(0), 0A37Eh, 0B392h, 0D2BEh, 0A37Eh ; The values in this table are used to set the read clock
dw 0B392h, 0D2BEh, 3 dup(0), 0F5h, 0F7h ; for the UM8326B via ports 4 and 5.
dw 4FBh, 0F5h, 0F7h, 4FBh
DMACntLst DMACountList <0, 0, 0, 0, 1AFFh, 1AFFh, 0,\
              34FFh, 34FFh;


; Gets DMA count based on disk type.

SetDmaCount proc near
mov     bl, ds:DiskType
cmp     bl, 0FFh
jnz     short loc_1684C
mov     bl, 7

loc_1684C:
and     bl, 7Fh
mov     bh, 0
shl     bx, 1
mov     ax, word ptr ds:DMACntLst.field_0[bx]
mov     ds:DMACount, ax
retn
SetDmaCount endp



; setup registers and stuff.

sub_1685B proc near
call    sub_16865
call    sub_16892
call    SetReadspeed
retn
sub_1685B endp




sub_16865 proc near
mov     al, 0
call    WriteTC_Port3
mov     al, 20h ; ' '
call    WriteTC_Port1
call    sub_16F04
mov     al, 0
call    WriteTC_Port7
sub_16865 endp




sub_16877 proc near
cmp     ds:byte_15FA7, 0FFh
jnz     short locret_16891
push    ds
mov     ax, seg bdata
mov     ds, ax
assume ds:bdata
mov     al, dsk_data_rate ; Last data rate for diskette
                        ;  bits 7 & 6 = 00 for 500K bit/sec
                        ;             = 01 for 300K bit/sec
                        ;             = 10 for 250K bit/sec
                        ;             = 11 for 1M bit/sec
                        ;  bits 5 & 4 = step rateRate at start of operation
                        ;  bits 3 & 2 = 00 for 500K bit/sec
                        ;             = 01 for 300K bit/sec
                        ;             = 10 for 250K bit/sec
                        ;             = 11 for 1M bit/sec
pop     ds
assume ds:nothing
rol     al, 1
rol     al, 1
and     al, 3
call    sub_16BCA

locret_16891:
retn
sub_16877 endp




sub_16892 proc near
call    sub_1689B
mov     ax, 0FF00h
jmp     WriteTC_Port2
sub_16892 endp




sub_1689B proc near
mov     al, ds:TC_Port7Byte
and     al, 0F7h ; '˜'
call    WriteTC_Port7
mov     al, ds:TC_Port7Byte
or      al, 8
or      al, 2
call    WriteTC_Port7
retn
sub_1689B endp




sub_168AE proc near
push    bx
mov     bh, 0
mov     bl, ds:CurrentDrive
mov     cl, byte ptr ds:stru_15F60.Drive0[bx]
mov     ch, 0
pop     bx
retn
sub_168AE endp




sub_168BD proc near
mov     al, ds:DiskType
call    sub_1690A
cmp     ds:DiskType, 7
jnz     short loc_168D6
cmp     ds:ReadLengthBytes, 3300h
jb      short loc_168D6
inc     al
inc     ah

loc_168D6:
jmp     short loc_168F1
sub_168BD endp

db 90h



SetReadspeed proc near
mov     al, ds:DiskType
call    sub_1690A
cmp     ds:DiskType, 7
jnz     short loc_168D6
cmp     ds:byte_167D5, 0
jz      short loc_168F1
inc     al
inc     ah

loc_168F1:
mov     dx, ds:TC_Port5
out     dx, al
mov     al, ah
mov     dx, ds:TC_Port4
out     dx, al
mov     al, ds:TC_Port1Byte
and     al, 0F0h
or      al, bl
or      al, 20h
call    WriteTC_Port1
retn
SetReadspeed endp




sub_1690A proc near
call    sub_168AE
cmp     cl, 2
jbe     short loc_16914
mov     cl, 0

loc_16914:
cmp     al, 0FFh
jnz     short loc_1691A
mov     al, 7

loc_1691A:
and     al, 7Fh
mov     ah, 0
mov     bx, ax
shl     bx, 1
add     bx, ax
add     bx, cx
shl     bx, 1
mov     ax, ds:ReadClkTbl[bx]
mov     bl, 2
cmp     al, 0F0h ; '='
jb      short locret_16936
mov     bl, ah
mov     ah, al

locret_16936:
retn
sub_1690A endp




sub_16937 proc near
cmp     ds:word_15F82, 0
jnz     short loc_16966
mov     bl, ds:CurrentDrive
mov     bh, 0
shl     bx, 1
mov     di, word ptr ds:stru_15F64.Drive0[bx]
mov     si, 5Eh ; '^'
mov     cx, 64h ; 'd'
mov     bx, 0

loc_16953:
mov     ax, di
mul     si
div     cx
mov     ds:word_15F82[bx], ax
add     bx, 2
inc     si
cmp     si, 6Ah ; 'j'
jbe     short loc_16953

loc_16966:
call    GetTrkDatOfs
call    RdTrkLngthTbl
cmp     ds:DiskType, 7
jnb     short loc_169AC
call    sub_1AC25
add     si, dx
sub     si, 8
sub     dx, 8
mov     cx, 0Fh

loc_16981:
mov     ax, es:[si]
cmp     ax, es:[si-5]
jnz     short loc_169A6
mov     ax, es:[si+2]
cmp     ax, es:[si-3]
jnz     short loc_169A6
mov     al, es:[si+4]
cmp     al, es:[si-1]
jnz     short loc_169A6
sub     si, 5
sub     dx, 5
loop    loc_16981

loc_169A6:
add     dx, 5
jmp     short loc_169E1
align 2

loc_169AC:
cmp     ds:DiskType, 8
jnz     short loc_169B9
sub     dx, 46h ; 'F'
jmp     short loc_169E1
db 90h

loc_169B9:
test    byte ptr ds:TrackTypeTable[bx], 80h
jnz     short loc_169E4
cmp     ds:DiskType, 7
jnz     short loc_169E4
call    sub_1AC25
add     si, dx
sub     si, 4
mov     ax, es:[si]
mov     cx, 46h ; 'F'

loc_169D5:
dec     si
dec     si
sub     dx, 2
cmp     ax, es:[si]
jnz     short loc_169E1
loop    loc_169D5

loc_169E1:
add     dx, 0Ch

loc_169E4:
mov     cx, dx
call    RdTrkLngthTbl
mov     ax, dx
sub     ax, cx
cmp     ax, 8
jb      short loc_169F5
sub     dx, 8

loc_169F5:
mov     bh, 0
mov     bl, ds:CurrentDrive
shl     bx, 1

loc_169FD:
mov     ax, word ptr ds:stru_15F64.Drive0[bx]
cmp     ds:DiskType, 7
jnb     short loc_16A0A
shr     ax, 1

loc_16A0A:
cmp     dx, ax
jb      short loc_16A10
mov     dx, cx

loc_16A10:
mov     bx, word ptr ds:stru_15F64.Drive0[bx]
mov     cx, dx
mov     ax, 60h ; '`'
mul     bx
div     cx
mov     dx, 101h
sub     dx, ax
mov     ax, dx
mov     ds:TC_Port4Byte, al
jmp     short loc_16A61
align 2
mov     bx, 0

loc_16A2D:
cmp     dx, ds:word_15F82[bx]
jb      short loc_16A49
add     bx, 2
cmp     bx, 0Eh
jb      short loc_16A2D

loc_16A3B:
cmp     cx, ds:word_15F82[bx]
jb      short loc_16A49
add     bx, 2
cmp     bx, 1Ah
jb      short loc_16A3B

loc_16A49:
shr     bx, 1
mov     al, byte ptr ds:unk_161BD[bx]
mov     ds:TC_Port4Byte, al
call    sub_168AE
cmp     cl, 0
jz      short loc_16A61
mov     al, ds:TC_Port4Byte
inc     al
shr     al, 1

loc_16A61:
mov     al, ds:TC_Port4Byte
mov     ds:byte_15F9C, al
call    WriteTC_Port4
mov     bl, 4
cmp     al, 0C0h ; '+'
jnb     short loc_16A72
mov     bl, 0

loc_16A72:
mov     al, ds:TC_Port1Byte
and     al, 0FBh
or      al, bl
call    WriteTC_Port1
retn
sub_16937 endp




GetTC_Port_DMA proc near
mov     al, 0Ch         ; enable diskette controller and DMA.
call    WriteDOR
mov     al, 64h ; 'd'
call    Delay
mov     ax, ds:TC_Port_Base
call    sub_16B6E
jnb     short loc_16AB0
mov     ax, ds:TC_Addr1
call    sub_16B6E
jnb     short loc_16AB0
mov     ax, ds:TC_Addr2
call    sub_16B6E
jnb     short loc_16AB0
mov     ax, ds:TC_Addr3
call    sub_16B6E
jnb     short loc_16AB0
mov     ax, ds:TC_Addr4
call    sub_16B6E
jnb     short loc_16AB0
retn

loc_16AB0:              ; Port 03h RW  DMA channel 1 word count byte 0, then byte 1
mov     ds:DMAWrdCntPort, 3
mov     ds:DMACurrAddrPort, 2 ; Port 02h R-  DMA channel 1 current address byte  0, then byte 1
                        ;             -W  DMA channel 1 base address byte 0, then byte 1
mov     ds:DMAPageRegPort, 83h ; 'â' ; Port 83h RW  DMA channel 1 address byte 2
mov     ds:DMA_Channel, 1
in      al, dx
and     al, 20h
jnz     short loc_16AE3
mov     ds:DMAWrdCntPort, 5 ; Port 05h RW  DMA channel 2 word count byte 0, then byte 1
mov     ds:DMACurrAddrPort, 4 ; Port 04h R-  DMA channel 2 current address byte  0, then byte 1
                        ;             -W  DMA channel 2 base address byte 0, then byte 1
mov     ds:DMAPageRegPort, 81h ; 'ü' ; Port 81h RW  DMA channel 2 address byte 2
mov     ds:DMA_Channel, 2

loc_16AE3:
sub     dx, 2
mov     ds:TC_Port_Base, dx
mov     ds:TC_Port0, dx
inc     dx
mov     ds:TC_Port1, dx
inc     dx
mov     ds:TC_Port2, dx
inc     dx
mov     ds:TC_Port3, dx
inc     dx
mov     ds:TC_Port4, dx
inc     dx
mov     ds:TC_Port5, dx
inc     dx
mov     ds:TC_Port6, dx
inc     dx
mov     ds:TC_Port7, dx
push    di
push    si
push    es
mov     ax, 0F000h      ; BIOS segment
mov     es, ax
assume es:nothing
mov     si, 0C050h      ; offset within BIOS to check for "OLIVETTI".
mov     di, 0

loc_16B1F:
mov     al, es:[si]
xor     al, byte ptr ds:aOlivetti[di] ; "OLIVETTI"
and     al, 7Fh
jnz     short loc_16B37
inc     si
inc     di
cmp     di, 8
jb      short loc_16B1F
mov     ds:FloppyCtlrPort, 65h ; 'e'

loc_16B37:
pop     es
assume es:nothing
pop     si
pop     di
mov     ds:byte_15FA7, 0
mov     ah, 15h
mov     dl, 0
int     13h             ; DISK - DISK - GET TYPE (AT,XT2,XT286,CONV,PS)
                        ; DL = drive ID
                        ; Return: CF set on error, AH = disk type
jb      short loc_16B6C
cmp     ah, 2
jz      short loc_16B59
mov     ah, 15h
mov     dl, 1
int     13h             ; DISK - DISK - GET TYPE (AT,XT2,XT286,CONV,PS)
                        ; DL = drive ID
                        ; Return: CF set on error, AH = disk type
jb      short loc_16B59
cmp     ah, 2
jnz     short loc_16B6C

loc_16B59:
push    ds
mov     ax, seg bdata
mov     ds, ax
assume ds:bdata
mov     al, dsk0_media_st ; Media state for diskette drive 0
                        ;     7      6      5      4
                        ;  data xfer rate  two   media
                        ;   00=500K bit/s  step  known
                        ;   01=300K bit/s
                        ;   10=250K bit/s
                        ;   11=1M bit/sec
                        ;     3      2      1      0
                        ;  unused  -----state of drive-----
                        ;          bits floppy  drive state
                        ;          000=  360K in 360K, ?
                        ;          001=  360K in 1.2M, ?
                        ;          010=  1.2M in 1.2M, ?
                        ;          011=  360K in 360K, ok
                        ;          100=  360K in 1.2M, ok
                        ;          101=  1.2M in 1.2M, ok
                        ;          111=  720K in 720K, ok
                        ;            or 1.44M in 1.44M
                        ;         (state not used for 2.88)
pop     ds
assume ds:nothing
cmp     al, 0
jz      short loc_16B6C
mov     ds:byte_15FA7, 0FFh

loc_16B6C:
clc
retn
GetTC_Port_DMA endp




sub_16B6E proc near
mov     ds:TC_Port_Base, ax
mov     cx, 14h

loc_16B74:
mov     dx, ds:TC_Port_Base
add     dx, 2
in      al, dx
jmp     short $+2
mov     ah, al
in      al, dx
cmp     ah, al
jnz     short loc_16BA8
and     al, 8Ch ; 'î'
cmp     al, 8Ch ; 'î'
jz      short loc_16BA8
and     ah, 1
jz      short loc_16BA8
jmp     short $+2
in      al, dx
and     al, 40h
jnz     short loc_16BA8
sub     dx, 2
jmp     short $+2
in      al, dx
and     al, 5Fh
jnz     short loc_16BA8
add     dx, 2
loop    loc_16B74
clc
retn

loc_16BA8:
stc
retn
sub_16B6E endp




sub_16BAA proc near
push    cx
call    sub_168AE
cmp     cl, 1
jz      short loc_16BB8
mov     al, 1
call    sub_16BCA

loc_16BB8:
pop     cx
retn
sub_16BAA endp




sub_16BBA proc near
push    cx
call    sub_168AE
cmp     cl, 1
jz      short loc_16BC8
mov     al, 2
call    sub_16BCA

loc_16BC8:
pop     cx
retn
sub_16BBA endp




sub_16BCA proc near
cmp     ds:byte_15FA7, 0FFh
jnz     short locret_16BD9
mov     dx, ds:FloppyCtlrPort
out     dx, al
call    sub_16BDA

locret_16BD9:
retn
sub_16BCA endp




sub_16BDA proc near
push    ds
push    ax
mov     ax, seg bdata
mov     ds, ax
assume ds:bdata
mov     al, dsk0_media_st ; Media state for diskette drive 0
                        ;     7      6      5      4
                        ;  data xfer rate  two   media
                        ;   00=500K bit/s  step  known
                        ;   01=300K bit/s
                        ;   10=250K bit/s
                        ;   11=1M bit/sec
                        ;     3      2      1      0
                        ;  unused  -----state of drive-----
                        ;          bits floppy  drive state
                        ;          000=  360K in 360K, ?
                        ;          001=  360K in 1.2M, ?
                        ;          010=  1.2M in 1.2M, ?
                        ;          011=  360K in 360K, ok
                        ;          100=  360K in 1.2M, ok
                        ;          101=  1.2M in 1.2M, ok
                        ;          111=  720K in 720K, ok
                        ;            or 1.44M in 1.44M
                        ;         (state not used for 2.88)
call    sub_16BF6
mov     dsk0_media_st, al ; Media state for diskette drive 0
                        ;     7      6      5      4
                        ;  data xfer rate  two   media
                        ;   00=500K bit/s  step  known
                        ;   01=300K bit/s
                        ;   10=250K bit/s
                        ;   11=1M bit/sec
                        ;     3      2      1      0
                        ;  unused  -----state of drive-----
                        ;          bits floppy  drive state
                        ;          000=  360K in 360K, ?
                        ;          001=  360K in 1.2M, ?
                        ;          010=  1.2M in 1.2M, ?
                        ;          011=  360K in 360K, ok
                        ;          100=  360K in 1.2M, ok
                        ;          101=  1.2M in 1.2M, ok
                        ;          111=  720K in 720K, ok
                        ;            or 1.44M in 1.44M
                        ;         (state not used for 2.88)
mov     al, dsk1_media_st ; Media state for diskette drive 1
                        ;  (see dsk0_media_st)
call    sub_16BF6
mov     dsk1_media_st, al ; Media state for diskette drive 1
                        ;  (see dsk0_media_st)
pop     ax
pop     ds
assume ds:nothing
retn
sub_16BDA endp




sub_16BF6 proc near
and     al, 0EFh
mov     ah, al
and     ah, 7
cmp     ah, 5
ja      short locret_16C09
cmp     ah, 3
jb      short locret_16C09
sub     al, 3

locret_16C09:
retn
sub_16BF6 endp




WriteDOR proc near
mov     dx, 3F2h
out     dx, al          ; Floppy: digital output reg bits:
                        ; 0-1: Drive to select 0-3 (AT: bit 1 not used)
                        ; 2:   0=reset diskette controller; 1=enable controller
                        ; 3:   1=enable diskette DMA and interrupts
                        ; 4-7: drive motor enable.  Set bits to turn drive ON.
                        ;
mov     cs:DisketteDOR, al
retn
WriteDOR endp




WriteTC_Port4 proc near
mov     dx, ds:TC_Port4
out     dx, al
mov     ds:TC_Port4Byte, al
retn
WriteTC_Port4 endp




WriteTC_Port3 proc near
mov     dx, ds:TC_Port3
out     dx, al
mov     ds:TC_Port3Byte, al
retn
WriteTC_Port3 endp




WriteTC_Port1 proc near
mov     dx, ds:TC_Port1
out     dx, al
mov     ds:TC_Port1Byte, al
retn
WriteTC_Port1 endp


WriteTC_Port2:
mov     dx, ds:TC_Port2
out     dx, al
mov     ds:TC_Port2Word, ax
mov     al, ah
out     dx, al
retn



WriteTC_Port7 proc near
mov     dx, cs:TC_Port7
mov     cs:TC_Port7Byte, al
out     dx, al
and     al, 0F0h
jz      short locret_16C64
cmp     al, 10h
jz      short loc_16C5E
mov     ah, al
mov     al, 21h ; '!'   ; select drive and motor 1
cmp     ah, 20h ; ' '
jz      short loc_16C5E
mov     al, 42h ; 'B'   ; select drive and motor 2
cmp     ah, 40h ; '@'
jz      short loc_16C5E
mov     al, 83h ; 'â'   ; select drive and motor 3

loc_16C5E:              ; Set enable controller and DMA bits.
or      al, 0Ch
call    WriteDOR
out     dx, al

locret_16C64:
retn
WriteTC_Port7 endp




sub_16C65 proc near
mov     ds:word_15FA8, 4E20h
pushf
push    dx
push    cx
push    bx
cli
call    ClearTimer0
mov     dx, ds:TC_Port_Base
in      al, dx
and     al, 80h
mov     ah, al
mov     cx, ds:word_15FA8

loc_16C80:
call    Delay2
mov     dx, ds:TC_Port_Base
in      al, dx
and     al, 80h
cmp     al, ah
jnz     short loc_16C96
loop    loc_16C80
pop     bx
pop     cx
pop     dx
popf
stc
retn

loc_16C96:
loop    loc_16C96
mov     bl, ds:CurrentDrive
mov     bh, 0
cmp     byte ptr ds:stru_15F60.Drive0[bx], 0FFh
jz      short loc_16CAB

loc_16CA5:
pop     bx
pop     cx
pop     dx
popf
clc
retn

loc_16CAB:
mov     dx, ds:TC_Port_Base
cli
call    ClearTimer0

loc_16CB3:
in      al, dx
and     al, 80h
jnz     short loc_16CB3
jmp     short $+2

loc_16CBA:
in      al, dx
and     al, 80h
jz      short loc_16CBA
mov     ds:DataRate, 0
push    bx

loc_16CC6:
pushf
cli
mov     al, 6           ; Latch timer 0 count.
                        ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
mov     bl, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
mov     bh, al
mov     al, 6           ; Latch timer 0 count.
                        ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
mov     ah, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
popf
xchg    ah, al
sub     ax, bx
cmp     ah, 0
jz      short loc_16CC6
neg     bx
mov     ds:word_15F80, bx
pop     bx
xor     ax, ax
push    bx

loc_16CFC:
pushf
cli
mov     al, 6           ; Latch timer 0 count.
                        ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
mov     bl, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
mov     bh, al
mov     al, 6           ; Latch timer 0 count.
                        ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
mov     ah, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
popf
xchg    ah, al
sub     ax, bx
cmp     ah, 0
jz      short loc_16CFC
neg     bx
mov     ax, bx
sub     ax, cs:word_15F80
pop     bx
mov     bx, ax

loc_16D34:
push    bx

loc_16D35:
pushf
cli
mov     al, 6           ; Latch timer 0 count.
                        ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
mov     bl, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
mov     bh, al
mov     al, 6           ; Latch timer 0 count.
                        ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
mov     ah, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
popf
xchg    ah, al
sub     ax, bx
cmp     ah, 0
jz      short loc_16D35
neg     bx
mov     ax, bx
sub     ax, cs:word_15F80
pop     bx
cmp     ax, bx
ja      short loc_16D73
inc     ds:DataRate

loc_16D73:
mov     bx, ax
in      al, dx
and     al, 80h
jnz     short loc_16D34

loc_16D7A:
push    bx

loc_16D7B:
pushf
cli
mov     al, 6           ; Latch timer 0 count.
                        ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
mov     bl, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
mov     bh, al
mov     al, 6           ; Latch timer 0 count.
                        ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
mov     ah, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
popf
xchg    ah, al
sub     ax, bx
cmp     ah, 0
jz      short loc_16D7B
neg     bx
mov     ax, bx
sub     ax, cs:word_15F80
pop     bx
cmp     ax, bx
ja      short loc_16DB9
inc     ds:DataRate

loc_16DB9:
mov     bx, ax
in      al, dx
and     al, 80h
jz      short loc_16D7A
push    bx

loc_16DC1:
pushf
cli
mov     al, 6           ; Latch timer 0 count.
                        ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
mov     bl, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
mov     bh, al
mov     al, 6           ; Latch timer 0 count.
                        ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
mov     ah, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
popf
xchg    ah, al
sub     ax, bx
cmp     ah, 0
jz      short loc_16DC1
neg     bx
mov     ax, bx
sub     ax, cs:word_15F80
pop     bx
cmp     ax, bx
ja      short loc_16DFF
inc     ds:DataRate

loc_16DFF:
cmp     ds:DataRate, 7
jbe     short loc_16E14
mov     ds:DataRate, 7
mov     ax, 4859h
mov     ds:byte_13D1C, 0FFh

loc_16E14:
mov     ds:word_15F7C, ax
push    ax
mov     ax, ds:DataRate
mov     cx, 20E5h
mul     cx
mov     bx, ax
pop     ax
mul     cx
add     dx, bx
shr     dx, 1
rcr     ax, 1
shr     dx, 1
rcr     ax, 1
shr     dx, 1
rcr     ax, 1
shr     dx, 1
rcr     ax, 1
mov     cx, 4E80h
div     cx
mov     bh, 0
mov     bl, ds:CurrentDrive
mov     byte ptr ds:stru_15F60.Drive0[bx], 0
cmp     ds:DataRate, 7
jz      short loc_16E5F
mov     byte ptr ds:stru_15F60.Drive0[bx], 1
cmp     ds:DataRate, 5
jnb     short loc_16E5F
mov     byte ptr ds:stru_15F60.Drive0[bx], 2

loc_16E5F:
shl     bx, 1
mov     word ptr ds:stru_15F64.Drive0[bx], ax
shl     bx, 1
mov     ax, ds:word_15F7C
mov     ds:word_15F6C[bx], ax
mov     ax, ds:DataRate
mov     ds:word_15F6E[bx], ax
jmp     loc_16CA5
sub_16C65 endp




sub_16E78 proc near
mov     ds:CurrentDrive, dl
mov     bl, dl
mov     bh, 0
mov     ds:byte_15FAA, 0
cmp     byte ptr ds:stru_15F60.Drive0[bx], 1
jnz     short loc_16E91
mov     ds:byte_15FAA, 0FFh

loc_16E91:
pushf
cli
call    ClearTimer0
push    ds
push    cx
in      al, 21h         ; Interrupt controller, 8259A.
jmp     short $+2
or      al, 1           ; disable IRQ0
out     21h, al         ; Interrupt controller, 8259A.
mov     cx, 40h ; '@'
mov     ds, cx
assume ds:bdata
mov     cl, dl
mov     al, 1
shl     al, cl
mov     dsk_motor_timer, 0FFh ; Motor timer, at 0, turn off motor
test    byte ptr ds:EndOfCurrTrk, al
jz      short loc_16EBE
cmp     cs:BiosModelByte, 0FCh ; 'n' ; FCh=AT,FDh=PCjr,FEh=XT,FF=PC
ja      short loc_16EEA

loc_16EBE:
and     byte ptr ds:EndOfCurrTrk, 0F0h
or      byte ptr ds:EndOfCurrTrk, al
mov     al, 10h
shl     al, cl
or      al, dl
or      al, 0Ch         ; enable controller and interrupts
push    dx
call    WriteDOR
push    cs
pop     ds
assume ds:seg001
mov     al, 0FAh ; '·'
call    Delay
mov     al, 0FAh ; '·'
call    Delay
mov     al, 0FAh ; '·'
call    Delay
mov     ax, seg bdata
mov     ds, ax
assume ds:bdata
pop     dx

loc_16EEA:
mov     cx, 0Ah

loc_16EED:
mov     dh, 0
call    GetDriveStatus
mov     al, dsk_status_1 ; Status bytes-disk controller chip
                        ;  Note: 7 info bytes returned from
                        ;  controller are saved here. Refer
                        ;  to the NEC uPD 765 chip manual
                        ;  for the specific info, depending
                        ;  on the previous command issued.
xor     al, dl
and     al, 1
jz      short loc_16EFD
loop    loc_16EED

loc_16EFD:              ; Status bytes-disk controller chip
mov     al, dsk_status_1 ;  Note: 7 info bytes returned from
                        ;  controller are saved here. Refer
                        ;  to the NEC uPD 765 chip manual
                        ;  for the specific info, depending
                        ;  on the previous command issued.
pop     cx
pop     ds
assume ds:nothing
popf
retn
sub_16E78 endp




sub_16F04 proc near
pushf
push    ax
push    bx
push    dx
push    ds
cli
mov     al, 0Ch         ; Bits 2 & 3 set, enable diskette controller, enable diskette DMA.
call    WriteDOR
mov     al, cs:TC_Port7Byte
and     al, 0Fh
call    WriteTC_Port7
mov     ax, seg bdata
mov     ds, ax
assume ds:bdata
and     dsk_motor_stat, 0F0h ; Motor running status & disk write
                        ;  bit 7=1 disk write in progress
                        ;  bits 6&5 = drive selected 0 to 3
                        ;     3       2       1       0
                        ;  drive-3 drive-2 drive-1 drive-0
                        ;  --------- 1=motor on-----------
and     dsk_recal_stat, 0F0h ; Recalibrate floppy drive bits
                        ;    3       2       1       0
                        ; drive-3 drive-2 drive-1 drive-0
                        ;
                        ; bit 7 = interrupt flag
in      al, 21h         ; Interrupt controller, 8259A.
jmp     short $+2
and     al, 0FEh
out     21h, al         ; Make sure IRQ0 (timer) enabled.
pop     ds
assume ds:nothing
pop     dx
pop     bx
pop     ax
popf
retn
sub_16F04 endp



; Sets motor timeout to FFh.

MaxtMotorTimer proc near
push    ax
mov     ax, seg bdata
mov     ds, ax
assume ds:bdata
mov     dsk_motor_timer, 0FFh ; Motor timer, at 0, turn off motor
pop     ax
retn
MaxtMotorTimer endp




sub_16F42 proc near
push    ds
call    MaxtMotorTimer
mov     dx, 3F2h
cli
mov     al, dsk_motor_stat ; Motor running status & disk write
                        ;  bit 7=1 disk write in progress
                        ;  bits 6&5 = drive selected 0 to 3
                        ;     3       2       1       0
                        ;  drive-3 drive-2 drive-1 drive-0
                        ;  --------- 1=motor on-----------
mov     cl, 4
shl     al, cl
test    al, 20h         ; drive 1
jnz     short loc_16F61
test    al, 40h
jnz     short loc_16F5F
test    al, 80h
jz      short loc_16F63
inc     al

loc_16F5F:
inc     al

loc_16F61:
inc     al

loc_16F63:
or      al, 8
out     dx, al          ; Diskette Digital output register.
                        ; Enable DMA and interrupts, turn on motor for selected drive.
mov     dsk_recal_stat, 0 ; Recalibrate floppy drive bits
                        ;    3       2       1       0
                        ; drive-3 drive-2 drive-1 drive-0
                        ;
                        ; bit 7 = interrupt flag
mov     dsk_ret_code, 0 ; Controller return code
                        ;  00h = ok
                        ;  01h = bad command or parameter
                        ;  02h = can't find address mark
                        ;  03h = can't write, protected dsk
                        ;  04h = sector not found
                        ;  08h = DMA overrun
                        ;  09h = DMA attempt over 64K bound
                        ;  10h = bad CRC on disk read
                        ;  20h = controller failure
                        ;  40h = seek failure
                        ;  80h = timeout, no response
or      al, 4
out     dx, al          ; Floppy: digital output reg bits:
                        ; 0-1: Drive to select 0-3 (AT: bit 1 not used)
                        ; 2:   0=reset diskette controller; 1=enable controller
                        ; 3:   1=enable diskette DMA and interrupts
                        ; 4-7: drive motor enable.  Set bits to turn drive ON.
                        ;
mov     cs:DisketteDOR, al
sti
call    CheckDskIntStat
mov     al, dsk_status_1 ; Status bytes-disk controller chip
                        ;  Note: 7 info bytes returned from
                        ;  controller are saved here. Refer
                        ;  to the NEC uPD 765 chip manual
                        ;  for the specific info, depending
                        ;  on the previous command issued.
cmp     al, 0C0h ; '+'
jz      short loc_16F8A
or      dsk_ret_code, 20h ; Controller return code
                        ;  00h = ok
                        ;  01h = bad command or parameter
                        ;  02h = can't find address mark
                        ;  03h = can't write, protected dsk
                        ;  04h = sector not found
                        ;  08h = DMA overrun
                        ;  09h = DMA attempt over 64K bound
                        ;  10h = bad CRC on disk read
                        ;  20h = controller failure
                        ;  40h = seek failure
                        ;  80h = timeout, no response
jmp     short loc_16F9B
align 2

loc_16F8A:
mov     ah, 3
call    DisketteCommand
mov     bx, 1
call    sub_16F9D
mov     bx, 3
call    sub_16F9D

loc_16F9B:
pop     ds
assume ds:nothing
retn
sub_16F42 endp




sub_16F9D proc near
push    ds
sub     ax, ax
mov     ds, ax
assume ds:nothing
lds     si, ds:dword_10078
assume ds:nothing
shr     bx, 1
mov     ah, [bx+si]
pop     ds
sub_16F9D endp




DisketteCommand proc near
push    ds
push    dx
push    cx
push    bx
mov     dx, seg bdata
mov     ds, dx
assume ds:bdata
mov     dx, 3F4h
xor     cx, cx
mov     bx, 14h

loc_16FBC:              ; Floppy: main status reg bits:
in      al, dx          ; 0-3: diskette busy
                        ; 4: 1=cntrlr busy
                        ; 5: 1=non-DMA mode
                        ; 6: Data dir: 1=cntrlr to CPU
                        ; 7: 1=OK to snd/rcv cmd or data
test    al, 40h
jz      short loc_16FCF
loop    loc_16FBC       ; wait for data ready?
                        ; Another delay loop, may be trouble on fast CPU.
dec     bx
jnz     short loc_16FBC

loc_16FC6:              ; 80h = timeout, no response
or      dsk_ret_code, 80h
stc
jmp     short loc_16FE7
db 90h

loc_16FCF:
xor     cx, cx
mov     bx, 14h

loc_16FD4:              ; Floppy: main status reg bits:
in      al, dx          ; 0-3: diskette busy
                        ; 4: 1=cntrlr busy
                        ; 5: 1=non-DMA mode
                        ; 6: Data dir: 1=cntrlr to CPU
                        ; 7: 1=OK to snd/rcv cmd or data
test    al, 80h
jnz     short loc_16FE0 ; wait for access ok?
                        ; Another delay loop, may be trouble on fast CPU.
loop    loc_16FD4
dec     bx
jnz     short loc_16FD4
jmp     short loc_16FC6

loc_16FE0:
mov     al, ah
mov     dx, 3F5h
out     dx, al          ; Floppy: FDC command/data register.
clc

loc_16FE7:
pop     bx
pop     cx
pop     dx
pop     ds
assume ds:nothing
retn
DisketteCommand endp ; sp =  2




sub_16FEC proc near
push    ds
call    MaxtMotorTimer
mov     ah, 7           ; command 7, calibrate drive.
call    DisketteCommand
mov     ah, dl
call    DisketteCommand
call    CheckDskIntStat
mov     ah, 7           ; command 7, calibrate drive.
call    DisketteCommand
mov     ah, dl
call    DisketteCommand
call    CheckDskIntStat
jmp     short loc_17036
sub_16FEC endp

db 90h



sub_1700D proc near
push    ds
call    MaxtMotorTimer
mov     ah, 0Fh         ; command 0fh seek cylinder
call    DisketteCommand
mov     ah, dh
shl     ah, 1
shl     ah, 1
and     ah, 4
or      ah, dl
call    DisketteCommand ; head and drive on which to seek
mov     ah, ch
cmp     cs:byte_15FAA, 0
jz      short loc_17030
shl     ah, 1

loc_17030:              ; cylinder desired
call    DisketteCommand
call    CheckDskIntStat

loc_17036:
pushf
mov     al, 0Ah
call    Delay
popf
pop     ds
retn
sub_1700D endp

push    dx
push    ds
mov     dl, cs:CurrentDrive
mov     dh, cs:CurrentSide
call    MaxtMotorTimer
mov     ah, 4Ah ; 'J'   ; Diskette controller command 4Ah
                        ; Read ID
call    DisketteCommand
mov     ah, dh
shl     ah, 1
shl     ah, 1
and     ah, 4
or      ah, dl
call    DisketteCommand ; drive and head to read id from.
call    WaitForIRQ6
jb      short loc_1706A
call    SaveCtlrReturnCd
clc

loc_1706A:
pop     ds
pop     dx
retn



sub_1706D proc near
cmp     dh, 80h ; 'Ç'
jnz     short loc_17076
call    SaveCtlrReturnCd
retn

loc_17076:
mov     ah, 4
push    dx
call    DisketteCommand ; Diskette controller command 4h
                        ; Sense drive status
pop     dx
jb      short locret_1708D
mov     ah, dh
shl     ah, 1
shl     ah, 1
and     ah, 4
or      ah, dl          ; head and drive to sense
call    DisketteCommand

locret_1708D:
retn
sub_1706D endp




sub_1708E proc near
cmp     ds:byte_13D70, 1
jnz     short loc_1709A
mov     al, 1
call    sub_16BCA

loc_1709A:
push    di
mov     al, 2
out     0Ah, al         ; DMA controller, 8237A-5.
                        ; single mask bit register
                        ; 0-1: select channel (00=0; 01=1; 10=2; 11=3)
                        ; 2: 1=set mask for channel; 0=clear mask (enable)
mov     ah, 46h ; 'F'   ; Diskette controller command 46h
                        ; Read sector
call    DisketteCommand
mov     ah, ds:CurrentSide
shl     ah, 1
shl     ah, 1
and     ah, 4
or      ah, ds:CurrentDrive ; head and drive to read
call    DisketteCommand
mov     ah, ds:Cylinder ; track to read
call    DisketteCommand
mov     ah, ds:CurrentHead ; side to read
call    DisketteCommand
mov     ah, ds:SectorNumber ; sector to read
call    DisketteCommand
mov     ah, ds:SectorSize ; sector size
call    DisketteCommand
mov     ah, ds:SectorNumber
inc     ah
call    DisketteCommand ; read 1 sector
mov     ah, 2Ah ; '*'
call    DisketteCommand ; gap length
mov     ah, 0FFh
cmp     ds:SectorSize, 6
ja      short loc_170F0
cmp     ds:SectorSize, 0
jnz     short loc_170F2

loc_170F0:
mov     ah, 0

loc_170F2:              ; data length
call    DisketteCommand
push    ds
call    MaxtMotorTimer
call    WaitForIRQ6
call    SaveCtlrReturnCd
mov     al, 6
out     0Ah, al         ; DMA controller, 8237A-5.
                        ; single mask bit register
                        ; 0-1: select channel (00=0; 01=1; 10=2; 11=3)
                        ; 2: 1=set mask for channel; 0=clear mask (enable)
mov     ax, word ptr ds:dsk_status_1 ; Status bytes-disk controller chip
                        ;  Note: 7 info bytes returned from
                        ;  controller are saved here. Refer
                        ;  to the NEC uPD 765 chip manual
                        ;  for the specific info, depending
                        ;  on the previous command issued.
mov     bx, word ptr ds:dsk_status_3
pop     ds
pop     di
cmp     cs:byte_13D70, 1
jnz     short locret_1711B
push    ax
mov     al, 2
call    sub_16BCA
pop     ax

locret_1711B:
retn
sub_1708E endp



; Diskette controller command 4h
; Sense drive status.

GetDriveStatus proc near
mov     ah, 4
call    DisketteCommand
mov     ah, dh
shl     ah, 1
shl     ah, 1
and     ah, 4
or      ah, dl          ; head and drive to sense
call    DisketteCommand
call    SaveCtlrReturnCd
retn
GetDriveStatus endp



; Enables the DMA channel being used by the DOB.

UnmaskDMA proc near
mov     al, cs:DMA_Channel
out     0Ah, al         ; DMA controller, 8237A-5.
                        ; single mask bit register
                        ; 0-1: select channel (00=0; 01=1; 10=2; 11=3)
                        ; 2: 1=set mask for channel; 0=clear mask (enable)
retn
UnmaskDMA endp



; Disables the DMA channel being used by the DOB.

MaskDMA proc near
mov     al, 4
or      al, cs:DMA_Channel
out     0Ah, al         ; DMA controller, 8237A-5.
                        ; single mask bit register
                        ; 0-1: select channel (00=0; 01=1; 10=2; 11=3)
                        ; 2: 1=set mask for channel; 0=clear mask (enable)
retn
MaskDMA endp




SetupDMA proc near
pushf
push    cx
cli
out     0Ch, al         ; DMA controller, 8237A-5.
                        ; clear byte pointer flip-flop.
push    ax
pop     ax
mov     cl, al
and     al, 0FCh ; 'n'  ; clear the channel selection bits.
or      al, ds:DMA_Channel
out     0Bh, al         ; DMA 8237A-5. mode register bits:
                        ; 0-1: channel (00=0; 01=1; 10=2; 11=3)
                        ; 2-3: transfer type (00=verify=Nop; 01=write; 10=read)
                        ; 4: 1=enable auto-initialization
                        ; 5: 1=address increment; 0=address decrement
                        ; 6-7: 00=demand mode; 01=single; 10=block; 11=cascade
mov     al, 0
push    dx
mov     dx, ds:DMACurrAddrPort
push    ax
pop     ax
out     dx, al
jmp     short $+2
mov     ax, bx
out     dx, al
mov     al, ah
mov     dx, ds:DMAPageRegPort
out     dx, al
mov     dx, ds:DMAWrdCntPort
push    ds
mov     ax, cs
mov     ds, ax
assume ds:seg001
mov     al, byte ptr DMACount
push    ax
pop     ax
out     dx, al
mov     al, byte ptr DMACount+1
out     dx, al
call    MaxtMotorTimer
pop     ds
assume ds:nothing
pop     dx
pop     cx
popf
retn
SetupDMA endp




sub_17186 proc near
pushf
push    cx
cli
out     0Ch, al         ; DMA controller, 8237A-5.
                        ; clear byte pointer flip-flop.
push    ax
pop     ax
mov     cl, al
and     al, 0FCh
or      al, 2
out     0Bh, al         ; DMA 8237A-5. mode register bits:
                        ; 0-1: channel (00=0; 01=1; 10=2; 11=3)
                        ; 2-3: transfer type (00=verify=Nop; 01=write; 10=read)
                        ; 4: 1=enable auto-initialization
                        ; 5: 1=address increment; 0=address decrement
                        ; 6-7: 00=demand mode; 01=single; 10=block; 11=cascade
mov     al, 0
push    dx
mov     dx, 4
push    ax
pop     ax
out     dx, al          ; DMA controller, 8237A-5.
                        ; channel 2 base address
                        ; (also sets current address)
jmp     short $+2
mov     ax, bx
out     dx, al          ; DMA controller, 8237A-5.
                        ; channel 2 base address
                        ; (also sets current address)
mov     al, ah
mov     dx, 81h ; 'ü'
out     dx, al          ; DMA page register 74LS612:
                        ; Channel 2 (diskette DMA)  (address bits 16-23)
mov     dx, 5
push    ds
mov     ax, cs
mov     ds, ax
assume ds:seg001
mov     al, byte ptr DMACount
push    ax
pop     ax
out     dx, al          ; DMA controller, 8237A-5.
                        ; channel 2 base address and word count
mov     al, byte ptr DMACount+1
out     dx, al          ; DMA controller, 8237A-5.
                        ; channel 2 base address and word count
call    MaxtMotorTimer
pop     ds
assume ds:nothing
pop     dx
pop     cx
popf
retn
sub_17186 endp

pushf
push    dx
mov     dx, cs:DMACurrAddrPort
cli
mov     al, 0
out     dx, al          ; DMA controller, 8237A-5.
                        ; channel 2 base address
                        ; (also sets current address)
jmp     short $+2
mov     al, bl
out     dx, al          ; DMA controller, 8237A-5.
                        ; channel 2 base address
                        ; (also sets current address)
inc     dx
mov     al, byte ptr cs:DMACount
out     dx, al          ; DMA controller, 8237A-5.
                        ; channel 2 base address and word count
mov     al, byte ptr cs:DMACount+1
out     dx, al          ; DMA controller, 8237A-5.
                        ; channel 2 base address and word count
pop     dx
popf
retn


; waits for int 0Eh (IRQ6) from diskette controller and saves the results.

CheckDskIntStat proc near
push    ds              ; waits for int 0Eh (IRQ6) from diskette controller and saves the results.
call    MaxtMotorTimer
call    WaitForIRQ6
mov     ah, 8           ; Diskette controller command 8h
                        ; Sense interrupt status
call    DisketteCommand
call    SaveCtlrReturnCd
jb      short loc_171FC
mov     al, ds:dsk_status_1 ; Status bytes-disk controller chip
                        ;  Note: 7 info bytes returned from
                        ;  controller are saved here. Refer
                        ;  to the NEC uPD 765 chip manual
                        ;  for the specific info, depending
                        ;  on the previous command issued.
and     al, 60h
cmp     al, 60h ; '`'
jz      short loc_171FE
clc

loc_171FC:
pop     ds
retn

loc_171FE:              ; Controller return code
or      ds:dsk_ret_code, 40h ;  00h = ok
                        ;  01h = bad command or parameter
                        ;  02h = can't find address mark
                        ;  03h = can't write, protected dsk
                        ;  04h = sector not found
                        ;  08h = DMA overrun
                        ;  09h = DMA attempt over 64K bound
                        ;  10h = bad CRC on disk read
                        ;  20h = controller failure
                        ;  40h = seek failure
                        ;  80h = timeout, no response
pop     ds
stc
retn
CheckDskIntStat endp

push    ds
call    MaxtMotorTimer
mov     ah, 8           ; Diskette controller command 8h
                        ; Sense interrupt status
call    DisketteCommand
call    SaveCtlrReturnCd
jb      short loc_1721E
mov     al, ds:dsk_status_1 ; Status bytes-disk controller chip
                        ;  Note: 7 info bytes returned from
                        ;  controller are saved here. Refer
                        ;  to the NEC uPD 765 chip manual
                        ;  for the specific info, depending
                        ;  on the previous command issued.
and     al, 60h
cmp     al, 60h ; '`'
jz      short loc_17220
clc

loc_1721E:
pop     ds
retn

loc_17220:              ; Controller return code
or      ds:dsk_ret_code, 40h ;  00h = ok
                        ;  01h = bad command or parameter
                        ;  02h = can't find address mark
                        ;  03h = can't write, protected dsk
                        ;  04h = sector not found
                        ;  08h = DMA overrun
                        ;  09h = DMA attempt over 64K bound
                        ;  10h = bad CRC on disk read
                        ;  20h = controller failure
                        ;  40h = seek failure
                        ;  80h = timeout, no response
pop     ds
stc
retn



WaitForIRQ6 proc near
sti
push    bx
push    cx
push    dx
mov     bl, 14h
xor     cx, cx

loc_17230:              ; Bit 7 = Diskette interrupt occurred. (int 0Eh)
test    ds:dsk_recal_stat, 80h
jnz     short loc_17243
loop    loc_17230
dec     bl
jnz     short loc_17230
or      ds:dsk_ret_code, 80h ; 80h = timeout, no response
stc

loc_17243:
pushf
and     ds:dsk_recal_stat, 7Fh ; clear the interrupt bit.
popf
pop     dx
pop     cx
pop     bx
retn
WaitForIRQ6 endp




SaveCtlrReturnCd proc near
cld
mov     di, offset dsk_status_1 ; Status bytes-disk controller chip
                        ;  Note: 7 info bytes returned from
                        ;  controller are saved here. Refer
                        ;  to the NEC uPD 765 chip manual
                        ;  for the specific info, depending
                        ;  on the previous command issued.
push    cx
push    dx
push    bx
mov     bl, 7

loc_17257:
mov     bh, 14h
xor     cx, cx
mov     dx, 3F4h

loc_1725E:              ; Floppy: main status reg bits:
in      al, dx          ; 7: 1=OK to snd/rcv cmd or data
test    al, 80h
jnz     short loc_17272
loop    loc_1725E
dec     bh
jnz     short loc_1725E
or      ds:dsk_ret_code, 80h ; Controller return code
                        ;  00h = ok
                        ;  01h = bad command or parameter
                        ;  02h = can't find address mark
                        ;  03h = can't write, protected dsk
                        ;  04h = sector not found
                        ;  08h = DMA overrun
                        ;  09h = DMA attempt over 64K bound
                        ;  10h = bad CRC on disk read
                        ;  20h = controller failure
                        ;  40h = seek failure
                        ;  80h = timeout, no response

loc_1726E:
stc
jmp     short loc_17295
align 2

loc_17272:              ; Floppy: main status reg bits:
in      al, dx          ; 0-3: diskette busy
                        ; 4: 1=cntrlr busy
                        ; 5: 1=non-DMA mode
                        ; 6: Data dir: 1=cntrlr to CPU
                        ; 7: 1=OK to snd/rcv cmd or data
test    al, 40h
jnz     short loc_1727E

loc_17277:              ; Controller return code
or      ds:dsk_ret_code, 20h ;  00h = ok
                        ;  01h = bad command or parameter
                        ;  02h = can't find address mark
                        ;  03h = can't write, protected dsk
                        ;  04h = sector not found
                        ;  08h = DMA overrun
                        ;  09h = DMA attempt over 64K bound
                        ;  10h = bad CRC on disk read
                        ;  20h = controller failure
                        ;  40h = seek failure
                        ;  80h = timeout, no response
jmp     short loc_1726E

loc_1727E:
inc     dx
in      al, dx          ; Floppy: FDC command/data register.
mov     [di], al        ; 0040:0042
inc     di
mov     cx, 28h ; '('

loc_17286:
loop    loc_17286
dec     dx
in      al, dx          ; Floppy: main status reg bits:
                        ; 0-3: diskette busy
                        ; 4: 1=cntrlr busy
                        ; 5: 1=non-DMA mode
                        ; 6: Data dir: 1=cntrlr to CPU
                        ; 7: 1=OK to snd/rcv cmd or data
test    al, 10h
jz      short loc_17294
dec     bl
jnz     short loc_17257
jmp     short loc_17277

loc_17294:
clc

loc_17295:
pop     bx
pop     dx
pop     cx
retn
SaveCtlrReturnCd endp




SelectHead proc near
mov     dl, cs:CurrentDrive
mov     al, cs:DiskType
push    ds
call    MaxtMotorTimer
cmp     al, 7
jnb     short loc_172B5
cmp     cs:CurrentSide, 1
jz      short loc_172B5
clc
pop     ds
retn

loc_172B5:
call    sub_1706D
pop     ds
retn
SelectHead endp



; Delay by amount proportional to AL.

Delay proc near
push    cx
push    bx
push    ax
mov     bl, al

loc_172BF:
push    bx

loc_172C0:
pushf
cli
mov     al, 6           ; Latch timer 0 count.
                        ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
mov     bl, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
mov     bh, al
mov     al, 6           ; Latch timer 0 count.
                        ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
mov     ah, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
popf
xchg    ah, al
sub     ax, bx
cmp     ah, 0
jz      short loc_172C0
neg     bx
mov     ax, bx
sub     ax, cs:word_15F80
pop     bx
mov     cx, ax

loc_172F8:
push    bx

loc_172F9:
pushf
cli
mov     al, 6           ; Latch timer 0 count.
                        ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
mov     bl, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
mov     bh, al
mov     al, 6           ; Latch timer 0 count.
                        ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
mov     ah, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
popf
xchg    ah, al
sub     ax, bx
cmp     ah, 0
jz      short loc_172F9
neg     bx
mov     ax, bx
sub     ax, cs:word_15F80
pop     bx
sub     ax, cx
cmp     ax, 952h
jb      short loc_172F8
dec     bl
jz      short loc_1733C
jmp     short loc_172BF

loc_1733C:
pop     ax
pop     bx
pop     cx
retn
Delay endp




Delay2 proc near
push    cx
push    ax
push    bx

loc_17343:
pushf
cli
mov     al, 6           ; Latch timer 0 count.
                        ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
mov     bl, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
mov     bh, al
mov     al, 6           ; Latch timer 0 count.
                        ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
mov     ah, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
popf
xchg    ah, al
sub     ax, bx
cmp     ah, 0
jz      short loc_17343
neg     bx
mov     ax, bx
sub     ax, cs:word_15F80
pop     bx
mov     cx, ax

loc_1737B:
push    bx

loc_1737C:
pushf
cli
mov     al, 6           ; Latch timer 0 count.
                        ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
mov     bl, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
mov     bh, al
mov     al, 6           ; Latch timer 0 count.
                        ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
mov     ah, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
popf
xchg    ah, al
sub     ax, bx
cmp     ah, 0
jz      short loc_1737C
neg     bx
mov     ax, bx
sub     ax, cs:word_15F80
pop     bx
sub     ax, cx
cmp     ax, 0EEh ; 'e'
jb      short loc_1737B
pop     ax
pop     cx
retn
Delay2 endp



; Enables controller, turns on floppy DMA,
; resets transcopy board.

TrackReadOff proc near
pushf
push    bx
mov     bl, 0Ch
jmp     short loc_173C7
TrackReadOff endp

db 90h


; Selects drive, enables controller, turns off floppy DMA,
; resets transcopy board.

TrackReadOn proc near
pushf
push    bx
mov     bl, 4

loc_173C7:
sti
jmp     short $+2
cli
mov     dl, ds:CurrentDrive
mov     cl, dl
mov     al, 10h
shl     al, cl
or      al, dl
or      al, bl
mov     dx, 3F2h
out     dx, al          ; Floppy: digital output reg bits:
                        ; 0-1: Drive to select 0-3 (AT: bit 1 not used)
                        ; 2:   0=reset diskette controller; 1=enable controller
                        ; 3:   1=enable diskette DMA and interrupts
                        ; 4-7: drive motor enable.  Set bits to turn drive ON.
                        ;
mov     dx, ds:TC_Port3
mov     al, ds:TC_Port3Byte
and     al, 0F9h ; '·'
or      al, 1
out     dx, al          ; turn on GO.
jmp     short $+2
dec     al
out     dx, al          ; turn off GO.
sti
push    ds
call    MaxtMotorTimer
cli
and     ds:dsk_recal_stat, 7Fh ; Recalibrate floppy drive bits
                        ;    3       2       1       0
                        ; drive-3 drive-2 drive-1 drive-0
                        ;
                        ; bit 7 = interrupt flag
pop     ds
pop     bx
popf
retn
TrackReadOn endp




sub_173FD proc near
mov     dx, cs:DMAWrdCntPort
in      al, dx          ; DMA controller, 8237A-5.
                        ; channel 2 current word count
jmp     short $+2
mov     bl, al
in      al, dx          ; DMA controller, 8237A-5.
                        ; channel 2 current word count
mov     bh, al
cmp     bx, 5
jbe     short WaitForDMA
cmp     bx, 0FFFFh
jz      short WaitForDMA
mov     al, 0
out     dx, al          ; DMA controller, 8237A-5.
                        ; channel 2 base address and word count
jmp     short $+2
mov     al, 0
out     dx, al          ; DMA controller, 8237A-5.
                        ; channel 2 base address and word count
jmp     short $+2
in      al, dx          ; DMA controller, 8237A-5.
                        ; channel 2 current word count
jmp     short $+2
mov     bl, al
in      al, dx          ; DMA controller, 8237A-5.
                        ; channel 2 current word count
mov     bh, al
cmp     bx, 5
jbe     short WaitForDMA
cmp     bx, 0FFFFh
jz      short WaitForDMA
mov     al, 0
out     dx, al          ; DMA controller, 8237A-5.
                        ; channel 2 base address and word count
jmp     short $+2
mov     al, 0
out     dx, al          ; DMA controller, 8237A-5.
                        ; channel 2 base address and word count
jmp     short $+2
in      al, dx          ; DMA controller, 8237A-5.
                        ; channel 2 current word count
jmp     short $+2
mov     bl, al
in      al, dx          ; DMA controller, 8237A-5.
                        ; channel 2 current word count
mov     bh, al
mov     cx, 10h

loc_17445:
loop    loc_17445
retn
sub_173FD endp




WaitForDMA proc near
push    dx
push    cx
push    bx
mov     dx, cs:DMAWrdCntPort

loc_17450:              ; DMA controller, 8237A-5.
in      al, dx          ; channel 2 current word count
jmp     short $+2
mov     ah, al
in      al, dx          ; DMA controller, 8237A-5.
                        ; channel 2 current word count
cmp     ax, 0
jnz     short loc_17466
in      al, dx          ; DMA controller, 8237A-5.
                        ; channel 2 current word count
jmp     short $+2
mov     ah, al
in      al, dx          ; DMA controller, 8237A-5.
                        ; channel 2 current word count
cmp     ax, 0
jz      short loc_1747C

loc_17466:
cmp     ax, 0FFFFh
jz      short loc_1747C
mov     bx, ax
mov     cx, 1F4h

loc_17470:              ; DMA controller, 8237A-5.
in      al, dx          ; channel 2 current word count
jmp     short $+2
mov     ah, al
in      al, dx          ; DMA controller, 8237A-5.
                        ; channel 2 current word count
cmp     ax, bx
jnz     short loc_17450
loop    loc_17470

loc_1747C:
pop     bx
pop     cx
pop     dx
retn
WaitForDMA endp




ReadDMAWrdCnt proc near
push    dx
mov     dx, cs:DMAWrdCntPort
in      al, dx          ; DMA controller, 8237A-5.
                        ; channel 2 current word count
jmp     short $+2
mov     bl, al
in      al, dx          ; DMA controller, 8237A-5.
                        ; channel 2 current word count
mov     bh, al
cmp     bl, 0
jnz     short loc_174A1
in      al, dx          ; DMA controller, 8237A-5.
                        ; channel 2 current word count
jmp     short $+2
mov     ah, al
in      al, dx          ; DMA controller, 8237A-5.
                        ; channel 2 current word count
xchg    ah, al
cmp     ax, bx
jbe     short loc_174A1
inc     bh

loc_174A1:
pop     dx
retn
ReadDMAWrdCnt endp




ReadDMACurrAddr proc near
push    dx
mov     dx, cs:DMACurrAddrPort
in      al, dx          ; DMA controller, 8237A-5.
                        ; channel 2 current address
jmp     short $+2
mov     bl, al
in      al, dx          ; DMA controller, 8237A-5.
                        ; channel 2 current address
mov     bh, al
cmp     bl, 0F8h ; '°'
jb      short loc_174C4
in      al, dx          ; DMA controller, 8237A-5.
                        ; channel 2 current address
jmp     short $+2
mov     ah, al
in      al, dx          ; DMA controller, 8237A-5.
                        ; channel 2 current address
xchg    ah, al
cmp     ax, bx
jnb     short loc_174C4
dec     bh

loc_174C4:
pop     dx
retn
ReadDMACurrAddr endp




sub_174C6 proc near
nop
cmp     ds:KeepTrkLngthFlag, 59h ; 'Y'
jnz     short locret_174FA
cmp     ds:word_1006A, 0
jnz     short locret_174FA
mov     ax, ds:word_13CC9
cmp     ax, ds:word_13CEE
jnz     short locret_174FA
call    GetInt0E
mov     ds:word_15FA8, 0

loc_174E7:
call    sub_174FB
jb      short loc_174F7
inc     ds:word_15FA8
cmp     ds:word_15FA8, 5
jb      short loc_174E7

loc_174F7:
call    RestoreInt0E

locret_174FA:
retn
sub_174C6 endp




sub_174FB proc near
cli
call    ClearTimer0
mov     bx, 0
mov     ds:word_15FB3, 0
mov     ds:word_15FB5, 0
mov     ds:word_15FB7, 0
mov     dx, ds:TC_Port_Base

loc_17518:
in      al, dx
and     al, 80h
jnz     short loc_17518
jmp     short $+2

loc_1751F:
in      al, dx
and     al, 80h
jz      short loc_1751F
sti
push    bx

loc_17526:
pushf
cli
mov     al, 6           ; Latch timer 0 count.
                        ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
mov     bl, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
mov     bh, al
mov     al, 6           ; Latch timer 0 count.
                        ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
mov     ah, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
popf
xchg    ah, al
sub     ax, bx
cmp     ah, 0
jz      short loc_17526
neg     bx
mov     ds:word_15F80, bx
pop     bx
xor     ax, ax

loc_1755B:
push    bx
call    sub_176B0
pop     bx
mov     ax, ds:word_15FAF
cmp     bx, 0
jz      short loc_1756C
sub     ax, ds:word_15FB1

loc_1756C:
mov     word ptr ds:unk_15FB9[bx], ax
mov     ax, ds:word_15FAF
mov     ds:word_15FB1, ax
add     bx, 4
add     ds:word_15FB5, ax
adc     ds:word_15FB7, 0
push    ds
call    MaxtMotorTimer
mov     cx, word ptr ds:dsk_status_4
mov     dx, word ptr ds:dsk_status_6
pop     ds
mov     si, ds:word_15FB3
cmp     cx, word ptr ds:unk_13E35[si]
jnz     short loc_1759F
cmp     dx, word ptr ds:unk_13E37[si]
jz      short loc_175A1

loc_1759F:
stc
retn

loc_175A1:
add     si, 4
mov     ds:word_15FB3, si
cmp     si, ds:word_13CC9
jb      short loc_1755B
mov     di, 0
call    GetTrkDatOfs
mov     cl, 4
shl     bx, cl
mov     bp, bx

loc_175BA:
mov     ax, ds:word_14235[di]
cmp     di, 0
jz      short loc_175C7
sub     ax, word ptr ds:unk_14231[di]

loc_175C7:
mov     cx, word ptr ds:unk_15FB9[di]
mov     dx, ds:word_13D71
mul     dx
push    cx
sub     cx, ax
jnb     short loc_175D8
neg     cx

loc_175D8:
cmp     cx, 8000h
jb      short loc_175E7
dec     dx
cmp     ax, 8000h
jb      short loc_175E7
add     dx, 2

loc_175E7:
pop     ax
mov     dh, dl
mov     dl, ah
mov     ah, al
mov     al, 0
shl     ax, 1
rcl     dx, 1
shl     ax, 1
rcl     dx, 1
mov     bl, ds:CurrentDrive
mov     bh, 0
shl     bx, 1
mov     cx, word ptr ds:stru_15F64.Drive0[bx]
cmp     cx, dx
div     cx
shr     di, 1
cmp     ds:word_15FA8, 0
jz      short loc_17620
mov     cx, 0
add     ax, word ptr ds:TrackDataBuffer[bp+di]
adc     cx, 0
shr     cx, 1
rcr     ax, 1

loc_17620:
mov     word ptr ds:TrackDataBuffer[bp+di], ax
shl     di, 1
add     di, 4
cmp     di, ds:word_13CEE
jnb     short locret_17632
jmp     short loc_175BA

locret_17632:
retn
sub_174FB endp




GetInt0E proc near
push    es
cli
mov     ax, 350Eh
int     21h             ; DOS - 2+ - GET INTERRUPT VECTOR
                        ; AL = interrupt number
                        ; Return: ES:BX = value of interrupt vector
mov     ds:OldInt0ESeg, es
mov     ds:OldInt0EOff, bx
push    cs
pop     ds
assume ds:seg001
mov     dx, offset Int0E_Entry
mov     ax, 250Eh
int     21h             ; DOS - SET INTERRUPT VECTOR
                        ; AL = interrupt number
                        ; DS:DX = new vector to be used for specified interrupt
pop     es
retn
GetInt0E endp




RestoreInt0E proc near
cli
push    ds
push    es
mov     dx, OldInt0EOff
mov     ds, OldInt0ESeg
assume ds:nothing
mov     ax, 250Eh
int     21h             ; DOS - SET INTERRUPT VECTOR
                        ; AL = interrupt number
                        ; DS:DX = new vector to be used for specified interrupt
pop     es
pop     ds
retn
RestoreInt0E endp


Int0E_Entry:            ; IRQ6 - Diskette controller.
sti
push    ds
push    ax
mov     ax, seg bdata
mov     ds, ax
assume ds:bdata
or      dsk_recal_stat, 80h ; Recalibrate floppy drive bits
                        ;    3       2       1       0
                        ; drive-3 drive-2 drive-1 drive-0
                        ;
                        ; bit 7 = interrupt flag
push    bx

loc_1766F:
pushf
cli
mov     al, 6           ; Latch timer 0 count.
                        ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
mov     bl, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
mov     bh, al
mov     al, 6           ; Latch timer 0 count.
                        ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
mov     ah, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
popf
xchg    ah, al
sub     ax, bx
cmp     ah, 0
jz      short loc_1766F
neg     bx
mov     ax, bx
sub     ax, cs:word_15F80
pop     bx
mov     cs:word_15FAF, ax
mov     al, 66h ; 'f'
out     20h, al         ; Interrupt controller, 8259A.
pop     ax
pop     ds
assume ds:nothing
iret



sub_176B0 proc near
cli
in      al, 21h         ; Interrupt controller, 8259A.
mov     ds:byte_161B9, al
in      al, 0A1h        ; Interrupt Controller #2, 8259A
mov     ds:byte_161BA, al
mov     al, 0BFh ; '+'
out     21h, al         ; Interrupt controller, 8259A.
sti
push    dx
push    ds
mov     dl, ds:CurrentDrive
mov     dh, ds:CurrentSide
mov     ax, seg bdata
mov     ds, ax
assume ds:bdata
mov     ah, 4Ah ; 'J'   ; Diskette controller command 4Ah
                        ; Read ID
call    DisketteCommand
mov     ah, dh
shl     ah, 1
shl     ah, 1
and     ah, 4
or      ah, dl
sti
call    DisketteCommand
hlt
cli
mov     al, cs:byte_161B9
out     21h, al         ; Interrupt controller, 8259A.
mov     al, cs:byte_161BA
out     0A1h, al        ; Interrupt Controller #2, 8259A
sti
call    SaveCtlrReturnCd
clc
pop     ds
assume ds:nothing
pop     dx
retn
sub_176B0 endp




sub_176F9 proc near
cmp     ds:byte_167D4, 0
jz      short loc_17702
clc
retn

loc_17702:
mov     ax, 203h
mov     cx, 1
mov     dh, 0
mov     dl, ds:CurrentDrive
mov     bx, offset unk_161CA
push    cs
pop     es
assume es:seg001
call    sub_17851
jnb     short loc_17732
mov     ah, 0
int     13h             ; DISK - RESET DISK SYSTEM
                        ; DL = drive (if bit 7 is set both hard disks and floppy disks reset)

loc_1771C:
clc

loc_1771D:
pushf
mov     ax, 0
push    cs
pop     es
mov     di, offset unk_161CA
mov     cx, 300h
rep stosw
mov     ds:byte_167D4, 0FEh ; '¦'
popf
retn

loc_17732:
cmp     ds:byte_15FA7, 0FFh
jnz     short loc_1774A
push    ds
mov     ax, seg bdata
mov     ds, ax
assume ds:bdata
mov     al, dsk_data_rate ; Last data rate for diskette
                        ;  bits 7 & 6 = 00 for 500K bit/sec
                        ;             = 01 for 300K bit/sec
                        ;             = 10 for 250K bit/sec
                        ;             = 11 for 1M bit/sec
                        ;  bits 5 & 4 = step rateRate at start of operation
                        ;  bits 3 & 2 = 00 for 500K bit/sec
                        ;             = 01 for 300K bit/sec
                        ;             = 10 for 250K bit/sec
                        ;             = 11 for 1M bit/sec
pop     ds
assume ds:nothing
and     al, 0C0h
jnz     short loc_1774A
stc
jmp     short loc_1771D

loc_1774A:
cmp     ds:byte_161D5, 0
jnz     short loc_177B5
cmp     ds:word_161D8, 1
jnz     short loc_177B5
mov     ax, ds:word_161E2
cmp     ax, 0Ah
ja      short loc_177B5
cmp     ax, 0
jz      short loc_177B5
mov     ds:word_167CC, ax
mov     ax, ds:word_161E4
cmp     ax, 2
ja      short loc_177B5
cmp     ax, 0
jz      short loc_177B5
mov     ds:word_167CA, ax
mov     al, ds:byte_161D7
cmp     al, 2
ja      short loc_177B5
cmp     al, 0
jz      short loc_177B5
mov     ah, 0
mov     ds:word_167CE, ax
mov     al, ds:byte_161DA
mul     ds:byte_161E0
mov     bx, ax
mov     ax, ds:word_161DB
mov     cl, 4
shr     ax, cl
add     ax, bx
inc     ax
mov     ds:word_167D0, ax
mov     ax, ds:word_161DD
mov     cx, ds:word_167CC
div     cl
mov     cx, ds:word_167CA
div     cl
mov     ah, 0
mov     ds:word_167D2, ax
jmp     short loc_177ED
db 90h

loc_177B5:
cmp     ds:byte_163CA, 0F9h ; '·'
jnb     short loc_177BF
jmp     loc_1771C

loc_177BF:
mov     bh, 0
mov     bl, ds:byte_163CA
sub     bl, 0F9h ; '·'
mov     al, byte ptr ds:unk_167D6[bx]
mov     ah, 0
mov     ds:word_167CC, ax
mov     al, byte ptr ds:unk_167DD[bx]
mov     ds:word_167CA, ax
mov     al, byte ptr ds:unk_167E4[bx]
mov     ds:word_167D0, ax
mov     al, byte ptr ds:unk_167EB[bx]
mov     ds:word_167CE, ax
mov     al, byte ptr ds:unk_167F2[bx]
mov     ds:word_167D2, ax

loc_177ED:
mov     di, offset unk_161CA
mov     cx, 80h ; 'Ç'
mov     ax, 0
push    cs
pop     es
rep stosw
mov     cx, 0
mov     dx, 0
mov     bx, 1

loc_17803:
call    sub_17876
push    bx
mov     bx, cx
shl     bx, 1
add     bx, dx
cmp     ax, 0FF7h
jnz     short loc_17821
mov     byte ptr ds:unk_161CA[bx], 2
cmp     bx, 2
jb      short loc_17821
mov     byte ptr ds:unk_161C8[bx], 1

loc_17821:
pop     bx
add     bx, ds:word_167CE
cmp     bx, ds:word_167CC
jbe     short loc_17803
sub     bx, ds:word_167CC
cmp     ds:word_167CA, 1
jz      short loc_1783D
inc     dx
cmp     dx, 2
jb      short loc_17803

loc_1783D:
mov     bx, 1
mov     dx, 0
inc     cx
cmp     cx, ds:word_167D2
jb      short loc_17803
mov     ds:byte_167D4, 0FFh
clc
retn
sub_176F9 endp




sub_17851 proc near
mov     ds:word_161BB, ax
int     13h             ; INT 13 - DISK - READ SECTOR(S) INTO MEMORY
                        ;         AH = 02h
                        ;         AL = number of sectors to read (must be nonzero)
                        ;         CH = low eight bits of cylinder number
                        ;         CL = sector number 1-63 (bits 0-5)
                        ;              high two bits of cylinder (bits 6-7, hard disk only)
                        ;         DH = head number
                        ;         DL = drive number (bit 7 set for hard disk)
                        ;         ES:BX -; data buffer
                        ; Return: CF set on error
                        ;             if AH = 11h (corrected ECC error), AL = burst length
                        ;         CF clear if successful
                        ;         AH = status (see #00234)
                        ;         AL = number of sectors transferred (only valid if CF set for some
                        ;               BIOSes)
jnb     short locret_17875
cmp     ds:byte_15FA7, 0FFh
jnz     short loc_17869
call    sub_16BDA
mov     ax, ds:word_161BB
int     13h             ; DISK -
jnb     short locret_17875

loc_17869:
cmp     ah, 6
jnz     short loc_17874
mov     ax, ds:word_161BB
int     13h             ; DISK -
retn

loc_17874:
stc

locret_17875:
retn
sub_17851 endp




sub_17876 proc near
push    bx
push    cx
push    dx
call    sub_1789E
cmp     ax, 0
jz      short loc_17897
mov     dx, ax
shr     ax, 1
add     ax, dx
mov     bx, ax
mov     ax, word ptr ds:byte_163CA[bx]
test    dx, 1
jz      short loc_17897
mov     cl, 4
shr     ax, cl

loc_17897:
and     ah, 0Fh
pop     dx
pop     cx
pop     bx
retn
sub_17876 endp




sub_1789E proc near
push    si
push    di
push    bx
push    cx
push    dx
mov     ax, dx
mul     ds:word_167CC
dec     bx
add     ax, bx
adc     dx, 0
mov     si, ax
mov     di, dx
mov     ax, ds:word_167CA
mul     ds:word_167CC
mul     cx
add     ax, si
adc     dx, di
sub     ax, ds:word_167D0
sbb     dx, 0
jb      short loc_178D3
div     ds:word_167CE
inc     ax
inc     ax
clc
jmp     short loc_178D5
db 90h

loc_178D3:
xor     ax, ax

loc_178D5:
pop     dx
pop     cx
pop     bx
pop     di
pop     si
retn
sub_1789E endp




ClearTimer0 proc near
mov     al, 36h ; '6'   ; timer 0 16 bit mode
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
mov     al, 0
out     40h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
out     40h, al         ; Timer 8253-5 (AT: 8254.2).
retn
ClearTimer0 endp

db    0
db    8
db    0
db    0
word_178EE dw 0
word_178F0 dw 0
unk_178F2 db    0
db    0
unk_178F4 db  4Fh ; O
unk_178F5 db  18h
db    0
db    0
db  4Fh ; O
db    4
db    0
db    4
db  4Fh ; O
db  12h
db    0
db  14h
db  4Fh ; O
db  18h
db    0
db  0Dh
db  4Fh ; O
db  12h
db    0
db    0
word_17908 dw 0
byte_1790A db 0
word_1790B dw 0
word_1790D dw 0
word_1790F dw 0
byte_17911 db 0
byte_17912 db 0
VideoAttribute db 37h   ; Sets color of displayed characters.
                        ; Bitfields for character's display attribute:
                        ; Bit(s)           Description
                        ;  7               foreground blink or (alternate) background bright
                        ;  6-4             background color
                        ;  3               foreground bright or (alternate) alternate character set
                        ;  2-0             foreground color
                        ;
                        ; Values for character color:
                        ;                 Normal             Bright
                        ;  000b           black              dark gray
                        ;  001b           blue               light blue
                        ;  010b           green              light green
                        ;  011b           cyan               light cyan
                        ;  100b           red                light red
                        ;  101b           magenta            light magenta
                        ;  110b           brown              yellow
                        ;  111b           light gray         white
ColorMono db 0          ; Calls for monochrome screen if 0, color if 1
byte_17915 db 0
byte_17916 db 0
byte_17917 db 0
byte_17918 db 0
byte_17919 db 0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
NumDsksScratch db 0Ah dup(0) ; Hex to decimal string decode area
                        ; for display of number of disks.
db 0CDh ; -
db  20h



DisplayHex proc near
cld
push    cx
mov     cx, 4
push    ax

loc_17A2A:
pop     ax
rol     ax, 1
rol     ax, 1
rol     ax, 1
rol     ax, 1
push    ax
and     al, 0Fh
cmp     al, 9
jbe     short loc_17A3C
add     al, 7

loc_17A3C:
add     al, '0'
call    DisplayChar
loop    loc_17A2A
pop     ax
pop     cx
retn
DisplayHex endp




DisplayHexTrack proc near
cld
push    cx
mov     cx, 2
push    ax

loc_17A4C:
pop     ax
rol     al, 1
rol     al, 1
rol     al, 1
rol     al, 1
push    ax
and     al, 0Fh
cmp     al, 9
jbe     short loc_17A5E
add     al, 7

loc_17A5E:
add     al, '0'
call    DisplayChar
loop    loc_17A4C
pop     ax
pop     cx
retn
DisplayHexTrack endp




DisplayDecByte proc near
push    ax
cmp     al, 9
jbe     short loc_17A6F
add     al, 7

loc_17A6F:
add     al, '0'
call    DisplayChar
pop     ax
retn
DisplayDecByte endp




DisplayNumDsks proc near
push    ax
push    bx
push    dx
push    di
push    bp
mov     di, 6
mov     ds:NumDsksScratch[di], 24h ; '$'
mov     bx, 0Ah

loc_17A86:
xor     dx, dx
div     bx
xchg    al, dl
add     al, 30h ; '0'
dec     di
mov     ds:NumDsksScratch[di], al
mov     al, dl
or      ax, ax
jnz     short loc_17A86
lea     dx, NumDsksScratch[di]
call    DecodeString
pop     bp
pop     di
pop     dx
pop     bx
pop     ax
retn
DisplayNumDsks endp




sub_17AA6 proc near
push    ax
mov     al, ds:byte_1949B
mov     ds:VideoAttribute, al
pop     ax
retn
sub_17AA6 endp




sub_17AAF proc near
push    ax
mov     al, ds:byte_1949C
mov     ds:VideoAttribute, al
pop     ax
retn
sub_17AAF endp




DecodeString proc near
push    ax
DecodeString endp

push    cx
push    si
push    dx
mov     si, dx
mov     cx, 800h

loc_17AC1:
cld
lodsb
cmp     al, 7Ch ; '|'
jz      short ChangeAttribute
cmp     al, 1Dh
jz      short MoveCursor
cmp     al, 24h ; '$'
jz      short EndOfString
or      al, al
jz      short EndOfString
call    DisplayChar

loc_17AD6:
loop    loc_17AC1

EndOfString:
pop     dx
pop     si
pop     cx
pop     ax
retn

ChangeAttribute:
lodsb
mov     ds:VideoAttribute, al
jmp     short loc_17AD6

MoveCursor:
call    ReadCursorPos
lodsb
mov     dl, al
call    SetCursorPos
jmp     short loc_17AD6



sub_17AEE proc near
push    ax
mov     al, 20h ; ' '
call    DisplayChar
pop     ax
retn
sub_17AEE endp




sub_17AF6 proc near
push    cx
mov     cl, al
mov     ch, 0

loc_17AFB:
call    sub_17AEE
loop    loc_17AFB
pop     cx
retn
sub_17AF6 endp




DisplayChar proc near
push    ax              ; Displays a character with color attribute.
push    bx
push    cx
push    dx
push    si
push    bp
push    ax
mov     ah, 3
mov     bh, 0
int     10h             ; - VIDEO - READ CURSOR POSITION
                        ; BH = page number
                        ; Return: DH,DL = row,column, CH = cursor start line, CL = cursor end line
mov     si, ds:word_178F0
pop     ax
cmp     al, 0Dh
jnz     short loc_17B1F
mov     dl, byte ptr ds:unk_178F2[si]
jmp     short loc_17B82
db 90h

loc_17B1F:
cmp     al, 0Ah
jnz     short loc_17B28
inc     dh
jmp     short loc_17B6C
align 2

loc_17B28:
cmp     al, 7
jnz     short loc_17B32
call    Beep
jmp     short loc_17B82
align 2

loc_17B32:
cmp     al, 8
jnz     short loc_17B41
cmp     dl, byte ptr ds:unk_178F2[si]
jz      short loc_17B82
dec     dl
jmp     short loc_17B82
db 90h

loc_17B41:
mov     bh, 0
mov     bl, ds:VideoAttribute
sub     bl, ds:byte_1949D
mov     ah, byte ptr ds:unk_1949E[bx]
cmp     ds:ColorMono, 0
jnz     short loc_17B5A
mov     ah, ds:byte_194AE[bx]

loc_17B5A:
mov     bl, ah
mov     cx, 1
mov     ah, 9
int     10h             ; - VIDEO - WRITE ATTRIBUTES/CHARACTERS AT CURSOR POSITION
                        ; AL = character, BH = display page
                        ; BL = attributes of character (alpha modes) or color (graphics modes)
                        ; CX = number of times to write character
inc     dl
cmp     ds:word_178F0, 0Ch
jz      short loc_17B82

loc_17B6C:
cmp     dl, byte ptr ds:unk_178F4[si]
jbe     short loc_17B78
mov     dl, byte ptr ds:unk_178F2[si]
inc     dh

loc_17B78:
cmp     dh, byte ptr ds:unk_178F5[si]
jbe     short loc_17B82
mov     dh, byte ptr ds:unk_178F5[si]

loc_17B82:
call    SetCursorPos
pop     bp
pop     si
pop     dx
pop     cx
pop     bx
pop     ax
retn
DisplayChar endp




SetCursorPos proc near
push    ax
push    bx
push    bp
mov     bh, 0
mov     ah, 2
int     10h             ; - VIDEO - SET CURSOR POSITION
                        ; DH,DL = row, column (0,0 = upper left)
                        ; BH = page number
pop     bp
pop     bx
pop     ax
mov     ds:word_178EE, dx
retn
SetCursorPos endp




ReadCursorPos proc near
push    ax
push    bx
push    bp
push    cx
mov     ah, 3
mov     bh, 0
int     10h             ; - VIDEO - READ CURSOR POSITION
                        ; BH = page number
                        ; Return: DH,DL = row,column, CH = cursor start line, CL = cursor end line
pop     cx
pop     bp
pop     bx
pop     ax
retn
ReadCursorPos endp

mov     ds:word_178F0, 4
jmp     short loc_17BD6
db 90h



sub_17BB5 proc near
mov     ds:word_178F0, 8
jmp     short loc_17BD6
sub_17BB5 endp

align 2



sub_17BBE proc near
mov     ds:word_178F0, 0Ch
jmp     short loc_17BD6
sub_17BBE endp

db  90h ; É
mov     ds:word_178F0, 10h
jmp     short loc_17BD6
db  90h ; É



ClearScreen proc near
mov     ds:word_178F0, 0

loc_17BD6:
push    ax
push    bx
push    cx
push    dx
push    si
push    bp
mov     al, ds:byte_1949B
mov     ds:VideoAttribute, al
mov     si, ds:word_178F0
mov     cx, word ptr ds:unk_178F2[si]
mov     dx, word ptr ds:unk_178F4[si]
mov     bh, 7
mov     ax, 700h
int     10h             ; - VIDEO - SCROLL PAGE DOWN
                        ; AL = number of lines to scroll window (0 = blank whole window)
                        ; BH = attributes to be used on blanked lines
                        ; CH,CL = row,column of upper left corner of window to scroll
                        ; DH,DL = row,column of lower right corner of window
mov     dx, word ptr ds:unk_178F2[si]
call    SetCursorPos
pop     bp
pop     si
pop     dx
pop     cx
pop     bx
pop     ax
retn
ClearScreen endp




Beep proc near
push    ax
push    bx
push    cx
push    dx
push    si
cli
mov     al, 0B6h ; '¦'  ; timer 2 16 bit mode 3
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
mov     dx, 400h
mov     si, dx
mov     ax, dx
shr     si, 1
shr     si, 1
out     42h, al         ; Timer 8253-5 (AT: 8254.2).
xchg    ah, al
out     42h, al         ; Timer 8253-5 (AT: 8254.2).
xchg    al, ah
in      al, 61h         ; PC/XT PPI port B bits:
                        ; 0: Tmr 2 gate --- OR 03H=spkr ON
                        ; 1: Tmr 2 data -+  AND 0fcH=spkr OFF
                        ; 3: 1=read high switches
                        ; 4: 0=enable RAM parity checking
                        ; 5: 0=enable I/O channel check
                        ; 6: 0=hold keyboard clock low
                        ; 7: 0=enable kbrd
mov     bl, al
or      al, 3
out     61h, al         ; PC/XT PPI port B bits:
                        ; 0: Tmr 2 gate --- OR 03H=spkr ON
                        ; 1: Tmr 2 data -+  AND 0fcH=spkr OFF
                        ; 3: 1=read high switches
                        ; 4: 0=enable RAM parity checking
                        ; 5: 0=enable I/O channel check
                        ; 6: 0=hold keyboard clock low
                        ; 7: 0=enable kbrd
mov     cx, 2000h

loc_17C2B:              ; PC/XT PPI port C. Bits:
in      al, 62h         ; 0-3: values of DIP switches
                        ; 5: 1=Timer 2 channel out
                        ; 6: 1=I/O channel check
                        ; 7: 1=RAM parity check error occurred.
and     al, 20h
cmp     al, bh
mov     bh, al
jz      short loc_17C49
or      al, al
mov     ax, dx
jz      short loc_17C3F
sub     ax, si
jmp     short loc_17C41

loc_17C3F:
add     ax, si

loc_17C41:              ; Timer 8253-5 (AT: 8254.2).
out     42h, al
xchg    ah, al
out     42h, al         ; Timer 8253-5 (AT: 8254.2).
xchg    al, ah

loc_17C49:
loop    loc_17C2B
mov     al, bl
and     al, 0FCh
out     61h, al         ; PC/XT PPI port B bits:
                        ; 0: Tmr 2 gate --- OR 03H=spkr ON
                        ; 1: Tmr 2 data -+  AND 0fcH=spkr OFF
                        ; 3: 1=read high switches
                        ; 4: 0=enable RAM parity checking
                        ; 5: 0=enable I/O channel check
                        ; 6: 0=hold keyboard clock low
                        ; 7: 0=enable kbrd
mov     cx, 3E8h
sti

loc_17C55:
mul     ax
loop    loc_17C55
pop     si
pop     dx
pop     cx
pop     bx
pop     ax
retn
Beep endp




sub_17C5F proc near
push    dx
push    ax
push    bx
push    si
push    cx
call    ReadCursorPos
push    dx
mov     si, ds:word_178F0

loc_17C6C:
mov     bh, 0
mov     cx, 1
mov     ah, 0Ah
mov     al, 20h ; ' '
int     10h             ; - VIDEO - WRITE CHARACTERS ONLY AT CURSOR POSITION
                        ; AL = character, BH = display page - alpha mode
                        ; BL = color of character (graphics mode, PCjr only)
                        ; CX = number of times to write character
inc     dl
cmp     dl, byte ptr ds:unk_178F4[si]
jb      short loc_17C6C
pop     dx
call    SetCursorPos
pop     cx
pop     si
pop     bx
pop     ax
pop     dx
retn
sub_17C5F endp




sub_17C89 proc near
mov     ds:word_1790B, ax
mov     ax, 102h
jmp     short loc_17CA1
sub_17C89 endp

align 2
mov     ds:word_1790B, ax
mov     ax, 103h
jmp     short loc_17CA1
db 90h



sub_17C9B proc near
mov     ds:word_1790B, ax
mov     ax, 101h

loc_17CA1:
mov     ds:word_1790D, ax

loc_17CA4:
mov     ax, ds:word_1790D
call    sub_17E21
jb      short loc_17CC8
mov     al, ds:byte_17918
cmp     al, 0Dh
jnz     short loc_17CBD
cmp     byte ptr ds:word_1790B+1, 0FFh
jz      short loc_17CC3
mov     al, byte ptr ds:word_1790B

loc_17CBD:
mov     ah, ds:byte_17917
clc
retn

loc_17CC3:
call    Beep
jmp     short loc_17CA4

loc_17CC8:
stc
retn
sub_17C9B endp




sub_17CCA proc near
push    dx
mov     ds:byte_17912, bh
mov     ds:byte_17911, bl
mov     ds:word_1790B, ax
call    ReadCursorPos
mov     ds:word_1790F, dx
jmp     short loc_17CEA
align 2

loc_17CE0:
call    Beep
mov     dx, ds:word_1790F
call    SetCursorPos

loc_17CEA:
mov     ax, 200h
call    sub_17E21
jb      short loc_17D35
mov     al, ds:byte_17918
cmp     al, 0Dh
jnz     short loc_17D06
cmp     byte ptr ds:word_1790B+1, 0FFh
jz      short loc_17CE0
mov     al, byte ptr ds:word_1790B
jmp     short loc_17D22
align 2

loc_17D06:
call    sub_17D38
cmp     ds:byte_17919, 0Dh
jz      short loc_17D22
mov     ah, al
shl     ah, 1
shl     ah, 1
shl     ah, 1
shl     ah, 1
mov     al, ds:byte_17919
call    sub_17D38
or      al, ah

loc_17D22:
cmp     al, ds:byte_17911
jb      short loc_17CE0
cmp     al, ds:byte_17912
ja      short loc_17CE0
pop     dx
mov     ah, ds:byte_17917
clc
retn

loc_17D35:
pop     dx
stc
retn
sub_17CCA endp




sub_17D38 proc near
cmp     al, 39h ; '9'
jbe     short loc_17D3E
sub     al, 7

loc_17D3E:
and     al, 0Fh
retn
sub_17D38 endp




sub_17D41 proc near
push    dx
push    cx
push    si
push    di
mov     ds:byte_17912, bh
mov     ds:byte_17911, bl

loc_17D4D:
mov     ds:word_1790B, ax
call    ReadCursorPos
mov     ds:word_1790F, dx
jmp     short loc_17D64
align 2

loc_17D5A:
call    Beep
mov     dx, ds:word_1790F
call    SetCursorPos

loc_17D64:
mov     ax, 506h
call    sub_17E21
jb      short loc_17D79
mov     al, ds:byte_17918
cmp     al, 0Dh
jnz     short loc_17D8A
mov     ax, ds:word_1790B
jmp     short loc_17D7E
db 90h

loc_17D79:
stc
jb      short loc_17D7F

loc_17D7C:
or      al, 20h

loc_17D7E:
clc

loc_17D7F:
mov     bl, ah
mov     ah, ds:byte_17917
pop     di
pop     si
pop     cx
pop     dx
retn

loc_17D8A:
mov     ah, 0FFh
cmp     al, 'Y'
jz      short loc_17D7C
cmp     al, 'N'
jz      short loc_17D7C
cmp     al, '-'
jz      short loc_17D5A
mov     si, 0
mov     di, 0
mov     ds:byte_17915, 0
mov     ds:byte_17916, 0

loc_17DA8:
mov     al, ds:byte_17918[si]
cmp     al, '-'
jnz     short loc_17DB9
cmp     di, 1
jz      short loc_17D5A
inc     di
inc     si
jmp     short loc_17DA8

loc_17DB9:
cmp     al, 0Dh
jz      short loc_17DD6
call    sub_17D38
mov     ah, ds:byte_17915[di]
cmp     ah, 0Fh
ja      short loc_17D5A
mov     cl, 4
shl     ah, cl
or      al, ah
mov     ds:byte_17915[di], al
inc     si
jmp     short loc_17DA8

loc_17DD6:
mov     al, ds:byte_17915
mov     ah, ds:byte_17916
cmp     di, 1
jz      short loc_17DE4
mov     ah, al

loc_17DE4:
cmp     al, ah
ja      short loc_17DF6
cmp     al, ds:byte_17911
jb      short loc_17DF6
cmp     ah, ds:byte_17912
ja      short loc_17DF6
jmp     short loc_17D7E

loc_17DF6:
jmp     loc_17D5A
sub_17D41 endp




sub_17DF9 proc near
cmp     al, 'P'
jb      short loc_17E0A
and     al, 0DFh
call    DisplayChar
call    sub_17AEE

loc_17E05:
mov     al, 3
jmp     sub_17AF6

loc_17E0A:
call    DisplayHexTrack
cmp     al, bl
jz      short loc_17E05
mov     al, '-'
call    DisplayChar
mov     al, bl
call    DisplayHexTrack
retn
sub_17DF9 endp

mov     al, ds:byte_17918[si]
retn



sub_17E21 proc near
mov     byte ptr ds:word_17908, ah
mov     ds:byte_1790A, al
mov     di, 0

loc_17E2B:
mov     ah, 0
int     16h             ; KEYBOARD - READ CHAR FROM BUFFER, WAIT IF EMPTY
                        ; Return: AH = scan code, AL = character
cmp     ax, 0
jnz     short loc_17E37
jmp     short loc_17E7F
db 90h

loc_17E37:
cmp     al, 'a'
jb      short loc_17E41
cmp     al, 'z'
ja      short loc_17E41
and     al, 0DFh

loc_17E41:
cmp     ah, 'D'
jz      short loc_17E7F
cmp     ah, '<'
jz      short loc_17E89
cmp     al, 1Bh
jz      short loc_17E81
cmp     al, 'Q'
jz      short loc_17E7F
cmp     al, ' '
jz      short loc_17E89
cmp     al, 0Dh
jz      short loc_17E8B
cmp     al, 8
jz      short loc_17EA3
cmp     ah, 'u'
jz      short loc_17EA3
cmp     di, ds:word_17908
jnb     short loc_17E7A
cmp     ah, 'w'
jnz     short loc_17E75
mov     ah, 8
mov     bh, 0
int     10h             ; - VIDEO - READ ATTRIBUTES/CHARACTER AT CURSOR POSITION
                        ; BH = display page
                        ; Return: AL = character
                        ; AH = attribute of character (alpha modes)

loc_17E75:
call    sub_17EB9
jnb     short loc_17EAE

loc_17E7A:
call    Beep
jmp     short loc_17E2B

loc_17E7F:
mov     al, 'D'

loc_17E81:
mov     ah, al
mov     ds:byte_17917, ah
stc
retn

loc_17E89:
mov     al, '<'

loc_17E8B:
mov     ah, al
push    ax
mov     ds:byte_17918[di], 0Dh
inc     di
cmp     di, 1
jz      short loc_17E9C
call    sub_17C5F

loc_17E9C:
pop     ax
mov     ds:byte_17917, ah
clc
retn

loc_17EA3:
cmp     di, 0
jz      short loc_17E7A
dec     di
mov     al, 8
jmp     short loc_17EB3
align 2

loc_17EAE:
mov     ds:byte_17918[di], al
inc     di

loc_17EB3:
call    DisplayChar
jmp     loc_17E2B
sub_17E21 endp




sub_17EB9 proc near
cmp     ds:byte_1790A, 0
jnz     short loc_17ED4

loc_17EC0:
cmp     al, '0'
jb      short loc_17ED2
cmp     al, '9'
jbe     short loc_17ED0
cmp     al, 'A'
jb      short loc_17ED2
cmp     al, 'F'
ja      short loc_17ED2

loc_17ED0:
clc
retn

loc_17ED2:
stc
retn

loc_17ED4:
cmp     ds:byte_1790A, 1
jnz     short loc_17EE5
cmp     al, 'A'
jb      short loc_17ED2
cmp     al, 'Z'
ja      short loc_17ED2
jmp     short loc_17ED0

loc_17EE5:
cmp     ds:byte_1790A, 2
jnz     short loc_17EF6
cmp     al, '1'
jz      short loc_17ED0
cmp     al, '2'
jnz     short loc_17ED2
jmp     short loc_17ED0

loc_17EF6:
cmp     ds:byte_1790A, 3
jnz     short loc_17F07
cmp     al, 'Y'
jz      short loc_17ED0
cmp     al, 'N'
jnz     short loc_17ED2
jmp     short loc_17ED0

loc_17F07:
cmp     ds:byte_1790A, 6
jnz     short loc_17F21
cmp     di, 0
jnz     short loc_17F1B
cmp     al, 'Y'
jz      short loc_17ED0
cmp     al, 'N'
jz      short loc_17ED0

loc_17F1B:
cmp     al, '-'
jz      short loc_17ED0
jmp     short loc_17EC0

loc_17F21:
jmp     short loc_17ED0
sub_17EB9 endp

db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
SyncBytePtr dw 0        ; points to start of sync bytes in track buffer
word_17F31 dw 0
db    0
OldInt08Seg dw 0
OldInt08Off dw 0
word_17F38 dw 0
word_17F3A dw 0
word_17F3C dw 0
CRC_END dw 0            ; End of data for CRC generation.
word_17F40 dw 0
DMATrkBufOfs dw 0
DMATrkBufSeg dw 0
byte_17F46 db 0
byte_17F47 db 2 dup(0)
word_17F49 dw 0
byte_17F4B db 0
word_17F4C dw 0
byte_17F4E db 0
byte_17F4F db 0
word_17F50 dw 0
byte_17F52 db 0
word_17F53 dw 0
word_17F55 dw 0
word_17F57 dw 0
word_17F59 dw 0
byte_17F5B db 0
DMAReadCount dw 0
db    0
db    0
db 0FFh
unk_17F61 db  3Fh ; ?
db 0CFh ; -
db 0F3h ; =
db 0FCh ; n
db 0AAh ; ¬
db 0A8h ; ¿
db  2Ah ; *
db 0AAh ; ¬
db  82h ; é
db 0AAh ; ¬
db 0A0h ; á
db 0AAh ; ¬
db 0AAh ; ¬
db  0Ah
db 0AAh ; ¬
db  82h ; é
db 0AAh ; ¬
db 0A8h ; ¿
db  2Ah ; *
db 0FEh ; ¦
unk_17F75 db  7Fh ; 
db  9Fh ; ƒ
db 0E7h ; t
db 0F9h ; ·
byte_17F79 db 52h
db  52h ; R
db  52h ; R
db  52h ; R
db  54h ; T
db  55h ; U
db  52h ; R
db  52h ; R
db  48h ; H
db  49h ; I
db  4Ah ; J
db  4Ah ; J
db  4Ah ; J
db  4Ah ; J
db  4Ah ; J
db  4Ah ; J
db  12h
db  11h
db  12h
db  12h
db  14h
db  15h
db  14h
db  12h
db  12h
db  11h
db  12h
db  12h
db  12h
db  12h
db  12h
db  12h
db  22h ; "
db  22h ; "
db  22h ; "
db  22h ; "
db  24h ; $
db  25h ; %
db  24h ; $
db  22h ; "
db  28h ; (
db  29h ; )
db  2Ah ; *
db  2Ah ; *
db  28h ; (
db  29h ; )
db  2Ah ; *
db  2Ah ; *
db  22h ; "
db  22h ; "
db  22h ; "
db  22h ; "
db  24h ; $
db  25h ; %
db  24h ; $
db  22h ; "
db  28h ; (
db  29h ; )
db  2Ah ; *
db  2Ah ; *
db  28h ; (
db  29h ; )
db  2Ah ; *
db  2Ah ; *
db  4Ah ; J
db  45h ; E
db  4Ah ; J
db  4Ah ; J
db  44h ; D
db  45h ; E
db  44h ; D
db  4Ah ; J
db  48h ; H
db  49h ; I
db  4Ah ; J
db  4Ah ; J
db  48h ; H
db  49h ; I
db  4Ah ; J
db  4Ah ; J
db  52h ; R
db  51h ; Q
db  52h ; R
db  52h ; R
db  54h ; T
db  55h ; U
db  54h ; T
db  52h ; R
db  52h ; R
db  51h ; Q
db  52h ; R
db  52h ; R
db  58h ; X
db  55h ; U
db  52h ; R
db  52h ; R
db  4Ah ; J
db  45h ; E
db  4Ah ; J
db  4Ah ; J
db  44h ; D
db  45h ; E
db  44h ; D
db  4Ah ; J
db  48h ; H
db  49h ; I
db  4Ah ; J
db  4Ah ; J
db  48h ; H
db  49h ; I
db  4Ah ; J
db  4Ah ; J
db  4Ah ; J
db  45h ; E
db  4Ah ; J
db  4Ah ; J
db  44h ; D
db  45h ; E
db  44h ; D
db  4Ah ; J
db  48h ; H
db  49h ; I
db  4Ah ; J
db  4Ah ; J
db  48h ; H
db  49h ; I
db  4Ah ; J
db  4Ah ; J
db  88h ; ê
db  89h ; ë
db  8Ah ; è
db  8Ah ; è
db  94h ; ö
db  95h ; ò
db  94h ; ö
db  92h ; Æ
db  88h ; ê
db  89h ; ë
db  8Ah ; è
db  8Ah ; è
db  88h ; ê
db  89h ; ë
db  8Ah ; è
db  8Ah ; è
db  92h ; Æ
db  91h ; æ
db  92h ; Æ
db  92h ; Æ
db  94h ; ö
db  95h ; ò
db  94h ; ö
db  92h ; Æ
db  92h ; Æ
db  91h ; æ
db  92h ; Æ
db  92h ; Æ
db  94h ; ö
db  95h ; ò
db  92h ; Æ
db  92h ; Æ
db 0A2h ; ó
db 0A5h ; Ñ
db 0A2h ; ó
db 0A2h ; ó
db 0A4h ; ñ
db 0A5h ; Ñ
db 0A4h ; ñ
db 0A2h ; ó
db 0A8h ; ¿
db 0A9h ; ¬
db 0AAh ; ¬
db 0AAh ; ¬
db 0A8h ; ¿
db 0A9h ; ¬
db 0AAh ; ¬
db 0AAh ; ¬
db 0A2h ; ó
db 0A5h ; Ñ
db 0A2h ; ó
db 0A2h ; ó
db 0A4h ; ñ
db 0A5h ; Ñ
db 0A4h ; ñ
db 0A2h ; ó
db 0A8h ; ¿
db 0A9h ; ¬
db 0AAh ; ¬
db 0AAh ; ¬
db 0A8h ; ¿
db 0A9h ; ¬
db 0AAh ; ¬
db 0AAh ; ¬
db  88h ; ê
db  89h ; ë
db  8Ah ; è
db  8Ah ; è
db  94h ; ö
db  95h ; ò
db  94h ; ö
db  92h ; Æ
db  88h ; ê
db  89h ; ë
db  8Ah ; è
db  8Ah ; è
db  88h ; ê
db  89h ; ë
db  8Ah ; è
db  8Ah ; è
db  92h ; Æ
db  91h ; æ
db  92h ; Æ
db  92h ; Æ
db  94h ; ö
db  95h ; ò
db  94h ; ö
db  92h ; Æ
db  92h ; Æ
db  91h ; æ
db  92h ; Æ
db  92h ; Æ
db  94h ; ö
db  95h ; ò
db  92h ; Æ
db  92h ; Æ
db  52h ; R
db  52h ; R
db  52h ; R
db  52h ; R
db  52h ; R
db  52h ; R
db  52h ; R
db  52h ; R
db  52h ; R
db  52h ; R
db  52h ; R
db  52h ; R
db  52h ; R
db  52h ; R
db  52h ; R
db  52h ; R
db  52h ; R
db  52h ; R
db  52h ; R
db  52h ; R
db  52h ; R
db  52h ; R
db  52h ; R
db  52h ; R
db  52h ; R
db  52h ; R
db  52h ; R
db  52h ; R
db  52h ; R
db  52h ; R
db  52h ; R
db  52h ; R
byte_18079 db 3Ch
db  39h ; 9
db  32h ; 2
db  33h ; 3
db  24h ; $
db  25h ; %
db  26h ; &
db  27h ; '
db  3Ch ; <
db  49h ; I
db  4Ah ; J
db  4Bh ; K
db  4Ch ; L
db  4Dh ; M
db  4Eh ; N
db  4Fh ; O
db  3Ch ; <
db  39h ; 9
db  32h ; 2
db  33h ; 3
db  34h ; 4
db  35h ; 5
db  36h ; 6
db  37h ; 7
db  3Ch ; <
db  39h ; 9
db  3Ah ; :
db  3Bh ; ;
db  3Ch ; <
db  3Dh ; =
db  3Eh ; ;
db  3Fh ; ?
db  2Ch ; ,
db  29h ; )
db  2Ah ; *
db  2Bh ; +
db  24h ; $
db  25h ; %
db  26h ; &
db  27h ; '
db  2Ch ; ,
db  29h ; )
db  2Ah ; *
db  2Bh ; +
db  2Ch ; ,
db  2Dh ; -
db  2Eh ; .
db  2Fh ; /
db  3Ch ; <
db  35h ; 5
db  32h ; 2
db  33h ; 3
db  34h ; 4
db  35h ; 5
db  36h ; 6
db  37h ; 7
db  3Ch ; <
db  39h ; 9
db  3Ah ; :
db  3Bh ; ;
db  3Ch ; <
db  3Dh ; =
db  3Eh ; ;
db  3Fh ; ?
db  4Ch ; L
db  49h ; I
db  5Ah ; Z
db  5Bh ; [
db  54h ; T
db  55h ; U
db  56h ; V
db  57h ; W
db  4Ch ; L
db  49h ; I
db  4Ah ; J
db  4Bh ; K
db  4Ch ; L
db  4Dh ; M
db  4Eh ; N
db  4Fh ; O
db  5Ch ; \
db  59h ; Y
db  52h ; R
db  53h ; S
db  54h ; T
db  55h ; U
db  56h ; V
db  57h ; W
db  52h ; R
db  59h ; Y
db  5Ah ; Z
db  5Bh ; [
db  5Ch ; \
db  5Dh ; ]
db  5Eh ; ^
db  5Fh ; _
db  64h ; d
db  65h ; e
db  6Ah ; j
db  6Bh ; k
db  64h ; d
db  65h ; e
db  66h ; f
db  67h ; g
db  69h ; i
db  69h ; i
db  6Ah ; j
db  6Bh ; k
db  6Ch ; l
db  6Dh ; m
db  6Eh ; n
db  6Fh ; o
db  72h ; r
db  73h ; s
db  72h ; r
db  73h ; s
db  74h ; t
db  75h ; u
db  76h ; v
db  77h ; w
db  79h ; y
db  79h ; y
db  7Ah ; z
db  7Bh ; {
db  7Ch ; |
db  7Dh ; }
db  7Eh ; ~
db  7Fh ; 
db  9Ch ; £
db  95h ; ò
db  92h ; Æ
db  93h ; ô
db  94h ; ö
db  95h ; ò
db  96h ; û
db  97h ; ù
db  9Ah ; Ü
db 0A9h ; ¬
db 0AAh ; ¬
db 0ABh ; ½
db 0ACh ; ¼
db 0ADh ; ¡
db 0AEh ; «
db 0AFh ; »
db  92h ; Æ
db  95h ; ò
db  92h ; Æ
db  93h ; ô
db  94h ; ö
db  95h ; ò
db  96h ; û
db  97h ; ù
db  99h ; Ö
db  99h ; Ö
db  9Ah ; Ü
db  9Bh ; ¢
db  9Ch ; £
db  9Dh ; ¥
db  9Eh ; P
db  9Fh ; ƒ
db 0A4h ; ñ
db 0A5h ; Ñ
db 0AAh ; ¬
db 0ABh ; ½
db 0A4h ; ñ
db 0A5h ; Ñ
db 0A6h ; ª
db 0A7h ; º
db 0A9h ; ¬
db 0A9h ; ¬
db 0AAh ; ¬
db 0ABh ; ½
db 0ACh ; ¼
db 0ADh ; ¡
db 0AEh ; «
db 0AFh ; »
db 0B2h ; ¦
db 0B5h ; ¦
db 0B2h ; ¦
db 0B3h ; ¦
db 0B4h ; ¦
db 0B5h ; ¦
db 0B6h ; ¦
db 0B7h ; +
db 0B9h ; ¦
db 0B9h ; ¦
db 0BAh ; ¦
db 0BBh ; +
db 0BCh ; +
db 0BDh ; +
db 0BEh ; +
db 0BFh ; +
db 0CCh ; ¦
db 0CDh ; -
db 0CAh ; -
db 0CBh ; -
db 0D4h ; +
db 0D5h ; +
db 0D6h ; +
db 0D6h ; +
db 0C9h ; +
db 0C9h ; +
db 0CAh ; -
db 0CBh ; -
db 0CCh ; ¦
db 0CDh ; -
db 0CEh ; +
db 0CFh ; -
db 0D2h ; -
db 0D5h ; +
db 0D2h ; -
db 0D3h ; +
db 0D4h ; +
db 0D5h ; +
db 0D6h ; +
db 0D7h ; +
db 0D9h ; +
db 0D9h ; +
db 0DAh ; +
db 0DBh ; ¦
db 0DCh ; _
db 0DDh ; ¦
db 0DEh ; ¦
db 0DFh ; ¯
db 0E4h ; S
db 0E5h ; s
db 0EAh ; O
db 0EBh ; d
db 0E4h ; S
db 0E5h ; s
db 0E6h ; µ
db 0E7h ; t
db 0E9h ; T
db 0E9h ; T
db 0EAh ; O
db 0EBh ; d
db 0ECh ; 8
db 0EDh ; f
db 0EEh ; e
db 0EFh ; n
db 0F2h ; =
db 0F3h ; =
db 0F2h ; =
db 0F3h ; =
db 0F4h ; (
db 0F5h ; )
db 0F6h ; ÷
db 0F7h ; ˜
db 0F9h ; ·
db 0F9h ; ·
db 0FAh ; ·
db 0FBh ; v
db 0FCh ; n
db 0FDh ; ²
db 0FEh ; ¦
db 0FFh
MFM_CLK_TBL db 0FFh, 0FEh, 0FCh, 0FCh, 0F9h, 0F8h, 0F8h
db 0F8h, 0F3h, 0F2h, 0F0h, 0F0h, 0F1h, 0F0h
db 0F0h, 0F0h, 0E7h, 0E6h, 0E4h, 0E4h, 0E1h
db 0E0h, 0E0h, 0E0h, 0E3h, 0E2h, 0E0h, 0E0h
db 0E1h, 0E0h, 0E0h, 0E0h, 0CFh, 0CEh, 0CCh
db 0CCh, 0C9h, 0C8h, 0C8h, 0C8h, 0C3h, 0C2h
db 0C0h, 0C0h, 0C1h, 0C0h, 0C0h, 0C0h, 0C7h
db 0C6h, 0C4h, 0C4h, 0C1h, 0C0h, 0C0h, 0C0h
db 0C3h, 0C2h, 0C0h, 0C0h, 0C1h, 0C0h, 0C0h
db 0C0h, 9Fh, 9Eh, 9Ch, 9Ch, 99h, 98h, 98h
db 98h, 93h, 92h, 90h, 90h, 91h, 90h, 90h
db 90h, 87h, 86h, 84h, 84h, 81h, 80h, 80h
db 80h, 83h, 82h, 80h, 80h, 81h, 80h, 80h
db 80h, 8Fh, 8Eh, 8Ch, 8Ch, 89h, 88h, 88h
db 88h, 83h, 82h, 80h, 80h, 81h, 80h, 80h
db 80h, 87h, 86h, 84h, 84h, 81h, 80h, 80h
db 80h, 83h, 82h, 80h, 80h, 81h, 80h, 80h
db 80h, 3Fh, 3Eh, 3Ch, 3Ch, 39h, 38h, 38h
db 38h, 33h, 32h, 30h, 30h, 31h, 30h, 30h
db 30h, 27h, 26h, 24h, 24h, 21h, 20h, 20h
db 20h, 23h, 22h, 20h, 20h, 21h, 20h, 20h
db 20h, 0Fh, 0Eh, 0Ch, 0Ch, 9, 8, 8, 8, 3
db 2, 0, 0, 1, 0, 0, 0, 7, 6, 4, 4, 1, 0
db 0, 0, 3, 2, 0, 0, 1, 0, 0, 0, 1Fh, 1Eh
db 1Ch, 1Ch, 19h, 18h, 18h, 18h, 13h, 12h
db 10h, 10h, 11h, 10h, 10h, 10h, 7, 6, 4
db 4, 1, 0, 0, 0, 3, 2, 0, 0, 1, 0, 0, 0
db 0Fh, 0Eh, 0Ch, 0Ch, 9, 8, 8, 8, 3, 2
db 0, 0, 1, 0, 0, 0, 7, 6, 4, 4, 1, 0, 0
db 0, 3, 2, 0, 0, 1, 0, 0, 0

loc_18279:
push    si
push    es
push    bx
push    dx
push    ds
mov     si, ds:word_13CF2
mov     dx, ds:word_13CF4
add     dx, 40h ; '@'
mov     al, ds:DiskType
and     al, 7Fh
cmp     al, 7
jb      short loc_182E2
push    es
pop     ds
assume ds:seg001
mov     bh, 0
mov     ah, 1

loc_18298:
mov     bl, [si]
mov     al, cs:byte_17F79[bx]
test    ah, 1
jz      short loc_182A6
and     al, 7Fh

loc_182A6:
test    al, 0E0h
jnz     short loc_182B4
test    ah, 1
jnz     short loc_182CF
or      al, 80h
jmp     short loc_182CF
align 2

loc_182B4:
test    ah, 7
jnz     short loc_182C4
test    al, 80h
jnz     short loc_182CF
or      byte ptr [si-1], 1
jmp     short loc_182CF
align 2

loc_182C4:
test    al, 0C0h
jnz     short loc_182CF
test    ah, 3
jnz     short loc_182CF
or      al, 80h

loc_182CF:
cmp     al, bl
jz      short $+2
mov     [si], al
mov     ah, al
inc     si
cmp     si, dx
jb      short loc_18298

loc_182DC:
pop     ds
assume ds:nothing
pop     dx
pop     bx
pop     es
assume es:nothing
pop     si
retn

loc_182E2:
push    es
pop     ds
assume ds:nothing
mov     bh, 0

loc_182E6:
mov     bl, [si]
mov     al, cs:byte_18079[bx]
mov     [si], al
test    al, 3
jnz     short loc_182FF
test    byte ptr [si+1], 80h
jnz     short loc_182FF
or      byte ptr [si], 1
jmp     short loc_1830C
db 90h

loc_182FF:
test    al, 0C0h
jnz     short loc_1830C
test    byte ptr [si-1], 1
jnz     short loc_1830C
or      byte ptr [si], 80h

loc_1830C:
inc     si
cmp     si, dx
jb      short loc_182E6
jmp     short loc_182DC



sub_18313 proc near
mov     dl, ds:CurrentDrive
mov     dh, 0
mov     ch, ds:CurrentCylinder
call    sub_1700D
retn
sub_18313 endp




sub_18321 proc near
mov     ds:CurrentDrive, al
cmp     ds:byte_15FA7, 0FFh
jnz     short loc_1832E
call    sub_18380

loc_1832E:
mov     cl, ds:CurrentDrive
mov     al, 1
shl     al, cl
push    ds
call    MaxtMotorTimer
mov     ds:dsk_motor_stat, al ; Motor running status & disk write
                        ;  bit 7=1 disk write in progress
                        ;  bits 6&5 = drive selected 0 to 3
                        ;     3       2       1       0
                        ;  drive-3 drive-2 drive-1 drive-0
                        ;  --------- 1=motor on-----------
call    sub_16F42
pop     ds
assume ds:nothing
call    sub_1685B
mov     dl, ds:CurrentDrive
call    sub_16E78
push    ax
call    sub_16FEC
mov     bl, ds:CurrentDrive
mov     bh, 0
cmp     ds:byte_1009B[bx], 0
jnz     short loc_18365
push    bx
call    sub_183E6
pop     bx
mov     ds:byte_1009B[bx], al

loc_18365:
cmp     ds:byte_17F5B, 0
jnz     short loc_18374
call    sub_18429
mov     ds:byte_17F5B, 0FFh

loc_18374:
pop     ax
mov     bl, ds:CurrentDrive
mov     bh, 0
mov     ah, ds:byte_1009B[bx]
retn
sub_18321 endp




sub_18380 proc near
mov     dl, ds:CurrentDrive
mov     ah, 8
int     13h             ; DISK - DISK - GET CURRENT DRIVE PARAMETERS (XT,AT,XT286,CONV,PS)
                        ; DL = drive number
                        ; Return: CF set on error, AH = status code, BL = drive type
                        ; DL = number of consecutive drives
                        ; DH = maximum value for head number, ES:DI -; drive parameter
jb      short loc_183B4
cmp     bl, 0           ; 0 = error/no drive?
jz      short loc_183B4
cmp     bl, 2           ; 2 = 1.2M drive
jnz     short loc_18397
mov     cx, 2709h       ; 27h tracks, 9 sectors/track

loc_18397:              ; 4 = 1.44M drive
cmp     bl, 4
jnz     short loc_1839E
mov     cl, 9           ; 9 sectors/track

loc_1839E:
mov     ah, 18h
mov     dl, ds:CurrentDrive
int     13h             ; DISK - SET MEDIA TYPE FOR FORMAT (AT model 3x9,XT2,XT286,PS)
                        ; DL = drive number, CH = lower 8 bits of number of tracks, CL = sectors per track
jnb     short locret_183B3
cmp     ah, 6           ; 6 = diskette change line active.
jnz     short loc_183B4
mov     ah, 18h
int     13h             ; DISK - SET MEDIA TYPE FOR FORMAT (AT model 3x9,XT2,XT286,PS)
                        ; DL = drive number, CH = lower 8 bits of number of tracks, CL = sectors per track
jb      short loc_183B4

locret_183B3:
retn

loc_183B4:
mov     dl, ds:CurrentDrive
cmp     dl, 1
ja      short loc_183DF
mov     bl, dl
mov     bh, 0
push    ds
call    MaxtMotorTimer
mov     al, ds:dsk0_media_st[bx] ; Media state for diskette drive 0
                        ;     7      6      5      4
                        ;  data xfer rate  two   media
                        ;   00=500K bit/s  step  known
                        ;   01=300K bit/s
                        ;   10=250K bit/s
                        ;   11=1M bit/sec
                        ;     3      2      1      0
                        ;  unused  -----state of drive-----
                        ;          bits floppy  drive state
                        ;          000=  360K in 360K, ?
                        ;          001=  360K in 1.2M, ?
                        ;          010=  1.2M in 1.2M, ?
                        ;          011=  360K in 360K, ok
                        ;          100=  360K in 1.2M, ok
                        ;          101=  1.2M in 1.2M, ok
                        ;          111=  720K in 720K, ok
                        ;            or 1.44M in 1.44M
                        ;         (state not used for 2.88)
pop     ds
and     al, 7
cmp     al, 5
ja      short loc_183DF
cmp     al, 3
jb      short loc_183D6
sub     al, 3

loc_183D6:
cmp     al, 0
jnz     short loc_183DF
mov     al, 1
jmp     short loc_183E1
db 90h

loc_183DF:
mov     al, 2

loc_183E1:
mov     ah, 17h
int     13h             ; DISK - DISK - SET TYPE (AT,XT2,XT286,CONV,PS
                        ; AL = disk type AL = 02h - regular disk in high-capacity drive
retn
sub_18380 endp




sub_183E6 proc near
mov     ds:CurrentCylinder, 28h ; '('
call    sub_18313
mov     ds:CurrentCylinder, 1
call    sub_18313
call    sub_18405
mov     al, 27h ; '''
jnz     short loc_183FF
inc     al

loc_183FF:
push    ax
call    sub_16FEC
pop     ax
retn
sub_183E6 endp




sub_18405 proc near
mov     dl, ds:CurrentDrive
push    ds
mov     cx, seg bdata
mov     ds, cx
assume ds:bdata
mov     cx, 0Ah

loc_18412:
mov     dh, 0
call    GetDriveStatus
mov     al, dsk_status_1 ; Status bytes-disk controller chip
                        ;  Note: 7 info bytes returned from
                        ;  controller are saved here. Refer
                        ;  to the NEC uPD 765 chip manual
                        ;  for the specific info, depending
                        ;  on the previous command issued.
xor     al, dl
and     al, 1
jz      short loc_18422
loop    loc_18412

loc_18422:              ; Status bytes-disk controller chip
mov     al, dsk_status_1 ;  Note: 7 info bytes returned from
                        ;  controller are saved here. Refer
                        ;  to the NEC uPD 765 chip manual
                        ;  for the specific info, depending
                        ;  on the previous command issued.
pop     ds
assume ds:nothing
and     al, 10h
retn
sub_18405 endp




sub_18429 proc near
mov     al, 5
out     0Ah, al         ; DMA controller, 8237A-5.
                        ; Disable (mask) channel 1
mov     al, 6
out     0Ah, al         ; DMA controller, 8237A-5.
                        ; Disable (mask) channel 2
retn
sub_18429 endp


GetInt08:
push    es
cli
mov     ax, 3508h
int     21h             ; DOS - 2+ - GET INTERRUPT VECTOR
                        ; AL = interrupt number
                        ; Return: ES:BX = value of interrupt vector
mov     ds:OldInt08Seg, es
mov     ds:OldInt08Off, bx
push    cs
pop     ds
assume ds:seg001
mov     dx, offset Int08Entry
mov     ax, 2508h
int     21h             ; DOS - SET INTERRUPT VECTOR
                        ; AL = interrupt number
                        ; DS:DX = new vector to be used for specified interrupt
pop     es
retn

RestoreInt08:
cli
push    ds
push    es
mov     dx, OldInt08Off
mov     ds, OldInt08Seg
assume ds:nothing
mov     ax, 2508h
int     21h             ; DOS - SET INTERRUPT VECTOR
                        ; AL = interrupt number
                        ; DS:DX = new vector to be used for specified interrupt
pop     es
pop     ds
retn

Int08Entry:             ; IRQ0 - Sytem Timer.
sti
push    ax
inc     cs:DataRate
mov     al, 20h ; ' '
out     20h, al         ; Interrupt controller, 8259A.
pop     ax
iret



sub_1846D proc near
mov     al, es:[si]
shr     al, cl
and     al, 1
dec     cl
js      short loc_1847A
clc
retn

loc_1847A:
mov     cl, 7
inc     si
cmp     ds:EndOfCurrTrk, si
retn
sub_1846D endp




sub_18482 proc near
mov     ah, es:[si]
shr     ah, cl
and     ah, 1
dec     cl
jns     short loc_18497
mov     cl, 7
inc     si
cmp     ds:EndOfCurrTrk, si
jb      short locret_184B0

loc_18497:
mov     al, es:[si]
shr     al, cl
and     al, 1
dec     cl
jns     short loc_184AB
mov     cl, 7
inc     si
cmp     ds:EndOfCurrTrk, si
jb      short locret_184B0

loc_184AB:
shl     ah, 1
or      al, ah
clc

locret_184B0:
retn
sub_18482 endp



; Decodes a bytes worth of raw MFM from ES:SI:CL
; (CL selects the starting bit, counting backwards from 7.)
; Data returned in DL, clock bits in DH.

MFMDecode proc near
push    cx
mov     ah, es:[si]
inc     si
cmp     ds:EndOfCurrTrk, si
jb      short loc_184ED
mov     al, es:[si]
mov     ch, 7
sub     ch, cl
mov     cl, ch
shl     ax, cl
mov     dh, ah
mov     ah, es:[si]
inc     si
cmp     ds:EndOfCurrTrk, si
jb      short loc_184ED
mov     al, es:[si]
shl     ax, cl
mov     al, ah
mov     ah, dh
mov     ch, 8

loc_184DE:
shl     ax, 1
rcl     dh, 1
shl     ax, 1
rcl     dl, 1
dec     ch
jnz     short loc_184DE
pop     cx
clc
retn

loc_184ED:
pop     cx
stc
retn
MFMDecode endp



; Decrements a bit address formed by ES:SI:CL.
; (CL counts backwards from 7.)

DecrBitAddr proc near
inc     cl
cmp     cl, 8
jz      short loc_184F8
retn

loc_184F8:
mov     cl, 0
dec     si
retn
DecrBitAddr endp




FindAddrMark proc near
cld
push    bx

loc_184FE:
lods    byte ptr es:[si]
cmp     al, 55h ; 'U'
jz      short loc_18511
cmp     al, 0AAh ; '¬'
jz      short loc_18511
cmp     si, ds:EndOfCurrTrk
jbe     short loc_184FE

loc_1850E:
pop     bx
stc
retn

loc_18511:
dec     si
mov     ds:SyncBytePtr, si

loc_18516:
inc     si
cmp     si, ds:EndOfCurrTrk
ja      short loc_1850E
cmp     al, es:[si]
jz      short loc_18516
mov     ax, si
sub     ax, ds:SyncBytePtr
cmp     ax, 3
jb      short loc_184FE
dec     si
mov     cl, 7
jmp     short loc_18538
db 90h

loc_18533:
call    sub_1846D
jb      short loc_1850E

loc_18538:
call    sub_18482
jb      short loc_1850E
cmp     al, 1
jz      short loc_18533
cmp     al, 2
jnz     short loc_18538

loc_18545:
call    sub_18482
jb      short loc_1850E
cmp     al, 2
jz      short loc_18545
call    DecrBitAddr
call    DecrBitAddr
call    MFMDecode
jb      short loc_1850E
cmp     dx, 0AA1h       ; Address mark, DH=clock DL=data.
jz      short loc_18565
cmp     dx, 14C2h       ; Index mark, DH=clock DL=data.
jnz     short loc_184FE

loc_18565:
clc
pop     bx
retn
FindAddrMark endp

stc
pop     bx
retn



sub_1856B proc near
call    FindAddrMark
jb      short locret_18590
call    MFMDecode
call    MFMDecode
call    MFMDecode
and     dl, 0Fh
cmp     dl, 3
jnz     short sub_1856B
call    MFMDecode
call    MFMDecode
and     dl, 0Fh
cmp     dl, 1
jnz     short sub_1856B
clc

locret_18590:
retn
sub_1856B endp




sub_18591 proc near
jmp     short sub_18594
sub_18591 endp

align 2



sub_18594 proc near
push    bx

loc_18595:
mov     al, es:[si]
cmp     al, 55h ; 'U'
jz      short loc_185AA
cmp     al, 0AAh ; '¬'
jz      short loc_185AA
inc     si
cmp     si, ds:EndOfCurrTrk
jbe     short loc_18595

loc_185A7:
pop     bx
stc
retn

loc_185AA:
mov     ds:SyncBytePtr, si

loc_185AE:
inc     si
cmp     si, ds:EndOfCurrTrk
ja      short loc_185A7
cmp     al, es:[si]
jz      short loc_185AE
mov     cx, si
sub     cx, ds:SyncBytePtr
cmp     cx, 4
jb      short loc_18595
dec     si
mov     cl, 7
cmp     al, 55h ; 'U'
jnz     short loc_185CE
mov     cl, 6

loc_185CE:
call    sub_18482
jb      short loc_185A7
cmp     al, 3
jz      short loc_185DD
cmp     al, 2
jz      short loc_185CE
jmp     short loc_18595

loc_185DD:
call    DecrBitAddr
call    DecrBitAddr
call    MFMDecode
jb      short loc_185A7
cmp     dh, 0C7h ; '¦'
jnz     short loc_185FE
cmp     dl, 0FEh ; '¦'
jz      short loc_18600
cmp     dl, 0F8h ; '°'
jb      short loc_185FE
cmp     dl, 0FBh ; 'v'
ja      short loc_185FE
jz      short loc_18600

loc_185FE:
jmp     short loc_18595

loc_18600:
clc
pop     bx
retn
sub_18594 endp




sub_18603 proc near
call    sub_18634
jb      short locret_18633
mov     ds:SyncBytePtr, di
mov     ds:word_17F31, bp

loc_18610:
call    sub_18634
jb      short loc_18625
cmp     bp, ds:word_17F31
jbe     short loc_18610
mov     ds:SyncBytePtr, di
mov     ds:word_17F31, bp
jmp     short loc_18610

loc_18625:
mov     si, ds:SyncBytePtr
mov     bp, ds:word_17F31
sub     bp, 9
add     si, bp
clc

locret_18633:
retn
sub_18603 endp




sub_18634 proc near
mov     di, si
mov     al, es:[si]
cmp     al, 0FFh
jz      short loc_18650
cmp     al, 0FEh ; '¦'
jz      short loc_1864A
inc     si
cmp     si, ds:EndOfCurrTrk
jbe     short sub_18634
stc
retn

loc_1864A:
mov     bx, offset unk_17F75
jmp     short loc_18653
align 2

loc_18650:
mov     bx, offset unk_17F61

loc_18653:
mov     bp, 1
mov     cx, 4

loc_18659:
inc     si
mov     al, es:[si]
cmp     al, [bx]
jnz     short loc_1866D
inc     bx
inc     bp
loop    loc_18659
mov     cx, 5
sub     bx, 5
jmp     short loc_18659

loc_1866D:
cmp     bp, 8
jb      short sub_18634
sub     si, 4
mov     cl, 7
jmp     short loc_1867D
align 2

loc_1867A:
call    sub_1846D

loc_1867D:
call    sub_18482
cmp     al, 3
jnz     short loc_1867A

loc_18684:
call    sub_18482
cmp     al, 2
jz      short loc_1867A
cmp     al, 0
jnz     short loc_18684

loc_1868F:
call    sub_18482
call    sub_18482
call    sub_18482
call    sub_18482
call    sub_18482
cmp     al, 0
jz      short loc_1868F
call    DecrBitAddr
call    DecrBitAddr
dec     si
dec     si
mov     bp, si
sub     bp, di
clc
retn
sub_18634 endp

stc
retn


; Gets the clock bits for normal (non address mark)
; bytes to be MFM encoded. Input byte to be encoded in AL,
; previous bit cell in AH. Returns clock bits in AH, AL
; unchanged.

GET_MFM_CLK proc near
push    bx
shr     ah, 1           ; check incoming phase from previous bit cell.
mov     ah, 0
mov     bx, ax
mov     ah, ds:MFM_CLK_TBL[bx]
jnb     short loc_186C2 ; adjust for incoming phase
and     ah, 7Fh

loc_186C2:
pop     bx
retn
GET_MFM_CLK endp



; MFM encodes byte in AL with normal clock.
; Output to ES:SI.

Encode_MFM_Normal proc near
mov     ah, es:[si-1]   ; Get previous bit cell
call    GET_MFM_CLK
Encode_MFM_Normal endp



; MFM encodes byte in AL with clock in AH.
; Output to ES:SI.

Encode_MFM_AM proc near
push    cx
push    dx
mov     cx, 8

loc_186D0:
shl     ah, 1
rcl     dx, 1
shl     al, 1
rcl     dx, 1
loop    loc_186D0
xchg    dh, dl
mov     es:[si], dx
inc     si
inc     si
pop     dx
pop     cx
retn
Encode_MFM_AM endp



; Generates a CRC from data at ES:SI with length AX.
; Return in BX.

CRC proc near
push    dx
push    cx
add     ax, si
mov     ds:CRC_END, ax
mov     bx, 0FFFFh

loc_186EE:
mov     cx, 8
mov     dh, es:[si]

loc_186F4:
mov     ah, dh
shl     dh, 1
xor     ah, bh
shl     ah, 1
mov     ax, 0
jnb     short loc_18704
mov     ax, 1021h

loc_18704:
shl     bx, 1
xor     bx, ax
loop    loc_186F4
inc     si
inc     si
cmp     si, ds:CRC_END
jb      short loc_186EE
pop     cx
pop     dx
retn
CRC endp




sub_18715 proc near
push    ds
push    es
push    di
push    si
call    ClearTimer0
call    sub_168BD
mov     ds:byte_17F46, 2
mov     ds:byte_10066, 0

loc_18729:
mov     bx, ds:TrackBufSeg
mov     ax, ds:TrackBufOfs
mov     bl, ah
shr     bh, 1
shr     bh, 1
shr     bh, 1
shr     bh, 1
mov     al, 46h ; 'F'
call    SetupDMA
mov     dx, ds:TC_Port_Base
cmp     ds:CopyXIDXFlag, 'Y'
jnz     short loc_18752
cmp     ds:byte_10066, 0
jmp     short loc_18755
align 2

loc_18752:
jmp     loc_18881

loc_18755:
mov     di, ds:trackSkewDly2
mov     bx, ds:word_13D18

loc_1875D:
in      al, dx
and     al, 80h
jnz     short loc_1875D
jmp     short loc_18765
db 90h

loc_18765:
in      al, dx
and     al, 80h
jz      short loc_18765
push    bx

loc_1876B:              ; Latch timer 0 count.
mov     al, 6           ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
mov     bl, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
mov     bh, al
mov     al, 6           ; Latch timer 0 count.
                        ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
mov     ah, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
xchg    ah, al
sub     ax, bx
cmp     ah, 0
jz      short loc_1876B
neg     bx
mov     ds:word_13D0E, bx
pop     bx
xor     ax, ax
cmp     di, 0
jnz     short loc_187AF
jmp     loc_18832

loc_187AF:
push    bx

loc_187B0:              ; Latch timer 0 count.
mov     al, 6           ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
mov     bl, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
mov     bh, al
mov     al, 6           ; Latch timer 0 count.
                        ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
mov     ah, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
xchg    ah, al
sub     ax, bx
cmp     ah, 0
jz      short loc_187B0
neg     bx
mov     ax, bx
sub     ax, ds:word_13D0E
pop     bx

loc_187EC:
mov     cx, ax
push    bx

loc_187EF:              ; Latch timer 0 count.
mov     al, 6           ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
mov     bl, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
mov     bh, al
mov     al, 6           ; Latch timer 0 count.
                        ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
mov     ah, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
xchg    ah, al
sub     ax, bx
cmp     ah, 0
jz      short loc_187EF
neg     bx
mov     ax, bx
sub     ax, ds:word_13D0E
pop     bx
cmp     ax, cx
ja      short loc_187EC
dec     di
jnz     short loc_187EC

loc_18832:
cmp     bx, 0Ah
jb      short loc_1888E

loc_18837:
mov     cx, ax
push    bx

loc_1883A:              ; Latch timer 0 count.
mov     al, 6           ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
mov     bl, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
mov     bh, al
mov     al, 6           ; Latch timer 0 count.
                        ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
mov     ah, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
xchg    ah, al
sub     ax, bx
cmp     ah, 0
jz      short loc_1883A
neg     bx
mov     ax, bx
sub     ax, ds:word_13D0E
pop     bx
cmp     ax, cx
jb      short loc_1888E
cmp     ax, bx
jb      short loc_18837
jmp     short loc_1888E
db 90h

loc_18881:
in      al, dx
and     al, 80h
jnz     short loc_18881
jmp     short loc_18889
db 90h

loc_18889:
in      al, dx
and     al, 80h
jz      short loc_18889

loc_1888E:
mov     al, ds:TC_Port3Byte
or      al, 3
mov     ds:TC_Port3Byte, al
add     dx, 3
out     dx, al          ; turn on GO and RDENBL
sub     dx, 3
mov     al, ds:DMA_Channel
out     0Ah, al         ; DMA controller, 8237A-5.
                        ; single mask bit register
                        ; 0-1: select channel (00=0; 01=1; 10=2; 11=3)
                        ; 2: 1=set mask for channel; 0=clear mask (enable)
call    sub_1AC25
mov     ds:CurrTrackBufOfs, si
mov     dx, si
add     dx, ds:ReadLengthBytes
mov     ds:EndOfCurrTrk, dx
call    sub_189E1
mov     ds:word_17F49, si
mov     ds:byte_17F4B, cl
mov     ax, ds:CurrTrackBufOfs
sub     si, ax
add     si, ds:TrackBufOfs

loc_188C7:
call    ReadDMACurrAddr
cmp     bx, si
jb      short loc_188C7
mov     si, ds:TrackBufOfs
mov     dx, si
add     dx, ds:ReadLengthBytes
add     dx, 180h
mov     ds:EndOfCurrTrk, dx
mov     ds:byte_17F52, 0

loc_188E5:
mov     es, ds:TrackBufSeg
call    sub_189E1
jb      short loc_18931
mov     ds:word_17F4C, si
mov     ds:byte_17F4E, cl
call    sub_1AC25
mov     si, ds:word_17F49
mov     ch, ds:byte_17F4B
mov     cl, ds:byte_17F4E
mov     dx, word ptr ds:byte_17F47
sub     dx, 38h ; '8'
mov     di, ds:word_17F4C
mov     ds, ds:TrackBufSeg
cmp     cl, ch
jnb     short loc_1891D
dec     si
sub     ch, cl
mov     cl, 8

loc_1891D:
sub     cl, ch
mov     bx, 4000h
cld
cmp     cl, 4
jb      short loc_1893A
mov     ch, 8
sub     ch, cl
mov     cl, ch
jmp     short loc_18956
db 90h

loc_18931:
mov     cs:byte_10066, 'C'
jmp     short loc_189A6
align 2

loc_1893A:
lods    word ptr es:[si]
dec     si
xchg    ah, al
shl     ax, cl
cmp     ah, [di]
jnz     short loc_18950
mov     bx, 4000h
inc     di
cmp     si, dx
jb      short loc_1893A
jmp     short loc_189A0
align 2

loc_18950:
dec     si
dec     bx
jnz     short loc_1893A
jz      short loc_18970

loc_18956:
lods    word ptr es:[si]
dec     si
xchg    ah, al
shr     ax, cl
cmp     al, [di]
jnz     short loc_1896C
mov     bx, 4000h
inc     di
cmp     si, dx
jb      short loc_18956
jmp     short loc_189A0
align 2

loc_1896C:
dec     si
dec     bx
jnz     short loc_18956

loc_18970:
cmp     cl, 0
jz      short loc_1897A
cmp     cl, 4
jnz     short loc_1897B

loc_1897A:
nop

loc_1897B:
push    cs
pop     ds
assume ds:seg001
add     si, 2
sub     si, word_17F49
cmp     si, 20h ; ' '
ja      short loc_1899E
inc     byte_17F52
cmp     byte_17F52, 4
ja      short loc_1899E
mov     si, word_17F4C
add     si, 8
jmp     loc_188E5

loc_1899E:
jmp     short loc_18931

loc_189A0:
mov     cs:byte_10066, 0

loc_189A6:
call    sub_173FD
push    cs
pop     ds
call    MaskDMA
mov     al, TC_Port3Byte
and     al, 0F8h
call    WriteTC_Port3
cmp     KeepTrkLngthFlag, 'Y'
jnz     short loc_189C0
jmp     short loc_189C0
align 2

loc_189C0:
cmp     byte_10066, 0
jz      short loc_189D0
dec     byte_17F46
jz      short loc_189D0
jmp     loc_18729

loc_189D0:
pop     si
pop     di
pop     es
pop     ds
assume ds:nothing
cmp     ds:byte_10066, 0
clc
jz      short loc_189DD
stc

loc_189DD:
mov     al, ds:byte_10066
retn
sub_18715 endp




sub_189E1 proc near
cmp     ds:DiskType, 7
jb      short loc_189EC
call    FindAddrMark
retn

loc_189EC:
cmp     ds:DiskType, 4
jnz     short loc_189F7
call    sub_18634
retn

loc_189F7:
call    sub_18594
retn
sub_189E1 endp




sub_189FB proc near
mov     bx, ds:TrackBufSeg
mov     ax, ds:TrackBufOfs
mov     bl, ah
jmp     short loc_18A13
sub_189FB endp

db 90h



sub_18A07 proc near
call    GetTrkDatOfs
mov     ax, word ptr ds:CurrTrackBufSeg
mov     al, byte ptr ds:(TrackOffsTbl+1)[bx]
mov     bx, ax

loc_18A13:
shr     bh, 1
shr     bh, 1
shr     bh, 1
shr     bh, 1
mov     al, 4Ah ; 'J'
mov     ds:DMATrkBufSeg, bx
mov     ds:DMATrkBufOfs, ax
mov     al, ds:byte_10068
mov     ds:byte_17F4F, al
mov     bx, 0

loc_18A2D:
cmp     ds:word_14435[bx], 0FFFEh
jz      short loc_18A39
add     bx, 4
jmp     short loc_18A2D

loc_18A39:
mov     ds:word_17F53, bx
call    SetDmaCount
mov     ds:word_17F55, ax
mov     ds:byte_13D04, 0
cmp     ds:KeepTrkLngthFlag, 'Y'
jnz     short loc_18A87
cmp     ds:CopyXIDXFlag, 'Y'
jnz     short loc_18A87
cmp     ds:word_1006A, 8
jnb     short loc_18A87
mov     ds:byte_13D04, 0FFh
mov     ax, ds:TrackLengthBits
add     ax, 5
shr     ax, 1
shr     ax, 1
shr     ax, 1
add     ax, 2000h
mov     ds:word_17F55, ax
add     ds:word_17F55, 3
call    GetTrkDatOfs
mov     bh, byte ptr ds:(TrackOffsTbl+1)[bx]
mov     bl, 0
add     ax, bx
mov     ds:word_17F50, ax

loc_18A87:
cli
call    ClearTimer0
call    MaskDMA
call    TrackReadOn
mov     dh, ds:CurrentSide
call    SelectHead
call    sub_16BAA

loc_18A9B:
mov     ds:word_17F40, 0
mov     ax, ds:word_17F55
mov     ds:DMACount, ax
mov     al, ds:byte_15F9C
call    WriteTC_Port4
mov     bx, ds:DMATrkBufSeg
mov     ax, ds:DMATrkBufOfs
call    SetupDMA
mov     di, ds:TrackSkewDly1
mov     bx, ds:word_10072
mov     cx, bx
or      cx, di
mov     dx, ds:TC_Port_Base
cmp     ds:CopyXIDXFlag, 'Y'
jz      short loc_18B42

loc_18ACE:
in      al, dx
and     al, 80h
jnz     short loc_18ACE
jmp     short loc_18AD6
align 2

loc_18AD6:
in      al, dx
and     al, 80h
jz      short loc_18AD6
mov     al, ds:TC_Port3Byte
or      al, 5
add     dx, 3
out     dx, al          ; turn on GO and WTENBL
sub     dx, 3
mov     ds:TC_Port3Byte, al
call    UnmaskDMA

loc_18AED:
call    ReadDMACurrAddr
mov     ax, bx
mov     bx, ds:word_17F40
cmp     ax, ds:word_14435[bx]
jb      short loc_18B11
shr     bx, 1
mov     al, byte ptr ds:unk_14535[bx]
add     dx, 4
out     dx, al
sub     dx, 4
add     ds:word_17F40, 2
mov     ds:TC_Port4Byte, al

loc_18B11:
in      al, dx
and     al, 80h
jnz     short loc_18AED

loc_18B16:
call    ReadDMACurrAddr
mov     ax, bx
mov     bx, ds:word_17F40
cmp     ax, ds:word_14435[bx]
jb      short loc_18B3A
shr     bx, 1
mov     al, byte ptr ds:unk_14535[bx]
add     dx, 4
out     dx, al
sub     dx, 4
add     ds:word_17F40, 2
mov     ds:TC_Port4Byte, al

loc_18B3A:
in      al, dx
and     al, 80h
jz      short loc_18B16
jmp     loc_18F3B

loc_18B42:
in      al, dx
and     al, 80h
jnz     short loc_18B42
jmp     short loc_18B4A
align 2

loc_18B4A:
in      al, dx
and     al, 80h
jz      short loc_18B4A
cmp     cx, 0
jnz     short loc_18B57
jmp     loc_18C6B

loc_18B57:
push    bx

loc_18B58:              ; Latch timer 0 count.
mov     al, 6           ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
mov     bl, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
mov     bh, al
mov     al, 6           ; Latch timer 0 count.
                        ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
mov     ah, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
xchg    ah, al
sub     ax, bx
cmp     ah, 0
jz      short loc_18B58
neg     bx
mov     ds:word_13D0E, bx
pop     bx
xor     ax, ax
cmp     di, 0
jnz     short loc_18B9C
jmp     loc_18C1F

loc_18B9C:
push    bx

loc_18B9D:              ; Latch timer 0 count.
mov     al, 6           ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
mov     bl, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
mov     bh, al
mov     al, 6           ; Latch timer 0 count.
                        ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
mov     ah, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
xchg    ah, al
sub     ax, bx
cmp     ah, 0
jz      short loc_18B9D
neg     bx
mov     ax, bx
sub     ax, ds:word_13D0E
pop     bx

loc_18BD9:
mov     cx, ax
push    bx

loc_18BDC:              ; Latch timer 0 count.
mov     al, 6           ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
mov     bl, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
mov     bh, al
mov     al, 6           ; Latch timer 0 count.
                        ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
mov     ah, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
xchg    ah, al
sub     ax, bx
cmp     ah, 0
jz      short loc_18BDC
neg     bx
mov     ax, bx
sub     ax, ds:word_13D0E
pop     bx
cmp     ax, cx
ja      short loc_18BD9
dec     di
jnz     short loc_18BD9

loc_18C1F:
cmp     bx, 0Ah
jb      short loc_18C6B

loc_18C24:
mov     cx, ax
push    bx

loc_18C27:              ; Latch timer 0 count.
mov     al, 6           ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
mov     bl, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
mov     bh, al
mov     al, 6           ; Latch timer 0 count.
                        ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
mov     ah, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
xchg    ah, al
sub     ax, bx
cmp     ah, 0
jz      short loc_18C27
neg     bx
mov     ax, bx
sub     ax, ds:word_13D0E
pop     bx
cmp     ax, cx
jb      short loc_18C6B
cmp     ax, bx
jb      short loc_18C24

loc_18C6B:
mov     al, ds:TC_Port3Byte
or      al, 5
mov     ds:TC_Port3Byte, al
add     dx, 3
out     dx, al          ; turn on GO and WTENBL
sub     dx, 3
mov     al, ds:DMA_Channel
out     0Ah, al         ; Unmask DMA
cmp     ds:byte_13D04, 0
jnz     short loc_18C93
cmp     ds:byte_13D1C, 0
jz      short loc_18C90
call    sub_19028

loc_18C90:
jmp     short loc_18D0C
db 90h

loc_18C93:
call    ReadDMACurrAddr
cmp     bx, ds:word_17F50
jnb     short loc_18D05
mov     si, ds:word_17F40
cmp     bx, ds:word_14435[si]
jb      short loc_18C93
shr     si, 1
mov     al, byte ptr ds:unk_14535[si]
add     dx, 4
out     dx, al
sub     dx, 4
add     ds:word_17F40, 2
mov     ds:TC_Port4Byte, al
shl     si, 1
cmp     word ptr ds:unk_14437[si], 0FFFEh
jnz     short loc_18C93
mov     dx, ds:DMACurrAddrPort
mov     si, ds:TC_Port3
mov     cl, ds:TC_Port3Byte
and     cl, 0F9h
mov     di, ds:word_17F50

loc_18CD7:
in      al, dx
jmp     short $+2
jmp     short $+2
mov     bl, al
in      al, dx
mov     bh, al
cmp     bl, 0F8h ; '°'
jb      short loc_18CF6
in      al, dx
jmp     short $+2
jmp     short $+2
mov     ah, al
in      al, dx
xchg    ah, al
cmp     ax, bx
jnb     short loc_18CF6
dec     bh

loc_18CF6:
cmp     bx, di
jb      short loc_18CD7
mov     dx, si
mov     al, cl
out     dx, al
mov     ds:TC_Port3Byte, al
jmp     loc_18F47

loc_18D05:
mov     dx, ds:TC_Port_Base
jmp     loc_18F3B

loc_18D0C:
cmp     ds:KeepTrkLngthFlag, 'Y'
jnz     short loc_18D37
call    ReadDMACurrAddr
mov     ax, bx
mov     bx, ds:word_17F40
cmp     ax, ds:word_14435[bx]
jb      short loc_18D37
shr     bx, 1
mov     al, byte ptr ds:unk_14535[bx]
add     dx, 4
out     dx, al
sub     dx, 4
add     ds:word_17F40, 2
mov     ds:TC_Port4Byte, al

loc_18D37:
in      al, dx
and     al, 80h
jnz     short loc_18D0C

loc_18D3C:
cmp     ds:KeepTrkLngthFlag, 'Y'
jnz     short loc_18D65
call    ReadDMACurrAddr
mov     si, ds:word_17F40
cmp     bx, ds:word_14435[si]
jb      short loc_18D65
shr     si, 1
mov     al, byte ptr ds:unk_14535[si]
add     dx, 4
out     dx, al
sub     dx, 4
add     ds:word_17F40, 2
mov     ds:TC_Port4Byte, al

loc_18D65:
in      al, dx
and     al, 80h
jz      short loc_18D3C
cmp     ds:byte_13D1C, 0
jz      short loc_18D7B
call    ReadDMACurrAddr
add     ds:word_17F50, bx
jmp     loc_18C93

loc_18D7B:
push    bx

loc_18D7C:              ; Latch timer 0 count.
mov     al, 6           ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
mov     bl, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
mov     bh, al
mov     al, 6           ; Latch timer 0 count.
                        ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
mov     ah, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
xchg    ah, al
sub     ax, bx
cmp     ah, 0
jz      short loc_18D7C
neg     bx
mov     ds:word_13D0E, bx
pop     bx
xor     ax, ax
mov     di, ds:TrackSkewDly1
cmp     di, 0
jnz     short loc_18DC4
jmp     loc_18E70

loc_18DC4:
push    bx

loc_18DC5:              ; Latch timer 0 count.
mov     al, 6           ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
mov     bl, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
mov     bh, al
mov     al, 6           ; Latch timer 0 count.
                        ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
mov     ah, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
xchg    ah, al
sub     ax, bx
cmp     ah, 0
jz      short loc_18DC5
neg     bx
mov     ax, bx
sub     ax, ds:word_13D0E
pop     bx

loc_18E01:
mov     cx, ax
cmp     ds:KeepTrkLngthFlag, 'Y'
jnz     short loc_18E2C
call    ReadDMACurrAddr
mov     si, ds:word_17F40
cmp     bx, ds:word_14435[si]
jb      short loc_18E2C
shr     si, 1
mov     al, byte ptr ds:unk_14535[si]
add     dx, 4
out     dx, al
sub     dx, 4
add     ds:word_17F40, 2
mov     ds:TC_Port4Byte, al

loc_18E2C:
push    bx

loc_18E2D:              ; Latch timer 0 count.
mov     al, 6           ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
mov     bl, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
mov     bh, al
mov     al, 6           ; Latch timer 0 count.
                        ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
mov     ah, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
xchg    ah, al
sub     ax, bx
cmp     ah, 0
jz      short loc_18E2D
neg     bx
mov     ax, bx
sub     ax, ds:word_13D0E
pop     bx
cmp     ax, cx
ja      short loc_18E01
dec     di
jnz     short loc_18E01

loc_18E70:
mov     cx, ds:word_10072
cmp     cx, 0Ah
jnb     short loc_18E7C
jmp     loc_18F3B

loc_18E7C:
mov     bp, ax
cmp     ds:KeepTrkLngthFlag, 'Y'
jnz     short loc_18EAD
call    ReadDMACurrAddr
mov     si, ds:word_17F40
cmp     bx, ds:word_14435[si]
jb      short loc_18EAD
shr     si, 1
mov     al, byte ptr ds:unk_14535[si]
add     dx, 4
out     dx, al
sub     dx, 4
add     ds:word_17F40, 2
shl     si, 1
cmp     word ptr ds:unk_14437[si], 0FFFEh
jz      short loc_18EF6

loc_18EAD:
push    bx

loc_18EAE:              ; Latch timer 0 count.
mov     al, 6           ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
mov     bl, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
mov     bh, al
mov     al, 6           ; Latch timer 0 count.
                        ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
mov     ah, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
xchg    ah, al
sub     ax, bx
cmp     ah, 0
jz      short loc_18EAE
neg     bx
mov     ax, bx
sub     ax, ds:word_13D0E
pop     bx
cmp     ax, bp
jb      short loc_18F3B
cmp     ax, cx
jb      short loc_18E7C
jnb     short loc_18F3B

loc_18EF4:
mov     bp, ax

loc_18EF6:
push    bx

loc_18EF7:              ; Latch timer 0 count.
mov     al, 6           ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
mov     bl, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
mov     bh, al
mov     al, 6           ; Latch timer 0 count.
                        ; Controller ignores lower nibble this command,
                        ; unknown why 06h used rather than 0h.
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
jmp     short $+2
jmp     short $+2
mov     ah, al
in      al, 40h         ; Timer 8253-5 (AT: 8254.2).
xchg    ah, al
sub     ax, bx
cmp     ah, 0
jz      short loc_18EF7
neg     bx
mov     ax, bx
sub     ax, ds:word_13D0E
pop     bx
cmp     ax, bp
jb      short loc_18F3B
cmp     ax, cx
jb      short loc_18EF4

loc_18F3B:
mov     al, ds:TC_Port3Byte
and     al, 0F9h ; '·'
add     dx, 3
out     dx, al          ; turn off WTENBL and RDENBL
mov     ds:TC_Port3Byte, al

loc_18F47:
call    ReadDMAWrdCnt
push    bx
call    ReadDMACurrAddr
mov     word ptr ds:byte_17F47, bx
pop     bx
cli
call    ClearTimer0
in      al, 21h         ; Interrupt controller, 8259A.
jmp     short $+2
jmp     short $+2
or      al, 1
and     al, 0FDh
out     21h, al         ; Interrupt controller, 8259A.
mov     ax, ds:DMACount
sub     ax, bx
sub     ax, 1
mov     ds:ReadLengthBytes, ax
shl     ax, 1
shl     ax, 1
shl     ax, 1
mov     ds:WrittenLength, ax
call    sub_173FD
call    MaskDMA
mov     al, ds:TC_Port3Byte
and     al, 0F8h
call    WriteTC_Port3
cmp     ds:KeepTrkLngthFlag, 'Y'
jnz     short loc_18FEB
call    sub_19089
mov     ds:WrittenLength, ax
mov     ds:word_13D02, dx
mov     dx, ax
sub     dx, ds:TrackLengthBits
jns     short loc_18FA0
neg     dx

loc_18FA0:
cmp     dx, ds:word_1006A
jbe     short loc_18FEB
push    dx
call    DispWritLngth
pop     dx
cmp     dx, 6
ja      short loc_18FB9
dec     ds:byte_10068
jz      short loc_18FB9
jmp     loc_18A9B

loc_18FB9:
mov     al, ds:byte_17F4F
mov     ds:byte_10068, al
dec     ds:byte_10069
jz      short loc_18FE3
cmp     ds:word_1006A, 8
jnb     short loc_18FDD
mov     al, 1
call    sub_138EE
cmp     ds:byte_10069, 1Eh
jnb     short loc_18FDD
mov     al, 2
call    sub_138EE

loc_18FDD:
call    sub_19160
jmp     loc_18A9B

loc_18FE3:
mov     ds:byte_10066, 'K'
jmp     short loc_19012
db 90h

loc_18FEB:
cmp     ds:VerifyWrtFlag, 'N'
clc
jz      short loc_19013
call    GetTrkDatOfs
mov     bl, byte ptr ds:TrackTypeTable[bx]
test    bl, 0C0h
clc
jnz     short loc_19013
call    sub_18715
jnb     short loc_19013
cmp     al, 0
jnz     short loc_19012
dec     ds:byte_10069
jz      short loc_19012
jmp     loc_18A9B

loc_19012:
stc

loc_19013:
pushf
call    MaskDMA
sti
mov     dh, 80h ; 'Ç'
call    SelectHead
call    TrackReadOff
call    sub_16BBA
mov     al, ds:byte_10066
popf
retn
sub_18A07 endp




sub_19028 proc near
push    dx
cmp     ds:KeepTrkLngthFlag, 'Y'
jz      short loc_19060
mov     al, 0
sub     al, ds:TC_Port4Byte
inc     al
mov     ah, 0
mov     bx, 4C6h
mul     bx
mov     bx, 6
div     bx

loc_19044:
mov     bx, ax
mov     dx, ds:TrackSkewDly1
mov     ax, ds:word_10072

loc_1904D:
mov     dh, dl
mov     dl, ah
mov     ah, al
mov     al, 0
shl     ax, 1
rcl     dx, 1
div     bx
mov     ds:word_17F50, ax
pop     dx
retn

loc_19060:
mov     bh, 0
mov     bl, ds:CurrentDrive
shl     bl, 1
shl     bl, 1
mov     dx, ds:word_15F6E[bx]
mov     ax, ds:word_15F6C[bx]
mov     dh, dl
mov     dl, ah
mov     ah, al
mov     al, 0
shl     ax, 1
rcl     dx, 1
push    dx
call    RdTrkLngthTbl
mov     bx, dx
pop     dx
div     bx
jmp     short loc_19044
sub_19028 endp




sub_19089 proc near
mov     ax, ds:EndOfCurrTrk
push    ax
mov     ds:EndOfCurrTrk, 69FEh
cmp     ds:word_1006A, 8
jb      short loc_1909D
jmp     loc_19152

loc_1909D:
call    SetDmaCount
shl     ds:DMACount, 1
call    sub_168BD
mov     bx, ds:TrackBufSeg
mov     ax, ds:TrackBufOfs
mov     bl, ah
shr     bh, 1
shr     bh, 1
shr     bh, 1
shr     bh, 1
mov     al, 46h ; 'F'
call    SetupDMA
mov     dx, ds:TC_Port_Base

loc_190C1:
in      al, dx
and     al, 80h
jnz     short loc_190C1
jmp     short loc_190C9
db 90h

loc_190C9:
in      al, dx
and     al, 80h
jz      short loc_190C9
mov     al, ds:TC_Port3Byte
or      al, 3
add     dx, 3
out     dx, al          ; turn on RDENBL and GO
sub     dx, 3
mov     ds:TC_Port3Byte, al
call    UnmaskDMA

loc_190E0:
in      al, dx
and     al, 80h
jnz     short loc_190E0
jmp     short loc_190E8
align 2

loc_190E8:
in      al, dx
and     al, 80h
jz      short loc_190E8
call    ReadDMAWrdCnt
mov     ax, ds:DMACount
sub     ax, bx
mov     ds:ReadLengthBytes, ax
sub     ds:ReadLengthBytes, 0
call    WaitForDMA
call    MaskDMA
mov     al, ds:TC_Port3Byte
and     al, 0F8h
call    WriteTC_Port3
mov     es, ds:TrackBufSeg
mov     si, ds:TrackBufOfs
call    FindAddrMark
jb      short loc_19152
mov     ch, 0
push    si
push    cx
add     si, ds:ReadLengthBytes
sub     si, 14h
call    FindAddrMark
mov     ch, 0
pop     bx
pop     ax
jb      short loc_19152
sub     si, ax
mov     ax, si
mov     dx, si
sub     dx, ds:ReadLengthBytes
cmp     dx, 3
jbe     short loc_19140
cmp     dx, 0FFFDh
jb      short loc_19152

loc_19140:
mov     dx, 8
mul     dx
add     ax, bx
sub     ax, cx
sbb     dx, 0
pop     bx
mov     ds:EndOfCurrTrk, bx
retn

loc_19152:
mov     ax, ds:ReadLengthBytes
mov     dx, 8
mul     dx
pop     bx
mov     ds:EndOfCurrTrk, bx
retn
sub_19089 endp




sub_19160 proc near
mov     dx, ds:TrackLengthBits
sub     dx, ds:WrittenLength
mov     ax, dx
test    ah, 80h
jz      short loc_19171
neg     ax

loc_19171:
mov     cl, 3
cmp     ax, 10h
ja      short loc_1917A
mov     cl, 2

loc_1917A:
shl     dx, cl
mov     ax, dx
mov     dx, 0
mov     cx, ds:word_17F53
cmp     cx, 0
jnz     short loc_1918D
mov     cx, 4

loc_1918D:
shr     cx, 1
shr     cx, 1
cwd
idiv    cx
mov     ds:word_17F57, 1
test    dh, 80h
jz      short loc_191A7
neg     dx
mov     ds:word_17F57, 0FFFFh

loc_191A7:
mov     ds:word_17F59, dx
mov     di, ax
mov     bx, 2

loc_191B0:
sub     ds:word_14435[bx], di
cmp     ds:word_17F59, 0
jz      short loc_191C6
mov     ax, ds:word_17F57
sub     ds:word_14435[bx], ax
dec     ds:word_17F59

loc_191C6:
mov     cx, ds:word_14435[bx]
cmp     cx, word ptr ds:unk_14437[bx]
jbe     short loc_191F9
add     ds:word_14435[bx], di
mov     ax, word ptr ds:unk_14437[bx]
sub     ax, ds:word_14435[bx]
add     ax, word ptr ds:unk_14433[bx]
mov     ds:word_14435[bx], ax
shr     bx, 1
mov     cl, byte ptr ds:unk_14534[bx]
mov     byte ptr ds:unk_14535[bx], cl
dec     cl
mov     byte ptr ds:unk_14534[bx], cl
shl     bx, 1
jmp     short loc_19227
db 90h

loc_191F9:
cmp     cx, word ptr ds:unk_14433[bx]
jnb     short loc_19227
add     ds:word_14435[bx], di
mov     ax, ds:word_14435[bx]
sub     ax, word ptr ds:unk_14433[bx]
mov     cx, word ptr ds:unk_14437[bx]
sub     cx, ax
mov     ds:word_14435[bx], cx
shr     bx, 1
mov     ch, byte ptr ds:unk_14535[bx]
mov     byte ptr ds:unk_14534[bx], ch
inc     ch
mov     byte ptr ds:unk_14535[bx], ch
shl     bx, 1

loc_19227:
add     bx, 4
cmp     bx, ds:word_17F53
jnb     short locret_19233
jmp     loc_191B0

locret_19233:
retn
sub_19160 endp




sub_19234 proc near
mov     bx, ds:TrackBufSeg
mov     ax, ds:TrackBufOfs
mov     bl, ah
jmp     short loc_19249
sub_19234 endp

align 2



ReadTrack proc near
mov     bx, ds:TrackBufSeg
mov     ax, ds:TrackBufOfs
mov     bl, ah

loc_19249:
shr     bh, 1
shr     bh, 1
shr     bh, 1
shr     bh, 1
mov     ds:DMATrkBufSeg, bx
mov     ds:DMATrkBufOfs, ax
call    SetDmaCount
shl     ax, 1
mov     ds:DMACount, ax
call    TrackReadOn
cli
call    ClearTimer0
call    SetReadspeed
mov     dh, ds:CurrentSide
call    SelectHead
mov     al, ds:TC_Port3Byte
or      al, 2
mov     dx, ds:TC_Port_Base
add     dx, 3
out     dx, al          ; turn on RDENBL (bit 2)
mov     ds:TC_Port3Byte, al
mov     bx, ds:DMATrkBufSeg
mov     ax, ds:DMATrkBufOfs
mov     al, 46h ; 'F'   ; DMA mode: Write to memory, count up, single.
call    SetupDMA
mov     dx, ds:TC_Port_Base

loc_19291:
in      al, dx
and     al, 80h
jnz     short loc_19291 ; wait for index to go high
jmp     short loc_19299
db 90h

loc_19299:
in      al, dx
and     al, 80h
jz      short loc_19299 ; wait for index to go low
mov     al, ds:TC_Port3Byte
or      al, 3
add     dx, 3
out     dx, al          ; turn on GO and RDENBL
sub     dx, 3
mov     ds:TC_Port3Byte, al
call    UnmaskDMA

loc_192B0:
in      al, dx
and     al, 80h
jnz     short loc_192B0
call    ReadDMAWrdCnt
mov     ds:DMAReadCount, bx

loc_192BC:
in      al, dx
and     al, 80h
jz      short loc_192BC
call    ReadDMAWrdCnt
mov     ax, ds:DMAReadCount
sub     ax, bx
cmp     ax, 100h
jnb     short loc_192F5
mov     ds:ReadLengthBytes, 3100h
mov     ds:TrackLengthBits, 8800h
push    di
push    es
mov     es, ds:TrackBufSeg
mov     di, ds:TrackBufOfs
mov     cx, 3500h
mov     ax, 0
cld
rep stosw
pop     es
pop     di
call    sub_173FD
jmp     short loc_19309
db 90h

loc_192F5:
mov     ax, ds:DMACount
sub     ax, bx
mov     ds:ReadLengthBytes, ax
shl     ax, 1
shl     ax, 1
shl     ax, 1
mov     ds:TrackLengthBits, ax
call    WaitForDMA

loc_19309:
call    MaskDMA
mov     al, ds:TC_Port3Byte
and     al, 0F8h ; '°'  ; GO and RDENBL off.
call    WriteTC_Port3
sti
mov     dh, 80h ; 'Ç'
call    SelectHead
call    TrackReadOff
retn
ReadTrack endp

cmp     ds:CurrentCylinder, ' '
jb      short loc_19350
cmp     ds:KeepTrkLngthFlag, 'Y'
jz      short loc_19350
cmp     ds:CpyWkBitsFlag, 'Y'
jnz     short loc_19350
mov     ds:byte_10097, 1
push    bx
call    GetTrkDatOfs
test    byte ptr ds:TrackTypeTable[bx], 40h
pop     bx
jnz     short loc_19356
mov     ds:byte_10097, 0FFh
cmp     ds:byte_10086, 1
jz      short loc_19356

loc_19350:
mov     ds:byte_10097, 0
retn

loc_19356:
push    bx
push    cx
push    dx
push    es
push    si
push    di
mov     es, ds:TrackBufSeg
mov     si, ds:TrackBufOfs
push    si
push    es
mov     cx, 1A80h

loc_19369:
mov     word ptr es:[si], 0AAAAh
inc     si
inc     si
loop    loc_19369
mov     al, ds:CopyXIDXFlag
push    ax
mov     ds:CopyXIDXFlag, 'N'
call    sub_189FB
mov     ax, ds:ReadLengthBytes
mov     ds:word_17F3C, ax
call    sub_19234
pop     ax
mov     ds:CopyXIDXFlag, al
pop     es
pop     si
mov     bx, si
add     si, 0Ch
mov     ax, es:[si]
mov     cx, ds:word_17F3C
sub     cx, 12h
shr     cx, 1

loc_1939E:
inc     si
inc     si
cmp     ax, es:[si]
jnz     short loc_193AF
loop    loc_1939E

loc_193A7:
mov     ds:byte_10097, 0
jmp     loc_19493

loc_193AF:
mov     di, si
mov     si, bx
add     si, ds:word_17F3C
sub     si, 12h
mov     ax, es:[si]

loc_193BD:
dec     si
dec     si
cmp     si, di
jb      short loc_193A7
cmp     ax, es:[si]
jz      short loc_193BD
mov     ax, si
sub     ax, di
add     ax, 1
mov     ds:word_17F38, ax
mov     si, di
sub     si, bx
mov     ds:word_17F3A, si
call    sub_1AC25
mov     bx, si
cmp     ds:byte_10097, 1
jnz     short loc_193FC
call    RdTrkLngthTbl
mov     cx, dx
shr     cx, 1
mov     ax, 0

loc_193F0:
inc     si
inc     si
cmp     es:[si], ax
jz      short loc_19440
loop    loc_193F0
jmp     loc_19493

loc_193FC:
call    RdTrkLngthTbl
add     dx, si
mov     ds:EndOfCurrTrk, dx
add     si, 30h ; '0'
mov     cl, 7
call    FindAddrMark
jb      short loc_19426
cmp     dx, 0AA1h
jz      short loc_1941A
call    FindAddrMark
jb      short loc_19426

loc_1941A:
push    si
add     si, 8
call    FindAddrMark
mov     ax, si
mov     cx, si
pop     si

loc_19426:
jb      short loc_19493
sub     cx, si
cmp     cx, 80h ; 'Ç'
jb      short loc_19432
mov     si, ax

loc_19432:
sub     si, 1Ah
mov     ax, 64h ; 'd'
add     ax, ds:word_17F38
shr     ax, 1
sub     si, ax

loc_19440:
sub     si, bx
jns     short loc_19447
mov     si, 0

loc_19447:
mov     ax, ds:word_17F3A
sub     ax, si
jns     short loc_19452
add     ax, ds:word_17F3C

loc_19452:
sub     ax, 8
jns     short loc_1945A
mov     ax, 2

loc_1945A:
cmp     ds:byte_10056, 20h ; ' '
jz      short loc_1947D
push    ax
mov     al, ds:byte_10056
mov     ah, 0
shr     ax, 1
shr     ax, 1
shr     ax, 1
and     ax, 1Fh
mov     cx, 24h ; '$'
sub     cx, ax
pop     ax
mul     cx
mov     cx, 20h ; ' '
div     cx

loc_1947D:
mov     ds:word_10072, ax
call    GetTrkDatOfs
or      ds:TrackSkewTbl[bx], ax
cmp     ds:word_17F38, 32h ; '2'
ja      short loc_19493
or      byte ptr ds:TrackTypeTable[bx], 40h

loc_19493:
pop     di
pop     si
pop     es
pop     dx
pop     cx
pop     bx
retn
byte_1949A db 33h
byte_1949B db 37h
byte_1949C db 3Dh
byte_1949D db 30h
unk_1949E db    0
db    3
db  0Eh
db  0Ch
db  0Ah
db  0Ch
db  0Ah
db    7
db    8
db    9
db  0Ah
db  0Bh
db  0Ch
db  17h
db  0Fh
db  0Fh
byte_194AE db 0
db    7
db  0Fh
db    7
db    7
db    7
db    7
db    7
db    7
db    7
db    7
db    7
db    7
db  70h ; p
db  0Fh
db  0Fh
db 0CDh ; -
db  20h



DisplayString proc near
push    ax
push    dx
cbw
shl     ax, 1
xchg    ax, bx
mov     dx, word ptr ds:StringOffsets.field_0[bx]
xchg    ax, bx
call    DecodeString
pop     dx
pop     ax
retn
DisplayString endp

byte_194D1 db 2Eh
db  2Eh ; .
byte_194D3 db 56h
db  4Bh ; K
StringOffsets MsgOffs <offset aInsufficientmem, \
         offset aVerifyWrite?, \
         offset aTcmRequiresAMini, \
         offset aStartingTrack, \
         offset aEndingTrack, \
         offset aTrackIncrement, \
         offset aKeepTrackLength, \
         offset acopyWeakBits?, \
         offset acopyAcrossIndex, \
         offset aline, \
         offset aInsertDiskette, \
         offset aSourceDrive, \
         offset aTargetDrive, \
         offset aNumberOfSides, \
         offset aTitle_Copyright, \
         offset aPressQToQuit, \
         offset aTrackNumbers, \
         offset aLength, \
         offset a15Spaces, \
         offset aTargetIsWP, \
         offset aMessagesBox, \
         offset aInsertSourceDisk, \
         offset aInsertTargetDisk, \
         offset aSpacesClrMsgWndw, \
         offset aCheckSourceDisk, \
         offset aDiskFullError, \
         offset aCheckTargetDisk, \
         offset aPleaseUseTCM, \
         offset aEnterSourceDrive, \
         offset aEnterTargetDrive, \
         offset aEnterFirstTrack, \
         offset aEnterLastTrack, \
         offset aEnterTrkSpacing, \
         offset aEnterNumSides, \
         offset aInsertDisksBegin, \
         offset aImportantNotice, \
         offset aPlaceSourceDisk, \
         offset aPlaceTargetDisk, \
         offset aPressSpace, \
         offset aDupProcComplete, \
         offset aMakeAnotherCopy?, \
         offset aTargetDrvIsWP, \
         offset aDupProcStopped, \
         offset aUnableToFindDOB, \
         offset aInvalidCommand, \
         offset aPressEnter, \
         offset aChkSrcDsk, \
         offset aDOBDoesNotReq, \
         offset aChkTargetDsk, \
         offset aDupHopperOpn, \
         offset aDiskJam, \
         offset aInputBinEmpty, \
         offset aLoaderOffline, \
         offset aUnknownResponse, \
         offset aDMAChanlPort, \
         offset aDiskGood, \
         offset aDiskBad, \
         offset aGoodDisks, \
         offset aBadDisks, \
         offset aDiskWPPresskey, \
         offset aTrackNumbers2, \
         offset aDiskType, \
         offset aNullMsg0, \
         offset aNullMsg1, \
         offset aNullMsg2, \
         offset AnullMsg3, \
         offset aApple, offset aFm, \
         offset aNullMsg4, offset aMfm, \
         offset aAmiga, \
         offset aMarginalCtlr, \
         offset aMarginalTimer, \
         offset aEnterTracks, \
         offset aIncompatibleImg;
aInsufficientmem db 0Dh,0Ah,0Ah          ; field_0
db 7                    ; field_3
db '  Insufficient memory.',0Dh,0Ah,0; field_4
aVerifyWrite? db 0Dh,0Ah              ; field_0
db 7Ch                  ; field_2
db 34h                  ; field_3
db 'Verify write?     ' ; field_4
db 7Ch                  ; field_16
db 37h                  ; field_17
db ' ',0                ; field_18
aTcmRequiresAMini db 0Dh,0Ah              ; field_0
db 7                    ; field_2
db 'TCM requires a minimum of 1.25 mega'; field_3
db 'bytes',0Dh,0Ah      ; field_3
db 'of free RAM. Please run TC instead.'; field_3
db 0Dh,0Ah,0            ; field_3
aStartingTrack db 0Dh,0Ah,0Ah          ; field_0
db 7Ch                  ; field_3
db 34h                  ; field_4
db 'Starting track:   ' ; field_5
db 7Ch                  ; field_17
db 37h                  ; field_18
db 0                    ; field_19
aEndingTrack db 0Dh,0Ah              ; field_0
db 7Ch                  ; field_2
db 34h                  ; field_3
db 'Ending   track:   ' ; field_4
db 7Ch                  ; field_16
db 37h                  ; field_17
db 0                    ; field_18
aTrackIncrement db 0Dh,0Ah,0Ah          ; field_0
db 7Ch                  ; field_3
db 34h                  ; field_4
db 'Track increment:  ' ; field_5
db 7Ch                  ; field_17
db 37h                  ; field_18
db 0                    ; field_19
aKeepTrackLength db 0Dh,0Ah              ; field_0
db 7Ch                  ; field_2
db 34h                  ; field_3
db 'Keep track length? '; field_4
db 7Ch                  ; field_17
db 37h                  ; field_18
db 0                    ; field_19
acopyWeakBits? db 0Dh,0Ah              ; field_0
db 7Ch                  ; field_2
db 34h                  ; field_3
db 'Copy weak bits?    '; field_4
db 7Ch                  ; field_17
db 37h                  ; field_18
db 0                    ; field_19
acopyAcrossIndex db 0Dh,0Ah              ; field_0
db 7Ch                  ; field_2
db 34h                  ; field_3
db 'Copy across index? '; field_4
db 7Ch                  ; field_17
db 37h                  ; field_18
db 0                    ; field_19
aline db 7Ch                  ; field_0
db 36h                  ; field_1
db '-----------------------------------'; field_2
db '-----------------------------------'; field_2
db '----------',0       ; field_2
aInsertDiskette db '                              '; field_0
db 7Ch                  ; field_1E
db 36h                  ; field_1F
db '- INSERT DISKETTES -',0Dh,0Ah; field_20
db 0Ah                  ; field_20
db '                       '; field_20
db 7Ch                  ; field_4E
db 3Eh                  ; field_4F
db 'SPACE'              ; field_50
db 7Ch                  ; field_55
db 36h                  ; field_56
db ' to Begin          '; field_57
db 7Ch                  ; field_6A
db 3Eh                  ; field_6B
db 'Q'                  ; field_6C
db 7Ch                  ; field_6D
db 36h                  ; field_6E
db ' to Quit',0Dh,0Ah   ; field_6F
db '                       '; field_6F
db 7Ch                  ; field_90
db 3Eh                  ; field_91
db 'ESC'                ; field_92
db 7Ch                  ; field_95
db 36h                  ; field_96
db '   to Restart        '; field_97
db 7Ch                  ; field_AC
db 3Eh                  ; field_AD
db 'ENTER'              ; field_AE
db 7Ch                  ; field_B3
db 36h                  ; field_B4
db ' to Accept'         ; field_B5
db 7Ch                  ; field_BF
db 37h                  ; field_C0
db 0                    ; field_C1
aSourceDrive db 0Dh,0Dh,0Ah          ; field_0
db 7Ch                  ; field_3
db 34h                  ; field_4
db 'Source drive:      '; field_5
db 7Ch                  ; field_18
db 37h                  ; field_19
db 0                    ; field_1A
aTargetDrive db 0Dh,0Ah              ; field_0
db 7Ch                  ; field_2
db 34h                  ; field_3
db 'Target drive:      '; field_4
db 7Ch                  ; field_17
db 37h                  ; field_18
db 0                    ; field_19
aNumberOfSides db 0Dh,0Ah,0Ah          ; field_0
db 7Ch                  ; field_3
db 34h                  ; field_4
db 'Number of sides:   '; field_5
db 7Ch                  ; field_18
db 37h                  ; field_19
db 0                    ; field_1A
aTitle_Copyright db '                '   ; field_0
db 7Ch                  ; field_10
db 31h                  ; field_11
db '+----------------------------------'; field_12
db '--------------+',0Dh,0Ah; field_12
db '                '   ; field_12
db 7Ch                  ; field_56
db 31h                  ; field_57
db '¦                 ' ; field_58
db 7Ch                  ; field_6A
db 32h                  ; field_6B
db 'TRANSCOPY V5.4'     ; field_6C
db 7Ch                  ; field_7A
db 31h                  ; field_7B
db '                 ¦',0Dh,0Ah; field_7C
db '                '   ; field_7C
db 7Ch                  ; field_A0
db 31h                  ; field_A1
db '¦  '                ; field_A2
db 7Ch                  ; field_A5
db 32h                  ; field_A6
db '(C) 1985-1989 by CENTRAL POINT SOFT'; field_A7
db 'WARE, INC.'         ; field_A7
db 7Ch                  ; field_D4
db 31h                  ; field_D5
db ' ¦',0Dh,0Ah         ; field_D6
db '                '   ; field_D6
db 7Ch                  ; field_EA
db 31h                  ; field_EB
db '+----------------------------------'; field_EC
db '--------------+'    ; field_EC
db 7Ch                  ; field_11E
db 37h                  ; field_11F
db 0Dh,0Ah              ; field_120
db 0Ah,0                ; field_120
aPressQToQuit db 1Dh                  ; field_0
db 32h                  ; field_1
db 7Ch                  ; field_2
db 33h                  ; field_3
db 'Press '             ; field_4
db 7Ch                  ; field_A
db 3Fh                  ; field_B
db 'Q'                  ; field_C
db 7Ch                  ; field_D
db 33h                  ; field_E
db ' to quit or',0Dh,0Ah; field_F
db 1Dh                  ; field_1C
db 32h                  ; field_1D
db 7Ch                  ; field_1E
db 33h                  ; field_1F
db 'Press '             ; field_20
db 7Ch                  ; field_26
db 3Fh                  ; field_27
db 'ENTER'              ; field_28
db 7Ch                  ; field_2D
db 33h                  ; field_2E
db ' to continue...'    ; field_2F
db 7Ch                  ; field_3E
db 37h                  ; field_3F
db 0                    ; field_40
aTrackNumbers db 7Ch                  ; field_0
db 35h                  ; field_1
db '  HEX   000000000000000011111111111'; field_2
db '111112222222222',0Dh,0Ah; field_2
db 'TRACK   0123456789ABCDEF0123456789A'; field_2
db 'BCDEF0123456789',0Dh,0Ah; field_2
db '-----------------------------------'; field_2
db '---------------',0Dh,0Ah; field_2
db 'SIDE 0:',0Dh,0Ah    ; field_2
db 'SIDE 1:'            ; field_2
db 7Ch                  ; field_AE
db 37h                  ; field_AF
db 0                    ; field_B0
aLength Stru_MSG11 <7Ch, 35h, 'LENGTH: ', 7Ch, \
            37h, 0;
a15Spaces Stru_MSG12 <'               ';
aTargetIsWP db 7                    ; field_0
db 1Dh                  ; field_1
db 37h                  ; field_2
db 7Ch                  ; field_3
db 33h                  ; field_4
db 'Target diskette is',0Dh,0Ah; field_5
db 1Dh                  ; field_19
db 38h                  ; field_1A
db 7Ch                  ; field_1B
db 3Fh                  ; field_1C
db 'WRITE PROTECTED'    ; field_1D
db 7Ch                  ; field_2C
db 33h                  ; field_2D
db '.',0Dh,0Ah          ; field_2E
db 1Dh                  ; field_31
db 32h                  ; field_32
db 'Press '             ; field_33
db 7Ch                  ; field_39
db 3Fh                  ; field_3A
db 'Q'                  ; field_3B
db 7Ch                  ; field_3C
db 33h                  ; field_3D
db ' to quit or',0Dh,0Ah; field_3E
db 1Dh                  ; field_4B
db 32h                  ; field_4C
db 'Press '             ; field_4D
db 7Ch                  ; field_53
db 3Fh                  ; field_54
db 'ENTER'              ; field_55
db 7Ch                  ; field_5A
db 33h                  ; field_5B
db ' to continue...'    ; field_5C
db 7Ch                  ; field_6B
db 37h                  ; field_6C
db 0                    ; field_6D
aMessagesBox db 1Dh                  ; field_0
db 30h                  ; field_1
db 7Ch                  ; field_2
db 31h                  ; field_3
db '+-----------------------------+',0Dh,0Ah; field_4
db 1Dh                  ; field_25
db 30h                  ; field_26
db '¦'                  ; field_27
db 1Dh                  ; field_28
db 3Ch                  ; field_29
db 7Ch                  ; field_2A
db 33h                  ; field_2B
db 'MESSAGES'           ; field_2C
db 7Ch                  ; field_34
db 31h                  ; field_35
db 1Dh                  ; field_36
db 4Eh                  ; field_37
db '¦',0Dh,0Ah          ; field_38
db 1Dh                  ; field_3B
db 30h                  ; field_3C
db '¦-----------------------------¦',0Dh,0Ah; field_3D
db 1Dh                  ; field_5E
db 30h                  ; field_5F
db '¦'                  ; field_60
db 1Dh                  ; field_61
db 4Eh                  ; field_62
db '¦',0Dh,0Ah          ; field_63
db 1Dh                  ; field_66
db 30h                  ; field_67
db '¦'                  ; field_68
db 1Dh                  ; field_69
db 4Eh                  ; field_6A
db '¦',0Dh,0Ah          ; field_6B
db 1Dh                  ; field_6E
db 30h                  ; field_6F
db '¦'                  ; field_70
db 1Dh                  ; field_71
db 4Eh                  ; field_72
db '¦',0Dh,0Ah          ; field_73
db 1Dh                  ; field_76
db 30h                  ; field_77
db '¦'                  ; field_78
db 1Dh                  ; field_79
db 4Eh                  ; field_7A
db '¦',0Dh,0Ah          ; field_7B
db 1Dh                  ; field_7E
db 30h                  ; field_7F
db '¦'                  ; field_80
db 1Dh                  ; field_81
db 4Eh                  ; field_82
db '¦',0Dh,0Ah          ; field_83
db 1Dh                  ; field_86
db 30h                  ; field_87
db '+-----------------------------+'; field_88
db 7Ch                  ; field_A7
db 37h                  ; field_A8
db 0                    ; field_A9
aInsertSourceDisk db 1Dh                  ; field_0
db 33h                  ; field_1
db 7Ch                  ; field_2
db 33h                  ; field_3
db 'Insert '            ; field_4
db 7Ch                  ; field_B
db 3Fh                  ; field_C
db 'SOURCE'             ; field_D
db 7Ch                  ; field_13
db 33h                  ; field_14
db ' diskette ',0Dh,0Ah ; field_15
db 1Dh                  ; field_21
db 36h                  ; field_22
db 'and press '         ; field_23
db 7Ch                  ; field_2D
db 3Fh                  ; field_2E
db 'ENTER'              ; field_2F
db 7Ch                  ; field_34
db 33h                  ; field_35
db '...'                ; field_36
db 7Ch                  ; field_39
db 37h                  ; field_3A
db 0                    ; field_3B
aInsertTargetDisk db 1Dh                  ; field_0
db 33h                  ; field_1
db 7Ch                  ; field_2
db 33h                  ; field_3
db 'Insert '            ; field_4
db 7Ch                  ; field_B
db 3Fh                  ; field_C
db 'TARGET'             ; field_D
db 7Ch                  ; field_13
db 33h                  ; field_14
db ' diskette',0Dh,0Ah  ; field_15
db 1Dh                  ; field_20
db 36h                  ; field_21
db 'and press '         ; field_22
db 7Ch                  ; field_2C
db 3Fh                  ; field_2D
db 'ENTER'              ; field_2E
db 7Ch                  ; field_33
db 33h                  ; field_34
db '...'                ; field_35
db 7Ch                  ; field_38
db 37h                  ; field_39
db 0                    ; field_3A
aSpacesClrMsgWndw db 1Dh                  ; field_0
db 31h                  ; field_1
db '                             ',0Dh,0Ah; field_2
db 1Dh                  ; field_21
db 31h                  ; field_22
db '                             ',0Dh,0Ah; field_23
db 1Dh                  ; field_42
db 31h                  ; field_43
db '                             ',0Dh,0Ah; field_44
db 1Dh                  ; field_63
db 31h                  ; field_64
db '                             ',0Dh,0Ah; field_65
db 1Dh                  ; field_84
db 31h                  ; field_85
db '                             ',0; field_86
aCheckSourceDisk db 7                    ; field_0
db 1Dh                  ; field_1
db 37h                  ; field_2
db 7Ch                  ; field_3
db 33h                  ; field_4
db 'Check diskette in',0Dh,0Ah; field_5
db 1Dh                  ; field_18
db 38h                  ; field_19
db 7Ch                  ; field_1A
db 3Fh                  ; field_1B
db 'SOURCE'             ; field_1C
db 7Ch                  ; field_22
db 33h                  ; field_23
db ' drive.',0Dh,0Ah    ; field_24
db 1Dh                  ; field_2D
db 32h                  ; field_2E
db 'Press '             ; field_2F
db 7Ch                  ; field_35
db 3Fh                  ; field_36
db 'Q'                  ; field_37
db 7Ch                  ; field_38
db 33h                  ; field_39
db ' to quit or',0Dh,0Ah; field_3A
db 1Dh                  ; field_47
db 32h                  ; field_48
db 'Press '             ; field_49
db 7Ch                  ; field_4F
db 3Fh                  ; field_50
db 'ENTER'              ; field_51
db 7Ch                  ; field_56
db 33h                  ; field_57
db ' to continue...'    ; field_58
db 7Ch                  ; field_67
db 37h                  ; field_68
db 0                    ; field_69
aDiskFullError db 7                    ; field_0
db 1Dh                  ; field_1
db 37h                  ; field_2
db 7Ch                  ; field_3
db 33h                  ; field_4
db 'Disk full error on',0Dh,0Ah; field_5
db 1Dh                  ; field_19
db 38h                  ; field_1A
db 7Ch                  ; field_1B
db 3Fh                  ; field_1C
db 'TARGET'             ; field_1D
db 7Ch                  ; field_23
db 33h                  ; field_24
db ' drive.',0Dh,0Ah    ; field_25
db 1Dh                  ; field_2E
db 32h                  ; field_2F
db 'Press '             ; field_30
db 7Ch                  ; field_36
db 3Fh                  ; field_37
db 'Q'                  ; field_38
db 7Ch                  ; field_39
db 33h                  ; field_3A
db ' to quit or',0Dh,0Ah; field_3B
db 1Dh                  ; field_48
db 32h                  ; field_49
db 'Press '             ; field_4A
db 7Ch                  ; field_50
db 3Fh                  ; field_51
db 'ENTER'              ; field_52
db 7Ch                  ; field_57
db 33h                  ; field_58
db ' to continue...'    ; field_59
db 7Ch                  ; field_68
db 37h                  ; field_69
db 0                    ; field_6A
aCheckTargetDisk db 7                    ; field_0
db 1Dh                  ; field_1
db 37h                  ; field_2
db 7Ch                  ; field_3
db 33h                  ; field_4
db 'Check diskette in',0Dh,0Ah; field_5
db 1Dh                  ; field_18
db 38h                  ; field_19
db 7Ch                  ; field_1A
db 3Fh                  ; field_1B
db 'TARGET'             ; field_1C
db 7Ch                  ; field_22
db 33h                  ; field_23
db ' drive.',0Dh,0Ah    ; field_24
db 1Dh                  ; field_2D
db 32h                  ; field_2E
db 'Press '             ; field_2F
db 7Ch                  ; field_35
db 3Fh                  ; field_36
db 'Q'                  ; field_37
db 7Ch                  ; field_38
db 33h                  ; field_39
db ' to quit or',0Dh,0Ah; field_3A
db 1Dh                  ; field_47
db 32h                  ; field_48
db 'Press '             ; field_49
db 7Ch                  ; field_4F
db 3Fh                  ; field_50
db 'ENTER'              ; field_51
db 7Ch                  ; field_56
db 33h                  ; field_57
db ' to continue...'    ; field_58
db 7Ch                  ; field_67
db 37h                  ; field_68
db 0                    ; field_69
aPleaseUseTCM db 7                    ; field_0
db 1Dh                  ; field_1
db 32h                  ; field_2
db 7Ch                  ; field_3
db 33h                  ; field_4
db 'Please use TCM to copy',0Dh,0Ah; field_5
db 1Dh                  ; field_1D
db 32h                  ; field_1E
db 'this disk.',0Dh,0Ah ; field_1F
db 1Dh                  ; field_2B
db 32h                  ; field_2C
db 'Press '             ; field_2D
db 7Ch                  ; field_33
db 3Fh                  ; field_34
db 'Q'                  ; field_35
db 7Ch                  ; field_36
db 33h                  ; field_37
db ' to quit or',0Dh,0Ah; field_38
db 1Dh                  ; field_45
db 32h                  ; field_46
db 'Press '             ; field_47
db 7Ch                  ; field_4D
db 3Fh                  ; field_4E
db 'ENTER'              ; field_4F
db 7Ch                  ; field_54
db 33h                  ; field_55
db ' to continue...'    ; field_56
db 7Ch                  ; field_65
db 37h                  ; field_66
db 0                    ; field_67
aEnterSourceDrive db 1Dh                  ; field_0
db 32h                  ; field_1
db 7Ch                  ; field_2
db 33h                  ; field_3
db 'Enter letter (A -  ) of',0Dh,0Ah; field_4
db 1Dh                  ; field_1D
db 32h                  ; field_1E
db 'drive that will contain',0Dh,0Ah; field_1F
db 1Dh                  ; field_38
db 32h                  ; field_39
db 'the source diskette.'; field_3A
db 7Ch                  ; field_4E
db 37h                  ; field_4F
db 0                    ; field_50
aEnterTargetDrive db 1Dh                  ; field_0
db 32h                  ; field_1
db 7Ch                  ; field_2
db 33h                  ; field_3
db 'Enter letter (A -  ) of',0Dh,0Ah; field_4
db 1Dh                  ; field_1D
db 32h                  ; field_1E
db 'drive that will contain',0Dh,0Ah; field_1F
db 1Dh                  ; field_38
db 32h                  ; field_39
db 'the target diskette.',0Dh,0Ah; field_3A
db 1Dh                  ; field_50
db 32h                  ; field_51
db 'This may be the same as the',0Dh,0Ah; field_52
db 1Dh                  ; field_6F
db 32h                  ; field_70
db 'source drive.'      ; field_71
db 7Ch                  ; field_7E
db 37h                  ; field_7F
db 0                    ; field_80
aEnterFirstTrack db 1Dh                  ; field_0
db 32h                  ; field_1
db 7Ch                  ; field_2
db 33h                  ; field_3
db 'Enter first track to copy.',0Dh,0Ah; field_4
db 1Dh                  ; field_20
db 32h                  ; field_21
db '(00 - 29 for 5.25" drives)',0Dh,0Ah; field_22
db 1Dh                  ; field_3E
db 32h                  ; field_3F
db '(00 - 4F for 3.5" drives)'; field_40
db 7Ch                  ; field_59
db 37h                  ; field_5A
db 0                    ; field_5B
aEnterLastTrack db 1Dh                  ; field_0
db 32h                  ; field_1
db 7Ch                  ; field_2
db 33h                  ; field_3
db 'Enter last track to copy.',0Dh,0Ah; field_4
db 1Dh                  ; field_1F
db 32h                  ; field_20
db '(   - 29 for 5.25" drives)',0Dh,0Ah; field_21
db 1Dh                  ; field_3D
db 32h                  ; field_3E
db '(   - 4F for 3.5" drives)'; field_3F
db 7Ch                  ; field_58
db 37h                  ; field_59
db 0                    ; field_5A
aEnterTrkSpacing db 1Dh                  ; field_0
db 32h                  ; field_1
db 7Ch                  ; field_2
db 33h                  ; field_3
db 'Enter spacing between',0Dh,0Ah; field_4
db 1Dh                  ; field_1B
db 32h                  ; field_1C
db 'tracks (01 -   ).'  ; field_1D
db 7Ch                  ; field_2E
db 37h                  ; field_2F
db 0                    ; field_30
aEnterNumSides db 1Dh                  ; field_0
db 32h                  ; field_1
db 7Ch                  ; field_2
db 33h                  ; field_3
db 'Enter number of sides',0Dh,0Ah; field_4
db 1Dh                  ; field_1B
db 32h                  ; field_1C
db 'to copy (1 or 2).'  ; field_1D
db 7Ch                  ; field_2E
db 37h                  ; field_2F
db 0                    ; field_30
aInsertDisksBegin db '                              '; field_0
db 7Ch                  ; field_1E
db 36h                  ; field_1F
db '- INSERT DISKETTES -',0Dh,0Ah; field_20
db 0Ah                  ; field_20
db '                       '; field_20
db 7Ch                  ; field_4E
db 3Eh                  ; field_4F
db 'SPACE'              ; field_50
db 7Ch                  ; field_55
db 36h                  ; field_56
db ' to Begin          '; field_57
db 7Ch                  ; field_6A
db 3Eh                  ; field_6B
db 'Q'                  ; field_6C
db 7Ch                  ; field_6D
db 36h                  ; field_6E
db ' to Quit',0Dh,0Ah   ; field_6F
db '                       '; field_6F
db 7Ch                  ; field_90
db 3Eh                  ; field_91
db 'ESC'                ; field_92
db 7Ch                  ; field_95
db 36h                  ; field_96
db '   to Restart'      ; field_97
db 7Ch                  ; field_A4
db 37h                  ; field_A5
db 0                    ; field_A6
aImportantNotice db 0Dh,0Ah,0Ah          ; field_0
db 7Ch                  ; field_3
db 33h                  ; field_4
db 'IMPORTANT NOTICE: This product is p'; field_5
db 'rovided for the purpose of',0Dh,0Ah; field_5
db 'enabling you to make archival copie'; field_5
db 's only. Under the Copyright Law',0Dh,0Ah; field_5
db 'you, as the owner of a copy of a co'; field_5
db 'mputer program, are entitled',0Dh,0Ah; field_5
db 'to make a new copy for archival pur'; field_5
db 'poses only and this product',0Dh,0Ah; field_5
db 'will enable you to do so. This prod'; field_5
db 'uct is supplied for no other',0Dh,0Ah; field_5
db 'purpose and you are not permitted t'; field_5
db 'o utilize it for any use, other',0Dh,0Ah; field_5
db 'than that specified. By using this '; field_5
db 'product, you agree to be bound',0Dh,0Ah; field_5
db 'by the terms of this notice.'; field_5
db 7Ch                  ; field_1ED
db 37h                  ; field_1EE
db 0Dh,0Ah,0            ; field_1EF
aPlaceSourceDisk db 0Dh,0Ah              ; field_0
db 7Ch                  ; field_2
db 33h                  ; field_3
db 'Place SOURCE diskette in drive '; field_4
db 7Ch                  ; field_23
db 37h                  ; field_24
db 0                    ; field_25
aPlaceTargetDisk db 0Dh,0Ah,0Ah          ; field_0
db 7Ch                  ; field_3
db 33h                  ; field_4
db 'Place TARGET diskette in drive '; field_5
db 7Ch                  ; field_24
db 37h                  ; field_25
db 0                    ; field_26
aPressSpace db 0Dh,0Ah              ; field_0
db 7Ch                  ; field_2
db 33h                  ; field_3
db 'Press SPACE to proceed, Q to quit.'; field_4
db 7Ch                  ; field_26
db 37h                  ; field_27
db 0                    ; field_28
aDupProcComplete db 0Dh,0Ah              ; field_0
db 7Ch                  ; field_2
db 33h                  ; field_3
db 'Duplication process complete.'; field_4
db 7Ch                  ; field_21
db 37h                  ; field_22
db 0Dh,0Ah              ; field_23
aMakeAnotherCopy? db 0Dh,0Ah              ; field_0
db 7Ch                  ; field_2
db 33h                  ; field_3
db 'Do you want to make another copy? ('; field_4
db 'Y/N) '              ; field_4
db 7Ch                  ; field_2C
db 37h                  ; field_2D
db 0                    ; field_2E
aTargetDrvIsWP db 0Dh,0Ah              ; field_0
db 7                    ; field_2
db 7Ch                  ; field_3
db 33h                  ; field_4
db 'Target drive is WRITE PROTECTED.'; field_5
db 7Ch                  ; field_25
db 37h                  ; field_26
db 0Dh,0Ah,0            ; field_27
aDupProcStopped db 0Dh,0Ah              ; field_0
db 7Ch                  ; field_2
db 33h                  ; field_3
db 'Duplication process stopped.'; field_4
db 7Ch                  ; field_20
db 37h                  ; field_21
db 0Dh,0Ah,0            ; field_22
aUnableToFindDOB db 0Dh,0Ah,0Ah          ; field_0
db 7                    ; field_3
db '  Unable to find Deluxe Option Boar'; field_4
db 'd.',0Dh,0Ah         ; field_4
db '  Please refer to Troubleshooting S'; field_4
db 'ection in manual.',0Ah,0; field_4
aInvalidCommand db 0Dh,0Ah,0Ah          ; field_0
db 7                    ; field_3
db '  Invalid command line.',0Dh,0Ah; field_4
db 0Ah,0                ; field_4
aPressEnter db 0Dh,0Ah              ; field_0
db 7Ch                  ; field_2
db 33h                  ; field_3
db 'Press ENTER to continue.'; field_4
db 7Ch                  ; field_1C
db 37h                  ; field_1D
db 0                    ; field_1E
aChkSrcDsk db 0Dh,0Ah              ; field_0
db 7                    ; field_2
db 7Ch                  ; field_3
db 33h                  ; field_4
db 'Check diskette in Source drive.'; field_5
db 7Ch                  ; field_24
db 37h                  ; field_25
db 0Dh,0Ah,0            ; field_26
aDOBDoesNotReq db 0Dh,0Ah,0Ah          ; field_0
db 7                    ; field_3
db 'Deluxe Option Board does not requir'; field_4
db 'e ',27h,'/C',27h,' parameter.',0Dh,0Ah; field_4
db 'Please set ',27h,'DMA 1 / DMA 2',27h,' ju'; field_4
db 'mper on board to desired DMA channe'; field_4
db 'l.',0Dh,0Ah         ; field_4
db 0Ah                  ; field_4
db 'Press any key to continue...',0; field_4
aChkTargetDsk db 0Dh,0Ah              ; field_0
db 7                    ; field_2
db 7Ch                  ; field_3
db 33h                  ; field_4
db 'Check diskette in Target drive.'; field_5
db 7Ch                  ; field_24
db 37h                  ; field_25
db 0Dh,0Ah,0            ; field_26
aDupHopperOpn db 7                    ; field_0
db 1Dh                  ; field_1
db 32h                  ; field_2
db 7Ch                  ; field_3
db 33h                  ; field_4
db 'Duplicator hopper drawer',0Dh,0Ah; field_5
db 1Dh                  ; field_1F
db 32h                  ; field_20
db 'is open!',0Dh,0Ah   ; field_21
db 1Dh                  ; field_2B
db 32h                  ; field_2C
db 'Close and press a key',0Dh,0Ah; field_2D
db 1Dh                  ; field_44
db 32h                  ; field_45
db 'to continue.'       ; field_46
db 7Ch                  ; field_52
db 37h                  ; field_53
db 0                    ; field_54
aDiskJam db 7                    ; field_0
db 1Dh                  ; field_1
db 32h                  ; field_2
db 7Ch                  ; field_3
db 33h                  ; field_4
db 'A disk has jammed in',0Dh,0Ah; field_5
db 1Dh                  ; field_1B
db 32h                  ; field_1C
db 'the dupilicator.',0Dh,0Ah; field_1D
db 1Dh                  ; field_2F
db 32h                  ; field_30
db 'Correct and press a key',0Dh,0Ah; field_31
db 1Dh                  ; field_4A
db 32h                  ; field_4B
db 'to continue.'       ; field_4C
db 7Ch                  ; field_58
db 37h                  ; field_59
db 0                    ; field_5A
aInputBinEmpty db 7                    ; field_0
db 1Dh                  ; field_1
db 32h                  ; field_2
db 7Ch                  ; field_3
db 33h                  ; field_4
db 'The duplicator input bin',0Dh,0Ah; field_5
db 1Dh                  ; field_1F
db 32h                  ; field_20
db 'is empty!',0Dh,0Ah  ; field_21
db 1Dh                  ; field_2C
db 32h                  ; field_2D
db 'Fill with diskettes and',0Dh,0Ah; field_2E
db 1Dh                  ; field_47
db 32h                  ; field_48
db 'press a key to continue.'; field_49
db 7Ch                  ; field_61
db 37h                  ; field_62
db 0                    ; field_63
aLoaderOffline db 7                    ; field_0
db 1Dh                  ; field_1
db 32h                  ; field_2
db 7Ch                  ; field_3
db 33h                  ; field_4
db 'Loader is off-line.',0Dh,0Ah; field_5
db 1Dh                  ; field_1A
db 32h                  ; field_1B
db 'Press any key to continue.'; field_1C
db 7Ch                  ; field_36
db 37h                  ; field_37
db 0                    ; field_38
aUnknownResponse db 7                    ; field_0
db 1Dh                  ; field_1
db 32h                  ; field_2
db 7Ch                  ; field_3
db 33h                  ; field_4
db 'An unknown response has',0Dh,0Ah; field_5
db 1Dh                  ; field_1E
db 32h                  ; field_1F
db 'been received.',0Dh,0Ah; field_20
db 1Dh                  ; field_30
db 32h                  ; field_31
db 'Press any key to continue.'; field_32
db 7Ch                  ; field_4C
db 37h                  ; field_4D
db 0                    ; field_4E
aDMAChanlPort Stru_MSG36 <7Ch, 35h, \
            'DMA Channel:      Port:     ',\
            7Ch, 37h, 0;
aDiskGood db 1Dh                  ; field_0
db 32h                  ; field_1
db 7Ch                  ; field_2
db 33h                  ; field_3
db 'Disk was GOOD.',0Dh,0Ah; field_4
db 1Dh                  ; field_14
db 32h                  ; field_15
db 'Insert next disk and',0Dh,0Ah; field_16
db 1Dh                  ; field_2C
db 32h                  ; field_2D
db 'press a key.'       ; field_2E
db 7Ch                  ; field_3A
db 37h                  ; field_3B
db 0                    ; field_3C
aDiskBad db 7                    ; field_0
db 1Dh                  ; field_1
db 32h                  ; field_2
db 7Ch                  ; field_3
db 33h                  ; field_4
db 'Disk was BAD!',0Dh,0Ah; field_5
db 1Dh                  ; field_14
db 32h                  ; field_15
db 'Insert next disk and',0Dh,0Ah; field_16
db 1Dh                  ; field_2C
db 32h                  ; field_2D
db 'press a key.'       ; field_2E
db 7Ch                  ; field_3A
db 37h                  ; field_3B
db 0                    ; field_3C
aGoodDisks Stru_MSG39 <7Ch, 35h, 'Good disks: ';
aBadDisks Stru_MSG3A <7Ch, 35h, 'Bad  disks: ';
aDiskWPPresskey db 7                    ; field_0
db 1Dh                  ; field_1
db 32h                  ; field_2
db 7Ch                  ; field_3
db 33h                  ; field_4
db 'Disk is write-protected!',0Dh,0Ah; field_5
db 1Dh                  ; field_1F
db 32h                  ; field_20
db 'Press a key to continue.'; field_21
db 7Ch                  ; field_39
db 37h                  ; field_3A
db 0                    ; field_3B
aTrackNumbers2 db 7Ch                  ; field_0
db 35h                  ; field_1
db '00000000000000001111111111111111222'; field_2
db '22222222222223333333333333333444444'; field_2
db '44444444440123456789ABCDEF012345678'; field_2
db '9ABCDEF0123456789ABCDEF0123456789AB'; field_2
db 'CDEF0123456789ABCDEF---------------'; field_2
db '-----------------------------------'; field_2
db '------------------------------',0Dh,0Ah; field_2
db 7Ch                  ; field_F4
db 37h                  ; field_F5
db 0                    ; field_F6
aDiskType Stru_MSG3D <7Ch, 35h, 'Disk type:', 7Ch,\
            37h, ' ';
aNullMsg0 Stru_MSG3E <0;
aNullMsg1 Stru_MSG3F <0;
aNullMsg2 Stru_MSG40 <0;
AnullMsg3 Stru_MSG42 <0;
aApple Stru_MSG43 <'Apple   ';
aFm Stru_MSG44 <'FM      ';
aNullMsg4 Stru_MSG45 <0;
aMfm Stru_MSG46 <'MFM     ';
aAmiga Stru_MSG47 <'Amiga   ';
aMarginalCtlr db 1Dh                  ; field_0
db 32h                  ; field_1
db 7Ch                  ; field_2
db 33h                  ; field_3
db 'Target disk may not boot',0Dh,0Ah; field_4
db 1Dh                  ; field_1E
db 32h                  ; field_1F
db 'reliably on this machine due',0Dh,0Ah; field_20
db 1Dh                  ; field_3E
db 32h                  ; field_3F
db 'to marginal disk controller.',0Dh,0Ah; field_40
db 1Dh                  ; field_5E
db 32h                  ; field_5F
db 7Ch                  ; field_60
db 33h                  ; field_61
db 'Press '             ; field_62
db 7Ch                  ; field_68
db 3Fh                  ; field_69
db 'Q'                  ; field_6A
db 7Ch                  ; field_6B
db 33h                  ; field_6C
db ' to quit or',0Dh,0Ah; field_6D
db 1Dh                  ; field_7A
db 32h                  ; field_7B
db 7Ch                  ; field_7C
db 33h                  ; field_7D
db 'Press '             ; field_7E
db 7Ch                  ; field_84
db 3Fh                  ; field_85
db 'ENTER'              ; field_86
db 7Ch                  ; field_8B
db 33h                  ; field_8C
db ' to continue...'    ; field_8D
db 7Ch                  ; field_9C
db 37h                  ; field_9D
db 0                    ; field_9E
aMarginalTimer db 1Dh                  ; field_0
db 32h                  ; field_1
db 7Ch                  ; field_2
db 33h                  ; field_3
db 'Target disk may not boot',0Dh,0Ah; field_4
db 1Dh                  ; field_1E
db 32h                  ; field_1F
db 'reliably due to marginal',0Dh,0Ah; field_20
db 1Dh                  ; field_3A
db 32h                  ; field_3B
db 'timer logic on motherboard.',0Dh,0Ah; field_3C
db 1Dh                  ; field_59
db 32h                  ; field_5A
db 7Ch                  ; field_5B
db 33h                  ; field_5C
db 'Press '             ; field_5D
db 7Ch                  ; field_63
db 3Fh                  ; field_64
db 'Q'                  ; field_65
db 7Ch                  ; field_66
db 33h                  ; field_67
db ' to quit or',0Dh,0Ah; field_68
db 1Dh                  ; field_75
db 32h                  ; field_76
db 7Ch                  ; field_77
db 33h                  ; field_78
db 'Press '             ; field_79
db 7Ch                  ; field_7F
db 3Fh                  ; field_80
db 'ENTER'              ; field_81
db 7Ch                  ; field_86
db 33h                  ; field_87
db ' to continue...'    ; field_88
db 7Ch                  ; field_97
db 37h                  ; field_98
db 0                    ; field_99
aEnterTracks db 1Dh                  ; field_0
db 32h                  ; field_1
db 7Ch                  ; field_2
db 33h                  ; field_3
db 'Enter '             ; field_4
db 7Ch                  ; field_A
db 3Fh                  ; field_B
db 'Y'                  ; field_C
db 7Ch                  ; field_D
db 33h                  ; field_E
db ' for all tracks,',0Dh,0Ah; field_F
db 1Dh                  ; field_21
db 32h                  ; field_22
db 7Ch                  ; field_23
db 3Fh                  ; field_24
db 'N'                  ; field_25
db 7Ch                  ; field_26
db 33h                  ; field_27
db ' for no tracks, a single',0Dh,0Ah; field_28
db 1Dh                  ; field_42
db 32h                  ; field_43
db 'track number or a range of',0Dh,0Ah; field_44
db 1Dh                  ; field_60
db 32h                  ; field_61
db 'tracks.'            ; field_62
db 7Ch                  ; field_69
db 37h                  ; field_6A
db 0                    ; field_6B
aIncompatibleImg db 1Dh                  ; field_0
db 32h                  ; field_1
db 7                    ; field_2
db 7Ch                  ; field_3
db 33h                  ; field_4
db 'Incompatible image file.',0Dh,0Ah; field_5
db 0Dh,0Ah              ; field_5
db 1Dh                  ; field_21
db 32h                  ; field_22
db 7Ch                  ; field_23
db 33h                  ; field_24
db 'Press '             ; field_25
db 7Ch                  ; field_2B
db 3Fh                  ; field_2C
db 'Q'                  ; field_2D
db 7Ch                  ; field_2E
db 33h                  ; field_2F
db ' to quit or',0Dh,0Ah; field_30
db 1Dh                  ; field_3D
db 32h                  ; field_3E
db 7Ch                  ; field_3F
db 33h                  ; field_40
db 'Press '             ; field_41
db 7Ch                  ; field_47
db 3Fh                  ; field_48
db 'ENTER'              ; field_49
db 7Ch                  ; field_4E
db 33h                  ; field_4F
db ' to continue...'    ; field_50
db 7Ch                  ; field_5F
db 37h                  ; field_60
db 0                    ; field_61
db    0
byte_1AAF5 db 0
byte_1AAF6 db 0
word_1AAF7 dw 0
word_1AAF9 dw 0



sub_1AAFB proc near
mov     ah, 0
cmp     al, 0
jnz     short loc_1AB07
cmp     dh, dl
jz      short loc_1AB07
mov     ah, 1

loc_1AB07:
call    sub_1AFAC
cmp     al, 0
jnz     short locret_1AB41
mov     cs:word_10093, cx
mov     bx, ds
push    cs
pop     ds
assume ds:seg001
mov     TrackBufSeg, bx
mov     word_10059, bx
mov     cl, 4
shr     bx, cl
mov     byte_1005B, bh
mov     TrackBufOfs, 0
mov     word_1005C, 7000h
mov     word_1005E, 9000h
shl     dh, 1
add     dh, dl
mov     byte_100B7, dh

locret_1AB41:
retn
sub_1AAFB endp




sub_1AB42 proc near
cmp     byte_100B7, 1
jz      short locret_1AB5C
mov     DiskType, 0FFh
mov     ax, 0
cld
push    cs
pop     es
assume es:seg001
mov     di, offset TrackOffsTbl
mov     cx, 100h
rep stosw

locret_1AB5C:
retn
sub_1AB42 endp




sub_1AB5D proc near
mov     al, 0
call    sub_1B071
mov     word_1AAF9, es
mov     al, 0
call    sub_1AC08
mov     si, 0BAh ; '¦'
mov     di, 100h
push    ds
push    cs
pop     ds
mov     es, cs:word_1AAF9
assume es:nothing
mov     cx, 2805h
shr     cx, 1
rep movsw
pop     ds
assume ds:nothing
mov     al, 0
call    sub_1B071
mov     ds:word_1AAF9, es
mov     al, 0
call    sub_1ABFF
retn
sub_1AB5D endp




sub_1AB90 proc near
mov     al, 0
call    sub_1B071
mov     ds:word_1AAF9, es
mov     al, 0
call    sub_1AC08
mov     di, 0BAh ; '¦'
mov     si, 100h
push    ds
push    cs
pop     es
assume es:seg001
mov     ds, cs:word_1AAF9
mov     cx, 2805h
shr     cx, 1
cmp     byte ptr [si+4], 'N'
jnb     short loc_1ABFC
rep movsw
pop     ds
mov     bx, ds:TrackTypeTable
mov     ds:KeepTrkLngth0, 'n'
mov     ds:CopyXIDX0, 'n'
mov     ds:CopyWkBits0, 'n'
mov     ds:VerifyWrite0, 'n'
test    bl, 1
jz      short loc_1ABDC
mov     ds:KeepTrkLngth0, 'y'

loc_1ABDC:
test    bl, 2
jz      short loc_1ABE6
mov     ds:CopyXIDX0, 'y'

loc_1ABE6:
test    bl, 4
jz      short loc_1ABF0
mov     ds:CopyWkBits0, 'y'

loc_1ABF0:
test    bl, 8
jz      short loc_1ABFA
mov     ds:VerifyWrite0, 'y'

loc_1ABFA:
clc
retn

loc_1ABFC:
pop     ds
stc
retn
sub_1AB90 endp




sub_1ABFF proc near
push    ds
call    MaxtMotorTimer
pop     ds
call    sub_1B0DC
retn
sub_1ABFF endp




sub_1AC08 proc near
push    ds
call    MaxtMotorTimer
pop     ds
call    sub_1B094
push    ds
call    MaxtMotorTimer
pop     ds
retn
sub_1AC08 endp



; Calculates track number from cylinder and head,
; then multiplies by 2 for addressing word per track
; tables. Offset returned in BX.

GetTrkDatOfs proc near
mov     bh, 0
mov     bl, ds:CurrentCylinder
shl     bx, 1
add     bl, ds:CurrentSide
shl     bx, 1
retn
GetTrkDatOfs endp




sub_1AC25 proc near
push    ax
call    GetTrkDatOfs
mov     ax, ds:TrackOffsTbl[bx]
mov     al, 0
mov     si, ax
mov     es, word ptr ds:CurrTrackBufSeg
assume es:nothing
pop     ax
retn
sub_1AC25 endp




sub_1AC37 proc near
call    sub_1AD37
mov     ds:byte_1AAF5, 0
mov     al, ds:byte_1AAF5
call    sub_1B071
mov     word ptr ds:CurrTrackBufSeg, es
mov     ds:word_10091, 0
call    GetTrkDatOfs
mov     ax, 4000h
mov     al, ds:byte_1AAF5
mov     ds:TrackOffsTbl[bx], ax
mov     ds:byte_1AAF6, 0
clc
retn
sub_1AC37 endp




sub_1AC63 proc near
call    sub_1AD37
call    GetTrkDatOfs
mov     ax, ds:TrackOffsTbl[bx]
mov     ds:byte_1AAF5, al
call    sub_1B071
mov     word ptr ds:CurrTrackBufSeg, es
mov     ds:word_10091, 0
mov     al, ds:byte_1AAF5
call    sub_1AC08
clc
retn
sub_1AC63 endp




sub_1AC85 proc near
cmp     ds:byte_1AAF6, 0
jnz     short loc_1AC94
mov     ds:byte_1AAF6, 1
jmp     short loc_1ACC8
align 2

loc_1AC94:
mov     ax, 0
cmp     ds:word_10093, 1
ja      short loc_1ACAF
cmp     ds:NumberOfSides, 1
jz      short loc_1ACAF
cmp     ds:CurrentSide, 1
jz      short loc_1ACAF
call    SetDmaCount

loc_1ACAF:
mov     dx, ds:word_13D05
add     ax, dx
mov     dx, ds:word_1AAF7
add     ax, dx
jb      short loc_1ACCF

loc_1ACBD:
call    GetTrkDatOfs
mov     dl, ds:byte_1AAF5
mov     ds:TrackOffsTbl[bx], dx

loc_1ACC8:
call    sub_14861
mov     al, 0
clc
retn

loc_1ACCF:
mov     al, ds:byte_1AAF5
call    sub_1ABFF
mov     ds:word_10093, cx
cmp     al, 0
jnz     short loc_1ACF8
cmp     cx, 0
jz      short loc_1ACF4
inc     ds:byte_1AAF5
mov     al, ds:byte_1AAF5
call    sub_1B071
mov     word ptr ds:CurrTrackBufSeg, es
mov     dh, 0
jmp     short loc_1ACBD

loc_1ACF4:
mov     al, 1
stc
retn

loc_1ACF8:
jmp     short loc_1ACF4
sub_1AC85 endp




sub_1ACFA proc near
call    GetTrkDatOfs
mov     ax, ds:TrackOffsTbl[bx]
cmp     ax, 0
jz      short loc_1AD28
cmp     al, ds:byte_1AAF5
jz      short loc_1AD24
mov     ds:byte_1AAF5, al
call    sub_1B071
mov     word ptr ds:CurrTrackBufSeg, es
mov     al, ds:byte_1AAF5
call    sub_1AC08
cmp     al, 2
jz      short locret_1AD27
cmp     al, 0
jnz     short loc_1AD2D

loc_1AD24:
mov     al, 0
clc

locret_1AD27:
retn

loc_1AD28:
mov     al, 1
stc
jmp     short locret_1AD27

loc_1AD2D:
jmp     short loc_1AD28
sub_1ACFA endp




sub_1AD2F proc near
mov     al, ds:byte_1AAF5
call    sub_1ABFF
clc
retn
sub_1AD2F endp




sub_1AD37 proc near
push    ax
push    ds
cmp     ds:byte_100B7, 0
jz      short loc_1AD48
mov     ax, seg seg002
mov     ds, ax
assume ds:seg002
call    sub_1BBAF

loc_1AD48:
pop     ds
assume ds:nothing
pop     ax
retn
sub_1AD37 endp




DuplicatorVector proc near
mov     ax, 0           ; Disk duplicator patches in a far call here??
clc
retn
DuplicatorVector endp

byte_1AD50 db 2 dup(0FFh)
word_1AD52 dw 0
word_1AD54 dw 0
word_1AD56 dw 0
word_1AD58 dw 0
word_1AD5A dw 0
word_1AD5C dw 0
word_1AD5E dw 0
word_1AD60 dw 0
word_1AD62 dw 0
byte_1AD64 db 2 dup(0)
word_1AD66 dw 0
word_1AD68 dw 0
word_1AD6A dw 0
word_1AD6C dw 0
byte_1AD6E db 3 dup(0)
byte_1AD71 db 0
byte_1AD72 db 0
byte_1AD73 db 0
byte_1AD74 db 0
byte_1AD75 db 0
byte_1AD76 db 0
byte_1AD77 db 0
byte_1AD78 db 0FFh
byte_1AD79 db 0
word_1AD7A dw 0
byte_1AD7C db 0
byte_1AD7D db 0
aC_Mm db 'C:$$$$$$$$.$MM',0
byte_1AD8D db 0
word_1AD8E dw 0
unk_1AD90 db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
unk_1ADA2 db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
word_1AFA2 dw 0
word_1AFA4 dw 0
OldInt24Off2 dw 0
OldInt24Seg2 dw 0
DosMajorVer db 2
byte_1AFAB db 0



sub_1AFAC proc near
push    cs
pop     ds
assume ds:seg001
call    sub_1B29C
call    GetInt24_2
mov     byte_1AD7D, ah
mov     byte_1AD74, dl
mov     byte_1AD76, dh
mov     al, byte_1AD74
call    sub_1B276
jnb     short loc_1AFCB
jmp     loc_1B064

loc_1AFCB:
mov     byte_1AD75, al
mov     al, byte_1AD76
call    sub_1B276
jnb     short loc_1AFD9
jmp     loc_1B064

loc_1AFD9:
mov     byte_1AD77, al
mov     al, byte_1AD75
and     al, byte_1AD77
jz      short loc_1AFE8
jmp     short loc_1B064
align 2

loc_1AFE8:
call    sub_1B210
jnb     short loc_1AFF0
jmp     short loc_1B05E
align 2

loc_1AFF0:
mov     al, byte_1AD75
cmp     al, byte_1AD77
jz      short loc_1B03C
cmp     byte_1AD71, 0
jnz     short loc_1B064
mov     byte_1AD79, 1
cmp     byte_1AD77, 0
jnz     short loc_1B020
call    sub_1B46B
cmp     ax, 0FFFFh
jz      short loc_1B06A
mov     ax, word_1AD54
call    sub_1B40F
call    sub_1B5EE
jmp     short loc_1B044
align 2

loc_1B020:
mov     byte_1AD79, 2
call    sub_1B48D
cmp     ax, 0FFFFh
jz      short loc_1B06A
mov     al, byte_1AD76
call    sub_1B428
mov     word_1AD7A, ax
call    sub_1B6BD
jmp     short loc_1B044
align 2

loc_1B03C:
mov     byte_1AD79, 0
call    sub_1B72B

loc_1B044:
mov     word_1AFA2, cx
mov     dl, byte_1AD75
mov     dh, byte_1AD77
mov     es, word_1AD5E
mov     ds, word_1AD60
assume ds:nothing
clc
mov     al, 0
jmp     short loc_1B06D
align 2

loc_1B05E:
stc
mov     al, 8
jmp     short loc_1B06D
align 2

loc_1B064:
stc
mov     al, 1
jmp     short loc_1B06D
align 2

loc_1B06A:
stc
mov     al, 5

loc_1B06D:
call    RestoreInt24_2
retn
sub_1AFAC endp




sub_1B071 proc near
push    ds
push    bx
push    cx
push    cs
pop     ds
assume ds:seg001
xor     ah, ah
cmp     ax, word_1AFA2
jnb     short loc_1B08D
mov     word_1AFA4, ax
call    sub_1B1A8
call    sub_1B1FC
mov     al, 0
clc
jmp     short loc_1B090
db 90h

loc_1B08D:
mov     al, 2
stc

loc_1B090:
pop     cx
pop     bx
pop     ds
assume ds:nothing
retn
sub_1B071 endp




sub_1B094 proc near
push    ds
push    bx
push    cs
pop     ds
assume ds:seg001
xor     ah, ah
cmp     ax, word_1AFA2
jnb     short loc_1B0D6
mov     word_1AFA4, ax
call    sub_1B1EF
mov     byte_1AD7C, ah
cmp     byte_1AD7C, 2
jnz     short loc_1B0B7
call    sub_1B4C1
jmp     short loc_1B0CD
db 90h

loc_1B0B7:
cmp     byte_1AD7C, 0
jnz     short loc_1B0C4
call    nullsub_1
jmp     short loc_1B0CD
align 2

loc_1B0C4:
push    es
mov     es, word_1AD5E
call    sub_1B4F2
pop     es

loc_1B0CD:
call    sub_1B1FC
mov     al, 0
clc
jmp     short loc_1B0D9
align 2

loc_1B0D6:
mov     al, 2
stc

loc_1B0D9:
pop     bx
pop     ds
assume ds:nothing
retn
sub_1B094 endp




sub_1B0DC proc near
push    ds
push    bx
push    cs
pop     ds
assume ds:seg001
xor     ah, ah
cmp     ax, word_1AFA2
jnb     short loc_1B124
mov     word_1AFA4, ax
call    sub_1B1EF
mov     byte_1AD7C, ah
cmp     byte_1AD7C, 2
jnz     short loc_1B0FF
call    sub_1B531
jmp     short loc_1B115
db 90h

loc_1B0FF:
cmp     byte_1AD7C, 0
jnz     short loc_1B10C
call    nullsub_2
jmp     short loc_1B115
align 2

loc_1B10C:
push    es
mov     es, word_1AD5E
call    sub_1B54A
pop     es

loc_1B115:
mov     cx, word_1AFA2
sub     cx, word_1AFA4
dec     cx
mov     al, 0
clc
jmp     short loc_1B127
align 2

loc_1B124:
mov     al, 2
stc

loc_1B127:
pop     bx
pop     ds
assume ds:nothing
retn
sub_1B0DC endp




sub_1B12A proc near
push    bx
push    dx
push    es
push    ds
push    cs
pop     ds
assume ds:seg001
cmp     word_1AD56, 0
jz      short loc_1B17B
mov     ah, 49h ; 'I'
mov     es, word_1AD56
int     21h             ; DOS - 2+ - FREE MEMORY
                        ; ES = segment address of area to be freed
cmp     word_1AD6A, 0
jz      short loc_1B155
mov     ah, 45h ; 'E'
mov     dx, word_1AD6C
call    CallInt67
mov     word_1AD6A, 0

loc_1B155:
cmp     word_1AD54, 0
jz      short loc_1B17B
mov     ah, 3Eh ; ';'
mov     bx, word_1AD54
int     21h             ; DOS - 2+ - CLOSE A FILE WITH HANDLE
                        ; BX = file handle
mov     word_1AD54, 0
cmp     byte_1AD79, 0
jnz     short loc_1B178
mov     ah, 41h ; 'A'
mov     dx, offset aC_Mm ; "C:$$$$$$$$.$MM"
int     21h             ; DOS - 2+ - DELETE A FILE (UNLINK)
                        ; DS:DX -; ASCIZ pathname of file to delete (no wildcards allowed)

loc_1B178:
call    sub_1B2C5

loc_1B17B:
mov     word_1AD56, 0
mov     byte_1AD73, 0
mov     ax, 0
clc
pop     ds
assume ds:nothing
pop     es
pop     dx
pop     bx
retn
sub_1B12A endp




sub_1B18F proc near
cmp     ds:byte_1AD79, 2
jnz     short loc_1B1A4
mov     ax, seg seg002
push    ds
mov     ds, ax
assume ds:seg002
mov     dx, offset unk_1D94A
mov     ah, 41h
int     21h             ; DOS - 2+ - DELETE A FILE (UNLINK)
                        ; DS:DX -; ASCIZ pathname of file to delete (no wildcards allowed)
pop     ds
assume ds:nothing

loc_1B1A4:
mov     ax, 0
retn
sub_1B18F endp




sub_1B1A8 proc near
push    ax
call    sub_1B1EF
mov     ds:byte_1AD7C, ah
mov     es, cs:word_1AD5E
cmp     ds:byte_1AD7C, 0
jnz     short loc_1B1C2
call    sub_1B581
jmp     short loc_1B1E0
align 2

loc_1B1C2:
call    sub_1B7F2
cmp     ds:byte_1AD7C, 2
jnz     short loc_1B1DD
call    sub_1B597
cmp     ds:byte_1AD6E, 0
jz      short loc_1B1E0
mov     es, ds:word_1AD68
jmp     short loc_1B1E0
db 90h

loc_1B1DD:
call    sub_1B518

loc_1B1E0:
pop     ax
retn
sub_1B1A8 endp




sub_1B1E2 proc near
push    bx
xor     bx, bx
mov     bl, cl
shl     bx, 1
mov     word ptr ds:unk_1ADA2[bx], ax
pop     bx
retn
sub_1B1E2 endp




sub_1B1EF proc near
push    bx
xor     bx, bx
mov     bl, al
shl     bx, 1
mov     ax, word ptr ds:unk_1ADA2[bx]
pop     bx
retn
sub_1B1EF endp




sub_1B1FC proc near
mov     ah, ds:byte_1AD7C
cmp     ah, 2
jnz     short locret_1B20F
test    ds:word_1AD68, 0FFFh
jnz     short locret_1B20F
mov     ah, 0

locret_1B20F:
retn
sub_1B1FC endp




sub_1B210 proc near
push    ax
push    bx
push    cx
mov     bx, 0FFFFh
mov     ah, 48h
int     21h             ; DOS - 2+ - ALLOCATE MEMORY
                        ; BX = number of 16-byte paragraphs desired
cmp     bx, 0FFFFh
jz      short loc_1B271
call    sub_1B302
jb      short loc_1B271
call    CheckEMS
jb      short loc_1B22C
call    GetEMS

loc_1B22C:
mov     al, ds:byte_1AD74
cmp     al, ds:byte_1AD76
jnz     short loc_1B26D
mov     cx, 2
mov     ds:byte_1AD8D, cl
mov     ds:word_1AD8E, 0

loc_1B242:
mov     al, cl
call    sub_1B276
jb      short loc_1B267
cmp     al, 0
jz      short loc_1B267
mov     al, cl
call    sub_1B428
mov     bx, cx
shl     bx, 1
mov     word ptr ds:unk_1AD90[bx], ax
cmp     ds:word_1AD8E, ax
jnb     short loc_1B267
mov     ds:byte_1AD8D, cl
mov     ds:word_1AD8E, ax

loc_1B267:
inc     cx
cmp     cx, 8
jl      short loc_1B242

loc_1B26D:
clc
jmp     short loc_1B272
db 90h

loc_1B271:
stc

loc_1B272:
pop     cx
pop     bx
pop     ax
retn
sub_1B210 endp




sub_1B276 proc near
push    bx
push    cx
push    si
cmp     al, 1
jbe     short loc_1B289
call    sub_1B2AA
jb      short loc_1B297
call    sub_1C4D0
test    al, 80h
jnz     short loc_1B290

loc_1B289:
mov     ax, 0
clc
jmp     short loc_1B298
align 2

loc_1B290:
mov     ax, 1
clc
jmp     short loc_1B298
db 90h

loc_1B297:
stc

loc_1B298:
pop     si
pop     cx
pop     bx
retn
sub_1B276 endp




sub_1B29C proc near
push    ax
push    bx
push    cx
mov     ah, 30h
int     21h             ; DOS - GET DOS VERSION
                        ; Return: AL = major version number (00h for DOS 1.x)
mov     ds:DosMajorVer, al
pop     cx
pop     bx
pop     ax
retn
sub_1B29C endp




sub_1B2AA proc near
push    ax
push    bx
push    cx
push    dx
push    ax
mov     ah, 19h
int     21h             ; DOS - GET DEFAULT DISK NUMBER
mov     dl, al
mov     ah, 0Eh
int     21h             ; DOS - SELECT DISK
                        ; DL = new default drive number (0 = A, 1 = B, etc.)
                        ; Return: AL = number of logical drives
mov     cl, al
pop     ax
dec     cl
cmp     cl, al
pop     dx
pop     cx
pop     bx
pop     ax
retn
sub_1B2AA endp




sub_1B2C5 proc near
push    ax
push    bx
push    cx
push    dx
push    ds
mov     ax, seg seg002
mov     ds, ax
assume ds:seg002
mov     dx, offset unk_1D94A
mov     al, 0
mov     ah, 3Dh
int     21h             ; DOS - 2+ - OPEN DISK FILE WITH HANDLE
                        ; DS:DX -; ASCIZ filename
                        ; AL = access mode
                        ; 0 - read
jb      short loc_1B2FC
mov     bx, ax
mov     ah, 42h ; 'B'
mov     al, 2
xor     cx, cx
xor     dx, dx
int     21h             ; DOS - 2+ - MOVE FILE READ/WRITE POINTER (LSEEK)
                        ; AL = method: offset from end of file
jb      short loc_1B2FC
or      ax, dx
push    ax
mov     ah, 3Eh
int     21h             ; DOS - 2+ - CLOSE A FILE WITH HANDLE
                        ; BX = file handle
pop     ax
cmp     ax, 0
jnz     short loc_1B2FC
mov     dx, offset unk_1D94A
mov     ah, 41h
int     21h             ; DOS - 2+ - DELETE A FILE (UNLINK)
                        ; DS:DX -; ASCIZ pathname of file to delete (no wildcards allowed)

loc_1B2FC:
pop     ds
assume ds:nothing
pop     dx
pop     cx
pop     bx
pop     ax
retn
sub_1B2C5 endp




sub_1B302 proc near
push    ax
push    bx
push    cx
cmp     bx, 1A00h
jb      short loc_1B373
mov     ds:word_1AD5C, bx
mov     ah, 48h
int     21h             ; DOS - 2+ - ALLOCATE MEMORY
                        ; BX = number of 16-byte paragraphs desired
jb      short loc_1B373
mov     ds:word_1AD56, ax
test    ax, 0FFFh
jz      short loc_1B323
and     ax, 0F000h
add     ax, 1000h

loc_1B323:
mov     ds:word_1AD5E, ax
mov     ds:word_1AD62, ax
mov     ax, ds:word_1AD5C
add     ax, ds:word_1AD56
sub     ax, 10h
mov     ds:word_1AD5A, ax
and     ax, 0F000h
mov     ds:word_1AD60, ax
mov     ax, ds:word_1AD5A
sub     ax, ds:word_1AD5E
cmp     ax, 1A00h
jb      short loc_1B373
call    sub_1B7B2
cmp     ds:byte_1AD73, 0
jz      short loc_1B357
cmp     ax, 2A00h
jb      short loc_1B373

loc_1B357:
add     ax, 800h
mov     cl, 0Ch
shr     ax, cl
dec     ax
cmp     ds:byte_1AFAB, 0
jz      short loc_1B367
dec     ax

loc_1B367:
cmp     ax, 0
jz      short loc_1B373
mov     ds:word_1AD58, ax
clc
jmp     short loc_1B374
db 90h

loc_1B373:
stc

loc_1B374:
pop     cx
pop     bx
pop     ax
retn
sub_1B302 endp




CallInt67 proc near
push    ax

loc_1B379:              ;  - LIM EMS
int     67h
cmp     ah, 82h ; 'é'
jz      short loc_1B379
or      ah, ah
pop     ax
retn
CallInt67 endp




GetEMS proc near
push    ax
push    bx
push    dx
mov     ah, 41h ; 'A'   ; INT 67 - LIM EMS - GET PAGE FRAME SEGMENT
                        ;         AH = 41h
                        ; Return: AH = status (see also AH=40h)
                        ;             00h function successful
                        ;                 BX = segment of page frame
call    CallInt67
jnz     short loc_1B3D7
mov     ds:word_1AD68, bx
mov     ah, 42h ; 'B'   ; INT 67 - LIM EMS - GET NUMBER OF PAGES
                        ;         AH = 42h
                        ; Return: AH = status (see also AH=40h)
                        ;             00h function successful
                        ;                 BX = number of unallocated pages
                        ;                 DX = total number of pages
call    CallInt67
jnz     short loc_1B3D7
mov     ah, 43h ; 'C'   ; INT 67 - LIM EMS - GET HANDLE AND ALLOCATE MEMORY
                        ;         AH = 43h
                        ;         BX = number of logical pages to allocate
                        ; Return: AH = status (00h,80h,81h,84h,85h,87h,88h,89h) (see #3500)
                        ;         DX = handle if AH=00h
call    CallInt67
jnz     short loc_1B3D7
shr     bx, 1
shr     bx, 1
mov     ds:word_1AD6A, bx
mov     ds:word_1AD6C, dx
mov     ds:byte_1AD6E, 0
test    ds:word_1AD68, 0FFFh
jnz     short loc_1B3D3
push    ds
push    si
push    di
push    cx
mov     ax, seg seg002
mov     ds, ax
assume ds:seg002
call    sub_1C067
pop     cx
pop     di
pop     si
pop     ds
assume ds:nothing
cmp     ax, 0
jnz     short loc_1B3D3
mov     ds:byte_1AD6E, 1

loc_1B3D3:
clc
jmp     short loc_1B3DE
db 90h

loc_1B3D7:
mov     ds:word_1AD6A, 0
stc

loc_1B3DE:
pop     dx
pop     bx
pop     ax
retn
GetEMS endp

aEmmxxxx0 db 'EMMXXXX0'



CheckEMS proc near
push    ax
push    cx
push    si
push    di
push    es
mov     ah, 35h ; '5'
mov     al, 67h ; 'g'
int     21h             ; DOS - 2+ - GET INTERRUPT VECTOR
                        ; AL = interrupt number
                        ; Return: ES:BX = value of interrupt vector
mov     di, 0Ah
lea     si, aEmmxxxx0   ; "EMMXXXX0"
mov     cx, 8
cld
repe cmpsb
jz      short loc_1B408
stc
jmp     short loc_1B409
align 2

loc_1B408:
clc

loc_1B409:
pop     es
pop     di
pop     si
pop     cx
pop     ax
retn
CheckEMS endp




sub_1B40F proc near
push    bx
push    cx
push    dx
mov     bx, ax
xor     cx, cx
xor     dx, dx
mov     ah, 42h ; 'B'
mov     al, 2
int     21h             ; DOS - 2+ - MOVE FILE READ/WRITE POINTER (LSEEK)
                        ; AL = method: offset from end of file
inc     dx
mov     ax, dx
mov     ds:word_1AD7A, ax
pop     dx
pop     cx
pop     bx
retn
sub_1B40F endp




sub_1B428 proc near
push    bx
push    cx
push    dx
mov     dl, al
inc     dl
mov     ah, 36h
int     21h             ; DOS - 2+ - GET DISK SPACE
                        ; DL = drive code (0 = default, 1 = A, 2 = B, etc.)
cmp     ax, 0FFFFh
jz      short loc_1B441
mul     cx
mul     bx
mov     ax, dx
jmp     short loc_1B444
db 90h

loc_1B441:
mov     ax, 0

loc_1B444:
pop     dx
pop     cx
pop     bx
retn
sub_1B428 endp

push    bx
push    cx
push    dx
mov     dl, al
inc     dl
mov     ah, 36h
int     21h             ; DOS - 2+ - GET DISK SPACE
                        ; DL = drive code (0 = default, 1 = A, 2 = B, etc.)
cmp     ax, 0FFFFh
jz      short loc_1B464
push    dx
mul     cx
pop     dx
mul     dx
mov     ax, dx
clc
jmp     short loc_1B467
db  90h ; É

loc_1B464:
mov     ax, 0

loc_1B467:
pop     dx
pop     cx
pop     bx
retn



sub_1B46B proc near
push    ds
mov     ax, seg seg002
mov     ds, ax
assume ds:seg002
mov     al, cs:byte_1AD74
xor     ah, ah
push    ax
call    sub_1BA38
add     sp, 2
mov     cs:word_1AD54, ax
push    word_1D932
pop     cs:word_1AD52
pop     ds
assume ds:nothing
retn
sub_1B46B endp




sub_1B48D proc near
push    ds
mov     ax, seg seg002
mov     ds, ax
assume ds:seg002
mov     al, cs:byte_1AD76
xor     ah, ah
push    ax
call    sub_1B832
add     sp, 2
mov     cs:word_1AD54, ax
pop     ds
assume ds:nothing
retn
sub_1B48D endp




sub_1B4A6 proc near
push    ax
push    cx
push    dx
mov     ah, 3Ch ; '<'
xor     cx, cx
mov     dx, offset aC_Mm ; "C:$$$$$$$$.$MM"
mov     al, ds:byte_1AD8D
add     al, 41h ; 'A'
mov     byte ptr ds:aC_Mm, al ; "C:$$$$$$$$.$MM"
int     21h             ; DOS - 2+ - CREATE A FILE WITH HANDLE (CREAT)
                        ; CX = attributes for file
                        ; DS:DX -; ASCIZ filename (may include drive and path)
mov     ds:word_1AD54, ax
pop     dx
pop     cx
pop     ax
retn
sub_1B4A6 endp




sub_1B4C1 proc near
push    ax
push    es
cmp     ds:byte_1AD6E, 0
jnz     short loc_1B4EE
mov     es, ds:word_1AD5E
push    ds
mov     ds, ds:word_1AD68
call    sub_1B5B8
pop     ds
cmp     ds:byte_1AD72, 0
jz      short loc_1B4EE
cmp     ds:byte_1AD79, 2
jz      short loc_1B4EE
cmp     al, 0
jbe     short loc_1B4EE
dec     al
call    sub_1B597

loc_1B4EE:
pop     es
pop     ax
retn
sub_1B4C1 endp

; [00000001 BYTES: COLLAPSED FUNCTION nullsub_1. PRESS KEYPAD "+" TO EXPAND]



sub_1B4F2 proc near
push    ax
push    bx
push    cx
push    dx
mov     bx, ds:word_1AD54
mov     cx, 8000h
mov     dx, 0
push    ds
mov     ah, 3Fh ; '?'
push    es
pop     ds
assume ds:nothing
int     21h             ; DOS - 2+ - READ FROM FILE WITH HANDLE
                        ; BX = file handle, CX = number of bytes to read
                        ; DS:DX -; buffer
mov     ax, ds
add     ax, 800h
mov     ds, ax
assume ds:nothing
mov     ah, 3Fh
int     21h             ; DOS - 2+ - READ FROM FILE WITH HANDLE
                        ; BX = file handle, CX = number of bytes to read
                        ; DS:DX -; buffer
pop     ds
assume ds:nothing
pop     dx
pop     cx
pop     bx
pop     ax
retn
sub_1B4F2 endp




sub_1B518 proc near
push    ax
push    bx
push    cx
push    dx
xor     cx, cx
mov     cl, al
xor     dx, dx
mov     bx, ds:word_1AD54
xor     al, al
mov     ah, 42h
int     21h             ; DOS - 2+ - MOVE FILE READ/WRITE POINTER (LSEEK)
                        ; AL = method: offset from beginning of file
pop     dx
pop     cx
pop     bx
pop     ax
retn
sub_1B518 endp




sub_1B531 proc near
push    ds
push    es
cmp     ds:byte_1AD6E, 0
jnz     short loc_1B546
mov     es, cs:word_1AD68
mov     ds, ds:word_1AD5E
call    sub_1B5B8

loc_1B546:
pop     es
pop     ds
retn
sub_1B531 endp

; [00000001 BYTES: COLLAPSED FUNCTION nullsub_2. PRESS KEYPAD "+" TO EXPAND]



sub_1B54A proc near
push    ax
push    bx
push    cx
push    dx
cmp     ds:byte_1AD79, 0
jz      short loc_1B55F
cmp     ds:word_1AFA4, 0
ja      short loc_1B55F
call    sub_1B5CB

loc_1B55F:
mov     bx, ds:word_1AD54
mov     cx, 8000h
mov     dx, 0
push    ds
push    es
pop     ds
assume ds:nothing
mov     ah, 40h
int     21h             ; DOS - 2+ - WRITE TO FILE WITH HANDLE
                        ; BX = file handle, CX = number of bytes to write, DS:DX -; buffer
mov     ax, ds
add     ax, 800h
mov     ds, ax
assume ds:nothing
mov     ah, 40h
int     21h             ; DOS - 2+ - WRITE TO FILE WITH HANDLE
                        ; BX = file handle, CX = number of bytes to write, DS:DX -; buffer
pop     ds
assume ds:nothing
pop     dx
pop     cx
pop     bx
pop     ax
retn
sub_1B54A endp




sub_1B581 proc near
push    ax
push    bx
push    cx
mov     bx, cs:word_1AD62
mov     cl, 0Ch
shr     bx, cl
add     bl, al
shl     bx, cl
mov     es, bx
pop     cx
pop     bx
pop     ax
retn
sub_1B581 endp




sub_1B597 proc near
push    ax
push    bx
push    dx
xor     ah, ah
mov     bx, ax
shl     bx, 1
shl     bx, 1
mov     al, 0
mov     dx, ds:word_1AD6C
mov     ah, 44h ; 'D'

loc_1B5AA:
call    CallInt67
inc     al
inc     bx
cmp     al, 4
jl      short loc_1B5AA
pop     dx
pop     bx
pop     ax
retn
sub_1B597 endp




sub_1B5B8 proc near
push    cx
push    si
push    di
mov     si, 0
mov     di, 0
mov     cx, 8000h
cld
rep movsw
pop     di
pop     si
pop     cx
retn
sub_1B5B8 endp




sub_1B5CB proc near
push    ds
push    es
push    ax
push    cx
push    si
push    di
mov     cx, 80h ; 'Ç'
mov     ax, seg seg002
mov     ds, ax
assume ds:seg002
mov     si, offset word_1E2B2
mov     es, cs:word_1AD5E
mov     di, 0
cld
rep movsw
pop     di
pop     si
pop     cx
pop     ax
pop     es
pop     ds
assume ds:nothing
retn
sub_1B5CB endp




sub_1B5EE proc near
push    ax
push    bx
push    es
push    ds
push    si
push    di
push    cx
mov     ax, seg seg002
mov     ds, ax
assume ds:seg002
call    sub_1C08D
pop     cx
pop     di
pop     si
pop     ds
assume ds:nothing
mov     ax, word ptr ds:byte_1AD50
cmp     ax, ds:word_1AD52
jnz     short loc_1B61A
mov     al, ds:byte_1AD78
cmp     al, ds:byte_1AD76
jnz     short loc_1B61A
mov     cx, ds:word_1AFA2
jmp     loc_1B69D

loc_1B61A:
mov     cx, 0
cmp     ds:word_1AD58, 1
jbe     short loc_1B657
mov     al, 1
mov     ah, 0
cmp     ds:byte_1AD73, 0
jz      short loc_1B638
cmp     ds:word_1AD58, 2
jbe     short loc_1B657
mov     al, 2

loc_1B638:
call    sub_1B1E2
push    ax
mov     ax, cx
call    sub_1B518
pop     ax
call    sub_1B581
call    sub_1B4F2
inc     cx
cmp     cx, ds:word_1AD7A
jnb     short loc_1B69D
inc     al
cmp     al, byte ptr ds:word_1AD58
jb      short loc_1B638

loc_1B657:
cmp     ds:word_1AD68, 0
jz      short loc_1B68C
cmp     ds:word_1AD6A, 0
jz      short loc_1B68C
mov     ah, 2
mov     al, 0
mov     es, ds:word_1AD68

loc_1B66D:
call    sub_1B1E2
push    ax
mov     ax, cx
call    sub_1B518
pop     ax
call    sub_1B597
call    sub_1B4F2
inc     cx
cmp     cx, ds:word_1AD7A
jnb     short loc_1B69D
inc     al
cmp     al, byte ptr ds:word_1AD6A
jb      short loc_1B66D

loc_1B68C:
mov     ah, 1

loc_1B68E:
mov     al, cl
call    sub_1B1E2
inc     cx
cmp     cx, ds:word_1AD7A
jb      short loc_1B68E
jmp     short loc_1B69D
db 90h

loc_1B69D:
mov     ax, ds:word_1AD52
mov     word ptr ds:byte_1AD50, ax
mov     al, ds:byte_1AD76
mov     ds:byte_1AD78, al
push    ds
push    si
push    di
push    cx
mov     ax, seg seg002
mov     ds, ax
assume ds:seg002
call    sub_1C11E
pop     cx
pop     di
pop     si
pop     ds
assume ds:nothing
pop     es
pop     bx
pop     ax
retn
sub_1B5EE endp




sub_1B6BD proc near
push    ax
mov     word ptr ds:byte_1AD50, 0FFFFh
mov     cx, 0
mov     ah, 1

loc_1B6C9:
mov     al, cl
call    sub_1B1E2
inc     cx
cmp     cx, 100h
jnb     short loc_1B6DB
cmp     cx, ds:word_1AD7A
jb      short loc_1B6C9

loc_1B6DB:
pop     ax
retn
sub_1B6BD endp




GetInt24_2 proc near
push    ax
push    bx
push    dx
push    ds
push    es
mov     ah, 35h ; '5'
mov     al, 24h ; '$'
int     21h             ; DOS - 2+ - GET INTERRUPT VECTOR
                        ; AL = interrupt number
                        ; Return: ES:BX = value of interrupt vector
mov     cs:OldInt24Off2, bx
mov     cs:OldInt24Seg2, es
mov     dx, offset Int_24_Handler2
push    cs
pop     ds
assume ds:seg001
mov     ah, 25h ; '%'
mov     al, 24h ; '$'
int     21h             ; DOS - SET INTERRUPT VECTOR
                        ; AL = interrupt number
                        ; DS:DX = new vector to be used for specified interrupt
pop     es
pop     ds
assume ds:nothing
pop     dx
pop     bx
pop     ax
retn
GetInt24_2 endp


Int_24_Handler2:
mov     ax, 3
cmp     cs:DosMajorVer, 3
jnb     short locret_1B711
mov     ax, 0

locret_1B711:
iret



RestoreInt24_2 proc near
pushf
push    ax
push    dx
push    ds
mov     dx, cs:OldInt24Off2
mov     ds, cs:OldInt24Seg2
mov     ah, 25h ; '%'
mov     al, 24h ; '$'
int     21h             ; DOS - SET INTERRUPT VECTOR
                        ; AL = interrupt number
                        ; DS:DX = new vector to be used for specified interrupt
pop     ds
pop     dx
pop     ax
popf
retn
RestoreInt24_2 endp




sub_1B72B proc near
push    es
push    ax
push    di
mov     word ptr ds:byte_1AD50, 0FFFFh
mov     cx, 0
mov     al, 0
mov     di, 0ADA2h
push    cs
pop     es
assume es:seg001
cmp     ds:word_1AD58, 1
jbe     short loc_1B773
mov     al, 2
cmp     ds:byte_1AD73, 0
jnz     short loc_1B767
mov     al, 1
cmp     ds:byte_1AD72, 0
jnz     short loc_1B767
cmp     ds:byte_1AD6E, 0
jz      short loc_1B767
cmp     ds:byte_1AD7D, 0
jz      short loc_1B767
mov     al, 0

loc_1B767:
mov     ah, 0

loc_1B769:
stosw
inc     cx
inc     al
cmp     al, byte ptr ds:word_1AD58
jb      short loc_1B769

loc_1B773:
cmp     ds:word_1AD68, 0
jz      short loc_1B78F
cmp     ds:word_1AD6A, 0
jz      short loc_1B78F
mov     ah, 2
mov     al, 0

loc_1B785:
stosw
inc     cx
inc     al
cmp     al, byte ptr ds:word_1AD6A
jb      short loc_1B785

loc_1B78F:
cmp     ds:byte_1AD7D, 0
jnz     short loc_1B7AE
cmp     ds:word_1AD8E, 0
jz      short loc_1B7AE
call    sub_1B4A6
mov     ah, 1
mov     al, 0

loc_1B7A4:
stosw
inc     cx
inc     al
cmp     al, byte ptr ds:word_1AD8E
jb      short loc_1B7A4

loc_1B7AE:
pop     di
pop     ax
pop     es
assume es:nothing
retn
sub_1B72B endp




sub_1B7B2 proc near
push    ax
cmp     ds:byte_1AD72, 0
jz      short loc_1B7F0
push    ds:word_1AD5E
pop     ds:word_1AD66
push    ds:word_1AD5E
pop     word ptr ds:byte_1AD64
add     word ptr ds:byte_1AD64, 1000h
mov     ds:byte_1AD73, 1
mov     ax, ds:word_1AD6A
cmp     ax, ds:word_1AD7A
jb      short loc_1B7F0
cmp     ds:byte_1AD6E, 0
jz      short loc_1B7F0
mov     ds:byte_1AD73, 0
mov     ax, ds:word_1AD68
mov     word ptr ds:byte_1AD64, ax

loc_1B7F0:
pop     ax
retn
sub_1B7B2 endp




sub_1B7F2 proc near
push    ax
cmp     ds:byte_1AD79, 2
jz      short loc_1B830
cmp     ds:byte_1AD72, 0
jz      short loc_1B830
push    ds:word_1AD66
push    word ptr ds:byte_1AD64
pop     ds:word_1AD66
pop     word ptr ds:byte_1AD64
mov     es, word ptr ds:byte_1AD64
mov     ds:word_1AD5E, es
mov     ds:byte_1AD6E, 0
mov     ax, es
cmp     ax, ds:word_1AD68
jnz     short loc_1B830
test    ax, 0FFFh
jnz     short loc_1B830
mov     ds:byte_1AD6E, 1

loc_1B830:
pop     ax
retn
sub_1B7F2 endp



; Attributes: bp-based frame

sub_1B832 proc near

var_6= word ptr -6
var_4= word ptr -4
var_2= word ptr -2
arg_0= word ptr  4

push    bp
mov     bp, sp
mov     ax, 6
call    __chkstk
mov     ds:word_1E2B2, 0A55Ah
mov     ax, ds:word_1D936
inc     ds:word_1D936
or      ax, ax
jnz     short loc_1B8AD
mov     ax, 2
push    ax
call    sub_1BFA8
add     sp, 2
mov     bx, ax
mov     [bp+var_4], bx
cmp     byte ptr [bx], 0
jz      short loc_1B8AD
push    bx
push    [bp+arg_0]
call    sub_1BB88
add     sp, 4
mov     [bp+var_6], ax
push    ax
call    sub_1C268
add     sp, 2
mov     [bp+var_2], ax
or      ax, ax
jle     short loc_1B884
push    ax
call    _close
add     sp, 2
jmp     short loc_1B8AD

loc_1B884:
push    [bp+var_6]
call    sub_1C2BD
add     sp, 2
mov     [bp+var_2], ax
or      ax, ax
jle     short loc_1B8AD
push    [bp+var_4]
mov     ax, 48h ; 'H'
push    ax
call    _strcpy
add     sp, 4
mov     ds:byte_1E2B4, 0
mov     ds:byte_1E2D4, 0
jmp     short loc_1B8B9

loc_1B8AD:
push    [bp+arg_0]
call    sub_1B8C6
add     sp, 2
mov     [bp+var_2], ax

loc_1B8B9:
mov     ds:word_10044, 1
mov     ax, [bp+var_2]
mov     sp, bp
pop     bp
retn
sub_1B832 endp



; Attributes: bp-based frame

sub_1B8C6 proc near

var_12= byte ptr -12h
var_10= byte ptr -10h
var_6= word ptr -6
var_4= word ptr -4
var_2= word ptr -2
arg_0= word ptr  4

push    bp
mov     bp, sp
mov     ax, 12h
call    __chkstk
mov     [bp+var_4], 0FFFFh
call    sub_1C23E
mov     ax, 0A04h
push    ax
mov     ax, 48h ; 'H'
push    ax
mov     ax, 11h
push    ax
mov     ax, 19h
push    ax
mov     ax, 5
push    ax
call    sub_1C1D7
add     sp, 0Ah
push    [bp+arg_0]
call    sub_1BEC1
add     sp, 2
call    sub_1BDF1
mov     ax, 6Ah ; 'j'
push    ax
mov     ax, 0Fh
push    ax
call    sub_1BBF6
add     sp, 4

loc_1B90B:
mov     ax, 8
push    ax
lea     ax, [bp+var_10]
push    ax
mov     ax, 32h ; '2'
push    ax
mov     ax, 0Fh
push    ax
call    sub_1C3CA
add     sp, 8
mov     [bp+var_2], ax
lea     ax, [bp+var_10]
mov     [bp+var_6], ax
jmp     short loc_1B940

loc_1B92C:
mov     al, [bp+var_12]
cbw
mov     bx, ax
test    byte ptr ds:asc_1EC89[bx], 7 ; "         (((((                  H"
jnz     short loc_1B93D
cmp     al, 5Fh ; '_'
jnz     short loc_1B94C

loc_1B93D:
inc     [bp+var_6]

loc_1B940:
mov     bx, [bp+var_6]
mov     al, [bx]
mov     [bp+var_12], al
or      al, al
jnz     short loc_1B92C

loc_1B94C:
mov     bx, [bp+var_6]
cmp     byte ptr [bx], 0
jz      short loc_1B95E
mov     ax, offset aBadFilename ; "Bad Filename"
push    ax
call    sub_1C147
add     sp, 2

loc_1B95E:
mov     bx, [bp+var_6]
cmp     byte ptr [bx], 0
jnz     short loc_1B90B
cmp     [bp+var_2], 0
jg      short loc_1B96F
jmp     loc_1BA06

loc_1B96F:
lea     ax, [bp+var_10]
push    ax
call    _strupr
add     sp, 2
lea     ax, [bp+var_10]
push    ax
push    [bp+arg_0]
call    sub_1BB88
add     sp, 4
mov     [bp+var_6], ax
push    ax
call    sub_1C268
add     sp, 2
mov     [bp+var_4], ax
or      ax, ax
jle     short loc_1B9AF
push    ax
call    sub_1C27F
add     sp, 2
mov     ax, offset aFileExists ; "File Exists"
push    ax
call    sub_1C147
add     sp, 2
mov     [bp+var_4], 0FFFFh
jmp     short loc_1BA06

loc_1B9AF:
push    [bp+var_6]
call    sub_1C2BD
add     sp, 2
mov     [bp+var_4], ax
cmp     ax, 0FFFFh
jnz     short loc_1B9CC
mov     ax, offset aCreateFailure ; "Create Failure"
push    ax
call    sub_1C147
add     sp, 2
jmp     short loc_1BA06

loc_1B9CC:              ; "Info;"
mov     ax, offset aInfo
push    ax
mov     ax, 0Fh
push    ax
call    sub_1BBF6
add     sp, 4
mov     ax, 1Fh
push    ax
mov     ax, 9C4h
push    ax
mov     ax, 21h ; '!'
push    ax
mov     ax, 0Fh
push    ax
call    sub_1C3CA
add     sp, 8
mov     ax, 1Fh
push    ax
mov     ax, 9E4h
push    ax
mov     ax, 21h ; '!'
push    ax
mov     ax, 10h
push    ax
call    sub_1C3CA
add     sp, 8

loc_1BA06:
mov     ax, 0A04h
push    ax
mov     ax, 48h ; 'H'
push    ax
mov     ax, 11h
push    ax
mov     ax, 19h
push    ax
mov     ax, 5
push    ax
call    sub_1C208
add     sp, 0Ah
call    sub_1C254
lea     ax, [bp+var_10]
push    ax
mov     ax, 48h ; 'H'
push    ax
call    _strcpy
add     sp, 4
mov     ax, [bp+var_4]
mov     sp, bp
pop     bp
retn
sub_1B8C6 endp



; Attributes: bp-based frame

sub_1BA38 proc near

var_4= word ptr -4
var_2= word ptr -2
arg_0= word ptr  4

push    bp
mov     bp, sp
mov     ax, 4
call    __chkstk
mov     ax, ds:word_1D936
inc     ds:word_1D936
or      ax, ax
jnz     short loc_1BABB
mov     ax, 1
push    ax
call    sub_1BFA8
add     sp, 2
mov     bx, ax
mov     [bp+var_4], bx
cmp     byte ptr [bx], 0
jz      short loc_1BABB
push    bx
push    [bp+arg_0]
call    sub_1BB88
add     sp, 4
push    ax
call    sub_1C268
add     sp, 2
mov     [bp+var_2], ax
or      ax, ax
jle     short loc_1BABB
push    [bp+var_4]
mov     ax, 48h ; 'H'
push    ax
call    _strcpy
add     sp, 4
push    [bp+arg_0]
call    sub_1BEC1
add     sp, 2
mov     ds:word_1D932, 0

loc_1BA94:
mov     ax, ds:EndOfCurrTrk+1
cmp     ds:word_1D932, ax
jge     short loc_1BAC7
mov     ax, 4Ah ; 'J'
imul    ds:word_1D932
add     ax, 82h ; 'é'
push    ax
push    [bp+var_4]
call    _strcmpi
add     sp, 4
or      ax, ax
jz      short loc_1BAC7
inc     ds:word_1D932
jmp     short loc_1BA94

loc_1BABB:
push    [bp+arg_0]
call    sub_1BACE
add     sp, 2
mov     [bp+var_2], ax

loc_1BAC7:
mov     ax, [bp+var_2]
mov     sp, bp
pop     bp
retn
sub_1BA38 endp



; Attributes: bp-based frame

sub_1BACE proc near

var_4= word ptr -4
var_2= word ptr -2
arg_0= word ptr  4

push    bp
mov     bp, sp
mov     ax, 4
call    __chkstk
mov     [bp+var_2], 0FFFFh
call    sub_1C23E
mov     ax, 0A04h
push    ax
mov     ax, 48h ; 'H'
push    ax
mov     ax, 11h
push    ax
mov     ax, 19h
push    ax
mov     ax, 5
push    ax
call    sub_1C1D7
add     sp, 0Ah
push    [bp+arg_0]
call    sub_1BEC1
add     sp, 2
call    sub_1BDF1
cmp     ds:word_1D930, 0
jle     short loc_1BB14
call    sub_1BD04
mov     [bp+var_4], ax
jmp     short loc_1BB1E

loc_1BB14:              ; "No Image Available"
mov     ax, offset aNoImageAvailab
push    ax
call    sub_1C147
add     sp, 2

loc_1BB1E:
cmp     [bp+var_4], 0
jl      short loc_1BB49
cmp     ds:word_1D932, 0
jl      short loc_1BB49
mov     ax, 4Ah ; 'J'
imul    ds:word_1D932
add     ax, 82h ; 'é'
push    ax
push    [bp+arg_0]
call    sub_1BB88
add     sp, 4
push    ax
call    sub_1C268
add     sp, 2
mov     [bp+var_2], ax

loc_1BB49:
mov     ax, 0A04h
push    ax
mov     ax, 48h ; 'H'
push    ax
mov     ax, 11h
push    ax
mov     ax, 19h
push    ax
mov     ax, 5
push    ax
call    sub_1C208
add     sp, 0Ah
call    sub_1C254
mov     ds:word_1D934, 0
mov     ax, 4Ah ; 'J'
imul    ds:word_1D932
add     ax, 82h ; 'é'
push    ax
mov     ax, 48h ; 'H'
push    ax
call    _strcpy
add     sp, 4
mov     ax, [bp+var_2]
mov     sp, bp
pop     bp
retn
sub_1BACE endp



; Attributes: bp-based frame

sub_1BB88 proc near

arg_0= word ptr  4
arg_2= word ptr  6

push    bp
mov     bp, sp
xor     ax, ax
call    __chkstk
push    [bp+arg_2]
mov     ax, [bp+arg_0]
add     ax, 41h ; 'A'
push    ax
mov     ax, offset aCS_img ; "%c:%s.IMG"
push    ax
mov     ax, 5Ah ; 'Z'
push    ax
call    _sprintf
add     sp, 8
mov     ax, 5Ah ; 'Z'
mov     sp, bp
pop     bp
retn
sub_1BB88 endp



; Attributes: bp-based frame

sub_1BBAF proc near

var_2= word ptr -2

push    bp
mov     bp, sp
mov     ax, 2
call    __chkstk
cmp     ds:word_10044, 0
jnz     short loc_1BBC6
mov     [bp+var_2], 5
jmp     short loc_1BBCB

loc_1BBC6:
mov     [bp+var_2], 6

loc_1BBCB:              ; ":"
mov     ax, offset asc_1E81F
push    ax
mov     ax, 7
push    ax
mov     ax, 14h
push    ax
push    [bp+var_2]
call    sub_1C180
add     sp, 8
mov     ax, 48h ; 'H'
push    ax
mov     ax, 7
push    ax
mov     ax, 15h
push    ax
push    [bp+var_2]
call    sub_1C180
mov     sp, bp
pop     bp
retn
sub_1BBAF endp



; Attributes: bp-based frame

sub_1BBF6 proc near

arg_0= word ptr  4
arg_2= word ptr  6

push    bp
mov     bp, sp
xor     ax, ax
call    __chkstk
push    [bp+arg_0]
call    sub_1BCE6
add     sp, 2
push    [bp+arg_2]
mov     ax, 7
push    ax
mov     ax, 1Bh
push    ax
push    [bp+arg_0]
call    sub_1C180
mov     sp, bp
pop     bp
retn
sub_1BBF6 endp



; Attributes: bp-based frame

sub_1BC1C proc near

var_4= word ptr -4
var_2= word ptr -2
arg_0= word ptr  4
arg_2= word ptr  6

push    bp
mov     bp, sp
mov     ax, 4
call    __chkstk
mov     ax, [bp+arg_0]
cwd
xor     ax, dx
sub     ax, dx
mov     cx, 2
sar     ax, cl
xor     ax, dx
sub     ax, dx
add     ax, 6
mov     [bp+var_2], ax
mov     ax, [bp+arg_0]
cwd
mov     cx, 4
idiv    cx
mov     ax, dx
shl     dx, 1
shl     dx, 1
add     dx, ax
shl     dx, 1
add     dx, 1Dh
mov     [bp+var_4], dx
mov     ax, 4Ah ; 'J'
imul    [bp+arg_0]
add     ax, 82h ; 'é'
push    ax
cmp     [bp+arg_2], 0
jz      short loc_1BC6A
mov     ax, 0Fh
jmp     short loc_1BC6D

loc_1BC6A:
mov     ax, 7

loc_1BC6D:
push    ax
push    [bp+var_4]
push    [bp+var_2]
call    sub_1C180
mov     sp, bp
pop     bp
retn
sub_1BC1C endp



; Attributes: bp-based frame

sub_1BC7B proc near

arg_0= word ptr  4

push    bp
mov     bp, sp
xor     ax, ax
call    __chkstk
mov     ax, 0Fh
push    ax
call    sub_1BCE6
add     sp, 2
mov     ax, offset aInfo_0 ; "Info ;"
push    ax
mov     ax, 7
push    ax
mov     ax, 1Bh
push    ax
mov     ax, 0Fh
push    ax
call    sub_1C180
add     sp, 8
mov     ax, 4Ah ; 'J'
imul    [bp+arg_0]
add     ax, 8Ch ; 'î'
push    ax
mov     ax, 0Fh
push    ax
mov     ax, 25h ; '%'
push    ax
mov     ax, 0Fh
push    ax
call    sub_1C180
add     sp, 8
mov     ax, 10h
push    ax
call    sub_1BCE6
add     sp, 2
mov     ax, 4Ah ; 'J'
imul    [bp+arg_0]
add     ax, 0ACh ; '¼'
push    ax
mov     ax, 0Fh
push    ax
mov     ax, 25h ; '%'
push    ax
mov     ax, 10h
push    ax
call    sub_1C180
mov     sp, bp
pop     bp
retn
sub_1BC7B endp



; Attributes: bp-based frame

sub_1BCE6 proc near

arg_0= word ptr  4

push    bp
mov     bp, sp
xor     ax, ax
call    __chkstk
mov     ax, 1018h
push    ax
mov     ax, 7
push    ax
mov     ax, 19h
push    ax
push    [bp+arg_0]
call    sub_1C180
mov     sp, bp
pop     bp
retn
sub_1BCE6 endp



; Attributes: bp-based frame

sub_1BD04 proc near

var_4= word ptr -4
var_2= word ptr -2

push    bp
mov     bp, sp
mov     ax, 4
call    __chkstk
mov     ax, ds:word_1D930
cmp     ds:word_1D932, ax
jl      short loc_1BD1A
dec     ax
mov     ds:word_1D932, ax

loc_1BD1A:
push    ds:word_1D932
call    sub_1BC7B
add     sp, 2
mov     ax, 1
push    ax
push    ds:word_1D932
call    sub_1BC1C
add     sp, 4

loc_1BD32:
call    sub_1C1AF
mov     [bp+var_2], ax
mov     al, byte ptr [bp+var_2]
sub     ah, ah
mov     [bp+var_4], ax
sub     ax, ax
push    ax
push    ds:word_1D932
call    sub_1BC1C
add     sp, 4
mov     ax, [bp+var_2]
mov     cl, 8
sar     ax, cl
cmp     ax, 44h ; 'D'
jnz     short loc_1BD5C
jmp     loc_1BDEA

loc_1BD5C:
cmp     ax, 48h ; 'H'
jz      short loc_1BD78
cmp     ax, 4Bh ; 'K'
jz      short loc_1BDD7
cmp     ax, 4Dh ; 'M'
jz      short loc_1BDB9
cmp     ax, 50h ; 'P'
jz      short loc_1BDA6
cmp     [bp+var_4], 1Bh
jnz     short loc_1BD84
jmp     short loc_1BDEA

loc_1BD78:
cmp     ds:word_1D932, 4
jl      short loc_1BD84
sub     ds:word_1D932, 4

loc_1BD84:
mov     ax, 1
push    ax
push    ds:word_1D932
call    sub_1BC1C
add     sp, 4
push    ds:word_1D932
call    sub_1BC7B
add     sp, 2
cmp     [bp+var_4], 0Dh
jnz     short loc_1BD32
sub     ax, ax
jmp     short loc_1BDED

loc_1BDA6:
mov     ax, ds:word_1D932
add     ax, 4
cmp     ax, ds:word_1D930
jge     short loc_1BD84
add     ds:word_1D932, 4
jmp     short loc_1BD84

loc_1BDB9:
mov     ax, ds:word_1D932
cwd
mov     cx, 4
idiv    cx
cmp     dx, 3
jge     short loc_1BD84
mov     ax, ds:word_1D930
dec     ax
cmp     ax, ds:word_1D932
jle     short loc_1BD84
inc     ds:word_1D932
jmp     short loc_1BD84

loc_1BDD7:
mov     ax, ds:word_1D932
cwd
mov     cx, 4
idiv    cx
or      dx, dx
jle     short loc_1BD84
dec     ds:word_1D932
jmp     short loc_1BD84

loc_1BDEA:
mov     ax, 0FFFFh

loc_1BDED:
mov     sp, bp
pop     bp
retn
sub_1BD04 endp



; Attributes: bp-based frame

sub_1BDF1 proc near

var_2= word ptr -2

push    bp
mov     bp, sp
mov     ax, 2
call    __chkstk
call    sub_1BE26
cmp     ds:word_1D930, 0
jle     short loc_1BE22
mov     [bp+var_2], 0
jmp     short loc_1BE1A

loc_1BE0B:
sub     ax, ax
push    ax
push    [bp+var_2]
call    sub_1BC1C
add     sp, 4
inc     [bp+var_2]

loc_1BE1A:
mov     ax, ds:word_1D930
cmp     [bp+var_2], ax
jl      short loc_1BE0B

loc_1BE22:
mov     sp, bp
pop     bp
retn
sub_1BDF1 endp



; Attributes: bp-based frame

sub_1BE26 proc near

var_2= word ptr -2

push    bp
mov     bp, sp
mov     ax, 2
call    __chkstk
mov     ax, offset asc_1E8D8 ; "+--------------------------------------"...
push    ax
mov     ax, 7
push    ax
mov     ax, 19h
push    ax
mov     ax, 5
push    ax
call    sub_1C180
add     sp, 8
mov     [bp+var_2], 6

loc_1BE4A:              ; "¦                                      "...
mov     ax, offset asc_1E908
push    ax
mov     ax, 7
push    ax
mov     ax, 19h
push    ax
push    [bp+var_2]
call    sub_1C180
add     sp, 8
inc     [bp+var_2]
cmp     [bp+var_2], 0Eh
jl      short loc_1BE4A
mov     ax, offset asc_1E938 ; "¦--------------------------------------"...
push    ax
mov     ax, 7
push    ax
mov     ax, 19h
push    ax
mov     ax, 0Eh
push    ax
call    sub_1C180
add     sp, 8
mov     ax, offset asc_1E908 ; "¦                                      "...
push    ax
mov     ax, 7
push    ax
mov     ax, 19h
push    ax
mov     ax, 0Fh
push    ax
call    sub_1C180
add     sp, 8
mov     ax, offset asc_1E908 ; "¦                                      "...
push    ax
mov     ax, 7
push    ax
mov     ax, 19h
push    ax
mov     ax, 10h
push    ax
call    sub_1C180
add     sp, 8
mov     ax, offset asc_1E968 ; "+--------------------------------------"...
push    ax
mov     ax, 7
push    ax
mov     ax, 19h
push    ax
mov     ax, 11h
push    ax
call    sub_1C180
mov     sp, bp
pop     bp
retn
sub_1BE26 endp



; Attributes: bp-based frame

sub_1BEC1 proc near

var_16= byte ptr -16h
var_14= word ptr -14h
var_12= word ptr -12h
var_E= byte ptr -0Eh
var_4= word ptr -4
var_2= word ptr -2
arg_0= byte ptr  4

push    bp
mov     bp, sp
mov     ax, 16h
call    __chkstk
push    si
mov     ds:word_1D930, 0
mov     al, [bp+arg_0]
add     al, 41h ; 'A'
mov     byte ptr ds:aC_img, al ; "C:*.IMG"
mov     ax, 52h ; 'R'
push    ax
call    __dos_findfirst
add     sp, 2
mov     [bp+var_12], ax
jmp     loc_1BF9A

loc_1BEE9:
cmp     ds:word_1D930, 20h ; ' '
jl      short loc_1BEF3
jmp     loc_1BFA3

loc_1BEF3:
lea     ax, [bp+var_E]
mov     [bp+var_14], ax
mov     ax, 4Ah ; 'J'
imul    ds:word_1D930
add     ax, 82h ; 'é'
mov     [bp+var_2], ax
jmp     short loc_1BF1E

loc_1BF08:
cmp     [bp+var_16], 2Eh ; '.'
jz      short loc_1BF2A
mov     bx, [bp+var_14]
inc     [bp+var_14]
mov     si, [bp+var_12]
inc     [bp+var_12]
mov     al, [si]
mov     [bx], al

loc_1BF1E:
mov     bx, [bp+var_12]
mov     al, [bx]
mov     [bp+var_16], al
or      al, al
jnz     short loc_1BF08

loc_1BF2A:
mov     bx, [bp+var_14]
mov     byte ptr [bx], 0
lea     ax, [bp+var_E]
push    ax
push    word ptr [bp+arg_0]
call    sub_1BB88
add     sp, 4
push    ax
call    sub_1C268
add     sp, 2
mov     [bp+var_4], ax
mov     ax, 42h ; 'B'
push    ax
mov     ax, offset word_1E2B2
push    ax
push    [bp+var_4]
call    sub_1C28D
add     sp, 6
lea     ax, [bp+var_E]
push    ax
push    [bp+var_2]
call    _strcpy
add     sp, 4
mov     ax, offset byte_1E2B4
push    ax
mov     ax, [bp+var_2]
add     ax, 0Ah
push    ax
call    _strcpy
add     sp, 4
mov     ax, offset byte_1E2D4
push    ax
mov     ax, [bp+var_2]
add     ax, 2Ah ; '*'
push    ax
call    _strcpy
add     sp, 4
push    [bp+var_4]
call    sub_1C27F
add     sp, 2
call    sub_1C2FA
mov     [bp+var_12], ax
inc     ds:word_1D930

loc_1BF9A:
cmp     [bp+var_12], 0
jz      short loc_1BFA3
jmp     loc_1BEE9

loc_1BFA3:
pop     si
mov     sp, bp
pop     bp
retn
sub_1BEC1 endp



; Attributes: bp-based frame

sub_1BFA8 proc near

var_6= byte ptr -6
var_4= word ptr -4
var_2= word ptr -2
arg_0= word ptr  4

push    bp
mov     bp, sp
mov     ax, 6
call    __chkstk
mov     [bp+var_4], 0
call    sub_1C317
mov     [bp+var_2], ax
jmp     short loc_1C00E

loc_1BFBE:
mov     ax, [bp+arg_0]
dec     [bp+arg_0]
or      ax, ax
jz      short loc_1C016
jmp     short loc_1BFD3

loc_1BFCA:
cmp     [bp+var_6], 3Ah ; ':'
jz      short loc_1BFDF
inc     [bp+var_2]

loc_1BFD3:
mov     bx, [bp+var_2]
mov     al, [bx]
mov     [bp+var_6], al
or      al, al
jnz     short loc_1BFCA

loc_1BFDF:
mov     bx, [bp+var_2]
cmp     byte ptr [bx], 0
jz      short loc_1C00E
inc     [bp+var_2]
mov     ax, [bp+var_2]
mov     [bp+var_4], ax
jmp     short loc_1C002

loc_1BFF2:
mov     al, [bp+var_6]
cbw
mov     bx, ax
test    byte ptr ds:asc_1EC89[bx], 7 ; "         (((((                  H"
jz      short loc_1C00E
inc     [bp+var_2]

loc_1C002:
mov     bx, [bp+var_2]
mov     al, [bx]
mov     [bp+var_6], al
or      al, al
jnz     short loc_1BFF2

loc_1C00E:
mov     bx, [bp+var_2]
cmp     byte ptr [bx], 0
jnz     short loc_1BFBE

loc_1C016:
mov     bx, [bp+var_2]
mov     byte ptr [bx], 0
mov     ax, [bp+var_4]
mov     sp, bp
pop     bp
retn
sub_1BFA8 endp



; Attributes: bp-based frame

sub_1C023 proc near

var_2= word ptr -2
arg_0= word ptr  4

push    bp
mov     bp, sp
mov     ax, 2
call    __chkstk
call    sub_1C317
mov     [bp+var_2], ax
jmp     short loc_1C055

loc_1C034:
mov     bx, [bp+var_2]
cmp     byte ptr [bx], 2Fh ; '/'
jnz     short loc_1C055
mov     ax, 2
push    ax
mov     ax, bx
inc     ax
push    ax
push    [bp+arg_0]
call    _strnicmp
add     sp, 6
or      ax, ax
jnz     short loc_1C055
sub     ax, ax
jmp     short loc_1C063

loc_1C055:
mov     bx, [bp+var_2]
inc     [bp+var_2]
cmp     byte ptr [bx], 0
jnz     short loc_1C034
mov     ax, 0FFFFh

loc_1C063:
mov     sp, bp
pop     bp
retn
sub_1C023 endp



; Attributes: bp-based frame

sub_1C067 proc near
push    bp
mov     bp, sp
xor     ax, ax
call    __chkstk
mov     ax, offset aDm  ; "DM"
push    ax
call    sub_1C023
mov     sp, bp
pop     bp
retn
sub_1C067 endp

push    bp
mov     bp, sp
xor     ax, ax
call    __chkstk
mov     ax, offset aCr  ; "CR"
push    ax
call    sub_1C023
mov     sp, bp
pop     bp
retn


; Attributes: bp-based frame

sub_1C08D proc near

var_50= byte ptr -50h

push    bp
mov     bp, sp
mov     ax, 50h ; 'P'
call    __chkstk
call    sub_1C23E
mov     ax, 0A04h
push    ax
mov     ax, 48h ; 'H'
push    ax
mov     ax, 8
push    ax
mov     ax, 19h
push    ax
mov     ax, 5
push    ax
call    sub_1C1D7
add     sp, 0Ah
mov     ax, offset asc_1E8D8 ; "+--------------------------------------"...
push    ax
mov     ax, 7
push    ax
mov     ax, 19h
push    ax
mov     ax, 5
push    ax
call    sub_1C180
add     sp, 8
mov     ax, offset asc_1E908 ; "¦                                      "...
push    ax
mov     ax, 7
push    ax
mov     ax, 19h
push    ax
mov     ax, 6
push    ax
call    sub_1C180
add     sp, 8
mov     ax, offset asc_1E968 ; "+--------------------------------------"...
push    ax
mov     ax, 7
push    ax
mov     ax, 19h
push    ax
mov     ax, 7
push    ax
call    sub_1C180
add     sp, 8
mov     ax, 48h ; 'H'
push    ax
mov     ax, offset aLoadingImageS_ ; "Loading Image %s ..."
push    ax
lea     ax, [bp+var_50]
push    ax
call    _sprintf
add     sp, 6
lea     ax, [bp+var_50]
push    ax
mov     ax, 7
push    ax
mov     ax, 1Bh
push    ax
mov     ax, 6
push    ax
call    sub_1C180
mov     sp, bp
pop     bp
retn
sub_1C08D endp



; Attributes: bp-based frame

sub_1C11E proc near
push    bp
mov     bp, sp
xor     ax, ax
call    __chkstk
mov     ax, 0A04h
push    ax
mov     ax, 48h ; 'H'
push    ax
mov     ax, 8
push    ax
mov     ax, 19h
push    ax
mov     ax, 5
push    ax
call    sub_1C208
add     sp, 0Ah
call    sub_1C254
mov     sp, bp
pop     bp
retn
sub_1C11E endp



; Attributes: bp-based frame

sub_1C147 proc near

var_30= byte ptr -30h
arg_0= word ptr  4

push    bp
mov     bp, sp
mov     ax, 30h ; '0'
call    __chkstk
call    Beep2
push    [bp+arg_0]
mov     ax, offset aSEnterToContin ; "%s - [Enter] To Continue"
push    ax
lea     ax, [bp+var_30]
push    ax
call    _sprintf
add     sp, 6
lea     ax, [bp+var_30]
push    ax
mov     ax, 10h
push    ax
call    sub_1BBF6
add     sp, 4
call    sub_1C396
mov     ax, 10h
push    ax
call    sub_1BCE6
mov     sp, bp
pop     bp
retn
sub_1C147 endp



; Attributes: bp-based frame

sub_1C180 proc near

arg_0= byte ptr  4
arg_2= byte ptr  6
arg_4= byte ptr  8
arg_6= word ptr  0Ah

push    bp
mov     bp, sp
push    si
mov     si, [bp+arg_6]
mov     dh, [bp+arg_0]
mov     dl, [bp+arg_2]
cmp     byte ptr [si], 0
jz      short loc_1C1AC

loc_1C192:
mov     bh, 0
mov     ah, 2
int     10h             ; - VIDEO - SET CURSOR POSITION
                        ; DH,DL = row, column (0,0 = upper left)
                        ; BH = page number
mov     bl, [bp+arg_4]
mov     al, [si]
mov     cx, 1
mov     ah, 9
int     10h             ; - VIDEO - WRITE ATTRIBUTES/CHARACTERS AT CURSOR POSITION
                        ; AL = character, BH = display page
                        ; BL = attributes of character (alpha modes) or color (graphics modes)
                        ; CX = number of times to write character
inc     dl
inc     si
cmp     byte ptr [si], 0
jnz     short loc_1C192

loc_1C1AC:
pop     si
pop     bp
retn
sub_1C180 endp




sub_1C1AF proc near
mov     ah, 0
int     16h             ; KEYBOARD - READ CHAR FROM BUFFER, WAIT IF EMPTY
                        ; Return: AH = scan code, AL = character
retn
sub_1C1AF endp



; Attributes: bp-based frame

sub_1C1B4 proc near

arg_0= byte ptr  4
arg_2= byte ptr  6
arg_4= byte ptr  8

push    bp
mov     bp, sp
push    bx
push    cx
push    dx
mov     dh, [bp+arg_0]
mov     dl, [bp+arg_2]
mov     bh, 0
mov     ah, 2
int     10h             ; - VIDEO - SET CURSOR POSITION
                        ; DH,DL = row, column (0,0 = upper left)
                        ; BH = page number
mov     al, [bp+arg_4]
mov     bl, 7
mov     cx, 1
mov     ah, 9
int     10h             ; - VIDEO - WRITE ATTRIBUTES/CHARACTERS AT CURSOR POSITION
                        ; AL = character, BH = display page
                        ; BL = attributes of character (alpha modes) or color (graphics modes)
                        ; CX = number of times to write character
pop     dx
pop     cx
pop     bx
pop     bp
retn
sub_1C1B4 endp



; Attributes: bp-based frame

sub_1C1D7 proc near

arg_0= byte ptr  4
arg_2= byte ptr  6
arg_4= byte ptr  8
arg_6= byte ptr  0Ah
arg_8= word ptr  0Ch

push    bp
mov     bp, sp
push    bx
push    dx
push    di
push    es
push    ds
pop     es
assume es:nothing
mov     dh, [bp+arg_0]
mov     di, [bp+arg_8]
mov     bh, 0

loc_1C1E8:
mov     dl, [bp+arg_2]

loc_1C1EB:
mov     ah, 2
int     10h             ; - VIDEO - SET CURSOR POSITION
                        ; DH,DL = row, column (0,0 = upper left)
                        ; BH = page number
mov     ah, 8
int     10h             ; - VIDEO - READ ATTRIBUTES/CHARACTER AT CURSOR POSITION
                        ; BH = display page
                        ; Return: AL = character
                        ; AH = attribute of character (alpha modes)
stosw
inc     dl
cmp     [bp+arg_6], dl
ja      short loc_1C1EB
inc     dh
cmp     [bp+arg_4], dh
jge     short loc_1C1E8
pop     es
assume es:nothing
pop     di
pop     dx
pop     bx
pop     bp
retn
sub_1C1D7 endp



; Attributes: bp-based frame

sub_1C208 proc near

arg_0= byte ptr  4
arg_2= byte ptr  6
arg_4= byte ptr  8
arg_6= byte ptr  0Ah
arg_8= word ptr  0Ch

push    bp
mov     bp, sp
push    bx
push    cx
push    dx
push    si
mov     dh, [bp+arg_0]
mov     si, [bp+arg_8]
mov     bh, 0
mov     cx, 1

loc_1C21A:
mov     dl, [bp+arg_2]

loc_1C21D:
mov     bh, 0
mov     ah, 2
int     10h             ; - VIDEO - SET CURSOR POSITION
                        ; DH,DL = row, column (0,0 = upper left)
                        ; BH = page number
lodsw
mov     bl, ah
mov     ah, 9
int     10h             ; - VIDEO - WRITE ATTRIBUTES/CHARACTERS AT CURSOR POSITION
                        ; AL = character, BH = display page
                        ; BL = attributes of character (alpha modes) or color (graphics modes)
                        ; CX = number of times to write character
inc     dl
cmp     [bp+arg_6], dl
ja      short loc_1C21D
inc     dh
cmp     [bp+arg_4], dh
jge     short loc_1C21A
pop     si
pop     dx
pop     cx
pop     bx
pop     bp
retn
sub_1C208 endp




sub_1C23E proc near
push    bx
push    cx
push    dx
mov     bh, 0
mov     ah, 3
int     10h             ; - VIDEO - READ CURSOR POSITION
                        ; BH = page number
                        ; Return: DH,DL = row,column, CH = cursor start line, CL = cursor end line
mov     cs:word_1C252, dx
mov     ax, dx
pop     dx
pop     cx
pop     bx
retn
sub_1C23E endp

word_1C252 dw 0



sub_1C254 proc near
push    bx
push    dx
mov     bh, 0
mov     ah, 2
mov     dx, cs:word_1C252
int     10h             ; - VIDEO - SET CURSOR POSITION
                        ; DH,DL = row, column (0,0 = upper left)
                        ; BH = page number
mov     ax, cs:word_1C252
pop     dx
pop     bx
retn
sub_1C254 endp



; Attributes: bp-based frame

sub_1C268 proc near

arg_0= word ptr  4

push    bp
mov     bp, sp
push    cx
push    dx
mov     ah, 3Dh ; '='
xor     al, al
mov     dx, [bp+arg_0]
int     21h             ; DOS - 2+ - OPEN DISK FILE WITH HANDLE
                        ; DS:DX -; ASCIZ filename
                        ; AL = access mode
                        ; 0 - read
jnb     short loc_1C27B
mov     ax, 0FFFFh

loc_1C27B:
pop     dx
pop     cx
pop     bp
retn
sub_1C268 endp



; Attributes: bp-based frame

sub_1C27F proc near

arg_0= word ptr  4

push    bp
mov     bp, sp
push    bx
mov     ah, 3Eh ; ';'
mov     bx, [bp+arg_0]
int     21h             ; DOS - 2+ - CLOSE A FILE WITH HANDLE
                        ; BX = file handle
pop     bx
pop     bp
retn
sub_1C27F endp



; Attributes: bp-based frame

sub_1C28D proc near

arg_0= word ptr  4
arg_2= word ptr  6
arg_4= word ptr  8

push    bp
mov     bp, sp
push    bx
push    cx
push    dx
mov     ah, 3Fh ; '?'
mov     bx, [bp+arg_0]
mov     cx, [bp+arg_4]
mov     dx, [bp+arg_2]
int     21h             ; DOS - 2+ - READ FROM FILE WITH HANDLE
                        ; BX = file handle, CX = number of bytes to read
                        ; DS:DX -; buffer
pop     dx
pop     cx
pop     bx
pop     bp
retn
sub_1C28D endp



; Attributes: bp-based frame

sub_1C2A5 proc near

arg_0= word ptr  4
arg_2= word ptr  6
arg_4= word ptr  8

push    bp
mov     bp, sp
push    bx
push    cx
push    dx
mov     ah, 40h ; '@'
mov     bx, [bp+arg_0]
mov     cx, [bp+arg_4]
mov     dx, [bp+arg_2]
int     21h             ; DOS - 2+ - WRITE TO FILE WITH HANDLE
                        ; BX = file handle, CX = number of bytes to write, DS:DX -; buffer
pop     dx
pop     cx
pop     bx
pop     bp
retn
sub_1C2A5 endp



; Attributes: bp-based frame

sub_1C2BD proc near

arg_0= word ptr  4

push    bp
mov     bp, sp
push    cx
push    dx
mov     ah, 3Ch ; '<'
xor     cx, cx
mov     dx, [bp+arg_0]
int     21h             ; DOS - 2+ - CREATE A FILE WITH HANDLE (CREAT)
                        ; CX = attributes for file
                        ; DS:DX -; ASCIZ filename (may include drive and path)
jnb     short loc_1C2D0
mov     ax, 0FFFFh

loc_1C2D0:
pop     dx
pop     cx
pop     bp
retn
sub_1C2BD endp



; Attributes: bp-based frame

__dos_findfirst proc near

arg_0= word ptr  4

push    bp              ; the name is a guess
mov     bp, sp
mov     dx, offset DiskXferBuff
mov     ah, 1Ah
int     21h             ; DOS - SET DISK TRANSFER AREA ADDRESS
                        ; DS:DX -; disk transfer buffer
mov     dx, [bp+arg_0]
xor     cx, cx
mov     ah, 4Eh
int     21h             ; DOS - 2+ - FIND FIRST ASCIZ (FINDFIRST)
                        ; CX = search attributes
                        ; DS:DX -; ASCIZ filespec
                        ; (drive, path, and wildcards allowed)
mov     ah, 0
or      ax, ax
jz      short loc_1C2F2
xor     ax, ax
jmp     short loc_1C2F8
align 2

loc_1C2F2:
mov     ax, offset DiskXferBuff
add     ax, 1Eh

loc_1C2F8:
pop     bp
retn
__dos_findfirst endp




sub_1C2FA proc near
mov     dx, offset DiskXferBuff
mov     ah, 1Ah
int     21h             ; DOS - SET DISK TRANSFER AREA ADDRESS
                        ; DS:DX -; disk transfer buffer
mov     ah, 4Fh
int     21h             ; DOS - 2+ - FIND NEXT ASCIZ (FINDNEXT)
                        ; [DTA] = data block from
                        ; last AH = 4Eh/4Fh call
mov     ah, 0
or      ax, ax
jz      short loc_1C310
xor     ax, ax
jmp     short locret_1C316
align 2

loc_1C310:
mov     ax, offset DiskXferBuff
add     ax, 1Eh

locret_1C316:
retn
sub_1C2FA endp




sub_1C317 proc near
push    ds
push    es
push    si
push    di
push    cx
push    ds
pop     es
assume es:nothing
mov     ax, cs
sub     ax, 10h
mov     ds, ax
assume ds:PSP
mov     si, offset TailByte
mov     di, offset unk_1E888
mov     cx, 50h ; 'P'
cld
rep movsb
mov     ax, offset unk_1E888
pop     cx
pop     di
pop     si
pop     es
assume es:nothing
pop     ds
assume ds:nothing
retn
sub_1C317 endp




Beep2 proc near
push    ax
push    bx
push    cx
push    dx
push    si
cli
mov     al, 0B6h ; '¦'  ; timer 2 16 bit mode 3
out     43h, al         ; Timer 8253-5 (AT: 8254.2).
mov     dx, 400h
mov     si, dx
mov     ax, dx
shr     si, 1
shr     si, 1
out     42h, al         ; Timer 8253-5 (AT: 8254.2).
xchg    ah, al
out     42h, al         ; Timer 8253-5 (AT: 8254.2).
xchg    al, ah
in      al, 61h         ; PC/XT PPI port B bits:
                        ; 0: Tmr 2 gate --- OR 03H=spkr ON
                        ; 1: Tmr 2 data -+  AND 0fcH=spkr OFF
                        ; 3: 1=read high switches
                        ; 4: 0=enable RAM parity checking
                        ; 5: 0=enable I/O channel check
                        ; 6: 0=hold keyboard clock low
                        ; 7: 0=enable kbrd
mov     bl, al
or      al, 3
out     61h, al         ; PC/XT PPI port B bits:
                        ; 0: Tmr 2 gate --- OR 03H=spkr ON
                        ; 1: Tmr 2 data -+  AND 0fcH=spkr OFF
                        ; 3: 1=read high switches
                        ; 4: 0=enable RAM parity checking
                        ; 5: 0=enable I/O channel check
                        ; 6: 0=hold keyboard clock low
                        ; 7: 0=enable kbrd
mov     cx, 2000h

loc_1C362:              ; PC/XT PPI port C. Bits:
in      al, 62h         ; 0-3: values of DIP switches
                        ; 5: 1=Timer 2 channel out
                        ; 6: 1=I/O channel check
                        ; 7: 1=RAM parity check error occurred.
and     al, 20h
cmp     al, bh
mov     bh, al
jz      short loc_1C380
or      al, al
mov     ax, dx
jz      short loc_1C376
sub     ax, si
jmp     short loc_1C378

loc_1C376:
add     ax, si

loc_1C378:              ; Timer 8253-5 (AT: 8254.2).
out     42h, al
xchg    ah, al
out     42h, al         ; Timer 8253-5 (AT: 8254.2).
xchg    al, ah

loc_1C380:
loop    loc_1C362
mov     al, bl
and     al, 0FCh
out     61h, al         ; PC/XT PPI port B bits:
                        ; 0: Tmr 2 gate --- OR 03H=spkr ON
                        ; 1: Tmr 2 data -+  AND 0fcH=spkr OFF
                        ; 3: 1=read high switches
                        ; 4: 0=enable RAM parity checking
                        ; 5: 0=enable I/O channel check
                        ; 6: 0=hold keyboard clock low
                        ; 7: 0=enable kbrd
mov     cx, 3E8h
sti

loc_1C38C:
mul     ax
loop    loc_1C38C
pop     si
pop     dx
pop     cx
pop     bx
pop     ax
retn
Beep2 endp



; Attributes: bp-based frame

sub_1C396 proc near

var_4= word ptr -4
var_2= word ptr -2

push    bp
mov     bp, sp
mov     ax, 4
call    __chkstk
call    sub_1C1AF
mov     [bp+var_4], ax
cmp     byte ptr [bp+var_4], 0
jz      short loc_1C3B2
mov     al, byte ptr [bp+var_4]

loc_1C3AE:
sub     ah, ah
jmp     short loc_1C3C6

loc_1C3B2:
mov     ax, [bp+var_4]
sub     al, al
mov     cl, 8
shr     ax, cl
mov     [bp+var_2], ax
mov     bx, ax
mov     al, ds:byte_1E998[bx]
jmp     short loc_1C3AE

loc_1C3C6:
mov     sp, bp
pop     bp
retn
sub_1C396 endp



; Attributes: bp-based frame

sub_1C3CA proc near

var_4= word ptr -4
var_2= word ptr -2
arg_0= word ptr  4
arg_2= word ptr  6
arg_4= word ptr  8
arg_6= word ptr  0Ah

push    bp
mov     bp, sp
mov     ax, 4
call    __chkstk
push    si
mov     [bp+var_2], 0
jmp     short loc_1C3F2

loc_1C3DB:
mov     ax, 20h ; ' '
push    ax
mov     ax, [bp+arg_2]
add     ax, [bp+var_2]
push    ax
push    [bp+arg_0]
call    sub_1C1B4
add     sp, 6
inc     [bp+var_2]

loc_1C3F2:
mov     ax, [bp+arg_6]
cmp     [bp+var_2], ax
jl      short loc_1C3DB
or      ax, ax
jg      short loc_1C401
jmp     loc_1C4AD

loc_1C401:
mov     [bp+var_2], 0

loc_1C406:
mov     ax, 0DBh ; '¦'
push    ax
mov     ax, [bp+arg_2]
add     ax, [bp+var_2]
push    ax
push    [bp+arg_0]
call    sub_1C1B4
add     sp, 6
call    sub_1C396
mov     [bp+var_4], ax
mov     ax, 20h ; ' '
push    ax
mov     ax, [bp+arg_2]
add     ax, [bp+var_2]
push    ax
push    [bp+arg_0]
call    sub_1C1B4
add     sp, 6
mov     ax, [bp+var_4]
cmp     ax, 8
jz      short loc_1C478
cmp     ax, 0Dh
jz      short loc_1C495
cmp     ax, 1Bh
jz      short loc_1C4B2
mov     ax, [bp+arg_6]
cmp     [bp+var_2], ax
jge     short loc_1C495
cmp     [bp+var_4], 80h ; 'Ç'
jge     short loc_1C495
mov     bx, [bp+var_2]
mov     si, [bp+arg_4]
mov     al, byte ptr [bp+var_4]
mov     [bx+si], al
push    [bp+var_4]
mov     ax, [bp+arg_2]
add     ax, [bp+var_2]
push    ax
push    [bp+arg_0]
call    sub_1C1B4
add     sp, 6
inc     [bp+var_2]
jmp     short loc_1C495

loc_1C478:
cmp     [bp+var_2], 0
jle     short loc_1C481
dec     [bp+var_2]

loc_1C481:
mov     ax, 20h ; ' '
push    ax
mov     ax, [bp+arg_2]
add     ax, [bp+var_2]
push    ax
push    [bp+arg_0]
call    sub_1C1B4
add     sp, 6

loc_1C495:
cmp     [bp+var_4], 0Dh
jz      short loc_1C4A4
cmp     [bp+var_4], 1Bh
jz      short loc_1C4A4
jmp     loc_1C406

loc_1C4A4:
mov     bx, [bp+var_2]
mov     si, [bp+arg_4]
mov     byte ptr [bx+si], 0

loc_1C4AD:
mov     ax, [bp+var_2]
jmp     short loc_1C4B9

loc_1C4B2:
mov     [bp+var_2], 0
jmp     short loc_1C495

loc_1C4B9:
pop     si
mov     sp, bp
pop     bp
retn
sub_1C3CA endp

byte_1C4BE db 0
byte_1C4BF db 0FFh
OldInt13Off dw 0
OldInt13Seg dw 0
byte_1C4C4 db 0
push    bp
mov     bp, sp
mov     al, [bp+4]
call    sub_1C4D0
pop     bp
retn



sub_1C4D0 proc near
push    ds
push    bx
push    cx
push    dx
push    cs
pop     ds
assume ds:seg001
mov     cs:byte_1C4BE, al
mov     cs:byte_1C4BF, 0FFh
mov     cs:byte_1C4C4, 0
mov     ah, 44h ; 'D'
mov     al, 0Eh
mov     bl, cs:byte_1C4BE
inc     bl
int     21h             ; DOS - 2+ - IOCTL -
jb      short loc_1C4F9
mov     cs:byte_1C4C4, al

loc_1C4F9:
mov     ah, 44h ; 'D'
mov     al, 0Fh
mov     bl, cs:byte_1C4BE
inc     bl
int     21h             ; DOS - 2+ - IOCTL -
cli
call    GetInt13
mov     al, cs:byte_1C4BE
call    sub_1C581
call    RestoreInt13
sti
cmp     cs:byte_1C4C4, 0
jz      short loc_1C528
mov     ah, 44h ; 'D'
mov     al, 0Fh
mov     bl, cs:byte_1C4C4
int     21h             ; DOS - 2+ - IOCTL -

loc_1C528:
xor     ah, ah
mov     al, cs:byte_1C4BF
cmp     al, 0FFh
jnz     short loc_1C535
mov     ax, 0FFFFh

loc_1C535:
pop     dx
pop     cx
pop     bx
pop     ds
assume ds:nothing
retn
sub_1C4D0 endp




GetInt13 proc near
push    ax
push    bx
push    dx
push    ds
push    es
mov     ah, 35h ; '5'
mov     al, 13h
int     21h             ; DOS - 2+ - GET INTERRUPT VECTOR
                        ; AL = interrupt number
                        ; Return: ES:BX = value of interrupt vector
mov     cs:OldInt13Off, bx
mov     cs:OldInt13Seg, es
mov     dx, offset Int13Entry
push    cs
pop     ds
assume ds:seg001
mov     ah, 25h ; '%'
mov     al, 13h
int     21h             ; DOS - SET INTERRUPT VECTOR
                        ; AL = interrupt number
                        ; DS:DX = new vector to be used for specified interrupt
pop     es
pop     ds
assume ds:nothing
pop     dx
pop     bx
pop     ax
retn
GetInt13 endp


Int13Entry:
mov     cs:byte_1C4BF, dl
mov     ax, 0
clc
iret



RestoreInt13 proc near
push    ax
push    dx
push    ds
mov     dx, cs:OldInt13Off
mov     ds, cs:OldInt13Seg
mov     ah, 25h ; '%'
mov     al, 13h
int     21h             ; DOS - SET INTERRUPT VECTOR
                        ; AL = interrupt number
                        ; DS:DX = new vector to be used for specified interrupt
pop     ds
pop     dx
pop     ax
retn
RestoreInt13 endp




sub_1C581 proc near
push    ds
push    cx
push    si
push    di
push    bp
mov     bx, seg seg002
mov     ds, bx
assume ds:seg002
mov     bx, offset DiskXferBuf2
mov     cx, 1
mov     dx, 0
int     25h             ; DOS - ABSOLUTE DISK READ (except DOS 4.0/COMPAQ DOS 3.31 ;32M partitn)
                        ; AL = drive number (0=A, 1=B, etc), DS:BX = Disk Transfer Address (buffer)
                        ; CX = number of sectors to read, DX = first relative sector to read
                        ; Return: CF set on error
popf
pop     bp
pop     di
pop     si
pop     cx
pop     ds
assume ds:nothing
retn
sub_1C581 endp ; sp =  2

; [00000016 BYTES: COLLAPSED FUNCTION __chkstk. PRESS KEYPAD "+" TO EXPAND]


; Attributes: bp-based frame

_close proc near

arg_0= word ptr  4

push    bp
mov     bp, sp
mov     bx, [bp+arg_0]
mov     ah, 3Eh
int     21h             ; DOS - 2+ - CLOSE A FILE WITH HANDLE
                        ; BX = file handle
jb      short loc_1C5C4
mov     ds:IOCTLFlags[bx], 0

loc_1C5C4:
jmp     __dosret0
_close endp

assume ss:seg003, ds:PSP



public start
start proc near
mov     ah, 30h
int     21h             ; DOS - GET DOS VERSION
                        ; Return: AL = major version number (00h for DOS 1.x)
cmp     al, 2
jnb     short DosVerOK
mov     ax, 4
push    ax
call    __NMSG_TEXT
xchg    ax, dx
mov     ah, 9
int     21h             ; DOS - PRINT STRING
                        ; DS:DX -; string terminated by "$"
int     20h             ; DOS - PROGRAM TERMINATION
                        ; returns to DOS--identical to INT 21/AH=00h

DosVerOK:
mov     di, seg seg002
mov     si, FreeSeg
sub     si, di
cmp     si, 1000h
jb      short loc_1C5EF
mov     si, 1000h

loc_1C5EF:
cli
mov     ss, di
assume ss:seg002
add     sp, offset TopOfStack
sti
jnb     short loc_1C604
xor     ax, ax
push    ax
call    __NMSG_WRITE
mov     ax, 4CFFh
int     21h             ; DOS - 2+ - QUIT WITH EXIT CODE (EXIT)
                        ; AL = exit code

loc_1C604:
and     sp, 0FFFEh
mov     ss:word_1EC36, sp
mov     ss:word_1EC34, sp
mov     ax, si
mov     cl, 4
shl     ax, cl
dec     ax
mov     ss:word_1EC32, ax
add     si, di
mov     FreeSeg, si
mov     bx, es
sub     bx, si
neg     bx
mov     ah, 4Ah
int     21h             ; DOS - 2+ - ADJUST MEMORY BLOCK SIZE (SETBLOCK)
                        ; ES = segment address of block to change
                        ; BX = new size in paragraphs
mov     ss:__psp, ds
push    ss
pop     es
assume es:seg002
cld
mov     di, offset word_1F046 ; start of stack
mov     cx, 1B80h       ; end of stack
sub     cx, di
xor     ax, ax
rep stosb               ; clear stack
push    ss
pop     ds
assume ds:seg002
call    __cinit
push    ss
pop     ds
call    __setargv
call    __setenvp
xor     bp, bp
push    envp
push    ___argv
push    ___argc
call    _Main
push    ax
call    _exit
__cintDIV db 0B8h ; +
db    3
db    0

__amsg_exit:
push    ax
call    __NMSG_WRITE
mov     ax, 0FFh
push    ax
call    __exit
start endp



; Attributes: library function bp-based frame

_sprintf proc near

arg_0= word ptr  4
arg_2= word ptr  6
arg_4= byte ptr  8

push    bp
mov     bp, sp
sub     sp, 0Ch
push    di
push    si
mov     di, bp
sub     di, 0Ah
mov     byte ptr [di+6], 42h ; 'B'
mov     ax, [bp+arg_0]
mov     [di+4], ax
mov     [di], ax
mov     word ptr [di+2], 7FFFh
lea     ax, [bp+arg_4]
push    ax
push    [bp+arg_2]
push    di
call    __output
add     sp, 6
mov     si, ax
dec     word ptr [di+2]
js      short loc_1C6B0
sub     al, al
mov     bx, [di]
inc     word ptr [di]
mov     [bx], al
sub     ah, ah
jmp     short loc_1C6BA

loc_1C6B0:
push    di
sub     ax, ax
push    ax
call    __flsbuf
add     sp, 4

loc_1C6BA:
mov     ax, si
pop     si
pop     di
mov     sp, bp
pop     bp
retn
_sprintf endp



; Attributes: library function bp-based frame

_strcmpi proc near

arg_0= word ptr  4
arg_2= word ptr  6

push    bp
mov     bp, sp
push    di
push    si
mov     si, [bp+arg_0]
mov     di, [bp+arg_2]
push    ds
pop     es
mov     bh, 'A'
mov     bl, 'Z'
mov     ch, ' '

loc_1C6D5:
mov     ah, [si]
mov     al, [di]
or      ah, ah
jz      short loc_1C6FD
or      al, al
jz      short loc_1C6FD
inc     si
inc     di
cmp     ah, bh
jb      short loc_1C6ED
cmp     ah, bl
ja      short loc_1C6ED
add     ah, ch

loc_1C6ED:
cmp     al, bh
jb      short loc_1C6F7
cmp     al, bl
ja      short loc_1C6F7
add     al, ch

loc_1C6F7:
cmp     ah, al
jnz     short loc_1C703
jmp     short loc_1C6D5

loc_1C6FD:
xor     cx, cx
cmp     ah, al
jz      short loc_1C70C

loc_1C703:
mov     cx, 0
jb      short loc_1C70A
dec     cx
dec     cx

loc_1C70A:
not     cx

loc_1C70C:
mov     ax, cx
pop     si
pop     di
mov     sp, bp
pop     bp
retn
_strcmpi endp



; Attributes: library function bp-based frame

_strcpy proc near

arg_0= word ptr  4
arg_2= word ptr  6

push    bp
mov     bp, sp
push    di
push    si
push    ds
pop     es
mov     di, [bp+arg_2]
mov     si, di
xor     ax, ax
mov     cx, 0FFFFh
repne scasb
inc     cx
neg     cx
mov     di, [bp+arg_0]
mov     dx, di
rep movsb
mov     ax, dx
pop     si
pop     di
mov     sp, bp
pop     bp
retn
_strcpy endp



; Attributes: library function bp-based frame

_strnicmp proc near

arg_0= word ptr  4
arg_2= word ptr  6
arg_4= word ptr  8

push    bp
mov     bp, sp
push    di
push    si
mov     si, [bp+arg_0]
mov     di, [bp+arg_2]
push    ds
pop     es
mov     cx, [bp+arg_4]
jcxz    short loc_1C788
mov     bh, 41h ; 'A'
mov     bl, 5Ah ; 'Z'
mov     dh, 20h ; ' '

loc_1C751:
mov     ah, [si]
mov     al, [di]
or      ah, ah
jz      short loc_1C779
or      al, al
jz      short loc_1C779
inc     si
inc     di
cmp     ah, bh
jb      short loc_1C769
cmp     ah, bl
ja      short loc_1C769
add     ah, dh

loc_1C769:
cmp     al, bh
jb      short loc_1C773
cmp     al, bl
ja      short loc_1C773
add     al, dh

loc_1C773:
cmp     ah, al
jnz     short loc_1C77F
loop    loc_1C751

loc_1C779:
xor     cx, cx
cmp     ah, al
jz      short loc_1C788

loc_1C77F:
mov     cx, 0
jb      short loc_1C786
dec     cx
dec     cx

loc_1C786:
not     cx

loc_1C788:
mov     ax, cx
pop     si
pop     di
mov     sp, bp
pop     bp
retn
_strnicmp endp



; Attributes: library function bp-based frame

_strupr proc near

arg_0= word ptr  4

push    bp
mov     bp, sp
push    si
mov     si, [bp+arg_0]
mov     dx, si
mov     bh, 61h ; 'a'
mov     bl, 7Ah ; 'z'
mov     al, 20h ; ' '
xor     ch, ch

loc_1C7A1:
mov     cl, [si]
jcxz    short loc_1C7B4
cmp     cl, bh
jb      short loc_1C7B1
cmp     cl, bl
ja      short loc_1C7B1
sub     cl, al
mov     [si], cl

loc_1C7B1:
inc     si
jmp     short loc_1C7A1

loc_1C7B4:
mov     ax, dx
pop     si
mov     sp, bp
pop     bp
retn
_strupr endp



; Attributes: library function bp-based frame

__flsbuf proc near

var_2= word ptr -2
arg_0= byte ptr  4
arg_2= word ptr  6

push    bp
mov     bp, sp
sub     sp, 4
push    di
push    si
mov     si, [bp+arg_2]
test    byte ptr [si+6], 83h
jz      short loc_1C7D2
test    byte ptr [si+6], 40h
jz      short loc_1C7DC

loc_1C7D2:
or      byte ptr [si+6], 20h
mov     ax, 0FFFFh
jmp     loc_1C8E0

loc_1C7DC:
test    byte ptr [si+6], 1
jnz     short loc_1C7D2
or      byte ptr [si+6], 2
and     byte ptr [si+6], 0EFh
sub     ax, ax
mov     [si+2], ax
mov     di, ax
mov     [bp+var_2], di
test    byte ptr [si+6], 8
jnz     short loc_1C80D
mov     al, [si+7]
cbw
mov     bx, ax
shl     bx, 1
add     bx, ax
shl     bx, 1
test    byte_1EE9E[bx], 1
jz      short loc_1C84D

loc_1C80D:
mov     di, [si]
sub     di, [si+4]
mov     ax, [si+4]
inc     ax
mov     [si], ax
mov     al, [si+7]
cbw
mov     bx, ax
shl     bx, 1
add     bx, ax
shl     bx, 1
mov     ax, word_1EEA0[bx]
dec     ax
mov     [si+2], ax
or      di, di
jle     short loc_1C842
push    di
push    word ptr [si+4]
mov     al, [si+7]
cbw
push    ax
call    _write
add     sp, 6
mov     [bp+var_2], ax

loc_1C842:
mov     bx, [si+4]
mov     al, [bp+arg_0]
mov     [bx], al
jmp     loc_1C8D3

loc_1C84D:
test    byte ptr [si+6], 4
jnz     short loc_1C8BD
cmp     si, 1516h
jnz     short loc_1C89C
mov     al, [si+7]
cbw
push    ax
call    _isatty
add     sp, 2
or      ax, ax
jnz     short loc_1C8B9
inc     word_1EDFC
mov     word ptr [si+4], 1780h
mov     al, [si+7]
cbw
mov     bx, ax
shl     bx, 1
add     bx, ax
shl     bx, 1
mov     byte_1EE9E[bx], 1
mov     word ptr [si], 1781h

loc_1C886:
cbw
mov     bx, ax
shl     bx, 1
add     bx, ax
shl     bx, 1
mov     word_1EEA0[bx], 200h
mov     word ptr [si+2], 1FFh
jmp     short loc_1C842

loc_1C89C:
mov     ax, 200h
push    ax
call    _malloc
add     sp, 2
mov     [si+4], ax
or      ax, ax
jz      short loc_1C8B9
or      byte ptr [si+6], 8
inc     ax
mov     [si], ax
mov     al, [si+7]
jmp     short loc_1C886

loc_1C8B9:
or      byte ptr [si+6], 4

loc_1C8BD:
mov     di, 1
push    di
lea     ax, [bp+arg_0]
push    ax
mov     al, [si+7]
cbw
push    ax
call    _write
add     sp, 6
mov     [bp+var_2], ax

loc_1C8D3:
cmp     [bp+var_2], di
jz      short loc_1C8DB
jmp     loc_1C7D2

loc_1C8DB:
mov     al, [bp+arg_0]
sub     ah, ah

loc_1C8E0:
pop     si
pop     di
mov     sp, bp
pop     bp
retn
__flsbuf endp



; Attributes: library function

__nullcheck proc near
push    si
xor     si, si
mov     cx, 36h ; '6'
xor     ah, ah
cld

loc_1C8EF:
lodsb
xor     ah, al
loop    loc_1C8EF
xor     ah, 55h
jz      short loc_1C900
mov     ax, 1
push    ax
call    __NMSG_WRITE

loc_1C900:
pop     si
retn
__nullcheck endp



; Attributes: library function

__cinit proc near
mov     ah, 30h         ; the name is a guess
int     21h             ; DOS - GET DOS VERSION
                        ; Return: AL = major version number (00h for DOS 1.x)
mov     __osmajor, ax
mov     bx, 4

loc_1C90C:
mov     ax, 4400h
int     21h             ; DOS - 2+ - IOCTL - GET DEVICE INFORMATION
                        ; BX = file or device handle
jb      short loc_1C91D
test    dl, 80h         ; Character device if bit 7 set, disk file if clear.
jz      short loc_1C91D
or      IOCTLFlags[bx], 40h

loc_1C91D:
dec     bx
jns     short loc_1C90C
mov     ax, 3500h
int     21h             ; DOS - 2+ - GET INTERRUPT VECTOR
                        ; AL = interrupt number
                        ; Return: ES:BX = value of interrupt vector
mov     word ptr OldInt0Vector, bx
mov     word ptr OldInt0Vector+2, es
push    cs
pop     ds
assume ds:seg001
mov     ax, 2500h
mov     dx, offset __cintDIV
int     21h             ; DOS - SET INTERRUPT VECTOR
                        ; AL = interrupt number
                        ; DS:DX = new vector to be used for specified interrupt
push    ss
pop     ds
assume ds:seg002
mov     cx, word_1EF32
jcxz    short loc_1C966
mov     es, __psp
assume es:nothing
mov     si, es:EnviroBlkSeg ; Segment of environment block
lds     ax, dword_1EF34
assume ds:nothing
mov     dx, ds
xor     bx, bx
call    dword ptr ss:unk_1EF30
lds     ax, ss:dword_1EF38
mov     dx, ds
mov     bx, 3
call    dword ptr ss:unk_1EF30
push    ss
pop     ds
assume ds:seg002

loc_1C966:
mov     es, __psp
mov     cx, es:EnviroBlkSeg ; Segment of environment block
jcxz    short loc_1C9A5
mov     es, cx
xor     di, di

loc_1C975:
cmp     byte ptr es:[di], 0
jz      short loc_1C9A5
mov     cx, 0Ch
mov     si, offset unk_1ED8A
repe cmpsb
jz      short loc_1C990
mov     cx, 7FFFh
xor     ax, ax
repne scasb
jnz     short loc_1C9A5
jmp     short loc_1C975

loc_1C990:
push    es
push    ds
pop     es
assume es:seg002
pop     ds
assume ds:nothing
mov     si, di
mov     di, offset IOCTLFlags
lodsb
cbw
xchg    ax, cx

loc_1C99C:
lodsb
inc     al
jz      short loc_1C9A2
dec     ax

loc_1C9A2:
stosb
loop    loc_1C99C

loc_1C9A5:
push    ss
pop     ds
assume ds:seg002
mov     si, offset off_1EF3C
mov     di, offset off_1EF3C
call    sub_1CA0D
retn
__cinit endp



; Attributes: library function noreturn bp-based frame

_exit proc near
push    bp
mov     bp, sp
mov     si, offset unk_1F06A
mov     di, offset unk_1F06A
call    sub_1CA0D
mov     si, offset off_1EF3C
mov     di, offset aNmsg ; "<<NMSG;;"
call    sub_1CA0D
jmp     short loc_1C9CB
_exit endp



; Attributes: library function noreturn bp-based frame

__exit proc near

arg_0= word ptr  4

push    bp
mov     bp, sp

loc_1C9CB:
mov     si, 164Eh
mov     di, 164Eh
call    sub_1CA0D
call    __nullcheck
mov     cx, 14h
xor     bx, bx

loc_1C9DC:
test    byte ptr [bx+14BEh], 1
jz      short loc_1C9E7
mov     ah, 3Eh
int     21h             ; DOS - 2+ - CLOSE A FILE WITH HANDLE
                        ; BX = file handle

loc_1C9E7:
inc     bx
loop    loc_1C9DC
call    __ctermsub
mov     ax, [bp+arg_0]
mov     ah, 4Ch
int     21h             ; DOS - 2+ - QUIT WITH EXIT CODE (EXIT)
__exit endp             ; AL = exit code



; Attributes: library function

__ctermsub proc near
mov     cx, word_1EF32
jcxz    short loc_1CA01
mov     bx, 2
call    dword ptr unk_1EF30

loc_1CA01:
push    ds
lds     dx, OldInt0Vector
assume ds:nothing
mov     ax, 2500h
int     21h             ; DOS - SET INTERRUPT VECTOR
                        ; AL = interrupt number
                        ; DS:DX = new vector to be used for specified interrupt
pop     ds
retn
__ctermsub endp




sub_1CA0D proc near
cmp     si, di
jnb     short locret_1CA1B
dec     di
dec     di
mov     cx, [di]
jcxz    short sub_1CA0D
call    cx
jmp     short sub_1CA0D

locret_1CA1B:
retn
sub_1CA0D endp


__dosret0:
jb      short loc_1CA26
xor     ax, ax
mov     sp, bp
pop     bp
retn

__dosretax:
jnb     short loc_1CA2C

loc_1CA26:
call    sub_1CA36
mov     ax, 0FFFFh

loc_1CA2C:
mov     sp, bp
pop     bp
retn


; Attributes: library function

__maperror proc near
xor     ah, ah
call    sub_1CA36
retn
__maperror endp




sub_1CA36 proc near
mov     ds:byte_1EDAC, al
or      ah, ah
jnz     short loc_1CA60
cmp     byte ptr ds:__osmajor, 3
jb      short loc_1CA51
cmp     al, 22h ; '"'
jnb     short loc_1CA55
cmp     al, 20h ; ' '
jb      short loc_1CA51
mov     al, 5
jmp     short loc_1CA57
db 90h

loc_1CA51:
cmp     al, 13h
jbe     short loc_1CA57

loc_1CA55:
mov     al, 13h

loc_1CA57:
mov     bx, offset unk_1EDD2
xlat

loc_1CA5B:
cbw
mov     ds:word_1EDA2, ax
retn

loc_1CA60:
mov     al, ah
jmp     short loc_1CA5B
sub_1CA36 endp



; Attributes: library function bp-based frame

__NMSG_TEXT proc near

arg_0= word ptr  4

push    bp
mov     bp, sp
push    si
push    di
mov     ax, seg seg002
mov     ds, ax
assume ds:seg002
push    ds
pop     es
mov     dx, [bp+arg_0]
mov     si, offset Nmsg_Text

loc_1CA76:
lodsw
cmp     ax, dx
jz      short loc_1CA8B
inc     ax
xchg    ax, si
jz      short loc_1CA8B
xchg    ax, di
xor     ax, ax
mov     cx, 0FFFFh
repne scasb
mov     si, di
jmp     short loc_1CA76

loc_1CA8B:
xchg    ax, si
pop     di
pop     si
mov     sp, bp
pop     bp
retn    2
__NMSG_TEXT endp



; Attributes: library function bp-based frame

__NMSG_WRITE proc near

arg_0= word ptr  4

push    bp
mov     bp, sp
push    di
push    [bp+arg_0]
call    __NMSG_TEXT
or      ax, ax
jz      short loc_1CAB6
xchg    ax, dx
mov     di, dx
xor     ax, ax
mov     cx, 0FFFFh
repne scasb
not     cx
dec     cx
mov     bx, 2
mov     ah, 40h
int     21h             ; DOS - 2+ - WRITE TO FILE WITH HANDLE
                        ; BX = file handle, CX = number of bytes to write, DS:DX -; buffer

loc_1CAB6:
pop     di
mov     sp, bp
pop     bp
retn    2
__NMSG_WRITE endp



; Attributes: library function bp-based frame

__output proc near

var_162= word ptr -162h
var_15E= byte ptr -15Eh
arg_0= word ptr  4
arg_2= word ptr  6
arg_4= word ptr  8

push    bp
mov     bp, sp
mov     ax, 162h
call    __chkstk
push    di
push    si
mov     si, [bp+arg_2]
lea     ax, [bp+var_15E]
mov     word_1F054, ax
mov     ax, [bp+arg_4]
mov     word_1F050, ax
mov     ax, [bp+arg_0]
mov     word_1F04A, ax
mov     word_1F062, 0
mov     word_1F060, 0
jmp     loc_1CD26

loc_1CAED:
cmp     byte ptr [si], '%'
jz      short loc_1CAF5
jmp     loc_1CCBD

loc_1CAF5:
mov     word_1F05A, 1
sub     ax, ax
mov     word_1F058, ax
mov     word_1F046, ax
mov     word_1F05C, ax
mov     word_1F04E, ax
mov     word_1F052, ax
mov     word_1F048, ax
mov     word_1F04C, ax
mov     word_1F066, ax
mov     word_1F068, ax
mov     word_1F056, ' '
cmp     byte ptr [si+1], '0'
jnz     short loc_1CB5F
inc     si
mov     word_1F056, '0'
jmp     short loc_1CB5F

loc_1CB2D:
cmp     byte ptr [si], '-'
jnz     short loc_1CB38
inc     word_1F068
jmp     short loc_1CB5F

loc_1CB38:
cmp     byte ptr [si], '+'
jnz     short loc_1CB49
inc     word_1F058
mov     word_1F048, 0
jmp     short loc_1CB5F

loc_1CB49:
cmp     byte ptr [si], ' '
jnz     short loc_1CB5B
cmp     word_1F058, 0
jnz     short loc_1CB5F
inc     word_1F048
jmp     short loc_1CB5F

loc_1CB5B:
inc     word_1F066

loc_1CB5F:
inc     si
mov     al, [si]
cbw
push    ax
call    sub_1D2A4       ; flagchar
add     sp, 2
or      ax, ax
jnz     short loc_1CB2D
push    si
mov     ax, offset word_1F05E
push    ax
call    sub_1D239       ; getnum
add     sp, 4
mov     si, ax
cmp     byte ptr [si], '.'
jnz     short loc_1CB92
inc     word_1F052
inc     si
push    si
mov     ax, offset word_1F05A
push    ax
call    sub_1D239       ; getnum
add     sp, 4
mov     si, ax

loc_1CB92:
mov     al, [si]
cbw
cmp     ax, 'F'
jz      short loc_1CBD3
cmp     ax, 'N'
jz      short loc_1CBDB
cmp     ax, 'h'
jz      short loc_1CBCB
cmp     ax, 'l'
jz      short loc_1CBB0
cmp     ax, 'p'
jz      short loc_1CBD3
jmp     short loc_1CBB6

loc_1CBB0:
mov     word_1F04E, 2

loc_1CBB6:
cmp     word_1F04E, 0
jz      short loc_1CBC3
cmp     byte ptr [si], 'p'
jz      short loc_1CBC3
inc     si

loc_1CBC3:
cmp     byte ptr [si], 0
jnz     short loc_1CBE3
jmp     loc_1CD2E

loc_1CBCB:
mov     word_1F04E, 1
jmp     short loc_1CBB6

loc_1CBD3:
mov     word_1F04E, 10h
jmp     short loc_1CBB6

loc_1CBDB:
mov     word_1F04E, 8
jmp     short loc_1CBB6

loc_1CBE3:
mov     al, [si]
cbw
mov     [bp+var_162], ax
cmp     ax, 'E'
jz      short loc_1CBF9
cmp     ax, 'G'
jz      short loc_1CBF9
cmp     ax, 'X'
jnz     short loc_1CC02

loc_1CBF9:
inc     word_1F046
add     [bp+var_162], ' '

loc_1CC02:
mov     ax, [bp+var_162]
sub     ax, 'c'
cmp     ax, 15h
jbe     short loc_1CC11
jmp     loc_1CCB3

loc_1CC11:
add     ax, ax
xchg    ax, bx
jmp     cs:off_1CCC1[bx]

loc_1CC19:
mov     bx, word_1F050
mov     bx, [bx]
mov     ax, word_1F060
mov     [bx], ax
jmp     loc_1CCED

loc_1CC27:
inc     word_1F05C

loc_1CC2B:
mov     word_1F066, 0
mov     ax, 0Ah

loc_1CC34:
push    ax
call    sub_1CD4D       ; iprint

loc_1CC38:
add     sp, 2
jmp     loc_1CCED

loc_1CC3E:
mov     ax, 8
jmp     short loc_1CC34

loc_1CC43:
inc     word_1F04C
mov     word_1F05A, 4
inc     word_1F046
inc     word_1F052
cmp     word_1F04E, 2
jz      short loc_1CC63
cmp     word_1F04E, 10h
jnz     short loc_1CC98

loc_1CC63:
mov     word_1F04E, 0
add     word_1F050, 2
mov     ax, 10h
push    ax
call    sub_1CD4D       ; iprint
add     sp, 2
mov     ax, 3Ah ; ':'
push    ax
call    sub_1D006       ; _outc
add     sp, 2
sub     word_1F050, 4
mov     ax, 10h
push    ax
call    sub_1CD4D       ; iprint
add     sp, 2
add     word_1F050, 2
jmp     short loc_1CCED

loc_1CC98:
mov     ax, 10h
jmp     short loc_1CC34

loc_1CC9D:
sub     ax, ax

loc_1CC9F:
push    ax
call    sub_1CE82       ; sprint
jmp     short loc_1CC38

loc_1CCA5:
mov     ax, 1
jmp     short loc_1CC9F

loc_1CCAA:
push    [bp+var_162]
call    sub_1CF66       ; fprint
jmp     short loc_1CC38

loc_1CCB3:
cmp     word_1F04E, 0
jz      short loc_1CCBD
mov     ax, si
dec     si

loc_1CCBD:
mov     di, si
jmp     short loc_1CD0F
off_1CCC1 dw offset loc_1CCA5
dw offset loc_1CC2B
dw offset loc_1CCAA
dw offset loc_1CCAA
dw offset loc_1CCAA
dw offset loc_1CCB3
dw offset loc_1CC2B
dw offset loc_1CCB3
dw offset loc_1CCB3
dw offset loc_1CCB3
dw offset loc_1CCB3
dw offset loc_1CC19
dw offset loc_1CC3E
dw offset loc_1CC43
dw offset loc_1CCB3
dw offset loc_1CCB3
dw offset loc_1CC9D
dw offset loc_1CCB3
dw offset loc_1CC27
dw offset loc_1CCB3
dw offset loc_1CCB3
dw offset loc_1CC98

loc_1CCED:
cmp     word_1F062, 0
jz      short loc_1CD07
cmp     word_1F060, 0
jnz     short loc_1CD44
mov     bx, word_1F04A
test    byte ptr [bx+6], 20h
jnz     short loc_1CD3F
jmp     short loc_1CD44

loc_1CD07:
inc     si
jmp     short loc_1CD26

loc_1CD0A:
cmp     byte ptr [di], '%'
jz      short loc_1CD15

loc_1CD0F:
inc     di
cmp     byte ptr [di], 0
jnz     short loc_1CD0A

loc_1CD15:
mov     ax, di
sub     ax, si
push    ax
mov     ax, si
push    ds
push    ax
call    sub_1D0B4       ; putbuf
add     sp, 6
mov     si, di

loc_1CD26:
cmp     byte ptr [si], 0
jz      short loc_1CD2E
jmp     loc_1CAED

loc_1CD2E:
cmp     word_1F060, 0
jnz     short loc_1CD44
mov     bx, word_1F04A
test    byte ptr [bx+6], 20h
jz      short loc_1CD44

loc_1CD3F:
mov     ax, 0FFFFh
jmp     short loc_1CD47

loc_1CD44:
mov     ax, word_1F060

loc_1CD47:
pop     si
pop     di
mov     sp, bp
pop     bp
retn
__output endp



; iprint
; Attributes: library function bp-based frame

sub_1CD4D proc near

var_A= word ptr -0Ah
var_8= word ptr -8
var_6= word ptr -6
var_2= word ptr -2
arg_0= word ptr  4

push    bp
mov     bp, sp
mov     ax, 18h
call    __chkstk
push    di
push    si
cmp     [bp+arg_0], 0Ah
jz      short loc_1CD62
inc     word_1F05C

loc_1CD62:
cmp     word_1F04E, 2
jz      short loc_1CD70
cmp     word_1F04E, 10h
jnz     short loc_1CD86

loc_1CD70:
mov     bx, word_1F050
mov     ax, [bx]
mov     dx, [bx+2]
mov     [bp+var_8], ax
mov     [bp+var_6], dx
add     word_1F050, 4
jmp     short loc_1CDAF

loc_1CD86:
cmp     word_1F05C, 0
jz      short loc_1CD9D
mov     bx, word_1F050
mov     ax, [bx]
mov     [bp+var_8], ax
mov     [bp+var_6], 0
jmp     short loc_1CDAA

loc_1CD9D:
mov     bx, word_1F050
mov     ax, [bx]
cwd
mov     [bp+var_8], ax
mov     [bp+var_6], dx

loc_1CDAA:
add     word_1F050, 2

loc_1CDAF:
cmp     word_1F066, 0
jz      short loc_1CDC3
mov     ax, [bp+var_8]
or      ax, [bp+var_6]
jz      short loc_1CDC3
mov     ax, [bp+arg_0]
jmp     short loc_1CDC5

loc_1CDC3:
sub     ax, ax

loc_1CDC5:
mov     word_1F064, ax
mov     si, word_1F054
cmp     word_1F05C, 0
jnz     short loc_1CDFD
cmp     [bp+var_6], 0
jge     short loc_1CDFD
cmp     [bp+arg_0], 0Ah
jnz     short loc_1CDF6
mov     byte ptr [si], 2Dh ; '-'
inc     si
mov     ax, [bp+var_8]
mov     dx, [bp+var_6]
neg     ax
adc     dx, 0
neg     dx
mov     [bp+var_8], ax
mov     [bp+var_6], dx

loc_1CDF6:
mov     [bp+var_A], 1
jmp     short loc_1CE02

loc_1CDFD:
mov     [bp+var_A], 0

loc_1CE02:
mov     di, bp
sub     di, 18h
push    [bp+arg_0]
push    di
push    [bp+var_6]
push    [bp+var_8]
call    _ultoa
add     sp, 8
cmp     word_1F052, 0
jz      short loc_1CE3E
push    di
call    _strlen
add     sp, 2
mov     cx, word_1F05A
sub     cx, ax
mov     [bp+var_2], cx
jmp     short loc_1CE34

loc_1CE30:
mov     byte ptr [si], 30h ; '0'
inc     si

loc_1CE34:
mov     ax, [bp+var_2]
dec     [bp+var_2]
or      ax, ax
jg      short loc_1CE30

loc_1CE3E:
mov     al, [di]
mov     [si], al
cmp     word_1F046, 0
jz      short loc_1CE50
cmp     al, 61h ; 'a'
jl      short loc_1CE50
sub     byte ptr [si], 20h ; ' '

loc_1CE50:
inc     si
inc     di
cmp     byte ptr [di-1], 0
jnz     short loc_1CE3E
cmp     word_1F05C, 0
jnz     short loc_1CE73
mov     ax, word_1F058
or      ax, word_1F048
jz      short loc_1CE73
cmp     [bp+var_A], 0
jnz     short loc_1CE73
mov     ax, 1
jmp     short loc_1CE75

loc_1CE73:
sub     ax, ax

loc_1CE75:
push    ax
call    sub_1D11F       ; _out
add     sp, 2
pop     si
pop     di
mov     sp, bp
pop     bp
retn
sub_1CD4D endp



; sprint
; Attributes: library function bp-based frame

sub_1CE82 proc near

var_C= word ptr -0Ch
var_A= word ptr -0Ah
var_8= word ptr -8
var_4= dword ptr -4
arg_0= word ptr  4

push    bp
mov     bp, sp
mov     ax, 10h
call    __chkstk
push    di
push    si
mov     word_1F056, 20h ; ' '
cmp     [bp+arg_0], 0
jz      short loc_1CEAD
mov     si, 1
mov     ax, word_1F050
mov     [bp+var_C], ax
mov     [bp+var_A], ds
add     word_1F050, 2
jmp     loc_1CF31

loc_1CEAD:
cmp     word_1F04E, 10h
jnz     short loc_1CECA
mov     bx, word_1F050
mov     ax, [bx]
mov     dx, [bx+2]
mov     [bp+var_C], ax
mov     [bp+var_A], dx
add     word_1F050, 4
jmp     short loc_1CEDE

loc_1CECA:
mov     bx, word_1F050
mov     ax, [bx]
mov     [bp+var_8], ax
mov     [bp+var_C], ax
mov     [bp+var_A], ds
add     word_1F050, 2

loc_1CEDE:
cmp     word_1F04E, 10h
jnz     short loc_1CEF2
mov     ax, [bp+var_C]
or      ax, [bp+var_A]
jnz     short loc_1CF01
mov     ax, offset aNull ; "(null)"
jmp     short loc_1CEFB

loc_1CEF2:
cmp     [bp+var_8], 0
jnz     short loc_1CF01
mov     ax, offset aNull_0 ; "(null)"

loc_1CEFB:
mov     [bp+var_C], ax
mov     [bp+var_A], ds

loc_1CF01:
mov     ax, [bp+var_C]
mov     dx, [bp+var_A]
mov     word ptr [bp+var_4], ax
mov     word ptr [bp+var_4+2], dx
sub     si, si
jmp     short loc_1CF15

loc_1CF11:
inc     word ptr [bp+var_4]
inc     si

loc_1CF15:
les     bx, [bp+var_4]
assume es:nothing
cmp     byte ptr es:[bx], 0
jnz     short loc_1CF11
cmp     word_1F052, 0
jz      short loc_1CF31
mov     ax, si
cmp     ax, word_1F05A
jbe     short loc_1CF31
mov     si, word_1F05A

loc_1CF31:
mov     di, word_1F05E
sub     di, si
cmp     word_1F068, 0
jnz     short loc_1CF45
push    di
call    sub_1D04F       ; putpad
add     sp, 2

loc_1CF45:
push    si
push    [bp+var_A]
push    [bp+var_C]
call    sub_1D0B4       ; putbuf
add     sp, 6
cmp     word_1F068, 0
jz      short loc_1CF60
push    di
call    sub_1D04F       ; putpad
add     sp, 2

loc_1CF60:
pop     si
pop     di
mov     sp, bp
pop     bp
retn
sub_1CE82 endp



; fprint
; Attributes: library function bp-based frame

sub_1CF66 proc near

var_2= word ptr -2
arg_0= word ptr  4

push    bp
mov     bp, sp
mov     ax, 2
call    __chkstk
mov     ax, word_1F050
mov     [bp+var_2], ax
cmp     word_1F052, 0
jnz     short loc_1CF82
mov     word_1F05A, 6

loc_1CF82:
push    word_1F046
push    word_1F05A
push    [bp+arg_0]
push    word_1F054
push    [bp+var_2]
call    sub_1D417
add     sp, 0Ah
cmp     [bp+arg_0], 'g'
jz      short loc_1CFA6
cmp     [bp+arg_0], 'G'
jnz     short loc_1CFBE

loc_1CFA6:
cmp     word_1F066, 0
jnz     short loc_1CFBE
cmp     word_1F05A, 0
jz      short loc_1CFBE
push    word_1F054
call    sub_1D417
add     sp, 2

loc_1CFBE:
cmp     word_1F066, 0
jz      short loc_1CFD6
cmp     word_1F05A, 0
jnz     short loc_1CFD6
push    word_1F054
call    sub_1D417
add     sp, 2

loc_1CFD6:
add     word_1F050, 8
mov     word_1F064, 0
mov     ax, word_1F058
or      ax, word_1F048
jz      short loc_1CFFC
push    [bp+var_2]
call    sub_1D417
add     sp, 2
or      ax, ax
jz      short loc_1CFFC
mov     ax, 1
jmp     short loc_1CFFE

loc_1CFFC:
sub     ax, ax

loc_1CFFE:
push    ax
call    sub_1D11F       ; _out
mov     sp, bp
pop     bp
retn
sub_1CF66 endp



; _outc
; Attributes: library function bp-based frame

sub_1D006 proc near

arg_0= byte ptr  4

push    bp
mov     bp, sp
xor     ax, ax
call    __chkstk
push    si
cmp     word_1F062, 0
jnz     short loc_1D04A
mov     bx, word_1F04A
dec     word ptr [bx+2]
js      short loc_1D030
mov     al, [bp+arg_0]
mov     bx, word_1F04A
mov     si, [bx]
inc     word ptr [bx]
mov     [si], al
sub     ah, ah
jmp     short loc_1D03D

loc_1D030:
push    word_1F04A
push    word ptr [bp+arg_0]
call    __flsbuf
add     sp, 4

loc_1D03D:
inc     ax
jnz     short loc_1D046
inc     word_1F062
jmp     short loc_1D04A

loc_1D046:
inc     word_1F060

loc_1D04A:
pop     si
mov     sp, bp
pop     bp
retn
sub_1D006 endp



; putpad
; Attributes: library function bp-based frame

sub_1D04F proc near

arg_0= word ptr  4

push    bp
mov     bp, sp
mov     ax, 2
call    __chkstk
push    di
push    si
cmp     word_1F062, 0
jnz     short loc_1D0AE
mov     si, [bp+arg_0]
or      si, si
jle     short loc_1D0AE
jmp     short loc_1D099

loc_1D06A:
mov     bx, word_1F04A
dec     word ptr [bx+2]
js      short loc_1D084
mov     al, byte ptr word_1F056
mov     bx, word_1F04A
mov     di, [bx]
inc     word ptr [bx]
mov     [di], al
sub     ah, ah
jmp     short loc_1D092

loc_1D084:
push    word_1F04A
push    word_1F056
call    __flsbuf
add     sp, 4

loc_1D092:
inc     ax
jnz     short loc_1D099
inc     word_1F062

loc_1D099:
mov     ax, si
dec     si
or      ax, ax
jg      short loc_1D06A
cmp     word_1F062, 0
jnz     short loc_1D0AE
mov     ax, [bp+arg_0]
add     word_1F060, ax

loc_1D0AE:
pop     si
pop     di
mov     sp, bp
pop     bp
retn
sub_1D04F endp



; putbuf
; Attributes: library function bp-based frame

sub_1D0B4 proc near

arg_0= dword ptr  4
arg_4= word ptr  8

push    bp
mov     bp, sp
mov     ax, 2
call    __chkstk
push    di
push    si
mov     si, [bp+arg_4]
cmp     word_1F062, 0
jnz     short loc_1D119
jmp     short loc_1D104

loc_1D0CB:
mov     bx, word_1F04A
dec     word ptr [bx+2]
js      short loc_1D0E8
les     bx, [bp+arg_0]
mov     al, es:[bx]
mov     bx, word_1F04A
mov     di, [bx]
inc     word ptr [bx]
mov     [di], al
sub     ah, ah
jmp     short loc_1D0FA

loc_1D0E8:
push    word_1F04A
les     bx, [bp+arg_0]
mov     al, es:[bx]
cbw
push    ax
call    __flsbuf
add     sp, 4

loc_1D0FA:
inc     ax
jnz     short loc_1D101
inc     word_1F062

loc_1D101:
inc     word ptr [bp+arg_0]

loc_1D104:
mov     ax, si
dec     si
or      ax, ax
jnz     short loc_1D0CB
cmp     word_1F062, 0
jnz     short loc_1D119
mov     ax, [bp+arg_4]
add     word_1F060, ax

loc_1D119:
pop     si
pop     di
mov     sp, bp
pop     bp
retn
sub_1D0B4 endp



; _out
; Attributes: library function bp-based frame

sub_1D11F proc near

var_8= word ptr -8
var_6= word ptr -6
var_4= word ptr -4
arg_0= word ptr  4

push    bp
mov     bp, sp
mov     ax, 0Ah
call    __chkstk
push    di
push    si
mov     si, word_1F054
sub     ax, ax
mov     [bp+var_4], ax
mov     [bp+var_8], ax
mov     di, word_1F05E
push    si
call    _strlen
add     sp, 2
mov     [bp+var_6], ax
sub     di, ax
sub     di, [bp+arg_0]
cmp     word_1F068, 0
jnz     short loc_1D168
cmp     byte ptr [si], '-'
jnz     short loc_1D168
cmp     word_1F056, '0'
jnz     short loc_1D168
lodsb
cbw
push    ax
call    sub_1D006       ; _outc
add     sp, 2
dec     [bp+var_6]

loc_1D168:
cmp     word_1F056, '0'
jz      short loc_1D17A
or      di, di
jle     short loc_1D17A
cmp     word_1F068, 0
jz      short loc_1D193

loc_1D17A:
cmp     [bp+arg_0], 0
jz      short loc_1D186
inc     [bp+var_8]
call    sub_1D1E7       ; putsign

loc_1D186:
cmp     word_1F064, 0
jz      short loc_1D193
inc     [bp+var_4]
call    sub_1D206       ; putprefix

loc_1D193:
cmp     word_1F068, 0
jnz     short loc_1D1C0
push    di
call    sub_1D04F       ; putpad
add     sp, 2
cmp     [bp+arg_0], 0
jz      short loc_1D1B0
cmp     [bp+var_8], 0
jnz     short loc_1D1B0
call    sub_1D1E7       ; putsign

loc_1D1B0:
cmp     word_1F064, 0
jz      short loc_1D1C0
cmp     [bp+var_4], 0
jnz     short loc_1D1C0
call    sub_1D206       ; putprefix

loc_1D1C0:
push    [bp+var_6]
mov     ax, si
push    ds
push    ax
call    sub_1D0B4       ; putbuf
add     sp, 6
cmp     word_1F068, 0
jz      short loc_1D1E1
mov     word_1F056, 20h ; ' '
push    di
call    sub_1D04F       ; putpad
add     sp, 2

loc_1D1E1:
pop     si
pop     di
mov     sp, bp
pop     bp
retn
sub_1D11F endp



; putsign
; Attributes: library function bp-based frame

sub_1D1E7 proc near
push    bp
mov     bp, sp
xor     ax, ax
call    __chkstk
cmp     word_1F058, 0
jz      short loc_1D1FB
mov     ax, 2Bh ; '+'
jmp     short loc_1D1FE

loc_1D1FB:
mov     ax, 20h ; ' '

loc_1D1FE:
push    ax
call    sub_1D006       ; _outc
mov     sp, bp
pop     bp
retn
sub_1D1E7 endp



; putprefix
; Attributes: library function bp-based frame

sub_1D206 proc near
push    bp
mov     bp, sp
xor     ax, ax
call    __chkstk
mov     ax, 30h ; '0'
push    ax
call    sub_1D006       ; _outc
add     sp, 2
cmp     word_1F064, 10h
jnz     short loc_1D235
cmp     word_1F046, 0
jz      short loc_1D22B
mov     ax, 'X'
jmp     short loc_1D22E

loc_1D22B:
mov     ax, 78h ; 'x'

loc_1D22E:
push    ax
call    sub_1D006       ; _outc
add     sp, 2

loc_1D235:
mov     sp, bp
pop     bp
retn
sub_1D206 endp



; getnum
; Attributes: library function bp-based frame

sub_1D239 proc near

arg_0= word ptr  4
arg_2= word ptr  6

push    bp
mov     bp, sp
mov     ax, 2
call    __chkstk
push    di
push    si
mov     si, [bp+arg_2]
cmp     byte ptr [si], '*'
jnz     short loc_1D25D
mov     bx, word_1F050
mov     al, [bx]
cbw
mov     di, ax
add     word_1F050, 2
inc     si
jmp     short loc_1D297

loc_1D25D:
sub     di, di
cmp     byte ptr [si], 30h ; '0'
jl      short loc_1D297
cmp     byte ptr [si], 39h ; '9'
jg      short loc_1D297
cmp     word_1F052, di
jnz     short loc_1D27A
cmp     byte ptr [si], 30h ; '0'
jnz     short loc_1D27A
mov     word_1F056, 30h ; '0'

loc_1D27A:
lodsb
cbw
mov     cx, di
shl     cx, 1
shl     cx, 1
add     cx, di
shl     cx, 1
add     cx, ax
sub     cx, 30h ; '0'
mov     di, cx
cmp     byte ptr [si], 30h ; '0'
jl      short loc_1D297
cmp     byte ptr [si], 39h ; '9'
jle     short loc_1D27A

loc_1D297:
mov     bx, [bp+arg_0]
mov     [bx], di
mov     ax, si
pop     si
pop     di
mov     sp, bp
pop     bp
retn
sub_1D239 endp



; flagchar
; Attributes: library function bp-based frame

sub_1D2A4 proc near

arg_0= byte ptr  4

push    bp
mov     bp, sp
mov     ax, 2
call    __chkstk
push    si
mov     si, offset asc_1EDF4 ; "+- #"
jmp     short loc_1D2C0

loc_1D2B3:
mov     al, [si]
cmp     [bp+arg_0], al
jnz     short loc_1D2BF
mov     ax, 1
jmp     short loc_1D2C7

loc_1D2BF:
inc     si

loc_1D2C0:
cmp     byte ptr [si], 0
jnz     short loc_1D2B3
sub     ax, ax

loc_1D2C7:
pop     si
mov     sp, bp
pop     bp
retn
sub_1D2A4 endp



; Attributes: library function

__setargv proc near
pop     word_1EDFA
mov     ds, __psp
assume ds:nothing
push    ss
pop     es
assume es:seg002
mov     si, 80h ; 'Ç'
lodsb
cbw
cmp     byte ptr es:__osmajor, 3
jb      short loc_1D328
push    ax
mov     es, ds:EnviroBlkSeg ; Segment of environment block
assume es:nothing
xor     ax, ax
mov     cx, ax
not     cx
mov     di, ax

loc_1D2F0:
repne scasb
cmp     es:[di], al
jnz     short loc_1D2F0
add     di, 3
mov     cx, ax
not     cx
push    di
repne scasb
pop     si
add     cx, 2
neg     cx
pop     bx
mov     ax, bx
add     ax, cx
add     ax, 3
and     ax, 0FFFEh
sub     sp, ax
mov     di, sp
push    ds
push    es
pop     ds
push    ss
pop     es
assume es:seg002
rep movsb
mov     al, 20h ; ' '
stosb
mov     cx, bx
pop     ds
mov     si, 81h ; 'ü'
jmp     short loc_1D336

loc_1D328:
mov     cx, ax
add     al, 4
and     al, 0FEh
sub     sp, ax
mov     di, sp
mov     ax, 2043h
stosw

loc_1D336:
rep movsb
mov     ax, cx
stosb
mov     si, sp
push    ss
pop     ds
assume ds:seg002
push    ax
mov     bx, sp

loc_1D342:
mov     di, si
lodsb
or      al, al
jz      short loc_1D369
call    sub_1D383
jz      short loc_1D342
dec     si
push    si
inc     ___argc

loc_1D354:
lodsb
call    sub_1D38A
stosb
or      al, al
jz      short loc_1D369
call    sub_1D383
jnz     short loc_1D354
mov     byte ptr [di-1], 0
jmp     short loc_1D342
stosb

loc_1D369:
mov     si, sp

loc_1D36B:
dec     bx
dec     bx
cmp     si, bx
jnb     short loc_1D379
lodsw
xchg    ax, [bx]
mov     [si-2], ax
jmp     short loc_1D36B

loc_1D379:
mov     bx, sp
mov     ___argv, sp
jmp     word_1EDFA
__setargv endp




sub_1D383 proc near
cmp     al, 9
jz      short locret_1D389
cmp     al, 20h ; ' '

locret_1D389:
retn
sub_1D383 endp




sub_1D38A proc near
cmp     al, '\'
jnz     short loc_1D396
cmp     byte ptr [si], '"'
jnz     short loc_1D396
lodsb
jmp     short locret_1D3B0

loc_1D396:
cmp     al, '"'
jnz     short locret_1D3B0

loc_1D39A:
lodsb
cmp     al, 0Dh
jz      short locret_1D3B0
cmp     al, '"'
jnz     short loc_1D3AA
cmp     byte ptr [si-2], '\'
jnz     short loc_1D3AD
dec     di

loc_1D3AA:
stosb
jmp     short loc_1D39A

loc_1D3AD:
lodsb
jmp     short sub_1D38A

locret_1D3B0:
retn
sub_1D38A endp



; Attributes: library function bp-based frame

__setenvp proc near
push    bp
mov     bp, sp
push    bp
mov     ds, __psp
assume ds:nothing
xor     cx, cx
mov     ax, cx
mov     bp, cx
mov     di, cx
dec     cx
mov     si, ds:EnviroBlkSeg ; Segment of environment block
or      si, si
jz      short loc_1D3D2
mov     es, si
assume es:nothing

loc_1D3CC:
repne scasb
inc     bp
scasb
jnz     short loc_1D3CC

loc_1D3D2:
inc     bp
xchg    ax, di
inc     ax
and     al, 0FEh
mov     di, bp
shl     bp, 1
add     ax, bp
push    ss
pop     ds
assume ds:seg002
push    di
mov     di, 9
call    __myalloc
pop     di
mov     cx, di
mov     di, bp
add     di, ax
mov     envp, bp
push    ds
pop     es
assume es:seg002
mov     ds, si
assume ds:nothing
xor     si, si
dec     cx
jcxz    short loc_1D40D

loc_1D3FA:
cmp     word ptr [si], 433Bh
jz      short loc_1D405
mov     [bp+0], di
inc     bp
inc     bp

loc_1D405:
lodsb
stosb
or      al, al
jnz     short loc_1D405
loop    loc_1D3FA

loc_1D40D:
mov     [bp+0], cx
push    ss
pop     ds
assume ds:seg002
pop     bp
mov     sp, bp
pop     bp
retn
__setenvp endp ; sp =  2




sub_1D417 proc near
call    sub_1D730
sub_1D417 endp



; Attributes: library function bp-based frame

_isatty proc near

arg_0= word ptr  4

push    bp
mov     bp, sp
mov     bx, [bp+arg_0]
cmp     bx, 14h
jge     short loc_1D436
cmp     bx, 0
jl      short loc_1D436
test    IOCTLFlags[bx], 40h
jz      short loc_1D436
mov     ax, 1
jmp     short loc_1D438

loc_1D436:
xor     ax, ax

loc_1D438:
mov     sp, bp
pop     bp
retn
_isatty endp



; Attributes: library function bp-based frame

_free proc near

arg_0= word ptr  4

push    bp
mov     bp, sp
mov     bx, [bp+arg_0]
or      byte ptr [bx-2], 1
mov     sp, bp
pop     bp
retn
_free endp



; Attributes: library function bp-based frame

_malloc proc near

arg_0= word ptr  4

push    bp
mov     bp, sp
push    si
push    di
mov     bx, offset __asegds
cmp     word ptr [bx], 0
jnz     short loc_1D480
push    ds
pop     es
mov     ax, 5
call    __amallocbrk
jnz     short loc_1D466
xor     ax, ax
cwd
jmp     short loc_1D48A

loc_1D466:
inc     ax
and     al, 0FEh
mov     __asegds, ax
mov     word_1EF1A, ax
xchg    ax, si
mov     word ptr [si], 1
add     si, 4
mov     word ptr [si-2], 0FFFEh
mov     word_1EF1E, si

loc_1D480:
mov     cx, [bp+arg_0]
mov     ax, ds
mov     es, ax
call    __amalloc

loc_1D48A:
pop     di
pop     si
mov     sp, bp
pop     bp
retn
_malloc endp



; Attributes: library function

__myalloc proc near
mov     dx, ax
add     ax, word_1EC36
jb      short loc_1D4CD
cmp     word_1EC32, ax
jnb     short loc_1D4C3
add     ax, 0Fh
push    ax
rcr     ax, 1
mov     cl, 3
shr     ax, cl
mov     cx, ds
mov     bx, __psp
sub     cx, bx
add     ax, cx
mov     es, bx
assume es:nothing
mov     bx, ax
mov     ah, 4Ah
int     21h             ; DOS - 2+ - ADJUST MEMORY BLOCK SIZE (SETBLOCK)
                        ; ES = segment address of block to change
                        ; BX = new size in paragraphs
pop     ax
jb      short loc_1D4CD
and     al, 0F0h
dec     ax
mov     word_1EC32, ax

loc_1D4C3:
xchg    ax, bp
mov     bp, word_1EC36
add     word_1EC36, dx
retn

loc_1D4CD:
mov     ax, di
jmp     __amsg_exit
__myalloc endp



; Attributes: library function bp-based frame

_strlen proc near

arg_0= word ptr  4

push    bp
mov     bp, sp
push    di
push    ds
pop     es
assume es:seg002
mov     di, [bp+arg_0]
xor     ax, ax
mov     cx, 0FFFFh
repne scasb
mov     ax, cx
inc     ax
inc     ax
neg     ax
pop     di
mov     sp, bp
pop     bp
retn
_strlen endp



; Attributes: library function bp-based frame

_ultoa proc near
push    bp
mov     bp, sp
push    si
push    di
mov     bl, 0
jmp     __cltoasub
_ultoa endp



; Attributes: library function bp-based frame

_write proc near

arg_0= word ptr  4
arg_2= word ptr  6
arg_4= word ptr  8

push    bp
mov     bp, sp
mov     bx, [bp+arg_0]
test    IOCTLFlags[bx], 20h
jz      short loc_1D512
mov     ax, 4202h
xor     cx, cx
mov     dx, cx
int     21h             ; DOS - 2+ - MOVE FILE READ/WRITE POINTER (LSEEK)
                        ; AL = method: offset from end of file
jnb     short loc_1D512
jmp     __dosretax

loc_1D512:
test    IOCTLFlags[bx], 80h
jnz     short loc_1D51C
jmp     loc_1D59D

loc_1D51C:
mov     cx, [bp+arg_4]
mov     dx, [bp+arg_2]
push    ds
pop     es
xor     ax, ax
cld
push    di
push    si
mov     si, ax
mov     di, dx

loc_1D52D:
jcxz    short loc_1D594
mov     ax, 400Ah
repne scasb
jnz     short loc_1D568
push    cx
mov     cx, di
sub     cx, dx
dec     cx
jcxz    short loc_1D54E
int     21h             ; DOS - 2+ - WRITE TO FILE WITH HANDLE
                        ; BX = file handle, CX = number of bytes to write, DS:DX -; buffer
pushf
add     si, ax
popf
jnb     short loc_1D54A
mov     ah, 9
jmp     short loc_1D593

loc_1D54A:
or      ax, ax
jz      short loc_1D57D

loc_1D54E:
inc     si
mov     cx, 2
mov     dx, offset unk_1EF22
mov     ah, 40h
int     21h             ; DOS - 2+ - WRITE TO FILE WITH HANDLE
                        ; BX = file handle, CX = number of bytes to write, DS:DX -; buffer
jnb     short loc_1D55F
mov     ah, 9
jmp     short loc_1D593

loc_1D55F:
or      ax, ax
jz      short loc_1D57D
pop     cx
mov     dx, di
jmp     short loc_1D52D

loc_1D568:
push    cx
mov     cx, di
sub     cx, dx
int     21h             ; DOS - PRINT STRING
                        ; DS:DX -; string terminated by "$"
pushf
add     si, ax
popf
jnb     short loc_1D579
mov     ah, 9
jmp     short loc_1D593

loc_1D579:
or      ax, ax
jnz     short loc_1D593

loc_1D57D:
test    IOCTLFlags[bx], 40h
jz      short loc_1D58F
mov     bx, [bp+arg_2]
cmp     byte ptr [bx], 1Ah
jnz     short loc_1D58F
clc
jmp     short loc_1D593

loc_1D58F:
stc
mov     ax, 1C00h

loc_1D593:
pop     cx

loc_1D594:
jb      short loc_1D598
mov     ax, si

loc_1D598:
pop     si
pop     di

loc_1D59A:
jmp     __dosretax

loc_1D59D:
mov     cx, [bp+arg_4]
or      cx, cx
jnz     short loc_1D5A9
mov     ax, cx
jmp     __dosretax

loc_1D5A9:
mov     dx, [bp+arg_2]
mov     ah, 40h
int     21h             ; DOS - 2+ - WRITE TO FILE WITH HANDLE
                        ; BX = file handle, CX = number of bytes to write, DS:DX -; buffer
jnb     short loc_1D5B6
mov     ah, 9
jmp     short loc_1D59A

loc_1D5B6:
or      ax, ax
jnz     short loc_1D59A
test    IOCTLFlags[bx], 40h
jz      short loc_1D5CB
mov     bx, dx
cmp     byte ptr [bx], 1Ah
jnz     short loc_1D5CB
clc
jmp     short loc_1D59A

loc_1D5CB:
stc
mov     ax, 1C00h
jmp     short loc_1D59A
_write endp


loc_1D5D1:
jmp     loc_1D6A0


; Attributes: library function

__amalloc proc near
cmp     cx, 0FFEEh
jnb     short loc_1D5D1
inc     cx
and     cl, 0FEh
mov     si, [bx+2]
cld
lodsw
mov     di, si
test    al, 1
jz      short loc_1D62A

loc_1D5E8:
dec     ax
cmp     ax, cx
jnb     short loc_1D602
mov     dx, ax
add     si, ax
lodsw
test    al, 1
jz      short loc_1D62A
add     ax, dx
add     ax, 2
mov     si, di
mov     [si-2], ax
jmp     short loc_1D5E8

loc_1D602:
mov     di, si
jz      short loc_1D612
add     di, cx
mov     [si-2], cx
sub     ax, cx
dec     ax
mov     [di], ax
jmp     short loc_1D617

loc_1D612:
add     di, cx
dec     byte ptr [si-2]

loc_1D617:
mov     ax, si
mov     dx, ds
mov     cx, ss
cmp     dx, cx
jz      short loc_1D626
mov     es:word_1EF28, ds

loc_1D626:
mov     [bx+2], di
retn

loc_1D62A:
mov     es:byte_1EF2C, 2

loc_1D630:
cmp     ax, 0FFFEh
jz      short loc_1D65A
mov     di, si
add     si, ax

loc_1D639:
lodsw
test    al, 1
jz      short loc_1D630
mov     di, si

loc_1D640:
dec     ax
cmp     ax, cx
jnb     short loc_1D602
mov     dx, ax
add     si, ax
lodsw
test    al, 1
jz      short loc_1D630
add     ax, dx
add     ax, 2
mov     si, di
mov     [si-2], ax
jmp     short loc_1D640

loc_1D65A:
mov     ax, [bx+8]
or      ax, ax
jz      short loc_1D665
mov     ds, ax
assume ds:nothing
jmp     short loc_1D679

loc_1D665:
dec     es:byte_1EF2C
jz      short loc_1D67D
mov     ax, ds
mov     di, ss
cmp     ax, di
jz      short loc_1D679
mov     ds, es:word_1EF24
assume ds:nothing

loc_1D679:
mov     si, [bx]
jmp     short loc_1D639

loc_1D67D:
mov     si, [bx+6]
xor     ax, ax
call    __amlink
cmp     ax, si
jz      short loc_1D696
and     al, 1
inc     ax
inc     ax
cbw
call    __amlink
jz      short loc_1D6A0
dec     byte ptr [di-2]

loc_1D696:
call    __amexpand
jz      short loc_1D6A0
xchg    ax, si
dec     si
dec     si
jmp     short loc_1D639

loc_1D6A0:
mov     ax, ds
mov     cx, ss
cmp     ax, cx
jz      short loc_1D6AC
mov     es:word_1EF28, ax

loc_1D6AC:
mov     ax, [bx]
mov     [bx+2], ax
xor     ax, ax
cwd
retn
__amalloc endp



; Attributes: library function

__amexpand proc near
push    cx
mov     ax, [di-2]
test    al, 1
jz      short loc_1D6C0
sub     cx, ax
dec     cx

loc_1D6C0:
inc     cx
inc     cx
mov     dx, 7FFFh

loc_1D6C5:
cmp     dx, es:word_1EF2A
jbe     short loc_1D6D0
shr     dx, 1
jnz     short loc_1D6C5

loc_1D6D0:
mov     ax, cx
add     ax, si
jb      short loc_1D6EB
add     ax, dx
jb      short loc_1D6E7
not     dx
and     ax, dx
sub     ax, si
call    __amlink
jnz     short loc_1D6ED
not     dx

loc_1D6E7:
shr     dx, 1
jnz     short loc_1D6D0

loc_1D6EB:
xor     ax, ax

loc_1D6ED:
pop     cx
retn
__amexpand endp



; Attributes: library function

__amlink proc near
push    dx
push    cx
call    __amallocbrk
jz      short loc_1D70E
push    di
mov     di, si
mov     si, ax
add     si, dx
mov     word ptr [si-2], 0FFFEh
mov     [bx+6], si
mov     dx, si
sub     dx, di
dec     dx
mov     [di-2], dx
pop     ax

loc_1D70E:
pop     cx
pop     dx
retn
__amlink endp



; Attributes: library function

__amallocbrk proc near
push    bx
push    ax
xor     dx, dx
push    ds
push    dx
push    dx
push    ax
mov     ax, 1
push    ax
push    es
pop     ds
assume ds:seg002
call    _brkctl
add     sp, 8
cmp     dx, 0FFFFh
pop     ds
assume ds:nothing
pop     dx
pop     bx
jz      short locret_1D72F
or      dx, dx

locret_1D72F:
retn
__amallocbrk endp




sub_1D730 proc near
mov     ax, 2
jmp     __amsg_exit
sub_1D730 endp



; Attributes: library function bp-based frame

_flushall proc near
push    bp
mov     bp, sp
sub     sp, 4
push    di
push    si
mov     si, offset unk_1EDFE
sub     di, di
jmp     short loc_1D759

loc_1D745:
test    byte ptr [si+6], 83h
jz      short loc_1D756
push    si
call    _fflush
add     sp, 2
inc     ax
jz      short loc_1D756
inc     di

loc_1D756:
add     si, 8

loc_1D759:
cmp     ds:word_1EF16, si
jnb     short loc_1D745
mov     ax, di
pop     si
pop     di
mov     sp, bp
pop     bp
retn
_flushall endp


__cltoasub:
mov     cx, [bp+0Ah]
mov     ax, [bp+4]
mov     dx, [bp+6]
mov     di, [bp+8]

__cxtoa:
push    di
push    ds
pop     es
assume es:nothing
cld
xchg    ax, bx
or      al, al
jz      short loc_1D78F
cmp     cx, 0Ah
jnz     short loc_1D78F
or      dx, dx
jns     short loc_1D78F
mov     al, 2Dh ; '-'
stosb
neg     bx
adc     dx, 0
neg     dx

loc_1D78F:
mov     si, di

loc_1D791:
xchg    ax, dx
xor     dx, dx
or      ax, ax
jz      short loc_1D79A
div     cx

loc_1D79A:
xchg    ax, bx
div     cx
xchg    ax, dx
xchg    dx, bx
add     al, 30h ; '0'
cmp     al, 39h ; '9'
jbe     short loc_1D7A8
add     al, 27h ; '''

loc_1D7A8:
stosb
mov     ax, dx
or      ax, bx
jnz     short loc_1D791
mov     [di], al
dec     di

loc_1D7B2:
lodsb
xchg    al, [di]
mov     [si-1], al
dec     di
cmp     si, di
jb      short loc_1D7B2
pop     ax
pop     di
pop     si
mov     sp, bp
pop     bp
retn


; Attributes: library function bp-based frame

_brkctl proc near

arg_0= word ptr  4
arg_2= word ptr  6
arg_4= word ptr  8
arg_8= word ptr  0Ch

push    bp
mov     bp, sp
push    si
push    di
push    es
cmp     [bp+arg_4], 0
jnz     short loc_1D808
mov     di, offset word_1EC36
mov     dx, [bp+arg_2]
mov     ax, [bp+arg_0]
dec     ax
jnz     short loc_1D7E3
call    sub_1D832
jb      short loc_1D808
jmp     short loc_1D82B

loc_1D7E3:
mov     si, ds:word_1EC86
dec     ax
jz      short loc_1D7FB
cmp     si, di
jz      short loc_1D7FB
mov     ax, [si+2]
mov     [bp+arg_8], ax
push    si
call    sub_1D832
pop     si
jnb     short loc_1D82B

loc_1D7FB:
add     si, 4
cmp     si, offset word_1EC86
jnb     short loc_1D808
or      dx, dx
jnz     short loc_1D80E

loc_1D808:
mov     ax, 0FFFFh
cwd
jmp     short loc_1D82B

loc_1D80E:
mov     bx, dx
add     bx, 0Fh
rcr     bx, 1
mov     cl, 3
shr     bx, cl
mov     ah, 48h
int     21h             ; DOS - 2+ - ALLOCATE MEMORY
                        ; BX = number of 16-byte paragraphs desired
jb      short loc_1D808
xchg    ax, dx
mov     [si], ax
mov     [si+2], dx
mov     ds:word_1EC86, si
xor     ax, ax

loc_1D82B:
pop     es
assume es:nothing
pop     di
pop     si
mov     sp, bp
pop     bp
retn
_brkctl endp

; [00000056 BYTES: COLLAPSED FUNCTION sub_1D832. PRESS KEYPAD "+" TO EXPAND]


; Attributes: library function bp-based frame

_fflush proc near

var_4= word ptr -4
arg_0= word ptr  4

push    bp
mov     bp, sp
sub     sp, 4
push    di
push    si
mov     si, [bp+arg_0]
sub     di, di
mov     al, [si+6]
and     al, 3
cmp     al, 2
jnz     short loc_1D8DE
test    byte ptr [si+6], 8
jnz     short loc_1D8B7
mov     al, [si+7]
cbw
mov     bx, ax
shl     bx, 1
add     bx, ax
shl     bx, 1
test    ds:byte_1EE9E[bx], 1
jz      short loc_1D8DE

loc_1D8B7:
mov     ax, [si]
sub     ax, [si+4]
mov     [bp+var_4], ax
or      ax, ax
jle     short loc_1D8DE
push    ax
push    word ptr [si+4]
mov     al, [si+7]
cbw
push    ax
call    _write
add     sp, 6
cmp     ax, [bp+var_4]
jz      short loc_1D8DE
or      byte ptr [si+6], 20h
mov     di, 0FFFFh

loc_1D8DE:
mov     ax, [si+4]
mov     [si], ax
mov     word ptr [si+2], 0
mov     ax, di
pop     si
pop     di
mov     sp, bp
pop     bp
retn
_fflush endp

seg001 ends


; Segment type: Regular
seg002 segment byte public 'UNK' use16
assume cs:seg002
assume es:nothing, ss:nothing, ds:nothing, fs:nothing, gs:nothing
db    0
unk_1D8F1 db    0
unk_1D8F2 db    0
unk_1D8F3 db    0
unk_1D8F4 db    0
unk_1D8F5 db    0
unk_1D8F6 db    0
unk_1D8F7 db    0
aCLibraryCCopyr db 'C Library - (C)Copyright Microsoft '
db 'Corp 1986'
db  1Fh
db    0
unk_1D926 db    0
db    0
db    0
unk_1D929 db    0
unk_1D92A db    0
db    0
unk_1D92C db    0
unk_1D92D db    0
unk_1D92E db    0
db    0
word_1D930 dw 0
word_1D932 dw 0
word_1D934 dw 0
word_1D936 dw 0
unk_1D938 db    0
unk_1D939 db    0
unk_1D93A db    0
db    0
db    0
db    0
db    0
db 0
db    0
db    0
aC_img db 'C:*.IMG',0
unk_1D94A db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
aEnterNewImageN db 'Enter New Image Name ;',0
unk_1D971 db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db 0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
word_1E2B2 dw 0
byte_1E2B4 db 0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
byte_1E2D4 db 0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
aBadFilename db 'Bad Filename',0
aFileExists db 'File Exists',0
aCreateFailure db 'Create Failure',0
aInfo db 'Info;',0
aNoImageAvailab db 'No Image Available',0
aCS_img db '%c:%s.IMG',0
asc_1E81F db ':',0
aInfo_0 db 'Info ;',0
aDm db 'DM',0
aCr db 'CR',0
aLoadingImageS_ db 'Loading Image %s ...',0
aSEnterToContin db '%s - [Enter] To Continue',0
DiskXferBuff db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
unk_1E888 db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
asc_1E8D8 db '+----------------------------------'
db '-----------+',0
asc_1E908 db '¦                                  '
db '           ¦',0
asc_1E938 db '¦----------------------------------'
db '-----------¦',0
asc_1E968 db '+----------------------------------'
db '-----------+',0
byte_1E998 db 0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db  8Fh ; Å
db 0D1h ; -
db 0D8h ; +
db 0C5h ; +
db 0D2h ; -
db 0D4h ; +
db 0D9h ; +
db 0D5h ; +
db 0C9h ; +
db 0CFh ; -
db 0D0h ; -
db    0
db    0
db    0
db    0
db 0C1h ; -
db 0D3h ; +
db 0C4h ; -
db 0C6h ; ¦
db 0C7h ; ¦
db 0C8h ; +
db 0CAh ; -
db 0CBh ; -
db 0CCh ; ¦
db    0
db    0
db    0
db    0
db    0
db 0DAh ; +
db 0D8h ; +
db 0C3h ; +
db 0D6h ; +
db 0C2h ; -
db 0CEh ; +
db 0CDh ; -
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db  80h ; Ç
db  81h ; ü
db  82h ; é
db  83h ; â
db  84h ; ä
db  85h ; à
db  86h ; å
db  87h ; ç
db  88h ; ê
db  89h ; ë
db    0
db    0
db  8Ah ; è
db  8Dh ; ì
db  9Ah ; Ü
db    0
db  8Bh ; ï
db    0
db  9Bh ; ¢
db    0
db  8Ch ; î
db  8Eh ; Ä
db  9Ch ; £
db  9Dh ; ¥
db  9Eh ; P
db  90h ; É
db  91h ; æ
db  92h ; Æ
db  93h ; ô
db  94h ; ö
db  95h ; ò
db  96h ; û
db  97h ; ù
db  98h ; ÿ
db  99h ; Ö
db 0A0h ; á
db 0A1h ; í
db 0A2h ; ó
db 0A3h ; ú
db 0A4h ; ñ
db 0A5h ; Ñ
db 0A6h ; ª
db 0A7h ; º
db 0A8h ; ¿
db 0A9h ; ¬
db 0E0h ; a
db 0E1h ; ß
db 0E2h ; G
db 0E3h ; p
db 0E4h ; S
db 0E5h ; s
db 0E6h ; µ
db 0E7h ; t
db 0E8h ; F
db 0E9h ; T
db 0AEh ; «
db 0ABh ; ½
db 0BBh ; +
db 0ACh ; ¼
db 0BCh ; +
db 0AAh ; ¬
db 0B1h ; ¦
db 0B2h ; ¦
db 0B3h ; ¦
db 0B4h ; ¦
db 0B5h ; ¦
db 0B6h ; ¦
db 0B7h ; +
db 0B8h ; +
db 0B9h ; ¦
db 0B0h ; ¦
db 0BDh ; +
db 0BEh ; +
db 0BAh ; ¦
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
DiskXferBuf2 db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
word_1EC30 dw 1C80h
word_1EC32 dw 0
word_1EC34 dw 0
word_1EC36 dw 0
dw seg seg002
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
word_1EC86 dw 1346h
db    0
asc_1EC89 db '         (((((                  H'
db  10h
db  10h
db  10h
db  10h
db  10h
db  10h
db  10h
db  10h
db  10h
db  10h
db  10h
db  10h
db  10h
db  10h
db  10h
db  84h ; ä
db  84h ; ä
db  84h ; ä
db  84h ; ä
db  84h ; ä
db  84h ; ä
db  84h ; ä
db  84h ; ä
db  84h ; ä
db  84h ; ä
db  10h
db  10h
db  10h
db  10h
db  10h
db  10h
db  10h
db  81h ; ü
db  81h ; ü
db  81h ; ü
db  81h ; ü
db  81h ; ü
db  81h ; ü
db    1
db    1
db    1
db    1
db    1
db    1
db    1
db    1
db    1
db    1
db    1
db    1
db    1
db    1
db    1
db    1
db    1
db    1
db    1
db    1
db  10h
db  10h
db  10h
db  10h
db  10h
db  10h
db  82h ; é
db  82h ; é
db  82h ; é
db  82h ; é
db  82h ; é
db  82h ; é
db    2
db    2
db    2
db    2
db    2
db    2
db    2
db    2
db    2
db    2
db    2
db    2
db    2
db    2
db    2
db    2
db    2
db    2
db    2
db    2
db  10h
db  10h
db  10h
db  10h
db  20h
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
unk_1ED8A db  3Bh ; ;
aC_file_info db 'C_FILE_INFO'
OldInt0Vector dd 0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
word_1EDA2 dw 0
db    0
db    0
db    0
db    0
__psp dw 0
__osmajor dw 0
byte_1EDAC db 0
db    0
IOCTLFlags db 3 dup(81h), 2 dup(1) ; 1 byte per file handle, bit 6 is character/file flag, other bits not known yet.
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
___argc dw 0
___argv dw 0
envp dw 0               ; the name is a guess
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
unk_1EDD2 db    0
db  16h
db    2
db    2
db  18h
db  0Dh
db    9
db  0Ch
db  0Ch
db  0Ch
db    7
db    8
db 0FFh
db 0FFh
db 0FFh
db  12h
db  0Dh
db  12h
db    2
db 0FFh
aNull db '(null)',0
aNull_0 db '(null)',0
asc_1EDF4 db '+- #',0
db    0
word_1EDFA dw 0
word_1EDFC dw 0
unk_1EDFE db  80h ; Ç
db  19h
db    0
db    0
db  80h ; Ç
db  19h
db    1
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    2
db    1
db    0
db    0
db    0
db    0
db    0
db    0
db    6
db    2
db    0
db    0
db    0
db    0
db    0
db    0
db  84h ; ä
db    3
db    0
db    0
db    0
db    0
db    0
db    0
db    2
db    4
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
byte_1EE9E db 1
db    0
word_1EEA0 dw 200h
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
db    0
word_1EF16 dw 15A6h
__asegds dw 0
word_1EF1A dw 0
db    0
db    0
word_1EF1E dw 0
db    0
db    0
unk_1EF22 db  0Dh
db  0Ah
word_1EF24 dw 0
align 4
word_1EF28 dw 0
word_1EF2A dw 2000h
byte_1EF2C db 0
align 4
unk_1EF30 db    0
db    0
word_1EF32 dw 0
dword_1EF34 dd 0
dword_1EF38 dd 0
off_1EF3C dw offset _flushall
aNmsg db '<<NMSG;;'
Nmsg_Text dw 1          ; NMSG1
aError2001NullP db 0Dh,0Ah
db 'error 2001: Null pointer assignment'
db 0Dh,0Ah,0
dw 0                    ; NMSG0
aError2000Stack db 0Dh,0Ah
db 'error 2000: Stack overflow',0Dh,0Ah,0
dw 3                    ; NMSG3
aError2003Integ db 0Dh,0Ah
db 'error 2003: Integer divide by 0',0Dh,0Ah,0
dw 4                    ; NMSG4
aError2004Dos2_ db 0Dh,0Ah
db 'error 2004: DOS 2.0 or later requir'
db 'ed',0Dh,0Ah
db '$',0
dw 9                    ; NMSG9
aError2009NotEn db 0Dh,0Ah
db 'error 2009: Not enough space for en'
db 'vironment',0Dh,0Ah,0
dw 2                    ; NMSG2
aError2002Float db 0Dh,0Ah
db 'error 2002: Floating point not load'
db 'ed',0Dh,0Ah,0
db 0FFh
db 0FFh
db 0FFh
word_1F046 dw 0
word_1F048 dw 0
word_1F04A dw 0
word_1F04C dw 0
word_1F04E dw 0
word_1F050 dw ?
word_1F052 dw ?
word_1F054 dw ?
word_1F056 dw ?
word_1F058 dw ?
word_1F05A dw ?
word_1F05C dw ?
word_1F05E dw ?
word_1F060 dw ?
word_1F062 dw ?
word_1F064 dw ?
word_1F066 dw ?
word_1F068 dw ?
unk_1F06A db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
db    ? ;
TopOfStack db    ? ;
db    ? ;
seg002 ends


; Segment type: Uninitialized
seg003 segment byte stack 'STACK' use16
assume cs:seg003
assume es:nothing, ss:nothing, ds:nothing, fs:nothing, gs:nothing
db 400h dup(?)
seg003 ends


end start