Re: coding the Z80 and 6510 From: w_gayk@NOSPAMbielefeld.netsurf.de (Brix) Reply to: Brix Date: Tue, 3 Nov 1998 21:13:58 +0100 Organization: [Customers of] IS Internet Services GmbH & Co, Hamburg References: <70r5ec$8jp$17@newsreader1.core.theplanet.net> <3635b416.21822437@news.telepac.pt> <16476-agent.imc@comlab.ox.ac.uk> <71fo4o$oe9@cpca3.uea.ac.uk> In article <71fo4o$oe9@cpca3.uea.ac.uk>, a.p.cadley@uea.ac.uk says... > > Brix wrote in message ... > > > :Well, to tell you about the 6510: > > > Well I'll fill in Z80 equivalents: > > :To load a byte into an index-register (let's have X) you have the > Instruction: > :LDX #$byte (2 cycles) > > Z80 Index registers are 16 bit, so it would need LD IX,word (14 cycles) Urggh! Ok, I can understand that you don't like indexes... > Needless to say the index registers aren't used much. To index a 256 byte > table, you'd normally use: > > LD H,highbyte of address (7 cycles) > > Indexing would then be done use the L register to form a 16 bit pair (HL) Pretty strange way.. reminds me to zeropage-adressing on The C-64.. i'll talk a bout that at the end of this reply. > To write a byte would then use LD (HL),byte (10 cycles) or LD (HL),"r" (7 > cycles) where "r" is an 8 bit register. "LD (HL),Byte" means "write byte to adress given in H (highbyte) and L (Lowbyte ) ? I f i understood correctly you need to load the highbyte to H and the Lowbyte t o L... means: to write a Byte to adress 1000h-1002h (stupido-method) you could do: ld l,00 ld h,10 ld (hl),byte ld l,01 ld (hl),byte ld l,02 ld (hl),byte ???? > :So now let's fill the Memory-Area $1000 - $1100 with the Byte $44. The > Code: > : > : LDA #$44 (2 Cycles) > : LDX #$00 (2 Cycles) > :-loop STA $1000,X (5 Cycles) > : DEX (decrement X-register, 2 Cycles) > : BNE loop (Branch if not equal Zero, 2 Cycles) > > > :So we need 9 Cycles (!) to write a Byte to memory (indexed), decrease the > index register, > :compare if it's zero or not and Branch depending on the result. > : > > He, he. The Z80 is particularly good at this kind of linear operation. The > code becomes: > > LD HL,1000h (10 cycles) > LD DE,1001h (10 cycles) > LD BC,0FFh (10 cycles) > LD (HL),44h (10 cycles) > > LDIR (21 cycles if BC > 1, 16 cycles if BC = 1) hm, i don't really see how the program works, ccos i don't see the loop inthere ... could you comment it a little, please? This is what I could see in this (without knowing anything of Z80 code): LD HL,1000h (10 cycles) Load High-byte of adress 1000h to register HL ? LD DE,1001h (10 cycles) Load Lowbyte of Adress 1001h (why 1001h?)to r egister DE? LD BC,0FFh (10 cycles) BC seems to be a counter.. in 0ffh.. right? LD (HL),44h (10 cycles) now you put the byte 44h in adress given in H L ? LDIR (21 cycles if BC > 1, 16 cycles if BC = 1) LDIR seems to be a branch, but where does it jump? Where is the adress increaded/decreased? > :What you see here is just a typical C-64 code, most Instructions take 2-5 > Cycles. The > :overall-average in a usual 6510-code is about about 3 - 3.5 Cycles per > Instruction. > :This makes the 6510 relatively fast, even when it is clocked relatively > slow. > : > :I'd be glad if you could show me the Z80-code for this program above (so > i'd learn some > :Z80 code aswell :) ). > > As you can see the above code is particularly well suited to the Z80s > powerful LDIR instruction. Given the clock ratio between a C64 and a Speccy > (1:3.54) the 6502 routine would need to execute in about 6 cycles to beat > the Z80 in this particular case. > > AndyC Hm, I just need a bit more info undersanding your code... then I'd comment this , ok? -Brix-