home *** CD-ROM | disk | FTP | other *** search
/ Sound, Music & MIDI Collection 2 / SMMVOL2.bin / PROG / BWSB120A.ZIP / UTIL / PIQ.ASM < prev    next >
Encoding:
Assembly Source File  |  1995-02-25  |  3.8 KB  |  104 lines

  1. ;Prefetch Instruction Queue (PIQ) Size Detection Routine
  2. ;Written by Zilym Limms/OTM. Copyright (c) 1995, Edward Schlunder
  3. ;
  4. ;Feel free to use this in anything you want (I have no idea what you
  5. ;*could* use it for, but oh well).. Just leave me credits if you do.
  6. ;
  7. ;While I've got your attention, check out some of my other programs:
  8. ;OmniPlayer - Multichannel digital music player for GUS, SB, SBPro, SB16, PAS
  9. ;BWSB       - Digital music and sound library for QB/PDS/TP/C/C++
  10. ;
  11. ;theory: this thing works on the fact that self modifying code
  12. ;        only modifies stuff in memory, and does not modify stuff already
  13. ;        loaded into the PIQ.
  14.  
  15. _codeseg segment
  16. assume cs:_codeseg
  17. org 100h
  18.  
  19. start:
  20.     mov     ax, ds                     ;get es pointing to this segment
  21.     mov     es, ax                     ;for the movsb
  22.  
  23.     mov     dx, offset header          ;display out little noise
  24.     mov     ah, 9h
  25.     int     21h
  26.  
  27.     cld                                ;make sure movsb goes the right direction
  28.     mov     dx, 1                      ;number of bytes in PIQ counter
  29. ;──────────────────────────────────────
  30. PIQLoop:
  31.     mov     si, offset STCIns          ;si=STC instruction table
  32.     mov     di, offset start1          ;offset into code
  33.     add     di, dx                     ;add byte number to test
  34.     mov     cx, 1                      ;make movsb only move one byte
  35.     clc                                ;clear the carry (our flag of PIQ end)
  36.     cli                                ;make sure IRQs don't reload the PIQ
  37.     jmp     start1                     ;clear PIQ clean
  38. align 16                               ;PIQ only works on paragraph aligned
  39. start1:                                ;Byte Number:
  40.     movsb                              ;1  (overwrite a NOP with STC)
  41. PIQ:db  63 dup (90h)                   ;tons of NOPs
  42.     sti                                ;reenable IRQs
  43.     jc      FoundSize
  44.  
  45.     mov     di, offset PIQ             ;Refill the NOP table with NOPs again
  46.     mov     al, 90h
  47.     mov     cx, 63
  48.     rep     stosb
  49.  
  50.     inc     dx                         ;Test the next size up
  51.     cmp     dx, 64                     ;are we at the limit?
  52.     jb      PIQLoop                    ;keep goin' if not..
  53.  
  54. NoFoundSize:
  55.     mov     dx, offset NoSize          ;display our error
  56.     mov     ah, 9h
  57.     int     21h
  58.     mov     ax, 4C01h                  ;exit to DOS, errorlevel=1
  59.     int     21h
  60.  
  61. FoundSize:
  62.     mov     cx, dx
  63.     mov     ah, 9
  64.     mov     dx, offset sizeis
  65.     int     21h
  66.  
  67.     mov     bx, cx
  68.     dec     bx
  69.     shl     bx, 1
  70.     add     bx, offset ascii
  71.     mov     byte ptr [bx+2], '$'
  72.     mov     dx, bx
  73.     mov     ah, 9
  74.     int     21h
  75.  
  76.     mov     ah, 9
  77.     mov     dx, offset bytes
  78.     int     21h
  79.  
  80.     mov     ax, 4C00h
  81.     int     21h
  82.  
  83. header      db      'Prefetch Instruction Queue Size Detection Routine',10,13
  84.             db      'Copyright (c) 1995, Edward Schlunder (zilym@hndymn.stat.com)',10,13
  85.             db      10, 13, '$'
  86. nosize      db      "PIQ size equal to or larger than 64 bytes$"
  87. sizeis      db      'PIQ size: $'
  88. bytes       db      ' byte(s)', 10, 13, '$'
  89.  
  90.  
  91. STCIns      db      32 dup (0F9h) ;this table is full of STC instructions
  92.  
  93. ascii       db      ' 1'        ; 1 or 0 byte PIQ (doesn't detect if 0 byte or not)
  94.             db      ' 2',' 3',' 4',' 5',' 6',' 7',' 8',' 9','10'
  95.             db      '11','12','13','14','15','16','17','18','19'
  96.             db      '20','21','22','23','24','25','26','27','28'
  97.             db      '29','30','31','32','33','34','35','36','37'
  98.             db      '38','39','40','41','42','43','44','45','46'
  99.             db      '47','48','49','50','51','52','53','54','55'
  100.             db      '56','57','58','59','60','61','62','63','64'
  101.  
  102. _codeseg ends
  103. end start
  104.