incdir "include:" include "system.gs" bsr Start ;oteverni okna a alokace vseho bsr Generuj bsr vypis bsr makeheap bsr vypis bsr utrid bsr vypis konec3 move.l vystup,d1 CALLDOS Close konec2 move.l _DOSBase,a1 CALLEXEC CloseLibrary konec1 rts *** Podprogramy *** utrid moveq #99-1,d7 ;99x vybereme minimum a prestavime haldu move.l #200,d6 ;cislo posledniho prvku move.l #pole-2,a5 moveq #0,d4 moveq #0,d0 moveq #0,d5 utr1 move.w (a5,d6),d0 move.w 2(a5),(a5,d6) move.w d0,2(a5) ;prohodili jsme - prestavime haldu move.w #2,d4 ;v d4 prvni prvek utr5 move.w d4,d5 ;v d4 je otec lsl.l #1,d5 ;v d5 1. syn cmp d5,d6 bls utr3 ;skaceme - nejsou synove utr2 subq #2,d6 cmp d5,d6 beq utr4 ;skok - je jen jeden syn move.w (a5,d5),d0 ;levy syn move.w 2(a5,d5),d1 ;pravy syn cmp d0,d1 bcc utr4 addq #2,d5 ;mensi je pravy syn utr4 addq #2,d6 ;v d5 je mensi ze synu move.w (a5,d5),d0 ;syn move.w (a5,d4),d1 ;otec cmp d0,d1 bls utr3 move.w d0,(a5,d4) ;prohodime move.w d1,(a5,d5) move.w d5,d4 bra utr5 utr3 subq #2,d6 dbra d7,utr1 rts makeheap moveq #2,d6 ;momentalni velikost - po dvou moveq #99-1,d7 move.l #pole-2,a5 moveq #0,d1 moveq #0,d2 mh1 addq #2,d6 ;v d6 index pridavaneho prvku move.l d6,d4 ;v d4 index syna mh3 move.l d4,d5 ;jdeme nahore ve strome lsr.l #2,d5 lsl.l #1,d5 ;v d5 index otce beq mh2 ;uz jsme uplne nahore move.w (a5,d4),d0 ;v d0 hodnota syna move.w (a5,d5),d1 ;v d1 otce cmp.w d0,d1 bls mh2 ;uz je halda v poradku move.w d1,(a5,d4) ;jeste neni - prohodime move.w d0,(a5,d5) move.l d5,d4 bra mh3 mh2 dbra d7,mh1 rts vypis move.l #pole,a5 moveq #100-1,d6 vyplab2 moveq #4-1,d7 moveq #0,d0 move.w (a5)+,d0 ;v d0 je cislo move.l #cislo,a1 ;adresa vypisovaneho bufferu swap d0 vyplab1 rol.l #4,d0 add.w #48,d0 cmp.w #58,d0 bcs noch add.w #7,d0 noch move.b d0,(a1)+ clr.w d0 dbf d7,vyplab1 move.l vystup,d1 move.l #cislo,d2 move.l #5,d3 CALLDOS Write dbf d6,vyplab2 move.l vystup,d1 move.l #odrad,d2 move.l #2,d3 CALLDOS Write rts Generuj ;procedura vygeneruje nahodna cisla - 100 wordu moveq #100-1,d7 move.l #pole,a0 move.l #$FFFF,d0 genlab bsr Rnd move.w d1,(a0)+ dbf d7,genlab rts ; D0 - Range (0 - x) ; D1 - Returns Number (Long Word, But Only Grab Word!) Rnd Move.w .seed(pc),d1 ;rnd by Ballfrog Mulu #9377,d1 Add.w #1,d1 ;9439 Move.w d1,.seed ; Store Value For Seed Next Time And.l #$7FFF,d1 ; Make Sure Positive Word Divu d0,d1 Swap d1 ; Make Remainder Low Word Rts .seed dc.w 1 Start move.l (sp)+,a5 ;vybereme navratovou adresu moveq #39,d0 move.l #dosname,a1 CALLEXEC OpenLibrary tst.l d0 beq konec1 move.l d0,_DOSBase move.l #newvystup,d1 move.l #MODE_NEWFILE,d2 CALLDOS Open tst.l d0 beq konec2 move.l d0,vystup jmp (a5) ;vse v poradku - vyskocime ***Data*** dosname dc.b 'dos.library',0 newvystup dc.b 'con:0/0/624/250/Halda/close/wait',0 _DOSBase ds.l 1 vystup ds.l 1 cislo dc.b 0,0,0,0,32,0 cnop 0,2 odrad dc.b 10,10 pole dcb.w 100,00