initial commit

This commit is contained in:
2026-07-18 20:34:55 +02:00
commit 59ad004c96
474 changed files with 226635 additions and 0 deletions
+95
View File
@@ -0,0 +1,95 @@
#include <c64/memmap.h>
#include <c64/vic.h>
#include <gfx/bitmap.h>
#include <string.h>
#include <conio.h>
#include <math.h>
#define Color ((char *)0xd000)
#define Hires ((char *)0xe000)
Bitmap Screen, Brush;
void init(void)
{
mmap_trampoline();
mmap_set(MMAP_RAM);
memset(Color, 0x10, 1000);
memset(Hires, 0x00, 8000);
mmap_set(MMAP_NO_ROM);
vic_setmode(VICM_HIRES, Color, Hires);
vic.color_border = VCOL_WHITE;
bm_init(&Screen, Hires, 40, 25);
}
void done(void)
{
mmap_set(MMAP_ROM);
getch();
vic_setmode(VICM_TEXT, (char *)0x0400, (char *)0x1000);
}
int poly_x[] = {0, 32, 32, 24, 40, 32, 32, 64, 52, 42, 22, 12};
int poly_y[] = {64, 0, 20, 36, 36, 20, 0, 64, 64, 44, 44, 64};
struct BlitDemo
{
const char * name;
BlitOp op;
};
BlitDemo blitDemos[11] = {
{"SET", BLTOP_SET},
{"RESET", BLTOP_RESET},
{"NOT", BLTOP_NOT},
{"XOR", BLTOP_XOR},
{"OR", BLTOP_OR},
{"AND", BLTOP_AND},
{"NAND", BLTOP_AND_NOT},
{"COPY", BLTOP_COPY},
{"NCOPY", BLTOP_NCOPY},
{"PATTERN", BLTOP_PATTERN},
{"MASKPAT", BLTOP_PATTERN_AND_SRC},
};
char pat[] = {0x6c, 0xfe, 0xfe, 0xfe, 0x7c, 0x38, 0x10, 0x00};
int main(void)
{
init();
bm_alloc(&Brush, 8, 8);
bm_fill(&Brush, 0);
ClipRect bcr = {0, 0, 64, 64};
bm_polygon_nc_fill(&Brush, &bcr, poly_x, poly_y, 12, NineShadesOfGrey[8]);
bmu_rect_pattern(&Screen, 0, 0, 320, 200, NineShadesOfGrey[2]);
ClipRect scr = {0, 0, 320, 200};
for(int i=0; i<11; i++)
{
int dx = 80 * ((i + 1) % 4);
int dy = 66 * ((i + 1) / 4);
bmu_bitblit(&Screen, dx + 8, dy + 1, &Brush, 0, 0, 64, 64, pat, blitDemos[i].op);
bm_put_string(&Screen, &scr, dx + 8, dy + 20, blitDemos[i].name, BLTOP_COPY);
}
done();
return 0;
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

+9
View File
@@ -0,0 +1,9 @@
#!/bin/sh
../../bin/oscar64 splitscreen.c
../../bin/oscar64 func3d.c -n
../../bin/oscar64 lines.c -n
../../bin/oscar64 polygon.c -n
../../bin/oscar64 bitblit.c -n
../../bin/oscar64 cube3d.c -n
../../bin/oscar64 fractaltree.c -n
../../bin/oscar64 qsort.c -n
+222
View File
@@ -0,0 +1,222 @@
#include <c64/memmap.h>
#include <c64/vic.h>
#include <gfx/bitmap.h>
#include <string.h>
#include <conio.h>
#include <stdio.h>
#include <gfx/vector3d.h>
#include <math.h>
#include <fixmath.h>
char * const Color = (char *)0xd000;
char * const Hires = (char *)0xe000;
Bitmap Screen;
void init(void)
{
mmap_trampoline();
mmap_set(MMAP_RAM);
memset(Color, 0x01, 1000);
memset(Hires, 0x00, 8000);
mmap_set(MMAP_NO_ROM);
vic_setmode(VICM_HIRES, Color, Hires);
vic.color_border = VCOL_WHITE;
bm_init(&Screen, Hires, 40, 25);
}
void done(void)
{
mmap_set(MMAP_ROM);
// getch();
vic_setmode(VICM_TEXT, (char *)0x0400, (char *)0x1000);
}
ClipRect cr = {0, 0, 320, 200};
struct Point
{
int x, y;
};
__striped Point tcorners[8], pcorners[8];
void drawCube(void)
{
for(char i=0; i<8; i++)
{
if (!(i & 1))
bm_line(&Screen, &cr, tcorners[i].x, tcorners[i].y, tcorners[i | 1].x, tcorners[i | 1].y, 0xff, LINOP_OR);
if (!(i & 2))
bm_line(&Screen, &cr, tcorners[i].x, tcorners[i].y, tcorners[i | 2].x, tcorners[i | 2].y, 0xff, LINOP_OR);
if (!(i & 4))
bm_line(&Screen, &cr, tcorners[i].x, tcorners[i].y, tcorners[i | 4].x, tcorners[i | 4].y, 0xff, LINOP_OR);
pcorners[i] = tcorners[i];
}
}
void hideCube(void)
{
for(char i=0; i<8; i++)
{
if (!(i & 1))
bm_line(&Screen, &cr, pcorners[i].x, pcorners[i].y, pcorners[i | 1].x, pcorners[i | 1].y, 0xff, LINOP_AND);
if (!(i & 2))
bm_line(&Screen, &cr, pcorners[i].x, pcorners[i].y, pcorners[i | 2].x, pcorners[i | 2].y, 0xff, LINOP_AND);
if (!(i & 4))
bm_line(&Screen, &cr, pcorners[i].x, pcorners[i].y, pcorners[i | 4].x, pcorners[i | 4].y, 0xff, LINOP_AND);
}
}
void xorCube(void)
{
for(char i=0; i<8; i++)
{
if (!(i & 1))
bm_line(&Screen, &cr, tcorners[i].x, tcorners[i].y, tcorners[i | 1].x, tcorners[i | 1].y, 0xff, LINOP_XOR);
if (!(i & 2))
bm_line(&Screen, &cr, tcorners[i].x, tcorners[i].y, tcorners[i | 2].x, tcorners[i | 2].y, 0xff, LINOP_XOR);
if (!(i & 4))
bm_line(&Screen, &cr, tcorners[i].x, tcorners[i].y, tcorners[i | 4].x, tcorners[i | 4].y, 0xff, LINOP_XOR);
pcorners[i] = tcorners[i];
}
}
void xor2Cube(void)
{
for(char i=0; i<8; i++)
{
if (!(i & 1))
{
bm_line(&Screen, &cr, pcorners[i].x, pcorners[i].y, pcorners[i | 1].x, pcorners[i | 1].y, 0xff, LINOP_XOR);
bm_line(&Screen, &cr, tcorners[i].x, tcorners[i].y, tcorners[i | 1].x, tcorners[i | 1].y, 0xff, LINOP_XOR);
}
if (!(i & 2))
{
bm_line(&Screen, &cr, pcorners[i].x, pcorners[i].y, pcorners[i | 2].x, pcorners[i | 2].y, 0xff, LINOP_XOR);
bm_line(&Screen, &cr, tcorners[i].x, tcorners[i].y, tcorners[i | 2].x, tcorners[i | 2].y, 0xff, LINOP_XOR);
}
if (!(i & 4))
{
bm_line(&Screen, &cr, pcorners[i].x, pcorners[i].y, pcorners[i | 4].x, pcorners[i | 4].y, 0xff, LINOP_XOR);
bm_line(&Screen, &cr, tcorners[i].x, tcorners[i].y, tcorners[i | 4].x, tcorners[i | 4].y, 0xff, LINOP_XOR);
}
}
for(char i=0; i<8; i++)
pcorners[i] = tcorners[i];
}
#if 1
F12Vector3 corners[8];
F12Matrix3 rmat, tmat;
int main(void)
{
init();
for(char i=0; i<8; i++)
{
corners[i].v[0] = (i & 1) ? -FIX12_ONE : FIX12_ONE;
corners[i].v[1] = (i & 2) ? -FIX12_ONE : FIX12_ONE;
corners[i].v[2] = (i & 4) ? -FIX12_ONE : FIX12_ONE;
}
for(int k=0; k<100; k++)
{
f12mat3_set_rotate_x(&rmat, 0.1 * k);
f12mat3_set_rotate_y(&tmat, 0.06 * k);
f12mat3_mmul(&rmat, &tmat);
for(char i=0; i<8; i++)
{
F12Vector3 vd;
f12vec3_mmul(&vd, &rmat, corners + i);
tcorners[i].x = lmuldiv16s(vd.v[0], 140, vd.v[2] + 4 * FIX12_ONE) + 160;
tcorners[i].y = lmuldiv16s(vd.v[1], 140, vd.v[2] + 4 * FIX12_ONE) + 100;
}
#if 1
if (k)
xor2Cube();
else
xorCube();
#else
hideCube();
drawCube();
#endif
}
done();
return 0;
}
#else
Matrix4 wmat, pmat, tmat, rmat;
Vector3 corners[8];
int main(void)
{
init();
mat4_ident(&wmat);
mat4_make_perspective(&pmat, 0.5 * PI, 1.0, 0.0, 200.0);
mat4_scale(&wmat, 1);
for(char i=0; i<8; i++)
{
vec3_set(corners + i,
(i & 1) ? -1.0 : 1.0,
(i & 2) ? -1.0 : 1.0,
(i & 4) ? -1.0 : 1.0);
}
for(int k=0; k<100; k++)
{
mat4_set_rotate_x(&rmat, 0.1 * k);
mat4_set_rotate_y(&tmat, 0.06 * k);
mat4_rmmul(&rmat, &tmat);
mat4_rmmul(&rmat, &wmat);
rmat.m[14] += 4.0;
tmat = pmat;
mat4_mmul(&tmat, &rmat);
for(char i=0; i<8; i++)
{
Vector3 vd;
vec3_project(&vd, &rmat, corners + i);
tcorners[i].x = (int)(vd.v[0] * 100) + 160;
tcorners[i].y = (int)(vd.v[1] * 100) + 100;
}
hideCube();
drawCube();
}
done();
return 0;
}
#endif
+64
View File
@@ -0,0 +1,64 @@
#include <c64/memmap.h>
#include <c64/vic.h>
#include <gfx/bitmap.h>
#include <math.h>
#include <string.h>
#include <conio.h>
char * const Color = (char *)0xd000;
char * const Hires = (char *)0xe000;
Bitmap Screen;
ClipRect Clip = {0, 0, 320, 200};
void init(void)
{
mmap_trampoline();
mmap_set(MMAP_RAM);
memset(Color, 0x01, 1000);
memset(Hires, 0x00, 8000);
mmap_set(MMAP_NO_ROM);
vic_setmode(VICM_HIRES, Color, Hires);
vic.color_border = VCOL_WHITE;
bm_init(&Screen, Hires, 40, 25);
}
void done(void)
{
mmap_set(MMAP_ROM);
getch();
vic_setmode(VICM_TEXT, (char *)0x0400, (char *)0x1000);
}
void draw(float x, float y, float a, float s)
{
if (s < 6.0)
return;
float tx = x + cos(a) * s;
float ty = y + sin(a) * s;
bm_line(&Screen, &Clip, x, y, tx, ty, 0xff, LINOP_SET);
draw(tx, ty, a + 0.3, s * 0.9);
draw(tx, ty, a - 0.4, s * 0.8);
}
int main(void)
{
init();
draw(140, 199, PI * 1.5, 32);
done();
return 0;
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

+231
View File
@@ -0,0 +1,231 @@
#include <c64/memmap.h>
#include <c64/vic.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <math.h>
#include <gfx/vector3d.h>
#include <gfx/bitmap.h>
#include <stdio.h>
#pragma stacksize(1024)
#pragma region(main, 0x0a00, 0xc800, , , {code, data, bss, heap, stack} )
#define Color ((char *)0xc800)
#define Hires ((char *)0xe000)
Bitmap Screen = {
Hires, nullptr, 40, 25, 320
};
ClipRect SRect = {
0, 0, 320, 200
};
char chk[] = {0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55};
char white[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
char black[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
Matrix4 wmat, pmat, tmat, rmat;
Vector3 vlight;
void init(void)
{
mmap_set(MMAP_NO_BASIC);
vic_setmode(VICM_HIRES, Color, Hires);
vic.color_back = VCOL_WHITE;
vic.color_border = VCOL_WHITE;
mmap_trampoline();
mmap_set(MMAP_NO_ROM);
memset(Color, 0x01, 1000);
memset(Hires, 0, 8000);
}
void restore(void)
{
vic_setmode(VICM_TEXT, (char *)0x0400, (char *)0x1000);
mmap_set(MMAP_ROM);
}
struct Point
{
int x, y;
};
#define HALF 15
#define FULL (HALF + HALF)
#define SIZE (FULL + 1)
#define QFULL (FULL * FULL)
Vector3 v[SIZE][SIZE];
Point p[SIZE][SIZE];
float z[SIZE][SIZE];
struct Surf
{
float z;
char x, y;
} surfs[QFULL];
void qsort(Surf * n, int s)
{
if (s > 1)
{
Surf pn = n[0];
int pi = 0;
for(int i=1; i<s; i++)
{
if (n[i].z > pn.z)
{
n[pi] = n[i];
pi++;
n[i] = n[pi];
}
}
n[pi] = pn;
qsort(n, pi);
qsort(n + pi + 1, s - pi - 1);
}
}
int main(void)
{
init();
bm_put_string(&Screen, &SRect, 0, 0, "Preparing function", BLTOP_COPY);
mat4_ident(&wmat);
mat4_make_perspective(&pmat, 0.5 * PI, 1.0, 0.0, 200.0);
for(int ix=0; ix<SIZE; ix++)
{
for(int iy=0; iy<SIZE; iy++)
{
float x = (ix - HALF) * (1.0 / HALF), y = (HALF - iy) * (1.0 / HALF);
float r = sqrt(x * x + y * y);
float f = - cos(r * 16) * exp(- 2 * r);
vec3_set(&(v[iy][ix]), x, f * 0.5, y);
}
}
bm_put_string(&Screen, &SRect, 0, 8, "Projecting vertices", BLTOP_COPY);
vec3_set(&vlight, 2.0, -2.0, -1.0);
vec3_norm(&vlight);
mat4_scale(&wmat, 18);
mat4_set_rotate_x(&rmat, -0.98);
mat4_set_rotate_y(&tmat, 0.3);
mat4_rmmul(&rmat, &tmat);
mat4_rmmul(&rmat, &wmat);
rmat.m[14] += 20.0;
tmat = pmat;
mat4_mmul(&tmat, &rmat);
for(int ix=0; ix<SIZE; ix++)
{
for(int iy=0; iy<SIZE; iy++)
{
Vector3 vp;
vec3_project(&vp, &tmat, &(v[iy][ix]));
p[iy][ix].x = vp.v[0] * 140 + 160;
p[iy][ix].y = vp.v[1] * 140 + 80;
z[iy][ix] = vp.v[2];
}
}
bm_put_string(&Screen, &SRect, 0, 16, "Sorting surfaces", BLTOP_COPY);
for(int iy=0; iy<FULL; iy++)
{
for(int ix=0; ix<FULL; ix++)
{
surfs[FULL * iy + ix].z =
z[iy + 0][ix + 0] +
z[iy + 0][ix + 1] +
z[iy + 1][ix + 0] +
z[iy + 1][ix + 1];
surfs[FULL * iy + ix].x = ix;
surfs[FULL * iy + ix].y = iy;
}
}
qsort(surfs, QFULL);
bm_put_string(&Screen, &SRect, 0, 24, "Drawing surfaces", BLTOP_COPY);
for(int i=0; i< QFULL; i++)
{
char ix = surfs[i].x, iy = surfs[i].y;
Vector3 d0, d1, n;
vec3_diff(&d0, &(v[iy + 0][ix + 0]), &(v[iy + 1][ix + 1]));
vec3_diff(&d1, &(v[iy + 1][ix + 0]), &(v[iy + 0][ix + 1]));
vec3_xmul(&n, &d0, &d1);
vec3_norm(&n);
float f = vec3_vmul(&vlight, &n);
int c = 8;
char patt = 0xaa;
if (f > 0)
{
c = 8 - (int)(f * 9);
if (c < 5)
patt = 0xff;
}
bm_quad_fill(&Screen, &SRect,
p[iy + 0][ix + 0].x, p[iy + 0][ix + 0].y,
p[iy + 0][ix + 1].x, p[iy + 0][ix + 1].y,
p[iy + 1][ix + 1].x, p[iy + 1][ix + 1].y,
p[iy + 1][ix + 0].x, p[iy + 1][ix + 0].y,
NineShadesOfGrey[c]);
bm_line(&Screen, &SRect,
p[iy + 0][ix + 0].x, p[iy + 0][ix + 0].y,
p[iy + 0][ix + 1].x, p[iy + 0][ix + 1].y, patt, LINOP_SET);
bm_line(&Screen, &SRect,
p[iy + 1][ix + 0].x, p[iy + 1][ix + 0].y,
p[iy + 1][ix + 1].x, p[iy + 1][ix + 1].y, patt, LINOP_SET);
bm_line(&Screen, &SRect,
p[iy + 0][ix + 0].x, p[iy + 0][ix + 0].y,
p[iy + 1][ix + 0].x, p[iy + 1][ix + 0].y, patt, LINOP_SET);
bm_line(&Screen, &SRect,
p[iy + 0][ix + 1].x, p[iy + 0][ix + 1].y,
p[iy + 1][ix + 1].x, p[iy + 1][ix + 1].y, patt, LINOP_SET);
}
mmap_set(MMAP_NO_BASIC);
getch();
restore();
return 0;
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

+68
View File
@@ -0,0 +1,68 @@
#include <c64/memmap.h>
#include <c64/vic.h>
#include <gfx/bitmap.h>
#include <string.h>
#include <conio.h>
#define Color ((char *)0xd000)
#define Hires ((char *)0xe000)
Bitmap Screen;
void init(void)
{
mmap_trampoline();
mmap_set(MMAP_RAM);
memset(Color, 0x01, 1000);
memset(Hires, 0x00, 8000);
mmap_set(MMAP_NO_ROM);
vic_setmode(VICM_HIRES, Color, Hires);
vic.color_border = VCOL_WHITE;
bm_init(&Screen, Hires, 40, 25);
}
void done(void)
{
mmap_set(MMAP_ROM);
getch();
vic_setmode(VICM_TEXT, (char *)0x0400, (char *)0x1000);
}
void draw(ClipRect * cr, byte pattern)
{
for(int i=0; i<40; i ++)
{
bm_line(&Screen, cr, 8 * i, 0, 319, 5 * i, pattern, LINOP_SET);
bm_line(&Screen, cr, 319, 5 * i, 319 - 8 * i, 199, pattern, LINOP_SET);
bm_line(&Screen, cr, 319 - 8 * i, 199, 0, 199 - 5 * i, pattern, LINOP_SET);
bm_line(&Screen, cr, 0, 199 - 5 * i, 8 * i, 0, pattern, LINOP_SET);
}
}
int main(void)
{
init();
ClipRect cr = {0, 0, 320, 200};
draw(&cr, 0xff);
draw(&cr, 0x00);
draw(&cr, 0xff);
draw(&cr, 0xaa);
draw(&cr, 0x88);
draw(&cr, 0x80);
draw(&cr, 0x00);
done();
return 0;
}
+8
View File
@@ -0,0 +1,8 @@
call ..\..\bin\oscar64 splitscreen.c
call ..\..\bin\oscar64 func3d.c -n
call ..\..\bin\oscar64 lines.c -n
call ..\..\bin\oscar64 polygon.c -n
call ..\..\bin\oscar64 bitblit.c -n
call ..\..\bin\oscar64 cube3d.c -n
call ..\..\bin\oscar64 fractaltree.c -n
call ..\..\bin\oscar64 qsort.c -n
+11
View File
@@ -0,0 +1,11 @@
%.prg: %.c
@echo "Compiling sample file" $<
@$(OSCAR64_CC) $(OSCAR64_CFLAGS) $<
all: splitscreen.prg func3d.prg lines.prg polygon.prg bitblit.prg cube3d.prg fractaltree.prg qsort.prg
splitscreen.prg: splitscreen.c
@$(OSCAR64_CC) $<
clean:
@$(RM) *.asm *.int *.lbl *.map *.prg *.bcs
+83
View File
@@ -0,0 +1,83 @@
#include <c64/memmap.h>
#include <c64/vic.h>
#include <gfx/bitmap.h>
#include <string.h>
#include <conio.h>
#include <math.h>
#define Color ((char *)0xd000)
#define Hires ((char *)0xe000)
Bitmap Screen;
void init(void)
{
mmap_trampoline();
mmap_set(MMAP_RAM);
memset(Color, 0x10, 1000);
memset(Hires, 0x00, 8000);
mmap_set(MMAP_NO_ROM);
vic_setmode(VICM_HIRES, Color, Hires);
vic.color_border = VCOL_WHITE;
bm_init(&Screen, Hires, 40, 25);
}
void done(void)
{
mmap_set(MMAP_ROM);
getch();
vic_setmode(VICM_TEXT, (char *)0x0400, (char *)0x1000);
}
int main(void)
{
init();
bmu_rect_pattern(&Screen, 0, 0, 320, 200, NineShadesOfGrey[4]);
bmu_rect_clear(&Screen, 14, 14, 304, 184);
bmu_rect_fill(&Screen, 8, 8, 304, 184);
bmu_rect_clear(&Screen, 10, 10, 300, 180);
ClipRect cr = {11, 11, 309, 189};
float px[10], py[10];
for(int i=0; i<10; i++)
{
float w = i * PI / 5, c = cos(w), s = sin(w), r = (i & 1) ? 1.0 : 0.4;
px[i] = r * c; py[i] = r * s;
}
for(int i=0; i<128; i++)
{
int rpx[10], rpy[10];
float r = i + 4;
float w = i * PI / 16, c = r * cos(w), s = r * sin(w), cw = r * cos(w * 2.0), sw = r * sin(w * 2.0);
for(int j=0; j<10; j++)
{
float fx = px[j], fy = py[j];
rpx[j] = 160 + cw + fx * c + fy * s;
rpy[j] = 100 + sw - fx * s + fy * c;
}
bm_polygon_nc_fill(&Screen, &cr, rpx, rpy, 10, NineShadesOfGrey[i % 9]);
for(int j=0; j<10; j++)
{
int k = (j + 1) % 10;
bm_line(&Screen, &cr, rpx[j], rpy[j], rpx[k], rpy[k], 0xff, LINOP_SET);
}
}
done();
return 0;
}
+117
View File
@@ -0,0 +1,117 @@
#include <c64/memmap.h>
#include <c64/vic.h>
#include <gfx/bitmap.h>
#include <string.h>
#include <conio.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#define Color ((char *)0xd000)
#define Hires ((char *)0xe000)
Bitmap Screen;
void init(void)
{
mmap_trampoline();
mmap_set(MMAP_RAM);
memset(Color, 0x01, 1000);
memset(Hires, 0x00, 8000);
mmap_set(MMAP_NO_ROM);
vic_setmode(VICM_HIRES, Color, Hires);
vic.color_border = VCOL_WHITE;
bm_init(&Screen, Hires, 40, 25);
}
void done(void)
{
mmap_set(MMAP_ROM);
getch();
vic_setmode(VICM_TEXT, (char *)0x0400, (char *)0x1000);
}
char field[160];
void fill(void)
{
for(int i=0; i<160; i++)
field[i] = i;
}
void shuffle(void)
{
for(int i=0; i<160; i++)
{
int j = rand() % 160;
char t = field[i];
field[i] = field[j];
field[j] = t;
}
}
void draw(unsigned i)
{
bmu_line(&Screen, 2 * i, 0, 2 * i, field[i], 0x00, LINOP_SET);
bmu_line(&Screen, 2 * i, field[i], 2 * i, 160, 0xff, LINOP_SET);
}
void partition(int l, int r)
{
while (l < r)
{
int i = l;
int j = r;
char pi = field[(r + l) >> 1];
while (i <= j)
{
while (field[i] > pi)
i++;
while (field[j] < pi)
j--;
if (i <= j)
{
char t = field[i];
field[i] = field[j];
field[j] = t;
draw(i);
draw(j);
i++;
j--;
}
}
partition(l, j);
l = i;
}
}
int main(void)
{
init();
fill();
shuffle();
for(int i=0; i<160; i++)
draw(i);
clock_t t0 = clock();
partition(0, 159);
clock_t t1 = clock();
char t[20];
sprintf(t, "TIME : %.1f SECS.", (float)(t1 - t0) / 60);
bmu_put_chars(&Screen, 4, 170, t, strlen(t), BLTOP_COPY);
done();
return 0;
}
+101
View File
@@ -0,0 +1,101 @@
#include <c64/vic.h>
#include <gfx/bitmap.h>
#include <c64/rasterirq.h>
#include <c64/memmap.h>
#include <string.h>
#include <stdio.h>
#include <c64/charwin.h>
#define Color ((char *)0xc800)
#define Hires ((char *)0xe000)
char white[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
char check[] = {0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa};
char black[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
Bitmap Screen;
RIRQCode rirqtop, rirqbottom;
#pragma align(rirqtop, 32)
#pragma align(rirqbottom, 32)
CharWin twin;
CharWin ewin;
int main(void)
{
mmap_trampoline();
mmap_set(MMAP_CHAR_ROM);
memcpy((char *)0xd000, (char *)0xd000, 4096);
mmap_set(MMAP_NO_ROM);
rirq_init(true);
vic.color_back = VCOL_BLACK;
memset(Color, 0x10, 1000);
memset(Hires, 0, 8000);
vic_setmode(VICM_HIRES, Color, Hires);
rirq_build(&rirqtop, 2);
rirq_write(&rirqtop, 0, &vic.memptr, 0x28);
rirq_write(&rirqtop, 1, &vic.ctrl1, VIC_CTRL1_BMM | VIC_CTRL1_DEN | VIC_CTRL1_RSEL | 3);
rirq_build(&rirqbottom, 3);
rirq_delay(&rirqbottom, 10);
rirq_write(&rirqbottom, 1, &vic.ctrl1, VIC_CTRL1_DEN | VIC_CTRL1_RSEL | 3);
rirq_write(&rirqbottom, 2, &vic.memptr, 0x26);
rirq_set(0, 10, &rirqtop);
rirq_set(1, 49 + 8 * 20, &rirqbottom);
rirq_sort();
rirq_start();
bm_init(&Screen, Hires, 40, 25);
bmu_rect_pattern(&Screen, 0, 0, 320, 160, check);
bmu_rect_fill(&Screen, 0, 159, 320, 1);
bmu_rect_clear(&Screen, 0, 158, 320, 1);
cwin_init(&twin, Color, 0, 20, 40, 4);
cwin_init(&ewin, Color, 0, 24, 40, 1);
ClipRect rect = {0, 0, 320, 158};
cwin_clear(&twin);
cwin_putat_string(&twin, 0, 0, p"Enter x, y and radius for circle", 0x07);
for(;;)
{
cwin_clear(&ewin);
cwin_cursor_move(&ewin, 0, 0);
mmap_set(MMAP_NO_BASIC);
cwin_edit(&ewin);
mmap_set(MMAP_RAM);
char str[40];
cwin_read_string(&ewin, str);
int n, x, y, r;
n = sscanf(str, "%d %d %d", &x, &y, &r);
cwin_putat_string(&twin, 0, 1, str, 0x0e);
sprintf(str, p"N: %d X: %3d Y: %3d R: %2d", n, x, y, r);
cwin_putat_string(&twin, 0, 2, str, 0x07);
if (n == 3)
{
bm_circle_fill(&Screen, &rect, x, y, r + 1, black);
bm_circle_fill(&Screen, &rect, x, y, r - 1, white);
}
}
return 0;
}