Jump to content
IGNORED

Converting Player position to an antic 4 screen


Recommended Posts

What's the best way to synchronize the position of a player with characters on an antic 4 screen? By keeping track with counters or by performing math to convert the player position to 0-23 and 0-39?

 

I've attempted to use the counter method in the code below (it gets a little messed up when you move left and I haven't solved that issue yet).

 

What I'm attempting to do is have the robot character (to be redrawn and made 22 pixels high, instead of the current 16) move around the screen and for the code to translate the robot's position to a position on the screen. To have some visual proof that it's working the code plots an "A" when you press trigger.

 

But is this the fastest way? Is there a better way of doing it?

 

And I should explain that eventually the robot will move left and right, fall of platforms, and engage with items on screen, but for now I'm only attempting to link player and character movement up.

 

Thanks.

 

*=$4000

p1     		= $d0
p2     		= $d2

xpos    	= 1536
ypos    	= 1537
joystick 	= 1538

p0hpos		= 1539
p0vpos		= 1540       
smlframe 	= 1541
frame		= 1542
playcount 	= 1543

xpm2scn		= 1544
ypm2scn		= 1545
xpm		= 1546
ypm		= 1547

begin   lda #<scr       ; start by calculating look-up tables
       sta p1         ; at the same time, we will clear the
       lda #>scr       ; screen
       sta p1+1

       ldx #0          
c0      lda #0          ; draw a character
       ldy #39         ; clear a single line
c1      ;sta (p1),y	;  WRITES OVER SCREEN
       dey
       bpl c1

       lda p1+1         ; store address into look-up table
       sta schi,x
       lda p1
       sta sclo,x
       clc             ; update zero page to next line
       adc #40         ; 40 bytes per line
       sta p1
       bcc c2
       inc p1+1
c2      inx             ; for all 24 lines...
       cpx #24
       bne c0

       lda #4          ; set some colors
       sta 708         ; make ANTIC4 slightly more readable
       lda #6
       sta 709
       lda #8
       sta 710

       lda #<DLIST     ; finally, point ANTIC to new display
       sta 560
       lda #>DLIST
       sta 561

; Main loop
             
pmmover        
       lda #$80        ; reserve 8 pages
       sta 54279       ; ... and in PMBASE
       lda #32         ;
       sta 623
       lda #62         ; turn on DMACTL. 46 is single-resolution
       sta 559
       lda #3          ; turn on GRACTL
       sta 53277
       lda #16		; single resolution players
       sta 54272
       lda #104	;
       sta 704         ; color players
       lda #28
       sta 705
       lda #0
       sta 710
  
; set up pm-to-screen
       lda #0
       sta smlframe
       lda #48+4	; starting position of pm. +4 is one character width
       sta p0hpos
       lda #32+4	; adding one char?
       sta p0vpos   
routine 
       lda $14         ; slow things down
delay   cmp $14         ; "
       beq delay       ; "

       lda p0hpos      ; store horizontal pos
       sta 53248
       sta 53249

lda #18		;size of player
sta playcount	
       ldx frame       ; begin height count    
ldy p0vpos
drawloop        
       lda shape,x     ; read shape data
       sta $8400,y     ; draw player 
       lda shape2,x    ; read shape data
       sta $8500,y     ; draw player 
       inx
       iny
dec playcount
       lda playcount
       bne drawloop    ; ...and repeat

       sty xpos
       stx ypos

       lda 644		;trigger (0) pressed?
       cmp #0
       bne stickread
       ldx ypm		; xpm	;get pm-to-screen coordinates
ldy xpm		;y carries horizontal
       lda #33		; get ready to print "A"
       jsr jplotchar

stickread                
       lda 632         ;joystick
cmp #13
bne up
inc p0vpos
inc ypm2scn
lda ypm2scn
cmp #8
beq down1
jmp routine
down1
lda #0
sta ypm2scn
inc ypm
jmp routine
up
lda 632
cmp #14
bne right
dec p0vpos
dec ypm2scn
lda ypm2scn
cmp #0
beq up1
jmp routine
up1
lda #8
sta ypm2scn
clc
dec ypm
jmp routine
right
lda 632
cmp #7
bne left
clc
inc p0hpos 
inc xpm2scn
lda xpm2scn
cmp #3
bne right1
lda #0
sta xpm2scn
inc xpm
right1
inc smlframe
lda smlframe
cmp #4
beq right2
jmp routine
right2	
lda #0	;reset smlframe
sta smlframe
inc p0hpos
clc
lda frame
adc #18 ; this will become 24
sta frame
cmp #54
beq right3
jmp routine
right3
lda #18
sta frame
jmp routine
left
lda 632
cmp #11
beq left0
leftexit
jmp routine
left0
dec p0hpos 
dec xpm2scn
lda xpm2scn
cmp #0
bne left1
lda #3
sta xpm2scn
dec xpm
left1
inc smlframe
lda smlframe
cmp #4
beq left2
jmp routine
left2	
lda #0	;reset smlframe
sta smlframe
dec p0hpos
clc
lda frame
adc #18 ; this will become 24
sta frame
cmp #54
beq left3
jmp routine
left3
lda #18
sta frame
jmp routine

;plot a character <A> at (Y,X)
jplotchar        
       pha
       lda sclo,x      ; set up zero-page address
       sta p1
       lda schi,x
       sta p1+1
       pla
       sta (p1),y
       rts
    
