home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 4: The Falcon Archive / nf_archive_four_v1.0.iso / ARCHIVE / MAGAZINE / DBA / dba13.ZIP / dba.13 / GOODIES / STARTASM.S < prev    next >
Text File  |  1993-10-30  |  7KB  |  262 lines

  1. ; How to get started in assembler.
  2. ; Program coded by O.T.M. of the D.B.A.
  3. ; This is a very simple example.
  4. ;
  5.     section    text
  6.  
  7.     bsr.s    init
  8.     bsr    main
  9.     bsr    exit
  10.  
  11. init:
  12.     dc.w    $a00a        ; kill the mouse
  13.  
  14.     clr.l    -(sp)        ; enter supervisor
  15.     move.w    #$20,-(sp)    ; (<--- 1 word and ^--- 1 longword)
  16.     trap    #1        ; Gemdos
  17.     addq.l    #6,sp        ; (1 word = 2 bytes and 1 longw = 4 bytes)
  18.     move.l    d0,oldstack    ; save this important value
  19.  
  20.     move.w    #4,-(sp)    ; this routine checks the resolution
  21.     trap    #14        ; xbios --> in G.f.a.: oldrez=xbios(4)
  22.     addq.l    #2,sp        ; correct stack: 1 word : 2 bytes
  23.     move.w    d0,oldrez    ; save the value
  24.  
  25. * The value that is returned by the previous routine contains the 
  26. * following information
  27. * 0 - Low resolution
  28. * 1 - Medium Resolution
  29. * 2 - High resolution    (Monochrome monitor connected)
  30. * Higher values are reserved for TT-resolutions
  31.     
  32.     cmp.w    #2,d0        ; test the resolution
  33.     bne.s    rez_good    ; if it's not equal then continue
  34.  
  35.     pea    err_text(pc)    ; else give an error message
  36.     move.w    #9,-(sp)    ; (on screen)
  37.     trap    #1        ; using Gemdos
  38.     addq.l    #6,sp        ; correct stack
  39.  
  40.     move.w    #7,-(sp)    ; wait for a key
  41.     trap    #1        ; Gemdos
  42.     addq.l    #2,sp        ; correct stack
  43.  
  44.     bra    clear_off    ; and quit nice and neatly
  45. rez_good:            ; and continue
  46.     move.w    #2,-(sp)    ; get the screen-address
  47.     trap    #14        ; it's an Xbios (compare it with G.f.a.)
  48.     addq.l    #2,sp        ; (It would be like this oldscr=XBIOS(2))
  49.     move.l    d0,oldscr    ; save the returned value
  50.  
  51. * We are now going to clear the screen without using Gemdos, Bios or
  52. * Xbios
  53. * Before we can do that you'll have to know that the screen is build up
  54. * out of 32000 bytes. 
  55. * The screenaddress can be found in d0 coz of the previous routine
  56. * We put it in an addressregister, and we will work our way through
  57. * the memorie until the whole screen is cleared.
  58.  
  59.     movea.l    d0,a0        ; move it to an address register
  60.     move.w    #8000-1,d0    ; use d0 as a counter (8000 longwords
  61.                 ; is equal to 32000 bytes)
  62. cls:
  63.     clr.l    (a0)+        ; clear a longword and go to the next
  64.     dbf    d0,cls        ; do until d0 is "FALSE" (-1)
  65.  
  66.  
  67. * done it.....
  68.  
  69.     move.w    #0,-(sp)    ; enter low resolution-------------v
  70.     move.l    #-1,-(sp)    ; keep screenaddress------------v
  71.     move.l    #-1,-(sp)    ; keep second screenaddress-v
  72.     move.w    #5,-(sp)    ; the routine    --------v        
  73.     trap    #14        ; In G.f.a.: VOID XBIOS(5,l:-1,l:-1,0)
  74.     add.l    #12,sp        ; correct the stack    
  75.  
  76.     move.w    #1,-(sp)    ; init some musix by our own musix-man
  77.     pea    song        ; Nice yamaha tunes by our own SONIC
  78.     jsr    routine+6    ;
  79.     addq.l    #6,sp        ; correct the stack again
  80.     
  81.     rts            ; all inits done 
  82.  
  83. main:
  84.     bsr.s    vsync        ; wait till the screen is finished
  85.     bsr.s    vu_meter    ; our own routine
  86.  
  87.     move.w    #11,-(sp)    ; test if a key is pressed
  88.     trap    #1        ; using Gemdos
  89.     addq.l    #2,sp
  90.  
  91.     tst.w    d0        ; if d0 is zero then no key is pressed
  92.     beq.s    main        ; no ---> continue
  93.     rts            ; else stop and go back
  94.  
  95. vsync:
  96.     movem.l    d0-a7,-(sp)    ; save all registers
  97.                 ; (Xbios messes em up)
  98.  
  99. * First we change the colour, we wait for the screen to finish
  100. * and then we change the background colour again to see how much
  101. * time we have left 
  102. * Also called rastertimer.
  103.  
  104.     move.w    #0,-(sp)    ; colour to change it into (black)
  105.     move.w    #0,-(sp)    ; this is the colour we wanna change
  106.     move.w    #7,-(sp)    ; This xbios routine is equal to setcolor
  107.     trap    #14        ; xbios
  108.     addq.l    #6,sp        ; correct stack: 3 word == 6 bytes
  109.  
  110.     move.w    #$25,-(sp)    ; official vsync routine
  111.     trap    #14        ; xbios    
  112.     addq.l    #2,sp        ; correct the stack
  113.     
  114.     move.w    #$777,-(sp)    ; change the colour again (white)
  115.     move.w    #0,-(sp)    ; the backgroundcolour
  116.     move.w    #7,-(sp)    ; setcolor
  117.     trap    #14        ; xbios routine
  118.     addq.l    #6,sp        ; correct the stack
  119.  
  120.     movem.l    (sp)+,d0-a7    ; give the registers back
  121.     rts            ; and back to main
  122.  
  123. vu_meter:            ; our own routine
  124.  
  125.     movem.l    d0-a7,-(sp)    ; save registers
  126.  
  127.     move.w    #8,-(sp)    ; G.f.a.:volume1=xbios(28,0,8)
  128.     move.w    #0,-(sp)
  129.     move.w    #28,-(sp)    ; xbios routine to check upon the musix
  130.     trap    #14        ; gives the volume of musix-channel 1
  131.     addq.l    #6,sp        ; correct the stack
  132.     move.w    d0,volume1    ; save the value
  133.  
  134.     move.w    #9,-(sp)    ; get the volume of channel 2
  135.     move.w    #0,-(sp)    ; read it 
  136.     move.w    #28,-(sp)    
  137.     trap    #14
  138.     addq.l    #6,sp        ; correct stack
  139.     move.w    d0,volume2    ; save the value
  140.  
  141.     move.w    #10,-(sp)    ; get the volume of channel 2
  142.     move.w    #0,-(sp)    ; read it 
  143.     move.w    #28,-(sp)    
  144.     trap    #14
  145.     addq.l    #6,sp        ; correct stack
  146.     move.w    d0,volume3    ; save the value
  147.  
  148. * I think it's best to take the routines below for granted. 
  149. * To understand them you have to know a lot more about the screen
  150. * and assembler.
  151. * And I think it is not very interesting for you to know yet.
  152. * It would only bore you, and you wouldn't code anymore because you
  153. * would be so depressed, and conviced that coding is difficult that 
  154. * you wouldn't continue coding, and that would be a terrible shame, 
  155. * coz coding isn't that difficult. It only needs some pursistance 
  156. * and normal common sense.
  157.  
  158.     move.l    oldscr,a0    ; the screenaddress
  159.     moveq    #15,d0    ; the counter
  160. clearline1:
  161.     clr.w    (a0)        ; clear the contense if this addres
  162.     addq.l    #8,a0        ; next address 
  163.     dbf    d0,clearline1
  164.  
  165.     move.l    oldscr,a0    ; the screenaddress
  166.     lea    $5*$a0(a0),a0    ; the offset
  167.     moveq    #15,d0    ; counter
  168. clearline2:
  169.     clr.w    (a0)        ; clear it
  170.     addq.l    #8,a0
  171.     dbf    d0,clearline2    
  172.  
  173.     move.l    oldscr,a0    ; same screen
  174.     lea    $a*$a0(a0),a0    ; another ofset
  175.     moveq    #15,d0
  176. clearline3:
  177.     clr.w    (a0)
  178.     addq.l    #8,a0
  179.     dbf    d0,clearline3
  180.  
  181.     move.l    oldscr,a0    ; re-install the screenaddress
  182.     move.w    volume1,d0    ; use d0 as a counter
  183. newline1:
  184.     move.w    #-1,(a0)    ; and form a new line
  185.     addq.l    #8,a0        ; next line in same plane
  186.     dbf    d0,newline1
  187.     
  188.     move.l    oldscr,a0
  189.     lea    $5*$a0(a0),a0
  190.     move.w    volume2,d0
  191. newline2:
  192.     move.w    #-1,(a0)
  193.     addq.l    #8,a0
  194.     dbf    d0,newline2
  195.     
  196.     move.l    oldscr,a0
  197.     lea    $a*$a0(a0),a0
  198.     move.w    volume3,d0
  199. newline3:
  200.     move.w    #-1,(a0)    
  201.     addq.l    #8,a0    
  202.     dbf    d0,newline3
  203.  
  204. * So, and that was it for the "difficult" part.
  205. * let's continue our lesson
  206.  
  207.     movem.l    (sp)+,d0-a7    ; give the stored addresses back
  208.     rts            ; return back to main
  209.  
  210. exit:                ; and now to quit everything
  211.     clr.l    -(sp)        ; shut up ze musix
  212.     clr.w    -(sp)        ; total silence
  213.     bsr    routine+6    ; from here
  214.     addq.l    #6,sp        ; correct stack
  215.  
  216.     move.w    #$777,-(sp)    ; colour to change it into (white)
  217.     move.w    #0,-(sp)    ; this is the colour we wanna change
  218.     move.w    #7,-(sp)    ; This xbios routine is equal to setcolor
  219.     trap    #14        ; xbios
  220.     addq.l    #6,sp        ; correct stack: 3 word == 6 bytes
  221.  
  222.     move.w    oldrez,-(sp)    ; change back to old-resolution
  223.     move.l    #-1,-(sp)    ; keep screen-address
  224.     move.l    #-1,-(sp)
  225.     move.w    #5,-(sp)    ; change it
  226.     trap    #14        ; xbios
  227.     add    #12,sp        ; correct stack
  228.  
  229.  
  230. clear_off:            ; in case of wrong rez we jump to this 
  231.                 ; label to quit in a good way
  232.     move.l    oldstack,-(sp)    ; enter user-mode again
  233.     move.w    #$20,-(sp)    ; set it
  234.     trap    #1        ; Gemdos
  235.     addq.l    #6,sp        ; correct stack    
  236.  
  237.     dc.w    $a009        ; make mouse active
  238.  
  239.     clr.w    -(sp)        ; quit program, and return to desktop
  240.     trap    #1        ; (When assembled)
  241.  
  242.     section    data
  243.  
  244. routine:incbin    'f:\music\sonic\include.sng\music_qu.inc'
  245.  
  246. song:    incbin    'f:\music\sonic\itgoeson.mod'
  247.  
  248. err_text:
  249.     dc.b    27,'E','Sorry monochrome is not supported so reconnect a colour-monitor.',13,10,0
  250.  
  251.     section bss
  252.  
  253. oldstack:
  254.     ds.l 1
  255. oldscr:    ds.l 1
  256. oldrez:    ds.w 1
  257. volume1:ds.w 1
  258. volume2:ds.w 1
  259. volume3:ds.w 1
  260.  
  261.  
  262.     end