I am currently in a conundrum with a bit of ASM that should be working but... isn't
Code: Select all
void asm_CopyWriteCell( void *scr_ptr, void *copy_cell, void *source) //HL / BC / DE
{
#asm
; load positions from stack
ld HL, 6 ; get the source cell data address
add HL, SP ;
ld E, (HL) ; store ( data source location ) in DE
inc HL
ld D, (HL)
ld HL, 4 ; get the copy cell address
add HL, SP ;
ld C, (HL) ; store in BC
inc HL
ld B, (HL)
ld HL, 2 ; get the screen pointer address
add HL, SP
; Processing TIME!
; P0
ld A, (HL) ; get the byte from the screen file
ld (BC), A ; store in Copy Cell
ld A, (DE) ; get byte to write to screen file
ld (HL),A ; test
inc H ; next byte line data in screen file *CELL
inc BC ; next byte in Copy Cell
inc DE ; next byte in Source Cell
; P1
ld A, (HL) ; get the byte from the screen file
ld (BC), A ; store in Copy Cell
ld A, (DE) ; get byte to write to screen file
ld (HL),A ; save to screen file
inc H ; next byte line data in screen file *CELL
inc BC ; next byte in Copy Cell
inc DE ; next byte in Source Cell
; P2
ld A, (HL) ; get the byte from the screen file
ld (BC), A ; store in Copy Cell
ld A, (DE) ; get byte to write to screen file
ld (HL),A ; save to screen file
inc H ; next byte line data in screen file *CELL
inc BC ; next byte in Copy Cell
inc DE ; next byte in Source Cell
; P3
ld A, (HL) ; get the byte from the screen file
ld (BC), A ; store in Copy Cell
ld A, (DE) ; get byte to write to screen file
ld (HL),A ; save to screen file
inc H ; next byte line data in screen file *CELL
inc BC ; next byte in Copy Cell
inc DE ; next byte in Source Cell
; P4
ld A, (HL) ; get the byte from the screen file
ld (BC), A ; store in Copy Cell
ld A, (DE) ; get byte to write to screen file
ld (HL),A ; save to screen file
inc H ; next byte line data in screen file *CELL
inc BC ; next byte in Copy Cell
inc DE ; next byte in Source Cell
; P5
ld A, (HL) ; get the byte from the screen file
ld (BC), A ; store in Copy Cell
ld A, (DE) ; get byte to write to screen file
ld (HL),A ; save to screen file
inc H ; next byte line data in screen file *CELL
inc BC ; next byte in Copy Cell
inc DE ; next byte in Source Cell
; P6
ld A, (HL) ; get the byte from the screen file
ld (BC), A ; store in Copy Cell
ld A, (DE) ; get byte to write to screen file
ld (HL),A ; save to screen file
inc H ; next byte line data in screen file *CELL
inc BC ; next byte in Copy Cell
inc DE ; next byte in Source Cell
; P7
ld A, (HL) ; get the byte from the screen file
ld (BC), A ; store in Copy Cell
ld A, (DE) ; get byte to write to screen file
ld (HL),A ; save to screen file
ret
#endasm
}
Code: Select all
CALL:
asm_CopyWriteCell( scr_ptr, &Tile[4].byte, &Tile[0].byte);
Code: Select all
ELEMENTS:
struct ZX_UDG
{
unsigned char byte[8];
};
struct ZX_UDG Tile[5];
During this process, it also writes a byte (each itteration) to the Screen File [SCR PTR (HL) ] from the [ SOURCE (DE) ]
Sadly when I inspect the retainers and print them to the screen I get a complete mess - so I have clearly missed something fundemental - my hope (and its most likely )that I missed something blindingly obvious - so any ideas of the above - what little is left of my hair - appreciates you
__________________________________________________________________________________
Interestingly the above is an extrapolation of another ASM function I wrote that works as expected -
Code: Select all
void asm_CopyClearCell( void *dest, void *source)
{
#asm
ld hl,2 ; jump the return address of the stack
add hl,sp ; by incrementing the stack ptr by 2
ld c,(hl) ; load the address of the *byte ptr from the stack to bc
inc hl ; "" *Remember Least Significant Byte First
ld b,(hl) ; ""
ld a,(bc) ; store the value of BC in a "source"
ld hl,4 ; add a four byte jump to the stack
add hl,sp ; getting to "dest"
ld e,(hl) ; get the address
inc hl ; of the
ld d,(hl) ; *dest
ex de,hl ; exchange registers
; unpacked for speed
ld (hl), a ; put the byte from the screen file to the copy cell
inc hl ; add 1 to get to the next row in the cell
xor a
ld (bc), a ; empty the byte from the screen file
inc b ; add 256 to the address ( next data line within the CELL of the Screen File)
ld a,(bc) ; put the value of the pointer of BC into A
ld (hl), a ; put the byte in the screen file
inc hl ; add 1 to get to the next row in the cell
xor a ; Empty A register
ld (bc), a ; empty the byte
inc b ; add 256 to the address of the byte
ld a,(bc) ; put the value of the pointer of BC into A
ld (hl), a ; put the byte in the screen file
inc hl ; add 1 to get to the next row in the cell
xor a
ld (bc), a ; Zero the byte within the Screen File
inc b ; add 256 to the address of the byte
ld a,(bc) ; put the value of the pointer of BC into A
ld (hl), a ; put the byte from the screen file to the copy cell
inc hl ; add 1 to get to the next row in the cell
xor a
ld (bc), a ; empty the byte
inc b ; add 256 to the address of the byte
ld a,(bc) ; put the value of the pointer of BC into A
ld (hl), a ; put the byte in the screen file
inc hl ; add 1 to get to the next row in the cell
xor a
ld (bc), a ; empty the byte
inc b ; add 256 to the address of the byte
ld a,(bc) ; put the value of the pointer of BC into A
ld (hl), a ; put the byte in the screen file
inc hl ; add 1 to get to the next row in the cell
xor a
ld (bc), a ; empty the byte
inc b ; add 256 to the address of the byte
ld a,(bc) ; put the value of the pointer of BC into A
ld (hl), a ; put the byte in the screen file
inc hl ; add 1 to get to the next row in the cell
xor a
ld (bc), a ; empty the byte
inc b ; add 256 to the address of the byte
ld a,(bc) ; put the value of the pointer of BC into A
ld (hl), a ; put the byte in the screen file
xor a
ld (bc), a
ret
#endasm
}
Code: Select all
ELEMENTS:
struct ZX_UDG
{
unsigned char byte[8];
};
struct ZX_UDG Tile[5];
Code: Select all
CALL:
asm_CopyClearCell( &Tile[4].byte, scr_ptr );
So slowly slowly getting there.... soo slowly.... but hey... picked up my set of glasses today, only been waiting 3 weeks - whom know's I may, (although unlikely) figure this mess out....
A huge thanks for reading.