home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / BEEHIVE / OS / Z80D24SR.ARC / Z80DCHAR.Z80 < prev    next >
Text File  |  1991-02-10  |  20KB  |  746 lines

  1. ;
  2. ; Z80DOS - Z80 Disk Operating System
  3. ;
  4. ; Version 2.4    Maskable disk reset's using variable fixdrv
  5. ;        Now can assemble with Z80MR if Z80MR equate
  6. ;        set to -1.
  7. ;        Gene Nolan 4/9/89
  8. ;
  9. ;------------------------------------------------------
  10. ;
  11. ; Version 2.3    Fast file lookup, ZRL compatability
  12. ; Date:        4 Nov 88
  13. ; Update:    Eugene Nolan
  14. ;
  15. ;------------------------------------------------------------
  16. ;
  17. ; Version 2.0a - BETA TEST VERSION - 6 Nov 87 by Carson Wilson
  18. ;
  19. ; Support file:    Z80DCHAR.Z80
  20. ; Version:    2.0
  21. ; Date:        6 Nov 87
  22. ; Author:    Carson Wilson
  23. ; Changes:    Combined BIOS read and write error messages into one
  24. ;        message - "Data error" so that BDOS error intecepts
  25. ;        work same as standard CP/M.
  26. ;
  27. ;        Added disk changed error routine.
  28. ;
  29. ; Description:    DOS Entry Points, Character I/O, and Error Routines
  30. ;
  31. ; Use ONE only of the following lines:
  32. ;---------------------------------------------
  33. ; Use following line for assembly to .COM file, comment it out for a .ZRL
  34.     org    DOS
  35.  
  36.     db    'Z80D24'
  37.  
  38. ;---------------------------------------------
  39. ;
  40. ; Start DOS
  41. ;
  42.  
  43. start:    jp    entry            ; Jump to entry point DOS
  44.  
  45. ;
  46. ; Error messages DOS - for programs which intercept DOS errors
  47. ;
  48. StRW:    defw    RWErr            ; Read or write error
  49. StSel:    defw    SelErr            ; Select error
  50. stro:    defw    rdonly            ; Drive read only
  51. sfilro:    defw    filro            ; File read only
  52.  
  53. ;
  54. ; Run-time configurable options:
  55. ;
  56. timead:
  57.      if    RTC
  58.     defw    BIOStim            ; Dummy or address of BIOS routine
  59.      else
  60.     defw    0
  61.      endif    ;RTC
  62.  
  63. fixdrvs:
  64.     dw    0            ; This word specifies fixed drives, ie:
  65.                     ; ones that do not need their ALV's
  66.                     ; re-built for every non-specific
  67.                     ; BDOS disk reset command. Set to
  68.                     ; 1 the bits for drives not to be reset
  69.                     ; 1=A; 3=A,B, 5=A,C etc
  70.  
  71.  
  72. flags:    defb    options            ; Flag byte for public and ^S interrupt
  73.  
  74. ; ----------------------------------------------------------------------
  75.  
  76. ; RAM area
  77.  
  78. ; -------------
  79.  
  80. tabcnt:    defb    0            ; Tab counter
  81. tabcx1:    defb    0            ; Temporary tab counter (used by rdbuf)
  82. fcontp:    defb    0            ; List enable flag (control p)
  83. lastch:    defb    0            ; Last character
  84. delay:    defb    0ffh            ; Delay counter
  85. ;
  86. trans:    defw    0            ; Translation vector
  87. temp0:    defw    0            ; Number of files on drive
  88. dirbuf:    defw    0            ; Directory buffer
  89. ixp:    defw    0            ; Disk parameter block
  90. csv:    defw    0            ; Checksum pointer
  91. alv:    defw    0            ; Allocation vector pointer
  92. ;
  93. maxsec:    defw    0            ; Maximum number of sectors/track
  94. nblock:    defb    0            ; Number of blocks
  95. nmask:    defb    0            ; Mask number of blocks
  96. nextnd:    defb    0            ; Extent mask
  97. maxlen:    defw    0            ; Maximum block number-1
  98. nfiles:    defw    0            ; Maximum number of files-1
  99. ndir0:    defb    0            ; First two entries alv buffer
  100. ndir1:    defb    0
  101. ncheck:    defw    0            ; Number of checksum entries
  102. nftrk:    defw    0            ; First track number
  103. ;
  104. dskro:    defw    0            ; Disk R/O vector
  105. login:    defw    0            ; Login vector
  106. diff:    defw    0            ; Disk changed vector <crw>
  107. ;
  108. DMA:    defw    080h            ; DMA address
  109. ;
  110. funct:    defb    0            ; Function number
  111. pexit:    defw    0            ; Exit code
  112. fldrv:    defb    0            ; Drive select used flag
  113. rdwr:    defb    0            ; Read/write flag
  114. ;
  115. FCB0:    defb    0            ; FCB byte 0
  116. user:    defb    0            ; User number
  117. drive:    defb    0            ; Drive number
  118. defdrv:    defb    0            ; Default drive number
  119. recdir:    defw    0            ; Record directory (checksum)
  120. filcnt:    defw    0            ; File counter
  121. secpnt:    defb    0            ; Sector pointer
  122. subflg:    defb    0            ; Submit flag (reset disk command)
  123. ;
  124. dcopy:    defw    0            ; Copy address FCB
  125. searex:    defb    0            ; Exit code search
  126. searnb:    defb    0            ; Search number of bytes
  127. searqu:    defb    0            ; Search question mark used
  128. searpu:    defb    0            ; Search public file
  129. ;
  130. retflg:    db    0            ; Allow retry on error when non-zero
  131. ;
  132. dtime    db    0            ; Flag for UseStp <crw>
  133. cdate    ds    2            ; Create date storage
  134. udate    ds    4            ; Update date/time
  135. adate    ds    4            ; Last access date/time <crw>
  136. ;
  137. spsave:    defw    0            ; Stack pointer location
  138.     defs    54
  139. DOSstk:    equ    $            ; DOS internal 64 byte stack
  140. DOSstop    equ    $
  141. ;
  142.  
  143. ;
  144. ; Entry point for DOS commands
  145. ;
  146. Entry:    ld    a,c            ; Get function number
  147.     ld    (funct),a        ; Save it for later use
  148.     ld    hl,0            ; Set hl to zero
  149.     ld    (pexit),hl        ; Clear exit code
  150.     ld    (fldrv),hl
  151.     ld    b,l
  152.     ld    (spsave),sp        ; Save stack pointer
  153.     ld    sp,DOSstk            ; Get internal stack pointer
  154.     push    ix            ; Save index register
  155.     push    de            ; Save parameter register
  156.     pop    ix            ; Get it back in ix
  157.     ld    hl,p2exit        ; Get exit address DOS
  158.     push    hl            ; Save it on stack to return from DOS
  159.     cp    maxcmd+1
  160.     jr    C,lowcmd
  161.     cp    105            ; Test get time <crw>
  162.     jp    Z,gettim        ; Yes then get time
  163.     cp    104            ; Test set time <crw>
  164.     jp    Z,settim        ; Yes then set time
  165.     cp    55            ; Test use time stamp <crw>
  166.     jp    Z,UseStp
  167.     cp    54            ; Test get time stamp <crw>
  168.     jp    Z,Getstp
  169.     ret
  170. lowcmd:    ld    hl,ctable        ; Load table
  171.     add    a,c
  172.     ld    c,a
  173.     add    hl,bc            ; Add
  174.     ld    a,(hl)            ; Get LSB
  175.     inc    hl            ; Pointer to MSB
  176.     ld    h,(hl)            ; Get MSB
  177.     ld    l,a            ; Save LSB in l
  178.     jp    (hl)            ; Jump to routine
  179. ;
  180. ; Command Jump Table
  181. ;
  182. CTable:    defw    WBoot            ; Warm boot
  183.     defw    rdcon            ; Console input
  184.     defw    bwrcon            ; Console output
  185.     defw    rdrdr            ; Reader input
  186.     defw    wpunch            ; Punch output
  187.     defw    wlist            ; List output
  188.     defw    dcio            ; Direct console I/O
  189.     defw    giost            ; Get I/O byte
  190.     defw    siost            ; Set I/O byte
  191.     defw    mess            ; Print string
  192.     defw    rdbuf            ; Read console buffer
  193.     defw    tstcs            ; Get console status
  194.     defw    cmnd12            ; Return version number
  195.     defw    cmnd13            ; Reset disk system
  196.     defw    cmnd14            ; Select disk
  197.     defw    cmnd15            ; Open file
  198.     defw    cmnd16            ; Close file
  199.     defw    cmnd17            ; Search for first
  200.     defw    cmnd18            ; Search for next
  201.     defw    cmnd19            ; Delete file
  202.     defw    cmnd20            ; Read sequential
  203.     defw    cmnd21            ; Write sequential
  204.     defw    cmnd22            ; Make file
  205.     defw    cmnd23            ; Rename file
  206.     defw    cmnd24            ; Return login vector
  207.     defw    cmnd25            ; Return current disk
  208.     defw    cmnd26            ; Set DMA address
  209.     defw    cmnd27            ; Get address allocation vector
  210.     defw    cmnd28            ; Write protect disk
  211.     defw    cmnd29            ; Get R/O vector
  212.     defw    cmnd30            ; Set file attributes
  213.     defw    cmnd31            ; Get address disk parameter header(dph)
  214.     defw    cmnd32            ; Get/set user code
  215.     defw    cmnd33            ; Read random
  216.     defw    cmnd34            ; Write random
  217.     defw    cmnd35            ; Compute file size
  218.     defw    cmnd36            ; Set random record
  219.     defw    cmnd37            ; Reset multiple drive
  220.     defw    dummy            ; Access drive - not implemented
  221.     defw    gfixed            ; Get fixed login vector
  222.     defw    cmnd40            ; Write random with zero fill
  223.  
  224. ; ---------------------------------
  225.  
  226. ; Return current fixed drive vector
  227.  
  228. gfixed:
  229.     ld    hl,(fixdrvs)
  230.     jp    cmd24a
  231.  
  232. ; ---------------------------------
  233.  
  234. ;    Character Routines
  235.  
  236. ; ---------------------------------
  237.  
  238. ; DOS console input
  239. ;
  240. ; Read character from console and echo
  241. ;  if char=cr, lf, tab, ContH or >=space
  242. ;
  243. RdCon:    call    getch            ; Get character
  244.     call    tstch            ; Test if cr,lf,tab,ContH or >=space
  245.     jr    C,exit            ; No then exit
  246.     call    wrcon            ; Echo character
  247. exit:    ld    (pexit),a        ; Return character
  248. dummy:    ret                ; And exit DOS
  249. ;
  250. ; DOS write console
  251. ;
  252. bwrcon:    ld    a,e            ; Copy character
  253.     jr    wrcon            ; And output it
  254. ;
  255. ; read reader
  256. ;
  257. rdrdr:    call    reader            ; Get character from reader
  258.     jr    exit            ; And return it to caller
  259. ;
  260. ; write punch
  261. ;
  262. wpunch:    ld    c,e            ; Copy character
  263.     jp    punch            ; And output it to punch device
  264. ;
  265. ; Write list
  266. ;
  267. wlist:    ld    c,e            ; Copy character
  268.     jp    list            ; And output it to list device
  269. ;
  270. ; Direct console input/output
  271. ;
  272. DCIO:    ld    c,e            ; Copy character
  273.     inc    e            ; Test if 0ffh
  274.     jr    Z,dcio0            ; Yes do input
  275.     inc    e            ; Test if 0feh
  276.     jp    NZ,ConOut        ; No then output character
  277.     call    ConSt            ; Get console status
  278.     and    1            ; Test it
  279.     jr    exit            ; And return it to caller
  280. DCIO0:    call    ConSt            ; Get console status
  281.     and    1            ; Test it
  282.     ret    Z            ; Exit if no character present
  283.     call    ConIn            ; Get character
  284.     jr    exit            ; And return it to caller
  285. ;
  286. ; Get I/O status byte
  287. ;
  288. giost:    ld    a,(RamLow+00003h)    ; Get I/O byte from ram
  289.     jr    exit            ; And return it to caller
  290. ;
  291. ; Set I/O status byte
  292. ;
  293. siost:    ld    a,e            ; Copy I/O byte
  294.     ld    (RamLow+00003h),a    ; And save it in ram
  295.     ret                ; Exit to caller
  296. ;
  297. ; Test console status
  298. ;
  299. tstcs:    call    gConSt            ; Get console status
  300.     jr    exit            ; And return it to caller
  301. ;
  302. ; Output char (control char = ^char)
  303. ;
  304. outch:    call    tstch            ; Test it cr,lf,tab,ContH or >=space
  305.     jr    NC,wrcon        ; Yes then jump
  306.     push    af            ; Save character
  307.     ld    a,'^'            ; Load a with '^'
  308.     call    wrcon            ; Output it
  309.     pop    af            ; Get character back
  310.     push    af            ; Save it again
  311.     add    a,'A'-1            ; Add offset
  312.     call    wrcon            ; Output it
  313.     pop    af            ; Get character
  314.     ret                ; Return to caller
  315. ;
  316. ; Echo cr,lf
  317. ;
  318. CROut:    ld    a,cr            ; A=carriage return
  319.     call    wrcon            ; Output it
  320.     ld    a,lf            ; A=line feed
  321.                     ; Fall through to output routine
  322. ;
  323. ; Write character on console
  324. ;
  325. wrcon:    cp    tab            ; Test if tab
  326.     jr    NZ,wrcon1        ; No then jump
  327. wrcon0:    ld    a,' '            ; Expand tab with spaces
  328.     call    wrcon            ; Write space
  329.     ld    a,(tabcnt)        ; Get tab count
  330.     and    7            ; Test if done
  331.     jr    NZ,wrcon0        ; No then repeat
  332.     ld    a,tab            ; Return tab
  333.     ret                ; Return to caller
  334. wrcon1:    push    af            ; Save character
  335.     call    gConSt            ; Test status and ContS/ContC
  336.     pop    af            ; Get character back
  337.     push    af            ; Save it again
  338.     ld    c,a            ; Copy it
  339.     call    ConOut            ; Output it
  340.     pop    af            ; Get character back
  341.     push    af            ; Save it again
  342.     ld    c,a            ; Copy it
  343.     ld    a,(fContP)        ; Get printer echo flag
  344.     or    a            ; Test it
  345.     call    nz,list            ; Non zero => output char to printer
  346.     ld    a,(flags)        ; Get flag byte
  347.     bit    1,a            ; Test delay 256 bytes active
  348.     jr    Z,wrcon2        ; No then exit
  349.     ld    hl,delay        ; Get delay counter
  350.     xor    a            ; A=0
  351.     or    (hl)            ; Test counter=0
  352.     jr    Z,wrcon2        ; Yes then exit
  353.     dec    (hl)            ; Else decrement counter
  354. wrcon2:    pop    af            ; Restore character
  355.                     ; Fall through to count routine
  356. ;
  357. ; Count characters in line
  358. ;
  359. countc:    ld    hl,tabcnt        ; Get pointer to tab counter
  360.     inc    (hl)            ; Increment tab counter
  361.     cp    ' '            ; Test if char >= ' '
  362.     ret    NC            ; Yes, normal character then exit
  363.     dec    (hl)            ; Control character, decrement tab count
  364.     cp    ContH            ; Test backspace
  365.     jr    NZ,count0        ; No backspace then jump
  366.     dec    (hl)            ; Decrement tab counter
  367.     ret                ; And exit
  368. count0:    cp    cr            ; Test carriage return
  369.     jr    NZ,count1        ; No then jump
  370.     ld    (hl),0            ; Reset tab count
  371.     ret                ; And exit
  372. count1:    cp    tab            ; Test tab character
  373.     ret    NZ            ; No then exit
  374.     push    af            ; Save character
  375.     ld    a,(hl)            ; Get tab count
  376.     add    a,8            ; Advance it 8 position
  377.     and    0f8h            ; Set it to next tab position
  378.     ld    (hl),a            ; Save it
  379.     pop    af            ; Restore character
  380.     ret                ; And exit
  381. ;
  382. ; Get character from console
  383. ;
  384. getch:    ld    hl,lastch        ; Get pointer to last input character
  385.     ld    a,(hl)            ; Get character
  386.     ld    (hl),0            ; Reset last character
  387.     or    a            ; Test if character present
  388.     ret    NZ            ; Return if so
  389.     jp    ConIn            ; Else get character
  390. ;
  391. ; Get console status
  392. ;
  393. gConSt:    ld    a,(delay)        ; Get 256 bytes delay
  394.     or    a            ; Test it
  395.     jr    NZ,gcons0        ; Non zero, delay stil active or disabled
  396.     call    ConSt            ; Get console status
  397.     and    1            ; Test it
  398.     jr    NZ,gcons1        ; Non zero then get character
  399. gcons0:    ld    a,(lastch)        ; Get last character
  400.     or    a            ; Test it
  401.     jr    NZ,gcons3        ; Non zero then character present
  402.     call    ConSt            ; Get console status
  403.     and    1            ; Test it
  404.     ret    Z            ; Return if no character present
  405. gcons1:    call    ConIn            ; Get character
  406.     cp    ContS            ; Test stop character
  407.     jr    NZ,gcons2        ; Not then exit character
  408.     call    ConIn            ; Get next character
  409.     cp    ContC            ; Test if user wants to exit
  410.     jp    Z,RamLow+00000h        ; Yes then warm boot
  411.     jr    gConSt            ; Test again
  412. gcons2:    ld    (lastch),a        ; Save character
  413.     ld    a,0ffh            ; Set delay counter
  414.     ld    (delay),a        ; And save it
  415. gcons3:    ld    a,1            ; Character present code
  416.     ret                ; Return to caller
  417. ;
  418. ; Test character
  419. ;  exit carry=0: cr,lf,tab,ContH or >=space
  420. ;    carry=1: all other characters
  421. ;
  422. tstch:    cp    cr            ; Test carriage return
  423.     ret    Z            ; Return if so
  424.     cp    tab            ; Test tab
  425.     ret    Z            ; Return if so
  426.     cp    ContH            ; Test backspace
  427.     ret    Z            ; Return if so
  428.     cp    rubout
  429.     ret    Z
  430.     cp    ' '            ; Test >=space
  431.     ret                ; Return to caller
  432. ;
  433. ; Write backspace, space, backspace
  434. ;
  435. wContH:    call    wcont0            ; Write backspace
  436.     ld    c,' '            ; Load space
  437.     call    ConOut            ; And output it
  438. wcont0:    ld    c,ContH            ; Load backspace
  439.     jp    ConOut            ; And output it
  440. ;
  441. ; Output message
  442. ;
  443. mess:    ld    a,(de)            ; Get byte from buffer
  444.     cp    '$'            ; Test last byte
  445.     ret    Z            ; Yes, then return to caller
  446.     inc    de            ; Point to next byte
  447.     push    de            ; Save pointer
  448.     call    wrcon            ; Output character
  449.     pop    de            ; Restore pointer
  450.     jr    mess            ; And test again
  451. ;
  452. again:    ld    hl,tabcnt        ; Get tab count pointer
  453.     ld    a,(tabcx1)        ; Get position first character line
  454.     cp    (hl)            ; Check it
  455.     ret    Z            ; Return if on same position
  456.     ld    a,' '            ; Load space
  457.     call    wrcon            ; Output it
  458.     jr    again            ; And test again
  459. ;
  460. ; Delete char
  461. ;  entry : HL = start buffer - 1
  462. ;       B  = character counter (always > 0)
  463. ;
  464. delch:    dec    b            ; Decrement character counter
  465.     ld    a,(tabcnt)        ; Get tab counter
  466.     push    af            ; Save it
  467.     push    bc            ; Save character counter
  468.     ld    a,(tabcx1)        ; Get position first character line
  469.     ld    (tabcnt),a        ; Save it in tab counter
  470. delch0:    ld    a,b            ; Copy character counter
  471.     or    a            ; Test if 0
  472.     jr    Z,delch2        ; Yes then jump
  473.     dec    b            ; Decrement it
  474.     inc    hl            ; Increment buffer pointer
  475.     ld    a,(hl)            ; Get character from buffer
  476.     push    hl            ; Save buffer pointer
  477.     call    tstch            ; Test if cr,lf,tab,ContH or >=sp
  478.     jr    NC,delch1        ; Yes then jump
  479.     rra                ; Else must be control character
  480.     call    countc            ; Count control character twice
  481. delch1:    call    countc            ; Count character
  482.     pop    hl            ; Get buffer pointer
  483.     jr    delch0            ; And test again
  484. delch2:    pop    bc            ; Restore character counter
  485.     pop    af            ; And tab counter
  486.     push    hl            ; Save buffer pointer
  487.     push    bc            ; And character counter
  488.     ld    hl,tabcnt        ; Get tab counter pointer
  489.     sub    (hl)            ; Calculate difference
  490. delch3:    dec    a            ; Decrement it
  491.     cp    8            ; Compare with 8
  492.     jr    NC,delch4        ; Jump if >=8
  493.     push    af            ; Save difference
  494.     call    wContH            ; Remove character end line
  495.     pop    af            ; Restore counter
  496.     jr    delch3            ; Remove more characters
  497. delch4:    pop    bc            ; Restore character counter
  498.     pop    hl            ; Restore buffer pointer
  499.     ret                ; And return to caller
  500. ;
  501. ; Read buffer
  502. ;
  503. rdbuf:    ld    a,(tabcnt)        ; Get current position cursor
  504.     ld    (tabcx1),a        ; Save it
  505. rdbuf0:    push    ix            ; Save start address buffer
  506.     pop    hl            ; Get it in hl
  507.     ld    c,(hl)            ; Get maximum line lenght
  508.     inc    hl            ; Increment to line lenght position
  509.     ld    b,0            ; Clear line lenght counter
  510.     push    hl            ; Save start line - 1
  511. rdbuf1:    push    hl            ; Save registers
  512.     push    bc
  513. rdbuf2:    call    getch            ; Get character
  514.     pop    bc            ; Restore registers
  515.     pop    hl
  516.     and    07fh            ; Mask character
  517. rdbuf3:    cp    ContH            ; Test backspace
  518.     jr    NZ,rdbuf4        ; Not then jump
  519. doback:    ld    a,b            ; Test if deleting char from empty line
  520.     or    a
  521.     jr    Z,rdbuf1        ; Yes then get next char
  522.     pop    hl            ; Get start line
  523.     push    hl            ; And save it again
  524.     call    delch            ; Delete character
  525.     jr    rdbuf1            ; Get next character
  526. rdbuf4:    cp    ContP            ; Test print enable/disable
  527.     jr    NZ,rdbufC        ; Not then jump
  528.     ld    a,(fContP)        ; Complement print flag
  529.     cpl
  530.     ld    (fContP),a
  531. rdbufc:    cp    ContX            ; Test delete line
  532.     jr    NZ,rdbufe        ; Not then jump
  533. rdbufd:    pop    hl            ; Get start line
  534.     ld    a,b            ; Test if last character deleted
  535.     or    a
  536.     jp    Z,RDBUF            ; Yes start routine again
  537.     push    hl            ; Save pointer
  538.     call    delch            ; Delete last character line
  539.     jr    rdbufd            ; Test last character deleted
  540. rdbufe:    cp    rubout            ; Test delete last character
  541.     jr    NZ,rdbuff        ; Not then jump
  542.     jr    doback            ; Part of delete key fix
  543. rdbuff:    cp    cr            ; Test carriage return
  544.     jr    Z,rdbufi        ; Yes, then exit
  545.     inc    hl            ; Increment pointer
  546.     ld    (hl),a            ; And save character
  547.     inc    b            ; Increment line counter
  548. rdbufg:    push    hl            ; Save registers
  549.     push    bc
  550.     call    outch            ; Echo character
  551.     pop    bc            ; Restore registers
  552.     pop    hl
  553.     cp    ContC            ; Test warm boot
  554.     ld    a,b            ; Get line count
  555.     jr    NZ,rdbufh        ; No warm boot then jump
  556.     cp    1            ; Test ContC is first character line
  557.     jp    Z,RamLow+00000h        ; Yes then execute warm boot
  558. rdbufh:    cp    c            ; Test line length=maximum line length
  559.     jp    NZ,rdbuf1        ; Not then get next character
  560. rdbufi:    pop    hl            ; Get start line - 1
  561.     ld    (hl),b            ; Save line counter
  562.     ld    a,cr            ; Load carriage return
  563.     jp    wrcon            ; And echo it
  564.  
  565.  
  566. ;---------------------------
  567.  
  568. ;    Error routines
  569.  
  570. ;---------------------------
  571.  
  572. ;
  573. ; Disk changed error
  574. ;
  575. ChgErr:
  576.     ld    de,mchg         ; Load changed error message
  577.     jr    derror            ; And display error
  578. ;
  579. ; Select error
  580. ;
  581. SelErr:    ld    de,msel            ; Load selected error message
  582.     jr    derror            ; And display error
  583. ;
  584. ; File read only error
  585. ;
  586. FilRO:    ld    de,mfilro        ; Load file R/O message
  587.     ld    a,0ffh            ; Set file R/O message flag
  588.     jr    error            ; And display error
  589. ;
  590. ; Read/Write error
  591. ;
  592. RWErr:
  593.     ld    de,mrwerr
  594.     jr    derror
  595. ;
  596. ; Drive read only error
  597. ;
  598. rdonly:    ld    de,mro            ; Load drive R/O message
  599. derror:    xor    a            ; Set no file R/O message
  600. ;    fall    thru
  601.  
  602. ;
  603. ; Display error message
  604. ;
  605. ; "Error message" error on d:
  606. ; Function    nn
  607. ; File        filename.typ
  608. ;
  609. error:    ld    c,a            ; Save file R/O message flag
  610.     push    bc
  611.     push    de            ; Save error message pointer
  612.     call    crout            ; Display cr/lf
  613.     pop    de
  614.     call    mess            ; Display error
  615.     ld    a,(defdrv)        ; Get current drive
  616.     add    a,'A'            ; Make ASCII
  617.     ld    (mdrive),a        ; Save it
  618.     ld    de,mberr        ; Load message " error on d:"
  619.     call    mess            ; Display message
  620.     ld    de,mbfunc        ; Load message "function "
  621.     call    mess            ; Display message
  622.     ld    a,(funct)        ; Get function number
  623.     push    af            ; Save it
  624.     ld    bc,100            ; Display number / 100
  625.     call    num
  626.     ld    c,10            ; Display number / 10
  627.     call    num
  628.     ld    bc,101h            ; Always display number / 1
  629.     call    num
  630.     pop    af            ; Get function number
  631.     pop    bc            ; Get file R/O flag
  632.     cp    15            ; Test if FCB used in command
  633.     jr    C,error3        ; Commands <16, don't show filename
  634.     cp    24
  635.     jr    C,error1        ; Commands 16..23 show file
  636.     cp    30
  637.     jr    Z,error1        ; Command 30 show file
  638.     cp    33
  639.     jr    C,error3        ; Other commands 24..32 no file
  640.     cp    37
  641.     jr    C,error1        ; 33..36 show
  642.     cp    40
  643.     jr    NZ,error3        ; 37 don't show
  644.  
  645. error1:    push    ix            ; Display "file ="
  646.     sub    19            ; Test delete file function
  647.     jr    NZ,error2        ; Not then jump
  648.     or    c            ; Test file R/O flag
  649.     jr    Z,error2        ; No file R/O then jump
  650.     call    caldir            ; Get FCB from directory buffer
  651.     ex    (sp),hl            ; Save it
  652. error2:    ld    de,mfile        ; Get message " file ="
  653.     call    mess            ; Display message
  654.     pop    hl            ; Get pointer FCB
  655.     ld    b,8            ; Display first 8 characters
  656.     call    filenm
  657.     ld    a,'.'            ; Load '.'
  658.     push    hl            ; Save FCB pointer
  659.     call    wrcon            ; Echo it
  660.     pop    hl            ; Restore FCB pointer
  661.     ld    b,3            ; Display last 3 characters
  662.     call    filenm
  663.  
  664. ; Absorb any pending characters:
  665.  
  666. error3:    call    gConSt            ; Test if character pending
  667.     or    a
  668.     jr    Z,error4        ; No then jump
  669.     call    getch            ; Get character
  670.     jr    error3            ; And test again
  671. ;
  672. ; Allow retry on read/write errors
  673. ;
  674. error4:
  675.     ld    a,(retflg)        ; Allow retry?
  676.     or    a
  677.     jr    Z,error5        ; No
  678.     xor    a
  679.     ld    (retflg),a        ; Reset flag <crw>
  680.     call    getch
  681.     cp    ContC            ; Control-c entered?
  682.     ret    NZ            ; No, retry
  683. error5:    xor    a            ; Make sure no use stamp flag is
  684.                     ; around when we warmboot
  685.     ld    (dtime),a
  686.     jp    RamLow+00000h        ; Do warm boot
  687. ;
  688. ; Display number
  689. ;
  690. num:    ld    d,0ffh            ; Load number -1
  691. num1:    inc    d            ; Increment number
  692.     sub    c            ; Divide by c
  693.     jr    NC,num1            ; Not finished then loop
  694.     add    a,c            ; Restore last value
  695.     push    af            ; Save it
  696.     ld    a,d            ; Test if "0"
  697.     or    b            ; And if leading zero
  698.     jr    Z,num2            ; Yes, then exit
  699.     ld    b,a            ; Set no leading zero
  700.     ld    a,d            ; Get number
  701.     add    a,'0'            ; Make ASCII
  702.     push    bc            ; Save registers
  703.     call    wrcon            ; Echo number
  704.     pop    bc            ; Restore registers
  705. num2:    pop    af            ; Restore number
  706.     ret                ; And exit
  707. ;
  708. ; Display filename.typ
  709. ;
  710. filenm:    inc    hl            ; Increment pointer FCB
  711.     ld    a,(hl)            ; Get character from FCB
  712.     and    07fh            ; Mask it
  713.     push    hl            ; Save registers
  714.     push    bc
  715.     call    wrcon            ; Echo character
  716.     pop    bc            ; Restore registers
  717.     pop    hl
  718.     djnz    filenm            ; Repeat b times
  719.     ret                ; And exit
  720. ;
  721. ; Error messages
  722. ; Made more meaningful--b.h.
  723. ;
  724.  
  725. mchg:    db    'Dk ch$'    ;DISK CHANGED
  726.  
  727. msel:    db    'Il dr$'    ;ILLEGAL DRIVE
  728.  
  729. mfilro:    db    'Fl '        ;FILE
  730.  
  731. mro:    db    'RO$'        ;READ ONLY
  732.  
  733. mrwerr:    db    'Dt$'        ; DATA  BIOS read/write error 
  734.  
  735. mberr:    defm    ' eron '    ;ERROR ON
  736. mdrive:    defb    0
  737.     defb    DrvSep
  738.     defm    '$'
  739.  
  740. mbfunc:    defm    cr,lf,'Ft',tab,'$'    ;FUNCTION
  741.  
  742. mfile:    defm    cr,lf,'Fi',tab,'$'    ;FILE
  743.  
  744. ; END Z80DCHAR.Z80
  745.  
  746.