Macros: add/sub16in to use indirect indexed, with integrated INY

This commit is contained in:
Joshua Bell 2018-07-04 20:58:54 -07:00
parent a12a8d3739
commit 3b085738aa
4 changed files with 110 additions and 225 deletions

View File

@ -1203,23 +1203,9 @@ L9B48: bit L9C75
L9B52: MGTK_CALL MGTK::FramePoly, drag_outline_buffer
copy16 #drag_outline_buffer, $08
L9B60: ldy #2
L9B62: lda ($08),y
clc
adc L9C96
sta ($08),y
L9B62: add16in ($08),y, L9C96, ($08),y
iny
lda ($08),y
adc L9C96+1
sta ($08),y
iny
lda ($08),y
clc
adc L9C98
sta ($08),y
iny
lda ($08),y
adc L9C98+1
sta ($08),y
add16in ($08),y, L9C98, ($08),y
iny
cpy #icon_poly_size
bne L9B62
@ -1823,14 +1809,7 @@ icon_poly_size := (8 * .sizeof(MGTK::Point)) + 2
;; Bottom edge of icon (v2, v7)
ldy #10 ; bitmap y2
lda (bitmap_ptr),y
clc
adc poly::v0::ycoord
sta poly::v2::ycoord
iny
lda ($08),y
adc poly::v0::ycoord+1
sta poly::v2::ycoord+1
add16in (bitmap_ptr),y, poly::v0::ycoord, poly::v2::ycoord
lda poly::v2::ycoord ; 2px down
clc
@ -2315,41 +2294,13 @@ LA56F: pla
tax
copy16 icon_ptrs,x, $06
ldy #3
lda ($06),y
clc
adc LA567
sta ($06),y
add16in ($06),y, LA567, ($06),y
iny
lda ($06),y
adc LA568
sta ($06),y
iny
lda ($06),y
clc
adc LA569
sta ($06),y
iny
lda ($06),y
adc LA56A
sta ($06),y
add16in ($06),y, LA569, ($06),y
ldy #3
lda ($06),y
sec
sbc LA56B
sta ($06),y
sub16in ($06),y, LA56B, ($06),y
iny
lda ($06),y
sbc LA56C
sta ($06),y
iny
lda ($06),y
sec
sbc LA56D
sta ($06),y
iny
lda ($06),y
sbc LA56E
sta ($06),y
sub16in ($06),y, LA56D, ($06),y
jsr pop_zp_addrs
rts
@ -2361,41 +2312,13 @@ LA5CB: pla
tax
copy16 icon_ptrs,x, $06
ldy #3
lda ($06),y
sec
sbc LA567
sta ($06),y
sub16in ($06),y, LA567, ($06),y
iny
lda ($06),y
sbc LA568
sta ($06),y
iny
lda ($06),y
sec
sbc LA569
sta ($06),y
iny
lda ($06),y
sbc LA56A
sta ($06),y
sub16in ($06),y, LA569, ($06),y
ldy #3
lda ($06),y
clc
adc LA56B
sta ($06),y
add16in ($06),y, LA56B, ($06),y
iny
lda ($06),y
adc LA56C
sta ($06),y
iny
lda ($06),y
clc
adc LA56D
sta ($06),y
iny
lda ($06),y
adc LA56E
sta ($06),y
add16in ($06),y, LA56D, ($06),y
jsr pop_zp_addrs
rts

View File

@ -233,14 +233,7 @@ L415B: sta active_window_id
jsr window_lookup
stax $06
ldy #$16
lda ($06),y
sec
sbc grafport2::viewloc::ycoord
sta L4242
iny
lda ($06),y
sbc grafport2::viewloc::ycoord+1
sta L4243
sub16in ($06),y, grafport2::viewloc::ycoord, L4242
cmp16 L4242, #15
bpl L41CB
jsr offset_grafport2
@ -4000,24 +3993,9 @@ L60DE: lda active_window_id
sta ($06),y
L6112: ldy #$14
lda ($06),y
sec
sbc port_copy+MGTK::GrafPort::viewloc+MGTK::Point::xcoord
sta L6197
sub16in ($06),y, port_copy+MGTK::GrafPort::viewloc+MGTK::Point::xcoord, L6197
iny
lda ($06),y
sbc port_copy+MGTK::GrafPort::viewloc+MGTK::Point::xcoord+1
sta L6197+1
iny
lda ($06),y
sec
sbc port_copy+MGTK::GrafPort::viewloc+MGTK::Point::ycoord
sta L6199
iny
lda ($06),y
sbc port_copy+MGTK::GrafPort::viewloc+MGTK::Point::ycoord+1
sta L6199+1
sub16in ($06),y, port_copy+MGTK::GrafPort::viewloc+MGTK::Point::ycoord, L6199
ldx active_window_id
dex
@ -4043,23 +4021,9 @@ L6161: txa
jsr icon_entry_lookup
stax $06
ldy #$03
lda ($06),y
clc
adc L6197
sta ($06),y
add16in ($06),y, L6197, ($06),y
iny
lda ($06),y
adc L6198
sta ($06),y
iny
lda ($06),y
clc
adc L6199
sta ($06),y
iny
lda ($06),y
adc L619A
sta ($06),y
add16in ($06),y, L6199, ($06),y
pla
tax
inx
@ -8305,47 +8269,19 @@ port_copy:
;; iconx
ldy #IconEntry::iconx
lda (entry_ptr),y
clc
adc pos_screen
sta (entry_ptr),y
iny
lda (entry_ptr),y
adc pos_screen+1
sta (entry_ptr),y
add16in (entry_ptr),y, pos_screen, (entry_ptr),y
iny
;; icony
lda (entry_ptr),y
clc
adc pos_screen+2
sta (entry_ptr),y
iny
lda (entry_ptr),y
adc pos_screen+3
sta (entry_ptr),y
add16in (entry_ptr),y, pos_screen+2, (entry_ptr),y
;; iconx
ldy #IconEntry::iconx
lda (entry_ptr),y
sec
sbc pos_win
sta (entry_ptr),y
iny
lda (entry_ptr),y
sbc pos_win+1
sta (entry_ptr),y
sub16in (entry_ptr),y, pos_win, (entry_ptr),y
iny
;; icony
lda (entry_ptr),y
sec
sbc pos_win+2
sta (entry_ptr),y
iny
lda (entry_ptr),y
sbc pos_win+3
sta (entry_ptr),y
sub16in (entry_ptr),y, pos_win+2, (entry_ptr),y
jsr pop_zp_addrs
rts
@ -8397,47 +8333,19 @@ pos_win: .word 0, 0
;; iconx
ldy #IconEntry::iconx
lda (entry_ptr),y
sec
sbc pos_screen
sta (entry_ptr),y
iny
lda (entry_ptr),y
sbc pos_screen+1
sta (entry_ptr),y
sub16in (entry_ptr),y, pos_screen, (entry_ptr),y
iny
;; icony
lda (entry_ptr),y
sec
sbc pos_screen+2
sta (entry_ptr),y
iny
lda (entry_ptr),y
sbc pos_screen+3
sta (entry_ptr),y
sub16in (entry_ptr),y, pos_screen+2, (entry_ptr),y
;; iconx
ldy #IconEntry::iconx
lda (entry_ptr),y
clc
adc pos_win
sta (entry_ptr),y
iny
lda (entry_ptr),y
adc pos_win+1
sta (entry_ptr),y
add16in (entry_ptr),y, pos_win, (entry_ptr),y
iny
;; icony
lda (entry_ptr),y
clc
adc pos_win+2
sta (entry_ptr),y
iny
lda (entry_ptr),y
adc pos_win+3
sta (entry_ptr),y
add16in (entry_ptr),y, pos_win+2, (entry_ptr),y
jsr pop_zp_addrs
rts

View File

@ -25,41 +25,13 @@ L853B: lda ($08),y
cpx #$04
bne L853B
ldy #$03
lda ($06),y
sec
sbc L8590
sta ($06),y
sub16in ($06),y, L8590, ($06),y
iny
lda ($06),y
sbc L8591
sta ($06),y
iny
lda ($06),y
sec
sbc L8592
sta ($06),y
iny
lda ($06),y
sbc L8593
sta ($06),y
sub16in ($06),y, L8592, ($06),y
ldy #$03
lda ($06),y
clc
adc L8594
sta ($06),y
add16in ($06),y, L8594, ($06),y
iny
lda ($06),y
adc L8595
sta ($06),y
iny
lda ($06),y
clc
adc L8596
sta ($06),y
iny
lda ($06),y
adc L8597
sta ($06),y
add16in ($06),y, L8596, ($06),y
jsr $83A5
rts

