Sprite/movesprite
Aus C64-Wiki
Zur Navigation springenZur Suche springenDas Assembler-Programm movesprite demonstriert die Bewegung eines Sprites und zeigt dabei seine Position an.
;******************************************************************************************** ;* create and move a simple sprite with coordinates displayed, (2021/22) by petrus * ;* based on David Roberts program at https://gist.github.com/biomood/1001256 * ;* openborder routine by "tonyp12" William Wobbler * ;* https://www.lemon64.com/forum/viewtopic.php?t=71739&sid=622fcffdd29a5588bdfa6c4ba17c825c * ;******************************************************************************************** !to "movesprite_v4.prg", cbm !ct pet ;useful rom routines strout = $ab1e ;stradr in (A/Y) clear = $e544 getin = $ffe4 scnkey = $ff9f bsout = $ffd2 ;sprite0 settings sprite0 = $07f8 color0 = $d027 sp0x = $d000 sp0y = $d001 msbx = $d010 control1= $d011 sp0val = $0340 enable = $d015 control2= $d016 yexpand = $d017 xexpand = $d01d priority= $d01b ;colors color = $0286 border = $d020 backgr = $d021 * = $0801 ; BASIC start !byte $0b,$08,$0a,$00,$9e,$32,$30,$36,$34,$00 ;10 SYS 2064 * = $0810 ;2064 lda #6 ;blue sta backgr lda #14 ;lightblue sta border sta color jsr clear jsr infos lda #$0d ;using block 13 for sprite0 sta sprite0 lda #01 ;enable sprite0 sta enable sta priority ;sprite0 behind text lda #7 ;use yellow for sprite0 sta color0 ldx #0 lda #0 ;reset the spriteval data cleanup sta sp0val,x inx cpx #63 bne cleanup ;build the sprite ldx #0 build lda data,x sta sp0val,x inx cpx #63 bne build jsr init ;set sprite0 startcoordinates entry lda #1 sta $0289 ;disable keyboard buffer lda #64 sta $028a ;disable key repeat scan jsr dspxy sckey jsr scnkey ;get key jsr getin ;put petscii into .A start cmp #145 ;crsr-up bne cdown ldy sp0y dey sty sp0y jmp scan cdown cmp #17 ;crsr-down bne cleft ldy sp0y iny cy sty sp0y jmp scan cleft cmp #157 ;crsr-left bne cright dec sp0x ldx sp0x cpx #255 bne le lda msbx eor #1 cxl sta msbx le jmp scan cright cmp #29 ;crsr-right bne home inc sp0x ldx sp0x cpx #0 bne re lda msbx eor #1 sta msbx re jmp scan home cmp #19 bne top jsr init jmp scan top cmp #84 ;'t' bne bottom ldy #50 bne cy bottom cmp #66 ;'b' bne bleft ldy #229 bne cy bleft cmp #76 ;'l' bne bright lda #0 ;sta msbx ldx #24 stx sp0x bne cxl bright cmp #82 ;'r' bne plus ldx #64 ;320 and 255 stx sp0x lda #$01 sta msbx jmp scan plus cmp #43 ;plus bne swscr1 lda color0 eor #5 ;toggle 7<->2 (ylw/red) sta color0 lda $028a ;repeat-flag eor #64 ;toggle on/off sta $028a jmp scan swscr1 cmp #87 ;W (width) bne swscr2 jsr scrcols ;toggle 40/38 columns jmp scan swscr2 cmp #72 ;H (height) bne xexp jsr scrlines ;toggle 25/24 lines jmp scan xexp cmp #88 ;X bne yexp lda xexpand eor #1 sta xexpand jmp scan yexp cmp #89 ;Y bne bopn lda yexpand eor #1 sta yexpand jmp scan bopn cmp #79 ;O : open Border bne bclos jsr opbd jsr crnchr jmp scan bclos cmp #67 ;C : close Border bne entr jsr crnclr jsr clbd jmp scan entr cmp #13 ;end if enter beq end jmp sckey ;clean up at the end end jsr clear lda #0 sta enable rts ;position init lda #0 ;stick with x0-255 sta msbx ;starting sprite location ldx #168 ldy #170 stx sp0x sty sp0y rts dspxy lda #1 ;white sta color ldx #12 ldy #18 clc jsr $fff0 ;setcrsr lda msbx ldx sp0x jsr $bdcd ;dsp 16-bit number jsr spcout ldx #13 ldy #18 clc jsr $fff0 ;setcrsr lda #0 ldx sp0y jsr $bdcd ;dsp 16-bit number jsr spcout lda #14 sta color rts spcout lda #$20 ;2x space jsr bsout jsr bsout rts scrcols lda control2 eor #$08 sta control2 rts scrlines lda control1 eor #$08 ;do not use this if using raster irqs sta control1 rts infos lda #<info1 ldy #>info1 jsr strout lda #<info2 ldy #>info2 jsr strout rts info1 !by $0d !tx " move sprite with cursor ",$0d !tx " 't','b','l','r': jump to border",$0d !tx " 'home' jump to start position ",$0d !tx " '+' toggle key repeat ",$0d !tx " 'w' toggle screen columns 40/38",$0d !tx " 'h' toggle screen lines 25/24",$0d !tx " 'x' x-expand sprite ",$0d,0 info2 !tx " 'y' y-expand sprite ",$0d !tx " 'o' open / 'c' close border ",$0d !tx " 'return' end programm ",0 ;define the sprite data !byte %########,%########,%######## !byte %#....###,%########,%######## !byte %#....###,%########,%######## !byte %#....###,%########,%######## !byte %#....###,%########,%######## !byte %########,%########,%######## !byte %########,%########,%######## !byte %########,%########,%######## !byte %########,%########,%######## !byte %########,%########,%######## !byte %########,%########,%######## !byte %########,%########,%######## !byte %########,%########,%######## !byte %########,%########,%######## !byte %########,%########,%######## !byte %########,%########,%######## !byte %########,%########,%######## !byte %########,%########,%######## !byte %########,%########,%######## !byte %########,%########,%######## !byte %########,%########,%######## ;--- open border (by tonyp12) ------------------- opbd sei ; set interrupt bit, make the cpu ignore interrupt requests lda #%01111111 ; switch off interrupt signals from cia-1 sta $dc0d and $d011 ; clear most significant bit of vic's raster register sta $d011 lda $dc0d ; acknowledge pending interrupts from cia-1 lda $dd0d ; acknowledge pending interrupts from cia-2 ldx #<irq ; set interrupt vectors, pointing to interrupt service routine below stx $0314 ldx #>irq stx $0315 ldx #%00000001 ; enable raster interrupt signals from vic stx $d01a dex ; was a one above stx $3fff ; clear garbage cli ; clear interrupt flag, allowing the cpu to respond to interrupt requests rts irq asl $d019 ; acknowledge the interrupt by clearing the vic's interrupt flag selfmod ldx #0-0 ; 249 or 27 stx $d012 ; set next rasterline where interrupt shall occur bmi restore25 ; branch if bit 7 set ldx #249 ; value over 128 is a 'minus' stx selfmod+1 ldx #$13 ; set 24 rows, has to be be done on line 249 stx $d011 ; scrolly trick for no border jmp $ea31 ; keyboard scan restore25 ldx #$1b ; decimal 27 stx $d011 ; undo scroll on any other line stx selfmod+1 ; set rasterline where interrupt shall occur jmp $ea81 ; no keyboard scan ;------------------------ clbd sei lda #%01111111 sta $dc0d and $d011 sta $d011 lda $dc0d lda $dd0d ldx #$31 ; restore interrupt vector stx $0314 ldx #$ea stx $0315 ldx #%00000000 ; disable raster interrupt signals from vic stx $d01a cli ; clear interrupt flag rts crnchr lda #99 ldy #100 bne poke crnclr lda #32 tay poke sta $0400 sta $0400+39 sty $0400+960 sty $0400+999 rts .end