; name: Fireworx ; date: 31.05.99 ; type: particles ; need: 2nd VRAM ; 470 bytes code ; 3370 bytes other (including generated tables) ; some stack ; maybe usable for 512 bytes intro...:-) (after some size optimizations - or packing) ; only fast RAM is used for code and IM2 tables, should run on each 128k (not tested) ; effect looks like shit - but colours are nice (well, I wanted better, but blur made it ; slow as hell.....) ; coded especially for SMG/CTL by SS/SMG/CTL org 44288 ; because of my assembler - this is first nice available adress ent START ; startpoint START call INITIM2 ; IM2 initialisation call INITWRK ; prepare tables, clear work area, etc. LOOP halt ; Blink, or not to blink? btw, the effect is quite ; fast, and with more particles isn't very nice, so ; add some halt's to change speed (one more halt is ; good) ld bc,32765 ld a,23 out (c),a ; First VRAM visible, Second VRAM paged call FIREWORX ; make effect halt ; same as the first halt ld bc,32765 ld a,29 out (c),a ; Second VRAM visible, First VRAM paged call FIREWORX ld a,127 in a,(254) rra jr c,LOOP ; If SPACE was pressed then get out, else loop call BACKIM1 ; prepare for return to BASIC ret ;routines for IM2 (usable for testing) BACKIM1 di ; prepare system for return to BASIC ld bc,32765 ld a,16 out (c),a ld a,63 ld i,a ld hl,10072 exx ld iy,23610 im 1 ei ret INITIM2 di ld hl,IM2TAB ld e,1 ld d,h ld b,e ld c,l ld a,h ld (hl),#BE ; higher byte of IM2 redirector :-) ldir ld i,a ld a,195 ld (#BEBE),a ; jump to ld hl,IM2HAND ; adress, where is the cool im2 routine ld (#BEBF),hl im 2 ei ret IM2HAND ei ; my IM2 routine does nothing ret ; routines for initalizations INITWRK ld hl,PARTTAB ; clears partition table ld de,parttab+1 ld bc,256*5-1 ld (hl),0 ldir call MAKETABS ; generate all needed tables ret MAKETABS ld hl,ADRTAB1 ; first putpixel table (ycoords) ld de,49152 ; - adressess for linear mapped screen ld b,96 ; but we use 2x2 pixels MALP1 ld (hl),e inc h ld (hl),d dec h inc l inc d call DOWNDE djnz MALP1 ld hl,ADRTAB2 ; second putpixel table (xcoords) ld a,0 ; - offsets in line for all pixels MALP2 ld bc,4*256+128+64 ; in each byte are 4 positions for our pixels ; (initial is ##------ == 128+64) MALP3 ld (hl),a inc h ld (hl),c dec h inc l or a rr c rr c djnz MALP3 inc a cp 32 jr nz,MALP2 ret DOWNDE inc d ; gives adress of pixel on next line ld a,d and 7 ret nz ld a,e add a,32 ld e,a ret c ld a,d sub 8 ld d,a ret ; code for real effect is coming.... please, don't eat before watching, or you can see your ; lunch again.... FIREWORX call CLS ; clear screen call ATRS ; set colour call NEWFIRE ; new rocket exploded (maybe) call FWXDRAW ; draw all particles ret ATRS ld a,ATABLN ; we will cycle colours for each frame - it will ; looks like multicolor a bit... dec a jr nz,ATRSOK ld a,ATABLN ; we reached the end (beginning) of table ATRSOK ld (ATRS+1),a ; save position for next time dec a ld l,a ld h,ATAB/256 ; higher byte of table (will be used many times...) ld a,(hl) ; get value from table ld hl,55296 ld de,55297 ld bc,767 ld (hl),a ldir ret CLS di ; clear screen and do it fast! ld (spstor+1),sp ; push is the fast way (no problem with interrupts ; because I made "halt" before calling cls (see main ; loop), In fact di isn't necessary, but it cannot ; make any problems... ld sp,55296 ld hl,0 ld b,192 CLSLP push hl push hl push hl push hl ; 8 bytes push hl push hl push hl push hl ; 16 bytes push hl push hl push hl push hl ; 24 bytes push hl push hl push hl ; 32 bytes djnz CLSLP SPSTOR ld sp,0 ei ret RANDOM exx ; hello to RANDOM/CC :-) ld c,a ; how many bits we wanna for the result RND ld de,0 ; only hell knows how it works... But I made some ; changes, because the effect is nicer then... ; Don't ask me, what this changes mean... ld h,e ld l,253 ld a,r ; I added this ... xor d or a sbc hl,de sbc a,0 add a,c ; again my attempt to change something ld e,a ld d,0 sbc hl,de jr nc,RANDOM1 inc hl RANDOM1 ld (RND+1),hl ; we have 16bit random number in hl ld a,l xor h and c ; now we have as big number as we wanted rr h jr nc,RANOK add a,1 ; fireworx are nicer, feel free to change it... neg ; we allow negative values RANOK exx ret NEWFIRE ld a,1 ; we will add new explosion to the sky dec a ld (NEWFIRE+1),a ret nz ; well, not now... ld a,r ; when will be next explosion? and 3 inc a ; will be in next 1..4 frames ld (NEWFIRE+1),a NEWFIRE2 ld a,3 ; what particle set will be changed (we have 4 sets ; of 64 particles) inc a and 3 ld (NEWFIRE2+1),a inc a ld b,a ld de,64*5 ; length of one set ld hl,0 NFLP1 add hl,de ; multiplying - no need for faster multiply as it is ; only low number of executions djnz NFLP1 ld de,PARTTAB-320 add hl,de ; in HL is position in table of particles to write ld a,63 call RANDOM ; random value from -64 to 63 add a,64 ; random value from 0 to 127 - xcoord of new ; explosion ld d,a ld a,31 ; I cannot use the closest smaller value writeable ; with [000....][111....] call RANDOM add a,48 ; ycoord from 16 to 79 ld e,a ld b,64 ; 64 particles NFLP2 ld a,3 call RANDOM ld (hl),a ; speed on x-axis from -3 to 3 inc hl ld a,1 call RANDOM ; xcoord of particle must be nearby center of ; explosion add a,d ld (hl),a ; xcoord of particle ld a,3 call RANDOM ld (hl),a ; speed on y-axis inc hl ld a,1 call RANDOM add a,e ld (hl),a ; ycoord of particle inc hl ld (hl),5 ; colour of new particle is always the biggest ; possible (if isn't effect sux) inc hl djnz NFLP2 ret FWXDRAW ld hl,PARTTAB ; particle drawing ld b,0 ; b=0==256 particles to write ld a,(DECCOL+1) ; colour of particle will decrease only every second ; frame (because it would be very short ;explosion...) xor 1 ld (DECCOL+1),a FWLP1 ld a,(hl) ; xspeed of particle inc hl add a,(hl) ; new xcoord of particle cp 128 ; if we are out of screen, we won't continue jr nc,SKIPXR ld (hl),a ; save it for next time ld e,a ; and be ready to write to screen (scream?? :-) inc hl ld a,(hl) ; particle yspeed GRAVITY add a,1 ; this gravitation is the best in my opinion - but if you want, change it... ld (hl),a ; speed changed! inc hl add a,(hl) ; new ycoord cp 96 jr nc,SKIPYR ; we are out of screen ld (hl),a inc hl ld d,a ; be ready to draw ld a,(hl) ; colour of particle DECCOL sub 0 jr z,SKIPCR ; we won't draw black on black ld (hl),a inc hl ld c,a ; now we have colour in c and coords in d,e push hl ; we will need this registers ld h,ADRTAB1/256 ld l,d ld a,(hl) inc h ld h,(hl) ld l,a ; now we have in hl adress of line with wanted y coord ld d,ADRTAB2/256 ld a,(de) add a,l ld l,a ; now we have adress of wanted byte in the hl inc d ld a,(de) ld e,c sla e ; we have in e offset to pattern to emulate colour (urgh....) ld c,a ; in c we have mask for wanted xcoord in selected byte ld d,DITTAB/256 ld a,(de) and c or (hl) ; draw first line of 2x2 pixel ld (hl),a inc h inc e ld a,(de) and c xor (hl) ld (hl),a ; next line pop hl djnz FWLP1 ; next particle ret SKIPXR inc hl ; moving to next particle in list inc hl SKIPYR inc hl SKIPCR inc hl djnz FWLP1 ret ; needed tables are on the way defs 256-$?256 ; table must be on adress with lower byte 0 DITTAB defb %00000000 ; patterns to emulate colours defb %00000000 defb %10101010 defb %00000000 defb %01010101 defb %10101010 defb %10101010 defb %11111111 defb %11111111 defb %11111111 ; 5 colours for 2x2 pixels defs 256-$?256 ATAB defb 6,66,4,71 ; colours, which will be cycled to emulate nice ; colourfull shitty fireworx defb 3,65,69,1 ; hey, change it!! they sux... I am sure they can be ;better mixed defb 2,68,7,67 defb 5,70 ATABLN equ 14 ; how many colours from the table will be rally used ; all other tables will be generated defs 256-$?256 IM2TAB defs 257 ; I really don't know why it is necessary (I was ; missing at school...:-) defs 256-$?256 ADRTAB1 defs 512 ADRTAB2 defs 512 ; table of particles defs 256-$?256 PARTTAB defs 256*5 ; the end.... ; I don't know, what pseudoinstructions are in other compiler... ; defb x,y,z means bytes x,y,z ; defs xx means xx bytes of ?? ; I added a snapshot of compiler I use (Prometheus) with source - not very commented... ; use cursors to move, ss-k for begin, ss-e for end, ss-r for run, ss-t to see the tables, ; ss-a to assembly and ss-m to monitor (debugger) ; if you want I can send you some docs about this program - but I have them only on paper so ; please don't want it very soon :-) (I hate typewriting) ; ok, written in NotePad with windows switching , I hope I made no ; mistakes/errors/fuckups... Prometheus version is 100% runable... ; ops, I found I somewhere wrote Partition, not Particle - I don't want to mess anyone, I ; just translated it in very hurry (you know, programming for school has higher priority ; unfortunately...) ; And please, send me answer if you will use it and if the code is understable - I really ; hate writing comments, so if you can understand my code without them I will be very ; happy... ; all, bye 4 now