*=$8000
shape
       .byte 0,102,0,126,126,102,0,0,0,255,255,219,255,60,255,24,231,0; rest
       .byte 0,126,120,126,126,126,0,0,0,255,255,251,255,60,109,255,182,0; frame 1, right
       .byte 0,0,126,120,126,126,126,0,0,255,255,251,255,60,182,255,109,0; frame 2, right
       .byte 0,0,0,126,120,126,126,126,0,255,255,253,255,60,219,126,219,0; frame 3, right
*=$8100
shape2
       .byte 0,0,90,126,0,0,24,24,24,129,129,231,0,0,231,231,231,0; rest
       .byte 0,0,6,6,0,0,24,24,24,48,96,24,0,0,255,129,255,0; frame 1, right
       .byte 0,0,0,6,6,0,0,24,24,48,48,60,0,0,255,129,255,0 ;frame 2, right
       .byte 0,0,0,0,6,6,0,0,24,48,24,14,0,0,255,129,255,0; frame 1, right
DLIST
       .byte 112,112,112                        ; blank lines
       .byte 68,<scr,>scr                       ; 24 lines of ANTIC 4
       .byte 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4
       .byte 4,4,4,4,4,4,4
       .byte 65,<DLIST,>DLIST                   ; Jump to top

       *=$5000
;scr     .ds 40*24                                ; 960 bytes for screen
scr	.sbyte "****************************************"
.sbyte "*                                      *"
.sbyte "*                                      *"
.sbyte "*                                      *"
.sbyte "*                       ===============*"
.sbyte "*                       ===============*"
.sbyte "*                                      *"
.sbyte "*                                      *"
.sbyte "*                                      *"
.sbyte "*                                      *"
.sbyte "* ================                     *"
.sbyte "* ================                     *"
.sbyte "*                                      *"
.sbyte "*                                      *"
.sbyte "*                                      *"
.sbyte "*               ==========             *"
.sbyte "*               ==========             *"
.sbyte "*                                      *"
.sbyte "*                                      *"
.sbyte "* ==========                           *"
.sbyte "* ==========                           *"
.sbyte "*                                      *"
.sbyte "****************************************"	
sclo    .ds 24
schi    .ds 24

Link to comment
Share on other sites

My point of view on this.

 

* = $4000

p1              = $d0
p2              = $d2

xpos            = 1536
ypos            = 1537
joystick        = 1538

p0hpos          = 1539
p0vpos          = 1540       
smlframe        = 1541
frame           = 1542
playcount       = 1543

xpm2scn         = 1544
ypm2scn         = 1545
xpm             = 1546
ypm             = 1547

begin   lda #<scr       ; start by calculating look-up tables
       sta p1         ; at the same time, we will clear the
       lda #>scr       ; screen
       sta p1+1

       ldx #0          
c0      lda #0          ; draw a character
       ldy #39         ; clear a single line
c1      ;sta (p1),y     ;  WRITES OVER SCREEN
       dey
       bpl c1

       lda p1+1         ; store address into look-up table
       sta schi,x
       lda p1
       sta sclo,x
       clc             ; update zero page to next line
       adc #40         ; 40 bytes per line
       sta p1
       bcc c2
       inc p1+1
c2      inx             ; for all 24 lines...
       cpx #24
       bne c0

       lda #4          ; set some colors
       sta 708         ; make ANTIC4 slightly more readable
       lda #6
       sta 709
       lda #8
       sta 710

       lda #<DLIST     ; finally, point ANTIC to new display
       sta 560
       lda #>DLIST
       sta 561

; Main loop
             
pmmover        
       lda #$80        ; reserve 8 pages
       sta 54279       ; ... and in PMBASE
       lda #32         ;
       sta 623
       lda #62         ; turn on DMACTL. 46 is single-resolution
       sta 559
       lda #3          ; turn on GRACTL
       sta 53277
       lda #16         ; single resolution players
       sta 54272
       lda #104        ;
       sta 704         ; color players
       lda #28
       sta 705
       lda #0
       sta 710
  
; set up pm-to-screen
       lda #0
       sta smlframe
       lda #48+4       ; starting position of pm. +4 is one character width
       sta p0hpos
       lda #32+4       ; adding one char?
       sta p0vpos   
routine 
       lda $14         ; slow things down
delay   cmp $14         ; "
       beq delay       ; "

       lda p0hpos      ; store horizontal pos
       sta 53248
       sta 53249

       lda #18         ;size of player
       sta playcount   
       ldx frame       ; begin height count    
       ldy p0vpos
drawloop        
       lda shape,x     ; read shape data
       sta $8400,y     ; draw player 
       lda shape2,x    ; read shape data
       sta $8500,y     ; draw player 
       inx
       iny
       dec playcount
       lda playcount
       bne drawloop    ; ...and repeat

       sty xpos
       stx ypos

       lda 644         ;trigger (0) pressed?
       cmp #0
       bne stickread
	jsr set_adress
	jsr check_walls		
	
stickread
ldx 632
lda xstick,x
clc
adc p0hpos
sta p0hpos
lda ystick,x
clc
adc p0vpos
sta p0vpos
lda tabside,x
bne nochange
;frame rest = 0
sta frame
jmp routine
nochange
bpl	rightmove
;leftmove
lda p0hpos
lsr a
lsr a
and #$03
tax
lda tabframeright,x
sta frame
   jmp routine
rightmove
lda p0hpos
lsr a
lsr a
and #$03
tax
lda tabframeleft,x
sta frame
jmp routine

xstick		.byte 0,0,0,0,0,1,1,1,0,$FF,$FF,$FF,0,0,0,0
ystick		.byte 0,0,0,0,0,1,$FF,0,0,1,$FF,0,0,1,$FF,0                
tabside		.byte 0,0,0,0,0,1,1,1,0,$FF,$FF,$FF,0,0,0,0
tabframeright .byte 18,18,36,54	;frames for move right
tabframeleft  .byte 18,18,36,54	;frames for move left - no frames yet 
temp	.byte 0

check_walls
;p1=robot -lefthigh corner 
lda #33
ldy #$00
sta (p1),y
rts

set_adress
lda p0hpos
sec
sbc #48
lsr a
lsr a
sta temp
lda	p0vpos
sec 
sbc #32
lsr a
lsr a
lsr a
tax
lda sclo,x
sta p1
lda schi,x
sta p1+1
lda p1
clc
adc temp
sta p1
bcc skip
inc p1+1
skip
rts

*=$8000
shape
       .byte 0,102,0,126,126,102,0,0,0,255,255,219,255,60,255,24,231,0; rest
       .byte 0,126,120,126,126,126,0,0,0,255,255,251,255,60,109,255,182,0; frame 1, right
       .byte 0,0,126,120,126,126,126,0,0,255,255,251,255,60,182,255,109,0; frame 2, right
       .byte 0,0,0,126,120,126,126,126,0,255,255,253,255,60,219,126,219,0; frame 3, right
*=$8100
shape2
       .byte 0,0,90,126,0,0,24,24,24,129,129,231,0,0,231,231,231,0; rest
       .byte 0,0,6,6,0,0,24,24,24,48,96,24,0,0,255,129,255,0; frame 1, right
       .byte 0,0,0,6,6,0,0,24,24,48,48,60,0,0,255,129,255,0 ;frame 2, right
       .byte 0,0,0,0,6,6,0,0,24,48,24,14,0,0,255,129,255,0; frame 1, right
DLIST
       .byte 112,112,112                        ; blank lines
       .byte 68,<scr,>scr                       ; 24 lines of ANTIC 4
       .byte 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4
       .byte 4,4,4,4,4,4,4
       .byte 65,<DLIST,>DLIST                   ; Jump to top

       *=$5000
;scr     .ds 40*24                                ; 960 bytes for screen
scr     .sbyte "****************************************"
       .sbyte "*                                      *"
       .sbyte "*                                      *"
       .sbyte "*                                      *"
       .sbyte "*                       ===============*"
       .sbyte "*                       ===============*"
       .sbyte "*                                      *"
       .sbyte "*                                      *"
       .sbyte "*                                      *"
       .sbyte "*                                      *"
       .sbyte "* ================                     *"
       .sbyte "* ================                     *"
       .sbyte "*                                      *"
       .sbyte "*                                      *"
       .sbyte "*                                      *"
       .sbyte "*               ==========             *"
       .sbyte "*               ==========             *"
       .sbyte "*                                      *"
       .sbyte "*                                      *"
       .sbyte "* ==========                           *"
       .sbyte "* ==========                           *"
       .sbyte "*                                      *"
       .sbyte "****************************************"       
sclo    .ds 24
schi    .ds 24

Link to comment
Share on other sites

Ok extra idea about collision :)

 

* = $4000

p1              = $d0
p2              = $d2

xpos            = 1536
ypos            = 1537
joystick        = 1538

p0hpos          = 1539
p0vpos          = 1540       
smlframe        = 1541
frame           = 1542
playcount       = 1543

xpm2scn         = 1544
ypm2scn         = 1545
xpm             = 1546
ypm             = 1547

begin   lda #<scr       ; start by calculating look-up tables
       sta p1         ; at the same time, we will clear the
       lda #>scr       ; screen
       sta p1+1

       ldx #0          
c0      lda #0          ; draw a character
       ldy #39         ; clear a single line
c1      ;sta (p1),y     ;  WRITES OVER SCREEN
       dey
       bpl c1

       lda p1+1         ; store address into look-up table
       sta schi,x
       lda p1
       sta sclo,x
       clc             ; update zero page to next line
       adc #40         ; 40 bytes per line
       sta p1
       bcc c2
       inc p1+1
c2      inx             ; for all 24 lines...
       cpx #24
       bne c0

       lda #4          ; set some colors
       sta 708         ; make ANTIC4 slightly more readable
       lda #6
       sta 709
       lda #8
       sta 710

       lda #<DLIST     ; finally, point ANTIC to new display
       sta 560
       lda #>DLIST
       sta 561

; Main loop
             
pmmover        
       lda #$80        ; reserve 8 pages
       sta 54279       ; ... and in PMBASE
       lda #32         ;
       sta 623
       lda #62         ; turn on DMACTL. 46 is single-resolution
       sta 559
       lda #3          ; turn on GRACTL
       sta 53277
       lda #16         ; single resolution players
       sta 54272
       lda #104        ;
       sta 704         ; color players
       lda #28
       sta 705
       lda #0
       sta 710
  
; set up pm-to-screen
       lda #0
       sta smlframe
       lda #48+8       ; starting position of pm. +4 is one character width
       sta p0hpos
       lda #32+8       ; adding one char?
       sta p0vpos   
routine 
       lda $14         ; slow things down
delay   cmp $14         ; "
       beq delay       ; "

       lda p0hpos      ; store horizontal pos
       sta 53248
       sta 53249

       lda #18         ;size of player
       sta playcount   
       ldx frame       ; begin height count    
       ldy p0vpos
