Ready64 Forum
Commodore 64 => Programmazione, Grafica e Musica => Topic aperto da: iAN CooG - 06 Agosto 2006, 02:57:44
-
In uno sprite ci stanno esattamente 3 caratteri in orrizontale, 3*8 fanno 24 caratteri, abbastanza per uno scroller :)
L'unico problema sta nello scrivere i bit (quindi pixels) che compongono un carattere e nella posizione giusta.
Un carattere e' composto di 8 byte contigui, uno per ogni riga di pixels, mentre negli sprites 3 bytes contigui fanno una riga orrizontale. Occorre scrivere ogni riga di pixels di un carattere ogni 3 byte di uno sprite.
01234567 012345670123456701234567
00011000 000110000000000000000000
00111100 001111000000000000000000
01100110 011001100000000000000000
01111110 011111100000000000000000
01100110 011001100000000000000000
01100110 011001100000000000000000
01100110 011001100000000000000000
00000000 000000000000000000000000
000000000000000000000000
000000000000000000000000
000000000000000000000000
000000000000000000000000
000000000000000000000000
000000000000000000000000
000000000000000000000000
000000000000000000000000
000000000000000000000000
000000000000000000000000
000000000000000000000000
000000000000000000000000
000000000000000000000000
Scritti poi 3 caratteri nello sprite 1 possiamo continuare nello sprite 2 e cosi' via.
Un altra cosa da tenere conto e' che i caratteri nel CharGen sono nell'ordine degli screen codes e non come petscii, e che essendo appunto composti da 8 bytes l'uno bisogna moltiplicare per 8 il valore di ogni carattere per trovarne l'offset.
Avendo come base $D800, cioe' il charset minuscole/maiuscole ($D000 e' per Maiuscole/semigrafici) abbiamo ad esempio che:
@=$00, 0*8 + charsetbase = $D800
a=$01, 1*8 + charsetbase = $D808
A=$41, $41*8 + charsetbase = $DA08
A questo punto possiamo procedere.
;------------------------------------------------------------
; Write texts into Sprites
; iAN CooG/HokutoForce
;------------------------------------------------------------
*= $801
debug = 1
zp2 = $02 ;16bit multiplication hi byte
app = $03 ;sprite counter
cnt = $05 ;text counter
sprptr= $07f8
SPR0X = $d000
SPR0Y = $d001
SPRact = $d015
SPR1col = $D027
sourcel = trch +1
sourceh = trch +2
destinl = trch +1+3
destinh = trch +2+3
;------------------------------------------------------------
word eop
word 7102
byte $9e,"2061",0
eop
word 0
;------------------------------------------------------------
start
;jsr $e544
;dex
ldy #[sprite1/$40]
setsprptr
tya
sta sprptr,x
lda #1
sta SPR1col,x
iny
inx
cpx #8
bne setsprptr
; all sprites active
lda #%11111111
sta SPRact
;now place them all in a row
lda #$40
sta app
ldx #0
placespr
lda #$64
sta SPR0Y,x
lda app
sta SPR0X,x
clc
adc #$18
sta app
inx
inx
cpx #$10
bne placespr
;chargen active at $D000-$DFFF
sei
lda #$33
sta $01
lda #0
sta cnt
sta app
;lda #<sprite1; already 0
sta destinl
lda #>sprite1
sta destinh
lp1
lda #0
sta zp2
;get a char to "print"
ldy cnt
lda texts,y
; multiply A * 8 to get charset pointer
; @=$D800, a=$D808, A=$DA08 etc
asl
rol zp2
asl
rol zp2
asl
rol zp2
sta sourcel
lda zp2
clc ; now add charset base address
adc #>$d800 ; lower/upper charset in chargen
sta sourceh
ldy #0
ldx #0
trch
lda $ffff,y;
sta $ffff,x;
inx;next row of the sprite
inx
inx
iny;next row of the char
cpy #8
bne trch
.if debug == 1
jsr w8sp
.endif
inc destinl
inc app
lda app
cmp #3
bne noincdestpr
lda #0
sta app
lda destinl
clc
adc #$3d;$40-3
sta destinl
bcc noincdestpr
inc destinh
noincdestpr
inc cnt
lda cnt
cmp #[endtexts-texts]
bne lp1
lda #$37
sta $01
cli
rts
;------------------------------------------------------------
texts scrl "iAN CooG/HokutoForce '06"
endtexts
;------------------------------------------------------------
.if debug == 1
w8sp
jsr w8sp2
bne w8sp
w8sp1
jsr w8sp2
beq w8sp1
lda #0
sta $c6
w8sp2
ldx $01
stx xx+1
ldx #$37
stx $01
lda $dc00
and $dc01
and #$10
php
xx ldx #$00
stx $01
plp
rts
.endif
;------------------------------------------------------------
*= $0900
sprite1
ds $40,0
sprite2
ds $40,0
sprite3
ds $40,0
sprite4
ds $40,0
sprite5
ds $40,0
sprite6
ds $40,0
sprite7
ds $40,0
sprite8
ds $40,0
;------------------------------------------------------------
-
Ottimo. Davvero interessante. :c64:
-
Versione con un po' di movimento, shiftando i bit si ottiene lo scrolling.
;------------------------------------------------------------
; Write texts into Sprites, flash and scroll added
; iAN CooG/HokutoForce
;------------------------------------------------------------
*= $801
byte 0
debug = 0
zp2 = $02 ;16bit multiplication hi byte
app = $03 ;sprite counter
cnt = $05 ;text counter
sprptr= $07f8
SPR0X = $d000
SPR0Y = $d001
SPRact = $d015
SPR1col = $D027
;------------------------------------------------------------
*= $801
word eop
word 7102
byte $9e,"2061",0
eop
word 0
;------------------------------------------------------------
start
ldx #$ff
ldy #[sprite1/$40]
setsprptr
tya
sta [sprptr-[sprite1/$40]],y
txa
sta [SPR1col-[sprite1/$40]],y
iny
cpy #[[sprite1/$40]+8]
bne setsprptr
;all sprites active
;lda #%11111111
;sta SPRact
;ldx #0
stx SPRact
inx
txa
fillspr
sta sprite1,x
sta sprite1+$100,x
inx
bne fillspr
;now place them all in a row
lda #$40
sta app
;ldx #$00
stx zp2
placespr
lda #$64
sta SPR0Y,x
lda app
sta SPR0X,x
clc
adc #$18
sta app
inx
inx
cpx #$10
bne placespr
;chargen active at $D000-$DFFF
sei
lda #$33
sta $01
lda #0
sta cnt
sta app
firstbyte = [sprite1+[[21-8]/2*3]]
;lda #<sprite1; already 0
lda #<firstbyte;centerd
sta destinl
;lda #>sprite1
lda #>firstbyte;centerd
sta destinh
lp1
lda #0
sta zp2
;get a char to "print"
ldy cnt
lda texts,y
; multiply A * 8 to get charset pointer
; @=$D800, a=$D808, A=$DA08 etc
asl
rol zp2
asl
rol zp2
asl
rol zp2
sta sourcel
lda zp2
clc ; now add charset base address
adc #>$d800 ; lower/upper charset in chargen
sta sourceh
ldy #0
ldx #0
trch
sourcel = * +1
sourceh = * +2
lda $ffff,y;
destinl = * +1
destinh = * +2
sta $ffff,x;
inx ;next row of the sprite
inx
inx
iny ;next row of the char
cpy #8
bne trch
.if debug == 1
jsr w8sp
.endif
inc destinl
inc app
lda app
cmp #3
bne noincdestpr
lda #0
sta app
lda destinl
clc
adc #$3d;$40-3
sta destinl
bcc noincdestpr
inc destinh
noincdestpr
inc cnt
lda cnt
cmp #[endtexts-texts]
bne lp1
lda #$37
sta $01
cli
col3
ldy #0
col2
ldx #$02
col4
bit $d011
bpl *-3
bit $d011
bmi *-3
dex
bne col4
lda coltable,y
;ldx #0
col1
sta SPR1col,x
inx
cpx #8
bne col1
jsr shiftsprites
iny
cpy #[endcol-coltable]
bne col2
ldx $dc01
inx
beq col3
rts
;------------------------------------------------------------
texts scrl "iAN CooG/HokutoForce'06 "
endtexts
coltable byte $0f,$0c,$0b,$00,$0b,$0c,$0f,$01
endcol
;------------------------------------------------------------
*= $0900
sprite1
;------------------------------------------------------------
*= sprite1 +$200
;------------------------------------------------------------
.if debug == 1
w8sp
jsr w8sp2
bne w8sp
w8sp1
jsr w8sp2
beq w8sp1
lda #0
sta $c6
w8sp2
ldx $01
stx xx+1
ldx #$37
stx $01
lda $dc00
and $dc01
and #$10
php
xx ldx #$00
stx $01
plp
rts
.endif
shiftsprites
; sta reta+1
; stx retx+1
; sty rety+1
M SET 0
REPEAT 8
lda firstbyte+[$40*7]+2 +[3*M]
sta $06
clc
rol
rol firstbyte+[$40*7]+1 +[3*M]
rol firstbyte+[$40*7]+0 +[3*M]
rol firstbyte+[$40*6]+2 +[3*M]
rol firstbyte+[$40*6]+1 +[3*M]
rol firstbyte+[$40*6]+0 +[3*M]
rol firstbyte+[$40*5]+2 +[3*M]
rol firstbyte+[$40*5]+1 +[3*M]
rol firstbyte+[$40*5]+0 +[3*M]
rol firstbyte+[$40*4]+2 +[3*M]
rol firstbyte+[$40*4]+1 +[3*M]
rol firstbyte+[$40*4]+0 +[3*M]
rol firstbyte+[$40*3]+2 +[3*M]
rol firstbyte+[$40*3]+1 +[3*M]
rol firstbyte+[$40*3]+0 +[3*M]
rol firstbyte+[$40*2]+2 +[3*M]
rol firstbyte+[$40*2]+1 +[3*M]
rol firstbyte+[$40*2]+0 +[3*M]
rol firstbyte+[$40*1]+2 +[3*M]
rol firstbyte+[$40*1]+1 +[3*M]
rol firstbyte+[$40*1]+0 +[3*M]
rol firstbyte+[$40*0]+2 +[3*M]
rol firstbyte+[$40*0]+1 +[3*M]
rol firstbyte+[$40*0]+0 +[3*M]
rol $06
lda $06
sta firstbyte+[$40*7]+2 +[3*M]
M SET M+1
repend
.if debug == 1
jsr w8sp
.endif
;reta lda #00
;retx ldx #00
;rety ldy #00
rts
-
Per ottenere un simpatico effetto, da monitor fate:
> d01d 81
> d000 28
Espandendo il primo e ulitmo sprite si ottiene una specie di effetto 3D
-
Allego il prg compilato.
Colgo l'occasione per ringraziare Rob per aver abilitato la feature, la comunita' tutta ringraziera' :continuacosi: