home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / COMM / MISC / SRC26_2.ZIP / SRC / VRAMJ3.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-06-22  |  25.1 KB  |  1,083 lines

  1. ;
  2. ; vramj3.asm: hterm screen control for J-3100 series (mainly using BIOS)
  3. ;
  4. ; Author: Kaz.Tominaga@Titech/Giken
  5. ;
  6. ; 1.1 89/11/01 Tominaga@Titech converted from vrampc.asm
  7. ; 1.2 90/06/22 Halca.Hirano add soft font support functions
  8. ;
  9. ; $Header: vramj3.asv  1.3  90/06/22 04:52:00  hirano  Exp $
  10. ;
  11. ; Entry:
  12. ;    utilities
  13. ;         u_short getDSeg()
  14. ;         splx():    enable interrupt
  15. ;         spl7():    disable interrupt
  16. ;         void moveMemory(to, toSeg, from, fromSeg, num)
  17. ;
  18. ;    J3100 VRAM access thru BIOS routines
  19. ;         void fillVRAMJ3(at, num, data, attrib)
  20. ;         void moveForwardJ3(to, from, num)
  21. ;         void moveBackwardJ3(to, from, num)
  22. ;         void saveVRAM(off, seg)
  23. ;         void loadVRAM(off, seg)
  24. ;         void swapVRAM(fromoff, fromseg, tooff, toseg)
  25. ;         u_short b_getCursor()
  26. ;         void b_setCursor(xy)
  27. ;         u_short b_readChar()
  28. ;         void b_writeChar(c)
  29. ;         void b_reverseChar()
  30. ;         u_short b_readCharAt(xy)
  31. ;         void b_writeCharAt(c, xy)
  32. ;         void b_reverseCharAt(xy)
  33. ;         void v_reverseScreen()
  34. ;
  35. ; soft font backing store access and GVRAM access routines
  36. ;         void fillVRAM(at, num, data, attrib)
  37. ;         void moveForward(to, from, num, attribFlag)
  38. ;         void moveBackward(to, from, num, attribFlag)
  39. ;         void moveForByte(to, from, num)
  40. ;         void moveBackByte(to, from, num)
  41. ;
  42.  
  43. ; Constants
  44. COLUMN_COUNT    equ    80        ; width of display
  45. ROW_COUNT    equ    25        ; height of display
  46.  
  47. ; compensate for the BIOS' unsuitable reading from the code buffer
  48. SPACE_CHAR_READ    equ    0020h        ; space character code with normal
  49.                     ; attribute read from the code buffer
  50. SPACE_CHAR_CODE    equ    7720h        ; if above is found, this code must be
  51.                     ; written because the attribute 00h
  52.                     ; means 'transparent' and if it is
  53.                     ; written no difference is appear on
  54.                     ; the screen instead of clearing
  55.                     ; the position by space character.
  56. ; constants used for kstate
  57. SJIS1_EXPECT    equ    0        ; sjis1 or ascii code is expected next
  58. SJIS2_EXPECT    equ    1        ; sjis2 is expected
  59. ;
  60. _DATA    segment    word public 'DATA'
  61. _DATA    ends
  62.  
  63. extrn    _vramSegment:word    ; extern u_short vramSegment
  64. extrn    _gvramSegment:word    ; extern u_short gvramSegment
  65.  
  66. _TEXT    segment    word public 'CODE'
  67.     assume    ds:_DATA,cs:_TEXT
  68. ;
  69. ; work area
  70. ;
  71. kstate    dw    SJIS1_EXPECT    ; kanji state
  72.  
  73.  
  74. ;
  75. ; u_short getDSeg()
  76. ; return:    data segment
  77. ;
  78.     public    _getDSeg
  79. _getDSeg proc    far
  80.     mov    ax,ds
  81.     ret
  82. _getDSeg endp
  83.  
  84. ;
  85. ; splx():    enable interrupt
  86. ;
  87.     public    _splx
  88. _splx    proc    far
  89.     sti
  90.     ret
  91. _splx    endp
  92.  
  93. ;
  94. ; spl7():    disable interrupt
  95. ;
  96.     public    _spl7
  97. _spl7    proc    far
  98.     cli
  99.     ret
  100. _spl7    endp
  101.  
  102.  
  103. ;
  104. ; void fillVRAMJ3(at, num, data, attrib)
  105. ; u_short at;        location to start filling at (y << 8) | x
  106. ; u_short num;        number to fill
  107. ; u_short data;        fill data
  108. ; u_short attrib;    fill attribute
  109. ;
  110. ; put 'num' 'data's at 'at' and put num 'attrib's at attribute area
  111. ;
  112.     public _fillVRAMJ3
  113. _fillVRAMJ3 proc    far
  114.     push    bp
  115.     mov    bp,sp
  116.     push    bx
  117.     push    cx
  118.     push    dx
  119.     mov    bx,[6+bp]        ; bx := location (bios expression)
  120.     mov    cx,[8+bp]        ; cx := filling count
  121.     mov    ax,[10+bp]        ; ax := filling data
  122.     mov    dx,[12+bp]        ; dx := attribute
  123.     mov    ah,dl            ; make ax to be (attr << 8) | data
  124.     ; dx is now not need
  125.     cmp    cx,0            ; if count = 0
  126.     jz    fvret            ; return
  127. fvloop:
  128.     ; write char
  129.     push    bx            ; location
  130.     push    ax            ; char
  131.     call    far ptr _b_writeCharAt    ; write ax at location bx
  132.     add    sp,4            ; restore stack
  133.     ; next cursor position
  134.     inc    bl            ; increment x
  135.     cmp    bl,COLUMN_COUNT        ; x < 80?
  136.     jl    fvnext            ; yes. jump.
  137.     ; x = 80
  138.     mov    bl,0            ; to top of next line
  139.     inc    bh
  140.     cmp    bh,ROW_COUNT        ; y < 25?
  141.     jl    fvnext            ; yes. jump.
  142.     ; y = 25
  143.     jmp    fvret            ; no more filling
  144. fvnext:
  145.     loop    fvloop            ; to fill next position
  146.     ; done
  147. fvret:
  148.     pop    dx
  149.     pop    cx
  150.     pop    bx
  151.     pop    bp
  152.     ret
  153. _fillVRAMJ3 endp
  154.  
  155. ;
  156. ; void moveForwardJ3(to, from, num)
  157. ; u_short to;        destination location (y << 8) | x
  158. ; u_short from;        source location (y << 8) | x
  159. ; u_short num;        the number of characters to move
  160. ;
  161. ; This routine moves char and attribute 'from' 'to' 'num' chars.
  162. ; The direction is incremental (from lower address to higher address).
  163. ; Therefore this procedure should be used to move sequenced char block
  164. ; from higher address to lower address. This is used by deleteChar().
  165. ;
  166. ; To make up for the lack of ability of J-3100 screen BIOS, this routine
  167. ; traces what kind of code(such as sjis1, sjis2...) is written on the
  168. ; screen the most recently while copying, and if the last character
  169. ; to be written is a sjis1 code, eliminates it.
  170. ;
  171.     public    _moveForwardJ3
  172. _moveForwardJ3    proc far
  173.     push    bp
  174.     mov    bp,sp
  175.     push    bx
  176.     push    cx
  177.     push    dx
  178.     ; reset kanji state
  179.     mov    cs:kstate,SJIS1_EXPECT    ; clear kanji state flag
  180.     ; get parameters
  181.     mov    dx,[6+bp]        ; destination location
  182.     mov    bx,[8+bp]        ; source location
  183.     mov    cx,[10+bp]        ; count
  184. mfloop:
  185.     ; counter
  186.     cmp    cx,0            ; if 0
  187.     jz    mfret            ; done
  188.     ; check source location
  189.     cmp    bl,COLUMN_COUNT        ; x < 80?
  190.     jl    mfsrcok            ; source location ok
  191.     ; x >= 80
  192.     mov    bl,0            ; to top of next line
  193.     inc    bh            ; increment y
  194.     cmp    bh,ROW_COUNT        ; y < 25?
  195.     jl    mfsrcok            ; source location ok
  196.     ; y >= 25
  197.     jmp    mfret            ; no more process
  198. mfsrcok:
  199.     ; check destination location
  200.     cmp    dl,COLUMN_COUNT        ; x < 80?
  201.     jl    mfdestok        ; destination location ok
  202.     ; x >= 80
  203.     mov    dl,0            ; to top of next line
  204.     inc    dh            ; increment y
  205.     cmp    dh,ROW_COUNT        ; y < 25?
  206.     jl    mfdestok        ; destination location ok
  207.     ; y >= 25
  208.     jmp    mfret            ; no more process
  209. mfdestok:
  210.     ; get one char at source location
  211.     push    bx            ; location
  212.     call    far ptr _b_readCharAt    ; read char and attr into ax
  213.     add    sp,2            ; restore stack
  214. ; now ax has char and its attr. BE CAREFUL TO PRESERVE IT UNTIL WRITING IT!
  215. ;    ; set kanji state by the character
  216. ;    cmp    cs:kstate,SJIS2_EXPECT
  217. ;    je    mfsjis2
  218. ;    ; either sjis1 or ascii code is expected
  219. ;    call    near ptr isSJIS1    ; check if al is sjis1 code
  220. ;    jnc    mfwriteok        ; if ascii, write it as it is
  221. ;    ; sjis1
  222. ;    mov    cs:kstate,SJIS2_EXPECT    ; change kanji state
  223. ;    ; check if the sjis1 code is all right to write
  224. ;    cmp    cx,1            ; is the last char?
  225. ;    jne    mfwriteok        ; if not, it can be written.
  226. ;    jmp    mfloopend        ; otherwise skip the process to write
  227. ;mfsjis2:; sjis2 is expected (and assume that it is)
  228. ;    mov    cs:kstate,SJIS1_EXPECT    ; change kanji state
  229. ;mfwriteok:
  230.     ; put it at destination
  231.     push    dx            ; location
  232.     push    ax            ; char and attr
  233.     call    far ptr _b_writeCharAt    ; write char and attr at dx
  234.     add    sp,4            ; restore stack
  235. mfloopend:
  236.     ; increment source location
  237.     inc    bl            ; increment x
  238.     ; increment destination location
  239.     inc    dl            ; increment x
  240.     ; decrement counter
  241.     dec    cx            ; to treat next char
  242.     jmp    mfloop            ; next looping
  243. mfret:
  244.     pop    di
  245.     pop    cx
  246.     pop    bx
  247.     pop    bp
  248.     ret
  249. _moveForwardJ3 endp
  250.  
  251. ;
  252. ; void moveBackwardJ3(to, from, num)
  253. ; u_short to;        destination location (y << 8) | x
  254. ; u_short from;        source location (y << 8) | x
  255. ; u_short num;        the number of characters to move
  256. ;
  257. ; This routine moves char and attribute 'from' 'to' 'num' chars.
  258. ; The direction is decremental (from higher address to lower address).
  259. ; Therefore this procedure should be used to move sequenced char block
  260. ; from lower address to higher address. This is used by insertChar().
  261. ;
  262. ; To make up for the lack of ability of J-3100 screen BIOS, this routine
  263. ; traces what kind of code(such as sjis1, sjis2...) is written on the
  264. ; screen the most recently while copying, and if the last character
  265. ; to be written is a sjis1 code, eliminates it.
  266. ;
  267. ; BE CAREFUL that this routine uses stack as working area. It counts
  268. ; the data when putting into the stack, and pop them (and may write on the
  269. ; screen) as much as pushed. You should set the stack size by carefully
  270. ; estimating how much it is needed (4096byte stack is large enough in fact,
  271. ; because J-3100 has 80x25 screen size and a character has its code and
  272. ; attribute each of 1byte.)
  273. ;
  274.     public    _moveBackwardJ3
  275. _moveBackwardJ3    proc far
  276.     push    bp
  277.     mov    bp,sp
  278.     push    bx
  279.     push    cx
  280.     push    dx
  281.     push    di
  282.     ; reset kanji state
  283.     mov    cs:kstate,SJIS1_EXPECT    ; clear kanji state flag
  284.     ; get source and destination location
  285.     mov    bx,[8+bp]        ; source location
  286.     mov    dx,[6+bp]        ; destination location
  287.     ; get count
  288.     mov    ax,[10+bp]        ; count
  289.     mov    cl,COLUMN_COUNT        ; = 80
  290.     div    cl            ; count / 80
  291.     ; set source location to tail of the string block to transfer
  292.     add    bh,al            ; add quotient (for y)
  293.     add    bl,ah            ; add modulo   (for x)
  294.     ;
  295.     ; loop for getting characters into stack
  296.     ;
  297.     mov    cx,[10+bp]        ; get count once more
  298.     mov    di,0            ; count of data actually pushed into the stack
  299. mbgetloop:
  300.     ; counter
  301.     cmp    cx,0            ; if 0
  302.     jz    mbgetend        ; done
  303.     ; decrement source location
  304.     dec    bl            ; decrement x
  305.     ; check source location
  306.     cmp    bl,0            ; x >= 0?
  307.     jge    mbsrcok            ; source location ok
  308.     ; x < 0
  309.     mov    bl,COLUMN_COUNT-1    ; to end of next line
  310.     dec    bh            ; decrement y
  311.     cmp    bh,0            ; y >= 0?
  312.     jge    mbsrcok            ; source location ok
  313.     ; y < 0
  314.     jmp    mbgetend        ; no more process
  315. mbsrcok:
  316.     mov    ax,7720h        ; clear ax with a space with normal attr
  317.     cmp    bh,ROW_COUNT        ; y >= 25?
  318.     jge    mbgot            ; then push the space as it is
  319.     ; get one char at source location
  320.     push    bx            ; location
  321.     call    far ptr _b_readCharAt    ; read char and attr into ax
  322.     add    sp,2            ; restore stack
  323. mbgot:
  324.     push    ax            ; push the data into stack
  325.     inc    di            ; count it
  326.     ; decrement counter
  327.     dec    cx            ; to treat next char
  328.     jmp    mbgetloop        ; next looping
  329. mbgetend:
  330.     ;
  331.     ; then pop them and write on the screen
  332.     ;
  333.     mov    cx,di            ; use the count of data in the stack
  334. mbputloop:
  335.     ; counter
  336.     cmp    cx,0            ; if 0
  337.     jz    mbputend        ; done
  338.     ; check destination location
  339.     cmp    dl,COLUMN_COUNT        ; x < 80?
  340.     jl    mbdestok        ; destination location ok
  341.     ; x >= 80
  342.     mov    dl,0            ; to the top of next line
  343.     inc    dh            ; increment y
  344.     cmp    dh,ROW_COUNT        ; y < 25?
  345.     jl    mbdestok        ; destination location ok
  346.     ; y >= 25
  347.     pop    ax            ; discard a character on the stack
  348.     jmp    mbputtail        ; go on looping
  349. mbdestok:
  350.     ; put the data at destination
  351.     pop    ax            ; get data from the stack
  352.     dec    di            ; not need in fact
  353. ; now ax has char and its attr. BE CAREFUL TO PRESERVE IT UNTIL WRITING IT!
  354. ;    ; set kanji state by the character
  355. ;    cmp    cs:kstate,SJIS2_EXPECT
  356. ;    je    mbsjis2
  357. ;    ; either sjis1 or ascii code is expected
  358. ;    call    near ptr isSJIS1    ; check if al is sjis1 code
  359. ;    jnc    mbwriteok        ; if ascii, write it as it is
  360. ;    ; sjis1
  361. ;    mov    cs:kstate,SJIS2_EXPECT    ; change kanji state
  362. ;    ; check if the sjis1 code is all right to write
  363. ;    cmp    cx,1            ; is the last char?
  364. ;    jne    mbwriteok        ; if not, it can be written.
  365. ;    jmp    mbputtail        ; otherwise skip the process to write
  366. ;mbsjis2:; sjis2 is expected (and assume that it is)
  367. ;    mov    cs:kstate,SJIS1_EXPECT    ; change kanji state
  368. ;mbwriteok:
  369.     push    dx            ; location
  370.     push    ax            ; char and attr as a parameter
  371.     call    far ptr _b_writeCharAt    ; write char and attr at dx
  372.     add    sp,4            ; restore stack
  373. mbputtail:
  374.     ; increment destination location
  375.     inc    dl            ; increment x
  376.     ; decrement counter
  377.     dec    cx            ; to treat next char
  378.     jmp    mbputloop        ; next looping
  379. mbputend:
  380.     pop    di
  381.     pop    dx
  382.     pop    cx
  383.     pop    bx
  384.     pop    bp
  385.     ret
  386. _moveBackwardJ3    endp
  387.  
  388. ;
  389. ; void moveMemory(to, toSeg, from, fromSeg, num)
  390. ; u_short to;        destination address
  391. ; u_short toSeg;    destination address
  392. ; u_short from;        source address
  393. ; u_short fromSeg;    source address
  394. ; u_short num;        words to move
  395. ;
  396.     public    _moveMemory
  397. _moveMemory proc far
  398.     push    bp
  399.     mov    bp,sp
  400.     push    cx
  401.     push    si
  402.     push    di
  403.     push    ds
  404.     push    es
  405.     mov    cx,[14+bp]        ; cx := count
  406.     mov    ax,[12+bp]
  407.     mov    ds,ax            ; ds := from segment
  408.     mov    ax,[10+bp]
  409.     mov    si,ax            ; si := from offset
  410.     mov    ax,[8+bp]
  411.     mov    es,ax            ; es := to segment
  412.     mov    ax,[6+bp]
  413.     mov    di,ax            ; di := to offset
  414.     cld                ; direction is forward
  415.     rep    movsw            ; move char
  416.     pop    es
  417.     pop    ds
  418.     pop    di
  419.     pop    si
  420.     pop    cx
  421.     pop    bp
  422.     ret    
  423. _moveMemory endp
  424.  
  425. ;
  426. ; void saveVRAM(off, seg)
  427. ; u_short    off;    offset of buffer
  428. ; u_short    seg;    segment of buffer
  429. ;    save the contents of VRAM into the buffer
  430. ;
  431.     public    _saveVRAM
  432. _saveVRAM    proc far
  433.     push    bp
  434.     mov    bp,sp
  435.     push    bx
  436.     push    cx
  437.     push    es
  438.     ; get parameters
  439.     mov    bx,[6+bp]        ; get offset of the buffer
  440.     mov    ax,[8+bp]        ; get segment of the buffer
  441.     mov    es,ax            ; set it into es
  442.     mov    cx,0            ; reset cursor position
  443. svvloop:
  444.     ; check if the position is valid
  445.     cmp    cl,COLUMN_COUNT        ; x < 80?
  446.     jl    svvok            ; yes. jump.
  447.     ; x >= 80
  448.     mov    cl,0            ; to top of next line
  449.     inc    ch            ; increment y
  450.     cmp    ch,ROW_COUNT        ; y < 25?
  451.     jl    svvok            ; yes. jump.
  452.     ; y >= 25
  453.     jmp    svvret            ; no more process
  454. svvok:
  455.     ; read char from VRAM
  456.     push    cx            ; x-y
  457.     call    far ptr _b_readCharAt    ; read char and attr at the position
  458.     add    sp,2            ; restore stack
  459. svvsavechar:
  460.     ; ax has char and its attr
  461.     mov    es:[bx],ax        ; save it into the buffer
  462.     inc    bx            ; increment
  463.     inc    bx
  464. svvloopend:
  465.     inc    cl            ; increment x
  466.     jmp    svvloop            ; next looping
  467.     ; done
  468. svvret:
  469.     pop    es
  470.     pop    cx
  471.     pop    bx
  472.     pop    bp
  473.     ret
  474. _saveVRAM    endp
  475.  
  476. ;
  477. ; void loadVRAM(off, seg)
  478. ; u_short    off;    offset of buffer
  479. ; u_short    seg;    segment of buffer
  480. ;    load the contents of the buffer into VRAM
  481. ;
  482.     public    _loadVRAM
  483. _loadVRAM    proc far
  484.     push    bp
  485.     mov    bp,sp
  486.     push    bx
  487.     push    cx
  488.     push    es
  489.     ; get parameters
  490.     mov    bx,[6+bp]        ; get offset of the buffer
  491.     mov    ax,[8+bp]        ; get segment of the buffer
  492.     mov    es,ax            ; set it into es
  493.     mov    cx,0            ; reset cursor position
  494. ldvloop:
  495.     ; check if the position is valid
  496.     cmp    cl,COLUMN_COUNT        ; x < 80?
  497.     jl    ldvok            ; yes. jump.
  498.     ; x >= 80
  499.     mov    cl,0            ; to top of next line
  500.     inc    ch            ; increment y
  501.     cmp    ch,ROW_COUNT        ; y < 25?
  502.     jl    ldvok            ; yes. jump.
  503.     ; y >= 25
  504.     jmp    ldvret            ; no more process
  505. ldvok:
  506.     mov    ax,es:[bx]        ; load one char from the buffer
  507.     inc    bx            ; increment
  508.     inc    bx
  509.     ; put char into VRAM
  510.     push    cx            ; x-y
  511.     push    ax            ; char and its attr
  512.     call    far ptr _b_writeCharAt    ; write char and attr at the position
  513.     add    sp,4            ; restore stack
  514. ldvloopend:
  515.     inc    cl            ; increment x
  516.     jmp    ldvloop            ; next looping
  517.     ; done
  518. ldvret:
  519.     pop    es
  520.     pop    cx
  521.     pop    bx
  522.     pop    bp
  523.     ret
  524. _loadVRAM    endp
  525.  
  526. ;
  527. ; void swapVRAM(fromoff, fromseg, tooff, toseg)
  528. ; u_short    fromoff;    offset of buffer where swap in VRAM from
  529. ; u_short    fromseg;    segment of buffer
  530. ; u_short    tooff;        offset of buffer where swap out VRAM to
  531. ; u_short    toseg;        segment of buffer
  532. ;    save the contents of VRAM into `to' buffer and
  533. ;    load the contents of `from' buffer into VRAM
  534. ;    (`from' and `to' buffer can be the same)
  535. ;
  536.     public    _swapVRAM
  537. _swapVRAM    proc far
  538.     push    bp
  539.     mov    bp,sp
  540.     push    bx
  541.     push    cx
  542.     push    dx
  543.     push    si
  544.     push    di
  545.     push    es
  546.     ;
  547.     mov    si,[6+bp]    ; get the offset of the source
  548.     mov    ax,[8+bp]    ;         segment
  549.     mov    es,ax        ; ... into ES
  550.     mov    di,[10+bp]    ; get the offset of the destination
  551.     mov    cx,[12+bp]    ;         segment (held in CX)
  552.     mov    bx,0        ; set cursor position to the leftmost-uppermost
  553.     ;
  554. spvloop:
  555.     cmp    bl,COLUMN_COUNT    ; check x of cursor
  556.     jl    spvok        ; ok. jump.
  557.     ; x >= 80
  558.     mov    bl,0        ; set x to top of next line
  559.     inc    bh        ; increment y
  560.     cmp    bh,ROW_COUNT    ; check y
  561.     jl    spvok        ; ok. jump.
  562.     ; y >= 25
  563.     jmp    spvend        ; end of screen
  564.     ;
  565. spvok:    ; now ES must have source segment and CX must have dest segment
  566.     push    bx            ; as a paramter
  567.     call    far ptr _b_readCharAt    ; read char at (BX) into AX
  568.     add    sp,2            ; restore stack
  569.     mov    dx,ax            ; put char read into DX
  570.     mov    ax,es:[si]        ; get char in source area
  571.     add    si,2            ; increment source address by 2
  572.     push    bx            ; as a parameter(location)
  573.     push    ax            ; char to be written
  574.     call    far ptr _b_writeCharAt    ; write char DX at (BX)
  575.     add    sp,4            ; restore stack
  576.     ; swap ES(source seg.) and CX(dest seg.)
  577.     mov    ax,es
  578.     mov    es,cx
  579.     mov    cx,ax
  580.     ; now ES has dest segment, CX has source segment and DX has char read
  581.     mov    es:[di],dx    ; put the char read from screen into dest area
  582.     add    di,2        ; increment dest address by 2
  583.     ; swap ES(dest seg.) and CX(source seg.)
  584.     mov    ax,es
  585.     mov    es,cx
  586.     mov    cx,ax
  587.     ; now ES has source segment and CX has dest segment
  588.     inc    bl            ; increment x
  589.     jmp    spvloop            ; loop to process next character
  590.     ;
  591. spvend:
  592.     pop    es
  593.     pop    di
  594.     pop    si
  595.     pop    dx
  596.     pop    cx
  597.     pop    bx
  598.     pop    bp
  599.     ret
  600. _swapVRAM    endp
  601.  
  602. ;
  603. ;        *** basic BIOS routines for screen operations ***
  604. ;
  605. ; u_short b_getCursor()
  606. ;    get current cursor position using BIOS
  607. ;    return AH=0~24, AL=0~79
  608. ;
  609.     public    _b_getCursor
  610. _b_getCursor    proc far
  611.     push    bx
  612.     push    cx
  613.     push    dx
  614.     mov    bh,0        ; screen page
  615.     mov    ah,3        ; read cursor position
  616.     int    10h        ; display bios
  617.     mov    ax,dx        ; dx has cursor position
  618.     pop    bx
  619.     pop    cx
  620.     pop    dx
  621.     ret
  622. _b_getCursor    endp
  623.  
  624. ;
  625. ; void b_setCursor(xy)
  626. ; u_short    xy;
  627. ;    set cursor position using BIOS
  628. ;    xy is (y << 8) | x
  629. ;
  630.     public    _b_setCursor
  631. _b_setCursor    proc far
  632.     push    bp
  633.     mov    bp,sp
  634.     push    bx
  635.     push    dx
  636.     mov    dx,[6+bp]    ; cursor position to dx
  637.     mov    bh,0        ; screen page
  638.     mov    ah,2        ; set cursor position
  639.     int    10h        ; screen bios
  640.     pop    dx
  641.     pop    bx
  642.     pop    bp
  643.     ret
  644. _b_setCursor    endp
  645.  
  646. ;
  647. ; u_short b_readChar()
  648. ;    read a character at the cursor position.
  649. ;    returns AX as AH=attr, AL=char
  650. ;
  651.     public    _b_readChar
  652. _b_readChar    proc far
  653.     push    bx
  654.     mov    bh,0        ; screen page
  655.     mov    ah,8        ; read char
  656.     int    10h        ; screen bios
  657.     ; now AX is set as shown above.
  658.     cmp    ax,SPACE_CHAR_READ    ; if the char is to be adjusted,
  659.     jne    rcret
  660.     mov    ax,SPACE_CHAR_CODE    ; adjust it suitable to later writing
  661. rcret:
  662.     pop    bx
  663.     ret
  664. _b_readChar    endp
  665.  
  666. ;
  667. ; void b_writeChar(c)
  668. ; u_short    c;
  669. ;    write a character (c & 0xff) at the cursor position
  670. ;    with attribute code (c >> 8). cursor is not moved.
  671. ;
  672.     public    _b_writeChar
  673. _b_writeChar    proc far
  674.     push    bp
  675.     mov    bp,sp
  676.     push    bx
  677.     push    cx
  678.     mov    ax,[6+bp]    ; get char and attr
  679.     mov    bl,ah        ; attr into bl
  680.     mov    cx,1        ; write 1 char
  681.     mov    ah,9        ; write char with attribute(al has char code)
  682.     int    10h        ; screen bios
  683.     ; done
  684.     pop    cx
  685.     pop    bx
  686.     pop    bp
  687.     ret
  688. _b_writeChar    endp
  689.  
  690. ;
  691. ; void b_reverseChar()
  692. ;    reverse the character displayed at the cursor position
  693. ;
  694.     public    _b_reverseChar
  695. _b_reverseChar    proc far
  696.     ; read character and its attribute
  697.     push    bx
  698.     push    cx
  699.     mov    bh,0        ; screen page
  700.     mov    ah,8        ; read character
  701.     int    10h        ; screen bios
  702.     ; now ax has (attr << 8) | char
  703.     mov    bh,0
  704.     mov    bl,ah        ; get attr
  705.     and    bl,07h        ; is normal or reversed?
  706.     jz    brc_reversed    ; reversed. jump.
  707.         ; normal. change into reversed
  708.     mov    bl,70h
  709.     jmp    brc_end
  710. brc_reversed:    ; reversed. change into normal
  711.     mov    bl,77h        ; attr 77h is assumed to be normal attr.
  712. brc_end:    ; now AL has char code, BL has new attr
  713.     mov    bh,0        ; screen page
  714.     mov    cx,1        ; write 1 char
  715.     mov    ah,9        ; write char and attr
  716.     int    10h        ; screen bios
  717.         ; done
  718.     pop    cx
  719.     pop    bx
  720.     ret
  721. _b_reverseChar    endp
  722.  
  723. ;
  724. ; u_short b_readCharAt(xy)
  725. ; u_short    xy;    (y << 8) | x
  726. ;    read a character at x-y
  727. ;
  728.     public    _b_readCharAt
  729. _b_readCharAt    proc far
  730.     push    bp
  731.     mov    bp,sp
  732.     ; set cursor to x-y
  733.     push    [6+bp]        ; set param
  734.     call    far ptr _b_setCursor
  735.     add    sp,2
  736.     ; read the char there
  737.     call    far ptr _b_readChar
  738.     ; done
  739.     pop    bp
  740.     ret
  741. _b_readCharAt    endp
  742.  
  743. ;
  744. ; void b_writeCharAt(c, xy)
  745. ; u_short    c;    (c & 0xff) is char, (c >> 8) is attribute
  746. ; u_short    xy;    (y << 8) | x
  747. ;    write a character (c & 0xff) at x-y
  748. ;    with attribute code (c >> 8). cursor is set to x-y.
  749. ;
  750.     public    _b_writeCharAt
  751. _b_writeCharAt    proc far
  752.     push    bp
  753.     mov    bp,sp
  754.     ; set cursor to x-y
  755.     push    [8+bp]        ; set param
  756.     call    far ptr _b_setCursor
  757.     add    sp,2
  758.     ; write c there
  759.     push    [6+bp]        ; set param
  760.     call    far ptr _b_writeChar
  761.     add    sp,2
  762.     ; done
  763.     pop    bp
  764.     ret
  765. _b_writeCharAt    endp
  766.  
  767. ;
  768. ; void b_reverseCharAt(xy)
  769. ; u_short    xy;    (y << 8) | x
  770. ;    reverse the character at x-y. cursor is set to x-y.
  771. ;
  772.     public    _b_reverseCharAt
  773. _b_reverseCharAt    proc far
  774.     push    bp
  775.     mov    bp,sp
  776.     ; set cursor to x-y
  777.     push    [6+bp]        ; set param
  778.     call    far ptr _b_setCursor
  779.     add    sp,2
  780.     ; reverse char there
  781.     call    far ptr _b_reverseChar
  782.     ; done
  783.     pop    bp
  784.     ret
  785. _b_reverseCharAt    endp
  786.  
  787. ;
  788. ; void v_reverseScreen()
  789. ;
  790. ;    reverse the screen
  791. ;
  792.     public    _v_reverseScreen
  793. _v_reverseScreen    proc far
  794.     push    bx
  795.     push    cx
  796.     push    si
  797.     push    es
  798.     mov    ax,word ptr _vramSegment
  799.     mov    es,ax            ; get VRAM segment into es
  800.     mov    ax,8300h        ; read start address
  801.     int    10h            ; screen bios
  802.     mov    cx,4            ; loop count
  803.     mov    si,0000h        ; first line (to fourth)
  804.     ; ax has the start address at any time during the loops below
  805. vroutloop:
  806.     push    cx            ; save outer loop counter
  807.     mov    bx,ax
  808.     mov    cx,COLUMN_COUNT*ROW_COUNT*2
  809. vrinloop:
  810.     not    word ptr es:[bx+si]    ; reverse the data
  811.     inc    bx
  812.     inc    bx
  813.     and    bx,1fffh        ; mask for vram offset
  814.     loop    vrinloop        ; until the end of the last row
  815.     ;
  816.     add    si,2000h        ; shift the top address
  817.     pop    cx            ; restore outer loop conter
  818.     loop    vroutloop        ; until end of screen
  819.     ;
  820.     pop    es
  821.     pop    si
  822.     pop    cx
  823.     pop    bx
  824.     ret
  825. _v_reverseScreen    endp
  826.  
  827. ;
  828. ; isSJIS1 : check if the content of AL is SJIS1 code and
  829. ;           if it is returns with CF set, otherwise CF cleared.
  830. ;
  831. isSJIS1    proc near
  832.     cmp    al,81h
  833.     jl    noSJIS1
  834.     cmp    al,9fh
  835.     jle    yesSJIS1
  836.     cmp    al,0e0h
  837.     jl    noSJIS1
  838.     cmp    al,0fch
  839.     jle    yesSJIS1
  840. noSJIS1:
  841.     clc
  842.     ret
  843. yesSJIS1:
  844.     stc
  845.     ret
  846. isSJIS1    endp
  847.  
  848. ;
  849. ; isSJIS2 : check if the content of AL is SJIS2 code and
  850. ;           if it is returns with CF set, otherwise CF cleared.
  851. ;
  852. isSJIS2    proc near
  853.     cmp    al,40h
  854.     jl    noSJIS2
  855.     cmp    al,7eh
  856.     jle    yesSJIS2
  857.     cmp    al,80h
  858.     jl    noSJIS2
  859. yesSJIS2:
  860.     stc
  861.     ret
  862. noSJIS2:
  863.     clc
  864.     ret
  865. isSJIS2    endp
  866.  
  867. ;
  868. ; soft font backing store access routines
  869. ;
  870.  
  871. ;
  872. ; void fillVRAM(at, num, data, attrib)
  873. ; u_short at;        address to fill
  874. ; u_short num;        number to fill
  875. ; u_short data;        fill data
  876. ; u_short attrib;    fill attribute
  877. ;
  878. ; put 'num' 'data's at 'at' and put num 'attrib's at attribute area
  879. ;
  880.     public _fillVRAM
  881. _fillVRAM proc    far
  882.     push    bp
  883.     mov    bp,sp
  884.     push    cx
  885.     push    di
  886.     push    es
  887.     mov    ax,[6+bp]
  888.     mov    di,ax            ; di := address
  889.     mov    ax,_vramSegment
  890.     mov    es,ax            ; es := VRAM segment
  891.     mov    al,[10+bp]        ; al := data to fill
  892.     mov    ah,[12+bp]        ; ah := attribute
  893.     mov    cx,[8+bp]        ; cx := fill words
  894.     rep    stosw            ; fill char
  895.     pop    es
  896.     pop    di
  897.     pop    cx
  898.     pop    bp
  899.     ret
  900. _fillVRAM endp
  901.  
  902. ;
  903. ; void moveForward(to, from, num, attribFlag)
  904. ; u_short to;        destination address
  905. ; u_short from;        source address
  906. ; u_short num;        words to move
  907. ; int attribFlag;    move attribute too (no meaning)
  908. ;
  909. ; move char and attribute 'from' 'to' 'num' chars
  910. ;  direction is from high address to low address
  911. ; this procedure is used for deleteLine()
  912. ;
  913. ; note: rep mov   
  914. ;        ds,es    vram segment
  915. ;        cx        count
  916. ;        di        destination address
  917. ;        si        source address
  918. ;
  919.     public    _moveForward
  920. _moveForward proc    far
  921.     push    bp
  922.     mov    bp,sp
  923.     push    cx
  924.     push    si
  925.     push    di
  926.     push    ds
  927.     push    es
  928.     mov    cx,[10+bp]        ; cx := count
  929.     mov    ax,[8+bp]
  930.     mov    si,ax            ; si := from
  931.     mov    ax,[6+bp]
  932.     mov    di,ax            ; di := to
  933.     cld                ; direction is forward
  934.     mov    ax,_vramSegment
  935.     mov    ds,ax
  936.     mov    es,ax            ; es := ds := vram segment
  937.     rep    movsw            ; move char
  938.     pop    es
  939.     pop    ds
  940.     pop    di
  941.     pop    si
  942.     pop    cx
  943.     pop    bp
  944.     ret    
  945. _moveForward endp
  946.  
  947. ;
  948. ; void moveBackward(to, from, num, attribFlag)
  949. ; u_short to;        destination address
  950. ; u_short from;        source address
  951. ; u_short num;        number of words to move
  952. ; int attribFlag;    move attribute too (no meaning)
  953. ;
  954. ; move char and attribute 'from' 'to' 'num' chars
  955. ;  direction is low address to high address
  956. ; this procedure is used in insertLine()
  957. ;
  958.     public    _moveBackward
  959. _moveBackward proc far
  960.     push    bp
  961.     mov    bp,sp
  962.     push    cx
  963.     push    si
  964.     push    di
  965.     push    ds
  966.     push    es
  967.     mov    cx,[10+bp]
  968.     shl    cx,1            ; cx := count * 2
  969.     mov    ax,[8+bp]
  970.     mov    si,ax            ; si := from
  971.     add    si,cx            ; si := from + count (last word + 2)
  972.     sub    si,2            ; si := last word
  973.     mov    ax,[6+bp]
  974.     mov    di,ax            ; di := to
  975.     add    di,cx            ; di := to + count (last word + 2)
  976.     sub    di,2            ; di := last word
  977.     mov    cx,[10+bp]        ; cx := words to move
  978.     mov    ax,_vramSegment
  979.     mov    ds,ax
  980.     mov    es,ax            ; es := ds := vram segment
  981.     std                ; direction is decrimental
  982.     rep    movsw            ; move char
  983.     cld
  984.     pop    es
  985.     pop    ds
  986.     pop    di
  987.     pop    si
  988.     pop    cx
  989.     pop    bp
  990.     ret    
  991. _moveBackward endp
  992.      
  993. ;
  994. ; void moveForByte(to, from, num)
  995. ; u_short to;        destination address
  996. ; u_short from;        source address
  997. ; u_short num;        words to move
  998. ;
  999. ; move memory in GRAM 'from' 'to' 'num' bytes
  1000. ;  direction is from high address to low address
  1001. ; this procedure is used for softFontDeleteChar()
  1002. ;
  1003. ; note: rep mov   
  1004. ;        ds,es    vram segment
  1005. ;        cx        count
  1006. ;        di        destination address
  1007. ;        si        source address
  1008. ;
  1009.     public    _moveForByte
  1010. _moveForByte proc far
  1011.     push    bp
  1012.     mov    bp,sp
  1013.     push    cx
  1014.     push    si
  1015.     push    di
  1016.     push    ds
  1017.     push    es
  1018.     mov    cx,[10+bp]        ; cx := count
  1019.     mov    ax,[8+bp]
  1020.     mov    si,ax            ; si := from
  1021.     mov    ax,[6+bp]
  1022.     mov    di,ax            ; di := to
  1023.     cld                ; direction is forward
  1024.     mov    ax,_gvramSegment
  1025.     mov    ds,ax
  1026.     mov    es,ax            ; es := ds := GVRAM segment
  1027.     rep    movsb            ; move char
  1028.     pop    es
  1029.     pop    ds
  1030.     pop    di
  1031.     pop    si
  1032.     pop    cx
  1033.     pop    bp
  1034.     ret    
  1035. _moveForByte endp
  1036.  
  1037. ;
  1038. ; void moveBackByte(to, from, num)
  1039. ; u_short to;        destination address
  1040. ; u_short from;        source address
  1041. ; u_short num;        number of bytes to move
  1042. ;
  1043. ; move GRAM memory 'from' 'to' 'num' bytes
  1044. ;  direction is low address to high address
  1045. ; this procedure is used in softFontInsertChar()
  1046. ;
  1047.     public    _moveBackByte
  1048. _moveBackByte proc far
  1049.     push    bp
  1050.     mov        bp,sp
  1051.     push    cx
  1052.     push    si
  1053.     push    di
  1054.     push    ds
  1055.     push    es
  1056.     mov    cx,[10+bp]
  1057.     mov    ax,[8+bp]
  1058.     mov    si,ax            ; si := from
  1059.     add    si,cx            ; si := from + count (last byte + 1)
  1060.     sub    si,1            ; si := last word
  1061.     mov    ax,[6+bp]
  1062.     mov    di,ax            ; di := to
  1063.     add    di,cx            ; di := to + count (last byte + 1)
  1064.     sub    di,1            ; di := last byte
  1065.     mov    cx,[10+bp]        ; cx := bytes to move
  1066.     mov    ax,_gvramSegment
  1067.     mov    ds,ax
  1068.     mov    es,ax            ; es := ds := GVRAM segment
  1069.     std                    ; direction is decrimental
  1070.     rep    movsb            ; move char
  1071.     cld
  1072.     pop    es
  1073.     pop    ds
  1074.     pop    di
  1075.     pop    si
  1076.     pop    cx
  1077.     pop    bp
  1078.     ret    
  1079. _moveBackByte endp
  1080.  
  1081. _TEXT   ends
  1082.     end
  1083.