home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / CSAPE32.ARJ / SOURCE / OWLSCR / PCBUNRUN.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-02-03  |  3.1 KB  |  139 lines

  1. ; pcbunrun.asm
  2. ;
  3. ; 5/5/88 by Ted
  4. ;
  5. ; Splash-style image unrunner for OWL
  6. ; THIS FILE IS FOR LARGE-DATA MODELS ONLY
  7. ;
  8. ; OWL-PCA 1.2
  9. ; Copyright (c) 1988, 1989 Oakland Group Inc.
  10. ; ALL RIGHTS RESERVED
  11. ;
  12. ;------------------------REVISION HISTORY--------------------------------------;
  13. ;------------------------------------------------------------------------------;
  14. include    PCDECL.MAC
  15.  
  16.     PSEG
  17. ; ---------------------------------------------------------------------------- ;
  18. ; int bunrun(dest_addr, nbytes, runcode)
  19. ;
  20. ;    Unrun in place into max nbytes bytes at addr
  21. ;    firstrun and runsize describe the runned data
  22. ;    dest_addr is a doubleword in form seg, offset
  23. ;  - runcode is runsize and firstrun as lo and hi of long value
  24. ;  - returns outsize, -1 if overflow
  25.  
  26. pubproc    DIGPRIV bunrun <daddr, dptr, nbytes, runsize, firstrun>
  27.     push bp
  28.     mov  bp, sp
  29.     pushm <ds, es, si, di>
  30.  
  31.     lds si, [bp].daddr            ; reg. ds = saddr seg
  32.     les    di, [bp].daddr            ; reg. es = daddr seg
  33.     mov bx, [bp].firstrun
  34.  
  35. ; move runned stuff from soff to runstart = soff+nbytes - runsize
  36.     add di, [bp].nbytes
  37.      mov dx, di                ; dx = end of runbuf and outbuf
  38.     mov cx, [bp].runsize
  39.     sub di, cx
  40.     mov [bp].firstrun, di    ; firstrun is now runstart address
  41.  
  42.     push bx        ; save bx for later
  43.     push dx        ; save dx for later
  44.  
  45. ; di > si : negative move
  46.     add    si, cx        ; point si and di to end of area
  47.     dec    si
  48.     add    di, cx
  49.     dec    di
  50.  
  51.     std
  52.     shr cx, 1
  53.     jnc ndow
  54.     movsb
  55.     jcxz ndone
  56. ndow:
  57.     dec    si
  58.     dec    di
  59.     rep    movsw
  60. ndone:
  61.     cld
  62.  
  63.     pop  dx        ; restore end address of runbuf and outbuf
  64.     pop  bx        ; restore address of first run
  65.  
  66. ; set up si and di to start
  67.     mov si, [bp].firstrun
  68.     les    di, [bp].daddr            ; reg. es = daddr seg
  69.  
  70. NEWMOV:
  71.     cmp si, dx            ; see if we are done
  72.     jz done
  73.     cmp di, dx            ; see if we have overflowed
  74.     jae overflow
  75.  
  76. ; find count of bytes until next run and blast them out
  77.     mov cx, bx
  78.     cmp cx, -1
  79.     jne nosubs
  80.     mov cx, [bp].runsize    ; substitute buf end for next-run start
  81. nosubs:
  82.     add cx, [bp].firstrun    ; cx = nextrun - curpos
  83.     sub cx, si
  84.     jcxz NEWRUN
  85.  
  86. ; test for error of run too big
  87.     mov ax, dx
  88.     sub ax, di
  89.     cmp cx, ax
  90.     jbe okmov
  91.     mov cx, ax
  92.     jcxz overflow
  93. okmov:
  94.     rep movsb            ; blast out bytes until next run
  95.  
  96. NEWRUN:
  97.     mov ax, dx
  98.     sub ax, si
  99.     jz done                ; test for all done
  100.     cmp ax, 2            ; test for error of incomplete run code
  101.     jb abort            ; allow no next-run ptr because it's redundant
  102. ; load up run data
  103.     mov bx, ds:[si+2]    ; get next run ptr
  104.     mov cl, ds:[si+1]    ; get run count
  105.     mov ch, 0
  106.  
  107. ; test for error of run too big
  108.     mov ax, dx
  109.     sub ax, di
  110.     cmp cx, ax
  111.     jbe okrun
  112.     mov cx, ax
  113.     jcxz overflow
  114. okrun:
  115.     mov al, ds:[si]        ; get run byte
  116.     add si, 4
  117.  
  118.     rep stosb            ; blast out the run
  119.     jmp NEWMOV
  120.  
  121. overflow:
  122.     mov ax, -1
  123.     jmp short fini
  124. done:
  125. abort:
  126.     mov ax, di
  127.     les    di, [bp].daddr            ; reg. es = daddr seg
  128.     sub ax, di
  129. fini:
  130.     popm <di, si, es, ds>
  131.     pop    bp
  132.     ret
  133. endproc bunrun
  134. ; ---------------------------------------------------------------------------- ;
  135.     ENDPS
  136.     end
  137. ; ---------------------------------------------------------------------------- ;
  138.  
  139.