Refactoring library files to remove dependency on include.h.

This commit is contained in:
Wayne Venables
2023-02-25 20:18:58 -08:00
parent 73a91f3508
commit 341fb86b22
34 changed files with 200 additions and 398 deletions

View File

@@ -1,65 +0,0 @@
# make clean ... clean
# make all ... compile
##############################################################################
# Input files
# ASM source files
ASRC +=
# C source files
CSRC +=
# C++ source files
SRC += src/main.cpp
##############################################################################
# Configuration
# defines
DEFINE += -DCFG_TUSB_DEBUG=0
DEFINE += -DCFG_TUSB_MCU=OPT_MCU_RP2040
DEFINE += -DCFG_TUSB_OS=OPT_OS_PICO
DEFINE += -DPICO_BIT_OPS_PICO=1
DEFINE += -DPICO_BOARD=\"pico\"
DEFINE += -DPICO_BUILD=1
DEFINE += -DPICO_CMAKE_BUILD_TYPE=\"Release\"
DEFINE += -DPICO_COPY_TO_RAM=0
DEFINE += -DPICO_CXX_ENABLE_EXCEPTIONS=0
DEFINE += -DPICO_DIVIDER_HARDWARE=1
DEFINE += -DPICO_DOUBLE_PICO=1
DEFINE += -DPICO_FLOAT_PICO=1
DEFINE += -DPICO_INT64_OPS_PICO=1
DEFINE += -DPICO_MEM_OPS_PICO=1
DEFINE += -DPICO_NO_FLASH=0
DEFINE += -DPICO_NO_HARDWARE=0
DEFINE += -DPICO_ON_DEVICE=1
DEFINE += -DPICO_PRINTF_PICO=1
DEFINE += -DPICO_PROGRAM_URL=\"https://github.com/raspberrypi/pico-examples\"
DEFINE += -DPICO_TARGET_NAME=\"pico\"
DEFINE += -DPICO_USE_BLOCKED_RAM=0
DEFINE += -DNDEBUG
# stdio output (select one option)
#DEFINE += -DPICO_STDIO_UART=1
#DEFINE += -DPICO_STDIO_SEMIHOSTING=1
#DEFINE += -DPICO_STDIO_USB=1
# How to connect UART to Pico:
# +---USB---+
# <-- UART0_TX GP0 |.1 40.|VBUS --- +5V power output to USB device
# --> UART0_RX GP1 |.2 39.|VSYS ---|<|--- +5V power input
# --- GND |.3 38.| GND K diode A
# GP2 |.4 37.| 3V3_EN
# GP3 |.5 36.| 3V3_OUT
# ......
#
# USB/UART adaptor PL2303TA:
# red ......... +5V VSYS (39)
# black ....... GND (3)
# white RxD ... UART0_TX GP0 (1)
# green TxD ... UART0_RX GP1 (2)
# Setup: 115200 Baud
include ../Makefile.inc

View File

@@ -1,15 +0,0 @@
// ****************************************************************************
//
// Common definitions
//
// ****************************************************************************
// ----------------------------------------------------------------------------
// Includes
// ----------------------------------------------------------------------------
#include "../../../global.h" // global common definitions
// main
#include "main.h" // main code

View File

@@ -5,7 +5,8 @@
//
// ****************************************************************************
#include "include.h"
#include "picovga.h"
// Draw box
ALIGNED u8 Box[512*400];

View File

@@ -1,11 +0,0 @@
// ****************************************************************************
//
// Main code
//
// ****************************************************************************
#ifndef _MAIN_H
#define _MAIN_H
#endif // _MAIN_H

281
global.h
View File

