<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://c64mags.untergrund.net/wiki/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://c64mags.untergrund.net/wiki/index.php?action=history&amp;feed=atom&amp;title=Skyhigh_11_ch18_Coders_Corner</id>
		<title>Skyhigh 11 ch18 Coders Corner - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://c64mags.untergrund.net/wiki/index.php?action=history&amp;feed=atom&amp;title=Skyhigh_11_ch18_Coders_Corner"/>
		<link rel="alternate" type="text/html" href="http://c64mags.untergrund.net/wiki/index.php?title=Skyhigh_11_ch18_Coders_Corner&amp;action=history"/>
		<updated>2026-06-21T01:52:09Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.19.0</generator>

	<entry>
		<id>http://c64mags.untergrund.net/wiki/index.php?title=Skyhigh_11_ch18_Coders_Corner&amp;diff=2737&amp;oldid=prev</id>
		<title>Ymgve at 15:37, 25 June 2007</title>
		<link rel="alternate" type="text/html" href="http://c64mags.untergrund.net/wiki/index.php?title=Skyhigh_11_ch18_Coders_Corner&amp;diff=2737&amp;oldid=prev"/>
				<updated>2007-06-25T15:37:21Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;pre&amp;gt;             coders corner.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 this is the second time i'm writing the&lt;br /&gt;
beginning of the code-chapter. why ?.&lt;br /&gt;
well, my text-disc got lost somewhere in&lt;br /&gt;
my room or maybe it has flown away.&lt;br /&gt;
&lt;br /&gt;
 i was planning to do some sort of a&lt;br /&gt;
'mnemonic-appendix' which descripes ALL&lt;br /&gt;
the MC-commands, the different way of&lt;br /&gt;
adressing them, the way they effect the&lt;br /&gt;
flags in the status-register and of-&lt;br /&gt;
course some hints &amp;amp;amp; tips. (eg. remember&lt;br /&gt;
to use at SEC before SBC if you subtract&lt;br /&gt;
without knowing what the CARRY-FLAG&lt;br /&gt;
holds). i've allready written ca 450&lt;br /&gt;
lines. hopefully i'll find my disc soon&lt;br /&gt;
and you'll see my 'MC-appendix' in the&lt;br /&gt;
next issue of skyhigh.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
       USING THE TURBO-ASSEMBLER.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 as written in the previous code-chapter&lt;br /&gt;
i assume you're using an assembler with&lt;br /&gt;
this MC-curse. the assembler translates&lt;br /&gt;
the mnemonics to the real machine-code&lt;br /&gt;
(opcodes, opcode vectors &amp;amp;amp; datas. eg.&lt;br /&gt;
LDA $c000,x = $bd $00 $c0 ). i'll now&lt;br /&gt;
introduce you to the turbo-ass.&lt;br /&gt;
 this is a general introduction and it&lt;br /&gt;
should work with allmost all variants.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
                 MEMORY.&lt;br /&gt;
&lt;br /&gt;
the turbo-assembler uses the following&lt;br /&gt;
locations for the assember itself &amp;amp;amp; for&lt;br /&gt;
source-code and datas.&lt;br /&gt;
&lt;br /&gt;
$9000-$d000 : turbo-assembler program.&lt;br /&gt;
&lt;br /&gt;
$d000-$ffff : labels &amp;amp;amp; other datas.&lt;br /&gt;
&lt;br /&gt;
$????-$8fff : source-code.&lt;br /&gt;
&lt;br /&gt;
 $???? is the end-address of the source-&lt;br /&gt;
code. please note that the source-code&lt;br /&gt;
is taking up memory-space backwards.&lt;br /&gt;
 the counter starts at $8fff and de-&lt;br /&gt;
creases as more lines are added. the&lt;br /&gt;
current address can be read in the&lt;br /&gt;
status-line in the buttom of the screen.&lt;br /&gt;
 use the memory-location below this&lt;br /&gt;
address for you own program. (if you&lt;br /&gt;
are a skilled programmer, you'll find&lt;br /&gt;
out ways to use the rest of the memory.&lt;br /&gt;
eg. by using a cross assembler).&lt;br /&gt;
&lt;br /&gt;
 for our test programs we'll use the&lt;br /&gt;
address $4000.&lt;br /&gt;
&lt;br /&gt;
             the '*' symbol:&lt;br /&gt;
&lt;br /&gt;
 the turbo assembler uses the symbol&lt;br /&gt;
