<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[ChipMusic.org - basic guide to programming the SID with assembly language]]></title>
		<link>https://chipmusic.org/forums/topic/8189/basic-guide-to-programming-the-sid-with-assembly-language/</link>
		<description><![CDATA[The most recent posts in basic guide to programming the SID with assembly language.]]></description>
		<lastBuildDate>Mon, 20 Aug 2012 07:37:43 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: basic guide to programming the SID with assembly language]]></title>
			<link>https://chipmusic.org/forums/post/128003/#p128003</link>
			<description><![CDATA[<b><i>Telerophon says:</i></b><p>Nanoloop has such a different interface from a tracker that it&#039;s either really intuitive or really counterintuitive or somehow both at the same time.</p><p>I find it really easy to make something that sounds cool and have no idea how I did it or how to make anything else go with it.</p><p>And I covered a squarepusher song in Nanoloop iOS once. <img src="https://chipmusic.org/forums/img/smilies/big_smile.png" width="15" height="15" alt="big_smile" /></p><div class="quotebox"><cite>Chainsaw Police wrote:</cite><blockquote><div class="quotebox"><cite>ant1 wrote:</cite><blockquote><p>well i haven&#039;t been able to figure out nanoloop at all</p></blockquote></div><p>it&#039;s not meant to be figured out.<br />henry homesweet just uses cheat c0dez</p></blockquote></div><p>Dude we should write a GameFAQ walkthrough for nanoloop 2.x</p>]]></description>
			<pubDate>Mon, 20 Aug 2012 07:37:43 +0000</pubDate>
			<guid>https://chipmusic.org/forums/post/128003/#p128003</guid>
		</item>
		<item>
			<title><![CDATA[Re: basic guide to programming the SID with assembly language]]></title>
			<link>https://chipmusic.org/forums/post/127995/#p127995</link>
			<description><![CDATA[<b><i>Chainsaw Police says:</i></b><div class="quotebox"><cite>ant1 wrote:</cite><blockquote><p>well i haven&#039;t been able to figure out nanoloop at all</p></blockquote></div><p>it&#039;s not meant to be figured out.<br />henry homesweet just uses cheat c0dez</p>]]></description>
			<pubDate>Mon, 20 Aug 2012 06:47:55 +0000</pubDate>
			<guid>https://chipmusic.org/forums/post/127995/#p127995</guid>
		</item>
		<item>
			<title><![CDATA[Re: basic guide to programming the SID with assembly language]]></title>
			<link>https://chipmusic.org/forums/post/127951/#p127951</link>
			<description><![CDATA[<b><i>The Silph Scope says:</i></b><div class="quotebox"><cite>ant1 wrote:</cite><blockquote><p>well i haven&#039;t been able to figure out nanoloop at all</p></blockquote></div><p>No one has, some people just pretend.</p>]]></description>
			<pubDate>Mon, 20 Aug 2012 02:51:20 +0000</pubDate>
			<guid>https://chipmusic.org/forums/post/127951/#p127951</guid>
		</item>
		<item>
			<title><![CDATA[Re: basic guide to programming the SID with assembly language]]></title>
			<link>https://chipmusic.org/forums/post/127935/#p127935</link>
			<description><![CDATA[<b><i>ant1 says:</i></b><p>well i haven&#039;t been able to figure out nanoloop at all</p>]]></description>
			<pubDate>Mon, 20 Aug 2012 00:39:48 +0000</pubDate>
			<guid>https://chipmusic.org/forums/post/127935/#p127935</guid>
		</item>
		<item>
			<title><![CDATA[Re: basic guide to programming the SID with assembly language]]></title>
			<link>https://chipmusic.org/forums/post/127934/#p127934</link>
			<description><![CDATA[<b><i>MegaMantra says:</i></b><p>ant1, is there anything you <em>don&#039;t</em> know how to do?</p>]]></description>
			<pubDate>Mon, 20 Aug 2012 00:36:05 +0000</pubDate>
			<guid>https://chipmusic.org/forums/post/127934/#p127934</guid>
		</item>
		<item>
			<title><![CDATA[Re: basic guide to programming the SID with assembly language]]></title>
			<link>https://chipmusic.org/forums/post/127850/#p127850</link>
			<description><![CDATA[<b><i>ant1 says:</i></b><p>maybe you will be better off using a PET though: <a href="http://www.youtube.com/watch?feature=player_detailpage&amp;v=Qq4KKnYsWWo#t=37s" target="_blank">http://www.youtube.com/watch?feature=pl &#133; sWWo#t=37s</a></p>]]></description>
			<pubDate>Sun, 19 Aug 2012 15:08:33 +0000</pubDate>
			<guid>https://chipmusic.org/forums/post/127850/#p127850</guid>
		</item>
		<item>
			<title><![CDATA[Re: basic guide to programming the SID with assembly language]]></title>
			<link>https://chipmusic.org/forums/post/127849/#p127849</link>
			<description><![CDATA[<b><i>chunter says:</i></b><p>The instruction manual had schematic diagrams in it, you can use that info to automate the toaster. I also still have a book with the room dumps disassembled and explained.</p>]]></description>
			<pubDate>Sun, 19 Aug 2012 15:00:41 +0000</pubDate>
			<guid>https://chipmusic.org/forums/post/127849/#p127849</guid>
		</item>
		<item>
			<title><![CDATA[Re: basic guide to programming the SID with assembly language]]></title>
			<link>https://chipmusic.org/forums/post/127844/#p127844</link>
			<description><![CDATA[<b><i>dsv101 says:</i></b><div class="quotebox"><cite>The Silph Scope wrote:</cite><blockquote><p>Make a guide on how to make the C64 make toast.</p></blockquote></div><p>I&#039;m pretty sure you could rip power of the PSU and plug in a toaster. Not sure though....</p>]]></description>
			<pubDate>Sun, 19 Aug 2012 13:45:27 +0000</pubDate>
			<guid>https://chipmusic.org/forums/post/127844/#p127844</guid>
		</item>
		<item>
			<title><![CDATA[Re: basic guide to programming the SID with assembly language]]></title>
			<link>https://chipmusic.org/forums/post/127818/#p127818</link>
			<description><![CDATA[<b><i>The Silph Scope says:</i></b><p>Make a guide on how to make the C64 make toast.</p>]]></description>
			<pubDate>Sun, 19 Aug 2012 06:26:12 +0000</pubDate>
			<guid>https://chipmusic.org/forums/post/127818/#p127818</guid>
		</item>
		<item>
			<title><![CDATA[Re: basic guide to programming the SID with assembly language]]></title>
			<link>https://chipmusic.org/forums/post/127814/#p127814</link>
			<description><![CDATA[<b><i>ant1 says:</i></b><p>couple of months <img src="https://chipmusic.org/forums/img/smilies/smile.png" width="15" height="15" alt="smile" />~ that&#039;s why i&#039;m writing all these tutorials (teaching is the best way of learning etc)</p>]]></description>
			<pubDate>Sun, 19 Aug 2012 06:01:52 +0000</pubDate>
			<guid>https://chipmusic.org/forums/post/127814/#p127814</guid>
		</item>
		<item>
			<title><![CDATA[Re: basic guide to programming the SID with assembly language]]></title>
			<link>https://chipmusic.org/forums/post/127813/#p127813</link>
			<description><![CDATA[<b><i>Aeros says:</i></b><p>jesus, how long have you been working with commodore shit</p>]]></description>
			<pubDate>Sun, 19 Aug 2012 06:00:41 +0000</pubDate>
			<guid>https://chipmusic.org/forums/post/127813/#p127813</guid>
		</item>
		<item>
			<title><![CDATA[basic guide to programming the SID with assembly language]]></title>
			<link>https://chipmusic.org/forums/post/127810/#p127810</link>
			<description><![CDATA[<b><i>ant1 says:</i></b><p>hi, if anyone is interested in writing a c64 music engine</p><p>i will get you started</p><p>enjoy!</p><div class="codebox"><pre><code>/*
ant1&#039;s guide to programming the SID  
this is kick assembler source-code
made in 2012
*/

.pc=$801
:BasicUpstart($810)
.pc=$810

  // clear all sid registers to 0
  ldx #$00
  lda #$00
clearsidloop:
  // SID registers start at $d400
  sta $d400
  inc clearsidloop+1 
  inx
  cpx #$29 // and there are 29 of them
  bne clearsidloop

  // set master volume and turn filter off
  lda #%00001111 
  sta filtermode_volume

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

mainloop:

  // check if rasterline is #$ff 
  // which happens every 20ms
  // do nothing and jump back to mainloop if not
  lda $d012 
  cmp #$ff
  bne mainloop

  // play a single frame of music (if there are any notes to play this frame)
  jsr music

  // loop forever
  jmp mainloop

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

music:

  // tickcounter counts the number of 20ms frames
  inc tickcounter

  // speed is the number of 20ms frames that will happen before the slowtable advances one position
  lda tickcounter
  cmp speed
  beq playnote
  jmp endmusic
  
playnote:

  // flash border and background
  inc $d020
  dec $d021
  
  // reset gatebit/waveform
  lda #%00000000
  sta $d404

  // reset tickcounter as we have got to the next row of the slowtable and we want to start counting towards the next note
  lda #$00
  sta tickcounter
  
  // add slowtablepos to slowtable to get the current position in the slowtable
  ldx slowtablepos
  lda slowtable, x
  
  // get low byte of frequency from slowtable
  sta frequency
  
  // get high byte of frequency from slowtable
  inx
  lda slowtable, x
  sta frequency+1
  
freqcheck1:

  // check if low byte of frequency is #$00, if not, continue to play note
  lda frequency
  cmp #$00
  bne playnote2
  
  // check if high byte of frequency is #$00 (frequency is #$0000), if not, continue to next check
  lda frequency+1
  cmp #$00
  bne freqcheck2
  
  // if it is, reset slowtablepos and start again
  lda #$00
  sta slowtablepos
  jmp playnote  
  
freqcheck2:

  // check if high byte of frequency is #$01 (frequency is #$0001), if not continue to play note
  lda frequency+1
  cmp #$01
  bne playnote2
  
  // if it is, increment slowtablepos to continue moving through the table, but jump back to the start without playing a note
  inc slowtablepos
  inc slowtablepos
  jmp music
    
playnote2:

  // set attack to 0, decay to 6
  lda #$06
  sta attack_decay
  
  // set sustain and release to 0
  lda #$00
  sta sustain_release
  
  // move frequency from frequency variable to sid buffer
  lda frequency
  sta freq_lowbyte
  lda frequency+1
  sta freq_highbyte
  
  // set waveform to saw and turn gatebit on
  lda #%00100001
  sta control

  // increment the slowtablepos twice (twice because there are two bytes for each note in the table)
  inc slowtablepos
  inc slowtablepos

  // write data from the sid buffer to the sid chip
  lda freq_lowbyte
  sta $d400
  lda freq_highbyte
  sta $d401
  lda control
  sta $d404
  lda attack_decay
  sta $d405
  lda sustain_release
  sta $d406
  lda filtermode_volume
  sta $d418

endmusic:

  // back to mainloop
  rts


// variables ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// the number of frames to wait before advancing the slowtable, you can set this to anything
speed:
  .byte $1f

// stores the tick (frame) counter
tickcounter:
  .byte $00

// stores the position in the slowtable  
slowtablepos:
  .byte $00

// temporarily stores the frequency of the next note  
frequency:
  .byte $00
  .byte $00

// music data ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// the slowtable is where the note data is stored
slowtable:

  // frequency is a sixteen bit number, a higher number is a higher pitch
  .byte $b1, $25
  .byte $30, $40
  .byte $b1, $25
  
  // a frequency of #$0001 tells the player to play no note on this row
  .byte $00, $01
  
  .byte $b1, $25
  .byte $30, $40
  .byte $b1, $15
  .byte $00, $01
  
  .byte $b1, $25
  .byte $30, $40
  .byte $b1, $25
  .byte $00, $01
  
  .byte $b1, $25
  .byte $30, $40
  .byte $b1, $65
  .byte $00, $01
  
  // a frequency of #$0000 tells the player to loop back to the start of the slowtable
  .byte $00, $00
  
// sid buffer ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// values that are going to be written to the sid are stored here and then written in one go

// freq_lowbyte is the low byte of the frequency
// on the SID this is $d400 
freq_lowbyte:
  .byte $00
  
// freq_highbyte is the high byte of the frequency
// on the SID this is $d401
freq_highbyte:  
  .byte $00

// control sets the waveform and gatebit
// on the SID this is $d404
control:
  .byte $00
  
// the first nybble of attack_decay is attack, the second nybble is decay
// on the SID this is $d405
attack_decay:
  .byte $00
  
// the first nybble of sustain_release is sustain, the second nybble is release
// on the SID this is $d406
sustain_release:
  .byte $00
  
// bits 7-4 of filtermode_volume control the filter, bits 3-1 control the master volume
// on the SID this is $d418
filtermode_volume:
  .byte $00</code></pre></div><p>edit:<br />if you&#039;ve never done any c64 programming before then you will need, to follow this guide,</p><p><a href="http://aanaaanaaanaaana.net/c64-docs-archive/6502%20Reference.htm" target="_blank">something that tells you what all the opcodes do</a><br /><a href="http://aanaaanaaanaaana.net/c64-docs-archive/All%20About%20Your%20C64.zip" target="_blank">something that tells you what all the sid registers do</a><br /><a href="http://aanaaanaaanaaana.net/tools-archive/kickassembler.zip" target="_blank">kick assembler</a></p>]]></description>
			<pubDate>Sun, 19 Aug 2012 05:36:58 +0000</pubDate>
			<guid>https://chipmusic.org/forums/post/127810/#p127810</guid>
		</item>
	</channel>
</rss>
