├── firmware ├── badge1.X │ ├── src │ │ ├── snake.h │ │ ├── post.h │ │ ├── tetrapuzz.h │ │ ├── badge_user.h │ │ ├── user_program.h │ │ ├── badge.h │ │ ├── disp.h │ │ ├── box_game.h │ │ ├── splash.h │ │ ├── Z80 │ │ │ ├── simglb.h │ │ │ ├── hwz.h │ │ │ ├── simint.c │ │ │ ├── simfun.c │ │ │ ├── sim.h │ │ │ ├── iosim.c │ │ │ ├── simglb.c │ │ │ ├── hwz.c │ │ │ └── sim7.c │ │ ├── tune_player.c │ │ ├── badge_settings.h │ │ ├── basic │ │ │ ├── ubasic.h │ │ │ ├── tokenizer.h │ │ │ └── tokenizer.c │ │ ├── tetrapuzz.c │ │ ├── user_program.c │ │ ├── tune_player.h │ │ ├── hw.h │ │ ├── splash.c │ │ ├── main.c │ │ ├── vt100.h │ │ ├── post.c │ │ └── snake.c │ ├── todo.txt │ ├── nbproject │ │ ├── private │ │ │ ├── SuppressibleMessageMemo.properties │ │ │ ├── private.xml │ │ │ └── configurations.xml │ │ ├── Makefile-genesis.properties │ │ ├── Makefile-variables.mk │ │ ├── project.xml │ │ ├── Package-default.bash │ │ ├── Makefile-local-default.mk │ │ └── Makefile-impl.mk │ ├── Makefile │ └── changes.txt ├── badge_alternative.X │ ├── build │ │ └── default │ │ │ └── production │ │ │ └── src │ │ │ ├── hw.o.d │ │ │ ├── disp.o.d │ │ │ ├── hw.o │ │ │ ├── badge.o │ │ │ ├── disp.o │ │ │ ├── main.o │ │ │ ├── vt100.o │ │ │ ├── badge.o.d │ │ │ ├── main.o.d │ │ │ └── vt100.o.d │ ├── nbproject │ │ ├── private │ │ │ ├── SuppressibleMessageMemo.properties │ │ │ ├── private.xml │ │ │ └── configurations.xml │ │ ├── Makefile-genesis.properties │ │ ├── Makefile-variables.mk │ │ ├── project.xml │ │ ├── Package-default.bash │ │ ├── Makefile-local-default.mk │ │ ├── Makefile-impl.mk │ │ └── Makefile-default.mk │ ├── dist │ │ └── default │ │ │ └── production │ │ │ ├── badge_alternative.X.production.elf │ │ │ └── memoryfile.xml │ ├── readme.md │ ├── src │ │ ├── main.c │ │ ├── badge.h │ │ ├── disp.h │ │ ├── hw.h │ │ ├── badge.c │ │ └── vt100.h │ └── Makefile └── auxiliary │ ├── scale_frequencies.py │ └── mario.txt ├── licensing.md ├── LICENSE └── README.md /firmware/badge1.X/src/snake.h: -------------------------------------------------------------------------------- 1 | int play_snake(void); -------------------------------------------------------------------------------- /firmware/badge1.X/src/post.h: -------------------------------------------------------------------------------- 1 | void post (void); 2 | 3 | -------------------------------------------------------------------------------- /firmware/badge1.X/todo.txt: -------------------------------------------------------------------------------- 1 | - more math functions 2 | 3 | 4 | -------------------------------------------------------------------------------- /firmware/badge_alternative.X/build/default/production/src/hw.o.d: -------------------------------------------------------------------------------- 1 | build/default/production/src/hw.o: \ 2 | src/hw.c \ 3 | src/hw.h 4 | -------------------------------------------------------------------------------- /firmware/badge1.X/nbproject/private/SuppressibleMessageMemo.properties: -------------------------------------------------------------------------------- 1 | # 2 | #Thu May 10 22:49:41 CEST 2018 3 | realice/DEVID_MISMATCH=true 4 | -------------------------------------------------------------------------------- /firmware/badge_alternative.X/nbproject/private/SuppressibleMessageMemo.properties: -------------------------------------------------------------------------------- 1 | # 2 | #Thu May 10 22:49:41 CEST 2018 3 | realice/DEVID_MISMATCH=true 4 | -------------------------------------------------------------------------------- /firmware/badge_alternative.X/build/default/production/src/disp.o.d: -------------------------------------------------------------------------------- 1 | build/default/production/src/disp.o: \ 2 | src/disp.c \ 3 | src/hw.h \ 4 | src/disp.h \ 5 | src/vt100.h 6 | -------------------------------------------------------------------------------- /firmware/badge_alternative.X/build/default/production/src/hw.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hack-a-Day/basic-badge/HEAD/firmware/badge_alternative.X/build/default/production/src/hw.o -------------------------------------------------------------------------------- /firmware/badge_alternative.X/build/default/production/src/badge.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hack-a-Day/basic-badge/HEAD/firmware/badge_alternative.X/build/default/production/src/badge.o -------------------------------------------------------------------------------- /firmware/badge_alternative.X/build/default/production/src/disp.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hack-a-Day/basic-badge/HEAD/firmware/badge_alternative.X/build/default/production/src/disp.o -------------------------------------------------------------------------------- /firmware/badge_alternative.X/build/default/production/src/main.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hack-a-Day/basic-badge/HEAD/firmware/badge_alternative.X/build/default/production/src/main.o -------------------------------------------------------------------------------- /firmware/badge_alternative.X/build/default/production/src/vt100.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hack-a-Day/basic-badge/HEAD/firmware/badge_alternative.X/build/default/production/src/vt100.o -------------------------------------------------------------------------------- /firmware/badge_alternative.X/build/default/production/src/badge.o.d: -------------------------------------------------------------------------------- 1 | build/default/production/src/badge.o: \ 2 | src/badge.c \ 3 | src/badge.h \ 4 | src/vt100.h \ 5 | src/hw.h \ 6 | src/disp.h 7 | -------------------------------------------------------------------------------- /firmware/badge_alternative.X/build/default/production/src/main.o.d: -------------------------------------------------------------------------------- 1 | build/default/production/src/main.o: \ 2 | src/main.c \ 3 | src/badge.h \ 4 | src/vt100.h \ 5 | src/hw.h \ 6 | src/disp.h 7 | -------------------------------------------------------------------------------- /firmware/badge_alternative.X/build/default/production/src/vt100.o.d: -------------------------------------------------------------------------------- 1 | build/default/production/src/vt100.o: \ 2 | src/vt100.c \ 3 | src/vt100.h \ 4 | src/badge.h \ 5 | src/hw.h \ 6 | src/disp.h 7 | -------------------------------------------------------------------------------- /firmware/badge1.X/src/tetrapuzz.h: -------------------------------------------------------------------------------- 1 | #define DROPRATE 19 2 | 3 | void tetrapuzz(void); 4 | void tetrapuzz_init(void); 5 | void tetrapuzz_loop(void); 6 | void tetrapuzz_pause(void); 7 | void tetrapuzz_gameover(void); -------------------------------------------------------------------------------- /firmware/badge_alternative.X/dist/default/production/badge_alternative.X.production.elf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hack-a-Day/basic-badge/HEAD/firmware/badge_alternative.X/dist/default/production/badge_alternative.X.production.elf -------------------------------------------------------------------------------- /firmware/badge1.X/src/badge_user.h: -------------------------------------------------------------------------------- 1 | #ifndef __BADGE_USER_H 2 | #define __BADGE_USER_H 3 | 4 | #include "badge.h" 5 | 6 | extern int8_t disp_buffer[DISP_BUFFER_HIGH+1][DISP_BUFFER_WIDE]; 7 | extern int8_t color_buffer[DISP_BUFFER_HIGH+1][DISP_BUFFER_WIDE]; 8 | 9 | 10 | #endif -------------------------------------------------------------------------------- /firmware/badge1.X/src/user_program.h: -------------------------------------------------------------------------------- 1 | /************************************ 2 | * This is the framework for those 3 | * who wish to write their own C 4 | * code for the basic badge 5 | ************************************/ 6 | void user_program_init(void); 7 | void user_program_loop(void); -------------------------------------------------------------------------------- /firmware/badge_alternative.X/readme.md: -------------------------------------------------------------------------------- 1 | This is alternative firmware, using reduced firmware framework, as starting point for those, wanting to write their own firmware on badge hardware. 2 | It is not doing anything useful, merely demonstrating how to access display/keyboard/spekaer/LEDs. -------------------------------------------------------------------------------- /licensing.md: -------------------------------------------------------------------------------- 1 | This software is licensed under MIT license, see file LICENSE. 2 | 3 | It contains sources from Z80 pack by Udo Munk, licensed under MIT license, see https://github.com/udo-munk/z80pack 4 | Also, it contains sources of UBASIC by Adam Dunkels, released under BSD license, see https://github.com/adamdunkels/ubasic 5 | 6 | -------------------------------------------------------------------------------- /firmware/badge_alternative.X/nbproject/private/private.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /firmware/badge1.X/nbproject/Makefile-genesis.properties: -------------------------------------------------------------------------------- 1 | # 2 | #Mon May 28 11:12:06 CEST 2018 3 | default.com-microchip-mplab-nbide-toolchainXC32-XC32LanguageToolchain.md5=fcf9db1a3d46b4ef4e0a46afcbf02251 4 | default.languagetoolchain.dir=/opt/microchip/xc32/v2.05/bin 5 | configurations-xml=46ac3e986feb227b11ab8d2af685c803 6 | com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=c8c2915d32f5d7e4be49831bc9827ab0 7 | default.languagetoolchain.version=2.05 8 | host.platform=linux 9 | conf.ids=default 10 | -------------------------------------------------------------------------------- /firmware/badge1.X/nbproject/Makefile-variables.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Generated - do not edit! 3 | # 4 | # NOCDDL 5 | # 6 | CND_BASEDIR=`pwd` 7 | # default configuration 8 | CND_ARTIFACT_DIR_default=dist/default/production 9 | CND_ARTIFACT_NAME_default=badge1.X.production.hex 10 | CND_ARTIFACT_PATH_default=dist/default/production/badge1.X.production.hex 11 | CND_PACKAGE_DIR_default=${CND_DISTDIR}/default/package 12 | CND_PACKAGE_NAME_default=badge1.x.tar 13 | CND_PACKAGE_PATH_default=${CND_DISTDIR}/default/package/badge1.x.tar 14 | -------------------------------------------------------------------------------- /firmware/badge_alternative.X/nbproject/Makefile-genesis.properties: -------------------------------------------------------------------------------- 1 | # 2 | #Fri May 25 16:29:17 CEST 2018 3 | default.com-microchip-mplab-nbide-toolchainXC32-XC32LanguageToolchain.md5=fcf9db1a3d46b4ef4e0a46afcbf02251 4 | default.languagetoolchain.dir=/opt/microchip/xc32/v2.05/bin 5 | configurations-xml=400581e35951badbe2d9613763196e5b 6 | com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=c8c2915d32f5d7e4be49831bc9827ab0 7 | default.languagetoolchain.version=2.05 8 | host.platform=linux 9 | conf.ids=default 10 | -------------------------------------------------------------------------------- /firmware/badge_alternative.X/nbproject/Makefile-variables.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Generated - do not edit! 3 | # 4 | # NOCDDL 5 | # 6 | CND_BASEDIR=`pwd` 7 | # default configuration 8 | CND_ARTIFACT_DIR_default=dist/default/production 9 | CND_ARTIFACT_NAME_default=badge_alternative.X.production.hex 10 | CND_ARTIFACT_PATH_default=dist/default/production/badge_alternative.X.production.hex 11 | CND_PACKAGE_DIR_default=${CND_DISTDIR}/default/package 12 | CND_PACKAGE_NAME_default=badgealternative.x.tar 13 | CND_PACKAGE_PATH_default=${CND_DISTDIR}/default/package/badgealternative.x.tar 14 | -------------------------------------------------------------------------------- /firmware/badge1.X/nbproject/private/private.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | file:/E:/jarin/_backup_m/badge/badge1.X/src/badge.c 7 | file:/E:/jarin/_backup_m/badge/badge1.X/src/basic/ubasic.c 8 | file:/E:/jarin/_backup_m/badge/badge1.X/src/main.c 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /firmware/badge1.X/nbproject/project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | com.microchip.mplab.nbide.embedded.makeproject 4 | 5 | 6 | badge1 7 | 4c890340-e8fa-4dd9-8ce3-1d80c8c40d12 8 | 0 9 | c 10 | 11 | h 12 | 13 | ISO-8859-1 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /firmware/badge_alternative.X/nbproject/project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | com.microchip.mplab.nbide.embedded.makeproject 4 | 5 | 6 | badge_alternative 7 | 4c890340-e8fa-4dd9-8ce3-1d80c8c40d12 8 | 0 9 | c 10 | 11 | h 12 | 13 | ISO-8859-1 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /firmware/badge_alternative.X/src/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "badge.h" 3 | #include "hw.h" 4 | 5 | uint8_t char_out,char_last; 6 | int16_t main(void) 7 | { 8 | hw_init(); 9 | badge_init(); 10 | stdio_write("keyboard repeater\n"); 11 | while (1) 12 | { 13 | uint8_t get_stat = stdio_get(&char_out); //get key status 14 | if (get_stat!=0) 15 | { 16 | stdio_c(char_out); //if there is anything in here, print it and play 17 | //major/diminished/augumented chord with minor or major triad, depending on current and prev key 18 | sound_play_notes(char_out>>1,3+char_out>>1+(char_out&1),6+char_out>>1+(char_last&0x03),100); 19 | //also, turn on/off LEDs depending on current key 20 | set_led(((char_out>>1)&0x03),char_out&0x01); 21 | video_set_color(char_last,char_out); //set some funny color next time 22 | char_last = char_out; 23 | } 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /firmware/badge_alternative.X/src/badge.h: -------------------------------------------------------------------------------- 1 | #ifndef __BADGE_H 2 | #define __BADGE_H 3 | 4 | #include 5 | #include "vt100.h" 6 | #include "hw.h" 7 | #include "disp.h" 8 | 9 | 10 | void terminal_init(void); 11 | int8_t term_k_stat (void); 12 | int8_t term_k_char (int8_t * out); 13 | uint8_t rx_sta (void); 14 | uint8_t rx_read (void); 15 | void tx_write (uint8_t data); 16 | 17 | uint8_t stdio_local_buffer_state (void); 18 | int8_t stdio_local_buffer_get (void); 19 | void stdio_local_buffer_put (int8_t data); 20 | void stdio_local_buffer_puts (int8_t * data); 21 | 22 | uint16_t get_user_value (void); 23 | void enable_display_scanning(uint8_t onoff); 24 | uint32_t millis(void); 25 | void display_refresh_force (void); 26 | void clr_buffer (void); 27 | 28 | #define STDIO_LOCAL_BUFF_SIZE 25 29 | 30 | /***************************************************************************************************/ 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /firmware/badge_alternative.X/dist/default/production/memoryfile.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | bytes 6 | 531968 7 | 60712 8 | 471256 9 | 10 | 11 | bytes 12 | 131072 13 | 3568 14 | 127504 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2018, Supplyframe, Inc. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /firmware/badge1.X/nbproject/private/configurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Makefile 4 | 0 5 | 6 | 7 | :=MPLABComm-USB-Microchip:=<vid>04D8:=<pid>900A:=<rev>0002:=<man>Microchip Technology Inc.:=<prod>PICkit 3:=<sn>BUR094610969:=<drv>x:=<xpt>h:=end 8 | /opt/microchip/xc32/v2.05/bin 9 | 10 | place holder 1 11 | place holder 2 12 | 13 | 14 | 15 | 16 | true 17 | 0 18 | 0 19 | 0 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /firmware/badge_alternative.X/nbproject/private/configurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Makefile 4 | 0 5 | 6 | 7 | :=MPLABComm-USB-Microchip:=<vid>04D8:=<pid>9012:=<rev>0100:=<man>Microchip Technology Incorporated:=<prod>MPLAB PICkit 4:=<sn>BUR180524591:=<drv>x:=<xpt>b:=end 8 | /opt/microchip/xc32/v2.05/bin 9 | 10 | place holder 1 11 | place holder 2 12 | 13 | 14 | 15 | 16 | true 17 | 0 18 | 0 19 | 0 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /firmware/badge1.X/src/badge.h: -------------------------------------------------------------------------------- 1 | #ifndef __BADGE_H 2 | #define __BADGE_H 3 | 4 | #include 5 | #include "tune_player.h" 6 | #include "splash.h" 7 | #include "tetrapuzz.h" 8 | #include "post.h" 9 | #include "badge_settings.h" 10 | #include "snake.h" 11 | #include "user_program.h" 12 | #include "vt100.h" 13 | #include "Z80/hwz.h" 14 | #include "hw.h" 15 | #include "disp.h" 16 | #include 17 | 18 | 19 | void terminal_init(void); 20 | int8_t term_k_stat (void); 21 | int8_t term_k_char (int8_t * out); 22 | uint8_t rx_sta (void); 23 | uint8_t rx_read (void); 24 | void tx_write (uint8_t data); 25 | 26 | const char* get_firmware_string(void); 27 | void loop_badge(void); 28 | 29 | uint8_t stdio_local_buffer_state (void); 30 | int8_t stdio_local_buffer_get (void); 31 | void stdio_local_buffer_put (int8_t data); 32 | void stdio_local_buffer_puts (int8_t * data); 33 | 34 | uint16_t get_user_value (void); 35 | void enable_display_scanning(uint8_t onoff); 36 | uint32_t millis(void); 37 | void display_refresh_force (void); 38 | void clr_buffer (void); 39 | 40 | 41 | /***************************************************************************************************/ 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /firmware/badge1.X/src/disp.h: -------------------------------------------------------------------------------- 1 | #ifndef __DISP_H 2 | #define __DISP_H 3 | 4 | 5 | void TFT_24_7789_Init(void); 6 | inline void TFT_24_7789_Write_Data(uint16_t data1); 7 | inline void TFT_24_7789_Write_Data3(uint16_t data1,uint16_t data2, uint16_t data3); 8 | void TFT_24_7789_Write_Command(uint16_t command); 9 | inline void tft_set_write_area (uint16_t x, uint16_t y, uint16_t xlen, uint16_t ylen); 10 | inline void tft_print_char (uint8_t val, uint16_t x, uint16_t y, uint32_t col, uint32_t back); 11 | void tft_fill_area (uint16_t x, uint16_t y, uint16_t xlen, uint16_t ylen, uint32_t back); 12 | void tft_disp_buffer_refresh(uint8_t * buff, uint8_t * color_buff); 13 | void tft_disp_buffer_refresh_part(uint8_t * buff, uint8_t * color_buff); 14 | void disp_tasks (void); 15 | void set_cursor_state (uint8_t state); 16 | 17 | 18 | #define EGA_BLACK 0 19 | #define EGA_BLUE 1 20 | #define EGA_GREEN 2 21 | #define EGA_CYAN 3 22 | #define EGA_RED 4 23 | #define EGA_MAGENTA 5 24 | #define EGA_BROWN 6 25 | #define EGA_LGRAY 7 26 | #define EGA_DGRAY 8 27 | #define EGA_BBLUE 9 28 | #define EGA_BBGREEN 10 29 | #define EGA_BCYAN 11 30 | #define EGA_BRED 12 31 | #define EGA_BMAGENTA 13 32 | #define EGA_YELLOW 14 33 | #define EGA_WHITE 15 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /firmware/badge_alternative.X/src/disp.h: -------------------------------------------------------------------------------- 1 | #ifndef __DISP_H 2 | #define __DISP_H 3 | 4 | 5 | void TFT_24_7789_Init(void); 6 | inline void TFT_24_7789_Write_Data(uint16_t data1); 7 | inline void TFT_24_7789_Write_Data3(uint16_t data1,uint16_t data2, uint16_t data3); 8 | void TFT_24_7789_Write_Command(uint16_t command); 9 | inline void tft_set_write_area (uint16_t x, uint16_t y, uint16_t xlen, uint16_t ylen); 10 | inline void tft_print_char (uint8_t val, uint16_t x, uint16_t y, uint32_t col, uint32_t back); 11 | void tft_fill_area (uint16_t x, uint16_t y, uint16_t xlen, uint16_t ylen, uint32_t back); 12 | void tft_disp_buffer_refresh(uint8_t * buff, uint8_t * color_buff); 13 | void tft_disp_buffer_refresh_part(uint8_t * buff, uint8_t * color_buff); 14 | void disp_tasks (void); 15 | void set_cursor_state (uint8_t state); 16 | 17 | 18 | #define EGA_BLACK 0 19 | #define EGA_BLUE 1 20 | #define EGA_GREEN 2 21 | #define EGA_CYAN 3 22 | #define EGA_RED 4 23 | #define EGA_MAGENTA 5 24 | #define EGA_BROWN 6 25 | #define EGA_LGRAY 7 26 | #define EGA_DGRAY 8 27 | #define EGA_BBLUE 9 28 | #define EGA_BBGREEN 10 29 | #define EGA_BCYAN 11 30 | #define EGA_BRED 12 31 | #define EGA_BMAGENTA 13 32 | #define EGA_YELLOW 14 33 | #define EGA_WHITE 15 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /firmware/badge1.X/src/box_game.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | //Prototypes 4 | void BOX_seed_random(unsigned char); 5 | void BOX_inc_random(void); 6 | uint8_t BOX_get_score(void); 7 | uint16_t BOX_get_delay(void); 8 | void BOX_clearscreen(void); 9 | void BOX_draw(uint8_t X, uint8_t Y, uint32_t color); 10 | void BOX_erase(uint8_t X, uint8_t Y); 11 | void BOX_pregame(void); 12 | void BOX_start_game(void); 13 | void BOX_show_gameover(void); 14 | uint8_t BOX_end_game(void); 15 | void BOX_update_score(void); 16 | void BOX_print_string(const int8_t * buf, uint16_t x_pixel, uint8_t y_pixel, uint32_t fgcolor, uint32_t bgcolor); 17 | uint8_t BOX_loc_return_bit(uint8_t X, uint8_t Y); 18 | void BOX_loc_set_bit(uint8_t X, uint8_t Y); 19 | void BOX_loc_clear_bit(uint8_t X, uint8_t Y); 20 | void BOX_store_loc(void); 21 | void BOX_clear_loc(void); 22 | void BOX_load_reference(uint8_t piece, uint8_t rotation); 23 | void BOX_rotate(uint8_t direction); 24 | void BOX_write_piece(void); 25 | void BOX_clear_piece(void); 26 | void BOX_rewrite_display(uint32_t fgcolor); 27 | void BOX_update_screen(void); 28 | void BOX_spawn(void); 29 | uint8_t BOX_check(int8_t X_offset, int8_t Y_offset); 30 | void BOX_line_check(void); 31 | void BOX_up(void); 32 | void BOX_dn(void); 33 | void BOX_lt(void); 34 | void BOX_rt(void); -------------------------------------------------------------------------------- /firmware/badge1.X/src/splash.h: -------------------------------------------------------------------------------- 1 | #ifndef __SLPASH_H 2 | #define __SLPASH_H 3 | 4 | /* 5 | * Graphic from poster located here: 6 | * https://cdn.hackaday.io/images/5980891518077065617.png 7 | * 8 | * Napkin calculations: 9 | * Original spacing is 347px letters with 32px spaces 10 | * Combining character with spaces calls for 8.44% space 11 | * 240px screen, 4 characters 12 | * Characters should be 54px (18px subchars each) with 5px spacing and 3px on top 13 | */ 14 | 15 | #include 16 | 17 | #define CIPHER_X0 42 18 | #define CIPHER_Y0 2 19 | #define CIPHER_CHAR_WIDTH 18 20 | #define CIPHER_SPACE 5 21 | #define CIPHER_COLOR 0xEE3530 22 | #define CIPHER_BACKGROUND 0x000000 23 | #define CIPHER_CURSOR 0xFFFFFF 24 | 25 | void show_splash(void); 26 | void draw_vert_line(uint16_t x, uint8_t y, uint8_t height, uint32_t color); 27 | void animate_splash(void); 28 | uint8_t overlaps_logo(int16_t x, uint8_t row); 29 | 30 | const uint16_t b_cipher[12] = { 31 | 0b0000101010111101, 32 | 0b0000010111100110, 33 | 0b0000101101111101, 34 | 35 | 0b0000010110010101, 36 | 0b0000111101111010, 37 | 0b0000101110101010, 38 | 39 | 0b0000100111100110, 40 | 0b0000111110100101, 41 | 0b0000111111111111, 42 | 43 | 0b0000111010110111, 44 | 0b0000110111101110, 45 | 0b0000101101110111 46 | }; 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /firmware/badge1.X/src/Z80/simglb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Z80SIM - a Z80-CPU simulator 3 | * 4 | * Copyright (C) 1987-92 by Udo Munk 5 | * 6 | * This module of the Z80-CPU simulator must not be modified by a user, 7 | * see license agreement! 8 | * 9 | * History: 10 | * 28-SEP-87 Development on TARGON/35 with AT&T Unix System V.3 11 | * 11-JAN-89 Release 1.1 12 | * 08-FEB-89 Release 1.2 13 | * 13-MAR-89 Release 1.3 14 | * 09-FEB-90 Release 1.4 Ported to TARGON/31 M10/30 15 | * 20-DEC-90 Release 1.5 Ported to COHERENT 3.0 16 | * 10-JUN-92 Release 1.6 long casting problem solved with COHERENT 3.2 17 | * and some optimization 18 | * 25-JUN-92 Release 1.7 comments in english and ported to COHERENT 4.0 19 | */ 20 | 21 | /* 22 | * Declaration of variables in simglb.c 23 | */ 24 | 25 | extern BYTE A,B,C,D,E,H,L,A_,B_,C_,D_,E_,H_,L_,*PC,*STACK,I,IFF; 26 | extern WORD IX,IY; 27 | extern int F,F_; 28 | extern long R; 29 | 30 | extern BYTE ram[],*wrk_ram; 31 | 32 | extern int s_flag,l_flag,m_flag,x_flag,break_flag,cpu_state,cpu_error, 33 | int_type,int_mode,cntl_c,cntl_bs,parrity[],sb_next; 34 | 35 | extern char xfn[]; 36 | 37 | #ifdef HISIZE 38 | extern struct history his[]; 39 | extern int h_next, h_flag; 40 | #endif 41 | 42 | #ifdef SBSIZE 43 | extern struct softbreak soft[]; 44 | #endif 45 | 46 | #ifdef WANT_TIM 47 | extern long t_states; 48 | extern int t_flag; 49 | extern BYTE *t_start, *t_end; 50 | #endif 51 | 52 | #if defined(COHERENT) && !defined(_I386) 53 | extern char adr_err[]; 54 | #endif 55 | -------------------------------------------------------------------------------- /firmware/badge1.X/src/tune_player.c: -------------------------------------------------------------------------------- 1 | #include "tune_player.h" 2 | 3 | void play_music_array(const unsigned char * arr, unsigned char length, const unsigned int * tempo_arr) 4 | { 5 | unsigned char i; 6 | for (i=0; i<(length/4); i++) 7 | { 8 | unsigned char index = i*4; 9 | sound_play_notes(*(arr+index), *(arr+index+1), *(arr+index+2), *(tempo_arr+*(arr+index+3))); 10 | } 11 | } 12 | 13 | void play_mario_tune(void) 14 | { 15 | play_music_array(mario_main0,mario_array_limits[0],mario_tempos); 16 | 17 | play_music_array(mario_clip0,mario_array_limits[4],mario_tempos); 18 | play_music_array(mario_clip1,mario_array_limits[5],mario_tempos); 19 | play_music_array(mario_clip0,mario_array_limits[4],mario_tempos); 20 | play_music_array(mario_clip1,mario_array_limits[5],mario_tempos); 21 | play_music_array(mario_clip2,mario_array_limits[6],mario_tempos); 22 | play_music_array(mario_clip3,mario_array_limits[7],mario_tempos); 23 | play_music_array(mario_clip2,mario_array_limits[6],mario_tempos); 24 | 25 | play_music_array(mario_main1,mario_array_limits[1],mario_tempos); 26 | 27 | play_music_array(mario_clip2,mario_array_limits[6],mario_tempos); 28 | play_music_array(mario_clip3,mario_array_limits[7],mario_tempos); 29 | play_music_array(mario_clip2,mario_array_limits[6],mario_tempos); 30 | 31 | play_music_array(mario_main2,mario_array_limits[2],mario_tempos); 32 | play_music_array(mario_clip4,mario_array_limits[7],mario_tempos); 33 | play_music_array(mario_main3,mario_array_limits[3],mario_tempos); 34 | play_music_array(mario_clip4,mario_array_limits[7],mario_tempos); 35 | } 36 | -------------------------------------------------------------------------------- /firmware/badge1.X/nbproject/Package-default.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash -x 2 | 3 | # 4 | # Generated - do not edit! 5 | # 6 | 7 | # Macros 8 | TOP=`pwd` 9 | CND_CONF=default 10 | CND_DISTDIR=dist 11 | TMPDIR=build/${CND_CONF}/${IMAGE_TYPE}/tmp-packaging 12 | TMPDIRNAME=tmp-packaging 13 | OUTPUT_PATH=dist/${CND_CONF}/${IMAGE_TYPE}/badge1.X.${IMAGE_TYPE}.${OUTPUT_SUFFIX} 14 | OUTPUT_BASENAME=badge1.X.${IMAGE_TYPE}.${OUTPUT_SUFFIX} 15 | PACKAGE_TOP_DIR=badge1.x/ 16 | 17 | # Functions 18 | function checkReturnCode 19 | { 20 | rc=$? 21 | if [ $rc != 0 ] 22 | then 23 | exit $rc 24 | fi 25 | } 26 | function makeDirectory 27 | # $1 directory path 28 | # $2 permission (optional) 29 | { 30 | mkdir -p "$1" 31 | checkReturnCode 32 | if [ "$2" != "" ] 33 | then 34 | chmod $2 "$1" 35 | checkReturnCode 36 | fi 37 | } 38 | function copyFileToTmpDir 39 | # $1 from-file path 40 | # $2 to-file path 41 | # $3 permission 42 | { 43 | cp "$1" "$2" 44 | checkReturnCode 45 | if [ "$3" != "" ] 46 | then 47 | chmod $3 "$2" 48 | checkReturnCode 49 | fi 50 | } 51 | 52 | # Setup 53 | cd "${TOP}" 54 | mkdir -p ${CND_DISTDIR}/${CND_CONF}/package 55 | rm -rf ${TMPDIR} 56 | mkdir -p ${TMPDIR} 57 | 58 | # Copy files and create directories and links 59 | cd "${TOP}" 60 | makeDirectory ${TMPDIR}/badge1.x/bin 61 | copyFileToTmpDir "${OUTPUT_PATH}" "${TMPDIR}/${PACKAGE_TOP_DIR}bin/${OUTPUT_BASENAME}" 0755 62 | 63 | 64 | # Generate tar file 65 | cd "${TOP}" 66 | rm -f ${CND_DISTDIR}/${CND_CONF}/package/badge1.x.tar 67 | cd ${TMPDIR} 68 | tar -vcf ../../../../${CND_DISTDIR}/${CND_CONF}/package/badge1.x.tar * 69 | checkReturnCode 70 | 71 | # Cleanup 72 | cd "${TOP}" 73 | rm -rf ${TMPDIR} 74 | -------------------------------------------------------------------------------- /firmware/badge_alternative.X/nbproject/Package-default.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash -x 2 | 3 | # 4 | # Generated - do not edit! 5 | # 6 | 7 | # Macros 8 | TOP=`pwd` 9 | CND_CONF=default 10 | CND_DISTDIR=dist 11 | TMPDIR=build/${CND_CONF}/${IMAGE_TYPE}/tmp-packaging 12 | TMPDIRNAME=tmp-packaging 13 | OUTPUT_PATH=dist/${CND_CONF}/${IMAGE_TYPE}/badge_alternative.X.${IMAGE_TYPE}.${OUTPUT_SUFFIX} 14 | OUTPUT_BASENAME=badge_alternative.X.${IMAGE_TYPE}.${OUTPUT_SUFFIX} 15 | PACKAGE_TOP_DIR=badgealternative.x/ 16 | 17 | # Functions 18 | function checkReturnCode 19 | { 20 | rc=$? 21 | if [ $rc != 0 ] 22 | then 23 | exit $rc 24 | fi 25 | } 26 | function makeDirectory 27 | # $1 directory path 28 | # $2 permission (optional) 29 | { 30 | mkdir -p "$1" 31 | checkReturnCode 32 | if [ "$2" != "" ] 33 | then 34 | chmod $2 "$1" 35 | checkReturnCode 36 | fi 37 | } 38 | function copyFileToTmpDir 39 | # $1 from-file path 40 | # $2 to-file path 41 | # $3 permission 42 | { 43 | cp "$1" "$2" 44 | checkReturnCode 45 | if [ "$3" != "" ] 46 | then 47 | chmod $3 "$2" 48 | checkReturnCode 49 | fi 50 | } 51 | 52 | # Setup 53 | cd "${TOP}" 54 | mkdir -p ${CND_DISTDIR}/${CND_CONF}/package 55 | rm -rf ${TMPDIR} 56 | mkdir -p ${TMPDIR} 57 | 58 | # Copy files and create directories and links 59 | cd "${TOP}" 60 | makeDirectory ${TMPDIR}/badgealternative.x/bin 61 | copyFileToTmpDir "${OUTPUT_PATH}" "${TMPDIR}/${PACKAGE_TOP_DIR}bin/${OUTPUT_BASENAME}" 0755 62 | 63 | 64 | # Generate tar file 65 | cd "${TOP}" 66 | rm -f ${CND_DISTDIR}/${CND_CONF}/package/badgealternative.x.tar 67 | cd ${TMPDIR} 68 | tar -vcf ../../../../${CND_DISTDIR}/${CND_CONF}/package/badgealternative.x.tar * 69 | checkReturnCode 70 | 71 | # Cleanup 72 | cd "${TOP}" 73 | rm -rf ${TMPDIR} 74 | -------------------------------------------------------------------------------- /firmware/badge1.X/src/Z80/hwz.h: -------------------------------------------------------------------------------- 1 | #ifndef __HWZ_H 2 | #define __HWZ_H 3 | 4 | #include 5 | #include "../badge_settings.h" 6 | 7 | #define CUT_ROMDISK2 8 | 9 | #ifdef CUT_ROMDISK2 10 | #define ROMDISK2_SIZE 131072-(18*1024) 11 | #endif 12 | #ifndef CUT_ROMDISK2 13 | #define ROMDISK2_SIZE 131072 14 | #endif 15 | 16 | #define RAMDISK_SIZE (1024*22) 17 | 18 | #define CPM1_DISK1_OFFSET 1*4096 19 | #define CPM1_DISK2_OFFSET 2*4096 20 | #define CPM1_DISK3_OFFSET 3*4096 21 | 22 | //#define USE_EEPROM 23 | 24 | uint8_t rx_sta (void); 25 | uint8_t rx_read (void); 26 | void tx_write (uint8_t data); 27 | void set_drive (uint8_t dat); 28 | void set_sector (uint8_t dat); 29 | void set_track (uint8_t dat); 30 | uint8_t read_disk_byte (void); 31 | void write_disk_byte (uint8_t dat); 32 | 33 | unsigned char SPI_dat (uint8_t data); 34 | uint8_t ee_rs (void); 35 | void ee_wren (void); 36 | void ee_wrdi (void); 37 | void init_diskb(void); 38 | 39 | uint8_t rxk_sta (void); 40 | uint8_t rxk_read (void); 41 | 42 | 43 | void wait_1ms (void); 44 | void wait_ms (uint32_t count); 45 | void wait_cyc (uint16_t cyc); 46 | void init_termint (void); 47 | 48 | 49 | 50 | uint8_t init_first_x_sects (uint8_t i, uint8_t verify); 51 | 52 | void fl_write(uint32_t addr,uint8_t data); 53 | void fl_erase_4k(uint32_t addr); 54 | void fl_read_4k(uint32_t addr, uint8_t * data); 55 | void fl_rst_pb(void); 56 | void fl_wren(void); 57 | void fl_write_4k(uint32_t addr, uint8_t * data); 58 | void fl_read_nk(uint32_t addr, uint8_t * data, uint16_t n); 59 | void fl_read_128(uint32_t sector,uint8_t * data); 60 | void fl_write_128(uint32_t sector,uint8_t * data); 61 | 62 | void read_sector (unsigned char *data, unsigned int addr); 63 | void write_sector (unsigned char *data, unsigned int addr); 64 | 65 | #define IO_CPM_MODE 0 66 | #define IO_BASIC_MODE 1 67 | 68 | #endif -------------------------------------------------------------------------------- /firmware/badge1.X/src/Z80/simint.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Z80SIM - a Z80-CPU simulator 3 | * 4 | * Copyright (C) 1987-92 by Udo Munk 5 | * 6 | * This module of the Z80-CPU simulator must not be modified by a user, 7 | * see license agreement! 8 | * 9 | * History: 10 | * 28-SEP-87 Development on TARGON/35 with AT&T Unix System V.3 11 | * 11-JAN-89 Release 1.1 12 | * 08-FEB-89 Release 1.2 13 | * 13-MAR-89 Release 1.3 14 | * 09-FEB-90 Release 1.4 Ported to TARGON/31 M10/30 15 | * 20-DEC-90 Release 1.5 Ported to COHERENT 3.0 16 | * 10-JUN-92 Release 1.6 long casting problem solved with COHERENT 3.2 17 | * and some optimization 18 | * 25-JUN-92 Release 1.7 comments in english 19 | */ 20 | 21 | /* 22 | * This module contain the interrupt handlers for the OS: 23 | * 24 | * int_on() : initialize interrupt handlers 25 | * int_off() : reset interrupts to default 26 | * user_int() : handler for user interrupt (CNTL-C) 27 | * quit_int() : handler for signal "quit" 28 | * nmi_int() : handler for non maskable interrupt (Z80) 29 | * int_int() : handler for maskable interrupt (Z80) 30 | */ 31 | 32 | #define _FULL_SIGNAL_IMPLEMENTATION 33 | 34 | #include 35 | #include 36 | #include 37 | #include "sim.h" 38 | #include "simglb.h" 39 | 40 | int_on() 41 | { 42 | void user_int(); 43 | void quit_int(); 44 | 45 | signal(SIGINT, user_int); 46 | signal(SIGQUIT, quit_int); 47 | } 48 | 49 | int_off() 50 | { 51 | signal(SIGINT, SIG_DFL); 52 | signal(SIGQUIT, SIG_DFL); 53 | } 54 | 55 | void user_int() 56 | { 57 | signal(SIGINT, user_int); 58 | #ifdef CNTL_C 59 | cpu_error = USERINT; 60 | cpu_state = STOPPED; 61 | #else 62 | cntl_c++; 63 | #endif 64 | } 65 | 66 | void quit_int() 67 | { 68 | signal(SIGQUIT, quit_int); 69 | #ifdef CNTL_BS 70 | cpu_error = USERINT; 71 | cpu_state = STOPPED; 72 | #else 73 | cntl_bs++; 74 | #endif 75 | } 76 | -------------------------------------------------------------------------------- /firmware/badge1.X/src/Z80/simfun.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Z80SIM - a Z80-CPU simulator 3 | * 4 | * Copyright (C) 1987-92 by Udo Munk 5 | * 6 | * This module of the Z80-CPU simulator must not be modified by a user, 7 | * see license agreement! 8 | * 9 | * History: 10 | * 28-SEP-87 Development on TARGON/35 with AT&T Unix System V.3 11 | * 11-JAN-89 Release 1.1 12 | * 08-FEB-89 Release 1.2 13 | * 13-MAR-89 Release 1.3 14 | * 09-FEB-90 Release 1.4 Ported to TARGON/31 M10/30 15 | * 20-DEC-90 Release 1.5 Ported to COHERENT 3.0 16 | * 10-JUN-92 Release 1.6 long casting problem solved with COHERENT 3.2 17 | * and some optimization 18 | * 25-JUN-92 Release 1.7 comments in english and ported to COHERENT 4.0 19 | */ 20 | 21 | /* 22 | * This modul contains some commonly used functions 23 | */ 24 | 25 | #include 26 | #include "sim.h" 27 | 28 | /* 29 | * atoi for hexadecimal numbers 30 | */ 31 | exatoi(str) 32 | register char *str; 33 | { 34 | register int num = 0; 35 | 36 | while (isxdigit(*str)) { 37 | num *= 16; 38 | if (*str <= '9') 39 | num += *str - '0'; 40 | else 41 | num += toupper(*str) - '7'; 42 | str++; 43 | } 44 | return(num); 45 | } 46 | 47 | /* 48 | * Wait for a single keystroke without echo 49 | */ 50 | getkey() 51 | { 52 | //jar 53 | /* 54 | register int c; 55 | #if defined(COHERENT) && !defined(_I386) 56 | struct sgttyb old_term, new_term; 57 | #else 58 | struct termio old_term, new_term; 59 | #endif 60 | 61 | #if defined(COHERENT) && !defined(_I386) 62 | gtty(0, &old_term); 63 | new_term = old_term; 64 | new_term.sg_flags |= CBREAK; 65 | new_term.sg_flags &= ~ECHO; 66 | stty(0, &new_term); 67 | #else 68 | ioctl(0, TCGETA, &old_term); 69 | new_term = old_term; 70 | new_term.c_lflag &= ~(ICANON | ECHO); 71 | new_term.c_cc[4] = 1; 72 | #endif 73 | c = getchar(); 74 | #if defined(COHERENT) && !defined(_I386) 75 | stty(0, &old_term); 76 | #else 77 | ioctl(0, TCSETAW, &old_term); 78 | #endif 79 | return(c); 80 | */ 81 | } 82 | -------------------------------------------------------------------------------- /firmware/badge1.X/src/badge_settings.h: -------------------------------------------------------------------------------- 1 | //badge user settings 2 | 3 | #ifndef __BADGE_SETTINGS_H 4 | #define __BADGE_SETTINGS_H 5 | 6 | //Badge firmware version should be defined as a string here: 7 | #define FIRMWARE_VERSION "1.04" 8 | 9 | //define length of BASIC program RAM buffer 10 | //increasing the length will allow you to hold larger programs 11 | // load and save functions are set to 4096B only though 12 | #define BPROG_LEN 16384 13 | 14 | //define size and number of sectors for saving BASIC programs 15 | //BPROG_LEN = BPROG_SECSIZ*BPROG_SECNUM 16 | #define BPROG_SECSIZ 4096 17 | #define BPROG_SECNUM 4 18 | 19 | //amount of BASIC program slots 20 | #define BASIC_SAVNUM 16 21 | //FLASH_CONSUMED = BASIC_SAVNUM*BPROG_LEN - that is how much of FLASH is consumed 22 | //the rest up to 0x080000 is free for user 23 | //if you don't care for BASIC or CP/M, do as you wish 24 | 25 | //where is the start of slot region in FLASH 26 | #define BASIC_BASEADDR 0 27 | /* 28 | * FLASH organization is as follows 29 | * 0x000000-0x003FFF - first slot 30 | * 0x004000-0x007FFF - second slot 31 | * ...etc 32 | * 0x03C000-0x03FFFF - 16-th slot 33 | * 0x040000-0x07FFFF - empty space 34 | * 0x080000-0x0FFFFF - D disk of CP/M machine 35 | */ 36 | 37 | //Set SHOW_SPLASH to 0 to skip splash screen at boot 38 | #define SHOW_SPLASH 1 39 | 40 | //B_BDG010 41 | //this one enables 64k of RAM image for CP/M 42 | //if off, disables all CP/M stuff and leaves "empty" Z80 machine 43 | #define USE_RAM_IMAGE 44 | //first ROM disk, full of utils, mapped as disk B. you can disable this one 45 | #define USE_ROMDISK 46 | //second ROM disk, with games, mapped as disk C. you can disable this one 47 | #define USE_ROMDISK2 48 | //RAM disk, you can save 22kb of RAM by disabling it 49 | #define USE_RAMDISK 50 | 51 | //FLASH buffering of CP/M disk drives. 52 | //enabled - use RAM buffering, faster, less wear-out 53 | //disabled - more stable and straight-forward 54 | #define FLASH_BUFFERING 55 | 56 | 57 | #endif -------------------------------------------------------------------------------- /firmware/badge1.X/src/basic/ubasic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006, Adam Dunkels 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. Neither the name of the author nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | */ 30 | #ifndef __UBASIC_H__ 31 | #define __UBASIC_H__ 32 | 33 | #include 34 | void ubasic_init(const char *program, uint8_t mode); 35 | void ubasic_run(void); 36 | int ubasic_finished(void); 37 | 38 | int ubasic_get_variable(int varnum); 39 | void ubasic_set_variable(int varum, int value); 40 | 41 | #endif /* __UBASIC_H__ */ 42 | -------------------------------------------------------------------------------- /firmware/badge1.X/nbproject/Makefile-local-default.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Generated Makefile - do not edit! 3 | # 4 | # 5 | # This file contains information about the location of compilers and other tools. 6 | # If you commmit this file into your revision control server, you will be able to 7 | # to checkout the project and build it from the command line with make. However, 8 | # if more than one person works on the same project, then this file might show 9 | # conflicts since different users are bound to have compilers in different places. 10 | # In that case you might choose to not commit this file and let MPLAB X recreate this file 11 | # for each user. The disadvantage of not commiting this file is that you must run MPLAB X at 12 | # least once so the file gets created and the project can be built. Finally, you can also 13 | # avoid using this file at all if you are only building from the command line with make. 14 | # You can invoke make with the values of the macros: 15 | # $ makeMP_CC="/opt/microchip/mplabc30/v3.30c/bin/pic30-gcc" ... 16 | # 17 | PATH_TO_IDE_BIN=/opt/microchip/mplabx/v4.15/mplab_ide/platform/../mplab_ide/modules/../../bin/ 18 | # Adding MPLAB X bin directory to path. 19 | PATH:=/opt/microchip/mplabx/v4.15/mplab_ide/platform/../mplab_ide/modules/../../bin/:$(PATH) 20 | # Path to java used to run MPLAB X when this makefile was created 21 | MP_JAVA_PATH="/opt/microchip/mplabx/v4.15/sys/java/jre1.8.0_144/bin/" 22 | OS_CURRENT="$(shell uname -s)" 23 | MP_CC="/opt/microchip/xc32/v2.05/bin/xc32-gcc" 24 | MP_CPPC="/opt/microchip/xc32/v2.05/bin/xc32-g++" 25 | # MP_BC is not defined 26 | MP_AS="/opt/microchip/xc32/v2.05/bin/xc32-as" 27 | MP_LD="/opt/microchip/xc32/v2.05/bin/xc32-ld" 28 | MP_AR="/opt/microchip/xc32/v2.05/bin/xc32-ar" 29 | DEP_GEN=${MP_JAVA_PATH}java -jar "/opt/microchip/mplabx/v4.15/mplab_ide/platform/../mplab_ide/modules/../../bin/extractobjectdependencies.jar" 30 | MP_CC_DIR="/opt/microchip/xc32/v2.05/bin" 31 | MP_CPPC_DIR="/opt/microchip/xc32/v2.05/bin" 32 | # MP_BC_DIR is not defined 33 | MP_AS_DIR="/opt/microchip/xc32/v2.05/bin" 34 | MP_LD_DIR="/opt/microchip/xc32/v2.05/bin" 35 | MP_AR_DIR="/opt/microchip/xc32/v2.05/bin" 36 | # MP_BC_DIR is not defined 37 | -------------------------------------------------------------------------------- /firmware/badge_alternative.X/nbproject/Makefile-local-default.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Generated Makefile - do not edit! 3 | # 4 | # 5 | # This file contains information about the location of compilers and other tools. 6 | # If you commmit this file into your revision control server, you will be able to 7 | # to checkout the project and build it from the command line with make. However, 8 | # if more than one person works on the same project, then this file might show 9 | # conflicts since different users are bound to have compilers in different places. 10 | # In that case you might choose to not commit this file and let MPLAB X recreate this file 11 | # for each user. The disadvantage of not commiting this file is that you must run MPLAB X at 12 | # least once so the file gets created and the project can be built. Finally, you can also 13 | # avoid using this file at all if you are only building from the command line with make. 14 | # You can invoke make with the values of the macros: 15 | # $ makeMP_CC="/opt/microchip/mplabc30/v3.30c/bin/pic30-gcc" ... 16 | # 17 | PATH_TO_IDE_BIN=/opt/microchip/mplabx/v4.15/mplab_ide/platform/../mplab_ide/modules/../../bin/ 18 | # Adding MPLAB X bin directory to path. 19 | PATH:=/opt/microchip/mplabx/v4.15/mplab_ide/platform/../mplab_ide/modules/../../bin/:$(PATH) 20 | # Path to java used to run MPLAB X when this makefile was created 21 | MP_JAVA_PATH="/opt/microchip/mplabx/v4.15/sys/java/jre1.8.0_144/bin/" 22 | OS_CURRENT="$(shell uname -s)" 23 | MP_CC="/opt/microchip/xc32/v2.05/bin/xc32-gcc" 24 | MP_CPPC="/opt/microchip/xc32/v2.05/bin/xc32-g++" 25 | # MP_BC is not defined 26 | MP_AS="/opt/microchip/xc32/v2.05/bin/xc32-as" 27 | MP_LD="/opt/microchip/xc32/v2.05/bin/xc32-ld" 28 | MP_AR="/opt/microchip/xc32/v2.05/bin/xc32-ar" 29 | DEP_GEN=${MP_JAVA_PATH}java -jar "/opt/microchip/mplabx/v4.15/mplab_ide/platform/../mplab_ide/modules/../../bin/extractobjectdependencies.jar" 30 | MP_CC_DIR="/opt/microchip/xc32/v2.05/bin" 31 | MP_CPPC_DIR="/opt/microchip/xc32/v2.05/bin" 32 | # MP_BC_DIR is not defined 33 | MP_AS_DIR="/opt/microchip/xc32/v2.05/bin" 34 | MP_LD_DIR="/opt/microchip/xc32/v2.05/bin" 35 | MP_AR_DIR="/opt/microchip/xc32/v2.05/bin" 36 | # MP_BC_DIR is not defined 37 | -------------------------------------------------------------------------------- /firmware/badge1.X/src/tetrapuzz.c: -------------------------------------------------------------------------------- 1 | #include "hw.h" 2 | #include "tetrapuzz.h" 3 | #include "box_game.h" 4 | #include 5 | 6 | //FIXME: these should probably not be globals 7 | uint32_t wait_until; 8 | uint8_t drop_timer_flag = 0; 9 | uint16_t state; 10 | 11 | int8_t sstr[3]; 12 | 13 | void tetrapuzz(void) 14 | { 15 | tetrapuzz_init(); 16 | 17 | while(1) 18 | { 19 | 20 | //This is just a rolling increment kind of fake random 21 | //because it gets called more often than the boxes are dropped 22 | BOX_inc_random(); 23 | 24 | //Service button inputs as necessary 25 | uint8_t get_stat = stdio_get(sstr); 26 | if (get_stat!=0) 27 | { 28 | if (sstr[0]==K_UP) { BOX_rotate(1); } 29 | if (sstr[0]==K_LT) { BOX_lt(); } 30 | if (sstr[0]==K_RT) { BOX_rt(); } 31 | if (sstr[0]==K_DN) { BOX_dn(); } 32 | } 33 | 34 | //Service the loop on a non-blocking delay here 35 | if (millis() > wait_until) 36 | { 37 | wait_until = millis()+BOX_get_delay(); 38 | tetrapuzz_loop(); 39 | } 40 | } 41 | } 42 | 43 | void tetrapuzz_init(void) 44 | { 45 | start_after_wake = &BOX_pregame; //Set function to run when waking from sleep] 46 | 47 | //Pull TMR1 value for a bit of not-really-but-kinda-random number 48 | int16_t timer1val = *(char*)0xBF800610; 49 | BOX_seed_random((unsigned char) timer1val&0xF); 50 | 51 | BOX_clearscreen(); 52 | drop_timer_flag = 0; 53 | wait_until = millis(); 54 | BOX_start_game(); 55 | } 56 | 57 | void tetrapuzz_loop(void) 58 | { 59 | BOX_dn(); 60 | 61 | if (BOX_end_game()) 62 | { 63 | //Print game ending information 64 | BOX_show_gameover(); 65 | //Loop until a button is pushed 66 | while (stdio_get(sstr) == 0) {;;} 67 | //Start game over 68 | tetrapuzz_init(); 69 | } 70 | } 71 | 72 | void tetrapuzz_pause(void) 73 | { 74 | //FIXME: we probably don't need a pause mode. 75 | /* deprecated camera badge code: 76 | if(butpress) 77 | { 78 | BOX_start_game(); 79 | state=s_run; 80 | return(0); 81 | } 82 | */ 83 | } 84 | 85 | void tetrapuzz_gameover(void) 86 | { 87 | //FIXME: we probably don't need this gameover mode. 88 | /* deprecated camera badge code: 89 | } 90 | if(butpress) { 91 | BOX_start_game(); 92 | state=s_run; 93 | } 94 | */ 95 | } -------------------------------------------------------------------------------- /firmware/badge1.X/nbproject/Makefile-impl.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Generated Makefile - do not edit! 3 | # 4 | # Edit the Makefile in the project folder instead (../Makefile). Each target 5 | # has a pre- and a post- target defined where you can add customization code. 6 | # 7 | # This makefile implements macros and targets common to all configurations. 8 | # 9 | # NOCDDL 10 | 11 | 12 | # Building and Cleaning subprojects are done by default, but can be controlled with the SUB 13 | # macro. If SUB=no, subprojects will not be built or cleaned. The following macro 14 | # statements set BUILD_SUB-CONF and CLEAN_SUB-CONF to .build-reqprojects-conf 15 | # and .clean-reqprojects-conf unless SUB has the value 'no' 16 | SUB_no=NO 17 | SUBPROJECTS=${SUB_${SUB}} 18 | BUILD_SUBPROJECTS_=.build-subprojects 19 | BUILD_SUBPROJECTS_NO= 20 | BUILD_SUBPROJECTS=${BUILD_SUBPROJECTS_${SUBPROJECTS}} 21 | CLEAN_SUBPROJECTS_=.clean-subprojects 22 | CLEAN_SUBPROJECTS_NO= 23 | CLEAN_SUBPROJECTS=${CLEAN_SUBPROJECTS_${SUBPROJECTS}} 24 | 25 | 26 | # Project Name 27 | PROJECTNAME=badge1.X 28 | 29 | # Active Configuration 30 | DEFAULTCONF=default 31 | CONF=${DEFAULTCONF} 32 | 33 | # All Configurations 34 | ALLCONFS=default 35 | 36 | 37 | # build 38 | .build-impl: .build-pre 39 | ${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .build-conf 40 | 41 | 42 | # clean 43 | .clean-impl: .clean-pre 44 | ${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .clean-conf 45 | 46 | # clobber 47 | .clobber-impl: .clobber-pre .depcheck-impl 48 | ${MAKE} SUBPROJECTS=${SUBPROJECTS} CONF=default clean 49 | 50 | 51 | 52 | # all 53 | .all-impl: .all-pre .depcheck-impl 54 | ${MAKE} SUBPROJECTS=${SUBPROJECTS} CONF=default build 55 | 56 | 57 | 58 | # dependency checking support 59 | .depcheck-impl: 60 | # @echo "# This code depends on make tool being used" >.dep.inc 61 | # @if [ -n "${MAKE_VERSION}" ]; then \ 62 | # echo "DEPFILES=\$$(wildcard \$$(addsuffix .d, \$${OBJECTFILES}))" >>.dep.inc; \ 63 | # echo "ifneq (\$${DEPFILES},)" >>.dep.inc; \ 64 | # echo "include \$${DEPFILES}" >>.dep.inc; \ 65 | # echo "endif" >>.dep.inc; \ 66 | # else \ 67 | # echo ".KEEP_STATE:" >>.dep.inc; \ 68 | # echo ".KEEP_STATE_FILE:.make.state.\$${CONF}" >>.dep.inc; \ 69 | # fi 70 | -------------------------------------------------------------------------------- /firmware/badge_alternative.X/nbproject/Makefile-impl.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Generated Makefile - do not edit! 3 | # 4 | # Edit the Makefile in the project folder instead (../Makefile). Each target 5 | # has a pre- and a post- target defined where you can add customization code. 6 | # 7 | # This makefile implements macros and targets common to all configurations. 8 | # 9 | # NOCDDL 10 | 11 | 12 | # Building and Cleaning subprojects are done by default, but can be controlled with the SUB 13 | # macro. If SUB=no, subprojects will not be built or cleaned. The following macro 14 | # statements set BUILD_SUB-CONF and CLEAN_SUB-CONF to .build-reqprojects-conf 15 | # and .clean-reqprojects-conf unless SUB has the value 'no' 16 | SUB_no=NO 17 | SUBPROJECTS=${SUB_${SUB}} 18 | BUILD_SUBPROJECTS_=.build-subprojects 19 | BUILD_SUBPROJECTS_NO= 20 | BUILD_SUBPROJECTS=${BUILD_SUBPROJECTS_${SUBPROJECTS}} 21 | CLEAN_SUBPROJECTS_=.clean-subprojects 22 | CLEAN_SUBPROJECTS_NO= 23 | CLEAN_SUBPROJECTS=${CLEAN_SUBPROJECTS_${SUBPROJECTS}} 24 | 25 | 26 | # Project Name 27 | PROJECTNAME=badge_alternative.X 28 | 29 | # Active Configuration 30 | DEFAULTCONF=default 31 | CONF=${DEFAULTCONF} 32 | 33 | # All Configurations 34 | ALLCONFS=default 35 | 36 | 37 | # build 38 | .build-impl: .build-pre 39 | ${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .build-conf 40 | 41 | 42 | # clean 43 | .clean-impl: .clean-pre 44 | ${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .clean-conf 45 | 46 | # clobber 47 | .clobber-impl: .clobber-pre .depcheck-impl 48 | ${MAKE} SUBPROJECTS=${SUBPROJECTS} CONF=default clean 49 | 50 | 51 | 52 | # all 53 | .all-impl: .all-pre .depcheck-impl 54 | ${MAKE} SUBPROJECTS=${SUBPROJECTS} CONF=default build 55 | 56 | 57 | 58 | # dependency checking support 59 | .depcheck-impl: 60 | # @echo "# This code depends on make tool being used" >.dep.inc 61 | # @if [ -n "${MAKE_VERSION}" ]; then \ 62 | # echo "DEPFILES=\$$(wildcard \$$(addsuffix .d, \$${OBJECTFILES}))" >>.dep.inc; \ 63 | # echo "ifneq (\$${DEPFILES},)" >>.dep.inc; \ 64 | # echo "include \$${DEPFILES}" >>.dep.inc; \ 65 | # echo "endif" >>.dep.inc; \ 66 | # else \ 67 | # echo ".KEEP_STATE:" >>.dep.inc; \ 68 | # echo ".KEEP_STATE_FILE:.make.state.\$${CONF}" >>.dep.inc; \ 69 | # fi 70 | -------------------------------------------------------------------------------- /firmware/auxiliary/scale_frequencies.py: -------------------------------------------------------------------------------- 1 | notes = ['C','C#/Db','D','D#/Eb','E','F','F#/Gb','G','G#/Ab','A','A#/Bb','B'] 2 | 3 | #table of frequncies from https://en.wikipedia.org/wiki/Scientific_pitch_notation 4 | raw = '''C 8.176 (0) 16.352 (12) 32.703 (24) 65.406 (36) 130.81 (48) 261.63 (60) 523.25 (72) 1046.5 (84) 2093.0 (96) 4186.0 (108) 8372.0 (120) 5 | C♯/D♭ 8.662 (1) 17.324 (13) 34.648 (25) 69.296 (37) 138.59 (49) 277.18 (61) 554.37 (73) 1108.7 (85) 2217.5 (97) 4434.9 (109) 8869.8 (121) 6 | D 9.177 (2) 18.354 (14) 36.708 (26) 73.416 (38) 146.83 (50) 293.66 (62) 587.33 (74) 1174.7 (86) 2349.3 (98) 4698.6 (110) 9397.3 (122) 7 | E♭/D♯ 9.723 (3) 19.445 (15) 38.891 (27) 77.782 (39) 155.56 (51) 311.13 (63) 622.25 (75) 1244.5 (87) 2489.0 (99) 4978.0 (111) 9956.1 (123) 8 | E 10.301 (4) 20.602 (16) 41.203 (28) 82.407 (40) 164.81 (52) 329.63 (64) 659.26 (76) 1318.5 (88) 2637.0 (100) 5274.0 (112) 10548.1 (124) 9 | F 10.914 (5) 21.827 (17) 43.654 (29) 87.307 (41) 174.61 (53) 349.23 (65) 698.46 (77) 1396.9 (89) 2793.8 (101) 5587.7 (113) 11175.3 (125) 10 | F♯/G♭ 11.563 (6) 23.125 (18) 46.249 (30) 92.499 (42) 185.00 (54) 369.99 (66) 739.99 (78) 1480.0 (90) 2960.0 (102) 5919.9 (114) 11839.8 (126) 11 | G 12.250 (7) 24.500 (19) 48.999 (31) 97.999 (43) 196.00 (55) 392.00 (67) 783.99 (79) 1568.0 (91) 3136.0 (103) 6271.9 (115) 12543.9 (127) 12 | A♭/G♯ 12.979 (8) 25.957 (20) 51.913 (32) 103.83 (44) 207.65 (56) 415.30 (68) 830.61 (80) 1661.2 (92) 3322.4 (104) 6644.9 (116) 13 | A 13.750 (9) 27.500 (21) 55.000 (33) 110.00 (45) 220.00 (57) 440.00 (69) 880.00 (81) 1760.0 (93) 3520.0 (105) 7040.0 (117) 14 | B♭/A♯ 14.568 (10) 29.135 (22) 58.270 (34) 116.54 (46) 233.08 (58) 466.16 (70) 932.33 (82) 1864.7 (94) 3729.3 (106) 7458.6 (118) 15 | B 15.434 (11) 30.868 (23) 61.735 (35) 123.47 (47) 246.94 (59) 493.88 (71) 987.77 (83) 1975.5 (95) 3951.1 (107) 7902.1 (119)''' 16 | 17 | x = raw.replace('\n','\t').split('\t') 18 | 19 | arraydata = dict() 20 | i = 0 21 | curNote = 'x' 22 | while i < len(x): 23 | #print x[i] 24 | if x[i][0].isupper(): 25 | curNote = x[i] 26 | i += 1 27 | continue 28 | frequency = float(x[i].split(' ')[0]) 29 | note_num = int(x[i].split(' ')[1].replace('(','').replace(')','')) 30 | timerval = int(3000000/frequency) 31 | #print frequency,note_num,timerval,curNote 32 | arraydata[note_num] = '\t' + str(timerval) + ', // '+ str(note_num) + ' | ' + curNote+ str(int(note_num/12)-1) + ' | ' + str(frequency) + 'Hz' 33 | i += 1 34 | 35 | for i in sorted(arraydata.keys()): 36 | print arraydata[i] 37 | -------------------------------------------------------------------------------- /firmware/badge1.X/src/user_program.c: -------------------------------------------------------------------------------- 1 | /************************************ 2 | * This is the framework for those 3 | * who wish to write their own C 4 | * code for the basic badge 5 | ************************************/ 6 | 7 | 8 | #include "badge_user.h" 9 | 10 | void user_program_init(void) 11 | { 12 | /* This will run when User Program is first selected form the menu */ 13 | clr_buffer(); 14 | video_gotoxy(5,4); 15 | stdio_write("Use this example to write"); 16 | video_gotoxy(5,5); 17 | stdio_write("your own C code for the badge."); 18 | } 19 | 20 | void user_program_loop(void) 21 | { 22 | /* This should contain user program (will be run after init function)*/ 23 | 24 | /* Write some stuff to the screen*/ 25 | video_set_color(3,8); //Set color before writing 26 | video_gotoxy(5,7); //Move cursor 27 | stdio_write(" Behold, color! And ASCII: \xCC\xCD\xCD\xB9 "); // stdio_write will affect both color and character in a location 28 | video_set_color(15,0); 29 | video_gotoxy(5,10); 30 | stdio_write("Counting seconds:"); 31 | video_gotoxy(5,14); 32 | stdio_write("Waiting for you to press any key..."); 33 | 34 | while(1) //Loop forever 35 | { 36 | /* Example of a non-blocking delay */ 37 | static uint32_t delay_until = 0; 38 | static uint8_t count = '0'; 39 | if (millis()>=delay_until) 40 | { 41 | /* Writing directly to disp_buffer instead of stdio_write */ 42 | /* Note that Y value is given before X: disp_buffer[Y][X]*/ 43 | disp_buffer[10][24] = count++; 44 | if (count > '9') 45 | { 46 | count = '0'; 47 | } 48 | delay_until = millis()+1000; 49 | } 50 | 51 | /* React to user input */ 52 | uint8_t get_stat, char_out; 53 | get_stat = stdio_get(&char_out); 54 | if (get_stat!=0) 55 | { 56 | /* Show which letter was pressed just as an example: */ 57 | /* Directly address color_buffer: first nibble is BG, second nibble is FG*/ 58 | color_buffer[16][8] = 0x1E; 59 | if (char_out > 31) // Make sure it was a printable character 60 | { 61 | disp_buffer[16][8] = char_out; 62 | } 63 | else disp_buffer[16][8] = 0xEC; 64 | 65 | video_gotoxy(5,19); 66 | stdio_write("2s until manual screen writing demo"); 67 | wait_ms(2000); //Make sure user sees entered character 68 | 69 | /* Now do something interesting */ 70 | enable_display_scanning(0); //Shut off auto-scanning of character buffer 71 | uint16_t x = 0; 72 | uint8_t y = 0; 73 | uint32_t colorshift = 0; 74 | while(1) //Loop forever 75 | { 76 | /* Draw a 1x1 box at x,y -- color is using XOR trick but should be format 0x00RRGGBB */ 77 | tft_fill_area (x, y, 1, 1, (x^(uint32_t)y)+colorshift); 78 | ++x; //Increment x 79 | 80 | /* Reset x/y as necessary */ 81 | if (x >= 320) 82 | { 83 | x = 0; 84 | ++y; 85 | } 86 | if (y >= 240) 87 | { 88 | y = 0; 89 | colorshift += 0x00123456; 90 | } 91 | 92 | /* Waste some time but less than 1 ms */ 93 | uint16_t quickdelay = 2000; 94 | while (quickdelay) 95 | { 96 | --quickdelay; 97 | } 98 | } 99 | //Badge will need to be reset to continue 100 | } 101 | } 102 | } 103 | 104 | -------------------------------------------------------------------------------- /firmware/badge1.X/src/tune_player.h: -------------------------------------------------------------------------------- 1 | #ifndef __TUNE_PLAYER_H 2 | #define __TUNE_PLAYER_H 3 | 4 | void play_mario_tune(void); 5 | void play_music_array(const unsigned char *, unsigned char, const unsigned int *); 6 | 7 | const unsigned char mario_array_limits[9] = { 48, 52, 52, 56, 52, 56, 64, 64, 64 }; 8 | const unsigned int mario_tempos[4] = {149, 198, 298, 447 }; 9 | 10 | const unsigned char mario_main0[48] = 11 | { 12 | 50,66,76,0, 13 | 50,66,76,0, 14 | 0,0,0,0, 15 | 50,66,76,0, 16 | 0,0,0,0, 17 | 50,66,72,0, 18 | 50,66,76,0, 19 | 0,0,0,0, 20 | 67,71,79,0, 21 | 0,0,0,3, 22 | 0,55,67,0, 23 | 0,0,0,3 24 | }; 25 | 26 | const unsigned char mario_main1[52] = 27 | { 28 | 48,0,0,0, 29 | 0,0,0,0, 30 | 56,68,75,0, 31 | 0,0,0,2, 32 | 58,65,74,0, 33 | 0,0,0,2, 34 | 60,64,72,0, 35 | 0,0,0,2, 36 | 55,0,0,0, 37 | 55,0,0,0, 38 | 0,0,0,0, 39 | 48,0,0,0, 40 | 0,0,0,0 41 | }; 42 | 43 | const unsigned char mario_main2[52] = 44 | { 45 | 48,0,0,0, 46 | 0,0,0,0, 47 | 56,68,75,0, 48 | 0,0,0,2, 49 | 56,65,74,0, 50 | 0,0,0,2, 51 | 60,64,72,0, 52 | 0,0,0,2, 53 | 55,0,0,0, 54 | 55,0,0,0, 55 | 0,0,0,0, 56 | 48,0,0,0, 57 | 0,0,0,0 58 | }; 59 | 60 | 61 | 62 | const unsigned char mario_main3[56] = 63 | { 64 | 44,68,72,0, 65 | 0,68,72,0, 66 | 0,0,0,0, 67 | 51,68,72,0, 68 | 0,0,0,0, 69 | 0,68,72,0, 70 | 56,70,74,0, 71 | 0,67,76,0, 72 | 55,0,0,0, 73 | 0,0,0,2, 74 | 48,0,0,0, 75 | 0,0,0,2, 76 | 43,0,0,0, 77 | 0,0,0,0 78 | }; 79 | 80 | const unsigned char mario_clip0[52] = 81 | { 82 | 55,64,72,0, 83 | 0,0,0,2, 84 | 52,60,67,0, 85 | 0,0,0,2, 86 | 48,55,64,0, 87 | 0,0,0,2, 88 | 53,60,69,0, 89 | 0,0,0,0, 90 | 55,62,71,0, 91 | 0,0,0,0, 92 | 54,61,70,0, 93 | 53,60,69,0, 94 | 0,0,0,0 95 | }; 96 | 97 | const unsigned char mario_clip1[56] = 98 | { 99 | 52,60,67,1, 100 | 60,67,76,1, 101 | 64,71,79,1, 102 | 65,72,81,0, 103 | 0,0,0,0, 104 | 62,69,77,0, 105 | 64,71,79,0, 106 | 0,0,0,0, 107 | 60,69,76,0, 108 | 0,0,0,0, 109 | 57,64,72,0, 110 | 59,65,74,0, 111 | 55,62,71,0, 112 | 0,0,0,2 113 | }; 114 | 115 | const unsigned char mario_clip2[64] = 116 | { 117 | 48,0,0,0, 118 | 0,0,0,0, 119 | 0,76,79,0, 120 | 55,75,78,0, 121 | 0,74,77,0, 122 | 0,71,75,0, 123 | 60,0,0,0, 124 | 0,72,76,0, 125 | 53,0,0,0, 126 | 0,64,68,0, 127 | 0,65,69,0, 128 | 60,67,72,0, 129 | 60,0,0,0, 130 | 0,60,69,0, 131 | 53,64,72,0, 132 | 0,65,74,0 133 | }; 134 | 135 | const unsigned char mario_clip3[64] = 136 | { 137 | 48,0,0,0, 138 | 0,0,0,0, 139 | 0,76,79,0, 140 | 52,75,78,0, 141 | 0,74,77,0, 142 | 0,71,75,0, 143 | 55,0,0,0, 144 | 60,72,76,0, 145 | 0,0,0,0, 146 | 77,79,84,0, 147 | 0,0,0,0, 148 | 77,79,84,0, 149 | 77,79,84,0, 150 | 0,0,0,0, 151 | 55,0,0,0, 152 | 0,0,0,0 153 | }; 154 | 155 | const unsigned char mario_clip4[64] = 156 | { 157 | 44,68,72,0, 158 | 0,68,72,0, 159 | 0,0,0,0, 160 | 51,68,72,0, 161 | 0,0,0,0, 162 | 0,68,72,0, 163 | 56,70,74,0, 164 | 0,0,0,0, 165 | 55,67,76,0, 166 | 0,64,72,0, 167 | 0,0,0,0, 168 | 48,64,69,0, 169 | 0,60,67,0, 170 | 0,0,0,0, 171 | 43,0,0,0, 172 | 0,0,0,0 173 | }; 174 | 175 | #endif 176 | 177 | -------------------------------------------------------------------------------- /firmware/badge1.X/src/basic/tokenizer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006, Adam Dunkels 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. Neither the name of the author nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | */ 30 | #ifndef __TOKENIZER_H__ 31 | #define __TOKENIZER_H__ 32 | 33 | 34 | 35 | 36 | 37 | 38 | //B_BAS003 39 | enum { 40 | TOKENIZER_ERROR, 41 | TOKENIZER_ENDOFINPUT, 42 | TOKENIZER_NUMBER, 43 | TOKENIZER_STRING, 44 | TOKENIZER_VARIABLE, 45 | TOKENIZER_LET, 46 | TOKENIZER_PRINT, 47 | TOKENIZER_IF, 48 | TOKENIZER_THEN, 49 | TOKENIZER_ELSE, 50 | TOKENIZER_FOR, 51 | TOKENIZER_TO, 52 | TOKENIZER_NEXT, 53 | TOKENIZER_GOTO, 54 | TOKENIZER_GOSUB, 55 | TOKENIZER_RETURN, 56 | TOKENIZER_CALL, 57 | TOKENIZER_END, 58 | TOKENIZER_COMMA, 59 | TOKENIZER_SEMICOLON, 60 | TOKENIZER_PLUS, 61 | TOKENIZER_MINUS, 62 | TOKENIZER_AND, 63 | TOKENIZER_OR, 64 | TOKENIZER_ASTR, 65 | TOKENIZER_SLASH, 66 | TOKENIZER_MOD, 67 | TOKENIZER_LEFTPAREN, 68 | TOKENIZER_RIGHTPAREN, 69 | TOKENIZER_LT, 70 | TOKENIZER_GT, 71 | TOKENIZER_EQ, 72 | TOKENIZER_CR, 73 | TOKENIZER_OUT, 74 | TOKENIZER_TUNE, 75 | TOKENIZER_TERMT, 76 | TOKENIZER_SETXY, 77 | TOKENIZER_CLRSCR, 78 | TOKENIZER_WAIT, 79 | TOKENIZER_LED, 80 | TOKENIZER_COLOR, 81 | TOKENIZER_RND, 82 | TOKENIZER_CHR, 83 | TOKENIZER_EIN, 84 | TOKENIZER_EOUT, 85 | TOKENIZER_EDR, 86 | TOKENIZER_PRINTLN, 87 | TOKENIZER_TERMUP, 88 | TOKENIZER_REM, 89 | TOKENIZER_UIN, 90 | TOKENIZER_UOUT, 91 | TOKENIZER_INPUT, 92 | TOKENIZER_PEEK, 93 | TOKENIZER_POKE, 94 | TOKENIZER_CURSOR, 95 | TOKENIZER_KIN, 96 | }; 97 | 98 | void tokenizer_init(const char *program); 99 | void tokenizer_next(void); 100 | int tokenizer_token(void); 101 | int tokenizer_num(void); 102 | int tokenizer_variable_num(void); 103 | void tokenizer_string(char *dest, int len); 104 | 105 | int tokenizer_finished(void); 106 | void tokenizer_error_print(void); 107 | 108 | #endif /* __TOKENIZER_H__ */ 109 | -------------------------------------------------------------------------------- /firmware/badge1.X/src/Z80/sim.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Z80SIM - a Z80-CPU simulator 3 | * 4 | * Copyright (C) 1987-92 by Udo Munk 5 | * 6 | * This is the configuration I'm using for software testing and debugging 7 | * 8 | * History: 9 | * 28-SEP-87 Development on TARGON/35 with AT&T Unix System V.3 10 | * 11-JAN-89 Release 1.1 11 | * 08-FEB-89 Release 1.2 12 | * 13-MAR-89 Release 1.3 13 | * 09-FEB-90 Release 1.4 Ported to TARGON/31 M10/30 14 | * 20-DEC-90 Release 1.5 Ported to COHERENT 3.0 15 | * 10-JUN-92 Release 1.6 long casting problem solved with COHERENT 3.2 16 | * and some optimization 17 | * 25-JUN-92 Release 1.7 comments in english 18 | */ 19 | 20 | /* 21 | * The following defines may be activated, commented or modified 22 | * by user for her/his own purpose. 23 | */ 24 | 25 | #include 26 | 27 | /*#define WANT_INT*/ /* activate CPU's interrupts */ 28 | #define WANT_SPC /* activate SP over-/underrun handling 0000<->FFFF */ 29 | #define WANT_PCC /* activate PC overrun handling FFFF->0000 */ 30 | //#define CNTL_C /* cntl-c will stop running emulation */ 31 | //#define CNTL_BS /* cntl-\ will stop running emulation */ 32 | //#define WANT_TIM /* activate runtime measurement */ 33 | //#define HISIZE 100 /* number of entrys in history */ 34 | //#define SBSIZE 4 /* number of software breakpoints */ 35 | 36 | 37 | /* 38 | * The following defines may be modified and activated by 39 | * user, to print her/his copyright for a developed system, 40 | * which contains the Z80-CPU simulation as a part. 41 | */ 42 | /* 43 | #define USR_COM "XYZ-System Simulation" 44 | #define USR_REL "x.y" 45 | #define USR_CPR "Copyright (C) 19xx by XYZ" 46 | */ 47 | 48 | /* 49 | * The following lines of this file must not be modified by user, 50 | * see license agreement! 51 | */ 52 | #define COPYR "Copyright (C) 1987-92 by Udo Munk" 53 | #define RELEASE "1.7" 54 | 55 | #define LENCMD 80 /* length of command buffers etc */ 56 | 57 | #define S_FLAG 128 /* bit definitions of CPU flags */ 58 | #define Z_FLAG 64 59 | #define N2_FLAG 32 60 | #define H_FLAG 16 61 | #define N1_FLAG 8 62 | #define P_FLAG 4 63 | #define N_FLAG 2 64 | #define C_FLAG 1 65 | 66 | /* operation of simulated CPU */ 67 | #define SINGLE_STEP 0 /* single step */ 68 | #define CONTIN_RUN 1 /* continual run */ 69 | #define STOPPED 0 /* stop CPU because of error */ 70 | 71 | /* causes of error */ 72 | #define NONE 0 /* no error */ 73 | #define OPHALT 1 /* HALT op-code trap */ 74 | #define IOTRAP 2 /* IN/OUT trap */ 75 | #define OPTRAP1 3 /* illegal 1 byte op-code trap */ 76 | #define OPTRAP2 4 /* illegal 2 byte op-code trap */ 77 | #define OPTRAP4 5 /* illegal 4 byte op-code trap */ 78 | #define USERINT 6 /* user interrupt */ 79 | 80 | /* type of CPU interrupt */ 81 | #define INT_NMI 1 /* non maskable interrupt */ 82 | #define INT_INT 2 /* maskable interrupt */ 83 | 84 | //typedef unsigned short WORD; /* 16 bit unsigned */ 85 | //typedef unsigned char BYTE; /* 8 bit unsigned */ 86 | 87 | #ifdef HISIZE 88 | struct history { /* structure of a history entry */ 89 | WORD h_adr; /* address of execution */ 90 | WORD h_af; /* register AF */ 91 | WORD h_bc; /* register BC */ 92 | WORD h_de; /* register DE */ 93 | WORD h_hl; /* register HL */ 94 | WORD h_ix; /* register IX */ 95 | WORD h_iy; /* register IY */ 96 | WORD h_sp; /* register SP */ 97 | }; 98 | #endif 99 | 100 | #ifdef SBSIZE 101 | struct softbreak { /* structure of a breakpoint */ 102 | WORD sb_adr; /* address of breakpoint */ 103 | BYTE sb_oldopc; /* op-code at address of breakpoint */ 104 | int sb_passcount; /* pass counter of breakpoint */ 105 | int sb_pass; /* no. of pass to break */ 106 | }; 107 | #endif 108 | -------------------------------------------------------------------------------- /firmware/badge1.X/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # There exist several targets which are by default empty and which can be 3 | # used for execution of your targets. These targets are usually executed 4 | # before and after some main targets. They are: 5 | # 6 | # .build-pre: called before 'build' target 7 | # .build-post: called after 'build' target 8 | # .clean-pre: called before 'clean' target 9 | # .clean-post: called after 'clean' target 10 | # .clobber-pre: called before 'clobber' target 11 | # .clobber-post: called after 'clobber' target 12 | # .all-pre: called before 'all' target 13 | # .all-post: called after 'all' target 14 | # .help-pre: called before 'help' target 15 | # .help-post: called after 'help' target 16 | # 17 | # Targets beginning with '.' are not intended to be called on their own. 18 | # 19 | # Main targets can be executed directly, and they are: 20 | # 21 | # build build a specific configuration 22 | # clean remove built files from a configuration 23 | # clobber remove all built files 24 | # all build all configurations 25 | # help print help mesage 26 | # 27 | # Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and 28 | # .help-impl are implemented in nbproject/makefile-impl.mk. 29 | # 30 | # Available make variables: 31 | # 32 | # CND_BASEDIR base directory for relative paths 33 | # CND_DISTDIR default top distribution directory (build artifacts) 34 | # CND_BUILDDIR default top build directory (object files, ...) 35 | # CONF name of current configuration 36 | # CND_ARTIFACT_DIR_${CONF} directory of build artifact (current configuration) 37 | # CND_ARTIFACT_NAME_${CONF} name of build artifact (current configuration) 38 | # CND_ARTIFACT_PATH_${CONF} path to build artifact (current configuration) 39 | # CND_PACKAGE_DIR_${CONF} directory of package (current configuration) 40 | # CND_PACKAGE_NAME_${CONF} name of package (current configuration) 41 | # CND_PACKAGE_PATH_${CONF} path to package (current configuration) 42 | # 43 | # NOCDDL 44 | 45 | 46 | # Environment 47 | MKDIR=mkdir 48 | CP=cp 49 | CCADMIN=CCadmin 50 | RANLIB=ranlib 51 | 52 | 53 | # build 54 | build: .build-post 55 | 56 | .build-pre: 57 | # Add your pre 'build' code here... 58 | 59 | .build-post: .build-impl 60 | # Add your post 'build' code here... 61 | 62 | 63 | # clean 64 | clean: .clean-post 65 | 66 | .clean-pre: 67 | # Add your pre 'clean' code here... 68 | # WARNING: the IDE does not call this target since it takes a long time to 69 | # simply run make. Instead, the IDE removes the configuration directories 70 | # under build and dist directly without calling make. 71 | # This target is left here so people can do a clean when running a clean 72 | # outside the IDE. 73 | 74 | .clean-post: .clean-impl 75 | # Add your post 'clean' code here... 76 | 77 | 78 | # clobber 79 | clobber: .clobber-post 80 | 81 | .clobber-pre: 82 | # Add your pre 'clobber' code here... 83 | 84 | .clobber-post: .clobber-impl 85 | # Add your post 'clobber' code here... 86 | 87 | 88 | # all 89 | all: .all-post 90 | 91 | .all-pre: 92 | # Add your pre 'all' code here... 93 | 94 | .all-post: .all-impl 95 | # Add your post 'all' code here... 96 | 97 | 98 | # help 99 | help: .help-post 100 | 101 | .help-pre: 102 | # Add your pre 'help' code here... 103 | 104 | .help-post: .help-impl 105 | # Add your post 'help' code here... 106 | 107 | 108 | 109 | # include project implementation makefile 110 | include nbproject/Makefile-impl.mk 111 | 112 | # include project make variables 113 | include nbproject/Makefile-variables.mk 114 | -------------------------------------------------------------------------------- /firmware/badge_alternative.X/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # There exist several targets which are by default empty and which can be 3 | # used for execution of your targets. These targets are usually executed 4 | # before and after some main targets. They are: 5 | # 6 | # .build-pre: called before 'build' target 7 | # .build-post: called after 'build' target 8 | # .clean-pre: called before 'clean' target 9 | # .clean-post: called after 'clean' target 10 | # .clobber-pre: called before 'clobber' target 11 | # .clobber-post: called after 'clobber' target 12 | # .all-pre: called before 'all' target 13 | # .all-post: called after 'all' target 14 | # .help-pre: called before 'help' target 15 | # .help-post: called after 'help' target 16 | # 17 | # Targets beginning with '.' are not intended to be called on their own. 18 | # 19 | # Main targets can be executed directly, and they are: 20 | # 21 | # build build a specific configuration 22 | # clean remove built files from a configuration 23 | # clobber remove all built files 24 | # all build all configurations 25 | # help print help mesage 26 | # 27 | # Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and 28 | # .help-impl are implemented in nbproject/makefile-impl.mk. 29 | # 30 | # Available make variables: 31 | # 32 | # CND_BASEDIR base directory for relative paths 33 | # CND_DISTDIR default top distribution directory (build artifacts) 34 | # CND_BUILDDIR default top build directory (object files, ...) 35 | # CONF name of current configuration 36 | # CND_ARTIFACT_DIR_${CONF} directory of build artifact (current configuration) 37 | # CND_ARTIFACT_NAME_${CONF} name of build artifact (current configuration) 38 | # CND_ARTIFACT_PATH_${CONF} path to build artifact (current configuration) 39 | # CND_PACKAGE_DIR_${CONF} directory of package (current configuration) 40 | # CND_PACKAGE_NAME_${CONF} name of package (current configuration) 41 | # CND_PACKAGE_PATH_${CONF} path to package (current configuration) 42 | # 43 | # NOCDDL 44 | 45 | 46 | # Environment 47 | MKDIR=mkdir 48 | CP=cp 49 | CCADMIN=CCadmin 50 | RANLIB=ranlib 51 | 52 | 53 | # build 54 | build: .build-post 55 | 56 | .build-pre: 57 | # Add your pre 'build' code here... 58 | 59 | .build-post: .build-impl 60 | # Add your post 'build' code here... 61 | 62 | 63 | # clean 64 | clean: .clean-post 65 | 66 | .clean-pre: 67 | # Add your pre 'clean' code here... 68 | # WARNING: the IDE does not call this target since it takes a long time to 69 | # simply run make. Instead, the IDE removes the configuration directories 70 | # under build and dist directly without calling make. 71 | # This target is left here so people can do a clean when running a clean 72 | # outside the IDE. 73 | 74 | .clean-post: .clean-impl 75 | # Add your post 'clean' code here... 76 | 77 | 78 | # clobber 79 | clobber: .clobber-post 80 | 81 | .clobber-pre: 82 | # Add your pre 'clobber' code here... 83 | 84 | .clobber-post: .clobber-impl 85 | # Add your post 'clobber' code here... 86 | 87 | 88 | # all 89 | all: .all-post 90 | 91 | .all-pre: 92 | # Add your pre 'all' code here... 93 | 94 | .all-post: .all-impl 95 | # Add your post 'all' code here... 96 | 97 | 98 | # help 99 | help: .help-post 100 | 101 | .help-pre: 102 | # Add your pre 'help' code here... 103 | 104 | .help-post: .help-impl 105 | # Add your post 'help' code here... 106 | 107 | 108 | 109 | # include project implementation makefile 110 | include nbproject/Makefile-impl.mk 111 | 112 | # include project make variables 113 | include nbproject/Makefile-variables.mk 114 | -------------------------------------------------------------------------------- /firmware/auxiliary/mario.txt: -------------------------------------------------------------------------------- 1 | char bprog[4097] = 2 | "10 tune 50,66,76,149\n\ 3 | 20 tune 50,66,76,149\n\ 4 | 30 tune 0,0,0,149\n\ 5 | 40 tune 50,66,76,149\n\ 6 | 50 tune 0,0,0,149\n\ 7 | 60 tune 50,66,72,149\n\ 8 | 70 tune 50,66,76,149\n\ 9 | 80 tune 0,0,0,149\n\ 10 | 90 tune 67,71,79,149\n\ 11 | 100 tune 0,0,0,447\n\ 12 | 110 tune 0,55,67,149\n\ 13 | 120 tune 0,0,0,447\n\ 14 | 130 gosub 670\n\ 15 | 140 gosub 810\n\ 16 | 150 gosub 670\n\ 17 | 160 gosub 810\n\ 18 | 170 gosub 960\n\ 19 | 180 gosub 1130\n\ 20 | 190 gosub 960\n\ 21 | 200 tune 48,0,0,149\n\ 22 | 210 tune 0,0,0,149\n\ 23 | 221 tune 56,68,75,149\n\ 24 | 230 tune 0,0,0,298\n\ 25 | 240 tune 58,65,74,149\n\ 26 | 250 tune 0,0,0,298\n\ 27 | 260 tune 60,64,72,149\n\ 28 | 270 tune 0,0,0,298\n\ 29 | 280 tune 55,0,0,149\n\ 30 | 290 tune 55,0,0,149\n\ 31 | 300 tune 0,0,0,149\n\ 32 | 310 tune 48,0,0,149\n\ 33 | 320 tune 0,0,0,149\n\ 34 | 330 gosub 960\n\ 35 | 340 gosub 1130\n\ 36 | 350 gosub 960\n\ 37 | 360 tune 48,0,0,149\n\ 38 | 370 tune 0,0,0,149\n\ 39 | 380 tune 56,68,75,149\n\ 40 | 390 tune 0,0,0,298\n\ 41 | 400 tune 56,65,74,149\n\ 42 | 410 tune 0,0,0,298\n\ 43 | 420 tune 60,64,72,149\n\ 44 | 430 tune 0,0,0,298\n\ 45 | 440 tune 55,0,0,149\n\ 46 | 450 tune 55,0,0,149\n\ 47 | 460 tune 0,0,0,149\n\ 48 | 470 tune 48,0,0,149\n\ 49 | 480 tune 0,0,0,149\n\ 50 | 490 gosub 1300\n\ 51 | 500 tune 44,68,72,149\n\ 52 | 510 tune 0,68,72,149\n\ 53 | 520 tune 0,0,0,149\n\ 54 | 530 tune 51,68,72,149\n\ 55 | 540 tune 0,0,0,149\n\ 56 | 550 tune 0,68,72,149\n\ 57 | 560 tune 56,70,74,149\n\ 58 | 570 tune 0,67,76,149\n\ 59 | 580 tune 55,0,0,149\n\ 60 | 590 tune 0,0,0,298\n\ 61 | 600 tune 48,0,0,149\n\ 62 | 610 tune 0,0,0,298\n\ 63 | 620 tune 43,0,0,149\n\ 64 | 630 tune 0,0,0,149\n\ 65 | 640 gosub 1300\n\ 66 | 650 goto 10\n\ 67 | 670 tune 55,64,72,149\n\ 68 | 680 tune 0,0,0,298\n\ 69 | 690 tune 52,60,67,149\n\ 70 | 700 tune 0,0,0,298\n\ 71 | 710 tune 48,55,64,149\n\ 72 | 720 tune 0,0,0,298\n\ 73 | 730 tune 53,60,69,149\n\ 74 | 740 tune 0,0,0,149\n\ 75 | 750 tune 55,62,71,149\n\ 76 | 760 tune 0,0,0,149\n\ 77 | 770 tune 54,61,70,149\n\ 78 | 780 tune 53,60,69,149\n\ 79 | 790 tune 0,0,0,149\n\ 80 | 800 return\n\ 81 | 810 tune 52,60,67,198\n\ 82 | 820 tune 60,67,76,198\n\ 83 | 830 tune 64,71,79,198\n\ 84 | 840 tune 65,72,81,149\n\ 85 | 850 tune 0,0,0,149\n\ 86 | 860 tune 62,69,77,149\n\ 87 | 870 tune 64,71,79,149\n\ 88 | 880 tune 0,0,0,149\n\ 89 | 890 tune 60,69,76,149\n\ 90 | 900 tune 0,0,0,149\n\ 91 | 910 tune 57,64,72,149\n\ 92 | 920 tune 59,65,74,149\n\ 93 | 930 tune 55,62,71,149\n\ 94 | 940 tune 0,0,0,298\n\ 95 | 950 return\n\ 96 | 960 tune 48,0,0,149\n\ 97 | 970 tune 0,0,0,149\n\ 98 | 980 tune 0,76,79,149\n\ 99 | 990 tune 55,75,78,149\n\ 100 | 1000 tune 0,74,77,149\n\ 101 | 1010 tune 0,71,75,149\n\ 102 | 1020 tune 60,0,0,149\n\ 103 | 1030 tune 0,72,76,149\n\ 104 | 1040 tune 53,0,0,149\n\ 105 | 1050 tune 0,64,68,149\n\ 106 | 1060 tune 0,65,69,149\n\ 107 | 1070 tune 60,67,72,149\n\ 108 | 1080 tune 60,0,0,149\n\ 109 | 1090 tune 0,60,69,149\n\ 110 | 1100 tune 53,64,72,149\n\ 111 | 1110 tune 0,65,74,149\n\ 112 | 1120 return\n\ 113 | 1130 tune 48,0,0,149\n\ 114 | 1140 tune 0,0,0,149\n\ 115 | 1150 tune 0,76,79,149\n\ 116 | 1160 tune 52,75,78,149\n\ 117 | 1170 tune 0,74,77,149\n\ 118 | 1180 tune 0,71,75,149\n\ 119 | 1190 tune 55,0,0,149\n\ 120 | 1200 tune 60,72,76,149\n\ 121 | 1210 tune 0,0,0,149\n\ 122 | 1220 tune 77,79,84,149\n\ 123 | 1230 tune 0,0,0,149\n\ 124 | 1240 tune 77,79,84,149\n\ 125 | 1250 tune 77,79,84,149\n\ 126 | 1260 tune 0,0,0,149\n\ 127 | 1270 tune 55,0,0,149\n\ 128 | 1280 tune 0,0,0,149\n\ 129 | 1290 return\n\ 130 | 1300 tune 44,68,72,149\n\ 131 | 1310 tune 0,68,72,149\n\ 132 | 1320 tune 0,0,0,149\n\ 133 | 1330 tune 51,68,72,149\n\ 134 | 1340 tune 0,0,0,149\n\ 135 | 1350 tune 0,68,72,149\n\ 136 | 1360 tune 56,70,74,149\n\ 137 | 1370 tune 0,0,0,149\n\ 138 | 1380 tune 55,67,76,149\n\ 139 | 1390 tune 0,64,72,149\n\ 140 | 1400 tune 0,0,0,149\n\ 141 | 1410 tune 48,64,69,149\n\ 142 | 1420 tune 0,60,67,149\n\ 143 | 1430 tune 0,0,0,149\n\ 144 | 1440 tune 43,0,0,149\n\ 145 | 1450 tune 0,0,0,149\n\ 146 | 1460 return\n"; 147 | -------------------------------------------------------------------------------- /firmware/badge_alternative.X/src/hw.h: -------------------------------------------------------------------------------- 1 | #ifndef __HW_H 2 | #define __HW_H 3 | 4 | //#include 5 | #include 6 | 7 | #define DISP_BUFFER_WIDE 40 8 | #define DISP_BUFFER_HIGH 20 9 | 10 | #define LCD_PORT LATE 11 | #define LCD_WR LATDbits.LATD4 12 | #define LCD_RES LATGbits.LATG7 13 | #define LCD_RD LATDbits.LATD5 14 | #define LCD_DC LATGbits.LATG8 15 | 16 | #define LCD_WR_SET PORTDSET = (1<<4) 17 | #define LCD_WR_CLR PORTDCLR = (1<<4) 18 | #define LCD_DC_SET PORTGSET = (1<<8) 19 | #define LCD_DC_CLR PORTGCLR = (1<<8) 20 | 21 | #define LCD_BKLT LATFbits.LATF0 22 | #define LCD_PWR LATCbits.LATC15 23 | 24 | #define K_R5 LATFbits.LATF4 25 | #define K_R4 LATBbits.LATB15 26 | #define K_R3 LATBbits.LATB14 27 | #define K_R2 LATBbits.LATB13 28 | #define K_R1 LATBbits.LATB12 29 | 30 | #define K_C1 PORTBbits.RB11 31 | #define K_C2 PORTBbits.RB10 32 | #define K_C3 PORTBbits.RB9 33 | #define K_C4 PORTBbits.RB8 34 | #define K_C5 PORTBbits.RB7 35 | #define K_C6 PORTBbits.RB6 36 | #define K_C7 PORTBbits.RB5 37 | #define K_C8 PORTBbits.RB4 38 | #define K_C9 PORTBbits.RB3 39 | #define K_C10 PORTBbits.RB2 40 | #define K_SHIFTR PORTDbits.RD9 41 | #define K_SHIFTL PORTDbits.RD10 42 | #define K_PWR PORTGbits.RG6 43 | #define KEY_BRK PORTGbits.RG9 44 | 45 | #define SYS_CLK 48000000UL 46 | #define PB_CLK 48000000UL 47 | 48 | #define LEDR LATDbits.LATD6 49 | #define LEDG LATFbits.LATF1 50 | #define LEDB LATDbits.LATD7 51 | 52 | 53 | #define CS_FLASH LATFbits.LATF2 54 | #define FLASH_WP LATDbits.LATD8 55 | #define FLASH_HOLD LATCbits.LATC12 56 | 57 | #define CS_MEM FLASH_WP 58 | 59 | 60 | #define GEN_0_PIN LATDbits.LATD1 61 | #define GEN_1_PIN LATDbits.LATD2 62 | #define GEN_2_PIN LATDbits.LATD3 63 | #define GEN_ENABLE LATDbits.LATD11 64 | 65 | #define LED_R LATDbits.LATD6 66 | #define LED_G LATFbits.LATF1 67 | #define LED_B LATDbits.LATD7 68 | 69 | #define EXP_0_IN PORTGbits.RG2 70 | #define EXP_0_OUT LATGbits.LATG2 71 | #define EXP_0_T TRISGbits.TRISG2 72 | #define EXP_1_IN PORTGbits.RG3 73 | #define EXP_1_OUT LATGbits.LATG3 74 | #define EXP_1_T TRISGbits.TRISG3 75 | #define EXP_2_IN PORTBbits.RB0 76 | #define EXP_2_OUT LATBbits.LATB0 77 | #define EXP_2_T TRISBbits.TRISB0 78 | #define EXP_3_IN PORTBbits.RB1 79 | #define EXP_3_OUT LATBbits.LATB1 80 | #define EXP_3_T TRISBbits.TRISB1 81 | 82 | 83 | void wait_1ms (void); 84 | void wait_ms (uint32_t count); 85 | uint8_t keyb_tasks (void); 86 | void hw_init (void); 87 | void sound_set_note (uint8_t note, uint8_t generator); 88 | void sound_set_generator (uint16_t period, uint8_t generator); 89 | void sound_play_notes (uint8_t note1, uint8_t note2, uint8_t note3, uint16_t wait); 90 | void hw_sleep (void); 91 | void (*start_after_wake)(void); 92 | void wake_return(void); 93 | void set_led (uint8_t led_n, uint8_t led_v); 94 | uint16_t get_rnd (void); 95 | void exp_set(uint8_t pos, uint8_t val); 96 | void exp_ddr(uint8_t pos, uint8_t val); 97 | uint8_t exp_get (uint8_t pos); 98 | uint8_t get_led_word(void); 99 | void set_led_word (uint8_t val); 100 | 101 | 102 | 103 | typedef union 104 | { 105 | struct 106 | { 107 | unsigned up:1; 108 | unsigned dn:1; 109 | unsigned lt:1; 110 | unsigned rt:1; 111 | unsigned ent:1; 112 | unsigned col:1; 113 | unsigned brk:1; 114 | unsigned del:1; 115 | }; 116 | uint8_t CHAR; 117 | }kspec_var; 118 | 119 | #define NEWLINE 0x0A 120 | #define K_ENT 0x0A 121 | #define K_ECR 0x0D 122 | 123 | #define BACKSPACE 0x08 124 | #define K_UP 0x1C 125 | #define K_DN 0x1D 126 | #define K_LT 0x1E 127 | #define K_RT 0x1F 128 | #define ESCAPE 0x1B 129 | #define K_DEL 0x7F 130 | #define K_COL 0x01 131 | #define K_BRK 0x02 132 | 133 | #define TBUF_LEN 2048 134 | #define TERM_WIDTH 40 135 | #define TERM_LINES 20 136 | 137 | #define STDIO_LOCAL 0 138 | #define STDIO_TTY1 1 139 | 140 | void init_io(uint8_t mode); 141 | uint8_t stdio_write (int8_t * data); 142 | uint8_t stdio_c (uint8_t data); 143 | uint8_t stdio_in (uint8_t block); 144 | int8_t stdio_get_state (void); 145 | int8_t stdio_get (int8_t * dat); 146 | 147 | #define FCY 48000000UL 148 | #define FPB FCY/1 149 | 150 | void serial_flush (void); 151 | uint8_t rx_sta (void); 152 | uint8_t rx_read (void); 153 | void tx_write (uint8_t data); 154 | 155 | 156 | #endif -------------------------------------------------------------------------------- /firmware/badge1.X/src/hw.h: -------------------------------------------------------------------------------- 1 | #ifndef __HW_H 2 | #define __HW_H 3 | 4 | //#include 5 | #include 6 | #include "badge_settings.h" 7 | 8 | #define DISP_BUFFER_WIDE 40 9 | #define DISP_BUFFER_HIGH 20 10 | 11 | #define LCD_PORT LATE 12 | #define LCD_WR LATDbits.LATD4 13 | #define LCD_RES LATGbits.LATG7 14 | #define LCD_RD LATDbits.LATD5 15 | #define LCD_DC LATGbits.LATG8 16 | 17 | #define LCD_WR_SET PORTDSET = (1<<4) 18 | #define LCD_WR_CLR PORTDCLR = (1<<4) 19 | #define LCD_DC_SET PORTGSET = (1<<8) 20 | #define LCD_DC_CLR PORTGCLR = (1<<8) 21 | 22 | #define LCD_BKLT LATFbits.LATF0 23 | #define LCD_PWR LATCbits.LATC15 24 | 25 | #define K_R5 LATFbits.LATF4 26 | #define K_R4 LATBbits.LATB15 27 | #define K_R3 LATBbits.LATB14 28 | #define K_R2 LATBbits.LATB13 29 | #define K_R1 LATBbits.LATB12 30 | 31 | #define K_C1 PORTBbits.RB11 32 | #define K_C2 PORTBbits.RB10 33 | #define K_C3 PORTBbits.RB9 34 | #define K_C4 PORTBbits.RB8 35 | #define K_C5 PORTBbits.RB7 36 | #define K_C6 PORTBbits.RB6 37 | #define K_C7 PORTBbits.RB5 38 | #define K_C8 PORTBbits.RB4 39 | #define K_C9 PORTBbits.RB3 40 | #define K_C10 PORTBbits.RB2 41 | #define K_SHIFTR PORTDbits.RD9 42 | #define K_SHIFTL PORTDbits.RD10 43 | #define K_PWR PORTGbits.RG6 44 | #define KEY_BRK PORTGbits.RG9 45 | 46 | #define SYS_CLK 48000000UL 47 | #define PB_CLK 48000000UL 48 | 49 | #define LEDR LATDbits.LATD6 50 | #define LEDG LATFbits.LATF1 51 | #define LEDB LATDbits.LATD7 52 | 53 | 54 | #define CS_FLASH LATFbits.LATF2 55 | #define FLASH_WP LATDbits.LATD8 56 | #define FLASH_HOLD LATCbits.LATC12 57 | 58 | #define CS_MEM FLASH_WP 59 | 60 | 61 | #define GEN_0_PIN LATDbits.LATD1 62 | #define GEN_1_PIN LATDbits.LATD2 63 | #define GEN_2_PIN LATDbits.LATD3 64 | #define GEN_ENABLE LATDbits.LATD11 65 | 66 | #define LED_R LATDbits.LATD6 67 | #define LED_G LATFbits.LATF1 68 | #define LED_B LATDbits.LATD7 69 | 70 | #define EXP_0_IN PORTGbits.RG2 71 | #define EXP_0_OUT LATGbits.LATG2 72 | #define EXP_0_T TRISGbits.TRISG2 73 | #define EXP_1_IN PORTGbits.RG3 74 | #define EXP_1_OUT LATGbits.LATG3 75 | #define EXP_1_T TRISGbits.TRISG3 76 | #define EXP_2_IN PORTBbits.RB0 77 | #define EXP_2_OUT LATBbits.LATB0 78 | #define EXP_2_T TRISBbits.TRISB0 79 | #define EXP_3_IN PORTBbits.RB1 80 | #define EXP_3_OUT LATBbits.LATB1 81 | #define EXP_3_T TRISBbits.TRISB1 82 | 83 | 84 | void wait_1ms (void); 85 | void wait_ms (uint32_t count); 86 | uint8_t keyb_tasks (void); 87 | void hw_init (void); 88 | void sound_set_note (uint8_t note, uint8_t generator); 89 | void sound_set_generator (uint16_t period, uint8_t generator); 90 | void sound_play_notes (uint8_t note1, uint8_t note2, uint8_t note3, uint16_t wait); 91 | void hw_sleep (void); 92 | void (*start_after_wake)(void); 93 | void wake_return(void); 94 | void set_led (uint8_t led_n, uint8_t led_v); 95 | uint16_t get_rnd (void); 96 | void exp_set(uint8_t pos, uint8_t val); 97 | void exp_ddr(uint8_t pos, uint8_t val); 98 | uint8_t exp_get (uint8_t pos); 99 | uint8_t get_led_word(void); 100 | void set_led_word (uint8_t val); 101 | 102 | 103 | 104 | typedef union 105 | { 106 | struct 107 | { 108 | unsigned up:1; 109 | unsigned dn:1; 110 | unsigned lt:1; 111 | unsigned rt:1; 112 | unsigned ent:1; 113 | unsigned col:1; 114 | unsigned brk:1; 115 | unsigned del:1; 116 | }; 117 | uint8_t CHAR; 118 | }kspec_var; 119 | 120 | #define NEWLINE 0x0A 121 | #define K_ENT 0x0A 122 | #define K_ECR 0x0D 123 | 124 | #define BACKSPACE 0x08 125 | #define K_UP 0x1C 126 | #define K_DN 0x1D 127 | #define K_LT 0x1E 128 | #define K_RT 0x1F 129 | #define ESCAPE 0x1B 130 | #define K_DEL 0x7F 131 | #define K_COL 0x01 132 | #define K_BRK 0x02 133 | 134 | #define TBUF_LEN 2048 135 | #define TERM_WIDTH 40 136 | #define TERM_LINES 20 137 | 138 | #define STDIO_LOCAL 0 139 | #define STDIO_TTY1 1 140 | 141 | void init_io(uint8_t mode); 142 | uint8_t stdio_write (int8_t * data); 143 | uint8_t stdio_c (uint8_t data); 144 | uint8_t stdio_in (uint8_t block); 145 | int8_t stdio_get_state (void); 146 | int8_t stdio_get (int8_t * dat); 147 | 148 | #define FCY 48000000UL 149 | #define FPB FCY/1 150 | 151 | void serial_flush (void); 152 | uint8_t rx_sta (void); 153 | uint8_t rx_read (void); 154 | void tx_write (uint8_t data); 155 | 156 | 157 | #endif -------------------------------------------------------------------------------- /firmware/badge1.X/src/Z80/iosim.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Z80SIM - a Z80-CPU simulator 3 | * 4 | * Copyright (C) 1987-92 by Udo Munk 5 | * 6 | * This modul of the simulator contains a simple terminal I/O 7 | * simulation as an example. It is released to the public domain 8 | * and may be modified by user. 9 | * 10 | * History: 11 | * 28-SEP-87 Development on TARGON/35 with AT&T Unix System V.3 12 | * 11-JAN-89 Release 1.1 13 | * 08-FEB-89 Release 1.2 14 | * 13-MAR-89 Release 1.3 15 | * 09-FEB-90 Release 1.4 Ported to TARGON/31 M10/30 16 | * 20-DEC-90 Release 1.5 Ported to COHERENT 3.0 17 | * 10-JUN-92 Release 1.6 long casting problem solved with COHERENT 3.2 18 | * and some optimization 19 | * 25-JUN-92 Release 1.7 comments in english 20 | */ 21 | 22 | /* 23 | * Sample I/O-handler 24 | * 25 | * Port 0 input: reads the next byte from stdin 26 | * Port 0 output: writes the byte to stdout 27 | * 28 | * All the other ports are connected to a I/O-trap handler, 29 | * I/O to this ports stops the simulation with an I/O error. 30 | */ 31 | #include 32 | #include 33 | #include "sim.h" 34 | #include "simglb.h" 35 | #include "hwz.h" 36 | #include "../hw.h" 37 | 38 | uint8_t iosim_mode; 39 | 40 | /* 41 | * This function is to initiate the I/O devices. 42 | * It will be called from the CPU simulation before 43 | * any operation with the Z80 is possible. 44 | * 45 | * In this sample I/O simulation we initialize all 46 | * unused port with an error trap handler, so that 47 | * simulation stops at I/O on the unused ports. 48 | */ 49 | void init_io(uint8_t mode) 50 | { 51 | iosim_mode = mode; 52 | } 53 | 54 | /* 55 | * This function is to stop the I/O devices. It is 56 | * called from the CPU simulation on exit. 57 | * 58 | */ 59 | void exit_io() 60 | { 61 | } 62 | 63 | /* 64 | * This is the main handler for all IN op-codes, 65 | * called by the simulator. It calls the input 66 | * function for port adr. 67 | */ 68 | BYTE io_in(adr) 69 | BYTE adr; 70 | { 71 | char sstr[3]; 72 | uint8_t test,test2; 73 | if (iosim_mode==IO_CPM_MODE) 74 | { 75 | if (adr==0x01) 76 | { //const 77 | // return rx_sta(); 78 | return stdio_get_state(); 79 | } 80 | if (adr==0x02) //conin 81 | { 82 | while (stdio_get_state()==0); 83 | stdio_get(sstr); 84 | return sstr[0]; 85 | } 86 | if (adr==0x07) 87 | { 88 | return read_disk_byte(); 89 | } 90 | //B_CPM001 91 | if (adr==0x0A) //reader device 92 | { 93 | //not implemented by now 94 | // while (rx_sta()==0x00); 95 | // return rx_read(); 96 | } 97 | 98 | if (adr==0x68) 99 | { 100 | return rx_read(); 101 | } 102 | if (adr==0x6D) 103 | { 104 | test=0x20; 105 | //if (rxm_sta()==0xFF) test = test|0x01; 106 | if (rx_sta()==0xFF) test = test|0x01; 107 | return test; 108 | } 109 | } 110 | if (iosim_mode==IO_BASIC_MODE) 111 | { 112 | // IN 0 returns serial status: 0x02 for no data on input buffer, 0x22 means data are available 113 | // IN 1 reads data from serial port 114 | if (adr==0x00) 115 | { 116 | if (stdio_get_state()==0) 117 | return 0x02; 118 | else 119 | return 0x22; 120 | } 121 | if (adr==0x01) 122 | { 123 | stdio_get(sstr); 124 | return sstr[0]; 125 | } 126 | } 127 | } 128 | 129 | /* 130 | * This is the main handler for all OUT op-codes, 131 | * called by the simulator. It calls the output 132 | * function for port adr. 133 | */ 134 | BYTE io_out(adr, data) 135 | BYTE adr, data; 136 | { 137 | uint8_t test; 138 | if (iosim_mode==IO_CPM_MODE) 139 | { 140 | if (adr==0x03) //concout device 141 | { 142 | stdio_c(data); 143 | } 144 | if (adr==0x04) 145 | { 146 | set_drive(data); 147 | } 148 | if (adr==0x05) 149 | { 150 | set_track(data); 151 | } 152 | if (adr==0x06) 153 | { 154 | set_sector(data); 155 | } 156 | if (adr==0x08) 157 | { 158 | write_disk_byte(data); 159 | } 160 | //B_CPM002 161 | if (adr==0x09) //punch device 162 | { 163 | // tx_write(data); //not implemented by now 164 | } 165 | if (adr==0x0B) //list device 166 | { 167 | // tx_write(data); //not implemented by now 168 | } 169 | if (adr==0x68) 170 | { 171 | tx_write(data); 172 | } 173 | if (adr==0xFF) 174 | { 175 | reload_cpm_warm(); 176 | } 177 | } 178 | if (iosim_mode==IO_BASIC_MODE) 179 | { 180 | if (adr==0x01) //concout device 181 | { 182 | stdio_c(data); 183 | } 184 | } 185 | } 186 | 187 | /* 188 | * I/O trap funtion 189 | * This function should be added into all unused 190 | * entrys of the port array. It stops the emulation 191 | * with an I/O error. 192 | */ 193 | static BYTE io_trap() 194 | { 195 | cpu_error = IOTRAP; 196 | cpu_state = STOPPED; 197 | return((BYTE) 0); 198 | } 199 | 200 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Retrocomputing BASIC Badge 2 | 3 | 2018 Hackaday Belgrade Hardware Badge 4 | 5 | * Hardware Lead: Voja Antonic 6 | * Software Lead: Jaromir Sukuba 7 | 8 | Hardware details available on [the BASIC Badge project page](https://hackaday.io/project/80627-badge-for-hackaday-conference-2018-in-belgrade). 9 | 10 | ## BASIC Word List: 11 | 12 | Firmware at the day of conference was 1.00. There are new versions coming since then, see changes at https://github.com/Hack-a-Day/basic-badge/blob/master/firmware/badge1.X/changes.txt 13 | 14 | ### Standard Words: 15 | * `print` 16 | * `println` 17 | * `if` 18 | * `else` 19 | * `goto` 20 | * `gosub` 21 | * `return` 22 | * `for` 23 | * `next` 24 | * `end` 25 | * `let` 26 | * `rem` 27 | 28 | ### Badge Custom Words 29 | 30 | * `led X,Y` - control LED, X[0..2] RGB, Y[0..1] on/off 31 | * `tune A,B,C,D` - plays tones A, B, C for duration D 32 | * `clrscr` - clear screen 33 | * `setxy X,Y` - set cursor at X,Y 34 | * `wait X` - wait for X ms 35 | * `color X,Y` - X=Foreground, Y=Background using EGA 16-color palette 36 | * `chr X` - prints character with ASCII representation X 37 | * `termt X` - sets VT100 terminal on or off (1-on, 0-off) 38 | * `rnd X` - function to return random number 0..X 39 | * `ein X` - function to return value of expansion pin X 40 | * `eout X,Y` - control expansion pin, X[0..3], Y[0..1] on/off 41 | * `edr X,Y` - sets expansion pin function X[0..3], Y[0..1] output/input 42 | * `uin X` - function to return received byte from serial port, if X=0, function is non-blocking, if X=1, function is blocking 43 | * `uout X` - outputs value X to serial port as single byte 44 | * `input "string"` - prints string and returns user entered value 45 | * `peek X` - returns value from memory location X 46 | * `poke X,Y` - write value Y into memory, on location X 47 | * `cursor X` - turns cursor on (X=1) or off (X=0) 48 | * `kin X` - function to return byte from keyboard, if X=0, function is non-blocking, if X=1, function is blocking 49 | 50 | ### BASIC CLI commands 51 | 52 | * `run` - runs program 53 | * `save X` - Save program buffer to flash. There are 16 slots: X[0..15] 54 | * `load X` - Load program into buffer from flash. There are 16 slots: X[0..15] 55 | * `list` - list whole program 56 | * `more` - list program by pages 57 | * `clr` - clears all code from the program buffer 58 | * `free` - prints amount of free program buffer 59 | * `sload` - load new program into buffer from serial port 60 | * `ssave` - output program buffer via serial port 61 | * `help` - prints out basic BASIC help 62 | 63 | 64 | 65 | ## Setting Up the Toolchain for BASIC Badge 66 | 67 | The BASIC badge is based around a PIC32MX370F512H. Software is compiled using MPLABX, XC32 compiler, and legacy peripheral libraries from Microchip. 68 | 69 | 1. Download three packages: 70 | * Navigate to the Downloads" tab at the bottom of the [Microchip Compilers](http://www.microchip.com/mplab/compilers) page. 71 | * Download `MPLAB® XC32/32++ Compiler v2.05` for your operating system 72 | * Download `PIC32 Legacy Peripheral Libraries` for your operating system 73 | * Navigate to the "Downloads" tab part way down the screen at the [Microchip MPLAB X IDE](http://www.microchip.com/mplab/mplab-x-ide) page. 74 | 75 | 2. Install the packages: 76 | * Install the XC32 compiler first 77 | * Install the peripheral libraries next. *IMPORTANT:* You must specify the same directory as the XC32 compiler. This will likely not be the default option during install. For Linux installation this director was: `/opt/microchip/xc32/v2.05/` 78 | * Install MPLABX IDE 79 | 80 | 3. Open the MPLABX project from this repository 81 | * A PIC programmer like the PICKIT3 is required to program your badge 82 | * On the PIC programmer, pins 1-5 correspond to RES, V+, GND, B0, and B1 on the badge 83 | 84 | ## Using XMODEM 85 | 86 | # Badge side 87 | 88 | * Launch "CP/M @ Z80" on the badge 89 | * b: 90 | * xmdm r e:ZORK1.DAT 91 | 92 | # Linux XMODEM info 93 | 94 | * sudo apt-get install lrzsz 95 | * sudo chmod 777 /dev/ttyUSB0 96 | * sx -X ZORK1.DAT > /dev/ttyUSB0 < /dev/ttyUSB0 97 | 98 | ## Proposed Functionality 99 | 100 | * High Importance: 101 | * BASIC interpreter 102 | * Line editor for BASIC programs 103 | * Save/Load ability (stored in program memory) 104 | * Simple menu system 105 | * Medium Importance 106 | * Hardware control on expansion port 107 | * Game(s) that come with the badge 108 | * Ability for users to write C files and compile them into new firmward to flash to badge 109 | * Low Importance 110 | * Serial connection allows users to program BASIC onto badge from computer without full reflash (needs USB to serial adapter) 111 | * Programming challenge? Like a game that encourages writing BASIC to solve it 112 | * Bling (demos that run on the badge) 113 | -------------------------------------------------------------------------------- /firmware/badge1.X/src/splash.c: -------------------------------------------------------------------------------- 1 | #include "splash.h" 2 | #include 3 | 4 | struct Cipher_box 5 | { 6 | int16_t x; // Pixel location on screen (negative values for left overflow) 7 | uint8_t row; // Which of 12 columns in the splash logo this belongs to 8 | }; 9 | 10 | void show_splash(void) 11 | { 12 | uint16_t i,j; 13 | tft_fill_area(0,0,320,240,CIPHER_BACKGROUND); //Make display black 14 | for (i=0; i<12; i++) 15 | { 16 | for (j=0; j<12; j++) 17 | { 18 | if (b_cipher[i] & 1<row * CIPHER_CHAR_WIDTH)+((b->row / 3) * CIPHER_SPACE); 36 | 37 | if ((b->x<320) && (b->x>=0)) 38 | { 39 | //Draw leading edge 40 | draw_vert_line(b->x,y,CIPHER_CHAR_WIDTH,CIPHER_CURSOR); 41 | } 42 | if (b->x>=CIPHER_CHAR_WIDTH) 43 | { 44 | //Erase trailing edge 45 | //FIXME: erase with red if this is within the splash area 46 | if (overlaps_logo(b->x-CIPHER_CHAR_WIDTH,b->row)) 47 | { 48 | draw_vert_line(b->x-CIPHER_CHAR_WIDTH,y,CIPHER_CHAR_WIDTH,CIPHER_COLOR); 49 | } 50 | else 51 | { 52 | draw_vert_line(b->x-CIPHER_CHAR_WIDTH,y,CIPHER_CHAR_WIDTH,CIPHER_BACKGROUND); 53 | } 54 | } 55 | 56 | b->x = b->x + 1; 57 | } 58 | 59 | void move_box_left(struct Cipher_box *b) 60 | { 61 | uint8_t y = CIPHER_Y0 + (b->row * CIPHER_CHAR_WIDTH)+((b->row / 3) * CIPHER_SPACE); 62 | 63 | if ((b->x<320) && (b->x>=0)) 64 | { 65 | //Draw leading edge 66 | draw_vert_line(b->x,y,CIPHER_CHAR_WIDTH,CIPHER_CURSOR); 67 | } 68 | if ((b->x+CIPHER_CHAR_WIDTH<320) && (b->x+CIPHER_CHAR_WIDTH>=0)) 69 | { 70 | //Erase trailing edge 71 | //FIXME: erase with red if this is within the splash area 72 | if (overlaps_logo(b->x+CIPHER_CHAR_WIDTH,b->row)) 73 | { 74 | draw_vert_line(b->x+CIPHER_CHAR_WIDTH,y,CIPHER_CHAR_WIDTH,CIPHER_COLOR); 75 | } 76 | else 77 | { 78 | draw_vert_line(b->x+CIPHER_CHAR_WIDTH,y,CIPHER_CHAR_WIDTH,CIPHER_BACKGROUND); 79 | } 80 | } 81 | 82 | b->x = b->x - 1; 83 | } 84 | 85 | uint8_t overlaps_logo(int16_t x, uint8_t row) { 86 | //Returns non-zero if the location overlaps part of the logo 87 | if ((x=320)) 88 | { 89 | return 0; //Not within area where logo will be drawn 90 | } 91 | int16_t offset_adjusted = x-CIPHER_X0;//55 92 | uint8_t superblock_size = (CIPHER_CHAR_WIDTH*3) + CIPHER_SPACE;//59 93 | uint8_t superblock = offset_adjusted / superblock_size;//0 94 | uint8_t local_x = offset_adjusted-(superblock * superblock_size);//55 95 | 96 | if (local_x >= (CIPHER_CHAR_WIDTH*3)) 97 | { 98 | return 0; //Falls within space between squares on logo 99 | } 100 | 101 | uint8_t index = (local_x/(CIPHER_CHAR_WIDTH))+(3*superblock); 102 | if (b_cipher[row] & 1<<(11-index)) 103 | { 104 | return 1; 105 | } 106 | return 0; 107 | } 108 | 109 | void animate_splash(void) 110 | { 111 | uint16_t x = 0; 112 | uint16_t splash_waitfor = 0; 113 | 114 | struct Cipher_box box0 = { 0, 0 }; 115 | struct Cipher_box box1 = { 319+(10*CIPHER_CHAR_WIDTH), 1 }; 116 | struct Cipher_box box2 = { 0-(2*CIPHER_CHAR_WIDTH), 2 }; 117 | struct Cipher_box box3 = { 319+(8*CIPHER_CHAR_WIDTH), 3 }; 118 | struct Cipher_box box4 = { 0-(4*CIPHER_CHAR_WIDTH), 4 }; 119 | struct Cipher_box box5 = { 319+(6*CIPHER_CHAR_WIDTH), 5 }; 120 | struct Cipher_box box6 = { 0-(6*CIPHER_CHAR_WIDTH), 6 }; 121 | struct Cipher_box box7 = { 319+(4*CIPHER_CHAR_WIDTH), 7 }; 122 | struct Cipher_box box8 = { 0-(8*CIPHER_CHAR_WIDTH), 8 }; 123 | struct Cipher_box box9 = { 319+(2*CIPHER_CHAR_WIDTH), 9 }; 124 | struct Cipher_box box10 = { 0-(10*CIPHER_CHAR_WIDTH), 10 }; 125 | struct Cipher_box box11 = { 319, 11 }; 126 | 127 | tft_fill_area(0,0,320,240,CIPHER_BACKGROUND); //Make display black 128 | 129 | while (1) { 130 | if (millis()>=splash_waitfor) 131 | { 132 | splash_waitfor = millis()+4; 133 | move_box_right(&box0); 134 | move_box_left(&box1); 135 | move_box_right(&box2); 136 | move_box_left(&box3); 137 | move_box_right(&box4); 138 | move_box_left(&box5); 139 | move_box_right(&box6); 140 | move_box_left(&box7); 141 | move_box_right(&box8); 142 | move_box_left(&box9); 143 | move_box_right(&box10); 144 | move_box_left(&box11); 145 | 146 | if (box10.x>=(320+CIPHER_CHAR_WIDTH)) 147 | { 148 | break; 149 | } 150 | } 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /firmware/badge_alternative.X/src/badge.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "badge.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | /************ Defines ****************************/ 12 | 13 | 14 | 15 | //a lot of magic numbers here, should be done properly 16 | int8_t key_buffer[10], stdio_local_buff[STDIO_LOCAL_BUFF_SIZE]; 17 | 18 | uint8_t get_stat,key_buffer_ptr =0; 19 | uint8_t stdio_local_len=0; 20 | int32_t i,j,len; 21 | volatile uint8_t handle_display = 1; 22 | volatile int8_t brk_key,stdio_src; 23 | extern volatile uint16_t bufsize; 24 | volatile uint32_t ticks; // millisecond timer incremented in ISR 25 | 26 | int8_t disp_buffer[DISP_BUFFER_HIGH+1][DISP_BUFFER_WIDE]; 27 | int8_t color_buffer[DISP_BUFFER_HIGH+1][DISP_BUFFER_WIDE]; 28 | 29 | void badge_init (void) 30 | { 31 | //B_BDG009 32 | ticks = 0; 33 | stdio_src = STDIO_LOCAL; 34 | // stdio_src = STDIO_TTY1; 35 | term_init(); 36 | set_cursor_state(1); 37 | } 38 | 39 | //B_BDG004 40 | void enable_display_scanning(uint8_t onoff) 41 | { 42 | //Turns vt100 scanning on or off 43 | if (onoff) handle_display = 1; 44 | else handle_display = 0; 45 | } 46 | 47 | uint32_t millis(void) 48 | { 49 | return ticks; 50 | } 51 | 52 | 53 | void clr_buffer (void) 54 | { 55 | for (i=0; i0) 156 | { 157 | strncpy(out,key_buffer,key_buffer_ptr); 158 | key_buffer_ptr = 0; 159 | } 160 | IEC0bits.T2IE = 1; 161 | return retval; 162 | } 163 | 164 | 165 | uint8_t stdio_local_buffer_state (void) 166 | { 167 | if (stdio_local_len>0) return 1; 168 | else return 0; 169 | } 170 | 171 | int8_t stdio_local_buffer_get (void) 172 | { 173 | int8_t retval=0; 174 | if (stdio_local_len>0) 175 | { 176 | retval = stdio_local_buff[0]; 177 | for (i=1;i0) 208 | key_buffer[key_buffer_ptr++] = key_temp; 209 | } 210 | 211 | void __ISR(_TIMER_1_VECTOR, IPL4AUTO) Timer1Handler(void) 212 | { 213 | IFS0bits.T1IF = 0; 214 | ++ticks; 215 | } 216 | void __ISR(_EXTERNAL_2_VECTOR, IPL4AUTO) Int2Handler(void) 217 | { 218 | IEC0bits.INT2IE = 0; 219 | } 220 | 221 | uint16_t get_user_value (void) 222 | { 223 | int8_t temp_arr[20]; 224 | uint8_t temp_arr_p=0,char_val,stat; 225 | uint32_t retval; 226 | stdio_write(" :"); 227 | while (1) 228 | { 229 | stat = stdio_get(&char_val); 230 | if ((char_val!=NEWLINE)&(stat!=0)) 231 | { 232 | stdio_c(char_val); 233 | if (char_val>=' ') temp_arr[temp_arr_p++] = char_val; 234 | else if (char_val==BACKSPACE) 235 | { 236 | if (temp_arr_p>0) temp_arr[--temp_arr_p]=0; 237 | } 238 | } 239 | if ((char_val==NEWLINE)&(stat!=0)) 240 | { 241 | temp_arr[temp_arr_p] = 0; 242 | sscanf(temp_arr,"%d",&retval); 243 | stdio_c('\n'); 244 | return retval; 245 | } 246 | if (brk_key) return 0; 247 | } 248 | } 249 | 250 | 251 | void display_refresh_force (void) 252 | { 253 | tft_disp_buffer_refresh((uint8_t *)disp_buffer,(uint8_t *)color_buffer); 254 | } -------------------------------------------------------------------------------- /firmware/badge1.X/src/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "badge_settings.h" 3 | #include "badge.h" 4 | #include "hw.h" 5 | #include "post.h" 6 | 7 | int16_t main(void) 8 | { 9 | hw_init(); 10 | badge_init(); 11 | if (KEY_BRK==0) post(); 12 | if ((SHOW_SPLASH)&(K_SHIFTR==1)) boot_animation(); 13 | badge_menu(); 14 | while (1); //menu is never left, but anyway 15 | } 16 | 17 | /* 18 | * Interesting places to take look at, in MPLABX use CtrlCtrl+Shift+F to search in all files 19 | * for those "bookmarks" 20 | * 21 | * 22 | * ----------------badge stuff---------------- 23 | * After reset, badge checks whether BRK key is pressed. In case it is, test routine starts, see 24 | * B_BDG001 25 | * If not, B_BDG002 is the place to jump. Welcome screen is painstakingly drawn via lot of setxy 26 | * and print commands. Then it waits for user input. All interaction with user is done mainly via 27 | * stdio functions, that can be redirected either to local screen or serial port, available on pins 28 | * C13 and C14 of expansion port. There is also stdio buffer that can be written from software, 29 | * for specific purposes 30 | * The four stdio functions are under B_BDG003 31 | * 32 | * For this badge, I opted to refresh display from interrupt handler linked to timer5, set to fire 33 | * every 12ms - B_BDG003. This is heartbeat of badge, where both partial display refresh (two 34 | * lines at once) and keyboard scanning tasks do take place. Notice, one can disable refreshing 35 | * the display if needed via function B_BDG004 or manipulating the variable handle_display 36 | * directly. Timer 1 runs with 1ms period, and increments variable ticks, available via function 37 | * millis(). 38 | * 39 | * User can write its own programs to be incorporated within "big firmware" of badge, see B_BDG006 40 | * and B_BDG007 and B_BDG008. Badge can be turned on or off via power button. This erases display. 41 | * Since badge doesn't have graphic framebuffer (it has terminal text buffer though), the user should 42 | * refresh the display in appropriate function, set up via function pointer, see B_BDG005 and B_BDG009 43 | * Currently, there is about 16kB of RAM and 45kB of FLASH free to use for user 44 | * If some CP/M features are disabled, see B_BDG010, user can gain additional quarter of megabyte of 45 | * FLASH space and about 22kB of RAM. 46 | * 47 | * Other than that, simple firmware skeleton will be provided too, so user doesn't need to use 48 | * software infrastructure of badge firmware, with all its dependencies; uncovering full hardware 49 | * potential of badge. 50 | * 51 | * 52 | * ----------------BASIC interpreter---------------- 53 | * 54 | * B_BAS001: This is where BASIC tokens are defined, have you want to add your word, add one 55 | * into this list, then go to B_BAS002 to define appropriate action. Of course, don't forget 56 | * to add the token number into list in B_BAS003 57 | * This way you can make words like LED, invoked as LED 2,1 58 | * If you want to add word returning value like RND in form of LET A = RND 10, take a look how it's 59 | * made in B_BAS004 60 | * 61 | * A lot of things around BASIC happens outside the interpreter itself. After invoking BASIC, the first 62 | * function to be called is B_BAS005 where everything is set to run BASIC loop in B_BAS006 63 | * It basically (no pun intended) collects users input and once buffer si full, it is sent to decide what 64 | * it is - B_BAS007 65 | * If it appears to be valid line of BASIC program, including line number, it goes to be added to 66 | * current program B_BAS008 67 | * If not, program flows through series of comparisons to determine whether the thing that user wrote is 68 | * something from a few commands that command interpreter can execute. One of them is RUN that sets up 69 | * interpreter in B_BAS009 and runs main loop in B_BAS010. 70 | * Program buffer is set to 16kB, so you can't have programs longer than that. You may redefine buffer 71 | * length (see badge_settings.h), you may want to check save/load routines, see B_BAS011 72 | * 73 | * 74 | * ----------------CP/M machine---------------- 75 | * 76 | * This one runs on Z80 interpreter, written by Udo Munk. It is directory /Z80, along with two other files, 77 | * defining memory and hardware configuration of this virtual machine, files hwz.c and iosim.c 78 | * 79 | * iosim.c defines the memory map. I wrote the BIOS for CP/M machine to be extremely simple, with more 80 | * automation and intelligence on software side, not achievable with classic hardware means. For example, 81 | * writing to address 0xFF triggers CP/M system reload. so BIOS hook can be as simple as writing single byte 82 | * into this address. Classic BIOS needed a lot of more Z80 instructions to achieve th same. 83 | * On address 0x68 (+0x6D) is implemented simple UART, linked to UART3 of badge (available on C13 and C14 of 84 | * expansion port). This UART is utilized in XMODEM program (available at drive B:), so user can transfer 85 | * CP/M binaries from PC via any compatible Xmodem terminal. I used moserial and cutecom in linux, or teraterm 86 | * in windows. 87 | * CP/M machine is setup to use six different drives: 88 | * A: - 22kB in size, RAM disk. Fast, no wearout, ideal for temporary storage. Trashed on reboot. 89 | * B: - 128kB ROM disk, contains a lot of goodies. You could pack a lot of software into 128kB then. 90 | * C: - 128kB ROM dosk, contains Zork and Sargon. You know, games. 91 | * D: - 512kB FLASH disk, free for your use 92 | * hwz.c contains all stuff to access disks and devices of CP/M machine, like disk byte read and write 93 | * functions, called directly by BIOS via addresses 0x07 and 0x08, with 0x05 and 0x06 setting track and 94 | * sector of drive selected via 0x04. 95 | * 96 | * CP/M defines some standard IO devices - reader, puncher for your punch cards and list device to print 97 | * out your program listings. Those are not implemented in badge hardware iosim.c, see B_CPM001 and B_CPM002 98 | * If defined, you can - for example - list files directly from CP/M via virtual printer, or make virtual 99 | * punch card reader/puncher to EEPROM, thumb drive, PC, FTP server via ESP32 or anything you can connect 100 | * to bitbanged interface on badge expansion port. 101 | * 102 | */ -------------------------------------------------------------------------------- /firmware/badge1.X/src/vt100.h: -------------------------------------------------------------------------------- 1 | #ifndef __VT100_H 2 | #define __VT100_H 3 | 4 | #define MAX_ESC_LEN 48 5 | #define NOT_IN_ESC 0 6 | #define ESC_GOT_1B 1 7 | #define ESC_CSI 2 8 | #define ESC_NONCSI 3 9 | 10 | 11 | 12 | typedef struct 13 | { 14 | int8_t cx; 15 | int8_t cy; 16 | uint8_t graphicchars; 17 | uint8_t revvideo; 18 | } termstate_t; 19 | 20 | void escseq_process(int8_t c); 21 | void escseq_process_noncsi(int8_t c); 22 | void escseq_process_csi(int8_t c); 23 | void escseq_csi_start(void); 24 | uint8_t escseq_get_param(uint8_t defaultval); 25 | void receive_char(uint8_t c); 26 | void save_term_state(void); 27 | void restore_term_state(void); 28 | void reset_term(void); 29 | uint8_t buf_dequeue(void); 30 | void buf_enqueue(uint8_t c); 31 | /* Set the top and bottom margins. The cursor is moved to the first column 32 | * of the top margin. */ 33 | void video_set_margins(int8_t top, int8_t bottom); 34 | /* Resets the top margin to the top line of the screen and the bottom margin 35 | * to the bottom line of the screen. */ 36 | void video_reset_margins(void); 37 | /* Returns the line number of the top margin. */ 38 | int8_t video_top_margin(void); 39 | /* Returns the line number of the bottom margin. */ 40 | int8_t video_bottom_margin(void); 41 | /* Sets whether or not the screen should be displayed in reverse video. */ 42 | void video_set_reverse(uint8_t val); 43 | /* Clears the screen, returns the cursor to (0,0), and resets the margins 44 | * to the full size of the screen. */ 45 | void video_clrscr(void); 46 | /* Clears the current line and returns the cursor to he start of the line. */ 47 | void video_clrline(void); 48 | /* Clears the rest of the line from the cursor position to the end of the line 49 | * without moving the cursor. */ 50 | void video_clreol(void); 51 | /* erasemode = 0: erase from the cursor (inclusive) to the end of the screen. 52 | * erasemode = 1: erase from the start of the screen to the cursor (inclusive). 53 | * erasemode = 2: erase the entire screen. 54 | * The cursor does not move. 55 | * This call corresponds to the ANSI "Erase in Display" escape sequence. */ 56 | void video_erase(uint8_t erasemode); 57 | /* erasemode = 0: erase from the cursor (inclusive) to the end of the line. 58 | * erasemode = 1: erase from the start of the line to the cursor (inclusive). 59 | * erasemode = 2: erase the entire line. 60 | * The cursor does not move. 61 | * This call corresponds to the ANSI "Erase in Line" escape sequence. */ 62 | void video_eraseline(uint8_t erasemode); 63 | /* Overwrites the character at the cursor position without moving it. */ 64 | void video_setc(int8_t c); 65 | /* Prints a character at the cursor position and advances the cursor. 66 | * Carriage returns and newlines are interpreted. */ 67 | void video_putc(int8_t c); 68 | /* Prints a character at the cursor position and advances the cursor. 69 | * Carriage returns and newlines are not interpreted. */ 70 | void video_putc_raw(int8_t c); 71 | /* Prints a string at the cursor position and advances the cursor. 72 | * The screen will be scrolled if necessary. */ 73 | void video_puts(int8_t *str); 74 | /* Prints a string from program memory at the cursor position and advances 75 | * the cursor. The screen will be scrolled if necessary. */ 76 | void video_putcxy(int8_t x, int8_t y, int8_t c); 77 | /* Prints a string at the specified position. Escape characters are not 78 | * interpreted. The cursor is not advanced and the screen is not scrolled. */ 79 | void video_putsxy(int8_t x, int8_t y, int8_t *str); 80 | /* Prints a string from program memory at the specified position. 81 | * Escape characters are not interpreted. The cursor is not advanced and the 82 | * screen is not scrolled. */ 83 | void video_putline(int8_t y, int8_t *str); 84 | /* Prints a string from program memory on the specified line. 85 | * The previous contents of the line are erased. Escape characters are not 86 | * interpreted. The cursor is not advanced and the screen is not scrolled. */ 87 | void video_gotoxy(int8_t x, int8_t y); 88 | /* Moves the cursor left/right by the specified number of columns. */ 89 | void video_movex(int8_t dx); 90 | /* Moves the cursor up/down the specified number of lines. 91 | * The cursor does not move beyond the top/bottom margins. */ 92 | void video_movey(int8_t dy); 93 | /* Moves the cursor to the start of the current line. */ 94 | void video_movesol(void); 95 | /* Sets the horizontal position of the cursor. */ 96 | void video_setx(int8_t x); 97 | /* Advances the cursor one character to the right, advancing to a new line if 98 | * necessary. */ 99 | void video_cfwd(void); 100 | /* Advances the cursor one line down and moves it to the start of the new line. 101 | * The screen is scrolled if the bottom margin is exceeded. */ 102 | void video_lfwd(void); 103 | /* Advances the cursor one line down but does not return the cursor to the start 104 | * of the new line. The screen is scrolled if the bottom margin is exceeded. */ 105 | void video_lf(void); 106 | /* Moves the cursor one character back, moving to the end of the previous line 107 | * if necessary. */ 108 | void video_cback(void); 109 | /* Moves the cursor to the end of the previous line, or to the first column 110 | * of the top margin if the top margin is exceeded. */ 111 | void video_lback(void); 112 | /* Scrolls the region between the top and bottom margins up one line. 113 | * A blank line is added at the bottom. The cursor is not moved. */ 114 | void video_scrollup(void); 115 | /* Scrolls the region between the top and bottom margins down one line. 116 | * A blank lines is added at the top. The cursor is not moved. */ 117 | void video_scrolldown(void); 118 | /* Returns the x coordinate of the cursor. */ 119 | int8_t video_getx(void); 120 | /* Returns the y coordinate of the cursor. */ 121 | int8_t video_gety(void); 122 | /* Returns the character at the specified position. */ 123 | int8_t video_charat(int8_t x, int8_t y); 124 | /* Shows the cursor. Off by default. */ 125 | void video_show_cursor(void); 126 | /* Hides the cursor. */ 127 | void video_hide_cursor(void); 128 | /* Returns 1 if the cursor is visible, 0 if it is hidden. */ 129 | uint8_t video_cursor_visible(); 130 | /* Set inverse video for the character range specified. */ 131 | void video_invert_range(int8_t x, int8_t y, uint8_t rangelen); 132 | static void CURSOR_INVERT(void); 133 | static void _video_scrollup(void); 134 | static void _video_scrolldown(void); 135 | static void _video_lfwd(void); 136 | static void _video_cfwd(void); 137 | static void _video_lback(void); 138 | static void _video_scrollup_lin(uint8_t lin); 139 | static void _video_scrolldown_lin(uint8_t line); 140 | 141 | 142 | void term_init (void); 143 | void video_set_color(uint8_t fg, uint8_t bg); 144 | 145 | #endif 146 | 147 | -------------------------------------------------------------------------------- /firmware/badge_alternative.X/src/vt100.h: -------------------------------------------------------------------------------- 1 | #ifndef __VT100_H 2 | #define __VT100_H 3 | 4 | #define MAX_ESC_LEN 48 5 | #define NOT_IN_ESC 0 6 | #define ESC_GOT_1B 1 7 | #define ESC_CSI 2 8 | #define ESC_NONCSI 3 9 | 10 | 11 | 12 | typedef struct 13 | { 14 | int8_t cx; 15 | int8_t cy; 16 | uint8_t graphicchars; 17 | uint8_t revvideo; 18 | } termstate_t; 19 | 20 | void escseq_process(int8_t c); 21 | void escseq_process_noncsi(int8_t c); 22 | void escseq_process_csi(int8_t c); 23 | void escseq_csi_start(void); 24 | uint8_t escseq_get_param(uint8_t defaultval); 25 | void receive_char(uint8_t c); 26 | void save_term_state(void); 27 | void restore_term_state(void); 28 | void reset_term(void); 29 | uint8_t buf_dequeue(void); 30 | void buf_enqueue(uint8_t c); 31 | /* Set the top and bottom margins. The cursor is moved to the first column 32 | * of the top margin. */ 33 | void video_set_margins(int8_t top, int8_t bottom); 34 | /* Resets the top margin to the top line of the screen and the bottom margin 35 | * to the bottom line of the screen. */ 36 | void video_reset_margins(void); 37 | /* Returns the line number of the top margin. */ 38 | int8_t video_top_margin(void); 39 | /* Returns the line number of the bottom margin. */ 40 | int8_t video_bottom_margin(void); 41 | /* Sets whether or not the screen should be displayed in reverse video. */ 42 | void video_set_reverse(uint8_t val); 43 | /* Clears the screen, returns the cursor to (0,0), and resets the margins 44 | * to the full size of the screen. */ 45 | void video_clrscr(void); 46 | /* Clears the current line and returns the cursor to he start of the line. */ 47 | void video_clrline(void); 48 | /* Clears the rest of the line from the cursor position to the end of the line 49 | * without moving the cursor. */ 50 | void video_clreol(void); 51 | /* erasemode = 0: erase from the cursor (inclusive) to the end of the screen. 52 | * erasemode = 1: erase from the start of the screen to the cursor (inclusive). 53 | * erasemode = 2: erase the entire screen. 54 | * The cursor does not move. 55 | * This call corresponds to the ANSI "Erase in Display" escape sequence. */ 56 | void video_erase(uint8_t erasemode); 57 | /* erasemode = 0: erase from the cursor (inclusive) to the end of the line. 58 | * erasemode = 1: erase from the start of the line to the cursor (inclusive). 59 | * erasemode = 2: erase the entire line. 60 | * The cursor does not move. 61 | * This call corresponds to the ANSI "Erase in Line" escape sequence. */ 62 | void video_eraseline(uint8_t erasemode); 63 | /* Overwrites the character at the cursor position without moving it. */ 64 | void video_setc(int8_t c); 65 | /* Prints a character at the cursor position and advances the cursor. 66 | * Carriage returns and newlines are interpreted. */ 67 | void video_putc(int8_t c); 68 | /* Prints a character at the cursor position and advances the cursor. 69 | * Carriage returns and newlines are not interpreted. */ 70 | void video_putc_raw(int8_t c); 71 | /* Prints a string at the cursor position and advances the cursor. 72 | * The screen will be scrolled if necessary. */ 73 | void video_puts(int8_t *str); 74 | /* Prints a string from program memory at the cursor position and advances 75 | * the cursor. The screen will be scrolled if necessary. */ 76 | void video_putcxy(int8_t x, int8_t y, int8_t c); 77 | /* Prints a string at the specified position. Escape characters are not 78 | * interpreted. The cursor is not advanced and the screen is not scrolled. */ 79 | void video_putsxy(int8_t x, int8_t y, int8_t *str); 80 | /* Prints a string from program memory at the specified position. 81 | * Escape characters are not interpreted. The cursor is not advanced and the 82 | * screen is not scrolled. */ 83 | void video_putline(int8_t y, int8_t *str); 84 | /* Prints a string from program memory on the specified line. 85 | * The previous contents of the line are erased. Escape characters are not 86 | * interpreted. The cursor is not advanced and the screen is not scrolled. */ 87 | void video_gotoxy(int8_t x, int8_t y); 88 | /* Moves the cursor left/right by the specified number of columns. */ 89 | void video_movex(int8_t dx); 90 | /* Moves the cursor up/down the specified number of lines. 91 | * The cursor does not move beyond the top/bottom margins. */ 92 | void video_movey(int8_t dy); 93 | /* Moves the cursor to the start of the current line. */ 94 | void video_movesol(void); 95 | /* Sets the horizontal position of the cursor. */ 96 | void video_setx(int8_t x); 97 | /* Advances the cursor one character to the right, advancing to a new line if 98 | * necessary. */ 99 | void video_cfwd(void); 100 | /* Advances the cursor one line down and moves it to the start of the new line. 101 | * The screen is scrolled if the bottom margin is exceeded. */ 102 | void video_lfwd(void); 103 | /* Advances the cursor one line down but does not return the cursor to the start 104 | * of the new line. The screen is scrolled if the bottom margin is exceeded. */ 105 | void video_lf(void); 106 | /* Moves the cursor one character back, moving to the end of the previous line 107 | * if necessary. */ 108 | void video_cback(void); 109 | /* Moves the cursor to the end of the previous line, or to the first column 110 | * of the top margin if the top margin is exceeded. */ 111 | void video_lback(void); 112 | /* Scrolls the region between the top and bottom margins up one line. 113 | * A blank line is added at the bottom. The cursor is not moved. */ 114 | void video_scrollup(void); 115 | /* Scrolls the region between the top and bottom margins down one line. 116 | * A blank lines is added at the top. The cursor is not moved. */ 117 | void video_scrolldown(void); 118 | /* Returns the x coordinate of the cursor. */ 119 | int8_t video_getx(void); 120 | /* Returns the y coordinate of the cursor. */ 121 | int8_t video_gety(void); 122 | /* Returns the character at the specified position. */ 123 | int8_t video_charat(int8_t x, int8_t y); 124 | /* Shows the cursor. Off by default. */ 125 | void video_show_cursor(void); 126 | /* Hides the cursor. */ 127 | void video_hide_cursor(void); 128 | /* Returns 1 if the cursor is visible, 0 if it is hidden. */ 129 | uint8_t video_cursor_visible(); 130 | /* Set inverse video for the character range specified. */ 131 | void video_invert_range(int8_t x, int8_t y, uint8_t rangelen); 132 | static void CURSOR_INVERT(void); 133 | static void _video_scrollup(void); 134 | static void _video_scrolldown(void); 135 | static void _video_lfwd(void); 136 | static void _video_cfwd(void); 137 | static void _video_lback(void); 138 | static void _video_scrollup_lin(uint8_t lin); 139 | static void _video_scrolldown_lin(uint8_t line); 140 | 141 | 142 | void term_init (void); 143 | void video_set_color(uint8_t fg, uint8_t bg); 144 | 145 | #endif 146 | 147 | -------------------------------------------------------------------------------- /firmware/badge1.X/src/post.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "hw.h" 9 | #include "vt100.h" 10 | #include "post.h" 11 | #include "disp.h" 12 | #include "Z80/hwz.h" 13 | 14 | uint16_t i; 15 | const int8_t post_char_table[4*11] = "1234567890=qwertyuiop;/asdfghjkl\n\0zxcvbnm,.\0"; 16 | extern uint8_t handle_display; 17 | 18 | void io_test_state (uint8_t state); 19 | 20 | 21 | 22 | //B_BDG001 23 | void post (void) 24 | { 25 | uint8_t retval,index,line,position,color; 26 | uint32_t flash_id; 27 | int8_t temp_string[30]; 28 | handle_display = 0; 29 | set_led(0,1); 30 | set_led(1,1); 31 | set_led(2,1); 32 | wait_ms(400); 33 | tft_fill_area(0,0,320,240,0xFF0000); 34 | wait_ms(1000); 35 | tft_fill_area(0,0,320,240,0x00FF00); 36 | wait_ms(1000); 37 | tft_fill_area(0,0,320,240,0x0000FF); 38 | wait_ms(1000); 39 | handle_display = 1; 40 | term_init(); 41 | set_led(0,0); 42 | set_led(1,0); 43 | set_led(2,0); 44 | 45 | flash_id = fl_rdid(); 46 | if (flash_id==0x1f4501) 47 | video_set_color(EGA_WHITE,EGA_GREEN); 48 | else 49 | video_set_color(EGA_YELLOW,EGA_RED); 50 | video_gotoxy(0,15); 51 | sprintf(temp_string,"FLASH ID is %x\n",flash_id); 52 | stdio_write(temp_string); 53 | video_set_color(EGA_WHITE,EGA_BLACK); 54 | stdio_write("Press LCTRL+ENTER to continue\n"); 55 | wait_ms(200); 56 | video_set_color(11,1); 57 | video_gotoxy(1,1); 58 | stdio_write("u "); 59 | video_gotoxy(0,2); 60 | stdio_write("l r "); 61 | video_gotoxy(22,2); 62 | stdio_write("b b "); 63 | video_gotoxy(1,3); 64 | stdio_write("d "); 65 | video_gotoxy(22,3); 66 | stdio_write("- d "); 67 | video_gotoxy(1,4); 68 | stdio_write("1 2 3 4 5 6 7 9 8 0 = "); 69 | video_gotoxy(1,5); 70 | stdio_write("Q W E R T Y U I O P ; "); 71 | video_gotoxy(1,6); 72 | stdio_write("? A S D F G H J K L e "); 73 | video_gotoxy(1,7); 74 | stdio_write("s Z X C V B N M < > s "); 75 | video_gotoxy(11,8); 76 | stdio_write("sp"); 77 | while (1) 78 | { 79 | if (KEY_BRK==0) 80 | { 81 | video_gotoxy(22,2); 82 | video_set_color(11,2); 83 | stdio_write(" "); 84 | } 85 | if (K_SHIFTR==0) 86 | { 87 | video_gotoxy(21,7); 88 | video_set_color(11,2); 89 | stdio_write(" "); 90 | } 91 | if (K_SHIFTL==0) 92 | { 93 | video_gotoxy(1,7); 94 | video_set_color(11,2); 95 | stdio_write(" "); 96 | } 97 | if (stdio_get(&retval)!=0) 98 | { 99 | if ((retval>=' ')&(retval<0x7F)) 100 | { 101 | index = 255; 102 | for (i=0;i<44;i++) 103 | { 104 | if (post_char_table[i]==retval) 105 | index = i; 106 | } 107 | if (index<255) 108 | { 109 | line = index / 11; 110 | position = index % 11; 111 | video_gotoxy (1+(2*position),4+line); 112 | video_set_color(11,2); 113 | stdio_write(" "); 114 | } 115 | else 116 | { 117 | if (retval=='-') 118 | { 119 | video_gotoxy(22,3); 120 | video_set_color(11,2); 121 | stdio_write(" "); 122 | } 123 | if (retval==' ') 124 | { 125 | video_gotoxy(11,8); 126 | video_set_color(11,2); 127 | stdio_write(" "); 128 | } 129 | } 130 | } 131 | else 132 | { 133 | if (retval==K_UP) video_gotoxy(1,1); 134 | if (retval==K_DN) video_gotoxy(1,3); 135 | if (retval==K_LT) video_gotoxy(0,2); 136 | if (retval==K_RT) video_gotoxy(2,2); 137 | if (retval==BACKSPACE) video_gotoxy(24,2); 138 | if (retval==K_DEL) video_gotoxy(24,3); 139 | if (retval==NEWLINE) video_gotoxy(21,6); 140 | if (retval == K_ECR) break; 141 | video_set_color(11,2); 142 | stdio_write(" "); 143 | } 144 | } 145 | } 146 | video_clrscr(); 147 | term_init(); 148 | color=0; 149 | while (1) 150 | { 151 | video_gotoxy(0,2); 152 | if (color==3) color = 0; 153 | if (color==0) 154 | { 155 | set_led(0,1); 156 | set_led(1,0); 157 | set_led(2,0); 158 | stdio_write("red LED \n"); 159 | stdio_write("generator 1, playing F4, ~349Hz \n"); 160 | wait_ms(600); 161 | sound_play_notes(65,0,0,200); 162 | } 163 | if (color==1) 164 | { 165 | set_led(0,0); 166 | set_led(1,1); 167 | set_led(2,0); 168 | stdio_write("green LED \n"); 169 | stdio_write("generator 2, playing A4, 440Hz \n"); 170 | wait_ms(600); 171 | sound_play_notes(0,69,0,200); 172 | } 173 | if (color==2) 174 | { 175 | set_led(0,0); 176 | set_led(1,0); 177 | set_led(2,1); 178 | stdio_write("blue LED \n"); 179 | stdio_write("generator 3, playing C5, ~523Hz \n"); 180 | wait_ms(600); 181 | sound_play_notes(0,0,72,200); 182 | } 183 | video_set_color(EGA_WHITE,EGA_BLACK); 184 | stdio_write("Press LCTRL+ENTER to continue\n"); 185 | if (stdio_get(&retval)!=0) 186 | { 187 | if (retval == K_ECR) break; 188 | } 189 | color++; 190 | } 191 | set_led(0,0); 192 | set_led(1,0); 193 | set_led(2,0); 194 | video_clrscr(); 195 | term_init(); 196 | U3MODEbits.ON = 0; 197 | TRISCbits.TRISC13 = 0; 198 | TRISCbits.TRISC14 = 0; 199 | TRISBbits.TRISB0 = 0; 200 | TRISBbits.TRISB1 = 0; 201 | while (1) 202 | { 203 | wait_ms(500); 204 | video_gotoxy(0,2); 205 | if (color==6) color = 0; 206 | io_test_state(color); 207 | video_gotoxy(1,7); 208 | video_set_color(EGA_WHITE,EGA_BLACK); 209 | sprintf(temp_string,"pin # %d\n",color); 210 | stdio_write(temp_string); 211 | stdio_write("Press LCTRL+ENTER to continue\n"); 212 | if (stdio_get(&retval)!=0) 213 | { 214 | if (retval == K_ECR) break; 215 | } 216 | color++; 217 | } 218 | video_clrscr(); 219 | term_init(); 220 | video_gotoxy(1,7); 221 | stdio_write("Press f to format FLASH\n"); 222 | while (1) 223 | { 224 | if (stdio_get(&retval)!=0) 225 | { 226 | if (retval == 'f') 227 | { 228 | stdio_write("Formatting FLASH...\n"); 229 | if (init_first_x_sects(128,1)==0) 230 | { 231 | video_set_color(EGA_WHITE,EGA_GREEN); 232 | stdio_write("OK, verified\n"); 233 | } 234 | else 235 | { 236 | video_set_color(EGA_YELLOW,EGA_RED); 237 | stdio_write("Verification error\n"); 238 | } 239 | break; 240 | } 241 | } 242 | } 243 | video_set_color(EGA_WHITE,EGA_BLACK); 244 | stdio_write("End of test, reset badge now\n"); 245 | while(1); 246 | } 247 | 248 | 249 | void io_test_state (uint8_t state) 250 | { 251 | if (state==0) 252 | { 253 | LATCbits.LATC13 = 1; 254 | LATCbits.LATC14 = 0; 255 | LATGbits.LATG2 = 0; 256 | LATGbits.LATG3 = 0; 257 | LATBbits.LATB0 = 0; 258 | LATBbits.LATB1 = 0; 259 | } 260 | else if (state==1) 261 | { 262 | LATCbits.LATC13 = 0; 263 | LATCbits.LATC14 = 1; 264 | LATGbits.LATG2 = 0; 265 | LATGbits.LATG3 = 0; 266 | LATBbits.LATB0 = 0; 267 | LATBbits.LATB1 = 0; 268 | } 269 | else if (state==2) 270 | { 271 | LATCbits.LATC13 = 0; 272 | LATCbits.LATC14 = 0; 273 | LATGbits.LATG2 = 1; 274 | LATGbits.LATG3 = 0; 275 | LATBbits.LATB0 = 0; 276 | LATBbits.LATB1 = 0; 277 | } 278 | else if (state==3) 279 | { 280 | LATCbits.LATC13 = 0; 281 | LATCbits.LATC14 = 0; 282 | LATGbits.LATG2 = 0; 283 | LATGbits.LATG3 = 1; 284 | LATBbits.LATB0 = 0; 285 | LATBbits.LATB1 = 0; 286 | } 287 | else if (state==4) 288 | { 289 | LATCbits.LATC13 = 0; 290 | LATCbits.LATC14 = 0; 291 | LATGbits.LATG2 = 0; 292 | LATGbits.LATG3 = 0; 293 | LATBbits.LATB0 = 1; 294 | LATBbits.LATB1 = 0; 295 | } 296 | else if (state==5) 297 | { 298 | LATCbits.LATC13 = 0; 299 | LATCbits.LATC14 = 0; 300 | LATGbits.LATG2 = 0; 301 | LATGbits.LATG3 = 0; 302 | LATBbits.LATB0 = 0; 303 | LATBbits.LATB1 = 1; 304 | } 305 | else 306 | { 307 | LATCbits.LATC13 = 0; 308 | LATCbits.LATC14 = 0; 309 | LATGbits.LATG2 = 0; 310 | LATGbits.LATG3 = 0; 311 | LATBbits.LATB0 = 0; 312 | LATBbits.LATB1 = 0; 313 | } 314 | 315 | 316 | } -------------------------------------------------------------------------------- /firmware/badge1.X/src/Z80/simglb.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Z80SIM - a Z80-CPU simulator 3 | * 4 | * Copyright (C) 1987-92 by Udo Munk 5 | * 6 | * This module of the Z80-CPU simulator must not be modified by a user, 7 | * see license agreement! 8 | * 9 | * History: 10 | * 28-SEP-87 Development on TARGON/35 with AT&T Unix System V.3 11 | * 11-JAN-89 Release 1.1 12 | * 08-FEB-89 Release 1.2 13 | * 13-MAR-89 Release 1.3 14 | * 09-FEB-90 Release 1.4 Ported to TARGON/31 M10/30 15 | * 20-DEC-90 Release 1.5 Ported to COHERENT 16 | * 10-JUN-92 Release 1.6 long casting problem solved with COHERENT 3.2 17 | * and some optimization 18 | * 25-JUN-92 Release 1.7 comments in english and ported to COHERENT 4.0 19 | */ 20 | 21 | /* 22 | * This modul contains all the global variables 23 | */ 24 | #include 25 | #include "sim.h" 26 | 27 | /* 28 | * CPU-Register 29 | */ 30 | BYTE A,B,C,D,E,H,L; /* Z80 primary registers */ 31 | int F; /* normaly 8-Bit, but int is faster */ 32 | WORD IX, IY; 33 | BYTE A_,B_,C_,D_,E_,H_,L_; /* Z80 secoundary registers */ 34 | int F_; 35 | BYTE *PC; /* Z80 programm counter */ 36 | BYTE *STACK; /* Z80 stackpointer */ 37 | BYTE I; /* Z80 interrupt register */ 38 | BYTE IFF; /* Z80 interrupt flags */ 39 | long R; /* Z80 refresh register */ 40 | /* is normaly a 8 bit register */ 41 | /* the 32 bits are used to measure the */ 42 | /* clock frequency */ 43 | 44 | /* 45 | * Variables for memory of the emulated CPU 46 | */ 47 | BYTE ram[65536L]; /* 64KB for all other OS's */ 48 | BYTE *wrk_ram; /* workpointer into memory for dump etc. */ 49 | 50 | /* 51 | * Variables for breakpoint memory 52 | */ 53 | #ifdef SBSIZE 54 | struct softbreak soft[SBSIZE]; /* memory to hold breakpoint informations */ 55 | int sb_next; /* index into breakpoint memory */ 56 | #endif 57 | 58 | /* 59 | * Variables for runtime measurement 60 | */ 61 | #ifdef WANT_TIM 62 | long t_states; /* number of counted T states */ 63 | int t_flag; /* flag, 1 = on, 0 = off */ 64 | #if !defined(COHERENT) || defined(_I386) 65 | BYTE *t_start = ram + 65535; /* start address for measurement */ 66 | BYTE *t_end = ram + 65535; /* end address for measurement */ 67 | #else 68 | BYTE *t_start = ram + 32767; 69 | BYTE *t_end = ram + 32767; 70 | #endif 71 | #endif 72 | 73 | /* 74 | * Flag to controll operation of simulation 75 | */ 76 | 77 | int break_flag = 1; /* 1 = break at HALT, 0 = execute HALT */ 78 | int cpu_state; /* status of CPU emulation */ 79 | int cpu_error; /* error status of CPU emulation */ 80 | int int_type; /* type of interrupt */ 81 | int int_mode; /* CPU interrupt mode (IM 0, IM 1, IM 2) */ 82 | 83 | /* 84 | * Table to get parritys as fast as possible 85 | */ 86 | const int parrity[256] = { 87 | 0 /* 00000000 */, 1 /* 00000001 */, 1 /* 00000010 */, 88 | 0 /* 00000011 */, 1 /* 00000100 */, 0 /* 00000101 */, 89 | 0 /* 00000110 */, 1 /* 00000111 */, 1 /* 00001000 */, 90 | 0 /* 00001001 */, 0 /* 00001010 */, 1 /* 00001011 */, 91 | 0 /* 00001100 */, 1 /* 00001101 */, 1 /* 00001110 */, 92 | 0 /* 00001111 */, 1 /* 00010000 */, 0 /* 00010001 */, 93 | 0 /* 00010010 */, 1 /* 00010011 */, 0 /* 00010100 */, 94 | 1 /* 00010101 */, 1 /* 00010110 */, 0 /* 00010111 */, 95 | 0 /* 00011000 */, 1 /* 00011001 */, 1 /* 00011010 */, 96 | 0 /* 00011011 */, 1 /* 00011100 */, 0 /* 00011101 */, 97 | 0 /* 00011110 */, 1 /* 00011111 */, 1 /* 00100000 */, 98 | 0 /* 00100001 */, 0 /* 00100010 */, 1 /* 00100011 */, 99 | 0 /* 00100100 */, 1 /* 00100101 */, 1 /* 00100110 */, 100 | 0 /* 00100111 */, 0 /* 00101000 */, 1 /* 00101001 */, 101 | 1 /* 00101010 */, 0 /* 00101011 */, 1 /* 00101100 */, 102 | 0 /* 00101101 */, 0 /* 00101110 */, 1 /* 00101111 */, 103 | 0 /* 00110000 */, 1 /* 00110001 */, 1 /* 00110010 */, 104 | 0 /* 00110011 */, 1 /* 00110100 */, 0 /* 00110101 */, 105 | 0 /* 00110110 */, 1 /* 00110111 */, 1 /* 00111000 */, 106 | 0 /* 00111001 */, 0 /* 00111010 */, 1 /* 00111011 */, 107 | 0 /* 00111100 */, 1 /* 00111101 */, 1 /* 00111110 */, 108 | 0 /* 00111111 */, 1 /* 01000000 */, 0 /* 01000001 */, 109 | 0 /* 01000010 */, 1 /* 01000011 */, 0 /* 01000100 */, 110 | 1 /* 01000101 */, 1 /* 01000110 */, 0 /* 01000111 */, 111 | 0 /* 01001000 */, 1 /* 01001001 */, 1 /* 01001010 */, 112 | 0 /* 01001011 */, 1 /* 01001100 */, 0 /* 01001101 */, 113 | 0 /* 01001110 */, 1 /* 01001111 */, 0 /* 01010000 */, 114 | 1 /* 01010001 */, 1 /* 01010010 */, 0 /* 01010011 */, 115 | 1 /* 01010100 */, 0 /* 01010101 */, 0 /* 01010110 */, 116 | 1 /* 01010111 */, 1 /* 01011000 */, 0 /* 01011001 */, 117 | 0 /* 01011010 */, 1 /* 01011011 */, 0 /* 01011100 */, 118 | 1 /* 01011101 */, 1 /* 01011110 */, 0 /* 01011111 */, 119 | 0 /* 01100000 */, 1 /* 01100001 */, 1 /* 01100010 */, 120 | 0 /* 01100011 */, 1 /* 01100100 */, 0 /* 01100101 */, 121 | 0 /* 01100110 */, 1 /* 01100111 */, 1 /* 01101000 */, 122 | 0 /* 01101001 */, 0 /* 01101010 */, 1 /* 01101011 */, 123 | 0 /* 01101100 */, 1 /* 01101101 */, 1 /* 01101110 */, 124 | 0 /* 01101111 */, 1 /* 01110000 */, 0 /* 01110001 */, 125 | 0 /* 01110010 */, 1 /* 01110011 */, 0 /* 01110100 */, 126 | 1 /* 01110101 */, 1 /* 01110110 */, 0 /* 01110111 */, 127 | 0 /* 01111000 */, 1 /* 01111001 */, 1 /* 01111010 */, 128 | 0 /* 01111011 */, 1 /* 01111100 */, 0 /* 01111101 */, 129 | 0 /* 01111110 */, 1 /* 01111111 */, 130 | 1 /* 10000000 */, 0 /* 10000001 */, 0 /* 10000010 */, 131 | 1 /* 10000011 */, 0 /* 10000100 */, 1 /* 10000101 */, 132 | 1 /* 10000110 */, 0 /* 10000111 */, 0 /* 10001000 */, 133 | 1 /* 10001001 */, 1 /* 10001010 */, 0 /* 10001011 */, 134 | 1 /* 10001100 */, 0 /* 10001101 */, 0 /* 10001110 */, 135 | 1 /* 10001111 */, 0 /* 10010000 */, 1 /* 10010001 */, 136 | 1 /* 10010010 */, 0 /* 10010011 */, 1 /* 10010100 */, 137 | 0 /* 10010101 */, 0 /* 10010110 */, 1 /* 10010111 */, 138 | 1 /* 10011000 */, 0 /* 10011001 */, 0 /* 10011010 */, 139 | 1 /* 10011011 */, 0 /* 10011100 */, 1 /* 10011101 */, 140 | 1 /* 10011110 */, 0 /* 10011111 */, 0 /* 10100000 */, 141 | 1 /* 10100001 */, 1 /* 10100010 */, 0 /* 10100011 */, 142 | 1 /* 10100100 */, 0 /* 10100101 */, 0 /* 10100110 */, 143 | 1 /* 10100111 */, 1 /* 10101000 */, 0 /* 10101001 */, 144 | 0 /* 10101010 */, 1 /* 10101011 */, 0 /* 10101100 */, 145 | 1 /* 10101101 */, 1 /* 10101110 */, 0 /* 10101111 */, 146 | 1 /* 10110000 */, 0 /* 10110001 */, 0 /* 10110010 */, 147 | 1 /* 10110011 */, 0 /* 10110100 */, 1 /* 10110101 */, 148 | 1 /* 10110110 */, 0 /* 10110111 */, 0 /* 10111000 */, 149 | 1 /* 10111001 */, 1 /* 10111010 */, 0 /* 10111011 */, 150 | 1 /* 10111100 */, 0 /* 10111101 */, 0 /* 10111110 */, 151 | 1 /* 10111111 */, 0 /* 11000000 */, 1 /* 11000001 */, 152 | 1 /* 11000010 */, 0 /* 11000011 */, 1 /* 11000100 */, 153 | 0 /* 11000101 */, 0 /* 11000110 */, 1 /* 11000111 */, 154 | 1 /* 11001000 */, 0 /* 11001001 */, 0 /* 11001010 */, 155 | 1 /* 11001011 */, 0 /* 11001100 */, 1 /* 11001101 */, 156 | 1 /* 11001110 */, 0 /* 11001111 */, 1 /* 11010000 */, 157 | 0 /* 11010001 */, 0 /* 11010010 */, 1 /* 11010011 */, 158 | 0 /* 11010100 */, 1 /* 11010101 */, 1 /* 11010110 */, 159 | 0 /* 11010111 */, 0 /* 11011000 */, 1 /* 11011001 */, 160 | 1 /* 11011010 */, 0 /* 11011011 */, 1 /* 11011100 */, 161 | 0 /* 11011101 */, 0 /* 11011110 */, 1 /* 11011111 */, 162 | 1 /* 11100000 */, 0 /* 11100001 */, 0 /* 11100010 */, 163 | 1 /* 11100011 */, 0 /* 11100100 */, 1 /* 11100101 */, 164 | 1 /* 11100110 */, 0 /* 11100111 */, 0 /* 11101000 */, 165 | 1 /* 11101001 */, 1 /* 11101010 */, 0 /* 11101011 */, 166 | 1 /* 11101100 */, 0 /* 11101101 */, 0 /* 11101110 */, 167 | 1 /* 11101111 */, 0 /* 11110000 */, 1 /* 11110001 */, 168 | 1 /* 11110010 */, 0 /* 11110011 */, 1 /* 11110100 */, 169 | 0 /* 11110101 */, 0 /* 11110110 */, 1 /* 11110111 */, 170 | 1 /* 11111000 */, 0 /* 11111001 */, 0 /* 11111010 */, 171 | 1 /* 11111011 */, 0 /* 11111100 */, 1 /* 11111101 */, 172 | 1 /* 11111110 */, 0 /* 11111111 */ 173 | }; 174 | 175 | #if defined(COHERENT) && !defined(_I386) 176 | char adr_err[] = "address out of range"; 177 | #endif 178 | -------------------------------------------------------------------------------- /firmware/badge1.X/changes.txt: -------------------------------------------------------------------------------- 1 | 0.10 2 | - you can now enter new lines into the source buffer, though for now only appending at the end of program, you can't insert it in the middle - that is high in TODO list 3 | - help command - writes out help 4 | - clr command - clears program buffer, so you can write new program 5 | - first numbered revision, 0.10 now. A lot of revision numbers available up to 1.00 6 | 7 | 0.11 8 | - allow inserting new lines of code anywhere, as well as overwriting previously entered lines. 9 | 10 | 0.12 11 | - moved to github 12 | - allowed deleting line by inserting zero length line at line number 13 | - interpreter now should fail gracefully, without hard crash, error report isn't much helpful by now 14 | 15 | 0.13 16 | - a lot of new things 17 | - Z80 interpreter from Udo Munk added, along with CP/M binaries and my CP/M BIOS tailored for virtual machines like this one. I can now run CP/M on the badge. There is 50kB RAM disk and 128kB ROM disk, containing useful stuff like ED, DDT, XMODEM, UNARC or MBASIC. I can send new binaries to CP/M machine via serial port and XMODEM protocol. Optionally, those can be ARC-ed on PC and un-ARC-ed on CP/M machine. Lots of possibilities to come with this one. FLASH disks don't work by now, probably in next version. 18 | - BASIC interpreter got some more tweaks and it's now better separated from other tasks. Major cleanup/separation of sources is needed, though. 19 | - primitive menu on start, allowing to choose either BASIC interpreter or CP/M machine. 20 | 21 | 0.14 22 | - half of FLASH memory now appears as four disk drives by 512k each in CP/M system. I downloaded ZORK via XMODEM and spent a while playing it. 23 | 24 | 0.15 25 | - local display terminal is now accepting VT100 escape sequences. Turbo Pascal or Wordstar under CP/M should now run with sensible output on display, should be better for everything else, too. 26 | - fixed bug where first command after starting BASIC interpreter was be mangled, resulting in funny behavior 27 | 28 | 0.16 29 | - merged pull request from Mike 30 | - music generator, available from BASIC interpreter 31 | - had to rework timer/delay structure to allow music 32 | - todo.txt started :-) 33 | 34 | 0.17 35 | - fixed v0.12 error reports broken by v0.15 36 | - minor changes in display init to prevent flickering when resetting 37 | 38 | 0.18 39 | - fixed timer issue 40 | - added some BASIC words: termt, setxy, clrscr, wait 41 | - added binary of "TINY BASIC FOR INTEL 8080", it runs fine on Z80 emulator, modified IO routines for this one 42 | 43 | 0.19 44 | - minor changes 45 | 46 | 0.20 47 | - fixed XY printing via setxy command 48 | 49 | 0.21 50 | - fixed typos 51 | 52 | 0.22 53 | - display update should be smoother now 54 | - fixed bug where empty line in BASIC will throw error 55 | 56 | 0.23 57 | - implemented primitive power button function. sleep current isn't that much awesome by now (~1mA), I'll investigate how to decrease it. badge will return to previous state after power up 58 | 59 | 0.24 60 | - BREAK key now woks 61 | - more sensible error messages 62 | - LED word included 63 | 64 | 0.25 65 | - added load x/save x function in basic 66 | - minor fixes 67 | 68 | 0.26 69 | - fixed more BASIC crashes 70 | 71 | 0.27 72 | - the crashes are now really fixed 73 | - setxy now works in VT100 mode too 74 | 75 | 0.28 76 | - merged Mike's changes 77 | - stdio input mode (keyboard->system) changed from weird three byte long something to single characters 78 | 79 | 0.29 80 | - colors added 81 | 82 | 0.30 83 | - color palette is now 16-color EGA 84 | 85 | 0.31 86 | - sound generator is now silenced after tone command ends 87 | 88 | 0.32 89 | - rnd word added 90 | 91 | 0.33 92 | - minor rnd bug fixed 93 | 94 | 0.34 95 | - started reorganizing sources 96 | 97 | 0.35 98 | - sources should now use uint8_t type defs 99 | - bug fixes 100 | 101 | 0.36 102 | - bug fix in BASIC tokenizer 103 | 104 | 0.37 105 | - extended ASCII characters are now available from C code 106 | 107 | 0.38 108 | - added BASIC word CHR that prints one character with given ASCII value, useful for handling extended ASCII characters 109 | 110 | 0.39 111 | - fixed some Z80 emulation bugs 112 | - adjusted and recompiled Z80 BIOS to fit smaller ramdisk and second ROM disk (currently empty) 113 | 114 | 0.40 115 | - added function MORE to list basic programs in more sensible way 116 | 117 | 0.41 118 | - fixed bug in MORE function 119 | 120 | 0.42 121 | - fixed bug in interpreter and line inserting algorithm 122 | 123 | 0.43 124 | - temprarily added CP/M disk formatter 125 | 126 | 0.44 127 | - slower LCD initialization 128 | 129 | 0.45 130 | - simple hardware check, available after reset with BRK key pressed 131 | - fixed timer issue 132 | 133 | 0.46 134 | - FLASH handling in Z80 CP/M is now more robust 135 | - BRK key bug fixed 136 | 137 | 0.47 138 | - fixed line insertion algorithm 139 | - new disk C in CP/M, containing zork and sargon 140 | 141 | 0.48 142 | - fixed problem with FLASH addressing, lost one CP/M drive though 143 | - less magic numbers in sources 144 | - consoles for stdio are now switchable via LSHIFT+BRK 145 | 146 | 0.49 147 | - zork now available from badge main menu 148 | 149 | 0.50 150 | - sources restructured a bit 151 | 152 | 0.51 153 | - more configuration options 154 | 155 | 0.52 156 | - adjusted interrupt priorities to get cleaner sound 157 | 158 | 0.53 159 | - the badge has now somehow better POST test, more stuff to come 160 | 161 | 0.54 162 | - changed format of RND word usage to something more sensible 163 | - added word println 164 | - changed word print 165 | - added words to manipulate IO on expansion port 166 | 167 | 0.55 168 | - improved function output handling of print/println functions 169 | 170 | 0.56 171 | - adjusted format of RND and EIN function 172 | 173 | 0.57 174 | - added word termup 175 | 176 | 0.58 177 | - enabled display handling after returning control if termt was 0 in BASIC program 178 | 179 | 0.59 180 | - colors are restored to default after exiting BASIC program 181 | 182 | 0.60 183 | - added commands sload and ssave to load/save BASIC program via serial port 184 | 185 | 0.61 186 | - tweaks to achieve lower current consumption in sleep mode. 187 | 188 | 0.62 189 | - comments added, some sources reorganziation made 190 | 191 | 0.63 192 | - BASIC now accepts both upper and lower case words. no mixing of cases, though, so HaXxORz are out of luck 193 | 194 | 0.64 195 | - REM word added 196 | 197 | 0.65 198 | - added BASIC words uin and uout for serial port handling 199 | 200 | 0.66 201 | - POST now allows testing IO pins on expansion header and FLASH formatting for CP/M system 202 | 203 | 0.67 204 | - improved handling of backspace character in BASIC command line mode 205 | 206 | 0.68 207 | - added word for user numeric input 208 | 209 | 0.70 210 | - minor typos 211 | 212 | 0.71 213 | - program buffer increased to 16kB 214 | 215 | 0.72 216 | - clr changed to mamclr, some aliases added 217 | 218 | 0.73 219 | - a lot of reformatting 220 | - LEDs status remembered after wake from sleep 221 | 222 | 0.74 223 | - LEDs are off after POR/manual reset 224 | 225 | 0.75 226 | - restricted availability of some words in interactive mode 227 | - some more aliases 228 | 229 | 0.76 230 | - added peek and poke words 231 | 232 | 0.77 233 | - added curor, as well word to turn it on/off 234 | 235 | 0.78 236 | - holding RSHIFT while resetting the badge skips splash screen 237 | 238 | 0.79 239 | - user input bug is fixed 240 | 241 | 0.80 242 | - switching consoles now via LSHIFT+RSHIFT+BRK 243 | 244 | 0.81 245 | - using correct FLASH type 246 | 247 | 0.82 248 | - POST test performs FLASH verification 249 | 250 | 0.83 251 | - fixed bug in FLASH handling 252 | 253 | 0.84 254 | - improved help 255 | - added license 256 | 257 | 0.85 258 | - improved help 259 | 260 | 0.86 261 | - included example BASIC program 262 | 263 | 1.00 264 | - first stable release 265 | 266 | 1.01 267 | - serial access functions should be more stable now 268 | - fixed bug with long input line 269 | - fixed backspace bug 270 | 271 | 1.02 272 | - added function kin that returns value of pressed key, can be either blocking or non-blocking 273 | 274 | 1.03 275 | - BRK key was flaky at times, now it's not 276 | 277 | 1.04 278 | - fixed bug where goto to non-existing line would lock up interpreter 279 | 280 | -------------------------------------------------------------------------------- /firmware/badge1.X/src/Z80/hwz.c: -------------------------------------------------------------------------------- 1 | #include "hwz.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "sim.h" 9 | #include "simglb.h" 10 | #include "../hw.h" 11 | 12 | extern const uint8_t rom_image[65536]; 13 | extern const uint8_t rd_image[131072]; 14 | extern const uint8_t rd_image2[ROMDISK2_SIZE]; 15 | uint8_t drive, sector, track,disk_temp_pointer; 16 | uint8_t disk_temp[128],flash_buff[4096], conin_buffer[30], conin_buffer_pointer; 17 | 18 | uint32_t last_addr = 0xFFFFF000; 19 | uint8_t unwritten; 20 | 21 | uint8_t fl_rdsr(void); 22 | uint32_t fl_rdid(void); 23 | 24 | #ifdef USE_RAM_IMAGE 25 | extern const uint8_t ram_image[65536]; 26 | #endif 27 | 28 | #ifdef USE_RAMDISK 29 | uint8_t ram_disk[RAMDISK_SIZE]; 30 | #endif 31 | 32 | void reload_cpm_warm (void) 33 | { 34 | uint16_t i; 35 | #ifdef USE_RAM_IMAGE 36 | for (i=0xD400;i<(0xD400+0x1EFF);i++) ram[i] = ram_image[i]; 37 | #endif 38 | } 39 | 40 | //-------------------device at 0x68----------------- 41 | uint8_t rxm_sta (void) 42 | { 43 | /* 44 | if (U3BSTAbits.URXDA==1) return 0xFF; 45 | else return 0x00; 46 | */ 47 | } 48 | uint8_t rxm_read (void) 49 | { 50 | /* 51 | return U3BRXREG; 52 | */ 53 | } 54 | void txm_write (uint8_t data) 55 | { 56 | /* 57 | U3BTXREG = data; 58 | while (U3BSTAbits.UTXBF==1); 59 | */ 60 | } 61 | 62 | void set_drive (uint8_t dat) 63 | { 64 | drive = dat; 65 | disk_temp_pointer = 0; 66 | } 67 | void set_sector (uint8_t dat) 68 | { 69 | sector = dat; 70 | disk_temp_pointer = 0; 71 | } 72 | void set_track (uint8_t dat) 73 | { 74 | track = dat; 75 | disk_temp_pointer = 0; 76 | } 77 | 78 | uint8_t read_disk_byte (void) 79 | { 80 | uint8_t temp; 81 | uint32_t base,ptr; 82 | base = (((uint32_t )(track))*16) + sector; 83 | if (drive==0) 84 | { 85 | base = base*128; 86 | #ifdef USE_RAMDISK 87 | ptr = base + disk_temp_pointer; 88 | if (ptr>16)&0xFF); 214 | SPI_dat((addr>>8)&0xFF); 215 | SPI_dat((addr>>0)&0xFF); 216 | for (i=0;i<4096;i++) *data++ = SPI_dat(0xFF); 217 | CS_FLASH = 1; 218 | } 219 | 220 | void fl_read_nk(uint32_t addr, uint8_t * data, uint16_t n) 221 | { 222 | uint16_t i; 223 | CS_FLASH = 0; 224 | SPI_dat(0x03); 225 | SPI_dat((addr>>16)&0xFF); 226 | SPI_dat((addr>>8)&0xFF); 227 | SPI_dat((addr>>0)&0xFF); 228 | for (i=0;i>16)&0xFF); 240 | SPI_dat((addr>>8)&0xFF); 241 | SPI_dat((addr>>0)&0xFF); 242 | CS_FLASH = 1; 243 | while ((fl_rdsr())&0x01); 244 | } 245 | 246 | 247 | void fl_write(uint32_t addr,uint8_t data) 248 | { 249 | uint16_t i; 250 | fl_wren(); 251 | CS_FLASH = 0; 252 | SPI_dat(0x02); 253 | SPI_dat((addr>>16)&0xFF); 254 | SPI_dat((addr>>8)&0xFF); 255 | SPI_dat((addr>>0)&0xFF); 256 | SPI_dat(data); 257 | CS_FLASH = 1; 258 | } 259 | 260 | void fl_rst_pb(void) 261 | { 262 | /* 263 | CS_FLASH = 0; 264 | SPI_dat(0x50); 265 | CS_FLASH = 1; 266 | */ 267 | fl_wren(); 268 | CS_FLASH = 0; 269 | SPI_dat(0x01); 270 | SPI_dat(0x00); 271 | CS_FLASH = 1; 272 | } 273 | 274 | void fl_wren(void) 275 | { 276 | CS_FLASH = 0; 277 | SPI_dat(0x06); 278 | CS_FLASH = 1; 279 | } 280 | 281 | 282 | void fl_write_4k(uint32_t addr, uint8_t * data) 283 | { 284 | uint16_t i; 285 | for (i=0;i<4096;i++) 286 | { 287 | fl_write(addr+i,*data++); 288 | while ((fl_rdsr())&0x01); 289 | } 290 | } 291 | 292 | void fl_write_128(uint32_t sector,uint8_t * data) 293 | { 294 | uint32_t addr; 295 | uint8_t i; 296 | addr = ((uint32_t )(sector))*128UL; 297 | addr = addr&0xFFFFF000; 298 | #ifdef FLASH_BUFFERING 299 | if (last_addr!=addr) 300 | { 301 | if (last_addr!=0xFFFFF000) 302 | { 303 | fl_erase_4k(last_addr); 304 | fl_write_4k(last_addr,flash_buff); 305 | } 306 | fl_read_4k(addr,flash_buff); 307 | last_addr = addr; 308 | } 309 | unwritten = 1; 310 | #endif 311 | #ifndef FLASH_BUFFERING 312 | fl_read_4k(addr,flash_buff); 313 | #endif 314 | addr = ((uint32_t )(sector))*128UL; 315 | addr = addr&0x00000FFF; 316 | for (i=0;i<128;i++) flash_buff[addr+i] = data[i]; 317 | addr = ((uint32_t )(sector))*128UL; 318 | addr = addr&0xFFFFF000; 319 | #ifndef FLASH_BUFFERING 320 | fl_erase_4k(addr); 321 | fl_write_4k(addr,flash_buff); 322 | #endif 323 | } 324 | 325 | void fl_read_128(uint32_t sector,uint8_t * data) 326 | { 327 | uint32_t addr; 328 | #ifdef FLASH_BUFFERING 329 | if (unwritten == 1) 330 | { 331 | fl_erase_4k(last_addr); 332 | fl_write_4k(last_addr,flash_buff); 333 | unwritten = 0; 334 | last_addr = 0xFFFFF000; 335 | } 336 | #endif 337 | addr = ((uint32_t )(sector))*128UL; 338 | fl_read_nk(addr,data,128); 339 | } 340 | 341 | uint8_t init_first_x_sects (uint8_t i, uint8_t verify) //format directory area 342 | { 343 | uint32_t j,k; 344 | for (j=0;j<128;j++) disk_temp[j]=0xE5; 345 | #ifdef USE_EEPROM 346 | for (j=0;j>9); 383 | SPI_dat(temp); 384 | temp = (addr>>1); 385 | SPI_dat(temp); 386 | temp = (addr<<7); 387 | SPI_dat(temp); 388 | 389 | for (i=0;i<128;i++) 390 | SPI_dat(data[i]); 391 | 392 | CS_MEM = 1; 393 | temp = ee_rs(); 394 | temp = temp&0x01; 395 | 396 | while (temp>0) 397 | { 398 | temp = ee_rs(); 399 | temp = temp&0x01; 400 | } 401 | } 402 | 403 | void read_sector (unsigned char *data, unsigned int addr) 404 | { 405 | unsigned char i,temp; 406 | CS_MEM = 0; 407 | SPI_dat(0x03); 408 | temp = (addr>>9); 409 | SPI_dat(temp); 410 | temp = (addr>>1); 411 | SPI_dat(temp); 412 | temp = (addr<<7); 413 | SPI_dat(temp); 414 | 415 | 416 | for (i=0;i<128;i++) 417 | { 418 | *data = SPI_dat(0xFF); 419 | *data++; 420 | } 421 | 422 | CS_MEM = 1; 423 | } 424 | unsigned char ee_rs (void) 425 | { 426 | unsigned char temp; 427 | CS_MEM = 0; 428 | SPI_dat(0x05); 429 | temp = SPI_dat(0xFF); 430 | CS_MEM = 1; 431 | return temp; 432 | } 433 | 434 | void ee_wren (void) 435 | { 436 | CS_MEM = 0; 437 | SPI_dat(0x06); 438 | CS_MEM = 1; 439 | } 440 | 441 | void ee_wrdi (void) 442 | { 443 | CS_MEM = 0; 444 | SPI_dat(0x04); 445 | CS_MEM = 1; 446 | } 447 | 448 | #endif -------------------------------------------------------------------------------- /firmware/badge1.X/src/basic/tokenizer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006, Adam Dunkels 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. Neither the name of the author nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | */ 30 | 31 | #define DEBUG 0 32 | 33 | #if DEBUG 34 | #define DEBUG_PRINTF(...) printf(__VA_ARGS__) 35 | #else 36 | #define DEBUG_PRINTF(...) 37 | #endif 38 | 39 | #include "tokenizer.h" 40 | #include 41 | #include 42 | #include 43 | 44 | static char const *ptr, *nextptr; 45 | 46 | #define MAX_NUMLEN 6 47 | 48 | struct keyword_token 49 | { 50 | char *keyword; 51 | int token; 52 | }; 53 | 54 | static int current_token = TOKENIZER_ERROR; 55 | 56 | //B_BAS001 - list of tokens 57 | static const struct keyword_token keywords[] = 58 | { 59 | {"let", TOKENIZER_LET}, 60 | {"print", TOKENIZER_PRINT}, 61 | {"println", TOKENIZER_PRINTLN}, 62 | {"if", TOKENIZER_IF}, 63 | {"then", TOKENIZER_THEN}, 64 | {"else", TOKENIZER_ELSE}, 65 | {"for", TOKENIZER_FOR}, 66 | {"to", TOKENIZER_TO}, 67 | {"next", TOKENIZER_NEXT}, 68 | {"goto", TOKENIZER_GOTO}, 69 | {"gosub", TOKENIZER_GOSUB}, 70 | {"return", TOKENIZER_RETURN}, 71 | {"call", TOKENIZER_CALL}, 72 | {"end", TOKENIZER_END}, 73 | {"out", TOKENIZER_OUT}, 74 | {"tune", TOKENIZER_TUNE}, 75 | {"termt", TOKENIZER_TERMT}, 76 | {"setxy", TOKENIZER_SETXY}, 77 | {"clrscr", TOKENIZER_CLRSCR}, 78 | {"wait", TOKENIZER_WAIT}, 79 | {"led", TOKENIZER_LED}, 80 | {"color", TOKENIZER_COLOR}, 81 | {"rnd", TOKENIZER_RND}, 82 | {"chr", TOKENIZER_CHR}, 83 | {"ein", TOKENIZER_EIN}, 84 | {"eout", TOKENIZER_EOUT}, 85 | {"edr", TOKENIZER_EDR}, 86 | {"termup", TOKENIZER_TERMUP}, 87 | {"LET", TOKENIZER_LET}, 88 | {"PRINT", TOKENIZER_PRINT}, 89 | {"PRINTLN", TOKENIZER_PRINTLN}, 90 | {"IF", TOKENIZER_IF}, 91 | {"THEN", TOKENIZER_THEN}, 92 | {"ELSE", TOKENIZER_ELSE}, 93 | {"FOR", TOKENIZER_FOR}, 94 | {"TO", TOKENIZER_TO}, 95 | {"NEXT", TOKENIZER_NEXT}, 96 | {"GOTO", TOKENIZER_GOTO}, 97 | {"GOSUB", TOKENIZER_GOSUB}, 98 | {"RETURN", TOKENIZER_RETURN}, 99 | {"CALL", TOKENIZER_CALL}, 100 | {"END", TOKENIZER_END}, 101 | {"OUT", TOKENIZER_OUT}, 102 | {"TUNE", TOKENIZER_TUNE}, 103 | {"TERMT", TOKENIZER_TERMT}, 104 | {"SETXY", TOKENIZER_SETXY}, 105 | {"CLRSCR", TOKENIZER_CLRSCR}, 106 | {"WAIT", TOKENIZER_WAIT}, 107 | {"LED", TOKENIZER_LED}, 108 | {"COLOR", TOKENIZER_COLOR}, 109 | {"RND", TOKENIZER_RND}, 110 | {"CHR", TOKENIZER_CHR}, 111 | {"EIN", TOKENIZER_EIN}, 112 | {"EOUT", TOKENIZER_EOUT}, 113 | {"EDR", TOKENIZER_EDR}, 114 | {"TERMUP", TOKENIZER_TERMUP}, 115 | {"rem", TOKENIZER_REM}, 116 | {"REM", TOKENIZER_REM}, 117 | {"uin", TOKENIZER_UIN}, 118 | {"UIN", TOKENIZER_UIN}, 119 | {"uout", TOKENIZER_UOUT}, 120 | {"UOUT", TOKENIZER_UOUT}, 121 | {"input", TOKENIZER_INPUT}, 122 | {"INPUT", TOKENIZER_INPUT}, 123 | {"peek", TOKENIZER_PEEK}, 124 | {"PEEK", TOKENIZER_PEEK}, 125 | {"poke", TOKENIZER_POKE}, 126 | {"POKE", TOKENIZER_POKE}, 127 | {"cursor", TOKENIZER_CURSOR}, 128 | {"CURSOR", TOKENIZER_CURSOR}, 129 | {"KIN", TOKENIZER_KIN}, 130 | {"kin", TOKENIZER_KIN}, 131 | //aliases 132 | {"clr", TOKENIZER_CLRSCR}, 133 | {"CLR", TOKENIZER_CLRSCR}, 134 | {"cls", TOKENIZER_CLRSCR}, 135 | {"CLS", TOKENIZER_CLRSCR}, 136 | {"pnt", TOKENIZER_PRINT}, 137 | {"PNT", TOKENIZER_PRINT}, 138 | {"ptl", TOKENIZER_PRINTLN}, 139 | {"Ptl", TOKENIZER_PRINTLN}, 140 | {"inp", TOKENIZER_INPUT}, 141 | {"INP", TOKENIZER_INPUT}, 142 | {"sxy", TOKENIZER_SETXY}, 143 | {"SXY", TOKENIZER_SETXY}, 144 | {"ret", TOKENIZER_RETURN}, 145 | {"RET", TOKENIZER_RETURN}, 146 | {"cur", TOKENIZER_CURSOR}, 147 | {"CUR", TOKENIZER_CURSOR}, 148 | {NULL, TOKENIZER_ERROR} 149 | }; 150 | 151 | /*---------------------------------------------------------------------------*/ 152 | static int 153 | singlechar(void) 154 | { 155 | if(*ptr == '\n') 156 | { 157 | return TOKENIZER_CR; 158 | } 159 | else if(*ptr == '\r') 160 | { 161 | *ptr++; 162 | return TOKENIZER_CR; 163 | } 164 | else if(*ptr == ',') 165 | { 166 | return TOKENIZER_COMMA; 167 | } 168 | else if(*ptr == ';') 169 | { 170 | return TOKENIZER_SEMICOLON; 171 | } 172 | else if(*ptr == '+') 173 | { 174 | return TOKENIZER_PLUS; 175 | } 176 | else if(*ptr == '-') 177 | { 178 | return TOKENIZER_MINUS; 179 | } 180 | else if(*ptr == '&') 181 | { 182 | return TOKENIZER_AND; 183 | } 184 | else if(*ptr == '|') 185 | { 186 | return TOKENIZER_OR; 187 | } 188 | else if(*ptr == '*') 189 | { 190 | return TOKENIZER_ASTR; 191 | } 192 | else if(*ptr == '/') 193 | { 194 | return TOKENIZER_SLASH; 195 | } 196 | else if(*ptr == '%') 197 | { 198 | return TOKENIZER_MOD; 199 | } 200 | else if(*ptr == '(') 201 | { 202 | return TOKENIZER_LEFTPAREN; 203 | } 204 | else if(*ptr == ')') 205 | { 206 | return TOKENIZER_RIGHTPAREN; 207 | } 208 | else if(*ptr == '<') 209 | { 210 | return TOKENIZER_LT; 211 | } 212 | else if(*ptr == '>') 213 | { 214 | return TOKENIZER_GT; 215 | } 216 | else if(*ptr == '=') 217 | { 218 | return TOKENIZER_EQ; 219 | } 220 | return 0; 221 | } 222 | /*---------------------------------------------------------------------------*/ 223 | static int 224 | get_next_token(void) 225 | { 226 | struct keyword_token const *kt; 227 | char token_string[20]; 228 | int i; 229 | char *ptr2; 230 | 231 | strncpy(token_string,ptr,sizeof(token_string)); 232 | ptr2 = strchr(token_string, ' '); 233 | if (ptr2!=0) *ptr2 = 0; 234 | ptr2 = strchr(token_string, '\n'); 235 | if (ptr2!=0) *ptr2 = 0; 236 | DEBUG_PRINTF("get_next_token(): '%s'\n", ptr); 237 | 238 | if(*ptr == 0) 239 | { 240 | return TOKENIZER_ENDOFINPUT; 241 | } 242 | 243 | if(isdigit(*ptr)) 244 | { 245 | for(i = 0; i < MAX_NUMLEN; ++i) 246 | { 247 | if(!isdigit(ptr[i])) 248 | { 249 | if(i > 0) 250 | { 251 | nextptr = ptr + i; 252 | return TOKENIZER_NUMBER; 253 | } 254 | else 255 | { 256 | DEBUG_PRINTF("get_next_token: error due to too short number\n"); 257 | return TOKENIZER_ERROR; 258 | } 259 | } 260 | if(!isdigit(ptr[i])) 261 | { 262 | DEBUG_PRINTF("get_next_token: error due to malformed number\n"); 263 | return TOKENIZER_ERROR; 264 | } 265 | } 266 | DEBUG_PRINTF("get_next_token: error due to too long number\n"); 267 | return TOKENIZER_ERROR; 268 | } 269 | else if(singlechar()) 270 | { 271 | nextptr = ptr + 1; 272 | return singlechar(); 273 | } 274 | else if(*ptr == '"') 275 | { 276 | nextptr = ptr; 277 | do 278 | { 279 | ++nextptr; 280 | } 281 | while(*nextptr != '"'); 282 | ++nextptr; 283 | return TOKENIZER_STRING; 284 | } 285 | else 286 | { 287 | for(kt = keywords; kt->keyword != NULL; ++kt) 288 | { 289 | if(strncmp(token_string, kt->keyword, strlen(token_string)) == 0) 290 | { 291 | if (strlen(token_string)==strlen(kt->keyword)) 292 | { 293 | nextptr = ptr + strlen(kt->keyword); 294 | return kt->token; 295 | } 296 | } 297 | } 298 | } 299 | 300 | if((*ptr >= 'a' && *ptr <= 'z')|(*ptr >= 'A' && *ptr <= 'Z')) 301 | { 302 | nextptr = ptr + 1; 303 | return TOKENIZER_VARIABLE; 304 | } 305 | nextptr = ptr + 1; 306 | 307 | return TOKENIZER_ERROR; 308 | } 309 | /*---------------------------------------------------------------------------*/ 310 | void 311 | tokenizer_init(const char *program) 312 | { 313 | ptr = program; 314 | current_token = get_next_token(); 315 | } 316 | /*---------------------------------------------------------------------------*/ 317 | int 318 | tokenizer_token(void) 319 | { 320 | return current_token; 321 | } 322 | /*---------------------------------------------------------------------------*/ 323 | void 324 | tokenizer_next(void) 325 | { 326 | 327 | if(tokenizer_finished()) 328 | { 329 | return; 330 | } 331 | 332 | DEBUG_PRINTF("tokenizer_next: %p\n", nextptr); 333 | ptr = nextptr; 334 | while(*ptr == ' ') 335 | { 336 | ++ptr; 337 | } 338 | current_token = get_next_token(); 339 | DEBUG_PRINTF("tokenizer_next: '%s' %d\n", ptr, current_token); 340 | return; 341 | } 342 | /*---------------------------------------------------------------------------*/ 343 | int 344 | tokenizer_num(void) 345 | { 346 | return atoi(ptr); 347 | } 348 | /*---------------------------------------------------------------------------*/ 349 | void 350 | tokenizer_string(char *dest, int len) 351 | { 352 | char *string_end; 353 | int string_len; 354 | 355 | if(tokenizer_token() != TOKENIZER_STRING) 356 | { 357 | return; 358 | } 359 | string_end = strchr(ptr + 1, '"'); 360 | if(string_end == NULL) 361 | { 362 | return; 363 | } 364 | string_len = string_end - ptr - 1; 365 | if(len < string_len) 366 | { 367 | string_len = len; 368 | } 369 | memcpy(dest, ptr + 1, string_len); 370 | dest[string_len] = 0; 371 | } 372 | /*---------------------------------------------------------------------------*/ 373 | void 374 | tokenizer_error_print(void) 375 | { 376 | DEBUG_PRINTF("tokenizer_error_print: '%s'\n", ptr); 377 | } 378 | /*---------------------------------------------------------------------------*/ 379 | int 380 | tokenizer_finished(void) 381 | { 382 | return *ptr == 0 || current_token == TOKENIZER_ENDOFINPUT; 383 | } 384 | /*---------------------------------------------------------------------------*/ 385 | int 386 | tokenizer_variable_num(void) 387 | { 388 | if (*ptr >= 'a' && *ptr <= 'z') return *ptr - 'a'; 389 | else return *ptr - 'A'; 390 | } 391 | /*---------------------------------------------------------------------------*/ 392 | -------------------------------------------------------------------------------- /firmware/badge1.X/src/snake.c: -------------------------------------------------------------------------------- 1 | #include "snake.h" 2 | #include "hw.h" 3 | #include "disp.h" 4 | #include 5 | 6 | #define BACKGROUND white 7 | #define FOREGROUND blue 8 | #define GAME_OVER_FONT_COLOR red 9 | #define GAME_OVER_BD_COLOR BACKGROUND 10 | #define FRUIT_COLOR red 11 | 12 | #define SNAKE_DEFAULT_DELAY 100 13 | 14 | #define SNAKE_GIRTH 8 15 | #define MAX_NODES 400 16 | #define GAMEBOARD_X (PAGE_SIZE+1)/SNAKE_GIRTH 17 | #define GAMEBOARD_Y (ROW_SIZE+1)/SNAKE_GIRTH 18 | 19 | #define PAGE_SIZE 320 20 | #define ROW_SIZE 240 21 | 22 | #define red 0x00FF0000 23 | #define yellow 0x00FFFFFF 24 | #define green 0x0000FF00 25 | #define cyan 0x00FFFFFF 26 | #define blue 0x000000FF 27 | #define magenta 0x00FFFFFF 28 | #define white 0x00FFFFFF 29 | #define black 0x00000000 30 | 31 | uint8_t game_running = 0; 32 | //uint8_t font_cursor_x = 15; 33 | //uint8_t font_cursor_y = 40; 34 | uint16_t tail; 35 | uint16_t head; 36 | uint16_t snake_length_limit; 37 | uint16_t snake_length_current; 38 | 39 | typedef struct { 40 | uint16_t x; 41 | uint8_t y; 42 | } point; 43 | 44 | point corners[MAX_NODES]; 45 | int8_t dirY; 46 | int8_t dirX; 47 | point fruit; 48 | uint8_t change_dir; 49 | 50 | //Variables 51 | uint32_t TimingDelay; 52 | uint8_t move_tick = 0; 53 | 54 | //Prototypes 55 | uint16_t get_next_node(uint16_t thisNode); 56 | uint16_t get_previous_node(uint16_t thisNode); 57 | uint16_t get_node_list_length(uint16_t node1, uint16_t node2); 58 | uint8_t collision(point target); 59 | void Draw_Box(uint16_t upperX, uint8_t upperY, uint16_t lowerX, uint8_t lowerY, uint32_t color); 60 | 61 | void Draw_Box(uint16_t upperX, uint8_t upperY, uint16_t lowerX, uint8_t lowerY, uint32_t color) 62 | { 63 | tft_fill_area(upperX, upperY, lowerX-upperX, lowerY-upperY, color); 64 | } 65 | 66 | void Write_String(const int8_t * buf, uint16_t x_pixel, uint8_t y_pixel, uint32_t fgcolor, uint32_t bgcolor) 67 | { 68 | uint8_t i=0; 69 | while (buf[i] != 0) 70 | { 71 | tft_print_char(buf[i],x_pixel+(i*8),y_pixel,fgcolor,bgcolor); 72 | ++i; 73 | } 74 | } 75 | 76 | void change_direction(void) 77 | { 78 | switch (change_dir) 79 | { 80 | case 1: 81 | dirX = -1; 82 | dirY = 0; 83 | break; 84 | case 2: 85 | dirX = 0; 86 | dirY = -1; 87 | break; 88 | case 3: 89 | dirX = 1; 90 | dirY = 0; 91 | break; 92 | case 4: 93 | dirX = 0; 94 | dirY = 1; 95 | break; 96 | } 97 | change_dir = 0; 98 | } 99 | 100 | uint8_t absolute_difference(uint8_t a, uint8_t b) 101 | { 102 | int16_t unknown = (int16_t)a - b; 103 | return (uint8_t)(unknown<0?0-unknown:unknown); 104 | } 105 | 106 | uint8_t neighbors(point node1, point node2) 107 | { 108 | if ((absolute_difference(node1.x,node2.x) == 1) || (absolute_difference(node1.y,node2.y) == 1)) return 1; 109 | return 0; 110 | } 111 | 112 | void make_fruit(void) 113 | { 114 | while(1) 115 | { 116 | fruit.x = (uint8_t)(rand()%(GAMEBOARD_X)); 117 | fruit.y = (uint8_t)(rand()%(GAMEBOARD_Y)); 118 | if (collision(fruit) == 0) break; 119 | } 120 | //TODO: Make sure fruit isn't overlapping the snake. 121 | Draw_Box(fruit.x*SNAKE_GIRTH,fruit.y*SNAKE_GIRTH,(fruit.x*SNAKE_GIRTH)+SNAKE_GIRTH-1,(fruit.y*SNAKE_GIRTH)+SNAKE_GIRTH-1,FRUIT_COLOR); 122 | } 123 | 124 | uint8_t ate_fruit(uint8_t x, uint8_t y) 125 | { 126 | if ((fruit.x == x) && (fruit.y == y)) return 1; 127 | return 0; 128 | } 129 | 130 | void game_over(void) 131 | { 132 | Write_String("GAME OVER",120,120,black,white); 133 | game_running = 0; 134 | } 135 | 136 | void move_head(uint8_t new_dir) 137 | { 138 | if (new_dir) 139 | { 140 | //Copy head to new position 141 | head = get_next_node(head); //increment head 142 | corners[head].x = corners[get_previous_node(head)].x; 143 | corners[head].y = corners[get_previous_node(head)].y; 144 | change_direction(); //change direction 145 | } 146 | 147 | //Have we left the game board? 148 | if ((corners[head].x == 0) && (dirX == -1)) { game_over(); return; } 149 | if ((corners[head].y == 0) && (dirY == -1)) { game_over(); return; } 150 | if ((corners[head].x == GAMEBOARD_X-1) && (dirX == 1)) { game_over(); return; } 151 | if ((corners[head].y == GAMEBOARD_Y-1) && (dirY == 1)) { game_over(); return; } 152 | corners[head].x += dirX; 153 | corners[head].y += dirY; 154 | ++snake_length_current; 155 | } 156 | 157 | void follow_tail(void) 158 | { 159 | --snake_length_current; 160 | //is tail a neighbor of next? 161 | if (neighbors(corners[tail],corners[get_next_node(tail)])) 162 | { 163 | tail = get_next_node(tail); 164 | } 165 | 166 | //find which axis tail and next have in common 167 | else 168 | { 169 | if (corners[tail].x == corners[get_next_node(tail)].x) 170 | { 171 | //These points have the same X, so make adjustment to the Y 172 | if ((corners[tail].y - corners[get_next_node(tail)].y) < 0) corners[tail].y += 1; 173 | else corners[tail].y -= 1; 174 | } 175 | else 176 | { 177 | //These points have the same Y, so make adjustment to the X 178 | if ((corners[tail].x - corners[get_next_node(tail)].x) < 0) corners[tail].x += 1; 179 | else corners[tail].x -= 1; 180 | } 181 | } 182 | } 183 | 184 | uint8_t collision(point target) 185 | { 186 | uint16_t lower = 0; 187 | uint16_t upper = 0; 188 | uint16_t testpoint = 1; 189 | uint16_t i=tail; 190 | uint16_t nextNode = get_next_node(i);; 191 | 192 | //Check to see if we hit part of the snake 193 | //traverse all nodes from tail forward 194 | int16_t count; 195 | for (count=get_node_list_length(tail,head)-3; count>0; count--) 196 | //while (nextNodeVAL); 241 | TimingDelay = millis() + SNAKE_DEFAULT_DELAY; 242 | make_fruit(); 243 | game_running = 1; 244 | } 245 | 246 | /*-------------------------------------------------------------------------- 247 | FUNC: 7/11/12 - Gets index of next node in a ring buffer array 248 | PARAMS: Current index 249 | RETURNS: Next index (will go 'around the bend' if necessary) 250 | NOTE: Depends on the constant MAX_NODES which defines size of array 251 | --------------------------------------------------------------------------*/ 252 | uint16_t get_next_node(uint16_t thisNode) 253 | { 254 | uint16_t nextNode = thisNode + 1; 255 | if (nextNode >= MAX_NODES) nextNode = 0; 256 | return nextNode; 257 | } 258 | 259 | /*-------------------------------------------------------------------------- 260 | FUNC: 7/11/12 - Gets index of previous node in a ring buffer array 261 | PARAMS: Current index 262 | RETURNS: Previous index (will go 'around the bend' if necessary) 263 | NOTE: Depends on the constant MAX_NODES which defines size of array 264 | --------------------------------------------------------------------------*/ 265 | uint16_t get_previous_node(uint16_t thisNode) 266 | { 267 | if (thisNode) return thisNode-1; // thisNode is not zero so just decrement 268 | return MAX_NODES-1; //thisNode is zero so go around the bend 269 | } 270 | 271 | /*-------------------------------------------------------------------------- 272 | FUNC: 7/11/12 - Finds length in ring buffer from one node to the next 273 | PARAMS: Index of first node, Index of second node 274 | RETURNS: Total number of nodes (inclusive) 275 | NOTE: Depends on the constant MAX_NODES which defines size of array 276 | will go 'around the bend' if necessary 277 | --------------------------------------------------------------------------*/ 278 | uint16_t get_node_list_length(uint16_t node1, uint16_t node2) 279 | { 280 | if (node1 == node2) return 1; 281 | if (node1 < node2) return (node2-node1)+1; //Adding 1 to adjust for 0 index 282 | else return node2+(MAX_NODES-node1)+1; //Adding 1 to adjust for 0 index 283 | } 284 | 285 | int play_snake(void) 286 | { 287 | snake_init(); 288 | while(1) 289 | { 290 | if (millis() > TimingDelay) 291 | { 292 | TimingDelay = millis() + SNAKE_DEFAULT_DELAY; 293 | ++move_tick; 294 | } 295 | if (move_tick) 296 | { 297 | 298 | move_head(change_dir); 299 | 300 | if (collision(corners[head])) game_over(); 301 | else 302 | { 303 | Draw_Box(corners[head].x*SNAKE_GIRTH,corners[head].y*SNAKE_GIRTH,(corners[head].x*SNAKE_GIRTH)+SNAKE_GIRTH-1,(corners[head].y*SNAKE_GIRTH)+SNAKE_GIRTH-1,FOREGROUND); //Redraw 304 | if (snake_length_current > snake_length_limit) 305 | { 306 | 307 | Draw_Box(corners[tail].x*SNAKE_GIRTH,corners[tail].y*SNAKE_GIRTH,(corners[tail].x*SNAKE_GIRTH)+SNAKE_GIRTH-1,(corners[tail].y*SNAKE_GIRTH)+SNAKE_GIRTH-1,BACKGROUND); //Erase 308 | follow_tail(); 309 | } 310 | } 311 | if (ate_fruit(corners[head].x,corners[head].y)) 312 | { 313 | snake_length_limit += (snake_length_limit/10); 314 | make_fruit(); 315 | } 316 | move_tick = 0; 317 | } 318 | int8_t sstr[3]; 319 | uint8_t get_stat; 320 | if (game_running) 321 | { 322 | get_stat = stdio_get(sstr); 323 | if (get_stat!=0) 324 | { 325 | if ((sstr[0]==K_LT) && (dirX == 0)) change_dir = 1; // Left 326 | if ((sstr[0]==K_UP) && (dirY == 0)) change_dir = 2; // Up 327 | if ((sstr[0]==K_RT) && (dirX == 0)) change_dir = 3; // Right 328 | if ((sstr[0]==K_DN) && (dirY == 0)) change_dir = 4; // Down 329 | } 330 | } 331 | else 332 | { 333 | while (stdio_get(sstr) == 0) { ;; } 334 | snake_init(); 335 | } 336 | } 337 | } -------------------------------------------------------------------------------- /firmware/badge_alternative.X/nbproject/Makefile-default.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Generated Makefile - do not edit! 3 | # 4 | # Edit the Makefile in the project folder instead (../Makefile). Each target 5 | # has a -pre and a -post target defined where you can add customized code. 6 | # 7 | # This makefile implements configuration specific macros and targets. 8 | 9 | 10 | # Include project Makefile 11 | ifeq "${IGNORE_LOCAL}" "TRUE" 12 | # do not include local makefile. User is passing all local related variables already 13 | else 14 | include Makefile 15 | # Include makefile containing local settings 16 | ifeq "$(wildcard nbproject/Makefile-local-default.mk)" "nbproject/Makefile-local-default.mk" 17 | include nbproject/Makefile-local-default.mk 18 | endif 19 | endif 20 | 21 | # Environment 22 | MKDIR=mkdir -p 23 | RM=rm -f 24 | MV=mv 25 | CP=cp 26 | 27 | # Macros 28 | CND_CONF=default 29 | ifeq ($(TYPE_IMAGE), DEBUG_RUN) 30 | IMAGE_TYPE=debug 31 | OUTPUT_SUFFIX=elf 32 | DEBUGGABLE_SUFFIX=elf 33 | FINAL_IMAGE=dist/${CND_CONF}/${IMAGE_TYPE}/badge_alternative.X.${IMAGE_TYPE}.${OUTPUT_SUFFIX} 34 | else 35 | IMAGE_TYPE=production 36 | OUTPUT_SUFFIX=hex 37 | DEBUGGABLE_SUFFIX=elf 38 | FINAL_IMAGE=dist/${CND_CONF}/${IMAGE_TYPE}/badge_alternative.X.${IMAGE_TYPE}.${OUTPUT_SUFFIX} 39 | endif 40 | 41 | ifeq ($(COMPARE_BUILD), true) 42 | COMPARISON_BUILD=-mafrlcsj 43 | else 44 | COMPARISON_BUILD= 45 | endif 46 | 47 | ifdef SUB_IMAGE_ADDRESS 48 | 49 | else 50 | SUB_IMAGE_ADDRESS_COMMAND= 51 | endif 52 | 53 | # Object Directory 54 | OBJECTDIR=build/${CND_CONF}/${IMAGE_TYPE} 55 | 56 | # Distribution Directory 57 | DISTDIR=dist/${CND_CONF}/${IMAGE_TYPE} 58 | 59 | # Source Files Quoted if spaced 60 | SOURCEFILES_QUOTED_IF_SPACED=src/badge.c src/disp.c src/hw.c src/main.c src/vt100.c 61 | 62 | # Object Files Quoted if spaced 63 | OBJECTFILES_QUOTED_IF_SPACED=${OBJECTDIR}/src/badge.o ${OBJECTDIR}/src/disp.o ${OBJECTDIR}/src/hw.o ${OBJECTDIR}/src/main.o ${OBJECTDIR}/src/vt100.o 64 | POSSIBLE_DEPFILES=${OBJECTDIR}/src/badge.o.d ${OBJECTDIR}/src/disp.o.d ${OBJECTDIR}/src/hw.o.d ${OBJECTDIR}/src/main.o.d ${OBJECTDIR}/src/vt100.o.d 65 | 66 | # Object Files 67 | OBJECTFILES=${OBJECTDIR}/src/badge.o ${OBJECTDIR}/src/disp.o ${OBJECTDIR}/src/hw.o ${OBJECTDIR}/src/main.o ${OBJECTDIR}/src/vt100.o 68 | 69 | # Source Files 70 | SOURCEFILES=src/badge.c src/disp.c src/hw.c src/main.c src/vt100.c 71 | 72 | 73 | CFLAGS= 74 | ASFLAGS= 75 | LDLIBSOPTIONS= 76 | 77 | ############# Tool locations ########################################## 78 | # If you copy a project from one host to another, the path where the # 79 | # compiler is installed may be different. # 80 | # If you open this project with MPLAB X in the new host, this # 81 | # makefile will be regenerated and the paths will be corrected. # 82 | ####################################################################### 83 | # fixDeps replaces a bunch of sed/cat/printf statements that slow down the build 84 | FIXDEPS=fixDeps 85 | 86 | .build-conf: ${BUILD_SUBPROJECTS} 87 | ifneq ($(INFORMATION_MESSAGE), ) 88 | @echo $(INFORMATION_MESSAGE) 89 | endif 90 | ${MAKE} -f nbproject/Makefile-default.mk dist/${CND_CONF}/${IMAGE_TYPE}/badge_alternative.X.${IMAGE_TYPE}.${OUTPUT_SUFFIX} 91 | 92 | MP_PROCESSOR_OPTION=32MX370F512H 93 | MP_LINKER_FILE_OPTION= 94 | # ------------------------------------------------------------------------------------ 95 | # Rules for buildStep: assemble 96 | ifeq ($(TYPE_IMAGE), DEBUG_RUN) 97 | else 98 | endif 99 | 100 | # ------------------------------------------------------------------------------------ 101 | # Rules for buildStep: assembleWithPreprocess 102 | ifeq ($(TYPE_IMAGE), DEBUG_RUN) 103 | else 104 | endif 105 | 106 | # ------------------------------------------------------------------------------------ 107 | # Rules for buildStep: compile 108 | ifeq ($(TYPE_IMAGE), DEBUG_RUN) 109 | ${OBJECTDIR}/src/badge.o: src/badge.c nbproject/Makefile-${CND_CONF}.mk 110 | @${MKDIR} "${OBJECTDIR}/src" 111 | @${RM} ${OBJECTDIR}/src/badge.o.d 112 | @${RM} ${OBJECTDIR}/src/badge.o 113 | @${FIXDEPS} "${OBJECTDIR}/src/badge.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -D__DEBUG -DPK4Tool=1 -fframe-base-loclist -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -O1 -funroll-loops -D_SUPPRESS_PLIB_WARNING -MMD -MF "${OBJECTDIR}/src/badge.o.d" -o ${OBJECTDIR}/src/badge.o src/badge.c -DXPRJ_default=$(CND_CONF) -legacy-libc $(COMPARISON_BUILD) 114 | 115 | ${OBJECTDIR}/src/disp.o: src/disp.c nbproject/Makefile-${CND_CONF}.mk 116 | @${MKDIR} "${OBJECTDIR}/src" 117 | @${RM} ${OBJECTDIR}/src/disp.o.d 118 | @${RM} ${OBJECTDIR}/src/disp.o 119 | @${FIXDEPS} "${OBJECTDIR}/src/disp.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -D__DEBUG -DPK4Tool=1 -fframe-base-loclist -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -O1 -funroll-loops -D_SUPPRESS_PLIB_WARNING -MMD -MF "${OBJECTDIR}/src/disp.o.d" -o ${OBJECTDIR}/src/disp.o src/disp.c -DXPRJ_default=$(CND_CONF) -legacy-libc $(COMPARISON_BUILD) 120 | 121 | ${OBJECTDIR}/src/hw.o: src/hw.c nbproject/Makefile-${CND_CONF}.mk 122 | @${MKDIR} "${OBJECTDIR}/src" 123 | @${RM} ${OBJECTDIR}/src/hw.o.d 124 | @${RM} ${OBJECTDIR}/src/hw.o 125 | @${FIXDEPS} "${OBJECTDIR}/src/hw.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -D__DEBUG -DPK4Tool=1 -fframe-base-loclist -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -O1 -funroll-loops -D_SUPPRESS_PLIB_WARNING -MMD -MF "${OBJECTDIR}/src/hw.o.d" -o ${OBJECTDIR}/src/hw.o src/hw.c -DXPRJ_default=$(CND_CONF) -legacy-libc $(COMPARISON_BUILD) 126 | 127 | ${OBJECTDIR}/src/main.o: src/main.c nbproject/Makefile-${CND_CONF}.mk 128 | @${MKDIR} "${OBJECTDIR}/src" 129 | @${RM} ${OBJECTDIR}/src/main.o.d 130 | @${RM} ${OBJECTDIR}/src/main.o 131 | @${FIXDEPS} "${OBJECTDIR}/src/main.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -D__DEBUG -DPK4Tool=1 -fframe-base-loclist -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -O1 -funroll-loops -D_SUPPRESS_PLIB_WARNING -MMD -MF "${OBJECTDIR}/src/main.o.d" -o ${OBJECTDIR}/src/main.o src/main.c -DXPRJ_default=$(CND_CONF) -legacy-libc $(COMPARISON_BUILD) 132 | 133 | ${OBJECTDIR}/src/vt100.o: src/vt100.c nbproject/Makefile-${CND_CONF}.mk 134 | @${MKDIR} "${OBJECTDIR}/src" 135 | @${RM} ${OBJECTDIR}/src/vt100.o.d 136 | @${RM} ${OBJECTDIR}/src/vt100.o 137 | @${FIXDEPS} "${OBJECTDIR}/src/vt100.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -D__DEBUG -DPK4Tool=1 -fframe-base-loclist -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -O1 -funroll-loops -D_SUPPRESS_PLIB_WARNING -MMD -MF "${OBJECTDIR}/src/vt100.o.d" -o ${OBJECTDIR}/src/vt100.o src/vt100.c -DXPRJ_default=$(CND_CONF) -legacy-libc $(COMPARISON_BUILD) 138 | 139 | else 140 | ${OBJECTDIR}/src/badge.o: src/badge.c nbproject/Makefile-${CND_CONF}.mk 141 | @${MKDIR} "${OBJECTDIR}/src" 142 | @${RM} ${OBJECTDIR}/src/badge.o.d 143 | @${RM} ${OBJECTDIR}/src/badge.o 144 | @${FIXDEPS} "${OBJECTDIR}/src/badge.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -O1 -funroll-loops -D_SUPPRESS_PLIB_WARNING -MMD -MF "${OBJECTDIR}/src/badge.o.d" -o ${OBJECTDIR}/src/badge.o src/badge.c -DXPRJ_default=$(CND_CONF) -legacy-libc $(COMPARISON_BUILD) 145 | 146 | ${OBJECTDIR}/src/disp.o: src/disp.c nbproject/Makefile-${CND_CONF}.mk 147 | @${MKDIR} "${OBJECTDIR}/src" 148 | @${RM} ${OBJECTDIR}/src/disp.o.d 149 | @${RM} ${OBJECTDIR}/src/disp.o 150 | @${FIXDEPS} "${OBJECTDIR}/src/disp.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -O1 -funroll-loops -D_SUPPRESS_PLIB_WARNING -MMD -MF "${OBJECTDIR}/src/disp.o.d" -o ${OBJECTDIR}/src/disp.o src/disp.c -DXPRJ_default=$(CND_CONF) -legacy-libc $(COMPARISON_BUILD) 151 | 152 | ${OBJECTDIR}/src/hw.o: src/hw.c nbproject/Makefile-${CND_CONF}.mk 153 | @${MKDIR} "${OBJECTDIR}/src" 154 | @${RM} ${OBJECTDIR}/src/hw.o.d 155 | @${RM} ${OBJECTDIR}/src/hw.o 156 | @${FIXDEPS} "${OBJECTDIR}/src/hw.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -O1 -funroll-loops -D_SUPPRESS_PLIB_WARNING -MMD -MF "${OBJECTDIR}/src/hw.o.d" -o ${OBJECTDIR}/src/hw.o src/hw.c -DXPRJ_default=$(CND_CONF) -legacy-libc $(COMPARISON_BUILD) 157 | 158 | ${OBJECTDIR}/src/main.o: src/main.c nbproject/Makefile-${CND_CONF}.mk 159 | @${MKDIR} "${OBJECTDIR}/src" 160 | @${RM} ${OBJECTDIR}/src/main.o.d 161 | @${RM} ${OBJECTDIR}/src/main.o 162 | @${FIXDEPS} "${OBJECTDIR}/src/main.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -O1 -funroll-loops -D_SUPPRESS_PLIB_WARNING -MMD -MF "${OBJECTDIR}/src/main.o.d" -o ${OBJECTDIR}/src/main.o src/main.c -DXPRJ_default=$(CND_CONF) -legacy-libc $(COMPARISON_BUILD) 163 | 164 | ${OBJECTDIR}/src/vt100.o: src/vt100.c nbproject/Makefile-${CND_CONF}.mk 165 | @${MKDIR} "${OBJECTDIR}/src" 166 | @${RM} ${OBJECTDIR}/src/vt100.o.d 167 | @${RM} ${OBJECTDIR}/src/vt100.o 168 | @${FIXDEPS} "${OBJECTDIR}/src/vt100.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CC} $(MP_EXTRA_CC_PRE) -g -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -O1 -funroll-loops -D_SUPPRESS_PLIB_WARNING -MMD -MF "${OBJECTDIR}/src/vt100.o.d" -o ${OBJECTDIR}/src/vt100.o src/vt100.c -DXPRJ_default=$(CND_CONF) -legacy-libc $(COMPARISON_BUILD) 169 | 170 | endif 171 | 172 | # ------------------------------------------------------------------------------------ 173 | # Rules for buildStep: compileCPP 174 | ifeq ($(TYPE_IMAGE), DEBUG_RUN) 175 | else 176 | endif 177 | 178 | # ------------------------------------------------------------------------------------ 179 | # Rules for buildStep: link 180 | ifeq ($(TYPE_IMAGE), DEBUG_RUN) 181 | dist/${CND_CONF}/${IMAGE_TYPE}/badge_alternative.X.${IMAGE_TYPE}.${OUTPUT_SUFFIX}: ${OBJECTFILES} nbproject/Makefile-${CND_CONF}.mk 182 | @${MKDIR} dist/${CND_CONF}/${IMAGE_TYPE} 183 | ${MP_CC} $(MP_EXTRA_LD_PRE) -g -mdebugger -DPK4Tool=1 -mprocessor=$(MP_PROCESSOR_OPTION) -o dist/${CND_CONF}/${IMAGE_TYPE}/badge_alternative.X.${IMAGE_TYPE}.${OUTPUT_SUFFIX} ${OBJECTFILES_QUOTED_IF_SPACED} -DXPRJ_default=$(CND_CONF) -legacy-libc $(COMPARISON_BUILD) -mreserve=data@0x0:0x1FC -mreserve=boot@0x1FC02000:0x1FC02FEF -mreserve=boot@0x1FC02000:0x1FC0275F -Wl,--defsym=__MPLAB_BUILD=1$(MP_EXTRA_LD_POST)$(MP_LINKER_FILE_OPTION),--defsym=__MPLAB_DEBUG=1,--defsym=__DEBUG=1,-D=__DEBUG_D,--defsym=PK4Tool=1,--defsym=_min_heap_size=128,--defsym=_min_stack_size=128,--no-code-in-dinit,--no-dinit-in-serial-mem,-Map="${DISTDIR}/${PROJECTNAME}.${IMAGE_TYPE}.map",--memorysummary,dist/${CND_CONF}/${IMAGE_TYPE}/memoryfile.xml 184 | 185 | else 186 | dist/${CND_CONF}/${IMAGE_TYPE}/badge_alternative.X.${IMAGE_TYPE}.${OUTPUT_SUFFIX}: ${OBJECTFILES} nbproject/Makefile-${CND_CONF}.mk 187 | @${MKDIR} dist/${CND_CONF}/${IMAGE_TYPE} 188 | ${MP_CC} $(MP_EXTRA_LD_PRE) -mprocessor=$(MP_PROCESSOR_OPTION) -o dist/${CND_CONF}/${IMAGE_TYPE}/badge_alternative.X.${IMAGE_TYPE}.${DEBUGGABLE_SUFFIX} ${OBJECTFILES_QUOTED_IF_SPACED} -DXPRJ_default=$(CND_CONF) -legacy-libc $(COMPARISON_BUILD) -Wl,--defsym=__MPLAB_BUILD=1$(MP_EXTRA_LD_POST)$(MP_LINKER_FILE_OPTION),--defsym=_min_heap_size=128,--defsym=_min_stack_size=128,--no-code-in-dinit,--no-dinit-in-serial-mem,-Map="${DISTDIR}/${PROJECTNAME}.${IMAGE_TYPE}.map",--memorysummary,dist/${CND_CONF}/${IMAGE_TYPE}/memoryfile.xml 189 | ${MP_CC_DIR}/xc32-bin2hex dist/${CND_CONF}/${IMAGE_TYPE}/badge_alternative.X.${IMAGE_TYPE}.${DEBUGGABLE_SUFFIX} 190 | endif 191 | 192 | 193 | # Subprojects 194 | .build-subprojects: 195 | 196 | 197 | # Subprojects 198 | .clean-subprojects: 199 | 200 | # Clean Targets 201 | .clean-conf: ${CLEAN_SUBPROJECTS} 202 | ${RM} -r build/default 203 | ${RM} -r dist/default 204 | 205 | # Enable dependency checking 206 | .dep.inc: .depcheck-impl 207 | 208 | DEPFILES=$(shell "${PATH_TO_IDE_BIN}"mplabwildcard ${POSSIBLE_DEPFILES}) 209 | ifneq (${DEPFILES},) 210 | include ${DEPFILES} 211 | endif 212 | -------------------------------------------------------------------------------- /firmware/badge1.X/src/Z80/sim7.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Z80SIM - a Z80-CPU simulator 3 | * 4 | * Copyright (C) 1987-92 by Udo Munk 5 | * 6 | * This module of the Z80-CPU simulator must not be modified by a user, 7 | * see license agreement! 8 | * 9 | * History: 10 | * 28-SEP-87 Development on TARGON/35 with AT&T Unix System V(3.1) 11 | * 11-JAN-89 Release 1.1 12 | * 08-FEB-89 Release 1.2 13 | * 13-MAR-89 Release 1.3 14 | * 09-FEB-90 Release 1.4 Ported to TARGON/31 M10/30 15 | * 20-DEC-90 Release 1.5 Ported to COHERENT 3.0 16 | * 10-JUN-92 Release 1.6 long casting problem solved with COHERENT 3.2 17 | * and some optimization 18 | * 25-JUN-92 Release 1.7 comments in english 19 | */ 20 | 21 | /* 22 | * Like the function "cpu()" this one emulates 4 byte opcodes 23 | * starting with 0xfd 0xcb 24 | */ 25 | 26 | #include "sim.h" 27 | #include "simglb.h" 28 | #include "fdefs.h" 29 | long op_fdcb_handel() 30 | { 31 | long trap_fdcb(); 32 | long op_tb0iyd(), op_tb1iyd(), op_tb2iyd(), op_tb3iyd(); 33 | long op_tb4iyd(), op_tb5iyd(), op_tb6iyd(), op_tb7iyd(); 34 | long op_rb0iyd(), op_rb1iyd(), op_rb2iyd(), op_rb3iyd(); 35 | long op_rb4iyd(), op_rb5iyd(), op_rb6iyd(), op_rb7iyd(); 36 | long op_sb0iyd(), op_sb1iyd(), op_sb2iyd(), op_sb3iyd(); 37 | long op_sb4iyd(), op_sb5iyd(), op_sb6iyd(), op_sb7iyd(); 38 | long op_rlciyd(), op_rrciyd(), op_rliyd(), op_rriyd(); 39 | long op_slaiyd(), op_sraiyd(), op_srliyd(); 40 | 41 | static long (*op_fdcb[256]) () = { 42 | trap_fdcb, /* 0x00 */ 43 | trap_fdcb, /* 0x01 */ 44 | trap_fdcb, /* 0x02 */ 45 | trap_fdcb, /* 0x03 */ 46 | trap_fdcb, /* 0x04 */ 47 | trap_fdcb, /* 0x05 */ 48 | op_rlciyd, /* 0x06 */ 49 | trap_fdcb, /* 0x07 */ 50 | trap_fdcb, /* 0x08 */ 51 | trap_fdcb, /* 0x09 */ 52 | trap_fdcb, /* 0x0a */ 53 | trap_fdcb, /* 0x0b */ 54 | trap_fdcb, /* 0x0c */ 55 | trap_fdcb, /* 0x0d */ 56 | op_rrciyd, /* 0x0e */ 57 | trap_fdcb, /* 0x0f */ 58 | trap_fdcb, /* 0x10 */ 59 | trap_fdcb, /* 0x11 */ 60 | trap_fdcb, /* 0x12 */ 61 | trap_fdcb, /* 0x13 */ 62 | trap_fdcb, /* 0x14 */ 63 | trap_fdcb, /* 0x15 */ 64 | op_rliyd, /* 0x16 */ 65 | trap_fdcb, /* 0x17 */ 66 | trap_fdcb, /* 0x18 */ 67 | trap_fdcb, /* 0x19 */ 68 | trap_fdcb, /* 0x1a */ 69 | trap_fdcb, /* 0x1b */ 70 | trap_fdcb, /* 0x1c */ 71 | trap_fdcb, /* 0x1d */ 72 | op_rriyd, /* 0x1e */ 73 | trap_fdcb, /* 0x1f */ 74 | trap_fdcb, /* 0x20 */ 75 | trap_fdcb, /* 0x21 */ 76 | trap_fdcb, /* 0x22 */ 77 | trap_fdcb, /* 0x23 */ 78 | trap_fdcb, /* 0x24 */ 79 | trap_fdcb, /* 0x25 */ 80 | op_slaiyd, /* 0x26 */ 81 | trap_fdcb, /* 0x27 */ 82 | trap_fdcb, /* 0x28 */ 83 | trap_fdcb, /* 0x29 */ 84 | trap_fdcb, /* 0x2a */ 85 | trap_fdcb, /* 0x2b */ 86 | trap_fdcb, /* 0x2c */ 87 | trap_fdcb, /* 0x2d */ 88 | op_sraiyd, /* 0x2e */ 89 | trap_fdcb, /* 0x2f */ 90 | trap_fdcb, /* 0x30 */ 91 | trap_fdcb, /* 0x31 */ 92 | trap_fdcb, /* 0x32 */ 93 | trap_fdcb, /* 0x33 */ 94 | trap_fdcb, /* 0x34 */ 95 | trap_fdcb, /* 0x35 */ 96 | trap_fdcb, /* 0x36 */ 97 | trap_fdcb, /* 0x37 */ 98 | trap_fdcb, /* 0x38 */ 99 | trap_fdcb, /* 0x39 */ 100 | trap_fdcb, /* 0x3a */ 101 | trap_fdcb, /* 0x3b */ 102 | trap_fdcb, /* 0x3c */ 103 | trap_fdcb, /* 0x3d */ 104 | op_srliyd, /* 0x3e */ 105 | trap_fdcb, /* 0x3f */ 106 | trap_fdcb, /* 0x40 */ 107 | trap_fdcb, /* 0x41 */ 108 | trap_fdcb, /* 0x42 */ 109 | trap_fdcb, /* 0x43 */ 110 | trap_fdcb, /* 0x44 */ 111 | trap_fdcb, /* 0x45 */ 112 | op_tb0iyd, /* 0x46 */ 113 | trap_fdcb, /* 0x47 */ 114 | trap_fdcb, /* 0x48 */ 115 | trap_fdcb, /* 0x49 */ 116 | trap_fdcb, /* 0x4a */ 117 | trap_fdcb, /* 0x4b */ 118 | trap_fdcb, /* 0x4c */ 119 | trap_fdcb, /* 0x4d */ 120 | op_tb1iyd, /* 0x4e */ 121 | trap_fdcb, /* 0x4f */ 122 | trap_fdcb, /* 0x50 */ 123 | trap_fdcb, /* 0x51 */ 124 | trap_fdcb, /* 0x52 */ 125 | trap_fdcb, /* 0x53 */ 126 | trap_fdcb, /* 0x54 */ 127 | trap_fdcb, /* 0x55 */ 128 | op_tb2iyd, /* 0x56 */ 129 | trap_fdcb, /* 0x57 */ 130 | trap_fdcb, /* 0x58 */ 131 | trap_fdcb, /* 0x59 */ 132 | trap_fdcb, /* 0x5a */ 133 | trap_fdcb, /* 0x5b */ 134 | trap_fdcb, /* 0x5c */ 135 | trap_fdcb, /* 0x5d */ 136 | op_tb3iyd, /* 0x5e */ 137 | trap_fdcb, /* 0x5f */ 138 | trap_fdcb, /* 0x60 */ 139 | trap_fdcb, /* 0x61 */ 140 | trap_fdcb, /* 0x62 */ 141 | trap_fdcb, /* 0x63 */ 142 | trap_fdcb, /* 0x64 */ 143 | trap_fdcb, /* 0x65 */ 144 | op_tb4iyd, /* 0x66 */ 145 | trap_fdcb, /* 0x67 */ 146 | trap_fdcb, /* 0x68 */ 147 | trap_fdcb, /* 0x69 */ 148 | trap_fdcb, /* 0x6a */ 149 | trap_fdcb, /* 0x6b */ 150 | trap_fdcb, /* 0x6c */ 151 | trap_fdcb, /* 0x6d */ 152 | op_tb5iyd, /* 0x6e */ 153 | trap_fdcb, /* 0x6f */ 154 | trap_fdcb, /* 0x70 */ 155 | trap_fdcb, /* 0x71 */ 156 | trap_fdcb, /* 0x72 */ 157 | trap_fdcb, /* 0x73 */ 158 | trap_fdcb, /* 0x74 */ 159 | trap_fdcb, /* 0x75 */ 160 | op_tb6iyd, /* 0x76 */ 161 | trap_fdcb, /* 0x77 */ 162 | trap_fdcb, /* 0x78 */ 163 | trap_fdcb, /* 0x79 */ 164 | trap_fdcb, /* 0x7a */ 165 | trap_fdcb, /* 0x7b */ 166 | trap_fdcb, /* 0x7c */ 167 | trap_fdcb, /* 0x7d */ 168 | op_tb7iyd, /* 0x7e */ 169 | trap_fdcb, /* 0x7f */ 170 | trap_fdcb, /* 0x80 */ 171 | trap_fdcb, /* 0x81 */ 172 | trap_fdcb, /* 0x82 */ 173 | trap_fdcb, /* 0x83 */ 174 | trap_fdcb, /* 0x84 */ 175 | trap_fdcb, /* 0x85 */ 176 | op_rb0iyd, /* 0x86 */ 177 | trap_fdcb, /* 0x87 */ 178 | trap_fdcb, /* 0x88 */ 179 | trap_fdcb, /* 0x89 */ 180 | trap_fdcb, /* 0x8a */ 181 | trap_fdcb, /* 0x8b */ 182 | trap_fdcb, /* 0x8c */ 183 | trap_fdcb, /* 0x8d */ 184 | op_rb1iyd, /* 0x8e */ 185 | trap_fdcb, /* 0x8f */ 186 | trap_fdcb, /* 0x90 */ 187 | trap_fdcb, /* 0x91 */ 188 | trap_fdcb, /* 0x92 */ 189 | trap_fdcb, /* 0x93 */ 190 | trap_fdcb, /* 0x94 */ 191 | trap_fdcb, /* 0x95 */ 192 | op_rb2iyd, /* 0x96 */ 193 | trap_fdcb, /* 0x97 */ 194 | trap_fdcb, /* 0x98 */ 195 | trap_fdcb, /* 0x99 */ 196 | trap_fdcb, /* 0x9a */ 197 | trap_fdcb, /* 0x9b */ 198 | trap_fdcb, /* 0x9c */ 199 | trap_fdcb, /* 0x9d */ 200 | op_rb3iyd, /* 0x9e */ 201 | trap_fdcb, /* 0x9f */ 202 | trap_fdcb, /* 0xa0 */ 203 | trap_fdcb, /* 0xa1 */ 204 | trap_fdcb, /* 0xa2 */ 205 | trap_fdcb, /* 0xa3 */ 206 | trap_fdcb, /* 0xa4 */ 207 | trap_fdcb, /* 0xa5 */ 208 | op_rb4iyd, /* 0xa6 */ 209 | trap_fdcb, /* 0xa7 */ 210 | trap_fdcb, /* 0xa8 */ 211 | trap_fdcb, /* 0xa9 */ 212 | trap_fdcb, /* 0xaa */ 213 | trap_fdcb, /* 0xab */ 214 | trap_fdcb, /* 0xac */ 215 | trap_fdcb, /* 0xad */ 216 | op_rb5iyd, /* 0xae */ 217 | trap_fdcb, /* 0xaf */ 218 | trap_fdcb, /* 0xb0 */ 219 | trap_fdcb, /* 0xb1 */ 220 | trap_fdcb, /* 0xb2 */ 221 | trap_fdcb, /* 0xb3 */ 222 | trap_fdcb, /* 0xb4 */ 223 | trap_fdcb, /* 0xb5 */ 224 | op_rb6iyd, /* 0xb6 */ 225 | trap_fdcb, /* 0xb7 */ 226 | trap_fdcb, /* 0xb8 */ 227 | trap_fdcb, /* 0xb9 */ 228 | trap_fdcb, /* 0xba */ 229 | trap_fdcb, /* 0xbb */ 230 | trap_fdcb, /* 0xbc */ 231 | trap_fdcb, /* 0xbd */ 232 | op_rb7iyd, /* 0xbe */ 233 | trap_fdcb, /* 0xbf */ 234 | trap_fdcb, /* 0xc0 */ 235 | trap_fdcb, /* 0xc1 */ 236 | trap_fdcb, /* 0xc2 */ 237 | trap_fdcb, /* 0xc3 */ 238 | trap_fdcb, /* 0xc4 */ 239 | trap_fdcb, /* 0xc5 */ 240 | op_sb0iyd, /* 0xc6 */ 241 | trap_fdcb, /* 0xc7 */ 242 | trap_fdcb, /* 0xc8 */ 243 | trap_fdcb, /* 0xc9 */ 244 | trap_fdcb, /* 0xca */ 245 | trap_fdcb, /* 0xcb */ 246 | trap_fdcb, /* 0xcc */ 247 | trap_fdcb, /* 0xcd */ 248 | op_sb1iyd, /* 0xce */ 249 | trap_fdcb, /* 0xcf */ 250 | trap_fdcb, /* 0xd0 */ 251 | trap_fdcb, /* 0xd1 */ 252 | trap_fdcb, /* 0xd2 */ 253 | trap_fdcb, /* 0xd3 */ 254 | trap_fdcb, /* 0xd4 */ 255 | trap_fdcb, /* 0xd5 */ 256 | op_sb2iyd, /* 0xd6 */ 257 | trap_fdcb, /* 0xd7 */ 258 | trap_fdcb, /* 0xd8 */ 259 | trap_fdcb, /* 0xd9 */ 260 | trap_fdcb, /* 0xda */ 261 | trap_fdcb, /* 0xdb */ 262 | trap_fdcb, /* 0xdc */ 263 | trap_fdcb, /* 0xdd */ 264 | op_sb3iyd, /* 0xde */ 265 | trap_fdcb, /* 0xdf */ 266 | trap_fdcb, /* 0xe0 */ 267 | trap_fdcb, /* 0xe1 */ 268 | trap_fdcb, /* 0xe2 */ 269 | trap_fdcb, /* 0xe3 */ 270 | trap_fdcb, /* 0xe4 */ 271 | trap_fdcb, /* 0xe5 */ 272 | op_sb4iyd, /* 0xe6 */ 273 | trap_fdcb, /* 0xe7 */ 274 | trap_fdcb, /* 0xe8 */ 275 | trap_fdcb, /* 0xe9 */ 276 | trap_fdcb, /* 0xea */ 277 | trap_fdcb, /* 0xeb */ 278 | trap_fdcb, /* 0xec */ 279 | trap_fdcb, /* 0xed */ 280 | op_sb5iyd, /* 0xee */ 281 | trap_fdcb, /* 0xef */ 282 | trap_fdcb, /* 0xf0 */ 283 | trap_fdcb, /* 0xf1 */ 284 | trap_fdcb, /* 0xf2 */ 285 | trap_fdcb, /* 0xf3 */ 286 | trap_fdcb, /* 0xf4 */ 287 | trap_fdcb, /* 0xf5 */ 288 | op_sb6iyd, /* 0xf6 */ 289 | trap_fdcb, /* 0xf7 */ 290 | trap_fdcb, /* 0xf8 */ 291 | trap_fdcb, /* 0xf9 */ 292 | trap_fdcb, /* 0xfa */ 293 | trap_fdcb, /* 0xfb */ 294 | trap_fdcb, /* 0xfc */ 295 | trap_fdcb, /* 0xfd */ 296 | op_sb7iyd, /* 0xfe */ 297 | trap_fdcb /* 0xff */ 298 | }; 299 | 300 | register int d; 301 | #ifdef WANT_TIM 302 | register long t; 303 | #endif 304 | 305 | d = (char) *PC++; 306 | 307 | #ifdef WANT_PCC 308 | if (PC > ram + 65535) /* correct PC overrun */ 309 | PC = ram; 310 | #endif 311 | 312 | #ifdef WANT_TIM 313 | t = (*op_fdcb[*PC++]) (d); /* execute next opcode */ 314 | #else 315 | (*op_fdcb[*PC++]) (d); 316 | #endif 317 | 318 | #ifdef WANT_PCC 319 | if (PC > ram + 65535) /* again correct PC overrun */ 320 | PC = ram; 321 | #endif 322 | 323 | #ifdef WANT_TIM 324 | return(t); 325 | #endif 326 | } 327 | 328 | /* 329 | * This function traps all illegal opcodes following the 330 | * initial 0xfd 0xcb of a 4 byte opcode. 331 | */ 332 | static long trap_fdcb() 333 | { 334 | cpu_error = OPTRAP4; 335 | cpu_state = STOPPED; 336 | #ifdef WANT_TIM 337 | return(0L); 338 | #endif 339 | } 340 | 341 | static long op_tb0iyd(int data) /* BIT 0,(IY+d) */ 342 | 343 | { 344 | F &= ~N_FLAG; 345 | F |= H_FLAG; 346 | (*(ram + IY + data) & 1) ? (F &= ~Z_FLAG) : (F |= Z_FLAG); 347 | #ifdef WANT_TIM 348 | return(20L); 349 | #endif 350 | } 351 | 352 | static long op_tb1iyd(int data) /* BIT 1,(IY+d) */ 353 | 354 | { 355 | F &= ~N_FLAG; 356 | F |= H_FLAG; 357 | (*(ram + IY + data) & 2) ? (F &= ~Z_FLAG) : (F |= Z_FLAG); 358 | #ifdef WANT_TIM 359 | return(20L); 360 | #endif 361 | } 362 | 363 | static long op_tb2iyd(int data) /* BIT 2,(IY+d) */ 364 | 365 | { 366 | F &= ~N_FLAG; 367 | F |= H_FLAG; 368 | (*(ram + IY + data) & 4) ? (F &= ~Z_FLAG) : (F |= Z_FLAG); 369 | #ifdef WANT_TIM 370 | return(20L); 371 | #endif 372 | } 373 | 374 | static long op_tb3iyd(int data) /* BIT 3,(IY+d) */ 375 | 376 | { 377 | F &= ~N_FLAG; 378 | F |= H_FLAG; 379 | (*(ram + IY + data) & 8) ? (F &= ~Z_FLAG) : (F |= Z_FLAG); 380 | #ifdef WANT_TIM 381 | return(20L); 382 | #endif 383 | } 384 | 385 | static long op_tb4iyd(int data) /* BIT 4,(IY+d) */ 386 | 387 | { 388 | F &= ~N_FLAG; 389 | F |= H_FLAG; 390 | (*(ram + IY + data) & 16) ? (F &= ~Z_FLAG) : (F |= Z_FLAG); 391 | #ifdef WANT_TIM 392 | return(20L); 393 | #endif 394 | } 395 | 396 | static long op_tb5iyd(int data) /* BIT 5,(IY+d) */ 397 | 398 | { 399 | F &= ~N_FLAG; 400 | F |= H_FLAG; 401 | (*(ram + IY + data) & 32) ? (F &= ~Z_FLAG) : (F |= Z_FLAG); 402 | #ifdef WANT_TIM 403 | return(20L); 404 | #endif 405 | } 406 | 407 | static long op_tb6iyd(int data) /* BIT 6,(IY+d) */ 408 | 409 | { 410 | F &= ~N_FLAG; 411 | F |= H_FLAG; 412 | (*(ram + IY + data) & 64) ? (F &= ~Z_FLAG) : (F |= Z_FLAG); 413 | #ifdef WANT_TIM 414 | return(20L); 415 | #endif 416 | } 417 | 418 | static long op_tb7iyd(int data) /* BIT 7,(IY+d) */ 419 | 420 | { 421 | F &= ~N_FLAG; 422 | F |= H_FLAG; 423 | (*(ram + IY + data) & 128) ? (F &= ~Z_FLAG) : (F |= Z_FLAG); 424 | #ifdef WANT_TIM 425 | return(20L); 426 | #endif 427 | } 428 | 429 | static long op_rb0iyd(int data) /* RES 0,(IY+d) */ 430 | 431 | { 432 | *(ram + IY + data) &= ~1; 433 | #ifdef WANT_TIM 434 | return(23L); 435 | #endif 436 | } 437 | 438 | static long op_rb1iyd(int data) /* RES 1,(IY+d) */ 439 | 440 | { 441 | *(ram + IY + data) &= ~2; 442 | #ifdef WANT_TIM 443 | return(23L); 444 | #endif 445 | } 446 | 447 | static long op_rb2iyd(int data) /* RES 2,(IY+d) */ 448 | 449 | { 450 | *(ram + IY + data) &= ~4; 451 | #ifdef WANT_TIM 452 | return(23L); 453 | #endif 454 | } 455 | 456 | static long op_rb3iyd(int data) /* RES 3,(IY+d) */ 457 | 458 | { 459 | *(ram + IY + data) &= ~8; 460 | #ifdef WANT_TIM 461 | return(23L); 462 | #endif 463 | } 464 | 465 | static long op_rb4iyd(int data) /* RES 4,(IY+d) */ 466 | 467 | { 468 | *(ram + IY + data) &= ~16; 469 | #ifdef WANT_TIM 470 | return(23L); 471 | #endif 472 | } 473 | 474 | static long op_rb5iyd(int data) /* RES 5,(IY+d) */ 475 | 476 | { 477 | *(ram + IY + data) &= ~32; 478 | #ifdef WANT_TIM 479 | return(23L); 480 | #endif 481 | } 482 | 483 | static long op_rb6iyd(int data) /* RES 6,(IY+d) */ 484 | 485 | { 486 | *(ram + IY + data) &= ~64; 487 | #ifdef WANT_TIM 488 | return(23L); 489 | #endif 490 | } 491 | 492 | static long op_rb7iyd(int data) /* RES 7,(IY+d) */ 493 | 494 | { 495 | *(ram + IY + data) &= ~128; 496 | #ifdef WANT_TIM 497 | return(23L); 498 | #endif 499 | } 500 | 501 | static long op_sb0iyd(int data) /* SET 0,(IY+d) */ 502 | 503 | { 504 | *(ram + IY + data) |= 1; 505 | #ifdef WANT_TIM 506 | return(23L); 507 | #endif 508 | } 509 | 510 | static long op_sb1iyd(int data) /* SET 1,(IY+d) */ 511 | 512 | { 513 | *(ram + IY + data) |= 2; 514 | #ifdef WANT_TIM 515 | return(23L); 516 | #endif 517 | } 518 | 519 | static long op_sb2iyd(int data) /* SET 2,(IY+d) */ 520 | 521 | { 522 | *(ram + IY + data) |= 4; 523 | #ifdef WANT_TIM 524 | return(23L); 525 | #endif 526 | } 527 | 528 | static long op_sb3iyd(int data) /* SET 3,(IY+d) */ 529 | 530 | { 531 | *(ram + IY + data) |= 8; 532 | #ifdef WANT_TIM 533 | return(23L); 534 | #endif 535 | } 536 | 537 | static long op_sb4iyd(int data) /* SET 4,(IY+d) */ 538 | 539 | { 540 | *(ram + IY + data) |= 16; 541 | #ifdef WANT_TIM 542 | return(23L); 543 | #endif 544 | } 545 | 546 | static long op_sb5iyd(int data) /* SET 5,(IY+d) */ 547 | 548 | { 549 | *(ram + IY + data) |= 32; 550 | #ifdef WANT_TIM 551 | return(23L); 552 | #endif 553 | } 554 | 555 | static long op_sb6iyd(int data) /* SET 6,(IY+d) */ 556 | 557 | { 558 | *(ram + IY + data) |= 64; 559 | #ifdef WANT_TIM 560 | return(23L); 561 | #endif 562 | } 563 | 564 | static long op_sb7iyd(int data) /* SET 7,(IY+d) */ 565 | 566 | { 567 | *(ram + IY + data) |= 128; 568 | #ifdef WANT_TIM 569 | return(23L); 570 | #endif 571 | } 572 | 573 | static long op_rlciyd(int data) /* RLC (IY+d) */ 574 | 575 | { 576 | register int i; 577 | register BYTE *p; 578 | 579 | p = ram + IY + data; 580 | i = *p & 128; 581 | (i) ? (F |= C_FLAG) : (F &= ~C_FLAG); 582 | F &= ~(H_FLAG | N_FLAG); 583 | *p <<= 1; 584 | if (i) *p |= 1; 585 | (*p) ? (F &= ~Z_FLAG) : (F |= Z_FLAG); 586 | (*p & 128) ? (F |= S_FLAG) : (F &= ~S_FLAG); 587 | (parrity[*p]) ? (F &= ~P_FLAG) : (F |= P_FLAG); 588 | #ifdef WANT_TIM 589 | return(23L); 590 | #endif 591 | } 592 | 593 | static long op_rrciyd(int data) /* RRC (IY+d) */ 594 | 595 | { 596 | register int i; 597 | register BYTE *p; 598 | 599 | p = ram + IY + data; 600 | i = *p & 1; 601 | (i) ? (F |= C_FLAG) : (F &= ~C_FLAG); 602 | F &= ~(H_FLAG | N_FLAG); 603 | *p >>= 1; 604 | if (i) *p |= 128; 605 | (*p) ? (F &= ~Z_FLAG) : (F |= Z_FLAG); 606 | (*p & 128) ? (F |= S_FLAG) : (F &= ~S_FLAG); 607 | (parrity[*p]) ? (F &= ~P_FLAG) : (F |= P_FLAG); 608 | #ifdef WANT_TIM 609 | return(23L); 610 | #endif 611 | } 612 | 613 | static long op_rliyd(int data) /* RL (IY+d) */ 614 | 615 | { 616 | register int old_c_flag; 617 | register BYTE *p; 618 | 619 | p = ram + IY + data; 620 | old_c_flag = F & C_FLAG; 621 | (*p & 128) ? (F |= C_FLAG) : (F &= ~C_FLAG); 622 | *p <<= 1; 623 | if (old_c_flag) *p |= 1; 624 | F &= ~(H_FLAG | N_FLAG); 625 | (*p) ? (F &= ~Z_FLAG) : (F |= Z_FLAG); 626 | (*p & 128) ? (F |= S_FLAG) : (F &= ~S_FLAG); 627 | (parrity[*p]) ? (F &= ~P_FLAG) : (F |= P_FLAG); 628 | #ifdef WANT_TIM 629 | return(23L); 630 | #endif 631 | } 632 | 633 | static long op_rriyd(int data) /* RR (IY+d) */ 634 | 635 | { 636 | register int old_c_flag; 637 | register BYTE *p; 638 | 639 | old_c_flag = F & C_FLAG; 640 | p = ram + IY + data; 641 | (*p & 1) ? (F |= C_FLAG) : (F &= ~C_FLAG); 642 | *p >>= 1; 643 | if (old_c_flag) *p |= 128; 644 | F &= ~(H_FLAG | N_FLAG); 645 | (*p) ? (F &= ~Z_FLAG) : (F |= Z_FLAG); 646 | (*p & 128) ? (F |= S_FLAG) : (F &= ~S_FLAG); 647 | (parrity[*p]) ? (F &= ~P_FLAG) : (F |= P_FLAG); 648 | #ifdef WANT_TIM 649 | return(23L); 650 | #endif 651 | } 652 | 653 | static long op_slaiyd(int data) /* SLA (IY+d) */ 654 | 655 | { 656 | register BYTE *p; 657 | 658 | p = ram + IY + data; 659 | (*p & 128) ? (F |= C_FLAG) : (F &= ~C_FLAG); 660 | *p <<= 1; 661 | F &= ~(H_FLAG | N_FLAG); 662 | (*p) ? (F &= ~Z_FLAG) : (F |= Z_FLAG); 663 | (*p & 128) ? (F |= S_FLAG) : (F &= ~S_FLAG); 664 | (parrity[*p]) ? (F &= ~P_FLAG) : (F |= P_FLAG); 665 | #ifdef WANT_TIM 666 | return(23L); 667 | #endif 668 | } 669 | 670 | static long op_sraiyd(int data) /* SRA (IY+d) */ 671 | 672 | { 673 | register int i; 674 | register BYTE *p; 675 | 676 | p = ram + IY + data; 677 | i = *p & 128; 678 | (*p & 1) ? (F |= C_FLAG) : (F &= ~C_FLAG); 679 | *p >>= 1; 680 | *p |= i; 681 | F &= ~(H_FLAG | N_FLAG); 682 | (*p) ? (F &= ~Z_FLAG) : (F |= Z_FLAG); 683 | (*p & 128) ? (F |= S_FLAG) : (F &= ~S_FLAG); 684 | (parrity[*p]) ? (F &= ~P_FLAG) : (F |= P_FLAG); 685 | #ifdef WANT_TIM 686 | return(23L); 687 | #endif 688 | } 689 | 690 | static long op_srliyd(int data) /* SRL (IY+d) */ 691 | 692 | { 693 | register BYTE *p; 694 | 695 | p = ram + IY + data; 696 | (*p & 1) ? (F |= C_FLAG) : (F &= ~C_FLAG); 697 | *p >>= 1; 698 | F &= ~(H_FLAG | N_FLAG); 699 | (*p) ? (F &= ~Z_FLAG) : (F |= Z_FLAG); 700 | (*p & 128) ? (F |= S_FLAG) : (F &= ~S_FLAG); 701 | (parrity[*p]) ? (F &= ~P_FLAG) : (F |= P_FLAG); 702 | #ifdef WANT_TIM 703 | return(23L); 704 | #endif 705 | } 706 | --------------------------------------------------------------------------------