drawloop        
       lda shape,x     ; read shape data
       sta $8400,y     ; draw player 
       lda shape2,x    ; read shape data
       sta $8500,y     ; draw player 
       inx
       iny
       dec playcount
       lda playcount
       bne drawloop    ; ...and repeat

       sty xpos
       stx ypos

;       lda 644         ;trigger (0) pressed?
;       cmp #0
;       bne stickread
	jsr set_adress
	jsr check_walls		
	
stickread
ldx 632
lda xstick,x
clc
adc p0hpos
sta p0hpos
lda ystick,x
clc
adc p0vpos
sta p0vpos
lda tabside,x
bne nochange
;frame rest = 0
sta frame
jmp routine
nochange
bpl	rightmove
;leftmove
lda p0hpos
lsr a
lsr a
and #$03
tax
lda tabframeright,x
sta frame
   jmp routine
rightmove
lda p0hpos
lsr a
lsr a
and #$03
tax
lda tabframeleft,x
sta frame
jmp routine

xstick		.byte 0,0,0,0,0,1,1,1,0,$FF,$FF,$FF,0,0,0,0
ystick		.byte 0,0,0,0,0,1,$FF,0,0,1,$FF,0,0,1,$FF,0                
tabside		.byte 0,0,0,0,0,1,1,1,0,$FF,$FF,$FF,0,0,0,0
tabframeright .byte 18,18,36,54	;frames for move right
tabframeleft  .byte 18,18,36,54	;frames for move left - no frames yet 
temp	.byte 0

check_walls
;p1=robot -lefthigh corner 
ldy #$00
lda (p1),y
beq	checkhead2
lda 632
ora #$01
sta 632
jmp checkleft
checkhead2
iny
lda (p1),y
beq	checkleft
lda 632
ora #$01
sta 632
checkleft	
ldy #40
lda (p1),y
beq	checkright
lda 632
ora #$04
sta 632
checkright
iny
iny
lda (p1),y
beq checkfeet
lda 632
ora #$08
sta 632
checkfeet
ldy #80
lda (p1),y
beq	checkfeet2
lda 632
ora #$02
sta 632
checkfeet2
iny
lda (p1),y
beq checkend
lda 632
ora #$02
sta 632
checkend
rts

rts

set_adress
lda p0hpos
sec
sbc #48
lsr a
lsr a
sta temp
lda	p0vpos
sec 
sbc #32
lsr a
lsr a
lsr a
tax
lda sclo,x
sta p1
lda schi,x
sta p1+1
lda p1
clc
adc temp
sta p1
bcc skip
inc p1+1
skip
rts

*=$8000
shape
       .byte 0,102,0,126,126,102,0,0,0,255,255,219,255,60,255,24,231,0; rest
       .byte 0,126,120,126,126,126,0,0,0,255,255,251,255,60,109,255,182,0; frame 1, right
       .byte 0,0,126,120,126,126,126,0,0,255,255,251,255,60,182,255,109,0; frame 2, right
       .byte 0,0,0,126,120,126,126,126,0,255,255,253,255,60,219,126,219,0; frame 3, right
*=$8100
shape2
       .byte 0,0,90,126,0,0,24,24,24,129,129,231,0,0,231,231,231,0; rest
       .byte 0,0,6,6,0,0,24,24,24,48,96,24,0,0,255,129,255,0; frame 1, right
       .byte 0,0,0,6,6,0,0,24,24,48,48,60,0,0,255,129,255,0 ;frame 2, right
       .byte 0,0,0,0,6,6,0,0,24,48,24,14,0,0,255,129,255,0; frame 1, right
DLIST
       .byte 112,112,112                        ; blank lines
       .byte 68,<scr,>scr                       ; 24 lines of ANTIC 4
       .byte 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4
       .byte 4,4,4,4,4,4,4
       .byte 65,<DLIST,>DLIST                   ; Jump to top

       *=$5000
;scr     .ds 40*24                                ; 960 bytes for screen
scr     .sbyte "****************************************"
       .sbyte "*                                      *"
       .sbyte "*                                      *"
       .sbyte "*                                      *"
       .sbyte "*                       ===============*"
       .sbyte "*                       ===============*"
       .sbyte "*                                      *"
       .sbyte "*                                      *"
       .sbyte "*                                      *"
       .sbyte "*                                      *"
       .sbyte "* ================                     *"
       .sbyte "* ================                     *"
       .sbyte "*                                      *"
       .sbyte "*                                      *"
       .sbyte "*                                      *"
       .sbyte "*               ==========             *"
       .sbyte "*               ==========             *"
       .sbyte "*                                      *"
       .sbyte "*                                      *"
       .sbyte "* ==========                           *"
       .sbyte "* ==========                           *"
       .sbyte "*                                      *"
       .sbyte "****************************************"       
sclo    .ds 24
schi    .ds 24

Link to comment
Share on other sites

Thanks the real bb. My first attempt at the code used similar math but I was worried that it would slow things down, even in machine code.

Eagle, thank you again! I really need to start working up the graphics now to see how it's going to play.

Link to comment
Share on other sites

the logic described in the turbo basic screenshot is the right one

 

so... actually you do this

 

lda player_xpos ;shadow register not the hardware register

sec

sbc #border_value ;depends on your screen layout but for a 40 byte screen it is $30

lsr ;div 2

lsr ;div 2 = div 4

;now akku contains the collum

tay

lda player_ypos

sec

sbc #border

lsr ;div 2

lsr ;div 2

lsr ;div 2 = div 8

;now akku contains the row

tax

lda screentabl,x ;contains the start adress of each line precalculated in a lookup table

