Add circle

This commit is contained in:
francescosblendorio 2021-12-22 15:11:55 +01:00
parent 03ad7c0ae4
commit 115f9f3afa
14 changed files with 106 additions and 21 deletions

16
demos/graphs/graphs.c Normal file
View File

@ -0,0 +1,16 @@
#include <tms9918.h>
#include <fastmultiply.h>
void main(void) {
mulf_init();
tms_init_regs(SCREEN2_TABLE);
byte text_color = FG_BG(COLOR_WHITE,COLOR_BLACK);
tms_set_color(COLOR_BLACK);
screen2_init_bitmap(text_color);
//screen2_puts("*** P-LAB VIDEO CARD SYSTEM ***", 0, 0, text_color);
screen2_plot_mode = PLOT_MODE_SET;
screen2_line(0, 0, (unsigned char) mulf8u(50,3), 50);
// TODO: THIS DOES NOT WORK screen2_ellipse_rect(10, 10, 150, 100);
screen2_circle(128,76,30);
}

1
demos/graphs/m.bat Normal file
View File

@ -0,0 +1 @@
@call ..\..\tools\build graphs

2
demos/graphs/m.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
../../tools/build.sh graphs

View File

@ -4,7 +4,7 @@
"start_address": "0x280",
"cpu": "MOS6502X",
"interrupt": "hardware_all",
"emulator": "x64sc",
"emulator": "echo",
"defines": {
"__APPLE1__": 1,
"APPLE1": 1,

View File

@ -4,7 +4,7 @@
"start_address": "0x4000",
"cpu": "MOS6502X",
"interrupt": "hardware_all",
"emulator": "x64sc",
"emulator": "echo",
"defines": {
"__APPLE1__": 1,
"APPLE1": 1,

View File

@ -5,10 +5,10 @@
"start_address": "0x120d",
"cpu": "MOS6502X",
"interrupt": "rom_min_vic20",
"emulator": "xvic",
"emulator": "echo",
"defines": {
"__VIC20__": 1,
"VIC20": 1,
"__KICKC__": 1
}
}
}

View File

@ -1,3 +1,6 @@
#ifndef APPLE1_H
#define APPLE1_H
#ifdef APPLE1
// APPLE1
const word WOZMON = 0xFF1F; // enters monitor
@ -119,3 +122,5 @@ inline void apple1_eprom_init() {
memcpy(LOWRAM_START, DATAINCODE, LOWRAM_SIZE);
}
#endif
#endif

View File

@ -1,3 +1,5 @@
#ifndef FONT8X8_H
#define FONT8X8_H
// font from LASER-500 (ASCII characters only)
#pragma data_seg(Code)
@ -860,3 +862,4 @@ byte FONT[768] = {
};
#pragma data_seg(Data)
#endif

View File

@ -1,3 +1,6 @@
#ifndef INTERRUPT_H
#define INTERRUPT_H
// reserve locations 0,1,2 used by the APPLE1 IRQ jump vector
// these will contain a three byte instruction "JUMP <interrupt_handler>"
// in order to make the interrupt routine not reside in zero page
@ -50,3 +53,4 @@ void wait_interrupt() {
// while(_irq_trigger == 0); // waits until it's set to 1 from the interrupt handler
}
#endif

View File

@ -1,3 +1,6 @@
#ifndef SCREEN1_H
#define SCREEN1_H
byte SCREEN1_TABLE[8] = { 0x00, 0xc0, 0x0e, 0x80, 0x00, 0x76, 0x03, 0x25 };
const word SCREEN1_SIZE = (32*24);
@ -179,3 +182,5 @@ void screen1_strinput(byte *buffer, byte max_length) {
}
}
}
#endif

View File

