Assembler for 6502 based systems by CodewinBzn.
WinASM65 [-option] sourcefile
-help Show help
-h Show help
-l Create listing (don't specify the file name)
-c Assemble one or multiple segments
Combine assembled segments/binary files
Assemble single segment:
-f Source file
-o Object file
{
"Input": [
{
"FileName": "path_to_main_file_seg1",
"OutputFile": "path_to_seg1_output_file",
"Dependencies": ["path_to_main_file_seg2"]
},
{
"FileName": "path_to_main_file_seg2",*
"OutputFile": "path_to_seg2_output_file",
"Dependencies": ["path_to_main_file_seg1"]
},
{
"FileName": "path_to_main_file_seg3",
"OutputFile": "path_to_seg3_output_file",
"Dependencies": []
},
......
]
}
If a segment refers to labels, variables ... or to routines declared in other segments then it must mention them in this array as ["path_to_main_file_seg1", .....].
The OutputFile is optional.
{
"Output": {
"ObjectFile": "final_object_file",
"Files":
[
{
"FileName": "path_to_seg1_output_file",
"Size": "$hex"
},
{
"FileName": "path_to_seg2_output_file",
"Size": "$hex"
},
{
"FileName": "path_to_seg3_output_file"
},
....
]
}
}
The Segments are declared in the order of their insertion in the final object file.
The size of the segment object file. If the size of the assembled segment is less then the declared size then the assembler will fill the rest of bytes with the value $00 .
- Comments begin with a semicolon (;).
lda #$00 ; this is a comment
-
Labels are declared in two ways.
-
before an instruction
ldx #$00
label lda $4000, x
cpx #$10
bne label
- Alone in a line, A colon (:) following a label is mandatory
ldx #$00
label:
lda $4000, x
cpx #$10
bne label
- Hexadecimal numbers begin with '$'.
- Binary numbers begin with '%'.
- Decimal.
- Set the starting address of a segment.
- To use only once in each segment.
- Accepts expressions.
.org $c000
lda #$00
- Set the starting address of a memory area for memory reservation (accepts expressions).
Reserve a number of bytes (accepts expressions).
.memarea $00 ; zero page
player_posx .res 1
player_pos_y .res 1
ram = $0400
.memarea ram
nbr_coins = 15
coins_pos_x .res nbr_coins ; to store posx of coins
coins_pos_y .res nbr_coins ; to store posy of coins
- Add the content of a binary file to the assembly output.
.incbin "path_to_binary_file"
- Assemble another source file as if it were part of the current source.
.include "path_to_source_file"
- Emit byte(s) or word(s).
- Multiple arguments are separated by commas.
- Accept expressions.
RED = $06
palette:
.byte $00, $10, RED + 4, $5d
lda #"A"
.byte "A", "B"
.byte "NES"
myString:
.byte "Hello World"
Conditional assembly
- Process a block of code if a symbol has been defined / not defined.
.ifdef _debug_
.
.
.
.else
.
.
.
.endif
Conditional assembly
- Process a block of code if the logical expression is evaluated to true.
- The expression must be a constant expression, that is, all operands must be defined.
.if expression
.
.
.
.else
.
.
.
.endif
- Define a macro. Macro arguments are comma separated.
- .macro name args...
.macro add @a, @b
clc
lda @a
adc @b
.endmacro
red_color = $85
add #red_color, #$00
- Repeat a block of code constant number of times.
- The command is followed by a constant expression that tells how many times the commands in the body should get repeated.
;clear memory
clrmem:
LDA #$00
{
mem = $0000
.rep 8
STA mem, x
mem = mem + $0100
.endrep
}
INX
BNE clrmem
;fill the remaining bytes of the bank
lastbyte:
.rep $2000 - (lastbyte - $c000)
.byte $ff
.endrep
- Forced end of assembly. Assembly stops at this point, even if the command is read from an include file.
- ()
- + - ~ ! < > (The unary < and > give respectively the lower and the upper byte of a value)
- * / %
- + -
- << >>
- < > <= >=
- = == != <>
- &
- ^
- |
- &&
- ||
- # Immidate addressing.
.macro vblank label, register
label:
BIT register
BPL label
.endmacro
.
.
.
{ ; All new symbols from now on are in the local lexical level and are not accessible from outside.
; Symbols defined outside this local level may be accessed as long as their names are not used for new symbols inside the level.
; Macro names are always in the global level.
vblank vblankwait, $2002
}
.
.
.
{
vblank vblankwait, $2002 ; Second wait for vblank, PPU is ready after this
}