home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / CONTRSRC.ZIP / SRC / TYPEONE / ANSI.ASM next >
Encoding:
Assembly Source File  |  1994-11-09  |  14.7 KB  |  444 lines

  1. ;*******************************************
  2. ; ANSI-PUT (C) 1994 Type One / TFL-TDV Prod.
  3. ;*******************************************
  4.  
  5. ;-----------------------------------------
  6. ; Déclaration modèle mémoire
  7. .386
  8. ANS_TEXT  SEGMENT DWORD PUBLIC USE16 'CODE'
  9.           ASSUME CS:ANS_TEXT,DS:ANS_DAT
  10. ANS_TEXT  ENDS
  11. ANS_DAT   SEGMENT DWORD PRIVATE USE16 'FAR_DATA'
  12. ANS_DAT   ENDS
  13. ;-----------------------------------------
  14.  
  15. ANS_DAT SEGMENT 
  16.  
  17.        INCLUDE pa2.inc  ; ANSI P.A. BBS II
  18.  
  19. CoulSize EQU 375*4
  20. CoulSeg WORD ?   ; ptr sur segment gradiant
  21.  
  22. ANS_DAT ENDS
  23.  
  24. ANS_TEXT SEGMENT
  25.  
  26.      EXTRN _WaitVBL: FAR
  27.      EXTRN _WaitHBL: FAR
  28.      PUBLIC _PutANSI
  29.  
  30. ;---- MACROs ----
  31.  
  32. HSYNC MACRO
  33.       call _WaitHBL
  34.       ENDM
  35.  
  36. VSYNC MACRO
  37.       call _WaitVbl
  38.       ENDM
  39.  
  40. STARTUP MACRO
  41.         mov ax,ANS_DAT
  42.         mov ds,ax
  43.         ENDM
  44.  
  45. MPUSH   MACRO reg1:REQ,reg2:VARARG   ; Vive Y.Roggeman/Greg & ses Macros
  46.         push reg1                    ; recursives !!!!!!! yahouuuuu !!!
  47.         IFNB <reg2>
  48.         MPUSH reg2
  49.         ENDIF
  50.         ENDM
  51.  
  52. MPOP    MACRO reg1:REQ,reg2:VARARG   ; bis bis !!!
  53.         IFNB <reg2>                  ; type brol = record....
  54.         MPOP reg2                    ; donc ça fait 20 bytes !!!
  55.         ENDIF                        ; donc 1 word ....
  56.         pop reg1                     ; brol je dis struct !!!
  57.         ENDM
  58.  
  59. ;---------------------- INIT ------------------------------------------
  60.  
  61. _PutANSI PROC FAR
  62.  
  63.          push    bp
  64.          mov     bp,sp
  65.          pushad
  66.          MPUSH   ds,es,fs,gs
  67.  
  68.          STARTUP
  69.  
  70.          cli
  71.  
  72.          mov     al,3                 ; Mode Texte 80x25
  73.          xor     ah,ah
  74.          int     10h
  75.          mov     ax,1112h             ; fonte 8x8
  76.          xor     bl,bl
  77.          int     10h
  78.          mov     ah,01h               ; Définit Curseur blanc...
  79.          mov     cx,0ff00h
  80.          int     10h
  81.  
  82.          mov     ah,48h                ; MALLOC
  83.          mov     bx,(CoulSize SHR 4)+1 ; memory requested
  84.          int     21h
  85.          mov     CoulSeg,ax            ; Segment address returned
  86.  
  87.          call    InitAnsiCol           ; genere gradiant
  88.  
  89.          mov     cx,20                 ; pause
  90. @@:      VSYNC 
  91.          loop    @B
  92.  
  93.          mov     si,OFFSET IMAGEDATA  ; Put ANSI Screen
  94.          mov     ax,0B800h
  95.          mov     es,ax
  96.          xor     di,di
  97.          xor     eax,eax
  98.          mov     cx,80*50/2           ; !!!!! Fuck TIME !!!!!
  99.          rep     stosd                ; arf arf, bien fait SAM !!!
  100.          xor     di,di
  101.          mov     cx,IMAGEDATA_LENGTH
  102.          call    UNCRUNCH
  103.  
  104.          push    ds
  105.          mov     ax,CoulSeg          ; segment couleur
  106.          mov     ds,ax
  107.  
  108. Ansi:    VSYNC
  109.          xor     si,si               ; begin of gradiant
  110.          mov     dx,3dah
  111.          mov     cx,56-32
  112. @@:      HSYNC                       ; on passe le logo.....
  113.          dec     cx
  114.          jnz     @B  
  115.          mov     cx,343+32
  116. @@:    ;  HSYNC                       ; dégradé sur coordonnées
  117.          
  118. ; cf Wizard/IMPCDA :-)
  119.          
  120.          mov     dx,3dah
  121. Wizard1: in      al,dx
  122.          test    al,1
  123.          jnz     Wizard1
  124.  
  125.          mov     dl,0c8h
  126.          outsw
  127.          inc     dl
  128.          outsb                        ; don't poke the last component yet !!!!
  129.  
  130.          mov     dl,0dah
  131. Wizard2: in      al,dx
  132.          test    al,1
  133.          jz      Wizard2  
  134.  
  135.          mov     dl,0c9h
  136.          outsb                        ; last component !!!!! 
  137.          dec     cx
  138.          jnz     @B
  139.  
  140.          in      al,60h              ; EXIT ?
  141.          cmp     al,39h              ; Space Bar ...
  142.          je      @F
  143.          cmp     al,1                ; Escape ...
  144.          jne     Ansi
  145.  
  146. @@:      mov     ax,40h              ; !!! Vider buffer clavier !!! ;-)
  147.          mov     es,ax
  148.          mov     ax,es:[001ah]
  149.          mov     es:[001ch],ax
  150.  
  151.          pop     ds
  152.  
  153.          sti
  154.  
  155.          mov     ax,CoulSeg            ; segment to free
  156.          mov     es,ax
  157.          mov     ah,49h                ; MFREE
  158.          int     21h
  159.  
  160.          MPOP    ds,es,fs,gs
  161.          popad
  162.          nop
  163.          leave
  164.  
  165.          retf
  166.  
  167. _PutANSI ENDP
  168.  
  169. InitAnsiCol PROC NEAR
  170.  
  171.        MPUSH     eax,cx,bx,di,es
  172.  
  173.        mov       ax,CoulSeg
  174.        mov       es,ax
  175.  
  176.        xor       di,di
  177.        xor       bl,bl
  178.  
  179.        mov       cx,62
  180. @@:    mov       WORD PTR es:[di],2            ; i = 0
  181.        mov       WORD PTR es:[di+4],2          ; REPT 62
  182.        mov       WORD PTR es:[di+8],2          ; db 2,0,i/2,i
  183.        mov       BYTE PTR es:[di+3],bl         ; db 2,0,i/2,i+1
  184.        mov       BYTE PTR es:[di+11],bl        ; db 2,0,i/2,i
  185.        mov       al,bl                         ; i=i+1
  186.        inc       al                            ; ENDM
  187.        mov       BYTE PTR es:[di+7],al
  188.        mov       al,bl
  189.        shr       al,1
  190.        mov       BYTE PTR es:[di+2],al
  191.        mov       BYTE PTR es:[di+6],al
  192.        mov       BYTE PTR es:[di+10],al
  193.        add       di,3*4
  194.        inc       bl
  195.        loop      @B
  196.  
  197.        xor       eax,eax                       ; i = 0
  198.        mov       cx,63                         ; REPT 63
  199. @@:    stosd                                   ; db 0,i,0,0
  200.        add       eax,100h                      ; i=i+1
  201.        loop      @B                            ; ENDM
  202.  
  203.        mov       DWORD PTR es:[di],0           ; i = 0
  204.        mov       DWORD PTR es:[di+4],1 SHL 24  ; REPT 4
  205.        mov       DWORD PTR es:[di+8],2 SHL 24  ; db 0,0,0,i
  206.        mov       DWORD PTR es:[di+12],3 SHL 24 ; i=i+1
  207.        add       di,4*4                        ; ENDM
  208.  
  209.        mov       eax,4 SHL 24                  ; REPT 12
  210.        mov       cx,12                         ; db 0,0,0,i
  211. @@:    stosd                                   ; db 0,0,0,i
  212.        stosd                                   ; db 0,0,0,i+1
  213.        add       eax,1 SHL 24                  ; i=i+2
  214.        stosd                                   ; ENDM
  215.        add       eax,1 SHL 24
  216.        loop      @B
  217.  
  218.        mov       cx,35                         ; REPT 35
  219. @@:    stosd                                   ; db 0,0,0,i
  220.        stosd                                   ; db 0,0,0,i
  221.        add       eax,1 SHL 24                  ; i=i+1
  222.        loop      @B                            ; ENDM
  223.  
  224.        sub       eax,1 SHL 24                  ; i=i-1
  225.  
  226.        mov       cx,5                          ; REPT 5
  227. @@:    stosd                                   ; db 0,0,0,i
  228.        stosd                                   ; db 0,0,0,i
  229.        stosd                                   ; db 0,0,0,i
  230.        loop      @B                            ; ENDM
  231.  
  232.        xor       eax,eax                       ; db 0,0,0,0
  233.        stosd
  234.  
  235.        MPOP      eax,cx,bx,di,es
  236.  
  237.        ret
  238.  
  239. InitAnsiCol ENDP
  240.  
  241. ;THEDRAW IMAGE UNCRUNCHING ROUTINE
  242. ;-----------------------------------------------------------------------------
  243. ;Compatible with MASM (Microsoft) and TASM v1.0 (Borland).  Minor format
  244. ;changes may be required for other assemblers.
  245. ;-----------------------------------------------------------------------------
  246. ;
  247. ;This is the routine for displaying crunched TheDraw image files.  The
  248. ;crunched data format is a simple custom protocol for reproducing any image.
  249. ;The control codes below decimal 32 are reserved for this function.
  250. ;Characters 32 and above are written directly to the destination address.
  251. ;
  252. ;The following shows the format of a control code sequence.  Please note that
  253. ;not all functions use the optional bytes <x> or <y>.
  254. ;
  255. ;Data Structure:  <current byte>[<x>[<y>]]
  256. ;
  257. ;   0..15 = New Foreground Color
  258. ;  16..23 = New Background Color
  259. ;      24 = Go down to next line, return to same horizontal position as when
  260. ;           routine was started (akin to a c/r).
  261. ;      25 = Displays <x> number of spaces.
  262. ;      26 = Displays <x> number of <y>.  Also used to display ANY characters
  263. ;           below #32.  This function is the only way to do this although it
  264. ;           uses three bytes.  Otherwise the code would be interpreted as
  265. ;           another command.
  266. ;      27 = Toggles on/off the foreground attribute blink flag.
  267. ;  28..31 = reserved
  268. ;
  269. ;----------------------------------------------------------------------------
  270. ;
  271. ;To use the routine, call the uncrunch procedure with the DS:SI register pair
  272. ;pointing to the TheDraw output listing, the ES:DI register pair pointing to
  273. ;the destination display address, and the length of the crunched image data
  274. ;in the CX register.  All modified registers are restored upon exiting.
  275. ;
  276. ;Assume an output file of a 40 character by 10 line block.  The label
  277. ;'IMAGEDATA' has been added for referencing purposes. ie:
  278. ;
  279. ;
  280. ;     ;TheDraw Assembler Crunched Screen Image
  281. ;     IMAGEDATA_WIDTH EQU 40
  282. ;     IMAGEDATA_DEPTH EQU 10
  283. ;     IMAGEDATA_LENGTH EQU 467
  284. ;     IMAGEDATA LABEL BYTE
  285. ;                DB      ...list of image bytes here...
  286. ;
  287. ;
  288. ;The following assembly language code could then be used to display the
  289. ;40x10 block on the screen with:
  290. ;
  291. ;                MOV     SI,offset IMAGEDATA
  292. ;                MOV     AX,0B800h
  293. ;                MOV     ES,AX
  294. ;                MOV     DI,34*2 + 5*160-162
  295. ;                MOV     CX,IMAGEDATA_LENGTH
  296. ;                CALL    UNCRUNCH
  297. ;
  298. ;The data segment (DS register) is assumed to point at the segment ImageData
  299. ;resides in.   The ES:DI register pair points at position (34,5) on the color
  300. ;graphics adapter screen, calculated as an offset from the start of the screen.
  301. ;Monochrome card users, replace the 0B800h with 0B000h.
  302. ;
  303. ;The original horizontal starting offset is remembered by the uncrunch routine.
  304. ;The offset is restored upon moving down to the next line.  This permits a
  305. ;block to be displayed correctly anywhere on the screen.  ie:
  306. ;
  307. ;              ┌─ horizontal starting offset
  308. ;              V
  309. ;  +-------------------------------------------------+
  310. ;  |                                                 |
  311. ;  |                                                 | <- Assume this
  312. ;  |                                                 |    is the video
  313. ;  |           ┌─────────────────────┐               |    display.
  314. ;  |           │█████████████████████│               |
  315. ;  |           │█████████████████████│               |
  316. ;  |           │██ ImageData block ██│               |
  317. ;  |           │█████████████████████│               |
  318. ;  |           │█████████████████████│               |
  319. ;  |           │█████████████████████│               |
  320. ;  |           └─────────────────────┘               |
  321. ;  |                                                 |
  322. ;  |                                                 |
  323. ;  |                                                 |
  324. ;  +-------------------------------------------------+
  325. ;
  326. ;
  327. ;To display the block in the lower-right corner, change the DI assignment to:
  328. ;
  329. ;                MOV     DI,40*2 + 15*160-162
  330. ;
  331. ;The block is 40 characters wide by 10 lines deep.  To display on a 80 by 25
  332. ;screen, we must display the block at coordinates (40,15).  To display in
  333. ;the upper-left screen corner use:
  334. ;
  335. ;                MOV     SI,offset IMAGEDATA
  336. ;                MOV     AX,0B800H
  337. ;                MOV     ES,AX
  338. ;                MOV     DI,1*2 + 1*160-162       ;coordinates 1,1
  339. ;                MOV     CX,IMAGEDATA_LENGTH
  340. ;                CALL    UNCRUNCH
  341. ;
  342. ;Notice in both cases only the offset address changed.  Note the latter case
  343. ;is also used for displaying a full screen image (which in general are
  344. ;always displayed at coordinate 1,1).
  345. ;
  346. ;----------------------------------------------------------------------------
  347. ;
  348. ;That's it!  The routine was designed for easy use and understanding; however,
  349. ;for some people the best way is to experiment.  Create a program using the
  350. ;above examples, perhaps with a 40x10 block (or any size).  Good luck!
  351. ;
  352.  
  353. UNCRUNCH PROC NEAR
  354. ;
  355. ;Parameters Required:
  356. ;  DS:SI  Crunched image source pointer.
  357. ;  ES:DI  Display address pointer.
  358. ;  CX     Length of crunched image source data.
  359. ;
  360.        PUSH    SI                      ;Save registers.
  361.        PUSH    DI
  362.        PUSH    AX
  363.        PUSH    BX
  364.        PUSH    CX
  365.        PUSH    DX
  366.        JCXZ    Done
  367.  
  368.        MOV     DX,DI                   ;Save X coordinate for later.
  369.        XOR     AX,AX                   ;Set Current attributes.
  370.        CLD
  371.  
  372. LOOPA: LODSB                           ;Get next character.
  373.        CMP     AL,32                   ;If a control character, jump.
  374.        JC      ForeGround
  375.        STOSW                           ;Save letter on screen.
  376. Next:  LOOP    LOOPA
  377.        JMP     Short Done
  378.  
  379. ForeGround:
  380.        CMP     AL,16                   ;If less than 16, then change the
  381.        JNC     BackGround              ;foreground color.  Otherwise jump.
  382.        AND     AH,0F0H                 ;Strip off old foreground.
  383.        OR      AH,AL
  384.        JMP     Next
  385.  
  386. BackGround:
  387.        CMP     AL,24                   ;If less than 24, then change the
  388.        JZ      NextLine                ;background color.  If exactly 24,
  389.        JNC     FlashBitToggle          ;then jump down to next line.
  390.        SUB     AL,16                   ;Otherwise jump to multiple output
  391.        ADD     AL,AL                   ;routines.
  392.        ADD     AL,AL
  393.        ADD     AL,AL
  394.        ADD     AL,AL
  395.        AND     AH,8FH                  ;Strip off old background.
  396.        OR      AH,AL
  397.        JMP     Next
  398.  
  399. NextLine:
  400.        ADD     DX,160                  ;If equal to 24,
  401.        MOV     DI,DX                   ;then jump down to
  402.        JMP     Next                    ;the next line.
  403.  
  404. FlashBitToggle:
  405.        CMP     AL,27                   ;Does user want to toggle the blink
  406.        JC      MultiOutput             ;attribute?
  407.        JNZ     Next
  408.        XOR     AH,128                  ;Done.
  409.        JMP     Next
  410.  
  411. MultiOutput:
  412.        CMP     AL,25                   ;Set Z flag if multi-space output.
  413.        MOV     BX,CX                   ;Save main counter.
  414.        LODSB                           ;Get count of number of times
  415.        MOV     CL,AL                   ;to display character.
  416.        MOV     AL,32
  417.        JZ      StartOutput             ;Jump here if displaying spaces.
  418.        LODSB                           ;Otherwise get character to use.
  419.        DEC     BX                      ;Adjust main counter.
  420.  
  421. StartOutput:
  422.        XOR     CH,CH
  423.        INC     CX
  424.        REP STOSW
  425.        MOV     CX,BX
  426.        DEC     CX                      ;Adjust main counter.
  427.        LOOPNZ  LOOPA                   ;Loop if anything else to do...
  428.  
  429. Done:  POP     DX                      ;Restore registers.
  430.        POP     CX
  431.        POP     BX
  432.        POP     AX
  433.        POP     DI
  434.        POP     SI
  435.        RET
  436.  
  437. UNCRUNCH ENDP
  438.  
  439. ANS_TEXT ENDS
  440.  
  441.        END
  442.  
  443.  
  444.