sta $b0

lda screentabh,x

sta $b1

lda ($b0),y ;read char at player position

 

my 2 cents

 

can not see a faster method for calculating out of player positions

Link to comment
Share on other sites

>can not see a faster method for calculating out of player positions

There are many.

It depends on how quickly you need and how much memory you have.

 

example for every line starts on page

 

ldx player_xpos
lda tabx,x
sta $B0
ldx player_ypos
lda taby,x
sta $B1
ldy #$00
lda ($b0),y
....
....

Link to comment
Share on other sites

Eagle, sure... but Avram is not yet into "hardcode optimisation" mode... he was thinking as far as I understood that the Turbo Basic "formulars" where hard to transfer into ASM. and I doubt that he is yet at the point where he is counting CPU-cycles wasted in lazy code segments... ;)

Link to comment
Share on other sites

Heaven, thanks for your take on the code. And you're correct - optimization is something I'm not capable of at the moment BUT what's good about the code that you, Eagle, Gauntman, Flashjazzcat, Groovybee etc have posted is that I'm forced to attempt to understand the more advanced 6502 coding. I'm learning absolutely loads right now and am still trying to understand the latest piece that Eagle wrote (i.e. why ORA to the joystick location and write it back?).

Link to comment
Share on other sites

;Tabstick - what you read from 632
;	0000	;--
;	0001	;--
;	0010	;--
;	0011	;--
;	0100	;--
;	0101	;right down
;	0110	;right up
;	0111	;right
;	1000	;----
;	1001	;left down
;	1010	;left up
;	1011	;left
;	1100	;---
;	1101	;down
;	1110	;up
;	1111	;no move
; simply - bit 0 = 0 - up
;          bit 1 = 0 - down
;          bit 2 = 0 - left
;          bit 3 = 0 - right

 

example:

I checked head - if char is there then i do ora #%0001 (ora #$01)

from table

; 1110 ;up - ora #%0001 = 1111 <- that means stick no move ;)

Edited by Eagle
Link to comment
Share on other sites

Okay Eagle - I'll admit I'm stumped (not all that hard to do).

 

1) I added the reversed frames for the robot so that it can 'walk' left. Besides adding the extra frames just The two things I changed were the heigh of each frame (it's gone from 18 bytes to 25 bytes) and this part here:

 

tabframeright .byte 18,18,36,54 ;frames for move right 
tabframeleft  .byte 18,18,36,54 ;frames for move left - no frames yet  

 

I assume that with my larger frames it should read like this:

 

tabframeright .byte 25,25,50,75 ;frames for move right 
tabframeleft  .byte 100,125,150,175 ;frames for move left - no frames yet  

 

The frames for the left frame follow immediately after the frames for the right.

 

PLAYER 0

frame 0, rest

frame 1, right

frame 2, right

frame 3, right

frame 1, left

frame 2, left

frame 3, left

 

PLAYER 1

(same structure)

 

I'm not on the computer I was working on but can post the code tomorrow. Right now it gets garbled when moving a different direction.

 

2) I haven't tackled this but wanted to ask this question. I want the robot to fall off platforms. Is it simply a matter of adding something along the lines of this?

 

checkfeet 
       ldy #80 
       lda (p1),y 
       beq     checkfeet2 
       is the character a space? If so, then fall
       is the character a unpainted platform? If so, then paint and decrease unpainted platform counter
       etc. 

       lda 632 
       ora #$02 
       sta 632 
checkfeet2 
       iny 
       lda (p1),y 
       beq checkend 
       is the character a space? If so, then fall
       is the character a unpainted platform? If so, then paint and decrease unpainted platform counter
       etc. 

       lda 632 
       ora #$02 
       sta 632 

 

Thanks!

Edited by Avram
Link to comment
Share on other sites

Your stick procedure was correct. But too long.

I just try show you different point of view.

With this stick procedure you will have some problems.

Not because of your programming skills.

Simply, it is different than others.

The procedure for jump, can cause you some problems.

But I think you can handle this.

 

* = $4000

p1              = $d0
p2              = $d2

xpos            = 1536
ypos            = 1537
joystick        = 1538

p0hpos          = 1539
p0vpos          = 1540       
smlframe        = 1541
frame           = 1542
playcount       = 1543

xpm2scn         = 1544
ypm2scn         = 1545
xpm             = 1546
ypm             = 1547

begin   lda #<scr       ; start by calculating look-up tables
       sta p1         ; at the same time, we will clear the
       lda #>scr       ; screen
       sta p1+1
       ldx #0          
c0      lda #0          ; draw a character
       ldy #39         ; clear a single line
c1      ;sta (p1),y     ;  WRITES OVER SCREEN
       dey
       bpl c1

       lda p1+1         ; store address into look-up table
       sta schi,x
       lda p1
       sta sclo,x
       clc             ; update zero page to next line
       adc #40         ; 40 bytes per line
       sta p1
       bcc c2
       inc p1+1
c2      inx             ; for all 24 lines...
       cpx #24
       bne c0

       lda #4          ; set some colors
       sta 708         ; make ANTIC4 slightly more readable
       lda #6
       sta 709
       lda #8
       sta 710

       lda #<DLIST     ; finally, point ANTIC to new display
       sta 560
       lda #>DLIST
       sta 561

; Main loop
             
