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 / KAYPRO / KPNUROM.LBR / SYSCNTRL.AQM / SYSCNTRL.ASM
Assembly Source File  |  2000-06-30  |  6KB  |  349 lines

  1. title    System Control for Kaypro 4-83 with CBF ROM
  2. ;
  3. cr    equ    0dh
  4. lf    equ    0ah
  5. buffsz    equ    20
  6. ;
  7. ; DOS calls
  8. coute    equ    2
  9. tstr    equ    9
  10. instrg    equ    10
  11. dreset    equ    13
  12. ;
  13. calldos    macro    funct, param
  14.     mvi    a,funct
  15.     if    not nul param
  16.      lxi    d,param
  17.     endif
  18.     call    dos
  19.     endm
  20. ;
  21.     org    0100h
  22.     lxi    h,0
  23.     dad    sp
  24.     shld    savsp
  25.     lxi    sp,savsp
  26.     mvi    a,buffsz
  27.     sta    buff
  28.     lhld    1;        get bios pointer
  29.     lxi    d,21;    MAGIC OFFSET
  30.     dad    d;        make "home" ptr
  31.     shld    dohome + 1
  32.     lhld    1
  33.     lxi    d,24;    MAGIC OFFSET
  34.     dad    d
  35.     shld    dodsksel + 1;    make disk select bios ptr
  36.     calldos    tstr, signon
  37.     calldos    dreset;        reset disk system to avoid later
  38.     mvi    c,0;          foulups, and select drive A
  39. dodsksel:
  40.     call    $-$;        patched on entry
  41. dohome:    call    $-$;        patched on entry
  42.     shld    sysptr
  43.     mov    a,h
  44.     ora    a
  45.     jz    abort
  46.     mov    a,m
  47.     ora    a
  48.     jz    wtsafe
  49.     cma
  50.     ora    a;        only ff or 0 here
  51.     jz    wtsafe
  52. abort:    calldos    tstr,badsys
  53.     jmp    exit
  54. ;
  55. ; check write safe flag
  56. wtsafe:    calldos    tstr,wtsafm
  57.     lhld    1
  58.     lxi    d,31h;    MAGIC OFFSET
  59.     dad    d
  60.     call    flipper
  61.     jnz    wrtchk
  62.     mov    a,m
  63.     cma
  64.     ani    1
  65.     mov    m,a
  66. ;    "    "
  67. ; check write check flag
  68. wrtchk:    calldos    tstr,wchkm
  69.     lhld    sysptr
  70.     call    flipper
  71.     jnz    retry2
  72.     mov    a,m
  73.     cma
  74.     mov    m,a
  75. ;    "    "
  76. ; show retries and change
  77. retry2:    calldos    tstr, r2msg
  78.     lhld    sysptr
  79.     inx    h
  80.     call    tnum
  81.     cz    alter
  82. ;    "    "
  83. ; show retry 2 and change
  84. retry1:    calldos    tstr, r1msg
  85.     lhld    sysptr
  86.     inx    h
  87.     inx    h
  88.     call    tnum
  89.     cz    alter
  90. ;    "    "
  91. ; display softerror counts for drive a, allow reset
  92. errcta:    mvi    a,'A'
  93.     call    couta
  94.     calldos    tstr, errmsg
  95.     lhld    sysptr
  96.     lxi    d,3
  97.     dad    d
  98.     call    terrct
  99.     jnz    errctb
  100.     xra    a
  101.     mov    m,a
  102.     inx    h
  103.     mov    m,a
  104.     inx    h
  105.     mov    m,a
  106. ;    "    "
  107. ; display softerror counts for drive b, allow reset
  108. errctb:    cnz    crlf
  109.     mvi    a,'B'
  110.     call    couta
  111.     calldos    tstr, errmsg
  112.     lhld    sysptr
  113.     lxi    d,6
  114.     dad    d
  115.     call    terrct
  116.     jnz    exit
  117.     xra    a
  118.     mov    m,a
  119.     inx    h
  120.     mov    m,a
  121.     inx    h
  122.     mov    m,a
  123. ;    "    "
  124. ; exit system
  125. exit:    lhld    savsp
  126.     sphl
  127.     ret
  128. ;
  129. ; alter the one byte number at hl^
  130. alter:    push    h
  131.     calldos    tstr,towhat
  132.     calldos    instrg,buff
  133.     call    crlf
  134.     xchg
  135.     inx    h
  136.     mov    a,m
  137.     ora    a
  138.     jz    alter2;        empty line, dont change
  139.     mov    b,a
  140.     mvi    c,0;        accumulator
  141. alter1:    inx    h
  142.     mvi    a,' '
  143.     cmp    m
  144.     jnz    alter3;        non blank
  145.     dcr    b
  146.     jnz    alter1;        skip blanks
  147. alter2:    pop    h
  148.     ret;            empty line or something, no change
  149. alter3:    mov    a,m
  150.     call    qnum
  151.     jc    alter2;        invalid, no change
  152.     mov    c,a
  153. alter4:    inx    h
  154.     dcr    b
  155.     jz    alter5;        have result
  156.     mov    a,m
  157.     call    qnum
  158.     jc    alter5;        terminator, have result
  159.     push    b
  160.     mov    b,a
  161.     mov    a,c
  162.     add    a;        2*
  163.     add    a;        4*
  164.     add    c;        5*
  165.     add    a;        10*
  166.     add    b;        ls digit
  167.     pop    b
  168.     mov    c,a
  169.     jmp    alter4;        someone may want three digits
  170. alter5:    pop    h
  171.     mov    m,a
  172.     ret
  173. ;
  174. ; check a numeric character.  carry if not, else convert to bin.
  175. qnum:    cpi    '0'
  176.     rc
  177.     cpi    '9'+1
  178.     cmc
  179.     rc
  180.     sui    '0'
  181.     ret;            with carry if invalid
  182. ;
  183. ; Display one byte value at (hl). Ask for change
  184. tnum:    push    h
  185.     mov    l,m
  186.     mvi    h,0
  187.     call    tdhlzs
  188.     calldos    tstr,chgmsg
  189.     pop    h
  190.     jmp    reply
  191. ;
  192. ; Display errcounts
  193. terrct:    push    h
  194.     inx    h
  195.     mov    a,m
  196.     inx    h
  197.     mov    h,m
  198.     mov    l,a
  199.     call    tdhlzs
  200.     mov    a,h
  201.     ora    l
  202.     pop    h
  203.     jnz    terr2
  204.     ori    'N';        reset z flag, no change
  205.     ret
  206. terr2:    push    h
  207.     calldos    tstr,ercode
  208.     pop    h
  209.     mov    a,m
  210.     push    h
  211.     lxi    d,erridsz
  212.     lxi    h,errids-erridsz
  213. terr3:    dad    d
  214.     rlc
  215.     jnc    terr3
  216.     xchg
  217.     calldos    tstr
  218.     calldos    tstr,change
  219.     pop    h
  220.     jmp    reply
  221. ;
  222. ; announce boolean state, allow inversion (0 or 1 only)
  223. ; a,f
  224. flipper:
  225.     mov    a,m
  226.     ora    a
  227.     push    d
  228.     lxi    d,onmsg
  229.     jnz    flip1
  230.     lxi    d,offmsg
  231. flip1:    push    h
  232.     calldos    tstr
  233.     pop    h
  234.     pop    d
  235. ;    "    "
  236. ; Get y/n reply.  Set z flag for y, else reset flag
  237. ; a,f
  238. reply:    push    h
  239.     push    d
  240.     push    b
  241.     calldos    tstr,ynmsg
  242.     calldos    instrg,buff
  243.     mvi    a,lf
  244.     call    couta
  245.     xchg
  246.     inx    h
  247.     mov    a,m
  248.     ora    a
  249.     jz    reply2;        empty line
  250.     mov    b,a
  251. reply1:    inx    h
  252.     mvi    a,' '
  253.     cmp    m
  254.     jnz    reply2;        non blank
  255.     dcr    b
  256.     jnz    reply1;        skip blanks
  257. reply2:    mov    a,m;        reply result (may be sz 0 or blank)
  258.     cpi    'y'
  259.     jz    reply3;        yes result
  260.     cpi    'Y'
  261. reply3:    pop    b
  262.     pop    d
  263.     pop    h
  264.     ret
  265. ;
  266. ; divide hl by ten, remainder to a with flags set
  267. ; a,f,h,l
  268. dten:    push    b
  269.     lxi    b,0f00ah;    b=-16, c=10
  270.     xra    a
  271. dten1:    dad    h
  272.     ral
  273.     cmp    c
  274.     jc    dten2
  275.     sub    c
  276.     inx    h
  277. dten2:    inr    b
  278.     jm    dten1
  279.     ora    a
  280.     pop    b
  281.     ret
  282. ;
  283. ; output hl as decimal number, leading zero suppress
  284. ; a,f
  285. tdhlzs:    push    h
  286.     call    dten
  287.     push    psw
  288.     mov    a,l
  289.     ora    h
  290.     cnz    tdhlzs;        recursive
  291.     pop    psw
  292.     pop    h
  293.     adi    '0'
  294. ;    "    "
  295. ; output a to console
  296. ; a,f
  297. couta:    push    d
  298.     push    h
  299.     mov    e,a
  300.     calldos    coute
  301.     pop    h
  302.     pop    d
  303.     ret
  304. ;
  305. ; crlf to console
  306. crlf:    mvi    a,cr
  307.     call    couta
  308.     mvi    a,lf
  309.     jmp    couta
  310. ;
  311. dos:    push    b
  312.     push    d
  313.     mov    c,a
  314.     call    5
  315.     pop    d
  316.     pop    b
  317.     ret
  318. ;
  319. signon:    db    'Kaypro 4-83 (cbf ROM) system tuner',cr,lf,'$'
  320. badsys:    db    'Incorrect system ROM for this operation$'
  321. wtsafm:    db    'Write safe (immediate, no blocking) is $'
  322. offmsg:    db    'OFF. Turn it on$'
  323. onmsg:    db    'ON. Turn it off$'
  324. ynmsg:    db    ' (y/n)?$'
  325. wchkm:    db    'Write checking (read after write) is $'
  326. r1msg:    db    'Disk read/write retries set at $'
  327. r2msg:    db    'Disk read/write reseeks set at $'
  328. chgmsg:    db    '. Change it$'
  329. towhat:    db    'To what ? $'
  330. errmsg:    db    ': soft error count is $'
  331. ercode:    db    ', last error was: $'
  332. change:    db    '. Reset it$'
  333. errids:    db    'NotReady$$$$';    bit 7 - not ready
  334.     db    'WrtProtect$$';        6 - write protect
  335.     db    'WrtFaulT$$$$';        5 - write fault
  336.     db    'RcdNotFound$';        4 - record not found
  337.     db    'CRC Error$$$';        3 - CRC error
  338.     db    'LostData$$$$';        2 - data overrun
  339.     db    'DataRequest$';        1 - data not supplied
  340.     db    'Busy$$$$$$$$';    bit 0 - controller busy
  341. erridsz    equ    ($-errids)/8;    size of each message (all same)
  342. ;
  343. buff    ds    buffsz+1;    input buffer
  344. sysptr:    ds    2
  345.     ds    64;        run time stack
  346. savsp:    ds    2;        save entry stack
  347. ;
  348.     end
  349.