inside the commodore 64

172
8/6/2019 Inside the Commodore 64 http://slidepdf.com/reader/full/inside-the-commodore-64 1/172

Upload: cubemanpdx

Post on 08-Apr-2018

242 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 1/172

Page 2: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 2/172

T h f i r s t m a c h i n e K n o w n t h a v e b e e ni n v e n t e d o p l a n e t E a r t h w i t h t h a b i l i t y t c o n t a i n s t o r e d a n m o d i f i a b l e p r o g r a m t o c o n t r o li t o p e r a t i o n w a i n v e n t e d i 1 8 0 1 b t h F r e n c hs i l k w e a v e r * J o s e p h - M a r i e C h a r l e s J a c q u a r d . I w a k n o w n a t h J a c q u a r d l o o m a n d i t p r o g r a m sw e r e e n c o d e d a s s e r i e s o p u n c h e d h o l e s o p a p e rc a r d s * t h d o m i n a n t m e a n s o p r o g r a m s t o r a g e f o t h n e x t 1 7 0 y e a r s . T h i n v e n t i o n e n a b l e d t h c r e a t i o n o f b e a u t i f u l a n i n t r i c a t e p a t t e r n s i t h f i n e s t f a b r i c k n o w n t m a a n w a t h p r e c u r s o r o f t h e m o d e r n c o m p u t e r . T h F r e n c h s i l kw e a v e r s g a i n e d i n t e r n a t i o n a l a c c l a i m f o t h u n s u r p a s s e d q u a l i t y o t h e i r w e a v i n g s . T h e i rt r a d i t i o n o p r o d u c i n g t h w o r l d ' s f i n e s t f a b r i c sh a i t b e g i n n i n g s w i t h t h e l o o m t h a t c o u l d b p r o g r a m m e d . F r e n c h s i l k i s t t h i s d a t h f i n e s t ,s m o o t h e s t , m o s t c a r e f u l l y c r a f t e d o f f a b r i c s .

Page 3: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 3/172

Page 4: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 4/172

P u b l i s h e d b F r e n c h S i l kP . O . B o 2 0 C a n n o n F a l l s , M 5 5 0 0 9

M a n u f a c t u r e d i t h U n i t e d S t a t e s o A m e r i c a

L i b r a r y o f C o n g r e s s n u m b e r 8 3 - 0 9 0 4 1 1

I S B N 0 - 9 6 1 2 4 2 2 - 0 - 5

C o p y r i g h t 1 9 8 3 ( C b F r e n c h S i l k . A l r i g h t s r e s e r v e d . N p a r t o t h i s p u b l i c a t i o n o r t h e a s s o c i a t e d c o m p u t e r s o f t w a r e m a b r e p r o d u c e di w h o l e o i p a r t w i t h o u t t h p r i o r w r i t t e n p e r m i s s i o n o F r e n c hS i l k .

Page 5: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 5/172

T a b l e o - C o n ± e n ± s

I n t r o d u c t o 1 -

C h a p t e r U s i n g D e v e l o p - 6 4 1 - O v e r v i e w 1 - T h e m a i n m e n u 1 - U s i n g t h t o o l s t u t o r i a l 1 - G e t t i n g g o i n g w i t h t h e d i t o r 1 - I n s e r t m o d e 1 - E r r o r m e s s a g e s 1 - M o d i f y m o d e 1 - L i s t m o d e 1 - I n s e r t m o d e r e v i s i t e d 1 - D e l e t e o p t i o n 1 - S a v i n g s o u r c e p r o g r a m 1 - 1 8

C h a p t e r U s i n g D e v e i o p - 6 4 I 2 - P r e p a r i n g t u s t h a s s e m b l e r 2 - L o a d i n g s o u r c e p r o g r a m 2 - A s s e m b l i n g t h s o u r c e p r o g r a m 2 - E r r o r m e s s a g e s 2 -

C h a p t e r U s i n g D e v e l o p - 6 4 I I 3 - R u n n i n g t h M L p r o g r a m 3 - D e c o d i n g t h p r o g r a m 3 -

C h a p t e r U s i n g D e v e l o p - 6 4 I V 4 - 1U s i n g t h d e b u g g e r 4 - T h e s a m p l e p r o g r a m e x p l a i n e d 4 -

C h a p t e r M a k i n g t h - f i n a l p r o d u c t 5 - W h e r e t p u M L p r o g r a m 5 - I n s i d e B A S I C p r o g r a m 5 - B e f o r e o a f t e r B A S I C 5 - I t h c a s s e t t e b u f f e r 5 - 7

Page 6: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 6/172

I s a c r e d R A 5 -

C h a p t e r

C h a p t e r

C h a p t e r

C h a p t e r

T h

T h

T h

T h

6 5 1 0 d a t a p r o c e s s o r

6 5 1 9 T h H a r d w a r eT h p r o g r a m c o u n t e rT h A - r e gT h e X a n d Y r e g sT h e S t a c k P o i n t e rT h P r o c e s s o r S t a t u s R e g i s t e rT h N e g a t i v e b i T h O v e r - F l o w b T h e B r e a k b i T h D e c i m a l m o d e b i T h e I n t e r r u p t d i s a b l e b i T h Z e r o b T h C a r r y b 6 5 1 0 s p e c i a l c h a r a c t e r i s t i c s6 5 1 9 t h s o f t w a r eA b s o l u t e m o d eZ e r o P a g e m o d eI m m e d i a t e m o d eI m p l i e d m o d e

A - r e g m o d eR e l a t u m o d eI n d e x e d m o d e sI n d i r e c t m o d e( I n d i r e c t ) , Y( I n d i r e c t ) , X

6 5 1 0 I n s t r u c t i o n s e R e g i s t e r - o n l y i n s t r u c t i o n sM e m o r y a c c e s s i n g i n s t r u c t i o n sC o n d i t i o n a l B r a n c h i n s t r u c t i o n sJ u m p i n s t r u c t i o n sS t a c k p u s h a n p u l l i n s t r u c t i o n sP s e u d o - o p i n s t r u c t i o n s

6 -

7 - 7 - 7 - 7 - 7 - 7 - 7 - 7 - 7 - 7 - 7 - 7 - 7 - 7 - 8 - 8 - 8 - 8 - 8 - 8 - 8 - 8 - 8 - 1 18 - 1 18 - 1 2

9 - 9 - 9 - 9 - 9 - 9 - 9 -

Page 7: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 7/172

-

S h i f t i n s t r u c t i o n s 9 - B o o l e a n a r i t h m e t i c i n s t r u c t i o n s 9 - A r i t h m e t i c i n s t r u c t i o n s 9 - 1 2C o m p a r e i n s t r u c t i o n s 9 - 1 5I m p o t e n t i n s t r u c t i o n s 9 - 1 6

C h a p t e r 1 S p e c i f i c a t i o n s f o A s s e m b l y l a n g u a g e 1 8 - 1G e n e r a l 1 8 - 1L a b e l s 1 8 - 1M n e m o n i c s 1 8 - 1S t a n d a r d m n e m o n i c s 1 8 - 1T h e E Q U p s e u d o - o p 1 8 - 2T h e B Y T p s e u d o - o p 1 8 - 3H e x a d e c i m a l s t r i n g s 1 8 - 3L i t e r a l t e x t s t r i n g s 1 8 - 3D a t a c o n s t a n t s 1 8 - 3A d d r e s s c o n s t a n t s 1 8 - 4T h o p e r a n d f i e l d 1 8 - 4A d d r e s s e x p r e s s i o n s 1 8 - 5T e r m s 1 8 - 5D e c i m a l F o r m a t 1 8 - 5H e x a d e c i m a l F o r m a t 1 8 - 5L i t e r a l F o r m a t 1 8 - 5S y m b o l i c l a b e l 1 8 - 6L o c a t i o n c o u n t e r 1 8 - 6A l g e b r a i c o p e r a t o r s 1 8 - 6A d d i t i o n 1 8 - 7S u b t r a c t i o n 1 8 - 7M u l t i p l i c a t i o n 1 8 - 7D i v i s i o n 1 8 - 7E x p o n e n t i a t i o n 1 8 - 7L o g i c a l A N 1 8 - 7L o g i c a l O 1 8 - 8E x p r e s s i o n e v a l u a t i o n 1 8 - 8T h h i g h - o r d e r s y m b o l 1 8 - 8T h l o w - o r d e r s y m b o l 1 8 - 9C o m p l e x e q u a t i o n s 1 8 - 9T h e c o m m e n t f i e l d 1 8 - 9Z e r o p a g e n o t a t i o n 1 8 - 1 8

Page 8: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 8/172

C h a p t e r 1

C h a p t e r 1

C h a p t e r 1

A p p e n d e x

A p p e n d i x

A p p e n d i x

A p p e n d i x

A p p e n d i x

A p p e n d i x

-

G r a p h i c s o n t h e C o m m o d o r e 6 T h V i d e o I n t e r - f a c e C h i p ( V I C - I I )B a n k s w i t c h i n gM u l t i p l e c h a r a c t e r s e t sM u l t i p l e s c r e e n sC o l o r c o n t r o l sC h a r a c t e r c o l o r sA l t e r n a t e d i s p l a y m o d e sM u l t i - c o l o r c h a r a c t e r sB t - m a p p e d g r a p h i c sM u l t i - c o l o r b i t - m a p p e d m o d eE x t e n d e d b a c k g r o u n d c o l o r m o d eS p r i t G r a p h i c s

T h 6 5 8 1 A s o u n d s y n t h e s i s e rR e g i s t e r a s s i g n m e n tT o n e g e n e r a t i o nW a v e s h a p e r e g u l a t i o nF i 1 t e r n M i i n

C o m m o d o r e 6 i n t e r n a l sF l o a t i n g p o i n t n u m b e r sA r i t h m e t i c r o u t i n e sI n p u t / O u t p u t r o u t i n e s

M n e m o n i c / A d d r e s i n g m o d e t a b l e

C o d e c o n v e r s i o n t a b l e

A u t o - s t a r t C a r t r i d g e s

C o m m o d o r e 6 M e m o r y m a

S a m p l e B i t - m a p p e d p l o t t i n g

U n d e r s t a n d i n g b i n a r y a n H e x a d e c i m a l

1 1 - 11 1 - 11 1 - 11 1 - 31 1 - 91 1 - 1 81 1 - 1 81 1 - 1 11 1 - 1 21 1 - 1 31 1 - 1 41 1 - 1 41 1 - 1 5

1 2 - 11 2 - 11 2 - 21 2 - 31 2 - 51 2 - 6

1 3 - 11 3 - 11 3 - 51 3 - 8

A -

B -

C -

D -

E -

F -

Page 9: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 9/172

I n s i d e T h C o m m o d o r e 6 P a g e I -

I n t r o d u c t i o nT h i s b o o k h a s b e e n w r i t t e n b o t h a g e n e r a l p u r p o s e C o m m o d o r e

6 4 a n d 6 5 1 6 m i c r o p r o c e s s o r t u t o r i a l a n d a s s p e c i f i c c o m p l e m e n t t a n g u i d e f o t h u s o s e o s o f t w a r e t o o l s . T h t o o l s * a l o n gw i t h t h i s b o o k c o m p r i s e D e v e l o p - 6 4 , p r o d u c t o F r e n c h S i l k . W h i l et h i s b o o k i c e r t a i n l y u s e f u l t o o l i n i t s o w r i g h t , i t v a l u e m a b m a g n i f i e d c o n s i d e r a b l y w h e n u s e d i c o n j u n c t i o n w i t h t h o t h e rt o o l s . P r o g r a m m e r s o a l l e v e l s o f e x p e r i e n c e s h o u l d f i n d t h i s g u i d e

v a l u a b l e r e s o u r c e .

T h b o o k m a b a s i c a l l y b d i v i d e d i n t o t h r e e s e c t i o n s . T h f i r s t s e c t i o n p r o v i d e s i n f o r m a t i o n o t h u s o f t h e D e v e l o p - 6 4 , t h s o f t w a r e . I b r i n g s y o s t e p - b y - s t e p t h r o u g h t h m e c h a n i c s o c r e a t i n g , m o d i f y i n g , r u n n i n g a n d d e b u g g i n g m a c h i n e l a n g u a g e p r o g r a m s .

T h s e c o n d s e c t i o n g i v e s d e t a i l e d l o o k a t t h e a r c h i t e c t u r eo t h 6 5 1 0 m i c r o p r o c e s s o r . I t a d d r e s s i n g m o d e s , r e g i s t e r s e a n i n s t r u c t i o n s e a r e x a m i n e d . T h n a t u r e a n s t r u c t u r e o d a t a i a l s o e x p l o r e d . T h i n t r o d u c t i o n t a s s e m b l y l a n g u a g e i p r e s e n t e d i t h i s s e c t i o n .

T h t h i r d s e c t i o n i v e r y C o m m o d o r e 6 4 - s p e c i f i c . I p r o v i d e st h i n f o r m a t i o n w h i c h i n e c e s s a r y t u t i l i z e t h C o m m o d o r e 6 4 ' sb u i l t - i n p r o g r a m s . I p r o v i d e s m e m o r y m a p s o a l o t h e 6 4 ' s B A S I Co p e r a t i n g s y s t e m a l o n g w i t h t h i n f o r m a t i o n a t h o t u s s o m e o t h e b u i l t - i n p r o g r a m s . I d e s c r i b e s h o t b u i l d c u s t o m c h a r a c t e r s ,c r e a t e s p r i t e s a n h o t p r o d u c e b i t - i m a g e g r a p h i c s a n t p r o g r a mt h m u s i c s y n t h e s i s e r .

T h a p p e n d i x e s c o n t a i n a d d i t i o n a l i n f o r m a t i o n o t h 6 5 1 6 a n t h C o m m o d o r e 6 a l o n g w i t h s o m e u s e f u l t a b l e s a n s a m p l e p r o g a m s .A l s o i n c l u d e d i t u t o r i a l o b i n a r y a n d h e x a d e c i m a l n u m b e r b a s e s .

I i s p e c i f i c a l l y p r o h i b i t e d t o m a k e c o p i e s o f t h e s o f t w a r e o t h i s b o o k f o r e s a l e o r f o r d i s t r i b u t i o n t o f r i e n d s , r e l a t i v e s ,a s s o c i a t e s o a n y o n e e l s e . W h o p e y o w i l l r e s p e c t t h l e g a l a n e t h i c a l r e s t r i c t i o n s w h i c h a p p l y t o t h e t h e f t o s o f t w a r e , b o t h o u r sa n e v e r y o n e e l s e ' s .

Page 10: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 10/172

I n t i d t T h C o m m o d o r t 6 P t g t 1 -

W h i l e t h i s p r o d u c t p r o v i d e s t o o l s w h i c h m a f a c i l i t a t e t h c o p y i n g o - l e g a l l y p r o t e c t e d s o f t w a r e , i i n o t h e i n t e n t o F r e n c hS i l k t h a t y o p u t h e s e t o o l s t o t h i s u s e . W o p p o s e a n d w i s h t v e r ys t r o n g l y d i s c o u r a g e t h p i r a t i n g o f s o f t w a r e . W w o u l d a l s o l i k e t p o i n t o u t h a t t h e r e a r s e v e r e p e n a l t i e s a s s o c i a t e d w i t h c o p y r i g h tv i o l a t i o n i n c l u d i n g f i n e s u t $ 1 M 0 0 a n d i m p r i s o n m e n t o u t o n y e a r ( n o t t m e n t i o n c i v i l l i a b i l i t y ) . W r e m i n d y o u t h a t p r o g r a m m e r sh a v e t h s a m e s o r t o f i n a n c i a l o b l i g a t i o n s a s e v e r y o n e e l s e a n w h e ny o u m a k e c o p y o f s o f t w a r e p r o d u c t t o g i v e t f r i e n d y o a r c o m m i t t i n g a a c t o f t h e f t a g a i n s t t h p r o g r a m m e r . I t h i n t e r e s t o p r o m o t i n g t h e c o n t i n u e d d e v e l o p m e n t o h i g h - q u a l i t y a n l o w - c o s ts o f t w a r e t h c o n s u m e r m u s t p l a y h i s a n h e r r o l e s i h e l p i n g t oe l i m i n a t e t h i s p r o b l e m .

T h a n k y o f o y o u r c o o p e r a t i o n a n m a a l y o u r p r o g r a m s w o r kt h f i r s t t i m e . E n j o y D e v e l o p - 6 4 .

D C

Page 11: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 11/172

I n i i d t T h C o m m o d o r t 6 P t g t 1 -

U s i n g D e v e l o p — 6 4T h i s c h a p t e r w i l l p r o v i d e a n o v e r v i e w o f t h e s o f t w a r e t o o l s

w h i c h c o m p r i s e D e v e l o p - 6 4 . I a l s o w i l l l e a d y o t h r o u g h t h f i r s ts t e p s o f t h e u s o t h t o o l s . I i r e c o m m e n d e d y o g t h r o u g h t h e x e r c i s e o f e n t e r i n g > m o d i f y i n g * a s s e m b l i n g ? e t c . t h g i v e n p r o g r a m si t h e t e x t a s y o r e a d . T h s a m p l e p r o g r a m c r e a t e d i t h i s c h a p t e rw i l l b u s e d i s u b s e q u e n t c h a p t e r s t i l l u s t r a t e t h u s o o t h e rf u n c t i o n s a n c a p a b i l i t i e s o D e v e l o p - 6 4 . I i n o n e c e s s a r y t u n d e r s t a n d t h p r o g r a m y o e n t e r a t t h i s t i m e . I w i l l b e x p l a i n e di m o r e d e t a i l l a t e r . T h i s a n t h n e x t f e c h a p t e r s a r d e s i g n e d t f a m i l i a r i z e y o w i t h t h m e c h a n i c s o o p e r a t i n g D e v e l o p - 6 4 . V e r yd e t a i l e d e x p l a n a t i o n o m a c h i n e l a n g u a g e f t h e a r c h i t e c t u r e o t h 6 5 1 9a n t h C o m m o d o r e 6 w i l l b e p r e s e n t e d i s u b s e q u e n t c h a p t e r s . Y o m a f i n d i v a l u a b l e t o r e t u r n t t h e s e f i r s t c h a p t e r s a f t e r y o u h a v eg a i n e d m o r e u n d e r s t a n d i n g .

O v e r v i e w

T g e t s t a r t e d y o s h o u l d h a v e t h 6 t u r n e d o a n t h t a p eo r d i s k e t t e i t h a p p r o p r i a t e d e v i c e r e a d y t l o a d . L o a d D e v e l o p - 6 4m u c h a s y o u w o u l d l o a d a n o t h e r p r o g r a m , i . e . L O A D " D E V E L O P - 6 4 " , 8 f o d i s k o r L O A D " D E V E L O P - 6 4 " f o r t a p e . I y o e x p e r i e n c e t r o u b l e l o a d i n gD e v e l o p - 6 4 b s u r e y o h a v e s p e l l e d t h n a m e r i g h t a n t h a t a l o y o u r e q u i p m e n t i i p r o p e r w o r k i n g c o n d i t i o n . I L O A D E R R O R s p r e v e n ty o f r o m l o a d i n g t h e p r o g r a m o r t h e p r o g r a m j u s t d o e s n ' t s e e m t b o t h m e d i a a a l a n d y o u a r s u r e y o u r m a c h i n e s a r i g o o d w o r k i n go r d e r » y o s h o u l d r e t u r n t h m e d i a f o r e p l a c e m e n t .

S t a r t t h p r o g r a m i t h e u s u a l f a s h i o n , i . e . b t y p i n g " R U N "f o l l o w e d b y C R ( t h e s y m b o l u s e d i t h i s b o o k t s i g n i f y t h r e t u r nk e y ) . P l e a s e n o t e t h a t w u s t h q u o t e s ( " f r e q u e n t l y i t h i s b o o kt b r a c k e t t h r e s p o n s e y o u a r e i n s t r u c t e d t g i v e t v a r i o u s p r o m p t s .T h q u o t e s a r n o a p a r t o w h a t y o k e i n t o t h c o m p u t e r . K e o n l yw h a t i e n c l o s e d w i t h i n t h e m .

T h f i r s t q u e s t i o n y o w i l l b e a s k e d r e l a t e s t w h e r e i t h m e m o r y s p a c e o f t h e 6 y o w o u l d l i k e D e v e l o p - 6 4 t o r e s i d e . T h d e f a u l t v a l u e s i y o h i C R w i l l b f r o m $ 9 8 e e t $ B F F F ( 2 6 4 8 t 4 6 9 5 9 ) . I m a b p l a c e d a n y w h e r e t h e r e i 1 6 a v a i l a b l e . T h

Page 12: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 12/172

I n s i d e T h C o m m o d o r e 6 P * 9 « 1 -

r e a s o n s - f o r w a n t i n g t d e t e r m i n e t h e s t a r t i n g a n d e n d i n g a d d r e s s e sw i l l b e d i s c u s s e d l a t e r . F o n o h i C R t w i c e .

T h e m e s s a g e w h i c h i n o d i s p l a y e d i s

T H E M A X I M U M N U M B E R O S T A T E M E N T S Y O M A Y H A V E I S O U R C ES E G M E N T I N O . . . .

T h v a l u e p r i n t e d i c o m p u t e d f r o m t h s t a r t i n g a n d e n d i n ga d d r e s s e s g i v e n a b o v e . N o t h s c r e e n w i l l g e t s t r a n g e f o a w h i l e a n t h e n t h c o p y r i g h t m e s s a g e w i l l a p p e a r f o l l o w e d b t h m a i n m e n u a d e s c r i b e d b e l o w . A f t e r t h m e n u w i l l b q u e s t i o n m a r k ( ? ) .

T h m a i n m e n uW h e n D e v e l o p - 6 4 i i n i t i a l l y r u a n u p o n e x i t i n g f r o m a n o

t h s u b - p r o g r a m s t h m a i n m e n u o p o s s i b l e s u b - p r o g r a m s i d i s p l a y e d :

1 E X I T 2 E D I T 3 A S S E M 4 D E C O D E5 D E B U G 6 L O A D 7 S A V E 8 N E

O p t i o n o t h m a i n m e n u c a u s e s t h r e t u r n t B A S I C . E v e r ys u b - p r o g r a m a l s o h a n u m b e r a s t h e e x i t o p t i o n . F o t h s u p r o g r a m s t h i s o p t i o n c a u s e s r e t u r n t o t h m a i n m e n u .

O p t i o n c a u s e s t h e d i t o r s u b - p r o g r a m t b r u n . T h e d i t o ri u s e d t c r e a t e a s s e m b l y l a n g u a g e p r o g r a m s f r o m s c r a t c h o r t o m a k em o d i f i c a t i o n s t t h e m . W i t h i y o c a i n s e r t * d e l e t e * m o d i f y a n dl i s t l i n e s o t h s o u r c e p r o g r a m . w a l k - t h r o u g h o t h u s o t h e d i t o r t o c r e a t e s m a l l m a c h i n e l a n g u a g e p r o g r a m f o l l o w s t h eo v e r v i e w .

O p t i o n c a u s e s t h a s s e m b l e r s u b - p r o g r a m t b r u n . T h f u n c t i o n o t h a s s e m b l e r i t t r a n s l a t e p r o g r a m s w r i t t e n i a s s e m b l yl a n g u a g e i n t o m a c h i n e l a n g u a g e . T h a s s e m b l e r f i n d s t h e a s s e m b l yl a n g u a g e p r o g r a m , c a l l e d t h " s o u r c e p r o g r a m 1 1 * i m e m o r y i t h s o u r c ep r o g r a m a r e a . T h e p r o g r a m m u s t h a v e b e e n p r e v i o u s l y c r e a t e d w i t h t h e d i t o r ( o p t i o n 2 o t h d e c o d e r ( o p t i o n 4 o l o a d e d D y t h l o a d e r( o p t i o n 6 ) T h s o u r c e p r o g r a m i a s s e m b l e d b t h a s s e m b l e r a n t h r e s u l t i n g m a c h i n e l a n g u a g e p r o g r a m i p r o d u c e d . T h l i s t i n g o t h

Page 13: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 13/172

I n s i d e T h C o m m o d o r e 6 P a g e 1 -

p r o g r a m i d i r e c t e d t o e i t h e r t h e s c r e e n o t h p r i n t e r . T h m a c h i n el a n g u a g e m a b d i r e c t e d t o e i t h e r a " o b j e c t " f i l e o t a p e o r d i s k o rd i r e c t l y P O K E e d i n t o m e m o r y o b o t h . T h s p e c i f i c a t i o n s f o t h c r e a t i o n o a s s e m b l y l a n g u a g e p r o g r a m s a r g i v e n i C h a p t e r 1 0

O p t i o n s e l e c t s t h d e c o d e r a t h s u b - p r o g r a m t b r u n . T h d e c o d e r d o e s t h o p p o s i t e o t h a s s e m b l e r . Y o s p e c i f y t h e s t a r t i n ga n e n d i n g a d d r e s s e s i m e m o r y w h i c h y o w a n t t d e c o d e a n i w i l lp r o d u c e t h a s s e m b l y l a n g u a g e p r o g r a m w h i c h c o r r e s p o n d s t t h m a c h i n el a n g u a g e p r o g r a m i m e m o r y . T h e d e c o d e r l i s t s t h a s s e m b l y l a n g u a g ep r o g r a m o t h s c r e e n a n o p t i o n a l l y t o t h p r i n t e r . I a l s o c a p l a c e t h g e n e r a t e d a s s e m b l y l a n g u a g e p r o g r a m i t h s o u r c e p r o g r a ma r e a o m e m o r y w h e r e y o m a a c c e s s i w i t h t h e e d i t o r a n d / o r t h a s s e m b l e r .

O p t i o n o f t h e m a i n m e n u s e l e c t s t h e d e b u g g e r . T h i s t o o la l l o w s y o t r u n a n y m a c h i n e l a n g u a g e p r o g r a m s i n g l e i n s t r u c t i o n a

t i m e . A e a c h i n s t r u c t i o n i e x e c u t e d i i d e c o d e d a n d a l t h i n t e r n a l r e g i s t e r s o f t h e 6 5 1 0 m i c r o p r o c e s s o r a r e d i s p l a y e d , i n c l u d i n gt h i n d i v i d u a l s t a t u s b i t s o t h p r o c e s s o r s t a t u s r e g i s t e r . A n m e m o r y l o c a t i o n m a b e d i s p l a y e d a n d a n y m e m o r y l o c a t i o n i R A m a b m o d i f i e d a m a a n o t h r e g i s t e r s . W h i l e s i n g l e - s t e p p i n g t h r o u g hp r o g r a m a n i n s t r u c t i o n m a b e b y p a s s e d .

O p t i o n s e l e c t s t h L O A D s u b - p r o g r a m . T h i s s u b - p r o g r a m c a l o a d t w t y p e s o f i l e s . I i u s e d t r e - l o a d s o u r c e f i l e s a n t l o a d " o b j e c t f i l e s " m a c h i n e l a n g u a g e p r o g r a m s w h i c h w e r e c r e a t e dw i t h t h e a s s e m b l e r ) . F i l e s m a b l o a d e d f r o m t a p e o d i s k .

O p t i o n o t h m a i n m e n u s e l e c t s t h S A V E s u b - p r o g r a m . S A V Ea l l o w s y o t d t w k i n d s o f s a v e s . Y o u m a y s a v e y o u r s o u r c e p r o g r a mw h i c h w a c r e a t e d w i t h t h e e d i t o r a n d / o r t h d e c o d e r o n t o t a p e o d i s k . S o u r c e p r o g r a m s a u t o m a t i c a l l y h a v e t h s u f f i x " . S R C " a p p e n d e dt o t h e f i l e n a m e y o a s s i g n . T h e y m a b e r e - l o a d e d i n t o t h s o u r c ep r o g r a m a r e a b y t h L O A D s u b - p r o g r a m ( o p t i o n 6 ) A l s o , b l o c k s o fm e m o r y m a b s a v e d a " b i n a r y " f i l e s w h i c h m a b r e - l o a d e d l a t e rw i t h t h e u s u a l B A S I C " L O A D " c o m m a n d . T h e t h i r d k i n d o s a v i n g d o n e b D e v e l o p - 6 4 i d o n e a s a n o p t i o n o t h a s s e m b l e r . I s a v e s " o b j e c t "f i l e s t t a p e o r d i s k w h i c h t h L O A D s u b - p r o g r a m c a r t t h e n r e a d a n p o k e i n t o m e m o r y . T h e s e f i l e s a u t o m a t i c a l l y h a v e t h s u f f i x " . O B J "

Page 14: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 14/172

I n s i d e T h C o m m o d o r e 6 P t g t 1 -

a p p e n d e d t t h e i r f i l e n a m e s .

O p t i o n i u s e d t c l e a r t h s o u r c e p r o g r a m a r e a . I t ' s u s i r e q u i r e d o n l y w h e n y o u w i s h t r e p l a c e t h e c u r r e n t s o u r c e p r o g r a m w i t ha n o t h e r .

U s i n g t h t o o l s t u t o r i a l

T h - f o l l o w i n g t u t o r i a l w i l l b r i n g y o u s t e p - b y - s t e p t h r o u g h t h m a n y u s e s o f t h e t o o l s . T h t u t o r i a l w i l l n o a t t e m p t t e x p l a i n t h ea s s e m b l y l a n g u a g e p r o g r a m o m u c h a b o u t t h s y n t a x o - t h s t a t e m e n t sc r e a t e d . F o a u n d e r s t a n d i n g o f t h e r u l e s o p r o p e r a s s e m b l ys t a t e m e n t c o n s t r u c t i o n ! s e C h a p t e r I d F o a n u n d e r s t a n d i n g o t h w a t h v a r i o u s i n s t r u c t i o n s c a u s e t h 6 5 1 0 t b e h a v e t r e a d C h a p t e r s6 - 9 . F o a n u n d e r s t a n d i n g o t h e 6 4 - s p e c i f i c p a r t s o t h p r o g r a mr e a d C h a p t e r s 1 1 — 1 3 . T h i s t u t o r i a l i d e s i g n e d t o f a m i l i a r i z e y o w i t h t h m e c h a n i c s o c r e a t i n g w o r k i n g a s s e m b l y l a n g u a g e p r o g r a m *a s s e m b l i n g i t l o a d i n g i i n t o m e m o r y a n r u n n i n g i b o t h a n o r m a ls p e e d a n a s i n g l e - s t e p s p e e d . Y o w i l l a l s o l e a r n h o t d e c o d em a c h i n e l a n g u a g e p r o g r a m b a c k i n t o a s s e m b l y l a n g u a g e .

G e t t i n g g o i n g w i t h t h e d i t o r

D e v e l o p - 6 4 i w a i t i n g f o m e n u s e l e c t i o n . W w i s h t c r e a t e as o u r c e p r o g r a m f r o m s c r a t c h s K e y a " 2 t o s e l e c t t h e d i t o r .

T h e d i t o r m e n u s h o u l d n o b o t h e s c r e e n . T h e d i t o r ' so p t i o n s a r e :

1 E X I T 2 L I S T 3 I N S E R T 4 D E L E T E 5 ) M 0 D I F YA m e n t i o n e d b e f o r e * o p t i o n w i l l r e t u r n y o t t h m a s t e r

m e n u * i . e . e x i t t h e d i t o r . O p t i o n w i l l l i s t t h s o u r c e p r o g r a m i t h e r e i o n t l i s t . W h a v e n ' t g o t t e n t h a t f a r y e t . W h a t w w a n tt d n o i t i n s e r t l i n e s o s o u r c e p r o g r a m i n t o t h e s o u r c ep r o g r a m a r e a . S t h o p t i o n t s e l e c t i " 3 " . N o t h n e x t p r o m p t ," I N S E R T A F T E R ? " w i l l a p p e a r .

I n s e r t m o d e

T h q u e s t i o n t h e d i t o r i a s k i n g i w h e r e w w a n t t s t a r t

Page 15: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 15/172

Page 16: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 16/172

I r m i d t T h C o m m o d o r t 6 P a g e 1 -

B s u r e t l e a v e a s p a c e b e t w e e n t h l a b e l , " S R C " a n t h m n e m o n i c * " E Q U " . B s u r e N O t o l e a v e a n s p a c e b e t w e e n t h " E Q U " a n t h o p e r a n d , " 2 5 1 " . N o K e y i n g s p a c e b e t w e e n t h e s e t w f i e l d s m a s e e m u n n a t u r a l t t h o s e w h h a v e e x p e r i e n c e w i t h o t h e ra s s e m b l e r / e d i t o r s b u i s a v e s y o u K e y s t r o k e a n b e c o m e s n a t u r a lv e r y q u i c k l y . T h a s s e m b l y l i s t i n g a n l i s t i n g s p r o d u c e d w i t h t h e d i t o r w i l l h a v e s p a c e i n s e r t e d - f o r i m p r o v e d r e a d a b i l i t y .

A n o t h e r s p a c e s h o u l d b p r e s e n t a f t e r t h o p e r a n d a n d b e - f o r et h c o m m e n t * " S O U R C E V E C T O R " . T h i s i t y p i c a l a s s e m b l y l a n g u a g es t a t e m e n t . I h a a l - f o u r p o s s i b l e f i e l d s p r e s e n t . T h l a b e l a n c o m m e n t f i e l d s a r n o a l w a y s p r e s e n t a n d f o s o m e i n s t r u c t i o n s t h eo p e r a n d f i e l d i s n o p r e s e n t e i t h e r . T h e m n e m o n i c i l i k e t h v e r b o ft h s t a t e m e n t a n m u s t a l w a y s b p r e s e n t . I m u s t a l w a y s h a v e s p a c eb e f o r e i t I t h e r e i l a b e l , t h e r e m u s t b o n l y o n e s p a c es e p a r a t i n g t h t w f i e l d s . I t h e r e i n l a b e l , t h f i r s t c h a r a c t e rm u s t b a s p a c e a n t h m n e m o n i c m u s t s t a r t i t h s e c o n d p o s i t i o na f t e r t h e q u o t e . C o m m e n t s m u s t a l w a y s b e s e p a r a t e d f r o m t h e p r e c e d i n gp a r t o t h s t a t e m e n t b s p a c e . N o t e t h a t t h e r e a r t w K i n d s o fc o m m e n t s , t h o s e o l i n e s b t h e m s e l v e s a n s t a r t i n g w i t h " ; a n t h o s e w h i c h a r o t h s a m e l i n e a t h a s s e m b l y l a n g u a g e i n s t r u c t i o n .

O n c e y o u h a v e t h s t a t e m e n t K e y e d j u s t a s h o w n , h i C R 3 . I s h o u l d a p p e a r b e l o w t h p r e v i o u s l i n e w i t h l i n e n u m b e r " 2 " . N o e n t e rt h r e m a i n d e r o f t h e f o l l o w i n g s h o r t a s s e m b l y l a n g u a g e s e g m e n t , o n s t a t e m e n t a t i m e . I y o m a k e m i s t a k e s w h i l e e n t e r i n g t h p r o g r a my o m a c o r r e c t t h e m b e f o r e h i t t i n g C R ] o n t h l i n e i q u e s t i o n o y o m a c o r r e c t t h e r r o r l a t e r w i t h t h m o d i f y o p t i o n .

S A M P L E P R O G R A MS R E Q U 2 5 1 S O U R C E V E C T O RD S E Q U 2 5 3 D E S T V E C T O RS R C E E Q U $ D 8 8 B O R I G C H A R S E TD S T E E Q U $ C 8 8 8 N E C H A R S E S T A R T E Q U * C 0 0 8

E r r o r M e s s a g e s

I i p o s s i b l e y o m a g e a e r r o r m e s s a g e o t w w h i l e k e y i n gt h p r o g r a m . E r r o r s a r e s i g n a l e d b a a u d i b l e " b e e p " a n d b y a

Page 17: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 17/172

I n s i d t T h C o m m o d o r e 6 P a g t 1 -

m e s s a g e a b o v e t h e d i t w i n d o w i r e v e r s e r e l e t t e r s . T h f o r m a t o e d i t o r e r r o r m e s s a g e s i E R o E R 2 W h e n a e r r o r o c c u r s , t h l i n e j u s t K e y e d w i l l r e m a i n i t h e d i t w i n d o w u n t i l i i c o r r e c t e d .E R s i g n i f i e s m n e m o n i c w h i c h i n o v a l i d . E R 2 s i g n i f i e s e i t h e ra s y n t a x e r r o r s u c h a n s p a c e b e f o r e t h e m n e m o n i c o a e x t r a s p a c eb e t w e e n t h m n e m o n i c a n t h o p e r a n d . E R w i l l a l s o b e g i v e n i t h a d d r e s s i n g m o d e i n o t a l e g a l o n f o t h m n e m o n i c u s e d . l i s t o a l t h m n e m o n i c s a n t h e i r v a l i d a d d r e s s i n g m o d e s m a y b e f o u n d i A p p e n d i x A

T e x i t t h e i n s e r t m o d e i i n e c e s s a r y o n l y t k e C R w i t hn f u r t h e r e n t r y i t h e e d i t w i n d o w . O n c e d o n e * t h e m e n u w i l lr e a p p e a r a n d y o u m a s e l e c t o t h e r o p t i o n s a y o c h o o s e .

I w o u l d b u s e f u l t t r t h m o d i f y m o d e n o e v e n i n m i s t a k e s w e r e m a d e i t h o r i g i n a l e n t r y .

M o d i f y m o d e

T s e l e c t t h m o d i f y o p t i o n k e y " 5 " . Y o w i l l n o b e a s k e dw h e r e t b e g i n m o d i f i c a t i o n s .

" B E G I N A T ? " s h o u l d a p p e a r o t h e s c r e e n . G i v e i t h l i n e n u m b e rw h e r e y o u w o u l d l i k e t b e g i n m a k i n g m o d i f i c a t i o n s . T r " 1 " . L i n en u m b e r s h o u l d n o a p p e a r i t h e d i t w i n d o w w a i t i n g f o y o u rc h a n g e s . Y o u m a y m a k e c h a n g e s o n o a y o w i s h . I n o c h a n g e s a r d e s i r e d h i C R ] . I y o u w i s h t m a k e c h a n g e s * m o v e t h c u r s o r t o t h ep l a c e y o w i s h t c h a n g e , m a k e t h m o d i f i c a t i o n a n w h e n d o n e , h i C R ] . Y o m a u s t h i n s e r t a n d e l e t e k e y s i y o w i s h .

O n c e y o u h a v e h i C R t h m o d i f i e d l i n e w i l l r e p l a c e t h e o l l i n e a n w i l l a p p e a r b e l o w . N o t h n e x t l i n e w i l l a p p e a r i t h e d i tw i n d o w f o y o u r e x a m i n a t i o n a n d p o s s i b l e m o d i f i c a t i o n . Y o w i l l s t a yi m o d i f y - m o d e u n t i l o n o t w t h i n g s h a p p e n s . E i t h e r t h e l a s t l i n eo t h p r o g r a m h a s b e e n m o d i f i e d o y o t e r m i n a t e m o d i f y - m o d e b o v e r -k e y i n g " i t h f i r s t c h a r a c t e r p o s i t i o n o f t h l i n e p u u i t h e d i t w i n d o w a n h i t t i n g C R ] . W h e n t e r m i n a t e d , t h e m e n u w i l l r a p p e a r , a n D e v e l o p - 6 4 w i l l a u t o m a t i c a l l y e n t e r l i s t m o d e a d e s c r i b e db e l o w .

Page 18: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 18/172

I n t i d t T h C o m m o d o n 6 P a g t i -

U s m o d t

T h s o u r c e p r o g r a m i l i s t e d a u t o m a t i c a l l y a f t e r e x i t i n g - f r o mi n s e r t m o d e a n - f r o m m o d i f y m o d e a n a f t e r d e l e t i n g l i n e s a n a f t e rl o a d i n g a s o u r c e p r o g r a m f r o m t a p e o d i s k . I t h e s e c a s e s t h l i s t i n g w i l l b d i r e c t e d t o t h s c r e e n o n l y a n t h l i s t i n g w i l l s t a r tw i t h l i n e 1 I i p o s s i b l e t c o m m a n d D e v e l o p - 6 4 t b e g i n l i s t i n gt h p r o g r a m a a n t i m e y o a r i t h e d i t s u b - p r o g r a m b s e l e c t i n go p t i o n 2

U p o n s e l e c t i n g t h l i s t o p t i o n * y o w i l l t h e n b a s k e d " B E G I NA T ? " . G i v e i l i n e n u m b e r , s u c h a s " ! " . N e x t y o w i l l b e a s k e dw h e t h e r y o w a n t t h l i s t i n g t g t t h " P R I N T E R ? " " Y " o r a " N i e x p e c t e d . T h " N r e s p o n s e i t h d e f a u l t , i w h i c h c a s e t h el i s t i n g w i l l g o o n t h s c r e e n . W h e t h e r t h l i s t m o d e w a e n t e r e da u t o m a t i c a l l y o b e x p l i c i t m e n u s e l e c t i o n , w h i l e t h e l i s t i n g i p r o c e e d i n g y o m a p a u s e i a a n t i m e b y h i t t i n g a n k e y . H i t t i n gC R w i l l c a u s e t h i m m e d i a t e r e t u r n t t h m e n u . Y o u m a y r e s u m ep a u s e d l i s t i n g b h i t t i n g a n k e e x c e p t C R J . H i t t i n g C R w i l l c a u s ea r e t u r n t t h m e n u .

I n s e r t m o d e r e v i s i t e d

I n s e r t m o d e m a y b e e n t e r e d t i n s e r t l i n e s o s o u r c e i t h m i d d l e o f p r o g r a m a w e l l a f o c r e a t i n g o n e f r o m s c r a t c h . W i t ht h s a m p l e p r o g r a m c r e a t e d t h u s f a r , s e l e c t o p t i o n 3 t r e - e n t e ri n s e r t m o d e . T h " I N S E R T A F T E R ? " p r o m p t s h o u l d b e a n s w e r e d w i t h" 1 " . N o s e v e r a l l i n e s o t h p r o g r a m s e g m e n t w i l l b e d i s p l a y e d o t h s c r e e n a n d t h e d i t - w i n d o w w i l l b o p e n a g a i n . K e s i n g l ec h a r a c t e r a n C R 3 . T h i s s h o u l d c a u s e n e l i n e t b e e n t e r e d a n di n s e r t e d a f t e r l i n e n u m b e r a n i w i l l a p p e a r b e l o w w i t h t h ef o l l o w i n g s t a t e m e n t s a u t o m a t i c a l l y r e n u m b e r e d . T h e e m p t y e d i t - w i n d o ww i l l r e - a p p e a r a n y o m a n o k e a n o t h e r s t a t e m e n t t b i n s e r t e da f t e r t h e o n j u s t e n t e r e d . I y o w i s h , t r i n s e r t i n g o t h e rs t a t e m e n t s . A n y t h i n g s t a r t i n g w i t h " ; w i l l b e a c c e p t e d . T l e a v et h i n s e r t m o d e , l i k e b e f o r e , h i C R w i t h b l a n k l i n e . L i s t i n g w i l la u t o m a t i c a l l y c o m m e n c e .

Page 19: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 19/172

I n t i d t T h C o m m o d o r t 6 P a g t i -

D e l e t e O p t i o n

I y o u w i s h t o d e l e t e s o m e l i n e s f r o m y o u r p r o g r a m t h m e n us e l e c t i o n i " 4 " . Y o w i l l b a s k e d t h e s t a r t i n g a n d e n d i n g l i n en u m b e r s t h a v e d e l e t e d . A w i t h i n s e r t , u p o n d e l e t i n g , t h r e m a i n d e ro t h p r o g r a m w i l l b r e n u m b e r e d . L i s t i n g w i l l c o m m e n c e .

N o y o c a n e n t e r t h e r e s t o f t h p r o g r a m . T h i s p r o g r a m w i l lb u s e d i t h e f o l l o w i n g c h a p t e r s t i l l u s t r a t e t h u s o t h o t h e rt o o l s . I i a l s o a e x a m p l e o f c r e a t i n g y o u r o w c u s t o m c h a r a c t e rs e t . I i r e c o m m e n d e d y o t r i t T h e f f e c t s a r u n u s u a l .

T h f o l l o w i n g i l i s t o t h c o m p l e t e p r o g r a m . T h i s l i s t i i t h f o r m a t p r o d u c e d b y u s i n g t h e L I S T o p t i o n a n p r i n t e r . I i n s e r t s s p a c e b e t w e e n t h m n e m o n i c a n t h o p e r a n d f o r e a d a b i l i t y .I a l s o l i n e s u t h c o m m e n t s f o r e a d a b i l i t y . W h e n k e y i n g t h ep r o g r a m r e m e m b e r n o t k e t h e x t r a s p a c e a n o n l y l e a v e o n e s p a c eb e t w e e n t h o p e r a n d a n t h c o m m e n t . l i t t l e p r a c t i c e a n i w i l lb e c o m e v e r y n a t u r a l .

Page 20: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 20/172

I r w i d t T h C o m m o d o r t 6 P a g t 1 - 1 0

S R D S S R C ED S T E

m

1 S T A R T1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 L O O P2 2 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 D O N E4 4 4 4 4 5

S A M P L EE Q E Q E Q E Q

E N T R YE Q L D S T L D S T L D S T L D S T L D A N S T L D A N S T L D L D L D P H T Y E O T A P L S T T Y E O T A

N B N D E B E I N I N J M L D O R S T L D O R S T R T

P R O G R A M2 5 2 5 $ D 0 € 0* C 8 0 0P O I N T < * C 0 0 0

* C 0 0 Ot » > S R C E4 - S R C + 1♦ K S R C E+ S R C* > D S T E< - D S T + 1♦ K D S T E< - D S T5 6 3 3 4f t * F E5 6 3 3 4# * F B1 * 1 * < S R C ) , Y

1 *

< D S T ) , Y* *

L O O PD O N E< - S R C - H< - D S T * lL O O P* * *

5 6 3 3 4M 5 6 3 3 4

S O U R C E V E C T O RD E S T V E C T O RO R I G C H A R S E N E C H A R S E T

4 9 1 5 2 )

B U I L D S O U R C EV E C T O R

A N D E S T V E C T O R

I N T E R R U P T S O F

I / O U T , R O I 1 C H A R M E P A G E SG E S O U R C E B Y T E

A N S A V E I

F L I P C H A R P A T T E RR E T R I E V E B Y T EA N S T O R E I

F I T H Y - R E GB U M P T H I N D E XA N D I A G A I NP A G E C O U N T D O W NI N C R E M E N T P A G E SO S R A N D E S TA N K E E P G O I N GR O O U T , I / I R E - E N A B L E

I N T E R R U P T SR E T U R N T O B A S I C

r

Page 21: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 21/172

I n s i d e T h C o m m o d o r e 6 P a g e i - i i

W h e n y o u h a v e c o m p l e t e d t h e n t r y o f t h e a b o v e p r o g r a m d o u b l ec h e c k i f o a c c u r a c y . O n c e y o u h a v e m a d e a n n e c e s s a r y m o d i f i c a t i o n st h s o u r c e p r o g r a m s h o u l d b e s a v e d .

S a v i n g s o u r c e p r o g r a m

I t h m a i n m e n u , o p t i o n 6 i s e l e c t e d t o s a v e a s o u r c ep r o g r a m . O n c e t h S A V E s u b - p r o g r a m i e n t e r e d * y o w i l l b a s k e dw h e t h e r y o w i s h t s a v e a s o u r c e o a b i n a r y f i l e . T h d e f a u l t a n t h c o r r e c t r e p l y h e r e i s o u r c e ( " S " ) . H i t t i n g C R w i l l c a u s es o u r c e f i l e t b s a v e d . Y o w i l l n e x t b e a s k e d w h e t h e r y o u w a n t t s a v e y o u r s o u r c e p r o g r a m t t a p e o d i s k . R e p l y a s i a p p r o p r i a t e f o y o u r s y s t e m . F i n a l l y * y o w i l l b p r o m p t e d f o r t h e n a m e y o w i s h t a s s i g n t t h f i l e . W h a t e v e r n a m e y o g i v e * D e v e l o p - 6 4 w i l la u t o m a t i c a l l y a p p e n d t h s u f f i x o f " . S R C " W h e n r e - l o a d i n g t h s a m ef i l e i t h e f u t u r e y o w i l l o n l y b r e q u i r e d t s p e c i f y t h b a s e n a m e tn o t h s u f f i x . O b j e c t f i l e s * w h e n s a v e d o u o f t h e a s s e m b l e r s u bp r o g r a m w i l l b c r e a t e d w i t h t h s u f f i x o " . O B J " . N o t e t h a t e i t h e rt y p e o s a v e w i l l c a u s e a n y p r e v i o u s v e r s i o n b y t h s a m e n a m e a n w i t ht h s a m e s u f f i x t b d e l e t e d a n r e p l a c e d b y t h f i l e y o a r n o c r e a t i n g .

Page 22: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 22/172

I n t i d t T h C o m m o d o r t 6 P t Q t 2 -

U s i n g D e v e l o p — 6 4 I P r e p a r i n g t u s t h a s s e m b l e r

T h a s s e m b l e r s u b - p r o g r a m w i l l p r o c e s s a s o u r c e p r o g r a m a n p r o d u c e a o b j e c t p r o g r a m . T h o b j e c t p r o g r a m i t h m a c h i n e l a n g u a g ew h i c h i t h u l t i m a t e o b j e c t i v e o f w r i t i n g a a s s e m b l y l a n g u a g ep r o g r a m . T h s o u r c e p r o g r a m m u s t b i D e v e l o p - 6 4 ' s s o u r c e p r o g r a ma r e a . s o u r c e p r o g r a m m a g e i n t o t h s o u r c e p r o g r a m a r e a v i t h e d i t o r , d e c o d e r a n d l o a d e r s u b p r o g r a m s . I t h p r e v i o u s c h a p t e r t h u s o t h e e d i t o r t o c r e a t e a s a m p l e s o u r c e p r o g r a m w a d e s c r i b e d . I t h s o u r c e p r o g r a m i s t i l l i t h e s o u r c e p r o g r a m a r e a y o m a n o a s s e m b l e i b s e l e c t i n g o p t i o n o f t h e m a i n m e n u . I n o t * y o w i l lh a v e t o c r e a t e a p r o g r a m w i t h t h e e d i t o r o r l o a d s a v e d s o u r c ep r o g r a m w i t h t h l o a d e r . T h p r o c e d u r e f o u s i n g t h e l o a d e r i g i v e nb e l o w .

L o a d i n g s o u r c e p r o g r a m

O p t i o n s e l e c t s t h e l o a d e r s u b - p r o g r a m . T h f i r s t q u e s t i o na s k e d i w h e t h e r y o u w i s h t l o a d s o u r c e o r o b j e c t f i l e . T h p o s s i b l e r e s p o n s e s a r " S a n " 0 " . " S i t h e d e f a u l t a n d y o u n e e do n l y h i C R 3 . Y o w i l l n o b g i v e n y o u r c h o i c e o f l o a d i n g t h e f i l ef r o m d i s k o t a p e ( D / T ) . R e s p o n d a p p r o p r i a t e l y f o y o u r s y s t e m . T h n e x t q u e s t i o n y o m u s t a n s w e r i w h a t f i l e n a m e D e v e l o p - 6 4 i s u p p o s e dt f i n d a n l o a d . W h e n s o u r c e f i l e s a r s a v e d w i t h t h e S A V E s u p r o g r a m , t h s u f f i x , " . S R C " i a u t o m a t i c a l l y a p p e n d e d t o t h e f i l e n a m ey o g a v e i t I i n o n e c e s s a r y t a d t h a t n o t t h f i l e n a m e t l o a d . T h l o a d e r w i l l a u t o m a t i c a l l y f i n d a n l o a d t h e f i l e w i t h t h n a m e y o s p e c i f i e d p l u s t h a p p e n d e d s u f f i x .

F i n a l l y » y o w i l l b e a s k e d w h e r e i t h s o u r c e p r o g r a m a r e a y o w i s h t h a v e t h s o u r c e p r o g r a m l o a d e d . T h a t i s a f t e r w h i c h l i n en u m b e r d o y o u w a n t t h f i l e i n s e r t e d . I y o a l r e a d y h a v e p r o g r a mi t h s o u r c e p r o g r a m a r e a a n d w a n t t h i s o n t o r e p l a c e i y o m u s tp r e c e d e t h e l o a d p r o c e s s w i t h " N E W 1 1 ( o p t i o n S ) I i p o s s i b l e t m e r g e m u l t i p l e s o u r c e f i l e s b y n o t N E W i n g b e t w e e n l o a d s . I t h i s c a s ey o m u s t t e l l D e v e l o p - 6 4 w h e r e y o w a n t e a c h f i l e i n s e r t e d a n d a s t h f i l e s a r l o a d e d t h e y w i l l b i n s e r t e d a c c o r d i n g l y , w i t h t h p r o g r a ma l r e a d y i t h s o u r c e a r e a b e i n g a u t o m a t i c a l l y r e n u m b e r e d t r e f l e c t

Page 23: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 23/172

I n s i d e T h C o m m o d o r e 6 P a g e 2 -

t h i n s e r t i o n .I t h c a s e o f l o a d i n g a p r o g r a m i n t o a n e m p t y s o u r c e p r o g r a m

a r e a * t h c o r r e c t r e s p o n s e t t h " I N S E R T A F T E R ? " q u e s t i o n i s " G " .O n c e t h p r o g r a m i l o a d e d t h l i s t m o d e o t h e e d i t o r s u b - p r o g r a mw i l l b a u t o m a t i c a l l y e n t e r e d .

A s s e m b l i n g t h s o u r c e p r o g r a m

T e n t e r t h e a s s e m b l e r s u b - p r o g r a m i i n e c e s s a r y t s e l e c to p t i o n " 3 o f t h e m a i n m e n u . T h - f i r s t q u e s t i o n y o m u s t a n s w e r i " D E C / H E X ( D / H ) ? Y o a r b e i n g a s k e d h o y o w i s h t s e t h g e n e r a t e dm a c h i n e l a n g u a g e d i s p l a y e d o t h a s s e m b l y l i s t i n g . T h t w p o s s i b l er e s p o n s e s a r e " D " a n " H " . A d d r e s s e s a n d d a t a w i l l b o t h b e d i s p l a y e di t h f o r m a t y o u s e l e c t . I y o h i C R t h e d e f a u l t v a l u e o " D f o d e c i m a l w i l l b u s e d . T h h e x a d e c i m a l c h o i c e c a u s e s t h a s s e m b l y t r u s o m e w h a t s l o w e r .

T h n e x t p r o m p t w i l l b " P O K E ? " I y o a n s w e r " Y t h g e n e r a t e d m a c h i n e l a n g u a g e p r o g r a m w i l l b P O K E d d i r e c t l y i n t o t h m e m o r y o f t h e c o m p u t e r . T h i s c a n b e d a n g e r o u s i t h m e m o r y a d d r e s s e sw h e r e t h p r o g r a m i d e s i g n a t e d t r e s i d e o v e r l a p t h m e m o r y s p a c ew h e r e D e v e l o p - 6 4 i t s e l f r e s i d e s . T h i s i c a l l e d s e l f - d e s t r u c t i o n a n w i l l n o g i v e p l e a s a n t r e s u l t s . T h e r e a r s e v e r a l w a y s t a v o i d t h i sp r o b l e m : i D e s i g n t h m a c h i n e l a n g u a g e p r o g r a m t r e s i d e i " s a c r e dR A M " s t a r t i n g a t $ C 0 e e ( 4 9 1 5 2 ) . 2 D o n ' t s e l e c t t h e P O K E o p t i o n . U s t h n e x t o p t i o n w h i c h c r e a t e s a " o b j e c t f i l e " w h i c h c a n t h e n b el o a d e d w i t h t h r e e s t a t e m e n t B A S I C p r o g r a m . 3 S e t h s t a r t a n d e n do D e v e l o p - 6 4 ' s a d d r e s s s p a c e t a d d r e s s e s w h i c h w i l l p r e c l u d e i f r o mb e i n g i t h s p a c e w h i c h w i l l b e o c c u p i e d b y t h e v e n t u a l m a c h i n el a n g u a g e p r o g r a m y o a r c r e a t i n g . T h i s i d o n e a t h v e r y b e g i n n i n go D e v e l o p - 6 4 .

A l t h e s e o p t i o n s a r e x p l a i n e d i m o r e d e t a i l i t h C h a p t e r5 F o t h s a m p l e p r o g r a m i d o e s n ' t m a t t e r h o y o r e s p o n d s i n c e t h p r o g r a m i s e u t r e s i d e i s a c r e d R A M .

T h n e x t q u e s t i o n , " C R E A T E O B J E C T ? " , i s a s k i n g w h e t h e rD e v e l o p - 6 4 s h o u l d b u i l d f i l e o t h m a c h i n e l a n g u a g e o u t p u t w h i c hc a t h e n b e l o a d e d l a t e r w i t h t h l o a d e r s u b - p r o g r a m . T h i s i c o n v e n i e n t w a o s a v i n g t h m a c h i n e l a n g u a g e p r o g r a m . T h l o a d e rs u b - p r o g r a m i v e r y s m a l l r o u t i n e w h i c h c o u l d b v e r y e a s i l y

Page 24: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 24/172

I n t i d t T h C o m m o d o r e 4 4 P a g e 2 -

i n c o r p o r a t e d i n t o B A S I C p r o g r a m . T h i s a l l o w s y o u o n e m e a n s o w r i t i n g a B A S I C p r o g r a m w h i c h h a m a c h i n e l a n g u a g e s u b r o u t i n e s . I t h n e x t c h a p t e r w w i l l p r e s e n t j u s t s u c h a B A S I C p r o g r a m w h i c h c a l l st h s a m p l e p r o g r a m . Y o s h o u l d a n s w e r " Y " t o t h i s q u e s t i o n i y o w i s h t f o l l o w t h s a m p l e p r o g r a m t h r o u g h t i t c o m p l e t i o n .

O n c e d o n e , t h n e x t q u e s t i o n i " D E V I C E ( D / T ) ? T h i s i a s k i n g y o w h e t h e r y o u w i s h t s a v e t h g e n e r a t e d m a c h i n e l a n g u a g eo b j e c t f i l e t t a p e o d i s k . A n s w e r a i a p p r o p r i a t e f o y o u rs y s t e m . N e x t , D e y e l o p - 6 4 w a n t s t k n o w w h a t y o w a n t t c a l l t h f i l e . W h a t e v e r y o r e s p o n d t " F I L E N A M E ? t h a c t u a l n a m e a s s i g n e dw i l l h a v e t h s u f f i x o " . O B J " a u t o m a t i c a l l y a p p e n d e d . Y o m a p i c ka n n a m e y o u w i s h b u t h p r o g r a m g i v e n i t h n e x t c h a p t e r a s s u m e sf i l e n a m e o " S A M P L E " .

F i n a l l y > D e v e l o p - 6 4 w i s h e s t K n o w i y o w a n t t h a s s e m b l yl i s t i n g t g t o p r i n t e r . I y o a n s w e r " Y t h l i s t i n g w i l l g o n l y t t h p r i n t e r . I y o a n s w e r " N t h l i s t i n g w i l l b d i s p l a y e do t h s c r e e n o n l y .

W h e n t h i s f i n a l o p t i o n i s e l e c t e d * D e v e l o p - 6 4 w i l l d i s p l a y t h em e s s a g e " N O W A S S E M B L I N G " a n t h f i r s t p a s s o f t h e a s s e m b l e r w i l lc o m m e n c e . W h e n c o m p l e t e d , t h a s s e m b l y l i s t i n g w i l l b e g i n t a p p e a ro t h e s e l e c t e d l i s t i n g d e v i c e . O t h s c r e e n , t h s o u r c e l i n e w i l la p p e a r f i r s t , f o l l o w e d b t h m a c h i n e l a n g u a g e w h i c h t h a s s e m b l e rc r e a t e d . T h l i n e n u m b e r s w i l l a p p e a r o n t h s e c o n d l i n e a l o n g w i t ht h m a c h i n e l a n g u a g e . T h m a c h i n e l a n g u a g e i v i s u a l l y s e p a r a t e d f r o mt h s o u r c e b b e i n g d i s p l a y e d o t h s c r e e n i r e v e r s e a n d o n t h p r i n t e r t t h r i g h t o f t h s o u r c e s t a t e m e n t . E r r o r s a r d i s p l a y e db o t h o t h e p r i n t e d l i s t i n g a n i r e v e r s e r e o t h e s c r e e n ,a c c o m p a n i e d b w a r n i n g " b e e p " .

E r r o r m e s s a g e s

T h e r e a r e f o u r e r r o r s w h i c h t h a s s e m b l e r r e c o g n i z e s . E a c h i d i s p l a y e d o t h l i n e w i t h t h g e n e r a t e d m a c h i n e l a n g u a g e i t h f o r m a t : " E R R F I E L D " w h e r e t h n u m b e r a f t e r t h E R m a b 3 , 4 , o

a n F I E L D w i l l b t h e a c t u a l d a t a t h a s s e m b l e r f o u n d i e r r o r .

E R m e a n s l a b e l s p e c i f i e d i a n o p e r a n d c a n n o t b f o u n da n y w h e r e i t h s o u r c e p r o g r a m . E R c a a l s o o c c u r o t h f i r s t p a s so t h a s s e m b l e r a n s i g n i f i e s t h a t a E Q s t a t e m e n t h a l a b e l i t h o p e r a n d f i e l d w h i c h h a n o y e b e e n e n c o u n t e r e d i t h s o u r c e

Page 25: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 25/172

I n m i d t T h C o m m o d o r f i 6 4 p A g t 2 - 4

p r o g r a m .

E R m e a n s a r e l a t i v e b r a n c h i n s t r u c t i o n s u c h a B N o r B P i n s t r u c t i o n i a t t e m p t i n g t o s p e c i f y a b r a n c h t a n a d d r e s so u t s i d e t h r a n g e o t h i n s t r u c t i o n .

B R m e a n s a i n v a l i d c h a r a c t e r h a b e e n e n c o u n t e r e d i h e x a d e c i m a l t e r m o a n a d d r e s s e x p r e s s i o n .

B R m e a n s t h a t a a d d r e s s h a s b e e n s p e c i f i e d w h i c h i o u o t h r a n g e o - 6 5 5 3 6 t 6 5 5 3 5 .

F o d e t a i l e d d e s c r i p t i o n s o f t h e s p e c i f i c a t i o n s f o r w r i t i n gv a l i d a s s e m b l y l a n g u a g e p r o g r a m s s e C h a p t e r 1 0

W h i l e t h l i s t i n g i b e i n g g e n e r a t e d » i i p o s s i b l e t p a u s ei b h i t t i n g a n k e y . I t h e K e y h i t i s C F U , t h a s s e m b l y w i l lt e r m i n a t e a n t h m a i n m e n u w i l l r e a p p e a r . O n c e i h a b e e n p a u s e d *y o m a c o n t i n u e b h i t t i n g a n K e e x c e p t C R 3 . H i t t i n g C R w i l lc a u s e t h m a i n m e n u t r e a p p e a r . Y o u m a y a a n t i m e r e - a s s e m b l e b r e - s e l e c t i n g o p t i o n o t h m a i n m e n u . I y o u h a v e n o s e l e c t e di n s e r t , d e l e t e o r m o d i f y o p t i o n s o f t h e e d i t o r o r h a v e n o d o n es o u r c e f i l e l o a d s i n c e t h e l a s t a s s e m b l y ! t h f i r s t p a s s w i l l b b y p a s s e d , a l l o w i n g s p e e d i e r a s s e m b l y .

I y o h a v e a c t u a l l y c r e a t e d t h s a m p l e p r o g r a m a n a s s e m b l e di t s e l e c t i n g p r i n t e r o u t p u t , y o s h o u l d h a v e r e c e i v e d p r o g r a ml i s t i n g s i m i l a r t o t h e f o l l o w i n g l i s t i n g .

Page 26: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 26/172

I n t i d t T h C o m m o d o r t 6 P t g t 2 - 5

F R E N C H S I L K D E V E L Q P - 6 4 A S S E M B L Y L I S T I N G

S R D S S R C ED S T E

1 S T A R T1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 L O O P2 2 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 D O N E4 4 4 4 4 5

S A M P L E P R O G R A M

E Q 2 5 E Q 2 5 E Q * D 6 8 8E Q U * C 8 8 8

E N T R Y P O I N T ( * C 8 8 8E Q U S C 8 8 8L D f t > S R C ES T « - S R C * lL D f t < S R C ES T 4 - S R CL D f t > D S T ES T < - D S T + lL D f t < D S T ES T « - D S TL D 5 6 3 3 4A N f t * F ES T 5 6 3 3 4L D 4 - A N f t * F BS T « - L D X M 8L D f t L D A < S R C ) , YP H T Y E O f t T A P L S T A < D S T ) , YT Y E O f t T A I N B N E L O O PD E B E Q D O N EI N < - S R C + lI N 4 - D S T + lJ M L O O PL D 4 - O R f t S T < - L D A 5 6 3 3 4O R f t S T 5 6 3 3 4R T

S O U R C E V E C T O RD E S T V E C T O RO R I G C H A R S E N E C H A R S E

4 9 1 5 2 )

B U I L D S O U R C EV E C T O R .

A N D E S T V E C T O R

I N T E R R U P T S O F F

I / O U T , R O I f C H A R M E P A G E S

G E T S O U R C E B Y T EA N S A V E I

F L I P C H A R P A T T E R NR E T R I E V E B Y T EA N S T O R E I F I T H E Y - R E GB U M P T H E I N D E XA N D I A G A I NP A G E C O U N T D O W N

I N C R E M E N T P A G E SO S R A N D E S TA N D K E E P G O I N GR O O U T , I / I R E - E N A B L E

I N T E R R U P T SR E T U R N T B A S I C

2 5 2 5 5 3 2 4 85 1 2 8 8

4 9 1 5 24 9 1 5 24 9 1 5 44 9 1 5 64 9 1 5 84 9 1 6 84 9 1 6 24 9 1 6 44 9 1 6 64 9 1 6 84 9 1 7 14 9 1 7 34 9 1 7 64 9 1 7 84 9 1 8 84 9 1 8 24 9 1 8 44 9 1 8 64 9 1 8 84 9 1 8 94 9 1 9 84 9 1 9 24 9 1 9 34 9 1 9 44 9 1 9 64 9 1 9 74 9 1 9 94 9 2 8 84 9 2 8 14 9 2 8 34 9 2 8 44 9 2 8 64 9 2 8 84 9 2 1 84 9 2 1 34 9 2 1 54 9 2 1 74 9 2 1 94 9 2 2 24 9 2 2 44 9 2 2 7

1 6 2 8 1 3 2 5 1 6 1 3 2 5 1 6 9 2 8 61 3 2 5 1 6 1 3 2 5 1 7 1 2 2 4 2 5 1 4 1 2 2 1 6

4 2 5 1 3 1 6 1 6 1 7 2 5 7 1 5 7 1 6 1 8 1 4 2 5 1 5 7 1 6 2 8 2 8 8 2 3 92 8 2 4 2 3 2 5 2 3 2 5 7 3 1 9 1 6 1 3 1 7 1 2 2 1 4 1 1 4 2 2 9

Page 27: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 27/172

I n s i d e T h C o m m o d o r e 6 4 P a g e 2 -

I y o d i n o s e l e c t t h p r i n t e r o p t i o n * t h l i s t i n g y o g o o t h s c r e e n s h o u l d h a v e b e e n s i m i l a r * e x c e p t t h a t t h e m a c h i n el a n g u a g e i o l i n e b i t s e l f . I t h e r e a r a n d i f f e r e n c e s *p a r t i c u l a r l y i t h m a c h i n e l a n g u a g e p o r t i o n o f t h e l i s t i n g * t h e r e i s o m e t h i n g s i g n i f i c a n t l y w r o n g w i t h y o u r s o u r c e p r o g r a m . I y o r e c e i v e d e r r o r s w h i l e a s s e m b l i n g y o m u s t f i n d t h s o u r c e o y o u rm i s t a k e * u s t h e d i t o r t c o r r e c t i a n g b a c k a n d r e - a s s e m b l e .O n c e i l o o k s r i g h t * p r o c e e d t o t h e n e x t c h a p t e r .

Page 28: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 28/172

I n t i d t T h C o m m o d o r t 6 4 P a g e 2 - 7

I y o d i n o s e l e c t t h p r i n t e r o p t i o n , t h l i s t i n g y o g o o t h s c r e e n s h o u l d h a v e b e e n s i m i l a r , e x c e p t t h a t t h e m a c h i n el a n g u a g e i o l i n e b i t s e l f . I t h e r e a r a n d i f f e r e n c e s ,p a r t i c u l a r l y i t h m a c h i n e l a n g u a g e p o r t i o n o f t h e l i s t i n g , t h e r e i s o m e t h i n g s i g n i f i c a n t l y w r o n g w i t h y o u r s o u r c e p r o g r a m . I y o r e c e i v e d e r r o r s w h i l e a s s e m b l i n g y o m u s t f i n d t h s o u r c e o y o u rm i s t a k e , u s t h e d i t o r t c o r r e c t i a n g b a c k a n d r e - a s s e m b l e .O n c e i l o o k s r i g h t , p r o c e e d t t h n e x t c h a p t e r .

Page 29: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 29/172

I n s i d e T h C o m m o d o r e 6 P a g e 3 -

U s i n g D e v e l o p - 6 4 I I L o a d i n g a n d r u n n i n g t h m a c h i n e l a n g u a g e p r o g r a m

I y o u h a v e c r e a t e d a n a s s e m b l e d t h s a m p l e p r o g r a m d e s c r i b e di t h p a s t t w c h a p t e r s a n h a v e c r e a t e d a o b j e c t f i l e a d e s c r i b e dy o c a n o u s t h f o l l o w i n g B A S I C p r o g r a m t l o a d a n r u t h p r o g r a m . N o t e t h a t t h f i r s t t w l i n e s o t h p r o g r a m a r w r i t t e nf o t h d i s k u s e r b u t h c a s s e t t e u s e r c a e l i m i n a t e l i n e 7 a n c h a n g e l i n e 5 t o O P E N i , i , e , " S A M P L E . O B J "

0 P E N l , 8 , 2 , n 8 : S A M P L E . 0 B J , S "C L 0 S E 1 5 : 0 P E N 1 5 , 8 , 1 5 : I N P U T t t l 5 , A , B * , C , D : I F T H E NP R I N T A , B * , C , D : C L Q S E l : C L 0 S E 1 5 : S T 0 P

1 I N P U T # 1 , N : I F N = - 1 8 0 8 T H E N C L O S E 1 s G O T O 3 02 I N < T H E N P O K E P , - N : P = P + l : G 0 T 0 1 82 P = N : 6 0 T 0 1 83 P O K E 6 4 8 , 1 9 6 : P O K E 5 6 5 7 8 , P E E K < 5 6 5 7 8 ) O 3

P O K E 5 6 5 7 6 , P E E K < 5 6 5 7 6 ) A N D 2 5 2 : S Y 4 9 1 5 24 P O K E 5 3 2 7 2 , < P E E K < 5 3 2 7 2 ) A N 2 4 8 ) O 5 P R I N T " C C L R 3 M I R R O R , M I R R O R O T H C E I L I N G "

I i a s s u m e d t h a t t h n a m e y o g a v e t t h f i l e w h e n t h a s s e m b l e r s u b - p r o g r a m a s K e d f o f i l e n a m e w a " S A M P L E " . I i w a s o m e t h i n g e l s e , s u b s t i t u t e t h a t f o " S A M P L E " i n l i n e 5

T h t h r e e P O K E S i n l i n e 3 a r s e t - u p p r e l i m i n a r i e s i p r e p a r a t i o n f o r u n n i n g t h m a c h i n e l a n g u a g e p r o g r a m . T h e y c o u l d h a v ej u s t a e a s i l y b e e n d o n e i t h m a c h i n e l a n g u a g e p r o g r a m . C h a p t e r 1 o g r a p h i c s p r o g r a m m i n g e x p l a i n s i d e t a i l t h p r o c e s s w h i c h i b e i n gp e r f o r m e d h e r e .

T h j u m p i n t o t h m a c h i n e l a n g u a g e p r o g r a m i a c c o m p l i s h e d b t h S Y 4 9 1 5 2 . N o t e t h a t t h f i r s t n o n - E Q U i n s t r u c t i o n i t h a s s e m b l y l a n g u a g e p r o g r a m h a s a a d d r e s s o 4 9 1 5 2 ( $ C 0 0 0 ) . T h i s i t h f i r s t e x e c u t a b l e s t a t e m e n t o t h p r o g r a m . I i c a l l e d t h e n t r yp o i n t o f t h e p r o g r a m . I t a d d r e s s w a d e t e r m i n e d b t h E Q

Page 30: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 30/172

I n s i d e T h C o m m o d o r e 6 P a g e 3 -

i m m e d i a t e l y p r e c e d i n g i t A e x p l a i n e d i C h a p t e r 1 0 t h a d d r e s s i R A w h e r e t h m a c h i n e l a n g u a g e p r o g r a m g e t s P O K E d i s e e a c h t i m e a E Q i e n c o u n t e r e d i t h s o u r c e p r o g r a m . T h e a s s e m b l e r w r i t e s t h a d d r e s s e x p r e s s e d i t h E Q t t h f i l e a p o s i t i v e d e c i m a ln u m b e r . I w r i t e s t h b y t e s o m a c h i n e l a n g u a g e t b P O K E d a n e g a t i v e n u m b e r s . T h l i t t l e l o a d e r r o u t i n e t h u s c a n i d e n t i f y e v e r yE Q a n c h a n g e t h a d d r e s s a w h i c h t o s t a r t P O K E i n g s u b s e q u e n tm a c h i n e l a n g u a g e .

T h P O K E i n l i n e 4 o f t h e B A S I C p r o g r a m c o u l d a l s o h a v e b e e ni n c l u d e d i t h m a c h i n e l a n g u a g e p r o g r a m . I t f u n c t i o n i a l s oe x p l a i n e d i C h a p t e r i t h s e c t i o n l a b e l e d m u l t i p l e c h a r a c t e rs e t s .

I a l w e n t a p l a n n e d , t h e r e s u l t s o r u n n i n g t h a b o v ep r o g r a m s h o u l d b e a p p a r e n t . A l s c r e e n o u t p u t f r o m n o o w i l l a p p e a ru p s i d e d o w n . ( T r y l i s t i n g t h B A S I C p r o g r a m , f o e x a m p l e ) . Y o m a e s c a p e f r o m t h i s m o d e o n l y b t u r n i n g t h m a c h i n e o f o b t y p i n gS Y 6 4 7 3 8 C R 3 o b y d o i n g s o m e P O K E s t s w i t c h t h c h a r a c t e r s e t b a c kt i t u s u a l s t a t e .

I t h p r o g r a m d i n o s e e m t w o r k a a d v e r t i s e d * y o w i l ln e e d t b a c k u p a n d t r t f i n d t h e r r o r . P l e a s e , b e f o r e c a l l i n g t h a u t h o r , d y o u r b e s t t t r t f i n d t h p r o b l e m . L o o k f o d i s c r e p a n c i e s b e t w e e n y o u r s o u r c e p r o g r a m a n t h a t l i s t e d i t h e b o o k .I y o g o a e r r o r m e s s a g e o t r y i n g t o l o a d t h e o b j e c t f i l e , f i n do u w h y . G b a c k a n d r e - a s s e m b l e i o t h e r s t r a n g e t h i n g s o c c u r .S e l e c t t h P O K E o p t i o n a n d t h e n u s e t h d e c o d e r s u b - p r o g r a m , d e s c r i b e db e l o w , t d e c o d e t h m a c h i n e l a n g u a g e t c o m p a r e t h g e n e r a t e da s s e m b l y l a n g u a g e w i t h t h o r i g i n a l s a m p l e p r o g r a m . ( N o t e : t h l i s t i n g o t h s a m p l e p r o g r a m g i v e n i t h i s b o o k c a m e d i r e c t l y f r o mD e v e l o p - 6 4 a n D O E S w o r k . I i a l s o h i g h l y u n l i k e l y t h a t C o m m o d o r eh a m a d e c h a n g e i t h d e s i g n o t h 6 4 w h i c h w i l l c a u s e t h s a m p l ep r o g r a m t b i n e f f e c t i v e . )

O t h o t h e r h a n d , i y o h a v e e x h a u s t e d a l o t h e rp o s s i b i l i t i e s a n i c e r t a i n l y a p p e a r s t h a t s o m e t h i n g i a m i s s , p l e a s es e n d u s a c o p y o y o u r D e v e l o p - 6 4 , w r i t t e n d e s c r i p t i o n o t h p r o b l e m , a n d a n y o t h e r r e l e v a n t i n f o r m a t i o n a n d d a t a f i l e s w h i c h c a a s s i s t u i f i n d i n g t h s o u r c e o t h p r o b l e m .

Page 31: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 31/172

I n s i d e T h C o m m o d o r e 6 P a g e 3 -

D e c o d i n g t h p r o g r a mN o t h a t y o h a v e w o r k i n g c o p y o t h s a m p l e p r o g r a m i

m e m o r y i w o u l d b g o o d t i m e t s e w h a t t h d e c o d e r c a n d f o y o u .I y o j u s t r a t h s a m p l e B A S I C p r o g r a m w h i c h l o a d e d a n r a t h m a c h i n e l a n g u a g e p r o g r a m y o c a n g e t b a c k t n o r m a l c h a r a c t e r s w i t h o u tl o s i n g t h m a c h i n e l a n g u a g e p r o g r a m b t y p i n g S Y 6 4 7 3 8 . I t h m a c h i n e l a n g u a g e p r o g r a m i n o i m e m o r y y o s h o u l d p u t i t h e r e b ya s s e m b l i n g t h s o u r c e p r o g r a m a n s e l e c t i n g t h e P O K E o p t i o n t o P O K Et h o u t p u t i n t o m e m o r y a t h p r o g r a m i b e i n g a s s e m b l e d .

L o a d a n r u D e v e l o p - 6 4 . S e l e c t t h d e c o d e r o p t i o n o f t h e m a i nm e n u * o p t i o n 4 Y o u r n e x t m e n u w i l l b e

1 E X I T 2 P R I N T E R 3 S C R E E N 4 I N S E R T

A l t h r e e o p t i o n s t d e c o d e m a c h i n e l a n g u a g e w i l l c a u s e t h g e n e r a t e d a s s e m b l y l a n g u a g e t a p p e a r o t h s c r e e n . I o p t i o n i s e l e c t e d t h o u t p u t w i l l g t y o u r p r i n t e r a w e l l . I o p t i o n i s e l e c t e d t h l i n e s o a s s e m b l y l a n g u a g e w i l l b e i n s e r t e d i n t o t h s o u r c e p r o g r a m a r e a w h e r e t h e y m a b e m o d i f i e d a n d / o r a s s e m b l e d a n d / o rs a v e d . I i n s e r t i s e l e c t e d t h e " I N S E R T A F T E R ? p r o m p t w i l l b g i v e n a n d y o m u s t t e l l D e v e l o p - 6 4 w h e r e y o w a n t t h e s o u r c e i n s e r t e di t h e c u r r e n t s o u r c e p r o g r a m . I t h e r e i a l r e a d y p r o g r a m i t h s o u r c e p r o g r a m a r e a a n y o w a n t t h i s o n t o r e p l a c e i t * i t w i l l b n e c e s s a r y t c l e a r t h e a r e a w i t h t h N E o p t i o n ( 8 o t h m a i n m e n ub e f o r e p r o c e e d i n g w i t h t h d e c o d e r s u b - p r o g r a m .

I e v e r y c a s e , t h e f i r s t p r o m p t w i l l b " D E C / H E X ( D / H ) ? " a s k i n g w h e t h e r t h g e n e r a t e d s o u r c e s h o u l d h a v e a d d r e s s e s a n d d a t a i h e x a d e c i m a l o d e c i m a l f o r m a t . H e c a u s e s t h d e c o d e r t r u a b o u tt w i c e a s l o w a s d e c i m a l .

T h n e x t p r o m p t w i l l b " S T A R T , E N ? • ' , a s k i n g f o t h a d d r e s s e s i m e m o r y b e t w e e n w h i c h y o u w o u l d l i k e t d e c o d e . Y o u m a yg i v e y o u r a n s w e r s i e i t h e r h e o d e c i m a l . H e v a l u e s m u s t b p r e c e d e d b a " $ " . T h e n p o i n t m a b e x p r e s s e d a d a t a v a l u ei n s t e a d o a a d d r e s s . B p r e c e d e i n g t h d a t a v a l u e w i t h " # " , t h d e c o d e r w i l l b d i r e c t e d t d e c o d e u n t i l i r e c o g n i z e s t h s p e c i f i e dd a t a v a l u e i t h o p - c o d e o a i n s t r u c t i o n . F o e x a m p l e , i y o w a n t t d e c o d e u n t i l t h e n o s u b r o u t i n e , y o c o u l d s p e c i f y a e n a d d r e s s o # 9 o # $ 6 8 w h i c h w i l l c a u s e t h d e c o d e r t d e c o d e u n t i l i e n c o u n t e r s R T i n s t r u c t i o n ( v a l u e o 9 o $ 6 0 ) .

Page 32: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 32/172

I n t i d t T h C o m m o d o r t 6 P a g t 3 -

I y o u h a v e t h s a m p l e m a c h i n e l a n g u a g e p r o g r a m i m e m o r y y o m a n o d e c o d e i t F o t h p u r p o s e s o f t h i s d e m o n s t r a t e d , s e l e c to p t i o n t I N S E R T . A n s w e r " 0 t o t h e " I N S E R T A F T E R ? 1 1 . S p e c i f ys t a r t i n g a d d r e s s o $ C 0 0 0 a n a e n d i n g a d d r e s s o # $ 6 0 , t h o p - c o d ef o t h R T i n s t r u c t i o n .

T h g e n e r a t e d o u t p u t s h o u l d l o o k v e r y m u c h b u t n o t e x a c t l y l i k et h o r i g i n a l s o u r c e p r o g r a m w h i c h c r e a t e d i t T h d i f f e r e n c e s a r e d u t t h f a c t t h a t t h e d e c o d e r c a n o c r e a t e c o m m e n t s . N o d o e s i g e n e r a t e l a b e l s .

T h d e c o d e r s u b - p r o g r a m c a d e c o d e a n m e m o r y b l o c k i t h c o m p u t e r , i n c l u d i n g t h o p e r a t i n g s y s t e m . I c a a l s o d e c o d ec a r t r i d g e s i t h c a r t r i d g e i a c t i v a t e d a f t e r p o w e r - o n . T h r e a s o nf o r t h i s e x c e p t i o n i t h a t i c a r t r i d g e i s i n p l a c e w h e n t h p o w e ri t u r n e d o t h p o w e r - u p p r o g r a m i t h c o m p u t e r w i l l a u t o m a t i c a l l yg i v e c o n t r o l t o t h e p r o g r a m i t h c a r t r i d g e . S i n c e m o s t c a r t r i d g e sw i l l n o a l l o w a n m e a n s o f g i v i n g c o n t r o l b a c k t a n o t h e r p r o g r a mt h e r e i n w a f o D e v e l o p - 6 4 t b r u n . T h e m o s t c o m m o n w a t d e f e a t t h i s i t h a v e t h c a r t r i d g e p l u g g e d i n t o a e x p a n s i o n c h a s s i sw h i c h h a s w i t c h e s w h i c h a c t i v a t e a n d e - a c t i v a t e t h e c a r t r i d g e s w h i c ha r p l u g g e d i n t o i t T h e n t h p r o c e d u r e i t p o w e r - u p w i t h t h c a r t r i d g e d e - a c t i v a t e d , l o a d a n r u D e v e l o p - 6 4 , t h e n a c t i v a t e t h ec a r t r i d g e . S i n c e t h o n l y t i m e c o n t r o l i p a s s e d t o t h e c a r t r i d g e i a p o w e r - u p , t h c a r t r i d g e i n o n o i c o n t r o l , y e i i a d d r e s s a b l e b t h d e c o d e r . T h e r e a r s o m e c a r t r i d g e s w h i c h a r d e s i g n e d t c a u s e B A S I C t b e " s w i t c h e d o u t " w h e n t h e y a r a c t i v a t e d .T h e s e c a r t r i d g e s m a n o b p o s s i b l e t d e c o d e w i t h D e v e l o p - 6 4 .

A m a t t e r o c u r i o s i t y , y o c o u l d n o e x i t t h d e c o d e r a n e n t e r t h a s s e m b l e r a n r e - a s s e m b l e t h d e c o d e d p r o g r a m . T h m a c h i n el a n g u a g e w h i c h i g e n e r a t e d w i l l b e x a c t l y t h e s a m e a t h m a c h i n el a n g u a g e w h i c h w a g e n e r a t e d f r o m t h o r i g i n a l s o u r c e p r o g r a m .

B e l o w i l i s t i n g o t h r e - a s s e m b l e d o u t p u t o t h d e c o d e r .N o t e t h a t t h e g e n e r a t e d m a c h i n e l a n g u a g e f r o m t h a s s e m b l e r i i d e n t i c a l t o t h g e n e r a t e d m a c h i n e l a n g u a g e o t h e o r i g i n a l a s s e m b l y .

Page 33: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 33/172

I n t i d t T h C o m m o d o r t 6 P a g t 3 -

F R E N C H S I L K D E V E L O P - 6 4 A S S E M B L Y L I S T I N G

i

1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 4 4

E Q L D S T L D S T L D S T L D S T

L D A N S T L D A N S T L D L D L D P H T Y E O T A P L S T T Y E O T A

N B N D E B E I N I N J M L D O R S T L D O R S T R T

4 9 1 5 2# 2 0 8< - 2 5 2# ♦ - 2 5 1# 2 0 0< - 2 5 41 * ♦ • 2 5 3

5 6 3 3 4# 2 5 45 6 3 3 44 - # 2 5 1♦ • # # ( 2 5 1 ) , Y

#

( 2 5 3 ) , Y#

3 - 1 53 + 4 - 2 5 2♦ • 2 5 44 9 1 8 6♦ - #

5 6 3 3 4# 5 6 3 3 4

4 9 1 8 64 9 2 1 3

4 9 1 5 24 9 1 5 24 9 1 5 44 9 1 5 64 9 1 5 84 9 1 6 04 9 1 6 24 9 1 6 44 9 1 6 6

4 9 1 6 84 9 1 7 14 9 1 7 34 9 1 7 64 9 1 7 84 9 1 8 04 9 1 8 24 9 1 8 44 9 1 8 64 9 1 8 84 9 1 8 94 9 1 9 04 9 1 9 24 9 1 9 34 9 1 9 44 9 1 9 64 9 1 9 74 9 1 9 94 9 2 0 04 9 2 0 14 9 2 0 34 9 2 0 44 9 2 0 64 9 2 0 84 9 2 1 04 9 2 1 34 9 2 1 54 9 2 1 74 9 2 1 94 9 2 2 24 9 2 2 44 9 2 2 7

1 6 2 0 1 3 3 2 5 21 6 1 3 2 5 t 6 2 0 1 3 3 2 5 41 6 1 3 3 2 5 3

1 7 1 2 2 4 2 5 1 4 1 1 4 2 2 1 6 4 2 5 1 3 1 6 1 6 1 7 2 5 7 1 5 7 1 6 1 0 1 4 2 5 1 5 7 1 6 2 0 2 0 2 3 2 0 2 4 2 3 2 5 2 3 0 2 5 47 3 1 9 1 6

1 3 1 7 1 2 2

1 4 1 2 2 9

Page 34: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 34/172

Page 35: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 35/172

I n s i d e T h C o m m o d o r e 6 P a g e 4 -

T h s a m p l e p r o g r a m e x p l a i n e d

A t h i s t i m e y o u c a n s e e t h " s l o w - m o t i o n " e x e c u t i o n o t h s a m p l e p r o g r a m . I y o d o n ' t K n o w m u c h a b o u t m a c h i n e l a n g u a g e o r t h ea r c h i t e c t u r e o f t h e 6 5 1 0 m i c r o p r o c e s s o r t h i s e x e r c i s e m a n o m a k el o o s e n s e t o y o u . Y o u m a y w a n t t s k i p a h e a d a n r e a d t h C h a p t e r s6 - t g a i n a n u n d e r s t a n d i n g o f t h e m a c h i n e . I c o u l d a l s o b h e l p f u lt j u s t w a l k t h r o u g h t h f o l l o w i n g e x p l a n a t i o n p r i o r t o h a v i n gf u l l e r u n d e r s t a n d i n g j u s t t f a m i l i a r i z e y o u r s e l f w i t h t h m e c h a n i c so u s i n g t h i s t o o l . E i t h e r w a y t i y o a r j u s t g e t t i n g s t a r t e d w i t hm a c h i n e l a n g u a g e > i i r e c o m m e n d e d y o r e t u r n t o t h i s c h a p t e r a f t e rh a v i n g s t u d i e d t h e f o l l o w i n g c h a p t e r s ,

K e " 2 i y o u w i s h t s i n g l e s t e p t h r o u g h t h s a m p l ep r o g r a m . A n s w e r t h " S T A R T A D D R " p r o m p t w i t h I C 0 0 0 , t h a d d r e s s o t h e n t r y p o i n t o t h p r o g r a m . T h f i r s t i n s t r u c t i o n o y o u r p r o g r a ms h o u l d n o a p p e a r o t h e s c r e e n .

A e a c h i n s t r u c t i o n i a b o u t t b e e x e c u t e d , i i d i s p l a y e d i b o t h m a c h i n e l a n g u a g e a n d i a s s e m b l y l a n g u a g e . T h p r o c e s s o r s t a t u s( P S ) r e g i s t e r i b r o k e n i n t o i t i n d i v i d u a l b i t s ( N n e g a t i v e ,o v e r f l o w , b r e a k m o d e , D e c i m a l m o d e , Z e r o , i n t e r r u p t si n h i b i t e d , = C a r r y ) . T h o t h e r r e g i s t e r s d i s p l a y e d a r e t h e A - r e g ,t h X - r e g , t h Y - r e g , a n t h e S t a c k P o i n t e r ( S P ) . U p o n e x e c u t i o n o e a c h i n s t r u c t i o n , t h r e g i s t e r s a r l o a d e d f r o m t h e s e s a v e a r e a s i m e m o r y :

A - 7 8 0 X 7 8 Y - 7 8 2 P S 1 4

I y o w i s h t m o d i f y o r p r e - i n i t i a l i z e a n o t h r e g i s t e r sa a n t i m e y o m a d o s o b e n t e r i n g t h M e m o r y - M o d i f y m o d e a n m o d i f y i n g t h a b o v e l o c a t i o n s .

I f w h i l e s i n g l e - s t e p p i n g t h r o u g h s o m e p r o g r a m , y o s h o u l de x e c u t e R T o P L o P L w i t h o u t f i r s t h a v i n g p u s h e d s o m e t h i n g o n t ot h s t a c k w i t h J S o P H o P H P , s t a c k u n d e r f l o w w i l l o c c u r .T X i n s t r u c t i o n s e t t i n g t h e S t s o m e o u t - o f - r a n g e v a l u e w i l l a l s oc a u s e s t a c k u n d e r f l o w . O v e r f l o w s a r c a u s e d b y r e p e t i t i v e P H A ' s P H P ' so J S R ' s w i t h o u t c o r r e s p o n d i n g P L A ' s P L P ' S o R T S ' s u n t i l t h m a x i m u ms t a c k d e p t h h a s b e e n e x c e e d e d . I t h e v e n t o u n d e r f l o w s a n o v e r f l o w s , " S T K E R R " m e s s a g e w i l l b d i s p l a y e d . E x e c u t i o n m a

Page 36: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 36/172

I n s i d e T h C o m m o d o r e 6 4 P * Q t 4 - 3

c o n t i n u e i d e s i r e d b u r e s u l t s a r e l i k e l y t b u n e x p e c t e d i y o u rm o n i t o r e d p r o g r a m i e x p e c t i n g t o f i n d s o m e s i g n i f i c a n t i n f o r m a t i o n i t h s t a c k ( l i k e a r e t u r n a d d r e s s ) .

C e r t a i n m a c h i n e l a n g u a g e p r o g r a m s a r e w r i t t e n t m o d i f y t h S t a c k d i r e c t l y b s t o r i n g d a t a i t h h i g h e n o p a g e i E x e c u t i n gt h e s e i n s t r u c t i o n s i d e b u g g i n g m o d e w i l l n o c a u s e t h d e s i r e d s t a c km o d i f i c a t i o n e f f e c t . I n f a c t , i i q u i t e l i k e l y t h a t D e v e l o p - 6 4 w i l la c t u a l l y c r a s h u p o n t h e x e c u t i o n o s u c h i n s t r u c t i o n s . S i n c e i i w r i t t e n p a r t i a l l y i B A S I C * a n i n s t r u c t i o n s w h i c h m o d i f y t h B A S I Cv e c t o r s o o t h e r i n f o r m a t i o n v i t a l t t h r u n n i n g o B A S I C p r o g r a m sm a a l s o c a u s e u n w a n t e d r e s u l t s .

A D e v e l o p - 6 4 s i n g l e s t e p s t h r o u g h a m a c h i n e l a n g u a g e p r o g r a m ,i c h e c k s e a c h o p - c o d e e n c o u n t e r e d f o v a l i d i t y . I a i n v a l i d o c o d e i e n c o u n t e r e d , t h m e s s a g e " O P - C O D E x x x " ( w h e r e x x i t h e n c o u n t e r e d o p - c o d e ) w i l l a p p e a r w h e r e t h m n e m o n i c w o u l d o t h e r w i s ea p p e a r . D e v e l o p - 6 4 w i l l n o t r t e x e c u t e i n v a l i d o p - c o d e s . N o w i l li t r t e x e c u t e B R o R T i n s t r u c t i o n s . A l o t h e s e w i l l b a u t o m a t i c a l l y b y p a s s e d .

I t h s a m p l e p r o g r a m i n o i m e m o r y a n d y o u h a v e s e l e c t e dt h s i n g l e - s t e p o p t i o n a n s p e c i f i e d a d d r e s s $ C 0 0 0 a t h s t a r t i n ga d d r e s s a n s e l e c t e d d e c i m a l a t h d i s p l a y f o r m a t , y o s h o u l d s e o t h s c r e e n t h a s s e m b l y l a n g u a g e s t a t e m e n t " L D A # 2 0 8 " f o l l o w e d b t h a d d r e s s 4 9 1 5 2 a n t h m a c h i n e l a n g u a g e e q u i v a l e n t o f t h e a b o v ea s s e m b l y l a n g u a g e s t a t e m e n t : 1 6 2 0 8 .

O t h n e x t l i n e w i l l b t h e d i s p l a y o f t h e r e g i s t e r s , t h A r e g , X - r e g , Y - r e g a n S P ( t h e s t a c k p o i n t e r ) , p r i o r t o t h e x e c u t i o n o t h d i s p l a y e d i n s t r u c t i o n . Y o w i l l a l s o s e t h s t a t u s r e g i s t e rd i s p l a y e d b r o k e n d o w n i n t o i t c o m p o n e n t b i t s , t h N e g a t i v e , o v e r f l o w ,B r e a k , D e c i m a l , I n t e r r u p t d i s a b l e , Z e r o a n C a r r y f l a g s . T h r e g i s t e r s w i l l h a v e n p a r t i c u l a r s i g n i f i c a n c e a t t h i s p o i n t b e c a u s et h e y w e r e n e v e r i n i t i a l i z e d . N o t e , h o w e v e r , t h e v a l u e o f t h e A - r e gb e c a u s e a f t e r e x e c u t i n g t h i n s t r u c t i o n i w i l l p r o b a b l y c h a n g e . T h Z e r o f l a g , i i i o n n o s h o u l d a l s o c h a n g e a r e s u l t o t h e x e c u t i o n o t h i n s t r u c t i o n . T h N e g a t i v e f l a g i a l s o a f f e c t e d b L D i n s t r u c t i o n .

N o t e t h d i s a s s e m b l e d s t a t e m e n t i n o i d e n t i c a l t t h a s s e m b l y l a n g u a g e s t a t e m e n t y o u o r i g i n a l l y w r o t e . I i e q u i v a l e n tb u t n o t i d e n t i c a l . T h o r i g i n a l s t a t e m e n t w a s : L D # > S R C E . T h i sd i s c r e p a n c y o c c u r s b e c a u s e T h M o n i t o r c a n ' t t e l l w h a t w e n t i n t o t h a s s e m b l e r , o n l y w h a t c a m e o u a n i d o e s t h b e s t i c a i

Page 37: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 37/172

I n s i d e T h C o m m o d o r e 6 P a g e 4 - 4

r e c o n s t r u c t i n g a v a l i d a s s e m b l y l a n g u a g e s t a t e m e n t f r o m t h m a c h i n el a n g u a g e i h a t w o r k w i t h .

T e x e c u t e t h i n s t r u c t i o n * h i r e t u r n . I a l i w e l l , t h n e x t i n s t r u c t i o n o f t h e s a m p l e p r o g r a m w i l l b d i s p l a y e d a n t h f i r s ti n s t r u c t i o n w i l l h a v e b e e n e x e c u t e d . Y o u m a y v e r i f y t h a t b c h e c k i n gt h A - r e g . I s h o u l d b o v a l u e 2 0 8 n o w . T h z e r o b i s h o u l d b b e c a u s e t h e r e s u l t o f l o a d i n g t h e A - r e g i n o n - z e r o . N o t e t h a t t h er e s u l t i n g v a l u e i t h A - r e g d o e s h a v e t h h i g h - o r d e r b i o ( i . e . t h n u m b e r i t h A - r e g i g r e a t e r t h a n 1 2 o r * 7 F ) . C o n s e q u e n t l y , t h N e g a t i v e f l a g s h o u l d n o b e t u r n e d o n T h n e x t i n s t r u c t i o n w h i c h i n o u f o e x e c u t i o n w i l l s t o r et h A - r e g i l o c a t i o n 2 5 2 . N o n e o t h s t a t u s f l a g s a r e a f f e c t e d b t h i s i n s t r u c t i o n s w s h o u l d s e n c h a n g e w h e n w e e x e c u t e i t P u s hC R a n s e e .

T h i s w o u l d b g o o d t i m e t l o o k a t h M e m o r y D i s p l a y / M o d i f ym o d e . R a t h e r t h a n h i C R a t t h i s t i m e , k e " C R T 1 .

U p o n e n t e r i n g t h i s m o d e , t h a d d r e s s w h e r e y o l e f t o f i s i n g l e - s t e p p i n g w i l l b s a v e d a n t h " S T A R T A D D R " p r o m p t w i l l b d i s p l a y e d . Y o m a e n t e r t h f i r s t a d d r e s s y o u w i s h t e x a m i n e o m o d i f y . T h a d d r e s s m a b i t h r a n g e 0 - 6 5 5 3 5 o $ 0 0 0 0 - $ F F F F . T ol o o k a t l o c a t i o n 2 5 2 , k e y a " 2 5 2 C R T 1 . T h a d d r e s s ( 2 5 2 ) w i l l b d i s p l a y e d f o l l o w e d b t h c o n t e n t s o t h s p e c i f i e d l o c a t i o n . I t h i sc a s e i s h o u l d b e 2 0 8 b e c a u s e t h a t i t h v a l u e w J u s t s t o r e d t h e r e .T h v a l u e o t h d a t a s t o r e d a t h r e q u e s t e d a d d r e s s w i l l b d i s p l a y e d a n d t h p r o m p t " V A L ? " w i l l f o l l o w . Y o m a d o n o t h r e et h i n g s . Y o m a e X i t t h M e m o r y m o d e b k e y i n g " C R T ' . Y o m a m o d i f y t h d i s p l a y e d l o c a t i o n b k e y i n g v a l u e i t h r a n g e 0 - 2 5 5 o $ 0 0 - $ F F . O r y o m a c o n t i n u e v i e w i n g t h n e x t s e q u e n t i a l m e m o r yl o c a t i o n s b h i t t n g C R ] .Y o m a n o c h a n g e t h c o n t e n t s o l o c a t i o n 2 5 i y o w i s h b k e y i n g s o m e n e v a l u e . T h n e x t l o c a t i o n w i l l n o b d i s p l a y e d ,m e m o r y l o c a t i o n 2 5 3 . N o t e i t c o n t e n t s a n d m o d i f y t h e m i y o w i s h .

T j u s t s c a n t h r o u g h m e m o r y , s i m p l y c o n t i n u e t h i C R e a c ht i m e a v a l u e i d i s p l a y e d . W h e n y o w i s h t r e t u r n t t h m a i n m e n u ,k e " C R ] " f o e x i t . O n c e t h i s h a s b e e n d o n e , t h e i n s t r u c t i o n y o l e f t o f a w i l l b r e d i s p l a y e d a l o n g w i t h t h m e n u . I y o m o d i f i e d l o c a t i o n 2 5 2 y o u s h t f u l d n o r e - e n t e r M - m o d e b y e n t e r i n g t h " 5 o p t i o n , a n d a d d r e s s 2 5 2 a g a i n . W h e n t h e v a l u e y o s t u c k i 2 5 i d i s p l a y e d , c h a n g e i b a c k t a n h i C R ] , a n w h e n l o c a t i o n 2 5 i

Page 38: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 38/172

I n s i d e T h C o m m o d o r e 6 P * g t 4 -

d i s p l a y e d , h i " C R 3 " t g e t o u t a g a i n .T h n e x t i n s t r u c t i o n i t h p r o g r a m i n o d i s p l a y e d . I i

L D i n s t r u c t i o n . N o t e t h r e g i s t e r s s t i l l h a v e t h s a m e c o n t e n t s a b e f o r e t h M - m o d e e x c u r s i o n . T h A - r e g w i l l b l o a d e d w i t h t h e v a l u e

b t h i n s t r u c t i o n t o b e x e c u t e d n e x t .T h i s p r o g r a m i s e t t i n g u a v e c t o r i l o c a t i o n s 2 a n d 2 5 2

o z e r o p a g e t a d d r e s s c h a r a c t e r R O a $ D 0 0 0 . l o o p i t h p r o g r a mw i l l s e q u e n t i a l l y m o v e c h a r a c t e r s f r o m t h a t a r e a i m e m o r y t a a r e aw h e r e a a l t e r n a t e c h a r a c t e r s e w i l l b b u i l t . H i C R 3 a n d s e t h n e x t i n s t r u c t i o n w h i c h i a S t o r e o t h A - r e g t o l o c a t i o n 2 5 1 . H i C R a g a i n . T h n e x t f o u r i n s t r u c t i o n s b u i l d a n o t h e r v e c t o r a 2 5 3 a n d2 5 4 . T h i s i t h e v e c t o r w h i c h p o i n t s t o t h e l o c a t i o n w h e r e t h n e c h a r a c t e r s e t w i l l r e s i d e . H i C R t e x e c u t e e a c h o t h e s ei n s t r u c t i o n s . Y o u m a y v e r i f y t h a t l o c a t i o n s 2 5 1 - 2 5 4 c o n t a i n t h ea d d r e s s e s o t h t w v e c t o r s b y g o i n g i n t o m e m o r y d i s p l a y m o d e i y o w i s h .

T h n e x t t h r e e i n s t r u c t i o n s c a u s e t h e t i m e r t b e t u r n e d o f f .L o c a t i o n 5 6 3 3 4 i o n o t h e r e g i s t e r s a s s o c i a t e d w i t h t h h a r d w a r et i m e r w h i c h i n t e r r u p t s t h C o m m o d o r e 6 6 t i m e s s e c o n d . A e x p l a i n e d i m o r e d e t a i l l a t e r , t h e c h a r a c t e r R O s t a r t i n g a $ D 0 0 0( 5 3 2 4 8 ) s h a r e s i t a d d r e s s s p a c e w i t h i n p u t / o u t p u t ( I / O ) r e g i s t e r s .T r e a d t h c h a r a c t e r R O M , i i n e c e s s a r y t s w i t c h t h I / o u a n s w i t c h t h R O i n T h o n l y p r o b l e m w i t h d o i n g t h i s i t h a t t h I / r e g i s t e r s a r u s e d i t h s e r v i c i n g o f i n t e r r u p t s . S o w h i l e t h I / i s w i t c h e d o u t t a c c e s s t h c h a r a c t e r R O t h t i m e r m u s t b t u r n e do f s o a s t d i s c o n t i n u e i n t e r r u p t s . O n o t h e t h i n g s t h o p e r a t i n gs y s t e m d o e s w h e n i p r o c e s s e s t h i n t e r r u p t s e v e r y 1 / 6 0 t o s e c o n di t p o l l t h K e y b o a r d t s e i a n K e y s h a v e b e e n p r e s s e d . S i n c ew n e e d t h a v e t h a t f u n c t i o n i n t a c t w h i l e r u n n i n g t h e d e b u g g e r , w c a n ' t r e a l l y a l l o w t h e i n t e r r u p t s t b d i s a b l e d . S i i n e c e s s a r yt b y p a s s t h i n s t r u c t i o n a t 4 9 1 7 3 w h i c h a c c o m p l i s h e s t h d i s a b l i n g .T h i s i w h e r e t h b y p a s s o p t i o n i u s e f u l . W h e n t h a t i n s t r u c t i o n i d i s p l a y e d , a b o u t t b e e x e c u t e d , p r e s s " 4 i n s t e a d o C R 3 .

T h s w i t c h i n g - i n o t h R O i a c c o m p l i s h e d i t h n e x t t h r e ei n s t r u c t i o n s . T h 6 5 1 0 , a e x p l a i n e d a t t h e e n o C h a p t e r 7 u s e sl o c a t i o n a s a n I / p o r t a n t h 2 - b i t c o n t r o l s w h e t h e r t h R O o t h I / r e g i s t e r s a r e s w i t c h e d i n T h A N # 2 5 1 i n s t r u c t i o na c c o m p l i s h e s t h e t u r n i n g o f f o f t h a t b i t . N o w , s i n c e w h a t l e a v et h e i n t e r r u p t s e n a b l e d , w c a n ' t s w i t c h o u t t h I / r e g i s t e r s s i n c et h e y a r u s e d i p r o c e s s i n g t h i n t e r r u p t s . I y o s h o u l d m a k e t h

Page 39: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 39/172

I n s i d e T h C o m m o d o r e 6 P a g e 4 -

m i s t a k e o e x e c u t i n g t h e i n s t r u c t i o n a t 4 9 1 8 0 t h c o m p u t e r w i l l h a n ga n t h e r e w i l l b n r e c o u r s e e x c e p t t t u r n i o f a n b a c k o n a g a i na n s t a r t o v e r .

N e x t , t h a n r e g i s t e r s a r s e u t c o u n t t h n u m b e r o t i m e s t h r o u g h t h e f o l l o w i n g l o o p . T h i n s t r u c t i o n w h i c h i a 4 9 1 8 6w a l a b e l e d L O O P i t h o r i g i n a l s o u r c e . T h i s i n s t r u c t i o n w i l l l o a dt h A - r e g w i t h t h b y t e a t h l o c a t i o n c o m p u t e d f r o m t h s u o t h c o n t e n t s o t h Y - r e g a n t h a d d r e s s v e c t o r i l o c a t i o n s 2 5 a n 2 5 2 .A u n f o r t u n a t e c o n s e o u e n c e o n o t b e i n g a b l e t o s w i t c h i t h c h a r a c t e r R O i t h a t t h e d a t a b e i n g l o a d e d i n o t h s a m e a i i w h e n t h p r o g r a m i r u a f u l l s p e e d .

I y o t a k e t h v a l u e s t o r e d a t l o c a t i o n 2 5 ( 2 0 8 ) » w h i c h i t h p a g e o t h c h a r a c t e r R O M ) a n m u l t i p l y i b 2 5 6 a n d a d d t h v a l u e s t o r e d i l o c a t i o n 2 5 1 , ( 0 ) * y o w i l l g e t h b a s e a d d r e s s t w h i c h t h Y - r e g i a d d e d . A l v e c t o r s w o r k t h s a m e w a y : a d d t h c o n t e n t s o t h f i r s t b y t e o t h v e c t o r t 2 5 6 t i m e s t h s e c o n d b y t et g e t h a d d r e s s b e i n g r e f e r e n c e d .

T h n e x t i n s t r u c t i o n * t h P H A * s a v e s t h e r e t r i e v e d b y t e o n t ot h s t a c k . N o t e t h e v a l u e o t h S ( s t a c k p o i n t e r ) b e f o r e a n a f t e re x e c u t i n g t h i s i n s t r u c t i o n .

N e x t * t h e r e i t h r e e i n s t r u c t i o n t r i c k p l a y e d w i t h t h Y - r e gt c a u s e t h e v e n t u a l t u r n i n g u p s i d e - d o w n o f t h e c h a r a c t e r s . T h f l i p p i n g o f e a c h c h a r a c t e r t o p - t o - b o t t o m r e q u i r e s k n o w l e d g e o h o c h a r a c t e r i n f o r m a t i o n i s t o r e d i m e m o r y . I t u r n s o u t t b f a i r l y s i m p l e p r o c e s s b u o n e w h i c h c a n b e b e t t e r u n d e r s t o o d b r e a d i n g C h a p t e r 1 1 S u f f i c e i h e r e t s a t h a t s i m p l e m a n i p u l a t i o no t h Y - r e g i s t e r m o d i f y s t h s e q u e n c e i w h i c h t h e c h a r a c t e ri n f o r m a t i o n o c c u r s i t h n e c h a r a c t e r s e t .

T h P L i n s t r u c t i o n p u l l s t h e s a v e d b y t e o c h a r a c t e ri n f o r m a t i o n b a c k o f f t h e s t a c k . Y o c a s e t h s t a c k p o i n t e r b e i n gm o d i f i e d a g a i n a t h P L i n s t r u c t i o n s i e x e c u t e d . O n c e t h b y t e i b a c k i t h A - r e g * i i s t o r e d i t h n e c h a r a c t e r s e t i p o s i t i o n d e t e r m i n e d b t h s o u r c e v e c t o r a 2 5 3 * 2 5 4 a n t h e v a l u e o ft h Y - r e g .

S i n c e t h e Y - r e g w a m a n i p u l a t e d t c a u s e t h f l i p p i n g o v e r o t h c h a r a c t e r * i m u s t n o b f i x e d b a c k t i t o r i g i n a l v a l u e b e f o r et h m o d i f i c a t i o n . T h n e x t t h r e e i n s t r u c t i o n s , T Y A * E O # 7 a n T A d t h t r i c k . T h i s i j u s t t h r e v e r s e o t h o p e r a t i o n w h i c hm o d i f i e d i i t h f i r s t p l a c e .

O n c e t h Y - r e g i r e s t o r e d , i t u s e a s l o o p c o u n t e r i

Page 40: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 40/172

I n s i d e T h C o m m o d o r e 4 P * g t 4 -

e m p l o y e d . T h I N i n s t r u c t i o n b u m p s i u b o n e a n d t h n e x ti n s t r u c t i o n t e s t s i t s e i f i t h a s g o n e p a s t 2 5 5 , i t m a x i m u mv a l u e . I - i h a s , i w i l l h a v e t h v a l u e o - z e r o . T h B N i n s t r u c t i o n t e s t s t h e z e r o b i o t h s t a t u s r e g i s t e r a n a l o n g a i i o f ( z e r o ) , t h e b r a n c h w i l l b e x e c u t e d a n d t h n e x ti n s t r u c t i o n t o b e e x e c u t e d w i l l b a t h £ t o p o f t h e l o o p a 4 9 1 8 6 .O n c e t h Y - r e g g e t s i n c r e m e n t e d p a s t 2 5 5 t 0 t h p r o g r a m w i l l " f a l lt h r o u g h " t t h D E i n s t r u c t i o n . T h i s w i l l h a p p e n a f t e r t h e 2 5 s e q u e n t i a l b y t e s o d a t a i t h f i r s t p a g e o t h e c h a r a c t e r R O h a v eb e e n m o v e d t o t h e n e c h a r a c t e r s e l o c a t i o n .

S t e p p i n g t h r o u g h f e c y c l e s o t h e l o o p w o u l d b i n s t r u c t i v ef o r t h e n e w c o m e r t m a c h i n e l a n g u a g e p r o g r a m m i n g . T h e r e a r e i g h tp a g e s o 2 5 b y t e s e a c h o c h a r a c t e r i n f o r m a t i o n w h i c h n e e d s t b m o v e d . T h Y - r e g i u s e d n o o n l y t o c o u n t t h r o u g h t h 2 5 b y t e s o e a c h p a g e b u a l s o t o i n d e x t h a d d r e s s w h e r e d a t a i b e i n g r e t r i e v e df r o m a n s t o r e d t o I y o s t e p t h r o u g h t h e l o o p e i g h t t i m e s a n dr e c o r d t h v a l u e o f t h e Y - r e g p r i o r t e x e c u t i n g t h i n s t r u c t i o n a 4 9 1 8 6 a n p r i o r t e x e c u t i n g t h i n s t r u c t i o n a 4 9 1 9 4 s o m e i n s i g h t m a b g a i n e d i n t o t h t e c h n i q u e e m p l o y e d . G t h r o u g h i a n o t h e r e i g h tt i m e s a n s e t h a t t h e p a t t e r n r e p e a t s .

Y o u m a y c o n t i n u e t h r o u g h t h e r e s t o t h p r o g r a m t s e i t c o m p l e t i o n w i t h o u t g o i n g t h r o u g h 2 0 4 8 ( t i m e s 2 5 6 ) c y c l e s o f t h l o o p . H e r e i a n o t h e r p l a c e t h b y p a s s o p t i o n i u s e f u l . T g e t o u to f t h e i n n e r l o o p w h i c h t e r m i n a t e s a t h B N i n s t r u c t i o n a 4 9 2 0 1 y o m a s e l e c t o p t i o n i n s t e a d o e x e c u t i n g t h b r a n c h i n s t r u c t i o n . T h i sw i l l c a u s e t h p r o g r a m t " f a l l t h r o u g h " t o t h e n e x t i n s t r u c t i o n , t h D E X . F o l l o w i n g t h D E i t h i n s t r u c t i o n w h i c h t e s t s t s e i a l e i g h t p a g e s h a v e b e e n p r o c e s s e d . I n o t * t h v e c t o r s f o t h s o u r c ea n d e s t i n a t i o n L D a n S T i n s t r u c t i o n s a r i n c r e a s e d a n t h i n n e rl o o p i e n t e r e d a g a i n f o a n o t h e r 2 5 i t e r a t i o n s . T g e p a s t d o i n gt h i s a g a i n , t h J M i n s t r u c t i o n a t 4 9 2 1 0 m u s t b b y p a s s e d .

T h l a s t s e v e n i n s t r u c t i o n s i t h p r o g r a m s w i t c h t h I / b a c ki a n d r e - e n a b l e t h e i n t e r r u p t s a n r e t u r n t o t h e c a l l i n g p r o g r a m .T h e s e m a b e e x e c u t e d w i t h o u t d a n g e r . E x e c u t i n g t h l a s t i n s t r u c t i o n ,t h R T S , w i l l c a u s e a s t a c k e r r o r . T h i s i w h a t s h o u l d b e e x p e c t e db e c a u s e t h r e t u r n f r o m s u b r o u t i n e w a n o p r e c e d e d b j u m p t s u b r o u t i n e . T h S Y i n s t r u c t i o n i t h B A S I C p r o g r a m w a t h i n t e n d e dm e a n s o f g e t t i n g t o t h e m a c h i n e l a n g u a g e p r o g r a m . T h R T i t h i n t e n d e d m e a n s o f r e t u r n i n g t o t h e B A S I C p r o g r a m . "

Page 41: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 41/172

I n i i d t T h C o m m o d o r t 6 P t g t 5 -

M a k i n g t h F i n a l P r o d u c tT h e r e a r s e v e r a l p l a c e s w h e r e m a c h i n e l a n g u a g e ( M L ) p r o g r a m s

m a b d e s i g n e d t o r e s i d e . T h e s e i n c l u d e : i I n s i d e a B A S I C p r o g r a m2 B e f o r e o a f t e r t h e B A S I C p r o g r a m . 3 I t h c a s s e t t e b u f f e r ,$ 3 3 C - $ 3 F B ( 8 2 8 - 1 9 1 9 ) 4 I " s a c r e d " R A a $ C e 9 0 - $ C F F F ( 4 9 1 5 2 - 5 3 2 4 7 ) .5 A n y p l a c e t h a t D e v e l o p - 6 4 i t s e l f d o e s n o r e s i d e . 6 A n y w h e r e i m e m o r y t h a t a " m i n i - l o a d e r " p r o g r a m c a a d d r e s s .

I n s i d e B A S I C p r o g r a m

T g e M p r o g r a m i n t o a B A S I C p r o g r a m s t h a t i m a b s a v e d w i t h t h e B A S I C p r o g r a m a n r e l o a d e d r i g h t a l o n g w i t h i t c o u p l e o t e c h n i q u e s m a b u s e d .

T h f i r s t w a i t l o a d B A S I C p r o g r a m w i t h s e v e r a l R E s t a t e m e n t s w h i c h t a k e u s p a c e a n w i l l b o v e r l a i d b t h M L T h t o k e n f o r t h e f i r s t R E m u s t n o t b e o v e r l a i d b u t e v e r y t h i n g a f t e r i c a b e

T f i n d t h a d d r e s s w h e r e t h R E s t a t e m e n t o y o u r B A S I Cp r o g r a m i s t o r e d i i n e c e s s a r y t u n d e r s t a n d h o w B A S I C p r o g r a m s a r s t r u c t u r e d . E a c h l i n e o f B A S I C p r o g r a m i s t o r e d i m e m o r y i c o n d e n s e d f a s h i o n . A l l t h " k e y w o r d s " , s u c h a G O T O , F O R , P R I N T , e t c .a r s t o r e d a a s i n g l e b y t e o f d a t a , c a l l e d t o k e n , p r e c e d i n g t h c o n d e n s e d B A S I C l i n e i f o u r b y t e s o s y s t e m i n f o r m a t i o n . T h f i r s tt w b y t e s a r l i n k a d d r e s s p o i n t i n g t t h n e x t B A S I C s t a t e m e n tf o l l o w i n g t h i s o n e . T h s e c o n d t w b y t e s a r e t h e l i n e n u m b e r o t h i sB A S I C s t a t e m e n t . A t h e n o e a c h s t a t e m e n t i a s i n g l e b y t e w i t hv a l u e 0 T h i s i t h s t a t e m e n t t e r m i n a t o r .T h l a s t B A S I C s t a t e m e n t i t h p r o g r a m h a l i n k a d d r e s s o 0 T h f i r s t s t a t e m e n t i t h p r o g r a m i p o i n t e d t b a a d d r e s sv e c t o r s t o r e d i l o c a t i o n s 4 a n 4 4 O n c e y o u r p r o g r a m i s i n m e m o r yy o m a f i n d t h a d d r e s s o a n g i v e n s t a t e m e n t b y s e a r c h i n g f o t h l i n e n u m b e r w i t h t h f o l l o w i n g s h o r t s t a t e m e n t w h i c h m a b e e n t e r e d i d i r e c t m o d e ( d o e s n o h a v e t b i p r o g r a m ) .

I = 4 3 : F O R J = i T O i e 0 e e : I = P E E K ( I ) + 2 5 6 * P E E K ( I + i ) : I F P E E K ( I + 2 ) +P E E K ( I + 3 ) * 2 5 6 O . . . T H E N N E X T

W h e r e t h " . . . " a p p e a r s y o m u s t k e y t h e s t a t e m e n t n u m b e r y o

Page 42: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 42/172

I n s i d e T h C o m m o d o r e 6 4 P a g e 5 -

a r s e a r c h i n g f o r . W h e n t h " R E A D Y . " r e a p p e a r s o t h e s c r e e n * t h ev a r i a b l e w i l l c o n t a i n t h e a d d r e s s o t h f i r s t b y t e o t h s t a t e m e n ty o a r s e a r c h i n g f o r . S i m p l y P R I N T I T h v a l u e p r i n t e d w i l l b t h a d d r e s s o t h f i r s t b y t e o t h l i n k a d d r e s s w h i c h p r e c e d e s t h a c t u a l s t a t e m e n t i m e m o r y . T h e a d d r e s s o f t h e f i r s t b y t e o t h s t a t e m e n t w i l l b f o u r g r e a t e r t h a n t h v a l u e o I

T h M p r o g r a m y o w i s h t i n c l u d e w i t h y o u r B A S I C p r o g r a m m a b o g r e a t e r l e n g t h t h a n w h a t m a y b a c c o m o d a t e d b s i n g l e B A S I CR E s t a t e m e n t . T h s o l u t i o n i t h a v e m u l t i p l e R E M s . B e f o r eo v e r l a y i n g t h e m * i w i l l b n e c e s s a r y t c h a n g e t h l i n k a d d r e s sp r e c e d i n g t h f i r s t o n t o p o i n t t t h s t a t e m e n t f o l l o w i n g t h b a t c ho s t a t e m e n t s t b o v e r l a i d . S i i n e c e s a r y t f i n d t h a d d r e s so t h s t a t e m e n t f o l l o w i n g t h e o v e r l a y a r e a u s i n g t h e t e c h n i q u e a b o v e *a n t m o d i f y t h l i n k a t h b e g i n n i n g o t h a r e a a c c o r d i n g l y .

F o e x a m p l e * i t h a d d r e s s o t h f i r s t s t a t e m e n t t b o v e r l a i d i 5 0 0 0 a n t h a d d r e s s o t h f i r s t s t a t e m e n t a f t e r t h o s et b o v e r l a i d i 6 0 0 0 * t h e f o l l o w i n g P O K E s w o u l d d o t h j o b : P O K E5 0 0 1 , 6 0 0 0 / 2 5 6 : P O K E 5 0 0 0 * 6 0 0 0 - P E E K < 5 0 0 1 ) * 2 5 6 . T h i s w o u l d a l l o w y o t s a v e M p r o g r a m f r o m 5 0 0 5 ( t h e b y t e a f t e r t h e R E t o k e n ) , t 5 9 9 9( t h e b y t e b e f o r e t h t e r m i n a t o r o f t h e l a s t R E o v e r l a i d ) .

T h e r e a r t w p l a c e s w i t h i n y o u r B A S I C p r o g r a m w h i c h m a k e s e n s et u s f o t h o v e r l a y a r e a . T h e r e a r a d v a n t a g e s a n d i s a d v a n t a g e st b o t h .

I y o p l a c e i a n y w h e r e b u t h b e g i n n i n g , t h p r o b l e m e x i s t so h a v i n g t h m a c h i n e l a n g u a g e p r o g r a m s h i f t i n g l o c a t i o n s e v e r y t i m em o d i f i c a t i o n i m a d e t t h B A S I C p r o g r a m . T h i s c a n b e m a j o rp r o b l e m i t h M h a n o n - r e l o c a t a b l e c o d e * e . g . J S i n s t r u c t i o n t os o m e f i x e d a d d r e s s w i t h i n t h p r o g r a m . N o n - r e l o c a t a b l e p r o g r a m ss h o u l d t h e r e f o r e o v e r l a y t h b e g i n n i n g o f B A S I C p r o g r a m w h e r em o d i f i c a t i o n s t s u b s e q u e n t s t a t e m e n t s o t h B A S I C p r o g r a m w i l l n o c a u s e a n y s h i f t i n g o f t h p o s i t i o n o t h M L

Page 43: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 43/172

I n s i d e T h C o m m o d o r e * P t g t 5 -

A e x a m p l e o s u c h p r o g r a m w o u l d b e

1 G O T O 1 0 82 R E M 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 . . .3 R E M 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 . . .4 R E M 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 . . .5 R E M 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 . . .6 R E M 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 , . .7 R E M 1 2 3 4 5 6 7 8 9 8 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 . . .8 R E M 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 . . .9 R E M 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 . . 1 0 R E S T A R T O T H P R O G R A M1 1

T h d r a w b a c k s t t h i s s c h e m e a r e p o t e n t i a l l y s e r i o u s . T h b i g g e s t d r a w b a c k i t h a t n o w h e r e i t h M p r o g r a m m a t h e r e a p p e a rt h v a l u e o 0 T h a t c o u l d b r e a l b o t h e r t g e a r o u n d i s o m es i t u a t i o n s . T h i s l i m i t a t i o n i d u t t h - f a c t t h a t B A S I C i n t e r p r e t st h a l i n e t e r m i n a t o r a n d a n y m o d i f i c a t i o n s o e v e n S A V E i n g t h p r o g r a m w i l l c a u s e h a v o c . T h o t h e r d r a w b a c k i t h a t c e r t a i n b y t e sw i l l c a u s e t h l i s t i n g o t h p r o g r a m t a p p e a r s t r a n g e o n o a p p e a ra a l l . I f a c t , t h e v a l u e o 2 6 < $ C C ) w i l l c a u s e B A S I C t c h o k eu p o n l i s t i n g i t I w i l l g i v e S Y N T A X ? e r r o r . T h p r o g r a m w i l l r u O b u w i l l n o t b e l i s t a b l e b e y o n d t h a t p o i n t . Y o u m a y l i s t t h r e m a i n d e r o t h p r o g r a m b t y p i n g " L I S T 3 0 - " f o e x a m p l e i t h s y n t a x e r r o r s t o p p e d t h l i s t i n g p r i o r t s t a t e m e n t 3 0 T h i s m i g h t b c o n s i d e r e d s o r t o p r o t e c t i o n f e a t u r e , a i w i l l c a u s e t h o p p o s i t i o n d i f f i c u l t y i l i s t i n g y o u r p r o g r a m ( a l e a s t f o a w h i l e ) .

T h o t h e r p l a c e w h i c h i l i k e l y c a n d i d a t e f o s t o r i n g t h p r o g r a m w i t h i n a B A S I C p r o g r a m i a t h e n o t h B A S I C p r o g r a m .H e r e , t h n o n - r e l o c a t a b i l i t y p r o b l e m i p r e s e n t b u t h p r o b l e m w i t hh a v i n g i t h M i s o l v e d . I y o c a n b e s u r e y o w i l l n e v e rm o d i f y y o u r B A S I C p r o g r a m t h e r e i n r e l o c a t a b i l i t y p r o b l e m . I o n l ye x i s t s i y o u a d d t o d e l e t e c h a r a c t e r s i t h B A S I C p r o g r a m a n t h p a s s e n g e r p r o g r a m g e t s r e l o c a t e d .

T h b e s t t e c h n i q u e f o a d d i n g t h M a t h e n d i f f e r s f r o mt h R E t e c h n i q u e e x p l a i n e d a b o v e . F i r s t , f i n d t h e n o y o u r B A S I Cp r o g r a m . T h i s i a s i m p l e a s P R I N T P E E K ( 4 5 ) P E E K ( 4 6 ) 2 5 6 . T h v a l u e p r i n t e d w i l l b t h e n o B A S I C a n t h e s t a r t o v a r i a b l es t o r a g e . T a d p a s s e n g e r a t h e n d y o u n e e d t c h a n g e t h v e c t o r

Page 44: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 44/172

I n i i d t T h C o m m o d o r e 6 4 P a g e 5 -

a 4 a n 4 t i n c r e a s e t h e p r o g r a m s i z e b y a s m u c h a s y o u n e e d f o y o u r M c o m p o n e n t . I f o e x a m p l e t h e n o y o u r B A S I C p r o g r a m i 1 0 0 0 9 a n y o u w i s h t a d M p r o g r a m o l e n g t h 2 0 0 0 * y o u w o u l d K e t h f o l l o w i n g : P O K E 4 6 , 1 2 0 0 0 / 2 5 6 : P O K E 4 5 1 2 0 0 0 - P E E K ( 4 5 ) * 2 5 6 . T h n e x t t h i n g t d i t S A V E t h p r o g r a m a n i m m e d i a t e l y r e - L O A D i t W h e n t h m a c h i n e l a n g u a g e i l o a d e d i n t o t h r e s e r v e d a r e a i w i l l n o a p p e a r o t h l i s t i n g a n i m a h a v e z e r o s o a n y o t h e r v a l u e . N o w ,a n a d d i t i o n s a n d e l e t i o n s , S A V E i n g a n r e - L O A D i n g o t h B A S I Cp r o g r a m w i l l K e e p t h M i n t a c t . R e f e r e n c i n g a d d r e s s e s w i t h i n i f r o my o u r B A S I C p r o g r a m i m o s t e a s i l y a c c o m p l i s h e d b c o m p u t i n g t h a d d r e s s a d i s p l a c e m e n t f r o m t h e n o t h p r o g r a m . F o e x a m p l e ,i t h e n t r y p o i n t o t h M p r o g r a m i 5 0 0 b y t e s f r o m t h e n o t h p r o g r a m , y o u r c a l l t i w o u l d b S Y P E E K ( 4 5 ) + P E E K < 4 6 ) * 2 5 6 - 5 0 0 . T h i sw a y , n o m a t t e r w h e r e t h p r o g r a m g e t s s h i f t e d t b c h a n g e s t t h B A S I C p r o g r a m , t h S Y s t a t e m e n t i a l w a y s c o r r e c t .

O n c e y o d e c i d e w h e r e y o w a n t y o u r M p r o g r a m t r e s i d e t h ep r o b l e m i t g e i t h e r e . T h e r e a r f e o p t i o n s . Y o f i r s t n e e dt f i n d t h a d d r e s s o t h e b e g i n n i n g o f t h e m a c h i n e l a n g u a g e p r o g r a m ,i . e . t h a d d r e s s i n s i d e t h B A S I C p r o g r a m w h e r e t h M p r o g r a m w i l lr e s i d e . T h i s a d d r e s s m u s t t h e n b t h a d d r e s s e x p r e s s e d i t h o p e r a n d o t h E Q s t a t e m e n t i t h M p r o g r a m w h i c h i m m e d i a t e l yp r e c e d e s t h f i r s t a c t u a l b y t e o M t b e g e n e r a t e d . ( E v e r y E Q e n c o u n t e r e d r e s e t s t h a d d r e s s o w h e r e s u c c e e d i n g M g e t s s t o r e d ) .

T h e r e i l o a d e r s u b - p r o g r a m w h i c h i p a r t o D e v e l o p - 6 4 .I i p o s s i b l e t u s i t l o a d t h e o b j e c t f i l e c o n t a i n i n g t h M i n t o t h e a r e a y o h a v e r e s e r v e d i y o u r B A S I C p r o g r a m . I i a l s op o s s i b l e t u s t h P O K E o p t i o n o t h a s s e m b l e r s u b - p r o g r a m t d i r e c t l y P O K E t h M i n t o t h r e s e r v e d a r e a . t h i r d c h o i c e i t w r i t e b r i e f l o a d e r i B A S I C a i l l u s t r a t e d i t h s a m p l e p r o g r a m i c h a p t e r 8 A l l o f t h e s e o p t i o n s h a v e o n t h i n g i c o m m o n . T h e y a l i n v o l v e h a v i n g t w B A S I C p r o g r a m s i m e m o r y a t h s a m e t i m e , t h B A S I C p r o g r a m y o a r e t r y i n g t o a d t h M t a n t h p r o g r a m w h i c h i d o i n g t h e a d d i n g .

T h i s i e a s i l y a c c o m p l i s h e d . F i r s t , l o a d t h e B A S I C p r o g r a m t b e i m p r e g n a t e d . N e x t , p r i n t t h v a l u e s o l o c a t i o n s 4 3 4 4 4 a n 4 ( e . g . ? P E E K ( 4 3 ) , e t c . ) . W r i t e t h e s e d o w n . N e x t , c h a n g e t h v a l u es t o r e d a 4 t o n g r e a t e r t h a n w h a t i i 4 6 N o l o a d t h e p r o g r a mw h i c h w i l l d t h l o a d i n g o t h M a n P O K E i n i i n t o t h r e s e r v e da r e a o f t h e f i r s t B A S I C p r o g r a m . T h i s p r o g r a m w i l l n o l o a d a f t e r t h ee n o y o u r B A S I C p r o g r a m . ( T h i s t e c h n i q u e o c h a n g i n g t h e l o a d

Page 45: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 45/172

I n s i d e t h C o m m o d o r e 6 P t g t 5 -

a d d r e s s o B A S I C p r o g r a m s i u s e f u l a l s o - f o r p l a c i n g D e v e l o p - 6 4 i m e m o r y l o c a t i o n w h i c h w i l l n o c o n f l i c t w i t h a p r o g r a m w h i c h y o u w i s ht d e c o d e o d e b u g ) .

R u n n i n g t h s e c o n d p r o g r a m * b i D e v e l o p - 6 4 o m i n i - l o a d e r *t o l o a d t h e o b j e c t f i l e o t a s s e m b l e t h s o u r c e p r o g r a m a n P O R E o u t h M w i l l c a u s e t h M t b p l a c e d i n t o t h s p a c e y o u h a v ec a r e f u l l y r e s e r v e d f o i b t h e p r e c e d i n g o p e r a t i o n s .

O n c e d o n e * i i n e c e s s a r y t s a v e t h B A S I C p r o g r a m w i t h i t e m b r y o . T d t h i s * y o m u s t r e s t o r e t h e v a l u e s o 4 3 * 4 4 * 4 a n 4 ( P O K E 4 3 * . . . : P O K E 4 4 , . . . - e t c . ) w i t h t h v a l u e s y o r e c o r d e dp r e v i o u s l y . I m m e d i a t e l y f o l l o w t h i s w i t h S A V E o f t h e f i r s t p r o g r a m .T h S A V E f u n c t i o n o f t h e C o m m o d o r e 6 4 c a u s e s w h a t e v e r i b e t w e e n t h a d d r e s s e s p o i n t e d t b y 4 3 * 4 4 a n 4 5 * 4 6 t o b s a v e d . W h e n y o r e - L O A Dt h B A S I C p r o g r a m i s h o u l d b e c a r r y i n g i t M c h i l d * r e a d y t d e l i v e r( p r o v i d i n g i w a w e l l c o n c e i v e d i t h f i r s t p l a c e ) .

T h f i n a l w a o g e t t i n g M i n t o B A S I C p r o g r a m i t h h a r d e s ta n u g l i e s t w a a v a i l a b l e . T h i s i t o t a k e t h e l i s t i n g o t h a s s e m b l e r a n c r e a t e s t r i n g o f D A T A s t a t e m e n t s w i t h o n e d e c i m a lv a l u e f o e v e r y b y t e o g e n e r a t e d M a n t i n c l u d e a F O N E X T l o o pr e a d i n g e v e r y v a l u e a n P O K E i n g i i n t o t h d e s i r e d m e m o r y l o c a t i o n s .F o r p r o g r a m s w h i c h n e e d t b e s e l f - d o c u m e n t i n g t h i s m a b t h r i g h ts o l u t i o n . A n y o n e r e a d i n g ^ t h e B A S I C p r o g r a m w i l l h a v e a l t h i n f o r m a t i o n n e e d e d t g e t h p r o g r a m t w o r k . T h i s i w h s m a n ym a g a z i n e s u s e t h i s c l u m s y a p p r o a c h i t h e i r a r t i c l e s .

T h f o l l o w i n g a p p r o a c h e s a l a s s u m e t h a t t h M w i l l n o b e p a r t o s o m e B A S I C p r o g r a m . T h e y a l r e q u i r e s o m e m e a n s o g e t t i n gt h M i n t o m e m o r y . F o e a c h c a s e * t h t e c h n i q u e s f o a c c o m p l i s h i n gt h i s a r t h s a m e . T h e y a r e t h e s a m e t e c h n i q u e s a d e s c r i b e d a b o v ef o g e t t i n g t h M i n t o r e s e r v e d s p a c e i B A S I C p r o g r a m * i . e .u s i n g D e v e l o p - 6 4 t P O K E t h M o t L O A D i f r o m c r e a t e d o b j e c tf i l e o w i t h m i n i - l o a d e r a i C h a p t e r 8 F o r s t a n d - a l o n e M p r o g r a m s * o n c e t h e y h a v e b e e n l o a d e d b o n o t h e s e m e a n s , t h e y m a b S A V E d b y t h e " b i n a r y " S A V E f e a t u r e o t h S A V E s u b - p r o g r a m o D e v e l o p - 6 4 . T h i s w i l l t h e n a l l o w t h e m t b e l o a d e d w i t h t h n o r m a lL O A ^ ' n a m e " ^ s t a t e m e n t f o d i s k o r L O A D " n a m e " f o c a s s e t t e .

I y o u w i s h t d b i n a r y s a v e w i t h o u t D e v e l o p - 6 4 i m e m o r y *t h f o l l o w i n g r o u t i n e w i l l a c c o m p l i s h i f o y o u .

Page 46: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 46/172

I n s i d t T h C o m m o d o r t 6 P a g e 5 -

1 T D = 1 : R E M F O R D I S K T 2 P O K E 7 8 1 , T D : P O K E 7 8 0 , 1 : P 0 K E 7 8 2 , 2 : S Y 6 5 4 6 63 I N P U T " S T A R T , E N D " $ A , B : I N P U T " F I L E N A M E " ; A *4 P O K E 7 8 0 , P E E K < 2 0 2 ) - l l s P O K E 7 8 1 , 0 : P O K E 7 8 2 , 2 ; S Y S 6 5 4 6 ?5 P O K E 7 8 0 , 2 5 1 : P 0 K E 2 5 2 , A / 2 5 6 : P 0 K E 2 5 1 , A - P E E K < 2 5 2 ) * 2 5 66 P 0 K E 7 8 2 , B / 2 5 6 : P 0 K E 7 8 1 , B - P E E K < 7 8 2 ) * 2 5 6 : S Y S 6 5 4 ? 6

T h i s p r o g r a m i l l u s t r a t e s t h a b i l i t y t c a l l k e r n a l r o u t i n e sd i r e c t l y - f r o m B A S I C . T h e A - r e g , X - r e g a n d Y - r e g m a b s e u i l o c a t i o n s 7 8 0 - 7 8 2 r e s p e c t i v e l y b e f o r e d o i n g S Y a n t h c a l l e dr o u t i n e w i l l b e n t e r e d w i t h t h e s e r e g i s t e r s p r e - i n i t i a l i z e d . U p o nr e t u r n i n g f r o m t h c a l l e d r o u t i n e , t h e a b o v e m e m o r y l o c a t i o n s w i l lc o n t a i n t h v a l u e s o f t h e r e g i s t e r s u p o n e x i t i n g t h r o u t i n e . T h i sc a n b e c o n v e n i e n t w a t c o m m u n i c a t e w i t h y o u r m a c h i n e l a n g u a g ep r o g r a m f r o m B A S I C .

B e f o r e o a f t e r B a s i c

T h u p p e r l i m i t o t h m e m o r y s p a c e w h i c h B A S I C b e l i e v e s i h a a v a i l a b l e f o r B A S I C p r o g r a m s i m a i n t a i n e d i a a d d r e s s v e c t o r a l o c a t i o n s 5 5 , 5 6 . A 5 2 , 5 3 i a n o t h e r v e c t o r w h i c h B A S I C u s e s t s e t h h i g h e s t m e m o r y a d d r e s s u s a b l e f o r s t r i n g s t o r a g e . T h b e g i n n i n ga d d r e s s , a s m e n t i o n e d a b o v e i p o i n t e d t b v e c t o r a t 4 3 , 4 4 .B A S I C s t a r t s s t o r i n g s t r i n g s a i t h i g h e s t a v a i l a b l e m e m o r y l o c a t i o na n w o r k s b a c k d o w n . T h f r e e m e m o r y a v a i l a b l e i B A S I C p r o g r a m i t h s p a c e b e t w e e n t h h i g h e n o f v a r i a b l e s t o r a g e a n t h b o t t o m o s t r i n g s t o r a g e . S t r i n g s a r e c o n t i n u a l l y f i l l i n g u t h f r e e m e m o r yg a a t h e y a r e c r e a t e d b y t h e p r o g r a m . O n l y w h e n f r e e m e m o r y i e x h a u s t e d w i l l B A S I C c l e a n u t h e s t r i n g a r e a f o f u t u r e s t r i n g u s a g e .T h i s i w h a t i k n o w n a " g a r b a g e c o l l e c t i o n " a n w h a t o c c a s i o n a l l yc a u s e s B A S I C p r o g r a m s t p a u s e f o w h i l e b e f o r e c o n t i n u i n g . T h r e s u l t o f t h i s s y s t e m o s t r i n g m a n a g e m e n t i t h a t n m e m o r y b e t w e e nt h s t a r t o B A S I C a n t h e " t o p o m e m o r y " i f r e e f r o m p o s s i b l ed e s t r u c t i o n b y t h B A S I C p r o g r a m .

I i p o s s i b l e t s a v e M p r o g r a m s e g m e n t s i s p a c e w h i c hw i l l n o b m o l e s t e d b B A S I C p r o g r a m s i y o m o d i f y t h t w v e c t o rs e t s a 5 1 , 5 2 a n 5 5 , 5 6 s t h a t t h e y p o i n t t a n a d d r e s s b e l o w t h M L O y o c o u l d m o d i f y t h s t a r t o f B A S I C v e c t o r b e f o r e l o a d i n g t h e B A S I C

Page 47: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 47/172

I n s i d e T h C o m m o d o r e 6 P a g t 5 -

p r o g r a m . I e i t h e r c a s e , B A S I C w i l l n o e v e n K n o w o t h e e x i s t e n c e o t h a t m e m o r y s p a c e a n d w i l l n o t r t s a v e a n y t h i n g t h e r e .

C a s s e t t e B u f f e r $ 3 3 C $ 3 F B ( 8 2 8 1 0 1 9 )

T h e r e i a s e r i o u s p r o b l e m w i t h p u t t i n g . t h e M i t h c a s s e t t eb u f f e r i y o d o n ' t h a v e d i s k d r i v e . W h a t e v e r p r o g r a m y o u u s t l o a d t h o b j e c t f i l e w i t h w i l l i t s e l f u s t h c a s s e t t e b u f f e r . A n s o a i i r e a d i n g t h e o b j e c t f i l e i i d e s t r o y i n g t h P O K E d M L I y o u h a v e d i s k e t t e b a s e d s y s t e m , t h e r e i n p r o b l e m .I s a c r e d R A $ C 0 e e * C F F F ( 4 9 1 5 2 - 5 3 2 4 7 )

N p r o t e c t i o n f r o m B A S I C n e e d b i m p l e m e n t e d w h e n t h p r o g r a mi u h e r e . B A S I C c a n ' t g e t t h i s a r e a . I t h e r e f o r e m a k e s a ni d e a l p l a c e f o M p r o g r a m s . T h o n l y d i s a d v a n t a g e i t h a t t h M c a n n o t b e l o a d e d a l o n g w i t h t h B A S I C p r o g r a m . I m u s t b e l o a d e ds e p a r a t e l y o b t h B A S I C p r o g r a m .

Page 48: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 48/172

I n s i d e T h C o m m o d o r e 6 4 P a g e 6 -

T h 6 5 1 O D a t a . P r o c e s s o rS i n c e D e v e l o p - 6 4 i f o c u s e d o t h d e v e l o p m e n t o s o f t w a r e

t h r o u g h t h e c r e a t i v e u s o m a c h i n e l a n g u a g e , i w i l l b e n e c e s s a r y t f i r s t u n d e r s t a n d t h m a c h i n e b e f o r e l e a r n i n g i t l a n g u a g e .

Y o u ' r e p r o b a b l y a w a r e t h a t t h e r e i s o m e t h i n g i n s i d e t h c a s eo f t h e C o m m o d o r e 6 w h i c h i K n o w n a t h 6 5 1 0 m i c r o p r o c e s s o r . T h i si t h e h e a r t o f t h e C o m m o d o r e 6 4 I i s l i g h t l y m o d i f i d e d v e r s i o no t h 6 5 0 2 w h i c h i t h h e a r t o t h V I 2 0 t h A p p l e , t h A t a r i ,t h P E T , K I M , A I M , S Y M , O S a n f e o t h e r m i c r o c o m p u t e r s . I i p r o d u c t o M O T e c h n o l o g y , w h o l l y o w n e d s u b s i d i a r y o f C o m m o d o r eB u s i n e s s M a c h i n e s .

T h 6 5 1 0 i a i n t e g r a t e d c i r c u i t . T h a t i s i i s i n g l ec h i p o s i l i c o n w h i c h h a b u i l t i n t o i t s o r t o f l i k e e t c h e d o n t o i t t h e l e c t r o n i c c i r c u i t r y w h i c h c o n n e c t s t h o u s a n d s o m i c r o s c o p i c a l l ys m a l i e l e c t r o n i c c o m p o n e n t s . T h e s e c o m p o n e n t s a r d e p o s i t e d o t h s i l i c o n b s o m e m a r v e l o m o d e r n t e c h n o l o g y w h i c h i b e y o n d t h s c o p eo t h i s t e x t . W w o n ' t g o i n t o h o t h e e l e c t r o n i c s a r e c r e a t e d o r h o t h e y f u n c t i o n e l e c t r o n i c a l l y . W a r e i n t e r e s t e d h e r e i h o t u s t h i s m a c h i n e a n h o i f i t s i n t o t h e n v i r o n m e n t o f t h e C o m m o d o r e 6 p e r s o n a l c o m p u t e r .

T h p i e c e o s i l i c o n c a l l e d t h 6 5 1 0 i p a c k a g e d i a p i e c e o p l a s t i c o c e r a m i c m a t e r i a l a b o u t o n i n c h b t w i n c h e s . I h a 4 l i t t l e b u g - l i k e l e g s c a l l e d p i n s w h i c h c o n n e c t t h i n t e r n a l c i r c u i t r yt o t h e o u t s i d e w o r l d . T h e s e p i n s p l u g i n t o c i r c u i t b o a r d w h i c h h a o t h e r s i m i l a r a p p e a r i n g c h i p s o s i l i c o n , e a c h w i t h i t o w s e o p i n s a n i t o w i n t e r n a l c h a r a c t e r i s t i c s , d i f f e r e n t f r o m t h c h a r a c t e r i s t i c s o f t h e 6 5 1 0 . E a c h o f t h e c h i p s h a i t o w s p e c i f i cf u n c t i o n a n t o g e t h e r t h e y a r c o m b i n e d , t h r o u g h t h e i r c o n n e c t i n g p i n sa n t h c i r c u i t e t c h e d o t h e p r i n t e d c i r c u i t b o a r d i n t o w h i c h t h e ya r p l u g g e d , t o m a k e m i c r o c o m p u t e r .

T h i s w i l l b e c o m e m o r e a n d m o r e c l e a r a w d e s c r i b e w h a t e a c ho f t h e c o m p o n e n t c h i p s a r e f o a n h o t h e y w o r k a n h o t h e yc o m m u n i c a t e w i t h o n a n o t h e r . T h d e s c r i p t i o n o f t h e f u n c t i o n a lc h a r a c t e r i s t i c s o t h 6 5 1 0 w i l l c o m p l e t e l y d e f i n e t h e p r o c e s s o r f r o mt h p r o g r a m m e r ' s s t a n d p o i n t . T h e l e c t r i c a l o e l e c t r o n i cc h a r a c t e r i s t i c s a r e o f n i n t e r e s t t u a w h a v e n o n e e d t u n d e r s t a n d t h m a c h i n e a t t h a t l e v e l .

T h 6 5 1 0 i d a t a p r o c e s s o r . I i m a c h i n e w h i c h p e r f o r m s

Page 49: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 49/172

I n s i d e T h C o m m o d o r e 6 P a g e 6 -

s i m p l e o p e r a t i o n s o d a t a m a n i p u l a t i o n u n d e r t h c o n t r o l o f s t o r e dp r o g r a m . B o t h t h d a t a a n t h p r o g r a m a r s t o r e d i m e m o r y d e v i c e sw h i c h a r i n t e g r a t e d c i r c u i t s e l e c t r i c a l l y c o n n e c t e d t t h e 6 5 1 0 .P r o g r a m s a r s p e c i a l c l a s s o f d a t a a n w w i l l e x p l a i n p r o g r a m sa f t e r w d i s c u s s d a t a i m o r e g e n e r a l s e n s e .

D a t a i i n f o r m a t i o n . I c a n b e t h b a l a n c e o y o u r c h e c k i n ga c c o u n t o t h g r a d e y o u r p h y s i c s t e a c h e r g a v e y o u o t h e p o s i t i o n o P A C - M A N o y o u r v i d e o s c r e e n . I n f o r m a t i o n ! a i i s t o r e d i n s i d e t h c o m p u t e r ' s m e m o r y d e v i c e s i c o d e d b s p e c i a l s e o s i m p l e r u l e s .M e m o r y d e v i c e s a r c o m p o s e d o t h o u s a n d s o c e l l s , o s t o r a g el o c a t i o n s , w h e r e t h d a t a i k e p t . E a c h c e l l i s c o m p o s e d o e i g h ts w i t c h e s w h i c h c a n b e t u r n e d e i t h e r o o o f f . W h e n t h l e t t e r " A i p r e s s e d o n t h k e y b o a r d o y o u r C o m m o d o r e 6 4 s o m e e l e c t r o n i cc i r c u i t r y w i l l a u t o m a t i c a l l y c r e a t e p a t t e r n o e i g h t s w i t c h s e t t i n g sw h i c h i u n i q u e l y i d e n t i f i e d a t h p a t t e r n f o t h l e t t e r " A " . T h i si t h c o d e f o " A " . E v e r y c h a r a c t e r h a i t o w c o d e a n i i d i f f e r e n t f r o m a l t h o t h e r c h a r a c t e r ' s c o d e s . T h e r e a r o n l y 2 5 d i f f e r e n t u n i q u e c o d e s w h i c h c a b c o n s t r u c t e d f r o m e i g h t s w i t c hs e t t i n g s . T h e r e a r t h e r e f o r e o n l y 2 5 p o s s i b l e d i f f e r e n t c h a r a c t e r sw h i c h c a b r e p r e s e n t e d a n d s t o r e d i t h m e m o r y c h i p s o f t h C o m m o d o r e - 6 4 . T h a t ' s s u f f i c i e n t t o h a n d l e A - Z , 0 - 9 , a l t h s p e c i a lc h a r a c t e r s a n t h g r a p h i c s c h a r a c t e r s .

T h e s e s w i t c h e s a r u s u a l l y c a l l e d " b i t s " . B i i s h o r t f o b i n a r y d i g i t . d i g i t m a h a v e 1 p o s s i b l e v a l u e s t 0 - 9 . b i m a h a v e t w p o s s i b l e v a l u e s , 0 - 1 . b i w h i c h i t u r n e d o m a b t h o u g h t o a h a v i n g t h e v a l u e o a n i i i o f f , i i 0 S c h a r a c t e r s a r r e p r e s e n t e d a a s t r i n g o f e i g h t b i t s w i t h b i v a l u e so f e i t h e r o 1 T h a c t u a l b i s t r i n g f o r t h l e t t e r " A i 0 1 0 0 0 0 0 1 . T h c o d i n g s c h e m e u s e d i a i n t e r n a t i o n a l s t a n d a r d c a l l e dA S C I I , w h i c h s t a n d s f o A m e r i c a n S t a n d a r d C o d e f o I n f o r m a t i o nI n t e r c h a n g e .

T h 6 5 1 0 ' s d a t a l i n k w i t h t h m e m o r y d e v i c e s i c a l l e d t h d a t ab u s . T h i s i n o t h i n g m o r e t h a n s e o e i g h t l i n e s , o e l e c t r i c a lc o n n e c t i o n s , b e t w e e n t h m e m o r y c h i p s a n t h 6 5 1 0 . W h e n t h 6 5 1 0 ,u n d e r c o n t r o l o f a p r o g r a m , w i s h e s t o e i t h e r t r a n s f e r d a t a t o o r f r o m

m e m o r y d e v i c e , i s e n d s a e l e c t r i c a l s i g n a l o t h R / ( R e a d / W r i t e )l i n e , t e l l i n g t h d e v i c e w h i c h d i r e c t i o n t h e d a t a i t g o S i n c e t h m e m o r y d e v i c e c a s t o r e t h o u s a n d s o c h a r a c t e r s o f d a t a , i i n e c e s s a r y f o t h 6 5 1 0 t t e l l i w h i c h s t o r a g e l o c a t i o n i w i s h e s t g e t d a t a f r o m o s e n d i t o I d o e s t h i s t h r o u g h a n o t h e r s e o

Page 50: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 50/172

I n s i d e T h C o m m o d o r e 6 P a g e 6 -

e l e c t r i c a l c o n n e c t i o n s c a l l e d t h a d d r e s s b u s . E v e r y s t o r a g e c e l lw i t h i n t h m e m o r y d e v i c e h a u n i q u e a d d r e s s a s s o c i a t e d w i t h i a n w h e n t h s i g n a l c o m e s t d d a t a t r a n s f e r , t h e m e m o r y d e v i c e i d e s i g n e d t u s t h i n f o r m a t i o n s e n t o t h a d d r e s s b u t k n o w w h i c hc e l l i b e i n g s e l e c t e d . E a c h d a t a c e l l h o l d s e i g h t b i t s o fi n f o r m a t i o n . T h i s b a s i c u n i t o d a t a , c a l l e d b y t e , i t r a n s f e r r e da l a o n c e a l o n g t h e i g h t p a r a l l e l e l e c t r i c a l c o n n e c t i o n s K n o w nc o l l e c t i v e l y a t h d a t a b u s .

T h a d d r e s s b u i v e r y s i m i l a r t t h d a t a b u e x c e p t i h a s i x t e e n p a r a l l e l e l e c t r i c a l c o n n e c t o r s . L i k e t h d a t a b u s , t h a d d r e s sb u i n f o r m a t i o n i c o d e d i b i n a r y . T h a t i s e a c h o f t h e s i x t e e nl i n e s m a h a v e o n l y o n o t w p o s s i b l e s t a t e s , a o r 1 p r e s e n t e dt t h d e v i c e s a o r + 5 v o l t s . T h b u s e s a r c o n n e c t e d d i r e c t l y t t h e p i n s w h i c h g i n s i d e t h p l a s t i c p a c k a g e a n d c o n n e c t t o t h ei n t e r n a l m i c r o c i r c u i t r y o t h s i l i c o n c h i p s . T h s i x t e e n b i a d d r e s sb u a l l o w s f o 6 5 5 3 6 d i f f e r e n t a d d r e s s a b l e m e m o r y l o c a t i o n s w h e r e d a t am a b s t o r e d .

F i n a l l y , t h e r e i c o n t r o l b u s w h i c h c o n t a i n s l i n e s w h i c hh e l p t o c o n t r o l t h e v a r i o u s c h i p s i t h C o m m o d o r e 6 4 T h R / l i n em e n t i o n e d a b o v e i o n o t h c o n t r o l s i g n a l s . W i t h t h e x c e p t i o n o t h i n t e r r u p t l i n e s , d i s c u s s e d l a t e r , w d o n ' t n e e d t k n o w m u c h a b o u tt h c o n t r o l b u s .

B e c a u s e t h 6 5 1 6 t r a n s f e r s a n p r o c e s s e s d a t a e i g h t b i t s a t i m e , i i K n o w n a a e i g h t b i p a r a l l e l p r o c e s s o r . A p p e n d i x g o e si n t o m u c h m o r e d e t a i l o t h f o r m a t o t h d a t a a i i s t o r e d i t h m e m o r y d e v i c e s . I i s t r o n g l y r e c o m m e n d e d y o r e a d i t

M e m o r y d e v i c e s c o m e i t w b a s i c v a r i e t i e s a o t h i s w r i t i n g .R O i r e a d - o n l y m e m o r y . W h e n t h p o w e r i t u r n e d o f R O d o e s n ' tl o s e i t c o n t e n t s . R O i k i n d o f c h i p w h i c h m a b " R e a d " b u n o t w r i t t e n t o I t c o n t e n t s a r e " b u r n e d - i n " a t h f a c t o r y . T h e r ei s i m i l a r k i n d o m e m o r y d e v i c e c a l l e d P R O M w h i c h s t a n d s f o P r o g r a m m a b l e R O a n i m a b e m o d i f i e d b y a s p e c i a l p i e c e o f h a r d w a r ec a l l e d P R O M p r o g r a m m e r . I m u s t b e r a s e d b s h i n i n g a i n t e n s eu l t r a v i o l e t l i g h t o i t t o s u r f a c e f o s o m e p r e s c r i b e d l e n g t h o ft i m e .

B o t h o t h e s e d i f f e r f r o m t h o t h e r m a i n k i n d o m e m o r y d e v i c ew h i c h i c a l l e d R A M . R A i b a d l y m i s n a m e d . I s h o u l d b e c a l l e d M O f o M O d i f y a b l e M e m o r y o R A f o R e a d A n W r i t e . R A s t a n d s f o R a n d o m A c c e s s M e m o r y , w h i c h m e a n s y o c a e x t r a c t d a t a f r o m i i a n s e q u e n c e y o u w a n t . T h s a m e t h i n g i t r u e o f a l c u r r e n t l y a v a i l a b l e

Page 51: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 51/172

I n i i d t T h C o m m o d o r e 6 4 P a g e 6 - 4

t y p e s o m e m o r y , i n c l u d i n g R O M .A n y w a y , t h d i f f e r e n c e s b e t w e e n R A a n R O i t h a t a p r o g r a mc a w r i t e t R A a n c h a n g e i t c o n t e n t s a n w h e n t h p o w e r i t u r n e do f t h e c o n t e n t s o R A a r l o s t , w h e r e a s R O c a n n o t b e m o d i f i e d b a n p r o g r a m u n d e r a n y c i r c u m s t a n c e s a n w h e n t h p o w e r i t u r n e d o f f ,t h c o n t e n t s o R O a r e k e p t i n t a c t . I t h C o m m o d o r e 6 4 a l o f t h eo p e r a t i n g s y s t e m p r o g r a m s a n t h B A S I C i n t e r p r e t e r a r e i R O M . T h a ti w h y o c a n r u n B A S I C p r o g r a m s a s o o n a s y o u t u r n t h e m a c h i n e o n w i t h o u t h a v i n g t o l o a d a n y t h i n g f r o m t a p e o d i s k .

Page 52: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 52/172

Page 53: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 53/172

I n s i d e T h C o m m o d o r e 6 P a g t 7 -

u s e f u l t a s k . Y o c h o o s e t h i n s t r u c t i o n s c a r e f u l l y f r o m t h e s e t o fa v a i l a b l e i n s t r u c t i o n s w h i c h t h 6 5 0 2 c a p e r f o r m . Y o c o d e t h e s ei n s t r u c t i o n s i t h l a n g u a g e w h i c h t h m a c h i n e c a n u n d e r s t a n d * m a c h i n el a n g u a g e . E a c h i n s t r u c t i o n h a s p e c i f i c b i p a t t e r n w h i c h i u n d e r s t o o d b t h 6 5 0 2 t m e a n p e r f o r m s o m e o p e r a t i o n a n u s o n o t h 1 p o s s i b l e a d d r e s s i n g m o d e s .

I y o h a v e a n a s s e m b l e r y o u c a w r i t e t h 6 5 0 2 i n s t r u c i o n s i a u n d e r s t a n d a b l e f o r m a t w h i c h m a k e s s o m e s e n s e t h u m a n s w h e n t h e yr e a d i t T h a s s e m b l e r w i l l t h e n c o n v e r t t h h u m a n u n d e r s t a n d a b l ep r o g r a m i n t o a m a c h i n e u n d e r s a n d a b l e s e q u e n c e o b i p a t t e r n s ( b y t e s ) .A S M / E D T , w h i c h c o m e s w i t h D e v e l o p - 6 4 i s u c h p r o g r a m f o t h C o m m o d o r e 6 4 T h n e x t s e c t i o n t e l l s y o h o t u s i t I n t h i ss e c t i o n w w i l l e x p l o r e t h 6 5 0 2 ' s a r c h i t e c t u r e , i t r e g i s t e r s , i t i n s t r u c t i o n s e a n i t v a r i o u s a d d r e s s i n g m o d e s . F i r s t , t h r e g i s t e r s .

T h P r o g r a m C o u n t e r

T h 1 6 - b i t P r o g r a m C o u n t e r R e g i s t e r i a c t u a l l y t w 8 - b i tr e g i s t e r s , t h e P C a n P C r e g i s t e r s . T h e s e t w r e g i s t e r s a r a l w a y su s e d a s p a i r . T h " P C H " s t a n d s f o P r o g r a m C o u n t e r H i g h a n d " P C L 1 1s t a n d s f o P r o g r a m C o u n t e r L o w . T o g e t h e r , t h e y a r u s e d b y t h e 6 5 0 2t f o r m s i x t e e n b i a d d r e s s p o i n t e r . T h 6 5 0 2 m o v e s t h c o n t e n t s o t h e s e t w r e g i s t e r s t o t h e a d d r e s s b u w h e n i w a n t s t f e t c h a i n s t r u c t i o n f r o m s o m e m e m o r y c h i p a t t a c h e d t t h 6 5 0 2 .

T h e P r o g r a m C o u n t e r t e l l s t h 6 5 0 2 w h e r e t h n e x t i n s t r u c t i o n t b e x e c u t e d i l o c a t e d i m e m o r y . W h e n t h c o m p u t e r i t u r n e d o n a i n i t i a l i z a t i o n p r o c e s s o c c u r s a u t o m a t i c a l l y . T h i s p r o c e s s i n c l u d e sm o v i n g t h d a t a c o n t a i n e d i a d d r e s s e s $ F F F C a n $ F F F D d i r e c t l y i n t ot h P C a n P C r e s p e c t i v e l y . A d d r e s s e s s u c h a t h i s w h i c h a r s t o r e di m e m o r y a n p o i n t t t h e s t a r t i n g p o i n t o f s o m e o t h e r p r o g r a m a r c a l l e d " v e c t o r s " . T h i s i h o t h 6 5 0 2 f i n d s t h e a d d r e s s o i t s f i r s ti n s t r u c t i o n t o b e x e c u t e d . S o e v e r y 6 5 0 2 m u s t h a v e t h a d d r e s s o t h b e g i n n i n g o f t h e f i r s t p r o g r a m t b e e x e c u t e d p r e s t o r e d a $ F F F C »$ F F F D ( 6 5 5 3 4 , 6 5 5 3 5 ) . T h i s m u s t o b v i o u s l y b i R O M .

T h i s i n i t i a l i z a t i o n p r o c e s s o c c u r s a p o w e r - o n t i m e a n w h e n e v e r t h R E S E T b u t t o n ( a v a i l a b l e o s o m e e x p a n s i o n c h a s s i s b u t n o to t h s t a n d a r d C o m m o d o r e 6 4 ) i s p u s h e d . A f t e r e a c h e x e c u t i o n o a i n s t r u c t i o n b t h 6 5 0 2 , t h e P r o g r a m C o u n t e r i i n c r e m e n t e d t t h n e x t i n s t r u c t i o n , a n s t h p r o g r a m f l o w o c c u r s .

Page 54: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 54/172

I n t i d t T h C o m m o d o r t 6 4 P a g e 7 -

T h t A - r e g

T h e A - r e g m a b e t h o u g h t o a t h A r i t h m e t i c r e g i s t e r . I i o f t e n c a l l e d t h A c c u m u l a t o r . L i k e a l t h r e g i s t e r s , i i o n e -b y t e ( 8 - b i t ) r e g i s t e r . I i t h p l a c e w h e r e a r i t h m e t i c o p e r a t i o n so c c u r . I n s t r u c t i o n s l i k e A D A d w i t h C a r r y a n S B S u b t r a c tw i t h C a r r y c a u s e d a t a t b a d d e d t o s u b t r a c t e d - f r o m t h r e g i s t e r . T h r e m a b l o a d e d ( n e w v a l u e b r o u g h t i n t o i t w i t h a i n s t r u c t i o n s u c h a L D ( L o a d t h e A - r e g ) . I t c o n t e n t s m a b s t o r e do u t s o m e m e m o r y l o c a t i o n w i t h a i n s t r u c t i o n s u c h a S T ( S t o r e t h A - r e g ) . T h a d d r e s s i m e m o r y w h e r e d a t a i l o a d e d - f r o m a n d s t o r e d - t oi s p e c i f i e d b - f u r t h e r a d d r e s s i n g i n f o r m a t i o n p r o v i d e d t o t h 6 5 0 2 b t h p r o g r a m i m a n n e r d i s c u s s e d i t h n e x t c h a p t e r .

R e f e r e n c e s t " S T A " o " L D A " i n s t r u c t i o n s a r e r e f e r r i n g t o t h a s s e m b l e r l a n g u a g e E n g l i s h - l i k e m n e m o n i c w h i c h g e t s t r a n s l a t e d i n t o am a c h i n e l a n g u a g e i n s t r u c t i o n r e c o g n i z a b l e b t h e 6 5 0 2 . T h e r e i o n f o o n c o r r e s p o n d e n c e b e t w e e n a s s e m b l y l a n g u a g e s t a t e m e n t s a n m a c h i n e l a n g u a g e i n s t r u c t i o n s .

T h e X a n r e g i s t e r s

T h e r e a r t w o t h e r " w o r k i n g " r e g i s t e r s c a l l e d t h a n r e g i s t e r s . T h e s e a r a l s o k n o w n a t h i n d e x r e g i s t e r s . T h e s e a r a l e i g h t b i s t o r a g e r e g i s t e r s i t h 6 5 0 2 c h i p i t s e l f . T h a n r e g i s t e r s a r u s e d m o s t l y i a d d r e s s i n g f u n c t i o n s a e x p l a i n e d n e x tc h a p t e r . T h a n r e g i s t e r s m a b o t h r e c e i v e t h e i r c o n t e n t s ( b l o a d e d ) f r o m m e m o r y w i t h i n s t r u c t i o n s s u c h a L D a n L D ( L o a d t h a n L o a d t h r e g i s t e r s ) . T h e y m a y b s a v e d ( s t o r e d ) i n m e m o r y w i t hS T a n S T i n s t r u c t i o n s . T h e y m a a l s o b e i n c r e m e n t e d * d e c r e m e n t e d ,a n c o m p a r e d t d a t a i e x t e r n a l m e m o r y .

S t a c k P o i n t e r ( S P )

T h s e c o n d 2 5 6 - b y t e b l o c k o m e m o r y ( $ 0 1 0 0 - $ 0 1 F F ) i u s e d b t h 6 5 0 2 i a s p e c i a l w a y . I i c a l l e d t h S t a c k . T h S t a c k i s p e c i a l s t o r a g e b l o c k w h i c h i a u t o m a t i c a l l y u t i l i z e d b c e r t a i ni n s t r u c t i o n s . I t p r i m a r y r e a s o n f o e x i s t e n c e i t a l l & w s u b r o u t i n e" n e s t i n g " a n t a l l o w f o r t h e s m o o t h h a n d l i n g o f i n t e r r u p t s .

S u b r o u t i n e s a r p r o g r a m s e g m e n t s w h i c h c a b e e x e c u t e d b m a n y

Page 55: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 55/172

I n s i d e T h C o m m o d o r e 6 P a g e 7 -

d i f f e r e n t p r o g r a m s . T h e y a r s u b - p r o g r a m s , w h i c h a r j u m p e d - t o a n r e t u r n e d - f r o m . T h e y s a v e h a v i n g t w r i t e c o m m o n l y u s e d p r o g r a ms e g m e n t s o v e r a n d o v e r a g a i n . T h s t a c k i t h e 6 5 0 2 ' s c o m m u n i c a t i o nm e c h a n i s m f o r e m e m b e r i n g w h e r e s u b r o u t i n e w a " c a l l e d " f r o m . T h J S ( J u m p t S u b r o u t i n e ) i n s t r u c t i o n i e x p l a i n e d i d e t a i l i C h a p t e r5 S u f f i c e i h e r e t s a t h a t t h e J S c a u s e s t h p r o g r a m t J u m p t s u b r o u t i n e i s u c h a w a t h a t t h e s u b r o u t i n e c a n r e t u r n t t h i n s t r u c t i o n a f t e r t h J S o n c e i i d o n e d o i n g i t p r o c e s s i n g . T h 6 5 0 2 s a v e s t h e r e t u r n a d d r e s s o t h s t a c k w h e n J S o c c u r s . I p u l l s i o f t h e s t a c k w h e n t h R T ( r e t u r n f r o m S u b r o u t i n e ) o c c u r s .T h p o s i t i o n o t h n e x t a v a i l a b l e s t a c k l o c a t i o n f o r e c o r d i n g r e t u r na d d r e s s e s i k e p t i t h S P T h e S P i s i n i t i a l i z e d b t h C o m m o d o r e6 s t a r t - u p p r o g r a m t t h v a l u e o $ F a p o w e r - o n a n R E S E T t i m e .T h h i g h - o r d e r b y t e o t h e s t a c k a d d r e s s i a l w a y s $ 0 1 . T h i s i f i x e di n s i d e t h e 6 5 0 2 . T h f i r s t t i m e J S i n s t r u c t i o n i e x e c u t e d * t h a d d r e s s o w h e r e t r e t u r n t i p u s h e d o n t o t h s t a c k a $ 0 1 F F a n $ 0 i F E . T h e S P i t h e n d e c r e m e n t e d b t w s t h a t t h e n e v a l u e o f t h S i $ 0 1 F D . T h e s u b r o u t i n e c a l l e d b t h J S R m a y t h e n c a l la d d i t i o n a l s u b r o u t i n e s a n d t h e r e t u r n a d d r e s s e s w i l l b s t o r e d b e l o wt h i n i t i a l r e t u r n a d d r e s s . T h e r e m a b u t 1 2 l e v e l s o fs u b r o u t i n e s c a l l i n g o t h e r s u b r o u t i n e s . E a c h s u b r o u t i n e m u s t h a v e a si t l a s t i n s t r u c t i o n R T ( r e t u r n f r o m s u b r o u t i n e ) i n s t r u c t i o n w h i c hc a u s e s t h 6 5 0 2 t o l o a d t h P w i t h t h s a v e d a d d r e s s f r o m t h e s t a c ka n t i n c r e m e n t t h S b t w o . T h u s t h r e t u r n t t h a d d r e s s f r o mw h i c h t h s u b r o u t i n e w a c a l l e d .

I n t e r r u p t s a r c a u s e d b a e l e c t r i c a l s i g n a l t o t h e 6 5 0 2 f r o mt h o u t s i d e w o r l d . T h e r e a r t w i n t e r r u p t l i n e s a t t a c h e d t o t h e p i n so t h e 6 5 0 2 . O n o t h e m , t h N M l i n e * w i l l c a u s e t h 6 5 0 2 t b i n t e r r u p t e d r e g a r d l e s s o w h a t i i d o i n g . T h i s i c a l l e d t h N o n -

a s k a b l e I n t e r r u p t . T h i s f a c i l i t y i s p r o v i d e d s t h a t h a r d w a r e w h i c hh a c r i t i c a l t i m i n g r e q u i r e m e n t s m a c a u s e t h 6 5 0 2 t o s e r v i c e t h e mi m m e d i a t e l y . I i a l s o p r o v i d e d a m e a n s o u n c o n d i t i o n a l l yb r e a k i n g i n t o t h p r o c e s s i n g o t h m a c h i n e i f i t i s u s p e c t e d t h a ts o m e t h i n g h a s g o n e a w r y i p r o g r a m a n t h e r e i n o t h e r w a t s i e z ec o n t r o l o f t h m a c h i n e s h o r t o t u r n i n g i o f a n t u r n i n g i b a c k o a g a i n .

T h o t h e r k i n d o f i n t e r r u p t i m a s k a b l e i n t e r r u p t . m e a n se x i s t s t p r e v e n t t h i n t e r r u p t f r o m b e i n g s e r v i c e d . A i n t e r r u p t m a b " m a s k e d " ( m a d e s i c a n ' t b s e e n b t h e 6 5 0 2 ) b t h m e a n s o a " i n t e r r u p t d i s a b l e " b i i t h P r o c e s s o r S t a t u s r e g i s t e r . M a s k a b l e

Page 56: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 56/172

I n i i d t T h C o m m o d o r t 6 P a g e 7 -

i n t e r r u p t s a r e t h o s e w h o s e e l e c t r i c a l c o n n e c t i o n s a r e t o t h e I R p i o t h 6 5 0 2 .

B o t h k i n d s o i n t e r r u p t s a r e h a n d l e d i a b o u t t h s a m e w a b t h e 6 5 6 2 . T h 6 5 0 2 f i n i s h e s p r o c e s s i n g t h i n s t r u c t i o n w h i c h w a i p r o g r e s s w h e n t h i n t e r r u p t s i g n a l w a r e c o g n i z e d . I t h e n s a v e s t h P o t h e s t a c k j u s t a i J S h a b e e n e x e c u t e d . A d d i t i o n a l l y , i s a v e s t h P r o c e s s o r S t a t u s R e g i s t e r o t h e s t a c k a n d e c r e m e n t s t h s t a c k b y t h r e e . I n o l o a d s t h P w i t h t h a d d r e s s f o u n d i l o c a t i o n $ F F F A a n $ F F A B f o N M i n t e r r u p t o $ F F F E a n * F F F F f o n o n - m a s k a b l e i n t e r r u p t . T h e s e l o c a t i o n s m u s t h a v e b e e n p r e - p r o g r a m m e dt o c o n t a i n t h e a d d r e s s e s o f t h e p r o g r a m s w h i c h w e r e w r i t t e n t o s e r v i c et h i n t e r r u p t s .

T h i n t e r r u p t p r o c e s s i n g r o u t i n e s m u s t b e e x i t e d v i R T i n s t r u c t i o n ( R e t u r n f r o m I n t e r r u p t ) . T h i s a c t s l i k e t h R T i n s t r u c t i o n e x c e p t t h a t t h e P r o c e s s o r S t a t u s R e g i s t e r i r e l o a d e d f r o mt h e s t a c k b e f o r e t h P i p u l l e d f r o m t h s t a c k . I n t h i s f a s h i o n ,t h e i n t e r r u p t e d p r o g r a m m a c o n t i n u e w h e r e i w a i n t e r r u p t e d a n t h s t a t u s o f t h e m a c h i n e w i l l b a i w a a t t h e t i m e o i n t e r r u p t i o n .

T h s t a c k i a l s o u s e d b t h P H a n P H i n s t r u c t i o n s t s t o r e t h A - r e g a n t h P - r e g r e s p e c t i v e l y i t h s t a c k . T h i s i u s e dt p a s s i n f o r m a t i o n t t h e s u b r o u t i n e . M o r e i n f o r m a t i o n a b o u t t h e s ei n s t r u c t i o n s m a b e f o u n d i C h a p t e r 5

T h P r o c e s s o r S t a t u s R e g i s t e r

T h P r o c e s s o r S t a t u s R e g i s t e r i c o l l e c t i o n o f e i g h t b i t s ,s o m e t i m e s c a l l e d f l a g s * w h i c h r e f l e c t a n c o n t r o l t h o p e r a t i o n o f t h e6 5 0 2 . T h b i a s s i g n m e n t o t h P - r e g i s

P - r e g b i p o s i t i o n 7 6 5 4 3 2 1 8S t a t u s - b i t l a b e l B D I Z C

T h N e g a t i v e B i

1 1 N " i t h N e g a t i v e - b i t . I i t u r n e d o b t h p r o c e s s o ru p o n t h e x e c u t i o n o f c e r t a i n i n s t r u c t i o n s . I r e f l e c t s w h e t h e r t h r e s u l t o a a d d i t i o n o s u b t r a c t i o n i n e g a t i v e o n o t . v a l u e i t h N e g a t i v e b i i n d i c a t e s a n e g a t i v e r e s u l t . T h i s b i t i s s e b l o a di n s t r u c t i o n s a n c o m p a r e i n s t r u c t i o n s t o o . S e t h c h a p t e r o t h 6 5 0 2 i n s t r u c t i o n s e f o c o m p l e t e e x p l a n a t i o n o e a c h i n s t r u c t i o n

Page 57: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 57/172

I n s i d e T h C o m m o d o r e 6 4 P a g e 7 -

a n h o e a c h a f f e c t s t h v a r i o u s s t a t u s b i t s .

T h O v e r f l o w B i

T h " V b i t i s t h o v e r f l o w b i t . I r e f l e c t s w h e t h e r o r n o t" t w o ' s c o m p l e m e n t " o v e r f l o w h a r e s u l t e d f r o m S B ( S u b t r a c t w i t hC a r r y ) i n s t r u c t i o n . I i a l s o s e t b t h B I i n s t r u c t i o n . S e t h d e s c r i p t i o n s o t h o s e i n s t r u c t i o n s f o r a m o r e c o m p l e t e e x p l a n a t i o n .

T h B r e a k B i T h " B b i i s e t b y t h e p r o c e s s o r w h e n B R i n s t r u c t i o n i

e x e c u t e d . T h B R i n s t r u c t i o n c a u s e s a i n t e r r u p t t o c c u r . I i s o f t w a r e i n t e r r u p t * u s e d m o s t l y i d e b u g g i n g m a c h i n e l a n g u a g ep r o g r a m s . T h B R i n t e r r u p t i p r o c e s s e d a l m o s t l i k e m a s k a b l ei n t e r r u p t . T h s a m e v e c t o r i u s e d b t h 6 5 0 2 t f i n d t h a d d r e s s o t h e i n t e r r u p t p r o c e s s i n g r o u t i n e . T h o n l y w a t h p r o c e s s i n gr o u t i n e c a k n o w i t h e i n t e r r u p t w a s o f t w a r e o h a r d w a r e i n t e r r u p ti b e x a m i n i n g t h e " B " b i i t h P r o c e s s o r S t a t u s R e g i s t e r w h i c h h a b e e n s t o r e d o t h s t a c k . T h B R i n o m a s k a b l e , b u i u s e s t h m a s k a b l e i n t e r r u p t v e c t o r . A l s o , t h r e t u r n a d d r e s s s t o r e d o n t h s t a c k i t h a d d r e s s o f t h e B R i n s t r u c t i o n p l u s t w o .

T h D e c i m a l M o d e B i

T h " D f l a g i t h P - r e g i c u t t h p r o c e s s o r t d a l A D a n S B i n s t r u c t i o n s i D e c i m a l m o d e . I d e c i m a l m o d e * t h d a t ab e i n g a d d e d o s u b t r a c t e d w i l l b a s s u m e d t b c o m p o s e d o t w d e c i m a l d i g i t s p e b y t e . E a c h d i g i t i c o d e d a s f o u r - b i t p a t t e r nh a v i n g t h r a n g e o v a l u e s $ $ 9 T h r a n g e o v a l u e s w h i c h c a n b c o n t a i n e d i b y t e i 0 - 9 9 d e c i m a l . T h n a m e o t h i s d a t a t y p e i B i n a r y C o d e d D e c i m a l ( B C D ) .

I t h D e c i m a l m o d e i c l e a r * t h A D a n S B i n s t r u c t i o n sw i l l t r e a t t h e d a t a b e i n g a d d e d a n d s u b t r a c t e d a e i g h t - b i t b i n a r yv a l u e s i t h r a n g e 0 - 2 5 5 .

T h " D b i m a b s e a n c l e a r e d b t h p r o g r a m w i t h S E a n C L i n s t r u c t i o n s .

Page 58: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 58/172

I n t i d t T h C o m m o d o r t 6 4 P a g t 7 -

T h I n t e r r u p t D i s a b l e b i

T h " I f l a g i t h e i n t e r r u p t - d i s a b l e f l a g . I m a b s e w i t ht h S E i n s t r u c t i o n a n c l e a r e d w i t h t h C L i n s t r u c t i o n . W h e n s e t to n l y n o n - m a s k a b l e a n s o f t w a r e i n t e r r u p t s m a o c c u r . W h e n C l e a r * a l i n t e r r u p t s a r e e n a b l e d .

T h Z e r o b i

T h " Z f l a g i s e l i k e t h e " N " f l a g , b a r i t h m e t i c a n l o a da n c o m p a r e i n s t r u c t i o n s . I t h e r e s u l t o f t h e s e o p e r a t i o n s g i v e sz e r o r e s u l t , t h Z - f l a g i s s e t . O t h e r w i s e i i c l e a r e d .

T h C a r r y b i

T h " C f l a g i t h C a r r y b i t . I t i s e b a d d i t i o n ,s u b t r a c t i o n , s h i f t a n c o m p a r e i n s t r u c t i o n s a w e l l a t h s p e c i f i cS S a n C L i n s t r u c t i o n s .

T h N , V , a n b i t s m a a l b t e s t e d b y c o n d i t i o n a l b r a n c hi n s t r u c t i o n s . f u l l e x p l a n a t i o n o t h i s f a c i l i t y i s p r o v i d e d i t h f o l l o w i n g c h a p t e r s .

T h 6 5 1 0 s p e c i a l c h a r a c t e r i s t i c s

T h e 6 5 1 0 h a b u i l t - i n I n p u t / O u t p u t ( I / O ) p o r t . T h e r e a r e i g h t p i n s o t h 6 5 1 0 w h i c h m a b e c o n n e c t e d t o t h e r p i e c e s o h a r d w a r e . T h r o u g h t h e s e p i n s , n u m b e r e d 0 - 7 , d a t a m a b t r a n s f e r e d o n b i a a t i m e . T h c o n n e c t e d e x t e r n a l p i e c e s , o h a r d w a r e m a t r a n s f e r d a t a d i r e c t l y t a n d f r o m t h m e m o r y o f t h e c o m p u t e r . T h d a t a m u s t b p l a c e d i m e m o r y l o c a t i o n f o i t b t r a n s f e r r e d t t h c o n n e c t e d I / d e v i c e . T h i s i t h s a m e a d d r e s s w h e r e t h d a t ap a s s e d b t h e x t e r n a l d e v i c e t o t h e 6 5 1 9 w i l l b f o u n d .

T h i n d i v i d u a l b i t s o l o c a t i o n m a b p r o g r a m m e d t b e i t h e ri n p u t b i t s o o u t p u t b i t s . T h i s i a c c o m p l i s h e d b y s e t t i n g t h c o r r e s p o n d i n g b i t s o f l o c a t i o n t o r e f l e c t t h d i r e c t i o n o f d a t at r a n s f e r . i a n g i v e n b i p o s i t i o n o f l o c a t i o n 0 w i l l c a u s e d a t at b t r a n s f e r r e d f r o m t h c o r r e s p o n d i n g b i p o s i t i o n o f l o c a t i o n t t h e d e v i c e a t t a c h e d t t h c o r r e s p o n d i n g I / p i o t h e 6 5 1 0 . i a n g i v e n b i p o s i t i o n o f l o c a t i o n 0 w i l l c a u s e d a t a t b t r a n s f e r r e d

Page 59: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 59/172

I n t i d t T h C o m m o d o r t 6 P a g e 7 -

f r o m t h d e v i c e a t t a c h e d t t h c o r r e s p o n d i n g I / p i o t h 6 5 1 0 t t h c o r r e s p o n d i n g b i p o s i t i o n o l o c a t i o n i I n p u t b i t s a r t h o s ew h i c h a r t u r n e d o o r o f f b y t h e c o n n e c t e d e x t e r n a l d e v i c e a i a l t e r s t h v o l t a g e l e v e l o f t h e e l e c t r i c a l s i g n a l w h i c h a p p e a r s a t h I / p i o t h e 6 5 1 e W h e n t h e d e v i c e p u t s h i g h v o l t a g e ( + v o l t s ) s i g n a l o t h c o n n e c t i n g p i a n t h d a t a d i r e c t i o n r e g i s t e r i s e a i n p u t * t h v a l u e w i l l a p p e a r i t h e c o r r e s p o n d i n g b i p o s i t i o n o f m e m o r y l o c a t i o n i l o s i g n a l ( v o l t s ) w i l l c a u s e t h v a l u e t b s t o r e d i t h c o r r e s p o n d i n g b i p o s i t i o n o f l o c a t i o n 1

O u t p u t b i t s a r t h o s e w h i c h a r e s t o r e d i l o c a t i o n b s o m ep r o g r a m r u n n i n g o t h e 6 5 1 0 . T h v a l u e o f t h b i t b t r a n s f e r r e d( e i t h e r o r 0 g e t s t r a n s l a t e d t a e l e c t r i c a l s i g n a l w h i c ha p p e a r s o n t h I / p o r t p i o t h e 6 5 1 0 . T h c o n n e c t e d o u t p u t d e v i c em u s t b e d e s i g n e d s u c h t h a t i u n d e r s t a n d s a v o l t a g e s i g n a l o f + v o l t st m e a n t h e v a l u e a n a v o l t a g e s i g n a l o f 0 v o l t s t o m e a n t h v a l u e0 F o d a t a t b e s e n t a d e s i r e d * l o c a t i o n m u s t h a v e i t h b i p o s i t i o n o f t h e d a t a t b t r a n s f e r r e d f r o m l o c a t i o n t o t h eo u t p u t d e v i c e .

L o c a t i o n i s c a l l e d t h d a t a d i r e c t i o n r e g i s t e r f o r t h e 6 5 1 0 ' sI / p o r t . L o c a t i o n i c a l l e d t h I / p o r t . T h e s e r e g i s t e r s d n o e x i s t o t h 6 5 0 2 a n a r w h a t d i s t i n g u i s h t h e t w m i c r o p r o c e s s o r s .

T h C o m m o d o r e 6 4 h a s d e d i c a t e d u s a g e o f t h e I / p o r t w h i c hw i l l b e x a m i n e d i l a t e r c h a p t e r s .

Page 60: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 60/172

I n s i d e T h C o m m o d o r e 6 4 P a g e 8 -

P r o c e s s i n gT h i n s t r u c t i o n s w i t h i n t h p r o g r a m w h i c h c o n t r o l t h p r o c e s s o r

c a u s e i t e i t h e r : 1 l o a d d a t a f r o m m e m o r y i n t o o n o i t i n t e r n a lr e g i s t e r s o 2 t m o v e d a t a f r o m o n e r e g i s t e r t a n o t h e r o 3 t s t o r e d a t a f r o m o n e o f t h e r e g i s t e r s i n t o m e m o r y o 4 t m o d i f y t h d a t a i o n o t h r e g i s t e r s b s o m e a r i t h m e t i c o p e r a t i o n o 5 t c a u s e c h a n g e i t h f l o w o t h p r o g r a m .T h 6 5 1 0 t a i d e c o d e s e a c h i n s t r u c t i o n a f t e r h a v i n g f e t c h e di f r o m m e m o r y * d i s c o v e r s t h r e e t h i n g s a b o u t t h i n s t r u c t i o n : i t h n u m b e r o b y t e s t h e i n s t r u c t i o n t a k e s i m e m o r y ; 2 t h a d d r e s s i n gm o d e o f t h e i n s t r u c t i o n ; 3 t h o p e r a t i o n t b p e r f o r m e d . T h o p e r a t i o n c o d e t a k e s o n l y o n b y t e f o e v e r y i n s t r u c t i o n b u s o m ei n s t r u c t i o n s n e e d t s u p p l y t h p r o c e s s o r a d d i t i o n a l i n f o r m a t i o nb e y o n d t h e o p - c o d e . T h i s i e i t h e r a d d r e s s i n f o r m a t i o n o r d a t a . I f f o e x a m p l e , a n i n s t r u c t i o n ' s p u r p o s e i t d i r e c t t h p r o c e s s o r t s t o r e t h d a t a c o n t a i n e d i n i t s r e g i s t e r i n t o s o m e l o c a t i o n i m e m o r y , i n e e d s t p r o v i d e t h 6 5 1 0 t h i n f o r m a t i o n a t w h e r e t s t o r e i t T h i s c o u l d t a k e o n o t w a d d i t i o n a l b y t e s d e p e n d i n g o nt h a d d r e s s i n g m o d e .

E a c h o p e r a t i o n c o d e h a c o d e d i n t o i t h i n f o r m a t i o n a t w h a t a d d r e s s i n g m o d e s h o u l d b u s e d t a c c o m p l i s h t h d e s i r e do p e r a t i o n . T h 6 5 1 0 h a t h i r t e e n a d d r e s s i n g m o d e s .

A B S O L U T E N O D E A b s o l u t e a d r e s s i n g r e q u i r e s a t h r e e b y t e i n s t r u c t i o n .T h * i r s x i t h o p - i o d e a n t h n e x t t w a r t h t w b y t e s o a d d r e s si n f o r m a t i o n .

Y o r e c a l l t h a t i t a k e s t w b y t e s s i x t e e n b i t s t s p e c i f y a n a d d r e s s i t h 6 5 1 0 a d d r e s s s p a c e . T h i s i b e c a u s e t h a d d r e s s b u i s i x t e e n b i t s w i d e . T h f i r s t b y t e o t h t w b y t ea d d r e s s i c a l l e d t h h i g h - o r d e r b y t e o t h m o s t - s i g n i f i c a n t b y t e o t h a d d r e s s . T h s e c o n d b y t e i t h l o w - o r d e r o l e a s t s i g n i f i c a n tb y t e . T h e s e a r s o m e t i m e s a b b r e v i a t e d t h M S a n t h L S B . T h 6 5 1 0 ,w h e n i e x e c u t e s i n s t r u c t i o n s w i t h a b s o l u t e a d d r e s s i n g , s i m p l y f e t c h e st h n e x t t w b y t e s a f t e r t h o p - c o d e a n d p u t s t h e m o t h a d d r e s s b u sw h e n i d o e s t h m e m o r y a c c e s s o p e r a t i o n s p e c i f i e d b y t h e o p - c o d e .T h m e m o r y d e v i c e s , w h i c h a r a t t a c h e d t o t h e a d d r e s s b u s a n t h d a t a

Page 61: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 61/172

I n i i d t T h C o m m o d o r t 6 P a g e 8 *

b u a n t h c o n t r o l b u s * a r s i g n a l e d b t h R / s i g n a l a n r e a d t h a d d r e s s i n f o r m a t i o n o f t h a d d r e s s b u t o s e l e c t t h m e m o r y l o c a t i o nt e i t h e r s t o r e d a t a i n t o o r e a d d a t a o u o f I t h R / s i g n a ls i g n i f i e s W r i t e , i w i l l t a k e t h e d a t a f r o m t h d a t a b u a n s t o r e i i n t o t h e m e m o r y l o c a t i o n s p e c i f i e d b t h a d d r e s s o n t h a d d r e s s b u s .I i i R e a d s i g n a l , i w i l l t a k e t h e d a t a a l r e a d y s t o r e d a t h s p e c i f i e d l o c a t i o n a n l o a d i o n t o t h d a t a b u w h e r e t h 6 5 1 0 w i l lf i n d i a n d w h a t e v e r t h o p - c o d e i n d i c a t e d s h o u l d b d o n e w i t h i t I a b s o l u t e m o d e , t h a d d r e s s i s t o r e d a f t e r t h o p - c o d e w i t h t h el e a s t s i g n i f i c a n t b y t e i m m e d i a t e l y f o l l o w i n g t h o p - c o d e a n t h m o s ts i g n i f i c a n t b y t e f o l l o w i n g t h a t . E x a m p l e :

L D A $ 4 5 2 i2 0 C 0 A 4

T h i s i a e x a m p l e o b o t h a n a s s e m b l y l a n g u a g e s t a t e m e n t o t h f i r s t l i n e a n t h m a c h i n e l a n g u a g e f o l l o w i n g i t T h f o r m a t i t h s a m e a t h a t w h i c h a p p e a r s o t h s c r e e n w h e n y o r u T h A s s e m b l e r .T h e a s s e m b l y l a n g u a g e m n e m o n i c i L D A . I i t h a s s e m b l y l a n g u a g ee q u i v a l e n t o t h o p - c o d e . I m e a n s L o a d t h r e g i s t e r . T h A s s e m b l e r , w h i c h c o n v e r t s a s s e m b l y l a n g u a g e i n t o m a c h i n e l a n g u a g e ,d e c o d e s t h m n e m o n i c a n t h e f o l l o w i n g o p e r a n d a n d p r o d u c e s t h m a c h i n e l a n g u a g e w h i c h a p p e a r s o t h s e c o n d l i n e . T h A s s e m b l e ra l s o p r o d u c e s c a s s e t t e o d i s k e t t e f i l e c o n t a i n i n g t h m a c h i n el a n g u a g e w h i c h T h L o a d e r c a n t h e n r e a d a n s t o r e i t h a p p r o p r i a t em e m o r y l o c a t i o n s , w h e r e f i n a l l y i c a n b e e x e c u t e d a s p r o g r a m .

F o n o w , l e t s j u s t l o o k a t h t w s t a t e m e n t s a t h e y a p p e a rh e r e . T h $ 4 5 2 1 i c a l l e d t h o p e r a n d f i e l d . I s p e c i f i e s t t h 6 5 1 0 w h e r e t h d a t a t b e l o a d e d i n t o t h r e g i s t e r i t b f o u n d .T h e 2 0 C 0 i t h a d d r e s s w h e r e t h e i n s t r u c t i o n i l o c a t e d . I w a a r b i t r a r i l y p i c k e d f o r t h i s e x a m p l e . T h s e c o n d f i e l d , $ A D , i t h h e x r e p r e s e n t a t i o n f o r t h e o p - c o d e . F o l l o w i n g t h o p - c o d e i $ 2 1 , t h es e c o n d b y t e o t h a d d r e s s s p e c f i e d i t h a s s e m b l y s t a t e m e n t a b o v e .I i f o l l o w e d b y $ 4 5 , t h e f i r s t b y t e o t h a d d r e s s . T h i s i t h o r d e r t h 6 5 1 0 e x p e c t s t f i n d a d d r e s s e s . T h 6 5 1 0 p r o c e s s e s t h i si n s t r u c t i o n w h e n i t P r o g r a m C o u n t e r h a t h e v a l u e o $ 2 0 C 0 . I f e t c h e s t h o p - c o d e a t h a t a d d r e s s a n d e c o d e s i a n d e x e c u t e s i i t h e f o l l o w i n g s e q u e n c e : i I d e t e r m i n e s f r o m t h o p - c o d e o $ A t h a tt h i s i a i n s t r u c t i o n t c a u s e t h r e g i s t e r t b e l o a d e d f r o ml o c a t i o n w h o s e a d d r e s s i w i l l f i n d i m m e d i a t e l y a f t e r t h o p - c o d e . 2

Page 62: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 62/172

I n s i d e T h C o m m o d o r e 6 P a g e 8 -

I f e t c h e s t h e n e x t b y t e a f t e r t h e o p - c o d e * $ 2 1 , a n d p u t s i o t h l e a s t s i g n i f i c a n t b / t e o t h a d d r e s s b u s . 3 ) I t f e t c h e s t h n e x tb y t e * $ 4 5 , a n p u t s i o t h m o s t s i g n i f i c a n t b y t e o f t h e a d d r e s sb u s . 4 I s e t s t h R / l i n e t o R . 5 I w a i t s f o t h m e m o r y d e v i c et g e t h s p e c i f i e d d a t a a n d p u t i o t h d a t a b u s . 6 I r e a d st h d a t a f r o m t h d a t a b u a n p u t s i i i t r e g i s t e r . 6 I i n c r e a s e s t h P C H t P C L r e g i s t e r p a i r b s t h a t i n o p o i n t s t t h n e x t o p - c o d e .

T h i s i c o m p l e t e i n s t r u c t i o n c y c l e .

Z E R O P A G E M O D E I y o t a k e t h e s i x t e e n b i a d d r e s s b u s a n s p l i t i i h a l f , t h f i r s t e i g h t b i t s c o u l d b t h o u g h t o a " p a g e n u m b e r "a n t h s e c o n d e i g h t b i t s c o u l d t h e n r e p r e s e n t t h a d d r e s s ( f r o m2 5 5 ) w i t h i n t h a t p a g e . T h i s w o u l d m e a n t h a t t h e r e a r e 2 5 p o s s i b l ep a g e s , e a c h w i t h 2 5 m e m o r y l o c a t i o n s . Z e r o P a g e w o u l d t h e n r e p r e s e n ta l m e m o r y l o c a t i o n s f r o m $ 0 0 0 0 t $ 0 0 F F ( t 2 5 5 ) . P a g e o n w o u l di m m e d i a t e l y f o l l o w , c o n t a i n i n g t h a d d r e s s e s $ 0 1 0 0 t $ 0 I F F ( 2 5 6 t 5 1 1 ) .

T h e s e a r t w p a g e s w h i c h h a v e s p e c i a l s i g n i f i c a n c e f o t h 6 5 1 0 . P a g e z e r o a d d r e s s e s m a b s p e c i f i e d w i t h c e r t a i n m a c h i n el a n g u a g e i n s t r u c t i o n s w h i c h a r s p e c i f i c a l l y c o d e d a s Z e r o P a g ea d d r e s s i n g m o d e . P a g e o n e i d e s i g n a t e d t h e s t a c k p a g e a s e x p l a i n e di t h p r e v i o u s c h a p t e r . M o r e a b o u t t h a t l a t e r . T h d e s i g n e r s o f t h e6 5 1 0 d e c i d e d i w o u l d b g o o d t h a v e a a d d r e s s i n g m o d e w h i c h a l l o w e dt h 6 5 1 0 t e x e c u t e i n s t r u c t i o n s f a s t e r a n w o u l d c o n s u m e l e s s m e m o r y .T h Z e r o P a g e a d d r e s s i n g m o d e w a p a r t o t h s o l u t i o n . T h a d d r e s s i n g m o d e i s p e c i f i e d a a p a r t o t h o p - c o d e . I d e c o d i n gt h o p - c o d e , t h e 6 5 1 0 , u p o n d e t e r m i n i n g t h a t t h e a d d r e s s i n g m o d e i Z P t h e n k n o w s t h a t t h a d d r e s s t b e a c c e s s e d i i z e r o p a g e . I t h e r e f o r e h a o n l y t o l o a d o n m o r e b y t e o f a d d r e s s i n g d a t a , t h l o w -o r d e r o l e a s t - s i g n i f i c a n t p o r t i o n o f t h e a d d r e s s . T h h i g h - o r d e rh a l f o t h a d d r e s s w i l l b f o r c e d t $ 0 b y t h e 6 5 1 0 . T h e r e f o r e ,Z e r o P a g e i n s t r u c t i o n s a r e o n l y t w b y t e s l o n g ; t h o p - c o d e a n t h a d d r e s s w i t h i n z e r o p a g e w h e r e t h d a t a i t b s t o r e d o f o u n d .E x a m p l e :

S T B $ 7 C2 0 C 0 8 7

T h l e f t - a r r o w i t h c o d e t t h a s s e m b l e r t h a t t h i s i Z e r o

Page 63: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 63/172

I n s i d e T h C o m m o d o r e 6 4 P t g t 8 - 4

P a g e i n s t r u c t i o n . T h e a d d r e s s s p e c i f i e d b t h o p e r a n d i $ 0 0 7 C .T h i s i a S t o r e t h A - r e g i n s t r u c t i o n . O p - c o d e $ 8 5 c a u s e s t h c o n t e n t s o t h A - r e g t b e s t o r e d i n t o t h e s p e c i f i e d z e r o p a g e m e m o r yl o c a t i o n ( $ 0 0 7 C i t h i s e x a m p l e ) .

I M M E D I A T E M O D E S o m e i n s t r u c t i o n s m a d i r e c t t h p r o c e s s o r t f i n dt h n e e d e d d a t a i m m e d i a t e l y a f t e r t h e o p - c o d e r a t h e r t h a n h a v i n g t g t s o m e s p e c i f i e d a d d r e s s t f i n d i t T h e s e a r t w o - b y t ei n s t r u c t i o n s , o n f o r t h e o p - c o d e , o n f o r t h e d a t a . T h e y e x e c u t ee v e n f a s t e r t h a n t h z e r o p a g e i n s t r u c t i o n s b e c a u s e t h 6 5 1 0 n e e d n ' tp u a n y t h i n g o t h a d d r e s s b u s o w a i t f o a n o t h e r f e t c h c y c l e t c o m p l e t e b e f o r e i g e t s t h d a t a i n e e d s . E x a m p l e :

S B # 2 2 0 C 0 E 1

N o t e h e r e t h a t t h o p e r a n d f i e l d h a " # p r e c e e d i n g t h d a t av a l u e . T h i s i t h c o d e t T h e A s s e m b l e r t h a t t h i s i a n I m m e d i a t eM o d e i n s t r u c t i o n . N o t e a l s o t h a t n " $ p r e c e e d s t h v a l u e 2 5 T h A s s e m b l e r r e c o g n i z e s f o u r d a t a t y p e s , d e c i m a l , h e x a d e c i m a l , s y m b o l i cl a b e l s a n A S C I I c h a r a c t e r . H e x n u m b e r s a r i n d i c a t e d b l e a d i n g" $ " , A S C I I c h a r a c t e r s b y ' d e c i m a l n u m b e r s b f i r s t c h a r a c t e ro 0 - 9 , a n d s y m b o l i c l a b e l s e v e r y t h i n g e l s e . I e v e r y c a s e , T h A s s e m b l e r w i l l c o n v e r t t h e s p e c i f i e d d a t a v a l u e i n t o b i n a r y ( o h e i y o w i s h , t h s h o r t h a n d n o t a t i o n f o r b i n a r y ) w h i c h i a l t h 6 5 1 0 c a u l t i m a t e l y u n d e r s t a n d . T h s e c o n d l i n e d i s p l a y s t h e m a c h i n e l a n g u a g ei t h s a m e f o r m a t a b e f o r e . T h f i r s t f i e l d i t h a d d r e s s i h e w h e r e t h e i n s t r u c t i o n w i l l r e s i d e , f o l l o w e d b y t h o p - c o d e i h e x ,f o l l o w e d b t h d a t a v a l u e i h e a l s o . C h e c k f o y o u r s e l f t h a t $ 1 i t h s a m e t h i n g a d e c i m a l 2 5

T h A s s e m b l e r h a a o p t i o n y o m a s e l e c t e a c h t i m e i i r u t p r i n t t h a d d r e s s e s a n d g e n e r a t e d m a c h i n e l a n g u a g e i e i t h e rd e c i m a l o h e x . T h f i l e w h i c h i c r e a t e d f o l o a d i n g b y T h L o a d e rw i l l a l w a y s c o n t a i n h e x a d e c i m a l .

S B s t a n d s f o S u b t r a c t w i t h C a r r y . I i a i n s t r u c t i o n t S u b t r a c t t h s p e c i f i e d d a t a v a l u e f r o m t h c o n t e n t s o f t h e A - r e g a n t s t o r e t h e r e s u l t b a c k i t h A - r e g .

O n f u r t h e r n o t e : M o s t i n s t r u c t i o n s m a b s p e c i f i e d w i t h av a r i e t y o a d d r e s s i n g m o d e s . T h e A s s e m b l e r e x a m i n e s t h o p e r a n d f i e l d

Page 64: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 64/172

I n s i d e T h C o m m o d o r e 6 P a g e 8 -

t d e t e r m i n e w h i c h a d d r e s s i n g m o d e i b e i n g s p e c i f i e d . I t h e ng e n e r a t e s t h p r o p e r m a c h i n e l a n g u a g e o p - c o d e t i n d i c a t e b o t h t h o p e r a t i o n t b p e r f o r m e d a n d t h a d d r e s s i n g m o d e . A a e x a m p l e ," S B C $ 4 F F 3 " i a a b s o l u t e m o d e v e r s i o n o t h S B i n s t r u c t i o n a n t h o p - c o d e f o i i $ B a c o m p a r e d w i t h $ B a i t h a b o v e e x a m p l e .A p p e n d i x c o n t a i n s l i s t o a l i n s t r u c t i o n s a n t h e i r a l l o w a b l ea d d r e s s i n g m o d e s .

I M P L I E D M O D S T h i m p l i e d m o d e o a d d r e s s i n g i t h f a s t e s t e x e c u t i n ga n t h s h o r t e s t i n s t r u c t i o n l e n g t h . I n i m p l i e d m o d e , o n l y t h ei n t e r n a l r e g i s t e r s o f t h e 6 5 1 0 a r a d d r e s s e d . B e y o n d t h e o p - c o d e , n m o r e i n f o r m a t i o n i r e q u i r e d * s i m p l i e d m o d e o n l y t a k e s o n b y t e .E x a m p l e s * .

T A 0 2 3 F A

T Y 0 2 4 0 9

T A c a u s e s t h e c o n t e n t s o f t h e A - r e g t b e t r a n s f e r r e d t o t h eX - r e g . T Y c a u s e s t h c o n t e n t s o f t h e Y - r e g t b t r a n s f e r r e d t o t h eA - r e g .

A - R B G M O D E T h e A - r e g i s o m e t i m e s c a l l e d t h A c c u m u l a t o r . T h i s i c a r r y o v e r f r o m m o r e p r i m i t i v e t i m e s . I a n e v e n t , C o m m o d o r e a n M O T e c h n o l o g y c h o o s e t o r e f e r t o t h e A - r e g M o d e a t h A c c u m u l a t o r M o d e .C a l l i w h a t y o l i k e * i i r e a l l y a i m p l i e d m o d e . I A - r e g M o d e ,o n l y t h e A - r e g a n t h e C a r r y * N e g a t i v e a n Z e r o b i t s o f t h e S t a t u sr e g i s t e r a r e a f f e c t e d . T h e A - r e g m o d e i n s t r u c t i o n s a r e v a l i d o n l y f o t h " s h i f t " i n s t r u c t i o n s * A S L * R O L * L S a n R O R . F o r m o r e i n f o r m a t i o no s h i f t i n s t r u c t i o n s * s e t h n e x t c h a p t e r . E x a m p l e s :

R O 0 2 1 A 6

A S L A0 2 1 B 0

R E L A T I V E M O D S T h e r e a r t h r e e c l a s s e s o f i n s t r u c t i o n s w h i c h c a u s et h f l o w o t h p r o g r a m t c h a n g e . T h J M a n J S i n s t r u c t i o n s a r ee x p l a i n e d i t h f o l l o w i n g c h a p t e r . A l l t h r e e t y p e s o i n s t r u c t i o n s

Page 65: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 65/172

I n s i d e T h C o m m o d o r e 6 4 P * g t 8 -

a c c o m p l i s h p r o g r a m f l o w c h a n g e s i t h s a m e g e n e r a l w a y . T h e y c a u s et h P r o g r a m C o u n t e r r e g i s t e r t o b m o d i f i e d . T h P i t h e r e g i s t e rp a i r w h i c h p o i n t s t w h e r e t h n e x t i n s t r u c t i o n i t b e f o u n d i m e m o r y . I i a u t o m a t i c a l l y i n c r e m e n t e d b t h e i n s t r u c t i o n l e n g t he a c h t i m e a i n s t r u c t i o n i e x e c u t e d . T h i n s t r u c t i o n s w h i c h m o d i f yt h P c a u s e t h p r o g r a m t " t a k e a b r a n c h " . T h a t i s t h n e x ti n s t r u c t i o n t o b e x e c u t e d w i l l n o t b e t h o n i m m e d i a t e l y f o l l o w i n g .I w i l l b f o u n d a a n a d d r e s s w h i c h i d e t e r m i n e d b t h a d d r e s s i n gd a t a s u p p l i e d b t h b r a n c h i n g i n s t r u c t i o n .

T h a d d d r e s s i n g i n f o r m a t i o n s u p p l i e d b y t h " r e l a t i v e m o d e "i n s t r u c t i o n s i s i n g l e b y t e o d a t a w h i c h f o l l o w s t h o p - c o d e a n dw h i c h i a d d e d t o t h e v a l u e o f t h e P t d e t e r m i n e t h n e w P C v a l u e .T h b r a n c h i t a a d d r e s s w h i c h i t h e s p e c i f i e d n u m b e r o b y t e sa w a y f r o m t h b r a n c h i n s t r u c t i o n i t s e l f . T h a d d r e s s i n f o r m a t i o n i c a l l e d t h r e l a t i v e d i s p l a c e m e n t .

T h e s e i n s t r u c t i o n s o n l y m o d i f y t h P s o m e t i m e s . T h e y a r c a l l e d c o n d i t i o n a l b r a n c h i n s t r u c t i o n s . T h e y t e s t t h s t a t u s o f b i i t h P r o c e s s o r S t a t u s R e g i s t e r a n d t h 6 5 1 0 d e c i d e s a t h t i m e t h i n s t r u c t i o n i e x e c u t e d w h e t h e r t B r a n c h m o d i f y t h P o n o t *b a s e d u p o n t h e v a l u e o f t h e b i b e i n g t e s t e d . E x a m p l e :

C M # ' 8 3 8 8 C 4 B N N O T A 8 3 8 2 D 8 J M P R O C E S S A 0 3 0 5 4 C ? D 0

N O T A C M P # ' B 0 3 0 8 C 4 B E P R O C E S S B 0 3 8 A F C

T h i s i a s h o r t p r o g r a m s e g m e n t w h i c h f i r s t c o m p a r e s t h c o n t e n t s o t h A - r e g w i t h t h e c h a r a c t e r " A " . T h f o r m a t o t h p r o g r a m l i s t i n g i t h s a m e a t h a t w h i c h i p r o d u c e d b T h e A s s e m b l e rw h e n p r i n t e r o u t p u t i e m p l o y e d . N o t e t h I m m e d i a t e s y m b o l * " # a n t h " c h a r a c t e r " s y m b o l " ' " T h f u n c t i o n o f t h e c o m p a r e i n s t r u c t i o ni t s e t h Z e r o b i i t h s t a t u s r e g i s t e r i t h c o m p a r e p r o v e s t b a m a t c h . O t h e r w i s e t h e Z e r o b i t i s c l e a r e d .

T h i n s t r u c t i o n a f t e r t h e c o m p a r e i t h c o n d i t i o n a l b r a n c hi n s t r u c t i o n . I i B r a n c h N o E q u a l i n s t r u c t i o n . I t h r e s u l t o ft h c o m p a r e r e s u l t s i t h z e r o f l a g b e i n g s e t t t h b r a n c h w i l l n o h a p p e n a n t h J M i n s t r u c t i o n f o l l o w i n g t h e B N w i l l b e e x e c u t e d n e x ta u s u a l . I n o t » t h n e x t i n s t r u c t i o n t b e x e c u t e d w i l l b t h

Page 66: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 66/172

I n s i d e T h C o m m o d o r e 6 P a g e 8 -

i n s t r u c t i o n a t $ 0 3 0 8 .H e r e y o u s e o n o f t h e g r e a t a d v a n t a g e s o h a v i n g a

a s s e m b l e r w h i c h a l l o w s y o t u s l a b e l s t o i d e n t i f y p r o g r a ml o c a t i o n s . Y o u * t h e p r o g r a m m e r c a u s e m e a n i n g f u l s y m b o l s t r e f e r t s o m e a d d r e s s i m e m o r y . Y o w r i t e t h e a s s e m b l y l a n g u a g e p r o g r a mw i t h o u t r e g a r d t t h a c t u a l a d d r e s s e s o e a c h i n s t r u c t i o n i t h p r o g r a m . I y o w a n t t c a u s e t h p r o g r a m t b r a n c h t s o m ei n s t r u c t i o n s o m e w h e r e i t h p r o g r a m , y o p u l a b e l i E n g l i s h o t h i n s t r u c t i o n a n T h A s s e m b l e r a u t o m a t i c a l l y c o m p u t e s t h a d d r e s so f t h e i n s t r u c t i o n f o r y o u . I n t h i s c a s e t h s y m b o l i c l a b e l i " N O T A " .

A s s e m b l e r s w h i c h p e r m i t t h i s c a p a b i l i t y a r c a l l e d s y m b o l i ca s s e m b l e r s . S i n g l e - l i n e a s s e m b l e r s s u c h a i i n c o r p o r a t e d i 6 4 M O Na r e s e v e r e l y l i m i t e d b t h e i r l a c K o t h i s f e a t u r e .

T h g e n e r a t e d m a c h i n e l a n g u a g e i p a r t i c u l a r l y i n t e r e s t i n gh e r e . T h b y t e f o l l o w i n g t h B N o p - c o d e i " $ 9 3 " . R e l a t i v ea d d r e s s s i n g m e a n s t h a t t h v a l u e f o u n d i t h e b y t e a f t e r t h e o p - c o d ei t h n u m b e r t b a d d e d t t h P t f i n d t h a d d r e s s t b B r a n c h e dt o T h a t i s i t h 6 5 1 0 f i n d s t h a t t h s t a t u s b i b e i n g t e s t e d b yt h B r a n c h i n s t r u c t i o n i n d i c a t e s a B r a n c h s h o u l d b t a k e n , i t h e na d d s t h e v a l u e f o u n d i t h b y t e a f t e r t h o p - c o d e t o t h e P C ( I h a a l r e a d y i n c r e m e n t e d t h P b t w b e f o r e t e s t i n g t h s t a t u s b i t ) . T h A s s e m b l e r a u t o m a t i c a l l y c o m p u t e s t h e d i f f e r e n c e b e t w e e n t h a d d r e s s o t h i n s t r u c t i o n f o l l o w i n g t h B N i n s t r u c t i o n a n t h b e g i n n i n g o f t h ei n s t r u c t i o n N O T A . I n t h i s c a s e t h a m o u n t o a d j u s t m e n t i t h r e eb y t e s . N O T A o c c u r s t h r e e b y t e s p a s t t h a d d r e s s o f t h e J M i n s t r u c t i o n . I i p o s s i b l e t o s p e c i f y c o n d i t i o n a l b r a n c h f o r w a r db a s m u c h a 1 2 b y t e s o b a c k w a r d s a . m u c h a 1 2 b y t e s . W h e nb a c k w a r d b r a n c h e s a r s p e c i f i e d , t h d i s p l a c e m e n t v a l u e i t h b y t ea f t e r t h e o p - c o d e m u s t c o n t a i n a n e g a t i v e n u m b e r .

W m e n t i o n e d e a r l i e r t h a t s i n g l e b y t e m a r e p r e s e n t t h d e c i m a l r a n g e o 0 - 2 5 5 . F o s p e c i a l s i t u a t i o n s s u c h a t h r e l a t i v eb r a n c h i n s t r u c t i o n s i i c o n v e c t e n i e n t t a l l o w t h 2 5 p o s s i b l e v a l u e so f t h e e i g h t b i t s t o r e p r e s e n t r a n g e o n u m b e r s f r o m - 1 2 8 t + 1 2 7 .T a c c o m o d a t e t h i s n e e d , s y s t e m w a d e v i s e d t i n d i c a t e n e g a t i v en u m b e r s . I i s c a l l e d t h t w o ' s c o m p l e m e n t s y s t e m . I s e e m s l i t t l es t r a n g e a f i r s t , b u t w i t h l i t t l e p r a c t i c e i t t o o , c a n b e m a s t e r e d .

N e g a t i v e o n e i r e p r e s e n t e d a $ F F . N e g a t i v e t w i r e p r e s e n t e d a s $ F ( o 2 5 i r e g u l a r d e c i m a l ) . Y o c a n c o n v e r tn u m b e r t i t n e g a t i v e b y s u b t r a c t i n g i f r o m 2 5 6 t h e n c o n v e r t i n g t h e

Page 67: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 67/172

I n s i d e T h C o m m o d o r e 6 P a g e 8 -

r e s u l t t h e x . F o e x a m p l e , t h h e x r e p r e s e n t a t i o n o f - 6 i 2 5 6 -6 = 2 5 0 = $ F A . T h i s s y s t e m i p o p u l a r w i t h c o m p u t e r d e s i g n e r s b e c a u s e i m a k e s a r i t h m e t i c e a s y . N o t e t h a t 2 5 i h e i $ 0 1 0 0 . S u b t r a c t i n gs i f r o m $ 0 1 0 0 g i v e s $ F A . B u t $ 0 1 0 0 t a k e s t w b y t e s . T h m a x i m u mv a l u e o o n b y t e i $ F F . I w a d d o n e t $ F F w e g e $ 0 w i t hc a r r y o o n e . A n w i t h $ F r e p r e s e n t i n g - i i y / e r y n i c e t h a t w h e nw a d t o - 1 w g e 0 L i k e w i s e w h e n w a d t m i n u s ( $ F S ) w g e $ F ( - i ) . A n o t h e r a d v a n t a g e o f t h i s s y s t e m i t h a t a l t h n e g a t i v e n u m b e r s h a v e t h h i g h - o r d e r b i o ( l e f t m o s t b i v a l u e i ) T h p o s i t i v e n u m b e r s a r $ 0 ( 0 0 0 0 0 0 0 0 ) t $ 7 ( 0 1 1 1 i l i l ) a n t h n e g a t i v e n u m b e r s a r $ 8 ( 1 0 0 0 0 0 0 0 ) t o $ F ( 1 1 1 1 1 1 1 1 ) . I i n o c o i n c i d e n t a l t h a t t h e N - f l a g ( N e g a t i v e b i o t h S t a t u s R e g i s t e r ) i s e t e v e r y t i m e a n a r i t h m e t i c o p e r a t i o n r e s u l t s i a v a l u e w i t h t h h i g h - o r d e r b i o n

T h e A s s e m b l e r w i l l a u t o m a t i c a l l y c o n v e r t r e l a t i v e b r a n c hd i s p l a c e m e n t s t o t h e p r o p e r v a l u e f o b o t h f o r w a r d a n d b a c k w a r db r a n c h e s . A n T h e A s s e m b l e r w i l l a l s o a l l o w t h e x p r e s s i o n o n e g a t i v e n u m b e r s i t h m o r e f a m i l i a r f o r m a t o d e c i m a l n u m b e r s - 3 4 ,- 1 2 2 , e t c . a n d t h c o n v e r s i o n t t h t w o ' s c o m p l e m e n t v a l u e f o y o u . I d e b u g g i n g , h o w e v e r , i s o m e t i m e s c o m e s i h a n d y t b a b l e t d t h c o n v e r s i o n y o u r s e l f a n i w o r t h k n o w i n g h o t d o

I N D E X E D N O D E S T h r e g i s t e r a n t h r e g i s t e r a r e s o m e t i m e s c a l l e dt h e i n d e x r e g i s t e r s . T h i s i b e c a u s e t h e y a r u s e d a s i n d e x e s t d a t a . T h a t i s t h r e l a t i v e p o s i t i o n o f d a t a i s t r i n g m a b a d d r e s s e d b s p e c i f y i n g a b a s e o s t a r t i n g a d d r e s s o t h s t r i n g p l u ss o m e p o s i t i o n i n d e x t i n d i c a t e w h i c h d a t a e l e m e n t i t h s t r i n g i b e i n g a d d r e s s e d . T h a n r e g i s t e r s c a n b e u s e d w i t h c e r t a i ni n s t r u c t i o n s t b t h p o s i t i o n i n d e x . T h i n s t r u c t i o n s p e c i f i e sb a s e a d d r e s s a n a i n d e x r e g i s t e r . T h 6 5 1 0 a d d s t h v a l u e o f t h i n d e x r e g i s t e r t o t h e b a s e a d d r e s s t g e t h e f f e c t i v e a d d r e s s o f t h ed a t a t b a c c e s s e d . T h i s i v e r y u s e f u l c a p a b i l i t y . T h f o l l o w i n gp r o g r a m s e g m e n t i l l u s t r a t e s t h u s o i n d e x e d a d d r e s s i n g t m o v es t r i n g o d a t a f r o m o n e p l a c e i m e m o r y t a n o t h e r :

Page 68: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 68/172

I n s i d t T h C o m m o d o r e 6 P a g t 8 -

S T R I N 6 1S T R I N G 2

L O O P

E Q E Q E Q L D L D S T D E B P

$ 8 4 8 8$ 8 4 8 8$ 2 8 8 8# 1 S T R I N G 1 , XS T R I N G 2 , X

L O O P

8 4 8 88 4 8 82 8 8 82 8 8 82 8 8 22 8 8 52 8 8 82 8 8 9

A B 9 C 1

8 8 8

F

8 8

S e v e r a l n e t h i n g s a r e p r e s e n t e d i t h i s p r o g r a m s e g m e n t . T h f i r s t t w s t a t e m e n t s c a u s e T h e A s s e m b l e r t e q u a t e a s y m b o l i c l a b e lw i t h s p e c i f i c a d d r e s s i m e m o r y . F o r e v e r y s u b s e q u e n t r e f e r e n c e t t h l a b e l b e i n g E Q U a t e d ( S T R I N G 1 i t h i s e x a m p l e ) T h A s s e m b l e r w i l lK n o w t h a t t h e a d d r e s s b e i n g r e f e r r e d t o i t h o n i t h o p e r a n df i e l d o f t h e E Q s t a t e m e n t ( $ 0 4 0 8 ) . N o t e t h g e n e r a t e d m a c h i n el a n g u a g e w h i c h f o l l o w s t h e s t a t e m e n t ; L O O P L D S T R I N G 1 , X . T h a d d r e s s $ 0 4 0 0 i a u t o m a t i c a l l y g e n e r a t e d b T h A s s e m b l e r ( i n t h er e q u i r e d l o w - o r d e r - b y t e - f i r s t f o r m a t ) .

T h t h i r d E Q U a t e t e l l s T h e A s s e m b l e r w h a t v a l u e t o a s s i g n t o t h eL o c a t i o n C o u n t e r . T h L o c a t i o n C o u n t e r i T h A s s e m b l e r ' s e q u i v a l e n to t h 6 5 i O ' s P r o g r a m C o u n t e r . T h d i f f e r e n c e i t h a t t h P r o g r a mC o u n t e r i a a c t u a l h a r d w a r e r e g i s t e r c o n t a i n e d o t h 6 5 1 0 c h i p .T h L o c a t i o n C o u n t e r i T h A s s e m b l e r ' s s y m b o l i c e q u i v a l e n t o t h P C T h a d d r e s s p r i n t e d o t h m a c h i n e l a n g u a g e l i n e a f t e r e a c h a s s e m b l yi n s t r u c t i o n i t h e v a l u e o f t h e L o c a t i o n C o u n t e r f o e a c h i n s t r u c t i o n .I s h o w s u w h e r e t h g e n e r a t e d m a c h i n e l a n g u a g e w i l l b i m e m o r yw h e n T h L o a d e r f i n a l l y l o a d s t h p r o g r a m i n t o m e m o r y . E v e r y E Q U a t es t a t e m e n t s e t s t h L o c a t i o n C o u n t e r t o t h e a d d r e s s e x p r e s s e d i t h o p e r a n d f i e l d o f t h e s t a t e m e n t .

T h L D i n s t r u c t i o n l o a d s t h X - r e g w i t h t h v a l u e 1 0 T h n e x t t w i n s t r u c t i o n s i l l u s t r a t e t h i n d e x e d a d d r e s s i n g m o d e . T h f i r s t i n s t r u c t i o n l o a d s t h A - r e g w i t h a b y t e o d a t a f o u n d a a d d r e s s$ 4 0 0 A . T h e a d d r e s s s p e c i f i e d i t h L D i n s t r u c t i o n i $ 0 4 0 0 . T h c o n t e n t s o t h X - r e g a r a d d e d t o t h e s p e c i f i e d a d d r e s s b t h 6 5 1 0b e f o r e p u t t i n g t h a d d r e s s o n t h a d d r e s s b u s . S i n c e t h e X - r e g h a J u s t b e e n l o a d e d w i t h t h v a l u e 1 0 t h a d d r e s s w h e r e t h d a t a w i l lc o m e f r o m t b l o a d e d i n t o t h A - r e g i $ 0 4 0 0 $ 0 0 0 A o $ 0 4 0 A .

T h n e x t i n s t r u c t i o n t u r n s r i g h t a r o u n d a n d s t o r e s t h a t s a m ed a t a b a c k i m e m o r y a t h a d d r e s s $ 0 4 8 A . S w e n o w h a v e t h r e e c o p i e s

Page 69: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 69/172

I n s i d e T h C o m m o d o r t 6 P a g e 8 - l f

o f t h e s a m e b y t e o d a t a . O n c o p y i $ 0 4 0 A , o n e i $ 0 4 8 A a n o n i t h A - r e g . T h n e x t i n s t r u c t i o n , D E X f c a u s e s t h e X - r e g t b D B c r e a s e d o d e c r e m e n t e d b 1 S i n c e i h a t h e v a l u e o f 1 c o m i n gi n t o t h i s i n s t r u c t i o n , a f t e r t h i n s t r u c t i o n i e x e c u t e d , i w i l l h a v et h v a l u e o 9 T h n e x t i n s t r u c t i o n , B P L O O P , w i l l c o n d i t i o n a l l yb r a n c h t t h i n s t r u c t i o n w h i c h h a t h l a b e l L O O P . N o t e t h i s i b a c k w a r d b r a n c h o b y t e s . T h g e n e r a t e d m a c h i n e l a n g u a g e v a l u e o fh o f a r t o b r a n c h i $ F 7 . R e m e m b e r a b o u t n e g a t i v e b r a n c hd i s p l a c e m e n t s ? 2 5 6 2 4 7 . 2 4 1 6 1 w i t h r e m a i n d e r o 7 H e n c e t h h e v a l u e o - $ F 7 . C o n v e n i e n t l y , T h e A s s e m b l e r m a d et h a t c a l c u l a t i o n f o u s

T h B P i n s t r u c t i o n t e s t s t h N e g a t i v e b i o t h S t a t u sR e g i s t e r . B P s t a n d s f o B r a n c h i P L u s . T h N e g a t i v e b i t i s

a f f e c t e d b e v e r y e x e c u t i o n o D E i n s t r u c t i o n ( a n d m a n y o t h e ri n s t r u c t i o n s a w e l l ) . I f t h X - r e g w a z e r o b e f o r e t h e x e c u t i o n o t h D E X , t h e r e s u l t o t h D E w o u l d b e n e g a t i v e n u m b e r i t h X r e g . T h N e g a t i v e b i w o u l d b s e t t o o n e . T h B P t e s t s t h en e g a t i v e b i t . I i i n o t a o n ( n o t n e g a t i v e ) t h e X - r e g m u s t s t i l lb p o s i t i v e o r z e r o a f t e r h a v i n g b e e n d e c r e m e n t e d b y t h e D E X .

T h b r a n c h w i l l b t a k e n b a c k u p t L O O P . T h e A - r e g w i l l n o b l o a d e d f r o m a d d r e s s $ 0 4 0 9 a n s t o r e d i n t o a d d r e s s $ 0 4 8 9 . T h X - r e gw i l l b d e c r e m e n t e d a g a i n a n t e s t e d t o s e i i w e n t n e g a t i v e y e t .O n c e a g a i n , i i p o s i t i v e ( i h a t h v a l u e n o w ) . T h b r a n c h w i l lb t a k e n b a c k u t L O O P , t h s a m e p r o c e s s w i l l o c c u r o n c e a g a i n , t h i st i m e m o v i n g a b y t e f r o m $ 0 4 0 8 t o $ 0 4 8 8 . O n c e a g a i n , t h X - r e g w i l l b d e c r e m e n t e d a n t e s t e d a n f o u n d n o t - n e g a t i v e . T h l o o p w i l l b e x e c u t e d t o t a l o 1 t i m e s , w i t h t h X - r e g v a r y i n g f r o m i O t o 0 t h a d d r e s s o d a t a b e i n g l o a d e d i n t o t h A - r e g v a r y i n g f r o m $ 0 4 0 A t $ 0 4 0 0 , t h a d d r e s s o w h e r e d a t a i m o v e d t v a r y i n g f r o m $ 0 4 8 A t $ 0 4 8 0 .

T h i s i t h p r o c e s s b w h i c h a w i d e v a r i e t y o r e p e t i t i v eo p e r a t i o n s a r p e r f o r m e d u p o n d a t a w i t h t h e 6 5 1 0 . T h i s i a v e r ys t a n d a r d l o o p . I i s t i l l s e e m s m y s t e r i o u s t y o r e a d i o v e r a g a i na n w h e n w g e t o t h e s e c t i o n o a c t u a l l y u s i n g T h e A s s e m b l e rE d i t o r , T h L o a d e r , T h M o n i t o r , a n T h D e c o d e r , w w i l l c r e a t e a a c t u a l p r o g r a m w h i c h d o e s j u s t t h i s p r o c e s s . W w i l l e x e c u t e t h p r o g r a m o n e s t e p a t i m e w i t h T h M o n i t o r , w a t c h i n g h o e v e r y t h i n gw o r k s a n s e e i n g t h e r e g i s t e r s a n t h m e m o r y l o c a t i o n s c h a n g i n g a w g t h r o u g h t h p r o g r a m .

Page 70: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 70/172

I n s i d e T h C o m m o d o r e 6 4 P a g t 8 - 1 1

T h e r e a r f o u r m o d e s o a d d r e s s i n g w h i c h a r c a l l e d i n d e x e d .B o t h t h X - r e g a n t h Y - r e g m a b u s e d i i n d e x e d i n s t r u c t i o n s a n b o t h m a b u s e d i c o m b i n a t i o n w i t h a b s o u l t e a n d Z e r o P a g e m o d e s .L i k e t h a b s o l u t e a n Z a d d r e s s i n g m o d e s , t h e a b s o l u t e , X a n Z P , Xi n s t r u c t i o n s t a k e t h r e e a n t w b y t e s r e s p e c t i v e l y . T h Y - r e g a n t h X - r e g - f u n c t i o n i d e n t i c a l l y i t h e i r r e s p e c t i v e m o d e s . T h f o u ri n d e x e d m o d e s t h e n a r e : a b s » X Z P » X a b s » Y Z P » Y

I N D I R E C T M O D E T h e r e i o n l y o n i n s t r u c t i o n w h i c h u s e s t h s i m p l ei n d i r e c t m o d e o a d d r e s s i n g . T h i s i t h J M ( a d d r ) i n s t r u c t i o n . T h p a r e n t h e s i s a r o u n d t h a b s o l u t e a d d r e s s s i g n i f i e s i n d i r e c t . W h a th a p p e n s w i t h t h i n d i r e c t j u m p i t h f o l l o w i n g : 1 T h 6 5 1 8 g e t s a a d d r e s s f r o m t h t w b y t e s i m m e d i a t e l y f o l l o w i n g t h e o p - c o d e . R a t h e rt h a n l o a d t h P w i t h t h i s v a l u e d i r e c t l y * i f e t c h e s a n a d d r e s s f r o mt h s p e c i f i e d m e m o r y l o c a t i o n a n t h m e m o r y l o c a t i o n i m m e d i a t e l yf o l l o w i n g i t T h i s i t h a d d r e s s w h i c h i l o a d s i n t o t h P C T h u sc h a n g e i t h p r o g r a m f l o w i c a u s e d .

T s t a t e t h i s a n o t h e r w a y , f o t h J M i n d i r e c t t o w o r k a d e s i r e d , t h e r e m u s t b e a n a d d r e s s p r e - s t o r e d s o m e w h e r e i m e m o r y . T h J M i n s t r u c t i o n m u s t t e l l t h 6 5 1 0 w h e r e t h a t a d d r e s s i l o c a t e d i m e m o r y . T h e 6 5 1 0 w i l l t h e n l o a d i t P w i t h t h a d d r e s s s t o r e dt h e r e i n . S u c h p r e s t o r e d a d d r e s s i c a l l e d v e c t o r . B A S I C h a s e v e r a l v e c t o r s s a v e d i t h f i r s t f e p a g e s o m e m o r y w h i c h p o i n t t ov a r i o u s p r o c e s s i n g p r o g r a m s .

V e c t o r s a r c o n v e n i e n t w a y s o a l l o w i n g t h e f l e x i b l e d e s i g no o p e r a t i n g s y s t e m s s u c h t h a t n e v e r s i o n s a n u p d a t e s t t h o p e r a t i n g s y s t e m c a b c o m p a t i b l e w i t h t h o l v e r s i o n s . P r o g r a m sw h i c h n e e d t u s t h v a r i o u s r o u t i n e s p o i n t e d t b y v e c t o r s w i l l n o n e e d t b c h a n g e d b e c a u s e o d i f f e r e n t l o c a t i o n o t h e r o u t i n e i t h n e v e r s i o n . T h v e c t o r w i l l b t h e o n l y t h i n g w h i c h w i l l h a v e t b e m o d i f i e d t a l l o w c o m p a t i b i l i t y .

( I N D I R E C T L Y T h i s m o d e i s o m e w h a t s i m i l a r t c / t h e i n d i r e c t m o d ed i s c u s s e d a b o v e . T h a b o v e i n s t r u c t i o n w a a p p l i c a b l e o n l y t t h J M i n s t r u c t i o n . T h i s m o d e i a p p l i c a b l e t o v a r i o u s d a t a a c c e s s a n m a n i p u l a t i o n i n s t r u c t i o n s . T h e s e i n s t r u c t i o n s a r e t w b y t ei n s t r u c t i o n s . T h s e c o n d b y t e o f t h e i n s t r u c t i o n s p e c i f i e s a n a d d r e s si z e r o p a g e . L i k e w i t h t h p r e v i o u s m o d e , t h e r e m u s t b a a d d r e s ss t o r e d a t h s p e c i f i e d l o c a t i o n . T h b i d i f f e r e n c e h e r e i t h a t t h Y - r e g i a d d e d t t h a d d r e s s f o u n d i z e r o p a g e t g i v e t h 6 5 1 0 t h

Page 71: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 71/172

I n s i d e T h C o m m o d o r e 6 P a g e 8 - 1 2

e v e n t u a l a d d r e s s o w h e r e t h d a t a s h o u l d c o m e f r o m o g t o T h ( I n d i r ) , Y m o d e i a c t u a l l y u s e d e x a c t l y l i k e t h a d d r , Y m o d e . I i u s e f u l f o d o i n g l o o p s . T h o n l y d i f f e r e n c e i t h a t t h e b a s ea d d r e s s o t h l o o p i s t o r e d i Z e r o P a g e r a t h e r t h a n s p e c i f i e dd i r e c t l y b t h i n s t r u c t i o n . T h i n s t r u c t i o n t h e n s p e c i f i e s t h e Z e r oP a g e l o c a t i o n o f t h e b a s e a d d r e s s . T h i s i a v e r y h a n d y w a t p r o g r a m s u b r o u t i n e w h i c h i u s e d a d i f f e r e n t t i m e s a n d c a l l e d f r o md i f f e r e n t p l a c e s i t h e m a i n l i n e p r o g r a m t d t h s a m e g e n e r a l t a s kb u w i t h d i f f e r i n g s e t s o f d a t a . T h b a s e a d d r e s s o t h d a t a t b m a n i p u l a t e d b t h s u b r o u t i n e m u s t b a p p r o p r i a t e l y s e u i Z e r oP a g e e a c h t i m e j u s t b e f o r e t h s u b r o u t i n e i c a l l e d . T h s u b r o u t i n ei t s e l f n e v e r h a t c h a n g e a n y t h i n g . I u s e s t h z e r o p a g e v e c t o r t og e t h d a t a i t ' s b e e n c a l l e d t o u s e . E x a m p l e :

S U B R A L D B $ 4 0L O O P A L D < $ 7 C ) , Y

S T ( $ 8 0 ) , YD E B P L O O P AR T

H e r e , t h s u b r o u t i n e , S U B R A , i d e s i g n e d t d g e n e r a lp u r p o s e m o v e o d a t a f r o m s o m e l o c a t i o n i m e m o r y t s o m e o t h e rl o c a t i o n . T h n u m b e r o b y t e s t b m o v e d i f o u n d i l o c a t i o n $ 0 6 4 0 .T h l o c a t i o n o f w h e r e t m o v e t h d a t a f r o m i f o u n d i $ 0 0 7 C a n $ 0 0 7 D . T h a d d r e s s o w h e r e t m o v e i t i f o u n d i l o c a t i o n s$ 0 0 8 0 a n $ 0 0 8 1 . T h c a l l i n g p r o g r a m m u s t s e t h o s e l o c a t i o n s u w i t ht h a p p r o p r i a t e v a l u e s f o t h s u b r o u t i n e t f u n c t i o n a d e s i r e d .N o t e t h a t n l e f t a r r o w i r e q u i r e d f o t h ( i n d e x e d ) , Y m o d e e v e nt h o u g h t h s p e c i f i e d a d d r e s s i a l w a y s i Z e r o P a g e .

( I N D I R E C T , X ) - T h i s i t h l a s t a n p r o b a b l y t h e l e a s t u s e f u la d d r e s s i n g m o d e p r o v i d e d w i t h t h 6 5 1 0 . Y o u m a y h a v e g u e s s e d t h a t i i s i m i l a r t t h p r e v i o u s m o d e . I w o u l d b l o m o r e u s e f u l i i w e r e i d e n t i c a l e x c e p t f o t h r e g i s t e r u s e d . U n f o r t u n a t e l y , i i s n ' t .Y o s h o u l d n o t i c e t h a t t h e X i i n s i d e t h p a r e n t h e s i s , w h e r e a s i t h p r e v i o u s m o d e , t h i o u t s i d e t h p a r e n t h e s i s . T h i s i r e f l e c t i v eo t h i m p o r t a n t d i s t i n c t i o n . T h p a r e n t h e s i s i n d i c a t e t h " i n d i r e c t i o n " . I t h p r e v i o u s e x a m p l e , t h Y - r e g w a a d d e d t t h a d d r e s s f o u n d i Z e r o P a g e , a n t h r e s u l t o f t h a t a d d i t i o n p r o v i d e d

Page 72: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 72/172

I n t i d t T h C o m m o d o r t 6 P a g t 8 - 1 3

t h a d d r e s s o f t h e d e s i r e d d a t a . H e r e , t h e X - r e g i a d d e d t o t h es p e c i f i e d a d d r e s s ! t f i n d w h e r e i Z e r o P a g e t h v e c t o r r e s i d e s . T h X - r e g i t h e r e f o r e a i n d e x t o t a b l e o f v e c t o r s s t o r e d i Z e r o P a g e .T h i s m o d e i n o u s e f u l * t h e r e f o r e , i t h s a m e w a y t h a t t h e o t h e r o n i s I m i g h t f i n d s o m e u s i u n u s u a l s i t u a t i o n s w h e r e t h e r e i n e e d t h a v e l i s t o a d d r e s s e s o d a t a b y t e s a n a r o u t i n e i n e e d e dt p r o c e s s t h e v a r i o u s d a t a b y t e s . S u c h a r o u t i n e w o u l d s t e p t h r o u g ht h l i s t * a n a d d r e s s ( t w o b y t e s ) a t i m e * u s i n g t h X - r e g t b u m pt h r u t h e l i s t a n t o p o i n t t o t h e a p p r o p r i a t e a d d r e s s a w h i c h t h d a t a w i l l u l t i m a t e l y b f o u n d . P e r h a p s y o c a f i n d s o m e b e t t e r u s o t h i s m o d e .

T h e s e l a s t f o u r c h a p t e r s h a v e b e e n f a i r l y p a c k e d w i t h i n f o r m a t i o no t h w o r k i n g s o f t h e 6 5 1 0 . I w i l l b e n e c e s s a r y t w r i t e s o m ep r o g r a m s a n t e x a m i n e t h p r o g r a m s o o t h e r s t g e c o m f o r t a b l ef e e l i n g a b o u t t h u s o t h e v a r i o u s i n s t r u c t i o n s a n a d d r e s s i n gm o d e s . T h n e x t c h a p t e r w i l l p r e s e n t e v e r y a v a i l a b l e i n s t r u c t i o n o t h 6 5 1 0 . A f t e r c o m p l e t i n g i t y o w i l l b a b l e t s t a r t t o t a k ec o n t r o l o f y o u r c o m p u t e r b w r i t i n g p o w e r f u l m a c h i n e l a n g u a g ep r o g r a m s .

Page 73: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 73/172

I n s i d e T h C o m m o d o r e 6 4 P a g e 9 -

6 1 I n s t r u c t i o n S e T h e r e a r 5 6 s e p a r a t e i n s t r u c t i o n s w h i c h t h 6 5 1 0 h a s b e e n

d e s i g n e d t o e x e c u t e . T h e r e a r e a l s o t w " p s e u d o - o p i n s t r u c t i o n s "w h i c h a r n o a p a r t o f t h e 6 5 1 0 ' s i n s t r u c t i o n s e b u t w h i c h T h A s s e m b l e r u n d e r s t a n d s .

T h e r e a r 1 a d d r e s s i n g m o d e s . S o m e i n s t r u c t i o n s a r e l i m i t e dt s i n g l e a d d r e s s i n g m o d e , o t h e r s a r e c a p a b l e o f u t i l i z i n g u t e i g h t . M o s t o t h i n s t r u c t i o n s a r e q u i t e s i m p l e f u n c t i o n a l l y * a n r e q u i r e o n l y a s e n t e n c e o t w t o d e s c r i b e t h e i r c h a r a c t e r i s t i c s . W w i l l c o v e r t h e s e f i r s t .

R e g i s t e r - o n l y i n s t r u c t i o n s

T A - T r a n s f e r t h c o n t e n t s o f t h e A - r e g t t h X - r e g . O n l y t h r e c e i v i n g r e g i s t e r i m o d i f i e d . T h Z e r o b i o f t h e S t a t u s R e g i s t e ri s e t ( m a d e t h a v e t h e v a l u e 1 i t h e v a l u e t r a n s f e r r e d i z e r o ,o t h e r w i s e i i c l e a r e d ( m a d e t h a v e t h e v a l u e 6 ) T h N e g a t i v e b i o f t h e P r o c e s s o r S t a t u s R e g i s t e r i s e i t h h i g h - o r d e r b i o t h v a l u e t r a n s f e r r e d i o ( v a l u e i ) e l s e i i c l e a r e d .

T A T r a n s f e r A - r e g t Y - r e g . T h e A - r e g i s t o r e d i n t o t h Y - r e g .T h s a m e n o t e s a p p l y a w i t h T A X .

T Y - T r a n s f e r Y - r e g t A - r e g . T h Y - r e g i s t o r e d i n t o t h A - r e g ,T h s a m e n o t e s a p p l y a w i t h T A X .

T X - T r a n s f e r X - r e g t A - r e g . T h X - r e g i s t o r e d i n t o t h A - r e g .T h s a m e n o t e s a p p l y a w i t h T A X .

T X T r a n s f e r X - r e g t S t a c k P o i n t e r . T h X - r e g i s t o r e d i n t o t h S t a c k P o i n t e r . N s t a t u s b i t s a r a f f e c t e d . T h i s i t h o n l y w a o i n i t i a l i z i n g t h e S t a c k P o i n t e r .

T S T r a n s f e r S t a c k P o i n t e r t X - r e g . T h S t a c k P o i n t e r i s t o r e di n t o t h e X - r e g . T h s a m e n o t e s a p p l y a w i t h T A X .

S E S E t h C a r r y b i t . T h C a r r y b i t i s s e t v a l u e 1

Page 74: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 74/172

I n s i d e T h C o m m o d o r e 6 P t g t 9 -

C L C L e a r t h C a r r y b i t . T h C a r r y b i i c l e a r e d .

S E S E t h D e c i m a l M o d e b i t . T h D e c i m a l M o d e b i i s e t v a l u e1 T h D e c i m a l m o d e o a r i t h m e t i c i e n a b l e d .

C L C L e a r t h D e c i m a l M o d e b i t . T h D e c i m a l m o d e o f o p e r a t i o n i d i s a b l e d . T h D e c i m a l M o d e b i t i s c l e a r e d .

C L C L e a r t h o v e r f l o w b i t . T h o v e r f l o w b i i t h P r o c e s s o rS t a t u s R e g i s t e r i c l e a r e d .C L C L e a r t h e I n t e r r u p t d i s a b l e b i t . T h I n t e r r u p t d i s a b l e b i t i nt h P r o c e s s o r S t a t u s R e g i s t e r i c l e a r e d , a l l o w i n g i n t e r r u p t s t oo c c u r .

S E S E t h e I n t e r r u p t D i s a b l e b i t . T h I n t e r r u p t d i s a b l e b i i t h P r o c e s s o r S t a t u s r e g i s t e r i s e t i c a u s i n g a l i n t e r r u p t s t b m a s k e d ( d i s a b l e d ) u n t i l t h e I n t e r r u p t d i s a b l e b i i c l e a r e d w i t hC L I .

D E D E c r e m e n t t h e X - r e g . T h v a l u e c o n t a i n e d i t h X - r e g i d e c r e a s e d b i I t h r e s u l t i n g v a l u e i t h X - r e g i z e r o * t h Z e r ob i t i s s e i t h P I i i n o z e r o * t h e z e r o b i i c l e a r e d . I t h r e s u l t i n g v a l u e i t h X - r e g h a t h h i g h - o r d e r b i o n t h N e g a t i v e b i i t h P r o c e s s o r S t a t u s R e g i s t e r i s s e t . O t h e r w i s e t h N e g a t i v e b i t w i l l b c l e a r e d . N o t e t h a t r e g i s t e r v a l u e s o 0 - 1 2 7 w i l lh a v e c l e a r h i g h - o r d e r b i a n v a l u e s o 1 2 8 - 2 5 5 w i l l h a v e t h b i s e t .

D E D E c r e m e n t t h Y - r e g . T h v a l u e o f t h e Y - r e g i d e c r e a s e d b 1 T h Z e r o a n d N e g a t i v e b i t s a r e a f f e c t e d a w i t h t h D E i n s t r u c t i o n .

I N I N c r e m e n t t h e X - r e g . T h v a l u e o f t h X - r e g i i n c r e a s e d b y i T h Z e r o a n N e g a t i v e b i t s a r e a f f e c t e d a w i t h t h D E i n s t r u c t i o n .

I N I N c r e m e n t t h e Y - r e g . T h v a l u e o f t h e Y - r e g i i n c r e a s e d b y 1 T h Z e r o a n N e g a t i v e b i t s a r e a f f e c t e d a w i t h t h D E i n s t r u c t i o n .

Page 75: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 75/172

I n s i d e T h C o m m o d o r e 6 P a g e 9 -

M e m o r y a c c e s s i n g i n s t r u c t i o n s

I N C - I N C r e m e n t m e m o r y . T h v a l u e o f a b y t e l o c a t e d i m e m o r y i i n c r e a s e d b y i T h Z e r o a n N e g a t i v e b i t s a r a f f e c t e d a w i t h t h D E i n s t r u c t i o n . O n l y Z P Z P > X ; A B S ; A B S » X m o d e s a r v a l i d .

D E D E C r e m e n t m e m o r y . T h e v a l u e o f a b y t e l o c a t e d i m e m o r y i d e c r e a s e d b i T h s a m e c o m m e n t s a a p p l y f o I N C .

L D L o a D t h A - r e g . T h c o n t e n t s o f m e m o r y l o c a t i o n a r t r a n s f e r r e d t t h A - r e g . T h Z e r o a n N e g a t i v e b i t s a r e a f f e c t e d a w i t h t h T A i n s t r u c t i o n . V a l i d a d d r e s s i n g m o d e s a r e : I m m e d i a t e ; Z P Z P , X ; A b s o l u t e ; A b s o l u t e , X ; A b s o l u t e ^ ; < I n d i r e c t , X ) ; ( I n d i r e c t , ? )

L D L o a D t h X - r e g . T h c o n t e n t s o f m e m o r y l o c a t i o n a r e t r a n s f e r r e dt t h X - r e g . T h Z e r o a n d N e g a t i v e b i t s a r e a f f e c t e d a w i t h t h T A i n s t r u c t i o n . A b s , Z a n Z P * Y a d d r e s s i n g m o d e s a r v a l i d .

L D L o a D t h Y - r e g . T h c o n t e n t s o m e m o r y l o c a t i o n a r et r a n s f e r r e d t t h e Y - r e g . T h Z e r o a n d N e g a t i v e b i t s a r e a f f e c t e d a w i t h t h T A i n s t r u c t i o n . A b s > Z a n Z P , X a d d r e s s i n g m o d e s a r v a l i d .

S T S T o r e t h A - r e g . T h c o n t e n t s o f t h e A - r e g a r t r a n s f e r r e d t m e m o r y l o c a t i o n . N r e g i s t e r s o s t a t u s b i t s a r a f f e c t e d . V a l i da d d r e s s i n g m o d e s a r e : Z P ; Z P » X ; A b s o l u t e ; A b s o l u t e , X ; A b s o l u t e , Y ;( I n d i r e c t , X ) ; ( I n d i r e c t , Y )

S T S T o r e t h X - r e g . T h c o n t e n t s o f t h e X - r e g a r e t r a n s f e r r e d t m e m o r y l o c a t i o n . N s t a t u s b i t s o r r e g i s t e r s a r e a f f e c t e d . A b s , Z a n Z P , Y a d d r e s s i n g m o d e s a r v a l i d .

S T S T o r e t h Y - r e g . T h c o n t e n t s o f t h e Y - r e g a r t r a n s f e r r e d t o m e m o r y l o c a t i o n . N s t a t u s b i t s o r r e g i s t e r s a r a f f e c t e d . A b s , Z a n Z P * X a d d r e s s i n g m o d e s a r v a l i d .

Page 76: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 76/172

I n s i d e T h C o m m o d o r t 6 P a g t 9 - 4

C o n d i t i o n a l B r a n c h I n s t r u c t i o n s

B C B r a n c h C a r r y C l e a r . T h e p r o g r a m c o u n t e r w i l l b e m o d i f i e d b y t h a m o u n t o t h s p e c i f i e d d i s p l a c e m e n t i a n o n l y i t h C a r r y b i t i sc l e a r ( 0 ) . F o r w a r d b r a n c h e s m a o c c u r u t 1 2 b y t e s f r o m t h a d d r e s s o t h f i r s t b y t e f o l l o w i n g t h e b r a n c h i n s t r u c t i o n . B a c k w a r db r a n c h e s m a o c c u r u t 1 2 b y t e s f r o m t h s a m e a d d r e s s . N o t h e rr e g i s t e r s o t h e r t h a n t h P a r a f f e c t e d . O n l y R e l a t i v e a d d r e s s i n gm o d e i s v a l i d .

B C B r a n c h C a r r y S e t . T h p r o g r a m c o u n t e r w i l l b m o d i f i e d b y t h a m o u n t o t h s p e c i f i e d d i s p l a c e m e n t i a n o n l y i t h C a r r y b i t i ss e ( 1 ) . S a m e c o m m e n t s a f o r t h e B C i n s t r u c t i o n .

B B B r a n c h E Q u a l . T h p r o g r a m c o u n t e r w i l l b m o d i f i e d b y t h a m o u n t o t h s p e c i f i e d d i s p l a c e m e n t i a n o n l y i t h Z e r o b i t i ss e ( i ) . S a m e c o m m e n t s a f o t h B C i n s t r u c t i o n .

B N B r a n c h N o E q u a l . T h p r o g r a m c o u n t e r w i l l b m o d i f i e d b y t h a m o u n t o f t h e s p e c i f i e d d i s p l a c e m e n t i a n o n l y i t h Z e r o b i i c l e a r ( 0 ) . S a m e c o m m e n t s a f o t h B C i n s t r u c t i o n .

B N B r a n c h M i n u s . T h p r o g r a m c o u n t e r w i l l b m o d i f i e d b y t h a m o u n t o t h s p e c i f i e d d i s p l a c e m e n t i a n o n l y i t h M i n u s b i t i ss e ( i ) . S a m e c o m m e n t s a f o t h B C i n s t r u c t i o n .

B P B r a n c h P L u s . T h e p r o g r a m c o u n t e r w i l l b m o d i f i e d b y t h a m o u n to f t h e s p e c i f i e d d i s p l a c e m e n t i a n o n l y i t h M i n u s b i t i s c l e a r( 0 ) . S a m e c o m m e n t s a f o r t h e B C i n s t r u c t i o n .

B V B r a n c h o v e r f l o w C l e a r . T h p r o g r a m c o u n t e r w i l l b e m o d i f i e d b yt h a m o u n t o t h e s p e c i f i e d d i s p l a c e m e n t i a n o n l y i t h O v e r f l o wb i t i s c l e a r ( 0 ) . S a m e c o m m e n t s a f o t h B C i n s t r u c t i o n .

B V B r a n c h o v e r f l o w S e t . T h p r o g r a m c o u n t e r w i l l b e m o d i f i e d b yt h a m o u n t o t h s p e c i f i e d d i s p l a c e m e n t i a n o n l y i t h O v e r f l o wb i i s e ( i ) . S a m e c o m m e n t s a f o t h B C i n s t r u c t i o n .

Page 77: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 77/172

I n t i d t T h C o m m o d o r e 6 P a g t 9 -

J u m p i n s t r u c t i o n s

J M J u M P . T h P i l o a d e d w i t h t h e s p e c i f i e d a d d r e s s t c a u s i n gc h a n g e i t h f l o w o t h p r o g r a m . B o t h A b s o l u t e a n I n d i r e c ta d d r e s s i n g m o d e s a r v a l i d .

J S J u m p t S u b R o u t i n e . T h P i s f i r s t i n c r e m e n t e d b 2 T h n e P i t h e n s t o r e d o t h s t a c k . T h P C i s t o r e d i t h s t a c kl o c a t i o n a d d r e s s e d b t h S t a c k P o i n t e r . T h S t a c k P o i n t e r i d e c r e m e n t e d a n t h P C i t h e n s t o r e d i t h n e s t a c k l o c a t i o n a a d d r e s s e d b t h S P T h e S P i d e c r e m e n t e d s e c o n d t i m e a n t h a d d r e s s s p e c i f i e d b t h J S i n s t r u c t i o n i l o a d e d i n t o t h e P C c a u s i n g j u m p t t h s p e c i f i e d s u b r o u t i n e l o c a t i o n . N o t e t h a t t h ea d d r e s s s t o r e d o t h s t a c k i n o w h a t m i g h t b e x p e c t e d . T h a d d r e s s i o t h t h i r d b y t e o t h J S i n s t r u c t i o n * n o t h a d d r e s so f t h e n e x t s e q u e n t i a l i n s t r u c t i o n a f t e r t h e J S R . T h R T i n s t r u c t i o n * w h i c h c a u s e s a r e t u r n f r o m t h e s u b r o u t i n e * c o m p e n s a t e sf o r t h i s a n o m a l y . G e n e r a l l y * t h e c a s u a l p r o g r a m m e r n e e d n ' t w o r r ya b o u t t h m e c h a n i c s o s t a c k o p e r a t i o n s a l o n g a s s h e a l w a y s h a sR T f o e v e r y J S R . H o w e v e r * a d v a n c e d m a c h i n e l a n g u a g e p r o g r a m m e r s a r f o n d o d i r e c t s t a c k m a n i p u l a t i o n t e c h n i q u e s * e s p e c i a l l y f o r p a s s i n ga r g u m e n t s t o s u b r o u t i n e s .

R T R e T u r n f r o m S u b r o u t i n e . T h S t a c k P o i n t e r i f i r s t i n c r e m e n t e d .T h P C i l o a d e d f r o m t h s t a c k a d d r e s s p o i n t e d t b t h S t a c kP o i n t e r . T h e S P i t h e n i n c r e m e n t e d a g a i n a n t h P C i l o a d e d f r o mt h s t a c k . T h P i i n c r e m e n t e d t c o m p e n s a t e f o t h J S o p e r a t i o no f p u t t i n g t h e a d d r e s s o f t h e t h i r d b y t e o f t h e J S o t h e s t a c ki n s t e a d o t h a d d r e s s o t h n e x t i n s t r u c t i o n . N o t h P h a t h a d d r e s s o t h i n s t r u c t i o n i m m e d i a t e l y f o l l o w i n g t h e m o s t r e c e n t J S i n s t r u c t i o n . T h e p r o g r a m f l o w i t h u s r e t u r n e d t o t h e m a i n l i n ep r o g r a m f r o m t h s u b r o u t i n e .

R T R e T u r n f r o m I n t e r r u p t . T h i s i n s t r u c t i o n r e v e r s e s t h p r o c e s sw h i c h o c c u r s w h e n a i n t e r r u p t o c c u r s . T h P r o c e s s o r S t a t u s R e g i s t e ri r e t r i e v e d f r o m t h s t a c k w h e r e t h i n t e r r u p t c a u s e d i t b s t o r e d . T h P C a n P C a r t h e n r e l o a d e d f r o m t h s t a c k w h e r e t h e yt o w e r e s t o r e d a a p a r t o f t h e 6 5 i e ' s i n t e r r u p t p r o c e s s i n g . T h r e t u r n t t h e p o i n t o i n t e r r u p t i o n i t h u s c o m p l e t e * w i t h t h

Page 78: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 78/172

I n s i d t T h C o m m o d o r t 6 4 P a g e 9 -

P r o c e s s o r S t a t u s R e g i s t e r h a v i n g t h s a m e v a l u e i h a a t h t i m e o - i n t e r r u p t i o n .

B R B R e a K . I n t e r r u p t p r o c e s s i n g i c a u s e d t o c c u r . T h a d d r e s s o t h n e x t b y t e f o l l o w i n g t h e B R i n s t r u c t i o n i s a v e d o n t h s t a c k .T h B r e a k b i t i s t u r n e d o i t h P r o c e s s o r S t a t u s R e g i s t e r w h i c h i t h e n s a v e d o n t h s t a c k . T h P i l o a d e d w i t h t h a d d r e s s f o u n d a m e m o r y l o c a t i o n $ F F F E a n $ F F F F .

S t a c k P u s h P u l l I n s t r u c t i o n s

P H P u s H t h A - r e g . T h A - r e g i s t o r e d o t h s t a c k a t t h e a d d r e s sp o i n t e d t b t h S P T h e S P i t h e n d e c r e m e n t e d . A l P H A ' s s h o u l dg e n e r a l l y b m a t c h e d w i t h a f o l l o w i n g P L A .

P L P u L l t h A - r e g . T h e S P i i n c r e m e n t e d * t h e n t h A - r e g i l o a d e df r o m t h s t a c k l o c a t i o n p o i n t e d t b t h n e v a l u e o f t h e S P

P H P u s H t h P - r e g . T h P r o c e s s o r S t a t u s r e g i s t e r i p u s h e d o n t ot h s t a c k i t h s a m e f a s h i o n t h A - r e g i w i t h t h P H A .

P L P u L l t h e P - r e g . T h P r o c e s s o r S t a t u s r e g i s t e r i p u l l e d o f ft h e s t a c k i t h s a m e f a s h i o n t h A - r e g i w i t h t h e P L i n s t r u c t i o n .

P s e u d o - o p I n s t r u c t i o n s

B Y T h i s i n o r e a l l y a i n s t r u c t i o n i t h i n s t r u c t i o n s e t o t h 6 5 1 6 . I i a i n s t r u c t i o n w h i c h T h e A s s e m b l e r r e c o g n i z e s a n di n t e r p r e t s t m e a n , g e n e r a t e m a c h i n e l a n g u a g e d a t a . T h o p e r a n d f i e l do f t h e B Y i n s t r u c t i o n c a e x p r e s s s e v e r a l t y p e s o d a t a w h i c h T h A s s e m b l e r w i l l u n d e r s t a n d .

I t h f i r s t c h a r a c t e r o t h B Y i " t h e f o l l o w i n gc h a r a c t e r s m u s t b h e c h a r a c t e r s * i . e . 0 - 9 , A - F . T h A s s e m b l e r w i l lh a n d l e a s t r i n g o f h e x c h a r a c t e r s u t 7 5 c h a r a c t e r s i l e n g t h . I w i l l g e n e r a t e d a t a s t r i n g w i t h t w n y b b l e s ( h a l f b y t e b i t s )p e b y t e * i n s e r t i n g $ i t h h i g h - o r d e r n y b b l e o f t h e h i g h - o r d e rb y t e i t h e r e a r e a o d n u m b e r o f c h a r a c t e r s s p e c i f i e d .

Page 79: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 79/172

I n s i d t T h C o m m o d o r e 6 P a g e 9 -

T h e A s s e m b l e r w i l l c r e a t ed a t a s t r i n g w i t h a m a n y b y t e s a t h e r e a r e c h a r a c t e r s f o l l o w i n g t h e

" T h v a l u e s o f t h e g e n e r a t e d b y t e s w i l l b t h A S C I I v a l u e s o t h c o r r e s p o n d i n g c h a r a c t e r s .

I t h f i r s t c h a r a c t e r o f t h e o p e r a n d i " > o l l < " t h r e m a i n d e r o f t h e o p e r a n d f i e l d w i l l b i n t e r p r e t e d a s a n a d d r e s se x p r e s s i o n a n t h g e n e r a t e d b y t e w i l l b e i t h e r t h h i g h - o r d e r b y t eo f t h e a d d r e s s o t h l o w - o r d e r b y t e d e p e n d i n g o w h e t h e r t h f i r s tc h a r a c t e r i " > o r " < " . A n o t h e r f i r s t c h a r a c t e r w i l l c a u s e t h eo p e r a n d f i e l d t b i n t e r p r e t e d a a n a d d r e s s e x p r e s s i o n a n t h a s s e m b l e r w i l l c o m p u t e t w o - b y t e a d d r e s s i t h l o w - o r d e r - b y t e - f i r s tf o r m a t . A d d r e s s e x p r e s s i o n s a r c o v e r e d f u l l y i n t h c h a p t e r o w r i t i n g a s s e m b l y l a n g u a g e p r o g r a m s .

E Q E Q U a t e . T h i s p s e u d o - o p d o e s n o g e n e r a t e a n y d a t a w h i c h g e t ss t o r e d i n t o m e m o r y b T h L o a d e r . I i a i n s t r u c t i o n t T h A s s e m b l e r t o s e t t h e L o c a t i o n C o u n t e r a n d t c a u s e t h l a b e l i t h l a b e l f i e l d t b e a s s i g n e d t t h a d d r e s s w h i c h i e x p r e s s e d i t h o p e r a n d f i e l d .

S h i f t I n s t r u c t i o n s

A S A r i t h m e t i c S h i f t L e f t . T h c o n t e n t s o t h A - r e g o r o f m e m o r yl o c a t i o n a r e s h i f t e d o n b i p o s i t i o n t o t h e l e f t . T h l o w - o r d e r b i p o s i t i o n i f o r c e d t v a l u e 2 e r o . T h h i g h - o r d e r b i i s h i f t e d i n t ot h C a r r y b i t . T h N e g a t i v e b i i s e i t h b i s h i f t e d i n t o t h h i g h - o r d e r b i p o s i t i o n i 1 I i c l e a r e d i i i z e r o . T h Z e r o b i i s e i t h e r e s u l t i n g v a l u e o f t h e s h i f t e d b y t e i z e r o ,c l e a r e d i f i t i n o t .

A a e x a m p l e * i t h A - r e g h a t h v a l u e $ C 1 1 0 0 1 1 0 0 ) a f t e r t h e " A S L A 1 i n s t r u c t i o n h a s b e e n e x e c u t e d , i w i l l h a v e t h v a l u e $ 9 1 0 0 1 1 0 0 0 a n t h e c a r r y b i w i l l b s e t . I t h A - r e gh a t h e v a l u e o $ 5 0 1 0 1 1 1 1 1 t h " A S L A w i l l c a u s e i t b e c o m e* B 1 0 1 1 1 1 1 0 a n t h e c a r r y b i t w i l l b c l e a r . N o t e t h a t e a c h l e f ts h i f t c a u s e s t h A - r e g t d o u b l e i v a l u e a l o n g a t h h i g h o r d e rb i t i s n o o n b e f o r e t h s h i f t . S h i f t i n g l e f t i c o n v e n i e n t w a o f m u l t i p l y i n g a v a l u e b y t w o . U s i n g A S i c o m b i n a t i o n w i t h R O L ,m u l t i p l e p r e c i s i o n s h i f t m a b e f f e c t e d . S e t h e d e s c r i p t i o n o t h

Page 80: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 80/172

Page 81: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 81/172

I n s i d e T h C o m m o d o r e 6 P a g t 9 -

p o s i t i o n t t h r i g h t . T h C a r r y b i i s h i f t e d i n t o t h e h i g h - o r d e rb i p o s i t i o n a n t h l o w - o r d e r b i p o s i t i o n i s h i f t e d i n t o t h C a r r yb i t . T h s a m e a d d r e s s i n g m o d e s a p p l y a f o t h A S i n s t r u c t i o n . T h L S a n R O i n s t r u c t i o n s a r e t h e s a m e a t h A S a n R O i n s t r u c t i o n se x c e p t t h e y s h i f t b i t s i t h o p p o s i t e d i r e c t i o n s . N o t e t h a t a o n e -b i s h i f t r i g h t r e s u l t s i a e f f e c t i v e d i v i s i o n b y t w o .

B o o l e a n a r i t h m e t i c i n s t r u c t i o n s

A N L o g i c a l A N D . T h A - r e g i l o g i c a l A N D e d w i t h t h s p e c i f i e d d a t ab y t e . T h b o o l e a n A N o p e r a t i o n i p e r f o r m e d b e t w e e n c o r r e s p o n d i n gb i t s o f t h e t w b y t e s . E a c h b i p o s i t i o n o f t h p a i r o b y t e s i o o e r a t e d o i n d i v i d u a l l y ) t h r e s u l t o t h o p e r a t i o n r e p l a c i n g t h c o r r e s p o n d i n g b i t i n t h A - r e g . T h r u l e s o f t h e A N o p e r a t i o n a r e :i t h t w b i t s b e i n g A N D e d a r e v a l u e 1 t h r e s u l t i 1 i e i t h e rb i i t h e r e s u l t i G T h a t i s C A N I C A N G

C A N 1 C A N 9 0 E x a m p l e :1 1 8 0 1 0 1 0 M e m o r y

A N 1 0 1 0 1 1 0 0 A - r e g

1 0 0 0 1 0 0 0 n e A - r e g

O n l y t h b i p o s i t i o n s w h i c h h a d a i b o t h b y t e s e n d e d u w i t h i t h r e s u l t . T h A N i n s t r u c t i o n i f r e q u e n t l y u s e d t s e l e c t i v e l y c l e a r i n d i v i d u a l b i t s w h i l e m a i n t a i n i n g t h s t a t u s o t h o t h e r b i t s i t h e b y t e . T h i s i d o n e b c r e a t i n g " m a s k - b y t e " w h i c hh a i e v e r y b i p o s i t i o n w h i c h n e e d s t b c l e a r e d ( s e t t 0 ) a n i a l t h o t h e r b i p o s i t i o n s . T h m a s k b y t e m a b i e i t h e r t h e A - r e g o t h s p e c i f i e d m e m o r y l o c a t i o n b u t t h e r e s u l t o ft h o p e r a t i o n a l w a y s r e p l a c e s t h A - r e g .

T h i s p r o c e s s w o r k s b e c a u s e A N D e d w i t h e i t h e r o r g i v e s a r e s u l t w h i l e A N D e d w i t h g i v e s a n A N D e d w i t hg i v e s 1

O R . L o g i c a l O R . T h e A - r e g a n t h e s p e c i f i e d m e m o r y l o c a t i o n , a r l o g i c a l O R e d t o g e t h e r , t h e r e s u l t r e p l a c i n g t h A - r e g . T h b o o l e a n O o p e r a t i o n , i i k e t h A N o p e r a t i o n , i b i b b i o p e r a t i o n . E a c h b i

Page 82: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 82/172

I n i i d t T h C o m m o d o r t 6 P a g e 9 - 1 6

o t h A - r e g i O R e d w i t h t h c o r r e s p o n d i n g b i o t h b y t e i m e m o r yb y t h e f o l l o w i n g r u l e s : I e i t h e r b i t i s i t h e r e s u l t i 1 I b o t h b i t s a r 0 t h r e s u l t i e T h a t i s C O 1 C O 8

C O 1 O 8 E x a m p l e :

1 1 8 0 1 0 1 8 M e m o r yO R 1 0 1 0 1 1 O 0 A - r e g

1 1 1 0 1 1 1 0 A - r e g

T h O R i f r e q u e n t l y u s e d t o s e l e c t i v e l y t u r n b i t s o ( s e t t i ) L i k e w i t h t h e A N D , m a s k m u s t b c r e a t e d w h i c h i n d i c a t e s t h ed e s i r e d b i t s t s e a n t h b i t s t b u n a f f e c t e d . T h O m a s k m u s th a v e b i o i t h b i p o s i t i o n s t b s e a n o f i t h p o s i t i o n sw h i c h n e e d t b m a i n t a i n e d . T h i s i o p p o s i t e o t h A N m a s k .T h e r e , 1 - b i t s m a i n t a i n e d t h s t a t u s q u o . H e r e , 8 - b i t s h a v e t h a tr e s p o n s i b i l i t y . i t h m a s k b y t e w h e n O R e d w i t h g i v e s a n w h e n O R e d w i t h a g i v e a 0 A n i t h m a s k b y t e a l w a y s r e s u l t si r e s u l t . C O 1 i C o 8 i V a l i d a d d r e s s i n g m o d e s a r t h s a m e a f o t h A N i n s t r u c t i o n .

E O - E x c l u s i v e O R T h c o n t e n t s o t h s p e c i f i e d m e m o r y b y t e a r E O R e d w i t h t h c o n t e n t s o t h A - r e g , r e p l a c i n g t h A - r e g w i t h t h r e s u l t . L i k e t h A N a n O i n s t r u c t i o n s , t h i s i b i o r i e n t e di n s t r u c t i o n . T h r u l e s o f E x d u s i v e - O r i n g a r e : T h r e s u l t w i l l h a v e

i a n b i p o s i t i o n f o w h i c h o n l y o n o f t h e t w b y t e s b e i n gE O R e d h a v e a o n e . A l o t h e r b i p o s i t i o n s o t h e r e s u l t w i l l h a v e6 ( i . e . C E O 8 i t E O 1 8 C E O 8 8 C E O 1 1 )

E x a m p l e :

1 1 0 8 1 0 1 0 M e m o r yE O R 1 0 1 0 1 1 0 0 A - r e g

0 1 1 0 0 1 1 0 N e w A - r e g

T h E O i n s t r u c t i o n i u s e f u l f o i n v e r t i n g b i t s . i a n m a s k b i p o s i t i o n w i l l c a u s e t h c o r r e s p o n d i n g b i t i n t h r e s u l t t

Page 83: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 83/172

I n s i d e T h C o m m o d o r e 6 4 P a g e 9 - 1 1

h a v e t h o p p o s i t e v a l u e a t h a t o f t h e c o r r e s p o n d i n g b i t i n t h o b j e c tb y t e . b e f o r e E O R i n g w i l l r e s u l t i 0 a f t e r a n v i c e v e r s a .z e r o i t h m a s k b y t e w i l l c a u s e t h c o r r e s p o n d i n g b i i t h o b j e c tb y t e t g u n m o l e s t e d .

B I B I t e s t . T h A - r e g i s l o g i c a l l y A N D e d w i t h t h c o n t e n t s o f t h es p e c i f i e d m e m o r y l o c a t i o n . T h Z e r o f l a g i s e i t h r e s u l t o t h o p e r a t i o n g i v e s z e r o r e s u l t . T h N e g a t i v e b i t i s s e i t h e h i g ho r d e r b i o t h m e m o r y l o c a t i o n i s e t . T h O v e r f l o w b i t i s s e i t h s e c o n d - h i g h e s t - o r d e r b i ( t h e 6 - b i t ) o f t h e m e m o r y l o c a t i o n i s e t . T h N e g a t i v e a n O v e r f l o w b i t s a r e c l e a r e d i t h 7 - b i t a n 6 - b i to t h m e m o r y l o c a t i o n a r e c l e a r . T h e A - r e g i n o a f f e c t e d b t h e x e c u t i o n o t h i s i n s t r u c t i o n .

T h i s i n s t r u c t i o n i v e r y u s e f u l f o r t e s t i n g i n d i v i d u a l b i t s o b y t e s i m e m o r y . T h e A - r e g i l o a d e d w i t h m a s k w h i c h h a o n e s i t h b i p o s i t i o n s t b t e s t e d a n z e r o s i t h r e s t . I a n o t h m e m o r y b y t e ' s b i t s i t h t e s t e d p o s i t i o n s a r e o t h r e s u l t o f t h A N D i n g o p e r a t i o n w i l l b n o n - z e r o . N o t e t h a t t h e m a s k m a b e i t h e ri m e m o r y o i t h A - r e g f o t h e t e s t t w o r k . T h N e g a t i v e a n dO v e r f l o w b i t s a r s e b a s e d o n l y u p o n t h b i c o n f i g u r a t i o n o t h m e m o r y b y t e h o w e v e r . E x a m p l e :

M A S K B Y $ 8 L D M A S KB I T V A L IB M B I T ?B V B I T *B N B I T 1 0 R 2

O E Q

T h v a l u e o t h b y t e a s s i g n e d t l a b e l M A S K i $ 0 6 . T h i b i a n t h e 2 - b i t a r e o a n a l o t h e r s a r o f f . T h B I i n s t r u c t i o nA N D s t h c o n t e n t s o t h A - r e g , * M w i t h t h b y t e a V A L i a n t h r e s u l t w i l l b n o n - z e r o o n l y i e i t h e r t h i - b i t o r t h e 2 - b i t o f V A L ii a o n e . I V A L i h a i t h i g h - o r d e r b i o n t h p r o g r a m w i l l b r a n c ht B I T 7 . I t h 6 - b i t i o i V A L i t h p r o g r a m w i l l b r a n c h t B I T 6 .I e i t h e r b i t - 2 o b i t - i a r o n t h b r a n c h t B I T 1 O R 2 w i l l b t a k e n .

T h Q i u s e d i t h l a s t s t a t e m e n t o t h p r o g r a m . I h a s p e c i a l s i g n i f i c a n c e t T h A s s e m b l e r . U s e d i t h o p e r a n d f i e l d o a i n s t r u c t i o n i i l i k e

Page 84: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 84/172

I n s i d e T h C o m m o d o r e 6 P * Q t » -

s y m b o l i c l a b e l e x c e p t i r e f e r e n c e s t h c u r r e n t v a l u e o t h L o c a t i o nC o u n t e r . H e r e t i p e r f o r m s t h e f u n c t i o n o f a s s i g n i n g t h e v a l u e o f t h eL o c a t i o n C o u n t e r t t h l a b e l " O K " .

A r i t h m e t i c i n s t r u c t i o n s

A D C - A D d w i t h C a r r y . A d d i t i o n i p e r f o r m e d w i t h t h A - r e g , t h s p e c i f i e d m e m o r y l o c a t i o n a n t h C a r r y b i t . A - r e g A - r e ga d d r c a r r y ) T h < . . . ) i u s e d h e r e t m e a n " t h e c o n t e n t so f " . T h r e s u l t r e p l a c e s t h A - r e g . T h m o d e o f a r i t h m e t i c i d e t e r m i n e d b y t h e s t a t u s o f t h e D e c i m a l m o d e b i a t h e t i m e t h i n s t r u c t i o n i e x e c u t e d . I s e t , t h m o d e o f a d d i t i o n i t h D e c i m a lm o d e . I d e a r , t h m o d e i b i n a r y . V a l i d a d d r e s s i n g m o d e s a r e t h es a m e a f o t h L D i n s t r u c t i o n .

B i n a r y a d d i t i o n i q u i t e s i m p l e . I i J u s t l i k e d e c i m a la d d i t i o n e x c e p t t h h i g h e s t n u m b e r y o u h a v e t w o r r y a b o u t i 1 T h r u l e s o f a d d i t i o n a r e :

1 < i d e c i m a l )

T h t h i r d e x a m p l e i t h e o n l y o n w h i c h i d i f f e r e n t f r o md e c i m a l a d d i t i o n . W h e n w e a d p a i r o b i n a r y n u m b e r s w i t h m o r e t h a no n b i a p i e c e , w p r o c e e d f r o m r i g h t t o l e f t J u s t l i k e d e c i m a la d d i t i o n . W a d t h t w b i t s t o g e t h e r a n i t h e r e s u l t i g r e a t e rt h a n w h a v e t c a r r y 1 S o 1 1 = 1 1 0 . D o i n g t h i s a d d i t i o no n e s t e p a a t i m e , t a k i n g t h r i g h t m o s t b i t s , a n 1 a n a d d i n gt h e m b t h a b o v e r u l e s , w s e t h a t t h a n s w e r i s 1 0 , o w i t hc a r r y o 1 N e x t w a d t h n e x t p a i r o b i t s p l u s t h e c a r r y .

( 1 1 1 1 T h a t s w i t h a c a r r y o f 1 N o t et h a t 1 + i d e c i m a l a n 1 i b i n a r y w h i c h i t h e b i n a r y e q u i v a l e n t o d e c i m a l . T h e m o s t y o h a v e t r e m e m b e r i b i n a r y a d d i t i o n o f t w n u m b e r s i 0 1 1 = 1 0( c a r r y 1 ) 1 ( c a r r y 1 ) T h A D i n s t r u c t i o n d o e st h i s b i n a r y a d d i t i o n w o r k f o y o u * s y o m i g h t n o n e e d t k n o w i t O t h o t h e r h a n d * y o p r o b a b l y w i l l w h e n y o u g o t d e b u g y o u rG a l a c t i c G o b b l e r G a m e . S o y o u m i g h t j u s t a w e l l l e a r n i n o w .

Page 85: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 85/172

I n s i d e T h C o m m o d o r e 6 P t g t 9 - 1 3

W h e n i D e c i m a l m o d e , t h 6 5 1 0 e x p e c t s t h d a t a i i a d d i n gt b i " b i n a r y c o d e d d e c i m a l " f o r m a t . T h i s i y e a n o t h e r d a t af o r m a t . I B C D , t h e i g h t b i t s o f b y t e a r e i n t e r p r e t e d t b t w f o u r b i d e c i m a l d i g i t s . E a c h f o u r b i t d i g i t m a h a v e t h h e x a d e c i m a lv a l u e s o 0 - 9 . I t h e r e i s o m e o t h e r b i c o n f i g u r a t i o n i t h r a n g eo A - i e i t h e r h a l f o f t h e b y t e s b e i n g a d d e d * t h e r e s u l t s w i l l b u n m e a n i n g f u l . W h e n t h A D i e x e c u t e d i D e c i m a l m o d e , t h t w l o w -o r d e r d i g i t s a r a d d e d a n d a n y d e c i m a l c a r r y i a d d e d t o g e t h e r w i t ht h t w h i g h - o r d e r d i g i t s . T h c a r r y b i w i l l b s e i t h e r e i d e c i m a l c a r r y f r o m t h e a d d i t i o n o f t h e h i g h - o r d e r d i g i t s .

I i s t a n d a r d p r o c e d u r e t c l e a r t h e c a r r y b i b e f o r e u s i n gt h A D i n s t r u c t i o n b e c a u s e t h C a r r y b i t i s a d d e d i n t o t h r e s u l t .T h i s i n i c e f e a t u r e w h e n y o a r e d o i n g m u l t i p l e p r e c i s i o n a d d i t i o ns u c h a a d d i n g t w 3 b i n u m b e r s t o g e t h e r . T h c a r r y b i t i s t h n e e d e d c o m m u n i c a t i o n b e t w e e n t h s u c c e s s i v e b y t e s o t h a d d i t i o n .

E x a m p l e o 3 b i m u l t i p l e p r e c i s i o n a d d i t i o n :

L D # B Y T E A D D I T I O NC L

N E X T L D V A L 1 , XA D V A L 2 , XS T V A L 3 , XD E B P N E X T

S B S u B t r a c t w i t h C a r r y . T h s p e c i f i e d b y t e i m e m o r y a n t h i n v e r s e o t h C a r r y b i a r s u b t r a c t e d f r o m t h A - r e g * r e p l a c i n g t h A - r e g w i t h t h e r e s u l t . T h a t i s ( A - r e g ) = ( A - r e g ) ( a d d r ) C ( C a r r y ) 3 T h C a r r y b i t i s s e i t h c o n t e n t s o t h A - r e g a r g r e a t e r t h a n o e q u a l t o t h e v a l u e b e i n g s u b t r a c t e d f r o m i t T h C a r r y b i t i s c l e a r e d i t h v a l u e s u b t r a c t e d i l e s s t h a n t h e c o n t e n t so t h A - r e g . I d e c i d i n g w h e t h e r t h c o n t e n t s o t h A - r e g a n t h m e m o r y l o c a t i o n a r g r e a t e r t h a n o l e s s t h a n o n e a n o t h e r * t h 6 5 1 0i n t e r p r e t s t h e v a l u e s a u n s i g n e d i n t e g e r s i t h r a n g e o 0 - 2 5 5 .

T h c a r r y b i t i s l i k e a i n v e r t e d b o r r o w . I b o r r o w i r e q u i r e d * t h C a r r y b i t i s 0 I n b o r r o w i r e q u i r e d * t h C a r r y i 1 T h N e g a t i v e a n d Z e r o b i t s a r e s e b a s e d o t h r e s u l t o t h s u b t r a c t i o n . T h e O v e r f l o w b i i s e i " t w o ' s c o m p l e m e n t o v e r f l o w "o c c u r r e d . V a l i d a d d r e s s i n g m o d e s a r t h s a m e a f o t h L D

Page 86: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 86/172

I n s i d e T h C o m m o d o r e 6 P t g t 9 - 1 4

i n s t r u c t i o n .T h n o r m a l s u b t r a c t i o n p r o c e d u r e i t s e t h C a r r y b i b e f o r e

t h S B i e x e c u t e d . U s i n g t h S B t c o m p a r e t w v a l u e s r e q u i r e st e s t i n g t h M i n u s b i a f t e r t h e s u b t r a c t i o n i c o m p l e t e .

I t h e d e s i r e i t b r a n c h t P R G A i t h c o n t e n t s o V A L ia r e l e s s t h a n t h c o n t e n t s o V A L 2 t h f o l l o w i n g p r o g r a m w o u l d b u s e d :

S E L D A V A L IS B V A L 2B M P R G A

O E Q

T h a b o v e r o u t i n e w o r k s f o u n s i g n e d n u m b e r s . I c o m p a r i s o ni b e i n g m a d e o n u m b e r s w h i c h m a h a v e n e g a t i v e v a l u e s * a m o r ec o m p l e x r o u t i n e m u s t b e u s e d . T h p o s s i b i l i t y o " n e g a t i v e o v e r f l o w 1 1e x i s t s w h e n s u b t r a c t i n g n u m b e r s w h i c h a r i n t e n d e d t r e p r e s e n t v a l u e si t h r a n g e o t 1 2 7 , - t - 1 2 8 . I w t r t s u b t r a c t 1 f r o m1 2 4 » t h r e s u l t w o u l d b - 1 3 4 . T h i s i o u o t h r a n g e o n e g a t i v en u m b e r s . T h 6 5 1 0 l e t s u k n o w t h a t i t h i s w a s i g n e d o p e r a t i o n ,t h e r e s u l t h a " n e g a t i v e o v e r f l o w " . T h i s i d o n e b y s e t t i n g t h eO v e r f l o w b i t i n t h P r o c e s s o r S t a t u s R e g i s t e r . T h v a l u e w h i c h e n d su i t h A - r e g i 1 2 ( 2 5 6 - 1 3 4 ) i t h a b o v e e x a m p l e . T h u n s i g n e de q u i v a l e n t o f t h e - 1 2 4 i 1 3 ( 2 5 6 - 1 2 4 ) . A n 1 3 2 - 1 0 = 1 2 2 . T h i sp o s i t i v e r e s u l t g i v e s f a l s e i n d i c a t i o n o f t h e r e l a t i v e m a g n i t u d e o t h t w s i g n e d n u m b e r s . W h e n w o r k i n g w i t h s i g n e d n u m b e r s t h f o l l o w i n g t e c h n i q u e i n e c e s s a r y t m a k e a c c u r a t e c o m p a r i s o n s o m a g n i t u d e :

C H K M IO

S E L D S B B V B M B P B P E Q

V A L IV A L 2C H K M IP R G AO P R G A

P o s i t i v e o v e r f l o w c a o c c u r t h e s a m e w a y . S u p p o s e V A L i h a

Page 87: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 87/172

I n s i d e T h C o m m o d o r e 6 P t g t 9 - 1 5

t h e v a l u e o 1 2 a n V A L 2 h a t h v a l u e o - 4 T h i n t e n t i o n o t h a b o v e p r o g r a m i t b r a n c h t P R G A i V A L i i l e s s t h a n V A L 2 . 1 2 6 -( - 4 ) 1 3 0 . 1 3 i o u o t h r a n g e o s i g n e d n u m b e r s ( 0 - 1 2 7 ) .P o s i t i v e o v e r f l o w o c c u r e d . T h e 6 5 1 0 t e l l s u t h i s i t h s a m e w a y , b s e t t i n g t h e O v e r f l o w b i t . D o e s t h p r o g r a m w o r k f o r t h i s c a s e ? 1 2 i n o l e s s t h a n - 4 T h o v e r f l o w b i w a s e b t h S B C . T h e b r a n c hi t a k e n t C H K M I w h e r e t h N e g a t i v e b i t i s t e s t e d . I i o n b e c a u s et h e v a l u e i t h A - r e g i g r e a t e r t h a n 1 2 7 . I i s 1 3 0 . S t h b r a n c hi n o t t a k e n t P R G A . I w o r k s !

C o m p a r e I n s t r u c t i o n s .

C M C o M P a r e . T h e m a g n i t u d e o f t h e s p e c i f i e d m e m o r y l o c a t i o n i c o m p a r e d w i t h t h m a g n i t u d e o f t h e A - r e g . T h Z e r o a n d N e g a t i v e b i t sa r s e a s t h o u g h S B h a o c c u r r e d . T h e A - r e g i n o m o d i f i e d b yt h i s i n s t r u c t i o n . T h c a r r y b i n e e d n o b p r e - s e t o c l e a r e d b e f o r ee x e c u t i n g t h i n s t r u c t i o n . T h c a r r y b i i s e i t h c o m p a r e f i n d st h a t t h A - r e g i g r e a t e r t h a n t h v a l u e o t h c o n t e n t s o t h m e m o r yl o c a t i o n . T h O v e r f l o w b i i n o a f f e c t e d b t h i s i n s t r u c t i o n . I i t h e r e f o r e n o p o s s i b l e t u s t h C M t m a k e m a g n i t u d ec o m p a r i s o n s o s i g n e d n u m b e r s . T h d e s c r i p t i o n o t h S B i n s t r u c t i o ni l l u s t r a t e s t h t e c h n i q u e f o a c c o m p l i s h i n g t h i s . V a l i d a d d r e s s i n gm o d e s a r e t h e s a m e a f o t h L D i n s t r u c t i o n .

C P C o m P a r e t h X - r e g . T h X - r e g i c o m p a r e d t t h c o n t e n t s o s p e c i f i e d m e m o r y l o c a t i o n . T h i s i n s t r u c t i o n f u n c t i o n s e x a c t l y l i k et h C M i n s t r u c t i o n e x c e p t t h r e g i s t e r b e i n g c o m p a r e d i t h e X - r e g .T h v a l i d a d d r e s s i n g m o d e s a r A b s o l u t e * Z e r o P a g e a n d I m m e d i a t e .

C P C o m P a r e t h Y - r e g . T h Y - r e g i c o m p a r e d w i t h t h e c o n t e n t s o t h s p e c i f i e d m e m o r y l o c a t i o n . T h i s i n s t r u c t i o n f u n c t i o n s e x a c t l yl i k e t h C M a n C P i n s t r u c t i o n s . A d d r e s s i n g m o d e s a r t h s a m e a C P X .

Page 88: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 88/172

I n t i d t T h C o m m o d o r e 6 4 P a g t 9 - 1 6

I m p o t e n t I n s t r u c t i o n s

N O N O p e r a t i o n . T h a m a z i n g N O i n s t r u c t i o n d o e s a b s o l u t e l yn o t h i n g . I c a u s e s t h 6 5 1 0 t s p i n i t e l e c t r o n i c w h e e l s f o f e m i c r o s e c o n d s . I t a k e s u o n b y t e o f m e m o r y .

Page 89: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 89/172

I n s i d e T h C o m m o d o r e 6 p a g e 1 0 - 1

S p e c i f i c a t i o n s - f o r A s s e m b l y L a n g u a g eG e n e r a l

T h i s c h a p t e r g i v e s c o m p a c t d e s c r i p t i o n o t h c a p a b i l i t i e sa n r e s t r i c t i o n s o f t h e a s s e m b l y l a n g u a g e o t h D e v e l o p - 6 4 . F o t u t o r i a l w a l k - t h r o u g h o t h o p e r a t i o n a l u s o t h e t o o l s r e a dC h a p t e r s i - 4 .

T h a s s e m b l y l a n g u a g e s t a t e m e n t m a b m a x i m u m o 7 c h a r a c t e r s i l e n g t h . T h i s i e x a c t l y t w l i n e s o t h s c r e e n m i n u st h p r o m p t c h a r a c t e r ( " ) . T h e r e a r t w k i n d s o f s t a t e m e n t s :c o m m e n t s a n r e g u l a r a s s e m b l y l a n g u a g e s t a t e m e n t s . C o m m e n t s m u s tb e g i n w i t h i t h f i r s t p o s i t i o n . T h e r e a r n o t h e rr e s t r i c t i o n s o c o m m e n t s o t h e r t h a n t h d i s a l l o w a n c e o t h q u o t e

c h a r a c t e r . T h i s r e s t r i c t i o n a p p l i e s e q u a l l y w e l l t a l s t a t e m e n t s .

L a b e l s

T h l a b e l f i e l d , i u s e d , i t h f i r s t f i e l d o t h a s s e m b l ys t a t e m e n t . I i n o r e q u i r e d f i e l d . I u s e d » i m u s t s t a r t w i t hl e t t e r ( A - Z ) a n m a b o a n l e n g t h . T h s i n g l e c h a r a c t e r " A s h o u l d n o t b e u s e d * a i w i l l b e c o n f u s e d w i t h t h e " A o t h A c c u m u l a t o r a d d r e s s i n g m o d e w h e n a p p e a r i n g i a n o p e r a n d f i e l d . O t h e rc h a r a c t e r s w h i c h s h o u l d b e a v o i d e d a r e t h e s e v e n a l g e b r a i c o p e r a t o r sa n t h q u o t e ( " ) . L a b e l s o m o r e t h a n s e v e n c h a r a c t e r s w i l l c a u s et h a s s e m b l y l i s t i n g t b s o m e w h a t l e s s n e a t a p p e a r i n g b u w o r k j u s tf i n e .M n e m o n i c s

S t a n d a r d m n e m o n i c s

T h m n e m o n i c i t h e E n g l i s h - l i k e c o d e w h i c h g e t s t r a n s l a t e d b D e v e l o p - 6 4 i n t o t h m a c h i n e l a n g u a g e o p - c o d e . d i s c u s s i o n o t h m n e m o n i c s i f o u n d i c h a p t e r 9 S e e a p p e n d i x f o r a c o m p l e t e l i s t o a l v a l i d m n e m o n i c s a n t h e i r l e g a l a d d r e s s i n g m o d e s .

Page 90: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 90/172

I n t i d t T h C o m m o d o r e 6 4 P a g t 1 6 - 2

T h E Q p s e u d o - o p

D e v e l o p - 6 4 c o m e s e q u i p p e d w i t h t w s p e c i a l m n e m o n i c s * S Q a n B Y T . T h e s e d n o g e n e r a t e p r o c e s s o r - e x e c u t a b l e i n s t r u c t i o n s a d t h s t a n d a r d m n e m o n i c s . T h B Y p s e u d o - o p i c o v e r e d i t h n e x tp a r a g r a p h . T h E Q m n e m o n i c i a i n s t r u c t i o n t D e v e l o p - 6 4 r a t h e rt h a n a i n s t r u c t i o n t t h e m a c h i n e . I h a t w f u n c t i o n s . T h f i r s ti t s e t t h e l o c a t i o n c o u n t e r . T h i s i f u n c t i o n s o m e t i m e s l e f t t

s e p a r a t e p s e u d o - o p s u c h a O R i o t h e r a s s e m b l e r s . T h s e c o n df u n c t i o n i t e q u a t e l a b e l w i t h a a d d r e s s . T h f o r m a t o t h E Q i n s t r u c t i o n i s

L A B E L E Q a d d r - e x p r e s s i o n

T h l a b e l f i e l d i o p t i o n a l . T h e r e i o n e x c e p t i o n t t h g e n e r a l r u l e s f o a d d r e s s e x p r e s s i o n s f o t h E Q i n s t r u c t i o n . T h e x p r e s s i o n m a n o r e f e r e n c e l a b e l s w h i c h d n o p r e c e d e t h E Q i n s t r u c t i o n i t h s e g m e n t . T h i s i t r u e o n l y f o t h E Q i n s t r u c t i o na n i t h e o n l y l i m i t a t i o n o i t A n p r o g r a m r e f e r e n c e s t o t h e l a b e lo t h E Q i n s t r u c t i o n w i l l r e f e r t o t h a d d r e s s e x p r e s s e d i t h o p e r a n d f i e l d .

T h a d d r e s s e x p r e s s i o n m u s t a l w a y s b p r e s e n t . A l l t h e r u l e sa n c a p a b i l i t i e s o a d d r e s s e x p r e s s i o n a d e f i n e d b e l o w a p p l y .

E Q U a t e s t a t e m e n t s a r u s e d t a l l o w o n t u s e m e a n i n g f u lE n g l i s h w o r d s i n s t e a d o n u m e r i c v a l u e s f o a d d r e s s e s a n o t h e rn u m b e r s . T h E Q i s e u o n c e a n d a l r e f e r e n c e s t o t h e a s s i g n e dl a b e l w i l l b i n t e r p r e t e d b t h a s s e m b l e r a s t h e v a l u e a s s o c i a t e dw i t h t h l a b e l . T h E Q m a a l s o b u s e d t r e s e r v e a b l o c k o f m e m o r ya n a s s i g n i s y m b o l i c l a b e l . T h f o l l o w i n g t w l i n e s w i l l a s s i g nt h l a b e l , D A T A t t h 2 e e - b y t e b l o c k o f d a t a s t a r t i n g a $ C G e 0 :

D A T A E Q * C 0 9 0E Q U 3 + 2 9 9

T h " f l " ( a s i g n ) s y m b o l i z e s t h e l o c a t i o n c o u n t e r , e x p l a i n e d i m o r e d e t a i l l a t e r i t h c h a p t e r .

Page 91: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 91/172

I n f t i d t T h C o m m o d o r t 6 P t g e 1 1 - 3

T h B Y p s e u d o - o p

T h B Y i n s t r u c t i o n , u n l i k e t h E Q i n s t r u c t i o n , d o e s c a u s em a c h i n e l a n g u a g e c o d e t b e g e n e r a t e d b D e v e l o p - 6 4 . I t i s n o g e n e r a l l y u s e d t g e n e r a t e e x e c u t a b l e c o d e l i k e t h s t a n d a r dm n e m o n i c s . I t f u n c t i o n i t p r o v i d e m e a n s o - c a u s i n g d a t a t b s t o r e d i m e m o r y . T h d a t a g e n e r a t e d b t h B Y i n s t r u c t i o n m a b s p e c i f i e d i s e v e r a l w a y s . D e p e n d i n g o t h f i r s t c h a r a c t e r o t h o p e r a n d f i e l d , t h B Y i n s t r u c t i o n m a s p e c i f y h e x a d e c i m a l s t r i n g s o rA S C I I s t r i n g s o r a d d r e s s c o n s t a n t s o s i n g l e b y t e v a l u e s o h e x ,d e c i m a l o A S C I I .

H e x a d e c i m a l s t r i n g s

I t h f i r s t c h a r a c t e r o t h o p e r a n d f i e l d i " $ t h e n h e s t r i n g w i l l b g e n e r a t e d . A l c h a r a c t e r s f o l l o w i n g t h e " $ s h o u l d b h e d i g i t s , 0 - A - F . T h e r e m a b a n n u m b e r o s u c h d i g i t s , u t t h m a x i m u m l i n e l e n g t h c o n s t r a i n t . D e v e l o p - 6 4 w i l l c r e a t e o n e b y t eo d a t a f o e a c h p a i r o f d i g i t s . I t h e r e a r e a n o d d n u m b e r o d i g i t s , D e v e l o p - 6 4 w i l l a p p e n d " 0 o t h l e f t o t h s t r i n g .

L i t e r a l t e x t s t r i n g s

I t h f i r s t c h a r a c t e r o f t h e o p e r a n d f i e l d i " a l f o l l o w i n g c h a r a c t e r s w i l l b t r a n s l a t e d t t h C o m m o d o r e A S C I I v a l u eo f t h e c h a r a c t e r s . E a c h t e x t c h a r a c t e r i t h o p e r a n d w i l l g e n e r a t eo n b y t e o f d a t a . A l l t h e c h a r a c t e r s w h i c h m a b e n t e r e d f r o m t h k e y b o a r d w i t h t h e x c e p t i o n o t h q u o t e ( a r l e g a l . T h B Y l i t e r a l i n s t r u c t i o n i t h o n l y i n s t r u c t i o n w h i c h c a n n o t h a v ec o m m e n t f i e l d . C o m m e n t s w o u l d b e i n t e r p r e t e d a p a r t o f t h e l i t e r a lt e x t . T h l e n g t h o f t h e l i t e r a l s t r i n g i l i m i t e d o n l y b t h m a x i m u ml i n e l e n g t h l i m i t a t i o n .

D a t a c o n s t a n t s

" < " i n t h f i r s t p o s i t i o n o t h o p e r a n d f i e l d c a u s e s t h e x p r e s s i o n w h i c h f o l l o w s t b e e v a l u a t e d b y t h r u l e s o a d d r e s se x p r e s s i o n e v a l u a t i o n . T h s i n g l e b y t e w h i c h i g e n e r a t e d i t h l o w -o r d e r b y t e o f t h e r e s u l t a n t t w o - b y t e e v a l u a t i o n .

Page 92: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 92/172

I n t i d t T h C o m m o d o r t 6 4 P a g t 1 6 - 4

" > " i n t h - f i r s t p o s i t i o n c a u s e s t h g e n e r a t i o n o s i n g l eb y t e w h o s e v a l u e i t h h i g h - o r d e r ( o p a g e n u m b e r ) o t h a d d r e s se x p r e s s i o n w h i c h f o l l o w s .

A d d r e s s c o n s t a n t s

I t h f i r s t c h a r a c t e r o f t h e o p e r a n d d o e s n o m e e t a n o t h a b o v e c r i t e r i a t h e n t h o p e r a n d i e v a l u a t e d a s a n a d d r e s se x p r e s s i o n a n d t h t w b y t e s o d a t a w h i c h a r g e n e r a t e d a r i t h 6 5 1 0 a d d r e s s f o r m a t , w i t h t h l o w - o r d e r b y t e p r e c e d i n g t h h i g h - o r d e rb y t e . I s h o u l d b e n o t e d t h a t B Y i n s t r u c t i o n s u c h a s

B Y $ 3 C C

w i l l n o g e n e r a t e a n a d d r e s s c o n s t a n t i t h l o w - h i g h f o r m a t .I i h e x s t r i n g a n w i l l g e n e r a t e 0 C C T g e a a d d r e s s c o n s t a n ti w o u l d b e r e q u i r e d t w r i t e a i n s t r u c t i o n s u c h a s

B Y 0 + $ 3 C C

w h i c h w o u l d g e n e r a t e C 0 3 a e x p e c t e d .

T h f o l l o w i n g w i l l a l s o g e n e r a t e t h s a m e a d d r e s s e x p r e s s i o n :

M S E Q * 3 C CB Y M S

T h o p e r a n d f i e l d

T h o p e r a n d f i e l d f o l l o w s i m m e d i a t e l y a f t e r t h e m n e m o n i c f i e l da n s p e c i f i e s t D e v e l o p - 6 4 t h a d d r e s s o t h d a t a t b e a c c e s s e d a n dt h m o d e b w h i c h i w i l l b e a d d r e s s e d . T h e r e a r a c t u a l l y 1 3d i s t i n c t a d d r e s s i n g m o d e s b w h i c h t h e l o c a t i o n o f d a t a i s p e c i f i e d .T h f o r m a t o t h o p e r a n d f i e l d d e t e r m i n e s w h i c h m o d e w i l l b u s e d a n t h e r e f o r e e x a c t l y w h i c h o p - c o d e w i l l b g e n e r a t e d a n d h o m a n y b y t e so a d d r e s s d a t a w i l l b e g e n e r a t e d . N o a l i n s t r u c t i o n s m a u s t h s a m e s e o a d d r e s s i n g m o d e s . A p p e n d i x s p e c i f i e s t h e v a l i da d d r e s s i n g m o d e s f o e a c h i n s t r u c t i o n o m n e m o n i c .

Page 93: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 93/172

I n s i d t T h C o m m o d o r t 6 P a g t 1 6 - 5

A d d r e s s e x p r e s s i o n s

O n o t h f e a t u r e s o t h i s a s s e m b l e r i t h a b i l i t y t c r e a t ea d d r e s s e x p r e s s i o n s o f g r e a t c o m p l e x i t y ( o s i m p l i c i t y ) w i t h e a s e a n df l e x i b i l i t y . T h t e r m " a d d r e s s e x p r e s s i o n " i m e a n t t i n c l u d e t h " i m m e d i a t e " c h a r a c t e r a n B Y d a t a c o n s t a n t s a w e l l a a c t u a l m e m o r yl o c a t i o n s . A d d r e s s e x p r e s s i o n s a r a l g e b r a i c c o m b i n a t i o n s o o n o m o r e t e r m s .

T e r m s

T h e r e a r f i v e d i f f e r e n t k i n d s o f t e r m s w h i c h m a b a l g e b r a i c a l l y c o m b i n e d i a n a d d r e s s e x p r e s s i o n . E a c h h a i t o w d i s t i n g u i s h i n g f o r m a t . T h r e s u l t o f t h e e v a l u a t i o n o f t h e e x p r e s s i o nm u s t n o t b e o u t o f t h e r a n g e o f - 6 5 5 3 6 t 6 5 5 3 5 b u t t h e i n d i v i d u a lt e r m s h a v e n o m a g n i t u d e r e s t r i c t i o n s . A d d r e s s e x p r e s s i o n s w h i c he x c e e d t h m a g n i t u d e r e s t r i c t i o n s w i l l c a u s e a n E R 6

D e c i m a l f o r m a t

A n t e r m i a n a d d r e s s e x p r e s s i o n w h i c h b e g i n s w i t h 0 - o " . w i l l b i n t e r p r e t e d a d e c i m a l t e r m . D e c i m a l t e r m s m a b i n t e g e r s o m a c o n t a i n a d e c i m a l p o i n t a n f r a c t i o n a l c o m p o n e n t .F l o a t i n g p o i n t n o t a t i o n m a a l s o b u s e d ( e . g . 3 E w i l l b i n t e r p r e t e da 3 6 0 ) .

H e x a d e c i m a l f o r m a tH e x a d e c i m a l t e r m s a r t h o s e w h i c h h a v e " $ a t h f i r s t

c h a r a c t e r . A l f o l l o w i n g c h a r a c t e r s , u t i l l t h n e x t o p e r a t o r o t h e n o t h e e x p r e s s i o n , m u s t b 0 - 9 , A - F . H e x t e r m s w h i c h h a v ec h a r a c t e r s o t h e r t h a n t h e s e w i l l c a u s e a E R w h e n t h p r o g r a m i a s s e m b l e d .

L i t e r a l f o r m a t

A n t e r m i a a d d r e s s e x p r e s s i o n w h i c h b e g i n s w i t h t h c h a r a c t e r ' w i l l b i n t e r p r e t e d a l i t e r a l . T h a t i s t h v a l u e

Page 94: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 94/172

I n s i d e T h C o m m o d o r e 6 4 P a g e 1 8 - 6

a s s i g n e d t o t h a t t e r m w i l l b t h A S C I I v a l u e o - t h - f i r s t c h a r a c t e rt t h r i g h t o t h ' A n c h a r a c t e r s f o l l o w i n g t h e f i r s tc h a r a c t e r f o l l o w i n g t h q u o t e w i l l b i g n o r e d .

S y m b o l i c l a b e l

A n t e r m w h i c h d o e s n o s t a r t w i t h " $ o l " 1 1 o a " 9 " o r" . o n u m b e r ( 0 - 9 ) w i l l b i n t e r p r e t e d a s y m b o l i c l a b e l .

D e v e l o p - 6 4 w i l l s e a r c h t h e n t i r e p r o g r a m l o o k i n g f o m a t c h o n t h l a b e l f i e l d . I n o n e i f o u n d , E R 3 w i l l b g e n e r a t e d . I m a t c hi f o u n d * t h t e r m w i l l b a s s i g n e d t h v a l u e o t h a d d r e s sa s s o c i a t e d w i t h t h l a b e l . L a b e l s m a b o a n l e n g t h .

L o c a t i o n c o u n t e r

T h l o c a t i o n c o u n t e r i D e v e l o p - 6 4 ' s e q u i v a l e n t o t h p r o g r a mc o u n t e r . T h l o c a t i o n c o u n t e r i a s s i g n e d t h e v a l u e o t h a d d r e s sa s s i g n e d t t h f i r s t b y t e o t h i n s t r u c t i o n i w h i c h i a p p e a r s . I i t h a d d r e s s a w h i c h t h i n s t r u c t i o n w i l l r e s i d e o n c e T h L o a d e rP O K E S t h e l o a d s e g m e n t i n t o m e m o r y . T h i s a s s e m b l e r u s e s t h " Q s y m b o l t o s i g n i f y t h l o c a t i o n c o u n t e r . M o s t o t h e r a s s e m b l e r s u s t h " # s y m b o l f o t h i s f u n c t i o n . H o w e v e r * t h " * i i n t e r p r e t e d b D e v e l o p - 6 4 a m u l t i p l i c a t i o n o p e r a t o r . T h e 1 1 ® 1 1 s y m b o l s e e m sl o g i c a l c h o i c e * b e i n g t h " a t " s i g n a n s i g n i f y i n g w h e r e w a r " a t "i m e m o r y . A n t e r m w h i c h h a " Q a i t s f i r s t c h a r a c t e r w i l l h a v e t h v a l u e o t h e l o c a t i o n c o u n t e r . A n f o l l o w i n g c h a r a c t e r s w i t h i n t h t e r m * s h o u l d t h e y e x i s t * w i l l b i g n o r e d .

A l g e b r a i c o p e r a t o r sT h v a r i o u s t e r m s o t h a d d r e s s e x p r e s s i o n m a b c o m b i n e d

a l g e b r a i c a l l y b y t h e f o l l o w i n g o p e r a t o r s : A t h e v a l u a t i o n p r o c e e d s f r o m l e f t t r i g h t * e a c h t e r m i a d d e d t o s u b t r a c t e d f r o m * m u l t i p l i e d b y e t c . t h r e s u l t o f t h e v a l u a t i o n o t h a t p o r t i o n o t h e x p r e s s i o n t t h l e f t o f t h e o p e r a t o r * g i v i n gn e c u r r e n t e v a l u a t i o n . T h f r a c t i o n a l p o r - t . . r e s u l t o a n o p e r a t i o n w i l l b c a r r i e d i n t o t h e n e x t o p e r a t i o n . T h f i n a le v a l u a t i o n o t h e x p r e s s i o n w i l l t r u n c a t e a n f r a c t i o n a l c o m p o n e n t sa n w i l l c o n v e r t n e g a t i v e n u m b e r s i n t o s i x t e e n b i t w o ' s c o m p l e m e n tv a l u e s .

Page 95: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 95/172

I n s i d e T h C o m m o d o r e 6 4 P a g e 1 8 - 7

A d d i t i o n M

T h a d d i t i o n o p e r a t o r c a u s e s t h t e r m i m m e d i a t e l y f o l l o w i n gt h " + t b a d d e d t t h r e s u l t o f t h e e v a l u a t i o n o t h e p o r t i o n o t h e x p r e s s i o n t t h l e f t o t h " + " .

S u b t r a c t i o n » - "

T h s u b t r a c t i o n o p e r a t o r c a u s e s t h t e r m t o t h e r i g h t o t h m i n u s s i g n t b s u b t r a c t e d f r o m t h e x p r e s s i o n t t h l e f t o t h m i n u s .

M u l t i p l i c a t i o n " *

T h m u l t i p l i c a t i o n o p e r a t o r c a u s e s t h e x p r e s s i o n t o t h e l e f to f t h e * t b m u l t i p l i e d b t h t e r m t o t h e r i g h t o f t h e

D i v i s i o n " / T h d i v i s i o n o p e r a t o r c a u s e s t h e x p r e s s i o n t t h l e f t o

t h t b d i v i d e d b t h t e r m t t h r i g h t o t h "

E x p o n e n t i a t i o n w

T h e x p o n e n t i a t i o n o p e r a t o r c a u s e s t h e x p r e s s i o n t o t h e l e f to t h t b r a i s e d t o t h e p o w e r o t h t e r m t o t h e r i g h t o t h 1 1 " F r a c t i o n a l p o w e r s m a y b e m p l o y e d w i t h d e c i m a l t e r m s . I i t h e r e f o r e p o s s i b l e t d s u c h t h i n g s a t a k e s q u a r e r o o t s w i t he x p r e s s i o n s s u c h a s

X A . 5

L o g i c a l A N D n & T h l o g i c a l A N o p e r a t o r c a u s e s t h r e s u l t o f t h e v a l u a t i o n

o t h e x p r e s s i o n t o t h e l e f t o f t h e " & t b l o g i c a l l y A N D e d w i t ht h t e r m t t h r i g h t o t h " & T h l o g i c a l A N o p e r a t i o n c o m p a r e st h t w t e r m s o t h o p e r a t i o n b i b b i t , g i v i n g a r e s u l t w i t h a b i s e o i e v e r y b i p o s i t i o n w h e r e b o t h t e r m s h a v e b i o n . I t s m a i nu s i t o f o r c e b i t s o f f i c e r t a i n d e s i r e d b i p o s i t i o n s , w h i l e

Page 96: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 96/172

I n t i d t T h C o m m o d o r e 6 P a g t 1 8 - 8

r e t a i n i n g t h s t a t u s q u i a l o t h e r p o s i t i o n s .

L o g i c a l O " % T h l o g i c a l O o p e r a t o r c a u s e s t h e r e s u l t o t h e e v a l u a t i o n o

t h e x p r e s s i o n t o t h e l e f t o f t h e " % " t b l o g i c a l l y O R ' e d w i t h t h et e r m t o t h e r i g h t : o f t h e " % T h l o g i c a l O o p e r a t i o n c o m p a r e s t h t w t e r m s o t h o p e r a t i o n b i b b i t , g i v i n g r e s u l t w i t h a b i s e o i e v e r y b i p o s i t i o n w h e r e e i t h e r t e r m h a b i o n I t m a i n u s ei t f o r c e b i o i c e r t a i n d e s i r e d b i p o s i t i o n s , w h i l e r e t a i n i n gt h s t a t u s q u i a l o t h e r p o s i t i o n s .

E x p r e s s i o n e v a l u a t i o n

A h a b e e n i n d i c a t e d i p r e v i o u s s e c t i o n s , s e v e r a l t e r m s m a b e c o m b i n e d i n t o a a l g e b r a i c e x p r e s s i o n , t h e v e n t u a l e v a l u a t i o n o fw h i c h w i l l r e s u l t i t h a d d r e s s s p e c i f i c a t i o n . T h e r e a r s e v e r a lf e a t u r e s o t h e e v a l u a t i o n a l g o r i t h m w h i c h m u s t b u n d e r s t o o d f o p r o p e r u s o t h a l g e b r a i c c a p a b i l i t y . F i r s t * t h o r d e r o e v a l u a t i o n i n o l i k e B A S I C . H e r e , t h e e x p r e s s i o n i e v a l u a t e d f r o ml e f t t r i g h t t r e g a r d l e s s o f w h a t o p e r a t o r s a p p e a r i t h e x p r e s s i o n .F o e x a m p l e , t h e x p r e s s i o n :

L A & i + G H % $ C / I J

w o u l d b e v a l u a t e d i t h e f o l l o w i n g w a y : T h a d d r e s s o L w o u l d b A N D ' e d w i t h t h e v a l u e i T h r e s u l t w o u l d b a d d e d t t h a d d r e s s o G H . T h a t r e s u l t w o u l d b O R ' e d w i t h * 8 C . T h r e s u l t o f t h a to p e r a t i o n w o u l d b d i v i d e d b t h a d d r e s s o I J T h f i n a l m a s s a g e o t h e x p r e s s i o n c o n v e r t s n e g a t i v e e x p r e s s i o n v a l u e s t o t w o ' sc o m p l e m e n t v a l u e b t h e a d d i t i o n o 6 5 5 3 6 t t h n e g a t i v e v a l u e . B w a o e x a m p l e :

- $ F F F F * - $ F F F E , - 2 5 6 $ F F 8 8 , a n - 2 5 7 $ F E F F .

" > T h h i g h - o r d e r s y m b o l

I t h " > s y m b o l i t h f i r s t c h a r a c t e r o t h a d d r e s se x p r e s s i o n * t h e e x p r e s s i o n w i l l b e v a l u a t e d a u s u a l b u t h f i n a l

Page 97: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 97/172

I n t i d t T h C o m m o d o r t 6 4 P a g t 1 6 - 9

o p e r a t i o n w i l l b t d i v i d e t h e e x p r e s s i o n ' s v a l u e b 2 5 6 . T h i sr e s u l t s i t h h i g h - o r d e r b y t e o t w o - b y t e v a l u e . T h i s i c o n v e n i e n t w a o e x p r e s s i n g t h p a g e - n u m b e r o a a d d r e s s . E x a m p l e :

S C R E E N E Q $ 8 4 6 0L D # > S C R E E N

w i l l c a u s e t h v a l u e $ 9 t b l o a d e d i n t o t h A - r e g .

n < T h l o w - o r d e r s y m b o l

T h i s s y m b o l o p e r a t e s J u s t l i k e t h h i g h - o r d e r s y m b o l e x c e p t t h f i n a l o p e r a t i o n i t p r o d u c e o n l y t h l o w - o r d e r b y t e o f t h e a d d r e s se x p r e s s i o n e v a l u a t i o n .

C o m p l e x e q u a t i o n s

F o t h o s e w h w i s h t u s m o r e c o m p l e x e q u a t i o n s t h a n c a n b eh a n d l e d b e x p r e s s i o n s w h i c h a r e v a l u a t e d s t r i c t l y l e f t t r i g h t * i i p o s s i b l e t a c c o m m o d a t e t h e m b y a s e r i e s o E Q U ' s w h i c h t h e m s e l v e sa r e e x p r e s s i o n s . F o e x a m p l e * t r e p r e s e n t a e q u a t i o n s u c h a s

< C - ( D / E ) ) * ( F & G )y o c o u l d w r i t e t h e f o l l o w i n g c o d e :

D E Q U D / EF E Q U F & GA B E Q U B + C - D E * F E

M u c h m o r e c o m p l e x e x p r e s s i o n s m a b r e p r e s e n t e d i s i m i l a r f a s h i o n .

T h c o m m e n t f i e l d

C o m m e n t s a r e n t e r e d o t h s t a t e m e n t l i n e b s k i p p i n g a tl e a s t o n e s p a c e a f t e r t h o p e r a n d f i e l d b e f o r e k e y i n g t h e c o m m e n t .C o m m e n t s a r n o t a l l o w e d o B Y i n s t r u c t i o n s w h i c h d e f i n e l i t e r a ls t r i n g s .

Page 98: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 98/172

I n s i d e T h C o m m o d o r e 6 4 P a g t i e - i «

E x p l i c i t z e r o p a g e a d d r e s s i n g c o n v e n t i o n

W h e n z e r o p a g e m o d e o a d d r e s s i n g i d e s i r e d i i n e c e s s a r yt e x p l i c i t l y i n d i c a t e s u c h d e s i r e b y p r e c e e d i n g t h a d d r e s se x p r e s s i o n w i t h t h e " l e f t - a r r o w " ( B ) . T h i s i t h o n l y w a t h t w o -b y t e z e r o p a g e a d d r e s s s i n g m o d e w i l l b s e l e c t e d . O m i t t i n g i w i l lr e s u l t i t h e l o n g f o r m o t h i n s t r u c t i o n . T h i s p r o v i d e s t h c a p a b i l i t y o a d d r e s s i n g z e r o p a g e w i t h l o n g i n s t r u c t i o n i d e s i r e d .N o t e t h a t t h i s r e q u i r e m e n t i s f o r Z P Z P t X a n Z P » Y m o d e s o n l y a n n o f o ( i n d i r * X ) a n ( i n d i r ) , Y m o d e s .

Page 99: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 99/172

I n s i d e T h C o m m o d o r e 6 P a g e i i - 1

G r a p h i c s o t h C o m m o d o r e 6 T h e s e n e x t c h a p t e r s w i l l a t t e m p t t e x p a n d u p o n t h

i n f o r m a t i o n f o u n d i t h C o m m o d o r e 6 P r o g r a m m e r ' s R e f e r e n c e G u i d e( P R G ) . T h P R s h o u l d b c o n s i d e r e d a i n d i s p e n s i b l e r e f e r e n c e t o o l .I i y o w i l l f i n d c o m p l e t e d e s c r i p t i o n s o f t h e v a r i o u s s p e c i a lf u n c t i o n i n t e g r a t e d c i r c u i t s w h i c h m a k e t h 6 t h p o w e r f u l c o m p u t e ri i s A l s o i n c l u d e d i i n f o r m a t i o n o t h e 6 4 ' s m e m o r y o r g a n i z a t i o na n t h " k e r n a l " r o u t i n e s a n h o t u s t h e m .

T h i s c h a p t e r w i l l p r o v i d e t h m a c h i n e l a n g u a g e p r o g r a m m e r ' sp e r s p e c t i v e o g r a p h i c s g e n e r a t i o n . J o s t i c k a n d p a d d l e u s a g e a n ds o u n d g e n e r a t i o n w i l l b c o v e r e d i t h f o l l o w i n g c h a p t e r . T h l a s tc h a p t e r w i l l c o v e r s o m e o t h i n t e r n a l p r o g r a m s c o n t a i n e d i t h 6 4 ' sR O a n t h m e a n s b w h i c h y o c a m a k e u s o t h e m .

T h V i d e o I n t e r f a c e C h i p

T h V i d e o I n t e r f a c e C h i p ( t h e V I C - I I ) i t h e l e c t r o n i cm a c h i n e * t h e i n t e g r a t e d c i r c u i t w i t h i n t h e 6 w h i c h t a m o n g o t h e rt h i n g s * c a u s e s p a t t e r n s t b d i s p l a y e d o y o u r v i d e o s c r e e n . I i a l s o k n o w n a t h e 6 5 6 7 . T h V I C - I I i c o n n e c t e d t t h 6 5 i e a n t h R A a n R O o f t h e 6 v i t h a d d r e s s * d a t a a n c o n t r o l b u s s e s .

T h V I C - I I r u n s c o n t i n u o u s l y f r o m t h e t i m e t h e p o w e r i t u r n e do u n t i l l i i t u r n e d o f f . I i u n d e r c o n t r o l o f i t o w i n t e r n a lp r o g r a m w h i c h i b u i l t i n t o t h e l e c t r o n i c s o f t h e c h i p . I h a 4 8 b i r e g i s t e r s w h i c h m a b a d d r e s s e d b t h 6 5 i 0 a n d t h e r e f o r e a n yp r o g r a m r u n n i n g o t h 6 5 1 6 . T h r e g i s t e r s a r t h c o m m u n i c a t i o nm e d i u m b w h i c h w d i r e c t t h o p e r a t i o n o f t h e V I C - I I . T h e y a r w i r e dd i r e c t l y t t h a d d r e s s b u s i s u c h w a t h a t w c a c h a n g e t h e i rc o n t e n t s b y s t o r i n g d a t a i n t o a d d r e s s e s $ D e e e t h r o u g h $ D 8 2 E ( 5 3 2 4 8 -5 3 2 9 5 ) . P O K E s f r o m B A S I C a n S T A s » S T X s a n S T Y s f r o m m a c h i n el a n g u a g e i n t o t h e s e l o c a t i o n s w i l l m o d i f y t h i n t e r n a l r e g i s t e r s o t h V I C - I I . W w i l l l o o k a t h s p e c i f i c a t i o n o t h e s e r e g i s t e r s a n h o t h e y c a u s e t h v a r i o u s g r a p h i c s c a p a b i l i t i e s t b a c t i v a t e d a n c o n t r o l l e d .

B a n k S w i t c h i n g

B u f i r s t * i i n e c e s s a r y t u n d e r s t a n d t h b a n k s w i t c h i n gc a p a b i l i t y i n c o r p o r a t e d i n t o a n o t h e r c h i p * t h 6 5 2 6 C o m p l e x i n t e r f a c e

Page 100: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 100/172

I r a i d t T h C o m m o d o r t 6 P a g t 1 1 - 2

a d a p t e r c h i p # ( C I A # 2 ) . B a n k s w i t c h i n g i t e r m w h i c h r e f e r s t t h c a p a b i l i t y o d i s c o n n e c t i n g o n b a n k o m e m o r y a n c o n n e c t i n g a n o t h e rb a n k i i t p l a c e . W h e n t h V I C - I I i d o i n g i t s t h i n g , i " l o o k s a t

b a n k o m e m o r y t f i n d t h p a t t e r n s t s e n d o u t o f t h e v i d e o p o r ta n d o n t o y o u r v i d e o s c r e e n . T h V I C - I I i d e s i g n e d t o " s e e " a n o n o f o u r 1 6 K b a n k s o m e m o r y . W h i c h b a n k i s e e s a a n o n t i m e i d e t e r m i n e d b t h e " b a n k - s e l e c t b i t s " o t h C I A # 2 . T s w i t c h b e t w e e n

. d i f f e r e n t b a n k s t h e f o l l o w i n g m a c h i n e l a n g u a g e p r o g r a m w i l l d t h t r i c k :

B A N K E Q C O U L D B 8 , 1 , 2 O L D $ D D 8 2 D A T A D I R R E G I S T E RO R A # 3 B I T S 8 , S E T O U T P U TS T * D D 8 2L D $ D D 8 8 O U T P U T P O R T A C I A # 2A N # * F C F O R C E B I T S 8 , O F O R # B A N K S E L E C T B A N KS T $ D D 8 8

W h e n t h 6 i p o w e r e d u b a n k i s e l e c t e d a u t o m a t i c a l l y .T h a d d r e s s r a n g e o t h v a r i o u s b a n k s a n d t h c o r r e s p o n d i n g v a l u ew h i c h m u s t b s p e c i f i e d i t h B A N K E Q U a t e f o l l o w :

Page 101: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 101/172

I n s i d e T h C o m m o d o r e 6 P a g e 1 1 - 3

B A N K E Q B A N K N U M B E R B A N K A D D R E S S R A N G E* 8 8 8 8 - * 3 F F F ( 8 - 1 6 3 8 3 )$ 4 8 8 8 - * 7 F F F ( 1 6 3 8 4 - 3 2 7 6 7 )$ 8 8 8 8 - * B F F F ( 3 2 7 6 8 - 4 9 1 5 1 )$ C 8 8 8 - $ F F F F ( 4 9 1 5 2 - 6 5 5 3 5 )

A l d a t a u s e d b t h V I C - I I i i t c r e a t i o n o f v i d e o i m a g e sw i l l c o m e f r o m t h b a n k o m e m o r y w h i c h i c u r r e n t l y s e l e c t e d v i t h C I A # 2 . T h m a o w h a t d a t a w i l l b e f o u n d w h e r e i e a c h b l o c k w i l ld e p e n d o n t h v a l u e s s t o r e d i t h v a r i o u s V I C - I I r e g i s t e r s . B u b e f o r e g e t t i n g i n t o t h a t l e t s l o o k a h o t h V I C - I I p u t s c h a r a c t e r so t h s c r e e n .

M u l t i p l e c h a r a c t e r s e t s

Y o h a v e n d o u b t n o t i c e d t h a t e a c h c h a r a c t e r w h i c h i d i s p l a y e d o y o u r s c r e e n i c o m p o s i t e o u t 6 d o t s a r r a n g e d i a b b l o c k . T h i n f o r m a t i o n w h i c h d e s c r i b e s t h e c h a r a c t e r i s t i cd o t p a t t e r n o e a c h c h a r a c t e r i s t o r e d i t h 6 4 ' s R O M .

c e r t a i n s e c t i o n o f R A i r e s e r v e d f o u s b t h 6 a " s c r e e n m e m o r y 1 1 . T h e r e i o n b y t e o s c r e e n m e m o r y r e s e r v e d f o e v e r yc h a r a c t e r p o s i t i o n o t h e s c r e e n . S i n c e t h e r e a r 4 c o l u m n s a n 2 r o w s t h e r e a r e 1 8 8 8 b y t e s o s c r e e n m e m o r y . T h d a t a s t o r e d i e a c hp o s i t i o n o s c r e e n m e m o r y m a y h a v e t h v a l u e o 8 - 2 5 5 # t h e r a n g e o v a l u e s o o n b y t e o f i n f o r m a t i o n . T h i s m a b c o n s i d e r e d t h c h a r a c t e r " c o d e " . B a c h c o d e s t a n d * f o m u n i q u e p a t t e r n o f d o t s .T h e r e a r t h e r e f o r e 2 5 p o s s i b l e d o t p a t t e r n s w h i c h m a b d i s p l a y e da a n o n t i m e . T h V I C - I I s c a n s c o n t i n u o u s l y t h r o u g h s c r e e n m e m o r ya n t r a n s l a t e s e a c h c o d e f o a l 1 6 6 6 s c r e e n p o s i t i o n s . T h t r a n s l a t i o n p r o c e s s c o n s i s t s o u s i n g t h e v a l u e o t h c o d e ( 8 - 2 5 5 ) t c o m p u t e t h d i s p l a c e m e n t ( o n u m b e r o f b y t e s ) i n t o c h a r a c t e r p a t t e r nt a b l e . E a c h c h a r a c t e r p a t t e r n h a 6 b i t s ( b y t e s ) o " d o t "i n f o r m a t i o n . S t f i n d t h r i g h t p a t t e r n , t h e V I C - I I m u l t i p l i e s t h v a l u e o f t h e c o d e b a n a d d s t h e r e s u l t t o t h e s t a r t i n g a d d r e s s o t h c h a r a c t e r p a t t e r n t a b l e . T h e r e , t h V I C - I I f i n d s t h 8 - b y t ep a t t e r n o d o t s t s e n d t o t h e v i d e o s c r e e n . T h f i r s t e i g h t b i t s o

c h a r a c t e r ' s p a t t e r n a r e t h e t o r o o d o t s w h i c h a p p e a r o t h s c r e e n . T h s e c o n d e i g h t b i t s a r t h s e c o n d r o a n s o u n t i l l t h

Page 102: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 102/172

I n i i d t T h C o m m o d o r e 6 P a g e 1 1 - 4

e i g h t h e i g h t b i t s f o t h b o t t o m r o w . T h V I C - I I d o e s t h i s s c a n n i n go s c r e e n m e m o r y a n t r a n s l a t i n g t h e c o d e s f o u n d t h e r e u s i n g t h p a t t e r n t a b l e a n s e n d i n g t h d o t i n f o r m a t i o n o u t t o t h e v i d e o p o r ta l a u t o m a t i c a l l y a n c o n t i n u o u s l y .

T h B A S I C " P R I N T " s t a t e m e n t c a u s e s " s c r e e n c o d e s " t b e s t o r e di s c r e e n m e m o r y . I i p o s s i b l e a l s o t P O K E s c r e e n c o d e s i n t os c r e e n m e m o r y . M a c h i n e l a n g u a g e p r o g r a m s m a s t o r e s c r e e n c o d e s i n t os c r e e n m e m o r y . T h e V I C - I I a u t o m a t i c a l l y a n c o n t i n u o u s l y s c a n s t h s c r e e n m e m o r y , g e t t i n g o n s c r e e n c o d e p e r s c r e e n l o c a t i o n a n d *t r a n s l a t e s t h e s c r e e n c o d e i n t o a e i g h t b e i g h t d o p a t t e r n w h i c h i t h e n s e n d s t t h v i d e o o u t p u t p o r t t b d i s p l a y e d . I a p p e n d i x o t h P R t h e r e i a t a b l e o s c r e e n c o d e s a n t h c o r r e s p o n d i n gc h a r a c t e r s w h i c h g e t d i s p l a y e d . T h e s e a r e t h e s t a n d a r d c h a r a c t e r sw h i c h a r b u r n e d i n t o t h 6 4 ' s c h a r a c t e r - t a b l e R O a $ D O G 0 - $ D i F F( 5 3 2 4 8 - 5 5 2 9 5 ) .

Y o a r p r o b a b l y a w a r e t h a t w h e n y o h o l d t h C o m m o d o r e a n t h S h i f t K e y s d o w n s i m u l t a n e o u s l y * t h e c h a r a c t e r s w h i c h a p p e a r o t h s c r e e n a r f r o m s e c o n d c h a r a c t e r s e t . O n c h a r a c t e r s e t c o n t a i n su p p e r a n d l o w e r c a s e c h a r a c t e r s a n d t h o t h e r c o n t a i n s u p p e r c a s e a n t h g r a p h i c s c h a r a c t e r s . T h e r e a r t w s e t s o f p a t t e r n s s t o r e di R O a n t h V I C - I I c a n b e " s w i t c h e d " b e t w e e n t h s e t s . I f a c t ,t h V I C - I I c a n b e s w i t c h e d b e t w e e n s e v e r a l d i f f e r e n t t a b l e s o p a t t e r n s . O n o t h V I C - I I ' s r e g i s t e r s d e t e r m i n e s w h e r e i t h b a n kt h e c h a r a c t e r t a b l e i t b f o u n d . S i n c e e a c h b a n k w h i c h t h V I C - I Ic a n s e e i 1 6 b y t e s l o n g a n s i n c e 2 5 c h a r a c t e r s t a k e 2 5 o 2 6 4 8 ( 2 K ) b y t e s , t h e r e c a n b e i g h t d i f f e r e n t c h a r a c t e r t a b l e sa c c e s s i b l e t t h V I C - I I i a n g i v e n b a n k . S i n c e t h e r e a r b a n k sa v a i l a b l e , t h e r e m a b u t 3 2 s e p a r a t e c h a r a c t e r s e t s a c c e s s i b l e t t h V I C - I I .

T h r e g i s t e r w h i c h c o n t r o l s w h i c h o t h e i g h t b l o c k s w i t h i nt h e c u r r e n t b a n k t u s f o t h e c h a r a c t e r p a t t e r n t a b l e i f o u n d a 5 3 2 7 2 ( $ 0 6 1 8 ) . I t a k e s t h r e e b i t s t s p e c i f y t h p a t t e r n l o c a t i o n .T h e s e t h r e e b i t s a r b i t s 3 a n o t h r e g i s t e r . T h f o u r h i g h -o r d e r b i t s o f t h i s s a m e r e g i s t e r a r u s e d f o a n o t h e r p u r p o s e a n m u s tn o t b e m o d i f i e d w h e n s w i t c h i n g b e t w e e n c h a r a c t e r s e t s . B i t - 0 i n o s i g n i f i c a n t . T h f o l l o w i n g r o u t i n e i l l u s t r a t e s t h e s e l e c t i n g o f t h ed e s i r e d c h a r a c t e r - p a t t e r n t a b l e .

Page 103: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 103/172

I n t i d t T h C o m m o d o r t 6 4 P t g t i l - 5

T A B L E E Q O O 4 6 , 8 , 1 0 1 O 1 L D A 5 3 2 7 2 G E T H R E G I S T E RA N t t * F 0 T U R N B I T S 3 - O F O R # T A B L E S E T H T A B L E - S E L E C T B I T SS T 5 3 2 7 2 R E S E T T H R E G I S T E R

T h v a l u e o f t h e T A B L E E Q s e l e c t s t h e l o c a t i o n o t h c h a r a c t e r p a t t e r n t a b l e w i t h i n t h s e l e c t e d b a n K . T h f o l l o w i n gt a b l e g i v e s t h p o s i t i o n w i t h i n t h b a n k f o t h v a r i o u s p o s s i b l ev a l u e s o T A B L E :

T A B L E L O C A T I O N W I T H I N B A N K

* 0 0 0 0 - * 8 7 F F < 0 - 2 0 4 7 )* 8 8 8 0 - $ 0 F F F < 2 0 4 8 - 4 0 ? 5 )* 1 0 0 0 - * 1 7 F F ( 4 0 9 6 - 6 1 4 3 )* 1 8 0 0 - $ 1 F F F ( 6 1 4 4 - 8 1 9 1 )* 2 0 0 0 - $ 2 7 F F ( 8 1 9 2 - 1 0 2 3 9 )

1 $ 2 8 0 0 - * 2 F F F ( 1 0 2 4 0 - 1 2 2 8 7 )1 $ 3 0 0 0 - $ 3 7 F F ( 1 2 2 8 8 - 1 4 3 3 5 )1 $ 3 8 0 0 - $ 3 F F F ( 1 4 3 3 6 - 1 6 3 8 5 )

S i n c e t h e l o c a t i o n s p e c i f i e d a b o v e i t h e r e l a t i v e a d d r e s sw i t h i n t h e c u r r e n t l y s e l e c t e d b a n k , t o a r r i v e a t h e a c t u a l a d d r e s s o t h c h a r a c t e r p a t t e r n t a b l e i i n e c e s s a r y t a d t h s t a r t i n ga d d r e s s o t h s e l e c t e d b a n k t t h a d d r e s s e s a b o v e . S e l e c t i n g a a l t e r n a t e t a b l e a d d r e s s a n d c r e a t i n g y o u r o w p a t t e r n t a b l e i t h t e c h n i q u e w h i c h y o u m u s t u s t c r e a t e y o u r o w c u s t o m c h a r a c t e r s a n t d h i g h - r e s o l u t i o n b i t - i m a g e g r a p h i c s . W e ' l l d i s c u s s t h o s ec a p a b i l i t i e s m o r e l a t e r .

T h C o m m o d o r e 6 c o m e s p r e - p r o g r a m m e d w i t h o n l y t w c h a r a c t e rp a t t e r n t a b l e s * t h u p p e r c a s e / g r a p h i c s s e a n t h u p p e r / l o w e r c a s es e t . T h e s e a r i R O a $ D 0 O e - D i F F a n $ D 3 0 0 - * D F F F . T h i s a l s oh a p p e n s t b w h e r e t h V I C - I I ' s r e g i s t e r s r e s i d e * w h i c h s e e m s m i g h t yc o n f u s i n g a f i r s t . T h e r e i a e x p l a n a t i o n . T h 6 5 1 0 h a v e r yi n t e r e s t i n g f e a t u r e w h i c h a l l o w s b o t h R A M , R O a n I / t a l o c c u p yt h s a m e a d d r e s s s p a c e . N o a t h s a m e t i m e o c o u r s e . T h b a n ks w i t c h i n g c o n c e p t i u s e d h e r e . W d i s c u s s e d a t h e n o C h a p t e rt h s p e c i a l c h a r a c t e r i s t i c s r e l a t i n g t o l o c a t i o n a n i t h 6 5 1 0 ' sm e m o r y s p a c e . W m e n t i o n e d a t h a t t i m e t h a t t h e 6 u s e s t h I / p o r t

Page 104: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 104/172

I n s i d e T h C o m m o d o r t 6 P a g e 1 1 - 6

a 8 , f o i t o w s p e c i a l p u r p o s e s . T h i s p o r t c o n t r o l s b a n k -s w i t c h i n g d e v i c e w h i c h s w i t c h e s R A M * R O a n I / i a n o u t o f t h m e m o r y s p a c e . T h i s i t h w a t h 6 c a h a v e f u l l 6 4 o R A M , 2 6 o R O a n 4 o I / a l a d d r e s s a b l e o 1 6 - b i t a d d r e s s b u s w h i c h c a o n l y h a v e 6 4 p o s s i b l e u n i q u e a d d r e s s e s .

I t h p r o g r a m m e r w i s h e s t c o p y p a r t o r a l o t h c h a r a c t e rR O i n t o s o m e p a r t o f R A M , i w i l l b n e c e s s a r y t s w i t c h t h I / a $ D 9 e e o u a n s w i t c h t h e R O i n B e c a u s e i n t e r r u p t p r o c e s s i n g o t h 6 u t i l i z e s t h I / w h i c h y o w a n t t s w i t c h o u t , i i n e c e s s a r y t d i s a b l e i n t e r r u p t s b e f o r e s w i t c h i n g i t h R O M . T h f o l l o w i n g r o u t i n ew i l l t u r n o f i n t e r r u p t s ! s w i t c h i t h R O M , m o v e t h e c h a r a c t e r t a b l e ts w i t c h t h I / b a c k i a n t u r n i n t e r r u p t s b a c k o n

L O O P

D O N E

L D A N S T L D A N S T L D L D L D S T I N B N D E B E I N I N J M L D O R S T L D O R S T

5 6 3 3 4# * F E5 6 3 3 4B # * F BB # # < S R C E ) , Y< D E S T ) , Y

L O O P

D O N EB S R C E + 1B D E S T + 1L O O PB # B 5 6 3 3 4# 5 6 3 3 4

S E T B I T O F T U R N S I N T E R R U P T S O F

B I O F S W I T C H E S R O I C O U N T O P A G E S T O M O V EB Y T E C O U N T E R

D E C R P A G E S B

N E X T P A G E O D A T A T M O V EN E X T P A G E O W H E R E T O P U I D N O T H E R P A G E

S W I T C H I / B A C K I N R O M O U TT U R N I N T E R R U P T S B A C K O

T h i s r o u t i n e a s s u m e s S R C E a n D E S T a r l a b e l s d e f i n e d e l s e w h e r ei t h p r o g r a m w h i c h a d d r e s s t w o - b y t e z e r o - p a g e v e c t o r s w h i c h h a v eb e e n p r e - s e t t a d d r e s s t h e c h a r a c t e r p a t t e r n R O a n t h p l a c e y o

Page 105: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 105/172

I n s i d e T h C o m m o d o r e 6 P a g e 1 1 - 7

w i s h t m o v e t h e c h a r a c t e r t a b l e t o W h e n t h s y s t e m i p o w e r e d u b a n k a n T A B L E 4 a r e

a u t o m a t i c a l l y s e l e c t e d b t h p o w e r - u p p r o g r a m . T h 6 h a a n o t h e rf e a t u r e w h i c h c a n b e e i t h e r c o n v e n i e n t o r b o t h e r d e p e n d i n g o y o u rn e e d s . W h e n b a n k o b a n k i s e l e c t e d a n t h T A B L E v a l u e i o

t h e V I C - I I w i l l g e t h c h a r a c t e r p a t t e r n s f r o m t h s t a n d a r d R O p a t t e r n t a b l e r a t h e r t h a n f r o m R A a y o m i g h t e x p e c t . T h u s , t h V I C - I I s e e s t h R O c h a r a c t e r p a t t e r n s a $ 1 0 0 0 - $ 1 F F F a n a $ 9 0 0 0 -$ 9 F F F e v e n t h o u g h t h e r e i r e a l l y R A t h e r e . I t ' s v e r y t r i c k y c h i p ft h a t V I C - I I . N o t e t h a t t h i s i V I C - I I r e l a t e d p h e n o m e n o n o n l y . T h m e m o r y a t h e s e a d d r e s s e s i r e a l l y R A a n y o m a t r e a t i a s u c hf o a l p u r p o s e s . P r o g r a m s a n d a t a s t o r e d t h e r e w i l l n o t b e i a n w a m o l e s t e d .

N o w * t c r e a t e y o u r o w c u s t o m c h a r a c t e r s y o m u s t b u i l dp a t t e r n t a b l e w h i c h d e s c r i b e s t h e d o t p a t t e r n s o t h c h a r a c t e r s y o w i s h t b u i l d . T h p a t t e r n t a b l e s c o n s i s t o u t 2 5 p a t t e r n s . E a c hp a t t e r n h a e i g h t b y t e s . b i t u r n e d o i a n o t h b y t e s w i l lc a u s e t h c o r r e s p o n d i n g d o o t h s c r e e n t b i l l u m i n a t e d . ( T h es c r e e n d o t s a r e a l s o c a l l e d p i x e l s w h i c h c o m e s f r o m " p i c t u r ee l e m e n t s " , )

I t h s t a n d a r d p a t t e r n t a b l e t h e s c r e e n c o d e " 0 r e f e r s t t h f i r s t 8 - b y t e p a t t e r n , t h a t o f t h e c h a r a c t e r " @ " . T h i s p a t t e r n m a b f o u n d b e g i n n i n g a 5 3 2 4 8 ( $ D 0 0 0 ) w h e n t h R O h a s b e e n s w i t c h e d i n r e e t h e a b o v e r o u t i n e f o s w i t c h i n g t h R O i m a c h i n e l a n g u a g e . T d i i B A S I C t h e f o l l o w i n g r o u t i n e c o u l d b u s e d .

P O K E 5 6 3 3 4 , P E E K ( 5 6 3 3 4 ) A N D 2 5 4 : P O K E i , P E E K ( i ) A N D 2 5 i

T h s e c o n d c h a r a c t e r i t h s t a n d a r d c h a r a c t e r R O s t a r t s a 5 3 2 5 6 a n i t h p a t t e r n f o r t h e l e t t e r " A ( s c r e e n c o d e i ) E v e r y e i g h t b y t e s ,a n o t h e r p a t t e r n i s t o r e d . T h i s g o e s o n f o 2 5 6 8 - b y t e p a t t e r n s . T h s c r e e n c o d e s 1 2 8 - 2 5 5 a r e t h e " r e v e r s e " o t h f i r s t 1 2 p a t t e r n s .T h a t i s w h e r e b i t i s o i o n e , i i o f i t h o t h e r .

T h f i r s t b y t e o s c r e e n m e m o r y h o l d s t h c h a r a c t e r c o d e w h i c hc o r r e s p o n d s t o b p a t t e r n i t h t a b l e t o b d i s p l a y e d i t h f i r s t c o l u m n o t h f i r s t r o o f t h e s c r e e n . T h f i r s t 4 p o s i t i o n so s c r e e n m e m o r y c o r r e s p o n d t o t h e f i r s t r o o t h e s c r e e n . T h s e c o n d 4 c h a r a c t e r s c o r r e s p o n d t t h s e c o n d r o a n s f o r t h .

A p o w e r - o n t i m e t h e 6 4 ' s b a n k a d d r e s s i s i n i t i a l i z e d t $ 0 0 0 0a n t h s c r e e n m e m o r y l o c a t i o n i s e t $ 0 4 0 0 ( 1 0 2 4 ) . Y o u m a y c r e a t e

Page 106: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 106/172

I n t i d t T h C o m m o d o r e 6 4 P a g t 1 1 - 8

a n s w i t c h b e t w e e n s e v e r a l s c r e e n s v e r y r a p i d l y t o c r e a t e t h e e f f e c to f f o r e g r o u n d / b a c k g r o u n d o r f o r o t h e r i n t e r e s t i n g e f f e c t s .

I y o P O K E 1 0 2 4 , i t h s c r e e n c o d e " 1 " w i l l b p l a c e d i t h s c r e e n m e m o r y p o s i t i o n c o r r e s p o n d i n g t t h u p p e r l e f t c h a r a c t e rp o s i t i o n o t h s c r e e n . D i a n y o s h o u l d s e t h l e t t e r " A a p p e a r t h e r e . T h V I O I I h a t r a n s l a t e d t h v a l u e i n t o t h c h a r a c t e r p a t t e r n f o t h l e t t e r " A b c o m p u t i n g K t h e c h a r a c t e rc o d e ) ( t h e n u m b e r o b y t e s p e p a t t e r n ) a n a d d i n g t h a t t t h s t a r t o f t h e c h a r a c t e r p a t t e r n t a b l e w h i c h s t a r t s a 5 3 2 4 8 ( R O Ml o c a t i o n w h i c h c a n o n l y b P E E K e d b s w i t c h i n g t h e I / o u t a n d t h R O i a e x p l a i n e d a b o v e ) . I s t a r t s a t h a t a d d r e s s ( 5 3 2 5 6 ) b u i l d i n gt h d o t p a t t e r n t s e n d t o t h e v i d e o s c r e e n . I f i n d s t h e f o l l o w i n ge i g h t b y t e s o d a t a s t a r t i n g a t 5 3 2 5 6 :

a d d r d e h e b i n a r y

5 3 2 5 6 2 $ 1 0 0 0 1 1 0 0 05 3 2 5 7 6 $ 3 0 0 1 1 1 1 0 05 3 2 5 8 1 0 % 6 0 1 1 0 0 1 1 05 3 2 5 9 1 2 $ 7 0 1 1 1 1 1 1 05 3 2 6 0 1 0 % 6 6 0 1 1 0 0 1 1 05 3 2 6 1 1 0 % 6 6 0 1 1 0 0 1 1 05 3 2 6 2 1 0 % 6 0 1 1 0 0 1 1 05 3 2 6 3 $ 0 0 0 0 0 0 0 0 0 0

I y o l o o k a t t h e a b o v e p a t t e r n o o n e s a n z e r o s , y o w i l lb a b l e t s e t h s h a p e o f t h e c h a r a c t e r " A f o r m e d b t h o n e s o nt h b a c k g r a o u n d o z e r o s . A l l o f t h e c h a r a c t e r s 7 s h a p e s a r f o r m e d i t h s a m e f a s h i o n . T h c h a r a c t e r s y o u f o r m i y o u r p r o g r a m m u s t f o l l o wt h s a m e r u l e s .

T c r e a t e t h n e c h a r a c t e r s i i n e c e s s a r y t b u i l d s e o 8 - b y t e p a t t e r n s i t h s a m e w a t h o r i g i n a l s e i c o n s t r u c t e d . I i n o n e c e s s a r y t r e s e r v e c o m p l e t e 2 0 4 8 b y t e b l o c k o f m e m o r y f o r ac o m p l e t e 2 5 6 c h a r a c t e r s i y o o n l y h a v e f e c h a r a c t e r s y o u w i s h t e v e r s e o t h e s c r e e n . H o w e v e r , y o m a n o u s b o t h t h s t a n d a r ds e t s a n d a n y s p e c i a l p r o g r a m m e d s e t s s i m u l t a n e o u s l y . O n c e t h b a n ka d d r e s s a n t h e V I C - I I ' s r e g i s t e r a 5 3 2 7 2 ( $ D 0 i 8 ) h a s b e e n s e t , t h e n t i r e s c r e e n w i l l b g e n e r a t e d u s i n g t h c h a r a c t e r p a t t e r n s f o u n d a t h s p e c i f i e d p a t t e r n t a b l e a r e a .

Page 107: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 107/172

I n s i d e T h C o m m o d o r e 6 P a g t i l - 9

M u l t i p l e S c r e e n s

T h l o c a t i o n o f s c r e e n m e m o r y i d e t e r m i n e d b y b o t h t h 1 6 b a n k s e l e c t e d a d e s c r i b e d a b o v e a n t h h i g h - o r d e r 4 b i t s D f t h r e g i s t e r f o u n d a 5 3 2 7 2 ( $ D 0 1 3 ) . T h l o c a t i o n o f s c r e e n m e m o r y w i t h i nt h b a n k m a b s e l e c t e d w i t h t h f o l l o w i n g s i m p l e r o u t i n e :

S C R N E Q U $ 6 0 ( O $ 1 , 2 0 , 3 0 , 4 0 , 5 0 , . . E , F 0 )L D $ D 0 1 8 G E R E G I S T E RA N # $ 0 F T U R N O F H I G H B I T S , S A V E L O O R # S C R N T U R N O T H S C R E E N S E L E C TS T $ D 0 1 8 S A V E N E R E G I S T E R

T h e r e a r 1 p o s s i b l e l o c a t i o n s w i t h i n t h e c u r r e n t b a n k a w h i c h s c r e e n m e m o r y c a b e g i n . S c r e e n m e m o r y i 1 0 0 0 b y t e s l o n g ( 2 4 0 ) . T h f o l l o w i n g t a b l e d e f i n e s t h d i s p l a c e m e n t w i t h i n t h b a n k f o t h b e g i n n i n g o e a c h o t h p o s s i b l e s c r e e n l o c a t i o n s a n t h v a l u eo S C R N w h i c h w i l l s e l e c t e a c h .

S C R N S C R E E N M E M O R Y S T A R T I N G A D D R E S S W I T H I N B A N K

$ 6 $ 1 $ 2 $ 3 $ 4 $ 5 $ 6 $ 7 $ 8 $ 9 $ A $ B $ C $ D $ E $ F

$ 0 0 0 0$ 0 4 0 0$ 0 8 0 0$ 0 C 0 0$ 1 0 0 0$ 1 4 0 0$ 1 8 0 0$ 1 C 0 0$ 2 0 0 0$ 2 4 0 0$ 2 8 0 0$ 2 C 0 0$ 3 0 0 0$ 3 4 0 0$ 3 8 0 0$ 3 C 0 0

( 0 ( 1 0 2 4 )< 2 0 4 8 )( 3 0 7 2 )< 4 0 9 6 )< 5 1 2 0 )< 6 1 4 4 )( 7 1 6 8 )< 8 1 9 2 )< 9 2 1 6 )< 1 0 2 4 0 )( 1 1 2 6 4 )( 1 2 2 8 8 )( 1 3 3 1 2 )( 1 4 3 3 6 )( 1 5 3 6 0 )

Page 108: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 108/172

Page 109: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 109/172

I n t i d e T h C o m m o d o r t 6 P a g e 1 1 - 1 1

c o n t r o l i n f o r m a t i o n w h i c h i n o s e l e c t a b l e l i k e t h s c r e e n o c h a r a c t e r p a t t e r n t a b l e . T h a t i s t h e r e i o n l y o n c o l o r m e m o r y a r e aa n i d e f i n e s t h c o l o r o e a c h o f t h e 1 0 0 0 c h a r a c t e r p o s i t i o n s o t h s c r e e n r e g a r d l e s s o w h i c h s c r e e n m e m o r y o r c h a r a c t e r s e y o a r u s i n g . T h 1 0 0 0 b y t e s o c o l o r m e m o r y s t a r t s a 5 5 2 9 6 ( $ D 8 0 0 ) a n r u n s t h r o u g h 5 6 2 9 5 ( $ D B E 7 ) . T h f i r s t 4 b y t e s d e f i n e t h e c o l o r o t h t o r o o c h a r a c t e r s a n s o n T h 1 p o s s i b l e c o l o r s a n t h v l a u e s w h i c h c o r r e s p o n d t t h e m a r t h o s e l i s t e d a b o v e f o t h b a c k g r o u n d a n b o r d e r .

A l t e r n a t e d i s p l a y m o d e s

T h e r e a r t w c o n t r o l b i t s w h i c h f u r t h e r d e t e r m i n e t h w a t h V 7 C - I I i n t e r p r e t s c h a r a c t e r s h a p e d a t a f r o m t h c h a r a c t e r m e m o r y . T h 4 - b i t i t h e r e g i s t e r a 5 3 2 7 0 s e t s t h m u l t i - c o l o r m o d e . T h 5 - b i to f t h e r e g i s t e r a t 5 3 2 6 5 s e t s t h h i g h - r e s b i m a m o d e . E i t h e r o b o t h o t h e s e b i t s m a b e s e t a n r e s e t b t h p r o g r a m m e r b t y p i c a lb i t - m a n i p u l a t i o n c o d e :

H I R E S E Q 5 3 2 6 5M U L T I E Q U 5 3 2 7 0S E T H I L D H I R E S G E T H H I R E S R E G I S T E R

O R A # 3 2 O O T H 5 - B I TS T H I R E S S T O R E T H N E H I R E S R E G I S T E R

S E T M C L D A M U L T I G E T T H M U L T I - C O L O R R E G I S T E RO R A # 1 6 O R O N T H 4 - B I TS T M U L T I S T O R E T H E N E W M U L T I - C O L O R R E

C L R H I L D H I R E SA N # * D F A N O F T H 5 - B I TS T H I R E S

C L R M C L D A M U L T IA N # * E F A N O F T H E 4 - B I TS T A M U L T I

T h w a i w h i c h t h v i d e o d i s p l a y i c r e a t e d d e p e n d s u p o n t h v a l u e o t h e s e t w b i t s a n s o m e t i m e s o t h e v a l u e o f t h e i n d i v i d u a l

Page 110: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 110/172

Page 111: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 111/172

I n s i d e T h C o m m o d o r e 6 P a g e 1 1 - 1 3

c o l o r m o d e .I b i t - 3 o f t h c h a r a c t e r c o l o r b y t e f o a n y g i v e n s c r e e n

p o s i t i o n i n o o n t h u s u a l s t a n d a r d r e s o l u t i o n c h a r a c t e r i g e n e r a t e d . H e r e , t h e o n l y c o l o r s w h i c h m a b u s e d a r 0 - 7 .

B i m a p p e d G r a p h i c s

I n t h i s m o d e e a c h p i x e l o t h s c r e e n m a b i n d i v i d u a l l yt u r n e d o a n o f f . I i u s e f u l f o r p l o t t i n g g e o m e t r i c s h a p e s a n f o g r a p h i n g f u n c t i o n s a n c r e a t i n g c o m p l e x g r a p h i c s .

S i n c e t h e r e a r 1 0 0 0 s c r e e n p o s i t i o n s a n e a c h p o s i t i o n h a 6 p i x e l s * i m u s t t a k e 6 4 * 0 0 0 b i t s o 8 0 0 0 b y t e s t s t o r e a l t h s c r e e ni n f o r m a t i o n i b i t - m a p p e d m o d e . B i t - m a p p e d m o d e i a c t i v a t e d b s e t t i n g b i t - 5 o f t h e r e g i s t e r a 5 3 2 6 5 ( $ D 0 1 1 ) a i n d i c a t e d a b o v e .O n c e t h m o d e h a s b e e n s e l e c t e d * t h V I C - I I n o u s e s s c r e e n m e m o r y t i n d i c a t e t h c o l o r c o m b i n a t i o n o f t h e b i t s w h i c h a r t u r n e d o a n o f i t h e i g h t b e i g h t s q u a r e o t h s c r e e n . T h h i g h - o r d e r f o u r b i t st e l l i t h e c o l o r o f t h e b i t s w h i c h a r s e t i T h l o w - o r d e r f o u rb i t s t e l l i t h c o l o r o f t h b i t s w h i c h a r s e t 0 B u t w h e r e a r e t h e b i t s s t o r e d w h i c h i n d i c a t e p i x e l s t i l l u m i n a t e d i t h t w p o s s i b l e c o l o r s ? I s t a n d a r d c h a r a c t e r m o d er e c a l l t h a t t h e s c r e e n m e m o r y b y t e s t o l d t h e V I C - I I w h e r e t g t f i n d t h e c h a r a c t e r b i p a t t e r n t d i s p l a y o t h s c r e e n . I b i m a p p e d m o d e t h c h a r a c t e r m e m o r y i s t i l l w h e r e t h i n f o r m a t i o n i s t o r e d . B u n o t h f i r s t e i g h t b y t e s o c h a r a c t e r m e m o r y a l w a y sc o r r e s p o n d s t t h 6 p i x e l s i t h u p p e r l e f t c o r n e r o f t h e s c r e e n .T h f i r s t b y t e c o n t a i n s t h p i x e l i n f o r m a t i o n f o t h t o r o o e i g h td o t s . T h s e c o n d b y t e c o n t a i n s t h i n f o r m a t i o n f o t h r o o e i g h td o t s i m m e d i a t e l y b e l o w t h f i r s t r o a n d s o f o r t h u n t i l l t h e i g t h r o e i g h t d o t s i t h u p p e r l e f t c o r n e r o t h e s c r e e n . T h s e c o n d e i g h tb y t e s c o n t a i n s t h e d o t i n f o r m a t i o n o t h s e c o n d b s q u a r e o n t h f i r s t r o o t h e s c r e e n . T h 4 0 t h g r o u p o e i g h t b y t e s c o r r e s p o n d s t t h u p p e r r i g h t c o r n e r a n t h 1 0 0 0 t h e i g h t b y t e s c o n t a i n s t h i n f o r m a t i o n f o t h l o w e r r i g h t 6 4 - b i t s q u a r e . T h p r o g r a m i t h a p p e n d i x i l l u s t r a t e s i d e t a i l h o t h m a c h i n e l a n g u a g e p r o g r a m m e rc a p l o t p o i n t s o t h s c r e e n b y c o m p u t i n g t h p r o p e r b y t e a n b i t t u r n o o r o f f g i v e n p a i r o n u m b e r s w h i c h c a n v a r y f r o m 0 - 3 1 9 a n 0 - 1 9 9 ( t h e a n a x i s o t h p l o t ) .

Page 112: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 112/172

I n s i d t T h C o m m o d o r e 6 P a g e 1 1 - 1 4

M u l t i - c o l o r b i t - m a p p e d m o d e

B s e t t i n g b o t h t h h i - r e s a n t h m u l t i - c o l o r b i t s y o c a b i m a u s i n g t h r e e c o l o r s i a d d i t i o n t o t h e b a c k g r o u n d s c r e e n c o l o r .T h i s i s i m i l a r t m u l t i - c o l o r m o d e i t h a t t h e d o t s a r f a i t h h o r i z o n t a l d i r e c t i o n a n t h b i t s w h i c h i n d i c a t e w h a t i o a n o f o t h s c r e e n a r g r o u p e d i p a i r s . T h s a m e a m o u n t o m e m o r y i r e q u i r e d t o m u l t i - c o l o r b i m a t h s c r e e n , 8 0 6 6 b y t e s . I i s l i k ei s t a n d a r d b i t - m a p m o d e * f o u n d w h e r e t h e c h a r a c t e r p a t t e r n t a b l e i s e t b e T h f o u r t w o - b i t c o m b i n a t i o n s i e a c h b y t e t e l l t h V I C - I Iw h i c h c o l o r s t m a k e t h f a d o t s o n t h s c r e e n . " 0 0 " c o m b i n a t i o ns a y s m a k e i t h b a c k g r o u n d c o l o r . " 0 1 " s a y s m a k e i t h c o l o ri n d i c a t e d b t h h i g h - o r d e r f o u r b i t s o f t h e a s s o c i a t e d s c r e e n m e m o r yb y t e . " 1 0 " c o m b i n a t i o n s a y s m a k e i t h c o l o r i n d i c a t e d b t h l o w -o r d e r f o u r b i t s o f t h e s c r e e n m e m o r y b y t e . F i n a l l y * t h e " 1 1 "c o m b i n a t i o n s a y s m a k e i t h c o l o r s e i t h c o l o r m e m o r y b y t ea s s o c i a t e d w i t h t h e s c r e e n l o c a t i o n i q u e s t i o n .

E x t e n d e d b a c k g r o u n d c o l o r m o d e

U n b e l i e v a b l y * t h e r e a r e s t i l l m o r e m o d e s o d i s p l a y a v a i l a b l et h r o u g h t h c o m b i n e d e l e c t r o n i c i n t e l l i g e n c e o t h 6 5 1 0 a n t h V I C -I c h i p . I y o u h a v e s o m e h o w m a d e i t h i s f a r * y o m i g h t a w e l l w a d et h r o u g h t h i s o n t o b e c a u s e s p r i t e s a r s t i l l t c o m e .

T h i s m o d e i s e l e c t e d b t u r n i n g o t h e 6 - b i t o f t h e r e g i s t e ra 5 3 2 6 5 ( $ 0 0 1 1 ) . W h a t i d o e s i t l e y o v a r y t h e b a c k g r o u n dc o l o r f r o m c h a r a c t e r t c h a r a c t e r i y o a r n o s a t i s f i e d w i t h h a v i n gt h s a m e b a c k g r o u n d o n t h e n t i r e s c r e e n . T h w a i t ' s d o n e i s T h t w h i g h - o r d e r b i t s o f t h s c r e e n m e m o r y b y t e s a r i n t e r p r e t e d a b a c k g r o u n d c o l o r s e l e c t o r . T h f i r s t t h i n g t h i s m e a n s i t h a t i t h i sm o d e t h e c h a r a c t e r s e t i l i m i t e d t o 6 c h a r a c t e r s ( t h e r e m a i n i n gb i t s c a o n l y h a v e 6 p o s s i b l e u n i q u e v a l u e s ) . T h t w s e l e c t o r b i t si n d i c a t e t h r e g i s t e r f o r t h e V I C - I I t u s t m a k e t h b a c k g r o u n dc o l o r . T h f o l l o w i n g t a b l e g i v e s t h p o s s i b i l i t i e s :

Page 113: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 113/172

I n s i d e T h C o m m o d o r e 6 4 P a g e 1 1 - 1 5

B i t - 7 B i t - 6 B a c k g r o u n d c o l o r r e g i s t e r

5 3 2 8 15 3 2 8 25 3 2 8 35 3 2 8 4

< * D 6 2 1 >< * D 0 2 2 >< $ D 9 2 3 )< * D 0 2 4 >

Y o u m a y s e t h r e g i s t e r s w i t h t h u s u a l 1 p o s s i b l e c o l o rc o d e s a s i d e n t i f i e d a b o v e .

S p r i t e G r a p h i c s

T h s u b j e c t w e ' v e a l b e e n w a i t i n g f o r . A y o p r o b a b l y k n o w ,s p r i t e s a r s p e c i a l m o v a b l e - f i g u r e s w h i c h m a b d e s i g n e d t h a v e a n s h a p e a n c o l o r c o m b i n a t i o n a n d w i l l c o e x i s t w i t h a l o t h e r m o d e s o d i s p l a y s i m u l t a n e o u s l y . T h e y a r n i c e g a m e p r o g r a m m e r s ' t o o l s . I i r e c o m m e n d e d y o r e a d t h d e s c r i p t i o n o s p r i t e s a n t h e i r c a p a b i l i t i e si t h P R G , a i i q u i t e g o o d . O n c e y o u h a v e c o m f o r t a b l e f e e l i n ga b o u t m a c h i n e l a n g u a g e y o u w i l l b a b l e t o t r a n s l a t e t h e B A S I Cs t a t e m e n t s g i v e n i t h P R e a s i l y t a s s e m b l e r .

E i g h t s p r i t e s m a b d e f i n e d a o n t i m e . T h e m e t h o d o s p r i t ed e f i n i t i o n i i d e n t i c a l t t h a t o f c u s t o m c h a r a c t e r d e f i n i t i o n . I nf a c t , t h e r e a r e t w m o d e s o s p r i t e d e f i n i t i o n * s t a n d a r d a n dm u l t i c o l o r , j u s t l i k e c h a r a c t e r s . T h m u l t i - c o l o r m o d e m i m i c s t h o t h e r m u l t i - c o l o r s t a n d a r d s .

T h s t a n d a r d s p r i t e i 2 d o t s w i d e b 2 h i g h . T h m u l t ic o l o r s p r i t e t a k e s j u s t a m u c h s p a c e o n t h s c r e e n b u e a c hd e f i n a b l e d o i t h h o r i z o n t a l d i r e c t i o n i t w i c e a f a a s t a n d a r d d o t . T h e r e f o r e * t h e r e a r e o n l y 1 d e f i n a b l e h o r i z o n t a lp o s i t i o n s i t h e m u l t i - c o l o r s p r i t e . A l s o , t h b i t s w h i c h d e f i n e t h s h a p e o t h s p r i t e a r g r o u p e d i p a i r s f o r m u l t i - c o l o r , a g a i n j u s tl i k e m u l t i - c o l o r c h a r a c t e r s . T h s t a n d a r d s p r i t e h a h i g h e rr e s o l u t i o n b u t m a b o f o n l y o n c o l o r .

T h m e m o r y l o c a t i o n w h e r e s p r i t e s a r e " d r a w n " m u s t b i t h s a m e 1 b l o c k a t h s c r e e n m e m o r y a n c h a r a c t e r m e m o r y a e x p l a i n e da t h b e g i n n i n g o t h i s c h a p t e r . A t h e n o t h b l o c k o m e m o r y w h i c h h o l d s t h s c r e e n m e m o r y t h V I C - I I e x p e c t s t f i n d t h p o i n t e r s t o t h e s p r i t e d e f i n i t i o n s . E a c h p o i n t e r i a s i n g l e b y t e a n m a h a v e v a l u e i t h r a n g e o 0 - 2 5 5 . T h p o i n t e r v a l u e , w h e n

Page 114: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 114/172

I n s i d e T h C o m m o d o r e 6 P a g e 1 1 - 1 6

m u l t i p l i e d b 6 4 a n d a d d e d t t h b a s e a d d r e s s o t h b a n k , w i l l p o i n tt h e V I C - I I t t h s p r i t e d e f i n i t i o n b l o c k . T h V I C - I I d o e s a l t h a ta r i t h m e t i c i t s e l f . Y o n e e d n ' t w o r r y a b o u t i a n m o r e t h a n t s e i t u o n c e c o r r e c t l y . T h a t i s y o u m u s t p i c k t h p l a c e i m e m o r y w h e r ey o w o u l d l i k e t b u i l d a s p r i t e ( i m u s t b o a e v e n 6 4 - b y t eb o u n d a r y ) * c o m p u t e h o f a t h a t i f r o m t h b e g i n n i n g o t h b l o c k ,d i v i d e b y 6 4 a n s t o r e t h a t v a l u e i t h s p r i t e p o i n t e r l o c a t i o n a tt h e n o f t h e s c r e e n m e m o r y i b l o c k . G o t h a t ?

T h s p r i t e s a r e n u m b e r e d 0 - 7 a n d t h c o r r e s p o n d i n g s p r i t ep o i n t e r s a r i l o c a t i o n s 1 0 1 6 - 1 0 2 3 o t h s c r e e n m e m o r y b l o c k . T h s p r i t e n u m b e r a l s o s p e c i f i e s t h e s p r i t e i n t e r s e c t i o n p r i o r i t y . T h l o w e r t h s p r i t e n u m b e r , t h h i g h e r t h p r i o r i t y . T h i s m e a n s t h a tw h e n t w m o v i n g s p r i t e s p a s s e a c h o t h e r o t h e s c r e e n , t h e o n w i t ht h l o w e r s p r i t e n u m b e r w i l l p a s s i f r o n t o f t h e h i g h e r n u m b e r e ds p r i t e . T r a n s p a r e n t a r e a s i t h f r o n t - p a s s i n g s p r i t e w i l l e n a b l e t h l o w e r - p r i o r i t y s p r i t e t b s e e n t h r o u g h t h " w i n d o w " .

T h e r e i a " s p r i t e - e n a b l e " r e g i s t e r a $ D 0 i 5 ( 5 3 2 6 9 ) w h i c h i t h w a s p r i t e s a r e t r i g g e r e d o n c e t h e y h a v e b e e n b u i l t a n p o i n t e d -t o T h V I C - I I , w h e n i d e t e c t s s p r i t e h a s b e e n e n a b l e d , w i l l f i n di t s h a p e d e f i n i t i o n v i t h p o i n t e r , i t d e s i r e d l o c a t i o n o t h s c r e e n v i a n o t h e r s e o r e g i s t e r s . I w i l l p r o c e e d t t h e n b u i l dt h v i d e o s i g n a l t o r e f l e c t t h e d e s c r i p t i o n y o h a v e p r o v i d e d i t T h s p r i t e - e n a b l e r e g i s t e r h a s a n e n a b l e b i f o e a c h s p r i t e . L o g i c a l l ye n o u g h , b i t - 0 e n a b l e s s p r i t e - 0 a n b i t - l e n a b l e s s p r i t e - i , e t c .

E a c h s t a n d a r d s p r i t e m a h a v e a n o f t h e 1 p o s s i b l e c o l o r s .T h r e g i s t e r s w h i c h d e t e r m i n e s p r i t e c o l o r a r a 5 3 2 8 7 - 5 3 2 9 4 ( $ D 0 2 7 -$ D 0 2 E ) f o s p r i t e s 0 - r e s p e c t i v e l y . A l d o t s w h i c h a r " o n " a f l a g g e d b b i o i t h 6 b y t e s p r i t e d e s c r i p t o r a r e a w i l l h a v et h c o l o r i n d i c a t e d i t h a p p r o p r i a t e r e g i s t e r . T h o t h e r s p a c e a d e f i n e d b b i t s t u r n e d o f ( s e t t 0 w i l l t a k e t h c o l o r o f w h a t e v e rb a c k g r o u n d i b e h i n d t h s p r i t e a t a n g i v e n t i m e . A m e n t i o n e db e f o r e , t h s p r i t e s m a h a v e m o r e t h a n o n c o l o r i d e f i n e d a m u l t i - c o l o r s p r i t e . T h i s i a c c o m p l i s h e d b s e t t i n g t h e c o r r e s p o n d i n gb i ( 0 - 7 ) i n t h s p r i t e m u l t i - c o l o r r e g i s t e r a 5 3 2 7 6 ( $ D 0 1 C ) . W h e ns p r i t e i s s e l e c t e d , t h V I C - I I w i l l i n t e r p r e t t h b i p a i r s o t h s p r i t e s h a p e d e s c r i p t i o n i t h e f o l l o w i n g w a y : " 0 0 " b i p a i r w i l lc a u s e t r a n s p a r e n c y . T h a t i s t h b a c k g r o u n d w i l l s h i n e t h r o u g h .b i p a i r o f " 0 1 " w i l l c a u s e t h d o u b l e - w i d e d o t s h a v i n g t h a td e f i n i t i o n t b d i s p l a y e d i t h c o l o r s e i t h s p r i t e m u l t i - c o l o rr e g i s t e r # a 5 3 2 8 5 ( $ D 0 2 5 ) . T h b i p a i r " 1 0 " w i l l c a u s e t h

Page 115: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 115/172

I n t i d t T h C o m m o d o r t 6 P a g e 1 1 - 1 7

a f o r e m e n t i o n e d s p r i t e c o l o r r e g i s t e r a p p r o p r i a t e f o t h s p r i t e i q u e s t i o n ( a 5 3 2 8 7 - 5 3 2 9 4 ) t o a p p e a r . F i n a l l y , b i p a i r o " 1 1 " w i l lc a u s e t h c o l o r s e i s p r i t e m u l t i - c o l o r r e g i s t e r # a 5 3 2 8 6 ( $ D 0 2 6 )t s h a d e a l p a r t s o t h s p r i t e w h i c h a r s e u w i t h t h " 1 1 "d e f i n i t i o n .

S p r i t e s m a b e x p a n d e d i b o t h t h h o r i z o n t a l a n t h v e r t i c a ld i r e c t i o n s . R e g i s t e r s a 5 3 2 7 7 ( $ D 0 1 D ) a n d 5 3 2 7 1 ( $ D 0 1 7 ) a r t h s p r i t e - e x p a n d r e g i s t e r s f o t h h o r i z o n t a l a n t h v e r t i c a l d i r e c t i o n sr e s p e c t i v e l y . T h b i t - p o s i t i o n s i e a c h r e g i s t e r c o r r e s p o n d t o t h es p r i t e t o e x p a n d . W h e n t h b i i o t h s p r i t e w i l l b a u t o m a t i c a l l ye x p a n d e d t t w i c e i t s i z e i t h a x i s s e l e c t e d . T h d i r e c t i o n o e x p a n s i o n i t t h l e f t a n t o w a r d t h b o t t o m o t h s c r e e n .

T p o s i t i o n a s p r i t e o t h s c r e e n , i i n e c e s s a r y t t e l l t h V I C - I I w h e r e y o w a n t i t g o A y o m i g h t h a v e g u e s s e d , t h e r e a r es o m e r e g i s t e r s w h i c h d j u s t t h a t . T h s p r i t e s m a b p o s i t i o n e d o o o f f t h e s c r e e n . T h e r e i a s o r t - o f s p r i t e o v e r f l o w a r e a o a l b o r d e r s o t h s c r e e n . S p r i t e s m a b m a d e t d r i f t s m o o t h l y o f t h s c r e e n b p r o p e r l y d e f i n i n g t h p o s i t i o n o f t h e s p r i t e .

T h p o s i t i o n w h i c h y o m u s t g i v e t o t h e V I C - I I i t h a t o t h u p p e r l e f t - m o s t d o o t h s p r i t e , e v e n i t h a t d o i d e f i n e d a s a ni n v i s i b l e d o t . T h p o s i t i o n y o d e f i n e i h o r i z o n t a l p i x e lp o s i t i o n a n v e r t i c a l p i x e l p o s i t i o n o f t h a t u p p e r - l e f t c o r n e r o t h s p r i t e . H o r i z o n t a l p o s i t i o n s m a v a r y f r o m t 5 1 a n v e r t i c a lf r o m . t o 2 5 5 . S i n c e t h e r e a r o n l y 3 2 p i x e l s b 2 0 i t h a c t u a lv i e w i n g a r e a t h i s l e a v e s t h n e c e s s a r y s p a c e a b o v e , b e l o w a n t o t h er i g h t a n l e f t o t h s c r e e n f o o f f - s c r e e n s p r i t e m o v e m e n t . T h l e f to f t h e s c r e e n i h o r i z o n t a l p i x e l p o s i t i o n 2 a n t h r i g h t s i d e o ft h v i e w a b l e s c r e e n i p i x e l p o s i t i o n 3 4 3 . S o s p r i t e w o u l d b v i s i b l e a t l e a s t p a r t i a l l y i t h s p e c i f i e d h o r i z o n t a l p o s i t i o n w e r eb e t w e e n a n d 3 4 3 ( a s s u m i n g t h a t t h e r e a r e n o n - t r a n s p a r e n t d o t s i t h r i g h t m o s t a n d l e f t m o s t c o l u m n s o d o p o s i t i o n s i t h s p r i t ed e f i n i t i o n ) . S p r i t e s e x p a n d e d i t h e h o r i z o n t a l d i r e c t i o n w i l l b a l e a s t p a r t i a l l y v i s i b l e i t h s p e c i f i e d h o r i z o n t a l p o s i t i o n i l e s st h a n 3 4 3 o g r e a t e r t h a n 4 8 8 . T h s e c o n d c o n d i t i o n i d u t t h w r a p - a r o u n d n a t u r e o t h p i x e l a d d r e s s i n g s c h e m e u s e d b t h V I C - I I .P o s i t i o n 5 1 1 i e q u i v a l e n t t - o t h l e f t s i d e o f t h s c r e e n .

T h t o o f t h e s c r e e n m a b e c o n s i d e r e d t b v e r t i c a l p i x e lp o s i t i o n 5 ( f r o m t h e t o o f t h e o f f - s c r e e n a r e a w h i c h s t a r t s a 0 ) T h e b o t t o m o f t h e s c r e e n i p i x e l p o s i t i o n i 2 4 9 . N o r m a l s p r i t e sw i l l b c o m p l e t e l y o f t h t o o f t h e v i e w i n g s c r e e n i t h v e r t i c a l

Page 116: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 116/172

I n s i d e T h C o m m o d o r e 6 P a g e 1 1 - 1 8

s p r i t e p o s i t i o n i s e a 2 o l e s s . I w i l l b o f t h b o t t o m i t h v e r t i c a l p o s i t i o n i 2 5 o g r e a t e r . E x p a n d e d s p r i t e s w i l l b o f s c r e e n i l e s s t h a n a n i g r e a t e r t h a n 2 4 9 .

T h r e g i s t e r s t s e p o s i t i o n i n f o r m a t i o n a r a 5 3 2 4 8 t h r o u g h5 3 2 6 3 4 . T h f i r s t 1 6 r e g i s t e r s a r e t h e h o r i z o n t a l a n v e r t i c a lp o s i t i o n r e g i s t e r s f o s p r i t e s 0 - r e s p e c t i v e l y . T h h o r i z o n t a lp o s i t i o n n e e d s m o r e i n f o r m a t i o n t h a n c a n b e c o n t a i n e d i s i n g l eb y t e * h o w e v e r . U t 5 1 2 u n i q u e p i x e l p o s i t i o n s m a b s p e c i f i e d f o rt h h o r i z o n t a l d i r e c t i o n . T h e r e f o r e a n o t h e r b i t i s r e q u i r e d t c o m p l e t e l y d e f i n e t h e p o s i t i o n . T h a t b i t i s f o u n d i t h M o s t -s i g n i f i c a n t - b i t r e g i s t e r a 5 3 2 4 8 . E a c h s p r i t e , 0 - h a i t h o r i z o n t a l m o s t - s i g n i f i c a n t - b i t o f p o s i t i o n i n f o r m a t i o n s t o r e d i t h c o r r e s p o n d i n g ( 6 - 7 ) b i t p o s i t i o n s o t h M S r e g i s t e r . S m o o t hh o r i z o n t a l s p r i t e m o v e m e n t s w i l l t a k e s o m e e x t r a c a r e f r o m t h p r o g r a m m e r t k e e p t r a c k o t h p o s i t i o n a n s e t h a t e x t r a b i c o r r e c t l y .

F i n a l l y , c o l l i s i o n d e t e c t i o n m u s t b c o v e r e d . S p r i t e s m a c o l l i d e w i t h o t h e r s p r i t e s a n w i t h t h b a c k g r o u n d . I c a n b e n i c e t k n o w w h e n c o l l i s i o n h a o c c u r r e d . T h v e r s a t i l e l i t t l e V I C - I Iw a t c h e s o v e r i t v i d e o d o m a i n a n r e p o r t s a l s u c h h a p p e n i n g s t y o u .A l y o u h a v e t d i r e a d t h r e g i s t e r w h i c h t h V I C - I I m a i n t a i n s f o t h a t p u r p o s e .

C o l l i s i o n s a r e d e f i n e d a n o n - t r a n s p a r e n t p o r t i o n o a s p r i t eo v e r l a p s a n o n - t r a n s p a r e n t p o r t i o n o a n o t h e r s p r i t e o r b a c k g r o u n dc h a r a c t e r s . F o t h p u r p o s e o c o l l i s i o n d e t e c t i o n , m u l t i - c o l o rs p r i t e d o t s d e f i n e d w i t h t h " 0 1 " b i p a i r a r c o n s i d e r e d t r a n s p a r e n t .

l i t t l e q u i r k t h e r e .T h s p r i t e - s p r i t e c o l l i s i o n r e g i s t e r i a 5 3 2 7 8 ( $ D 0 i E ) a n e a c h

b i t i n t h r e g i s t e r s t a n d s f o r a s p r i t e . A n t i m e s p r i t e i i n v o l v e d i c o l l i s i o n w i t h a n o t h e r s p r i t e b o t h s p r i t e b i t s a r t u r n e d o i t h c o l l i s i o n r e g i s t e r . S o , i y o c a r e i c o l l i s i o n so c c u r , i w i l l b e n e c e s s a r y t c h e c k t h r e g i s t e r a f t e r e v e r y m o v e m e n to t h s p r i t e s y o a r c o n c e r n e d a b o u t . R e a d i n g t h r e g i s t e r w i l lc a u s e i t b c l e a r e d a u t o m a t i c a l l y . Y o c a n n o t p r e v e n t t h a t f r o mh a p p e n i n g , s i y o w a n t t h i n f o r m a t i o n f o f u t u r e r e f e r e n c e y o m u s t s t o r e i s o m e p l a c e w h e r e y o c a n g e t a i t

S p r i t e s c a a l s o c o l l i d e w i t h t h b a c k g r o u n d ( t e x t , e t c ) . L i k es p r i t e - s p r i t e c o l l i s i o n , s p r i t e - d a t a c o l l i s i o n s a r e k e p t i a r e g i s t e r( 5 3 2 7 9 $ D 0 1 F ) . E a c h s p r i t e h a i t o w b i ( 0 - 7 ) a n i n d i c a t e s t h a tt h a t s p r i t e h a s b e e n i n v o l v e d i c o l l i s i o n . T h i s r e g i s t e r i a l s o

Page 117: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 117/172

I n s i d e T h C o m m o d o r e 6 P t g t 1 1 - 1 *

c l e a r e d b y r e a d o f t h e r e g i s t e r ( L D A , L D X , L D i n s t r u c t i o n ) ) s s a v ei t i f y o d o n ' t w a n t t o l o s e i t

O n c e a g a i n , i t v e r y s t r o n g l y r e c o m m e n d e d y o s t u d y t h P R f o a l a r e a s o g r a p h i c p r o g r a m m i n g . T h i n s i g h t s w h i c h m a b g a i n e df r o m r e a d i n g a n u n d e r s t a n d i n g t h B A S I C p r o g r a m m e r ' s p e r s p e c t i v e o t h e s e s u b j e c t s w i l l g r e a t l y i n c r e a s e y o u r u n d e r s t a n d i n g a n d a b i l i t y t m o v e i n t o a s s e m b l y l a n g u a g e .

Page 118: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 118/172

I n s i d e T h C o m m o d o r e 6 P a g e 1 2 - i

T h 6 5 S o u n d s y n t h e s i z e rT h C o m m o d o r e 6 c o m e s e q u i p p e d w i t h a v e r y r e s p e c t a b l e s i n g l e -

c h i p s o u n d s y n t h e s i z e r . I h a t h r e e v o i c e s , e a c h w i t h i n d e p e n d e n ta t t a c k - d e c a y - s u s t a i n - r e l e a s e ( A S D R ) e n v e l o p e s * - f o u r K i n d s o f i l t e r s *

r e s o n a n c e c o n t r o l a n m a s t e r v o l u m e c o n t r o l . T h e p r o g r a m m e r c a m a k e t h c o m p u t e r g e n e r a t e w i d e v a r i e t y o f m u s i c a l a n o t h e r s o u n d s *s i m u l a t i n g v a r i o u s i n s t r u m e n t s s o l o a n i c o n c e r t . T h s o u n d o u t p u tm a b e p l a y e d t h r o u g h t h s p e a k e r o n y o u r T o r d i r e c t e d t o y o u rs t e r e o f o r h i g h - f i d e l i t y o u t p u t .

T h m u s i c a n a s s o c i a t e d w a v e s h a p e t h e o r y w h i c h i r e q u i r e d t a c c o m p l i s h t h e s e e n d s i c o n s i d e r a b l e . T h i s c h a p t e r w i l l p r e s e n t y o uw i t h t h e n e c e s s a r y t e c h n i c a l i n f o r m a t i o n o t h r e q u i r e m e n t s f o p r o g r a m m i n g t h s y n t h e s i z e r . I w i l l n o g d e e p l y i n t o t h e t h e o r yo s y n t h e s i z e d s o u n d . T h P R i a s o u r c e o m o r e d e t a i l e di n f o r m a t i o n o t h s u b j e c t .

R e g i s t e r A s s i g n m e n t

T h s y n t h e s i z e r c h i p i c a l l e d t h 6 5 8 1 o " S I D " ( s o u n di n t e r f a c e d e v i c e ) c h i p . T h c h i p s h o u l d b i n i t i a l i z e d b e f o r ea t t e m p t i n g a n y s o u n d g e n e r a t i o n . I h a a s e t o 2 r e g i s t e r s w h i c ha r d i r e c t l y a d d r e s s a b l e b y t h e 6 5 1 0 a n t h e r e f o r e a n p r o g r a m r u n n i n go i t I n i t i a l i z i n g m a b e a c c o m p l i s h e d b y s e t t i n g t h e r e g i s t e r s t z e r o :

S I D E Q U * D 4 8 8L D # $ 1 8L D #

L O O P S T S I D , XD E B P L O O P

T h r e g i s t e r s e i c o n t i g u o u s s t r i n g o b y t e s s t a r t i n g a $ D 4 0 0 ( 5 4 2 7 2 ) a n r u n n i n g t h r o u g h $ D 4 i C ( 5 4 2 3 0 ) . T h i s b l o c k o fr e g i s t e r s i s i n t h I / b l o c k a t $ D 0 0 0 - $ D F F F w h i c h a l s o c o n t a i n s t h V I C - I I c h i p a n w h i c h m a b s w i t c h e d w i t h t h c h a r a c t e r R O a e x p l a i n e d i t h p r e v i o u s c h a p t e r .

Page 119: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 119/172

I n s i d e T h C o m m o d o r e 6 P a g e 1 2 - 2

T o n e G e n e r a t i o n

T h S I c h i p c o n t a i n s t h r e e t o n e g e n e r a t o r s * t h e i r a s s o c i a t e de n v e l o p e g e n e r a t o r s a n d t h f i l t e r i n g a n v o l u m e c o n t r o l s . T h e r e a r s e v e n r e g i s t e r s f o e a c h o f t h e t h r e e v o i c e s . T h f i r s t v o i c e ' sr e g i s t e r s a r a $ D 4 0 0 - D 4 0 6 ( 5 4 2 7 2 - 5 4 2 7 8 ) . T h s e c o n d v o i c e i a $ D 4 0 7 - $ D 4 0 D ( 5 4 2 7 9 - 5 4 2 8 5 ) a n t h t h i r d v o i c e i a $ D 4 0 E - D 4 1 4 ( 5 4 2 8 6 -5 4 2 9 2 ) .

T h i n d i v i d u a l v o i c e s m a h a v e f r e q u e n c i e s r a n g i n g f r o m 0 3 8 9 4 h z T c a u s e a n y g i v e n f r e q u e n c y t b g e n e r a t e d * i i n e c e s s a r y t s t o r e a 1 6 - b i t n u m b e r i t h f i r s t t w r e g i s t e r s f o t h v o i c e d e s i r e d . T h v a l u e o f t h e n u m b e r t o s t o r e i 1 6 . 7 7 7 t i m e s t h f r e q u e n c y d e s i r e d . I A p p e n d i x o t h P R t h e r e i d e s c r i p t i o n o ft h d e s i g n c r i t e r i a f o a r o u t i n e t o s e l e c t a n o t h 1 s e m i - t o n e so a n o e i g h t o c t a v e s . T h f o l l o w i n g p r o g r a m s e g m e n t w i l la c c o m p l i s h t h o s e e n d s :

L O H N O T E SC C # D D # E F F # 6 G # A A # B

E Q E Q E Q B Y B Y B Y B Y B Y B Y B Y B Y B Y B Y B Y B Y

* D 4 6 8* D 4 0 1* C 8 8 03 4 3 3 43 6 3 7 63 8 5 3 94 8 8 3 84 3 2 5 84 5 8 3 04 8 5 5 65 1 4 4 35 4 5 0 25 7 7 4 36 1 1 7 66 4 8 1 4

V O I C E F R E Q L O F R E Q H

S E L C T E Q UR E M U S T H A V E N O T E I L O B I T S ( 0 - 1 1 )

O C T A V E I H I G H B I T S < 8 - 7 >

T A X S A V E F O O C T A V EA N # * 8 F J U S T T H N O T EA S N O T E

Page 120: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 120/172

Page 121: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 121/172

I n s i d e T h C o m m o d o r e 6 P t g t 1 2 - 4

P u l s e w i d t h m u s t b s p e c i f i e d i p u l s e w a v e f o r m i s e l e c t e d .T h p u l s e w i d t h i s e b s p e c i f y i n g t h p e r c e n t a g e o t i m e t h p u l s ei o v e r s u s t h t i m e i i s o f f . F i f t y p e r c e n t c r e a t e s a s q u a r e w a v e .0 a n 1 0 0 % c a u s e c o n s t a n t s i g n a l o u t p u t w h i c h i t h e r e f o r e n o t a a u d i o t o n e . T h w i d t h i s e a a 1 2 - b i t v a l u e w h i c h i r e l a t e d t p e r c e n t o n - t i m e b t h f o l l o w i n g f o r m u l a : W I D T H T I M E % 4 0 . 9 5 T h l o w - o r d e r e i g h t b i t s a r s e i t h t h i r d r e g i s t e r o f t h e v o i c e ' s s e t .T h h i g h - o r d e r b i t s o W I D T H a r s e i t h l o f o u r b i t s o t h f o u r t h r e g i s t e r .

W I D T H E Q P C T Q N * 4 0 . 9 5L D # W I D T H / 2 5 6S T M 0 I C E * 7 + S I D + 3L D H W I D T H & 2 5 5S T V Q I C E + 7 + S I D + 2

E a c h v o i c e h a p r o g r a m m a b l e e n v e l o p e g e n e r a t o r w h i c h a l l o w sy o t p r o g r a m t h v o l u m e o f t h e o u t p u t s i g n a l i s e v e r a l p h a s e s . T h a t t a c k p h a s e i w h e n t h n o t e b e g i n s a n d i n c r e a s e s i v o l u m e t i t m a x i m u m . T h e d e c a y p h a s e f o l l o w s t h r e a c h i n g o m a x i m u m v o l u m e a n c o n t i n u e s a t h v o l u m e d e c r e a s e s t i l l i r e a c h e s t h s u s t a i n p h a s e .H e r e t h n o t e m a i n t a i n s c o n s t a n t v o l u m e u n t i l t h r e l e a s e p h a s e ,w h e n t h v o l u m e d e c r e a s e s b a c k t z e r o . T h e n v e l o p e g e n e r a t o r a l l o w sy o t p r o g r a m t h e r a t e o v o l u m e i n c r e a s e i t h e a t t a c k p h a s e t t h r a t e o d e c r e a s e i t h d e c a y p h a s e * t h l e v e l a t w h i c h i s u s t a i n sa n t h r a t e o f f i n a l d e c r e a s e d u r i n g t h r e l e a s e p h a s e .

T h n o t e i s t a r t e d b y t u r n i n g o t h s t a r t b i t ( c a l l e d t h g a t e s i g n a l ) i b i t - 0 o f t h e f i f t h r e g i s t e r o f t h e v o i c e :

L D # O R M Q l C E * 7 + S I D + 4S T V 0 I C E * 7 + S I D + 4

T h a t t a c k r a t e i s e i t h s i x t h r e g i s t e r * t h h i g h - o r d e rf o u r b i t s ( 7 - 3 ) . T h v a l u e o t h e f o u r - b i t f i e l d c o r r e s p o n d s t t h t i m e i t a k e s f o t h t o n e t r e a c h m a x i m u m v o l u m e a i n d i c a t e d i t h f o l l o w i n g t a b l e .

T h d e c a y r a t e i s e i t h l o w - o r d e r f o u r b i t s o f t h e s a m er e g i s t e r a t h a t t a c k . T h c o r r e s p o n d i n g t a b l e v a l u e s ( i s e c o n d s )a r t h t i m e s f o r t h e v o l u m e t d e c r e a s e t t h s u s t a i n l e v e l .

Page 122: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 122/172

I n s i d e T h C o m m o d o r e 6 P t g t 1 2 - 5

T h s u s t a i n l e v e l i f o u r - b i t v a l u e i t h h i g h - o r d e r n y b b l eo f t h e s e v e n t h r e g i s t e r o f e a c h v o i c e . T h s u s t a i n v a l u e ( 0 - 1 5 )c o n t r o l s t h e r e l a t i v e v o l u m e o f t h e g e n e r a t e d t o n e a w h i c h d e c a ys t o p s a n d t h n o t e i h e l d u n t i l r e l e a s e d . T h v o l u m e a w h i c hs u s t a i n o c c u r s i s i n r a t i o t o t h e p e a k v o l u m e a t h s u s t a i n r e g i s t e ri t 1 5 N o t e t h a t t h p e a k v o l u m e i t h s a m e f o a l v o i c e s a n i u n d e r c o n t r o l o f t h e m a s t e r v o l u m e c o n t r o l . T h r e l e a s er a t e i s e i t h l o w - o r d e r n y b b l e o f t h e s e v e n t h r e g i s t e r . I s p e c i f i e s t h t i m e i w i l l t a k e t h n o t e t c o m p l e t e i t d e c a y o n c es u s t a i n h a b e e n t e r m i n a t e d .T h n o t e i t u r n e d o ( g a t e d ) b t h g a t e b i w h i c h i b i t - 0 ,t h l o w - o r d e r b i o t h e s i x t h r e g i s t e r . W h e n t h i s b i i t h n o t ew i l l c o m m e n c e . I w i l l g t h r o u g h t h a t t a c k , d e c a y a n s u s t a i n p h a s ea n h o l d t h e r e u n t i l t h b i i s e t 0

T h f o l l o w i n g t a b l e g i v e s t h e v a l u e o f t h e v a r i o u s f o u r - b i tr e g i s t e r s w h i c h c o n t r o l t h e n v e l o p e g e n e r a t o r s a n t h t i m e i s e c o n d s b e t w e e n c o m m e n c e m e n t a n c e s s a t i o n o e a c h p h a s e .

V A L U E A T T A C K D E C A Y / R E L V A L U E A T T A C K D E C A Y / R E L

. 8 8 2. 8 8 8. 0 1 6. 8 2 4. 8 3 8. 8 5 6. 8 6 8. 8

. 8 8 6. 8 2 4. 8 4 8. 8 7 2. 1 1 4. 1 6 8. 2 8 4. 2

1 1 1 1 1 1

. . 2 . .

1 . 3 . 5 . 8 .

. . 7

1 . 2 . 3 . 9 .

1 5 . 82 4 . 8

F i l t e r i n g

T h e r e a r e f o u r k i n d s o f s i g n a l f i l t e r i n g p l u s r e s o n a n c ec o n t r o l w h i c h m a b e m p l o y e d . I n d i v i d u a l v o i c e s m a b e i n d e p e n d e n t l yc o n n e c t e d a n d i s c o n n e c t e d t t h f i l t e r . T h f i l t e r h a a i i - b i tr e g i s t e r w h i c h i t h f r e q u e n c y c u t - o f f p o i n t a n r a n g e s f r o m 3 t 1 2 k h z . T h l o w - p a s s f i l t e r w i l l r e j e c t a l f r e q u e n c i e s a b o v e t h c u o f f r e q u e n c y . T h h i g h - p a s s w i l l r e j e c t a l f r e q u e n c i e s b e l o w t h c u t - o f f . T h b a n d p a s s f i l t e r w i l l a l l o w o n l y t h s e l e c t e d f r e q u e n c ya n t h n o t c h - r e j e c t w i l l p a s s a l f r e q u e n c i e s e x c e p t t h s p e c i f i e d

Page 123: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 123/172

I n s i d e T h C o m m o d o r e 6 P a g e 1 2 - 6

- f r e q u e n c y . F i n a l l y * t h r e s o n a n c e c o n t r o l h a r a n g e o - 1 v a l u e s( 0 - 1 5 ) w h i c h r e g u l a t e h o m u c h r e s o n a n c e w i l l b p r e s e n t o t h o u t p u ts i g n a l ( n r e s o n a n c e * 1 m a x i m u m r e s o n a n c e ) .

T h r e s o n a n c e c o n t r o l r e g i s t e r i i b i t s 4 - o - l o c a t i o n $ D 0 1 7( 5 4 2 9 6 ) . B i t s 0 - c o n t r o l w h i c h v o i c e s ( i - 3 p l u s e x t e r n a l i n p u t ) w i l lb r o u t e d t h r o u g h t h f i l t e r . B i t s 3 - o $ D 4 1 8 c o n t r o l s t h p e a kv o l u m e . B i t s 6 - c o n t r o l w h i c h f i l t e r e f f e c t i a c t i v e b i t 6h i g h - p a s s * b i 5 b a n d - p a s s * b i l o w - p a s s * b i t s 6 + n o t c hr e j e c t ) .

T h f o l l o w i n g r o u t i n e c o u l d b u s e d t s e l e c t t h f i l t e r i n g :

L D A S I D + 2 4A N t t * 8 FO R A # T Y P E < 1 6 = L 0 W , 6 4 = H I G H , 3 2 = B A N D , 8 0 = N O T C H - R E J )S T S I D + 2 4

T h f o l l o w i n g r o u t i n e m i g h t b u s e d t s e t h f i l t e r f r e q u e n c y :

F R E Q E Q U 5 6 7 A N V A L U E B E T W E E N A N 2 0 4 7L D # F R E Q / 8S T A S I D + 2 2L D A # F R E Q & 7S T S I D + 2 1

T h r e l a t i o n s h i p b e t w e e n F R E Q a n t h e a c t u a l f r e q u e n c y o f t h ef i l t e r i s s u p p o s e d l y l i n e a r f r o m 3 0 h z t 1 2 0 0 0 h z E x p e r i m e n t a t i o nh a n o b o r n t h i s o u t * h o w e v e r * a n y o a r e n c o u r a g e d t d y o u r o w t e s t i n g o t h f i l t e r c o n t r o l s .

M i x i n g

I i p o s s i b l e t m i a e x t e r n a l s i g n a l w i t h t h g e n e r a t e do u t p u t s i g n a l . O n o t h e p i n s o t h e a u d i o o u t p u t p o r t m a b u s e df o m i k e o r o t h e r i n s t r u m e n t s i g n a l i n p u t t o t h e 6 4 S e t h P R f o d e t a i l s .

m a c h i n e l a n g u a g e a p p r o a c h t p a d d l e a n j o y s t i c k p r o g r a m m i n gi p r e s e n t e d i t h P R a n s w w i l l n o a t t e m p t t d u p l i c a t e t h a ti n f o r m a t i o n h e r e .

Page 124: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 124/172

I n s i d e T h C o m m o d o r e 6 P a g e 1 3 - 1

I n t e r n a l sT h C o m m o d o r e 6 c o m e s w i t h 1 6 o R O i w h i c h t h e i n t e r n a l

o p e r a t i n g p r o g r a m s r e s i d e . T h e s e a r t h p r o g r a m s w h i c h i n t e r p r e tB A S I C p r o g r a m s a n w h i c h c o n t r o l t h e i n p u t a n o u t p u t d e v i c e s w h i c hc o m e w i t h t h 6 4 a n d t h o s e w h i c h c a n b e a d d e d . T h i s b l o c k o - m e m o r yi b r o k e n i n t o t w s e g m e n t s . T h - f i r s t * t h B A S I C i n t e r p r e t e r *e x t e n d s f r o m $ A 0 e e T $ B F F F . T h s e c o n d , c a l l e d t h " k e r n a l " , e x t e n d sf r o m $ E 0 0 0 t $ F F F F . S o m e o f t h e k e r n a l p r o g r a m s h a v e b e e n d o c u m e n t e db C o m m o d o r e i t h e i r P r o g r a m m e r ' s R e f e r e n c e G u i d e . T h e y d e a l m a i n l yw i t h i n p u t / o u t p u t ( I / O ) p r o c e s s i n g o t h 6 4 T h i s t e x t w i l l n o a t t e m p t t d u p l i c a t e t h i n f o r m a t i o n p r o v i d e d i t h P R G . I i o n c ea g a i n s t r o n g l y r e c o m m e n d e d t h a t y o o b t a i n c o p y o t h a t r e f e r e n c ew o r k .

T h e r e a r m a n y o t h e r s u b r o u t i n e s i n c l u d e d i t h 6 4 ' s R O w h i c ha r n o t c o v e r e d i t h P R G . W w i l l a t t e m p t t p r o v i d e i n f o r m a t i o n o u s i n g t h m o r e u s e f u l o t h o s e . W w i l l a l s o p r e s e n t l i s t o f t h ee n t r y p o i n t s o t h r e m a i n d e r . T h o s e w h i c h a r n o d i s c u s s e d i d e t a i l m a b d e c o d e d w i t h t h D e c o d e r f o y o u r i n s p e c t i o n a n u n d e r s t a n d i n g .

F l o a t i n g P o i n t n u m b e r s

A B A S I C p r o c e s s e s y o u r a r i t h m e t i c e x p r e s i o n s * i u s e sv a r i e t y o m a c h i n e l a n g u a g e s u b r o u t i n e s t d a d d i t i o n * s u b t r a c t i o n *e x p o n e n t i a t i o n , t r i g f u n c t i o n s * e t c . T h e s e s u b r o u t i n e s a r a v a i l a b l et t h m a c h i n e l a n g u a g e p r o g r a m f o a c c o m p l i s h i n g t h s a m e f u n c t i o n s .T h e y a r a l f a i r l y s i m i l i a r i t h c o n v e n t i o n s o t h e i r u s e * i . e . t h m e a n s o p a s s i n g p a r a m e t e r s * g e t t i n g t h r e s u l t s * e t c .

N u m b e r s i B A S I C m a b e x p r e s s e d a e i t h e r i n t e g e r s o a " f l o a t i n g p o i n t " n u m b e r s . I n t e g e r s h a v e n f r a c t i o n a l c o m p o n e n t .T h e y a r s i x t e e n b i s i g n e d n u m b e r s w h i c h m a h a v e t h r a n g e o 3 2 7 6 7 t 3 2 7 6 8 . N e g a t i v e n u m b e r s a r e x p r e s s e d i t w o ' s c o m p l e m e n tn o t a t i o n a s d i s c u s s e d i c h a p t e r f o u r .

B A S I C d o e s a l i t c o m p u t a t i o n s i f l o a t i n g p o i n t m o d e .F l o a t i n g p o i n t n u m b e r s h a v e f r a c t i o n a l c o m p o n e n t s . T h e y a r c o m p o s e do t h r e e p o r t i o n s * t h e x p o n e n t * t h m a n t i s s a a n t h s i g n . T h e x p o n e n t o c c u p i e s o n b y t e a n i t b i n a r y v a l u e i 1 2 g r e a t e r t h a nt h e x p o n e n t b e i n g e x p r e s s e d . T h v a l u e o t h e x p r e s s e d e x p o n e n t i t h n u m b e r o b i t s w h i c h t h m a n t i s s a n e e d s t b s h i f t e d . S i n c e t h

Page 125: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 125/172

Page 126: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 126/172

I n s i d e T h C o m m o d o r e 6 P a g e 1 3 - 3

t h l e f t o f t h e b i n a r y n u m b e r t h r e e p l a c e s t o t h e r i g h t .

O t h e r e x a m p l e s :

T h e n u m b e r ( 8 0 8 8 8 8 8 1 )

1 8 8 8 8 8 6 1 1 8 8 8 8 6 6 8 6 6 8 8 6 8 8 6 6 8 6 6 6 6 6 6 6 6 6 8 6 6 6 61 2 ? 1 2 8 6

$ 8 $ 8 6 $ 8 8 $ 8 6 $ 8

e x p o n e n t m a n t i s s a

T h e n u m b e r < 8 8 8 8 6 8 1 8 )

1 8 6 6 8 6 1 6 1 8 8 8 8 6 6 6 8 6 6 6 8 6 8 6 6 6 8 6 6 6 6 6 6 6 6 6 6 6 8 61 2 1 2 8 6

$ 8 $ 8 6 $ 8 6 $ 6 6 $ 6 8

e x p o n e n t m a n t i s s a

T h e n u m b e r < 8 8 6 8 8 8 1 1 )

1 6 6 6 6 6 1 6 1 1 6 6 6 6 8 6 6 6 8 6 6 6 6 6 6 6 6 6 8 6 6 6 6 6 6 6 6 6 6 61 2 1 9 8 8

$ 8 $ C 6 $ 6 6 $ 6 6 $ 6 6

e x p o n e n t m a n t i s s a

T h e n u m b e r 6 ( 8 1 6 6 6 8 8 1 )

1 8 6 6 6 1 1 1 1 6 6 6 6 6 1 6 6 6 6 6 6 6 6 8 8 6 6 6 8 6 6 8 6 6 6 6 6 6 8 81 3 1 3

$ 8 7 $ 8 2 $ 6 6 $ 8 6 $ 6 6

e x p o n e n t m a n t i s s a

Page 127: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 127/172

I n s i d e T h C o m m o d o r e 6 4 P a g e 1 3 - 4

T h e n u m b e r 1 ( 8 8 8 8 1 1 1 1 )

1 8 8 8 8 1 8 8 1 1 1 1 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 81 3 2 4 8 $ 8 $ F $ 8 $ 8 8 $ 8 8

e x p o n e n t m a n t i s s a

T h s i g n o t h n u m b e r i c a r r i e d i t h h i g h - o r d e r b i o t h b y t e f o l l o w i n g t h e m a n t i s s a . I t h e s i g n b i i o n t h n u m b e r i n e g a t i v e . I o f i i p o s i t i v e .

T h e r e a r t w f l o a t i n g p o i n t a c c u m u l a t o r s m a i n t a i n e d b B A S I C *F A C i a n F A C 2 . F A C i i l o c a t e d a $ 6 1 - $ 6 6 < 9 7 - 1 0 3 ) a n F A C 2 i a $ 6 9 - $ 6 E ( 1 8 5 - 1 1 1 ) . T h e s e t w a c c u m u l a t o r s a r u s e d f o a l m a t h e m a t i c a l o p e r a t i o n s . F o l l o w i n g t h F A C s , a $ 6 ( i l l ) , i s i g nc o m p a r i s o n f l a g . T h h i g h - o r d e r b i t , i o n s i g n i f i e s t h t w F A C sa r o f d i f f e r i n g s i g n s .

A r i t h m e t i c r o u t i n e s

T h f o l l o w i n g r o u t i n e s p e r f o r m m a t h e m a t i c a l o p e r a t i o n s u s i n gF A C i , F A C 2 , a n v a l u e s s t o r e d i o t h e r m e m o r y l o c a t i o n s . E a c h r o u t i n em a b e x e c u t e d b J S i n s t r u c t i o n t o t h i n d i c a t e d e n t r y p o i n t .R e f e r e n c e s t m e m o r y l o c a t i o n s a r e f r e q u e n t l y c o m m u n i c a t e d t v a r i o u sr o u t i n e s b y a n a d d r e s s c o n t a i n e d i t h A - r e g ( L S B ) a n t h Y - r e g( M S B ) . W w i l l r e f e r t t h i s f o r m a t a s f o r m a t - 1 .

M o s t o t h e f o l l o w i n g r o u t i n e s u s t h A - r e g , X - r e g a n d Y - r e gf o c o m m u n i c a t i o n . I i a i n t e r e s t i n g f a c t t h a t w h e n S Y i d o n ef r o m B A S I C * t h e s e t h r e e r e g i s t e r s a r e l o a d e d f r o m m e m o r y l o c a t i o n s7 8 0 , 7 8 a n 7 8 r e s p e c t i v e l y . A d d i t i o n a l l y , t h e P r o c e s s o r S t a t u sr e g i s t e r i p a s s e d i 7 8 3 . A l o t h r e g i s t e r s a r s t o r e d b a c k i t h e s e s a m e l o c a t i o n s u p o n r e t u r n i n g t B A S I C s i i t h e r e f o r ep o s s i b l e t e a s i l y p a s s i n f o r m a t i o n b a c k a n f o r t h b e t w e e n B A S I C a n m a c h i n e l a n g u a g e p r o g r a m s . Y o c a c a l l t h e f o l l o w i n g r o u t i n e s a n t h o s e i t h K e r n a l f r o m B A S I C b S Y S i n g t t h e m a f t e r s e t t i n g u t h t h r e e r e g i s t e r s t o r a g e b y t e s .

Page 128: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 128/172

I m i d t T h C o m m o d o r t 6 P a g e 1 3 - 5

I n t t g t r t o F A C i I B 3 9 1 ( 4 5 9 6 9 )t w o - b y t e i n t e g e r v a l u e i f o r m a t - i i c o n v e r t e d t f l o a t i n g

p o i n t n u m b e r s t o r e d i F A C i .

F A C i t o I n t t g t r I B i A A ( 4 5 4 8 2 )T h F A C i i c o n v e r t e d t t w o - b y t e i n t e g e r w h i c h i s a v e d i n t o

l o c a t i o n s $ 6 4 , $ 6 5 ( 1 6 0 , 1 6 1 ) . T h F A C i i d e s t r o y e d .

M e m o r y t F A C I * B B A 2 ( 4 8 0 3 4 )f i v e - b y t e f l o a t i n g p o i n t n u m b e r a n y w h e r e i m e m o r y i l o a d e d

i n t o F A C i . T h a d d r e s s o t h s t a r t i n g m e m o r y l o c a t i o n i s i n f o r m a t -1 T h s i g n f l a g o F A C i i s e o i t h h i g h - o r d e r b i o f t h em a n t i s s a i o n e , e l s e i i s e o f f . T h e x p o n e n t i r e t u r n e d i t h A - r e g .

A S C I I t F A C I * B 7 B 5 ( 4 7 0 2 9 )A A S C I I s t r i n g i c o n v e r t e d t f l o a t i n g p o i n t f o r m a t a n s a v e d

i t h F A C i . T h s t r i n g m a b a n y w h e r e i m e m o r y a n t h a d d r e s s o t h s t a r t i n g l o c a t i o n m u s t b p o i n t e d t b t h u t i l i t y s t r i n g p o i n t e ra $ 2 2 , $ 2 3 ( 3 4 , 3 5 ) . T h l e n g t h o t h s t r i n g m u s t b l o a d e d i n t o t h A - r e g .

F A C I t A S C I I $ B D D D ( 4 8 6 0 5 )T h A S C I I r e p r e s e n t a t i o n o f t h e v a l u e i F A C I w i l l b s a v e d

s t a r t i n g a t $ 0 1 0 0 ( 2 5 6 ) a n c o n t i n u i n g u n t i l $ 0 i e n c o u n t e r e d .

M e m o r y t F A C 2 $ B A 8 C ( 4 7 7 5 6 )S a m e a a b o v e e x c e p t u s i n g F A C 2 a n t h e s i g n c o m p a r i s o n f l a g i

s e t . T h e x p o n e n t o F A C I i r e t u r n e d i t h A - r e g .

F A C I t M e m o r y $ B B D 7 ( 4 8 0 8 7 )T h F A C I i s t o r e d i n t o a n f i v e b y t e m e m o r y l o c a t i o n . T h M S

o f t h e a d d r e s s o f t h e s t a r t o f t h m e m o r y l o c a t i o n i p a s s e d i t h X r e g . T h L S i s i n t h Y - r e g . T h h i g h - o r d e r b i o t h m a n t i s s af i e l d i s f o r c e d t o t h F A C I s i g n f l a g .

F A C 2 t F A C I $ B B F C ( 4 8 1 2 4 )s i m p l e m o v e i p e r f o r m e d f r o m F A C 2 t F A C i . F A C 2 i n o

a f f e c t e d .

Page 129: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 129/172

I n s i d e T h C o m m o d o r e 6 4 P t g t 1 3 - 6

F A C i t o F A C 2 I B C 8 F ( 4 8 1 4 3 )s i m p l e m o v e i p e r f o r m e d f r o m F A C l t F A C 2 . F A C l i n o

a f f e c t e d .

L o g i c a l A N o F A C l a n F A C 2 * A F B 9 ( 4 5 6 3 3 )F A C l a n F A C 2 a r l o g i c a l l y A N D e d t o g e t h e r * t h r e s u l t e n d i n g

u i F A C l

L o g i c a l O o F A C l a n F A C 2 * A F B 6 ( 4 5 6 3 9 )F A C l a n F A C 2 a r l o g i c a l l y O R e d t o g e t h e r * t h r e s u l t e n d i n g u

i F A C i

F A C l F A C i F A C 2 $ B 8 5 3 ( 4 7 1 8 7 )F A C 2 i s u b t r a c t e d f r o m F A C i , t h r e s u l t r e p l a c i n g F A C i . F A C 2

i n o a f f e c t e d .

F A C l F A C l F A C 2 * B 8 6 A ( 4 7 2 1 8 )F A C l i r e p l a c e d b t h s u o F A C l a n F A C 2 . I i n e c e s s a r y

t s e t t h e s i g n c o m p a r e f l a g p r i o r t o c a l l i n g t h i s r o u t i n e . T h i s i d o n e b O i n l o c a t i o n s $ 6 a n % 6 ( 1 6 2 a n 1 1 6 ) a n s t o r i n g t h er e s u l t i $ 6 F . I i a l s o n e c e s s a r y t l o a d t h A - r e g w i t h t h e v a l u ef o u n d i $ 6 ( 9 7 ) . N o t e t h a t b o t h o t h e s e f u n c t i o n s a r d o n e b t h M e t F A C 2 r o u t i n e .

F A C l F A C i F A C 2 * B A 3 6 ( 4 7 6 6 4 )F A C l i r e p l a c e d b t h p r o d u c t o F A C l A N F A C 2 . T h e s a m e

n o t e s a p p l y a f o r t h e a b o v e r o u t i n e . A a l t e r n a t e e n t r y p o i n t f o t h i s r o u t i n e i $ B A 2 8 ( 4 7 6 5 6 ) . T h i s e n t r y p o i n t w i l l e x e c u t e t h m e m o r y t F A C 2 r o u t i n e b e f o r e d o i n g t h m u l t i p l i c a t i o n .

F A C l L O F A C l ) $ B 9 E A ( 4 7 9 5 4 )F A C l i r e p l a c e d b t h L O o F A C l .

F A C i F A C 2 F A C l * B B 1 2 ( 4 7 8 9 6 )F A C i i r e p l a c e d b t h q o u t i e n t o F A C 2 a n F A C i . T h s a m e

n o t e s a p p l y a f o r a d d i t i o n . H o w e v e r b J S R i n g t $ B B 8 F ( 4 7 8 8 7 *i n s t e a d * t h e l o a d i n g o f t h e F A C 2 f r o m m e m o r y w i l l b e a c c o m p l i s h e dp r i o r t d o i n g t h e d i v i s i o n .

Page 130: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 130/172

I n s i d t T h C o m m o d o r t 6 4 P a g e 1 3 - 7

F A C I F A C 2 F A C I $ B F 7 B ( 4 9 6 1 3 )F A C I i r e p l a c e d w i t h F A C 2 r a i s e d t o t h e p o w e r o F A C i . S a m e

c o m m e n t s a f o r a d d i t i o n . B u s i n g t h $ B F 7 8 ( 4 9 0 1 6 ) e n t r y p o i n t , t h r o u t i n e t o l o a d F A C I f r o m m e m o r y m a y b e x e c u t e d p r i o r t o t h ee x p o n e n t i a t i o n r o u t i n e . T h M e m p r y t F A C i r o u t i n e d o e s n o t p r o p e r l ys e t h s i g n c o m p a r e f l a g h o w e v e r . A l s o n o t e t h a t w h e n u s i n g t h e s ea l t e r n a t e e n t r y p o i n t s * t h s a m e s e t u p o f t h e A - r e g a n Y - r e g m u s t b p e r f o r m e d a p e M e m - t o - F A C r o u t i n e s b e f o r e c a l l i n g t h d e s i r e da r i t h m e t i c r o u t i n e .F A C I F A C I 1 * B A F B ( 4 7 8 7 0 )

F A C i i r e p l a c e d b F A C I 1 0

C o m p a r e F A C I a n M e m o r y $ B C 5 B ( 4 8 2 1 9 )T h e A - r e g i s e t d e p e n d i n g o t h r e s u l t o f t h e c o m p a r e b e t w e e n

F A C i a n s o m e f l o a t i n g p o i n t n u m b e r i s p e c i f i e d m e m o r y l o c a t i o n .I t h e y a r e q u a l , t h r e s u l t i 0 i t h e y a r n o t e q u a l t h r e s u l ti $ F ( 2 5 5 ) . T h a d d r e s s o f t h e s t a r t o t h m e m o r y l o c a t i o n i i f o r m a t - i .

F A C I A B F A C I ) I B C 5 8 ( 4 8 2 1 6 )T h F A C i i r e p l a c e d b t h a b s o l u t e v a l u e o f F A C I .

F A C I I N F A C I ) $ B C C C ( 4 8 3 3 2 )T h F A C i i r e p l a c e d b y t h e i n t e g e r p o r t i o n o F A C i .

F A C I S G F A C I ) I B C 3 9 ( 4 8 1 8 5 )T h F A C i i r e p l a c e d b t h e v a l u e i f i t w a z e r o * b i i w a g r e a t e r t h a n z e r o a n b - i i w a l e s s t h a n z e r o .

F A C I S Q F A C I ) I B F 7 1 ( 4 9 0 6 9 )T h F A C i i r e p l a c e d b t h s q u a r e r o o t o F A C i .

F A C I E X P ( F A C I ) * B F B D ( 4 9 1 3 3 )T h F A C i i r e p l a c e d b t h v a l u e c o m p u t e d b r a i s i n g e o

n a t u r a l l o g a r i t h m t o t h e p o w e r o F A C I .

F A C I C O F A C I ) $ B 2 6 4 ( 5 7 9 5 6 )T h F A C I i r e p l a c e d b t h C o s i n e o F A C I e x p r e s s e d i r a d i a n s .

Page 131: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 131/172

I n t i d t T h C o m m o d o r e 6 P * g t 1 3 - 8

F A C i S I F A C I ) $ B 2 6 B ( 5 7 9 6 3 )T h F A C l i r e p l a c e d b t h S i n e o F A C i e x p r e s s e d i r a d i a n s .

F A C l T A F A C l ) I E 2 B 7 ( 5 8 0 3 9 )T h F A C l i r e p l a c e d b t h t a n g e n t o F A C i e x p r e s s e d i r a d i a n s .

F A C I A T F A C I ) $ B 3 e D ( 5 8 1 2 5 )T h F A C i i r e p l a c e d b t h a r c t a n g e n t o F A C i e x p r e s s e d i

r a d i a n s .

I n p u t / O u t p u t r o u t i n e s

M o s t o t h I / r o u t i n e s a r e p r e s e n t e d i t h P R b u t h e r e a r et w m o r e p r e s e n t e d h e r e w h i c h d n o a p p e a r t h e r e .

I n p u t i n t o B A S I C b u f f e r $ A 5 6 6 ( 4 2 3 3 6 )T h 8 8 b y t e B A S I C i n p u t b u f f e r s t a r t i n g a $ 0 2 0 0 ( 5 1 2 ) i s

f i l l e d w i t h c h a r a c t e r s f r o m t h K e y b o a r d . C R e t u r n 3 t e r m i n a t e s t h i n p u t a n $ 0 s i g n i f i e s t h e n o t h m e s s a g e i t h b u f f e r .

O u t p u t s t r i n g t s c r e e n $ A B 1 B ( 4 3 8 0 6 )T h s t a r t i n g a d d r e s s o s t r i n g o A S C I I c h a r a c t e r s t b

p r i n t e d o t h s c r e e n i s e i f o r m a t - i . T h s t r i n g m u s t b t e r m i n a t e d b $ 0 0 .

Page 132: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 132/172

I n i i d t T h C o m m o d o r t 6 P a g e A -

A p p e n d i x

M o d e 3 4 9 1 8 1 1 1 2 1 3A D A N A S B C B C B E B I B M B N B P B R B V B V C L C L C L C L C M C P C P D E D E D E E O I N 1 N I N J M J S L D L D L D L S N O

Page 133: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 133/172

I n s i d e T h C o m m o d o r e 6 P a g e A -

M o d e 6 8 1 1 1 2 1 3

O R P H P H P L P L R O R O R T R T S B S E S E S E S T S T S T T A T A T S T X T X T Y

M o d e s :

2

4

X

A c c u m u l a t o rI m m e d i a t eZ e r o p a g eZ e r o p a g e ,Z e r o p a g e , YA b s o l u t e

1 1 1 1

X

X

A b s o l u t e , XA b s o l u t e , YI m p l i e dR e l a t i v e( I n d i r e c t ,( I n d i r e c t )( I n d i r e c t )

X

X

X

Page 134: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 134/172

I n s i d e T h C o m m o d o r e 6 P a g e B - i

A p p e n d i xD E C I M A L H E X A S C I I S C R E E N B A S I C 6 5 8 2 D E C I N A L B I N A R Y H E X

1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 I 1 I I I

c a p p e t

c u d o w np e v e p s ec u p h o n ed e l e t e

c u r i g h t

e n d - l i n e B R K0 R A U , X >

O R A S

P H O R A S

O R A S

B P O R A ( 1 ) , Y

O R A Z , XA S Z ,

C L O R A Y

O R A XA S L X

1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3

0 0 0 00 0 0 00 0 0 00 0 0 00 0 0 00 0 0 00 0 0 00 0 0 00 0 0 00 0 0 00 0 0 00 0 0 00 0 0 00 0 0 00 0 0 00 0 0 00 0 0 10 0 0 10 0 0 10 0 0 10 0 0 10 0 0 10 0 0 10 0 0 10 0 0 10 0 0 10 0 0 10 0 0 10 0 0 10 0 0 10 0 0 10 0 0 1

0 0 8 88 8 0 10 0 1 00 0 1 10 1 0 00 1 0 10 1 1 00 1 1 11 0 0 01 0 0 11 0 1 01 0 1 11 1 0 01 1 0 11 1 1 01 1 1 10 0 0 00 0 0 10 0 1 00 0 1 10 1 0 00 1 0 10 1 1 00 1 1 11 0 0 01 0 0 11 0 1 01 0 1 11 1 0 01 1 0 11 1 1 01 1 1 1

0 0 0 0 0 0 0 0 0 0 8 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 I 1 I I I

Page 135: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 135/172

I n s i d e T h C o m m o d o r e 6 P a g e B -

D E C I M A L H E X A S C I I S C R E E N B A S I C 6 5 0 2 D E C I M A L B I W R Y H E

3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 6 6 6 6

2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3

s p a c e

f

7

s p a c e

f

V

s p a c e

f

'

J S A N D U , X )

B I # R O

P L A N R O

B I A N R O

B M # M ! ) , Y

m \ 2 f R O L 2 , X

S E M D C L

A N D XR O L X

3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 6 6 6 6

e e i ee e i ee e i ee e i ee e i ee e i ee e i ee e i ee e i ee e i ee e i ee e i ee e i ee e i ee e i ee e i ee e i ie e e e e e e e e e e e e e e e e e e e e e e e e e e e e e

e e e ee e e ie e i ee e e i e ee i e ie n 8 1 1 1l e e el e e i1 8 1 81 0 1 1n e 1 1 0 1m m e e e ee e e ie e i ee e e i e ee i e ie n 8 1 1 1l e e el e e i1 8 1 61 8 1 1n e 1 1 8 11 1 1 8n

2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3

Page 136: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 136/172

I n s i d e T h C o m m o d o r e 6 P a g e B -

D E C I M A L H E X A S C I I S C R E E N B A S I C 6 5 9 2 D E C I M L B I N A R Y H E X

6 6 6 6 6 6 7 7 1 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 8 8 9 9 9 9 9 9

4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5

(

e

I

a f f

C

R T E O R ( I , X )

E O R ZL S R Z

E O L S R A

J N E O L S

e v E O R ( I ) , Y

E O R 2 , XL S R ' Z , X

C L E O R Y

E O R XL S R X

6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 8 8 9 9 9 9 9 9

8 1 8 88 1 8 88 1 8 88 1 8 88 1 8 88 1 8 88 1 8 88 1 8 88 1 8 88 1 8 88 1 8 88 1 8 88 1 8 88 1 8 88 1 8 88 1 8 88 1 8 18 1 8 18 1 8 18 1 8 18 1 8 18 1 8 18 1 8 18 1 8 18 1 8 18 1 8 18 1 8 18 1 8 18 1 8 18 1 8 18 1 8 18 1 8 1

8 8 8 88 8 8 18 8 1 88 8 1 18 1 8 88 1 8 18 1 1 88 1 1 11 8 8 81 8 8 11 8 1 81 8 1 11 1 9 81 1 8 11 1 1 81 1 1 18 8 9 99 8 8 18 8 1 88 8 1 18 1 8 88 1 8 18 1 1 88 1 1 11 8 8 81 8 8 11 8 1 81 8 1 11 1 8 81 1 8 11 1 1 81 1 1 1

4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5

Page 137: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 137/172

I n s i f r T h t C o m m o d a r t 4 P » g t B - 4

D E C I M A L H E A S C I I S C R E E N B A S I C 4 5 8 2 D E C 1 M L B I N A R Y H E

E E

9 9 9 9

1 0 1 8 1 8 1 8 1 8 1 8 1 8 1 8 1 8 1 8 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2

6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 I 7 7 7 7 7 7 7 7 7

R T A D C ( I , X )

A D R C R 2

P L A D R C R A

J M P U )A D R O

B U A D C ( I ) , Y

A D 2 , R O R 2 , X

S E A D C Y

A D C XR O R X

9 9 9 9

1 8 1 8 1 8 1 8 1 8 1 8 1 8 1 8 1 8 1 8 1 1 H 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2

8 1 1 88 1 1 88 1 1 88 1 1 88 1 1 88 1 1 88 1 1 88 1 1 88 1 1 88 1 1 88 1 1 88 1 1 88 1 1 88 1 1 88 1 1 88 1 1 88 1 1 18 1 1 18 1 1 18 1 1 18 1 1 18 1 1 18 1 1 18 1 1 18 1 1 18 1 1 18 1 1 18 1 1 18 1 1 18 1 1 18 1 1 18 1 1 1

8 8 8 88 8 8 18 8 1 88 8 1 18 1 8 88 1 8 18 1 1 88 1 1 11 8 8 81 8 8 11 8 1 81 8 1 11 1 8 81 1 8 11 1 1 81 1 1 18 8 8 88 8 8 18 8 1 88 8 1 18 1 8 88 1 8 18 1 1 88 1 1 11 8 8 81 8 8 11 8 1 81 8 1 11 1 8 81 1 8 11 1 1 81 1 1 1

6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7

Page 138: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 138/172

I n s i d e T h C o m m o d o r e 6 P * g t B -

D E C I r t i L H E X A S C I I S C R E E N B A S I C 6 5 8 2 D E C I M A L B I M R Y H E

1 2 1 2 1 3 1 3 1 3 1 3 1 3 1 3

1 3 1 3 1 3 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5

8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 9 9 c u u 9 2 r v s o 9 d e a r9 i n s e r t9 9 9 9 9 9 9 9 9 D c u r ) t i \9 9

r - O E N Dr - A F O Rp - B N E X Tr - D A T Ap - D I N P U Tp - E I N P U Tp - F D I Mp - G R E A Dp - H L E Tp - G O T Or - J R U Np - I p - L R E S T O R Er - f f 6 0 S U Bp - N R E T U R Np - 0 R E Mp - P S T O Pp - O p - W A I Tp - L O A Dp - S A V Er - \ i V E R I Rp - D E p - W P O K Ep - P R I N Tp - Y P R I N Tp - C O N Tr - L I S Tp - \ C L Rr - C M r - S Y r - % - O P E N

S T A < I , X )

S T S T A 2S T

D E

T X

S T S T S T

B C S T A ( I ) , Y

S T Y Z , XS T A Z , XS T X Z , Y

T Y S T A YT X

S T A X

1 2 1 2 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5

1 8 8 81 8 8 81 8 8 81 8 8 81 8 8 81 8 8 81 8 8 81 8 8 81 8 8 81 8 8 81 8 8 81 8 8 81 8 8 81 8 8 81 8 8 81 8 8 81 8 8 11 8 8 11 8 8 11 8 8 11 8 8 11 8 8 11 8 8 11 8 8 11 8 8 11 8 8 11 8 8 11 8 8 11 8 8 11 8 8 11 8 8 11 8 8 1

8 8 8 88 8 8 18 8 1 88 8 1 18 1 8 88 1 8 18 1 1 88 1 1 11 8 8 81 8 8 11 8 1 81 8 1 11 1 8 81 1 8 11 1 1 81 1 1 18 8 8 88 8 8 18 8 1 88 8 1 18 1 8 88 1 8 18 1 1 88 1 1 11 8 8 81 8 8 11 8 1 81 8 1 11 1 8 81 1 8 11 1 1 81 1 1 1

8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9

Page 139: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 139/172

I n i i d t T h C o m m o d o r t 6 P a g t B -

D E C I M A L H E X A S C I I

1 6 1 6 1 6 1 6 1 6 1 6 1 6 1 6 1 6 1 6 1 7 1 7 1 7 1 7 1 7 1 7 1 7 1 7 1 7 1 7 1 8 1 8 1 8 1 8 1 8 1 8 1 8 1 8 1 8 1 8 1 ? ! ?

A A A A A A A A A A

A A A A A B B B B B B B B B B B B B B B B

p - p - p - p - p - ' / .p - r - p - p - p - p - r -

p - r - p - r - p - p - p - p - r - p - p - p - p - p - r p - p P -

B A S I C

C L O S E6 E N E T A 6 <T F S P C <T H E NN O S T E P

A N O

S G I N A B H S F R P O S Q R N L 0 E X C O S I

6 5 8 2

L D L D A < I , X )L D

L D L D L D

T A L D f T A

L D L D L D

B C L D A < I ) , Y

L D Y 2 , XL D 2 , L D X 2 , Y

C L L D T S

L D Y XL D A XL D X Y

D E C I M A L

1 6 1 6 1 6 1 6 1 6 1 6 1 6 1 6 1 6 1 6 1 7 1 7 1 7 1 7 1 7 1 7 1 7 1 7 1 7 1 7 1 8 1 8 1 8 1 8 1 8 1 8 1 8 1 8 1 8 1 8 1 9 1 ?

B I f t i R Y

1 8 1 8 8 8 8 81 8 1 8 8 8 8 11 8 1 8 8 8 1 81 8 1 8 8 8 1 11 8 1 8 8 1 8 81 8 1 8 8 1 8 11 8 1 8 8 1 1 81 8 1 8 8 1 1 11 8 1 8 1 8 8 81 8 1 8 1 8 8 11 8 1 8 1 8 1 81 8 1 8 1 8 1 11 8 1 8 1 1 8 81 8 1 8 1 1 8 11 8 1 8 1 1 1 81 8 1 8 1 1 1 11 8 1 1 8 8 8 81 8 1 1 8 8 8 11 8 1 1 8 8 1 81 8 1 1 8 8 1 11 8 1 1 8 1 8 81 8 1 1 8 1 8 11 8 1 1 8 1 1 81 8 1 1 8 1 1 11 8 1 1 1 8 8 81 8 1 1 1 8 8 11 8 1 1 1 8 1 81 8 1 1 1 8 1 11 8 1 1 1 1 8 81 8 1 1 1 1 8 11 8 1 1 1 1 1 81 8 1 1 1 1 1 1

H E

A A A A A A A A A A A A A A A A B B B B B B B B B B B B B B B B

Page 140: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 140/172

I n s i d e T h C o m m o d o r e 6 4 P a g e B -

D E C I M L H E X A S C I I S C R E E N B A S I C 6 5 8 2 D E C I M L B I N A R Y H E X

T A N C P Y 1 9 2 1 1 8 8 8 8 8 8 C A T C H P ( I f X ) 1 9 3 1 1 8 8 8 8 8 1 C P E E K 1 9 4 1 1 8 8 8 8 1 8 C 2L E 1 9 5 1 1 8 8 8 8 1 1 C S T R * C P Y 1 9 6 1 1 8 8 8 1 8 8 C 4M C M 1 9 1 1 8 8 8 1 8 1 C A S D E 1 9 8 1 1 8 8 8 1 1 8 C 6C H R $ 1 9 1 1 8 8 8 1 1 1 C L E F T ! I N Y 2 8 8 1 1 8 8 1 8 8 8 C R I G H T S C M P f 2 8 1 1 8 8 1 8 8 1 C M I D * D E 2 8 1 1 8 8 1 8 1 8 C

2 8 3 1 1 8 8 1 8 1 1 C C Y 2 8 4 1 1 8 8 1 1 8 8 C C M 2 8 1 1 8 8 1 1 8 1 C D E C 2 8 6 1 1 8 8 1 1 1 8 C

2 8 1 1 8 8 1 1 1 1 C B N 2 8 1 1 8 1 8 8 8 8 D C M P U ) , Y 2 8 1 1 8 1 8 8 8 1 D

2 1 1 1 8 1 8 8 1 8 D 22 1 1 1 1 8 1 8 8 1 1 D 2 1 1 1 8 1 8 1 8 8 D

C M P Z . X 2 1 3 1 1 8 1 8 1 8 1 D D E C Z , X 2 1 4 1 1 8 1 8 1 1 8 l >

2 1 1 1 8 1 8 1 1 1 D C L D 2 1 6 1 1 8 1 1 8 8 8 D 8C M P Y 2 1 7 1 1 8 1 1 8 8 1 D

2 1 1 1 8 1 1 8 1 8 D 2 1 1 1 8 1 1 8 1 1 D 2 2 1 1 8 1 1 1 8 8 D C2 2 1 1 1 8 1 1 1 8 1 D

D E C X 2 2 2 1 1 8 1 1 1 1 8 D E2 2 1 1 8 1 1 1 1 1 D

1 9 1 9 1 9 1 9 1 9 1 9 1 9 1 9 2 8 2 8 2 8 2 8 2 8 2 8 2 8 2 8 2 8 2 8 2 1 2 1 2 1 2 1 2 1 2 3 2 1 2 1 2 1 2 1 2 2 2 2 2 2 2 2

C C C C C C C C C C C C C C C C D D D D D D D D D D D D D D D D

Page 141: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 141/172

I n s i d e T h C o m m o d o r e 6 P a g e B -

D E C I M L H E A S C H S C R E B 4 B A S I C 6 5 6 2 D E C I M A L B I N A R Y H E X

C P « 2 2 4 1 1 1 8 8 8 8 0 E s b u , x ) 2 2 m e e e i e

2 2 m e e i e E 22 2 m e e E

c p 2 2 m e i e e E 4s b 2 2 m e i e i e I N 2 3 m 8 1 1 6 E 6

2 3 m e e i n 2 3 m l e e e E s b 2 3 m l e e i E N O 2 3 1 1 1 6 1 8 1 0 E

2 3 m 1 8 1 1 E C P X 2 3 6 m 1 1 0 0 E S B C 2 3 7 m 1 1 8 1 E i n 2 3 m m e

2 3 m m e B E 2 4 1 1 1 1 8 0 0 0 F S B < I ) , Y 2 4 1 1 1 1 1 8 6 8 1 F

2 4 m e e i e F 22 4 1 1 1 1 8 8 1 1 F 2 4 1 1 1 1 8 1 8 8 F

S B C Z , X 2 4 1 1 1 1 8 1 8 1 F I N Z f 2 4 1 1 1 1 8 1 1 8 F 6

2 4 1 1 1 1 8 1 1 1 F S E D 2 4 8 1 1 1 1 1 8 6 6 F S B C Y 2 4 9 1 1 1 1 1 8 8 1 F

2 5 1 1 1 1 1 8 1 8 F 2 5 1 1 1 1 1 8 1 1 F 2 5 1 1 1 1 1 1 8 8 F

S B C X 2 5 1 1 1 1 1 1 8 1 F I N C X 2 5 1 1 1 1 1 1 1 8 F E

2 5 1 1 1 1 1 1 1 1 F

2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 5 2 5 2 5 2 5 2 5 2 5

E E E E E E E E E E E E E E E E F F F F F F F F F F F F F F F F

Page 142: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 142/172

I n s i d e T h C o m m o d o r e 6 P a g e C -

— S ± a . r ± C a r t r i d g e sT h C o m m o d o r e 6 h a f e a t u r e w h i c h a l l o w s p r o g r a m i

R O s t a r t i n g a t $ 8 0 0 0 ( 3 2 7 6 8 ) t s i e z e c o n t r o l o t h m a c h i n e a p o w e r - u p a n R E S E T t i m e s w i t h o u t a n y f u r t h e r i n t e r v e n t i o nr e q u i r e d o t h e p a r t o f t h o p e r a t o r .

A p o w e r - u p t i m e o n o f t h e v e r y f i r s t t h i n g s t h o p e r a t i n g s y s t e m d o e s i c h e c k f o a f i v e c h a r a c t e r s e q u e n c es t a r t i n g a l o c a t i o n $ 8 0 0 4 . I i f i n d s $ C 3 , $ C 2 , $ C D , $ 3 8 , $ 3 0 i w i l l a u t o m a t i c a l l y j u m p t t h a d d r e s s i f o u n d a $ 8 0 0 0 , $ 8 0 0 i .s e c o n d a d d r e s s i s t o r e d i $ 8 0 0 2 * * 8 0 0 3 . T h i s i t h a d d r e s so f t h e [ R E S T O R E D k e p r o c e s s i n g r o u t i n e .

T c r e a t e y o u r o w c a r t r i d g e s y o m u s t e n c o d e t h f i r s tb y t e s a d e s c r i b e d a b o v e . I w i l l b n e c e s s a r y t b u r n P R O M( p r o g r a m m a b l e r e a d o n l y m e m o r y ) a n i n s t a l l i o n a n a p p r o p r i a t ec a r d f o r c o m p l e t e a u t o - s t a r t c a p a b i l i t y . T h P r o g r a m m e r ' sR e f e r e n c e G u i d e h a c o m p l e t e d e f i n i t i o n o f t h e c a r d c o n n e c t o rs p e c i f i c a t i o n s . P r o m p r o g r a m m e r s a r e a v a i l a b l e f r o m v a r i e t y o s o u r c e s . C h e c k t h m a g a z i n e a d s .

Page 143: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 143/172

I n t i d t T h C o m m o d o r t 6 P a g t D -

C o m m o d o r e 6 M e m o r y M a H e D e c i m a l F u n c t i o n

O n - c h i p d a t a - d i r e c t i o n r e g i s t e rO n - c h i p I / P o r tU n u s e dF l o a t - > i n t e g e rI n t e g e r - > f l o a tS e a r c h c h a r " : o e n d l i n eS c a n b t w n q u o t e s f l a g 0 0 a s d e l i m e t e rC o l u m n p o o l a s t T a V e r i f y f l a g ( 0 = L o a d / i = V e r i f y )B a s i c i n p u t b u f f e r p o i n t e r / t t s u b s c r i p t sD I f l a gV a r i a b l e f l a g t y p e : F F = s t r i n g 0 0 = n u m e r i cI n t e g e r f l a g : 8 0 = i n t e g e r 0 0 = f l o a t i n g p D A T A s c a n f l a g / L I S T q u o t e f l a g / m e m o r y f l a gS u b s c r i p t f l a g ; F N x f l a g

i n p u t r e a d ( 0 = i n p u t - 6 4 = g e t i 5 2 = r e a dA T s i g n f l a g : c o m p a r i s o n e v a l u a t i o n f l a gC u r r e n t I / d e v i c e f o p r o m p t s u p p r e s sB a s i c i n t e g e r a d r . ( f o r S Y G O T O e t c )T e m p o r a r y s t r i n g d e s c r i p t o r s t a c k p o i n t e rL a s t t e m p o r a r y s t r i n g v e c t o rS t a c k o d e s c r i p t o r s f o t e m p o r a r y s t r i n g sP o i n t e r f o n u m b e r t r a n s f e rM i s c n u m b e r p o i n t e rP r o d c t a r e a f o m u l tP o i n t e r t o s t a r t o f B a s i cP o i n t e r t e n o p r o g . s t a r t o v a r i a b l e sP o i n t e r t e n o v a r i a b l e s s t a r t o a r r a y sP o i n t e r t e n o a r r a y sP o i n t e r t b o t t o m o s t r n g s p c e ( c o m i n g d w n )P o i n t e r t t o o a c t i v e s t r i n g sP o i n t e r t e n o m e m o r yC u r r e n t B a s i c l i n e n u m b e rP r e v B A S I C l i n e n u P r e v i o u s B A S I C s t a t e m e n t < f o r C O N T )

0 0 0 00 0 0 10 0 0 20 0 0 30 0 0 59 0 0 70 0 0 80 0 0 90 0 0 A8 0 8 B0 0 0 C0 0 8 D0 0 0 E0 8 0 F9 0 1 00 0 1 10 0 1 20 0 1 30 0 1 40 0 1 60 0 1 70 0 1 ?8 0 2 28 8 2 40 0 2 68 0 2 B0 0 2 D0 0 2 F0 0 3 10 8 3 30 8 3 58 0 3 70 0 3 ?8 8 3 B0 8 3 D

3 - 5 -

1 1 1 1 1 1 1 1 1 1 2 0 - 2 12 2 3 - 2 42 5 - 3 33 4 - 3 53 6 - 3 73 8 - 4 24 3 - 4 44 5 - 4 64 7 - 4 84 ? - 5 05 1 - 5 25 3 - 5 45 5 - 5 65 7 - 5 85 ? - 6 86 1 - 6 2

Page 144: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 144/172

I n s i d e T h C o m m o d o r e 6 P a g e D -

H e

8 8 3 F8 6 4 18 0 4 30 0 4 50 0 4 70 0 4 90 0 4 B0 8 4 D0 0 4 E0 0 5 00 0 5 20 0 5 30 0 5 40 0 5 70 0 6 10 0 6 70 0 6 80 0 6 F8 0 7 00 0 7 10 0 7 30 0 8 B0 0 9 00 0 9 10 8 9 20 0 9 30 0 9 40 0 9 5Z Z 9 60 0 9 70 0 9 80 0 9 90 0 9 ^8 0 9 B0 0 9 C0 0 9 D0 0 9 E

D e c i m a l

6 3 - 6 46 5 - 6 66 7 - 6 86 9 - 7 07 1 - 7 27 3 - 7 47 5 - 7 67 7 8 - 7 98 0 - 8 18 8 8 4 - 8 68 7 - 9 69 7 - 1 0 21 0 1 0 1 0 5 - 1 1 81 1 1 1 1 1 3 - 1 1 41 1 5 - 1 3 81 3 9 - 1 4 31 4 1 4 1 4 1 4 1 4 1 4 1 5 1 5 1 5 1 5 i b 1 5 1 5 1 5 1 5

F u n c t i o n

L i n e n u m b e r - c u r r e n t D A T A l i n eP o i n t e r t o c u r r e n t D A T A i t e mI n p u t v e c t o rC u r r e n t v a r i a b l e n a m eC u r r e n t v a r i a b l e a d d r e s sV a r i a b l e p o i n t e r - f o r F O R / N E X T

s a v e / n e w o s a v e / c u r r o p o i n t e rS p e c i a l m a s k - f o r c u r r o p r t r j C o m p a r i s o n s y m b o lM i s c . w o r k a r e a j f u n c t i o n d e p o i n t e r h i - l oW o r k a r e a j p o i n t e r t o s t r n g d e s c r p t nL e n g t h o a b o v e s t r i n gC o n s t a n t u s e d b g a r b a g e c o l l e c t o J u m p v e c t o r f o f u n c t i o n sM i s c . n u m e r i c a l s t o r a g e a r e aF A C # iS e r i e s e v a l u a t i o n c o n s t a n t p o i n t e rF A C # i h i g h o r p r o p o g a t i o nA c c u m u l a t o r # S i g n c o m p a r i s o n F A C 1 v F A C 2L o o r d e r r o u n d i n g b y t e f o A c c # iC a s s e t t e b u f f e r l e n g t h / s e r i e s p o i n t e rS u b r t n : G e t B a s i c c h a r ; 7 A - 7 B = p o i n t e r ( C H A R G O T )R N s t o r a g e a n d w o r k a r e aS t a t u s S S t o p / R V S k e f l a gT i m i n g c o n s t a n t f o t a p eL o a d o v e r i f y f l a g L = 0 / V = iS e r i a l o u t p u t / d e f e r r e d c h a r f l a gS e r i a l d e f e r r e d c h a r a c t e rT a p e E O r e c v dR e g i s t e r s a v e a r e a# o p e n f i l e sI n p u t d e v i c e # n o r m a l l yO u t p u t C M d e v i c e - n o r m a l l yT a p e c h a r a c t e r p a r i t yC a s s e t t e d i p o l e s w i t c hO m e s s a g e f l a g d i r e c t = $ S 0 r u n = 0C a s s e t t e e r r o r p a s s

Page 145: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 145/172

I n t i d t T h C o m o o 6 P t g t D -

H e D e c i m a l F u n c t i o n

0 0 9 F 1 5 C a s s e t t e e r r o r p a s s8 8 A 8 1 6 9 - 1 6 2 J i f f y c l o c k ( H M D0 6 A 3 1 6 S e r i a l b i c o u n t0 0 A 4 1 6 C y c l e c o u n t e r f o r s e r i a l I / 0 0 A 5 1 6 C n t d w n f o t a p e w r i t e8 0 A 6 1 6 C a s s e t t e b u f f e r p o i n t e r0 0 A 7 6 R S - 2 3 2 i n p u t b i s t o r a g e / T a p e s h r t c n t8 0 A 8 1 6 R S - 2 3 2 b i c n i n T a p e r e a d e r r o r0 0 A ? 1 6 R S - 2 3 2 f l a g s t a r t b i c k / T a p e r b i e r 0 0 A A 1 7 R S - 2 3 2 b y t e b u f f e r / T a p e r m o d e0 8 A B 7 R S - 2 3 2 p a r i t y s t o r a g e / T a p e c h k s u m0 0 A C 1 7 2 - 1 7 3 T a p e s t a r t a d d r / t a p e b u f f e r s c r o l l i n g0 8 A E 1 7 4 - 1 7 5 T a p e e n a d d r / e n d o c u r r e n t p r o g r a m0 0 B 0 1 7 6 - 1 7 7 T a p e t i m i n g c o n s t a n t s0 0 B 2 1 7 8 - 1 7 ? A d d r o t a p e b u f f e r0 0 B 4 1 8 R S - 2 3 2 t r a n s m i t t e r b i c n o u 8 0 B 5 1 8 R S - 2 3 2 t r a n s m i t t e r n x t b i t b s e n t0 0 B 6 1 8 2 R S - 2 3 2 t r a n s m i t t e r b y t e b u f f e r8 0 B 7 1 8 L e n g t h o c u r r e n t f i l e n a m e s t r i n g0 0 B 8 1 8 C u r r e n t l o g i c a l f i l e n u m b e r0 0 B ? 1 8 C u r r s e c o n d a r y a d d r o R / c o m m a n d0 0 B A 1 8 C u r r d e v i c e n u m b e r8 0 B B 1 8 7 - 1 8 8 A d d r o c u r r f i l e n a m e s t r i n g8 0 B D 1 8 9 R S - 2 3 2 w r i t e s h i f t w o r d / R e c e i v e i n p u t c h a r0 8 B E 1 9 # b l o c k s r e m a i n i n g t r e a d / w r i t e0 0 B F 1 9 S e r i a l w o r d b u f f e r0 0 C 0 1 9 C a s s m o t o r i n t e r l o c k0 C 1 9 3 - 1 9 4 T a p e s t a r t a d d r ( l o a d )8 8 C 3 1 9 5 - 1 9 6 K E R N A L s e t u p p o i n t e r0 8 C 5 1 9 M a t r i x c o - o r d i n a t e s o f k e y p r e s s e d0 0 C 6 1 9 # o c h a r a c t e r s i k e y b r d b u f f e r0 0 C 7 1 9 9 R e v e r s e m o d e f l a g 0 = o f f 1 3 = o n8 8 C 8 2 0 E n o l i n e f o i n p u t p o i n t e r0 0 C 9 2 8 1 - 2 0 2 C u r s o r l o g ( r o w c o l u m n )0 0 C B 2 0 P r i n t s h i f t e d C h a r s f l a g0 0 C C 2 0 C u r s o r b l i n k e n a b l e d f l a g - 0 = o n i = o f f0 C D 2 8 5 D e l a y b e f o r e c u r s o r b l i n k s0 0 C E 2 0 C h a r a c t e r u n d e r c u r s o r

Page 146: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 146/172

I n s i d e T h C o m m o d o r e P a g e D -

H e

8 8 C F8 0 D 00 8 D 10 8 D 30 0 D 40 0 D 50 0 D 60 8 D 78 0 D 80 0 D ?0 0 F 28 0 F 30 8 F 50 0 F 70 0 F 98 0 F B8 0 F F0 1 0 00 1 0 00 1 0 00 2 0 00 2 5 ?0 2 6 30 2 6 D0 2 7 70 2 8 10 2 8 30 2 8 50 2 8 60 2 8 70 2 8 80 2 8 ?0 2 8 A0 2 8 B0 2 8 C6 2 8 D0 2 8 E0 2 8 F

D e c i m a l

2 0 2 0 2 0 ? - 2 1 02 1 2 1 2 1 2 1 2 1 2 1 2 1 7 - 2 4 22 4 2 4 3 - 2 4 42 4 5 - 2 4 62 4 7 - 2 4 82 4 ? - 2 5 02 5 1 - 2 5 42 5 2 5 6 - 2 6 62 5 6 - 3 1 82 5 6 - 5 1 15 1 2 - 6 8 06 0 1 - 6 1 86 1 1 - 6 2 06 2 1 - 6 3 06 3 1 - 6 4 06 4 1 - 6 4 26 4 3 - 6 4 46 4 6 4 6 4 6 4 6 4 6 5 6 5 6 5 6 5 6 5 6 5 5 - 6 5 6

F u n c t i o n

C u r s o r o n / o f f b l i n k - f l a gI n p u t f r o m s c r e e n / k e y b r dS c r e e n a d d r ( r o w ) p o i n t e r ( s c r e e n m e m o r y )P o s i t i o n o c u r s o r o c u r r l i n eQ u o t e m o d e f l a g ( 0 = o f f i = o n )L i n e l e n g t h f o s c r e e nC u r r e n t s c r e e n l i n e n u m b e rA S C I I v a l u e o l a s t k e p r e s s

o i n s e r t s o u t s t a n d i n gS c r e e n l i n e l i n k t a b l eS c r e e n r o m a r k e rS c r e e n c o l o r p t K e y s c a n t a b l e i n d i r e c tP o i n t e r t R S - 2 3 2 r e c e i v e b u f f e r a d d rP o i n t e r t R S - 2 3 2 t r a n s m i t t e r b u f f e r a d d rF r e e z e r o p a g e l o c a t i o n sB A S I C s t o r a g eF l o a t i n g t A S C I I w o r k a r e aT a p e e r r o r l o P r o c e s s o r s t a c k a r e aB a s i c i n p u t b u f f e rL o g i c a l f i l e n u m b e r t a b l eD e v i c e n u m b e r t a b l eS e c o n d a r y a d d r o R / c m t a b l eK e y b o a r d b u f f e rS t a r t o f m e m o r yT o o m e m o r yS e r i a l t i m e o u t f l a gA c t i v e c o l o r c o d eB a c k g r o u n d c o l o r u n d e r c u r s o rT o o S c r e e n p a g eK e y b o a r d b u f f e r m a l e n g t hR e p e a t f l a g 0 = c u r s o r o n l y - 1 2 8 = a l l k e y sD e l a y b e f o r e r e p e a t o c c u r sD e l a y b t w n r e p e a t sS h i f t f l a g b y t eL a s t s h i f t p a t t e r nI n d i r e c t f o r k e y b o a r d t a b l e s e t u p

Page 147: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 147/172

I n s i d e T h C o m m o d o r e 6 P t g t D -

8 2 9 10 2 9 20 2 9 30 2 9 46 2 9 50 2 9 70 2 9 80 2 9 98 2 9 B0 2 9 C0 2 9 D0 2 9 E0 2 9 F0 2 A 18 3 0 00 3 0 28 3 0 40 3 0 60 3 8 30 3 0 A0 3 0 C0 3 0 00 3 8 E0 3 0 F0 3 1 40 3 1 60 3 1 88 3 1 A0 3 1 C0 3 1 E0 3 2 00 3 2 28 3 2 40 3 2 60 3 2 80 3 2 A0 3 2 C0 3 2 E8 3 3 80 3 3 2

6 5 6 5 6 5 6 6 6 6 1 - 6 6 26 6 6 6 6 6 5 - 6 6 66 6 6 6 6 6 6 7 6 7 1 - 6 7 26 7 3 - 7 6 77 6 8 - 7 6 97 7 0 - 7 7 17 7 2 - 7 7 37 7 4 - 7 7 57 7 6 - 7 7 77 7 8 - 7 7 97 8 7 8 7 8 7 8 7 3 8 - 7 8 97 9 0 - 7 9 17 9 2 - 7 9 37 9 4 - 7 9 57 9 6 - 7 9 77 9 8 - 7 9 98 0 0 - 8 0 18 8 2 - 8 0 38 8 4 - 8 0 58 0 6 - 8 0 78 8 8 - 8 0 98 1 0 - 8 1 18 1 2 - 8 1 38 1 4 - 8 1 58 1 6 - 8 1 78 1 8 - 8 1 9

S h i f t m o d e s w i t c h - 0 = e n a b l e d - 1 2 8 = l o c K e dA u t o s c r o l l d w f l a g ( 0 = o n - < > 0 = o f f )

6 5 5 1 R S 2 3 2 c o n t r o l r e g i s t e r i m a g e6 5 5 1 R S 2 3 2 C o m m a n d r e g i s t e r i m a g e

N o s t a n d a r d ( b i t t i m e / 2 - i e e )6 5 5 1 R S - 2 3 2 s t a t u s r e g i s t e r i m a g eN u m b e r o b i t s t o s e n dB a u d r a t e f u l l b i t i m eR S - 2 3 2 e n o f r e c e i v e r p o i n t e rR S - 2 3 2 s t a r t r e c e i v e b u f f e rR S - 2 3 2 s t a r t t r a n s m i t o u t p u t b u fR S - 2 3 2 e n o t r a n s m i t b u f f e rH o l d s I R d u r i n g t a p e o p e r a t i o nP r o g r a m i n d i r e c t sI n d i r e c t e r r o r r o u t i n eI n d i r e c t w a r m s t a r tI n d i r e c t t o k e n i z e B A S I CI n d i r e c t t o k e n p r i n tI n d i r e c t n e t o k e nI n d i r e c t s y m b o l e v a l u a t i o nT e m p o r a r y s t o r a g e d u r i n g S Y o A - r e gT e m p o r a r y s t o r a g e d u r i n g S Y o X - r e gT e m p o r a r y s t o r a g e d u r i n g S Y o Y - r e gT e m p o r a r y s t o r a g e d u r i n g S Y o P - r e gI R v e c t o rB R v e c t o rN M v e c t o rO p e n l o g i c a l f i l e v e c t o r ( O P E N )C l o s e l o g i c a l f i l e v e c t o r ( C L O S E )S e t i n p u t d e v i c e v e c t o r ( C H K I N )S e o u t p u t d e v i c e v e c t o r ( C H K O U T )R e s e t d e f a u l t I / ( C L R C H N )I n p u t f r o m d e v i c e ( C H R I N )O u t p u t t d e v i c e v e c t o r ( C H R O U T )T e s t S T O P k e v e c t o r ( S T O P )G e t f r o m k e y b o a r d v e c t o r ( G E T I N )C l o s e a l f i l e s v e c t o r ( C L A L L )U s e r d e f i n e d v e c t o r

L o a d f r o m d e v i c e v e c t o r ( L O A D )S a v e t d e v i c e v e c t o r ( S A V E )

Page 148: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 148/172

I n s i d t T h C o m m o d o r t 6

H e

8 3 3 48 3 3 C8 3 F C0 4 0 80 4 0 00 7 F 80 8 0 0A 0 0 0A 0 0 0A 6 4 6A 0 7 4A 0 9 2A 1 9 3A 3 8 AA 3 B 8A 3 F BA 4 0 8A 4 3 5A 4 7 4A 4 8 3A 5 3 3A 5 6 0A 5 7 CA 6 1 3A 6 4 2A 6 6 0A 6 8 EA 6 9 CA 7 4 2A 7 E DA 8 1 DA 8 2 CA 8 5 7A 8 7 1A 8 8 3A 8 A 0A 8 D 2A 8 E B

D e c i m a l

8 2 0 - 8 2 78 2 8 - 1 0 1 ?1 0 2 0 - 1 0 2 31 0 2 4 - 2 0 4 71 0 2 4 - 2 0 2 32 0 4 0 - 2 0 4 72 0 4 8 - 4 0 9 5 94 0 9 6 0 - 4 9 1 5 14 0 9 6 04 1 6 3 04 1 0 7 64 1 1 0 64 1 3 6 34 1 8 6 64 1 9 1 24 1 9 7 94 1 9 9 24 2 0 3 74 2 1 0 04 2 1 1 04 2 2 9 14 2 3 3 64 2 3 6 44 2 5 1 54 2 5 6 24 2 5 9 24 2 6 3 84 2 6 5 24 2 8 1 84 2 9 8 94 3 9 3 74 3 0 5 24 3 0 9 54 3 1 2 14 3 1 3 94 3 1 6 84 3 2 1 84 3 2 4 3

F u n c t i o n

U n u s e dC a s s e t t e b u f f e rU n u s e d1 0 2 4 b y t e s c r e e n m e m o r y a r e a2 l i n e s b 4 c o l u m n s v i d e o m a t r i xS p r i t e d a t a p o i n t e r sN o r m a l u s e r B a s i c a r e aB A S I C R O o 8 o R A K e y w o r d a c t i o n a d d r e s s e sF u n c t i o n a c t i o n a d d r e s s e sO p e r a t o r a c t i o n a d d r e s s e sK e y w o r d T a b l eE r r o r m e s s a g e sF O G O S U B s e a r c h s t a c kO p e n m e m o r y s p a c eT e s t s t a c k d e p t hC h e c k a v a i l a b l e m e m o r yS e n d e r r o r m e s s a g eP r i n t R E A D Y .N e B A S I C l i n e p r o c e s s i n gB A S I C l i n e c h a i n i n gR e c e i v e l i n e f r o m k e y b o a r dT o k e n i z e B A S I C l i n eS e a r c h f o l i n e n u m b e rP e r f o r m N E P e r f o r m C L R e s e t B A S I C e x e c u t i o n t s t a r t - o f - p r o g r a mP e r f o r m L I S TP e r f o r m F O E x e c u t e B A S I C s t a t e m e n tP e r f o r m R E S T O R EP e r f o r m S T O P a n E N P e r f o r m C O N TP e r f o r m R U P e r f o r m G O S U BP e r f o r m G O T OP e r f o r m R E T U R NP e r f o r m D A T A

Page 149: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 149/172

I n s i d B T h C o m m o d o r t 6 P t g i 0 -

H e

A 9 0 6A 9 9 9A 9 2 8A 9 3 BA 9 4 BA 9 6 BA 9 A 5A A 8 8A A 8 6A A 9 AA B I EA B 3 BA B 4 DA B 7 BA B A SA B B FA B F 9A C 8 6A C F CA D 1 EA D 7 8A D 9 EA E A 8A E F 1A E F 7A E F AA E F DA F 0 8A F 1 4A F A 7A F E 6A F E 9B 8 1 6B 0 7 EB 0 8 BB 1 B U B 1 9 4

D e c i m a l

4 3 2 7 84 3 2 7 34 3 3 0 44 3 3 2 34 3 3 3 94 3 3 7 14 3 4 2 94 3 6 4 84 3 6 5 44 3 6 7 44 3 8 0 64 3 8 3 54 3 8 5 34 3 8 9 94 3 9 4 14 3 9 6 74 4 0 2 54 4 0 3 84 4 2 8 44 4 3 1 84 4 4 0 84 4 4 4 64 4 7 1 24 4 7 8 54 4 7 9 14 4 7 9 44 4 7 9 74 4 8 0 84 4 8 2 04 4 9 6 74 5 0 3 04 5 0 3 34 5 0 7 84 5 1 8 24 5 1 9 54 5 3 4 34 5 3 4 14 5 4 6 0

F u n c t i o n

S c a n f o n e x t s t a t e m e n tS c a n f o n e x t l i n eP e r f o r m I P e r f o r m R E P e r f o r m O G e i n t e g e r f r o m t e x tP e r f o r m L E P e r f o r m P R I N T *P e r f o r m C M P e r f o r m P R I N TP r i n t s t r i n g f r o m a n m e m o r yP r i n t f o r m a t c h a r a c t e rP r o c e s s b a d i n p u tP e r f o r m G E P e r f o r m I N P U T #P e r f o r m I N P U TP r o m p t & i n p u tP e r f o r m R E A DI n p u t e r r o r m e s s a g e sP e r f o r m N E X TT y p e m a t c h c h e c kE v a l u a t e e x p r e s s i o nP i f l o a t i n g p o i n tE v a l u a t e w i t h i n p a r e n t h e s i sC h e c K f o r " ) "C h e c k f o r ' TC h e c k f o S y n t a x e r r o rS e a r c h f o r v a r i a b l e n a m eS e u F r e f e r e n c e sP e r f o r m O P e r f o r m A N C o m p a r i s o n r o u t i n eP e r f o r m D I L o c a t e v a r i a b l eC h e c k f o a l p h a A S C I IC r e a t e n e v a r i a b l eA r r a y p o i n t e r r o u t i n e

Page 150: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 150/172

I n s i d e T h C o m m o d o r e 6 P a g e D -

H e

B 1 A 5B 1 B FB 1 D 1B 3 4 CB 3 7 DB 3 9 1B 3 9 EB 3 A 6B 3 B 3B 3 E 1B 3 F 4B 4 6 5B 4 7 5B 4 8 7B 4 F 4B 5 2 6B 5 B DB 6 8 6B 6 3 DB 6 7 AB 6 A 3B 6 D BB 4 E CB 7 8 8B 7 2 CB 7 3 7B 7 6 1B 7 7 CB 7 8 2B 7 8 BB 7 9 BB 7 A DB 7 E BB 7 F 7B 8 0 DB 8 2 4B 8 2 DB 8 4 ?

D e c i m a l

4 5 4 7 74 5 5 8 34 5 5 2 14 5 9 8 84 5 9 4 94 5 9 4 94 5 9 8 24 5 9 9 84 6 8 8 34 6 8 4 94 6 8 6 84 6 1 8 14 6 1 9 74 6 2 1 54 6 3 2 44 6 3 7 44 6 5 2 54 6 5 9 84 6 6 5 34 6 7 1 44 6 7 5 54 6 8 1 14 6 8 2 84 6 8 4 84 6 8 9 24 6 9 8 34 6 9 4 54 6 9 7 24 6 9 7 84 6 9 8 74 7 8 8 34 7 8 2 14 7 8 8 34 7 8 9 54 7 1 1 74 7 1 4 84 7 1 4 94 7 1 7 7

F u n c t i o n

3 2 7 6 8 i f l o a t i n g p o i n tF A C 1 t o i n t e g e rF i n d o C r e a t e A r r a yC o m p u t e s u b s c r i p t s i z eP e r f o r m F R I n t e g e r t F A C iP e r f o r m P O C h e c k f o D I R E C T m o d eP e r f o r m D E C h e c k F s y n t a xE v a l u a t e F P e r f o r m S T R $C a l c u l a t e s t r i n g v e c t o rS e u s t r i n gB u i l d s t r i n g v e c t o rC o l l e c t g a r b a g e ( m a k e r o o m f o s t r i n g )C h e c k s t r i n g c o l l e c t i o n e l i g i b i l i t yC o l l e c t s t r i n gC o n c a t e n a t e s t r i n gB u i l d s t r i n g t o m e m o r yD i s c a r d u n w a n t e d s t r i n gC l e a n t h e d e s c r i p t o r s t a c kP e r f o r m C H R $P e r f o r m L E F T *P e r f o r m R I G H T SP e r f o r m M I D $P u l l s t r i n g p a r a m e t e r s f r o m s t a c kP e r f o r m L E E x i t s t r i n g m o d eP e r f o r m A S I n p u t b y t e p a r a m e t e rP e r f o r m V A G e P O K E / W A I T p a r a m e t e r sF A C i t i n t e g e rP e r f o r m P E E KP e r f o r m P O K EP e r f o r m W A I TA d 6 . t F A C i

Page 151: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 151/172

I n s i d e T h C o m m o d o r e 6 P a g e D -

H e

B 8 5 8B 8 6 AB 9 4 7B 9 7 EB 9 8 3B 9 B CB 9 E AB A 2 8B A 3 0B A 5 9B A 8 CB A B 7B A D 4B A E 2B A F 9B A F EB B 6 7B B 0 FB B 1 2B B A 2B B D 7B B F CB C 9 FB C 1 BB C 2 BB C 3 9B C 5 8B C 5 BB C 9 BB C C CB C F 3B D 7 EB D B 3B D D DB F 1 1B F 7 1B F 7 8B F B 4

D e c i m a l

4 7 1 8 44 7 2 1 84 7 4 3 14 7 4 8 64 7 4 9 14 7 5 4 84 7 5 9 44 7 6 5 64 7 6 6 44 7 7 8 54 7 7 5 64 7 7 9 94 7 8 2 84 7 8 4 24 7 8 6 54 7 8 7 84 7 8 7 94 7 8 8 74 7 8 9 84 8 8 3 44 8 0 8 74 8 1 2 44 8 1 4 34 8 1 5 54 8 1 7 14 8 1 8 54 8 2 1 64 8 2 1 94 8 2 8 34 8 3 3 24 8 3 7 14 8 5 1 04 8 5 6 34 8 6 8 54 8 9 1 34 9 8 0 94 9 0 1 64 9 0 7 6

F u n c t i o n

P e r f o r m s u b t r a c t i o nP e r f o r m a d d i t i o nC o m p l e m e n t F A C iO v e r - f l o wS i n g l e b y t e m u l t i p l yF l o a t i n g p o i n t c o n s t a n t sP e r f o r m L O M u l t i p l y F A C i m e m o r yM u l t i p l y F A C 2 F A C iM u l t i p l y b i M e m o r y t F A C 2A d j u s t F A C i / F A C 2U n d e r f l o w / o v e r f l o wM u l t i p l y F A C i b 1 C o n s t a n t 1 D i v i d e b y 1 D i v i d e F A C 2 m e m o r yD i v i d e m e m o r y F A C iD i v i d e F A C 2 F A C iM e m o r y t F A C iF A C i t m e m o r yF A C 2 t F A C iF A C i t F A C 2R o u n d o f F A C iG e s i g nP e r f o r m S G P e r f o r m A B C o m p a r e F A C i t m e m o r yF A C i t i n t e g e rP e r f o r m I N A S C I I t F A C IG e n e A S C I I d i g i tC o n s t a n t sF A C i t A S C I IM o r e c o n s t a n t sP e r f o r m S Q P e r f o r m e x p o n e n t i a t i o nP e r f o r m n e g a t i o n

Page 152: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 152/172

I n s i d e T h C o m m o d o r e 6 P t g t D - t t

H e

B F B FB F E DC 9 8 0D 9 0 0D 0 6 0D 0 8 1D 0 0 2D 8 0 3D 0 0 4D 0 6 5D 0 0 6D 8 0 7D 0 0 8D 0 0 9D 0 0 AD 0 0 BD 0 0 CD 0 6 DD 0 0 ED 0 0 FD 0 1 0D 0 1 1D 0 1 2D 0 1 3D 0 1 4D 8 1 5D 0 1 6D 0 1 7D 0 1 8D 0 1 9D 0 1 AD 0 1 BD 0 1 CD 0 1 DO 0 1 ED 0 1 FD 0 2 0D 0 2 1

D e c i m a l

4 9 0 8 74 9 1 3 34 9 1 5 2 - 5 3 2 4 75 3 2 4 8 - 5 7 3 4 35 3 2 4 85 3 2 4 95 3 2 5 05 3 2 5 15 3 2 5 25 3 2 5 35 3 2 5 45 3 2 5 55 3 2 5 65 3 2 5 75 3 2 5 85 3 2 5 95 3 2 6 05 3 2 6 15 3 2 6 25 3 2 6 35 3 2 6 45 3 2 6 55 3 2 6 65 3 2 6 75 3 2 6 85 3 2 6 95 3 2 7 05 3 2 7 15 3 2 7 25 3 2 7 35 3 2 7 45 3 2 7 55 3 2 7 65 3 2 7 75 3 2 7 85 3 2 7 95 3 2 8 05 3 2 8 1

F u n c t i o n

M o r e c o n s t a n t s y e P e r f o r m E X R A a v a i l a b l e - f o r m a c h i n e l a n g u a g e p r o g sI / C o l o r R A M / C h a r G n r a t r R O M / 4 K R A S p r i t e P o S p r i t e P o S p r i t e P o S p r i t e P o S p r i t e P o S p r i t e P o S p r i t e P o S p r i t e P o S p r i t e P o S p r i t e 4 P o S p r i t e P o S p r i t e P o S p r i t e P o S p r i t e P o S p r i t e P o S p r i t e P o S p r i t e s 0 - P o ( m s b o f c o o r d . )V I C o n t r o l R e g i s t e rR e a d / W r i t e R a s t e r V a l u e f o C o m p a r e I R L i g h t - P e n L a t c h P o L i g h t - P e n L a t c h Y P o sS p r i t e D i s p l a y E n a b l e : 1 = E n a b l eV I C o n t r o l R e g i s t e rS p r i t e s 0 - 7 E x p a n d 2 V e r t i c a l ( Y V I M e m o r y C o n t r o l R e g i s t e rV I I n t e r r u p t F l a g R e g . ( B i t = i : I R O c c u r r e d )I R M a s k R e g . ^ I n t e r r u p t E n a b l e dS p r i t e t o B k g r n d D i s p l a y P r i o r i t y : 1 S p r i t eS p r i t e s 0 - 7 M u l t i - C o l o r M o d e S e l e c tS p r i t e s 0 - E x p a n d 2 H o r i z o n t a lS p r i t e t o S p r i t e C o l l i s i o n D e t e c tS p r i t e t o B a c k g r o u n d C o l l i s i o n D e t e c tB o r d e r C o l o rB a c k g r o u n d C o l o r

Page 153: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 153/172

I n s i d e T h C o m m o d o r e 6 P i g t D - i l

H e D e c i m a l F u n c t i o n

D 8 2 2 5 3 2 8 2 B a c k g r o u n d C o l o rD 8 2 3 5 3 2 8 3 B a c k g r o u n d C o l o rD 0 2 4 5 3 2 8 4 B a c k g r o u n d C o l o rD 8 2 5 5 3 2 8 5 S p r i t e M u l t i - C o l o r R e g i s t e rD 8 2 6 5 3 2 8 6 S p r i t e M u l t i - C o l o r R e g i s t e rD 0 2 7 5 3 2 8 7 S p r i t e C o l o rD 6 2 8 5 3 2 8 8 S p r i t e C o l o rD 0 2 ? 5 3 2 8 9 S p r i t e C o l o rD 0 2 A 5 3 2 9 6 S p r i t e C o l o rD 0 2 B 5 3 2 9 1 S p r i t e C o l o rD 0 2 C 5 3 2 9 2 S p r i t e C o l o rD 0 2 D 5 3 2 9 3 S p r i t e C o l o rD 0 2 E 5 3 2 9 4 S p r i t e C o l o rD 4 0 0 5 4 2 7 2 V o i c e l : F r e q u e n c y C o n t r o l - L o w - B y t eD 4 0 1 5 4 2 7 3 V o i c e 1 : F r e q u e n c y C o n t r o l - H i g h - B y t eD 4 0 2 5 4 2 7 4 V o i c e i : P u l s e W a v e f o r m W i d t h - L o w - B y t eD 4 9 3 5 4 2 7 5 U n u s e dD 4 0 4 5 4 2 7 6 V o i c e l : C t r l R e g . R a n d o m N o i s e l = O nD 4 0 5 5 4 2 7 7 E n v e l o p e G n r t r " l : A t t a c k / D e c a y C y c l e C o n t r o lD 4 0 6 5 4 2 7 8 E n v e l o p e G n r t r i : S u s t / r e l C y c l e C o n t r o lD 4 0 7 5 4 2 7 9 V o i c e 2 F r e q u e n c y C o n t r o l - L o w B y t eD 4 0 8 5 4 2 8 0 V o i c e 2 F r e q u e n c y C o n t r o l - H i g h - B y t eD 4 0 9 5 4 2 8 1 V o i c e 2 P u l s e W a v e f o r m W i d t h - L o w - B y t eD 4 0 A 5 4 2 8 2 U n u s e dD 4 8 B 5 4 2 8 3 V o i c e 2 C o n t r o l R e g i s t e rD 4 0 C 5 4 2 8 4 E n v e l o p e G n r t r 2 A t t a c k / D e c a y C y c l e C o n t r o lD 4 0 D 5 4 2 8 5 E n v e l o p e G n r t r 2 : S u s t / R e l C y c l e C o n t r o lD 4 0 E 5 4 2 8 6 V o i c e 3 F r e q u e n c y C o n t r o l - L o w - B y t eD 4 0 F 5 4 2 8 7 V o i c e 3 F r e q u e n c y C o n t r o l - H i g h - B y t eD 4 1 0 5 4 2 8 8 V o i c e 3 P u l s e W a v e f o r m W i d t h - L o w - B y t eD 4 1 1 5 4 2 8 9 U n u s e dD 4 1 2 5 4 2 9 0 V o i c e 3 : C t r l R e R a n d o m N o i s e : l = O nD 4 1 3 5 4 2 9 1 E n v e l o p e G n r t r 3 : A t t a c k / D e c a y C y c l e C t r lD 4 1 4 5 4 2 9 2 E n v e l o p e G n r t r 3 : S u s t / R e l C y c l e C o n t r o lD 4 1 5 5 4 2 9 3 F i l t e r C u t o f f F r e q L o w - N y b b l e ( B i t s 2 - 0 )D 4 1 6 5 4 2 9 4 F i l t e r C u t o f f F r e q H i g h - B y t eD 4 1 7 5 4 2 9 5 F i l t e r R e s o n a n c e C t r l / I n p u t C o n t r o lD 4 1 8 5 4 2 9 6 S e l e c t F i l t e r M o d e a n V o l u m e

Page 154: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 154/172

I n s i d e T h C o m m o d o r e 6 P a g e D - 1 2

H e D e c i m a l F u n c t i o n

D 4 1 ? 5 4 2 9 7 A n a l o g / D i g i t a l C v t r G a m e P a d d l e ( 0 - 2 5 5 )D 4 1 A 5 4 2 9 8 A n a l o g / D i g i t a l C v t r : G a m e P a d d l e ( 0 - 2 5 5 )D 4 1 B 5 4 2 9 9 O s c i l l a t o r R a n d o m N u m b e r G e n e r a t o rD 4 1 C 5 4 2 3 8 E n v e l o p e G e n e r a t o r O u t p u tD C 8 8 5 6 3 2 8 D a t a P o r t ( K y b d , J o y , P a d d l e s , L i g h t - P e n )D C 9 1 5 6 3 2 1 D a t a P o r t ( K y b d , J o y , P a d d l e s , G a m e P o r tD C 0 2 5 6 3 2 2 D a t a D i r e c t i o n R e g i s t e r - P o r t ( 5 6 3 2 0 )D C 0 3 5 6 3 2 3 D a t a D i r e c t i o n R e g i s t e r - P o r t ( 5 6 3 2 1 )D C 0 4 5 6 3 2 4 T i m e r A L o w - B y t eD C 0 5 5 6 3 2 5 T i m e r A H i g h - B y t eD C 0 6 5 6 3 2 6 T i m e r B L o w - B y t eD C 0 7 5 6 3 2 7 T i m e r B H i g h - B y t eD C 0 8 5 6 3 2 8 T i m e - o f - D a y C l o c k : i / 1 0 S e c o n d sD C 0 9 5 6 3 2 9 T i m e - o f - D a y C l o c k : S e c o n d sD C 0 A 5 6 3 3 8 T i m e - o f - D a y C l o c k : M i n u t e sD C 8 B 5 6 3 3 1 T i m e - o f - D a y C l o c k : H o u r s A M / P M F l a g ( B i t 7 D C O C 5 6 3 3 2 S y n c h r o n o u s S e r i a l 1 / D a t a B u f f e rD C 0 D 5 6 3 3 3 C I I n t r p t C t r l R e ( R e a d I R Q s / W r i t e M a s k )D C O E 5 6 3 3 4 C I C o n t r o l R e g i s t e rD C C F 5 6 3 3 5 C I C t r l R e i a l a r m , 0 = C l o c kD D 0 0 5 6 5 7 6 D a t a P o r t ( S e r i a l B u s , R S - 2 3 2 , M e m C t r l )D D 0 1 5 6 5 7 7 D a t a P o r t ( U s e r P o r t , R S - 2 3 2 )D D 0 2 5 6 5 7 8 D a t a D i r e c t i o n R e g i s t e r - P o r tD D 0 3 5 6 5 7 9 D a t a D i r e c t i o n R e g i s t e r - P o r tD D 0 4 5 6 5 8 0 T i m e r A L o w - B y t eD D 0 5 5 6 5 8 1 T i m e r A H i g h - B y t eD D 0 6 5 6 5 8 2 T i m e r B L o w - B y t eD D 0 7 5 6 5 8 3 T i m e r B H i g h - B y t eD D 0 8 5 6 5 8 4 T i m e - o f - D a y C l o c k : i / i e S e c o n d sD D 0 9 5 6 5 8 5 T i m e - o f - D a y C l o c k : S e c o n d sD D 0 A 5 6 5 8 6 T i m e - o f - d a y C l o c k : M i n u t e sD D 0 B 5 6 5 8 7 T i m e - o f - D a y C l o c k : H o u r s A M / P M F l a g ( B i t 7 D D 0 C 5 6 5 8 8 S y n c h r o n o u s S e r i a l 1 / D a t a B u f f e rD D 0 C 5 6 5 8 9 C I I n t r p C t r l R e ( R e a d N M I s / W r i t e M a s k )D D 0 E 5 6 5 9 0 C I C t r l R e g . A T O C l o c k F r e q i = 5 0 H z » 0 = 6 0 H zD D 0 F 5 6 5 9 1 C I C t r l R e i = A l a r m , 0 = C l o c kE 0 0 0 5 7 3 4 4 - 6 5 5 3 5 K E R N A L R O E 0 4 3 5 7 4 1 1 S e r i e s e v a l u a t i o n

Page 155: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 155/172

I n s i d e T h C o m m o d o r e 6 P a g e D - 1 3

H e

E 0 3 DE 0 9 7E 2 6 4E 2 6 BE 2 B 7E 2 E 9E 3 0 DE 3 3 EE 3 9 4E 3 A 2E 3 B FE 4 5 FE 4 A DE 5 0 5E 5 6 AE 5 1 8E 5 3 1E 5 4 4E 5 6 6E 5 6 CE 5 A 6E 5 A 8E 5 B 4E 6 3 2E 6 8 4E 6 9 1E 6 B 6E 6 F 7E 7 0 1E 7 1 6E 8 7 CE 8 9 1E 8 A 1E 8 B 3E 8 C BE 8 D AE 8 E 2E 8 E 7

D e c i m a l

5 7 5 7 4 9 55 7 9 5 65 7 9 6 35 8 0 3 95 8 0 8 05 8 1 2 55 8 1 7 45 8 2 6 05 8 2 7 45 8 3 0 35 8 4 6 35 8 5 4 15 8 6 2 95 8 6 3 45 8 6 4 85 8 6 7 35 8 6 9 25 8 7 2 65 8 7 3 25 8 7 8 45 8 7 9 25 8 8 0 45 8 9 3 05 9 0 1 25 9 0 2 55 9 0 6 25 9 1 2 75 9 1 3 75 9 1 5 95 9 5 1 65 9 5 3 75 9 5 5 35 9 5 7 15 9 5 9 55 9 6 1 05 9 6 1 85 9 6 2 4

F u n c t i o n

R N c o n s t a n t sP e r f o r m R N P e r f o r m C O P e r f o r m S I NP e r f o r m T A C o n s t a n t s f o t r i g f u n c t i o n sP e r f o r m A T C o n s t a n t s f o A T I n i t i a l i z e R A v e c t o r sC H R G E T f o z e r o p a g eI n i t i a l i z e B A S I CM e s s a g e sP r o g r a m p a t c h a r e aS e t s c r e e n l i m i t sT r a c k c u r s o r l o c a t i o nI n i t i a l i z e I / N o r m a l i z e s c r e e nC l e a r s c r e e nH o m e c u r s o rS e s c r e e n p o i n t e r sS e I / d e f a u l t sS e v i c h i p d e f a u l t sI n p u t f r o m k e y b o a r dI n p u t f r o m s c r e e nQ u o t e m a r k t e s tS e u s c r e e n p r i n tA d v a n c e c u r s o rR e t r e a t c u r s o rB a c k i n t o p r e v i o u s l i n eO u t p u t t s c r e e nG t n e x t l i n eD o ' R E T U R N 'C h e c k l i n e d e c r e m e n tC h e c k l i n e i n c r e m e n tS e c o l o u r c o d eC o l o u r c o d e t a b l eC o d e c o n v e r s i o nS c r o l l s c r e e n

Page 156: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 156/172

I n s i d e T h C o m m o d o r e 6 P » g t D - 1 4

H e

E 9 6 5E 9 C 8E 9 E 0E 9 F 0E 9 F FE A 1 3E A 1 CE A 2 4E A 3 1E A 8 7E B 5 9E B 7 9E B 9 1E C 4 4E C 4 FE D 9 9E D 9 CE D 1 1E D 3 6E D B 6E D B 9E D B EE D C ?E D D DE D E FE D F EE E 1 3E E 8 5E E 8 EE E B 3E E B BE F 6 6E F 2 EE F 4 AE F 5 9E F 7 ' EE F C 5E F C A

D e c i m a l

5 9 7 4 95 9 8 4 85 9 8 7 25 9 8 8 85 9 9 0 35 9 9 2 35 9 9 3 25 9 9 4 05 9 9 5 36 0 0 3 96 0 2 4 96 0 2 8 16 0 3 0 56 0 4 8 46 0 4 9 56 0 6 8 16 0 6 8 46 0 6 8 96 0 7 2 66 0 8 4 86 0 8 5 76 0 8 6 26 0 8 7 16 0 8 9 36 0 9 1 16 0 9 2 66 0 9 4 76 1 6 6 16 1 0 7 06 1 1 6 76 1 1 1 56 1 1 9 06 1 2 3 06 1 2 5 86 1 2 7 36 1 3 1 66 1 3 8 36 1 3 8 6

F u n c t i o n

O p e n s p a c e o s c r e e nM o v e s c r e e n l i n eS y n c h c o l o u r t r a n s f e rS e t s t a r t - o f - l i n eC l e a r s c r e e n l i n eP r i n t t s c r e e nS t o r e o s c r e e nS y n c h c o l o u r t o c h a rI n t e r r u p t ( I R Q )C h e c K k e y b o a r dS e t t e x t m o d eK e y b o a r d v e c t o r sK e y b o a r d m a p sG r a p h i c s / t e x t c o n t r o lS e t g r a p h i c s m o d eS e n d ' t a l k 'S e n d ' l i s t e n 'S e n d c o n t r o l c h a rS e n d t o s e r i a l b u T i m e o u t o s e r i a lS e n d l i s t e n S C l e a r A T S e n d t a l k S S e n d s e r i a l d e f e r r e dS e n d ' u n t a l k 'S e n d ' u n l i s t e n 'R e c e i v e - f r o m s e r i a l b u C l o c k l i n e o C l o c k l i n e o D e l a y m R S 2 3 2 s e n d ( N M DN e R S 2 3 2 b y t e s e n dE r r o r o q u i tC o m p u t e b i c o u n tR S 2 3 2 r e c e i v e ( N M DS e t u p t r e c e i v eR e c e i v e p a r i t y e r r o rR e c e i v e o v e r r u n e r r o r

Page 157: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 157/172

I n s i d t T h C o m m o d o r t 6 P t g t D - 1 3

H e

E F C DE F D 9E F E 1F 8 1 7F 0 4 DF 0 8 6F 9 A 4F 0 B DF i 2 BF 1 3 EF 1 4 EF 1 5 7F 1 9 9F 1 C BF 1 D DF 2 0 EF 2 5 0F 2 9 1F 3 0 FF 3 1 FF 3 2 FF 3 3 3F 3 4 AF 3 D 5F 4 0 ?F 4 9 EF 5 A FF 5 B 8F 5 D 2F 5 D DF 6 8 FF 6 9 BF 6 D DF 6 E 4F 6 E DF 6 F BF 7 2 CF 7 6 A

D e c i m a l

6 1 3 8 96 1 3 9 26 1 4 8 96 1 4 6 36 1 5 1 76 1 5 7 46 1 6 0 46 1 6 2 96 1 7 3 96 1 7 5 86 1 7 7 46 1 7 8 36 1 8 4 96 1 8 9 96 1 9 1 76 1 9 6 66 2 0 3 26 2 0 9 76 2 2 2 36 2 2 3 96 2 2 5 56 2 2 5 96 2 2 8 26 2 4 2 16 2 4 7 36 2 6 2 26 2 8 9 56 2 9 0 46 2 9 3 06 2 9 4 16 3 1 1 96 3 1 3 16 3 1 9 76 3 2 0 46 3 2 2 76 3 2 2 76 3 2 7 66 3 3 3 8

F u n c t i o n

R e c e i v e b r e a k e r r o rR e c e i v e f r a m e e r r o rF i l e t o R S 2 3 2S e n d t R S 2 3 2 b u f f e rI n p u t f r o m R S 2 3 2 b u f f e rG e t f r o m R S 2 3 2 b u f f e rC h e c k s e r i a l b u i d l eM e s s a g e sP r i n t i d i r e c tG e t . .. . f r o m R S 2 3 2I n p u tG e t . . t a p e / s e r i a l / R S 2 3 2O u t p u t . .. . t o t a p eS e i n p u t d e v i c eS e o u t p u t d e v i c eC l o s eF i n d f i l eS e f i l e v a l u e sA b o r t a l f i l e sR e s t o r e d e f a u l t I / D f i l e o p e n i n gS e n d S O p e n R S 2 3 2L o a d p r o g r a m' S E A R C H I N G 'P r i n t f i l e n a m e' L O A D I N G / V E R I F Y I N G 'S a v e p r o g r a m' S A V I N G 'B u m p d o c kG e t i m eS e t t i m eA c t i o n s t o p k e F i l e E r r o r M e s s a g e sF i n d a n y t a p e h e a d e rW r i t e t a p e h e a d e r

Page 158: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 158/172

I n s i d e T h C o m m o d o r e 6 P a g e D - 1 6

H e

F 7 D 8F 7 D 7F 7 E AF 8 8 DF 8 1 7F 8 2 EF 8 3 8F 8 4 1F 8 6 4F 8 7 5F 8 D 8F 8 E 2F 9 2 CF A 6 8F D 8 EF B 9 7F B A 6F B C 8F B C DF C 5 7F C 9 3F C B 8F C C AF C D 1F C D BF C E 2F D 8 2F D 1 3F D 5 2F D 9 BF D A 2F D F 9F E 0 9F E 0 7F E 1 8F E 2 1F E 2 5F E 3 4

D e c i m a l

6 3 4 4 06 3 4 4 76 3 4 6 66 3 5 0 16 3 5 1 16 3 5 3 46 3 5 4 46 3 5 5 36 3 5 8 86 3 6 0 56 3 6 9 66 3 7 1 46 3 7 8 86 4 0 9 66 4 3 9 86 4 4 8 76 4 4 2 26 4 4 5 66 4 4 6 16 4 5 9 96 4 6 5 96 4 6 9 66 4 7 1 46 4 7 2 16 4 7 3 16 4 7 3 86 4 7 7 06 4 7 8 76 4 8 5 06 4 9 2 36 4 9 3 06 5 0 1 76 5 0 2 46 5 0 3 16 5 0 4 86 5 9 5 76 5 0 6 16 5 6 7 6

F u n c t i o n

G e b u f f e r a d d r e s sS e t b u f f e r s t a r t e n p o i n t e r sF i n d s p e c i f i c h e a d e rB u m p t a p e p o i n t e r' P R E S S P L A Y 7C h e c k c a s s e t t e s t a t u s' P R E S S R E C O R D 'I n i t i a t e t a p e r e a dI n i t i a t e t a p e w r i t eC o m m o n t a p e r e a d / w r i t eC h e c k t a p e s t o pS e t i m i n gR e a d b i t s ( I R Q )S t o r e c h a r a c t e r sR e s e t p o i n t e rN e t a p e c h a r a c t e r s e t u pT o g g l e t a p eD a t a w r i t eT a p e w r i t e ( I R Q )L e a d e r w r i t e ( I R Q )R e s t o r e v e c t o r sS e t v e c t o rK i l l m o t o rC h e c k r e a d / w r i t e p o i n t e rB u m p r e a d / w r i t e p o i n t e rP o w e r u p e n t r yC h e c k A - r o mS e k e r n a lI n i t i a l i z e s y s t e m c o n s t a n t sI R v e c t o r sI n i t i a l i z e I / O r e g sS a v e d a t a n a m eS a v e - f i l e d e t a i l sG e s t a t u sF l a g S S e t i m e o u tR e a d / s e t t o m e m o r yR e a d / s e t b o t t o m o - m e m o r y

Page 159: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 159/172

I n t i d t T h C o m m o d o r t 6 P * g t D - 1 7

H e D e c i m a l F u n c t i o n

F E 4 3F E 6 6F E B CF E C 2F F 4 8F F 8 1F F F A

6 5 0 9 16 5 1 2 66 5 2 1 26 5 2 1 86 5 3 5 26 5 4 8 96 5 5 3 0

N M i n t e r r u p t e n t r yR E S E T / S T O P w a r m s t a r tR e s t o r e & e x i tR S 2 3 2 t i m i n g t a b l eM a i n I R e n t r yJ u m b o j u m p t a b l eH a r d w a r e v e c t o r s

Page 160: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 160/172

I n s i d e T h C o m m o d o r e 6 P a g e E -

S a m p l e B i t - M a p p e d p l o t t i n gT h f o l l o w i n g p r o g r a m s a r a n e x a m p l e o m a c h i n e l a n g u a g e

s u b r o u t i n e * c a l l a b l e b e i t h e r B A S I C o m a c h i n e l a n g u a g e * a n B A S I Cp r o g r a m w h i c h u s e s t h r o u t i n e . T h m a c h i n e l a n g u a g e p r o g r a m i d e s i g n e d t o t u r n o i n d i v i d u a l p i x e l s b a s e d o n a n b i t - p o s i t i o np a s s e d f r o m t h c a l l i n g r o u t i n e . T h r o u t i n e a s s u m e s t h a t t h ec o o r d i n a t e o f t h e p o i n t t b p l o t t e d i s t o r e d i 2 5 3 * 2 5 4 . L o c a t i o n2 5 m u s t c o n t a i n t h e h i g h - o r d e r b i o f t h e n u m b e r a n 2 5 t h l o w -o r d e r e i g h t b i t s . T h v a l u e m a r a n g e f r o m t 3 1 9 . T h y c o o r d i n a t e m u s t b s t o r e d i l o c a t i o n 2 5 5 . T h v a l u e m a r a n g e f r o m0 t 1 9 9 . T h u p p e r l e f t c o r n e r o t h s c r e e n i c o n s i d e r e d b i p o s i t i o n 0 * a n t h l o w e r r i g h t i p o s i t i o n 3 1 9 * 1 9 9 . T h c a r r y b i i u s e d a s m o d e s w i t c h . I i p a s s e d t t h M p r o g r a m f r o m B A S I Cb s e t t i n g t h e l o w - o r d e r b i o l o c a t i o n 7 8 3 . T h i s i t h e l o c a t i o n o t h p r o c e s s o r s t a t u s r e g i s t e r w h e n c o m m u n i c a t i n g t m a c h i n e l a n g u a g ep r o g r a m s v i S Y S . I t h e c a r r y b i i s e t h M p r o g r a m w i l l s e t h s p e c i f i e d b i o t h s c r e e n t o t h e f o r e g r o u n d c o l o r . I c l e a r *t h c o l o r o t h b i t w i l l b e s e t t t h b a c k g r o u n d c o l o r . T h B A S I C p r o g r a m w h i c h c a l l s t h p l o t r o u t i n e m u s t f i r s t c a l l t h i n i t i a l i z a t i o n r o u t i n e w h i c h w i l l s e t h s c r e e n l o c a t i o n * c l e a r t h s c r e e n a n t h c o l o r m e m o r y . T h i s s i m p l e B A S I C p r o g r a m p l o t ss i n u s o i d a l p a t t e r n .T h B A S I C p r o g r a m :

1 S Y 4 9 3 2 32 f o t i o o o s t e p . 0 5 : y i e e + 4 s i < x 3 X X 3 0 P O K E 2 5 4 * X P A N 2 5 5 : P O K E 2 5 3 * X P / 2 5 64 P O K E 2 5 5 * Y : P O K E 7 8 3 * 1 : S Y 4 9 2 3 1 : N E X TT h m a c h i n e l a n g u a g e p r o g r a m :

Page 161: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 161/172

I n s i d e T h C o m m o d o r e P a g e B -

P L O T S U B R O U T I N E SB T O C O U R T

L W A D R E Q 2 5 H I A D R E Q 2 5 C U R H X E Q U 2 5 3C U R L X E Q 2 5 C U R Y E Q 2 5 1 T E M P E Q

1 C H A R M E M E Q U * E 0 0 01 S C R E E N E Q U * C 4 0 01 I R Q C T R L E Q 5 6 3 3 41 R O M S W C H E Q 1 B A N K E Q 5 6 5 7 61 B I T M O D E E Q 5 3 2 6 51 S C R N P O S E Q U 5 3 2 7 21 1 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 S T R A D R E Q * C 0 0 03 L D * » 3 S T + T E M P3 S T * H I A D R4 L D 4 - C U R Y

A D D R E S S P O I N T E RC O O R D I N A T E O P L O T

R A N G E < 0 - 3 1 9 )C O O R D I N A T E ( 0 - 1 9 9 )

B I M A O S C R E E N

S T R A D R O U T I N EC O N V E R T X , C O O R D O P L O T T

A D D R E S S O B Y T E T M O D I F Y I B I T - M A P P E D C H A R M E M O R YX - C O O R D M U S T B S T O R E D I C U R X

( 9 - B I T V A L U E G O E S I T W B Y T E S )Y - C p O R D M U S T B I C U R YO R E T U R N X - R E 6 C O N T A I N S 0 -

( B Y T E W I T H I N 8 - B Y T E B L O C K )

Y - R E G C O N T A I N S B I P O S I T I O NW I T H I N T H B Y T E T M O D I F Y

Page 162: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 162/172

I n i i d t T h C o m m o d o r t 6 P t g t B -

4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 8

A N # * F 8 Y = 8 * I N T < Y / 8 >T M U L T B 4 0

F I R S T M I U L T B 3 ( 5 - B I T S H I F T L T H E NT H E N

A S R O A S R O A S R O A S R O A S R O S T L D A N A S R O A S R O A S R O C L A D S T L D A D S T L D A N

M U L T I B < 3 - B I T L E F T )A D T H T W T O G E T H E R

* H I A D R* H I A D R+ H I A D R* H I A D R* H I A D R* L W A D R* C U R Yt t * F 8

* T E M P+ T E M P♦ • T E M P

* L W A D R* L W A D R* T E M P< - H I A D R< - H I A D R♦ - C U R L X# * F 8 X = 8 * I N T < X / 8 >

$ P O S I T I O N = 4 0 * < 8 * I N T < Y / 8 > * 8 + I N T < X / 8 > >

C L A D S T

< - L U I A D R< - L W A D R

Page 163: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 163/172

I n i l d i T h C o m m o d o r e P a g f B - 4

8 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 9 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2

D O

L D A D

A D D RO R S T L D A N T A L D A N T A R T

D R A WC A R R Y

* C U R H X+ H I A D R

P O S I T I O N I

# > C H A R M E M* H I A D R< - C U R Y#

* C U R L X#

E N T R Y P O I N TS E T O

P L O T ( S E T ) U N P L O TC U R X ,

P H J S L D A N S T L D A N S T P L B C L D O R S T J M

U N D R A W L D E O A N S T

M A S T R T O M A

P O I B L O C K < A N B I P O S « < A N 7

R E T U R N T D O

< C L E A R )C U R Y M U S T C O N T A I N X , Y C O O R D

S T R A D RI R Q C T R L# * F E

R Q C T R L* R O M S W C Ht t * F D* R O M S W C HU N D R A W< L W A D R ) , Y

T A B L , X( L W A D R ) , YS K P U N DT A B L , X# * F F< L W A D R ) , Y< L W A D R ) , Y

G E B I T - M A P A D D R T T U R N O F I R Q ' S

S W I T C H O U T H R O

T E S T C A R R YG E B Y T E T M O T U R N O S E L E C T E D D O

T U R N D O O F R E V E R S E A L L B I T S

Page 164: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 164/172

I n t i d t T h C o m m o d o r t 4 P t g t E - S

1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 6

S K P U N D L D < - R O M S W C HO R # S T < - R O M S W C HL D A I R Q C T R LO R # S T A I R Q C T R LR T

; C O L O R S E T R O U T I N E

8 R I N G B A C K R O

E N A B L E T H I R Q ' S

S E T S S C R E E N C O L O R SA - A R E G M U S T H A V E F G R N D C O L O R

I H I G H 4 - B I T S .B K G R N D I L O W - 4 B I T S .

C O L O R L D # 2 5 0L O P C O L D E

S T S C R E E N , XS T S C R E E N * 2 5 0 , XS T S C R E E N + 5 0 0 , XS T S C R E E N * 7 5 0 , XB N L O P C O LR T

S E C O U N T

C L C L E A R S E N T I R E H I R E S S C R E E N

L O P O U TL O P I N

L D # S T < - L W A D RL D # > C H A R M E MS T * H I A D RL D # D E S T ( L W A D R ) , YB N E L O P I NI N B N L O P O U TR T

I N I T R O U T I N E

G E S T A R T I N G P A G E

S T O R E A

C O N T I N U E T I L L D O N E

Page 165: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 165/172

I n s i d e T h C o m m o d o r e 4 P t g e B -

1 6 1 6 1 6 1 6 1 6 1 6 1 6 1 6 1 6 1 7 1 7 1 7 1 7 1 7 1 7 1 7 1 7 1 7 1 7 1 8 1 8 T A B L

T U R N S O T H E G R A P H I C S M O D E ,C L E A R S T H S C R E E NS E T S F O R E G R O U U N D W H I T EA N B K G R N D B L A C K

L D B A N K + 2O R A # 3S T B A N K + 2L D B A N KA N # $ F CS T B A N KL D B I T M O D EO R # 3 S T B I T M O D EL D A # $ 1 8S T S C R N P O SL D A # $ 1 0J S C O L O RJ M C L

S E B A N K P O R T T O U T P U T

A N D T H E V I D E O B A N K T

S E C H A R M E M T O E 0 0 0 - F F F FA N S C R E E N T $ C 0 0 0S E C O L O R SC L E A R S C R E E N A N R E T U R N

B Y $ 8 0 4 0 2 0 1 0 0 8 0 4 0 2 0 1

Page 166: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 166/172

I n s i d e T h C o m m o d o r e 6 4 P * 9 * B -

E x p l a n a t i o n :

T h s c r e e n h a 2 r o w s o 4 c h a r a c t e r s e a c h . E a c h c h a r a c t e rh a e i g h t r o w s o f e i g h t d o t s e a c h . T h c h a r a c t e r m e m o r y i w h e r e t h - h i - r e s b i m a o f t h e s c r e e n r e s i d e s . T h e r e a r 8 0 0 0 b y t e s o s c r e e ni n f o r m a t i o n c o n t a i n e d t h e r e . T h i s b r e a k s d o w n t 4 c o l u m n s * 2 r o w s

b y t e s p e c h a r a c t e r . T h f i r s t e i g h t b y t e s o c h a r m e c o n t a i nt h b i m a o t h u p p e r l e f t s q u a r e o 6 d o t s a r r a n g e d i a e i g h tb e i g h t a r r a y . T h e r e a r t h e r e f o r e 4 0 o 3 2 b y t e s t m a t h f i r s t e i g h t r o w s o d o t s . T h s e c o n d 3 2 0 b y t e s i c h a r a c t e r m e m o r yr e f e r e n c e t h s e c o n d r o o c h a r a c t e r s r o w s o f a c t u a l d o t s ) .S o b l o c k # i t h e p a t t e r n f o t h u p p e r l e f t e i g h t b e i g h t b l o c k o fd o t s a n b l o c k # i t h b l o c k t o t h r i g h t o f t h a t a n b l o c k # 4 i t h p a t t e r n o d o t s f o t h b l o c k b e l o w i a n s f o r t h t i l l b l o c k# 1 0 0 0 w h i c h d e s c r i b e s w h i c h p i x e l s w i l l b i l l u m i n a t e d i t h b o t t o mr i g h t c o r n e r o f t h e s c r e e n .

T h a b o v e m a c h i n e l a n g u a g e s u b r o u t i n e c o m p u t e s w h i c h b l o c kc o r r e s p o n d s t a n g i v e n a n d o c o o r d i n a t e . I a l s o c o m p u t e sw h i c h b y t e w i t h i n t h e e i g h t - b y t e b l o c k h o l d s t h e d o t i q u e s t i o n a n w h i c h b i p o s i t i o n w i t h i n t h a t b y t e t o t u r n o o o f f .

T h Y - c o o r d i n a t e r e p r e s e n t s h o f a f r o m t h t o o f t h e s c r e e nt h d o i l o c a t e d . I i i s i n t h r a n g e o 0 - 7 , t h e d o i s i n t h f i r s t r o o f c h a r a c t e r s . I i s i s 8 - 1 5 , i i s i n t h s e c o n d r o w , e t c .S t f i n d t h r o m u s t b d i v i d e d b 8 d i s c a r d i n g a n r e m a i n d e r .E a c h r o o c h a r a c t e r s c o n t a i n s 4 b l o c k s a c r o s s t h s c r e e n a n d e a c hb l o c k c o n t a i n s e i g h t b y t e s o d a t a . S o f o e v e r y r o w , t h e p o s i t i o nw i t h i n t h t a b l e i n c r e a s e s b t i m e s 4 o r 2 0 0 .

T h a d d r e s s o t h e a p p r o p r i a t e b y t e o f t h e t a b l e t m o d i f y i b u i l t i t h t w o - b y t e f i e l d l a b e l e d L W A D R a n H I A D R . S T A D R i t h r o u t i n e w h i c h c o m p u t e s t h a d d r e s s o t h b l o c k t o m o d i f y . I a l s or e t u r n s w i t h t h r e l a t i v e b y t e w i t h i n t h e b l o c k i t h X - r e g a n t h b i w i t h i n t h a t b y t e t m o d i f y i t h Y - r e g . T h o n l y t h i n gr e m a i n i n g i t g e t h a c t u a l b i w i t h i n t h e b y t e a n e i t h e r t u r n i o o r o f f a i n d i c a t e d b t h m o d e s w i t c h i l o c a t i o n 0 T h i s i d o n ei t h m a i n l i n e o f t h D O r o u t i n e .

Page 167: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 167/172

I n s i d e T h C o m m o d o r e 6 4 P a g e F - i

A p p e n d i x D a t aB i t s . B i n a r y d i g i t s . I t s a c t u a l l y c o n t r a d i c t i o n i t e r m s .

B i n a r y m e a n s i c a h a v e t w p o s s i b l e v a l u e s . D i g i t i m p l i e s t e n .T h b i t i s t h m o s t b a s i c u n i t o f i n f o r m a t i o n . I i t h

f o u n d a t i o n o a l o t h e r m o r e c o m p l e x i n f o r m a t i o n f o r m a t s . I i t h o n l y k i n d o i n f o r m a t i o n w h i c h m a b e s t o r e d i " d i g i t a l " c o m p u t e r .

b i m a h a v e t h e v a l u e o f e i t h e r o n o z e r o . b y t e i g r o u p i n go f e i g h t b i t s . T h 6 5 1 0 i c a l l e d a e i g h t - b i t m i c r o p r o c e s s o r . T h i si b e c a u s e i p r o c e s s e s a n d s t o r e s d a t a e i g h t b i t s a t i m e . I i m o r e c o n v e n i e n t f o t h p u r p o s e o u n d e r s t a n d i n g t h e n a t u r e o c o m p u t e r d a t a t b r e a k t h e e i g h t b i t s i n t o t w f o u r b i s e c t i o n s ,c a l l e d n y b b l e s .

T h e r e a r e x a c t l y s i x t e e n u n i q u e f o u r - b i t c o m b i n a t i o n s o o n e sa n z e r o s s u c h t h a t n t w a r r a n g e m e n t s a r a l i k e . T h e r e i c o m m o ns h o r t h a n d n o t a t i o n f o r i d e n t i f y i n g t h e s e s i x t e e n p a t t e r n s . I g o e sl i k e t h i s :

8 4 2 1 8 4 2 1 8 4 2 1 8 4 2 1

8 6 8 8 = 8 8 1 8 8 = 4 1 8 8 8 = 8 1 1 8 8 = C8 8 8 1 = 1 8 1 8 1 = 5 1 8 8 1 = 9 1 1 8 1 = D8 8 1 8 = 2 8 1 1 8 = 6 1 8 1 8 = A 1 1 1 8 = E8 8 1 1 = 3 8 1 1 1 = 7 1 8 1 1 = B 1 1 1 1 = F

I t ' s c o n v e n i e n t s h o r t h a n d s y s t e m b e c a u s e i i e a s y t r e m e m b e r . I s i m p l y n u m b e r s t h p a t t e r n s f r o m t 1 5 e x c e p t * i k e e p i n g w i t h t h e i d e a o u s i n g o n c h a r a c t e r c o d e f o e a c h p a t t e r n *t h n u m b e r s 1 8 - 1 5 a r c a l l e d A - F . S o p a t t e r n 1 i c a l l e d " C a n i s i " F " , e t c . I t ' s g o a n o t h e r a d v a n t a g e t o o . T h s h o r t h a n d l a b e ls y s t e m h a s a n o r d e r w h i c h m a k e s i e a s y t r e m e m b e r . I t h l e f t - m o s tb i p o s i t i o n m a b e c o n s i d e r e d t h a v e t h e v a l u e o f 8 a n t h n e x tp o s i t i o n , t h e v a l u e 4 a n t h n e x t , 2 a n t h l a s t , o n e : t h e n t h b i p a t t e r n s m a b c o n v e r t e d t t h e i r l a b e l s b y a d d i n g t h b i v a l u e so f t h e i n d i v i d u a l b i p o s i t i o n s . F o e x a m p l e : i e i e h a i t h p o s i t i o n , a i t h 4 p o s i t i o n , i t h p o s i t i o n , a n i t h

p o s i t i o n . S i t l a b e l i " A b e c a u s e 1 a n " A i t h c o d e f o 1 0 L i k e w i s e , 0 1 1 0 i l a b e l e d " 6 b e c a u s e i h a s n o 8 o n

Page 168: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 168/172

I n s i d e T h C o m m o d o r e 6 P a g e F -

4 o n a n n 1 T h l e f t m o s t b i p o s i t i o n i c a l l e d t h e " m o s t - s i g n i f i c a n t " b i

b e c a u s e i h a t h g r e a t e s t b i v a l u e . I i a l s o c a l l e d t h " h i g h -o r d e r " b i t . L i k e w i s e * t h r i g h t m o s t b i i t h " l e a s t s i g n i f i c a n t " o " l o w - o r d e r b i t " .

N o t e t h a t a l t h o d n u m b e r s h a v e o n i t h r i g h t m o s t b i p o s i t i o n . A l t h e v e n n u m b e r s * z e r o .

Y o c a n o s e t h a t t h e s h o r t h a n d n o t a t i o n f o i d e n t i f y i n gf o u r b i d a t a f i e l d i s v e r y l o g i c a l a n i i n o t h a r d t c o n v e r t b a c ka n f o r t h b e t w e e n t h b i p a t t e r n s a n t h p a t t e r n c o d e . T h i s i i m p o r t a n t b e c a u s e a m a c h i n e l a n g u a g e p r o g r a m m e r s ! w h a v e t e n u w o r k i n g l o w i t h b i t s . T h i s i b e c a u s e t h 6 5 1 6 a n d a l o f t h em e m o r y d e v i c e s s t o r e a n w o r k w i t h a l d a t a c o d e d a b i t s .

T h a d d r e s s e s o w h e r e d a t a i l o c a t e d w i t h i n m e m o r y d e v i c ei l i k e w i s e r e p r e s e n t e d a n d t r a n s f e r r e d o t h a d d r e s s b u i b i t s .

N o w , s i n c e d a t a i s t o r e d a n r e t r i e v e d t o a n f r o m t h m e m o r yd e v i c e s e i g h t b i t s a a t i m e ( c a l l e d a b y t e o d a t a ) , i t a k e s t w s h o r t h a n d c o d e s t d e s c r i b e t h b i c o n t e n t o t h d a t a . b y t e o d a t a w h i c h h a b i s t r u c t u r e o 1 1 0 0 0 1 6 8 w o u l d b i d e n t i f i e d a h a v i n g t h t w o - c h a r a c t e r c o d e o " C 4 " . T h b i s t r u c t u r e o t h c o d ef o t h l e t t e r " A w o u l d b " 4 1 " b e c a u s e t h b i p a t t e r n a s s i g n e d t " A i t h A S C I I c o d i n g s c h e m e i 0 1 6 6 6 6 6 1 . I t ' s h e l p f u l t s i w i t h

p e n c i l a n p a p e r a n w r i t e o u b i p a t t e r n s a n d f i g u r e o u w h a tt h e i r c o d e s a r e . Y o s h o u l d a l s o s t a r t w i t h t h c o d e s 6 - a n d c o n v e r tb a c k t b i p a t t e r n s .

T h a t t h e r e a r 2 5 w a y s t r e p r e s e n t e i g h t b i t s i o b v i o u sf r o m t h f a c t t h a t t h e r e a r s i x t e e n p o s s i b l e f i r s t c h a r a c t e r s o t h t w c h a r a c t e r c o d e w h i c h i d e n t i f i e s a e i g h t - b i t p a t t e r n a n s i x t e e np o s s i b l e s e c o n d c h a r a c t e r s . A n 1 t i m e s 1 2 5 6 . I w w a n t e db y t e o d a t a t r e p r e s e n t n u m e r i c v a l u e i n s t e a d o a n A S C I I c o d e dc h a r a c t e r , w c a n s e e t h a t i c o u l d r e p r e s e n t a n y v a l u e b e t w e e n a n 2 5 5 . T h 6 5 1 6 d o e s , i n f a c t * s o m e t i m e s t r e a t d a t a a i f i t i n u m e r i ci n s t e a d o c h a r a c t e r d a t a . U s i n g t h s a m e t w o - c h a r a c t e r c o d e t i d e n t i f y a b i p a t t e r n , w c a c o n v e r t b e t w e e n t h n u m e r i c v a l u ea n t h t w o - c h a r a c t e r c o d e q u i t e e a s i l y . F o e x a m p l e , t c o n v e r t f r o m" A 6 " t i t n u m e r i c v a l u e , w w o u l d m u l t i p l y 1 t i m e s 1 ( " A " 1 a n d a d d t o g i v e 1 6 6 . L i k e w i s e , t c o n v e r t " 4 F " t n u m e r i c w w o u l dm u l t i p l y t i m e s 1 a n a d 1 ( " F " 1 t o g i v e 7 9 I t ' s e a s y t s e t h a t t h m a x i m u m v a l u e o f " F F " = 1 t i m e s 1 6 , ( 2 4 6 ) p l u s 1 t g i v e 2 5 5 . O c o u r s e , t h e m i n i m u m w o u l d b " 6 6 " w h i c h i ( t i m e s 1 6

Page 169: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 169/172

I n s i d e T h C o m m o d o r e 6 P a g e F -

p l u s 0 H o a b o u t g o i n g t h o t h e r w a y ? I w w a n t t c r e a t e t h b i

p a t t e r n f o s o m e n u m b e r i t h r a n g e o 2 5 5 * w o n l y h a v e t d i v i d e t h n u m b e r b 1 t g e t h f i r s t c h a r a c t e r o t h c o d e< r e m e m b e r t t r a n s l a t e 1 t h r u 1 5 t o t h r u F > T h e n t h r e m a i n d e r o t h d i v i s i o n i t h s e c o n d c h a r a c t e r . N o t g e t t h e b i p a t t e r n w J u s t l o o k i u i t h l i t t l e b i p a t t e r n t a b l e . P u t h f i r s t f o u r -b i p a t t e r n t o g e t h e r w i t h t h s e c o n d a n y o h a v e a n e i g h t b i p a t t e r nw h i c h r e p r e s e n t s t h n u m e r i c v a l u e . N o h a r d a a l l . L e t s t r i w i t h f e n u m b e r s . T a k e t h n u m b e r 1 6 9 . H o m a n y t i m e s d o e s 1 g i n t o 1 6 9 ? R i g h t . A n d h o w i t h a t r e p r e s e n t e d i o u s i n g l e c h a r a c t e rc o d e ? A t h l e t t e r " A " . T h r e m a i n d e r f r o m d i v i d i n g 1 6 b 1 i 9 S o u r c h a r a c t e r - c o d e r e p r e s e n t a t i o n o 1 6 i " A 9 " a n d i w g t t h b i p a t t e r n t a b l e * w w i l l s e t h a t t h b i p a t t e r n s a r 1 0 1 01 0 0 1 .

I i v a l u a b l e e x e r c i s e t p r a c t i c e c o n v e r t i n g b i p a t t e r n st c h a r a c t e r - c o d e s a n d f r o m c h a r a c t e r - c o d e s t d e c i m a l a n f r o md e c i m a l t c h a r a c t e r - c o d e s a n c h a r a c t e r - c o d e s t b i p a t t e r n s . Y o w i l l f i n d a t a b l e o f a l 2 5 b i p a t t e r n s a n t h c o r r e s p o n d i n gc h a r a c t e r - c o d e s a n c o r r e s p o n d i n g d e c i m a l v a l u e s i A p p e n d i x B Y o u m a y c h e c k y o u r s u c c e s s w i t h t h t a b l e .

T h c h a r a c t e r - c o d e s y s t e m f o i d e n t i f y i n g t h v a r i o u s b i p a t t e r n s i s a y o m i g h t k n o w o h a v e f i g u r e d o u t , w h a t i c o m p u t e rc i r c l e s i c a l l e d h e x a d e c i m a l . N u m b e r s * w h e n r e p r e s e n t e d i h e x a d e c i m a l * a r u s u a l l y p r o c e e d e d b " $ " . $ 4 i t h h e r e p r e s e n t a t i o n f o t h A S C I I c o d e f o r t h e l e t t e r " A " . T h i s r e m o v e sa n y q u e s t i o n a t w h e t h e r t h n u m b e r i d e c i m a l o h e x a d e c i m a l . F r o mn o o w w i l l f o l l o w t h a t c o n v e n t i o n i t h i s b o o k .

T h e r e i a n o t h e r c o n v e n t i o n w h i c h i w i d e l y u s e d t i d e n t i f yt h i n d i v i d u a l b i t s i a b y t e . T h b i t s a r n u m b e r e d 0 - 7 f r o m r i g h tt l e f t . T h h i g h - o r d e r b i i t h e 7 - b i t a n t h l o w - o r d e r b i t i s t h 0 - b i t .

W d i s c u s s e d t h w a t r e p r e s e n t t h d e c i m a l n u m b e r s f r o mt o 2 5 5 . T h s a m e g e n e r a l t e c h n i q u e m a b u s e d t r e p r e s e n t n u m b e r sf r o m t 6 5 5 3 5 . I n s t e a d o t w h e x c h a r a c t e r s r e p r e s e n t i n g o n b y t eo d a t a * w n e e d f o u r h e x c h a r a c t e r s r e p r e s e n t i n g s i x t e e n b i t s o t w b y t e s . N o t h f i r s t p a i r o h e c h a r a c t e r s m a b e f o l l o w e d b a n o 2 5 p a i r s o h e x c h a r a c t e r s $ 0 $ F ) S t h t o t a l n u m b e r o p o s s i b l e c o m b i n a t i o n s o f o u r h e x c h a r a c t e r s i 2 5 6 t i m e s 2 5 6 o 6 5 5 3 6 . T h a d d r e s s b u s i s i x t e e n b i t s w i d e . W h i c h i w h t h e r e a r e

Page 170: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 170/172

I m i d t T h C o m m o d o r t 6 4 P a g e F -

e x a c t l y 6 5 5 3 6 u n i q u e a d d r e s s e s p o s s i b l e . N o w , i i f r e q u e n t l y u s e f u lt b a b l e t o c o n v e r t d e c i m a l a d d r e s s e s i n t o h e x a d e c i m a l . W s a w h o wt d i w i t h s i n g l e b y t e o t w h e c h a r a c t e r s ( b i t s ) . W d i v i d e d t h e n u m b e r b 1 6 t o g e t h f i r s t c h a r a c t e r a n t h r e m a i n d e rw a t h s e c o n d c h a r a c t e r . T h p r o c e s s i s i m i l a r f o r g o i n g f r o mn u m b e r l a r g e r t h a n 2 5 5 .

W d i v i d e t h n u m b e r b 2 5 t o g e t t h f i r s t h a l f o f t h ea n s w e r . T h i s w i l l b n u m b e r b e t w e e n a n 2 5 5 . T h r e m a i n d e r w i l lb t h s e c o n d h a l f o f t h e a n s w e r . B o t h o t h e s e d e c i m a l n u m b e r s c a t h e n b e c o n v e r t e d t t h e i r h e x a d e c i m a l c o u n t e r p a r t s b y t h e d i v i d i n g -b y - 1 6 t e c h n i q u e . T h e s e h e d i g i t s c a b t h e n e a s i l y c o n v e r t e d t b i t s ( b i n a r y ) b l o o k i n g u t h t a b l e o r e t r i e v i n g i f r o m o u b i o l o g i c a l m e m o r y d e v i c e .

L e t ' s d o a n e x a m p l e : S a w w a n t t g e t h e b i n a r y v a l u e b i c o n f i g u r a t i o n o f t h e d e c i m a l n u m b e r 4 7 8 9 2 . T h f i r s t t h i n g w d i s e h o m a n y t i m e s 2 5 w i l l g i n t o 4 7 8 9 2 . T h e a n s w e r i 1 8 7 . T h r e m a i n d e r i 2 0 l i n e o B A S I C c o d e t d t h i s c o m p u t a t i o n w o u l db e

H I N N U 2 5 ) H N U H 2 5

H i t h f i r s t h a l f o f t h a n s w e r i d e c i m a l . H i t h s e c o n d h a l f . W s t i l l h a v e t t a k e 1 8 a n 2 a n d b r e a k t h e m i n t ot h e i r t w h e c o m p o n e n t s . W d t h i s b d i v i d i n g b 1 6 1 8 1 1 w i t h r e m a i n d e r o 1 1 S t h f i r s t t w h e d i g i t s a r $ B B . 2 1 w i t h a r e m a i n d e r o 4 S t h c o m p l e t e a n s w e r i $ B B 1 4 . T h eb i n a r y e q u i v a l e n t o $ B B 1 4 i 1 0 1 1 1 0 1 1 0 0 0 1 0 1 0 0 . T d o u b l e c h e c ko u a n s w e r , w g b a c k t h o t h e r d i r e c t i o n a n c o n v e r t $ B B 1 4 t d e c i m a l . $ 1 ( 1 6 ♦ 2 0 $ B B = 1 1 1 1 7 i = 1 8 7 . ( 1 8 7 2 5 2 4 7 8 7 2 + 2 4 7 8 9 2 . A n t h a t ' s t h n u m b e r w s t a r t e d w i t h . T h i s p r o c e s s s h o u l d b e p r a c t i c e d . I i v e r yh e l p f u l i s o l i d i f y i n g t h u n d e r s t a n d i n g o h e a n b i n a r y a n t h e i rr e l a t i o n s h i p s t o d e c i m a l n u m b e r s .

Page 171: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 171/172

I n s i d e T h C o m m o d o r e 6 P a g e F -

p l u s 0 H o a b o u t g o i n g t h o t h e r w a y ? I w w a n t t c r e a t e t h b i

p a t t e r n f o s o m e n u m b e r i t h r a n g e o 2 5 5 * w o n l y h a v e t d i v i d e t h n u m b e r b 1 t g e t h f i r s t c h a r a c t e r o t h c o d e< r e m e m b e r t t r a n s l a t e 1 t h r u 1 5 t o t h r u F > T h e n t h r e m a i n d e r o t h d i v i s i o n i t h s e c o n d c h a r a c t e r . N o t g e t t h e b i p a t t e r n w J u s t l o o k i u i t h l i t t l e b i p a t t e r n t a b l e . P u t h f i r s t f o u r -b i p a t t e r n t o g e t h e r w i t h t h s e c o n d a n y o h a v e a n e i g h t b i p a t t e r nw h i c h r e p r e s e n t s t h n u m e r i c v a l u e . N o h a r d a a l l . L e t s t r i w i t h f e n u m b e r s . T a k e t h n u m b e r 1 6 9 . H o m a n y t i m e s d o e s 1 g i n t o 1 6 9 ? R i g h t . A n d h o w i t h a t r e p r e s e n t e d i o u s i n g l e c h a r a c t e rc o d e ? A t h l e t t e r " A " . T h r e m a i n d e r f r o m d i v i d i n g 1 6 b 1 i 9 S o u r c h a r a c t e r - c o d e r e p r e s e n t a t i o n o 1 6 i " A 9 " a n d i w g t t h b i p a t t e r n t a b l e * w w i l l s e t h a t t h b i p a t t e r n s a r 1 0 1 01 0 0 1 .

I i v a l u a b l e e x e r c i s e t p r a c t i c e c o n v e r t i n g b i p a t t e r n st c h a r a c t e r - c o d e s a n d f r o m c h a r a c t e r - c o d e s t d e c i m a l a n f r o md e c i m a l t c h a r a c t e r - c o d e s a n c h a r a c t e r - c o d e s t b i p a t t e r n s . Y o w i l l f i n d a t a b l e o f a l 2 5 b i p a t t e r n s a n t h c o r r e s p o n d i n gc h a r a c t e r - c o d e s a n c o r r e s p o n d i n g d e c i m a l v a l u e s i A p p e n d i x B Y o u m a y c h e c k y o u r s u c c e s s w i t h t h t a b l e .

T h c h a r a c t e r - c o d e s y s t e m f o i d e n t i f y i n g t h v a r i o u s b i p a t t e r n s i s a y o m i g h t k n o w o h a v e f i g u r e d o u t , w h a t i c o m p u t e rc i r c l e s i c a l l e d h e x a d e c i m a l . N u m b e r s * w h e n r e p r e s e n t e d i h e x a d e c i m a l * a r u s u a l l y p r o c e e d e d b " $ " . $ 4 i t h h e r e p r e s e n t a t i o n f o t h A S C I I c o d e f o r t h e l e t t e r " A " . T h i s r e m o v e sa n y q u e s t i o n a t w h e t h e r t h n u m b e r i d e c i m a l o h e x a d e c i m a l . F r o mn o o w w i l l f o l l o w t h a t c o n v e n t i o n i t h i s b o o k .

T h e r e i a n o t h e r c o n v e n t i o n w h i c h i w i d e l y u s e d t i d e n t i f yt h i n d i v i d u a l b i t s i a b y t e . T h b i t s a r n u m b e r e d 0 - 7 f r o m r i g h tt l e f t . T h h i g h - o r d e r b i i t h e 7 - b i t a n t h l o w - o r d e r b i t i s t h 0 - b i t .

W d i s c u s s e d t h w a t r e p r e s e n t t h d e c i m a l n u m b e r s f r o mt o 2 5 5 . T h s a m e g e n e r a l t e c h n i q u e m a b u s e d t r e p r e s e n t n u m b e r sf r o m t 6 5 5 3 5 . I n s t e a d o t w h e x c h a r a c t e r s r e p r e s e n t i n g o n b y t eo d a t a * w n e e d f o u r h e x c h a r a c t e r s r e p r e s e n t i n g s i x t e e n b i t s o t w b y t e s . N o t h f i r s t p a i r o h e c h a r a c t e r s m a b e f o l l o w e d b a n o 2 5 p a i r s o h e x c h a r a c t e r s $ 0 $ F ) S t h t o t a l n u m b e r o p o s s i b l e c o m b i n a t i o n s o f o u r h e x c h a r a c t e r s i 2 5 6 t i m e s 2 5 6 o 6 5 5 3 6 . T h a d d r e s s b u s i s i x t e e n b i t s w i d e . W h i c h i w h t h e r e a r e

Page 172: Inside the Commodore 64

8/6/2019 Inside the Commodore 64

http://slidepdf.com/reader/full/inside-the-commodore-64 172/172