@@ -1,281 +0,0 @@
// ****************************************************************************
//
// Global common definitions
//
// ****************************************************************************
// ----------------------------------------------------------------------------
// Base data types
// ----------------------------------------------------------------------------
typedef signed char s8;
typedef unsigned char u8;
typedef signed short s16;
typedef unsigned short u16;
typedef signed long int s32;
typedef unsigned long int u32;
typedef signed long long int s64;
typedef unsigned long long int u64;
typedef unsigned int uint;
typedef unsigned char Bool;
#define True 1
#define False 0
// NULL
#ifndef NULL
#ifdef __cplusplus
#define NULL 0
#else
#define NULL ((void*)0)
#endif
#endif
// I/O port prefix
#define __IO volatile
// request to use inline
#define INLINE __attribute__((always_inline)) inline
// avoid to use inline
#define NOINLINE __attribute__((noinline))
// weak function
#define WEAK __attribute__((weak))
// align array to 4-bytes
#define ALIGNED __attribute__((aligned(4)))
#define LED_PIN 25
// ----------------------------------------------------------------------------
// Constants
// ----------------------------------------------------------------------------
#define B0 (1<<0)
#define B1 (1<<1)
#define B2 (1<<2)
#define B3 (1<<3)
#define B4 (1<<4)
#define B5 (1<<5)
#define B6 (1<<6)
#define B7 (1<<7)
#define B8 (1U<<8)
#define B9 (1U<<9)
#define B10 (1U<<10)
#define B11 (1U<<11)
#define B12 (1U<<12)
#define B13 (1U<<13)
#define B14 (1U<<14)
#define B15 (1U<<15)
#define B16 (1UL<<16)
#define B17 (1UL<<17)
#define B18 (1UL<<18)
#define B19 (1UL<<19)
#define B20 (1UL<<20)
#define B21 (1UL<<21)
#define B22 (1UL<<22)
#define B23 (1UL<<23)
#define B24 (1UL<<24)
#define B25 (1UL<<25)
#define B26 (1UL<<26)
#define B27 (1UL<<27)
#define B28 (1UL<<28)
#define B29 (1UL<<29)
#define B30 (1UL<<30)
#define B31 (1UL<<31)
#define BIT(pos) (1UL<<(pos))
#define BIGINT 0x40000000 // big int value
#define _T(a) a
#define PI 3.14159265358979324
#define PI2 (3.14159265358979324*2)
// ----------------------------------------------------------------------------
// Includes
// ----------------------------------------------------------------------------
// fonts
extern const ALIGNED u8 FontBold8x8[2048];
extern const ALIGNED u8 FontBold8x14[3584];
extern const ALIGNED u8 FontBold8x16[4096];
extern const ALIGNED u8 FontBoldB8x14[3584];
extern const ALIGNED u8 FontBoldB8x16[4096];
extern const ALIGNED u8 FontGame8x8[2048];
extern const ALIGNED u8 FontIbm8x8[2048];
extern const ALIGNED u8 FontIbm8x14[3584];
extern const ALIGNED u8 FontIbm8x16[4096];
extern const ALIGNED u8 FontIbmTiny8x8[2048];
extern const ALIGNED u8 FontItalic8x8[2048];
extern const ALIGNED u8 FontThin8x8[2048];
// system includes
#include <string.h>
// SDK includes
#include "boards/pico.h"
#include "hardware/regs/addressmap.h"
#include "hardware/regs/adc.h"
#include "hardware/regs/busctrl.h"
#include "hardware/regs/clocks.h"
#include "hardware/regs/dma.h"
#include "hardware/regs/dreq.h"
#include "hardware/regs/i2c.h"
#include "hardware/regs/intctrl.h"
#include "hardware/regs/io_bank0.h"
#include "hardware/regs/io_qspi.h"
#include "hardware/regs/m0plus.h"
#include "hardware/regs/pads_bank0.h"
#include "hardware/regs/pads_qspi.h"
#include "hardware/regs/pio.h"
#include "hardware/regs/pll.h"
#include "hardware/regs/psm.h"
#include "hardware/regs/pwm.h"
#include "hardware/regs/resets.h"
#include "hardware/regs/rosc.h"
#include "hardware/regs/rtc.h"
#include "hardware/regs/sio.h"
#include "hardware/regs/spi.h"
#include "hardware/regs/ssi.h"
#include "hardware/regs/syscfg.h"
#include "hardware/regs/sysinfo.h"
#include "hardware/regs/tbman.h"
#include "hardware/regs/timer.h"
#include "hardware/regs/uart.h"
#include "hardware/regs/usb.h"
#include "hardware/regs/vreg_and_chip_reset.h"
#include "hardware/regs/watchdog.h"
#include "hardware/regs/xip.h"
#include "hardware/regs/xosc.h"
#include "hardware/structs/adc.h"
#include "hardware/structs/bus_ctrl.h"
#include "hardware/structs/clocks.h"
#include "hardware/structs/dma.h"
#include "hardware/structs/i2c.h"
#include "hardware/structs/interp.h"
#include "hardware/structs/iobank0.h"
#include "hardware/structs/ioqspi.h"
#include "hardware/structs/mpu.h"
#include "hardware/structs/padsbank0.h"
#include "hardware/structs/pads_qspi.h"
#include "hardware/structs/pio.h"
#include "hardware/structs/pll.h"
#include "hardware/structs/psm.h"
#include "hardware/structs/pwm.h"
#include "hardware/structs/resets.h"
#include "hardware/structs/rosc.h"
#include "hardware/structs/rtc.h"
#include "hardware/structs/scb.h"
#include "hardware/structs/sio.h"
#include "hardware/structs/spi.h"
#include "hardware/structs/ssi.h"
#include "hardware/structs/syscfg.h"
#include "hardware/structs/systick.h"
#include "hardware/structs/timer.h"
#include "hardware/structs/uart.h"
#include "hardware/structs/usb.h"
#include "hardware/structs/vreg_and_chip_reset.h"
#include "hardware/structs/watchdog.h"
#include "hardware/structs/xip_ctrl.h"
#include "hardware/structs/xosc.h"
//#include "hardware/adc.h"
#include "hardware/address_mapped.h"
#include "hardware/claim.h"
#include "hardware/clocks.h"
#include "hardware/divider.h"
#include "hardware/dma.h"
//#include "hardware/flash.h"
#include "hardware/gpio.h"
//#include "hardware/i2c.h"
#include "hardware/interp.h"
#include "hardware/irq.h"
#include "hardware/pio.h"
#include "hardware/pio_instructions.h"
#include "hardware/platform_defs.h"
#include "hardware/pll.h"
#include "hardware/pwm.h"
#include "hardware/resets.h"
//#include "hardware/rtc.h"
//#include "hardware/spi.h"
#include "hardware/sync.h"
#include "hardware/timer.h"
#include "hardware/uart.h"
#include "hardware/vreg.h"
#include "hardware/watchdog.h"
#include "hardware/xosc.h"
//#include "boot/picoboot.h"
//#include "boot/uf2.h"
//#include "pico.h"
//#include "tusb_config.h"
#include "pico/assert.h"
#include "pico/binary_info.h"
#include "pico/bit_ops.h"
#include "pico/bootrom.h"
#include "pico/config.h"
#include "pico/config_autogen.h"
#include "pico/critical_section.h"
#include "pico/divider.h"
#include "pico/double.h"
#include "pico/error.h"
#include "pico/float.h"
#include "pico/int64_ops.h"
#include "pico/lock_core.h"
#include "pico/malloc.h"
//#include "pico/mem_ops.h"
#include "pico/multicore.h"
#include "pico/mutex.h"
#include "pico/platform.h"
#include "pico/printf.h"
#include "pico/runtime.h"
#include "pico/sem.h"
#include "pico/stdio.h"
//#include "pico/stdio_semihosting.h"
//#include "pico/stdio_uart.h"
//#include "pico/stdio_usb.h"
#include "pico/stdlib.h"
#include "pico/sync.h"
#include "pico/time.h"
#include "pico/timeout_helper.h"
#include "pico/types.h"
//#include "pico/unique_id.h"
#include "pico/version.h"
#include "pico/binary_info/code.h"
#include "pico/binary_info/defs.h"
#include "pico/binary_info/structure.h"
#include "pico/bootrom/sf_table.h"
//#include "pico/fix/rp2040_usb_device_enumeration.h"
#include "pico/stdio/driver.h"
#include "pico/util/datetime.h"
#include "pico/util/pheap.h"
#include "pico/util/queue.h"
// PicoVGA includes
#include "src/define.h" // common definitions of C and ASM
#include "src/util/canvas.h" // canvas
#include "src/util/overclock.h" // overclock
#include "src/util/print.h" // print to attribute text buffer
#include "src/util/rand.h" // random number generator
#include "src/util/mat2d.h" // 2D transformation matrix
#include "src/util/pwmsnd.h" // PWM sound output
#include "src/vga_pal.h" // VGA colors and palettes
#include "src/vga_vmode.h" // VGA videomodes
#include "src/vga_layer.h" // VGA layers
#include "src/vga_screen.h" // VGA screen layout
#include "src/vga_util.h" // VGA utilities
#include "src/vga.h" // VGA output

