home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / BDOS / DOSPLSOR.ARK / KBIOS4D.MAC < prev    next >
Text File  |  1986-10-31  |  14KB  |  445 lines

  1. title    'revised KAYPRO 4-83 DOS+/CPM2 BIOS (86/10/31)'
  2. ;#################################################################
  3. ;##    KAYPRO CBIOS for CP/M 2.2                ##
  4. ;##    Copyright (C) 1982 By Non-Linear Systems, Inc.        ##
  5. ;##    No warranty is made, expressed or implied.        ##
  6. ;#################################################################
  7. ;##    Last Update: july 7,1982    [001]            ##
  8. ;##        by  jim Nickerson    (Kaypro 2)        ##
  9. ;##        changes:                    ##
  10. ;##         -allow redefinition of kpd in cbios        ##
  11. ;##         -change to allow test of serial on liststatus    ##
  12. ;##         -default ul1: to tty on list            ##
  13. ;#################################################################
  14. ;##    Updated to match KAYPRO 4 bios, 83/10/1, cbf        ##
  15. ;#################################################################
  16. ;## Revised for double console, more stack, correct lsta,    ##
  17. ;##  avoid use of primed registers for future interrupts.    ##
  18. ;##  Anomalous connection to CCP eliminated. dmadr/ram remains.    ##
  19. ;##  "Warm boot" message eliminated. Boot error resets disks.    ##
  20. ;##  Disk shutdown when using list, reader, etc.        ##
  21. ;##  remote console with interrupt. ul1=crt on lst:  84/3/9 cbf    ##
  22. ;## by C.B.Falconer, 680 Hartford Tpk, Hamden Ct. (203)281-1438    ##
  23. ;#################################################################
  24. ;## "gorom" now passes iobyte in (l).  Future systems can thus    ##
  25. ;## implement device selection entirely in ROM.  New entries    ##
  26. ;## must be made for cin,cout,csta,rin,pout,lout,lsta, and for    ##
  27. ;## psta and rsta for future plans.  After this bios can shrink    ##
  28. ;#################################################################
  29. ;## (2) rev 85/01/06 to preserve (bc) across rom calls, and so    ##
  30. ;## that the "rem" device allows mixed remote and kbd input.    ##
  31. ;## Rem operation now halted with an 08Eh from keyboard, which    ##
  32. ;## is only available with the "uniqkeys" table configuration.    ##
  33. ;## (i.e. no translation at all).  This comes from numpad "-".    ##
  34. ;## All this provides the fundamental groundwork for RCPM and    ##
  35. ;## BBS operation.  Rem can be stopped by altering iobyte also. ##
  36. ;## Also removed anomalous connection to RAM storage.  This is    ##
  37. ;## carefully packed so the start-up message works on the orig-    ##
  38. ;## inal ROM.  Any extra length fouls it.  With NEWROM mounted    ##
  39. ;## vout returns current cursor pos'n in hl, and home returns    ##
  40. ;## pointer to disk system info (last errors/soft count). cbf    ##
  41. ;#################################################################
  42. ;## (3) rev 86/10/06 to initialize a wheel and PATH on cold     ##
  43. ;## boot for DOS+.  Allow function keys 92h up.        cbf    ##
  44. ;#################################################################
  45. ;## (4) rev 86/10/31 for "nul" device 3 on lister. lsta=true.   ##
  46. ;#################################################################
  47. ;##    86/12/07 No change.  DOS+ ver equate becomes 25        ##
  48. ;#################################################################
  49. ;
  50. ; Works for M80 and SLRMAC
  51. INCLUDE    Z80.LIB
  52. ;
  53. bver    equ    4;        cbf bios version
  54. vers    equ    25;        CPM/DOS+ version number
  55. ccpsz    equ    0800h;        size of CCP (can change independant)
  56. bdossz    equ    0E00h;        size of BDOS
  57. cpml    equ    ccpsz+bdossz;    lgth of CP/M sys (bytes, less BIOS)
  58. nsects    equ    cpml/128;    lgth of CP/M sys (sector, less BIOS)
  59. ;
  60. iobyte    equ    3;        logical to physical map
  61. ;                and initial usr/drv at iobyte+1
  62. ;
  63. ; SYSTEM DEPENDANT values
  64. trksec    equ    40;        sectors/track.
  65. bauda    equ    0;        control kbd baud rate
  66. msize    equ    63;        system memory size in k. Elim later
  67. ;                (I install RAMDSK above bios)
  68. ; KAYPRO DEPENDANT values
  69. bitpt    equ    1CH;        status/control bit mapped port
  70. @wheel    equ    045h;        And PATH at @wheel +1
  71. rom    equ    00000H;        base of rom
  72. ram    equ    0FC00H;        scratch ram
  73. ;
  74. cr    equ    0dh
  75. lf    equ    0ah
  76. clear    equ    01ah;        Clear Kaypro crt screen
  77. brk    equ    ('N' and 03fh) + 080h;    "REM" breakin char.
  78. ;
  79. ;
  80. ; *** CODE BEGINS, bios vector ***
  81. bios:    jmp    boot;        <00> arrive here from cold start
  82.     jmp    wboot;        <01> arrive here for warm start
  83.     jmp    const;        <02> console status return in A
  84. ;                     FF=ready, 00=not
  85.     jmp    conin;        <03> console char in
  86.     jmp    cout;        <04> console char out
  87.     jmp    list;        <05> listing char out
  88.     jmp    punch;        <06> punch char out
  89.     jmp    rin;        <07> reader char in
  90.     jmp    home;        <08> move to tk0 on selected dsk drv
  91.     jmp    seldk;        <09> select disk drive
  92.     jmp    setrk;        <10> set track #
  93.     jmp    setsec;        <11> set sector #
  94.     jmp    setdma;        <12> set DMA address
  95.     jmp    read;        <13> read selected sector
  96.     jmp    write;        <14> write selected sector
  97.     jmp    lsta;        <15> list status (Rdy for a char)
  98.     jmp    xltsec;        <16> sector translate
  99. ;
  100. ; defaults to be loaded
  101. ; These occupy the space for extended bios calls 17 thru 23
  102. iobgn:    db    10000001B;    initial value for i/o byte
  103. ;                    (may be patched)
  104. wtsafe:    db    0;        write safe flag, 0=false
  105. vtab:    db    11, 10, 8, 12;    vector pad xlate table ^k ^j ^h ^l
  106.     db    '0', '1', '2', '3'
  107.     db    '4', '5', '6', '7'
  108.     db    '8', '9', brk, ',';    Set intercept for REM
  109.     db    cr,  '.';        last on 091h key code
  110. bdbgn:    db    7;        initial serial port baud rate.
  111. ;                5,6,7,10,12,14 correspond to 300,
  112. ;                600,1200,2400,4800,9600 baud.
  113. ;
  114. ; add any extended bios calls here, #24 up. This should preserve
  115. ; compatibility with Kaypro normal software.
  116. ;
  117. ; if only these were standard CP/m items. Portable communications
  118.     jmp    sistat;        (24) Reader status
  119.     jmp    sostat;        (25) Punch status
  120.     jmp    romhl;        (26) GP rom system connector
  121. ;                     calls rom address (hl), passing
  122. ;                     a,b,c,d,e, returns a,f,d,e,h,l
  123. ;                     preserving bc
  124. ;
  125. ; logical devices are con: rdr: pun: and lst:
  126. ; physical devices are:
  127. ;    crt:    video and kbd
  128. ;    tty:    serial
  129. ;    lpt:    centronics
  130. ;    dbl:    video and lst device
  131. ;    rem:    video and tty (remote opn with CRT monitor)
  132. ;        kbd mixes with serin, can stop rem operation
  133. ;    nul:    Discards output, always ready
  134. ;
  135. ;con:    tty, crt, rem, dbl
  136. ;rdr:    tty (all assignments)
  137. ;pun:    tty (all assignments)
  138. ;lst:    tty, crt, lpt, nul
  139. ;
  140. ; check for local character and interuption. preserve (bc)
  141. chkhlt:    call    ksta
  142.     rz;            no local char
  143.     call    kbdin
  144.     cpi    brk
  145.     rnz;            not interrupted
  146. ;    "    "
  147. ; shut down "rem" operation
  148.     lxi    h,iobyte;    Must have been 2 in con field
  149.     dcr    m;        set back to "crt"
  150.     ori    07fh;        return a rub in case input
  151.     ret;            with nz to exit remin
  152. ;
  153. conin:    call    dkoff;        Immediate shut down on operator wait
  154.     lda    iobyte
  155.     ani    03H;        check i/o byte
  156.     jrz    serin;        0, serial
  157.     rar
  158.     jrnc    remin;        2, remote input
  159. ;     "     "        1,3 keyboard input
  160. kbdin:    mvi    l,rom+2DH
  161.     call    gorom;        go get char
  162.     ora    a
  163.     rp;            msb not set
  164. ;     "     "
  165. ; Translate kbd char (80h..91h) via system table
  166.     cpi    092h;        form table index to vtab
  167.     rnc;            do not xlate. Allows extra keys
  168.     lxi    h,vtab+080h
  169.     add    l
  170.     mov    l,a;        discard carry to index table
  171.     mov    a,m;        pick up xlated character
  172.     ret
  173. ;
  174. cout:    lda    iobyte;        check i/o byte
  175.     ani    03H
  176.     jrz    serout;        0, serial
  177.     dcr    a
  178.     jrz    vout;        1, crt
  179.     push    psw
  180.     call    vout;        2,3 video out
  181.     pop    psw;        (iobyte.con)-1
  182.     rar
  183.     jrc    remout;        (2-1)=rem
  184. ;     "     "        3=dbl, do listout
  185. list:    lda    iobyte
  186.     ani    0C0H;        check i/o byte
  187.     jrz    serout;        0, serial
  188.     mvi    l,rom+3FH;    centronics
  189.     cpi    80H
  190.     jrz    gorom;        2, centronics
  191.     rnc;            3, nul device
  192. ;     "     "        1, use video
  193. ; Output to CRT screen only. Escapes etc apply
  194. vout:    mvi    l,rom+45H;    video
  195.     jr    gorom;        1,3 default to video
  196. ;
  197. lsta:    lda    iobyte;        check i/o byte
  198.     ani    0C0H
  199.     jrz    sostat;        0, serial
  200.     cpi    80H
  201.     jrz    ppstat;        2, centronics port
  202. ;     "     "        1,3 video, nul is ready
  203. ; return (a) = 0ffh with nz flag
  204.     ori    0ffh
  205.     ret
  206. ;
  207. sostat:    mvi    l,rom+042h;    serial port output status
  208.     jr    gorom
  209. ;
  210. ppstat:    mvi    l,rom+3ch;    centronics
  211.     call    gorom;        Fix bad original ROM return value
  212.     rnz;
  213. ;     "     "
  214. ; Return (a) = 0 with zero flag
  215.     xra    a
  216.     ret
  217. ;
  218. sistat:    mvi    l,rom+033h;    serial port input status
  219.     jr    gorom
  220. ;
  221. ; get char from remote terminal or local keyboard.
  222. ; Any local char. = brk interrupts (- on num pad with config)
  223. remin:    call    chkhlt;        check for local halt
  224.     rnz;            a local char in interrupted
  225.     call    sistat;        do not get hung in ROM routines,
  226.     jrz    remin;         wait for char. ready
  227. ;     "     "
  228. ; reader input/serial with disk turn off
  229. rin:    call    dkoff;        during wait for peripheral
  230. serin:    mvi    l,rom+36H;    serial input
  231.     jr    gorom
  232. ;
  233. const:    lda    iobyte;        get i/o byte
  234.     rar;            strip to con bits
  235.     jrc    ksta;        1,3 CRT input
  236.     rar
  237.     jrnc    sistat;        0, TTY
  238.     call    sistat;        2, REM
  239.     rnz;            have something
  240. ;     "     "        else check keyboard
  241. ksta:    mvi    l,rom+2AH
  242.     jr    gorom;        keyboard status
  243. ;
  244. ; char. to remote terminal, any local char. interrupts
  245. ; only called from conout set for con:=rem:
  246. remout:    call    chkhlt;        may inhibit further rem opn
  247. ;    "    "        echo on remote terminal
  248. punch:
  249. serout:    mvi    l,rom+39h;    serial punch
  250. ;     "     "
  251. ; transfer control to rom bank at (l).  Switch stack
  252. ; The a,f,b,c,d,e registers are passed to the ROM routines and ROM
  253. ; routine exit registers a,f,d,e,h,l are returned.  Rewritten to avoid
  254. ; disturbing the primed registers and to pass all registers except hl,
  255. ; sp so that interrupt driven systems can co-exist. (bc) preserved.
  256. ; (l) is used to pass iobyte, thus making it visible in the ROM.  The
  257. ; ROM system can then perform the complete device allocation.
  258. ; Note that ROM operation is non-reentrant, because of stack.
  259. gorom:    mvi    h,0;        all rom entries in page zero
  260. ;     "     "
  261. ; Entry here can call any Rom addr, pass abcde, rtn afdehl, save bc
  262. romhl:    di;            No interrupts during stk manipulation
  263.     push    b;        save thru rom call
  264.     sspd    savsp;        save current stack (may be under rom)
  265.     lxi    sp,romret;    Set return for ROM routines
  266.     sspd    stktop;        at top of local stack
  267.     lxi    sp,stktop;    and switch to the local stack
  268. ;    ** USING LOCAL STACK **
  269.     push    h;        set execution point on stack
  270.     push    psw;        useless save at present.
  271.     lxi    h,mtime
  272.     inr    m
  273.     cz    dkoff;        timed out disk motors
  274.     lhld    iobyte;        in (l), default disk id in (h)
  275.     in    bitpt;        turn rom on
  276.     ori    080h;        set bit 7
  277.     out    bitpt;        now 0..3fffh is a new bank
  278.     pop    psw;        pass input (a)
  279.     ei
  280.     ret;    <execute>    rom routine specified on TOS
  281. romret:    push    psw;        save returned (a)
  282.     in    bitpt;        off the rom
  283.     ani    07fh;        clear bit 7
  284.     out    bitpt
  285.     pop    psw;        restore reg A
  286. ;    ** END LOCAL STACK USE **
  287.     lspd    savsp;        restore stack
  288.     pop    b;        restore entry value
  289.     ret;            done with rom routine
  290. ;
  291. dkini:    mvi    l,rom+03H;    re-set disk software sub-system
  292.     jr    gorom
  293. ;
  294. home:    mvi    l,rom+0CH;    home disk drive rom routine
  295.     jr    gorom
  296. ;
  297. seldk:    mvi    l,rom+0FH;    select disk drive
  298.     jr    gorom
  299. ;
  300. setrk:    mvi    l,rom+12H;    seek track
  301.     jr    gorom
  302. ;
  303. setsec:    mvi    l,rom+15H;    set sector number
  304.     jr    gorom
  305. ;
  306. setdma:    mvi    l,rom+18H;    set dma address
  307.     jr    gorom
  308. ;
  309. read:    mvi    l,rom+1BH;    read a logical sector
  310. ;    "    "
  311. ; a disk read/write operation (via (l))
  312. rdwrt:    xra    a
  313.     sta    mtime;        reset disk motor time-out
  314.     jr    gorom
  315. ;
  316. xltsec:    mvi    l,rom+21H;    xlate logical to physical sector
  317.     jr    gorom
  318. ;
  319. write:    mvi    l,rom+1EH;    write a logical sector
  320.     lda    wtsafe;        write safe flag
  321.     ora    a;        true or false
  322.     jrz    rdwrt;        normal operation
  323.     mvi    c,1;        directory write code (forces write op)
  324.     jr    rdwrt
  325. ;
  326. ; shut down disk drive motors
  327. dkoff:    in    bitpt
  328.     ori    040h
  329.     out    bitpt
  330.     ret
  331. ;
  332. ; Warm boot entry point, re-load the CCP and BDOS
  333. ; Uses 8 bytes below 0100h for stack operations.
  334. wboot:    call    dkini
  335.     lxi    sp,100H;    re-set stack
  336.     mvi    c,0;        select drive A:
  337.     call    seldk
  338.     lxi    b,nsects*256+1; (b)=num to do; (c)=sector #
  339.     lxi    h,bios-cpml-128; first mem loc (-128) to load
  340.     push    h
  341.     push    b
  342.     lxi    b,0;        set track
  343. wboot1:    call    setrk
  344.     pop    b;        get sector/trk setting
  345. wboot2:    call    setsec;        select sector
  346.     pop    h
  347.     push    b
  348.     lxi    b,128;        This modification is to avoid
  349.     dad    b;        the anomalous connection to
  350.     mov    b,h;        RAM storage area in the
  351.     mov    c,l;        original, which prevents free
  352.     call    setdma;        ROM modification. cbf 85/1/6
  353.     mov    h,b
  354.     mov    l,c
  355.     pop    b
  356.     push    h
  357.     call    read
  358.     ora    a
  359.     jrnz    wboot;        error on warm boot. CHECK DISKS
  360.     mvi    a,3;        Use warm ccp entry
  361.     dcr    b;        Sequence allows 1 track boot (dd)
  362.     jrz    goccp;        done loading. Stack will be ignored
  363.     inr    c;        bump sector count
  364.     mvi    a,trksec;    on to next track?
  365.     cmp    c
  366.     jrnz    wboot2
  367.      mvi    c,16;        first sector on next track
  368.     push    b;        save counters
  369.     lxi    b,1
  370.     jr    wboot1
  371. ;
  372. ; Set the CP/m vectors, and enter the CCP
  373. ; (a) = 0 for cold load, (a) = 3 for warm boot
  374. ; there may be anomalous garbage on the stack, ccp resets.
  375. goccp:    lxi    h,bios+3;    wboot entry point
  376.     shld    1
  377.     lxi    h,bios-bdossz+6; entry point to bdos
  378.     shld    6
  379.     lxi    h,bios-cpml
  380.     mov    l,a;        Warm/cold entry
  381.     mvi    a,0C3H;        set up CP/M jumps to bdos and wboot
  382.     sta    0
  383.     sta    5
  384.     lda    4;        last logical disk unit used
  385.     mov    c,a;        pass to ccp to select
  386.     pchl;            pass control to ccp
  387. ;
  388. ; Cold boot entry point, set up sys pointers, pass control to CCP
  389. ; **** This space is re-usable as stack after a cold boot ****
  390. boot:    call    dkini;        purpose is to set RAM access
  391.     lhld    iobgn;        junk into h
  392.     mvi    h,0
  393.     shld    iobyte;        init iobyte, system disk number
  394.     mvi    l,0ffh;        wheel on
  395.     shld    @wheel;        init wheel, set path to empty
  396.     lda    bdbgn
  397.     out    bauda;        set initial serial baud
  398.     lxi    h,mesg
  399. boot1:    push    h
  400.     mov    c,m;        1st char. known non-null
  401.     call    vout
  402.     pop    h;        Prevent any stack overflow destroying
  403.     inx    h;        code until after overwriting "mesg"
  404.     mov    a,m;        Somewhere a null will be found
  405.     ora    a;        in such a case. Present ROM ok.
  406.     jrnz    boot1;        more
  407.     jr    goccp;        (a) is zero, cold entry
  408. ;
  409. ; NOT enough room for this - Use later when ROM upgraded
  410. ; for automatic size info on sign on without special MOVCPM cases
  411. ; eliminates all need for the MSIZE parameter, and postpones
  412. ; all customization to link/relocation time.
  413. ;show:    pop    h
  414. ;    push    h;        get calling point - indicates mem size
  415. ;    mov    a,h
  416. ;    adi    5;        form no. of Ks
  417. ;    rar;            assumes no extra pieces
  418. ;    rar;            to set extra carries
  419. ;    mvi    c,'0'-1;    if so extract and list as /n (n=1..3)
  420. ;show1:    inr    c
  421. ;    sub    a,10
  422. ;    jr    p,show1;    convert to 2 decimal digits
  423. ;    adi    10
  424. ;    push    psw
  425. ;    call    vout
  426. ;    pop    psw
  427. ;    mov    c,a
  428. ;    jmp    vout
  429. ;
  430. mesg:    db    clear, msize/10+'0', msize mod 10+'0'
  431.     db    'k DOS+'
  432.     db    vers/10+'0', '.', vers mod 10+'0'
  433.     db    ' KP4(f', bver + '0', ')',0
  434. ; The final nul must appear  before 1f7 from the start of
  435. ; the bios, for the message to appear correctly with the
  436. ; original issue Kaypro 4 (83) ROM.  For NEWROM this is 1f1
  437. ;
  438. used    equ    $-bios;        Max value 01f7 or 1f1, see above
  439.     ds    507-used,0;    ",0" to ensure null fill
  440. stktop:    ds    2,0;        a local stack with a return address
  441. savsp:    ds    2,0;        stack pointer during rom call
  442. mtime:    ds    1,0;        control disk motor time-out
  443. ;
  444.     end
  445. I┼