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
+5
View File
@@ -0,0 +1,5 @@
#!/bin/sh
../../bin/oscar64 func3d.c -n
../../bin/oscar64 polygon.c -n
../../bin/oscar64 floodfill.c -n
../../bin/oscar64 paint.c -n
+55
View File
@@ -0,0 +1,55 @@
#include <c64/vic.h>
#include <c64/memmap.h>
#include <gfx/mcbitmap.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <math.h>
#pragma region(main, 0x0a00, 0xc800, , , {code, data, bss, heap, stack} )
#define Color1 ((char *)0xc800)
#define Color2 ((char *)0xd800)
#define Hires ((char *)0xe000)
Bitmap sbm;
int main(void)
{
mmap_trampoline();
vic_setmode(VICM_HIRES_MC, Color1, Hires);
mmap_set(MMAP_NO_ROM);
vic.color_back = VCOL_BLACK;
vic.color_border = VCOL_BLACK;
memset(Color1, 0x67, 1000);
memset(Color2, 0x02, 1000);
memset(Hires, 0, 8000);
bm_init(&sbm, Hires, 40, 25);
ClipRect scr = { 0, 0, 320, 200 };
for(;;)
{
for(int i=0; i<20; i++)
{
bmmc_circle_fill(&sbm, &scr, rand() % 320, rand() % 200, 5 + rand() % 40, MixedColors[1][1]);
}
for(int i=0; i<20; i++)
{
bmmc_circle_fill(&sbm, &scr, rand() % 320, rand() % 200, 5 + rand() % 40, MixedColors[0][0]);
}
bmmc_flood_fill(&sbm, &scr, 210, 100, 2);
bmmc_flood_fill(&sbm, &scr, 60, 140, 3);
}
mmap_set(MMAP_ROM);
getch();
return 0;
}
+228
View File
@@ -0,0 +1,228 @@
#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/mcbitmap.h>
#include <stdio.h>
#pragma region(main, 0x0a00, 0xc800, , , {code, data, bss, heap, stack} )
#define Color1 ((char *)0xc800)
#define Color2 ((char *)0xd800)
#define Hires ((char *)0xe000)
Bitmap Screen = {
Hires, nullptr, 40, 25, 320
};
ClipRect SRect = {
0, 0, 320, 200
};
Matrix4 wmat, pmat, tmat, rmat;
Vector3 vlight;
void init(void)
{
mmap_set(MMAP_NO_BASIC);
vic_setmode(VICM_HIRES_MC, Color1, Hires);
vic.color_back = VCOL_DARK_GREY;
vic.color_border = VCOL_DARK_GREY;
mmap_trampoline();
mmap_set(MMAP_NO_ROM);
memset(Color1, 0xcf, 1000);
memset(Color2, 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 = 0;
char patt = 3;
if (f > 0)
{
c = 1 + (int)(f * 6);
if (c > 4)
patt = 0;
}
bmmc_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,
MixedColors[c >> 1][(c + 1) >> 1]);
#if 0
bmmc_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);
bmmc_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);
bmmc_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);
bmmc_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);
#endif
}
mmap_set(MMAP_NO_BASIC);
getch();
restore();
return 0;
}
+4
View File
@@ -0,0 +1,4 @@
call ..\..\bin\oscar64 floodfill.c -n
call ..\..\bin\oscar64 polygon.c -n
call ..\..\bin\oscar64 func3d.c -n
call ..\..\bin\oscar64 paint.c -n
+8
View File
@@ -0,0 +1,8 @@
%.prg: %.c
@echo "Compiling sample file" $<
@$(OSCAR64_CC) $(OSCAR64_CFLAGS) $<
all: func3d.prg polygon.prg floodfill.prg paint.prg
clean:
@$(RM) *.asm *.int *.lbl *.map *.prg
+181
View File
@@ -0,0 +1,181 @@
#include <c64/vic.h>
#include <c64/memmap.h>
#include <gfx/mcbitmap.h>
#include <c64/mouse.h>
#include <c64/joystick.h>
#include <c64/keyboard.h>
#include <c64/cia.h>
#include <c64/sprites.h>
#include <string.h>
#include <oscar.h>
#pragma region(main, 0x0880, 0xd000, , , {code, data, bss, heap, stack} )
static char * const Color1 = (char *)0xd000;
static char * const Color2 = (char *)0xd800;
static char * const Hires = (char *)0xe000;
static char * const Sprites = (char *)0xd800;
const char MouseSpriteData[] = {
#embed spd_sprites lzo "../resources/mouse.spd"
};
Bitmap sbm;
ClipRect scr = { 0, 0, 320, 200 };
void init(void)
{
// Install IRQ trampoline
mmap_trampoline();
cia_init();
// All RAM
mmap_set(MMAP_RAM);
// Init hires mem, and resources
memset(Color1, 0x67, 1000);
memset(Hires, 0, 8000);
oscar_expand_lzo(Sprites, MouseSpriteData);
// Sprite image for cursor
Color1[0x3f8] = 97;
Color1[0x3f9] = 96;
// Enable IO space
mmap_set(MMAP_NO_ROM);
// Clear color RAM
memset(Color2, 0x02, 1000);
// Set screen
vic.color_back = VCOL_BLACK;
vic.color_border = VCOL_BLACK;
vic_setmode(VICM_HIRES_MC, Color1, Hires);
// Init mouse cursor
spr_show(0, true);
spr_show(1, true);
spr_color(0, VCOL_BLACK);
spr_color(1, VCOL_WHITE);
spr_move(0, 24, 50);
spr_move(1, 24, 50);
// Disable system interrupt and init mouse
mouse_init();
bm_init(&sbm, Hires, 40, 25);
}
int mouse_x, mouse_y;
bool mouse_move(void)
{
// Poll mouse and joystick for backup
joy_poll(0);
mouse_poll();
// New mouse cursor position
int mx = mouse_x + (signed char)(joyx[0] + mouse_dx);
int my = mouse_y + (signed char)(joyy[0] - mouse_dy);
// Clip to screen
if (mx < 0)
mx = 0;
else if (mx > 319)
mx = 319;
if (my < 0)
my = 0;
else if (my > 199)
my = 199;
// Check if moved
if (mx != mouse_x || my != mouse_y)
{
mouse_x = mx;
mouse_y = my;
// Update cursor sprite
spr_move(0, mx + 24, my + 50);
spr_move(1, mx + 24, my + 50);
return true;
}
return false;
}
int main(void)
{
init();
char c0 = 1, c1 = 1;
for(;;)
{
// Check if mouse moved
if (mouse_move())
{
// Paint a circle at the mouse position, if mouse was moved
if (mouse_lb || joyb[0])
bmmc_circle_fill(&sbm, &scr, mouse_x, mouse_y, 5, MixedColors[c0][c1]);
else if (mouse_rb)
bmmc_circle_fill(&sbm, &scr, mouse_x, mouse_y, 5, MixedColors[0][0]);
}
// Poll the keyboard
keyb_poll();
switch (keyb_key)
{
// Clear screen
case KSCAN_HOME + KSCAN_QUAL_DOWN:
bmmcu_rect_fill(&sbm, 0, 0, 320, 200, 0);
break;
// Select color with 0..9
case KSCAN_0 + KSCAN_QUAL_DOWN:
c0 = 0; c1 = 0;
break;
case KSCAN_1 + KSCAN_QUAL_DOWN:
c0 = 1; c1 = 1;
break;
case KSCAN_2 + KSCAN_QUAL_DOWN:
c0 = 2; c1 = 2;
break;
case KSCAN_3 + KSCAN_QUAL_DOWN:
c0 = 3; c1 = 3;
break;
case KSCAN_4 + KSCAN_QUAL_DOWN:
c0 = 1; c1 = 0;
break;
case KSCAN_5 + KSCAN_QUAL_DOWN:
c0 = 1; c1 = 2;
break;
case KSCAN_6 + KSCAN_QUAL_DOWN:
c0 = 1; c1 = 3;
break;
case KSCAN_7 + KSCAN_QUAL_DOWN:
c0 = 2; c1 = 0;
break;
case KSCAN_8 + KSCAN_QUAL_DOWN:
c0 = 2; c1 = 3;
break;
case KSCAN_9 + KSCAN_QUAL_DOWN:
c0 = 3; c1 = 0;
break;
// Flood fill
case KSCAN_F + KSCAN_QUAL_DOWN:
bmmc_flood_fill(&sbm, &scr, mouse_x, mouse_y, c0);
break;
}
// Wait one frame
vic_waitFrame();
}
return 0;
}
+86
View File
@@ -0,0 +1,86 @@
#include <c64/memmap.h>
#include <c64/vic.h>
#include <gfx/mcbitmap.h>
#include <string.h>
#include <conio.h>
#include <math.h>
#define Color1 ((char *)0xc800)
#define Color2 ((char *)0xd800)
#define Hires ((char *)0xe000)
Bitmap Screen;
void init(void)
{
mmap_trampoline();
mmap_set(MMAP_RAM);
memset(Color1, 0x67, 1000);
memset(Color2, 0x02, 1000);
memset(Hires, 0x00, 8000);
mmap_set(MMAP_NO_ROM);
vic_setmode(VICM_HIRES_MC, Color1, Hires);
vic.color_back = VCOL_BLACK;
vic.color_border = VCOL_BLACK;
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();
bmmcu_rect_fill(&Screen, 0, 0, 320, 200, 1);
bmmcu_rect_fill(&Screen, 8, 8, 304, 184, 2);
bmmcu_rect_fill(&Screen, 10, 10, 300, 180, 0);
ClipRect cr = {10, 10, 310, 190};
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;
}
bmmc_polygon_nc_fill(&Screen, &cr, rpx, rpy, 10, MixedColors[i & 3][(i >> 2) & 3]);
for(int j=0; j<10; j++)
{
int k = (j + 1) % 10;
bmmc_line(&Screen, &cr, rpx[j], rpy[j], rpx[k], rpy[k], 0);
}
}
done();
return 0;
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB