123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- ; SUB32
- ; TOP of the stack - DEHL
- ; Pops operand out of the stack (CALLEE)
- ; and returns result in DEHL
- ; Operands come reversed => So we swap then using EX (SP), HL
- ;
- __SUB32:
- lda z80_c ;- exx
- ldx z80_cp
- stx z80_c
- sta z80_cp
- lda z80_b
- ldx z80_bp
- stx z80_b
- sta z80_bp
- lda z80_e
- ldx z80_ep
- stx z80_e
- sta z80_ep
- lda z80_d
- ldx z80_dp
- stx z80_d
- sta z80_dp
- lda z80_l
- ldx z80_lp
- stx z80_l
- sta z80_lp
- lda z80_h
- ldx z80_hp
- stx z80_h
- sta z80_hp
- pla ;- pop bc ; Return address
- sta z80_b
- pla
- sta z80_c
- lda z80_c ;- exx
- ldx z80_cp
- stx z80_c
- sta z80_cp
- lda z80_b
- ldx z80_bp
- stx z80_b
- sta z80_bp
- lda z80_e
- ldx z80_ep
- stx z80_e
- sta z80_ep
- lda z80_d
- ldx z80_dp
- stx z80_d
- sta z80_dp
- lda z80_l
- ldx z80_lp
- stx z80_l
- sta z80_lp
- lda z80_h
- ldx z80_hp
- stx z80_h
- sta z80_hp
- tsx ;- ex (sp),hl
- lda $0103,x
- ldy z80_h
- sta z80_h
- tya
- sta $0103,x
- lda $0104,x
- ldy z80_l
- sta z80_l
- tya
- sta $104,x
- pla ;- pop bc
- sta z80_b
- pla
- sta z80_c
- ora z80_a ;- or a
- lda z80_l ;- sbc hl,bc
- sbc z80_c
- sta z80_l
- lda z80_h
- sbc z80_b
- sta z80_h
- lda z80_e ;- ex_de_hl
- ldx z80_l
- stx z80_e
- sta z80_l
- lda z80_d
- ldx z80_h
- stx z80_d
- sta z80_h
- tsx ;- ex (sp),hl
- lda $0103,x
- ldy z80_h
- sta z80_h
- tya
- sta $0103,x
- lda $0104,x
- ldy z80_l
- sta z80_l
- tya
- sta $104,x
- pla ;- pop bc
- sta z80_b
- pla
- sta z80_c
- lda z80_l ;- sbc hl,bc
- sbc z80_c
- sta z80_l
- lda z80_h
- sbc z80_b
- sta z80_h
- lda z80_e ;- ex_de_hl
- ldx z80_l
- stx z80_e
- sta z80_l
- lda z80_d
- ldx z80_h
- stx z80_d
- sta z80_h
- lda z80_c ;- exx
- ldx z80_cp
- stx z80_c
- sta z80_cp
- lda z80_b
- ldx z80_bp
- stx z80_b
- sta z80_bp
- lda z80_e
- ldx z80_ep
- stx z80_e
- sta z80_ep
- lda z80_d
- ldx z80_dp
- stx z80_d
- sta z80_dp
- lda z80_l
- ldx z80_lp
- stx z80_l
- sta z80_lp
- lda z80_h
- ldx z80_hp
- stx z80_h
- sta z80_hp
- lda z80_c ;- push bc ; Put return address
- pha
- lda z80_b
- pha
- lda z80_c ;- exx
- ldx z80_cp
- stx z80_c
- sta z80_cp
- lda z80_b
- ldx z80_bp
- stx z80_b
- sta z80_bp
- lda z80_e
- ldx z80_ep
- stx z80_e
- sta z80_ep
- lda z80_d
- ldx z80_dp
- stx z80_d
- sta z80_dp
- lda z80_l
- ldx z80_lp
- stx z80_l
- sta z80_lp
- lda z80_h
- ldx z80_hp
- stx z80_h
- sta z80_hp
- rts ;- ret
|