Jump to content
IGNORED

Need some help with getting rid of excess code


Recommended Posts

I'm working on the Polarium game and I need help, specifically with drawing the PF. So why did I post it here and not in the bB subforum? Because the part I need help with is in ASM. I decided that instead of the playfield data being this:


  %11111111, %11111111, %11111111, %11111111
  %00000000, %00000001, %00000000, %00000000
  %01111110, %00001001, %01000101, %01110100
  %01000010, %00001101, %01000101, %00010101
  %01110110, %00001001, %01000101, %00010110
  %01101110, %11001001, %01000101, %01110100
  %01000010, %00001001, %01000101, %00010100
  %01111110, %00011101, %01110101, %01110100
  %00000000, %00000001, %00000000, %00000000
  %11111111, %11111111, %11111111, %11111111
  %11111111, %11111111, %11111111, %11111111

I could just shorten it to this:


  %11111111
  %00000000
  %01111110
  %01000010
  %01110110
  %01101110
  %01000010
  %01111110
  %00000000
  %11111111
  %11111111

Thus saving 32 bytes per level, since the other three columns are the same per level (spelling out "1-LINE"). The code that 'prints' the playfield data on the screen is thus:

  asm
  lda #$00
  sta temp2
  lda ballx
  asl
  adc ballx
  asl
  rol temp2
  asl
  rol temp2
  sec
  sbc ballx
  bcs *+4
  dec temp2
  asl
  rol temp2
  asl
  rol temp2
  adc #<PF_dat1
  sta temp1
  lda temp2
  adc #>PF_dat1
  sta temp2
end

load_new_level3
 asm
 ldy #43
load_loop
 lda (temp1),y
 sta var0,y
 dey
 bpl load_loop
end

ballx being the level number because I ran out of a-z variables. So what I want to do is change this code so it only prints the left-most column. I tried various things but nothing seems to be working. Help me please.

Link to comment
Share on other sites

 something like this maybe? (I didn't include the tables)
 how many levels? this needs an extra byte per for the x 11 table
 and assumes col0 data is all in one page so 256/11 = 23 levels max

  ldx #$2B
loop_pf
  lda pf_dat,x    ; col0 will be over written but it's probably not worth trying to avoid
  sta var0,x
  dex
  bbl loop_pf

  ldx level        ;  ballx
  ldy x11,x        ;  level x 11 look up
  ldx #$00
  lda #>col0_dat
  sta temp2
  lda #<col0_dat
  sta temp1
loop_col0
  lda (temp1),y
  sta var0,x
  iny
  inx
  inx
  inx
  inx
  cpx #$2C
  bne loop_col0

 

edit: the ending value for x is 44 (not var44, duh ;) )

Edited by bogax
goofed the cpx, didn't store the lo byte of the pointer, typos in the reason for edit
Link to comment
Share on other sites

 lda #>col0_dat
  sta temp2
  lda #<col0_dat 
loop_col0

I haven't looked at the logic of that code, but the above is missing a "sta temp2+1" just before the loop.

And inside the loop it looks like it should be "lda (temp2),y" not "lda (temp1),y"

And finally, no idea what that "cpx #var43" is, but that's something else to check.

 

Link to comment
Share on other sites

must be something else going on

the playfield color changed, the score is corrupted, the movement is messed up

 

edit

fixed some of that

score is still corrupted, but I suppose you're using custom characters

Edited by bogax
update
Link to comment
Share on other sites

47 minutes ago, bogax said:

must be something else going on

the playfield color changed, the score is corrupted, the movement is messed up

  lda #>col0_dat
  sta temp2
  lda #<col0_dat
  sta temp1
loop_col0

 

If you are using (zp),y addressing, it is common usage to declare the variable (zp) as two bytes and then store low byte to zp, and high byte to zp+1.

The above still looks wrong to me, using two variables, one for the high (temp2) and one for the low (temp1).  In (zp),y addressing, zp is a single variable which happens to be two bytes in size. It's not two variables, temp1 and temp2.

So, I would still say the above looks wrong. If you use "lda (temp1),y" inside the loop, then store to temp1 (low) and temp1+1 (high) in the setup outside the loop.

 

 

Link to comment
Share on other sites

I got this working. Since I probably will plan to have more than just 23 levels, I will just repeat the code and have it look up different data (like I did in Castle of Doom). One thing I don't understand though is the x11 thing you did. I ended up putting in data numbers divisible by 11 (0, 11, 22, 33). Don't know what that's all about. Thank you, and this did save a bunch of room.

Link to comment
Share on other sites

I was able to save even more room by modifying the code a tiny bit:


 asm
  ldx level        ;  ballx
  ldy x11,x        ;  level x 11 look up
  ldx #$8
  lda #>col0_dat
  sta temp2
  lda #<col0_dat
  sta temp1
loop_col0
  lda (temp1),y
  sta var0,x
  iny
  inx
  inx
  inx
  inx
  cpx #$20
  bne loop_col0
end

   return otherbank

 data x11
  0, 6, 12, 18
end

 data col0_dat
  %01111110
  %01000010
  %01110110
  %01101110
  %01000010
  %01111110

  %00100100
  %01100110
  %00111100
  %00100100
  %00011000
  %01100110

  %00111100
  %01011010
  %01111110
  %01011010
  %01100110
  %00111100

  %01000010
  %01111110
  %01001010
  %01111110
  %01010010
  %01111110
end


Link to comment
Share on other sites

On 5/23/2020 at 7:06 AM, atari2600land said:

