It is a long time since someone mentioned ASM coding on MRC.
Time to repair this issue.
Can this code be optimized ?
The two functions are supposed to copy from and to a "room" of size map_w X map_h (height do not care)
the background under a frame taken from external data and store the tiles in a buffer.
The position in the room and the address of the buffer that stores the background are passed
as parameters in registers BC and DE.
The frame number is passed on the stack.
;de source_addr; ;bc dest_addr; ;ix+4 e ix+5 nframe global _npctgrab _npctgrab: push ix ld ix,0 add ix,sp push de ld e,(ix+4) ld d,(ix+5) ld hl,_frames add hl,de add hl,de ld e,(hl) inc hl ld d,(hl) ; de punta alla frame corrente push de pop ix ; ora ix punta alla frame corrente pop hl ; hl punta alla source in room ld d,b ; bc puntava alla destination in frame buffer ld e,c ; ora de punta alla destination in frame buffer 1: ld a,(ix+0) ; 127 == fine cp 127 jp z,3f ld c,a ld b,0 push hl add hl,bc ; source ld c,(ix+1) ; len inc ix inc ix add ix,bc ldir pop hl ld bc,(_map_w) add hl,bc jp 1b 3: pop ix pop hl pop af jp (hl) ;de source_addr; ;bc dest_addr; ;ix+4 e ix+5 nframe global _npctrest _npctrest: push ix ld ix,0 add ix,sp push de ld e,(ix+4) ld d,(ix+5) ld hl,_frames add hl,de add hl,de ld e,(hl) inc hl ld d,(hl) ; de punta alla frame corrente push de pop ix ; ora ix punta alla frame corrente pop hl ; hl punta alla source in room ld d,b ; bc puntava alla destination in frame buffer ld e,c ; ora de punta alla destination in frame buffer 1: ld a,(ix+0) ; 127 == fine cp 127 jp z,3f ld c,a ld b,0 push de ex de,hl add hl,bc ; source ex de,hl ld c,(ix+1) ; len inc ix inc ix add ix,bc ldir pop de ld bc,(_map_w) ex de,hl add hl,bc ex de,hl jp 1b 3: pop ix pop hl pop af jp (hl)
The frame data are structured like this
framex1: db 0,2,18,19 ; X offset of line 0, length of line 0, data, data ect db 0,2,20,21; X offset of line 1, length of line 1, data, data ect db 127 ; end of the frame frame0: db 5,1,147 db 4,1,147 db 3,1,147 db 2,1,147 db 1,1,147 db 127 etc _frames: dw framex1,frame0,frame1,frame2,frame3,frame4,frame5, etc etc
!login ou Inscrivez-vous pour poster