Skip to content

Commit

Permalink
[MOS6502] Fix to use W65C816 memory
Browse files Browse the repository at this point in the history
  • Loading branch information
tgtakaoka committed Jun 18, 2024
1 parent bf5ed81 commit 8b4a8df
Show file tree
Hide file tree
Showing 12 changed files with 1,172 additions and 1,252 deletions.
3 changes: 3 additions & 0 deletions debugger/mos6502/pins_mos6502.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ void PinsMos6502::checkHardwareType() {
pinMode(PIN_BE, OUTPUT);
}
// Keep PIN_SO HIGH using pullup
// Set 16-bit memory
Target6502.setMems(mos6502::Memory);
} else {
// PIN_PHI1O/W65C816_ABORT keeps HIGH, means W65C816S.
Expand All @@ -195,6 +196,8 @@ void PinsMos6502::checkHardwareType() {
// Enable BE
digitalWriteFast(PIN_BE, HIGH);
pinMode(PIN_BE, OUTPUT);
// Set 24-bit memory
Target6502.setMems(w65c816::Memory);
}
}

Expand Down
4 changes: 2 additions & 2 deletions debugger/mos6502/regs_mos6502.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ void RegsMos6502::print() const {
if (Pins.native65816()) {
// clang-format off
// 012345678901234567890123456789012345678901234567890123456789012
static constexpr char line[] = "K=xx PC=xxxx S=xxxx D=xxxx B=xx X=xxxx Y=xxxx C=xxxx P=NVMXDIZC";
static constexpr char line[] = "K:PC=xx:xxxx S=xxxx D=xxxx B=xx X=xxxx Y=xxxx C=xxxx P=NVMXDIZC";
// clang-format on
static auto &buffer = *new CharBuffer(line);
buffer.hex8(2, _pbr);
buffer.hex8(5, _pbr);
buffer.hex16(8, _pc);
buffer.hex16(15, _s);
buffer.hex16(22, _d);
Expand Down
10 changes: 5 additions & 5 deletions samples/mos6502/arith.inc
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ print_uint16_inner:
stx R2L ; divisor=10
jsr udiv16 ; R0=value/10
lda R1L
pha ; push reminder
pha ; push remainder
jsr print_uint16_inner
pla ; pop reminder
pla ; pop remainder
print_uint16_digit:
ora #'0'
jmp putchar
Expand Down Expand Up @@ -304,11 +304,11 @@ mulsi2_multiply:
mulsi2_return:
rts

;;; Unsigned division: dividend / divisor = quotient ... reminder
;;; Unsigned division: dividend / divisor = quotient ... remainder
;;; @praram R1 dividend
;;; @praram R2 divisor
;;; @return R0 quotient
;;; @return R1 reminder
;;; @return R1 remainder
;;; @clobber R2
udiv16:
lda R2H
Expand Down Expand Up @@ -367,7 +367,7 @@ udiv16_return:
;;; @param R1 dividend
;;; @param R2 divisor
;;; @return R0 quotient
;;; @return R1 reminder
;;; @return R1 remainder
;;; @clobber R2
divsi2:
lda R1H
Expand Down
10 changes: 5 additions & 5 deletions samples/mos6502/arith.lst
Original file line number Diff line number Diff line change
Expand Up @@ -426,9 +426,9 @@
(1) 1295 : 86 14 stx R2L ; divisor=10
(1) 1297 : 20 DB 13 jsr udiv16 ; R0=value/10
(1) 129A : A5 12 lda R1L
(1) 129C : 48 pha ; push reminder
(1) 129C : 48 pha ; push remainder
(1) 129D : 20 83 12 jsr print_uint16_inner
(1) 12A0 : 68 pla ; pop reminder
(1) 12A0 : 68 pla ; pop remainder
(1) 12A1 : print_uint16_digit:
(1) 12A1 : 09 30 ora #'0'
(1) 12A3 : 4C 13 10 jmp putchar
Expand Down Expand Up @@ -709,11 +709,11 @@
(1) 13DA : mulsi2_return:
(1) 13DA : 60 rts
(1) 13DB :
(1) 13DB : ;;; Unsigned division: dividend / divisor = quotient ... reminder
(1) 13DB : ;;; Unsigned division: dividend / divisor = quotient ... remainder
(1) 13DB : ;;; @praram R1 dividend
(1) 13DB : ;;; @praram R2 divisor
(1) 13DB : ;;; @return R0 quotient
(1) 13DB : ;;; @return R1 reminder
(1) 13DB : ;;; @return R1 remainder
(1) 13DB : ;;; @clobber R2
(1) 13DB : udiv16:
(1) 13DB : A5 15 lda R2H
Expand Down Expand Up @@ -772,7 +772,7 @@
(1) 142C : ;;; @param R1 dividend
(1) 142C : ;;; @param R2 divisor
(1) 142C : ;;; @return R0 quotient
(1) 142C : ;;; @return R1 reminder
(1) 142C : ;;; @return R1 remainder
(1) 142C : ;;; @clobber R2
(1) 142C : divsi2:
(1) 142C : A5 13 lda R1H
Expand Down
10 changes: 5 additions & 5 deletions samples/mos6502/mandelbrot.lst
Original file line number Diff line number Diff line change
Expand Up @@ -490,9 +490,9 @@
(1) 1256 : 86 14 stx R2L ; divisor=10
(1) 1258 : 20 9C 13 jsr udiv16 ; R0=value/10
(1) 125B : A5 12 lda R1L
(1) 125D : 48 pha ; push reminder
(1) 125D : 48 pha ; push remainder
(1) 125E : 20 44 12 jsr print_uint16_inner
(1) 1261 : 68 pla ; pop reminder
(1) 1261 : 68 pla ; pop remainder
(1) 1262 : print_uint16_digit:
(1) 1262 : 09 30 ora #'0'
(1) 1264 : 4C 2E 10 jmp putchar
Expand Down Expand Up @@ -773,11 +773,11 @@
(1) 139B : mulsi2_return:
(1) 139B : 60 rts
(1) 139C :
(1) 139C : ;;; Unsigned division: dividend / divisor = quotient ... reminder
(1) 139C : ;;; Unsigned division: dividend / divisor = quotient ... remainder
(1) 139C : ;;; @praram R1 dividend
(1) 139C : ;;; @praram R2 divisor
(1) 139C : ;;; @return R0 quotient
(1) 139C : ;;; @return R1 reminder
(1) 139C : ;;; @return R1 remainder
(1) 139C : ;;; @clobber R2
(1) 139C : udiv16:
(1) 139C : A5 15 lda R2H
Expand Down Expand Up @@ -836,7 +836,7 @@
(1) 13ED : ;;; @param R1 dividend
(1) 13ED : ;;; @param R2 divisor
(1) 13ED : ;;; @return R0 quotient
(1) 13ED : ;;; @return R1 reminder
(1) 13ED : ;;; @return R1 remainder
(1) 13ED : ;;; @clobber R2
(1) 13ED : divsi2:
(1) 13ED : A5 13 lda R1H
Expand Down
55 changes: 43 additions & 12 deletions samples/w65c816/arith.asm
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ stack = *-1
initialize:
clc
xce ; native mode
longa off
rep #P_X ; 16-bit index
longi on
ldx #stack
Expand All @@ -33,24 +34,41 @@ initialize:
;;; @param A char
;;; @clobber A
putchar:
pha ; save A
putchar_loop:
php
sep #P_M ; 8-bit memory
longa off
jsr _putchar
plp
rts
_putchar:
pha
_putchar_loop:
lda ACIA_status
and #TDRE_bm
beq putchar_loop
beq _putchar_loop
pla ; restore A
sta ACIA_data
rts

newline:
php
sep #P_M ; 8-bit memory
longa off
lda #$0D
jsr putchar
jsr _putchar
lda #$0A
bra putchar
jsr _putchar
plp
rts

putspace:
php
sep #P_M ; 8-bit memory
longa off
lda #' '
bra putchar
jsr _putchar
plp
rts

;;; Print "X op Y"
;;; @params A op letter
Expand Down Expand Up @@ -98,7 +116,6 @@ comp_out:
jsr expr
jmp newline


arith:
ldx #18000
ldy #28000
Expand Down Expand Up @@ -276,8 +293,15 @@ arith:
addsi2:
php
rep #P_M ; 16-bit memory
jsr add16
longa on
txa
phy
clc
adc 1,S
tax
ply
plp
longa off
rts

;;; Subtraction
Expand All @@ -289,8 +313,14 @@ addsi2:
subsi2:
php
rep #P_M ; 16-bit memory
jsr sub16
txa
phy
sec
sbc 1,S
tax
ply
plp
longa off
rts

;;; Signed compare
Expand All @@ -302,9 +332,10 @@ subsi2:
;;; C=-1; BMI (minuend < subtrahend)
longa off
cmpsi2:
php
rep #P_M ; 16-bit memory
jsr cmp16
sep #P_M ; 8-bit memory
plp
rts

;;; Multiply: result = multiplicand * multiplier
Expand All @@ -320,11 +351,11 @@ mulsi2:
plp
rts

;;; Division: dividend / divisor = quotient ... reminder
;;; Division: dividend / divisor = quotient ... remainder
;;; @param X dividend
;;; @param Y divisor
;;; @return X quotient
;;; @return Y reminder
;;; @return Y remainder
;;; @clobber C
longa off
divsi2:
Expand Down
Loading

0 comments on commit 8b4a8df

Please sign in to comment.