CabaretVoltaire Posted February 21, 2005 Share Posted February 21, 2005 I am learning 6809 assembly language (which is my first assembly language) and am having difficulties doing array like code. I have made a variable: InvaderXY equ $c886 and left space for 25 entries before the next variable I give set the coords at start up: lda #10 sta #InvaderXY sta #InvaderXY+2 sta #InvaderXY+4 sta #InvaderXY+6 sta #InvaderXY+8 lda #10 sta #InvaderXY+1 lda #20 sta #InvaderXY+3 lda #30 sta #InvaderXY+5 lda #40 sta #InvaderXY+7 lda #50 sta #InvaderXY+9 ..which should spread them out a bit to draw the vectors I do this: lda #0 sta Temp ;set Temp to 0 drawBadGuys: jsr RESET0REF ldx #InvaderXY ;set X as the address of InvaderXY lda Temp,x ;put value at (InvaderXY + X) into A inc Temp ;add 1 to Temp to get the X coordinate ldb Temp,x ;put value ..... into B ....draw the object at ldb,lda.. loop around until all are drawn This doesn't seem to work though.. What is the best way to create/read/write array type variables in 6809 asm? Thanks Quote Link to comment Share on other sites More sharing options...
Bruce Tomlin Posted February 22, 2005 Share Posted February 22, 2005 (edited) sta #InvaderXY '#' means immediate mode. you don't store immediate. (actually there are places in the opcodes for a store immediate, but it always stores an FF, or FF followed by the low byte for a 2-byte store) Hey, this ain't no stinking 6502! You have a real index register, you know! here's a better version of your initialization, but a loop would be better lda #10 ldb #10 ldx #InvaderXY; or leax InvaderXY,PC if you're doing position-independent code std ,x++ ldb #20 std ,x++ ldb #30 std ,x++ ldb #40 std ,x++ ldb #50 std ,x++ this is a little better version of the other part: ldx #InvaderXY; base address ldb #invadernumber aslb; multiply by 2 incb; X is the second byte lda b,x; get X position adda #10 sta b,x cmpa #60 bls .1 lda #10; go back to the left sta b,x decb; Y is the first byte lda b,x; get Y position adda #10 sta b,x .1: except this is really the "right" way to do it: ldx #InvaderXY; base address ldb #invadernumber aslb; multiply by 2 leax b,x; now X points to the current invader lda 1,x; get X position adda #10 sta 1,x cmpa #60 bls .1 lda #10; go back to the left sta 1,x lda 0,x; get Y position adda #10 sta 0,x .1: One other thing to watch out for on with the Vectrex is that IIRC, some of the Exec calls expect the DP register =D0 and some expect it =C8. /got paid to work on 6809 code for over four years Edited April 12, 2005 by Bruce Tomlin Quote Link to comment Share on other sites More sharing options...
CabaretVoltaire Posted February 22, 2005 Author Share Posted February 22, 2005 Thanks for you help! I have a couple of questions though, if you don't mind. What do these mean: lda 1,x sta 1,x I know what ld and st do but don't understand the "1,x".. Does it mean load/store at 1 + x? The pdf I have doesn't seem to detail all of the addressing modes... Also I have found a problem with comparing negative numbers with positive numbers.. The code would be something like: moveBaddies: ;moves the enemies in direction EnemyDir (which is either 4, or -4) lda EnemyX adda EnemyDir sta EnemyX ;see if enemies have gone too far left cmpa #-110 bls changeDirR ;if if enemies have gone too far right ;this is where the problem is, if this number isn't negative then ;the comparison doesn't work. cmpa #-5 bhs changeDirL ;otherwise skip ahead to the next section bra fireBullet changeDirL: lda #-4 sta EnemyDir bra fireBullet changeDirR: lda #4 sta EnemyDir Thanks again for your help Quote Link to comment Share on other sites More sharing options...
FURY Posted February 22, 2005 Share Posted February 22, 2005 Try ble instead of bls, and bge instead of bhs. George Quote Link to comment Share on other sites More sharing options...
Bruce Tomlin Posted February 23, 2005 Share Posted February 23, 2005 Signed compares: BLE BLT BGE BGT Unsigned compares: BLS BLO BHI BHS (note: BCC=BHS and BCS=BLO) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.