pmmover        
       lda #$80        ; reserve 8 pages
       sta 54279       ; ... and in PMBASE
       lda #32         ;
       sta 623
       lda #62         ; turn on DMACTL. 46 is single-resolution
       sta 559
       lda #3          ; turn on GRACTL
       sta 53277
       lda #16         ; single resolution players
       sta 54272
       lda #104        ;
       sta 704         ; color players
       lda #28
       sta 705
       lda #0
       sta 710
  
; set up pm-to-screen
       lda #0
       sta smlframe
       lda #48+8       ; starting position of pm. +4 is one character width
       sta p0hpos
       lda #32+8       ; adding one char?
       sta p0vpos   
routine 
       lda $14         ; slow things down
delay   cmp $14         ; "
       beq delay       ; "

       lda p0hpos      ; store horizontal pos
       sta 53248
       sta 53249

       lda #18         ;size of player
       sta playcount   
       ldx frame       ; begin height count    
       ldy p0vpos
drawloop        
       lda shape,x     ; read shape data
       sta $8400,y     ; draw player 
       lda shape2,x    ; read shape data
       sta $8500,y     ; draw player 
       inx
       iny
       dec playcount
       lda playcount
       bne drawloop    ; ...and repeat

       sty xpos
       stx ypos

;       lda 644         ;trigger (0) pressed?
;       cmp #0
;       bne stickread
	jsr set_adress
	jsr check_walls		
	
stickread
ldx 632
lda xstick,x
clc
adc p0hpos
sta p0hpos
lda ystick,x
clc
adc p0vpos
sta p0vpos
lda tabside,x
bne nochange
;frame rest = 0
sta frame
jmp routine
nochange
bpl	rightmove
;leftmove
lda p0hpos
lsr a
lsr a
and #$03
tax
lda tabframeright,x
sta frame
   jmp routine
rightmove
lda p0hpos
lsr a
lsr a
and #$03
tax
lda tabframeleft,x
sta frame
jmp routine

xstick		.byte 0,0,0,0,0,1,1,1,0,$FF,$FF,$FF,0,0,0,0
ystick		.byte 0,0,0,0,0,1,$FF,0,0,1,$FF,0,0,1,$FF,0                
tabside		.byte 0,0,0,0,0,1,1,1,0,$FF,$FF,$FF,0,0,0,0
tabframeright .byte 18,36,54,36	;frames for move right
tabframeleft  .byte 18,36,54,36	;frames for move left - no frames yet 
temp	.byte 0

check_walls
;p1=robot -lefthigh corner 
ldy #$01
lda (p1),y
beq	checkleft
lda 632
ora #$01
sta 632
checkleft	
ldy #40
lda (p1),y
beq	checkright
lda 632
ora #$04
sta 632
checkright
iny
iny
lda (p1),y
beq checkfeet
lda 632
ora #$08
sta 632
checkfeet
ldy #81
lda (p1),y
beq fall_down
lda 632
ora #$02
sta 632
rts
fall_down
lda 632		;set stick down
and #$0d	;%1101
ora #$01	;clear stick up - robot fall down
sta 632
rts

set_adress
lda p0hpos
sec
sbc #48
lsr a
lsr a
sta temp
lda	p0vpos
sec 
sbc #32
lsr a
lsr a
lsr a
tax
lda sclo,x
sta p1
lda schi,x
sta p1+1
lda p1
clc
adc temp
sta p1
bcc skip
inc p1+1
skip
rts
*=$8000
shape
       .byte 0,102,0,126,126,102,0,0,0,255,255,219,255,60,255,24,231,0; rest
       .byte 0,126,120,126,126,126,0,0,0,255,255,251,255,60,109,255,182,0; frame 1, right
       .byte 0,0,126,120,126,126,126,0,0,255,255,251,255,60,182,255,109,0; frame 2, right
       .byte 0,0,0,126,120,126,126,126,0,255,255,253,255,60,219,126,219,0; frame 3, right
*=$8100
shape2
       .byte 0,0,90,126,0,0,24,24,24,129,129,231,0,0,231,231,231,0; rest
       .byte 0,0,6,6,0,0,24,24,24,48,96,24,0,0,255,129,255,0; frame 1, right
       .byte 0,0,0,6,6,0,0,24,24,48,48,60,0,0,255,129,255,0 ;frame 2, right
       .byte 0,0,0,0,6,6,0,0,24,48,24,14,0,0,255,129,255,0; frame 1, right
DLIST
       .byte 112,112,112                        ; blank lines
       .byte 68,<scr,>scr                       ; 24 lines of ANTIC 4
       .byte 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4
       .byte 4,4,4,4,4,4,4
       .byte 65,<DLIST,>DLIST                   ; Jump to top

       *=$5000
;scr     .ds 40*24                                ; 960 bytes for screen
scr     .sbyte "****************************************"
       .sbyte "*                                      *"
       .sbyte "*                                      *"
       .sbyte "*                                      *"
       .sbyte "*                       ===============*"
       .sbyte "*                       ===============*"
       .sbyte "*                                      *"
       .sbyte "*                                      *"
       .sbyte "*                                      *"
       .sbyte "*                                      *"
       .sbyte "* ================                     *"
       .sbyte "* ================                     *"
       .sbyte "*                                      *"
       .sbyte "*                                      *"
       .sbyte "*                                      *"
       .sbyte "*               ==========             *"
       .sbyte "*               ==========             *"
       .sbyte "*                                      *"
       .sbyte "*                                      *"
       .sbyte "* ==========                           *"
       .sbyte "* ==========                           *"
       .sbyte "*                                      *"
       .sbyte "****************************************"       
sclo    .ds 24
schi    .ds 24

Link to comment
Share on other sites

