6502-OS/utility.h65

91 lines
3.2 KiB
Plaintext

.ifndef INCLUDE_UTILITY
INCLUDE_UTILITY = 1
.macpack longbranch ; jeq, jge...
.macpack generic ; bge, add, sub
;********************************************************************************
; @macro Update a byte in memory using a mask
; @param orignal Address of the byte to update
; @param new New value
; @param mask Mask of the bits to affect by the new value
; @details
; xor new with original -> only bits that need to flip are 1
; and result with mask -> only selected bits that need to flip stay 1
; xor result with original -> flips selected bits
;********************************************************************************
.macro UT_update_with_mask original,new,mask
lda #new
eor original
and #mask
eor original
sta original
.endmacro
;_n_genlabel .set 0
;;********************************************************************************
;; @macro Generate a unique label
;;********************************************************************************
;.macro genlabel
; .ident(.sprintf("generated_label%04X", _n_genlabel))
; _n_genlabel .set _n_genlabel + 1
;.endmacro
;;********************************************************************************
;; @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
.endif