├── .gitignore ├── Compiler ├── .gitignore ├── bin │ ├── build-linux.sh │ ├── clbr19.dll │ ├── mt7r19.dll │ ├── pawn.cfg │ ├── pawn.ico │ ├── pawncc │ ├── pawncc.exe │ ├── pawnccnew │ └── windows_build.txt ├── history.txt ├── include │ ├── buttons.inc │ ├── calibration.inc │ ├── complex.inc │ ├── config.inc │ ├── console.inc │ ├── core.inc │ ├── default.inc │ ├── device.inc │ ├── dialog.inc │ ├── draw.inc │ ├── file.inc │ ├── fixed.inc │ ├── fourier.inc │ ├── fpga.inc │ ├── graph.inc │ ├── inifile.inc │ ├── menu.inc │ ├── metadata.inc │ ├── string.inc │ ├── time.inc │ ├── wavein.inc │ └── waveout.inc ├── readme.txt ├── source │ ├── amx │ │ ├── CMakeLists.txt │ │ ├── amx.c │ │ ├── amx.h │ │ ├── amxDGram.def │ │ ├── amxDGram.rc │ │ ├── amxFile.rc │ │ ├── amxFixed.def │ │ ├── amxFixed.rc │ │ ├── amxFloat.def │ │ ├── amxFloat.rc │ │ ├── amxProcess.def │ │ ├── amxProcess.rc │ │ ├── amxargs.c │ │ ├── amxargs.def │ │ ├── amxargs.rc │ │ ├── amxaux.c │ │ ├── amxaux.h │ │ ├── amxcons.c │ │ ├── amxcons.h │ │ ├── amxcons_arm7.c │ │ ├── amxcore.c │ │ ├── amxdbg.c │ │ ├── amxdbg.h │ │ ├── amxdef.asm │ │ ├── amxdefn.asm │ │ ├── amxdgram.c │ │ ├── amxexec.asm │ │ ├── amxexec_arm7.s │ │ ├── amxexec_arm7_gas.s │ │ ├── amxexec_gcc.c │ │ ├── amxexec_thumb2.s │ │ ├── amxexec_thumb2_gas.s │ │ ├── amxexecn.asm │ │ ├── amxfile.c │ │ ├── amxfile.def │ │ ├── amxgc.c │ │ ├── amxgc.h │ │ ├── amxjitr.asm │ │ ├── amxjits.asm │ │ ├── amxjitsn.asm │ │ ├── amxpool.c │ │ ├── amxpool.h │ │ ├── amxprocess.c │ │ ├── amxstring.c │ │ ├── amxstring.def │ │ ├── amxstring.rc │ │ ├── amxtime.c │ │ ├── amxtime.def │ │ ├── amxtime.rc │ │ ├── dllmain.c │ │ ├── examples │ │ │ ├── logfile.cpp │ │ │ ├── power.c │ │ │ ├── prun1.c │ │ │ ├── prun2.c │ │ │ ├── prun3.c │ │ │ ├── prun4.c │ │ │ ├── prun5.c │ │ │ ├── prun_jit.c │ │ │ └── readme.txt │ │ ├── fixed.c │ │ ├── float.c │ │ ├── fpattern.c │ │ ├── fpattern.h │ │ ├── keeloq.c │ │ ├── keeloq.h │ │ ├── minGlue.h │ │ ├── minIni.c │ │ ├── minIni.h │ │ ├── osdefs.h │ │ ├── pawndbg.c │ │ ├── pawnrun.c │ │ ├── term_ga.c │ │ ├── term_ga.h │ │ ├── termwin.c │ │ └── termwin.h │ ├── compiler │ │ ├── CMakeLists.txt │ │ ├── libpawnc.c │ │ ├── libpawnc.def │ │ ├── libpawnc.def.borland │ │ ├── libpawnc.lbc │ │ ├── libpawnc.rc │ │ ├── lstring.c │ │ ├── lstring.h │ │ ├── memfile.c │ │ ├── memfile.h │ │ ├── pawncc.c │ │ ├── pawncc.def │ │ ├── pawncc.def.borland │ │ ├── pawncc.rc │ │ ├── pawndisasm.c │ │ ├── sc.h │ │ ├── sc1.c │ │ ├── sc2.c │ │ ├── sc3.c │ │ ├── sc4.c │ │ ├── sc5.c │ │ ├── sc5.scp │ │ ├── sc6.c │ │ ├── sc7.c │ │ ├── sc7.scp │ │ ├── scexpand.c │ │ ├── sci18n.c │ │ ├── sclist.c │ │ ├── scmemfil.c │ │ ├── scpack.c │ │ ├── scstate.c │ │ ├── scstub.c │ │ ├── scvars.c │ │ └── svnrev.h │ ├── linux │ │ ├── binreloc.c │ │ ├── binreloc.h │ │ ├── getch.c │ │ ├── getch.h │ │ └── sclinux.h │ └── macosx │ │ ├── .DS_Store │ │ ├── pawn.xcodeproj │ │ └── project.pbxproj │ │ ├── pawnmacosx.h │ │ └── readme.rtf └── xml │ ├── pawndoc.css │ └── pawndoc.xsl ├── LICENSE ├── Programs ├── LOGIC.FPG ├── Makefile ├── TESTFPGA.BIN ├── advvolt.amx ├── advvolt.pawn ├── beeper.amx ├── beeper.pawn ├── calibrat.amx ├── calibrat.pawn ├── charmap.amx ├── charmap.pawn ├── fpga_test.amx ├── fpga_test.pawn ├── freqresp.amx ├── freqresp.pawn ├── getlicense.amx ├── getlicense.pawn ├── hello.amx ├── hello.pawn ├── i2c.amx ├── i2c.pawn ├── logiccap.amx ├── logiccap.pawn ├── servo.amx ├── servo.pawn ├── signlgen.amx ├── signlgen.pawn ├── spec_an.amx ├── spec_an.pawn ├── specgram.amx ├── specgram.pawn ├── spectrum.amx ├── spectrum.pawn ├── torch.amx ├── torch.pawn ├── unittest.amx ├── unittest.pawn ├── voltmetr.amx └── voltmetr.pawn ├── README.md └── Runtime ├── .gitignore ├── DS203 ├── BIOS.S ├── BIOS.h ├── Interrupt.c ├── Interrupt.h └── startup.c ├── Makefile ├── alterbios ├── ALTBIOS.HEX ├── alterbios.h ├── alterbios.s └── fatfs │ ├── ff.h │ ├── ffconf.h │ └── integer.h ├── amx ├── amx.c ├── amx.h ├── amxDGram.def ├── amxDGram.rc ├── amxFile.rc ├── amxFixed.def ├── amxFixed.rc ├── amxFloat.def ├── amxFloat.rc ├── amxProcess.def ├── amxProcess.rc ├── amxargs.c ├── amxargs.rc ├── amxaux.c ├── amxaux.h ├── amxcons.c ├── amxcons.h ├── amxcore.c ├── amxdbg.c ├── amxdbg.h ├── amxdef.asm ├── amxdefn.asm ├── amxdgram.c ├── amxexec.asm ├── amxexec_arm7.s ├── amxexec_arm7_gas.s ├── amxexec_gcc.c ├── amxexec_thumb2.s ├── amxexec_thumb2_gas.s ├── amxexecn.asm ├── amxfile.c ├── amxfile.def ├── amxgc.c ├── amxgc.h ├── amxjitr.asm ├── amxjits.asm ├── amxjitsn.asm ├── amxpool.c ├── amxpool.h ├── amxprocess.c ├── amxstring.c ├── amxstring.def ├── amxstring.rc ├── amxtime.c ├── amxtime.def ├── amxtime.rc ├── dllmain.c ├── examples │ ├── logfile.cpp │ ├── power.c │ ├── prun1.c │ ├── prun2.c │ ├── prun3.c │ ├── prun4.c │ ├── prun5.c │ ├── prun_jit.c │ └── readme.txt ├── fixed.c ├── float.c ├── fpattern.c ├── fpattern.h ├── keeloq.c ├── keeloq.h ├── minGlue.h ├── minIni.c ├── minIni.h ├── osdefs.h ├── pawndbg.c ├── pawnrun.c ├── readme.txt ├── term_ga.c ├── term_ga.h ├── termwin.c └── termwin.h ├── amx_buttons.c ├── amx_core.c ├── amx_debug.c ├── amx_debug.h ├── amx_device.c ├── amx_draw.c ├── amx_file.c ├── amx_fixed.c ├── amx_fourier.c ├── amx_fpga.c ├── amx_menu.c ├── amx_menu.h ├── amx_overlays.c ├── amx_string.c ├── amx_time.c ├── amx_wavein.c ├── amx_waveout.c ├── baselibc ├── .gitignore ├── Makefile ├── README.md ├── include │ ├── assert.h │ ├── ctype.h │ ├── inttypes.h │ ├── klibc │ │ ├── extern.h │ │ └── inline.h │ ├── netinet │ │ └── in.h │ ├── stdio.h │ ├── stdlib.h │ ├── string.h │ └── tinyprintf.h └── src │ ├── asprintf.c │ ├── atoi.c │ ├── atol.c │ ├── atoll.c │ ├── atox.c │ ├── bsearch.c │ ├── bzero.c │ ├── calloc.c │ ├── fgets.c │ ├── fprintf.c │ ├── inline.c │ ├── jrand48.c │ ├── lrand48.c │ ├── malloc.c │ ├── malloc.h │ ├── memccpy.c │ ├── memchr.c │ ├── memcmp.c │ ├── memcpy.c │ ├── memmem.c │ ├── memmove.c │ ├── memrchr.c │ ├── memset.c │ ├── memswap.c │ ├── mrand48.c │ ├── nrand48.c │ ├── printf.c │ ├── qsort.c │ ├── realloc.c │ ├── snprintf.c │ ├── sprintf.c │ ├── srand48.c │ ├── sscanf.c │ ├── strcasecmp.c │ ├── strcat.c │ ├── strchr.c │ ├── strcmp.c │ ├── strcpy.c │ ├── strcspn.c │ ├── strdup.c │ ├── strlcat.c │ ├── strlcpy.c │ ├── strlen.c │ ├── strncasecmp.c │ ├── strncat.c │ ├── strncmp.c │ ├── strncpy.c │ ├── strndup.c │ ├── strnlen.c │ ├── strntoimax.c │ ├── strntoumax.c │ ├── strpbrk.c │ ├── strrchr.c │ ├── strsep.c │ ├── strspn.c │ ├── strstr.c │ ├── strtoimax.c │ ├── strtok.c │ ├── strtok_r.c │ ├── strtol.c │ ├── strtoll.c │ ├── strtoul.c │ ├── strtoull.c │ ├── strtoumax.c │ ├── strtox.c │ ├── strxspn.h │ ├── tinyprintf.c │ ├── vasprintf.c │ ├── vfprintf.c │ ├── vprintf.c │ ├── vsnprintf.c │ ├── vsprintf.c │ └── vsscanf.c ├── buttons.c ├── buttons.h ├── debug.c ├── drawing.c ├── drawing.h ├── ds203_io.c ├── ds203_io.h ├── file_selector.c ├── file_selector.h ├── fix16_fft.c ├── fpga.c ├── fpga.h ├── gdb_debug_memory_dump.txt ├── gpio.h ├── irq.h ├── libc_glue.c ├── libfixmath ├── Makefile ├── fix16.c ├── fix16.h ├── fix16.hpp ├── fix16_exp.c ├── fix16_sqrt.c ├── fix16_trig.c ├── fix16_trig_sin_lut.h ├── fixmath.h ├── fract32.c ├── fract32.h ├── int64.h ├── libfixmath.cbp ├── uint32.c └── uint32.h ├── linker_scripts ├── app1.lds ├── app2.lds ├── app3.lds ├── app4.lds └── main.lds ├── main.c ├── mathutils.h ├── menubar.c ├── menubar.h ├── metadata.c ├── metadata.h ├── msgbox.c ├── msgbox.h ├── stm32_headers ├── core_cm3.h └── stm32f10x.h └── utils.h /.gitignore: -------------------------------------------------------------------------------- 1 | .*~ 2 | -------------------------------------------------------------------------------- /Compiler/.gitignore: -------------------------------------------------------------------------------- 1 | CMakeCache.txt 2 | CMakeFiles 3 | Makefile 4 | cmake_install.cmake 5 | install_manifest.txt 6 | -------------------------------------------------------------------------------- /Compiler/bin/build-linux.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | rm -f CMakeCache.txt 4 | export CFLAGS="-DHAVE_I64" 5 | cmake ../source/compiler/ 6 | make 7 | -------------------------------------------------------------------------------- /Compiler/bin/clbr19.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PetteriAimonen/QuadPawn/704ea78c61738574bb62407f503fc49a13ffb405/Compiler/bin/clbr19.dll -------------------------------------------------------------------------------- /Compiler/bin/mt7r19.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PetteriAimonen/QuadPawn/704ea78c61738574bb62407f503fc49a13ffb405/Compiler/bin/mt7r19.dll -------------------------------------------------------------------------------- /Compiler/bin/pawn.cfg: -------------------------------------------------------------------------------- 1 | -X32768 2 | -S1024 3 | -O2 4 | -v2 5 | -------------------------------------------------------------------------------- /Compiler/bin/pawn.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PetteriAimonen/QuadPawn/704ea78c61738574bb62407f503fc49a13ffb405/Compiler/bin/pawn.ico -------------------------------------------------------------------------------- /Compiler/bin/pawncc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PetteriAimonen/QuadPawn/704ea78c61738574bb62407f503fc49a13ffb405/Compiler/bin/pawncc -------------------------------------------------------------------------------- /Compiler/bin/pawncc.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PetteriAimonen/QuadPawn/704ea78c61738574bb62407f503fc49a13ffb405/Compiler/bin/pawncc.exe -------------------------------------------------------------------------------- /Compiler/bin/pawnccnew: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PetteriAimonen/QuadPawn/704ea78c61738574bb62407f503fc49a13ffb405/Compiler/bin/pawnccnew -------------------------------------------------------------------------------- /Compiler/bin/windows_build.txt: -------------------------------------------------------------------------------- 1 | The Windows build is done using OpenWatcom compiler and CMakeSetup. 2 | 3 | It is also possible to cross-compile using mingw, but the resulting 4 | binary somehow messes up the parser and spits out errors. 5 | -------------------------------------------------------------------------------- /Compiler/history.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PetteriAimonen/QuadPawn/704ea78c61738574bb62407f503fc49a13ffb405/Compiler/history.txt -------------------------------------------------------------------------------- /Compiler/include/complex.inc: -------------------------------------------------------------------------------- 1 | /** Simple complex number manipulation routines. */ 2 | 3 | #include 4 | 5 | /// Get the absolute value from a complex number 6 | stock Fixed: cabs(Fixed: real, Fixed: imag) 7 | { 8 | return sqrt(real * real + imag * imag); 9 | } 10 | 11 | /// Get the argument (phase) from a complex number, in radians 12 | stock Fixed: carg(Fixed: real, Fixed: imag) 13 | { 14 | return atan2(imag, real); 15 | } 16 | 17 | /// Multiply complex numbers 18 | stock cmul(&Fixed: real1, &Fixed: imag1, Fixed: real2, Fixed: imag2) 19 | { 20 | // (a + ib) * (c + id) = ac - bd + i(bc + ad) 21 | new Fixed: tmp = real1 * real2 - imag1 * imag2; 22 | imag1 = imag1 * real2 + imag2 * real1; 23 | real1 = tmp; 24 | } 25 | 26 | /// Divide complex numbers 27 | stock cdiv(&Fixed: real1, &Fixed: imag1, Fixed: real2, Fixed: imag2) 28 | { 29 | // (a + ib) / (c + id) = (a + ib) (c - id) / (c^2 + d^2) 30 | new Fixed: divisor = (real2 * real2 + imag2 * imag2); 31 | cmul(real1, imag1, real2, -imag2); 32 | 33 | real1 = real1 / divisor; 34 | imag1 = imag1 / divisor; 35 | } 36 | -------------------------------------------------------------------------------- /Compiler/include/core.inc: -------------------------------------------------------------------------------- 1 | /// Return number of free cells in the virtual machine heap 2 | native heapspace(); 3 | 4 | /// Return index of a public function. 5 | native funcidx(const name[]); 6 | 7 | /// Variable argument list handling 8 | native numargs(); 9 | native getarg(arg, index=0); 10 | native setarg(arg, index=0, value); 11 | 12 | /// Clear an array 13 | native memset(array[], value = 0, count = sizeof array); 14 | 15 | /// Copy array into another 16 | native memcpy(dest[], const src[], count = sizeof dest); 17 | 18 | stock min(value1, value2) 19 | return (value1 <= value2) ? value1 : value2; 20 | 21 | stock max(value1, value2) 22 | return (value1 >= value2) ? value1 : value2; 23 | 24 | stock clamp(value, min=cellmin, max=cellmax) 25 | { 26 | if (value < min) 27 | return min; 28 | else if (value > max) 29 | return max; 30 | else 31 | return value; 32 | } 33 | 34 | stock abs(value) 35 | { 36 | if (value < 0) 37 | return -value; 38 | else 39 | return value; 40 | } 41 | -------------------------------------------------------------------------------- /Compiler/include/default.inc: -------------------------------------------------------------------------------- 1 | /** This file lists all the Pawn modules that are included by default, 2 | * so that apps don't need a huge list of #include statements. 3 | */ 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | -------------------------------------------------------------------------------- /Compiler/include/device.inc: -------------------------------------------------------------------------------- 1 | /** Functions to control the device hardware, such as screen backlight, 2 | * beeper and power saving. 3 | */ 4 | 5 | /// Set backlight level, value from 0 to 100 (0 is off). 6 | native set_backlight(level); 7 | 8 | /// Set FPGA & ADC power save mode. 9 | /// To enter power save, simply call set_powersave(true). 10 | /// To exit power save, call set_powersave(false) and then 11 | /// reconfigure wavein_samplerate() etc. settings. 12 | /// You'll also need to turn on the backlight using e.g. set_backlight(100). 13 | native set_powersave(bool: enable); 14 | 15 | /// Beep for the given time (in milliseconds), at the given 16 | /// frequency (in hertz) and with the given volume (0 to 100). 17 | /// Function will return immediately, beep will continue for given time. 18 | native beep(milliseconds = 500, frequency = 400, volume = 80); 19 | 20 | /// Returns the current battery voltage in millivolts. 21 | /// Full is 4.2V, Empty is 3.5V, but discharge is not linear. 22 | native battery_voltage(); 23 | 24 | //Returns the content of the flash at the given address 25 | native read_flash(int: address); 26 | 27 | //Returns the SN 28 | native read_SN(); -------------------------------------------------------------------------------- /Compiler/include/dialog.inc: -------------------------------------------------------------------------------- 1 | /** Simple routines for showing a question dialog to the user. */ 2 | 3 | #include 4 | #include 5 | 6 | /// Show a multiple choice dialog. Returns the index of the selected option, ie. an integer 0 to 3. 7 | stock show_dialog(const message{}, opt1{}, opt2{} = "", opt3{} = "", opt4{} = "") 8 | { 9 | clear_screen(); 10 | get_keys(ANY_KEY); 11 | draw_menubar(opt1, opt2, opt3, opt4); 12 | draw_flowtext(message, 10, 10, 380, 160); 13 | 14 | new result = -1; 15 | while (result < 0) 16 | { 17 | new button: keys = get_keys(ANY_KEY); 18 | if (opt1{0} && (keys & BUTTON1)) result = 0; 19 | if (opt2{0} && (keys & BUTTON2)) result = 1; 20 | if (opt3{0} && (keys & BUTTON3)) result = 2; 21 | if (opt4{0} && (keys & BUTTON4)) result = 3; 22 | } 23 | 24 | clear_screen(); 25 | return result; 26 | } 27 | 28 | /// Show a yes-no question box. Returns true if user answers yes. 29 | stock bool: show_question(const question{}) 30 | { 31 | return show_dialog(question, "Yes", "No") == 0; 32 | } 33 | 34 | /// Show a message box with OK button only. 35 | stock show_msgbox(const message{}) 36 | { 37 | show_dialog(message, "OK"); 38 | } 39 | -------------------------------------------------------------------------------- /Compiler/include/fourier.inc: -------------------------------------------------------------------------------- 1 | /** Implementation of some Fourier transform algorithms. These typically 2 | * take an input of 8-bit packed arrays, such as the ones you get from 3 | * the wavein module. Output is in the fixed point format. 4 | */ 5 | 6 | #include 7 | #include 8 | 9 | /// Discrete Fourier transform at a single frequency. 10 | /// The frequency is given as the number of samples in a single period. 11 | /// Count is the number of samples available in input. It will be rounded 12 | /// down to the nearest multiple of period. 13 | native dft(const input{}, &Fixed: real, &Fixed: imag, Fixed: period, count); 14 | 15 | /// Fast Fourier transform. 16 | /// Transform length (count) must be a power of 2. 17 | /// All arrays are of same size. 18 | /// If window is true, the Hamming window function is applied to input values before processing. 19 | native fft(const input{}, Fixed: real[], Fixed: imag[], count, bool:window = true); 20 | -------------------------------------------------------------------------------- /Compiler/include/menu.inc: -------------------------------------------------------------------------------- 1 | /** The menu bar appears at the top of the screen and contains labels for 2 | * button actions. This file also declares event callbacks for buttons, 3 | * which are an alternative interface relative to the polling functions in 4 | * buttons.inc. 5 | */ 6 | 7 | /// Set the menu labels, there is space for about 7 characters on the screen. 8 | native draw_menubar(label1{}, label2{} = "", label3{} = "", label4{} = ""); 9 | 10 | /// Implement these functions to handle the buttons 11 | forward @button1(); 12 | forward @button2(); 13 | forward @button3(); 14 | forward @button4(); 15 | 16 | /// Implement these functions to handle the scrollers. 17 | /// Parameter is the scroll amount (positive or negative), or 0 for scroller 18 | /// click. 19 | // forward @scroll1(delta); 20 | // forward @scroll2(delta); 21 | 22 | /// If you want the program to keep handling events even after main() exits, you must implement this function. 23 | /// It should return false when the program should exit. 24 | /// Other way is to use the sleep(ms) instruction, but that stops stack usage calculation from working so returning from main and using @idle() is preferred. 25 | forward bool: @idle(); 26 | -------------------------------------------------------------------------------- /Compiler/include/metadata.inc: -------------------------------------------------------------------------------- 1 | /** Stores metadata about the program, i.e. icon and name. 2 | * Define variables program_icon[] and program_name{} and then 3 | * include this file 4 | */ 5 | 6 | forward get_program_icon(icon[32]); 7 | forward get_program_name(name{32}); 8 | 9 | public get_program_icon(icon[32]) 10 | icon = program_icon; 11 | 12 | public get_program_name(name{32}) 13 | name = program_name; 14 | -------------------------------------------------------------------------------- /Compiler/include/time.inc: -------------------------------------------------------------------------------- 1 | /** Functions based on internal 1ms timer tick. */ 2 | 3 | /// Return time passed since system boot in milliseconds. 4 | /// Overflows after 24 days of operation. 5 | native get_time(); 6 | 7 | /// Implement this function to get periodic callbacks when 8 | /// in "event driven" mode. 9 | forward @timertick(); 10 | 11 | /// Set the period for the timertick callback, in milliseconds. 12 | /// Set to 0 (default) to disable the timer tick. 13 | native set_timer(period); 14 | 15 | /// Delay without yielding events. This simply waits in a busy loop. 16 | native delay_ms(delay); 17 | -------------------------------------------------------------------------------- /Compiler/source/amx/amxDGram.def: -------------------------------------------------------------------------------- 1 | NAME amxDGram 2 | DESCRIPTION 'Pawn AMX: network datagram' 3 | 4 | EXPORTS 5 | amx_DGramInit 6 | amx_DGramCleanup 7 | -------------------------------------------------------------------------------- /Compiler/source/amx/amxDGram.rc: -------------------------------------------------------------------------------- 1 | #include 2 | #if defined WIN32 || defined _WIN32 || defined __WIN32__ 3 | # include 4 | #else 5 | # include 6 | #endif 7 | 8 | /* Version information 9 | * 10 | * All strings MUST have an explicit \0. See the Windows SDK documentation 11 | * for details on version information and the VERSIONINFO structure. 12 | */ 13 | #define VERSION 4 14 | #define REVISION 0 15 | #define BUILD 0 16 | #define VERSIONSTR "4.0.0\0" 17 | #define VERSIONNAME "amxDGram.dll\0" 18 | #define VERSIONDESCRIPTION "Pawn AMX: network datagram\0" 19 | #define VERSIONCOMPANYNAME "ITB CompuPhase\0" 20 | #define VERSIONPRODUCTNAME "amxDGram\0" 21 | #define VERSIONCOPYRIGHT "Copyright \251 2007-2011 ITB CompuPhase\0" 22 | 23 | VS_VERSION_INFO VERSIONINFO 24 | FILEVERSION VERSION, REVISION, BUILD, 0 25 | PRODUCTVERSION VERSION, REVISION, BUILD, 0 26 | FILEFLAGSMASK 0x0000003FL 27 | FILEFLAGS 0 28 | #if defined(WIN32) 29 | FILEOS VOS__WINDOWS32 30 | #else 31 | FILEOS VOS__WINDOWS16 32 | #endif 33 | FILETYPE VFT_DLL 34 | BEGIN 35 | BLOCK "StringFileInfo" 36 | BEGIN 37 | BLOCK "040904E4" 38 | BEGIN 39 | VALUE "CompanyName", VERSIONCOMPANYNAME 40 | VALUE "FileDescription", VERSIONDESCRIPTION 41 | VALUE "FileVersion", VERSIONSTR 42 | VALUE "InternalName", VERSIONNAME 43 | VALUE "LegalCopyright", VERSIONCOPYRIGHT 44 | VALUE "OriginalFilename", VERSIONNAME 45 | VALUE "ProductName", VERSIONPRODUCTNAME 46 | VALUE "ProductVersion", VERSIONSTR 47 | END 48 | END 49 | 50 | BLOCK "VarFileInfo" 51 | BEGIN 52 | VALUE "Translation", 0x409, 1252 53 | END 54 | END 55 | -------------------------------------------------------------------------------- /Compiler/source/amx/amxFile.rc: -------------------------------------------------------------------------------- 1 | #include 2 | #if defined WIN32 || defined _WIN32 || defined __WIN32__ 3 | # include 4 | #else 5 | # include 6 | #endif 7 | 8 | /* Version information 9 | * 10 | * All strings MUST have an explicit \0. See the Windows SDK documentation 11 | * for details on version information and the VERSIONINFO structure. 12 | */ 13 | #define VERSION 4 14 | #define REVISION 0 15 | #define BUILD 0 16 | #define VERSIONSTR "4.0.0\0" 17 | #define VERSIONNAME "amxFile.dll\0" 18 | #define VERSIONDESCRIPTION "Pawn AMX: File I/O support\0" 19 | #define VERSIONCOMPANYNAME "ITB CompuPhase\0" 20 | #define VERSIONPRODUCTNAME "amxFile\0" 21 | #define VERSIONCOPYRIGHT "Copyright \251 2004-2011 ITB CompuPhase\0" 22 | 23 | VS_VERSION_INFO VERSIONINFO 24 | FILEVERSION VERSION, REVISION, BUILD, 0 25 | PRODUCTVERSION VERSION, REVISION, BUILD, 0 26 | FILEFLAGSMASK 0x0000003FL 27 | FILEFLAGS 0 28 | #if defined(WIN32) 29 | FILEOS VOS__WINDOWS32 30 | #else 31 | FILEOS VOS__WINDOWS16 32 | #endif 33 | FILETYPE VFT_DLL 34 | BEGIN 35 | BLOCK "StringFileInfo" 36 | BEGIN 37 | BLOCK "040904E4" 38 | BEGIN 39 | VALUE "CompanyName", VERSIONCOMPANYNAME 40 | VALUE "FileDescription", VERSIONDESCRIPTION 41 | VALUE "FileVersion", VERSIONSTR 42 | VALUE "InternalName", VERSIONNAME 43 | VALUE "LegalCopyright", VERSIONCOPYRIGHT 44 | VALUE "OriginalFilename", VERSIONNAME 45 | VALUE "ProductName", VERSIONPRODUCTNAME 46 | VALUE "ProductVersion", VERSIONSTR 47 | END 48 | END 49 | 50 | BLOCK "VarFileInfo" 51 | BEGIN 52 | VALUE "Translation", 0x409, 1252 53 | END 54 | END 55 | -------------------------------------------------------------------------------- /Compiler/source/amx/amxFixed.def: -------------------------------------------------------------------------------- 1 | NAME amxFixed 2 | DESCRIPTION 'Pawn AMX: fixed-point arithmetic' 3 | 4 | EXPORTS 5 | amx_FixedInit 6 | amx_FixedCleanup 7 | -------------------------------------------------------------------------------- /Compiler/source/amx/amxFixed.rc: -------------------------------------------------------------------------------- 1 | #include 2 | #if defined WIN32 || defined _WIN32 || defined __WIN32__ 3 | # include 4 | #else 5 | # include 6 | #endif 7 | 8 | /* Version information 9 | * 10 | * All strings MUST have an explicit \0. See the Windows SDK documentation 11 | * for details on version information and the VERSIONINFO structure. 12 | */ 13 | #define VERSION 4 14 | #define REVISION 0 15 | #define BUILD 0 16 | #define VERSIONSTR "4.0.0\0" 17 | #define VERSIONNAME "amxFixed.dll\0" 18 | #define VERSIONDESCRIPTION "Pawn AMX: Fixed Point support\0" 19 | #define VERSIONCOMPANYNAME "ITB CompuPhase\0" 20 | #define VERSIONPRODUCTNAME "amxFixed\0" 21 | #define VERSIONCOPYRIGHT "Copyright \251 2003-2011 ITB CompuPhase\0" 22 | 23 | VS_VERSION_INFO VERSIONINFO 24 | FILEVERSION VERSION, REVISION, BUILD, 0 25 | PRODUCTVERSION VERSION, REVISION, BUILD, 0 26 | FILEFLAGSMASK 0x0000003FL 27 | FILEFLAGS 0 28 | #if defined(WIN32) 29 | FILEOS VOS__WINDOWS32 30 | #else 31 | FILEOS VOS__WINDOWS16 32 | #endif 33 | FILETYPE VFT_DLL 34 | BEGIN 35 | BLOCK "StringFileInfo" 36 | BEGIN 37 | BLOCK "040904E4" 38 | BEGIN 39 | VALUE "CompanyName", VERSIONCOMPANYNAME 40 | VALUE "FileDescription", VERSIONDESCRIPTION 41 | VALUE "FileVersion", VERSIONSTR 42 | VALUE "InternalName", VERSIONNAME 43 | VALUE "LegalCopyright", VERSIONCOPYRIGHT 44 | VALUE "OriginalFilename", VERSIONNAME 45 | VALUE "ProductName", VERSIONPRODUCTNAME 46 | VALUE "ProductVersion", VERSIONSTR 47 | END 48 | END 49 | 50 | BLOCK "VarFileInfo" 51 | BEGIN 52 | VALUE "Translation", 0x409, 1252 53 | END 54 | END 55 | -------------------------------------------------------------------------------- /Compiler/source/amx/amxFloat.def: -------------------------------------------------------------------------------- 1 | NAME amxFloat 2 | DESCRIPTION 'Pawn AMX: floating-point arithmetic' 3 | 4 | EXPORTS 5 | amx_FloatInit 6 | amx_FloatCleanup 7 | -------------------------------------------------------------------------------- /Compiler/source/amx/amxFloat.rc: -------------------------------------------------------------------------------- 1 | #include 2 | #if defined WIN32 || defined _WIN32 || defined __WIN32__ 3 | # include 4 | #else 5 | # include 6 | #endif 7 | 8 | /* Version information 9 | * 10 | * All strings MUST have an explicit \0. See the Windows SDK documentation 11 | * for details on version information and the VERSIONINFO structure. 12 | */ 13 | #define VERSION 4 14 | #define REVISION 0 15 | #define BUILD 0 16 | #define VERSIONSTR "4.0.0\0" 17 | #define VERSIONNAME "amxFloat.dll\0" 18 | #define VERSIONDESCRIPTION "Pawn AMX: Floating Point support\0" 19 | #define VERSIONCOMPANYNAME "ITB CompuPhase\0" 20 | #define VERSIONPRODUCTNAME "amxFloat\0" 21 | #define VERSIONCOPYRIGHT "Copyright \251 2003-2011 ITB CompuPhase\0" 22 | 23 | VS_VERSION_INFO VERSIONINFO 24 | FILEVERSION VERSION, REVISION, BUILD, 0 25 | PRODUCTVERSION VERSION, REVISION, BUILD, 0 26 | FILEFLAGSMASK 0x0000003FL 27 | FILEFLAGS 0 28 | #if defined(WIN32) 29 | FILEOS VOS__WINDOWS32 30 | #else 31 | FILEOS VOS__WINDOWS16 32 | #endif 33 | FILETYPE VFT_DLL 34 | BEGIN 35 | BLOCK "StringFileInfo" 36 | BEGIN 37 | BLOCK "040904E4" 38 | BEGIN 39 | VALUE "CompanyName", VERSIONCOMPANYNAME 40 | VALUE "FileDescription", VERSIONDESCRIPTION 41 | VALUE "FileVersion", VERSIONSTR 42 | VALUE "InternalName", VERSIONNAME 43 | VALUE "LegalCopyright", VERSIONCOPYRIGHT 44 | VALUE "OriginalFilename", VERSIONNAME 45 | VALUE "ProductName", VERSIONPRODUCTNAME 46 | VALUE "ProductVersion", VERSIONSTR 47 | END 48 | END 49 | 50 | BLOCK "VarFileInfo" 51 | BEGIN 52 | VALUE "Translation", 0x409, 1252 53 | END 54 | END 55 | -------------------------------------------------------------------------------- /Compiler/source/amx/amxProcess.def: -------------------------------------------------------------------------------- 1 | NAME amxProcess 2 | DESCRIPTION 'Pawn AMX: process control and foreign function interface' 3 | 4 | EXPORTS 5 | amx_ProcessInit 6 | amx_ProcessCleanup 7 | -------------------------------------------------------------------------------- /Compiler/source/amx/amxProcess.rc: -------------------------------------------------------------------------------- 1 | #include 2 | #if defined WIN32 || defined _WIN32 || defined __WIN32__ 3 | # include 4 | #else 5 | # include 6 | #endif 7 | 8 | /* Version information 9 | * 10 | * All strings MUST have an explicit \0. See the Windows SDK documentation 11 | * for details on version information and the VERSIONINFO structure. 12 | */ 13 | #define VERSION 4 14 | #define REVISION 0 15 | #define BUILD 0 16 | #define VERSIONSTR "4.0.0\0" 17 | #define VERSIONNAME "amxProcess.dll\0" 18 | #define VERSIONDESCRIPTION "Pawn AMX: process control and foreign function interface\0" 19 | #define VERSIONCOMPANYNAME "ITB CompuPhase\0" 20 | #define VERSIONPRODUCTNAME "amxProcess\0" 21 | #define VERSIONCOPYRIGHT "Copyright \251 2005-2011 ITB CompuPhase\0" 22 | 23 | VS_VERSION_INFO VERSIONINFO 24 | FILEVERSION VERSION, REVISION, BUILD, 0 25 | PRODUCTVERSION VERSION, REVISION, BUILD, 0 26 | FILEFLAGSMASK 0x0000003FL 27 | FILEFLAGS 0 28 | #if defined(WIN32) 29 | FILEOS VOS__WINDOWS32 30 | #else 31 | FILEOS VOS__WINDOWS16 32 | #endif 33 | FILETYPE VFT_DLL 34 | BEGIN 35 | BLOCK "StringFileInfo" 36 | BEGIN 37 | BLOCK "040904E4" 38 | BEGIN 39 | VALUE "CompanyName", VERSIONCOMPANYNAME 40 | VALUE "FileDescription", VERSIONDESCRIPTION 41 | VALUE "FileVersion", VERSIONSTR 42 | VALUE "InternalName", VERSIONNAME 43 | VALUE "LegalCopyright", VERSIONCOPYRIGHT 44 | VALUE "OriginalFilename", VERSIONNAME 45 | VALUE "ProductName", VERSIONPRODUCTNAME 46 | VALUE "ProductVersion", VERSIONSTR 47 | END 48 | END 49 | 50 | BLOCK "VarFileInfo" 51 | BEGIN 52 | VALUE "Translation", 0x409, 1252 53 | END 54 | END 55 | -------------------------------------------------------------------------------- /Compiler/source/amx/amxargs.def: -------------------------------------------------------------------------------- 1 | NAME amxArgs 2 | DESCRIPTION 'Pawn AMX: Script Arguments support' 3 | 4 | EXPORTS 5 | amx_ArgsInit 6 | amx_ArgsCleanup 7 | -------------------------------------------------------------------------------- /Compiler/source/amx/amxargs.rc: -------------------------------------------------------------------------------- 1 | #include 2 | #if defined WIN32 || defined _WIN32 || defined __WIN32__ 3 | # include 4 | #else 5 | # include 6 | #endif 7 | 8 | /* Version information 9 | * 10 | * All strings MUST have an explicit \0. See the Windows SDK documentation 11 | * for details on version information and the VERSIONINFO structure. 12 | */ 13 | #define VERSION 4 14 | #define REVISION 0 15 | #define BUILD 0 16 | #define VERSIONSTR "4.0.0\0" 17 | #define VERSIONNAME "amxArgs.dll\0" 18 | #define VERSIONDESCRIPTION "Pawn AMX: Script Arguments support\0" 19 | #define VERSIONCOMPANYNAME "ITB CompuPhase\0" 20 | #define VERSIONPRODUCTNAME "amxArgs\0" 21 | #define VERSIONCOPYRIGHT "Copyright \251 2005-2011 ITB CompuPhase\0" 22 | 23 | VS_VERSION_INFO VERSIONINFO 24 | FILEVERSION VERSION, REVISION, BUILD, 0 25 | PRODUCTVERSION VERSION, REVISION, BUILD, 0 26 | FILEFLAGSMASK 0x0000003FL 27 | FILEFLAGS 0 28 | #if defined(WIN32) 29 | FILEOS VOS__WINDOWS32 30 | #else 31 | FILEOS VOS__WINDOWS16 32 | #endif 33 | FILETYPE VFT_DLL 34 | BEGIN 35 | BLOCK "StringFileInfo" 36 | BEGIN 37 | BLOCK "040904E4" 38 | BEGIN 39 | VALUE "CompanyName", VERSIONCOMPANYNAME 40 | VALUE "FileDescription", VERSIONDESCRIPTION 41 | VALUE "FileVersion", VERSIONSTR 42 | VALUE "InternalName", VERSIONNAME 43 | VALUE "LegalCopyright", VERSIONCOPYRIGHT 44 | VALUE "OriginalFilename", VERSIONNAME 45 | VALUE "ProductName", VERSIONPRODUCTNAME 46 | VALUE "ProductVersion", VERSIONSTR 47 | END 48 | END 49 | 50 | BLOCK "VarFileInfo" 51 | BEGIN 52 | VALUE "Translation", 0x409, 1252 53 | END 54 | END 55 | -------------------------------------------------------------------------------- /Compiler/source/amx/amxaux.h: -------------------------------------------------------------------------------- 1 | /* Support routines for the Pawn Abstract Machine 2 | * 3 | * Copyright (c) ITB CompuPhase, 2003-2011 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 6 | * use this file except in compliance with the License. You may obtain a copy 7 | * of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | * 17 | * Version: $Id: amxaux.h 4523 2011-06-21 15:03:47Z thiadmer $ 18 | */ 19 | #ifndef AMXAUX_H_INCLUDED 20 | #define AMXAUX_H_INCLUDED 21 | 22 | #include "amx.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* loading and freeing programs */ 29 | size_t AMXAPI aux_ProgramSize(const char *filename); 30 | int AMXAPI aux_LoadProgram(AMX *amx, const char *filename, void *memblock); 31 | int AMXAPI aux_FreeProgram(AMX *amx); 32 | 33 | /* a readable error message from an error code */ 34 | char * AMXAPI aux_StrError(int errnum); 35 | 36 | enum { 37 | CODE_SECTION, 38 | DATA_SECTION, 39 | HEAP_SECTION, 40 | STACK_SECTION, 41 | /* ----- */ 42 | NUM_SECTIONS 43 | }; 44 | int AMXAPI aux_GetSection(const AMX *amx, int section, cell **start, size_t *size); 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif /* AMXAUX_H_INCLUDED */ 51 | -------------------------------------------------------------------------------- /Compiler/source/amx/amxcons.h: -------------------------------------------------------------------------------- 1 | #ifndef AMXCONS_H_INCLUDED 2 | #define AMXCONS_H_INCLUDED 3 | 4 | typedef struct tagFMTINFO { 5 | const cell *params; 6 | int numparams; 7 | int skip; /* number of characters to skip from the beginning */ 8 | int length; /* number of characters to print */ 9 | /* helper functions */ 10 | int (*f_putstr)(void *dest,const TCHAR *); 11 | int (*f_putchar)(void *dest,TCHAR); 12 | void *user; /* user data */ 13 | } AMX_FMTINFO; 14 | 15 | int amx_printstring(AMX *amx,cell *cstr,AMX_FMTINFO *info); 16 | 17 | #endif /* AMXCONS_H_INCLUDED */ 18 | -------------------------------------------------------------------------------- /Compiler/source/amx/amxfile.def: -------------------------------------------------------------------------------- 1 | NAME amxFile 2 | DESCRIPTION 'File I/O support library' 3 | 4 | EXPORTS 5 | amx_FileInit 6 | amx_FileCleanup 7 | -------------------------------------------------------------------------------- /Compiler/source/amx/amxgc.h: -------------------------------------------------------------------------------- 1 | /* Simple garbage collector for the Pawn Abstract Machine 2 | * 3 | * Copyright (c) ITB CompuPhase, 2004-2011 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 6 | * use this file except in compliance with the License. You may obtain a copy 7 | * of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | * 17 | * Version: $Id: amxgc.h 4523 2011-06-21 15:03:47Z thiadmer $ 18 | */ 19 | 20 | #ifndef AMXGC_H 21 | #define AMXGC_H 22 | 23 | typedef void _FAR (* GC_FREE)(cell unreferenced); 24 | enum { 25 | GC_ERR_NONE, 26 | GC_ERR_CALLBACK, /* no callback, or invalid callback */ 27 | GC_ERR_INIT, /* garbage collector not initialized (no table size) */ 28 | GC_ERR_MEMORY, /* insufficient memory to set/resize the table */ 29 | GC_ERR_PARAMS, /* parameter error */ 30 | GC_ERR_TABLEFULL, /* domain error, expression result does not fit in range */ 31 | GC_ERR_DUPLICATE, /* item is already in the table */ 32 | }; 33 | 34 | /* flags */ 35 | #define GC_AUTOGROW 1 /* gc_mark() may grow the hash table when it fills up */ 36 | 37 | int gc_setcallback(GC_FREE callback); 38 | 39 | int gc_settable(int exponent,int flags); 40 | int gc_tablestat(int *exponent,int *percentage); 41 | /* Upon return, "exponent" will hold the values passed to gc_settable(); 42 | * "percentage" is the level (in percent) that the hash table is filled 43 | * up. Either parameter may be set to NULL. 44 | */ 45 | 46 | int gc_mark(cell value); 47 | int gc_scan(AMX *amx); 48 | int gc_clean(void); 49 | 50 | #endif /* AMXGC_H */ 51 | -------------------------------------------------------------------------------- /Compiler/source/amx/amxpool.h: -------------------------------------------------------------------------------- 1 | /* Simple allocation from a memory pool, with automatic release of 2 | * least-recently used blocks (LRU blocks). 3 | * 4 | * Copyright (c) ITB CompuPhase, 2007-2011 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 7 | * use this file except in compliance with the License. You may obtain a copy 8 | * of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 14 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 15 | * License for the specific language governing permissions and limitations 16 | * under the License. 17 | * 18 | * Version: $Id: amxpool.h 37 2012-05-18 13:14:55Z thiadmer.riemersma@gmail.com $ 19 | */ 20 | #ifndef AMXPOOL_H_INCLUDED 21 | #define AMXPOOL_H_INCLUDED 22 | 23 | void amx_poolinit(void *pool, unsigned size); 24 | void *amx_poolalloc(unsigned size, int index); 25 | void amx_poolfree(void *block); 26 | void *amx_poolfind(int index); 27 | int amx_poolprotect(int index); 28 | 29 | 30 | #endif /* AMXPOOL_H_INCLUDED */ 31 | -------------------------------------------------------------------------------- /Compiler/source/amx/amxstring.def: -------------------------------------------------------------------------------- 1 | NAME amxString 2 | DESCRIPTION 'Pawn AMX: string manipulation routines' 3 | 4 | EXPORTS 5 | amx_StringInit 6 | amx_StringCleanup 7 | -------------------------------------------------------------------------------- /Compiler/source/amx/amxstring.rc: -------------------------------------------------------------------------------- 1 | #include 2 | #if defined WIN32 || defined _WIN32 || defined __WIN32__ 3 | # include 4 | #else 5 | # include 6 | #endif 7 | 8 | /* Version information 9 | * 10 | * All strings MUST have an explicit \0. See the Windows SDK documentation 11 | * for details on version information and the VERSIONINFO structure. 12 | */ 13 | #define VERSION 4 14 | #define REVISION 0 15 | #define BUILD 0 16 | #define VERSIONSTR "4.0.0\0" 17 | #define VERSIONNAME "amxString.dll\0" 18 | #define VERSIONDESCRIPTION "Pawn AMX: String manipulation routines\0" 19 | #define VERSIONCOMPANYNAME "ITB CompuPhase\0" 20 | #define VERSIONPRODUCTNAME "amxString\0" 21 | #define VERSIONCOPYRIGHT "Copyright \251 2005-2011 ITB CompuPhase\0" 22 | 23 | VS_VERSION_INFO VERSIONINFO 24 | FILEVERSION VERSION, REVISION, BUILD, 0 25 | PRODUCTVERSION VERSION, REVISION, BUILD, 0 26 | FILEFLAGSMASK 0x0000003FL 27 | FILEFLAGS 0 28 | #if defined(WIN32) 29 | FILEOS VOS__WINDOWS32 30 | #else 31 | FILEOS VOS__WINDOWS16 32 | #endif 33 | FILETYPE VFT_DLL 34 | BEGIN 35 | BLOCK "StringFileInfo" 36 | BEGIN 37 | BLOCK "040904E4" 38 | BEGIN 39 | VALUE "CompanyName", VERSIONCOMPANYNAME 40 | VALUE "FileDescription", VERSIONDESCRIPTION 41 | VALUE "FileVersion", VERSIONSTR 42 | VALUE "InternalName", VERSIONNAME 43 | VALUE "LegalCopyright", VERSIONCOPYRIGHT 44 | VALUE "OriginalFilename", VERSIONNAME 45 | VALUE "ProductName", VERSIONPRODUCTNAME 46 | VALUE "ProductVersion", VERSIONSTR 47 | END 48 | END 49 | 50 | BLOCK "VarFileInfo" 51 | BEGIN 52 | VALUE "Translation", 0x409, 1252 53 | END 54 | END 55 | -------------------------------------------------------------------------------- /Compiler/source/amx/amxtime.def: -------------------------------------------------------------------------------- 1 | NAME amxTime 2 | DESCRIPTION 'Pawn AMX: time routines' 3 | 4 | EXPORTS 5 | amx_TimeInit 6 | amx_TimeCleanup 7 | -------------------------------------------------------------------------------- /Compiler/source/amx/amxtime.rc: -------------------------------------------------------------------------------- 1 | #include 2 | #if defined WIN32 || defined _WIN32 || defined __WIN32__ 3 | # include 4 | #else 5 | # include 6 | #endif 7 | 8 | /* Version information 9 | * 10 | * All strings MUST have an explicit \0. See the Windows SDK documentation 11 | * for details on version information and the VERSIONINFO structure. 12 | */ 13 | #define VERSION 4 14 | #define REVISION 0 15 | #define BUILD 0 16 | #define VERSIONSTR "4.0.0\0" 17 | #define VERSIONNAME "amxTime.dll\0" 18 | #define VERSIONDESCRIPTION "Pawn AMX: time routines\0" 19 | #define VERSIONCOMPANYNAME "ITB CompuPhase\0" 20 | #define VERSIONPRODUCTNAME "amxTime\0" 21 | #define VERSIONCOPYRIGHT "Copyright \251 2005-2011 ITB CompuPhase\0" 22 | 23 | VS_VERSION_INFO VERSIONINFO 24 | FILEVERSION VERSION, REVISION, BUILD, 0 25 | PRODUCTVERSION VERSION, REVISION, BUILD, 0 26 | FILEFLAGSMASK 0x0000003FL 27 | FILEFLAGS 0 28 | #if defined(WIN32) 29 | FILEOS VOS__WINDOWS32 30 | #else 31 | FILEOS VOS__WINDOWS16 32 | #endif 33 | FILETYPE VFT_DLL 34 | BEGIN 35 | BLOCK "StringFileInfo" 36 | BEGIN 37 | BLOCK "040904E4" 38 | BEGIN 39 | VALUE "CompanyName", VERSIONCOMPANYNAME 40 | VALUE "FileDescription", VERSIONDESCRIPTION 41 | VALUE "FileVersion", VERSIONSTR 42 | VALUE "InternalName", VERSIONNAME 43 | VALUE "LegalCopyright", VERSIONCOPYRIGHT 44 | VALUE "OriginalFilename", VERSIONNAME 45 | VALUE "ProductName", VERSIONPRODUCTNAME 46 | VALUE "ProductVersion", VERSIONSTR 47 | END 48 | END 49 | 50 | BLOCK "VarFileInfo" 51 | BEGIN 52 | VALUE "Translation", 0x409, 1252 53 | END 54 | END 55 | -------------------------------------------------------------------------------- /Compiler/source/amx/dllmain.c: -------------------------------------------------------------------------------- 1 | /* DLL support functions for dynamically loadable extension libraries. 2 | * 3 | * Copyright (c) ITB CompuPhase, 2004-2011 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 6 | * use this file except in compliance with the License. You may obtain a copy 7 | * of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | * 17 | * Version: $Id: dllmain.c 4523 2011-06-21 15:03:47Z thiadmer $ 18 | */ 19 | 20 | #if defined _UNICODE || defined __UNICODE__ || defined UNICODE 21 | # if !defined UNICODE /* for Windows */ 22 | # define UNICODE 23 | # endif 24 | # if !defined _UNICODE /* for C library */ 25 | # define _UNICODE 26 | # endif 27 | #endif 28 | 29 | #include 30 | #include 31 | 32 | #if !defined UNUSED_PARAM 33 | #define UNUSED_PARAM(p) ((void)(p)) 34 | #endif 35 | 36 | HINSTANCE hinstDLL; 37 | 38 | /* Especially Watcom C/C++ does not like DLLs that do not have a LibMain() 39 | * set. Apparently, the start address is not set well, and some required 40 | * initializations are not done. 41 | */ 42 | #if defined __WIN32__ || defined _WIN32 || defined WIN32 43 | 44 | BOOL WINAPI DllMain(HINSTANCE hinst, DWORD dwReason, LPVOID lpRes) 45 | { 46 | UNUSED_PARAM(lpRes); 47 | switch (dwReason) { 48 | case DLL_PROCESS_ATTACH: 49 | hinstDLL=hinst; 50 | break; 51 | case DLL_PROCESS_DETACH: 52 | break; 53 | } /* switch */ 54 | return TRUE; 55 | } 56 | 57 | #else 58 | 59 | int FAR PASCAL LibMain(HINSTANCE hinst, WORD wDataSeg, WORD wHeapSize, LPSTR lpszCmdLine) 60 | { 61 | UNUSED_PARAM(wDataSeg); 62 | UNUSED_PARAM(wHeapSize); 63 | UNUSED_PARAM(lpszCmdLine); 64 | hinstDLL=hinst; 65 | return 1; 66 | } 67 | 68 | int FAR PASCAL _export WEP(int param) 69 | { 70 | UNUSED_PARAM(param); 71 | return 1; 72 | } 73 | 74 | #endif /* __WIN32__ */ 75 | 76 | -------------------------------------------------------------------------------- /Compiler/source/amx/examples/logfile.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "amx.h" 5 | 6 | class LogFile; 7 | static std::map lookup; 8 | 9 | class LogFile { 10 | public: 11 | LogFile() 12 | { 13 | f = tmpfile(); 14 | } 15 | 16 | ~LogFile() 17 | { 18 | fclose(f); 19 | } 20 | 21 | private: 22 | int write(AMX* /*amx*/, const cell params[]) 23 | { 24 | int r = 0; 25 | char *pstr; 26 | 27 | amx_StrParam_Type(amx, params[1], pstr, char*); 28 | if (pstr != NULL) 29 | r = fprintf(f, "%s", pstr); 30 | return r; 31 | } 32 | 33 | FILE *f; 34 | 35 | public: 36 | static cell n_write(AMX* amx, const cell params[]) 37 | { 38 | std::map::iterator p = lookup.find(amx); 39 | if (p != lookup.end()) 40 | return p->second->write(amx, params); 41 | return 0; 42 | } 43 | 44 | }; 45 | 46 | extern "C" 47 | int amx_LogFileInit(AMX* amx) 48 | { 49 | LogFile* lf = new LogFile; 50 | if (lf) { 51 | lookup.insert(std::make_pair(amx, lf)); 52 | 53 | static AMX_NATIVE_INFO nativelist[] = { 54 | { "write", LogFile::n_write }, 55 | { 0, 0 } /* terminator */ 56 | }; 57 | return amx_Register(amx, nativelist, -1); 58 | } /* if */ 59 | return AMX_ERR_MEMORY; 60 | } 61 | 62 | extern "C" 63 | int amx_LogFileExit(AMX* amx) 64 | { 65 | std::map::iterator p = lookup.find(amx); 66 | if (p != lookup.end()) { 67 | delete p->second; 68 | lookup.erase(p); 69 | } /* if */ 70 | return AMX_ERR_NONE; 71 | } 72 | -------------------------------------------------------------------------------- /Compiler/source/amx/examples/power.c: -------------------------------------------------------------------------------- 1 | /* This file implements two the native functions: power(value,exponent) 2 | * and sqroot(value). 3 | */ 4 | #include "amx.h" 5 | 6 | static cell n_power(AMX *amx, const cell *params) 7 | { 8 | /* power(value, exponent); 9 | * params[1] = value 10 | * params[2] = exponent 11 | */ 12 | cell result = 1; 13 | cell exponent = params[2]; 14 | while (exponent-- > 0) 15 | result *= params[1]; 16 | return result; 17 | } 18 | 19 | static cell n_sqroot(AMX *amx, const cell *params) 20 | { 21 | /* sqroot(value); 22 | * params[1] = value 23 | * This routine uses a simple successice approximation algorithm. 24 | */ 25 | cell div = params[1]; 26 | cell result = 1; 27 | while (div > result) { /* end when div == result, or just below */ 28 | div = (div + result) / 2; /* take mean value as new divisor */ 29 | result = params[1] / div; 30 | } /* while */ 31 | return div; 32 | } 33 | 34 | int amx_PowerInit(AMX *amx) 35 | { 36 | static AMX_NATIVE_INFO power_Natives[] = { 37 | { "power", n_power }, 38 | { "sqroot", n_sqroot }, 39 | { 0, 0 } /* terminator */ 40 | }; 41 | return amx_Register(amx, power_Natives, -1); 42 | } 43 | 44 | int amx_PowerCleanup(AMX *amx) 45 | { 46 | return AMX_ERR_NONE; 47 | } 48 | -------------------------------------------------------------------------------- /Compiler/source/amx/examples/prun1.c: -------------------------------------------------------------------------------- 1 | /* Command-line shell for the "Pawn" Abstract Machine. 2 | * 3 | * Copyright (c) ITB CompuPhase, 2001-2010 4 | * 5 | * This file may be freely used. No warranties of any kind. 6 | */ 7 | #include 8 | #include /* for exit() */ 9 | #include /* for memset() (on some compilers) */ 10 | #include "amx.h" 11 | #include "amxaux.c" 12 | 13 | void ErrorExit(AMX *amx, int errorcode) 14 | { 15 | printf("Run time error %d: \"%s\" on address %ld\n", 16 | errorcode, aux_StrError(errorcode), 17 | (amx != NULL) ? amx->cip : 0); 18 | exit(1); 19 | } 20 | 21 | void PrintUsage(char *program) 22 | { 23 | printf("Usage: %s \n is a compiled script.\n", program); 24 | exit(1); 25 | } 26 | 27 | int main(int argc,char *argv[]) 28 | { 29 | extern AMX_NATIVE_INFO console_Natives[]; 30 | extern AMX_NATIVE_INFO core_Natives[]; 31 | 32 | AMX amx; 33 | cell ret = 0; 34 | int err; 35 | 36 | if (argc != 2) 37 | PrintUsage(argv[0]); 38 | 39 | err = aux_LoadProgram(&amx, argv[1], NULL); 40 | if (err != AMX_ERR_NONE) 41 | ErrorExit(&amx, err); 42 | 43 | amx_Register(&amx, console_Natives, -1); 44 | err = amx_Register(&amx, core_Natives, -1); 45 | if (err) 46 | ErrorExit(&amx, err); 47 | 48 | err = amx_Exec(&amx, &ret, AMX_EXEC_MAIN); 49 | if (err) 50 | ErrorExit(&amx, err); 51 | printf("%s returns %ld\n", argv[1], (long)ret); 52 | 53 | aux_FreeProgram(&amx); 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /Compiler/source/amx/examples/prun2.c: -------------------------------------------------------------------------------- 1 | /* Command-line shell for the "Pawn" Abstract Machine. 2 | * 3 | * Copyright (c) ITB CompuPhase, 2001-2010 4 | * 5 | * This file may be freely used. No warranties of any kind. 6 | */ 7 | #include 8 | #include /* for exit() */ 9 | #include 10 | #include /* for memset() (on some compilers) */ 11 | #include "amx.h" 12 | #include "amxaux.c" 13 | 14 | void AMXAPI core_Init(void); /* two functions from AMX_CORE.C */ 15 | void AMXAPI core_Exit(void); 16 | 17 | static int abortflagged = 0; 18 | void sigabort(int sig) 19 | { 20 | abortflagged = 1; 21 | signal(sig, sigabort); /* re-install the signal handler */ 22 | } 23 | 24 | int AMXAPI aux_Monitor(AMX *amx) 25 | { 26 | /* check whether an "abort" was requested */ 27 | return abortflagged ? AMX_ERR_EXIT : AMX_ERR_NONE; 28 | } 29 | 30 | 31 | void ErrorExit(AMX *amx, int errorcode) 32 | { 33 | printf("Run time error %d: \"%s\" on address %ld\n", 34 | errorcode, aux_StrError(errorcode), 35 | (amx != NULL) ? amx->cip : 0); 36 | exit(1); 37 | } 38 | 39 | void PrintUsage(char *program) 40 | { 41 | printf("Usage: %s \n is a compiled script.\n", program); 42 | exit(1); 43 | } 44 | 45 | int main(int argc,char *argv[]) 46 | { 47 | extern AMX_NATIVE_INFO console_Natives[]; 48 | extern AMX_NATIVE_INFO core_Natives[]; 49 | 50 | AMX amx; 51 | cell ret = 0; 52 | int err; 53 | 54 | if (argc != 2) 55 | PrintUsage(argv[0]); 56 | 57 | err = aux_LoadProgram(&amx, argv[1], NULL); 58 | if (err != AMX_ERR_NONE) 59 | ErrorExit(&amx, err); 60 | 61 | amx_Register(&amx, console_Natives, -1); 62 | err = amx_Register(&amx, core_Natives, -1); 63 | if (err) 64 | ErrorExit(&amx, err); 65 | 66 | amx_SetDebugHook(&amx, aux_Monitor); 67 | signal(SIGINT, sigabort); 68 | 69 | err = amx_Exec(&amx, &ret, AMX_EXEC_MAIN); 70 | if (err) 71 | ErrorExit(&amx, err); 72 | printf("%s returns %ld\n", argv[1], (long)ret); 73 | 74 | aux_FreeProgram(&amx); 75 | return 0; 76 | } 77 | -------------------------------------------------------------------------------- /Compiler/source/amx/examples/prun4.c: -------------------------------------------------------------------------------- 1 | /* Command-line shell for the "Pawn" Abstract Machine. 2 | * 3 | * Copyright (c) ITB CompuPhase, 2001-2010 4 | * 5 | * This file may be freely used. No warranties of any kind. 6 | */ 7 | #include 8 | #include /* for exit() */ 9 | #include /* for memset() (on some compilers) */ 10 | #include "amx.h" 11 | #include "amxaux.c" 12 | 13 | 14 | void ErrorExit(AMX *amx, int errorcode) 15 | { 16 | printf("Run time error %d: \"%s\" on address %ld\n", 17 | errorcode, aux_StrError(errorcode), 18 | (amx != NULL) ? amx->cip : 0); 19 | exit(1); 20 | } 21 | 22 | void PrintUsage(char *program) 23 | { 24 | printf("Usage: %s \n", program); 25 | exit(1); 26 | } 27 | 28 | int main(int argc, char *argv[]) 29 | { 30 | extern int AMXAPI amx_ConsoleInit(AMX *amx); 31 | extern int AMXAPI amx_ConsoleCleanup(AMX *amx); 32 | extern int AMXAPI amx_CoreInit(AMX *amx); 33 | extern int AMXAPI amx_CoreCleanup(AMX *amx); 34 | 35 | size_t memsize; 36 | void *program; 37 | AMX amx; 38 | int index, err; 39 | cell *address; 40 | char output[128]; 41 | 42 | if (argc != 4) 43 | PrintUsage(argv[0]); 44 | if ((memsize = aux_ProgramSize(argv[1])) == 0) 45 | PrintUsage(argv[0]); 46 | 47 | program = malloc(memsize); 48 | if (program == NULL) 49 | ErrorExit(NULL, AMX_ERR_MEMORY); 50 | 51 | err = aux_LoadProgram(&amx, argv[1], program); 52 | if (err) 53 | ErrorExit(&amx, err); 54 | 55 | amx_ConsoleInit(&amx); 56 | err = amx_CoreInit(&amx); 57 | if (err) 58 | ErrorExit(&amx, err); 59 | 60 | err = amx_FindPublic(&amx, argv[2], &index); 61 | if (err) 62 | ErrorExit(&amx, err); 63 | 64 | err = amx_PushString(&amx, &address, argv[3], 0, 0); 65 | if (err) 66 | ErrorExit(&amx, err); 67 | 68 | err = amx_Exec(&amx, NULL, index); 69 | if (err) 70 | ErrorExit(&amx, err); 71 | 72 | amx_GetString(output, address, 0, sizeof output); 73 | amx_Release(&amx, address); 74 | printf("%s returns %s\n", argv[1], output); 75 | 76 | amx_ConsoleCleanup(&amx); 77 | amx_CoreCleanup(&amx); 78 | amx_Cleanup(&amx); 79 | free(program); 80 | return 0; 81 | } 82 | -------------------------------------------------------------------------------- /Compiler/source/amx/fpattern.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PetteriAimonen/QuadPawn/704ea78c61738574bb62407f503fc49a13ffb405/Compiler/source/amx/fpattern.h -------------------------------------------------------------------------------- /Compiler/source/amx/keeloq.c: -------------------------------------------------------------------------------- 1 | /*\ 2 | * Corrected KeeLoq Encryption and Decryption functions by Ruptor. 3 | * Use at your own risk! This source is not copyrighted. 4 | * Encoder encrypts an all-0 block, decoder decrypts it. 5 | * KeeLoq cipher encrypts 32-bit blocks with 64-bit keys. 6 | * Key is XORed with a 32-bit IV incremented on each use. 7 | * See http://www.keeloq.boom.ru/decryption.pdf for more details. 8 | * KeeLoq algorithm itself is not patented. 9 | \*/ 10 | #include "amx.h" 11 | 12 | #define KeeLoq_NLF 0x3A5C742E 13 | #define bit(x,n) (((x)>>(n))&1) 14 | #define g5(x,a,b,c,d,e) (bit(x,a)+bit(x,b)*2+bit(x,c)*4+bit(x,d)*8+bit(x,e)*16) 15 | 16 | uint32_t KeeLoq_Encrypt (const uint32_t data, const uint64_t key) 17 | { 18 | uint32_t x = data, r; 19 | 20 | for (r = 0; r < 528; r++) 21 | { 22 | x = (x>>1)^((bit(x,0)^bit(x,16)^(uint32_t)bit(key,r&63)^bit(KeeLoq_NLF,g5(x,1,9,20,26,31)))<<31); 23 | } 24 | return x; 25 | } 26 | 27 | uint32_t KeeLoq_Decrypt (const uint32_t data, const uint64_t key) 28 | { 29 | uint32_t x = data, r; 30 | 31 | for (r = 0; r < 528; r++) 32 | { 33 | x = (x<<1)^bit(x,31)^bit(x,15)^(uint32_t)bit(key,(15-r)&63)^bit(KeeLoq_NLF,g5(x,0,8,19,25,30)); 34 | } 35 | return x; 36 | } 37 | -------------------------------------------------------------------------------- /Compiler/source/amx/keeloq.h: -------------------------------------------------------------------------------- 1 | /* see keeloq.c for information */ 2 | uint32_t KeeLoq_Encrypt (const uint32_t data, const uint64_t key); 3 | uint32_t KeeLoq_Decrypt (const uint32_t data, const uint64_t key); 4 | -------------------------------------------------------------------------------- /Compiler/source/amx/minGlue.h: -------------------------------------------------------------------------------- 1 | /* Glue functions for the minIni library, based on the C/C++ stdio library 2 | * 3 | * Or better said: this file contains macros that maps the function interface 4 | * used by minIni to the standard C/C++ file I/O functions. 5 | * 6 | * Copyright (c) ITB CompuPhase, 2008-2010 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 9 | * use this file except in compliance with the License. You may obtain a copy 10 | * of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 16 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 17 | * License for the specific language governing permissions and limitations 18 | * under the License. 19 | * 20 | * Version: $Id: minGlue.h 4234 2010-03-30 09:04:26Z thiadmer $ 21 | */ 22 | 23 | /* map required file I/O to the standard C library */ 24 | #include 25 | #define ini_openread(filename,file) ((*(file) = fopen((filename),"rt")) != NULL) 26 | #define ini_openwrite(filename,file) ((*(file) = fopen((filename),"wt")) != NULL) 27 | #define ini_close(file) fclose(*(file)) 28 | #define ini_read(buffer,size,file) fgets((buffer),(size),*(file)) 29 | #define ini_write(buffer,file) fputs((buffer),*(file)) 30 | #define ini_rename(source,dest) rename((source),(dest)) 31 | #define ini_remove(filename) remove(filename) 32 | #define ini_rewind(file) rewind(*(file)) 33 | -------------------------------------------------------------------------------- /Compiler/source/amx/pawndbg.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PetteriAimonen/QuadPawn/704ea78c61738574bb62407f503fc49a13ffb405/Compiler/source/amx/pawndbg.c -------------------------------------------------------------------------------- /Compiler/source/amx/term_ga.h: -------------------------------------------------------------------------------- 1 | /* Simple terminal using GraphApp 2 | * 3 | * Copyright (c) ITB CompuPhase, 2004-2011 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 6 | * use this file except in compliance with the License. You may obtain a copy 7 | * of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | * 17 | * Version: $Id: term_ga.h 4523 2011-06-21 15:03:47Z thiadmer $ 18 | */ 19 | 20 | #if !defined TERMGA_H_INCLUDED 21 | #define TERMGA_H_INCLUDED 22 | 23 | #if defined _UNICODE || defined __UNICODE__ || defined UNICODE 24 | # if !defined UNICODE /* for Windows */ 25 | # define UNICODE 26 | # endif 27 | # if !defined _UNICODE /* for C library */ 28 | # define _UNICODE 29 | # endif 30 | #endif 31 | 32 | #if defined _UNICODE 33 | # include 34 | #elif !defined __T 35 | typedef char TCHAR; 36 | # define __T(string) string 37 | # define _tcschr strchr 38 | # define _tcscpy strcpy 39 | # define _tcsdup strdup 40 | # define _tcslen strlen 41 | # define _stprintf sprintf 42 | # define _vstprintf vsprintf 43 | #endif 44 | 45 | #ifdef __cplusplus 46 | extern "C" { 47 | #endif 48 | 49 | int createconsole(int argc, char *argv[]); 50 | int deleteconsole(void); 51 | 52 | int amx_printf(const TCHAR*,...); 53 | int amx_putstr(const TCHAR*); 54 | int amx_putchar(int); 55 | int amx_fflush(void); 56 | int amx_kbhit(void); 57 | int amx_getch(void); 58 | TCHAR* amx_gets(TCHAR*,int); 59 | int amx_termctl(int,int); 60 | void amx_clrscr(void); 61 | void amx_clreol(void); 62 | void amx_gotoxy(int x,int y); 63 | void amx_wherexy(int *x,int *y); 64 | unsigned amx_setattr(int foregr,int backgr,int highlight); 65 | void amx_console(int columns, int lines, int flags); 66 | 67 | #ifdef __cplusplus 68 | } 69 | #endif 70 | 71 | #endif /* TERMGA_H_INCLUDED */ 72 | -------------------------------------------------------------------------------- /Compiler/source/compiler/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #build file for CMake, see http://www.cmake.org/ 2 | 3 | CMAKE_MINIMUM_REQUIRED(VERSION 2.6) 4 | 5 | PROJECT(pawnc) 6 | 7 | # check for optional include files 8 | INCLUDE(${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake) 9 | CHECK_INCLUDE_FILE("unistd.h" HAVE_UNISTD_H) 10 | IF(HAVE_UNISTD_H) 11 | ADD_DEFINITIONS(-DHAVE_UNISTD_H) 12 | ENDIF(HAVE_UNISTD_H) 13 | CHECK_INCLUDE_FILE("inttypes.h" HAVE_INTTYPES_H) 14 | IF(HAVE_INTTYPES_H) 15 | ADD_DEFINITIONS(-DHAVE_INTTYPES_H) 16 | ENDIF(HAVE_INTTYPES_H) 17 | CHECK_INCLUDE_FILE("stdint.h" HAVE_STDINT_H) 18 | IF(HAVE_STDINT_H) 19 | ADD_DEFINITIONS(-DHAVE_STDINT_H) 20 | ENDIF(HAVE_STDINT_H) 21 | CHECK_INCLUDE_FILE("alloca.h" HAVE_ALLOCA_H) 22 | IF(HAVE_ALLOCA_H) 23 | ADD_DEFINITIONS(-DHAVE_ALLOCA_H) 24 | ENDIF(HAVE_ALLOCA_H) 25 | 26 | IF(UNIX) 27 | ADD_DEFINITIONS(-DENABLE_BINRELOC -D_GNU_SOURCE) 28 | INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../linux) 29 | LINK_LIBRARIES(pthread m) #CMake adds the "lib" prefix, so "pthread" becomes "libpthread" 30 | ENDIF(UNIX) 31 | IF(WIN32) 32 | ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS) 33 | ENDIF(WIN32) 34 | 35 | # The Pawn compiler 36 | SET(PAWNCC_SRCS sc1.c sc2.c sc3.c sc4.c sc5.c sc6.c sc7.c 37 | scexpand.c sci18n.c sclist.c scmemfil.c scstate.c scvars.c 38 | lstring.c memfile.c 39 | ${CMAKE_CURRENT_SOURCE_DIR}/../amx/keeloq.c) 40 | IF(WIN32) 41 | SET(PAWNCC_SRCS ${PAWNCC_SRCS} pawncc.rc) 42 | ENDIF(WIN32) 43 | IF(UNIX) 44 | SET(PAWNCC_SRCS ${PAWNCC_SRCS} ${CMAKE_CURRENT_SOURCE_DIR}/../linux/binreloc.c) 45 | ENDIF(UNIX) 46 | ADD_EXECUTABLE(pawncc ${PAWNCC_SRCS}) 47 | 48 | 49 | # Simple Pawn disassembler 50 | SET(PAWNDISASM_SRCS pawndisasm.c) 51 | ADD_EXECUTABLE(pawndisasm ${PAWNDISASM_SRCS}) 52 | -------------------------------------------------------------------------------- /Compiler/source/compiler/libpawnc.def: -------------------------------------------------------------------------------- 1 | LIBRARY PAWNC 2 | 3 | EXPORTS Compile 4 | pc_compile 5 | pc_addconstant 6 | pc_addtag 7 | pc_enablewarning 8 | -------------------------------------------------------------------------------- /Compiler/source/compiler/libpawnc.def.borland: -------------------------------------------------------------------------------- 1 | LIBRARY PAWNC 2 | DESCRIPTION 'Pawn compiler' 3 | 4 | EXPORTS Compile 5 | pc_compile = _pc_compile 6 | pc_addconstant = _pc_addconstant 7 | pc_addtag = _pc_addtag 8 | pc_enablewarning = _pc_enablewarning 9 | -------------------------------------------------------------------------------- /Compiler/source/compiler/libpawnc.lbc: -------------------------------------------------------------------------------- 1 | ++_Compile@16 .libpawnc .Compile 2 | #++pc_compile .libpawnc .pc_compile 3 | #++pc_addconstant .libpawnc .pc_addconstant 4 | #++pc_addtag .libpawnc .pc_addtag 5 | #++pc_enablewarning .libpawnc .pc_enablewarning 6 | -------------------------------------------------------------------------------- /Compiler/source/compiler/libpawnc.rc: -------------------------------------------------------------------------------- 1 | #include 2 | #if defined WIN32 || defined _WIN32 || defined __WIN32__ 3 | # include 4 | #else 5 | # include 6 | #endif 7 | #include "svnrev.h" 8 | 9 | AppIcon ICON "../bin/pawn.ico" 10 | 11 | /* Version information 12 | * 13 | * All strings MUST have an explicit \0. See the Windows SDK documentation 14 | * for details on version information and the VERSIONINFO structure. 15 | */ 16 | #define VERSION 3 17 | #define REVISION 3 18 | #define BUILD SVN_REV 19 | #define VERSIONSTR "3.3." SVN_REVSTR "\0" 20 | #if defined PAWNCC 21 | #define VERSIONNAME "pawncc.exe\0" 22 | #define VERSIONDESCRIPTION "Pawn Compiler\0" 23 | #define VERSIONPRODUCTNAME "pawncc\0" 24 | #elif defined PAWNRUN 25 | #define VERSIONNAME "pawnrun.exe\0" 26 | #define VERSIONDESCRIPTION "Pawn run-time\0" 27 | #define VERSIONPRODUCTNAME "pawnrun\0" 28 | #else 29 | #define VERSIONNAME "libpawnc.dll\0" 30 | #define VERSIONDESCRIPTION "Pawn Compiler library\0" 31 | #define VERSIONPRODUCTNAME "libpawnc\0" 32 | #endif 33 | #define VERSIONCOMPANYNAME "ITB CompuPhase\0" 34 | #define VERSIONCOPYRIGHT "Copyright \251 1998-2009 ITB CompuPhase\0" 35 | 36 | VS_VERSION_INFO VERSIONINFO 37 | FILEVERSION VERSION, REVISION, BUILD, 0 38 | PRODUCTVERSION VERSION, REVISION, BUILD, 0 39 | FILEFLAGSMASK 0x0000003FL 40 | FILEFLAGS 0 41 | #if defined(WIN32) 42 | FILEOS VOS__WINDOWS32 43 | #else 44 | FILEOS VOS__WINDOWS16 45 | #endif 46 | FILETYPE VFT_DLL 47 | BEGIN 48 | BLOCK "StringFileInfo" 49 | BEGIN 50 | BLOCK "040904E4" 51 | BEGIN 52 | VALUE "CompanyName", VERSIONCOMPANYNAME 53 | VALUE "FileDescription", VERSIONDESCRIPTION 54 | VALUE "FileVersion", VERSIONSTR 55 | VALUE "InternalName", VERSIONNAME 56 | VALUE "LegalCopyright", VERSIONCOPYRIGHT 57 | VALUE "OriginalFilename", VERSIONNAME 58 | VALUE "ProductName", VERSIONPRODUCTNAME 59 | VALUE "ProductVersion", VERSIONSTR 60 | END 61 | END 62 | 63 | BLOCK "VarFileInfo" 64 | BEGIN 65 | VALUE "Translation", 0x409, 1252 66 | END 67 | END 68 | -------------------------------------------------------------------------------- /Compiler/source/compiler/lstring.h: -------------------------------------------------------------------------------- 1 | /* prototypes for strlcpy() and strlcat() */ 2 | 3 | #include 4 | 5 | #if defined __WATCOMC__ && __WATCOMC__ >= 1240 6 | /* OpenWatcom introduced BSD "safe string functions" with version 1.4 */ 7 | #define HAVE_SAFESTR 8 | #endif 9 | 10 | #if !defined HAVE_SAFESTR 11 | 12 | size_t 13 | strlcpy(char *dst, const char *src, size_t siz); 14 | 15 | size_t 16 | strlcat(char *dst, const char *src, size_t siz); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /Compiler/source/compiler/memfile.h: -------------------------------------------------------------------------------- 1 | /* Implementation of a file functions interface for reading/writing into 2 | * memory. 3 | * 4 | * Copyright (c) faluco / http://www.amxmodx.org/, 2006 5 | * Version: $Id: memfile.h 4611 2011-12-05 17:46:53Z thiadmer $ 6 | */ 7 | 8 | #ifndef _INCLUDE_MEMFILE_H 9 | #define _INCLUDE_MEMFILE_H 10 | 11 | typedef struct memfile_s 12 | { 13 | char *name; 14 | char *base; 15 | size_t offs; 16 | size_t usedoffs; 17 | size_t size; 18 | } memfile_t; 19 | 20 | memfile_t *memfile_creat(const char *name, size_t init); 21 | void memfile_destroy(memfile_t *mf); 22 | void memfile_seek(memfile_t *mf, long seek); 23 | int memfile_write(memfile_t *mf, const void *buffer, size_t size); 24 | size_t memfile_read(memfile_t *mf, void *buffer, size_t maxsize); 25 | size_t memfile_tell(const memfile_t *mf); 26 | 27 | #endif //_INCLUDE_MEMFILE_H 28 | -------------------------------------------------------------------------------- /Compiler/source/compiler/pawncc.c: -------------------------------------------------------------------------------- 1 | /* Pawn compiler driver 2 | * 3 | * Pawn is a scripting language system consisting of a compiler and an 4 | * abstract machine, for building and running programs in the Pawn language. 5 | * 6 | * Copyright (c) ITB CompuPhase, 2006-2011 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 9 | * use this file except in compliance with the License. You may obtain a copy 10 | * of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 16 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 17 | * License for the specific language governing permissions and limitations 18 | * under the License. 19 | * 20 | * Version: $Id: pawncc.c 4523 2011-06-21 15:03:47Z thiadmer $ 21 | */ 22 | #include "sc.h" 23 | 24 | int main(int argc, char *argv[]) 25 | { 26 | return pc_compile(argc,argv); 27 | } 28 | -------------------------------------------------------------------------------- /Compiler/source/compiler/pawncc.def: -------------------------------------------------------------------------------- 1 | NAME PAWNCC 2 | DESCRIPTION 'Pawn compiler' 3 | -------------------------------------------------------------------------------- /Compiler/source/compiler/pawncc.def.borland: -------------------------------------------------------------------------------- 1 | NAME PAWNCC 2 | DESCRIPTION 'Pawn compiler' 3 | 4 | IMPORTS 5 | _pc_compile = pawnc.pc_compile 6 | -------------------------------------------------------------------------------- /Compiler/source/compiler/pawncc.rc: -------------------------------------------------------------------------------- 1 | #include 2 | #if defined WIN32 || defined _WIN32 || defined __WIN32__ 3 | # include 4 | #else 5 | # include 6 | #endif 7 | #include "svnrev.h" 8 | 9 | AppIcon ICON "../bin/pawn.ico" 10 | 11 | /* Version information 12 | * 13 | * All strings MUST have an explicit \0. See the Windows SDK documentation 14 | * for details on version information and the VERSIONINFO structure. 15 | */ 16 | #define VERSION 4 17 | #define REVISION 0 18 | #define BUILD SVN_REV 19 | #define VERSIONSTR "4.0." SVN_REVSTR "\0" 20 | #if defined PAWNCC 21 | #define VERSIONNAME "pawncc.exe\0" 22 | #define VERSIONDESCRIPTION "Pawn Compiler\0" 23 | #define VERSIONPRODUCTNAME "pawncc\0" 24 | #elif defined PAWNRUN 25 | #define VERSIONNAME "pawnrun.exe\0" 26 | #define VERSIONDESCRIPTION "Pawn run-time\0" 27 | #define VERSIONPRODUCTNAME "pawnrun\0" 28 | #else 29 | #define VERSIONNAME "pawn\0" 30 | #define VERSIONDESCRIPTION "Pawn Compiler\0" 31 | #define VERSIONPRODUCTNAME "pawn\0" 32 | #endif 33 | #define VERSIONCOMPANYNAME "CompuPhase\0" 34 | #define VERSIONCOPYRIGHT "Copyright \251 1998-2011 CompuPhase\0" 35 | 36 | VS_VERSION_INFO VERSIONINFO 37 | FILEVERSION VERSION, REVISION, BUILD, 0 38 | PRODUCTVERSION VERSION, REVISION, BUILD, 0 39 | FILEFLAGSMASK 0x0000003FL 40 | FILEFLAGS 0 41 | #if defined(WIN32) 42 | FILEOS VOS__WINDOWS32 43 | #else 44 | FILEOS VOS__WINDOWS16 45 | #endif 46 | FILETYPE VFT_DLL 47 | BEGIN 48 | BLOCK "StringFileInfo" 49 | BEGIN 50 | BLOCK "040904E4" 51 | BEGIN 52 | VALUE "CompanyName", VERSIONCOMPANYNAME 53 | VALUE "FileDescription", VERSIONDESCRIPTION 54 | VALUE "FileVersion", VERSIONSTR 55 | VALUE "InternalName", VERSIONNAME 56 | VALUE "LegalCopyright", VERSIONCOPYRIGHT 57 | VALUE "OriginalFilename", VERSIONNAME 58 | VALUE "ProductName", VERSIONPRODUCTNAME 59 | VALUE "ProductVersion", VERSIONSTR 60 | END 61 | END 62 | 63 | BLOCK "VarFileInfo" 64 | BEGIN 65 | VALUE "Translation", 0x409, 1252 66 | END 67 | END 68 | -------------------------------------------------------------------------------- /Compiler/source/compiler/scexpand.c: -------------------------------------------------------------------------------- 1 | /* expand.c -- Byte Pair Encoding decompression */ 2 | /* Copyright 1996 Philip Gage */ 3 | 4 | /* Byte Pair Compression appeared in the September 1997 5 | * issue of C/C++ Users Journal. The original source code 6 | * may still be found at the web site of the magazine 7 | * (www.cuj.com). 8 | * 9 | * The decompressor has been modified by me (Thiadmer 10 | * Riemersma) to accept a string as input, instead of a 11 | * complete file. 12 | */ 13 | #include 14 | #include 15 | #include "sc.h" 16 | 17 | #define STACKSIZE 16 18 | 19 | SC_FUNC int strexpand(char *dest, unsigned char *source, int maxlen, unsigned char pairtable[128][2]) 20 | { 21 | unsigned char stack[STACKSIZE]; 22 | short c, top = 0; 23 | int len; 24 | 25 | assert(maxlen > 0); 26 | len = 1; /* already 1 byte for '\0' */ 27 | for (;;) { 28 | 29 | /* Pop byte from stack or read byte from the input string */ 30 | if (top) 31 | c = stack[--top]; 32 | else if ((c = *(unsigned char *)source++) == '\0') 33 | break; 34 | 35 | /* Push pair on stack or output byte to the output string */ 36 | if (c > 127) { 37 | assert(top+2 <= STACKSIZE); 38 | stack[top++] = pairtable[c-128][1]; 39 | stack[top++] = pairtable[c-128][0]; 40 | } 41 | else { 42 | len++; 43 | if (maxlen > 1) { /* reserve one byte for the '\0' */ 44 | *dest++ = (char)c; 45 | maxlen--; 46 | } 47 | } 48 | } 49 | *dest = '\0'; 50 | return len; /* return number of bytes decoded */ 51 | } 52 | 53 | #if 0 /*for testing*/ 54 | #include "sc5.scp" 55 | 56 | int main (int argc, char **argv) 57 | { 58 | int i; 59 | char str[128]; 60 | 61 | for (i=0; i<58; i++) { 62 | strexpand(str, errmsg[i], sizeof str, SCPACK_TABLE); 63 | printf("%s", str); 64 | } /* for */ 65 | return 0; 66 | } 67 | #endif 68 | 69 | -------------------------------------------------------------------------------- /Compiler/source/compiler/sclist.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PetteriAimonen/QuadPawn/704ea78c61738574bb62407f503fc49a13ffb405/Compiler/source/compiler/sclist.c -------------------------------------------------------------------------------- /Compiler/source/compiler/scstub.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | static char filename[] = "pccdos.exe"; 6 | 7 | int main(int argc, char *argv[]) 8 | { 9 | int result; 10 | 11 | /* build a command line to pass on to the "DOS" program */ 12 | char path[80], *ptr; 13 | strcpy(path,argv[0]); 14 | ptr=strrchr(path,'\\'); 15 | if (ptr==NULL) 16 | ptr=strchr(path,':'); 17 | if (ptr==NULL) { 18 | strcpy(path,filename); 19 | } else { 20 | strcpy(ptr+1,filename); 21 | } /* if */ 22 | 23 | /* launch the DOS version of the tool */ 24 | result=execv(path,argv); 25 | if (result==-1) 26 | printf("Error launching '%s'\n",path); 27 | return result; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /Compiler/source/compiler/svnrev.h: -------------------------------------------------------------------------------- 1 | /* This file was generated by the "svnrev" utility 2 | * (http://www.compuphase.com/svnrev.htm). 3 | * You should not modify it manually, as it may be re-generated. 4 | * 5 | * $Revision: 4611$ 6 | * $Date: 2011-12-05$ 7 | */ 8 | 9 | #if !defined SVN_REV_H 10 | #define SVN_REV_H 11 | 12 | #define SVN_REV 4611 13 | #define SVN_REVSTR "4611" 14 | #define SVN_REVDATE "2011-12-05" 15 | #define SVN_REVSTAMP 20111205L 16 | #define SVN_REVMODIFIED 0 17 | 18 | #endif /* SVN_REV_H */ 19 | -------------------------------------------------------------------------------- /Compiler/source/linux/getch.h: -------------------------------------------------------------------------------- 1 | /* Extremely inefficient but portable POSIX getch(), see getch.c */ 2 | #ifndef GETCH_H 3 | #define GETCH_H 4 | 5 | #if defined __cplusplus 6 | extern "C" { 7 | #endif 8 | int getch(void); 9 | int kbhit(void); 10 | 11 | #if defined __cplusplus 12 | } 13 | #endif 14 | 15 | #endif /* GETCH_H */ 16 | -------------------------------------------------------------------------------- /Compiler/source/linux/sclinux.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Things needed to compile under linux. 3 | * 4 | * Should be reworked totally to use GNU's 'configure' 5 | */ 6 | #ifndef SCLINUX_H 7 | #define SCLINUX_H 8 | 9 | /* getchar() is not a 'cool' replacement for MSDOS getch: Linux/unix depends on the features activated or not about the 10 | * controlling terminal's tty. This means that ioctl(2) calls must be performed, for instance to have the controlling 11 | * terminal tty's in 'raw' mode, if we want to be able to fetch a single character. This also means that everything must 12 | * be put back correctly when the function ends. See GETCH.C for an implementation. 13 | * 14 | * For interactive use of PawnRun/PawnDbg if would be much better to use GNU's readline package: the user would be able to 15 | * have a complete emacs/vi like line editing system. 16 | */ 17 | #if !defined getch && !defined kbhit 18 | #include "getch.h" 19 | #endif 20 | 21 | #define stricmp(a,b) strcasecmp(a,b) 22 | #define strnicmp(a,b,c) strncasecmp(a,b,c) 23 | 24 | /* 25 | * WinWorld wants '\'. Unices do not. 26 | */ 27 | #define DIRECTORY_SEP_CHAR '/' 28 | #define DIRECTORY_SEP_STR "/" 29 | 30 | /* 31 | * SC assumes that a computer is Little Endian unless told otherwise. It uses 32 | * (and defines) the macros BYTE_ORDER and BIG_ENDIAN. 33 | * For Linux, we must overrule these settings with those defined in glibc. 34 | */ 35 | #if !defined __BYTE_ORDER 36 | # include 37 | #endif 38 | 39 | #if defined __OpenBSD__ || defined __FreeBSD__ 40 | # define __BYTE_ORDER BYTE_ORDER 41 | # define __LITTLE_ENDIAN LITTLE_ENDIAN 42 | # define __BIG_ENDIAN BIG_ENDIAN 43 | #endif 44 | 45 | #if !defined __BYTE_ORDER 46 | # error "Can't figure computer byte order (__BYTE_ORDER macro not found)" 47 | #endif 48 | 49 | #endif /* SCLINUX_H */ 50 | -------------------------------------------------------------------------------- /Compiler/source/macosx/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PetteriAimonen/QuadPawn/704ea78c61738574bb62407f503fc49a13ffb405/Compiler/source/macosx/.DS_Store -------------------------------------------------------------------------------- /Compiler/source/macosx/pawnmacosx.h: -------------------------------------------------------------------------------- 1 | /* 2 | * pawnmacosx.h 3 | * 4 | * Common include file for Mac OS X Pawn build under Xcode. 5 | * 6 | * Copyright (c) ITB CompuPhase, 2005 7 | * 8 | * This software is provided "as-is", without any express or implied warranty. 9 | * In no event will the authors be held liable for any damages arising from 10 | * the use of this software. 11 | * 12 | * Permission is granted to anyone to use this software for any purpose, 13 | * including commercial applications, and to alter it and redistribute it 14 | * freely, subject to the following restrictions: 15 | * 16 | * 1. The origin of this software must not be misrepresented; you must not 17 | * claim that you wrote the original software. If you use this software in 18 | * a product, an acknowledgment in the product documentation would be 19 | * appreciated but is not required. 20 | * 2. Altered source versions must be plainly marked as such, and must not be 21 | * misrepresented as being the original software. 22 | * 3. This notice may not be removed or altered from any source distribution. 23 | * 24 | * Created by Allen Cronce on 06-Aug-2005. 25 | * 26 | */ 27 | 28 | #define MACOS 29 | 30 | #if __ppc__ || __ppc64__ 31 | # define BYTE_ORDER BIG_ENDIAN 32 | #elif __i386__ 33 | # define BYTE_ORDER LITTLE_ENDIAN 34 | #else 35 | # error Unknown endian! 36 | #endif 37 | 38 | #define HAVE_STDINT_H 39 | #define stricmp strcasecmp 40 | #define strnicmp strncasecmp 41 | 42 | #define ANSITERM 43 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | ----------------------------------------------- 2 | The following files are under the BSD license: 3 | 4 | 1. Files under the Programs folder, unless indicated otherwise by 5 | comments in the beginning of the file. 6 | 2. Files under Compiler/include 7 | 3. Files directly under Runtime folder, but excluding the subdirectories 8 | which contain third-party modules. 9 | 10 | Copyright (c) 2011 Petteri Aimonen 11 | 12 | Redistribution and use in source and binary forms, with or without 13 | modification, are permitted provided that the following conditions are met: 14 | 15 | 1. Redistributions of source code must retain the above copyright 16 | notice, this list of conditions and the following disclaimer. 17 | 2. Redistributions in binary form must reproduce the above copyright notice, 18 | this list of conditions and the following disclaimer in the documentation 19 | and/or other materials provided with the distribution. 20 | 21 | ----------------------------------------------------- 22 | The following third-party components have their own 23 | licenses. Any changes to these third-party modules are 24 | under the same license as the module. 25 | 26 | 1. Pawn interpreter and compiler (Runtime/amx, Compiler/source) 27 | Apache license with exception clause allowing unrestricted 28 | distribution of binaries under any license. 29 | See http://www.compuphase.com/pawn/pawn.htm for details. 30 | 31 | 2. libfixmath library (Runtime/libfixmath), under MIT license. 32 | 33 | 3. Baselibc library (Runtime/baselibc), under GPL license. 34 | 35 | 4. Fatfs library (Runtime/fatfs), no restriction on use. 36 | 37 | 5. STM32 header files 38 | 39 | 6. DSO Quad BIOS.h 40 | -------------------------------------------------------------------------------- /Programs/LOGIC.FPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PetteriAimonen/QuadPawn/704ea78c61738574bb62407f503fc49a13ffb405/Programs/LOGIC.FPG -------------------------------------------------------------------------------- /Programs/Makefile: -------------------------------------------------------------------------------- 1 | PAWNCC = ../Compiler/bin/pawncc 2 | SRCS = $(wildcard *.pawn) 3 | OBJS = $(SRCS:.pawn=.amx) 4 | 5 | all: $(OBJS) 6 | 7 | clean: 8 | rm -rf $(OBJS) 9 | 10 | %.amx: %.pawn ../Compiler/include/*.inc 11 | $(PAWNCC) -d2 -v2 -V1 $< 12 | 13 | -------------------------------------------------------------------------------- /Programs/TESTFPGA.BIN: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PetteriAimonen/QuadPawn/704ea78c61738574bb62407f503fc49a13ffb405/Programs/TESTFPGA.BIN -------------------------------------------------------------------------------- /Programs/advvolt.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PetteriAimonen/QuadPawn/704ea78c61738574bb62407f503fc49a13ffb405/Programs/advvolt.amx -------------------------------------------------------------------------------- /Programs/beeper.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PetteriAimonen/QuadPawn/704ea78c61738574bb62407f503fc49a13ffb405/Programs/beeper.amx -------------------------------------------------------------------------------- /Programs/beeper.pawn: -------------------------------------------------------------------------------- 1 | /* This program beeps when a positive voltage > 0.5 volt is applied to the Ch A 2 | * input. It also gives a 1V output on waveout, so it can be used to check 3 | * conductivity of e.g. PCB traces. 4 | */ 5 | 6 | #include 7 | #include 8 | 9 | new Fixed: threshold; 10 | new Fixed: output_voltage; 11 | new volume; 12 | new beep_freq; 13 | 14 | configure(bool: load_only = false) 15 | { 16 | start_config("beeper.ini", load_only); 17 | while (do_config()) 18 | { 19 | config_fixed("threshold", "Voltage threshold", threshold, 20 | FIX(0.5), FIX(0.1), FIX(0.1), FIX(10.0)); 21 | config_fixed("output_voltage", "Waveout voltage", output_voltage, 22 | FIX(1.0), FIX(0.1), FIX(0.1), FIX(10.0)); 23 | config_integer("volume", "Beep volume", volume, 24 | 10, 0, 100); 25 | config_integer("beep_freq", "Beep frequency", beep_freq, 26 | 500, 100, 5000); 27 | } 28 | } 29 | 30 | main() 31 | { 32 | configure(true); 33 | 34 | clear_screen(); 35 | draw_menubar("", "", "Config", "Quit"); 36 | 37 | load_calibration(); 38 | 39 | wavein_samplerate(100000); 40 | wavein_settrigger(Trig_Always); 41 | config_chA(ADC_DC, ADC_1V); 42 | 43 | while (!get_keys(BUTTON4)) 44 | { 45 | if (get_keys(BUTTON3)) 46 | { 47 | configure(); 48 | 49 | clear_screen(); 50 | draw_menubar("", "", "Config", "Quit"); 51 | } 52 | 53 | waveout_voltage(output_voltage); 54 | 55 | new Fixed: avgA; 56 | 57 | wavein_start(); 58 | wavein_aggregate(.avgA = avgA, .count = 100); 59 | 60 | avgA = get_voltage(Ch_A, avgA); 61 | 62 | new buf{10}; 63 | buf = strf(avgA, 1); 64 | strcat(buf, " V"); 65 | strpad(buf, 8); 66 | draw_text(strjoin("Voltage: ", buf), 67 | 100, 100, .fg = green, .bg = black); 68 | 69 | if (avgA > FIX(0.5)) 70 | { 71 | beep(10, beep_freq, volume); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Programs/calibrat.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PetteriAimonen/QuadPawn/704ea78c61738574bb62407f503fc49a13ffb405/Programs/calibrat.amx -------------------------------------------------------------------------------- /Programs/charmap.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PetteriAimonen/QuadPawn/704ea78c61738574bb62407f503fc49a13ffb405/Programs/charmap.amx -------------------------------------------------------------------------------- /Programs/charmap.pawn: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | main() 4 | { 5 | // 32 characters on each row, 8 rows. 6 | println(" 0123456789ABCDEF 0123456789ABCDEF"); 7 | 8 | for (new i = 0; i < 8; i++) 9 | { 10 | print(hex(i * 2)); 11 | print(" "); 12 | 13 | for (new j = 0; j < 32; j++) 14 | { 15 | new buf{2} = {0,0}; 16 | buf{0} = i * 32 + j; 17 | 18 | if (buf{0} == '\n' || buf{0} == '\r') 19 | buf{0} = ' '; 20 | 21 | print(buf); 22 | 23 | if (j == 15) 24 | print(" "); 25 | } 26 | 27 | print("\n"); 28 | } 29 | } -------------------------------------------------------------------------------- /Programs/fpga_test.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PetteriAimonen/QuadPawn/704ea78c61738574bb62407f503fc49a13ffb405/Programs/fpga_test.amx -------------------------------------------------------------------------------- /Programs/fpga_test.pawn: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | main() 5 | { 6 | println(str(fpga_load("TESTFPGA.BIN"))); 7 | 8 | new buf[3]; 9 | fpga_read(buf); 10 | 11 | for (new i = 0; i < 3; i++) 12 | { 13 | println(strjoin("buf[", str(i), "] = 0x", hex(buf[i]))); 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /Programs/freqresp.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PetteriAimonen/QuadPawn/704ea78c61738574bb62407f503fc49a13ffb405/Programs/freqresp.amx -------------------------------------------------------------------------------- /Programs/getlicense.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PetteriAimonen/QuadPawn/704ea78c61738574bb62407f503fc49a13ffb405/Programs/getlicense.amx -------------------------------------------------------------------------------- /Programs/getlicense.pawn: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | main() 5 | { 6 | new curvalue {8} ; 7 | print("SERIAL NUMBER : "); 8 | new serialNum = read_SN(); //sadly it is signed 9 | new firstByte = serialNum >>> 24; 10 | serialNum &= 0x00FFFFFF; 11 | valstr(curvalue, firstByte, 2, 16, 2); 12 | print(curvalue, blue); 13 | valstr(curvalue, serialNum, 6, 16, 6); 14 | println(curvalue); 15 | 16 | 17 | print("LICENSE CODE HW <= 2.72 : "); 18 | valstr(curvalue, read_flash(0x08003807), 2, 16, 2); 19 | print(curvalue); 20 | valstr(curvalue, read_flash(0x08003806), 2, 16, 2); 21 | print(curvalue); 22 | valstr(curvalue, read_flash(0x08003805), 2, 16, 2); 23 | print(curvalue); 24 | valstr(curvalue, read_flash(0x08003804), 2, 16, 2); 25 | println(curvalue); 26 | 27 | print("LICENSE CODE HW >= 2.81 : "); 28 | valstr(curvalue, read_flash(0x080000FF), 2, 16, 2); 29 | print(curvalue); 30 | valstr(curvalue, read_flash(0x080000FE), 2, 16, 2); 31 | print(curvalue); 32 | valstr(curvalue, read_flash(0x080000FD), 2, 16, 2); 33 | print(curvalue); 34 | valstr(curvalue, read_flash(0x080000FC), 2, 16, 2); 35 | println(curvalue); 36 | } 37 | -------------------------------------------------------------------------------- /Programs/hello.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PetteriAimonen/QuadPawn/704ea78c61738574bb62407f503fc49a13ffb405/Programs/hello.amx -------------------------------------------------------------------------------- /Programs/hello.pawn: -------------------------------------------------------------------------------- 1 | #include 2 | main() 3 | println("Hello world!"); 4 | -------------------------------------------------------------------------------- /Programs/i2c.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PetteriAimonen/QuadPawn/704ea78c61738574bb62407f503fc49a13ffb405/Programs/i2c.amx -------------------------------------------------------------------------------- /Programs/logiccap.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PetteriAimonen/QuadPawn/704ea78c61738574bb62407f503fc49a13ffb405/Programs/logiccap.amx -------------------------------------------------------------------------------- /Programs/servo.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PetteriAimonen/QuadPawn/704ea78c61738574bb62407f503fc49a13ffb405/Programs/servo.amx -------------------------------------------------------------------------------- /Programs/servo.pawn: -------------------------------------------------------------------------------- 1 | 2 | main() 3 | { 4 | draw_menubar("Quit", "Min", "Max", ""); 5 | 6 | draw_text("Servo tester", 200, 200, .fg = green, .center = true); 7 | 8 | draw_text("Pulse length:", 100, 160); 9 | 10 | new pulse = 1500; // 1.5 ms pulse 11 | new period = 20000; // 20 ms period 12 | 13 | // waveout_digital(100, FIX(0.85)); 14 | while (!get_keys(BUTTON1)) 15 | { 16 | if (held_keys(SCROLL2_LEFT)) 17 | pulse -= 1; 18 | 19 | if (held_keys(SCROLL2_RIGHT)) 20 | pulse += 1; 21 | 22 | if (get_keys(BUTTON2)) 23 | pulse = 1000; 24 | 25 | if (get_keys(BUTTON3)) 26 | pulse = 2000; 27 | 28 | pulse = clamp(pulse, 500, 2500); 29 | 30 | waveout_digital(1000000 / period, FIX(1.0) - fixed(pulse) / fixed(period)); 31 | 32 | new buffer{20}; 33 | buffer = str(pulse); 34 | strcat(buffer, " us "); 35 | draw_text(buffer, 200, 160, .bg = black); 36 | 37 | delay_ms(1); 38 | } 39 | } -------------------------------------------------------------------------------- /Programs/signlgen.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PetteriAimonen/QuadPawn/704ea78c61738574bb62407f503fc49a13ffb405/Programs/signlgen.amx -------------------------------------------------------------------------------- /Programs/spec_an.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PetteriAimonen/QuadPawn/704ea78c61738574bb62407f503fc49a13ffb405/Programs/spec_an.amx -------------------------------------------------------------------------------- /Programs/specgram.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PetteriAimonen/QuadPawn/704ea78c61738574bb62407f503fc49a13ffb405/Programs/specgram.amx -------------------------------------------------------------------------------- /Programs/spectrum.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PetteriAimonen/QuadPawn/704ea78c61738574bb62407f503fc49a13ffb405/Programs/spectrum.amx -------------------------------------------------------------------------------- /Programs/spectrum.pawn: -------------------------------------------------------------------------------- 1 | /** FFT-based spectrum analyzer. */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | new inbuf{2048}; 13 | new Fixed: real_fft[2048]; 14 | new Fixed: imag_fft[2048]; 15 | 16 | bool:@idle() 17 | { 18 | wavein_read(inbuf); 19 | wavein_start(); 20 | 21 | fft(inbuf, real_fft, imag_fft, 2048); 22 | 23 | real_fft[0] -= fixed(128); // Subtract the DC offset 24 | 25 | for (new i = 0; i < 400; i++) 26 | { 27 | new Color: column[200] = [black]; 28 | 29 | // There are more values (1024) than can fit on the screen, 30 | // so draw 2 values per column. This makes tight frequency 31 | // spikes more visible than just skipping the extra values. 32 | new Fixed: maxval = FIX(0.0001); 33 | for (new j = 0; j < 2; j++) 34 | { 35 | new idx = i * 2 + j; 36 | new Fixed: val = cabs(real_fft[idx], imag_fft[idx]); 37 | if (val > maxval) maxval = val; 38 | } 39 | 40 | new pos = fround(5 * 20 * log10(maxval) + 100); 41 | pos = clamp(pos, 0, sizeof(column)); 42 | memset(_:column, _:green, pos); 43 | 44 | putcolumn(i, 20, column); 45 | } 46 | 47 | return !get_keys(BUTTON4); 48 | } 49 | 50 | main() 51 | { 52 | draw_menubar("", "", "", "Quit"); 53 | config_chA(ADC_DC, ADC_50mV); 54 | // waveout_digital(100000); 55 | waveout_voltage(0); 56 | wavein_settrigger(Trig_Always); 57 | wavein_samplerate(24000000); 58 | wavein_start(); 59 | } 60 | -------------------------------------------------------------------------------- /Programs/torch.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PetteriAimonen/QuadPawn/704ea78c61738574bb62407f503fc49a13ffb405/Programs/torch.amx -------------------------------------------------------------------------------- /Programs/torch.pawn: -------------------------------------------------------------------------------- 1 | /* 2 | * This program turns the DSO Quad in to a torch with brightness adjustable 3 | * from soft for seeing where your sleeping toddler is without waking them up 4 | * to bright for finding your slippers under the bed. 5 | */ 6 | 7 | new brightness 8 | new should_clear 9 | 10 | 11 | help() 12 | { 13 | fill_rectangle( 0, 0, 400, 240, black) 14 | new lines[]{} = [ 15 | "Button 1 - Keys", 16 | "Button 4 - Quit", 17 | "Scroll 1 - Fine adjustment", 18 | "Scroll 2 - Coarse adjustment" 19 | ] 20 | for ( new i = 0; i < sizeof lines; i += 1) 21 | { 22 | // 28 = characters in widest line 23 | // 6 = character row of first line 24 | draw_text( lines[i], (screenwidth - fontwidth*28) / 2, screenheight - fontheight * (6+i) - fontheight) 25 | } 26 | should_clear = true 27 | } 28 | 29 | 30 | change_brightness( change) 31 | { 32 | brightness = clamp( brightness + change, 5, 100) 33 | set_backlight( brightness) 34 | if (should_clear) 35 | { 36 | fill_rectangle( 0, 0, 400, 240, white) 37 | should_clear = false 38 | } 39 | } 40 | 41 | 42 | main() 43 | { 44 | help() 45 | 46 | while (!get_keys(BUTTON4)) 47 | { 48 | if (get_keys(BUTTON1)) 49 | { 50 | help() 51 | } 52 | else if (get_keys(SCROLL2_RIGHT)) 53 | { 54 | change_brightness(30) 55 | } 56 | else if (get_keys(SCROLL2_LEFT)) 57 | { 58 | change_brightness(-30) 59 | } 60 | else if (get_keys(SCROLL1_RIGHT)) 61 | { 62 | change_brightness(5) 63 | } 64 | else if (get_keys(SCROLL1_LEFT)) 65 | { 66 | change_brightness(-5) 67 | } 68 | } 69 | } 70 | 71 | -------------------------------------------------------------------------------- /Programs/unittest.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PetteriAimonen/QuadPawn/704ea78c61738574bb62407f503fc49a13ffb405/Programs/unittest.amx -------------------------------------------------------------------------------- /Programs/unittest.pawn: -------------------------------------------------------------------------------- 1 | /** Unit tests for the standard library. */ 2 | 3 | #include 4 | 5 | test_num({Fixed, _}: value, {Fixed, _}: expected, const errormsg{}) 6 | { 7 | if (value != expected) 8 | { 9 | print(errormsg); print(": "); 10 | print(str(_:value)); print(" vs. "); 11 | println(str(_:expected)); 12 | } 13 | } 14 | 15 | // Usage: TEST_NUM(expression, expected) 16 | #define TEST_NUM(%1,%2) \ 17 | test_num(%1, %2, "Test " ... #%1 ... " failed") 18 | 19 | test_str(const value{}, const expected{}, const errormsg{}) 20 | { 21 | if (!strequal(value, expected)) 22 | { 23 | print(errormsg); print(": "); 24 | print(value); print(" vs. "); println(expected); 25 | } 26 | } 27 | 28 | // Usage: TEST_STR(expression, expected) 29 | #define TEST_STR(%1,%2) \ 30 | test_str(%1, %2, "Test " ... #%1 ... " failed") 31 | 32 | main() 33 | { 34 | TEST_NUM(ftrunc(FIX(1.6)), 1); 35 | TEST_NUM(ftrunc(FIX(-1.6)), -1); 36 | TEST_NUM(ftrunc(FIX(0.5)), 0); 37 | TEST_NUM(ftrunc(FIX(-0.5)), 0); 38 | 39 | TEST_NUM(frac(FIX(1.6)), FIX(0.6)); 40 | TEST_NUM(frac(FIX(-1.6)), FIX(0.6)); 41 | 42 | TEST_STR(str(-1), "-1"); 43 | TEST_STR(str(0), "0"); 44 | TEST_STR(str(1), "1"); 45 | 46 | TEST_STR(strf(FIX(0.0000)), "0.0000"); 47 | TEST_STR(strf(FIX(0.0001)), "0.0001"); 48 | TEST_STR(strf(FIX(-0.0001)), "-0.0001"); 49 | TEST_STR(strf(FIX(1.0001)), "1.0001"); 50 | TEST_STR(strf(FIX(-1.0001)), "-1.0001"); 51 | 52 | TEST_STR(strf(FIX(0.99999)), "1.0000"); 53 | TEST_STR(strf(FIX(-0.99999)), "-1.0000"); 54 | 55 | TEST_STR(strf(FIX(-179.99), 1), "-180.0"); 56 | 57 | new a = 40; 58 | new b = 1; 59 | TEST_NUM(200 - a * b, 160); 60 | 61 | println("Tests complete."); 62 | } 63 | -------------------------------------------------------------------------------- /Programs/voltmetr.amx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PetteriAimonen/QuadPawn/704ea78c61738574bb62407f503fc49a13ffb405/Programs/voltmetr.amx -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Pawn for DSO Quad 2 | 3 | ![Header image](http://kapsi.fi/~jpa/stuff/pix/pawn_header.jpg) 4 | 5 | Pawn scripting language for the DSO Quad pocket oscilloscope. 6 | This is intended to make programming for DSO Quad easier and to allow tens of programs to reside on the flash drive. 7 | 8 | It offers a comprehensive set of [libraries](https://github.com/PetteriAimonen/QuadPawn/tree/master/Compiler/include), 9 | intuitive program selector and basic debugging facilities. 10 | 11 | Read the [Getting started](https://github.com/PetteriAimonen/QuadPawn/wiki/Getting-started) guide, or just download 12 | [the runtime](http://koti.kapsi.fi/~jpa/dsoquad/#QuadPawn) and [some apps](https://github.com/PetteriAimonen/QuadPawn/wiki). 13 | 14 | Update 03/07/2021 15 | tested on 2.72 8Mb only. 16 | Modified linker script to use the new Alterbios placed just after SYS (ALT_F164.HEX/BIN). 17 | Since the latest Alterbios is patched to work on 8Mb devices, no more fat corruption occur. 18 | Now the flash in the range 0x08040000-0x0804C000 (52Kb!!) is free for other app. 19 | 20 | Just for fun I added 2 new pawn functions: read_flash(address) and read_SN() 21 | Wrote getlicense.pawn to test them, this app simply shows the serial number and the valid license to insert in case of DFU wipe. 22 | -------------------------------------------------------------------------------- /Runtime/.gitignore: -------------------------------------------------------------------------------- 1 | *.HEX 2 | build 3 | -------------------------------------------------------------------------------- /Runtime/DS203/Interrupt.c: -------------------------------------------------------------------------------- 1 | /********************* (C) COPYRIGHT 2010 e-Design Co.,Ltd. ******************** 2 | File Name : Interrupt.c 3 | Version : DS203_APP Ver 2.3x Author : bure 4 | *******************************************************************************/ 5 | #include "Interrupt.h" 6 | #include "BIOS.h" 7 | #include 8 | 9 | void NMIException(void) __attribute__((externally_visible)); 10 | void USB_HP_CAN_TX_IRQHandler(void) __attribute__((externally_visible)); 11 | void USB_LP_CAN_RXO_IRQHandler(void) __attribute__((externally_visible)); 12 | 13 | void NMIException(void) 14 | {} 15 | 16 | void USB_HP_CAN_TX_IRQHandler(void) 17 | { 18 | __CTR_HP(); 19 | } 20 | 21 | void USB_LP_CAN_RX0_IRQHandler(void) 22 | { 23 | __USB_Istr(); 24 | } 25 | -------------------------------------------------------------------------------- /Runtime/alterbios/alterbios.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __ALTERBIOS_H__ 3 | #define __ALTERBIOS_H__ 4 | 5 | extern uint32_t alterbios_version_tag; 6 | 7 | /* Verify that the installed AlterBIOS version is compatible with this 8 | * API version. Return values: 9 | * Success: positive (number of exported functions) 10 | * Not installed: -1 11 | * Too old version: -2 12 | */ 13 | static int alterbios_check() 14 | { 15 | if ((alterbios_version_tag & 0xFFFF0000) != 0x0A170000) 16 | return -1; 17 | if ((alterbios_version_tag & 0x0000FFFF) < 36) 18 | return -2; 19 | return (alterbios_version_tag & 0x0000FFFF); 20 | } 21 | 22 | /* Initialize AlterBIOS (basically mounts the FAT filesystem) */ 23 | extern void alterbios_init(); 24 | 25 | #endif 26 | 27 | -------------------------------------------------------------------------------- /Runtime/alterbios/fatfs/integer.h: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------*/ 2 | /* Integer type definitions for FatFs module */ 3 | /*-------------------------------------------*/ 4 | 5 | #ifndef _INTEGER 6 | #define _INTEGER 7 | 8 | #ifdef _WIN32 /* FatFs development platform */ 9 | 10 | #include 11 | #include 12 | 13 | #else /* Embedded platform */ 14 | 15 | /* These types must be 16-bit, 32-bit or larger integer */ 16 | typedef int INT; 17 | typedef unsigned int UINT; 18 | 19 | /* These types must be 8-bit integer */ 20 | typedef char CHAR; 21 | typedef unsigned char UCHAR; 22 | typedef unsigned char BYTE; 23 | 24 | /* These types must be 16-bit integer */ 25 | typedef short SHORT; 26 | typedef unsigned short USHORT; 27 | typedef unsigned short WORD; 28 | typedef unsigned short WCHAR; 29 | 30 | /* These types must be 32-bit integer */ 31 | typedef long LONG; 32 | typedef unsigned long ULONG; 33 | typedef unsigned long DWORD; 34 | 35 | #endif 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /Runtime/amx/amxDGram.def: -------------------------------------------------------------------------------- 1 | NAME amxDGram 2 | DESCRIPTION 'Pawn AMX: network datagram' 3 | 4 | EXPORTS 5 | amx_DGramInit 6 | amx_DGramCleanup 7 | -------------------------------------------------------------------------------- /Runtime/amx/amxDGram.rc: -------------------------------------------------------------------------------- 1 | #include 2 | #if defined WIN32 || defined _WIN32 || defined __WIN32__ 3 | # include 4 | #else 5 | # include 6 | #endif 7 | 8 | /* Version information 9 | * 10 | * All strings MUST have an explicit \0. See the Windows SDK documentation 11 | * for details on version information and the VERSIONINFO structure. 12 | */ 13 | #define VERSION 4 14 | #define REVISION 0 15 | #define BUILD 0 16 | #define VERSIONSTR "4.0.0\0" 17 | #define VERSIONNAME "amxDGram.dll\0" 18 | #define VERSIONDESCRIPTION "Pawn AMX: network datagram\0" 19 | #define VERSIONCOMPANYNAME "ITB CompuPhase\0" 20 | #define VERSIONPRODUCTNAME "amxDGram\0" 21 | #define VERSIONCOPYRIGHT "Copyright \251 2007-2011 ITB CompuPhase\0" 22 | 23 | VS_VERSION_INFO VERSIONINFO 24 | FILEVERSION VERSION, REVISION, BUILD, 0 25 | PRODUCTVERSION VERSION, REVISION, BUILD, 0 26 | FILEFLAGSMASK 0x0000003FL 27 | FILEFLAGS 0 28 | #if defined(WIN32) 29 | FILEOS VOS__WINDOWS32 30 | #else 31 | FILEOS VOS__WINDOWS16 32 | #endif 33 | FILETYPE VFT_DLL 34 | BEGIN 35 | BLOCK "StringFileInfo" 36 | BEGIN 37 | BLOCK "040904E4" 38 | BEGIN 39 | VALUE "CompanyName", VERSIONCOMPANYNAME 40 | VALUE "FileDescription", VERSIONDESCRIPTION 41 | VALUE "FileVersion", VERSIONSTR 42 | VALUE "InternalName", VERSIONNAME 43 | VALUE "LegalCopyright", VERSIONCOPYRIGHT 44 | VALUE "OriginalFilename", VERSIONNAME 45 | VALUE "ProductName", VERSIONPRODUCTNAME 46 | VALUE "ProductVersion", VERSIONSTR 47 | END 48 | END 49 | 50 | BLOCK "VarFileInfo" 51 | BEGIN 52 | VALUE "Translation", 0x409, 1252 53 | END 54 | END 55 | -------------------------------------------------------------------------------- /Runtime/amx/amxFile.rc: -------------------------------------------------------------------------------- 1 | #include 2 | #if defined WIN32 || defined _WIN32 || defined __WIN32__ 3 | # include 4 | #else 5 | # include 6 | #endif 7 | 8 | /* Version information 9 | * 10 | * All strings MUST have an explicit \0. See the Windows SDK documentation 11 | * for details on version information and the VERSIONINFO structure. 12 | */ 13 | #define VERSION 4 14 | #define REVISION 0 15 | #define BUILD 0 16 | #define VERSIONSTR "4.0.0\0" 17 | #define VERSIONNAME "amxFile.dll\0" 18 | #define VERSIONDESCRIPTION "Pawn AMX: File I/O support\0" 19 | #define VERSIONCOMPANYNAME "ITB CompuPhase\0" 20 | #define VERSIONPRODUCTNAME "amxFile\0" 21 | #define VERSIONCOPYRIGHT "Copyright \251 2004-2011 ITB CompuPhase\0" 22 | 23 | VS_VERSION_INFO VERSIONINFO 24 | FILEVERSION VERSION, REVISION, BUILD, 0 25 | PRODUCTVERSION VERSION, REVISION, BUILD, 0 26 | FILEFLAGSMASK 0x0000003FL 27 | FILEFLAGS 0 28 | #if defined(WIN32) 29 | FILEOS VOS__WINDOWS32 30 | #else 31 | FILEOS VOS__WINDOWS16 32 | #endif 33 | FILETYPE VFT_DLL 34 | BEGIN 35 | BLOCK "StringFileInfo" 36 | BEGIN 37 | BLOCK "040904E4" 38 | BEGIN 39 | VALUE "CompanyName", VERSIONCOMPANYNAME 40 | VALUE "FileDescription", VERSIONDESCRIPTION 41 | VALUE "FileVersion", VERSIONSTR 42 | VALUE "InternalName", VERSIONNAME 43 | VALUE "LegalCopyright", VERSIONCOPYRIGHT 44 | VALUE "OriginalFilename", VERSIONNAME 45 | VALUE "ProductName", VERSIONPRODUCTNAME 46 | VALUE "ProductVersion", VERSIONSTR 47 | END 48 | END 49 | 50 | BLOCK "VarFileInfo" 51 | BEGIN 52 | VALUE "Translation", 0x409, 1252 53 | END 54 | END 55 | -------------------------------------------------------------------------------- /Runtime/amx/amxFixed.def: -------------------------------------------------------------------------------- 1 | NAME amxFixed 2 | DESCRIPTION 'Pawn AMX: fixed-point arithmetic' 3 | 4 | EXPORTS 5 | amx_FixedInit 6 | amx_FixedCleanup 7 | -------------------------------------------------------------------------------- /Runtime/amx/amxFixed.rc: -------------------------------------------------------------------------------- 1 | #include 2 | #if defined WIN32 || defined _WIN32 || defined __WIN32__ 3 | # include 4 | #else 5 | # include 6 | #endif 7 | 8 | /* Version information 9 | * 10 | * All strings MUST have an explicit \0. See the Windows SDK documentation 11 | * for details on version information and the VERSIONINFO structure. 12 | */ 13 | #define VERSION 4 14 | #define REVISION 0 15 | #define BUILD 0 16 | #define VERSIONSTR "4.0.0\0" 17 | #define VERSIONNAME "amxFixed.dll\0" 18 | #define VERSIONDESCRIPTION "Pawn AMX: Fixed Point support\0" 19 | #define VERSIONCOMPANYNAME "ITB CompuPhase\0" 20 | #define VERSIONPRODUCTNAME "amxFixed\0" 21 | #define VERSIONCOPYRIGHT "Copyright \251 2003-2011 ITB CompuPhase\0" 22 | 23 | VS_VERSION_INFO VERSIONINFO 24 | FILEVERSION VERSION, REVISION, BUILD, 0 25 | PRODUCTVERSION VERSION, REVISION, BUILD, 0 26 | FILEFLAGSMASK 0x0000003FL 27 | FILEFLAGS 0 28 | #if defined(WIN32) 29 | FILEOS VOS__WINDOWS32 30 | #else 31 | FILEOS VOS__WINDOWS16 32 | #endif 33 | FILETYPE VFT_DLL 34 | BEGIN 35 | BLOCK "StringFileInfo" 36 | BEGIN 37 | BLOCK "040904E4" 38 | BEGIN 39 | VALUE "CompanyName", VERSIONCOMPANYNAME 40 | VALUE "FileDescription", VERSIONDESCRIPTION 41 | VALUE "FileVersion", VERSIONSTR 42 | VALUE "InternalName", VERSIONNAME 43 | VALUE "LegalCopyright", VERSIONCOPYRIGHT 44 | VALUE "OriginalFilename", VERSIONNAME 45 | VALUE "ProductName", VERSIONPRODUCTNAME 46 | VALUE "ProductVersion", VERSIONSTR 47 | END 48 | END 49 | 50 | BLOCK "VarFileInfo" 51 | BEGIN 52 | VALUE "Translation", 0x409, 1252 53 | END 54 | END 55 | -------------------------------------------------------------------------------- /Runtime/amx/amxFloat.def: -------------------------------------------------------------------------------- 1 | NAME amxFloat 2 | DESCRIPTION 'Pawn AMX: floating-point arithmetic' 3 | 4 | EXPORTS 5 | amx_FloatInit 6 | amx_FloatCleanup 7 | -------------------------------------------------------------------------------- /Runtime/amx/amxFloat.rc: -------------------------------------------------------------------------------- 1 | #include 2 | #if defined WIN32 || defined _WIN32 || defined __WIN32__ 3 | # include 4 | #else 5 | # include 6 | #endif 7 | 8 | /* Version information 9 | * 10 | * All strings MUST have an explicit \0. See the Windows SDK documentation 11 | * for details on version information and the VERSIONINFO structure. 12 | */ 13 | #define VERSION 4 14 | #define REVISION 0 15 | #define BUILD 0 16 | #define VERSIONSTR "4.0.0\0" 17 | #define VERSIONNAME "amxFloat.dll\0" 18 | #define VERSIONDESCRIPTION "Pawn AMX: Floating Point support\0" 19 | #define VERSIONCOMPANYNAME "ITB CompuPhase\0" 20 | #define VERSIONPRODUCTNAME "amxFloat\0" 21 | #define VERSIONCOPYRIGHT "Copyright \251 2003-2011 ITB CompuPhase\0" 22 | 23 | VS_VERSION_INFO VERSIONINFO 24 | FILEVERSION VERSION, REVISION, BUILD, 0 25 | PRODUCTVERSION VERSION, REVISION, BUILD, 0 26 | FILEFLAGSMASK 0x0000003FL 27 | FILEFLAGS 0 28 | #if defined(WIN32) 29 | FILEOS VOS__WINDOWS32 30 | #else 31 | FILEOS VOS__WINDOWS16 32 | #endif 33 | FILETYPE VFT_DLL 34 | BEGIN 35 | BLOCK "StringFileInfo" 36 | BEGIN 37 | BLOCK "040904E4" 38 | BEGIN 39 | VALUE "CompanyName", VERSIONCOMPANYNAME 40 | VALUE "FileDescription", VERSIONDESCRIPTION 41 | VALUE "FileVersion", VERSIONSTR 42 | VALUE "InternalName", VERSIONNAME 43 | VALUE "LegalCopyright", VERSIONCOPYRIGHT 44 | VALUE "OriginalFilename", VERSIONNAME 45 | VALUE "ProductName", VERSIONPRODUCTNAME 46 | VALUE "ProductVersion", VERSIONSTR 47 | END 48 | END 49 | 50 | BLOCK "VarFileInfo" 51 | BEGIN 52 | VALUE "Translation", 0x409, 1252 53 | END 54 | END 55 | -------------------------------------------------------------------------------- /Runtime/amx/amxProcess.def: -------------------------------------------------------------------------------- 1 | NAME amxProcess 2 | DESCRIPTION 'Pawn AMX: process control and foreign function interface' 3 | 4 | EXPORTS 5 | amx_ProcessInit 6 | amx_ProcessCleanup 7 | -------------------------------------------------------------------------------- /Runtime/amx/amxProcess.rc: -------------------------------------------------------------------------------- 1 | #include 2 | #if defined WIN32 || defined _WIN32 || defined __WIN32__ 3 | # include 4 | #else 5 | # include 6 | #endif 7 | 8 | /* Version information 9 | * 10 | * All strings MUST have an explicit \0. See the Windows SDK documentation 11 | * for details on version information and the VERSIONINFO structure. 12 | */ 13 | #define VERSION 4 14 | #define REVISION 0 15 | #define BUILD 0 16 | #define VERSIONSTR "4.0.0\0" 17 | #define VERSIONNAME "amxProcess.dll\0" 18 | #define VERSIONDESCRIPTION "Pawn AMX: process control and foreign function interface\0" 19 | #define VERSIONCOMPANYNAME "ITB CompuPhase\0" 20 | #define VERSIONPRODUCTNAME "amxProcess\0" 21 | #define VERSIONCOPYRIGHT "Copyright \251 2005-2011 ITB CompuPhase\0" 22 | 23 | VS_VERSION_INFO VERSIONINFO 24 | FILEVERSION VERSION, REVISION, BUILD, 0 25 | PRODUCTVERSION VERSION, REVISION, BUILD, 0 26 | FILEFLAGSMASK 0x0000003FL 27 | FILEFLAGS 0 28 | #if defined(WIN32) 29 | FILEOS VOS__WINDOWS32 30 | #else 31 | FILEOS VOS__WINDOWS16 32 | #endif 33 | FILETYPE VFT_DLL 34 | BEGIN 35 | BLOCK "StringFileInfo" 36 | BEGIN 37 | BLOCK "040904E4" 38 | BEGIN 39 | VALUE "CompanyName", VERSIONCOMPANYNAME 40 | VALUE "FileDescription", VERSIONDESCRIPTION 41 | VALUE "FileVersion", VERSIONSTR 42 | VALUE "InternalName", VERSIONNAME 43 | VALUE "LegalCopyright", VERSIONCOPYRIGHT 44 | VALUE "OriginalFilename", VERSIONNAME 45 | VALUE "ProductName", VERSIONPRODUCTNAME 46 | VALUE "ProductVersion", VERSIONSTR 47 | END 48 | END 49 | 50 | BLOCK "VarFileInfo" 51 | BEGIN 52 | VALUE "Translation", 0x409, 1252 53 | END 54 | END 55 | -------------------------------------------------------------------------------- /Runtime/amx/amxargs.rc: -------------------------------------------------------------------------------- 1 | #include 2 | #if defined WIN32 || defined _WIN32 || defined __WIN32__ 3 | # include 4 | #else 5 | # include 6 | #endif 7 | 8 | /* Version information 9 | * 10 | * All strings MUST have an explicit \0. See the Windows SDK documentation 11 | * for details on version information and the VERSIONINFO structure. 12 | */ 13 | #define VERSION 4 14 | #define REVISION 0 15 | #define BUILD 0 16 | #define VERSIONSTR "4.0.0\0" 17 | #define VERSIONNAME "amxArgs.dll\0" 18 | #define VERSIONDESCRIPTION "Pawn AMX: Script Arguments support\0" 19 | #define VERSIONCOMPANYNAME "ITB CompuPhase\0" 20 | #define VERSIONPRODUCTNAME "amxArgs\0" 21 | #define VERSIONCOPYRIGHT "Copyright \251 2005-2011 ITB CompuPhase\0" 22 | 23 | VS_VERSION_INFO VERSIONINFO 24 | FILEVERSION VERSION, REVISION, BUILD, 0 25 | PRODUCTVERSION VERSION, REVISION, BUILD, 0 26 | FILEFLAGSMASK 0x0000003FL 27 | FILEFLAGS 0 28 | #if defined(WIN32) 29 | FILEOS VOS__WINDOWS32 30 | #else 31 | FILEOS VOS__WINDOWS16 32 | #endif 33 | FILETYPE VFT_DLL 34 | BEGIN 35 | BLOCK "StringFileInfo" 36 | BEGIN 37 | BLOCK "040904E4" 38 | BEGIN 39 | VALUE "CompanyName", VERSIONCOMPANYNAME 40 | VALUE "FileDescription", VERSIONDESCRIPTION 41 | VALUE "FileVersion", VERSIONSTR 42 | VALUE "InternalName", VERSIONNAME 43 | VALUE "LegalCopyright", VERSIONCOPYRIGHT 44 | VALUE "OriginalFilename", VERSIONNAME 45 | VALUE "ProductName", VERSIONPRODUCTNAME 46 | VALUE "ProductVersion", VERSIONSTR 47 | END 48 | END 49 | 50 | BLOCK "VarFileInfo" 51 | BEGIN 52 | VALUE "Translation", 0x409, 1252 53 | END 54 | END 55 | -------------------------------------------------------------------------------- /Runtime/amx/amxaux.h: -------------------------------------------------------------------------------- 1 | /* Support routines for the Pawn Abstract Machine 2 | * 3 | * Copyright (c) ITB CompuPhase, 2003-2011 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 6 | * use this file except in compliance with the License. You may obtain a copy 7 | * of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | * 17 | * Version: $Id: amxaux.h 4523 2011-06-21 15:03:47Z thiadmer $ 18 | */ 19 | #ifndef AMXAUX_H_INCLUDED 20 | #define AMXAUX_H_INCLUDED 21 | 22 | #include "amx.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* loading and freeing programs */ 29 | size_t AMXAPI aux_ProgramSize(const char *filename); 30 | int AMXAPI aux_LoadProgram(AMX *amx, const char *filename, void *memblock); 31 | int AMXAPI aux_FreeProgram(AMX *amx); 32 | 33 | /* a readable error message from an error code */ 34 | char * AMXAPI aux_StrError(int errnum); 35 | 36 | enum { 37 | CODE_SECTION, 38 | DATA_SECTION, 39 | HEAP_SECTION, 40 | STACK_SECTION, 41 | /* ----- */ 42 | NUM_SECTIONS 43 | }; 44 | int AMXAPI aux_GetSection(const AMX *amx, int section, cell **start, size_t *size); 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif /* AMXAUX_H_INCLUDED */ 51 | -------------------------------------------------------------------------------- /Runtime/amx/amxcons.h: -------------------------------------------------------------------------------- 1 | #ifndef AMXCONS_H_INCLUDED 2 | #define AMXCONS_H_INCLUDED 3 | 4 | typedef struct tagFMTINFO { 5 | const cell *params; 6 | int numparams; 7 | int skip; /* number of characters to skip from the beginning */ 8 | int length; /* number of characters to print */ 9 | /* helper functions */ 10 | int (*f_putstr)(void *dest,const TCHAR *); 11 | int (*f_putchar)(void *dest,TCHAR); 12 | void *user; /* user data */ 13 | } AMX_FMTINFO; 14 | 15 | int amx_printstring(AMX *amx,cell *cstr,AMX_FMTINFO *info); 16 | 17 | #endif /* AMXCONS_H_INCLUDED */ 18 | -------------------------------------------------------------------------------- /Runtime/amx/amxfile.def: -------------------------------------------------------------------------------- 1 | NAME amxFile 2 | DESCRIPTION 'File I/O support library' 3 | 4 | EXPORTS 5 | amx_FileInit 6 | amx_FileCleanup 7 | -------------------------------------------------------------------------------- /Runtime/amx/amxgc.h: -------------------------------------------------------------------------------- 1 | /* Simple garbage collector for the Pawn Abstract Machine 2 | * 3 | * Copyright (c) ITB CompuPhase, 2004-2011 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 6 | * use this file except in compliance with the License. You may obtain a copy 7 | * of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | * 17 | * Version: $Id: amxgc.h 4523 2011-06-21 15:03:47Z thiadmer $ 18 | */ 19 | 20 | #ifndef AMXGC_H 21 | #define AMXGC_H 22 | 23 | typedef void _FAR (* GC_FREE)(cell unreferenced); 24 | enum { 25 | GC_ERR_NONE, 26 | GC_ERR_CALLBACK, /* no callback, or invalid callback */ 27 | GC_ERR_INIT, /* garbage collector not initialized (no table size) */ 28 | GC_ERR_MEMORY, /* insufficient memory to set/resize the table */ 29 | GC_ERR_PARAMS, /* parameter error */ 30 | GC_ERR_TABLEFULL, /* domain error, expression result does not fit in range */ 31 | GC_ERR_DUPLICATE, /* item is already in the table */ 32 | }; 33 | 34 | /* flags */ 35 | #define GC_AUTOGROW 1 /* gc_mark() may grow the hash table when it fills up */ 36 | 37 | int gc_setcallback(GC_FREE callback); 38 | 39 | int gc_settable(int exponent,int flags); 40 | int gc_tablestat(int *exponent,int *percentage); 41 | /* Upon return, "exponent" will hold the values passed to gc_settable(); 42 | * "percentage" is the level (in percent) that the hash table is filled 43 | * up. Either parameter may be set to NULL. 44 | */ 45 | 46 | int gc_mark(cell value); 47 | int gc_scan(AMX *amx); 48 | int gc_clean(void); 49 | 50 | #endif /* AMXGC_H */ 51 | -------------------------------------------------------------------------------- /Runtime/amx/amxpool.h: -------------------------------------------------------------------------------- 1 | /* Simple allocation from a memory pool, with automatic release of 2 | * least-recently used blocks (LRU blocks). 3 | * 4 | * Copyright (c) ITB CompuPhase, 2007-2011 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 7 | * use this file except in compliance with the License. You may obtain a copy 8 | * of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 14 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 15 | * License for the specific language governing permissions and limitations 16 | * under the License. 17 | * 18 | * Version: $Id: amxpool.h 4523 2011-06-21 15:03:47Z thiadmer $ 19 | */ 20 | #ifndef AMXPOOL_H_INCLUDED 21 | #define AMXPOOL_H_INCLUDED 22 | 23 | void amx_poolinit(void *pool, unsigned size); 24 | void *amx_poolalloc(unsigned size, int index); 25 | void amx_poolfree(void *block); 26 | void *amx_poolfind(int index); 27 | int amx_poolprotect(int index); 28 | 29 | 30 | #endif /* AMXPOOL_H_INCLUDED */ 31 | -------------------------------------------------------------------------------- /Runtime/amx/amxstring.def: -------------------------------------------------------------------------------- 1 | NAME amxString 2 | DESCRIPTION 'Pawn AMX: string manipulation routines' 3 | 4 | EXPORTS 5 | amx_StringInit 6 | amx_StringCleanup 7 | -------------------------------------------------------------------------------- /Runtime/amx/amxstring.rc: -------------------------------------------------------------------------------- 1 | #include 2 | #if defined WIN32 || defined _WIN32 || defined __WIN32__ 3 | # include 4 | #else 5 | # include 6 | #endif 7 | 8 | /* Version information 9 | * 10 | * All strings MUST have an explicit \0. See the Windows SDK documentation 11 | * for details on version information and the VERSIONINFO structure. 12 | */ 13 | #define VERSION 4 14 | #define REVISION 0 15 | #define BUILD 0 16 | #define VERSIONSTR "4.0.0\0" 17 | #define VERSIONNAME "amxString.dll\0" 18 | #define VERSIONDESCRIPTION "Pawn AMX: String manipulation routines\0" 19 | #define VERSIONCOMPANYNAME "ITB CompuPhase\0" 20 | #define VERSIONPRODUCTNAME "amxString\0" 21 | #define VERSIONCOPYRIGHT "Copyright \251 2005-2011 ITB CompuPhase\0" 22 | 23 | VS_VERSION_INFO VERSIONINFO 24 | FILEVERSION VERSION, REVISION, BUILD, 0 25 | PRODUCTVERSION VERSION, REVISION, BUILD, 0 26 | FILEFLAGSMASK 0x0000003FL 27 | FILEFLAGS 0 28 | #if defined(WIN32) 29 | FILEOS VOS__WINDOWS32 30 | #else 31 | FILEOS VOS__WINDOWS16 32 | #endif 33 | FILETYPE VFT_DLL 34 | BEGIN 35 | BLOCK "StringFileInfo" 36 | BEGIN 37 | BLOCK "040904E4" 38 | BEGIN 39 | VALUE "CompanyName", VERSIONCOMPANYNAME 40 | VALUE "FileDescription", VERSIONDESCRIPTION 41 | VALUE "FileVersion", VERSIONSTR 42 | VALUE "InternalName", VERSIONNAME 43 | VALUE "LegalCopyright", VERSIONCOPYRIGHT 44 | VALUE "OriginalFilename", VERSIONNAME 45 | VALUE "ProductName", VERSIONPRODUCTNAME 46 | VALUE "ProductVersion", VERSIONSTR 47 | END 48 | END 49 | 50 | BLOCK "VarFileInfo" 51 | BEGIN 52 | VALUE "Translation", 0x409, 1252 53 | END 54 | END 55 | -------------------------------------------------------------------------------- /Runtime/amx/amxtime.def: -------------------------------------------------------------------------------- 1 | NAME amxTime 2 | DESCRIPTION 'Pawn AMX: time routines' 3 | 4 | EXPORTS 5 | amx_TimeInit 6 | amx_TimeCleanup 7 | -------------------------------------------------------------------------------- /Runtime/amx/amxtime.rc: -------------------------------------------------------------------------------- 1 | #include 2 | #if defined WIN32 || defined _WIN32 || defined __WIN32__ 3 | # include 4 | #else 5 | # include 6 | #endif 7 | 8 | /* Version information 9 | * 10 | * All strings MUST have an explicit \0. See the Windows SDK documentation 11 | * for details on version information and the VERSIONINFO structure. 12 | */ 13 | #define VERSION 4 14 | #define REVISION 0 15 | #define BUILD 0 16 | #define VERSIONSTR "4.0.0\0" 17 | #define VERSIONNAME "amxTime.dll\0" 18 | #define VERSIONDESCRIPTION "Pawn AMX: time routines\0" 19 | #define VERSIONCOMPANYNAME "ITB CompuPhase\0" 20 | #define VERSIONPRODUCTNAME "amxTime\0" 21 | #define VERSIONCOPYRIGHT "Copyright \251 2005-2011 ITB CompuPhase\0" 22 | 23 | VS_VERSION_INFO VERSIONINFO 24 | FILEVERSION VERSION, REVISION, BUILD, 0 25 | PRODUCTVERSION VERSION, REVISION, BUILD, 0 26 | FILEFLAGSMASK 0x0000003FL 27 | FILEFLAGS 0 28 | #if defined(WIN32) 29 | FILEOS VOS__WINDOWS32 30 | #else 31 | FILEOS VOS__WINDOWS16 32 | #endif 33 | FILETYPE VFT_DLL 34 | BEGIN 35 | BLOCK "StringFileInfo" 36 | BEGIN 37 | BLOCK "040904E4" 38 | BEGIN 39 | VALUE "CompanyName", VERSIONCOMPANYNAME 40 | VALUE "FileDescription", VERSIONDESCRIPTION 41 | VALUE "FileVersion", VERSIONSTR 42 | VALUE "InternalName", VERSIONNAME 43 | VALUE "LegalCopyright", VERSIONCOPYRIGHT 44 | VALUE "OriginalFilename", VERSIONNAME 45 | VALUE "ProductName", VERSIONPRODUCTNAME 46 | VALUE "ProductVersion", VERSIONSTR 47 | END 48 | END 49 | 50 | BLOCK "VarFileInfo" 51 | BEGIN 52 | VALUE "Translation", 0x409, 1252 53 | END 54 | END 55 | -------------------------------------------------------------------------------- /Runtime/amx/dllmain.c: -------------------------------------------------------------------------------- 1 | /* DLL support functions for dynamically loadable extension libraries. 2 | * 3 | * Copyright (c) ITB CompuPhase, 2004-2011 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 6 | * use this file except in compliance with the License. You may obtain a copy 7 | * of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | * 17 | * Version: $Id: dllmain.c 4523 2011-06-21 15:03:47Z thiadmer $ 18 | */ 19 | 20 | #if defined _UNICODE || defined __UNICODE__ || defined UNICODE 21 | # if !defined UNICODE /* for Windows */ 22 | # define UNICODE 23 | # endif 24 | # if !defined _UNICODE /* for C library */ 25 | # define _UNICODE 26 | # endif 27 | #endif 28 | 29 | #include 30 | #include 31 | 32 | #if !defined UNUSED_PARAM 33 | #define UNUSED_PARAM(p) ((void)(p)) 34 | #endif 35 | 36 | HINSTANCE hinstDLL; 37 | 38 | /* Especially Watcom C/C++ does not like DLLs that do not have a LibMain() 39 | * set. Apparently, the start address is not set well, and some required 40 | * initializations are not done. 41 | */ 42 | #if defined __WIN32__ || defined _WIN32 || defined WIN32 43 | 44 | BOOL WINAPI DllMain(HINSTANCE hinst, DWORD dwReason, LPVOID lpRes) 45 | { 46 | UNUSED_PARAM(lpRes); 47 | switch (dwReason) { 48 | case DLL_PROCESS_ATTACH: 49 | hinstDLL=hinst; 50 | break; 51 | case DLL_PROCESS_DETACH: 52 | break; 53 | } /* switch */ 54 | return TRUE; 55 | } 56 | 57 | #else 58 | 59 | int FAR PASCAL LibMain(HINSTANCE hinst, WORD wDataSeg, WORD wHeapSize, LPSTR lpszCmdLine) 60 | { 61 | UNUSED_PARAM(wDataSeg); 62 | UNUSED_PARAM(wHeapSize); 63 | UNUSED_PARAM(lpszCmdLine); 64 | hinstDLL=hinst; 65 | return 1; 66 | } 67 | 68 | int FAR PASCAL _export WEP(int param) 69 | { 70 | UNUSED_PARAM(param); 71 | return 1; 72 | } 73 | 74 | #endif /* __WIN32__ */ 75 | 76 | -------------------------------------------------------------------------------- /Runtime/amx/examples/logfile.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "amx.h" 5 | 6 | class LogFile; 7 | static std::map lookup; 8 | 9 | class LogFile { 10 | public: 11 | LogFile() 12 | { 13 | f = tmpfile(); 14 | } 15 | 16 | ~LogFile() 17 | { 18 | fclose(f); 19 | } 20 | 21 | private: 22 | int write(AMX* /*amx*/, const cell params[]) 23 | { 24 | int r = 0; 25 | char *pstr; 26 | 27 | amx_StrParam_Type(amx, params[1], pstr, char*); 28 | if (pstr != NULL) 29 | r = fprintf(f, "%s", pstr); 30 | return r; 31 | } 32 | 33 | FILE *f; 34 | 35 | public: 36 | static cell n_write(AMX* amx, const cell params[]) 37 | { 38 | std::map::iterator p = lookup.find(amx); 39 | if (p != lookup.end()) 40 | return p->second->write(amx, params); 41 | return 0; 42 | } 43 | 44 | }; 45 | 46 | extern "C" 47 | int amx_LogFileInit(AMX* amx) 48 | { 49 | LogFile* lf = new LogFile; 50 | if (lf) { 51 | lookup.insert(std::make_pair(amx, lf)); 52 | 53 | static AMX_NATIVE_INFO nativelist[] = { 54 | { "write", LogFile::n_write }, 55 | { 0, 0 } /* terminator */ 56 | }; 57 | return amx_Register(amx, nativelist, -1); 58 | } /* if */ 59 | return AMX_ERR_MEMORY; 60 | } 61 | 62 | extern "C" 63 | int amx_LogFileExit(AMX* amx) 64 | { 65 | std::map::iterator p = lookup.find(amx); 66 | if (p != lookup.end()) { 67 | delete p->second; 68 | lookup.erase(p); 69 | } /* if */ 70 | return AMX_ERR_NONE; 71 | } 72 | -------------------------------------------------------------------------------- /Runtime/amx/examples/power.c: -------------------------------------------------------------------------------- 1 | /* This file implements two the native functions: power(value,exponent) 2 | * and sqroot(value). 3 | */ 4 | #include "amx.h" 5 | 6 | static cell n_power(AMX *amx, const cell *params) 7 | { 8 | /* power(value, exponent); 9 | * params[1] = value 10 | * params[2] = exponent 11 | */ 12 | cell result = 1; 13 | cell exponent = params[2]; 14 | while (exponent-- > 0) 15 | result *= params[1]; 16 | return result; 17 | } 18 | 19 | static cell n_sqroot(AMX *amx, const cell *params) 20 | { 21 | /* sqroot(value); 22 | * params[1] = value 23 | * This routine uses a simple successice approximation algorithm. 24 | */ 25 | cell div = params[1]; 26 | cell result = 1; 27 | while (div > result) { /* end when div == result, or just below */ 28 | div = (div + result) / 2; /* take mean value as new divisor */ 29 | result = params[1] / div; 30 | } /* while */ 31 | return div; 32 | } 33 | 34 | int amx_PowerInit(AMX *amx) 35 | { 36 | static AMX_NATIVE_INFO power_Natives[] = { 37 | { "power", n_power }, 38 | { "sqroot", n_sqroot }, 39 | { 0, 0 } /* terminator */ 40 | }; 41 | return amx_Register(amx, power_Natives, -1); 42 | } 43 | 44 | int amx_PowerCleanup(AMX *amx) 45 | { 46 | return AMX_ERR_NONE; 47 | } 48 | -------------------------------------------------------------------------------- /Runtime/amx/examples/prun1.c: -------------------------------------------------------------------------------- 1 | /* Command-line shell for the "Pawn" Abstract Machine. 2 | * 3 | * Copyright (c) ITB CompuPhase, 2001-2010 4 | * 5 | * This file may be freely used. No warranties of any kind. 6 | */ 7 | #include 8 | #include /* for exit() */ 9 | #include /* for memset() (on some compilers) */ 10 | #include "amx.h" 11 | #include "amxaux.c" 12 | 13 | void ErrorExit(AMX *amx, int errorcode) 14 | { 15 | printf("Run time error %d: \"%s\" on address %ld\n", 16 | errorcode, aux_StrError(errorcode), 17 | (amx != NULL) ? amx->cip : 0); 18 | exit(1); 19 | } 20 | 21 | void PrintUsage(char *program) 22 | { 23 | printf("Usage: %s \n is a compiled script.\n", program); 24 | exit(1); 25 | } 26 | 27 | int main(int argc,char *argv[]) 28 | { 29 | extern AMX_NATIVE_INFO console_Natives[]; 30 | extern AMX_NATIVE_INFO core_Natives[]; 31 | 32 | AMX amx; 33 | cell ret = 0; 34 | int err; 35 | 36 | if (argc != 2) 37 | PrintUsage(argv[0]); 38 | 39 | err = aux_LoadProgram(&amx, argv[1], NULL); 40 | if (err != AMX_ERR_NONE) 41 | ErrorExit(&amx, err); 42 | 43 | amx_Register(&amx, console_Natives, -1); 44 | err = amx_Register(&amx, core_Natives, -1); 45 | if (err) 46 | ErrorExit(&amx, err); 47 | 48 | err = amx_Exec(&amx, &ret, AMX_EXEC_MAIN); 49 | if (err) 50 | ErrorExit(&amx, err); 51 | printf("%s returns %ld\n", argv[1], (long)ret); 52 | 53 | aux_FreeProgram(&amx); 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /Runtime/amx/examples/prun2.c: -------------------------------------------------------------------------------- 1 | /* Command-line shell for the "Pawn" Abstract Machine. 2 | * 3 | * Copyright (c) ITB CompuPhase, 2001-2010 4 | * 5 | * This file may be freely used. No warranties of any kind. 6 | */ 7 | #include 8 | #include /* for exit() */ 9 | #include 10 | #include /* for memset() (on some compilers) */ 11 | #include "amx.h" 12 | #include "amxaux.c" 13 | 14 | void AMXAPI core_Init(void); /* two functions from AMX_CORE.C */ 15 | void AMXAPI core_Exit(void); 16 | 17 | static int abortflagged = 0; 18 | void sigabort(int sig) 19 | { 20 | abortflagged = 1; 21 | signal(sig, sigabort); /* re-install the signal handler */ 22 | } 23 | 24 | int AMXAPI aux_Monitor(AMX *amx) 25 | { 26 | /* check whether an "abort" was requested */ 27 | return abortflagged ? AMX_ERR_EXIT : AMX_ERR_NONE; 28 | } 29 | 30 | 31 | void ErrorExit(AMX *amx, int errorcode) 32 | { 33 | printf("Run time error %d: \"%s\" on address %ld\n", 34 | errorcode, aux_StrError(errorcode), 35 | (amx != NULL) ? amx->cip : 0); 36 | exit(1); 37 | } 38 | 39 | void PrintUsage(char *program) 40 | { 41 | printf("Usage: %s \n is a compiled script.\n", program); 42 | exit(1); 43 | } 44 | 45 | int main(int argc,char *argv[]) 46 | { 47 | extern AMX_NATIVE_INFO console_Natives[]; 48 | extern AMX_NATIVE_INFO core_Natives[]; 49 | 50 | AMX amx; 51 | cell ret = 0; 52 | int err; 53 | 54 | if (argc != 2) 55 | PrintUsage(argv[0]); 56 | 57 | err = aux_LoadProgram(&amx, argv[1], NULL); 58 | if (err != AMX_ERR_NONE) 59 | ErrorExit(&amx, err); 60 | 61 | amx_Register(&amx, console_Natives, -1); 62 | err = amx_Register(&amx, core_Natives, -1); 63 | if (err) 64 | ErrorExit(&amx, err); 65 | 66 | amx_SetDebugHook(&amx, aux_Monitor); 67 | signal(SIGINT, sigabort); 68 | 69 | err = amx_Exec(&amx, &ret, AMX_EXEC_MAIN); 70 | if (err) 71 | ErrorExit(&amx, err); 72 | printf("%s returns %ld\n", argv[1], (long)ret); 73 | 74 | aux_FreeProgram(&amx); 75 | return 0; 76 | } 77 | -------------------------------------------------------------------------------- /Runtime/amx/examples/prun4.c: -------------------------------------------------------------------------------- 1 | /* Command-line shell for the "Pawn" Abstract Machine. 2 | * 3 | * Copyright (c) ITB CompuPhase, 2001-2010 4 | * 5 | * This file may be freely used. No warranties of any kind. 6 | */ 7 | #include 8 | #include /* for exit() */ 9 | #include /* for memset() (on some compilers) */ 10 | #include "amx.h" 11 | #include "amxaux.c" 12 | 13 | 14 | void ErrorExit(AMX *amx, int errorcode) 15 | { 16 | printf("Run time error %d: \"%s\" on address %ld\n", 17 | errorcode, aux_StrError(errorcode), 18 | (amx != NULL) ? amx->cip : 0); 19 | exit(1); 20 | } 21 | 22 | void PrintUsage(char *program) 23 | { 24 | printf("Usage: %s \n", program); 25 | exit(1); 26 | } 27 | 28 | int main(int argc, char *argv[]) 29 | { 30 | extern int AMXAPI amx_ConsoleInit(AMX *amx); 31 | extern int AMXAPI amx_ConsoleCleanup(AMX *amx); 32 | extern int AMXAPI amx_CoreInit(AMX *amx); 33 | extern int AMXAPI amx_CoreCleanup(AMX *amx); 34 | 35 | size_t memsize; 36 | void *program; 37 | AMX amx; 38 | int index, err; 39 | cell *address; 40 | char output[128]; 41 | 42 | if (argc != 4) 43 | PrintUsage(argv[0]); 44 | if ((memsize = aux_ProgramSize(argv[1])) == 0) 45 | PrintUsage(argv[0]); 46 | 47 | program = malloc(memsize); 48 | if (program == NULL) 49 | ErrorExit(NULL, AMX_ERR_MEMORY); 50 | 51 | err = aux_LoadProgram(&amx, argv[1], program); 52 | if (err) 53 | ErrorExit(&amx, err); 54 | 55 | amx_ConsoleInit(&amx); 56 | err = amx_CoreInit(&amx); 57 | if (err) 58 | ErrorExit(&amx, err); 59 | 60 | err = amx_FindPublic(&amx, argv[2], &index); 61 | if (err) 62 | ErrorExit(&amx, err); 63 | 64 | err = amx_PushString(&amx, &address, argv[3], 0, 0); 65 | if (err) 66 | ErrorExit(&amx, err); 67 | 68 | err = amx_Exec(&amx, NULL, index); 69 | if (err) 70 | ErrorExit(&amx, err); 71 | 72 | amx_GetString(output, address, 0, sizeof output); 73 | amx_Release(&amx, address); 74 | printf("%s returns %s\n", argv[1], output); 75 | 76 | amx_ConsoleCleanup(&amx); 77 | amx_CoreCleanup(&amx); 78 | amx_Cleanup(&amx); 79 | free(program); 80 | return 0; 81 | } 82 | -------------------------------------------------------------------------------- /Runtime/amx/fpattern.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PetteriAimonen/QuadPawn/704ea78c61738574bb62407f503fc49a13ffb405/Runtime/amx/fpattern.h -------------------------------------------------------------------------------- /Runtime/amx/keeloq.c: -------------------------------------------------------------------------------- 1 | /*\ 2 | * Corrected KeeLoq Encryption and Decryption functions by Ruptor. 3 | * Use at your own risk! This source is not copyrighted. 4 | * Encoder encrypts an all-0 block, decoder decrypts it. 5 | * KeeLoq cipher encrypts 32-bit blocks with 64-bit keys. 6 | * Key is XORed with a 32-bit IV incremented on each use. 7 | * See http://www.keeloq.boom.ru/decryption.pdf for more details. 8 | * KeeLoq algorithm itself is not patented. 9 | \*/ 10 | #include "amx.h" 11 | 12 | #define KeeLoq_NLF 0x3A5C742E 13 | #define bit(x,n) (((x)>>(n))&1) 14 | #define g5(x,a,b,c,d,e) (bit(x,a)+bit(x,b)*2+bit(x,c)*4+bit(x,d)*8+bit(x,e)*16) 15 | 16 | uint32_t KeeLoq_Encrypt (const uint32_t data, const uint64_t key) 17 | { 18 | uint32_t x = data, r; 19 | 20 | for (r = 0; r < 528; r++) 21 | { 22 | x = (x>>1)^((bit(x,0)^bit(x,16)^(uint32_t)bit(key,r&63)^bit(KeeLoq_NLF,g5(x,1,9,20,26,31)))<<31); 23 | } 24 | return x; 25 | } 26 | 27 | uint32_t KeeLoq_Decrypt (const uint32_t data, const uint64_t key) 28 | { 29 | uint32_t x = data, r; 30 | 31 | for (r = 0; r < 528; r++) 32 | { 33 | x = (x<<1)^bit(x,31)^bit(x,15)^(uint32_t)bit(key,(15-r)&63)^bit(KeeLoq_NLF,g5(x,0,8,19,25,30)); 34 | } 35 | return x; 36 | } 37 | -------------------------------------------------------------------------------- /Runtime/amx/keeloq.h: -------------------------------------------------------------------------------- 1 | /* see keeloq.c for information */ 2 | uint32_t KeeLoq_Encrypt (const uint32_t data, const uint64_t key); 3 | uint32_t KeeLoq_Decrypt (const uint32_t data, const uint64_t key); 4 | -------------------------------------------------------------------------------- /Runtime/amx/minGlue.h: -------------------------------------------------------------------------------- 1 | /* Glue functions for the minIni library, based on the C/C++ stdio library 2 | * 3 | * Or better said: this file contains macros that maps the function interface 4 | * used by minIni to the standard C/C++ file I/O functions. 5 | * 6 | * Copyright (c) ITB CompuPhase, 2008-2010 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 9 | * use this file except in compliance with the License. You may obtain a copy 10 | * of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 16 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 17 | * License for the specific language governing permissions and limitations 18 | * under the License. 19 | * 20 | * Version: $Id: minGlue.h 4234 2010-03-30 09:04:26Z thiadmer $ 21 | */ 22 | 23 | /* map required file I/O to the standard C library */ 24 | #include 25 | #define ini_openread(filename,file) ((*(file) = fopen((filename),"rt")) != NULL) 26 | #define ini_openwrite(filename,file) ((*(file) = fopen((filename),"wt")) != NULL) 27 | #define ini_close(file) fclose(*(file)) 28 | #define ini_read(buffer,size,file) fgets((buffer),(size),*(file)) 29 | #define ini_write(buffer,file) fputs((buffer),*(file)) 30 | #define ini_rename(source,dest) rename((source),(dest)) 31 | #define ini_remove(filename) remove(filename) 32 | #define ini_rewind(file) rewind(*(file)) 33 | -------------------------------------------------------------------------------- /Runtime/amx/pawndbg.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PetteriAimonen/QuadPawn/704ea78c61738574bb62407f503fc49a13ffb405/Runtime/amx/pawndbg.c -------------------------------------------------------------------------------- /Runtime/amx/term_ga.h: -------------------------------------------------------------------------------- 1 | /* Simple terminal using GraphApp 2 | * 3 | * Copyright (c) ITB CompuPhase, 2004-2011 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 6 | * use this file except in compliance with the License. You may obtain a copy 7 | * of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | * 17 | * Version: $Id: term_ga.h 4523 2011-06-21 15:03:47Z thiadmer $ 18 | */ 19 | 20 | #if !defined TERMGA_H_INCLUDED 21 | #define TERMGA_H_INCLUDED 22 | 23 | #if defined _UNICODE || defined __UNICODE__ || defined UNICODE 24 | # if !defined UNICODE /* for Windows */ 25 | # define UNICODE 26 | # endif 27 | # if !defined _UNICODE /* for C library */ 28 | # define _UNICODE 29 | # endif 30 | #endif 31 | 32 | #if defined _UNICODE 33 | # include 34 | #elif !defined __T 35 | typedef char TCHAR; 36 | # define __T(string) string 37 | # define _tcschr strchr 38 | # define _tcscpy strcpy 39 | # define _tcsdup strdup 40 | # define _tcslen strlen 41 | # define _stprintf sprintf 42 | # define _vstprintf vsprintf 43 | #endif 44 | 45 | #ifdef __cplusplus 46 | extern "C" { 47 | #endif 48 | 49 | int createconsole(int argc, char *argv[]); 50 | int deleteconsole(void); 51 | 52 | int amx_printf(const TCHAR*,...); 53 | int amx_putstr(const TCHAR*); 54 | int amx_putchar(int); 55 | int amx_fflush(void); 56 | int amx_kbhit(void); 57 | int amx_getch(void); 58 | TCHAR* amx_gets(TCHAR*,int); 59 | int amx_termctl(int,int); 60 | void amx_clrscr(void); 61 | void amx_clreol(void); 62 | void amx_gotoxy(int x,int y); 63 | void amx_wherexy(int *x,int *y); 64 | unsigned amx_setattr(int foregr,int backgr,int highlight); 65 | void amx_console(int columns, int lines, int flags); 66 | 67 | #ifdef __cplusplus 68 | } 69 | #endif 70 | 71 | #endif /* TERMGA_H_INCLUDED */ 72 | -------------------------------------------------------------------------------- /Runtime/amx_buttons.c: -------------------------------------------------------------------------------- 1 | /* Polling interface to buttons */ 2 | 3 | #include "amx.h" 4 | #include "buttons.h" 5 | 6 | static cell AMX_NATIVE_CALL amx_peek_keys(AMX *amx, const cell *params) 7 | { 8 | return peek_keys(params[1]); 9 | } 10 | 11 | static cell AMX_NATIVE_CALL amx_get_keys(AMX *amx, const cell *params) 12 | { 13 | return get_keys(params[1]); 14 | } 15 | 16 | static cell AMX_NATIVE_CALL amx_held_keys(AMX *amx, const cell *params) 17 | { 18 | return held_keys(params[1], (uint32_t*)params[2]); 19 | } 20 | 21 | static cell AMX_NATIVE_CALL amx_scroller_speed(AMX *amx, const cell *params) 22 | { 23 | return scroller_speed(); 24 | } 25 | 26 | int amxinit_buttons(AMX *amx) 27 | { 28 | static const AMX_NATIVE_INFO funcs[] = { 29 | {"peek_keys", amx_peek_keys}, 30 | {"get_keys", amx_get_keys}, 31 | {"held_keys", amx_held_keys}, 32 | {"scroller_speed", amx_scroller_speed}, 33 | {0, 0} 34 | }; 35 | 36 | return amx_Register(amx, funcs, -1); 37 | } 38 | -------------------------------------------------------------------------------- /Runtime/amx_debug.h: -------------------------------------------------------------------------------- 1 | /* This is a bunch of functions to print traceback information when a 2 | * Pawn program crashes. It differs from the stock amxdbg.c by accessing 3 | * the debug information from the file instead of loading it all to RAM. 4 | */ 5 | 6 | #pragma once 7 | #include 8 | #include "ff.h" 9 | #include "amxdbg.h" // For definition of AMX_DBG_HDR 10 | 11 | typedef struct { 12 | AMX_DBG_HDR header; 13 | FIL *file; 14 | const AMX *amx; 15 | 16 | // Offsets to the tables, relative to file start 17 | unsigned filetbl_offset; 18 | unsigned linetbl_offset; 19 | unsigned symboltbl_offset; 20 | } AMX_DEBUG_INFO; 21 | 22 | // Load the debug header and find table locations in the file 23 | // Note: the file pointer is stored in dbg, so dbg will be invalid 24 | // once the file is closed. 25 | bool amxdbg_load(FIL* file, const AMX* amx, AMX_DEBUG_INFO *dbg); 26 | 27 | // Find the file and line that correspond to given instruction 28 | bool amxdbg_find_location(AMX_DEBUG_INFO *dbg, unsigned instruction_pointer, 29 | char *location, unsigned location_size); 30 | 31 | // Format locals and their values to a string 32 | bool amxdbg_format_locals(AMX_DEBUG_INFO *dbg, AMX *amx, 33 | unsigned frame, unsigned instruction_pointer, 34 | char *dest, int dest_size); 35 | 36 | // Get the previous caller from the call stack and the frame pointer of it 37 | // Returns the instruction pointer to the CALL instruction, or 0 if there are no more callers. 38 | unsigned amxdbg_get_caller(AMX *amx, unsigned *frame); 39 | -------------------------------------------------------------------------------- /Runtime/amx_device.c: -------------------------------------------------------------------------------- 1 | /* Device backlight etc. */ 2 | 3 | #include "amx.h" 4 | #include "buttons.h" 5 | #include "BIOS.h" 6 | #include 7 | 8 | static cell AMX_NATIVE_CALL amx_set_backlight(AMX *amx, const cell *params) 9 | { 10 | __Set(BACKLIGHT, params[1]); 11 | return 0; 12 | } 13 | 14 | static cell AMX_NATIVE_CALL amx_set_powersave(AMX *amx, const cell *params) 15 | { 16 | if (params[1]) 17 | { 18 | __Set(BACKLIGHT, 0); 19 | __Set(STANDBY, 1); 20 | } 21 | else 22 | { 23 | __Set(STANDBY, 0); 24 | } 25 | 26 | return 0; 27 | } 28 | 29 | static cell AMX_NATIVE_CALL amx_beep(AMX *amx, const cell *params) 30 | { 31 | // beep(milliseconds = 500, frequency = 400, volume = 80); 32 | 33 | int psc = 72000000 / 100 / params[2]; 34 | if (psc > 7200) psc = 7200; 35 | if (psc < 36) psc = 36; 36 | 37 | TIM8->PSC = psc; 38 | 39 | beep(params[1], params[3]); 40 | return 0; 41 | } 42 | 43 | static cell AMX_NATIVE_CALL amx_battery_voltage(AMX *amx, const cell *params) 44 | { 45 | __Set(BETTERY_DT, 1); // Start battery voltage measurement 46 | delay_ms(1); 47 | return __Get(V_BATTERY); 48 | } 49 | 50 | static cell AMX_NATIVE_CALL amx_read_flash(AMX *amx, const cell *params) 51 | { 52 | if ((params[1] >= 0x08000000 ) && (params[1] <= 0x08080000)) { 53 | return *(char *)( params[1] ); 54 | } else { 55 | return 0; 56 | } 57 | } 58 | 59 | static cell AMX_NATIVE_CALL amx_read_SN(AMX *amx , const cell *params) 60 | { 61 | return __GetDev_SN(); 62 | } 63 | 64 | 65 | 66 | int amxinit_device(AMX *amx) 67 | { 68 | static const AMX_NATIVE_INFO funcs[] = { 69 | {"set_backlight", amx_set_backlight}, 70 | {"set_powersave", amx_set_powersave}, 71 | {"beep", amx_beep}, 72 | {"battery_voltage", amx_battery_voltage}, 73 | {"read_flash", amx_read_flash}, 74 | {"read_SN", amx_read_SN}, 75 | {0, 0} 76 | }; 77 | 78 | return amx_Register(amx, funcs, -1); 79 | } 80 | -------------------------------------------------------------------------------- /Runtime/amx_fixed.c: -------------------------------------------------------------------------------- 1 | /* Bindings from PAWN to libfixmath */ 2 | 3 | #include "amx.h" 4 | #include "fix16.h" 5 | 6 | static cell AMX_NATIVE_CALL amx_fadd(AMX *amx, const cell *params) 7 | { 8 | return fix16_sadd(params[1], params[2]); 9 | } 10 | 11 | static cell AMX_NATIVE_CALL amx_fsub(AMX *amx, const cell *params) 12 | { 13 | return fix16_ssub(params[1], params[2]); 14 | } 15 | 16 | static cell AMX_NATIVE_CALL amx_fmul(AMX *amx, const cell *params) 17 | { 18 | return fix16_smul(params[1], params[2]); 19 | } 20 | 21 | static cell AMX_NATIVE_CALL amx_fdiv(AMX *amx, const cell *params) 22 | { 23 | return fix16_sdiv(params[1], params[2]); 24 | } 25 | 26 | static cell AMX_NATIVE_CALL amx_fixed(AMX *amx, const cell *params) 27 | { 28 | return fix16_from_int(params[1]); 29 | } 30 | 31 | static cell AMX_NATIVE_CALL amx_fround(AMX *amx, const cell *params) 32 | { 33 | return fix16_to_int(params[1]); 34 | } 35 | 36 | static cell AMX_NATIVE_CALL amx_exp(AMX *amx, const cell *params) 37 | { 38 | return fix16_exp(params[1]); 39 | } 40 | 41 | static cell AMX_NATIVE_CALL amx_log(AMX *amx, const cell *params) 42 | { 43 | return fix16_log(params[1]); 44 | } 45 | 46 | static cell AMX_NATIVE_CALL amx_sqrt(AMX *amx, const cell *params) 47 | { 48 | return fix16_sqrt(params[1]); 49 | } 50 | 51 | static cell AMX_NATIVE_CALL amx_sin(AMX *amx, const cell *params) 52 | { 53 | return fix16_sin(params[1]); 54 | } 55 | 56 | static cell AMX_NATIVE_CALL amx_atan2(AMX *amx, const cell *params) 57 | { 58 | return fix16_atan2(params[1], params[2]); 59 | } 60 | 61 | int amxinit_fixed(AMX *amx) 62 | { 63 | static const AMX_NATIVE_INFO funcs[] = { 64 | {"fadd", amx_fadd}, 65 | {"fsub", amx_fsub}, 66 | {"fmul", amx_fmul}, 67 | {"fdiv", amx_fdiv}, 68 | {"fixed", amx_fixed}, 69 | {"fround", amx_fround}, 70 | {"exp", amx_exp}, 71 | {"log", amx_log}, 72 | {"sqrt", amx_sqrt}, 73 | {"sin", amx_sin}, 74 | {"atan2", amx_atan2}, 75 | {0, 0} 76 | }; 77 | 78 | return amx_Register(amx, funcs, -1); 79 | } 80 | -------------------------------------------------------------------------------- /Runtime/amx_menu.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | int amx_menu_doevents(AMX *amx); 4 | int amxinit_menu(AMX *amx); -------------------------------------------------------------------------------- /Runtime/amx_string.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "amx.h" 4 | 5 | static cell AMX_NATIVE_CALL amx_strlen(AMX *amx, const cell *params) 6 | { 7 | int result = 0; 8 | amx_StrLen((cell*)params[1], &result); 9 | return result; 10 | } 11 | 12 | static cell AMX_NATIVE_CALL amx_strval(AMX *amx, const cell *params) 13 | { 14 | // strval(const string[], index, endindex, base); 15 | char *text; 16 | amx_StrParam(amx, params[1], text); 17 | char *start = text + params[2]; 18 | int base = params[4]; 19 | 20 | char *endptr; 21 | int result = strtol(text, &endptr, base); 22 | *((cell*)params[3]) = endptr - text; 23 | return result; 24 | } 25 | 26 | static cell AMX_NATIVE_CALL amx_valstr(AMX *amx, const cell *params) 27 | { 28 | // valstr(dest[], value, maxlength = sizeof dest, base = 10, minlength = 0); 29 | char dest[36]; 30 | int value = params[2]; 31 | int base = params[4]; 32 | int minlength = params[5]; 33 | int count = 0; 34 | 35 | dest[35] = 0; 36 | char *p = dest + 34; 37 | int maxlength = 32; 38 | 39 | bool negative = (value < 0); 40 | if (negative) value = -value; 41 | 42 | if (value == 0) 43 | { 44 | *p-- = '0'; 45 | count++; 46 | } 47 | else 48 | { 49 | while (value && count < maxlength) 50 | { 51 | int digit = value % base; 52 | value /= base; 53 | 54 | *p-- = (digit < 10) ? (digit + '0') : (digit - 10 + 'A'); 55 | count++; 56 | } 57 | } 58 | 59 | while (count < minlength) 60 | { 61 | *p-- = '0'; 62 | count++; 63 | } 64 | 65 | if (negative) 66 | { 67 | *p-- = '-'; 68 | count++; 69 | } 70 | 71 | amx_SetString((cell*)params[1], p+1, true, false, params[3]); 72 | return count; 73 | } 74 | 75 | int amxinit_string(AMX *amx) 76 | { 77 | static const AMX_NATIVE_INFO funcs[] = { 78 | {"strlen", amx_strlen}, 79 | {"strval", amx_strval}, 80 | {"valstr", amx_valstr}, 81 | {0, 0} 82 | }; 83 | 84 | return amx_Register(amx, funcs, -1); 85 | } 86 | -------------------------------------------------------------------------------- /Runtime/amx_time.c: -------------------------------------------------------------------------------- 1 | /* Time functions based on the 1ms tick. */ 2 | 3 | #include "buttons.h" 4 | #include "amx.h" 5 | 6 | static cell AMX_NATIVE_CALL amx_get_time(AMX *amx, const cell *params) 7 | { 8 | return get_time(); 9 | } 10 | 11 | static cell AMX_NATIVE_CALL amx_delay_ms(AMX *amx, const cell *params) 12 | { 13 | delay_ms(params[1]); 14 | return 0; 15 | } 16 | 17 | static uint32_t timer_period = 0; 18 | static uint32_t timer_last_tick; 19 | static int timer_func = -1; 20 | 21 | static cell AMX_NATIVE_CALL amx_set_timer(AMX *amx, const cell *params) 22 | { 23 | timer_period = params[1]; 24 | timer_last_tick = get_time(); 25 | return 0; 26 | } 27 | 28 | int amx_timer_doevents(AMX *amx) 29 | { 30 | int status; 31 | cell retval; 32 | 33 | if (timer_func != -1 && timer_period != 0 && 34 | get_time() - timer_last_tick >= timer_period) 35 | { 36 | status = amx_Exec(amx, &retval, timer_func); 37 | return status; 38 | } 39 | 40 | return 0; 41 | } 42 | 43 | int amxinit_time(AMX *amx) 44 | { 45 | static const AMX_NATIVE_INFO funcs[] = { 46 | {"get_time", amx_get_time}, 47 | {"delay_ms", amx_delay_ms}, 48 | {"set_timer", amx_set_timer}, 49 | {0, 0} 50 | }; 51 | 52 | if (amx_FindPublic(amx, "@timertick", &timer_func) != 0) 53 | timer_func = -1; 54 | 55 | return amx_Register(amx, funcs, -1); 56 | } -------------------------------------------------------------------------------- /Runtime/amx_waveout.c: -------------------------------------------------------------------------------- 1 | /* Functions for accessing the DAC from Pawn. */ 2 | 3 | #include "amx.h" 4 | #include "BIOS.h" 5 | #include "stm32f10x.h" 6 | #include "mathutils.h" 7 | #include "fix16.h" 8 | 9 | static cell AMX_NATIVE_CALL amx_waveout_analog(AMX *amx, const cell *params) 10 | { 11 | cell *buffer = (cell*)params[1]; 12 | int samplerate = params[2]; 13 | int count = params[3]; 14 | 15 | int prescale = (CPUFREQ / 65536) / samplerate; 16 | int arr = div_round_up(CPUFREQ / (prescale + 1), samplerate) - 1; 17 | 18 | DAC->CR = 0; 19 | TIM7->PSC = prescale; 20 | DMA2_Channel4->CCR &= ~DMA_CCR1_EN; 21 | DMA2_Channel4->CMAR = (uint32_t)buffer; 22 | DMA2_Channel4->CNDTR = count; 23 | DMA2_Channel4->CCR = 0x1AB1; 24 | DMA2_Channel4->CCR |= DMA_CCR1_EN; 25 | 26 | __Set(ANALOG_ARR, arr); 27 | 28 | // Turn off the DAC output buffer - it limits the voltage range. 29 | DAC->CR |= DAC_CR_BOFF1; 30 | 31 | return div_round(CPUFREQ / (prescale + 1), arr + 1); 32 | } 33 | 34 | static cell AMX_NATIVE_CALL amx_waveout_digital(AMX *amx, const cell *params) 35 | { 36 | int frequency = params[1]; 37 | fix16_t duty = params[2]; 38 | 39 | int prescale = (CPUFREQ / 65536) / frequency; 40 | int arr = div_round_up(CPUFREQ / (prescale + 1), frequency) - 1; 41 | int ccr = fix16_mul(duty, arr + 1); 42 | 43 | if (arr == 0) return 0; 44 | 45 | __Set(DIGTAL_ARR, arr); 46 | __Set(DIGTAL_PSC, prescale); 47 | __Set(DIGTAL_CCR, ccr); 48 | 49 | return div_round(CPUFREQ / (prescale + 1), arr + 1); 50 | } 51 | 52 | int amxinit_waveout(AMX *amx) 53 | { 54 | static const AMX_NATIVE_INFO funcs[] = { 55 | {"waveout_analog", amx_waveout_analog}, 56 | {"waveout_digital", amx_waveout_digital}, 57 | {0, 0} 58 | }; 59 | 60 | return amx_Register(amx, funcs, -1); 61 | 62 | } -------------------------------------------------------------------------------- /Runtime/baselibc/.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.a 3 | -------------------------------------------------------------------------------- /Runtime/baselibc/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -fno-common -Os -g -Wall -Werror -I include 2 | 3 | # Platform specific settings 4 | CC = arm-none-eabi-gcc 5 | AR = arm-none-eabi-ar 6 | CFLAGS += -mcpu=cortex-m3 -mthumb 7 | 8 | ifdef windir 9 | RM = del 10 | endif 11 | 12 | FILES = src/asprintf.o src/atoi.o src/atol.o \ 13 | src/atoll.o src/bsearch.o src/bzero.o \ 14 | src/calloc.o src/fgets.o \ 15 | src/inline.o \ 16 | src/jrand48.o src/lrand48.o src/malloc.o src/memccpy.o \ 17 | src/memchr.o src/memcmp.o src/memcpy.o src/memmem.o \ 18 | src/memmove.o src/memrchr.o src/memset.o src/memswap.o \ 19 | src/mrand48.o src/nrand48.o src/qsort.o \ 20 | src/realloc.o \ 21 | src/srand48.o src/sscanf.o src/strcasecmp.o \ 22 | src/strcat.o src/strchr.o src/strcmp.o src/strcpy.o \ 23 | src/strcspn.o src/strdup.o src/strlcat.o \ 24 | src/strlcpy.o src/strlen.o src/strncasecmp.o src/strncat.o \ 25 | src/strncmp.o src/strncpy.o src/strndup.o src/strnlen.o \ 26 | src/strntoimax.o src/strntoumax.o src/strpbrk.o \ 27 | src/strrchr.o src/strsep.o src/strspn.o src/strstr.o \ 28 | src/strtoimax.o src/strtok.o src/strtok_r.o src/strtol.o \ 29 | src/strtoll.o src/strtoul.o src/strtoull.o \ 30 | src/strtoumax.o 31 | 32 | # For proper printf 33 | #FILES += src/fprintf.o src/vasprintf.o src/vfprintf.o src/vprintf.o \ 34 | # src/vsnprintf.o src/vsprintf.o src/vsscanf.o src/snprintf.o \ 35 | # src/printf.o 36 | 37 | # For tiny printf 38 | FILES += src/tinyprintf.o 39 | 40 | 41 | all: libc.a 42 | 43 | clean: 44 | $(RM) $(FILES) libc.a 45 | 46 | libc.a: $(FILES) 47 | $(RM) $@ 48 | $(AR) ru $@ $^ 49 | 50 | %.o: %.c 51 | $(CC) $(CFLAGS) -c -o $@ $< 52 | -------------------------------------------------------------------------------- /Runtime/baselibc/README.md: -------------------------------------------------------------------------------- 1 | Baselibc 2 | ======== 3 | This is a very simple libc for embedded systems. Mainly geared for 32-bit microcontrollers in the 10-100kB memory range. 4 | 5 | The code is based on klibc and tinyprintf modules. License is therefore GPL. 6 | -------------------------------------------------------------------------------- /Runtime/baselibc/include/assert.h: -------------------------------------------------------------------------------- 1 | /* 2 | * assert.h 3 | */ 4 | 5 | #ifndef _ASSERT_H 6 | #define _ASSERT_H 7 | 8 | #ifdef NDEBUG 9 | 10 | /* 11 | * NDEBUG doesn't just suppress the faulting behavior of assert(), 12 | * but also all side effects of the assert() argument. This behavior 13 | * is required by the C standard, and allows the argument to reference 14 | * variables that are not defined without NDEBUG. 15 | */ 16 | #define assert(x) ((void)(0)) 17 | 18 | #else 19 | 20 | extern void __assert_fail(const char *, const char *, unsigned int); 21 | 22 | #define assert(x) ((x) ? (void)0 : __assert_fail(#x, __FILE__, __LINE__)) 23 | 24 | #endif 25 | 26 | #endif /* _ASSERT_H */ 27 | -------------------------------------------------------------------------------- /Runtime/baselibc/include/ctype.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ctype.h 3 | * 4 | * This assumes ASCII. 5 | */ 6 | 7 | #ifndef _CTYPE_H 8 | #define _CTYPE_H 9 | 10 | #include 11 | #include 12 | 13 | __extern_inline int isupper(int __c) 14 | { 15 | return __c >= 'A' && __c <= 'Z'; 16 | } 17 | 18 | __extern_inline int islower(int __c) 19 | { 20 | return __c >= 'a' && __c <= 'z'; 21 | } 22 | 23 | __extern_inline int isalpha(int __c) 24 | { 25 | return islower(__c) || isupper(__c); 26 | } 27 | 28 | __extern_inline int isdigit(int __c) 29 | { 30 | return ((unsigned)__c - '0') <= 9; 31 | } 32 | 33 | __extern_inline int isalnum(int __c) 34 | { 35 | return isalpha(__c) || isdigit(__c); 36 | } 37 | 38 | __extern_inline int isascii(int __c) 39 | { 40 | return !(__c & ~0x7f); 41 | } 42 | 43 | __extern_inline int isblank(int __c) 44 | { 45 | return (__c == '\t') || (__c == ' '); 46 | } 47 | 48 | __extern_inline int iscntrl(int __c) 49 | { 50 | return __c < 0x20; 51 | } 52 | 53 | __extern_inline int isspace(int __c) 54 | { 55 | return __c == ' ' || __c == '\n' || __c == '\t' || __c == '\r'; 56 | } 57 | 58 | __extern_inline int isxdigit(int __c) 59 | { 60 | return isdigit(__c) || (__c >= 'a' && __c <= 'f') || (__c >= 'A' && __c <= 'F'); 61 | } 62 | 63 | __extern_inline int toupper(int __c) 64 | { 65 | return islower(__c) ? (__c & ~32) : __c; 66 | } 67 | 68 | __extern_inline int tolower(int __c) 69 | { 70 | return isupper(__c) ? (__c | 32) : __c; 71 | } 72 | 73 | #endif /* _CTYPE_H */ 74 | -------------------------------------------------------------------------------- /Runtime/baselibc/include/klibc/extern.h: -------------------------------------------------------------------------------- 1 | /* 2 | * klibc/extern.h 3 | */ 4 | 5 | #ifndef _KLIBC_EXTERN_H 6 | #define _KLIBC_EXTERN_H 7 | 8 | #ifdef __cplusplus 9 | #define __extern extern "C" 10 | #else 11 | #define __extern extern 12 | #endif 13 | 14 | #define __alias(x) __attribute__((weak, alias(x))) 15 | 16 | #endif /* _KLIBC_EXTERN_H */ 17 | -------------------------------------------------------------------------------- /Runtime/baselibc/include/klibc/inline.h: -------------------------------------------------------------------------------- 1 | /* 2 | * klibc/inline.h 3 | */ 4 | 5 | #ifndef _KLIBC_INLINE_H 6 | #define _KLIBC_INLINE_H 7 | 8 | #ifndef __extern_inline 9 | #define __extern_inline extern inline __attribute__((gnu_inline)) 10 | #endif 11 | 12 | #endif /* _KLIBC_INLINE_H */ 13 | -------------------------------------------------------------------------------- /Runtime/baselibc/include/stdlib.h: -------------------------------------------------------------------------------- 1 | /* 2 | * stdlib.h 3 | */ 4 | 5 | #ifndef _STDLIB_H 6 | #define _STDLIB_H 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | __extern_inline int abs(int __n) 14 | { 15 | return (__n < 0) ? -__n : __n; 16 | } 17 | 18 | __extern int atoi(const char *); 19 | __extern long atol(const char *); 20 | __extern long long atoll(const char *); 21 | 22 | __extern_inline long labs(long __n) 23 | { 24 | return (__n < 0L) ? -__n : __n; 25 | } 26 | 27 | __extern_inline long long llabs(long long __n) 28 | { 29 | return (__n < 0LL) ? -__n : __n; 30 | } 31 | 32 | __extern void free(void *); 33 | __extern void *malloc(size_t); 34 | __extern void *calloc(size_t, size_t); 35 | __extern void *realloc(void *, size_t); 36 | 37 | /* Giving malloc some memory from which to allocate */ 38 | __extern void add_malloc_block(void *, size_t); 39 | __extern void get_malloc_memory_status(size_t *, size_t *); 40 | 41 | /* Malloc locking 42 | * Until the callbacks are set, malloc doesn't do any locking. 43 | * malloc_lock() *may* timeout, in which case malloc() will return NULL. 44 | */ 45 | typedef bool (*malloc_lock_t)(); 46 | typedef void (*malloc_unlock_t)(); 47 | __extern void set_malloc_locking(malloc_lock_t, malloc_unlock_t); 48 | 49 | __extern long strtol(const char *, char **, int); 50 | __extern long long strtoll(const char *, char **, int); 51 | __extern unsigned long strtoul(const char *, char **, int); 52 | __extern unsigned long long strtoull(const char *, char **, int); 53 | 54 | typedef int (*__comparefunc_t) (const void *, const void *); 55 | __extern void *bsearch(const void *, const void *, size_t, size_t, 56 | __comparefunc_t); 57 | __extern void qsort(void *, size_t, size_t, __comparefunc_t); 58 | 59 | __extern long jrand48(unsigned short *); 60 | __extern long mrand48(void); 61 | __extern long nrand48(unsigned short *); 62 | __extern long lrand48(void); 63 | __extern unsigned short *seed48(const unsigned short *); 64 | __extern void srand48(long); 65 | 66 | #define RAND_MAX 0x7fffffff 67 | __extern_inline int rand(void) 68 | { 69 | return (int)lrand48(); 70 | } 71 | __extern_inline void srand(unsigned int __s) 72 | { 73 | srand48(__s); 74 | } 75 | __extern_inline long random(void) 76 | { 77 | return lrand48(); 78 | } 79 | __extern_inline void srandom(unsigned int __s) 80 | { 81 | srand48(__s); 82 | } 83 | 84 | #endif /* _STDLIB_H */ 85 | -------------------------------------------------------------------------------- /Runtime/baselibc/include/tinyprintf.h: -------------------------------------------------------------------------------- 1 | #ifndef _TINYPRINTF_H_ 2 | #define _TINYPRINTF_H_ 3 | 4 | #include 5 | #include 6 | 7 | typedef void (*putcf) (void *, char); 8 | 9 | void tfp_format(void *putp, putcf putf, const char *fmt, va_list va); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/asprintf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * asprintf.c 3 | */ 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | int asprintf(char **bufp, const char *format, ...) 10 | { 11 | va_list ap, ap1; 12 | int rv; 13 | int bytes; 14 | char *p; 15 | 16 | va_start(ap, format); 17 | va_copy(ap1, ap); 18 | 19 | bytes = vsnprintf(NULL, 0, format, ap1) + 1; 20 | va_end(ap1); 21 | 22 | *bufp = p = malloc(bytes); 23 | if (!p) 24 | return -1; 25 | 26 | rv = vsnprintf(p, bytes, format, ap); 27 | va_end(ap); 28 | 29 | return rv; 30 | } 31 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/atoi.c: -------------------------------------------------------------------------------- 1 | #define TYPE int 2 | #define NAME atoi 3 | #include "atox.c" 4 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/atol.c: -------------------------------------------------------------------------------- 1 | #define TYPE long 2 | #define NAME atol 3 | #include "atox.c" 4 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/atoll.c: -------------------------------------------------------------------------------- 1 | #define TYPE long long 2 | #define NAME atoll 3 | #include "atox.c" 4 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/atox.c: -------------------------------------------------------------------------------- 1 | /* 2 | * atox.c 3 | * 4 | * atoi(), atol(), atoll() 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | TYPE NAME(const char *nptr) 12 | { 13 | return (TYPE) strntoumax(nptr, (char **)NULL, 10, ~(size_t) 0); 14 | } 15 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/bsearch.c: -------------------------------------------------------------------------------- 1 | /* 2 | * bsearch.c 3 | */ 4 | 5 | #include 6 | 7 | void *bsearch(const void *key, const void *base, size_t nmemb, 8 | size_t size, int (*cmp) (const void *, const void *)) 9 | { 10 | while (nmemb) { 11 | size_t mididx = nmemb / 2; 12 | const void *midobj = base + mididx * size; 13 | int diff = cmp(key, midobj); 14 | 15 | if (diff == 0) 16 | return (void *)midobj; 17 | 18 | if (diff > 0) { 19 | base = midobj + size; 20 | nmemb -= mididx + 1; 21 | } else 22 | nmemb = mididx; 23 | } 24 | 25 | return NULL; 26 | } 27 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/bzero.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void bzero(void *dst, size_t n) 4 | { 5 | memset(dst, 0, n); 6 | } 7 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/calloc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * calloc.c 3 | */ 4 | 5 | #include 6 | #include 7 | 8 | /* FIXME: This should look for multiplication overflow */ 9 | 10 | void *calloc(size_t nmemb, size_t size) 11 | { 12 | void *ptr; 13 | 14 | size *= nmemb; 15 | ptr = malloc(size); 16 | if (ptr) 17 | memset(ptr, 0, size); 18 | 19 | return ptr; 20 | } 21 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/fgets.c: -------------------------------------------------------------------------------- 1 | /* 2 | * fgets.c 3 | * 4 | * This will be very slow due to the implementation of getc(), 5 | * but we don't have anywhere to put characters we don't need from 6 | * the input. 7 | */ 8 | 9 | #include 10 | 11 | char *fgets(char *s, int n, FILE *f) 12 | { 13 | int ch; 14 | char *p = s; 15 | 16 | while (n > 1) { 17 | ch = getc(f); 18 | if (ch == EOF) { 19 | *p = '\0'; 20 | return NULL; 21 | } 22 | *p++ = ch; 23 | n--; 24 | if (ch == '\n') 25 | break; 26 | } 27 | if (n) 28 | *p = '\0'; 29 | 30 | return s; 31 | } 32 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/fprintf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * fprintf.c 3 | */ 4 | 5 | #include 6 | #include 7 | 8 | #define BUFFER_SIZE 16384 9 | 10 | int fprintf(FILE * file, const char *format, ...) 11 | { 12 | va_list ap; 13 | int rv; 14 | 15 | va_start(ap, format); 16 | rv = vfprintf(file, format, ap); 17 | va_end(ap); 18 | return rv; 19 | } 20 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/inline.c: -------------------------------------------------------------------------------- 1 | // Make an externally visible symbol out of inlined functions 2 | #define __extern_inline 3 | #include 4 | #include 5 | #include 6 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/jrand48.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jrand48.c 3 | */ 4 | 5 | #include 6 | #include 7 | 8 | long jrand48(unsigned short xsubi[3]) 9 | { 10 | uint64_t x; 11 | 12 | /* The xsubi[] array is littleendian by spec */ 13 | x = (uint64_t) (uint16_t) xsubi[0] + 14 | ((uint64_t) (uint16_t) xsubi[1] << 16) + 15 | ((uint64_t) (uint16_t) xsubi[2] << 32); 16 | 17 | x = (0x5deece66dULL * x) + 0xb; 18 | 19 | xsubi[0] = (unsigned short)(uint16_t) x; 20 | xsubi[1] = (unsigned short)(uint16_t) (x >> 16); 21 | xsubi[2] = (unsigned short)(uint16_t) (x >> 32); 22 | 23 | return (long)(int32_t) (x >> 16); 24 | } 25 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/lrand48.c: -------------------------------------------------------------------------------- 1 | /* 2 | * lrand48.c 3 | */ 4 | 5 | #include 6 | #include 7 | 8 | extern unsigned short __rand48_seed[3]; /* Common with mrand48.c, srand48.c */ 9 | 10 | long lrand48(void) 11 | { 12 | return (uint32_t) jrand48(__rand48_seed) >> 1; 13 | } 14 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/malloc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * malloc.h 3 | * 4 | * Internals for the memory allocator 5 | */ 6 | 7 | #include 8 | #include 9 | 10 | /* 11 | * This structure should be a power of two. This becomes the 12 | * alignment unit. 13 | */ 14 | struct free_arena_header; 15 | 16 | struct arena_header { 17 | size_t type; 18 | size_t size; 19 | struct free_arena_header *next, *prev; 20 | }; 21 | 22 | #ifdef DEBUG_MALLOC 23 | #define ARENA_TYPE_USED 0x64e69c70 24 | #define ARENA_TYPE_FREE 0x012d610a 25 | #define ARENA_TYPE_HEAD 0x971676b5 26 | #define ARENA_TYPE_DEAD 0xeeeeeeee 27 | #else 28 | #define ARENA_TYPE_USED 0 29 | #define ARENA_TYPE_FREE 1 30 | #define ARENA_TYPE_HEAD 2 31 | #endif 32 | 33 | #define ARENA_SIZE_MASK (~(sizeof(struct arena_header)-1)) 34 | 35 | /* 36 | * This structure should be no more than twice the size of the 37 | * previous structure. 38 | */ 39 | struct free_arena_header { 40 | struct arena_header a; 41 | struct free_arena_header *next_free, *prev_free; 42 | }; 43 | 44 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/memccpy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * memccpy.c 3 | * 4 | * memccpy() 5 | */ 6 | 7 | #include 8 | #include 9 | 10 | void *memccpy(void *dst, const void *src, int c, size_t n) 11 | { 12 | char *q = dst; 13 | const char *p = src; 14 | char ch; 15 | 16 | while (n--) { 17 | *q++ = ch = *p++; 18 | if (ch == (char)c) 19 | return q; 20 | } 21 | 22 | return NULL; /* No instance of "c" found */ 23 | } 24 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/memchr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * memchr.c 3 | */ 4 | 5 | #include 6 | #include 7 | 8 | void *memchr(const void *s, int c, size_t n) 9 | { 10 | const unsigned char *sp = s; 11 | 12 | while (n--) { 13 | if (*sp == (unsigned char)c) 14 | return (void *)sp; 15 | sp++; 16 | } 17 | 18 | return NULL; 19 | } 20 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/memcmp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * memcmp.c 3 | */ 4 | 5 | #include 6 | 7 | int memcmp(const void *s1, const void *s2, size_t n) 8 | { 9 | const unsigned char *c1 = s1, *c2 = s2; 10 | int d = 0; 11 | 12 | while (n--) { 13 | d = (int)*c1++ - (int)*c2++; 14 | if (d) 15 | break; 16 | } 17 | 18 | return d; 19 | } 20 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/memcpy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * memcpy.c 3 | */ 4 | 5 | #include 6 | #include 7 | 8 | void *memcpy(void *dst, const void *src, size_t n) 9 | { 10 | const char *p = src; 11 | char *q = dst; 12 | #if defined(__i386__) 13 | size_t nl = n >> 2; 14 | asm volatile ("cld ; rep ; movsl ; movl %3,%0 ; rep ; movsb":"+c" (nl), 15 | "+S"(p), "+D"(q) 16 | :"r"(n & 3)); 17 | #elif defined(__x86_64__) 18 | size_t nq = n >> 3; 19 | asm volatile ("cld ; rep ; movsq ; movl %3,%%ecx ; rep ; movsb":"+c" 20 | (nq), "+S"(p), "+D"(q) 21 | :"r"((uint32_t) (n & 7))); 22 | #else 23 | while (n--) { 24 | *q++ = *p++; 25 | } 26 | #endif 27 | 28 | return dst; 29 | } 30 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/memmem.c: -------------------------------------------------------------------------------- 1 | /* 2 | * memmem.c 3 | * 4 | * Find a byte string inside a longer byte string 5 | * 6 | * This uses the "Not So Naive" algorithm, a very simple but 7 | * usually effective algorithm, see: 8 | * 9 | * http://www-igm.univ-mlv.fr/~lecroq/string/ 10 | */ 11 | 12 | #include 13 | 14 | void *memmem(const void *haystack, size_t n, const void *needle, size_t m) 15 | { 16 | const unsigned char *y = (const unsigned char *)haystack; 17 | const unsigned char *x = (const unsigned char *)needle; 18 | 19 | size_t j, k, l; 20 | 21 | if (m > n || !m || !n) 22 | return NULL; 23 | 24 | if (1 != m) { 25 | if (x[0] == x[1]) { 26 | k = 2; 27 | l = 1; 28 | } else { 29 | k = 1; 30 | l = 2; 31 | } 32 | 33 | j = 0; 34 | while (j <= n - m) { 35 | if (x[1] != y[j + 1]) { 36 | j += k; 37 | } else { 38 | if (!memcmp(x + 2, y + j + 2, m - 2) 39 | && x[0] == y[j]) 40 | return (void *)&y[j]; 41 | j += l; 42 | } 43 | } 44 | } else 45 | do { 46 | if (*y == *x) 47 | return (void *)y; 48 | y++; 49 | } while (--n); 50 | 51 | return NULL; 52 | } 53 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/memmove.c: -------------------------------------------------------------------------------- 1 | /* 2 | * memmove.c 3 | */ 4 | 5 | #include 6 | 7 | void *memmove(void *dst, const void *src, size_t n) 8 | { 9 | const char *p = src; 10 | char *q = dst; 11 | #if defined(__i386__) || defined(__x86_64__) 12 | if (q < p) { 13 | asm volatile("cld; rep; movsb" 14 | : "+c" (n), "+S"(p), "+D"(q)); 15 | } else { 16 | p += (n - 1); 17 | q += (n - 1); 18 | asm volatile("std; rep; movsb; cld" 19 | : "+c" (n), "+S"(p), "+D"(q)); 20 | } 21 | #else 22 | if (q < p) { 23 | while (n--) { 24 | *q++ = *p++; 25 | } 26 | } else { 27 | p += n; 28 | q += n; 29 | while (n--) { 30 | *--q = *--p; 31 | } 32 | } 33 | #endif 34 | 35 | return dst; 36 | } 37 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/memrchr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * memrchr.c 3 | */ 4 | 5 | #include 6 | #include 7 | 8 | void *memrchr(const void *s, int c, size_t n) 9 | { 10 | const unsigned char *sp = (const unsigned char *)s + n - 1; 11 | 12 | while (n--) { 13 | if (*sp == (unsigned char)c) 14 | return (void *)sp; 15 | sp--; 16 | } 17 | 18 | return NULL; 19 | } 20 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/memset.c: -------------------------------------------------------------------------------- 1 | /* 2 | * memset.c 3 | */ 4 | 5 | #include 6 | #include 7 | 8 | void *memset(void *dst, int c, size_t n) 9 | { 10 | char *q = dst; 11 | 12 | #if defined(__i386__) 13 | size_t nl = n >> 2; 14 | asm volatile ("cld ; rep ; stosl ; movl %3,%0 ; rep ; stosb" 15 | : "+c" (nl), "+D" (q) 16 | : "a" ((unsigned char)c * 0x01010101U), "r" (n & 3)); 17 | #elif defined(__x86_64__) 18 | size_t nq = n >> 3; 19 | asm volatile ("cld ; rep ; stosq ; movl %3,%%ecx ; rep ; stosb" 20 | :"+c" (nq), "+D" (q) 21 | : "a" ((unsigned char)c * 0x0101010101010101U), 22 | "r" ((uint32_t) n & 7)); 23 | #else 24 | while (n--) { 25 | *q++ = c; 26 | } 27 | #endif 28 | 29 | return dst; 30 | } 31 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/memswap.c: -------------------------------------------------------------------------------- 1 | /* 2 | * memswap() 3 | * 4 | * Swaps the contents of two nonoverlapping memory areas. 5 | * This really could be done faster... 6 | */ 7 | 8 | #include 9 | 10 | void memswap(void *m1, void *m2, size_t n) 11 | { 12 | char *p = m1; 13 | char *q = m2; 14 | char tmp; 15 | 16 | while (n--) { 17 | tmp = *p; 18 | *p = *q; 19 | *q = tmp; 20 | 21 | p++; 22 | q++; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/mrand48.c: -------------------------------------------------------------------------------- 1 | /* 2 | * mrand48.c 3 | */ 4 | 5 | #include 6 | #include 7 | 8 | extern unsigned short __rand48_seed[3]; /* Common with lrand48.c, srand48.c */ 9 | 10 | long mrand48(void) 11 | { 12 | return jrand48(__rand48_seed); 13 | } 14 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/nrand48.c: -------------------------------------------------------------------------------- 1 | /* 2 | * nrand48.c 3 | */ 4 | 5 | #include 6 | #include 7 | 8 | long nrand48(unsigned short xsubi[3]) 9 | { 10 | return (long)((uint32_t) jrand48(xsubi) >> 1); 11 | } 12 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/printf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * printf.c 3 | */ 4 | 5 | #include 6 | #include 7 | 8 | #define BUFFER_SIZE 16384 9 | 10 | int printf(const char *format, ...) 11 | { 12 | va_list ap; 13 | int rv; 14 | 15 | va_start(ap, format); 16 | rv = vfprintf(stdout, format, ap); 17 | va_end(ap); 18 | return rv; 19 | } 20 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/qsort.c: -------------------------------------------------------------------------------- 1 | /* 2 | * qsort.c 3 | * 4 | * This is actually combsort. It's an O(n log n) algorithm with 5 | * simplicity/small code size being its main virtue. 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | static inline size_t newgap(size_t gap) 13 | { 14 | gap = (gap * 10) / 13; 15 | if (gap == 9 || gap == 10) 16 | gap = 11; 17 | 18 | if (gap < 1) 19 | gap = 1; 20 | return gap; 21 | } 22 | 23 | void qsort(void *base, size_t nmemb, size_t size, 24 | int (*compar) (const void *, const void *)) 25 | { 26 | size_t gap = nmemb; 27 | size_t i, j; 28 | char *p1, *p2; 29 | int swapped; 30 | 31 | if (!nmemb) 32 | return; 33 | 34 | do { 35 | gap = newgap(gap); 36 | swapped = 0; 37 | 38 | for (i = 0, p1 = base; i < nmemb - gap; i++, p1 += size) { 39 | j = i + gap; 40 | if (compar(p1, p2 = (char *)base + j * size) > 0) { 41 | memswap(p1, p2, size); 42 | swapped = 1; 43 | } 44 | } 45 | } while (gap > 1 || swapped); 46 | } 47 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/realloc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * realloc.c 3 | */ 4 | 5 | #include 6 | #include 7 | 8 | #include "malloc.h" 9 | 10 | /* FIXME: This is cheesy, it should be fixed later */ 11 | 12 | void *realloc(void *ptr, size_t size) 13 | { 14 | struct free_arena_header *ah; 15 | void *newptr; 16 | size_t oldsize; 17 | 18 | if (!ptr) 19 | return malloc(size); 20 | 21 | if (size == 0) { 22 | free(ptr); 23 | return NULL; 24 | } 25 | 26 | /* Add the obligatory arena header, and round up */ 27 | size = (size + 2 * sizeof(struct arena_header) - 1) & ARENA_SIZE_MASK; 28 | 29 | ah = (struct free_arena_header *) 30 | ((struct arena_header *)ptr - 1); 31 | 32 | if (ah->a.size >= size && size >= (ah->a.size >> 2)) { 33 | /* This field is a good size already. */ 34 | return ptr; 35 | } else { 36 | /* Make me a new block. This is kind of bogus; we should 37 | be checking the following block to see if we can do an 38 | in-place adjustment... fix that later. */ 39 | 40 | oldsize = ah->a.size - sizeof(struct arena_header); 41 | 42 | newptr = malloc(size); 43 | memcpy(newptr, ptr, (size < oldsize) ? size : oldsize); 44 | free(ptr); 45 | 46 | return newptr; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/snprintf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * snprintf.c 3 | */ 4 | 5 | #include 6 | 7 | int snprintf(char *buffer, size_t n, const char *format, ...) 8 | { 9 | va_list ap; 10 | int rv; 11 | 12 | va_start(ap, format); 13 | rv = vsnprintf(buffer, n, format, ap); 14 | va_end(ap); 15 | return rv; 16 | } 17 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/sprintf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * sprintf.c 3 | */ 4 | 5 | #include 6 | #include 7 | 8 | int sprintf(char *buffer, const char *format, ...) 9 | { 10 | va_list ap; 11 | int rv; 12 | 13 | va_start(ap, format); 14 | rv = vsnprintf(buffer, ~(size_t) 0, format, ap); 15 | va_end(ap); 16 | 17 | return rv; 18 | } 19 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/srand48.c: -------------------------------------------------------------------------------- 1 | /* 2 | * srand48.c 3 | */ 4 | 5 | #include 6 | #include 7 | 8 | unsigned short __rand48_seed[3]; /* Common with mrand48.c, lrand48.c */ 9 | 10 | void srand48(long seedval) 11 | { 12 | __rand48_seed[0] = 0x330e; 13 | __rand48_seed[1] = (unsigned short)seedval; 14 | __rand48_seed[2] = (unsigned short)((uint32_t) seedval >> 16); 15 | } 16 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/sscanf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * sscanf() 3 | */ 4 | 5 | #include 6 | 7 | int sscanf(const char *str, const char *format, ...) 8 | { 9 | va_list ap; 10 | int rv; 11 | 12 | va_start(ap, format); 13 | rv = vsscanf(str, format, ap); 14 | va_end(ap); 15 | 16 | return rv; 17 | } 18 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/strcasecmp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * strcasecmp.c 3 | */ 4 | 5 | #include 6 | #include 7 | 8 | int strcasecmp(const char *s1, const char *s2) 9 | { 10 | const unsigned char *c1 = (const unsigned char *)s1; 11 | const unsigned char *c2 = (const unsigned char *)s2; 12 | unsigned char ch; 13 | int d = 0; 14 | 15 | while (1) { 16 | /* toupper() expects an unsigned char (implicitly cast to int) 17 | as input, and returns an int, which is exactly what we want. */ 18 | d = toupper(ch = *c1++) - toupper(*c2++); 19 | if (d || !ch) 20 | break; 21 | } 22 | 23 | return d; 24 | } 25 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/strcat.c: -------------------------------------------------------------------------------- 1 | /* 2 | * strcat.c 3 | */ 4 | 5 | #include 6 | 7 | char *strcat(char *dst, const char *src) 8 | { 9 | strcpy(strchr(dst, '\0'), src); 10 | return dst; 11 | } 12 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/strchr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * strchr.c 3 | */ 4 | 5 | #include 6 | 7 | char *strchr(const char *s, int c) 8 | { 9 | while (*s != (char)c) { 10 | if (!*s) 11 | return NULL; 12 | s++; 13 | } 14 | 15 | return (char *)s; 16 | } 17 | 18 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/strcmp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * strcmp.c 3 | */ 4 | 5 | #include 6 | 7 | int strcmp(const char *s1, const char *s2) 8 | { 9 | const unsigned char *c1 = (const unsigned char *)s1; 10 | const unsigned char *c2 = (const unsigned char *)s2; 11 | unsigned char ch; 12 | int d = 0; 13 | 14 | while (1) { 15 | d = (int)(ch = *c1++) - (int)*c2++; 16 | if (d || !ch) 17 | break; 18 | } 19 | 20 | return d; 21 | } 22 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/strcpy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * strcpy.c 3 | * 4 | * strcpy() 5 | */ 6 | 7 | #include 8 | 9 | char *strcpy(char *dst, const char *src) 10 | { 11 | char *q = dst; 12 | const char *p = src; 13 | char ch; 14 | 15 | do { 16 | *q++ = ch = *p++; 17 | } while (ch); 18 | 19 | return dst; 20 | } 21 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/strcspn.c: -------------------------------------------------------------------------------- 1 | /* 2 | FUNCTION 3 | <>---count characters not in string 4 | 5 | INDEX 6 | strcspn 7 | 8 | ANSI_SYNOPSIS 9 | size_t strcspn(const char *<[s1]>, const char *<[s2]>); 10 | 11 | TRAD_SYNOPSIS 12 | size_t strcspn(<[s1]>, <[s2]>) 13 | char *<[s1]>; 14 | char *<[s2]>; 15 | 16 | DESCRIPTION 17 | This function computes the length of the initial part of 18 | the string pointed to by <[s1]> which consists entirely of 19 | characters <[NOT]> from the string pointed to by <[s2]> 20 | (excluding the terminating null character). 21 | 22 | RETURNS 23 | <> returns the length of the substring found. 24 | 25 | PORTABILITY 26 | <> is ANSI C. 27 | 28 | <> requires no supporting OS subroutines. 29 | */ 30 | 31 | #include 32 | 33 | size_t strcspn(const char *s1, const char *s2) 34 | { 35 | const char *s = s1; 36 | const char *c; 37 | 38 | while (*s1) 39 | { 40 | for (c = s2; *c; c++) 41 | { 42 | if (*s1 == *c) 43 | break; 44 | } 45 | if (*c) 46 | break; 47 | s1++; 48 | } 49 | 50 | return s1 - s; 51 | } 52 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/strdup.c: -------------------------------------------------------------------------------- 1 | /* 2 | * strdup.c 3 | */ 4 | 5 | #include 6 | #include 7 | 8 | char *strdup(const char *s) 9 | { 10 | int l = strlen(s) + 1; 11 | char *d = malloc(l); 12 | 13 | if (d) 14 | memcpy(d, s, l); 15 | 16 | return d; 17 | } 18 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/strlcat.c: -------------------------------------------------------------------------------- 1 | /* 2 | * strlcat.c 3 | */ 4 | 5 | #include 6 | 7 | size_t strlcat(char *dst, const char *src, size_t size) 8 | { 9 | size_t bytes = 0; 10 | char *q = dst; 11 | const char *p = src; 12 | char ch; 13 | 14 | while (bytes < size && *q) { 15 | q++; 16 | bytes++; 17 | } 18 | if (bytes == size) 19 | return (bytes + strlen(src)); 20 | 21 | while ((ch = *p++)) { 22 | if (bytes + 1 < size) 23 | *q++ = ch; 24 | 25 | bytes++; 26 | } 27 | 28 | *q = '\0'; 29 | return bytes; 30 | } 31 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/strlcpy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * strlcpy.c 3 | */ 4 | 5 | #include 6 | 7 | size_t strlcpy(char *dst, const char *src, size_t size) 8 | { 9 | size_t bytes = 0; 10 | char *q = dst; 11 | const char *p = src; 12 | char ch; 13 | 14 | while ((ch = *p++)) { 15 | if (bytes + 1 < size) 16 | *q++ = ch; 17 | 18 | bytes++; 19 | } 20 | 21 | /* If size == 0 there is no space for a final null... */ 22 | if (size) 23 | *q = '\0'; 24 | 25 | return bytes; 26 | } 27 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/strlen.c: -------------------------------------------------------------------------------- 1 | /* 2 | * strlen() 3 | */ 4 | 5 | #include 6 | 7 | size_t strlen(const char *s) 8 | { 9 | const char *ss = s; 10 | while (*ss) 11 | ss++; 12 | return ss - s; 13 | } 14 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/strncasecmp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * strncasecmp.c 3 | */ 4 | 5 | #include 6 | #include 7 | 8 | int strncasecmp(const char *s1, const char *s2, size_t n) 9 | { 10 | const unsigned char *c1 = (const unsigned char *)s1; 11 | const unsigned char *c2 = (const unsigned char *)s2; 12 | unsigned char ch; 13 | int d = 0; 14 | 15 | while (n--) { 16 | /* toupper() expects an unsigned char (implicitly cast to int) 17 | as input, and returns an int, which is exactly what we want. */ 18 | d = toupper(ch = *c1++) - toupper(*c2++); 19 | if (d || !ch) 20 | break; 21 | } 22 | 23 | return d; 24 | } 25 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/strncat.c: -------------------------------------------------------------------------------- 1 | /* 2 | * strncat.c 3 | */ 4 | 5 | #include 6 | 7 | char *strncat(char *dst, const char *src, size_t n) 8 | { 9 | char *q = strchr(dst, '\0'); 10 | const char *p = src; 11 | char ch; 12 | 13 | while (n--) { 14 | *q++ = ch = *p++; 15 | if (!ch) 16 | return dst; 17 | } 18 | *q = '\0'; 19 | 20 | return dst; 21 | } 22 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/strncmp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * strncmp.c 3 | */ 4 | 5 | #include 6 | 7 | int strncmp(const char *s1, const char *s2, size_t n) 8 | { 9 | const unsigned char *c1 = (const unsigned char *)s1; 10 | const unsigned char *c2 = (const unsigned char *)s2; 11 | unsigned char ch; 12 | int d = 0; 13 | 14 | while (n--) { 15 | d = (int)(ch = *c1++) - (int)*c2++; 16 | if (d || !ch) 17 | break; 18 | } 19 | 20 | return d; 21 | } 22 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/strncpy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * strncpy.c 3 | */ 4 | 5 | #include 6 | 7 | char *strncpy(char *dst, const char *src, size_t n) 8 | { 9 | char *q = dst; 10 | const char *p = src; 11 | char ch; 12 | 13 | while (n) { 14 | n--; 15 | *q++ = ch = *p++; 16 | if (!ch) 17 | break; 18 | } 19 | 20 | /* The specs say strncpy() fills the entire buffer with NUL. Sigh. */ 21 | memset(q, 0, n); 22 | 23 | return dst; 24 | } 25 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/strndup.c: -------------------------------------------------------------------------------- 1 | /* 2 | * strndup.c 3 | */ 4 | 5 | #include 6 | #include 7 | 8 | char *strndup(const char *s, size_t n) 9 | { 10 | int l = n > strlen(s) ? strlen(s) + 1 : n + 1; 11 | char *d = malloc(l); 12 | 13 | if (!d) 14 | return NULL; 15 | 16 | memcpy(d, s, l); 17 | d[n] = '\0'; 18 | return d; 19 | } 20 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/strnlen.c: -------------------------------------------------------------------------------- 1 | /* 2 | * strnlen() 3 | */ 4 | 5 | #include 6 | 7 | size_t strnlen(const char *s, size_t maxlen) 8 | { 9 | const char *ss = s; 10 | 11 | /* Important: the maxlen test must precede the reference through ss; 12 | since the byte beyond the maximum may segfault */ 13 | while ((maxlen > 0) && *ss) { 14 | ss++; 15 | maxlen--; 16 | } 17 | return ss - s; 18 | } 19 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/strntoimax.c: -------------------------------------------------------------------------------- 1 | /* 2 | * strntoimax.c 3 | * 4 | * strntoimax() 5 | */ 6 | 7 | #include 8 | #include 9 | 10 | intmax_t strntoimax(const char *nptr, char **endptr, int base, size_t n) 11 | { 12 | return (intmax_t) strntoumax(nptr, endptr, base, n); 13 | } 14 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/strntoumax.c: -------------------------------------------------------------------------------- 1 | /* 2 | * strntoumax.c 3 | * 4 | * The strntoumax() function and associated 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | static inline int digitval(int ch) 13 | { 14 | if (ch >= '0' && ch <= '9') { 15 | return ch - '0'; 16 | } else if (ch >= 'A' && ch <= 'Z') { 17 | return ch - 'A' + 10; 18 | } else if (ch >= 'a' && ch <= 'z') { 19 | return ch - 'a' + 10; 20 | } else { 21 | return -1; 22 | } 23 | } 24 | 25 | uintmax_t strntoumax(const char *nptr, char **endptr, int base, size_t n) 26 | { 27 | int minus = 0; 28 | uintmax_t v = 0; 29 | int d; 30 | 31 | while (n && isspace((unsigned char)*nptr)) { 32 | nptr++; 33 | n--; 34 | } 35 | 36 | /* Single optional + or - */ 37 | if (n) { 38 | char c = *nptr; 39 | if (c == '-' || c == '+') { 40 | minus = (c == '-'); 41 | nptr++; 42 | n--; 43 | } 44 | } 45 | 46 | if (base == 0) { 47 | if (n >= 2 && nptr[0] == '0' && 48 | (nptr[1] == 'x' || nptr[1] == 'X')) { 49 | n -= 2; 50 | nptr += 2; 51 | base = 16; 52 | } else if (n >= 1 && nptr[0] == '0') { 53 | n--; 54 | nptr++; 55 | base = 8; 56 | } else { 57 | base = 10; 58 | } 59 | } else if (base == 16) { 60 | if (n >= 2 && nptr[0] == '0' && 61 | (nptr[1] == 'x' || nptr[1] == 'X')) { 62 | n -= 2; 63 | nptr += 2; 64 | } 65 | } 66 | 67 | while (n && (d = digitval(*nptr)) >= 0 && d < base) { 68 | v = v * base + d; 69 | n--; 70 | nptr++; 71 | } 72 | 73 | if (endptr) 74 | *endptr = (char *)nptr; 75 | 76 | return minus ? -v : v; 77 | } 78 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/strpbrk.c: -------------------------------------------------------------------------------- 1 | /* 2 | FUNCTION 3 | <>---find characters in string 4 | 5 | INDEX 6 | strpbrk 7 | 8 | ANSI_SYNOPSIS 9 | #include 10 | char *strpbrk(const char *<[s1]>, const char *<[s2]>); 11 | 12 | TRAD_SYNOPSIS 13 | #include 14 | char *strpbrk(<[s1]>, <[s2]>) 15 | char *<[s1]>; 16 | char *<[s2]>; 17 | 18 | DESCRIPTION 19 | This function locates the first occurence in the string 20 | pointed to by <[s1]> of any character in string pointed to by 21 | <[s2]> (excluding the terminating null character). 22 | 23 | RETURNS 24 | <> returns a pointer to the character found in <[s1]>, or a 25 | null pointer if no character from <[s2]> occurs in <[s1]>. 26 | 27 | PORTABILITY 28 | <> requires no supporting OS subroutines. 29 | */ 30 | 31 | #include 32 | 33 | char *strpbrk(const char *s1, const char *s2) 34 | { 35 | const char *c = s2; 36 | if (!*s1) 37 | return (char *) NULL; 38 | 39 | while (*s1) 40 | { 41 | for (c = s2; *c; c++) 42 | { 43 | if (*s1 == *c) 44 | break; 45 | } 46 | if (*c) 47 | break; 48 | s1++; 49 | } 50 | 51 | if (*c == '\0') 52 | s1 = NULL; 53 | 54 | return (char *) s1; 55 | } 56 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/strrchr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * strrchr.c 3 | */ 4 | 5 | #include 6 | 7 | char *strrchr(const char *s, int c) 8 | { 9 | const char *found = NULL; 10 | 11 | while (*s) { 12 | if (*s == (char)c) 13 | found = s; 14 | s++; 15 | } 16 | 17 | return (char *)found; 18 | } 19 | 20 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/strsep.c: -------------------------------------------------------------------------------- 1 | /* 2 | * strsep.c 3 | */ 4 | 5 | #include 6 | 7 | char *strsep(char **stringp, const char *delim) 8 | { 9 | char *s = *stringp; 10 | char *e; 11 | 12 | if (!s) 13 | return NULL; 14 | 15 | e = strpbrk(s, delim); 16 | if (e) 17 | *e++ = '\0'; 18 | 19 | *stringp = e; 20 | return s; 21 | } 22 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/strspn.c: -------------------------------------------------------------------------------- 1 | /* 2 | FUNCTION 3 | <>---find initial match 4 | 5 | INDEX 6 | strspn 7 | 8 | ANSI_SYNOPSIS 9 | #include 10 | size_t strspn(const char *<[s1]>, const char *<[s2]>); 11 | 12 | TRAD_SYNOPSIS 13 | #include 14 | size_t strspn(<[s1]>, <[s2]>) 15 | char *<[s1]>; 16 | char *<[s2]>; 17 | 18 | DESCRIPTION 19 | This function computes the length of the initial segment of 20 | the string pointed to by <[s1]> which consists entirely of 21 | characters from the string pointed to by <[s2]> (excluding the 22 | terminating null character). 23 | 24 | RETURNS 25 | <> returns the length of the segment found. 26 | 27 | PORTABILITY 28 | <> is ANSI C. 29 | 30 | <> requires no supporting OS subroutines. 31 | 32 | QUICKREF 33 | strspn ansi pure 34 | */ 35 | 36 | #include 37 | 38 | size_t strspn(const char *s1, const char *s2) 39 | { 40 | const char *s = s1; 41 | const char *c; 42 | 43 | while (*s1) 44 | { 45 | for (c = s2; *c; c++) 46 | { 47 | if (*s1 == *c) 48 | break; 49 | } 50 | if (*c == '\0') 51 | break; 52 | s1++; 53 | } 54 | 55 | return s1 - s; 56 | } 57 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/strstr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * strstr.c 3 | */ 4 | 5 | #include 6 | 7 | char *strstr(const char *haystack, const char *needle) 8 | { 9 | return (char *)memmem(haystack, strlen(haystack), needle, 10 | strlen(needle)); 11 | } 12 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/strtoimax.c: -------------------------------------------------------------------------------- 1 | #define TYPE intmax_t 2 | #define NAME strtoimax 3 | #include "strtox.c" 4 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/strtok.c: -------------------------------------------------------------------------------- 1 | /* 2 | * strtok.c 3 | */ 4 | 5 | #include 6 | 7 | char *strtok(char *s, const char *delim) 8 | { 9 | static char *holder; 10 | 11 | return strtok_r(s, delim, &holder); 12 | } 13 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/strtok_r.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | char *strtok_r(char *s, const char *delim, char **holder) 4 | { 5 | if (s) 6 | *holder = s; 7 | 8 | do { 9 | s = strsep(holder, delim); 10 | } while (s && !*s); 11 | 12 | return s; 13 | } 14 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/strtol.c: -------------------------------------------------------------------------------- 1 | #define TYPE signed long 2 | #define NAME strtol 3 | #include "strtox.c" 4 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/strtoll.c: -------------------------------------------------------------------------------- 1 | #define TYPE signed long long 2 | #define NAME strtoll 3 | #include "strtox.c" 4 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/strtoul.c: -------------------------------------------------------------------------------- 1 | #define TYPE unsigned long 2 | #define NAME strtoul 3 | #include "strtox.c" 4 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/strtoull.c: -------------------------------------------------------------------------------- 1 | #define TYPE unsigned long long 2 | #define NAME strtoull 3 | #include "strtox.c" 4 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/strtoumax.c: -------------------------------------------------------------------------------- 1 | #define TYPE uintmax_t 2 | #define NAME strtoumax 3 | #include "strtox.c" 4 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/strtox.c: -------------------------------------------------------------------------------- 1 | /* 2 | * strtox.c 3 | * 4 | * strto...() functions, by macro definition 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | TYPE NAME(const char *nptr, char **endptr, int base) 12 | { 13 | return (TYPE) strntoumax(nptr, endptr, base, ~(size_t) 0); 14 | } 15 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/strxspn.h: -------------------------------------------------------------------------------- 1 | /* 2 | * strxspn.h 3 | */ 4 | 5 | #ifndef STRXSPN_H 6 | #define STRXSPN_H 7 | 8 | #include 9 | 10 | extern size_t __strxspn(const char *s, const char *map, int parity); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/vasprintf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * vasprintf.c 3 | */ 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | int vasprintf(char **bufp, const char *format, va_list ap) 10 | { 11 | va_list ap1; 12 | int bytes; 13 | char *p; 14 | 15 | va_copy(ap1, ap); 16 | 17 | bytes = vsnprintf(NULL, 0, format, ap1) + 1; 18 | va_end(ap1); 19 | 20 | *bufp = p = malloc(bytes); 21 | if (!p) 22 | return -1; 23 | 24 | return vsnprintf(p, bytes, format, ap); 25 | } 26 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/vfprintf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * vfprintf.c 3 | */ 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | // This amount of memory is always taken from stack. 11 | // If it is not enough, the function tries to malloc(). 12 | #define BUFFER_SIZE 40 13 | 14 | int vfprintf(FILE * file, const char *format, va_list ap) 15 | { 16 | int rv; 17 | char buffer[BUFFER_SIZE]; 18 | 19 | va_list ap_copy; 20 | va_copy(ap_copy, ap); 21 | rv = vsnprintf(buffer, BUFFER_SIZE, format, ap); 22 | va_end(ap_copy); 23 | 24 | if (rv < 0) 25 | return rv; 26 | 27 | if (rv > BUFFER_SIZE - 1) 28 | { 29 | char *buf2 = malloc(rv + 1); 30 | if (buf2 == NULL) 31 | { 32 | // Couldn't malloc, output what fits on stack. 33 | rv = BUFFER_SIZE - 1; 34 | } else { 35 | rv = vsnprintf(buf2, rv + 1, format, ap); 36 | rv = fwrite(buffer, rv, 1, file); 37 | free(buf2); 38 | return rv; 39 | } 40 | } 41 | 42 | return fwrite(buffer, 1, rv, file); 43 | } 44 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/vprintf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * vprintf.c 3 | */ 4 | 5 | #include 6 | #include 7 | 8 | int vprintf(const char *format, va_list ap) 9 | { 10 | return vfprintf(stdout, format, ap); 11 | } 12 | -------------------------------------------------------------------------------- /Runtime/baselibc/src/vsprintf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * vsprintf.c 3 | */ 4 | 5 | #include 6 | #include 7 | 8 | int vsprintf(char *buffer, const char *format, va_list ap) 9 | { 10 | return vsnprintf(buffer, ~(size_t) 0, format, ap); 11 | } 12 | -------------------------------------------------------------------------------- /Runtime/buttons.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "irq.h" 5 | 6 | /* Functions for accessing the button status and timer ticks, which are 7 | * updated in a 1ms interval interrupt routine. 8 | */ 9 | 10 | // This can be replaced elsewhere to execute custom code every ms 11 | // The call will come from an interrupt context. 12 | void TimerTick(); // {} 13 | 14 | // Check if some keys have been pressed, but don't clear the key status. 15 | uint32_t peek_keys(uint32_t mask); 16 | 17 | // Check if some keys have been pressed, and clear the status for them. 18 | uint32_t get_keys(uint32_t mask); 19 | 20 | // Check if some keys are being held down 21 | // Returns the keys that are still down and the number of milliseconds they've 22 | // been down. 23 | uint32_t held_keys(uint32_t mask, uint32_t *ticks); 24 | 25 | // Get number of milliseconds passed since boot 26 | uint32_t get_time(); 27 | 28 | // Delay a specified number of milliseconds in a while loop 29 | void delay_ms(uint32_t milliseconds); 30 | 31 | // Beep for a given time 32 | void beep(int milliseconds, int volume); 33 | 34 | // Get scroller increment based on held_keys time. This achieves incremental 35 | // acceleration. 36 | int scroller_speed(); 37 | 38 | #define BUTTON1 0x4000 39 | #define BUTTON2 0x2000 40 | #define BUTTON3 0x0100 41 | #define BUTTON4 0x0200 42 | 43 | #define SCROLL1_LEFT 0x0400 44 | #define SCROLL1_RIGHT 0x0800 45 | #define SCROLL1_PRESS 0x1000 46 | 47 | #define SCROLL2_LEFT 0x0008 48 | #define SCROLL2_RIGHT 0x8000 49 | #define SCROLL2_PRESS 0x0040 50 | 51 | #define ANY_KEY 0xFFFF -------------------------------------------------------------------------------- /Runtime/drawing.h: -------------------------------------------------------------------------------- 1 | /* Functions for drawing on the DS203 lcd */ 2 | 3 | #pragma once 4 | #include 5 | #include "fix16.h" 6 | 7 | // Macros for converting from normal (r,g,b) 0-255 values to 16-bit RGB565 8 | // and back again. Use e.g. RGB(255,0,0) for bright red. 9 | #define RGB565RGB(r, g, b) (((r)>>3)|(((g)>>2)<<5)|(((b)>>3)<<11)) 10 | #define RGB(r,g,b) RGB565RGB(r,g,b) 11 | #define RGB565_R(color) (int)((color & 0x001F) << 3) 12 | #define RGB565_G(color) (int)((color & 0x07E0) >> 3) 13 | #define RGB565_B(color) (int)((color & 0xF800) >> 8) 14 | 15 | // You can pass -1 as bg to have transparent background. 16 | void draw_text(const char *text, int x, int y, int fg, int bg, bool center); 17 | 18 | // Returns number of lines in the text 19 | int draw_flowtext(const char *text, int x, int y, int w, int h, int fg, int bg, bool center); 20 | 21 | int blend(int fg, int bg, int alpha); 22 | 23 | void drawline_aa(fix16_t fx1, fix16_t fy1, fix16_t fx2, fix16_t fy2, int color); 24 | 25 | void drawline(int x1, int y1, int x2, int y2, int color, int dots); 26 | 27 | void fill_rectangle(int x, int y, int w, int h, int color); 28 | 29 | void draw_rectangle(int x, int y, int w, int h, int color, int dots); 30 | 31 | void draw_bitmap(const uint32_t *bitmap, int x, int y, int color, int bitmap_size, bool center); 32 | -------------------------------------------------------------------------------- /Runtime/ds203_io.h: -------------------------------------------------------------------------------- 1 | // Useful IO routines for developing on DS203 2 | // Petteri Aimonen 2011 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | /* ----------- Text printing ------------ */ 12 | 13 | // Print stack trace and display a message 14 | void crash_with_message(const char *message, void *caller); 15 | 16 | // Print to lcd with specified position & color. Mode can be 0 for normal text 17 | // or 1 for inverted colors (black text on hilighted background). 18 | int lcd_printf(u16 x0, u16 y0, u16 color, u8 mode, const char *fmt, ...) 19 | __attribute__ ((format (printf, 5, 6)));; 20 | 21 | // Shorthand function for printing debug messages. Always writes on the bottom 22 | // row of the screen. 23 | #define debugf(...) lcd_printf(0, 0, 0xFFFF, 0, __VA_ARGS__) 24 | 25 | // Helper function for clearing a text row before printing. 26 | #define clearline(y0) lcd_printf(0, y0, 0, 0, " ") 27 | 28 | /* ------------- File IO ------------- */ 29 | // Select a free filename using a printf-style template. 30 | // Goes through parameters 0 to 999 until a non-existent filename is found. 31 | // Returns pointer to a static array, so next call will overwrite the value. 32 | // E.g. select_filename("FILE%03d.CSV") might give "FILE001.CSV". 33 | 34 | bool f_exists(const char *name); 35 | 36 | char *select_filename(const char *format); 37 | 38 | extern const uint32_t bmp_default_palette[16]; 39 | 40 | // Write current LCD contents as a bitmap into file. 41 | bool write_bitmap(const char *filename, const uint32_t *palette); 42 | -------------------------------------------------------------------------------- /Runtime/file_selector.h: -------------------------------------------------------------------------------- 1 | void select_file(char result[13]); -------------------------------------------------------------------------------- /Runtime/fpga.h: -------------------------------------------------------------------------------- 1 | /* FPGA configuration loading. */ 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | bool fpga_configure(FIL *file); 10 | -------------------------------------------------------------------------------- /Runtime/gdb_debug_memory_dump.txt: -------------------------------------------------------------------------------- 1 | target sim 2 | load 3 | start 4 | restore memory.dmp binary 0x20000000 5 | set $pc=CRASHDATA.PC 6 | set $lr=CRASHDATA.LR 7 | set $r7=CRASHDATA.R7 8 | set $sp=CRASHDATA.SP 9 | 10 | -------------------------------------------------------------------------------- /Runtime/gpio.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | // Use this macro to declare an IO pin for a particular purpose. 7 | // For example DECLARE_GPIO(led1, GPIOC, 3) creates these functions: 8 | // 9 | // static GPIO_TypeDef* gpio_led1_port = GPIOC; 10 | // static int gpio_led1_pin = 3; 11 | // void gpio_led1_set(bool value); 12 | // bool gpio_led1_get(); 13 | // void gpio_led1_mode(enum gpio_cnf mode); 14 | // 15 | #define DECLARE_GPIO(name, port, pin) \ 16 | static GPIO_TypeDef * const _GPIO_PASTE_NAME(gpio_, name, _port) = port; \ 17 | static int _GPIO_PASTE_NAME(gpio_, name, _pin) = pin; \ 18 | static void _GPIO_PASTE_NAME(gpio_, name, _set)(bool value) { \ 19 | port->BSRR = (1 << (pin)) << (value ? 0 : 16); \ 20 | } \ 21 | static bool _GPIO_PASTE_NAME(gpio_, name, _get)() { \ 22 | return (port->IDR >> (pin)) & 1; \ 23 | } \ 24 | static void _GPIO_PASTE_NAME(gpio_, name, _mode)(enum gpio_cnf mode) { \ 25 | volatile uint32_t *conf = ((pin) < 8) ? (&port->CRL) : (&port->CRH); \ 26 | int shift = ((pin) & 7) * 4; \ 27 | *conf = (*conf & ~(15 << shift)) | (mode << shift); \ 28 | } 29 | 30 | // GPIO mode configuration 31 | enum gpio_cnf { 32 | // Choose one of the following 33 | GPIO_ANALOG_INPUT = 0, 34 | GPIO_HIGHZ_INPUT = 4, 35 | GPIO_PULL_INPUT = 8, 36 | GPIO_OUT_10 = 1, 37 | GPIO_OUT_2 = 2, 38 | GPIO_OUT_50 = 3, 39 | GPIO_AFOUT_10 = 9, 40 | GPIO_AFOUT_2 = 10, 41 | GPIO_AFOUT_50 = 11, 42 | 43 | // This can be combined with the output modes above 44 | GPIO_OPEN_DRAIN = 4, 45 | }; 46 | 47 | // Used to form the function names 48 | #define _GPIO_PASTE_NAME(x, y, z) _GPIO_PASTE_TOKENS(x, y, z) 49 | #define _GPIO_PASTE_TOKENS(x, y, z) x ## y ## z 50 | -------------------------------------------------------------------------------- /Runtime/irq.h: -------------------------------------------------------------------------------- 1 | #ifndef __IRQ_H_ 2 | #define __IRQ_H_ 3 | 4 | // Note: Uses optimize("O2") to work around this bug: 5 | // http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39585 6 | #define __irq__ __attribute__((interrupt("IRQ"), optimize("O2"), externally_visible)) 7 | 8 | #endif -------------------------------------------------------------------------------- /Runtime/libc_glue.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "drawing.h" 5 | #include "BIOS.h" 6 | 7 | #include "stm32f10x.h" 8 | 9 | size_t __attribute__((externally_visible)) _fread(void *ptr, size_t size, FILE *stream) 10 | { 11 | return 0; 12 | } 13 | 14 | size_t __attribute__((externally_visible)) _fwrite(const void *ptr, size_t size, FILE *stream) 15 | { 16 | static int y = 220; 17 | static int x = 10; 18 | 19 | char buffer[2] = {0, 0}; 20 | 21 | // Everything to USART1, stderr also to screen 22 | size_t i; 23 | char *p = (char*)ptr; 24 | for (i = 0; i < size; i++, p++) 25 | { 26 | if (stream == stderr) 27 | { 28 | buffer[0] = *p; 29 | 30 | if (*p != '\n') 31 | __Display_Str(x, y, 0xFFFF, 0, (u8*)buffer); 32 | 33 | x += FONT_WIDTH; 34 | if (x >= 390 || *p == '\n') 35 | { 36 | x = 10; 37 | y -= FONT_HEIGHT; 38 | } 39 | } 40 | 41 | while (!(USART1->SR & USART_SR_TXE)); 42 | USART1->DR = *p; 43 | } 44 | 45 | return i; 46 | } -------------------------------------------------------------------------------- /Runtime/libfixmath/Makefile: -------------------------------------------------------------------------------- 1 | #Project settings 2 | PROJECT = libfixmath 3 | LIB = 4 | SRC = . 5 | INC = 6 | 7 | #Compiler settings 8 | CPP = gcc 9 | CC = gcc 10 | AS = gcc 11 | LD = gcc 12 | AR = ar 13 | CPP_FLAGS = -O2 $(INC) -Wall -Wextra -c 14 | CC_FLAGS = -O2 $(INC) -Wall -Wextra -c 15 | AS_FLAGS = $(CC_FLAGS) -D_ASSEMBLER_ 16 | LD_FLAGS = -Wall 17 | 18 | # Find all source files 19 | SRC_CPP = $(foreach dir, $(SRC), $(wildcard $(dir)/*.cpp)) 20 | SRC_C = $(foreach dir, $(SRC), $(wildcard $(dir)/*.c)) 21 | SRC_S = $(foreach dir, $(SRC), $(wildcard $(dir)/*.S)) 22 | OBJ_CPP = $(patsubst %.cpp, %.o, $(SRC_CPP)) 23 | OBJ_C = $(patsubst %.c, %.o, $(SRC_C)) 24 | OBJ_S = $(patsubst %.S, %.o, $(SRC_S)) 25 | OBJ = $(OBJ_CPP) $(OBJ_C) $(OBJ_S) 26 | 27 | # Compile rules. 28 | .PHONY : all 29 | all: $(PROJECT).a 30 | 31 | $(PROJECT).a: $(OBJ) 32 | $(AR) rcs $(PROJECT).a $(OBJ) 33 | 34 | $(OBJ_CPP) : %.o : %.cpp 35 | $(CPP) $(CPP_FLAGS) -o $@ $< 36 | 37 | $(OBJ_C) : %.o : %.c 38 | $(CC) $(CC_FLAGS) -o $@ $< 39 | 40 | $(OBJ_S) : %.o : %.S 41 | $(AS) $(AS_FLAGS) -o $@ $< 42 | 43 | 44 | 45 | # Clean rules 46 | .PHONY : clean 47 | clean: 48 | rm -f $(PROJECT).a $(OBJ) 49 | -------------------------------------------------------------------------------- /Runtime/libfixmath/fixmath.h: -------------------------------------------------------------------------------- 1 | #ifndef __libfixmath_fixmath_h__ 2 | #define __libfixmath_fixmath_h__ 3 | 4 | #ifdef __cplusplus 5 | extern "C" 6 | { 7 | #endif 8 | 9 | /*! 10 | \file fixmath.h 11 | \brief Functions to perform fast accurate fixed-point math operations. 12 | */ 13 | 14 | #include "uint32.h" 15 | #include "int64.h" 16 | #include "fract32.h" 17 | #include "fix16.h" 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /Runtime/libfixmath/fract32.c: -------------------------------------------------------------------------------- 1 | #include "fract32.h" 2 | 3 | 4 | 5 | fract32_t fract32_create(uint32_t inNumerator, uint32_t inDenominator) { 6 | if(inDenominator <= inNumerator) 7 | return 0xFFFFFFFF; 8 | uint32_t tempMod = (inNumerator % inDenominator); 9 | uint32_t tempDiv = (0xFFFFFFFF / (inDenominator - 1)); 10 | return (tempMod * tempDiv); 11 | } 12 | 13 | fract32_t fract32_invert(fract32_t inFract) { 14 | return (0xFFFFFFFF - inFract); 15 | } 16 | 17 | #ifndef FIXMATH_NO_64BIT 18 | uint32_t fract32_usmul(uint32_t inVal, fract32_t inFract) { 19 | return (uint32_t)(((uint64_t)inVal * (uint64_t)inFract) >> 32); 20 | } 21 | 22 | int32_t fract32_smul(int32_t inVal, fract32_t inFract) { 23 | if(inVal < 0) 24 | return -fract32_usmul(-inVal, inFract); 25 | return fract32_usmul(inVal, inFract); 26 | } 27 | #endif 28 | -------------------------------------------------------------------------------- /Runtime/libfixmath/fract32.h: -------------------------------------------------------------------------------- 1 | #ifndef __libfixmath_fract32_h__ 2 | #define __libfixmath_fract32_h__ 3 | 4 | #ifdef __cplusplus 5 | extern "C" 6 | { 7 | #endif 8 | 9 | #include 10 | 11 | typedef uint32_t fract32_t; 12 | 13 | /*! Creates a fraction using unsigned integers. 14 | \param inNumerator the unsigned integer numerator 15 | \param inDenominator the unsigned integer denominator 16 | \return a fraction using the given numerator and denominator 17 | */ 18 | extern fract32_t fract32_create(uint32_t inNumerator, uint32_t inDenominator); 19 | 20 | /*! Inverts the given fraction, swapping the numerator and the denominator. 21 | */ 22 | extern fract32_t fract32_invert(fract32_t inFract); 23 | 24 | #ifndef FIXMATH_NO_64BIT 25 | /*! Performs unsigned saturated (overflow-protected) multiplication with the two given fractions and returns the result as an unsigned integer. 26 | */ 27 | extern uint32_t fract32_usmul(uint32_t inVal, fract32_t inFract); 28 | 29 | /*! Performs saturated (overflow-protected) multiplication with the two given fractions and returns the result as a signed integer. 30 | */ 31 | extern int32_t fract32_smul(int32_t inVal, fract32_t inFract); 32 | #endif 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /Runtime/libfixmath/libfixmath.cbp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 71 | 72 | -------------------------------------------------------------------------------- /Runtime/libfixmath/uint32.c: -------------------------------------------------------------------------------- 1 | #include "uint32.h" 2 | 3 | 4 | 5 | uint32_t uint32_log2(uint32_t inVal) { 6 | if(inVal == 0) 7 | return 0; 8 | uint32_t tempOut = 0; 9 | if(inVal >= (1 << 16)) { inVal >>= 16; tempOut += 16; } 10 | if(inVal >= (1 << 8)) { inVal >>= 8; tempOut += 8; } 11 | if(inVal >= (1 << 4)) { inVal >>= 4; tempOut += 4; } 12 | if(inVal >= (1 << 2)) { inVal >>= 2; tempOut += 2; } 13 | if(inVal >= (1 << 1)) { tempOut += 1; } 14 | return tempOut; 15 | } 16 | -------------------------------------------------------------------------------- /Runtime/libfixmath/uint32.h: -------------------------------------------------------------------------------- 1 | #ifndef __libfixmath_uint32_h__ 2 | #define __libfixmath_uint32_h__ 3 | 4 | #ifdef __cplusplus 5 | extern "C" 6 | { 7 | #endif 8 | 9 | #include 10 | 11 | /*! Performs an unsigned log-base2 on the specified unsigned integer and returns the result. 12 | */ 13 | extern uint32_t uint32_log2(uint32_t inVal); 14 | 15 | #ifdef __cplusplus 16 | } 17 | #endif 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /Runtime/linker_scripts/app1.lds: -------------------------------------------------------------------------------- 1 | /* Define memory regions. */ 2 | MEMORY 3 | { 4 | rom (rx) : ORIGIN = 0x0800C000, LENGTH = 32K 5 | ram (rwx) : ORIGIN = 0x20003000, LENGTH = 34K /* Total size is 36K, leave 2K for stack */ 6 | } 7 | 8 | INCLUDE main.lds 9 | -------------------------------------------------------------------------------- /Runtime/linker_scripts/app2.lds: -------------------------------------------------------------------------------- 1 | /* Define memory regions. */ 2 | MEMORY 3 | { 4 | rom (rx) : ORIGIN = 0x08014000, LENGTH = 32K 5 | ram (rwx) : ORIGIN = 0x20003000, LENGTH = 34K /* Total size is 36K, leave 2K for stack */ 6 | } 7 | 8 | INCLUDE main.lds 9 | -------------------------------------------------------------------------------- /Runtime/linker_scripts/app3.lds: -------------------------------------------------------------------------------- 1 | /* Define memory regions. */ 2 | MEMORY 3 | { 4 | rom (rx) : ORIGIN = 0x0801C000, LENGTH = 32K 5 | ram (rwx) : ORIGIN = 0x20003000, LENGTH = 34K /* Total size is 36K, leave 2K for stack */ 6 | } 7 | 8 | INCLUDE main.lds 9 | -------------------------------------------------------------------------------- /Runtime/linker_scripts/app4.lds: -------------------------------------------------------------------------------- 1 | /* Define memory regions. */ 2 | MEMORY 3 | { 4 | rom (rx) : ORIGIN = 0x08024000, LENGTH = 32K 5 | ram (rwx) : ORIGIN = 0x20003000, LENGTH = 34K /* Total size is 36K, leave 2K for stack */ 6 | } 7 | 8 | INCLUDE main.lds 9 | -------------------------------------------------------------------------------- /Runtime/linker_scripts/main.lds: -------------------------------------------------------------------------------- 1 | /* Linker script for Olimex STM32-H103 eval board. 2 | * 3 | * Version: 0.1 4 | * 5 | * Copyright 2007 CodeSourcery. 6 | * 7 | * The authors hereby grant permission to use, copy, modify, distribute, 8 | * and license this software and its documentation for any purpose, provided 9 | * that existing copyright notices are retained in all copies and that this 10 | * notice is included verbatim in any distributions. No written agreement, 11 | * license, or royalty fee is required for any of the authorized uses. 12 | * Modifications to this software may be copyrighted by their authors 13 | * and need not follow the licensing terms described here, provided that 14 | * the new terms are clearly indicated on the first page of each file where 15 | * they apply. 16 | * 17 | * Modified by Olimex 18 | * 2009-04-07: Modified by Piotr Esden-Tempski 19 | */ 20 | 21 | _estack = 0x20000000 + 48K; 22 | 23 | SECTIONS 24 | { 25 | . = 0x0; /* From 0x00000000 */ 26 | 27 | .bios 0x08004200 (NOLOAD) : { 28 | build/BIOS.o 29 | } 30 | 31 | .alterbios 0x08009400 (NOLOAD) : { 32 | build/alterbios.o 33 | } 34 | 35 | .text : { 36 | _vectors = .; 37 | *(.isr_vectors) /* Vector table */ 38 | _scode = .; 39 | *(.text*) /* Program code */ 40 | _ecode = .; 41 | *(.rodata*) /* Read only data */ 42 | _etext = .; 43 | _sidata = _etext; 44 | } >rom 45 | 46 | . = 0x20000000; /* From 0x20000000 */ 47 | 48 | .data : { 49 | _sdata = . ; 50 | *(.data) /* Data memory */ 51 | _edata = .; 52 | } >ram AT > rom 53 | 54 | .bss : { 55 | _sbss = .; 56 | *(.bss) /* Zero-filled run time allocate data memory */ 57 | _ebss = .; 58 | } >ram AT > rom 59 | 60 | .dummy (NOLOAD) : { 61 | /* We don't need no stinking exceptions */ 62 | *(.ARM.exidx*) 63 | } 64 | } 65 | /*========== end of file ==========*/ 66 | -------------------------------------------------------------------------------- /Runtime/mathutils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define abs(x) (((x)>0) ? (x) : -(x)) 4 | 5 | // Integer division, return ceiling of the result. 6 | static inline uint32_t div_round_up(uint32_t x, uint32_t y) 7 | { 8 | return (x - 1) / y + 1; 9 | } 10 | 11 | // Integer division, round to nearest (for positive numbers) 12 | static inline uint32_t div_round(uint32_t x, uint32_t y) 13 | { 14 | return (x + y / 2) / y; 15 | } 16 | -------------------------------------------------------------------------------- /Runtime/menubar.c: -------------------------------------------------------------------------------- 1 | #include "drawing.h" 2 | #include "menubar.h" 3 | #include "BIOS.h" 4 | #include "string.h" 5 | #include 6 | 7 | #define MENU_BG RGB(0, 0, 60) 8 | #define MENU_BORDER RGB(0, 0, 120) 9 | #define MENU_TEXT RGB(255,255,255) 10 | 11 | static void draw_batteryicon(); 12 | 13 | void draw_menubar(const char *btn1, const char *btn2, const char *btn3, const char *btn4) 14 | { 15 | __Set(BETTERY_DT, 1); // Start battery voltage measurement 16 | 17 | fill_rectangle(0, 220, 400, 20, MENU_BG); 18 | drawline(0, 220, 400, 220, MENU_BORDER, 0); 19 | drawline(0, 240, 400, 240, MENU_BORDER, 0); 20 | 21 | draw_text(btn1, 20, 222, MENU_TEXT, -1, true); 22 | draw_text(btn2, 87, 222, MENU_TEXT, -1, true); 23 | draw_text(btn3, 155, 222, MENU_TEXT, -1, true); 24 | draw_text(btn4, 224, 222, MENU_TEXT, -1, true); 25 | 26 | draw_batteryicon(); 27 | } 28 | 29 | 30 | static const uint32_t battery_icon[10] = { 31 | 0b011111111111111111110000, 32 | 0b100000000000000000001000, 33 | 0b100000000000000000001000, 34 | 0b100000000000000000001100, 35 | 0b100000000000000000000010, 36 | 0b100000000000000000000010, 37 | 0b100000000000000000001100, 38 | 0b100000000000000000001000, 39 | 0b100000000000000000001000, 40 | 0b011111111111111111110000 41 | }; 42 | 43 | static const uint32_t fillpat1 = 0b101010101010101010101000; 44 | static const uint32_t fillpat2 = 0b010101010101010101011000; 45 | static const uint32_t fillmask = 0b111111111111111111111111; 46 | 47 | static void draw_batteryicon() 48 | { 49 | // Get battery charge level in percents 50 | int level = __Get(V_BATTERY); 51 | level = (level - 3500) * 100 / 500; 52 | 53 | // Copy the icon base 54 | uint32_t icon[10]; 55 | memcpy(icon, battery_icon, sizeof(icon)); 56 | 57 | // Fill in the charge level 58 | int shift = 20 - 20 * level / 100; 59 | if (shift < 0) shift = 0; 60 | uint32_t p1 = (fillpat1 << shift) & fillmask; 61 | uint32_t p2 = (fillpat2 << shift) & fillmask; 62 | 63 | for (int i = 1; i < 9; i += 2) 64 | { 65 | icon[i] |= p1; 66 | icon[i + 1] |= p2; 67 | } 68 | 69 | draw_bitmap(icon, 370, 224, MENU_TEXT, 10, false); 70 | } 71 | -------------------------------------------------------------------------------- /Runtime/menubar.h: -------------------------------------------------------------------------------- 1 | /* Function for drawing a nice menubar at the top of the screen, to show the 2 | * meanings of the keys. 3 | */ 4 | 5 | #pragma once 6 | 7 | void draw_menubar(const char *btn1, const char *btn2, const char *btn3, const char *btn4); 8 | -------------------------------------------------------------------------------- /Runtime/metadata.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | #include 4 | #include 5 | 6 | bool get_program_metadata(const char *filename, uint32_t icon[32], int *icon_size, char *name, int name_size); 7 | -------------------------------------------------------------------------------- /Runtime/msgbox.c: -------------------------------------------------------------------------------- 1 | /* A message dialog, with just simply a Close button. */ 2 | 3 | #include "drawing.h" 4 | #include "buttons.h" 5 | #include "menubar.h" 6 | #include "msgbox.h" 7 | #include "BIOS.h" 8 | 9 | void show_msgbox(const char *title, const char *message) 10 | { 11 | show_question("Close", " ", title, " ", message); 12 | } 13 | 14 | int show_question(const char *opt1, const char *opt2, const char *opt3, 15 | const char *opt4, const char *message) 16 | { 17 | get_keys(ANY_KEY); // Clear key buffer 18 | __Clear_Screen(0); 19 | 20 | draw_menubar(opt1, opt2, opt3, opt4); 21 | 22 | draw_flowtext(message, 0, 0, 400, 200, RGB(255,255,255), 0, false); 23 | 24 | bool has_command[5] = {0, !!(*opt1), !!(*opt2), !!(*opt3), !!(*opt4)}; 25 | int option = 0; 26 | while (!option) 27 | { 28 | if (get_keys(BUTTON1)) option = 1; 29 | if (get_keys(BUTTON2)) option = 2; 30 | if (get_keys(BUTTON3)) option = 3; 31 | if (get_keys(BUTTON4)) option = 4; 32 | 33 | if (!has_command[option]) option = 0; 34 | } 35 | 36 | __Clear_Screen(0); 37 | get_keys(ANY_KEY); // Clear key buffer 38 | 39 | return option; 40 | } 41 | 42 | -------------------------------------------------------------------------------- /Runtime/msgbox.h: -------------------------------------------------------------------------------- 1 | // Show a simple message box that can only be closed. 2 | void show_msgbox(const char *title, const char *message); 3 | 4 | // Returns the index 1 to 4 of the entry selected 5 | int show_question(const char *opt1, const char *opt2, const char *opt3, 6 | const char *opt4, const char *message); 7 | -------------------------------------------------------------------------------- /Runtime/utils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | /* Prevent compiler from optimizing away a memory access. 3 | * Used to reset flags for USART/SPI by reading status register. */ 4 | #define always_read(x) asm(""::"r"(x)) 5 | 6 | /* Ordinary MAX() and MIN() macros */ 7 | #define MAX(x,y) ((x) > (y) ? (x) : (y)) 8 | #define MIN(x,y) ((x) < (y) ? (x) : (y)) 9 | 10 | /* Bit-banding access to single bits. */ 11 | #define BITBAND_ACCESS(variable, bitnumber) \ 12 | *(uint32_t*)(((uint32_t)&variable & 0xF0000000) \ 13 | + 0x2000000 \ 14 | + (((uint32_t)&variable & 0x000FFFFF) << 5) \ 15 | + (bitnumber << 2)) 16 | 17 | #define set_bit(variable, bitmask) \ 18 | BITBAND_ACCESS(variable, __builtin_ctz(bitmask)) = 1 19 | 20 | #define clear_bit(variable, bitmask) \ 21 | BITBAND_ACCESS(variable, __builtin_ctz(bitmask)) = 0 22 | 23 | #define read_bit(variable, bitmask) \ 24 | BITBAND_ACCESS(variable, __builtin_ctz(bitmask)) 25 | 26 | 27 | --------------------------------------------------------------------------------