View File

@ -4,6 +4,7 @@
.define _is_immediate(arg) (.match (.mid (0, 1, {arg}), #))
.define _is_register(arg) (.match ({arg}, x) .or .match ({arg}, y))
.define _is_y_register(arg) (.match ({arg}, y))
.define _immediate_value(arg) (.right (.tcount ({arg})-1, {arg}))
.macro _op_lo op, arg
@ -315,6 +316,79 @@ end:
.endif
.endmacro
;;; Core for add16in/sub16in
.macro _addsub16in op, opc, arg1, arg2, arg3, arg4, arg5, arg6
.if _is_y_register {arg2} && _is_y_register {arg4} && _is_y_register {arg6}
;; xxx16in $1111,y, $2222,y, $3333,y
lda (arg1),y
opc
op (arg3),y
sta (arg5),y
iny
lda (arg1),y
op (arg3),y
sta (arg5),y
.elseif _is_y_register {arg2} && _is_y_register {arg4}
;; xxx16in $1111,y, $2222,y, $3333
lda (arg1),y
opc
op (arg3),y
sta arg5
iny
lda (arg1),y
op (arg3),y
sta arg5+1
.elseif _is_y_register {arg2} && _is_y_register {arg5}
;; xxx16in $1111,y, $2222, $3333,y
;; xxx16in $1111,y, #$2222, $3333,y
lda (arg1),y
opc
_op_lo op, {arg3}
sta (arg4),y
iny
lda (arg1),y
_op_hi op, {arg3}
sta (arg4),y
.elseif _is_y_register {arg2}
;; xxx16in $1111,x, $2222, $3333
;; xxx16in $1111,x, #$2222, $3333
lda (arg1),y
opc
_op_lo op, {arg3}
sta arg4
iny
lda (arg1),y
_op_hi op, {arg3}
sta arg4+1
.elseif _is_y_register {arg3}
;; xxx16in $1111, $2222,y $3333
;; xxx16in #$1111, $2222,y $3333
_op_lo lda, {arg1}
opc
op (arg2),y
sta arg4
iny
_op_hi lda, {arg1}
op (arg2),y
sta arg4+1
.elseif _is_y_register {arg4}
;; xxx16in $1111, $2222, $3333,y
;; xxx16in #$1111, $2222, $3333,y
;; xxx16in $1111, #$2222, $3333,y
;; xxx16in #$1111, #$2222, $3333,y
_op_lo lda, {arg1}
opc
_op_lo op, {arg2}
sta (arg3),y
iny
_op_hi lda, {arg1}
_op_hi op, {arg2}
sta (arg3),y
.else
.error "Indirect indexed required at least one use of y reg"
.endif
.endmacro
;;; Add arg1 to arg2, store to arg3
;;; add16 $1111, $2222, $3333 ; absolute, absolute, absolute
;;; add16 $1111, #$2222, $3333 ; absolute, immediate, absolute
@ -330,6 +404,10 @@ end:
.macro add16lc arg1, arg2, arg3, arg4, arg5, arg6
_addsub16lc adc, clc, arg1, arg2, arg3, arg4, arg5, arg6
.endmacro
;;; (as above, but indirect indexed, y register is incremented)
.macro add16in arg1, arg2, arg3, arg4, arg5, arg6
_addsub16in adc, clc, arg1, arg2, arg3, arg4, arg5, arg6
.endmacro
;;; Add arg1 (absolute) to arg2 (8-bit absolute), store to arg3
@ -374,6 +452,10 @@ end:
.macro sub16lc arg1, arg2, arg3, arg4, arg5, arg6
_addsub16lc sbc, sec, arg1, arg2, arg3, arg4, arg5, arg6
.endmacro
;;; (as above, but indirect indexed, y register incremented)
.macro sub16in arg1, arg2, arg3, arg4, arg5, arg6
_addsub16in sbc, sec, arg1, arg2, arg3, arg4, arg5, arg6
.endmacro
;;; Subtract arg2 from arg1, store to arg3
;;; sub16_8 #$1111, #$22, $3333 ; immediate, immediate, absolute