I got this working. Since I probably will plan to have more than just 23 levels, I will just repeat the code and have it look up different data (like I did in Castle of Doom). One thing I don't understand though is the x11 thing you did. I ended up putting in data numbers divisible by 11 (0, 11, 22, 33). Don't know what that's all about. Thank you, and this did save a bunch of room.

you could substitute your times 11 (44) code for the table

I think I figured break even was about 8 levels

incidentally I think you weren't initializing y in your original code

 

 

 here the [byte] column 0 playfield data is transposed so essentially there's a table

 for each row of the playfield and the data is selected by the level and you loop through the tables
 so now you can have 256 levels or whatever you can fit into the bank (which ever is less

 

 the times 11 and indexing is built into the pf_ptr_dat table and x is just a pointer

 

 it compiles but I didn't go beyond the first level

 

load_new_level3

  const number_of_levels = 3

  asm
  ldx #$2B
loop_pf
  lda pf_dat,x    ; col0 will be over written but it's probably not worth trying to avoid
  sta var0,x
  dex
  bpl loop_pf

  lda #<col_dat
  sta temp1
  lda #>col_dat
  sta temp2
  lda #$00
  sta temp3

loop_col

  ;  get the playfield pointer
  ldy temp3
  ldx pf_ptr_dat,y

  ;  get the level pointer and move the column 0 data
  ldy ballx
  lda (temp1),y
  sta $00,x

  ;  increment the data pointer
  lda temp1
  clc
  adc #number_of_levels
  sta temp1
  bcc *+4
  inc temp2

  ; increment the playfield pointer pointer
  inc temp3

  cpx #var40
  bne loop_col
end  

  return otherbank


  data pf_ptr_dat
  var0,  var4,  var8, var12, var16, var20, var24, var28, var32,  var36,  var40
end

 data pf_dat
  %00000000, %11111111, %11111111, %11111111
  %00000000, %00000001, %00000000, %00000000
  %00000000, %00001001, %01000101, %01110100
  %00000000, %00001101, %01000101, %00010101
  %00000000, %00001001, %01000101, %00010110
  %00000000, %11001001, %01000101, %01110100
  %00000000, %00001001, %01000101, %00010100
  %00000000, %00011101, %01110101, %01110100
  %00000000, %00000001, %00000000, %00000000
  %00000000, %11111111, %11111111, %11111111
  %00000000, %11111111, %11111111, %11111111
end

  data col_dat
  %11111111, %11111111, %11111111
  %00000000, %00000000, %00000000
  %01111110, %00100100, %00111100
  %01000010, %01100110, %01011010
  %01110110, %00111100, %01111110
  %01101110, %00100100, %01011010
  %01000010, %00011000, %01100110
  %01111110, %01100110, %00111100
  %00000000, %00000000, %00000000
  %11111111, %11111111, %11111111
  %11111111, %11111111, %11111111
end

Edited by bogax
clarification
Link to comment
Share on other sites

 OK one more

 y is now the page and temp2 the level index
 that saves a couple of bytes and a couple cycles in the loop

 back to incrementing x

 branches into the loop to avoid an unneeded increment of the pointers
 

load_new_level3

  const number_of_levels = 4

  ;  initialize the playfield
  asm
  ldx #$2B
loop_pf
  lda pf_dat,x    ; col0 will be over written but it's probably not worth trying to avoid
  sta var0,x
  dex
  bpl loop_pf

  ;  initialize pointers
  ldy #<col_dat
  lda level
  sta temp1
  lda #>col_dat
  sta temp2
  ldx #var8
  bne enter_col0_loop

loop_col
  ;  increment the data pointer
  tya
  clc
  adc #number_of_levels
  tay
  bcc increment_playfield_pointer
  inc temp2

increment_playfield_pointer
  inx
  inx
  inx
  inx

enter_col0_loop
  ;  move the column 0 data
  lda (temp1),y
  sta $00,x

  cpx #var28
  bne loop_col
end  

  return otherbank


 data pf_dat
  %11111111, %11111111, %11111111, %11111111
  %00000000, %00000001, %00000000, %00000000
  %00000000, %00001001, %01000101, %01110100
  %00000000, %00001101, %01000101, %00010101
  %00000000, %00001001, %01000101, %00010110
  %00000000, %11001001, %01000101, %01110100
  %00000000, %00001001, %01000101, %00010100
  %00000000, %00011101, %01110101, %01110100
  %00000000, %00000001, %00000000, %00000000
  %11111111, %11111111, %11111111, %11111111
  %11111111, %11111111, %11111111, %11111111
end

  data col_dat
  %01111110, %00100100, %00111100, %01000010
  %01000010, %01100110, %01011010, %01111110
  %01110110, %00111100, %01111110, %01001010
  %01101110, %00100100, %01011010, %01111110
  %01000010, %00011000, %01100110, %01010010
  %01111110, %01100110, %00111100, %01111110
end


 

Edited by bogax
fix the data, touch up the code, satisfy the critics
Link to comment
Share on other sites

10 minutes ago, bogax said:

  bcc *+4

 

 

Dangerous, and unnecessary.

Use a label to branch to.  That way, if you insert code between the branch and the destination it will still work.

The above is just asking for trouble!

 

Edited by Andrew Davie
Link to comment
Share on other sites

6 minutes ago, Andrew Davie said:

Dangerous, and unnecessary.

Use a label to branch to.  That way, if you insert code between the branch and the destination it will still work.

The above is just asking for trouble!

worse than that I think is it's harder to read and keep track of

Edited by bogax
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...