03-09-2010, 03:39 PM
spritebuffer.bas: I made a small routine to take care of the background and use it with the previous sprite.bas routine. It has zero optimization (note the repeated code, that is also used in the sprite routine) but I just wanted something working.
Code:
SUB cpbuffer (xd as ubyte,yd as ubyte,buff as Uinteger)
POKE @buffer,xd:POKE @buffer+1,yd: POKE uinteger @buffer+5,buff
gosub copybuffer
END SUB
SUB rstbuffer (xd as ubyte,yd as ubyte,buff as Uinteger)
POKE @buffer,xd:POKE @buffer+1,yd: POKE uinteger @buffer+5,buff
gosub restorebuffer
END SUB
SUB cpattr (xd as ubyte, yd as ubyte, buff as Uinteger)
LET xattr=INT (xd/8): LET yattr=INT (yd/8): LET dirattr=22528+(32*xattr)+yattr
'POKE uinteger @buffer+5,buff
POKE buff,PEEK dirattr: POKE buff+1,PEEK (dirattr+1): POKE buff+2,PEEK (dirattr+2)
POKE buff+3,PEEK (dirattr+32): POKE buff+4,PEEK (dirattr+33): POKE buff+5,PEEK (dirattr+34)
POKE buff+6,PEEK (dirattr+64): POKE buff+7,PEEK (dirattr+65): POKE buff+8,PEEK (dirattr+66)
END SUB
SUB rstattr (xd as ubyte, yd as ubyte, buff as Uinteger)
LET xattr=INT (xd/8): LET yattr=INT (yd/8): LET dirattr=22528+(32*xattr)+yattr
'POKE uinteger @buffer+5,buff
POKE dirattr,PEEK buff: POKE dirattr+1,PEEK (buff+1): POKE dirattr+2,PEEK (buff+2)
POKE dirattr+32,PEEK (buff+3): POKE dirattr+33,PEEK (buff+4): POKE dirattr+34,PEEK (buff+5)
POKE dirattr+64,PEEK (buff+6): POKE dirattr+65,PEEK (buff+7): POKE dirattr+66,PEEK (buff+8)
END SUB
end
buffer:
ASM
xcoord: defb 0
ycoord: defb 0
altura: defb 0
gfx: defw 0
buf: defw 0
END ASM
copybuffer:
ASM
copybuffer:
;rutina para copiar algo en algun sitio, más o menos.
; This routine returns a screen address for (c, b) in de.
ld bc,(xcoord)
scadd3: ld a,c ; get vertical position.
and 7 ; line 0-7 within character square.
add a,64 ; 64 * 256 = 16384 (Start of screen display)
ld d,a ; line * 256.
ld a,c ; get vertical again.
rrca ; multiply by 32.
rrca
rrca
and 24 ; high byte of segment displacement.
add a,d ; add to existing screen high byte.
ld d,a ; that's the high byte sorted.
ld a,c ; 8 character squares per segment.
rlca ; 8 pixels per cell, mulplied by 4 = 32.
rlca ; cell x 32 gives position within segment.
and 224 ; make sure it's a multiple of 32.
ld e,a ; vertical coordinate calculation done.
ld a,b ; y coordinate.
rrca ; only need to divide by 8.
rrca
rrca
and 31 ; squares 0 - 31 across screen.
add a,e ; add to total so far.
ld e,a ; hl = address of screen.
ld (gfx),de
ld b,16
ld HL,(gfx) ;apuntar a la primera celda de la pantalla
ld DE,(buf) ;apuntar al buffer
bucle3: ld a,(HL) ;capturo el grafico en a
;LD C,a ;y lo paso a C
;ld a,(HL) ;cargo en a el contenido de la celda destino
;xor C ;xoreo con lo que traigo del grafico
ld (DE),a ;lo pinto en (hasta aquí sale xdd)
inc L
inc E
ld a,(HL)
ld (DE),a
inc L
inc E
ld a,(HL)
ld (DE),a
dec L
dec L
call uphl
inc E
djnz bucle3
ret
END ASM
restorebuffer:
ASM
restorebuffer:
;rutina para copiar algo en algun sitio, más o menos.
; This routine returns a screen address for (c, b) in de.
ld bc,(xcoord)
scadd2: ld a,c ; get vertical position.
and 7 ; line 0-7 within character square.
add a,64 ; 64 * 256 = 16384 (Start of screen display)
ld d,a ; line * 256.
ld a,c ; get vertical again.
rrca ; multiply by 32.
rrca
rrca
and 24 ; high byte of segment displacement.
add a,d ; add to existing screen high byte.
ld d,a ; that's the high byte sorted.
ld a,c ; 8 character squares per segment.
rlca ; 8 pixels per cell, mulplied by 4 = 32.
rlca ; cell x 32 gives position within segment.
and 224 ; make sure it's a multiple of 32.
ld e,a ; vertical coordinate calculation done.
ld a,b ; y coordinate.
rrca ; only need to divide by 8.
rrca
rrca
and 31 ; squares 0 - 31 across screen.
add a,e ; add to total so far.
ld e,a ; hl = address of screen.
ld (gfx),de
ld b,16
ld HL,(gfx) ;apuntar a la primera celda del destino
ld DE,(buf) ;apuntar al origen
bucle2: ld a,(DE) ;capturo el grafico en a
;LD C,a ;y lo paso a C
;ld a,(HL) ;cargo en a el contenido de la celda destino
;xor C ;xoreo con lo que traigo del grafico
ld (HL),a ;lo pinto en la pantalla (hasta aquí sale xdd)
inc L
inc E
ld a,(DE)
ld (HL),a
inc L
inc E
ld a,(DE)
ld (HL),a
dec L
dec L
call uphl
inc E
djnz bucle2
ret
uphl:
inc h
ld a,h
and 7
ret nz
ld a,l
add a,32
ld l,a
ret c
ld a,h
sub 8
ld h,a
ret
END ASM