Random line of code thread
category: code [glöplog]
Code:
PlasmaX:
LEA (EBX + number)
STOSD
....
// 80 times unroll (320 pixels)
JP NZ,PlasmaX
EBX has SIN(Y1) + SIN(Y2 + time)
number can be SIN(X1) + SIN(X2 + time), automodify code for just 80 values.
sines have to be from 0 to 63 to add to 0-255 range.
could also be LEA(ECX + EBX + number) I think
where ECX could be SIN(Z1)+ SIN(Z2 + time) for 3d plasma!
That's one fast plasma.
only thing making it fast is the loop-unrolling and the precalced tables. also using bytes only, sure!
but a fast-typed/coded-plasma it is for sure! thanks to macros!
oh, wait, almost forgot about random code:
MAX HEADROOM = #$ffff ;Define amount of room for max artificial intelligence here!
init: //fill subTourettine here!
main: bsr subTourettine
btst #6,#$bfe001
bne main
rts
subTourettine: blk.l #MAX_HEADROOM, rts
but a fast-typed/coded-plasma it is for sure! thanks to macros!
oh, wait, almost forgot about random code:
MAX HEADROOM = #$ffff ;Define amount of room for max artificial intelligence here!
init: //fill subTourettine here!
main: bsr subTourettine
btst #6,#$bfe001
bne main
rts
subTourettine: blk.l #MAX_HEADROOM, rts
fucked up the "define" there, missing an underscore, happens if you code sth without indents and without actually ever assembling it ;) still wish there would be an easy implementation of [code], where the pouet-editor would realize you opened an editor for code via BB and changing the behaviour of every browser until you close the code-segment via BB again. ;) -> not even in the most far future i say!
NOP
Code:
if (m_nZoom == 0) // Fit to display
m_sizeTotal.cx = m_rcClient.Width();
else if(m_nZoom == 1) // 1:1
m_sizeTotal.cx = dwLen;
else if(m_nZoom > 1) // Zoom out
m_sizeTotal.cx = (dwLen + (1 << (m_nZoom- 1)) - 1) >> (m_nZoom - 1);
else // Zoom in
m_sizeTotal.cx = dwLen + m_rcClient.Width() - (m_rcClient.Width() >> (-m_nZoom - 1));
Code:
cmp.w #$601a,(a0) ; Atari ST executable? -> convert to standard Amiga exe
I have a square grid with 0s and 1s.
I want to draw it with as few Box(x1;y1)->(x2;y2) instructions as possible.
Here's a first greedy try, not always optimal, as the coment shows.
Is it possible to find the optimal solution in an elegant way?
I want to draw it with as few Box(x1;y1)->(x2;y2) instructions as possible.
Here's a first greedy try, not always optimal, as the coment shows.
Is it possible to find the optimal solution in an elegant way?
Code:
//Note: In the case aside, biggest box filling is not 111110
//optimal, it gives 4 boxes while simple horizontal 011111
//boxes would give 3. But that's quite rare IMO. 111110
//As long as there are pixels set to 1:
// Search for the biggest box
// if Width*(Height+1-y) <= BestBoxSize we can stop searching for this iteration!
// (assuming we're making an y loop first)
// if (width-x)*(height-y) <= BiggestFoundBox we can stop searching for this cell!
// Output \psframe for this box
// Fill this box with 0s in the array
// Decrease nb of 1s by w*h
//Loop
while(NbColoredSquares>0) {
BestBoxSize=0;
y=1;
while((y<=Height) && (Width*(Height+1-y)>BestBoxSize)) {
x=1;
while((x<=Width) && ((Width+1-x)*(Height+1-y)>BestBoxSize)) {
if(Coloring[x][y]==1) {
BestBoxSizeForThisCell=0;
MaxDXForThisCell=Width-x;
dy=0;
while(Coloring[x][y+dy]==1) {
dx=0;
while((Coloring[x+dx+1][y+dy]==1) && (dx<=MaxDXForThisCell)) {
dx++;
}
if(dx<MaxDXForThisCell) { MaxDXForThisCell=dx; }
CurrentBoxSize=(MaxDXForThisCell+1)*(dy+1);
if(CurrentBoxSize>BestBoxSizeForThisCell) {
BestDXForThisCell=MaxDXForThisCell;
BestDYForThisCell=dy;
BestBoxSizeForThisCell=CurrentBoxSize;
}
dy++;
}
if(BestBoxSizeForThisCell>BestBoxSize) {
BestX=x;
BestY=y;
BestDX=BestDXForThisCell;
BestDY=BestDYForThisCell;
BestBoxSize=BestBoxSizeForThisCell;
}
}
x++;
}
y++;
}
//We know the best box, output FFEN code for it, fill it with 0s
yy=Height+1-BestY;
fprintf(filep,"\\psframe[linewidth=0,");
switch(FFEN_FillStyle) {
case 0: fprintf(filep,"linecolor=lightgray,fillstyle=solid,fillcolor=lightgray]"); break; // 0=lightgray
case 1: fprintf(filep,"linecolor=gray,fillstyle=solid,fillcolor=gray]"); break; // 1=gray
case 2: fprintf(filep,"linecolor=black,fillstyle=solid,fillcolor=black]"); break; // 2=black
case 3: fprintf(filep,"linecolor=white,fillstyle=vlines]"); break; // 3=vlines
case 4: fprintf(filep,"linecolor=white,fillstyle=hlines]"); break; // 4=hlines
case 5: fprintf(filep,"linecolor=white,fillstyle=crosshatch]"); break; // 5=crosshatch
}
fprintf(filep,"(%g,%g)(%g,%g)\n",(BestX-1)*FFEN_SquareSize,yy*FFEN_SquareSize,(BestX+BestDX)*FFEN_SquareSize,(yy-BestDY-1)*FFEN_SquareSize);
for(y=BestY;y<BestY+BestDY+1;y++) {
for(x=BestX;x<BestX+BestDX+1;x++) {
Coloring[x][y]=0;
}
}
NbColoredSquares=NbColoredSquares-BestBoxSize;
}
Code:
float leftb[3] = {NUM_INF, NUM_INF, NUM_INF}, rightb[3] = {-NUM_INF, -NUM_INF, -NUM_INF};
Code:
move.l d0,d1 ; GODDAMN stinkin' BCPL!!!!
Baah: not 100% related but it sounds like a similar problem to Liquid Wars' space partitioning for mass-pathfinding.
Thanks Gargaj, but after a quick read i don't think it would do the trick. A clever algorithm sure, with speed in mind, but i don't see how to transpose the problem...
Also, while the optimal algorithm would be of great theoretical interest, i won't implement it if it's too complex. I should ask on codegolf or elsewhere i think...
Also, while the optimal algorithm would be of great theoretical interest, i won't implement it if it's too complex. I should ask on codegolf or elsewhere i think...
Code:
void sync_save_tracks(const struct sync_device *d)
{
FILE *file = fopen("sync.h","wt");
int len = 0;
FILE *fileread = NULL;
int count;
int i;
int j;
char * buffer;
for (i = 0; i < (int)d->data.num_tracks; ++i) {
const struct sync_track *t = d->data.tracks[i];
save_track(t, sync_track_path(d->base, t->name));
//read trackfile
fprintf(file,"//data from rocket track: %s\n",sync_track_path(d->base, t->name));
fileread = fopen(sync_track_path(d->base, t->name),"rb");
//determine file size
fseek( fileread, 0, SEEK_END);
len = ftell(fileread);
fseek(fileread, 0, SEEK_SET);
//allocate buf
buffer = (char*) malloc (sizeof(char)*len);
//read it
fread (buffer,1,len,fileread);
count = 0;
//write data
fprintf(file,"unsigned char %s[%d] = {\n\t",sync_track_name(d->base, t->name),len);
for (j=0;j<len;j++)
{
fprintf(file,"0x%02x,",buffer[j]);
count++;
if ((count & 15) == 0)
fprintf(file,"\n\t");
}
free (buffer);
fprintf(file,"\n};\n// end of %s\n",sync_track_path(d->base, t->name));
fprintf(file,"\n");
fclose(fileread);
}
fclose(file);
}
when i'm bored...
Code:
masstoredna_compressed()
{
for (int x=0; x<=numberofbases; x++)
{
setoffset(x);
if (changed(inputseq[x], storageseq[x]));
{
write2bit(getbytecount(getoffset());
writepointerbytes(getbytecount(getoffset(), getoffset()));
write2bit(deltaencode(inputseq[x], storageseq[x]);
resetoffset();
}
}
}
Quote:
Code:move.w #$20,$dff01e ;interrupt ok
What do you presume to achieve by writing to a read-only register? :)
Blueberry: you got me there!
Dont booze and code!
Especially not if you havent coded in 68k-asm for >15 years!
For real, i got it from here, when i googled "interrupt 68000".
I didnt even think about if this is correct code or not, just fitted my alcoholised brain of wanting to post sth in this thread!
Dont booze and code!
Especially not if you havent coded in 68k-asm for >15 years!
For real, i got it from here, when i googled "interrupt 68000".
I didnt even think about if this is correct code or not, just fitted my alcoholised brain of wanting to post sth in this thread!
Code:
jmp !skip+
Quote:
Quote:Code:move.w #$20,$dff01e ;interrupt ok
What do you presume to achieve by writing to a read-only register? :)
Thus buggy piece of code is actually present in more old demos than you think. They only work correctly because they jump to the system VBI at the end of their own interrupt routine which then clears the interrupt request bits in $dff09c. :)
Code:
SEI
loop EOR $D012
STA $0400,y
STA $0400+256,y
STA $0400+512,y
STA $0400+768,y
DEY
BVC loop
Not really one line, but a cute text noise in 18 bytes without SEI. :) I'm posting mini routines and micro games every now and then here.
Code:
move.w VIDEOMODE-DT(a4),d1
cmp.w #666,d1
Code:
pixelOut->r = (uint8_t)Clamp(p->r + (p->r * xOff) / 32, 0, 255);
pixelOut->g = (uint8_t)Clamp(p->g + (p->g * xOff) / 32, 0, 255);
pixelOut->b = (uint8_t)Clamp(p->b + (p->b * xOff) / 32, 0, 255);
// ...and mix it with original picture
pixelOut->r = (pixelOut->r + pixelIn->r) / 2u;
pixelOut->g = (pixelOut->g + pixelIn->g) / 2u;
pixelOut->b = (pixelOut->b + pixelIn->b) / 2u;
// And now some cheap image smoothing...
pixelOut[-1].r = (pixelOut->r + pixelOut[-1].r) / 2u;
pixelOut[-1].g = (pixelOut->g + pixelOut[-1].g) / 2u;
pixelOut[-1].b = (pixelOut->b + pixelOut[-1].b) / 2u;
pixelOut[-w].r = (pixelOut->r + pixelOut[-w].r) / 2u;
pixelOut[-w].g = (pixelOut->g + pixelOut[-w].g) / 2u;
pixelOut[-w].b = (pixelOut->b + pixelOut[-w].b) / 2u;
Code:
class Ribbons {
Code:
theServer->trace(cU("Word limbo!"), NULL);
Code:
var batman = Matrix.Identity / 0.0f;
Old loaders are still interesting, quite funny how the companies tried to protect their data :)
Code:
; create sync table based on the key stored in
; the directory (right in front of the first file)
move.l LD_Directory-DT(a5),a0
lea $90(a0),a0 ; key
moveq #8-1,d7 ; key length: 8 bytes
lea LD_TAB(pc),a1
.filltab
move.b (a0)+,d0
move.b d0,d1 ; key, low nibble
lsr.w #4,d1 ; key, high nibble
and.w #15,d0
and.w #15,d1
move.w d1,(a1)+
move.w d0,(a1)+
dbf d7,.filltab
lea SYNCTAB(pc),a0
lea LD_TAB(pc),a1
lea SYNCTAB2(pc),a2
moveq #16-1,d7 ; number of used SYNC values
.make_synctab
move.w (a1)+,d0
asl.w #1,d0
move.w (a0,d0.w),(a2)+
dbf d7,.make_synctab