@ -1,3 +1,9 @@
#ifndef SCREEN2_H
#define SCREEN2_H
#include <fastmultiply.h>
byte tms_global_mulf_initialized = 0;
byte SCREEN2_TABLE[8] = { 0x02, 0xc0, 0x0e, 0xff, 0x03, 0x76, 0x03, 0x25 };
const word SCREEN2_SIZE = (32*24);
@ -71,7 +77,7 @@ void screen2_plot(byte x, byte y) {
}
signed int vti_abs(signed int x) {
signed int math_abs(signed int x) {
return x < 0 ? -x : x;
}
@ -83,8 +89,8 @@ void screen2_line(byte _x0, byte _y0, byte _x1, byte _y1) {
signed int y0 = (signed int) _y0;
signed int y1 = (signed int) _y1;
signed int dx = vti_abs(x1-x0);
signed int dy = -vti_abs(y1-y0);
signed int dx = math_abs(x1-x0);
signed int dy = -math_abs(y1-y0);
signed int err = dx+dy; /* error value e_xy */
bool ix = x0<x1;
@ -100,34 +106,43 @@ void screen2_line(byte _x0, byte _y0, byte _x1, byte _y1) {
}
}
/*
// http://members.chello.at/~easyfilter/bresenham.html
void vti_ellipse_rect(byte _x0, byte _y0, byte _x1, byte _y1)
/* TODO: FIX THIS, IT DOES NOT DRAW AN ELLIPSE
void screen2_ellipse_rect(byte _x0, byte _y0, byte _x1, byte _y1)
{
if (tms_global_mulf_initialized == 0) {
mulf_init();
tms_global_mulf_initialized = 1;
}
//unsigned int x0,y0,x1,y1;
signed int x0 = (signed int) _x0;
signed int y0 = (signed int) _y0;
signed int x1 = (signed int) _x1;
signed int y1 = (signed int) _y1;
signed int a = vti_abs(x1-x0), b = vti_abs(y1-y0);
signed int a = math_abs(x1-x0), b = math_abs(y1-y0);
signed int b1 = b&1; // values of diameter
signed int dx = 4*(1-a)*b*b, dy = 4*(b1+1)*a*a; // error increment
signed int err = dx+dy+b1*a*a, e2; // error of 1.step
long dx = mulf16s(1-a, (signed int) mulf16s(b,b))*4;
long dy = mulf16s(b1+1,(signed int) mulf16s(a,a))*4; // error increment
long err = dx+dy+(signed int) mulf16s((signed int) b1, (signed int) mulf16s(a,a));
long e2; // error of 1.step
if (x0 > x1) { x0 = x1; x1 += a; } // if called with swapped points
if (y0 > y1) y0 = y1; // .. exchange them
y0 += (b+1)/2; y1 = y0-b1; // starting pixel
a *= 8*a; b1 = 8*b*b;
y0 += (b+1)/2;
y1 = y0 - b1; // starting pixel
a = ((signed int) mulf16s(a,a))*8; b1 = ((signed int) mulf16s(b,b))*8;
do {
screen2_plot((byte) x1, (byte) y0); // I. Quadrant
screen2_plot((byte) x0, (byte) y0); // II. Quadrant
screen2_plot((byte) x0, (byte) y1); // III. Quadrant
screen2_plot((byte) x1, (byte) y1); // IV. Quadrant
e2 = 2*err;
if (e2 <= dy) { y0++; y1--; err += dy += a; } // y step
if (e2 >= dx || 2*err > dy) { x0++; x1--; err += dx += b1; } // x step
screen2_plot((byte) x1, (byte) y0); // I. Quadrant
screen2_plot((byte) x0, (byte) y0); // II. Quadrant
screen2_plot((byte) x0, (byte) y1); // III. Quadrant
screen2_plot((byte) x1, (byte) y1); // IV. Quadrant
e2 = err*2;
if ((signed int) e2 <= (signed int) dy) { y0++; y1--; err += dy += a; } // y step
if ((signed int) e2 >= (signed int) dx || (signed int) e2 > (signed int) dy) { x0++; x1--; err += dx += b1; } // x step
} while (x0 <= x1);
while (y0-y1 < b) { // too early stop of flat ellipses a=1
@ -136,6 +151,29 @@ void vti_ellipse_rect(byte _x0, byte _y0, byte _x1, byte _y1)
screen2_plot((byte) x0-1, (byte) (y1));
screen2_plot((byte) x1+1, (byte) (y1--));
}
}
*/
// http://members.chello.at/~easyfilter/bresenham.html
void screen2_circle(byte _xm, byte _ym, byte _r) {
signed int xm = (signed int) _xm;
signed int ym = (signed int) _ym;
signed int r = (signed int) _r;
int x = -r, y = 0, err = 2-2*r; /* II. Quadrant */
do {
screen2_plot((byte) (xm-x), (byte) (ym+y)); /* I. Quadrant */
screen2_plot((byte) (xm-y), (byte) (ym-x)); /* II. Quadrant */
screen2_plot((byte) (xm+x), (byte) (ym-y)); /* III. Quadrant */
screen2_plot((byte) (xm+y), (byte) (ym+x)); /* IV. Quadrant */
r = err;
if (r <= y) err += ++y*2+1; /* e_xy+e_y < 0 */
if (r > x || err > y) err += ++x*2+1; /* e_xy+e_x > 0 or no 2nd y-step */
} while (x < 0);
}
#endif

View File

@ -1,3 +1,5 @@
#ifndef SPRITES_H
#define SPRITES_H
// clears all the sprites
void tms_clear_sprites() {
// fills first sprite pattern with 0
@ -15,3 +17,4 @@ void tms_clear_sprites() {
TMS_WRITE_DATA_PORT(i); NOP; NOP; NOP; NOP; // color
}
}
#endif

View File

@ -1,3 +1,5 @@
#ifndef TMS9918_H
#define TMS9918_H
// TODO a bitmapped text writing routine (double size ecc)
// TODO console like text output in screen 2
// TODO more fonts (C64 and PET/VIC20)
@ -168,3 +170,4 @@ inline void tms_wait_end_of_frame() {
#include "screen1.h"
#include "screen2.h"
#include "interrupt.h"
#endif

View File

@ -1,3 +1,6 @@
#ifndef UTILS_H
#define UTILS_H
#define POKE(a,b) (*((byte *)(a))=(byte)(b))
#define PEEK(a) (*((byte *)(a)))
@ -12,3 +15,5 @@
typedef unsigned char byte;
typedef unsigned int word;
#endif
#endif