Okay. Here's the code with the new robot graphics. One of the things I don't understand is the frame code. I've expanded each frame to 25 bytes high but the code reading them incorrectly, as well as leaving a trail. What I am I doing wrong?

 

* = $4000

p1              = $d0
p2              = $d2

xpos            = 1536
ypos            = 1537
joystick        = 1538

p0hpos          = 1539
p0vpos          = 1540       
smlframe        = 1541
frame           = 1542
playcount       = 1543

xpm2scn         = 1544
ypm2scn         = 1545
xpm             = 1546
ypm             = 1547

begin   lda #<scr       ; start by calculating look-up tables
       sta p1         ; at the same time, we will clear the
       lda #>scr       ; screen
       sta p1+1
       ldx #0          
c0      lda #0          ; draw a character
       ldy #39         ; clear a single line
c1      ;sta (p1),y     ;  WRITES OVER SCREEN
       dey
       bpl c1

       lda p1+1         ; store address into look-up table
       sta schi,x
       lda p1
       sta sclo,x
       clc             ; update zero page to next line
       adc #40         ; 40 bytes per line
       sta p1
       bcc c2
       inc p1+1
c2      inx             ; for all 24 lines...
       cpx #24
       bne c0

       lda #4          ; set some colors
       sta 708         ; make ANTIC4 slightly more readable
       lda #6
       sta 709
       lda #8
       sta 710

       lda #<DLIST     ; finally, point ANTIC to new display
       sta 560
       lda #>DLIST
       sta 561

; Main loop
             
pmmover        
       lda #$80        ; reserve 8 pages
       sta 54279       ; ... and in PMBASE
       lda #32         ;
       sta 623
       lda #62         ; turn on DMACTL. 46 is single-resolution
       sta 559
       lda #3          ; turn on GRACTL
       sta 53277
       lda #16         ; single resolution players
       sta 54272
       lda #104        ;
       sta 704         ; color players
       lda #28
       sta 705
       lda #0
       sta 710
  
; set up pm-to-screen
       lda #0
       sta smlframe
       lda #48+8       ; starting position of pm. +4 is one character width
       sta p0hpos
       lda #32+8       ; adding one char?
       sta p0vpos   
routine 
       lda $14         ; slow things down
delay   cmp $14         ; "
       beq delay       ; "

       lda p0hpos      ; store horizontal pos
       sta 53248
       sta 53249

       lda #25         ;size of player
       sta playcount   
       ldx frame       ; begin height count    
       ldy p0vpos
drawloop        
       lda shape,x     ; read shape data
       sta $8400,y     ; draw player 
       lda shape2,x    ; read shape data
       sta $8500,y     ; draw player 
       inx
       iny
       dec playcount
       lda playcount
       bne drawloop    ; ...and repeat

       sty xpos
       stx ypos

       jsr set_adress
       jsr check_walls         
               
stickread
       ldx 632
       lda xstick,x
       clc
       adc p0hpos
       sta p0hpos
       lda ystick,x
       clc
       adc p0vpos
       sta p0vpos
       lda tabside,x
       bne nochange
;frame rest = 0
       sta frame
       jmp routine
nochange
       bpl     rightmove
;leftmove
       lda p0hpos
       lsr a
       lsr a
       and #$03
       tax
       lda tabframeright,x
       sta frame
   jmp routine
rightmove
       lda p0hpos
       lsr a
       lsr a
       and #$03
       tax
       lda tabframeleft,x
       sta frame
       jmp routine

xstick          .byte 0,0,0,0,0,1,1,1,0,$FF,$FF,$FF,0,0,0,0
ystick          .byte 0,0,0,0,0,1,$FF,0,0,1,$FF,0,0,1,$FF,0                
tabside         .byte 0,0,0,0,0,1,1,1,0,$FF,$FF,$FF,0,0,0,0
tabframeright .byte 25,25,50,75 ;frames for move right
tabframeleft  .byte 100,100,125,150 ;frames for move left - no frames yet 
temp    .byte 0

check_walls
;p1=robot -lefthigh corner 
       ldy #$01
       lda (p1),y
       beq     checkleft
       lda 632
       ora #$01
       sta 632
checkleft       
       ldy #40
       lda (p1),y
       beq     checkright
       lda 632
       ora #$04
       sta 632
checkright
       iny
       iny
       lda (p1),y
       beq 	checkfeet
       lda 632
       ora #$08
       sta 632
checkfeet
       ldy #81
       lda (p1),y
       beq 	fall_down
       lda 632
       ora #$02
       sta 632
       rts
fall_down
       lda 632         ;set stick down
       and #$0d        ;%1101
       ora #$01        ;clear stick up - robot fall down
       sta 632
       rts

set_adress
       lda p0hpos
       sec
       sbc #48
       lsr a
       lsr a
       sta temp
       lda     p0vpos
       sec 
       sbc #32
       lsr a
       lsr a
       lsr a
       tax
       lda sclo,x
       sta p1
       lda schi,x
       sta p1+1
       lda p1
       clc
       adc temp
       sta p1
       bcc skip
       inc p1+1
skip
       rts
*=$8000
shape
       .byte 0,102,126,0,0,24,60,126,60,36,24,0,255,255,231,165,36,60,255,24,24,0,0,0,0; rest. Note, pm is 26 bytes tall
       .byte 0,6,126,96,96,126,126,126,24,30,0,0,126,126,126,114,126,60,255,0,0,126,126,0,0; frame 1, right
       .byte 0,0,6,126,96,96,126,126,126,24,30,0,126,126,126,118,126,60,255,0,0,126,126,0,0; frame 2, right
       .byte 0,0,0,6,126,96,96,126,126,126,24,30,126,126,126,222,126,60,255,0,0,126,126,0; frame 3, right