'*' as a 'program counter'. the '*'&lt;br /&gt;
always hold the current address. when&lt;br /&gt;
the source-code is assembled the '*'&lt;br /&gt;
will hold the start-value (eg $4000) and&lt;br /&gt;
during the assembling process it'll&lt;br /&gt;
indicate where to in the memory the&lt;br /&gt;
code is being assembled.&lt;br /&gt;
&lt;br /&gt;
exampels:&lt;br /&gt;
&lt;br /&gt;
     * = $4000  ; set start-address&lt;br /&gt;
&lt;br /&gt;
     lda #$00   ;'*' holds the value&lt;br /&gt;
                ;$4000 when this command&lt;br /&gt;
                ;is about to be assemb-&lt;br /&gt;
                ;led.&lt;br /&gt;
&lt;br /&gt;
     sta $d020  ;'*' now holds the add.&lt;br /&gt;
                ;$4002.&lt;br /&gt;
&lt;br /&gt;
     rts        ;$4005&lt;br /&gt;
&lt;br /&gt;
                ;$4006&lt;br /&gt;
example 2:&lt;br /&gt;
&lt;br /&gt;
     * = $4000 ;start&lt;br /&gt;
&lt;br /&gt;
     lda #$00  ; all this is assembled&lt;br /&gt;
     sta $d020 ; into the area $4000-&lt;br /&gt;
     rts       ; $4005 (inclusive).&lt;br /&gt;
&lt;br /&gt;
     * = $2000 ;new start in the same&lt;br /&gt;
               ;source-code.&lt;br /&gt;
&lt;br /&gt;
     .byte $00,$01,$02,$03,$04&lt;br /&gt;
&lt;br /&gt;
               ;these datas are ass.&lt;br /&gt;
               ;into $2000-$2004.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
           THE USE OF NUMBERS.&lt;br /&gt;
&lt;br /&gt;
 the turbo-assembler 'understands'&lt;br /&gt;
three different set of numbers. decimal,&lt;br /&gt;
hex and binary.&lt;br /&gt;
&lt;br /&gt;
 a '$' sign infront of the number indi-&lt;br /&gt;
cates hex.&lt;br /&gt;
&lt;br /&gt;
 '%' means binary.&lt;br /&gt;
&lt;br /&gt;
 if you use binary numbers, the turbo-&lt;br /&gt;
assembler will only accept you entries&lt;br /&gt;
if it made of 8 digits. if the number&lt;br /&gt;
is too big (eg. %1111110011) you'll&lt;br /&gt;
get a error message. if the number is&lt;br /&gt;
too small the assembler will inset the&lt;br /&gt;
'missing' zeros (eg %10001 = %00010001)&lt;br /&gt;
 the turbo-assembler always work eigher&lt;br /&gt;
byte-wise (1 byte = 8 bits = 8 BInary&lt;br /&gt;
digiTS) or WORD-wise (2 bytes). binary&lt;br /&gt;
numbers are bytes only. HEX can be both.&lt;br /&gt;
(eg: you write $1, the turbo-assembler&lt;br /&gt;
insets a zero = $01. example 2: $211 is&lt;br /&gt;
equal to $0211). is quite a clever act&lt;br /&gt;
to inset the missing zeros. by doing&lt;br /&gt;
this the turbo-assembler you source-&lt;br /&gt;
code easier to understand:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
example:  (this is chaos:)&lt;br /&gt;
&lt;br /&gt;
       lda #$1&lt;br /&gt;
       sta $400&lt;br /&gt;
       sta $0401&lt;br /&gt;
       lda #%101&lt;br /&gt;
       sta $0400&lt;br /&gt;
       sta $401&lt;br /&gt;
       lda #%0101&lt;br /&gt;
       sta $d020&lt;br /&gt;
       lda #%1010&lt;br /&gt;
       sta $800&lt;br /&gt;
&lt;br /&gt;
 if you enter this mess in turbo-ass,&lt;br /&gt;
you'll get this listing:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
       lda #$01&lt;br /&gt;
       sta $0400&lt;br /&gt;
       sta $0401&lt;br /&gt;
       lda #%00000101&lt;br /&gt;
       sta $0400&lt;br /&gt;
       sta $0401&lt;br /&gt;
       lda #%00000101&lt;br /&gt;
       sta $d020&lt;br /&gt;
       lda #%00001010&lt;br /&gt;
       sta $0800&lt;br /&gt;
