Code: Select all
Repeat a block of code a specified number of times.
Labels defined inside REPT are local.
i=0
REPT 256
DB i
i=i+1
ENDR
Moderator: Moderators
Code: Select all
Repeat a block of code a specified number of times.
Labels defined inside REPT are local.
i=0
REPT 256
DB i
i=i+1
ENDR
Code: Select all
i=0
.rept 256
lda #45
sta $4012
i=i+1
.endr
This is correct. A better way to describe it is: .rept/.endr allows you to "repeat generation of assembly code". E.g.WheelInventor wrote:AFAIK (correct me if i'm wrong), the .rept directive isn't meant for doing runtime loops, because it repeats your code at assembly-time. Your assembled code will get very long as .rept will hard-code every repetition for you.
Code: Select all
lda #$00
i=$1f
.rept 4
sta $0200+i
i=i+1
.endr
Code: Select all
lda #$00
sta $021f
sta $0220
sta $0221
sta $0222
Apologies, i think i may have caused more confusion than clarity; i shouldn't write when in a hurry. Unrolling may be the most efficient way if your function needs to execute quickly and you have the space to spare. .rept may be the most convenient way of doing it, depending on personal preference.What should I do to make loading metasprites the most efficent then?
Code: Select all
LoadYacaBackFrame1:
LDX $00
-
LDY yacaloadtable, x
LDA yacaback1, x
STA $201, y
INX
CPX $08
BNE -
RTS
yacaback1:
.db $02, %00000000, $02, %01000000, $12, %00000000,$13, %00000000
yacaloadtable:
.db $00, $01, $04, $05, $08, $09, $0C, $0D
Code: Select all
CheckPickupCollision:
LDA $204
SEC
SBC #$08
CMP PICKUP_RAM
BEQ +
BCC +
JMP CheckPickupCollisionRTS
+
LDA $210
CLC
ADC #$08
CMP PICKUP_RAM
BCS +
JMP CheckPickupCollisionRTS
+
LDA $203
CMP PICKUP_RAM + 3
BEQ +
BCC +
JMP CheckPickupCollisionRTS
+
LDA $20B
CLC
ADC #$08
CMP PICKUP_RAM + 3
BCS +
JMP CheckPickupCollisionRTS
+
Pickup1CollidesPlayer1:
LDA #$FF
STA PICKUP_RAM
STA PICKUP_RAM + 3
LDA #BEAM
STA P1_SPECIAL_TYPE
LDA #$03
STA P1_SPECIAL_AMOUNT
CheckPickupCollisionRTS:
RTS
Code: Select all
BasicEnemyPattern01:
LDX PATTERN_EXECUTION_DELAY
CPX #$00
BNE BasicEnemyPattern01_Execute_Prepare_Loop
LDX PATTERN_EXECUTION_IND1
CPX #$14
BEQ BasicEnemyPattern01_Execute_Prepare_Loop
BasicEnemyPattern01_Load:
LDY basicenemyloadtable, x
LDA #$21
STA BASIC_ENEMY_RAM + 1, y
LDA #%00000001
STA BASIC_ENEMY_RAM + 2, y
LDA #$00
STA BASIC_ENEMY_RAM + 3, y
LDA #$04
STA BASIC_ENEMY_RAM, y
INX
LDA #$22
STA BASIC_ENEMY_RAM + 5, y
LDA #%00000001
STA BASIC_ENEMY_RAM + 6, y
LDA #$08
STA BASIC_ENEMY_RAM + 7, y
LDA #$04
STA BASIC_ENEMY_RAM + 4, y
INX
STX PATTERN_EXECUTION_IND1
LDA #$20
STA PATTERN_EXECUTION_DELAY
BasicEnemyPattern01_Execute_Prepare_Loop:
LDX #$00
BasicEnemyPattern01_Check_Loop_Conditions:
LDY basicenemyloadtable, x
LDA BASIC_ENEMY_RAM + 1, y
CMP #$21
BEQ BasicEnemyPattern01_Loop_Section1
CMP #$23
BNE BasicEnemyPattern01_INC_Register
BasicEnemyPattern01_Loop_Section1:
LDA BASIC_ENEMY_RAM + 3, y
CLC
ADC #$01
STA BASIC_ENEMY_RAM + 3, y
LDA BASIC_ENEMY_RAM, y
CLC
ADC #$02
STA BASIC_ENEMY_RAM, y
LDA ANIM_TIMER_2
CMP #$00
BNE BasicEnemyPattern01_Loop_Section2
LDA BASIC_ENEMY_RAM + 1, y
CMP #$21
BEQ ShowBasicEnemyFrame2
CMP #$23
BNE BasicEnemyPattern01_Loop_Section2
ShowBasicEnemyFrame1:
LDA #$21
STA BASIC_ENEMY_RAM + 1, y
LDA #$00
STA CURRENT_BASIC_ENEMY_FRAME
JMP BasicEnemyPattern01_Loop_Section2
ShowBasicEnemyFrame2:
LDA #$23
STA BASIC_ENEMY_RAM + 1, y
LDA #$01
STA CURRENT_BASIC_ENEMY_FRAME
BasicEnemyPattern01_Loop_Section2:
INY
INY
INY
INY
LDA ANIM_TIMER_2
CMP #$00
BNE BasicEnemyPattern01_Loop_Section3
LDA CURRENT_BASIC_ENEMY_FRAME
CMP #$00
BNE +
LDA #$22
STA BASIC_ENEMY_RAM + 1, y
JMP BasicEnemyPattern01_Loop_Section3
+
CMP #$01
BNE +
LDA #$24
STA BASIC_ENEMY_RAM + 1, y
+
BasicEnemyPattern01_Loop_Section3:
LDA BASIC_ENEMY_RAM + 3, y
CLC
ADC #$01
STA BASIC_ENEMY_RAM + 3, y
LDA BASIC_ENEMY_RAM, y
CLC
ADC #$02
STA BASIC_ENEMY_RAM, y
BasicEnemyPattern01_INC_Register:
INX
CPX #$14
BNE BasicEnemyPattern01_Check_Loop_Conditions
BasicEnemyPattern01_End:
RTS
Code: Select all
P1_Idle_Animation:
LDA P1_CURRENT_FRAME
CMP #$00
BNE +
JSR Player1_LoadSprite_Idle1
+
LDA P1_CURRENT_FRAME
CMP #$01
BNE +
JSR Player1_LoadSprite_Idle2
LDA P1_CURRENT_FRAME
+
LDA P1_CURRENT_FRAME
CMP #$02
BNE +
JSR Player1_LoadSprite_Idle3
+
LDA P1_CURRENT_FRAME
CMP #$03
BNE +
JSR Player1_LoadSprite_Idle4
+
LDA P1_CURRENT_FRAME
CMP #$04
BNE +
JSR Player1_LoadSprite_Idle5
+
LDA P1_CURRENT_FRAME
CMP #$05
BNE +
JSR Player1_LoadSprite_Idle6and8
+
LDA P1_CURRENT_FRAME
CMP #$06
BNE +
JSR Player1_LoadSprite_Idle7
+
LDA P1_CURRENT_FRAME
CMP #$07
BNE +
JSR Player1_LoadSprite_Idle6and8
+
LDA P1_CURRENT_FRAME
CMP #$08
BNE +
JSR Player1_LoadSprite_Idle9
+
LDA P1_CURRENT_FRAME
CMP #$09
BNE +
JSR Player1_LoadSprite_Idle10
+
LDA P1_CURRENT_FRAME
CMP #$0A
BNE +
JSR Player1_LoadSprite_Idle11
+
LDA P1_CURRENT_FRAME
CMP #$0B
BNE +
JSR Player1_LoadSprite_Idle12
+
RTS
Yes.Is there any better way to do this?
Code: Select all
LDA $204
SEC
SBC #$08
CMP PICKUP_RAM
BEQ +
BCC +
JMP CheckPickupCollisionRTS
+
Code: Select all
LDA PICKUP_RAM
CMP $204
BCS +
RTS
+
Look at the OAM mirror at $200.3. Tile number 0 in the top left corner.
Seems good to me.if A >= 10
A = A - 10
B = B + 1
if B >= 10
B = B - 10
C = C + 1
Good or bad idea?
One way to do it is to load it once and decrement it each time. The 65c02 (CMOS) has a DEA (decrement accumulator) instruction; but if you're using an NMOS 6502, you'll have to use X or Y, then do for example:Are all these LDA P1_CURRENT_FRAME really neccessary or should I just load the value at the beginning only?
Code: Select all
P1_Idle_Animation:
LDY P1_CURRENT_FRAME
BNE +
JSR Player1_LoadSprite_Idle1 ; Look out! The RTS will come back here to continue
; the comparisons, which I doubt is what you wanted.
+
DEY
BNE +
JSR Player1_LoadSprite_Idle2
+
DEY
BNE +
JSR Player1_LoadSprite_Idle3
+
<etc.>
Code: Select all
LDA P1_CURRENT_FRAME
ASL A
TAX ; Start with function (an even number) in X.
LDA TABLE+1,X ; Read high address byte from the actual table, and
PHA ; push it. Low byte comes next, below.
LDA TABLE,X ; Be sure to make the table reflect start addresses
PHA ; minus 1, since RTS increments the address by 1.
RTS ; RTS does the absolute indexed indirect jump.