home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / comm / ykh121.zip / YKHSRC.ZIP / JISLIB.ASM < prev    next >
Assembly Source File  |  1992-09-15  |  15KB  |  786 lines

  1. ;       3C4h index  2  (r/W): Sequencer: Map Mask Register
  2. ;         bit 0  Enable writes to plane 0 if set
  3. ;             1  Enable writes to plane 1 if set
  4. ;             2  Enable writes to plane 2 if set
  5. ;             3  Enable writes to plane 3 if set
  6. ;
  7. ;       3CEh index  4  (r/W): Graphics: Read Map Select Register
  8. ;       bit 0-1  Number of the plane read Mode 0 will read from.
  9.  
  10. INT_10H MACRO
  11.   PUSH BP
  12.   INT 10H
  13.   POP BP
  14. ENDM
  15.  
  16. INT_10HP MACRO
  17.   PUSH AX
  18.   PUSH BX
  19.   PUSH CX
  20.   PUSH DX
  21.   PUSH BP
  22.   PUSH DS
  23.   PUSH ES
  24.   PUSH SI
  25.   PUSH DI
  26.   INT 10H
  27.   POP DI
  28.   POP SI
  29.   POP ES
  30.   POP DS
  31.   POP BP
  32.   POP DX
  33.   POP CX
  34.   POP BX
  35.   POP AX
  36. ENDM
  37.  
  38.  
  39. VIDEOSEG EQU 0A000H
  40.  
  41. MAP_MASK  EQU 3c4h
  42. READ_MAP  EQU 3ceh
  43. MISC_OUT  EQU 3c2h
  44. CRTC_IDX  EQU 3d4h
  45.  
  46. ADAPTER_CGA EQU 0
  47. ADAPTER_EGA EQU 1
  48. ADAPTER_VGA EQU 2
  49.  
  50. JISLIB_ERROR_OPEN EQU 1 ;file not found
  51. JISLIB_ERROR_READ EQU 2 ;unexpected end of file
  52. JISLIB_ERROR_CARD EQU 3 ;inadequate video card
  53. JISLIB_ERROR_MODE EQU 4 ;unable to set requested mode
  54.  
  55. JISLIB_TEXT    segment byte public 'CODE'
  56. JISLIB_TEXT    ends
  57. DGROUP    group    _DATA,_BSS
  58.     assume    cs:JISLIB_TEXT,ds:DGROUP
  59. _DATA    segment word public 'DATA'
  60. _DATA    ends
  61. _BSS    segment word public 'BSS'
  62. _BSS    ends
  63. JISLIB_TEXT    segment byte public 'CODE'
  64.    ;
  65.  
  66. LAST_62 db (32*62) dup(0)
  67.  
  68. asciiseg  dw ?
  69. asciioffs dw ?
  70.  
  71. oldmode db ?
  72. adapter db ?
  73.  
  74.  
  75. ;
  76. ;int far jis_deinit();
  77. ;
  78. _jis_deinit proc far
  79.             xor ah,ah
  80.             mov al,cs:oldmode
  81.             INT_10HP
  82.             ret
  83. _jis_deinit endp
  84.  
  85.  
  86.  
  87. ;
  88. ;int far jis_init(unsigned scanlines,unsigned fg,unsigned bg,char far* filename);
  89. ;
  90. _jis_init proc far
  91.           push bp
  92.           mov bp,sp
  93.  
  94.           push ds
  95.           push si
  96.           push es
  97.           push di
  98. ;
  99. ; beginning of video detect code
  100. ;
  101.           mov ax,1200h  ;detect presence of EGA/VGA
  102.           mov bl,10h    ;
  103.           INT_10H       ;
  104.           cmp bl,10h    ;
  105.           jne @@egg     ;
  106.  
  107.           mov ax,JISLIB_ERROR_CARD
  108.           jmp @@end
  109.  
  110. @@egg:    mov cs:adapter,ADAPTER_EGA ;detect presence of VGA
  111.           mov ax,1a00h               ;
  112.           INT_10H                    ;
  113.           cmp bl,7                   ;
  114.           jb @@toast                 ;
  115.  
  116.           mov cs:adapter,ADAPTER_VGA
  117. @@toast:
  118. ;
  119. ; end of video detect code
  120. ;
  121.  
  122.  
  123. ;
  124. ; beginning of video init code
  125. ;
  126.           mov ax,0f00h
  127.           INT_10H
  128.           mov cs:oldmode,al
  129.  
  130.           cmp word ptr [bp+6],200
  131.           ja @@ega
  132.  
  133.           mov ax,0eh
  134.           jmp @@vid
  135.  
  136. @@ega:    cmp word ptr [bp+6],350
  137.           ja @@vga
  138.  
  139.           mov ax,10h
  140.           jmp @@vid
  141.  
  142. @@vga:    cmp cs:adapter,ADAPTER_VGA
  143.           jnb @@okvga
  144.  
  145.           mov ax,JISLIB_ERROR_MODE
  146.           jmp @@end
  147.  
  148. @@okvga:  mov ax,12h
  149.  
  150. @@vid:    INT_10HP
  151.           cmp cs:adapter,ADAPTER_VGA
  152.           jb @@no400
  153.           cmp word ptr [bp+6],400
  154.           ja @@no400
  155.           cmp word ptr [bp+6],350
  156.           jna @@no400
  157.  
  158.           mov dx,3cch     ;forces VGA into 640x400 mode
  159.           in al,dx        ;unstable!
  160.           and al,73h      ;
  161.           mov dx,3c2h     ;
  162.           out dx,al       ;
  163.                           ;
  164.           mov dx,3d4h     ;
  165.           mov ax,02716h   ;
  166.           out dx,ax       ;
  167.                           ;
  168.           mov dx,3d4h     ;
  169.           mov ax,0b815h   ;
  170.           out dx,ax
  171.  
  172. @@no400:
  173.           mov ax,1000h ;
  174.           xor bl,bl
  175.           mov cx,8
  176.           mov dl,[bp+8 ]
  177.           mov dh,[bp+10]
  178.  
  179. @@pal:    mov bh,dh    ;set palette entry to background color
  180.           INT_10HP     ;
  181.           inc bl       ;
  182.           mov bh,dl    ;set palette entry to foreground col
  183.           INT_10HP     ;
  184.           inc bl       ;
  185.           loop @@pal   ;repeat 8 times, for a total of 16 entries
  186.  
  187.  
  188.           mov bh,6                   ;get 16 point font if VGA,
  189.           cmp cs:adapter,ADAPTER_VGA ;
  190.           je @@getfont               ;
  191.           mov bh,2                   ;14 point font if EGA
  192. @@getfont:
  193.           mov ax,1130h         ;get location of ASCII font
  194.           push bp              ;
  195.           push ds
  196.           int 10h              ;
  197.           mov cs:asciiseg,es   ;
  198.           mov cs:asciioffs,bp  ;
  199.           pop ds
  200.           pop bp               ;
  201.  
  202. ;
  203. ; end of video init code
  204. ;
  205.           lds dx,[bp+12] ;DS:DX now points to filename
  206.  
  207.           mov ax,3d00h   ;DOS open file function
  208.           int 21h        ;
  209.  
  210.           jnc @@open
  211.  
  212.           call _jis_deinit
  213.           mov ax,JISLIB_ERROR_OPEN ;file not found.
  214.           jmp @@end                ;return with error code
  215.  
  216. @@open:   mov bx,ax        ;handle must be in BX for DOS file functions
  217.           mov dx,VIDEOSEG  ;
  218.           mov ds,dx        ;DS:DX will soon point to video memory
  219.  
  220.           mov bp,0202H        ;store video plane picker in BP
  221.  
  222. @@loop:   mov dx,MAP_MASK   ;
  223.           mov ax,bp         ;
  224.           out dx,ax         ;pick a video plane for writing
  225.  
  226. @@read:   mov ax,3f00h     ;read 32768 bytes into first half
  227.           mov cx,32768     ;of video plane
  228.           xor dx,dx        ;
  229.           int 21h          ;DOS read file function
  230.  
  231.           cmp cx,ax        ;if 32768 bytes were read, go read more
  232.           je @@half        ;
  233.  
  234.           mov ax,3e00h          ;unexpected end of file.
  235.           int 21h               ;DOS close file function
  236.  
  237.           call _jis_deinit
  238.           mov ax,JISLIB_ERROR_READ ;
  239.           jmp @@end             ;return with error code
  240.  
  241. @@half:   mov ax,3f00h     ;read 32768 bytes into second half
  242.           mov cx,32768     ;of video plane
  243.           mov dx,cx        ;
  244.           int 21h          ;DOS read file function
  245.  
  246.           cmp cx,ax        ;if 32768 bytes were read, go read more
  247.           je @@done        ;if there was an error, close the file and exit
  248.  
  249.           mov ax,3e00h          ;unexpected end of file.
  250.           int 21h               ;DOS close file function
  251.           call _jis_deinit
  252.           mov ax,JISLIB_ERROR_READ ;
  253.           jmp @@end             ;return with error code
  254.  
  255. @@done:   mov ax,bp             ;rotate plane picker to select next plane
  256.           shl ah,1              ;if we have already read three,
  257.           mov bp,ax             ;
  258.           test ah,0f0h          ;
  259.           jnz @@final           ;go read the last chunk of data
  260.  
  261.           jmp @@loop            ;jump back to read another plane
  262.  
  263. @@final:  mov dx,MAP_MASK ;select plane zero for writing
  264.           mov ax,0102H    ;
  265.           out dx,ax       ;
  266.  
  267.           mov ax,3f00h     ;load all remaining kanji but 62 just below the
  268.           mov cx,27136     ;480th line of the 640x480 video page
  269.           mov dx,(80*480)  ;
  270.           int 21h          ;DOS read file function
  271.  
  272.           cmp cx,ax
  273.           jne @@jclose
  274.  
  275.           mov ax,3f00h     ;load final 62 kanji
  276.           mov cx,(32*62)   ;into code segment
  277.           lea dx,LAST_62   ;(weird!)
  278.           push cs          ;
  279.           pop ds           ;
  280.           int 21h          ;
  281.  
  282. @@jclose: mov dx,ax        ;did we get all the kanji we asked for?
  283.           mov ax,3e00h     ;wait until we close the file to decide.
  284.           int 21h          ;DOS close file function
  285.           cmp dx,cx        ;if all kanji were read, we have won.
  286.           je @@win         ;
  287.  
  288.           call _jis_deinit
  289.           mov ax,JISLIB_ERROR_READ ;unexpected end of file.
  290.           jmp @@end                ;return with error code
  291.  
  292. @@win:    mov dx,READ_MAP   ;pick a plane for reading
  293.           mov ax,0004H      ;
  294.           out dx,ax         ;
  295.  
  296.           mov dx,MAP_MASK   ;pick plane zero for writing
  297.           mov ax,0102h      ;
  298.           out dx,ax         ;
  299.           xor ax,ax         ;return with 0
  300.  
  301. @@end:    pop di
  302.           pop es
  303.           pop si
  304.           pop ds
  305.           pop bp
  306.           ret
  307. _jis_init endp
  308.  
  309.  
  310. ;
  311. ; void far jis_put(unsigned jis,unsigned scanline, unsigned column)
  312. ;
  313. _jis_put proc far
  314.          push bp
  315.          mov bp,sp
  316.  
  317.          push ds
  318.          push si
  319.          push es
  320.          push di
  321.  
  322.          mov ax,80           ;
  323.          mul word ptr [bp+8] ;multiply scanline by bytes/scanline
  324.          mov di,ax           ;
  325.          add di,[bp+10]      ;add column to obtain video offset
  326.  
  327.          mov ax,di       ;forbid attempts to overwrite jis table
  328.          add ax,(80*15+1);
  329.          cmp ax,(80*480) ;
  330.          jna @@adjust    ;
  331.          jmp @@putend    ;
  332.  
  333. @@adjust:mov ax,VIDEOSEG ;set up segments
  334.          mov ds,ax       ;
  335.          mov es,ax       ;
  336.  
  337.          mov si,[bp+6]  ;load jis code into SI
  338.          mov ax,si
  339.          mov cl,3
  340.          shr ah,cl
  341.          mov cl,5
  342.          shl si,cl
  343.  
  344.          ;SI = ((jis*32)%65536) ;jis "offset"
  345.          ;AH = jis/2048         ;jis "segment"
  346.  
  347.          inc ah
  348.          and ah,3
  349.          jnz @@putit
  350.  
  351.          add si,(80*480)
  352.          cmp si,(80*480)
  353.          jae @@putit
  354.          add si,OFFSET LAST_62
  355.          push cs
  356.          pop ds
  357.  
  358. @@putit: mov dx,READ_MAP   ;pick a plane for reading
  359.          mov al,04H        ;
  360.          out dx,ax         ;
  361.  
  362.          mov dx,MAP_MASK   ;pick plane zero for writing
  363.          mov ax,0102H      ;
  364.          out dx,ax         ;
  365.  
  366.          mov ax,78
  367.          mov cx,16
  368.  
  369. @@putit2:movsw         ;copy lines to video memory
  370.          add di,ax     ;
  371.          loop @@putit2
  372.  
  373. @@putend:mov dx,READ_MAP   ;pick a plane for reading
  374.          mov ax,0004H      ;
  375.          out dx,ax         ;
  376.  
  377.          mov dx,MAP_MASK   ;pick plane zero for writing
  378.          mov ax,0102h      ;
  379.          out dx,ax         ;
  380.  
  381.          pop di
  382.          pop es
  383.          pop si
  384.          pop ds
  385.          pop bp
  386.          ret
  387. _jis_put endp
  388.  
  389.  
  390. ;
  391. ; void far ascii_put(unsigned ascii,unsigned scanline, unsigned column)
  392. ;
  393. _ascii_put proc far
  394.          push bp
  395.          mov bp,sp
  396.  
  397.          push ds
  398.          push si
  399.          push es
  400.          push di
  401.  
  402.          mov ax,80           ;
  403.          mul word ptr [bp+8] ;multiply scanline by bytes/scanline
  404.          mov di,ax           ;
  405.          add di,[bp+10]      ;add column to obtain video offset
  406.  
  407.          mov ax,di       ;forbid attempts to overwrite jis table
  408.          add ax,(80*15)  ;
  409.          cmp ax,(80*480) ;
  410.          jna @@asciifoo    ;
  411.          jmp @@asciiend    ;
  412.  
  413. @@asciifoo:mov ax,VIDEOSEG
  414.          mov es,ax
  415.          mov ds,cs:asciiseg
  416.          mov si,[bp+6]     ;SI = ascii character code
  417.  
  418.          mov bx,79
  419.          cmp cs:adapter,ADAPTER_VGA
  420.          je @@funfun
  421.          call ascii14
  422.          jmp @@asciiend
  423. @@funfun:call ascii16
  424.  
  425. @@asciiend:pop di
  426.          pop es
  427.          pop si
  428.          pop ds
  429.          pop bp
  430.          ret
  431. _ascii_put endp
  432.  
  433.  
  434. ascii14 proc near
  435.         mov ax,14
  436.         mul si
  437.         mov si,ax
  438.         add si,cs:asciioffs
  439.  
  440.         mov cx,14
  441.  
  442.         xor al,al
  443.         stosb
  444.         add di,bx
  445. @@jujube:
  446.         movsb
  447.         add di,bx
  448.         loop @@jujube
  449.  
  450.         stosb
  451.  
  452.         ret
  453. ascii14 endp
  454.  
  455.  
  456. ascii16 proc near
  457.         mov cl,4
  458.         shl si,cl
  459.         add si,cs:asciioffs
  460.  
  461.         mov cx,16
  462. @@twojube:
  463.         movsb
  464.         add di,bx
  465.         loop @@twojube
  466.         ret
  467. ascii16 endp
  468.  
  469.  
  470. ;
  471. ; void far jis_clear(unsigned scanline, unsigned column,
  472. ;                    unsigned scanlines, unsigned columns);
  473. ;
  474. _jis_clear proc far
  475.            push bp
  476.            mov bp,sp
  477.  
  478.            push es
  479.            push di
  480.  
  481.            mov di,VIDEOSEG
  482.            mov es,di
  483.            mov ax,[bp+6]
  484.            mov di,80
  485.            mul di
  486.            mov di,ax
  487.            add di,[bp+8]
  488.            xor al,al
  489.  
  490. @@clr:       mov cx,[bp+12]
  491. rep        stosb
  492.            sub di,[bp+12]
  493.            add di,80
  494.            dec word ptr [bp+10]
  495.            jnz @@clr
  496.  
  497.            pop di
  498.            pop es
  499.            pop bp
  500.            ret
  501. _jis_clear endp
  502.  
  503.  
  504. ;
  505. ; void far jis_set(unsigned scanline, unsigned column,
  506. ;                  unsigned scanlines, unsigned columns);
  507. ;
  508. _jis_set proc far
  509.          push bp
  510.          mov bp,sp
  511.  
  512.          push es
  513.          push di
  514.  
  515.          mov di,VIDEOSEG
  516.          mov es,di
  517.          mov ax,[bp+6]
  518.          mov di,80
  519.          mul di
  520.          mov di,ax
  521.          add di,[bp+8]
  522.          mov al,0FFH
  523.          jmp @@clr
  524.          ;
  525.          ; NO RET
  526.          ;
  527. _jis_set endp
  528.  
  529.  
  530. ;
  531. ; void far jis_xor(unsigned scanline, unsigned column,
  532. ;                  unsigned scanlines, unsigned columns);
  533. ;
  534. _jis_xor proc far
  535.          push bp
  536.          mov bp,sp
  537.  
  538.          push es
  539.          push di
  540.  
  541.          mov di,VIDEOSEG
  542.          mov es,di
  543.          mov ax,[bp+6]
  544.          mov di,80
  545.          mul di
  546.          mov di,ax
  547.          add di,[bp+8]
  548.          xor al,al
  549.  
  550. @@clx:     mov cx,[bp+12]
  551.  
  552. @@cly:   not byte ptr es:[di]
  553.          inc di
  554.          loop @@cly
  555.  
  556.          sub di,[bp+12]
  557.          add di,80
  558.          dec word ptr [bp+10]
  559.          jnz @@clx
  560.  
  561.          pop di
  562.          pop es
  563.          pop bp
  564.          ret
  565. _jis_xor endp
  566.  
  567.  
  568. ;
  569. ; void far jis_gray(unsigned scanline, unsigned column,
  570. ;                   unsigned scanlines, unsigned columns);
  571. ;
  572. _jis_gray proc far
  573.          push bp
  574.          mov bp,sp
  575.  
  576.          push es
  577.          push di
  578.  
  579.          mov di,VIDEOSEG
  580.          mov es,di
  581.          mov ax,[bp+6]
  582.          mov di,80
  583.          mul di
  584.          mov di,ax
  585.          add di,[bp+8]
  586.          xor al,al
  587.          mov bl,55H
  588.  
  589. @@gra:     mov cx,[bp+12]
  590. @@grb:   and es:[di],bl
  591.          inc di
  592.          loop @@grb
  593.  
  594.          sub di,[bp+12]
  595.          add di,80
  596.          not bl
  597.          dec word ptr [bp+10]
  598.          jnz @@gra
  599.  
  600.          pop di
  601.          pop es
  602.          pop bp
  603.          ret
  604. _jis_gray endp
  605.  
  606.  
  607. ;
  608. ; void far jis_bold8(unsigned scanline, unsigned column,
  609. ;                    unsigned scanlines, unsigned columns);
  610. ;
  611. _jis_bold8 proc far
  612.          push bp
  613.          mov bp,sp
  614.  
  615.          push es
  616.          push di
  617.  
  618.          mov di,VIDEOSEG
  619.          mov es,di
  620.          mov ax,[bp+6]
  621.          mov di,80
  622.          mul di
  623.          mov di,ax
  624.          add di,[bp+8]
  625.  
  626. @@bgra:     mov cx,[bp+12]
  627. @@bgrb:  mov al,es:[di]
  628.          shr al,1
  629.          or es:[di],al
  630.          inc di
  631.          loop @@bgrb
  632.  
  633.          sub di,[bp+12]
  634.          add di,80
  635.          dec word ptr [bp+10]
  636.          jnz @@bgra
  637.  
  638.          pop di
  639.          pop es
  640.          pop bp
  641.          ret
  642. _jis_bold8 endp
  643.  
  644.  
  645. ;
  646. ; void far jis_fcopy(unsigned srcy,   unsigned srcx,
  647. ;                    unsigned desty,  unsigned destx,
  648. ;                    unsigned height, unsigned width  );
  649. ;
  650. _jis_fcopy proc far
  651.          push bp
  652.          mov bp,sp
  653.  
  654.          push ds  ;save data and extra segments
  655.          push si  ;
  656.          push es  ;
  657.          push di  ;
  658.  
  659.          mov di,VIDEOSEG ;set up segments for video transfer
  660.          mov es,di       ;
  661.          mov ds,di       ;
  662.  
  663.          mov ax,[bp+6]  ;set up source register
  664.          mov si,80      ;
  665.          mul si         ;
  666.          mov si,ax      ;
  667.          add si,[bp+8]  ;
  668.  
  669.          mov ax,[bp+10] ;set up destination register
  670.          mov di,80      ;
  671.          mul di         ;
  672.          mov di,ax      ;
  673.          add di,[bp+12] ;
  674.  
  675.          mov bx,80
  676.          mov dx,[bp+16]
  677.          sub bx,dx
  678.          js @@copend
  679.          cld
  680. @@cop1:
  681.          mov cx,dx
  682.          shr cx,1
  683.          jz @@cop2
  684. rep      movsw
  685. @@cop2:     jnc @@cop3
  686.          movsb
  687. @@cop3:
  688.  
  689.          add si,bx
  690.          add di,bx
  691.          dec word ptr [bp+14]
  692.          jnz @@cop1
  693.  
  694. @@copend:
  695.          pop di
  696.          pop es
  697.          pop si
  698.          pop ds
  699.          pop bp
  700.          ret
  701. _jis_fcopy endp
  702.  
  703.  
  704. ;
  705. ; void far jis_bcopy(unsigned srcy,   unsigned srcx,
  706. ;                    unsigned desty,  unsigned destx,
  707. ;                    unsigned height, unsigned width  );
  708. ;
  709. _jis_bcopy proc far
  710.          push bp
  711.          mov bp,sp
  712.  
  713.          push ds  ;save data and extra segments
  714.          push si  ;
  715.          push es  ;
  716.          push di  ;
  717.  
  718.          mov di,VIDEOSEG ;set up segments for video transfer
  719.          mov es,di       ;
  720.          mov ds,di       ;
  721.  
  722.          mov ax,[bp+6]  ;set up source register
  723.          mov si,80      ;
  724.          mul si         ;
  725.          mov si,ax      ;
  726.          add si,[bp+8]  ;
  727.  
  728.          mov ax,[bp+10] ;set up destination register
  729.          mov di,80      ;
  730.          mul di         ;
  731.          mov di,ax      ;
  732.          add di,[bp+12] ;
  733.  
  734.          mov ax,80
  735.          mul word ptr [bp+14]
  736.          sub ax,80
  737.          add ax,[bp+16]
  738.          dec ax
  739.  
  740.          add si,ax
  741.          add di,ax
  742.  
  743.          mov bx,80
  744.          mov dx,[bp+16]
  745.          sub bx,dx
  746.  
  747.          std
  748. @@bcop1:
  749.          mov cx,dx
  750. rep         movsb
  751.  
  752.          sub si,bx
  753.          sub di,bx
  754.          dec word ptr [bp+14]
  755.          jnz @@bcop1
  756.  
  757.          cld
  758.          pop di
  759.          pop es
  760.          pop si
  761.          pop ds
  762.          pop bp
  763.          ret
  764. _jis_bcopy endp
  765.  
  766.  
  767.  
  768.    ;
  769. JISLIB_TEXT    ends
  770.  
  771.     public    _jis_init
  772.     public    _jis_deinit
  773.     public  _jis_put
  774.     public  _ascii_put
  775.     public  _jis_clear
  776.     public  _jis_set
  777.     public  _jis_xor
  778.     public  _jis_gray
  779.     public  _jis_bold8
  780.     public  _jis_fcopy
  781.     public  _jis_bcopy
  782.     end
  783.  
  784.  
  785.  
  786.