home *** CD-ROM | disk | FTP | other *** search
/ Large Pack of OldSkool DOS MOD Trackers / cdfm.zip / CDFMSB.BAK < prev    next >
Text File  |  2001-02-22  |  83KB  |  3,147 lines

  1.         .386p
  2. code32  segment para public use32
  3.         assume cs:code32, ds:code32, ss:code32
  4.  
  5. include pmode.inc
  6. include argc.inc
  7. include file.inc
  8. include dfmpm.inc
  9. include kb.inc
  10. include vga50.inc
  11.  
  12. extrn   muzorderc:byte
  13.  
  14. public  _main, exit
  15.  
  16. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  17. ; MAIN DATA
  18. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  19.  
  20. _hextbl db      '0123456789ABCDEF'
  21.  
  22. ht      db      15,13,01,'Renaissance 670 quickie composer, by Tran ofcourse...',0
  23.         db      07,00,04,'As for the keys:',0
  24.         db      07,01,05,24,', ',25,', PgUp, PgDn, Home, and End reformat your HD in all the menus.',0
  25.         db      07,00,06,'These are common basic keys:',0
  26.         db      07,01,07,'= and \ decrease and increase editing volume.',0
  27.         db      07,01,08,'; and '' decrease and increase master tempo.',0
  28.         db      07,01,09,'/ and * decrease and increase editing volume.',0
  29.         db      07,02,10,'(A note on this, the octaves range from 0-3 for digital and 0-5 for FM)',0
  30.         db      07,01,12,'Tab toggles stereo digital.',0
  31.         db      07,01,13,'Shift-Tab toggles stereo FM.',0
  32.         db      07,02,14,'(both start off as mono, however in stereo FM there are 9 extra channels',0
  33.         db      07,03,15,'but in stereo digital, the existing 4 are just split up between l and r)',0
  34.         db      07,01,17,'F5 plays the whole song.',0
  35.         db      07,01,18,'F6 plays just the pattern youre editing at the moment.',0
  36.         db      07,01,19,'F7 plays from the order the cursor is on in the order thingy.',0
  37.         db      07,02,20,'(press any key during playback to stop)',0
  38.         db      07,01,22,'F12 saves the song in full info mode. (you use this)',0
  39.         db      07,01,23,'ALT-F12 saves the song as the data file that will actually be used by moi.',0
  40.         db      07,01,27,'F4 takes ya to FM instrument menu thing.',0
  41.         db      07,01,24,'F1 takes ya to the digital instrument menu.',0
  42.         db      07,01,25,'F2 takes ya to the edit pattern menu or window or whatever.',0
  43.         db      07,01,26,'F3 lets ya edit the order list, then blows out your VGA.',0
  44.         db      07,01,28,'ALT-X destroys your computer...',0
  45.         db      07,01,30,'Space in the instrument menu whatevers allows ya to select an instrument.',0
  46.         db      07,01,31,'Enter be allowing ya to edit the instrument name.',0
  47.         db      07,01,32,'. clears stuff in any menu...',0
  48.         db      07,01,33,'- and + decrease and increase values in the FM instrument menu.',0
  49.         db      07,01,34,'ALT-Backspace saves the instrument ya got currently selected.',0
  50.         db      07,02,35,'(digital instruments are saved as filez, FM are saved in the bank file',0
  51.         db      07,03,36,'which can hold up to 666 FM instruments. Thus make sure the digital',0
  52.         db      07,03,37,'instrument namez are valid filenames before saving)',0
  53.         db      07,01,40,'Umm, ok, U B on your own now... play wit this ting and figure it out for',0
  54.         db      07,01,41,'yourself, I gotta finish coding it now... L8r...',0
  55.         db      12,07,47,'Overall, this composer works pretty much like my other composers...',0
  56.         db      12,05,48,'But for the sake of speed in coding this ting, it is a bare-bones thing.',0
  57.         db      12,06,49,'There is very little error cheking and shit, so dont make any mistakes!',0
  58.         db      0
  59.  
  60. l8rmsg          db      'L8r...$'
  61. errmsg0         db      'CDFM <670 filename with no extention> <digital instrument directory> [-c#]$'
  62.  
  63. songfile        db      64 dup(?)
  64. datafile        db      64 dup(?)
  65. dinsdir         db      64 dup(?)
  66. prgdir          db      64 dup(?)
  67. fileworkbuf     db      64 dup(?)
  68. extention670    db      '.C67',0
  69. extentiondat    db      '.670',0
  70. allfilemask     db      '*.*',0
  71. fminsfile       db      'CDFM.DAT',0
  72. fminsdat0       db      'Spaceguitar',0,0
  73.                 db      0,48,195,242,128,2,0,0,240,2,2
  74.  
  75. patbase         dd      ?               ; beginning of compiled patterns
  76. patoffbase      dd      ?               ; pattern offset data
  77. patlenbase      dd      ?               ; pattern length data
  78. dinsbase        dd      ?               ; digital instrument data
  79. dinsnames       dd      ?               ; names of digital instruments
  80. fminsbase       dd      ?               ; FM instrument data
  81. fminsnames      dd      ?               ; names of FM instruments
  82. fminsbank       dd      ?               ; ptr to bank file of FM instruments
  83. ordbase         dd      ?               ; ptr to order list
  84. workpatptr      dd      ?               ; ptr to workpattern
  85. buildpat        dd      ?               ; ptr to build pattern buffer
  86. dinsfilez       dd      ?               ; ptr to cached digital filenames
  87. worktrak        dd      ?               ; ptr to single worktrack
  88. savetrak        dd      ?               ; ptr to save buffer
  89.  
  90. vgacolorz:
  91.         db      21,19,3, 42,22,0, 26,39,33, 48,35,9, 24,21,4, 35,10,37
  92.         db      4,23,31, 40,38,22, 30,28,12, 63,24,14, 37,63,44
  93.         db      59,50,29, 0,29,56, 53,12,61, 15,48,56, 60,59,56
  94.         db      3,21,19, 0,42,22, 33,26,39, 9,48,35, 4,23,21, 37,35,10
  95.         db      31,4,23, 22,40,38, 12,30,28, 14,63,24, 44,37,63
  96.         db      29,59,50, 56,0,29, 61,53,12, 56,15,48, 56,60,59
  97.         db      19,3,21, 22,0,42, 39,33,26, 35,9,48, 21,4,23, 10,37,35
  98.     db    23,31,4, 38,22,40, 28,12,30, 24,14,63, 63,44,37
  99.     db    50,29,59, 29,56,0, 12,61,53, 48,56,15, 59,56,60
  100.         db      0,3,12, 0,0,31, 0,31,0, 0,31,42, 1,5,15, 38
  101.         db      0,31,31, 21,0,9, 39,49,21, 21,21,10, 21,53,10, 44
  102.         db      21,10,42, 63,53,21, 10,44,21, 51,56,46, 10,20,53, 63
  103.         db      0, 0, 10, 0, 0, 24, 0, 22, 19, 0, 25, 28, 1, 2, 13, 24
  104.         db      5, 22, 20, 17, 13, 0, 24, 33, 2, 24, 38, 16, 24, 41, 0, 32
  105.         db      28, 0, 34, 38, 38, 19, 19, 34, 7, 31, 36, 32, 12, 32, 43, 56
  106.         db      19, 0, 0, 25, 0, 0, 31, 0, 0, 37, 0, 0, 22, 2, 1, 50
  107.         db      0, 0, 56, 0, 0, 63, 0, 0, 63, 0, 0, 63, 8, 0, 63, 17
  108.         db      0, 63, 26, 0, 63, 35, 0, 63, 44, 0, 63, 53, 0, 63, 63, 0
  109.         db      2, 16, 21, 3, 18, 23, 6, 21, 26, 8, 24, 29, 3, 18, 24, 14
  110.         db      29, 35, 17, 32, 37, 21, 35, 40, 25, 38, 43, 29, 42, 46, 34, 45
  111.         db      49, 39, 48, 51, 44, 52, 54, 50, 55, 57, 56, 59, 60, 63, 63, 63
  112.  
  113. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  114. ; BEGINNING, MISC, AND CODE
  115. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  116. include textmode.rt
  117. include putnumtm.rt
  118. include strcpy.rt
  119. include strcat.rt
  120. include strlen.rt
  121. include strltu.rt
  122. include strhtn.rt
  123. include indxword.rt
  124. include indxbyte.rt
  125. include copymem.rt
  126. include pdosmsg.rt
  127.  
  128. ;═════════════════════════════════════════════════════════════════════════════
  129. exitsave:                               ; exit and save FM instrument bank
  130.         mov edi,offset fileworkbuf
  131.         mov esi,offset prgdir
  132.         call _strcpy
  133.         mov esi,offset fminsfile
  134.         call _strcat
  135.         mov edx,edi
  136.         call _createfile
  137.         mov edx,offset fminsnum
  138.         mov ecx,2
  139.         call _writefile
  140.         mov edx,fminsbank
  141.         imul cx,fminsnum,24
  142.         call _writefile
  143.         call _closefile
  144. exit1:                                  ; exit with L8r msg
  145.         mov edx,offset l8rmsg
  146.         jmp short exit
  147. exit0:                                  ; exit cuz commandline be not right
  148.         mov edx,offset errmsg0
  149. exit:                                   ; exit with a message
  150.         push edx
  151.         call _resetkb
  152.         call _uninstall_dfm
  153.         call _text_mode
  154.         pop edx
  155.         call _putdosmsg
  156.         jmp _exit
  157. ;═════════════════════════════════════════════════════════════════════════════
  158. _main:                                  ; beginning of program............
  159.         mov ax,220h
  160.         mov bl,7
  161.         mov bh,1
  162.  
  163.         add ax,0ch
  164.         mov _sbport,ax
  165.         mov _sbirq,bl
  166. ;        mov _sbdma,bh
  167.  
  168. ;        mov _sbport,530h
  169. ;        mov _sbirq,10
  170. ;        mov _sbdma,3
  171. ;        mov _scard,1101b
  172.  
  173.         sti
  174.         call _initkb
  175.         mov al,1001b
  176.         call _install_dfm
  177.         call allocbuffers
  178.         call setdirs
  179.         call setupscreen
  180.         call cachedins
  181.         call loadfmins
  182.         call clearsong
  183.         call loadsong
  184. ;        call _getch
  185. ;        jmp exit1
  186.  
  187.         mov eax,dinsfilez
  188.         mov selbps,eax
  189.         mov eax,fminsbank
  190.         mov selbps[4],eax
  191.         jmp editins1
  192.  
  193. ;-----------------------------------------------------------------------------
  194. setdirs:                                ; set and chek files and dirs
  195.         mov ebp,offset extention670
  196.         mov edx,offset songfile
  197.         call setdirsrout
  198.         mov ebp,offset extentiondat
  199.         mov edx,offset datafile
  200.         call setdirsrout
  201.         mov al,1
  202.         mov edx,offset dinsdir
  203.         call _cchekstr
  204.         jc exit0
  205.         mov ax,18h
  206.         mov es,ax
  207.         mov edi,_code16a
  208.         sub edi,0d4h
  209.         movzx edi,word ptr es:[edi]
  210.         shl edi,4
  211.         mov ecx,-1
  212.         xor al,al
  213. setdirsl0:
  214.         repnz scasb
  215.         scasb
  216.         jnz setdirsl0
  217.         add edi,2
  218.         mov esi,edi
  219.         mov ecx,edi
  220. setdirsl1:
  221.         mov al,es:[edi]
  222.         inc edi
  223.         or al,al
  224.         jz short setdirsl1d
  225.         cmp al,'\'
  226.         jne setdirsl1
  227.         mov ecx,edi
  228.         jmp setdirsl1
  229. setdirsl1d:
  230.         mov ax,ds
  231.         mov bx,es
  232.         mov ds,bx
  233.         mov es,ax
  234.         sub ecx,esi
  235.         mov edi,offset prgdir
  236.         rep movsb
  237.         xor al,al
  238.         stosb
  239.         mov ax,es
  240.         mov ds,ax
  241.         ret
  242. ;-----------------------------------------------------------------------------
  243. setdirsrout:
  244.         xor al,al
  245.         call _cchekstr
  246.         jc exit0
  247.         mov edi,edx
  248.         mov esi,ebp
  249.         jmp _strcat
  250. ;-----------------------------------------------------------------------------
  251. allocbuffers:                           ; set up buffers
  252.         mov eax,4000h
  253.         call _getmem
  254.         mov _filebufloc,eax
  255.         mov eax,60000h
  256.         call _getmem
  257.         mov patbase,eax
  258.         mov eax,4353
  259.         call _getmem
  260.         mov buildpat,eax
  261.         mov eax,11*32
  262.         call _getmem
  263.         mov fminsbase,eax
  264.         mov eax,13*32
  265.         call _getmem
  266.         mov fminsnames,eax
  267.         mov eax,4*4*32
  268.         call _getmem
  269.         mov dinsbase,eax
  270.         mov eax,13*32
  271.         call _getmem
  272.         mov dinsnames,eax
  273.         mov eax,4*128
  274.         call _getmem
  275.         mov patoffbase,eax
  276.         mov eax,4*128
  277.         call _getmem
  278.         mov patlenbase,eax
  279.         mov eax,256
  280.         call _getmem
  281.         mov ordbase,eax
  282.         mov eax,22*2*64
  283.         call _getmem
  284.         mov workpatptr,eax
  285.         mov eax,666*24
  286.         call _getmem
  287.         mov fminsbank,eax
  288.         mov eax,2048*13
  289.         call _getmem
  290.         mov dinsfilez,eax
  291.         mov eax,128
  292.         call _getmem
  293.         mov worktrak,eax
  294.         mov eax,128
  295.         call _getmem
  296.         mov savetrak,eax
  297.         ret
  298. ;-----------------------------------------------------------------------------
  299. loadfmins:                              ; load or create FM instruments
  300.     mov esi,offset prgdir
  301.         mov edi,offset fileworkbuf
  302.     call _strcpy
  303.         mov esi,offset fminsfile
  304.     call _strcat
  305.     mov edx,edi
  306.     call _openfile
  307.     jc short loadfminsf0
  308.     mov edx,offset fminsnum
  309.     mov ecx,2
  310.     call _readfile
  311.     movzx ecx,fminsnum
  312.     imul ecx,24
  313.         mov edx,fminsbank
  314.     call _readfile
  315.     call _closefile
  316.     ret
  317. loadfminsf0:
  318.         mov esi,offset fminsdat0
  319.         mov edi,fminsbank
  320.         mov ecx,24
  321.         rep movsb
  322.     ret
  323. ;-----------------------------------------------------------------------------
  324. setupscreenstr  db      'Name',0
  325. setupscreen:                            ; setup VGA and clear screen
  326.         mov al,'c'
  327.         mov edx,offset fileworkbuf
  328.         call _ccheksstr
  329.         jc short setupscreenf0
  330.         movzx esi,fileworkbuf
  331.         sub esi,'0'
  332.         imul esi,30h
  333.         mov ecx,0ch
  334.         add esi,offset vgacolorz
  335.         mov edi,offset _vgadefcolorz
  336.         rep movsd
  337. setupscreenf0:
  338.         call _initvga50
  339.         mov edi,_vgatextptr
  340.         mov eax,10201020h
  341.         mov ecx,40*50
  342.         rep stosd
  343.         mov bx,4
  344.         mov ah,19h
  345.         mov edx,offset setupscreenstr
  346.         call _putstr
  347.         ret
  348. ;-----------------------------------------------------------------------------
  349. cachedins:                              ; cache filenames in dinsdir
  350.         mov esi,offset dinsdir
  351.         mov edi,offset fileworkbuf
  352.         call _strcpy
  353.         mov esi,offset allfilemask
  354.         call _strcat
  355.         add edi,_code32a
  356.         mov eax,edi
  357.         and di,0fh
  358.         mov v86r_dx,di
  359.         shr eax,4
  360.         mov v86r_ds,ax
  361.         mov v86r_cx,0
  362.         mov ebp,_code16a
  363.         sub ebp,62h
  364.         mov edi,dinsfilez
  365.         mov v86r_ah,4eh
  366.         jmp short cachedinsf0
  367. cachedinsml:
  368.         mov v86r_ah,4fh
  369. cachedinsf0:
  370.         mov al,21h
  371.         int 33h
  372.         test v86r_flags,1
  373.         jnz short cachedinsd
  374.         mov esi,ebp
  375.         mov ax,18h
  376.         mov ds,ax
  377.         movsd
  378.         movsd
  379.         movsd
  380.         movsb
  381.         mov ax,es
  382.         mov ds,ax
  383.         inc dinsnum
  384.         jmp cachedinsml
  385. cachedinsd:
  386.         mov ebp,dinsfilez
  387.         mov cx,dinsnum
  388.         jmp alph
  389. ;-----------------------------------------------------------------------------
  390. loadsong:                               ; load 670 specified if exists
  391.         mov edx,offset songfile
  392.         call _openfile
  393.         jc _ret
  394.         mov edx,offset mztempo
  395.         mov ecx,1
  396.         call _readfile
  397.         mov edx,offset mzloop
  398.         call _readfile
  399.         mov edx,dinsnames
  400.         mov ecx,13*32
  401.         call _readfile
  402.         mov edx,dinsbase
  403.         mov ecx,16*32
  404.         call _readfile
  405.         mov edx,fminsnames
  406.         mov ecx,13*32
  407.         call _readfile
  408.         mov edx,fminsbase
  409.         mov ecx,11*32
  410.         call _readfile
  411.         mov edx,ordbase
  412.         mov ecx,100h
  413.         call _readfile
  414.         mov ecx,4*128
  415.         mov edx,patoffbase
  416.         call _readfile
  417.         mov ebx,[edx+4*127]
  418.         mov edx,patlenbase
  419.         call _readfile
  420.         add ebx,[edx+4*127]
  421.         mov edx,patbase
  422.         mov ecx,ebx
  423.         call _readfile
  424. ;        @rlp edx,100000h
  425.         mov edx,_himembase
  426.         mov ecx,1000000h
  427.         call _readfile
  428.         call _closefile
  429.         push offset putall
  430.         jmp resetdinslens
  431.  
  432. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  433. ; COMPOSER SPECIFIC DATA
  434. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  435. nkeylist        db      24,'zsxdcvgbhnjmq2w3er5t6y7u'
  436. numlist         db      16,'0123456789ABCDEF'
  437.  
  438. installword     dw      1001b
  439. zeroforplay     db      0
  440. maxvoiceb       db      2
  441. smpbase         dd      ?
  442. dinsnum         dw      0
  443. fminsnum        dw      1               ; number of FM instruments in bank
  444.  
  445. mztempo         db      ?               ; tempo of muzik
  446. svnord          db      ?
  447. svnpat          db      ?
  448. svndins         db      ?
  449. svnfmins        db      ?
  450. mzloop          db      ?               ; muzik loop
  451. svdinsoff       dd      ?
  452. mzbreak         db      ?               ; break for this pattern
  453.  
  454. edpat           db      ?               ; current pattern
  455. edvol           db      ?               ; current volume
  456. edoct           db      ?               ; editing octave
  457. edvoiceb        db      ?               ; editing voice base
  458. edvoiceo        db      ?               ; editing voice offset
  459. edrowb          db      ?               ; editing row base
  460. edrowo          db      ?               ; editing row offset
  461. edinsb          db      ?               ; editing instrument base
  462. edinso          db      ?               ; editing instrument offset
  463. edordb          db      ?               ; editing order base
  464. edordo          db      ?               ; editing order offset
  465. edfmval         db      ?               ; editing FM value
  466.  
  467. edblkb          db      -1
  468. edblke          db      -1
  469. edblkl          db      -1
  470.  
  471. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  472. ; COMPOSER CODE
  473. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  474.  
  475. ;─────────────────────────────────────────────────────────────────────────────
  476. setdinslens:
  477.         mov ebx,dinsbase
  478.         mov ecx,32
  479. setdinslensml:
  480.         mov eax,[ebx]
  481.         sub [ebx+4],eax
  482.         sub [ebx+8],eax
  483.         sub [ebx+12],eax
  484.         mov dword ptr [ebx],0
  485.         add ebx,10h
  486.         loop setdinslensml
  487.         ret
  488. ;─────────────────────────────────────────────────────────────────────────────
  489. resetdinslens:
  490. ;        @rlp eax,100000h
  491.         mov eax,_himembase
  492.         mov ebx,dinsbase
  493.         mov ecx,32
  494. resetdinslensml:
  495.         mov edx,[ebx+4]
  496.         or edx,edx
  497.         jz short resetdinslensmlc
  498.         mov [ebx],eax
  499.         add [ebx+8],eax
  500.         add [ebx+12],eax
  501.         add eax,edx
  502.         mov [ebx+4],eax
  503. resetdinslensmlc:
  504.         add ebx,10h
  505.         loop resetdinslensml
  506.         ret
  507.  
  508. ;─────────────────────────────────────────────────────────────────────────────
  509. adjoct:
  510.         cmp edoct,4
  511.         jb _ret
  512.         mov edoct,3
  513.         ret
  514.  
  515. ;─────────────────────────────────────────────────────────────────────────────
  516. calcloc:
  517.         movzx eax,edrowb
  518.         add al,edrowo
  519.         imul edi,eax,44
  520.         movzx eax,edvoiceb
  521.         add al,edvoiceo
  522.         lea edi,[edi+eax*2]
  523.         add edi,workpatptr
  524.         ret
  525.  
  526. ;─────────────────────────────────────────────────────────────────────────────
  527. boxgrfx db      '═║╔╗╚╝ '
  528. playstr db      'Playing...',0
  529. play:
  530.         mov bx,1822h
  531.         mov cx,60fh
  532.         call _pushtext
  533.         add bx,101h
  534.         sub cx,101h
  535.         mov ax,20h
  536.         call _textbox0
  537.         sub bx,101h
  538.         mov edx,offset boxgrfx
  539.         mov ah,87h
  540.         call _textbox1
  541.         add bx,202h
  542.         mov edx,offset playstr
  543.         mov ah,8fh
  544.         call _putstr
  545.         mov al,mztempo
  546.         mov muztempo,al
  547.         mov eax,dinsbase
  548.         mov muzsbinsptr,eax
  549.         mov eax,fminsbase
  550.         mov muzfminsptr,eax
  551.         mov eax,patbase
  552.         mov muzpatbase,eax
  553.         call _setmuzik
  554.         call _getch
  555.         call _stopmuzik
  556.         call _poptext
  557.         ret
  558.  
  559. ;─────────────────────────────────────────────────────────────────────────────
  560. howmanyorders:
  561.         xor ah,ah
  562.         mov esi,ordbase
  563. howmanyordersml:
  564.         lodsb
  565.         cmp al,-1
  566.         je short howmanyordersd
  567.         inc ah
  568.         jmp howmanyordersml
  569. howmanyordersd:
  570.         mov al,ah
  571.         ret
  572.  
  573. ;─────────────────────────────────────────────────────────────────────────────
  574. calcloc2:
  575.         mov bh,edrowo
  576.         add bh,16
  577.         movzx eax,edvoiceo
  578.         imul eax,7
  579.         mov bl,al
  580.         add bl,3
  581.         ret
  582.  
  583. ;─────────────────────────────────────────────────────────────────────────────
  584. setins:
  585.         xor bl,bl
  586.         mov bh,al
  587.         cmp al,14h
  588.         jb short setinsf0
  589.         mov bl,al
  590.         sub bl,13h
  591.         mov bh,13h
  592. setinsf0:
  593.         mov edinsb,bh
  594.         mov edinso,bl
  595.         ret
  596.  
  597. ;─────────────────────────────────────────────────────────────────────────────
  598. gettrak:
  599.         movzx eax,edvoiceb
  600.         add al,edvoiceo
  601.         lea esi,[eax*2]
  602.         add esi,workpatptr
  603.         mov edi,worktrak
  604.         mov ecx,64
  605. gettrakml:
  606.         movsw
  607.         add esi,42
  608.         loop gettrakml
  609.         ret
  610. ;─────────────────────────────────────────────────────────────────────────────
  611. puttrak:
  612.         movzx eax,edvoiceb
  613.         add al,edvoiceo
  614.         lea edi,[eax*2]
  615.         add edi,workpatptr
  616.         mov esi,worktrak
  617.         mov ecx,64
  618. puttrakml:
  619.         movsw
  620.         add edi,42
  621.         loop puttrakml
  622.         ret
  623.  
  624. ;─────────────────────────────────────────────────────────────────────────────
  625. calc3:
  626.         call gettrak
  627.         mov edi,worktrak
  628.         movzx ebx,edblkb
  629.         or bl,bl
  630.         js ret2
  631.         lea edi,[edi+ebx*2]
  632.         movzx ecx,edblke
  633.         or cl,cl
  634.         js ret2
  635.         sub cl,bl
  636.         inc cl
  637.         ret
  638. ret2:
  639.         add esp,4
  640.         ret
  641.  
  642. ;─────────────────────────────────────────────────────────────────────────────
  643. inputlist       db      19
  644.                 dw      278h,'*','/','=','\',12ch,12eh,';','''',0fh,10fh
  645.                 dw      13fh,8,6,5,7,12,20ch
  646. inputrout       dd      exitsave,incoct,decoct,decvol,incvol,decloop,incloop
  647.                 dd      dectempo,inctempo,togglesd,togglesfm,help,_stopmuzik
  648.                 dd      playpat,playsong,playord,savesong,savedata
  649. getinput:                               ; regular high get input routine
  650.         call _getch
  651.         mov edx,offset inputlist
  652.         call _indexword
  653.         jc _ret
  654.         call inputrout[eax*4]
  655.         jmp getinput
  656. ;-----------------------------------------------------------------------------
  657. incoct:
  658.         mov ah,1
  659.         jmp short changeoct
  660. ;-----------------------------------------------------------------------------
  661. decoct:
  662.         mov ah,-1
  663. changeoct:
  664.         mov al,edoct
  665.         add al,ah
  666.         js _ret
  667.         cmp al,6
  668.         ja _ret
  669.         mov edoct,al
  670.         jmp putstat
  671. ;-----------------------------------------------------------------------------
  672. incvol:
  673.         mov ah,1
  674.         jmp short changevol
  675. ;-----------------------------------------------------------------------------
  676. decvol:
  677.         mov ah,-1
  678. changevol:
  679.         mov al,edvol
  680.         add al,ah
  681.         js _ret
  682.         cmp al,0fh
  683.         ja _ret
  684.         mov edvol,al
  685.         jmp putstat
  686. ;-----------------------------------------------------------------------------
  687. incloop:
  688.         mov ah,1
  689.         jmp short changeloop
  690. ;-----------------------------------------------------------------------------
  691. decloop:
  692.         mov ah,-1
  693. changeloop:
  694.         mov al,mzloop
  695.         add al,ah
  696.         js _ret
  697.         cmp al,7fh
  698.         ja _ret
  699.         mov mzloop,al
  700.         jmp putstat
  701. ;-----------------------------------------------------------------------------
  702. inctempo:
  703.         mov ah,1
  704.         jmp short changetempo
  705. ;-----------------------------------------------------------------------------
  706. dectempo:
  707.         mov ah,-1
  708. changetempo:
  709.         mov al,mztempo
  710.         add al,ah
  711.         jz _ret
  712.         cmp al,0fh
  713.         ja _ret
  714.         mov mztempo,al
  715.         jmp putstat
  716. ;-----------------------------------------------------------------------------
  717. togglesd:
  718.         xor installword,100b
  719. togglereinstall:
  720.         mov ax,installword
  721.         jmp _install_dfm
  722. ;-----------------------------------------------------------------------------
  723. togglesfm:
  724. ;       xor maxvoiceb,9
  725. ;       mov edvoiceb,0
  726.         xor installword,11b
  727.         jmp togglereinstall
  728. ;-----------------------------------------------------------------------------
  729. help:
  730.         xor ebx,ebx
  731.         mov cx,3250h
  732.         call _pushtext
  733.         mov ax,0f20h
  734.         call _textbox0
  735.         mov esi,offset ht
  736. helploop:
  737.         lodsb
  738.         or al,al
  739.         jz helpdone
  740.         mov ah,al
  741.         lodsb
  742.         mov bl,al
  743.         lodsb
  744.         mov bh,al
  745.         mov edx,esi
  746.         call _putstr
  747.         mov edi,esi
  748.         mov ecx,-1
  749.         xor al,al
  750.         repnz scasb
  751.         mov esi,edi
  752.         jmp helploop
  753. helpdone:
  754.         call _getch
  755.         call _poptext
  756.         ret
  757. ;-----------------------------------------------------------------------------
  758. playpat:
  759.         call setpat
  760.         mov muzordptr,offset zeroforplay
  761.         mov muzordern,1
  762.         mov muzorderl,0
  763.         movzx eax,edpat
  764.         shl eax,2
  765.         add eax,patoffbase
  766.         mov muzpatoffptr,eax
  767.         mov muzorderc,0
  768.         jmp play
  769. ;-----------------------------------------------------------------------------
  770. playsong:
  771.         xor al,al
  772.         jmp short playfrom
  773. playord:
  774.         mov al,edordb
  775.         add al,edordo
  776. playfrom:
  777.         dec al
  778.         mov muzorderc,al
  779.         call setpat
  780.         call howmanyorders
  781.         mov muzordern,al
  782.         mov al,mzloop
  783.         mov muzorderl,al
  784.         mov eax,ordbase
  785.         mov muzordptr,eax
  786.         mov eax,patoffbase
  787.         mov muzpatoffptr,eax
  788.         jmp play
  789. ;-----------------------------------------------------------------------------
  790. savesong:
  791.         call setdinslens
  792.         call setpat
  793.         mov edx,offset songfile
  794.         call _createfile
  795.         mov edx,offset mztempo
  796.         mov ecx,1
  797.         call _writefile
  798.         mov edx,offset mzloop
  799.         call _writefile
  800.         mov edx,dinsnames
  801.         mov ecx,13*32
  802.         call _writefile
  803.         mov edx,dinsbase
  804.         mov ecx,16*32
  805.         call _writefile
  806.         mov edx,fminsnames
  807.         mov ecx,13*32
  808.         call _writefile
  809.         mov edx,fminsbase
  810.         mov ecx,11*32
  811.         call _writefile
  812.         mov edx,ordbase
  813.         mov ecx,100h
  814.         call _writefile
  815.         mov ecx,4*128
  816.         mov edx,patoffbase
  817.         mov ebx,[edx+4*127]
  818.         call _writefile
  819.         mov edx,patlenbase
  820.         add ebx,[edx+4*127]
  821.         call _writefile
  822.         mov edx,patbase
  823.         mov ecx,ebx
  824.         call _writefile
  825. ;        @rlp edx,100000h
  826.         mov edx,_himembase
  827.         mov ecx,smpbase
  828.         sub ecx,edx
  829.         call _writefile
  830.         call _closefile
  831.         jmp resetdinslens
  832. ;-----------------------------------------------------------------------------
  833. svpatlen        dd      ?
  834. svrouttbl       dd      savedatan,savedata1,savedata1,_ret
  835. savedata:
  836.         call setpat
  837.         call howmanyorders
  838.         or al,al
  839.         jz _ret
  840.         mov svnord,al
  841.         movzx ecx,al
  842.         mov esi,ordbase
  843.         xor ah,ah
  844. savedatal0:
  845.         lodsb
  846.         cmp al,ah
  847.         jbe short savedatal0c
  848.         mov ah,al
  849. savedatal0c:
  850.         loop savedatal0
  851.         movzx ebp,ah
  852.         inc ah
  853.         mov svnpat,ah
  854.         lea eax,[ebp*4]
  855.         add eax,patoffbase
  856.         mov edi,[eax]
  857.         lea eax,[ebp*4]
  858.         add eax,patlenbase
  859.         add edi,[eax]
  860.         mov svpatlen,edi
  861.         mov esi,patbase
  862.         add edi,esi
  863.         mov edx,-1
  864. savedatal1:
  865.         lodsb
  866.         movzx ebx,al
  867.         shr bl,5
  868.         call svrouttbl[ebx*4]
  869.         cmp esi,edi
  870.         jb savedatal1
  871.         jmp short savedatal1d
  872. savedata1:
  873.         inc esi
  874.         ret
  875. savedatan:
  876.         mov bl,al
  877.         and bl,1fh
  878.         lodsw
  879.         xchg ah,al
  880.         shr ah,7
  881.         shr eax,4
  882.         cmp bl,3
  883.         ja short savedatanfm
  884.         cmp al,dl
  885.         jle _ret
  886.         mov dl,al
  887.         ret
  888. savedatanfm:
  889.         cmp al,dh
  890.         jle _ret
  891.         mov dh,al
  892.         ret
  893. savedatal1d:
  894.         inc dh
  895.         inc dl
  896.         mov svndins,dl
  897.         mov svnfmins,dh
  898.         movzx eax,dl
  899.         shl eax,4
  900.         movzx ebx,dh
  901.         imul ebx,11
  902.         add eax,svpatlen
  903.         lea eax,[eax+ebx+10]
  904.         movzx ebx,svnord
  905.         add eax,ebx
  906.         movzx ebx,svnpat
  907.         lea eax,[eax+ebx*4]
  908.         mov svdinsoff,eax
  909.         mov edi,workpatptr
  910.         mov esi,dinsbase
  911.         mov ecx,32
  912. savedatal2:
  913.         xor eax,eax
  914.         stosd
  915.         lodsd
  916.         mov ebx,eax
  917.         lodsd
  918.         sub eax,ebx
  919.         stosd
  920.         lodsd
  921.         sub eax,ebx
  922.         stosd
  923.         lodsd
  924.         sub eax,ebx
  925.         stosd
  926.         loop savedatal2
  927.         mov edx,offset datafile
  928.         call _createfile
  929.         mov edx,offset mztempo
  930.         mov ecx,10
  931.         call _writefile
  932.         mov edx,ordbase
  933.         movzx ecx,svnord
  934.         call _writefile
  935.         mov edx,patoffbase
  936.         movzx ecx,svnpat
  937.         shl ecx,2
  938.         call _writefile
  939.         mov edx,workpatptr
  940.         movzx ecx,svndins
  941.         shl ecx,4
  942.         call _writefile
  943.         mov edx,fminsbase
  944.         movzx ecx,svnfmins
  945.         imul ecx,11
  946.         call _writefile
  947.         mov edx,patbase
  948.         mov ecx,svpatlen
  949.         call _writefile
  950.         movzx eax,svndins
  951.         or al,al
  952.         jz getpat
  953.         dec eax
  954.         shl eax,4
  955.         add eax,dinsbase
  956.         mov ecx,[eax+4]
  957. ;        @rlp edx,100000h
  958.         mov edx,_himembase
  959.         sub ecx,edx
  960.         call _writefile
  961.         jmp _closefile
  962.  
  963. ;═════════════════════════════════════════════════════════════════════════════
  964. editordlist     db      14
  965.                 dw      25,26,21,22,19,20,13,32,'.',1,4,2,17,18
  966. editordrout     dd      eoup,eodn,eopgup,eopgdn,eohome,eoend,eoed,eoed,eoclear
  967.                 dd      eof1,eof2,eof3,eoins,eodel
  968. editord:
  969.         call putstat
  970.         call putord
  971.         call putordcur
  972.         call getinput
  973.         mov edx,offset editordlist
  974.         call _indexword
  975.         jc editord
  976.         call editordrout[eax*4]
  977.         jmp editord
  978. ;-----------------------------------------------------------------------------
  979. eoup:
  980.         mov ah,-1
  981.         jmp short eoupdn
  982. ;-----------------------------------------------------------------------------
  983. eodn:
  984.         mov ah,1
  985. eoupdn:
  986.         mov al,edordo
  987.         add al,ah
  988.         js eopgupdn
  989.         cmp al,0ch
  990.         ja eopgupdn
  991.         mov edordo,al
  992.         ret
  993. ;-----------------------------------------------------------------------------
  994. eopgup:
  995.         mov ah,-0dh
  996.         jmp short eopgupdn
  997. ;-----------------------------------------------------------------------------
  998. eopgdn:
  999.         mov ah,0dh
  1000. eopgupdn:
  1001.         mov al,edordb
  1002.         add al,ah
  1003.         jc short eopgupdnf2
  1004.         or ah,ah
  1005.         js short eopgupdnf1
  1006.         cmp al,0f4h
  1007.         jb short eopgupdnf0
  1008. eopgupdnf3:
  1009.         mov edordb,0f3h
  1010.         ret
  1011. eopgupdnf1:
  1012.         mov edordb,0
  1013.         ret
  1014. eopgupdnf2:
  1015.         or ah,ah
  1016.         jns eopgupdnf3
  1017. eopgupdnf0:
  1018.         mov edordb,al
  1019.         ret
  1020. ;-----------------------------------------------------------------------------
  1021. eohome:
  1022.         mov edordo,0
  1023.         ret
  1024. ;-----------------------------------------------------------------------------
  1025. eoend:
  1026.         mov edordo,0ch
  1027.         ret
  1028. ;-----------------------------------------------------------------------------
  1029. eoed:
  1030.         mov bh,edordo
  1031.         add bh,1
  1032.         mov bl,77
  1033.         mov cl,2
  1034.         call getnum
  1035.         jc _ret
  1036.         movzx ebx,edordb
  1037.         add bl,edordo
  1038.         add ebx,ordbase
  1039.         and al,7fh
  1040.         mov [ebx],al
  1041.         jmp eodn
  1042. ;-----------------------------------------------------------------------------
  1043. eoclear:
  1044.         movzx ebx,edordb
  1045.         add bl,edordo
  1046.         add ebx,ordbase
  1047.         mov byte ptr [ebx],-1
  1048.         jmp eodn
  1049. ;-----------------------------------------------------------------------------
  1050. eof1:
  1051.         add esp,4
  1052.         call putord
  1053.         jmp editins0
  1054. ;-----------------------------------------------------------------------------
  1055. eof2:
  1056.         add esp,4
  1057.         call putord
  1058.         jmp editins1
  1059. ;-----------------------------------------------------------------------------
  1060. eof3:
  1061.         add esp,4
  1062.         call putord
  1063.         jmp editpat
  1064. ;-----------------------------------------------------------------------------
  1065. eoins:
  1066.         mov eax,offset ins
  1067.         jmp short eoid
  1068. ;-----------------------------------------------------------------------------
  1069. eodel:
  1070.         mov eax,offset del
  1071. eoid:
  1072.         mov ebp,ordbase
  1073.         movzx bx,edordb
  1074.         add bl,edordo
  1075.         mov dx,100h
  1076.         mov ecx,1
  1077.         call eax
  1078.         mov byte ptr [edi],-1
  1079.         ret
  1080.  
  1081. ;═════════════════════════════════════════════════════════════════════════════
  1082. editins0list    db      17
  1083.                 dw      4,2,3,25,26,21,22,19,20,13,'[',']',32,'.',17,18,210h
  1084. editins0rout    dd      esf2,esf3,esf4,eiup,eidn,eipgup,eipgdn,eihome,eiend
  1085.                 dd      esgetname,eslbeg,eslend,esload,esclearins,esins,esdel
  1086.                 dd      esaddins
  1087. editins0:
  1088.         call putstat
  1089.         call putins0
  1090.         call putins0cur
  1091.         call getinput
  1092.         mov edx,offset editins0list
  1093.         call _indexword
  1094.         jc short editins0f0
  1095.         call editins0rout[eax*4]
  1096.         jmp editins0
  1097. editins0f0:
  1098.         or ah,ah
  1099.         jnz editins0
  1100.         mov edx,offset nkeylist
  1101.         call _indexbyte
  1102.         jc editins0
  1103.         movzx edx,edinsb
  1104.         add dl,edinso
  1105.         shl edx,4
  1106.         add edx,dinsbase
  1107.         mov bl,edvol
  1108.         mov ah,al
  1109.         cmp ah,12
  1110.         jb short editins0f1
  1111.         add ah,10h-12
  1112. editins0f1:
  1113.         call adjoct
  1114.         mov al,edoct
  1115.         shl al,4
  1116.         add ah,al
  1117.         xor al,al
  1118.         mov ebp,[edx+4]
  1119.         mov esi,[edx]
  1120.         mov ecx,[edx+8]
  1121.         mov edx,[edx+12]
  1122.         call _sbnote
  1123.         jmp editins0
  1124.  
  1125. ;-----------------------------------------------------------------------------
  1126. esf4:
  1127.         add esp,4
  1128.         call putins0
  1129.         jmp editord
  1130. ;-----------------------------------------------------------------------------
  1131. esf2:
  1132.         add esp,4
  1133.         call putins0
  1134.         jmp editins1
  1135. ;-----------------------------------------------------------------------------
  1136. esf3:
  1137.         add esp,4
  1138.         call putins0
  1139.         jmp editpat
  1140. ;-----------------------------------------------------------------------------
  1141. esgetname:
  1142.         call putins0
  1143.         mov ax,8a00h
  1144.         mov bx,104h
  1145.         add bh,edinso
  1146.         mov cl,12
  1147.         movzx edx,edinsb
  1148.         add dl,edinso
  1149.         imul edx,13
  1150.         add edx,dinsnames
  1151.         mov ebp,offset editinsaccept
  1152.         call _getstr
  1153.         ret
  1154. ;-----------------------------------------------------------------------------
  1155. eslbeg:
  1156.         mov edx,8
  1157.         mov bl,17
  1158.         jmp short eslnum
  1159. ;-----------------------------------------------------------------------------
  1160. eslend:
  1161.         mov edx,12
  1162.         mov bl,23
  1163. eslnum:
  1164.         push edx
  1165.         mov bh,edinso
  1166.         inc bh
  1167.         mov cl,5
  1168.         call getnum
  1169.         pop edx
  1170.         jc _ret
  1171.         movzx ebx,edinsb
  1172.         add bl,edinso
  1173.         shl ebx,4
  1174.         add ebx,dinsbase
  1175.         add eax,[ebx]
  1176.         mov [ebx+edx],eax
  1177.         ret
  1178. ;-----------------------------------------------------------------------------
  1179. esload:
  1180.         mov edx,dinsfilez
  1181.         movzx ecx,dinsnum
  1182.         mov seli,0
  1183.         call select
  1184.         jc _ret
  1185.         movzx ebx,edinsb
  1186.         add bl,edinso
  1187.         mov edi,offset fileworkbuf
  1188.         mov esi,offset dinsdir
  1189.         call _strcpy
  1190.         imul esi,eax,13
  1191.         add esi,dinsfilez
  1192.         call _strcat
  1193.         mov edx,edi
  1194.         imul edi,ebx,13
  1195.         add edi,dinsnames
  1196.         movsd
  1197.         movsd
  1198.         movsd
  1199.         movsb
  1200.         call _openfile
  1201.         call _filesize
  1202.         mov ecx,eax
  1203.         mov edx,smpbase
  1204.         shl ebx,4
  1205.         add ebx,dinsbase
  1206.         mov [ebx],edx
  1207.         mov [ebx+8],edx
  1208.         add eax,edx
  1209.         mov [ebx+4],eax
  1210.         lea eax,[edx+0ffffffh]
  1211.         mov [ebx+12],eax
  1212.         call _readfile
  1213.         call _closefile
  1214.         jmp adjsmp
  1215. ;-----------------------------------------------------------------------------
  1216. esclearins:
  1217.         movzx ebx,edinsb
  1218.         add bl,edinso
  1219.         mov edi,ebx
  1220.         shl edi,4
  1221.         add edi,dinsbase
  1222.         xor eax,eax
  1223.         stosd
  1224.         stosd
  1225.         stosd
  1226.         mov dword ptr [edi],0ffffffh
  1227.         imul ebx,13
  1228.         add ebx,fminsnames
  1229.         mov byte ptr [ebx],0
  1230.         call adjsmp
  1231.         jmp eidn
  1232. ;-----------------------------------------------------------------------------
  1233. esins:
  1234.         mov idcall,offset ins
  1235.         jmp short esid
  1236. ;-----------------------------------------------------------------------------
  1237. esdel:
  1238.         mov idcall,offset del
  1239. esid:
  1240.         mov dx,20h
  1241.         movzx bx,edinsb
  1242.         add bl,edinso
  1243.         mov ebp,dinsnames
  1244.         mov ecx,13
  1245.         push bx
  1246.         push dx
  1247.         call idcall
  1248.         pop dx
  1249.         pop bx
  1250.         mov byte ptr [edi],0
  1251.         mov ebp,dinsbase
  1252.         mov ecx,16
  1253.         call idcall
  1254.         xor eax,eax
  1255.         stosd
  1256.         stosd
  1257.         stosd
  1258.         mov dword ptr [edi],0ffffffh
  1259.         jmp adjsmp
  1260. ;-----------------------------------------------------------------------------
  1261. esaddins:
  1262.         movzx eax,edinsb
  1263.         add al,edinso
  1264.         imul esi,eax,13
  1265.         add esi,dinsnames
  1266.         mov edi,offset errmsg0
  1267.         call _strcpy
  1268.         mov edx,edi
  1269.         call _strltu
  1270.         mov ebp,edx
  1271.         movzx ebx,dinsnum
  1272.         mov esi,dinsfilez
  1273.         call alphfind
  1274.         jc _ret
  1275.         mov bx,ax
  1276.         mov dx,dinsnum
  1277.         inc dx
  1278.         mov dinsnum,dx
  1279.         mov ecx,13
  1280.         mov ebp,dinsfilez
  1281.         call ins
  1282.         mov esi,offset errmsg0
  1283.         movsd
  1284.         movsd
  1285.         movsd
  1286.         movsb
  1287.         mov esi,offset dinsdir
  1288.         mov edi,offset fileworkbuf
  1289.         call _strcpy
  1290.         mov esi,offset errmsg0
  1291.         call _strcat
  1292.         mov edx,edi
  1293.         call _createfile
  1294.         movzx eax,edinsb
  1295.         add al,edinso
  1296.         shl eax,4
  1297.         add eax,dinsbase
  1298.         mov edx,[eax]
  1299.         mov ecx,[eax+4]
  1300.         sub ecx,edx
  1301.         call _writefile
  1302.         call _closefile
  1303.         ret
  1304.  
  1305. ;═════════════════════════════════════════════════════════════════════════════
  1306. editinsaccept   db      editins1list-editinsaccept,'QWERTYUIOPASDFGHJKLZXCVBNM'
  1307.                 db      'qwertyuiopasdfghjklzxcvbnm1234567890 !_?,.()-'
  1308. editins1list    db      19
  1309.                 dw      25,26,23,24,'+','-',21,22,32,13,19,20,'.',210h,1,2,3
  1310.                 dw      17,18
  1311. editins1rout    dd      eiup,eidn,eivald,eivalu,eiincval,eidecval
  1312.                 dd      eipgup,eipgdn,eigetins,eigetname,eihome,eiend
  1313.                 dd      eiclearins,eiaddins,eif1,eif3,eif4,eiins,eidel
  1314. editins1:
  1315.         call putstat
  1316.         call putins1
  1317.         call putins1cur
  1318.         call getinput
  1319.         mov edx,offset editins1list
  1320.         call _indexword
  1321.         jc short editins1f0
  1322.         call editins1rout[eax*4]
  1323.         jmp editins1
  1324. editins1f0:
  1325.         or ah,ah
  1326.         jnz editins1
  1327.         mov edx,offset nkeylist
  1328.         call _indexbyte
  1329.         jc editins1
  1330.         movzx edx,edinsb
  1331.         add dl,edinso
  1332.         imul edx,11
  1333.         add edx,fminsbase
  1334.         mov bl,edvol
  1335.         mov ah,al
  1336.         cmp ah,12
  1337.         jb short editins1f1
  1338.         add ah,10h-12
  1339. editins1f1:
  1340.         mov al,edoct
  1341.         shl al,4
  1342.         add ah,al
  1343.         xor al,al
  1344.         call _fmnote
  1345.         mov al,9
  1346.         call _fmnote
  1347.         jmp editins1
  1348. ;-----------------------------------------------------------------------------
  1349. eiup:
  1350.         mov ah,-1
  1351.         jmp short eiupdn
  1352. ;-----------------------------------------------------------------------------
  1353. eidn:
  1354.         mov ah,1
  1355. eiupdn:
  1356.         mov al,edinso
  1357.         add al,ah
  1358.         js eipgupdn
  1359.         cmp al,0ch
  1360.         ja eipgupdn
  1361.         mov edinso,al
  1362.         ret
  1363. ;-----------------------------------------------------------------------------
  1364. eipgup:
  1365.         mov ah,-0dh
  1366.         jmp short eipgupdn
  1367. ;-----------------------------------------------------------------------------
  1368. eipgdn:
  1369.         mov ah,0dh
  1370. eipgupdn:
  1371.         mov al,edinsb
  1372.         add al,ah
  1373.         jns short eipgupdnf0
  1374.         mov edinsb,0
  1375.         ret
  1376. eipgupdnf0:
  1377.         cmp al,14h
  1378.         jb short eipgupdnf1
  1379.         mov al,13h
  1380. eipgupdnf1:
  1381.         mov edinsb,al
  1382.         ret
  1383. ;-----------------------------------------------------------------------------
  1384. eivald:
  1385.         mov ah,-1
  1386.         jmp short eichangeval
  1387. ;-----------------------------------------------------------------------------
  1388. eivalu:
  1389.         mov ah,1
  1390. eichangeval:
  1391.         mov al,edfmval
  1392.         add al,ah
  1393.         js _ret
  1394.         cmp al,25
  1395.         ja _ret
  1396.         mov edfmval,al
  1397.         ret
  1398. ;-----------------------------------------------------------------------------
  1399. eiincval:
  1400.         mov bl,1
  1401.         jmp short eiincdecval
  1402. ;-----------------------------------------------------------------------------
  1403. eidecval:
  1404.         mov bl,-1
  1405. eiincdecval:
  1406.         mov ah,edinsb
  1407.         add ah,edinso
  1408.         mov al,edfmval
  1409.         call getfminsval
  1410.         add bl,al
  1411.         mov al,edfmval
  1412.         call setfminsval
  1413.         ret
  1414. ;-----------------------------------------------------------------------------
  1415. eigetname:
  1416.         call putins1
  1417.         mov ax,8a00h
  1418.         mov bx,104h
  1419.         add bh,edinso
  1420.         mov cl,12
  1421.         movzx edx,edinsb
  1422.         add dl,edinso
  1423.         imul edx,13
  1424.         add edx,fminsnames
  1425.         mov ebp,offset editinsaccept
  1426.         call _getstr
  1427.         ret
  1428. ;-----------------------------------------------------------------------------
  1429. eihome:
  1430.         mov edinso,0
  1431.         ret
  1432. ;-----------------------------------------------------------------------------
  1433. eiend:
  1434.         mov edinso,0ch
  1435.         ret
  1436. ;-----------------------------------------------------------------------------
  1437. eigetins:
  1438.         mov edx,fminsbank
  1439.         movzx ecx,fminsnum
  1440.         mov seli,1
  1441.         call select
  1442.         jc _ret
  1443.         movzx ebx,edinsb
  1444.         add bl,edinso
  1445.         imul edi,ebx,13
  1446.         add edi,fminsnames
  1447.         imul esi,eax,13
  1448.         add esi,fminsbank
  1449.         movsd
  1450.         movsd
  1451.         movsd
  1452.         movsb
  1453.         imul edi,ebx,11
  1454.         add edi,fminsbase
  1455.         movzx ebx,fminsnum
  1456.         imul ebx,13
  1457.         imul esi,eax,11
  1458.         add esi,fminsbank
  1459.         add esi,ebx
  1460.         movsd
  1461.         movsd
  1462.         movsw
  1463.         movsb
  1464.         ret
  1465. ;-----------------------------------------------------------------------------
  1466. eiclearins:
  1467.         movzx ebx,edinsb
  1468.         add bl,edinso
  1469.         imul edi,ebx,11
  1470.         add edi,fminsbase
  1471.         xor eax,eax
  1472.         stosd
  1473.         stosd
  1474.         stosw
  1475.         stosb
  1476.         imul ebx,13
  1477.         add ebx,fminsnames
  1478.         mov byte ptr [ebx],0
  1479.         jmp eidn
  1480. ;-----------------------------------------------------------------------------
  1481. eif1:
  1482.         add esp,4
  1483.         call putins1
  1484.         jmp editins0
  1485. ;-----------------------------------------------------------------------------
  1486. eif3:
  1487.         add esp,4
  1488.         call putins1
  1489.         jmp editpat
  1490. ;-----------------------------------------------------------------------------
  1491. eif4:
  1492.         add esp,4
  1493.         call putins1
  1494.         jmp editord
  1495. ;-----------------------------------------------------------------------------
  1496. idcall  dd      ?
  1497. eiins:
  1498.         mov idcall,offset ins
  1499.         jmp short eiid
  1500. ;-----------------------------------------------------------------------------
  1501. eidel:
  1502.         mov idcall,offset del
  1503. eiid:
  1504.         mov dx,20h
  1505.         movzx bx,edinsb
  1506.         add bl,edinso
  1507.         mov ebp,fminsnames
  1508.         mov ecx,13
  1509.         push bx
  1510.         push dx
  1511.         call idcall
  1512.         pop dx
  1513.         pop bx
  1514.         mov byte ptr [edi],0
  1515.         mov ebp,fminsbase
  1516.         mov ecx,11
  1517.         call idcall
  1518.         xor eax,eax
  1519.         stosd
  1520.         stosd
  1521.         stosw
  1522.         stosb
  1523.         ret
  1524. ;-----------------------------------------------------------------------------
  1525. eiaddinsbase    dd      ?
  1526. eiaddinsindx    dw      ?
  1527. eiaddins:
  1528.         movzx eax,edinsb
  1529.         add al,edinso
  1530.         movzx ebx,fminsnum
  1531.         mov esi,fminsbank
  1532.         imul ebp,eax,13
  1533.         add ebp,fminsnames
  1534.         call alphfind
  1535.         jc eiaddinsf0
  1536.         mov eiaddinsindx,ax
  1537.         movzx edi,fminsnum
  1538.         imul ecx,edi,11
  1539.         inc edi
  1540.         mov fminsnum,di
  1541.         imul edi,13
  1542.         add edi,fminsbank
  1543.         mov esi,edi
  1544.         sub esi,13
  1545.         mov eiaddinsbase,edi
  1546.         call _copymem
  1547.         mov dx,fminsnum
  1548.         mov bx,eiaddinsindx
  1549.         mov ecx,13
  1550.         mov ebp,fminsbank
  1551.         call ins
  1552.         movzx eax,edinsb
  1553.         add al,edinso
  1554.         imul esi,eax,13
  1555.         add esi,fminsnames
  1556.         movsd
  1557.         movsd
  1558.         movsd
  1559.         movsb
  1560.         mov dx,fminsnum
  1561.         mov bx,eiaddinsindx
  1562.         mov ecx,11
  1563.         mov ebp,eiaddinsbase
  1564.         call ins
  1565. eiaddinsf1:
  1566.         movzx eax,edinsb
  1567.         add al,edinso
  1568.         imul esi,eax,11
  1569.         add esi,fminsbase
  1570.         movsd
  1571.         movsd
  1572.         movsw
  1573.         movsb
  1574.         ret
  1575. eiaddinsf0:
  1576.         movzx edi,fminsnum
  1577.         imul edi,13
  1578.         imul eax,11
  1579.         add edi,eax
  1580.         add edi,fminsbank
  1581.         jmp eiaddinsf1
  1582.  
  1583. ;═════════════════════════════════════════════════════════════════════════════
  1584. editpatlist     db      34
  1585.                 dw      1,4,3,25,26,21,22,19,20,23,24,'[',']','.','-','+',13
  1586.                 dw      621,'`',262h,265h,26ch,275h,17,18,27ah,263h,26fh
  1587.                 dw      276h,269h,271h,261h,277h,273h
  1588. editpatrout     dd      epf1,epf2,epf4,epup,epdn,eppgup,eppgdn,ephome,epend
  1589.                 dd      epdecvoice,epincvoice,epcins,epcvol,epclear,epdecpat
  1590.                 dd      epincpat,epbreak,epcopypat,eppickup,epblkb,epblke
  1591.                 dd      epblkl,epblku,epins,epdel,epblkzero,epblkcopy
  1592.                 dd      epblkover,epblkvol,epblkins,epblkou,epblkod,epblknu
  1593.                 dd      epblknd
  1594. editpat:
  1595.         call putstat
  1596.         call putpat
  1597.         call putpatcur
  1598.         call getinput
  1599.         mov edx,offset editpatlist
  1600.         call _indexword
  1601.         jc short editpatf0
  1602.         call editpatrout[eax*4]
  1603.         jmp editpat
  1604. editpatf0:
  1605.         or ah,ah
  1606.         jnz editpat
  1607.         push ax
  1608.         call calcloc
  1609.         pop ax
  1610.         mov edx,offset nkeylist
  1611.         call _indexbyte
  1612.         jc editpat
  1613.         mov dl,edvoiceb
  1614.         add dl,edvoiceo
  1615.         cmp dl,3
  1616.         ja short editpatf1
  1617.         call adjoct
  1618. editpatf1:
  1619.         mov bl,edoct
  1620.         shl bl,4
  1621.         cmp al,12
  1622.         jb short editpatf2
  1623.         add al,10h-12
  1624. editpatf2:
  1625.         add bl,al
  1626.         mov bh,edvol
  1627.         movzx ecx,edinsb
  1628.         add cl,edinso
  1629.         shld ax,cx,20
  1630.         or bh,al
  1631.         shl ah,7
  1632.         or bl,ah
  1633.         mov [edi],bx
  1634.         mov al,dl
  1635.         mov ah,bl
  1636.         and ah,7fh
  1637.         mov bl,edvol
  1638.         cmp al,3
  1639.         ja editpatfm
  1640.         shl ecx,4
  1641.         add ecx,dinsbase
  1642.         mov esi,[ecx]
  1643.         mov ebp,[ecx+4]
  1644.         mov edx,[ecx+12]
  1645.         mov ecx,[ecx+8]
  1646.         call _sbnote
  1647.         push offset editpat
  1648.         jmp epdn
  1649. editpatfm:
  1650.         sub al,4
  1651.         imul edx,ecx,11
  1652.         add edx,fminsbase
  1653.         call _fmnote
  1654.         push offset editpat
  1655.         jmp epdn
  1656.  
  1657. ;-----------------------------------------------------------------------------
  1658. epf1:
  1659.         add esp,4
  1660.         call putpat
  1661.         jmp editins0
  1662. ;-----------------------------------------------------------------------------
  1663. epf2:
  1664.         add esp,4
  1665.         call putpat
  1666.         jmp editins1
  1667. ;-----------------------------------------------------------------------------
  1668. epf4:
  1669.         add esp,4
  1670.         call putpat
  1671.         jmp editord
  1672. ;-----------------------------------------------------------------------------
  1673. ephome:
  1674.         mov edrowo,0
  1675.         ret
  1676. ;-----------------------------------------------------------------------------
  1677. epend:
  1678.         mov edrowo,1fh
  1679.         ret
  1680. ;-----------------------------------------------------------------------------
  1681. epup:
  1682.         mov ah,-1
  1683.         jmp short epupdn
  1684. ;-----------------------------------------------------------------------------
  1685. epdn:
  1686.         mov ah,1
  1687. epupdn:
  1688.         mov al,edrowo
  1689.         add al,ah
  1690.         js eppgupdn
  1691.         cmp al,1fh
  1692.         ja eppgupdn
  1693.         mov edrowo,al
  1694.         ret
  1695. ;-----------------------------------------------------------------------------
  1696. eppgup:
  1697.         mov ah,-10h
  1698.         jmp short eppgupdn
  1699. ;-----------------------------------------------------------------------------
  1700. eppgdn:
  1701.         mov ah,10h
  1702. eppgupdn:
  1703.         mov al,edrowb
  1704.         add al,ah
  1705.         jns short eppgupdnf0
  1706.         mov edrowb,0
  1707.         ret
  1708. eppgupdnf0:
  1709.         cmp al,21h
  1710.         jb short eppgupdnf1
  1711.         mov al,20h
  1712. eppgupdnf1:
  1713.         mov edrowb,al
  1714.         ret
  1715. ;-----------------------------------------------------------------------------
  1716. epdecvoice:
  1717.         mov ah,-1
  1718.         jmp short epcvoice
  1719. ;-----------------------------------------------------------------------------
  1720. epincvoice:
  1721.         mov ah,1
  1722. epcvoice:
  1723.         mov al,edvoiceo
  1724.         add al,ah
  1725.         js epcvoiceb
  1726.         cmp al,10
  1727.         ja epcvoiceb
  1728.         mov edvoiceo,al
  1729.         ret
  1730. epcvoiceb:
  1731.         mov al,edvoiceb
  1732.         add al,ah
  1733.         js _ret
  1734.         cmp al,maxvoiceb
  1735.         ja _ret
  1736.         mov edvoiceb,al
  1737.         ret
  1738. ;-----------------------------------------------------------------------------
  1739. epcins:
  1740.         call calcloc
  1741.         cmp byte ptr [edi],0feh
  1742.         jae _ret
  1743.         call calcloc2
  1744.         add bl,3
  1745.         mov cl,2
  1746.         call getnum
  1747.         jc _ret
  1748.         and al,1fh
  1749.         call setins
  1750.         shl eax,4
  1751.         shl ah,7
  1752.         xchg al,ah
  1753.         and word ptr [edi],0f7fh
  1754.         or word ptr [edi],ax
  1755.         jmp epdn
  1756. ;-----------------------------------------------------------------------------
  1757. epcvol:
  1758.         call calcloc
  1759.         call calcloc2
  1760.         add bl,5
  1761.         mov cl,1
  1762.         call getnum
  1763.         jc _ret
  1764.         mov edvol,al
  1765.         cmp byte ptr [edi],0ffh
  1766.         jb short epcvolf0
  1767.         mov word ptr [edi],0feh
  1768. epcvolf0:
  1769.         and byte ptr [edi+1],0f0h
  1770.         or byte ptr [edi+1],al
  1771.         jmp epdn
  1772. ;-----------------------------------------------------------------------------
  1773. epclear:
  1774.         call calcloc
  1775.         mov word ptr [edi],-1
  1776.         jmp epdn
  1777. ;-----------------------------------------------------------------------------
  1778. epdecpat:
  1779.         mov ah,-1
  1780.         jmp short epchangepat
  1781. ;-----------------------------------------------------------------------------
  1782. epincpat:
  1783.         mov ah,1
  1784. epchangepat:
  1785.         push ax
  1786.         call setpat
  1787.         pop ax
  1788.         mov al,edpat
  1789.         add al,ah
  1790.         and al,7fh
  1791.         mov edpat,al
  1792.         call getpat
  1793.         ret
  1794. ;-----------------------------------------------------------------------------
  1795. epbreak:
  1796.         mov al,edrowb
  1797.         add al,edrowo
  1798.         mov mzbreak,al
  1799.         ret
  1800. ;-----------------------------------------------------------------------------
  1801. wpatstr db      'Copy to which pattern?',0
  1802. epcopypat:
  1803.         mov bx,181ah
  1804.         mov cx,61eh
  1805.         call _pushtext
  1806.         add bx,101h
  1807.         sub cx,101h
  1808.         mov ax,20h
  1809.         call _textbox0
  1810.         sub bx,101h
  1811.         mov edx,offset boxgrfx
  1812.         mov ah,87h
  1813.         call _textbox1
  1814.         add bx,202h
  1815.         mov edx,offset wpatstr
  1816.         mov ah,8fh
  1817.         call _putstr
  1818.         add bx,17h
  1819.         mov cl,2
  1820.         call getnum
  1821.         jc short epcopypatd
  1822.         mov ah,edpat
  1823.         push ax
  1824.         mov edpat,al
  1825.         call setpat
  1826.         pop ax
  1827.         mov edpat,ah
  1828. epcopypatd:
  1829.         call _poptext
  1830.         ret
  1831. ;-----------------------------------------------------------------------------
  1832. eppickup:
  1833.         call calcloc
  1834.         mov dx,[edi]
  1835.         cmp dl,-2
  1836.         ja _ret
  1837.         je short eppickupf0
  1838.         mov ah,dl
  1839.         mov al,dh
  1840.         shr ah,7
  1841.         shr eax,4
  1842.         call setins
  1843. eppickupf0:
  1844.         and dh,0fh
  1845.         mov edvol,dh
  1846.         ret
  1847. ;-----------------------------------------------------------------------------
  1848. epblkb:
  1849.     mov al,edrowb
  1850.     add al,edrowo
  1851.     mov edblkb,al
  1852.     ret
  1853. ;-----------------------------------------------------------------------------
  1854. epblke:
  1855.     mov al,edrowb
  1856.     add al,edrowo
  1857.     mov edblke,al
  1858.         ret
  1859. ;-----------------------------------------------------------------------------
  1860. epblkl:
  1861.     mov edblkb,0
  1862.     mov edblke,3fh
  1863.     ret
  1864. ;-----------------------------------------------------------------------------
  1865. epblku:
  1866.     mov edblkb,-1
  1867.     mov edblke,-1
  1868.         ret
  1869. ;-----------------------------------------------------------------------------
  1870. epins:
  1871.         mov idcall,offset ins
  1872.         jmp short epid
  1873. ;-----------------------------------------------------------------------------
  1874. epdel:
  1875.         mov idcall,offset del
  1876. epid:
  1877.         call gettrak
  1878.         mov dx,64
  1879.         movzx bx,edrowb
  1880.         add bl,edrowo
  1881.         mov ecx,2
  1882.         mov ebp,worktrak
  1883.         call idcall
  1884.         mov eax,-1
  1885.         stosw
  1886.         jmp puttrak
  1887. ;-----------------------------------------------------------------------------
  1888. epblkzero:
  1889.         call calc3
  1890. epblkzeroml:
  1891.         mov word ptr [edi],-1
  1892.         add edi,2
  1893.         loop epblkzeroml
  1894.         jmp puttrak
  1895. ;-----------------------------------------------------------------------------
  1896. epblkcopy:
  1897.         call calc3
  1898.         mov esi,edi
  1899.         mov edi,savetrak
  1900.         mov edblkl,cl
  1901.         rep movsw
  1902.         ret
  1903. ;-----------------------------------------------------------------------------
  1904. epblkover:
  1905.         call gettrak
  1906.         movzx ecx,edblkl
  1907.         or cl,cl
  1908.         js _ret
  1909.         movzx eax,edrowb
  1910.         add al,edrowo
  1911.         mov ebx,64
  1912.         sub ebx,eax
  1913.         cmp ecx,ebx
  1914.         jbe epblkoverf0
  1915.         mov ecx,ebx
  1916. epblkoverf0:
  1917.         mov esi,savetrak
  1918.         lea edi,[eax*2]
  1919.         add edi,worktrak
  1920.         mov bl,edvoiceb
  1921.         add bl,edvoiceo
  1922. epblkoverml:
  1923.         lodsw
  1924.         cmp al,0fdh
  1925.         ja short epblkovermlc
  1926.         cmp bl,3
  1927.         ja short epblkovermlc
  1928.         cmp al,1010000b
  1929.         jb short epblkovermlc
  1930.         and al,0bfh
  1931. epblkovermlc:
  1932.         stosw
  1933.         loop epblkoverml
  1934.         jmp puttrak
  1935. ;-----------------------------------------------------------------------------
  1936. epblkvol:
  1937.         call calc3
  1938.         mov esi,edi
  1939.         mov bl,edvol
  1940. epblkvolml:
  1941.         lodsw
  1942.         and ah,0f0h
  1943.         or ah,bl
  1944.         stosw
  1945.         loop epblkvolml
  1946.         jmp puttrak
  1947. ;-----------------------------------------------------------------------------
  1948. epblkins:
  1949.         call calc3
  1950.         mov esi,edi
  1951.         mov bl,edinsb
  1952.         add bl,edinso
  1953.         shl ebx,4
  1954.         shl bh,7
  1955.         xchg bl,bh
  1956. epblkinsml:
  1957.         lodsw
  1958.         cmp al,0fdh
  1959.         ja short epblkinsmlc
  1960.         and ax,0f7fh
  1961.         or ax,bx
  1962. epblkinsmlc:
  1963.         stosw
  1964.         loop epblkinsml
  1965.         jmp puttrak
  1966. ;-----------------------------------------------------------------------------
  1967. epblkou:
  1968.         mov dh,10h
  1969.         jmp short epblkoc
  1970. ;-----------------------------------------------------------------------------
  1971. epblkod:
  1972.         mov dh,-10h
  1973. epblkoc:
  1974.         call calc3
  1975.         mov esi,edi
  1976.         mov al,edvoiceb
  1977.         add al,edvoiceo
  1978.         mov dl,40h
  1979.         cmp al,4
  1980.         jb short epblkoml
  1981.         mov dl,70h
  1982. epblkoml:
  1983.         lodsw
  1984.         cmp al,0fdh
  1985.         ja short epblkomlc
  1986.         mov bl,al
  1987.         and bl,70h
  1988.         add bl,dh
  1989.         js short epblkomlc
  1990.         cmp bl,dl
  1991.         ja short epblkomlc
  1992.         and al,8fh
  1993.         or al,bl
  1994. epblkomlc:
  1995.         stosw
  1996.         loop epblkoml
  1997.         jmp puttrak
  1998. ;-----------------------------------------------------------------------------
  1999. epblknu:
  2000.         mov dh,1
  2001.         jmp short epblknc
  2002. ;-----------------------------------------------------------------------------
  2003. epblknd:
  2004.         mov dh,-1
  2005. epblknc:
  2006.         call calc3
  2007.         mov esi,edi
  2008.         mov al,edvoiceb
  2009.         add al,edvoiceo
  2010.         mov dl,4
  2011.         cmp al,4
  2012.         jb short epblknml
  2013.         mov dl,7
  2014. epblknml:
  2015.         lodsw
  2016.         cmp al,0fdh
  2017.         ja short epblknmlc
  2018.         mov bl,al
  2019.         and bl,0fh
  2020.         mov bh,al
  2021.         shr bh,4
  2022.         and bh,7
  2023.         add bl,dh
  2024.         js short epblknmlf0
  2025.         cmp bl,12
  2026.         jb short epblknmlf1
  2027.         sub bl,12
  2028.         jmp short epblknmlf2
  2029. epblknmlf0:
  2030.         add bl,12
  2031. epblknmlf2:
  2032.         add bh,dh
  2033.         js short epblknmlc
  2034.         cmp bh,dl
  2035.         ja short epblknmlc
  2036.         shl bh,4
  2037.         and al,8fh
  2038.         or al,bh
  2039. epblknmlf1:
  2040.         and al,0f0h
  2041.         or al,bl
  2042. epblknmlc:
  2043.         stosw
  2044.         loop epblknml
  2045.         jmp puttrak
  2046.  
  2047. ;─────────────────────────────────────────────────────────────────────────────
  2048. ; CL - number to start at
  2049. ; CH - number to do
  2050. ; EDI -> coordinates to start at
  2051. putnumbar:
  2052.         mov ebx,offset _hextbl
  2053.         mov ah,2
  2054. putnumbarml:
  2055.         mov al,cl
  2056.         shr al,4
  2057.         xlat
  2058.         stosw
  2059.         mov al,cl
  2060.         and al,0fh
  2061.         xlat
  2062.         stosw
  2063.         add edi,156
  2064.         inc cl
  2065.         dec ch
  2066.         jnz putnumbarml
  2067.         ret
  2068. ;─────────────────────────────────────────────────────────────────────────────
  2069. ; AH - attributes
  2070. ; EDX - number
  2071. ; EDI - coordinates
  2072. putnum5:
  2073.         mov ebx,offset _hextbl
  2074.         shl edx,12
  2075.         mov ecx,5
  2076. putnum5ml:
  2077.         rol edx,4
  2078.         mov al,dl
  2079.         and al,0fh
  2080.         xlat
  2081.         stosw
  2082.         loop putnum5ml
  2083.         ret
  2084. ;─────────────────────────────────────────────────────────────────────────────
  2085. ; AH - attributes
  2086. ; AL - number
  2087. ; EDI - coordinates
  2088. putnum2:
  2089.         mov ebx,offset _hextbl
  2090.         mov dl,al
  2091.         shr al,4
  2092.         xlat
  2093.         stosw
  2094.         mov al,dl
  2095.         and al,0fh
  2096.         xlat
  2097.         stosw
  2098.         ret
  2099. ;─────────────────────────────────────────────────────────────────────────────
  2100. ; AH - attributes
  2101. ; AL - number
  2102. ; EDI - coordinates
  2103. putnum1:
  2104.         mov ebx,offset _hextbl
  2105.         and al,0fh
  2106.         xlat
  2107.         stosw
  2108.         ret
  2109.  
  2110. ;-----------------------------------------------------------------------------
  2111. putcur:                                 ; routine for putcursor
  2112.         add edi,_vgatextptr
  2113. putcurl0:
  2114.         lodsb
  2115.         movzx ecx,al
  2116.         mov al,8fh
  2117. putcurl1:
  2118.         inc edi
  2119.         stosb
  2120.         loop putcurl1
  2121.         lodsb
  2122.         or al,al
  2123.         jz _ret
  2124.         movzx eax,al
  2125.         lea edi,[edi+eax*2]
  2126.         jmp putcurl0
  2127. ;─────────────────────────────────────────────────────────────────────────────
  2128. putins:                                 ; General put ins routine
  2129.         mov bx,17
  2130.         mov cx,0e2dh
  2131.         mov ax,1920h
  2132.         call _textbox0
  2133.         mov bx,17
  2134.         mov ah,13h
  2135.         mov edx,[esp+4]
  2136.         call _putstr
  2137.         mov edi,2
  2138.         mov edi,_vgatextptr
  2139.         add edi,160+2
  2140.         mov cl,edinsb
  2141.         mov ch,13
  2142.         call putnumbar
  2143.         mov ax,720h
  2144.         mov bx,104h
  2145.         mov cx,0d0ch
  2146.         call _textbox0
  2147.         movzx edx,edinsb
  2148.         imul edx,13
  2149.         add edx,[esp+8]
  2150.         mov ecx,13
  2151. putinsl0:
  2152.         call _putstr
  2153.         inc bh
  2154.         add edx,13
  2155.         loop putinsl0
  2156.         ret 8
  2157. ;─────────────────────────────────────────────────────────────────────────────
  2158. putins0str      db      'Lbeg  Lend  Len',0
  2159. putins0:                                ; Put digital instrument data
  2160.         push dinsnames
  2161.         push offset putins0str
  2162.         call putins
  2163.         movzx esi,edinsb
  2164.         imul esi,16
  2165.         add esi,dinsbase
  2166.         mov ecx,13
  2167.         mov ah,7
  2168.         mov edi,_vgatextptr
  2169.         add edi,160+34
  2170. putins0ml:
  2171.         push ecx
  2172.         mov edx,[esi+8]
  2173.         sub edx,[esi]
  2174.         call putnum5
  2175.         add edi,2
  2176.         mov edx,[esi+12]
  2177.         sub edx,[esi]
  2178.         call putnum5
  2179.         add edi,2
  2180.         mov edx,[esi+4]
  2181.         sub edx,[esi]
  2182.         call putnum5
  2183.         add edi,126
  2184.         add esi,16
  2185.         pop ecx
  2186.         loop putins0ml
  2187.         ret
  2188. ;─────────────────────────────────────────────────────────────────────────────
  2189. ins0curdat      db      2,1,12,1,5,1,5,1,5,0
  2190. putins0cur:                             ; Put digital instrument cursor
  2191.         movzx edi,edinso
  2192.         imul edi,160
  2193.         add edi,160+2
  2194.         mov esi,offset ins0curdat
  2195.         jmp putcur
  2196. ;─────────────────────────────────────────────────────────────────────────────
  2197. putins1str      db      'ArDrSlRrMlKsTlWsAVEK ArDrSlRrMlKsTlWsAVEK FbC',0
  2198. putins1pmns     db      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,2
  2199.                 db      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,2
  2200.                 db      0,0,1,0
  2201. putins1pm       dd      putnum2,putnum1
  2202. putins1:                                ; Put FM instrument data
  2203.         push fminsnames
  2204.         push offset putins1str
  2205.         call putins
  2206.         mov dh,edinsb
  2207.         mov edi,_vgatextptr
  2208.         add edi,160+34
  2209.         mov ecx,13
  2210. putins1l0:
  2211.         push ecx
  2212.         mov esi,offset putins1pmns
  2213.         xor cl,cl
  2214. putins1l1:
  2215.         mov ah,dh
  2216.         mov al,cl
  2217.         call getfminsval
  2218.         movzx ebp,byte ptr [esi]
  2219.         mov ah,7
  2220.         call putins1pm[ebp*4]
  2221.         movzx ebp,byte ptr [esi+1]
  2222.         add esi,2
  2223.         add edi,ebp
  2224.         inc cl
  2225.         cmp cl,26
  2226.         jb putins1l1
  2227.         inc dh
  2228.         add edi,70
  2229.         pop ecx
  2230.         loop putins1l0
  2231.         ret
  2232. ;─────────────────────────────────────────────────────────────────────────────
  2233. ins1curdat      db      2,1,12,1,20,1,20,1,3,0
  2234. ins1curdat2     db      0,1,2,1,4,1,6,1,8,1,10,1,12,1,14,1,16,0,17,0,18,0,19,0
  2235.                 db      21,1,23,1,25,1,27,1,29,1,31,1,33,1,35,1,37,0,38,0,39,0,40,0
  2236.                 db      42,1,44,0
  2237. putins1cur:                             ; Put FM instrument cursor
  2238.         movzx edi,edinso
  2239.         imul edi,160
  2240.         add edi,160+2
  2241.         mov esi,offset ins1curdat
  2242.         call putcur
  2243.         movzx esi,edfmval
  2244.         movzx edi,ins1curdat2[esi*2]
  2245.         lea edi,[edi*2+160+35]
  2246.         add edi,_vgatextptr
  2247.         movzx eax,edinso
  2248.         imul eax,160
  2249.         add edi,eax
  2250.         mov byte ptr [edi],0dh
  2251.         cmp ins1curdat2[esi*2+1],0
  2252.         je _ret
  2253.         mov byte ptr [edi+2],0dh
  2254.         ret
  2255. ;─────────────────────────────────────────────────────────────────────────────
  2256. putord:                                 ; Put order list
  2257.         mov edi,_vgatextptr
  2258.         add edi,160+148
  2259.         mov cl,edordb
  2260.         mov ch,13
  2261.         call putnumbar
  2262.         mov edi,_vgatextptr
  2263.         add edi,160+154
  2264.         movzx esi,edordb
  2265.         add esi,ordbase
  2266.         mov ecx,13
  2267.         mov ah,7
  2268. putordl0:
  2269.         lodsb
  2270.         cmp al,-1
  2271.         je short putordl0f0
  2272.         call putnum2
  2273.         jmp short putordl0c
  2274. putordl0f0:
  2275.         mov al,'·'
  2276.         stosw
  2277.         stosw
  2278. putordl0c:
  2279.         add edi,156
  2280.         loop putordl0
  2281.         ret
  2282. ;─────────────────────────────────────────────────────────────────────────────
  2283. ordcurdat       db      2,1,2,0
  2284. putordcur:                              ; Put order list cursor
  2285.         movzx edi,edordo
  2286.         imul edi,160
  2287.         add edi,160+148
  2288.         mov esi,offset ordcurdat
  2289.         jmp putcur
  2290. ;─────────────────────────────────────────────────────────────────────────────
  2291. statline db '  Tempo:_   Loop:__   Channel:__   Octave:_   Volume:_   Order:__   Pattern:__  ',0
  2292. putstat:                                ; Put stat line
  2293.         mov al,mztempo
  2294.         mov cl,0
  2295.         mov edx,offset statline+8
  2296.         call _putnumtomem
  2297.         mov al,mzloop
  2298.         mov cl,1
  2299.         mov edx,offset statline+17
  2300.         call _putnumtomem
  2301.         mov al,edvoiceb
  2302.         add al,edvoiceo
  2303.         mov cl,1
  2304.         mov edx,offset statline+30
  2305.         call _putnumtomem
  2306.         mov al,edoct
  2307.         mov cl,0
  2308.         mov edx,offset statline+42
  2309.         call _putnumtomem
  2310.         mov al,edvol
  2311.         mov cl,0
  2312.         mov edx,offset statline+53
  2313.         call _putnumtomem
  2314.         mov al,edordb
  2315.         add al,edordo
  2316.         mov cl,1
  2317.         mov edx,offset statline+63
  2318.         call _putnumtomem
  2319.         mov al,edpat
  2320.         mov cl,1
  2321.         mov edx,offset statline+76
  2322.         call _putnumtomem
  2323.         mov edx,offset statline
  2324.         mov bx,3100h
  2325.         mov ah,08fh
  2326.         call _putstr
  2327.         ret
  2328. ;─────────────────────────────────────────────────────────────────────────────
  2329. noteascii       db      'C·C#D·D#E·F·F#G·G#A·A#B·'
  2330. patchannels     db      '00  DL01  DR02  DL03  DR04  FL05  FR06  FL07  FR'
  2331.                 db      '08  FL09  FR0A  FL0B  FR0C  FL0D *FR0E *FL0F *FR'
  2332.                 db      '10 *FL11 *FR12 *FL13 *FR14 *FL15 *FR'
  2333. putpatphase     db      ?
  2334. putpatcolor     db      ?
  2335. putpat:                                 ; Put pattern
  2336.         mov edi,_vgatextptr
  2337.         add edi,16*160+2
  2338.         mov cl,edrowb
  2339.         mov ch,32
  2340.         call putnumbar
  2341.         mov ax,132dh
  2342.         mov bx,104fh
  2343.         mov cx,2001h
  2344.         call _textbox0
  2345.         movzx esi,edrowb
  2346.         imul esi,44
  2347.         add esi,workpatptr
  2348.         movzx eax,edvoiceb
  2349.         lea esi,[esi+eax*2]
  2350.         mov edi,_vgatextptr
  2351.         add edi,16*160+6
  2352.         mov ebp,20h
  2353.         mov al,edrowb
  2354.         dec al
  2355.         mov putpatphase,al
  2356. putpatl0:
  2357.         mov al,putpatphase
  2358.         inc al
  2359.         mov putpatphase,al
  2360.         test al,3
  2361.         setz ah
  2362.         shl ah,6
  2363.         mov putpatcolor,ah
  2364.         mov ecx,11
  2365. putpatl1:
  2366.         mov bl,[esi]
  2367.         cmp bl,0feh
  2368.         jb short putpatl1f0
  2369.         mov ax,7fah
  2370.         or ah,putpatcolor
  2371.         stosw
  2372.         stosw
  2373.         stosw
  2374.         stosw
  2375.         stosw
  2376.         cmp bl,-1
  2377.         jb short putpatl1f1
  2378.         stosw
  2379.         jmp short putpatl1c
  2380. putpatl1f0:
  2381.         mov ah,putpatcolor
  2382.         or ah,11
  2383.         movzx edx,bl
  2384.         and dl,0fh
  2385.         mov al,noteascii[edx*2]
  2386.         stosw
  2387.         mov al,noteascii[edx*2+1]
  2388.         stosw
  2389.         mov dl,bl
  2390.         mov al,bl
  2391.         shr al,4
  2392.         and al,7
  2393.         call putnum1
  2394.         mov ah,putpatcolor
  2395.         or ah,3
  2396.         mov al,[esi+1]
  2397.         shr al,4
  2398.         and dl,80h
  2399.         shr dl,3
  2400.         or al,dl
  2401.         call putnum2
  2402. putpatl1f1:
  2403.         mov ah,putpatcolor
  2404.         or ah,11
  2405.         mov al,[esi+1]
  2406.         call putnum1
  2407. putpatl1c:
  2408.         add esi,2
  2409.         add edi,2
  2410.         dec ecx
  2411.         jnz putpatl1
  2412.         add esi,22
  2413.         add edi,6
  2414.         dec ebp
  2415.         jnz putpatl0
  2416.         mov edi,_vgatextptr
  2417.         add edi,15*160+6
  2418.         movzx esi,edvoiceb
  2419.         imul esi,6
  2420.         add esi,offset patchannels
  2421.         mov ah,8fh
  2422.         mov ecx,11
  2423. putpatl2:
  2424.         lodsb
  2425.         stosw
  2426.         lodsb
  2427.         stosw
  2428.         lodsb
  2429.         stosw
  2430.         lodsb
  2431.         stosw
  2432.         lodsb
  2433.         stosw
  2434.         lodsb
  2435.         stosw
  2436.         add edi,2
  2437.         loop putpatl2
  2438.         mov bh,edblkb
  2439.         cmp bh,0ffh
  2440.         je putpatf2
  2441.         mov ch,edblke
  2442.         cmp ch,0ffh
  2443.         je putpatf2
  2444.         cmp ch,bh
  2445.     jae short putpatf3
  2446.     mov edblkb,-1
  2447.         mov edblke,-1
  2448.     jmp short putpatf2
  2449. putpatf3:
  2450.         mov al,edrowb
  2451.         cmp ch,al
  2452.         jb short putpatf2
  2453.         cmp bh,al
  2454.         jae putpatf0
  2455.         mov bh,al
  2456. putpatf0:
  2457.         add al,1fh
  2458.         cmp bh,al
  2459.         ja short putpatf2
  2460.         cmp ch,al
  2461.         jbe putpatf1
  2462.         mov ch,al
  2463. putpatf1:
  2464.         sub ch,bh
  2465.         inc ch
  2466.         sub bh,edrowb
  2467.         add bh,16
  2468.         mov bl,79
  2469.         mov cl,1
  2470.         mov ax,0b02dh
  2471.         call _textbox0
  2472.         movzx ecx,ch
  2473.         movzx edi,bh
  2474.         imul edi,160
  2475.         movzx eax,edvoiceo
  2476.         imul eax,14
  2477.         lea edi,[edi+eax+7]
  2478.         add edi,_vgatextptr
  2479.         mov byte ptr [edi],0ffh
  2480.         mov al,04eh
  2481. putpatl3:
  2482.         stosb
  2483.         inc edi
  2484.         stosb
  2485.         inc edi
  2486.         stosb
  2487.         inc edi
  2488.         stosb
  2489.         inc edi
  2490.         stosb
  2491.         inc edi
  2492.         stosb
  2493.         inc edi
  2494.         add edi,148
  2495.         loop putpatl3
  2496. putpatf2:
  2497.         mov edi,_vgatextptr
  2498.         add edi,16*160+158
  2499.         movzx eax,mzbreak
  2500.         sub al,edrowb
  2501.         jc _ret
  2502.         cmp al,1fh
  2503.         ja _ret
  2504.         imul eax,160
  2505.         add edi,eax
  2506.         mov byte ptr [edi],11h
  2507.         mov al,[edi+1]
  2508.         and al,0f0h
  2509.         or al,0fh
  2510.         mov [edi+1],al
  2511.         ret
  2512. ;─────────────────────────────────────────────────────────────────────────────
  2513. patcurdat       db      6,0
  2514. putpatcur:
  2515.         movzx edi,edrowo
  2516.         imul edi,160
  2517.         add edi,16*160+6
  2518.         movzx eax,edvoiceo
  2519.         imul eax,14
  2520.         add edi,eax
  2521.         mov esi,offset patcurdat
  2522.         jmp putcur
  2523.  
  2524. ;─────────────────────────────────────────────────────────────────────────────
  2525. clearsong:                              ; Clear song
  2526.         call _stopmuzik
  2527.         mov mztempo,6
  2528.         mov mzloop,0
  2529.         xor al,al
  2530.         mov edvol,0fh
  2531.         mov edoct,2
  2532.         mov edpat,al
  2533.         mov edvoiceb,al
  2534.         mov edvoiceo,al
  2535.         mov edrowb,al
  2536.         mov edrowo,al
  2537.         mov edinsb,al
  2538.         mov edinso,al
  2539.         mov edordb,al
  2540.         mov edordo,al
  2541.         mov edfmval,al
  2542.         mov edi,ordbase
  2543.         mov eax,-1
  2544.         mov ecx,40h
  2545.         rep stosd
  2546.         mov edi,patbase
  2547.         mov eax,604040h
  2548.         mov ecx,80h
  2549. clearsongl0:
  2550.         stosd
  2551.         dec edi
  2552.         loop clearsongl0
  2553.         mov edi,patoffbase
  2554.         mov ecx,80h
  2555.         xor eax,eax
  2556. clearsongl1:
  2557.         stosd
  2558.         add eax,3
  2559.         loop clearsongl1
  2560.         mov edi,patlenbase
  2561.         mov ecx,80h
  2562.         mov eax,3
  2563.         rep stosd
  2564.         xor eax,eax
  2565.         mov edi,dinsbase
  2566.         mov ecx,32
  2567. clearsongl2:
  2568.         xor eax,eax
  2569.         stosd
  2570.         stosd
  2571.         stosd
  2572.         mov eax,0ffffffh
  2573.         stosd
  2574.         loop clearsongl2
  2575.         xor eax,eax
  2576.         mov edi,fminsbase
  2577.         mov ecx,11*8
  2578.         rep stosd
  2579.         mov edi,dinsnames
  2580.         mov ecx,13*8
  2581.         rep stosd
  2582.         mov edi,fminsnames
  2583.         mov ecx,13*8
  2584.         rep stosd
  2585. putall:
  2586.         call getpat
  2587.         call putins0
  2588.         call putpat
  2589.         call putord
  2590.         call putstat
  2591.         call adjsmp
  2592. _retc:
  2593.         stc
  2594.         ret
  2595.  
  2596. ;─────────────────────────────────────────────────────────────────────────────
  2597. adjsmp:                                 ; defragment sample memory...
  2598.         call _stopmuzik
  2599. ;        @rlp ebp,100000h
  2600.         mov ebp,_himembase
  2601. adjsmpl1:
  2602.         xor ebx,ebx
  2603.         mov ecx,20h
  2604.         mov edx,-1
  2605.         mov esi,dinsbase
  2606. adjsmpl2:
  2607.         mov eax,[esi+4]
  2608.         or eax,eax
  2609.         je short adjsmpl2c
  2610.         cmp eax,ebx
  2611.         jb short adjsmpl2f1
  2612.         mov ebx,eax
  2613. adjsmpl2f1:
  2614.         mov eax,[esi]
  2615.         cmp eax,ebp
  2616.         jb short adjsmpl2c
  2617.         cmp eax,edx
  2618.         ja short adjsmpl2c
  2619.         mov edi,esi
  2620.         mov edx,eax
  2621. adjsmpl2c:
  2622.         add esi,16
  2623.         loop adjsmpl2
  2624.         cmp edx,-1
  2625.         je short adjsmpdone
  2626.         cmp edx,ebp
  2627.         je short adjsmpl1c
  2628.         push edi
  2629.         mov eax,edx
  2630.         sub eax,ebp
  2631.         mov ecx,20h
  2632.         mov esi,dinsbase
  2633. adjsmpl3:
  2634.         cmp [esi],ebp
  2635.         jb short adjsmpl3c
  2636.         sub [esi],eax
  2637.         sub [esi+4],eax
  2638.         sub [esi+8],eax
  2639.         sub [esi+12],eax
  2640. adjsmpl3c:
  2641.         add esi,16
  2642.         loop adjsmpl3
  2643.         mov esi,edx
  2644.         mov edi,ebp
  2645.         mov ecx,ebx
  2646.         sub ecx,esi
  2647.         rep movsb
  2648.         pop edi
  2649. adjsmpl1c:
  2650.         mov ebp,[edi+4]
  2651.         jmp adjsmpl1
  2652. adjsmpdone:
  2653.         mov smpbase,ebp
  2654.         ret
  2655.  
  2656. ;─────────────────────────────────────────────────────────────────────────────
  2657. ; CX - number of strings
  2658. ; EBP - 13 byte ASCIIZstrings
  2659. alph:
  2660.         cmp cx,2
  2661.         jb _ret
  2662.         movzx edx,cx
  2663.         dec edx
  2664. alphl1:
  2665.         mov ecx,edx
  2666.         mov esi,ebp
  2667. alphl2:
  2668.         push cx
  2669.         push esi
  2670.         mov edi,esi
  2671.         add edi,13
  2672.         mov cx,13
  2673.         repe cmpsb
  2674.         jb alphl2c
  2675.         pop esi
  2676.         pop cx
  2677.         mov cx,13
  2678. alphl3:
  2679.         lodsb
  2680.         xchg al,[esi+12]
  2681.         mov [esi-1],al
  2682.         loop alphl3
  2683.         jmp alphl1
  2684. alphl2c:
  2685.         pop esi
  2686.         pop cx
  2687.         add esi,13
  2688.         loop alphl2
  2689.         ret
  2690.  
  2691. ;─────────────────────────────────────────────────────────────────────────────
  2692. alphfindbp      dd      ?
  2693. ; EBX - total strings present
  2694. ; ESI - base of strings
  2695. ; EBP - string to place
  2696. ; out:
  2697. ;  EAX - index to put string at
  2698. alphfind:
  2699.         mov alphfindbp,esi
  2700.         mov edx,ebp
  2701.         call _strlen
  2702.         lea edx,[eax+1]
  2703.         xor eax,eax
  2704. alphfindml:
  2705.         mov ecx,edx
  2706.         mov edi,ebp
  2707.         repe cmpsb
  2708.         je _retc
  2709.         ja _retnc
  2710.         mov esi,alphfindbp
  2711.         add esi,13
  2712.         mov alphfindbp,esi
  2713.         inc eax
  2714.         dec ebx
  2715.         jnz alphfindml
  2716. _retnc:
  2717.         clc
  2718.         ret
  2719.  
  2720. ;─────────────────────────────────────────────────────────────────────────────
  2721. ; DX - total items present
  2722. ; BX - number to insert at
  2723. ; EBP - base of list
  2724. ; ECX - size of each item
  2725. ; out:
  2726. ;  EDI - item to fill with blank
  2727. ins:
  2728.         movzx esi,bx
  2729.         imul esi,ecx
  2730.         add esi,ebp
  2731.         lea edi,[esi+ecx]
  2732.         sub dx,bx
  2733.         movzx edx,dx
  2734.         dec edx
  2735.         jz short insdone
  2736.         imul ecx,edx
  2737.         call _copymem
  2738. insdone:
  2739.         mov edi,esi
  2740.         ret
  2741. ;─────────────────────────────────────────────────────────────────────────────
  2742. ; DX - total items present
  2743. ; BX - number to insert at
  2744. ; EBP - base of list
  2745. ; ECX - size of each item
  2746. ; out:
  2747. ;  EDI - item to fill with blank
  2748. del:
  2749.         movzx eax,dx
  2750.         dec eax
  2751.         imul eax,ecx
  2752.         add eax,ebp
  2753.         movzx edi,bx
  2754.         imul edi,ecx
  2755.         add edi,ebp
  2756.         lea esi,[edi+ecx]
  2757.         sub dx,bx
  2758.         movzx edx,dx
  2759.         dec edx
  2760.         jz short deldone
  2761.         imul ecx,edx
  2762.         call _copymem
  2763. deldone:
  2764.         mov edi,eax
  2765.         ret
  2766.  
  2767. ;─────────────────────────────────────────────────────────────────────────────
  2768. ; BL,BH - X and Y
  2769. ; CL - number of digits
  2770. ; out:
  2771. ;  EAX - number
  2772. getnum:
  2773.         mov ax,8a01h
  2774.         mov edx,offset errmsg0
  2775.         mov byte ptr [edx],0
  2776.         mov ebp,offset numlist
  2777.         call _getstr
  2778.         jc _ret
  2779.         cmp byte ptr [edx],0
  2780.         je _retc
  2781.         call _strltu
  2782.         call _strhtn
  2783.         clc
  2784.         ret
  2785.  
  2786. ;─────────────────────────────────────────────────────────────────────────────
  2787. sellist db      9
  2788.         dw      14,32,13,21,22,25,26,19,20
  2789. selrout dd      selectexit,selectdone,selectdone,selpgup,selpgdn,selup,seldn
  2790.         dd      selhome,selend
  2791. sels    dd      ?
  2792. selbp   dd      ?
  2793. seln    dw      ?
  2794. selb    dw      ?
  2795. selo    db      ?
  2796. seli    db      ?
  2797. selbs   dw      0,0
  2798. selos   db      0,0
  2799. selbps  dd      ?,?
  2800. ; EDX -> 13 byte ASCIIZ strings
  2801. ; ECX - number present
  2802. ; out:
  2803. ;  EAX - index
  2804. select:
  2805.         movzx ebx,seli
  2806.         mov eax,selbps[ebx*4]
  2807.         mov selbp,eax
  2808.         mov ax,selbs[ebx*2]
  2809.         mov selb,ax
  2810.         mov al,selos[ebx]
  2811.         mov selo,al
  2812.         mov sels,edx
  2813.         mov seln,cx
  2814.         mov bx,32
  2815.         mov cx,3210h
  2816.         call _pushtext
  2817.         mov ax,7020h
  2818.         call _textbox0
  2819. selectml:
  2820.         mov bx,33
  2821.         mov cx,320eh
  2822.         mov ax,7020h
  2823.         call _textbox0
  2824.         movzx ecx,seln
  2825.         movzx edx,selb
  2826.         sub ecx,edx
  2827.         cmp ecx,50
  2828.         jbe short selectf0
  2829.         mov ecx,50
  2830. selectf0:
  2831.         mov edx,selbp
  2832.         inc bl
  2833. selectl0:
  2834.         call _putstr
  2835.         inc bh
  2836.         add edx,13
  2837.         loop selectl0
  2838.         movzx edi,selo
  2839.         imul edi,160
  2840.         add edi,_vgatextptr
  2841.         add edi,67
  2842.         mov al,15
  2843.         mov ecx,14
  2844. selectl1:
  2845.         stosb
  2846.         inc edi
  2847.         loop selectl1
  2848. selectml2:
  2849.         call _getch
  2850.         mov edx,offset sellist
  2851.         call _indexword
  2852.         jc short selectfind
  2853.         push offset selectml
  2854.         jmp selrout[eax*4]
  2855. ;-----------------------------------------------------------------------------
  2856. selectfind:
  2857.         or ah,ah
  2858.         jnz selectml2
  2859.         mov edx,sels
  2860.         movzx ecx,seln
  2861. selectfindml:
  2862.         cmp al,[edx]
  2863.         jz short selectfindf0
  2864.         add edx,13
  2865.         loop selectfindml
  2866.         cmp al,'a'
  2867.         jb selectml2
  2868.         cmp al,'z'
  2869.         ja selectml2
  2870.         add al,'A'-'a'
  2871.         jmp selectfind
  2872. selectfindf0:
  2873.         mov selbp,edx
  2874.         mov ax,seln
  2875.         sub ax,cx
  2876.         mov selb,ax
  2877.         mov selo,0
  2878.         jmp selectml
  2879. ;-----------------------------------------------------------------------------
  2880. selup:
  2881.         mov bx,-1
  2882.         jmp short selupdn
  2883. ;-----------------------------------------------------------------------------
  2884. seldn:
  2885.         mov bx,1
  2886. selupdn:
  2887.         mov al,selo
  2888.         add al,bl
  2889.         js short selpgupdn
  2890.         movzx cx,al
  2891.         add cx,selb
  2892.         cmp cx,seln
  2893.         jae _ret
  2894.         cmp al,49
  2895.         ja selpgupdn
  2896.         mov selo,al
  2897.         ret
  2898. ;-----------------------------------------------------------------------------
  2899. selpgup:
  2900.         mov bx,-50
  2901.         jmp short selupdn
  2902. ;-----------------------------------------------------------------------------
  2903. selpgdn:
  2904.         mov bx,50
  2905. selpgupdn:
  2906.         mov ax,selb
  2907.         add ax,bx
  2908.         js _ret
  2909.         movzx cx,selo
  2910.         add cx,ax
  2911.         cmp cx,seln
  2912.         jae _ret
  2913.         movsx ebx,bx
  2914.         imul ebx,13
  2915.         add selbp,ebx
  2916.         mov selb,ax
  2917.         ret
  2918. ;-----------------------------------------------------------------------------
  2919. selectdone:
  2920.         movzx ebx,seli
  2921.         mov eax,selbp
  2922.         mov selbps[ebx*4],eax
  2923.         mov ax,selb
  2924.         mov selbs[ebx*2],ax
  2925.         mov al,selo
  2926.         mov selos[ebx],al
  2927.         add esp,4
  2928.         call _poptext
  2929.         movzx eax,selo
  2930.         add ax,selb
  2931.         clc
  2932.         ret
  2933. ;-----------------------------------------------------------------------------
  2934. selectexit:
  2935.         add esp,4
  2936.         call _poptext
  2937.         stc
  2938.         ret
  2939. ;-----------------------------------------------------------------------------
  2940. selhome:
  2941.         mov selo,0
  2942.         ret
  2943. ;-----------------------------------------------------------------------------
  2944. selend:
  2945.         mov ax,seln
  2946.         sub ax,selb
  2947.         cmp ax,51
  2948.         jb short selendf0
  2949.         mov al,50
  2950. selendf0:
  2951.         dec al
  2952.         mov selo,al
  2953.         ret
  2954.  
  2955. ;─────────────────────────────────────────────────────────────────────────────
  2956. fminsvaldat     db      3,4,15, 3,0,15, 4,4,15, 4,0,15, 1,0,15, 2,6,3, 2,0,63, 5,0,3, 1,7,1,1,6,1,1,5,1,1,4,1
  2957.                 db      8,4,15, 8,0,15, 9,4,15, 9,0,15, 6,0,15, 7,6,3, 7,0,63, 10,0,3, 6,7,1,6,6,1,6,5,1,6,4,1
  2958.                 db      0,1,7, 0,0,1
  2959. ; AH - instrument
  2960. ; AL - value number
  2961. ; out AL - val
  2962. getfminsval:
  2963.         push ebx
  2964.         push ecx
  2965.         push edx
  2966.         movzx edx,ah
  2967.         imul edx,11
  2968.         add edx,fminsbase
  2969.         movzx ebx,al
  2970.         lea ebx,[ebx*2+ebx+fminsvaldat]
  2971.         movzx ecx,byte ptr [ebx]
  2972.         add edx,ecx
  2973.         mov cl,[ebx+1]
  2974.         mov al,[edx]
  2975.         shr al,cl
  2976.         and al,[ebx+2]
  2977.         pop edx
  2978.         pop ecx
  2979.         pop ebx
  2980.         ret
  2981. ;─────────────────────────────────────────────────────────────────────────────
  2982. ; AH - instrument
  2983. ; AL - value number
  2984. ; BL - val
  2985. setfminsval:
  2986.         push ax
  2987.         push ecx
  2988.         push edx
  2989.         push edi
  2990.         movzx edx,ah
  2991.         imul edx,11
  2992.         add edx,fminsbase
  2993.         movzx edi,al
  2994.         lea edi,[edi*2+edi+fminsvaldat]
  2995.         movzx ecx,byte ptr [edi]
  2996.         add edx,ecx
  2997.         mov cl,[edi+1]
  2998.         mov ch,[edx]
  2999.         mov al,[edi+2]
  3000.         shl al,cl
  3001.         not al
  3002.         and ch,al
  3003.         mov al,bl
  3004.         and al,[edi+2]
  3005.         shl al,cl
  3006.         or al,ch
  3007.         mov [edx],al
  3008.         pop edi
  3009.         pop edx
  3010.         pop ecx
  3011.         pop ax
  3012.         ret
  3013.  
  3014. ;─────────────────────────────────────────────────────────────────────────────
  3015. getpatrout      dd      getpat0,getpat1,getpat2,getpat3
  3016. getpat:                                 ; Unsquish EDPAT to work buffer
  3017.         mov edi,workpatptr
  3018.         mov eax,-1
  3019.         mov ecx,11*64
  3020.         rep stosd
  3021.         movzx esi,edpat
  3022.         shl esi,2
  3023.         add esi,patoffbase
  3024.         mov esi,[esi]
  3025.         add esi,patbase
  3026.         mov edi,workpatptr
  3027.         xor edx,edx
  3028. getpatml:
  3029.         lodsb
  3030.         movzx ebx,al
  3031.         shr bl,5
  3032.         jmp getpatrout[ebx*4]
  3033. getpat0:
  3034.         movzx ebx,al
  3035.         and bl,1fh
  3036.         lodsw
  3037.         mov [edi+ebx*2],ax
  3038.         jmp getpatml
  3039. getpat1:
  3040.         movzx ebx,al
  3041.         and bl,1fh
  3042.         lodsb
  3043.         mov ah,al
  3044.         mov al,0feh
  3045.         mov [edi+ebx*2],ax
  3046.         jmp getpatml
  3047. getpat2:
  3048.         lodsb
  3049.         movzx ebx,al
  3050.         add dl,al
  3051.         imul ebx,44
  3052.         add edi,ebx
  3053.         jmp getpatml
  3054. getpat3:
  3055.         dec dl
  3056.         mov mzbreak,dl
  3057.         ret
  3058.  
  3059. ;─────────────────────────────────────────────────────────────────────────────
  3060. setpat:                                 ; Squish work buffer to EDPAT
  3061.         mov esi,workpatptr
  3062.         mov edi,buildpat
  3063.         xor edx,edx
  3064. setpatl0:
  3065.         mov ecx,22
  3066. setpatl1:
  3067.         mov ah,[esi]
  3068.         cmp ah,0feh
  3069.         ja short setpatl1c
  3070.         call setpatrout
  3071.         mov al,22
  3072.         sub al,cl
  3073.         cmp ah,0feh
  3074.         jb short setpatl1f0
  3075.         or al,20h
  3076.         jmp short setpatl1f1
  3077. setpatl1f0:
  3078.         stosb
  3079.         mov al,ah
  3080. setpatl1f1:
  3081.         stosb
  3082.         mov al,[esi+1]
  3083.         stosb
  3084. setpatl1c:
  3085.         add esi,2
  3086.         loop setpatl1
  3087.         add dx,101h
  3088.         cmp dh,mzbreak
  3089.         jbe setpatl0
  3090.         call setpatrout
  3091.         mov al,60h
  3092.         stosb
  3093.         movzx ebp,edpat
  3094.         mov edx,edi
  3095.         sub edx,buildpat
  3096.         push edx
  3097.         lea ebx,[ebp*4]
  3098.         add ebx,patlenbase
  3099.         xchg edx,[ebx]
  3100.         sub edx,[ebx]
  3101.         cmp ebp,7fh
  3102.         je short setpatf0
  3103.         lea esi,[ebp*4+4]
  3104.         add esi,patoffbase
  3105.         mov esi,[esi]
  3106.         mov ecx,patoffbase
  3107.         mov ecx,[ecx+4*127]
  3108.         mov ebx,patlenbase
  3109.         add ecx,[ebx+4*127]
  3110.         sub ecx,esi
  3111.         add esi,patbase
  3112.         mov edi,esi
  3113.         sub edi,edx
  3114.         call _copymem
  3115. setpatf0:
  3116.         pop ecx
  3117.         mov esi,buildpat
  3118.         lea edi,[ebp*4]
  3119.         add edi,patoffbase
  3120.         mov edi,[edi]
  3121.         add edi,patbase
  3122.         rep movsb
  3123.         mov ecx,7fh
  3124.         sub ecx,ebp
  3125.         jz _ret
  3126.         lea ebp,[ebp*4+4]
  3127.         add ebp,patoffbase
  3128. setpatl2:
  3129.         sub [ebp],edx
  3130.         add ebp,4
  3131.         loop setpatl2
  3132.         ret
  3133. ;-----------------------------------------------------------------------------
  3134. setpatrout:
  3135.         or dl,dl
  3136.         jz _ret
  3137.         mov al,40h
  3138.         stosb
  3139.         mov al,dl
  3140.         stosb
  3141.         xor dl,dl
  3142.         ret
  3143.  
  3144.  
  3145. code32  ends
  3146.         end
  3147.