News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu

Convert Basic pokes loop into ASM

Started by R0b1n, 20:40, 06 January 24

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

R0b1n

Hello everyone.

First of all I wish you a very happy new year :)

I'm converting the Basic loader of a famous game into asm and it contains a for pokes loop like this:


100 FOR i=&BE80 TO &BE88:READ a$:POKE i,VAL("&"+a$):NEXT
110 DATA CD,CE,BC,3E,00,32,00,AA,C9


I don't know what it's for but it says "adaptation" in the comments.

I converted this loop like this:

ld   hl,&be80
ld   (hl),&cd
ld   hl,&be81
ld   (hl),&ce
ld   hl,&be82
ld   (hl),&bc
ld   hl,&be83
ld   (hl),&3e
ld   hl,&be84
ld   (hl),&00
ld   hl,&be85
ld   (hl),&32
ld   hl,&be86
ld   (hl),&00
ld   hl,&be87
ld   (hl),&aa
ld   hl,&be88
ld   (hl),&c9
ld   hl,&be84
push hl
ld   hl,&a700
ld   a,(hl)
pop  hl
ld   (hl),a
ld   hl,&848f
ld   (hl),&80
ld   hl,&8490
ld   (hl),&be


It is working great but I would like to know if this is the best and fastest execute code way or is there another one to do it more simply and efficiently ?

Thanks in advance.

lightforce6128

#1
The encoded sequence disassembles to:

call &bcce     ;; CD CE BC
ld   a,0       ;; 3E 00
ld   (&aa00),a ;; 32 00 AA
ret            ;; C9

To place the bytes to their target position, I suggest to use the "ldir" command. The original program uses pairs of "ld hl,xxxx : ld (hl),xx" (5 bytes each), what results in 9*5=45 bytes. The setup for the "ldir" command only needs 10 bytes (plus a data section for the 9 bytes to copy).

ld   bc,9     ;; length
ld   de,&BE80 ;; target
ld   hl,xxxx  ;; source
ldir          ;; copy bytes

The next part transfers a single byte to the "ld a,0" command. By rearranging it, the "push/pop" pair can be removed. Also the command pair "ld hl,xxxx : ld a,(hl)" can be merged in a single command "ld a,(xxxx)"

ld   a,(&a700)
ld   (&be84),a

Finally, two values are stored at other adresses. I think, this can not be shortend.

R0b1n

#2
Thank you very much lightforce6128. It works like a charm. It's seems that you recognized the loader game  :D

Powered by SMFPacks Menu Editor Mod