.byte 0,96,126,6,6,126,126,126,24,120,0,0,126,126,126,78,126,60,255,0,0,126,126,126,0,0; frame 1; left
.byte 0,0,96,126,6,6,126,126,126,24,120,0,126,126,126,110,126,60,255,0,0,126,126,0,0; frame 2; left
.byte 0,0,0,96,126,6,6,126,126,126,24,120,126,126,126,123,126,60,255,0,0,126,126,0,0; frame 3; left
       
*=$8100
shape2
       .byte 0,0,0,00,90,126,24,0,0,0,24,24,195,129,153,153,219,0,255,231,0,231,0,231,0; rest
       .byte 0,0,0,0,26,2,2,0,0,0,24,24,0,32,32,60,0,0,255,0,221,129,1,238,0; frame 1, right
       .byte 0,0,0,0,0,26,2,2,0,0,0,24,0,32,64,120,0,0,255,0,238,1,129,221,0 ;frame 2, right
       .byte 0,0,0,0,0,0,26,2,2,0,0,0,0,32,64,224,0,0,255,0,119,128,129,187,0; frame 1, right
.byte 0,0,0,0,88,64,64,0,0,0,24,24,0,4,4,60,0,0,255,0,187,129,128,119,0; frame 1; left
.byte 0,0,0,0,88,64,64,0,0,0,24,0,4,2,30,0,0,255,0,119,128,129,187,0; frame 2; left
.byte 0,0,0,0,0,0,88,64,64,0,0,0,0,4,2,7,0,0,255,0,238,1,129,221,0; frame 3; left
DLIST
       .byte 112,112,112                        ; blank lines
       .byte 68,<scr,>scr                       ; 24 lines of ANTIC 4
       .byte 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4
       .byte 4,4,4,4,4,4,4
       .byte 65,<DLIST,>DLIST                   ; Jump to top

       *=$5000
;scr     .ds 40*24                                ; 960 bytes for screen
scr     .sbyte "****************************************"
       .sbyte "*                                      *"
       .sbyte "*                                      *"
       .sbyte "*                                      *"
       .sbyte "*                       ===============*"
       .sbyte "*                       ===============*"
       .sbyte "*                                      *"
       .sbyte "*                                      *"
       .sbyte "*                                      *"
       .sbyte "*                                      *"
       .sbyte "* ================                     *"
       .sbyte "* ================                     *"
       .sbyte "*                                      *"
       .sbyte "*                                      *"
       .sbyte "*                                      *"
       .sbyte "*               ==========             *"
       .sbyte "*               ==========             *"
       .sbyte "*                                      *"
       .sbyte "*                                      *"
       .sbyte "* ==========                           *"
       .sbyte "* ==========                           *"
       .sbyte "*                                      *"
       .sbyte "****************************************"       
sclo    .ds 24
schi    .ds 24

Link to comment
Share on other sites

You test me? :)

You lost two bytes in your data :)

 

*=$8000
shape
       .byte 0,102,126,0,0,24,60,126,60,36,24,0,255,255,231,165,36,60,255,24,24,0,0,0,0; rest. Note, pm is 26 bytes tall
       .byte 0,6,126,96,96,126,126,126,24,30,0,0,126,126,126,114,126,60,255,0,0,126,126,0,0; frame 1, right
       .byte 0,0,6,126,96,96,126,126,126,24,30,0,126,126,126,118,126,60,255,0,0,126,126,0,0; frame 2, right
       .byte 0,0,0,6,126,96,96,126,126,126,24,30,126,126,126,222,126,60,255,0,0,126,126,0,0 ; frame 3, right
       .byte 0,96,126,6,6,126,126,126,24,120,0,0,126,126,126,78,126,60,255,0,0,126,126,126,0,0 ;<- you lost 1 byte here (last zero)  - frame 1; left
       .byte 0,0,96,126,6,6,126,126,126,24,120,0,126,126,126,110,126,60,255,0,0,126,126,0,0; frame 2; left
       .byte 0,0,0,96,126,6,6,126,126,126,24,120,126,126,126,123,126,60,255,0,0,126,126,0,0; frame 3; left
b1       
*=$8100
shape2
       .byte 0,0,0,00,90,126,24,0,0,0,24,24,195,129,153,153,219,0,255,231,0,231,0,231,0; rest
       .byte 0,0,0,0,26,2,2,0,0,0,24,24,0,32,32,60,0,0,255,0,221,129,1,238,0; frame 1, right
       .byte 0,0,0,0,0,26,2,2,0,0,0,24,0,32,64,120,0,0,255,0,238,1,129,221,0 ;frame 2, right
       .byte 0,0,0,0,0,0,26,2,2,0,0,0,0,32,64,224,0,0,255,0,119,128,129,187,0; frame 1, right
       .byte 0,0,0,0,88,64,64,0,0,0,24,24,0,4,4,60,0,0,255,0,187,129,128,119,0; frame 1; left
       .byte 0,0,0,0,0,88,64,64,0,0,0,24,0,4,2,30,0,0,255,0,119,128,129,187,0; <- you lost 1 byte here (first zero) frame 2; left
       .byte 0,0,0,0,0,0,88,64,64,0,0,0,0,4,2,7,0,0,255,0,238,1,129,221,0; frame 3; left

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...