Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
name = "mos6502"
description = "A MOS 6502 Emulator"
license = "BSD-3-Clause"
version = "0.6.2"
version = "0.6.3"
authors = ["The 6502-rs Developers"]
exclude = ["examples/**"]
edition = "2024"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fn main() {
0x4c, 0x12, 0x00, // Jump to .algo_
// .end
0xa5, 0x00, // Load from S to A
0xff,
0x02, // JAM - halt CPU to end program
// .swap
0xa6, 0x00, // load F to X
0xa4, 0x01, // load S to Y
Expand Down
Binary file modified examples/asm/euclid/euclid.bin
Binary file not shown.
42 changes: 17 additions & 25 deletions examples/asm/euclid/euclid.ca65
Original file line number Diff line number Diff line change
@@ -1,33 +1,25 @@
; euclid.ca65
; A program to find the greatest common divisor of two numbers

.ORG $1000
.segment "CODE"

; .algo
LDA $00 ; Load from F to A
; .algo_
SEC ; Set carry flag
SBC $01 ; Subtract S from the number in A (from F)
BEQ end ; Jump to .end if the difference is zero
BMI swap ; Jump to .swap if the difference is negative
STA $00 ; Load A to F
JMP algo_ ; Jump to .algo_
algo:
LDA $00 ; Load from F to A
algo_:
SEC ; Set carry flag
SBC $01 ; Subtract S from A
BEQ end ; Jump to end if zero
BMI swap ; Jump to swap if negative
STA $00 ; Store A to F
JMP algo_ ; Continue algorithm

; .end
end:
LDA $00 ; Load from F to A
BRK ; Break (end program)
LDA $00 ; Load result to A
.byte $02 ; JAM - halt CPU

; .swap
swap:
LDX $00 ; Load F to X
LDY $01 ; Load S to Y
STX $01 ; Store X to S
STY $00 ; Store Y to F
JMP algo ; Jump to .algo

algo:
JMP algo ; Infinite loop to prevent program from ending

algo_:
JMP algo_ ; Infinite loop to prevent program from ending
LDX $00 ; Load F to X
LDY $01 ; Load S to Y
STX $01 ; Store X to S
STY $00 ; Store Y to F
JMP algo ; Restart algorithm
36 changes: 11 additions & 25 deletions examples/asm/linker.cfg
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tested this, but it seems reasonable.

Original file line number Diff line number Diff line change
@@ -1,32 +1,18 @@
# Linker configuration for cc65 (ld65)
# Defines memory layout and segment placement for 6502 programs
# Outputs raw binary containing only the code segment

MEMORY {
# RAM: 32KB from $0000-$7FFF
# Used for zero page, stack, data, and code in this emulator config
RAM: start = $0000, size=$8000, type = rw, fill = yes, fillval = $FF, file = %O;

# ROM: Almost 32KB from $8000-$FFF9
# Defined but not used in examples (code runs from RAM instead)
ROM: start = $8000, size=$7FFA, type = ro, fill = yes, fillval = $FF, file = %O;

# ROM_VECTORS: 6 bytes at $FFFA-$FFFF
# Holds the three 16-bit interrupt vectors: NMI, RESET, IRQ
ROM_VECTORS: start = $FFFA, size=6, type = ro, fill = yes, fillval = $FF, file = %O;
# Code region starting at $0010, matching README examples
CODE: start = $0010, size = $1000, type = rw, file = %O;
}

SEGMENTS {
# Zero page ($00-$FF): Fast access variables
ZEROPAGE: load=RAM, type=rw;

# Data segment: Starts at $0200 (page 2)
# Page 1 ($0100-$01FF) is reserved for the stack
DATA: load=RAM, type=rw, offset=$0200;
# Code segment: Contains the program
CODE: load = CODE, type = ro;

# Code segment: Starts at $0400 (page 4)
# Leaves room for zero page, stack, and data
CODE: load=RAM, type=rw, offset=$0400;

# Interrupt vectors at top of memory
VECTORS: load=ROM_VECTORS, type=ro;
}
# Optional segments
ZEROPAGE: load = CODE, type = rw, optional = yes;
DATA: load = CODE, type = rw, optional = yes;
RODATA: load = CODE, type = rw, optional = yes;
BSS: load = CODE, type = rw, optional = yes;
}
Loading
Loading