├── .clang-format ├── .gitignore ├── .vimrc ├── README.md ├── SConstruct ├── _bin ├── include │ ├── nes.h │ ├── nes_audio.h │ ├── nes_io.h │ ├── nes_mappers.h │ ├── nes_system.h │ ├── nes_video.h │ ├── std.h │ ├── std_assignment.h │ ├── std_bitwise.h │ ├── std_boolean.h │ ├── std_math.h │ ├── std_memory.h │ └── std_stack.h └── lib │ ├── lib_ram.as │ ├── std_init.as │ ├── std_jumps.as │ ├── std_math.as │ ├── std_memory.as │ └── std_palette.as ├── _democode ├── font2.chr ├── game.as ├── main.as ├── main.h ├── ramdata.as └── visuals.as ├── _docs └── options.txt ├── compiler.c ├── compiler.h ├── data ├── data.h └── mappers.c ├── expressions ├── exp_asm.c ├── exp_asm.h ├── exp_funccall.c ├── exp_funccall.h ├── exp_funcdeclare.c ├── exp_funcdeclare.h ├── exp_general.c ├── exp_general.h ├── exp_ifloop.c ├── exp_ifloop.h ├── exp_labels.c ├── exp_labels.h ├── exp_preprocess.c ├── exp_preprocess.h ├── exp_switch.c ├── exp_switch.h ├── exp_vardeclare.c └── exp_vardeclare.h ├── functions.c ├── functions.h ├── getcode.c ├── getcode.h ├── init.c ├── init.h ├── labels.c ├── labels.h ├── list.c ├── list.h ├── opcodes.c ├── opcodes.h ├── opcodetable.c ├── opcodetable.h ├── output ├── banks.c ├── banks.h ├── fixoffs.c ├── fixoffs.h ├── outbuf.c ├── outbuf.h ├── scrbin.c ├── scrbin.h ├── writecode.c └── writecode.h ├── prepbase.c ├── prepbase.h ├── scrbase.c ├── scrbase.h ├── strhand.c ├── strhand.h ├── system ├── config.c ├── config.h ├── fileio.c ├── fileio.h ├── memalloc.c ├── memalloc.h ├── message.c └── message.h ├── typedefs.h ├── vars.c └── vars.h /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | Language: Cpp 3 | # BasedOnStyle: WebKit 4 | AccessModifierOffset: -4 5 | ConstructorInitializerIndentWidth: 4 6 | AlignEscapedNewlinesLeft: false 7 | AlignTrailingComments: false 8 | AllowAllParametersOfDeclarationOnNextLine: true 9 | AllowShortBlocksOnASingleLine: false 10 | AllowShortIfStatementsOnASingleLine: false 11 | AllowShortLoopsOnASingleLine: false 12 | AllowShortFunctionsOnASingleLine: All 13 | AlwaysBreakTemplateDeclarations: false 14 | AlwaysBreakBeforeMultilineStrings: false 15 | BreakBeforeBinaryOperators: true 16 | BreakBeforeTernaryOperators: true 17 | BreakConstructorInitializersBeforeComma: true 18 | BinPackParameters: true 19 | ColumnLimit: 0 20 | ConstructorInitializerAllOnOneLineOrOnePerLine: false 21 | DerivePointerAlignment: false 22 | ExperimentalAutoDetectBinPacking: false 23 | IndentCaseLabels: false 24 | IndentWrappedFunctionNames: false 25 | IndentFunctionDeclarationAfterType: false 26 | MaxEmptyLinesToKeep: 1 27 | KeepEmptyLinesAtTheStartOfBlocks: true 28 | NamespaceIndentation: Inner 29 | ObjCSpaceAfterProperty: true 30 | ObjCSpaceBeforeProtocolList: true 31 | PenaltyBreakBeforeFirstCallParameter: 19 32 | PenaltyBreakComment: 300 33 | PenaltyBreakString: 1000 34 | PenaltyBreakFirstLessLess: 120 35 | PenaltyExcessCharacter: 1000000 36 | PenaltyReturnTypeOnItsOwnLine: 60 37 | PointerAlignment: Left 38 | SpacesBeforeTrailingComments: 1 39 | Cpp11BracedListStyle: false 40 | Standard: Cpp03 41 | IndentWidth: 4 42 | TabWidth: 8 43 | UseTab: Never 44 | BreakBeforeBraces: Stroustrup 45 | SpacesInParentheses: false 46 | SpacesInAngles: false 47 | SpaceInEmptyParentheses: false 48 | SpacesInCStyleCastParentheses: false 49 | SpacesInContainerLiterals: true 50 | SpaceBeforeAssignmentOperators: true 51 | ContinuationIndentWidth: 4 52 | CommentPragmas: '^ IWYU pragma:' 53 | ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] 54 | SpaceBeforeParens: ControlStatements 55 | DisableFormat: false 56 | ... 57 | 58 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | -------------------------------------------------------------------------------- /.vimrc: -------------------------------------------------------------------------------- 1 | set makeprg=scons 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # neshla 2 | Fork of neshla from http://neshla.sourceforge.net/ 3 | 4 | From original authors website: 5 | 6 | "NESHLA is an assembler for the Nintendo NES which gives the features of high level languages such as C 7 | without sacrificing any efficiency or speed. 8 | It structures and simplifies coding the NES, while still using assembly language. 9 | Compilers are inefficient for low end systems such as the NES. 10 | Even with optimizers, they would never produce code for fast action games or capable of tapping deep into the NES. 11 | It's the best of both worlds!" 12 | 13 | Source code updated to compile on Linux OS. 14 | 15 | # build 16 | To build neshla binary you need scons from https://scons.org/ and gcc multilib installed. 17 | After cloning repo, run scons command in neshla directory. 18 | 19 | -------------------------------------------------------------------------------- /SConstruct: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | env = Environment( 4 | CPPPATH=".", 5 | CCFLAGS=["-g", "-O0", "-m32"], 6 | LINKFLAGS=["-m32", '-zmuldefs'], 7 | LIBS=[] 8 | ) 9 | system_obj = env.Object(Glob('system/*.c')) 10 | data_obj = env.Object(Glob('data/*.c')) 11 | main_obj = env.Object(Glob('*.c')) 12 | output_obj = env.Object(Glob('output/*.c')) 13 | expressions_obj = env.Object(Glob('expressions/*.c')) 14 | 15 | objects = [ 16 | data_obj, 17 | main_obj, 18 | system_obj, 19 | output_obj, 20 | expressions_obj 21 | ] 22 | 23 | env.Program('neshla', objects) 24 | 25 | testEnv = env.Clone() 26 | testEnv['LIBS'] += ['cunit'] 27 | 28 | all_objs = env.Object([f for f in Glob('*.c') if 'compiler.c' not in f.path]) 29 | 30 | testEnv.Program( 31 | 'simple_test', 32 | [ 33 | 'test/test.c', 34 | data_obj, 35 | output_obj, 36 | expressions_obj, 37 | system_obj, 38 | all_objs 39 | ] 40 | ) 41 | -------------------------------------------------------------------------------- /_bin/include/nes.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * NES High Level Assembler Headers 3 | * (c) 2003 Brian Provinciano 4 | * http://www.bripro.com 5 | ****************************************************************************** 6 | * NES.H 7 | ****************************************************************************** 8 | * Standard NES registers 9 | ******************************************************************************/ 10 | #ifndef _NES_H 11 | #define _NES_H 12 | /******************************************************************************/ 13 | 14 | // enable_interrupts() 15 | // disable_interrupts() 16 | 17 | // enable_decimal_mode() 18 | // disable_decimal_mode() 19 | 20 | // set_carry_flag() 21 | // clear_carry_flag() 22 | 23 | // reset_stack() 24 | 25 | // system_initialize() 26 | 27 | #include "nes_system.h" 28 | 29 | 30 | //PPU CONTROL REGISTER #0 31 | 32 | // ppu_ctl0_assign(newctl) 33 | // ppu_ctl0_set(mask) 34 | // ppu_ctl0_clear(mask) 35 | // ppu_ctl0_adjust( clearmask, setmask ) 36 | // ppu_enable_nmi(mask) 37 | // ppu_disable_nmi() 38 | // ppu_turn_on_draw() 39 | // ppu_turn_off_draw(mask) 40 | // ppu_set_nametable(nametable) 41 | 42 | //PPU CONTROL REGISTER #1 43 | 44 | // ppu_ctl1_assign(newctl) 45 | // ppu_ctl1_set(mask) 46 | // ppu_ctl1_clear(mask) 47 | // ppu_ctl1_adjust( clearmask, setmask ) 48 | 49 | // ppu_set_palette_intensity(newbits) 50 | 51 | //SCANLINES 52 | 53 | // vblank_wait() 54 | // unvblank_wait() 55 | // test_scanline() 56 | 57 | //VRAM ADDRESSING 58 | 59 | // vram_clear_address() 60 | // vram_set_address(newaddress) 61 | // vram_set_address_i(newaddress) 62 | // vram_set_scroll( x, y ) 63 | 64 | //VRAM DATA 65 | // vram_write(value) 66 | // vram_write_ind(value) 67 | // vram_write_x(value) 68 | // vram_write_ind_y(value) 69 | // vram_write_a() 70 | // vram_write_16(value) 71 | // vram_write_16_i(value) 72 | // vram_read(dest) 73 | // vram_ind_read(dest) 74 | // vram_ind_y_read(dest) 75 | // vram_read_a() 76 | // vram_read_16(dest) 77 | 78 | //SPRITES 79 | 80 | // vram_set_sprite_address(newaddress) 81 | // vram_set_sprite_address_i(newaddress) 82 | // vram_set_sprite_data( x, y, tile, attributes ) 83 | // vram_sprite_dma_copy(oamptr) 84 | 85 | //PALETTE MACROS 86 | // set_palette_ptr(pal) 87 | // set_palette(pal) 88 | // set_palette_entry(pal,entry) 89 | 90 | //FUNCTIONS 91 | // function set_ptr_palette() 92 | // function write_palette() 93 | 94 | #include "nes_video.h" 95 | 96 | //JOYSTICK 97 | // reset_joystick() 98 | // read_joystick0() 99 | // read_joystick1() 100 | // test_joystick1(buttonmask) 101 | // test_joystick1_prev(buttonmask) 102 | // test_button_release(buttonmask) 103 | // test_button_press(buttonmask) 104 | 105 | #include "nes_io.h" 106 | 107 | 108 | #include "nes_audio.h" 109 | 110 | 111 | #include "nes_mappers.h" 112 | 113 | /******************************************************************************/ 114 | #endif 115 | /******************************************************************************/ 116 | -------------------------------------------------------------------------------- /_bin/include/nes_audio.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * NES High Level Assembler Headers 3 | * (c) 2003 Brian Provinciano 4 | * http://www.bripro.com 5 | ****************************************************************************** 6 | * NES_AUDIO.H 7 | ****************************************************************************** 8 | * NES audio registers, defines and macros 9 | ******************************************************************************/ 10 | #ifndef _NES_AUDIO_H 11 | #define _NES_AUDIO_H 12 | /******************************************************************************/ 13 | 14 | /****************************************************************************** 15 | * AUDIO 16 | ******************************************************************************/ 17 | 18 | // FOR THOSE WHO LIKE THE UNDERSCRORE STYLE 19 | BYTE SQUAREWAVEA_CNT0 :$4000 20 | BYTE SQUAREWAVEA_CNT1 :$4001 21 | BYTE SQUAREWAVEA_FREQ0 :$4002 22 | BYTE SQUAREWAVEA_FREQ1 :$4003 23 | 24 | // FOR THOSE WHO LIKE THE STRUCTURED '.' STYLE 25 | enum SQUAREWAVEA { 26 | CNT0 = $4000, 27 | CNT1 = $4001, 28 | FREQ0 = $4002, 29 | FREQ1 = $4003 30 | } 31 | 32 | 33 | BYTE SQUAREWAVEB_CNT0 :$4004 34 | BYTE SQUAREWAVEB_CNT1 :$4005 35 | BYTE SQUAREWAVEB_FREQ0 :$4006 36 | BYTE SQUAREWAVEB_FREQ1 :$4007 37 | 38 | enum SQUAREWAVEB { 39 | CNT0 = $4004, 40 | CNT1 = $4005, 41 | FREQ0 = $4006, 42 | FREQ1 = $4007 43 | } 44 | 45 | 46 | BYTE TRIANGLEWAVE_CNT0 :$4008 47 | BYTE TRIANGLEWAVE_CNT1 :$4009 48 | BYTE TRIANGLEWAVE_FREQ0 :$400A 49 | BYTE TRIANGLEWAVE_FREQ1 :$400B 50 | 51 | enum TRIANGLEWAVE { 52 | CNT0 = $4008, 53 | CNT1 = $4009, 54 | FREQ0 = $400A, 55 | FREQ1 = $400B 56 | } 57 | 58 | 59 | BYTE NOISE_CNT0 :$400C 60 | BYTE NOISE_CNT1 :$400D 61 | BYTE NOISE_FREQ0 :$400E 62 | BYTE NOISE_FREQ1 :$400F 63 | 64 | 65 | BYTE PCM_CNT :$4010 66 | BYTE PCM_VOLUMECNT :$4011 67 | BYTE PCM_ADDRESS :$4012 68 | BYTE PCM_LENGTH :$4013 69 | 70 | 71 | BYTE SND_CNT :$4015 72 | 73 | enum SNDENABLE { 74 | SQUARE_0 = %00000001, 75 | SQUARE_1 = %00000010, 76 | TRIANGLE = %00000100, 77 | NOISE = %00001000, 78 | DMC = %00010000 79 | } 80 | 81 | 82 | /******************************************************************************/ 83 | 84 | 85 | 86 | /******************************************************************************/ 87 | #endif 88 | /******************************************************************************/ 89 | -------------------------------------------------------------------------------- /_bin/include/nes_io.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * NES High Level Assembler Headers 3 | * (c) 2003 Brian Provinciano 4 | * http://www.bripro.com 5 | ****************************************************************************** 6 | * NES.H 7 | ****************************************************************************** 8 | * Reads and Write the NES Serial Ports 9 | ******************************************************************************/ 10 | #ifndef _NES_IO_H 11 | #define _NES_IO_H 12 | /******************************************************************************/ 13 | 14 | /****************************************************************************** 15 | * REGISTERS and FLAGS 16 | ******************************************************************************/ 17 | 18 | BYTE JOYSTICK_CNT0 :$4016 19 | BYTE JOYSTICK_CNT1 :$4017 20 | 21 | enum JOYSTICK { 22 | CNT0 = $4016, 23 | CNT1 = $4017, 24 | } 25 | 26 | #define JS_ZAPPERSPRITE $10 27 | #define JS_ZAPPERTRIGGER $08 28 | #define JS_ZAPPEREXPMASK $06 29 | #define JS_DATA $01 30 | 31 | // joypad masks 32 | #define BUTTON_A %10000000 33 | #define BUTTON_B %01000000 34 | #define BUTTON_SELECT %00100000 35 | #define BUTTON_START %00010000 36 | #define BUTTON_UP %00001000 37 | #define BUTTON_DOWN %00000100 38 | #define BUTTON_LEFT %00000010 39 | #define BUTTON_RIGHT %00000001 40 | /****************************************************************************** 41 | * MACROS 42 | ******************************************************************************/ 43 | 44 | /****************************************************************************** 45 | * strobe the joypad before read 46 | */ 47 | inline reset_joystick() 48 | { 49 | assign(JOYSTICK.CNT0, #1) 50 | assign(JOYSTICK.CNT0, #0) 51 | } 52 | 53 | /****************************************************************************** 54 | * reads the joystick on controller port 1 55 | */ 56 | inline read_joystick0() 57 | { 58 | lda JOYSTICK.CNT0 59 | and #1 60 | } 61 | 62 | /****************************************************************************** 63 | * reads the joystick on controller port 2 64 | */ 65 | inline read_joystick1() 66 | { 67 | lda JOYSTICK.CNT1 68 | and #1 69 | } 70 | 71 | 72 | /****************************************************************************** 73 | * tests if a button is pressed on the joystick 74 | * poll_joystick() must be called prior 75 | * 76 | * buttonmask: Memory location of 8bit variable, 8bit immediate value 77 | */ 78 | inline test_joystick1(buttonmask) 79 | { 80 | lda _joypad 81 | and buttonmask 82 | } 83 | 84 | /****************************************************************************** 85 | * tests if a button was pressed on the joystick last check 86 | * poll_joystick() must have been initially called 87 | * 88 | * buttonmask: Memory location of 8bit variable, 8bit immediate value 89 | */ 90 | inline test_joystick1_prev(buttonmask) 91 | { 92 | lda _joypad_prev 93 | and buttonmask 94 | } 95 | 96 | /****************************************************************************** 97 | * tests if a button was pressed but has been released 98 | * poll_joystick() must have been initially called 99 | * 100 | * buttonmask: Memory location of 8bit variable, 8bit immediate value 101 | */ 102 | inline test_button_release(buttonmask) 103 | { 104 | test_joystick1(buttonmask) 105 | if(zero) { 106 | test_joystick1_prev(buttonmask) 107 | } 108 | eor #0xFF 109 | } 110 | 111 | /****************************************************************************** 112 | * tests if a button was released but has been pressed 113 | * poll_joystick() must have been initially called 114 | * 115 | * buttonmask: Memory location of 8bit variable, 8bit immediate value 116 | */ 117 | inline test_button_press(buttonmask) 118 | { 119 | test_joystick1(buttonmask) // return( 120 | if(nonzero) { // if(joypad&buttonmask) 121 | test_joystick1_prev(buttonmask) // !(joypad&buttonmask) 122 | eor #0xFF // 123 | } // ) 124 | } 125 | 126 | /******************************************************************************/ 127 | #endif 128 | /******************************************************************************/ 129 | -------------------------------------------------------------------------------- /_bin/include/nes_system.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * NES High Level Assembler Headers 3 | * (c) 2003 Brian Provinciano 4 | * http://www.bripro.com 5 | ****************************************************************************** 6 | * NES_SYSTEM.H 7 | ****************************************************************************** 8 | * The low level NES system macros 9 | ******************************************************************************/ 10 | #ifndef _NES_SYSTEM_H 11 | #define _NES_SYSTEM_H 12 | /******************************************************************************/ 13 | 14 | // enable_interrupts() 15 | // disable_interrupts() 16 | 17 | // enable_decimal_mode() 18 | // disable_decimal_mode() 19 | 20 | // set_carry_flag() 21 | // clear_carry_flag() 22 | 23 | // reset_stack() 24 | 25 | // system_initialize() 26 | 27 | /******************************************************************************/ 28 | 29 | inline enable_interrupts() 30 | { 31 | cli // clear interrupt disable 32 | } 33 | /******************************************************************************/ 34 | 35 | inline disable_interrupts() 36 | { 37 | sei // set interrupt disable 38 | } 39 | 40 | 41 | /******************************************************************************/ 42 | 43 | inline enable_decimal_mode() 44 | { 45 | sei // set decimal mode 46 | } 47 | /******************************************************************************/ 48 | 49 | inline disable_decimal_mode() 50 | { 51 | cld // clear decimal mode 52 | } 53 | 54 | 55 | /******************************************************************************/ 56 | 57 | inline set_carry_flag() 58 | { 59 | sec // set the carry flag 60 | } 61 | /******************************************************************************/ 62 | 63 | inline clear_carry_flag() 64 | { 65 | clc // clear the carry flag 66 | } 67 | 68 | 69 | /******************************************************************************/ 70 | 71 | inline reset_stack() 72 | { 73 | ldx #0xFF // reset the stack pointer 74 | txs 75 | } 76 | 77 | /******************************************************************************/ 78 | 79 | inline nes_reset() 80 | { 81 | jmp [$FFFC] 82 | } 83 | 84 | /******************************************************************************/ 85 | inline system_initialize() 86 | { 87 | disable_decimal_mode() 88 | disable_interrupts() 89 | 90 | reset_stack() // this is why this MUST be inline! 91 | 92 | vblank_wait() 93 | 94 | // clear the registers 95 | lda #0 96 | 97 | sta PPU.CNT0 98 | sta PPU.CNT1 99 | 100 | sta PPU.BG_SCROLL 101 | sta PPU.BG_SCROLL 102 | 103 | sta PCM_CNT 104 | sta PCM_VOLUMECNT 105 | sta SND_CNT 106 | 107 | lda #0xC0 108 | sta joystick.cnt1 109 | 110 | 111 | enable_interrupts() 112 | } 113 | 114 | /******************************************************************************/ 115 | #endif 116 | /******************************************************************************/ 117 | -------------------------------------------------------------------------------- /_bin/include/std.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * NES High Level Assembler Headers 3 | * (c) 2003 Brian Provinciano 4 | * http://www.bripro.com 5 | ****************************************************************************** 6 | * STD.H 7 | ****************************************************************************** 8 | * 8 and 16 bit assignment, arithmatic, bitwise and boolean support macros 9 | ******************************************************************************/ 10 | #ifndef _STD_H 11 | #define _STD_H 12 | /******************************************************************************/ 13 | 14 | //DEFINES 15 | 16 | #define TRUE 1 17 | #define FALSE 0 18 | 19 | /******************************************************************************/ 20 | 21 | //8 BIT ASSIGNMENTS 22 | 23 | // assign(dest,value) 24 | // assign_x(dest,value) 25 | // x_assign(dest,value) 26 | // ind_assign(dest,value) 27 | // ind_x_assign(dest,value) 28 | // assign_ind(dest,src) 29 | // assign_ind_x(dest,src) 30 | 31 | //16 BIT ASSIGNMENTS 32 | 33 | // assign_16_8(dest,value) 34 | // assign_16_8_x(dest,value) 35 | 36 | // assign_16_16(dest,value) 37 | // assign_16_16_x(dest,value) 38 | 39 | // assign_16i(dest,value) 40 | // assign_16i_x(dest,value) 41 | 42 | #include "std_assignment.h" 43 | 44 | 45 | //BIT TESTS 46 | 47 | // test(value,mask) 48 | // test_16_8(value,mask) 49 | // test_16_16(value,mask) 50 | // test_16i(value,mask) 51 | 52 | //BITWISE OR 53 | 54 | // or(dest,mask) 55 | // or_x(dest,mask) 56 | // or_16_8(dest,mask) 57 | // or_16_8_x(dest,mask) 58 | // or_16_16(dest,mask) 59 | // or_16_16_x(dest,mask) 60 | // or_16i(dest,mask) 61 | // or_16i_x(dest,mask) 62 | 63 | //BITWISE EXCLUSIVE OR 64 | 65 | // xor(dest,mask) 66 | // xor_x(dest,mask) 67 | // xor_16_8(dest,mask) 68 | // xor_16_8_x(dest,mask) 69 | // xor_16_16(dest,mask) 70 | // xor_16_16_x(dest,mask) 71 | // xor_16i(dest,mask) 72 | // xor_16i_x(dest,mask) 73 | 74 | //BITWISE AND 75 | 76 | // and(dest,mask) 77 | // and_x(dest,mask) 78 | // and_16_8(dest,mask) 79 | // and_16_8_x(dest,mask) 80 | // and_16_16(dest,mask) 81 | // and_16_16_x(dest,mask) 82 | // and_16i(dest,mask) 83 | // and_16i_x(dest,mask) 84 | 85 | #include "std_bitwise.h" 86 | 87 | //ADDITION 88 | // add(dest,value) 89 | // add_x(dest,value) 90 | // add_16_8_a(dest) 91 | // add_16_8_a_x(dest) 92 | // add_16_8(dest,value) 93 | // add_16_8_x(dest,value) 94 | // add_16_16(dest,value) 95 | // add_16_16_x(dest,value) 96 | // add_16i(dest,value) 97 | // add_16i_x(dest,value) 98 | 99 | //SUBTRACTION 100 | // sub(dest,value) 101 | // sub_x(dest,value) 102 | // sub_16_8_a(dest) 103 | // sub_16_8_a_x(dest) 104 | // sub_16_8(dest,value) 105 | // sub_16_8_x(dest,value) 106 | // sub_16_16(dest,value) 107 | // sub16_16_x(dest,value) 108 | // sub_16i(dest,value) 109 | // sub_16i_x(dest,value) 110 | 111 | //MULTIPLICATION 112 | // mul_a( dest, multipiler ) 113 | // mul_x_a( dest, multipiler ) 114 | // mul( dest, multipiler ) 115 | // mul_x( dest, multipiler ) 116 | // mul_16_8( dest, multipiler ) 117 | // mul_16_8_x( dest, multipiler ) 118 | 119 | //SHIFT LEFT 120 | // asl_16( dest, amount ) 121 | // asl_16_to( dest, src, amount ) 122 | 123 | //SHIFT RIGHT 124 | // lsr_16( dest, amount ) 125 | // lsr_16_to( dest, src, amount ) 126 | 127 | //DIVISION 128 | // div( dest, amount ) 129 | // div_with_rem( dest, amount ) 130 | // div_16_8_to_x( dest, amount ) 131 | 132 | // mod_16_8_by_240( dest, src ) 133 | 134 | //NEGATIVITY 135 | // abs(number) 136 | // abs_16(number) 137 | // neg(number) 138 | // neg_16(number) 139 | 140 | //INCREMENT 141 | // inc_16(number) 142 | // inc_16_ind(number) 143 | 144 | //DECREMENT 145 | // dec_16(number) 146 | // dec_16_ind(number) 147 | 148 | //FUNCTIONS 149 | // function random() 150 | // function do_clock() 151 | 152 | #include "std_math.h" 153 | 154 | 155 | 156 | #include "std_boolean.h" 157 | 158 | 159 | //STACK OPERATIONS 160 | 161 | // pusha() 162 | // popa() 163 | 164 | // push(value) 165 | // push_x(src) 166 | // pop(dest) 167 | // pop_x(dest) 168 | // peek() 169 | 170 | // pushx() 171 | // popx() 172 | 173 | // pushy() 174 | // popy() 175 | 176 | // pushp() 177 | // popp() 178 | 179 | // pushsp() 180 | // popsp() 181 | 182 | // push_all() 183 | // pop_all() 184 | 185 | #include "std_stack.h" 186 | 187 | 188 | //MEMORY 189 | 190 | // memcpy_inline( dest, src, size ) 191 | // memset_inline( memdest, value, memsize) 192 | 193 | //FUNCTIONS 194 | // function memcpy() 195 | // function memset() 196 | // function clear_ram() 197 | // function clear_nametable() 198 | 199 | #include "std_memory.h" 200 | 201 | /******************************************************************************/ 202 | #endif 203 | /******************************************************************************/ 204 | -------------------------------------------------------------------------------- /_bin/include/std_boolean.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * NES High Level Assembler Headers 3 | * (c) 2003 Brian Provinciano 4 | * http://www.bripro.com 5 | ****************************************************************************** 6 | * STD_BOOLEAN.H 7 | ****************************************************************************** 8 | * boolean expressions 9 | ******************************************************************************/ 10 | #ifndef _STD_BOOLEAN_H 11 | #define _STD_BOOLEAN_H 12 | /******************************************************************************/ 13 | 14 | inline compare(src, value) 15 | { 16 | lda src 17 | cmp value 18 | } 19 | 20 | inline compare_x(src, value) 21 | { 22 | lda src, x 23 | cmp value 24 | } 25 | inline x_compare_x(src, value) 26 | { 27 | lda src, x 28 | cmp value, x 29 | } 30 | 31 | inline compare_16_16(src, value) 32 | { 33 | lda src+1 34 | cmp value+1 35 | if(equal) { 36 | lda src+0 37 | cmp value+0 38 | } 39 | } 40 | 41 | inline compare_16_16_x(src, value) 42 | { 43 | lda src+1 44 | cmp value+1, x 45 | if(equal) { 46 | lda src+0 47 | cmp value+0, x 48 | } 49 | } 50 | 51 | inline compare_16_x_16_x(src, value) 52 | { 53 | lda src+1, x 54 | cmp value+1, x 55 | if(equal) { 56 | lda src+0, x 57 | cmp value+0, x 58 | } 59 | } 60 | 61 | inline compare_16_y_16_x(src, value) 62 | { 63 | lda src+1, y 64 | cmp value+1, x 65 | if(equal) { 66 | lda src+0, y 67 | cmp value+0, x 68 | } 69 | } 70 | 71 | inline compare_8_y_8_x(src, value) 72 | { 73 | lda src, y 74 | cmp value, x 75 | } 76 | 77 | inline compare_16_x_16_y(src, value) 78 | { 79 | lda src+1, x 80 | cmp value+1, y 81 | if(equal) { 82 | lda src+0, x 83 | cmp value+0, y 84 | } 85 | } 86 | 87 | inline compare_8_x_8_y(src, value) 88 | { 89 | lda src, x 90 | cmp value, y 91 | } 92 | 93 | inline compare_8_x_8_x(src, value) 94 | { 95 | lda src, x 96 | cmp value, x 97 | } 98 | 99 | inline compare_8_x_8(src, value) 100 | { 101 | lda src, x 102 | cmp value 103 | } 104 | 105 | inline compare_8_y_8_y(src, value) 106 | { 107 | lda src, y 108 | cmp value, y 109 | } 110 | 111 | inline compare_16_16_y(src, value) 112 | { 113 | lda src+1 114 | cmp value+1, y 115 | if(equal) { 116 | lda src+0 117 | cmp value+0, y 118 | } 119 | } 120 | 121 | inline compare_16i(src, value) 122 | { 123 | lda src+1 124 | cmp #hi(value) 125 | if(equal) { 126 | lda src+0 127 | cmp #lo(value) 128 | } 129 | } 130 | 131 | 132 | /******************************************************************************/ 133 | #endif 134 | /******************************************************************************/ 135 | -------------------------------------------------------------------------------- /_bin/include/std_memory.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * NES High Level Assembler Headers 3 | * (c) 2003 Brian Provinciano 4 | * http://www.bripro.com 5 | ****************************************************************************** 6 | * STD_MEMORY.H 7 | ****************************************************************************** 8 | * Memory/RAM routines 9 | * 10 | * Functions defined in std_memory.as 11 | * To use them, you must include std_memory.as in one of your ROM code banks 12 | * as well as use lib_ram.as 13 | ******************************************************************************/ 14 | #ifndef _STD_MEMORY_H 15 | #define _STD_MEMORY_H 16 | /******************************************************************************/ 17 | 18 | // inline memcpy_inline( dest, src, size ) 19 | // function memcpy() 20 | // function memset() 21 | // inline memset_inline( memdest, value, memsize) 22 | // function clear_ram() 23 | // function clear_nametable() 24 | 25 | /****************************************************************************** 26 | * size==0? size=256 27 | * 28 | * Registers changed: A, X 29 | */ 30 | inline memcpy_inline( dest, src, size ) 31 | { 32 | /* 33 | ldx size 34 | do { 35 | dex 36 | lda src,x 37 | sta dest,x 38 | txa 39 | } while(nonzero)*/ 40 | ldx #0 41 | do { 42 | lda src,x 43 | sta dest,x 44 | inx 45 | cpx size 46 | } while(nonzero) 47 | } 48 | 49 | /****************************************************************************** 50 | * memset_inline( memdest, value, memsize ) 51 | * 52 | * memSize==0? memSize=256 53 | * 54 | * memdest: Memory location of buffer 55 | * value: Memory location of 8bit variable, 8bit immediate value 56 | * memsize: Memory location of 8bit variable, 8bit immediate value 57 | * 58 | * Registers changed: A, Y 59 | */ 60 | inline memset_inline( memdest, value, memsize) 61 | { 62 | lda value 63 | ldx #0 64 | do { 65 | sta memdest,x 66 | inx 67 | cpx memsize 68 | } while(nonzero) 69 | } 70 | 71 | 72 | /****************************************************************************** 73 | * size==0? size=256 74 | * 75 | * Registers changed: A, X 76 | */ 77 | inline vram_memcpy_inline( src, size ) 78 | { 79 | ldx #0 80 | do { 81 | lda src,x 82 | vram_write_a() 83 | inx 84 | cpx size 85 | } while(nonzero) 86 | } 87 | 88 | /****************************************************************************** 89 | * size==0? size=256 90 | * 91 | * Registers changed: A, X 92 | */ 93 | inline vram_memcpy_rev_inline( src, size ) 94 | { 95 | ldx size 96 | do { 97 | dex 98 | lda src,x 99 | vram_write_a() 100 | txa 101 | } while(nonzero) 102 | } 103 | 104 | 105 | /****************************************************************************** 106 | * copies all nonzero bytes to the vram 107 | * size==0? size=256 108 | * 109 | * Registers changed: A, X 110 | */ 111 | inline vram_maskcpy_inline( src, size ) 112 | { 113 | ldx #0 114 | do { 115 | lda src,x 116 | if(zero) { 117 | vram_read_a() 118 | } else { 119 | vram_write_a() 120 | } 121 | inx 122 | cpx size 123 | } while(nonzero) 124 | } 125 | 126 | /******************************************************************************/ 127 | #endif 128 | /******************************************************************************/ 129 | -------------------------------------------------------------------------------- /_bin/include/std_stack.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * NES High Level Assembler Headers 3 | * (c) 2003 Brian Provinciano 4 | * http://www.bripro.com 5 | ****************************************************************************** 6 | * STD_STACK.H 7 | ****************************************************************************** 8 | * 8 and 16 bit stack operation support macros 9 | ******************************************************************************/ 10 | #ifndef _STD_STACK_H 11 | #define _STD_STACK_H 12 | /******************************************************************************/ 13 | 14 | // pusha() 15 | // popa() 16 | 17 | // push(value) 18 | // push_x(src) 19 | // pop(dest) 20 | // pop_x(dest) 21 | // peek() 22 | 23 | // pushx() 24 | // popx() 25 | 26 | // pushy() 27 | // popy() 28 | 29 | // pushp() 30 | // popp() 31 | 32 | // pushsp() 33 | // popsp() 34 | 35 | // push_all() 36 | // pop_all() 37 | 38 | /****************************************************************************** 39 | * STACK MACROS 40 | ******************************************************************************/ 41 | 42 | /****************************************************************************** 43 | * pushes a value of REG.A to the stack 44 | */ 45 | inline pusha() 46 | { 47 | pha 48 | } 49 | 50 | /****************************************************************************** 51 | * pops a value from the stack into REG.A 52 | */ 53 | inline popa() 54 | { 55 | pla 56 | } 57 | 58 | /****************************************************************************** 59 | * tosses two bytes from the stack 60 | */ 61 | inline toss16() 62 | { 63 | pla 64 | pla 65 | } 66 | 67 | /****************************************************************************** 68 | * pushes value to the stack 69 | * value: Memory location of 8bit variable, 8bit immediate value 70 | */ 71 | inline push(value) 72 | { 73 | lda value 74 | pusha() 75 | } 76 | 77 | /****************************************************************************** 78 | * pushes the value of src[x] to the stack 79 | * src: Memory location of 8bit variable 80 | */ 81 | inline push_x(src) 82 | { 83 | lda src,x 84 | pusha() 85 | } 86 | 87 | /****************************************************************************** 88 | * pushes the value of src to the stack 89 | * src: Memory location of 16bit variable 90 | */ 91 | inline push_16(src) 92 | { 93 | lda src+0 94 | pusha() 95 | lda src+1 96 | pusha() 97 | } 98 | 99 | /****************************************************************************** 100 | * pushes the value of src[x] to the stack 101 | * src: Memory location of 16bit variable 102 | */ 103 | inline push_16_x(src) 104 | { 105 | lda src+0,x 106 | pusha() 107 | lda src+1,x 108 | pusha() 109 | } 110 | 111 | /****************************************************************************** 112 | * pops a value from the stack and stores it in dest 113 | * dest: Memory location of 8bit variable 114 | */ 115 | inline pop(dest) 116 | { 117 | popa() 118 | sta dest 119 | } 120 | 121 | /****************************************************************************** 122 | * pops a value from the stack and stores it in dest[x] 123 | * dest: Memory location of 8bit variable 124 | */ 125 | inline pop_x(dest) 126 | { 127 | popa() 128 | sta dest,x 129 | } 130 | 131 | /****************************************************************************** 132 | * pops a value from the stack and stores it in dest 133 | * dest: Memory location of 16bit variable 134 | */ 135 | inline pop_16(dest) 136 | { 137 | popa() 138 | sta dest+1 139 | popa() 140 | sta dest+0 141 | } 142 | 143 | /****************************************************************************** 144 | * pops a value from the stack and stores it in dest[x] 145 | * dest: Memory location of 16bit variable 146 | */ 147 | inline pop_16_x(dest) 148 | { 149 | popa() 150 | sta dest+1,x 151 | popa() 152 | sta dest+0,x 153 | } 154 | 155 | /****************************************************************************** 156 | * reads the top value of the stack 157 | */ 158 | inline peek() 159 | { 160 | popa() 161 | pusha() 162 | } 163 | 164 | 165 | /****************************************************************************** 166 | * psuh REG.X to the stack 167 | */ 168 | inline pushx() 169 | { 170 | txa 171 | pusha() 172 | } 173 | 174 | /****************************************************************************** 175 | * pops REG.X from the stack 176 | */ 177 | inline popx() 178 | { 179 | popa() 180 | tax 181 | } 182 | 183 | /****************************************************************************** 184 | * reads the top value of the stack, stores it in REG.X 185 | */ 186 | inline peekx() 187 | { 188 | popa() 189 | pusha() 190 | tax 191 | } 192 | 193 | /****************************************************************************** 194 | * push REG.Y to the stack 195 | */ 196 | inline pushy() 197 | { 198 | tya 199 | pusha() 200 | } 201 | 202 | /****************************************************************************** 203 | * pops REG.Y from the stack 204 | */ 205 | inline popy() 206 | { 207 | popa() 208 | tay 209 | } 210 | 211 | /****************************************************************************** 212 | * reads the top value of the stack, stores it in REG.Y 213 | */ 214 | inline peeky() 215 | { 216 | popa() 217 | pusha() 218 | tay 219 | } 220 | 221 | /****************************************************************************** 222 | * pushes the processor status flags to the stack 223 | */ 224 | inline pushp() 225 | { 226 | php 227 | } 228 | 229 | /****************************************************************************** 230 | * pops the processor status flags from the stack 231 | */ 232 | inline popp() 233 | { 234 | plp 235 | } 236 | 237 | /****************************************************************************** 238 | * pushes the stack pointer to the stack 239 | */ 240 | inline pushsp() 241 | { 242 | tsx 243 | pushx() 244 | } 245 | 246 | /****************************************************************************** 247 | * pops the stack pointer from the stack 248 | */ 249 | inline popsp() 250 | { 251 | popx() 252 | txs 253 | } 254 | 255 | /****************************************************************************** 256 | * pushes all the registers and processor flags to the stack 257 | */ 258 | inline push_all() 259 | { 260 | pushp() 261 | pusha() 262 | pushx() 263 | pushy() 264 | } 265 | 266 | /****************************************************************************** 267 | * pops all the registers and processor flags from the stack 268 | */ 269 | inline pop_all() 270 | { 271 | popy() 272 | popx() 273 | popa() 274 | popp() 275 | } 276 | 277 | /******************************************************************************/ 278 | #endif 279 | /******************************************************************************/ 280 | -------------------------------------------------------------------------------- /_bin/lib/lib_ram.as: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * NES High Level Assembler Library 3 | * (c) 2003,2004,2005 Brian Provinciano 4 | * http://www.bripro.com 5 | ****************************************************************************** 6 | * LIB_RAM.AS 7 | ****************************************************************************** 8 | * The variables in RAM space required the library functions 9 | * 10 | * must be included within a RAM bank 11 | ******************************************************************************/ 12 | 13 | 14 | /****************************************************************************** 15 | * VIDEO 16 | ******************************************************************************/ 17 | #ifdef _NES_VIDEO_H 18 | 19 | // local copies of the ppu control registers 20 | shared byte 21 | _ppu_ctl0, _ppu_ctl1 22 | 23 | pointer 24 | _pal_ptr 25 | #endif 26 | 27 | /****************************************************************************** 28 | * IO 29 | ******************************************************************************/ 30 | #ifdef _NES_IO_H 31 | 32 | // holds bits for each joypad button 33 | shared byte 34 | _joypad, _joypad_prev 35 | 36 | 37 | #endif 38 | 39 | /****************************************************************************** 40 | * STANDARD 41 | ******************************************************************************/ 42 | #ifdef _STD_H 43 | 44 | // temporary variables for macros such as the math ones 45 | byte _b_temp 46 | word _w_temp 47 | pointer _p_temp, _jsrind_temp 48 | 49 | #ifdef _STD_MATH_H 50 | byte _b_remainder, 51 | 52 | _random_value, 53 | _random_ticks 54 | #endif 55 | 56 | #endif 57 | 58 | /****************************************************************************** 59 | * MEMORY 60 | ******************************************************************************/ 61 | #ifdef _STD_MEMORY_H 62 | 63 | // temporary pointers to the memory locations 64 | pointer _mem_src, _mem_dest 65 | 66 | 67 | #endif 68 | 69 | byte pBankA000_prev, pBankA000_cur 70 | /******************************************************************************/ 71 | -------------------------------------------------------------------------------- /_bin/lib/std_init.as: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * NES High Level Assembler Library 3 | * (c) 2003,2004,2005 Brian Provinciano 4 | * http://www.bripro.com 5 | ****************************************************************************** 6 | * STD_INIT.AS 7 | ****************************************************************************** 8 | * Functions for system initialization 9 | ******************************************************************************/ 10 | 11 | // function clear_ram() 12 | 13 | /******************************************************************************/ 14 | 15 | 16 | /****************************************************************************** 17 | * clears the 2K ram ($800 bytes) 18 | * 19 | * Registers changed: A, X 20 | */ 21 | function clear_ram() 22 | { 23 | lda #0 // the value 24 | ldx #0 // the loop (256 reps) 25 | 26 | do { 27 | sta 0x00,x 28 | // no $100 because it's the stack! 29 | sta 0x200,x 30 | sta 0x300,x 31 | sta 0x400,x 32 | sta 0x500,x 33 | sta 0x600,x 34 | sta 0x700,x 35 | dex 36 | } while(nonzero) 37 | } 38 | /******************************************************************************/ 39 | -------------------------------------------------------------------------------- /_bin/lib/std_jumps.as: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * NES High Level Assembler Headers 3 | * (c) 2003,2004,2005 Brian Provinciano 4 | * http://www.bripro.com 5 | ****************************************************************************** 6 | * STD_JUMPS.AS 7 | ****************************************************************************** 8 | * Indirect subroutine calling support 9 | * - clean without any manual stack manipulation! 10 | ******************************************************************************/ 11 | 12 | /******************************************************************************/ 13 | function noreturn jsrind_f() 14 | { 15 | jmp [_jsrind_temp] 16 | } 17 | /******************************************************************************/ 18 | inline jsrind(pproc) 19 | { 20 | lda pproc+0 21 | ora pproc+1 22 | if(not zero) { 23 | assign_16_16(_jsrind_temp, pproc) 24 | jsrind_f() 25 | } 26 | } 27 | /******************************************************************************/ 28 | inline jsrind_x(pproc) 29 | { 30 | lda pproc+0,x 31 | ora pproc+1,x 32 | if(not zero) { 33 | x_assign_16_16(_jsrind_temp, pproc) 34 | jsrind_f() 35 | } 36 | } 37 | /******************************************************************************/ 38 | inline jsrind_y(pproc) 39 | { 40 | lda pproc+0,y 41 | ora pproc+1,y 42 | if(not zero) { 43 | y_assign_16_16(_jsrind_temp, pproc) 44 | jsrind_f() 45 | } 46 | } 47 | /******************************************************************************/ 48 | inline jsrind_imd(pproc) 49 | { 50 | lda #lo(pproc) 51 | ora #hi(pproc) 52 | if(not zero) { 53 | assign_16i(_jsrind_temp, pproc) 54 | jsrind_f() 55 | } 56 | } 57 | /******************************************************************************/ 58 | inline jsr_table(ptable) 59 | { 60 | asl a 61 | tay 62 | y_assign_16_16(_jsrind_temp, ptable) 63 | jsrind_f() 64 | } 65 | /******************************************************************************/ 66 | inline jsr_table_xy(ptable) 67 | { 68 | x_assign_16_16(_p_temp, ptable) 69 | y_ind_assign_16_16(_jsrind_temp, _p_temp) 70 | jsrind_f() 71 | } 72 | /******************************************************************************/ 73 | -------------------------------------------------------------------------------- /_bin/lib/std_math.as: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * NES High Level Assembler Library 3 | * (c) 2003,2004,2005 Brian Provinciano 4 | * http://www.bripro.com 5 | ****************************************************************************** 6 | * STD_MATH.AS 7 | ****************************************************************************** 8 | * Math related functions 9 | ******************************************************************************/ 10 | 11 | //function random() 12 | //function do_clock() 13 | 14 | /****************************************************************************** 15 | * _random_value = rand(); 16 | * generates a random 8bit number 17 | */ 18 | function random_more() 19 | { 20 | lda _random_value 21 | adc [_random_value],y 22 | adc _random_value,x 23 | ldy _random_value 24 | adc $C123,y // just some random pointer to ROM data 25 | sbc time.ticks // just a little more randomness 26 | sta _random_value 27 | } 28 | 29 | /****************************************************************************** 30 | * _random_value = rand(); 31 | * generates a random 8bit number 32 | */ 33 | function random() 34 | { 35 | lda _random_value 36 | adc [_random_value,x] 37 | sbc time.ticks // just a little more randomness 38 | sta _random_value 39 | } 40 | 41 | /****************************************************************************** 42 | * executes the clock updating the hours, minutes, seconds and ticks 43 | */ 44 | function do_clock() 45 | { 46 | inc time.ticks 47 | lda time.ticks 48 | cmp #60 49 | if(equal) { 50 | lda #0 51 | sta time.ticks 52 | 53 | inc time.seconds 54 | lda time.seconds 55 | cmp #60 56 | if(equal) { 57 | lda #0 58 | sta time.seconds 59 | 60 | inc time.minutes 61 | lda time.minutes 62 | cmp #60 63 | if(equal) { 64 | lda #0 65 | sta time.minutes 66 | 67 | inc time.hours 68 | } 69 | } 70 | } 71 | } 72 | /******************************************************************************/ 73 | -------------------------------------------------------------------------------- /_bin/lib/std_memory.as: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * NES High Level Assembler Library 3 | * (c) 2003,2004,2005 Brian Provinciano 4 | * http://www.bripro.com 5 | ****************************************************************************** 6 | * STD_MEMORY.AS 7 | ****************************************************************************** 8 | * Memory/RAM functions 9 | ******************************************************************************/ 10 | 11 | // function memcpy() 12 | // function memset() 13 | // function clear_nametable() 14 | 15 | /******************************************************************************/ 16 | 17 | 18 | /****************************************************************************** 19 | * memcpy( WORD pMemDest, WORD pMemSrc, REG.Y memSize ) 20 | * 21 | * memSize==0? memSize=256 22 | * 23 | * Registers changed: A, Y 24 | */ 25 | function memcpy() 26 | { 27 | do { 28 | dey 29 | lda [_mem_src],y 30 | sta [_mem_dest],y 31 | tya 32 | } while(nonzero) 33 | } 34 | 35 | /****************************************************************************** 36 | * memset( WORD pMemDest, REG.A value, REG.Y memSize ) 37 | * 38 | * memSize==0? memSize=256 39 | * 40 | * Registers changed: A, Y 41 | */ 42 | function memset() 43 | { 44 | do { 45 | sta [_mem_dest],y 46 | dey 47 | } while(nonzero) 48 | } 49 | 50 | /****************************************************************************** 51 | * clears the full name table and attribute table ram 52 | * 53 | * Registers changed: A, X, Y 54 | */ 55 | function vram_clear_name_tables() 56 | { 57 | vram_set_address_i(NAME_TABLE_0_ADDRESS) 58 | 59 | lda #0 // the value 60 | 61 | ldy #16 // full even mirror clear just in case of four screen 62 | do { 63 | 64 | ldx #0 // the loop (256 reps) 65 | do { 66 | 67 | vram_write_a() 68 | dex 69 | 70 | } while(nonzero) 71 | 72 | } while(nonzero) 73 | } 74 | 75 | 76 | /****************************************************************************** 77 | * clears a name table in vram with the desired character 78 | * 79 | * First, set the vram address pointer, then load the character into REG.A 80 | * 81 | * eg. 82 | * vram_set_address_i(NAME_TABLE_0_ADDRESS) // name table #0 83 | * lda #'A' // clear it to character 'A' 84 | * vram_memset_name_table() 85 | */ 86 | function vram_memset_name_table() 87 | { 88 | ldy #NAMETABLE_HEIGHT/2 // little bit faster 89 | do { 90 | ldx #NAMETABLE_WIDTH/4*2 91 | do { 92 | vram_write_a() 93 | vram_write_a() 94 | vram_write_a() 95 | vram_write_a() 96 | dex 97 | } while(not zero) 98 | dey 99 | } while(not zero) 100 | } 101 | 102 | /****************************************************************************** 103 | * clears a attribute table in vram to the desired value 104 | * 105 | * First, set the vram address pointer, then load the value into REG.A 106 | * 107 | * eg. 108 | * vram_set_address_i(ATTRIBUTE_TABLE_1_ADDRESS) // attribute table #1 109 | * lda #0 // set it to all #0 110 | * vram_memset_attribute_table() 111 | */ 112 | function vram_memset_attribute_table() 113 | { 114 | ldy #ATTRIBUTE_TABLE_SIZE 115 | do { 116 | vram_write_a() 117 | dey 118 | } while(not zero) 119 | } 120 | 121 | /****************************************************************************** 122 | * clears a up to 256 bytes of VRAM with the desired value 123 | * 124 | * First, set the vram address pointer, then load the value into REG.A 125 | * 126 | * eg. 127 | * vram_set_address_i(PATTERN_TABLE_0_ADDRESS) 128 | * lda #0 // set it to all #0 129 | * vram_memset() 130 | */ 131 | function vram_memset() 132 | { 133 | do { 134 | vram_write_a() 135 | dey 136 | } while(not zero) 137 | } 138 | 139 | /****************************************************************************** 140 | * clears a name table in wram/exram with the desired character (960 bytes) 141 | * 142 | * Can be used for MMC5's exram extended name/attr table data 143 | * 144 | * First, set _p_temp to point to the name table, then load the character 145 | * into REG.A 146 | * 147 | * eg. 148 | * assign_16i(_p_temp, myRamNameTableData) 149 | * lda #'A' // clear it to character 'A' 150 | * memset_ram_name_table() 151 | */ 152 | function memset_ram_name_table() 153 | { 154 | // CLEAN 155 | ldx #NAMETABLE_HEIGHT/2 156 | do { 157 | 158 | ldy #0 159 | do { 160 | sta [_p_temp],y 161 | iny 162 | cpy #NAMETABLE_WIDTH*2 163 | } while(not equal) 164 | 165 | pha 166 | add_16_8(_p_temp, #(NAMETABLE_WIDTH*2)) 167 | pla 168 | dex 169 | } while(not zero) 170 | } 171 | 172 | /****************************************************************************** 173 | * clears a name table followed by an attribute table in wram/exram 174 | * with the desired character (1024 bytes, 960+64) 175 | * 176 | * First, set _p_temp to point to the name table, then load the character 177 | * into REG.A 178 | * 179 | * eg. 180 | * assign_16i(_p_temp, myRamNameTableData) 181 | * lda #'A' // clear it to character 'A' 182 | * memset_ram_name_n_attr_table() 183 | */ 184 | function memset_ram_name_n_attr_table() 185 | { 186 | ldx #4 187 | do { 188 | 189 | ldy #0 190 | do { 191 | sta [_p_temp],y 192 | iny 193 | } while(nonzero) 194 | 195 | inc _p_temp+1 196 | dex 197 | } while(not zero) 198 | } 199 | 200 | 201 | 202 | /****************************************************************************** 203 | * copies data to the nametable 204 | * 205 | * Registers changed: A, X, Y 206 | */ 207 | // vram_set_address_i(NAME_TABLE_0_ADDRESS) 208 | // assign16i(_p_temp, nametabledata) 209 | // vram_memcpy_name_table() 210 | function vram_memcpy_name_table() 211 | { 212 | 213 | lda #0 // the value 214 | 215 | ldx #NAMETABLE_HEIGHT // full even mirror clear just in case of four screen 216 | do { 217 | 218 | ldy #0 219 | do { 220 | 221 | lda [_p_temp], y 222 | vram_write_a() 223 | iny 224 | cpy #NAMETABLE_WIDTH 225 | } while(nonzero) 226 | 227 | add_16i(_p_temp, NAMETABLE_WIDTH) 228 | 229 | dex 230 | } while(nonzero) 231 | } 232 | /****************************************************************************** 233 | * memcpy( WORD pMemDest, WORD pMemSrc, REG.Y memSize ) 234 | * 235 | * memSize==0? memSize=256 236 | * 237 | * Registers changed: A, Y 238 | */ 239 | function vram_memcpy() 240 | { 241 | ldy #0 242 | do { 243 | lda [_mem_src],y 244 | vram_write_a() 245 | iny 246 | dex 247 | } while(nonzero) 248 | } 249 | 250 | /****************************************************************************** 251 | * REG.X : number of rows 252 | * REG.A : value 253 | */ 254 | function vram_memset_rows() 255 | { 256 | do { 257 | ldy #NAMETABLE_WIDTH 258 | do { 259 | vram_write_a() 260 | dey 261 | } while(nonzero) 262 | dex 263 | } while(nonzero) 264 | } 265 | /******************************************************************************/ 266 | -------------------------------------------------------------------------------- /_bin/lib/std_palette.as: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * NES High Level Assembler Library 3 | * (c) 2003,2004,2005 Brian Provinciano 4 | * http://www.bripro.com 5 | ****************************************************************************** 6 | * STD_PALETTE.AS 7 | ****************************************************************************** 8 | * palette related functions 9 | ******************************************************************************/ 10 | 11 | //PALETTE MACROS 12 | // set_palette_ptr(pal) 13 | // set_palette(pal) 14 | // set_palette_entry(pal,entry) 15 | 16 | //FUNCTIONS 17 | // function set_ptr_palette() 18 | // function write_palette() 19 | 20 | /****************************************************************************** 21 | * _random_value = rand(); 22 | * generates a random 8bit number 23 | */ 24 | inline set_palette_ptr(pal) 25 | { 26 | assign_16i(_pal_ptr,pal) 27 | } 28 | 29 | /****************************************************************************** 30 | * _random_value = rand(); 31 | * generates a random 8bit number 32 | */ 33 | function set_ptr_palette() 34 | { 35 | vram_set_address_i(PAL_ADDRESS) 36 | 37 | ldy #0 38 | do { 39 | vram_write_ind_y(_pal_ptr) 40 | iny 41 | cpy #sizeof(PALETTE) 42 | } while(not equal) 43 | 44 | vram_clear_address() 45 | } 46 | 47 | /****************************************************************************** 48 | */ 49 | inline set_palette(pal) 50 | { 51 | memcpy_inline( _palette, pal, #sizeof(PALETTE) ) 52 | write_palette() 53 | } 54 | 55 | /****************************************************************************** 56 | */ 57 | inline set_sprite_palette(pal) 58 | { 59 | vram_set_address_i(PAL_ADDRESS+16) 60 | 61 | ldx #0 62 | do { 63 | vram_write_x(pal) 64 | inx 65 | cpx #sizeof(PALETTE) 66 | } while(not equal) 67 | 68 | vram_clear_address() 69 | } 70 | 71 | /****************************************************************************** 72 | * _random_value = rand(); 73 | * generates a random 8bit number 74 | */ 75 | inline set_palette_entry(pal,entry) 76 | { 77 | memcpy_inline( _palette+(entry*4), pal, 4 ) 78 | write_palette() 79 | } 80 | 81 | /****************************************************************************** 82 | * inputs _p_temp 83 | */ 84 | function set_palette_entry_x() 85 | { 86 | ldy #0 87 | do { 88 | lda [_p_temp], y 89 | sta _palette, x 90 | inx 91 | iny 92 | cpy #3 93 | } while(not equal) 94 | write_palette() 95 | } 96 | 97 | /****************************************************************************** 98 | * _random_value = rand(); 99 | * generates a random 8bit number 100 | */ 101 | function write_palette() 102 | { 103 | vram_set_address_i(PAL_ADDRESS) 104 | 105 | ldx #0 106 | do { 107 | vram_write_x(_palette) 108 | inx 109 | cpx #sizeof(PALETTE) 110 | } while(not equal) 111 | 112 | vram_clear_address() 113 | } 114 | 115 | /****************************************************************************** 116 | * writes a palette to the pal memory quickly without looping, 117 | * does not clear the vram address after 118 | */ 119 | inline write_updated_palette_fast(paladdr) 120 | { 121 | vram_set_address_i(PAL_ADDRESS) 122 | vram_write(paladdr+0x00) 123 | vram_write(paladdr+0x01) 124 | vram_write(paladdr+0x02) 125 | vram_write(paladdr+0x03) 126 | vram_write(paladdr+0x00) 127 | vram_write(paladdr+0x05) 128 | vram_write(paladdr+0x06) 129 | vram_write(paladdr+0x07) 130 | vram_write(paladdr+0x00) 131 | vram_write(paladdr+0x09) 132 | vram_write(paladdr+0x0A) 133 | vram_write(paladdr+0x0B) 134 | vram_write(paladdr+0x00) 135 | vram_write(paladdr+0x0D) 136 | vram_write(paladdr+0x0E) 137 | vram_write(paladdr+0x0F) 138 | } 139 | 140 | /******************************************************************************/ 141 | -------------------------------------------------------------------------------- /_democode/font2.chr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/malikcjm/neshla/dc3f62501a7007c3f44dbf2519e76fa067adfd29/_democode/font2.chr -------------------------------------------------------------------------------- /_democode/game.as: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * NESHLA Demo Code 3 | * (c) 2003-2005 Brian Provinciano 4 | * http://www.bripro.com 5 | ****************************************************************************** 6 | * BASE.AS 7 | ****************************************************************************** 8 | * The base definition 9 | ******************************************************************************/ 10 | 11 | /******************************************************************************/ 12 | 13 | #ines.mapper "none" 14 | #ines.mirroring "Vertical" 15 | #ines.battery "no" 16 | #ines.trainer "no" 17 | #ines.fourscreen "no" 18 | //#ines.prgrepeat 8 // 128K 19 | 20 | #rom.banksize 16K 21 | #chr.banksize 8K 22 | 23 | /******************************************************************************/ 24 | 25 | 26 | #include "nes.h" 27 | #include "std.h" 28 | 29 | #include "main.h" 30 | 31 | // RAM DEFINITIONS 32 | #include "ramdata.as" 33 | 34 | 35 | /****************************************************************************** 36 | * MAIN CODE // 16K (2 banks) 37 | ******************************************************************************/ 38 | 39 | /******************************************************************************/ 40 | 41 | #rom.bank BANK_MAIN_ENTRY 42 | #rom.org 0xC000 43 | 44 | #interrupt.start main 45 | #interrupt.irq int_irq 46 | #interrupt.nmi int_nmi 47 | 48 | #include "visuals.as" 49 | #include "main.as" 50 | 51 | /******************************************************************************/ 52 | 53 | 54 | /*############################################################################# 55 | # MMMM MM MM MMMM 56 | # MM MM MM MM MM MM 57 | # MM MMMMMM MMMM 58 | # MM MM MM MM MM MM 59 | # MMMM MM MM MM MM 60 | #############################################################################*/ 61 | 62 | #chr.banksize 8K 63 | #chr.bank CHR_FONT_BANK 64 | #incbin "font2.chr" 65 | #chr.end 66 | /******************************************************************************/ 67 | -------------------------------------------------------------------------------- /_democode/main.as: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * NESHLA Demo Code 3 | * (c) 2003-2005 Brian Provinciano 4 | * http://www.bripro.com 5 | ****************************************************************************** 6 | * MAIN.AS 7 | ****************************************************************************** 8 | * The entry/interrupts/main engine 9 | ******************************************************************************/ 10 | 11 | /******************************************************************************/ 12 | 13 | char strTitle[] = "\a\a\a\a\a\a\aNESHLA Demo Program" 14 | char strHello[] = "Hello, World!" 15 | 16 | /****************************************************************************** 17 | * MAIN 18 | ******************************************************************************/ 19 | 20 | /******************************************************************************/ 21 | inline custom_system_initialize() 22 | { 23 | disable_decimal_mode() 24 | disable_interrupts() 25 | 26 | reset_stack() // this is why this MUST be inline! 27 | 28 | // clear the registers 29 | lda #0 30 | 31 | sta PPU.CNT0 32 | sta PPU.CNT1 33 | 34 | sta PPU.BG_SCROLL 35 | sta PPU.BG_SCROLL 36 | 37 | sta PCM_CNT 38 | sta PCM_VOLUMECNT 39 | sta SND_CNT 40 | 41 | lda #0xC0 42 | sta joystick.cnt1 43 | } 44 | /******************************************************************************/ 45 | interrupt.irq int_irq() 46 | { 47 | } 48 | /******************************************************************************/ 49 | interrupt.nmi int_nmi() 50 | { 51 | } 52 | /******************************************************************************/ 53 | interrupt.start main() 54 | { 55 | custom_system_initialize() 56 | 57 | vram_init() 58 | 59 | Turn_Video_Off() 60 | 61 | vram_write_string_inl(NAME_TABLE_0_ADDRESS+(15*32+10), strHello) 62 | vram_clear_address() 63 | 64 | assign(palcol, #COLOUR.YELLOW) 65 | 66 | Turn_Video_On() 67 | 68 | forever { 69 | wait_for(#6) 70 | pal_animate() 71 | } 72 | } 73 | /******************************************************************************/ 74 | function jsr_ind() 75 | { 76 | jmp [paddr] 77 | } 78 | /******************************************************************************/ 79 | -------------------------------------------------------------------------------- /_democode/main.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * NESHLA Demo Code 3 | * (c) 2003-2005 Brian Provinciano 4 | * http://www.bripro.com 5 | ****************************************************************************** 6 | * MAIN.H 7 | ****************************************************************************** 8 | * 9 | ******************************************************************************/ 10 | 11 | 12 | enum COLOUR { 13 | BLUE = 0x01, 14 | RED = 0x05, 15 | YELLOW = 0x07, 16 | GREEN = 0x09, 17 | } 18 | 19 | -------------------------------------------------------------------------------- /_democode/ramdata.as: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * NESHLA Demo Code 3 | * (c) 2003-2005 Brian Provinciano 4 | * http://www.bripro.com 5 | ****************************************************************************** 6 | * RAMDATA.AS 7 | ****************************************************************************** 8 | * All the WRAM declarations 9 | ******************************************************************************/ 10 | 11 | /****************************************************************************** 12 | * ZERO PAGE 13 | ******************************************************************************/ 14 | #ram.org 0x0000, 0x100 // start, max block len 15 | 16 | #include "lib_ram.as" 17 | 18 | byte counter, palcol 19 | pointer paddr, pstr 20 | 21 | char msgbuf[64] 22 | 23 | #ram.end 24 | 25 | /******************************************************************************/ 26 | -------------------------------------------------------------------------------- /_democode/visuals.as: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * NESHLA Demo Code 3 | * (c) 2003-2005 Brian Provinciano 4 | * http://www.bripro.com 5 | ****************************************************************************** 6 | * VISUALS.AS 7 | ****************************************************************************** 8 | * 9 | ******************************************************************************/ 10 | 11 | 12 | /******************************************************************************/ 13 | function Turn_Video_On() 14 | { 15 | assign(PPU.CNT1, #CR_BACKVISIBLE|CR_BACKNOCLIP) 16 | } 17 | /******************************************************************************/ 18 | function Turn_Video_Off() 19 | { 20 | assign(PPU.CNT1, #0) 21 | } 22 | /******************************************************************************/ 23 | function vram_write_hex_a() 24 | { 25 | pha 26 | tax 27 | lsr a 28 | lsr a 29 | lsr a 30 | lsr a 31 | and #$0F 32 | cmp #$A 33 | bcs _hexxy0 34 | clc 35 | adc #$30 36 | jmp _hexxy0d 37 | _hexxy0: 38 | clc 39 | adc #$41-10 40 | _hexxy0d: 41 | 42 | sta $2007 43 | 44 | txa 45 | and #$0F 46 | cmp #$A 47 | bcs _hexxy1 48 | clc 49 | adc #$30 50 | jmp _hexxy1d 51 | _hexxy1: 52 | clc 53 | adc #$41-10 54 | _hexxy1d: 55 | 56 | sta $2007 57 | 58 | pla 59 | } 60 | /******************************************************************************/ 61 | inline vram_write_string_inl(addr, str) 62 | { 63 | vram_set_address_i(addr) 64 | assign_16i(pstr, str) 65 | vram_write_string() 66 | } 67 | /******************************************************************************/ 68 | function vram_write_string() 69 | { 70 | ldy #0 71 | forever { 72 | lda [pstr], y 73 | if(zero) { 74 | vram_clear_address() 75 | return 76 | } 77 | vram_write_a() 78 | iny 79 | } 80 | } 81 | /******************************************************************************/ 82 | byte setamt[] = {0,0,0,0,0,0,0,7} 83 | function vram_init() 84 | { 85 | vram_set_address_i(PAL_ADDRESS) 86 | vram_write(#0x30) 87 | vram_write(#0x21) 88 | vram_write(#0x22) 89 | vram_write(#0x0F) 90 | 91 | vram_set_address_i(NAME_TABLE_0_ADDRESS) 92 | lda #0 93 | ldy #8 // 1024 bytes 94 | do { 95 | lda setamt-1,y 96 | ldx #128 97 | do { 98 | vram_write_a() 99 | dex 100 | } while(not zero) 101 | dey 102 | } while(not zero) 103 | 104 | vram_write_string_inl(NAME_TABLE_0_ADDRESS+0x40, strTitle) 105 | 106 | vram_clear_address() 107 | } 108 | /******************************************************************************/ 109 | // inputs colour in reg.x 110 | function palette_memset() 111 | { 112 | unvblank_wait() 113 | vblank_wait() 114 | 115 | vram_set_address_i(PAL_ADDRESS) 116 | 117 | ldy #16 118 | do { 119 | vram_write_regx() 120 | dey 121 | } while(not equal) 122 | 123 | vram_clear_address() 124 | } 125 | /******************************************************************************/ 126 | inline palette_memset_inl(col) 127 | { 128 | ldx col 129 | palette_memset() 130 | } 131 | /******************************************************************************/ 132 | function pal_animate() 133 | { 134 | vram_set_address_i(PAL_ADDRESS) 135 | 136 | lda palcol 137 | clc 138 | adc #0x10 139 | sta palcol 140 | and #0x40 141 | php 142 | lda palcol 143 | plp 144 | if(set) { 145 | eor #0x30 146 | } 147 | and #0x3F 148 | vram_write_a() 149 | 150 | vram_clear_address() 151 | } 152 | /******************************************************************************/ 153 | function pal_animate2() 154 | { 155 | vram_set_address_i(PAL_ADDRESS) 156 | 157 | ldx palcol 158 | inx 159 | txa 160 | sta palcol 161 | and #0x10 162 | php 163 | lda palcol 164 | plp 165 | if(set) { 166 | eor #0x0F 167 | } 168 | and #0x0F 169 | vram_write_a() 170 | 171 | vram_clear_address() 172 | } 173 | /******************************************************************************/ 174 | inline wait_for(amount) 175 | { 176 | ldx amount 177 | wait_for_func() 178 | } 179 | /******************************************************************************/ 180 | function wait_for_func() 181 | { 182 | do { 183 | vblank_wait_full() 184 | dex 185 | } while(nonzero) 186 | } 187 | /******************************************************************************/ 188 | function message_error() 189 | { 190 | assign(palcol, #COLOUR.RED) 191 | forever { 192 | wait_for(#5) 193 | pal_animate() 194 | } 195 | } 196 | /******************************************************************************/ 197 | -------------------------------------------------------------------------------- /_docs/options.txt: -------------------------------------------------------------------------------- 1 | Usage: 2 | neshla [-options] 3 | 4 | General Options 5 | -o path : Set the destination path for the output files 6 | -h : Display options help 7 | 8 | Message options 9 | 10 | -emax n : Maximum number of errors before stopping (default: 100) 11 | 12 | -wmax n : Maximum number of warnings before stopping (default: 100) 13 | -wlevel n : Warning level 0-2 (default: 1) 14 | 15 | -todo : enable todo preprocessor messages (default: off) 16 | -todomax n : Maximum number of todo messages before stopping (default: 100) 17 | 18 | -tell : enable tell preprocessor messages (default: off) 19 | -tellmax n : Maximum number of tell messages before stopping (default: 100) 20 | 21 | 22 | Stats/Logs 23 | 24 | -listvars : output file [game].vlst with stats on each variable and it's memory usage/properties (default: off) 25 | -listfuncs : output file [game].flst with stats on each function file and it's address/type (default: off) 26 | -listbanks : output file [game].blst with stats on each bank and it's memory usage (default: off) 27 | -listsrc : output file [game].slst with stats on each source file and it's memory usage (default: off) 28 | 29 | 30 | Output Options 31 | 32 | -outraw : output raw .prg and .chr binaries (default: off) 33 | -nopadding : pad the output ROMs up to the nearest solid size (default: off) 34 | -noheader : output ROM file without 16 byte iNES header (default: off) -------------------------------------------------------------------------------- /compiler.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #pragma hdrstop 12 | #include 13 | #include "compiler.h" 14 | 15 | #pragma package(smart_init) 16 | 17 | 18 | 19 | void PrintTime(void); 20 | 21 | int main(int argc, char* argv[]) 22 | { 23 | int c, i, l; 24 | char* s, *p; 25 | 26 | clock_t start, end; 27 | start = clock(); 28 | 29 | message(0, "Nintendo NES High Level Assembler"); 30 | message(0, "Version %s, %s", SZ_VERSION, SZ_BUILD_DATE); 31 | message(0, "By Brian Provinciano :: http://www.bripro.com"); 32 | message(0, ""); 33 | 34 | if (argc < 1) 35 | return 3; 36 | 37 | s = argv[0]; 38 | if (strlen(s) > 3 && (s[1] == ':')) { 39 | strcpy(szprogdir, argv[0]); 40 | l = strlen(szprogdir) - 1; 41 | s = szprogdir + l; 42 | while (l > 0) { 43 | if (*s == PATH_SEP) { 44 | *s = '\0'; 45 | break; 46 | } 47 | s--; 48 | } 49 | } else { 50 | if (!getcwd(szprogdir, sizeof(szprogdir) - 1)) 51 | return 3; 52 | } 53 | 54 | l = strlen(szprogdir); 55 | if (l && szprogdir[l - 1] != PATH_SEP) { 56 | szprogdir[l] = PATH_SEP; 57 | szprogdir[l + 1] = '\0'; 58 | } 59 | 60 | if (!InitConfig()) 61 | return 4; 62 | ParseCommandLine(argc, argv); 63 | 64 | sysDirList = includeDirList = libDirList = NULL; 65 | 66 | l = strlen(szoutdir); 67 | if (l && szoutdir[l - 1] != PATH_SEP) { 68 | szoutdir[l] = PATH_SEP; 69 | szoutdir[l + 1] = '\0'; 70 | } 71 | strcpy(outDir, szoutdir); 72 | 73 | sprintf(szTemp, "%s", szprogdir); 74 | AddDirList(&sysDirList, szTemp); 75 | message(0, "Adding dir %s", szTemp); 76 | 77 | sprintf(szTemp, "%sinclude%c", szprogdir, PATH_SEP); 78 | message(0, "Adding dir %s", szTemp); 79 | AddDirList(&includeDirList, szTemp); 80 | 81 | sprintf(szTemp, "%slib%c", szprogdir, PATH_SEP); 82 | message(0, "Adding dir %s", szTemp); 83 | AddDirList(&libDirList, szTemp); 84 | 85 | if (InitializeCompiler()) { 86 | message(0, "Compiling file: %s ...", szfilename); 87 | DoCompile(szfilename); 88 | } 89 | 90 | { 91 | float fl = (clock() - start) / CLOCKS_PER_SEC; 92 | printf("The time was: %f\n", fl); 93 | } 94 | 95 | if (COMPILE_SUCCESS) { 96 | ShutDownCompiler(); 97 | PrintTime(); 98 | message(MSG_COMPSUCCESS); 99 | } else // automatically shuts down 100 | fatal(FTL_COMPFAIL); 101 | message(0, ""); 102 | 103 | return 0; 104 | } 105 | 106 | BOOL DoCompile(char* szFilename) 107 | { 108 | BOOL result; 109 | 110 | result = CompileScript(szFilename, NULL, NULL); 111 | 112 | if (cfg.list.sourcesize && fSrcList) { 113 | CloseFile(fSrcList); 114 | } 115 | return result; 116 | } 117 | 118 | void PrintTime() 119 | { 120 | time_t t; 121 | char* s; 122 | 123 | time(&t); 124 | s = ctime(&t); 125 | 126 | message(0, ""); 127 | message(0, "%s", s); 128 | 129 | //free(s); 130 | } 131 | 132 | 133 | /* 134 | FILE *f = fopen("e:\\neshla\\_design\\mappershtml.txt","w"); 135 | 136 | STRINT *si = siMappers, **sip, *sp; 137 | int cnt=0; 138 | STRINT **sints; 139 | while(si->string[0]) { 140 | si++; 141 | cnt++; 142 | } 143 | sints = (STRINT**)malloc(sizeof(STRINT*)*cnt); 144 | sip = sints; 145 | si = siMappers;; 146 | while(si->string[0]) { 147 | *sip++ = si; 148 | si++; 149 | } 150 | 151 | moo: 152 | i = 1; 153 | while(istring,sints[i]->string)>0) { 155 | sp = sints[i-1]; 156 | sints[i-1] = sints[i]; 157 | sints[i] = sp; 158 | goto moo; 159 | } 160 | i++; 161 | } 162 | 163 | i = 0; 164 | while(i"); 167 | fprintf(f,"
%s
", si->string); 168 | fprintf(f,"
%d
", si->index); 169 | fprintf(f,"\n"); 170 | si++; 171 | } 172 | fclose(f); 173 | 174 | free(sints); */ 175 | 176 | /* 177 | 178 | FILE *f = fopen("e:\\neshla\\_design\\condhtml.txt","w"); 179 | 180 | i = 0; 181 | while(siConditions[i].string[0]) { 182 | fprintf(f,""); 183 | fprintf(f,"
%s
", siConditions[i].string); 184 | fprintf(f,"
%s
", GetOpcodeName(siConditions[i].index)); 185 | fprintf(f,"\n"); 186 | i++; 187 | } 188 | fclose(f);*/ 189 | -------------------------------------------------------------------------------- /compiler.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #ifndef compilerH 12 | #define compilerH 13 | 14 | #define SZ_VERSION "1.0.0" 15 | #define SZ_BUILD_DATE "April 12th, 2005" //"December 19th, 2003" 16 | 17 | 18 | #include 19 | #include 20 | #include 21 | //#include 22 | #include 23 | #include 24 | #include 25 | 26 | #include "typedefs.h" 27 | 28 | #include "system/message.h" 29 | #include "system/memalloc.h" 30 | #include "system/fileio.h" 31 | #include "system/config.h" 32 | 33 | #include "init.h" 34 | #include "list.h" 35 | #include "strhand.h" 36 | #include "scrbase.h" 37 | 38 | #include "opcodes.h" 39 | #include "opcodetable.h" 40 | 41 | #include "getcode.h" 42 | 43 | #include "prepbase.h" 44 | 45 | #include "vars.h" 46 | #include "functions.h" 47 | #include "labels.h" 48 | 49 | #include "output/outbuf.h" 50 | #include "output/fixoffs.h" 51 | #include "output/writecode.h" 52 | #include "output/scrbin.h" 53 | #include "output/banks.h" 54 | 55 | #include "data/data.h" 56 | 57 | 58 | #define STRCMP ssStrCmp 59 | 60 | BOOL DoCompile(char* szFilename); 61 | 62 | #endif 63 | 64 | -------------------------------------------------------------------------------- /data/data.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #ifndef dataH 12 | #define dataH 13 | 14 | extern STRINT siMappers[]; 15 | 16 | #endif 17 | 18 | 19 | -------------------------------------------------------------------------------- /data/mappers.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #pragma hdrstop 12 | #include "../compiler.h" 13 | /****************************************************************************** 14 | * board names and mapper numbers 15 | ******************************************************************************/ 16 | #pragma package(smart_init) 17 | 18 | 19 | STRINT siMappers[] = { 20 | 21 | {"NONE", 0}, 22 | {"NROM", 0}, 23 | {"NES-NROM", 0}, 24 | 25 | {"MMC1", 1}, 26 | {"S*ROM", 1}, 27 | {"SAROM", 1}, 28 | {"SBROM", 1}, 29 | {"SCROM", 1}, 30 | {"SEROM", 1}, 31 | {"SGROM", 1}, 32 | {"SKROM", 1}, 33 | {"SLROM", 1}, 34 | {"SL1ROM", 1}, 35 | {"SNROM", 1}, 36 | {"SOROM", 1}, 37 | {"NES-MMC1", 1}, 38 | {"NES-S*ROM", 1}, 39 | {"NES-SAROM", 1}, 40 | {"NES-SBROM", 1}, 41 | {"NES-SCROM", 1}, 42 | {"NES-SEROM", 1}, 43 | {"NES-SGROM", 1}, 44 | {"NES-SKROM", 1}, 45 | {"NES-SLROM", 1}, 46 | {"NES-SL1ROM", 1}, 47 | {"NES-SNROM", 1}, 48 | {"NES-SOROM", 1}, 49 | 50 | {"U*ROM", 2}, 51 | {"UNROM", 2}, 52 | {"UOROM", 2}, 53 | {"NES-U*ROM", 2}, 54 | {"NES-UNROM", 2}, 55 | {"NES-UOROM", 2}, 56 | 57 | {"CNROM", 3}, 58 | {"NES-CNROM", 3}, 59 | 60 | {"MMC3", 4}, 61 | {"MMC6", 4}, 62 | {"T*ROM", 4}, 63 | {"TFROM", 4}, 64 | {"TGROM", 4}, 65 | {"TKROM", 4}, 66 | {"TLROM", 4}, 67 | {"TR1ROM", 4}, 68 | {"TSROM", 4}, 69 | {"NES-B4", 4}, 70 | {"H*ROM", 4}, 71 | {"HKROM", 4}, 72 | {"NES-MMC3", 4}, 73 | {"NES-MMC6", 4}, 74 | {"NES-T*ROM", 4}, 75 | {"NES-TFROM", 4}, 76 | {"NES-TGROM", 4}, 77 | {"NES-TKROM", 4}, 78 | {"NES-TLROM", 4}, 79 | {"NES-TR1ROM", 4}, 80 | {"NES-TSROM", 4}, 81 | {"NES-NES-B4", 4}, 82 | {"NES-H*ROM", 4}, 83 | {"NES-HKROM", 4}, 84 | 85 | {"MMC5", 5}, 86 | {"E*ROM", 5}, 87 | {"EKROM", 5}, 88 | {"ELROM", 5}, 89 | {"ETROM", 5}, 90 | {"EWROM", 5}, 91 | {"NES-MMC5", 5}, 92 | {"NES-E*ROM", 5}, 93 | {"NES-EKROM", 5}, 94 | {"NES-ELROM", 5}, 95 | {"NES-ETROM", 5}, 96 | {"NES-EWROM", 5}, 97 | 98 | {"FFE F4", 6}, 99 | 100 | {"A*ROM", 7}, 101 | {"AMROM", 7}, 102 | {"ANROM", 7}, 103 | {"AOROM", 7}, 104 | {"NES-A*ROM", 7}, 105 | {"NES-AMROM", 7}, 106 | {"NES-ANROM", 7}, 107 | {"NES-AOROM", 7}, 108 | 109 | {"FFE F3", 8}, 110 | 111 | {"MMC2", 9}, 112 | {"P*ROM", 9}, 113 | {"PNROM", 9}, 114 | {"PEEOROM", 9}, 115 | {"NES-MMC2", 9}, 116 | {"NES-P*ROM", 9}, 117 | {"NES-PNROM", 9}, 118 | {"NES-PEEOROM", 9}, 119 | 120 | {"MMC4", 10}, 121 | {"NES-MMC4", 10}, 122 | 123 | {"Color Dreams", 11}, 124 | 125 | {"CPROM", 13}, 126 | 127 | {"100-in-1 Contra Function 16", 15}, 128 | 129 | {"Bandai", 16}, 130 | 131 | {"FFE F8", 17}, 132 | 133 | {"Jaleco SS8806", 18}, 134 | 135 | {"Namcot 106", 19}, 136 | 137 | {"Konami VRC4", 21}, 138 | {"VRC4", 21}, 139 | 140 | {"Konami VRC2 Type A", 22}, 141 | {"Konami VRC2 A", 22}, 142 | {"VRC2 A", 22}, 143 | 144 | {"Konami VRC2 Type B", 23}, 145 | {"Konami VRC2 B", 23}, 146 | {"VRC2 B", 23}, 147 | 148 | {"Konami VRC6 A1/A0", 24}, 149 | {"VRC6 A1/A0", 24}, 150 | 151 | {"Konami VRC4 Type Y", 25}, 152 | {"Konami VRC4 Y", 25}, 153 | {"VRC4 Y", 25}, 154 | 155 | {"Irem G-101", 32}, 156 | 157 | {"Taito TC0190", 33}, 158 | {"TC0190", 33}, 159 | 160 | {"BNROM", 34}, 161 | {"NES-BNROM", 34}, 162 | {"Nina-01", 34}, 163 | 164 | {"SMB2j Pirate", 40}, 165 | 166 | {"Caltron 6-in-1", 41}, 167 | 168 | {"Mario Baby", 42}, 169 | 170 | {"SMB2j (LF36)", 43}, 171 | 172 | {"Super HiK 7 in 1 (MMC3)", 44}, 173 | 174 | {"Super 1,000,000 in 1 (MMC3)", 45}, 175 | 176 | {"GameStation/RumbleStation", 46}, 177 | 178 | {"Super Spike & Nintendo World Cup Soccer (MMC3)", 47}, 179 | {"Super Spike/World Cup", 47}, 180 | 181 | {"1993 Super HiK 4-in-1 (MMC3)", 49}, 182 | 183 | {"SMB2j rev. A", 50}, 184 | 185 | {"11 in 1 Ball Games", 51}, 186 | 187 | {"Mario 7 in 1 (MMC3)", 52}, 188 | 189 | {"SMB3 Pirate", 56}, 190 | 191 | {"Study & Game 32 in 1", 58}, 192 | 193 | {"T3H53", 59}, 194 | 195 | {"T3H53", 59}, 196 | 197 | {"20-in-1", 61}, 198 | 199 | {"700-in-1", 62}, 200 | 201 | {"Hello Kitty 255 in 1", 63}, 202 | 203 | {"Tengen RAMBO-1", 64}, 204 | {"RAMBO-1", 64}, 205 | 206 | {"Irem H-3001", 65}, 207 | 208 | {"GNROM", 66}, 209 | {"NES-GNROM", 66}, 210 | 211 | {"Sunsoft Mapper #3", 67}, 212 | {"Sunsoft 3", 67}, 213 | 214 | {"Sunsoft Mapper #4", 68}, 215 | {"Sunsoft 4", 68}, 216 | 217 | {"Sunsoft FME-07", 69}, 218 | {"FME-07", 69}, 219 | 220 | {"Camerica (partial)", 71}, 221 | 222 | {"Konami VRC3", 73}, 223 | {"VRC3", 73}, 224 | 225 | {"Konami VRC1", 75}, 226 | {"VRC1", 75}, 227 | 228 | {"Irem 74161/32", 78}, 229 | 230 | {"NINA-03", 79}, 231 | {"NINA-06", 79}, 232 | 233 | {"Cony", 83}, 234 | 235 | {"Konami VRC7", 85}, 236 | {"VRC7", 85}, 237 | 238 | {"Copyright", 90}, 239 | {"Mapper 90", 90}, 240 | {"Super Mario World", 90}, 241 | 242 | {"PC-HK-SF3", 91}, 243 | 244 | {"Dragon Buster (MMC3 variant)", 95}, 245 | {"Dragon Buster", 95}, 246 | 247 | {"Kid Niki (J)", 97}, 248 | 249 | {"VS Unisystem", 99}, 250 | {"Nintendo VS Unisystem", 99}, 251 | 252 | {"Debugging Mapper", 100}, 253 | 254 | {"Nintendo World Championship", 105}, 255 | 256 | {"HES-Mapper #113", 113}, 257 | 258 | {"TKSROM", 118}, 259 | {"TLSROM", 118}, 260 | {"NES-TKSROM", 118}, 261 | {"NES-TLSROM", 118}, 262 | 263 | {"TQROM", 119}, 264 | {"NES-TQROM", 119}, 265 | 266 | {"Sachen Mapper 141", 141}, 267 | 268 | {"SMB2j Pirate (KS 202)", 142}, 269 | {"KS 202", 142}, 270 | 271 | {"Sachen Copy Protection", 143}, 272 | 273 | {"AGCI", 144}, 274 | 275 | {"Extended VS Unisystem", 151}, 276 | {"Nintendo VS Unisystem (Extended)", 151}, 277 | 278 | {"Super Donkey Kong", 182}, 279 | 280 | {"72-in-1", 225}, 281 | 282 | {"76-in-1", 226}, 283 | 284 | {"1200-in-1", 227}, 285 | 286 | {"Action 52", 228}, 287 | 288 | {"31-in-1", 229}, 289 | 290 | {"Camerica 9096", 232}, 291 | 292 | {"Maxi 15", 234}, 293 | 294 | {"Golden Game 150-in-1", 235}, 295 | 296 | {"Sachen 74LS374N", 243}, 297 | 298 | 299 | {"", 0}, 300 | }; 301 | 302 | -------------------------------------------------------------------------------- /expressions/exp_asm.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #ifndef asmH 12 | #define asmH 13 | 14 | #include "../getcode.h" 15 | 16 | 17 | 18 | 19 | BOOL comProc_Asm(U16 flags, S16* brackCnt); 20 | BOOL GetOperands(int opid); 21 | 22 | #endif 23 | 24 | -------------------------------------------------------------------------------- /expressions/exp_funccall.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #pragma hdrstop 12 | #include "../compiler.h" 13 | /****************************************************************************** 14 | * Handles the rest of the valid expressions 15 | ******************************************************************************/ 16 | #pragma package(smart_init) 17 | 18 | 19 | char szParam[1024]; 20 | char* GetParamBlock() 21 | { 22 | int bracks = 0; 23 | szParam[0] = '\0'; 24 | 25 | //USE_DEFS = FALSE; 26 | while (GetNextWord()[0]) { 27 | if (szTemp[0] == '.') { 28 | USE_DEFS = FALSE; 29 | 30 | while (szTemp[0] == '.') { 31 | strcat(szParam, szTemp); 32 | if (!GetNextWord()[0]) 33 | break; 34 | strcat(szParam, szTemp); 35 | GetNextWord(); 36 | } 37 | 38 | USE_DEFS = TRUE; 39 | if (!szTemp[0]) 40 | break; 41 | } 42 | if (szTemp[0] == '(') { 43 | bracks++; 44 | strcat(szParam, szTemp); 45 | } else if (szTemp[0] == ')') { 46 | if (!bracks) { 47 | break; 48 | } 49 | bracks--; 50 | strcat(szParam, szTemp); 51 | } else if (szTemp[0] == ',') { 52 | if (bracks) { 53 | 54 | } else 55 | break; 56 | } else if (szTemp[0] == '"') { 57 | strcat(szParam, DoStringDirect()); 58 | } else if (szTemp[0] == '\'') { 59 | strcat(szParam, GetCharString()); 60 | } else { 61 | strcat(szParam, szFull); 62 | } 63 | } 64 | //USE_DEFS = TRUE; 65 | 66 | return szParam; 67 | } 68 | 69 | 70 | void SeekThroughParamBlock() 71 | { 72 | int bracks = 0; 73 | 74 | while (GetNextWord()[0]) { 75 | if (szTemp[0] == '.') { 76 | USE_DEFS = FALSE; 77 | 78 | while (szTemp[0] == '.') { 79 | if (!GetNextWord()[0]) 80 | break; 81 | GetNextWord(); 82 | } 83 | 84 | USE_DEFS = TRUE; 85 | if (!szTemp[0]) 86 | break; 87 | } 88 | if (szTemp[0] == '(') { 89 | bracks++; 90 | } else if (szTemp[0] == ')') { 91 | if (!bracks) { 92 | break; 93 | } 94 | bracks--; 95 | } else if (szTemp[0] == ',') { 96 | if (bracks) { 97 | 98 | } else 99 | break; 100 | } else if (szTemp[0] == '"') { 101 | DoStringDirect(); 102 | } else if (szTemp[0] == '\'') { 103 | GetCharString(); 104 | } 105 | } 106 | } 107 | 108 | BOOL comProc_FunctionCall(U16 flags, S16* brackCnt) 109 | { 110 | FUNC* func, *f_macro; 111 | int pnum; 112 | PARAM* param; 113 | 114 | if ((func = FindFunction(functions, szTemp)) == NULL) 115 | return FALSE; 116 | 117 | func->flags |= FUNCFLAG_USED; 118 | CheckoutCurVar(); 119 | 120 | switch (func->type) { 121 | case FUNCTYPE_FUNCTION: 122 | case FUNCTYPE_INTERRUPT: 123 | if (!PRECOMPILING) { 124 | WriteOpcode(func->type == FUNCTYPE_FUNCTION ? opJSR_ABS : opJMP_ABS); 125 | AddFixOffs(FIXTYPE_FUNCTION, FIXOFFS_FAR, curBank->ptr, GetBankOffset() + 2, func); 126 | WriteCodeW(0); 127 | } 128 | break; 129 | case FUNCTYPE_INLINE: // der macros! 130 | f_macro = MakeCurMacro(func); 131 | if (PRECOMPILING) { 132 | if (PeekNextWord()[0] == '(') { 133 | GetNextWord(); 134 | pnum = 0; 135 | if (f_macro->params) { 136 | for (;;) { 137 | SeekThroughParamBlock(); 138 | if (szTemp[0] == ')') { 139 | break; 140 | } else if (szTemp[0] != ',') { 141 | SeekPastWord(")"); 142 | break; 143 | } 144 | } 145 | } else { 146 | if (GetNextWord()[0] != ')') { 147 | error(ERR_FUNCENDEXP, f_macro->label); 148 | SeekPastWord(")"); 149 | } 150 | } 151 | } 152 | } else { 153 | if (PeekNextWord()[0] == '(') { 154 | GetNextWord(); 155 | pnum = 0; 156 | if (f_macro->params) { 157 | for (;;) { 158 | if (!SetParameter(f_macro, pnum++, GetParamBlock())) { 159 | error(ERR_FUNCFRAMESIZE, f_macro->label); 160 | SeekPastWord(")"); 161 | break; 162 | } 163 | if (szTemp[0] == ')') { 164 | break; 165 | } else if (szTemp[0] != ',') { 166 | SeekPastWord(")"); 167 | break; 168 | } 169 | } 170 | if ((param = SetParameter(f_macro, pnum, "")) != NULL) { 171 | error(ERR_FUNCNEEDSPARAM, f_macro->label, param->def.label); 172 | } 173 | } else { 174 | if (GetNextWord()[0] != ')') { 175 | error(ERR_FUNCENDEXP, f_macro->label); 176 | SeekPastWord(")"); 177 | } 178 | } 179 | } else { 180 | if (func->params) { 181 | error(ERR_FUNCNEEDSPARAMS, func->label); 182 | SkipLine(FALSE); 183 | break; 184 | } 185 | } 186 | SetCurMacro(f_macro); 187 | CompileScript(f_macro->label, NULL, f_macro); 188 | GetCode(flags | CF_GETNEXTWORD | CF_BRACEOK, brackCnt); 189 | } 190 | break; 191 | } 192 | 193 | return TRUE; 194 | } 195 | 196 | -------------------------------------------------------------------------------- /expressions/exp_funccall.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #ifndef funccallH 12 | #define funccallH 13 | 14 | #include "../getcode.h" 15 | 16 | 17 | 18 | char* GetParamBlock(void); 19 | void SeekThroughParamBlock(void); 20 | BOOL comProc_FunctionCall(U16 flags, S16* brackCnt); 21 | 22 | #endif 23 | 24 | -------------------------------------------------------------------------------- /expressions/exp_funcdeclare.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #pragma hdrstop 12 | #include "../compiler.h" 13 | /****************************************************************************** 14 | * Handles variable declarations 15 | ******************************************************************************/ 16 | #pragma package(smart_init) 17 | 18 | void ParseMacroBlock(FUNC* func) 19 | { 20 | OUTBUF macroBlock; 21 | int braceCnt = 0, sl; 22 | S16 brackCnt = 0; 23 | BOOL MAC_EXCEED = FALSE; 24 | 25 | macker = func; 26 | 27 | SetupOutbuf(¯oBlock, MAX_MACRO_SIZE); 28 | do { 29 | 30 | NEWLINE = FALSE; 31 | GetNextWord(); 32 | 33 | // handle the optional brace enclosure 34 | if (*szTemp == '{') { 35 | obPutB(¯oBlock, (NEWLINE) ? '\n' : ' '); 36 | obPutB(¯oBlock, *szTemp); 37 | if (braceCnt >= 0x7FFE) 38 | fatal(FTL_TOOMANYBRACES); 39 | braceCnt++; 40 | continue; 41 | } 42 | 43 | if (*szTemp == '}') { 44 | obPutB(¯oBlock, (NEWLINE) ? '\n' : ' '); 45 | obPutB(¯oBlock, *szTemp); 46 | if (!braceCnt) 47 | error(ERR_BRACECLOSENOTALLOWED); 48 | else if (!--braceCnt) 49 | break; 50 | continue; 51 | } 52 | 53 | // write the word 54 | sl = (int)strlen(szTemp); 55 | if (!MAC_EXCEED) { 56 | if (OB_SIZE(macroBlock) + sl + 3 > MAX_MACRO_SIZE) { 57 | MAC_EXCEED = TRUE; 58 | error(ERR_MACROTOOLARGE, func->label, MAX_MACRO_SIZE); 59 | } else { 60 | if (NEWLINE) 61 | obPutB(¯oBlock, '\n'); 62 | else { 63 | if (IsCharLabel(obPeekB(¯oBlock, -1)) && IsCharLabel(szTemp[0])) 64 | obPutB(¯oBlock, ' '); 65 | } 66 | WriteOutbuf(¯oBlock, szTemp, sl); 67 | if (comProc_LabelDeclaration(0, &brackCnt)) { 68 | obPutB(¯oBlock, ':'); 69 | } 70 | } 71 | } 72 | 73 | } while (braceCnt); 74 | if (!MAC_EXCEED) { 75 | obPutB(¯oBlock, '\0'); 76 | } 77 | 78 | macker = NULL; 79 | 80 | func->macDef = macroBlock.buffer; 81 | } 82 | 83 | BOOL comProc_FuncDeclare(U16 flags, S16* brackCnt) 84 | { 85 | int type, subtype; 86 | U16 funcFlags = 0; 87 | char* label = NULL; 88 | FUNC* func; 89 | 90 | if ((type = IsFuncType(szTemp)) == -1) 91 | return FALSE; 92 | 93 | if (!STRCMP(GetNextWord(), ".")) { 94 | GetNextWord(); 95 | if (type != FUNCTYPE_INTERRUPT) 96 | error(ERR_SUBFUNCTYPENONINT); 97 | else { 98 | if (-1 != (subtype = StrInList(szTemp, szIntTypes))) 99 | FUNCFLAG_MAKETYPE(funcFlags, subtype); 100 | else 101 | error(ERR_SUBFUNCTYPEBAD, szTemp); 102 | } 103 | GetNextWord(); 104 | } 105 | 106 | if (!STRCMP(szTemp, "noreturn")) { 107 | if (type == FUNCTYPE_INLINE) 108 | error(ERR_NORETURN_INLINE); 109 | else 110 | funcFlags |= FUNCFLAG_NORET; 111 | GetNextWord(); 112 | } 113 | 114 | if (!IsStringLabel(szTemp)) { 115 | error(ERR_BADLABEL, szTemp); 116 | } 117 | label = strdup(szTemp); 118 | //if(! strcmp(label,"Car_CheckCollisions_Sprites_CarBSub") ) 119 | // label=label; 120 | 121 | if (PRECOMPILING) { 122 | func = AddFunction(label, type); 123 | func->flags |= funcFlags; 124 | } else { 125 | func = FindFunction(functions, label); 126 | if (func == NULL) { 127 | fatal(FTL_FUNCTIONERR); 128 | } 129 | if (func->type != FUNCTYPE_INLINE) 130 | func->offset = GetBankOffset(); 131 | } 132 | 133 | if (GetNextWord()[0] != '(') { 134 | error(ERR_FUNCDECINBRACK, label); 135 | } else { 136 | if (type == FUNCTYPE_INLINE) { 137 | if (!PRECOMPILING) { 138 | SeekPastWord(")"); 139 | } else if (GetNextWord()[0] != ')') { 140 | for (;;) { 141 | if (!AddParameter(func, szTemp)) { 142 | SeekPastWord(")"); 143 | break; 144 | } 145 | if (GetNextWord()[0] == ')') { 146 | break; 147 | } else if (szTemp[0] != ',') { 148 | SeekPastWord(")"); 149 | break; 150 | } 151 | GetNextWord(); 152 | } 153 | } 154 | } else if (GetNextWord()[0] != ')') { 155 | error(ERR_FUNCPARAMSNOTINLINE, label); 156 | SeekPastWord(")"); 157 | } 158 | } 159 | 160 | ssFree(label); 161 | 162 | if (type == FUNCTYPE_INLINE) { 163 | if (PRECOMPILING) { 164 | ParseMacroBlock(func); 165 | } else 166 | SeekPastBraceBlock(); 167 | } else { 168 | //if(!cfg.func.stripUnused || (func->flags&FUNCFLAG_USED)) { 169 | curFunction = func; 170 | 171 | GetCode(flags | CF_BRACEOK | CF_GETNEXTWORD, brackCnt); 172 | 173 | if (!(func->flags & FUNCFLAG_NORET)) 174 | WriteReturn(); 175 | 176 | ReleaseCurFunc(); 177 | //} else 178 | // SeekPastBraceBlock(); 179 | } 180 | 181 | return TRUE; 182 | } 183 | 184 | -------------------------------------------------------------------------------- /expressions/exp_funcdeclare.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #ifndef funcdeclareH 12 | #define funcdeclareH 13 | 14 | #include "../getcode.h" 15 | 16 | #define MAX_MACRO_SIZE 8192 17 | 18 | 19 | BOOL comProc_FuncDeclare(U16 flags, S16* brackCnt); 20 | 21 | #endif 22 | 23 | -------------------------------------------------------------------------------- /expressions/exp_general.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #pragma hdrstop 12 | #include "../compiler.h" 13 | /****************************************************************************** 14 | * Handles the rest of the valid expressions 15 | ******************************************************************************/ 16 | #pragma package(smart_init) 17 | 18 | 19 | 20 | BOOL comProc_General(U16 flags, S16* brackCnt) 21 | { 22 | if (!STRCMP(szTemp, "return")) { 23 | WriteReturn(); 24 | } else { 25 | switch (*szTemp) { 26 | default: 27 | return FALSE; 28 | } 29 | } 30 | return TRUE; 31 | } 32 | 33 | -------------------------------------------------------------------------------- /expressions/exp_general.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #ifndef generalH 12 | #define generalH 13 | 14 | #include "../getcode.h" 15 | 16 | 17 | 18 | 19 | BOOL comProc_General(U16 flags, S16* brackCnt); 20 | 21 | #endif 22 | 23 | -------------------------------------------------------------------------------- /expressions/exp_ifloop.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #pragma hdrstop 12 | #include "../compiler.h" 13 | /****************************************************************************** 14 | * Handles the if/while expressions 15 | ******************************************************************************/ 16 | #pragma package(smart_init) 17 | 18 | 19 | STRINT siConditions[] = { 20 | { "plus", opBPL_REL }, 21 | { "positive", opBPL_REL }, 22 | { "greater", opBPL_REL }, 23 | 24 | { "minus", opBMI_REL }, 25 | { "negative", opBMI_REL }, 26 | 27 | { "overflow", opBVC_REL }, 28 | 29 | { "carry", opBCS_REL }, 30 | { "greatereq", opBCS_REL }, 31 | 32 | { "lessthan", opBCC_REL }, 33 | 34 | { "nonzero", opBNE_REL }, 35 | { "set", opBNE_REL }, 36 | { "true", opBNE_REL }, 37 | { "1", opBNE_REL }, 38 | 39 | { "equal", opBEQ_REL }, 40 | { "zero", opBEQ_REL }, 41 | { "false", opBEQ_REL }, 42 | { "unset", opBEQ_REL }, 43 | { "clear", opBEQ_REL }, 44 | { "0", opBEQ_REL }, 45 | 46 | { "", 0 }, 47 | }; 48 | 49 | STRINT siIsNot[] = { 50 | { "is", 1 }, 51 | 52 | { "has", 1 }, 53 | 54 | { "no", 0 }, 55 | 56 | { "not", 0 }, 57 | 58 | { "", 0 }, 59 | }; 60 | 61 | #define IFMODE_IF 0 62 | #define IFMODE_WHILE 1 63 | #define IFMODE_DOWHILE 2 64 | STRINT siIffys[] = { 65 | { "if", IFMODE_IF }, 66 | { "while", IFMODE_WHILE }, 67 | { "do", IFMODE_DOWHILE }, 68 | { "", 0 }, 69 | }; 70 | 71 | BOOL comProc_IfLoop(U16 flags, S16* brackCnt) 72 | { 73 | BOOL BRACK = FALSE, FAR_BRANCH = FALSE, FLIPOP; 74 | S32 start, whilestart, offset; 75 | BANK* bank; 76 | U8* condPtr, *elsePtr; 77 | int index, mode; 78 | 79 | CheckCurBank(); 80 | 81 | if ((mode = StrInStrint(szTemp, siIffys)) != -1) { 82 | 83 | if (mode == IFMODE_DOWHILE) { 84 | bank = curBank; 85 | start = GetBankOffset(); 86 | if (STRCMP(GetNextWord(), "while")) { 87 | // 'ist der code block! 88 | GetCode(flags | CF_BRACEOK, brackCnt); 89 | if (STRCMP(GetNextWord(), "while")) 90 | error(ERR_WHILEEXP, szTemp); 91 | } 92 | } 93 | 94 | if (GetNextWord()[0] != '(') 95 | error(ERR_INVCOND, szTemp); 96 | else { 97 | GetNextWord(); 98 | BRACK = TRUE; 99 | } 100 | 101 | USE_DEFS = FALSE; 102 | if (!STRCMP(szTemp, "far")) { 103 | FAR_BRANCH = TRUE; 104 | GetNextWord(); 105 | } else if (!STRCMP(szTemp, "near")) { 106 | GetNextWord(); 107 | } 108 | 109 | // parse the "is" "is not" "not" "no", etc. 110 | FLIPOP = FALSE; 111 | while ((index = StrInStrint(szTemp, siIsNot)) != -1) { 112 | if (!siIsNot[index].index) 113 | FLIPOP = !FLIPOP; 114 | GetNextWord(); 115 | } 116 | 117 | USE_DEFS = TRUE; 118 | if (!PRECOMPILING) { 119 | if ((index = StrInStrint(szTemp, siConditions)) == -1) { 120 | error(ERR_INVALIDCOND, szTemp); 121 | condPtr = NULL; 122 | } else { 123 | if (mode == IFMODE_IF || mode == IFMODE_WHILE) 124 | FLIPOP = !FLIPOP; 125 | index = (FLIPOP) ? RelSwapOp(siConditions[index].index) : siConditions[index].index; 126 | 127 | if (mode == IFMODE_WHILE) 128 | whilestart = GetBankOffset(); 129 | 130 | if (FAR_BRANCH) { 131 | WriteOpcodeB(RelSwapOp(index), 3); 132 | WriteOpcode(opJMP_ABS); 133 | condPtr = curBank->ptr; 134 | WriteCodeW(0); 135 | } else { 136 | condPtr = curBank->ptr + 1; 137 | WriteOpcodeB(index, 0); 138 | } 139 | } 140 | if (mode != IFMODE_DOWHILE) { 141 | bank = curBank; 142 | start = GetBankOffset(); 143 | } 144 | } 145 | 146 | if (BRACK && GetNextWord()[0] != ')') { 147 | error(ERR_IFCONDCLOSEEXP, szTemp); 148 | } 149 | 150 | if (mode != IFMODE_DOWHILE) 151 | GetCode(flags | CF_BRACEOK | CF_GETNEXTWORD, brackCnt); 152 | 153 | elsePtr = NULL; 154 | if (!STRCMP(PeekNextWord(), "else")) { 155 | GetNextWord(); 156 | if (mode != IFMODE_IF) 157 | error(ERR_ONLYIFSELSE); 158 | else { 159 | if (!PRECOMPILING) 160 | WriteOpcode(opJMP_ABS); 161 | elsePtr = curBank->ptr; 162 | if (!PRECOMPILING) 163 | WriteCodeW(0); 164 | } 165 | } 166 | 167 | if (!PRECOMPILING) { 168 | if (bank != curBank) 169 | error(ERR_FOREVEROUTOFBANK, bank->label, curBank->label); 170 | else if (condPtr) { 171 | if (mode == IFMODE_WHILE) { 172 | WriteOpcodeW(opJMP_ABS, whilestart); 173 | } 174 | if (FAR_BRANCH) { 175 | if (mode == IFMODE_DOWHILE) { 176 | PUTW(condPtr, start); 177 | } else { 178 | PUTW(condPtr, GetBankOffset()); 179 | } 180 | } else { 181 | offset = mode == IFMODE_DOWHILE ? start - GetBankOffset() : GetBankOffset() - start; 182 | 183 | if ((offset < -128 || offset > 127)) 184 | error(ERR_BRANCHOUTOFRANGE); 185 | else 186 | PUTB(condPtr, (U8)offset); 187 | } 188 | } 189 | } 190 | if (elsePtr) { 191 | GetCode(flags | CF_BRACEOK | CF_GETNEXTWORD, brackCnt); 192 | if (!PRECOMPILING) 193 | PUTW(elsePtr, GetBankOffset()); 194 | } 195 | 196 | } else if (!STRCMP(szTemp, "forever")) { 197 | 198 | bank = curBank; 199 | start = GetBankOffset(); 200 | 201 | GetCode(flags | CF_BRACEOK | CF_GETNEXTWORD, brackCnt); 202 | 203 | if (bank != curBank) 204 | error(ERR_FOREVEROUTOFBANK, bank->label, curBank->label); 205 | else 206 | WriteOpcodeW(opJMP_ABS, start); 207 | 208 | } else 209 | return FALSE; 210 | return TRUE; 211 | } 212 | 213 | -------------------------------------------------------------------------------- /expressions/exp_ifloop.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #ifndef ifloopH 12 | #define ifloopH 13 | 14 | #include "../getcode.h" 15 | 16 | extern STRINT siConditions[]; 17 | 18 | 19 | BOOL comProc_IfLoop(U16 flags, S16* brackCnt); 20 | 21 | #endif 22 | 23 | -------------------------------------------------------------------------------- /expressions/exp_labels.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #pragma hdrstop 12 | #include "../compiler.h" 13 | 14 | #pragma package(smart_init) 15 | 16 | 17 | 18 | BOOL comProc_LabelDeclaration(U16 flags, S16* brackCnt) 19 | { 20 | char* label; 21 | LABEL* lab; 22 | 23 | if (!IsStringLabel(szTemp)) 24 | return FALSE; 25 | 26 | label = strdup(szTemp); 27 | if (PeekNextWord()[0] != ':') { 28 | strcpy(szTemp, label); 29 | ssFree(label); 30 | return FALSE; 31 | } 32 | GetNextWord(); 33 | 34 | if (PRECOMPILING) 35 | AddLabel(label, -1); 36 | else { 37 | lab = FindLabel(label); 38 | lab->offset = GetBankOffset(); 39 | } 40 | ssFree(label); 41 | 42 | return TRUE; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /expressions/exp_labels.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #ifndef exp_labelsH 12 | #define exp_labelsH 13 | 14 | #include "../getcode.h" 15 | 16 | 17 | 18 | 19 | BOOL comProc_LabelDeclaration(U16 flags, S16* brackCnt); 20 | 21 | #endif 22 | 23 | -------------------------------------------------------------------------------- /expressions/exp_preprocess.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #ifndef preprocessH 12 | #define preprocessH 13 | 14 | #include "../prepbase.h" 15 | #include "../getcode.h" 16 | 17 | enum _PREPROCESS_KEYWORDS { 18 | 19 | PREPROCESS_SETPAD, 20 | PREPROCESS_ALIGN, 21 | 22 | PREPROCESS_DEFINE, 23 | PREPROCESS_UNDEF, 24 | 25 | PREPROCESS_IFDEF, 26 | PREPROCESS_IFNDEF, 27 | PREPROCESS_ELSE, 28 | PREPROCESS_ENDIF, 29 | 30 | PREPROCESS_TODO, 31 | PREPROCESS_WARNING, 32 | PREPROCESS_ERROR, 33 | PREPROCESS_FATAL, 34 | PREPROCESS_TELL, 35 | 36 | PREPROCESS_INCLUDE, 37 | PREPROCESS_INCBIN, 38 | PREPROCESS_USEPATH, 39 | 40 | PREPROCESS_RAM, 41 | PREPROCESS_ROM, 42 | PREPROCESS_CHR, 43 | PREPROCESS_INES, 44 | 45 | PREPROCESS_INTERRUPT, 46 | 47 | PREPROCESS_TOTAL, 48 | }; 49 | 50 | enum _PREPROCESS_TELL { 51 | PREPROCESS_TELL_BANK, 52 | PREPROCESS_TELL_BANKOFFSET, 53 | PREPROCESS_TELL_BANKSIZE, 54 | PREPROCESS_TELL_BANKFREE, 55 | PREPROCESS_TELL_BANKTYPE, 56 | }; 57 | 58 | enum _PREPROCESS_RAM { 59 | PREPROCESS_RAM_ORG, 60 | PREPROCESS_RAM_END, 61 | }; 62 | 63 | enum _PREPROCESS_ROM { 64 | PREPROCESS_ROM_ORG, 65 | PREPROCESS_ROM_END, 66 | PREPROCESS_ROM_BANKSIZE, 67 | PREPROCESS_ROM_BANK, 68 | }; 69 | 70 | enum _PREPROCESS_CHR { 71 | PREPROCESS_CHR_BANKSIZE, 72 | PREPROCESS_CHR_BANK, 73 | PREPROCESS_CHR_END, 74 | }; 75 | 76 | enum _PREPROCESS_INES { 77 | PREPROCESS_INES_MAPPER, 78 | PREPROCESS_INES_MIRRORING, 79 | PREPROCESS_INES_BATTERY, 80 | PREPROCESS_INES_TRAINER, 81 | PREPROCESS_INES_FOURSCREEN, 82 | PREPROCESS_INES_PRGREPEAT, 83 | PREPROCESS_INES_CHRREPEAT, 84 | PREPROCESS_INES_OFF, 85 | }; 86 | 87 | enum _PREPROCESS_INTERRUPT { 88 | PREPROCESS_INTERRUPT_NMI, 89 | PREPROCESS_INTERRUPT_START, 90 | PREPROCESS_INTERRUPT_IRQ, 91 | }; 92 | 93 | void EnterIfDef(BOOL RESULT); 94 | void ReleaseIfDef(void); 95 | BOOL InFalseIfDef(void); 96 | 97 | BOOL comProc_Preprocess(U16 flags, S16* brackCnt); 98 | 99 | typedef struct { 100 | char* label; 101 | char* members[16]; 102 | } STRNAMELIST; 103 | 104 | extern STRNAMELIST szPreprocess[]; 105 | 106 | #endif 107 | 108 | -------------------------------------------------------------------------------- /expressions/exp_switch.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #pragma hdrstop 12 | #include "../compiler.h" 13 | /****************************************************************************** 14 | * Handles the switch/case expressions 15 | ******************************************************************************/ 16 | #pragma package(smart_init) 17 | enum switchMode { 18 | SWITCHMODE_CMP, 19 | SWITCHMODE_CPX, 20 | SWITCHMODE_CPY 21 | }; 22 | char* szCaseOps[] = { 23 | "CMP", 24 | "CPX", 25 | "CPY" 26 | }; 27 | 28 | BOOL comProc_Switch(U16 flags, S16* _brackCnt) 29 | { 30 | BOOL FAR_BRANCH; 31 | BANK* bank; 32 | int mode, opid; 33 | BOOL BRACED_CASE; 34 | 35 | BRANCHLIST* cmpBranches = NULL, *endBranches = NULL; 36 | 37 | if (STRCMP(szTemp, "switch")) 38 | return FALSE; 39 | 40 | CheckCurBank(); 41 | 42 | if (GetNextWord()[0] != '(') { 43 | error(ERR_SWITCHINBRACKEXP, szTemp); 44 | return TRUE; 45 | } 46 | mode = SWITCHMODE_CMP; 47 | 48 | USE_DEFS = FALSE; 49 | 50 | if (STRCMP(GetNextWord(), "reg")) { 51 | error(ERR_SWITCHREG, szTemp); 52 | } else { 53 | if (STRCMP(GetNextWord(), ".")) { 54 | error(ERR_SWITCHREGPOINT, szTemp); 55 | } else { 56 | GetNextWord(); 57 | if (!STRCMP(szTemp, "a")) { 58 | // 59 | } else if (!STRCMP(szTemp, "x")) { 60 | mode = SWITCHMODE_CPX; 61 | } else if (!STRCMP(szTemp, "y")) { 62 | mode = SWITCHMODE_CPY; 63 | } else { 64 | error(ERR_SWITCHREGARG, szTemp); 65 | } 66 | } 67 | } 68 | 69 | USE_DEFS = TRUE; 70 | 71 | if (GetNextWord()[0] != ')') { 72 | error(ERR_CLOSEBRACKEXP, szTemp); 73 | return TRUE; 74 | } 75 | if (GetNextWord()[0] != '{') { 76 | error(ERR_SWITCHINBRACE); 77 | return TRUE; 78 | } 79 | 80 | opid = IsOpcodeName(szCaseOps[mode]); // returns -1 on error, but it's fixed so that won't happen 81 | 82 | while (*GetNextWord() && *szTemp != '}') { 83 | WriteBranches(&cmpBranches); 84 | if (!STRCMP(szTemp, "case")) { 85 | FAR_BRANCH = CheckNearFar(); 86 | GetOperands(opid); 87 | 88 | if (FAR_BRANCH) { 89 | WriteOpcodeB(opBEQ_REL, 3); 90 | WriteOpcode(opJMP_ABS); 91 | AddBranchPos(&cmpBranches, prmABS); 92 | WriteCodeW(0); 93 | } else { 94 | WriteOpcode(opBNE_REL); 95 | AddBranchPos(&cmpBranches, prmREL); 96 | WriteCodeB(0); 97 | } 98 | 99 | if (!DoCaseBlock(flags)) 100 | return FALSE; 101 | 102 | WriteOpcode(opJMP_ABS); 103 | AddBranchPos(&endBranches, prmABS); 104 | WriteCodeW(0); 105 | } else if (!STRCMP(szTemp, "default")) { 106 | 107 | if (!DoCaseBlock(flags)) 108 | return FALSE; 109 | 110 | GetNextWord(); // the closing '}' 111 | break; 112 | } else { 113 | error(ERR_SWITCHEXPRESSION, szTemp); 114 | } 115 | } 116 | 117 | WriteBranches(&cmpBranches); 118 | WriteBranches(&endBranches); 119 | 120 | if (*szTemp != '}') { 121 | error(ERR_SWITCHOUTBRACE); 122 | return TRUE; 123 | } 124 | 125 | return TRUE; 126 | } 127 | 128 | BOOL CheckNearFar() 129 | { 130 | PeekNextWord(); 131 | if (!STRCMP(szTemp, "far")) { 132 | GetNextWord(); 133 | return TRUE; 134 | } else { 135 | if (!STRCMP(szTemp, "near")) 136 | GetNextWord(); 137 | } 138 | return FALSE; 139 | } 140 | 141 | BOOL DoCaseBlock(U16 flags) 142 | { 143 | S16 brackCnt = 0; 144 | 145 | GetCode(flags | CF_BRACEOK | CF_GETNEXTWORD, &brackCnt); 146 | 147 | return TRUE; 148 | } 149 | 150 | void AddBranchPos(BRANCHLIST** branches, int mode) 151 | { 152 | BRANCHLIST* b = (BRANCHLIST*)ssAlloc(sizeof(BRANCHLIST)); 153 | 154 | b->mode = mode; 155 | b->ptr = curBank->ptr; 156 | b->offset = GetBankOffset() + 1; 157 | 158 | b->prev = *branches; 159 | 160 | *branches = b; 161 | } 162 | 163 | void WriteBranches(BRANCHLIST** branches) 164 | { 165 | BRANCHLIST* b = *branches, *next = NULL; 166 | S32 offset = GetBankOffset(), noffset; 167 | while (b) { 168 | next = b->prev; 169 | 170 | if (b->mode == prmABS) { 171 | PUTW(b->ptr, offset); 172 | } else { 173 | noffset = offset - b->offset; 174 | 175 | if ((noffset < -128 || noffset > 127)) 176 | error(ERR_BRANCHOUTOFRANGE); 177 | else 178 | PUTB(b->ptr, (U8)noffset); 179 | } 180 | 181 | ssFree(b); 182 | 183 | b = next; 184 | } 185 | *branches = NULL; 186 | } 187 | 188 | -------------------------------------------------------------------------------- /expressions/exp_switch.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #ifndef exp_switchH 12 | #define exp_switchH 13 | 14 | #include "../getcode.h" 15 | 16 | 17 | 18 | 19 | BOOL comProc_Switch(U16 flags, S16* brackCnt); 20 | BOOL DoCaseBlock(U16 flags); 21 | BOOL CheckNearFar(void); 22 | 23 | 24 | typedef struct _BRANCHLIST { 25 | struct _BRANCHLIST* prev; 26 | int mode; 27 | U8* ptr; 28 | S32 offset; 29 | } BRANCHLIST; 30 | 31 | void AddBranchPos(BRANCHLIST** branches, int mode); 32 | void WriteBranches(BRANCHLIST** branches); 33 | 34 | #endif 35 | 36 | -------------------------------------------------------------------------------- /expressions/exp_vardeclare.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #ifndef vardeclareH 12 | #define vardeclareH 13 | 14 | #include "../getcode.h" 15 | 16 | 17 | 18 | 19 | BOOL comProc_VarDeclare(U16 flags, S16* brackCnt); 20 | 21 | #endif 22 | 23 | -------------------------------------------------------------------------------- /functions.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #pragma hdrstop 12 | #include "compiler.h" 13 | /****************************************************************************** 14 | * Handles variables 15 | ******************************************************************************/ 16 | #pragma package(smart_init) 17 | 18 | FUNC* functions, *curFunction, *curMacro, *macker; 19 | char* szFuncTypes[] = { 20 | "function", "interrupt", "inline", "" 21 | }; 22 | char* szIntTypes[] = { 23 | "nmi", "start", "irq", "" 24 | }; 25 | 26 | void FreeParameters(PARAM** pparams) 27 | { 28 | PARAM* params = *pparams, *next; 29 | if (params) { 30 | while (params) { 31 | next = params->prev; 32 | ssFree(params->def.label); 33 | ssFree(params->def.definition); 34 | ssFree(params); 35 | params = next; 36 | } 37 | *pparams = NULL; 38 | } 39 | } 40 | 41 | void FreeFunctions(FUNC** pfunc) 42 | { 43 | FUNC* func = *pfunc, *next; 44 | if (func) { 45 | while (func) { 46 | next = func->prev; 47 | FreeFunctions(&func->childFuncs); 48 | if (func->type != FUNCTYPE_INLINE) { 49 | FreeParameters(&func->params); 50 | } 51 | FreeLabels(&func->labels); 52 | FreeFixoffs(&func->fixoffs); 53 | ssFree(func->label); 54 | ssFree(func->macDef); 55 | ssFree(func); 56 | func = next; 57 | } 58 | *pfunc = NULL; 59 | } 60 | } 61 | 62 | FUNC* AddFunction(char* label, U16 type) 63 | { 64 | FUNC* newfunc; 65 | 66 | if (IsLabelUsed(label, vars)) 67 | label[0] = '\0'; 68 | 69 | newfunc = (FUNC*)ssCalloc(sizeof(FUNC)); 70 | 71 | if (curFunction) { // in a struct 72 | if (curFunction->childFuncs) 73 | curFunction->childFuncs->next = newfunc; 74 | newfunc->prev = curFunction->childFuncs; 75 | curFunction->childFuncs = newfunc; 76 | newfunc->parent = curFunction; 77 | } else { 78 | if (functions) 79 | functions->next = newfunc; 80 | newfunc->prev = functions; 81 | functions = newfunc; 82 | newfunc->parent = NULL; 83 | } 84 | newfunc->next = NULL; 85 | newfunc->childFuncs = NULL; 86 | newfunc->type = type; 87 | newfunc->label = strdup(label); 88 | newfunc->flags = 0; 89 | newfunc->macDef = NULL; 90 | newfunc->params = NULL; 91 | newfunc->labels = NULL; 92 | 93 | if (type == FUNCTYPE_INLINE) { 94 | newfunc->offset = -1; 95 | newfunc->bank = NULL; 96 | } else { 97 | if (!curBank) { 98 | error(ERR_VARNOBANK); 99 | newfunc->offset = 0; 100 | } else { 101 | newfunc->bank = curBank; 102 | newfunc->offset = -1; //GetBankOffset(); 103 | switch (curBank->type) { 104 | case BANKTYPE_RAM: 105 | error(ERR_CODEINRAM, label); 106 | break; 107 | case BANKTYPE_ROM: 108 | break; 109 | case BANKTYPE_CHR: 110 | warning(WRN_CODEINCHR, label); 111 | break; 112 | } 113 | } 114 | } 115 | 116 | return newfunc; 117 | } 118 | 119 | FUNC* ReleaseCurFunc() 120 | { 121 | if (curFunction) 122 | curFunction = curFunction->parent; 123 | return curFunction; 124 | } 125 | 126 | PARAM* CloneParams(PARAM* params) 127 | { 128 | PARAM* newparams = NULL, *prev = NULL, *np = NULL; 129 | if (params) { 130 | while (params) { 131 | newparams = (PARAM*)ssAlloc(sizeof(PARAM)); 132 | if (!np) 133 | np = newparams; 134 | 135 | newparams->def.label = params->def.label ? strdup(params->def.label) : NULL; 136 | newparams->def.definition = params->def.definition ? strdup(params->def.definition) : NULL; 137 | 138 | if (prev) 139 | prev->prev = newparams; 140 | newparams->prev = NULL; 141 | 142 | prev = newparams; 143 | 144 | params = params->prev; 145 | } 146 | } 147 | return np; 148 | } 149 | 150 | FUNC* MakeCurMacro(FUNC* ofmac) 151 | { 152 | FUNC* newmac; 153 | 154 | newmac = (FUNC*)memclone(ofmac, sizeof(FUNC)); 155 | 156 | newmac->prev = curMacro; 157 | if (curMacro) 158 | curMacro->next = newmac; 159 | newmac->next = newmac->parent = newmac->childFuncs = NULL; 160 | 161 | newmac->params = CloneParams(newmac->params); 162 | newmac->labels = CloneLabels(newmac->labels); 163 | newmac->fixoffs = NULL; // good to be safe 164 | 165 | return newmac; 166 | } 167 | 168 | FUNC* SetCurMacro(FUNC* ofmac) 169 | { 170 | return curMacro = ofmac; 171 | } 172 | 173 | FUNC* ReleaseCurMacro() 174 | { 175 | FUNC* next; 176 | if (curMacro) { 177 | next = curMacro->prev; 178 | FreeParameters(&curMacro->params); 179 | DoFixOffs(curMacro->fixoffs); 180 | FreeFixoffs(&curMacro->fixoffs); 181 | FreeLabels(&curMacro->labels); 182 | ssFree(curMacro); 183 | curMacro = next; 184 | } 185 | return curMacro; 186 | } 187 | 188 | 189 | FUNC* FindFirstFunction(FUNC* func) 190 | { 191 | while (func && func->prev) 192 | func = func->prev; 193 | return func; 194 | } 195 | 196 | 197 | FUNC* FindFirstCurFunc() 198 | { 199 | FUNC* func = curFunction; 200 | while (func && func->parent) 201 | func = func->parent; 202 | return func; 203 | } 204 | 205 | 206 | FUNC* FindFunction(FUNC* func, char* label) 207 | { 208 | while (func && STRCMP(func->label, label)) 209 | func = func->prev; 210 | return func; 211 | } 212 | 213 | 214 | int IsFuncType(char* label) 215 | { 216 | return StrInList(label, szFuncTypes); 217 | } 218 | 219 | PARAM* AddParameter(FUNC* func, char* str) 220 | { 221 | PARAM* param; 222 | 223 | param = (PARAM*)ssAlloc(sizeof(param)); 224 | 225 | param->prev = func->params; 226 | func->params = param; 227 | 228 | param->def.label = strdup(str); 229 | param->def.definition = NULL; 230 | 231 | return param; 232 | } 233 | 234 | 235 | PARAM* FindParameterIndex(PARAM* param, int idx) 236 | { 237 | PARAM* paramstart = param; 238 | int total = 0; 239 | 240 | if (!param) 241 | return NULL; 242 | 243 | while (param->prev) { 244 | param = param->prev; 245 | total++; 246 | } 247 | 248 | total -= idx; 249 | if (total < 0) 250 | param = NULL; 251 | else { 252 | param = paramstart; 253 | while ((param) && total--) 254 | param = param->prev; 255 | } 256 | 257 | return param; 258 | } 259 | 260 | PARAM* SetParameter(FUNC* func, int num, char* str) 261 | { 262 | PARAM* param = func->params; 263 | int total = 0; 264 | 265 | if (!param) 266 | return NULL; 267 | 268 | while (param->prev) { 269 | param = param->prev; 270 | total++; 271 | } 272 | 273 | total -= num; 274 | if (total < 0) 275 | param = NULL; 276 | else { 277 | param = func->params; 278 | while ((param) && total--) 279 | param = param->prev; 280 | if (param) { 281 | ssFree(param->def.definition); 282 | param->def.definition = strdup(str); 283 | } 284 | } 285 | 286 | return param; 287 | } 288 | 289 | -------------------------------------------------------------------------------- /functions.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #ifndef functionsH 12 | #define functionsH 13 | 14 | #include "labels.h" 15 | #include "output/banks.h" 16 | #include "output/fixoffs.h" 17 | 18 | #define FUNCFLAG_USED 0x8000 19 | #define FUNCFLAG_NORET 0x4000 20 | #define FUNCFLAG_MAKETYPE(funcFlags, subtype) \ 21 | funcFlags = (funcFlags & 0xFFFC) | (subtype & 0x0003) 22 | #define FUNCFLAG_GETTYPE(funcFlags) \ 23 | (funcFlags & 0x0003) 24 | 25 | enum { 26 | FUNCTYPE_FUNCTION, 27 | FUNCTYPE_INTERRUPT, 28 | FUNCTYPE_INLINE, 29 | 30 | FUNCTYPE_TOTAL 31 | }; 32 | 33 | enum { 34 | INTTYPE_START, 35 | INTTYPE_NMI, 36 | INTTYPE_IRQ, 37 | 38 | INTTYPE_TOTAL 39 | }; 40 | 41 | typedef struct _PARAM { 42 | struct _PARAM* prev; 43 | DEFINE def; 44 | } PARAM; 45 | 46 | typedef struct _FUNC { 47 | struct _FUNC* prev, *next, *parent, *childFuncs; 48 | U16 type; 49 | U16 flags; 50 | S32 offset; 51 | char* label; 52 | BANK* bank; 53 | // for inline 54 | char* macDef; 55 | PARAM* params; 56 | LABEL* labels; 57 | FIXOFFS* fixoffs; 58 | } FUNC; 59 | 60 | extern FUNC* functions, *curFunction, *curMacro, *macker; 61 | extern char* szFuncTypes[], *szIntTypes[]; 62 | 63 | void FreeParameters(PARAM** pparams); 64 | void FreeFunctions(FUNC** pfunc); 65 | FUNC* AddFunction(char* label, U16 type); 66 | FUNC* ReleaseCurFunc(void); 67 | FUNC* FindFunction(FUNC* func, char* label); 68 | FUNC* FindFirstCurFunc(void); 69 | FUNC* FindFirstFunction(FUNC* func); 70 | int IsFuncType(char* label); 71 | PARAM* FindParameterIndex(PARAM* param, int idx); 72 | PARAM* AddParameter(FUNC* func, char* str); 73 | FUNC* MakeCurMacro(FUNC* ofmac); 74 | FUNC* SetCurMacro(FUNC* newmac); 75 | FUNC* ReleaseCurMacro(void); 76 | 77 | PARAM* SetParameter(FUNC* func, int num, char* str); 78 | 79 | #endif 80 | 81 | -------------------------------------------------------------------------------- /getcode.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #ifndef getcodeH 12 | #define getcodeH 13 | 14 | #include "opcodes.h" 15 | 16 | #include "expressions/exp_general.h" 17 | 18 | #include "expressions/exp_preprocess.h" 19 | 20 | #include "expressions/exp_vardeclare.h" 21 | #include "expressions/exp_funcdeclare.h" 22 | #include "expressions/exp_labels.h" 23 | 24 | #include "expressions/exp_funccall.h" 25 | #include "expressions/exp_ifloop.h" 26 | #include "expressions/exp_switch.h" 27 | 28 | #include "expressions/exp_asm.h" 29 | 30 | #define CF_GETNEXTWORD 0x0001 31 | #define CF_INOBJECT 0x0002 32 | #define CF_INFUNCTION 0x0004 33 | #define CF_BRACEOK 0x0008 34 | #define CF_BRACED 0x0010 35 | #define CF_MACRO 0x0020 36 | 37 | #define CF_VARCHILD 0x8000 38 | 39 | typedef BOOL (*COMPPROC)(U16 flags, S16* brackCnt); 40 | 41 | enum _ARITHOPS { 42 | ARITHOPS_ADD, 43 | ARITHOPS_SUB, 44 | ARITHOPS_MUL, 45 | ARITHOPS_DIV, 46 | ARITHOPS_MOD, 47 | ARITHOPS_SHR, 48 | ARITHOPS_SHL, 49 | ARITHOPS_XOR, 50 | ARITHOPS_AND, 51 | ARITHOPS_OR, 52 | ARITHOPS_EQ, 53 | ARITHOPS_NE, 54 | ARITHOPS_GTE, 55 | ARITHOPS_LTE, 56 | ARITHOPS_GT, 57 | ARITHOPS_LT, 58 | }; 59 | BOOL CompileImmediateInteger(S16 brackCnt, S32* outnum, S32 set, S32 inval); 60 | 61 | S16 GetCode(U16 flags, S16* brackCnt); 62 | 63 | void CheckSemicolon(void); 64 | void CheckBracksZero(S16* brackCnt); 65 | void SeekThroughInBracks(S16* brackCnt); 66 | void PeekThroughInBracks(S16* brackCnt); 67 | void SeekThroughOutBracks(S16* brackCnt); 68 | void PeekThroughOutBracks(S16* brackCnt); 69 | void SeekThroughOutBracksNM(S16* brackCnt); 70 | void PeekThroughOutBracksNM(S16* brackCnt); 71 | 72 | S32 AccOpNum(int idx, S32 _num2); 73 | 74 | #endif 75 | 76 | -------------------------------------------------------------------------------- /init.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #pragma hdrstop 12 | #include "compiler.h" 13 | 14 | #pragma package(smart_init) 15 | 16 | 17 | 18 | BOOL InitializeCompiler() 19 | { 20 | InitMessages(); 21 | 22 | COMPILE_SUCCESS = TRUE; 23 | 24 | errorCnt = warnCnt = todoCnt = 0; 25 | 26 | scriptNumber = -1; // no script specified yet 27 | 28 | firstScript = curScript = NULL; 29 | 30 | defList = defListPtr = NULL; 31 | USE_DEFS = TRUE; 32 | 33 | fixOffs = NULL; 34 | 35 | curVar = vars = typedefs = NULL; 36 | 37 | functions = curFunction = curMacro = macker = NULL; 38 | 39 | labels = NULL; 40 | 41 | enumClasses = NULL; 42 | 43 | InitROMHeader(); 44 | InitBanks(); 45 | 46 | return TRUE; 47 | } 48 | 49 | void ShutDownCompiler() 50 | { 51 | FreeFixoffs(&fixOffs); 52 | 53 | DiscardScript(firstScript); 54 | 55 | FreeLists(&defList); 56 | 57 | DisposeStringList(&sysDirList); 58 | DisposeStringList(&includeDirList); 59 | DisposeStringList(&libDirList); 60 | 61 | ssFree(labelStrings.buffer); 62 | 63 | ReleaseCurVar(); 64 | ReleaseCurFunc(); 65 | 66 | FreeVars(&vars); 67 | FreeVars(&typedefs); 68 | 69 | FreeFunctions(&functions); 70 | while (ReleaseCurMacro()) 71 | ; 72 | FreeLabels(&labels); 73 | 74 | FreeBanks(); 75 | ShutDownMessages(); 76 | } 77 | 78 | -------------------------------------------------------------------------------- /init.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #ifndef initH 12 | #define initH 13 | 14 | 15 | 16 | BOOL InitializeCompiler(void); 17 | void ShutDownCompiler(void); 18 | 19 | #endif 20 | 21 | -------------------------------------------------------------------------------- /labels.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #pragma hdrstop 12 | #include "compiler.h" 13 | 14 | #pragma package(smart_init) 15 | 16 | LABEL* labels; 17 | 18 | BOOL IsLabelUsed(char* str, VAR* varset) 19 | { 20 | if (FindVariable(varset, str)) { 21 | error(ERR_VAREXISTS, str); 22 | } else if (varset == vars && FindVariable(typedefs, str)) { 23 | error(ERR_VAREXISTS, str); 24 | } else if (FindFunction(functions, str)) { 25 | error(ERR_FUNCEXISTS, str); 26 | } else if (FindLabel(str)) { 27 | error(ERR_LABELEXISTS, str); 28 | } else if (FindBank(str)) { 29 | error(ERR_LABELEXISTS, str); 30 | } else if (IsOpcodeName(str) != -1) { 31 | error(ERR_LABELRESERVEDWORD, str); 32 | } else if (StrInList(str, szAdditionalKeywords) != -1 || (StrInList(str, szAccOps) != -1)) { 33 | error(ERR_LABELRESERVEDWORD, str); 34 | } else { 35 | return FALSE; 36 | } 37 | return TRUE; 38 | } 39 | 40 | void* CheckLabel(char* str, S32* _offset, S16* _type, BOOL CHECK) 41 | { 42 | LABEL* lab; 43 | VAR* var; 44 | FUNC* func; 45 | BANK* bank; 46 | S32 offset, num; 47 | S16 brackCnt; 48 | 49 | if ((lab = FindLabel(str)) != NULL) { 50 | *_type = FIXTYPE_LABEL; 51 | *_offset = lab->offset; 52 | return lab; 53 | } 54 | 55 | if ((bank = FindBank(str)) != NULL) { 56 | if (PeekNextChar() == '(') { 57 | GetNextChar(); 58 | if (!CompileImmediateInteger(0, &num, -1, 0)) { 59 | error(ERR_INTEXP); 60 | offset = 0; 61 | } else { 62 | // get the bank index of num, 63 | // ie. bank at 8192, num==1024, result 8 64 | offset = GetBankIndex(bank, ConfirmWord(num)); 65 | } 66 | if (GetNextWord()[0] != ')') 67 | error(ERR_CLOSEBRACKEXP); 68 | } else 69 | offset = bank->bank; 70 | *_type = FIXTYPE_NONE; 71 | *_offset = offset; 72 | return bank; 73 | } 74 | 75 | if ((var = FindVariable(vars, str)) != NULL) { 76 | var = PonderVariable(var, &offset); 77 | if (!var) { 78 | return NULL; 79 | } 80 | *_type = FIXTYPE_VARIABLE; 81 | *_offset = offset; 82 | return var; 83 | } 84 | 85 | if ((func = FindFunction(functions, str)) != NULL) { 86 | func->flags |= FUNCFLAG_USED; 87 | if (func->type == FUNCTYPE_INLINE) { 88 | if (!CHECK) 89 | error(ERR_ACCESSINLINE, str); 90 | return NULL; 91 | } 92 | *_type = FIXTYPE_FUNCTION; 93 | *_offset = func->offset; 94 | return func; 95 | } 96 | 97 | return NULL; 98 | } 99 | 100 | void* GetLabel(char* str, S32* _offset, S16* _type) 101 | { 102 | 103 | return CheckLabel(str, _offset, _type, FALSE); 104 | } 105 | 106 | // skip a label object such as a variable/function label if it's not yet known 107 | BOOL PrecompileSkipLabelObject() 108 | { 109 | if (!IsStringLabel(szTemp)) 110 | return FALSE; 111 | 112 | for (;;) { 113 | PeekNextWord(); 114 | switch (*szTemp) { 115 | case '.': // struct element 116 | GetNextWord(); 117 | GetNextWord(); 118 | if (!IsStringLabel(szTemp)) { 119 | return FALSE; 120 | } 121 | break; 122 | case '[': // struct element 123 | GetNextWord(); 124 | SeekPastWord("]"); 125 | break; 126 | default: 127 | return TRUE; 128 | } 129 | } 130 | } 131 | 132 | void FreeLabels(LABEL** plabel) 133 | { 134 | LABEL* lab = *plabel, *next; 135 | if (lab) { 136 | while (lab) { 137 | next = lab->prev; 138 | ssFree(lab->label); 139 | ssFree(lab); 140 | lab = next; 141 | } 142 | *plabel = NULL; 143 | } 144 | } 145 | 146 | LABEL* CloneLabels(LABEL* lab) 147 | { 148 | LABEL* next, *start = NULL, *prev = NULL; 149 | while (lab) { 150 | next = lab->prev; 151 | lab = (LABEL*)memclone(lab, sizeof(LABEL)); 152 | if (!start) 153 | start = lab; 154 | lab->label = strdup(lab->label); 155 | 156 | if (prev) 157 | prev->prev = lab; 158 | lab->prev = NULL; 159 | prev = lab; 160 | 161 | lab = next; 162 | } 163 | return start; 164 | } 165 | 166 | LABEL* AddLabel(char* label, S32 offset) 167 | { 168 | LABEL* newlab; 169 | 170 | if (IsLabelUsed(label, vars)) 171 | label[0] = '\0'; 172 | 173 | newlab = (LABEL*)ssAlloc(sizeof(LABEL)); 174 | 175 | newlab->label = strdup(label); 176 | newlab->flags = 0; 177 | if (macker) { 178 | newlab->prev = macker->labels; 179 | macker->labels = newlab; 180 | newlab->offset = -1; 181 | newlab->flags |= LABELFLAG_MACKER; 182 | } else { 183 | newlab->prev = labels; 184 | labels = newlab; 185 | 186 | if (!curBank) { 187 | error(ERR_LABELNOBANK); 188 | newlab->offset = 0; 189 | } else { 190 | newlab->offset = -1; 191 | } 192 | } 193 | 194 | return newlab; 195 | } 196 | 197 | 198 | LABEL* FindLabel(char* label) 199 | { 200 | LABEL* lab = labels; 201 | 202 | while (lab && STRCMP(lab->label, label)) 203 | lab = lab->prev; 204 | if (!lab && curMacro) { 205 | lab = curMacro->labels; 206 | while (lab && STRCMP(lab->label, label)) 207 | lab = lab->prev; 208 | } 209 | return lab; 210 | } 211 | 212 | -------------------------------------------------------------------------------- /labels.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #ifndef labelsH 12 | #define labelsH 13 | 14 | 15 | #include "vars.h" 16 | 17 | #define LABELFLAG_MACKER 0x0001 18 | 19 | typedef struct _LABEL { 20 | struct _LABEL* prev; 21 | S32 offset; 22 | char* label; 23 | U16 flags; 24 | } LABEL; 25 | 26 | 27 | extern LABEL* labels; 28 | void FreeLabels(LABEL** plabels); 29 | LABEL* AddLabel(char* label, S32 offset); 30 | LABEL* FindLabel(char* label); 31 | 32 | LABEL* CloneLabels(LABEL* lab); 33 | 34 | BOOL IsLabelUsed(char* str, VAR* varset); 35 | void* GetLabel(char* str, S32* _offset, S16* _type); 36 | void* CheckLabel(char* str, S32* _offset, S16* _type, BOOL check); 37 | 38 | BOOL PrecompileSkipLabelObject(void); 39 | 40 | #endif 41 | 42 | -------------------------------------------------------------------------------- /list.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #pragma hdrstop 12 | #include "compiler.h" 13 | 14 | #pragma package(smart_init) 15 | 16 | 17 | 18 | PLIST* NewList(PLIST* parent, int size) 19 | { 20 | PLIST* newlist = (PLIST*)ssCalloc(sizeof(PLIST)); 21 | if (parent) 22 | parent->next = newlist; 23 | newlist->prev = parent; 24 | newlist->data = (void*)ssCalloc(size); 25 | return newlist; 26 | } 27 | 28 | void FreeList(PLIST* list) 29 | { 30 | if (!list) 31 | return; 32 | if (list->next) 33 | list->next->prev = list->prev; 34 | if (list->prev) 35 | list->prev->next = list->next; 36 | ssFree(list->data); 37 | ssFree(list); 38 | } 39 | 40 | void FreeLists(PLIST** plist) 41 | { 42 | PLIST* list = *plist; 43 | if (!list) 44 | return; 45 | while (list->next) 46 | FreeList(list->next); 47 | FreeList(list); 48 | *plist = NULL; 49 | } 50 | 51 | -------------------------------------------------------------------------------- /list.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #ifndef listH 12 | #define listH 13 | 14 | typedef struct _PLIST { 15 | struct _PLIST* prev, *next; 16 | U16 entCount; 17 | void* data; 18 | } PLIST; 19 | 20 | PLIST* NewList(PLIST* parent, int size); 21 | void FreeList(PLIST* list); 22 | void FreeLists(PLIST** plist); 23 | 24 | #endif 25 | 26 | -------------------------------------------------------------------------------- /opcodes.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #pragma hdrstop 12 | #include "compiler.h" 13 | 14 | #pragma package(smart_init) 15 | 16 | U8 opRelSwap[] = { 17 | opBPL_REL, opBMI_REL, 18 | opBVC_REL, opBVS_REL, 19 | opBCC_REL, opBCS_REL, 20 | opBNE_REL, opBEQ_REL, 21 | }; 22 | 23 | OPCODE* activeOpcode, *opcodeSta, *opcodeSty, *opcodeStx; // todo add opcode properties instead for check (ie. OP_STORE) 24 | 25 | void OpcodesInit(char* label) 26 | { 27 | activeOpcode = NULL; 28 | opcodeSta = &opcodes[IsOpcodeName("STA")]; 29 | opcodeSty = &opcodes[IsOpcodeName("STY")]; 30 | opcodeStx = &opcodes[IsOpcodeName("STX")]; 31 | } 32 | 33 | int IsOpcodeName(char* label) 34 | { 35 | int i; 36 | OPCODE* o = opcodes; 37 | for (i = opTOTAL_UNIQUE - 1; i >= 0; i--) 38 | if (!STRCMP((o++)->name, label)) 39 | return (opTOTAL_UNIQUE - 1) - i; 40 | return -1; 41 | } 42 | 43 | char* GetOpcodeName(int code) 44 | { 45 | int i, j; 46 | OPCODE* o = opcodes; 47 | for (i = opTOTAL_UNIQUE - 1; i >= 0; i--) 48 | for (j = 0; j < prtTOTAL; j++) 49 | if ((o++)->codes[j] == code) 50 | return ((o - 1))->name; 51 | return ""; 52 | } 53 | 54 | int RelSwapOp(int opcode) 55 | { 56 | int i; 57 | for (i = 7; i >= 0; i--) 58 | if (opRelSwap[i] == opcode) { 59 | return opRelSwap[i ^ 1]; 60 | } 61 | return -1; 62 | } 63 | 64 | -------------------------------------------------------------------------------- /opcodes.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #ifndef opcodesH 12 | #define opcodesH 13 | 14 | #include "opcodetable.h" 15 | 16 | extern U8 opRelSwap[]; 17 | extern OPCODE* activeOpcode, *opcodeSta, *opcodeSty, *opcodeStx; 18 | 19 | int IsOpcodeName(char* label); 20 | int RelSwapOp(int op); 21 | char* GetOpcodeName(int code); 22 | 23 | #endif 24 | 25 | -------------------------------------------------------------------------------- /opcodetable.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | /***************************************************************************** 11 | * The opcode matrixes! 12 | *****************************************************************************/ 13 | #include "compiler.h" 14 | 15 | OPARGS opArgs[prtTOTAL] = { 16 | { priNONE, prmNONE, "", 0, 0, argNONE, argNONE }, 17 | { priIMD, prmIMD, "immediate", 1, 1, argIMD, argNONE }, 18 | { priREL, prmREL, "relative address", 1, 1, argRELADDR, argNONE }, 19 | { pri0PG, prm0PG, "zp address", 1, 1, argZPADDR, argNONE }, 20 | { pri0PX, prm0PX, "zp address, x", 1, 2, argZPADDR, argX }, 21 | { pri0PY, prm0PY, "zp address, y", 1, 2, argZPADDR, argY }, 22 | { priABS, prmABS, "address", 2, 1, argADDR, argNONE }, 23 | { priABX, prmABX, "address, x", 2, 2, argADDR, argX }, 24 | { priABY, prmABY, "address, y", 2, 2, argADDR, argY }, 25 | { priIND, prmIND, "[address]", 2, 1, argADDR, argNONE }, 26 | { priNDX, prmNDX, "[zp address, x]", 1, 2, argZPADDR, argX }, 27 | { priNDY, prmNDY, "[zp address], y", 1, 2, argZPADDR, argY }, 28 | { priA, prmA, "A", 0, 1, argA, argNONE }, 29 | }; 30 | 31 | OPCODE opcodes[opTOTAL_UNIQUE] = { 32 | { "BRK", prmIMD, { 0xFF, opBRK_IMD, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }, 33 | { "ORA", prmNDX | prm0PG | prmIMD | prmABS | prmNDY | prm0PX | prmABY | prmABX, { 0xFF, opORA_IMD, 0xFF, opORA_0PG, opORA_0PX, 0xFF, opORA_ABS, opORA_ABX, opORA_ABY, 0xFF, opORA_NDX, opORA_NDY, 0xFF } }, 34 | { "ASL", prm0PG | prmA | prmABS | prm0PX | prmABX, { 0xFF, 0xFF, 0xFF, opASL_0PG, opASL_0PX, 0xFF, opASL_ABS, opASL_ABX, 0xFF, 0xFF, 0xFF, 0xFF, opASL_A } }, 35 | { "PHP", prmNONE, { opPHP, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }, 36 | { "BPL", prmREL, { 0xFF, 0xFF, opBPL_REL, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }, 37 | { "CLC", prmNONE, { opCLC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }, 38 | { "JSR", prmABS, { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, opJSR_ABS, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }, 39 | { "AND", prmNDX | prm0PG | prmIMD | prmABS | prmNDY | prm0PX | prmABY | prmABX, { 0xFF, opAND_IMD, 0xFF, opAND_0PG, opAND_0PX, 0xFF, opAND_ABS, opAND_ABX, opAND_ABY, 0xFF, opAND_NDX, opAND_NDY, 0xFF } }, 40 | { "BIT", prm0PG | prmABS, { 0xFF, 0xFF, 0xFF, opBIT_0PG, 0xFF, 0xFF, opBIT_ABS, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }, 41 | { "ROL", prm0PG | prmA | prmABS | prm0PX | prmABX, { 0xFF, 0xFF, 0xFF, opROL_0PG, opROL_0PX, 0xFF, opROL_ABS, opROL_ABX, 0xFF, 0xFF, 0xFF, 0xFF, opROL_A } }, 42 | { "PLP", prmNONE, { opPLP, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }, 43 | { "BMI", prmREL, { 0xFF, 0xFF, opBMI_REL, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }, 44 | { "SEC", prmNONE, { opSEC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }, 45 | { "RTI", prmNONE, { opRTI, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }, 46 | { "EOR", prmNDX | prm0PG | prmIMD | prmABS | prmNDY | prm0PX | prmABY | prmABX, { 0xFF, opEOR_IMD, 0xFF, opEOR_0PG, opEOR_0PX, 0xFF, opEOR_ABS, opEOR_ABX, opEOR_ABY, 0xFF, opEOR_NDX, opEOR_NDY, 0xFF } }, 47 | { "LSR", prm0PG | prmA | prmABS | prm0PX | prmABX, { 0xFF, 0xFF, 0xFF, opLSR_0PG, opLSR_0PX, 0xFF, opLSR_ABS, opLSR_ABX, 0xFF, 0xFF, 0xFF, 0xFF, opLSR_A } }, 48 | { "PHA", prmNONE, { opPHA, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }, 49 | { "JMP", prmABS | prmIND, { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, opJMP_ABS, 0xFF, 0xFF, opJMP_IND, 0xFF, 0xFF, 0xFF } }, 50 | { "BVC", prmREL, { 0xFF, 0xFF, opBVC_REL, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }, 51 | { "CLI", prmNONE, { opCLI, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }, 52 | { "RTS", prmNONE, { opRTS, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }, 53 | { "ADC", prmNDX | prm0PG | prmIMD | prmABS | prmNDY | prm0PX | prmABY | prmABX, { 0xFF, opADC_IMD, 0xFF, opADC_0PG, opADC_0PX, 0xFF, opADC_ABS, opADC_ABX, opADC_ABY, 0xFF, opADC_NDX, opADC_NDY, 0xFF } }, 54 | { "ROR", prm0PG | prmA | prmABS | prm0PX | prmABX, { 0xFF, 0xFF, 0xFF, opROR_0PG, opROR_0PX, 0xFF, opROR_ABS, opROR_ABX, 0xFF, 0xFF, 0xFF, 0xFF, opROR_A } }, 55 | { "PLA", prmNONE, { opPLA, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }, 56 | { "BVS", prmREL, { 0xFF, 0xFF, opBVS_REL, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }, 57 | { "SEI", prmNONE, { opSEI, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }, 58 | { "STA", prmNDX | prm0PG | prmABS | prmNDY | prm0PX | prmABY | prmABX, { 0xFF, 0xFF, 0xFF, opSTA_0PG, opSTA_0PX, 0xFF, opSTA_ABS, opSTA_ABX, opSTA_ABY, 0xFF, opSTA_NDX, opSTA_NDY, 0xFF } }, 59 | { "STY", prm0PG | prmABS | prm0PX, { 0xFF, 0xFF, 0xFF, opSTY_0PG, opSTY_0PX, 0xFF, opSTY_ABS, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }, 60 | { "STX", prm0PG | prmABS | prm0PY, { 0xFF, 0xFF, 0xFF, opSTX_0PG, 0xFF, opSTX_0PY, opSTX_ABS, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }, 61 | { "DEY", prmNONE, { opDEY, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }, 62 | { "TXA", prmNONE, { opTXA, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }, 63 | { "BCC", prmREL, { 0xFF, 0xFF, opBCC_REL, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }, 64 | { "TYA", prmNONE, { opTYA, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }, 65 | { "TXS", prmNONE, { opTXS, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }, 66 | { "LDY", prmIMD | prm0PG | prmABS | prm0PX | prmABX, { 0xFF, opLDY_IMD, 0xFF, opLDY_0PG, opLDY_0PX, 0xFF, opLDY_ABS, opLDY_ABX, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }, 67 | { "LDA", prmNDX | prm0PG | prmIMD | prmABS | prmNDY | prm0PX | prmABY | prmABX, { 0xFF, opLDA_IMD, 0xFF, opLDA_0PG, opLDA_0PX, 0xFF, opLDA_ABS, opLDA_ABX, opLDA_ABY, 0xFF, opLDA_NDX, opLDA_NDY, 0xFF } }, 68 | { "LDX", prmIMD | prm0PG | prmABS | prm0PY | prmABY, { 0xFF, opLDX_IMD, 0xFF, opLDX_0PG, 0xFF, opLDX_0PY, opLDX_ABS, 0xFF, opLDX_ABY, 0xFF, 0xFF, 0xFF, 0xFF } }, 69 | { "TAY", prmNONE, { opTAY, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }, 70 | { "TAX", prmNONE, { opTAX, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }, 71 | { "BCS", prmREL, { 0xFF, 0xFF, opBCS_REL, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }, 72 | { "CLV", prmNONE, { opCLV, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }, 73 | { "TSX", prmNONE, { opTSX, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }, 74 | { "CPY", prmIMD | prm0PG | prmABS, { 0xFF, opCPY_IMD, 0xFF, opCPY_0PG, 0xFF, 0xFF, opCPY_ABS, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }, 75 | { "CMP", prmNDX | prm0PG | prmIMD | prmABS | prmNDY | prm0PX | prmABY | prmABX, { 0xFF, opCMP_IMD, 0xFF, opCMP_0PG, opCMP_0PX, 0xFF, opCMP_ABS, opCMP_ABX, opCMP_ABY, 0xFF, opCMP_NDX, opCMP_NDY, 0xFF } }, 76 | { "DEC", prm0PG | prmABS | prm0PX | prmABX, { 0xFF, 0xFF, 0xFF, opDEC_0PG, opDEC_0PX, 0xFF, opDEC_ABS, opDEC_ABX, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }, 77 | { "INY", prmNONE, { opINY, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }, 78 | { "DEX", prmNONE, { opDEX, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }, 79 | { "BNE", prmREL, { 0xFF, 0xFF, opBNE_REL, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }, 80 | { "CLD", prmNONE, { opCLD, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }, 81 | { "CPX", prmIMD | prm0PG | prmABS, { 0xFF, opCPX_IMD, 0xFF, opCPX_0PG, 0xFF, 0xFF, opCPX_ABS, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }, 82 | { "SBC", prmNDX | prm0PG | prmIMD | prmABS | prmNDY | prm0PX | prmABY | prmABX, { 0xFF, opSBC_IMD, 0xFF, opSBC_0PG, opSBC_0PX, 0xFF, opSBC_ABS, opSBC_ABX, opSBC_ABY, 0xFF, opSBC_NDX, opSBC_NDY, 0xFF } }, 83 | { "INC", prm0PG | prmABS | prm0PX | prmABX, { 0xFF, 0xFF, 0xFF, opINC_0PG, opINC_0PX, 0xFF, opINC_ABS, opINC_ABX, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }, 84 | { "INX", prmNONE, { opINX, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }, 85 | { "NOP", prmNONE, { opNOP, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }, 86 | { "BEQ", prmREL, { 0xFF, 0xFF, opBEQ_REL, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }, 87 | { "SED", prmNONE, { opSED, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }, 88 | { "NOP", prmNONE, { opNOP, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }, 89 | }; 90 | 91 | -------------------------------------------------------------------------------- /opcodetable.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #ifndef _OPTABLE_H_ 12 | #define _OPTABLE_H_ 13 | 14 | // op modifiers 15 | #define omREAD_A 0x0001 16 | #define omREAD_X 0x0002 17 | #define omREAD_Y 0x0004 18 | #define omREAD_RAM 0x0008 19 | #define omREAD_CODE 0x0010 20 | #define omREAD_IMD 0x0020 21 | #define omWRITE_A 0x0100 22 | #define omWRITE_X 0x0200 23 | #define omWRITE_Y 0x0400 24 | #define omWRITE_RAM 0x0800 25 | // omWRITE_CODE 0x1000 not possible, just here for looks ;) 26 | // omWRITE_IMD 0x2000 ditto 27 | 28 | // param masks 29 | #define prmNONE 0x0001 // 30 | #define prmIMD 0x0002 //#$xx 31 | #define prmREL 0x0004 //$xx,PC (8-bit signed displacement, relative to PC) 32 | #define prm0PG 0x0008 //$xx 33 | #define prm0PX 0x0010 //$xx,X 34 | #define prm0PY 0x0020 //$xx,Y 35 | #define prmABS 0x0040 //$xxxx 36 | #define prmABX 0x0080 //$xxxx,X 37 | #define prmABY 0x0100 //$xxxx,Y 38 | #define prmIND 0x0200 //($xxxx) 39 | #define prmNDX 0x0400 //($xx,X) 40 | #define prmNDY 0x0800 //($xx),Y 41 | #define prmA 0x1000 //A 42 | 43 | // param indexes 44 | #define priNONE 0 45 | #define priIMD 1 46 | #define priREL 2 47 | #define pri0PG 3 48 | #define pri0PX 4 49 | #define pri0PY 5 50 | #define priABS 6 51 | #define priABX 7 52 | #define priABY 8 53 | #define priIND 9 54 | #define priNDX 10 55 | #define priNDY 11 56 | #define priA 12 57 | 58 | #define prtTOTAL 13 59 | 60 | // arg types 61 | #define argNONE 0 62 | #define argIMD 1 63 | #define argADDR 2 64 | #define argZPADDR 3 65 | #define argRELADDR 4 66 | #define argINDADDR 5 67 | #define argINDZPADDR 6 68 | #define argA 7 69 | #define argX 8 70 | #define argY 9 71 | 72 | #define opTOTAL_UNIQUE 57 73 | #define opTOTAL 151 74 | 75 | #define opBRK_IMD 0x00 76 | #define opORA_NDX 0x01 77 | #define opORA_0PG 0x05 78 | #define opASL_0PG 0x06 79 | #define opPHP 0x08 80 | #define opORA_IMD 0x09 81 | #define opASL_A 0x0A 82 | #define opORA_ABS 0x0D 83 | #define opASL_ABS 0x0E 84 | #define opBPL_REL 0x10 85 | #define opORA_NDY 0x11 86 | #define opORA_0PX 0x15 87 | #define opASL_0PX 0x16 88 | #define opCLC 0x18 89 | #define opORA_ABY 0x19 90 | #define opORA_ABX 0x1D 91 | #define opASL_ABX 0x1E 92 | #define opJSR_ABS 0x20 93 | #define opAND_NDX 0x21 94 | #define opBIT_0PG 0x24 95 | #define opAND_0PG 0x25 96 | #define opROL_0PG 0x26 97 | #define opPLP 0x28 98 | #define opAND_IMD 0x29 99 | #define opROL_A 0x2A 100 | #define opBIT_ABS 0x2C 101 | #define opAND_ABS 0x2D 102 | #define opROL_ABS 0x2E 103 | #define opBMI_REL 0x30 104 | #define opAND_NDY 0x31 105 | #define opAND_0PX 0x35 106 | #define opROL_0PX 0x36 107 | #define opSEC 0x38 108 | #define opAND_ABY 0x39 109 | #define opAND_ABX 0x3D 110 | #define opROL_ABX 0x3E 111 | #define opRTI 0x40 112 | #define opEOR_NDX 0x41 113 | #define opEOR_0PG 0x45 114 | #define opLSR_0PG 0x46 115 | #define opPHA 0x48 116 | #define opEOR_IMD 0x49 117 | #define opLSR_A 0x4A 118 | #define opJMP_ABS 0x4C 119 | #define opEOR_ABS 0x4D 120 | #define opLSR_ABS 0x4E 121 | #define opBVC_REL 0x50 122 | #define opEOR_NDY 0x51 123 | #define opEOR_0PX 0x55 124 | #define opLSR_0PX 0x56 125 | #define opCLI 0x58 126 | #define opEOR_ABY 0x59 127 | #define opEOR_ABX 0x5D 128 | #define opLSR_ABX 0x5E 129 | #define opRTS 0x60 130 | #define opADC_NDX 0x61 131 | #define opADC_0PG 0x65 132 | #define opROR_0PG 0x66 133 | #define opPLA 0x68 134 | #define opADC_IMD 0x69 135 | #define opROR_A 0x6A 136 | #define opJMP_IND 0x6C 137 | #define opADC_ABS 0x6D 138 | #define opROR_ABS 0x6E 139 | #define opBVS_REL 0x70 140 | #define opADC_NDY 0x71 141 | #define opADC_0PX 0x75 142 | #define opROR_0PX 0x76 143 | #define opSEI 0x78 144 | #define opADC_ABY 0x79 145 | #define opADC_ABX 0x7D 146 | #define opROR_ABX 0x7E 147 | #define opSTA_NDX 0x81 148 | #define opSTY_0PG 0x84 149 | #define opSTA_0PG 0x85 150 | #define opSTX_0PG 0x86 151 | #define opDEY 0x88 152 | #define opTXA 0x8A 153 | #define opSTY_ABS 0x8C 154 | #define opSTA_ABS 0x8D 155 | #define opSTX_ABS 0x8E 156 | #define opBCC_REL 0x90 157 | #define opSTA_NDY 0x91 158 | #define opSTY_0PX 0x94 159 | #define opSTA_0PX 0x95 160 | #define opSTX_0PY 0x96 161 | #define opTYA 0x98 162 | #define opSTA_ABY 0x99 163 | #define opTXS 0x9A 164 | #define opSTA_ABX 0x9D 165 | #define opLDY_IMD 0xA0 166 | #define opLDA_NDX 0xA1 167 | #define opLDX_IMD 0xA2 168 | #define opLDY_0PG 0xA4 169 | #define opLDA_0PG 0xA5 170 | #define opLDX_0PG 0xA6 171 | #define opTAY 0xA8 172 | #define opLDA_IMD 0xA9 173 | #define opTAX 0xAA 174 | #define opLDY_ABS 0xAC 175 | #define opLDA_ABS 0xAD 176 | #define opLDX_ABS 0xAE 177 | #define opBCS_REL 0xB0 178 | #define opLDA_NDY 0xB1 179 | #define opLDY_0PX 0xB4 180 | #define opLDA_0PX 0xB5 181 | #define opLDX_0PY 0xB6 182 | #define opCLV 0xB8 183 | #define opLDA_ABY 0xB9 184 | #define opTSX 0xBA 185 | #define opLDY_ABX 0xBC 186 | #define opLDA_ABX 0xBD 187 | #define opLDX_ABY 0xBE 188 | #define opCPY_IMD 0xC0 189 | #define opCMP_NDX 0xC1 190 | #define opCPY_0PG 0xC4 191 | #define opCMP_0PG 0xC5 192 | #define opDEC_0PG 0xC6 193 | #define opINY 0xC8 194 | #define opCMP_IMD 0xC9 195 | #define opDEX 0xCA 196 | #define opCPY_ABS 0xCC 197 | #define opCMP_ABS 0xCD 198 | #define opDEC_ABS 0xCE 199 | #define opBNE_REL 0xD0 200 | #define opCMP_NDY 0xD1 201 | #define opCMP_0PX 0xD5 202 | #define opDEC_0PX 0xD6 203 | #define opCLD 0xD8 204 | #define opCMP_ABY 0xD9 205 | #define opCMP_ABX 0xDD 206 | #define opDEC_ABX 0xDE 207 | #define opCPX_IMD 0xE0 208 | #define opSBC_NDX 0xE1 209 | #define opCPX_0PG 0xE4 210 | #define opSBC_0PG 0xE5 211 | #define opINC_0PG 0xE6 212 | #define opINX 0xE8 213 | #define opSBC_IMD 0xE9 214 | #define opNOP 0xEA 215 | #define opCPX_ABS 0xEC 216 | #define opSBC_ABS 0xED 217 | #define opINC_ABS 0xEE 218 | #define opBEQ_REL 0xF0 219 | #define opSBC_NDY 0xF1 220 | #define opSBC_0PX 0xF5 221 | #define opINC_0PX 0xF6 222 | #define opSED 0xF8 223 | #define opSBC_ABY 0xF9 224 | #define opSBC_ABX 0xFD 225 | #define opINC_ABX 0xFE 226 | 227 | typedef struct { 228 | int index, mask; 229 | char* name; 230 | int argSize, argCount; 231 | int arg1, arg2; 232 | } OPARGS; 233 | 234 | extern OPARGS opArgs[prtTOTAL]; 235 | 236 | typedef struct { 237 | char name[4]; 238 | U16 paramTypes; 239 | //U16 modifiers; 240 | U8 codes[prtTOTAL]; 241 | } OPCODE; 242 | 243 | extern OPCODE opcodes[opTOTAL_UNIQUE]; 244 | 245 | 246 | #endif 247 | 248 | -------------------------------------------------------------------------------- /output/banks.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #ifndef banksH 12 | #define banksH 13 | 14 | typedef struct _BANK { 15 | struct _BANK* next; 16 | S16 type; 17 | S16 bank; 18 | S32 org; 19 | S32 maxsize; 20 | U8* buffer, *ptr, *end; 21 | char* label; 22 | } BANK; 23 | 24 | enum _BANK_TYPE { 25 | BANKTYPE_RAM, 26 | BANKTYPE_ROM, 27 | BANKTYPE_CHR, 28 | 29 | BANKTYPE_TOTAL, 30 | }; 31 | 32 | #define BANK_OFFSET(bank) GET_BUF_OFFSET((bank)->buffer, (bank)->ptr) 33 | #define BANK_OFFSET_OF(bank, ptr) GET_BUF_OFFSET((bank)->buffer, ptr) 34 | #define BANK_REMAINING(bank, ptr) GET_BUF_OFFSET(ptr, (bank)->end) 35 | #define MAX_BANKCOUNT 4096 36 | #define MAX_BANKSIZE 65536 37 | 38 | extern char szPadding[65], *szPadPtr; 39 | extern int bankCounts[BANKTYPE_TOTAL]; 40 | extern BANK* banks, *bankPtr, *curBank, ramBank; 41 | 42 | extern S32 bankSizes[BANKTYPE_TOTAL]; 43 | extern char* szBankTypes[]; 44 | 45 | BOOL InitBanks(void); 46 | void FreeBanks(void); 47 | BANK* FindBank(char* label); 48 | void SetBank(S16 type, char* label); 49 | 50 | #define CheckCurBank() \ 51 | \ 52 | { \ 53 | if (!curBank) \ 54 | fatal(FTL_NOACTIVEBANK); \ 55 | \ 56 | } 57 | #define CheckRomBank() \ 58 | \ 59 | { \ 60 | if (!curBank) \ 61 | fatal(FTL_NOACTIVEBANK); \ 62 | if (curBank->type != BANKTYPE_ROM) \ 63 | fatal(FTL_NOTROMBANK, curBank->label); \ 64 | \ 65 | } 66 | #define CheckChrBank() \ 67 | \ 68 | { \ 69 | if (!curBank) \ 70 | fatal(FTL_NOACTIVEBANK); \ 71 | if (curBank->type != BANKTYPE_CHR) \ 72 | fatal(FTL_NOTCHRBANK, curBank->label); \ 73 | \ 74 | } 75 | 76 | void LabelBank(char* label); 77 | 78 | void AlignCode(int align); 79 | S32 GetBankOffset(void); 80 | S32 GetBankSpace(void); 81 | 82 | void BankWrite(U8* data, S32 size); 83 | void BankFill(U8 c, S32 size); 84 | void BankSeekFwd(S32 size); 85 | void BankSeek(S32 dest); 86 | void BankSeekIntVect(S32 dest); 87 | void BankPutB(S8 code); 88 | void BankPutW(S16 code); 89 | void BankWriteIntVect(S16 code); 90 | void BankPutL(S32 code); 91 | 92 | U32 CountBanksize(int type); 93 | void FWriteBanks(int type, FILE* f); 94 | 95 | BOOL IncBin(char* filename, S32 maxsize); 96 | char GetPadChar(void); 97 | 98 | U32 GetBankIndex(BANK* bank, int banksize); 99 | 100 | long GetBankBinOffset(BANK* bank); 101 | long GetBankBinLength(BANK* bankOfPtr, U8* ptr, BANK* bankSpan); 102 | 103 | #endif 104 | 105 | -------------------------------------------------------------------------------- /output/fixoffs.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #pragma hdrstop 12 | #include "../compiler.h" 13 | 14 | #pragma package(smart_init) 15 | 16 | FIXOFFS* fixOffs; 17 | 18 | 19 | 20 | 21 | void AddFixOffs(S16 type, S16 size, U8* ptr, S32 org, void* data) 22 | { 23 | FIXOFFS* fix; 24 | INSCRIPT* scr = curScript; 25 | if (scr) 26 | while (scr->parent && !scr->path) 27 | scr = scr->parent; 28 | 29 | if (PRECOMPILING) 30 | return; 31 | 32 | fix = (FIXOFFS*)ssAlloc(sizeof(FIXOFFS)); 33 | 34 | if (curMacro && (type == FIXTYPE_LABEL) && (((LABEL*)data)->flags & LABELFLAG_MACKER)) { 35 | fix->prev = curMacro->fixoffs; 36 | curMacro->fixoffs = fix; 37 | } else { 38 | fix->prev = fixOffs; 39 | fixOffs = fix; 40 | } 41 | 42 | fix->type = type; 43 | fix->ptr = ptr; 44 | fix->org = org; 45 | fix->size = size; 46 | fix->data = data; 47 | 48 | if (scr) { 49 | fix->filename = strdup(scr->filename); 50 | fix->line = scr->line; 51 | } else 52 | fix->filename = NULL; 53 | } 54 | 55 | 56 | void FreeFixoffs(FIXOFFS** pfix) 57 | { 58 | FIXOFFS* fix = *pfix, *iNext; 59 | 60 | if (fix) { 61 | while (fix) { 62 | iNext = fix->prev; 63 | ssFree(fix->filename); 64 | ssFree(fix); 65 | fix = iNext; 66 | } 67 | 68 | *pfix = NULL; 69 | } 70 | } 71 | 72 | 73 | void DoFixOffs(FIXOFFS* fix) 74 | { 75 | S32 value, newoffset; 76 | 77 | if (fix) { 78 | while (fix) { 79 | value = GetLabelObjectOffset(fix->data, fix->type); 80 | if (fix->size == FIXOFFS_NEAR) { 81 | newoffset = (S32)value - fix->org; 82 | if (newoffset < -128 || newoffset > 127) { 83 | errorf(fix->filename, fix->line, ERR_FIXOFFSNEAR, GetLabelObjectName(fix->data, fix->type)); 84 | } else 85 | PUTB(fix->ptr, (U8)newoffset); 86 | } else if (fix->size == FIXOFFS_FAR) { 87 | PUTW(fix->ptr, (U16)value); 88 | } else if (fix->size == FIXOFFS_WORD) { 89 | PUTW(fix->ptr, (U16)value); 90 | } else if (fix->size == FIXOFFS_BYTE) { 91 | PUTB(fix->ptr, (U8)value); 92 | } else { 93 | newoffset = AccOpNum(fix->size - FIXOFFS_ARITH, (U16)value); 94 | PUTB(fix->ptr, (U8)newoffset); 95 | } 96 | fix = fix->prev; 97 | } 98 | } 99 | } 100 | 101 | 102 | 103 | S32 GetLabelObjectOffset(void* labelObject, int type) 104 | { 105 | S32 value; 106 | switch (type) { 107 | case FIXTYPE_LABEL: 108 | value = ((LABEL*)labelObject)->offset; 109 | break; 110 | case FIXTYPE_FUNCTION: 111 | value = ((FUNC*)labelObject)->offset; 112 | break; 113 | case FIXTYPE_VARIABLE: 114 | value = ((VAR*)labelObject)->offset; 115 | break; 116 | } 117 | return value; 118 | } 119 | 120 | 121 | char* GetLabelObjectName(void* labelObject, int type) 122 | { 123 | char* value; 124 | switch (type) { 125 | case FIXTYPE_LABEL: 126 | value = ((LABEL*)labelObject)->label; 127 | break; 128 | case FIXTYPE_FUNCTION: 129 | value = ((FUNC*)labelObject)->label; 130 | break; 131 | case FIXTYPE_VARIABLE: 132 | value = ((VAR*)labelObject)->label; 133 | break; 134 | } 135 | return value; 136 | } 137 | 138 | 139 | -------------------------------------------------------------------------------- /output/fixoffs.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #ifndef fixoffsH 12 | #define fixoffsH 13 | 14 | 15 | 16 | #define FIXTYPE_NONE 0 17 | #define FIXTYPE_LABEL 1 18 | #define FIXTYPE_FUNCTION 2 19 | #define FIXTYPE_VARIABLE 3 20 | 21 | #define FIXOFFS_NEAR 1 22 | #define FIXOFFS_FAR 3 23 | #define FIXOFFS_BYTE 4 24 | #define FIXOFFS_WORD 5 25 | #define FIXOFFS_ARITH 10 26 | 27 | typedef struct _FIXOFFS { 28 | struct _FIXOFFS* prev; 29 | S16 type; 30 | S16 size; 31 | U8* ptr; 32 | S32 org; 33 | void* data; // obj ptr, function ptr, etc. 34 | 35 | char* filename; 36 | int line; 37 | } FIXOFFS; 38 | 39 | extern FIXOFFS* fixOffs; 40 | 41 | void AddFixOffs(S16 type, S16 size, U8* ptr, S32 org, void* data); 42 | void FreeFixoffs(FIXOFFS** pfix); 43 | void DoFixOffs(FIXOFFS* fix); 44 | 45 | S32 GetLabelObjectOffset(void* labelObject, int type); 46 | char* GetLabelObjectName(void* labelObject, int type); 47 | 48 | #endif 49 | 50 | -------------------------------------------------------------------------------- /output/outbuf.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #pragma hdrstop 12 | #include "../compiler.h" 13 | 14 | #pragma package(smart_init) 15 | 16 | OUTBUF rCode, labelStrings; 17 | 18 | void SetupOutbuf(OUTBUF* out, U32 size) 19 | { 20 | out->buffer = out->ptr = ssCalloc(size); 21 | out->end = out->buffer + size; 22 | } 23 | 24 | BOOL WriteOutbuf(OUTBUF* outbuf, U8* data, U16 size) 25 | { 26 | if (outbuf->ptr + size > outbuf->end) { 27 | fatal(FTL_OUTPUTSCRIPTOVERFLO); 28 | } 29 | memcpy(outbuf->ptr, data, size); 30 | outbuf->ptr += size; 31 | return TRUE; 32 | } 33 | 34 | void SeekFwdOutbuf(OUTBUF* outbuf, U16 size) 35 | { 36 | if (outbuf->ptr + size > outbuf->end) { 37 | fatal(FTL_OUTPUTSCRIPTOVERFLO); 38 | } 39 | outbuf->ptr += size; 40 | } 41 | 42 | void SeekOutbuf(OUTBUF* outbuf, U16 dest) 43 | { 44 | if ((S32)dest > (S32)GET_BUF_OFFSET(outbuf->buffer, outbuf->end)) { 45 | fatal(FTL_OUTPUTSCRIPTOVERFLO); 46 | } 47 | outbuf->ptr = outbuf->buffer + dest; 48 | } 49 | 50 | void obPutB(OUTBUF* outbuf, S8 code) 51 | { 52 | *outbuf->ptr++ = code; 53 | } 54 | 55 | void obPutW(OUTBUF* outbuf, S16 code) 56 | { 57 | PUTWi(outbuf->ptr, code); 58 | } 59 | 60 | void obPutL(OUTBUF* outbuf, S32 code) 61 | { 62 | PUTLi(outbuf->ptr, code); 63 | } 64 | 65 | U8 obPeekB(OUTBUF* outbuf, S32 offs) 66 | { 67 | return outbuf->ptr[offs]; 68 | } 69 | 70 | BOOL FWriteOutbuf(char* name, char* ext, OUTBUF* outbuf) 71 | { 72 | FILE* f; 73 | U32 len = GET_BUF_OFFSET((U32)outbuf->buffer, (U32)outbuf->ptr); 74 | if (len) { 75 | sprintf(szTemp, "%s%c%05d.%s", name, PATH_SEP, scriptNumber, ext); 76 | if ((f = OpenFile(DIR_GAME, szTemp, "wb")) == NULL) { 77 | fatal(FTL_SAVINGRESOURCE, szTemp); 78 | } 79 | FWrite(outbuf->buffer, len, f); 80 | CloseFile(f); 81 | } 82 | return TRUE; 83 | } 84 | 85 | 86 | char* OutBuf_FindLabel(OUTBUF* outbuf, char* label) 87 | { 88 | char* p = (char*)outbuf->buffer; 89 | while (p < (char*)outbuf->ptr) { 90 | if (STRCMP(p, label) == 0) 91 | return p; 92 | p += strlen(p) + 1; 93 | } 94 | return NULL; 95 | } 96 | 97 | char* OutBuf_AddLabel(OUTBUF* outbuf, char* label) 98 | { 99 | int len = (int)strlen(label) + 1; 100 | char* p = OutBuf_FindLabel(outbuf, label); 101 | if (p) 102 | return p; 103 | p = (char*)outbuf->ptr; 104 | if ((outbuf->ptr += len) < outbuf->end) { 105 | memcpy(p, label, len); 106 | return p; 107 | } 108 | fatal(FTL_LABELMEMORY, label); 109 | return NULL; 110 | } 111 | 112 | U16 OutBuf_AddLabelIdx(OUTBUF* outbuf, char* label) 113 | { 114 | return (U16)GET_BUF_OFFSET(outbuf->buffer, OutBuf_AddLabel(outbuf, label)); 115 | } 116 | 117 | -------------------------------------------------------------------------------- /output/outbuf.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #ifndef outbufH 12 | #define outbufH 13 | 14 | #include "../system/memalloc.h" 15 | 16 | #define MAX_RES_NUM 65535 17 | #define MAX_RES_SIZE 64000 18 | #define CLASS_SCRIPT MAX_RES_NUM 19 | #define GLOBAL_SCRIPT MAX_RES_NUM 20 | 21 | typedef struct { 22 | U8* buffer, *ptr, *end; 23 | } OUTBUF; 24 | 25 | #define OB_SIZE(ob) (GET_BUF_OFFSET((U32)(ob).buffer, (U32)(ob).ptr)) 26 | 27 | extern OUTBUF rCode, rVarData, rText, rCodeData, labelStrings; 28 | 29 | void SetupOutbuf(OUTBUF* out, U32 size); 30 | 31 | BOOL WriteOutbuf(OUTBUF* outbuf, U8* data, U16 size); 32 | void SeekFwdOutbuf(OUTBUF* outbuf, U16 size); 33 | void SeekOutbuf(OUTBUF* outbuf, U16 dest); 34 | void obPutB(OUTBUF* outbuf, S8 code); 35 | void obPutW(OUTBUF* outbuf, S16 code); 36 | void obPutL(OUTBUF* outbuf, S32 code); 37 | U8 obPeekB(OUTBUF* outbuf, S32 offs); 38 | BOOL FWriteOutbuf(char* name, char* ext, OUTBUF* outbuf); 39 | 40 | char* OutBuf_FindLabel(OUTBUF* outbuf, char* label); 41 | char* OutBuf_AddLabel(OUTBUF* outbuf, char* label); 42 | U16 OutBuf_AddLabelIdx(OUTBUF* outbuf, char* label); 43 | 44 | #endif 45 | 46 | -------------------------------------------------------------------------------- /output/scrbin.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #ifndef scrbinH 12 | #define scrbinH 13 | 14 | typedef struct { 15 | int mapper; 16 | int mirroring; 17 | int battery; 18 | int trainer; 19 | int fourscreen; 20 | int prgCount; 21 | int chrCount; 22 | int prgrepeat, chrrepeat; 23 | U8 ineshdr[16]; 24 | } ROMHEADER; 25 | extern ROMHEADER romHeader; 26 | extern FILE* fSrcList; 27 | 28 | void InitROMHeader(void); 29 | void AssembleScriptBinary(void); 30 | 31 | #endif 32 | 33 | -------------------------------------------------------------------------------- /output/writecode.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #pragma hdrstop 12 | #include "../compiler.h" 13 | 14 | #pragma package(smart_init) 15 | 16 | 17 | 18 | 19 | 20 | U16 GetCodeOffset() 21 | { 22 | return (U16)GET_BUF_OFFSET(rCode.buffer, rCode.ptr); 23 | } 24 | 25 | void WriteOpcode(U8 code) 26 | { 27 | if (!PRECOMPILING) { 28 | 29 | //logprint("\n//%04X: %s",GetCodeOffset(),szOpcodes[code]); 30 | BankPutB(code); 31 | } 32 | } 33 | 34 | void WriteCodeB(S32 code) 35 | { 36 | if (!PRECOMPILING) { 37 | code = ConfirmChar(code); 38 | BankPutB((S8)code); 39 | logprint(" %d", code); 40 | } 41 | } 42 | 43 | void WriteCodeW(S32 code) 44 | { 45 | if (!PRECOMPILING) { 46 | code = ConfirmWord(code); 47 | BankPutW((S16)code); 48 | logprint(" %d", code); 49 | } 50 | } 51 | 52 | void WriteCodeL(S32 code) 53 | { 54 | if (!PRECOMPILING) { 55 | BankPutL(code); 56 | logprint(" %d", code); 57 | } 58 | } 59 | 60 | void WriteOpcodeB(U8 code, S32 value) 61 | { 62 | WriteOpcode(code); 63 | WriteCodeB(value); 64 | } 65 | 66 | void WriteOpcodeW(U8 code, S32 value) 67 | { 68 | WriteOpcode(code); 69 | WriteCodeW(value); 70 | } 71 | 72 | void WriteOpcodeL(U8 code, S32 value) 73 | { 74 | WriteOpcode(code); 75 | WriteCodeL(value); 76 | } 77 | 78 | void WriteCodeWL(U8 opw, U8 opl, S32 value) 79 | { 80 | if (value & 0xFFFF8000) { 81 | WriteOpcode(opw); 82 | WriteCodeW((S16)value); 83 | } else { 84 | WriteOpcode(opl); 85 | WriteCodeL(value); 86 | } 87 | } 88 | 89 | void WriteReturn() 90 | { 91 | if (curFunction) 92 | switch (curFunction->type) { 93 | case FUNCTYPE_FUNCTION: 94 | WriteOpcode(opRTS); 95 | break; 96 | case FUNCTYPE_INTERRUPT: 97 | WriteOpcode(opRTI); 98 | break; 99 | } 100 | } 101 | 102 | -------------------------------------------------------------------------------- /output/writecode.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #ifndef writecodeH 12 | #define writecodeH 13 | 14 | 15 | 16 | 17 | U16 GetCodeOffset(void); 18 | 19 | void WriteOpcode(U8 code); 20 | void WriteOpcodeB(U8 code, S32 value); 21 | void WriteOpcodeW(U8 code, S32 value); 22 | void WriteOpcodeL(U8 code, S32 value); 23 | void WriteCodeB(S32 code); 24 | void WriteCodeW(S32 code); 25 | void WriteCodeL(S32 code); 26 | void WriteCodeWL(U8 opw, U8 opl, S32 value); 27 | 28 | void WriteReturn(void); 29 | 30 | #endif 31 | 32 | -------------------------------------------------------------------------------- /prepbase.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #pragma hdrstop 12 | #include "compiler.h" 13 | 14 | #pragma package(smart_init) 15 | 16 | PLIST* defList, *defListPtr; 17 | ENUMCLASS* enumClasses; 18 | BOOL USE_DEFS; 19 | 20 | 21 | BOOL AddDefine(char* label, char* definition) 22 | { 23 | DEFINE* def, *lastDef; 24 | char* szS, *szE, *s; 25 | 26 | // if(!STRCMP(label,"_STD_MEMORY_H")) 27 | // szS=szS; 28 | 29 | if (!IsStringLabel(label)) { 30 | error(ERR_BADLABEL, szTemp); 31 | return FALSE; 32 | } 33 | 34 | if ((lastDef = FindDefine(defList, label)) != NULL) { 35 | if (lastDef->definition && lastDef->definition[0]) 36 | warning(WRN_DEFALREADYDEF, szTemp, lastDef->definition); 37 | // NULL DEFS OK 38 | } 39 | 40 | if (IsLabelUsed(label, vars)) 41 | label[0] = '\0'; 42 | 43 | if (!defListPtr || defListPtr->entCount == DEFSET_SIZE) 44 | defListPtr = NewList(defListPtr, sizeof(DEFINE) * DEFSET_SIZE); 45 | if (!defList) 46 | defList = defListPtr; 47 | 48 | def = ((DEFINE*)defListPtr->data) + defListPtr->entCount; 49 | def->label = strdup(label); 50 | if (definition) { 51 | def->definition = strdup(definition); 52 | } else { 53 | szS = curScript->inPtr; 54 | szE = SkipLine(TRUE); 55 | def->definition = s = (char*)ssAlloc((U32)(szE - szS + 1)); 56 | while (szS < szE && issep(*szS)) 57 | szS++; 58 | while (szS < szE) { 59 | if (*szS == '\\' && (szS[1] == '\r' || szS[1] == '\n')) 60 | szS += 2; 61 | else if (*szS == '\r' || *szS == '\n') 62 | szS++; 63 | else 64 | *s++ = *szS++; 65 | } 66 | *s = '\0'; 67 | } 68 | defListPtr->entCount++; 69 | 70 | if (lastDef && STRCMP(lastDef->definition, def->definition)) { 71 | warning(WRN_REDEFNOTIDENTICAL, szTemp); 72 | } 73 | return TRUE; 74 | } 75 | 76 | ENUMCLASS* FindEnumClass(char* label) 77 | { 78 | ENUMCLASS* enumClass = enumClasses; 79 | while (enumClass) { 80 | if (!STRCMP(enumClass->label, label)) 81 | break; 82 | enumClass = enumClass->prev; 83 | } 84 | return enumClass; 85 | } 86 | 87 | void FreeEnumClasses() 88 | { 89 | ENUMCLASS* enumClass = enumClasses, *next; 90 | while (enumClass) { 91 | next = enumClass->prev; 92 | 93 | FreeLists(&enumClass->defList); 94 | 95 | ssFree(enumClass->label); 96 | ssFree(enumClass); 97 | 98 | enumClass = next; 99 | } 100 | } 101 | 102 | BOOL AddEnum(char* szenumclass, char* label, int index) 103 | { 104 | DEFINE* def; 105 | ENUMCLASS* enumClass; 106 | 107 | if (szenumclass) { 108 | if ((enumClass = FindEnumClass(szenumclass)) == NULL) { 109 | // add it 110 | enumClass = (ENUMCLASS*)ssCalloc(sizeof(ENUMCLASS)); 111 | enumClass->label = strdup(szenumclass); 112 | enumClass->prev = enumClasses; 113 | enumClasses = enumClass; 114 | } 115 | 116 | if (!enumClass->defListPtr || enumClass->defListPtr->entCount == DEFSET_SIZE) 117 | enumClass->defListPtr = NewList(enumClass->defListPtr, sizeof(DEFINE) * DEFSET_SIZE); 118 | if (!enumClass->defList) 119 | enumClass->defList = enumClass->defListPtr; 120 | def = ((DEFINE*)enumClass->defListPtr->data) + enumClass->defListPtr->entCount; 121 | 122 | enumClass->defListPtr->entCount++; 123 | 124 | def->label = strdup(label); 125 | def->definition = IntToStr(index); 126 | } else { 127 | return AddDefine(label, IntToStr(index)); 128 | } 129 | 130 | return TRUE; 131 | } 132 | 133 | BOOL DelDefine(char* label) 134 | { 135 | DEFINE* def = FindDefine(defList, label); 136 | // if(!STRCMP(label,"_STD_MEMORY_H")) 137 | // label=label; 138 | if (def) { 139 | def->label[0] = '\0'; 140 | return TRUE; 141 | } 142 | return FALSE; 143 | } 144 | 145 | DEFINE* FindDefine(PLIST* list, char* label) 146 | { 147 | register DEFINE* def; 148 | register int i; 149 | 150 | while (list) { 151 | def = (DEFINE*)list->data; 152 | for (i = list->entCount; i > 0; i--) { 153 | if (!STRCMP(label, def->label)) { 154 | return def; 155 | } 156 | def++; 157 | } 158 | list = list->next; 159 | } 160 | return NULL; 161 | } 162 | 163 | BOOL HandleMacros(char* label) 164 | { 165 | if (USE_DEFS) { 166 | DEFINE* def; 167 | FUNC* func; 168 | PARAM* param; 169 | 170 | if (!(BOOL)(def = FindDefine(defList, label))) { 171 | ENUMCLASS* enm = FindEnumClass(label); 172 | if (enm) { 173 | if (GetNextChar() != '.') { 174 | error(ERR_ENUMCLASSDOT, enm->label, *szTemp); 175 | } else { 176 | def = FindDefine(enm->defList, GetNextWord()); 177 | if (!def) { 178 | error(ERR_ENUMCLASSMEMBER, label, enm->label); 179 | } 180 | } 181 | } 182 | } 183 | if (def) { 184 | if (FindScript(firstScript, NULL, def->label)) { 185 | error(ERR_SELFNESTEDDEF, def->label); 186 | return FALSE; //TRUE; 187 | } 188 | CompileScript(label, def, NULL); 189 | return TRUE; 190 | } 191 | func = curMacro; 192 | while (func) { 193 | param = func->params; 194 | while (param) { 195 | if (!STRCMP(param->def.label, label)) { 196 | if (FindScript(firstScript, NULL, label)) { 197 | error(ERR_SELFNESTEDDEF, label); 198 | return FALSE; //TRUE; 199 | } 200 | CompileScript(label, ¶m->def, NULL); 201 | return TRUE; 202 | } 203 | param = param->prev; 204 | } 205 | func = NULL; //func->prev; 206 | } 207 | } 208 | return FALSE; // none found, but ok 209 | } 210 | 211 | -------------------------------------------------------------------------------- /prepbase.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #ifndef prepbaseH 12 | #define prepbaseH 13 | 14 | 15 | 16 | typedef struct { 17 | char* label; 18 | char* definition; 19 | } DEFINE; 20 | #define DEFSET_SIZE 32 21 | 22 | typedef struct _ENUMCLASS { 23 | struct _ENUMCLASS* prev; 24 | char* label; 25 | PLIST* defList, *defListPtr; 26 | } ENUMCLASS; 27 | 28 | 29 | extern PLIST* defList, *defListPtr; 30 | extern ENUMCLASS* enumClasses; 31 | extern BOOL USE_DEFS; 32 | 33 | BOOL AddDefine(char* label, char* definition); 34 | BOOL AddEnum(char* enumclass, char* label, int index); 35 | BOOL DelDefine(char* label); 36 | DEFINE* FindDefine(PLIST* list, char* label); 37 | BOOL HandleMacros(char* label); 38 | 39 | #endif 40 | 41 | -------------------------------------------------------------------------------- /scrbase.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #ifndef scrbaseH 12 | #define scrbaseH 13 | 14 | #include "prepbase.h" 15 | #include "functions.h" 16 | #include "output/banks.h" 17 | 18 | 19 | #define SCRFLAG_CLONE 0x8000 20 | #define SCRFLAG_LOCKED 0x0001 21 | #define SCRFLAG_MACRO 0x0002 22 | 23 | typedef struct _IFDEF { 24 | struct _IFDEF* prev; 25 | BOOL RESULT, ELSE; 26 | } IFDEF; 27 | 28 | typedef struct _INSCRIPT { 29 | struct _INSCRIPT* parent; 30 | struct _INSCRIPT* child; 31 | 32 | char* path; 33 | char* filename; 34 | 35 | char* buffer; 36 | char* inPtr, *prevPtr; 37 | S32 inLen; 38 | 39 | S32 line; 40 | 41 | U16 flags; 42 | IFDEF* ifdefTrack; 43 | 44 | struct { 45 | BANK* bank; 46 | U8* ptr; 47 | } location; 48 | } INSCRIPT; 49 | 50 | typedef struct _SCRIPTSTATE { 51 | INSCRIPT* firstScript, *curScript; 52 | //char *szTemp; 53 | } SCRIPTSTATE; 54 | 55 | extern S32 scriptNumber; 56 | extern INSCRIPT* firstScript, *curScript; 57 | extern BOOL PRECOMPILING; 58 | 59 | INSCRIPT* AddScript(INSCRIPT* parent, char* filename, DEFINE* def, FUNC* macro); 60 | INSCRIPT* DiscardScript(INSCRIPT* scr); 61 | INSCRIPT* CloneScript(INSCRIPT* scr); 62 | INSCRIPT* FindScript(INSCRIPT* scr, char* path, char* filename); 63 | SCRIPTSTATE* SaveScriptState(void); 64 | void RestoreScriptState(SCRIPTSTATE** pstate); 65 | void DiscardScriptState(SCRIPTSTATE** pstate); 66 | 67 | BOOL CompileScript(char* filename, DEFINE* def, FUNC* macro); 68 | 69 | #endif 70 | 71 | -------------------------------------------------------------------------------- /strhand.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #ifndef strhandH 12 | #define strhandH 13 | 14 | #include "scrbase.h" 15 | 16 | extern S32 scriptNumber; 17 | extern int strToInt_UndefLabel, strToInt_Size, lenSzStr; 18 | extern S16 strToInt_LabelType; 19 | extern void* strToInt_LabelObject; 20 | extern INSCRIPT* firstScript, *curScript; 21 | #define STRING_MAX_SIZE 0x800 22 | extern char szTemp[STRING_MAX_SIZE], szString[STRING_MAX_SIZE]; 23 | 24 | extern char* szDualOps[]; 25 | extern char* szArithOps[]; 26 | extern U8 opAriths[12][2]; 27 | extern char* szCmpOps[]; 28 | extern U8 opCmps[6][2]; 29 | extern char* szAccOps[]; 30 | extern U8 opAccs[6][2]; 31 | extern int invlabel; 32 | 33 | enum _ACCOP { 34 | ACCOP_NOT, 35 | ACCOP_BNOT, 36 | ACCOP_LO, 37 | ACCOP_HI, 38 | ACCOP_NYLO, 39 | ACCOP_NYHI, 40 | ACCOP_SIZEOF, 41 | ACCOP_PLUS, 42 | ACCOP_MINUS, 43 | ACCOP_BANKOF, 44 | 45 | ACCOP_TOTAL 46 | }; 47 | extern char* szObjHdrProps[]; 48 | extern char* szAdditionalKeywords[]; 49 | extern BOOL NEWLINE; 50 | 51 | #define ISNUM(c) (((c) >= '0') && ((c) <= '9')) 52 | #define ISHEX(c) ((((c) >= 'A') && ((c) <= 'F')) || (((c) >= 'a') && ((c) <= 'f'))) 53 | 54 | 55 | char GetNextChar(void); 56 | char PeekNextChar(void); 57 | char* PeekNextWord(void); 58 | char* GetNextWord(void); 59 | char* SkipLine(BOOL TOKOK); 60 | char* SkipBlock(void); 61 | 62 | char* DoString(void); 63 | char* DoStringDirect(void); 64 | S32 StrToIntFull(char* s, S32* outint, void** _labelObject, S16* _labelType); 65 | S32 StrToInt(char* s); 66 | BOOL IsStrNum(char* s); 67 | int IsStrNumEx(char* s); 68 | BOOL IsStrNumA(char* s); 69 | char* IntToStr(S32 num); 70 | BOOL IsStringLabel(char* string); 71 | BOOL DoChar(char* ch); 72 | char* GetCharString(void); 73 | 74 | BOOL SkipFuncBracks(void); 75 | 76 | int GetLineChars(char* start, char* ptr); 77 | int GetLineCharsEx(char* start, char* ptr); 78 | 79 | BOOL CharInStr(char* s, char c); 80 | int StrStarts(char* str, char** slist); 81 | int StrStartsIdx(char* str, char** slist); 82 | char* SeekPastWord(char* str); 83 | char* SeekPastChars(char* str); 84 | int StrInList(char* str, char** slist); 85 | BOOL IsCharLabel(char c); 86 | 87 | S32 ConfirmChar(S32 num); 88 | S32 ConfirmWord(S32 num); 89 | 90 | typedef struct { 91 | char* string; 92 | int index; 93 | } STRINT; 94 | 95 | int StrInStrint(char* string, STRINT* strint); 96 | 97 | void SeekPastBraceBlock(void); 98 | 99 | int ssStrCmp(const char* s1, const char* s2); 100 | 101 | extern char szFull[8192]; 102 | 103 | BOOL issep(char c); 104 | 105 | #define STRCPY(s1, s2) strncpy(s1, s2, sizeof(s1) - 1); 106 | 107 | #endif 108 | 109 | -------------------------------------------------------------------------------- /system/config.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #ifndef configH 12 | #define configH 13 | 14 | typedef struct { 15 | struct { 16 | 17 | struct { 18 | int max; 19 | int level; 20 | } warning; 21 | 22 | struct { 23 | int max; 24 | } error; 25 | 26 | struct { 27 | BOOL enabled; 28 | int max; 29 | } todo; 30 | 31 | struct { 32 | BOOL enabled; 33 | int max; 34 | } tell; 35 | 36 | } msg; 37 | 38 | //struct { 39 | //BOOL stripUnused; 40 | //} func; 41 | 42 | struct { 43 | BOOL vars, functions, banklist, sourcesize; 44 | } list; 45 | 46 | struct { 47 | BOOL rawPrgChr; 48 | BOOL padUp; 49 | BOOL enableHeader; 50 | } output; 51 | } CONFIG; 52 | extern CONFIG cfg; 53 | 54 | enum { 55 | OPPARAMTYPE_NONE = 0, 56 | OPPARAMTYPE_INTEGER = 1, 57 | OPPARAMTYPE_STRING = 2, 58 | }; 59 | 60 | typedef struct { 61 | const char* label; 62 | U16 paramtype; 63 | U16 defaultvalue; 64 | const char* desc; 65 | } COMOP; 66 | 67 | enum { 68 | COMOP_o, 69 | COMOP_h, 70 | 71 | COMOP_emax, 72 | COMOP_wmax, 73 | COMOP_wlevel, 74 | COMOP_todo, 75 | COMOP_todomax, 76 | COMOP_tell, 77 | COMOP_tellmax, 78 | 79 | COMOP_listvars, 80 | COMOP_listfuncs, 81 | COMOP_listbanks, 82 | COMOP_listsrc, 83 | 84 | COMOP_outraw, 85 | COMOP_nopadding, 86 | COMOP_noheader, 87 | 88 | COMOP_total 89 | }; 90 | 91 | extern char szfilename[4096], szoutdir[4096], szprogdir[4096]; 92 | 93 | BOOL InitConfig(void); 94 | void ParseCommandLine(int argc, char* argv[]); 95 | 96 | #endif 97 | 98 | -------------------------------------------------------------------------------- /system/fileio.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #include "../compiler.h" 12 | 13 | char szFile[1024]; 14 | STRLIST* sysDirList, *includeDirList, *libDirList; 15 | char outDir[1024]; 16 | 17 | FILE* PListOpenFile(PLIST* sysDirs, char* filename, char* access) 18 | { 19 | FILE* f = NULL; 20 | while (sysDirs && sysDirs->data) { 21 | sprintf(szFile, "%s%s", (char*)sysDirs->data, filename); 22 | if ((f = fopen(szFile, access)) != NULL) 23 | break; 24 | sysDirs = sysDirs->next; 25 | } 26 | return f; 27 | } 28 | 29 | FILE* StrListOpenFile(STRLIST* list, char* filename, char* access) 30 | { 31 | FILE* f = NULL; 32 | while (list) { /* 33 | char *s = list->string; 34 | long l = strlen(s); 35 | strcpy(szFile,s); 36 | strcpy(szFile+l,filename); */ 37 | sprintf(szFile, "%s%s", list->string, filename); 38 | if ((f = fopen(szFile, access)) != NULL) 39 | break; 40 | list = list->next; 41 | } 42 | return f; 43 | } 44 | 45 | FILE* OpenFile(int dir, char* filename, char* access) 46 | { 47 | FILE* f = NULL; 48 | INSCRIPT* scr = curScript; 49 | if (dir & DIR_SCRIPT) { 50 | while (scr) { 51 | sprintf(szFile, "%s%s", scr->path, filename); 52 | if ((f = fopen(szFile, access)) != NULL) 53 | break; 54 | scr = scr->parent; 55 | } 56 | } 57 | if (!f && (dir & DIR_INCLUDE)) 58 | f = StrListOpenFile(includeDirList, filename, access); 59 | if (!f && (dir & DIR_LIB)) 60 | f = StrListOpenFile(libDirList, filename, access); 61 | if (!f && (dir & DIR_GAME)) { 62 | sprintf(szFile, "%s%s", outDir, filename); 63 | f = fopen(szFile, access); 64 | } 65 | if (!f) { 66 | sprintf(szFile, "%s%s", curScript ? curScript->path : "", filename); 67 | f = fopen(szFile, access); 68 | if (!f) { 69 | strcpy(szFile, filename); 70 | f = fopen(filename, access); 71 | } 72 | } 73 | return f; 74 | } 75 | //--------------------------------------------------------------------------- 76 | U32 FileLen(FILE* fHandle) 77 | { 78 | U32 len, oldPos; 79 | 80 | oldPos = ftell(fHandle); 81 | fseek(fHandle, 0, SEEK_END); 82 | len = ftell(fHandle); 83 | fseek(fHandle, oldPos, SEEK_SET); 84 | 85 | return (U32)len; 86 | } 87 | 88 | U8* LoadFile(int dir, char* filename, S32* _len) 89 | { 90 | U32 len; 91 | U8* buffer = NULL; 92 | FILE* f = OpenFile(dir, filename, "rb"); 93 | if (f) { 94 | len = FileLen(f); 95 | if (len) { 96 | buffer = ssAlloc(len + 1); 97 | FRead(buffer, len, f); 98 | buffer[len] = 0; 99 | } 100 | if (_len) 101 | *_len = len; 102 | CloseFile(f); 103 | } 104 | return buffer; 105 | } 106 | 107 | char* ExtractFilePath(char* filename) 108 | { 109 | char* s; 110 | strcpy(szFile, filename); 111 | s = szFile + strlen(szFile); 112 | while (s != szFile) { 113 | if (*s == PATH_SEP) { 114 | s[1] = '\0'; 115 | return szFile; 116 | } 117 | s--; 118 | } 119 | szFile[0] = '\0'; 120 | return szFile; 121 | } 122 | 123 | char* ExtractFileName(char* filename) 124 | { 125 | char* s; 126 | strcpy(szFile, filename); 127 | s = szFile + strlen(szFile); 128 | while (s != szFile) { 129 | if (*s == PATH_SEP) { 130 | return s + 1; 131 | } 132 | s--; 133 | } 134 | return szFile; 135 | } 136 | 137 | char* SwapFileExt(char* filename, char* newext) 138 | { 139 | char* s; 140 | strcpy(szTemp, filename); 141 | s = szTemp + strlen(szTemp); 142 | while (s != szTemp) { 143 | if (*s == '.') { 144 | break; 145 | } 146 | s--; 147 | } 148 | if (s == szTemp) 149 | s = szTemp + strlen(szTemp); 150 | strcpy(s, newext); 151 | return szTemp; 152 | } 153 | 154 | void FixPath(char* s) 155 | { 156 | int l = (int)strlen(s) - 1; 157 | if (s[l] == PATH_SEP) 158 | s[l] = '\0'; 159 | } 160 | 161 | char* FixPathSet(char* s) 162 | { 163 | int l = (int)strlen(s) - 1; 164 | strcpy(szFile, s); 165 | if (szFile[l] != PATH_SEP) { 166 | szFile[l + 1] = PATH_SEP; 167 | szFile[l + 2] = '\0'; 168 | } 169 | return szFile; 170 | } 171 | 172 | U16 bGetW_(U8** buf) 173 | { 174 | U16 w = *(((U16*)(*(buf)))); //( (*buf)[0] | ((*buf)[1]<<8) ); 175 | *buf += 2; 176 | return w; 177 | } 178 | 179 | U32 bGetL_(U8** buf) 180 | { 181 | U32 l = *(((U32*)(*(buf)))); //( (*buf)[0] | ((*buf)[1]<<8) | ((*buf)[2]<<16) | ((*buf)[3]<<24) ); 182 | *buf += 4; 183 | return l; 184 | } 185 | 186 | void bPutW_(U8** buf, U16 w) 187 | { 188 | *(((U16*)(*(buf)))) = w; 189 | *buf += 2; 190 | } 191 | 192 | void bPutL_(U8** buf, U32 l) 193 | { 194 | *(((U32*)(*(buf)))) = l; 195 | *buf += 4; 196 | } 197 | 198 | void fputscaps(FILE* f, char* s) 199 | { 200 | while (*s) { 201 | if (*s >= 'a' && *s <= 'z') 202 | fputc(*s & 0xDF, f); 203 | else 204 | fputc(*s, f); 205 | s++; 206 | } 207 | } 208 | 209 | BOOL AddDirList(STRLIST** plist, char* label) 210 | { 211 | label = FixPathSet(label); 212 | if (SearchStringList(plist, label)) 213 | return TRUE; 214 | return AddStringList(plist, label); 215 | } 216 | 217 | BOOL SearchStringList(STRLIST** plist, char* label) 218 | { 219 | STRLIST* list = *plist; 220 | while (list) { 221 | if (!STRCMP(list->string, label)) 222 | return TRUE; 223 | list = list->next; 224 | } 225 | return FALSE; 226 | } 227 | 228 | BOOL AddStringList(STRLIST** plist, char* label) 229 | { 230 | STRLIST* list = *plist, *newlist; 231 | 232 | newlist = ssAlloc(sizeof(STRLIST)); 233 | 234 | if (list) { 235 | while (list->next) 236 | list = list->next; 237 | list->next = newlist; 238 | } else 239 | *plist = newlist; 240 | 241 | newlist->next = NULL; 242 | newlist->string = strdup(label); 243 | 244 | return TRUE; 245 | } 246 | 247 | void DisposeStringList(STRLIST** plist) 248 | { 249 | STRLIST* list = *plist, *next; 250 | if (list) 251 | while ((next = list->next) != NULL) { 252 | ssFree(list->string); 253 | ssFree(list); 254 | list = next; 255 | } 256 | *plist = NULL; 257 | } 258 | 259 | void FFill(FILE* f, U32 size) 260 | { 261 | while (size--) 262 | fputc(0, f); 263 | } 264 | 265 | -------------------------------------------------------------------------------- /system/fileio.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #ifndef _fileio_h_ 12 | #define _fileio_h_ 13 | 14 | #include "compiler.h" 15 | #include "list.h" 16 | 17 | #define PATH_SEP '/' 18 | 19 | typedef struct _STRLIST { 20 | struct _STRLIST* next; 21 | char* string; 22 | } STRLIST; 23 | char* FixPathSet(char* s); 24 | BOOL AddDirList(STRLIST** plist, char* label); 25 | BOOL SearchStringList(STRLIST** plist, char* label); 26 | BOOL AddStringList(STRLIST** plist, char* label); 27 | void DisposeStringList(STRLIST** plist); 28 | 29 | extern STRLIST* sysDirList, *includeDirList, *libDirList; 30 | extern char outDir[1024]; 31 | extern char szFile[]; 32 | 33 | #define DIR_ROOT 0 34 | #define DIR_GAME 1 35 | #define DIR_SCRIPT 2 36 | #define DIR_INCLUDE 2 37 | #define DIR_LIB 4 38 | #define DIR_ALL (DIR_GAME | DIR_INCLUDE | DIR_LIB | DIR_SCRIPT) 39 | 40 | FILE* OpenFile(int dir, char* filename, char* access); 41 | FILE* PListOpenFile(PLIST* sysDirs, char* filename, char* access); 42 | FILE* StrListOpenFile(STRLIST* list, char* filename, char* access); 43 | #define CloseFile(f) fclose(f) 44 | U32 FileLen(FILE* fHandle); 45 | U8* LoadFile(int dir, char* filename, S32* _len); 46 | char* ExtractFilePath(char* filename); 47 | char* ExtractFileName(char* filename); 48 | char* SwapFileExt(char* filename, char* newext); 49 | void FixPath(char* s); 50 | void fputscaps(FILE* f, char* s); 51 | 52 | #define FGetB(fHandle) \ 53 | fgetc(fHandle) 54 | #define FGetW(fHandle) \ 55 | (U16)(fgetc(fHandle) | (fgetc(fHandle) << 8)) 56 | #define FGetT(fHandle) \ 57 | (U32)(fgetc(fHandle) | (fgetc(fHandle) << 8) | (fgetc(fHandle) << 16)) 58 | #define FGetL(fHandle) \ 59 | (U32)(fgetc(fHandle) | (fgetc(fHandle) << 8) | (fgetc(fHandle) << 16) | (fgetc(fHandle) << 24)) 60 | #define FPutB(b, fHandle) \ 61 | fputc(b, fHandle) 62 | 63 | 64 | #define FPutW(w, fHandle) \ 65 | \ 66 | { \ 67 | fputc((w)&0xFF, fHandle); \ 68 | fputc((w) >> 8, fHandle); \ 69 | \ 70 | } 71 | #define FPutT(l, fHandle) \ 72 | \ 73 | { \ 74 | fputc((l)&0xFF, fHandle); \ 75 | fputc((l) >> 8, fHandle); \ 76 | fputc((l) >> 16, fHandle); \ 77 | \ 78 | } 79 | #define FPutL(l, fHandle) \ 80 | \ 81 | { \ 82 | fputc((l)&0xFF, fHandle); \ 83 | fputc(((l) >> 8) & 0xFF, fHandle); \ 84 | fputc(((l) >> 16) & 0xFF, fHandle); \ 85 | fputc(((l) >> 24) & 0xFF, fHandle); \ 86 | \ 87 | } 88 | 89 | #define GETB(buf) \ 90 | *(((U8*)((buf)))) 91 | #define GETW(buf) \ 92 | *(((U16*)((buf)))) 93 | #define GETT(buf) \ 94 | (U32)((buf)[0] | ((buf)[1] << 8) | ((buf)[2] << 16)) 95 | #define GETL(buf) \ 96 | (U32)((buf)[0] | ((buf)[1] << 8) | ((buf)[2] << 16) | ((buf)[3] << 24)) 97 | 98 | #define PUTB(buf, b) \ 99 | *((U8*)(buf)) = b 100 | #define PUTW(buf, w) \ 101 | *((U16*)(buf)) = w 102 | #define BPutT(l, buf) \ 103 | (buf)[0] = w & 0xFF; \ 104 | (buf)[1] = w >> 8; \ 105 | (buf)[2] = w >> 16 106 | #define BPutL(l, buf) \ 107 | (buf)[0] = w & 0xFF; \ 108 | (buf)[1] = w >> 8; \ 109 | (buf)[2] = w >> 16; \ 110 | (buf)[3] = w >> 24 111 | 112 | #define FRead(buf, len, fHandle) \ 113 | ((U32)fread(buf, len, 1, fHandle)) 114 | #define FWrite(buf, len, fHandle) \ 115 | ((U32)fwrite(buf, len, 1, fHandle)) 116 | #define FSeek(fHandle, offset, whence) \ 117 | fseek(fHandle, offset, whence) 118 | #define FTell(fHandle) \ 119 | ftell(fHandle) 120 | 121 | #define GET_BUF_OFFSET(a, b) \ 122 | ((U32)(b) - (U32)(a)) 123 | 124 | U16 bGetW_(U8** buf); 125 | U32 bGetL_(U8** buf); 126 | void bPutW_(U8** buf, U16 w); 127 | void bPutL_(U8** buf, U32 l); 128 | 129 | #define GETWi(b) bGetW_(&(b)) 130 | #define GETLi(b) bGetL_(&(b)) 131 | #define PUTWi(b, w) bPutW_(&(b), w) 132 | #define PUTLi(b, l) bPutL_(&(b), l) 133 | 134 | void FFill(FILE* f, U32 size); 135 | 136 | #endif 137 | -------------------------------------------------------------------------------- /system/memalloc.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #include "../compiler.h" 12 | 13 | /* Allocate memory--always use instead of malloc */ 14 | void* ssAlloc(U32 size) 15 | { 16 | void* p; 17 | if ((p = malloc(size)) == NULL) { 18 | fatal(FTL_OUTOFMEMORY, size); 19 | } 20 | return p; 21 | } 22 | 23 | /* Allocate & clear memory--always use instead of calloc */ 24 | void* ssCalloc(U32 size) 25 | { 26 | void* p; 27 | if ((p = calloc(1, size)) == NULL) { 28 | fatal(FTL_OUTOFMEMORY, size); 29 | } 30 | return p; 31 | } 32 | 33 | /* Free allocated memory--always use instead of free() */ 34 | void ssFreeX(void** p) 35 | { 36 | if (*p) 37 | free(*p); 38 | *p = NULL; 39 | } 40 | 41 | void* memclone(void* src, U32 size) 42 | { 43 | void* dest; 44 | dest = ssAlloc(size); 45 | memcpy(dest, src, size); 46 | return dest; 47 | } 48 | 49 | -------------------------------------------------------------------------------- /system/memalloc.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | //--------------------------------------------------------------------------- 11 | #ifndef _memalloc_h_ 12 | #define _memalloc_h_ 13 | //--------------------------------------------------------------------------- 14 | void* ssAlloc(U32 size); 15 | void* ssCalloc(U32 size); 16 | void ssFreeX(void** p); 17 | #define ssFree(p) ssFreeX((void**)&p) 18 | void* memclone(void* src, U32 size); 19 | //--------------------------------------------------------------------------- 20 | #endif 21 | //--------------------------------------------------------------------------- 22 | -------------------------------------------------------------------------------- /system/message.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #ifndef _message_h_ 12 | #define _message_h_ 13 | 14 | #include "compiler.h" 15 | 16 | extern int errorCnt, warnCnt, todoCnt; 17 | extern BOOL COMPILE_SUCCESS; 18 | 19 | void InitMessages(void); 20 | void ShutDownMessages(void); 21 | 22 | void error(int errnum, ...); 23 | void errorf(char* filename, int line, int errnum, ...); 24 | void fatal(int errnum, ...); 25 | void warning(int errnum, ...); 26 | void notice(int msg, char* str, ...); 27 | void todo(char*); 28 | void message(int errnum, ...); 29 | void logprint(char* s, ...); 30 | void logenter(void); 31 | void logexit(void); 32 | #define QSTR "\"%s\"" 33 | #define QCHAR "'%c'" 34 | 35 | enum _ERRORS { 36 | ERR_USERPREP, 37 | ERR_INVALIDCODE, 38 | ERR_MISPLACEDCODE, 39 | ERR_BRACENOTALLOWED, 40 | ERR_BRACECLOSENOTALLOWED, 41 | ERR_TOOFEWBRACKETS, 42 | ERR_CLOSEBRACKEXP, 43 | ERR_CLOSEBRACEEXP, 44 | ERR_INVCHARCODE, 45 | ERR_CHARENDEXP, 46 | ERR_SCRIPTNUMNOTSPEC, 47 | ERR_SCRIPTDEFINED, 48 | ERR_RESNUMOUTOFRANGE, 49 | ERR_INTEXP, 50 | ERR_PREPROCESSORID, 51 | ERR_ILLEGALINT, 52 | ERR_ILLEGALCHARACTER, 53 | ERR_UNTERM_STRING, 54 | ERR_EXPRESSIONTOOLONG, 55 | ERR_STRINGTOOLONG, 56 | ERR_STRINGEXP, 57 | ERR_UNDEFINE, 58 | ERR_NEEDENDIF, 59 | ERR_SEMICOLONEXP, 60 | ERR_ENUMBRACK, 61 | ERR_VAREXISTS, 62 | ERR_FUNCEXISTS, 63 | ERR_LABELEXISTS, 64 | ERR_BADLABEL, 65 | ERR_KERNELFUNCPROCEXP, 66 | ERR_KERNELFUNCPROCEXPBRACK, 67 | ERR_MAXPOINTERS, 68 | ERR_BRACKCNT, 69 | ERR_INTTOOLARGE, 70 | ERR_ARRAYTOOSMALL, 71 | ERR_ARRAYTOOLARGE, 72 | ERR_ARRAYENDEXP, 73 | ERR_VARPOINTASSIGN, 74 | ERR_ARRAYCOMMAEXP, 75 | ERR_ARRAYBRACSEXP, 76 | ERR_NOTARRAY, 77 | ERR_ARRAYENDBRACEXP, 78 | ERR_INTEGEROUTOFRANGE, 79 | ERR_VARMUSTBEPOINTER, 80 | ERR_ELEMENTSTOOLARGE, 81 | ERR_CHARORSTREXP, 82 | ERR_ILLEGALSTRCHAR, 83 | ERR_VARTYPECAST, 84 | ERR_FUNCDECNOTTERM, 85 | ERR_FUNCINFUNC, 86 | ERR_SUPERNAME, 87 | ERR_OBJINOBJ, 88 | ERR_OBJINFUNC, 89 | ERR_TEMPSTACK, 90 | ERR_LABELRESERVEDWORD, 91 | ERR_ASSIGNMENT, 92 | ERR_INVCOND, 93 | ERR_IFCONDCLOSEEXP, 94 | ERR_IFENCLOSEEXP, 95 | ERR_WHILEEXP, 96 | ERR_FUNCVOIDRET, 97 | ERR_CASECOLEXP, 98 | ERR_PROPORMETHFORSEND, 99 | ERR_SENDTOOLARGE, 100 | ERR_SWITCHINBRACE, 101 | ERR_SWITCHOUTBRACE, 102 | ERR_FUNCINBRACK, 103 | ERR_FUNCENDSOON, 104 | ERR_PARAMCOMMA, 105 | ERR_FUNCENDEXP, 106 | ERR_FUNCFRAMESIZE, 107 | ERR_ARRAYOUTOFRANGE, 108 | ERR_VARNOTPOINTER, 109 | ERR_SENDNOOBJECT, 110 | ERR_SENDNOTTERM, 111 | ERR_READONLYPROP, 112 | ERR_INVSEND, 113 | ERR_NOSENDOBJ, 114 | ERR_KERNELFUNCPUBLIC, 115 | ERR_VARPUBLIC, 116 | ERR_MAXDISPATCH, 117 | ERR_OBJFILEOVERFLOW, 118 | ERR_SAVINGUNIT, 119 | ERR_LOADINGUNIT, 120 | ERR_INVALIDUNIT, 121 | ERR_INVALIDUNITVER, 122 | ERR_TOOMANYPARAMS, 123 | ERR_ILLEGALBIN, 124 | ERR_UNIMPLEMENTED, 125 | ERR_INVALIDALIGN, 126 | ERR_VARNOBANK, 127 | ERR_LABELNOBANK, 128 | ERR_PREPROCESSSUB, 129 | ERR_UNKMAPPER, 130 | ERR_UNKMIRRORING, 131 | ERR_CODEINRAM, 132 | 133 | ERR_FUNCDECINBRACK, 134 | ERR_FUNCDECOUTBRACK, 135 | ERR_FUNCPARAMSNOTINLINE, 136 | 137 | ERR_INVOPOPCOMBO, 138 | ERR_UNTERMINATEDINT, 139 | 140 | ERR_NEWLINEEXPECTED, 141 | 142 | ERR_PARAMNOTIMMIDIATE, 143 | ERR_PARAMNOTINDIRECT, 144 | ERR_PARAMNOINDEXED, 145 | ERR_PARAMINVALIDINDEX, 146 | ERR_OPBRACECLOSEUNEXP, 147 | ERR_OPBRACECLOSEEXP, 148 | ERR_OPERANDMUSTBEZP, 149 | ERR_OPERANDEXP, 150 | 151 | ERR_NOTLABEL, 152 | ERR_BRANCHOUTOFRANGE, 153 | ERR_LABELNOTYETDEFINED, 154 | 155 | ERR_NOTINTEGER, 156 | ERR_NOTMEMBEROFSTRUCT, 157 | 158 | ERR_DECNOTINSTRUCT, 159 | ERR_STRINGNOTBYTE, 160 | ERR_VARDECLAREINRAM, 161 | ERR_DECLAREINRAM, 162 | 163 | ERR_OPENFILE_IN, 164 | ERR_OPENFILE_OUT, 165 | ERR_INCBINSIZE, 166 | ERR_INCBINSIZEBANK, 167 | 168 | ERR_UNKREQUEST, 169 | 170 | ERR_INTERRUPTNAMEEXP, 171 | ERR_CURBANKINTERRUPTSMALL, 172 | 173 | ERR_INTUNEXP, 174 | ERR_ACCESSINLINE, 175 | 176 | ERR_MACROTOOLARGE, 177 | 178 | ERR_IFOUTOFBANK, 179 | ERR_WHILEOUTOFBANK, 180 | ERR_FOREVEROUTOFBANK, 181 | 182 | ERR_INVALIDCOND, 183 | ERR_IFINBRACKEXP, 184 | 185 | ERR_NOTTYPECAST, 186 | ERR_NOTTYPECASTORVAR, 187 | ERR_VARCASTASSIGN, 188 | ERR_INVALIDARRAYINDEX, 189 | 190 | ERR_ONLYIFSELSE, 191 | 192 | ERR_FUNCNOTTERM, 193 | ERR_VARNOTTERM, 194 | 195 | ERR_ENUMCLASSDOT, 196 | ERR_ENUMCLASSMEMBER, 197 | 198 | ERR_PREPELSEUNEXP, 199 | 200 | ERR_SELFNESTEDDEF, 201 | ERR_SELFNESTEDSOURCE, 202 | 203 | ERR_ADDINGPATH, 204 | 205 | ERR_VARNOTARRAY, 206 | ERR_FUNCNEEDSPARAMS, 207 | ERR_FUNCNEEDSPARAM, 208 | 209 | ERR_BANKSIZEZERO, 210 | 211 | ERR_NORETURN_INLINE, 212 | 213 | ERR_SWITCHINBRACKEXP, 214 | ERR_SWITCHREG, 215 | ERR_SWITCHREGPOINT, 216 | ERR_SWITCHREGARG, 217 | ERR_CASECODEEXP, 218 | ERR_SWITCHEXPRESSION, 219 | ERR_UNTERMINATEDSWITCH, 220 | 221 | ERR_FIXOFFSNEAR, 222 | ERR_SUBFUNCTYPENONINT, 223 | ERR_SUBFUNCTYPEBAD, 224 | ERR_BANKSIZE, 225 | 226 | ERR_INTERRUPTTYPE, 227 | 228 | ERR_ARITHLABEL, 229 | 230 | ERR_STRUCTELEMENTBRACE, 231 | ERR_STRUCTELEMENTCOMMA, 232 | 233 | ERR_INLINESIZEOF, 234 | ERR_INLINEBANKOF, 235 | ERR_VARBANKOF, 236 | ERR_NOBANKOF, 237 | 238 | ERR_OPZPINDEXONLY, 239 | }; 240 | 241 | enum _FATALS { 242 | FTL_USERPREP, 243 | FTL_OUTOFMEMORY, 244 | FTL_COMPFAIL, 245 | FTL_OUTPUTSCRIPTOVERFLO, 246 | FTL_SAVINGRESOURCE, 247 | FTL_OPENFILE_IN, 248 | FTL_OPENFILE_OUT, 249 | FTL_TOOMANYBRACKETS, 250 | FTL_LABELMEMORY, 251 | FTL_CODENOTTERMINATED, 252 | FTL_NOACTIVEBANK, 253 | FTL_MAXBANKCOUNT, 254 | FTL_BANKOVERFLO, 255 | FTL_CURBANKINTERRUPTOVER, 256 | FTL_NOTROMBANK, 257 | FTL_NOTCHRBANK, 258 | FTL_VARNOTROMBANK, 259 | FTL_TOOMANYBRACES, 260 | FTL_OPENINGFILEWRITE, 261 | FTL_FUNCTIONERR, 262 | }; 263 | 264 | enum _WARNINGS { 265 | WRN_USERPREP, 266 | WRN_CHARCONV, 267 | WRN_WORDCONV, 268 | WRN_CODEINCHR, 269 | 270 | WRN_INTDIVBYZERO, 271 | WRN_ARRAYINDEXOUTOFBOUNDS, 272 | 273 | WRN_DEFALREADYDEF, 274 | WRN_REDEFNOTIDENTICAL, 275 | 276 | WRN_VARINTFUNC, 277 | WRN_CODEINRAM, 278 | }; 279 | 280 | enum _NOTICE { 281 | MSG_NONE, 282 | MSG_DEBUG, 283 | MSG_COMPSUCCESS, 284 | 285 | }; 286 | 287 | 288 | void bexit(int code); 289 | 290 | #endif 291 | -------------------------------------------------------------------------------- /typedefs.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #ifndef _typedefs_h_ 12 | #define _typedefs_h_ 13 | 14 | 15 | /* data types */ 16 | typedef unsigned char U8; 17 | typedef signed char S8; 18 | typedef unsigned short U16; 19 | typedef signed short S16; 20 | typedef unsigned long U32; 21 | typedef signed long S32; 22 | typedef unsigned short BOOL; 23 | 24 | #define TRUE 1 25 | #define FALSE 0 26 | 27 | 28 | #endif 29 | 30 | -------------------------------------------------------------------------------- /vars.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * NESHLA: The Nintendo Entertainment System High Level Assembler 3 | * Copyright (C) 2003,2004,2005 Brian Provinciano, http://www.bripro.com 4 | * 5 | * This program is free software. 6 | * You may use this code for anything you wish. 7 | * It comes with no warranty. 8 | ***************************************************************************/ 9 | 10 | 11 | #ifndef varsH 12 | #define varsH 13 | 14 | #include "output/banks.h" 15 | 16 | 17 | #define VARSIZE_NULL 0 18 | #define VARSIZE_BYTE 1 19 | #define VARSIZE_WORD 2 20 | 21 | #define VARFLAG_16BIT 0x0001 22 | #define VARFLAG_ROM 0x0002 23 | #define VARFLAG_TYPECAST 0x0004 24 | #define VARFLAG_DEFCASTED 0x0008 25 | 26 | #define VARFLAG_FIXED 0x0100 // defined with : xxxx 27 | #define VARFLAG_SHARED 0x0200 // shared between interrupts/functions 28 | #define VARFLAG_FUNCCALLED 0x2000 29 | #define VARFLAG_INTCALLED 0x4000 30 | 31 | enum { 32 | VARCAST_NULL, 33 | VARCAST_BYTE, 34 | VARCAST_CHAR, 35 | VARCAST_BOOL, 36 | VARCAST_WORD, 37 | VARCAST_POINTER, 38 | VARCAST_STRUCT, 39 | 40 | VARCAST_TOTAL 41 | }; 42 | 43 | typedef struct _VAR { 44 | struct _VAR* prev, *next, *parent, *childVars; 45 | U16 cast; 46 | U16 size, arraySize; 47 | U16 flags; 48 | S32 offset; 49 | BANK* bank; 50 | char* label; 51 | } VAR; 52 | 53 | typedef struct { 54 | char* label; 55 | int id; 56 | int size; 57 | } VARCAST; 58 | 59 | extern VAR* vars, *curVar, *typedefs; 60 | int IsVarCast(char* label, VAR** castvar); 61 | void FreeVars(VAR** pvar); 62 | VAR* AddVariable(char* label, U16 cast, VAR* castvar, U16 flags, S32 offset); 63 | 64 | BOOL CheckoutCurVar(void); 65 | void SetCurVar(VAR* var); 66 | VAR* ReleaseCurVar(void); 67 | 68 | VAR* FindVariable(VAR* var, char* label); 69 | VAR* FindFirstVariable(VAR* var); 70 | 71 | extern VARCAST varcasts[]; 72 | 73 | void SetVarOffsets(VAR* var, S32 offset, BOOL SCAN); 74 | VAR* CloneVar(VAR* var, VAR* parent, U16 flags); 75 | 76 | S32 VarSize(VAR* var); 77 | 78 | VAR* PonderVariable(VAR* var, S32* _offset); 79 | void CheckVariableCalls(void); 80 | 81 | #endif 82 | 83 | --------------------------------------------------------------------------------