I am trying to get to the next level in rom hacking by learning 6502 ASM. I am using ASM6 but I don't understand it's syntax at all. When I try to compile some code I found on Romhacking.net and I keep getting invalid opcodes, and branching out of range errors.
What I really want to know is how do you define/declare labels in ASM6 and if I manage to assemble/compile my code row can I patch to the rom?
Here is the code I am working with. It's just dte subroutines I'd like to stick in a rom.
What I really want to know is how do you define/declare labels in ASM6 and if I manage to assemble/compile my code row can I patch to the rom?
Here is the code I am working with. It's just dte subroutines I'd like to stick in a rom.
Code:
DTE_Routine:
LDY $0658 ;This was the first command I overwrote with the jump to the routine.
LDA ($BE),Y ;This is the second.
CMP #$30 ;DTE Range compare 1
BCC End ;If A is < #$30, skip DTE (Branch if carry clear)
CLC ;Clear the carry flag - we get here because
CMP #$80 ;DTE Range Compare 2
BCS End ;If A is >=#$80, skip DTE (Branch if carry set)
;If we get past the upper and lower bound range compares, we have DTE!
RunCheck:
STX $07FE ;Store X temporarily to THE DEPTHS OF UNUSED RAM
SEC
SBC #$30
CLC
LDX $07FF ;Load X with a test byte from THE DEPTHS OF UNUSED RAM
CPX #$9D ;Compare it with test=true (#$9D in this case)
BEQ SecondRun ;If test=true, we're printing the second character
BNE FirstRun ;If test=false, we're printing the FIRST character.
FirstRun: ;For outputting the first character...
LDX #$9D ;Load X with Test=true
DEC $0658 ;Decrement load index (which gets transferred into Y)
ASL A ;Double A to get DTE Pair Number
JMP Base_Routine ;Jump to the shared bits of the routine (4C2780)
SecondRun:
ASL A ;Double A for DTE Pair Number
CLC ;Clear the carry cuz we're gonna add
ADC #$01 ;Increment the accumulator
;A is now the index location of the second byte in the DTE Pair.
LDX #$00 ;Load X with Test=FALSE
Base_Routine:
STX $07FF ;Store test byte to THE DEPTHS OF UNUSED RAM
TAX ;Transer A to X for the DTE table lookup
LDA $DTETable,X ;Load A with where ever your DTE table happens to be,X
LDX $07FE ;Restore X from before routine
End:
JMP $AF29 ;Jump back to the routine
Create_DTE_Table:
.DSW 80 ;Create an 80 ($50) byte empty DTE table to be later filled in
;This gets put -immediately- after the routine.2389
LDY $0658 ;This was the first command I overwrote with the jump to the routine.
LDA ($BE),Y ;This is the second.
CMP #$30 ;DTE Range compare 1
BCC End ;If A is < #$30, skip DTE (Branch if carry clear)
CLC ;Clear the carry flag - we get here because
CMP #$80 ;DTE Range Compare 2
BCS End ;If A is >=#$80, skip DTE (Branch if carry set)
;If we get past the upper and lower bound range compares, we have DTE!
RunCheck:
STX $07FE ;Store X temporarily to THE DEPTHS OF UNUSED RAM
SEC
SBC #$30
CLC
LDX $07FF ;Load X with a test byte from THE DEPTHS OF UNUSED RAM
CPX #$9D ;Compare it with test=true (#$9D in this case)
BEQ SecondRun ;If test=true, we're printing the second character
BNE FirstRun ;If test=false, we're printing the FIRST character.
FirstRun: ;For outputting the first character...
LDX #$9D ;Load X with Test=true
DEC $0658 ;Decrement load index (which gets transferred into Y)
ASL A ;Double A to get DTE Pair Number
JMP Base_Routine ;Jump to the shared bits of the routine (4C2780)
SecondRun:
ASL A ;Double A for DTE Pair Number
CLC ;Clear the carry cuz we're gonna add
ADC #$01 ;Increment the accumulator
;A is now the index location of the second byte in the DTE Pair.
LDX #$00 ;Load X with Test=FALSE
Base_Routine:
STX $07FF ;Store test byte to THE DEPTHS OF UNUSED RAM
TAX ;Transer A to X for the DTE table lookup
LDA $DTETable,X ;Load A with where ever your DTE table happens to be,X
LDX $07FE ;Restore X from before routine
End:
JMP $AF29 ;Jump back to the routine
Create_DTE_Table:
.DSW 80 ;Create an 80 ($50) byte empty DTE table to be later filled in
;This gets put -immediately- after the routine.2389