&lt;br /&gt;
 NOTICE: DECIMAL numbers are shown&lt;br /&gt;
as they are written = no zeros infront.&lt;br /&gt;
 i normally stick up hex-numbers, and&lt;br /&gt;
only use the decimal version when i'm&lt;br /&gt;
too lazy to find out the hex-value or&lt;br /&gt;
if i'm changing the number very often.&lt;br /&gt;
(eg. in my firework routine in 'camel&lt;br /&gt;
park' (soon to be released) i used a&lt;br /&gt;
label which hold the number of plots.&lt;br /&gt;
(maxplots = 54) i had to change this&lt;br /&gt;
as i optimized the routine. lazyness ?)&lt;br /&gt;
&lt;br /&gt;
            JUMPS AND LABELS.&lt;br /&gt;
&lt;br /&gt;
 last time i expained the general func-&lt;br /&gt;
tion of 'LDA', 'STA' and RTS.&lt;br /&gt;
 the next command i'll introduce is the&lt;br /&gt;
'JMP'.&lt;br /&gt;
&lt;br /&gt;
 as told last issue the 6502/6510 has&lt;br /&gt;
got Program Counter (PC) which is a 2-&lt;br /&gt;
byte (1 word) register which points to&lt;br /&gt;
the location of the command currently&lt;br /&gt;
being executed. the function of the&lt;br /&gt;
'JMP' (JuMP) is the change the pointer.&lt;br /&gt;
 is quite simple: by using a JMP you&lt;br /&gt;
can perform a jump to somewhere else&lt;br /&gt;
in you code.&lt;br /&gt;
&lt;br /&gt;
example:&lt;br /&gt;
&lt;br /&gt;
$4000   lda #$00    ;'A'=0&lt;br /&gt;
$4002   sta $d020   ;'A' into $d020&lt;br /&gt;
$4005   sta $d021   ;'A' into $d021&lt;br /&gt;
$4008   jmp $4020   ;jump .....&lt;br /&gt;
$4009                         .&lt;br /&gt;
 .                            .&lt;br /&gt;
 .                            .&lt;br /&gt;
 .                            .&lt;br /&gt;
$401f                         .&lt;br /&gt;
$4020   lda #$01   ;...........&lt;br /&gt;
$4022   sta $0400  ;$01 into $0400&lt;br /&gt;
$4023   rts        ;return to basic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 this is an example of a direct jump.&lt;br /&gt;
&lt;br /&gt;
 if you move the code at $4020 to some-&lt;br /&gt;
where else in the memory you'll have&lt;br /&gt;
to change the jump.&lt;br /&gt;
&lt;br /&gt;
 in an assembler you'll allways use&lt;br /&gt;
LABELS instead.&lt;br /&gt;
&lt;br /&gt;
 LABELS are words which descripes diffe-&lt;br /&gt;
rent location in the code. 'inside' the&lt;br /&gt;
assembler the labels represent a value&lt;br /&gt;
(normally the position in the code&lt;br /&gt;
where they are written.)&lt;br /&gt;
&lt;br /&gt;
example:&lt;br /&gt;
&lt;br /&gt;
      SOURCE CODE: ASSEMBLED CODE:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
      * = $4000&lt;br /&gt;
&lt;br /&gt;
      jmp white    4000 jmp $400e&lt;br /&gt;
black&lt;br /&gt;
      lda #$00     4003 lda #$00&lt;br /&gt;
      sta $d020    4005 sta $d020&lt;br /&gt;
      sta $d021    4008 sta $d021&lt;br /&gt;
      jmp exit     400b jmp $4016&lt;br /&gt;
white&lt;br /&gt;
      lda #$01     400e lda #$01&lt;br /&gt;
      sta $d020    4010 sta $d020&lt;br /&gt;
      sta $d021    4013 sta $d021&lt;br /&gt;
exit&lt;br /&gt;
      lda #$01     4016 lda #$01&lt;br /&gt;
      sta $0400    4018 sta $0400&lt;br /&gt;
      rts          401b rts&lt;br /&gt;
&lt;br /&gt;
 if you'd written this small program&lt;br /&gt;
in a mc-monitor you'll get serious&lt;br /&gt;
trouble if you want to expand the&lt;br /&gt;
routine 'black'. you'd have to copy the&lt;br /&gt;
rest of the program 'white','exit' to&lt;br /&gt;
another location. (eg. if you want to&lt;br /&gt;
inplant a 'sta $d015' in 'black' you'll&lt;br /&gt;
have to push the rest of the program&lt;br /&gt;
3 bytes). you'll then have to modify&lt;br /&gt;
all the JMPs.&lt;br /&gt;
 if you use an assembler, it'll take&lt;br /&gt;
