2023-10-26 19:51:20 +02:00
|
|
|
.ifndef INCLUDE_UTILITY
|
|
|
|
INCLUDE_UTILITY = 1
|
|
|
|
|
|
|
|
.macpack longbranch ; jeq, jge...
|
2023-12-08 22:56:35 +01:00
|
|
|
.macpack generic ; bge, add, sub
|
2023-10-26 19:51:20 +02:00
|
|
|
|
2023-12-16 02:41:19 +01:00
|
|
|
.feature string_escapes
|
|
|
|
.feature underline_in_numbers
|
|
|
|
|
|
|
|
|
2023-10-26 19:51:20 +02:00
|
|
|
;********************************************************************************
|
|
|
|
; @macro Update a byte in memory using a mask
|
2023-12-16 02:41:19 +01:00
|
|
|
; @param addr Address of the byte to update
|
|
|
|
; @param value New value
|
2023-10-26 19:51:20 +02:00
|
|
|
; @param mask Mask of the bits to affect by the new value
|
|
|
|
; @details
|
2023-12-16 02:41:19 +01:00
|
|
|
; 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
|
2023-10-26 19:51:20 +02:00
|
|
|
;********************************************************************************
|
2023-12-16 02:41:19 +01:00
|
|
|
.macro MaskedWrite addr,value,mask
|
|
|
|
lda #value
|
|
|
|
eor addr
|
2023-10-26 19:51:20 +02:00
|
|
|
and #mask
|
2023-12-16 02:41:19 +01:00
|
|
|
eor addr
|
|
|
|
sta addr
|
2023-10-26 19:51:20 +02:00
|
|
|
.endmacro
|
2023-11-01 13:13:23 +01:00
|
|
|
|
|
|
|
|
2023-12-20 12:27:54 +01:00
|
|
|
_n_genlabel .set 0
|
2023-11-01 13:13:23 +01:00
|
|
|
;;********************************************************************************
|
|
|
|
;; @macro Generate a unique label
|
|
|
|
;;********************************************************************************
|
2023-12-20 12:27:54 +01:00
|
|
|
.macro GenLabel name
|
2023-12-12 14:44:19 +01:00
|
|
|
.ident(.sprintf("generated_label%04X", _n_genlabel))
|
|
|
|
_n_genlabel .set _n_genlabel + 1
|
|
|
|
.endmacro
|
2023-11-09 12:09:06 +01:00
|
|
|
|
2023-12-08 22:56:35 +01:00
|
|
|
;;********************************************************************************
|
|
|
|
;; @macro Export labels with a prefix
|
|
|
|
;; @details
|
|
|
|
;; Equivalent to:
|
|
|
|
;; .export prefix_l1:=l1
|
|
|
|
;; .export prefix_l2:=l2
|
|
|
|
;; ...
|
|
|
|
;;********************************************************************************
|
|
|
|
.macro Export prefix,l1,l2,l3,l4,l5,l6,l7,l8
|
|
|
|
.if .blank(l1)
|
|
|
|
.exitmacro
|
|
|
|
.endif
|
|
|
|
; .out .sprintf("Exporting %s as %s_%s", .string(l1), .string(prefix), .string(l1))
|
|
|
|
.export .ident(.sprintf("%s_%s", .string(prefix), .string(l1))):=l1
|
|
|
|
Export prefix,l2,l3,l4,l5,l6,l7,l8
|
|
|
|
.endmacro
|
|
|
|
.macro ExportZp prefix,l1,l2,l3,l4,l5,l6,l7,l8
|
|
|
|
.if .blank(l1)
|
|
|
|
.exitmacro
|
|
|
|
.endif
|
|
|
|
; .out .sprintf("Exporting (zp) %s as %s_%s", .string(l1), .string(prefix), .string(l1))
|
|
|
|
.exportzp .ident(.sprintf("%s_%s", .string(prefix), .string(l1))):=l1
|
|
|
|
ExportZp prefix,l2,l3,l4,l5,l6,l7,l8
|
|
|
|
.endmacro
|
|
|
|
|
|
|
|
;;********************************************************************************
|
|
|
|
;; @macro Import labels and remove prefix
|
|
|
|
;; @details
|
|
|
|
;; Equivalent to:
|
|
|
|
;; .import prefix_l1
|
|
|
|
;; .import prefix_l2
|
|
|
|
;; ...
|
|
|
|
;; l1 = prefix_l1
|
|
|
|
;; l2 = prefix_l2
|
|
|
|
;; ...
|
|
|
|
;; Use in a scope to have the lX available as scope::lX
|
|
|
|
;;********************************************************************************
|
|
|
|
.macro Import prefix,l1,l2,l3,l4,l5,l6,l7,l8
|
|
|
|
.if .blank(l1)
|
|
|
|
.exitmacro
|
|
|
|
.endif
|
|
|
|
; .out .sprintf("Importing %s_%s as %s", .string(prefix), .string(l1), .string(l1))
|
|
|
|
.import .ident(.sprintf("%s_%s", .string(prefix), .string(l1))):absolute
|
|
|
|
.ident(.sprintf("%s", .string(l1))) = .ident(.sprintf("%s_%s", .string(prefix), .string(l1)))
|
|
|
|
Import prefix,l2,l3,l4,l5,l6,l7,l8
|
|
|
|
.endmacro
|
|
|
|
.macro ImportZp prefix,l1,l2,l3,l4,l5,l6,l7,l8
|
|
|
|
.if .blank(l1)
|
|
|
|
.exitmacro
|
|
|
|
.endif
|
|
|
|
; .out .sprintf("Importing (zp) %s_%s as %s", .string(prefix), .string(l1), .string(l1))
|
|
|
|
.importzp .ident(.sprintf("%s_%s", .string(prefix), .string(l1))):zeropage
|
|
|
|
.ident(.sprintf("%s", .string(l1))) = .ident(.sprintf("%s_%s", .string(prefix), .string(l1)))
|
|
|
|
ImportZp prefix,l2,l3,l4,l5,l6,l7,l8
|
|
|
|
.endmacro
|
2023-11-09 12:09:06 +01:00
|
|
|
.endif
|