; ; File generated by cc65 v 2.11.0 ; .fopt compiler,"cc65 v 2.11.0" .setcpu "6502" .smart on .autoimport on .case on .debuginfo on .importzp sp, sreg, regsave, regbank, tmp1, ptr1, ptr2 .macpack longbranch .dbg file, "bsearch.c", 999, 1067464299 .dbg file, "../../include/stdlib.h", 5287, 1122210074 .export _bsearch ; --------------------------------------------------------------- ; void* __fastcall__ bsearch (const void*, const void*, unsigned int, unsigned int, function returning int*) ; --------------------------------------------------------------- .segment "CODE" .proc _bsearch .segment "CODE" ; ; { ; .dbg line, "bsearch.c", 15 jsr pushax ; ; int found = 0; ; .dbg line, "bsearch.c", 18 jsr decsp4 ldx #$00 txa jsr pushax ; ; int first = 0; ; .dbg line, "bsearch.c", 19 jsr pushax ; ; int last = n - 1; ; .dbg line, "bsearch.c", 20 ldy #$0D jsr ldaxysp sec sbc #$01 bcs L0006 dex L0006: jsr pushax ; ; while (first <= last) { ; .dbg line, "bsearch.c", 23 L0007: ldy #$05 jsr pushwysp ldy #$03 jsr ldaxysp jsr tosicmp beq L0029 jpl L0008 ; ; current = (last + first) / 2; ; .dbg line, "bsearch.c", 26 L0029: ldy #$00 lda (sp),y clc ldy #$02 adc (sp),y pha dey lda (sp),y ldy #$03 adc (sp),y tax pla jsr asrax1 ldy #$08 jsr staxysp ; ; result = cmp ((void*) (((int) base) + current*size), key); ; .dbg line, "bsearch.c", 29 ldy #$0D jsr pushwysp jsr decsp4 ldy #$19 jsr pushwysp ldy #$13 jsr pushwysp ldy #$17 jsr ldaxysp jsr tosumulax jsr tosaddax ldy #$02 sta (sp),y iny txa sta (sp),y ldy #$19 jsr ldaxysp ldy #$00 sta (sp),y iny txa sta (sp),y ldy #$05 jsr ldaxysp jsr callax jsr incsp2 ldy #$06 jsr staxysp ; ; if (result < 0) { ; .dbg line, "bsearch.c", 30 txa bpl L0013 ; ; first = current + 1; ; .dbg line, "bsearch.c", 31 ldy #$09 jsr ldaxysp clc adc #$01 bcc L0017 inx L0017: ldy #$02 jsr staxysp ; ; } else { ; .dbg line, "bsearch.c", 32 jmp L0007 ; ; last = current - 1; ; .dbg line, "bsearch.c", 33 L0013: ldy #$09 jsr ldaxysp sec sbc #$01 bcs L001B dex L001B: ldy #$00 jsr staxysp ; ; if (result == 0) { ; .dbg line, "bsearch.c", 34 ldy #$06 lda (sp),y iny ora (sp),y jne L0007 ; ; found = 1; ; .dbg line, "bsearch.c", 39 tax lda #$01 ldy #$04 jsr staxysp ; ; } ; .dbg line, "bsearch.c", 42 jmp L0007 ; ; return (void*) (found? ((int) base) + first*size : 0); ; .dbg line, "bsearch.c", 45 L0008: ldy #$05 lda (sp),y dey ora (sp),y beq L0023 ldy #$13 jsr pushwysp ldy #$07 jsr pushwysp ldy #$11 jsr ldaxysp jsr tosumulax jsr tosaddax jmp L0002 L0023: tax ; ; } ; .dbg line, "bsearch.c", 46 L0002: ldy #$14 jmp addysp .dbg line .endproc