View File

@@ -69,5 +69,5 @@ macro(add_picovga project)
target_link_libraries(${project} pico_stdlib hardware_pio hardware_dma pico_multicore hardware_interp hardware_pwm)
include_directories(${project} ${CMAKE_CURRENT_BINARY_DIR})
include_directories(${project} ${CMAKE_CURRENT_BINARY_DIR} ${PICOVGA_PATH}/src)
endmacro()

Binary file not shown.

View File

@@ -1,4 +1,4 @@
#include "include.h"
#include "picovga.h"
// format: 1-bit pixel graphics
// image width: 2048 pixels

View File

@@ -1,4 +1,4 @@
#include "include.h"
#include "picovga.h"
// format: 1-bit pixel graphics
// image width: 2048 pixels

View File

@@ -1,4 +1,4 @@
#include "include.h"
#include "picovga.h"
// format: 1-bit pixel graphics
// image width: 2048 pixels

View File

@@ -1,4 +1,4 @@
#include "include.h"
#include "picovga.h"
// format: 1-bit pixel graphics
// image width: 2048 pixels

View File

@@ -1,4 +1,4 @@
#include "include.h"
#include "picovga.h"
// format: 1-bit pixel graphics
// image width: 2048 pixels

View File

@@ -1,4 +1,4 @@
#include "include.h"
#include "picovga.h"
// format: 1-bit pixel graphics
// image width: 2048 pixels

View File

@@ -1,4 +1,4 @@
#include "include.h"
#include "picovga.h"
// format: 1-bit pixel graphics
// image width: 2048 pixels

View File

@@ -1,4 +1,4 @@
#include "include.h"
#include "picovga.h"
// format: 1-bit pixel graphics
// image width: 2048 pixels

View File

@@ -1,4 +1,4 @@
#include "include.h"
#include "picovga.h"
// format: 1-bit pixel graphics
// image width: 2048 pixels

View File

@@ -1,4 +1,4 @@
#include "include.h"
#include "picovga.h"
// format: 1-bit pixel graphics
// image width: 2048 pixels

View File

@@ -1,4 +1,4 @@
#include "include.h"
#include "picovga.h"
// format: 1-bit pixel graphics
// image width: 2048 pixels

View File

@@ -1,4 +1,4 @@
#include "include.h"
#include "picovga.h"
// format: 1-bit pixel graphics
// image width: 2048 pixels

136
src/picovga.h Normal file
View File

@@ -0,0 +1,136 @@
// ****************************************************************************
//
// Global common definitions
//
// ****************************************************************************
// ----------------------------------------------------------------------------
// Base data types
// ----------------------------------------------------------------------------
#ifndef _PICOVGA_H
#define _PICOVGA_H
typedef signed char s8;
typedef unsigned char u8;
typedef signed short s16;
typedef unsigned short u16;
typedef signed long int s32;
typedef unsigned long int u32;
typedef signed long long int s64;
typedef unsigned long long int u64;
typedef unsigned int uint;
typedef unsigned char Bool;
#define True 1
#define False 0
// NULL
#ifndef NULL
#ifdef __cplusplus
#define NULL 0
#else
#define NULL ((void*)0)
#endif
#endif
// I/O port prefix
#define __IO volatile
// request to use inline
#define INLINE __attribute__((always_inline)) inline
// avoid to use inline
#define NOINLINE __attribute__((noinline))
// weak function
#define WEAK __attribute__((weak))
// align array to 4-bytes
#define ALIGNED __attribute__((aligned(4)))
#define LED_PIN 25
// ----------------------------------------------------------------------------
// Constants
// ----------------------------------------------------------------------------
#define B0 (1<<0)
#define B1 (1<<1)
#define B2 (1<<2)
#define B3 (1<<3)
#define B4 (1<<4)
#define B5 (1<<5)
#define B6 (1<<6)
#define B7 (1<<7)
#define B8 (1U<<8)
#define B9 (1U<<9)
#define B10 (1U<<10)
#define B11 (1U<<11)
#define B12 (1U<<12)
#define B13 (1U<<13)
#define B14 (1U<<14)
#define B15 (1U<<15)
#define B16 (1UL<<16)
#define B17 (1UL<<17)
#define B18 (1UL<<18)
#define B19 (1UL<<19)
#define B20 (1UL<<20)
#define B21 (1UL<<21)
#define B22 (1UL<<22)
#define B23 (1UL<<23)
#define B24 (1UL<<24)
#define B25 (1UL<<25)
#define B26 (1UL<<26)
#define B27 (1UL<<27)
#define B28 (1UL<<28)
#define B29 (1UL<<29)
#define B30 (1UL<<30)
#define B31 (1UL<<31)
#define BIT(pos) (1UL<<(pos))
#define BIGINT 0x40000000 // big int value
#define _T(a) a
#define PI 3.14159265358979324
#define PI2 (3.14159265358979324*2)
// ----------------------------------------------------------------------------
// Includes
// ----------------------------------------------------------------------------
// fonts
extern const ALIGNED u8 FontBold8x8[2048];
extern const ALIGNED u8 FontBold8x14[3584];
extern const ALIGNED u8 FontBold8x16[4096];
extern const ALIGNED u8 FontBoldB8x14[3584];
extern const ALIGNED u8 FontBoldB8x16[4096];
extern const ALIGNED u8 FontGame8x8[2048];
extern const ALIGNED u8 FontIbm8x8[2048];
extern const ALIGNED u8 FontIbm8x14[3584];
extern const ALIGNED u8 FontIbm8x16[4096];
extern const ALIGNED u8 FontIbmTiny8x8[2048];
extern const ALIGNED u8 FontItalic8x8[2048];
extern const ALIGNED u8 FontThin8x8[2048];
// PicoVGA includes
#include "define.h" // common definitions of C and ASM
#include "util/canvas.h" // canvas
#include "util/overclock.h" // overclock
#include "util/print.h" // print to attribute text buffer
#include "util/rand.h" // random number generator
#include "util/mat2d.h" // 2D transformation matrix
#include "util/pwmsnd.h" // PWM sound output
#include "vga_pal.h" // VGA colors and palettes
#include "vga_vmode.h" // VGA videomodes
#include "vga_layer.h" // VGA layers
#include "vga_screen.h" // VGA screen layout
#include "vga_util.h" // VGA utilities
#include "vga.h" // VGA output
#endif

