home *** CD-ROM | disk | FTP | other *** search
/ Assembly 1994 - The 3rd Phase / ASMROM94.mdf / fc / other / sp2.asm < prev    next >
Assembly Source File  |  1993-11-25  |  21KB  |  977 lines

  1. ;--------------------------------------------------------------------
  2. ;                  StarPort Intro II V1.0
  3. ;--------------------------------------------------------------------
  4. ;              Copyright (C) 1993 Future Crew
  5. ;--------------------------------------------------------------------
  6. ;                        code: Psi
  7. ;                       music: Skaven
  8. ;--------------------------------------------------------------------
  9. ;    This code is released to the public domain. You can do
  10. ;    whatever you like with this code, but remember, that if
  11. ;    you are just planning on making another small intro by
  12. ;    changing a few lines of code, be prepared to enter the
  13. ;    worldwide lamers' club. However, if you are looking at
  14. ;    this code in hope of learning something new, go right 
  15. ;    ahead. That's exactly why this source was released. 
  16. ;    (BTW: I don't claim there's anything new to find here,
  17. ;    but it's always worth looking, right?) 
  18. ;--------------------------------------------------------------------
  19. ;    The code is optimized mainly for size but also a little
  20. ;    for speed. The goal was to get this little bbs intro to
  21. ;    under 2K, and 1993 bytes sounded like a good size. Well,
  22. ;    it wasn't easy, and there are surely places left one could 
  23. ;    squeeze a few extra bytes off...
  24. ;      Making a small intro is not hard. Making a small intro
  25. ;    with a nice feel is very hard, and you have to sacrifice
  26. ;    ideas to fit the intro to the limits you have set. I had
  27. ;    a lot of plans (a background piccy for example), but well,
  28. ;    the size limit came first.
  29. ;      I hope you enjoy my choice of size/feature ratio in this
  30. ;    intro! In case you are interested, this was a three evening
  31. ;    project (the last one spent testing).
  32. ;--------------------------------------------------------------------
  33. ;    You can compile this with TASM, but the resulting COM-file
  34. ;    will be a lot larger than the released version. This is
  35. ;    because all the zero data is included to the result. The
  36. ;    released version was first compiled to a COM file, and then
  37. ;    a separate postprocessing program was ran which removed all
  38. ;    the zero data from the end of the file. If you are just 
  39. ;    experimenting, recompiling is as easy as MAKE.BAT. If you
  40. ;    want to make this small again, you have to do some work as
  41. ;    well, and make your own postprocessor.
  42. ;--------------------------------------------------------------------
  43.  
  44. BORDERS=0    ;set to 1 for visible border-timings
  45.  
  46. code     SEGMENT para public 'CODE'
  47.     ASSUME cs:code
  48.     LOCALS
  49.     .386
  50.  
  51. ORG    100h
  52. start:    cld    ;filler to make the filesize exactly 1993 bytes
  53.     cld    ;filler to make the filesize exactly 1993 bytes
  54.     jmp    main
  55.  
  56. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ setborder ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  57. ;descr: debug/change border color
  58. setborder MACRO col
  59.     IF BORDERS
  60.     push    ax
  61.     push    dx
  62.     mov    dx,3dah
  63.     in    al,dx
  64.     mov    dx,3c0h
  65.     mov    al,11h+32
  66.     out    dx,al
  67.     mov    al,col
  68.     out    dx,al
  69.     pop    dx
  70.     pop    ax
  71.     ENDIF
  72.     ENDM
  73.  
  74. ;████████████████ Simplex Adlib Player ████████████████
  75. ;this doesn't just read raw data to output to adlib like the one
  76. ;used in the last starport intro. This player really does have 
  77. ;note & instrument data it reads and processes!
  78.  
  79. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ output data to adlib ▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  80. a_lodsboutaw03: ;size optimization related entry (instrument loading)
  81.     call    a_lodsboutaw
  82.     add    ah,3
  83. a_lodsboutaw: ;size optimization related entry (instrument loading)
  84.     lodsb
  85. a_outaw    PROC NEAR ;ah=reg,al=data
  86.     push    ax
  87.     push    cx
  88.     xchg    al,ah
  89.     mov    dx,388h
  90.     out    dx,al
  91.     mov    cx,7
  92.     call    a_wait
  93.     mov    dx,389h
  94.     mov    al,ah
  95.     out    dx,al
  96.     mov    cx,30
  97.     call    a_wait
  98.     pop    cx
  99.     pop    ax
  100.     ret
  101. a_wait:    in    al,dx
  102.     loop    a_wait
  103.     ret
  104. a_outaw    ENDP
  105.  
  106. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ load instrument to adlib ▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  107. a_loadinstrument PROC NEAR
  108.     ;bx=channel, ds:si=offset to instrument data
  109.     mov    ah,ds:a_inst_table[bx]
  110.     mov    cx,4
  111. @@1:    call    a_lodsboutaw03
  112.     add    ah,20h-3
  113.     loop    @@1
  114.     add    ah,40h
  115.     call    a_lodsboutaw03
  116.     mov    ah,bl
  117.     add    ah,0c0h
  118.     jmp    a_lodsboutaw
  119. a_loadinstrument ENDP
  120.  
  121. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ set note on/off ▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  122. a_playnote PROC NEAR
  123.     ;bx=channel, ax=data
  124.     push    bx
  125.     xchg    ah,bl
  126.     add    ah,0a0h
  127.     call    a_outaw
  128.     mov    al,bl
  129.     add    ah,010h
  130.     pop    bx
  131.     jmp    a_outaw
  132. a_playnote ENDP
  133.  
  134. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ initialize/clear/shutup adlib ▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  135. a_init PROC NEAR
  136.     mov    ax,00120h
  137.     call    a_outaw
  138.     mov    ax,00800h
  139.     call    a_outaw
  140.     mov    ah,0bdh
  141.     call    a_outaw
  142.     mov    bp,9
  143.     xor    bx,bx
  144.     mov    di,OFFSET music_instruments
  145. @@1:    mov    si,ds:[di]
  146.     add    di,2
  147.     call    a_loadinstrument
  148.     xor    ax,ax
  149.     call    a_playnote
  150.     inc    bx
  151.     dec    bp
  152.     jnz    @@1    
  153.     ret
  154. a_init ENDP
  155.  
  156. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ advance music one row ▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  157. a_dorow PROC NEAR
  158.     sub    ds:a_musiccnt,1
  159.     jnc    @@0
  160.     mov    ds:a_musiccnt,music_speed
  161.     mov    cx,music_channels
  162.     mov    di,OFFSET music_patterns
  163.     xor    bx,bx
  164. @@1:    sub    ds:a_chdelaycnt[bx],1
  165.     jns    @@2
  166.     mov    si,ds:[di]    
  167.     xor    ax,ax
  168.     call    a_playnote
  169. @@4:    lodsb    
  170.     or    al,al
  171.     jz    @@7
  172.     jns    @@6
  173.     sub    al,81h
  174.     mov    ds:a_chdelay[bx],al
  175.     lodsb
  176. @@6:    mov    dl,al
  177.     and    ax,15
  178.     mov    bp,ax
  179.     add    bp,bp
  180.     mov    ax,ds:a_note_table[bp]
  181.     shr    dl,2
  182.     and    dl,not 3
  183.     add    ah,dl
  184.     call    a_playnote
  185.     mov    al,ds:a_chdelay[bx]
  186.     mov    ds:a_chdelaycnt[bx],al
  187.     mov    ds:[di],si
  188. @@2:    add    di,4
  189.     inc    bx
  190.     loop    @@1
  191. @@0:    ret
  192. @@7:    mov    si,ds:[di+2]
  193.     jmp    @@4
  194. a_dorow ENDP
  195.  
  196. ;███████████████ Intro Routines ████████████████████
  197.  
  198. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ sin/cos ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  199. ;entry: ax=angle (0..65535)
  200. ; exit: ax=muller (-127..127)
  201. addwcos:add    ax,ds:[bx] ;optimized entry for wavesets
  202.     mov    ds:[bx],ax
  203. cos:    add    ax,16384
  204. sin:    mov    bx,ax
  205.     mov    cx,bx
  206.     and    cx,1023
  207.     neg    cx
  208.     add    cx,1023
  209.     shr    bx,10
  210.     mov    ah,ds:sintable[bx]
  211.     xor    al,al
  212.     imul    cx
  213.     push    ax
  214.     push    dx
  215.     mov    ah,ds:sintable[bx+1]
  216.     xor    al,al
  217.     neg    cx
  218.     add    cx,1023
  219.     imul    cx
  220.     pop    bx
  221.     pop    cx
  222.     add    ax,cx
  223.     adc    dx,bx
  224.     shrd    ax,dx,11
  225.     ret
  226.  
  227. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ rand ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  228. ;returns a random value in range -4096..4095
  229. rand    PROC NEAR
  230.     mov    eax,1107030247
  231.     mul    ds:seed
  232.     add    eax,97177
  233.     mov    ds:seed,eax
  234.     shr    eax,15
  235.     and    ax,8191
  236.     sub    ax,4096
  237. ;size optimizatin, some code moved from after all rand calls
  238.     add    bx,2
  239.     mov    ds:[bx],ax
  240.     ret
  241. rand    ENDP
  242.  
  243. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ timer ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  244. inittimer PROC NEAR
  245.     mov    eax,fs:[8*4]
  246.     mov    ds:oldint8,eax
  247.     mov    ax,cs
  248.     shl    eax,16
  249.     mov    ax,OFFSET intti8
  250.     mov    dx,17000 ;70hz
  251.     jmp    @@1
  252. deinittimer:
  253.     mov    eax,ds:oldint8
  254.     xor    dx,dx
  255. @@1:    cli
  256.     mov    fs:[8*4],eax
  257.     mov    al,036h
  258.     out    43h,al
  259.     mov    al,dl
  260.     out    40h,al
  261.     mov    al,dh
  262.     out    40h,al
  263.     sti
  264.     ret
  265. inittimer ENDP
  266.  
  267. intti8    PROC FAR ;timer interrupt
  268.     push    ax
  269.     mov    al,20h
  270.     out    20h,al
  271.     inc    cs:framecounter
  272.     pop    ax
  273.     iret
  274. intti8    ENDP
  275.  
  276. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ load indexed palette ▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  277. setpal    PROC NEAR
  278.     ;ds:si=pointer to colorindices
  279.     mov    dx,3c8h
  280.     xor    al,al
  281.     out    dx,al
  282.     inc    dx
  283.     mov    cx,8
  284. @@1:    xor    bh,bh
  285.     mov    bl,ds:[si]
  286.     shr    bl,2
  287.     call    setpl2
  288.     mov    bl,ds:[si]
  289.     shl    bx,2
  290.     call    setpl2
  291.     inc    si
  292.     loop    @@1
  293.     ret
  294. setpl2:    and    bx,15*2
  295.     mov    ax,word ptr ds:col0[bx]
  296.     out    dx,al
  297.     mov    al,ah
  298.     out    dx,al
  299.     mov    al,ds:col0[bx+2]
  300.     out    dx,al
  301.     ret
  302. setpal    ENDP
  303.  
  304. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒ clear & copy videobuffer to screen ▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  305. clearcopy PROC NEAR
  306. ;---copy/clear buf
  307.     xor    edx,edx
  308.     mov    si,OFFSET vbuf
  309.     mov    bx,4
  310.     mov    cx,200
  311.     mov    di,-4
  312. @@1:    mov    bp,5
  313. @@2:    REPT    2
  314.     mov    eax,ds:[si]
  315.     add    di,bx
  316.     mov    ds:[si],edx
  317.     add    si,bx
  318.     mov    es:[di],eax
  319.     ENDM
  320.     dec    bp
  321.     jnz    @@2
  322.     add    si,bx
  323.     dec    cx
  324.     jnz    @@1
  325.     ret
  326. clearcopy ENDP
  327.  
  328. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒ draw a small pixel ▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  329. pset1    PROC NEAR ;ds:di=destination center, si=xmask offset
  330.     mov    al,ds:colb[si]
  331.     or    ds:[di],al
  332. @@1:    ret
  333. pset1     ENDP
  334.  
  335. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒ draw a big pixel (depending on Z) ▒▒▒▒▒▒▒▒▒▒▒▒▒
  336. pset2    PROC NEAR ;ds:di=destination center, si=xmask offset
  337.     mov    ax,ds:colbww[si]
  338.     or    ds:[di+0],ax
  339.     or    ds:[di+44],ax
  340.     cmp    bp,8300 ;zcompare for size
  341.     jl    pset3
  342.     ;smaller one
  343.     mov    ax,ds:colbw[si]
  344.     or    ds:[di-44],ax
  345.     or    ds:[di+88],ax
  346.     mov    ax,ds:colbv[si]
  347.     or    ds:[di-88],ax
  348.     or    ds:[di+132],ax
  349.     ret
  350. pset3:    ;larger one
  351.     or    ds:[di-44],ax
  352.     or    ds:[di+88],ax
  353.     mov    ax,ds:colbw[si]
  354.     or    ds:[di-88],ax
  355.     or    ds:[di+132],ax
  356.     ret
  357. pset2     ENDP
  358.  
  359. ;▒▒▒