home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 2: PC / frozenfish_august_1995.bin / bbs / d01xx / d0165.lha / CPM / Source / ce.a next >
Text File  |  1988-11-22  |  72KB  |  3,015 lines

  1. ;    CP/M and terminal emulator for Amiga
  2. ;    for z80 emulator
  3.  
  4. cever        dc.b    'Ce    Ver: 00090   Date: 03-Oct-88 19:57:44 ',0
  5.  
  6. ;    This source code is released into the public domain for
  7. ;    non-profit use only.
  8. ;    Copyright (C) 1988, Ulf Nordquist. All Rights Reserved !
  9. ;    Ulf Nordquist
  10. ;    Brunnehagen 36
  11. ;    417 47 Gothenburg
  12. ;    Sweden
  13.  
  14. ;    History
  15. ;    871110 : osinit
  16. ;         osentry, jumptable for bdos & bios but no functions
  17. ;    871114 : conwin
  18. ;         console device
  19. ;         bdos06
  20. ;    871117 : sizing for console window
  21. ;         escape sequence decoding in bdos06
  22. ;    871118 : esc seq $3d,$4c in bdos06
  23. ;    871121 : msg port for console device
  24. ;    871122 : set up stack and pc in osinit
  25. ;         oserr6 + errors report function no. in d6
  26. ;    871203 : osrun (ccp)
  27. ;         conchk conwait
  28. ;    871213 : bios03
  29. ;         command tail buffer in ccp
  30. ;    871214 : fcb1 & fcb2 setup
  31. ;    871217 : error texts
  32. ;         bdos09
  33. ;    871219 : bios06,09,0c
  34. ;    871220 : bdos01,02,10,11
  35. ;         clean up console status check/in/out routines
  36. ;         getclin
  37. ;    871222 : bdos12
  38. ;    880111 : bdos15
  39. ;    880117 : bdos20
  40. ;    880119 : bug1 a=l & b=h at return from bdos
  41. ;         real bios jump table
  42. ;    880205 : bug2 when waiting for chraracters from console
  43. ;    880208 : bdos17, 26
  44. ;    880221 : bdos18, 25
  45. ;    880224 : esc seq $27, $28, $2b, $2c, $4b
  46. ;         bdos13, 14
  47. ;         choice of error at undefined escape sequence
  48. ;    880226 : bdos31 & dpb
  49. ;         bdos27 & alloc
  50. ;         try to set up file size in bdos17 & 18
  51. ;    880227 : change osinit to allow more than one call and move it to
  52. ;           osrun
  53. ;         $1a as clear screen to terminal
  54. ;    880311 ; resident command dir, type
  55. ;         serfir, sernxt
  56. ;         log to file in conout
  57. ;    880312 : log to file via logbuf
  58. ;    880313 : serfir/nxt widcard in ex
  59. ;    880430 : ver 00001
  60. ;    880529 : reqstr
  61. ;    880531 : openlog asks for file name
  62. ;    880714 : bdos33
  63. ;         bug3 update lastpos if repos in bdos20
  64. ;         bdos16
  65. ;         allow transient to open more than one file (5 for now)
  66. ;    880715 : console window is borderless
  67. ;         remove windowsizing fron console window and make it
  68. ;           max height direct
  69. ;    880816 : bug4 in cursor pos, add 1
  70. ;         chk if file already open in bdos15
  71. ;    880822 : sizeable window during debug (Curse of the 512k Amiga)
  72. ;    880909 : ActivateGadget in reqstr
  73. ;         bdos00,19,21,22,34
  74. ;         bios0f,2d
  75. ;    880912 : bdos32,23,36
  76. ;         ^C in getclin
  77. ;    880913 : start message in console window
  78. ;    880914 : oserr8
  79. ;    880915 : count bios & bdos calls
  80. ;    880918 : possible to load program to tpa bigger than $7ff0
  81. ;         bug5 when read or write via bdos over $8000 boundry
  82. ;    880924 : really corrected bug5
  83. ;         resident command era
  84. ;    880929 : change console window height and change BorderTop in struct
  85. ;         to get 80x24 in 200 pixels
  86.  
  87. ;    Differences and limitations in emulation (as many as I can think of)
  88. ;    unimplemented  functions
  89. ;           resident commands : ren
  90. ;           bdos : 03,04,05,07,08,13,14,24
  91. ;              28,29,30,35,37,40
  92. ;           bios : 00,12,15,18,1b,1e,21,24,27,2a,30
  93. ;    dir    no wildcards supported
  94. ;    bdos15 (Open file) sets cr in fcb to 0 (to work with zsid) and
  95. ;           same with ex (for symmetry (or whatever)). Always returns
  96. ;           directory code 0 if successful
  97. ;    bdos16 (Close file) always returns directory code 0 if successful
  98. ;    bdos17 (Search for first) sets directory entry to 0, except for name,
  99. ;           ex and rc. Wildcard only supported in ex, always gets first
  100. ;           file in directory. Always returns directory code 0 if
  101. ;           successful.
  102. ;    bdos18 (Search for next) same limitations as bdos17, except gets
  103. ;           next file in directory
  104. ;    bdos19 (Delete file) always returns directory code 0 if successful
  105. ;    bdos20 (Read sequential) always returns directory code 0 if
  106. ;           successful
  107. ;    bdos21 (Write sequential) always returns directory code 0 if
  108. ;           successful
  109. ;    bdos22 (Make file) always returns directory code 0 if successful
  110. ;    bdos2  (Rename file) always returns directory code 0 if successful
  111. ;    bdos27 (Get adddr(alloc)) the vector is wrong when used disk size is
  112. ;           less than directory size (cks*recsiz)
  113. ;    bdos32 (Set/get user code) always return 0, cannot set
  114. ;    bdos33 (Read random) returns $ff if error
  115. ;    bdos34 (Write random) returns $ff if error
  116. ;    bios0f (List) recognized but ignored
  117. ;    bios2d (Listst) will always return 0
  118. ;    ccp    (and bdos10) uses bs & cr for its expected use, ^C first in
  119. ;           the line restart cpm, all other control codes is sent to user
  120. ;    maximum of five files open by transient
  121. ;    only user 0 is supported
  122. ;    not possible to change default drive
  123. ;    virtual terminal is adm3a (bdos02 06 09)
  124. ;           --- implemented escape sequences ---
  125. ;           27            : start inverse video
  126. ;           28            : end inverse video
  127. ;           2b            : end reduced intensity (ignored)
  128. ;           2c            : start reduced intensity (ignored)
  129. ;           3d<line+$20><column+$20> : position cursor
  130. ;           4b            : erase to end of line
  131. ;           4c            : clear and home
  132. ;           --- implemented control codes ---
  133. ;           1a            : clear screen
  134.  
  135. ;    program area is $10000 bytes, logical start is at start+$8000
  136. ;    logical start is $0000 for the processor
  137.  
  138. ;    map over program area (logical addresses)  CP/M standard address
  139. ;    $0000-$00ff    system parameters           BOOT:
  140. ;    $0100-$feff    transient program area           TBASE:
  141. ;    $fe00-$feff    bdos jump               FBASE:
  142. ;    $ff00-$ff7f    bios jump table
  143. ;    $ff80-$ffff    disk parameter block, allocation vector
  144.  
  145. ;    globals from this module
  146.  
  147.         xdef    cever
  148.         xdef    closelog
  149.         xdef    comdata
  150.         xdef    conchk
  151.         xdef    conmsgpsb
  152.         xdef    conout1
  153.         xdef    conwin
  154.         xdef    dbgconwin
  155.         xdef    inpbuftab
  156.         xdef    inppmttab
  157.         xdef    newline
  158.         xdef    openlog
  159.         xdef    osclose
  160.         xdef    osentry
  161.         xdef    osrun
  162.         xdef    reqstr
  163.  
  164. ;    externals from cz
  165.  
  166.         xref    conwinptr
  167.         xref    error2
  168.         xref    error4
  169.         xref    error5
  170.         xref    error6
  171.         xref    genntxt
  172.         xref    gg_GadgetID
  173.         xref    gg_NextGadget
  174.         xref    gg_SpecialInfo
  175.         xref    gg_TopEdge
  176.         xref    glflgs
  177.         xref    im_Class
  178.         xref    im_IAddress
  179.         xref    intbase
  180.         xref    minpeh
  181.         xref    MP_SIGBIT
  182.         xref    osexit
  183.         xref    wd_RPort
  184.         xref    wd_Size
  185.         xref    wd_UserPort
  186.         xref    winbp
  187.         xref    windp
  188.         xref    winmnh
  189.         xref    winmxh
  190.         xref    winmnw
  191.         xref    winmxw
  192.         xref    xalloc
  193.         xref    z80pc
  194.         xref    z80pgmptr
  195.         xref    z80sp
  196.  
  197. ;    externals from zek
  198.  
  199.         xref    bdosoffs
  200.         xref    biosoffs
  201.         xref    cntbuf
  202.         xref    emucall
  203.         xref    emuret
  204.         xref    stoptrc
  205.  
  206. ;    externals from mystartup
  207.  
  208.         xref    _DOSBase
  209.         xref    _SysBase
  210.  
  211. ;    externals from dos.library
  212.  
  213.         xref    _LVOClose
  214.         xref    _LVODeleteFile
  215.         xref    _LVOExamine
  216.         xref    _LVOExNext
  217.         xref    _LVOInfo
  218.         xref    _LVOLock
  219.         xref    _LVOOpen
  220.         xref    _LVORead
  221.         xref    _LVORename
  222.         xref    _LVOSeek
  223.         xref    _LVOUnLock
  224.         xref    _LVOWrite
  225.  
  226. ;    externals from exec.library
  227.  
  228.         xref    _LVOAddPort
  229.         xref    _LVOAllocSignal
  230.         xref    _LVOCloseDevice
  231.         xref    _LVODoIO
  232.         xref    _LVOFindTask
  233.         xref    _LVOFreeSignal
  234.         xref    _LVOGetMsg
  235.         xref    _LVOOpenDevice
  236.         xref    _LVORemPort
  237.         xref    _LVOReplyMsg
  238.         xref    _LVOSendIO
  239.         xref    _LVOWait
  240.  
  241. ;    externals from intuition.library
  242.  
  243. _LVOActivateGadget equ    -$1ce        ;($fe32) I have an 1.1 amiga.lib
  244.         xref    _LVOCloseWindow
  245.         xref    _LVOOpenWindow
  246.  
  247. ;    equates
  248. ;    include/graphics/rastport.i
  249.  
  250. RP_JAM1     equ    0
  251. RP_JAM2     equ    1
  252.  
  253. ;    include/intuition.i
  254.  
  255. ACTIVATE    equ    $1000
  256. BOOLGADGET    equ    $0001
  257. BORDERLESS    equ    $0800
  258. GADGETUP    equ    $00000040
  259. GADGHCOMP    equ    $0000
  260. GRELBOTTOM    equ    $0008
  261. NOCAREREFRESH    equ    $00020000
  262. RELVERIFY    equ    $0001
  263. SELECTED    equ    $0080
  264. SMART_REFRESH    equ    $0000
  265. STRGADGET    equ    $0004
  266. WBENCHSCREEN    equ    $0001
  267. WINDOWDEPTH    equ    $0004
  268. WINDOWDRAG    equ    $0002
  269. WINDOWSIZING    equ    $0001
  270.  
  271. ;    StringInfo structure
  272.  
  273. si_Buffer    equ 0
  274. si_UndoBuffer    equ 4
  275. si_BufferPos    equ 8
  276. si_MaxChars    equ 10
  277. si_DispPos    equ 12
  278. si_UndoPos    equ 14
  279. si_NumChars    equ 16
  280. si_DispCount    equ 18
  281. si_CLeft    equ 20
  282. si_CTop     equ 22
  283. si_LayerPtr    equ 24
  284. si_LongInt    equ 28
  285. si_AltKeyMap    equ 32
  286. si_SIZEOF    equ 36
  287.  
  288. ;    NewWindow structure
  289.  
  290. nw_LeftEdge    equ 0
  291. nw_TopEdge    equ 2
  292. nw_Width    equ 4
  293. nw_Height    equ 6
  294. nw_DetailPen    equ 8
  295. nw_BlockPen    equ 9
  296. nw_IDCMPFlags    equ 10
  297. nw_Flags    equ 14
  298. nw_FirstGadget    equ 18
  299. nw_CheckMark    equ 22
  300. nw_Title    equ 26
  301. nw_Screen    equ 30
  302. nw_BitMap    equ 34
  303. nw_MinWidth    equ 38
  304. nw_MinHeight    equ 40
  305. nw_MaxWidth    equ 42
  306. nw_MaxHeight    equ 44
  307. nw_Type     equ 46
  308. nw_SIZE     equ 48
  309.  
  310. ;    window struct
  311.  
  312. wd_BorderTop    equ    13*4+2+1
  313.  
  314. ;    include/libraries/dos.i
  315.  
  316. ACCESS_READ    equ    -2
  317. MODE_NEWFILE    equ    1006
  318. MODE_OLDFILE    equ    1005
  319. OFFSET_BEGINNING equ    -1
  320. OFFSET_CURRENT    equ    0
  321.  
  322. ;    DateStamp structure
  323.  
  324. ds_Days     equ    0    ;Number of days since Jan. 1, 1978
  325. ds_Minute    equ    4    ;Number of minutes past midnight
  326. ds_Tick     equ    8    ;Number of ticks past minute
  327. ds_SIZEOF    equ    12
  328.  
  329. ;    FileInfoBlock structure
  330.  
  331. fib_DiskKey    equ    0
  332. fib_DirEntryType equ    4    ;Type of Directory. If <0 file, if > 0 dir
  333. fib_FileName    equ    8    ;Null terminated. Max 30 chars used for now
  334. fib_Protection    equ    116    ;bit mask of protection, rwxd are 3-0
  335. fib_EntryType    equ    120
  336. fib_Size    equ    124    ;Number of bytes in file
  337. fib_NumBlocks    equ    128    ;Number of blocks in file
  338. fib_DateStamp    equ    132    ;Date file last changed
  339. fib_Comment    equ    144    ;Null terminated. Comment associated with file
  340. fib_SIZEOF    equ    260
  341.  
  342. ;    InfoData structure
  343.  
  344. id_NumSoftErrors equ    0    ;number of soft errors on disk
  345. id_UnitNumber     equ    4    ;Which unit disk is (was) mounted on
  346. id_DiskState     equ    8    ;See defines below
  347. id_NumBlocks     equ    12    ;Number of blocks on disk
  348. id_NumBlocksUsed equ    16    ;Number of block in use
  349. id_BytesPerBlock equ    20
  350. id_DiskType     equ    24    ;Disk Type code
  351. id_VolumeNode     equ    28    ;BCPL pointer to volume node
  352. id_InUse     equ    32    ;Flag, zero if not in use
  353. id_SIZEOF     equ    36
  354.  
  355. ;    include/exec/io.i
  356.  
  357. CMD_READ    equ    2
  358. CMD_WRITE    equ    3
  359. NT_MSGPORT    equ    4
  360. PA_SIGNAL    equ    0
  361.  
  362. ;    for cpm program area
  363.  
  364. bios        equ    $ff00
  365. biosentry    equ    $40        ;log addr to bios spec opcode (low)
  366. bioshi        equ    $ff
  367. bioslo        equ    $00        ;logical address to bios jump table
  368. biostl        equ    3        ;length of one bios table entry
  369. ccpbufpos    equ    $80        ;ccp buffer position
  370. dpb        equ    $ff80        ;disk parameter block
  371. defdma        equ    $80        ;default file dma address
  372. defdrv        equ    0        ;default drive A:
  373. fbase        equ    $fe00
  374. fbasehi     equ    $fe
  375. fbaselo     equ    $00        ;logical adress to FBASE:
  376. iobyte        equ    %10010101    ;intel standard iobyte
  377.                     ;list is assigned to line printer
  378.                     ;punch is assigned to high speed puncher
  379.                     ;reader is assigned to high speed reader
  380.                     ;console is assigned to crt
  381. tbase:        equ    $100        ;logical address to TBASE
  382.  
  383. ;    references backward
  384.  
  385. alloc        equ    dpb+15+2
  386. ccpbuflen    equ    tbase-ccpbufpos ;ccp buffer length (pos here)
  387.  
  388. ;    for fcb
  389.  
  390. fcb1        equ    $5c        ;default fcb start
  391. fcb2        equ    $6c        ;2:nd fcb, used only by ccp
  392. fcbex        equ    $68        ;fcb1 current extent 0-31
  393. fcbs1        equ    $69        ;fcb1 s1
  394. fcbs2        equ    $6a        ;fcb1 s2
  395. fcbrc        equ    $6b        ;fcb1 record count 0-127
  396. fcbd0        equ    $6c        ;fcb1 d0
  397. fcbcr        equ    $7c        ;fcb1 current record
  398. fcbr0        equ    $7d        ;fcb1 random record lsb
  399. fcbr1        equ    $7e        ;fcb1 random record
  400. fcbr2        equ    $7f        ;fcb1 random record msb
  401.  
  402. ;    for dpb
  403. ;    BLS*(DSM+1)=901120, total bytes per disk
  404. ;    set BLS=2048 -> DSM=901120/BLS-1=439, BSH=4, BLM=15, EXM=0
  405. ;    set DRM=255  -> AL0=%11110000, AL1=0, CKS=64
  406.  
  407. blsiz        equ    2048            ;BLS, cpm block size
  408. dirsiz        equ    4            ;dir size, in BLS
  409.  
  410. ;    actual dpb
  411.  
  412. spt        equ    11            ;SPT sectors per track, 16b
  413. bsh        equ    4            ;BSH block shift factor, 8b
  414. blm        equ    15            ;BLM block mask, 8b
  415. exm        equ    0            ;EXM extent mask, 8b
  416. dsm        equ    439            ;DSM, 16b
  417. drm        equ    255            ;DRM dir entries - 1, 16b
  418. al0        equ    %11110000        ;AL0, 8b
  419. al1        equ    0            ;AL1, 8b
  420. cks        equ    64            ;CKS, 16b
  421. off        equ    0            ;OFF, 16b
  422.  
  423. ;    various
  424.  
  425. chrh        equ    7        ;character height
  426. chrw        equ    8        ;character width
  427. cls        equ    $1a        ;clear screen
  428. cpmver        equ    $0022        ;cpm version 2.2
  429. csi        equ    $9b
  430. extsiz        equ    $4000        ;extent size
  431. logsiz        equ    1024        ;size of log buffer
  432. namelen     equ    8        ;max filename length
  433. recmax        equ    128        ;max no of records per extent
  434. recsiz        equ    $80        ;record size
  435. secsiz        equ    512        ;amiga sector size
  436. strbufsiz    equ    31        ;max string gadget len+1, total
  437. typelen     equ    3        ;max filetype length
  438. z80jp        equ    $c3        ;z80 jump instruction
  439. z80pgmsiz    equ    $10000
  440.  
  441. ;    backward reference
  442.  
  443. logfilesize    equ    strbufsiz    ;length of logfile name string
  444.  
  445. ;    for console window
  446. ;    normal
  447.  
  448. btchg        equ    1        ;change in BorderTop
  449. winx        equ    0        ;top x
  450. winy        equ    0        ;top y
  451. conwinw     equ    640        ;width
  452. conwinh     equ    200        ;height
  453. conwinflg    equ    WINDOWDRAG+WINDOWDEPTH+SMART_REFRESH+NOCAREREFRESH+BORDERLESS
  454.  
  455. ;    special for debug
  456.  
  457. dbgconwinw    equ    100        ;start width
  458. dbgconwinh    equ    50        ;start height
  459. dbgconwinflg    equ    WINDOWDRAG+WINDOWDEPTH+WINDOWSIZING+SMART_REFRESH+NOCAREREFRESH
  460.  
  461. ;    for input window
  462.  
  463. strgadsiz    equ    20*chrw+4    ;gadget size
  464. txtxoff     equ    chrh+4
  465. inpxmarg    equ    2*chrw        ;marginal to vert
  466. inpymarg    equ    inpxmarg/2    ;marginal to horiz
  467. inpwinw     equ    strgadsiz+2*inpxmarg ;width
  468.  
  469. ;    for input window gadgets
  470. ;    ok
  471.  
  472. inpokw        equ    6*chrw+5    ;width
  473. inpokh        equ    chrh+5        ;height
  474. inpokx        equ    inpxmarg    ;top x
  475. inpoky        equ    -2*chrh     ;top y
  476. inpoktx     equ    2*chrw+2    ;text top x
  477. okid        equ    0        ;id#
  478.  
  479. ;    cancel
  480.  
  481. inpcanw     equ    inpokw        ;width
  482. inpcanh     equ    inpokh        ;height
  483. inpcanx     equ    inpwinw-inpxmarg-inpcanw ;top x
  484. inpcany     equ    inpoky        ;top y
  485. canid        equ    1        ;id#
  486.  
  487. ;    strings
  488.  
  489. inpstrw     equ    strgadsiz    ;width
  490. inpstrh     equ    chrh+4        ;height
  491. inpstrx     equ    inpokx        ;top x
  492. strid        equ    2        ;id#
  493.  
  494. ;    ascii control
  495.  
  496. bs        equ    $08
  497. cr        equ    $0d
  498. esc        equ    $1b
  499. lf        equ    $0a
  500.  
  501.         ds.w    0            ;alignment
  502.  
  503.         section ce,code
  504.  
  505. ;    osinit
  506. ;    initialize CP/M emulator
  507. ;    console window must be open
  508. ;    entry : d0.w=two byte opcode to transfer control from the z80emulator
  509. ;             to the cpm emulator
  510. ;    chg : d0,d1,d2,a0,a1,a6
  511.  
  512. osinit:     clr.b    flags
  513.  
  514. ;    put special opcode
  515. ;    init fbase, the one and only jump
  516.  
  517.         move.l    z80pgmptr,a0
  518.         add.l    #z80pgmsiz/2,a0     ;ptr log pgm start
  519.         move.l    a0,a1
  520.         add.w    #fbase,a0        ;ptr fbase
  521.         move.b    d0,1(a0)                ;2:nd opcode byte
  522.         rol.w    #8,d0
  523.         move.b    d0,(a0)                 ;1:st opcode byte
  524.  
  525. ;    init bios, the z80 jump table
  526.  
  527.         move.l    a1,a0            ;log pgm start
  528.         add.w    #bios,a0        ;ptr bios
  529.         move.b    #biosentry,d2        ;spec op code table start
  530.         move.w    #(biostabend-biostab)/4-1,d1 ;cnt
  531. osinit2:    move.b    #z80jp,(a0)+
  532.         move.b    d2,(a0)+
  533.         move.b    #bioshi,(a0)+           ;one entry in table
  534.         addq.b    #biostl,d2        ;nxt 2:nd tab start
  535.         dbra    d1,osinit2
  536.  
  537. ;    init bios, the special opcode table
  538.  
  539.         add.w    #bios+biosentry,a1    ;ptr bios entry addr
  540.         move.w    #(biostabend-biostab)/4-1,d1 ;cnt
  541. osinit4:    rol.w    #8,d0            ;restore opcode
  542.         move.b    d0,1(a1)                ;2:nd opcode byte
  543.         rol.w    #8,d0
  544.         move.b    d0,(a1)                 ;1:st opcode byte
  545.         addq.l    #biostl,a1        ;nxt 2:nd tab start
  546.         dbra    d1,osinit4
  547.         cmp.b    #$ff,conmsgpsb
  548.         beq.s    osinit1         ;if no signal alloc
  549.         rts
  550.  
  551. ;    open message port, console device & 2 StdIOReq
  552.  
  553. osinit1:    move.l    #-1,d0
  554.         move.l    _SysBase,a6
  555.         jsr    _LVOAllocSignal(a6)
  556.         cmp.l    #-1,d0
  557.         beq    osinit3         ;if no alloc
  558.         move.b    d0,conmsgpsb        ;signal #
  559.         move.l     #0,a1
  560.         jsr    _LVOFindTask(a6)
  561.         move.l    d0,conmsgpt        ;task ptr
  562.         move.l    #conmsgp,a1
  563.         jsr    _LVOAddPort(a6)
  564.         move.l    #conname,a0        ;dev name
  565.         move.l    #conimsg,a1        ;ptr IOReq, read
  566.         move.l    conwinptr,a5
  567.         subq.b    #btchg,wd_BorderTop(a5) ;to get 24 lines in console
  568.         move.l    a5,cimdata        ;conwinptr
  569.         move.l    a1,a5
  570.         move.l    #wd_Size,cimlen     ;set up data
  571.         moveq.l #0,d0            ;unit #
  572.         moveq.l #0,d1            ;flgs
  573.         jsr    _LVOOpenDevice(a6)
  574.         or.l    d0,d0
  575.         bne.s    osinit3         ;if error
  576.         move.l    cimdev,comdev
  577.         move.l    cimunit,comunit     ;clone the 2:nd
  578.  
  579. ;    queue a read
  580.  
  581.         move.l    a5,a1            ;conimsg ptr
  582.         move.l    #conichr,cimdata    ;data ptr
  583.         move.l    #1,cimlen
  584.         jsr    _LVOSendIO(a6)
  585.  
  586. ;    message in console window
  587.  
  588.         move.l    #startmsg,comdata
  589.         jmp    conout1
  590.  
  591. ;    error in open console
  592.  
  593. osinit3:    jmp    error5
  594.  
  595. ;    pzinit
  596. ;    initialize z80 page zero
  597. ;    dma address & disk parameter block
  598. ;    close and/or unlock file
  599. ;    exit  : d2=ptr z80 pgm logical start
  600. ;    chg : d0,d1,d2,d3
  601. ;          a0,a1
  602.  
  603. pzinit:     move.w    #defdma,dmaddr
  604.         move.l    _DOSBase,a6
  605.         move.l    lock1,d1
  606.         beq.s    pzinit5         ;if no lock
  607.         bclr.b    #1,flags
  608.         clr.l    lock1            ;flg no lock
  609.         jsr    _LVOUnLock(a6)
  610.  
  611. ;    close all files opened by transient
  612.  
  613. pzinit5:    move.l    a2,-(a7)
  614.         move.l    #handles,a2        ;ptr 1:st handle
  615.         move.w    #maxhan-1,d2        ;loop cnt
  616. pzinit6:    move.l    (a2),d1                 ;handle
  617.         beq.s    pzinit4         ;if file not open
  618.         jsr    _LVOClose(a6)
  619. pzinit4:    clr.l    (a2)                    ;flg closed
  620.         add.l    #hanentsiz,a2
  621.         dbra    d2,pzinit6        ;loop
  622.         move.l    (a7)+,a2                ;restore
  623.  
  624. ;    data area initialization
  625.  
  626.         move.l    #pz1,a1
  627.         move.l    z80pgmptr,d2
  628.         add.l    #z80pgmsiz/2,d2     ;ptr log pgm start
  629. pzinit3:    move.l    d2,a0            ;restore a0
  630.         move.w    (a1)+,d1
  631.         bne.s    pzinit1         ;if not end
  632.         rts
  633. pzinit1:    move.w    (a1)+,d3                ;start
  634.         add.w    d3,a0            ;start
  635. pzinit2:    move.b    (a1)+,(a0)+             ;move to pgm area
  636.         dbra    d1,pzinit2
  637.         bra.s    pzinit3         ;nxt block
  638.  
  639. ;    osclose
  640. ;    emulator end cleanup
  641. ;    chg : d0,d1,a0,a1,a6
  642.  
  643. osclose:    bsr    closelog
  644.         jsr    stoptrc
  645.         move.l    _SysBase,a6
  646.         move.b    conmsgpsb,d0        ;signal #
  647.         cmp.b    #$ff,d0
  648.         bne.s    osclose2        ;if signal alloc
  649.         rts
  650. osclose2:    jsr    _LVOFreeSignal(a6)
  651.         move.l    #conmsgp,a1
  652.         jsr    _LVORemPort(a6)
  653.         tst.l    cimdev
  654.         bne.s    osclose1        ;if con is open
  655.         rts
  656. osclose1:    move.l    #conimsg,a1
  657.         jsr    _LVOCloseDevice(a6)
  658.         bra    pzinit
  659.  
  660. ;    osrun
  661. ;    initialize cpm and entry into cpm ccp
  662. ;    entry : d0.w=two byte opcode to transfer control from the z80emulator
  663. ;             to the cpm emulator
  664. ;    exit  : file loaded in tpa and z80pc & z80sp set up
  665. ;    chg : d0,d1,d2,d3,d4,d5,d6,d7
  666. ;          a0,a1,a2,a3,a6,a7
  667. ;    26->
  668.  
  669. osrun:        bsr    osinit
  670.  
  671. ;    entry from file not found
  672.  
  673. osrun9:     move.l    _SysBase,a6
  674.         move.l    z80pgmptr,d5
  675.         add.l    #z80pgmsiz/2+ccpbufpos,d5 ;ptr ccp buf start
  676.         bsr    pzinit
  677.         move.l    d5,a4
  678.         move.b    (-ccpbufpos+(pzdrv-pagezero))(a4),d7 ;def drive
  679.         add.b    #'A',d7                 ;drive letter
  680.         move.b    d7,d0
  681.         bsr    conout
  682.         move.b    #'>',d0
  683.         bsr    conout            ;prompt
  684.         move.l    d5,d4
  685.         add.l    #ccpbuflen,d4        ;max addr+1
  686.  
  687. ;    get data and process it
  688.  
  689.         bsr    getclin
  690.  
  691. ;    construct file name in tpa
  692.  
  693.         move.l    #newline,comdata
  694.         bsr    conout1
  695.         move.l    d4,a1            ;start of tpa
  696.         move.b    d7,(a1)+                ;drive letter
  697.         move.b    #':',(a1)+
  698.         move.l    a4,d0
  699.         sub.l    d5,d0            ;cmd line len
  700.         beq    osrun9            ;if len=0
  701.         subq.l    #1,d0
  702.         move.l    d5,a2            ;buf start
  703. osrun5:     cmp.b    #' ',(a2)
  704.         beq.s    osrun4            ;if end of first word
  705.         move.b    (a2)+,(a1)+             ;pgm name
  706.         dbra    d0,osrun5        ;search
  707.  
  708. ;    end of first (or only) word found
  709. ;    construct command line tail
  710.  
  711. osrun4:     move.l    d5,a3            ;ptr start of cmd tail buf
  712.         addq.l    #1,d0            ;comp for dbxx
  713.         move.b    d0,(a3)+                ;cmd tail len
  714.         move.b    d0,d1
  715.         beq    osrun11         ;if len=0
  716.         subq.l    #1,d0
  717. osrun12:    move.b    (a2)+,(a3)+
  718.         dbra    d0,osrun12        ;move cmd tail
  719.  
  720. ;    construct fcb1 & fcb2
  721.  
  722.         move.l    d5,a3            ;ptr cmd tail buf
  723.         addq.l    #1,a3            ;ptr 1:st chr
  724. osrun24:    cmp.b    #' ',(a3)
  725.         bne.s    osrun25         ;if start of word
  726.         addq.l    #1,a3            ;nxt chr
  727.         sub.b    #1,d1
  728.         beq    osrun11         ;if cmd tail end
  729.         bra.s    osrun24         ;search for 1:st word
  730. osrun25:    move.l    #-ccpbufpos+fcb1,a0
  731.         add.l    d5,a0            ;ptr fcb1
  732.         bclr.l    #30,d1            ;flg fcb1 loop
  733.  
  734. ;    drive letter if any
  735.  
  736. osrun18:    bclr.l    #31,d1            ;flg file name loop
  737.         cmp.b    #1,d1
  738.         beq.s    osrun13         ;rem len =1
  739.         cmp.b    #':',1(a3)
  740.         bne.s    osrun13         ;if no drv spec
  741.         move.b    (a3)+,(a0)              ;drv letter
  742.         sub.b    #'A'-1,(a0)             ;cpm drv spec
  743.         addq.l    #1,a3            ;skip ':'
  744.         sub.b    #2,d1
  745.         beq    osrun11         ;if cmd tail end
  746.  
  747. ;    file name & type
  748.  
  749. osrun13:    addq.l    #1,a0            ;ptr file mame
  750.         move.w    #namelen-1,d0        ;chr cnt
  751. osrun16:    cmp.b    #' ',(a3)
  752.         beq.s    osrun14         ;if end of name&type
  753.         cmp.b    #'.',(a3)+
  754.         beq.s    osrun15         ;if end of name
  755.         move.b    -1(a3),(a0)+            ;name letter
  756.         sub.b    #1,d1
  757.         beq    osrun11         ;if cmd tail end
  758.         dbra    d0,osrun16        ;loop thru name or type
  759. osrun17:    cmp.b    #' ',(a3)
  760.         beq.s    osrun14         ;if end of name&type
  761.         cmp.b    #'.',(a3)+
  762.         beq.s    osrun15         ;if end of name
  763.         sub.b    #1,d1
  764.         beq    osrun11         ;if cmd tail end
  765.         bra.s    osrun17         ;search for type
  766. osrun15:    sub.b    #1,d1
  767.         beq.s    osrun11         ;if cmd tail end
  768.         move.l    #-ccpbufpos+fcb1+namelen+1,a0
  769.         btst.l    #30,d1
  770.         beq.s    osrun19         ;if fcb1 loop
  771.         move.l    #-ccpbufpos+fcb2+namelen+1,a0
  772. osrun19:    add.l    d5,a0            ;ptr fcb1 type
  773.         move.w    #typelen-1,d0        ;chr cnt
  774.         bset.l    #31,d1            ;flg file type loop
  775.         beq.s    osrun16         ;if name loop
  776. osrun20:    sub.b    #1,d1
  777.         beq.s    osrun11         if cmd tail end
  778.         cmp.b    #' ',(a3)+
  779.         bne.s    osrun20         ;search for nxt word
  780.         bra.s    osrun21
  781. osrun14:    addq.l    #1,a3            ;skip ' '
  782.         sub.b    #1,d1
  783.         beq.s    osrun11         if cmd tail end
  784. osrun21:    cmp.b    #' ',(a3)
  785.         bne.s    osrun23         ;if nxt word
  786.         addq.l    #1,a3            ;nxt chr
  787.         sub.b    #1,d1
  788.         beq.s    osrun11         ;if cmd tail end
  789.         bra.s    osrun21         ;search for nxt word
  790. osrun23:    move.l    #-ccpbufpos+fcb2,a0
  791.         add.l    d5,a0            ;ptr fcb2
  792.         bset.l    #30,d1            ;flg fcb2 loop
  793.         beq    osrun18         ;if fcb1 loop
  794.  
  795. ;    check for resident commands
  796.  
  797. osrun11:    move.b    #' ',(a1)               ;space last in name
  798.         move.l    d4,a0
  799.         cmp.l    #'DIR ',2(a0)
  800.         beq    rcdir
  801.         cmp.l    #'ERA ',2(a0)
  802.         beq    rcera
  803.         cmp.l    #'TYPE',2(a0)
  804.         bne.s    osrun1            ;if not type
  805.         cmp.b    #' ',2+4(a0)
  806.         beq    rctype
  807.  
  808. ;    load file into tpa
  809.  
  810. osrun1:     move.l    #filetyp,a0
  811.         move.w    #(filetype-filetyp)-1,d0
  812. osrun6:     move.b    (a0)+,(a1)+
  813.         dbra    d0,osrun6        ;move file type
  814.         move.l    d4,d1            ;name ptr
  815.         move.l    #MODE_OLDFILE,d2
  816.         move.l    _DOSBase,a6
  817.         jsr    _LVOOpen(a6)            ;open file
  818.         or.l    d0,d0
  819.         beq    osrun7            ;if no file
  820.         move.l    d0,d6            ;file handle
  821.         move.l    d4,d2            ;ptr tpa
  822.         move.l    #(z80pgmsiz/2)-tbase,d3 ;length
  823.         move.l    d6,d1            ;file handle
  824.         jsr    _LVORead(a6)            ;read file
  825.         cmp.l    d0,d3
  826.         bne.s    osrun3            ;if no more to read
  827.         move.l    d4,d2            ;ptr tpa
  828.         sub.l    #(z80pgmsiz/2)+tbase,d2 ;ptr $8000 z80 mem
  829.         move.l    #(z80pgmsiz/2)-($10000-fbase),d3 ;length
  830.         move.l    d6,d1            ;file handle
  831.         jsr    _LVORead(a6)            ;read file again
  832. osrun3:     move.l    d0,d4            ;result
  833.         move.l    d6,d1            ;file handle
  834.         jsr    _LVOClose(a6)           ;close file
  835.         cmp.l    #-1,d4
  836.         beq    osrun8            ;if read error
  837.  
  838. ;    file successfully placed in tpa
  839.  
  840.         move.w    #tbase,z80pc        ;set z80 pc
  841.         move.w    #bios-2,z80sp        ;stack in end of bdos
  842.         move.l    d5,a0            ;ptr cmd tailbuf start
  843.         add.w    #bios-ccpbuflen,a0    ;ptr bios
  844.         move.b    pagezero+1,-2(a0)
  845.         move.b    pagezero+2,-1(a0)       ;wboot ret addr
  846.         rts
  847.  
  848. ;    file not found or read error
  849.  
  850. osrun8:
  851. osrun7:     move.l    #ccpbuflen+2,a0
  852.         add.l    d5,a0            ;ptr name
  853.         move.l    a0,comdata
  854. osrun22:    cmp.b    #'.',(a0)+
  855.         bne.s    osrun22         ;search for '.'
  856.         clr.b    -(a0)                   ;mark end
  857.  
  858. ;    entry from error in resident commands
  859.  
  860. osrun2:     bsr    conout1
  861.         move.b    #'?',d0
  862.         bsr    conout            ;'name?'
  863.         move.l    #newline,comdata
  864.         bsr    conout1
  865.         bra    osrun9            ;try again
  866.  
  867. ;    resident commands
  868.  
  869. ;    dir
  870.  
  871. rcdir:        move.w    #fcb1,d2save+2        ;fcbptr
  872.         sub.w    #tbase,a0        ;ptr log start
  873.         move.l    a0,a1
  874.         add.w    #defdma+1,a1
  875.         move.l    a1,d5            ;abs dir ptr
  876.         move.l    a0,a4save
  877.         bsr    serfir
  878.         beq.s    rcdir1            ;if no find
  879.  
  880. ;    output dir list
  881.  
  882. rcdir7:     move.w    #3,d6            ;4 entries / line
  883. rcdir6:     cmp.w    #3,d6
  884.         bne.s    rcdir4            ;if not 1:st on line
  885.         move.b    drvlet,d0
  886.         bsr    conout
  887.         move.l    #dirsep+1,comdata
  888.         bsr    conout1
  889. rcdir4:     move.l    d5,a2
  890.         move.w    #namelen-1,d2
  891. rcdir2:     move.b    (a2)+,d0
  892.         bsr    conout
  893.         dbra    d2,rcdir2        ;output name
  894.         move.b    #' ',d0
  895.         bsr    conout            ;output nt separator
  896.         move.w    #typelen-1,d2
  897. rcdir3:     move.b    (a2)+,d0
  898.         bsr    conout
  899.         dbra    d2,rcdir3        ;output type
  900.         tst.w    d6
  901.         beq.s    rcdir5            ;if last on line
  902.         move.l    #dirsep,comdata
  903.         bsr    conout1
  904. rcdir5:     bsr    sernxt
  905.         beq.s    rcdir1            ;if no find
  906.         dbra    d6,rcdir6        ;line loop
  907.         move.l    #newline,comdata
  908.         bsr    conout1
  909.         bra.s    rcdir7            ;start new line
  910. rcdir1:     jmp    osexit
  911.  
  912. ;    type
  913.  
  914. rctype:     sub.w    #tbase,a0        ;ptr log start
  915.         move.l    a0,a4save
  916.         move.l    a0,a3
  917.         add.w    #fcb1,a3        ;abs fcb ptr
  918.         add.w    #defdma,a0        ;abs dma addr
  919.         move.l    a0,d4
  920.         bsr    xlname
  921.         addq.l    #2,d1            ;skip drv
  922.         move.l    d1,comdata        ;set up for error
  923.         subq.l    #2,d1            ;restore
  924.         move.l    #MODE_OLDFILE,d2
  925.         move.l    _DOSBase,a6
  926.         jsr    _LVOOpen(a6)
  927.         or.l    d0,d0
  928.         beq    osrun2            ;if no file
  929.         move.l    d0,d5
  930.  
  931. ;    output file to terminal
  932.  
  933. rctype2:    move.l    d5,d1            ;handle
  934.         move.l    d4,d2            ;ptr buffer
  935.         move.l    #recsiz,d3        ;len
  936.         move.l    _DOSBase,a6
  937.         jsr    _LVORead(a6)
  938.         or.l    d0,d0
  939.         beq.s    rctype1         ;if eof
  940.         move.l    d0,comlen        ;length
  941.         move.l    d4,comdata        ;ptr buffer
  942.         bsr    conout2
  943.  
  944. ;    allow pause and/or break of output
  945.  
  946.         bsr    conchk
  947.         beq.s    rctype2         ;if no chr
  948.         cmp.b    #3,d6
  949.         beq.s    rctype1         ;if ctrl-c
  950.         bsr    conwait
  951.         cmp.b    #3,d6
  952.         bne.s    rctype2         ;if not ctrl-c
  953. rctype1:    jmp    osexit
  954.  
  955. ;    era
  956.  
  957. rcera:        move.l    _DOSBase,a6        ;for later use
  958.         move.w    #fcb1,a3        ;z80 fcb ptr
  959.         add.l    a4save,a3        ;abs fcb ptr
  960.         bsr    xlname
  961.         jsr    _LVODeleteFile(a6)
  962.         tst.l    d0
  963.         beq    osrun2            ;if no file
  964.         jmp    osexit
  965.  
  966. ;    osentry
  967. ;    entry into cpm fdos functions
  968. ;    the z80 emulator should transfer control to this routine when it
  969. ;    encounters the 2 byte opcode set up by osinit
  970. ;    entry : registers as per emulation
  971. ;    exit : register set up as defined by cpm bdos and bios calls
  972. ;           last the routine does a ret by jumping to emuret
  973. ;           d6.w=ffee, ff=function number, ee=error code
  974. ;            error code 0 : no error
  975. ;                   1 : transfer from over bios area
  976. ;                   2 : call to unimplemented bios function
  977. ;                   3 : transfer from under bdos area
  978. ;                   4 : transfer from between bdos-bios area
  979. ;                   5 : call to undefined bdos function
  980. ;                   6 : call to unimplemented bdos function
  981. ;                   7 : unimplemented terminal escape requence
  982. ;                   8 : file handle table full
  983.  
  984. ;    chg : - (except as defined in exit)
  985.  
  986. osentry:
  987.  
  988. ;    save registers
  989.  
  990.         move.l    d0,d0save
  991.         move.l    d1,d1save
  992.         move.l    d2,d2save
  993.         move.l    d3,d3save
  994.         move.l    d4,d4save
  995.         move.l    d5,d5save
  996.         move.l    d7,d7save
  997.         move.l    a0,a0save
  998.         move.l    a1,a1save
  999.         move.l    a2,a2save
  1000.         move.l    a3,a3save
  1001.         move.l    a4,a4save
  1002.         move.l    a6,a6save
  1003.  
  1004. ;    check were the routine were called
  1005.  
  1006.         move.w    a0,d6            ;pc
  1007.         subq.w    #2,d6            ;comp for 2 byte opcode
  1008.         cmp.w    #bios,d6
  1009.         blt    osentry1        ;if possible bdos entry
  1010.  
  1011. ;    possible bios entry
  1012.  
  1013.         cmp.w    #bios+biosentry+(biostabend-biostab)/4*biostl,d6
  1014.         bge    oserr1            ;if over bios
  1015.         sub.w    #biosentry,d6        ;rel ptr into bios
  1016.         divu.w    #biostl,d6
  1017.         swap    d6            ;q<->r
  1018.         or.w    d6,d6
  1019.         bne    oserr1            ;if not correct entry point
  1020.  
  1021. ;    correct bios call
  1022.  
  1023.         swap    d6
  1024.         moveq.l #0,d3
  1025.         move.b    d6,d3            ;function #
  1026.         btst.b    #5,glflgs
  1027.         beq.s    osentry4        ;if no count
  1028.  
  1029. ;    count bios calls
  1030.  
  1031.         move.l    cntbuf,a5
  1032.         add.w    d3,a5
  1033.         addq.b    #1,biosoffs(a5)         ;inc cnt
  1034.         bne.s    osentry2        ;if not max cnt
  1035.         subq.b    #1,biosoffs(a5)         ;restore max cnt
  1036. osentry2:    addq.l    #1,a0
  1037. osentry4:    move.l    #biostab,a5
  1038.         asl.w    #2,d3            ;4 bytes per entry
  1039.         move.l    0(a5,d3.l),a5           ;routine addr
  1040.         lsr.w    #2,d3            ;restore
  1041.         jmp    (a5)                    ;do routine
  1042.  
  1043. ;    possible bdos call
  1044.  
  1045. osentry1:    cmp.w    #fbase,d6
  1046.         blt    oserr3            ;if under fbase
  1047.         bne    oserr4            ;if not at start
  1048.  
  1049. ;    correct bdos call
  1050.  
  1051.         and.l    #$000000ff,d3        ;isolate routine #
  1052.         btst.b    #5,glflgs
  1053.         beq.s    osentry5        ;if no count
  1054.  
  1055. ;    count bdos calls
  1056.  
  1057.         move.l    cntbuf,a5
  1058.         add.w    d3,a5
  1059.         addq.b    #1,bdosoffs(a5)         ;inc cnt
  1060.         bne.s    osentry6        ;if not max cnt
  1061.         subq.b    #1,bdosoffs(a5)         ;restore max cnt
  1062. osentry6:    addq.l    #1,a0
  1063. osentry5:    move.l    #bdostab,a5
  1064.         cmp.b    #(bdostabend-bdostab)/4,d3
  1065.         bgt    oserr5            ;if undefined bdos call
  1066.         asl.w    #2,d3            ;4 bytes per entry
  1067.         move.l    0(a5,d3.l),a5           ;routine addr
  1068.         lsr.w    #2,d3            ;restore #
  1069.         jmp    (a5)                    ;do routine
  1070.  
  1071. ;    common exit point from bdos & bios functions
  1072. ;    restore registers
  1073.  
  1074. osentry3:    move.l    d0save,d0
  1075.         move.l    d1save,d1
  1076.         move.l    d2save,d2
  1077.         move.l    d3save,d3
  1078.         move.l    d4save,d4
  1079.         move.l    d5save,d5
  1080.         move.l    d7save,d7
  1081.         move.l    a0save,a0
  1082.         move.l    a1save,a1
  1083.         move.l    a2save,a2
  1084.         move.l    a3save,a3
  1085.         move.l    a4save,a4
  1086.         move.l    a6save,a6
  1087.         jmp    emuret            ;return to caller
  1088.  
  1089. ;    errors
  1090.  
  1091. oserr1:     move.w    #1,d6            ;transfer over bios
  1092.         move.l    #errtxt1,a5
  1093.         bra.s    osentry3
  1094. oserr2:     move.b    #2,d6            ;unimplemented bios
  1095.         move.l    #errtxt2,a5
  1096.         bra.s    oserr61
  1097. oserr3:     move.w    #3,d6            ;transfer under bdos
  1098.         move.l    #errtxt3,a5
  1099.         bra.s    osentry3
  1100. oserr4:     move.w    #4,d6            ;transfer betwee bdos/bios
  1101.         move.l    #errtxt4,a5
  1102.         bra    osentry3
  1103. oserr5:     move.b    #5,d6            ;undefined bdos
  1104.         move.l    #errtxt5,a5
  1105.         bra.s    oserr61
  1106. oserr6:     move.b    #6,d6            ;unimplemented bdos
  1107.         move.l    #errtxt6,a5
  1108. oserr61:    rol.w    #8,d6
  1109.         move.b    d3,d6            ;function no
  1110.         rol.w    #8,d6
  1111.         bra    osentry3
  1112. oserr7:     move.b    #7,d6            ;unimplemented esc seq
  1113.         move.l    #errtxt7,a5
  1114.         bra.s    oserr61
  1115. oserr8:     move.w    #8,d6            ;file handle table full
  1116.         move.l    #errtxt8,a5
  1117.         bra    osentry3
  1118.  
  1119. ;    bdos functions
  1120.  
  1121. ;    bdos function 0 : system reset
  1122. ;    entry : c=00h
  1123.  
  1124. bdos00:     jmp    osexit
  1125.  
  1126. ;    bdos function 1 : console input
  1127. ;    echo to console output, wait until character ready
  1128. ;    entry : c=01h
  1129. ;    exit  : a=chr
  1130.  
  1131. bdos01:     bsr    biosci
  1132.         move.b    d6,d0save+3        ;chr to a reg
  1133.         move.b    d6,d1save+3        ;chr to l reg
  1134.         move.b    d6,d0
  1135.         bra.s    bdos0613        ;echo & exit
  1136.  
  1137. ;    bdos function 2 : console output
  1138. ;    entry : c=02h, e=chr
  1139.  
  1140. bdos02:     move.b    d2save+3,d0        ;e reg
  1141.         bra.s    bdos0613        ;output & exit
  1142.  
  1143. ;    bdos function 6 : direct console I/O
  1144. ;    entry : c=06h, e=$ff (if input) or chr (if output)
  1145. ;    exit  : a=chr ($ff if no chr)
  1146.  
  1147. ;    14->
  1148.  
  1149. bdos06:     move.b    d2save+3,d0        ;e reg
  1150.         move.l    _SysBase,a6        ;for later use
  1151.         cmp.b    #$ff,d0
  1152.         beq    bdos061         ;if input
  1153.  
  1154. ;    if console output
  1155. ;    NOTEZ BIEN !!!
  1156. ;    all output to console should be routed through this routine
  1157. ;    entry from bios0c
  1158.  
  1159. bdos0613:    and.b    #%01111111,d0        ;use 7 bits
  1160.         btst.b    #0,flags
  1161.         bne.s    bdos067         ;if esc seq
  1162.         cmp.b    #' ',d0
  1163.         blt.s    bdos062         ;if ctrl
  1164.  
  1165. ;    output alphanumeric
  1166.  
  1167. bdos066:    bsr    conout
  1168. bdos0611:    move.b    #0,d6            ;flg no error
  1169.         beq    osentry3        ;if no error
  1170.  
  1171. ;    output control characters
  1172.  
  1173. bdos062:    cmp.b    #esc,d0
  1174.         beq.s    bdos063         ;if <esc>
  1175.  
  1176. ;    control except esc
  1177.  
  1178.         cmp.b    #cls,d0
  1179.         beq    txl4c            ;if clear screen
  1180.         bra.s    bdos066         ;go and output
  1181.  
  1182. ;    escape
  1183.  
  1184. bdos063:    bset.b    #0,flags        ;flg esc
  1185.         clr.b    escptr            ;seq rel ptr
  1186.         bra.s    bdos0611
  1187.  
  1188. ;    escape sequence
  1189.  
  1190. bdos067:    tst.b    escptr
  1191.         bne.s    bdos0610        ;if param rx
  1192.  
  1193. ;    first chr in escape sequence, get sequence lenght
  1194.  
  1195.         move.b    d0,escseq
  1196.         move.w    #(esctabend-esctab)/8,d1 ;cnt
  1197.         move.l    #esctab+1,a0        ;ptr 1:st
  1198. bdos069:    cmp.b    (a0)+,d0
  1199.         beq.s    bdos068         ;if find
  1200.         addq.l    #7,a0            ;nxt entry
  1201.         dbra    d1,bdos069        ;tab loop
  1202.         bclr.b    #0,flags        ;flg no esc
  1203.         btst.b    #4,glflgs
  1204.         beq.s    bdos0611        ;if no req
  1205.         move.b    d0,d3            ;esc seq
  1206.         bra    oserr7            ;make requester
  1207. bdos068:    move.l    (a0)+,escxlt            ;xlt addr
  1208.         move.w    (a0),escptr             ;rel cnt
  1209.         bne.s    bdos0611        ;if seq len >0
  1210.         bclr.b    #0,flags        ;flg no esc
  1211.         bra.s    bdos0612        ;do esc
  1212.  
  1213. ;    escape sequence parameter reception
  1214.  
  1215. bdos0610:    move.l    #escrx,a0        ;buffer ptr
  1216.         move.w    escptr,d1        ;rel ptr
  1217.         move.b    d0,0(a0,d1.w)           ;save chr
  1218.         addq.w    #1,escptr        ;nxt buf pos
  1219.         bne    bdos0611        ;if not last in seq
  1220.         bclr.b    #0,flags        ;flg no esc
  1221. bdos0612:    move.l    escxlt,a1
  1222.         jmp    (a1)                    ;translate esc seq
  1223.  
  1224. ;    console input
  1225.  
  1226. bdos061:    bsr    bioscc
  1227.         or.b    d6,d6
  1228.         beq.s    bdos064         ;if no chr
  1229.         bsr    biosci
  1230.         move.b    d6,d0save+3        ;chr to a reg
  1231.         move.b    d6,d1save+3        ;chr to l reg
  1232.         bra    bdos0611        ;exit
  1233.  
  1234. ;    no message
  1235.  
  1236. bdos064:    move.b    d6,d0save+3        ;flg no chr
  1237.         move.b    d6,d1save+3        ;and i l reg
  1238.         bra    bdos0611        ;exit
  1239.  
  1240. ;    bdos function 9 : Print string
  1241. ;    entry : c=09h, de=ptr to string, string ends with '$'
  1242.  
  1243. bdos09:     move.w    d2save+2,d0        ;de reg
  1244.         move.l    z80pgmptr,a2
  1245.         add.l    #z80pgmsiz/2,a2     ;ptr log pgm start
  1246.         add.w    d0,a2            ;ptr string
  1247.         move.l    _SysBase,a6        ;for later use
  1248. bdos092:    move.b    (a2)+,d0                ;chr
  1249.         cmp.b    #'$',d0
  1250.         beq    bdos0611        ;if end, exit
  1251.         bsr    conout
  1252.         bra.s    bdos092         ;loop until end
  1253.  
  1254. ;    bdos function 10 : Read console buffer
  1255. ;    entry : c=0ah, de=ptr to buffer (buffer pos 00=buffer size)
  1256. ;    exit  : characters in buffer (buffer pos 01=actual buffer size)
  1257.  
  1258. bdos10:     move.w    d2save+2,d0        ;de reg
  1259.         move.l    z80pgmptr,a4
  1260.         add.l    #z80pgmsiz/2,a4     ;ptr log pgm start
  1261.         add.w    d0,a4            ;ptr buffer
  1262.         moveq.l #0,d4
  1263.         move.b    (a4),d4                 ;buffer size
  1264.         add.l    a4,d4            ;max addr + 1
  1265.         addq.l    #2,a4            ;ptr 1:st in buffer
  1266.         move.l    a4,d5            ;min addr
  1267.         bsr    getclin
  1268.         sub.l    d5,a4            ;# of chrs
  1269.         move.l    a4,d4
  1270.         move.l    d5,a4            ;min addr
  1271.         move.b    d4,-1(a4)               ;set # of chrs
  1272.         bra    bdos0611        ;exit
  1273.  
  1274. ;    bdos function 11 : Get console status
  1275. ;    entry : c=0bh
  1276. ;    exit  : a=console status, $ff=chr rdy, $00=no chr
  1277.  
  1278. bdos11:     bsr    bioscc
  1279.         move.b    d6,d0save+3        ;flg in a
  1280.         move.b    d6,d1save+3        ;and in l
  1281.         bra    bdos0611        ;exit
  1282.  
  1283. ;    bdos function 12 : Return version number
  1284. ;    entry : c=0ch
  1285. ;    exit  : hl=version number
  1286.  
  1287. bdos12:     move.w    #cpmver,d1save+2    ;hl reg
  1288.         move.b    d1save+2,d3save+2    ;copy h to b
  1289.         move.b    d1save+3,d0save+3    ;copy a to l
  1290.         bra    bdos0611        ;exit
  1291.  
  1292. ;    bdos function 13 : Reset disk system
  1293. ;    entry : c=0dh
  1294.  
  1295. bdos13:     move.w    #defdma,dmaddr        ;dma address
  1296.         move.l    z80pgmptr,a4
  1297.         move.b    #defdrv,(-ccpbufpos+(pzdrv-pagezero))(a4) ;def drive
  1298.         bra    bdos0611        ;exit
  1299.  
  1300. ;    bdos function 14 : Select disk
  1301. ;    entry : c=0eh, e=selected disk
  1302.  
  1303. bdos14:     move.b    d2save+2,d0        ;e reg
  1304.         cmp.b    #15,d0
  1305.         bgt    bdos0611        ;exit if >15
  1306.         tst.b    d0
  1307.         blt    bdos0611        ;exit if <0
  1308.         move.l    z80pgmptr,a4
  1309.         move.b    d0,(-ccpbufpos+(pzdrv-pagezero))(a4) ;def drive
  1310.         bra    bdos0611        ;exit
  1311.  
  1312. ;    bdos function 15 : Open file
  1313. ;    entry     : c=0fh, de=fcb address
  1314. ;    internal : d5.l b0=make file
  1315. ;    exit     : a=directory code
  1316.  
  1317. bdos15:     bclr.l    #0,d5            ;flg open file
  1318.  
  1319. ;    entry from bdos22
  1320.  
  1321. bdos154:    move.w    d2save+2,a3        ;z80 fcb ptr
  1322.         add.l    a4save,a3        ;abs fcb ptr
  1323.         clr.b    fcbcr-fcb1(a3)          ;clr cr (sic)
  1324.         clr.b    fcbex-fcb1(a3)          ;clr ex (sic)
  1325.         move.l    a3,a5            ;abs fcb ptr
  1326.         bsr    gethan
  1327.         bne.s    bdos157         ;if already open
  1328.         bsr    xlname
  1329.  
  1330. ;    check directory for file
  1331.  
  1332.         move.l    #MODE_OLDFILE,d2    ;for open
  1333.         btst.l    #0,d5
  1334.         beq.s    bdos155         ;if open
  1335.         move.l    #MODE_NEWFILE,d2    ;for make
  1336. bdos155:    move.l    _DOSBase,a6
  1337.         jsr    _LVOOpen(a6)            ;open file
  1338.         or.l    d0,d0
  1339.         beq    bdos156         ;if no file
  1340.  
  1341. ;    if successful open
  1342. ;    search for free place in table
  1343.  
  1344.         move.l    #handles,a2        ;ptr 1:st handle
  1345.         move.w    #maxhan-1,d2        ;loop cnt
  1346. bdos152:    tst.l    (a2)                    ;handle
  1347.         beq.s    bdos151         ;if free
  1348.         add.l    #hanentsiz,a2
  1349.         dbra    d2,bdos152
  1350.  
  1351. ;    no place found in table
  1352.  
  1353.         move.l    d0,d1            ;handle
  1354.         jsr    _LVOClose(a6)
  1355.         bra    oserr8
  1356.  
  1357.         bra.s    bdos156
  1358.  
  1359. ;    place found in table
  1360.  
  1361. bdos151:    move.l    d0,(a2)+                ;handle
  1362.         move.w    #hannamsiz-1,d2     ;loop cnt
  1363. bdos153:    move.b    (a5)+,(a2)+             ;copy FCB file name
  1364.         dbra    d2,bdos153
  1365.  
  1366. ;    successful exit from bdos16,17,18,19,20,23 also
  1367.  
  1368. bdos157:    clr.b    d0save+3        ;flg open success
  1369.         clr.b    d1save+3        ;and in l reg
  1370.         bra    bdos0611        ;exit
  1371.  
  1372. ;    if unsuccessful open
  1373. ;    if seek or read/write error or end of file from bdos20
  1374. ;    if no find from bdos17 & bdos18 & bdos19 & bdos23
  1375. ;    if no file open error from bdos16
  1376.  
  1377. bdos156:    move.b    #$ff,d0save+3        ;flg open failure
  1378.         move.b    #$ff,d1save+3        ;and in l reg
  1379.         bra    bdos0611        ;exit
  1380.  
  1381. ;    bdos function 16 : Close file
  1382. ;    entry : c=10h, de=fcb address
  1383. ;    exit  : a=directory code
  1384.  
  1385. bdos16:     move.l    _DOSBase,a6        ;for later use
  1386.         move.w    d2save+2,a3        ;z80 fcb ptr
  1387.         add.l    a4save,a3        ;abs fcb ptr
  1388.         bsr    gethan
  1389.         beq.s    bdos156         ;if no handle found
  1390.         clr.l    (a2)                    ;flg closed
  1391.         jsr    _LVOClose(a6)
  1392.         bra.s    bdos157         ;exit
  1393.  
  1394. ;    bdos function 17 : Search for first
  1395. ;    entry : c=11h, de=fcb address
  1396. ;    exit  : a=directory code
  1397.  
  1398. bdos17:     bsr    serfir
  1399. bdos171:    beq.s    bdos156
  1400.         bra.s    bdos157
  1401.  
  1402. ;    bdos function 18 : Search for next
  1403. ;    entry : c=12h, de=fcb address
  1404. ;    exit  : a=directory code
  1405.  
  1406. bdos18:     bsr    sernxt
  1407.         bra.s    bdos171
  1408.  
  1409. ;    bdos function 19 : Delete file
  1410. ;    entry     : c=13h, de=fcb address
  1411. ;    exit     : a=directory code
  1412.  
  1413. bdos19:     move.l    _DOSBase,a6        ;for later use
  1414.         move.w    d2save+2,a3        ;z80 fcb ptr
  1415.         add.l    a4save,a3        ;abs fcb ptr
  1416.         bsr    gethan
  1417.         bne.s    bdos191         ;if handle found
  1418.         clr.l    d0
  1419.         move.l    d0,a2            ;flg no handle
  1420. bdos191:    move.l    a2,a5
  1421.         bsr    xlname
  1422.         jsr    _LVODeleteFile(a6)
  1423.         tst.l    d0
  1424.         beq.s    bdos156         ;if no file
  1425.         move.l    a5,d0
  1426.         tst.l    d0            ;flg closed
  1427.         beq    bdos157         ;exit if no handle
  1428.         clr.l    (a5)                    ;flg closed
  1429.         bra    bdos157         ;exit
  1430.  
  1431. ;    bdos function 20 : Read sequential
  1432. ;    entry     : c=14h, de=fcb address
  1433. ;    internal : d5.l b0=random, b1=write
  1434. ;    exit     : a=directory code
  1435.  
  1436. bdos20:     bclr.l    #0,d5            ;flg sequential
  1437.         bclr.l    #1,d5            ;flg read
  1438.  
  1439. ;    entry from bdos21,33,34
  1440.  
  1441. bdos203:    move.l    _DOSBase,a6        ;for later use
  1442.         move.w    d2save+2,a3        ;z80 fcb ptr
  1443.         move.l    a4save,a4        ;ptr pgm middle
  1444.         add.l    a4,a3            ;abs fcb ptr
  1445.         moveq.l #0,d0
  1446.         move.w    d0,d6
  1447.         btst.l    #0,d5
  1448.         beq.s    bdos202         ;if read seq
  1449.  
  1450. ;    if random, calculate extent and record
  1451.  
  1452.         move.b    fcbr1-fcb1(a3),d0       ;rnd rec hi
  1453.         asl.w    #8,d0            ;move hi
  1454.         move.b    fcbr0-fcb1(a3),d0       ;rnd rec lo
  1455.         divu.w    #extsiz/recsiz,d0    ;rec.w ext.w
  1456.         move.b    d0,fcbex-fcb1(a3)       ;set cur extent
  1457.         swap    d0            ;get rec
  1458.         move.b    d0,fcbcr-fcb1(a3)       ;set cur record
  1459.         moveq.l #0,d0
  1460. bdos202:    move.b    fcbex-fcb1(a3),d0       ;cur extent
  1461.         mulu.w    #extsiz,d0        ;tot extent size
  1462.         move.b    fcbcr-fcb1(a3),d6       ;cur record
  1463.         mulu.w    #recsiz,d6        ;tot record size
  1464.         add.l    d0,d6            ;pos in file
  1465.         bsr    gethan
  1466.         beq    bdos156         ;if no handle
  1467.         move.l    d1,d4            ;handle for later use
  1468.         moveq.l #0,d2
  1469.         move.l    #OFFSET_CURRENT,d3
  1470.         jsr    _LVOSeek(a6)            ;get position
  1471.         cmp.l    d0,d6
  1472.         beq.s    bdos201         ;if correct pos
  1473.  
  1474. ;    if repositioning in file is required
  1475.  
  1476.         move.l    d4,d1            ;handle
  1477.         move.l    d6,d2            ;pos
  1478.         move.l    #OFFSET_BEGINNING,d3
  1479.         jsr    _LVOSeek(a6)            ;position
  1480.         cmp.l    #-1,d0
  1481.         beq    bdos156         ;if error
  1482.  
  1483. ;    read/write file
  1484.  
  1485. bdos201:    moveq.l #0,d0
  1486.         move.w    dmaddr,d0
  1487.         cmp.l    #$8000-recsiz,d0
  1488.         ble.s    bdos206         ;if dma in lower z80 mem
  1489.         cmp.l    #$8000,d0
  1490.         bge.s    bdos206         ;if dma in upper z80 mem
  1491.  
  1492. ;    dma over $8000 boundry
  1493.  
  1494.         move.w    #$8000,d3
  1495.         sub.w    d0,d3            ;size to $8000
  1496.         move.l    a4,a5            ;mid ptr
  1497.         add.w    d0,a5
  1498.         move.l    a5,d2            ;abs dma ptr
  1499.         move.l    d4,d1            ;handle
  1500.         btst.l    #1,d5
  1501.         bne.s    bdos207         ;if write
  1502.         jsr    _LVORead(a6)
  1503.         bra.s    bdos208
  1504. bdos207:    jsr    _LVOWrite(a6)
  1505. bdos208:    cmp.l    #-1,d0
  1506.         beq    bdos156         ;if error
  1507.         or.l    d0,d0
  1508.         beq    bdos156         ;if end of file
  1509.         move.w    #recsiz,d0
  1510.         sub.w    d3,d0            ;remaining size
  1511.         move.w    d0,d3
  1512.         move.w    #$8000,d0        ;new dma addr
  1513.         bra.s    bdos209
  1514.  
  1515. ;    normal read/write
  1516.  
  1517. bdos206:    move.l    #recsiz,d3        ;length
  1518. bdos209:    add.w    d0,a4            ;abs ptr file dma
  1519.         move.l    a4,d2
  1520.         move.l    d4,d1            ;handle
  1521.         btst.l    #1,d5
  1522.         bne.s    bdos204         ;if write
  1523.         jsr    _LVORead(a6)
  1524.         bra.s    bdos205
  1525. bdos204:    jsr    _LVOWrite(a6)
  1526. bdos205:    cmp.l    #-1,d0
  1527.         beq    bdos156         ;if error
  1528.         or.l    d0,d0
  1529.         beq    bdos156         ;if end of file
  1530.         btst.l    #0,d5
  1531.         bne    bdos157         ;if read rnd
  1532.  
  1533. ;    if sequential, update record and extent
  1534.  
  1535.         addq.b    #1,fcbcr-fcb1(a3)       ;next record
  1536.         cmp.b    #recmax,fcbcr-fcb1(a3)
  1537.         bne    bdos157         ;if no rec ovf
  1538.         addq.b    #1,fcbex-fcb1(a3)       ;next extent
  1539.         clr.b    fcbcr-fcb1(a3)          ;init record
  1540.         bra    bdos157         ;success exit
  1541.  
  1542. ;    bdos function 21 : Write sequential
  1543. ;    entry     : c=15h, de=fcb address
  1544. ;    exit     : a=directory code
  1545.  
  1546. bdos21:     bclr.l    #0,d5            ;flg sequential
  1547.         bset.l    #1,d5            ;flg write
  1548.         bra    bdos203
  1549.  
  1550. ;    bdos function 22 : Make file
  1551. ;    entry     : c=16h, de=fcb address
  1552. ;    exit     : a=directory code
  1553.  
  1554. bdos22:     bset.l    #0,d5            ;flg make file
  1555.         bra    bdos154
  1556.  
  1557. ;    bdos function 23 : Rename file
  1558. ;    entry     : c=17h, de=fcb address old name, de+16=fcb new name
  1559. ;    exit     : a=directory code
  1560.  
  1561. bdos23:     move.w    d2save+2,a5        ;z80 fcb ptr
  1562.         add.l    a4save,a5        ;abs fcb ptr old
  1563.         move.l    a5,a3
  1564.         add.w    #fcb2-fcb1,a3        ;abs fcb ptr new
  1565.         bsr    xlname
  1566.         move.l    d1,d2            ;ptr new name
  1567.         move.l    a5,a3            ;abs fcb old
  1568.         move.l    #fnbuf2,a4
  1569.         bsr    xlnameb
  1570.         move.l    _DOSBase,a6
  1571.         jsr    _LVORename(a6)
  1572.         tst.l    d0
  1573.         beq    bdos156         ;if failure
  1574.         bra    bdos157         ;exit
  1575.  
  1576. ;    bdos function 25 : Return current disk
  1577. ;    entry : c=19h
  1578. ;    exit  : a=current disk
  1579.  
  1580. bdos25:     move.l    a4save,a2        ;ptr pgm middle
  1581.         move.b    pzdrv-pagezero(a2),d0   ;def drv
  1582.         move.b    d0,d0save+3        ;to a reg
  1583.         move.b    d0,d1save+3        ;and to l reg
  1584.         bra    bdos0611        ;exit
  1585.  
  1586. ;    bdos function 26 : Set DMA address
  1587. ;    entry : c=1ah, de=DMA address
  1588.  
  1589. bdos26:     move.w    d2save+2,dmaddr     ;dma address
  1590.         bra    bdos0611        ;exit
  1591.  
  1592. ;    bdos function 27 : Get ADDR(Alloc)
  1593. ;    entry : c=1bh
  1594. ;    exit  : hl=ALLOC address
  1595.  
  1596. bdos27:     move.w    #alloc,d1save+2     ;ptr to hl reg
  1597.         move.b    d1save+3,d0save+3    ;copy l to a
  1598.         move.b    d1save+2,d3save+2    ;copy h to b
  1599.  
  1600. ;    calculate allocation vector
  1601. ;    get info for current drive
  1602.  
  1603.         bclr.b    #1,flags        ;flg fib & lock not valid
  1604.         move.l    a4save,a2        ;ptr pgm middle
  1605.         move.b    pzdrv-pagezero(a2),d0   ;def drive
  1606.         add.b    #'A',d0                 ;drive letter
  1607.         move.l    #fnbuf,a1
  1608.         move.l    a1,d1            ;name ptr
  1609.         move.b    d0,(a1)+
  1610.         move.b    #':',(a1)+
  1611.         clr.b    (a1)+                   ;disk name
  1612.         move.l    #ACCESS_READ,d2
  1613.         move.l    _DOSBase,a6
  1614.         jsr    _LVOLock(a6)
  1615.         or.l    d0,d0
  1616.         beq    bdos0611        ;if no lock, exit
  1617.         move.l    d0,d3
  1618.         move.l    fibptr,d0
  1619.         bne.s    bdos272         ;if allocated
  1620.         move.l    #fib_SIZEOF,d0        ;size
  1621.         jsr    xalloc
  1622.         bne.s    bdos273         ;if success
  1623.         jmp    error4
  1624. bdos273:    move.l    d0,fibptr
  1625. bdos272:    move.l    d0,d2            ;data ptr
  1626.         move.l    d0,a3
  1627.         move.l    d3,d1            ;lock
  1628.         move.l    _DOSBase,a6
  1629.         jsr    _LVOInfo(a6)
  1630.         or.l    d0,d0
  1631.         beq    bdos0611        ;if no info, exit
  1632.  
  1633. ;    set up allocation vector
  1634.  
  1635.         move.l    id_NumBlocksUsed(a3),d0
  1636.         mulu.w    #secsiz,d0        ;bytes used
  1637.         add.w    #alloc,a2        ;ptr alloc
  1638.         move.b    #al0,(a2)+
  1639.         move.b    #al1,(a2)+              ;move al
  1640.         move.l    a2,a3
  1641.         move.w    #(dsm>>3),d1            ;byte cnt
  1642. bdos271:    clr.b    (a2)+
  1643.         dbra    d1,bdos271        ;clr vector
  1644.         divu.w    #blsiz,d0        ;cpm blocks used
  1645.         sub.w    #dirsiz,d0        ;sub used by dir
  1646.         bmi    bdos0611        ;if neg allocated
  1647.         move.w    d0,d1
  1648.         and.w    #%0000000000000111,d1
  1649.         beq.s    bdos275         ;if no partial byte
  1650.         subq.w    #1,d1            ;use d1 as cnt
  1651.         move.b    #%10000000,d2
  1652.         asr.b    d1,d2            ;shift in bytes
  1653.         move.b    d2,(a3)+
  1654. bdos275:    lsr.w    #3,d0            ;whole bytes
  1655.         beq    bdos0611        ;if no whole bytes
  1656.         subq.w    #1,d0
  1657. bdos274:    move.b    #$ff,(a3)+
  1658.         dbra    d0,bdos274        ;fill bytes
  1659.         bra    bdos0611        ;exit
  1660.  
  1661. ;    bdos function 31 : Get ADDR(Disk parms)
  1662. ;    entry : c=1fh
  1663. ;    exit  : hl=DPB address
  1664.  
  1665. bdos31:     move.w    #dpb,d1save+2        ;ptr to hl reg
  1666.         move.b    d1save+3,d0save+3    ;copy l to a
  1667.         move.b    d1save+2,d3save+2    ;copy h to b
  1668.         bra    bdos0611        ;exit
  1669.  
  1670. ;    bdos function 32 : Set/get user code
  1671. ;    entry : c=20h, e=ffh(get) else set user code
  1672. ;    exit  : a=current user code
  1673.  
  1674. bdos32:     move.b    #0,d1save+3        ;user code to l
  1675.         move.b    d1save+3,d0save+3    ;copy l to a
  1676.         move.b    d1save+2,d3save+2    ;copy h to b
  1677.         bra    bdos0611        ;exit
  1678.  
  1679. ;    bdos function 33 : Read random
  1680. ;    entry : c=21h, de=FCB address
  1681. ;    exit  : a=return code
  1682.  
  1683. bdos33:     bset.l    #0,d5            ;flg random
  1684.         bclr.l    #1,d5            ;flg read
  1685.         bra    bdos203         ;same as read seq
  1686.  
  1687. ;    bdos function 34 : Write random
  1688. ;    entry : c=22h, de=FCB address
  1689. ;    exit  : a=return code
  1690.  
  1691. bdos34:     bset.l    #0,d5            ;flg random
  1692.         bset.l    #1,d5            ;flg write
  1693.         bra    bdos203         ;same as read seq
  1694.  
  1695. ;    bdos function 36 : Set random record
  1696. ;    entry : c=24h, de=FCB address
  1697. ;    exit  : random record field set in FCB
  1698.  
  1699. bdos36:     move.w    d2save+2,a3        ;z80 fcb ptr
  1700.         add.l    a4save,a3        ;abs fcb ptr old
  1701.  
  1702. ;    set random record from extent and record
  1703.  
  1704.         moveq.l #0,d0
  1705.         move.l    d0,d1
  1706.         move.b    fcbcr-fcb1(a3),d0       ;cur record
  1707.         move.b    fcbex-fcb1(a3),d1       ;cur extent
  1708.         mulu.w    #extsiz/recsiz,d1    ;tot extent size
  1709.         add.w    d0,d1            ;tot record size
  1710.         move.b    d1,fcbr0-fcb1(a3)       ;rnd rec lo
  1711.         lsr.w    #8,d0            ;move hi->lo
  1712.         move.b    d1,fcbr1-fcb1(a3)       ;rnd rec hi
  1713.         move.b    #0,fcbr2-fcb1(a3)       ;rnd rec highest
  1714.         bra    bdos0611        ;exit
  1715.  
  1716. ;       ___     ___         ___   ___     ___   ___   ___   ___
  1717. ;    |     |     | |   | |      |        | |   | |    | |   |
  1718. ;    |  ___|  ___| |___| |___  |___        | |___| |___| |   |
  1719. ;    | |        |      |    | |   |     | |   |    | |   |
  1720. ;    | |___     ___|      |  ___| |___|     | |___|  ___| |___|
  1721.  
  1722.         ds.w    0            ;alignment
  1723. bdos03:
  1724. bdos04:
  1725. bdos05:
  1726. bdos07:
  1727. bdos08:
  1728. bdos24:
  1729. bdos28:
  1730. bdos29:
  1731. bdos30:
  1732. bdos35:
  1733. bdos37:
  1734. bdos40:     bra    oserr6
  1735.  
  1736. ;    gethan
  1737. ;    get a handle to a file from table
  1738. ;    entry : a3=ptr to FCB file name
  1739. ;    exit  : a2=ptr to handle in tab, d1=handle, zflg=no find
  1740. ;    chg   : d0,d1,d2,d3
  1741. ;        a2
  1742.  
  1743. gethan:     move.l    #handles,a2        ;ptr 1:st handle
  1744.         move.w    #maxhan-1,d1        ;handle loop cnt
  1745. gethan4:    move.w    #hannamsiz-1,d2     ;name loop cnt
  1746.         tst.l    (a2)                    ;handle
  1747.         beq.s    gethan1         ;if free
  1748.         moveq.l #0,d0            ;name index
  1749. gethan3:    move.b    0(a3,d0.w),d3           ;FCB chr
  1750.         cmp.b    4(a2,d0.w),d3
  1751.         bne.s    gethan1         ;if no match
  1752.         addq.l    #1,d0            ;nxt chr
  1753.         dbra    d2,gethan3        ;name match loop
  1754.         move.l    (a2),d1                 ;handle
  1755.         rts                ;exit
  1756. gethan1:    add.l    #hanentsiz,a2        ;nxt handle
  1757.         dbra    d1,gethan4
  1758.         moveq.l #0,d1            ;flg no find
  1759.         rts
  1760.  
  1761. ;    reqstr
  1762. ;    get strings from user
  1763. ;    entry : a2.l=ptr table of size.w of & ptrs.l to input buffers
  1764. ;             last size is 0
  1765. ;        a4.l=ptr table of ptrs to prompts to buffers, last is zero
  1766. ;    exit : d2.l=1 if ok gadget, 2 if cancel gadget
  1767. ;    chg : d0,d1,d2,d3
  1768. ;          a0,a1,a2,a3,a4,a6
  1769.  
  1770. ;    8->
  1771.  
  1772. reqstr:     move.l    intbase,a6
  1773.  
  1774. ;    calculate window size and gadget positions
  1775. ;    init string gadget structures
  1776.  
  1777.         move.w    #txtxoff,d0        ;init height
  1778.         move.l    #inpstr1,a1        ;ptr 1:st gad
  1779. reqstr5:    move.w    (a2)+,d1                ;buf size
  1780.         beq.s    reqstr4         ;if end of tab
  1781.         add.w    #2*txtxoff,d0        ;y pos of nxt gadget
  1782.         move.w    d0,gg_TopEdge(a1)
  1783.         move.l    gg_SpecialInfo(a1),a3   ;ptr spec info
  1784.         move.l    (a2)+,si_Buffer(a3)     ;buf ptr
  1785.         move.w    d1,si_MaxChars(a3)      ;buf size
  1786.         move.l    gg_NextGadget(a1),d1    ;nxt gadget
  1787.         move.l    d1,a1
  1788.         bne.s    reqstr5         ;if more str gads
  1789.  
  1790. ;    open window
  1791.  
  1792. reqstr4:    move.l    #inpwin,a0        ;window ptr
  1793.         move.w    d0,d3            ;y pos last gadget
  1794.         add.w    #4*txtxoff,d0
  1795.         move.w    d0,nw_Height(a0)        ;window height
  1796.         jsr    _LVOOpenWindow(a6)
  1797.         or.l    d0,d0
  1798.         bne.s    reqstr7         ;if window
  1799.         jmp    error2
  1800. reqstr7:    move.l    d0,a3            ;win ptr
  1801.         move.l    wd_RPort(a3),a2         ;rast port ptr
  1802.  
  1803. ;    display text
  1804.  
  1805.         move.b    #2*txtxoff,d1        ;1:st y coord
  1806. reqstr2:    cmp.b    d3,d1
  1807.         bge.s    reqstr3         ;if past last gadget
  1808.         move.l    (a4)+,d0                ;pmt ptr
  1809.         beq.s    reqstr3         ;if no more ptrs
  1810.         move.l    d0,a5
  1811.         move.b    #chrw,d0        ;1:st x coord
  1812.         move.b    d1,d2
  1813.         move.l    a2,a0            ;rast port ptr
  1814.         jsr    genntxt
  1815.         move.b    d2,d1            ;y coord
  1816.         add.b    #2*txtxoff,d1        ;new y coord
  1817.         bra.s    reqstr2         ;nxt pmt
  1818.  
  1819. ;    activate gadget and wait for user response
  1820.  
  1821. reqstr3:    move.l    a3,a1            ;winptr
  1822.         move.l    #inpstr1,a0        ;ptr 1:st gad
  1823.         clr.l    d0
  1824.         move.l    d0,a2            ;no req
  1825.         jsr    _LVOActivateGadget(a6)
  1826.         move.l    wd_UserPort(a3),a2      ;IDCMP ptr
  1827.         move.b    MP_SIGBIT(a2),d1        ;sigbit #
  1828.         moveq.l #1,d0
  1829.         asl.l    d1,d0            ;sigbit mask
  1830.         move.l    _SysBase,a6
  1831.         jsr    _LVOWait(a6)
  1832.         move.l    a2,a0            ;IDCMP ptr
  1833.         jsr    _LVOGetMsg(a6)
  1834.         or.l    d0,d0
  1835.         beq.s    reqstr3         ;if no msg
  1836.         move.l    d0,a1            ;ptr msg
  1837.         move.l    im_Class(a1),d2         ;IDCMP class
  1838.         move.l    im_IAddress(a1),a2      ;gadget ptr
  1839.         jsr    _LVOReplyMsg(a6)
  1840.         cmp.l    #GADGETUP,d2
  1841.         bne.s    reqstr3         ;if not gadget
  1842.         move.w    gg_GadgetID(a2),d1
  1843.         moveq.l #1,d2            ;flg ok gadget
  1844.         cmp.w    #okid,d1
  1845.         beq.s    reqstr6         ;if ok gadget
  1846.         addq.l    #1,d2            ;flg cancel gadget
  1847.         cmp.w    #canid,d1
  1848.         bne.s    reqstr3         ;if not cancel gadget
  1849.  
  1850. ;    close window
  1851.  
  1852. reqstr6:    move.l    a3,a0            ;win ptr
  1853.         move.l    intbase,a6
  1854.         jmp    _LVOCloseWindow(a6)
  1855.  
  1856. ;    close/openlog is called by minpeh and can *only*
  1857. ;    chg : d0,d1,d2,d3
  1858. ;          a0,a1,a2,a3,a6
  1859. ;    it is furthermore called by a menu handling routine and can *only*
  1860. ;    chg : d3
  1861. ;          a0,a1,a2,a3,a6
  1862.  
  1863. ;    closelog
  1864. ;    close terminal log file
  1865. ;    exit : z=no close
  1866.  
  1867. closelog:    movem.l d0-d2,-(a7)
  1868.         move.l    handle2,d1
  1869.         beq.s    closelog1        ;if no log file open
  1870.  
  1871. ;    write buffer and close file
  1872.  
  1873.         move.l    logbuf,d2
  1874.         move.l    logcnt,d3
  1875.         beq.s    closelog2        ;if buffer empty
  1876.         move.l    _DOSBase,a6
  1877.         jsr    _LVOWrite(a6)
  1878.         move.l    handle2,d1
  1879. closelog2:    clr.l    handle2         ;flg no log
  1880.         jsr    _LVOClose(a6)
  1881.         move.l    #1,d0            ;flg success
  1882. closelog1:    movem.l (a7)+,d0-d2
  1883.         rts
  1884.  
  1885. ;    openlog
  1886. ;    open terminal log file
  1887. ;    exit : z=no open
  1888.  
  1889. openlog:    movem.l d0-d3/a4-a5,-(a7)
  1890.  
  1891. ;    set up buffer and prompt tables and get file name
  1892.  
  1893.         move.l    #inpbuftab,a0
  1894.         move.l    a0,a2
  1895.         move.w    #logfilesize,(a0)+      ;size
  1896.         move.l    #logfile,(a0)+          ;ptr buf
  1897.         move.w    #0,(a0)                 ;end
  1898.         move.l    #inppmttab,a0
  1899.         move.l    a0,a4
  1900.         move.l    #openlogpmt,(a0)+       ;prompt
  1901.         move.l    #0,(a0)                 ;end
  1902.         bsr    reqstr
  1903.         cmp.b    #2,d2
  1904.         beq.s    openlog1        ;if cancel
  1905.  
  1906. ;    open file
  1907.  
  1908.         move.l    #logfile,d1        ;buf
  1909.         move.l    #MODE_NEWFILE,d2
  1910.         move.l    _DOSBase,a6
  1911.         jsr    _LVOOpen(a6)
  1912.         move.l    d0,handle2
  1913.         beq.s    openlog1        ;if failure
  1914.         clr.l    logcnt
  1915.         tst.l    logbuf
  1916.         bne.s    openlog1        ;if buffer allocated
  1917.         move.l    #logsiz,d0
  1918.         jsr    xalloc
  1919.         bne.s    openlog2        ;if we got memory
  1920.         jmp    error4
  1921. openlog2:    move.l    d0,logbuf        ;ptr
  1922. openlog1:    movem.l (a7)+,d0-d3/a4-a5
  1923.         rts
  1924.  
  1925. ;    sernxt
  1926. ;    search for next file
  1927. ;    entry : (d2save+2)=z80 fcb ptr, (a4save)=ptr pgm middle
  1928. ;        (dmaddr)=ptr to directory entry
  1929. ;    exit  : directory entry set up at (dmaddr)
  1930. ;        z=no find
  1931.  
  1932. sernxt:     btst.b    #1,flags
  1933.         bne.s    sernxt1
  1934.         rts                ;exit if fib & lock not valid
  1935. sernxt1:    move.l    lock1,d4        ;lock
  1936.         move.l    fibptr,a5        ;file info ptr
  1937.         move.l    _DOSBase,a6        ;yes, do not forget this
  1938.         move.l    a4save,d3        ;abs fcb ptr
  1939.         add.w    foobar,d3        ;z80 fcb ptr
  1940.         bra    serfir5
  1941.  
  1942. ;    serfir
  1943. ;    search for first file
  1944. ;    entry : (d2save+2)=z80 fcb ptr, (a4save)=ptr pgm middle
  1945. ;        (dmaddr)=ptr to directory entry
  1946. ;    exit  : directory entry set up at (dmaddr)
  1947. ;        z=no find
  1948. ;    chg   : d0,d1,d2,d3,d4
  1949. ;        a0,a1,a2,a3,a4,a5,a6
  1950.  
  1951. ;    23->
  1952.  
  1953. serfir:     bclr.b    #1,flags        ;flg fib & lock not valid
  1954.         move.b    #-1,excnt        ;flg invalid
  1955.         move.l    fibptr,d0
  1956.         bne.s    serfir1         ;if allocated
  1957.         move.l    #fib_SIZEOF,d0        ;size
  1958.         jsr    xalloc
  1959.         bne.s    serfir2         ;if success
  1960.         jmp    error4
  1961. serfir2:    move.l    d0,fibptr
  1962.  
  1963. ;    get lock to directory
  1964.  
  1965. serfir1:    move.l    d0,a5
  1966.         move.w    d2save+2,a3        ;z80 fcb ptr
  1967.         add.l    a4save,a3        ;abs fcb ptr
  1968.         move.l    a3,d4
  1969.         bsr    xlname
  1970.         move.l    d1,a3
  1971.         move.b    2(a3),d3
  1972.         clr.b    2(a3)                   ;use only dir
  1973.         move.l    ACCESS_READ,d2
  1974.         move.l    _DOSBase,a6
  1975.         jsr    _LVOLock(a6)            ;get lock
  1976.         or.l    d0,d0
  1977.         bne.s    serfir13
  1978.         rts                ;exit if no lock
  1979. serfir13:    move.b    d3,2(a3)                ;restore
  1980.         move.l    d4,d3            ;ptr fcb
  1981.  
  1982. ;    get FileInfoBlock for dir
  1983.  
  1984.         move.l    d0,d4            ;lock
  1985.         move.l    d4,d1            ;lock
  1986.         move.l    a5,d2            ;fibptr
  1987.         jsr    _LVOExamine(a6)
  1988.         or.l    d0,d0
  1989.         bne.s    serfir14
  1990.         rts                ;exit if no success
  1991. serfir14:    move.l    d4,lock1        ;save lock
  1992.         bset.b    #1,flags        ;flg fib & lock valid
  1993.  
  1994. ;    entry from sernxt
  1995.  
  1996. serfir5:    move.b    excnt,d2
  1997. serfir20:    cmp.b    #-1,d2
  1998.         beq.s    serfir16        ;if not valid
  1999.  
  2000. ;    if valid count
  2001.  
  2002.         move.l    d3,a0            ;fcb ptr
  2003.         move.b    fcbex-fcb1(a0),d0       ;fcb ex
  2004.         cmp.b    #'?',d0
  2005.         beq.s    serfir17        ;if ex wildcard
  2006.         move.b    d0,excnt        ;set ex
  2007.         bra.s    serfir19
  2008.  
  2009. ;    if wildcard in extent count
  2010.  
  2011. serfir17:    move.l    fib_Size(a5),d1
  2012.         move.l    #14,d0
  2013.         lsr.l    d0,d1            ;/16384, ex count
  2014.         cmp.b    d1,d2
  2015.         ble.s    serfir9         ;if more ex
  2016.  
  2017. ;    get FileInfoBlock for next file
  2018.  
  2019. serfir16:    clr.b    excnt            ;1:st ex
  2020. serfir19:    move.l    d4,d1            ;lock
  2021.         move.l    a5,d2            ;fibptr
  2022.         jsr    _LVOExNext(a6)
  2023.         or.l    d0,d0
  2024.         bne.s    serfir15
  2025.         rts                ;exit if no success
  2026. serfir15:    tst.l    fib_DirEntryType(a5)
  2027.         bgt.s    serfir21        ;if a directory, try again
  2028.  
  2029. ;    first file found, check name for cpm compatibility
  2030. ;    check if name <= namelen chrs
  2031.  
  2032.         move.l    a5,a3            ;fibptr
  2033.         add.l    #fib_FileName,a3    ;ptr name
  2034.         move.l    #fnbuf,a4        ;tmp file name buf
  2035.         move.l    a4,a1
  2036.         move.w    #namelen+typelen,d0
  2037. serfir8:    move.b    #' ',(a1)+
  2038.         dbra    d0,serfir8        ;fill tmp with ' '
  2039.         move.w    #namelen,d0
  2040. serfir6:    cmp.b    #'.',(a3)
  2041.         beq.s    serfir4         ;if type separator found
  2042.         tst.b    (a3)
  2043.         beq.s    serfir9         ;if end found
  2044.         move.b    (a3)+,(a4)+             ;to tmp
  2045.         dbra    d0,serfir6        ;name loop
  2046. serfir21:    move.b    #-1,d2            ;not valid
  2047.         bra    serfir20        ;if no cpm name, try again
  2048.  
  2049. ;    check if type <= typelen chrs
  2050.  
  2051. serfir4:    add.w    d0,a4            ;skip rest of name
  2052.         addq.l    #1,a3            ;skip '.'
  2053.         move.w    #typelen,d0
  2054. serfir7:    tst.b    (a3)
  2055.         beq.s    serfir9         ;if end found
  2056.         move.b    (a3)+,(a4)+             ;to tmp
  2057.         dbra    d0,serfir7        ;type loop
  2058.         bra.s    serfir21        ;if no cpm type, try again
  2059.  
  2060. ;    if file checks out
  2061. ;    set up directory entry at dma address
  2062.  
  2063. serfir9:    move.l    a4save,a2        ;ptr pgm middle
  2064.         add.w    dmaddr,a2        ;abs ptr file dma
  2065.         move.l    #fnbuf,a1
  2066.         clr.b    (a2)+                   ;drive
  2067.         move.w    #namelen+typelen-1,d0
  2068. serfir10:    cmp.b    #'a',(a1)
  2069.         blt.s    serfir12        ;if upper case
  2070.         sub.b    #$20,(a1)               ;to lower
  2071. serfir12:    move.b    (a1)+,(a2)+
  2072.         dbra    d0,serfir10        ;move file name
  2073.         move.l    fib_Size(a5),d1
  2074.         move.l    d1,d2
  2075.         move.l    #14,d0
  2076.         lsr.l    d0,d1            ;/16384, ex count
  2077.         move.b    excnt,d0
  2078.         cmp.b    d1,d0
  2079.         ble.s    serfir18
  2080.         moveq.l #0,d0            ;flg no find
  2081.         rts                ;exit if ex too big for file
  2082. serfir18:    beq.s    serfir22        ;if last ex
  2083.         move.w    #$ffff,d2        ;set max size
  2084. serfir22:    move.b    d0,(a2)+                ;ex
  2085.         addq.b    #1,excnt        ;nxt ex
  2086.         clr.b    (a2)+
  2087.         clr.b    (a2)+                   ;clr s1 & s2
  2088.         and.l    #$00003fff,d2
  2089.         move.l    d2,d0
  2090.         and.w    #$7f,d0
  2091.         beq.s    serfir03        ;if exact rec
  2092.         add.w    #128,d2         ;add 1 rec
  2093. serfir03:    lsr.l    #7,d2            ;/128, rec cnt
  2094.         move.b    d2,(a2)+                ;rc
  2095.         move.w    #fcbcr-fcbd0-1,d0
  2096. serfir11:    clr.b    (a2)+
  2097.         dbra    d0,serfir11        ;clr rest
  2098.         moveq.l #1,d2            ;flg no error
  2099.         rts
  2100.  
  2101. ;    xlname xlnameb
  2102. ;    translate name from cpm fcb format to amigados format
  2103. ;    entry : xlname : a3=fcb ptr, (a4save)=ptr to log pgm start
  2104. ;        xlnameb: as xlname + a4=amiga name buffer
  2105. ;    exit  : d1=ptr name
  2106. ;    chg   : d0,d1
  2107. ;        a2,a3,a4
  2108.  
  2109. xlname:     move.l    #fnbuf,a4
  2110. xlnameb:    move.l    a4,-(a7)
  2111.         move.b    (a3)+,d0
  2112.         bne.s    xlname1         ;if not default
  2113.         move.l    a4save,a2        ;ptr pgm middle
  2114.         move.b    pzdrv-pagezero(a2),d0   ;def drv
  2115.         addq.b    #1,d0            ;fcb format
  2116. xlname1:    add.b    #$40,d0         ;drv letter
  2117.         move.b    d0,(a4)+                ;to name buf
  2118.         move.b    d0,drvlet        ;and once again
  2119.         move.b    #':',(a4)+
  2120.  
  2121. ;    move name and type to buffer
  2122.  
  2123.         bclr.l    #31,d0            ;flg name loop
  2124.         move.w    #namelen-1,d0        ;name cnt
  2125. xlname3:    move.b    (a3)+,d1
  2126.         cmp.b    #' ',d1
  2127.         beq.s    xlname2         ;if end of name
  2128.         move.b    d1,(a4)+                ;to name buf
  2129.         dbra    d0,xlname3        ;name loop
  2130. xlname4:    bset.l    #31,d0
  2131.         bne.s    xlname5         ;if type loop
  2132.         move.w    #typelen-1,d0        ;type cnt
  2133.         move.b    #'.',(a4)+              ;name/type delimiter
  2134.         bra.s    xlname3         ;enter type loop
  2135.  
  2136. ;    premature end of name
  2137.  
  2138. xlname2:    add.w    d0,a3            ;skip empty part of name
  2139.         beq.s    xlname4
  2140. xlname5:    clr.b    (a4)                    ;end of name
  2141.         move.l    (a7)+,d1                ;name ptr
  2142.         rts
  2143.  
  2144. ;    conchk
  2145. ;    check for character from console, receive it if any
  2146. ;    exit : d6.b=chr, z=no chr
  2147. ;    chg : d0,d1,d6
  2148. ;          a0,a1
  2149.  
  2150. conchk:     move.l    _SysBase,a6
  2151.         move.l    cimport,a0        ;con in port ptr
  2152.         jsr    _LVOGetMsg(a6)
  2153.         or.l    d0,d0
  2154.         bne.s    conchk1         ;if msg
  2155.         rts                ;exit if no msg
  2156.  
  2157. ;    message from console
  2158. ;    get chr, and queue new request
  2159.  
  2160. conchk1:    move.b    conichr,d6        ;chr
  2161.         move.l    #conimsg,a1        ;ptr IOReq, read
  2162.         move.l    #conichr,cimdata    ;data ptr
  2163.         move.l    #1,cimlen
  2164.         jsr    _LVOSendIO(a6)
  2165.         moveq.l #1,d0            ;flg chr
  2166.         rts
  2167.  
  2168. ;    conwait
  2169. ;    wait for chr from console
  2170. ;    exit : d6.b=chr
  2171. ;    chg : d0,d1,d2,d3,d6
  2172. ;          a0,a1,a2,a3,a6
  2173.  
  2174. conwait:    bset.b    #2,glflgs        ;flg conwait
  2175.         bsr.s    conchk
  2176.         beq.s    conwait1        ;if no chr
  2177.         bclr.b    #2,glflgs        ;flg no conwait
  2178.         rts
  2179. conwait1:    jsr    minpeh
  2180.         bra.s    conwait         ;get chr
  2181.  
  2182. ;    conout conout1 conout2
  2183. ;    output chr to console
  2184. ;    output string to console
  2185. ;    entry : conout : d0.b=chr
  2186. ;        conout1: (comdata)=ptr to string+<nul>
  2187. ;        conout2: (comdata)=ptr to string, (comlen)=length of string
  2188. ;    chg :    d0,d1
  2189. ;        a0,a1,a6,a7
  2190.  
  2191. conout1:    move.l    comdata,a0
  2192.         move.l    a0,d1
  2193. conout4:    tst.b    (a0)+
  2194.         bne.s    conout4         ;if not end
  2195.         sub.l    d1,a0
  2196.         subq.l    #1,a0            ;len
  2197.         move.l    a0,comlen
  2198.         bra.s    conout2
  2199. conout:     move.b    d0,conochr        ;data
  2200.         move.l    #conochr,comdata
  2201.         move.l    #1,comlen
  2202. conout2:    movem.l d2-d5,-(a7)
  2203.         move.l    comlen,d3        ;for use by Write
  2204.         move.l    comdata,d5
  2205.         move.l    _SysBase,a6
  2206.         move.l    #conomsg,a1        ;ptr IOReq, write
  2207.         jsr    _LVODoIO(a6)
  2208.         or.l    d0,d0
  2209.         beq.s    conout3         ;if no error
  2210.         jmp    error6
  2211.  
  2212. ;    log to file if so requested
  2213.  
  2214. conout3:    move.l    handle2,d1
  2215.         beq.s    conout5         ;if no log file
  2216.         move.l    logcnt,d4        ;used in buffer
  2217.         add.l    d3,d4
  2218.         cmp.l    #logsiz,d4
  2219.         blt.s    conout6         ;if new data will fit
  2220.  
  2221. ;    if new data will overflow buffer
  2222. ;    write buffer to file
  2223.  
  2224.         sub.l    d3,d4            ;logcnt
  2225.         exg.l    d3,d4            ;logcnt to d3
  2226.         move.l    logbuf,d2
  2227.         move.l    _DOSBase,a6
  2228.         jsr    _LVOWrite(a6)
  2229.         clr.l    logcnt
  2230.         move.l    d4,d3            ;new data len
  2231.         cmp.l    #logsiz,d4
  2232.         blt.s    conout6         ;if new data will fit
  2233.         move.l    handle2,d1
  2234.         move.l    d5,d2            ;new data ptr
  2235.         jsr    _LVOWrite(a6)
  2236. conout5:    movem.l (a7)+,d2-d5
  2237.         rts
  2238.  
  2239. ;    put new data in buffer
  2240. ;    d3=new data len, d4=total len, d5=ptr new data
  2241.  
  2242. conout6:    move.l    d5,a0            ;ptr new data
  2243.         sub.l    d3,d4            ;d4=present logcnt
  2244.         move.l    logbuf,a1
  2245.         add.l    d4,a1            ;ptr into logbuf
  2246.         add.l    d3,d4
  2247.         move.l    d4,logcnt
  2248.         subq.l    #1,d3
  2249. conout7:    move.b    (a0)+,(a1)+
  2250.         dbra    d3,conout7        ;move data to buf
  2251.         bra.s    conout5
  2252.  
  2253. ;    getclin
  2254. ;    get one line of data from console
  2255. ;    exit on <cr> or full buffer
  2256. ;    exit on ^C in pos 1 to main1
  2257. ;    convert all other ctrl chrs to ^<chr>
  2258. ;    entry : d4=max address + 1, d5=min address
  2259. ;        a4=buffer ptr
  2260. ;    exit  : a4=ptr last used in buffer + 1
  2261. ;        d4,d5 same
  2262.  
  2263. ;    9->
  2264.  
  2265. getclin:    bsr    conwait
  2266.         cmp.b    #$20,d6
  2267.         bge.s    getclin1        ;if no ctrl chr
  2268.  
  2269. ;    control chr
  2270.  
  2271.         cmp.b    #3,d6
  2272.         beq.s    getclin4        ;if ^C
  2273.         cmp.b    #bs,d6
  2274.         beq.s    getclin5        ;if backspace
  2275.         cmp.b    #cr,d6
  2276.         beq.s    getclin6        ;if cr
  2277.  
  2278. ;    unrecognized control chr
  2279.  
  2280. getclin8:    move.b    #'^',d0
  2281.         bsr    conout
  2282.         move.b    d6,d0
  2283.         add.b    #$40,d0         ;make real chr
  2284.         bsr    conout
  2285.         bra.s    getclin3
  2286.  
  2287. ;    normal chr
  2288.  
  2289. getclin1:    move.b    d6,d0            ;chr
  2290. getclin2:    bsr    conout
  2291.         cmp.b    #'a',d6
  2292.         blt.s    getclin3        ;if upper case
  2293.         sub.b    #$20,d6         ;make upper case
  2294. getclin3:    move.b    d6,(a4)+                ;store chr
  2295.         cmp.l    d4,a4
  2296.         blt.s    getclin         ;if not at end
  2297.  
  2298. ;    cr
  2299.  
  2300. getclin6:    rts
  2301.  
  2302. ;    ^C
  2303.  
  2304. getclin4:    cmp.l    d5,a4
  2305.         bne.s    getclin8        ;if not at start
  2306.         jmp    osexit            ;restart cpm
  2307.  
  2308. ;    backspace
  2309.  
  2310. getclin5:    cmp.l    d5,a4
  2311.         beq.s    getclin         ;if at start
  2312.         move.b    -(a4),d0
  2313.         cmp.b    #$20,d0
  2314.         bge.s    getclin7        ;if no ctrl chr
  2315.         move.l    #delete,comdata
  2316.         bsr    conout1
  2317. getclin7:    move.l    #delete,comdata
  2318.         bsr    conout1
  2319.         bra    getclin
  2320.  
  2321. ;    bioscc
  2322. ;    bios console check
  2323. ;    NOTEZ BIEN !!!
  2324. ;    all console status requests should be routed through this routine
  2325. ;    exit : d6.b=00 : if no chr, ff if chr
  2326.  
  2327. bioscc:     move.l    _SysBase,a6
  2328.         btst.b    #3,glflgs
  2329.         bne.s    bioscc1         ;if chr (old chk)
  2330.         bsr    conchk
  2331.         beq.s    bioscc2         ;if no chr
  2332.         move.b    d6,conbuf        ;chr
  2333.         bset.b    #3,glflgs        ;flg chr
  2334. bioscc1:    move.b    #$ff,d6         ;flg chr
  2335.         rts
  2336.  
  2337. ;    no message
  2338.  
  2339. bioscc2:    move.b    #0,d6            ;flg no chr in a
  2340.         rts
  2341.  
  2342. ;    biosci
  2343. ;    bios console input
  2344. ;    NOTEZ BIEN !!!
  2345. ;    all console input should be routed through this routine
  2346. ;    exit : d6.b=chr
  2347.  
  2348. biosci:     move.l    _SysBase,a6
  2349.         btst.b    #3,glflgs
  2350.         bne.s    biosci1         ;if old chr
  2351.         bsr    conwait
  2352.         rts
  2353.  
  2354. ;    old character
  2355.  
  2356. biosci1:    bclr.b    #3,glflgs        ;flg no chr
  2357.         move.b    conbuf,d6        ;old chr
  2358.         rts
  2359.  
  2360. ;    routines for translating escape sequences
  2361. ;    from adm3a to ansi x3.64
  2362. ;    entry : a0=ptr to last in buffer +1
  2363.  
  2364. ;    txlnop
  2365. ;    recognized but ignored escape sequences
  2366. ;    entry : -
  2367. ;    exit  : -
  2368.  
  2369. txlnop:     bra    bdos0611
  2370.  
  2371. ;    txl27
  2372. ;    start reverse video
  2373. ;    entry : -
  2374. ;    exit  : <csi> 7 m
  2375.  
  2376. txl27:        move.l    #txl27d,comdata
  2377.         bra    txl3d4
  2378.  
  2379. ;    data to be sent to console
  2380.  
  2381. txl27d:     dc.b    csi,'7','m',0
  2382.         ds.w    0            ;alignment
  2383.  
  2384. ;    txl28
  2385. ;    end reverse video
  2386. ;    entry : -
  2387. ;    exit  : <csi> 0 m
  2388.  
  2389. txl28:        move.l    #txl28d,comdata
  2390.         bra    txl3d4
  2391.  
  2392. ;    data to be sent to console
  2393.  
  2394. txl28d:     dc.b    csi,'0','m',0
  2395.         ds.w    0            ;alignment
  2396.  
  2397. ;    txl3d
  2398. ;    position cursor
  2399. ;    entry : <line+$20> <column+$20> (in hex, line & column starts at 0)
  2400. ;    exit  : <csi> <line> ; <column> H (line & columns starts at 1)
  2401.  
  2402. txl3d:        move.l    #txl3dd+4,a1        ;ptr tx data tens col
  2403.         move.w    #1,d2            ;2 numbers
  2404. txl3d3:     move.b    -(a0),d0                ;col/line+$20
  2405.         sub.b    #$20,d0         ;col/line pos
  2406.         addq.b    #1,d0            ;conv to ansi pos
  2407. txl3d2:     move.b    #-1,d1            ;res
  2408. txl3d1:     addq.b    #1,d1
  2409.         sub.b    #10,d0
  2410.         bcc.s    txl3d1            ;if no cy
  2411.         add.b    #$30,d1         ;make ascii tens
  2412.         move.b    d1,(a1)+                ;put in tx data
  2413.         add.b    #$30+10,d0        ;make ascii units
  2414.         move.b    d0,(a1)                 ;put in tx data
  2415.         subq.l    #4,a1            ;ptr tx data tens line
  2416.         dbra    d2,txl3d3        ;do line
  2417.         move.l    #txl3dd,comdata
  2418. txl3d4:     bsr    conout1
  2419.         bra    bdos0611        ;exit
  2420.  
  2421. ;    data to be sent to console
  2422.  
  2423. txl3dd:     dc.b    csi,0,0,';',0,0,'H',0   ;zeros to be filled in
  2424.         ds.w    0            ;alignment
  2425.  
  2426. ;    txl4b
  2427. ;    erase to end line
  2428. ;    entry : -
  2429. ;    exit  : <csi> <$4b>
  2430.  
  2431. txl4b:        move.l    #txl4bd,comdata
  2432.         bra    txl3d4
  2433.  
  2434. ;    data to be sent to console
  2435.  
  2436. txl4bd:     dc.b    csi,$4b,0
  2437.         ds.w    0            ;alignment
  2438.  
  2439. ;    txl4c
  2440. ;    clear and home
  2441. ;    entry : -
  2442. ;    exit  : <$0c> <csi> H
  2443.  
  2444. txl4c:        move.l    #txl4cd,comdata
  2445.         bra    txl3d4
  2446.  
  2447. ;    data to be sent to console
  2448.  
  2449. txl4cd:     dc.b    $0c,csi,'H',0
  2450.         ds.w    0            ;alignment
  2451.  
  2452. ;    esctab
  2453. ;    table for receiving escape sequences
  2454. ;    word : sequence character
  2455. ;    long : address to translation routine
  2456. ;    word : -(number of parameters)
  2457.  
  2458. esctab:     dc.w    $27            ;start reverse video
  2459.         dc.l    txl27
  2460.         dc.w    0
  2461.         dc.w    $28            ;end reverse video
  2462.         dc.l    txl28
  2463.         dc.w    0
  2464.         dc.w    $2b            ;end reduced intensity
  2465.         dc.l    txlnop
  2466.         dc.w    0
  2467.         dc.w    $2c            ;start reduced intensity
  2468.         dc.l    txlnop
  2469.         dc.w    0
  2470.         dc.w    $3d            ;cursor positioning
  2471.         dc.l    txl3d
  2472.         dc.w    -2
  2473.         dc.w    $4b            ;erase to end of line
  2474.         dc.l    txl4b
  2475.         dc.w    0
  2476.         dc.w    $4c            ;clear and home
  2477.         dc.l    txl4c
  2478.         dc.w    0
  2479. esctabend:
  2480.  
  2481. ;    bios functions
  2482.  
  2483. ;    bios03, wboot
  2484.  
  2485. bios03:     addq.l    #4,a7            ;remove ret addr
  2486.         jmp    osexit
  2487.  
  2488. ;    bios06, const
  2489. ;    check for console char ready
  2490. ;    exit : a=0 : if no chr, ff if chr
  2491.  
  2492. bios06:     bsr    bioscc
  2493.         move.b    d6,d0save+3        ;flg in a
  2494.         bra    bdos0611        ;exit
  2495.  
  2496. ;    bios09, conin
  2497. ;    read console character in, wait until character available
  2498. ;    exit : a=chr
  2499.  
  2500. bios09:     bsr    biosci
  2501.         move.b    d6,d0save+3        ;chr in a
  2502.         bra    bdos0611        ;exit
  2503.  
  2504. ;    bios0c, conout
  2505. ;    write console character out
  2506. ;    entry : c=chr
  2507.  
  2508. bios0c:     move.b    d3save+3,d0        ;c reg
  2509.         bra    bdos0613
  2510.  
  2511. ;    bios0f, list
  2512. ;    write list character out
  2513. ;    entry : c=chr
  2514.  
  2515. bios0f:     bra    bdos0611        ;exit
  2516.  
  2517. ;    bios2d, listst
  2518. ;    check list status
  2519. ;    exit : a=$ff if ready, a=0 if not ready
  2520.  
  2521. bios2d:     clr.b    d0save+3        ;flg not rdy
  2522.         bra    bdos0611        ;exit
  2523.  
  2524. bios00:
  2525. bios12:
  2526. bios15:
  2527. bios18:
  2528. bios1b:
  2529. bios1e:
  2530. bios21:
  2531. bios24:
  2532. bios27:
  2533. bios2a:
  2534. bios30:     bra    oserr2
  2535.  
  2536. ;    initialized data
  2537. ;    strings
  2538. ;    errors, max 27 characters
  2539. ;             123456789012345678901234567
  2540. errtxt1:    dc.b    'Transfer over bios area',0
  2541. errtxt2:    dc.b    'Unimplemented bios function',0
  2542. errtxt3:    dc.b    'Transfer under bdos area',0
  2543. errtxt4:    dc.b    'Transfer between bdos/bios',0
  2544. errtxt5:    dc.b    'Undefined bdos function',0
  2545. errtxt6:    dc.b    'Unimplemented bdos function',0
  2546. errtxt7:    dc.b    'Unimplemented escape seq',0
  2547. errtxt8:    dc.b    'File handle table full',0
  2548.  
  2549. ;    prompts
  2550.  
  2551. openlogpmt:    dc.b    'Enter name of log file',0
  2552.  
  2553. ;    various
  2554.  
  2555. conname:    dc.b    'console.device',0
  2556. delete:     dc.b    bs,' ',bs,0
  2557. dirsep:     dc.b    ' : ',0
  2558. filetyp:    dc.b    '.com',0
  2559. filetype:
  2560. logfile:    dc.b    'a:cpm.log',0                   ;default string
  2561. logfend:
  2562.         ds.b    logfilesize-(logfend-logfile)   ;fill out
  2563. newline:    dc.b    cr,lf,0
  2564. startmsg:    dc.b    'CP/M 2.2 - Z80 - ADM3A - emulator',cr,lf
  2565.         dc.b    'AmigaDos Bios V1.02',cr,lf
  2566.         dc.b    'Copyright (C) 1988 by Ulf Nordquist !',cr,lf,cr,lf,0
  2567.  
  2568. ;    cpm console window data area
  2569. ;    title
  2570.  
  2571. conwinttl:    dc.b    'CP/M Console',0
  2572.  
  2573. ;    normal console NewWindow struct
  2574.  
  2575. conwin:     dc.w    winx,winy        ;top x,y
  2576.         dc.w    conwinw,conwinh     ;width, height
  2577.         dc.b    windp,winbp        ;detail, block pen
  2578.         dc.l    0            ;idcmp flags
  2579.         dc.l    conwinflg        ;window flgs
  2580.         dc.l    0            ;ptr 1st gadget
  2581.         dc.l    0            ;ptr checkmark
  2582.         dc.l    conwinttl        ;ptr title
  2583.         dc.l    0            ;ptr screen
  2584.         dc.l    0            ;ptr bit map
  2585.         dc.w    winmnw,winmnh        ;min width height
  2586.         dc.w    winmxw,winmxh        ;max width height
  2587.         dc.w    WBENCHSCREEN        ;screen type
  2588.  
  2589. ;    debug console NewWindow struct
  2590.  
  2591. dbgconwin:    dc.w    winx,winy        ;top x,y
  2592.         dc.w    dbgconwinw,dbgconwinh    ;width, height
  2593.         dc.b    windp,winbp        ;detail, block pen
  2594.         dc.l    0            ;idcmp flags
  2595.         dc.l    dbgconwinflg        ;window flgs
  2596.         dc.l    0            ;ptr 1st gadget
  2597.         dc.l    0            ;ptr checkmark
  2598.         dc.l    conwinttl        ;ptr title
  2599.         dc.l    0            ;ptr screen
  2600.         dc.l    0            ;ptr bit map
  2601.         dc.w    winmnw,winmnh        ;min width height
  2602.         dc.w    winmxw,winmxh        ;max width height
  2603.         dc.w    WBENCHSCREEN        ;screen type
  2604.  
  2605. ;    input window data area
  2606. ;    input window NewWindow struct
  2607.  
  2608. inpwin:     dc.w    winx,winy        ;top x,y
  2609.         dc.w    inpwinw,0        ;width, height (setup)
  2610.         dc.b    windp,winbp        ;detail, block pen
  2611.         dc.l    GADGETUP        ;idcmp flags
  2612.         dc.l    WINDOWDRAG+WINDOWDEPTH+ACTIVATE ;window flags
  2613.         dc.l    inpok            ;ptr 1st gadget
  2614.         dc.l    0            ;ptr checkmark
  2615.         dc.l    conwinttl        ;ptr title
  2616.         dc.l    0            ;ptr screen
  2617.         dc.l    0            ;ptr bit map
  2618.         dc.w    0,0            ;min width height
  2619.         dc.w    0,0            ;max width height
  2620.         dc.w    WBENCHSCREEN        ;screen type
  2621.  
  2622. ;    input window gadget structs
  2623. ;    Ok
  2624.  
  2625. inpok:        dc.l    inpcan            ;ptr nxt gadget
  2626.         dc.w    inpokx,inpoky        ;top x,y
  2627.         dc.w    inpokw,inpokh        ;width, height
  2628.         dc.w    GADGHCOMP+GRELBOTTOM    ;flags
  2629.         dc.w    RELVERIFY        ;activation
  2630.         dc.w    BOOLGADGET        ;gadget type
  2631.         dc.l    inpbox            ;ptr gadget render
  2632.         dc.l    0            ;ptr select render
  2633.         dc.l    1$            ;ptr gadget txt
  2634.         dc.l    0            ;mutual exclude
  2635.         dc.l    0            ;ptr spec info
  2636.         dc.w    okid            ;id#
  2637.         dc.l    0            ;ptr user data
  2638.  
  2639. ;    text to ok gadget
  2640.  
  2641. 1$:        dc.b    winbp,windp        ;front, back pen
  2642.         dc.b    RP_JAM2         ;draw mode
  2643.         dc.b    0            ;word align fill
  2644.         dc.w    inpoktx,2        ;top x,y
  2645.         dc.l    0            ;ptr font
  2646.         dc.l    2$            ;ptr text
  2647.         dc.l    0            ;ptr next intui text
  2648. 2$:        dc.b    'Ok',0
  2649.  
  2650. ;    box for ok & cancel gadgets
  2651.  
  2652. inpbox:     dc.w    0,0            ;top x,y
  2653.         dc.b    winbp,windp        ;front, back pen
  2654.         dc.b    RP_JAM2         ;draw mode
  2655.         dc.b    (2$-1$)/4               ;# coord pairs
  2656.         dc.l    1$            ;ptr coord pairs
  2657.         dc.l    0            ;nxt border
  2658.  
  2659. ;    coordinates for box
  2660. ;            x,y
  2661.  
  2662. 1$:        dc.w    0,0
  2663.         dc.w    0,inpokh-1
  2664.         dc.w    inpokw-1,inpokh-1
  2665.         dc.w    inpokw-1,0
  2666.         dc.w    0,0
  2667. 2$:
  2668.  
  2669. ;    input window gadget structs
  2670. ;    cancel
  2671.  
  2672. inpcan:     dc.l    inpstr1         ;ptr nxt gadget
  2673.         dc.w    inpcanx,inpoky        ;top x,y
  2674.         dc.w    inpcanw,inpcanh     ;width, height
  2675.         dc.w    GADGHCOMP+GRELBOTTOM    ;flags
  2676.         dc.w    RELVERIFY        ;activation
  2677.         dc.w    BOOLGADGET        ;gadget type
  2678.         dc.l    inpbox            ;ptr gadget render
  2679.         dc.l    0            ;ptr select render
  2680.         dc.l    1$            ;ptr gadget txt
  2681.         dc.l    0            ;mutual exclude
  2682.         dc.l    0            ;ptr spec info
  2683.         dc.w    canid            ;id#
  2684.         dc.l    0            ;ptr user data
  2685.  
  2686. ;    text to cancel gadget
  2687.  
  2688. 1$:        dc.b    winbp,windp        ;front, back pen
  2689.         dc.b    RP_JAM2         ;draw mode
  2690.         dc.b    0            ;word align fill
  2691.         dc.w    2,2            ;top x,y
  2692.         dc.l    0            ;ptr font
  2693.         dc.l    2$            ;ptr text
  2694.         dc.l    0            ;ptr next intui text
  2695. 2$:        dc.b    'Cancel',0
  2696.  
  2697. ;    input window gadget structs
  2698. ;    first string
  2699.  
  2700. inpstr1:    dc.l    0            ;ptr nxt gadget
  2701.         dc.w    inpstrx,0        ;top x,y (setup)
  2702.         dc.w    inpstrw,inpstrh     ;width, height
  2703.         dc.w    SELECTED+GADGHCOMP    ;flags
  2704.         dc.w    RELVERIFY        ;activation
  2705.         dc.w    STRGADGET        ;gadget type
  2706.         dc.l    inpboxs         ;ptr gadget render
  2707.         dc.l    0            ;ptr select render
  2708.         dc.l    0            ;ptr gadget txt
  2709.         dc.l    0            ;mutual exclude
  2710.         dc.l    inpstr1info        ;ptr spec info
  2711.         dc.w    strid            ;id#
  2712.         dc.l    0            ;ptr user data
  2713.  
  2714. ;    special info for first string gadget
  2715.  
  2716. inpstr1info:    dc.l    0            ;ptr buffer (setup)
  2717.         dc.l    undobuf         ;ptr undo buffer
  2718.         dc.w    0            ;init buf pos
  2719.         dc.w    strbufsiz        ;buf size (setup)
  2720.         dc.w    0            ;pos of 1:st disp chr
  2721.         dc.w    0            ;pos in undo buf
  2722.         dc.w    0            ;# chr in buf
  2723.         dc.w    0            ;# chr disp
  2724.         dc.w    0,0            ;top x,y
  2725.         dc.l    0            ;ptr layer
  2726.         dc.l    0            ;result if int gadget
  2727.         dc.l    0            ;ptr alt key map
  2728.  
  2729. ;    box for string cancel gadget
  2730.  
  2731. inpboxs:    dc.w    -2,-2             ;top x,y
  2732.         dc.b    winbp,windp        ;front, back pen
  2733.         dc.b    RP_JAM2         ;draw mode
  2734.         dc.b    (2$-1$)/4               ;# coord pairs
  2735.         dc.l    1$            ;ptr coord pairs
  2736.         dc.l    0            ;nxt border
  2737.  
  2738. ;    coordinates for box
  2739. ;            x,y
  2740.  
  2741. 1$:        dc.w    0,0
  2742.         dc.w    0,inpstrh
  2743.         dc.w    inpstrw,inpstrh
  2744.         dc.w    inpstrw,0
  2745.         dc.w    0,0
  2746. 2$:
  2747.  
  2748. ;    tables for buffer and prompt pointers
  2749. ;    set up by caller
  2750.  
  2751. inpbuftab:    ds.b    2+4
  2752. inppmttab:    ds.l    1
  2753.  
  2754. ;    parameters set up by pzinit
  2755. ;    area 1 : $0000-$0007
  2756.  
  2757. pz1:        dc.w    pz2-pz1-4-1        ;len of 1:st
  2758.         dc.w    0            ;rel addr of 1:st
  2759. pagezero:    dc.b    z80jp            ;0 z80 jp
  2760.         dc.b    bioslo+3        ;1
  2761.         dc.b    bioshi            ;2 WBOOT in bios table
  2762.         dc.b    iobyte            ;3
  2763. pzdrv:        dc.b    defdrv            ;4 default drive
  2764.         dc.b    z80jp            ;5 z80 jp
  2765.         dc.b    fbaselo         ;6
  2766.         dc.b    fbasehi         ;7 FBASE:
  2767.  
  2768. ;    area 2 : $005c-$007b fcb1 & fcb2
  2769.  
  2770. pz2:        dc.w    pz3-pz2-4-1        ;len of 2:nd
  2771.         dc.w    fcb1            ;rel addr of 2nd
  2772.         dc.b    0            ;$5c fcb1 drive
  2773.         dc.b    ' '                     ;$5d fcb1 n1
  2774.         dc.b    ' '                     ;$5e fcb1 n2
  2775.         dc.b    ' '                     ;$5f fcb1 n3
  2776.         dc.b    ' '                     ;$60 fcb1 n4
  2777.         dc.b    ' '                     ;$61 fcb1 n5
  2778.         dc.b    ' '                     ;$62 fcb1 n6
  2779.         dc.b    ' '                     ;$63 fcb1 n7
  2780.         dc.b    ' '                     ;$64 fcb1 n8
  2781.         dc.b    ' '                     ;$65 fcb1 t1
  2782.         dc.b    ' '                     ;$66 fcb1 t2
  2783.         dc.b    ' '                     ;$67 fcb1 t3
  2784.         dc.b    0            ;$68 fcb1 ex
  2785.         dc.b    0            ;$69 fcb1 s1
  2786.         dc.b    0            ;$6a fcb1 s2
  2787.         dc.b    0            ;$6b fcb1 rc
  2788.         dc.b    0            ;$6c fcb2 drive
  2789.         dc.b    ' '                     ;$6d fcb2 n1
  2790.         dc.b    ' '                     ;$5e fcb2 n2
  2791.         dc.b    ' '                     ;$5f fcb2 n3
  2792.         dc.b    ' '                     ;$70 fcb2 n4
  2793.         dc.b    ' '                     ;$71 fcb2 n5
  2794.         dc.b    ' '                     ;$72 fcb2 n6
  2795.         dc.b    ' '                     ;$73 fcb2 n7
  2796.         dc.b    ' '                     ;$74 fcb2 n8
  2797.         dc.b    ' '                     ;$75 fcb2 t1
  2798.         dc.b    ' '                     ;$76 fcb2 t2
  2799.         dc.b    ' '                     ;$77 fcb2 t3
  2800.         dc.b    0            ;$78 fcb2 ex
  2801.         dc.b    0            ;$79 fcb2 s1
  2802.         dc.b    0            ;$7a fcb2 s2
  2803.         dc.b    0            ;$7b fcb2 rc
  2804.  
  2805. ;    area 3 : disk parameter block
  2806.  
  2807. pz3:        dc.w    pz4-pz3-4-1        ;len of 3:rd
  2808.         dc.w    dpb            ;rel addr of 3:rd
  2809.         dc.b    spt
  2810.         dc.b    0            ;SPT sectors per track, 16b
  2811.         dc.b    bsh            ;BSH block shift factor, 8b
  2812.         dc.b    blm            ;BLM block mask, 8b
  2813.         dc.b    exm            ;EXM extent mask, 8b
  2814.         dc.b    dsm&$000000ff
  2815.         dc.b    dsm>>8            ;DSM, 16b
  2816.         dc.b    drm&$000000ff
  2817.         dc.b    drm>>8            ;DRM dir entries - 1, 16b
  2818.         dc.b    al0            ;AL0, 8b
  2819.         dc.b    al1            ;AL1, 8b
  2820.         dc.b    cks&$000000ff
  2821.         dc.b    cks>>8            ;CKS, 16b
  2822.         dc.b    off&$000000ff
  2823.         dc.b    off>>8            ;OFF, 16b
  2824.  
  2825. ;    area 4 : empty
  2826.  
  2827. pz4:        dc.w    0            ;len of 4:th, mark end
  2828.  
  2829. ;    bdostab
  2830. ;    jump table for bdos functions
  2831.  
  2832. bdostab:    dc.l    bdos00
  2833.         dc.l    bdos01
  2834.         dc.l    bdos02
  2835.         dc.l    bdos03
  2836.         dc.l    bdos04
  2837.         dc.l    bdos05
  2838.         dc.l    bdos06
  2839.         dc.l    bdos07
  2840.         dc.l    bdos08
  2841.         dc.l    bdos09
  2842.         dc.l    bdos10
  2843.         dc.l    bdos11
  2844.         dc.l    bdos12
  2845.         dc.l    bdos13
  2846.         dc.l    bdos14
  2847.         dc.l    bdos15
  2848.         dc.l    bdos16
  2849.         dc.l    bdos17
  2850.         dc.l    bdos18
  2851.         dc.l    bdos19
  2852.         dc.l    bdos20
  2853.         dc.l    bdos21
  2854.         dc.l    bdos22
  2855.         dc.l    bdos23
  2856.         dc.l    bdos24
  2857.         dc.l    bdos25
  2858.         dc.l    bdos26
  2859.         dc.l    bdos27
  2860.         dc.l    bdos28
  2861.         dc.l    bdos29
  2862.         dc.l    bdos30
  2863.         dc.l    bdos31
  2864.         dc.l    bdos32
  2865.         dc.l    bdos33
  2866.         dc.l    bdos34
  2867.         dc.l    bdos35
  2868.         dc.l    bdos36
  2869.         dc.l    bdos37
  2870.         dc.l    oserr5        ;38 is undefined in cpm
  2871.         dc.l    oserr5        ;39 is undefined in cpm
  2872.         dc.l    bdos40
  2873. bdostabend:
  2874.  
  2875. ;    biostab
  2876. ;    jump table for bios functions
  2877. ;    max length in z80 program area $40
  2878.  
  2879. biostab:    dc.l    bios00        ;0
  2880.         dc.l    bios03        ;1
  2881.         dc.l    bios06        ;2
  2882.         dc.l    bios09        ;3
  2883.         dc.l    bios0c        ;4
  2884.         dc.l    bios0f        ;5
  2885.         dc.l    bios12        ;6
  2886.         dc.l    bios15        ;7
  2887.         dc.l    bios18        ;8
  2888.         dc.l    bios1b        ;9
  2889.         dc.l    bios1e        ;a
  2890.         dc.l    bios21        ;b
  2891.         dc.l    bios24        ;c
  2892.         dc.l    bios27        ;d
  2893.         dc.l    bios2a        ;e
  2894.         dc.l    bios2d        ;f
  2895.         dc.l    bios30        ;10
  2896. biostabend:
  2897.  
  2898. ;    handles and associated filenames for CPM transient
  2899.  
  2900. handles:    dc.l    0        ;handle
  2901. hnd1:        ds.l    3        ;name, from FCB
  2902. hnd2:        dc.l    0
  2903.         ds.l    3
  2904.         dc.l    0
  2905.         ds.l    3
  2906.         dc.l    0
  2907.         ds.l    3
  2908.         dc.l    0
  2909.         ds.l    3
  2910. hndend:
  2911.  
  2912. hanentsiz    equ    hnd2-handles    ;size of one entry
  2913. hannamsiz    equ    hnd2-hnd1    ;size of one name entry
  2914. maxhan        equ    (hndend-handles)/hanentsiz ;maximal number of handles
  2915.  
  2916. ;    various
  2917.  
  2918. excnt:        dc.b    -1        ;ex counter for search directory
  2919. fibptr:     dc.l    0        ;ptr to file info area
  2920. flags:        dc.b    0        ;bit 0 : esc seq decoding
  2921.                     ;    1 : lock1 and fib valid
  2922. handle2:    dc.l    0        ;file handle for log file
  2923. lock1:        dc.l    0        ;file lock for search directory
  2924. logbuf:     dc.l    0        ;ptr to log file buffer
  2925.  
  2926. ;    console MsgPort
  2927.  
  2928. conmsgp:    dcb.l    2,0            ;succ,pred ptrs
  2929.         dc.b    NT_MSGPORT        ;type
  2930.         dc.b    0            ;priority
  2931.         dc.l    conmsgpn        ;name ptr    --- node
  2932.         dc.b    PA_SIGNAL        ;action
  2933. conmsgpsb:    dc.b    $ff            ;signalbit #
  2934. conmsgpt:    dc.l    0            ;task ptr    --- msg
  2935. 2$:        dc.l    3$            ;head ptr
  2936. 3$:        dc.l    0
  2937.         dc.l    2$            ;tail ptr
  2938.         dc.b    NT_MSGPORT        ;type
  2939.         dc.b    0            ;word align    --- list
  2940.  
  2941. conmsgpn:    dc.b    'CPMConsolePort',0
  2942.  
  2943. ;    console device IOStdReq, read
  2944.  
  2945. conimsg:    dcb.w    7,0            ;Node struct
  2946. cimport:    dc.l    conmsgp         ;msg port ptr
  2947.         dc.w    cimend-cimdev        ;msg size
  2948. cimdev:     dc.l    0            ;ptr Device
  2949. cimunit:    dc.l    0            ;ptr Unit
  2950.         dc.w    CMD_READ        ;command
  2951.         dc.b    0            ;flags
  2952.         dc.b    0            ;error
  2953.         dc.l    0            ;actual, byte cnt
  2954. cimlen:     dc.l    0            ;length, byte cnt
  2955. cimdata:    dc.l    0            ;data ptr
  2956.         dc.l    0            ;offset
  2957. cimend:
  2958.  
  2959. ;    console device IOStdReq, write
  2960.  
  2961. conomsg:    dcb.w    7,0            ;Node struct
  2962. comport:    dc.l    0            ;msg port ptr
  2963.         dc.w    comend-comdev        ;msg size
  2964. comdev:     dc.l    0            ;ptr Device
  2965. comunit:    dc.l    0            ;ptr Unit
  2966.         dc.w    CMD_WRITE        ;command
  2967.         dc.b    0            ;flags
  2968.         dc.b    0            ;error
  2969.         dc.l    0            ;actual, byte cnt
  2970. comlen:     dc.l    0            ;length, byte cnt
  2971. comdata:    dc.l    0            ;data ptr
  2972.         dc.l    0            ;offset
  2973. comend:
  2974.  
  2975. ;    not initialized data
  2976. ;    to save registers
  2977.  
  2978. d0save:     ds.l    1
  2979. d1save:     ds.l    1
  2980. d2save:     ds.l    1
  2981. d3save:     ds.l    1
  2982. d4save:     ds.l    1
  2983. d5save:     ds.l    1
  2984. d7save:     ds.l    1
  2985. a0save:     ds.l    1
  2986. a1save:     ds.l    1
  2987. a2save:     ds.l    1
  2988. a3save:     ds.l    1
  2989. a4save:     ds.l    1
  2990. a6save:     ds.l    1
  2991.  
  2992. foobar        equ    d2save+2
  2993.  
  2994. ;    various
  2995.  
  2996. conbuf:     dc.b    1        ;console read buffer for bios 06,09
  2997. conichr:    dc.l    1        ;read chr for con
  2998. conochr:    dc.l    1        ;write chr for con
  2999. escptr:     ds.w    1        ;rx cnt for esc seq
  3000. buffer:     ds.b    8        ;8 byte esc seq rx buffer
  3001. escrx:                    ;end of rx buffer+1
  3002. dmaddr:     ds.w    1        ;current cpm dma address
  3003. drvlet:     ds.b    1        ;xlname saves drive letter
  3004. escseq:     ds.b    1        ;current esc seq
  3005. escxlt:     ds.l    1        ;address to esc xlate routine
  3006. fnbuf:        ds.b    1+1+8+1+3+1    ;buffer for filename
  3007. fnbufe:
  3008. fnbuf2:     ds.b    1+1+8+1+3+1    ;secondary buffer for filename
  3009. fnbuf2e:
  3010. logcnt:     ds.l    1        ;byte count in logbuf
  3011. undobuf:    ds.b    strbufsiz    ;undo buf for str gadgets
  3012.  
  3013.         end
  3014.  
  3015.