View File

@@ -5,7 +5,11 @@
//
// ****************************************************************************
#include "include.h"
#include "pico/stdlib.h"
#include "picovga.h"
#include <string.h>
#include "hardware/interp.h"
// Draw rectangle
// col with CANVAS_ATTRIB8 format: bit 0..3 = draw color, bit 4 = draw color is background color

View File

@@ -5,7 +5,7 @@
//
// ****************************************************************************
#include "include.h"
#include "mat2d.h"
// prepare transformation matrix (for DrawImgMat function)
// ws ... source image width

View File

@@ -8,6 +8,9 @@
#ifndef _MAT2D_H
#define _MAT2D_H
#include "pico/double.h"
#include "define.h"
// transformation matrix
template <typename m2type> class cMat2D
{

View File

@@ -5,7 +5,10 @@
//
// ****************************************************************************
#include "include.h"
#include "picovga.h"
#include "overclock.h"
#include "hardware/clocks.h"
#include "hardware/structs/ssi.h"
// Search PLL setup
// reqkhz ... required output frequency in kHz

View File

@@ -8,6 +8,8 @@
#ifndef _OVERCLOCK_H
#define _OVERCLOCK_H
#include "pico/stdlib.h"
// Search PLL setup
// reqkhz ... required output frequency in kHz
// input ... PLL input frequency in kHz (default 12000, or use clock_get_hz(clk_ref)/1000)

View File

@@ -5,7 +5,7 @@
//
// ****************************************************************************
#include "include.h"
#include "picovga.h"
// current print buffer
u8* PrintBuf;

View File

@@ -6,7 +6,10 @@
// ****************************************************************************
// Note: Cannot use DMA, because sample is 8-bit, but CC port requires 16-bit write.
#include "include.h"
#include "picovga.h"
#include "hardware/pwm.h"
#include "hardware/clocks.h"
#include "hardware/sync.h"
// current sound
const u8* CurSound = NULL; // current playing sound

View File

@@ -5,7 +5,8 @@
//
// ****************************************************************************
#include "include.h"
#include "picovga.h"
#include "hardware/structs/rosc.h"
// global random generator
cRandom Rand;

View File

@@ -5,9 +5,17 @@
//
// ****************************************************************************
#include "include.h"
#include "pico/stdlib.h"
#include "pico/printf.h"
#include "picovga.h"
#include "vga.pio.h"
#include <string.h>
#include "hardware/divider.h"
#include "hardware/dma.h"
#include "hardware/sync.h"
// scanline type
u8 ScanlineType[MAXLINE];

View File

@@ -5,9 +5,12 @@
//
// ****************************************************************************
#include "include.h"
#include "pico/stdlib.h"
#include "picovga.h"
#include "hardware/sync.h"
#include "vga.pio.h"
// layer program descriptors
const sLayerProg LayerProg[LAYERPROG_NUM] = {

View File

@@ -5,7 +5,8 @@
//
// ****************************************************************************
#include "include.h"
#include "pico/stdlib.h"
#include "picovga.h"
// default 16-color palettes (EGA colors)
// - do not set "const", to stay in faster RAM

View File

@@ -5,7 +5,9 @@
//
// ****************************************************************************
#include "include.h"
#include "pico/stdlib.h"
#include "picovga.h"
#include "hardware/sync.h"
// current video screen
sScreen Screen = { .num = 0 }; // default video screen

View File

@@ -5,7 +5,10 @@
//
// ****************************************************************************
#include "include.h"
#include "pico/stdlib.h"
#include "picovga.h"
#include <string.h>
// convert image from 16-color to 8x8 attribute format
void Attr8Conv(u8* dst, u8* attr, const u8* src, int w, int h, const u8* pal)

View File

@@ -5,7 +5,11 @@
//
// ****************************************************************************
#include "include.h"
#include "pico/stdlib.h"
#include "pico/printf.h"
#include "pico/multicore.h"
#include "picovga.h"
sVmode Vmode; // videomode setup
sVgaCfg Cfg; // required configuration