pull macros out; some formatting

This commit is contained in:
Joshua Bell 2018-02-05 19:01:17 -08:00
parent f37d997e2c
commit f7a879c4c7
2 changed files with 405 additions and 357 deletions

View File

@ -6,6 +6,7 @@
.include "../inc/prodos.inc" .include "../inc/prodos.inc"
.include "../mgtk.inc" .include "../mgtk.inc"
.include "../desktop.inc" .include "../desktop.inc"
.include "macros.inc"
;;; ================================================== ;;; ==================================================
;;; DeskTop - the actual application ;;; DeskTop - the actual application
@ -17,107 +18,6 @@ INVOKER_FILENAME := $280 ; File to invoke (PREFIX must be set)
dummy0000 := $0000 ; overwritten by self-modified code dummy0000 := $0000 ; overwritten by self-modified code
dummy1234 := $1234 ; overwritten by self-modified code dummy1234 := $1234 ; overwritten by self-modified code
.macro addr_call target, addr
lda #<addr
ldx #>addr
jsr target
.endmacro
.macro addr_jump target, addr
lda #<addr
ldx #>addr
jmp target
.endmacro
.macro axy_call target, yparam, addr
lda #<addr
ldx #>addr
ldy #yparam
jsr target
.endmacro
.macro yax_call target, yparam, addr
ldy #yparam
lda #<addr
ldx #>addr
jsr target
.endmacro
.macro yxa_call target, yparam, addr
ldy #yparam
ldx #>addr
lda #<addr
jsr target
.endmacro
.macro yxa_jump target, yparam, addr
ldy #yparam
ldx #>addr
lda #<addr
jmp target
.endmacro
.macro ldax arg
.if (.match (.mid (0, 1, {arg}), #))
lda #<(.right (.tcount ({arg})-1, {arg}))
ldx #>(.right (.tcount ({arg})-1, {arg}))
.else
lda arg
ldx arg+1
.endif
.endmacro
.macro stax arg
sta arg
stx arg+1
.endmacro
.macro add16 aa, bb, rr
.if (.match (.mid (0, 1, {bb}), #))
lda aa
clc
adc #<(.right (.tcount ({bb})-1, {bb}))
sta rr
lda aa+1
adc #>(.right (.tcount ({bb})-1, {bb}))
sta rr+1
.else
lda aa
clc
adc bb
sta rr
lda aa+1
adc bb+1
sta rr+1
.endif
.endmacro
.macro add16_8 aa, bb, rr
lda aa
clc
adc bb
sta rr
lda aa+1
adc #0
sta rr+1
.endmacro
.macro sub16 aa, bb, rr
.if (.match (.mid (0, 1, {bb}), #))
lda aa
sec
sbc #<(.right (.tcount ({bb})-1, {bb}))
sta rr
lda aa+1
sbc #>(.right (.tcount ({bb})-1, {bb}))
sta rr+1
.else
lda aa
sec
sbc bb
sta rr
lda aa+1
sbc bb+1
sta rr+1
.endif
.endmacro
.macro MGTK_RELAY_CALL call, addr .macro MGTK_RELAY_CALL call, addr
.if .paramcount > 1 .if .paramcount > 1
yax_call MGTK_RELAY, (call), (addr) yax_call MGTK_RELAY, (call), (addr)
@ -443,6 +343,7 @@ online_params_buffer:
;;; ================================================== ;;; ==================================================
.assert * = $8800, error, "Entry point mismatch"
.include "font.inc" .include "font.inc"
;;; ================================================== ;;; ==================================================
@ -469,13 +370,17 @@ L8C83: .byte $00,$00,$00,$00,$77,$30,$01
.assert * = $8D02, error, "Segment length mismatch" .assert * = $8D02, error, "Segment length mismatch"
PAD_TO $8E00 PAD_TO $8E00
;;; ==================================================
;;; Entry point for "DESKTOP"
;;; ================================================== ;;; ==================================================
;; Entry point for "DESKTOP"
.assert * = DESKTOP, error, "DESKTOP entry point must be at $8E00" .assert * = DESKTOP, error, "DESKTOP entry point must be at $8E00"
jmp DESKTOP_DIRECT jmp DESKTOP_DIRECT
;;; ==================================================
.macro MGTK_RELAY2_CALL call, addr .macro MGTK_RELAY2_CALL call, addr
.if .paramcount > 1 .if .paramcount > 1
yax_call MGTK_RELAY2, (call), (addr) yax_call MGTK_RELAY2, (call), (addr)
@ -682,7 +587,9 @@ notpenOR_2: .byte 5
notpenXOR_2: .byte 6 notpenXOR_2: .byte 6
notpenBIC_2: .byte 7 notpenBIC_2: .byte 7
;; DESKTOP command jump table ;;; ==================================================
;;; DESKTOP command jump table
L939E: .addr 0 ; $00 L939E: .addr 0 ; $00
.addr L9419 ; $01 .addr L9419 ; $01
.addr HIGHLIGHT_ICON_IMPL .addr HIGHLIGHT_ICON_IMPL
@ -705,7 +612,8 @@ L939E: .addr 0 ; $00
.addr addr .addr addr
.endmacro .endmacro
;; DESKTOP entry point (after jump) ;;; DESKTOP entry point (after jump)
DESKTOP_DIRECT: DESKTOP_DIRECT:
;; Stash return value from stack, adjust by 3 ;; Stash return value from stack, adjust by 3
@ -2407,6 +2315,7 @@ LA2A5: .byte 0
.endproc .endproc
;;; ================================================== ;;; ==================================================
;;; REDRAW_ICONS IMPL
REDRAW_ICONS_IMPL: REDRAW_ICONS_IMPL:
jmp LA2AE jmp LA2AE
@ -2572,15 +2481,18 @@ LA3B7: .byte 0
window_id: .byte 0 window_id: .byte 0
.endproc .endproc
LA3B9: ldy #0 .proc LA3B9
ldy #0
lda ($06),y lda ($06),y
sta LA3AC sta LA3AC
iny iny
iny iny
lda ($06),y lda ($06),y
and #$0F and #$0F ; type - is volume?
sta LA3AD sta LA3AD
beq LA3F4 beq volume
;; File (i.e. icon in window)
lda #$80 lda #$80
sta LA3B7 sta LA3B7
MGTK_CALL MGTK::SetPattern, white_pattern MGTK_CALL MGTK::SetPattern, white_pattern
@ -2593,14 +2505,17 @@ LA3B9: ldy #0
jsr erase_icon jsr erase_icon
jmp LA446 jmp LA446
LA3F4: MGTK_CALL MGTK::InitPort, grafport ;; Volume (i.e. icon on desktop)
volume:
MGTK_CALL MGTK::InitPort, grafport
jsr LA63F jsr LA63F
LA3FD: jsr LA6A3 : jsr LA6A3
jsr erase_desktop_icon jsr erase_desktop_icon
lda L9F93 lda L9F93
bne LA3FD bne :-
MGTK_CALL MGTK::SetPortBits, grafport MGTK_CALL MGTK::SetPortBits, grafport
jmp LA446 jmp LA446
.endproc
;;; ================================================== ;;; ==================================================
@ -6823,7 +6738,7 @@ L46CF: .addr dummy0000
jmp begin jmp begin
.proc get_file_info_params .proc get_file_info_params
params: .byte $A param_count: .byte $A
path: .addr $220 path: .addr $220
access: .byte 0 access: .byte 0
type: .byte 0 type: .byte 0
@ -6909,7 +6824,7 @@ L477F: lda $D345,x
;;; ================================================== ;;; ==================================================
.proc get_file_info_params2 .proc get_file_info_params2
params: .byte $A param_count: .byte $A
path: .addr $1800 path: .addr $1800
access: .byte 0 access: .byte 0
type: .byte 0 type: .byte 0
@ -7127,7 +7042,7 @@ L498F: .byte $00
;;; ================================================== ;;; ==================================================
.proc get_file_info_params3 .proc get_file_info_params3
params: .byte $A param_count: .byte $A
path: .addr $220 path: .addr $220
access: .byte 0 access: .byte 0
type: .byte 0 type: .byte 0
@ -7491,7 +7406,7 @@ close: yxa_jump MLI_RELAY, CLOSE, close_params
unused: .byte 0 ; ??? unused: .byte 0 ; ???
.proc open_params .proc open_params
params: .byte 3 param_count: .byte 3
pathname:.addr str_desk_acc pathname:.addr str_desk_acc
buffer: .addr $1C00 buffer: .addr $1C00
ref_num:.byte 0 ref_num:.byte 0
@ -7499,7 +7414,7 @@ ref_num:.byte 0
open_params_ref_num := open_params::ref_num open_params_ref_num := open_params::ref_num
.proc read_params .proc read_params
params: .byte 4 param_count: .byte 4
ref_num:.byte 0 ref_num:.byte 0
buffer: .addr DA_LOAD_ADDRESS buffer: .addr DA_LOAD_ADDRESS
request:.word DA_MAX_SIZE request:.word DA_MAX_SIZE
@ -7508,7 +7423,7 @@ trans: .word 0
read_params_ref_num := read_params::ref_num read_params_ref_num := read_params::ref_num
.proc close_params .proc close_params
params: .byte 1 param_count: .byte 1
ref_num:.byte 0 ref_num:.byte 0
.endproc .endproc
close_params_ref_num := close_params::ref_num close_params_ref_num := close_params::ref_num
@ -7872,7 +7787,7 @@ L4F68: .byte $00
L4F69: .byte $00 L4F69: .byte $00
.proc create_params .proc create_params
params: .byte 7 param_count: .byte 7
path: .addr path_buffer path: .addr path_buffer
access: .byte %11000011 ; destroy/rename/write/read access: .byte %11000011 ; destroy/rename/write/read
type: .byte FT_DIRECTORY type: .byte FT_DIRECTORY
@ -7995,7 +7910,7 @@ quit_code:
;; 5C 04 D0 E0 jmp $E0D004 ; long jump ;; 5C 04 D0 E0 jmp $E0D004 ; long jump
.proc quit_params .proc quit_params
params: .byte 4 param_count: .byte 4
.byte 0 .byte 0
.word 0 .word 0
.byte 0 .byte 0
@ -11415,7 +11330,7 @@ L704C: .byte 0
L7054: jmp L70C5 L7054: jmp L70C5
.proc open_params .proc open_params
params: .byte 3 param_count: .byte 3
path: .addr L705D path: .addr L705D
buffer: .addr $800 buffer: .addr $800
ref_num:.byte 0 ref_num:.byte 0
@ -11425,7 +11340,7 @@ L705D: .res 64, 0
.byte $00 .byte $00
.proc read_params .proc read_params
params: .byte 4 param_count: .byte 4
ref_num:.byte 0 ref_num:.byte 0
buffer: .addr $0C00 buffer: .addr $0C00
request:.word $200 request:.word $200
@ -11433,12 +11348,12 @@ trans: .word 0
.endproc .endproc
.proc close_params .proc close_params
params: .byte 1 param_count: .byte 1
ref_num:.byte 0 ref_num:.byte 0
.endproc .endproc
.proc get_file_info_params4 .proc get_file_info_params4
params: .byte $A param_count: .byte $A
path: .addr L705D path: .addr L705D
access: .byte 0 access: .byte 0
type: .byte 0 type: .byte 0
@ -14317,7 +14232,7 @@ L899A: sta grafport5::cliprect_x1,x
;;; ================================================== ;;; ==================================================
.proc on_line_params .proc on_line_params
params: .byte 2 param_count: .byte 2
unit: .byte 0 unit: .byte 0
buffer: .addr $800 buffer: .addr $800
.endproc .endproc
@ -14484,7 +14399,7 @@ L8AC5: .byte $00,$00,$00,$00,$EA,$01,$10,$00
.byte $28,$00,$A0,$00 .byte $28,$00,$A0,$00
.proc get_prefix_params .proc get_prefix_params
params: .byte 1 param_count: .byte 1
buffer: .addr $4824 buffer: .addr $4824
.endproc .endproc
@ -14853,7 +14768,7 @@ addr_table:
.addr $0800,$0800,$9000,$5000,$7000,$7000,$7000,$5000,$9000 .addr $0800,$0800,$9000,$5000,$7000,$7000,$7000,$5000,$9000
.proc open_params .proc open_params
params: .byte 3 param_count: .byte 3
path: .addr str_desktop2 path: .addr str_desktop2
buffer: .addr $1C00 buffer: .addr $1C00
ref_num:.byte 0 ref_num:.byte 0
@ -14863,13 +14778,13 @@ str_desktop2:
PASCAL_STRING "DeskTop2" PASCAL_STRING "DeskTop2"
.proc set_mark_params .proc set_mark_params
params: .byte 2 param_count: .byte 2
ref_num:.byte 0 ref_num:.byte 0
pos: .faraddr 0 pos: .faraddr 0
.endproc .endproc
.proc read_params .proc read_params
params: .byte 4 param_count: .byte 4
ref_num:.byte 0 ref_num:.byte 0
buffer: .addr 0 buffer: .addr 0
request:.word 0 request:.word 0
@ -14877,7 +14792,7 @@ trans: .word 0
.endproc .endproc
.proc close_params .proc close_params
params: .byte 1 param_count: .byte 1
ref_num:.byte 0 ref_num:.byte 0
.endproc .endproc
@ -15413,7 +15328,7 @@ L92C5: .byte $00,$00
L92C7: .byte $00,$00 L92C7: .byte $00,$00
.proc get_file_info_params5 .proc get_file_info_params5
params: .byte $A param_count: .byte $A
path: .addr $220 path: .addr $220
access: .byte 0 access: .byte 0
type: .byte 0 type: .byte 0
@ -15429,7 +15344,7 @@ ctime: .word 0
L92DB: .byte 0,0 L92DB: .byte 0,0
.proc block_params .proc block_params
params: .byte $03 param_count: .byte $03
unit_num:.byte $0 unit_num:.byte $0
buffer: .addr $0800 buffer: .addr $0800
block_num:.word $A block_num:.word $A
@ -15704,7 +15619,7 @@ L9558: lda $E6EC,x
rts rts
.proc rename_params .proc rename_params
params: .byte 2 param_count: .byte 2
path: .addr $220 path: .addr $220
newpath:.addr $1FC0 newpath:.addr $1FC0
.endproc .endproc
@ -15898,14 +15813,14 @@ L9708: .byte $00
L9709: .byte $00 L9709: .byte $00
.proc open_params3 .proc open_params3
params: .byte 3 param_count: .byte 3
path: .addr $220 path: .addr $220
buffer: .addr $800 buffer: .addr $800
ref_num:.byte 0 ref_num:.byte 0
.endproc .endproc
.proc read_params3 .proc read_params3
params: .byte 4 param_count: .byte 4
ref_num:.byte 0 ref_num:.byte 0
buffer: .addr L9718 buffer: .addr L9718
request:.word 4 request:.word 4
@ -15914,12 +15829,12 @@ trans: .word 0
L9718: .res 4, 0 L9718: .res 4, 0
.proc close_params6 .proc close_params6
params: .byte 1 param_count: .byte 1
ref_num:.byte 0 ref_num:.byte 0
.endproc .endproc
.proc read_params4 .proc read_params4
params: .byte 4 param_count: .byte 4
ref_num:.byte 0 ref_num:.byte 0
buffer: .addr L97AD buffer: .addr L97AD
request:.word $27 request:.word $27
@ -15927,7 +15842,7 @@ trans: .word 0
.endproc .endproc
.proc read_params5 .proc read_params5
params: .byte 4 param_count: .byte 4
ref_num:.byte 0 ref_num:.byte 0
buffer: .addr L972E buffer: .addr L972E
request:.word 5 request:.word 5
@ -15938,36 +15853,36 @@ L972E: .res 5, 0
.res 4, 0 .res 4, 0
.proc close_params5 .proc close_params5
params: .byte 1 param_count: .byte 1
ref_num:.byte 0 ref_num:.byte 0
.endproc .endproc
.proc close_params3 .proc close_params3
params: .byte 1 param_count: .byte 1
ref_num:.byte 0 ref_num:.byte 0
.endproc .endproc
.proc destroy_params .proc destroy_params
params: .byte 1 param_count: .byte 1
path: .addr $0220 path: .addr $0220
.endproc .endproc
.proc open_params4 .proc open_params4
params: .byte 3 param_count: .byte 3
path: .addr $220 path: .addr $220
buffer: .addr $0D00 buffer: .addr $0D00
ref_num:.byte 0 ref_num:.byte 0
.endproc .endproc
.proc open_params5 .proc open_params5
params: .byte 3 param_count: .byte 3
path: .addr $1FC0 path: .addr $1FC0
buffer: .addr $1100 buffer: .addr $1100
ref_num:.byte 0 ref_num:.byte 0
.endproc .endproc
.proc read_params6 .proc read_params6
params: .byte 4 param_count: .byte 4
ref_num:.byte 0 ref_num:.byte 0
buffer: .addr $1500 buffer: .addr $1500
request:.word $AC0 request:.word $AC0
@ -15975,7 +15890,7 @@ trans: .word 0
.endproc .endproc
.proc write_params .proc write_params
params: .byte 4 param_count: .byte 4
ref_num:.byte 0 ref_num:.byte 0
buffer: .addr $1500 buffer: .addr $1500
request:.word $AC0 request:.word $AC0
@ -15983,7 +15898,7 @@ trans: .word 0
.endproc .endproc
.proc create_params3 .proc create_params3
params: .byte 7 param_count: .byte 7
path: .addr $1FC0 path: .addr $1FC0
access: .byte %11000011 access: .byte %11000011
type: .byte 0 type: .byte 0
@ -15994,7 +15909,7 @@ ctime: .word 0
.endproc .endproc
.proc create_params2 .proc create_params2
params: .byte 7 param_count: .byte 7
path: .addr $1FC0 path: .addr $1FC0
access: .byte 0 access: .byte 0
type: .byte 0 type: .byte 0
@ -16007,7 +15922,7 @@ ctime: .word 0
.byte $00,$00 .byte $00,$00
.proc file_info_params2 .proc file_info_params2
params: .byte $A param_count: .byte $A
path: .addr $220 path: .addr $220
access: .byte 0 access: .byte 0
type: .byte 0 type: .byte 0
@ -16023,7 +15938,7 @@ ctime: .word 0
.byte 0 .byte 0
.proc file_info_params3 .proc file_info_params3
params: .byte $A param_count: .byte $A
path: .addr $1FC0 path: .addr $1FC0
access: .byte 0 access: .byte 0
type: .byte 0 type: .byte 0
@ -16039,25 +15954,25 @@ ctime: .word 0
.byte 0 .byte 0
.proc set_eof_params .proc set_eof_params
params: .byte 2 param_count: .byte 2
ref_num:.byte 0 ref_num:.byte 0
eof: .faraddr 0 eof: .faraddr 0
.endproc .endproc
.proc mark_params .proc mark_params
params: .byte 2 param_count: .byte 2
ref_num: .byte 0 ref_num: .byte 0
position: .faraddr 0 position: .faraddr 0
.endproc .endproc
.proc mark_params2 .proc mark_params2
params: .byte 2 param_count: .byte 2
ref_num:.byte 0 ref_num:.byte 0
position: .faraddr 0 position: .faraddr 0
.endproc .endproc
.proc on_line_params2 .proc on_line_params2
params: .byte 2 param_count: .byte 2
unit_num:.byte 0 unit_num:.byte 0
buffer: .addr $800 buffer: .addr $800
.endproc .endproc
@ -17319,7 +17234,7 @@ LA39F: jsr L917F
jmp LA3A7 jmp LA3A7
.proc close_params4 .proc close_params4
params: .byte 1 param_count: .byte 1
ref_num:.byte 0 ref_num:.byte 0
.endproc .endproc
@ -20430,7 +20345,7 @@ L0ABC: jsr desktop_main::a_times_6
rts rts
.proc open_params .proc open_params
params: .byte 3 param_count: .byte 3
path: .addr str_selector_list path: .addr str_selector_list
buffer: .addr $1000 buffer: .addr $1000
ref_num:.byte 0 ref_num:.byte 0
@ -20440,7 +20355,7 @@ str_selector_list:
PASCAL_STRING "Selector.List" PASCAL_STRING "Selector.List"
.proc read_params .proc read_params
params: .byte 4 param_count: .byte 4
ref_num:.byte 0 ref_num:.byte 0
buffer: .addr $1400 buffer: .addr $1400
request:.word $400 request:.word $400
@ -20448,7 +20363,7 @@ trans: .word 0
.endproc .endproc
.proc close_params .proc close_params
params: .byte 1 param_count: .byte 1
ref_num:.byte 0 ref_num:.byte 0
.endproc .endproc
@ -20613,7 +20528,7 @@ L0CCB: MLI_RELAY_CALL CLOSE, close_params2
jmp L0D0A jmp L0D0A
.proc open_params2 .proc open_params2
params: .byte 3 param_count: .byte 3
path: .addr str_desk_acc path: .addr str_desk_acc
buffer: .addr $1000 buffer: .addr $1000
ref_num:.byte 0 ref_num:.byte 0
@ -20621,7 +20536,7 @@ ref_num:.byte 0
open_params2_ref_num := open_params2::ref_num open_params2_ref_num := open_params2::ref_num
.proc read_params2 .proc read_params2
params: .byte 4 param_count: .byte 4
ref_num:.byte 0 ref_num:.byte 0
buffer: .addr $1400 buffer: .addr $1400
request:.word $200 request:.word $200
@ -20630,7 +20545,7 @@ trans: .word 0
read_params2_ref_num := read_params2::ref_num read_params2_ref_num := read_params2::ref_num
.proc get_file_info_params .proc get_file_info_params
params: .byte $A param_count: .byte $A
path: .addr str_desk_acc path: .addr str_desk_acc
access: .byte 0 access: .byte 0
type: .byte 0 type: .byte 0
@ -20647,7 +20562,7 @@ ctime: .word 0
.byte 0 .byte 0
.proc close_params2 .proc close_params2
params: .byte 1 param_count: .byte 1
ref_num:.byte 0 ref_num:.byte 0
.endproc .endproc
close_params2_ref_num := close_params2::ref_num close_params2_ref_num := close_params2::ref_num
@ -20888,7 +20803,7 @@ L0EB0: .addr s00,s01,s02,s03,s04,s05,s06
.proc get_file_info_params2 .proc get_file_info_params2
params: .byte $A param_count: .byte $A
path: .addr desktop_main::L4862 path: .addr desktop_main::L4862
access: .byte 0 access: .byte 0
type: .byte 0 type: .byte 0
@ -20903,7 +20818,7 @@ ctime: .word 0
.byte 0 .byte 0
.proc get_prefix_params .proc get_prefix_params
params: .byte 1 param_count: .byte 1
buffer: .addr desktop_main::L4862 buffer: .addr desktop_main::L4862
.endproc .endproc

133
desktop/macros.inc Normal file
View File

@ -0,0 +1,133 @@
;;; ==================================================
;;; Generic Macros
;;; ==================================================
;;; ==================================================
;;; Calls with one parameter (address in A,X)
.macro addr_call target, addr
lda #<addr
ldx #>addr
jsr target
.endmacro
.macro addr_jump target, addr
lda #<addr
ldx #>addr
jmp target
.endmacro
;;; ==================================================
;;; Calls with two paramters (call # in y, address in A,X)
;;; (various output orders to match original binary)
.macro axy_call target, yparam, addr
lda #<addr
ldx #>addr
ldy #yparam
jsr target
.endmacro
.macro yax_call target, yparam, addr
ldy #yparam
lda #<addr
ldx #>addr
jsr target
.endmacro
.macro yxa_call target, yparam, addr
ldy #yparam
ldx #>addr
lda #<addr
jsr target
.endmacro
.macro yxa_jump target, yparam, addr
ldy #yparam
ldx #>addr
lda #<addr
jmp target
.endmacro
;;; ==================================================
;;; 16-bit pseudo-ops
;;; Load A,X (immediate or absolute)
;;; ldax $1234
;;; ldax #$1234
.macro ldax arg
.if (.match (.mid (0, 1, {arg}), #))
lda #<(.right (.tcount ({arg})-1, {arg}))
ldx #>(.right (.tcount ({arg})-1, {arg}))
.else
lda arg
ldx arg+1
.endif
.endmacro
;;; Store A,X (absolute)
;;; stax $1234
.macro stax arg
sta arg
stx arg+1
.endmacro
;;; Add arg1 (absolute) to arg2 (immediate or absolute), store to arg3
;;; add16 $1111, $2222, $3333
;;; add16 $1111, #$2222, $3333
.macro add16 aa, bb, rr
.if (.match (.mid (0, 1, {bb}), #))
lda aa
clc
adc #<(.right (.tcount ({bb})-1, {bb}))
sta rr
lda aa+1
adc #>(.right (.tcount ({bb})-1, {bb}))
sta rr+1
.else
lda aa
clc
adc bb
sta rr
lda aa+1
adc bb+1
sta rr+1
.endif
.endmacro
;;; Add arg1 (absolute) to arg2 (8-bit absolute), store to arg3
;;; add16_8 $1111, $22, $3333
;;; add16_8 $1111, #$22, $3333
.macro add16_8 aa, bb, rr
lda aa
clc
adc bb
sta rr
lda aa+1
adc #0
sta rr+1
.endmacro
;;; Subtract arg2 (immediate or absolute) from arg1, store to arg3
;;; sub16 $1111, $2222, $3333
;;; sub16 $1111, #$2222, $3333
.macro sub16 aa, bb, rr
.if (.match (.mid (0, 1, {bb}), #))
lda aa
sec
sbc #<(.right (.tcount ({bb})-1, {bb}))
sta rr
lda aa+1
sbc #>(.right (.tcount ({bb})-1, {bb}))
sta rr+1
.else
lda aa
sec
sbc bb
sta rr
lda aa+1
sbc bb+1
sta rr+1
.endif
.endmacro