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$AP+ACP!-52+SOV#14X"DP <#P 3$D"6&6H\$P! !#1^!
MP#A"2OP@\15$)> !> 8%-*:AL'E0L&6!T)SB7$#!L#$ , "DM 3-&*G_ '
M'B4<(4\P(.B C&C #0((L@ F!P^$"*5T@PGC* %_H+P #43"$+I )@W_%W6
M]((X"_0!""(
M006"B00)!KT BIT !\K0Y2#D__#[K38(3! (EKR]E@W<7Q04!>/SR3J6@W\0
M;)$4%<2O%P')2Q .43$P,"6"YJ59+DID)$$(#P7.H4$$<@(4L S[@HDOH9"&
MX@(14#HR,+B3$P$<1&]J0D!#P\,IR_#1'!)0HR,#6/%48AI QJ)9",/L049)0LC1UP@"@]R*ND#
M"V B""X2+G0["0=\#Q@I2( R#@<@(O0@,B(L$GHV-" 71WH((P,Z"#$D%P4!
M"V,: C4("08,"2T%! G64Q*6"%P.!,#SX"0@LA$)#07A]0586HTY 0X+>C4-
M%1,N 9 H VDT#A0@&G072Z P#! )A@\4$AF@H4 @$Q ! P4" 4(M!@\2( P/
M!_ [#PXO#P8&(2XNK(U8( @%$@4G$R 4#R !# P@&0\5(! #+0<5&1,AE@0N
ME@ ";B"6&+OX"PC&!YXR,#8QUFM79P"-8BZ-(="-A@+CR>6B)[VZ9,,$J0^G
MD]C)//()F"@]V43ZHE*@>(0!N5@(F?\$E+VYKUB9 /]!/O?.&:[.20B1=^Y,
M"P63C(6$AX6(KJ")B>C(L7K EM 23LD T >0#JAHJB!.!8WH!^Y Z@PURN";
MB-#OS'30S[PG$7HMO"@%E"[ [W(!AJTSK^Y/!= #[E %Q@'JZNKF 6 QLAL8
M+3DV.B $!04+ 1DO Q(%1*HK !@@(" .+Q Z$Q09# 66'P"I&\#J7] @J.5@
M>*DT41N@A*+]($3A!WT@1@BB +UA")W<0>C0]ZE,C0T(J3>% 5BB'[V,A)TP
;_>S&]TP1EX0\ACX_NH0> USE@*(^L3N1/ ;(if we don't introduce a delay, the text will scroll by
> ; WAY TOO FAST to READ ! ! Incredible, this 1 Mhz bugger
> ; machine of ours is, eh?) - delays not set in stone, play
> ; with them :) higher, lower, etc...
>
> LDX #$05 ; just a delay loop - ldx counted down by dex
>waitloop LDY #$FF ; a delay loop within a delay loop
>wl2 DEY ; decrement y in our delay looop
> BNE wl2 ; keep counting y down until y = 0
> DEX ; decrement x in our top delay loop
> BNE waitloop ; repeat the y loop until x = 0
[even more snipped here]
In the following, I'll describe *very* basic features like the
concepts of rasters and frames. This is probably only interesting
for newcomers in the assembly-domain.
If you are looking for a smoother scroll, you would use what is commonly
known as "rasters".
Your tv-set displays the image on the screen using an electron-beam
which moves from the top, left corner down towards the lower, right
corner in horizontal lines. If my memory serves my right, PAL (mostly
european) screens have 312 lines, while NTSC (in the USA) screens have
262 lines. We count these lines starting from 0 (263 total), and call them
"raster-lines", or just "rasters".
The Commodore 64 has a few registers in the VIC (the chip that generates
the video-image) which reflect where the electron-beam is. We have one
register at adress $D012 which contains the first 8 bits of the raster,
and another at adress $D011, where bit 7 describes the 9th bit of the
rastervalue.
You can safely regard the rasterline as a Y-coordinate on the screen
that starts from above and works its way down.
In this way, you can use this formula to obtain the rastervalue:
raster= peek(53266)+ (peek(53265) and 128) * 2;
Note, that this isn't of much use in a basic-program because
basic simply is too slow, and when the calculation is done,
the rasterline has changed so much that the value of "raster"
is more random than useful.
Well, the value in $D012 goes from 0 to 255 while $D011 bit 7 is 0,
refrecting that the rasterline goes from 0-255. Then bit 7 in $D011
is set to 1, and $D012 goes from 0 to 55 on a PAL-system, refrecting
that the rasterline is 256-311. This is what is know as a "frame",
and the cycle starts over with $D012 being 0, and bit 7 in $D011 also
being 0.
You can exploit this register to get a smooth scroll in several ways.
I'll describe the most primitive of these techniques in the following.
A smooth scroll is achieved, if the text is moved every frame, not
more, not less. In other words, the delay loop in the scroll should
be adjusted so that the entire scroll-loop is performed exactly once
per frame.
Okay, that's fine, but how do I achieve this?
You simply monitor the rasterline. A simple way of doing this is to
use a bit of code like this, which waits until the rasterline is
at position 0 exactly.
wait lda $d012 ;Wait until the lower bits of the rastervalue
cmp #0 ;is 0.
bne wait
lda $d011 ;We also need to check if the high bit of
and #$80 ;the rastervalue is 0, in order to distinguish
bne wait ;raster 0 from raster 256.
Another, slighty optimized version, could be:
lda #$ff
wait cmp $d012
bne wait
which waits until the rasterline is $ff. This one exploits the fact
that the rasterline never exceeds 311, so $d011 bit 7 will always
be 0, when $d012 is >55.
You should try to play around with such wait-loops, and with a little
effort you should be able to do a smooth scroll.
You can also try to use $d020 to set the border-color at different
rasterlines, like:
wait1 lda $d012 ;Wait for rasterline $30
cmp #$30
bne wait1
lda $d011
bmi wait1
lda #1 ;Set border-color to white
sta $d020
wait2 lda $d012 ;Wait for rasterline $108
cmp #$08
bne wait2
lda #0 ;Set border-color to black
sta $d020
jmp wait1 ;And keep looping
Notice that the second wait-loop exploits that the next
time $d012 will be $08 after rasterline $30, will be
at rasterline $108, which makes a check on $d011 unnecessary.
This little program will produce a white stripe in the
border of the screen, but the area where the color
changes will probably "flicker" a bit, i.e. move randomly
around in a small area.
This is because we only check when the rasterLINE is right.
Ideally, we would also want to check for the right "raster-
coloumn" to be right, so that the cut could be at our specific
(x,y) point, but unfortunately the c64 doesn't directly provide
such a rastercolumn register, so removing the flicker can be tricky
business.
Of course there's much more to it than this. For instance, the
VIC provides a facility to automatically announce to the program
when a certain rasterline arives, so that we needn't check the
rastervalue ourselves in a loop. This technique is known as raster-
interrupts, but I'll leave that subject to another time.
Until then, welcome to the world of rasters, and happy hacking!
Asger Alstrup
--
For questions and comments, 'XmikeX' may be reached through the Editor-in-Chief
of disC=overy.
/S03::$d000:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
The Raster StarterKit,
-+-+-+-+-+-+ -+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+ -+-+-+-+-+-+-
A classic 'slice' of VIC-II code
by XmikeX and Dokken/Electron
My early experiences with VIC-II programming on the C64 led me to the
conclusion that being able to manipulate the VIC-II on a rasterline level
is essential to success as a "coder". Over the years, 64 coders have moved
far beyond this simple dogma, but it is recognized that all have to start
somewhere. The following is an example of one of my early attempts. I
still use this bit of code to form the core of many of my programs. I
would like at this time to thank Dokken/Electron for his part in providing
the base code that follows. Please note that for the purposes of proper
instruction to those who might be more familiar with BASIC than ML, the
source below has all values in decimal (same as with BASIC peek/poke).
However, please note that raster programming requires quick action and is
best left to ML code.
*=49152 ; origin at 49152 or whatever free memory location desired
sei
lda #127
sta 56333
lda #18 ; the first 3 STA's just tell the 64 to
sta 53265 ; do IRQ's. Well, the 53265 hi-byte value
lda #1 ; says to do a IRQ at rasters 0-255, but
sta 53274 ; whatever
lda #100
sta 53266 ; the IRQ'll happen at raster line 100
lda #main
sta 789 ; high byte of IRQ routine
cli
jkjk
jmp jkjk ; this just happily jumps back to itself
; whenever we're not in an IRQ
main
rol 53273 ; or: lda #1:sta 53273 tell the 64 an IRQ
; happened or something goofy like that
ldx #1
jsr rast
ldx #0
jsr rast
lda #126 ; this sets up a raster IRQ at scan line
sta 53266 ; 126 for the 'rain' routine
lda #rain
sta 789
jmp $ea81 ; ok. you can use either $ea81 or $ea31
; $ea31 with an RTS where the 'jmp jkjk'
; is allows the 64 to process everything
; normally. ie. you can run a basic
; proggy and have an ML interrupt doing
; something on top of it like maybe playing
; a happy tune or something.
; $ea81 gives you total control with no
; overhead. ($ea31 scans the keyboard
; takes a decent chunk of time). So with
; $ea81, if you want to read the keyboard,
; you get to do it explicitly.
rain
rol 53273
ldx #6 ; rasterline is now set at color : blue!
jsr rast
ldx #0
jsr rast
lda #100 ; this sets up a raster IRQ at scan line
sta 53266 ; 100 for the 'main' routine
lda #main
sta 789
jmp $ea81
rast ; this routine just makes a raster bar out of
lda 53266 ; the value in the x register. Note that this
rast2 ; only works for 7 of 8 scan lines cuz the
cmp 53266 ; 64 needs to chunk away at graphix
beq rast2
stx 53280
stx 53281
rts
Try and expand this routine to include many many rasters or color bars,
or anything you dream up. It would be prudent to point out at this time
that a text such as "Mapping the 64" is extremely useful for delving into
VIC-II chip registers. "Mapping the 64" in particular, gives a wonderful
description of VIC-II register function.
Goodbye.
--
For more information or general commentary on this article, XmikeX may be
reached through the Editor-in-Chief of disC=overy.
/S04::$d000:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Heaven in the net, an unedited excerpt of IRC on #c-64
by Mike Gordillo
As a self-proclaimed "demo freak", the following transcript (largely unedited)
represents one of the most interesting discussions concerning C-64 that I have
ever witnessed on IRC (Internet Relay Chat). I present this to the reader
in the hopes of encouraging further participation and patronage of IRC channel
#c-64. We begin with a discussion on raster programming by "Fungus", "_dW",
"hld", "Sorex of WOW", and "XmikeX".
--
<[Fungus]> I'd like to know just how to do that. Stable Raster that is. I've
tried double interrupts and stuff and every now and then I'd get like
this 1-2 cycle jitter I couldn't get rid of.
<_dW> My raster is completely stable.. or so I think.
fungus: use nops or something to time it out
<[Fungus]> Sorex : I did and still couldn't get it out. The next routine's
timing kept changing the original timing.
<_dW> Fungus: it works like this: set up a raster int on line 'n',
then in the irq code change the $0314-$0315 vector to point to a
different routine and set a raster to strike on line n+1.. execute
NOPs 'till it strikes. When the second raster hits, you'll be
at most 1 cycle off, which can then be corrected by code like
LDA # n+1 : CMP $d012 : BEQ sync (sync: rest of the code)
<[Fungus]> I 've tried that too, and banking out The Kernal etc... Using fffe
& ffff. I still got goofy jitter. It would be totally stable for like
5 second then screw 1-2 cycles to the left exactly 3 times. Then would
be stable for another 5 secs. CIA's are Disabled as well as NMI's: NTSC.
<_dW> Fungus: you must have left out something... what method did you use?
<[Fungus]> Tried it both ways.
<_dW> double ints and?
<[Fungus]> Didn't matter, double Interupts VIA 0314 0315 Double Int VIA
FFFE FFFF too, and yes, all in NTSC R-8 VIC chip so 65 cycles.
fun:i have a source here from Graham/Oxyron for that 4*4 display
routine, i uses multiple IRQ's to get the damn thing steady timed
and nops
<_dW> Fungus: send me mail at agonzalez@nlaredo.globalpc.net I'll send you
source code for a double int 0314/15 raster sync. Sorex: 4x4 display?
dw:you know... that mode everyone uses to get fullscreen effect
like rotzoomers/plasmas/doomstuff/tunnels/...
<_dW> Sorex: the one with the plasma in dawnfall/oxyron?
dw:yeah, and the fire in 'The Masque' ....
<[Fungus]> You guys wanna idea? Have any of you tried playing with $d012 like
decrementing it 1 cycle after it changes?
<_dW> Fungus: that could cause an interrupt, if they're enabled and $d019 lsb
is clear.
If I could interject a simple question -> Does the VIC-20 have a
$d012 equivalent?
XmikeX - the vic20 has no $d012 equivalent - so you cant tell
what raster you are on.
<[Fungus]> Hehehe On the contrary. I code stuff on the Vic-20 too. You can just
poll the raster register and SEI and never clear it. Makes it preety
easy. It's just that the Vic-20 treats 2 raster lines as one. I made
a cool looking 16 color ROL scroller on it once. (Basically, its $d012
equivalent does not generate IRQ's like $d012 does on the C-64).
I prefer to just poll $9004 ($d012) Easy to do. Then you can do
all sorts of twisted stuff. The VIC is a different Animal. Really
neat registers. Remove the borders with out an INT even!
I'd like to see people get interested in the Vic-20. It's capable
of some cool stuff. You can make the screen scroll in any direction
really Fast. The Entire screnn too -No borders. Full Charsets and
big color Memory. Full Screen High res too, no borders.=]
[...]
<_dW> hld: you did real raytracing in your 4k entry?
dw - yup.. My 4k entry distorted a checker board. The code was about $4f0
bytes (and 20KB of tables ;)
<_dW> Are you using lots of rom routines? Any division?
dw - It uses ROM routines to create the 20KB tables, but it is pure
integer assembly when running - with very small error rate.
I have no division at all in this tracer.. only +,*,srqt
Remember, pre-calcing all the sqrt's takes quite a while and it
is all pre-calced in floating point, but i do some nifty weird
things so that it only needs to accumulate integers to do the trace.
Basically, it does one frame in about 4 seconds where a frame is
defined as 256x64 monochrome.
[...]
Wave, how is your plotter routine coming along?
Right now, its "doing" 16*16 character rotation. Going to optimize
it a bit and see how far out I can go and still have the routine update
reasonably fast, but my line vector is under 4k.
Any drags so far?
The main thing that slows down the vector routine is the clearing
of the next buffer. Man, that EATS time... but a character or bitmap
rotation doesn't necessarily need to be cleared first, and even if it
does, the amount of zeros to stuff into memory is significantly less.
<_dW> Wave: are you doing a complete clear? or a redraw-clear?
Dw: complete zap of memory...but I toyed with re-draw clear idea.
Hmm, nothing really faster than inlined STA :(
Mr. X : I got a loop like this:
lda #$00
ldy #$00
sta $2000,y
sta $2080,y
sta $2100,y
... ...
iny
bpl
Each STA line will zap 128 bytes in that loop... I may unroll it
further, but I don't know.
How about :
LDX #0
LDA #times/4
Sorry, LDY #0
STY ....,X
BNE
DEX
If you INX, you need a CMP or you waste time going over your area.
ah... you are DEXing from times/4
1 = 256, 2 = 512, 3=768, 4=1024; none of which is the 800 bytes
you mentioned.
2k of zeros; 2k=$800
You should still kill it by pages!
It does kill by pages!
?? It wasn't clear from the code. How many STA's inside loop?
several
Define several? It should be like 8 STA to kill 2K : base+0,
base+256, etc up to base+2K-255
Here is my 'clear' code, Mr. X :
sta $2000,y
sta $2080,y
sta $2100,y
sta $2180,y
sta $2200,y
sta $2280,y
sta $2300,y
sta $2380,y
sta $2400,y
sta $2480,y
sta $2500,y
sta $2580,y
sta $2600,y
sta $2680,y
sta $2700,y
sta $2780,y
iny
bpl
rts
I cover the whole area in one loop, except I kill 128 bytes with
each STA.
Wave: But that's way past the point of diminishing returns....
And why pick 128 bytes?
Because it runs faster than 256 bytes!
So you got, what, 16 STA in your actual code?
if each STA wipes 256 bytes, then the loop runs 256 times. Which
means that all the loop overhead (agreed - not too much, but there)
is multiplied by 256. If you loop 128 times, I would think it should
reduce the overhead by half.
Have you actually done the math?
I should time it tonight to be sure.
effective cycles = loop + overhead / total cycles <-- will give
an average number for overhead cost.
Well ok, but heck if I'm going to 1:1 unroll it though! 2000 STAs,
no way...even if I write a program to generate them.
4K for your clear routine! hehe :) But 1:1 may lead you past the
point of diminishing returns...
Well, I used 128 because there is only a INY (or DEY depending on
what you think when you code) and one branch. (BPL or BMI respectively).
BTW, 256 has the same functionality... Both will set a processor flag.
Hmmm, actually all numbers will with a DEY.
In general, I DEX BNE, just considering it a good habit, always trying
by pages.....
But doesn't it stand to reason that a 1:1 is the fastest since it
has no overhead? So if thats true, if you only looped twice, you'd
cut out half the STA's, but increase the overhead by a factor or 2.
The overhead is small though (couple cycles for dey, couple for the
branch.)
Yeah, the overhead is small. Your first STA is the "best", each
additional one after that gives less and less improvement in speed and
just takes more space....
And if you need to zap like 2k of memory, there ain't a Bxx
instruction in 6510 thats going to get you back to the beginning of
that STA loop. =) After all, you can only have 40 or 41 STA's to use
a Bxx instruction.
Time to unroll your loop, Waveform :).
Then I'd get 6144 bytes of code to clear 2048 bytes of buffer. :(
I can't believe I am thinking of making a 6144 byte clear routine and
actually, it would have to be 12288 bytes, since I double buffer.
Three bytes per STA... 2048 bytes to clear... (2048 * 3 = 6144) * two
buffers doubles that to 12288.
Hmmm... Loop overhead... Let us see here...
Each time you gotta INY/DEY and CMP and/or Bxx (branch) or JMP
at the end of the loop, with the number of times through the loop
multiplying the overhead. The less times through the loop, the less
overhead.
Yes, and DEX BNE = 2 + 3 = 5 (assuming your smart enought to line
it up in one page! otherwise 6 cycles)
Yeah, if I completely unroll it, I'll have NO loop overhead
to deal with at all... I will certainly have to give this idea some
further thought.
[...]
So, did you take MrX's advice?
Yes, I unrolled that clear loop, but I'm not sure how much savings
I was able to obtain. I mean I know how much in cycles, but I don't
see much of a real difference it made to the overall performance of
the code.
Well, there should be a difference.
Yeah, but I'm not seeing THAT much of a diff... hmmm... but it was a
while inbetween running each version. I should run them one right after
another and see. So far, to tell the truth, the effect seems neglegible.
What are your cycle times now?
10752 for old code - 8192 for new code = 2560 cycles.
Hmmm, if I am doing my math right, then it is actually 2.5 ms.
Let's see, NTSC C64 draws a full screen every 1/60, and if one
raster line is 1/263 of 1/60 sec in NTSC, it takes approx. 0.0000636
seconds to draw one raster line, and there are 65 cycles per line.
This means one cycle is more or less .0000009 seconds which
is approx. NTSC 1Mhz rate. My calculator lacks the required
precision here, but enough to give credence to the clock rate. :)
So if we forget about 'bad lines' (VIC-II DMA), I am saving
around 2.5 ms per iteration. My code rotates an object around
its center completely in 8-bit increments, hence the routine is
called 256 times.
So 256 * 2.5 ms = 640 ms per 1 complete rotation (.640 sec! :)
So I lose 12k of RAM for .640 sec..... NOT! I will rip that code
out and instead work on speeding up my line drawing code.
Sigh...plotting...truth tables... blah :)
Hehehe, 0 OR 1 = 1
0 AND 1 = 0
0 EOR 0 = 0
0 EOR 1 = 1
1 EOR 1 = 0
Etc., Etc., Etc...and remember, anytime you got that N in front
(NAND, NOR, NOT, etc) you just invert the truth table.
Hey gang, wassup?
Wix, right now I am looking at a balance of neatness in programming
vs speed of execution (plotter)
the age old conflict... speed vs smoothness, how many cycles?
Mine is 70 as it stands.
wave - that's your theta,r plotter right?
Yeah, and the plotter doesn't care where the coords come from, Wix.
yeah, I know, a general point plotter... but where it plots points would
change the code a bit, no? the plotter takes r,theta and turns the right
pixel on in the chargrid right?
I coded 3 general purpose routines:
1> point rotater (basically, change all the thetas)
2> Resolve r,theta into x,y
3> plot x,y on charmap
ahhh... ok... I thought you had said that there was no step 2
(conversion of r/theta into x/y) ??? the speed of the steps 1-2-3 are
combined at 76 cycles?
no no no, I don't have inital x,y... no need to convert x,y into
polar just to rotate it and bring back.
well I udnerstand you start from polar, but I was imagining you had a
direct r/theta to bitmap plotter... that's all
yeah... well I have to resolve into X,Y somewhere, Wix. =)
ok, so your step 1-2-3 combined is 76 cycles?
But the point of the routine is that I don't start in X,Y... Which
makes the Rotation part very fast... just inc/dec the thetas.
And, no... just the plot into the char map is 70 cycles (as it
stands, I think I can get it down to below 60 though)
but, yes, you do convert back to x/y to plot. That's your step 2 right?
Wix, yeah.
Wave well, you could do better on the x/y plotter. But if what you
have works & looks good... who cares? At the most I was able to
achieve 35 cycles onto a full screen bitmap coming from X & Y,
with an X high bit. Think for a moment... :)
Oh wait! I've just had a brainstorm. Be right back, getting a pen.
DUDE!!!!! Woah!!!!! Just a sec... let me recount this.
I -think- I have a 26 cycle plotter now.
26 should be possible in a right-made chargrid, but not on a bitmap
I think...
Perhaps, but I will definately explore this! In fact, once I'm
done, I think I'll put this all down in writing. :)
[...end of transcript...]
/S05::$d000:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
A demo of 'disC=overy', =
-+*+-
= The exploration of rotation :)
by John Kaiser (Waveform/MLM)
Shoooom! Greetings from the Wave! =)
In this article I am going to talk about a relatively simple two-
dimensional vector routine. Before I dive in, however, I'd like to
give some credit to Steven Judd, who through one of his C= Hacking
articles showed me the way to the core of a fast line drawing routine
as well as an amazing method of quick multiplication. I'd also like to
give thanks to those 'hard-core coding animals' on IRC channel #c-64
for their most-nifty insight. Before I forget, to all those who I have
been taunting with my (I think, I hope..) 'super fast pixel plotter', you
are finally able to see the source for it. Its so extremely simple, you'll
probably kick yourself for not coming up with it yourself.
[Ed. Note : According to S. Judd, the 'quick multiplication' method
which John is referring to was originally formulated by George Taylor.]
For all of those expecting a full blown demo in this article, I am afraid
I have to disappoint you. The "real world" has been taking a heavy toll on
me during the last month so the amount of time I was able to spend working
on this article was extremely limited. What you will see, however, is a
fully functional rotating vector routine, in a relatively basic form.
There are tons of uses for the routines involved, and infact, my next demo
uses quite a few variations on the code you are about to see.
It is interesting to note that I did not set out to code a rotating vector
routine. =) I have another project I'm working on that involves some of
the same routines. While working I thought, "Hey, I could probably rotate
a two dimensional shape pretty easy with this."
And Voila! You get something like the source code that follows.
Preface To The Code
-------------------
The trick to this code is referencing the endpoints of a line by a radius
and theta, as opposed to regular X and Y.
The advantage to referencing the endpoints - or even just individual
pixels - like this is that to rotate a point, you merely add or subtract
from the theta value. This process ends up being extremely fast,
especially when compared to taking an X,Y coordinate and sending it
through a whole slew of mathematics just to move it around. Observe a
quick comparison of the steps needed to rotate a number of endpoints about
their geometric center:
Old Method:
-----------
1. Get an X,Y endpoint
2. Convert to radius and theta (or some other convenient rotation friendly
reference)
3. Apply the rotation
4. Convert back to X,Y
5. Store result
6. Loop back until all endpoints are finished
Nifty Method:
-------------
1. Get a radius,theta endpoint
2. Apply the rotation
3. Store result
4. Loop back until all endpoints are finished
What is missing is the slow, and sometimes bulky conversion routines. Even
if you have a fast conversion routine, this method still is faster because
you have less steps from beginning to end. You have less code to execute
per endpoint.
One other trick to this particular code is that my circles have 256 units
to them, while most peoples circles have 360 degrees. Rather than have a
boring name like "units" I decided to use the name "byts". So, by way of
comparison, a normal circle has 360 degrees, while my circles have 256
byts.
Why use a different unit of measurement? The thinking man will quickly
realize that in our nifty 8bit machines, the largest value a single byte -
register, or memory location - can hold is 255. By using the byt unit of
measurement, we can make an entire circle with just one byte, and not have
to worry about fiddling with high bits. This way of thinking saves many
many processor cycles, and many many hairs on a coder's head. =)
Finally, before I slam you with the source code (which, by the way, is in
TurboAssembler format) there is one more trick to this particular code.
Sometimes the only way to get real speed out of a Commodore is to reduce
the code necessary to perform calculations. How do the great coders do
that? The keyword(s) are LOOKUP TABLES.
This code uses tables for the plot routine and for the multiplication
routine. I wrote basic programs to create the tables and will do my best
to explain how they work, near the end of this article. As to the tables
themselves, I'll explain how the code uses them when I get to the relevant
section of the source code.
Wow, what a preface! Now, on to bigger and better things: The documented
and commented Source Code!
The Source Code - In TurboAssembler Format
-----------------------------------------
Okay, here it is. I'll be commenting on the code throughout the remainder
of the article in hopes to further clarify what the code is doing.
First, no code is complete without a little self glorification before the
origin and equates are setup...
;---------------------------------------
; A Demo of disC=overy - By: Waveform
;
; (c) 1996 for disC=overy Magazine
;"The Journal of the Commodore Enthusiast"
;---------------------------------------
The afore mentioned origin and equates...
*= $0820
points = $033c ;number of points
angleinc = $033d ;angle to increment
curshape = $033e ;current shape
theta = $0340 ;thetas
radiu = $0350 ;radius
itheta = $0360 ;tab of init thetas
iradiu = $0370 ; init radius
scrloc = 1196 ;location of top
; left corner of
; char matrix on
; screen
msin = $3000 ;table of sines
mcos = $3100 ; cosines
msqr = $3200 ; squares
lobyte = $3300 ;lo bytes
hibyte0 = $3380 ;hi bytes ($2000+)
hibyte1 = $3400 ; ($2800+)
bitmask = $3480 ;pixel bit mask
Okay: "points" is the number of endpoints for the current displayed shape.
"angleinc" is the amount to rotate the shape, in byts.
"curshape" is the number of the current shape. This demonstration
has three predefined shapes. Feel free to experiment
with the ones I included or add your own!
"theta" is a table of thetas. This code is written such that a
shape can have up to 16 endpoints defined. To change this
"limitation" simply give yourself more bytes in-between
these tables.
"radiu" is a table of radii. Both "theta" and "radiu" change as the
program executes. At any point in time, these two tables
hold the current values of all the endpoints for the
current shape.
"itheta" is a table of the initial values of the shapes theta
coordinate component.
"iradiu" is a table of the initial values of the shapes radius
coordinate component. Both "itheta" and "iradiu" tables
are static and are not changed by the program. It is
convenient to have these two tables for when you need to
alter the coordinates of a endpoint relative to its
initial position.
"scrloc" is used by the routine that places the character matrix on
the screen. 1196 places it in the center of the screen.
"msin" is the base address of the table of sines. Each value
represents the sine of the address, relative to the base. So
that msin+0 = sine of 0 byts, msin+64 = sine of 64 byts, etc.
"mcos" is the base address of the table of cosines. Works the same
way as the sine table.
"msqr" is the base address for the table of squares. Works similar
to the sine and cosine table, except that this table is a
table of squares of both positive and negative numbers. More
on this later.
"lobyte" is the base address of a table of low bytes used by the
plot routine as the low byte of the address where the
pixel to be plotted lives.
"hibyte0" is the base address of a table of high bytes used by the
plot routine as the high byte in buffer #0 where the
pixel to be plotted lives.
"hibyte1" high byte of the address in buffer #1 where the pixel to
be plotted lives.
"bitmask" is the base address of a table of bit masks applied to
the byte where the pixel to be plotted lives.
;---------------------------------------
jsr demoinit ;init for demo
;---------------------------------------
That's just a JSR to the demo initialization routine...
main lda #%11111110 ;scan matrix
sta $dc00 ;
lda $dc01 ;
cmp #%11101111 ;f1
beq keyf1
cmp #%11011111 ;f3
beq keyf3
cmp #%10111111 ;f5
beq keyf5
cmp #%11110111 ;f7
beq keyf7
cmp #%11111101 ;return
beq keyreturn
lda #%01111111 ;scan matrix
sta $dc00 ;
lda $dc01 ;
cmp #%11101111 ;space
beq keyspace
cmp #%01111111 ;return
beq keystop
What the above does is scan the keyboard matrix to see if the user has
pressed one of the keys our program is looking for. Later on you'll see
that we disabled the CIA interrupts that cause the computer to scan the
keyboard, so we needed a way to tell if one of our "do-something" keys was
pressed. We "scan" twice since the various keys we are looking for are on
different rows of the keyboard matrix.
reentry jsr rotate ;rotate shape
jsr drawshape ;draw shape
jmp main ;loop
;---------------------------------------
The little code snippet above is where the JSRs to the real workhorses
are. As you can see this demo is pretty simple. =) We rotate the current
shape, and then we draw the shape. Then we go back to the beginning and
see if the user wants to do something.
keyf1 jmp rotup
keyf3 jmp rotdn
keyf5 jmp expup
keyf7 jmp expdn
keyreturn jmp newshape
keyspace jmp stoprot
keystop jmp stopdemo
;---------------------------------------
Above is a little jump table to the various little routines that do what
needs to be done when a key is pressed...
rotup inc angleinc ;increase
jmp reentry
;---------------------------------------
rotdn dec angleinc ;decrease
jmp reentry
;---------------------------------------
The above two "routines" change the value by which the shape rotates per
run-though of the main loop. As you can see, referencing the endpoints as
radius and theta takes alot of the work out of rotating a shape about its
center! Each time the user presses the F1 key, the angle that the shape
rotates per run-though increases. Holding down the F1 key will cause the
shape to spin up quite rapidly. Indeed, if you continue to hold down the
F1 key, the speed of the rotation will appear to increase to the point
where it begins slowing down again.
Obviously, F1 increases the angle of rotation, and F3 will decrease it.
expup ldy #$00
expup1 lda radiu,y
clc
adc #$01 ;add one
cmp #63 ;at maximum?
bcc expup2
lda #63
expup2 sta radiu,y ;store
iny
cpy points ;do all points
bne expup1
jmp reentry ;return
;---------------------------------------
expdn ldy #$00
expdn1 lda radiu,y
sec
sbc #$01 ;subtract one
cmp #2 ;at minimum?
bcs expdn2
lda #2
expdn2 sta radiu,y ;store
iny
cpy points ;do all points
bne expdn1
jmp reentry ;return
;---------------------------------------
What the above two routines do is expand or shrink the shape. These two
routines work well because of the way our shapes are defined. The shapes
that come with this demo are all equidistant from the objects center. So,
it is easy to change the shapes size by altering all of the shapes radius
coordinate components. Obviously, more detailed shapes that have endpoints
that are at varying radii from the center will need improved routines if
the shape is to maintain its proportions through the expansion and
shrinking.
Notice the error checking, also. Bad things happen when are radii get too
large or too small for our line drawing routine to handle properly.
newshape inc curshape
lda curshape
cmp #3 ;last shape?
bne newshape1 ;nope
lda #$00 ;select first
sta curshape ; shape
newshape1 cmp #2 ;8 point star?
bne newshape2
jsr initobj20 ;init shape
jmp reentry
newshape2 cmp #1 ;2 triangles?
bne newshape3
jsr initobj10 ;init shape
jmp reentry
newshape3 jsr initobj00 ;1 triangle
jmp reentry
;---------------------------------------
The above routine handles the users request to change the displayed shape.
There are better ways to handle this, but since this demo only has three
shapes built in to it, the quick and dirty way suffices without being
extremely bulky.
stoprot lda #$00 ;stop all
sta angleinc ; rotation
jmp reentry ;
;---------------------------------------
The above little bit of code simply stops the rotation of the current
shape. It merely stores a zero into "angleinc" which controls the amount
of rotation applied to the shape.
stopdemo lda #$81 ;reset cia
sta $dc0d ; interrupts
jmp $fe66 ;exit via
; kernal warm
; start
;---------------------------------------
The above code resets the CIA to its default setting so that when our demo
exits back out to basic, the user is able to type something. =) It then
exits via the Kernal warm start vector to reset other important things
like the VIC chip. =)
rotate ldy #$00
rotate1 lda theta,y ;get theta
clc
adc angleinc ;add amount
sta theta,y ;store theta
iny
cpy points ;do all points
bne rotate1
rts
;---------------------------------------
Okay, there it is. The code that actually rotates the shape. It takes the
current value of the theta coordinate for each endpoint and adds the value
of "angleinc" to it. Extremely simple and quite fast too. =) You can speed
it up a bit by unrolling this loop, but for this demo, there aren't enough
endpoints to work through to get that much of a savings.
drawshape ldy #$00 ;first point
lda theta,y ;pass theta &
sta gxytheta ; radius to
lda radiu,y ; getxy for
sta gxyradius ; conversion
jsr getxy ;
lda xpos ;convert polar
clc ; to
adc #64 ; Cartesian
sta x1 ;
lda ypos ;
clc ;
adc #64 ;
sta y1 ;
The above code starts off the shape drawing routine. It gets the first
endpoint prior to entering the loop below. The loop below joins endpoint
to endpoint with a line.
You will notice that we do actually convert from the radius,theta system
to the X,Y system, finally. This is necessary because I haven't yet
written a routine that will draw lines only from radius and theta. =) Also
notice that it adds 64 to both the X and Y coordinate. This is to center
the shape in our character matrix. The routine that converts from
radius,theta to X,Y returns numbers ranging from -63 to +63, so adding 64
also normalizes our coordinates to make them easier to plot in our
character matrix. (It makes the range of possible values equal to 0 to
+127)
ldy #$01 ;second point
ds2 lda theta,y
sta gxytheta
lda radiu,y
sta gxyradius
jsr getxy
lda xpos
clc
adc #64
sta x2
lda ypos
clc
adc #64
sta y2
sty dsy ;preserve .y
jsr drawline ;draw a line
ldy dsy ;restore .y
lda x2 ;make endpoint
sta x1 ; of this line
lda y2 ; start point
sta y1 ; of next line
iny ;do all points
cpy points ;
bne ds2 ;
That's the routine that puts the shape on the screen. You may of noticed
that each shape has one extra endpoint. For example, the triangle has four
endpoints. This is to allow the shape drawing routine a place to end the
last line. We of course, want to make the last endpoint equal to the first
endpoint. This causes the routine to complete the shape.
lda $d018 ;show our work
eor #%00000010 ;
sta $d018 ;
Once we have finished drawing the shape in the buffer, we tell the VIC to
display the buffer. This technique is known as double buffering. We
display one buffer, while we do all our work in the other. When we are
done with the work, we display that buffer, and do all our work in the
first.
A nifty trick in situations like these is to use the VIC to our advantage.
Since we are using a character matrix to do our drawing in, we make both
of our buffers in sequential character matrix slots in memory. Then to
swap the displayed buffers, we merely toggle a bit in the VIC register
that tells the VIC which matrix to display. =)
A little confused? Well hopefully this will clear things up, at least a
little. We start our program with the VIC pointing at buffer#0 which is at
$2000. Bits 3,2,and 1 of $d018 control which address the VIC finds the
character matrix. Here is a nifty table showing the addresses which
correlate to those bits in $d018:
$d018 points to
----- ---------
%xxxx000x $0000
%xxxx001x $0800
%xxxx010x $1000
%xxxx011x $1800
%xxxx100x $2000 -> This is our Buffer#0
%xxxx101x $2800 -> This is our Buffer#1
%xxxx110x $3000
%xxxx111x $3800
You can see how we can make the VIC do all the work of displaying the
right buffer. All we have to do is toggle bit 1 of $d018 to make the VIC
switch between the character matrix at $2000 and the one at $2800.
lda $d018 ;clear the
and #%00000010 ; next buffer
beq ds4 ; for drawing
jsr blank0 ; in
jmp ds5 ;
ds4 jsr blank1 ;
This code checks which buffer is currently being displayed and the JSRs to
the routine to clear the OTHER one, in preparation for drawing in.
ds5 rts
dsy .byte $00
;---------------------------------------
Finish up... "dsy" is a temporary storage location.
getxy sty gxyy ;preserve .y
sta gxya ; .a
ldy gxytheta ;
lda mcos,y ;a
sec ;
sbc gxyradius ;-b
tay ;
lda msqr,y ;f(a-b)
sta gxytemp ;store result
ldy gxytheta ;
lda mcos,y ;a
clc ;
adc gxyradius ;+b
tay ;
lda msqr,y ;f(a+b)
sec ;
sbc gxytemp ;-f(a-b)
sta xpos ;=x coordinate
Ah, now you get to see the fast multiplication in action. This routine is
based heavily on the routine outlined by Steven Judd in C=Hacking. He has
already documented fairly well how the table of squares work, so I'll not
re-invent the wheel by explaining precisely how it works. What I will do
is step you through the steps of what this code does.
Okay, know that you can arrive at A*B with a function like:
f(A+B) - f(A-B) when f(x) = (x^2)/4.
I created a table of squares such that the offset from the beginning of
the table was the (x) in the f(x) above. For example, location $3300 + 0 =
0, since obviously (0^2)/4 is still 0. By the same token, $3300 + 9 = 20,
since (9^2)/4 = 20.25.
In our case, the radius component is the (A) and the (cos (theta))
component is the (B). Those who didn't sleep through trigonometry class
will recall that when converting from radius,theta into X,Y, your X
coordinate is R * cos(theta). Hence, our A*B routine.
Those that have read ahead, will note that I made some adjustments to the
tables to the effect that the sin and cos tables are multiplied by 64, and
that our table of squares is really the result of a function where f(x) =
(x^2)/4*64. The reason for this is to maintain some level of accuracy in
our tables. If you don't understand why this was done, I'll explain it
further when I detail the basic programs that build our tables.
ldy gxytheta ;
lda msin,y ;a
sec ;
sbc gxyradius ;-b
tay ;
lda msqr,y ;f(a-b)
sta gxytemp ;store result
ldy gxytheta ;
lda msin,y ;a
clc ;
adc gxyradius ;+b
tay ;
lda msqr,y ;f(a+b)
sec ;
sbc gxytemp ;-f(a-b)
sta ypos ;=y coordinate
ldy gxyy ;restore .y
lda gxya ;restore .a
rts
;----------------------------
gxyradius .byte $00
gxytheta .byte $00
xpos .byte $00
ypos .byte $00
gxyy .byte $00
gxya .byte $00
gxytemp .byte $00
;---------------------------------------
The code above does exactly the same thing the last piece of code did,
except this time we were calculating the Y coordinate, and of course, to
be trigonomically correct, our multiplication performs this equation:
Y = R * sin(theta).
The labels at the end are for temporary storage of values during the
multiplication routine.
plot pha ;preserve .a
lda $d018 ;plot in
and #%00000010 ; correct
bne plot2 ; buffer
plot1 lda lobyte,x ;lo byte
sta $02 ;
lda hibyte1,x ;hi byte
sta $03 ;
lda ($02),y ;
ora bitmask,x ;turn pixel on
sta ($02),y ;
pla ;restore .a
rts
;---------------------------------------
plot2 lda lobyte,x ;lo byte
sta $02 ;
lda hibyte0,x ;hi byte
sta $03 ;
lda ($02),y ;
ora bitmask,x ;turn pixel on
sta ($02),y ;
pla ;restore .a
rts
;---------------------------------------
Shoooom! There it is! If you blinked you may of missed it. The plot
routine is quite small, and its even smaller if your program doesn't need
to decide which buffer it needs to plot in.
In detail, first it checks which buffer we are working in and branches to
the appropriate plot routine.
How it works: the X register holds our X coordinate, and the Y register
holds our Y coordinate. Both our X and Y registers hold a value between 0
and 127. Knowing that, we can quickly and easily use some cleverly thought
out planning ahead to make plotting a pixel super fast and very clean.
Things we planned for ahead of time: We drew our character grid on the
screen such that the addresses that define the character data are laid out
to our advantage. Then we made a couple tables with data that makes it
extremely simple to look up the address of the byte where we want to plot
a pixel.
Sound a little vague? I'll explain in greater detail when we get to the
basic programs that set up the tables and also the little routine that
lays out our character grid.
First, it looks up an address based on our X coordinate. Each byte has 8
pixels so, our table looks like this:
$3300 $00 $00 $00 $00 $00 $00 $00 $00
$3308 $80 $80 $80 $80 $80 $80 $80 $80
$3310 $00 $00 $00 $00 $00 $00 $00 $00
$3318 $80 $80 $80 $80 $80 $80 $80 $80
...
Notice that the values change every eight locations? Each byte has eight
pixels. For example, imagine that the X coordinate is 0. We get the first
(0th) byte from our low byte table and see its a zero. Its easy to see
that we would always be plotting in the first (0th) byte until X is
greater than 7 (i.e.: 8) in which case the value in our low byte table is
$80. $80 is 128 bytes over from our first column of bytes, and holds the
byte that has pixels 8-15 in it. If you are still confused, I will explain
this further when we get to the routine that builds our character grid on
the screen.
Now that we have the low byte, we need a high byte. Again we look into a
cleverly planned table using X as our index. The high byte table looks
alot like the low byte table except that we change values every sixteen
bytes. Take a look:
$3380 $20 $20 $20 $20 $20 $20 $20 $20
$3388 $20 $20 $20 $20 $20 $20 $20 $20
$3390 $21 #21 $21 $21 $21 $21 $21 $21
$3398 $21 #21 $21 $21 $21 $21 $21 $21
...
This is because each column only has 128 pixels in it. If the X coordinate
is 0-7, then the byte that holds our pixel is at $2000. When the X
coordinate is 8-15, the byte is at $2080. Only when X is 16-23 does our
high byte change from $20 to, in this example, $21, since the bye we are
looking for would be $2100.
Now, we got an address based on the value of X. But what about Y? We
aren't always going to be plotting in the first top row of pixels! Since
we were clever in how we laid out our character grid, Y becomes an offset
from our address. We figured our how far to go across in bytes from a
table, but we don't need a table to figure out how far down to go. We
simply address the byte using indexed addressing. =) So, for example if
our Y coordinate was 5, the instruction LDA ($02),Y would get the 5th byte
down from the byte we arrived at earlier.
Nifty eh?
After we get the byte, we need to turn on a pixel. This is where the
bitmask table comes in. Our bitmask table looks like this:
$3480 $80 $40 $20 $10 $08 $04 $02 $01
$3488 $80 $40 $20 $10 $08 $04 $02 $01
$3490 $80 $40 $20 $10 $08 $04 $02 $01
$3498 $80 $40 $20 $10 $08 $04 $02 $01
...
It should be obvious how this table works. This table allows us to arrive
at the right pixel to turn on (via ORA) when we plot. Notice that it
repeats every eight bytes, and notice that there are eight pixels in a
byte. =)
drawline sec ;get dx
lda x1 ;
sbc x2 ;
sta dx ;
sec ;get dy
lda y1 ;
sbc y2 ;
sta dy ;
clc ;
lda dx ;
bpl drawline2 ;handle -dx
eor #%11111111 ;make dx
adc #%00000001 ; positive
sta dx ;
lda dy ;
bpl drawline1 ;handle -dy
eor #%11111111 ;make dy
adc #%00000001 ; positive
sta dy ;
lda dx
cmp dy
bcs dl00
jmp dl10
drawline1 lda dx
cmp dy
bcs dl20
jmp dl30
drawline2 lda dy
bpl drawline3
eor #%11111111
adc #%00000001
sta dy
lda dx
cmp dy
bcs drawline4 ;dl40
jmp dl50
drawline3 lda dx
cmp dy
bcs drawline5 ;dl50
jmp dl70
el rts
drawline4 jmp dl40
drawline5 jmp dl60
;---------------------------------------
The above code determines the slope of the line to be drawn. This is the
part of my code that I *know* in my gut I can improve on, but as of yet
have been unable to. There are eight separate little routines below that
draw a line. Each one is slightly different, they are written to handle
each of the eight possible types of line slopes that can be encountered
when drawing a line between two points.
The values DX and DY are calculated such that DX=X2-X1, and DY=Y2-Y1.
dl00 lda #$00 ;0 - dx
sbc dx ;
ldx x1 ;plot first
ldy y1 ; pixel
jsr plot ;
dl00a clc ;step in x
inx ; positive
adc dy ; until time
bcc dl00b ; to take a
iny ; positive
sbc dx ; step in y
dl00b jsr plot ;
cpx x2 ;
bne dl00a ;
rts
;----------------------------
All eight of these routines are basically the same with only two real
differences:
1) The value which is being stepped through until it's time to step the
other value.
2) The direction of the stepping
Here is a step-by-step description of what the above does:
1. Subtract DX (change in X) from zero
2. Plot the first pixel
3. Step upwards in values of X, until it is time to take a step in Y
4. Plot the pixel
5. Loop back until we've reached the second endpoint
Each of the following routines works exactly the same way.
dl10 lda #$00
sbc dy
ldx x1
ldy y1
jsr plot
dl10a clc ;step +y
iny ; until need
adc dx ; to +x
bcc dl10b ;
inx ;
sbc dy ;
dl10b jsr plot ;
cpy y2 ;
bne dl10a ;
rts
;----------------------------
dl20 lda #$00
sbc dx
ldx x1
ldy y1
jsr plot
dl20a clc ;step +x
inx ; until need
adc dy ; to -y
bcc dl20b ;
dey ;
sbc dx ;
dl20b jsr plot ;
cpx x2 ;
bne dl20a ;
rts
;----------------------------
dl30 lda #$00
sbc dy
ldx x1
ldy y1
jsr plot
dl30a clc ;step -y
dey ; until need
adc dx ; to +x
bcc dl30b ;
inx ;
sbc dy ;
dl30b jsr plot ;
cpy y2 ;
bne dl30a ;
rts
;----------------------------
dl40 lda #$00
sbc dx
ldx x1
ldy y1
jsr plot
dl40a clc ;step -x
dex ; until need
adc dy ; to +y
bcc dl40b ;
iny ;
sbc dx ;
dl40b jsr plot ;
cpx x2 ;
bne dl40a ;
rts
;----------------------------
dl50 lda #$00
sbc dy
ldx x1
ldy y1
jsr plot
dl50a clc ;step +y
iny ; until need
adc dx ; to -x
bcc dl50b ;
dex ;
sbc dy ;
dl50b jsr plot ;
cpy y2 ;
bne dl50a ;
rts
;----------------------------
dl60 lda #$00
sbc dx
ldx x1
ldy y1
jsr plot
dl60a clc ;step -x
dex ; until need
adc dy ; to -y
bcc dl60b ;
dey ;
sbc dx ;
dl60b jsr plot ;
cpx x2 ;
bne dl60a ;
rts
;----------------------------
dl70 lda #$00
sbc dy
ldx x1
ldy y1
jsr plot
dl70a clc ;step -y
dey ; until need
adc dx ; to -x
bcc dl70b ;
dex ;
sbc dy ;
dl70b jsr plot ;
cpy y2 ;
bne dl70a ;
rts
;---------------------------------------
x1 .byte $00
y1 .byte $00
x2 .byte $00
y2 .byte $00
dx .byte $00
dy .byte $00
;---------------------------------------
The values above are temporary holding places for the values used and
generated by the drawline routines.
demoinit lda #$06 ;dark blue
sta $d020 ; background
sta $d021 ; and border
lda #147 ;clear screen
jsr $ffd2 ;
lda #$7f ;disable cia
sta $dc0d ; time irqs
jsr blank0 ;clear both
jsr blank1 ; buffers
lda #$00
sta char
ldy #$00 ;dirty way to
demoinit4 lda #scrloc ; matrix on
sta $fb ; the screen
ldx #$00 ;
demoinit5 lda char ; the top
sta ($fa),y ; left corner
inc char ; is the
lda $fa ; value in
clc ; scrloc
adc #40 ;
sta $fa ;
bcc demoinit6 ;
inc $fb ;
demoinit6 inx ;
cpx #16 ;
bne demoinit5 ;
iny ;
cpy #16 ;
bne demoinit4 ;
ldy #$00 ;fill color
lda #$01 ; memory with
demoinit10 sta $d800,y ; white
sta $d900,y ;
sta $da00,y ;
sta $db00,y ;
iny ;
bne demoinit10 ;
lda $d018 ;point VIC to
and #%11110000 ; first
ora #%00001000 ; buffer
sta $d018 ;
jsr initobj00 ;1st shape
lda #$00 ;init
sta angleinc ; variables
sta curshape ;
rts
char .byte $00
;---------------------------------------
The above initialization routine sets everything up for the demo. In order
of appearance, here is an explanation of what each part of this
initialization does.
1. Turn the border and background dark blue.
2. Clear the screen
3. Disable the CIA timer IRQs
4. Clear both of the drawing buffers
5. Draw our character grid on the screen
6. Fill Color RAM with WHITE
7. Point the VIC to the first buffer (Buffer#0)
8. Initialize the first shape
9. Initialize the "angleinc" and "curshape" variables.
Drawing the character grid on the screen could possibly of been done a
little better. But as it says in the comments, its quick and dirty, but it
does the job. =)
Using our brains a bit, we draw the character grid on the screen in such a
way that starting with zero (the @ sign) we place sequential characters on
the screen in columns, 16 down, by 16 across. This enables us to use a
very nifty and fast plotter as described above. Laying out our character
grid in this manner, gives us 128 sequential bytes in the first column,
128 sequential bytes in the second, and so on.
You can make character grids of any size (up to 16*16) in this manner very
easily. A smaller grid frees up characters to be used for other things,
like say a niftycool border or other graphics to be used along side of the
character grid where your vectors are being drawn. You just have to adjust
your low byte and high byte tables accordingly.
blank0 ldy #$00
lda #$00
blank0a sta $2000,y
sta $2080,y
sta $2100,y
sta $2180,y
sta $2200,y
sta $2280,y
sta $2300,y
sta $2380,y
sta $2400,y
sta $2480,y
sta $2500,y
sta $2580,y
sta $2600,y
sta $2680,y
sta $2700,y
sta $2780,y
iny
bpl blank0a
rts
;---------------------------------------
Clears the first buffer (buffer#0). Unfortunately, these clear routines
are real cycle hogs. There just aren't many fast ways to zero out 4k of
memory.
blank1 ldy #$00
lda #$00
blank1a sta $2800,y
sta $2880,y
sta $2900,y
sta $2980,y
sta $2a00,y
sta $2a80,y
sta $2b00,y
sta $2b80,y
sta $2c00,y
sta $2c80,y
sta $2d00,y
sta $2d80,y
sta $2e00,y
sta $2e80,y
sta $2f00,y
sta $2f80,y
iny
bpl blank1a
rts
;---------------------------------------
The above clears the second buffer (buffer#1)...
initobj00 lda #$04
sta points
ldy #$00
initobj01 lda theta00,y
sta itheta,y
sta theta,y
lda radiu00,y
sta iradiu,y
sta radiu,y
iny
cpy points
bne initobj01
rts
;---------------------------------------
initobj10 lda #$05
sta points
ldy #$00
initobj11 lda theta10,y
sta itheta,y
sta theta,y
lda radiu10,y
sta iradiu,y
sta radiu,y
iny
cpy points
bne initobj11
rts
;---------------------------------------
initobj20 lda #$09
sta points
ldy #$00
initobj21 lda theta20,y
sta itheta,y
sta theta,y
lda radiu20,y
sta iradiu,y
sta radiu,y
iny
cpy points
bne initobj21
rts
;---------------------------------------
theta00 .byte 0,86,172,0
radiu00 .byte 40,40,40,40
theta10 .byte 0,64,192,128,0
radiu10 .byte 40,40,40,40,40
theta20 .byte 0,96,192,32,128
.byte 224,64,160,0
radiu20 .byte 40,40,40,40,40
.byte 40,40,40,40
The above short routines are the three that define the three shapes I
included in this demo. The initialization for a shape is very simple. You
store the number of endpoints in the "points" variable, and then copy the
information from the appropriate table into the "theta" and "radiu"
tables. I also copy the values into the "itheta" and "iradiu" tables in
case there is a routine that needs to reference the initial values rather
than the current values.
Also note, that as mentioned before, the last end point is the same as the
first endpoint. This closes off the shape by drawing a line back to the
first endpoint.
Well, there you have it! Documented source code for a demonstration of a
different way to play with two-dimensional vectors. What follows are the
basic programs used to create the data tables used by the above program,
and of course, the uuencoded programs themselves.
The BASIC Programs
------------------
The first program is the program which builds the sine, cosine and squares
tables.
1 rem -+- make sin/cos/sqr 2.0 -+-
2 rem -+- -+-
3 rem -+- by: waveform -+-
4 rem -+- for: disC=overy magazine -+-
5 rem -+- on: 09-14-96 -+-
10 rem ::: make sin and cos tables :::
12 ba=12288:bh=int(ba/256):bl=ba-bh*256
"ba" is the starting address for the data created by this program.
14 forby=0to255
16 de=by*1.407:ra=de*(pi/180)
18 s=int((sin(ra)*64)+.5)
20 ifs<0thens=255-abs(s)+1
22 c=int((cos(ra)*64)+.5)
24 ifc<0thenc=255-abs(c)+1
26 poke ba + by,s:poke ba + 256 + by,c
28 next
The above loop makes both the sine table and the cosine table. Also please
note that in place of the word "pi" in line 16 above, you should instead
use Commodore Basic's pi symbol.
Step-by-step, the loop does this:
1. Convert from byts to degrees.
2. Convert from degrees to radians. This is necessary since Commodore's
Basic trigonomic functions work with radians.
3. Calculate the sine of the angle.
4. If the sine is less than 0 (i.e.. negative) adjust the number.
5. Calculate the cosine of the angle
6. If the cosine is negative, adjust the number.
7. Store both the sine and cosine in their tables.
8. Loop back until all 256 byts have been calculated and stored in a
table.
When we calculate the sine or cosine of an angle, it becomes quickly
evident that except when the result is 0 or 1, the result is always a
decimal number. Our Commodores don't have a quick and easy way to store a
decimal number, certainly not in one byte.
Rather than mess with program code to deal with decimal numbers, we can
resolve this issue rather quickly by some planning ahead here when we
create our tables.
If we take a decimal number, for instance .707107 (the sine of 45 degrees,
or 32 byts) and multiply that number by a constant, in our case 64, we can
arrive at a number which is much easier for our computers to store: 45.25.
The fractional part of the number is chopped off when we store the value
to memory, but what remains is a value that we can work with.
Incidentally, we add the .5 to the value to reduce the rounding errors
caused when the fractional portion of the number is chopped off.
What is this about "adjusting" the number, anyway? Well, we know how to
store a decimal number now, but what about a number that's negative?
One of the nifty things about the math instructions on a Commodore is that
they work the same for both unsigned and signed arithmetic. But to store a
negative number you have to use twos compliment. To arrive at the twos
compliment (negative) number, you flip all of the bits, and add one.
Commodore basic doesn't have an EOR instruction, so we do the next best
thing: subtract the number from 255. Subtracting a number from 255 has the
same effect as EORing a number by %11111111, which would, of course, flip
all of the bits. We then add one, and POOF, the twos complement of a
number.
The niftiness about twos compliment and signed values in assembly, is that
it gives us a way to represent negative numbers. When you ADD or SBC with
these numbers, the instructions work just as they did before, but the
perform the task you'd expect by using a negative number.
Steven Judd talks a bit about this in the same articles for C=Hacking that
he wrote detailing how the table of squares works for fast multiplication.
Also, you can read more about this in virtually any book or reference work
that talks about the 65xx line of microprocessors.
Having mentioned that, how do we arrive at the right answer later on if
one of our values has been multiplied by a factor of 64? Read on...
50 rem ::: make sqr table :::
52 forby=0to127
54 sq=(by*by)/(4*64)
56 poke ba + 512 +by,sq:next
60 forby=0to127
62 sq=(by*by)/(4*64)
64 poke ba + 512 +255-by,sq:next
The above loop creates a table of squares. I did a little planning ahead
as well, and realized that the table need only be 128 bytes long. Recall
our niftycool formula for fast multiplication: f(a+b) - f(a-b) = a*b.
When we do the first part of the formula (f(a+b)) you can see from how our
program works that the radius is never larger than 64, and at the most,
the value from our sine table will be is 64. Remember from trig class that
sines and cosines range from 0 to 1. =) Since we multiplied our sine and
cosine values by 64, the largest value we could ever get is 64.
Well, you say, but since the values you pull from your sine and cosine
table can be negative, what happens if the result of A+B or A-B is
negative? The result of a squaring will always be positive, so we don't
have to store any numbers using twos compliment, but we will end up with
situations where the sum or the difference of A and B will be negative. We
resolve this by building a second table of squares above the first, and we
build it downward in memory.
Hopefully, this example will clear up any confusion:
If A (our radius) is 20, and the sine of our angle is -40, the sum of A
and B is -20. The value in the register is 236, which means -20 in two
complement. Since we built another table above the first 128 byte table of
squares, we are free and clear. Our foresight put the correct value for
f(-20) in that location.
Now, there is one more issue to deal with. We multiplied all of our sines
and cosines by a factor of 64. Somewhere we have to divide by 64 to keep
the equation equal (and to not freak out my 7th grade algebra instructor)
so we take a look at the function we have for f(x):
f(x)=(x^2)/4
We realize we can do that *divide-by-64* thing here, to arrive at:
f(x)=(x^2)/4/64
Or, written another way:
f(x)=(x^2)/4*64 which is also f(x)=(x^2)/128
I left it as 4*64 in the program for clarity sake.
100 rem ::: save to disk :::
102 open1,8,15,"s0:sin/cos/sqr":close1
104 open2,8,2,"sin/cos/sqr,p,w"
106 print#2,chr$(bl)chr$(bh);
108 fort=0to767
110 print#2,chr$(peek(ba+t));
112 next
114 close2
The above simply saves the table we created to disk, with a loading
address of $3000. =) Just what the demo needs! =)
Now, on to the second program...
The second program is the program to build the low byte, high byte and
bitmask tables.
1 rem -+- make base/mask table 2.0 -+-
2 rem -+- -+-
3 rem -+- by: waveform -+-
4 rem -+- for: disC=overy magazine -+-
5 rem -+- on: 09-14-96 -+-
10 ba = 13056 : cb=8192
"ba" is the starting address for the data created by this program.
"cb" is the base address for the character matrix used by our demo.
12 bh=int(ba/256):bl=ba-bh*256
100 c=0:fort=0 to 15
102 forq=0to7
104 b1=cb+(t*128)
106 hb=int(b1/256):lb=b1-hb*256
108 poke ba + c,lb:poke ba + 128 + c,hb
110 c=c+1:nextq,t
The above loop creates the low byte table as well as the high byte table
for the first buffer (buffer#0)
120 c=0:fort=0 to 15
122 forq=0to7
124 b1=cb+2048+(t*128)
126 hb=int(b1/256):lb=b1-hb*256
128 poke ba +256 +c,hb
130 c=c+1:nextq,t
The above loop creates the high byte table for the second buffer
(buffer#1)
150 fort=0 to 15
152 forq=0to7
154 poke ba + 384+(t*8)+q,2 (7-q)
156 nextq,t
The above loop creates the bitmask table.
200 open1,8,15,"s0:base/mask":close1
202 open2,8,2,"base/mask,p,w"
204 print#2,chr$(bl)chr$(bh);
206 fort=0to511
208 print#2,chr$(peek(ba+t));
210 next
212 close2
Here we have a small routine to save the tables created by this program to
disk, with a loading address of $3300.
UUEncoded Files
---------------
Below you will find the uuencoded files detailed in this article. I
included TurboAssmembler source, Object code (sys 2080 to run), both
tables needed by the program to run, as well as the basic programs used to
create them.
I will make all of these available in a zip package on my web site:
http://marie.az.com/~waveform
How To Get The Demo To Run
--------------------------
There wasn't enough time to write a loader for this demo before the
deadline, and even though my gracious host allowed me the opportunity to
add one, it is really more trouble than its worth.
So for those of you explorers who want to know how things are really
done, here's a quick and simple method of launching this demo:
Step One: load "sin_cos_sqr",8,1
Step Two: load "base_mask",8,1
Step Three: load "disc-demo.obj",8,1
Step Four: sys2080
[Ed. Note : To prevent possible compatibility problems with unix file-handling,
the UUencoded files in this article will extract with filenames as seen
in the loading sequence above. If you generate new tables with the basic
table generators, then the new tables will be named to their original
designations (i.e., sin/cos/sqr instead of sin_cos_sqr). Please remember
to change filenames in your loading procedure to match.]
Demo-Controls
-------------
F1 : increments angle (apparent speed)
F3 : decrements angle
F5 : expands shape
F7 : shrinks shape
: changes shape
: resets to default size and angle
: quits the demo
--
For more information or general commentary on this article, Mr. John Kaiser
(Waveform/MLM) may be reached at waveform@az.com
Addenum by S. Judd, Technical Editor
------+------^-------^------+-------
John shrewdly omitted a few "tricks" in order for the code to flow more
clearly as a learning experience. Once the process is well-understood, a
bit of sneaky optimization can be undertaken, as follows :
[...]
> ;---------------------------------------
> expdn ldy #$00
> expdn1 lda radiu,y
> sec
> sbc #$01 ;subtract one
> cmp #2 ;at minimum?
> bcs expdn2
> lda #2
> expdn2 sta radiu,y ;store
> iny
> cpy points ;do all points
> bne expdn1
This can be written more efficiently, as follows :
expdn LDX POINTS ;Start at top
:L1 LDA RADIU,X
CMP #3
BCC :SKIP
DEC RADIU,X
:SKIP DEX
BPL :L1 ;Only allows 128 points though
It is always better to start Y large and count downwards when you can.
His loop takes 4+2+3+2+3/(2+2)+4+2+3 = 23/24 cycles per iteration, while
the rewrite takes 4+2+3/(2+7)+2 = 11/17 cycles per iteration, and a few
less bytes too. Here it is not such a huge deal -- 6 cycles savings
per loop for the one usually used -- but this kind of trick can sometimes
lead to immense savings.
[...]
> rotate ldy #$00
In 'sneaky mode' we could start at Y points and go downwards here as well.
> rotate1 lda theta,y ;get theta
> clc
> adc angleinc ;add amount
> sta theta,y ;store theta
> iny
> cpy points ;do all points
> bne rotate1
> rts
[...]
> ;---------------------------------------
> plot2 lda lobyte,x ;lo byte
> sta $02 ;
> lda hibyte0,x ;hi byte
> sta $03 ;
>
> lda ($02),y ;
> ora bitmask,x ;turn pixel on
> sta ($02),y ;
>
> pla ;restore .a
> rts
> ;---------------------------------------
Please note :
1- Using a JSR plot each time adds 12 cycles (JSR + RTS)
2- Most of the time you plot within the same byte.
That is, reloading $02/$03 each time is redundant by a
factor of 8 at the very least. (The x-coordinate is
not going to change by more than 1 at each iteration!)
Every cycle saved in a line drawing routine produces huge dividends. If
you have an object with just three lines in it, and each line has 100
points in it, you suddenly start saving thousands of cycles, (i.e., using
a JSR adds 3600 cycles immediately). Those 14 cycles in loading the
coordinate each time translates to many extra thousand cycles too.
In raster time, we're talking well over half the screen here!
In general, if it's in a loop, you can't optimize it enough :).
Again, though, doing things this way makes things much clearer (which makes
life easier on the programmer too).
--
begin 644 disc-demo.sou
M.RTM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+0T[("#!
M(,1%34\@3T8@Q$E30SU/5D5262`M(,)9.B#7059%1D]230T[#3L@("A#*2`Q
M.3DV($9/4B#$25-#/4]615)9(,U!1T%:24Y%#3LBU$A%(,I/55).04P@1D]2
M(,-/34U/1$]212#%3E1(55-)05-44R(-.RTM+2TM+2TM+2TM+2TM+2TM+2TM
M+2TM+2TM+2TM+2TM+2TM+2TM+0T@("`@("`@("`@("H]("0P.#(P#0U03TE.
M5%,@("`@(#T@)#`S,T,@("`[3E5-0D52($]&(%!/24Y44PU!3D=,14E.0R`@
M(#T@)#`S,T0@("`[04Y'3$4@5$\@24Y#4D5-14Y4#4-54E-(05!%("`@/2`D
M,#,S12`@(#M#55)214Y4(%-(05!%#51(151!("`@("`@/2`D,#,T,"`@(#M4
M2$5405,-4D%$254@("`@("`]("0P,S4P("`@.U)!1$E54PU)5$A%5$$@("`@
M(#T@)#`S-C`@("`[5$%"($]&($E.250@5$A%5$%3#4E2041)52`@("`@/2`D
M,#,W,"`@(#L@("`@("`@24Y)5"!2041)55,-#5-#4DQ/0R`@("`@/2`Q,3DV
M("`@(#M,3T-!5$E/3B!/1B!43U`-("`@("`@("`@("`@("`@("`@("`@.R!,
M1494($-/4DY%4B!/1@T@("`@("`@("`@("`@("`@("`@("`[($-(05(@34%4
M4DE8($].#2`@("`@("`@("`@("`@("`@("`@(#L@4T-2145.#0U-4TE.("`@
M("`@(#T@)#,P,#`@("`[5$%"3$4@3T8@4TE.15,-34-/4R`@("`@("`]("0S
M,3`P("`@.R`@("`@("`@($-/4TE.15,-35-14B`@("`@("`]("0S,C`P("`@
M.R`@("`@("`@(%-154%215,-3$]"651%("`@("`]("0S,S`P("`@.TQ/($)9
M5$53#4A)0EE413`@("`@/2`D,S,X,"`@(#M(22!"651%4R`H)#(P,#`K*0U(
M24)95$4Q("`@(#T@)#,T,#`@("`[("`@("`@("`@*"0R.#`P*RD-0DE434%3
M2R`@("`]("0S-#@P("`@.U!)6$5,($))5"!-05-+#3LM+2TM+2TM+2TM+2TM
M+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2T-("`@("`@("`@("!*4U(@1$5-
M3TE.250@("`[24Y)5"!&3U(@1$5-3PT@("`@("`@("`@(#LM+2TM+2TM+2TM
M+2TM+2TM+2TM+2TM+2TM+2TM#4U!24X@("`@("`@3$1!(",E,3$Q,3$Q,3`@
M.U-#04X@34%44DE8#2`@("`@("`@("`@4U1!("1$0S`P("`@("`@.PT@("`@
M("`@("`@($Q$02`D1$,P,2`@("`@(#L-#2`@("`@("`@("`@0TU0(",E,3$Q
M,#$Q,3$@.T8Q#2`@("`@("`@("`@0D51($M%648Q#2`@("`@("`@("`@0TU0
M(",E,3$P,3$Q,3$@.T8S#2`@("`@("`@("`@0D51($M%648S#2`@("`@("`@
M("`@0TU0(",E,3`Q,3$Q,3$@.T8U#2`@("`@("`@("`@0D51($M%648U#2`@
M("`@("`@("`@0TU0(",E,3$Q,3`Q,3$@.T8W#2`@("`@("`@("`@0D51($M%
M648W#2`@("`@("`@("`@0TU0(",E,3$Q,3$Q,#$@.U)%5%523@T@("`@("`@
M("`@($)%42!+15E215154DX-#2`@("`@("`@("`@3$1!(",E,#$Q,3$Q,3$@
M.U-#04X@34%44DE8#2`@("`@("`@("`@4U1!("1$0S`P("`@("`@.PT@("`@
M("`@("`@($Q$02`D1$,P,2`@("`@(#L-#2`@("`@("`@("`@0TU0(",E,3$Q
M,#$Q,3$@.U-004-%#2`@("`@("`@("`@0D51($M%65-004-%#2`@("`@("`@
M("`@0TU0(",E,#$Q,3$Q,3$@.U)%5%523@T@("`@("`@("`@($)%42!+15E3
M5$]0#0U2145.5%)9("`@($I34B!23U1!5$4@("`@(#M23U1!5$4@4TA!4$4-
M("`@("`@("`@("!*4U(@1%)!5U-(05!%("`[1%)!5R!32$%010T-("`@("`@
M("`@("!*35`@34%)3B`@("`@("`[3$]/4`T[+2TM+2TM+2TM+2TM+2TM+2TM
M+2TM+2TM+2TM+2TM+2TM+2TM+2TM#4M%648Q("`@("`@2DU0(%)/5%50#4M%
M648S("`@("`@2DU0(%)/5$1.#4M%648U("`@("`@2DU0($584%50#4M%648W
M("`@("`@2DU0($584$1.#4M%65)%5%523B`@2DU0($Y%5U-(05!%#4M%65-0
M04-%("`@2DU0(%-43U!23U0-2T594U1/4"`@("!*35`@4U1/4$1%34\-.RTM
M+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+0U23U154"`@
M("`@($E.0R!!3D=,14E.0R`@(#M)3D-214%310T@("`@("`@("`@($I-4"!2
M145.5%)9#3LM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM
M+2T-4D]41$X@("`@("!$14,@04Y'3$5)3D,@("`[1$5#4D5!4T4-("`@("`@
M("`@("!*35`@4D5%3E1260T[+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM
M+2TM+2TM+2TM+2TM#4584%50("`@("`@3$19(",D,#`-15A055`Q("`@("!,
M1$$@4D%$254L60T@("`@("`@("`@($-,0PT@("`@("`@("`@($%$0R`C)#`Q
M("`@("`@(#M!1$0@3TY%#2`@("`@("`@("`@0TU0(",V,R`@("`@("`@.T%4
M($U!6$E-54T_#2`@("`@("`@("`@0D-#($584%50,@T@("`@("`@("`@($Q$
M02`C-C,-15A055`R("`@("!35$$@4D%$254L62`@("`[4U1/4D4-("`@("`@
M("`@("!)3ED-("`@("`@("`@("!#4%D@4$])3E13("`@("`[1$\@04Q,(%!/
M24Y44PT@("`@("`@("`@($).12!%6%!54#$-#2`@("`@("`@("`@2DU0(%)%
M14Y44ED@("`@.U)%5%523@T[+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM
M+2TM+2TM+2TM+2TM#4584$1.("`@("`@3$19(",D,#`-15A01$XQ("`@("!,
M1$$@4D%$254L60T@("`@("`@("`@(%-%0PT@("`@("`@("`@(%-"0R`C)#`Q
M("`@("`@(#M354)44D%#5"!/3D4-("`@("`@("`@("!#35`@(S(@("`@("`@
M("`[050@34E.24U533\-("`@("`@("`@("!"0U,@15A01$XR#2`@("`@("`@
M("`@3$1!(",R#4584$1.,B`@("`@4U1!(%)!1$E5+%D@("`@.U-43U)%#2`@
M("`@("`@("`@24Y9#2`@("`@("`@("`@0U!9(%!/24Y44R`@("`@.T1/($%,
M3"!03TE.5%,-("`@("`@("`@("!"3D4@15A01$XQ#0T@("`@("`@("`@($I-
M4"!2145.5%)9("`@(#M215154DX-.RTM+2TM+2TM+2TM+2TM+2TM+2TM+2TM
M+2TM+2TM+2TM+2TM+2TM+0U.15=32$%012`@($E.0R!#55)32$%010T@("`@
M("`@("`@($Q$02!#55)32$%010T@("`@("`@("`@($--4"`C,R`@("`@("`@
M(#M,05-4(%-(05!%/PT@("`@("`@("`@($).12!.15=32$%013$@(#M.3U!%
M#2`@("`@("`@("`@3$1!(",D,#`@("`@("`@.U-%3$5#5"!&25)35`T@("`@
M("`@("`@(%-402!#55)32$%012`@(#L@4TA!4$4-#4Y%5U-(05!%,2`@0TU0
M(",R("`@("`@("`@.S@@4$])3E0@4U1!4C\-("`@("`@("`@("!"3D4@3D57
M4TA!4$4R#2`@("`@("`@("`@2E-2($E.251/0DHR,"`@.TE.250@4TA!4$4-
M("`@("`@("`@("!*35`@4D5%3E1260U.15=32$%013(@($--4"`C,2`@("`@
M("`@(#LR(%1224%.1TQ%4S\-("`@("`@("`@("!"3D4@3D574TA!4$4S#2`@
M("`@("`@("`@2E-2($E.251/0DHQ,"`@.TE.250@4TA!4$4-("`@("`@("`@
M("!*35`@4D5%3E1260U.15=32$%013,@($I34B!)3DE43T)*,#`@(#LQ(%12
M24%.1TQ%#0T@("`@("`@("`@($I-4"!2145.5%)9#3LM+2TM+2TM+2TM+2TM
M+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2T-4U1/4%)/5"`@("!,1$$@(R0P
M,"`@("`@("`[4U1/4"!!3$P-("`@("`@("`@("!35$$@04Y'3$5)3D,@("`[
M(%)/5$%424].#2`@("`@("`@("`@2DU0(%)%14Y44ED@("`@.PT[+2TM+2TM
M+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM#5-43U!$14U/("`@
M3$1!(",D.#$@("`@("`@.U)%4T54($-)00T@("`@("`@("`@(%-402`D1$,P
M1"`@("`@(#L@24Y415)255!44PT-("`@("`@("`@("!*35`@)$9%-C8@("`@
M("`[15A)5"!624$-("`@("`@("`@("`@("`@("`@("`@("`@("`[($M%4DY!
M3"!705)-#2`@("`@("`@("`@("`@("`@("`@("`@("`@.R!35$%25`T[+2TM
M+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM#5)/5$%412`@
M("`@3$19(",D,#`-4D]4051%,2`@("!,1$$@5$A%5$$L62`@("`[1T54(%1(
M151!#2`@("`@("`@("`@0TQ##2`@("`@("`@("`@041#($%.1TQ%24Y#("`@
M.T%$1"!!34]53E0-("`@("`@("`@("!35$$@5$A%5$$L62`@("`[4U1/4D4@
M5$A%5$$-("`@("`@("`@("!)3ED-("`@("`@("`@("!#4%D@4$])3E13("`@
M("`[1$\@04Q,(%!/24Y44PT@("`@("`@("`@($).12!23U1!5$4Q#0T@("`@
M("`@("`@(%)44PT[+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM
M+2TM+2TM#41205=32$%012`@3$19(",D,#`@("`@("`@.T9)4E-4(%!/24Y4
M#0T@("`@("`@("`@($Q$02!42$5402Q9("`@(#M005-3(%1(151!("8-("`@
M("`@("`@("!35$$@1UA95$A%5$$@("`[(%)!1$E54R!43PT@("`@("`@("`@
M($Q$02!2041)52Q9("`@(#L@1T546%D@1D]2#2`@("`@("`@("`@4U1!($=8
M65)!1$E54R`@.R!#3TY615)324].#2`@("`@("`@("`@2E-2($=%5%A9("`@
M("`@.PT-("`@("`@("`@("!,1$$@6%!/4R`@("`@("`[0T].5D525"!03TQ!
M4@T@("`@("`@("`@($-,0R`@("`@("`@("`@(#L@5$\-("`@("`@("`@("!!
M1$,@(S8T("`@("`@("`[($-!4E1%4TE!3@T@("`@("`@("`@(%-402!8,2`@
M("`@("`@(#L-("`@("`@("`@("!,1$$@65!/4R`@("`@("`[#2`@("`@("`@
M("`@0TQ#("`@("`@("`@("`@.PT@("`@("`@("`@($%$0R`C-C0@("`@("`@
M(#L-("`@("`@("`@("!35$$@63$@("`@("`@("`[#0T@("`@("`@("`@($Q$
M62`C)#`Q("`@("`@(#M314-/3D0@4$])3E0-1%,R("`@("`@("!,1$$@5$A%
M5$$L60T@("`@("`@("`@(%-402!'6%E42$5400T@("`@("`@("`@($Q$02!2
M041)52Q9#2`@("`@("`@("`@4U1!($=865)!1$E54PT@("`@("`@("`@($I3
M4B!'151860T@("`@("`@("`@($Q$02!84$]3#2`@("`@("`@("`@0TQ##2`@
M("`@("`@("`@041#(",V-`T@("`@("`@("`@(%-402!8,@T@("`@("`@("`@
M($Q$02!94$]3#2`@("`@("`@("`@0TQ##2`@("`@("`@("`@041#(",V-`T@
M("`@("`@("`@(%-402!9,@T@("`@("`@("`@(%-462!$4UD@("`@("`@(#M0
M4D5315)612`N60T@("`@("`@("`@($I34B!$4D%73$E.12`@(#M$4D%7($$@
M3$E.10T@("`@("`@("`@($Q$62!$4UD@("`@("`@(#M215-43U)%("Y9#0T@
M("`@("`@("`@($Q$02!8,B`@("`@("`@(#M-04M%($5.1%!/24Y4#2`@("`@
M("`@("`@4U1!(%@Q("`@("`@("`@.R!/1B!42$E3($Q)3D4-("`@("`@("`@
M("!,1$$@63(@("`@("`@("`[(%-405)4(%!/24Y4#2`@("`@("`@("`@4U1!
M(%DQ("`@("`@("`@.R!/1B!.15A4($Q)3D4-#2`@("`@("`@("`@24Y9("`@
M("`@("`@("`@.T1/($%,3"!03TE.5%,-("`@("`@("`@("!#4%D@4$])3E13
M("`@("`[#2`@("`@("`@("`@0DY%($13,B`@("`@("`@.PT-("`@("`@("`@
M("!,1$$@)$0P,3@@("`@("`[4TA/5R!/55(@5T]22PT@("`@("`@("`@($5/
M4B`C)3`P,#`P,#$P(#L-("`@("`@("`@("!35$$@)$0P,3@@("`@("`[#0T@
M("`@("`@("`@($Q$02`D1#`Q."`@("`@(#M#3$5!4B!42$4-("`@("`@("`@
M("!!3D0@(R4P,#`P,#`Q,"`[($Y%6%0@0E5&1D52#2`@("`@("`@("`@0D51
M($13-"`@("`@("`@.R!&3U(@1%)!5TE.1PT@("`@("`@("`@($I34B!"3$%.
M2S`@("`@(#L@24X-("`@("`@("`@("!*35`@1%,U("`@("`@("`[#413-"`@
M("`@("`@2E-2($),04Y+,2`@("`@.PT-1%,U("`@("`@("!25%,-#41362`@
M("`@("`@+D)95$4@)#`P#3LM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM
M+2TM+2TM+2TM+2T-1T546%D@("`@("!35%D@1UA962`@("`@("`[4%)%4T52
M5D4@+ED-("`@("`@("`@("!35$$@1UA902`@("`@("`[("`@("`@("`@+D$-
M#2`@("`@("`@("`@3$19($=8651(151!("`@.PT@("`@("`@("`@($Q$02!-
M0T]3+%D@("`@(#M!#2`@("`@("`@("`@4T5#("`@("`@("`@("`@.PT@("`@
M("`@("`@(%-"0R!'6%E2041)55,@(#LM0@T@("`@("`@("`@(%1!62`@("`@
M("`@("`@(#L-("`@("`@("`@("!,1$$@35-14BQ9("`@("`[1BA!+4(I#2`@
M("`@("`@("`@4U1!($=8651%35`@("`@.U-43U)%(%)%4U5,5`T-("`@("`@
M("`@("!,1%D@1UA95$A%5$$@("`[#2`@("`@("`@("`@3$1!($U#3U,L62`@
M("`@.T$-("`@("`@("`@("!#3$,@("`@("`@("`@("`[#2`@("`@("`@("`@
M041#($=865)!1$E54R`@.RM"#2`@("`@("`@("`@5$%9("`@("`@("`@("`@
M.PT@("`@("`@("`@($Q$02!-4U%2+%D@("`@(#M&*$$K0BD-("`@("`@("`@
M("!314,@("`@("`@("`@("`[#2`@("`@("`@("`@4T)#($=8651%35`@("`@
M.RU&*$$M0BD-("`@("`@("`@("!35$$@6%!/4R`@("`@("`[/5@@0T]/4D1)
M3D%410T-("`@("`@("`@("!,1%D@1UA95$A%5$$@("`[#2`@("`@("`@("`@
M3$1!($U324XL62`@("`@.T$-("`@("`@("`@("!314,@("`@("`@("`@("`[
M#2`@("`@("`@("`@4T)#($=865)!1$E54R`@.RU"#2`@("`@("`@("`@5$%9
M("`@("`@("`@("`@.PT@("`@("`@("`@($Q$02!-4U%2+%D@("`@(#M&*$$M
M0BD-("`@("`@("`@("!35$$@1UA95$5-4"`@("`[4U1/4D4@4D5354Q4#0T@
M("`@("`@("`@($Q$62!'6%E42$5402`@(#L-("`@("`@("`@("!,1$$@35-)
M3BQ9("`@("`[00T@("`@("`@("`@($-,0R`@("`@("`@("`@(#L-("`@("`@
M("`@("!!1$,@1UA94D%$2553("`[*T(-("`@("`@("`@("!405D@("`@("`@
M("`@("`[#2`@("`@("`@("`@3$1!($U345(L62`@("`@.T8H02M"*0T@("`@
M("`@("`@(%-%0R`@("`@("`@("`@(#L-("`@("`@("`@("!30D,@1UA95$5-
M4"`@("`[+48H02U"*0T@("`@("`@("`@(%-402!94$]3("`@("`@(#L]62!#
M3T]21$E.051%#0T@("`@("`@("`@($Q$62!'6%E9("`@("`@(#M215-43U)%
M("Y9#2`@("`@("`@("`@3$1!($=864$@("`@("`@.U)%4U1/4D4@+D$-#2`@
M("`@("`@("`@4E13#2`@("`@("`@("`@.RTM+2TM+2TM+2TM+2TM+2TM+2TM
M+2TM+2TM+2T-1UA94D%$2553("`N0EE412`D,#`-1UA95$A%5$$@("`N0EE4
M12`D,#`-#5A03U,@("`@("`@+D)95$4@)#`P#5E03U,@("`@("`@+D)95$4@
M)#`P#0U'6%E9("`@("`@("Y"651%("0P,`U'6%E!("`@("`@("Y"651%("0P
M,`U'6%E414U0("`@("Y"651%("0P,`T[+2TM+2TM+2TM+2TM+2TM+2TM+2TM
M+2TM+2TM+2TM+2TM+2TM+2TM#5!,3U0@("`@("`@4$A!("`@("`@("`@("`@
M.U!215-%4E9%("Y!#0T@("`@("`@("`@($Q$02`D1#`Q."`@("`@(#M03$]4
M($E.#2`@("`@("`@("`@04Y$(",E,#`P,#`P,3`@.R!#3U)214-4#2`@("`@
M("`@("`@0DY%(%!,3U0R("`@("`@.R!"549&15(-#5!,3U0Q("`@("`@3$1!
M($Q/0EE412Q8("`@.TQ/($)95$4-("`@("`@("`@("!35$$@)#`R("`@("`@
M("`[#2`@("`@("`@("`@3$1!($A)0EE413$L6"`@.TA)($)95$4-("`@("`@
M("`@("!35$$@)#`S("`@("`@("`[#2`@("`@("`@("`@3$1!("@D,#(I+%D@
M("`@.PT@("`@("`@("`@($]202!"251-05-++%@@(#M455).(%!)6$5,($].
M#2`@("`@("`@("`@4U1!("@D,#(I+%D@("`@.PT-("`@("`@("`@("!03$$@
M("`@("`@("`@("`[4D535$]212`N00T@("`@("`@("`@(%)44PT[+2TM+2TM
M+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM#5!,3U0R("`@("`@
M3$1!($Q/0EE412Q8("`@.TQ/($)95$4-("`@("`@("`@("!35$$@)#`R("`@
M("`@("`[#2`@("`@("`@("`@3$1!($A)0EE413`L6"`@.TA)($)95$4-("`@
M("`@("`@("!35$$@)#`S("`@("`@("`[#2`@("`@("`@("`@3$1!("@D,#(I
M+%D@("`@.PT@("`@("`@("`@($]202!"251-05-++%@@(#M455).(%!)6$5,
M($].#2`@("`@("`@("`@4U1!("@D,#(I+%D@("`@.PT-("`@("`@("`@("!0
M3$$@("`@("`@("`@("`[4D535$]212`N00T@("`@("`@("`@(%)44PT[+2TM
M+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM#41205=,24Y%
M("`@4T5#("`@("`@("`@("`@.T=%5"!$6`T@("`@("`@("`@($Q$02!8,2`@
M("`@("`@(#L-("`@("`@("`@("!30D,@6#(@("`@("`@("`[#2`@("`@("`@
M("`@4U1!($18("`@("`@("`@.PT-("`@("`@("`@("!314,@("`@("`@("`@
M("`[1T54($19#2`@("`@("`@("`@3$1!(%DQ("`@("`@("`@.PT@("`@("`@
M("`@(%-"0R!9,B`@("`@("`@(#L-("`@("`@("`@("!35$$@1%D@("`@("`@
M("`[#0T@("`@("`@("`@($-,0R`@("`@("`@("`@(#L-("`@("`@("`@("!,
M1$$@1%@@("`@("`@("`[#2`@("`@("`@("`@0E!,($1205=,24Y%,B`@.TA!
M3D1,12`M1%@-("`@("`@("`@("!%3U(@(R4Q,3$Q,3$Q,2`[34%+12!$6`T@
M("`@("`@("`@($%$0R`C)3`P,#`P,#`Q(#L@4$]3251)5D4-("`@("`@("`@
M("!35$$@1%@@("`@("`@("`[#0T@("`@("`@("`@($Q$02!$62`@("`@("`@
M(#L-("`@("`@("`@("!"4$P@1%)!5TQ)3D4Q("`[2$%.1$Q%("U$60T@("`@
M("`@("`@($5/4B`C)3$Q,3$Q,3$Q(#M-04M%($19#2`@("`@("`@("`@041#
M(",E,#`P,#`P,#$@.R!03U-)5$E610T@("`@("`@("`@(%-402!$62`@("`@
M("`@(#L-#2`@("`@("`@("`@3$1!($18#2`@("`@("`@("`@0TU0($19#2`@
M("`@("`@("`@0D-3($1,,#`-("`@("`@("`@("!*35`@1$PQ,`T-1%)!5TQ)
M3D4Q("!,1$$@1%@-("`@("`@("`@("!#35`@1%D-("`@("`@("`@("!"0U,@
M1$PR,`T@("`@("`@("`@($I-4"!$3#,P#0U$4D%73$E.13(@($Q$02!$60T@
M("`@("`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7]JJD$A?L]`,#P`JDQ&&D@H`"1_J7ZR4S0!:`#($D/J86%
M_JD&A?^I!!AE_:JI"(7[/0#`\`*I,1AI(*``D?ZE^LE-T`6@`R!)#ZG7A?ZI
M!H7_HA>I`87[+1?`\`*I,1AI(*``D?ZE^LE.T`6@`2!)#ZG:A?ZI!H7_J0*%
M^RT7P/`"J3$8:2"@`)'^I?K)3]`%H`$@20^IW87^J0:%_ZD$A?LM%\#P`JDQ
M&&D@H`"1_J7ZR5#0!:`!($D/J?B%_JD&A?^B&*D0A?LM&,#P`JDQ&&D@H`"1
M_J7ZR5'0!:`'($D/J2"%_JD'A?^I((7[+1C`\`*I,1AI(*``D?ZE^LE2T`6@
M""!)#ZE(A?ZI!X7_J4"%^RT8P/`"J3$8:2"@`)'^I?K)4]`%H`@@20^IF(7^
MJ0>%_Z`*K1?`2DI*2H7[(*8/I?K)5-`5H`@@&`\*"@H*A?NM%\`I#P7[C1?`
MJ<"%_JD'A?^I`(7[K1;`"B;["B;["B;[#17`A?R@!R#9#Z7ZR5706J`&('L/
M(.3_IOW)*]`3K17`&&D!*0>-%<#0/^X6P$P"#\DMT!&N%<#0!0`^B%^VB0`H7\L.V*D?[(HC"E_#CIZ$BE^^D#D`/H
MA?MHD`*%_+#MBI'^R*(OI?PXA?SI9.BP^<;[$/2*D?[(HB^E_#B%_.D*Z+#Y
-BI'^R*7\&&DPD?[(8*(O
`
end
/S07::$d400:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Progenitor of the SID :
An interview with Bob Yannes
by Andreas Varga
This is an interview with the creator of the SID chip, namely Bob
Yannes, who after working for Commodore, co-founded the well-known
synthesizer company Ensoniq. In the latter part of the interview he
gives us a very detailed description of the SID's technology.
The interview was done via e-mail in August 1996 by Andreas Varga.
Some questions came from Linus Walleij.
[A note from your friendly technical editor: There is a little addendum
at the end of this interview, with a few comments to clarify or expand
upon some of the statements in the interview. These comments are
referenced in the interview by a number in square brackets, like this: [3]
These comments are due in large part to a series of very helpful
conversations with Andreas Boose, Marko Makela, Michael Schwendt, and
Andreas Varga. Special thanks to Andreas Boose for explaining how a
phase accumulating oscillator works :).
-TechEd]
--
> Did you foresee that people would actually treat your little
> VLSI-chip like an instrument?
Actually, I was an electronic music hobbyist before I started
working for MOS Technology (one of Commodore's chip divisions at the
time) and before I knew anything at all about VLSI chip design. One of
the reasons I was hired was my knowledge of music synthesis was deemed
valuable for future MOS/Commodore products. When I designed the SID
chip, I was attempting to create a single-chip synthesizer voice which
hopefully would find it's way into polyphonic/polytimbral
synthesizers.
> Are you aware of the existence of programs like SIDPLAY,
> PlaySID,... which emulate the SID chip up to the smallest click ?
I only recently became aware of them (through your website).
I'm afraid I haven't thought much about SID in the last 15 years...I
am constantly amazed and gratified at the number of people who have
been positively affected by the SID chip and the Commodore 64 (which I
also designed) and who continue to do productive things with them
despite their "obsolescence".
> Have you heard the tunes by Rob Hubbard, Martin Galway, Tim
> Follin, Jeroen Tel, and all the other composers ?
I'm afraid not, are recordings available in the US?
> Did you believe this was possible to do with your chip?
Since I haven't heard them I'm not sure what we are talking
about, however, I did design the SID chip with enough resolution to
produce high-quality music. I was never able to refine the
Signal-to-noise ratio to the level I wanted, though.
> How much of the architecture in the SID inspired you when
> working with the Ensoniq synthesizers?
The SID chip was my first attempt at a phase-accumulating
oscillator, which is the heart of all wavetable synthesis systems.
Due to time constraints, the oscillators in SID were not multiplexed,
therefore they took up a lot of chip area, constraining the number of
voices I could fit on a chip. All ENSONIQ sound chips use a
multiplexed oscillator which allows us to produce at least 32 voices
per chip. Aside from that, little else of SID is to be found in our
designs, which more closely resemble the Mountain Computer sound card
for the Apple II (the basis of the Alpha Syntauri system). The DOC I
chip (used in the Mirage and ESQ-1) was modeled on this sound card.
Our current designs, which include waveform interpolation, digital
filters and digital effects are new designs that aren't really based
on anything other than our imaginations.
> How big impact do you think the SID had on the synthesizer
> industry?
Well, I don't think it had much impact on the synthesizer
industry. I remember once at Commodore that Sequential Circuits was
interested in buying the chip, but nothing ever came of it. My
intention in designing the chip (since MOS Technology was a merchant
semiconductor house at the time and sold chips to the outside world)
was to be able to sell the SID chip to synthesizer manufacturers. SID
chip production was completely consumed by the Commodore 64 and by the
time chips were readily available, I had left Commodore and never had
the opportunity to improve the fidelity of the chip.
> What would you have changed in the SIDs design, if you had a
> bigger budget from Commodore ?
The issue wasn't budget, it was development time and chip size
constraints. The design/prototype/debug/production schedule of the SID
chip, VIC II chip and Commodore 64 were incredibly tight (some would
say impossibly tight)--we did things faster than Commodore had ever
done before and were never able to repeat after! If I had had more
time, I would have developed a proper MOS op-amp which would have
eliminated the signal leakage which occurred when the volume of the
voice was supposed to be zero. This lead to poor signal-to-noise
ratio, although it could be dealt with by stopping the oscillator. It
would also have greatly improved the filter, particularly in achieving
high resonance. I originally planned to have an exponential look-up
table to provide a direct translation for the equal-tempered scale,
but it took up too much silicon and it was easy enough to do in
software anyway.
> The SID is very complex for its time. Why didn't you settle
> with an easier design ?
I thought the sound chips on the market (including those in
the Atari computers) were primitive and obviously had been designed
by people who knew nothing about music. As I said previously, I was
attempting to create a synthesizer chip which could be used in
professional synthesizers.
> Do you still own a C64 (or another SID-equipped computer) ?
Sure, I have a couple of them (including the portable), but I
honestly haven't turned them on in years.
> Did Commodore ever plan to build an improved successor to the SID?
I don't know. After I left I don't think there was anyone
there who knew enough about music synthesis to do much more than
improve the yield of the SID chip. I would have liked to have improved
the SID chip before we had to release to production, but I doubt it
would have made any difference to the success of the Commodore 64.
> Can you give us a short overview of the SIDs internal architecture ?
It's pretty brute-force, I didn't have time to be elegant.
Each "voice" consisted of an Oscillator, a Waveform Generator, a
Waveform Selector, a Waveform D/A converter, a Multiplying D/A
converter for amplitude control and an Envelope Generator for
modulation. The analog output of each voice could be sent through a
Multimode Analog Filter or bypass the filter and a final Multiplying
D/A converter provided overall manual volume control.
As I recall, the Oscillator is a 24-bit phase-accumulating design of
which the lower 16-bits are programmable for pitch control. [1] The output
of the accumulator goes directly to a D/A converter through a waveform
selector. Normally, the output of a phase-accumulating oscillator
would be used as an address into memory which contained a wavetable,
but SID had to be entirely self-contained and there was no room at all
for a wavetable on the chip.
The Sawtooth waveform was created by sending the upper 12-bits of the
accumulator to the 12-bit Waveform D/A.
The Triangle waveform was created by using the MSB of the accumulator
to invert the remaining upper 11 accumulator bits using EXOR gates.
These 11 bits were then left-shifted (throwing away the MSB) and sent
to the Waveform D/A (so the resolution of the triangle waveform was
half that of the sawtooth, but the amplitude and frequency were the
same).
The Pulse waveform was created by sending the upper 12-bits of the
accumulator to a 12-bit digital comparator. The output of the
comparator was either a one or a zero. This single output was then
sent to all 12 bits of the Waveform D/A.
The Noise waveform was created using a 23-bit pseudo-random sequence
generator (i.e., a shift register with specific outputs fed back to
the input through combinatorial logic). [2] The shift register was clocked
by one of the intermediate bits of the accumulator to keep the
frequency content of the noise waveform relatively the same as the
pitched waveforms. The upper 12-bits of the shift register were sent
to the Waveform D/A.
Since all of the waveforms were just digital bits, the Waveform
Selector consisted of multiplexers that selected which waveform bits
would be sent to the Waveform D/A. The multiplexers were single
transistors and did not provide a "lock-out", allowing combinations of
the waveforms to be selected. The combination was actually a logical
ANDing of the bits of each waveform, which produced unpredictable
results, so I didn't encourage this, especially since it could lock up
the pseudo-random sequence generator by filling it with zeroes. [3]
[Actually, the result isn't a logical ANDing at all. -TechEd]
The output of the Waveform D/A (which was an analog voltage at this
point) was fed into the reference input of an 8-bit multiplying D/A,
creating a DCA (digitally-controlled-amplifier). The digital control
word which modulated the amplitude of the waveform came from the
Envelope Generator.
The Envelope Generator was simply an 8-bit up/down counter which, when
triggered by the Gate bit, counted from 0 to 255 at the Attack rate,
from 255 down to the programmed Sustain value at the Decay rate,
remained at the Sustain value until the Gate bit was cleared then
counted down from the Sustain value to 0 at the Release rate.
A programmable frequency divider was used to set the various rates
(unfortunately I don't remember how many bits the divider was,
either 12 or 16 bits). A small look-up table translated the 16
register-programmable values to the appropriate number to load into
the frequency divider. Depending on what state the Envelope Generator
was in (i.e. ADS or R), the appropriate register would be selected and
that number would be translated and loaded into the divider. Obviously
it would have been better to have individual bit control of the
divider which would have provided great resolution for each rate,
however I did not have enough silicon area for a lot of register bits.
Using this approach, I was able to cram a wide range of rates into 4
bits, allowing the ADSR to be defined in two bytes instead of eight.
The actual numbers in the look-up table were arrived at subjectively
by setting up typical patches on a Sequential Circuits Pro-1 and
measuring the envelope times by ear (which is why the available rates
seem strange)!
In order to more closely model the exponential decay of sounds,
another look-up table on the output of the Envelope Generator would
sequentially divide the clock to the Envelope Generator by two at
specific counts in the Decay and Release cycles. This created a
piece-wise linear approximation of an exponential. I was particularly
happy how well this worked considering the simplicity of the
circuitry. The Attack, however, was linear, but this sounded fine.
A digital comparator was used for the Sustain function. The upper four
bits of the Up/Down counter were compared to the programmed Sustain
value and would stop the clock to the Envelope Generator when the
counter counted down to the Sustain value. This created 16 linearly
spaced sustain levels without havingto go through a look-up table
translation between the 4-bit register value and the 8-bit Envelope
Generator output. It also meant that sustain levels were adjustable in
steps of 16. Again, more register bits would have provided higher
resolution.
When the Gate bit was cleared, the clock would again be enabled,
allowing the counter to count down to zero. Like an analog envelope
generator, the SID Envelope Generator would track the Sustain level if
it was changed to a lower value during the Sustain portion of the
envelope, however, it would not count UP if the Sustain level were set
higher.
The 8-bit output of the Envelope Generator was then sent to the
Multiplying D/A converter to modulate the amplitude of the selected
Oscillator Waveform (to be technically accurate, actually the waveform
was modulating the output of the Envelope Generator, but the result is
the same).
Hard Sync was accomplished by clearing the accumulator of an
Oscillator based on the accumulator MSB of the previous oscillator. [4]
Ring Modulation was accomplished by substituting the accumulator MSB
of an oscillator in the EXOR function of the triangle waveform
generator with the accumulator MSB of the previous oscillator. [5]
That is why the triangle waveform must be selected to use Ring Modulation.
The Filter was a classic multi-mode (state variable) VCF design. There
was no way to create a variable transconductance amplifier in our NMOS
process, so I simply used FETs as voltage-controlled resistors to
control the cutoff frequency. An 11-bit D/A converter generates the
control voltage for the FETs (it's actually a 12-bit D/A, but the LSB
had no audible affect so I disconnected it!).
Filter resonance was controlled by a 4-bit weighted resistor ladder.
Each bit would turn on one of the weighted resistors and allow a
portion of the output to feed back to the input. The state-variable
design provided simultaneous low-pass, band-pass and high-pass
outputs. Analog switches selected which combination of outputs were
sent to the final amplifier (a notch filter was created by enabling
both the high and low-pass outputs simultaneously).
The filter is the worst part of SID because I could not create
high-gain op-amps in NMOS, which were essential to a resonant filter.
In addition, the resistance of the FETs varied considerably with
processing, so different lots of SID chips had different cutoff
frequency characteristics. I knew it wouldn't work very well, but it
was better than nothing and I didn't have time to make it better.
Analog switches were also used to either route an Oscillator output
through or around the filter to the final amplifier. The final amp was
a 4-bit multiplying D/A converter which allowed the volume of the
output signal to be controlled. By stopping an Oscillator, it was
possible to apply a DC voltage to this D/A. Audio could then be
created by having the microprocessor write the Final Volume register
in real-time. Game programs often used this method to synthesize
speech or play "sampled" sounds.
An external audio input could also be mixed in at the final amp or
processed through the filter.
The Modulation registers were probably never used since they could
easily be simulated in software without having to give up a voice. For
novice programmers they provided a way to create vibrato or filter
sweeps without having to write much code (just read the value from the
modulation register and write it back to the frequency register).
These registers just give microprocessor access to the upper 8 bits of
the instantaneous value of the waveform and envelope of Voice 3. Since
you probably wouldn't want to hear the modulation source in the audio
output, an analog switch was provided to turn off the audio output of
Voice 3.
> Any other interesting tidbits or anecdotes ?
The funniest thing I remember was getting in a whole bunch of
C-64 video games which had been written in Japan. The Japanese are so
obsessed with technical specifications that they had written their
code according to a SID spec. sheet (which I had written before SID
prototypes even existed). Needless to say, the specs were not
accurate. Rather than correct the obvious errors in their code, they
produced games with out of tune sounds and filter settings that
produced only quiet, muffled sound at the output. As far as they were
concerned, it didn't matter that their code sounded all wrong, they
had written their code correctly according to the spec. and that was
all that mattered!
--
For questions or comments, Mr. Andreas Varga may be reached through his SID
Homepage on the World Wide Web at - http://stud1.tuwien.ac.at/~e9426444/
Addendum by S. Judd, Technical Editor
------+-----+----------+-----+-------
References / suggested reading:
"Design case history: the Commodore 64", Tekal S. Perry and Paul Wallich,
IEEE Specturm, March 1985
"Programming the Commodore 64", Raeto Colin West, Compute Publications.
"Mapping the Commodore 128", Otis Cowper, Compute Publications.
The SID Homepage, maintained by Andreas Varga:
http://stud1.tuwien.ac.at/~e9426444/
"SID Primer: The Working Man's Guide to SID"
by Stephen L. Judd, disC=overy issue 2 (Yep, this issue!)
"Mapping the Commodore 64", Sheldon Leemon, Compute Publications.
"Commodore 64/128 Programmer's Reference Guide", CBM.
The first article makes for very interesting reading and should be available
at most public libraries. The second and third references have more detailed
and accurate explanations of SID and the theory behind its general features,
as well as actual implementation. The SID homepage has lots of technical and
general information. The disC=overy article attempts to provide a general
overview of the chip. The last two are included as good references for
information on programming SID, especially since they are easy to acquire.
The program included with the disC=overy article (wave3) is useful for
investigating the SID. By selecting voice 3, and using a low freq. (e.g. a
frequency setting of 1 or 2 say) the output of the waveform generator may be
seen visually. Ring Modulation, Synchronization, and multiple waveform
selection may all be investigated in this manner.
Notes:
[1] In the words of Andreas Boose:
"The phase accumulating oscillator is just a 24-bit accumulator
which is increased by the 16-bit value of the frequency register
every phi2 cycle. And like Bob said, the upper 12 bits of this
accumulator are sent to the waveform generators.
Note that although he uses 12 bit, the resulting *resolution* of
this signal is only 12 bit on lower frequencies, if the frequency
register is smaller than 4096. On higher frequencies the resolution
drops down to nearly 8-bit when the frequency register is at its
max value (65535)."
It should now be clear why all of SID's waveforms are linear in
nature (i.e. composed of straight lines): instead of using this
counter as an index into a wave table, only the counter itself
is used in generating the waveforms (and counting up is an awfully
linear process). On the other hand, this raises the intriguing
possibility of modulating the waveform via rapid changes in the
frequency register.
[2] Asger Alstrup Nielsen has done a good deal of research into SID's
random number generator for generating the noise waveform. I am
told that the algorithm was implemented by Michael Schwendt in
SIDplay and the result was not too accurate. For more information,
visit the SID home page, in the references above.
[3] From the IEEE article referenced above:
The precise capabilities of the sound chip are not clear even
today, largely because of incorrect specifications having been written
when the chip was first designed. "The spec. sheet got distributed
and copied and rewritten by various people until it made practically
no sense anymore," said Yannes. An example of the faulty documentation
is the claim that the chip can logically AND several waveforms. ...
"There is no interlock to make sure that if one bit is on, the others
are off," Yannes said. "That would have taken too much silicon."
So if more than one waveform is selected, the internal nodes of the
output multiplexer are discharged, and what emerges is the minimum
of amplitudes."
The meaning of that last statement is unclear, as the result
is certainly not the minimum of the waveform values either. A
very simple way to see what the result looks like is to use the "wave3"
program in the other disC=overy article with voice 3. To test the
logical ANDing hypothesis, "freeze" the voice 3 pulse waveform
output at $FF by selecting pulse and a nonzero pulse width. Select
a very low note frequency, 1 or 2 say. When the waveform output
becomes $FF set the pulse width to zero: the pulse output is now
stuck at $FF. Select another waveform, such as sawtooth, and watch
(and listen to) the result! (To hear the result, make sure the sustain
level is set (to 15 say) and that the gate bit is set as well). About
the only thing that can be said about multiple waveforms is that they
are periodic with the expected frequency.
In short, nobody really knows what the result is when multiple
waveforms are selected!
[4] It should be clear that synchronization generates a new waveform at
a fundamental frequency related to the preceding voice. Moreover,
resetting the accumulator to zero will in general introduce
a discontinuity into the waveform. Discontinuities will always
amplify the presence of high frequencies, as can be seen by
taking the Fourier transform of a discontinuous function. Compare
for instance the triangle waveform, whose mode amplitudes decay
as 1/k^2, and the sawtooth waveform, whose mode amplitudes decay
as 1/k, where k is the wave number. High frequencies are needed to
make sharp transitions.
Try synchronizing a triangle waveform -- if the synchronization
frequencies are very different, the result will unsurprisingly sound
like a sawtooth. The higher frequencies are easy to hear; sometimes
even the fundamental pitch of the note will change significantly.
[5] Ring Modulation. Most books, not to mention the other SID article
elsewhere in this issue of disC=overy, will explain ring modulation
as a multiplication of two waveforms, which generates sum and
difference frequencies. Simply put, if one signal is cos(w1*t)
and another signal is cos(w2*t), then the ring modulated output is:
cos(w1*t) * cos(w2*t) = 1/2 (cos((w1+w2)*t) + cos((w1-w2)*t) )
Voila! Two new waves, with frequencies which are the sum and difference
of the two frequencies. Note that if the two frequencies differ only
slightly, very noticable beats will result.
SID works a little differently. What it does not do is to multiply
any waveforms. What it does do is generate a new waveform, somewhat
related to the original waveform, which contains all the sum and
difference frequencies.
Recall that the triangle waveform may be written essentially as:
f(x) = { x, MSB=0 i.e. 0 < x <= max/2
{ max-x, MSB=1 i.e. max/2 < x < max
where max is the maximum value of the accumulator, 2^24. f(x) then
counts upwards on one half of the cycle and downwards on the other
half.
Ring modulation uses the MSB of the preceeding voice to evaluate
the function above. The normal triangle waveform is continuous,
since when x=max/2 the two pieces of the function have the same
value. If MSB is suddenly changed, however, the function, which
was couting upwards, might suddenly change values significantly
and start counting downwards. It is pretty simple to sketch out
the result on a piece of paper. Consider the following:
V3: At some frequency a little higher than V1 (waveform doesn't matter)
V1: A triangle wave at some base frequency, modulated by V3.
Modulated output of V1:
------------*-------*[--------------------------------- maximum value
[* * [
[ * * [
* [ * [ [
* [ [ * [ [ * etc.
* [ [ * [ *
* [ [ [ *
* * [ [ *
* * [ [ *
* * [ [ *
*----------*[--------[*-------------------------------- minimum value
^ ^ ^ ^
[ [ [ [
[ [ [ Curve hits FF and wraps around to 00
[ [ [
[ [ V3 completes a cycle; MSB is cleared; V1 wave counts up again
[ [
[ Curve hits FF and wraps around to 00; MSB is high so result
[ is 255-value (i.e. counting downwards)
[
V3 hits midway point in cycle; MSB is now high; V1 goes from t
to 255-t, goes downwards.
Well it's not really 0..255, but the meaning should be clear. :)
There are now two important features: first, a number of
discontinuities have been suddenly introduced, which tends
to amplify higher frequencies. The second is that the
frequency of the resulting waveform is quite different than
that of the pure triangle. What is the frequency? To put it
another way, what is the period: how long must one wait before
the waveform repeats itself?
In terms of SID, let both of the accumulators start at zero, and let
one count up faster than the other. The period of a given voice is
the amount of time it takes for its counter to return to zero. At
some point both counters will return to zero, and of course the
modulated wave will then repeat. This then gives the period of the
modulated waveform.
Let one wave have period T1 (frequency w1) and the other have period T3
(and frequency w3). When m*T1 = n*T3, for some integers m and n, the
wave will repeat. That is, perhaps after ten repetitions of wave 1 and
three repetitions of wave 3 the waves will both be at zero again. The
resulting wave will then have frequencies w=(p*w1 + q*w3) for integer
p,q. To see this, consider a wave like:
f(t) = e^i 2*pi (p*w1 + q*w3) t, where w1=1/T1, w3=1/T3
let t = T = m*T1 = n*T3, then
f(T) = e^i 2*pi (p*m + q*n) = f(2*pi) = f(0)
Thus, such a wave has period T (although not necessarily least
period T), for *any* p,q integer. This then implies that the resulting
waveform contains all of the sum and difference frequencies, e.g.
w1-w3, w1+w3, 2*w1+w3, etc.
Q.E.D.
In summary, SID's ring modulation produces a new waveform containing
sum and difference frequencies of the modulating waveforms, with
a strong high frequency content due to the discontinuities in the
resulting modulated waveform.
Note that by using ring modulation (not to mention sync) frequencies
much much higher than than the upper frequency limit (~4000 Hz) of the
frequency register may be generated.
/S08::0100h:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
--- Z80, The basics of it ---
by Raver/Phantasy
------------------------------------------------------------------------------
Introduction
------------------------------------------------------------------------------
This article is a brief overview of the Z80 CPU processor. Made by the people
at the American company ZILOG. It was and still is a very popular CPU. Used
in many machines, from the early Cromenco's to the later Kaypro's and C128's,
in 1996 it is a prime workhorse in many microcontroller operations.
The Z80 first saw action in a Commodore computer with the introduction of
the CP/M cartridge for the C64. Later, CBM introduced the C128 home computer,
which has a built in Z80. Both Z80 implementations are accurately regarded
as half-done, limiting the processor in many ways. Focusing on the short-
comings however, would be the topic of another article. Instead, I will
concentrate here on the Z80 itself rather than on how it interacts with
any given specific Commodore system or operating system protocol. I hope
this will be of sufficient value for further exploration on your particular
system configuration.
------------------------------------------------------------------------------
The Z80 Registers.
------------------------------------------------------------------------------
AF - can be only used as two 8bit registers, but push on stack and change to
alternative always both. "A" is 8bit accumulator, very useful register. Most
of operations can be done with "A". "F" is flag register. There are "C", "Z",
"P", "V" and "S" flags.
BC - 16bit register, can be used as two 8bit registers "B" and "C". It's
usually used as "back counter".
DE - 16bit register, can be used as two 8bit registers "D" and "E". It's
usually used as "destination index", as register, who points to address of
destination.
HL - 16bit register, can be used as two 8bit registers "H" and "L". It's
very special register, there are lots of commands available only for this
register. It's sometimes called "16bit accumulator".
IX - 16bit register. It can be used as two 8bit registers "XL" and "XH" too,
but it's undocumented feature. That register have one very useful addressing
mode, but arn't widely used, cause it's slow (14-23 cycles).
IY - the same as "IX". The difference is two 8bit registers - "YL" and "YH"
for this one.
SP - 16bit register. "Stack pointer", points to memory location, used as start
of stack. Stack can be pointed to every memory location (#0000 - #FFFF).
I - 8bit register, which points to interrupt.
R - 8bit register for memory regenerating.
PC - 16bit register, "program counter", what points to address, where are next
executing command.
! Z80 has two independent sets of registers: "AF", "BC", "DE", "HL". They can
be changed by EXX registers "BC", "DE", "HL" to "BC'", "DE'", "HL'" and by
EX AF, AF' register "AF" to "AF'". Values of other register set will be saved.
Processor don't know, with which one of two sets it works now.
-------------------------------------------------------------------------------
Commands: What moves numbers in registers and memory?
-------------------------------------------------------------------------------
LD A,#04 - moves 4 into register "A"
LD HL,#4000 - moves 16384 into register "HL"
LD (#C000),A - moves value of register "A" into memory location 49152
LD (HL),B - moves value of register "B" into memory location pointed by "HL"
LD A,(HL) - moves value, which is held in memory location pointed by "HL",
into register "A"
LD (IY+#03),A - moves value of register "A" into memory location, pointed by
register "IY" +3. This addressing mode is only for "IX" and "IY".
-------------------------------------------------------------------------------
Commands: What moves blocks of bytes?
-------------------------------------------------------------------------------
LDIR - very cool command, moves block of bytes pointed by "HL" to memory
location pointed by "DE". The lenght of block is in "BC".
Example:
LD HL,SOURCE
LD DE,DESTINATION
LD BC,LENGHT
LDIR
It's fully automatic, but you can do it manualy by replacing LDIR with a
lots of LDI - it's much faster! There is another block command LDDR, the
difference is: LDIR moves blocks from start to end, LDDR moves them from end
to start.
Also, there are commands for searching block of bytes in memory and commands
to put in port block of bytes and take from port block of bytes.
-------------------------------------------------------------------------------
The Stack.
-------------------------------------------------------------------------------
Stack is very useful on Z80. It's pointed by register "SP" and can be located
anywhere you want, because "SP" is a 16bit reg! (Note : In the 65xx series
CPU, the SP (Stack Pointer) is merely an 8bit offset of page 1 ($01xx). This
is why the 65xx stack is limited to page 1).
Stack is used for commands like CALL, it pushes on stack return address, which
is later used by an RET. The stack can be used as a very fast block-byte mover
and buffer refresher, for example.
Commands for stack using are PUSH and POP. PUSH puts 16bit value of registers
on stack and POP pops 16bit value from stack. Remember, the stack can be of
any 16bit (0-65535) size and placed anywhere.
-------------------------------------------------------------------------------
Interrupts.
-------------------------------------------------------------------------------
Z80 has two interrupt modes - NMI and INT. NMI is a non-maskable interrupt
and INT is maskable. NMI defines the main hardware interrupts and generally,
they can not be used by coder. Fortunately, INT can be used by coder and
register I holds value of interrupt vector. There is IM0, IM1 and IM2 mode of
INT. Rather use have IM2 mode. Command to return from intrrupt routine on Z80
is RETI.
-------------------------------------------------------------------------------
Port control.
-------------------------------------------------------------------------------
The commands to control port are: OUT and IN. OUT writes value to port, but IN
reads value from it. All controling of music processors, disk controller and
RAM pages swithching is done by OUT. But some, for example to check, if key is
pressed, you must use command IN. There can be following combinations of IN:
LD A,high value of port address
IN A,(low value of port address)
or
LD BC,full 16bit port address
IN A,(C)
and for OUT:
LD A,value to send to port
LD C,high value of port address
OUT (low value of port address),A
or
LD A,value to send to port
LD BC,full 16bit port adress
OUT (C),A
There is more to the Z80 of course (Flags, etc.), but this should get you
started. Worthy texts on Z80 ML include works by Rodnay Zaks or Kathe
Spracklen (co-author of Sargon chess). These and a bit of hard gumption
will yield great rewards with Z80, as with any human endeavour persued
at length. :)
Raver
--
For questions or comments on this article, Raver may be reached at the
following internet address : raver@10mb.com
:::::::::::d:i:s:C=:o:v:e:r:y:::::::::::::::::i:s:s:u:e::2::::::::::::::::::::
\H01::::::::::::::::::::::::::H:A:R:D:W:A:R:E:::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Charger up!
The VIC-20 to ATARI 2600 'Ram Cartridge' Programmer
-----+-------+----------+----------+-------+-----
by Ravid Noam (nravid@newton.bgu.ac.il)
A while back, I was searching the internet and found several hundred ROM
images for the Atari 2600 video computer system. I also found a couple of
ways to transfer the images to the 2600, but none used a Commodore computer
as a host. Seeing that my own VIC-20 was equipped with sufficient hardware
to become a host, I set about the task of devising a VIC-20 --> Atari 2600
programming interface. This article includes the instructions on how to
build it. Be warned that most of the wiring is in schematics (.gif format-
-two of the .uue's at the end of this article) so you do need to have the
ability to read and carry out a schematic. In this text, I will attempt
to outline some of the more salient points required to build the interface
and thereby ease the process. As with all hardware projects, you undertake
this at your own risk. Neither myself nor the staff of disC=overy is
responsible for any use or misuse of the information presented in this
article.
--
What you need to own:
- Atari 2600 video game.
- Commodore Vic20 plus ram expansion of 8k or more. If you don't have 8k
expansion, read the notes about the basic program included in this
document.
- Commodore 1540/1541/1571 disk drive, or other model compatible with the
Vic20. A tape drive can be used instead, but you have to change the device
numb. from 8 to 1 in the basic program running on the Vic. The "8" appears
three times in the program.
What you have to build:
RAM CARTRIDGE
-------------
It's like a regular 2600 cartridge, but with the rom chip replaced by
a 32k cmos ram chip, plus backup battery and some additional parts.
The ram cart is plugged directly to the atari like a real cartridge.
To load games to the ram, the cart has to be plugged to the main
circuit. The ram cart can hold up to 16 games of 2k or 8 games of 4k
length.
Components description:
- U1 : ...62..256... - the name isn't important. Has to be a 32k by 8bit
static ram memory device, with access time lower than 200 nano-seconds
and low-power data retention ability, i.e. ability to remember the
data when the operating voltage is falling to 1.5V or lower. Most
CMOS chips have these capabilities. It has to come in the standard
28 pin dual-in-line package.
32k static ram pinout diagram:
________
A14 -|1 28|- Vcc Vcc - operating voltage +5V,
A12 -|2 27|- R/W or 1.5V in sdandby mode.
A7 -|3 26|- A13 _
A6 -|4 25|- A8 R/W - read/write select
A5 -|5 24|- A9 0 - write , 1- read
A4 -|6 23|- A11 __
A3 -|7 22|- OE OE - Output Enable, active low
A2 -|8 21|- A10 __
A1 -|9 20|- CS CS - Chip Select, active low
A0 -|10 19|- D7
D0 -|11 18|- D6 A0..A14 - adrress lines
D1 -|12 17|- D5
D2 -|13 16|- D4 D0..D7 - data lines
ground -|14 15|- D3
-------- ground - common ground
- U2 : CMOS 4011 - quad two-input nand gate, 14 pin IC.
In this circuit and in the main circuit, it can be replaced by a CMOS
hex inverter or by NPN transistor + 2 resistors -- implementation for
each inverter. I used 4011 because I have many of this kind.
- Q1 : 2N2222. Can be replaced by any silicon NPN small signal
transistor with these ratings :
Vce(max) > 10V , Ic(max) > 30mA , Hfe(min) > 100 .
- D1 : 1N4001. Can be replaced by any similar rectifier diode.
- D2 : 1N4148 , or similar.
- C1 : 100 micro-farad , 10V, electrolithic capacitor.
- R1 : 22 kilo-ohm resistor .
- R2 : 10 kilo-ohm resistor .
- R3 : 500 kilo-ohm resistor .
- R4 : 50 kilo-ohm resistor .
All resistors are small power resistors. 0.125 Watt type should be big
enough.
- BAT1 : 3.6V Nickel-Cadmium rechargable battery. The same as the CMOS-RAM
backup battery inside the IBM-PCs. It can be soldered into a printed
circuit.
- S1...S5 : two-position switch.
- PCB edge connector : The ram cartridge has to be plugged to the Atari like
a regular cartridge, so it must end with double-side printed circuit
edge connector, with 24 contacts, 12 on each side, and with the same size
as of a regular cartridge edge connector.
The Connector can be an old atari cartridge as the PCB connector. Just
remove the rom chip and connect the old cart to the rest of the ram
cartridge circuit by wires. Using one or two flat-cables instead of 24
seperate wires will give a nicer look.
Another option is that the connector and the rest of the cartridge can
be on the same printed circuit. I know There are EPROM cartridges made
for the Atari2600, where instead of the rom they have socket for eprom
chip, plus the 4011 chip. The whole ram-cartridge can be built on this
platform, saving a lot of wiring work.
- >> Important notes << -
1. When using one of these options, remember to disconnect the ground
(contact 13) from the signal ground (contact 12), as the latter one
is the read/write control.
2. It is strongly advised that the ram cart is made in a way obtaining
only one possible way to plug in the cartridge, Otherwise, every time
you plug it to the atary or to the main circuit, you have to be
carefull not to plug it the wrong way, i.e. upside down - this can
cause permanent damage.
Edge-connector diagram :
(looking at the edge connectors of an atari cartridge, when the cartridge's
big label is up)
D3 D4 D5 D6 D7 A11 A10 A12 A9 A8 +5V SGND up side
1 2 3 4 5 6 7 8 9 10 11 12
----------------------------------------------------------- printed circuit
13 14 15 16 17 18 19 20 21 22 23 24
GND D2 D1 D0 A0 A1 A2 A3 A4 A5 A6 A7 down side
Functional description:
(you don't have to read this if the schematic is clear to you)
- CS inverter: the nand gate in the lower-right corner - invert the
active-high chip select signal from the atari to the standard low-active
signal used on memory chips.
- chip select protection: R3,R4,Q1 - lock the ram when the power is down, ie.
when Atari is off. R1 and the CS inverter also contribute to this task.
- R/W inverter: the upper nand gate. Like with the chip select, converts
active-high to active-low.
- back-up section : the battery BAT1 feeds the ram and the 4011 when the
external 5V is down. R2 recharges the battery when power is up, and pass on
the stand-by current from the battery when power is down. D2 and C1 improves
the power supply in transition times.
- s3,s4 and s5 : select one of the eight 4k blocks avilable.
- s1: 4k-mode / 2k-mode selection.
- s2: in 2k-mode - select which one of the 2k-blocks is used.
Notes:
Build the cart in a way you can hold it in your hands without touching the
metal parts. Shorting something with your fingers can lead to data lost.
If the circuit seems too complicated, there are some ways to simplify it:
- The rechargable battery. Can be replaced by a cheaper non-rechargable
battery, and the resistor R2 has to be removed, to prevent charging.
Remember that the 4011 chip must receive minimum 3V operating voltage, and
plus the voltage drop over D2, we get minimum voltage of 3.6 that the
battery must supply. Battery that consists of three 1.5V (=4.5) cells is
applicable, but isn't a common thing. In theory, a 3.0V or even 1.5V battery
can be used, since most of the cmos ram chips can retain their data under
1.5, 1.0 or even 0.7V stand-by operating voltage. If the problem is with the
4011, it can be replaced. Each one of the two gates used in this circuit
can be replaced by a NPN transistor and two resistors, and this combination
should function under 1.0V or even 0.8V .
- The chip select protection circuit: Q1, R3 and R4. Before the 3.6V battery,
there was 2.4V battery. After some months, the cartridge became forgetful.
Then I added these parts, but the problem didn't get solved. Only when the
battery was replaced by the 3.6V one, the ram cart returned to function
properly. It's probably the 4011 which decided to demand the 3.0V.
Now, R3,R4 and Q1 seem useless, but I have decided not to remove them,
because the data retention issue is too sensitive from being economized.
If you want to check this, remove them and see if the ram cart still
function. The CS pin of the ram has then to be connected directly to the
output of the nand gate.
- s3,s4 and s5 : If you use standard pin-compatible 8k ram chip instead of
the 32k ram, you don't need s3 and s4. But then the cartridge can hold only
two 4k atari games or four 2k games. s5 can be replaced by shorting A12 of
the ram to ground or to +5V, but then the amount of data that can be stored
on the chip is divided by two.
- s1,s2 : After selecting the 4k bank by s3..s5, s1 is used to select between
two options: one 4k game or two 2k games. In 2k mode, s2 selects between the
two 2k banks. s1 and s2 can be omitted if you load the 2k games as 4k games-
you load a 4k file which it's last 2k half is a copy of the first 2k half.
In this case, the A11 pin of the ram should be connected directly to the A11
incoming signal from the atari.
THE MAIN CIRCUIT
----------------
The task of the main circuit is to load games into the ram cartridge. Also,
it can read to save the content of a real cartridge. The circuit is connected
to the Vic20's user port.
[Ed. Note : Assuming the VIC-20's user port is similar to the C64's user port,
then my guess is that this portion of the project could be adapted to the
C-64 with some minor hardware and software revisions. Any takers? ]
Components description:
- U1,U2,U3 : CMOS 4094 - shift register, 16 pin IC.
- U4 : TTL 74LS165/74HCT165/74LSHCT165 - shift register, 16 pin IC.
- U5 : CMOS 4011 - quad two-input nand gate, 14 pin IC.
- Q2,Q4 : 2N2222. Can be replaced by any silicon NPN small signal
transistor with these ratings :
Vce(max) > 10V , Ic(max) > 30mA , Hfe(min) > 100 .
- Q1 : 2N2907. Can be replaced by any silicon PNP small signal
transistor with the ratings of Q2 and Q4.
- Q3 : 2N2905. Can be replaced by any silicon PNP transistor, with
these ratings :
Vce(max) > 10V , Ic(max) > 300mA , Hfe(min) > 50 ,
metal package (TO-3,TO-5 etc).
- LED : any common small (2mm size) visible LED. The LED and its
resistor R9 are optional.
- R1,R2,R3,R6,R8 : 22 kilo-ohm resistor .
- R4,R7 : 1 kilo-ohm resistor.
- R5 : 220 kilo-ohm resistor.
- R9 : 5 kilo-ohm resistor.
All resistors are small power resistors. 0.125 Watt type should be big
enough.
- Vic20 User Port interface : The user port in the Vic20 is a double-side
printed circuit edge connector, with 24 contacts, 12 on each side. The
interface is a female connector in the same size which can be plagged on
it, and contacted to the main board by 8 wires.
Be careful not to plug the interface to the Vic20 the wrong way,
i.e. replacing the top side with the bottom side. Such a mistake can
damage the VIA-6522 on your Vic20 or some parts in the external circuit.
Write "top" on the top side of the female connector or, if you have time,
you can shape two little plastic parts and insert them in the female
connector, against the two a-symetric slots in the user-port edge
connector. This will prevent you from doing such a dangerous mistake.
- Atari2600 cartridge interface : exactly like the one in the Atari - a
female PCB connector with 24 contacts, 12 on each side. like in the case
of the VIC's user port, it is recomended to ensure that there is only one
way to plug in the ram cartridge or the regular atari2600 cartridge.
The easiest way to obtain this interface is to take it out of old Atari
video game cart. Then the interface can include its plastic housing which
eliminates the possibility to insert a cartridge the wrong way. You can use
the entire case of the atari cart. to hold the main circuit inside.
Functional description:
(you don't have to read this if the schematic is clear to you)
- U1, U2 and U3 : three 8 bit serial to parallel shift registers, which
spreads the serial signals from CB1 and CB2 to 20 bits word - 8 bit data out
+ 12 bit adrress.
- U4 : converts the parallel data byte read from the cartridge to serial data
sent to CB2 under control of CB1.
- chip-select inverter - the lower nand gate inverts active-low chip select
signal from PB0 to active-high one needed for the Atari cart. Although PB0
is software programmable and can produce active-low signal, the default
position of it (i.e. after turning on the Vic20 or hitting RUN/STOP+RESTORE)
is high. Also this gate isolates the vic from the plugged card - you can
never know what you plug in, so this method of operation is prefered.
- Q4, R5 and R6 : Q4 and R5 enables U4 to send data to the serial line CB2
when PB7 is in read mode. Otherwise CB2 is used to send data to the 4094s.
R6 is pull-up resistor for data coming from U4.
- read/write inverter: the upper nand gate - similar to the chip select
inverter (default position,isolation).
- R7, R8: this voltage divider protects the nand gate from overload when PB7
is in write mode and a real cart is plugged. R8 is also pull-down resistor
for the read/write in the ram cart.
- power control: Q1, Q2, Q3, R1, R2, R3 and R4 amplifies the 0.2mA control
current from PB5 to the current consumed by the main circuit and the
cartridge.
Notes:
- The LED isn't necessary, but it helps you know when the main circuit is
turned off - when it's on, you are not allowed to plug in or out the
cartridge.
- The ground sign on the schematic doesn't mean physical grounding. It means
that everything ended with it is connected with each other. It can be really
grounded, but that depends on your Vic20's power supply.
- The 4011 can be replaced. See the notes about the 4011 in the ram
cartridge section of this document.
- The power control can, theoriticaly, be reduced to R1,R2 and Q3 only. The
base of Q3 is then connected to the hook up of R1 and R2, instead of the base
of Q1. But the current amplification of Q3 has to be high. We don't want to
overload PB5 and, Q3 has to be in its saturation area in order to output
more than 4.8V, under load currents of 50mA, 100mA and more.
If we don't chage R1, then I(PB5) = 0.2mA. The user port of the Vic20 is
permitted to supply up to 100mA. Thus Hfe(min)= 100/0.2 = 500. Too high. The
nominal active current of the main board and the ram cart is less than 50mA.
Now we get Hfe(min)= 250. Still can't be obtained from every 2N2905-type
transistor, according to the manofacturer data. But you can try it, it will
probably work. A darlington transistor isn't suitable because it will give
4.3V output, not enough for U4 and the memory chip on the cart.
One transistor can be saved if PB5 turns into active-high instead of
active-low. But then the circuit is automaticaly turned on when the VIA6522
in the Vic is being reseted.
The software part:
The program which controls the ram-cart loading and the cartridge saving
is a 3.5k Basic program, running on the Vic20. It uses 0.5k machine language
program.
The program files are:
- ATARI14/C the basic program.
- ATARI MCP the machine code program.
[Ed. Note : The uuencoded versions of these files will extract with these
filenames. If this is a problem for your host machine, please edit
the filename field in the uuencoded versions at the end of this article.
Please keep in mind that you should rename them (as seen above) on your
VIC-20's drive. Such action will prevent potential load-chaining problems.]
The basic program is written for using a disk drive. If you have only tape,
change the "8" device number in the basic program to 1. It appears three
times: When loading games, when saving cartridge content and when loading the
machine code program.
Every time the program is runned, a checksum is made over the m.code program
in memory, and only if the checksum fails, the m.code program is reloaded.
Something i forgot - after reloading, the m.c. program isn't being checked-
so it's downloading from the PC has to be done carefully. To check it, load
first the machine code program with ",8,1" or ",1,1", type "NEW", and only
then load and run the basic program. If the m.c. program isn't reloaded, then
you know it had been downloaded properly.
If the ram expansion on the vic is non volatile, the mc. program will remain
in memory when the Vic is off. In the case of 16k+ ram expansion, the basic
start can be raised to $4000 and then the basic program becomes non volatile
too. In this case you have to change the memory settings in the program's
first lines.
The current memory configuration:
$1000 4096 - $11FF 4095 : screen bytes
$1200 4608 - $2DFF 11775 : basic program + variables
$2E00 11776 - $2FFF 12287 : machine language code
$3000 12288 - $3FFF 16383 : 4k game buffer
It's possible to cancel the 4k buffer by transferring data between the
disk and the cartridge byte by byte, and thus to compress the entire thing
to an unexpanded Vic20. But It's not simple and limits the program's ability
to grow up.
Operating instructions:
SAVING-CARTRIDGE CONTENT
------------------------
1. The main circuit has to be plugged to the Vic20's user port, before the Vic
is turned on.
2. Run the basic program, if it is not already running.
3. Plug in the Atari2600 game cartridge.
4. From the main menu, select "copy 2k" / "copy 4k" with or without check.
Before selecting, check that the cartridge is plugged in. DON'T plug it
in or out when the vic is reading it. It is avdised to connect a LED
(+ its resistor) to the main circuit, to see when it is powered on. Only when
the power is off, the cartridge can be inserted or removed.
5. If you selected copy with check, the saved file will be reloaded & compared
with the cartridge content.
6. The cartridge content is now saved in a file. The format of the file is 2
bytes - low and high byte of the start adrress of the buffer, followed by the
content itself - 2048 or 4096 bytes.
7. Now you will be asked for continue. If yes, the procedure repeats itself in
the same copy-type selection.
Notes:
- 2k games can be saved as 4k games, by choosing "copy 4k" on the menu.
The 4k file following the start adrress will be a double image of a 2k game.
- The saving proccess can be done with no cart plugged in without damaging
anything. The saved file will be full of 255's ($FF).
- You can hit RUN/STOP + RESTORE anytime and the main circuit will be
turned off.
LOADING GAMES TO THE RAM CARTRIDGE
----------------------------------
1. The main circuit has to be plugged to the Vic20's user port, before the Vic
is turned on.
2. Run the basic program, if it's not already running.
3. Insert the ram cartridge, if it isn't already plugged in. DON'T plug it
in or out when the vic is writing to reading it. It is avdised to connect a
LED (+ its resistor) to the main circuit, to see when it is powered on. Only
when the power is off, the cartridge can be inserted or removed.
4. Select the desired switch combination on the ram-cart. Check that it is not
the combination of an already loaded game, which you don't want to be
overwritten.
If loading 4k game,move s1 to 4k mode. For a 2k game, move s1 to 2k mode
and select (with s2) one of the 2k banks. s3, s4 and s5 selects between
4k banks, and gives 8 combinations.
5. From the main menu, select "load game". Type the name of the game and it
will be loaded. No disk browser at this stage.
Notes:
- When loading 2k games which have been saved as 4k games, move s1 to 4k
mode.
- The loading proccess can be done with no cart plugged in without damaging
anything.
- You can hit RUN/STOP + RESTORE anytime and the main circuit will be
turned off.
begin 644 atari14/c
M 1(<$@$ CR!3059%(D P.D%405)),30O0R(L. O$@( ES,V.#
M$@P CP"%$A0 ES4R+#0V.I($U#JC$U
M.H\@4$]715(@3T9& /,27P"/ /X2O@")(#(W,# #Q-> 8\@4D5!1"!"3$]#
M2P N$W(!ER X,C0L3$\ZER X,C4L2$DZCR!33U520T4 2A.& 4A)LK4H5*TR
M-38I.DQ/LE2K,C4VK$A) &D3D &7(#@R-BQ,3SJ7(#@R-RQ(23J/(%1!4D=%
M5 "'$YH!2$FRM2A,3JTR-38I.DQ/LDQ.JS(U-JQ(20"F$Z0!ER X,C L3$\Z
MER X,C$L2$DZCR!,14Y'5$@ R!.N 8\@0T]062!&4D]-($-!4U-%5$4@5$\@
M345-3U)9 -,3N &>($U#JC8 V1/" 8X ZQ,F H\@5U))5$4@0DQ/0TL "10Z
M DA)LK4H042M,C4V*3I,3[)!1*LR-3:L2$D *!1$ I<@.#(V+$Q/.I<@.#(W
M+$A).H\@4T]54D-% $043@)(2;*U*%2M,C4V*3I,3[)4JS(U-JQ(20!C%%@"
MER X,C0L3$\ZER X,C4L2$DZCR!405)'150 @11B DA)LK4H3$ZM,C4V*3I,
M3[),3JLR-3:L2$D H!1L I<@.#(P+$Q/.I<@.#(Q+$A).H\@3$5.1U1( ,,4
M=@*/($-/4%D@1E)/32!-14U/4ED@5$\@4T4N(%!/4E0 SA2 IX@34.J,P#N
M%(H"F2 BG2(@3$X@(D)95$53($-/35!,151%1"XB /04E *. @53 2/($=%
M5"!&24Q%($Y!344 (156!(L@3DTDLB(BIT(DLB(B.HDQ,3,P $D58 1")++(
M*"*=G9V=G9V=G9V=G9V=G9V=G9TB+,,H3DTD*:HR*0!H%6H$F2)&24Q%($Y!
M344@(" B3DTD0B0[.H5.320 >15T!(M.322R(B*G,3$Q, "L%7X$3++#*$Y-
M)"DZBTRQ,3:GF2)-05@N(#$V($Q%5%1%4E,B.DY-)+(B(CJ),3$Q, "R%8@$
MC@#)%9P$F2)/550@3T8@4D%.1T61(CJ. . 5L 2/(%)%4T54($1)4TL@1%))
M5D4 _16Z!)\R+#@L,34ZA#(L0BQ")"Q!+$$ZH#(ZC@ 7%CP%CR!3150@1DE,
M12!005)!345415)3 "(61@6!0K(QI$P /!90!9-C4T
M-CDZCR!3150@1DE,12!.04U% ) 6;P67-S@P+#$ZES-C4T.3,ZCR!,3T%$($9)3$4 &A?4!45/1K+"*#-C4T.38ZCR!3059%($9)3$4 O1<8!HX VA= !H\@5T%)5$E.1R!&
M3U(@2T59(%-44D]+10#Q%TH&F2(1'1TM2$E4($%.62!+15DB 485 :A020Z
MBT$DLB(BIS$V,C "QA>!HX &1A\!H\@34534T5'10!;&($&F2(124Y315)4
M(%1(12 24D%-DB!#05-3151%04Y$(%-44DE+12!!3ED@2T59(" @(%=(14X@
M4D5!1%DN(@!E&(8&B3$V,C B1BB!H\@("!>7EX@($5.1"!/1B!354)23U1)
M3D53("!>7EX CQBC!H\ M1@T"(\@3$]!1"!!5$%262!'04U%(%1/(%)!32!#
M05-3151410#$D(F2*3(CJ-,38V, #.(C3$Q,# X1A#")DB3$]!1$E.
M1R B3DTD /T82 A,3[(P.DA)LC0X.HTQ-# P.H\@3$]!1 '&4T(C3(T,#
M%QE2"(M%4K(P(*"IDB$1$@("!93U52($-(3TE#12 M/R( *1N@
M"J$@020 .1NB"HM!)+(B42(@IR" %D;I J+022R(C$BIR!,3K(R,#0X.D-+
MLC ZB3(W,S0 >1NE"HM!)+(B,B*G($Q.LC(P-#@Z0TNR,3J),C'9H+F2)#3TY424Y512 _("A9
M+TXI(@"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