From 5767133ae387ecf5a95d2e4e9220f80803fb9c74 Mon Sep 17 00:00:00 2001 From: "matthias@arch" Date: Sun, 31 Dec 2023 01:57:46 +0100 Subject: [PATCH] add byte reverse --- utility.h65 | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/utility.h65 b/utility.h65 index 640dce7..0fd8799 100644 --- a/utility.h65 +++ b/utility.h65 @@ -7,6 +7,34 @@ INCLUDE_UTILITY = 1 .feature string_escapes .feature underline_in_numbers +.macro DEBUG_LED_OFF nr + pha + lda IO1 + IO::RA +.if nr = 0 + and #%11111110 +.elseif nr = 1 + and #%11111101 +.else + and #%11111011 +.endif + sta IO1 + IO::RA + pla +.endmacro + +.macro DEBUG_LED_ON nr + pha + lda IO1 + IO::RA +.if nr = 0 + ora #%00000001 +.elseif nr = 1 + ora #%00000010 +.else + ora #%00000100 +.endif + sta IO1 + IO::RA + pla +.endmacro + ;;******************************************************************************** ;; @macro Update a byte in memory using a mask @@ -17,6 +45,7 @@ INCLUDE_UTILITY = 1 ;; xor #value with addr -> only bits that need to flip are 1 ;; and result with #mask -> only selected bits that need to flip stay 1 ;; xor result with addr -> flips selected bits +;; @TODO optimize when immediate is used ;;******************************************************************************** .macro MaskedWrite addr,value,mask lda value @@ -123,4 +152,26 @@ _n_genlabel .set 0 .ident(.sprintf("%s", .string(l1))) = .ident(.sprintf("%s_%s", .string(prefix), .string(l1))) ImportZp prefix,l2,l3,l4,l5,l6,l7,l8 .endmacro -.endif + + +.import REVERSE_TABLE +;;******************************************************************************** +;; @macro Reverse a byte +;; @param reg: The byte to reverse. May be in X, Y or A +;; @returns A: The reversed byte +;; @modifies A, X (only when reg = A) +;;******************************************************************************** +.macro Reverse reg + .if .match(reg, A) + tax + lda REVERSE_TABLE,x + .elseif .match(reg, x) + lda REVERSE_TABLE,x + .elseif .match(reg, y) + lda REVERSE_TABLE,y + .else + .fatal ("Reverse macro got invalid argument. This syntax error is intentional to show the line number") + .endif +.endmacro + +.endif ; guard