home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / msvp98b1.lzh / MSZP98.ASM < prev   
Assembly Source File  |  1992-07-04  |  12KB  |  549 lines

  1. ;+ This is MSZP98.ASM
  2. ;
  3. ;  Utility and SetUp Package for NEC PC-9801
  4. ;  Author: Hirofumi Fujii (KEK On-line group)
  5. ;  Last Edited: 17-Apr-1990
  6. ;  04-Jul-1992    VTS is moved to MSYP98.ASM
  7. ;  17-Apr-1991  deleted prn_out
  8. ;  05-Apr-1991  added pcwtst
  9. ;  30-Sep-1990    added text_scrn
  10. ;  27-Sep-1990    VTS comes here !
  11. ;  13-Aug-1990    added sense_sftkey
  12. ;  24-Jul-1990    for MS-Kermit v3.02
  13.  
  14.     include    mssdef.h
  15.     include    msxp98.h
  16.  
  17.     public    s2jis, jis2s, is_kanji1
  18.     public    set_keydef, reset_keydef
  19.     public    set_cursor
  20.     public    sense_sftkey
  21.     public    text_scrn
  22.     public    pc98_bell
  23.     public    pc98_tstrt, pc98_tend
  24.     public    pcwait, pcwtst
  25.     public    setnbios
  26.  
  27. data     segment
  28.  
  29. ;-------------------------------------------------------------------
  30. ; Data for set-up routine
  31. ;-------------------------------------------------------------------
  32.     extrn    flags:byte
  33.     extrn    comand:byte        ; in MSSCMD.ASM
  34.     extrn    denyflg:word
  35.     extrn    cpu_clock:byte, vtgrph_flg:byte, vttest_flg:byte
  36.     extrn    curkey_mode:byte, keypad_mode:byte
  37.     extrn    display_mode:byte
  38.     extrn    keyin_dos:byte
  39.     extrn    kanji_rcode:byte, kanji_scode:byte
  40.     extrn    vt100_flags:byte, vt100_pflag:byte
  41.     extrn    vt100_lflag:byte, vt100_gflag:byte
  42.     extrn    def_color:byte, scn_color:byte
  43.  
  44. pc98v8old    dd    0        ; old vector 8
  45. pc98tick_L    dw    0        ; pc98 tick count (low word)
  46. pc98tick_H    dw    0        ; pc98 tick count (high word)
  47. pc98tcnt    db    0        ; counter for interval timer
  48. pc98tmsk    db    0        ; old interrupt mask
  49.  
  50. pcwcnt        dw    480        ; wait count
  51. pcwtst_vect    dw    0, 0, 0, 0
  52. pcwtst_done    dw    0
  53.  
  54. param_dst    dw    ?
  55. temp        dw    ?
  56.  
  57. ;---------------------------------------------------------------------------
  58. ; Function key definition tables
  59.  
  60. ker_keydef    db    0FEh,'f 01 ',0FFh,062h, 8 dup (0)    ; f 1
  61.         db    0FEh,'f 02 ',0FFh,063h, 8 dup (0)    ; f 2
  62.         db    0FEh,'f 03 ',0FFh,064h, 8 dup (0)    ; f 3
  63.         db    0FEh,'f 04 ',0FFh,065h, 8 dup (0)    ; f 4
  64.         db    0FEh,'f 05 ',0FFh,066h, 8 dup (0)    ; f 5
  65.         db    0FEh,'f 06 ',0FFh,067h, 8 dup (0)    ; f 6
  66.         db    0FEh,'f 07 ',0FFh,068h, 8 dup (0)    ; f 7
  67.         db    0FEh,'f 08 ',0FFh,069h, 8 dup (0)    ; f 8
  68.         db    0FEh,'f 09 ',0FFh,06Ah, 8 dup (0)    ; f 9
  69.         db    0FEh,'f 10 ',0FFh,06Bh, 8 dup (0)    ; f10
  70.         db    0FEh,'F 01 ',0FFh,082h, 8 dup (0)    ; shift f 1
  71.         db    0FEh,'F 02 ',0FFh,083h, 8 dup (0)    ; shift f 2
  72.         db    0FEh,'F 03 ',0FFh,084h, 8 dup (0)    ; shift f 3
  73.         db    0FEh,'F 04 ',0FFh,085h, 8 dup (0)    ; shift f 4
  74.         db    0FEh,'F 05 ',0FFh,086h, 8 dup (0)    ; shift f 5
  75.         db    0FEh,'F 06 ',0FFh,087h, 8 dup (0)    ; shift f 6
  76.         db    0FEh,'F 07 ',0FFh,088h, 8 dup (0)    ; shift f 7
  77.         db    0FEh,'F 08 ',0FFh,089h, 8 dup (0)    ; shift f 8
  78.         db    0FEh,'F 09 ',0FFh,08Ah, 8 dup (0)    ; shift f 9
  79.         db    0FEh,'F 10 ',0FFh,08Bh, 8 dup (0)    ; shift f10
  80.         db    0FFh,036h, 4 dup (0)    ; ROLL UP
  81.         db    0FFh,037h, 4 dup (0)    ; ROLL DOWN
  82.         db    0FFh,038h, 4 dup (0)    ; INS
  83.         db    0FFh,039h, 4 dup (0)    ; DEL
  84.         db    0FFh,03Ah, 4 dup (0)    ; up arrow
  85.         db    0FFh,03Bh, 4 dup (0)    ; left arrow
  86.         db    0FFh,03Ch, 4 dup (0)    ; right arrow
  87.         db    0FFh,03Dh, 4 dup (0)    ; down arrow
  88.         db    0FFh,03Eh, 4 dup (0)    ; HOME CLR
  89.         db    0FFh,03Fh, 4 dup (0)    ; HELP
  90.         db    0FFh,0AEh, 4 dup (0)    ; shift HOME CLR
  91. KEYDEF_SIZE = $ - ker_keydef + 2
  92.  
  93. DOS_keydef    db    KEYDEF_SIZE dup (?)
  94.  
  95. ;
  96. data    ends
  97.  
  98. _TEXT    segment
  99.     assume    cs:_TEXT
  100.     public    _realclock
  101. _realclock    proc    near
  102.     push    ds
  103.     cli
  104.     mov    ax,seg data
  105.     mov    ds,ax
  106.     mov    ax,ds:pc98tick_L
  107.     mov    dx,ds:pc98tick_H
  108.     sti
  109.     pop    ds
  110.     ret
  111. _realclock    endp
  112. _TEXT    ends
  113.  
  114. code    segment
  115.     assume    cs:code, ds:data
  116. ;-------------------
  117. is_kanji1    proc    near
  118. ;
  119. ; Check if al is Kanji 1st byte (stc) or not (clc)
  120. ;
  121.     cmp    al,81h
  122.     jb    is_kanji1_no
  123.     cmp    al,0FCh
  124.     ja    is_kanji1_no
  125.     cmp    al,9fh
  126.     jbe    is_kanji1_yes
  127.     cmp    al,0E0h
  128.     jae    is_kanji1_yes
  129. is_kanji1_no:
  130.     clc
  131.     ret
  132. is_kanji1_yes:
  133.     stc
  134.     ret
  135. is_kanji1    endp
  136.  
  137. ;-------------------
  138. jis2s    proc    near
  139. ;
  140. ; Convert JIS Kanji code in AX to shift-JIS Kanji code
  141. ;    ah    2nd byte
  142. ;    al    1st byte
  143. ;
  144.     test    al,1
  145.     jz    jis2s1
  146.     add    ah,1Fh
  147.     jmp    jis2s2
  148. jis2s1:
  149.     add    ah,7Dh
  150. jis2s2:
  151.     cmp    ah,7Fh
  152.     jb    jis2s3
  153.     add    ah,1
  154. jis2s3:
  155.     sub    al,21h
  156.     shr    al,1
  157.     add    al,81h
  158.     cmp    al,9Fh
  159.     jbe    jis2s4
  160.     add    al,40h
  161. jis2s4:
  162.     ret
  163. jis2s    endp
  164.  
  165. ;-------------------
  166. s2jis    proc    near
  167. ;
  168. ; Convert Shift JIS Kanji code in AX to JIS Kanji code
  169. ;    ah    2nd byte
  170. ;    al    1st byte
  171. ;
  172.     cmp    al,9Fh
  173.     ja    s2jis1
  174.     sub    al,71h
  175.     jmp    s2jis2
  176. s2jis1:
  177.     sub    al,0B1h
  178. s2jis2:
  179.     shl    al,1
  180.     inc    al
  181.     cmp    ah,7Fh
  182.     jbe    s2jis3
  183.     dec    ah
  184. s2jis3:
  185.     cmp    ah,9Eh
  186.     jb    s2jis4
  187.     sub    ah,7Dh
  188.     inc    al
  189.     jmp    s2jis5
  190. s2jis4:
  191.     sub    ah,1Fh
  192. s2jis5:
  193.     ret
  194. s2jis    endp
  195.  
  196. set_keydef    proc    near
  197. ; Save MS-DOS key definition table and set new key definition table.
  198. ; This is done by calling NEC-PC98 extended bios.
  199.  
  200.     push    ax
  201.     push    cx
  202.     push    dx
  203.  
  204.     mov    dx,offset DOS_keydef
  205.     mov    ax,0
  206.     mov    cl,0Ch
  207.     int    0DCh
  208.     mov    dx,offset ker_keydef
  209.     mov    ax,0
  210.     mov    cl,0Dh
  211.     int    0DCh
  212.  
  213.     pop    dx
  214.     pop    cx
  215.     pop    ax
  216.     ret
  217. set_keydef    endp
  218.  
  219. reset_keydef    proc    near
  220. ; Restore MS-DOS key definition table
  221.  
  222.     push    ax
  223.     push    cx
  224.     push    dx
  225.  
  226.     mov    dx,offset DOS_keydef
  227.     mov    ax,0
  228.     mov    cl,0Dh
  229.     int    0DCh
  230.  
  231.     pop    dx
  232.     pop    cx
  233.     pop    ax
  234.     ret
  235. reset_keydef    endp
  236.  
  237. ;---------------------------
  238. text_scrn    proc    near
  239. ;
  240. ; Text screen on/off control
  241. ;
  242. ; Input        AL: 0      off
  243. ;                   others on
  244. ;
  245.     push    ax
  246.     push    bx
  247.     mov    bl,0Ch        ; assume off
  248.     cmp    al,0        ; want off ?
  249.     je    text_scrn_1    ; e=yes
  250.     mov    bl,0Dh        ; on
  251. text_scrn_1:
  252.     in    al,60h        ; Read Text GDC status
  253.     test    al,04h        ; GDC buffer empty ?
  254.     jz    text_scrn_1    ; z=no
  255.     mov    al,bl
  256.     out    62h,al        ; send command
  257.     pop    bx
  258.     pop    ax
  259.     ret
  260. text_scrn    endp
  261. ;
  262. ;---------------------------
  263. set_cursor    proc    near
  264. ;
  265. ; set cursor
  266. ; Input
  267. ;        AH: Lines/Row - 1 (15 or 19)
  268. ;                   25 line mode = 400 / 25 - 1 = 15
  269. ;                   20 line mode = 400 / 20 - 1 = 19
  270. ;        AL: cursor attributes
  271. ;            bit0    0:visible,   1:invisible
  272. ;                   bit1    0:blink,     1:noblink
  273. ;                   bit2    0:block,     1:underline
  274. ;
  275. ; GDC CSFORM command is
  276. ;   +--+--+--+--+--+--+--+--+
  277. ;   | 0| 1| 0| 0| 1| 0| 1| 1|
  278. ;   +--+--+--+--+--+--+--+--+
  279. ;   |CS| 0| 0|     L/R      | CS=cursor 0:off/1:on, L/R=(lines/row - 1)
  280. ;   +--+--+--+--+--+--+--+--+
  281. ;   | BLL |BD|     CST      | BD=blink 0:yes/1:no,  CST=(start line - 1)
  282. ;   +--+--+--+--+--+--+--+--+
  283. ;   |     CFI      |  BLH   | CFI=(final line - 1), BLH+BLD=blink speed
  284. ;   +--+--+--+--+--+--+--+--+
  285. ;
  286.     push    ax
  287.     push    bx
  288.     mov    bx,ax
  289.     cli
  290. set_cursor1:
  291.     in    al,60h        ; Read Text GDS status
  292.     test    al,04h        ; GDC buffer empty ?
  293.     jz    set_cursor1    ; z = no
  294.     mov    al,4Bh        ; CSFORM command
  295.     out    62h,al        ; send command
  296.     mov    al,ah        ; set L/R
  297.     or    al,80h        ; assume cursor is on
  298.     test    bx,1        ; cursor off ?
  299.     jz    set_cursor2    ; z = no
  300.     and    al,07Fh        ; cursor is off, set CS=0
  301. set_cursor2:
  302.     out    60h,al        ; send P1 parameter
  303.     mov    al,0        ; set CST to zero
  304.     test    bx,4        ; underline cursor ?
  305.     jz    set_cursor3    ; z = yes
  306.     mov    al,ah        ; set CST to last line
  307.     dec    al        ; one line (underline) cursor
  308. set_cursor3:
  309.     and    al,1fh        ; mask other bit (BD=0)
  310.     test    bx,2        ; blink ?
  311.     jz    set_cursor4    ; z = yes. blink cursor
  312.     or    al,20h        ; no blink, set BD=1
  313. set_cursor4:
  314.     out    60h,al        ; send P2 parameter
  315.     mov    al,ah        ; CFI is last line
  316.     shl    al,1
  317.     shl    al,1
  318.     shl    al,1
  319.     and    al,0F8h
  320.     or    al,0Bh        ; BL=12
  321.     out    60h,al        ; send P3 parameter
  322.     sti
  323.     pop    bx
  324.     pop    ax
  325.     ret
  326. set_cursor    endp
  327.  
  328. ;-----------------------------------------------------------------------
  329. ; Bell routine
  330. ;
  331. pc98_bell    proc    near
  332.     push    ax
  333.     push    cx
  334. ;
  335.     mov    al,06h        ; bell on
  336.     out    37h,al
  337.     mov    cx,0D000h    ; counter
  338. pc98_bell_loop:
  339.     loop    pc98_bell_loop
  340.     mov    al,07h        ; bell off
  341.     out    37h,al
  342. ;
  343.     pop    cx
  344.     pop    ax
  345.     ret
  346. pc98_bell    endp
  347. ;-----------------------------------------------------------------------
  348. ; timer routines
  349. ;
  350. pc98_tint    proc    near
  351.     push    ds
  352.     push    ax
  353.     mov    ax,seg data    ; set our data segment
  354.     mov    ds,ax        ;   to DS
  355.     pushf
  356.     call    dword ptr ds:pc98v8old    ; call old interrupt routine
  357.     cli
  358.     mov    ax,seg data
  359.     mov    ds,ax
  360.     mov    al,pc98tcnt    ; get tick count (every 10msec)
  361.     inc    al
  362.     and    al,3        ; use only lower 2 bits
  363.     mov    pc98tcnt,al    ; save it
  364.     or    al,al        ; zero?
  365.     jnz    pc98_tint_ex    ; nz = no, don't do anything
  366.     add    pc98tick_L,1    ; longword increment1
  367.     adc    pc98tick_H,0
  368. pc98_tint_ex:
  369.     in    al,2        ; make sure timer interrupt enabled
  370.     and    al,0feh
  371.     out    2,al
  372.     sti            ; enable interrupt
  373.     pop    ax
  374.     pop    ds
  375.     iret
  376. pc98_tint    endp
  377.  
  378. pc98_tstrt    proc    near
  379. ; start pc98 tick timer
  380.     push    ax
  381.     push    bx
  382.     push    dx
  383.     push    ds
  384.     push    es
  385. ;
  386.     xor    ax,ax
  387.     mov    pc98tcnt,al
  388.     mov    pc98tick_L,ax
  389.     mov    pc98tick_H,ax
  390.     cli            ; disable interrupt
  391.     in    al,2        ; read interrupt mask
  392.     mov    pc98tmsk,al    ; save old mask
  393.     and    al,0feh        ; unmask timer interrupt (#0)
  394.     out    2,al        ; set mask value
  395.     mov    ah,35h        ; read vector
  396.     mov    al,8
  397.     int    DOS        ; call DOS function
  398.     mov    WORD PTR pc98v8old,bx    ; save offset
  399.     mov    WORD PTR pc98v8old+2,es    ; save segment
  400.     mov    dx,offset pc98_tint    ; new interrupt routine
  401.     push    cs
  402.     pop    ds        ; DS = CS
  403.     mov    ah,25h        ; set vector
  404.     mov    al,8        ; vector number
  405.     int    DOS        ; call DOS function
  406. ;
  407.     sti            ; enable interrupt
  408.     pop    es
  409.     pop    ds
  410.     pop    dx
  411.     pop    bx
  412.     pop    ax
  413.     clc
  414.     ret
  415. pc98_tstrt    endp
  416.  
  417. pc98_tend    proc    near
  418.     push    ax
  419.     push    bx
  420.     push    dx
  421.     push    ds
  422.     cli
  423.     mov    al,pc98tmsk    ; restore old interrupt mask
  424.     out    2,al
  425.     mov    ah,25h        ; set vector
  426.     mov    al,8        ; vector number
  427.     mov    dx,WORD PTR pc98v8old
  428.     mov    bx,WORD PTR pc98v8old+2
  429.     push    bx
  430.     pop    ds
  431.     int    DOS        ; call DOS function
  432.     sti
  433.     pop    ds
  434.     pop    dx
  435.     pop    bx
  436.     pop    ax
  437.     clc
  438.     ret
  439. pc98_tend    endp
  440.  
  441. ;-----------------------------------------------------------------------
  442. ; set the pcwcnt used in pcwait.
  443. ;
  444. pcwtst_int    proc    near
  445.     mov    pcwtst_done,1
  446.     iret
  447. pcwtst_int    endp
  448.  
  449. pcwtst    proc    near
  450.     push    ax
  451.     push    bx
  452.     push    cx
  453.     push    si
  454.     push    di
  455.     push    es
  456. ;
  457.     xor    ax,ax
  458.     mov    es,ax        ; ES = 0
  459.     cli            ; disable interrupt
  460.     mov    si,28        ; save vector number 7 & 8
  461.     mov    di,offset pcwtst_vect
  462.     mov    ax,es:[si]
  463.     mov    [di],ax
  464.     mov    ax,es:[si+2]
  465.     mov    [di+2],ax
  466.     mov    ax,es:[si+4]
  467.     mov    [di+4],ax
  468.     mov    ax,es:[si+6]
  469.     mov    [di+6],ax
  470. ;
  471.     mov    pcwcnt,0
  472.     mov    pcwtst_done,0
  473.     sti            ; enable interrupt
  474.     mov    cx,10        ; 100msec mesurements
  475.     mov    ax,cs
  476.     mov    es,ax
  477.     mov    bx,offset pcwtst_int
  478.     mov    ah,02h        ; interval timer function number
  479.     int    1Ch        ; BIOS call
  480. ;
  481. pcwtst0:
  482.     cmp    pcwtst_done,0
  483.     jne    pcwtst2
  484.     mov    cx,100
  485. pcwtst1:
  486.     sub    cx,1
  487.     jnz    pcwtst1
  488.     inc    pcwcnt
  489.     jmp    pcwtst0
  490. ;
  491. pcwtst2:
  492.     inc    pcwcnt        ; add 1
  493.     cli
  494.     xor    ax,ax
  495.     mov    es,ax        ; ES = 0
  496.     mov    si,28        ; restore vector 7 & 8
  497.     mov    di,offset pcwtst_vect
  498.     mov    ax,[di]
  499.     mov    es:[si],ax
  500.     mov    ax,[di+2]
  501.     mov    es:[si+2],ax
  502.     mov    ax,[di+4]
  503.     mov    es:[si+4],ax
  504.     mov    ax,[di+6]
  505.     mov    es:[si+6],ax
  506.     sti
  507.     pop    es
  508.     pop    di
  509.     pop    si
  510.     pop    cx
  511.     pop    bx
  512.     pop    ax
  513.     ret
  514. pcwtst    endp
  515. ;-----------------------------------------------------------------------
  516. ;; Wait for the # of milliseconds in ax, for non-IBM compatibles.
  517. ; inner loop counter (pcwcnt, adjusted by proc pcwtst).
  518. pcwait  proc    near
  519.         push    cx
  520. pcwai0: mov     cx,pcwcnt       ; inner loop counter for 1 ms
  521. pcwai1: sub     cx,1            ; inner loop takes 20 clock cycles
  522.         jnz     pcwai1
  523.         dec     ax              ; outer loop counter
  524.         jnz     pcwai0          ; wait another millisecond
  525.         pop     cx
  526.         ret
  527. pcwait  endp
  528.  
  529. ;-----------------------------------------------------------------------
  530. ; Sense shfit-key status
  531. ;
  532. ; output
  533. ;             +----+----+----+----+----+----+----+----+
  534. ;   AL        | -- | -- | -- |CTRL|GRPH|KANA|CAPS|SHFT|
  535. ;             +----+----+----+----+----+----+----+----+
  536. sense_sftkey    proc    near
  537.     mov    ah,02h
  538.     int    18h
  539.     ret
  540. sense_sftkey    endp
  541.  
  542. setnbios    proc    near
  543.     stc            ; can't do this
  544.     ret
  545. setnbios    endp
  546.  
  547. code    ends
  548.     end
  549.