Rewrite macros to be more flexible

This commit is contained in:
hugova 2025-03-30 16:15:07 +02:00
parent abcac12471
commit 1144fd01ca

108
wip-hugo/macros/16aritmatic.s Normal file → Executable file
View file

@ -7,64 +7,82 @@
;;Se below for some fast 16bit logic
;;http://6502.org/tutorials/compare_beyond.html
;; Addition uses the A register
;; Addition always uses the A register
;; a = a + b
.macro Add_16 a_low, a_hi, b_low, b_hi, fast_unsafe
;; IF to run it fast
.ifblank fast_unsafe
CLC
.endif
.if .not .match ({b_low}, a)
LDA b_low
.endif ;;untested
ADC a_low
STA a_low
LDA b_hi
ADC a_hi
STA a_hi
.endmacro
;; Untested!
;; Addition uses the A register
;; a = a + b. b_low = A, b_hi = X
.macro Add_16_AX low, hi, fast_unsafe
;; IF to run it fast
.ifblank fast_unsafe
CLC
.endif
ADC low
STA low
.if .match ({b_hi}, x) ;;Untested
TXA
ADC hi
STA hi
.endmacro
.macro Add_16_A a_low, a_hi, b_low, b_hi, fast_unsafe
;; IF to run it fast
.ifblank fast_unsafe
CLC
.endif
LDA a_low
ADC b_low
STA a_low
.else
LDA b_hi
.endif
ADC a_hi
STA a_hi
.endmacro
;; Subtraction uses the A register
;; Subtraction uses always uses A register
;; a = a - b
.macro Sub_16 a_low, a_hi, b_low, b_hi, fast_unsafe
;; IF to run it fast
.ifblank fast_unsafe
SEC
.endif
;; if b_low = A and b_hi =A
.if .match({b_low}, a) .and .match({b_hi}, a) ;;untested
.LOCAL rewrite
.LOCAL rewrite2
STA rewrite +1
STA rewrite2 + 1
LDA a_low
rewrite:
SBC #b_low
STA a_low
LDA a_hi
rewrite2:
SBC #b_hi
STA a_hi
;; if b_low = A
.elseif .match({b_low}, a) ;;untested
.LOCAL rewrite
STA rewrite +1
LDA a_low
rewrite:
SBC #b_low
STA a_low
LDA a_hi
SBC b_hi
STA a_hi
.elseif .match({b_hi}, a) ;;untested
.LOCAL rewrite
STA rewrite +1
LDA a_low
SBC b_low
STA a_low
LDA a_hi
rewrite:
SBC #b_hi
STA a_hi
.else
LDA a_low
SBC b_low
STA a_low
LDA a_hi
SBC b_hi
STA a_hi
.endif
.endmacro
;; Subtraction uses always uses A register
;; a = (A, a_hi) - b
.macro Sub_16_A a_low, a_hi, b_low, b_hi, fast_unsafe
;; IF to run it fast
.ifblank fast_unsafe
@ -77,20 +95,6 @@
STA a_hi
.endmacro
;; Untested
;; Subtraction uses the A register
;; a = a - b. b_low = A, b_hi = X
.macro Sub_16_AX low, hi, fast_unsafe
;; IF to run it fast
.ifblank fast_unsafe
SEC
.endif
SBC low
STA low
TXA
SBC hi
STA hi
.endmacro
;; Multiplication of 2
;; a = a*2
@ -112,29 +116,25 @@
STA a_hi
.endmacro
;;http://www.6502.org/tutorials/compare_beyond.html
;;Larger then operation, uses the A register
;;IF a < b then: jump to label
; C =0 if jump to LABEL
.macro Lag_16 a_low, a_hi, b_low, b_hi, label
.LOCAL LABEL
LDA a_hi
CMP b_hi
BCC label
BNE LABEL
LDA a_low
CMP b_low
BCC label
LABEL:
.endmacro
.macro Lag_16y a_low, a_hi, b_hi, label
LDA a_hi
CMP b_hi
BCC label
BNE LABEL
LDA a_low
.if .match ({b_low}, a)
.LOCAL next
STY next +1
next:
CMP #$ff
.else
CMP b_low
.endif
BCC label
LABEL:
.endmacro