care of this for you.&lt;br /&gt;
&lt;br /&gt;
              PRESET LABELS&lt;br /&gt;
&lt;br /&gt;
 if the labels are written as descriped&lt;br /&gt;
(as marks in the sourcecode) they'll&lt;br /&gt;
represent the value of the memory-&lt;br /&gt;
location of the next order (and this is&lt;br /&gt;
handy of jumps etc). however it's&lt;br /&gt;
possible to assign any value to a label.&lt;br /&gt;
&lt;br /&gt;
example:&lt;br /&gt;
&lt;br /&gt;
clrscr   = $e544 ;the lable 'clrscr' is&lt;br /&gt;
                 ;set to the value&lt;br /&gt;
                 ;$e544 (where the ROM&lt;br /&gt;
                 ;clearscreen routine&lt;br /&gt;
                 ;is placed.&lt;br /&gt;
&lt;br /&gt;
       * = $4000 ;start of own program.&lt;br /&gt;
&lt;br /&gt;
       lda #$0b  ;grey&lt;br /&gt;
       sta $d020&lt;br /&gt;
       lda #$00  ;black&lt;br /&gt;
       sta $d021&lt;br /&gt;
       lda #$07  ;yellow&lt;br /&gt;
       sta $0286 ;set basic-char-col to&lt;br /&gt;
                 ;yellow.&lt;br /&gt;
&lt;br /&gt;
       jmp clrscr;jump to ROM-clear-&lt;br /&gt;
                 ;screen routine.&lt;br /&gt;
                 ;(it clears the screen&lt;br /&gt;
                 ;and fills the col-ram&lt;br /&gt;
                 ;with the value&lt;br /&gt;
                 ;written in $0286.&lt;br /&gt;
&lt;br /&gt;
 in some version of turbo-assember the&lt;br /&gt;
addressing will be messed up if you&lt;br /&gt;
place the setting of the labels in the&lt;br /&gt;
middle of the program. you can avoid&lt;br /&gt;
this by placing all the preset labels&lt;br /&gt;
above the start-address setting&lt;br /&gt;
(* $xxxx) or by witting a * = * after&lt;br /&gt;
the settings.&lt;br /&gt;
&lt;br /&gt;
                 X and Y&lt;br /&gt;
&lt;br /&gt;
 so far i've use the accumulator (A) in&lt;br /&gt;
my examples. the 6502/6510 has got two&lt;br /&gt;
more registers which can be used of&lt;br /&gt;
manipulating the memory. the X and Y&lt;br /&gt;
register can be used the same way as the&lt;br /&gt;
accumulator, but they make more sophis-&lt;br /&gt;
ticated adressing possible also.&lt;br /&gt;
&lt;br /&gt;
 using X and Y the same way as the&lt;br /&gt;
accumulator:&lt;br /&gt;
&lt;br /&gt;
               LDX &amp;amp;amp; LDY:&lt;br /&gt;
&lt;br /&gt;
        like LDA but for X and Y.&lt;br /&gt;
&lt;br /&gt;
               STX &amp;amp;amp; STY:&lt;br /&gt;
&lt;br /&gt;
                like sta.&lt;br /&gt;
&lt;br /&gt;
 loading one register (a,x or y) does&lt;br /&gt;
not change the contents of the others.&lt;br /&gt;
&lt;br /&gt;
 it's possible to use the x and y&lt;br /&gt;
register for flexible addressing:&lt;br /&gt;
&lt;br /&gt;
       LDA $XXXX,X and LDA $XXXX,Y&lt;br /&gt;
&lt;br /&gt;
 loading the accumulator from an address&lt;br /&gt;
coma x, makes the processor load A from&lt;br /&gt;
the specified address PLUS the number&lt;br /&gt;
hold in x:&lt;br /&gt;
&lt;br /&gt;
example 1:&lt;br /&gt;
&lt;br /&gt;
       ldx #$02&lt;br /&gt;
       lda $4000,x ;load a from $4002&lt;br /&gt;
&lt;br /&gt;
example 2:&lt;br /&gt;
&lt;br /&gt;
       ldy #$fe&lt;br /&gt;
       lda $4157,y ;load a from $4255&lt;br /&gt;
&lt;br /&gt;
example 3:&lt;br /&gt;
&lt;br /&gt;
       ldy #$02&lt;br /&gt;
       ldx $4000,y ;load x from $4002&lt;br /&gt;
&lt;br /&gt;
example 4:&lt;br /&gt;
&lt;br /&gt;
       ldx #$28&lt;br /&gt;
       ldy $0400,x ;load y from $0428&lt;br /&gt;
&lt;br /&gt;
 STA can be used much the same way:&lt;br /&gt;
&lt;br /&gt;
example 1:&lt;br /&gt;
&lt;br /&gt;
       lda #$00&lt;br /&gt;
       ldx #$01&lt;br /&gt;
       sta $d020,x ;set $d021 to $00&lt;br /&gt;
&lt;br /&gt;
example 2:&lt;br /&gt;
&lt;br /&gt;
       lda #$0f&lt;br /&gt;
       ldx #$20&lt;br /&gt;
       sta $d000,x ;set $d020 to $0f&lt;br /&gt;
&lt;br /&gt;
NOTICE: stx,y and sty,x are NOT possible&lt;br /&gt;
        unless you store ZEROPAGE,x/y.&lt;br /&gt;
&lt;br /&gt;
 (read MUCH more about all the diffe-&lt;br /&gt;
rent ways of addressing in the next iss.&lt;br /&gt;
&lt;br /&gt;
          DEX, INX &amp;amp;amp; DEY, INY.&lt;br /&gt;
&lt;br /&gt;
      (DEcrease X/Y, INcrease X/Y)&lt;br /&gt;
&lt;br /&gt;
 these four orders can be used for in-/&lt;br /&gt;
de-creasing x and y by 1 BYTE.&lt;br /&gt;
&lt;br /&gt;
example 1:&lt;br /&gt;
&lt;br /&gt;
       lda #$00&lt;br /&gt;
       ldx #$00&lt;br /&gt;
       sta $d020,x ;store in $d020&lt;br /&gt;
       inx&lt;br /&gt;
       sta $d020,x ;store in $d021&lt;br /&gt;
&lt;br /&gt;
example 2:&lt;br /&gt;
&lt;br /&gt;
       lda #$0f&lt;br /&gt;
       ldy #$21&lt;br /&gt;
       sta $d000,y ;store in $d021&lt;br /&gt;
       dey&lt;br /&gt;
       sta $d000,y ;store in $d020&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
                 LOOPS:&lt;br /&gt;
&lt;br /&gt;
 the last thing i'm going to teach you&lt;br /&gt;
now is how to make a loop. further&lt;br /&gt;
information on all different types to&lt;br /&gt;
'test-and-jumps' (branches) will be&lt;br /&gt;
printed in the next issue.&lt;br /&gt;
&lt;br /&gt;
       * = $4000&lt;br /&gt;
&lt;br /&gt;
       lda #$01 ;$01=char $01='a'&lt;br /&gt;
       ldy #$27&lt;br /&gt;
loop&lt;br /&gt;
       sta $0400,y;store $01 into screen&lt;br /&gt;
       dey        ;decrease y by 1&lt;br /&gt;
       bne loop   ;jump if not zero&lt;br /&gt;
&lt;br /&gt;
       sta $0400,y;when y=0&lt;br /&gt;
       rts&lt;br /&gt;
&lt;br /&gt;
 the program fills the first line on the&lt;br /&gt;
screen with 'a's. the 'dey' decreases y&lt;br /&gt;
and the sta $0400,y will therefore store&lt;br /&gt;
to a decreasing location during the loop&lt;br /&gt;
($0427,$0426,$0425...$0402,$0401). when&lt;br /&gt;
y reaces zero a flag will be set in the&lt;br /&gt;
statuts-register. 'bne' test this flag.&lt;br /&gt;
as long as y (DEY is the only command&lt;br /&gt;
that influences on this flag during the&lt;br /&gt;
loop) is different from zero the&lt;br /&gt;
program will jump to 'loop'. the last&lt;br /&gt;
sta $0400,y is used to make a sta $0400.&lt;br /&gt;
&lt;br /&gt;
  NEXT ISSUE MY BIG MC-COMMAND APPENDIX&lt;br /&gt;
              WILL BE HERE.&lt;br /&gt;
&lt;br /&gt;
   see you in the next coders corner.&lt;br /&gt;
&lt;br /&gt;
                  -raz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ymgve</name></author>	</entry>

	</feed>