home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / mbug / mbug097.arc / BIOS.MAC < prev    next >
Text File  |  1979-12-31  |  7KB  |  413 lines

  1. ;
  2. ;
  3. ;    Header to assemble BIOS keyboard driver file : KEYBOARD.SYS
  4. ;    (or KBDSTAND.SYS, KBDINT.SYS, KBDEXT.SYS)
  5. ;
  6. ;    Also contains some status line stuff
  7. ;
  8. ;    Written by Peter Broughton.
  9. ;
  10. ;    1st Dec., 1987
  11. ;
  12.  
  13. ; keyboard driver, select the appropriate file
  14. keyboard_driver    macro
  15.  
  16. ;    include    BKBD3870.MAC
  17.     include BKBD6545.MAC
  18.  
  19.     endm
  20.  
  21. true        equ    -1
  22. false        equ    not true
  23.  
  24.  
  25. ; start of keyboard driver in system page
  26. keyboard_start    equ    5800h
  27.  
  28. bios_start    equ    0E700h
  29.  
  30. piob_ctrl    equ    3
  31. piob_data    equ    2
  32.  
  33. crtc        equ    0Ch
  34.  
  35. col_port    equ    8
  36.  
  37. window_char    equ    0A0h
  38.  
  39. user_char    equ    0A1h
  40.  
  41. ; locations within BIOS
  42.  
  43. col_mode    equ    bios_start+129h
  44. al_rev        equ    bios_start+27Bh+17
  45. click_length    equ    bios_start+223h
  46. click_tone    equ    bios_start+224h
  47. fn_active    equ    bios_start+220h
  48.  
  49. speed_port    equ    9        ; Port to change CPU speed
  50. speed_bit    equ    2        ; Bit to do this
  51. fast_cpu    equ    0E98Dh        ; Flag for fast speed
  52.  
  53.  
  54.     aseg
  55.     org    100h
  56.  
  57. ; usual .SYS header
  58.  
  59.     dw    8000h        ; lowest BIOS start ???
  60.  
  61.     dw    keyboard_start    ; where this file loads to
  62.  
  63.     dw    end_marker-keyboard_start    ; length of this file
  64.  
  65.     ds    180h-$,0    ; must fill one record
  66.  
  67. ; leave space in system page for flags and BDOS
  68.     .phase    keyboard_start
  69.  
  70. ; must start with jumps to scn_in and is_closed routines, etc.
  71.  
  72.     jp    scn_in
  73.     jp    is_closed
  74.     jp    print_s_line
  75.     jp    set_up_s_line
  76.  
  77.     keyboard_driver
  78.  
  79.  
  80. ; Key click routine for either keyboard.
  81. ;
  82. do_click:
  83.     push    af
  84.     ld    a,(click_length)
  85.     or    a
  86.     jr    z,no_click
  87.     ld    b,a
  88.     ld    a,(fast_cpu)    ; 'Halve' bit time if 3.375 MHz
  89.     or    a
  90.     ld    a,(click_tone)
  91.     jr    nz,not_fast
  92.     srl    a        ; Divide by 2
  93. not_fast:
  94.     ld    d,a
  95.     in    a,(2)
  96.     ld    e,a
  97. click_loop:
  98.     ld    c,d
  99.     xor    40h
  100.     out    (2),a
  101. tone_loop:
  102.     ld    a,a
  103.     ld    a,a
  104.     ld    a,a
  105.     ld    a,a
  106.     dec    c
  107.     jr    nz,tone_loop
  108.     djnz    click_loop
  109.     ld    a,e
  110.     out    (2),a
  111. no_click:
  112.     pop    af
  113.     ret
  114.  
  115. ; Status line routines
  116.  
  117. vdu        equ    8000h
  118.  
  119. s_line        equ    0E700h+58    ;active flag (=25 for on)
  120.  
  121. sl_table    equ    0E700h+2CBh    ;pointer to info for line
  122.  
  123. no_clock    equ    0E700h+28Eh    ;no clock fitted (unitialised)
  124.  
  125. sl_msgs        equ    0E700h+2CDh    ;pointer to messages
  126.  
  127. get_rtc_addr    equ    0E700h+27Dh    ;address of rtc routine
  128.  
  129. ; status line positions
  130. status_start    equ    vdu+(24*80)+2
  131. pjb_sl        equ    status_start+2
  132. fast_sl        equ    status_start+16    ; 'fast' message
  133. swap_a_m_sl    equ    status_start+28    ; pos of 'A<>M' message
  134. lock_sl        equ    status_start+34    ; pos of lock message
  135. fn_sl        equ    status_start+43    ; 'fn key' message
  136. fn_on_sl    equ    status_start+40    ; 'fn active'
  137. clock_sl    equ    status_start+52    ; pos of time on status line
  138.  
  139.  
  140. num_sl_msgs    equ    5    ; number of messages on status line
  141.  
  142. sl_pjb_mes:
  143.     db    -'(',-'c',-')',-' ',-'P',-'J',-'B'
  144. len_sl_pjb_mes    equ    $-sl_pjb_mes
  145.  
  146.  
  147.  
  148. ; update status line
  149. ; must push all but AF and HL
  150. print_s_line:
  151.     push    bc
  152.     push    de
  153.     push    ix
  154.     push    iy
  155.     ld    b,num_sl_msgs
  156.     ld    ix,(sl_table)
  157.     ld    iy,old_sl_vals
  158. p_sl_loop:
  159.     push    bc
  160.     ld    b,0
  161.     ld    h,(ix+1)
  162.     ld    l,(ix+0)
  163.     ld    a,(hl)        ; new val
  164.     cp    (iy)        ; old val
  165.     jr    z,p_sl1        ; no change so goto next one
  166.     ld    (iy),a        ; else update old val
  167.     ld    hl,null_mes
  168.     or    a
  169.     jr    z,p_sl3
  170.     ld    hl,(sl_msgs)
  171.     ld    c,(ix+2)    ; offset of message
  172.     add    hl,bc        ; points to message
  173. p_sl3:
  174.     ld    a,(status_start)
  175.     cp    '['
  176.     jp    nz,p_sl2    ; no status line so NO printing
  177.     ex    de,hl
  178.     ld    hl,status_start
  179.     ld    c,(ix+3)    ; offset on status line
  180.     add    hl,bc
  181.     ex    de,hl
  182.     ld    c,(ix+4)    ; length of msg
  183.     ldir
  184. p_sl1:
  185.     ld    c,5
  186.     add    ix,bc
  187.     inc    iy
  188.     pop    bc
  189.     djnz    p_sl_loop
  190.  
  191. ; clock now, but is it there
  192.     ld    a,(no_clock)
  193.     or    a
  194.     jr    nz,p_sl6    ; wasn't there - make sure no display occurs
  195.     ld    hl,time_spot
  196.     ld    e,0        ; read from reg 0
  197.     ld    b,10        ; 10 regs
  198. call_rtc:
  199.     call    0
  200. ; update 'old' time and check for change
  201.     ld    hl,time_spot_o
  202.     ld    de,time_spot
  203.     ld    bc,10 shl 8    ; b - counter, c - change flag
  204. p_sl4:
  205.     ld    a,(de)
  206.     cp    (hl)
  207.     jr    z,p_sl5
  208.     ld    c,true
  209. p_sl5:
  210.     ld    (hl),a
  211.     inc    hl
  212.     inc    de
  213.     djnz    p_sl4
  214.     bit    7,c
  215.     jr    z,p_sl6
  216.     ld    a,(status_start)
  217.     cp    '['
  218.     jr    nz,p_sl6
  219.  
  220. ; now display it
  221.     ld    ix,time_spot
  222.     ld    hl,clock_sl
  223.     ld    a,(ix+4)    ; hours
  224.     ld    b,'A'        ; AM
  225.     cp    12h
  226.     jr    c,dt_1
  227.     sub    12h        ; Actually PM
  228.     daa
  229.     ld    b,'P'
  230. dt_1:
  231.     or    a
  232.     jr    nz,dt_2
  233.     ld    a,12h        ; 12 o'clock
  234. dt_2:
  235.     ld    c,' '        ; blank leading zero
  236.     cp    10h
  237.     jr    c,dt_3
  238.     ld    c,'1'
  239.     sub    10h
  240. dt_3:
  241.     ld    (hl),c
  242.     inc    hl
  243.     add    a,'0'
  244.     ld    (hl),a
  245.     inc    hl
  246.     inc    hl
  247.     ld    a,(ix+5)    ; min
  248.     call    print_bcd
  249.     inc    hl
  250.     ld    a,(ix+6)    ; sec
  251.     call    print_bcd
  252.     inc    hl
  253.     ld    (hl),b        ; A/P
  254.     inc    hl
  255.     inc    hl
  256.     inc    hl
  257.     inc    hl
  258.     ld    a,(ix+2)    ; date
  259.     call    print_bcd
  260.     inc    hl
  261.     ld    a,(ix+1)    ; month
  262.     call    print_bcd
  263.     inc    hl
  264.     ld    a,(ix+0)    ; year
  265.     call    print_bcd
  266. p_sl6:
  267.     pop    iy
  268.     pop    ix
  269.     pop    de
  270.     pop    bc
  271.     ret
  272.  
  273. p_sl2:
  274.     pop    bc
  275.     jr    p_sl6
  276.  
  277. ; print bcd num in a to (hl)
  278. print_bcd:
  279.     ld    e,a
  280.     rra
  281.     rra
  282.     rra
  283.     rra
  284.     and    0Fh
  285.     add    a,'0'
  286.     ld    (hl),a
  287.     inc    hl
  288.     ld    a,e
  289.     and    0Fh
  290.     add    a,'0'
  291.     ld    (hl),a
  292.     inc    hl
  293.     ret
  294.  
  295.  
  296. ; clear and set up status line
  297. set_up_s_line:
  298.     ld    hl,(get_rtc_addr)
  299.     ld    (call_rtc+1),hl
  300. ; Must clear status line if it is being used
  301. ; Actually assume it is being used to allow compatability with window's
  302. ;  status line on/off function.
  303. ;    ld    a,(s_line)
  304. ;    cp    24
  305. ;    ret    z
  306.     ld    hl,status_start-2
  307.     ld    b,80
  308. su_sl_1:
  309.     ld    (hl),' '
  310.     inc    hl
  311.     djnz    su_sl_1
  312.  
  313.     ld    a,'['
  314.     ld    (status_start),a
  315.     ld    a,']'
  316.     ld    (status_start+75),a
  317.     ld    hl,sl_pjb_mes
  318.     ld    de,status_start+2
  319.     ld    b,len_sl_pjb_mes
  320. sl_l_n:
  321.     ld    a,(hl)
  322.     neg
  323.     ld    (de),a
  324.     inc    hl
  325.     inc    de
  326.     djnz    sl_l_n
  327.  
  328. ;    if    not telecomputer
  329. ; is the real time clock fitted
  330.     ld    c,7
  331.     ld    a,14
  332.     out    (4),a
  333.     in    b,(c)
  334.     ld    a,14
  335.     out    (4),a
  336.     ld    a,85
  337.     out    (6),a
  338.     ld    a,14
  339.     out    (4),a
  340.     in    d,(c)
  341.     ld    a,14
  342.     out    (4),a
  343.     ld    a,b
  344.     out    (6),a
  345.     ld    a,d
  346.     sub    85
  347.  
  348. ;    else
  349. ; telecomputer must have clock
  350. ;    xor    a
  351. ;    endif
  352.  
  353.     ld    (no_clock),a    ; nz if no rtc present
  354.     push    af
  355. ; fill 'old' status values with impossible code so update occurs immediately
  356.     ld    hl,time_spot_o    ; make sure full status line is printed
  357.     ld    b,num_old_vals
  358. s_sl1:
  359.     ld    (hl),55h
  360.     inc    hl
  361.     djnz    s_sl1
  362.     call    print_s_line
  363.     pop    af
  364. ; if no then don't print ':' & '/'
  365.     ret    nz
  366.  
  367.     ld    a,':'
  368.     ld    (clock_sl+2),a
  369.     ld    (clock_sl+5),a
  370.     ld    a,'M'
  371.     ld    (clock_sl+10),a
  372.     ld    a,'/'
  373.     ld    (clock_sl+15),a
  374.     ld    (clock_sl+18),a
  375.     ret
  376.  
  377.  
  378. ; 'previous' values for status line flags
  379. ; do not alter their relative positions
  380.  
  381. time_spot_o:    ds    10,55h
  382. in_fnstr_o:    db    55h
  383. al_rev_o:    db    55h
  384. fn_active_o:    db    55h
  385. swap_a_m_o:    db    55h
  386. fast_o:        db    55h
  387.  
  388. num_old_vals    equ    $-time_spot_o    ; number of bytes
  389.  
  390. old_sl_vals    equ    in_fnstr_o    ; start of above table
  391.  
  392.  
  393. null_mes:
  394.     db    '         '
  395.  
  396. time_spot:
  397.     ds    10        ;10 bytes for time
  398.  
  399. last_ascii:    db    0FFh
  400. rept_flip:    ds    1
  401.  
  402.  
  403. end_marker    equ    $
  404.  
  405.     if    $ ge 5E00h
  406.      error    probably ran past window start
  407. diff     equ    $-keyboard_start+zero
  408.     endif
  409.  
  410.     .dephase
  411.  
  412.     end
  413.