From 115f9f3afa1c56d8418971b6071ff54bfd1fb380 Mon Sep 17 00:00:00 2001 From: francescosblendorio Date: Wed, 22 Dec 2021 15:11:55 +0100 Subject: [PATCH] Add circle --- demos/graphs/graphs.c | 16 +++++++++ demos/graphs/m.bat | 1 + demos/graphs/m.sh | 2 ++ kickc/apple1.tgt | 2 +- kickc/apple1_jukebox.tgt | 2 +- kickc/vic20_8k.tgt | 4 +-- lib/apple1.h | 5 +++ lib/font8x8.h | 3 ++ lib/interrupt.h | 4 +++ lib/screen1.h | 5 +++ lib/screen2.h | 72 ++++++++++++++++++++++++++++++---------- lib/sprites.h | 3 ++ lib/tms9918.h | 3 ++ lib/utils.h | 5 +++ 14 files changed, 106 insertions(+), 21 deletions(-) create mode 100644 demos/graphs/graphs.c create mode 100644 demos/graphs/m.bat create mode 100755 demos/graphs/m.sh diff --git a/demos/graphs/graphs.c b/demos/graphs/graphs.c new file mode 100644 index 0000000..aa35b78 --- /dev/null +++ b/demos/graphs/graphs.c @@ -0,0 +1,16 @@ +#include +#include + +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); +} diff --git a/demos/graphs/m.bat b/demos/graphs/m.bat new file mode 100644 index 0000000..4c358d1 --- /dev/null +++ b/demos/graphs/m.bat @@ -0,0 +1 @@ +@call ..\..\tools\build graphs diff --git a/demos/graphs/m.sh b/demos/graphs/m.sh new file mode 100755 index 0000000..1814511 --- /dev/null +++ b/demos/graphs/m.sh @@ -0,0 +1,2 @@ +#!/bin/sh +../../tools/build.sh graphs diff --git a/kickc/apple1.tgt b/kickc/apple1.tgt index 5604e4f..4187e01 100644 --- a/kickc/apple1.tgt +++ b/kickc/apple1.tgt @@ -4,7 +4,7 @@ "start_address": "0x280", "cpu": "MOS6502X", "interrupt": "hardware_all", - "emulator": "x64sc", + "emulator": "echo", "defines": { "__APPLE1__": 1, "APPLE1": 1, diff --git a/kickc/apple1_jukebox.tgt b/kickc/apple1_jukebox.tgt index b2a99db..36cec4c 100644 --- a/kickc/apple1_jukebox.tgt +++ b/kickc/apple1_jukebox.tgt @@ -4,7 +4,7 @@ "start_address": "0x4000", "cpu": "MOS6502X", "interrupt": "hardware_all", - "emulator": "x64sc", + "emulator": "echo", "defines": { "__APPLE1__": 1, "APPLE1": 1, diff --git a/kickc/vic20_8k.tgt b/kickc/vic20_8k.tgt index ba110dd..5b12787 100644 --- a/kickc/vic20_8k.tgt +++ b/kickc/vic20_8k.tgt @@ -5,10 +5,10 @@ "start_address": "0x120d", "cpu": "MOS6502X", "interrupt": "rom_min_vic20", - "emulator": "xvic", + "emulator": "echo", "defines": { "__VIC20__": 1, "VIC20": 1, "__KICKC__": 1 } -} \ No newline at end of file +} diff --git a/lib/apple1.h b/lib/apple1.h index fb298cd..b040b8e 100644 --- a/lib/apple1.h +++ b/lib/apple1.h @@ -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 \ No newline at end of file diff --git a/lib/font8x8.h b/lib/font8x8.h index f2f47c2..ba970de 100644 --- a/lib/font8x8.h +++ b/lib/font8x8.h @@ -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 diff --git a/lib/interrupt.h b/lib/interrupt.h index f6e9fed..92f5e1b 100644 --- a/lib/interrupt.h +++ b/lib/interrupt.h @@ -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 " // 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 diff --git a/lib/screen1.h b/lib/screen1.h index 34094ea..26d933a 100644 --- a/lib/screen1.h +++ b/lib/screen1.h @@ -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 diff --git a/lib/screen2.h b/lib/screen2.h index aa2a083..4f5e82d 100644 --- a/lib/screen2.h +++ b/lib/screen2.h @@ -1,3 +1,9 @@ +#ifndef SCREEN2_H +#define SCREEN2_H + +#include +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) { 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 diff --git a/lib/sprites.h b/lib/sprites.h index 4078b1e..65374cf 100644 --- a/lib/sprites.h +++ b/lib/sprites.h @@ -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 diff --git a/lib/tms9918.h b/lib/tms9918.h index c4c7e54..b99321d 100644 --- a/lib/tms9918.h +++ b/lib/tms9918.h @@ -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 diff --git a/lib/utils.h b/lib/utils.h index 3d25a54..fcc831f 100644 --- a/lib/utils.h +++ b/lib/utils.h @@ -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