home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-386-Vol-2of3.iso / b / bbl-v-1.zip / TSTBBL.ASM < prev    next >
Assembly Source File  |  1992-07-29  |  12KB  |  455 lines

  1. page    58,132
  2. title    TestBBL    Test algorithms for Big Block Letter device driver
  3.  
  4. Stak    SEGMENT PARA STACK 'STACK'
  5.     DB    64 DUP ('STACK   ')
  6. Stak    ENDS
  7.  
  8.  
  9. CharWidth    EQU    08h        ;width of chars in pixels
  10. CharHeight    EQU    08h        ;height of chars in pixels
  11. DispChar    EQU    219        ;solid block to construct display
  12. CharAttr    EQU    0fh        ;attribute of char to display
  13.  
  14. BELChar    EQU    07h
  15. BSChar    EQU    08h
  16. HTChar    EQU    09h
  17. LFChar    EQU    0ah
  18. VTChar    EQU    0bh
  19. FFChar    EQU    0ch
  20. CRChar    EQU    0dh
  21. SOChar    EQU    0eh
  22. SIChar    EQU    0fh
  23.  
  24. S$Init    EQU    0        ;State 0 ==> Initial
  25. S$VP    EQU    1        ;State 1 ==> Vertical position
  26. S$HP    EQU    2        ;State 2 ==> Horizontal position
  27. S$SM    EQU    3        ;State 3 ==> Set Mode (BBL display mode)
  28.  
  29. TT$NOND    EQU    0        ;Token type 0 ==> non-operation, non-digit
  30. TT$Dig    EQU    1        ;Token type 1 ==> digit
  31. TT$CM    EQU    2        ;Token type 2 ==> cursor movement
  32. TT$HP    EQU    3        ;Token type 3 ==> horizontal position
  33. TT$VP    EQU    4        ;Token type 4 ==> vertical position
  34. TT$SM    EQU    5        ;Token type 5 ==> set mode
  35. NumTokTyp EQU    6
  36.  
  37.  
  38. ModeDesc    STRUC
  39.     Mag        db    ?    ;magnification for bit pattern
  40.     MaxRows        db    ?    ;max rows with this mode
  41.     MaxCols        db    ?    ;max cols with this mode
  42.     RowOff        db    ?    ;row offset on phys screen 
  43.     ColOff        db    ?    ;col offset on phys screen
  44. ModeDesc    ENDS
  45.  
  46. StateDesc     STRUC
  47.     ActionProc    DW    ?    ;action this token invokes in this state
  48.     NextState    DB    ?    ;next state
  49. StateDesc    ENDS
  50.  
  51. ;    The token classes are stored in the table "TC", and the
  52. ;    default is TT$NOND, non-op, non-digit.
  53. ;    We build the token table exceptions by processing a table
  54. ;    of exceptions, labeled with the characters (tokens), into the
  55. ;    TC table, addressed by char value.  First, define
  56. ;    the structure we use to build the exceptions table.
  57.  
  58.  
  59. TokDef STRUC
  60.     char    DB    ?    ;character being classified ("typed")
  61.     ctype    DB    ?    ;type of that char
  62. TokDef ENDS
  63.  
  64.  
  65. DSEG    SEGMENT PARA PUBLIC 'DATA'
  66.  
  67. strng    db    "01.23",0dh,"45.67",08h,"8",0ch,"abc",0ah,"def"
  68.     db    0ah,0dh,"ghi",0ah,0dh,"jkl",0
  69.  
  70. CurXY    DW    0            ;row,,col of cur virtual position
  71. CurPhys    DW    0            ;row,,col of cur phys position
  72. CurMode    db    1            ;default to mode 1 on startup
  73. CurChar    db    0            ;space for char being written
  74. CurPage    db    0            ;current video page on entry
  75. CurState db    0            ;current state of input char processing
  76.  
  77. Mode    ModeDesc    3 DUP(<1,3,10,0,0>,<2,1,5,4,0>,<3,1,3,0,0>)
  78.                     ;describe layout for each of
  79.                     ; the three display sizes
  80. BitMask    dw    0
  81. ft_ptr    dd    0
  82.  
  83.  
  84. ;    The following table describes the actions and next-states
  85. ;    that result when a token is given to BBL.  There are four 
  86. ;    states (rows) and six token types (columns) in the table 
  87. ;    (in version 1).  The table is addressed as a matrix ... 
  88. ;    State[Current_State,Type_of_Incoming_Token], so the number of
  89. ;    token types is needed to compute the address for a given
  90. ;    (state, toktype) entry.
  91.  
  92. States    StateDesc    <ShowChar,S$Init>,<ShowChar,S$Init>,<Move,S$Init> ;state 0
  93.     StateDesc        <Noop,S$HP>,<Noop,S$VP>,<Noop,S$SM>    
  94.     StateDesc    <Beep,S$Init>,<VertPos,S$Init>,<Beep,S$Init>    ;state 1
  95.     StateDesc        <Beep,S$Init>,<Beep,S$Init>,<Beep,S$Init>
  96.     StateDesc    <Beep,S$Init>,<HorPos,S$Init>,<Beep,S$Init>    ;state 2
  97.     StateDesc        <Beep,S$Init>,<Beep,S$Init>,<Beep,S$Init>
  98.     StateDesc    <Beep,S$Init>,<SetMode,S$Init>,<Beep,S$Init>    ;state 3
  99.     StateDesc        <Beep,S$Init>,<Beep,S$Init>,<Beep,S$Init>
  100.  
  101. ;    Now set up the table with default values
  102. ;    Bytes contain token type of chars <even,,odd>, with token type
  103. ;    stored as a 4-bit nibble
  104.  
  105. TC    db    128 dup(0)    ; <TT$NOND<<4 + TT$NOND> ))
  106.  
  107. ;    Next define the exceptions ... these all happen at assembly time
  108.  
  109. NDT    TokDef    <FFChar,TT$CM>
  110.     irp    x,<'0','1','2','3','4','5','6','7','8','9'>
  111.     TokDef    <x,TT$Dig>        
  112.     endm
  113.     TokDef    <BSCHar,TT$CM>
  114.     TokDef    <LFChar,TT$CM>
  115.     TokDef    <CRChar,TT$CM>
  116.     TokDef    <HTChar,TT$HP>
  117.     TokDef    <VTChar,TT$VP>
  118.     TokDef    <SOChar,TT$SM>
  119. NumTokDefs = ($-NDT)/SIZE TokDef
  120.  
  121. DSEG    ENDS
  122.  
  123. CSeg    SEGMENT    PARA PUBLIC 'CODE'
  124.     ASSUME    CS:CSeg,DS:DSeg, SS:Stak
  125.  
  126. BLDemo     PROC    FAR
  127.  
  128.     push    ds
  129.     sub    ax,ax
  130.     push    ax
  131.     mov    ax,dseg
  132.     mov    ds,ax
  133.  
  134.     call    FillTT            ;init token table with non-defaults
  135.     call    SetFontPtr        ;point to 8x8 font
  136.  
  137.     lea    si,strng        ;point to string
  138. Lup:    mov    dl,[si]            ;get next char
  139.     inc    si            ;  and prepare for following
  140.     cmp    dl,0            ;is it the NULL?
  141.      je    Done            ;yes ... done
  142.     push    si            ;save the only thing we care about
  143.     call    ProcessChar        ;no ... process it
  144.     pop    si
  145.     jmp    Lup
  146. Done:    ret
  147. BLDemo    endp
  148.  
  149. SetFontPtr PROC    NEAR
  150.     mov    ax,1130h        ;get char font address
  151.     mov    bh,03h
  152.     int    10h
  153.     mov    word ptr ft_ptr,bp    ;save seg:off
  154.     mov    word ptr ft_ptr+2,es
  155.     ret
  156. SetFontPtr    ENDP
  157.  
  158. ProcessChar PROC NEAR
  159. ;    Process the character in dl
  160. ;    Preserve nothing but leave char in dl and pointer
  161. ;     struc describing this mode upon dispatch
  162.     mov    al,CurMode        ; for this mode
  163.     mov    bl,SIZE ModeDesc    ;size of mode record
  164.     mul    bl            
  165.     lea    si,Mode
  166.     add    si,ax            ;si now points to the right block
  167.  
  168.     mov    CurChar,dl        ;keep this char
  169.     xor    bh,bh            ;clear high byte for addressing
  170.     mov    bl,dl            ;get char & compute token-class
  171.     shr    bl,1            ; table address
  172.     mov    ch,TC[bx]        ;get the byte containing the class
  173.      jc    TCxtr            ;odd-valued chars are in right nibble
  174.     mov    cl,4
  175.     shr    ch,cl
  176. TCxtr:    and    ch,0fh            ;mask out that nibble
  177.                     ;ch contains the token class of this char
  178.     xor    ax,ax            ;now compute the addr of the state-table
  179.     mov    al,CurState        ; entry for the current state
  180.     mov    bl,NumTokTyp        ; matrix address is
  181.     mul    bl            ; States + (CurState*NumTokTypes
  182.     add    al,ch            ;            + TokenType) 
  183.     mov    bl,SIZE StateDesc
  184.     mul    bl            ;  [adjusted for size of entries]
  185.     mov    bx,ax
  186.     lea    bx,States[bx]
  187.     mov    al,[bx].NextState    ;get next state from this transition
  188.     mov    CurState,al
  189.     mov    bx,[bx].ActionProc
  190.     jmp    bx            ;and act on this token/state
  191.                     ; dl still contains input char
  192.  
  193. ProcessChar ENDP
  194.  
  195.  
  196. Beep    PROC    NEAR
  197.     mov    ax,0e07h        ;write a bell in teletype mode
  198.     xor    bx,bx
  199.     int    10h
  200.     ret
  201. Beep    ENDP
  202.  
  203. Noop    PROC    NEAR
  204.     ret
  205. Noop    ENDP
  206.  
  207. VertPos    PROC    NEAR
  208.     call    Digit            ;convert char in dl to integer in dl
  209.     mov    cl,[si].MaxRows    
  210.     cmp    dl,cl            ;too large for this mode?
  211.      jle    VPSet            ; no ..
  212.     xchg    dl,cl            ; yes ... set to max
  213. VPSet:    mov    BYTE PTR CurXY+1,dl    ;store into row-byte of position word
  214.     ret
  215. VertPos    ENDP
  216.  
  217. HorPos    PROC    NEAR
  218.     call    Digit            ;convert char in dl to integer in dl
  219.     mov    cl,[si].MaxCols
  220.     cmp    dl,cl            ;too large for this mode?
  221.      jle    HPSet            ; no ...
  222.     xchg    dl,cl            ; yes ... set to max
  223. HPSet:    mov    BYTE PTR CurXY,dl    ;store into col-byte of position word
  224.     ret
  225. HorPos    ENDP
  226.  
  227. SetMode    PROC    NEAR
  228.     call    Digit            ;convert char in dl to integer in dl
  229.     mov    CurMode,dl        ;store into current mode byte
  230.     call    FF            ;clear screen & reset CurXY
  231.     ret
  232. SetMode    ENDP
  233.  
  234. Digit    PROC    NEAR
  235.     sub    dl,'0'
  236.     ret
  237. Digit    ENDP
  238.  
  239. Move    PROC    NEAR
  240. ; Assumptions:
  241. ; on entry, dl contains character to display
  242. ; no regs will have been preserved upon exit
  243. ; si points to struc that describes the display parameters in this mode
  244. ; Preserves: nothing
  245.  
  246.     cmp    dl,CRChar        ;is CurChar a CR?
  247.      je    CR            ; yes
  248.     cmp    dl,LFChar        ;no, is it a LF?
  249.      je    LF            ; yes
  250.     cmp    dl,BSChar        ;no, is it a BackSpace?
  251.      je    BS            ; yes
  252.     cmp    dl,FFChar        ;no, is it a FF?
  253.      jne    Beep            ; no -- beep & ignore
  254.  
  255.                     ;yes, do screen clear
  256. FF:    mov    ah,0fh            ;get current mode
  257.     int    10h            ; mode left in al
  258.     mov    ah,00h            ;where we use it now
  259.     int    10h            ;reset in same mode clears
  260.     xor    ax,ax            ;reset our virtual pointer
  261.     mov    CurXY,ax
  262.     ret
  263.  
  264. CR:    mov    ax,CurXY        ;reset pointer to col 0
  265.     xor    al,al
  266.     mov    CurXY,ax
  267.     ret
  268.  
  269. BS:    mov    ax,CurXY        ;decrement virtual col position by 1
  270.     dec    al
  271.     mov    CurXY,ax
  272.     ret
  273.  
  274. LF:    mov    dx,CurXY        ;inc virtual row if we can
  275.     inc    dh
  276.     cmp    dh,[si].MaxRows        ;can we?
  277.      jl    LFDone            ; yes! Done
  278.     call    ScrollUp        ;no -- scroll up screen
  279.     ret                ;note that we haven't changed CurXY
  280. LFDone:    mov    CurXY,dx        ;but we did here
  281.     ret
  282. ScrollUp:
  283.     mov    ch,[si].RowOff        ;rows down to top of scroll region
  284.     mov    cl,[si].ColOff        ;cols to left side of scroll region
  285.  
  286.     mov    al,[si].MaxRows        ;compute bottom addr of scroll region
  287.     xor    ah,ah
  288.     mov    bl,CharHeight
  289.     mul    bl
  290.     mov    bl,[si].mag
  291.     mul    bl
  292.     mov    dh,al
  293.     add    dh,ch            ;dh now has addr of last row of scroll reg
  294.  
  295.     mov    al,[si].MaxCols        ;compute right col of scroll reg
  296.     xor    ah,ah
  297.     mov    bl,CharWIdth
  298.     mul    bl
  299.     mov    bl,[si].mag
  300.     mul    bl
  301.     mov    dl,al
  302.     add    dl,cl            ;dl now has addr of las col of scroll reg
  303.  
  304.     mov    al,CharHeight        ;finally, compute scroll distance
  305.     xor    ah,ah
  306.     mov    bl,[si].Mag
  307.     mul    bl            ;al now has # rows to scroll
  308.     mov    bh,CharAttr
  309.     mov    ah,06h            ;function 6 scrolls up
  310.     int    10h            ;scroll that region
  311.     ret
  312. Move    ENDP
  313.  
  314. ShowChar PROC    NEAR
  315. ; Assumptions:
  316. ; si points to struc that describes the display parameters in this mode
  317. ; Preserves: nothing
  318.     mov    dx,CurXY        ;see if there's room on this line
  319.     cmp    dl,[si].MaxCols
  320.      jl    Proceed            ;yes, go on with it
  321.     call    CR            ;no, move back
  322.     call    LF            ; and down
  323.  
  324. Proceed:
  325.     mov    ah,0fh            ;get current video page
  326.     int    10h
  327.     xor    bl,bl            ;[hdt] zero for now 
  328.     mov    CurPage,bl        ;and save for future use
  329.  
  330.     mov    al,CurChar        ;now get pointer to our char bit pattern
  331.     mov    bl,CharWidth
  332.     mul    bl
  333.     les    bx,ft_ptr
  334.     add    bx,ax
  335.     mov    di,bx            ;es:di points to the pattern
  336.  
  337.      mov    dx,CurXY        ;compute phys row/col starting position
  338.     mov    al,dh            ;first, row position
  339.     mov    bl,CharHeight
  340.     mul    bl
  341.     mov    bl,[si].Mag
  342.     mul    bl
  343.     add    al,[si].RowOff
  344.     mov    dh,al            ;store back in our active pointer
  345.     mov    al,dl            ;now compute col position
  346.     mov    bl,CharWidth
  347.     mul    bl
  348.     mov    bl,[si].Mag
  349.     mul    bl
  350.     add    al,[si].ColOff
  351.     mov    dl,al            ;store col back into pointer
  352.  
  353.     mov    cx,CharHeight        ;set up counter to count down rows
  354.                     ;of char's pixel pattern
  355.  
  356. ; assumptions in this section:
  357. ; si points to descriptor block for this mode
  358. ; es:di points to next row of pixels for this character
  359. ; dx contains row,,col (dh,,dl) of PHYSICAL location to write next on screen
  360.  
  361. RowLoop:                ;loop over all the rows of the pattern
  362.     push    cx            ;save row counter
  363.                     ;get a word from the pattern ...
  364.     mov    bp,word ptr es:[di]    ; even if we use only 8 bits
  365.     add    di,CharWidth/8        ;and bump the pointer appropriately
  366.  
  367.     xor    cx,cx
  368.     mov    cl,si.[mag]        ;display each row "mag" times
  369.                     ;for magnification effect
  370. MagLoop:
  371.     push    cx            ;save magnification count
  372.                     ;# of screen rows written with this
  373.                     ; character pixel row
  374.     push    dx            ;save phys screen position
  375.  
  376.     mov    bx,0080h        ;starting mask for copying this row
  377.     mov    BitMask,bx
  378.  
  379.     mov    cx,CharWidth        ;set up counter to copy pixels
  380.  
  381. ColLoop:
  382.     push    cx            ;save column (pixel) counter
  383.  
  384.     mov    bh,CurPage        ;set position on page
  385.     mov    ah,02h            ; dx already points to position
  386.     int    10h
  387.  
  388.     mov    bx,BitMask        ;get the mask & check the char
  389.     test    bp,bx            ;now is the pixel bit on?
  390.      jnz    LoadBlock        ; yes
  391.     mov    al,' '            ;no ... write a blank
  392.     jmp    DispIt            ; go do it
  393. LoadBlock:
  394.     mov    al,DispChar        ;write the block char
  395. DispIt:    
  396.     ror    bx,1            ;ready to mask the next pixel
  397.     mov    BitMask,bx
  398.  
  399.                     ;write out the designated disp char
  400.     mov    ah,0Ah            ; al already has char to write
  401.     mov    bh,CurPage        ; to this video page
  402.     mov    bl,CharAttr        ; with appropriate video attribute
  403.     xor    cx,cx
  404.     mov    cl,[si].Mag        ; with appropriate magnification for
  405.     int    10h            ;  this BL mode
  406.  
  407.     add    dl,[si].Mag        ;update col position
  408.     pop    cx            ;retrieve our pixel-width counter
  409.     loop    ColLoop            ;and process next pixel, if any
  410.  
  411.     pop    dx            ;done with that row.  Restore phys
  412.     inc    dh            ; postion and update phys row
  413.     pop    cx            ;and repeat "mag" times
  414.     loop    MagLoop
  415.  
  416.     pop    cx            ;retrieve counter of # of rows of pattern
  417.     loop    RowLoop            ;and process next row of pattern
  418.     mov    cx,CurXY        ;note change in virtual col
  419.     inc    cl
  420.     mov    CurXY,cx
  421.     ret
  422.  
  423. ShowChar ENDP
  424.  
  425. ;    The following code gets executed once during startup to fill in
  426. ;    the non-default table values from the non-default token table 
  427.  
  428. FillTT    PROC    NEAR
  429.     mov    cx,NumTokDefs
  430.     xor    bx,bx
  431.     lea    si,NDT            ;point to the non-def token table
  432.  
  433. FillLoop:
  434.     mov    al,[si][bx].char    ;get char
  435.     mov    dl,[si][bx].ctype    ;and its type
  436.     shr    al,1            ;compute address of char in token class table
  437.     jc    StoreType        ;if char was even, goes to left half
  438.     shl    dx,1            ; of the byte we're ready to write
  439.     shl    dx,1
  440.     shl    dx,1
  441.     shl    dx,1
  442. StoreType:
  443.     xor    ah,ah
  444.     mov    di,ax            ;ready to point to char in TokenClass table
  445.     xor    BYTE PTR TC[di],dl
  446.     add    bx,SIZE TokDef
  447.     loop    FillLoop
  448.  
  449.     ret
  450. FILLTT    ENDP
  451.  
  452. CSeg    ENDS
  453.  
  454.     END    BLDemo
  455.