diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..176a458f9 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto diff --git a/.travis.yml b/.travis.yml index 10ea789cf..c84eb0cc2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,13 +6,9 @@ install: script: - make bin USER_CFLAGS=-Werror - make lib QUIET=1 - - make -C test + - make -C test QUIET=1 - make -C src clean - make bin USER_CFLAGS=-Werror CROSS_COMPILE=i686-w64-mingw32- - make doc zip after_success: - make -f Makefile.travis -env: - global: - - secure: "h+hoQdEHGPLNwaqGKmSaM8NBRDLc2X+W05VsnNG2Feq/wPv/AiBjONNlzN7jRf6D6f3aoPXaQ2Lc3bYWdxGvFRCmwiofdxkJI9n5L8HPHLZ2lf37MQsXmGJzoTFOvjPLj73H6HlbI9Ux0El3zO6hvalxiXj6TfoZ41dbhNyvpYk=" - - secure: "A4hMEe5RRfUtYjFGbT7QAvT1Tyo434N+/TiuQeQ4q0L46c79LnXuGQzbFLOFZshZiplLkJr7lFg466CoI1bf2L0cQOew/LesMhE75v0HQ7tZnExWhdpAk0ri6nWixbjn/dmQ0+HxjzJ48A44DMMBYcvSIsO4vflvuJ8etfSg42k=" diff --git a/Makefile b/Makefile index 808689c82..206f853fc 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: all mostlyclean clean install zip avail unavail bin lib doc samples +.PHONY: all mostlyclean clean install zip avail unavail bin lib doc html info samples .SUFFIXES: @@ -14,7 +14,7 @@ avail unavail bin: lib: @$(MAKE) -C libsrc --no-print-directory $@ -doc: +doc html info: @$(MAKE) -C doc --no-print-directory $@ samples: diff --git a/asminc/atari5200.inc b/asminc/atari5200.inc index b67c9a8db..91fae4a9a 100644 --- a/asminc/atari5200.inc +++ b/asminc/atari5200.inc @@ -8,42 +8,42 @@ ; ATASCII CHARACTER DEFS ;------------------------------------------------------------------------- -ATEOL = $9B ;END-OF-LINE, used by CONIO +ATEOL = $9B ; END-OF-LINE, used by CONIO ;------------------------------------------------------------------------- ; Zero Page ;------------------------------------------------------------------------- -POKMSK = $00 ;Mask for Pokey IRQ enable -RTCLOK = $01 ;60 hz. clock +POKMSK = $00 ; Mask for Pokey IRQ enable +RTCLOK = $01 ; 60 hz. clock JUMP = $01 -CRITIC = $03 ;Critical section -ATRACT = $04 ;Attract Mode +CRITIC = $03 ; Critical section +ATRACT = $04 ; Attract Mode -SDLSTL = $05 ;DLISTL Shadow -SDLSTH = $06 ;DLISTH " -SDMCTL = $07 ;DMACTL " +SDLSTL = $05 ; DLISTL Shadow +SDLSTH = $06 ; DLISTH " +SDMCTL = $07 ; DMACTL " -PCOLR0 = $08 ;COLPM0 Shadow -PCOLR1 = $09 ;COLPM1 " -PCOLR2 = $0A ;COLPM2 " -PCOLR3 = $0B ;COLPM3 " +PCOLR0 = $08 ; COLPM0 Shadow +PCOLR1 = $09 ; COLPM1 " +PCOLR2 = $0A ; COLPM2 " +PCOLR3 = $0B ; COLPM3 " -COLOR0 = $0C ;COLPF0 Shadow -COLOR1 = $0D ;COLPF1 " -COLOR2 = $0E ;COLPF2 " -COLOR3 = $0F ;COLPF3 " -COLOR4 = $10 ;COLBK " +COLOR0 = $0C ; COLPF0 Shadow +COLOR1 = $0D ; COLPF1 " +COLOR2 = $0E ; COLPF2 " +COLOR3 = $0F ; COLPF3 " +COLOR4 = $10 ; COLBK " -PADDL0 = $11 ;POT0 Shadow -PADDL1 = $12 ;POT1 " -PADDL2 = $13 ;POT2 " -PADDL3 = $14 ;POT3 " -PADDL4 = $15 ;POT4 " -PADDL5 = $16 ;POT5 " -PADDL6 = $17 ;POT6 " -PADDL7 = $18 ;POT7 " +PADDL0 = $11 ; POT0 Shadow +PADDL1 = $12 ; POT1 " +PADDL2 = $13 ; POT2 " +PADDL3 = $14 ; POT3 " +PADDL4 = $15 ; POT4 " +PADDL5 = $16 ; POT5 " +PADDL6 = $17 ; POT6 " +PADDL7 = $18 ; POT7 " ; cc65 runtime zero page variables @@ -57,26 +57,26 @@ SAVMSC = $1B ; pointer to screen memory (conio) ;Interrupt Vectors -VIMIRQ = $0200 ;Immediate IRQ - ;Preset $FC03 (SYSIRQ) -VVBLKI = $0202 ;Vblank immediate - ;Preset $FCB8 (SYSVBL) -VVBLKD = $0204 ;Vblank deferred - ;Preset $FCB2 (XITVBL) -VDSLST = $0206 ;Display List - ;Preset $FEA1 (OSDLI) -VKYBDI = $0208 ;Keyboard immediate - ;Preset $FD02 (SYSKBD) -VKYBDF = $020A ;Deferred Keyboard - ;Preset $FCB2 (XITVBL) -VTRIGR = $020C ;Soft Trigger -VBRKOP = $020E ;BRK Opcode -VSERIN = $0210 ;Serial in Ready -VSEROR = $0212 ;Serial Out Ready -VSEROC = $0214 ;Serial Output complete -VTIMR1 = $0216 ;Pokey Timer 1 -VTIMR2 = $0218 ;Pokey Timer 2 -VTIMR4 = $021A ;Pokey Timer 4 +VIMIRQ = $0200 ; Immediate IRQ + ; Preset $FC03 (SYSIRQ) +VVBLKI = $0202 ; Vblank immediate + ; Preset $FCB8 (SYSVBL) +VVBLKD = $0204 ; Vblank deferred + ; Preset $FCB2 (XITVBL) +VDSLST = $0206 ; Display List + ; Preset $FEA1 (OSDLI) +VKYBDI = $0208 ; Keyboard immediate + ; Preset $FD02 (SYSKBD) +VKYBDF = $020A ; Deferred Keyboard + ; Preset $FCB2 (XITVBL) +VTRIGR = $020C ; Soft Trigger +VBRKOP = $020E ; BRK Opcode +VSERIN = $0210 ; Serial in Ready +VSEROR = $0212 ; Serial Out Ready +VSEROC = $0214 ; Serial Output complete +VTIMR1 = $0216 ; Pokey Timer 1 +VTIMR2 = $0218 ; Pokey Timer 2 +VTIMR4 = $021A ; Pokey Timer 4 @@ -84,21 +84,21 @@ VTIMR4 = $021A ;Pokey Timer 4 ; CTIA/GTIA Address Equates ;------------------------------------------------------------------------- -GTIA = $C000 ;CTIA/GTIA area +GTIA = $C000 ; CTIA/GTIA area .include "atari_gtia.inc" ;------------------------------------------------------------------------- ; ANTIC Address Equates ;------------------------------------------------------------------------- -ANTIC = $D400 ;ANTIC area +ANTIC = $D400 ; ANTIC area .include "atari_antic.inc" ;------------------------------------------------------------------------- ; POKEY Address Equates ;------------------------------------------------------------------------- -POKEY = $E800 ;POKEY area +POKEY = $E800 ; POKEY area .include "atari_pokey.inc" @@ -106,11 +106,10 @@ POKEY = $E800 ;POKEY area ; Cartridge Parameters ;------------------------------------------------------------------------- -CARTNM = $BFE8 ;Cartridge Name Area -COPYD = $BFFC ;Copyright Decade in Cart -COPYR = $BFFD ;Copyright Year in Cart +CARTNM = $BFE8 ; Cartridge Name Area +COPYD = $BFFC ; Copyright Decade in Cart +COPYR = $BFFD ; Copyright Year in Cart ; $FF=Diagnostic Cart -GOCART = $BFFE ;Cartridge Start Vector +GOCART = $BFFE ; Cartridge Start Vector - -CHRORG = $F800 ;Character Generator Base +CHRORG = $F800 ; Character Generator Base diff --git a/asminc/c128.inc b/asminc/c128.inc index e6c89b07b..9e9acc5a8 100644 --- a/asminc/c128.inc +++ b/asminc/c128.inc @@ -38,6 +38,10 @@ INIT_STATUS := $A04 ; Flags: Reset/Restore initiation status FKEY_LEN := $1000 ; Function key lengths FKEY_TEXT := $100A ; Function key texts +KBDREPEAT := $28a +KBDREPEATRATE := $28b +KBDREPEATDELAY := $28c + ; --------------------------------------------------------------------------- ; Kernal routines diff --git a/asminc/c64.inc b/asminc/c64.inc index ababb1ea0..00b66a64f 100644 --- a/asminc/c64.inc +++ b/asminc/c64.inc @@ -33,6 +33,9 @@ CHARCOLOR := $286 CURS_COLOR := $287 ; Color under the cursor PALFLAG := $2A6 ; $01 = PAL, $00 = NTSC +KBDREPEAT := $28a +KBDREPEATRATE := $28b +KBDREPEATDELAY := $28c ; --------------------------------------------------------------------------- ; Kernal routines diff --git a/asminc/creativision.inc b/asminc/creativision.inc index 59b26101b..49d55a342 100644 --- a/asminc/creativision.inc +++ b/asminc/creativision.inc @@ -10,10 +10,10 @@ CURSOR_X = $3C CURSOR_Y = $3D ;** VDP -VDP_CONTROL_W = $3001 -VDP_DATA_W = $3000 -VDP_STATUS_R = $2001 VDP_DATA_R = $2000 +VDP_STATUS_R = $2001 +VDP_DATA_W = $3000 +VDP_CONTROL_W = $3001 ;** PIA PIA0_DATA = $1000 @@ -36,7 +36,26 @@ ZP_JOY1_DIR = $13 ZP_JOY0_BUTTONS = $16 ZP_JOY1_BUTTONS = $17 +;** Joystick direction values (ZP_JOY0_DIR/ZP_JOY1_DIR) +JOY_N = $49 +JOY_NNE = $48 +JOY_NE = $47 +JOY_ENE = $46 +JOY_E = $45 +JOY_ESE = $44 +JOY_SE = $43 +JOY_SSE = $42 +JOY_S = $41 +JOY_SSW = $40 +JOY_SW = $4F +JOY_WSW = $4E +JOY_W = $4D +JOY_WNW = $4C +JOY_NW = $4B +JOY_NNW = $4A + ;** BIOS BIOS_IRQ1_ADDR = $FF3F BIOS_IRQ2_ADDR = $FF52 BIOS_NMI_RESET_ADDR = $F808 +BIOS_WRITE_VDP_REG = $FE1F diff --git a/asminc/joy-kernel.inc b/asminc/joy-kernel.inc index 4fe5572cf..ba969da1d 100644 --- a/asminc/joy-kernel.inc +++ b/asminc/joy-kernel.inc @@ -43,7 +43,6 @@ ID .byte 3 ; $6A, $6F, $79 ("joy") VERSION .byte 1 ; Interface version LIBREF .addr ; Library reference - MASKS .byte 8 ; Joystick state mask array JUMPTAB .struct INSTALL .addr ; INSTALL routine UNINSTALL .addr ; UNINSTALL routine diff --git a/asminc/opcodes.inc b/asminc/opcodes.inc index 7c52871d2..96cdefb65 100644 --- a/asminc/opcodes.inc +++ b/asminc/opcodes.inc @@ -1,509 +1,509 @@ -; opcodes.inc -; ca65 6502 - opcode definitions, mainly for self modifying code -; -; Christian Krüger, latest change: 18-Sep-2010 -; -; This software is provided 'as-is', without any expressed or implied -; warranty. In no event will the authors be held liable for any damages -; arising from the use of this software. -; -; Permission is granted to anyone to use this software for any purpose, -; including commercial applications, and to alter it and redistribute it -; freely, subject to the following restrictions: -; -; 1. The origin of this software must not be misrepresented; you must not -; claim that you wrote the original software. If you use this software -; in a product, an acknowledgment in the product documentation would be -; appreciated but is not required. -; 2. Altered source versions must be plainly marked as such, and must not -; be misrepresented as being the original software. -; 3. This notice may not be removed or altered from any source -; distribution. -; - -; Opcode-Table -; ------------ -; Post fix explanation: -; imm = #$00 -; zp = $00 -; zpx = $00,X -; zpy = $00,Y -; izp = ($00) -; izx = ($00,X) -; izy = ($00),Y -; abs = $0000 -; abx = $0000,X -; aby = $0000,Y -; ind = ($0000) -; iax = ($0000,X) -; rel = $0000 (PC-relative) (supressed here) - -.macpack cpu - -OPC_BRK = $00 -OPC_ORA_izx = $01 -OPC_ORA_zp = $05 -OPC_ASL_zp = $06 -OPC_PHP = $08 -OPC_ORA_imm = $09 -OPC_ASL = $0A -OPC_ORA_abs = $0D -OPC_ASL_abs = $0E - -OPC_BPL = $10 -OPC_ORA_izy = $11 -OPC_ORA_zpx = $15 -OPC_ASL_zpx = $16 -OPC_CLC = $18 -OPC_ORA_aby = $19 -OPC_ORA_abx = $1D -OPC_ASL_abx = $1E - -OPC_JSR_abs = $20 -OPC_AND_izx = $21 -OPC_BIT_zp = $24 -OPC_AND_zp = $25 -OPC_ROL_zp = $26 -OPC_PLP = $28 -OPC_AND_imm = $29 -OPC_ROL = $2A -OPC_BIT_abs = $2C -OPC_AND_abs = $2D -OPC_ROL_abs = $2E - -OPC_BMI = $30 -OPC_AND_izy = $31 -OPC_AND_zpx = $35 -OPC_ROL_zpx = $36 -OPC_SEC = $38 -OPC_AND_aby = $39 -OPC_AND_abx = $3D -OPC_ROL_abx = $3E - - -OPC_RTI = $40 -OPC_EOR_izx = $41 -OPC_EOR_zp = $45 -OPC_LSR_zp = $46 -OPC_PHA = $48 -OPC_EOR_imm = $49 -OPC_LSR = $4A -OPC_JMP_abs = $4C -OPC_EOR_abs = $4D -OPC_LSR_abs = $4E - -OPC_BVC = $50 -OPC_EOR_izy = $51 -OPC_EOR_zpx = $55 -OPC_LSR_zpx = $56 -OPC_CLI = $58 -OPC_EOR_aby = $59 -OPC_EOR_abx = $5D -OPC_LSR_abx = $5E - -OPC_RTS = $60 -OPC_ADC_izx = $61 -OPC_ADC_zp = $65 -OPC_ROR_zp = $66 -OPC_PLA = $68 -OPC_ADC_imm = $69 -OPC_ROR = $6A -OPC_JMP_ind = $6C -OPC_ADC_abs = $6D -OPC_ROR_abs = $6E - -OPC_BVS = $70 -OPC_ADC_izy = $71 -OPC_ADC_zpx = $75 -OPC_ROR_zpx = $76 -OPC_SEI = $78 -OPC_ADC_aby = $79 -OPC_ADC_abx = $7D -OPC_ROR_abx = $7E - -OPC_STA_izx = $81 -OPC_STY_zp = $84 -OPC_STA_zp = $85 -OPC_STX_zp = $86 -OPC_DEY = $88 -OPC_TXA = $8A -OPC_STY_abs = $8C -OPC_STA_abs = $8D -OPC_STX_abs = $8E - -OPC_BCC = $90 -OPC_STA_izy = $91 -OPC_STY_zpx = $94 -OPC_STA_zpx = $95 -OPC_STX_zpy = $96 -OPC_TYA = $98 -OPC_STA_aby = $99 -OPC_TXS = $9A -OPC_STA_abx = $9D - -OPC_LDY_imm = $A0 -OPC_LDA_izx = $A1 -OPC_LDX_imm = $A2 -OPC_LDY_zp = $A4 -OPC_LDA_zp = $A5 -OPC_LDX_zp = $A6 -OPC_TAY = $A8 -OPC_LDA_imm = $A9 -OPC_TAX = $AA -OPC_LDY_abs = $AC -OPC_LDA_abs = $AD -OPC_LDX_abs = $AE - -OPC_BCS = $B0 -OPC_LDA_izy = $B1 -OPC_LDY_zpx = $B4 -OPC_LDA_zpx = $B5 -OPC_LDX_zpy = $B6 -OPC_CLV = $B8 -OPC_LDA_aby = $B9 -OPC_TSX = $BA -OPC_LDY_abx = $BC -OPC_LDA_abx = $BD -OPC_LDX_aby = $BE - -OPC_CPY_imm = $C0 -OPC_CMP_izx = $C1 -OPC_CPY_zp = $C4 -OPC_CMP_zp = $C5 -OPC_DEC_zp = $C6 -OPC_INY = $C8 -OPC_CMP_imm = $C9 -OPC_DEX = $CA -OPC_CPY_abs = $CC -OPC_CMP_abs = $CD -OPC_DEC_abs = $CE - -OPC_BNE = $D0 -OPC_CMP_izy = $D1 -OPC_CMP_zpx = $D5 -OPC_DEC_zpx = $D6 -OPC_CLD = $D8 -OPC_CMP_aby = $D9 -OPC_CMP_abx = $DD -OPC_DEC_abx = $DE - -OPC_CPX_imm = $E0 -OPC_SBC_izx = $E1 -OPC_CPX_zp = $E4 -OPC_SBC_zp = $E5 -OPC_INC_zp = $E6 -OPC_INX = $E8 -OPC_SBC_imm = $E9 -OPC_NOP = $EA -OPC_CPX_abs = $EC -OPC_SBC_abs = $ED -OPC_INC_abs = $EE - - -OPC_BEQ = $F0 -OPC_SBC_izy = $F1 -OPC_SBC_zpx = $F5 -OPC_INC_zpx = $F6 -OPC_SED = $F8 -OPC_SBC_aby = $F9 -OPC_SBC_abx = $FD -OPC_INC_abx = $FE - - -.if (.cpu .bitand ::CPU_ISET_65SC02) - -; OPC_NOP = $02 ; doublet -; OPC_NOP = $03 ; doublet -OPC_TSB_zp = $04 -; OPC_NOP = $0B ; doublet -OPC_TSB_abs = $0C - -OPC_ORA_izp = $12 -; OPC_NOP = $13 ; doublet -OPC_TRB_zp = $14 -OPC_INC = $1A -; OPC_NOP = $1B ; doublet -OPC_TRB_abs = $1C - -; OPC_NOP = $22 ; doublet -; OPC_NOP = $23 ; doublet -; OPC_NOP = $2B ; doublet - -OPC_AND_izp = $32 -; OPC_NOP = $33 ; doublet -OPC_BIT_zpx = $34 -OPC_DEC = $3A -; OPC_NOP = $3B ; doublet -OPC_BIT_abx = $3C - -; OPC_NOP = $42 ; doublet -; OPC_NOP = $43 ; doublet -; OPC_NOP = $44 ; doublet -; OPC_NOP = $4B ; doublet - -OPC_EOR_izp = $52 -; OPC_NOP = $53 ; doublet -; OPC_NOP = $54 ; doublet -; OPC_NOP = $5A ; doublet -; OPC_NOP = $5B ; doublet -OPC_EOR_abx = $5C - -; OPC_NOP = $62 ; doublet -; OPC_NOP = $63 ; doublet -OPC_STZ_zp = $64 -; OPC_NOP = $6B ; doublet - -OPC_ADC_izp = $72 -; OPC_NOP = $73 ; doublet -OPC_STZ_zpx = $74 -OPC_PLY = $7A -; OPC_NOP = $7B ; doublet -OPC_JMP_iax = $7C - -OPC_BRA = $80 -; OPC_NOP = $82 ; doublet -; OPC_NOP = $83 ; doublet -OPC_BIT_imm = $89 -; OPC_NOP = $8B ; doublet - -OPC_STA_izp = $92 -; OPC_NOP = $93 ; doublet -; OPC_NOP = $9B ; doublet -OPC_STZ_abs = $9C -OPC_STZ_abx = $9E - -; OPC_NOP = $A3 ; doublet -; OPC_NOP = $AB ; doublet - -OPC_LDA_izp = $B2 -; OPC_NOP = $B3 ; doublet -; OPC_NOP = $BB ; doublet - -; OPC_NOP = $C2 ; doublet -; OPC_NOP = $C3 ; doublet -; OPC_NOP = $CB ; doublet - -OPC_CMP_izp = $D2 -; OPC_NOP = $D3 ; doublet -; OPC_NOP = $D4 ; doublet -OPC_PHX = $DA -; OPC_NOP = $DB ; doublet -; OPC_NOP = $DC ; doublet - -; OPC_NOP = $E2 ; doublet -; OPC_NOP = $E3 ; doublet -; OPC_NOP = $EB ; doublet - -OPC_SBC_izp = $F2 -; OPC_NOP = $F3 ; doublet -; OPC_NOP = $F4 ; doublet -OPC_PLX = $FA -; OPC_NOP = $FB ; doublet -; OPC_NOP = $FC ; doublet - - -.if (.cpu .bitand ::CPU_ISET_65C02) - -; bit instructions for 65C02 - -OPC_RMB0 = $07 -OPC_RMB1 = $17 -OPC_RMB2 = $27 -OPC_RMB3 = $37 -OPC_RMB4 = $47 -OPC_RMB5 = $57 -OPC_RMB6 = $67 -OPC_RMB7 = $77 - -OPC_SMB0 = $87 -OPC_SMB1 = $97 -OPC_SMB2 = $A7 -OPC_SMB3 = $B7 -OPC_SMB4 = $C7 -OPC_SMB5 = $D7 -OPC_SMB6 = $E7 -OPC_SMB7 = $F7 - -OPC_BBR0 = $0F -OPC_BBR1 = $1F -OPC_BBR2 = $2F -OPC_BBR3 = $3F -OPC_BBR4 = $4F -OPC_BBR5 = $5F -OPC_BBR6 = $6F -OPC_BBR7 = $7F - -OPC_BBS0 = $8F -OPC_BBS1 = $9F -OPC_BBS2 = $AF -OPC_BBS3 = $BF -OPC_BBS4 = $CF -OPC_BBS5 = $DF -OPC_BBS6 = $EF -OPC_BBS7 = $FF - -.else - -; no bit instructions for 65SC02 - -; OPC_NOP = $07 ; doublet -; OPC_NOP = $17 ; doublet -; OPC_NOP = $27 ; doublet -; OPC_NOP = $37 ; doublet -; OPC_NOP = $47 ; doublet -; OPC_NOP = $57 ; doublet -; OPC_NOP = $67 ; doublet -; OPC_NOP = $77 ; doublet -; OPC_NOP = $87 ; doublet -; OPC_NOP = $97 ; doublet -; OPC_NOP = $A7 ; doublet -; OPC_NOP = $B7 ; doublet -; OPC_NOP = $C7 ; doublet -; OPC_NOP = $D7 ; doublet -; OPC_NOP = $E7 ; doublet -; OPC_NOP = $F7 ; doublet -; OPC_NOP = $0F ; doublet -; OPC_NOP = $1F ; doublet -; OPC_NOP = $2F ; doublet -; OPC_NOP = $3F ; doublet -; OPC_NOP = $4F ; doublet -; OPC_NOP = $5F ; doublet -; OPC_NOP = $6F ; doublet -; OPC_NOP = $7F ; doublet -; OPC_NOP = $8F ; doublet -; OPC_NOP = $9F ; doublet -; OPC_NOP = $AF ; doublet -; OPC_NOP = $BF ; doublet -; OPC_NOP = $CF ; doublet -; OPC_NOP = $DF ; doublet -; OPC_NOP = $EF ; doublet -; OPC_NOP = $FF ; doublet - -.endif - -.elseif (.cpu .bitand ::CPU_ISET_6502X) - -; stable, undocumented opcodes - -; OPC_KIL = $02 ; unstable -OPC_SLO_izx = $03 -OPC_NOP_zp = $04 -OPC_SLO_zp = $07 -OPC_ANC_imm = $0B -OPC_NOP_abs = $0C -OPC_SLO_abs = $0F - -; OPC_KIL = $12 ; unstable -OPC_SLO_izy = $13 -OPC_NOP_zpx = $14 -OPC_SLO_zpx = $17 -;OPC_NOP = $1A -OPC_SLO_aby = $1B -OPC_NOP_abx = $1C -OPC_SLO_abx = $1F - -; OPC_KIL = $22 ; unstable -OPC_RLA_izx = $23 -OPC_RLA_zp = $27 -OPC_ANC_imm = $2B -OPC_RLA_abs = $2F - -; OPC_KIL = $32 ; unstable -OPC_RLA_izy = $33 -OPC_NOP_zpx = $34 -OPC_RLA_zpx = $37 -; OPC_NOP = $3A ; doublet -OPC_RLA_aby = $3B -OPC_NOP_abx = $3C -OPC_RLA_abx = $3F - -; OPC_KIL = $42 ; unstable -OPC_SRE_izx = $43 -OPC_NOP_zp = $44 -OPC_SRE_zp = $47 -OPC_ALR_imm = $4B -OPC_SRE_abs = $4F - -; OPC_KIL = $52 ; unstable -OPC_SRE_izy = $53 -OPC_NOP_zpx = $54 -OPC_SRE_zpx = $57 -; OPC_NOP = $5A ; doublet -OPC_SRE_aby = $5B -OPC_NOP_abx = $5C -OPC_SRE_abx = $5F - -; OPC_KIL = $62 -OPC_RRA_izx = $63 -OPC_NOP_zp = $64 -OPC_RRA_zp = $67 -OPC_ARR_imm = $6B -OPC_RRA_abs = $6F - -; OPC_KIL = $72 -OPC_RRA_izy = $73 -OPC_NOP_zpx = $74 -OPC_RRA_zpx = $77 -; OPC_NOP = $7A ; doublet -OPC_RRA_aby = $7B -OPC_NOP_abx = $7C -OPC_RRA_abx = $7F - -OPC_NOP_imm = $80 -; OPC_NOP_imm = $82 ; doublet -OPC_SAX_izx = $83 -OPC_SAX_zp = $87 -; OPC_NOP_imm = $89 ; doublet -; OPC_XAA = $8B ; unstable -OPC_SAX_abs = $8F - -; OPC_KIL = $92 ; unstable -; OPC_AHX_izy = $93 ; unstable -OPC_SAX_zpy = $97 -; OPC_TAS_aby = $9B ; unstable -; OPC_SHY_abx = $9C ; unstable -; OPC_SHX_aby = $9E ; unstable -; OPC_AHX_aby = $9F ; unstable - -OPC_LAX_izx = $A3 -OPC_LAX_zp = $A7 -; OPC_LAX_imm = $AB ; unstable -OPC_LAX_abs = $AF - -; OPC_KIL = $B2 ; unstable -OPC_LAX_izy = $B3 -OPC_LAX_zpy = $B7 -OPC_LAS_aby = $BB -OPC_LAX_aby = $BF - -; OPC_NOP_imm = $C2 ; doublet -OPC_DCP_izx = $C3 -OPC_DCP_zp = $C7 -OPC_AXS_imm = $CB -OPC_DCP_abs = $CF - -; OPC_KIL = $D2 ; unstable -OPC_DCP_izy = $D3 -OPC_NOP_zpx = $D4 -OPC_DCP_zpx = $D7 -OPC_NOP_DA = $DA -OPC_DCP_aby = $DB -OPC_NOP_abx = $DC -OPC_DCP_abx = $DF - -; OPC_NOP_imm = $E2 ; doublet -OPC_ISC_izx = $E3 -OPC_ISC_zp = $E7 -; OPC_SBC_imm = $EB ; doublet -OPC_ISC_abs = $EF - -; OPC_KIL = $F2 ; unstable -OPC_ISC_izy = $F3 -OPC_NOP_zpx = $F4 -OPC_ISC_zpx = $F7 -OPC_NOP_FA = $FA -OPC_ISC_aby = $FB -OPC_NOP_abx = $FC -OPC_ISC_abx = $FF - -.endif +; opcodes.inc +; ca65 6502 - opcode definitions, mainly for self modifying code +; +; Christian Krüger, latest change: 18-Sep-2010 +; +; This software is provided 'as-is', without any expressed or implied +; warranty. In no event will the authors be held liable for any damages +; arising from the use of this software. +; +; Permission is granted to anyone to use this software for any purpose, +; including commercial applications, and to alter it and redistribute it +; freely, subject to the following restrictions: +; +; 1. The origin of this software must not be misrepresented; you must not +; claim that you wrote the original software. If you use this software +; in a product, an acknowledgment in the product documentation would be +; appreciated but is not required. +; 2. Altered source versions must be plainly marked as such, and must not +; be misrepresented as being the original software. +; 3. This notice may not be removed or altered from any source +; distribution. +; + +; Opcode-Table +; ------------ +; Post fix explanation: +; imm = #$00 +; zp = $00 +; zpx = $00,X +; zpy = $00,Y +; izp = ($00) +; izx = ($00,X) +; izy = ($00),Y +; abs = $0000 +; abx = $0000,X +; aby = $0000,Y +; ind = ($0000) +; iax = ($0000,X) +; rel = $0000 (PC-relative) (supressed here) + +.macpack cpu + +OPC_BRK = $00 +OPC_ORA_izx = $01 +OPC_ORA_zp = $05 +OPC_ASL_zp = $06 +OPC_PHP = $08 +OPC_ORA_imm = $09 +OPC_ASL = $0A +OPC_ORA_abs = $0D +OPC_ASL_abs = $0E + +OPC_BPL = $10 +OPC_ORA_izy = $11 +OPC_ORA_zpx = $15 +OPC_ASL_zpx = $16 +OPC_CLC = $18 +OPC_ORA_aby = $19 +OPC_ORA_abx = $1D +OPC_ASL_abx = $1E + +OPC_JSR_abs = $20 +OPC_AND_izx = $21 +OPC_BIT_zp = $24 +OPC_AND_zp = $25 +OPC_ROL_zp = $26 +OPC_PLP = $28 +OPC_AND_imm = $29 +OPC_ROL = $2A +OPC_BIT_abs = $2C +OPC_AND_abs = $2D +OPC_ROL_abs = $2E + +OPC_BMI = $30 +OPC_AND_izy = $31 +OPC_AND_zpx = $35 +OPC_ROL_zpx = $36 +OPC_SEC = $38 +OPC_AND_aby = $39 +OPC_AND_abx = $3D +OPC_ROL_abx = $3E + + +OPC_RTI = $40 +OPC_EOR_izx = $41 +OPC_EOR_zp = $45 +OPC_LSR_zp = $46 +OPC_PHA = $48 +OPC_EOR_imm = $49 +OPC_LSR = $4A +OPC_JMP_abs = $4C +OPC_EOR_abs = $4D +OPC_LSR_abs = $4E + +OPC_BVC = $50 +OPC_EOR_izy = $51 +OPC_EOR_zpx = $55 +OPC_LSR_zpx = $56 +OPC_CLI = $58 +OPC_EOR_aby = $59 +OPC_EOR_abx = $5D +OPC_LSR_abx = $5E + +OPC_RTS = $60 +OPC_ADC_izx = $61 +OPC_ADC_zp = $65 +OPC_ROR_zp = $66 +OPC_PLA = $68 +OPC_ADC_imm = $69 +OPC_ROR = $6A +OPC_JMP_ind = $6C +OPC_ADC_abs = $6D +OPC_ROR_abs = $6E + +OPC_BVS = $70 +OPC_ADC_izy = $71 +OPC_ADC_zpx = $75 +OPC_ROR_zpx = $76 +OPC_SEI = $78 +OPC_ADC_aby = $79 +OPC_ADC_abx = $7D +OPC_ROR_abx = $7E + +OPC_STA_izx = $81 +OPC_STY_zp = $84 +OPC_STA_zp = $85 +OPC_STX_zp = $86 +OPC_DEY = $88 +OPC_TXA = $8A +OPC_STY_abs = $8C +OPC_STA_abs = $8D +OPC_STX_abs = $8E + +OPC_BCC = $90 +OPC_STA_izy = $91 +OPC_STY_zpx = $94 +OPC_STA_zpx = $95 +OPC_STX_zpy = $96 +OPC_TYA = $98 +OPC_STA_aby = $99 +OPC_TXS = $9A +OPC_STA_abx = $9D + +OPC_LDY_imm = $A0 +OPC_LDA_izx = $A1 +OPC_LDX_imm = $A2 +OPC_LDY_zp = $A4 +OPC_LDA_zp = $A5 +OPC_LDX_zp = $A6 +OPC_TAY = $A8 +OPC_LDA_imm = $A9 +OPC_TAX = $AA +OPC_LDY_abs = $AC +OPC_LDA_abs = $AD +OPC_LDX_abs = $AE + +OPC_BCS = $B0 +OPC_LDA_izy = $B1 +OPC_LDY_zpx = $B4 +OPC_LDA_zpx = $B5 +OPC_LDX_zpy = $B6 +OPC_CLV = $B8 +OPC_LDA_aby = $B9 +OPC_TSX = $BA +OPC_LDY_abx = $BC +OPC_LDA_abx = $BD +OPC_LDX_aby = $BE + +OPC_CPY_imm = $C0 +OPC_CMP_izx = $C1 +OPC_CPY_zp = $C4 +OPC_CMP_zp = $C5 +OPC_DEC_zp = $C6 +OPC_INY = $C8 +OPC_CMP_imm = $C9 +OPC_DEX = $CA +OPC_CPY_abs = $CC +OPC_CMP_abs = $CD +OPC_DEC_abs = $CE + +OPC_BNE = $D0 +OPC_CMP_izy = $D1 +OPC_CMP_zpx = $D5 +OPC_DEC_zpx = $D6 +OPC_CLD = $D8 +OPC_CMP_aby = $D9 +OPC_CMP_abx = $DD +OPC_DEC_abx = $DE + +OPC_CPX_imm = $E0 +OPC_SBC_izx = $E1 +OPC_CPX_zp = $E4 +OPC_SBC_zp = $E5 +OPC_INC_zp = $E6 +OPC_INX = $E8 +OPC_SBC_imm = $E9 +OPC_NOP = $EA +OPC_CPX_abs = $EC +OPC_SBC_abs = $ED +OPC_INC_abs = $EE + + +OPC_BEQ = $F0 +OPC_SBC_izy = $F1 +OPC_SBC_zpx = $F5 +OPC_INC_zpx = $F6 +OPC_SED = $F8 +OPC_SBC_aby = $F9 +OPC_SBC_abx = $FD +OPC_INC_abx = $FE + + +.if (.cpu .bitand ::CPU_ISET_65SC02) + +; OPC_NOP = $02 ; doublet +; OPC_NOP = $03 ; doublet +OPC_TSB_zp = $04 +; OPC_NOP = $0B ; doublet +OPC_TSB_abs = $0C + +OPC_ORA_izp = $12 +; OPC_NOP = $13 ; doublet +OPC_TRB_zp = $14 +OPC_INC = $1A +; OPC_NOP = $1B ; doublet +OPC_TRB_abs = $1C + +; OPC_NOP = $22 ; doublet +; OPC_NOP = $23 ; doublet +; OPC_NOP = $2B ; doublet + +OPC_AND_izp = $32 +; OPC_NOP = $33 ; doublet +OPC_BIT_zpx = $34 +OPC_DEC = $3A +; OPC_NOP = $3B ; doublet +OPC_BIT_abx = $3C + +; OPC_NOP = $42 ; doublet +; OPC_NOP = $43 ; doublet +; OPC_NOP = $44 ; doublet +; OPC_NOP = $4B ; doublet + +OPC_EOR_izp = $52 +; OPC_NOP = $53 ; doublet +; OPC_NOP = $54 ; doublet +; OPC_NOP = $5A ; doublet +; OPC_NOP = $5B ; doublet +OPC_EOR_abx = $5C + +; OPC_NOP = $62 ; doublet +; OPC_NOP = $63 ; doublet +OPC_STZ_zp = $64 +; OPC_NOP = $6B ; doublet + +OPC_ADC_izp = $72 +; OPC_NOP = $73 ; doublet +OPC_STZ_zpx = $74 +OPC_PLY = $7A +; OPC_NOP = $7B ; doublet +OPC_JMP_iax = $7C + +OPC_BRA = $80 +; OPC_NOP = $82 ; doublet +; OPC_NOP = $83 ; doublet +OPC_BIT_imm = $89 +; OPC_NOP = $8B ; doublet + +OPC_STA_izp = $92 +; OPC_NOP = $93 ; doublet +; OPC_NOP = $9B ; doublet +OPC_STZ_abs = $9C +OPC_STZ_abx = $9E + +; OPC_NOP = $A3 ; doublet +; OPC_NOP = $AB ; doublet + +OPC_LDA_izp = $B2 +; OPC_NOP = $B3 ; doublet +; OPC_NOP = $BB ; doublet + +; OPC_NOP = $C2 ; doublet +; OPC_NOP = $C3 ; doublet +; OPC_NOP = $CB ; doublet + +OPC_CMP_izp = $D2 +; OPC_NOP = $D3 ; doublet +; OPC_NOP = $D4 ; doublet +OPC_PHX = $DA +; OPC_NOP = $DB ; doublet +; OPC_NOP = $DC ; doublet + +; OPC_NOP = $E2 ; doublet +; OPC_NOP = $E3 ; doublet +; OPC_NOP = $EB ; doublet + +OPC_SBC_izp = $F2 +; OPC_NOP = $F3 ; doublet +; OPC_NOP = $F4 ; doublet +OPC_PLX = $FA +; OPC_NOP = $FB ; doublet +; OPC_NOP = $FC ; doublet + + +.if (.cpu .bitand ::CPU_ISET_65C02) + +; bit instructions for 65C02 + +OPC_RMB0 = $07 +OPC_RMB1 = $17 +OPC_RMB2 = $27 +OPC_RMB3 = $37 +OPC_RMB4 = $47 +OPC_RMB5 = $57 +OPC_RMB6 = $67 +OPC_RMB7 = $77 + +OPC_SMB0 = $87 +OPC_SMB1 = $97 +OPC_SMB2 = $A7 +OPC_SMB3 = $B7 +OPC_SMB4 = $C7 +OPC_SMB5 = $D7 +OPC_SMB6 = $E7 +OPC_SMB7 = $F7 + +OPC_BBR0 = $0F +OPC_BBR1 = $1F +OPC_BBR2 = $2F +OPC_BBR3 = $3F +OPC_BBR4 = $4F +OPC_BBR5 = $5F +OPC_BBR6 = $6F +OPC_BBR7 = $7F + +OPC_BBS0 = $8F +OPC_BBS1 = $9F +OPC_BBS2 = $AF +OPC_BBS3 = $BF +OPC_BBS4 = $CF +OPC_BBS5 = $DF +OPC_BBS6 = $EF +OPC_BBS7 = $FF + +.else + +; no bit instructions for 65SC02 + +; OPC_NOP = $07 ; doublet +; OPC_NOP = $17 ; doublet +; OPC_NOP = $27 ; doublet +; OPC_NOP = $37 ; doublet +; OPC_NOP = $47 ; doublet +; OPC_NOP = $57 ; doublet +; OPC_NOP = $67 ; doublet +; OPC_NOP = $77 ; doublet +; OPC_NOP = $87 ; doublet +; OPC_NOP = $97 ; doublet +; OPC_NOP = $A7 ; doublet +; OPC_NOP = $B7 ; doublet +; OPC_NOP = $C7 ; doublet +; OPC_NOP = $D7 ; doublet +; OPC_NOP = $E7 ; doublet +; OPC_NOP = $F7 ; doublet +; OPC_NOP = $0F ; doublet +; OPC_NOP = $1F ; doublet +; OPC_NOP = $2F ; doublet +; OPC_NOP = $3F ; doublet +; OPC_NOP = $4F ; doublet +; OPC_NOP = $5F ; doublet +; OPC_NOP = $6F ; doublet +; OPC_NOP = $7F ; doublet +; OPC_NOP = $8F ; doublet +; OPC_NOP = $9F ; doublet +; OPC_NOP = $AF ; doublet +; OPC_NOP = $BF ; doublet +; OPC_NOP = $CF ; doublet +; OPC_NOP = $DF ; doublet +; OPC_NOP = $EF ; doublet +; OPC_NOP = $FF ; doublet + +.endif + +.elseif (.cpu .bitand ::CPU_ISET_6502X) + +; stable, undocumented opcodes + +; OPC_KIL = $02 ; unstable +OPC_SLO_izx = $03 +OPC_NOP_zp = $04 +OPC_SLO_zp = $07 +OPC_ANC_imm = $0B +OPC_NOP_abs = $0C +OPC_SLO_abs = $0F + +; OPC_KIL = $12 ; unstable +OPC_SLO_izy = $13 +OPC_NOP_zpx = $14 +OPC_SLO_zpx = $17 +;OPC_NOP = $1A +OPC_SLO_aby = $1B +OPC_NOP_abx = $1C +OPC_SLO_abx = $1F + +; OPC_KIL = $22 ; unstable +OPC_RLA_izx = $23 +OPC_RLA_zp = $27 +OPC_ANC_imm = $2B +OPC_RLA_abs = $2F + +; OPC_KIL = $32 ; unstable +OPC_RLA_izy = $33 +OPC_NOP_zpx = $34 +OPC_RLA_zpx = $37 +; OPC_NOP = $3A ; doublet +OPC_RLA_aby = $3B +OPC_NOP_abx = $3C +OPC_RLA_abx = $3F + +; OPC_KIL = $42 ; unstable +OPC_SRE_izx = $43 +OPC_NOP_zp = $44 +OPC_SRE_zp = $47 +OPC_ALR_imm = $4B +OPC_SRE_abs = $4F + +; OPC_KIL = $52 ; unstable +OPC_SRE_izy = $53 +OPC_NOP_zpx = $54 +OPC_SRE_zpx = $57 +; OPC_NOP = $5A ; doublet +OPC_SRE_aby = $5B +OPC_NOP_abx = $5C +OPC_SRE_abx = $5F + +; OPC_KIL = $62 +OPC_RRA_izx = $63 +OPC_NOP_zp = $64 +OPC_RRA_zp = $67 +OPC_ARR_imm = $6B +OPC_RRA_abs = $6F + +; OPC_KIL = $72 +OPC_RRA_izy = $73 +OPC_NOP_zpx = $74 +OPC_RRA_zpx = $77 +; OPC_NOP = $7A ; doublet +OPC_RRA_aby = $7B +OPC_NOP_abx = $7C +OPC_RRA_abx = $7F + +OPC_NOP_imm = $80 +; OPC_NOP_imm = $82 ; doublet +OPC_SAX_izx = $83 +OPC_SAX_zp = $87 +; OPC_NOP_imm = $89 ; doublet +; OPC_XAA = $8B ; unstable +OPC_SAX_abs = $8F + +; OPC_KIL = $92 ; unstable +; OPC_AHX_izy = $93 ; unstable +OPC_SAX_zpy = $97 +; OPC_TAS_aby = $9B ; unstable +; OPC_SHY_abx = $9C ; unstable +; OPC_SHX_aby = $9E ; unstable +; OPC_AHX_aby = $9F ; unstable + +OPC_LAX_izx = $A3 +OPC_LAX_zp = $A7 +; OPC_LAX_imm = $AB ; unstable +OPC_LAX_abs = $AF + +; OPC_KIL = $B2 ; unstable +OPC_LAX_izy = $B3 +OPC_LAX_zpy = $B7 +OPC_LAS_aby = $BB +OPC_LAX_aby = $BF + +; OPC_NOP_imm = $C2 ; doublet +OPC_DCP_izx = $C3 +OPC_DCP_zp = $C7 +OPC_AXS_imm = $CB +OPC_DCP_abs = $CF + +; OPC_KIL = $D2 ; unstable +OPC_DCP_izy = $D3 +OPC_NOP_zpx = $D4 +OPC_DCP_zpx = $D7 +OPC_NOP_DA = $DA +OPC_DCP_aby = $DB +OPC_NOP_abx = $DC +OPC_DCP_abx = $DF + +; OPC_NOP_imm = $E2 ; doublet +OPC_ISC_izx = $E3 +OPC_ISC_zp = $E7 +; OPC_SBC_imm = $EB ; doublet +OPC_ISC_abs = $EF + +; OPC_KIL = $F2 ; unstable +OPC_ISC_izy = $F3 +OPC_NOP_zpx = $F4 +OPC_ISC_zpx = $F7 +OPC_NOP_FA = $FA +OPC_ISC_aby = $FB +OPC_NOP_abx = $FC +OPC_ISC_abx = $FF + +.endif diff --git a/asminc/pet.inc b/asminc/pet.inc index a745a89c8..43d52a5d5 100644 --- a/asminc/pet.inc +++ b/asminc/pet.inc @@ -26,11 +26,22 @@ SCR_LINELEN := $D5 ; Screen line length CURS_Y := $D8 ; Cursor row FNADR := $DA ; Pointer to file name +; 80-Column CBMs +KBDREPEAT80 := $E4 +KBDRPTRATE80 := $E5 +KBDRPTDELAY80 := $E6 + BASIC_BUF := $200 ; Location of command-line BASIC_BUF_LEN = 81 ; Maximum length of command-line KEY_BUF := $26F ; Keyboard buffer +; 40-Column PETs/CBMs +KBDRPTDELAY40 := $3E9 +KBDRPTRATE40 := $3EA +KBDREPEAT40 := $3EE +KBDREPEAT40B := $3F8 + ;---------------------------------------------------------------------------- ; PET ROM type detection @@ -55,5 +66,3 @@ VIA_PRB := $E840 VIA_PRA := $E841 VIA_DDRB := $E842 VIA_DDRA := $E843 - - diff --git a/asminc/plus4.inc b/asminc/plus4.inc index 69b2298a3..3b2f08c54 100644 --- a/asminc/plus4.inc +++ b/asminc/plus4.inc @@ -33,6 +33,10 @@ FKEY_COUNT := $55D ; Characters for function key FKEY_SPACE := $55F ; Function key definitions FKEY_ORIG := $F3D2 ; Original definitions +KBDREPEAT := $540 +KBDREPEATRATE := $541 +KBDREPEATDELAY := $542 + ; --------------------------------------------------------------------------- ; Kernal routines diff --git a/asminc/smc.inc b/asminc/smc.inc index d5752a5f5..0583f79e0 100644 --- a/asminc/smc.inc +++ b/asminc/smc.inc @@ -1,267 +1,267 @@ -; smc.mac -; ca65 Macro-Pack for Self Modifying Code (SMC) -; -; (c) Christian Krüger, latest change: 17-Jul-2016 -; -; This software is provided 'as-is', without any expressed or implied -; warranty. In no event will the authors be held liable for any damages -; arising from the use of this software. -; -; Permission is granted to anyone to use this software for any purpose, -; including commercial applications, and to alter it and redistribute it -; freely, subject to the following restrictions: -; -; 1. The origin of this software must not be misrepresented; you must not -; claim that you wrote the original software. If you use this software -; in a product, an acknowledgment in the product documentation would be -; appreciated but is not required. -; 2. Altered source versions must be plainly marked as such, and must not -; be misrepresented as being the original software. -; 3. This notice may not be removed or altered from any source -; distribution. -; - -.define _SMCDesignator .mid(0, .tcount(label) - 1, label) .ident(.concat(.string(.right(1, label)), "_SMC")) -.define _SMCAlias .mid(0, .tcount(alias) - 1, alias) .ident(.concat(.string(.right(1, alias)), "_SMC")) -.define SMC_AbsAdr $FADE -.define SMC_ZpAdr $00 -.define SMC_Opcode nop -.define SMC_Value $42 - -.macro SMC_OperateOnValue opcode, label - opcode _SMCDesignator+1 -.endmacro - -.macro SMC_OperateOnLowByte opcode, label - SMC_OperateOnValue opcode, label -.endmacro - -.macro SMC_OperateOnHighByte opcode, label - opcode _SMCDesignator + 2 -.endmacro - -.macro SMC_Import alias -.import _SMCAlias -.endmacro - -.macro SMC_Export alias, label -.export _SMCAlias := _SMCDesignator -.endmacro - -.macro SMC label, statement -_SMCDesignator: statement -.endmacro - -.macro SMC_TransferOpcode label, opcode, register -.if .paramcount = 2 .or .match ({register}, a) .or .match ({register}, ) - lda #opcode - sta _SMCDesignator -.elseif .match ({register}, x) - ldx #opcode - stx _SMCDesignator -.elseif .match ({register}, y) - ldy #opcode - sty _SMCDesignator -.else - .error "Invalid usage of macro 'SMC_TransferOpcode'" -.endif -.endmacro - -.macro SMC_LoadOpcode label, register -.if .paramcount = 1 .or .match ({register}, a) .or .match ({register}, ) - lda _SMCDesignator -.elseif .match ({register}, x) - ldx _SMCDesignator -.elseif .match ({register}, y) - ldy _SMCDesignator -.else - .error "Invalid usage of macro 'SMC_LoadOpcode'" -.endif -.endmacro - -.macro SMC_StoreOpcode label, register -.if .paramcount = 1 .or .match ({register}, a) .or .match ({register}, ) - sta _SMCDesignator -.elseif .match ({register}, x) - stx _SMCDesignator -.elseif .match ({register}, y) - sty _SMCDesignator -.else - .error "Invalid usage of macro 'SMC_StoreOpcode'" -.endif -.endmacro - -.macro SMC_ChangeBranch label, destination, register -.if .paramcount = 2 .or .match ({register}, a) .or .match ({register}, ) - lda #(<(destination - _SMCDesignator -2)) - sta _SMCDesignator+1 -.elseif .match ({register}, x) - ldx #(<(destination - _SMCDesignator - 2)) - stx _SMCDesignator+1 -.elseif .match ({register}, y) - ldy #(<(destination - _SMCDesignator - 2)) - sty _SMCDesignator+1 -.else - .error "Invalid usage of macro 'SMC_ChangeBranch'" -.endif -.endmacro - -.macro SMC_TransferValue label, value, register -.if .paramcount = 2 .or .match ({register}, a) .or .match ({register}, ) - lda value - sta _SMCDesignator+1 -.elseif .match ({register}, x) - ldx value - stx _SMCDesignator+1 -.elseif .match ({register}, y) - ldy value - sty _SMCDesignator+1 -.else - .error "Invalid usage of macro 'SMC_TransferValue'" -.endif -.endmacro - -.macro SMC_LoadValue label, register -.if .paramcount = 1 .or .match ({register}, a) .or .match ({register}, ) - lda _SMCDesignator+1 -.elseif .match ({register}, x) - ldx _SMCDesignator+1 -.elseif .match ({register}, y) - ldy _SMCDesignator+1 -.else - .error "Invalid usage of macro 'SMC_LoadValue'" -.endif -.endmacro - -.macro SMC_StoreValue label, register -.if .paramcount = 1 .or .match ({register}, a) .or .match ({register}, ) - sta _SMCDesignator+1 -.elseif .match ({register}, x) - stx _SMCDesignator+1 -.elseif .match ({register}, y) - sty _SMCDesignator+1 -.else - .error "Invalid usage of macro 'SMC_StoreValue'" -.endif -.endmacro - - -.macro SMC_TransferLowByte label, value, register -SMC_TransferValue label, value, register -.endmacro - -.macro SMC_LoadLowByte label, register -SMC_LoadValue label, register -.endmacro - -.macro SMC_StoreLowByte label, register -SMC_StoreValue label, register -.endmacro - -.macro SMC_TransferHighByte label, value, register -.if .paramcount = 2 .or .match ({register}, a) .or .match ({register}, ) - lda value - sta _SMCDesignator+2 -.elseif .match ({register}, x) - ldx value - stx _SMCDesignator+2 -.elseif .match ({register}, y) - ldy value - sty _SMCDesignator+2 -.else - .error "Invalid usage of macro 'SMC_TransferHighByte'" -.endif -.endmacro - -.macro SMC_LoadHighByte label, register -.if .paramcount = 1 .or .match ({register}, a) .or .match ({register}, ) - lda _SMCDesignator+2 -.elseif .match ({register}, x) - ldx _SMCDesignator+2 -.elseif .match ({register}, y) - ldy _SMCDesignator+2 -.else - .error "Invalid usage of macro 'SMC_LoadHighByte'" -.endif -.endmacro - -.macro SMC_StoreHighByte label, register -.if .paramcount = 1 .or .match ({register}, a) .or .match ({register}, ) - sta _SMCDesignator+2 -.elseif .match ({register}, x) - stx _SMCDesignator+2 -.elseif .match ({register}, y) - sty _SMCDesignator+2 -.else - .error "Invalid usage of macro 'SMC_StoreHighByte'" -.endif -.endmacro - -.macro SMC_TransferAddressSingle label, address, register -.if .paramcount = 2 .or .match ((register), a) .or .match ({register}, ) - .if (.match (.left (1, {address}), #)) - ; immediate mode - lda #<(.right (.tcount ({address})-1, {address})) - sta _SMCDesignator+1 - lda #>(.right (.tcount ({address})-1, {address})) - sta _SMCDesignator+2 - .else - ; assume absolute or zero page - lda address - sta _SMCDesignator+1 - lda 1+(address) - sta _SMCDesignator+2 - .endif -.elseif .match ((register), x) - .if (.match (.left (1, {address}), #)) - ; immediate mode - ldx #<(.right (.tcount ({address})-1, {address})) - stx _SMCDesignator+1 - ldx #>(.right (.tcount ({address})-1, {address})) - stx _SMCDesignator+2 - .else - ; assume absolute or zero page - ldx address - stx _SMCDesignator+1 - ldx 1+(address) - stx _SMCDesignator+2 - .endif -.elseif .match ((register), y) - .if (.match (.left (1, {address}), #)) - ; immediate mode - ldy #<(.right (.tcount ({address})-1, {address})) - sty _SMCDesignator+1 - ldy #>(.right (.tcount ({address})-1, {address})) - sty _SMCDesignator+2 - .else - ; assume absolute or zero page - ldy address - sty _SMCDesignator+1 - ldy 1+(address) - sty _SMCDesignator+2 - .endif -.else - .error "Invalid usage of macro 'SMC_TransferAddressSingle'" -.endif -.endmacro - -.macro SMC_TransferAddress label, address -.if (.match (.left (1, {address}), #)) - ; immediate mode - lda #<(.right (.tcount ({address})-1, {address})) - sta _SMCDesignator+1 - ldx #>(.right (.tcount ({address})-1, {address})) - stx _SMCDesignator+2 -.else - ; assume absolute or zero page - lda {address} - sta _SMCDesignator+1 - ldx 1+{address} - stx _SMCDesignator)+2 -.endif -.endmacro - -.macro SMC_StoreAddress label - sta _SMCDesignator+1 - stx _SMCDesignator+2 -.endmacro +; smc.mac +; ca65 Macro-Pack for Self Modifying Code (SMC) +; +; (c) Christian Krüger, latest change: 17-Jul-2016 +; +; This software is provided 'as-is', without any expressed or implied +; warranty. In no event will the authors be held liable for any damages +; arising from the use of this software. +; +; Permission is granted to anyone to use this software for any purpose, +; including commercial applications, and to alter it and redistribute it +; freely, subject to the following restrictions: +; +; 1. The origin of this software must not be misrepresented; you must not +; claim that you wrote the original software. If you use this software +; in a product, an acknowledgment in the product documentation would be +; appreciated but is not required. +; 2. Altered source versions must be plainly marked as such, and must not +; be misrepresented as being the original software. +; 3. This notice may not be removed or altered from any source +; distribution. +; + +.define _SMCDesignator .mid(0, .tcount(label) - 1, label) .ident(.concat(.string(.right(1, label)), "_SMC")) +.define _SMCAlias .mid(0, .tcount(alias) - 1, alias) .ident(.concat(.string(.right(1, alias)), "_SMC")) +.define SMC_AbsAdr $FADE +.define SMC_ZpAdr $00 +.define SMC_Opcode nop +.define SMC_Value $42 + +.macro SMC_OperateOnValue opcode, label + opcode _SMCDesignator+1 +.endmacro + +.macro SMC_OperateOnLowByte opcode, label + SMC_OperateOnValue opcode, label +.endmacro + +.macro SMC_OperateOnHighByte opcode, label + opcode _SMCDesignator + 2 +.endmacro + +.macro SMC_Import alias +.import _SMCAlias +.endmacro + +.macro SMC_Export alias, label +.export _SMCAlias := _SMCDesignator +.endmacro + +.macro SMC label, statement +_SMCDesignator: statement +.endmacro + +.macro SMC_TransferOpcode label, opcode, register +.if .paramcount = 2 .or .match ({register}, a) .or .match ({register}, ) + lda #opcode + sta _SMCDesignator +.elseif .match ({register}, x) + ldx #opcode + stx _SMCDesignator +.elseif .match ({register}, y) + ldy #opcode + sty _SMCDesignator +.else + .error "Invalid usage of macro 'SMC_TransferOpcode'" +.endif +.endmacro + +.macro SMC_LoadOpcode label, register +.if .paramcount = 1 .or .match ({register}, a) .or .match ({register}, ) + lda _SMCDesignator +.elseif .match ({register}, x) + ldx _SMCDesignator +.elseif .match ({register}, y) + ldy _SMCDesignator +.else + .error "Invalid usage of macro 'SMC_LoadOpcode'" +.endif +.endmacro + +.macro SMC_StoreOpcode label, register +.if .paramcount = 1 .or .match ({register}, a) .or .match ({register}, ) + sta _SMCDesignator +.elseif .match ({register}, x) + stx _SMCDesignator +.elseif .match ({register}, y) + sty _SMCDesignator +.else + .error "Invalid usage of macro 'SMC_StoreOpcode'" +.endif +.endmacro + +.macro SMC_ChangeBranch label, destination, register +.if .paramcount = 2 .or .match ({register}, a) .or .match ({register}, ) + lda #(<(destination - _SMCDesignator -2)) + sta _SMCDesignator+1 +.elseif .match ({register}, x) + ldx #(<(destination - _SMCDesignator - 2)) + stx _SMCDesignator+1 +.elseif .match ({register}, y) + ldy #(<(destination - _SMCDesignator - 2)) + sty _SMCDesignator+1 +.else + .error "Invalid usage of macro 'SMC_ChangeBranch'" +.endif +.endmacro + +.macro SMC_TransferValue label, value, register +.if .paramcount = 2 .or .match ({register}, a) .or .match ({register}, ) + lda value + sta _SMCDesignator+1 +.elseif .match ({register}, x) + ldx value + stx _SMCDesignator+1 +.elseif .match ({register}, y) + ldy value + sty _SMCDesignator+1 +.else + .error "Invalid usage of macro 'SMC_TransferValue'" +.endif +.endmacro + +.macro SMC_LoadValue label, register +.if .paramcount = 1 .or .match ({register}, a) .or .match ({register}, ) + lda _SMCDesignator+1 +.elseif .match ({register}, x) + ldx _SMCDesignator+1 +.elseif .match ({register}, y) + ldy _SMCDesignator+1 +.else + .error "Invalid usage of macro 'SMC_LoadValue'" +.endif +.endmacro + +.macro SMC_StoreValue label, register +.if .paramcount = 1 .or .match ({register}, a) .or .match ({register}, ) + sta _SMCDesignator+1 +.elseif .match ({register}, x) + stx _SMCDesignator+1 +.elseif .match ({register}, y) + sty _SMCDesignator+1 +.else + .error "Invalid usage of macro 'SMC_StoreValue'" +.endif +.endmacro + + +.macro SMC_TransferLowByte label, value, register +SMC_TransferValue label, value, register +.endmacro + +.macro SMC_LoadLowByte label, register +SMC_LoadValue label, register +.endmacro + +.macro SMC_StoreLowByte label, register +SMC_StoreValue label, register +.endmacro + +.macro SMC_TransferHighByte label, value, register +.if .paramcount = 2 .or .match ({register}, a) .or .match ({register}, ) + lda value + sta _SMCDesignator+2 +.elseif .match ({register}, x) + ldx value + stx _SMCDesignator+2 +.elseif .match ({register}, y) + ldy value + sty _SMCDesignator+2 +.else + .error "Invalid usage of macro 'SMC_TransferHighByte'" +.endif +.endmacro + +.macro SMC_LoadHighByte label, register +.if .paramcount = 1 .or .match ({register}, a) .or .match ({register}, ) + lda _SMCDesignator+2 +.elseif .match ({register}, x) + ldx _SMCDesignator+2 +.elseif .match ({register}, y) + ldy _SMCDesignator+2 +.else + .error "Invalid usage of macro 'SMC_LoadHighByte'" +.endif +.endmacro + +.macro SMC_StoreHighByte label, register +.if .paramcount = 1 .or .match ({register}, a) .or .match ({register}, ) + sta _SMCDesignator+2 +.elseif .match ({register}, x) + stx _SMCDesignator+2 +.elseif .match ({register}, y) + sty _SMCDesignator+2 +.else + .error "Invalid usage of macro 'SMC_StoreHighByte'" +.endif +.endmacro + +.macro SMC_TransferAddressSingle label, address, register +.if .paramcount = 2 .or .match ((register), a) .or .match ({register}, ) + .if (.match (.left (1, {address}), #)) + ; immediate mode + lda #<(.right (.tcount ({address})-1, {address})) + sta _SMCDesignator+1 + lda #>(.right (.tcount ({address})-1, {address})) + sta _SMCDesignator+2 + .else + ; assume absolute or zero page + lda address + sta _SMCDesignator+1 + lda 1+(address) + sta _SMCDesignator+2 + .endif +.elseif .match ((register), x) + .if (.match (.left (1, {address}), #)) + ; immediate mode + ldx #<(.right (.tcount ({address})-1, {address})) + stx _SMCDesignator+1 + ldx #>(.right (.tcount ({address})-1, {address})) + stx _SMCDesignator+2 + .else + ; assume absolute or zero page + ldx address + stx _SMCDesignator+1 + ldx 1+(address) + stx _SMCDesignator+2 + .endif +.elseif .match ((register), y) + .if (.match (.left (1, {address}), #)) + ; immediate mode + ldy #<(.right (.tcount ({address})-1, {address})) + sty _SMCDesignator+1 + ldy #>(.right (.tcount ({address})-1, {address})) + sty _SMCDesignator+2 + .else + ; assume absolute or zero page + ldy address + sty _SMCDesignator+1 + ldy 1+(address) + sty _SMCDesignator+2 + .endif +.else + .error "Invalid usage of macro 'SMC_TransferAddressSingle'" +.endif +.endmacro + +.macro SMC_TransferAddress label, address +.if (.match (.left (1, {address}), #)) + ; immediate mode + lda #<(.right (.tcount ({address})-1, {address})) + sta _SMCDesignator+1 + ldx #>(.right (.tcount ({address})-1, {address})) + stx _SMCDesignator+2 +.else + ; assume absolute or zero page + lda {address} + sta _SMCDesignator+1 + ldx 1+{address} + stx _SMCDesignator)+2 +.endif +.endmacro + +.macro SMC_StoreAddress label + sta _SMCDesignator+1 + stx _SMCDesignator+2 +.endmacro diff --git a/asminc/vic20.inc b/asminc/vic20.inc index 12424dc11..d882eb1ad 100644 --- a/asminc/vic20.inc +++ b/asminc/vic20.inc @@ -31,6 +31,9 @@ BASIC_BUF_LEN = 89 ; Maximum length of command-line CHARCOLOR := $286 CURS_COLOR := $287 ; Color under the cursor +KBDREPEAT := $28a +KBDREPEATRATE := $28b +KBDREPEATDELAY := $28c ; --------------------------------------------------------------------------- ; Screen size diff --git a/cfg/creativision.cfg b/cfg/creativision.cfg index 06e39b36f..9e4ecd8ce 100644 --- a/cfg/creativision.cfg +++ b/cfg/creativision.cfg @@ -4,7 +4,7 @@ SYMBOLS { MEMORY { ZP: file = "", define = yes, start = $0020, size = $00E0; RAM: file = "", define = yes, start = $01FA, size = $0206; - ROM: file = %O, define = yes, start = $B000, size = $1000; + ROM: file = %O, define = yes, start = $B000, size = $1000, fill = yes, fillval = $FF; } SEGMENTS { ZEROPAGE: load = ZP, type = zp; diff --git a/cfg/sim6502.cfg b/cfg/sim6502.cfg index b4f7738f5..530787489 100644 --- a/cfg/sim6502.cfg +++ b/cfg/sim6502.cfg @@ -3,7 +3,7 @@ SYMBOLS { __STACKSIZE__: type = weak, value = $0800; # 2k stack } MEMORY { - ZP: file = "", start = $0000, size = $001A; + ZP: file = "", start = $0000, size = $001B; HEADER: file = %O, start = $0000, size = $0001; MAIN: file = %O, define = yes, start = $0200, size = $FDF0 - __STACKSIZE__; } diff --git a/cfg/sim65c02.cfg b/cfg/sim65c02.cfg index b4f7738f5..530787489 100644 --- a/cfg/sim65c02.cfg +++ b/cfg/sim65c02.cfg @@ -3,7 +3,7 @@ SYMBOLS { __STACKSIZE__: type = weak, value = $0800; # 2k stack } MEMORY { - ZP: file = "", start = $0000, size = $001A; + ZP: file = "", start = $0000, size = $001B; HEADER: file = %O, start = $0000, size = $0001; MAIN: file = %O, define = yes, start = $0200, size = $FDF0 - __STACKSIZE__; } diff --git a/doc/Makefile b/doc/Makefile index 96a3ba59b..33b5c2686 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -6,8 +6,8 @@ endif .SUFFIXES: -htmldir = $(prefix)/share/doc/cc65$(DESTPACKAGE_SUFFIX)/html -infodir = $(prefix)/share/info +htmldir = $(PREFIX)/share/doc/cc65$(DESTPACKAGE_SUFFIX)/html +infodir = $(PREFIX)/share/info ifdef CMD_EXE @@ -46,7 +46,7 @@ clean: $(RM) -r ../html ../info install: - $(if $(prefix),,$(error variable `prefix' must be set)) + $(if $(PREFIX),,$(error variable `PREFIX' must be set)) ifeq ($(wildcard ../html),../html) $(INSTALL) -d $(DESTDIR)$(htmldir) $(INSTALL) -m0644 ../html/*.* $(DESTDIR)$(htmldir) diff --git a/doc/apple2.sgml b/doc/apple2.sgml index d0405b6de..33a878223 100644 --- a/doc/apple2.sgml +++ b/doc/apple2.sgml @@ -435,7 +435,7 @@ BASIC.SYSTEM) there are some limitations for DOS 3.3:

@@ -511,6 +511,109 @@ url="ca65.html" name="assembler manual">.

+Specifying file types for fopen

+ + + + Explanation of File Types + + ProDOS associates a file type and an auxiliary type with each file. + These type specifications are separate from the file's name, unlike + Windows which uses the file name's suffix (a.k.a. + extension) to specify the file type. For example, Specifying the File Type and Auxiliary Type + + There are two global variables provided that allow the file type + and auxiliary type to be specified before a call to + + extern unsigned char _filetype; /* Default: PRODOS_T_BIN */ + extern unsigned int _auxtype; /* Default: 0 */ + + + + The header file Example + + A text file cannot be created with just the + standard C functions because they default to the binary type + + + #include <stdio.h> + #include <string.h> + #include <errno.h> + #include <apple2.h> + + void main(void) + { + FILE *out; + char *name = "MY.FAVS"; + + /*-----------------------------*/ + + _filetype = PRODOS_T_TXT; + _auxtype = PRODOS_AUX_T_TXT_SEQ; + + /*-----------------------------*/ + + if ((out = fopen(name, "w")) != NULL) { + fputs("Jorah Mormont\r", out); + fputs("Brienne of Tarth\r", out); + fputs("Daenerys Targaryen\r", out); + fputs("Sandor Clegane\r", out); + if (fclose(out) == EOF) { + fprintf(stderr, "fclose failed for %s: %s", name, strerror(errno)); + } + } + else { + fprintf(stderr, "fopen failed for %s: %s", name, strerror(errno)); + } + } + + + +

+ License

diff --git a/doc/apple2enh.sgml b/doc/apple2enh.sgml index b5231b4cd..4f5202543 100644 --- a/doc/apple2enh.sgml +++ b/doc/apple2enh.sgml @@ -436,7 +436,7 @@ BASIC.SYSTEM) there are some limitations for DOS 3.3:

@@ -517,6 +517,109 @@ url="ca65.html" name="assembler manual">.

+Specifying file types for fopen

+ + + + Explanation of File Types + + ProDOS associates a file type and an auxiliary type with each file. + These type specifications are separate from the file's name, unlike + Windows which uses the file name's suffix (a.k.a. + extension) to specify the file type. For example, Specifying the File Type and Auxiliary Type + + There are two global variables provided that allow the file type + and auxiliary type to be specified before a call to + + extern unsigned char _filetype; /* Default: PRODOS_T_BIN */ + extern unsigned int _auxtype; /* Default: 0 */ + + + + The header file Example + + A text file cannot be created with just the + standard C functions because they default to the binary type + + + #include <stdio.h> + #include <string.h> + #include <errno.h> + #include <apple2.h> + + void main(void) + { + FILE *out; + char *name = "MY.FAVS"; + + /*-----------------------------*/ + + _filetype = PRODOS_T_TXT; + _auxtype = PRODOS_AUX_T_TXT_SEQ; + + /*-----------------------------*/ + + if ((out = fopen(name, "w")) != NULL) { + fputs("Jorah Mormont\r", out); + fputs("Brienne of Tarth\r", out); + fputs("Daenerys Targaryen\r", out); + fputs("Sandor Clegane\r", out); + if (fclose(out) == EOF) { + fprintf(stderr, "fclose failed for %s: %s", name, strerror(errno)); + } + } + else { + fprintf(stderr, "fopen failed for %s: %s", name, strerror(errno)); + } + } + + + +

+ License

diff --git a/doc/ar65.sgml b/doc/ar65.sgml index 136defd40..2e01025ca 100644 --- a/doc/ar65.sgml +++ b/doc/ar65.sgml @@ -4,7 +4,7 @@ ar65 Users Guide <author><url url="mailto:uz@cc65.org" name="Ullrich von Bassewitz"> -<date>19.07.2000 +<date>2017-05-28 <abstract> ar65 is an archiver for object files generated by ca65. It allows to create @@ -32,16 +32,17 @@ for the cc65 compiler. ar65 is part of this suite. The archiver is called as follows: <tscreen><verb> - Usage: ar65 <operation> lib file|module ... - Operation is one of: - a Add modules - d Delete modules - l List library contents - x Extract modules - V Print the archiver version + Usage: ar65 <operation ...> lib file|module ... + Operations are some of: + r Add modules + d Delete modules + t List library table + v Increase verbosity (put before other operation) + x Extract modules + V Print the archiver version </verb></tscreen> -You may add modules to a library using the `a' command. If the library +You may add modules to a library using the `r' command (`a' is deprecated). If the library does not exist, it is created (and a warning message is printed which you may ignore if creation of the library was your intention). You may specify any number of modules on the command line following the library. @@ -53,7 +54,7 @@ has a newer timestamp than the one to add. Here's an example: <tscreen><verb> - ar65 a mysubs.lib sub1.o sub2.o + ar65 r mysubs.lib sub1.o sub2.o </verb></tscreen> This will add two modules to the library `mysubs.lib' creating the @@ -63,10 +64,10 @@ sub2.o, they are replaced by the new ones. Modules names in the library are stored without the path, so, using <tscreen><verb> - ar65 a mysubs.lib ofiles/sub1.o ofiles/sub2.o + ar65 v v r mysubs.lib ofiles/sub1.o ofiles/sub2.o </verb></tscreen> -will add two modules named `sub1.o' and `sub2.o' to the library. +will verbose add two modules named `sub1.o' and `sub2.o' to the library. Deleting modules from a library is done with the `d' command. You may not give a path when naming the modules. @@ -81,13 +82,13 @@ This will delete the module named `sub1.o' from the library, printing an error if the library does not contain that module. -The `l' command prints a list of all modules in the library. Any module -names on the command line are ignored. +The `t' command prints a table of all modules in the library (`l' is deprecated). +Any module names on the command line are ignored. Example: <tscreen><verb> - ar65 l mysubs.lib + ar65 tv mysubs.lib </verb></tscreen> diff --git a/doc/ca65.sgml b/doc/ca65.sgml index da0233c62..715ecd89e 100644 --- a/doc/ca65.sgml +++ b/doc/ca65.sgml @@ -1636,7 +1636,7 @@ either a string or an expression. <tscreen><verb> ; Reserve space for the larger of two data blocks - savearea: .max (.sizeof (foo), .sizeof (bar)) + savearea: .res .max (.sizeof (foo), .sizeof (bar)) </verb></tscreen> See: <tt><ref id=".MIN" name=".MIN"></tt> @@ -1695,8 +1695,8 @@ either a string or an expression. Example: <tscreen><verb> - ; Reserve space for some data, but 256 bytes minimum - savearea: .min (.sizeof (foo), 256) + ; Reserve space for some data, but 256 bytes maximum + savearea: .res .min (.sizeof (foo), 256) </verb></tscreen> See: <tt><ref id=".MAX" name=".MAX"></tt> @@ -4305,6 +4305,13 @@ different: some things may be done with both macro types, each type has special usages. The types complement each other. +<item> Parentheses work differently from C macros. + The common practice of wrapping C macros in parentheses may cause + unintended problems here, such as accidentally implying an + indirect addressing mode. While the definition of a macro requires + parentheses around its argument list, when invoked they should not be + included. + </itemize> Let's look at a few examples to make the advantages and disadvantages @@ -4337,18 +4344,42 @@ Macros with parameters may also be useful: DEBUG "Assembling include file #3" </verb></tscreen> -Note that, while formal parameters have to be placed in braces, this is -not true for the actual parameters. Beware: Since the assembler cannot -detect the end of one parameter, only the first token is used. If you -don't like that, use classic macros instead: +Note that, while formal parameters have to be placed in parentheses, +the actual argument used when invoking the macro should not be. +The invoked arguments are separated by commas only, if parentheses are +used by accident they will become part of the replaced token. + +If you wish to have an expression follow the macro invocation, the +last parameter can be enclosed in curly braces {} to indicate the end of that +argument. + +Examples: <tscreen><verb> -.macro DEBUG message - .out message -.endmacro +.define COMBINE(ta,tb,tc) ta+tb*10+tc*100 + +.word COMBINE 5,6,7 ; 5+6*10+7*100 = 765 +.word COMBINE(5,6,7) ; (5+6*10+7)*100 = 7200 ; incorrect use of parentheses +.word COMBINE 5,6,7+1 ; 5+6*10+7+1*100 = 172 +.word COMBINE 5,6,{7}+1 ; 5+6*10+7*100+1 = 766 ; {} encloses the argument +.word COMBINE 5,6-2,7 ; 5+6-2*10+7*100 = 691 +.word COMBINE 5,(6-2),7 ; 5+(6-2)*10+7*100 = 745 +.word COMBINE 5,6,7+COMBINE 0,1,2 ; 5+6*10+7+0+1*10+2*100*100 = 20082 +.word COMBINE 5,6,{7}+COMBINE 0,1,2 ; 5+6*10+7*100+0+1*10+2*100 = 975 </verb></tscreen> -(That is an example where a problem can be solved with both macro types). +With C macros it is common to enclose the results in parentheses to +prevent unintended interactions with the text of the arguments, but +additional care must be taken in this assembly context where parentheses +may alter the meaning of a statement. In particular, indirect addressing modes +may be accidentally implied: + +<tscreen><verb> +.define DUO(ta,tb) (ta+(tb*10)) + + lda DUO(5,4), Y ; LDA (indirect), Y + lda 0+DUO(5,4), Y ; LDA absolute indexed, Y +</verb></tscreen> <sect1>Characters in macros<p> diff --git a/doc/cbm510.sgml b/doc/cbm510.sgml index c24eba142..b171c2ce3 100644 --- a/doc/cbm510.sgml +++ b/doc/cbm510.sgml @@ -67,7 +67,7 @@ Special locations: <descrip> <tag/Stack/ - The C runtime stack is located at $FF81, and grows downwards. + The C runtime stack is located at $FEC2, and grows downwards. <tag/Heap/ The C heap is located at the end of the program, and grows towards the C diff --git a/doc/cc65.sgml b/doc/cc65.sgml index 80dba89b8..cd94f50ac 100644 --- a/doc/cc65.sgml +++ b/doc/cc65.sgml @@ -4,7 +4,7 @@ <title>cc65 Users Guide <author><url url="mailto:uz@cc65.org" name="Ullrich von Bassewitz">,<newline> <url url="mailto:gregdk@users.sf.net" name="Greg King"> -<date>2016-06-11 +<date>2017-05-20 <abstract> cc65 is a C compiler for 6502 targets. It supports several 6502 based home @@ -58,7 +58,7 @@ Short options: -O Optimize code -Oi Optimize code, inline more code -Or Enable register variables - -Os Inline some known functions + -Os Inline some standard functions -T Include source as comment -V Print the compiler version number -W warning[,...] Suppress warnings @@ -88,9 +88,11 @@ Long options: --debug-opt name Debug optimization steps --dep-target target Use this dependency target --disable-opt name Disable an optimization step + --eagerly-inline-funcs Eagerly inline some known functions --enable-opt name Enable an optimization step --help Help (this text) --include-dir dir Set an include directory search path + --inline-stdfuncs Inline some standard functions --list-opt-steps List all optimizer steps and exit --list-warnings List available warning types for -W --local-strings Emit string literals immediately @@ -219,11 +221,53 @@ Here is a description of all the command line options: symbols in a special section in the object file. + <label id="option-eagerly-inline-funcs"> + <tag><tt>--eagerly-inline-funcs</tt></tag> + + Have the compiler eagerly inline these functions from the C library: + <itemize> + <item><tt/memcpy()/ + <item><tt/memset()/ + <item><tt/strcmp()/ + <item><tt/strcpy()/ + <item><tt/strlen()/ + <item>most of the functions declared in <tt/<ctype.h>/ + </itemize> + + Note: This has two consequences: + <itemize> + <item>You may not use names of standard C functions for your own functions. + If you do that, your program is not standard-compliant anyway; but, + using <tt/--eagerly-inline-funcs/ actually will break things. + <p> + <item>The inlined string and memory functions will not handle strings or + memory areas larger than 255 bytes. Similarly, the inlined <tt/is..()/ + functions will not work with values outside the char. range (such as + <tt/EOF/). + <p> + </itemize> + + <tt/--eagerly-inline-funcs/ implies the <tt><ref id="option-inline-stdfuncs" + name="--inline-stdfuncs"></tt> command line option. + + See also <tt><ref id="pragma-allow-eager-inline" name="#pragma allow-eager-inline"></tt>. + + <tag><tt>-h, --help</tt></tag> Print the short option summary shown above. + <label id="option-inline-stdfuncs"> + <tag><tt>--inline-stdfuncs</tt></tag> + + Allow the compiler to inline some standard functions from the C library like + strlen. This will not only remove the overhead for a function call, but will + make the code visible for the optimizer. See also the <tt><ref id="option-O" + name="-Os"></tt> command line option and <tt><ref id="pragma-inline-stdfuncs" + name="#pragma inline-stdfuncs"></tt>. + + <label id="option-list-warnings"> <tag><tt>--list-warnings</tt></tag> @@ -392,22 +436,22 @@ Here is a description of all the command line options: using <tscreen><verb> - void f (void) - { - unsigned a = 1; - ... - } + void f (void) + { + unsigned a = 1; + ... + } </verb></tscreen> the variable <tt/a/ will always have the value <tt/1/ when entering the function and using <tt/-Cl/, while in <tscreen><verb> - void f (void) - { - static unsigned a = 1; - .... - } + void f (void) + { + static unsigned a = 1; + .... + } </verb></tscreen> the variable <tt/a/ will have the value <tt/1/ only the first time that the @@ -444,23 +488,14 @@ Here is a description of all the command line options: name="--register-vars">/ command line option, and the <ref id="register-vars" name="discussion of register variables"> below. - Using <tt/-Os/ will force the compiler to inline some known functions from - the C library like strlen. Note: This has two consequences: - <p> - <itemize> - <item>You may not use names of standard C functions in your own code. If you - do that, your program is not standard compliant anyway, but using - <tt/-Os/ will actually break things. - <p> - <item>The inlined string and memory functions will not handle strings or - memory areas larger than 255 bytes. Similarly, the inlined <tt/is..()/ - functions will not work with values outside the char. range (such as - <tt/EOF/). - <p> - </itemize> - <p> + Using <tt/-Os/ will allow the compiler to inline some standard functions + from the C library like strlen. This will not only remove the overhead + for a function call, but will make the code visible for the optimizer. + See also the <tt/<ref id="option-inline-stdfuncs" name="--inline-stdfuncs">/ + command line option. + It is possible to concatenate the modifiers for <tt/-O/. For example, to - enable register variables and inlining of known functions, you may use + enable register variables and inlining of standard functions, you may use <tt/-Ors/. @@ -518,6 +553,7 @@ Here is a description of all the command line options: </descrip><p> + <sect>Input and output<p> The compiler will accept one C file per invocation and create a file with @@ -556,21 +592,21 @@ and the one defined by the ISO standard: <itemize> -<item> The datatypes "float" and "double" are not available. - <p> -<item> C Functions may not return structs (or unions), and structs may not +<item> The datatypes "float" and "double" are not available. + <p> +<item> C Functions may not return structs (or unions), and structs may not be passed as parameters by value. However, struct assignment *is* - possible. - <p> -<item> Most of the C library is available with only the fastcall calling - convention (<ref id="extension-fastcall" name="see below">). It means - that you must not mix pointers to those functions with pointers to - user-written, cdecl functions (the calling conventions are incompatible). - <p> -<item> The <tt/volatile/ keyword has almost no effect. That is not as bad + possible. + <p> +<item> Most of the C library is available with only the fastcall calling + convention (<ref id="extension-fastcall" name="see below">). It means + that you must not mix pointers to those functions with pointers to + user-written, cdecl functions (the calling conventions are incompatible). + <p> +<item> The <tt/volatile/ keyword has almost no effect. That is not as bad as it sounds, since the 6502 has so few registers that it isn't possible to keep values in registers anyway. - <p> + <p> </itemize> There may be some more minor differences I'm currently not aware of. The @@ -585,49 +621,48 @@ This cc65 version has some extensions to the ISO C standard. <itemize> -<item> The compiler allows to insert assembler statements into the output - file. The syntax is +<item> The compiler allows to insert assembler statements into the output + file. The syntax is - <tscreen><verb> - asm [optional volatile] (<string literal>[, optional parameters]) ; - </verb></tscreen> - or - <tscreen><verb> + <tscreen><verb> + asm [optional volatile] (<string literal>[, optional parameters]) ; + </verb></tscreen> + or + <tscreen><verb> __asm__ [optional volatile] (<string literal>[, optional parameters]) ; - </verb></tscreen> + </verb></tscreen> - The first form is in the user namespace; and, is disabled if the <tt/-A/ - switch is given. + The first form is in the user namespace; and, is disabled if the <tt/-A/ + switch is given. - There is a whole section covering inline assembler statements, - <ref id="inline-asm" name="see there">. - <p> + There is a whole section covering inline assembler statements, + <ref id="inline-asm" name="see there">. + <p> <label id="extension-fastcall"> -<item> The normal calling convention -- for non-variadic functions -- is - named "fastcall". The syntax for a function declaration that - <em/explicitly/ uses fastcall is +<item> The normal calling convention -- for non-variadic functions -- is + named "fastcall". The syntax for a function declaration that + <em/explicitly/ uses fastcall is - <tscreen><verb> - <return type> fastcall <function name> (<parameter list>) - </verb></tscreen> - or - <tscreen><verb> - <return type> __fastcall__ <function name> (<parameter list>) - </verb></tscreen> - An example is - <tscreen><verb> - void __fastcall__ f (unsigned char c) - </verb></tscreen> - The first form of the fastcall keyword is in the user namespace and can - therefore be disabled with the <tt><ref id="option--standard" + <tscreen><verb> + <return type> fastcall <function name> (<parameter list>) + </verb></tscreen> + or + <tscreen><verb> + <return type> __fastcall__ <function name> (<parameter list>) + </verb></tscreen> + An example is + <tscreen><verb> + void __fastcall__ f (unsigned char c) + </verb></tscreen> + The first form of the fastcall keyword is in the user namespace and can + therefore be disabled with the <tt><ref id="option--standard" name="--standard"></tt> command line option. - For functions that are <tt/fastcall/, the rightmost parameter is not - pushed on the stack but left in the primary register when the function - is called. That significantly reduces the cost of calling those functions. - <newline><newline> - <p> + For functions that are <tt/fastcall/, the rightmost parameter is not + pushed on the stack but left in the primary register when the function + is called. That significantly reduces the cost of calling those functions. + <p> <item> There is another calling convention named "cdecl". Variadic functions (their prototypes have an ellipsis [<tt/.../]) always use that @@ -652,65 +687,72 @@ This cc65 version has some extensions to the ISO C standard. For functions that are <tt/cdecl/, the rightmost parameter is pushed onto the stack before the function is called. That increases the cost of calling those functions, especially when they are called from many - places.<newline><newline> + places. <p> -<item> There are two pseudo variables named <tt/__AX__/ and <tt/__EAX__/. - Both refer to the primary register that is used by the compiler to - evaluate expressions or return function results. <tt/__AX__/ is of - type <tt/unsigned int/ and <tt/__EAX__/ of type <tt/long unsigned int/ - respectively. The pseudo variables may be used as lvalue and rvalue as - every other variable. They are most useful together with short - sequences of assembler code. For example, the macro +<item> There are two pseudo variables named <tt/__AX__/ and <tt/__EAX__/. + Both refer to the primary register that is used by the compiler to + evaluate expressions or return function results. <tt/__AX__/ is of + type <tt/unsigned int/ and <tt/__EAX__/ of type <tt/long unsigned int/ + respectively. The pseudo variables may be used as lvalue and rvalue as + every other variable. They are most useful together with short + sequences of assembler code. For example, the macro - <tscreen><verb> - #define hi(x) \ + <tscreen><verb> + #define hi(x) \ (__AX__ = (x), \ asm ("txa"), \ asm ("ldx #$00"), \ __AX__) - </verb></tscreen> + </verb></tscreen> - will give the high byte of any unsigned value. - <p> + will give the high byte of any unsigned value. + <p> -<item> Inside a function, the identifier <tt/__func__/ gives the name of the - current function as a string. Outside of functions, <tt/__func__/ is - undefined. - Example: +<item> Inside a function, the identifier <tt/__func__/ gives the name of the + current function as a string. Outside of functions, <tt/__func__/ is + undefined. + Example: - <tscreen><verb> - #define PRINT_DEBUG(s) printf ("%s: %s\n", __func__, s); - </verb></tscreen> + <tscreen><verb> + #define PRINT_DEBUG(s) printf ("%s: %s\n", __func__, s); + </verb></tscreen> - The macro will print the name of the current function plus a given - string. - <p> + The macro will print the name of the current function plus a given + string. + <p> -<item> cc65 allows the initialization of <tt/void/ variables. This may be - used to create variable structures that are more compatible with - interfaces written for assembler languages. Here is an example: +<item> cc65 allows the initialization of <tt/void/ variables. This may be + used to create arbitrary structures that are more compatible with + interfaces written for assembler languages. Here is an example: - <tscreen><verb> - void GCmd = { (char)3, (unsigned)0x2000, (unsigned)0x3000 }; - </verb></tscreen> + <tscreen><verb> + void GCmd = { (char)3, (unsigned)0x2000, (unsigned)0x3000 }; + </verb></tscreen> - This will be translated as follows: + That will be translated as follows: - <tscreen><verb> - _GCmd: - .byte 3 - .word $2000 - .word $3000 - </verb></tscreen> + <tscreen><verb> + _GCmd: + .byte 3 + .word $2000 + .word $3000 + </verb></tscreen> - Since the variable is of type <tt/void/ you may not use it as is. - However, taking the address of the variable results in a <tt/void*/ - which may be passed to any function expecting a pointer. + Since the variable is of type <tt/void/, you may not use it as-is. + However, taking the address of the variable results in a <tt/void*/ + which may be passed to any function expecting a pointer. Also, the + <tt/sizeof/ operator will give the length of the initializer: - See the <url url="geos.html" name="GEOS library document"> for examples - on how to use this feature. - <p> + <tscreen><verb> + GLen = sizeof GCmd; + </verb></tscreen> + + will assign the value 5 to <tt/GLen/. + + See the <url url="geos.html" name="GEOS library document"> for examples + on how to use that feature. + <p> <item> cc65 implements flexible array struct members as defined in the C99 ISO standard. As an extension, these fields may be initialized. There are @@ -818,6 +860,11 @@ The compiler defines several macros at startup: This macro expands to the date of translation of the preprocessing translation unit in the form "Mmm dd yyyy". + <tag><tt>__EAGERLY_INLINE_FUNCS__</tt></tag> + + Is defined if the compiler was called with the <tt><ref id="option-eagerly-inline-funcs" + name="--eagerly-inline-funcs"></tt> command line option. + <tag><tt>__FILE__</tt></tag> This macro expands to a string containing the name of the C source file. @@ -905,6 +952,7 @@ The compiler defines several macros at startup: </descrip> + <sect>#pragmas<label id="pragmas"><p> The compiler understands some pragmas that may be used to change code @@ -913,6 +961,19 @@ If the first parameter is <tt/push/, the old value is saved onto a stack before changing it. The value may later be restored by using the <tt/pop/ parameter with the <tt/#pragma/. + +<sect1><tt>#pragma allow-eager-inline ([push,] on|off)</tt><label id="pragma-allow-eager-inline"><p> + + Allow eager inlining of known functions. If the argument is "off", eager + inlining is disabled, otherwise it is enabled. Please note that (in contrast + to the <tt><ref id="option-eagerly-inline-funcs" name="--eagerly-inline-funcs"></tt> + command line option) this pragma does not imply the <tt><ref id="option-inline-stdfuncs" + name="--inline-stdfuncs"></tt> command line option. Rather it marks code to be safe for + eager inlining of known functions if inlining of standard functions is enabled. + + The <tt/#pragma/ understands the push and pop parameters as explained above. + + <sect1><tt>#pragma bss-name ([push,] <name>)</tt><label id="pragma-bss-name"><p> This pragma changes the name used for the BSS segment (the BSS segment @@ -931,7 +992,7 @@ parameter with the <tt/#pragma/. Example: <tscreen><verb> - #pragma bss-name ("MyBSS") + #pragma bss-name ("MyBSS") </verb></tscreen> @@ -986,6 +1047,7 @@ parameter with the <tt/#pragma/. The <tt/#pragma/ understands the push and pop parameters as explained above. + <sect1><tt>#pragma code-name ([push,] <name>)</tt><label id="pragma-code-name"><p> This pragma changes the name used for the CODE segment (the CODE segment @@ -1000,7 +1062,7 @@ parameter with the <tt/#pragma/. Example: <tscreen><verb> - #pragma code-name ("MyCODE") + #pragma code-name ("MyCODE") </verb></tscreen> @@ -1028,10 +1090,21 @@ parameter with the <tt/#pragma/. Example: <tscreen><verb> - #pragma data-name ("MyDATA") + #pragma data-name ("MyDATA") </verb></tscreen> +<sect1><tt>#pragma inline-stdfuncs ([push,] on|off)</tt><label id="pragma-inline-stdfuncs"><p> + + Allow the compiler to inline some standard functions from the C library like + strlen. If the argument is "off", inlining is disabled, otherwise it is enabled. + + See also the <tt/<ref id="option-inline-stdfuncs" name="--inline-stdfuncs">/ + command line option. + + The <tt/#pragma/ understands the push and pop parameters as explained above. + + <sect1><tt>#pragma local-strings ([push,] on|off)</tt><label id="pragma-local-strings"><p> When "on", emit string literals to the data segment when they're encountered @@ -1046,6 +1119,23 @@ parameter with the <tt/#pragma/. remembered and output as a whole when translation is finished. +<sect1><tt>#pragma message (<message>)</tt><label id="pragma-message"><p> + + This pragma is used to display informational messages at compile-time. + + The message intented to be displayed must be a string literal. + + Example: + <tscreen><verb> + #pragma message ("in a bottle") + </verb></tscreen> + + Results in the compiler outputting the following to stderr: + <tscreen><verb> + example.c(42): Note: in a bottle + </verb></tscreen> + + <sect1><tt>#pragma optimize ([push,] on|off)</tt><label id="pragma-optimize"><p> Switch optimization on or off. If the argument is "off", optimization is @@ -1076,7 +1166,7 @@ parameter with the <tt/#pragma/. Example: <tscreen><verb> - #pragma rodata-name ("MyRODATA") + #pragma rodata-name ("MyRODATA") </verb></tscreen> @@ -1098,9 +1188,9 @@ parameter with the <tt/#pragma/. Example: <tscreen><verb> - #pragma regvaraddr(on) /* Allow taking the address - * of register variables - */ + #pragma regvaraddr(on) /* Allow taking the address + * of register variables + */ </verb></tscreen> @@ -1147,7 +1237,7 @@ parameter with the <tt/#pragma/. Example: <tscreen><verb> /* Don't warn about the unused parameter in function func */ - #pragma warn (unused-param, push, off) + #pragma warn (unused-param, push, off) static int func (int unused) { return 0; @@ -1156,6 +1246,39 @@ parameter with the <tt/#pragma/. </verb></tscreen> +<sect1><tt>#pragma wrapped-call (push, <name>, <identifier>)</tt><label id="pragma-wrapped-call"><p> + + This pragma sets a wrapper for functions, often used for trampolines. + + The name is a function returning <tt/void/, and taking no parameters. + It must preserve the CPU's <tt/A/ and <tt/X/ registers if it wraps any + <tt/__fastcall__/ functions that have parameters. It must preserve + the <tt/Y/ register if it wraps any variadic functions (they have "<tt/.../" + in their prototypes). + + The identifier is an 8-bit number that's set into <tt/tmp4/. + + The address of a wrapped function is passed in <tt/ptr4/. The wrapper can + call that function by using "<tt/jsr callptr4/". + + This feature is useful, for example, with banked memory, to switch banks + automatically to where a wrapped function resides, and then to restore the + previous bank when it returns. + + The <tt/#pragma/ requires the push or pop argument as explained above. + + Example: + <tscreen><verb> +/* Note that this code can be in a header. */ +void mytrampoline(void); /* Doesn't corrupt __AX__ */ + +#pragma wrapped-call (push, mytrampoline, 5) +void somefunc1(void); +void somefunc2(int, char *); +#pragma wrapped-call (pop) + </verb></tscreen> + + <sect1><tt>#pragma writable-strings ([push,] on|off)</tt><label id="pragma-writable-strings"><p> Changes the storage location of string literals. For historical reasons, @@ -1180,13 +1303,12 @@ parameter with the <tt/#pragma/. Example: <tscreen><verb> - extern int foo; - #pragma zpsym ("foo"); /* foo is in the zeropage */ + extern int foo; + #pragma zpsym ("foo"); /* foo is in the zeropage */ </verb></tscreen> - <sect>Register variables<label id="register-vars"><p> The runtime for all supported platforms has 6 bytes of zero page space @@ -1269,7 +1391,7 @@ that function). As a shortcut, you can put the <tt/volatile/ qualifier in your <tt/asm/ statements. It will disable optimization for the functions in which those <tt/asm volatile/ statements sit. The effect is the same as though you put -</#pragma optimize(push, off)/ above those functions, and </#pragma +<tt/#pragma optimize(push, off)/ above those functions, and <tt/#pragma optimize(pop)/ below those functions. The string literal may contain format specifiers from the following list. For @@ -1443,14 +1565,14 @@ including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: <enum> -<item> The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. -<item> Altered source versions must be plainly marked as such, and must not - be misrepresented as being the original software. -<item> This notice may not be removed or altered from any source - distribution. +<item> The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. +<item> Altered source versions must be plainly marked as such, and must not + be misrepresented as being the original software. +<item> This notice may not be removed or altered from any source + distribution. </enum> </article> diff --git a/doc/cl65.sgml b/doc/cl65.sgml index eef6a12a3..ca5f9d2af 100644 --- a/doc/cl65.sgml +++ b/doc/cl65.sgml @@ -2,8 +2,9 @@ <article> <title>cl65 Users Guide -<author><url url="mailto:uz@cc65.org" name="Ullrich von Bassewitz"> -<date>01.08.2000, 27.11.2000, 02.10.2001 +<author><url url="mailto:uz@cc65.org" name="Ullrich von Bassewitz">,<newline> +<url url="mailto:greg.king5@verizon.net" name="Greg King"> +<date>2017-10-16 <abstract> cl65 is the compile & link utility for cc65, the 6502 C compiler. It was @@ -50,13 +51,14 @@ Short options: -C name Use linker config file -Cl Make local variables static -D sym[=defn] Define a preprocessor symbol + -E Stop after the preprocessing stage -I dir Set a compiler include directory path -L path Specify a library search path -Ln name Create a VICE label file -O Optimize code - -Oi Optimize code, inline functions + -Oi Optimize code, inline more code -Or Optimize code, honour the register keyword - -Os Optimize code, inline known C funtions + -Os Optimize code, inline standard funtions -S Compile but don't assemble and link -T Include source as comment -V Print the version number @@ -67,6 +69,7 @@ Short options: Long options: --add-source Include source as comment + --all-cdecl Make functions default to __cdecl__ --asm-args options Pass options to the assembler --asm-define sym[=v] Define an assembler symbol --asm-include-dir dir Set an assembler include directory @@ -120,56 +123,66 @@ Long options: --------------------------------------------------------------------------- </verb></tscreen> -Most of the options have the same meaning than the corresponding compiler, -assembler or linker option. See the documentation for these tools for an +Most of the options have the same meanings as the corresponding compiler, +assembler, and linker options. See the documentation for those tools for an explanation. If an option is available for more than one of the tools, it -is set for all tools, where it is available. One example for this is <tt/-v/: -The compiler, the assembler and the linker are all called with the <tt/-v/ +is set for all tools where it is available. One example for that is <tt/-v/: +The compiler, the assembler, and the linker are all called with the <tt/-v/ switch. There are a few remaining options that control the behaviour of cl65: <descrip> + <tag><tt>-E</tt></tag> + + This option is passed to the cc65 compiler; and, it forces cl65 to stop + before the assembly step. That means that C-level preprocessor directives + are obeyed; and, macroes are expanded. But, the C source isn't compiled. + If the <tt/-o/ option isn't used, then the C code results are written into + files with a ".i" suffix on their base names. Assembler files, object + files, and libraries given on the command line are ignored. + + <tag><tt>-S</tt></tag> - This option forces cl65 to stop after the assembly step. This means that - C files are translated into assembler files, but nothing more is done. - Assembler files, object files and libraries given on the command line + This option forces cl65 to stop before the assembly step. That means that + C files are translated into assembler files; but, nothing more is done. + Assembler files, object files, and libraries given on the command line are ignored. <tag><tt>-c</tt></tag> - This options forces cl65 to stop after the assembly step. This means + This option forces cl65 to stop after the assembly step. That means that C and assembler files given on the command line are translated into - object files, but there is no link step, and object files and libraries + object files; but, there is no link step. Object files and libraries given on the command line are ignored. <tag><tt>-o name</tt></tag> - The -o option is used for the target name in the final step. This causes - problems, if the linker will not be called, and there are several input - files on the command line. In this case, the name given with -o will be + The -o option is used for the target name in the final step. That causes + problems if the linker will not be called, and there are several input + files on the command line. In that case, the name given with -o will be used for all of them, which makes the option pretty useless. You - shouldn't use -o when more than one output file is created. + shouldn't use <tt/-o/ when more than one output file is created. <tag><tt>--print-target-path</tt></tag> - This option prints the absolute path of the target file directory and exits + This option prints the absolute path of the target file directory, and exits then. It is supposed to be used with shell backquotes or the GNU make shell - function. This way you can write build scripts or Makefiles accessing target + function. That way, you can write build scripts or Makefiles accessing target files without any assumption about the cc65 installation path. <tag><tt>-t sys, --target sys</tt></tag> - The default for this option is different from the compiler and linker in the - case that the option is missing: While the other tools (compiler, assembler + The default for this option is different from the compiler and linker, in the + case that the option is missing: While the other tools (compiler, assembler, and linker) will use the "none" system settings by default, cl65 will use - the C64 as a target system by default. This was chosen since most people + "c64" as a target system by default. That was chosen because most people seem to use cc65 to develop for the C64. @@ -177,10 +190,10 @@ There are a few remaining options that control the behaviour of cl65: Pass options directly to the assembler. This may be used to pass options that aren't directly supported by cl65. Several options may be separated by - commas, the commas are replaced by spaces when passing them to the - assembler. Beware: Passing arguments directly to the assembler may interfere - with some of the defaults, because cl65 doesn't parse the options passed. So - if cl65 supports an option by itself, do not pass this option to the + commas; the commas are replaced by spaces when passing them to the + assembler. Beware: Passing arguments directly to the assembler might interfere + with some of the defaults because cl65 doesn't parse the options passed. So, + if cl65 supports an option by itself, do not pass that option to the assembler by means of the <tt/-Wa/ switch. @@ -188,10 +201,10 @@ There are a few remaining options that control the behaviour of cl65: Pass options directly to the compiler. This may be used to pass options that aren't directly supported by cl65. Several options may be separated by - commas, the commas are replaced by spaces when passing them to the - compiler. Beware: Passing arguments directly to the compiler may interfere - with some of the defaults, because cl65 doesn't parse the options passed. So - if cl65 supports an option by itself, do not pass this option to the + commas; the commas are replaced by spaces when passing them to the + compiler. Beware: Passing arguments directly to the compiler might interfere + with some of the defaults because cl65 doesn't parse the options passed. So, + if cl65 supports an option by itself, do not pass that option to the compiler by means of the <tt/-Wc/ switch. @@ -199,10 +212,10 @@ There are a few remaining options that control the behaviour of cl65: Pass options directly to the linker. This may be used to pass options that aren't directly supported by cl65. Several options may be separated by - commas, the commas are replaced by spaces when passing them to the linker. - Beware: Passing arguments directly to the linker may interfere with some of - the defaults, because cl65 doesn't parse the options passed. So if cl65 - supports an option by itself, do not pass this option to the linker by means + commas; the commas are replaced by spaces when passing them to the linker. + Beware: Passing arguments directly to the linker might interfere with some of + the defaults because cl65 doesn't parse the options passed. So, if cl65 + supports an option by itself, do not pass that option to the linker by means of the <tt/-Wl/ switch. </descrip> @@ -211,7 +224,7 @@ There are a few remaining options that control the behaviour of cl65: <sect>More usage<p> -Since cl65 was created to simplify the use of the cc65 development +Because cl65 was created to simplify the use of the cc65 development package, it tries to be smart about several things. <itemize> @@ -219,15 +232,14 @@ package, it tries to be smart about several things. <item> If you don't give a target system on the command line, cl65 defaults to the C64. -<item> When linking, cl65 will supply the names of the startup file and - library for the target system to the linker, so you don't have to do - that. +<item> When linking, cl65 will supply the name of the library file for + the target system to the linker; so, you don't have to do that. <item> If the final step is the linker, and the name of the output file was not explicitly given, cl65 will use the name of the first input file - without the extension, provided that the name of this file has an - extension. So you don't need to name the executable name in most - cases, just give the name of your "main" file as first input file. + without the extension, provided that the name of that file has an + extension. So, you don't need to give the executable name in most + cases; just give the name of your "main" file as the first input file. </itemize> The command line is parsed from left to right, and the actual processing tool @@ -248,7 +260,7 @@ The type of an input file is derived from its extension: <itemize> <item>C files: <tt/.c/ <item>Assembler files: <tt/.s/, <tt/.asm/, <tt/.a65/ -<item>Object files: <tt/.o/ <tt/.obj/ +<item>Object files: <tt/.o/, <tt/.obj/ <item>Libraries: <tt/.a/, <tt/.lib/ <item>GEOS resource files: <tt/.grc/ <item>o65 files: <tt/.o65/, <tt/.emd/, <tt/.joy/, <tt/.tgi/ diff --git a/doc/funcref.sgml b/doc/funcref.sgml index d4c2f3fe1..1d5ee7c19 100644 --- a/doc/funcref.sgml +++ b/doc/funcref.sgml @@ -2,8 +2,9 @@ <article> <title>cc65 function reference -<author><url url="mailto:uz@cc65.org" name="Ullrich von Bassewitz"> -<date>2016-08-07 +<author><url url="mailto:uz@cc65.org" name="Ullrich von Bassewitz">,<newline> +<url url="mailto:greg.king5@verizon.net" name="Greg King"> +<date>2017-09-02 <abstract> cc65 is a C compiler for 6502 based systems. This function reference describes @@ -183,6 +184,7 @@ function. <!-- <item><ref id="cbm_save" name="cbm_save"> --> <!-- <item><ref id="cbm_write" name="cbm_write"> --> <!-- <item><ref id="get_tv" name="get_tv"> --> +<item><ref id="kbrepeat" name="kbrepeat"> </itemize> (incomplete) @@ -398,6 +400,13 @@ function. (incomplete) +<sect1><tt/lz4.h/<label id="lz4.h"><p> + +<itemize> +<item><ref id="decompress_lz4" name="decompress_lz4"> +</itemize> + + <sect1><tt/modload.h/<label id="modload.h"><p> <itemize> @@ -430,7 +439,7 @@ function. <!-- <itemize> --> <!-- <item><ref id="get_tv" name="get_tv"> --> -<!-- <item><ref id="waitvblank" name="waitvblank"> --> +<!-- <item><ref id="waitvsync" name="waitvsync"> --> <!-- </itemize> --> (incomplete) @@ -2632,6 +2641,23 @@ used in presence of a prototype. </quote> +<sect1>decompress_lz4<label id="decompress_lz4"><p> + +<quote> +<descrip> +<tag/Function/Uncompress a LZ4-compressed buffer. +<tag/Header/<tt/<ref id="lz4.h" name="lz4.h">/ +<tag/Declaration/<tt/void decompress_lz4 (const unsigned char* src, unsigned char* const dst, const unsigned short uncompressed_size);/ +<tag/Description/<tt/decompress_lz4/ uncompresses a LZ4-compressed buffer. +<tag/Notes/<itemize> +<item>Use LZ4_compress_HC with compression level 16 for best compression. +</itemize> +<tag/Availability/cc65 +<tag/Example/None. +</descrip> +</quote> + + <sect1>div<label id="div"><p> <quote> @@ -3710,7 +3736,7 @@ fastcall function, so it may only be used in presence of a prototype. <quote> <descrip> -<tag/Function/Check if a given character is a a white-space character. +<tag/Function/Check if a given character is a white-space character. <tag/Header/<tt/<ref id="ctype.h" name="ctype.h">/ <tag/Declaration/<tt/int __fastcall__ isspace (int c);/ <tag/Description/The function returns a non zero value if the given argument @@ -4017,6 +4043,28 @@ do), the function is rather useless. </quote> +<sect1>kbrepeat<label id="kbrepeat"><p> + +<quote> +<descrip> +<tag/Function/Set the keyboard repeat mode. +<tag/Header/<tt/<ref id="cbm.h" name="cbm.h">/ +<tag/Declaration/<tt/unsigned char __fastcall__ kbrepeat (unsigned char mode);/ +<tag/Description/This function changes which keys have automatic repeat when +being held down for a certain time. Possible values are <tt/KBREPEAT_CURSOR/ +(repeat only cursor-related keys), <tt/KBREPEAT_NONE/ (no repeat for any +keys), and <tt/KBREPEAT_ALL/ (repeat all keys). The old mode is returned, so +it can be restored later. +<tag/Notes/<itemize> +<item>The function is available only as a fastcall function; so, it may be used +only in the presence of a prototype. +</itemize> +<tag/Availability/cc65 +<tag/Example/None. +</descrip> +</quote> + + <sect1>labs<label id="labs"><p> <quote> diff --git a/doc/ld65.sgml b/doc/ld65.sgml index 5687aa8ab..8f9dd7093 100644 --- a/doc/ld65.sgml +++ b/doc/ld65.sgml @@ -247,10 +247,11 @@ Here is a description of all of the command-line options: <tag><tt>-Ln</tt></tag> This option allows you to create a file that contains all global labels and - may be loaded into the VICE emulator using the <tt/ll/ (load label) command. You + may be loaded into the VICE emulator using the <tt/ll/ (load label) command + or into the Oricutron emulator using the <tt/sl/ (symbols load) command. You may use this to debug your code with VICE. Note: Older versions had some bugs in the label code. If you have problems, please get the latest <url - url="http://vice-emu.sourceforge.net/" name="VICE"> version. + url="http://vice-emu.sourceforge.net" name="VICE"> version. <label id="option-S"> diff --git a/doc/nes.sgml b/doc/nes.sgml index 98c25b6af..8f4374e05 100644 --- a/doc/nes.sgml +++ b/doc/nes.sgml @@ -69,8 +69,8 @@ Programs containing NES specific code may use the <tt/nes.h/ header file. <sect1>NES specific functions<p> <itemize> -<item>waitvblank - wait until the start of vblank -<item>get_tv +<item>waitvsync - wait until the start of the next frame</item> +<item>get_tv</item> </itemize> diff --git a/doc/pce.sgml b/doc/pce.sgml index 104dee526..927df8f5c 100644 --- a/doc/pce.sgml +++ b/doc/pce.sgml @@ -77,7 +77,7 @@ Programs containing PCE specific code may use the <tt/pce.h/ header file. <sect1>PCE specific functions<p> <itemize> -<item>waitvblank</item> +<item>waitvsync</item> <item>get_tv (since all PCE systems are NTSC, this always returns TV_NTSC)</item> </itemize> diff --git a/doc/supervision.sgml b/doc/supervision.sgml index 97495dea5..cf2af7967 100644 --- a/doc/supervision.sgml +++ b/doc/supervision.sgml @@ -66,7 +66,7 @@ Programs containing Supervision specific code may use the <tt/supervision.h/ hea <sect1>Supervision specific functions<p> <itemize> -<item>waitvblank +<item>waitvsync</item> </itemize> diff --git a/doc/telestrat.sgml b/doc/telestrat.sgml index 0c85c68c5..2d05f8985 100644 --- a/doc/telestrat.sgml +++ b/doc/telestrat.sgml @@ -4,13 +4,15 @@ <title>Oric Telestrat-specific information for cc65 <author> -<url url="mailto:jede@oric.org" name="Jede">,<newline> +<url url="mailto:jede@oric.org" name="Jede"> <date>2017-01-22 <abstract> + An overview over the Telestrat (Telemon 2.4 & Telemon 3.x : http://orix.oric.org) runtime system as it is implemented for the cc65 C compiler.) + </abstract> <!-- Table of contents --> @@ -32,25 +34,28 @@ information. <sect>Binary format<p> -The standard binary output format generated the linker for the Telestrat target -is a machine language program with a 20 bytes header described here : http://orix.oric.org/doku.php?id=orix:header +The standard binary output format generated the linker for the Telestrat +target is a machine language program with a 20 bytes header described <url +name="here" url="http://orix.oric.org/doku.php?id=orix:header"> -This header is used for Telemon 3.0. +This header is used for Telemon 3.0. -Anyway, for Telemon 2.4, there is no file management, there is no TAPE routine in Telemon, there is no way to load a binary easily. +Anyway, for Telemon 2.4, there is no file management, there is no TAPE routine in Telemon, there is no way to load a binary easily. -Stratsed (the Telestrat operating system) handles files management. Stratsed is loaded to memory from floppy disk. +Stratsed (the Telestrat operating system) handles files management. Stratsed is loaded to memory from floppy disk. -There is no tool to insert a binary in a Stratsed floppy disk. +There is no tool to insert a binary in a Stratsed floppy disk. -The only way to load a binary (for Telemon 2.4) is to : +The only way to load a binary (for Telemon 2.4) is to: <itemize> <item>remove the 20 bytes header -<item>download osdk : http://osdk.defence-force.org/index?page=download +<item>download <url name="osdk" url="http://osdk.defence-force.org/index?page=download"> <item>use Floppybuilder in OSDK to insert the binary with the tool (please read FloppyBuilder manual to insert your binary, and to start microdisc boot sector when Telestrat starts) </itemize> -Please note also, that the binary converted into TAP file, will not produce a right stratsed file when tap2dsk and old2mfm are used. You will be in the case that Telestrat/Stratsed crashed when you do "DIR" command. +Please note also, that the binary converted into TAP file, will not produce +a right stratsed file when tap2dsk and old2mfm are used. You will be in the +case that Telestrat/Stratsed crashed when you do "DIR" command. If you know the Stratsed disk format, please contact the author of this doc. @@ -79,7 +84,7 @@ Special locations: <sect>Platform-specific header files<p> -Programs containing Telestrat -specific code may use the <tt/telestrat.h/ header file. +Programs containing Telestrat-specific code may use the <tt/telestrat.h/ header file. <sect1>Telestrat-specific functions<p> @@ -162,8 +167,12 @@ Telestrat has a RS232 port, but it's not usable in cc65. <sect1>Disk I/O<p> -Telemon 3.0 handles fopen, fread, fclose primitives. It means that this function will crash the Telestrat because Telemon 2.4 does not have these primitives. -By the way, Telemon 3.0 uses an extension "ch376 card" which handles sdcard and FAT 32 usb key. In the next version of Telemon, FT DOS, Sedoric, Stratsed will be handled in these 3 primitives (fopen, fread, fclose). +Telemon 3.0 handles fopen, fread, fclose primitives. It means that this +function will crash the Telestrat because Telemon 2.4 does not have these +primitives. By the way, Telemon 3.0 uses an extension "ch376 card" which +handles sdcard and FAT 32 usb key. In the next version of Telemon, FT DOS, +Sedoric, Stratsed will be handled in these 3 primitives (fopen, fread, +fclose). <itemize> <item>fclose diff --git a/doc/vic20.sgml b/doc/vic20.sgml index b1a08ac83..26a4aa558 100644 --- a/doc/vic20.sgml +++ b/doc/vic20.sgml @@ -2,11 +2,11 @@ <article> -<title>Commodore VIC20 (aka VC20) specific information for cc65 +<title>Commodore VIC20 (aka VC20 aka VIC1001) specific information for cc65 <author> <url url="mailto:uz@cc65.org" name="Ullrich von Bassewitz">,<newline> <url url="mailto:polluks@sdf.lonestar.org" name="Stefan A. Haubenthal"> -<date>2014-04-12 +<date>2017-05-18 <abstract> An overview over the VIC20 runtime system as it is implemented for the cc65 C @@ -182,13 +182,14 @@ No VIC1011 drivers are currently available for the VIC20. <sect>Limitations<p> - -<sect>Other hints<p> - - <sect1>Escape code<p> -For an Esc, press CTRL and the <tt/[/ key. +The CTRL key cannot be used to type most control characters, +entering an Esc is not possible. + + + +<sect>Other hints<p> <sect1>Passing arguments to the program<p> @@ -219,8 +220,7 @@ The program return code (low byte) is passed back to BASIC by use of the <sect1>Using extended memory<p> -The extended memory at $A000 may be added to the heap by using the following -code: +BLK5 memory may be added to the heap by using the following code: <tscreen><verb> /* Check for the existence of RAM */ diff --git a/include/apple2.h b/include/apple2.h index a1b094d4d..421b5db6c 100644 --- a/include/apple2.h +++ b/include/apple2.h @@ -42,6 +42,7 @@ #endif +#include <apple2_filetype.h> /*****************************************************************************/ /* Data */ @@ -90,6 +91,14 @@ #define CH_RTEE '+' #define CH_CROSS '+' +/* Masks for joy_read */ +#define JOY_UP_MASK 0x10 +#define JOY_DOWN_MASK 0x20 +#define JOY_LEFT_MASK 0x04 +#define JOY_RIGHT_MASK 0x08 +#define JOY_BTN_1_MASK 0x40 +#define JOY_BTN_2_MASK 0x80 + /* Return codes for get_ostype */ #define APPLE_UNKNOWN 0x00 #define APPLE_II 0x10 /* Apple ][ */ @@ -136,11 +145,9 @@ extern unsigned char _dos_type; /* The file stream implementation and the POSIX I/O functions will use the -** following variables to determine the file type, aux type and creation time -** stamp to use. +** following struct to set the date and time stamp on files. This specificially +** applies to the open and fopen functions. */ -extern unsigned char _filetype; /* Default: 6 */ -extern unsigned int _auxtype; /* Default: 0 */ extern struct { struct { unsigned day :5; diff --git a/include/apple2_filetype.h b/include/apple2_filetype.h new file mode 100644 index 000000000..83a44f532 --- /dev/null +++ b/include/apple2_filetype.h @@ -0,0 +1,322 @@ +/*****************************************************************************/ +/* */ +/* apple2_filetype.h */ +/* */ +/* Apple ][ file type definitions */ +/* */ +/* */ +/* */ +/* (C) 2017 Bill Chatfield, <bill_chatfield@yahoo.com> */ +/* */ +/* */ +/* This software is provided 'as-is', without any expressed or implied */ +/* warranty. In no event will the authors be held liable for any damages */ +/* arising from the use of this software. */ +/* */ +/* Permission is granted to anyone to use this software for any purpose, */ +/* including commercial applications, and to alter it and redistribute it */ +/* freely, subject to the following restrictions: */ +/* */ +/* 1. The origin of this software must not be misrepresented; you must not */ +/* claim that you wrote the original software. If you use this software */ +/* in a product, an acknowledgment in the product documentation would be */ +/* appreciated but is not required. */ +/* 2. Altered source versions must be plainly marked as such, and must not */ +/* be misrepresented as being the original software. */ +/* 3. This notice may not be removed or altered from any source */ +/* distribution. */ +/* */ +/*****************************************************************************/ + + + +#ifndef _APPLE2_FILETYPE_H +#define _APPLE2_FILETYPE_H + + + +/* Check for errors */ +#if !defined(__APPLE2__) +# error This module may only be used when compiling for the Apple ][! +#endif + + + +/*****************************************************************************/ +/* Data */ +/*****************************************************************************/ + + + +/* ProDOS general file types */ +#define PRODOS_T_UNK 0x00 /* Unknown */ +#define PRODOS_T_BAD 0x01 /* Bad blocks */ +#define PRODOS_T_PCD 0x02 /* Pascal code */ +#define PRODOS_T_PTX 0x03 /* Pascal text */ +#define PRODOS_T_TXT 0x04 /* ASCII text */ +#define PRODOS_T_PDA 0x05 /* Pascal data */ +#define PRODOS_T_BIN 0x06 /* Binary */ +#define PRODOS_T_FNT 0x07 /* Apple III font */ +#define PRODOS_T_FOT 0x08 /* Hi-res, dbl hi-res graphics */ +#define PRODOS_T_BA3 0x09 /* Apple III BASIC program */ +#define PRODOS_T_DA3 0x09 /* Apple III BASIC data */ +#define PRODOS_T_WPF 0x0A /* Generic word processing */ +#define PRODOS_T_SOS 0x0B /* SOS system */ +#define PRODOS_T_DIR 0x0F /* ProDOS directory */ + +/* ProDOS productivity file types */ +#define PRODOS_T_RPD 0x10 /* RPS data */ +#define PRODOS_T_RPI 0x11 /* RPS index */ +#define PRODOS_T_AFD 0x12 /* AppleFile discard */ +#define PRODOS_T_AFM 0x13 /* AppleFile model */ +#define PRODOS_T_AFR 0x14 /* AppleFile report */ +#define PRODOS_T_SCL 0x15 /* Screen library */ +#define PRODOS_T_PFS 0x16 /* PFS document */ +#define PRODOS_T_ADB 0x19 /* AppleWorks database */ +#define PRODOS_T_AWP 0x1A /* AppleWorks word processing */ +#define PRODOS_T_ASP 0x1B /* AppleWorks spreadsheet */ + +/* ProDOS code file types */ +#define PRODOS_T_TDM 0x20 /* Desktop Manager */ +#define PRODOS_T_IPS 0x21 /* Instant Pascal source */ +#define PRODOS_T_UPV 0x22 /* USCD Pascal volume */ +#define PRODOS_T_3SD 0x29 /* SOS directory */ +#define PRODOS_T_8SC 0x2A /* Source code */ +#define PRODOS_T_8OB 0x2B /* Object code */ +#define PRODOS_T_8IC 0x2C /* Interpreted code */ +#define PRODOS_T_8LD 0x2D /* Language data */ +#define PRODOS_T_P8C 0x2E /* ProDOS 8 code module */ + +/* ProDOS miscellaneous file types */ +#define PRODOS_T_OCR 0x41 /* Optical char recognition */ +#define PRODOS_T_FTD 0x42 /* File type definitions */ + +/* ProDOS Apple IIgs general file types */ +#define PRODOS_T_GWP 0x50 /* Apple IIgs word processing */ +#define PRODOS_T_GSS 0x51 /* Apple IIgs spreadsheet */ +#define PRODOS_T_GDB 0x52 /* Apple IIgs database */ +#define PRODOS_T_DRW 0x53 /* Object oriented graphics */ +#define PRODOS_T_GDP 0x54 /* Apple IIgs desktop publish */ +#define PRODOS_T_HMD 0x55 /* HyperMedia */ +#define PRODOS_T_EDU 0x56 /* Educational program data */ +#define PRODOS_T_STN 0x57 /* Stationary */ +#define PRODOS_T_HLP 0x58 /* Help */ +#define PRODOS_T_COM 0x59 /* Communications */ +#define PRODOS_T_CFG 0x5A /* Configuration */ +#define PRODOS_T_ANM 0x5B /* Animation */ +#define PRODOS_T_MUM 0x5C /* Multimedia */ +#define PRODOS_T_ENT 0x5D /* Entertainment */ +#define PRODOS_T_DVU 0x5E /* Development utility */ + +/* ProDOS PC Transporter file types */ +#define PRODOS_T_PRE 0x60 /* PC pre-boot */ +#define PRODOS_T_BIO 0x6B /* PC BIOS */ +#define PRODOS_T_NCF 0x66 /* ProDOS File Nav command file */ +#define PRODOS_T_DVR 0x6D /* PC driver */ +#define PRODOS_T_PRE2 0x6E /* PC pre-boot */ +#define PRODOS_T_HDV 0x6F /* PC hard disk image */ + +/* ProDOS Kreative Software file types */ +#define PRODOS_T_SN2 0x70 /* Sabine's Notebook 2.0 */ +#define PRODOS_T_KMT 0x71 +#define PRODOS_T_DSR 0x72 +#define PRODOS_T_BAN 0x73 +#define PRODOS_T_CG7 0x74 +#define PRODOS_T_TNJ 0x75 +#define PRODOS_T_SA7 0x76 +#define PRODOS_T_KES 0x77 +#define PRODOS_T_JAP 0x78 +#define PRODOS_T_CSL 0x79 +#define PRODOS_T_TME 0x7A +#define PRODOS_T_TLB 0x7B +#define PRODOS_T_MR7 0x7C +#define PRODOS_T_MLR 0x7D /* Mika City */ +#define PRODOS_T_MMM 0x7E +#define PRODOS_T_JCP 0x7F + +/* ProDOS GEOS file types */ +#define PRODOS_T_GES 0x80 /* GEOS system file */ +#define PRODOS_T_GEA 0x81 /* GEOS desk accessory */ +#define PRODOS_T_GEO 0x82 /* GEOS application */ +#define PRODOS_T_GED 0x83 /* GEOS document */ +#define PRODOS_T_GEF 0x84 /* GEOS font */ +#define PRODOS_T_GEP 0x85 /* GEOS printer driver */ +#define PRODOS_T_GEI 0x86 /* GEOS input driver */ +#define PRODOS_T_GEX 0x87 /* GEOS auxiliary driver */ +#define PRODOS_T_GEV 0x89 /* GEOS swap file */ +#define PRODOS_T_GEC 0x8B /* GEOS clock driver */ +#define PRODOS_T_GEK 0x8C /* GEOS interface card driver */ +#define PRODOS_T_GEW 0x8D /* GEOS formatting data */ + +/* ProDOS Apple IIgs BASIC file types */ +#define PRODOS_T_WP 0xA0 /* WordPerfect */ +#define PRODOS_T_GSB 0xAB /* Apple IIgs BASIC program */ +#define PRODOS_T_TDF 0xAB /* Apple IIgs BASIC TDF */ +#define PRODOS_T_BDF 0xAB /* Apple IIgs BASIC data */ + +/* ProDOS Apple IIgs system file types */ +#define PRODOS_T_SRC 0xB0 /* Apple IIgs source code */ +#define PRODOS_T_OBJ 0xB1 /* Apple IIgs object code */ +#define PRODOS_T_LIB 0xB2 /* Apple IIgs library */ +#define PRODOS_T_S16 0xB3 /* Apple IIgs application pgm */ +#define PRODOS_T_RTL 0xB4 /* Apple IIgs runtime library */ +#define PRODOS_T_EXE 0xB5 /* Apple IIgs shell script */ +#define PRODOS_T_PIF 0xB6 /* Apple IIgs permanent init */ +#define PRODOS_T_TIF 0xB7 /* Apple IIgs temporary init */ +#define PRODOS_T_NDA 0xB8 /* Apple IIgs new desk accesry */ +#define PRODOS_T_CDA 0xB9 /* Apple IIgs classic desk aces */ +#define PRODOS_T_TOL 0xBA /* Apple IIgs tool */ +#define PRODOS_T_DRV 0xBB /* Apple IIgs device driver */ +#define PRODOS_T_LDF 0xBC /* Apple IIgs generic load file */ +#define PRODOS_T_FST 0xBD /* Apple IIgs file sys translat */ +#define PRODOS_T_DOC 0xBF /* Apple IIgs document */ + +/* ProDOS graphics file types */ +#define PRODOS_T_PNT 0xC0 /* Apple IIgs packed sup hi-res */ +#define PRODOS_T_PIC 0xC1 /* Apple IIgs super hi-res */ +#define PRODOS_T_ANI 0xC2 /* PaintWorks animation */ +#define PRODOS_T_PAL 0xC3 /* PaintWorks palette */ +#define PRODOS_T_OOG 0xC5 /* Object-oriented graphics */ +#define PRODOS_T_SCR 0xC6 /* Script */ +#define PRODOS_T_CDV 0xC7 /* Apple IIgs control panel */ +#define PRODOS_T_FON 0xC8 /* Apple IIgs font */ +#define PRODOS_T_FND 0xC9 /* Apple IIgs Finder data */ +#define PRODOS_T_ICN 0xCA /* Apple IIgs icon */ + +/* ProDOS audio file types */ +#define PRODOS_T_MUS 0xD5 /* Music */ +#define PRODOS_T_INS 0xD6 /* Instrument */ +#define PRODOS_T_MID 0xD7 /* MIDI */ +#define PRODOS_T_SND 0xD8 /* Apple IIgs audio */ +#define PRODOS_T_DBM 0xDB /* DB master document */ + +/* ProDOS miscellaneous file types */ +#define PRODOS_T_LBR 0xE0 /* Archive */ +#define PRODOS_T_ATK 0xE2 /* AppleTalk data */ +#define PRODOS_T_R16 0xEE /* EDASM 816 relocatable code */ +#define PRODOS_T_PAR 0xEF /* Pascal area */ + +/* ProDOS system file types */ +#define PRODOS_T_CMD 0xF0 /* ProDOS command file */ +#define PRODOS_T_OVL 0xF1 /* User defined 1 */ +#define PRODOS_T_UD2 0xF2 /* User defined 2 */ +#define PRODOS_T_UD3 0xF3 /* User defined 3 */ +#define PRODOS_T_UD4 0xF4 /* User defined 4 */ +#define PRODOS_T_BAT 0xF5 /* User defined 5 */ +#define PRODOS_T_UD6 0xF6 /* User defined 6 */ +#define PRODOS_T_UD7 0xF7 /* User defined 7 */ +#define PRODOS_T_PRG 0xF8 /* User defined 8 */ +#define PRODOS_T_P16 0xF9 /* ProDOS-16 system file */ +#define PRODOS_T_INT 0xFA /* Integer BASIC program */ +#define PRODOS_T_IVR 0xFB /* Integer BASIC variables */ +#define PRODOS_T_BAS 0xFC /* Applesoft BASIC program */ +#define PRODOS_T_VAR 0xFD /* Applesoft BASIC variables */ +#define PRODOS_T_REL 0xFE /* EDASM relocatable code */ +#define PRODOS_T_SYS 0xFF /* ProDOS-8 system file */ + +/* The auxiliary type of a text file specifies its record length. +** A record length of 0 indicates a sequential text file, which is +** equivalent to text files of other operating systems like MacOS +** or Windows, except that lines are delimited by carriage returns +** only. An auxiliary type value greater than 0 for a text file, +** which is the record length, indicates a random access text file +** with fixed-length lines. +*/ +#define PRODOS_AUX_T_TXT_SEQ 0x0000 /* Sequential text */ + +/* 8IC auxiliary types */ +#define PRODOS_AUX_T_8IC_APEX_PGM 0x8003 /* Apex program */ + +/* GWP auxiliary types */ +#define PRODOS_AUX_T_GWP_TEACH 0x5445 /* Teach */ +#define PRODOS_AUX_T_GWP_DELUXEWRITE 0x8001 /* DeluxeWrite */ +#define PRODOS_AUX_T_GWP_APPLEWORKS_GS 0x8010 /* AppleWorks GS */ + +/* GSS auxiliary types */ +#define PRODOS_AUX_T_GSS_APPLEWORKS_GS 0x8010 /* AppleWorks GS */ + +/* GDB auxiliary types */ +#define PRODOS_AUX_T_GDB_APPLEWORKS_GS 0x8010 /* AppleWorks GS DB */ +#define PRODOS_AUX_T_GDB_AWGS_TMPL 0x8011 /* AWGS template */ +#define PRODOS_AUX_T_GDB_GSAS 0x8013 + +/* DRW auxiliary types */ +#define PRODOS_AUX_T_DRW_OO_GRAPHICS 0x8013 /* AWGS O-O graphics */ + +/* GDP auxiliary types */ +#define PRODOS_AUX_T_GDP_GRAPHICWRITER 0x8002 /* A2gs GraphicWriter */ +#define PRODOS_AUX_T_GDP_APPLEWORKS_GS 0x8010 /* A2gs AWGS */ + +/* HMD auxiliary types */ +#define PRODOS_AUX_T_HMD_HYPERCARD_GS 0x0001 /* HyperCard GS */ +#define PRODOS_AUX_T_HMD_TUTOR_TECH 0x8001 /* Tutor-Tech */ +#define PRODOS_AUX_T_HMD_HYPERSTUDIO 0x8002 /* HyperStudio */ +#define PRODOS_AUX_T_HMD_NEXUS 0x8003 /* Nexus */ + +/* COM auxiliary types */ +#define PRODOS_AUX_T_COM_APPLEWORKS_GS 0x8003 /* AppleWorks GS */ + +/* MLR auxiliary types */ +#define PRODOS_AUX_T_MLR_SCRIPT 0x005C /* Mika City script */ +#define PRODOS_AUX_T_MLR_COLOR_TABLE 0xC7AB /* Mika City color table */ +#define PRODOS_AUX_T_MLR_CHARACTER_DEF 0xCDEF /* Mika City character def */ + +/* LDF auxiliary types */ +#define PRODOS_AUX_T_LDF_NIFTY_LIST_MOD 0x4001 /* Nifty list module */ +#define PRODOS_AUX_T_LDF_SUPER_INFO_MOD 0x4002 /* Super info module */ +#define PRODOS_AUX_T_LDF_TWILIGHT_MOD 0x4004 /* Twilight module */ +#define PRODOS_AUX_T_LDF_MARINETTI_LLM 0x4004 /* Marinetti link layer mod */ + +/* PNT auxiliary types */ +#define PRODOS_AUX_T_PNT_PK_SUPER_HIRES 0x0001 /* Packed super hi-res */ +#define PRODOS_AUX_T_PNT_APPLE_PREF 0x0002 /* Apple preferred format */ +#define PRODOS_AUX_T_PNT_PK_QUICKDRAWII 0x0003 /* Packed QuickDraw II */ + +/* PIC auxiliary types */ +#define PRODOS_AUX_T_PIC_QUICKDRAW 0x0001 /* QuickDraw image */ +#define PRODOS_AUX_T_PIC_SHIRES_3200 0x0002 /* Super hi-res 3200 */ + +/* FON auxiliary types */ +#define PRODOS_AUX_T_FON_QUICKDRAW_BIT 0x0000 /* QuickDraw bitmap font */ +#define PRODOS_AUX_T_FON_POINTLESS_TT 0x0001 /* Pointless TrueType font */ + +/* SND auxiliary types */ +#define PRODOS_AUX_T_SND_AIFF 0x0000 /* AIFF */ +#define PRODOS_AUX_T_SND_AIFF_C 0x0001 /* AIFF-C */ +#define PRODOS_AUX_T_SND_ASIF_INSTR 0x0002 /* ASIF instrument */ +#define PRODOS_AUX_T_SND_SOUND_RSRC 0x0003 /* Sound resource */ +#define PRODOS_AUX_T_SND_MIDI_SYNTH_WAV 0x0004 /* MIDI synth wave */ +#define PRODOS_AUX_T_SND_HYPERSTUDIO 0x8001 /* HyperStudio sound */ + +/* LBR auxiliary types */ +#define PRODOS_AUX_T_LBR_ALU 0x0000 /* ALU */ +#define PRODOS_AUX_T_LBR_APPLE_SINGLE 0x0001 /* AppleSingle */ +#define PRODOS_AUX_T_LBR_APPLEDBL_HDR 0x0002 /* AppleDouble header */ +#define PRODOS_AUX_T_LBR_APPLEDBL_DATA 0x0003 /* AppleDouble data */ +#define PRODOS_AUX_T_LBR_BINARY_II 0x8000 /* Binary II */ +#define PRODOS_AUX_T_LBR_APPLELINK_ACU 0x8001 /* AppleLink ACU */ +#define PRODOS_AUX_T_LBR_SHRINKIT 0x8002 /* ShrinkIt */ + +/* LBR auxiliary types */ +#define PRODOS_AUX_T_ATK_EASYMNT_ALIAS 0x0000 /* EasyMount alias */ + +/* BAS auxiliary types */ +#define PRODOS_AUX_T_BAS_PGM_LOAD_ADDR 0x0801 /* Applesoft pgm load addr */ + + + +/*****************************************************************************/ +/* Variables */ +/*****************************************************************************/ + + + +/* The file stream implementation and the POSIX I/O functions will use the +** following variables to determine the file type and auxiliary type to use. +** This applies specifically to the fopen and open functions. +*/ +extern unsigned char _filetype; /* Default: PRODOS_T_BIN */ +extern unsigned int _auxtype; /* Default: 0 */ + +/* End of apple2_filetype.h */ +#endif diff --git a/include/atari.h b/include/atari.h index fa99fca20..bf1af7d7b 100644 --- a/include/atari.h +++ b/include/atari.h @@ -149,6 +149,16 @@ #define TGI_COLOR_LIGHTBLUE COLOR_LIGHTBLUE #define TGI_COLOR_GRAY3 COLOR_GRAY3 +/* Masks for joy_read */ +#define JOY_UP_MASK 0x01 +#define JOY_DOWN_MASK 0x02 +#define JOY_LEFT_MASK 0x04 +#define JOY_RIGHT_MASK 0x08 +#define JOY_BTN_1_MASK 0x10 + +#define JOY_FIRE_MASK JOY_BTN_1_MASK +#define JOY_FIRE(v) ((v) & JOY_FIRE_MASK) + /* color register functions */ extern void __fastcall__ _setcolor (unsigned char color_reg, unsigned char hue, unsigned char luminace); extern void __fastcall__ _setcolor_low (unsigned char color_reg, unsigned char color_value); @@ -346,4 +356,4 @@ struct __iocb { #define IOCB_FORMAT 0xFE /* format */ /* End of atari.h */ -#endif /* #ifndef _ATARI_H */ +#endif diff --git a/include/atari5200.h b/include/atari5200.h index 4bd5bc0fd..12c2bb349 100644 --- a/include/atari5200.h +++ b/include/atari5200.h @@ -87,6 +87,13 @@ extern void atr5200std_joy[]; /* referred to by joy_static_stddrv[] */ #define COLOR_LIGHTBLUE _gtia_mkcolor(HUE_BLUE,6) #define COLOR_GRAY3 _gtia_mkcolor(HUE_GREY,5) +/* Masks for joy_read */ +#define JOY_UP_MASK 0x01 +#define JOY_DOWN_MASK 0x02 +#define JOY_LEFT_MASK 0x04 +#define JOY_RIGHT_MASK 0x08 +#define JOY_BTN_1_MASK 0x10 + /* get_tv return values */ #define AT_NTSC 0 #define AT_PAL 1 @@ -104,4 +111,4 @@ extern void atr5200std_joy[]; /* referred to by joy_static_stddrv[] */ #define ANTIC (*(struct __antic*)0xD400) /* End of atari5200.h */ -#endif /* #ifndef _ATARI5200_H */ +#endif diff --git a/include/atmos.h b/include/atmos.h index 72388c974..c642f9e2a 100644 --- a/include/atmos.h +++ b/include/atmos.h @@ -113,6 +113,15 @@ +/* Masks for joy_read */ +#define JOY_UP_MASK 0x10 +#define JOY_DOWN_MASK 0x08 +#define JOY_LEFT_MASK 0x01 +#define JOY_RIGHT_MASK 0x02 +#define JOY_BTN_1_MASK 0x20 + + + /* No support for dynamically loadable drivers */ #define DYN_DRV 0 diff --git a/include/c128.h b/include/c128.h index 565fbc9ce..356140d41 100644 --- a/include/c128.h +++ b/include/c128.h @@ -91,6 +91,13 @@ #define TGI_COLOR_LIGHTBLUE COLOR_LIGHTBLUE #define TGI_COLOR_GRAY3 COLOR_GRAY3 +/* Masks for joy_read */ +#define JOY_UP_MASK 0x01 +#define JOY_DOWN_MASK 0x02 +#define JOY_LEFT_MASK 0x04 +#define JOY_RIGHT_MASK 0x08 +#define JOY_BTN_1_MASK 0x10 + /* Video mode defines */ #define VIDEOMODE_40x25 0x00 #define VIDEOMODE_80x25 0x80 diff --git a/include/c64.h b/include/c64.h index adf3840b9..eb10600d6 100644 --- a/include/c64.h +++ b/include/c64.h @@ -99,6 +99,13 @@ #define TGI_COLOR_LIGHTBLUE COLOR_LIGHTBLUE #define TGI_COLOR_GRAY3 COLOR_GRAY3 +/* Masks for joy_read */ +#define JOY_UP_MASK 0x01 +#define JOY_DOWN_MASK 0x02 +#define JOY_LEFT_MASK 0x04 +#define JOY_RIGHT_MASK 0x08 +#define JOY_BTN_1_MASK 0x10 + /* Define hardware */ #include <_vic2.h> #define VIC (*(struct __vic2*)0xD000) diff --git a/include/cbm.h b/include/cbm.h index 241d70a6e..a4b232406 100644 --- a/include/cbm.h +++ b/include/cbm.h @@ -75,6 +75,11 @@ +#define JOY_FIRE_MASK JOY_BTN_1_MASK +#define JOY_FIRE(v) ((v) & JOY_FIRE_MASK) + + + /*****************************************************************************/ /* Variables */ /*****************************************************************************/ @@ -153,7 +158,17 @@ struct cbm_dirent { unsigned char get_tv (void); /* Return the video mode the machine is using. */ +#define KBREPEAT_CURSOR 0x00 +#define KBREPEAT_NONE 0x40 +#define KBREPEAT_ALL 0x80 +unsigned char __fastcall__ kbrepeat (unsigned char mode); +/* Changes which keys have automatic repeat. */ + +#if !defined(__CBM610__) && !defined(__PET__) +void waitvsync (void); +/* Wait for the start of the next frame */ +#endif /*****************************************************************************/ /* CBM kernal functions */ diff --git a/include/cbm264.h b/include/cbm264.h index ff7468d30..46fa64050 100644 --- a/include/cbm264.h +++ b/include/cbm264.h @@ -112,6 +112,17 @@ #define COLOR_LIGHTBLUE (BCOLOR_LIGHTBLUE | CATTR_LUMA7) #define COLOR_GRAY3 (BCOLOR_WHITE | CATTR_LUMA5) + + +/* Masks for joy_read */ +#define JOY_UP_MASK 0x01 +#define JOY_DOWN_MASK 0x02 +#define JOY_LEFT_MASK 0x04 +#define JOY_RIGHT_MASK 0x08 +#define JOY_BTN_1_MASK 0x80 + + + /* Define hardware */ #include <_ted.h> #define TED (*(struct __ted*)0xFF00) diff --git a/include/cbm510.h b/include/cbm510.h index 25ea07540..3d6ccd209 100644 --- a/include/cbm510.h +++ b/include/cbm510.h @@ -92,6 +92,13 @@ #define COLOR_LIGHTBLUE 0x0E #define COLOR_GRAY3 0x0F +/* Masks for joy_read */ +#define JOY_UP_MASK 0x01 +#define JOY_DOWN_MASK 0x02 +#define JOY_LEFT_MASK 0x04 +#define JOY_RIGHT_MASK 0x08 +#define JOY_BTN_1_MASK 0x10 + /* Define hardware */ #include <_vic2.h> #define VIC (*(struct __vic2*)0xD800) diff --git a/include/conio.h b/include/conio.h index 9eb68e565..baf55dd08 100644 --- a/include/conio.h +++ b/include/conio.h @@ -63,12 +63,16 @@ # include <apple2enh.h> #elif defined(__APPLE2__) # include <apple2.h> +#elif defined(__ATARI5200__) +# include <atari5200.h> #elif defined(__ATARI__) # include <atari.h> #elif defined(__ATMOS__) # include <atmos.h> #elif defined(__CBM__) # include <cbm.h> +#elif defined(__CREATIVISION__) +# include <creativision.h> #elif defined(__GAMATE__) # include <gamate.h> #elif defined(__GEOS__) @@ -225,6 +229,3 @@ void __fastcall__ cputhex16 (unsigned val); /* End of conio.h */ #endif - - - diff --git a/include/creativision.h b/include/creativision.h index 5cc99b7af..a97109029 100644 --- a/include/creativision.h +++ b/include/creativision.h @@ -40,6 +40,14 @@ #define CH_LLCORNER 37 #define CH_LRCORNER 38 +/* Masks for joy_read */ +#define JOY_UP_MASK 0x10 +#define JOY_DOWN_MASK 0x04 +#define JOY_LEFT_MASK 0x20 +#define JOY_RIGHT_MASK 0x08 +#define JOY_BTN_1_MASK 0x01 +#define JOY_BTN_2_MASK 0x02 + /* no support for dynamically loadable drivers */ #define DYN_DRV 0 diff --git a/include/ctype.h b/include/ctype.h index b440bfb70..17cbafe9f 100644 --- a/include/ctype.h +++ b/include/ctype.h @@ -89,9 +89,9 @@ unsigned char __fastcall__ toascii (unsigned char c); ** #undef'ing the macroes. ** Please note that the following macroes do NOT handle EOF correctly, as ** stated in the manual. If you need correct behaviour for EOF, don't -** use -Os, or #undefine the following macroes. +** use --eagerly-inline-funcs, or #undefine the following macroes. */ -#ifdef __OPT_s__ +#ifdef __EAGERLY_INLINE_FUNCS__ #define isalnum(c) (__AX__ = (c), \ __asm__ ("tay"), \ diff --git a/include/em/em-kernel.h b/include/em/em-kernel.h index e5df80321..ffc6e131a 100644 --- a/include/em/em-kernel.h +++ b/include/em/em-kernel.h @@ -52,6 +52,7 @@ typedef struct { /* Driver header */ char id[3]; /* Contains 0x65, 0x6d, 0x64 ("emd") */ unsigned char version; /* Interface version */ + void* libreference; /* Library reference */ /* Jump vectors. Note that these are not C callable */ void* install; /* INSTALL routine */ @@ -74,6 +75,3 @@ extern em_drv_header* em_drv; /* Pointer to driver */ /* End of em-kernel.h */ #endif - - - diff --git a/include/gamate.h b/include/gamate.h index 82bca08b1..0af21623d 100644 --- a/include/gamate.h +++ b/include/gamate.h @@ -80,17 +80,6 @@ bit 3: */ -#define JOY_DATA 0x4400 - -#define JOY_DATA_UP 0x01 -#define JOY_DATA_DOWN 0x02 -#define JOY_DATA_LEFT 0x04 -#define JOY_DATA_RIGHT 0x08 -#define JOY_DATA_FIRE_A 0x10 -#define JOY_DATA_FIRE_B 0x20 -#define JOY_DATA_START 0x40 -#define JOY_DATA_SELECT 0x80 - /* LCD resolution 160x152 in 4 greys/greens @@ -181,15 +170,31 @@ /* No support for dynamically loadable drivers */ #define DYN_DRV 0 +/* Masks for joy_read */ +#define JOY_UP_MASK 0x01 +#define JOY_DOWN_MASK 0x02 +#define JOY_LEFT_MASK 0x04 +#define JOY_RIGHT_MASK 0x08 +#define JOY_BTN_1_MASK 0x10 +#define JOY_BTN_2_MASK 0x20 +#define JOY_BTN_3_MASK 0x40 +#define JOY_BTN_4_MASK 0x80 + +#define JOY_BTN_A_MASK JOY_BTN_1_MASK +#define JOY_BTN_B_MASk JOY_BTN_2_MASK +#define JOY_START_MASK JOY_BTN_3_MASK +#define JOY_SELECT_MASK JOY_BTN_4_MASK + +#define JOY_BTN_A(v) ((v) & JOY_BTN_A_MASK) +#define JOY_BTN_B(v) ((v) & JOY_BTN_B_MASK) +#define JOY_START(v) ((v) & JOY_START_MASK) +#define JOY_SELECT(v) ((v) & JOY_SELECT_MASK) + /* The addresses of the static drivers */ extern void gamate_stdjoy_joy[]; /* Referred to by joy_static_stddrv[] */ -#define JOY_FIRE_B 5 -#define JOY_START 6 -#define JOY_SELECT 7 - -void waitvblank (void); -/* Wait for the vertical blanking */ +void waitvsync (void); +/* Wait for start of next frame */ /* NOTE: all Gamate are "NTSC" */ #define get_tv() TV_NTSC diff --git a/include/geos.h b/include/geos.h index 65b85cd59..ae356d679 100644 --- a/include/geos.h +++ b/include/geos.h @@ -133,6 +133,12 @@ #define TGI_COLOR_LIGHTBLUE COLOR_LIGHTBLUE #define TGI_COLOR_GRAY3 COLOR_GRAY3 +#define JOY_UP_MASK 0x01 +#define JOY_DOWN_MASK 0x02 +#define JOY_LEFT_MASK 0x04 +#define JOY_RIGHT_MASK 0x08 +#define JOY_BTN_1_MASK 0x10 + /* End of geos.h */ #endif diff --git a/include/joystick.h b/include/joystick.h index 710d9b5a6..26f339fe4 100644 --- a/include/joystick.h +++ b/include/joystick.h @@ -52,27 +52,18 @@ #define JOY_ERR_NO_DEVICE 4 /* Device (hardware) not found */ /* Argument for the joy_read function */ -#define JOY_1 0 -#define JOY_2 1 - -/* The following codes are *indices* into the joy_masks array */ -#define JOY_UP 0 -#define JOY_DOWN 1 -#define JOY_LEFT 2 -#define JOY_RIGHT 3 -#define JOY_FIRE 4 -#define JOY_FIRE2 5 /* Second fire button if available */ - -/* Array of masks used to check the return value of joy_read for a state */ -extern const unsigned char joy_masks[8]; +#define JOY_1 0 +#define JOY_2 1 /* Macros that evaluate the return code of joy_read */ -#define JOY_BTN_UP(v) ((v) & joy_masks[JOY_UP]) -#define JOY_BTN_DOWN(v) ((v) & joy_masks[JOY_DOWN]) -#define JOY_BTN_LEFT(v) ((v) & joy_masks[JOY_LEFT]) -#define JOY_BTN_RIGHT(v) ((v) & joy_masks[JOY_RIGHT]) -#define JOY_BTN_FIRE(v) ((v) & joy_masks[JOY_FIRE]) -#define JOY_BTN_FIRE2(v) ((v) & joy_masks[JOY_FIRE2]) +#define JOY_UP(v) ((v) & JOY_UP_MASK) +#define JOY_DOWN(v) ((v) & JOY_DOWN_MASK) +#define JOY_LEFT(v) ((v) & JOY_LEFT_MASK) +#define JOY_RIGHT(v) ((v) & JOY_RIGHT_MASK) +#define JOY_BTN_1(v) ((v) & JOY_BTN_1_MASK) /* Universally available */ +#define JOY_BTN_2(v) ((v) & JOY_BTN_2_MASK) /* Second button if available */ +#define JOY_BTN_3(v) ((v) & JOY_BTN_3_MASK) /* Third button if available */ +#define JOY_BTN_4(v) ((v) & JOY_BTN_4_MASK) /* Fourth button if available */ /* The name of the standard joystick driver for a platform */ extern const char joy_stddrv[]; diff --git a/include/joystick/joy-kernel.h b/include/joystick/joy-kernel.h index bb571de3d..e984291f7 100644 --- a/include/joystick/joy-kernel.h +++ b/include/joystick/joy-kernel.h @@ -52,9 +52,7 @@ typedef struct { /* Driver header */ char id[3]; /* Contains 0x6a, 0x6f, 0x79 ("joy") */ unsigned char version; /* Interface version */ - - /* Bitmasks for the joystick states. See joystick.h for indices */ - unsigned char masks[8]; + void* libreference; /* Library reference */ /* Jump vectors. Note that these are not C callable */ void* install; /* INSTALL routine */ @@ -85,6 +83,3 @@ void joy_clear_ptr (void); /* End of joy-kernel.h */ #endif - - - diff --git a/include/lynx.h b/include/lynx.h index 72f3d5bfd..3629f322e 100644 --- a/include/lynx.h +++ b/include/lynx.h @@ -87,6 +87,20 @@ #define TGI_COLOR_LIGHTBLUE COLOR_LIGHTBLUE #define TGI_COLOR_WHITE COLOR_WHITE +/* Masks for joy_read */ +#define JOY_UP_MASK 0x80 +#define JOY_DOWN_MASK 0x40 +#define JOY_LEFT_MASK 0x20 +#define JOY_RIGHT_MASK 0x10 +#define JOY_BTN_1_MASK 0x01 +#define JOY_BTN_2_MASK 0x02 + +#define JOY_BTN_A_MASK JOY_BTN_1_MASK +#define JOY_BTN_B_MASK JOY_BTN_2_MASK + +#define JOY_BTN_A(v) ((v) & JOY_BTN_A_MASK) +#define JOY_BTN_B(v) ((v) & JOY_BTN_B_MASK) + /* No support for dynamically loadable drivers */ #define DYN_DRV 0 diff --git a/include/lz4.h b/include/lz4.h new file mode 100644 index 000000000..fd11c3e2a --- /dev/null +++ b/include/lz4.h @@ -0,0 +1,43 @@ +/*****************************************************************************/ +/* */ +/* lz4.h */ +/* */ +/* Decompression routine for the 'lz4' format */ +/* */ +/* */ +/* */ +/* (C) 2017 Mega Cat Studios */ +/* */ +/* This software is provided 'as-is', without any expressed or implied */ +/* warranty. In no event will the authors be held liable for any damages */ +/* arising from the use of this software. */ +/* */ +/* Permission is granted to anyone to use this software for any purpose, */ +/* including commercial applications, and to alter it and redistribute it */ +/* freely, subject to the following restrictions: */ +/* */ +/* 1. The origin of this software must not be misrepresented; you must not */ +/* claim that you wrote the original software. If you use this software */ +/* in a product, an acknowledgment in the product documentation would be */ +/* appreciated but is not required. */ +/* 2. Altered source versions must be plainly marked as such, and must not */ +/* be misrepresented as being the original software. */ +/* 3. This notice may not be removed or altered from any source */ +/* distribution. */ +/* */ +/*****************************************************************************/ + + + +#ifndef _LZ4_H +#define _LZ4_H + +void __fastcall__ decompress_lz4 (const unsigned char* src, unsigned char* const dst, + const unsigned short uncompressed_size); +/* Decompresses the source buffer into the destination buffer. +** The size of the decompressed data must be known in advance, LZ4 +** does not include any terminator in-stream. +*/ + +/* end of lz4.h */ +#endif diff --git a/include/nes.h b/include/nes.h index a472a0f3c..217a90779 100644 --- a/include/nes.h +++ b/include/nes.h @@ -82,6 +82,26 @@ #define COLOR_LIGHTBLUE 0x0E #define COLOR_GRAY3 0x0F +/* Masks for joy_read */ +#define JOY_UP_MASK 0x10 +#define JOY_DOWN_MASK 0x20 +#define JOY_LEFT_MASK 0x40 +#define JOY_RIGHT_MASK 0x80 +#define JOY_BTN_1_MASK 0x01 +#define JOY_BTN_2_MASK 0x02 +#define JOY_BTN_3_MASK 0x04 +#define JOY_BTN_4_MASK 0x08 + +#define JOY_BTN_A_MASK JOY_BTN_1_MASK +#define JOY_BTN_B_MASK JOY_BTN_2_MASK +#define JOY_SELECT_MASK JOY_BTN_3_MASK +#define JOY_START_MASK JOY_BTN_4_MASK + +#define JOY_BTN_A(v) ((v) & JOY_BTN_A_MASK) +#define JOY_BTN_B(v) ((v) & JOY_BTN_B_MASK) +#define JOY_SELECT(v) ((v) & JOY_SELECT_MASK) +#define JOY_START(v) ((v) & JOY_START_MASK) + /* Return codes of get_tv */ #define TV_NTSC 0 #define TV_PAL 1 @@ -90,16 +110,6 @@ /* No support for dynamically loadable drivers */ #define DYN_DRV 0 -/* The joystick keys - all keys are supported */ -#define KEY_A 0x01 -#define KEY_B 0x02 -#define KEY_SELECT 0x04 -#define KEY_START 0x08 -#define KEY_UP 0x10 -#define KEY_DOWN 0x20 -#define KEY_LEFT 0x40 -#define KEY_RIGHT 0x80 - /* Define hardware */ /* Picture Processing Unit */ @@ -163,8 +173,8 @@ extern void nes_64_56_2_tgi[]; /* Referred to by tgi_static_stddrv[] */ -void waitvblank (void); -/* Wait for the vertical blanking */ +void waitvsync (void); +/* Wait for start of the next frame */ unsigned char get_tv (void); /* Return the video mode the machine is using. */ diff --git a/include/osic1p.h b/include/osic1p.h index 57fe0cd24..d6ab5fee1 100644 --- a/include/osic1p.h +++ b/include/osic1p.h @@ -1,47 +1,47 @@ -/*****************************************************************************/ -/* */ -/* osic1p.h */ -/* */ -/* Challenger 1P system specific definitions */ -/* */ -/* */ -/* */ -/* (C) 2015 Stephan Muehlstrasser */ -/* */ -/* */ -/* This software is provided 'as-is', without any expressed or implied */ -/* warranty. In no event will the authors be held liable for any damages */ -/* arising from the use of this software. */ -/* */ -/* Permission is granted to anyone to use this software for any purpose, */ -/* including commercial applications, and to alter it and redistribute it */ -/* freely, subject to the following restrictions: */ -/* */ -/* 1. The origin of this software must not be misrepresented; you must not */ -/* claim that you wrote the original software. If you use this software */ -/* in a product, an acknowledgment in the product documentation would be */ -/* appreciated but is not required. */ -/* 2. Altered source versions must be plainly marked as such, and must not */ -/* be misrepresented as being the original software. */ -/* 3. This notice may not be removed or altered from any source */ -/* distribution. */ -/* */ -/*****************************************************************************/ - -#ifndef _OSIC1P_H -#define _OSIC1P_H - -/* Check for errors */ -#if !defined(__OSIC1P__) -# error "This module may only be used when compiling for the Challenger 1P!" -#endif - -/* The following #defines will cause the matching functions calls in conio.h -** to be overlaid by macros with the same names, saving the function call -** overhead. -*/ -#define _textcolor(color) COLOR_WHITE -#define _bgcolor(color) COLOR_BLACK -#define _bordercolor(color) COLOR_BLACK - -#endif +/*****************************************************************************/ +/* */ +/* osic1p.h */ +/* */ +/* Challenger 1P system specific definitions */ +/* */ +/* */ +/* */ +/* (C) 2015 Stephan Muehlstrasser */ +/* */ +/* */ +/* This software is provided 'as-is', without any expressed or implied */ +/* warranty. In no event will the authors be held liable for any damages */ +/* arising from the use of this software. */ +/* */ +/* Permission is granted to anyone to use this software for any purpose, */ +/* including commercial applications, and to alter it and redistribute it */ +/* freely, subject to the following restrictions: */ +/* */ +/* 1. The origin of this software must not be misrepresented; you must not */ +/* claim that you wrote the original software. If you use this software */ +/* in a product, an acknowledgment in the product documentation would be */ +/* appreciated but is not required. */ +/* 2. Altered source versions must be plainly marked as such, and must not */ +/* be misrepresented as being the original software. */ +/* 3. This notice may not be removed or altered from any source */ +/* distribution. */ +/* */ +/*****************************************************************************/ + +#ifndef _OSIC1P_H +#define _OSIC1P_H + +/* Check for errors */ +#if !defined(__OSIC1P__) +# error "This module may only be used when compiling for the Challenger 1P!" +#endif + +/* The following #defines will cause the matching functions calls in conio.h +** to be overlaid by macros with the same names, saving the function call +** overhead. +*/ +#define _textcolor(color) COLOR_WHITE +#define _bgcolor(color) COLOR_BLACK +#define _bordercolor(color) COLOR_BLACK + +#endif diff --git a/include/pce.h b/include/pce.h index 7700654c8..7744d0148 100644 --- a/include/pce.h +++ b/include/pce.h @@ -73,18 +73,34 @@ #define TV_PAL 1 #define TV_OTHER 2 +/* Masks for joy_read */ +#define JOY_UP_MASK 0x10 +#define JOY_DOWN_MASK 0x40 +#define JOY_LEFT_MASK 0x80 +#define JOY_RIGHT_MASK 0x20 +#define JOY_BTN_1_MASK 0x01 +#define JOY_BTN_2_MASK 0x02 +#define JOY_BTN_3_MASK 0x04 +#define JOY_BTN_4_MASK 0x08 + +#define JOY_BTN_I_MASK JOY_BTN_1_MASK +#define JOY_BTN_II_MASK JOY_BTN_2_MASK +#define JOY_SELECT_MASK JOY_BTN_3_MASK +#define JOY_RUN_MASK JOY_BTN_4_MASK + +#define JOY_BTN_I(v) ((v) & JOY_BTN_I_MASK) +#define JOY_BTN_II(v) ((v) & JOY_BTN_II_MASK) +#define JOY_SELECT(v) ((v) & JOY_SELECT_MASK) +#define JOY_RUN(v) ((v) & JOY_RUN_MASK) + /* No support for dynamically loadable drivers */ -#define DYN_DRV 0 +#define DYN_DRV 0 /* The addresses of the static drivers */ extern void pce_stdjoy_joy[]; /* Referred to by joy_static_stddrv[] */ -#define JOY_FIRE_B 5 -#define JOY_SELECT 6 -#define JOY_RUN 7 - -void waitvblank (void); -/* Wait for the vertical blanking */ +void waitvsync (void); +/* Wait for start of the next frame */ /* NOTE: all PCE are NTSC */ #define get_tv() TV_NTSC diff --git a/include/pet.h b/include/pet.h index 720e40a78..e9659d524 100644 --- a/include/pet.h +++ b/include/pet.h @@ -55,6 +55,13 @@ #define COLOR_BLACK 0x00 #define COLOR_WHITE 0x01 +/* Masks for joy_read */ +#define JOY_UP_MASK 0x01 +#define JOY_DOWN_MASK 0x02 +#define JOY_LEFT_MASK 0x04 +#define JOY_RIGHT_MASK 0x08 +#define JOY_BTN_1_MASK 0x10 + /* Define hardware */ #include <_pia.h> #define PIA1 (*(struct __pia*)0xE810) diff --git a/include/vic20.h b/include/vic20.h index c675de6d2..c6ad9632d 100644 --- a/include/vic20.h +++ b/include/vic20.h @@ -77,6 +77,15 @@ +/* Masks for joy_read */ +#define JOY_UP_MASK 0x01 +#define JOY_DOWN_MASK 0x02 +#define JOY_LEFT_MASK 0x04 +#define JOY_RIGHT_MASK 0x08 +#define JOY_BTN_1_MASK 0x10 + + + /* Define hardware */ #include <_vic.h> #define VIC (*(struct __vic*)0x9000) diff --git a/include/zlib.h b/include/zlib.h index 8fa6a2bd1..8ced89800 100644 --- a/include/zlib.h +++ b/include/zlib.h @@ -1,172 +1,172 @@ -/*****************************************************************************/ -/* */ -/* zlib.h */ -/* */ -/* Decompression routines for the 'deflate' format */ -/* */ -/* */ -/* */ -/* (C) 2000-2015 Piotr Fusik <fox@scene.pl> */ -/* */ -/* This file is based on the zlib.h from 'zlib' general purpose compression */ -/* library, version 1.1.3, (C) 1995-1998 Jean-loup Gailly and Mark Adler. */ -/* */ -/* Jean-loup Gailly Mark Adler */ -/* jloup@gzip.org madler@alumni.caltech.edu */ -/* */ -/* This software is provided 'as-is', without any expressed or implied */ -/* warranty. In no event will the authors be held liable for any damages */ -/* arising from the use of this software. */ -/* */ -/* Permission is granted to anyone to use this software for any purpose, */ -/* including commercial applications, and to alter it and redistribute it */ -/* freely, subject to the following restrictions: */ -/* */ -/* 1. The origin of this software must not be misrepresented; you must not */ -/* claim that you wrote the original software. If you use this software */ -/* in a product, an acknowledgment in the product documentation would be */ -/* appreciated but is not required. */ -/* 2. Altered source versions must be plainly marked as such, and must not */ -/* be misrepresented as being the original software. */ -/* 3. This notice may not be removed or altered from any source */ -/* distribution. */ -/* */ -/*****************************************************************************/ - - - -#ifndef _ZLIB_H -#define _ZLIB_H - -#define Z_OK 0 -#define Z_DATA_ERROR (-3) -/* Return codes for uncompress() */ - -#define Z_DEFLATED 8 -/* The deflate compression method (the only one supported) */ - -#define Z_NULL 0 - - -unsigned __fastcall__ inflatemem (char* dest, const char* source); -/* - Decompresses the source buffer into the destination buffer. - Returns the size of the uncompressed data (number of bytes written starting - from dest). - - This function expects data in the DEFLATE format, described in RFC - (Request for Comments) 1951 in the file - ftp://ds.internic.net/rfc/rfc1951.txt. - - This function does not exist in the original zlib. Its implementation - using original zlib might be following: - - unsigned inflatemem (char* dest, const char* source) - { - z_stream stream; - - stream.next_in = (Bytef*) source; - stream.avail_in = 65535; - - stream.next_out = dest; - stream.avail_out = 65535; - - stream.zalloc = (alloc_func) 0; - stream.zfree = (free_func) 0; - - inflateInit2(&stream, -MAX_WBITS); - inflate(&stream, Z_FINISH); - inflateEnd(&stream); - - return stream.total_out; - } -*/ - - -int __fastcall__ uncompress (char* dest, unsigned* destLen, - const char* source, unsigned sourceLen); -/* - Original zlib description: - - Decompresses the source buffer into the destination buffer. sourceLen is - the byte length of the source buffer. Upon entry, destLen is the total - size of the destination buffer, which must be large enough to hold the - entire uncompressed data. (The size of the uncompressed data must have - been saved previously by the compressor and transmitted to the decompressor - by some mechanism outside the scope of this compression library.) - Upon exit, destLen is the actual size of the compressed buffer. - This function can be used to decompress a whole file at once if the - input file is mmap'ed. - - uncompress returns Z_OK if success, Z_MEM_ERROR if there was not - enough memory, Z_BUF_ERROR if there was not enough room in the output - buffer, or Z_DATA_ERROR if the input data was corrupted. - - Implementation notes: - - This function expects data in the ZLIB format, described in RFC 1950 - in the file ftp://ds.internic.net/rfc/rfc1950.txt. The ZLIB format is - essentially the DEFLATE format plus a very small header and Adler-32 - checksum. - - Z_MEM_ERROR and Z_BUF_ERROR are never returned in this implementation. -*/ - - -unsigned long __fastcall__ adler32 (unsigned long adler, const char* buf, - unsigned len); - -/* - Original zlib description: - - Update a running Adler-32 checksum with the bytes buf[0..len-1] and - return the updated checksum. If buf is NULL, this function returns - the required initial value for the checksum. - An Adler-32 checksum is almost as reliable as a CRC32 but can be computed - much faster. Usage example: - - unsigned long adler = adler32(0L, Z_NULL, 0); - - while (read_buffer(buffer, length) != EOF) { - adler = adler32(adler, buffer, length); - } - if (adler != original_adler) error(); - - Implementation notes: - - This function isn't actually much faster than crc32(), but it is smaller - and does not use any lookup tables. -*/ - - -unsigned long __fastcall__ crc32 (unsigned long crc, const char* buf, - unsigned len); -/* - Original zlib description: - - Update a running crc with the bytes buf[0..len-1] and return the updated - crc. If buf is NULL, this function returns the required initial value - for the crc. Pre- and post-conditioning (one's complement) is performed - within this function so it shouldn't be done by the application. - Usage example: - - unsigned long crc = crc32(0L, Z_NULL, 0); - - while (read_buffer(buffer, length) != EOF) { - crc = crc32(crc, buffer, length); - } - if (crc != original_crc) error(); - - Implementation notes: - - This function uses statically allocated 1 KB lookup table. The table is - initialised before it is used for the first time (that is, if buffer is - NULL or length is zero, then the lookup table isn't initialised). -*/ - - -/* end of zlib.h */ -#endif - - - +/*****************************************************************************/ +/* */ +/* zlib.h */ +/* */ +/* Decompression routines for the 'deflate' format */ +/* */ +/* */ +/* */ +/* (C) 2000-2015 Piotr Fusik <fox@scene.pl> */ +/* */ +/* This file is based on the zlib.h from 'zlib' general purpose compression */ +/* library, version 1.1.3, (C) 1995-1998 Jean-loup Gailly and Mark Adler. */ +/* */ +/* Jean-loup Gailly Mark Adler */ +/* jloup@gzip.org madler@alumni.caltech.edu */ +/* */ +/* This software is provided 'as-is', without any expressed or implied */ +/* warranty. In no event will the authors be held liable for any damages */ +/* arising from the use of this software. */ +/* */ +/* Permission is granted to anyone to use this software for any purpose, */ +/* including commercial applications, and to alter it and redistribute it */ +/* freely, subject to the following restrictions: */ +/* */ +/* 1. The origin of this software must not be misrepresented; you must not */ +/* claim that you wrote the original software. If you use this software */ +/* in a product, an acknowledgment in the product documentation would be */ +/* appreciated but is not required. */ +/* 2. Altered source versions must be plainly marked as such, and must not */ +/* be misrepresented as being the original software. */ +/* 3. This notice may not be removed or altered from any source */ +/* distribution. */ +/* */ +/*****************************************************************************/ + + + +#ifndef _ZLIB_H +#define _ZLIB_H + +#define Z_OK 0 +#define Z_DATA_ERROR (-3) +/* Return codes for uncompress() */ + +#define Z_DEFLATED 8 +/* The deflate compression method (the only one supported) */ + +#define Z_NULL 0 + + +unsigned __fastcall__ inflatemem (char* dest, const char* source); +/* + Decompresses the source buffer into the destination buffer. + Returns the size of the uncompressed data (number of bytes written starting + from dest). + + This function expects data in the DEFLATE format, described in RFC + (Request for Comments) 1951 in the file + ftp://ds.internic.net/rfc/rfc1951.txt. + + This function does not exist in the original zlib. Its implementation + using original zlib might be following: + + unsigned inflatemem (char* dest, const char* source) + { + z_stream stream; + + stream.next_in = (Bytef*) source; + stream.avail_in = 65535; + + stream.next_out = dest; + stream.avail_out = 65535; + + stream.zalloc = (alloc_func) 0; + stream.zfree = (free_func) 0; + + inflateInit2(&stream, -MAX_WBITS); + inflate(&stream, Z_FINISH); + inflateEnd(&stream); + + return stream.total_out; + } +*/ + + +int __fastcall__ uncompress (char* dest, unsigned* destLen, + const char* source, unsigned sourceLen); +/* + Original zlib description: + + Decompresses the source buffer into the destination buffer. sourceLen is + the byte length of the source buffer. Upon entry, destLen is the total + size of the destination buffer, which must be large enough to hold the + entire uncompressed data. (The size of the uncompressed data must have + been saved previously by the compressor and transmitted to the decompressor + by some mechanism outside the scope of this compression library.) + Upon exit, destLen is the actual size of the compressed buffer. + This function can be used to decompress a whole file at once if the + input file is mmap'ed. + + uncompress returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_BUF_ERROR if there was not enough room in the output + buffer, or Z_DATA_ERROR if the input data was corrupted. + + Implementation notes: + + This function expects data in the ZLIB format, described in RFC 1950 + in the file ftp://ds.internic.net/rfc/rfc1950.txt. The ZLIB format is + essentially the DEFLATE format plus a very small header and Adler-32 + checksum. + + Z_MEM_ERROR and Z_BUF_ERROR are never returned in this implementation. +*/ + + +unsigned long __fastcall__ adler32 (unsigned long adler, const char* buf, + unsigned len); + +/* + Original zlib description: + + Update a running Adler-32 checksum with the bytes buf[0..len-1] and + return the updated checksum. If buf is NULL, this function returns + the required initial value for the checksum. + An Adler-32 checksum is almost as reliable as a CRC32 but can be computed + much faster. Usage example: + + unsigned long adler = adler32(0L, Z_NULL, 0); + + while (read_buffer(buffer, length) != EOF) { + adler = adler32(adler, buffer, length); + } + if (adler != original_adler) error(); + + Implementation notes: + + This function isn't actually much faster than crc32(), but it is smaller + and does not use any lookup tables. +*/ + + +unsigned long __fastcall__ crc32 (unsigned long crc, const char* buf, + unsigned len); +/* + Original zlib description: + + Update a running crc with the bytes buf[0..len-1] and return the updated + crc. If buf is NULL, this function returns the required initial value + for the crc. Pre- and post-conditioning (one's complement) is performed + within this function so it shouldn't be done by the application. + Usage example: + + unsigned long crc = crc32(0L, Z_NULL, 0); + + while (read_buffer(buffer, length) != EOF) { + crc = crc32(crc, buffer, length); + } + if (crc != original_crc) error(); + + Implementation notes: + + This function uses statically allocated 1 KB lookup table. The table is + initialised before it is used for the first time (that is, if buffer is + NULL or length is zero, then the lookup table isn't initialised). +*/ + + +/* end of zlib.h */ +#endif + + + diff --git a/libsrc/Makefile b/libsrc/Makefile index 54b54860c..0583b6761 100644 --- a/libsrc/Makefile +++ b/libsrc/Makefile @@ -1,4 +1,3 @@ - ifneq ($(shell echo),) CMD_EXE = 1 endif @@ -15,24 +14,24 @@ CBMS = c128 \ GEOS = geos-apple \ geos-cbm -TARGETS = apple2 \ - apple2enh \ - atari \ - atarixl \ - atari2600 \ - atari5200 \ - atmos \ +TARGETS = apple2 \ + apple2enh \ + atari \ + atarixl \ + atari2600 \ + atari5200 \ + atmos \ creativision \ - $(CBMS) \ - $(GEOS) \ - gamate \ - lynx \ - nes \ - osic1p \ - pce \ - sim6502 \ - sim65c02 \ - supervision\ + $(CBMS) \ + $(GEOS) \ + gamate \ + lynx \ + nes \ + osic1p \ + pce \ + sim6502 \ + sim65c02 \ + supervision \ telestrat DRVTYPES = emd \ @@ -41,13 +40,13 @@ DRVTYPES = emd \ ser \ tgi -OUTPUTDIRS := lib \ - asminc \ - cfg \ - include \ - $(subst ../,,$(filter-out $(wildcard ../include/*.*),$(wildcard ../include/*)))\ - $(subst ../,,$(wildcard ../target/*/drv/*))\ - $(subst ../,,$(wildcard ../target/*/util))\ +OUTPUTDIRS := lib \ + asminc \ + cfg \ + include \ + $(subst ../,,$(filter-out $(wildcard ../include/*.*),$(wildcard ../include/*))) \ + $(subst ../,,$(wildcard ../target/*/drv/*)) \ + $(subst ../,,$(wildcard ../target/*/util)) .PHONY: all mostlyclean clean install zip lib $(TARGETS) @@ -73,7 +72,7 @@ endif ifndef TARGET -datadir = $(prefix)/share/cc65 +datadir = $(PREFIX)/share/cc65 all lib: $(TARGETS) @@ -93,7 +92,7 @@ INSTALL = install define INSTALL_recipe -$(if $(prefix),,$(error variable `prefix' must be set)) +$(if $(PREFIX),,$(error variable `PREFIX' must be set)) $(INSTALL) -d $(DESTDIR)$(datadir)/$(dir) $(INSTALL) -m0644 ../$(dir)/*.* $(DESTDIR)$(datadir)/$(dir) @@ -197,6 +196,7 @@ DEPS = $(OBJS:.o=.d) EXTRA_SRCPAT = $(SRCDIR)/extra/%.s EXTRA_OBJPAT = ../lib/$(TARGET)-%.o EXTRA_OBJS := $(patsubst $(EXTRA_SRCPAT),$(EXTRA_OBJPAT),$(wildcard $(SRCDIR)/extra/*.s)) +DEPS += $(EXTRA_OBJS:../lib/%.o=../libwrk/$(TARGET)/%.d) ZPOBJ = ../libwrk/$(TARGET)/zeropage.o ifeq ($(TARGET),$(filter $(TARGET),$(EXTZP))) @@ -280,9 +280,9 @@ endef # COMPILE_recipe ../libwrk/$(TARGET)/%.o: %.c | ../libwrk/$(TARGET) $(COMPILE_recipe) -$(EXTRA_OBJPAT): $(EXTRA_SRCPAT) | ../lib +$(EXTRA_OBJPAT): $(EXTRA_SRCPAT) | ../libwrk/$(TARGET) ../lib @echo $(TARGET) - $(<F) - @$(CA65) -t $(TARGET) $(CA65FLAGS) -o $@ $< + @$(CA65) -t $(TARGET) $(CA65FLAGS) --create-dep $(@:../lib/%.o=../libwrk/$(TARGET)/%.d) -o $@ $< ../lib/$(TARGET).lib: $(OBJS) | ../lib $(AR65) a $@ $? diff --git a/libsrc/apple2/joy/a2.stdjoy.s b/libsrc/apple2/joy/a2.stdjoy.s index e4097e043..ed2083255 100644 --- a/libsrc/apple2/joy/a2.stdjoy.s +++ b/libsrc/apple2/joy/a2.stdjoy.s @@ -46,17 +46,6 @@ PREAD := $FB1E ; Read paddle in X, return AD conv. value in Y .addr $0000 -; Button state masks (8 values) - - .byte $10 - .byte $20 - .byte $04 - .byte $08 - .byte $40 - .byte $80 - .byte $00 ; Future expansion - .byte $00 ; Future expansion - ; Jump table .addr INSTALL @@ -119,7 +108,7 @@ READJOY: lda BUTN0-1,x ; Check button (1, 3) asl tya - ror ; FIRE DOWN !UP RIGHT !LEFT 0 0 0 + ror ; BTN DOWN !UP RIGHT !LEFT 0 0 0 ; Read secondary button tay @@ -130,10 +119,10 @@ READJOY: lda BUTN0-1,x ; Check button (2, 0) asl tya - ror ; FIRE2 FIRE DOWN !UP RIGHT !LEFT 0 0 + ror ; BTN2 BTN DOWN !UP RIGHT !LEFT 0 0 ; Finalize - eor #%00010100 ; FIRE2 FIRE DOWN UP RIGHT LEFT 0 0 + eor #%00010100 ; BTN2 BTN DOWN UP RIGHT LEFT 0 0 ldx #$00 bit $C080 ; Switch in LC bank 2 for R/O rts diff --git a/libsrc/atari/cgetc.s b/libsrc/atari/cgetc.s index 2e9ebcb31..f8d938dfb 100644 --- a/libsrc/atari/cgetc.s +++ b/libsrc/atari/cgetc.s @@ -6,9 +6,9 @@ ; .include "atari.inc" - .export _cgetc,setcursor + .export _cgetc + .import setcursor .import KEYBDV_handler - .import cursor,mul40 _cgetc: jsr setcursor @@ -29,43 +29,3 @@ _cgetc: pha rts .endif - -.proc setcursor - - ldy #0 - lda OLDCHR - sta (OLDADR),y - - lda ROWCRS - jsr mul40 - clc - adc SAVMSC ; add start of screen memory - sta OLDADR - txa - adc SAVMSC+1 - sta OLDADR+1 - lda COLCRS - adc OLDADR - sta OLDADR - bcc nc - inc OLDADR+1 -nc: lda (OLDADR),y - sta OLDCHR - - ldx cursor ; current cursor setting as requested by the user - beq off - ldx #0 - beq cont - -off: inx -cont: stx CRSINH ; update system variable - - beq turnon - and #$7f ; clear high bit / inverse flag -finish: sta (OLDADR),y ; update on-screen display - rts - -turnon: ora #$80 ; set high bit / inverse flag - bne finish - -.endproc diff --git a/libsrc/atari/joy/atrmj8.s b/libsrc/atari/joy/atrmj8.s index 46766070b..0e8cd2a0a 100644 --- a/libsrc/atari/joy/atrmj8.s +++ b/libsrc/atari/joy/atrmj8.s @@ -35,17 +35,6 @@ .addr $0000 -; Button state masks (8 values) - - .byte $02 ; JOY_UP - .byte $04 ; JOY_DOWN - .byte $08 ; JOY_LEFT - .byte $10 ; JOY_RIGHT - .byte $01 ; JOY_FIRE - .byte $00 ; JOY_FIRE2 not available - .byte $00 ; Future expansion - .byte $00 ; Future expansion - ; Jump table. .addr INSTALL @@ -115,10 +104,12 @@ READJOY: ; Read joystick - lda PORTA ; get position - and #%00001111 + lda STRIG0 ; get button asl a - ora TRIG0 ; add button information - eor #%00011111 + asl a + asl a + asl a + ora PORTA ; add position information + eor #$1F ldx #0 ; fix X rts diff --git a/libsrc/atari/joy/atrstd.s b/libsrc/atari/joy/atrstd.s index fc7aa55f4..0c8799e21 100644 --- a/libsrc/atari/joy/atrstd.s +++ b/libsrc/atari/joy/atrstd.s @@ -34,17 +34,6 @@ .addr $0000 -; Button state masks (8 values) - - .byte $01 ; JOY_UP - .byte $02 ; JOY_DOWN - .byte $04 ; JOY_LEFT - .byte $08 ; JOY_RIGHT - .byte $10 ; JOY_FIRE - .byte $00 ; JOY_FIRE2 not available - .byte $00 ; Future expansion - .byte $00 ; Future expansion - ; Jump table. .addr INSTALL diff --git a/libsrc/atari/setcursor.s b/libsrc/atari/setcursor.s new file mode 100644 index 000000000..cf596d4fe --- /dev/null +++ b/libsrc/atari/setcursor.s @@ -0,0 +1,48 @@ +; +; Christian Groessler, November-2002 +; +; cursor handling, internal function + + .include "atari.inc" + .import cursor,mul40 + .export setcursor + +.proc setcursor + + ldy #0 + lda OLDCHR + sta (OLDADR),y + + lda ROWCRS + jsr mul40 + clc + adc SAVMSC ; add start of screen memory + sta OLDADR + txa + adc SAVMSC+1 + sta OLDADR+1 + lda COLCRS + adc OLDADR + sta OLDADR + bcc nc + inc OLDADR+1 +nc: lda (OLDADR),y + sta OLDCHR + + ldx cursor ; current cursor setting as requested by the user + beq off + ldx #0 + beq cont + +off: inx +cont: stx CRSINH ; update system variable + + beq turnon + and #$7f ; clear high bit / inverse flag +finish: sta (OLDADR),y ; update on-screen display + rts + +turnon: ora #$80 ; set high bit / inverse flag + bne finish + +.endproc diff --git a/libsrc/atari5200/joy/atr5200std.s b/libsrc/atari5200/joy/atr5200std.s index 3483cc11a..0b8b93b63 100644 --- a/libsrc/atari5200/joy/atr5200std.s +++ b/libsrc/atari5200/joy/atr5200std.s @@ -27,17 +27,6 @@ .addr $0000 -; Button state masks (8 values) - - .byte $01 ; JOY_UP - .byte $02 ; JOY_DOWN - .byte $04 ; JOY_LEFT - .byte $08 ; JOY_RIGHT - .byte $10 ; JOY_FIRE - .byte $20 ; JOY_FIRE2 - .byte $00 ; Future expansion - .byte $00 ; Future expansion - ; Jump table. .addr INSTALL @@ -99,7 +88,7 @@ READJOY: lda #0 ; Initialize return value cmp TRIG0,y bne @notrg - lda #$10 ; JOY_FIRE + lda #$10 ; JOY_BTN ; Read joystick diff --git a/libsrc/atmos/gotoxy.s b/libsrc/atmos/gotoxy.s index 80d4d5251..6652c9419 100644 --- a/libsrc/atmos/gotoxy.s +++ b/libsrc/atmos/gotoxy.s @@ -1,14 +1,18 @@ ; -; Ullrich von Bassewitz, 2003-04-13 +; 2003-04-13, Ullrich von Bassewitz +; 2017-06-15, Greg King ; ; void gotoxy (unsigned char x, unsigned char y); ; - .export _gotoxy + .export gotoxy, _gotoxy + .import popa .include "atmos.inc" +gotoxy: jsr popa ; Get Y + .proc _gotoxy sta CURS_Y ; Set Y @@ -17,5 +21,3 @@ rts .endproc - - diff --git a/libsrc/atmos/joy/atmos-pase.s b/libsrc/atmos/joy/atmos-pase.s index 26d7c74d8..637571c04 100644 --- a/libsrc/atmos/joy/atmos-pase.s +++ b/libsrc/atmos/joy/atmos-pase.s @@ -28,17 +28,6 @@ .addr $0000 -; Button state masks (8 values) - - .byte $10 ; JOY_UP - .byte $08 ; JOY_DOWN - .byte $01 ; JOY_LEFT - .byte $02 ; JOY_RIGHT - .byte $20 ; JOY_FIRE - .byte $00 ; Future expansion - .byte $00 ; Future expansion - .byte $00 ; Future expansion - ; Jump table. .addr INSTALL diff --git a/libsrc/c128/joy/c128-ptvjoy.s b/libsrc/c128/joy/c128-ptvjoy.s index 6f65ce5eb..c9ae39a47 100644 --- a/libsrc/c128/joy/c128-ptvjoy.s +++ b/libsrc/c128/joy/c128-ptvjoy.s @@ -30,17 +30,6 @@ .addr $0000 -; Button state masks (8 values) - - .byte $01 ; JOY_UP - .byte $02 ; JOY_DOWN - .byte $04 ; JOY_LEFT - .byte $08 ; JOY_RIGHT - .byte $10 ; JOY_FIRE - .byte $00 ; JOY_FIRE2 unavailable - .byte $00 ; Future expansion - .byte $00 ; Future expansion - ; Jump table. .addr INSTALL diff --git a/libsrc/c128/joy/c128-stdjoy.s b/libsrc/c128/joy/c128-stdjoy.s index 119d3784f..943361da5 100644 --- a/libsrc/c128/joy/c128-stdjoy.s +++ b/libsrc/c128/joy/c128-stdjoy.s @@ -30,17 +30,6 @@ .addr $0000 -; Button state masks (8 values) - - .byte $01 ; JOY_UP - .byte $02 ; JOY_DOWN - .byte $04 ; JOY_LEFT - .byte $08 ; JOY_RIGHT - .byte $10 ; JOY_FIRE - .byte $00 ; JOY_FIRE2 unavailable - .byte $00 ; Future expansion - .byte $00 ; Future expansion - ; Jump table. .addr INSTALL @@ -104,7 +93,7 @@ joy1: lda #$7F sei sta CIA1_PRA lda CIA1_PRB - cli +back: cli and #$1F eor #$1F rts @@ -118,9 +107,4 @@ joy2: ldx #0 sta CIA1_DDRA lda CIA1_PRA sty CIA1_DDRA - cli - and #$1F - eor #$1F - rts - - + jmp back diff --git a/libsrc/c128/kbrepeat.s b/libsrc/c128/kbrepeat.s new file mode 100644 index 000000000..4b9bc22af --- /dev/null +++ b/libsrc/c128/kbrepeat.s @@ -0,0 +1,14 @@ +; +; unsigned char __fastcall__ kbrepeat (unsigned char mode); +; + + .export _kbrepeat + + .include "c128.inc" + +_kbrepeat: + ldx KBDREPEAT ; get old value + sta KBDREPEAT ; store new value + txa ; return old value + ldx #0 + rts diff --git a/libsrc/c128/waitvsync.s b/libsrc/c128/waitvsync.s new file mode 100644 index 000000000..e4bbbf7c9 --- /dev/null +++ b/libsrc/c128/waitvsync.s @@ -0,0 +1,30 @@ +; +; Written by Groepaz <groepaz@gmx.net> +; +; void waitvsync (void); +; + + .export _waitvsync + + .include "c128.inc" + +_waitvsync: + + bit MODE + bmi @c80 + +@l1: + bit VIC_CTRL1 + bpl @l1 +@l2: + bit VIC_CTRL1 + bmi @l2 + rts + +@c80: + ;FIXME: do we have to switch banks? +@l3: + lda VDC_INDEX + and #$20 + beq @l3 + rts diff --git a/libsrc/c64/emd/c64-65816.s b/libsrc/c64/emd/c64-65816.s index bf44a0ecc..39f323d28 100644 --- a/libsrc/c64/emd/c64-65816.s +++ b/libsrc/c64/emd/c64-65816.s @@ -1,376 +1,376 @@ -; -; Extended memory driver for 65816 based extra RAM. Driver works without -; problems when statically linked. -; -; Marco van den Heuvel, 2015-12-01 -; - - .include "zeropage.inc" - - .include "em-kernel.inc" - .include "em-error.inc" - - - .macpack generic - .macpack module - - -; ------------------------------------------------------------------------ -; Header. Includes jump table - - module_header _c64_65816_emd - -; Driver signature - - .byte $65, $6d, $64 ; "emd" - .byte EMD_API_VERSION ; EM API version number - -; Library reference - - .addr $0000 - -; Jump table - - .addr INSTALL - .addr UNINSTALL - .addr PAGECOUNT - .addr MAP - .addr USE - .addr COMMIT - .addr COPYFROM - .addr COPYTO - -; ------------------------------------------------------------------------ -; Data. - -.bss -isnotscpu: .res 1 ; SuperCPU not present -curpage: .res 1 ; Current page number -curbank: .res 1 ; Current bank number (+1) -bankcount: .res 1 ; Number of available banks (pages = banks * 256) -window: .res 256 ; Memory "window" - -.code - -; ------------------------------------------------------------------------ -; INSTALL routine. Is called after the driver is loaded into memory. If -; possible, check if the hardware is present and determine the amount of -; memory available. -; Must return an EM_ERR_xx code in a/x. -; - -INSTALL: - sei - clc - sed - lda #$99 - adc #$01 ; on 65C02, 65SC02, 65CE02, 65802 and 65816 sets the zero flag correctly - cld - bne @not_present - clc -.P816 - sep #$01 ; nop #$01 on 65C02/65SC02 and lda ($01,s),y on 65CE02 -.P02 - bcc @not_present - lda $d0bc - and #$80 - sta isnotscpu - lda $07e8 - pha ; save value incase it was used somewhere else - ldx #$ff -@fillloop: ; fill from top (bank 255) to bottom - txa - pha -.P816 - plb ; pull dbr -.P02 - stx $07e8 - dex - cpx #$ff - bne @fillloop - inx -@compareloop: ; check from bottom to top - txa - pha -.P816 - plb -.P02 - cmp $07e8 - bne @found_pages -.P816 - inc -.P02 - sta $07e8 - cmp $07e8 - bne @found_pages - inx - bne @compareloop -@found_pages: - dex - lda #$00 - pha -.P816 - plb -.P02 - pla - sta $07e8 - cli - lda isnotscpu - bne @noextradex - dex -@noextradex: - stx bankcount - lda #<EM_ERR_OK - ldx #>EM_ERR_OK - rts -@not_present: - cli - lda #<EM_ERR_NO_DEVICE - ldx #>EM_ERR_NO_DEVICE -; rts ; Run into UNINSTALL instead - - -; ------------------------------------------------------------------------ -; UNINSTALL routine. Is called before the driver is removed from memory. -; Can do cleanup or whatever. Must not return anything. -; - -UNINSTALL: - rts - - -; ------------------------------------------------------------------------ -; PAGECOUNT: Return the total number of available pages in a/x. -; - -PAGECOUNT: - lda #$00 ; a whole bank is either usable or not - ldx bankcount - rts - -; ------------------------------------------------------------------------ -; MAP: Map the page in a/x into memory and return a pointer to the page in -; a/x. The contents of the currently mapped page (if any) may be discarded -; by the driver. -; - -MAP: sta curpage ; Remember the new page - stx curbank ; Remember the new bank - - sta ptr2+1 ; src address low - lda #$00 - sta ptr2 ; src address high - inx - ldy isnotscpu ; check if not scpu - bne @notscpu - inx -@notscpu: - stx tmp2 ; src bank - - sta tmp1 ; dst bank - - sta ptr3+1 ; length high - lda #$ff - sta ptr3 ; length low - - lda #<window - sta ptr1 ; dst address low - ldx #>window - stx ptr1+1 ; dst address high - - jsr transfer - - rts - -; ------------------------------------------------------------------------ -; USE: Tell the driver that the window is now associated with a given page. - -USE: sta curpage ; Remember the page - stx curbank ; Remember the bank - lda #<window - ldx #>window ; Return the window - rts - -; ------------------------------------------------------------------------ -; COMMIT: Commit changes in the memory window to extended storage. - -COMMIT: lda curpage ; Get the current page - sta ptr1+1 ; dst high - ldx #$00 - stx ptr1 ; dst low - - lda #<window - sta ptr2 ; src low - lda #>window - sta ptr2+1 ; src high - - stx ptr3+1 ; length high - lda #$ff - sta ptr3 ; length low - - stx tmp2 ; src bank - ldy curbank ; Get the current bank - iny - ldx isnotscpu - bne @notascpu - iny -@notascpu: - sty tmp1 ; dst bank - - jsr transfer - - rts - -; ------------------------------------------------------------------------ -; COPYFROM: Copy from extended into linear memory. A pointer to a structure -; describing the request is passed in a/x. -; The function must not return anything. -; - -COPYFROM: - sta ptr4 - stx ptr4+1 ; Save the passed em_copy pointer - - ldy #EM_COPY::COUNT+1 ; start at the end of the struct - lda (ptr4),y ; get high byte of count - tax - dey - lda (ptr4),y ; get low byte of count - bne @nodex - dex -@nodex: -.P816 - dec -.P02 - sta ptr3 ; length low - stx ptr3+1 ; length high - dey - lda (ptr4),y ; get bank -.P816 - inc -.P02 - ldx isnotscpu - bne @notscpu64 -.P816 - inc -.P02 -@notscpu64: - sta tmp2 ; src bank - dey - lda (ptr4),y ; get page - sta ptr2+1 ; src high - dey - lda (ptr4),y ; get offset in page - sta ptr2 ; src low - dey - lda (ptr4),y ; get memory buffer high - sta ptr1+1 ; dst high - dey - lda (ptr4),y ; get memory buffer low - sta ptr1 ; dst low - lda #$00 - sta tmp1 ; dst bank - - jsr transfer - - rts - -; ------------------------------------------------------------------------ -; COPYTO: Copy from linear into extended memory. A pointer to a structure -; describing the request is passed in a/x. -; The function must not return anything. -; - -COPYTO: sta ptr4 - stx ptr4+1 ; Save the passed em_copy pointer - - ldy #EM_COPY::COUNT+1 ; start at the end of the struct - lda (ptr4),y ; get high byte of count - tax - dey - lda (ptr4),y ; get low byte of count - bne @nodex2 - dex -@nodex2: -.P816 - dec -.P02 - sta ptr3 ; length low - txa - sta ptr3+1 ; length high - dey - lda (ptr4),y ; get bank -.P816 - inc -.P02 - ldx isnotscpu - bne @notascpu64 -.P816 - inc -.P02 -@notascpu64: - sta tmp1 ; dst bank - dey - lda (ptr4),y ; get page - sta ptr1+1 ; dst high - dey - lda (ptr4),y ; get page offset - sta ptr1 ; dst low - dey - lda (ptr4),y ; get memory buffer high - sta ptr2+1 ; src low - dey - lda (ptr4),y ; get memory buffer low - sta ptr2 ; src high - lda #$00 - sta tmp2 ; src bank - - jsr transfer - - rts - -; ------------------------------------------------------------------------ -; Helper function for moving a block, the following is used: -; ptr1: dst -; ptr2: src -; ptr3: length -; tmp1: dst bank -; tmp2: src bank - -transfer: -.P816 -.A8 -.I8 - sei - pha - phx - phy - ldx tmp1 ; load srcbank - stx @move+1 ; store srcbank in move + 1 - ldy tmp2 ; load dstbank - sty @move+2 ; store dstbank in move + 2 - clc ; switch to native mode - xce - php ; save status bits - rep #%00110000 ; set A and index to 16bit -.A16 -.I16 - ldy ptr1 - ldx ptr2 - lda ptr3 -@move: - mvn 0,0 - plp ; restore status bits -.A8 -.I8 - lda #$00 - pha - plb ; restore dbr - sec - xce ; switch to emul mode - ply - plx - pla - cli - rts -.P02 +; +; Extended memory driver for 65816 based extra RAM. Driver works without +; problems when statically linked. +; +; Marco van den Heuvel, 2015-12-01 +; + + .include "zeropage.inc" + + .include "em-kernel.inc" + .include "em-error.inc" + + + .macpack generic + .macpack module + + +; ------------------------------------------------------------------------ +; Header. Includes jump table + + module_header _c64_65816_emd + +; Driver signature + + .byte $65, $6d, $64 ; "emd" + .byte EMD_API_VERSION ; EM API version number + +; Library reference + + .addr $0000 + +; Jump table + + .addr INSTALL + .addr UNINSTALL + .addr PAGECOUNT + .addr MAP + .addr USE + .addr COMMIT + .addr COPYFROM + .addr COPYTO + +; ------------------------------------------------------------------------ +; Data. + +.bss +isnotscpu: .res 1 ; SuperCPU not present +curpage: .res 1 ; Current page number +curbank: .res 1 ; Current bank number (+1) +bankcount: .res 1 ; Number of available banks (pages = banks * 256) +window: .res 256 ; Memory "window" + +.code + +; ------------------------------------------------------------------------ +; INSTALL routine. Is called after the driver is loaded into memory. If +; possible, check if the hardware is present and determine the amount of +; memory available. +; Must return an EM_ERR_xx code in a/x. +; + +INSTALL: + sei + clc + sed + lda #$99 + adc #$01 ; on 65C02, 65SC02, 65CE02, 65802 and 65816 sets the zero flag correctly + cld + bne @not_present + clc +.P816 + sep #$01 ; nop #$01 on 65C02/65SC02 and lda ($01,s),y on 65CE02 +.P02 + bcc @not_present + lda $d0bc + and #$80 + sta isnotscpu + lda $07e8 + pha ; save value incase it was used somewhere else + ldx #$ff +@fillloop: ; fill from top (bank 255) to bottom + txa + pha +.P816 + plb ; pull dbr +.P02 + stx $07e8 + dex + cpx #$ff + bne @fillloop + inx +@compareloop: ; check from bottom to top + txa + pha +.P816 + plb +.P02 + cmp $07e8 + bne @found_pages +.P816 + inc +.P02 + sta $07e8 + cmp $07e8 + bne @found_pages + inx + bne @compareloop +@found_pages: + dex + lda #$00 + pha +.P816 + plb +.P02 + pla + sta $07e8 + cli + lda isnotscpu + bne @noextradex + dex +@noextradex: + stx bankcount + lda #<EM_ERR_OK + ldx #>EM_ERR_OK + rts +@not_present: + cli + lda #<EM_ERR_NO_DEVICE + ldx #>EM_ERR_NO_DEVICE +; rts ; Run into UNINSTALL instead + + +; ------------------------------------------------------------------------ +; UNINSTALL routine. Is called before the driver is removed from memory. +; Can do cleanup or whatever. Must not return anything. +; + +UNINSTALL: + rts + + +; ------------------------------------------------------------------------ +; PAGECOUNT: Return the total number of available pages in a/x. +; + +PAGECOUNT: + lda #$00 ; a whole bank is either usable or not + ldx bankcount + rts + +; ------------------------------------------------------------------------ +; MAP: Map the page in a/x into memory and return a pointer to the page in +; a/x. The contents of the currently mapped page (if any) may be discarded +; by the driver. +; + +MAP: sta curpage ; Remember the new page + stx curbank ; Remember the new bank + + sta ptr2+1 ; src address low + lda #$00 + sta ptr2 ; src address high + inx + ldy isnotscpu ; check if not scpu + bne @notscpu + inx +@notscpu: + stx tmp2 ; src bank + + sta tmp1 ; dst bank + + sta ptr3+1 ; length high + lda #$ff + sta ptr3 ; length low + + lda #<window + sta ptr1 ; dst address low + ldx #>window + stx ptr1+1 ; dst address high + + jsr transfer + + rts + +; ------------------------------------------------------------------------ +; USE: Tell the driver that the window is now associated with a given page. + +USE: sta curpage ; Remember the page + stx curbank ; Remember the bank + lda #<window + ldx #>window ; Return the window + rts + +; ------------------------------------------------------------------------ +; COMMIT: Commit changes in the memory window to extended storage. + +COMMIT: lda curpage ; Get the current page + sta ptr1+1 ; dst high + ldx #$00 + stx ptr1 ; dst low + + lda #<window + sta ptr2 ; src low + lda #>window + sta ptr2+1 ; src high + + stx ptr3+1 ; length high + lda #$ff + sta ptr3 ; length low + + stx tmp2 ; src bank + ldy curbank ; Get the current bank + iny + ldx isnotscpu + bne @notascpu + iny +@notascpu: + sty tmp1 ; dst bank + + jsr transfer + + rts + +; ------------------------------------------------------------------------ +; COPYFROM: Copy from extended into linear memory. A pointer to a structure +; describing the request is passed in a/x. +; The function must not return anything. +; + +COPYFROM: + sta ptr4 + stx ptr4+1 ; Save the passed em_copy pointer + + ldy #EM_COPY::COUNT+1 ; start at the end of the struct + lda (ptr4),y ; get high byte of count + tax + dey + lda (ptr4),y ; get low byte of count + bne @nodex + dex +@nodex: +.P816 + dec +.P02 + sta ptr3 ; length low + stx ptr3+1 ; length high + dey + lda (ptr4),y ; get bank +.P816 + inc +.P02 + ldx isnotscpu + bne @notscpu64 +.P816 + inc +.P02 +@notscpu64: + sta tmp2 ; src bank + dey + lda (ptr4),y ; get page + sta ptr2+1 ; src high + dey + lda (ptr4),y ; get offset in page + sta ptr2 ; src low + dey + lda (ptr4),y ; get memory buffer high + sta ptr1+1 ; dst high + dey + lda (ptr4),y ; get memory buffer low + sta ptr1 ; dst low + lda #$00 + sta tmp1 ; dst bank + + jsr transfer + + rts + +; ------------------------------------------------------------------------ +; COPYTO: Copy from linear into extended memory. A pointer to a structure +; describing the request is passed in a/x. +; The function must not return anything. +; + +COPYTO: sta ptr4 + stx ptr4+1 ; Save the passed em_copy pointer + + ldy #EM_COPY::COUNT+1 ; start at the end of the struct + lda (ptr4),y ; get high byte of count + tax + dey + lda (ptr4),y ; get low byte of count + bne @nodex2 + dex +@nodex2: +.P816 + dec +.P02 + sta ptr3 ; length low + txa + sta ptr3+1 ; length high + dey + lda (ptr4),y ; get bank +.P816 + inc +.P02 + ldx isnotscpu + bne @notascpu64 +.P816 + inc +.P02 +@notascpu64: + sta tmp1 ; dst bank + dey + lda (ptr4),y ; get page + sta ptr1+1 ; dst high + dey + lda (ptr4),y ; get page offset + sta ptr1 ; dst low + dey + lda (ptr4),y ; get memory buffer high + sta ptr2+1 ; src low + dey + lda (ptr4),y ; get memory buffer low + sta ptr2 ; src high + lda #$00 + sta tmp2 ; src bank + + jsr transfer + + rts + +; ------------------------------------------------------------------------ +; Helper function for moving a block, the following is used: +; ptr1: dst +; ptr2: src +; ptr3: length +; tmp1: dst bank +; tmp2: src bank + +transfer: +.P816 +.A8 +.I8 + sei + pha + phx + phy + ldx tmp1 ; load srcbank + stx @move+1 ; store srcbank in move + 1 + ldy tmp2 ; load dstbank + sty @move+2 ; store dstbank in move + 2 + clc ; switch to native mode + xce + php ; save status bits + rep #%00110000 ; set A and index to 16bit +.A16 +.I16 + ldy ptr1 + ldx ptr2 + lda ptr3 +@move: + mvn 0,0 + plp ; restore status bits +.A8 +.I8 + lda #$00 + pha + plb ; restore dbr + sec + xce ; switch to emul mode + ply + plx + pla + cli + rts +.P02 diff --git a/libsrc/c64/joy/c64-hitjoy.s b/libsrc/c64/joy/c64-hitjoy.s index a798100a7..10c936399 100644 --- a/libsrc/c64/joy/c64-hitjoy.s +++ b/libsrc/c64/joy/c64-hitjoy.s @@ -29,17 +29,6 @@ .addr $0000 -; Button state masks (8 values) - - .byte $01 ; JOY_UP - .byte $02 ; JOY_DOWN - .byte $04 ; JOY_LEFT - .byte $08 ; JOY_RIGHT - .byte $10 ; JOY_FIRE - .byte $00 ; JOY_FIRE2 unavailable - .byte $00 ; Future expansion - .byte $00 ; Future expansion - ; Jump table. .addr INSTALL diff --git a/libsrc/c64/joy/c64-numpad.s b/libsrc/c64/joy/c64-numpad.s index 5f6464215..5ed7af187 100644 --- a/libsrc/c64/joy/c64-numpad.s +++ b/libsrc/c64/joy/c64-numpad.s @@ -30,17 +30,6 @@ .addr $0000 -; Button state masks (8 values) - - .byte $02 ; JOY_UP "8" - .byte $10 ; JOY_DOWN "2" - .byte $20 ; JOY_LEFT "4" - .byte $08 ; JOY_RIGHT "6" - .byte $04 ; JOY_FIRE "5" ENTER - .byte $00 ; JOY_FIRE2 unavailable - .byte $00 ; Future expansion - .byte $00 ; Future expansion - ; Jump table. .addr INSTALL @@ -58,6 +47,49 @@ JOY_COUNT = 1 ; Number of joysticks we support ; ------------------------------------------------------------------------ ; Data. +.rodata + +; <U>p '8' key +; <D>own '2' key +; <L>eft '4' key +; <R>ight '6' key +; <B>utton '5' or ENTER key + +masktable: + ; Input: LDRBU + ; Output: BRLDU + .byte %00000000 ; $00 + .byte %00000001 ; $01 + .byte %00010000 ; $02 + .byte %00010001 ; $03 + .byte %00001000 ; $04 + .byte %00001001 ; $05 + .byte %00011000 ; $06 + .byte %00011001 ; $07 + .byte %00000010 ; $08 + .byte %00000011 ; $09 + .byte %00010010 ; $0A + .byte %00010011 ; $0B + .byte %00001010 ; $0C + .byte %00001011 ; $0D + .byte %00011010 ; $0E + .byte %00011011 ; $0F + .byte %00000100 ; $10 + .byte %00000101 ; $11 + .byte %00010100 ; $12 + .byte %00010101 ; $13 + .byte %00001100 ; $14 + .byte %00001101 ; $15 + .byte %00011100 ; $16 + .byte %00011101 ; $17 + .byte %00000110 ; $18 + .byte %00000111 ; $19 + .byte %00010110 ; $1A + .byte %00010111 ; $1B + .byte %00001110 ; $1C + .byte %00001111 ; $1D + .byte %00011110 ; $1E + .byte %00011111 ; $1F .code @@ -100,21 +132,23 @@ COUNT: lda #JOY_COUNT ; READ: tax ; Clear high byte - lda #$FD - ldy #$FE + lda #$FD ; For ENTER and '6' + ldy #$FE ; For '8', '5', '2', '4' sei sta VIC_KBD_128 lda CIA1_PRB and #%00110000 eor #%00110000 - lsr - lsr + lsr ; Map ENTER ... + lsr ; ... onto '5' sty VIC_KBD_128 eor CIA1_PRB iny sty VIC_KBD_128 ; Reset to $FF cli - and #%11111110 - eor #%11111110 + and #%00111110 + eor #%00111110 + lsr + tay + lda masktable,y ; Convert LDRBU to BRLDU rts - diff --git a/libsrc/c64/joy/c64-ptvjoy.s b/libsrc/c64/joy/c64-ptvjoy.s index 31850488c..af5c27e13 100644 --- a/libsrc/c64/joy/c64-ptvjoy.s +++ b/libsrc/c64/joy/c64-ptvjoy.s @@ -29,17 +29,6 @@ .addr $0000 -; Button state masks (8 values) - - .byte $01 ; JOY_UP - .byte $02 ; JOY_DOWN - .byte $04 ; JOY_LEFT - .byte $08 ; JOY_RIGHT - .byte $10 ; JOY_FIRE - .byte $00 ; JOY_FIRE2 unavailable - .byte $00 ; Future expansion - .byte $00 ; Future expansion - ; Jump table. .addr INSTALL @@ -133,8 +122,8 @@ joy3: sta CIA2_PRB ; (output one at PB7) lda CIA2_PRB ; cia 2 port B read/write - and #$1f ; get bit 4-0 (PB4-PB0) - eor #$1f + and #$1F ; get bit 4-0 (PB4-PB0) + eor #$1F rts ; Read joystick 4 @@ -143,14 +132,14 @@ joy4: lda #$00 ; cia 2 port B read/write sta CIA2_PRB ; (output zero at PB7) lda CIA2_PRB ; cia 2 port B read/write - and #$0f ; get bit 3-0 (PB3-PB0) + and #$0F ; get bit 3-0 (PB3-PB0) sta tmp1 ; joy 4 directions lda CIA2_PRB ; cia 2 port B read/write and #%00100000 ; get bit 5 (PB5) lsr ora tmp1 - eor #$1f + eor #$1F ldx #0 rts diff --git a/libsrc/c64/joy/c64-stdjoy.s b/libsrc/c64/joy/c64-stdjoy.s index 2932c77fd..930ad6227 100644 --- a/libsrc/c64/joy/c64-stdjoy.s +++ b/libsrc/c64/joy/c64-stdjoy.s @@ -29,17 +29,6 @@ .addr $0000 -; Button state masks (8 values) - - .byte $01 ; JOY_UP - .byte $02 ; JOY_DOWN - .byte $04 ; JOY_LEFT - .byte $08 ; JOY_RIGHT - .byte $10 ; JOY_FIRE - .byte $00 ; JOY_FIRE2 unavailable - .byte $00 ; Future expansion - .byte $00 ; Future expansion - ; Jump table. .addr INSTALL diff --git a/libsrc/c64/kbrepeat.s b/libsrc/c64/kbrepeat.s new file mode 100644 index 000000000..0df13e58d --- /dev/null +++ b/libsrc/c64/kbrepeat.s @@ -0,0 +1,14 @@ +; +; unsigned char __fastcall__ kbrepeat (unsigned char mode); +; + + .export _kbrepeat + + .include "c64.inc" + +_kbrepeat: + ldx KBDREPEAT ; get old value + sta KBDREPEAT ; store new value + txa ; return old value + ldx #0 + rts diff --git a/libsrc/c64/waitvsync.s b/libsrc/c64/waitvsync.s new file mode 100644 index 000000000..a4bf13080 --- /dev/null +++ b/libsrc/c64/waitvsync.s @@ -0,0 +1,18 @@ +; +; Written by Groepaz <groepaz@gmx.net> +; +; void waitvsync (void); +; + + .export _waitvsync + + .include "c64.inc" + +_waitvsync: +@l1: + bit VIC_CTRL1 + bpl @l1 +@l2: + bit VIC_CTRL1 + bmi @l2 + rts diff --git a/libsrc/cbm510/joy/cbm510-std.s b/libsrc/cbm510/joy/cbm510-std.s index 7133f9379..0c2efc12d 100644 --- a/libsrc/cbm510/joy/cbm510-std.s +++ b/libsrc/cbm510/joy/cbm510-std.s @@ -30,17 +30,6 @@ .addr $0000 -; Button state masks (8 values) - - .byte $01 ; JOY_UP - .byte $02 ; JOY_DOWN - .byte $04 ; JOY_LEFT - .byte $08 ; JOY_RIGHT - .byte $10 ; JOY_FIRE - .byte $00 ; JOY_FIRE2 unavailable - .byte $00 ; Future expansion - .byte $00 ; Future expansion - ; Jump table. .addr INSTALL @@ -105,7 +94,7 @@ READ: ldx #$0F ; Switch to the system bank lda (cia2),y ; Read joystick inputs sta tmp1 -; Get the fire bits +; Get the push button bits ldy #CIA::PRA lda (cia2),y @@ -115,12 +104,12 @@ READ: ldx #$0F ; Switch to the system bank cpx #$00 ; Joystick 0? bne @L1 ; Jump if no -; Joystick 1, fire is in bit 6, direction in bit 0-3 +; Joystick 1, push button is in bit 6, direction in bit 0-3 asl a jmp @L2 -; Joystick 2, fire is in bit 7, direction in bit 5-7 +; Joystick 2, push button is in bit 7, direction in bit 5-7 @L1: ldx #$00 ; High byte of return value lsr tmp1 @@ -128,9 +117,9 @@ READ: ldx #$0F ; Switch to the system bank lsr tmp1 lsr tmp1 -; Mask the relavant bits, get the fire bit +; Mask the relavant bits, get the push button bit -@L2: asl a ; Fire bit into carry +@L2: asl a ; push button bit into carry lda tmp1 and #$0F bcc @L3 diff --git a/libsrc/cbm510/waitvsync.s b/libsrc/cbm510/waitvsync.s new file mode 100644 index 000000000..ed7300f7c --- /dev/null +++ b/libsrc/cbm510/waitvsync.s @@ -0,0 +1,28 @@ +; +; Written by Groepaz <groepaz@gmx.net> +; +; void waitvsync (void); +; + + .export _waitvsync + .import PALFLAG + .import sys_bank, restore_bank + + .importzp vic + + .include "cbm510.inc" + +_waitvsync: + jsr sys_bank ; Switch to the system bank + sei + + ldy #VIC_CTRL1 +@l1: + lda (vic),y + bpl @l1 +@l2: + lda (vic),y + bmi @l2 + + cli + jmp restore_bank diff --git a/libsrc/common/lz4.s b/libsrc/common/lz4.s new file mode 100644 index 000000000..4702137bc --- /dev/null +++ b/libsrc/common/lz4.s @@ -0,0 +1,286 @@ +; +; Lauri Kasanen, 6 Jun 2017 +; (C) Mega Cat Studios +; An optimized LZ4 decompressor +; +; Almost 7 times faster, uses no RAM (vs 14 bytes BSS), and takes 1/4 the space +; vs the official C source. +; + + .importzp sp, sreg, regsave, regbank + .importzp tmp1, tmp2, tmp3, tmp4, ptr1, ptr2, ptr3, ptr4 + .macpack longbranch + .import memcpy_upwards,pushax,popax + .export _decompress_lz4 + +out = regsave +written = regsave + 2 +tmp = tmp1 +token = tmp2 +offset = ptr3 +in = sreg +outlen = ptr4 + +; --------------------------------------------------------------- +; void decompress_lz4 (const u8 *in, u8 * const out, const u16 outlen) +; --------------------------------------------------------------- + +.segment "CODE" + +.proc _decompress_lz4: near + + sta outlen + stx outlen+1 + + jsr popax + sta out + stx out+1 + + jsr popax + sta in + stx in+1 + +; +; written = 0; +; + lda #$00 + sta written +; +; while (written < outlen) { +; + jmp L0046 +; +; token = *in++; +; +L0004: ldy #$00 + lda (in),y + sta token + + inc in + bne L000A + inc in+1 +L000A: +; +; offset = token >> 4; +; + ldx #$00 + lsr a + lsr a + lsr a + lsr a + sta offset + stx offset+1 +; +; token &= 0xf; +; token += 4; // Minmatch +; + lda token + and #$0F + clc + adc #$04 + sta token +; +; if (offset == 15) { +; + lda offset + cmp #$0F +L0013: bne L001A +; +; tmp = *in++; +; + ldy #$00 + lda (in),y + sta tmp + + inc in + bne L0017 + inc in+1 +L0017: +; +; offset += tmp; +; + clc + adc offset + sta offset + lda #$00 + adc offset+1 + sta offset+1 +; +; if (tmp == 255) +; + lda tmp + cmp #$FF +; +; goto moreliterals; +; + jmp L0013 +; +; if (offset) { +; +L001A: lda offset + ora offset+1 + beq L001C +; +; memcpy(&out[written], in, offset); +; + lda out + clc + adc written + sta ptr2 + lda out+1 + adc written+1 + tax + lda ptr2 + stx ptr2+1 + jsr pushax + lda in + ldx in+1 + sta ptr1 + stx ptr1+1 +; ldy #$00 - not needed as pushax zeroes Y + jsr memcpy_upwards +; +; written += offset; +; + lda offset + clc + adc written + sta written + lda offset+1 + adc written+1 + sta written+1 +; +; in += offset; +; + lda offset + clc + adc in + sta in + lda offset+1 + adc in+1 + sta in+1 +; +; if (written >= outlen) +; +L001C: lda written + cmp outlen + lda written+1 + sbc outlen+1 +; +; return; +; + bcc L0047 + rts +; +; memcpy(&offset, in, 2); +; +L0047: ldy #$00 + lda (in),y + sta offset + iny + lda (in),y + sta offset+1 +; +; in += 2; +; + lda #$02 + clc + adc in + sta in + bcc L002F + inc in+1 +; +; copysrc = out + written - offset; +; +L002F: lda out + clc + adc written + tay + lda out+1 + adc written+1 + tax + tya + sec + sbc offset + sta ptr1 + txa + sbc offset+1 + sta ptr1+1 +; +; offset = token; +; + lda #$00 + sta offset+1 + lda token + sta offset +; +; if (token == 19) { +; + cmp #$13 +L0045: bne L003C +; +; tmp = *in++; +; + ldy #$00 + lda (in),y + sta tmp + + inc in + bne L0039 + inc in+1 +L0039: +; +; offset += tmp; +; + clc + adc offset + sta offset + tya + adc offset+1 + sta offset+1 +; +; if (tmp == 255) +; + lda tmp + cmp #$FF +; +; goto morematches; +; + jmp L0045 +; +; memcpy(&out[written], copysrc, offset); +; +L003C: lda out + clc + adc written + sta ptr2 + lda out+1 + adc written+1 + tax + lda ptr2 + stx ptr2+1 + jsr pushax + jsr memcpy_upwards +; +; written += offset; +; + lda offset + clc + adc written + sta written + lda offset+1 + adc written+1 +L0046: sta written+1 +; +; while (written < outlen) { +; + lda written + cmp outlen + lda written+1 + sbc outlen+1 + jcc L0004 + + rts + +.endproc + diff --git a/libsrc/common/memmove.s b/libsrc/common/memmove.s index 9c33124f1..666447cd8 100644 --- a/libsrc/common/memmove.s +++ b/libsrc/common/memmove.s @@ -1,6 +1,6 @@ ; ; 2003-08-20, Ullrich von Bassewitz -; 2009-09-13, Christian Krueger -- performance increase (about 20%) +; 2009-09-13, Christian Krueger -- performance increase (about 20%), 2013-07-25 improved unrolling ; 2015-10-23, Greg King ; ; void* __fastcall__ memmove (void* dest, const void* src, size_t size); @@ -61,13 +61,10 @@ PageSizeCopy: ; assert Y = 0 dec ptr1+1 ; adjust base... dec ptr2+1 dey ; in entry case: 0 -> FF - lda (ptr1),y ; need to copy this 'intro byte' - sta (ptr2),y ; to 'land' later on Y=0! (as a result of the '.repeat'-block!) - dey ; FF ->FE @copyBytes: - .repeat 2 ; Unroll this a bit to make it faster... - lda (ptr1),y - sta (ptr2),y + .repeat 3 ; unroll this a bit to make it faster... + lda (ptr1),y ; important: unrolling three times gives a nice + sta (ptr2),y ; 255/3 = 85 loop which ends at 0 dey .endrepeat @copyEntry: ; in entry case: 0 -> FF diff --git a/libsrc/common/rand.s b/libsrc/common/rand.s index 8ad7bcdb4..102dd5be2 100644 --- a/libsrc/common/rand.s +++ b/libsrc/common/rand.s @@ -2,6 +2,7 @@ ; Randum number generator ; ; Written and donated by Sidney Cadot - sidney@ch.twi.tudelft.nl +; 2016-11-07, modified by Brad Smith ; ; May be distributed with the cc65 runtime using the same license. ; @@ -13,10 +14,14 @@ ; Multiplier must be 1 (mod 4) ; Added value must be 1 (mod 2) ; This guarantees max. period (2**32) -; Bits 8-22 are returned (positive 2-byte int) -; where 0 is LSB, 31 is MSB. -; This is better as lower bits exhibit easily -; detectable patterns. +; The lowest bits have poor entropy and +; exhibit easily detectable patterns, so +; only the upper bits 16-22 and 24-31 of the +; 4-byte state are returned. +; +; The best 8 bits, 24-31 are returned in the +; low byte A to provide the best entropy in the +; most commonly used part of the return value. ; .export _rand, _srand diff --git a/libsrc/common/strcat.s b/libsrc/common/strcat.s index 7784d89f7..f9cd94633 100644 --- a/libsrc/common/strcat.s +++ b/libsrc/common/strcat.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 31.05.1998 +; Christian Krueger: 2013-Jul-24, minor optimizations ; ; char* strcat (char* dest, const char* src); ; @@ -7,49 +8,44 @@ .export _strcat .import popax .importzp ptr1, ptr2, tmp3 + .macpack cpu _strcat: - sta ptr1 ; Save src - stx ptr1+1 - jsr popax ; Get dest - sta ptr2 - stx ptr2+1 - sta tmp3 ; Remember for function return - ldy #0 + sta ptr1 ; Save src + stx ptr1+1 + jsr popax ; Get dest + sta tmp3 ; Remember for function return + tay +.if (.cpu .bitand ::CPU_ISET_65SC02) + stz ptr2 +.else + lda #0 + sta ptr2 ; access from page start, y contains low byte +.endif + stx ptr2+1 -; find end of dest - -sc1: lda (ptr2),y - beq sc2 +findEndOfDest: + lda (ptr2),y + beq endOfDestFound iny - bne sc1 - inc ptr2+1 - bne sc1 + bne findEndOfDest + inc ptr2+1 + bne findEndOfDest -; end found, get offset in y into pointer +endOfDestFound: + sty ptr2 ; advance pointer to last y position + ldy #0 ; reset new y-offset -sc2: tya - clc - adc ptr2 - sta ptr2 - bcc sc3 - inc ptr2+1 - -; copy src - -sc3: ldy #0 -sc4: lda (ptr1),y - sta (ptr2),y - beq sc5 +copyByte: + lda (ptr1),y + sta (ptr2),y + beq done iny - bne sc4 - inc ptr1+1 - inc ptr2+1 - bne sc4 + bne copyByte + inc ptr1+1 + inc ptr2+1 + bne copyByte ; like bra here -; done, return pointer to dest - -sc5: lda tmp3 ; X does still contain high byte +; return pointer to dest +done: lda tmp3 ; X does still contain high byte rts - - diff --git a/libsrc/common/strchr.s b/libsrc/common/strchr.s index 308381b06..206b5160e 100644 --- a/libsrc/common/strchr.s +++ b/libsrc/common/strchr.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 31.05.1998 +; Christian Krueger, 2013-Aug-04, minor optimization ; ; const char* strchr (const char* s, int c); ; @@ -7,42 +8,45 @@ .export _strchr .import popax .importzp ptr1, tmp1 + .macpack cpu _strchr: - sta tmp1 ; Save c - jsr popax ; get s - sta ptr1 - stx ptr1+1 - ldy #0 + sta tmp1 ; Save c + jsr popax ; get s + tay ; low byte of pointer to y + stx ptr1+1 +.if (.cpu .bitand ::CPU_ISET_65SC02) + stz ptr1 +.else + lda #0 + sta ptr1 ; access from page start, y contains low byte +.endif -Loop: lda (ptr1),y ; Get next char - beq EOS ; Jump on end of string - cmp tmp1 ; Found? - beq Found ; Jump if yes +Loop: lda (ptr1),y ; Get next char + beq EOS ; Jump on end of string + cmp tmp1 ; Found? + beq Found ; Jump if yes iny - bne Loop - inc ptr1+1 - bne Loop ; Branch always + bne Loop + inc ptr1+1 + bne Loop ; Branch always ; End of string. Check if we're searching for the terminating zero -EOS: lda tmp1 ; Get the char we're searching for - bne NotFound ; Jump if not searching for terminator +EOS: + lda tmp1 ; Get the char we're searching for + bne NotFound ; Jump if not searching for terminator -; Found. Calculate pointer to c. +; Found. Set pointer to c. -Found: ldx ptr1+1 ; Load high byte of pointer - tya ; Low byte offset - clc - adc ptr1 - bcc Found1 - inx -Found1: rts +Found: + ldx ptr1+1 ; Load high byte of pointer + tya ; low byte is in y + rts ; Not found, return NULL NotFound: - lda #0 + lda #0 tax rts - diff --git a/libsrc/common/strcspn.s b/libsrc/common/strcspn.s index 8fd567ae4..c9122dc90 100644 --- a/libsrc/common/strcspn.s +++ b/libsrc/common/strcspn.s @@ -1,54 +1,53 @@ ; ; Ullrich von Bassewitz, 11.06.1998 +; Christian Krueger: 05-Aug-2013, optimization ; ; size_t strcspn (const char* s1, const char* s2); ; .export _strcspn - .import popax - .importzp ptr1, ptr2, tmp1, tmp2, tmp3 + .import popax, _strlen + .importzp ptr1, ptr2, tmp1, tmp2 _strcspn: - sta ptr2 ; Save s2 - stx ptr2+1 - jsr popax ; Get s1 - sta ptr1 - stx ptr1+1 - ldx #0 ; low counter byte - stx tmp1 ; high counter byte - ldy #$00 + jsr _strlen ; get length in a/x and transfer s2 to ptr1 + ; Note: It does not make sense to + ; have more than 255 test chars, so + ; we don't support a high byte here! (ptr1+1 is + ; also unchanged in strlen then (important!)) + ; -> the original implementation also + ; ignored this case -L1: lda (ptr1),y ; get next char from s1 - beq L6 ; jump if done - sta tmp2 ; save char + sta tmp1 ; tmp1 = strlen of test chars + jsr popax ; get and save s1 + sta ptr2 ; to ptr2 + stx ptr2+1 + ldx #0 ; low counter byte + stx tmp2 ; high counter byte + +loadChar: + ldy #0 + lda (ptr2),y ; get next char from s1 + beq leave ; handly byte of s1 +advance: + inc ptr2 ; advance string position to test + bne check + inc ptr2+1 + dey ; correct next iny (faster/shorter than bne...) + +checkNext: iny - bne L2 - inc ptr1+1 -L2: sty tmp3 ; save index into s1 +check: cpy tmp1 ; compare with length of test character string + beq endOfTestChars + cmp (ptr1),y ; found matching char? + bne checkNext - ldy #0 ; get index into s2 -L3: lda (ptr2),y ; - beq L4 ; jump if done - cmp tmp2 - beq L6 - iny - bne L3 - -; The character was not found in s2. Increment the counter and start over - -L4: ldy tmp3 ; reload index - inx - bne L1 - inc tmp1 - bne L1 - -; The character was found, or we reached the end of s1. Return count of -; characters - -L6: txa ; get low counter byte - ldx tmp1 ; get high counter byte +leave: txa ; restore position of finding + ldx tmp2 ; and return rts - - - +endOfTestChars: + inx + bne loadChar + inc tmp2 + bne loadChar ; like bra... diff --git a/libsrc/common/strftime.c b/libsrc/common/strftime.c index 25cfd0606..38ea4850e 100644 --- a/libsrc/common/strftime.c +++ b/libsrc/common/strftime.c @@ -53,11 +53,11 @@ size_t __fastcall__ strftime (char* buf, size_t bufsize, const char* format, const struct tm* tm) { - static const char* days[7] = { + static const char* const days[7] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; - static const char* months[12] = { + static const char* const months[12] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; diff --git a/libsrc/common/strlen.s b/libsrc/common/strlen.s index b583eea50..1a51edb11 100644 --- a/libsrc/common/strlen.s +++ b/libsrc/common/strlen.s @@ -1,6 +1,10 @@ ; ; Ullrich von Bassewitz, 31.05.1998 ; +; Note: strspn & strcspn call internally this function and rely on +; the usage of only ptr1 here! Keep in mind when appling changes +; and check the other implementations too! +; ; int strlen (const char* s); ; @@ -23,4 +27,3 @@ L1: lda (ptr1),y L9: tya ; get low byte of counter, hi's all set rts - diff --git a/libsrc/common/strncat.s b/libsrc/common/strncat.s index b7bb04b2a..457e39e25 100644 --- a/libsrc/common/strncat.s +++ b/libsrc/common/strncat.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 31.05.1998 +; Christian Krueger: 12-Aug-2013, minor optimizations ; ; char* strncat (char* dest, const char* src, size_t n); ; @@ -7,66 +8,66 @@ .export _strncat .import popax .importzp ptr1, ptr2, ptr3, tmp1, tmp2 - + .macpack cpu + _strncat: - eor #$FF ; one's complement to count upwards - sta tmp1 - txa - eor #$FF - sta tmp2 - jsr popax ; get src - sta ptr1 - stx ptr1+1 - jsr popax ; get dest - sta ptr2 - stx ptr2+1 - sta ptr3 ; remember for function return - stx ptr3+1 - ldy #0 + eor #$FF ; one's complement to count upwards + sta tmp1 + txa + eor #$FF + sta tmp2 + + jsr popax ; get src + sta ptr1 + stx ptr1+1 + + jsr popax ; get dest + sta ptr3 ; remember for function return + stx ptr3+1 + stx ptr2+1 + tay ; low byte as offset in Y +.if (.cpu .bitand ::CPU_ISET_65SC02) + stz ptr2 +.else + ldx #0 + stx ptr2 ; destination on page boundary +.endif ; find end of dest -L1: lda (ptr2),y - beq L2 - iny - bne L1 - inc ptr2+1 - bne L1 +L1: lda (ptr2),y + beq L2 + iny + bne L1 + inc ptr2+1 + bne L1 -; end found, get offset in y into pointer - -L2: tya - clc - adc ptr2 - sta ptr2 - bcc L3 - inc ptr2+1 +; end found, apply offset to dest ptr and reset y +L2: sty ptr2 ; copy src. We've put the ones complement of the count into the counter, so ; we'll increment the counter on top of the loop -L3: ldy #0 - ldx tmp1 ; low counter byte +L3: ldy #0 + ldx tmp1 ; low counter byte -L4: inx - bne L5 - inc tmp2 - beq L6 ; jump if done -L5: lda (ptr1),y - sta (ptr2),y - beq L7 - iny - bne L4 - inc ptr1+1 - inc ptr2+1 - bne L4 +L4: inx + bne L5 + inc tmp2 + beq L6 ; jump if done +L5: lda (ptr1),y + sta (ptr2),y + beq L7 + iny + bne L4 + inc ptr1+1 + inc ptr2+1 + bne L4 ; done, set the trailing zero and return pointer to dest -L6: lda #0 - sta (ptr2),y -L7: lda ptr3 - ldx ptr3+1 - rts - - +L6: lda #0 + sta (ptr2),y +L7: lda ptr3 + ldx ptr3+1 + rts diff --git a/libsrc/common/strrchr.s b/libsrc/common/strrchr.s index bd7389e76..3e4fb0810 100644 --- a/libsrc/common/strrchr.s +++ b/libsrc/common/strrchr.s @@ -1,47 +1,41 @@ ; ; Ullrich von Bassewitz, 31.05.1998 +; Christian Krueger: 2013-Aug-01, optimization ; ; char* strrchr (const char* s, int c); ; .export _strrchr .import popax - .importzp ptr1, ptr2, tmp1 + .importzp ptr1, tmp1, tmp2 _strrchr: - sta tmp1 ; Save c - jsr popax ; get s - sta ptr1 - stx ptr1+1 - lda #0 ; function result = NULL - sta ptr2 - sta ptr2+1 - tay + sta tmp1 ; Save c + jsr popax ; get s + tay ; low byte to y + stx ptr1+1 + ldx #0 ; default function result is NULL, X is high byte... + stx tmp2 ; tmp2 is low-byte + stx ptr1 ; low-byte of source string is in Y, so clear real one... + +testChar: + lda (ptr1),y ; get char + beq finished ; jump if end of string + cmp tmp1 ; found? + bne nextChar ; jump if no -L1: lda (ptr1),y ; get next char - beq L3 ; jump if end of string - cmp tmp1 ; found? - bne L2 ; jump if no +charFound: + sty tmp2 ; y has low byte of location, save it + ldx ptr1+1 ; x holds high-byte of result -; Remember a pointer to the character +nextChar: + iny + bne testChar + inc ptr1+1 + bne testChar ; here like bra... - tya - clc - adc ptr1 - sta ptr2 - lda ptr1+1 - adc #$00 - sta ptr2+1 +; return the pointer to the last occurrence -; Next char - -L2: iny - bne L1 - inc ptr1+1 - bne L1 ; jump always - -; Return the pointer to the last occurrence - -L3: lda ptr2 - ldx ptr2+1 +finished: + lda tmp2 ; high byte in X is already correct... rts diff --git a/libsrc/common/strspn.s b/libsrc/common/strspn.s index f8b8fff2a..079b935ee 100644 --- a/libsrc/common/strspn.s +++ b/libsrc/common/strspn.s @@ -1,56 +1,53 @@ ; ; Ullrich von Bassewitz, 11.06.1998 +; Christian Krueger: 08-Aug-2013, optimization ; ; size_t strspn (const char* s1, const char* s2); ; .export _strspn - .import popax - .importzp ptr1, ptr2, tmp1, tmp2, tmp3 + .import popax, _strlen + .importzp ptr1, ptr2, tmp1, tmp2 _strspn: - sta ptr2 ; Save s2 - stx ptr2+1 - jsr popax ; get s1 - sta ptr1 - stx ptr1+1 - ldx #0 ; low counter byte - stx tmp1 ; high counter byte - ldy #$00 + jsr _strlen ; get length in a/x and transfer s2 to ptr1 + ; Note: It does not make sense to + ; have more than 255 test chars, so + ; we don't support a high byte here! (ptr1+1 is + ; also unchanged in strlen then (important!)) + ; -> the original implementation also + ; ignored this case -L1: lda (ptr1),y ; get next char from s1 - beq L6 ; jump if done - sta tmp2 ; save char + sta tmp1 ; tmp1 = strlen of test chars + jsr popax ; get and save s1 + sta ptr2 ; to ptr2 + stx ptr2+1 + ldx #0 ; low counter byte + stx tmp2 ; high counter byte + +loadChar: + ldy #0 + lda (ptr2),y ; get next char from s1 + beq leave ; handly byte of s1 +advance: + inc ptr2 ; advance string position to test + bne check + inc ptr2+1 + dey ; correct next iny (faster/shorter than bne...) + +checkNext: iny - bne L2 - inc ptr1+1 -L2: sty tmp3 ; save index into s1 +check: cpy tmp1 ; compare with length of test character string + beq leave + cmp (ptr1),y ; found matching char? + bne checkNext - ldy #0 ; get index into s2 -L3: lda (ptr2),y ; - beq L6 ; jump if done - cmp tmp2 - beq L4 - iny - bne L3 - -; The character was found in s2. Increment the counter and start over - -L4: ldy tmp3 ; reload index +foundTestChar: inx - bne L1 - inc tmp1 - bne L1 + bne loadChar + inc tmp2 + bne loadChar ; like bra... -; The character was not found, or we reached the end of s1. Return count of -; characters - -L6: txa ; get low counter byte - ldx tmp1 ; get high counter byte +leave: txa ; restore position of finding + ldx tmp2 ; and return rts - - - - - - diff --git a/libsrc/conio/cputs.s b/libsrc/conio/cputs.s index c9ca5df76..ef7c65462 100644 --- a/libsrc/conio/cputs.s +++ b/libsrc/conio/cputs.s @@ -1,8 +1,8 @@ ; ; Ullrich von Bassewitz, 06.08.1998 ; -; void cputsxy (unsigned char x, unsigned char y, char* s); -; void cputs (char* s); +; void cputsxy (unsigned char x, unsigned char y, const char* s); +; void cputs (const char* s); ; .export _cputsxy, _cputs diff --git a/libsrc/creativision/clrscr.s b/libsrc/creativision/clrscr.s index 9e7238345..3c4856446 100644 --- a/libsrc/creativision/clrscr.s +++ b/libsrc/creativision/clrscr.s @@ -18,7 +18,7 @@ _clrscr: lda #$50 ; VRAM offset high ($10 OR $40) sta VDP_CONTROL_W - lda #$C0 ; Space from ROM setup + lda #$40 ; Space char from ROM setup ldx #0 ldy #3 @@ -34,8 +34,8 @@ L1: sta VDP_DATA_W lda #0 sta CURSOR_X sta CURSOR_Y - sta <SCREEN_PTR + sta SCREEN_PTR lda #$10 - sta >SCREEN_PTR + sta SCREEN_PTR+1 rts diff --git a/libsrc/creativision/cputc.s b/libsrc/creativision/cputc.s index ff60494b9..437b738b2 100644 --- a/libsrc/creativision/cputc.s +++ b/libsrc/creativision/cputc.s @@ -96,8 +96,8 @@ BAD_CHAR: jmp plot ;----------------------------------------------------------------------------- -; Initialize the conio subsystem. Code goes into the INIT segment, which may -; be reused after startup. +; Initialize the conio subsystem. "INIT" segment is nothing special on the +; Creativision, it is part of the "ROM" memory. .segment "INIT" @@ -122,4 +122,4 @@ LL: lda boxchars,x bne LL cli - jmp plot + jmp plot diff --git a/libsrc/creativision/crt0.s b/libsrc/creativision/crt0.s index 6faec38eb..5185ff237 100644 --- a/libsrc/creativision/crt0.s +++ b/libsrc/creativision/crt0.s @@ -31,9 +31,6 @@ entry: ldx #<__RAM_START__ - 1 txs - ; Start interrupts - cli - ; Clear the BSS data jsr zerobss @@ -49,13 +46,21 @@ entry: ; Call module constructors jsr initlib + ; enable vertical blank interrupts in the display controller + lda #$E0 ; 16K RAM, Active Display, Mode 1, VBI enabled + ldx #$01 ; Register 1 + jsr BIOS_WRITE_VDP_REG + + ; Start interrupts + cli + ; Call main() jsr callmain ; Call module destructors. This is also the _exit entry. _exit: jsr donelib - ; TODO: Replace with some sort of reset + ; A Creativision program isn't supposed to exit. loop: jmp loop ; ------------------------------------------------------------------------ @@ -81,7 +86,7 @@ irq2: jmp BIOS_IRQ2_ADDR ; VDP Setup ; This sets to Graphics Mode 1 .byte $00 ; Register 0 - .byte $C0 ; Register 1 16K RAM, Active Display, Mode 1 + .byte $C0 ; Register 1 16K RAM, Active Display, Mode 1, VBI disabled .byte $04 ; Register 2 Name Table at $1000 - $12FF .byte $60 ; Register 3 Colour Table at $1800 - $181F .byte $00 ; Register 4 Pattern Table at $0000 - $07FF diff --git a/libsrc/creativision/gotoxy.s b/libsrc/creativision/gotoxy.s index 12ce0abea..588dd83a0 100644 --- a/libsrc/creativision/gotoxy.s +++ b/libsrc/creativision/gotoxy.s @@ -1,15 +1,19 @@ ; -; Ullrich von Bassewitz, 06.08.1998 +; 1998-08-06, Ullrich von Bassewitz +; 2017-06-15, Greg King ; ; void gotoxy (unsigned char x, unsigned char y); ; - .export _gotoxy + .export gotoxy, _gotoxy + .import setcursor .import popa .include "creativision.inc" +gotoxy: jsr popa ; Get Y + .proc _gotoxy sta CURSOR_Y ; Set Y diff --git a/libsrc/creativision/joy/creativision-stdjoy.s b/libsrc/creativision/joy/creativision-stdjoy.s index 37b927d08..9a5afc42b 100644 --- a/libsrc/creativision/joy/creativision-stdjoy.s +++ b/libsrc/creativision/joy/creativision-stdjoy.s @@ -1,60 +1,56 @@ ; ; Standard joystick driver for the Creativision. ; -; Christian Groessler, 2017-02-06 +; Christian Groessler, 2017-03-08 ; - .include "zeropage.inc" + .include "zeropage.inc" - .include "joy-kernel.inc" - .include "joy-error.inc" - .include "creativision.inc" + .include "joy-kernel.inc" + .include "joy-error.inc" + .include "creativision.inc" - .macpack module + .macpack module ; ------------------------------------------------------------------------ ; Header. Includes jump table - module_header _creativisionstd_joy + module_header _creativisionstd_joy ; Driver signature - .byte $6A, $6F, $79 ; "joy" - .byte JOY_API_VERSION ; Driver API version number + .byte $6A, $6F, $79 ; "joy" + .byte JOY_API_VERSION ; Driver API version number ; Library reference - .addr $0000 - -; Button state masks (8 values) - - .byte $10 ; JOY_UP - .byte $04 ; JOY_DOWN - .byte $20 ; JOY_LEFT - .byte $08 ; JOY_RIGHT - .byte $01 ; JOY_FIRE (button #1) - .byte $02 ; JOY_FIRE2 (button #2) - .byte $00 ; Future expansion - .byte $00 ; Future expansion + .addr $0000 ; Jump table. - .addr INSTALL - .addr UNINSTALL - .addr COUNT - .addr READJOY - .addr 0 ; IRQ entry not used + .addr INSTALL + .addr UNINSTALL + .addr COUNT + .addr READJOY + .addr 0 ; IRQ entry not used ; ------------------------------------------------------------------------ ; Constants -JOY_COUNT = 2 ; Number of joysticks we support +JOY_COUNT = 2 ; Number of joysticks we support + +; Symbolic names for joystick masks (similar names like the defines in joystick.h, but not related to them) + +JOY_UP = $10 +JOY_DOWN = $04 +JOY_LEFT = $20 +JOY_RIGHT = $08 ; ------------------------------------------------------------------------ ; Code - .code + .code ; ------------------------------------------------------------------------ ; INSTALL routine. Is called after the driver is loaded into memory. If @@ -63,131 +59,180 @@ JOY_COUNT = 2 ; Number of joysticks we support ; Must return an JOY_ERR_xx code in a/x. ; -INSTALL: - lda #JOY_ERR_OK - ldx #0 -; rts ; Fall through +INSTALL: lda #JOY_ERR_OK + ldx #0 +; rts ; Fall through ; ------------------------------------------------------------------------ ; UNINSTALL routine. Is called before the driver is removed from memory. ; Can do cleanup or whatever. Must not return anything. ; -UNINSTALL: - rts +UNINSTALL: rts ; ------------------------------------------------------------------------ ; COUNT: Return the total number of available joysticks in a/x. ; -COUNT: - lda #<JOY_COUNT - ldx #>JOY_COUNT - rts +COUNT: lda #<JOY_COUNT + ldx #>JOY_COUNT + rts ; ------------------------------------------------------------------------ ; READ: Read a particular joystick passed in A. ; -READJOY: - and #1 ; fix joystick number - bne READJOY_1 ; read right joystick +READJOY: and #1 ; fix joystick number + bne READJOY_1 ; read right joystick ; Read left joystick - ldx ZP_JOY0_DIR - lda ZP_JOY0_BUTTONS - jmp convert ; convert joystick state to sane cc65 values + ldx ZP_JOY0_DIR + lda ZP_JOY0_BUTTONS + jmp convert ; convert joystick state to cc65 values ; Read right joystick -READJOY_1: - - ldx ZP_JOY1_DIR - lda ZP_JOY1_BUTTONS - lsr a - lsr a - ;jmp convert ; convert joystick state to sane cc65 values - ; fall thru... +READJOY_1: ldx ZP_JOY1_DIR + lda ZP_JOY1_BUTTONS + lsr a + lsr a + ;jmp convert ; convert joystick state to cc65 values + ; fall thru... ; ------------------------------------------------------------------------ ; convert: make runtime lib compatible values -; A - buttons -; X - direction +; inputs: +; A - buttons +; X - direction ; convert: - ldy #0 - sty retval ; initialize return value ; ------ ; buttons: - ; Port values are for the left hand joystick (right hand joystick - ; values were shifted to the right to be identical). - ; Why are there two bits indicating a pressed trigger? - ; According to the "Second book of programs for the Dick Smith Wizard" - ; (pg. 88ff), the left hand fire button gives the value of - ; %00010001 and the right hand button gives %00100010 - ; Why two bits? Am I missing something? Can there be cases that just - ; one of those bits is set? - ; We just test if any of those two bits is not zero... +; Port values are for the left hand joystick (right hand joystick +; values were shifted to the right to be identical). +; Why are there two bits indicating a pressed trigger? +; According to the "Second book of programs for the Dick Smith Wizard" +; (pg. 88ff), the left hand button gives the value of +; %00010001 and the right hand button gives %00100010 +; Why two bits? Can there be cases that just one of those bits is set? +; Until these questions have been answered, we only use the lower two +; bits and ignore the upper ones... - tay - and #%00010001 - beq cnv_1 - - inc retval ; left button pressed - -cnv_1: tya - and #%00100010 - beq cnv_2 - - lda #$02 - ora retval - sta retval ; right button pressed + and #%00000011 ; button status came in in A, strip high bits + sta retval ; initialize 'retval' with button status ; ------ ; direction: -cnv_2: txa - ; tested with https://sourceforge.net/projects/creativisionemulator - ; $49 - %01001001 - up - ; $41 - %01000001 - down - ; $4D - %01001101 - left - ; $45 - %01000101 - right - ; - ; are these correct? "Second book of programs for the Dick Smith Wizard" pg. 85 says something different - ; ignored for now... - ; $85 - %10000101 - up + right - ; $8D - %10001101 - down + left - ; $89 - %10001001 - up + left - ; $85 - %10000101 - down + right (emulator bug?) +; CV has a 16-direction joystick +; +; port values: (compass points) +; N - $49 - %01001001 +; NNE - $48 - %01001000 +; NE - $47 - %01000111 +; ENE - $46 - %01000110 +; E - $45 - %01000101 +; ESE - $44 - %01000100 +; SE - $43 - %01000011 +; SSE - $42 - %01000010 +; S - $41 - %01000001 +; SSW - $40 - %01000000 +; SW - $4F - %01001111 +; WSW - $4E - %01001110 +; W - $4D - %01001101 +; WNW - $4C - %01001100 +; NW - $4B - %01001011 +; NNW - $4A - %01001010 +; center - $00 - %00000000 +; +; mapping to cc65 definitions (4-direction joystick with 8 possible directions thru combinations) +; N, E, S, W -> JOY_UP, JOY_RIGHT, JOY_DOWN, JOY_LEFT +; NE, SE, SW, NW -> (JOY_UP | JOY_RIGHT), (JOY_DOWN | JOY_RIGHT), (JOY_DOWN | JOY_LEFT), (JOY_UP | JOY_LEFT) +; NNE, ENE, ESE, SSE, SSW, WSW, WNW, NNW: +; toggle between straight and diagonal direction for every call, e.g. +; NNE: +; call to READJOY: return JOY_UP | JOY_RIGHT +; call to READJOY: return JOY_UP +; call to READJOY: return JOY_UP | JOY_RIGHT +; call to READJOY: return JOY_UP +; call to READJOY: return JOY_UP | JOY_RIGHT +; etc... - bit testbit ; bit #0 set? - beq done ; no, no direction + txa ; move direction status into A + beq done ; center position (no bits are set), nothing to do - and #%00001100 ; mask out other bits - lsr a - lsr a - tax - lda #%00000100 ; init bitmask -loop: dex - bmi done2 - asl a - bne loop + and #$0F ; get rid of the "$40" bit + bit bit0 ; is it a "three letter" direction (NNE, ENE, etc.)? + beq special ; yes (bit #0 is zero) -done2: ora retval - rts + lsr a ; create index into table + tax + lda dirtable,x +done: ora retval ; include "button" bits + ldx #0 + rts -done: lda retval - rts +; NNE, ENE, ESE, SSE, SSW, WSW, WNW, NNW + +special: lsr a + tax + + lda toggler ; toggle the toggler + eor #$01 + sta toggler + bne spec_1 ; toggler is 1, use spectable_1 entry + + lda spectable_0,x ; toggler is 0, use spectable_0 entry + bne done ; jump always + +spec_1: lda spectable_1,x + bne done ; jump always ; ------------------------------------------------------------------------ ; - .data -testbit:.byte $01 + .rodata + + ; a mapping table of "port values" to "cc65 values" + ; port value had been shifted one bit to the right (range 0..7) +dirtable: .byte JOY_DOWN ; S + .byte JOY_DOWN | JOY_RIGHT ; SE + .byte JOY_RIGHT ; E + .byte JOY_UP | JOY_RIGHT ; NE + .byte JOY_UP ; N + .byte JOY_UP | JOY_LEFT ; NW + .byte JOY_LEFT ; W + .byte JOY_DOWN | JOY_LEFT ; SW + + ; two "special" mapping tables for three-letter directions (NNE, etc.) +spectable_0: .byte JOY_DOWN ; SSW + .byte JOY_DOWN ; SSE + .byte JOY_RIGHT ; ESE + .byte JOY_RIGHT ; ENE + .byte JOY_RIGHT ; NNE + .byte JOY_UP ; NNW + .byte JOY_LEFT ; WNW + .byte JOY_LEFT ; WSW + +spectable_1: .byte JOY_DOWN | JOY_LEFT ; SSW + .byte JOY_DOWN | JOY_RIGHT ; SSE + .byte JOY_DOWN | JOY_RIGHT ; ESE + .byte JOY_UP | JOY_RIGHT ; ENE + .byte JOY_UP | JOY_RIGHT ; NNE + .byte JOY_UP | JOY_LEFT ; NNW + .byte JOY_UP | JOY_LEFT ; WNW + .byte JOY_DOWN | JOY_LEFT ; WSW ; ------------------------------------------------------------------------ ; - .bss -retval: .res 0 +bit0: .byte $01 + +; ------------------------------------------------------------------------ +; + .bss +toggler: .res 1 +retval: .res 1 + + .end diff --git a/libsrc/creativision/mainargs.s b/libsrc/creativision/mainargs.s deleted file mode 100644 index cda76d8d0..000000000 --- a/libsrc/creativision/mainargs.s +++ /dev/null @@ -1,22 +0,0 @@ -; -; Ullrich von Bassewitz, 2003-03-07 -; -; Setup arguments for main -; - - - .constructor initmainargs, 24 - .import __argc, __argv - - -;--------------------------------------------------------------------------- -; Get possible command-line arguments. Goes into the special INIT segment, -; which may be reused after the startup code is run - -.segment "INIT" - -.proc initmainargs - - rts - -.endproc diff --git a/libsrc/dbg/dbg.c b/libsrc/dbg/dbg.c index 8b09484f6..60b452799 100644 --- a/libsrc/dbg/dbg.c +++ b/libsrc/dbg/dbg.c @@ -32,7 +32,7 @@ static char DumpHandler (void); static char HelpHandler (void); /* Forwards for other functions */ -static void DisplayPrompt (char* s); +static void DisplayPrompt (const char* s); static void SingleStep (char StepInto); static void RedrawStatic (char Frame); static void Redraw (char Frame); @@ -166,7 +166,7 @@ extern unsigned DbgHI; /* High 16 bit of primary reg */ typedef struct { unsigned char x; unsigned char y; - char* text; + const char* text; } TextDesc; /* Window descriptor */ @@ -181,13 +181,13 @@ typedef struct { unsigned char fd_visible; /* Is the window currently visible? */ char (*fd_func) (void); /* Handler function */ unsigned char fd_textcount; /* Number of text lines to print */ - TextDesc* fd_text; /* Static text in the window */ + const TextDesc* fd_text; /* Static text in the window */ } FrameDesc; /* Texts for the windows */ -static TextDesc RegText [] = { +static const TextDesc RegText [] = { { 1, 0, "PC" }, { 1, 1, "SR" }, { 1, 2, "A" }, @@ -197,7 +197,7 @@ static TextDesc RegText [] = { { 1, 6, "CS" }, { 1, 7, "HI" } }; -static TextDesc HelpText [] = { +static const TextDesc HelpText [] = { { 1, 0, "F1, ? Help" }, { 1, 1, "F2, t Toggle breakpoint" }, { 1, 2, "F3, u Run until subroutine returns" }, @@ -220,7 +220,7 @@ static TextDesc HelpText [] = { /* Window data */ -static FrameDesc AsmFrame = { +static const FrameDesc AsmFrame = { CH_ULCORNER, CH_TTEE, CH_LTEE, CH_CROSS, 0, 0, MAX_X - 10, 15, MAX_X - 11, 14, @@ -228,7 +228,7 @@ static FrameDesc AsmFrame = { AsmHandler, 0, 0 }; -static FrameDesc RegFrame = { +static const FrameDesc RegFrame = { CH_TTEE, CH_URCORNER, CH_LTEE, CH_RTEE, MAX_X - 10, 0, MAX_X - 1, 9, 8, 8, @@ -236,7 +236,7 @@ static FrameDesc RegFrame = { RegHandler, sizeof (RegText) / sizeof (RegText [0]), RegText }; -static FrameDesc StackFrame = { +static const FrameDesc StackFrame = { CH_LTEE, CH_RTEE, CH_CROSS, CH_RTEE, MAX_X - 10, 9, MAX_X - 1, 15, 8, 5, @@ -244,7 +244,7 @@ static FrameDesc StackFrame = { StackHandler, 0, 0 }; -static FrameDesc CStackFrame = { +static const FrameDesc CStackFrame = { CH_CROSS, CH_RTEE, CH_BTEE, CH_LRCORNER, MAX_X - 10, 15, MAX_X - 1, MAX_Y - 1, 8, MAX_Y - 17, @@ -252,7 +252,7 @@ static FrameDesc CStackFrame = { CStackHandler, 0, 0 }; -static FrameDesc DumpFrame = { +static const FrameDesc DumpFrame = { CH_LTEE, CH_CROSS, CH_LLCORNER, CH_BTEE, 0, 15, MAX_X - 10, MAX_Y-1, MAX_X - 11, MAX_Y - 17, @@ -260,7 +260,7 @@ static FrameDesc DumpFrame = { DumpHandler, 0, 0 }; -static FrameDesc HelpFrame = { +static const FrameDesc HelpFrame = { CH_ULCORNER, CH_URCORNER, CH_LLCORNER, CH_LRCORNER, 0, 0, MAX_X - 1, MAX_Y-1, MAX_X - 2, MAX_Y - 2, @@ -268,7 +268,7 @@ static FrameDesc HelpFrame = { HelpHandler, sizeof (HelpText) / sizeof (HelpText [0]), HelpText }; -static FrameDesc* Frames [] = { +static const FrameDesc* const Frames [] = { &AsmFrame, &RegFrame, &StackFrame, @@ -297,7 +297,7 @@ static unsigned char StackAddr; /* Start address of output */ /* Prompt line data */ -static char* ActivePrompt = 0; /* Last prompt line displayed */ +static const char* ActivePrompt = 0; /* Last prompt line displayed */ static char PromptColor; /* Color behind prompt */ static char PromptLength; /* Length of current prompt string */ @@ -346,10 +346,10 @@ BreakPoint* DbgIsBreak (unsigned Addr); -static void DrawFrame (register FrameDesc* F, char Active) +static void DrawFrame (register const FrameDesc* F, char Active) /* Draw one window frame */ { - TextDesc* T; + const TextDesc* T; unsigned char Count; unsigned char tl, tr, bl, br; unsigned char x1, y1, width; @@ -410,7 +410,7 @@ static void DrawFrames (void) /* Draw all frames */ { unsigned char I; - FrameDesc* F; + const FrameDesc* F; /* Build the frame layout of the screen */ for (I = 0; I < sizeof (Frames) / sizeof (Frames [0]); ++I) { @@ -427,7 +427,7 @@ static void ActivateFrame (int Num, unsigned char Clear) /* Activate a new frame, deactivate the old one */ { unsigned char y; - register FrameDesc* F; + register const FrameDesc* F; if (ActiveFrame != Num) { @@ -462,7 +462,7 @@ static void ActivateFrame (int Num, unsigned char Clear) -static void DisplayPrompt (char* s) +static void DisplayPrompt (const char* s) /* Display a prompt */ { unsigned char OldColor; @@ -626,11 +626,11 @@ static char InputHex (char* Prompt, unsigned* Val) -static void ErrorPrompt (char* Msg) +static void ErrorPrompt (const char* Msg) /* Display an error message and wait for a key */ { /* Save the current prompt */ - char* OldPrompt = ActivePrompt; + const char* OldPrompt = ActivePrompt; /* Display the new one */ DisplayPrompt (Msg); diff --git a/libsrc/gamate/gotoxy.s b/libsrc/gamate/gotoxy.s index 4a4871444..d49bd2967 100644 --- a/libsrc/gamate/gotoxy.s +++ b/libsrc/gamate/gotoxy.s @@ -9,7 +9,7 @@ .include "extzp.inc" gotoxy: - jsr popa ; Get X + jsr popa ; Get Y _gotoxy: sta CURS_Y ; Set Y @@ -20,6 +20,4 @@ _gotoxy: ;------------------------------------------------------------------------------- ; force the init constructor to be imported - .import initconio -conio_init = initconio - + .forceimport initconio diff --git a/libsrc/gamate/joy/gamate-stdjoy.s b/libsrc/gamate/joy/gamate-stdjoy.s index 8b18bae7a..d10eb6f41 100644 --- a/libsrc/gamate/joy/gamate-stdjoy.s +++ b/libsrc/gamate/joy/gamate-stdjoy.s @@ -24,17 +24,6 @@ .addr $0000 -; Button state masks (8 values) - - .byte $01 ; JOY_UP - .byte $02 ; JOY_DOWN - .byte $04 ; JOY_LEFT - .byte $08 ; JOY_RIGHT - .byte $10 ; JOY_FIRE_A - .byte $20 ; JOY_FIRE_B - .byte $80 ; JOY_SELECT - .byte $40 ; JOY_START - ; Jump table. .addr INSTALL diff --git a/libsrc/gamate/waitvblank.s b/libsrc/gamate/waitvsync.s similarity index 67% rename from libsrc/gamate/waitvblank.s rename to libsrc/gamate/waitvsync.s index 66686c08a..dee83400d 100644 --- a/libsrc/gamate/waitvblank.s +++ b/libsrc/gamate/waitvsync.s @@ -1,16 +1,18 @@ ; -; void waitvblank (void); +; Written by Groepaz <groepaz@gmx.net> +; +; void waitvsync (void); ; .include "gamate.inc" .include "extzp.inc" .forceimport ticktock - .export _waitvblank + .export _waitvsync ; FIXME: is this actually correct? -.proc _waitvblank +.proc _waitvsync lda tickcount @lp: cmp tickcount diff --git a/libsrc/geos-cbm/joy/geos-stdjoy.s b/libsrc/geos-cbm/joy/geos-stdjoy.s index 6afe46092..2787cb594 100644 --- a/libsrc/geos-cbm/joy/geos-stdjoy.s +++ b/libsrc/geos-cbm/joy/geos-stdjoy.s @@ -28,17 +28,6 @@ .addr $0000 -; Button state masks (8 values) - - .byte $01 ; JOY_UP - .byte $02 ; JOY_DOWN - .byte $04 ; JOY_LEFT - .byte $08 ; JOY_RIGHT - .byte $10 ; JOY_FIRE - .byte $00 ; Future expansion - .byte $00 ; Future expansion - .byte $00 ; Future expansion - ; Jump table. .word INSTALL diff --git a/libsrc/geos-common/dlgbox/messagebox.c b/libsrc/geos-common/dlgbox/messagebox.c index 533267be1..fd4a5cd11 100644 --- a/libsrc/geos-common/dlgbox/messagebox.c +++ b/libsrc/geos-common/dlgbox/messagebox.c @@ -10,21 +10,21 @@ void _mbprintout(void); -static dlgBoxStr _mbdlg_EMPTY = { +static const dlgBoxStr _mbdlg_EMPTY = { DB_DEFPOS(1), DB_OPVEC(&RstrFrmDialogue), DB_USRROUT(&_mbprintout), DB_END, }; -static dlgBoxStr _mbdlg_OK = { +static const dlgBoxStr _mbdlg_OK = { DB_DEFPOS(1), DB_USRROUT(&_mbprintout), DB_ICON(OK, DBI_X_1, DBI_Y_2), DB_END, }; -static dlgBoxStr _mbdlg_OKCANCEL = { +static const dlgBoxStr _mbdlg_OKCANCEL = { DB_DEFPOS(1), DB_USRROUT(&_mbprintout), DB_ICON(OK, DBI_X_0, DBI_Y_2), @@ -32,7 +32,7 @@ static dlgBoxStr _mbdlg_OKCANCEL = { DB_END, }; -static dlgBoxStr _mbdlg_YESNO = { +static const dlgBoxStr _mbdlg_YESNO = { DB_DEFPOS(1), DB_USRROUT(&_mbprintout), DB_ICON(YES, DBI_X_0, DBI_Y_2), @@ -40,7 +40,7 @@ static dlgBoxStr _mbdlg_YESNO = { DB_END, }; -static dlgBoxStr *_mbboxes[] = { +static const dlgBoxStr * const _mbboxes[] = { &_mbdlg_EMPTY, &_mbdlg_OK, &_mbdlg_OKCANCEL, diff --git a/libsrc/joystick/joy-kernel.s b/libsrc/joystick/joy-kernel.s index 2b1dcf884..0746709e9 100644 --- a/libsrc/joystick/joy-kernel.s +++ b/libsrc/joystick/joy-kernel.s @@ -19,8 +19,6 @@ .bss _joy_drv: .res 2 ; Pointer to driver -_joy_masks: .res .sizeof(JOY_HDR::MASKS) - ; Jump table for the driver functions. .data joy_vectors: @@ -65,38 +63,28 @@ _joy_install: lda #>joy_libref sta (ptr1),y -; Copy the mask array - - ldy #JOY_HDR::MASKS + .sizeof(JOY_HDR::MASKS) - 1 - ldx #.sizeof(JOY_HDR::MASKS)-1 -@L1: lda (ptr1),y - sta _joy_masks,x - dey - dex - bpl @L1 - ; Copy the jump vectors ldy #JOY_HDR::JUMPTAB ldx #0 -@L2: inx ; Skip the JMP opcode +@L1: inx ; Skip the JMP opcode jsr copy ; Copy one byte jsr copy ; Copy one byte cpy #(JOY_HDR::JUMPTAB + .sizeof(JOY_HDR::JUMPTAB)) - bne @L2 + bne @L1 jsr joy_install ; Call driver install routine tay ; Test error code - bne @L3 ; Bail out if install had errors + bne @L2 ; Bail out if install had errors ; Install the IRQ vector if the driver needs it. A/X contains the error code ; from joy_install, so don't use it. ldy joy_irq+2 ; Check high byte of IRQ vector - beq @L3 ; Jump if vector invalid + beq @L2 ; Jump if vector invalid ldy #$4C ; JMP opcode sty joy_irq ; Activate IRQ routine -@L3: rts +@L2: rts ; Driver signature invalid diff --git a/libsrc/lynx/joy/lynx-stdjoy.s b/libsrc/lynx/joy/lynx-stdjoy.s index 114647072..2e91cc43b 100644 --- a/libsrc/lynx/joy/lynx-stdjoy.s +++ b/libsrc/lynx/joy/lynx-stdjoy.s @@ -31,18 +31,6 @@ .addr $0000 -; Button state masks (8 values) - -joy_mask: - .byte $80 ; JOY_UP - .byte $40 ; JOY_DOWN - .byte $20 ; JOY_LEFT - .byte $10 ; JOY_RIGHT - .byte $01 ; JOY_FIRE - .byte $02 ; JOY_FIRE1 - .byte $00 ; - .byte $00 ; - ; Jump table. .addr INSTALL diff --git a/libsrc/nes/joy/nes-stdjoy.s b/libsrc/nes/joy/nes-stdjoy.s index b5e653c16..3032e9330 100644 --- a/libsrc/nes/joy/nes-stdjoy.s +++ b/libsrc/nes/joy/nes-stdjoy.s @@ -29,17 +29,6 @@ .addr $0000 -; Button state masks (8 values) - - .byte $10 ; JOY_UP - .byte $20 ; JOY_DOWN - .byte $40 ; JOY_LEFT - .byte $80 ; JOY_RIGHT - .byte $01 ; JOY_FIRE (A) - .byte $02 ; JOY_FIRE2 (B) - .byte $04 ; (Select) - .byte $08 ; (Start) - ; Jump table. .addr INSTALL diff --git a/libsrc/nes/waitvblank.s b/libsrc/nes/waitvsync.s similarity index 56% rename from libsrc/nes/waitvblank.s rename to libsrc/nes/waitvsync.s index 408646904..4bdf9a9d0 100644 --- a/libsrc/nes/waitvblank.s +++ b/libsrc/nes/waitvsync.s @@ -1,15 +1,15 @@ ; -; Written by Groepaz/Hitmen <groepaz@gmx.net> +; Written by Groepaz <groepaz@gmx.net> ; Cleanup by Ullrich von Bassewitz <uz@cc65.org> ; -; void waitvblank(void); +; void waitvsync(void); ; - .export _waitvblank + .export _waitvsync .include "nes.inc" -.proc _waitvblank +.proc _waitvsync wait: lda PPU_STATUS bpl wait diff --git a/libsrc/osic1p/cgetc.s b/libsrc/osic1p/cgetc.s index 9161645c7..f05ad33e0 100644 --- a/libsrc/osic1p/cgetc.s +++ b/libsrc/osic1p/cgetc.s @@ -1,50 +1,50 @@ -; -; char cgetc (void); -; - - .constructor initcgetc - .export _cgetc - .import cursor - - .include "osic1p.inc" - .include "extzp.inc" - .include "zeropage.inc" - -; Initialize one-character buffer that is filled by kbhit() - .segment "ONCE" -initcgetc: - lda #$00 - sta CHARBUF ; No character in buffer initially - rts - -; Input routine from 65V PROM MONITOR, show cursor if enabled - .code -_cgetc: - lda CHARBUF ; character in buffer available? - beq nobuffer - tax ; save character in X - lda #$00 - sta CHARBUF ; empty buffer - beq restorex ; restore X and return -nobuffer: - lda cursor ; show cursor? - beq nocursor - ldy CURS_X - lda (SCREEN_PTR),y ; fetch current character - sta tmp1 ; save it - lda #$A1 ; full white square - sta (SCREEN_PTR),y ; store at cursor position -nocursor: - jsr INPUTC ; get input character in A - ldx cursor - beq done ; was cursor on? - tax ; save A in X - lda tmp1 ; fetch saved character - ldy CURS_X - sta (SCREEN_PTR),y ; store at cursor position - -restorex: - txa ; restore saved character from X -done: - ldx #$00 ; high byte of int return value - rts +; +; char cgetc (void); +; + + .constructor initcgetc + .export _cgetc + .import cursor + + .include "osic1p.inc" + .include "extzp.inc" + .include "zeropage.inc" + +; Initialize one-character buffer that is filled by kbhit() + .segment "ONCE" +initcgetc: + lda #$00 + sta CHARBUF ; No character in buffer initially + rts + +; Input routine from 65V PROM MONITOR, show cursor if enabled + .code +_cgetc: + lda CHARBUF ; character in buffer available? + beq nobuffer + tax ; save character in X + lda #$00 + sta CHARBUF ; empty buffer + beq restorex ; restore X and return +nobuffer: + lda cursor ; show cursor? + beq nocursor + ldy CURS_X + lda (SCREEN_PTR),y ; fetch current character + sta tmp1 ; save it + lda #$A1 ; full white square + sta (SCREEN_PTR),y ; store at cursor position +nocursor: + jsr INPUTC ; get input character in A + ldx cursor + beq done ; was cursor on? + tax ; save A in X + lda tmp1 ; fetch saved character + ldy CURS_X + sta (SCREEN_PTR),y ; store at cursor position + +restorex: + txa ; restore saved character from X +done: + ldx #$00 ; high byte of int return value + rts diff --git a/libsrc/osic1p/doesclrscr.s b/libsrc/osic1p/doesclrscr.s new file mode 100644 index 000000000..3d15e8ade --- /dev/null +++ b/libsrc/osic1p/doesclrscr.s @@ -0,0 +1,14 @@ +; +; 2016-06, Christian Groessler +; 2017-06-26, Greg King +; +; unsigned char doesclrscrafterexit (void); +; +; Returns 0/1 if, after program termination, the screen isn't/is cleared. +; + + .import return1 + +; cc65's OSI programs return to the monitor ROM which clears the screen. + + .export _doesclrscrafterexit := return1 diff --git a/libsrc/osic1p/osic1p.inc b/libsrc/osic1p/osic1p.inc index eabeaf79e..aaa03ba61 100644 --- a/libsrc/osic1p/osic1p.inc +++ b/libsrc/osic1p/osic1p.inc @@ -1,4 +1,4 @@ -; Addresses -INPUTC := $FD00 ; Input character from keyboard -RESET := $FF00 ; Reset address, show boot prompt -KBD := $DF00 ; Polled keyboard register +; Addresses +INPUTC := $FD00 ; Input character from keyboard +RESET := $FF00 ; Reset address, show boot prompt +KBD := $DF00 ; Polled keyboard register diff --git a/libsrc/osic1p/osiscreen.inc b/libsrc/osic1p/osiscreen.inc index fc8324781..9399d7eee 100644 --- a/libsrc/osic1p/osiscreen.inc +++ b/libsrc/osic1p/osiscreen.inc @@ -1,183 +1,183 @@ -; -; Macro definitions for screen layout modules -; - - .include "extzp.inc" - -.linecont + - -; -; Internal function for screensize() -; -.macro osi_screensize ScrWidth, ScrHeight - ; Macro implementation of internal screensize - ; function for given width and height in - ; characters - - .export screensize - -.proc screensize - ldx #ScrWidth - ldy #ScrHeight - rts -.endproc -.endmacro - -; -; void clrscr (void); -; -.macro osi_clrscr ScrBase, ScrRamSize - - .export _clrscr - -.proc _clrscr - lda #<ScrBase ; Fill whole video RAM with blanks by calling - ldx #>ScrBase ; memset appropriately - jsr pushax - - lda #' ' - ldx #$00 - jsr pushax - - lda #<ScrRamSize - ldx #>ScrRamSize - jsr _memset - - lda #$00 ; Cursor in upper left corner - sta CURS_X - sta CURS_Y - - jmp plot ; Set the cursor position -.endproc - -.endmacro - -; -; cputc/cputcxy for Challenger 1P -; Based on PET/CBM implementation -; - -.macro osi_cputfuncs ScrBase, ScrFirstChar, ScrWidth, ScrHeight, \ - ScrollDist, ScrLo, ScrHi - - ; Number of characters to move for scrolling - ; by one line -ScrollLength = (ScrHeight - 1) * ScrollDist - -; -; void cputcxy (unsigned char x, unsigned char y, char c); -; void cputc (char c); -; - .export _cputcxy, _cputc, cputdirect, putchar - .export newline, plot - -_cputcxy: - pha ; Save C - jsr gotoxy ; Set cursor, drop x and y - pla ; Restore C - -; Plot a character - also used as internal function - -_cputc: cmp #$0A ; CR? - bne L1 - lda #0 - sta CURS_X - beq plot ; Recalculate pointers - -L1: cmp #$0D ; LF? - beq newline ; Recalculate pointers - -cputdirect: - jsr putchar ; Write the character to the screen - -; Advance cursor position, register Y contains horizontal position after -; putchar - - cpy #(ScrWidth - 1) ; Check whether line is full - bne L3 - jsr newline ; New line - ldy #$FF ; + cr -L3: iny - sty CURS_X - rts - -newline: - inc CURS_Y - lda CURS_Y - cmp #ScrHeight ; Screen height - bne plot - dec CURS_Y ; Bottom of screen reached, scroll - - ; Scroll destination address - lda #<(ScrBase + ScrFirstChar) - ldx #>(ScrBase + ScrFirstChar) - jsr pushax - - ; Scroll source address - lda #<(ScrBase + ScrFirstChar + ScrollDist) - ldx #>(ScrBase + ScrFirstChar + ScrollDist) - jsr pushax - - ; Number of characters to move - lda #<ScrollLength - ldx #>ScrollLength - jsr _memmove - - ; Address of first character in last line - ; of screen - lda #<(ScrBase + ScrFirstChar + ScrollLength) - sta ptr1 - lda #>(ScrBase + ScrFirstChar + ScrollLength) - sta ptr1+1 - - ldy #ScrWidth ; Fill last line with blanks - lda #' ' -clrln: sta (ptr1),y - dey - bpl clrln - -plot: ldy CURS_Y - lda ScrLo,y - sta SCREEN_PTR - lda ScrHi,y - sta SCREEN_PTR+1 - rts - -; Write one character to the screen without doing anything else, return X -; position in register Y - -putchar: - ldy CURS_X - sta (SCREEN_PTR),y ; Set char - rts - -.endmacro - -.macro osi_screen_funcs ScrBase, ScrRamSize, ScrFirstChar, \ - ScrWidth, ScrHeight, ScrollDist - - .import gotoxy - .import _memmove, _memset, pushax - .importzp ptr1 - -.rodata - -; Screen address tables - offset to real screen -ScrTabLo: - .repeat ScrHeight, I - .byte <(ScrBase + ScrFirstChar + I * ScrollDist) - .endrep - -ScrTabHi: - .repeat ScrHeight, I - .byte >(ScrBase + ScrFirstChar + I * ScrollDist) - .endrep - -.code - -osi_cputfuncs ScrBase, ScrFirstChar, ScrWidth, ScrHeight, \ - ScrollDist, ScrTabLo, ScrTabHi -osi_screensize ScrWidth, ScrHeight -osi_clrscr ScrBase, ScrRamSize - +; +; Macro definitions for screen layout modules +; + + .include "extzp.inc" + +.linecont + + +; +; Internal function for screensize() +; +.macro osi_screensize ScrWidth, ScrHeight + ; Macro implementation of internal screensize + ; function for given width and height in + ; characters + + .export screensize + +.proc screensize + ldx #ScrWidth + ldy #ScrHeight + rts +.endproc +.endmacro + +; +; void clrscr (void); +; +.macro osi_clrscr ScrBase, ScrRamSize + + .export _clrscr + +.proc _clrscr + lda #<ScrBase ; Fill whole video RAM with blanks by calling + ldx #>ScrBase ; memset appropriately + jsr pushax + + lda #' ' + ldx #$00 + jsr pushax + + lda #<ScrRamSize + ldx #>ScrRamSize + jsr _memset + + lda #$00 ; Cursor in upper left corner + sta CURS_X + sta CURS_Y + + jmp plot ; Set the cursor position +.endproc + +.endmacro + +; +; cputc/cputcxy for Challenger 1P +; Based on PET/CBM implementation +; + +.macro osi_cputfuncs ScrBase, ScrFirstChar, ScrWidth, ScrHeight, \ + ScrollDist, ScrLo, ScrHi + + ; Number of characters to move for scrolling + ; by one line +ScrollLength = (ScrHeight - 1) * ScrollDist + +; +; void cputcxy (unsigned char x, unsigned char y, char c); +; void cputc (char c); +; + .export _cputcxy, _cputc, cputdirect, putchar + .export newline, plot + +_cputcxy: + pha ; Save C + jsr gotoxy ; Set cursor, drop x and y + pla ; Restore C + +; Plot a character - also used as internal function + +_cputc: cmp #$0A ; CR? + bne L1 + lda #0 + sta CURS_X + beq plot ; Recalculate pointers + +L1: cmp #$0D ; LF? + beq newline ; Recalculate pointers + +cputdirect: + jsr putchar ; Write the character to the screen + +; Advance cursor position, register Y contains horizontal position after +; putchar + + cpy #(ScrWidth - 1) ; Check whether line is full + bne L3 + jsr newline ; New line + ldy #$FF ; + cr +L3: iny + sty CURS_X + rts + +newline: + inc CURS_Y + lda CURS_Y + cmp #ScrHeight ; Screen height + bne plot + dec CURS_Y ; Bottom of screen reached, scroll + + ; Scroll destination address + lda #<(ScrBase + ScrFirstChar) + ldx #>(ScrBase + ScrFirstChar) + jsr pushax + + ; Scroll source address + lda #<(ScrBase + ScrFirstChar + ScrollDist) + ldx #>(ScrBase + ScrFirstChar + ScrollDist) + jsr pushax + + ; Number of characters to move + lda #<ScrollLength + ldx #>ScrollLength + jsr _memmove + + ; Address of first character in last line + ; of screen + lda #<(ScrBase + ScrFirstChar + ScrollLength) + sta ptr1 + lda #>(ScrBase + ScrFirstChar + ScrollLength) + sta ptr1+1 + + ldy #ScrWidth ; Fill last line with blanks + lda #' ' +clrln: sta (ptr1),y + dey + bpl clrln + +plot: ldy CURS_Y + lda ScrLo,y + sta SCREEN_PTR + lda ScrHi,y + sta SCREEN_PTR+1 + rts + +; Write one character to the screen without doing anything else, return X +; position in register Y + +putchar: + ldy CURS_X + sta (SCREEN_PTR),y ; Set char + rts + +.endmacro + +.macro osi_screen_funcs ScrBase, ScrRamSize, ScrFirstChar, \ + ScrWidth, ScrHeight, ScrollDist + + .import gotoxy + .import _memmove, _memset, pushax + .importzp ptr1 + +.rodata + +; Screen address tables - offset to real screen +ScrTabLo: + .repeat ScrHeight, I + .byte <(ScrBase + ScrFirstChar + I * ScrollDist) + .endrep + +ScrTabHi: + .repeat ScrHeight, I + .byte >(ScrBase + ScrFirstChar + I * ScrollDist) + .endrep + +.code + +osi_cputfuncs ScrBase, ScrFirstChar, ScrWidth, ScrHeight, \ + ScrollDist, ScrTabLo, ScrTabHi +osi_screensize ScrWidth, ScrHeight +osi_clrscr ScrBase, ScrRamSize + .endmacro \ No newline at end of file diff --git a/libsrc/osic1p/revers.s b/libsrc/osic1p/revers.s new file mode 100644 index 000000000..bb178f647 --- /dev/null +++ b/libsrc/osic1p/revers.s @@ -0,0 +1,9 @@ +; +; 2017-06-26, Greg King +; +; unsigned char __fastcall__ revers (unsigned char onoff) +; + + .import return0 + + .export _revers := return0 ; no attribute diff --git a/libsrc/pce/joy/pce-stdjoy.s b/libsrc/pce/joy/pce-stdjoy.s index 746929dd2..ab25134dd 100644 --- a/libsrc/pce/joy/pce-stdjoy.s +++ b/libsrc/pce/joy/pce-stdjoy.s @@ -24,17 +24,6 @@ .addr $0000 -; Button state masks (8 values) - - .byte $10 ; JOY_UP - .byte $40 ; JOY_DOWN - .byte $80 ; JOY_LEFT - .byte $20 ; JOY_RIGHT - .byte $01 ; JOY_FIRE_A - .byte $02 ; JOY_FIRE_B - .byte $04 ; JOY_SELECT - .byte $08 ; JOY_RUN - ; Jump table. .addr INSTALL diff --git a/libsrc/pce/waitvblank.s b/libsrc/pce/waitvsync.s similarity index 63% rename from libsrc/pce/waitvblank.s rename to libsrc/pce/waitvsync.s index b9f0f902f..c6435dabd 100644 --- a/libsrc/pce/waitvblank.s +++ b/libsrc/pce/waitvsync.s @@ -1,14 +1,16 @@ ; -; void waitvblank (void); +; Written by Groepaz <groepaz@gmx.net> +; +; void waitvsync (void); ; .include "pce.inc" .include "extzp.inc" .forceimport ticktock - .export _waitvblank + .export _waitvsync -.proc _waitvblank +.proc _waitvsync lda tickcount @lp: cmp tickcount diff --git a/libsrc/pet/joy/pet-ptvjoy.s b/libsrc/pet/joy/pet-ptvjoy.s index 229055fcb..3bb368355 100644 --- a/libsrc/pet/joy/pet-ptvjoy.s +++ b/libsrc/pet/joy/pet-ptvjoy.s @@ -28,17 +28,6 @@ .addr $0000 -; Button state masks (8 values) - - .byte $01 ; JOY_UP - .byte $02 ; JOY_DOWN - .byte $04 ; JOY_LEFT - .byte $08 ; JOY_RIGHT - .byte $10 ; JOY_FIRE - .byte $00 ; JOY_FIRE2 unavailable - .byte $00 ; Future expansion - .byte $00 ; Future expansion - ; Jump table. .addr INSTALL diff --git a/libsrc/pet/joy/pet-stdjoy.s b/libsrc/pet/joy/pet-stdjoy.s index 5847c2b09..29c6de627 100644 --- a/libsrc/pet/joy/pet-stdjoy.s +++ b/libsrc/pet/joy/pet-stdjoy.s @@ -27,17 +27,6 @@ .addr $0000 -; Button state masks (8 values) - - .byte $01 ; JOY_UP - .byte $02 ; JOY_DOWN - .byte $04 ; JOY_LEFT - .byte $08 ; JOY_RIGHT - .byte $10 ; JOY_FIRE - .byte $00 ; JOY_FIRE2 unavailable - .byte $00 ; Future expansion - .byte $00 ; Future expansion - ; Jump table. .addr INSTALL diff --git a/libsrc/pet/kbrepeat.s b/libsrc/pet/kbrepeat.s new file mode 100644 index 000000000..100d8502a --- /dev/null +++ b/libsrc/pet/kbrepeat.s @@ -0,0 +1,29 @@ +; +; unsigned char __fastcall__ kbrepeat (unsigned char mode); +; +; 2017-06-16, Groepaz +; 2017-09-05, Greg King +; + + .export _kbrepeat + + .include "pet.inc" + +_kbrepeat: + ldx #>$0000 + ldy SCR_LINELEN + cpy #40 + 1 + bcc L1 ; branch if screen is 40 columns wide + + ldy KBDREPEAT80 ; get old value + sta KBDREPEAT80 ; store new value + tya ; return old value + rts + +L1: tay + lda KBDREPEAT40B ; get REPEAT-key flag (used by some editor ROMs) + lsr a ; move bit 0 into bit 7 + ror a + ora KBDREPEAT40 ; combine with old key-REPEAT flags + sty KBDREPEAT40 + rts diff --git a/libsrc/plus4/joy/plus4-stdjoy.s b/libsrc/plus4/joy/plus4-stdjoy.s index 4a5132887..d998b2699 100644 --- a/libsrc/plus4/joy/plus4-stdjoy.s +++ b/libsrc/plus4/joy/plus4-stdjoy.s @@ -31,17 +31,6 @@ .addr $0000 -; Button state masks (8 values) - - .byte $01 ; JOY_UP - .byte $02 ; JOY_DOWN - .byte $04 ; JOY_LEFT - .byte $08 ; JOY_RIGHT - .byte $80 ; JOY_FIRE - .byte $00 ; JOY_FIRE2 unavailable - .byte $00 ; Future expansion - .byte $00 ; Future expansion - ; Jump table. .addr INSTALL @@ -107,7 +96,7 @@ READ: ldy #%11111011 ; Load index for joystick #1 cli eor #%11111111 -; The fire buttons are in bits 6 and 7. Both of them cannot be %1 together. +; The push buttons are in bits 6 and 7. Both of them cannot be %1 together. ; Therefore, bit 6 can be merged with bit 7. clc diff --git a/libsrc/plus4/kbrepeat.s b/libsrc/plus4/kbrepeat.s new file mode 100644 index 000000000..9c0dc6855 --- /dev/null +++ b/libsrc/plus4/kbrepeat.s @@ -0,0 +1,14 @@ +; +; unsigned char __fastcall__ kbrepeat (unsigned char mode); +; + + .export _kbrepeat + + .include "plus4.inc" + +_kbrepeat: + ldx KBDREPEAT ; get old value + sta KBDREPEAT ; store new value + txa ; return old value + ldx #0 + rts diff --git a/libsrc/plus4/waitvsync.s b/libsrc/plus4/waitvsync.s new file mode 100644 index 000000000..32b81b52b --- /dev/null +++ b/libsrc/plus4/waitvsync.s @@ -0,0 +1,17 @@ +; +; Written by Groepaz <groepaz@gmx.net> +; +; void waitvsync (void); +; + + .export _waitvsync + + .include "plus4.inc" + +_waitvsync: +@l1: + lda TED_VLINEHI + and #$01 + ora TED_VLINELO + bne @l1 + rts diff --git a/libsrc/runtime/add.s b/libsrc/runtime/add.s index 6fb2dacf7..e644671c0 100644 --- a/libsrc/runtime/add.s +++ b/libsrc/runtime/add.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 05.08.1998 +; Christian Krueger, 11-Mar-2017, spend two bytes for one cycle, improved 65SC02 optimization ; ; CC65 runtime: add ints ; @@ -8,32 +9,46 @@ ; called a lot! .export tosadda0, tosaddax - .importzp sp + .importzp sp, tmp1 .macpack cpu tosadda0: ldx #0 tosaddax: - clc -.if (.cpu .bitand CPU_ISET_65SC02) - adc (sp) ; 65SC02 version - saves 2 cycles - ldy #1 -.else - ldy #0 - adc (sp),y ; lo byte - iny -.endif - pha ; save it - txa - adc (sp),y ; hi byte - tax - clc - lda sp - adc #2 - sta sp - bcc L1 - inc sp+1 -L1: pla ; Restore low byte - rts + clc ; (2) +.if (.cpu .bitand ::CPU_ISET_65SC02) + + adc (sp) ; (7) + tay ; (9) + inc sp ; (14) + bne hiadd ; (17) + inc sp+1 ; (-1+5) +hiadd: txa ; (19) + adc (sp) ; (24) + tax ; (26) + inc sp ; (31) + bne done ; (34) + inc sp+1 ; (-1+5) +done: tya ; (36) + +.else + + ldy #0 ; (4) + adc (sp),y ; (9) lo byte + iny ; (11) + sta tmp1 ; (14) save it + txa ; (16) + adc (sp),y ; (21) hi byte + tax ; (23) + clc ; (25) + lda sp ; (28) + adc #2 ; (30) + sta sp ; (33) + bcc L1 ; (36) + inc sp+1 ; (-1+5) +L1: lda tmp1 ; (39) restore low byte + +.endif + rts ; (6502: 45 cycles, 26 bytes <-> 65SC02: 42 cycles, 22 bytes ) diff --git a/libsrc/runtime/along.s b/libsrc/runtime/along.s index 661b3124a..bd3462915 100644 --- a/libsrc/runtime/along.s +++ b/libsrc/runtime/along.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 23.11.2002 +; Christian Krueger, 11-Mar-2017, saved 5 bytes ; ; CC65 runtime: Convert char in ax into a long ; @@ -9,16 +10,11 @@ ; Convert A from char to long in EAX +along: ldx #$ff + cmp #$80 ; Positive? + bcs store ; no, apply $FF + aulong: ldx #0 - stx sreg +store: stx sreg stx sreg+1 rts - -along: cmp #$80 ; Positive? - bcc aulong ; Yes, handle like unsigned type - ldx #$ff - stx sreg - stx sreg+1 - rts - - diff --git a/libsrc/runtime/axlong.s b/libsrc/runtime/axlong.s index 6d97b5025..1fbd53ef0 100644 --- a/libsrc/runtime/axlong.s +++ b/libsrc/runtime/axlong.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 25.10.2000 +; Christian Krueger, 02-Mar-2017, some bytes saved ; ; CC65 runtime: Convert int in ax into a long ; @@ -9,18 +10,12 @@ ; Convert AX from int to long in EAX +axlong: ldy #$ff + cpx #$80 ; Positive? + bcs store ; No, apply $FF + axulong: ldy #0 - sty sreg +store: sty sreg sty sreg+1 rts - -axlong: cpx #$80 ; Positive? - bcc axulong ; Yes, handle like unsigned type - ldy #$ff - sty sreg - sty sreg+1 - rts - - - diff --git a/libsrc/runtime/callptr4.s b/libsrc/runtime/callptr4.s new file mode 100644 index 000000000..9a15609aa --- /dev/null +++ b/libsrc/runtime/callptr4.s @@ -0,0 +1,10 @@ +; +; CC65 runtime: call function via pointer in ptr4 +; + + .export callptr4 + .importzp ptr4 + +callptr4: + jmp (ptr4) ; jump there + diff --git a/libsrc/runtime/laddeq.s b/libsrc/runtime/laddeq.s index 2632ec909..57bec0629 100644 --- a/libsrc/runtime/laddeq.s +++ b/libsrc/runtime/laddeq.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 07.04.2000 +; Christian Krueger, 12-Mar-2017, added 65SC02 optimization ; ; CC65 runtime: += operator ; @@ -10,6 +11,7 @@ .export laddeq1, laddeqa, laddeq .importzp sreg, ptr1, tmp1 + .macpack cpu laddeq1: lda #$01 @@ -20,14 +22,20 @@ laddeqa: stx sreg+1 laddeq: sty ptr1+1 ; Store high byte of address - ldy #$00 ; Address low byte clc +.if (.cpu .bitand ::CPU_ISET_65SC02) + adc (ptr1) + sta (ptr1) + ldy #$01 ; Address byte 1 +.else + ldy #$00 ; Address low byte adc (ptr1),y sta (ptr1),y + iny ; Address byte 1 +.endif pha ; Save byte 0 of result for later - iny ; Address byte 1 txa adc (ptr1),y ; Load byte 1 sta (ptr1),y diff --git a/libsrc/runtime/land.s b/libsrc/runtime/land.s index 506c071a4..6ea4e5bcb 100644 --- a/libsrc/runtime/land.s +++ b/libsrc/runtime/land.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 06.08.1998 +; Christian Krueger, 11-Mar-2017, added 65SC02 optimization ; ; CC65 runtime: and on longs ; @@ -8,17 +9,28 @@ .import addysp1 .importzp sp, sreg, tmp1 + .macpack cpu tosand0ax: +.if (.cpu .bitand ::CPU_ISET_65SC02) + stz sreg + stz sreg+1 +.else ldy #$00 sty sreg sty sreg+1 +.endif tosandeax: +.if (.cpu .bitand ::CPU_ISET_65SC02) + and (sp) ; byte 0 + ldy #1 +.else ldy #0 and (sp),y ; byte 0 - sta tmp1 iny +.endif + sta tmp1 txa and (sp),y ; byte 1 tax diff --git a/libsrc/runtime/leave.s b/libsrc/runtime/leave.s index 8f4e055f5..4a9ff7994 100644 --- a/libsrc/runtime/leave.s +++ b/libsrc/runtime/leave.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 06.08.1998 +; Christian Krueger, 11-Mar-2017, added 65SC02 optimization ; ; CC65 runtime: function epilogue ; @@ -13,6 +14,8 @@ .import addysp .importzp sp + .macpack cpu + leave00: lda #0 leave0: ldx #0 @@ -24,6 +27,20 @@ leavey0: ldx #0 ; return < 256 leavey: jsr addysp ; drop stack frame + +.if (.cpu .bitand ::CPU_ISET_65SC02) + +leave: tay ; save A a sec + lda (sp) ; that's the pushed arg size + sec ; Count the byte, the count's stored in + adc sp + sta sp + bcc L1 + inc sp+1 +L1: tya ; Get return value back + +.else + leave: pha ; save A a sec ldy #0 lda (sp),y ; that's the pushed arg size @@ -33,5 +50,7 @@ leave: pha ; save A a sec bcc L1 inc sp+1 L1: pla ; Get return value back + +.endif rts diff --git a/libsrc/runtime/lmod.s b/libsrc/runtime/lmod.s index 74deb23f0..caeb0c4f6 100644 --- a/libsrc/runtime/lmod.s +++ b/libsrc/runtime/lmod.s @@ -1,6 +1,6 @@ ; ; Ullrich von Bassewitz, 07.08.1998 -; +; Christian Krueger, 11-Mar-2017, added 65SC02 optimization ; CC65 runtime: modulo operation for long signed ints ; @@ -11,10 +11,17 @@ .import poplsargs, udiv32, negeax .importzp sreg, ptr1, ptr2, tmp1, tmp3, tmp4 + .macpack cpu + tosmod0ax: +.if (.cpu .bitand ::CPU_ISET_65SC02) + stz sreg + stz sreg+1 +.else ldy #$00 sty sreg sty sreg+1 +.endif tosmodeax: jsr poplsargs ; Get arguments from stack, adjust sign diff --git a/libsrc/runtime/lmul.s b/libsrc/runtime/lmul.s index 7ad2b2aa4..860d58cba 100644 --- a/libsrc/runtime/lmul.s +++ b/libsrc/runtime/lmul.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 13.08.1998 +; Christian Krueger, 11-Mar-2017, added 65SC02 optimization ; ; CC65 runtime: multiplication for long (unsigned) ints ; @@ -8,20 +9,32 @@ .import addysp1 .importzp sp, sreg, tmp1, tmp2, tmp3, tmp4, ptr1, ptr3, ptr4 + .macpack cpu + tosmul0ax: tosumul0ax: +.if (.cpu .bitand ::CPU_ISET_65SC02) + stz sreg + stz sreg+1 +.else ldy #$00 sty sreg sty sreg+1 +.endif tosmuleax: tosumuleax: mul32: sta ptr1 stx ptr1+1 ; op2 now in ptr1/sreg +.if (.cpu .bitand ::CPU_ISET_65SC02) + lda (sp) + ldy #1 +.else ldy #0 lda (sp),y - sta ptr3 iny +.endif + sta ptr3 lda (sp),y sta ptr3+1 iny diff --git a/libsrc/runtime/lor.s b/libsrc/runtime/lor.s index a74b33059..94ab3c890 100644 --- a/libsrc/runtime/lor.s +++ b/libsrc/runtime/lor.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 06.08.1998 +; Christian Krueger, 11-Mar-2017, added 65SC02 optimization ; ; CC65 runtime: or on longs ; @@ -8,17 +9,28 @@ .import addysp1 .importzp sp, sreg, tmp1 + .macpack cpu tosor0ax: +.if (.cpu .bitand ::CPU_ISET_65SC02) + stz sreg + stz sreg+1 +.else ldy #$00 sty sreg - sty sreg+1 + sty sreg+1 +.endif tosoreax: +.if (.cpu .bitand ::CPU_ISET_65SC02) + ora (sp) + ldy #1 +.else ldy #0 ora (sp),y ; byte 0 - sta tmp1 iny +.endif + sta tmp1 txa ora (sp),y ; byte 1 tax diff --git a/libsrc/runtime/lpop.s b/libsrc/runtime/lpop.s index 7d281db52..ffff5ffc1 100644 --- a/libsrc/runtime/lpop.s +++ b/libsrc/runtime/lpop.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 29.12.1999 +; Christian Krueger, 11-Mar-2017, added 65SC02 optimization ; ; CC65 runtime: long pop ; @@ -8,6 +9,7 @@ .import incsp4 .importzp sp, sreg + .macpack cpu popeax: ldy #3 lda (sp),y @@ -18,8 +20,12 @@ popeax: ldy #3 dey lda (sp),y tax +.if (.cpu .bitand ::CPU_ISET_65SC02) + lda (sp) +.else dey lda (sp),y +.endif jmp incsp4 diff --git a/libsrc/runtime/lpush.s b/libsrc/runtime/lpush.s index 074b4320a..4fed77f05 100644 --- a/libsrc/runtime/lpush.s +++ b/libsrc/runtime/lpush.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 06.08.1998 +; Christian Krueger, 11-Mar-2017, added 65SC02 optimization ; ; CC65 runtime: long push ; @@ -11,13 +12,20 @@ .import decsp4 .importzp sp, sreg + .macpack cpu + pushl0: lda #0 tax push0ax: - ldy #0 +.if (.cpu .bitand ::CPU_ISET_65SC02) + stz sreg + stz sreg+1 +.else + ldy #$00 sty sreg sty sreg+1 +.endif pusheax: pha ; decsp will destroy A (but not X) jsr decsp4 @@ -30,8 +38,12 @@ pusheax: dey txa sta (sp),y - dey pla +.if (.cpu .bitand ::CPU_ISET_65SC02) + sta (sp) +.else + dey sta (sp),y +.endif rts diff --git a/libsrc/runtime/lrsub.s b/libsrc/runtime/lrsub.s index fd519ca4f..928164f40 100644 --- a/libsrc/runtime/lrsub.s +++ b/libsrc/runtime/lrsub.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 05.08.1998 +; Christian Krueger, 11-Mar-2017, added 65SC02 optimization ; ; CC65 runtime: long sub reversed ; @@ -11,18 +12,30 @@ .import addysp1 .importzp sp, sreg, tmp1 + .macpack cpu + tosrsub0ax: +.if (.cpu .bitand ::CPU_ISET_65SC02) + stz sreg + stz sreg+1 +.else ldy #$00 sty sreg sty sreg+1 +.endif -tosrsubeax: - ldy #0 +tosrsubeax: sec +.if (.cpu .bitand ::CPU_ISET_65SC02) + sbc (sp) + ldy #1 +.else + ldy #0 sbc (sp),y ; byte 0 + iny +.endif sta tmp1 ; use as temp storage txa - iny sbc (sp),y ; byte 1 tax iny diff --git a/libsrc/runtime/lsave.s b/libsrc/runtime/lsave.s index fa21e463e..d5f4c45b3 100644 --- a/libsrc/runtime/lsave.s +++ b/libsrc/runtime/lsave.s @@ -1,7 +1,8 @@ ; ; Ullrich von Bassewitz, 08.08.1998 +; Christian Krueger, 11-Mar-2017, optimization ; -; CC65 runtime: save ax into temp storage/restore ax from temp storage +; CC65 runtime: save eax into temp storage/restore eax from temp storage ; .export saveeax, resteax @@ -10,11 +11,10 @@ saveeax: sta regsave stx regsave+1 - lda sreg - sta regsave+2 - lda sreg+1 - sta regsave+3 - lda regsave + ldy sreg + sty regsave+2 + ldy sreg+1 + sty regsave+3 rts resteax: @@ -25,4 +25,3 @@ resteax: ldx regsave+1 lda regsave rts - diff --git a/libsrc/runtime/lsub.s b/libsrc/runtime/lsub.s index 926d52e51..6f80491ca 100644 --- a/libsrc/runtime/lsub.s +++ b/libsrc/runtime/lsub.s @@ -1,6 +1,6 @@ ; ; Ullrich von Bassewitz, 05.08.1998 -; +; Christian Krueger, 11-Mar-2017, ímproved 65SC02 optimization ; CC65 runtime: long sub ; @@ -14,14 +14,19 @@ .macpack cpu tossub0ax: +.if (.cpu .bitand ::CPU_ISET_65SC02) + stz sreg + stz sreg+1 +.else ldy #$00 sty sreg sty sreg+1 +.endif tossubeax: sec eor #$FF -.if (.cpu .bitand CPU_ISET_65SC02) +.if (.cpu .bitand ::CPU_ISET_65SC02) adc (sp) ; 65SC02 version - saves 2 cycles ldy #1 .else diff --git a/libsrc/runtime/lsubeq.s b/libsrc/runtime/lsubeq.s index 9f5853d29..5e3d25783 100644 --- a/libsrc/runtime/lsubeq.s +++ b/libsrc/runtime/lsubeq.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 07.04.2000 +; Christian Krueger, 12-Mar-2017, added 65SC02 optimization ; ; CC65 runtime: -= operator ; @@ -10,6 +11,7 @@ .export lsubeq1, lsubeqa, lsubeq .importzp sreg, ptr1 + .macpack cpu lsubeq1: lda #$01 @@ -20,15 +22,20 @@ lsubeqa: stx sreg+1 lsubeq: sty ptr1+1 ; Store high byte of address - ldy #$00 ; Address low byte + sec - eor #$FF + .if (.cpu .bitand ::CPU_ISET_65SC02) + adc (ptr1) ; Subtract byte 0 + sta (ptr1) + ldy #$01 ; Address byte 1 + .else + ldy #$00 ; Address low byte adc (ptr1),y ; Subtract byte 0 sta (ptr1),y + iny ; Address byte 1 + .endif pha ; Save byte 0 of result for later - - iny ; Address byte 1 txa eor #$FF adc (ptr1),y ; Subtract byte 1 diff --git a/libsrc/runtime/ludiv.s b/libsrc/runtime/ludiv.s index 149c98a78..54af4780e 100644 --- a/libsrc/runtime/ludiv.s +++ b/libsrc/runtime/ludiv.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 17.08.1998 +; Christian Krueger, 11-Mar-2017, added 65SC02 optimization ; ; CC65 runtime: division for long unsigned ints ; @@ -8,10 +9,17 @@ .import addysp1 .importzp sp, sreg, tmp3, tmp4, ptr1, ptr2, ptr3, ptr4 + .macpack cpu + tosudiv0ax: +.if (.cpu .bitand ::CPU_ISET_65SC02) + stz sreg + stz sreg+1 +.else ldy #$00 sty sreg sty sreg+1 +.endif tosudiveax: jsr getlop ; Get the paramameters @@ -30,10 +38,15 @@ getlop: sta ptr3 ; Put right operand in place lda sreg+1 sta ptr4+1 +.if (.cpu .bitand ::CPU_ISET_65SC02) + lda (sp) + ldy #1 +.else ldy #0 ; Put left operand in place lda (sp),y - sta ptr1 iny +.endif + sta ptr1 lda (sp),y sta ptr1+1 iny diff --git a/libsrc/runtime/lumod.s b/libsrc/runtime/lumod.s index e290e1167..241801a90 100644 --- a/libsrc/runtime/lumod.s +++ b/libsrc/runtime/lumod.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 27.09.1998 +; Christian Krueger, 11-Mar-2017, added 65SC02 optimization ; ; CC65 runtime: modulo operation for long unsigned ints ; @@ -8,10 +9,17 @@ .import getlop, udiv32 .importzp sreg, tmp3, tmp4, ptr2 + .macpack cpu + tosumod0ax: +.if (.cpu .bitand ::CPU_ISET_65SC02) + stz sreg + stz sreg+1 +.else ldy #$00 sty sreg sty sreg+1 +.endif tosumodeax: jsr getlop ; Get the paramameters diff --git a/libsrc/runtime/lxor.s b/libsrc/runtime/lxor.s index ce21ef35b..4ec9a4129 100644 --- a/libsrc/runtime/lxor.s +++ b/libsrc/runtime/lxor.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 06.08.1998 +; Christian Krueger, 11-Mar-2017, added 65SC02 optimization ; ; CC65 runtime: xor on longs ; @@ -8,16 +9,28 @@ .import addysp1 .importzp sp, sreg, tmp1 + .macpack cpu + tosxor0ax: +.if (.cpu .bitand ::CPU_ISET_65SC02) + stz sreg + stz sreg+1 +.else ldy #$00 sty sreg sty sreg+1 +.endif -tosxoreax: +tosxoreax: +.if (.cpu .bitand ::CPU_ISET_65SC02) + eor (sp) ; byte 0 + ldy #1 +.else ldy #0 eor (sp),y ; byte 0 - sta tmp1 iny +.endif + sta tmp1 txa eor (sp),y ; byte 1 tax diff --git a/libsrc/runtime/makebool.s b/libsrc/runtime/makebool.s index a15b24b93..643f418aa 100644 --- a/libsrc/runtime/makebool.s +++ b/libsrc/runtime/makebool.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 05.10.1998 +; Christian Krueger, 11-Mar-2017, optimization ; ; CC65 runtime: Make boolean according to flags ; @@ -9,14 +10,14 @@ boolne: bne ret1 - ldx #$00 +ret0: ldx #$00 txa rts -booleq: beq ret1 - ldx #$00 - txa +booleq: bne ret0 +ret1: ldx #$00 + lda #$01 rts @@ -44,17 +45,9 @@ boolult: boolugt: - beq L1 + beq ret0 booluge: - bcs ret1 -L1: ldx #$00 + ldx #$00 txa + rol a rts - - -ret1: ldx #$00 - lda #$01 - rts - - - diff --git a/libsrc/runtime/or.s b/libsrc/runtime/or.s index 8570c0cd7..1c2c4125e 100644 --- a/libsrc/runtime/or.s +++ b/libsrc/runtime/or.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 05.08.1998 +; Christian Krueger, 11-Mar-2017, added 65SC02 optimization ; ; CC65 runtime: or on ints ; @@ -8,13 +9,20 @@ .import addysp1 .importzp sp, tmp1 + .macpack cpu + tosora0: ldx #$00 tosorax: +.if (.cpu .bitand ::CPU_ISET_65SC02) + ora (sp) + ldy #1 +.else ldy #0 ora (sp),y - sta tmp1 iny +.endif + sta tmp1 txa ora (sp),y tax diff --git a/libsrc/runtime/rsub.s b/libsrc/runtime/rsub.s index 475a69e76..69ee6da22 100644 --- a/libsrc/runtime/rsub.s +++ b/libsrc/runtime/rsub.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 05.08.1998 +; Christian Krueger, 11-Mar-2017, added 65SC02 optimization ; ; CC65 runtime: sub ints reversed ; @@ -8,6 +9,8 @@ .import addysp1 .importzp sp, tmp1 + .macpack cpu + ; ; AX = AX - TOS ; @@ -15,12 +18,17 @@ tosrsuba0: ldx #0 tosrsubax: - ldy #0 sec +.if (.cpu .bitand CPU_ISET_65SC02) + sbc (sp) + ldy #1 +.else + ldy #0 sbc (sp),y ; lo byte + iny +.endif sta tmp1 ; save lo byte txa - iny sbc (sp),y ; hi byte tax lda tmp1 diff --git a/libsrc/runtime/staxspi.s b/libsrc/runtime/staxspi.s index 90738e0d2..3114f449c 100644 --- a/libsrc/runtime/staxspi.s +++ b/libsrc/runtime/staxspi.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 26.10.2000 +; Christian Krueger, 12-Mar-2017, added 65SC02 optimization ; ; CC65 runtime: Store a/x indirect into address at top of stack with index ; @@ -8,6 +9,8 @@ .import incsp2 .importzp sp, tmp1, ptr1 + .macpack cpu + .proc staxspidx sty tmp1 ; Save Y @@ -15,8 +18,12 @@ ldy #1 lda (sp),y sta ptr1+1 +.if (.cpu .bitand ::CPU_ISET_65SC02) + lda (sp) +.else dey lda (sp),y +.endif sta ptr1 ; Address now in ptr1 ldy tmp1 ; Restore Y iny ; Address high byte diff --git a/libsrc/runtime/swap.s b/libsrc/runtime/swap.s index e91eeca31..d4a74df5f 100644 --- a/libsrc/runtime/swap.s +++ b/libsrc/runtime/swap.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 06.08.1998 +; Christian Krueger, 11-Mar-2017, added 65SC02 optimization ; ; CC65 runtime: swap ax with TOS ; @@ -7,6 +8,8 @@ .export swapstk .importzp sp, ptr4 + .macpack cpu + swapstk: sta ptr4 stx ptr4+1 @@ -15,11 +18,18 @@ swapstk: tax lda ptr4+1 sta (sp),y +.if (.cpu .bitand ::CPU_ISET_65SC02) + lda (sp) + tay + lda ptr4 + sta (sp) + tya +.else dey lda (sp),y pha lda ptr4 sta (sp),y pla +.endif rts ; whew! - diff --git a/libsrc/runtime/xor.s b/libsrc/runtime/xor.s index 825c576d1..e03922926 100644 --- a/libsrc/runtime/xor.s +++ b/libsrc/runtime/xor.s @@ -1,5 +1,6 @@ ; ; Ullrich von Bassewitz, 05.08.1998 +; Christian Krueger, 11-Mar-2017, added 65SC02 optimization ; ; CC65 runtime: xor on ints ; @@ -8,13 +9,20 @@ .import addysp1 .importzp sp, tmp1 + .macpack cpu + tosxora0: ldx #$00 tosxorax: +.if (.cpu .bitand CPU_ISET_65SC02) + eor (sp) + ldy #1 +.else ldy #0 eor (sp),y - sta tmp1 iny +.endif + sta tmp1 txa eor (sp),y tax diff --git a/libsrc/telestrat/gotoxy.s b/libsrc/telestrat/gotoxy.s index e0c8154e3..e1470f848 100644 --- a/libsrc/telestrat/gotoxy.s +++ b/libsrc/telestrat/gotoxy.s @@ -1,19 +1,26 @@ ; -; jede jede@oric.org 2017-02-25 +; 2017-02-25, jede <jede@oric.org> +; 2017-06-15, Greg King +; +; void gotoxy (unsigned char x, unsigned char y); ; - .export _gotoxy - - .import popa - - .importzp sp - .include "telestrat.inc" + .export gotoxy, _gotoxy + + .import popa + .importzp sp + + .include "telestrat.inc" + +gotoxy: jsr popa ; Get Y .proc _gotoxy - ; This function move only cursor for display, it does not move the prompt position - ; in telemon, there is position for prompt, and another for the cursor - sta SCRY - jsr popa - sta SCRX - rts -.endproc + +; This function moves only the display cursor; it does not move the prompt position. +; In telemon, there is a position for the prompt, and another for the cursor. + + sta SCRY + jsr popa + sta SCRX + rts +.endproc diff --git a/libsrc/vic20/joy/vic20-ptvjoy.s b/libsrc/vic20/joy/vic20-ptvjoy.s index cdd4c274f..3b1db402a 100644 --- a/libsrc/vic20/joy/vic20-ptvjoy.s +++ b/libsrc/vic20/joy/vic20-ptvjoy.s @@ -30,17 +30,6 @@ .addr $0000 -; Button state masks (8 values) - - .byte $01 ; JOY_UP - .byte $02 ; JOY_DOWN - .byte $04 ; JOY_LEFT - .byte $08 ; JOY_RIGHT - .byte $10 ; JOY_FIRE - .byte $00 ; JOY_FIRE2 unavailable - .byte $00 ; Future expansion - .byte $00 ; Future expansion - ; Jump table. .addr INSTALL @@ -113,10 +102,21 @@ joy1: lda #$7F ; mask for VIA2 JOYBIT: sw3 sty VIA1_DDRA ; restore the state of DDRA cli ; necessary? - ror ; Shift sw3 into bit 7 - and #$9E ; Mask relevant bits - eor #$9E ; Active states are inverted + php ; Save sw3 in carry + lsr ; Shift sw0,sw1,sw2,sw4 into bits 1-4 + tax ; Save sw0,sw1,sw2 + and #$10 ; Extract sw4 in bit 4 + sta tmp1 ; Save sw4 in bit 4 + txa ; Restore sw0,sw1,sw2 + lsr ; Shift sw0,sw1,sw2 into bits 0-2 + and #$07 ; Mask bits 0-2 + plp ; Restore sw3 in carry + bcc @L0 ; Is sw3 set? + ora #$08 ; Yes: Add sw3 in bit 3 +@L0: ora tmp1 ; Add sw4 in bit 4 + eor #$1F ; Active states are inverted + ldx #0 rts ; Read joystick 2 @@ -131,8 +131,8 @@ joy2: lda #%10000000 ; via port B Data-Direction sta VIA1_PRB ; (output one at PB7) lda VIA1_PRB ; via port B read/write - and #$1f ; get bit 4-0 (PB4-PB0) - eor #$1f + and #$1F ; get bit 4-0 (PB4-PB0) + eor #$1F rts ; Read joystick 3 @@ -141,15 +141,14 @@ joy3: lda #$00 ; via port B read/write sta VIA1_PRB ; (output zero at PB7) lda VIA1_PRB ; via port B read/write - and #$0f ; get bit 3-0 (PB3-PB0) + and #$0F ; get bit 3-0 (PB3-PB0) sta tmp1 ; joy 4 directions lda VIA1_PRB ; via port B read/write and #%00100000 ; get bit 5 (PB5) lsr ora tmp1 - eor #$1f + eor #$1F ldx #0 rts - diff --git a/libsrc/vic20/joy/vic20-stdjoy.s b/libsrc/vic20/joy/vic20-stdjoy.s index 56fb35ae4..67299cc1a 100644 --- a/libsrc/vic20/joy/vic20-stdjoy.s +++ b/libsrc/vic20/joy/vic20-stdjoy.s @@ -30,17 +30,6 @@ .addr $0000 -; Button state masks (8 values) - - .byte $02 ; JOY_UP - .byte $04 ; JOY_DOWN - .byte $08 ; JOY_LEFT - .byte $80 ; JOY_RIGHT - .byte $10 ; JOY_FIRE - .byte $00 ; JOY_FIRE2 unavailable - .byte $00 ; Future expansion - .byte $00 ; Future expansion - ; Jump table. .addr INSTALL @@ -112,10 +101,19 @@ READ: lda #$7F ; mask for VIA2 JOYBIT: sw3 sty VIA1_DDRA ; restore the state of DDRA cli ; necessary? - ror ; Shift sw3 into bit 7 - and #$9E ; Mask relevant bits - eor #$9E ; Active states are inverted + php ; Save sw3 in carry + lsr ; Shift sw0,sw1,sw2,sw4 into bits 1-4 + tax ; Save sw0,sw1,sw2 + and #$10 ; Extract sw4 in bit 4 + sta tmp1 ; Save sw4 in bit 4 + txa ; Restore sw0,sw1,sw2 + lsr ; Shift sw0,sw1,sw2 into bits 0-2 + and #$07 ; Mask bits 0-2 + plp ; Restore sw3 in carry + bcc @L0 ; Is sw3 set? + ora #$08 ; Yes: Add sw3 in bit 3 +@L0: ora tmp1 ; Add sw4 in bit 4 + eor #$1F ; Active states are inverted + ldx #0 rts - - diff --git a/libsrc/vic20/kbrepeat.s b/libsrc/vic20/kbrepeat.s new file mode 100644 index 000000000..dce4949fb --- /dev/null +++ b/libsrc/vic20/kbrepeat.s @@ -0,0 +1,14 @@ +; +; unsigned char __fastcall__ kbrepeat (unsigned char mode); +; + + .export _kbrepeat + + .include "vic20.inc" + +_kbrepeat: + ldx KBDREPEAT ; get old value + sta KBDREPEAT ; store new value + txa ; return old value + ldx #0 + rts diff --git a/libsrc/vic20/waitvsync.s b/libsrc/vic20/waitvsync.s new file mode 100644 index 000000000..1c76f2497 --- /dev/null +++ b/libsrc/vic20/waitvsync.s @@ -0,0 +1,16 @@ +; +; Written by Groepaz <groepaz@gmx.net> +; +; void waitvsync (void); +; + + .export _waitvsync + + .include "vic20.inc" + +_waitvsync: +@l2: + lda VIC_HLINE + bne @l2 + rts + diff --git a/samples/Makefile b/samples/Makefile index edfeca689..59841d655 100644 --- a/samples/Makefile +++ b/samples/Makefile @@ -90,7 +90,7 @@ LDFLAGS_tgidemo_atarixl = --start-addr 0x4000 %: %.s .c.o: - $(CC) $(CFLAGS) -Oirs --codesize 500 -T -g -t $(SYS) $< + $(CC) $(CFLAGS) -Ors --codesize 500 -T -g -t $(SYS) $< $(AS) $(<:.c=.s) .s.o: @@ -237,10 +237,10 @@ samples.atr: samples # Installation rules INSTALL = install -samplesdir = $(prefix)/share/cc65 +samplesdir = $(PREFIX)/share/cc65/samples install: - $(if $(prefix),,$(error variable `prefix' must be set)) + $(if $(PREFIX),,$(error variable `PREFIX' must be set)) $(INSTALL) -d $(DESTDIR)$(samplesdir) $(INSTALL) -d $(DESTDIR)$(samplesdir)/geos $(INSTALL) -d $(DESTDIR)$(samplesdir)/tutorial diff --git a/src/Makefile b/src/Makefile index edb6f5aa8..8b41ceb9c 100644 --- a/src/Makefile +++ b/src/Makefile @@ -19,8 +19,8 @@ PROGS = ar65 \ .SUFFIXES: -bindir := $(prefix)/bin -datadir := $(if $(prefix),$(prefix)/share/cc65,$(abspath ..)) +bindir := $(PREFIX)/bin +datadir := $(if $(PREFIX),$(PREFIX)/share/cc65,$(abspath ..)) CA65_INC = $(datadir)/asminc CC65_INC = $(datadir)/include @@ -62,10 +62,10 @@ else endif endif -CFLAGS += -MMD -MP -O -I common \ +CFLAGS += -MMD -MP -O3 -I common \ -Wall -Wextra -Wno-char-subscripts $(USER_CFLAGS) \ -DCA65_INC=$(CA65_INC) -DCC65_INC=$(CC65_INC) -DCL65_TGT=$(CL65_TGT) \ - -DLD65_LIB=$(LD65_LIB) -DLD65_OBJ=$(LD65_OBJ) -DLD65_CFG=$(LD65_CFG) + -DLD65_LIB=$(LD65_LIB) -DLD65_OBJ=$(LD65_OBJ) -DLD65_CFG=$(LD65_CFG) \ -DGIT_SHA=$(GIT_SHA) LDLIBS += -lm @@ -107,7 +107,7 @@ $(RM) /usr/local/bin/$(prog) endef # UNAVAIL_recipe install: - $(if $(prefix),,$(error variable `prefix' must be set)) + $(if $(PREFIX),,$(error variable `PREFIX' must be set)) $(INSTALL) -d $(DESTDIR)$(bindir) $(INSTALL) ../bin/* $(DESTDIR)$(bindir) diff --git a/src/ar65/list.c b/src/ar65/list.c index 656299860..367c950dc 100644 --- a/src/ar65/list.c +++ b/src/ar65/list.c @@ -36,6 +36,9 @@ #include <stdio.h> #include <stdlib.h> +/* common */ +#include "print.h" + /* ar65 */ #include "error.h" #include "library.h" @@ -73,8 +76,10 @@ void ListObjFiles (int argc, char* argv []) /* Get the entry */ O = CollConstAt (&ObjPool, I); + /* Print the size if verbose */ + Print (stdout, 1, "%5lu ", O->Size); /* Print the name */ - printf ("%s\n", O->Name); + puts (O->Name); } diff --git a/src/ar65/main.c b/src/ar65/main.c index a1839bad2..48561027f 100644 --- a/src/ar65/main.c +++ b/src/ar65/main.c @@ -62,9 +62,9 @@ static void Usage (void) { fprintf (stderr, "Usage: %s <operation ...> lib file|module ...\n" "Operations are some of:\n" - "\ta\tAdd modules\n" + "\tr\tAdd modules\n" "\td\tDelete modules\n" - "\tl\tList library contents\n" + "\tt\tList library table\n" "\tv\tIncrease verbosity (put before other operation)\n" "\tx\tExtract modules\n" "\tV\tPrint the archiver version\n", @@ -94,13 +94,10 @@ int main (int argc, char* argv []) /* Get the argument */ const char* Arg = ArgVec [I]; - /* Check for an option */ - if (strlen (Arg) != 1) { - Usage (); - } switch (Arg [0]) { - case 'a': + case 'r': /* POSIX.2 */ + case 'a': /* staying compatible */ AddObjFiles (ArgCount - I - 1, &ArgVec[I+1]); break; @@ -108,7 +105,11 @@ int main (int argc, char* argv []) DelObjFiles (ArgCount - I - 1, &ArgVec [I+1]); break; - case 'l': + case 't': /* POSIX.2 */ + case 'l': /* staying compatible */ + if (Arg [1] == 'v') { + ++Verbosity; + } ListObjFiles (ArgCount - I - 1, &ArgVec [I+1]); break; diff --git a/src/ca65/dbginfo.c b/src/ca65/dbginfo.c index 8a55f9ddc..135739fb5 100644 --- a/src/ca65/dbginfo.c +++ b/src/ca65/dbginfo.c @@ -211,7 +211,7 @@ void DbgInfoFile (void) void DbgInfoFunc (void) /* Parse and handle func subcommand of the .dbg pseudo instruction */ { - static const char* StorageKeys[] = { + static const char* const StorageKeys[] = { "EXTERN", "STATIC", }; @@ -352,7 +352,7 @@ void DbgInfoLine (void) void DbgInfoSym (void) /* Parse and handle SYM subcommand of the .dbg pseudo instruction */ { - static const char* StorageKeys[] = { + static const char* const StorageKeys[] = { "AUTO", "EXTERN", "REGISTER", diff --git a/src/ca65/feature.c b/src/ca65/feature.c index 35bdf4b98..0fb766b6f 100644 --- a/src/ca65/feature.c +++ b/src/ca65/feature.c @@ -48,7 +48,7 @@ /* Names of the features */ -static const char* FeatureKeys[FEAT_COUNT] = { +static const char* const FeatureKeys[FEAT_COUNT] = { "dollar_is_pc", "labels_without_colons", "loose_string_term", diff --git a/src/ca65/main.c b/src/ca65/main.c index 3c3daf7f7..fbca2beac 100644 --- a/src/ca65/main.c +++ b/src/ca65/main.c @@ -123,7 +123,6 @@ static void Usage (void) " --large-alignment\t\tDon't warn about large alignments\n" " --listing name\t\tCreate a listing file if assembly was ok\n" " --list-bytes n\t\tMaximum number of bytes per listing line\n" - " --macpack-dir dir\t\tSet a macro package directory\n" " --memory-model model\t\tSet the memory model\n" " --pagelength n\t\tSet the page length for the listing\n" " --relax-checks\t\tRelax some checks (see docs)\n" diff --git a/src/ca65/pseudo.c b/src/ca65/pseudo.c index b44c28dd8..5dd67af90 100644 --- a/src/ca65/pseudo.c +++ b/src/ca65/pseudo.c @@ -151,7 +151,7 @@ static unsigned char OptionalAddrSize (void) static void SetBoolOption (unsigned char* Flag) /* Read a on/off/+/- option and set flag accordingly */ { - static const char* Keys[] = { + static const char* const Keys[] = { "OFF", "ON", }; @@ -451,7 +451,7 @@ static void DoASCIIZ (void) static void DoAssert (void) /* Add an assertion */ { - static const char* ActionTab [] = { + static const char* const ActionTab [] = { "WARN", "WARNING", "ERROR", "LDWARN", "LDWARNING", @@ -659,7 +659,7 @@ static void DoCode (void) static void DoConDes (void) /* Export a symbol as constructor/destructor */ { - static const char* Keys[] = { + static const char* const Keys[] = { "CONSTRUCTOR", "DESTRUCTOR", "INTERRUPTOR", @@ -744,7 +744,7 @@ static void DoData (void) static void DoDbg (void) /* Add debug information from high level code */ { - static const char* Keys[] = { + static const char* const Keys[] = { "FILE", "FUNC", "LINE", @@ -1039,7 +1039,7 @@ static void DoFileOpt (void) if (CurTok.Tok == TOK_IDENT) { /* Option given as keyword */ - static const char* Keys [] = { + static const char* const Keys [] = { "AUTHOR", "COMMENT", "COMPILER" }; @@ -1388,7 +1388,7 @@ static void DoList (void) /* Enable/disable the listing */ { /* Get the setting */ - unsigned char List; + unsigned char List = 0; SetBoolOption (&List); /* Manage the counter */ diff --git a/src/ca65/scanner.c b/src/ca65/scanner.c index e186b19a7..7c291666c 100644 --- a/src/ca65/scanner.c +++ b/src/ca65/scanner.c @@ -1477,7 +1477,7 @@ CharAgain: -int GetSubKey (const char** Keys, unsigned Count) +int GetSubKey (const char* const* Keys, unsigned Count) /* Search for a subkey in a table of keywords. The current token must be an ** identifier and all keys must be in upper case. The identifier will be ** uppercased in the process. The function returns the index of the keyword, diff --git a/src/ca65/scanner.h b/src/ca65/scanner.h index c445aefa6..4fd9041c1 100644 --- a/src/ca65/scanner.h +++ b/src/ca65/scanner.h @@ -84,7 +84,7 @@ void UpcaseSVal (void); void NextRawTok (void); /* Read the next raw token from the input stream */ -int GetSubKey (const char** Keys, unsigned Count); +int GetSubKey (const char* const* Keys, unsigned Count); /* Search for a subkey in a table of keywords. The current token must be an ** identifier and all keys must be in upper case. The identifier will be ** uppercased in the process. The function returns the index of the keyword, diff --git a/src/cc65.vcxproj b/src/cc65.vcxproj index 1c1f993fe..70f43dc73 100644 --- a/src/cc65.vcxproj +++ b/src/cc65.vcxproj @@ -145,6 +145,7 @@ <ClInclude Include="cc65\typecmp.h" /> <ClInclude Include="cc65\typeconv.h" /> <ClInclude Include="cc65\util.h" /> + <ClInclude Include="cc65\wrappedcall.h" /> </ItemGroup> <ItemGroup> <ClCompile Include="cc65\anonname.c" /> @@ -218,6 +219,7 @@ <ClCompile Include="cc65\typecmp.c" /> <ClCompile Include="cc65\typeconv.c" /> <ClCompile Include="cc65\util.c" /> + <ClCompile Include="cc65\wrappedcall.c" /> </ItemGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> diff --git a/src/cc65/codegen.c b/src/cc65/codegen.c index bf0251813..dfc06fccc 100644 --- a/src/cc65/codegen.c +++ b/src/cc65/codegen.c @@ -2211,7 +2211,7 @@ void g_cmp (unsigned flags, unsigned long val) -static void oper (unsigned Flags, unsigned long Val, const char** Subs) +static void oper (unsigned Flags, unsigned long Val, const char* const* Subs) /* Encode a binary operation. subs is a pointer to four strings: ** 0 --> Operate on ints ** 1 --> Operate on unsigneds @@ -2499,7 +2499,7 @@ void g_stackcheck (void) void g_add (unsigned flags, unsigned long val) /* Primary = TOS + Primary */ { - static const char* ops[12] = { + static const char* const ops[4] = { "tosaddax", "tosaddax", "tosaddeax", "tosaddeax" }; @@ -2515,8 +2515,8 @@ void g_add (unsigned flags, unsigned long val) void g_sub (unsigned flags, unsigned long val) /* Primary = TOS - Primary */ { - static const char* ops[12] = { - "tossubax", "tossubax", "tossubeax", "tossubeax", + static const char* const ops[4] = { + "tossubax", "tossubax", "tossubeax", "tossubeax" }; if (flags & CF_CONST) { @@ -2531,8 +2531,8 @@ void g_sub (unsigned flags, unsigned long val) void g_rsub (unsigned flags, unsigned long val) /* Primary = Primary - TOS */ { - static const char* ops[12] = { - "tosrsubax", "tosrsubax", "tosrsubeax", "tosrsubeax", + static const char* const ops[4] = { + "tosrsubax", "tosrsubax", "tosrsubeax", "tosrsubeax" }; oper (flags, val, ops); } @@ -2542,8 +2542,8 @@ void g_rsub (unsigned flags, unsigned long val) void g_mul (unsigned flags, unsigned long val) /* Primary = TOS * Primary */ { - static const char* ops[12] = { - "tosmulax", "tosumulax", "tosmuleax", "tosumuleax", + static const char* const ops[4] = { + "tosmulax", "tosumulax", "tosmuleax", "tosumuleax" }; int p2; @@ -2649,8 +2649,8 @@ void g_mul (unsigned flags, unsigned long val) void g_div (unsigned flags, unsigned long val) /* Primary = TOS / Primary */ { - static const char* ops[12] = { - "tosdivax", "tosudivax", "tosdiveax", "tosudiveax", + static const char* const ops[4] = { + "tosdivax", "tosudivax", "tosdiveax", "tosudiveax" }; /* Do strength reduction if the value is constant and a power of two */ @@ -2674,8 +2674,8 @@ void g_div (unsigned flags, unsigned long val) void g_mod (unsigned flags, unsigned long val) /* Primary = TOS % Primary */ { - static const char* ops[12] = { - "tosmodax", "tosumodax", "tosmodeax", "tosumodeax", + static const char* const ops[4] = { + "tosmodax", "tosumodax", "tosmodeax", "tosumodeax" }; int p2; @@ -2699,8 +2699,8 @@ void g_mod (unsigned flags, unsigned long val) void g_or (unsigned flags, unsigned long val) /* Primary = TOS | Primary */ { - static const char* ops[12] = { - "tosorax", "tosorax", "tosoreax", "tosoreax", + static const char* const ops[4] = { + "tosorax", "tosorax", "tosoreax", "tosoreax" }; /* If the right hand side is const, the lhs is not on stack but still @@ -2769,8 +2769,8 @@ void g_or (unsigned flags, unsigned long val) void g_xor (unsigned flags, unsigned long val) /* Primary = TOS ^ Primary */ { - static const char* ops[12] = { - "tosxorax", "tosxorax", "tosxoreax", "tosxoreax", + static const char* const ops[4] = { + "tosxorax", "tosxorax", "tosxoreax", "tosxoreax" }; @@ -2837,8 +2837,8 @@ void g_xor (unsigned flags, unsigned long val) void g_and (unsigned Flags, unsigned long Val) /* Primary = TOS & Primary */ { - static const char* ops[12] = { - "tosandax", "tosandax", "tosandeax", "tosandeax", + static const char* const ops[4] = { + "tosandax", "tosandax", "tosandeax", "tosandeax" }; /* If the right hand side is const, the lhs is not on stack but still @@ -2929,8 +2929,8 @@ void g_and (unsigned Flags, unsigned long Val) void g_asr (unsigned flags, unsigned long val) /* Primary = TOS >> Primary */ { - static const char* ops[12] = { - "tosasrax", "tosshrax", "tosasreax", "tosshreax", + static const char* const ops[4] = { + "tosasrax", "tosshrax", "tosasreax", "tosshreax" }; /* If the right hand side is const, the lhs is not on stack but still @@ -3060,8 +3060,8 @@ void g_asr (unsigned flags, unsigned long val) void g_asl (unsigned flags, unsigned long val) /* Primary = TOS << Primary */ { - static const char* ops[12] = { - "tosaslax", "tosshlax", "tosasleax", "tosshleax", + static const char* const ops[4] = { + "tosaslax", "tosshlax", "tosasleax", "tosshleax" }; @@ -3438,8 +3438,8 @@ void g_dec (unsigned flags, unsigned long val) void g_eq (unsigned flags, unsigned long val) /* Test for equal */ { - static const char* ops[12] = { - "toseqax", "toseqax", "toseqeax", "toseqeax", + static const char* const ops[4] = { + "toseqax", "toseqax", "toseqeax", "toseqeax" }; unsigned L; @@ -3492,8 +3492,8 @@ void g_eq (unsigned flags, unsigned long val) void g_ne (unsigned flags, unsigned long val) /* Test for not equal */ { - static const char* ops[12] = { - "tosneax", "tosneax", "tosneeax", "tosneeax", + static const char* const ops[4] = { + "tosneax", "tosneax", "tosneeax", "tosneeax" }; unsigned L; @@ -3546,8 +3546,8 @@ void g_ne (unsigned flags, unsigned long val) void g_lt (unsigned flags, unsigned long val) /* Test for less than */ { - static const char* ops[12] = { - "tosltax", "tosultax", "toslteax", "tosulteax", + static const char* const ops[4] = { + "tosltax", "tosultax", "toslteax", "tosulteax" }; unsigned Label; @@ -3708,8 +3708,8 @@ void g_lt (unsigned flags, unsigned long val) void g_le (unsigned flags, unsigned long val) /* Test for less than or equal to */ { - static const char* ops[12] = { - "tosleax", "tosuleax", "tosleeax", "tosuleeax", + static const char* const ops[4] = { + "tosleax", "tosuleax", "tosleeax", "tosuleeax" }; @@ -3823,8 +3823,8 @@ void g_le (unsigned flags, unsigned long val) void g_gt (unsigned flags, unsigned long val) /* Test for greater than */ { - static const char* ops[12] = { - "tosgtax", "tosugtax", "tosgteax", "tosugteax", + static const char* const ops[4] = { + "tosgtax", "tosugtax", "tosgteax", "tosugteax" }; @@ -3954,8 +3954,8 @@ void g_gt (unsigned flags, unsigned long val) void g_ge (unsigned flags, unsigned long val) /* Test for greater than or equal to */ { - static const char* ops[12] = { - "tosgeax", "tosugeax", "tosgeeax", "tosugeeax", + static const char* const ops[4] = { + "tosgeax", "tosugeax", "tosgeeax", "tosugeeax" }; unsigned Label; diff --git a/src/cc65/codeinfo.c b/src/cc65/codeinfo.c index de51781a6..e9d98f5b8 100644 --- a/src/cc65/codeinfo.c +++ b/src/cc65/codeinfo.c @@ -401,6 +401,11 @@ void GetFuncInfo (const char* Name, unsigned short* Use, unsigned short* Chg) */ if ((D->Flags & FD_VARIADIC) != 0) { *Use = REG_Y; + } else if (D->Flags & FD_CALL_WRAPPER) { + /* Wrappers may go to any functions, so mark them as using all + ** registers. + */ + *Use = REG_EAXY; } else if (D->ParamCount > 0 && (AutoCDecl ? IsQualFastcall (E->Type) : diff --git a/src/cc65/compile.c b/src/cc65/compile.c index 9f1ab29f5..d79ef350b 100644 --- a/src/cc65/compile.c +++ b/src/cc65/compile.c @@ -157,7 +157,7 @@ static void Parse (void) CurTok.Tok == TOK_ASSIGN))) { /* We will allocate storage */ - Decl.StorageClass |= SC_STORAGE | SC_DEF; + Decl.StorageClass |= SC_STORAGE; } /* If this is a function declarator that is not followed by a comma @@ -190,6 +190,13 @@ static void Parse (void) /* Allow initialization */ if (CurTok.Tok == TOK_ASSIGN) { + /* This is a definition */ + if (SymIsDef (Entry)) { + Error ("Global variable `%s' has already been defined", + Entry->Name); + } + Entry->Flags |= SC_DEF; + /* We cannot initialize types of unknown size, or ** void types in ISO modes. */ @@ -235,19 +242,24 @@ static void Parse (void) Error ("Variable `%s' has unknown size", Decl.Ident); } Entry->Flags &= ~(SC_STORAGE | SC_DEF); - } + } else { + /* A global (including static) uninitialized variable is + ** only a tentative definition. For example, this is valid: + ** int i; + ** int i; + ** static int j; + ** static int j = 42; + ** Code for them will be generated by FinishCompile(). + ** For now, just save the BSS segment name + ** (can be set by #pragma bss-name). + */ + const char* bssName = GetSegName (SEG_BSS); - /* Allocate storage if it is still needed */ - if (Entry->Flags & SC_STORAGE) { - - /* Switch to the BSS segment */ - g_usebss (); - - /* Define a label */ - g_defgloblabel (Entry->Name); - - /* Allocate space for uninitialized variable */ - g_res (Size); + if (Entry->V.BssName && strcmp (Entry->V.BssName, bssName) != 0) { + Error ("Global variable `%s' already was defined in the `%s' segment.", + Entry->Name, Entry->V.BssName); + } + Entry->V.BssName = xstrdup (bssName); } } @@ -303,7 +315,7 @@ void Compile (const char* FileName) struct tm* TM; /* Since strftime is locale dependent, we need the abbreviated month names - ** in english. + ** in English. */ static const char MonthNames[12][4] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", @@ -324,17 +336,22 @@ void Compile (const char* FileName) ** changes using #pragma later. */ if (IS_Get (&Optimize)) { - long CodeSize = IS_Get (&CodeSizeFactor); DefineNumericMacro ("__OPT__", 1); + } + { + long CodeSize = IS_Get (&CodeSizeFactor); if (CodeSize > 100) { DefineNumericMacro ("__OPT_i__", CodeSize); } - if (IS_Get (&EnableRegVars)) { - DefineNumericMacro ("__OPT_r__", 1); - } - if (IS_Get (&InlineStdFuncs)) { - DefineNumericMacro ("__OPT_s__", 1); - } + } + if (IS_Get (&EnableRegVars)) { + DefineNumericMacro ("__OPT_r__", 1); + } + if (IS_Get (&InlineStdFuncs)) { + DefineNumericMacro ("__OPT_s__", 1); + } + if (IS_Get (&EagerlyInlineFuncs)) { + DefineNumericMacro ("__EAGERLY_INLINE_FUNCS__", 1); } /* __TIME__ and __DATE__ macros */ @@ -400,20 +417,32 @@ void Compile (const char* FileName) void FinishCompile (void) /* Emit literals, externals, debug info, do cleanup and optimizations */ { - SymTable* SymTab; - SymEntry* Func; + SymEntry* Entry; - /* Walk over all functions, doing cleanup, optimizations ... */ - SymTab = GetGlobalSymTab (); - Func = SymTab->SymHead; - while (Func) { - if (SymIsOutputFunc (Func)) { + /* Walk over all global symbols: + ** - for functions, do clean-up and optimizations + ** - generate code for uninitialized global variables + */ + for (Entry = GetGlobalSymTab ()->SymHead; Entry; Entry = Entry->NextSym) { + if (SymIsOutputFunc (Entry)) { /* Function which is defined and referenced or extern */ - MoveLiteralPool (Func->V.F.LitPool); - CS_MergeLabels (Func->V.F.Seg->Code); - RunOpt (Func->V.F.Seg->Code); + MoveLiteralPool (Entry->V.F.LitPool); + CS_MergeLabels (Entry->V.F.Seg->Code); + RunOpt (Entry->V.F.Seg->Code); + } else if ((Entry->Flags & (SC_STORAGE | SC_DEF | SC_STATIC)) == (SC_STORAGE | SC_STATIC)) { + /* Assembly definition of uninitialized global variable */ + + /* Set the segment name only when it changes */ + if (strcmp (GetSegName (SEG_BSS), Entry->V.BssName) != 0) { + SetSegName (SEG_BSS, Entry->V.BssName); + g_segname (SEG_BSS); + } + g_usebss (); + g_defgloblabel (Entry->Name); + g_res (SizeOf (Entry->Type)); + /* Mark as defined; so that it will be exported, not imported */ + Entry->Flags |= SC_DEF; } - Func = Func->NextSym; } /* Output the literal pool */ diff --git a/src/cc65/coptstop.c b/src/cc65/coptstop.c index cf6392bd3..41d928750 100644 --- a/src/cc65/coptstop.c +++ b/src/cc65/coptstop.c @@ -1711,7 +1711,7 @@ static int HarmlessCall (const char* Name) ** the pushax/op sequence when encountered. */ { - static const char* Tab[] = { + static const char* const Tab[] = { "aslax1", "aslax2", "aslax3", diff --git a/src/cc65/datatype.c b/src/cc65/datatype.c index 8c9d6dcb0..2d54316cd 100644 --- a/src/cc65/datatype.c +++ b/src/cc65/datatype.c @@ -389,7 +389,10 @@ unsigned SizeOf (const Type* T) switch (UnqualifiedType (T->C)) { case T_VOID: - return 0; /* Assume voids have size zero */ + /* A void variable is a cc65 extension. + ** Get its size (in bytes). + */ + return T->A.U; /* Beware: There's a chance that this triggers problems in other parts of the compiler. The solution is to fix the callers, because calling @@ -438,7 +441,7 @@ unsigned SizeOf (const Type* T) /* Array with unspecified size */ return 0; } else { - return T->A.L * SizeOf (T + 1); + return T->A.U * SizeOf (T + 1); } default: diff --git a/src/cc65/declare.c b/src/cc65/declare.c index 163084835..a6b232905 100644 --- a/src/cc65/declare.c +++ b/src/cc65/declare.c @@ -58,6 +58,7 @@ #include "scanner.h" #include "standard.h" #include "symtab.h" +#include "wrappedcall.h" #include "typeconv.h" @@ -891,6 +892,7 @@ static void ParseTypeSpec (DeclSpec* D, long Default, TypeCode Qualifiers) case TOK_VOID: NextToken (); D->Type[0].C = T_VOID; + D->Type[0].A.U = 0; D->Type[1].C = T_END; break; @@ -1314,6 +1316,8 @@ static FuncDesc* ParseFuncDecl (void) { unsigned Offs; SymEntry* Sym; + SymEntry* WrappedCall; + unsigned char WrappedCallData; /* Create a new function descriptor */ FuncDesc* F = NewFuncDesc (); @@ -1379,6 +1383,13 @@ static FuncDesc* ParseFuncDecl (void) /* Leave the lexical level remembering the symbol tables */ RememberFunctionLevel (F); + /* Did we have a WrappedCall for this function? */ + GetWrappedCall((void **) &WrappedCall, &WrappedCallData); + if (WrappedCall) { + F->WrappedCall = WrappedCall; + F->WrappedCallData = WrappedCallData; + } + /* Return the function descriptor */ return F; } @@ -1446,6 +1457,7 @@ static void Declarator (const DeclSpec* Spec, Declaration* D, declmode_t Mode) /* Function declaration */ FuncDesc* F; + SymEntry* PrevEntry; /* Skip the opening paren */ NextToken (); @@ -1459,6 +1471,16 @@ static void Declarator (const DeclSpec* Spec, Declaration* D, declmode_t Mode) Qualifiers &= ~T_QUAL_FASTCALL; } + /* Was there a previous entry? If so, copy WrappedCall info from it */ + PrevEntry = FindGlobalSym (D->Ident); + if (PrevEntry && PrevEntry->Flags & SC_FUNC) { + FuncDesc* D = PrevEntry->V.F.Func; + if (D->WrappedCall && !F->WrappedCall) { + F->WrappedCall = D->WrappedCall; + F->WrappedCallData = D->WrappedCallData; + } + } + /* Add the function type. Be sure to bounds check the type buffer */ NeedTypeSpace (D, 1); D->Type[D->Index].C = T_FUNC | Qualifiers; @@ -2114,7 +2136,7 @@ NextMember: -static unsigned ParseVoidInit (void) +static unsigned ParseVoidInit (Type* T) /* Parse an initialization of a void variable (special cc65 extension). ** Return the number of bytes initialized. */ @@ -2181,6 +2203,9 @@ static unsigned ParseVoidInit (void) /* Closing brace */ ConsumeRCurly (); + /* Number of bytes determined by initializer */ + T->A.U = Size; + /* Return the number of bytes initialized */ return Size; } @@ -2216,8 +2241,8 @@ static unsigned ParseInitInternal (Type* T, int AllowFlexibleMembers) case T_VOID: if (IS_Get (&Standard) == STD_CC65) { - /* Special cc65 extension in non ANSI mode */ - return ParseVoidInit (); + /* Special cc65 extension in non-ANSI mode */ + return ParseVoidInit (T); } /* FALLTHROUGH */ diff --git a/src/cc65/expr.c b/src/cc65/expr.c index 34cf550a2..acfd95fed 100644 --- a/src/cc65/expr.c +++ b/src/cc65/expr.c @@ -536,6 +536,10 @@ static void FunctionCall (ExprDesc* Expr) /* Special handling for function pointers */ if (IsFuncPtr) { + if (Func->WrappedCall) { + Warning("Calling a wrapped function via a pointer, wrapped-call will not be used"); + } + /* If the function is not a fastcall function, load the pointer to ** the function into the primary. */ @@ -584,7 +588,47 @@ static void FunctionCall (ExprDesc* Expr) } else { /* Normal function */ - g_call (TypeOf (Expr->Type), (const char*) Expr->Name, ParamSize); + if (Func->WrappedCall) { + char tmp[64]; + StrBuf S = AUTO_STRBUF_INITIALIZER; + + /* Store the WrappedCall data in tmp4 */ + sprintf(tmp, "ldy #%u", Func->WrappedCallData); + SB_AppendStr (&S, tmp); + g_asmcode (&S); + SB_Clear(&S); + + SB_AppendStr (&S, "sty tmp4"); + g_asmcode (&S); + SB_Clear(&S); + + /* Store the original function address in ptr4 */ + SB_AppendStr (&S, "ldy #<(_"); + SB_AppendStr (&S, (const char*) Expr->Name); + SB_AppendChar (&S, ')'); + g_asmcode (&S); + SB_Clear(&S); + + SB_AppendStr (&S, "sty ptr4"); + g_asmcode (&S); + SB_Clear(&S); + + SB_AppendStr (&S, "ldy #>(_"); + SB_AppendStr (&S, (const char*) Expr->Name); + SB_AppendChar (&S, ')'); + g_asmcode (&S); + SB_Clear(&S); + + SB_AppendStr (&S, "sty ptr4+1"); + g_asmcode (&S); + SB_Clear(&S); + + SB_Done (&S); + + g_call (TypeOf (Expr->Type), Func->WrappedCall->Name, ParamSize); + } else { + g_call (TypeOf (Expr->Type), (const char*) Expr->Name, ParamSize); + } } @@ -1534,26 +1578,35 @@ static void PostInc (ExprDesc* Expr) /* Get the data type */ Flags = TypeOf (Expr->Type); - /* Push the address if needed */ - PushAddr (Expr); + /* Emit smaller code if a char variable is at a constant location */ + if ((Flags & CF_CHAR) == CF_CHAR && ED_IsLocConst(Expr)) { - /* Fetch the value and save it (since it's the result of the expression) */ - LoadExpr (CF_NONE, Expr); - g_save (Flags | CF_FORCECHAR); + LoadExpr (CF_NONE, Expr); + AddCodeLine ("inc %s", ED_GetLabelName(Expr, 0)); - /* If we have a pointer expression, increment by the size of the type */ - if (IsTypePtr (Expr->Type)) { - g_inc (Flags | CF_CONST | CF_FORCECHAR, CheckedSizeOf (Expr->Type + 1)); } else { - g_inc (Flags | CF_CONST | CF_FORCECHAR, 1); + + /* Push the address if needed */ + PushAddr (Expr); + + /* Fetch the value and save it (since it's the result of the expression) */ + LoadExpr (CF_NONE, Expr); + g_save (Flags | CF_FORCECHAR); + + /* If we have a pointer expression, increment by the size of the type */ + if (IsTypePtr (Expr->Type)) { + g_inc (Flags | CF_CONST | CF_FORCECHAR, CheckedSizeOf (Expr->Type + 1)); + } else { + g_inc (Flags | CF_CONST | CF_FORCECHAR, 1); + } + + /* Store the result back */ + Store (Expr, 0); + + /* Restore the original value in the primary register */ + g_restore (Flags | CF_FORCECHAR); } - /* Store the result back */ - Store (Expr, 0); - - /* Restore the original value in the primary register */ - g_restore (Flags | CF_FORCECHAR); - /* The result is always an expression, no reference */ ED_MakeRValExpr (Expr); } @@ -1581,26 +1634,35 @@ static void PostDec (ExprDesc* Expr) /* Get the data type */ Flags = TypeOf (Expr->Type); - /* Push the address if needed */ - PushAddr (Expr); + /* Emit smaller code if a char variable is at a constant location */ + if ((Flags & CF_CHAR) == CF_CHAR && ED_IsLocConst(Expr)) { - /* Fetch the value and save it (since it's the result of the expression) */ - LoadExpr (CF_NONE, Expr); - g_save (Flags | CF_FORCECHAR); + LoadExpr (CF_NONE, Expr); + AddCodeLine ("dec %s", ED_GetLabelName(Expr, 0)); - /* If we have a pointer expression, increment by the size of the type */ - if (IsTypePtr (Expr->Type)) { - g_dec (Flags | CF_CONST | CF_FORCECHAR, CheckedSizeOf (Expr->Type + 1)); } else { - g_dec (Flags | CF_CONST | CF_FORCECHAR, 1); + + /* Push the address if needed */ + PushAddr (Expr); + + /* Fetch the value and save it (since it's the result of the expression) */ + LoadExpr (CF_NONE, Expr); + g_save (Flags | CF_FORCECHAR); + + /* If we have a pointer expression, increment by the size of the type */ + if (IsTypePtr (Expr->Type)) { + g_dec (Flags | CF_CONST | CF_FORCECHAR, CheckedSizeOf (Expr->Type + 1)); + } else { + g_dec (Flags | CF_CONST | CF_FORCECHAR, 1); + } + + /* Store the result back */ + Store (Expr, 0); + + /* Restore the original value in the primary register */ + g_restore (Flags | CF_FORCECHAR); } - /* Store the result back */ - Store (Expr, 0); - - /* Restore the original value in the primary register */ - g_restore (Flags | CF_FORCECHAR); - /* The result is always an expression, no reference */ ED_MakeRValExpr (Expr); } diff --git a/src/cc65/funcdesc.c b/src/cc65/funcdesc.c index b9561a97c..273263dec 100644 --- a/src/cc65/funcdesc.c +++ b/src/cc65/funcdesc.c @@ -60,6 +60,8 @@ FuncDesc* NewFuncDesc (void) F->ParamCount = 0; F->ParamSize = 0; F->LastParam = 0; + F->WrappedCall = 0; + F->WrappedCallData = 0; /* Return the new struct */ return F; diff --git a/src/cc65/funcdesc.h b/src/cc65/funcdesc.h index b79c6a055..a04ffb14a 100644 --- a/src/cc65/funcdesc.h +++ b/src/cc65/funcdesc.h @@ -52,9 +52,10 @@ #define FD_OLDSTYLE 0x0010U /* Old style (K&R) function */ #define FD_OLDSTYLE_INTRET 0x0020U /* K&R func has implicit int return */ #define FD_UNNAMED_PARAMS 0x0040U /* Function has unnamed params */ +#define FD_CALL_WRAPPER 0x0080U /* This function is used as a wrapper */ /* Bits that must be ignored when comparing funcs */ -#define FD_IGNORE (FD_OLDSTYLE | FD_OLDSTYLE_INTRET | FD_UNNAMED_PARAMS) +#define FD_IGNORE (FD_OLDSTYLE | FD_OLDSTYLE_INTRET | FD_UNNAMED_PARAMS | FD_CALL_WRAPPER) @@ -67,6 +68,8 @@ struct FuncDesc { unsigned ParamCount; /* Number of parameters */ unsigned ParamSize; /* Size of the parameters */ struct SymEntry* LastParam; /* Pointer to last parameter */ + struct SymEntry* WrappedCall; /* Pointer to the WrappedCall */ + unsigned char WrappedCallData;/* The WrappedCall's user data */ }; diff --git a/src/cc65/global.c b/src/cc65/global.c index dbdd72f3c..a337549fe 100644 --- a/src/cc65/global.c +++ b/src/cc65/global.c @@ -53,7 +53,8 @@ unsigned RegisterSpace = 6; /* Space available for register vars */ /* Stackable options */ IntStack WritableStrings = INTSTACK(0); /* Literal strings are r/w */ IntStack LocalStrings = INTSTACK(0); /* Emit string literals immediately */ -IntStack InlineStdFuncs = INTSTACK(0); /* Inline some known functions */ +IntStack InlineStdFuncs = INTSTACK(0); /* Inline some standard functions */ +IntStack EagerlyInlineFuncs = INTSTACK(0); /* Eagerly inline some known functions */ IntStack EnableRegVars = INTSTACK(0); /* Enable register variables */ IntStack AllowRegVarAddr = INTSTACK(0); /* Allow taking addresses of register vars */ IntStack RegVarsToCallStack = INTSTACK(0); /* Save reg variables on call stack */ diff --git a/src/cc65/global.h b/src/cc65/global.h index 8b0af5a83..4ffc84a39 100644 --- a/src/cc65/global.h +++ b/src/cc65/global.h @@ -61,7 +61,8 @@ extern unsigned RegisterSpace; /* Space available for register /* Stackable options */ extern IntStack WritableStrings; /* Literal strings are r/w */ extern IntStack LocalStrings; /* Emit string literals immediately */ -extern IntStack InlineStdFuncs; /* Inline some known functions */ +extern IntStack InlineStdFuncs; /* Inline some standard functions */ +extern IntStack EagerlyInlineFuncs; /* Eagerly inline some known functions */ extern IntStack EnableRegVars; /* Enable register variables */ extern IntStack AllowRegVarAddr; /* Allow taking addresses of register vars */ extern IntStack RegVarsToCallStack; /* Save reg variables on call stack */ diff --git a/src/cc65/main.c b/src/cc65/main.c index 9ed19b90c..d3d298876 100644 --- a/src/cc65/main.c +++ b/src/cc65/main.c @@ -88,7 +88,7 @@ static void Usage (void) " -O\t\t\t\tOptimize code\n" " -Oi\t\t\t\tOptimize code, inline more code\n" " -Or\t\t\t\tEnable register variables\n" - " -Os\t\t\t\tInline some known functions\n" + " -Os\t\t\t\tInline some standard functions\n" " -T\t\t\t\tInclude source as comment\n" " -V\t\t\t\tPrint the compiler version number\n" " -W warning[,...]\t\tSuppress warnings\n" @@ -118,9 +118,11 @@ static void Usage (void) " --debug-opt name\t\tDebug optimization steps\n" " --dep-target target\t\tUse this dependency target\n" " --disable-opt name\t\tDisable an optimization step\n" + " --eagerly-inline-funcs\t\tEagerly inline some known functions\n" " --enable-opt name\t\tEnable an optimization step\n" " --help\t\t\tHelp (this text)\n" " --include-dir dir\t\tSet an include directory search path\n" + " --inline-stdfuncs\t\tInline some standard functions\n" " --list-opt-steps\t\tList all optimizer steps and exit\n" " --list-warnings\t\tList available warning types for -W\n" " --local-strings\t\tEmit string literals immediately\n" @@ -581,6 +583,16 @@ static void OptDisableOpt (const char* Opt attribute ((unused)), const char* Arg +static void OptEagerlyInlineFuncs (const char* Opt attribute((unused)), + const char* Arg attribute((unused))) +/* Eagerly inline some known functions */ +{ + IS_Set (&InlineStdFuncs, 1); + IS_Set (&EagerlyInlineFuncs, 1); +} + + + static void OptEnableOpt (const char* Opt attribute ((unused)), const char* Arg) /* Enable an optimization step */ { @@ -608,6 +620,15 @@ static void OptIncludeDir (const char* Opt attribute ((unused)), const char* Arg +static void OptInlineStdFuncs (const char* Opt attribute((unused)), + const char* Arg attribute((unused))) +/* Inline some standard functions */ +{ + IS_Set (&InlineStdFuncs, 1); +} + + + static void OptListOptSteps (const char* Opt attribute ((unused)), const char* Arg attribute ((unused))) /* List all optimizer steps */ @@ -819,39 +840,41 @@ int main (int argc, char* argv[]) { /* Program long options */ static const LongOpt OptTab[] = { - { "--add-source", 0, OptAddSource }, - { "--all-cdecl", 0, OptAllCDecl }, - { "--bss-name", 1, OptBssName }, - { "--check-stack", 0, OptCheckStack }, - { "--code-name", 1, OptCodeName }, - { "--codesize", 1, OptCodeSize }, - { "--cpu", 1, OptCPU }, - { "--create-dep", 1, OptCreateDep }, - { "--create-full-dep", 1, OptCreateFullDep }, - { "--data-name", 1, OptDataName }, - { "--debug", 0, OptDebug }, - { "--debug-info", 0, OptDebugInfo }, - { "--debug-opt", 1, OptDebugOpt }, - { "--debug-opt-output", 0, OptDebugOptOutput }, - { "--dep-target", 1, OptDepTarget }, - { "--disable-opt", 1, OptDisableOpt }, - { "--enable-opt", 1, OptEnableOpt }, - { "--help", 0, OptHelp }, - { "--include-dir", 1, OptIncludeDir }, - { "--list-opt-steps", 0, OptListOptSteps }, - { "--list-warnings", 0, OptListWarnings }, - { "--local-strings", 0, OptLocalStrings }, - { "--memory-model", 1, OptMemoryModel }, - { "--register-space", 1, OptRegisterSpace }, - { "--register-vars", 0, OptRegisterVars }, - { "--rodata-name", 1, OptRodataName }, - { "--signed-chars", 0, OptSignedChars }, - { "--standard", 1, OptStandard }, - { "--static-locals", 0, OptStaticLocals }, - { "--target", 1, OptTarget }, - { "--verbose", 0, OptVerbose }, - { "--version", 0, OptVersion }, - { "--writable-strings", 0, OptWritableStrings }, + { "--add-source", 0, OptAddSource }, + { "--all-cdecl", 0, OptAllCDecl }, + { "--bss-name", 1, OptBssName }, + { "--check-stack", 0, OptCheckStack }, + { "--code-name", 1, OptCodeName }, + { "--codesize", 1, OptCodeSize }, + { "--cpu", 1, OptCPU }, + { "--create-dep", 1, OptCreateDep }, + { "--create-full-dep", 1, OptCreateFullDep }, + { "--data-name", 1, OptDataName }, + { "--debug", 0, OptDebug }, + { "--debug-info", 0, OptDebugInfo }, + { "--debug-opt", 1, OptDebugOpt }, + { "--debug-opt-output", 0, OptDebugOptOutput }, + { "--dep-target", 1, OptDepTarget }, + { "--disable-opt", 1, OptDisableOpt }, + { "--eagerly-inline-funcs", 0, OptEagerlyInlineFuncs }, + { "--enable-opt", 1, OptEnableOpt }, + { "--help", 0, OptHelp }, + { "--include-dir", 1, OptIncludeDir }, + { "--inline-stdfuncs", 0, OptInlineStdFuncs }, + { "--list-opt-steps", 0, OptListOptSteps }, + { "--list-warnings", 0, OptListWarnings }, + { "--local-strings", 0, OptLocalStrings }, + { "--memory-model", 1, OptMemoryModel }, + { "--register-space", 1, OptRegisterSpace }, + { "--register-vars", 0, OptRegisterVars }, + { "--rodata-name", 1, OptRodataName }, + { "--signed-chars", 0, OptSignedChars }, + { "--standard", 1, OptStandard }, + { "--static-locals", 0, OptStaticLocals }, + { "--target", 1, OptTarget }, + { "--verbose", 0, OptVerbose }, + { "--version", 0, OptVersion }, + { "--writable-strings", 0, OptWritableStrings }, }; unsigned I; diff --git a/src/cc65/pragma.c b/src/cc65/pragma.c index 86739ce22..25bc29d43 100644 --- a/src/cc65/pragma.c +++ b/src/cc65/pragma.c @@ -51,6 +51,7 @@ #include "scanstrbuf.h" #include "symtab.h" #include "pragma.h" +#include "wrappedcall.h" @@ -64,6 +65,7 @@ typedef enum { PRAGMA_ILLEGAL = -1, PRAGMA_ALIGN, + PRAGMA_ALLOW_EAGER_INLINE, PRAGMA_BSS_NAME, PRAGMA_BSSSEG, /* obsolete */ PRAGMA_CHARMAP, @@ -74,10 +76,12 @@ typedef enum { PRAGMA_CODESIZE, PRAGMA_DATA_NAME, PRAGMA_DATASEG, /* obsolete */ + PRAGMA_INLINE_STDFUNCS, PRAGMA_LOCAL_STRINGS, + PRAGMA_MESSAGE, PRAGMA_OPTIMIZE, - PRAGMA_REGVARADDR, PRAGMA_REGISTER_VARS, + PRAGMA_REGVARADDR, PRAGMA_REGVARS, /* obsolete */ PRAGMA_RODATA_NAME, PRAGMA_RODATASEG, /* obsolete */ @@ -86,6 +90,7 @@ typedef enum { PRAGMA_STATIC_LOCALS, PRAGMA_STATICLOCALS, /* obsolete */ PRAGMA_WARN, + PRAGMA_WRAPPED_CALL, PRAGMA_WRITABLE_STRINGS, PRAGMA_ZPSYM, PRAGMA_COUNT @@ -96,31 +101,35 @@ static const struct Pragma { const char* Key; /* Keyword */ pragma_t Tok; /* Token */ } Pragmas[PRAGMA_COUNT] = { - { "align", PRAGMA_ALIGN }, - { "bss-name", PRAGMA_BSS_NAME }, - { "bssseg", PRAGMA_BSSSEG }, /* obsolete */ - { "charmap", PRAGMA_CHARMAP }, - { "check-stack", PRAGMA_CHECK_STACK }, - { "checkstack", PRAGMA_CHECKSTACK }, /* obsolete */ - { "code-name", PRAGMA_CODE_NAME }, - { "codeseg", PRAGMA_CODESEG }, /* obsolete */ - { "codesize", PRAGMA_CODESIZE }, - { "data-name", PRAGMA_DATA_NAME }, - { "dataseg", PRAGMA_DATASEG }, /* obsolete */ - { "local-strings", PRAGMA_LOCAL_STRINGS }, - { "optimize", PRAGMA_OPTIMIZE }, - { "register-vars", PRAGMA_REGISTER_VARS }, - { "regvaraddr", PRAGMA_REGVARADDR }, - { "regvars", PRAGMA_REGVARS }, /* obsolete */ - { "rodata-name", PRAGMA_RODATA_NAME }, - { "rodataseg", PRAGMA_RODATASEG }, /* obsolete */ - { "signed-chars", PRAGMA_SIGNED_CHARS }, - { "signedchars", PRAGMA_SIGNEDCHARS }, /* obsolete */ - { "static-locals", PRAGMA_STATIC_LOCALS }, - { "staticlocals", PRAGMA_STATICLOCALS }, /* obsolete */ - { "warn", PRAGMA_WARN }, - { "writable-strings", PRAGMA_WRITABLE_STRINGS }, - { "zpsym", PRAGMA_ZPSYM }, + { "align", PRAGMA_ALIGN }, + { "allow-eager-inline", PRAGMA_ALLOW_EAGER_INLINE }, + { "bss-name", PRAGMA_BSS_NAME }, + { "bssseg", PRAGMA_BSSSEG }, /* obsolete */ + { "charmap", PRAGMA_CHARMAP }, + { "check-stack", PRAGMA_CHECK_STACK }, + { "checkstack", PRAGMA_CHECKSTACK }, /* obsolete */ + { "code-name", PRAGMA_CODE_NAME }, + { "codeseg", PRAGMA_CODESEG }, /* obsolete */ + { "codesize", PRAGMA_CODESIZE }, + { "data-name", PRAGMA_DATA_NAME }, + { "dataseg", PRAGMA_DATASEG }, /* obsolete */ + { "inline-stdfuncs", PRAGMA_INLINE_STDFUNCS }, + { "local-strings", PRAGMA_LOCAL_STRINGS }, + { "message", PRAGMA_MESSAGE }, + { "optimize", PRAGMA_OPTIMIZE }, + { "register-vars", PRAGMA_REGISTER_VARS }, + { "regvaraddr", PRAGMA_REGVARADDR }, + { "regvars", PRAGMA_REGVARS }, /* obsolete */ + { "rodata-name", PRAGMA_RODATA_NAME }, + { "rodataseg", PRAGMA_RODATASEG }, /* obsolete */ + { "signed-chars", PRAGMA_SIGNED_CHARS }, + { "signedchars", PRAGMA_SIGNEDCHARS }, /* obsolete */ + { "static-locals", PRAGMA_STATIC_LOCALS }, + { "staticlocals", PRAGMA_STATICLOCALS }, /* obsolete */ + { "warn", PRAGMA_WARN }, + { "wrapped-call", PRAGMA_WRAPPED_CALL }, + { "writable-strings", PRAGMA_WRITABLE_STRINGS }, + { "zpsym", PRAGMA_ZPSYM }, }; /* Result of ParsePushPop */ @@ -379,11 +388,11 @@ static void StringPragma (StrBuf* B, void (*Func) (const char*)) static void SegNamePragma (StrBuf* B, segment_t Seg) /* Handle a pragma that expects a segment name parameter */ { - StrBuf S = AUTO_STRBUF_INITIALIZER; const char* Name; + StrBuf S = AUTO_STRBUF_INITIALIZER; + int Push = 0; /* Check for the "push" or "pop" keywords */ - int Push = 0; switch (ParsePushPop (B)) { case PP_NONE: @@ -396,7 +405,13 @@ static void SegNamePragma (StrBuf* B, segment_t Seg) case PP_POP: /* Pop the old value and output it */ PopSegName (Seg); - g_segname (Seg); + + /* BSS variables are output at the end of the compilation. Don't + ** bother to change their segment, now. + */ + if (Seg != SEG_BSS) { + g_segname (Seg); + } /* Done */ goto ExitPoint; @@ -427,7 +442,13 @@ static void SegNamePragma (StrBuf* B, segment_t Seg) } else { SetSegName (Seg, Name); } - g_segname (Seg); + + /* BSS variables are output at the end of the compilation. Don't + ** bother to change their segment, now. + */ + if (Seg != SEG_BSS) { + g_segname (Seg); + } } else { @@ -442,6 +463,85 @@ ExitPoint: } +static void WrappedCallPragma (StrBuf* B) +/* Handle the wrapped-call pragma */ +{ + StrBuf S = AUTO_STRBUF_INITIALIZER; + const char *Name; + long Val; + SymEntry *Entry; + + /* Check for the "push" or "pop" keywords */ + switch (ParsePushPop (B)) { + + case PP_NONE: + Error ("Push or pop required"); + break; + + case PP_PUSH: + break; + + case PP_POP: + PopWrappedCall(); + + /* Done */ + goto ExitPoint; + + case PP_ERROR: + /* Bail out */ + goto ExitPoint; + + default: + Internal ("Invalid result from ParsePushPop"); + + } + + /* A symbol argument must follow */ + if (!SB_GetSym (B, &S, NULL)) { + goto ExitPoint; + } + + /* Skip the following comma */ + if (!GetComma (B)) { + /* Error already flagged by GetComma */ + Error ("Value required for wrapped-call identifier"); + goto ExitPoint; + } + + if (!GetNumber (B, &Val)) { + Error ("Value required for wrapped-call identifier"); + goto ExitPoint; + } + + if (Val < 0 || Val > 255) { + Error ("Identifier must be between 0-255"); + goto ExitPoint; + } + + /* Get the string */ + Name = SB_GetConstBuf (&S); + Entry = FindSym(Name); + + /* Check if the name is valid */ + if (Entry && Entry->Flags & SC_FUNC) { + + PushWrappedCall(Entry, Val); + Entry->Flags |= SC_REF; + Entry->V.F.Func->Flags |= FD_CALL_WRAPPER; + + } else { + + /* Segment name is invalid */ + Error ("Wrapped-call target does not exist or is not a function"); + + } + +ExitPoint: + /* Call the string buf destructor */ + SB_Done (&S); +} + + static void CharMapPragma (StrBuf* B) /* Change the character map */ @@ -652,6 +752,13 @@ static void IntPragma (StrBuf* B, IntStack* Stack, long Low, long High) +static void MakeMessage (const char* Message) +{ + fprintf (stderr, "%s(%u): Note: %s\n", GetInputName (CurTok.LI), GetInputLine (CurTok.LI), Message); +} + + + static void ParsePragma (void) /* Parse the contents of the _Pragma statement */ { @@ -703,6 +810,10 @@ static void ParsePragma (void) IntPragma (&B, &DataAlignment, 1, 4096); break; + case PRAGMA_ALLOW_EAGER_INLINE: + FlagPragma (&B, &EagerlyInlineFuncs); + break; + case PRAGMA_BSSSEG: Warning ("#pragma bssseg is obsolete, please use #pragma bss-name instead"); /* FALLTHROUGH */ @@ -739,10 +850,18 @@ static void ParsePragma (void) SegNamePragma (&B, SEG_DATA); break; + case PRAGMA_INLINE_STDFUNCS: + FlagPragma (&B, &InlineStdFuncs); + break; + case PRAGMA_LOCAL_STRINGS: FlagPragma (&B, &LocalStrings); break; + case PRAGMA_MESSAGE: + StringPragma (&B, MakeMessage); + break; + case PRAGMA_OPTIMIZE: FlagPragma (&B, &Optimize); break; @@ -779,6 +898,10 @@ static void ParsePragma (void) FlagPragma (&B, &StaticLocals); break; + case PRAGMA_WRAPPED_CALL: + WrappedCallPragma(&B); + break; + case PRAGMA_WARN: WarnPragma (&B); break; diff --git a/src/cc65/standard.c b/src/cc65/standard.c index 36897a059..f26b63c20 100644 --- a/src/cc65/standard.c +++ b/src/cc65/standard.c @@ -50,7 +50,7 @@ IntStack Standard = INTSTACK(STD_UNKNOWN); /* Table mapping names to standards, sorted by standard. */ -static const char* StdNames[STD_COUNT] = { +static const char* const StdNames[STD_COUNT] = { "c89", "c99", "cc65" }; diff --git a/src/cc65/stdfunc.c b/src/cc65/stdfunc.c index 720e6db15..2d4317ef8 100644 --- a/src/cc65/stdfunc.c +++ b/src/cc65/stdfunc.c @@ -261,262 +261,277 @@ static void StdFunc_memcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr) goto ExitPoint; } - /* We've generated the complete code for the function now and know the - ** types of all parameters. Check for situations where better code can - ** be generated. If such a situation is detected, throw away the - ** generated, and emit better code. - */ - if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.IVal <= 256 && - ((ED_IsRVal (&Arg2.Expr) && ED_IsLocConst (&Arg2.Expr)) || - (ED_IsLVal (&Arg2.Expr) && ED_IsLocRegister (&Arg2.Expr))) && - ((ED_IsRVal (&Arg1.Expr) && ED_IsLocConst (&Arg1.Expr)) || - (ED_IsLVal (&Arg1.Expr) && ED_IsLocRegister (&Arg1.Expr)))) { + if (IS_Get (&InlineStdFuncs)) { - int Reg1 = ED_IsLVal (&Arg1.Expr) && ED_IsLocRegister (&Arg1.Expr); - int Reg2 = ED_IsLVal (&Arg2.Expr) && ED_IsLocRegister (&Arg2.Expr); - - /* Drop the generated code */ - RemoveCode (&Arg1.Expr.Start); - - /* We need a label */ - Label = GetLocalLabel (); - - /* Generate memcpy code */ - if (Arg3.Expr.IVal <= 127) { - - AddCodeLine ("ldy #$%02X", (unsigned char) (Arg3.Expr.IVal-1)); - g_defcodelabel (Label); - if (Reg2) { - AddCodeLine ("lda (%s),y", ED_GetLabelName (&Arg2.Expr, 0)); - } else { - AddCodeLine ("lda %s,y", ED_GetLabelName (&Arg2.Expr, 0)); - } - if (Reg1) { - AddCodeLine ("sta (%s),y", ED_GetLabelName (&Arg1.Expr, 0)); - } else { - AddCodeLine ("sta %s,y", ED_GetLabelName (&Arg1.Expr, 0)); - } - AddCodeLine ("dey"); - AddCodeLine ("bpl %s", LocalLabelName (Label)); - - } else { - - AddCodeLine ("ldy #$00"); - g_defcodelabel (Label); - if (Reg2) { - AddCodeLine ("lda (%s),y", ED_GetLabelName (&Arg2.Expr, 0)); - } else { - AddCodeLine ("lda %s,y", ED_GetLabelName (&Arg2.Expr, 0)); - } - if (Reg1) { - AddCodeLine ("sta (%s),y", ED_GetLabelName (&Arg1.Expr, 0)); - } else { - AddCodeLine ("sta %s,y", ED_GetLabelName (&Arg1.Expr, 0)); - } - AddCodeLine ("iny"); - AddCmpCodeIfSizeNot256 ("cpy #$%02X", Arg3.Expr.IVal); - AddCodeLine ("bne %s", LocalLabelName (Label)); - - } - - /* memcpy returns the address, so the result is actually identical - ** to the first argument. + /* We've generated the complete code for the function now and know the + ** types of all parameters. Check for situations where better code can + ** be generated. If such a situation is detected, throw away the + ** generated, and emit better code. */ - *Expr = Arg1.Expr; + if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.IVal <= 256 && + ((ED_IsRVal (&Arg2.Expr) && ED_IsLocConst (&Arg2.Expr)) || + (ED_IsLVal (&Arg2.Expr) && ED_IsLocRegister (&Arg2.Expr))) && + ((ED_IsRVal (&Arg1.Expr) && ED_IsLocConst (&Arg1.Expr)) || + (ED_IsLVal (&Arg1.Expr) && ED_IsLocRegister (&Arg1.Expr)))) { - } else if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.IVal <= 256 && - ED_IsRVal (&Arg2.Expr) && ED_IsLocConst (&Arg2.Expr) && - ED_IsRVal (&Arg1.Expr) && ED_IsLocStack (&Arg1.Expr) && - (Arg1.Expr.IVal - StackPtr) + Arg3.Expr.IVal < 256) { + int Reg1 = ED_IsLVal (&Arg1.Expr) && ED_IsLocRegister (&Arg1.Expr); + int Reg2 = ED_IsLVal (&Arg2.Expr) && ED_IsLocRegister (&Arg2.Expr); - /* It is possible to just use one index register even if the stack - ** offset is not zero, by adjusting the offset to the constant - ** address accordingly. But we cannot do this if the data in - ** question is in the register space or at an absolute address less - ** than 256. Register space is zero page, which means that the - ** address calculation could overflow in the linker. - */ - int AllowOneIndex = !ED_IsLocRegister (&Arg2.Expr) && - !(ED_IsLocAbs (&Arg2.Expr) && Arg2.Expr.IVal < 256); + /* Drop the generated code */ + RemoveCode (&Arg1.Expr.Start); - /* Calculate the real stack offset */ - Offs = ED_GetStackOffs (&Arg1.Expr, 0); + /* We need a label */ + Label = GetLocalLabel (); - /* Drop the generated code */ - RemoveCode (&Arg1.Expr.Start); + /* Generate memcpy code */ + if (Arg3.Expr.IVal <= 129) { - /* We need a label */ - Label = GetLocalLabel (); - - /* Generate memcpy code */ - if (Arg3.Expr.IVal <= 127 && !AllowOneIndex) { - - if (Offs == 0) { - AddCodeLine ("ldy #$%02X", (unsigned char) (Offs + Arg3.Expr.IVal - 1)); + AddCodeLine ("ldy #$%02X", (unsigned char) (Arg3.Expr.IVal-1)); g_defcodelabel (Label); - AddCodeLine ("lda %s,y", ED_GetLabelName (&Arg2.Expr, -Offs)); - AddCodeLine ("sta (sp),y"); + if (Reg2) { + AddCodeLine ("lda (%s),y", ED_GetLabelName (&Arg2.Expr, 0)); + } else { + AddCodeLine ("lda %s,y", ED_GetLabelName (&Arg2.Expr, 0)); + } + if (Reg1) { + AddCodeLine ("sta (%s),y", ED_GetLabelName (&Arg1.Expr, 0)); + } else { + AddCodeLine ("sta %s,y", ED_GetLabelName (&Arg1.Expr, 0)); + } AddCodeLine ("dey"); AddCodeLine ("bpl %s", LocalLabelName (Label)); + } else { - AddCodeLine ("ldx #$%02X", (unsigned char) (Arg3.Expr.IVal-1)); - AddCodeLine ("ldy #$%02X", (unsigned char) (Offs + Arg3.Expr.IVal - 1)); + + AddCodeLine ("ldy #$00"); g_defcodelabel (Label); - AddCodeLine ("lda %s,x", ED_GetLabelName (&Arg2.Expr, 0)); - AddCodeLine ("sta (sp),y"); - AddCodeLine ("dey"); - AddCodeLine ("dex"); - AddCodeLine ("bpl %s", LocalLabelName (Label)); + if (Reg2) { + AddCodeLine ("lda (%s),y", ED_GetLabelName (&Arg2.Expr, 0)); + } else { + AddCodeLine ("lda %s,y", ED_GetLabelName (&Arg2.Expr, 0)); + } + if (Reg1) { + AddCodeLine ("sta (%s),y", ED_GetLabelName (&Arg1.Expr, 0)); + } else { + AddCodeLine ("sta %s,y", ED_GetLabelName (&Arg1.Expr, 0)); + } + AddCodeLine ("iny"); + AddCmpCodeIfSizeNot256 ("cpy #$%02X", Arg3.Expr.IVal); + AddCodeLine ("bne %s", LocalLabelName (Label)); + } - } else { - - if (Offs == 0 || AllowOneIndex) { - AddCodeLine ("ldy #$%02X", (unsigned char) Offs); - g_defcodelabel (Label); - AddCodeLine ("lda %s,y", ED_GetLabelName (&Arg2.Expr, -Offs)); - AddCodeLine ("sta (sp),y"); - AddCodeLine ("iny"); - AddCmpCodeIfSizeNot256 ("cpy #$%02X", Offs + Arg3.Expr.IVal); - AddCodeLine ("bne %s", LocalLabelName (Label)); - } else { - AddCodeLine ("ldx #$00"); - AddCodeLine ("ldy #$%02X", (unsigned char) Offs); - g_defcodelabel (Label); - AddCodeLine ("lda %s,x", ED_GetLabelName (&Arg2.Expr, 0)); - AddCodeLine ("sta (sp),y"); - AddCodeLine ("iny"); - AddCodeLine ("inx"); - AddCmpCodeIfSizeNot256 ("cpx #$%02X", Arg3.Expr.IVal); - AddCodeLine ("bne %s", LocalLabelName (Label)); - } + /* memcpy returns the address, so the result is actually identical + ** to the first argument. + */ + *Expr = Arg1.Expr; + /* Bail out, no need for further processing */ + goto ExitPoint; } - /* memcpy returns the address, so the result is actually identical - ** to the first argument. - */ - *Expr = Arg1.Expr; + if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.IVal <= 256 && + ED_IsRVal (&Arg2.Expr) && ED_IsLocConst (&Arg2.Expr) && + ED_IsRVal (&Arg1.Expr) && ED_IsLocStack (&Arg1.Expr) && + (Arg1.Expr.IVal - StackPtr) + Arg3.Expr.IVal < 256) { - } else if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.IVal <= 256 && - ED_IsRVal (&Arg2.Expr) && ED_IsLocStack (&Arg2.Expr) && - (Arg2.Expr.IVal - StackPtr) + Arg3.Expr.IVal < 256 && - ED_IsRVal (&Arg1.Expr) && ED_IsLocConst (&Arg1.Expr)) { + /* It is possible to just use one index register even if the stack + ** offset is not zero, by adjusting the offset to the constant + ** address accordingly. But we cannot do this if the data in + ** question is in the register space or at an absolute address less + ** than 256. Register space is zero page, which means that the + ** address calculation could overflow in the linker. + */ + int AllowOneIndex = !ED_IsLocRegister (&Arg2.Expr) && + !(ED_IsLocAbs (&Arg2.Expr) && Arg2.Expr.IVal < 256); - /* It is possible to just use one index register even if the stack - ** offset is not zero, by adjusting the offset to the constant - ** address accordingly. But we cannot do this if the data in - ** question is in the register space or at an absolute address less - ** than 256. Register space is zero page, which means that the - ** address calculation could overflow in the linker. - */ - int AllowOneIndex = !ED_IsLocRegister (&Arg1.Expr) && - !(ED_IsLocAbs (&Arg1.Expr) && Arg1.Expr.IVal < 256); + /* Calculate the real stack offset */ + Offs = ED_GetStackOffs (&Arg1.Expr, 0); - /* Calculate the real stack offset */ - Offs = ED_GetStackOffs (&Arg2.Expr, 0); + /* Drop the generated code */ + RemoveCode (&Arg1.Expr.Start); - /* Drop the generated code */ - RemoveCode (&Arg1.Expr.Start); + /* We need a label */ + Label = GetLocalLabel (); - /* We need a label */ - Label = GetLocalLabel (); + /* Generate memcpy code */ + if (Arg3.Expr.IVal <= 129 && !AllowOneIndex) { - /* Generate memcpy code */ - if (Arg3.Expr.IVal <= 127 && !AllowOneIndex) { + if (Offs == 0) { + AddCodeLine ("ldy #$%02X", (unsigned char) (Offs + Arg3.Expr.IVal - 1)); + g_defcodelabel (Label); + AddCodeLine ("lda %s,y", ED_GetLabelName (&Arg2.Expr, -Offs)); + AddCodeLine ("sta (sp),y"); + AddCodeLine ("dey"); + AddCodeLine ("bpl %s", LocalLabelName (Label)); + } else { + AddCodeLine ("ldx #$%02X", (unsigned char) (Arg3.Expr.IVal-1)); + AddCodeLine ("ldy #$%02X", (unsigned char) (Offs + Arg3.Expr.IVal - 1)); + g_defcodelabel (Label); + AddCodeLine ("lda %s,x", ED_GetLabelName (&Arg2.Expr, 0)); + AddCodeLine ("sta (sp),y"); + AddCodeLine ("dey"); + AddCodeLine ("dex"); + AddCodeLine ("bpl %s", LocalLabelName (Label)); + } - if (Offs == 0) { + } else { + + if (Offs == 0 || AllowOneIndex) { + AddCodeLine ("ldy #$%02X", (unsigned char) Offs); + g_defcodelabel (Label); + AddCodeLine ("lda %s,y", ED_GetLabelName (&Arg2.Expr, -Offs)); + AddCodeLine ("sta (sp),y"); + AddCodeLine ("iny"); + AddCmpCodeIfSizeNot256 ("cpy #$%02X", Offs + Arg3.Expr.IVal); + AddCodeLine ("bne %s", LocalLabelName (Label)); + } else { + AddCodeLine ("ldx #$00"); + AddCodeLine ("ldy #$%02X", (unsigned char) Offs); + g_defcodelabel (Label); + AddCodeLine ("lda %s,x", ED_GetLabelName (&Arg2.Expr, 0)); + AddCodeLine ("sta (sp),y"); + AddCodeLine ("iny"); + AddCodeLine ("inx"); + AddCmpCodeIfSizeNot256 ("cpx #$%02X", Arg3.Expr.IVal); + AddCodeLine ("bne %s", LocalLabelName (Label)); + } + + } + + /* memcpy returns the address, so the result is actually identical + ** to the first argument. + */ + *Expr = Arg1.Expr; + + /* Bail out, no need for further processing */ + goto ExitPoint; + } + + if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.IVal <= 256 && + ED_IsRVal (&Arg2.Expr) && ED_IsLocStack (&Arg2.Expr) && + (Arg2.Expr.IVal - StackPtr) + Arg3.Expr.IVal < 256 && + ED_IsRVal (&Arg1.Expr) && ED_IsLocConst (&Arg1.Expr)) { + + /* It is possible to just use one index register even if the stack + ** offset is not zero, by adjusting the offset to the constant + ** address accordingly. But we cannot do this if the data in + ** question is in the register space or at an absolute address less + ** than 256. Register space is zero page, which means that the + ** address calculation could overflow in the linker. + */ + int AllowOneIndex = !ED_IsLocRegister (&Arg1.Expr) && + !(ED_IsLocAbs (&Arg1.Expr) && Arg1.Expr.IVal < 256); + + /* Calculate the real stack offset */ + Offs = ED_GetStackOffs (&Arg2.Expr, 0); + + /* Drop the generated code */ + RemoveCode (&Arg1.Expr.Start); + + /* We need a label */ + Label = GetLocalLabel (); + + /* Generate memcpy code */ + if (Arg3.Expr.IVal <= 129 && !AllowOneIndex) { + + if (Offs == 0) { + AddCodeLine ("ldy #$%02X", (unsigned char) (Arg3.Expr.IVal - 1)); + g_defcodelabel (Label); + AddCodeLine ("lda (sp),y"); + AddCodeLine ("sta %s,y", ED_GetLabelName (&Arg1.Expr, 0)); + AddCodeLine ("dey"); + AddCodeLine ("bpl %s", LocalLabelName (Label)); + } else { + AddCodeLine ("ldx #$%02X", (unsigned char) (Arg3.Expr.IVal-1)); + AddCodeLine ("ldy #$%02X", (unsigned char) (Offs + Arg3.Expr.IVal - 1)); + g_defcodelabel (Label); + AddCodeLine ("lda (sp),y"); + AddCodeLine ("sta %s,x", ED_GetLabelName (&Arg1.Expr, 0)); + AddCodeLine ("dey"); + AddCodeLine ("dex"); + AddCodeLine ("bpl %s", LocalLabelName (Label)); + } + + } else { + + if (Offs == 0 || AllowOneIndex) { + AddCodeLine ("ldy #$%02X", (unsigned char) Offs); + g_defcodelabel (Label); + AddCodeLine ("lda (sp),y"); + AddCodeLine ("sta %s,y", ED_GetLabelName (&Arg1.Expr, -Offs)); + AddCodeLine ("iny"); + AddCmpCodeIfSizeNot256 ("cpy #$%02X", Offs + Arg3.Expr.IVal); + AddCodeLine ("bne %s", LocalLabelName (Label)); + } else { + AddCodeLine ("ldx #$00"); + AddCodeLine ("ldy #$%02X", (unsigned char) Offs); + g_defcodelabel (Label); + AddCodeLine ("lda (sp),y"); + AddCodeLine ("sta %s,x", ED_GetLabelName (&Arg1.Expr, 0)); + AddCodeLine ("iny"); + AddCodeLine ("inx"); + AddCmpCodeIfSizeNot256 ("cpx #$%02X", Arg3.Expr.IVal); + AddCodeLine ("bne %s", LocalLabelName (Label)); + } + + } + + /* memcpy returns the address, so the result is actually identical + ** to the first argument. + */ + *Expr = Arg1.Expr; + + /* Bail out, no need for further processing */ + goto ExitPoint; + } + + if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.IVal <= 256 && + ED_IsRVal (&Arg2.Expr) && ED_IsLocStack (&Arg2.Expr) && + (Offs = ED_GetStackOffs (&Arg2.Expr, 0)) == 0) { + + /* Drop the generated code but leave the load of the first argument*/ + RemoveCode (&Arg1.Push); + + /* We need a label */ + Label = GetLocalLabel (); + + /* Generate memcpy code */ + AddCodeLine ("sta ptr1"); + AddCodeLine ("stx ptr1+1"); + if (Arg3.Expr.IVal <= 129) { AddCodeLine ("ldy #$%02X", (unsigned char) (Arg3.Expr.IVal - 1)); g_defcodelabel (Label); AddCodeLine ("lda (sp),y"); - AddCodeLine ("sta %s,y", ED_GetLabelName (&Arg1.Expr, 0)); + AddCodeLine ("sta (ptr1),y"); AddCodeLine ("dey"); AddCodeLine ("bpl %s", LocalLabelName (Label)); } else { - AddCodeLine ("ldx #$%02X", (unsigned char) (Arg3.Expr.IVal-1)); - AddCodeLine ("ldy #$%02X", (unsigned char) (Offs + Arg3.Expr.IVal - 1)); + AddCodeLine ("ldy #$00"); g_defcodelabel (Label); AddCodeLine ("lda (sp),y"); - AddCodeLine ("sta %s,x", ED_GetLabelName (&Arg1.Expr, 0)); - AddCodeLine ("dey"); - AddCodeLine ("dex"); - AddCodeLine ("bpl %s", LocalLabelName (Label)); - } - - } else { - - if (Offs == 0 || AllowOneIndex) { - AddCodeLine ("ldy #$%02X", (unsigned char) Offs); - g_defcodelabel (Label); - AddCodeLine ("lda (sp),y"); - AddCodeLine ("sta %s,y", ED_GetLabelName (&Arg1.Expr, -Offs)); + AddCodeLine ("sta (ptr1),y"); AddCodeLine ("iny"); - AddCmpCodeIfSizeNot256 ("cpy #$%02X", Offs + Arg3.Expr.IVal); - AddCodeLine ("bne %s", LocalLabelName (Label)); - } else { - AddCodeLine ("ldx #$00"); - AddCodeLine ("ldy #$%02X", (unsigned char) Offs); - g_defcodelabel (Label); - AddCodeLine ("lda (sp),y"); - AddCodeLine ("sta %s,x", ED_GetLabelName (&Arg1.Expr, 0)); - AddCodeLine ("iny"); - AddCodeLine ("inx"); - AddCmpCodeIfSizeNot256 ("cpx #$%02X", Arg3.Expr.IVal); + AddCmpCodeIfSizeNot256 ("cpy #$%02X", Arg3.Expr.IVal); AddCodeLine ("bne %s", LocalLabelName (Label)); } + /* Reload result - X hasn't changed by the code above */ + AddCodeLine ("lda ptr1"); + + /* The function result is an rvalue in the primary register */ + ED_MakeRValExpr (Expr); + Expr->Type = GetFuncReturn (Expr->Type); + + /* Bail out, no need for further processing */ + goto ExitPoint; } - - /* memcpy returns the address, so the result is actually identical - ** to the first argument. - */ - *Expr = Arg1.Expr; - - } else if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.IVal <= 256 && - ED_IsRVal (&Arg2.Expr) && ED_IsLocStack (&Arg2.Expr) && - (Offs = ED_GetStackOffs (&Arg2.Expr, 0)) == 0) { - - /* Drop the generated code but leave the load of the first argument*/ - RemoveCode (&Arg1.Push); - - /* We need a label */ - Label = GetLocalLabel (); - - /* Generate memcpy code */ - AddCodeLine ("sta ptr1"); - AddCodeLine ("stx ptr1+1"); - if (Arg3.Expr.IVal <= 127) { - AddCodeLine ("ldy #$%02X", (unsigned char) (Arg3.Expr.IVal - 1)); - g_defcodelabel (Label); - AddCodeLine ("lda (sp),y"); - AddCodeLine ("sta (ptr1),y"); - AddCodeLine ("dey"); - AddCodeLine ("bpl %s", LocalLabelName (Label)); - } else { - AddCodeLine ("ldy #$00"); - g_defcodelabel (Label); - AddCodeLine ("lda (sp),y"); - AddCodeLine ("sta (ptr1),y"); - AddCodeLine ("iny"); - AddCmpCodeIfSizeNot256 ("cpy #$%02X", Arg3.Expr.IVal); - AddCodeLine ("bne %s", LocalLabelName (Label)); - } - - /* Reload result - X hasn't changed by the code above */ - AddCodeLine ("lda ptr1"); - - /* The function result is an rvalue in the primary register */ - ED_MakeRValExpr (Expr); - Expr->Type = GetFuncReturn (Expr->Type); - - } else { - - /* The function result is an rvalue in the primary register */ - ED_MakeRValExpr (Expr); - Expr->Type = GetFuncReturn (Expr->Type); - } + /* The function result is an rvalue in the primary register */ + ED_MakeRValExpr (Expr); + Expr->Type = GetFuncReturn (Expr->Type); + ExitPoint: /* We expect the closing brace */ ConsumeRParen (); @@ -595,140 +610,151 @@ static void StdFunc_memset (FuncDesc* F attribute ((unused)), ExprDesc* Expr) goto ExitPoint; } - /* We've generated the complete code for the function now and know the - ** types of all parameters. Check for situations where better code can - ** be generated. If such a situation is detected, throw away the - ** generated, and emit better code. - ** Note: Lots of improvements would be possible here, but I will - ** concentrate on the most common case: memset with arguments 2 and 3 - ** being constant numerical values. Some checks have shown that this - ** covers nearly 90% of all memset calls. - */ - if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.IVal <= 256 && - ED_IsConstAbsInt (&Arg2.Expr) && - ((ED_IsRVal (&Arg1.Expr) && ED_IsLocConst (&Arg1.Expr)) || - (ED_IsLVal (&Arg1.Expr) && ED_IsLocRegister (&Arg1.Expr)))) { + if (IS_Get (&InlineStdFuncs)) { - int Reg = ED_IsLVal (&Arg1.Expr) && ED_IsLocRegister (&Arg1.Expr); + /* We've generated the complete code for the function now and know the + ** types of all parameters. Check for situations where better code can + ** be generated. If such a situation is detected, throw away the + ** generated, and emit better code. + ** Note: Lots of improvements would be possible here, but I will + ** concentrate on the most common case: memset with arguments 2 and 3 + ** being constant numerical values. Some checks have shown that this + ** covers nearly 90% of all memset calls. + */ + if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.IVal <= 256 && + ED_IsConstAbsInt (&Arg2.Expr) && + ((ED_IsRVal (&Arg1.Expr) && ED_IsLocConst (&Arg1.Expr)) || + (ED_IsLVal (&Arg1.Expr) && ED_IsLocRegister (&Arg1.Expr)))) { - /* Drop the generated code */ - RemoveCode (&Arg1.Expr.Start); + int Reg = ED_IsLVal (&Arg1.Expr) && ED_IsLocRegister (&Arg1.Expr); - /* We need a label */ - Label = GetLocalLabel (); + /* Drop the generated code */ + RemoveCode (&Arg1.Expr.Start); - /* Generate memset code */ - if (Arg3.Expr.IVal <= 127) { + /* We need a label */ + Label = GetLocalLabel (); + + /* Generate memset code */ + if (Arg3.Expr.IVal <= 129) { + + AddCodeLine ("ldy #$%02X", (unsigned char) (Arg3.Expr.IVal-1)); + AddCodeLine ("lda #$%02X", (unsigned char) Arg2.Expr.IVal); + g_defcodelabel (Label); + if (Reg) { + AddCodeLine ("sta (%s),y", ED_GetLabelName (&Arg1.Expr, 0)); + } else { + AddCodeLine ("sta %s,y", ED_GetLabelName (&Arg1.Expr, 0)); + } + AddCodeLine ("dey"); + AddCodeLine ("bpl %s", LocalLabelName (Label)); - AddCodeLine ("ldy #$%02X", (unsigned char) (Arg3.Expr.IVal-1)); - AddCodeLine ("lda #$%02X", (unsigned char) Arg2.Expr.IVal); - g_defcodelabel (Label); - if (Reg) { - AddCodeLine ("sta (%s),y", ED_GetLabelName (&Arg1.Expr, 0)); } else { - AddCodeLine ("sta %s,y", ED_GetLabelName (&Arg1.Expr, 0)); + + AddCodeLine ("ldy #$00"); + AddCodeLine ("lda #$%02X", (unsigned char) Arg2.Expr.IVal); + g_defcodelabel (Label); + if (Reg) { + AddCodeLine ("sta (%s),y", ED_GetLabelName (&Arg1.Expr, 0)); + } else { + AddCodeLine ("sta %s,y", ED_GetLabelName (&Arg1.Expr, 0)); + } + AddCodeLine ("iny"); + AddCmpCodeIfSizeNot256 ("cpy #$%02X", Arg3.Expr.IVal); + AddCodeLine ("bne %s", LocalLabelName (Label)); + } - AddCodeLine ("dey"); - AddCodeLine ("bpl %s", LocalLabelName (Label)); - } else { - - AddCodeLine ("ldy #$00"); - AddCodeLine ("lda #$%02X", (unsigned char) Arg2.Expr.IVal); - g_defcodelabel (Label); - if (Reg) { - AddCodeLine ("sta (%s),y", ED_GetLabelName (&Arg1.Expr, 0)); - } else { - AddCodeLine ("sta %s,y", ED_GetLabelName (&Arg1.Expr, 0)); - } - AddCodeLine ("iny"); - AddCmpCodeIfSizeNot256 ("cpy #$%02X", Arg3.Expr.IVal); - AddCodeLine ("bne %s", LocalLabelName (Label)); + /* memset returns the address, so the result is actually identical + ** to the first argument. + */ + *Expr = Arg1.Expr; + /* Bail out, no need for further processing */ + goto ExitPoint; } - /* memset returns the address, so the result is actually identical - ** to the first argument. - */ - *Expr = Arg1.Expr; + if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.IVal <= 256 && + ED_IsConstAbsInt (&Arg2.Expr) && + ED_IsRVal (&Arg1.Expr) && ED_IsLocStack (&Arg1.Expr) && + (Arg1.Expr.IVal - StackPtr) + Arg3.Expr.IVal < 256) { - } else if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.IVal <= 256 && - ED_IsConstAbsInt (&Arg2.Expr) && - ED_IsRVal (&Arg1.Expr) && ED_IsLocStack (&Arg1.Expr) && - (Arg1.Expr.IVal - StackPtr) + Arg3.Expr.IVal < 256) { + /* Calculate the real stack offset */ + int Offs = ED_GetStackOffs (&Arg1.Expr, 0); - /* Calculate the real stack offset */ - int Offs = ED_GetStackOffs (&Arg1.Expr, 0); + /* Drop the generated code */ + RemoveCode (&Arg1.Expr.Start); - /* Drop the generated code */ - RemoveCode (&Arg1.Expr.Start); + /* We need a label */ + Label = GetLocalLabel (); - /* We need a label */ - Label = GetLocalLabel (); - - /* Generate memset code */ - AddCodeLine ("ldy #$%02X", (unsigned char) Offs); - AddCodeLine ("lda #$%02X", (unsigned char) Arg2.Expr.IVal); - g_defcodelabel (Label); - AddCodeLine ("sta (sp),y"); - AddCodeLine ("iny"); - AddCmpCodeIfSizeNot256 ("cpy #$%02X", Offs + Arg3.Expr.IVal); - AddCodeLine ("bne %s", LocalLabelName (Label)); - - /* memset returns the address, so the result is actually identical - ** to the first argument. - */ - *Expr = Arg1.Expr; - - } else if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.IVal <= 256 && - ED_IsConstAbsInt (&Arg2.Expr) && - (Arg2.Expr.IVal != 0 || IS_Get (&CodeSizeFactor) > 200)) { - - /* Remove all of the generated code but the load of the first - ** argument. - */ - RemoveCode (&Arg1.Push); - - /* We need a label */ - Label = GetLocalLabel (); - - /* Generate code */ - AddCodeLine ("sta ptr1"); - AddCodeLine ("stx ptr1+1"); - if (Arg3.Expr.IVal <= 127) { - AddCodeLine ("ldy #$%02X", (unsigned char) (Arg3.Expr.IVal-1)); + /* Generate memset code */ + AddCodeLine ("ldy #$%02X", (unsigned char) Offs); AddCodeLine ("lda #$%02X", (unsigned char) Arg2.Expr.IVal); g_defcodelabel (Label); - AddCodeLine ("sta (ptr1),y"); - AddCodeLine ("dey"); - AddCodeLine ("bpl %s", LocalLabelName (Label)); - } else { - AddCodeLine ("ldy #$00"); - AddCodeLine ("lda #$%02X", (unsigned char) Arg2.Expr.IVal); - g_defcodelabel (Label); - AddCodeLine ("sta (ptr1),y"); + AddCodeLine ("sta (sp),y"); AddCodeLine ("iny"); - AddCmpCodeIfSizeNot256 ("cpy #$%02X", Arg3.Expr.IVal); + AddCmpCodeIfSizeNot256 ("cpy #$%02X", Offs + Arg3.Expr.IVal); AddCodeLine ("bne %s", LocalLabelName (Label)); + + /* memset returns the address, so the result is actually identical + ** to the first argument. + */ + *Expr = Arg1.Expr; + + /* Bail out, no need for further processing */ + goto ExitPoint; } - /* Load the function result pointer into a/x (x is still valid). This - ** code will get removed by the optimizer if it is not used later. - */ - AddCodeLine ("lda ptr1"); + if (ED_IsConstAbsInt (&Arg3.Expr) && Arg3.Expr.IVal <= 256 && + ED_IsConstAbsInt (&Arg2.Expr) && + (Arg2.Expr.IVal != 0 || IS_Get (&CodeSizeFactor) > 200)) { - /* The function result is an rvalue in the primary register */ - ED_MakeRValExpr (Expr); - Expr->Type = GetFuncReturn (Expr->Type); + /* Remove all of the generated code but the load of the first + ** argument. + */ + RemoveCode (&Arg1.Push); - } else { + /* We need a label */ + Label = GetLocalLabel (); - /* The function result is an rvalue in the primary register */ - ED_MakeRValExpr (Expr); - Expr->Type = GetFuncReturn (Expr->Type); + /* Generate code */ + AddCodeLine ("sta ptr1"); + AddCodeLine ("stx ptr1+1"); + if (Arg3.Expr.IVal <= 129) { + AddCodeLine ("ldy #$%02X", (unsigned char) (Arg3.Expr.IVal-1)); + AddCodeLine ("lda #$%02X", (unsigned char) Arg2.Expr.IVal); + g_defcodelabel (Label); + AddCodeLine ("sta (ptr1),y"); + AddCodeLine ("dey"); + AddCodeLine ("bpl %s", LocalLabelName (Label)); + } else { + AddCodeLine ("ldy #$00"); + AddCodeLine ("lda #$%02X", (unsigned char) Arg2.Expr.IVal); + g_defcodelabel (Label); + AddCodeLine ("sta (ptr1),y"); + AddCodeLine ("iny"); + AddCmpCodeIfSizeNot256 ("cpy #$%02X", Arg3.Expr.IVal); + AddCodeLine ("bne %s", LocalLabelName (Label)); + } + /* Load the function result pointer into a/x (x is still valid). This + ** code will get removed by the optimizer if it is not used later. + */ + AddCodeLine ("lda ptr1"); + + /* The function result is an rvalue in the primary register */ + ED_MakeRValExpr (Expr); + Expr->Type = GetFuncReturn (Expr->Type); + + /* Bail out, no need for further processing */ + goto ExitPoint; + } } + /* The function result is an rvalue in the primary register */ + ED_MakeRValExpr (Expr); + Expr->Type = GetFuncReturn (Expr->Type); + ExitPoint: /* We expect the closing brace */ ConsumeRParen (); @@ -790,142 +816,142 @@ static void StdFunc_strcmp (FuncDesc* F attribute ((unused)), ExprDesc* Expr) ECount1 = ECount2; } - /* If the second argument is the empty string literal, we can generate - ** more efficient code. - */ - if (ED_IsLocLiteral (&Arg2.Expr) && - IS_Get (&WritableStrings) == 0 && - GetLiteralSize (Arg2.Expr.LVal) == 1 && - GetLiteralStr (Arg2.Expr.LVal)[0] == '\0') { + if (IS_Get (&InlineStdFuncs)) { - /* Drop the generated code so we have the first argument in the - ** primary + /* If the second argument is the empty string literal, we can generate + ** more efficient code. */ - RemoveCode (&Arg1.Push); + if (ED_IsLocLiteral (&Arg2.Expr) && + IS_Get (&WritableStrings) == 0 && + GetLiteralSize (Arg2.Expr.LVal) == 1 && + GetLiteralStr (Arg2.Expr.LVal)[0] == '\0') { - /* We don't need the literal any longer */ - ReleaseLiteral (Arg2.Expr.LVal); - - /* We do now have Arg1 in the primary. Load the first character from - ** this string and cast to int. This is the function result. - */ - IsArray = IsTypeArray (Arg1.Type) && ED_IsRVal (&Arg1.Expr); - if (IsArray && ED_IsLocStack (&Arg1.Expr) && - (Offs = ED_GetStackOffs (&Arg1.Expr, 0) < 256)) { - /* Drop the generated code */ - RemoveCode (&Arg1.Load); - - /* Generate code */ - AddCodeLine ("ldy #$%02X", Offs); - AddCodeLine ("ldx #$00"); - AddCodeLine ("lda (sp),y"); - } else if (IsArray && ED_IsLocConst (&Arg1.Expr)) { - /* Drop the generated code */ - RemoveCode (&Arg1.Load); - - /* Generate code */ - AddCodeLine ("ldx #$00"); - AddCodeLine ("lda %s", ED_GetLabelName (&Arg1.Expr, 0)); - } else { - /* Drop part of the generated code so we have the first argument - ** in the primary + /* Drop the generated code so we have the first argument in the + ** primary */ RemoveCode (&Arg1.Push); - /* Fetch the first char */ - g_getind (CF_CHAR | CF_UNSIGNED, 0); + /* We don't need the literal any longer */ + ReleaseLiteral (Arg2.Expr.LVal); + + /* We do now have Arg1 in the primary. Load the first character from + ** this string and cast to int. This is the function result. + */ + IsArray = IsTypeArray (Arg1.Type) && ED_IsRVal (&Arg1.Expr); + if (IsArray && ED_IsLocStack (&Arg1.Expr) && + (Offs = ED_GetStackOffs (&Arg1.Expr, 0) < 256)) { + /* Drop the generated code */ + RemoveCode (&Arg1.Load); + + /* Generate code */ + AddCodeLine ("ldy #$%02X", Offs); + AddCodeLine ("ldx #$00"); + AddCodeLine ("lda (sp),y"); + } else if (IsArray && ED_IsLocConst (&Arg1.Expr)) { + /* Drop the generated code */ + RemoveCode (&Arg1.Load); + + /* Generate code */ + AddCodeLine ("ldx #$00"); + AddCodeLine ("lda %s", ED_GetLabelName (&Arg1.Expr, 0)); + } else { + /* Drop part of the generated code so we have the first argument + ** in the primary + */ + RemoveCode (&Arg1.Push); + + /* Fetch the first char */ + g_getind (CF_CHAR | CF_UNSIGNED, 0); + } + + } else if ((IS_Get (&CodeSizeFactor) >= 165) && + ((ED_IsRVal (&Arg2.Expr) && ED_IsLocConst (&Arg2.Expr)) || + (ED_IsLVal (&Arg2.Expr) && ED_IsLocRegister (&Arg2.Expr))) && + ((ED_IsRVal (&Arg1.Expr) && ED_IsLocConst (&Arg1.Expr)) || + (ED_IsLVal (&Arg1.Expr) && ED_IsLocRegister (&Arg1.Expr))) && + (IS_Get (&EagerlyInlineFuncs) || (ECount1 > 0 && ECount1 < 256))) { + + unsigned Entry, Loop, Fin; /* Labels */ + const char* Load; + const char* Compare; + + if (ED_IsLVal (&Arg1.Expr) && ED_IsLocRegister (&Arg1.Expr)) { + Load = "lda (%s),y"; + } else { + Load = "lda %s,y"; + } + if (ED_IsLVal (&Arg2.Expr) && ED_IsLocRegister (&Arg2.Expr)) { + Compare = "cmp (%s),y"; + } else { + Compare = "cmp %s,y"; + } + + /* Drop the generated code */ + RemoveCode (&Arg1.Expr.Start); + + /* We need labels */ + Entry = GetLocalLabel (); + Loop = GetLocalLabel (); + Fin = GetLocalLabel (); + + /* Generate strcmp code */ + AddCodeLine ("ldy #$00"); + AddCodeLine ("beq %s", LocalLabelName (Entry)); + g_defcodelabel (Loop); + AddCodeLine ("tax"); + AddCodeLine ("beq %s", LocalLabelName (Fin)); + AddCodeLine ("iny"); + g_defcodelabel (Entry); + AddCodeLine (Load, ED_GetLabelName (&Arg1.Expr, 0)); + AddCodeLine (Compare, ED_GetLabelName (&Arg2.Expr, 0)); + AddCodeLine ("beq %s", LocalLabelName (Loop)); + AddCodeLine ("ldx #$01"); + AddCodeLine ("bcs %s", LocalLabelName (Fin)); + AddCodeLine ("ldx #$FF"); + g_defcodelabel (Fin); + + } else if ((IS_Get (&CodeSizeFactor) > 190) && + ((ED_IsRVal (&Arg2.Expr) && ED_IsLocConst (&Arg2.Expr)) || + (ED_IsLVal (&Arg2.Expr) && ED_IsLocRegister (&Arg2.Expr))) && + (IS_Get (&EagerlyInlineFuncs) || (ECount1 > 0 && ECount1 < 256))) { + + unsigned Entry, Loop, Fin; /* Labels */ + const char* Compare; + + if (ED_IsLVal (&Arg2.Expr) && ED_IsLocRegister (&Arg2.Expr)) { + Compare = "cmp (%s),y"; + } else { + Compare = "cmp %s,y"; + } + + /* Drop the generated code */ + RemoveCode (&Arg1.Push); + + /* We need labels */ + Entry = GetLocalLabel (); + Loop = GetLocalLabel (); + Fin = GetLocalLabel (); + + /* Store Arg1 into ptr1 */ + AddCodeLine ("sta ptr1"); + AddCodeLine ("stx ptr1+1"); + + /* Generate strcmp code */ + AddCodeLine ("ldy #$00"); + AddCodeLine ("beq %s", LocalLabelName (Entry)); + g_defcodelabel (Loop); + AddCodeLine ("tax"); + AddCodeLine ("beq %s", LocalLabelName (Fin)); + AddCodeLine ("iny"); + g_defcodelabel (Entry); + AddCodeLine ("lda (ptr1),y"); + AddCodeLine (Compare, ED_GetLabelName (&Arg2.Expr, 0)); + AddCodeLine ("beq %s", LocalLabelName (Loop)); + AddCodeLine ("ldx #$01"); + AddCodeLine ("bcs %s", LocalLabelName (Fin)); + AddCodeLine ("ldx #$FF"); + g_defcodelabel (Fin); } - - } else if ((IS_Get (&CodeSizeFactor) >= 165) && - ((ED_IsRVal (&Arg2.Expr) && ED_IsLocConst (&Arg2.Expr)) || - (ED_IsLVal (&Arg2.Expr) && ED_IsLocRegister (&Arg2.Expr))) && - ((ED_IsRVal (&Arg1.Expr) && ED_IsLocConst (&Arg1.Expr)) || - (ED_IsLVal (&Arg1.Expr) && ED_IsLocRegister (&Arg1.Expr))) && - (IS_Get (&InlineStdFuncs) || (ECount1 > 0 && ECount1 < 256))) { - - - unsigned Entry, Loop, Fin; /* Labels */ - const char* Load; - const char* Compare; - - if (ED_IsLVal (&Arg1.Expr) && ED_IsLocRegister (&Arg1.Expr)) { - Load = "lda (%s),y"; - } else { - Load = "lda %s,y"; - } - if (ED_IsLVal (&Arg2.Expr) && ED_IsLocRegister (&Arg2.Expr)) { - Compare = "cmp (%s),y"; - } else { - Compare = "cmp %s,y"; - } - - /* Drop the generated code */ - RemoveCode (&Arg1.Expr.Start); - - /* We need labels */ - Entry = GetLocalLabel (); - Loop = GetLocalLabel (); - Fin = GetLocalLabel (); - - /* Generate strcmp code */ - AddCodeLine ("ldy #$00"); - AddCodeLine ("beq %s", LocalLabelName (Entry)); - g_defcodelabel (Loop); - AddCodeLine ("tax"); - AddCodeLine ("beq %s", LocalLabelName (Fin)); - AddCodeLine ("iny"); - g_defcodelabel (Entry); - AddCodeLine (Load, ED_GetLabelName (&Arg1.Expr, 0)); - AddCodeLine (Compare, ED_GetLabelName (&Arg2.Expr, 0)); - AddCodeLine ("beq %s", LocalLabelName (Loop)); - AddCodeLine ("ldx #$01"); - AddCodeLine ("bcs %s", LocalLabelName (Fin)); - AddCodeLine ("ldx #$FF"); - g_defcodelabel (Fin); - - } else if ((IS_Get (&CodeSizeFactor) > 190) && - ((ED_IsRVal (&Arg2.Expr) && ED_IsLocConst (&Arg2.Expr)) || - (ED_IsLVal (&Arg2.Expr) && ED_IsLocRegister (&Arg2.Expr))) && - (IS_Get (&InlineStdFuncs) || (ECount1 > 0 && ECount1 < 256))) { - - - unsigned Entry, Loop, Fin; /* Labels */ - const char* Compare; - - if (ED_IsLVal (&Arg2.Expr) && ED_IsLocRegister (&Arg2.Expr)) { - Compare = "cmp (%s),y"; - } else { - Compare = "cmp %s,y"; - } - - /* Drop the generated code */ - RemoveCode (&Arg1.Push); - - /* We need labels */ - Entry = GetLocalLabel (); - Loop = GetLocalLabel (); - Fin = GetLocalLabel (); - - /* Store Arg1 into ptr1 */ - AddCodeLine ("sta ptr1"); - AddCodeLine ("stx ptr1+1"); - - /* Generate strcmp code */ - AddCodeLine ("ldy #$00"); - AddCodeLine ("beq %s", LocalLabelName (Entry)); - g_defcodelabel (Loop); - AddCodeLine ("tax"); - AddCodeLine ("beq %s", LocalLabelName (Fin)); - AddCodeLine ("iny"); - g_defcodelabel (Entry); - AddCodeLine ("lda (ptr1),y"); - AddCodeLine (Compare, ED_GetLabelName (&Arg2.Expr, 0)); - AddCodeLine ("beq %s", LocalLabelName (Loop)); - AddCodeLine ("ldx #$01"); - AddCodeLine ("bcs %s", LocalLabelName (Fin)); - AddCodeLine ("ldx #$FF"); - g_defcodelabel (Fin); - } /* The function result is an rvalue in the primary register */ @@ -983,142 +1009,154 @@ static void StdFunc_strcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr) /* Get the element count of argument 1 if it is an array */ ECount = ArrayElementCount (&Arg1); - /* We've generated the complete code for the function now and know the - ** types of all parameters. Check for situations where better code can - ** be generated. If such a situation is detected, throw away the - ** generated, and emit better code. - */ - if (((ED_IsRVal (&Arg2.Expr) && ED_IsLocConst (&Arg2.Expr)) || - (ED_IsLVal (&Arg2.Expr) && ED_IsLocRegister (&Arg2.Expr))) && - ((ED_IsRVal (&Arg1.Expr) && ED_IsLocConst (&Arg1.Expr)) || - (ED_IsLVal (&Arg1.Expr) && ED_IsLocRegister (&Arg1.Expr))) && - (IS_Get (&InlineStdFuncs) || - (ECount != UNSPECIFIED && ECount < 256))) { + if (IS_Get (&InlineStdFuncs)) { - const char* Load; - const char* Store; - if (ED_IsLVal (&Arg2.Expr) && ED_IsLocRegister (&Arg2.Expr)) { - Load = "lda (%s),y"; - } else { - Load = "lda %s,y"; - } - if (ED_IsLVal (&Arg1.Expr) && ED_IsLocRegister (&Arg1.Expr)) { - Store = "sta (%s),y"; - } else { - Store = "sta %s,y"; - } - - /* Drop the generated code */ - RemoveCode (&Arg1.Expr.Start); - - /* We need labels */ - L1 = GetLocalLabel (); - - /* Generate strcpy code */ - AddCodeLine ("ldy #$FF"); - g_defcodelabel (L1); - AddCodeLine ("iny"); - AddCodeLine (Load, ED_GetLabelName (&Arg2.Expr, 0)); - AddCodeLine (Store, ED_GetLabelName (&Arg1.Expr, 0)); - AddCodeLine ("bne %s", LocalLabelName (L1)); - - /* strcpy returns argument #1 */ - *Expr = Arg1.Expr; - - } else if (ED_IsRVal (&Arg2.Expr) && ED_IsLocStack (&Arg2.Expr) && - StackPtr >= -255 && - ED_IsRVal (&Arg1.Expr) && ED_IsLocConst (&Arg1.Expr)) { - - /* It is possible to just use one index register even if the stack - ** offset is not zero, by adjusting the offset to the constant - ** address accordingly. But we cannot do this if the data in - ** question is in the register space or at an absolute address less - ** than 256. Register space is zero page, which means that the - ** address calculation could overflow in the linker. + /* We've generated the complete code for the function now and know the + ** types of all parameters. Check for situations where better code can + ** be generated. If such a situation is detected, throw away the + ** generated, and emit better code. */ - int AllowOneIndex = !ED_IsLocRegister (&Arg1.Expr) && - !(ED_IsLocAbs (&Arg1.Expr) && Arg1.Expr.IVal < 256); + if (((ED_IsRVal (&Arg2.Expr) && ED_IsLocConst (&Arg2.Expr)) || + (ED_IsLVal (&Arg2.Expr) && ED_IsLocRegister (&Arg2.Expr))) && + ((ED_IsRVal (&Arg1.Expr) && ED_IsLocConst (&Arg1.Expr)) || + (ED_IsLVal (&Arg1.Expr) && ED_IsLocRegister (&Arg1.Expr))) && + (IS_Get (&EagerlyInlineFuncs) || + (ECount != UNSPECIFIED && ECount < 256))) { - /* Calculate the real stack offset */ - int Offs = ED_GetStackOffs (&Arg2.Expr, 0); + const char* Load; + const char* Store; + if (ED_IsLVal (&Arg2.Expr) && ED_IsLocRegister (&Arg2.Expr)) { + Load = "lda (%s),y"; + } else { + Load = "lda %s,y"; + } + if (ED_IsLVal (&Arg1.Expr) && ED_IsLocRegister (&Arg1.Expr)) { + Store = "sta (%s),y"; + } else { + Store = "sta %s,y"; + } - /* Drop the generated code */ - RemoveCode (&Arg1.Expr.Start); + /* Drop the generated code */ + RemoveCode (&Arg1.Expr.Start); - /* We need labels */ - L1 = GetLocalLabel (); + /* We need labels */ + L1 = GetLocalLabel (); - /* Generate strcpy code */ - AddCodeLine ("ldy #$%02X", (unsigned char) (Offs - 1)); - if (Offs == 0 || AllowOneIndex) { + /* Generate strcpy code */ + AddCodeLine ("ldy #$FF"); g_defcodelabel (L1); AddCodeLine ("iny"); - AddCodeLine ("lda (sp),y"); - AddCodeLine ("sta %s,y", ED_GetLabelName (&Arg1.Expr, -Offs)); - } else { - AddCodeLine ("ldx #$FF"); - g_defcodelabel (L1); - AddCodeLine ("iny"); - AddCodeLine ("inx"); - AddCodeLine ("lda (sp),y"); - AddCodeLine ("sta %s,x", ED_GetLabelName (&Arg1.Expr, 0)); + AddCodeLine (Load, ED_GetLabelName (&Arg2.Expr, 0)); + AddCodeLine (Store, ED_GetLabelName (&Arg1.Expr, 0)); + AddCodeLine ("bne %s", LocalLabelName (L1)); + + /* strcpy returns argument #1 */ + *Expr = Arg1.Expr; + + /* Bail out, no need for further processing */ + goto ExitPoint; } - AddCodeLine ("bne %s", LocalLabelName (L1)); - /* strcpy returns argument #1 */ - *Expr = Arg1.Expr; + if (ED_IsRVal (&Arg2.Expr) && ED_IsLocStack (&Arg2.Expr) && + StackPtr >= -255 && + ED_IsRVal (&Arg1.Expr) && ED_IsLocConst (&Arg1.Expr)) { - } else if (ED_IsRVal (&Arg2.Expr) && ED_IsLocConst (&Arg2.Expr) && - ED_IsRVal (&Arg1.Expr) && ED_IsLocStack (&Arg1.Expr) && - StackPtr >= -255) { + /* It is possible to just use one index register even if the stack + ** offset is not zero, by adjusting the offset to the constant + ** address accordingly. But we cannot do this if the data in + ** question is in the register space or at an absolute address less + ** than 256. Register space is zero page, which means that the + ** address calculation could overflow in the linker. + */ + int AllowOneIndex = !ED_IsLocRegister (&Arg1.Expr) && + !(ED_IsLocAbs (&Arg1.Expr) && Arg1.Expr.IVal < 256); - /* It is possible to just use one index register even if the stack - ** offset is not zero, by adjusting the offset to the constant - ** address accordingly. But we cannot do this if the data in - ** question is in the register space or at an absolute address less - ** than 256. Register space is zero page, which means that the - ** address calculation could overflow in the linker. - */ - int AllowOneIndex = !ED_IsLocRegister (&Arg2.Expr) && - !(ED_IsLocAbs (&Arg2.Expr) && Arg2.Expr.IVal < 256); + /* Calculate the real stack offset */ + int Offs = ED_GetStackOffs (&Arg2.Expr, 0); - /* Calculate the real stack offset */ - int Offs = ED_GetStackOffs (&Arg1.Expr, 0); + /* Drop the generated code */ + RemoveCode (&Arg1.Expr.Start); - /* Drop the generated code */ - RemoveCode (&Arg1.Expr.Start); + /* We need labels */ + L1 = GetLocalLabel (); - /* We need labels */ - L1 = GetLocalLabel (); + /* Generate strcpy code */ + AddCodeLine ("ldy #$%02X", (unsigned char) (Offs - 1)); + if (Offs == 0 || AllowOneIndex) { + g_defcodelabel (L1); + AddCodeLine ("iny"); + AddCodeLine ("lda (sp),y"); + AddCodeLine ("sta %s,y", ED_GetLabelName (&Arg1.Expr, -Offs)); + } else { + AddCodeLine ("ldx #$FF"); + g_defcodelabel (L1); + AddCodeLine ("iny"); + AddCodeLine ("inx"); + AddCodeLine ("lda (sp),y"); + AddCodeLine ("sta %s,x", ED_GetLabelName (&Arg1.Expr, 0)); + } + AddCodeLine ("bne %s", LocalLabelName (L1)); - /* Generate strcpy code */ - AddCodeLine ("ldy #$%02X", (unsigned char) (Offs - 1)); - if (Offs == 0 || AllowOneIndex) { - g_defcodelabel (L1); - AddCodeLine ("iny"); - AddCodeLine ("lda %s,y", ED_GetLabelName (&Arg2.Expr, -Offs)); - AddCodeLine ("sta (sp),y"); - } else { - AddCodeLine ("ldx #$FF"); - g_defcodelabel (L1); - AddCodeLine ("iny"); - AddCodeLine ("inx"); - AddCodeLine ("lda %s,x", ED_GetLabelName (&Arg2.Expr, 0)); - AddCodeLine ("sta (sp),y"); + /* strcpy returns argument #1 */ + *Expr = Arg1.Expr; + + /* Bail out, no need for further processing */ + goto ExitPoint; } - AddCodeLine ("bne %s", LocalLabelName (L1)); - /* strcpy returns argument #1 */ - *Expr = Arg1.Expr; + if (ED_IsRVal (&Arg2.Expr) && ED_IsLocConst (&Arg2.Expr) && + ED_IsRVal (&Arg1.Expr) && ED_IsLocStack (&Arg1.Expr) && + StackPtr >= -255) { - } else { + /* It is possible to just use one index register even if the stack + ** offset is not zero, by adjusting the offset to the constant + ** address accordingly. But we cannot do this if the data in + ** question is in the register space or at an absolute address less + ** than 256. Register space is zero page, which means that the + ** address calculation could overflow in the linker. + */ + int AllowOneIndex = !ED_IsLocRegister (&Arg2.Expr) && + !(ED_IsLocAbs (&Arg2.Expr) && Arg2.Expr.IVal < 256); - /* The function result is an rvalue in the primary register */ - ED_MakeRValExpr (Expr); - Expr->Type = GetFuncReturn (Expr->Type); + /* Calculate the real stack offset */ + int Offs = ED_GetStackOffs (&Arg1.Expr, 0); + /* Drop the generated code */ + RemoveCode (&Arg1.Expr.Start); + + /* We need labels */ + L1 = GetLocalLabel (); + + /* Generate strcpy code */ + AddCodeLine ("ldy #$%02X", (unsigned char) (Offs - 1)); + if (Offs == 0 || AllowOneIndex) { + g_defcodelabel (L1); + AddCodeLine ("iny"); + AddCodeLine ("lda %s,y", ED_GetLabelName (&Arg2.Expr, -Offs)); + AddCodeLine ("sta (sp),y"); + } else { + AddCodeLine ("ldx #$FF"); + g_defcodelabel (L1); + AddCodeLine ("iny"); + AddCodeLine ("inx"); + AddCodeLine ("lda %s,x", ED_GetLabelName (&Arg2.Expr, 0)); + AddCodeLine ("sta (sp),y"); + } + AddCodeLine ("bne %s", LocalLabelName (L1)); + + /* strcpy returns argument #1 */ + *Expr = Arg1.Expr; + + /* Bail out, no need for further processing */ + goto ExitPoint; + } } + /* The function result is an rvalue in the primary register */ + ED_MakeRValExpr (Expr); + Expr->Type = GetFuncReturn (Expr->Type); + +ExitPoint: /* We expect the closing brace */ ConsumeRParen (); } @@ -1142,8 +1180,6 @@ static void StdFunc_strlen (FuncDesc* F attribute ((unused)), ExprDesc* Expr) long ECount; unsigned L; - - /* Setup the argument type string */ ArgType[1].C = GetDefaultChar () | T_QUAL_CONST; @@ -1175,125 +1211,147 @@ static void StdFunc_strlen (FuncDesc* F attribute ((unused)), ExprDesc* Expr) /* Do type conversion */ TypeConversion (&Arg, ArgType); - /* If the expression is a literal, and if string literals are read - ** only, we can calculate the length of the string and remove it - ** from the literal pool. Otherwise we have to calculate the length - ** at runtime. - */ - if (ED_IsLocLiteral (&Arg) && IS_Get (&WritableStrings) == 0) { + if (IS_Get (&Optimize)) { - /* Constant string literal */ - ED_MakeConstAbs (Expr, GetLiteralSize (Arg.LVal) - 1, type_size_t); + /* If the expression is a literal, and if string literals are read + ** only, we can calculate the length of the string and remove it + ** from the literal pool. Otherwise we have to calculate the length + ** at runtime. + */ + if (ED_IsLocLiteral (&Arg) && IS_Get (&WritableStrings) == 0) { - /* We don't need the literal any longer */ - ReleaseLiteral (Arg.LVal); + /* Constant string literal */ + ED_MakeConstAbs (Expr, GetLiteralSize (Arg.LVal) - 1, type_size_t); - /* We will inline strlen for arrays with constant addresses, if either the - ** inlining was forced on the command line, or the array is smaller than - ** 256, so the inlining is considered safe. - */ - } else if (ED_IsLocConst (&Arg) && IsArray && - (IS_Get (&InlineStdFuncs) || IsByteIndex)) { - - /* Generate the strlen code */ - L = GetLocalLabel (); - AddCodeLine ("ldy #$FF"); - g_defcodelabel (L); - AddCodeLine ("iny"); - AddCodeLine ("lda %s,y", ED_GetLabelName (&Arg, 0)); - AddCodeLine ("bne %s", LocalLabelName (L)); - AddCodeLine ("tax"); - AddCodeLine ("tya"); - - /* The function result is an rvalue in the primary register */ - ED_MakeRValExpr (Expr); - Expr->Type = type_size_t; - - /* We will inline strlen for arrays on the stack, if the array is - ** completely within the reach of a byte sized index register. - */ - } else if (ED_IsLocStack (&Arg) && IsArray && IsByteIndex && - (Arg.IVal - StackPtr) + ECount < 256) { - - /* Calculate the true stack offset */ - int Offs = ED_GetStackOffs (&Arg, 0); - - /* Generate the strlen code */ - L = GetLocalLabel (); - AddCodeLine ("ldx #$FF"); - AddCodeLine ("ldy #$%02X", (unsigned char) (Offs-1)); - g_defcodelabel (L); - AddCodeLine ("inx"); - AddCodeLine ("iny"); - AddCodeLine ("lda (sp),y"); - AddCodeLine ("bne %s", LocalLabelName (L)); - AddCodeLine ("txa"); - AddCodeLine ("ldx #$00"); - - /* The function result is an rvalue in the primary register */ - ED_MakeRValExpr (Expr); - Expr->Type = type_size_t; - - /* strlen for a string that is pointed to by a register variable will only - ** get inlined if requested on the command line, since we cannot know how - ** big the buffer actually is, so inlining is not always safe. - */ - } else if (ED_IsLocRegister (&Arg) && ED_IsLVal (&Arg) && IsPtr && - IS_Get (&InlineStdFuncs)) { - - /* Generate the strlen code */ - L = GetLocalLabel (); - AddCodeLine ("ldy #$FF"); - g_defcodelabel (L); - AddCodeLine ("iny"); - AddCodeLine ("lda (%s),y", ED_GetLabelName (&Arg, 0)); - AddCodeLine ("bne %s", LocalLabelName (L)); - AddCodeLine ("tax"); - AddCodeLine ("tya"); - - /* The function result is an rvalue in the primary register */ - ED_MakeRValExpr (Expr); - Expr->Type = type_size_t; - - /* Last check: We will inline a generic strlen routine if inlining was - ** requested on the command line, and the code size factor is more than - ** 400 (code is 13 bytes vs. 3 for a jsr call). - */ - } else if (IS_Get (&CodeSizeFactor) > 400 && IS_Get (&InlineStdFuncs)) { - - /* Load the expression into the primary */ - LoadExpr (CF_NONE, &Arg); - - /* Inline the function */ - L = GetLocalLabel (); - AddCodeLine ("sta ptr1"); - AddCodeLine ("stx ptr1+1"); - AddCodeLine ("ldy #$FF"); - g_defcodelabel (L); - AddCodeLine ("iny"); - AddCodeLine ("lda (ptr1),y"); - AddCodeLine ("bne %s", LocalLabelName (L)); - AddCodeLine ("tax"); - AddCodeLine ("tya"); - - /* The function result is an rvalue in the primary register */ - ED_MakeRValExpr (Expr); - Expr->Type = type_size_t; - - } else { - - /* Load the expression into the primary */ - LoadExpr (CF_NONE, &Arg); - - /* Call the strlen function */ - AddCodeLine ("jsr _%s", Func_strlen); - - /* The function result is an rvalue in the primary register */ - ED_MakeRValExpr (Expr); - Expr->Type = type_size_t; + /* We don't need the literal any longer */ + ReleaseLiteral (Arg.LVal); + /* Bail out, no need for further improvements */ + goto ExitPoint; + } } + if (IS_Get (&InlineStdFuncs)) { + + /* We will inline strlen for arrays with constant addresses, if either + ** requested on the command line, or the array is smaller than 256, + ** so the inlining is considered safe. + */ + if (ED_IsLocConst (&Arg) && IsArray && + (IS_Get (&EagerlyInlineFuncs) || IsByteIndex)) { + + /* Generate the strlen code */ + L = GetLocalLabel (); + AddCodeLine ("ldy #$FF"); + g_defcodelabel (L); + AddCodeLine ("iny"); + AddCodeLine ("ldx %s,y", ED_GetLabelName (&Arg, 0)); + AddCodeLine ("bne %s", LocalLabelName (L)); + AddCodeLine ("tya"); + + /* The function result is an rvalue in the primary register */ + ED_MakeRValExpr (Expr); + Expr->Type = type_size_t; + + /* Bail out, no need for further processing */ + goto ExitPoint; + } + + /* We will inline strlen for arrays on the stack, if the array is + ** completely within the reach of a byte sized index register. + */ + if (ED_IsLocStack (&Arg) && IsArray && IsByteIndex && + (Arg.IVal - StackPtr) + ECount < 256) { + + /* Calculate the true stack offset */ + int Offs = ED_GetStackOffs (&Arg, 0); + + /* Generate the strlen code */ + L = GetLocalLabel (); + AddCodeLine ("ldx #$FF"); + AddCodeLine ("ldy #$%02X", (unsigned char) (Offs-1)); + g_defcodelabel (L); + AddCodeLine ("inx"); + AddCodeLine ("iny"); + AddCodeLine ("lda (sp),y"); + AddCodeLine ("bne %s", LocalLabelName (L)); + AddCodeLine ("txa"); + AddCodeLine ("ldx #$00"); + + /* The function result is an rvalue in the primary register */ + ED_MakeRValExpr (Expr); + Expr->Type = type_size_t; + + /* Bail out, no need for further processing */ + goto ExitPoint; + } + + /* strlen for a string that is pointed to by a register variable will only + ** get inlined if requested on the command line, since we cannot know how + ** big the buffer actually is, so inlining is not always safe. + */ + if (ED_IsLocRegister (&Arg) && ED_IsLVal (&Arg) && IsPtr && + IS_Get (&EagerlyInlineFuncs)) { + + /* Generate the strlen code */ + L = GetLocalLabel (); + AddCodeLine ("ldy #$FF"); + g_defcodelabel (L); + AddCodeLine ("iny"); + AddCodeLine ("lda (%s),y", ED_GetLabelName (&Arg, 0)); + AddCodeLine ("bne %s", LocalLabelName (L)); + AddCodeLine ("tax"); + AddCodeLine ("tya"); + + /* The function result is an rvalue in the primary register */ + ED_MakeRValExpr (Expr); + Expr->Type = type_size_t; + + /* Bail out, no need for further processing */ + goto ExitPoint; + } + + /* Last check: We will inline a generic strlen routine if inlining was + ** requested on the command line, and the code size factor is more than + ** 400 (code is 13 bytes vs. 3 for a jsr call). + */ + if (IS_Get (&CodeSizeFactor) > 400 && IS_Get (&EagerlyInlineFuncs)) { + + /* Load the expression into the primary */ + LoadExpr (CF_NONE, &Arg); + + /* Inline the function */ + L = GetLocalLabel (); + AddCodeLine ("sta ptr1"); + AddCodeLine ("stx ptr1+1"); + AddCodeLine ("ldy #$FF"); + g_defcodelabel (L); + AddCodeLine ("iny"); + AddCodeLine ("lda (ptr1),y"); + AddCodeLine ("bne %s", LocalLabelName (L)); + AddCodeLine ("tax"); + AddCodeLine ("tya"); + + /* The function result is an rvalue in the primary register */ + ED_MakeRValExpr (Expr); + Expr->Type = type_size_t; + + /* Bail out, no need for further processing */ + goto ExitPoint; + } + } + + /* Load the expression into the primary */ + LoadExpr (CF_NONE, &Arg); + + /* Call the strlen function */ + AddCodeLine ("jsr _%s", Func_strlen); + + /* The function result is an rvalue in the primary register */ + ED_MakeRValExpr (Expr); + Expr->Type = type_size_t; + +ExitPoint: /* We expect the closing brace */ ConsumeRParen (); } diff --git a/src/cc65/stmt.c b/src/cc65/stmt.c index 84b516dc3..c6167fa78 100644 --- a/src/cc65/stmt.c +++ b/src/cc65/stmt.c @@ -273,9 +273,6 @@ static void WhileStatement (void) /* Remember the current position */ GetCodePos (&CondCodeStart); - /* Emit the code position label */ - g_defcodelabel (CondLabel); - /* Test the loop condition */ TestInParens (LoopLabel, 1); @@ -288,6 +285,9 @@ static void WhileStatement (void) /* Loop body */ Statement (&PendingToken); + /* Emit the while condition label */ + g_defcodelabel (CondLabel); + /* Move the test code here */ GetCodePos (&Here); MoveCode (&CondCodeStart, &CondCodeEnd, &Here); diff --git a/src/cc65/symentry.c b/src/cc65/symentry.c index 980ee27f2..d6e68d1bb 100644 --- a/src/cc65/symentry.c +++ b/src/cc65/symentry.c @@ -71,6 +71,7 @@ SymEntry* NewSymEntry (const char* Name, unsigned Flags) E->Type = 0; E->Attr = 0; E->AsmName = 0; + E->V.BssName = 0; memcpy (E->Name, Name, Len+1); /* Return the new entry */ diff --git a/src/cc65/symentry.h b/src/cc65/symentry.h index 4fa84255b..ff136702f 100644 --- a/src/cc65/symentry.h +++ b/src/cc65/symentry.h @@ -153,6 +153,8 @@ struct SymEntry { struct LiteralPool* LitPool; /* Literal pool for this function */ } F; + /* Segment name for tentantive global definitions */ + const char* BssName; } V; char Name[1]; /* Name, dynamically allocated */ }; diff --git a/src/cc65/symtab.c b/src/cc65/symtab.c index fdf459873..3275332c5 100644 --- a/src/cc65/symtab.c +++ b/src/cc65/symtab.c @@ -821,7 +821,7 @@ SymEntry* AddGlobalSym (const char* Name, const Type* T, unsigned Flags) } /* An extern declaration must not change the current linkage. */ - if (IsFunc || (Flags & (SC_EXTERN | SC_DEF)) == SC_EXTERN) { + if (IsFunc || (Flags & (SC_EXTERN | SC_STORAGE)) == SC_EXTERN) { Flags &= ~SC_EXTERN; } diff --git a/src/cc65/wrappedcall.c b/src/cc65/wrappedcall.c new file mode 100644 index 000000000..2d11245fd --- /dev/null +++ b/src/cc65/wrappedcall.c @@ -0,0 +1,102 @@ +/*****************************************************************************/ +/* */ +/* wrappedcall.c */ +/* */ +/* WrappedCall management */ +/* */ +/* */ +/* */ +/* (C) 2017, Mega Cat Studios */ +/* */ +/* */ +/* This software is provided 'as-is', without any expressed or implied */ +/* warranty. In no event will the authors be held liable for any damages */ +/* arising from the use of this software. */ +/* */ +/* Permission is granted to anyone to use this software for any purpose, */ +/* including commercial applications, and to alter it and redistribute it */ +/* freely, subject to the following restrictions: */ +/* */ +/* 1. The origin of this software must not be misrepresented; you must not */ +/* claim that you wrote the original software. If you use this software */ +/* in a product, an acknowledgment in the product documentation would be */ +/* appreciated but is not required. */ +/* 2. Altered source versions must be plainly marked as such, and must not */ +/* be misrepresented as being the original software. */ +/* 3. This notice may not be removed or altered from any source */ +/* distribution. */ +/* */ +/*****************************************************************************/ + + + +#include <stdarg.h> +#include <string.h> + +/* common */ +#include "chartype.h" +#include "check.h" +#include "coll.h" +#include "scanner.h" +#include "intptrstack.h" +#include "xmalloc.h" + +/* cc65 */ +#include "codeent.h" +#include "error.h" +#include "wrappedcall.h" + + + +/*****************************************************************************/ +/* Data */ +/*****************************************************************************/ + + +/* WrappedCalls */ +static IntPtrStack WrappedCalls; + + + +/*****************************************************************************/ +/* Code */ +/*****************************************************************************/ + + + +void PushWrappedCall (void *Ptr, unsigned char Val) +/* Push the current WrappedCall */ +{ + if (IPS_IsFull (&WrappedCalls)) { + Error ("WrappedCall stack overflow"); + } else { + IPS_Push (&WrappedCalls, Val, Ptr); + } +} + + + +void PopWrappedCall (void) +/* Remove the current WrappedCall */ +{ + if (IPS_GetCount (&WrappedCalls) < 1) { + Error ("WrappedCall stack is empty"); + } else { + IPS_Drop (&WrappedCalls); + } +} + + + +void GetWrappedCall (void **Ptr, unsigned char *Val) +/* Get the current WrappedCall */ +{ + if (IPS_GetCount (&WrappedCalls) < 1) { + *Ptr = NULL; + *Val = 0; + } else { + long Temp; + IPS_Get (&WrappedCalls, &Temp, Ptr); + *Val = Temp; + } +} diff --git a/src/cc65/wrappedcall.h b/src/cc65/wrappedcall.h new file mode 100644 index 000000000..3517c2465 --- /dev/null +++ b/src/cc65/wrappedcall.h @@ -0,0 +1,65 @@ +/*****************************************************************************/ +/* */ +/* wrappedcall.h */ +/* */ +/* Wrapped-call management */ +/* */ +/* */ +/* */ +/* (C) 2017, Mega Cat Studios */ +/* */ +/* */ +/* This software is provided 'as-is', without any expressed or implied */ +/* warranty. In no event will the authors be held liable for any damages */ +/* arising from the use of this software. */ +/* */ +/* Permission is granted to anyone to use this software for any purpose, */ +/* including commercial applications, and to alter it and redistribute it */ +/* freely, subject to the following restrictions: */ +/* */ +/* 1. The origin of this software must not be misrepresented; you must not */ +/* claim that you wrote the original software. If you use this software */ +/* in a product, an acknowledgment in the product documentation would be */ +/* appreciated but is not required. */ +/* 2. Altered source versions must be plainly marked as such, and must not */ +/* be misrepresented as being the original software. */ +/* 3. This notice may not be removed or altered from any source */ +/* distribution. */ +/* */ +/*****************************************************************************/ + + + +#ifndef WRAPPEDCALL_H +#define WRAPPEDCALL_H + + + +#include <stdio.h> + +/* common */ +#include "attrib.h" + +/* cc65 */ +#include "opcodes.h" + + +/*****************************************************************************/ +/* Code */ +/*****************************************************************************/ + + + +void PushWrappedCall (void *Ptr, unsigned char Val); +/* Push the current WrappedCall */ + +void PopWrappedCall (void); +/* Pop the current WrappedCall */ + +void GetWrappedCall (void **Ptr, unsigned char *Val); +/* Get the current WrappedCall, if any */ + + +/* End of wrappedcall.h */ + +#endif diff --git a/src/cl65/main.c b/src/cl65/main.c index 7bdbe7a8a..565f20b45 100644 --- a/src/cl65/main.c +++ b/src/cl65/main.c @@ -158,6 +158,34 @@ static char* TargetLib = 0; +/*****************************************************************************/ +/* Credential functions */ +/*****************************************************************************/ + + + +static void DisableAssembling (void) +{ + DoAssemble = 0; +} + + + +static void DisableLinking (void) +{ + DoLink = 0; +} + + + +static void DisableAssemblingAndLinking (void) +{ + DisableAssembling (); + DisableLinking (); +} + + + /*****************************************************************************/ /* Command structure handling */ /*****************************************************************************/ @@ -706,6 +734,7 @@ static void Usage (void) " -C name\t\t\tUse linker config file\n" " -Cl\t\t\t\tMake local variables static\n" " -D sym[=defn]\t\t\tDefine a preprocessor symbol\n" + " -E\t\t\t\tStop after the preprocessing stage\n" " -I dir\t\t\tSet a compiler include directory path\n" " -L path\t\t\tSpecify a library search path\n" " -Ln name\t\t\tCreate a VICE label file\n" @@ -723,6 +752,7 @@ static void Usage (void) "\n" "Long options:\n" " --add-source\t\t\tInclude source as comment\n" + " --all-cdecl\t\t\tMake functions default to __cdecl__\n" " --asm-args options\t\tPass options to the assembler\n" " --asm-define sym[=v]\t\tDefine an assembler symbol\n" " --asm-include-dir dir\t\tSet an assembler include directory\n" @@ -786,6 +816,14 @@ static void OptAddSource (const char* Opt attribute ((unused)), } +static void OptAllCDecl (const char* Opt attribute ((unused)), + const char* Arg attribute ((unused))) +/* Make functions default to __cdecl__ */ +{ + CmdAddArg (&CC65, "--all-cdecl"); +} + + static void OptAsmArgs (const char* Opt attribute ((unused)), const char* Arg) /* Pass arguments to the assembler */ @@ -1261,6 +1299,7 @@ int main (int argc, char* argv []) /* Program long options */ static const LongOpt OptTab[] = { { "--add-source", 0, OptAddSource }, + { "--all-cdecl", 0, OptAllCDecl }, { "--asm-args", 1, OptAsmArgs }, { "--asm-define", 1, OptAsmDefine }, { "--asm-include-dir", 1, OptAsmIncludeDir }, @@ -1398,8 +1437,7 @@ int main (int argc, char* argv []) case 'S': /* Dont assemble and link the created files */ - DoAssemble = 0; - DoLink = 0; + DisableAssemblingAndLinking (); break; case 'T': @@ -1411,17 +1449,35 @@ int main (int argc, char* argv []) /* Print version number */ OptVersion (Arg, 0); break; - + + case 'E': + /* Forward -E to compiler */ + CmdAddArg (&CC65, Arg); + DisableAssemblingAndLinking (); + break; + case 'W': - if (Arg[2] == 'a' && Arg[3] == '\0') { - /* -Wa: Pass options to assembler */ - OptAsmArgs (Arg, GetArg (&I, 3)); - } else if (Arg[2] == 'c' && Arg[3] == '\0') { - /* -Wc: Pass options to compiler */ - OptCCArgs (Arg, GetArg (&I, 3)); - } else if (Arg[2] == 'l' && Arg[3] == '\0') { - /* -Wl: Pass options to linker */ - OptLdArgs (Arg, GetArg (&I, 3)); + /* avoid && with'\0' in if clauses */ + if (Arg[3] == '\0') { + switch (Arg[2]) { + case 'a': + /* -Wa: Pass options to assembler */ + OptAsmArgs (Arg, GetArg (&I, 3)); + break; + case 'c': + /* -Wc: Pass options to compiler + ** Remember -Wc sub arguments in cc65 arg struct + */ + OptCCArgs (Arg, GetArg (&I, 3)); + break; + case 'l': + /* -Wl: Pass options to linker */ + OptLdArgs (Arg, GetArg (&I, 3)); + break; + default: + UnknownOption (Arg); + break; + } } else { /* Anything else: Suppress warnings (compiler) */ CmdAddArg2 (&CC65, "-W", GetArg (&I, 2)); @@ -1430,7 +1486,7 @@ int main (int argc, char* argv []) case 'c': /* Don't link the resulting files */ - DoLink = 0; + DisableLinking (); break; case 'd': diff --git a/src/co65/model.c b/src/co65/model.c index 87a6966b7..bb815cd15 100644 --- a/src/co65/model.c +++ b/src/co65/model.c @@ -52,7 +52,7 @@ O65Model Model = O65_MODEL_NONE; /* Name table */ -static const char* NameTable[O65_MODEL_COUNT] = { +static const char* const NameTable[O65_MODEL_COUNT] = { "none", "os/a65", "lunix", diff --git a/src/common.vcxproj b/src/common.vcxproj index 053d23981..39fea35e5 100644 --- a/src/common.vcxproj +++ b/src/common.vcxproj @@ -38,6 +38,7 @@ <ClInclude Include="common\hashtab.h" /> <ClInclude Include="common\hlldbgsym.h" /> <ClInclude Include="common\inline.h" /> + <ClInclude Include="common\intptrstack.h" /> <ClInclude Include="common\intstack.h" /> <ClInclude Include="common\inttypes.h" /> <ClInclude Include="common\libdefs.h" /> @@ -87,6 +88,7 @@ <ClCompile Include="common\gentype.c" /> <ClCompile Include="common\hashfunc.c" /> <ClCompile Include="common\hashtab.c" /> + <ClCompile Include="common\intptrstack.c" /> <ClCompile Include="common\intstack.c" /> <ClCompile Include="common\matchpat.c" /> <ClCompile Include="common\mmodel.c" /> diff --git a/src/common/intptrstack.c b/src/common/intptrstack.c new file mode 100644 index 000000000..de02c09e7 --- /dev/null +++ b/src/common/intptrstack.c @@ -0,0 +1,90 @@ +/*****************************************************************************/ +/* */ +/* intptrstack.c */ +/* */ +/* Integer+ptr stack used for program settings */ +/* */ +/* */ +/* */ +/* (C) 2017, Mega Cat Studios */ +/* */ +/* */ +/* This software is provided 'as-is', without any expressed or implied */ +/* warranty. In no event will the authors be held liable for any damages */ +/* arising from the use of this software. */ +/* */ +/* Permission is granted to anyone to use this software for any purpose, */ +/* including commercial applications, and to alter it and redistribute it */ +/* freely, subject to the following restrictions: */ +/* */ +/* 1. The origin of this software must not be misrepresented; you must not */ +/* claim that you wrote the original software. If you use this software */ +/* in a product, an acknowledgment in the product documentation would be */ +/* appreciated but is not required. */ +/* 2. Altered source versions must be plainly marked as such, and must not */ +/* be misrepresented as being the original software. */ +/* 3. This notice may not be removed or altered from any source */ +/* distribution. */ +/* */ +/*****************************************************************************/ + + + +/* common */ +#include "check.h" +#include "intptrstack.h" + + + +/*****************************************************************************/ +/* Code */ +/*****************************************************************************/ + + + +void IPS_Get (const IntPtrStack* S, long *Val, void **Ptr) +/* Get the value on top of an int stack */ +{ + PRECONDITION (S->Count > 0); + if (Val) *Val = S->Stack[S->Count-1].val; + if (Ptr) *Ptr = S->Stack[S->Count-1].ptr; +} + + + +void IPS_Set (IntPtrStack* S, long Val, void *Ptr) +/* Set the value on top of an int stack */ +{ + PRECONDITION (S->Count > 0); + S->Stack[S->Count-1].val = Val; + S->Stack[S->Count-1].ptr = Ptr; +} + + + +void IPS_Drop (IntPtrStack* S) +/* Drop a value from an int stack */ +{ + PRECONDITION (S->Count > 0); + --S->Count; +} + + + +void IPS_Push (IntPtrStack* S, long Val, void *Ptr) +/* Push a value onto an int stack */ +{ + PRECONDITION (S->Count < sizeof (S->Stack) / sizeof (S->Stack[0])); + S->Stack[S->Count].val = Val; + S->Stack[S->Count++].ptr = Ptr; +} + + + +void IPS_Pop (IntPtrStack* S, long *Val, void **Ptr) +/* Pop a value from an int stack */ +{ + PRECONDITION (S->Count > 0); + if (Val) *Val = S->Stack[--S->Count].val; + if (Ptr) *Ptr = S->Stack[S->Count].ptr; +} diff --git a/src/common/intptrstack.h b/src/common/intptrstack.h new file mode 100644 index 000000000..a7b1c6683 --- /dev/null +++ b/src/common/intptrstack.h @@ -0,0 +1,121 @@ +/*****************************************************************************/ +/* */ +/* intptrstack.h */ +/* */ +/* Integer+ptr stack used for program settings */ +/* */ +/* */ +/* */ +/* (C) 2017, Mega Cat Studios */ +/* */ +/* */ +/* This software is provided 'as-is', without any expressed or implied */ +/* warranty. In no event will the authors be held liable for any damages */ +/* arising from the use of this software. */ +/* */ +/* Permission is granted to anyone to use this software for any purpose, */ +/* including commercial applications, and to alter it and redistribute it */ +/* freely, subject to the following restrictions: */ +/* */ +/* 1. The origin of this software must not be misrepresented; you must not */ +/* claim that you wrote the original software. If you use this software */ +/* in a product, an acknowledgment in the product documentation would be */ +/* appreciated but is not required. */ +/* 2. Altered source versions must be plainly marked as such, and must not */ +/* be misrepresented as being the original software. */ +/* 3. This notice may not be removed or altered from any source */ +/* distribution. */ +/* */ +/*****************************************************************************/ + + + +#ifndef INTPTRSTACK_H +#define INTPTRSTACK_H + + + +#include "inline.h" + + + +/*****************************************************************************/ +/* Data */ +/*****************************************************************************/ + + + +typedef struct IntPtrStack IntPtrStack; +struct IntPtrInner { + long val; + void *ptr; +}; +struct IntPtrStack { + unsigned Count; + struct IntPtrInner Stack[8]; +}; + +/* An initializer for an empty int stack */ +#define STATIC_INTPTRSTACK_INITIALIZER { 0, { 0, 0 }, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0} } } + +/* Declare an int stack with the given value as first element */ +#define INTPTRSTACK(Val, Ptr) { 1, { {Val, Ptr}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0} } } + + + +/*****************************************************************************/ +/* Code */ +/*****************************************************************************/ + + + +#if defined(HAVE_INLINE) +INLINE int IPS_IsFull (const IntPtrStack* S) +/* Return true if there is no space left on the given int stack */ +{ + return (S->Count >= sizeof (S->Stack) / sizeof (S->Stack[0])); +} +#else +# define IPS_IsFull(S) ((S)->Count >= sizeof ((S)->Stack) / sizeof ((S)->Stack[0])) +#endif + +#if defined(HAVE_INLINE) +INLINE int IPS_IsEmpty (const IntPtrStack* S) +/* Return true if there are no values on the given int stack */ +{ + return (S->Count == 0); +} +#else +# define IPS_IsEmpty(S) ((S)->Count == 0) +#endif + +#if defined(HAVE_INLINE) +INLINE unsigned IPS_GetCount (const IntPtrStack* S) +/* Return the number of elements on the given int stack */ +{ + return S->Count; +} +#else +# define IPS_GetCount(S) (S)->Count +#endif + +void IPS_Get (const IntPtrStack* S, long *Val, void **Ptr); +/* Get the value on top of an int stack */ + +void IPS_Set (IntPtrStack* S, long Val, void *Ptr); +/* Set the value on top of an int stack */ + +void IPS_Drop (IntPtrStack* S); +/* Drop a value from an int stack */ + +void IPS_Push (IntPtrStack* S, long Val, void *Ptr); +/* Push a value onto an int stack */ + +void IPS_Pop (IntPtrStack* S, long *Val, void **Ptr); +/* Pop a value from an int stack */ + + + +/* End of IntPtrStack.h */ + +#endif diff --git a/src/common/version.c b/src/common/version.c index 4e61a5f83..bf0a6bf71 100644 --- a/src/common/version.c +++ b/src/common/version.c @@ -47,7 +47,7 @@ #define VER_MAJOR 2U -#define VER_MINOR 15U +#define VER_MINOR 16U diff --git a/src/da65/labels.c b/src/da65/labels.c index 547a79869..6aa7f38cf 100644 --- a/src/da65/labels.c +++ b/src/da65/labels.c @@ -264,11 +264,11 @@ const char* GetLabel (unsigned Addr, unsigned RefFrom) ** of unnamed labels, to determine the name. */ { - static const char* FwdLabels[] = { + static const char* const FwdLabels[] = { ":+", ":++", ":+++", ":++++", ":+++++", ":++++++", ":+++++++", ":++++++++", ":+++++++++", ":++++++++++" }; - static const char* BackLabels[] = { + static const char* const BackLabels[] = { ":-", ":--", ":---", ":----", ":-----", ":------", ":-------", ":--------", ":---------", ":----------" }; diff --git a/src/grc65/main.c b/src/grc65/main.c index 2a1fef953..a53801a39 100644 --- a/src/grc65/main.c +++ b/src/grc65/main.c @@ -226,18 +226,18 @@ static void openSFile (void) } -static int findToken (const char **tokenTbl, const char *token) +static int findToken (const char * const *tokenTbl, const char *token) { /* takes as input table of tokens and token, returns position in table or -1 if not found */ - int a = 0; + int i; - while (strlen (tokenTbl[a]) != 0) { - if (strcmp (tokenTbl[a], token) == 0) break; - a++; + for (i = 0; tokenTbl[i][0]; i++) { + if (strcmp (tokenTbl[i], token) == 0) { + return i; + } } - if (strlen (tokenTbl[a]) == 0) a = -1; - return a; + return -1; } diff --git a/src/sim65/6502.c b/src/sim65/6502.c index e6f358295..1febef657 100644 --- a/src/sim65/6502.c +++ b/src/sim65/6502.c @@ -11,6 +11,7 @@ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ /* */ +/* Mar-2017, Christian Krueger, added support for 65SC02 */ /* */ /* This software is provided 'as-is', without any expressed or implied */ /* warranty. In no event will the authors be held liable for any damages */ @@ -31,7 +32,14 @@ /* */ /*****************************************************************************/ - +/* Known bugs and limitations of the 65C02 simulation: + * support currently only on the level of 65SC02: + BBRx, BBSx, RMBx, SMBx, WAI, and STP are unsupported + * BCD flag handling equals 6502 (unchecked if bug is simulated or wrong for + 6502) + * one cycle win for fetch-modify-write instructions ignored + (e.g., ROL abs,x takes only 6 cycles if no page break occurs) +*/ #include "memory.h" #include "error.h" @@ -77,12 +85,11 @@ int PrintCycles; -/* Return the flags as a boolean value (0/1) */ +/* Return the flags as boolean values (0/1) */ #define GET_CF() ((Regs.SR & CF) != 0) #define GET_ZF() ((Regs.SR & ZF) != 0) #define GET_IF() ((Regs.SR & IF) != 0) #define GET_DF() ((Regs.SR & DF) != 0) -#define GET_BF() ((Regs.SR & BF) != 0) #define GET_OF() ((Regs.SR & OF) != 0) #define GET_SF() ((Regs.SR & SF) != 0) @@ -93,7 +100,6 @@ int PrintCycles; #define SET_ZF(f) do { if (f) { Regs.SR |= ZF; } else { Regs.SR &= ~ZF; } } while (0) #define SET_IF(f) do { if (f) { Regs.SR |= IF; } else { Regs.SR &= ~IF; } } while (0) #define SET_DF(f) do { if (f) { Regs.SR |= DF; } else { Regs.SR &= ~DF; } } while (0) -#define SET_BF(f) do { if (f) { Regs.SR |= BF; } else { Regs.SR &= ~BF; } } while (0) #define SET_OF(f) do { if (f) { Regs.SR |= OF; } else { Regs.SR &= ~OF; } } while (0) #define SET_SF(f) do { if (f) { Regs.SR |= SF; } else { Regs.SR &= ~SF; } } while (0) @@ -109,8 +115,8 @@ int PrintCycles; #define PCH ((Regs.PC >> 8) & 0xFF) /* Stack operations */ -#define PUSH(Val) MemWriteByte (0x0100 + Regs.SP--, Val) -#define POP() MemReadByte (0x0100 + ++Regs.SP) +#define PUSH(Val) MemWriteByte (0x0100 | (Regs.SP-- & 0xFF), Val) +#define POP() MemReadByte (0x0100 | (++Regs.SP & 0xFF)) /* Test for page cross */ #define PAGE_CROSS(addr,offs) ((((addr) & 0xFF) + offs) >= 0x100) @@ -205,7 +211,23 @@ int PrintCycles; unsigned Addr; \ Cycles = 5; \ ZPAddr = MemReadByte (Regs.PC+1); \ - Addr = MemReadZPWord (ZPAddr) + Regs.YR; \ + Addr = MemReadZPWord (ZPAddr); \ + if (PAGE_CROSS (Addr, Regs.YR)) { \ + ++Cycles; \ + } \ + Addr += Regs.YR; \ + Regs.AC = Regs.AC op MemReadByte (Addr); \ + TEST_ZF (Regs.AC); \ + TEST_SF (Regs.AC); \ + Regs.PC += 2 + +/* (zp) */ +#define AC_OP_ZPIND(op) \ + unsigned char ZPAddr; \ + unsigned Addr; \ + Cycles = 5; \ + ZPAddr = MemReadByte (Regs.PC+1); \ + Addr = MemReadZPWord (ZPAddr); \ Regs.AC = Regs.AC op MemReadByte (Addr); \ TEST_ZF (Regs.AC); \ TEST_SF (Regs.AC); \ @@ -234,6 +256,9 @@ int PrintCycles; } \ TEST_CF (Regs.AC); \ SET_OF ((res < -128) || (res > 127)); \ + if (CPU != CPU_6502) { \ + ++Cycles; \ + } \ } else { \ Regs.AC += rhs + GET_CF (); \ TEST_ZF (Regs.AC); \ @@ -313,6 +338,9 @@ int PrintCycles; TEST_SF (res); \ SET_CF (res <= 0xFF); \ SET_OF (((old^rhs) & (old^res) & 0x80)); \ + if (CPU != CPU_6502) { \ + ++Cycles; \ + } \ } else { \ Regs.AC -= rhs + (!GET_CF ()); \ TEST_ZF (Regs.AC); \ @@ -344,11 +372,14 @@ static void OPC_6502_00 (void) { Cycles = 7; Regs.PC += 2; - SET_BF (1); PUSH (PCH); PUSH (PCL); PUSH (Regs.SR); SET_IF (1); + if (CPU != CPU_6502) + { + SET_DF (0); + } Regs.PC = MemReadWord (0xFFFE); } @@ -362,6 +393,21 @@ static void OPC_6502_01 (void) +static void OPC_65SC02_04 (void) +/* Opcode $04: TSB zp */ +{ + unsigned char ZPAddr; + unsigned char Val; + Cycles = 5; + ZPAddr = MemReadByte (Regs.PC+1); + Val = MemReadByte (ZPAddr); + SET_ZF ((Val & Regs.AC) == 0); + MemWriteByte (ZPAddr, (unsigned char)(Val | Regs.AC)); + Regs.PC += 2; +} + + + static void OPC_6502_05 (void) /* Opcode $05: ORA zp */ { @@ -377,7 +423,7 @@ static void OPC_6502_06 (void) unsigned Val; Cycles = 5; ZPAddr = MemReadByte (Regs.PC+1); - Val = MemReadByte (ZPAddr) << 1; + Val = MemReadByte (ZPAddr) << 1; MemWriteByte (ZPAddr, (unsigned char) Val); TEST_ZF (Val & 0xFF); TEST_SF (Val); @@ -391,7 +437,7 @@ static void OPC_6502_08 (void) /* Opcode $08: PHP */ { Cycles = 3; - PUSH (Regs.SR & ~BF); + PUSH (Regs.SR); Regs.PC += 1; } @@ -419,6 +465,21 @@ static void OPC_6502_0A (void) +static void OPC_65SC02_0C (void) +/* Opcode $0C: TSB abs */ +{ + unsigned Addr; + unsigned char Val; + Cycles = 6; + Addr = MemReadWord (Regs.PC+1); + Val = MemReadByte (Addr); + SET_ZF ((Val & Regs.AC) == 0); + MemWriteByte (Addr, (unsigned char) (Val | Regs.AC)); + Regs.PC += 3; +} + + + static void OPC_6502_0D (void) /* Opcode $0D: ORA abs */ { @@ -434,7 +495,7 @@ static void OPC_6502_0E (void) unsigned Val; Cycles = 6; Addr = MemReadWord (Regs.PC+1); - Val = MemReadByte (Addr) << 1; + Val = MemReadByte (Addr) << 1; MemWriteByte (Addr, (unsigned char) Val); TEST_ZF (Val & 0xFF); TEST_SF (Val); @@ -460,6 +521,29 @@ static void OPC_6502_11 (void) +static void OPC_65SC02_12 (void) +/* Opcode $12: ORA (zp) */ +{ + AC_OP_ZPIND (|); +} + + + +static void OPC_65SC02_14 (void) +/* Opcode $14: TRB zp */ +{ + unsigned char ZPAddr; + unsigned char Val; + Cycles = 5; + ZPAddr = MemReadByte (Regs.PC+1); + Val = MemReadByte (ZPAddr); + SET_ZF ((Val & Regs.AC) == 0); + MemWriteByte (ZPAddr, (unsigned char)(Val & ~Regs.AC)); + Regs.PC += 2; +} + + + static void OPC_6502_15 (void) /* Opcode $15: ORA zp,x */ { @@ -475,7 +559,7 @@ static void OPC_6502_16 (void) unsigned Val; Cycles = 6; ZPAddr = MemReadByte (Regs.PC+1) + Regs.XR; - Val = MemReadByte (ZPAddr) << 1; + Val = MemReadByte (ZPAddr) << 1; MemWriteByte (ZPAddr, (unsigned char) Val); TEST_ZF (Val & 0xFF); TEST_SF (Val); @@ -503,6 +587,33 @@ static void OPC_6502_19 (void) +static void OPC_65SC02_1A (void) +/* Opcode $1A: INC a */ +{ + Cycles = 2; + Regs.AC = (Regs.AC + 1) & 0xFF; + TEST_ZF (Regs.AC); + TEST_SF (Regs.AC); + Regs.PC += 1; +} + + + +static void OPC_65SC02_1C (void) +/* Opcode $1C: TRB abs */ +{ + unsigned Addr; + unsigned char Val; + Cycles = 6; + Addr = MemReadWord (Regs.PC+1); + Val = MemReadByte (Addr); + SET_ZF ((Val & Regs.AC) == 0); + MemWriteByte (Addr, (unsigned char) (Val & ~Regs.AC)); + Regs.PC += 3; +} + + + static void OPC_6502_1D (void) /* Opcode $1D: ORA abs,x */ { @@ -518,7 +629,7 @@ static void OPC_6502_1E (void) unsigned Val; Cycles = 7; Addr = MemReadWord (Regs.PC+1) + Regs.XR; - Val = MemReadByte (Addr) << 1; + Val = MemReadByte (Addr) << 1; MemWriteByte (Addr, (unsigned char) Val); TEST_ZF (Val & 0xFF); TEST_SF (Val); @@ -533,7 +644,7 @@ static void OPC_6502_20 (void) { unsigned Addr; Cycles = 6; - Addr = MemReadWord (Regs.PC+1); + Addr = MemReadWord (Regs.PC+1); Regs.PC += 2; PUSH (PCH); PUSH (PCL); @@ -559,7 +670,7 @@ static void OPC_6502_24 (void) unsigned char Val; Cycles = 3; ZPAddr = MemReadByte (Regs.PC+1); - Val = MemReadByte (ZPAddr); + Val = MemReadByte (ZPAddr); SET_SF (Val & 0x80); SET_OF (Val & 0x40); SET_ZF ((Val & Regs.AC) == 0); @@ -583,7 +694,7 @@ static void OPC_6502_26 (void) unsigned Val; Cycles = 5; ZPAddr = MemReadByte (Regs.PC+1); - Val = MemReadByte (ZPAddr); + Val = MemReadByte (ZPAddr); ROL (Val); MemWriteByte (ZPAddr, Val); Regs.PC += 2; @@ -595,7 +706,9 @@ static void OPC_6502_28 (void) /* Opcode $28: PLP */ { Cycles = 4; - Regs.SR = (POP () & ~BF); + + /* Bits 5 and 4 aren't used, and always are 1! */ + Regs.SR = (POP () | 0x30); Regs.PC += 1; } @@ -627,7 +740,7 @@ static void OPC_6502_2C (void) unsigned char Val; Cycles = 4; Addr = MemReadByte (Regs.PC+1); - Val = MemReadByte (Addr); + Val = MemReadByte (Addr); SET_SF (Val & 0x80); SET_OF (Val & 0x40); SET_ZF ((Val & Regs.AC) == 0); @@ -651,7 +764,7 @@ static void OPC_6502_2E (void) unsigned Val; Cycles = 6; Addr = MemReadWord (Regs.PC+1); - Val = MemReadByte (Addr); + Val = MemReadByte (Addr); ROL (Val); MemWriteByte (Addr, Val); Regs.PC += 3; @@ -675,6 +788,30 @@ static void OPC_6502_31 (void) +static void OPC_65SC02_32 (void) +/* Opcode $32: AND (zp) */ +{ + AC_OP_ZPIND (&); +} + + + +static void OPC_65SC02_34 (void) +/* Opcode $34: BIT zp,x */ +{ + unsigned char ZPAddr; + unsigned char Val; + Cycles = 4; + ZPAddr = MemReadByte (Regs.PC+1) + Regs.XR; + Val = MemReadByte (ZPAddr); + SET_SF (Val & 0x80); + SET_OF (Val & 0x40); + SET_ZF ((Val & Regs.AC) == 0); + Regs.PC += 2; +} + + + static void OPC_6502_35 (void) /* Opcode $35: AND zp,x */ { @@ -690,7 +827,7 @@ static void OPC_6502_36 (void) unsigned Val; Cycles = 6; ZPAddr = MemReadByte (Regs.PC+1) + Regs.XR; - Val = MemReadByte (ZPAddr); + Val = MemReadByte (ZPAddr); ROL (Val); MemWriteByte (ZPAddr, Val); Regs.PC += 2; @@ -716,6 +853,36 @@ static void OPC_6502_39 (void) +static void OPC_65SC02_3A (void) +/* Opcode $3A: DEC a */ +{ + Cycles = 2; + Regs.AC = (Regs.AC - 1) & 0xFF; + TEST_ZF (Regs.AC); + TEST_SF (Regs.AC); + Regs.PC += 1; +} + + + +static void OPC_65SC02_3C (void) +/* Opcode $3C: BIT abs,x */ +{ + unsigned Addr; + unsigned char Val; + Cycles = 4; + Addr = MemReadWord (Regs.PC+1); + if (PAGE_CROSS (Addr, Regs.XR)) + ++Cycles; + Val = MemReadByte (Addr + Regs.XR); + SET_SF (Val & 0x80); + SET_OF (Val & 0x40); + SET_ZF ((Val & Regs.AC) == 0); + Regs.PC += 3; +} + + + static void OPC_6502_3D (void) /* Opcode $3D: AND abs,x */ { @@ -731,7 +898,7 @@ static void OPC_6502_3E (void) unsigned Val; Cycles = 7; Addr = MemReadWord (Regs.PC+1) + Regs.XR; - Val = MemReadByte (Addr); + Val = MemReadByte (Addr); ROL (Val); MemWriteByte (Addr, Val); Regs.PC += 2; @@ -743,7 +910,9 @@ static void OPC_6502_40 (void) /* Opcode $40: RTI */ { Cycles = 6; - Regs.SR = POP (); + + /* Bits 5 and 4 aren't used, and always are 1! */ + Regs.SR = POP () | 0x30; Regs.PC = POP (); /* PCL */ Regs.PC |= (POP () << 8); /* PCH */ } @@ -758,6 +927,15 @@ static void OPC_6502_41 (void) +static void OPC_65C02_44 (void) +/* Opcode $44: 'zp' 3 cycle NOP */ +{ + Cycles = 3; + Regs.PC += 2; +} + + + static void OPC_6502_45 (void) /* Opcode $45: EOR zp */ { @@ -773,7 +951,7 @@ static void OPC_6502_46 (void) unsigned char Val; Cycles = 5; ZPAddr = MemReadByte (Regs.PC+1); - Val = MemReadByte (ZPAddr); + Val = MemReadByte (ZPAddr); SET_CF (Val & 0x01); Val >>= 1; MemWriteByte (ZPAddr, Val); @@ -841,7 +1019,7 @@ static void OPC_6502_4E (void) unsigned char Val; Cycles = 6; Addr = MemReadWord (Regs.PC+1); - Val = MemReadByte (Addr); + Val = MemReadByte (Addr); SET_CF (Val & 0x01); Val >>= 1; MemWriteByte (Addr, Val); @@ -868,6 +1046,14 @@ static void OPC_6502_51 (void) +static void OPC_65SC02_52 (void) +/* Opcode $52: EOR (zp) */ +{ + AC_OP_ZPIND (^); +} + + + static void OPC_6502_55 (void) /* Opcode $55: EOR zp,x */ { @@ -883,7 +1069,7 @@ static void OPC_6502_56 (void) unsigned char Val; Cycles = 6; ZPAddr = MemReadByte (Regs.PC+1) + Regs.XR; - Val = MemReadByte (ZPAddr); + Val = MemReadByte (ZPAddr); SET_CF (Val & 0x01); Val >>= 1; MemWriteByte (ZPAddr, Val); @@ -912,6 +1098,25 @@ static void OPC_6502_59 (void) +static void OPC_65SC02_5A (void) +/* Opcode $5A: PHY */ +{ + Cycles = 3; + PUSH (Regs.YR); + Regs.PC += 1; +} + + + +static void OPC_65C02_5C (void) +/* Opcode $5C: 'Absolute' 8 cycle NOP */ +{ + Cycles = 8; + Regs.PC += 3; +} + + + static void OPC_6502_5D (void) /* Opcode $5D: EOR abs,x */ { @@ -927,7 +1132,7 @@ static void OPC_6502_5E (void) unsigned char Val; Cycles = 7; Addr = MemReadWord (Regs.PC+1) + Regs.XR; - Val = MemReadByte (Addr); + Val = MemReadByte (Addr); SET_CF (Val & 0x01); Val >>= 1; MemWriteByte (Addr, Val); @@ -956,13 +1161,25 @@ static void OPC_6502_61 (void) unsigned Addr; Cycles = 6; ZPAddr = MemReadByte (Regs.PC+1) + Regs.XR; - Addr = MemReadZPWord (ZPAddr); + Addr = MemReadZPWord (ZPAddr); ADC (MemReadByte (Addr)); Regs.PC += 2; } +static void OPC_65SC02_64 (void) +/* Opcode $64: STZ zp */ +{ + unsigned char ZPAddr; + Cycles = 3; + ZPAddr = MemReadByte (Regs.PC+1); + MemWriteByte (ZPAddr, 0); + Regs.PC += 2; +} + + + static void OPC_6502_65 (void) /* Opcode $65: ADC zp */ { @@ -982,7 +1199,7 @@ static void OPC_6502_66 (void) unsigned Val; Cycles = 5; ZPAddr = MemReadByte (Regs.PC+1); - Val = MemReadByte (ZPAddr); + Val = MemReadByte (ZPAddr); ROR (Val); MemWriteByte (ZPAddr, Val); Regs.PC += 2; @@ -1026,19 +1243,28 @@ static void OPC_6502_6C (void) /* Opcode $6C: JMP (ind) */ { unsigned PC, Lo, Hi; - Cycles = 5; PC = Regs.PC; Lo = MemReadWord (PC+1); - /* Emulate the 6502 bug */ - Regs.PC = MemReadByte (Lo); - Hi = (Lo & 0xFF00) | ((Lo + 1) & 0xFF); - Regs.PC |= (MemReadByte (Hi) << 8); + if (CPU == CPU_6502) + { + /* Emulate the 6502 bug */ + Cycles = 5; + Regs.PC = MemReadByte (Lo); + Hi = (Lo & 0xFF00) | ((Lo + 1) & 0xFF); + Regs.PC |= (MemReadByte (Hi) << 8); - /* Output a warning if the bug is triggered */ - if (Hi != Lo + 1) { - Warning ("6502 indirect jump bug triggered at $%04X, ind addr = $%04X", - PC, Lo); + /* Output a warning if the bug is triggered */ + if (Hi != Lo + 1) + { + Warning ("6502 indirect jump bug triggered at $%04X, ind addr = $%04X", + PC, Lo); + } + } + else + { + Cycles = 6; + Regs.PC = MemReadWord(Lo); } } @@ -1106,6 +1332,32 @@ static void OPC_6502_71 (void) +static void OPC_65SC02_72 (void) +/* Opcode $72: ADC (zp) */ +{ + unsigned char ZPAddr; + unsigned Addr; + Cycles = 5; + ZPAddr = MemReadByte (Regs.PC+1); + Addr = MemReadZPWord (ZPAddr); + ADC (MemReadByte (Addr)); + Regs.PC += 2; +} + + + +static void OPC_65SC02_74 (void) +/* Opcode $74: STZ zp,x */ +{ + unsigned char ZPAddr; + Cycles = 4; + ZPAddr = MemReadByte (Regs.PC+1) + Regs.XR; + MemWriteByte (ZPAddr, 0); + Regs.PC += 2; +} + + + static void OPC_6502_75 (void) /* Opcode $75: ADC zp,x */ { @@ -1125,7 +1377,7 @@ static void OPC_6502_76 (void) unsigned Val; Cycles = 6; ZPAddr = MemReadByte (Regs.PC+1) + Regs.XR; - Val = MemReadByte (ZPAddr); + Val = MemReadByte (ZPAddr); ROR (Val); MemWriteByte (ZPAddr, Val); Regs.PC += 2; @@ -1148,7 +1400,7 @@ static void OPC_6502_79 (void) { unsigned Addr; Cycles = 4; - Addr = MemReadWord (Regs.PC+1); + Addr = MemReadWord (Regs.PC+1); if (PAGE_CROSS (Addr, Regs.YR)) { ++Cycles; } @@ -1158,12 +1410,36 @@ static void OPC_6502_79 (void) +static void OPC_65SC02_7A (void) +/* Opcode $7A: PLY */ +{ + Cycles = 4; + Regs.YR = POP (); + TEST_ZF (Regs.YR); + TEST_SF (Regs.YR); + Regs.PC += 1; +} + + + +static void OPC_65SC02_7C (void) +/* Opcode $7C: JMP (ind,X) */ +{ + unsigned PC, Adr; + Cycles = 6; + PC = Regs.PC; + Adr = MemReadWord (PC+1); + Regs.PC = MemReadWord(Adr+Regs.XR); +} + + + static void OPC_6502_7D (void) /* Opcode $7D: ADC abs,x */ { unsigned Addr; Cycles = 4; - Addr = MemReadWord (Regs.PC+1); + Addr = MemReadWord (Regs.PC+1); if (PAGE_CROSS (Addr, Regs.XR)) { ++Cycles; } @@ -1179,8 +1455,8 @@ static void OPC_6502_7E (void) unsigned Addr; unsigned Val; Cycles = 7; - Addr = MemReadByte (Regs.PC+1) + Regs.XR; - Val = MemReadByte (Addr); + Addr = MemReadWord (Regs.PC+1) + Regs.XR; + Val = MemReadByte (Addr); ROR (Val); MemWriteByte (Addr, Val); Regs.PC += 3; @@ -1188,6 +1464,14 @@ static void OPC_6502_7E (void) +static void OPC_65SC02_80 (void) +/* Opcode $80: BRA */ +{ + BRANCH (1); +} + + + static void OPC_6502_81 (void) /* Opcode $81: STA (zp,x) */ { @@ -1195,7 +1479,7 @@ static void OPC_6502_81 (void) unsigned Addr; Cycles = 6; ZPAddr = MemReadByte (Regs.PC+1) + Regs.XR; - Addr = MemReadZPWord (ZPAddr); + Addr = MemReadZPWord (ZPAddr); MemWriteByte (Addr, Regs.AC); Regs.PC += 2; } @@ -1250,6 +1534,20 @@ static void OPC_6502_88 (void) +static void OPC_65SC02_89 (void) +/* Opcode $89: BIT #imm */ +{ + unsigned char Val; + Cycles = 2; + Val = MemReadByte (Regs.PC+1); + SET_SF (Val & 0x80); + SET_OF (Val & 0x40); + SET_ZF ((Val & Regs.AC) == 0); + Regs.PC += 2; +} + + + static void OPC_6502_8A (void) /* Opcode $8A: TXA */ { @@ -1313,7 +1611,21 @@ static void OPC_6502_91 (void) unsigned Addr; Cycles = 6; ZPAddr = MemReadByte (Regs.PC+1); - Addr = MemReadZPWord (ZPAddr) + Regs.YR; + Addr = MemReadZPWord (ZPAddr) + Regs.YR; + MemWriteByte (Addr, Regs.AC); + Regs.PC += 2; +} + + + +static void OPC_65SC02_92 (void) +/* Opcode $92: sta (zp) */ +{ + unsigned char ZPAddr; + unsigned Addr; + Cycles = 5; + ZPAddr = MemReadByte (Regs.PC+1); + Addr = MemReadZPWord (ZPAddr); MemWriteByte (Addr, Regs.AC); Regs.PC += 2; } @@ -1373,7 +1685,7 @@ static void OPC_6502_99 (void) { unsigned Addr; Cycles = 5; - Addr = MemReadWord (Regs.PC+1) + Regs.YR; + Addr = MemReadWord (Regs.PC+1) + Regs.YR; MemWriteByte (Addr, Regs.AC); Regs.PC += 3; } @@ -1390,18 +1702,42 @@ static void OPC_6502_9A (void) +static void OPC_65SC02_9C (void) +/* Opcode $9C: STZ abs */ +{ + unsigned Addr; + Cycles = 4; + Addr = MemReadWord (Regs.PC+1); + MemWriteByte (Addr, 0); + Regs.PC += 3; +} + + + static void OPC_6502_9D (void) /* Opcode $9D: STA abs,x */ { unsigned Addr; Cycles = 5; - Addr = MemReadWord (Regs.PC+1) + Regs.XR; + Addr = MemReadWord (Regs.PC+1) + Regs.XR; MemWriteByte (Addr, Regs.AC); Regs.PC += 3; } +static void OPC_65SC02_9E (void) +/* Opcode $9E: STZ abs,x */ +{ + unsigned Addr; + Cycles = 5; + Addr = MemReadWord (Regs.PC+1) + Regs.XR; + MemWriteByte (Addr, 0); + Regs.PC += 3; +} + + + static void OPC_6502_A0 (void) /* Opcode $A0: LDY #imm */ { @@ -1525,7 +1861,7 @@ static void OPC_6502_AC (void) { unsigned Addr; Cycles = 4; - Addr = MemReadWord (Regs.PC+1); + Addr = MemReadWord (Regs.PC+1); Regs.YR = MemReadByte (Addr); TEST_ZF (Regs.YR); TEST_SF (Regs.YR); @@ -1539,7 +1875,7 @@ static void OPC_6502_AD (void) { unsigned Addr; Cycles = 4; - Addr = MemReadWord (Regs.PC+1); + Addr = MemReadWord (Regs.PC+1); Regs.AC = MemReadByte (Addr); TEST_ZF (Regs.AC); TEST_SF (Regs.AC); @@ -1553,7 +1889,7 @@ static void OPC_6502_AE (void) { unsigned Addr; Cycles = 4; - Addr = MemReadWord (Regs.PC+1); + Addr = MemReadWord (Regs.PC+1); Regs.XR = MemReadByte (Addr); TEST_ZF (Regs.XR); TEST_SF (Regs.XR); @@ -1577,7 +1913,7 @@ static void OPC_6502_B1 (void) unsigned Addr; Cycles = 5; ZPAddr = MemReadByte (Regs.PC+1); - Addr = MemReadZPWord (ZPAddr); + Addr = MemReadZPWord (ZPAddr); if (PAGE_CROSS (Addr, Regs.YR)) { ++Cycles; } @@ -1589,6 +1925,22 @@ static void OPC_6502_B1 (void) +static void OPC_65SC02_B2 (void) +/* Opcode $B2: LDA (zp) */ +{ + unsigned char ZPAddr; + unsigned Addr; + Cycles = 5; + ZPAddr = MemReadByte (Regs.PC+1); + Addr = MemReadZPWord (ZPAddr); + Regs.AC = MemReadByte (Addr); + TEST_ZF (Regs.AC); + TEST_SF (Regs.AC); + Regs.PC += 2; +} + + + static void OPC_6502_B4 (void) /* Opcode $B4: LDY zp,x */ { @@ -1662,7 +2014,7 @@ static void OPC_6502_BA (void) /* Opcode $BA: TSX */ { Cycles = 2; - Regs.XR = Regs.SP; + Regs.XR = Regs.SP & 0xFF; TEST_ZF (Regs.XR); TEST_SF (Regs.XR); Regs.PC += 1; @@ -1738,7 +2090,7 @@ static void OPC_6502_C1 (void) unsigned Addr; Cycles = 6; ZPAddr = MemReadByte (Regs.PC+1) + Regs.XR; - Addr = MemReadZPWord (ZPAddr); + Addr = MemReadZPWord (ZPAddr); CMP (Regs.AC, MemReadByte (Addr)); Regs.PC += 2; } @@ -1776,7 +2128,7 @@ static void OPC_6502_C6 (void) unsigned char Val; Cycles = 5; ZPAddr = MemReadByte (Regs.PC+1); - Val = MemReadByte (ZPAddr) - 1; + Val = MemReadByte (ZPAddr) - 1; MemWriteByte (ZPAddr, Val); TEST_ZF (Val); TEST_SF (Val); @@ -1824,7 +2176,7 @@ static void OPC_6502_CC (void) { unsigned Addr; Cycles = 4; - Addr = MemReadWord (Regs.PC+1); + Addr = MemReadWord (Regs.PC+1); CMP (Regs.YR, MemReadByte (Addr)); Regs.PC += 3; } @@ -1836,7 +2188,7 @@ static void OPC_6502_CD (void) { unsigned Addr; Cycles = 4; - Addr = MemReadWord (Regs.PC+1); + Addr = MemReadWord (Regs.PC+1); CMP (Regs.AC, MemReadByte (Addr)); Regs.PC += 3; } @@ -1874,7 +2226,7 @@ static void OPC_6502_D1 (void) unsigned Addr; Cycles = 5; ZPAddr = MemReadByte (Regs.PC+1); - Addr = MemReadWord (ZPAddr); + Addr = MemReadWord (ZPAddr); if (PAGE_CROSS (Addr, Regs.YR)) { ++Cycles; } @@ -1884,6 +2236,20 @@ static void OPC_6502_D1 (void) +static void OPC_65SC02_D2 (void) +/* Opcode $D2: CMP (zp) */ +{ + unsigned ZPAddr; + unsigned Addr; + Cycles = 5; + ZPAddr = MemReadByte (Regs.PC+1); + Addr = MemReadWord (ZPAddr); + CMP (Regs.AC, MemReadByte (Addr)); + Regs.PC += 2; +} + + + static void OPC_6502_D5 (void) /* Opcode $D5: CMP zp,x */ { @@ -1937,6 +2303,16 @@ static void OPC_6502_D9 (void) +static void OPC_65SC02_DA (void) +/* Opcode $DA: PHX */ +{ + Cycles = 3; + PUSH (Regs.XR); + Regs.PC += 1; +} + + + static void OPC_6502_DD (void) /* Opcode $DD: CMP abs,x */ { @@ -1959,7 +2335,7 @@ static void OPC_6502_DE (void) unsigned char Val; Cycles = 7; Addr = MemReadWord (Regs.PC+1) + Regs.XR; - Val = MemReadByte (Addr) - 1; + Val = MemReadByte (Addr) - 1; MemWriteByte (Addr, Val); TEST_ZF (Val); TEST_SF (Val); @@ -1985,7 +2361,7 @@ static void OPC_6502_E1 (void) unsigned Addr; Cycles = 6; ZPAddr = MemReadByte (Regs.PC+1) + Regs.XR; - Addr = MemReadZPWord (ZPAddr); + Addr = MemReadZPWord (ZPAddr); SBC (MemReadByte (Addr)); Regs.PC += 2; } @@ -2023,7 +2399,7 @@ static void OPC_6502_E6 (void) unsigned char Val; Cycles = 5; ZPAddr = MemReadByte (Regs.PC+1); - Val = MemReadByte (ZPAddr) + 1; + Val = MemReadByte (ZPAddr) + 1; MemWriteByte (ZPAddr, Val); TEST_ZF (Val); TEST_SF (Val); @@ -2064,6 +2440,42 @@ static void OPC_6502_EA (void) +static void OPC_65C02_NOP11(void) +/* Opcode 'Illegal' 1 cycle NOP */ +{ + Cycles = 1; + Regs.PC += 1; +} + + + +static void OPC_65C02_NOP22 (void) +/* Opcode 'Illegal' 2 byte 2 cycle NOP */ +{ + Cycles = 2; + Regs.PC += 2; +} + + + +static void OPC_65C02_NOP24 (void) +/* Opcode 'Illegal' 2 byte 4 cycle NOP */ +{ + Cycles = 4; + Regs.PC += 2; +} + + + +static void OPC_65C02_NOP34 (void) +/* Opcode 'Illegal' 3 byte 4 cycle NOP */ +{ + Cycles = 4; + Regs.PC += 3; +} + + + static void OPC_6502_EC (void) /* Opcode $EC: CPX abs */ { @@ -2081,7 +2493,7 @@ static void OPC_6502_ED (void) { unsigned Addr; Cycles = 4; - Addr = MemReadWord (Regs.PC+1); + Addr = MemReadWord (Regs.PC+1); SBC (MemReadByte (Addr)); Regs.PC += 3; } @@ -2095,7 +2507,7 @@ static void OPC_6502_EE (void) unsigned char Val; Cycles = 6; Addr = MemReadWord (Regs.PC+1); - Val = MemReadByte (Addr) + 1; + Val = MemReadByte (Addr) + 1; MemWriteByte (Addr, Val); TEST_ZF (Val); TEST_SF (Val); @@ -2119,7 +2531,7 @@ static void OPC_6502_F1 (void) unsigned Addr; Cycles = 5; ZPAddr = MemReadByte (Regs.PC+1); - Addr = MemReadZPWord (ZPAddr); + Addr = MemReadZPWord (ZPAddr); if (PAGE_CROSS (Addr, Regs.YR)) { ++Cycles; } @@ -2129,6 +2541,20 @@ static void OPC_6502_F1 (void) +static void OPC_65SC02_F2 (void) +/* Opcode $F2: SBC (zp) */ +{ + unsigned char ZPAddr; + unsigned Addr; + Cycles = 5; + ZPAddr = MemReadByte (Regs.PC+1); + Addr = MemReadZPWord (ZPAddr); + SBC (MemReadByte (Addr)); + Regs.PC += 2; +} + + + static void OPC_6502_F5 (void) /* Opcode $F5: SBC zp,x */ { @@ -2148,7 +2574,7 @@ static void OPC_6502_F6 (void) unsigned char Val; Cycles = 6; ZPAddr = MemReadByte (Regs.PC+1) + Regs.XR; - Val = MemReadByte (ZPAddr) + 1; + Val = MemReadByte (ZPAddr) + 1; MemWriteByte (ZPAddr, Val); TEST_ZF (Val); TEST_SF (Val); @@ -2160,7 +2586,9 @@ static void OPC_6502_F6 (void) static void OPC_6502_F8 (void) /* Opcode $F8: SED */ { + Cycles = 2; SET_DF (1); + Regs.PC += 1; } @@ -2170,7 +2598,7 @@ static void OPC_6502_F9 (void) { unsigned Addr; Cycles = 4; - Addr = MemReadWord (Regs.PC+1); + Addr = MemReadWord (Regs.PC+1); if (PAGE_CROSS (Addr, Regs.YR)) { ++Cycles; } @@ -2180,12 +2608,24 @@ static void OPC_6502_F9 (void) +static void OPC_65SC02_FA (void) +/* Opcode $7A: PLX */ +{ + Cycles = 4; + Regs.XR = POP (); + TEST_ZF (Regs.XR); + TEST_SF (Regs.XR); + Regs.PC += 1; +} + + + static void OPC_6502_FD (void) /* Opcode $FD: SBC abs,x */ { unsigned Addr; Cycles = 4; - Addr = MemReadWord (Regs.PC+1); + Addr = MemReadWord (Regs.PC+1); if (PAGE_CROSS (Addr, Regs.XR)) { ++Cycles; } @@ -2202,7 +2642,7 @@ static void OPC_6502_FE (void) unsigned char Val; Cycles = 7; Addr = MemReadWord (Regs.PC+1) + Regs.XR; - Val = MemReadByte (Addr) + 1; + Val = MemReadByte (Addr) + 1; MemWriteByte (Addr, Val); TEST_ZF (Val); TEST_SF (Val); @@ -2483,260 +2923,260 @@ static const OPFunc OP6502Table[256] = { static const OPFunc OP65C02Table[256] = { OPC_6502_00, OPC_6502_01, - OPC_Illegal, - OPC_Illegal, - OPC_Illegal, + OPC_65C02_NOP22, // $02 + OPC_65C02_NOP11, // $03 + OPC_65SC02_04, OPC_6502_05, OPC_6502_06, - OPC_Illegal, + OPC_Illegal, // $07: RMB0 currently unsupported OPC_6502_08, OPC_6502_09, OPC_6502_0A, - OPC_Illegal, - OPC_Illegal, + OPC_65C02_NOP11, // $0B + OPC_65SC02_0C, OPC_6502_0D, OPC_6502_0E, - OPC_Illegal, + OPC_Illegal, // $0F: BBR0 currently unsupported OPC_6502_10, OPC_6502_11, - OPC_Illegal, - OPC_Illegal, - OPC_Illegal, + OPC_65SC02_12, + OPC_65C02_NOP11, // $13 + OPC_65SC02_14, OPC_6502_15, OPC_6502_16, - OPC_Illegal, + OPC_Illegal, // $17: RMB1 currently unsupported OPC_6502_18, OPC_6502_19, - OPC_Illegal, - OPC_Illegal, - OPC_Illegal, + OPC_65SC02_1A, + OPC_65C02_NOP11, // $1B + OPC_65SC02_1C, OPC_6502_1D, OPC_6502_1E, - OPC_Illegal, + OPC_Illegal, // $1F: BBR1 currently unsupported OPC_6502_20, OPC_6502_21, - OPC_Illegal, - OPC_Illegal, + OPC_65C02_NOP22, // $22 + OPC_65C02_NOP11, // $23 OPC_6502_24, OPC_6502_25, OPC_6502_26, - OPC_Illegal, + OPC_Illegal, // $27: RMB2 currently unsupported OPC_6502_28, OPC_6502_29, OPC_6502_2A, - OPC_Illegal, + OPC_65C02_NOP11, // $2B OPC_6502_2C, OPC_6502_2D, OPC_6502_2E, - OPC_Illegal, + OPC_Illegal, // $2F: BBR2 currently unsupported OPC_6502_30, OPC_6502_31, - OPC_Illegal, - OPC_Illegal, - OPC_Illegal, + OPC_65SC02_32, + OPC_65C02_NOP11, // $33 + OPC_65SC02_34, OPC_6502_35, OPC_6502_36, - OPC_Illegal, + OPC_Illegal, // $37: RMB3 currently unsupported OPC_6502_38, OPC_6502_39, - OPC_Illegal, - OPC_Illegal, - OPC_Illegal, + OPC_65SC02_3A, + OPC_65C02_NOP11, // $3B + OPC_65SC02_3C, OPC_6502_3D, OPC_6502_3E, - OPC_Illegal, + OPC_Illegal, // $3F: BBR3 currently unsupported OPC_6502_40, OPC_6502_41, - OPC_Illegal, - OPC_Illegal, - OPC_Illegal, + OPC_65C02_NOP22, // $42 + OPC_65C02_NOP11, // $43 + OPC_65C02_44, // $44 OPC_6502_45, OPC_6502_46, - OPC_Illegal, + OPC_Illegal, // $47: RMB4 currently unsupported OPC_6502_48, OPC_6502_49, OPC_6502_4A, - OPC_Illegal, + OPC_65C02_NOP11, // $4B OPC_6502_4C, OPC_6502_4D, OPC_6502_4E, - OPC_Illegal, + OPC_Illegal, // $4F: BBR4 currently unsupported OPC_6502_50, OPC_6502_51, - OPC_Illegal, - OPC_Illegal, - OPC_Illegal, + OPC_65SC02_52, + OPC_65C02_NOP11, // $53 + OPC_65C02_NOP24, // $54 OPC_6502_55, OPC_6502_56, - OPC_Illegal, + OPC_Illegal, // $57: RMB5 currently unsupported OPC_6502_58, OPC_6502_59, - OPC_Illegal, - OPC_Illegal, - OPC_Illegal, + OPC_65SC02_5A, + OPC_65C02_NOP11, // $5B + OPC_65C02_5C, OPC_6502_5D, OPC_6502_5E, - OPC_Illegal, + OPC_Illegal, // $5F: BBR5 currently unsupported OPC_6502_60, OPC_6502_61, - OPC_Illegal, - OPC_Illegal, - OPC_Illegal, + OPC_65C02_NOP22, // $62 + OPC_65C02_NOP11, // $63 + OPC_65SC02_64, OPC_6502_65, OPC_6502_66, - OPC_Illegal, + OPC_Illegal, // $67: RMB6 currently unsupported OPC_6502_68, OPC_6502_69, OPC_6502_6A, - OPC_Illegal, + OPC_65C02_NOP11, // $6B OPC_65C02_6C, OPC_6502_6D, OPC_6502_6E, - OPC_Illegal, + OPC_Illegal, // $6F: BBR6 currently unsupported OPC_6502_70, OPC_6502_71, - OPC_Illegal, - OPC_Illegal, - OPC_Illegal, + OPC_65SC02_72, + OPC_65C02_NOP11, // $73 + OPC_65SC02_74, OPC_6502_75, OPC_6502_76, - OPC_Illegal, + OPC_Illegal, // $77: RMB7 currently unsupported OPC_6502_78, OPC_6502_79, - OPC_Illegal, - OPC_Illegal, - OPC_Illegal, + OPC_65SC02_7A, + OPC_65C02_NOP11, // $7B + OPC_65SC02_7C, OPC_6502_7D, OPC_6502_7E, - OPC_Illegal, - OPC_Illegal, + OPC_Illegal, // $7F: BBR7 currently unsupported + OPC_65SC02_80, OPC_6502_81, - OPC_Illegal, - OPC_Illegal, + OPC_65C02_NOP22, // $82 + OPC_65C02_NOP11, // $83 OPC_6502_84, OPC_6502_85, OPC_6502_86, - OPC_Illegal, + OPC_Illegal, // $87: SMB0 currently unsupported OPC_6502_88, - OPC_Illegal, + OPC_65SC02_89, OPC_6502_8A, - OPC_Illegal, + OPC_65C02_NOP11, // $8B OPC_6502_8C, OPC_6502_8D, OPC_6502_8E, - OPC_Illegal, + OPC_Illegal, // $8F: BBS0 currently unsupported OPC_6502_90, OPC_6502_91, - OPC_Illegal, - OPC_Illegal, + OPC_65SC02_92, + OPC_65C02_NOP11, // $93 OPC_6502_94, OPC_6502_95, OPC_6502_96, - OPC_Illegal, + OPC_Illegal, // $97: SMB1 currently unsupported OPC_6502_98, OPC_6502_99, OPC_6502_9A, - OPC_Illegal, - OPC_Illegal, + OPC_65C02_NOP11, // $9B + OPC_65SC02_9C, OPC_6502_9D, - OPC_Illegal, - OPC_Illegal, + OPC_65SC02_9E, + OPC_Illegal, // $9F: BBS1 currently unsupported OPC_6502_A0, OPC_6502_A1, OPC_6502_A2, - OPC_Illegal, + OPC_65C02_NOP11, // $A3 OPC_6502_A4, OPC_6502_A5, OPC_6502_A6, - OPC_Illegal, + OPC_Illegal, // $A7: SMB2 currently unsupported OPC_6502_A8, OPC_6502_A9, OPC_6502_AA, - OPC_Illegal, + OPC_65C02_NOP11, // $AB OPC_6502_AC, OPC_6502_AD, OPC_6502_AE, - OPC_Illegal, + OPC_Illegal, // $AF: BBS2 currently unsupported OPC_6502_B0, OPC_6502_B1, - OPC_Illegal, - OPC_Illegal, + OPC_65SC02_B2, + OPC_65C02_NOP11, // $B3 OPC_6502_B4, OPC_6502_B5, OPC_6502_B6, - OPC_Illegal, + OPC_Illegal, // $B7: SMB3 currently unsupported OPC_6502_B8, OPC_6502_B9, OPC_6502_BA, - OPC_Illegal, + OPC_65C02_NOP11, // $BB OPC_6502_BC, OPC_6502_BD, OPC_6502_BE, - OPC_Illegal, + OPC_Illegal, // $BF: BBS3 currently unsupported OPC_6502_C0, OPC_6502_C1, - OPC_Illegal, - OPC_Illegal, + OPC_65C02_NOP22, // $C2 + OPC_65C02_NOP11, // $C3 OPC_6502_C4, OPC_6502_C5, OPC_6502_C6, - OPC_Illegal, + OPC_Illegal, // $C7: SMB4 currently unsupported OPC_6502_C8, OPC_6502_C9, OPC_6502_CA, - OPC_Illegal, + OPC_Illegal, // $CB: WAI currently unsupported OPC_6502_CC, OPC_6502_CD, OPC_6502_CE, - OPC_Illegal, + OPC_Illegal, // $CF: BBS4 currently unsupported OPC_6502_D0, OPC_6502_D1, - OPC_Illegal, - OPC_Illegal, - OPC_Illegal, + OPC_65SC02_D2, + OPC_65C02_NOP11, // $D3 + OPC_65C02_NOP24, // $D4 OPC_6502_D5, OPC_6502_D6, - OPC_Illegal, + OPC_Illegal, // $D7: SMB5 currently unsupported OPC_6502_D8, OPC_6502_D9, - OPC_Illegal, - OPC_Illegal, - OPC_Illegal, + OPC_65SC02_DA, + OPC_Illegal, // $DB: STP currently unsupported + OPC_65C02_NOP34, // $DC OPC_6502_DD, OPC_6502_DE, - OPC_Illegal, + OPC_Illegal, // $DF: BBS5 currently unsupported OPC_6502_E0, OPC_6502_E1, - OPC_Illegal, - OPC_Illegal, + OPC_65C02_NOP22, // $E2 + OPC_65C02_NOP11, // $E3 OPC_6502_E4, OPC_6502_E5, OPC_6502_E6, - OPC_Illegal, + OPC_Illegal, // $E7: SMB6 currently unsupported OPC_6502_E8, OPC_6502_E9, OPC_6502_EA, - OPC_Illegal, + OPC_65C02_NOP11, // $EB OPC_6502_EC, OPC_6502_ED, OPC_6502_EE, - OPC_Illegal, + OPC_Illegal, // $EF: BBS6 currently unsupported OPC_6502_F0, OPC_6502_F1, - OPC_Illegal, - OPC_Illegal, - OPC_Illegal, + OPC_65SC02_F2, + OPC_65C02_NOP11, // $F3 + OPC_65C02_NOP24, // $F4 OPC_6502_F5, OPC_6502_F6, - OPC_Illegal, + OPC_Illegal, // $F7: SMB7 currently unsupported OPC_6502_F8, OPC_6502_F9, - OPC_Illegal, - OPC_Illegal, - OPC_Illegal, + OPC_65SC02_FA, + OPC_65C02_NOP11, // $FB + OPC_65C02_NOP34, // $FC OPC_6502_FD, OPC_6502_FE, - OPC_Illegal, + OPC_Illegal, // $FF: BBS7 currently unsupported }; @@ -2776,7 +3216,9 @@ void Reset (void) /* Reset the CPU */ HaveIRQRequest = 0; HaveNMIRequest = 0; - Regs.SR = 0; + + /* Bits 5 and 4 aren't used, and always are 1! */ + Regs.SR = 0x30; Regs.PC = MemReadWord (0xFFFC); } @@ -2791,8 +3233,12 @@ unsigned ExecuteInsn (void) HaveNMIRequest = 0; PUSH (PCH); PUSH (PCL); - PUSH (Regs.SR); + PUSH (Regs.SR & ~BF); SET_IF (1); + if (CPU != CPU_6502) + { + SET_DF (0); + } Regs.PC = MemReadWord (0xFFFA); Cycles = 7; @@ -2801,8 +3247,12 @@ unsigned ExecuteInsn (void) HaveIRQRequest = 0; PUSH (PCH); PUSH (PCL); - PUSH (Regs.SR); + PUSH (Regs.SR & ~BF); SET_IF (1); + if (CPU != CPU_6502) + { + SET_DF (0); + } Regs.PC = MemReadWord (0xFFFE); Cycles = 7; diff --git a/src/sp65/attr.c b/src/sp65/attr.c index db026af48..e57b86973 100644 --- a/src/sp65/attr.c +++ b/src/sp65/attr.c @@ -240,7 +240,7 @@ void SplitAddAttr (Collection* C, const char* Combined, const char* Name) -Collection* ParseAttrList (const char* List, const char** NameList, unsigned NameCount) +Collection* ParseAttrList (const char* List, const char* const* NameList, unsigned NameCount) /* Parse a list containing name/value pairs into a sorted collection. Some ** attributes may not need a name, so NameList contains these names. If there ** were no errors, the function returns a alphabetically sorted collection diff --git a/src/sp65/attr.h b/src/sp65/attr.h index 2b7ce68b9..e93bcd937 100644 --- a/src/sp65/attr.h +++ b/src/sp65/attr.h @@ -111,7 +111,7 @@ void SplitAddAttr (Collection* C, const char* Combined, const char* Name); ** Name is NULL, terminate with an error. */ -Collection* ParseAttrList (const char* List, const char** NameList, unsigned NameCount); +Collection* ParseAttrList (const char* List, const char* const* NameList, unsigned NameCount); /* Parse a list containing name/value pairs into a sorted collection. Some ** attributes may not need a name, so NameList contains these names. If there ** were no errors, the function returns a alphabetically sorted collection diff --git a/src/sp65/main.c b/src/sp65/main.c index 828a48fc8..5c9724a8a 100644 --- a/src/sp65/main.c +++ b/src/sp65/main.c @@ -141,7 +141,7 @@ static void SetOutputData (StrBuf* N) static void OptConvertTo (const char* Opt attribute ((unused)), const char* Arg) /* Convert the bitmap into a target format */ { - static const char* NameList[] = { + static const char* const NameList[] = { "format" }; @@ -220,7 +220,7 @@ static void OptPop (const char* Opt attribute ((unused)), static void OptRead (const char* Opt attribute ((unused)), const char* Arg) /* Read an input file */ { - static const char* NameList[] = { + static const char* const NameList[] = { "name", "format" }; @@ -294,7 +294,7 @@ static void OptVersion (const char* Opt attribute ((unused)), static void OptWrite (const char* Opt attribute ((unused)), const char* Arg) /* Write an output file */ { - static const char* NameList[] = { + static const char* const NameList[] = { "name", "format" }; diff --git a/test/Makefile b/test/Makefile index 4817e70e0..c85883517 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,51 +1,36 @@ - -# top-level makefile for the regression tests - -# You can comment this special target when you debug the regression tests. -# Then, make will give you more progress reports. -.SILENT: +# top-level Makefile for the regression tests ifneq ($(shell echo),) - CMD_EXE := 1 + CMD_EXE = 1 endif ifdef CMD_EXE - EXE := .exe - MKDIR = mkdir $(subst /,\,$1) RMDIR = -rmdir /s /q $(subst /,\,$1) else - EXE := - MKDIR = mkdir $1 RMDIR = $(RM) -r $1 endif -WORKDIR := ../testwrk - -CC := gcc +WORKDIR = ../testwrk .PHONY: all dotests continue mostlyclean clean all: dotests -$(WORKDIR): - $(call MKDIR,$(WORKDIR)) - -$(WORKDIR)/bdiff$(EXE): bdiff.c | $(WORKDIR) - $(CC) -O2 -o $@ $< - .NOTPARALLEL: dotests: mostlyclean continue -continue: $(WORKDIR)/bdiff$(EXE) - @$(MAKE) -C assembler all - @$(MAKE) -C disassembler all +continue: + @$(MAKE) -C asm all + @$(MAKE) -C dasm all @$(MAKE) -C val all @$(MAKE) -C ref all @$(MAKE) -C err all @$(MAKE) -C misc all mostlyclean: + @$(MAKE) -C asm clean + @$(MAKE) -C dasm clean @$(MAKE) -C val clean @$(MAKE) -C ref clean @$(MAKE) -C err clean diff --git a/test/assembler/4510-cpudetect.ref b/test/asm/4510-cpudetect.ref similarity index 100% rename from test/assembler/4510-cpudetect.ref rename to test/asm/4510-cpudetect.ref diff --git a/test/assembler/4510-opcodes.ref b/test/asm/4510-opcodes.ref similarity index 100% rename from test/assembler/4510-opcodes.ref rename to test/asm/4510-opcodes.ref diff --git a/test/assembler/4510-opcodes.s b/test/asm/4510-opcodes.s similarity index 100% rename from test/assembler/4510-opcodes.s rename to test/asm/4510-opcodes.s diff --git a/test/assembler/6502-cpudetect.ref b/test/asm/6502-cpudetect.ref similarity index 100% rename from test/assembler/6502-cpudetect.ref rename to test/asm/6502-cpudetect.ref diff --git a/test/assembler/6502-opcodes.ref b/test/asm/6502-opcodes.ref similarity index 100% rename from test/assembler/6502-opcodes.ref rename to test/asm/6502-opcodes.ref diff --git a/test/assembler/6502-opcodes.s b/test/asm/6502-opcodes.s similarity index 100% rename from test/assembler/6502-opcodes.s rename to test/asm/6502-opcodes.s diff --git a/test/assembler/6502x-cpudetect.ref b/test/asm/6502x-cpudetect.ref similarity index 100% rename from test/assembler/6502x-cpudetect.ref rename to test/asm/6502x-cpudetect.ref diff --git a/test/assembler/6502x-opcodes.ref b/test/asm/6502x-opcodes.ref similarity index 100% rename from test/assembler/6502x-opcodes.ref rename to test/asm/6502x-opcodes.ref diff --git a/test/assembler/6502x-opcodes.s b/test/asm/6502x-opcodes.s similarity index 100% rename from test/assembler/6502x-opcodes.s rename to test/asm/6502x-opcodes.s diff --git a/test/assembler/65816-cpudetect.ref b/test/asm/65816-cpudetect.ref similarity index 100% rename from test/assembler/65816-cpudetect.ref rename to test/asm/65816-cpudetect.ref diff --git a/test/assembler/65c02-cpudetect.ref b/test/asm/65c02-cpudetect.ref similarity index 100% rename from test/assembler/65c02-cpudetect.ref rename to test/asm/65c02-cpudetect.ref diff --git a/test/assembler/65c02-opcodes.ref b/test/asm/65c02-opcodes.ref similarity index 100% rename from test/assembler/65c02-opcodes.ref rename to test/asm/65c02-opcodes.ref diff --git a/test/assembler/65c02-opcodes.s b/test/asm/65c02-opcodes.s similarity index 100% rename from test/assembler/65c02-opcodes.s rename to test/asm/65c02-opcodes.s diff --git a/test/assembler/65sc02-cpudetect.ref b/test/asm/65sc02-cpudetect.ref similarity index 100% rename from test/assembler/65sc02-cpudetect.ref rename to test/asm/65sc02-cpudetect.ref diff --git a/test/assembler/65sc02-opcodes.ref b/test/asm/65sc02-opcodes.ref similarity index 100% rename from test/assembler/65sc02-opcodes.ref rename to test/asm/65sc02-opcodes.ref diff --git a/test/assembler/65sc02-opcodes.s b/test/asm/65sc02-opcodes.s similarity index 100% rename from test/assembler/65sc02-opcodes.s rename to test/asm/65sc02-opcodes.s diff --git a/test/asm/Makefile b/test/asm/Makefile new file mode 100644 index 000000000..93210aaee --- /dev/null +++ b/test/asm/Makefile @@ -0,0 +1,74 @@ +# Makefile for the assembler regression tests + +ifneq ($(shell echo),) + CMD_EXE = 1 +endif + +ifdef CMD_EXE + EXE = .exe + MKDIR = mkdir $(subst /,\,$1) + RMDIR = -rmdir /s /q $(subst /,\,$1) + DEL = del /f $(subst /,\,$1) +else + EXE = + MKDIR = mkdir -p $1 + RMDIR = $(RM) -r $1 + DEL = $(RM) $1 +endif + +ifdef QUIET + .SILENT: +endif + +CL65 := $(if $(wildcard ../../bin/cl65*),../../bin/cl65,cl65) + +WORKDIR = ../../testwrk/asm + +DIFF = $(WORKDIR)/bdiff$(EXE) + +CC = gcc +CFLAGS = -O2 + +.PHONY: all clean + +OPCODE_REFS := $(wildcard *-opcodes.ref) +OPCODE_CPUS = $(foreach ref,$(OPCODE_REFS),$(ref:%-opcodes.ref=%)) +OPCODE_BINS = $(foreach cpu,$(OPCODE_CPUS),$(WORKDIR)/$(cpu)-opcodes.bin) + +CPUDETECT_REFS := $(wildcard *-cpudetect.ref) +CPUDETECT_CPUS = $(foreach ref,$(CPUDETECT_REFS),$(ref:%-cpudetect.ref=%)) +CPUDETECT_BINS = $(foreach cpu,$(CPUDETECT_CPUS),$(WORKDIR)/$(cpu)-cpudetect.bin) + +all: $(OPCODE_BINS) $(CPUDETECT_BINS) + +$(WORKDIR): + $(call MKDIR,$(WORKDIR)) + +$(DIFF): ../bdiff.c | $(WORKDIR) + $(CC) $(CFLAGS) -o $@ $< + +define OPCODE_template + +$(WORKDIR)/$1-opcodes.bin: $1-opcodes.s $(DIFF) + $(if $(QUIET),echo asm/$1-opcodes.bin) + $(CL65) --cpu $1 -t none -l $(WORKDIR)/$1-opcodes.lst -o $$@ $$< + $(DIFF) $$@ $1-opcodes.ref + +endef # OPCODE_template + +$(foreach cpu,$(OPCODE_CPUS),$(eval $(call OPCODE_template,$(cpu)))) + +define CPUDETECT_template + +$(WORKDIR)/$1-cpudetect.bin: cpudetect.s $(DIFF) + $(if $(QUIET),echo asm/$1-cpudetect.bin) + $(CL65) --cpu $1 -t none -l $(WORKDIR)/$1-cpudetect.lst -o $$@ $$< + $(DIFF) $$@ $1-cpudetect.ref + +endef # CPUDETECT_template + +$(foreach cpu,$(CPUDETECT_CPUS),$(eval $(call CPUDETECT_template,$(cpu)))) + +clean: + @$(call RMDIR,$(WORKDIR)) + @$(call DEL,$(OPCODE_REFS:.ref=.o) cpudetect.o) diff --git a/test/assembler/README b/test/asm/README similarity index 100% rename from test/assembler/README rename to test/asm/README diff --git a/test/assembler/cpudetect.s b/test/asm/cpudetect.s similarity index 100% rename from test/assembler/cpudetect.s rename to test/asm/cpudetect.s diff --git a/test/assembler/huc6280-cpudetect.ref b/test/asm/huc6280-cpudetect.ref similarity index 100% rename from test/assembler/huc6280-cpudetect.ref rename to test/asm/huc6280-cpudetect.ref diff --git a/test/assembler/huc6280-opcodes.ref b/test/asm/huc6280-opcodes.ref similarity index 100% rename from test/assembler/huc6280-opcodes.ref rename to test/asm/huc6280-opcodes.ref diff --git a/test/assembler/huc6280-opcodes.s b/test/asm/huc6280-opcodes.s similarity index 100% rename from test/assembler/huc6280-opcodes.s rename to test/asm/huc6280-opcodes.s diff --git a/test/assembler/m740-opcodes.s b/test/asm/m740-opcodes.s similarity index 100% rename from test/assembler/m740-opcodes.s rename to test/asm/m740-opcodes.s diff --git a/test/assembler/.gitignore b/test/assembler/.gitignore deleted file mode 100644 index c0c74a35e..000000000 --- a/test/assembler/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -*.o -*.bin -*.lst diff --git a/test/assembler/Makefile b/test/assembler/Makefile deleted file mode 100644 index 5d38847f5..000000000 --- a/test/assembler/Makefile +++ /dev/null @@ -1,45 +0,0 @@ - -# makefile for the assembler regression tests - -BINDIR = ../../bin -WORKDIR := ../../testwrk - -BASE_TARGETS = 6502 6502x 65sc02 65c02 -BASE_TARGETS += 4510 huc6280 - -OPCODE_TARGETS = $(BASE_TARGETS) -CPUDETECT_TARGETS = $(BASE_TARGETS) - -CPUDETECT_TARGETS += 65816 - -# default target defined later -all: - -# generate opcode targets and expand target list -define opcode -OPCODE_TARGETLIST += $$(WORKDIR)/$(1)-opcodes.bin -$$(WORKDIR)/$(1)-opcodes.bin: $(1)-opcodes.s - @$$(BINDIR)/cl65 --cpu $(1) -t none -l $$(WORKDIR)/$(1)-opcodes.lst --obj-path $$(WORKDIR) -o $$@ $$< - @diff -q $(1)-opcodes.ref $$@ || (cat $$(WORKDIR)/$(1)-opcodes.lst ; exit 1) - @echo ca65 --cpu $(1) opcodes ok - @rm -f $(1)-opcodes.o #workaround for #168 -endef -$(foreach target,$(OPCODE_TARGETS),$(eval $(call opcode,$(target)))) - -# generate cpudetect targets and expand target list -define cpudetect -CPUDETECT_TARGETLIST += $$(WORKDIR)/$(1)-cpudetect.bin -$$(WORKDIR)/$(1)-cpudetect.bin: cpudetect.s - @$$(BINDIR)/cl65 --cpu $(1) -t none -l $$(WORKDIR)/$(1)-cpudetect.lst --obj-path $$(WORKDIR) -o $$@ $$< - @diff -q $(1)-cpudetect.ref $$@ || (cat $$(WORKDIR)/$(1)-cpudetect.lst ; exit 1) - @echo ca65 --cpu $(1) cpudetect ok - @rm -f cpudetect.o #workaround for #168 -endef -$(foreach target,$(CPUDETECT_TARGETS),$(eval $(call cpudetect,$(target)))) - -# now that all targets have been generated, get to the manual ones -all: $(OPCODE_TARGETLIST) $(CPUDETECT_TARGETLIST) - @# - -.PHONY: all $(OPCODE_TARGETLIST) $(CPUDETECT_TARGETLIST) - diff --git a/test/disassembler/4510-disass.s b/test/dasm/4510-disass.s similarity index 100% rename from test/disassembler/4510-disass.s rename to test/dasm/4510-disass.s diff --git a/test/dasm/Makefile b/test/dasm/Makefile new file mode 100644 index 000000000..d70711491 --- /dev/null +++ b/test/dasm/Makefile @@ -0,0 +1,69 @@ +# Makefile for the disassembler regression tests + +ifneq ($(shell echo),) + CMD_EXE = 1 +endif + +ifdef CMD_EXE + EXE = .exe + MKDIR = mkdir $(subst /,\,$1) + RMDIR = -rmdir /s /q $(subst /,\,$1) + DEL = del /f $(subst /,\,$1) +else + EXE = + MKDIR = mkdir -p $1 + RMDIR = $(RM) -r $1 + DEL = $(RM) $1 +endif + +ifdef QUIET + .SILENT: +endif + +CL65 := $(if $(wildcard ../../bin/cl65*),../../bin/cl65,cl65) +DA65 := $(if $(wildcard ../../bin/da65*),../../bin/da65,da65) + +WORKDIR = ../../testwrk/dasm + +DIFF = $(WORKDIR)/bdiff$(EXE) + +CC = gcc +CFLAGS = -O2 + +START = --start-addr 0x8000 + +.PHONY: all clean + +SOURCES := $(wildcard *.s) +CPUS = $(foreach src,$(SOURCES),$(src:%-disass.s=%)) +BINS = $(foreach cpu,$(CPUS),$(WORKDIR)/$(cpu)-reass.bin) + +# default target defined later +all: $(BINS) + +$(WORKDIR): + $(call MKDIR,$(WORKDIR)) + +$(DIFF): ../bdiff.c | $(WORKDIR) + $(CC) $(CFLAGS) -o $@ $< + +define DISASS_template + +$(WORKDIR)/$1-disass.bin: $1-disass.s | $(WORKDIR) + $(CL65) --cpu $1 -t none $(START) -o $$@ $$< + +$(WORKDIR)/$1-reass.s: $(WORKDIR)/$1-disass.bin + $(DA65) --cpu $1 $(START) -o $$@ $$< + +$(WORKDIR)/$1-reass.bin: $(WORKDIR)/$1-reass.s $(DIFF) + $(if $(QUIET),echo dasm/$1-reass.bin) + $(CL65) --cpu $1 -t none $(START) -o $$@ $$< + $(DIFF) $$@ $(WORKDIR)/$1-disass.bin + +endef # DISASS_template + +$(foreach cpu,$(CPUS),$(eval $(call DISASS_template,$(cpu)))) + +clean: + @$(call RMDIR,$(WORKDIR)) + @$(call DEL,$(SOURCES:.s=.o)) diff --git a/test/disassembler/Makefile b/test/disassembler/Makefile deleted file mode 100644 index 2621b0c20..000000000 --- a/test/disassembler/Makefile +++ /dev/null @@ -1,42 +0,0 @@ - -# makefile for the disassembler regression tests - -BINDIR = ../../bin -WORKDIR := ../../testwrk - -#BASE_TARGETS = 6502 6502x 65sc02 65c02 -#BASE_TARGETS += 4510 huc6280 -BASE_TARGETS = 4510 - -START = --start-addr 0x8000 - -DISASS_TARGETS = $(BASE_TARGETS) - -# default target defined later -all: - -# generate opcode targets and expand target list -define disass -DISASS_TARGETLIST += $$(WORKDIR)/$(1)-reass.bin $$(WORKDIR)/$(1)-reass.s $$(WORKDIR)/$(1)-disass.bin - -$$(WORKDIR)/$(1)-disass.bin: $(1)-disass.s - @$$(BINDIR)/cl65 --cpu $(1) -t none $(START) --obj-path $$(WORKDIR) -o $$@ $$< - @rm -f $(1)-disass.o #workaround for #168 - -$$(WORKDIR)/$(1)-reass.s: $$(WORKDIR)/$(1)-disass.bin - @$$(BINDIR)/da65 --cpu $(1) $(START) -o $$@ $$< - -$$(WORKDIR)/$(1)-reass.bin: $$(WORKDIR)/$(1)-reass.s - @$$(BINDIR)/cl65 --cpu $(1) -t none $(START) --obj-path $$(WORKDIR) -o $$@ $$< - @rm -f $(1)-reass.o #workaround for #168 - @cmp $$@ $$(WORKDIR)/$(1)-disass.bin - @echo da65 --cpu $(1) ok -endef -$(foreach target,$(DISASS_TARGETS),$(eval $(call disass,$(target)))) - -# now that all targets have been generated, get to the manual ones -all: $(DISASS_TARGETLIST) - @# - -.PHONY: all $(DISASS_TARGETLIST) - diff --git a/test/err/Makefile b/test/err/Makefile index bc4226acb..4b05ca5db 100644 --- a/test/err/Makefile +++ b/test/err/Makefile @@ -1,29 +1,42 @@ -# makefile for the tests that MUST NOT compile +# Makefile for the tests that MUST NOT compile ifneq ($(shell echo),) - CMD_EXE := 1 + CMD_EXE = 1 endif ifdef CMD_EXE - NOT := - # Hack - DEL = -del /f $(subst /,\,$1) + S = $(subst /,\,/) + NOT = - # Hack + NULLDEV = nul: + MKDIR = mkdir $(subst /,\,$1) + RMDIR = -rmdir /s /q $(subst /,\,$1) else - NOT := ! - DEL = $(RM) $1 + S = / + NOT = ! + NULLDEV = /dev/null + MKDIR = mkdir -p $1 + RMDIR = $(RM) -r $1 endif -CC65 := $(if $(wildcard ../../bin/cc65*),../../bin/cc65,cc65) +ifdef QUIET + .SILENT: + NULLERR = 2>$(NULLDEV) +endif -WORKDIR := ../../testwrk +CC65 := $(if $(wildcard ../../bin/cc65*),..$S..$Sbin$Scc65,cc65) + +WORKDIR = ../../testwrk/err .PHONY: all clean -TESTS := $(patsubst %.c,$(WORKDIR)/%.s,$(wildcard *.c)) +SOURCES := $(wildcard *.c) +TESTS = $(patsubst %.c,$(WORKDIR)/%.s,$(SOURCES)) all: $(TESTS) $(WORKDIR)/%.s: %.c - $(NOT) $(CC65) -o $@ $< + $(if $(QUIET),echo err/$*.s) + $(NOT) $(CC65) -o $@ $< $(NULLERR) clean: - @$(call DEL,$(TESTS)) + @$(call RMDIR,$(WORKDIR)) diff --git a/test/err/bss-name-conflict.c b/test/err/bss-name-conflict.c new file mode 100644 index 000000000..1d6cd5066 --- /dev/null +++ b/test/err/bss-name-conflict.c @@ -0,0 +1,20 @@ +/* + !!DESCRIPTION!! conflicting bss-name pragmas + !!ORIGIN!! cc65 regression tests + !!LICENCE!! Public Domain + !!AUTHOR!! Piotr Fusik +*/ + +/* + see: https://github.com/cc65/cc65/issues/409 +*/ + +char oam_off; +#pragma bss-name (push,"ZEROPAGE") +char oam_off; +#pragma bss-name (pop) + +int main(void) +{ + return 0; +} diff --git a/test/err/duplicate-global-static.c b/test/err/duplicate-global-static.c new file mode 100644 index 000000000..6aa27f5b7 --- /dev/null +++ b/test/err/duplicate-global-static.c @@ -0,0 +1,18 @@ +/* + !!DESCRIPTION!! global duplicated with static variable + !!ORIGIN!! cc65 regression tests + !!LICENCE!! Public Domain + !!AUTHOR!! Piotr Fusik +*/ + +/* + see: https://github.com/cc65/cc65/issues/191 +*/ + +int n = 0; +static int n = 0; /* should give an error */ + +int main(void) +{ + return n; +} diff --git a/test/err/duplicate-global.c b/test/err/duplicate-global.c new file mode 100644 index 000000000..bd4fcc24a --- /dev/null +++ b/test/err/duplicate-global.c @@ -0,0 +1,20 @@ +/* + !!DESCRIPTION!! duplicate globals + !!ORIGIN!! cc65 regression tests + !!LICENCE!! Public Domain + !!AUTHOR!! Piotr Fusik +*/ + +/* + see: https://github.com/cc65/cc65/issues/191 +*/ + +#pragma warn(error, on) + +int n = 0; +int n = 0; /* should give an error */ + +int main(void) +{ + return n; +} diff --git a/test/err/duplicate-static-global.c b/test/err/duplicate-static-global.c new file mode 100644 index 000000000..6e5e70a37 --- /dev/null +++ b/test/err/duplicate-static-global.c @@ -0,0 +1,18 @@ +/* + !!DESCRIPTION!! static duplicated with global variable + !!ORIGIN!! cc65 regression tests + !!LICENCE!! Public Domain + !!AUTHOR!! Piotr Fusik +*/ + +/* + see: https://github.com/cc65/cc65/issues/191 +*/ + +static int n = 0; +int n = 0; /* should give an error */ + +int main(void) +{ + return n; +} diff --git a/test/err/duplicate-static.c b/test/err/duplicate-static.c new file mode 100644 index 000000000..394cc1e09 --- /dev/null +++ b/test/err/duplicate-static.c @@ -0,0 +1,20 @@ +/* + !!DESCRIPTION!! duplicate static variables + !!ORIGIN!! cc65 regression tests + !!LICENCE!! Public Domain + !!AUTHOR!! Piotr Fusik +*/ + +/* + see: https://github.com/cc65/cc65/issues/191 +*/ + +#pragma warn(error, on) + +static int n = 0; +static int n = 0; /* should give an error */ + +int main(void) +{ + return n; +} diff --git a/test/err/void-empty.c b/test/err/void-empty.c new file mode 100644 index 000000000..900918222 --- /dev/null +++ b/test/err/void-empty.c @@ -0,0 +1,9 @@ +/* + !!DESCRIPTION!! Uninitialized void variables + !!ORIGIN!! cc65 regression tests + !!LICENCE!! Public Domain + !!AUTHOR!! Greg King +*/ + +void test; +const void list; diff --git a/test/err/void-size2.c b/test/err/void-size2.c new file mode 100644 index 000000000..3d4f13322 --- /dev/null +++ b/test/err/void-size2.c @@ -0,0 +1,11 @@ +/* + !!DESCRIPTION!! Size of void cast + !!ORIGIN!! cc65 regression tests + !!LICENCE!! Public Domain + !!AUTHOR!! Greg King +*/ + +unsigned test (void) +{ + return sizeof ((void)12345); +} diff --git a/test/misc/Makefile b/test/misc/Makefile index 918316c6c..330c9d500 100644 --- a/test/misc/Makefile +++ b/test/misc/Makefile @@ -1,63 +1,96 @@ - -# makefile for the remaining tests that need special care in one way or another +# Makefile for the remaining tests that need special care in one way or another ifneq ($(shell echo),) - CMD_EXE := 1 + CMD_EXE = 1 endif ifdef CMD_EXE - S := $(subst /,\,/) - NOT := - # Hack - DEL = -del /f $(subst /,\,$1) + S = $(subst /,\,/) + NOT = - # Hack + EXE = .exe + NULLDEV = nul: + MKDIR = mkdir $(subst /,\,$1) + RMDIR = -rmdir /s /q $(subst /,\,$1) + DEL = del /f $(subst /,\,$1) else - S := / - NOT := ! + S = / + NOT = ! + EXE = + NULLDEV = /dev/null + MKDIR = mkdir -p $1 + RMDIR = $(RM) -r $1 DEL = $(RM) $1 endif -CC65FLAGS := -t sim6502 -SIM65FLAGS := -x 200000000 +ifdef QUIET + .SILENT: + NULLOUT = >$(NULLDEV) + NULLERR = 2>$(NULLDEV) +endif -CL65 := $(if $(wildcard ../../bin/cl65*),../../bin/cl65,cl65) +SIM65FLAGS = -x 200000000 + +CL65 := $(if $(wildcard ../../bin/cl65*),..$S..$Sbin$Scl65,cl65) SIM65 := $(if $(wildcard ../../bin/sim65*),..$S..$Sbin$Ssim65,sim65) -WORKDIR := ..$S..$Stestwrk -DIFF := $(WORKDIR)/bdiff +WORKDIR = ..$S..$Stestwrk$Smisc + +OPTIONS = g O Os Osi Osir Osr Oi Oir Or + +DIFF = $(WORKDIR)$Sbdiff$(EXE) + +CC = gcc +CFLAGS = -O2 .PHONY: all clean SOURCES := $(wildcard *.c) -TESTS := $(foreach option,. .o. .os. .osi. .osir. .oi. .oir. .or.,$(SOURCES:%.c=$(WORKDIR)/%$(option)prg)) +TESTS = $(foreach option,$(OPTIONS),$(SOURCES:%.c=$(WORKDIR)/%.$(option).6502.prg)) +TESTS += $(foreach option,$(OPTIONS),$(SOURCES:%.c=$(WORKDIR)/%.$(option).65c02.prg)) all: $(TESTS) +$(WORKDIR): + $(call MKDIR,$(WORKDIR)) + +$(DIFF): ../bdiff.c | $(WORKDIR) + $(CC) $(CFLAGS) -o $@ $< + +define PRG_template + # should compile, but then hangs in an endless loop -$(WORKDIR)/endless%prg: endless.c - $(CL65) $(subst .,,$(*:.o%=-O%)) $(CC65FLAGS) $< -o $@ - $(NOT) $(SIM65) $(SIM65FLAGS) $@ +$(WORKDIR)/endless.$1.$2.prg: endless.c | $(WORKDIR) + $(if $(QUIET),echo misc/endless.$1.$2.prg) + $(CL65) -t sim$2 -$1 -o $$@ $$< $(NULLERR) + $(NOT) $(SIM65) $(SIM65FLAGS) $$@ $(NULLOUT) $(NULLERR) # these need reference data that can't be generated by a host-compiled program, # in a useful way -$(WORKDIR)/limits%prg: limits.c - $(CL65) $(subst .,,$(*:.o%=-O%)) $(CC65FLAGS) $< -o $@ - $(SIM65) $(SIM65FLAGS) $@ > $(WORKDIR)/limits.out - $(DIFF) $(WORKDIR)/limits.out limits.ref +$(WORKDIR)/limits.$1.$2.prg: limits.c $(DIFF) + $(if $(QUIET),echo misc/limits.$1.$2.prg) + $(CL65) -t sim$2 -$1 -o $$@ $$< $(NULLERR) + $(SIM65) $(SIM65FLAGS) $$@ > $(WORKDIR)/limits.$1.out + $(DIFF) $(WORKDIR)/limits.$1.out limits.ref # the rest are tests that fail currently for one reason or another -$(WORKDIR)/fields%prg: fields.c - @echo "FIXME: " $@ "currently will fail." - $(CL65) $(subst .,,$(*:.o%=-O%)) $(CC65FLAGS) $< -o $@ - -$(SIM65) $(SIM65FLAGS) $@ -$(WORKDIR)/sitest%prg: sitest.c - @echo "FIXME: " $@ "currently will fail." - -$(CL65) $(subst .,,$(*:.o%=-O%)) $(CC65FLAGS) $< -o $@ -# -$(SIM65) $(SIM65FLAGS) $@ -$(WORKDIR)/cc65141011%prg: cc65141011.c - @echo "FIXME: " $@ "currently can fail." - $(CL65) $(subst .,,$(*:.o%=-O%)) $(CC65FLAGS) $< -o $@ - -$(SIM65) $(SIM65FLAGS) $@ +$(WORKDIR)/fields.$1.$2.prg: fields.c | $(WORKDIR) + @echo "FIXME: " $$@ "currently will fail." + $(CL65) -t sim$2 -$1 -o $$@ $$< $(NULLERR) + -$(SIM65) $(SIM65FLAGS) $$@ $(NULLOUT) +$(WORKDIR)/sitest.$1.$2.prg: sitest.c | $(WORKDIR) + @echo "FIXME: " $$@ "currently will fail." + -$(CL65) -t sim$2 -$1 -o $$@ $$< $(NULLERR) +# -$(SIM65) $(SIM65FLAGS) $$@ $(NULLOUT) +$(WORKDIR)/cc65141011.$1.$2.prg: cc65141011.c | $(WORKDIR) + @echo "FIXME: " $$@ "currently can fail." + $(CL65) -t sim$2 -$1 -o $$@ $$< $(NULLERR) + -$(SIM65) $(SIM65FLAGS) $$@ $(NULLOUT) + +endef # PRG_template + +$(foreach option,$(OPTIONS),$(eval $(call PRG_template,$(option),6502))) +$(foreach option,$(OPTIONS),$(eval $(call PRG_template,$(option),65c02))) clean: - @$(call DEL,$(TESTS)) + @$(call RMDIR,$(WORKDIR)) @$(call DEL,$(SOURCES:.c=.o)) - @$(call DEL,$(SOURCES:%.c=$(WORKDIR)/%.out)) diff --git a/test/ref/Makefile b/test/ref/Makefile index 09dd96d44..3c2e582e4 100644 --- a/test/ref/Makefile +++ b/test/ref/Makefile @@ -1,96 +1,94 @@ - -# makefile for the regression tests that generate output which has to be +# Makefile for the regression tests that generate output which has to be # compared with reference output ifneq ($(shell echo),) - CMD_EXE := 1 + CMD_EXE = 1 endif ifdef CMD_EXE - S := $(subst /,\,/) - DEL = -del /f $(subst /,\,$1) + S = $(subst /,\,/) + EXE = .exe + NULLDEV = nul: + MKDIR = mkdir $(subst /,\,$1) + RMDIR = -rmdir /s /q $(subst /,\,$1) + DEL = del /f $(subst /,\,$1) else - S := / + S = / + EXE = + NULLDEV = /dev/null + MKDIR = mkdir -p $1 + RMDIR = $(RM) -r $1 DEL = $(RM) $1 endif -CC65FLAGS := -t sim6502 -SIM65FLAGS := -x 200000000 +ifdef QUIET + .SILENT: + NULLERR = 2>$(NULLDEV) +endif -CL65 := $(if $(wildcard ../../bin/cl65*),../../bin/cl65,cl65) +SIM65FLAGS = -x 200000000 + +CL65 := $(if $(wildcard ../../bin/cl65*),..$S..$Sbin$Scl65,cl65) SIM65 := $(if $(wildcard ../../bin/sim65*),..$S..$Sbin$Ssim65,sim65) -WORKDIR := ..$S..$Stestwrk -DIFF := $(WORKDIR)/bdiff +WORKDIR = ..$S..$Stestwrk$Sref -CC := gcc -CFLAGS := -O2 -Wall -W -Wextra -fwrapv -fno-strict-overflow +OPTIONS = g O Os Osi Osir Osr Oi Oir Or + +DIFF = $(WORKDIR)$Sbdiff$(EXE) + +CC = gcc +CFLAGS = -O2 -Wall -W -Wextra -funsigned-char -fwrapv -fno-strict-overflow .PHONY: all clean SOURCES := $(wildcard *.c) -REFS := $(SOURCES:%.c=$(WORKDIR)/%.ref) -TESTS := $(foreach option,. .o. .os. .osi. .osir. .oi. .oir. .or.,$(SOURCES:%.c=$(WORKDIR)/%$(option)prg)) +REFS = $(SOURCES:%.c=$(WORKDIR)/%.ref) +TESTS = $(foreach option,$(OPTIONS),$(SOURCES:%.c=$(WORKDIR)/%.$(option).6502.prg)) +TESTS += $(foreach option,$(OPTIONS),$(SOURCES:%.c=$(WORKDIR)/%.$(option).65c02.prg)) all: $(REFS) $(TESTS) -$(WORKDIR)/%.ref: %.c - $(CC) $(CFLAGS) $< -o $(WORKDIR)/$*.host +$(WORKDIR): + $(call MKDIR,$(WORKDIR)) + +$(WORKDIR)/%.ref: %.c | $(WORKDIR) + $(if $(QUIET),echo ref/$*.host) + $(CC) $(CFLAGS) -o $(WORKDIR)/$*.host $< $(NULLERR) $(WORKDIR)$S$*.host > $@ +$(DIFF): ../bdiff.c | $(WORKDIR) + $(CC) $(CFLAGS) -o $@ $< + # Some files have "K & R"-style syntax. Therefore, some forward # function-declarations don't match the later function definitions. # Those programs fail when fastcall is used; but, the cdecl calling convention # tolerates those conflicts. Therefore, make their functions default to cdecl. # -$(WORKDIR)/init%prg: CC65FLAGS += -Wc --all-cdecl -$(WORKDIR)/switch.%rg: CC65FLAGS += -Wc --all-cdecl -$(WORKDIR)/yacc.%rg: CC65FLAGS += -Wc --all-cdecl -$(WORKDIR)/yaccdbg%prg: CC65FLAGS += -Wc --all-cdecl +$(WORKDIR)/init.%.prg \ +$(WORKDIR)/switch.%.prg \ +$(WORKDIR)/yacc.%.prg \ +$(WORKDIR)/yaccdbg.%.prg: CC65FLAGS += -Wc --all-cdecl -$(WORKDIR)/%.prg: %.c $(WORKDIR)/%.ref - $(CL65) $(CC65FLAGS) $< -o $@ - $(SIM65) $(SIM65FLAGS) $@ > $(WORKDIR)/$*.out - $(DIFF) $(WORKDIR)/$*.out $(WORKDIR)/$*.ref +# "yaccdbg.c" includes "yacc.c". +# yaccdbg's built files must depend on both of them. +# +$(WORKDIR)/yaccdbg.ref: yacc.c +$(WORKDIR)/yaccdbg.%.prg: yacc.c -$(WORKDIR)/%.o.prg: %.c $(WORKDIR)/%.ref - $(CL65) -O $(CC65FLAGS) $< -o $@ - $(SIM65) $(SIM65FLAGS) $@ > $(WORKDIR)/$*.out - $(DIFF) $(WORKDIR)/$*.out $(WORKDIR)/$*.ref +define PRG_template -$(WORKDIR)/%.os.prg: %.c $(WORKDIR)/%.ref - $(CL65) -Os $(CC65FLAGS) $< -o $@ - $(SIM65) $(SIM65FLAGS) $@ > $(WORKDIR)/$*.out - $(DIFF) $(WORKDIR)/$*.out $(WORKDIR)/$*.ref +$(WORKDIR)/%.$1.$2.prg: %.c $(WORKDIR)/%.ref $(DIFF) + $(if $(QUIET),echo ref/$$*.$1.$2.prg) + $(CL65) -t sim$2 $$(CC65FLAGS) -$1 -o $$@ $$< $(NULLERR) + $(SIM65) $(SIM65FLAGS) $$@ > $(WORKDIR)/$$*.out + $(DIFF) $(WORKDIR)/$$*.out $(WORKDIR)/$$*.ref -$(WORKDIR)/%.osi.prg: %.c $(WORKDIR)/%.ref - $(CL65) -Osi $(CC65FLAGS) $< -o $@ - $(SIM65) $(SIM65FLAGS) $@ > $(WORKDIR)/$*.out - $(DIFF) $(WORKDIR)/$*.out $(WORKDIR)/$*.ref +endef # PRG_template -$(WORKDIR)/%.osir.prg: %.c $(WORKDIR)/%.ref - $(CL65) -Osir $(CC65FLAGS) $< -o $@ - $(SIM65) $(SIM65FLAGS) $@ > $(WORKDIR)/$*.out - $(DIFF) $(WORKDIR)/$*.out $(WORKDIR)/$*.ref - -$(WORKDIR)/%.oi.prg: %.c $(WORKDIR)/%.ref - $(CL65) -Oi $(CC65FLAGS) $< -o $@ - $(SIM65) $(SIM65FLAGS) $@ > $(WORKDIR)/$*.out - $(DIFF) $(WORKDIR)/$*.out $(WORKDIR)/$*.ref - -$(WORKDIR)/%.oir.prg: %.c $(WORKDIR)/%.ref - $(CL65) -Oir $(CC65FLAGS) $< -o $@ - $(SIM65) $(SIM65FLAGS) $@ > $(WORKDIR)/$*.out - $(DIFF) $(WORKDIR)/$*.out $(WORKDIR)/$*.ref - -$(WORKDIR)/%.or.prg: %.c $(WORKDIR)/%.ref - $(CL65) -Or $(CC65FLAGS) $< -o $@ - $(SIM65) $(SIM65FLAGS) $@ > $(WORKDIR)/$*.out - $(DIFF) $(WORKDIR)/$*.out $(WORKDIR)/$*.ref +$(foreach option,$(OPTIONS),$(eval $(call PRG_template,$(option),6502))) +$(foreach option,$(OPTIONS),$(eval $(call PRG_template,$(option),65c02))) clean: - @$(call DEL,$(TESTS)) + @$(call RMDIR,$(WORKDIR)) @$(call DEL,$(SOURCES:.c=.o)) - @$(call DEL,$(SOURCES:%.c=$(WORKDIR)/%.out)) - @$(call DEL,$(SOURCES:%.c=$(WORKDIR)/%.ref)) - @$(call DEL,$(SOURCES:%.c=$(WORKDIR)/%.host)) diff --git a/test/ref/divmod.c b/test/ref/divmod.c index 68a0198e1..8fcc951a6 100644 --- a/test/ref/divmod.c +++ b/test/ref/divmod.c @@ -1,38 +1,38 @@ -/* - !!DESCRIPTION!! div/mod test - !!ORIGIN!! - !!LICENCE!! public domain -*/ - -#include <stdio.h> - -void printc(signed char a,signed char b){ -signed char x=a/b,y=a%b,z=a*b; - printf("%3d,%3d is %3d,%3d,%3d\n",a,b,x,y,z); -} -void prints(short a,short b){ -short x=a/b,y=a%b,z=a*b; - printf("%3d,%3d is %3d,%3d,%3d\n",a,b,x,y,z); -} -void printl(long a,long b){ -long x=a/b,y=a%b,z=a*b; - printf("%3ld,%3ld is %3ld,%3ld,%3ld\n",a,b,x,y,z); -} - -int main(void) { - printl( 3,-2); - printl(-3,-2); - printl(-3, 2); - printl( 3, 2); - printf("-\n"); - prints( 3,-2); - prints(-3,-2); - prints(-3, 2); - prints( 3, 2); - printf("-\n"); - printc( 3,-2); - printc(-3,-2); - printc(-3, 2); - printc( 3, 2); +/* + !!DESCRIPTION!! div/mod test + !!ORIGIN!! + !!LICENCE!! public domain +*/ + +#include <stdio.h> + +void printc(signed char a,signed char b){ +signed char x=a/b,y=a%b,z=a*b; + printf("%3d,%3d is %3d,%3d,%3d\n",a,b,x,y,z); +} +void prints(short a,short b){ +short x=a/b,y=a%b,z=a*b; + printf("%3d,%3d is %3d,%3d,%3d\n",a,b,x,y,z); +} +void printl(long a,long b){ +long x=a/b,y=a%b,z=a*b; + printf("%3ld,%3ld is %3ld,%3ld,%3ld\n",a,b,x,y,z); +} + +int main(void) { + printl( 3,-2); + printl(-3,-2); + printl(-3, 2); + printl( 3, 2); + printf("-\n"); + prints( 3,-2); + prints(-3,-2); + prints(-3, 2); + prints( 3, 2); + printf("-\n"); + printc( 3,-2); + printc(-3,-2); + printc(-3, 2); + printc( 3, 2); return 0; -} +} diff --git a/test/ref/init.c b/test/ref/init.c index 5a5816753..44cd544fd 100644 --- a/test/ref/init.c +++ b/test/ref/init.c @@ -1,95 +1,95 @@ -/* - !!DESCRIPTION!! variable initialization - !!ORIGIN!! LCC 4.1 Testsuite - !!LICENCE!! own, freely distributeable for non-profit. read CPYRIGHT.LCC -*/ - -#include "common.h" -/* todo: add back conditional stuff here ! */ - -typedef struct { int codes[3]; char name[6]; } Word; - -#ifdef NO_IMPLICIT_FUNC_PROTOTYPES - -#ifdef NO_OLD_FUNC_DECL -f(); -void g(Word *p); -h(); -#else -f(); -g(); -h(); -#endif - -#endif - -/* -Word words[] = { - 1, 2, 3,"if", - { { 4, 5 }, { 'f', 'o', 'r' } }, - 6, 7, 8, {"else"}, - { { 9, 10, 11,}, 'w', 'h', 'i', 'l', 'e', }, - { 0 }, -}, *wordlist = words; -*/ - -Word words[] = { - {{1, 2, 3},"if"}, - { { 4, 5 }, { 'f', 'o', 'r' } }, - {{6, 7, 8}, "else"}, - { { 9, 10, 11}, {'w', 'h', 'i', 'l', 'e', }}, - {{ 0 }}, -}, *wordlist = words; - -/*int x[][5] = { 1, 2, 3, 4, 0, { 5, 6 }, { 7 } };*/ -int x[][5] = { {1, 2, 3, 4, 0 }, { 5, 6 }, { 7 } }; -int *y[] = { x[0], x[1], x[2], 0 }; - -main() -{ - int i, j; - - for (i = 0; y[i]; i++) { - for (j = 0; y[i][j]; j++) - printf(" %d", y[i][j]); - printf("\n"); - } - f(); - g(wordlist); - return 0; -} - -f() { - static char *keywords[] = {"if", "for", "else", "while", 0, }; - char **p; - - for (p = keywords; *p; p++) - printf("%s\n", *p); -} - -#ifdef NO_OLD_FUNC_DECL -void g(Word *p) -#else -g(p) -Word *p; -#endif -{ - int i; - - for ( ; p->codes[0]; p++) { - for (i = 0; i < sizeof p->codes/sizeof(p->codes[0]); i++) - printf("%d ", p->codes[i]); - printf("%s\n", p->name); - } - h(); -} - -h() -{ - int i; - - for (i = 0; i < sizeof(words)/sizeof(Word); i++) - printf("%d %d %d %s\n", words[i].codes[0], - words[i].codes[1], words[i].codes[2], - &words[i].name[0]); -} +/* + !!DESCRIPTION!! variable initialization + !!ORIGIN!! LCC 4.1 Testsuite + !!LICENCE!! own, freely distributeable for non-profit. read CPYRIGHT.LCC +*/ + +#include "common.h" +/* todo: add back conditional stuff here ! */ + +typedef struct { int codes[3]; char name[6]; } Word; + +#ifdef NO_IMPLICIT_FUNC_PROTOTYPES + +#ifdef NO_OLD_FUNC_DECL +f(); +void g(Word *p); +h(); +#else +f(); +g(); +h(); +#endif + +#endif + +/* +Word words[] = { + 1, 2, 3,"if", + { { 4, 5 }, { 'f', 'o', 'r' } }, + 6, 7, 8, {"else"}, + { { 9, 10, 11,}, 'w', 'h', 'i', 'l', 'e', }, + { 0 }, +}, *wordlist = words; +*/ + +Word words[] = { + {{1, 2, 3},"if"}, + { { 4, 5 }, { 'f', 'o', 'r' } }, + {{6, 7, 8}, "else"}, + { { 9, 10, 11}, {'w', 'h', 'i', 'l', 'e', }}, + {{ 0 }}, +}, *wordlist = words; + +/*int x[][5] = { 1, 2, 3, 4, 0, { 5, 6 }, { 7 } };*/ +int x[][5] = { {1, 2, 3, 4, 0 }, { 5, 6 }, { 7 } }; +int *y[] = { x[0], x[1], x[2], 0 }; + +main() +{ + int i, j; + + for (i = 0; y[i]; i++) { + for (j = 0; y[i][j]; j++) + printf(" %d", y[i][j]); + printf("\n"); + } + f(); + g(wordlist); + return 0; +} + +f() { + static char *keywords[] = {"if", "for", "else", "while", 0, }; + char **p; + + for (p = keywords; *p; p++) + printf("%s\n", *p); +} + +#ifdef NO_OLD_FUNC_DECL +void g(Word *p) +#else +g(p) +Word *p; +#endif +{ + int i; + + for ( ; p->codes[0]; p++) { + for (i = 0; i < sizeof p->codes/sizeof(p->codes[0]); i++) + printf("%d ", p->codes[i]); + printf("%s\n", p->name); + } + h(); +} + +h() +{ + int i; + + for (i = 0; i < sizeof(words)/sizeof(Word); i++) + printf("%d %d %d %s\n", words[i].codes[0], + words[i].codes[1], words[i].codes[2], + &words[i].name[0]); +} diff --git a/test/ref/pointer2.c b/test/ref/pointer2.c index d8c064ef3..29f9e3de4 100644 --- a/test/ref/pointer2.c +++ b/test/ref/pointer2.c @@ -1,112 +1,112 @@ -/* - !!DESCRIPTION!! pointer test - !!ORIGIN!! - !!LICENCE!! public domain -*/ - -#include "common.h" -#include <stdio.h> - -/* - check behaviour on incompletely declared arrays -*/ - -char i1[]; - -void test1(void) { -int a; - - a=sizeof(i1[0]); - printf("%04x - ",a); - if(sizeof(i1[0])==sizeof(char)) { - /* gcc gives size of element */ - printf("sizeof(i1[0]) gives size of element\n"); - } - if(sizeof(i1[0])==sizeof(char*)) { - printf("sizeof(i1[0]) gives size of pointer to element\n"); - } -} - -/* - check behaviour on string init -*/ - -char t1[]="abcde"; -char t2[]={"abcde"}; - -char *t3="abcde"; -char *t4={"abcde"}; - -void test2(void) { -char c1,c2,c3,c4; -int i,e=0; - for(i=0;i<5;i++){ - c1=t1[i];c2=t2[i];c3=t3[i];c4=t4[i]; -/* printf("%02x %02x %02x %02x\n",c1,c2,c3,c4); */ - printf("%c %c %c %c\n",c1,c2,c3,c4); - if(!((c1==c2)&(c1==c3)&(c1==c4))) e=1; - } - if(e) printf("test2 failed.\n"); - else printf("test2 ok.\n"); -} - -/* - check behaviour on extern-declarations inside functions -*/ - -typedef struct { - char *name; - void *func; -} A3; - -#ifdef NO_SLOPPY_STRUCT_INIT -A3 a3[] = { - { "test3", (void*) NULL }, - { "test3", (void*) NULL }, -}; -#else -/*gcc warning: missing braces around initializer (near initialization for `a3[0]') - this type of struct-initialization seems to be kinda common */ -A3 a3[] = { - "test3", (void*) NULL , - "test3", (void*) NULL , -}; -#endif - -void test3a(A3 *list, int number){ - printf("%s %d\n",list->name,number); -} - -static void test31(void) -{ - extern A3 a3[]; - test3a(a3, -1); -} - -#if 0 -/* this variation compiles and works with cc65, but gives an error with gcc :=P */ -static void test32(void) -{ - extern A3 *a3; - test3a(a3, -1); -} -#endif - -static void test30(void) -{ - test3a(a3, -1); -} - -/* - todo: add test on function pointers in the form of (*func)(arg) ... - cc65 seems to have problems here aswell ;/ -*/ - -int main(void) { - test1(); - test2(); - test30(); - test31(); -/* test32(); */ - return 0; -} +/* + !!DESCRIPTION!! pointer test + !!ORIGIN!! + !!LICENCE!! public domain +*/ + +#include "common.h" +#include <stdio.h> + +/* + check behaviour on incompletely declared arrays +*/ + +char i1[]; + +void test1(void) { +int a; + + a=sizeof(i1[0]); + printf("%04x - ",a); + if(sizeof(i1[0])==sizeof(char)) { + /* gcc gives size of element */ + printf("sizeof(i1[0]) gives size of element\n"); + } + if(sizeof(i1[0])==sizeof(char*)) { + printf("sizeof(i1[0]) gives size of pointer to element\n"); + } +} + +/* + check behaviour on string init +*/ + +char t1[]="abcde"; +char t2[]={"abcde"}; + +char *t3="abcde"; +char *t4={"abcde"}; + +void test2(void) { +char c1,c2,c3,c4; +int i,e=0; + for(i=0;i<5;i++){ + c1=t1[i];c2=t2[i];c3=t3[i];c4=t4[i]; +/* printf("%02x %02x %02x %02x\n",c1,c2,c3,c4); */ + printf("%c %c %c %c\n",c1,c2,c3,c4); + if(!((c1==c2)&(c1==c3)&(c1==c4))) e=1; + } + if(e) printf("test2 failed.\n"); + else printf("test2 ok.\n"); +} + +/* + check behaviour on extern-declarations inside functions +*/ + +typedef struct { + char *name; + void *func; +} A3; + +#ifdef NO_SLOPPY_STRUCT_INIT +A3 a3[] = { + { "test3", (void*) NULL }, + { "test3", (void*) NULL }, +}; +#else +/*gcc warning: missing braces around initializer (near initialization for `a3[0]') + this type of struct-initialization seems to be kinda common */ +A3 a3[] = { + "test3", (void*) NULL , + "test3", (void*) NULL , +}; +#endif + +void test3a(A3 *list, int number){ + printf("%s %d\n",list->name,number); +} + +static void test31(void) +{ + extern A3 a3[]; + test3a(a3, -1); +} + +#if 0 +/* this variation compiles and works with cc65, but gives an error with gcc :=P */ +static void test32(void) +{ + extern A3 *a3; + test3a(a3, -1); +} +#endif + +static void test30(void) +{ + test3a(a3, -1); +} + +/* + todo: add test on function pointers in the form of (*func)(arg) ... + cc65 seems to have problems here aswell ;/ +*/ + +int main(void) { + test1(); + test2(); + test30(); + test31(); +/* test32(); */ + return 0; +} diff --git a/test/ref/switch2.c b/test/ref/switch2.c index e75cfe71e..7a9bcecd7 100644 --- a/test/ref/switch2.c +++ b/test/ref/switch2.c @@ -1,262 +1,262 @@ -/* - !!DESCRIPTION!! switch test - !!ORIGIN!! - !!LICENCE!! public domain -*/ - -/*#define STANDALONE*/ - -#include <stdio.h> - +/* + !!DESCRIPTION!! switch test + !!ORIGIN!! + !!LICENCE!! public domain +*/ + +/*#define STANDALONE*/ + +#include <stdio.h> + void testlimits(int i) { - printf("%d:",i); - + printf("%d:",i); + switch(i) { - case -1: /* works */ - /* case 0xffff: */ /* 'range error' (-1) */ - - printf("-1\n"); - break; - /* max int */ - -/* case 0x7fff: */ /* works */ - case 32767: /* works */ - /* case 32768: */ /* 'range error' (correct for that one!) */ - - printf("max\n"); - break; - /* min int */ - - case -32768: /* 'warning. constant is long' */ - /* case 0x8000: */ /* 'range error' */ - /* case -32769: */ /* 'range error' (correct for that one!) */ - printf("min\n"); - break; - } - printf("\n"); -} - -void testdefault1(unsigned char i) { -/* we want a signed char */ -#ifdef REFCC - -#ifdef REFCC_UNSIGNED_CHARS -signed char k; -#else -char k; -#endif - -#else - -#ifdef UNSIGNED_CHARS -signed char k; -#else -char k; -#endif - -#endif - - for(;i<254;) { - k = i; - printf(">%d\n",i);i++; - switch(k) { - case 1: - break; - case 2: - break; - case 3: - break; - case 4: - break; - case 5: - break; - case 6: - break; - case 7: - break; - case 8: - break; - case 9: - break; - case 10: - break; - case 11: - break; - case 12: - break; - case 13: - break; - case 14: - break; - case 15: - break; - case 17: - break; - /* triggers bug ? */ - /* gcc warning: case label value exceeds maximum value for type */ - /* cc65 error: range error */ - - /* - case 170: - break; - */ - case 18: - break; - case 19: - break; - case 20: - break; - case 21: - break; - case 22: - break; - case 23: - break; - case 24: - switch(k) { - case 1: - break; - case 2: - break; - case 3: - break; - case 4: - case 5: - break; - case 6: - case 7: - break; - case 8: - case 9: - break; - } - break; - case 100: - break; - default: - printf(">>>default\n"); - /* triggers bug if this break; is missing? */ - /* break; */ - } - } -} - -void testdefault2(unsigned char i) { -/* we want a unsigned char */ -#ifdef REFCC - -#ifdef REFCC_UNSIGNED_CHARS -char k; -#else -unsigned char k; -#endif - -#else - -#ifdef UNSIGNED_CHARS -char k; -#else -unsigned char k; -#endif - -#endif - - for(;i<254;) { - k = i; - printf(">%d\n",i);i++; - switch(k) { - case 1: - break; - case 2: - break; - case 3: - break; - case 4: - break; - case 5: - break; - case 6: - break; - case 7: - break; - case 8: - break; - case 9: - break; - case 10: - break; - case 11: - break; - case 12: - break; - case 13: - break; - case 14: - break; - case 15: - break; - case 17: - break; - /* triggers bug ? */ - - case 170: - break; - - case 18: - break; - case 19: - break; - case 20: - break; - case 21: - break; - case 22: - break; - case 23: - break; - case 24: - switch(k) { - case 1: - break; - case 2: - break; - case 3: - break; - case 4: - case 5: - break; - case 6: - case 7: - break; - case 8: - case 9: - break; - } - break; - case 100: - break; - default: - printf(">>>default\n"); - /* triggers bug if this break; is missing? */ - /* break; */ - } - } + case -1: /* works */ + /* case 0xffff: */ /* 'range error' (-1) */ + + printf("-1\n"); + break; + /* max int */ + +/* case 0x7fff: */ /* works */ + case 32767: /* works */ + /* case 32768: */ /* 'range error' (correct for that one!) */ + + printf("max\n"); + break; + /* min int */ + + case -32768: /* 'warning. constant is long' */ + /* case 0x8000: */ /* 'range error' */ + /* case -32769: */ /* 'range error' (correct for that one!) */ + printf("min\n"); + break; + } + printf("\n"); +} + +void testdefault1(unsigned char i) { +/* we want a signed char */ +#ifdef REFCC + +#ifdef REFCC_UNSIGNED_CHARS +signed char k; +#else +char k; +#endif + +#else + +#ifdef UNSIGNED_CHARS +signed char k; +#else +char k; +#endif + +#endif + + for(;i<254;) { + k = i; + printf(">%d\n",i);i++; + switch(k) { + case 1: + break; + case 2: + break; + case 3: + break; + case 4: + break; + case 5: + break; + case 6: + break; + case 7: + break; + case 8: + break; + case 9: + break; + case 10: + break; + case 11: + break; + case 12: + break; + case 13: + break; + case 14: + break; + case 15: + break; + case 17: + break; + /* triggers bug ? */ + /* gcc warning: case label value exceeds maximum value for type */ + /* cc65 error: range error */ + + /* + case 170: + break; + */ + case 18: + break; + case 19: + break; + case 20: + break; + case 21: + break; + case 22: + break; + case 23: + break; + case 24: + switch(k) { + case 1: + break; + case 2: + break; + case 3: + break; + case 4: + case 5: + break; + case 6: + case 7: + break; + case 8: + case 9: + break; + } + break; + case 100: + break; + default: + printf(">>>default\n"); + /* triggers bug if this break; is missing? */ + /* break; */ + } + } +} + +void testdefault2(unsigned char i) { +/* we want a unsigned char */ +#ifdef REFCC + +#ifdef REFCC_UNSIGNED_CHARS +char k; +#else +unsigned char k; +#endif + +#else + +#ifdef UNSIGNED_CHARS +char k; +#else +unsigned char k; +#endif + +#endif + + for(;i<254;) { + k = i; + printf(">%d\n",i);i++; + switch(k) { + case 1: + break; + case 2: + break; + case 3: + break; + case 4: + break; + case 5: + break; + case 6: + break; + case 7: + break; + case 8: + break; + case 9: + break; + case 10: + break; + case 11: + break; + case 12: + break; + case 13: + break; + case 14: + break; + case 15: + break; + case 17: + break; + /* triggers bug ? */ + + case 170: + break; + + case 18: + break; + case 19: + break; + case 20: + break; + case 21: + break; + case 22: + break; + case 23: + break; + case 24: + switch(k) { + case 1: + break; + case 2: + break; + case 3: + break; + case 4: + case 5: + break; + case 6: + case 7: + break; + case 8: + case 9: + break; + } + break; + case 100: + break; + default: + printf(">>>default\n"); + /* triggers bug if this break; is missing? */ + /* break; */ + } + } } int main(void) { - testlimits(32767); - testlimits(-32768); - testlimits(-1); - - testdefault1(1); - testdefault1(2); - testdefault1(3); - testdefault1(4); - - testdefault2(1); - testdefault2(2); - testdefault2(3); - testdefault2(4); - - return 0; -} + testlimits(32767); + testlimits(-32768); + testlimits(-1); + + testdefault1(1); + testdefault1(2); + testdefault1(3); + testdefault1(4); + + testdefault2(1); + testdefault2(2); + testdefault2(3); + testdefault2(4); + + return 0; +} diff --git a/test/ref/varargs.c b/test/ref/varargs.c index 11fd33b38..3d61fdbd0 100644 --- a/test/ref/varargs.c +++ b/test/ref/varargs.c @@ -1,105 +1,105 @@ /* - !!DESCRIPTION!! varargs test - !!ORIGIN!! - !!LICENCE!! public domain -*/ - -#include <stdlib.h> -#include <stdio.h> -#include <stdarg.h> - -void chk0(char *format,...); -void chk1(int fd,char *format,...); - -#if 0 -// old workaround for broken varargs - -void chk0(char *format,...){ - __asm__ ("pha"); // save argument size - { -//va_list ap; -char *ap; -char *_format; -static char string[0x100]; - -// va_start(ap,format); - __asm__ ("pla"); // restore argument size - __asm__ ("ldx #$00"); // clear hibyte of AX - ap=__AX__; - ap+=(char*)&format; - // get value of format - ap-=2; - _format=*((char**)ap); - -// vsprintf(string,format,ap); - vsprintf(&string[0],_format,ap); - printf("format:%s,string:%s\n",_format,string); -// va_end(ap); - - } -} - -void chk1(int fd,char *format,...){ - __asm__ ("pha"); // save argument size - { -//va_list ap; -char *ap; -char *_format; -int _fd; -static char string[0x100]; - -// va_start(ap,format); - __asm__ ("pla"); // restore argument size - __asm__ ("ldx #$00"); // clear hibyte of AX - ap=__AX__; - ap+=(char*)&format; - // get value of fd - ap-=2; - _fd=*((int*)ap); - // get value of format - ap-=2; - _format=*((char**)ap); - -// vsprintf(string,format,ap); - vsprintf(&string[0],_format,ap); - printf("fd:%d,format:%s,string:%s\n",_fd,_format,string); -// va_end(ap); - - } -} - -#endif - -void chk0(char *format,...){ -va_list ap; -static char string[0x100]; - va_start(ap,format); - vsprintf(string,format,ap); - printf("format:%s,string:%s\n",format,string); - va_end(ap); -} - -void chk1(int fd,char *format,...){ -va_list ap; -static char string[0x100]; - - va_start(ap,format); - - vsprintf(string,format,ap); - printf("fd:%d,format:%s,string:%s\n",fd,format,string); - va_end(ap); + !!DESCRIPTION!! varargs test + !!ORIGIN!! + !!LICENCE!! public domain +*/ + +#include <stdlib.h> +#include <stdio.h> +#include <stdarg.h> + +void chk0(char *format,...); +void chk1(int fd,char *format,...); + +#if 0 +// old workaround for broken varargs + +void chk0(char *format,...){ + __asm__ ("pha"); // save argument size + { +//va_list ap; +char *ap; +char *_format; +static char string[0x100]; + +// va_start(ap,format); + __asm__ ("pla"); // restore argument size + __asm__ ("ldx #$00"); // clear hibyte of AX + ap=__AX__; + ap+=(char*)&format; + // get value of format + ap-=2; + _format=*((char**)ap); + +// vsprintf(string,format,ap); + vsprintf(&string[0],_format,ap); + printf("format:%s,string:%s\n",_format,string); +// va_end(ap); + + } } -int main(int argc,char **argv) { - printf("varargs test\n"); - - printf("\nchk0/0:\n");chk0("chk0 %s","arg0"); - printf("\nchk0/1:\n");chk0("chk0 %s %s","arg0","arg1"); - printf("\nchk0/2:\n");chk0("chk0 %s %s %s","arg0","arg1","arg2"); - - printf("\nchk1/0:\n");chk1(0xfd,"chk1 %s","arg0"); - printf("\nchk1/1:\n");chk1(0xfd,"chk1 %s %s","arg0","arg1"); - printf("\nchk1/2:\n");chk1(0xfd,"chk1 %s %s %s","arg0","arg1","arg2"); - +void chk1(int fd,char *format,...){ + __asm__ ("pha"); // save argument size + { +//va_list ap; +char *ap; +char *_format; +int _fd; +static char string[0x100]; + +// va_start(ap,format); + __asm__ ("pla"); // restore argument size + __asm__ ("ldx #$00"); // clear hibyte of AX + ap=__AX__; + ap+=(char*)&format; + // get value of fd + ap-=2; + _fd=*((int*)ap); + // get value of format + ap-=2; + _format=*((char**)ap); + +// vsprintf(string,format,ap); + vsprintf(&string[0],_format,ap); + printf("fd:%d,format:%s,string:%s\n",_fd,_format,string); +// va_end(ap); + + } +} + +#endif + +void chk0(char *format,...){ +va_list ap; +static char string[0x100]; + va_start(ap,format); + vsprintf(string,format,ap); + printf("format:%s,string:%s\n",format,string); + va_end(ap); +} + +void chk1(int fd,char *format,...){ +va_list ap; +static char string[0x100]; + + va_start(ap,format); + + vsprintf(string,format,ap); + printf("fd:%d,format:%s,string:%s\n",fd,format,string); + va_end(ap); +} + +int main(int argc,char **argv) { + printf("varargs test\n"); + + printf("\nchk0/0:\n");chk0("chk0 %s","arg0"); + printf("\nchk0/1:\n");chk0("chk0 %s %s","arg0","arg1"); + printf("\nchk0/2:\n");chk0("chk0 %s %s %s","arg0","arg1","arg2"); + + printf("\nchk1/0:\n");chk1(0xfd,"chk1 %s","arg0"); + printf("\nchk1/1:\n");chk1(0xfd,"chk1 %s %s","arg0","arg1"); + printf("\nchk1/2:\n");chk1(0xfd,"chk1 %s %s %s","arg0","arg1","arg2"); + return 0; -} +} diff --git a/test/ref/yacc.c b/test/ref/yacc.c index 5768f80d0..ab72e24c0 100644 --- a/test/ref/yacc.c +++ b/test/ref/yacc.c @@ -562,13 +562,13 @@ yylook() } # ifdef LEXDEBUG - if((*(lsp-1)-yysvec-1)<0) + if (lsp == yylstate) { fprintf(yyout,"yylook: stopped (end)\n"); } else { - fprintf(yyout,"yylook: stopped at %d with\n",*(lsp-1)-yysvec-1); + fprintf(yyout,"yylook: stopped at %d with:\n",*(lsp-1)-(yysvec+1)); } # endif while (lsp-- > yylstate) @@ -594,7 +594,7 @@ yylook() yyleng = yylastch-yytext+1; yytext[yyleng] = 0; # ifdef LEXDEBUG - fprintf(yyout,"\nyylook: match action %d\n",*yyfnd); + fprintf(yyout,"yylook: match action %d\n",*yyfnd); fprintf(yyout,"yylook: done loops: %d\n",testbreak); # endif return(*yyfnd++); diff --git a/test/val/Makefile b/test/val/Makefile index 4ad8160ef..fe194d892 100644 --- a/test/val/Makefile +++ b/test/val/Makefile @@ -1,70 +1,71 @@ - -# makefile for the regression tests that return an error code on failure +# Makefile for the regression tests that return an error code on failure ifneq ($(shell echo),) - CMD_EXE := 1 + CMD_EXE = 1 endif ifdef CMD_EXE - DEL = -del /f $(subst /,\,$1) + S = $(subst /,\,/) + NULLDEV = nul: + MKDIR = mkdir $(subst /,\,$1) + RMDIR = -rmdir /s /q $(subst /,\,$1) + DEL = del /f $(subst /,\,$1) else + S = / + NULLDEV = /dev/null + MKDIR = mkdir -p $1 + RMDIR = $(RM) -r $1 DEL = $(RM) $1 endif -CC65FLAGS := -t sim6502 -SIM65FLAGS := -x 200000000 +ifdef QUIET + .SILENT: + NULLOUT = >$(NULLDEV) + NULLERR = 2>$(NULLDEV) +endif -CL65 := $(if $(wildcard ../../bin/cl65*),../../bin/cl65,cl65) -SIM65 := $(if $(wildcard ../../bin/sim65*),../../bin/sim65,sim65) +SIM65FLAGS = -x 200000000 -WORKDIR := ../../testwrk +CL65 := $(if $(wildcard ../../bin/cl65*),..$S..$Sbin$Scl65,cl65) +SIM65 := $(if $(wildcard ../../bin/sim65*),..$S..$Sbin$Ssim65,sim65) + +WORKDIR = ../../testwrk/val + +OPTIONS = g O Os Osi Osir Osr Oi Oir Or .PHONY: all clean SOURCES := $(wildcard *.c) -TESTS := $(foreach option,. .o. .os. .osi. .osir. .oi. .oir. .or.,$(SOURCES:%.c=$(WORKDIR)/%$(option)prg)) +TESTS = $(foreach option,$(OPTIONS),$(SOURCES:%.c=$(WORKDIR)/%.$(option).6502.prg)) +TESTS += $(foreach option,$(OPTIONS),$(SOURCES:%.c=$(WORKDIR)/%.$(option).65c02.prg)) all: $(TESTS) +$(WORKDIR): + $(call MKDIR,$(WORKDIR)) + # Some files have "K & R"-style syntax. Therefore, some forward # function-declarations don't match the later function definitions. # Those programs fail when fastcall is used; but, the cdecl calling convention # tolerates those conflicts. Therefore, make their functions default to cdecl. # -$(WORKDIR)/cq4%prg $(WORKDIR)/cq71.%rg $(WORKDIR)/cq81%prg $(WORKDIR)/cq84%prg: CC65FLAGS += -Wc --all-cdecl +$(WORKDIR)/cq4.%.prg \ +$(WORKDIR)/cq71.%.prg \ +$(WORKDIR)/cq81.%.prg \ +$(WORKDIR)/cq84.%.prg: CC65FLAGS += -Wc --all-cdecl -$(WORKDIR)/%.prg: %.c - $(CL65) $(CC65FLAGS) $< -o $@ - $(SIM65) $(SIM65FLAGS) $@ +define PRG_template -$(WORKDIR)/%.o.prg: %.c - $(CL65) -O $(CC65FLAGS) $< -o $@ - $(SIM65) $(SIM65FLAGS) $@ +$(WORKDIR)/%.$1.$2.prg: %.c | $(WORKDIR) + $(if $(QUIET),echo val/$$*.$1.$2.prg) + $(CL65) -t sim$2 $$(CC65FLAGS) -$1 -o $$@ $$< $(NULLERR) + $(SIM65) $(SIM65FLAGS) $$@ $(NULLOUT) -$(WORKDIR)/%.os.prg: %.c - $(CL65) -Os $(CC65FLAGS) $< -o $@ - $(SIM65) $(SIM65FLAGS) $@ +endef # PRG_template -$(WORKDIR)/%.osi.prg: %.c - $(CL65) -Osi $(CC65FLAGS) $< -o $@ - $(SIM65) $(SIM65FLAGS) $@ - -$(WORKDIR)/%.osir.prg: %.c - $(CL65) -Osir $(CC65FLAGS) $< -o $@ - $(SIM65) $(SIM65FLAGS) $@ - -$(WORKDIR)/%.oi.prg: %.c - $(CL65) -Oi $(CC65FLAGS) $< -o $@ - $(SIM65) $(SIM65FLAGS) $@ - -$(WORKDIR)/%.oir.prg: %.c - $(CL65) -Oir $(CC65FLAGS) $< -o $@ - $(SIM65) $(SIM65FLAGS) $@ - -$(WORKDIR)/%.or.prg: %.c - $(CL65) -Or $(CC65FLAGS) $< -o $@ - $(SIM65) $(SIM65FLAGS) $@ +$(foreach option,$(OPTIONS),$(eval $(call PRG_template,$(option),6502))) +$(foreach option,$(OPTIONS),$(eval $(call PRG_template,$(option),65c02))) clean: - @$(call DEL,$(TESTS)) + @$(call RMDIR,$(WORKDIR)) @$(call DEL,$(SOURCES:.c=.o)) diff --git a/test/val/bss-name-decl.c b/test/val/bss-name-decl.c new file mode 100644 index 000000000..9a535844e --- /dev/null +++ b/test/val/bss-name-decl.c @@ -0,0 +1,22 @@ +/* + !!DESCRIPTION!! bss-name pragma not affecting declarations + !!ORIGIN!! cc65 regression tests + !!LICENCE!! Public Domain + !!AUTHOR!! Piotr Fusik +*/ + +/* + see: https://github.com/cc65/cc65/issues/409 +*/ + +#pragma bss-name (push,"ZEROPAGE") + +char n; /* only a declaration because followed by definition */ +char n = 1; /* not BSS */ + +#pragma bss-name (pop) + +int main(void) +{ + return (unsigned) &n >= 0x100 ? 0 : 1; +} diff --git a/test/val/bss-name.c b/test/val/bss-name.c new file mode 100644 index 000000000..f0ad7111e --- /dev/null +++ b/test/val/bss-name.c @@ -0,0 +1,21 @@ +/* + !!DESCRIPTION!! bss-name pragma + !!ORIGIN!! cc65 regression tests + !!LICENCE!! Public Domain + !!AUTHOR!! Piotr Fusik +*/ + +/* + see: https://github.com/cc65/cc65/issues/409 +*/ + +#pragma bss-name (push,"ZEROPAGE") + +char zp_var; + +#pragma bss-name (pop) + +int main(void) +{ + return (unsigned) &zp_var < 0x100 ? 0 : 1; +} diff --git a/test/val/atoi-test.c b/test/val/lib_common_atoi.c similarity index 100% rename from test/val/atoi-test.c rename to test/val/lib_common_atoi.c diff --git a/test/val/lib_common_memmove.c b/test/val/lib_common_memmove.c new file mode 100644 index 000000000..6b2273e78 --- /dev/null +++ b/test/val/lib_common_memmove.c @@ -0,0 +1,58 @@ +#include <string.h> +#include "unittest.h" + +#define BufferSize 384 // test correct page passing (>256, multiple of 128 here) + +static char Buffer[BufferSize+3]; // +1 to move up (and down) + + +TEST +{ + unsigned i, v; + char* p; + + for (i=0; i < BufferSize; ++i) + Buffer[i+1] = (i%128); + + Buffer[0] = 255; // to check if start position is untouched + Buffer[BufferSize+2] = 255; // to check if end position is untouched + + // copy upwards + p = memmove(Buffer+2, Buffer+1, BufferSize); + + // check buffer consistency before target + ASSERT_AreEqual(255, (unsigned)Buffer[0], "%u", "Unexpected value before range!"); + + // check buffer consistency at starting point + ASSERT_AreEqual(0, (unsigned)Buffer[1], "%u", "Unexpected value at range start!"); + + // check buffer consistency after range + ASSERT_AreEqual(255, (unsigned)Buffer[BufferSize+2], "%u", "Unexpected value after range!"); + + // check buffer values + for (i=0; i < BufferSize; ++i) + { + ASSERT_AreEqual(i%128, (unsigned)Buffer[i+2], "%u", "Unexpected value in buffer at position %u!" COMMA i+2); + } + + v = Buffer[BufferSize+1]; // rember value of first untouched end-byte + + // copy downwards + p = memmove(Buffer+1, Buffer+2, BufferSize); + + // check buffer consistency before target + ASSERT_AreEqual(255, (unsigned)Buffer[0], "%u", "Unexpected value before range!"); + + // check buffer consistency at end point + ASSERT_AreEqual(v, (unsigned)Buffer[BufferSize+1], "%u", "Unexpected value at range end!"); + + // check buffer consistency after range + ASSERT_AreEqual(255, (unsigned)Buffer[BufferSize+2], "%u", "Unexpected value after range!"); + + // check buffer values + for (i=0; i < BufferSize; ++i) + { + ASSERT_AreEqual(i%128, (unsigned)Buffer[i+1], "%u", "Unexpected value in buffer at position %u!" COMMA i+1); + } +} +ENDTEST diff --git a/test/val/lib_common_strcat.c b/test/val/lib_common_strcat.c new file mode 100644 index 000000000..1872053a4 --- /dev/null +++ b/test/val/lib_common_strcat.c @@ -0,0 +1,54 @@ +#include <string.h> +#include "unittest.h" + +#define SourceStringSize 257 // test correct page passing (>256) + +static char SourceString[SourceStringSize+1]; // +1 room for terminating null +static char DestinationString[2*SourceStringSize+1]; // will contain two times the source buffer + + +TEST +{ + unsigned i,j; + char* p; + + for (i=0; i < SourceStringSize; ++i) + SourceString[i] = (i%128)+1; + + SourceString[i] = 0; + + ASSERT_AreEqual(SourceStringSize, strlen(SourceString), "%u", "Source string initialization or 'strlen()' problem!"); + + /* Ensure empty destination string */ + DestinationString[0] = 0; + + ASSERT_AreEqual(0, strlen(DestinationString), "%u", "Destination string initialization or 'strlen()' problem!"); + + /* Test concatenation to empty buffer */ + + strcat(DestinationString, SourceString); + + ASSERT_AreEqual(SourceStringSize, strlen(DestinationString), "%u", "Unexpected string length while string concatenation to empty buffer!"); + + /* Test concatenation to non empty buffer */ + + p = strcat(DestinationString, SourceString); + + ASSERT_AreEqual(2*SourceStringSize, strlen(DestinationString), "%u", "Unexpected string length while string concatenation to non-empty buffer!"); + + /* Test return value */ + + ASSERT_IsTrue(p == DestinationString,"Invalid return value!"); + + /* Test contents */ + + for(j=0; j <2; ++j) + for(i=0; i < SourceStringSize; ++i) + { + unsigned position = j*SourceStringSize+i; + unsigned current = DestinationString[position]; + unsigned expected = (i%128)+1; + ASSERT_AreEqual(expected, current, "%u", "Unexpected destination buffer contents at position %u!\n" COMMA position); + } +} +ENDTEST diff --git a/testcode/lib/strchr-test.c b/test/val/lib_common_strchr.c similarity index 50% rename from testcode/lib/strchr-test.c rename to test/val/lib_common_strchr.c index 7aba1de1e..a48d287e5 100644 --- a/testcode/lib/strchr-test.c +++ b/test/val/lib_common_strchr.c @@ -1,7 +1,5 @@ -#include <stdio.h> -#include <stdlib.h> #include <string.h> - +#include "unittest.h" /* Test string. Must NOT have duplicate characters! */ @@ -11,49 +9,34 @@ static char Found[256]; -int main (void) +TEST { unsigned Len; unsigned I; char* P; - /* Print a header */ - printf ("strchr(): "); - /* Get the length of the string */ Len = strlen (S); /* Search for all characters in the string, including the terminator */ - for (I = 0; I < Len+1; ++I) { - + for (I = 0; I < Len+1; ++I) + { /* Search for this char */ P = strchr (S, S[I]); /* Check if we found it */ - if (P == 0 || (P - S) != I) { - printf ("Failed for code 0x%02X, offset %u!\n", S[I], I); - printf ("P = %04X offset = %04X\n", P, P-S); - exit (EXIT_FAILURE); - } - + ASSERT_IsFalse(P == 0 || (P - S) != I, "For code 0x%02X, offset %u!\nP = %04X offset = %04X\n" COMMA S[I] COMMA I COMMA P COMMA P-S); /* Mark the char as checked */ Found[S[I]] = 1; } /* Search for all other characters and make sure they aren't found */ - for (I = 0; I < 256; ++I) { - if (Found[I] == 0) { - if (strchr (S, (char)I) != 0) { - printf ("Failed for code 0x%02X\n", I); - exit (EXIT_FAILURE); - } + for (I = 0; I < 256; ++I) + { + if (Found[I] == 0) + { + ASSERT_IsFalse(strchr (S, (char)I), "Failed for code 0x%02X\n" COMMA I); } } - - /* Test passed */ - printf ("Passed\n"); - return EXIT_SUCCESS; } - - - +ENDTEST diff --git a/test/val/lib_common_strcspn.c b/test/val/lib_common_strcspn.c new file mode 100644 index 000000000..f289ddb95 --- /dev/null +++ b/test/val/lib_common_strcspn.c @@ -0,0 +1,25 @@ +#include <string.h> +#include "unittest.h" + +#define EstimatedStringSize 384 // test correct page passing (>256) + +static char EstimatedString[EstimatedStringSize+1]; // +1 room for terminating null +static char* EmptyTestChars=""; // strlen equivalent... +static char* TestChars="1234567890"; // we like to find numbers + + +TEST +{ + unsigned i; + + for (i=0; i < EstimatedStringSize; ++i) + EstimatedString[i] = (i%26)+'A'; // put ABCD... into the string to be estimated + + ASSERT_AreEqual(strlen(EstimatedString), strcspn(EstimatedString, TestChars), "%u", "Unxpected position returned for non-participant case!"); + + EstimatedString[EstimatedStringSize/2] = TestChars[strlen(TestChars-1)]; + ASSERT_AreEqual(EstimatedStringSize/2, strcspn(EstimatedString, TestChars), "%u", "Unxpected position returned for participant case!"); + + ASSERT_AreEqual(strlen(EstimatedString), strcspn(EstimatedString, EmptyTestChars), "%u", "Unxpected position returned for empty test case!"); +} +ENDTEST diff --git a/test/val/lib_common_strncat.c b/test/val/lib_common_strncat.c new file mode 100644 index 000000000..a6f92ac05 --- /dev/null +++ b/test/val/lib_common_strncat.c @@ -0,0 +1,52 @@ +#include <string.h> +#include "unittest.h" + +#define SourceStringSize 384 // test correct page passing (>256, multiple of 128 here) + +static char SourceString[SourceStringSize+1]; // +1 room for terminating null +static char DestinationString[2*SourceStringSize+1]; // will contain two times the source buffer + + +TEST +{ + unsigned i; + char* p; + + for (i=0; i < SourceStringSize; ++i) + SourceString[i] = (i%128)+1; + + SourceString[i] = 0; + + ASSERT_AreEqual(SourceStringSize, strlen(SourceString), "%u", "Source string initialization or 'strlen()' problem!"); + + /* Ensure empty destination string */ + DestinationString[0] = 0; + + ASSERT_AreEqual(0, strlen(DestinationString), "%u", "Destination string initialization or 'strlen()' problem!"); + + /* Test "unlimted" concatenation to empty buffer */ + + strncat(DestinationString, SourceString, 1024); + + ASSERT_AreEqual(SourceStringSize, strlen(DestinationString), "%u", "Unexpected string length while string concatenation to empty buffer!"); + + /* Test limited concatenation to non empty buffer */ + + p = strncat(DestinationString, SourceString, 128); + + ASSERT_AreEqual(SourceStringSize+128, strlen(DestinationString), "%u", "Unexpected string length while string concatenation to non-empty buffer!"); + + /* Test return value */ + + ASSERT_IsTrue(p == DestinationString, "Invalid return value!"); + + /* Test contents */ + + for(i=0; i < strlen(DestinationString); ++i) + { + unsigned current = DestinationString[i]; + unsigned expected = (i%128)+1; + ASSERT_AreEqual(expected, current, "%u", "Unexpected destination buffer contents at position %u!\n" COMMA i); + } +} +ENDTEST diff --git a/test/val/strtol-test.c b/test/val/lib_common_strol.c similarity index 100% rename from test/val/strtol-test.c rename to test/val/lib_common_strol.c diff --git a/test/val/lib_common_strrchr.c b/test/val/lib_common_strrchr.c new file mode 100644 index 000000000..a72c44db9 --- /dev/null +++ b/test/val/lib_common_strrchr.c @@ -0,0 +1,38 @@ +#include <string.h> +#include "unittest.h" + +static char TestString[] = "01234567890123456789"; // two times the same string +static char Found[256]; + +TEST +{ + unsigned len; + unsigned i; + char* p; + + len = strlen(TestString)/2; // test only one half of the string, to find last appearance + + /* Search for all characters in the string, including the terminator */ + for (i = 0; i < len; ++i) + { + /* Search for this char */ + p = strrchr (TestString, TestString[i]); + ASSERT_AreEqual(i+len, p-TestString, "%u", "Unexpected location of character '%c' found!" COMMA TestString[i]); + + /* Mark the char as checked */ + Found[TestString[i]] = 1; + } + + /* Search for all other characters and make sure they aren't found */ + for (i = 0; i < 256; ++i) + { + if (!Found[i]) + { + p = strrchr (TestString, i); + ASSERT_IsFalse(p, "Unexpected location of character '%c' found!" COMMA TestString[i]); + } + } +} +ENDTEST + + diff --git a/test/val/lib_common_strspn.c b/test/val/lib_common_strspn.c new file mode 100644 index 000000000..96a006469 --- /dev/null +++ b/test/val/lib_common_strspn.c @@ -0,0 +1,24 @@ +#include <string.h> +#include "unittest.h" + +#define EstimatedStringSize 384 // test correct page passing (>256) + +static char EstimatedString[EstimatedStringSize+1]; // +1 room for terminating null +static char* EmptyTestChars=""; // empty test case... +static char* TestChars="1234567890"; // we like to find numbers + +TEST +{ + unsigned i; + + for (i=0; i < EstimatedStringSize; ++i) + EstimatedString[i] = (i%10)+'0'; // put 0123... into the string to be estimated + + ASSERT_AreEqual(strlen(EstimatedString), strspn(EstimatedString, TestChars), "%u", "Unxpected position returned for all participant case!"); + + EstimatedString[EstimatedStringSize/2] = 'X'; + ASSERT_AreEqual(EstimatedStringSize/2, strspn(EstimatedString, TestChars), "%u", "Unxpected position returned for breaking case!"); + + ASSERT_AreEqual(0, strspn(EstimatedString, EmptyTestChars), "%u", "Unxpected position returned for empty test case!"); +} +ENDTEST diff --git a/test/val/strtoul-test.c b/test/val/lib_common_strtoul.c similarity index 100% rename from test/val/strtoul-test.c rename to test/val/lib_common_strtoul.c diff --git a/test/val/lz4.c b/test/val/lz4.c new file mode 100644 index 000000000..dceefbfcc --- /dev/null +++ b/test/val/lz4.c @@ -0,0 +1,669 @@ +/* + !!DESCRIPTION!! lz4 decompression + !!ORIGIN!! cc65 regression tests + !!LICENCE!! BSD 2-clause + !!AUTHOR!! Lauri Kasanen +*/ + +#include <zlib.h> +#include <stdio.h> +#include <lz4.h> + +/* The sample data is the original lz4.h, compressed with lz4 hc */ +static const unsigned char compressed[] = { +0xf0, 0x1a, 0x2f, 0x2a, 0x0a, 0x20, 0x20, 0x20, 0x4c, 0x5a, 0x34, 0x20, +0x2d, 0x20, 0x46, 0x61, 0x73, 0x74, 0x20, 0x4c, 0x5a, 0x20, 0x63, 0x6f, +0x6d, 0x70, 0x72, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x61, 0x6c, +0x67, 0x6f, 0x72, 0x69, 0x74, 0x68, 0x6d, 0x27, 0x00, 0xb0, 0x48, 0x65, +0x61, 0x64, 0x65, 0x72, 0x20, 0x46, 0x69, 0x6c, 0x65, 0x0f, 0x00, 0xf0, +0x17, 0x43, 0x6f, 0x70, 0x79, 0x72, 0x69, 0x67, 0x68, 0x74, 0x20, 0x28, +0x43, 0x29, 0x20, 0x32, 0x30, 0x31, 0x31, 0x2d, 0x32, 0x30, 0x31, 0x35, +0x2c, 0x20, 0x59, 0x61, 0x6e, 0x6e, 0x20, 0x43, 0x6f, 0x6c, 0x6c, 0x65, +0x74, 0x2e, 0x0a, 0x2a, 0x00, 0xf2, 0x22, 0x42, 0x53, 0x44, 0x20, 0x32, +0x2d, 0x43, 0x6c, 0x61, 0x75, 0x73, 0x65, 0x20, 0x4c, 0x69, 0x63, 0x65, +0x6e, 0x73, 0x65, 0x20, 0x28, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, +0x77, 0x77, 0x77, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x73, 0x6f, 0x75, 0x72, +0x63, 0x65, 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x6c, 0x23, 0x00, 0x63, 0x73, +0x2f, 0x62, 0x73, 0x64, 0x2d, 0x0d, 0x00, 0x51, 0x2e, 0x70, 0x68, 0x70, +0x29, 0x4e, 0x00, 0xb1, 0x52, 0x65, 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, +0x62, 0x75, 0x74, 0xa3, 0x00, 0x30, 0x6e, 0x64, 0x20, 0x58, 0x00, 0x32, +0x69, 0x6e, 0x20, 0x43, 0x00, 0x01, 0x12, 0x00, 0xf1, 0x06, 0x62, 0x69, +0x6e, 0x61, 0x72, 0x79, 0x20, 0x66, 0x6f, 0x72, 0x6d, 0x73, 0x2c, 0x20, +0x77, 0x69, 0x74, 0x68, 0x20, 0x6f, 0x72, 0x08, 0x00, 0x30, 0x6f, 0x75, +0x74, 0x46, 0x00, 0x80, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x63, 0x61, +0x44, 0x00, 0xf0, 0x22, 0x2c, 0x20, 0x61, 0x72, 0x65, 0x20, 0x70, 0x65, +0x72, 0x6d, 0x69, 0x74, 0x74, 0x65, 0x64, 0x20, 0x70, 0x72, 0x6f, 0x76, +0x69, 0x64, 0x65, 0x64, 0x20, 0x74, 0x68, 0x61, 0x74, 0x20, 0x74, 0x68, +0x65, 0x20, 0x66, 0x6f, 0x6c, 0x6c, 0x6f, 0x77, 0x69, 0x6e, 0x67, 0x20, +0x63, 0x6f, 0x6e, 0x64, 0x69, 0x35, 0x00, 0x10, 0x73, 0x35, 0x00, 0x01, +0x4a, 0x00, 0x31, 0x65, 0x74, 0x3a, 0x99, 0x00, 0x00, 0x01, 0x00, 0x1b, +0x2a, 0x9f, 0x00, 0x44, 0x73, 0x20, 0x6f, 0x66, 0x98, 0x00, 0xf1, 0x01, +0x63, 0x6f, 0x64, 0x65, 0x20, 0x6d, 0x75, 0x73, 0x74, 0x20, 0x72, 0x65, +0x74, 0x61, 0x69, 0x6e, 0x5a, 0x00, 0x40, 0x61, 0x62, 0x6f, 0x76, 0x1b, +0x00, 0x03, 0x4c, 0x01, 0x00, 0x48, 0x00, 0xf0, 0x02, 0x6e, 0x6f, 0x74, +0x69, 0x63, 0x65, 0x2c, 0x20, 0x74, 0x68, 0x69, 0x73, 0x20, 0x6c, 0x69, +0x73, 0x74, 0x44, 0x00, 0x08, 0x78, 0x00, 0x2b, 0x6e, 0x64, 0x95, 0x00, +0xbf, 0x64, 0x69, 0x73, 0x63, 0x6c, 0x61, 0x69, 0x6d, 0x65, 0x72, 0x2e, +0x89, 0x00, 0x07, 0x28, 0x69, 0x6e, 0x16, 0x01, 0x04, 0x89, 0x00, 0x76, +0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x65, 0x8c, 0x00, 0x00, 0x41, 0x00, +0x05, 0x8f, 0x00, 0x0f, 0x8c, 0x00, 0x2a, 0x00, 0x4a, 0x00, 0x03, 0xe6, +0x00, 0x94, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x61, 0xb3, +0x01, 0xf6, 0x04, 0x2f, 0x6f, 0x72, 0x20, 0x6f, 0x74, 0x68, 0x65, 0x72, +0x20, 0x6d, 0x61, 0x74, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x73, 0x77, 0x01, +0x01, 0xaf, 0x01, 0x21, 0x74, 0x68, 0x8b, 0x00, 0x08, 0xc4, 0x00, 0x02, +0x4e, 0x02, 0xf0, 0x34, 0x54, 0x48, 0x49, 0x53, 0x20, 0x53, 0x4f, 0x46, +0x54, 0x57, 0x41, 0x52, 0x45, 0x20, 0x49, 0x53, 0x20, 0x50, 0x52, 0x4f, +0x56, 0x49, 0x44, 0x45, 0x44, 0x20, 0x42, 0x59, 0x20, 0x54, 0x48, 0x45, +0x20, 0x43, 0x4f, 0x50, 0x59, 0x52, 0x49, 0x47, 0x48, 0x54, 0x20, 0x48, +0x4f, 0x4c, 0x44, 0x45, 0x52, 0x53, 0x20, 0x41, 0x4e, 0x44, 0x20, 0x43, +0x4f, 0x4e, 0x54, 0x52, 0x49, 0x42, 0x55, 0x54, 0x4f, 0x52, 0x53, 0x47, +0x00, 0x71, 0x22, 0x41, 0x53, 0x20, 0x49, 0x53, 0x22, 0x1c, 0x00, 0xf1, +0x26, 0x41, 0x4e, 0x59, 0x20, 0x45, 0x58, 0x50, 0x52, 0x45, 0x53, 0x53, +0x20, 0x4f, 0x52, 0x20, 0x49, 0x4d, 0x50, 0x4c, 0x49, 0x45, 0x44, 0x20, +0x57, 0x41, 0x52, 0x52, 0x41, 0x4e, 0x54, 0x49, 0x45, 0x53, 0x2c, 0x20, +0x49, 0x4e, 0x43, 0x4c, 0x55, 0x44, 0x49, 0x4e, 0x47, 0x2c, 0x20, 0x42, +0x55, 0x54, 0x20, 0x4e, 0x4f, 0x54, 0x3a, 0x03, 0xa1, 0x49, 0x4d, 0x49, +0x54, 0x45, 0x44, 0x20, 0x54, 0x4f, 0x2c, 0x7b, 0x00, 0x0e, 0x3a, 0x00, +0xf1, 0x04, 0x20, 0x4f, 0x46, 0x20, 0x4d, 0x45, 0x52, 0x43, 0x48, 0x41, +0x4e, 0x54, 0x41, 0x42, 0x49, 0x4c, 0x49, 0x54, 0x59, 0x73, 0x00, 0x40, +0x46, 0x49, 0x54, 0x4e, 0x6f, 0x00, 0x30, 0x46, 0x4f, 0x52, 0x49, 0x00, +0xf0, 0x06, 0x41, 0x20, 0x50, 0x41, 0x52, 0x54, 0x49, 0x43, 0x55, 0x4c, +0x41, 0x52, 0x20, 0x50, 0x55, 0x52, 0x50, 0x4f, 0x53, 0x45, 0x20, 0xe0, +0x00, 0xfa, 0x0e, 0x44, 0x49, 0x53, 0x43, 0x4c, 0x41, 0x49, 0x4d, 0x45, +0x44, 0x2e, 0x20, 0x49, 0x4e, 0x20, 0x4e, 0x4f, 0x20, 0x45, 0x56, 0x45, +0x4e, 0x54, 0x20, 0x53, 0x48, 0x41, 0x4c, 0x4c, 0xef, 0x00, 0x00, 0x48, +0x00, 0x50, 0x4f, 0x57, 0x4e, 0x45, 0x52, 0xc4, 0x00, 0x08, 0xef, 0x00, +0xa0, 0x20, 0x42, 0x45, 0x20, 0x4c, 0x49, 0x41, 0x42, 0x4c, 0x45, 0x6f, +0x00, 0x01, 0xee, 0x00, 0x60, 0x44, 0x49, 0x52, 0x45, 0x43, 0x54, 0xd7, +0x00, 0x06, 0x0a, 0x00, 0x90, 0x43, 0x49, 0x44, 0x45, 0x4e, 0x54, 0x41, +0x4c, 0x2c, 0x49, 0x00, 0xf3, 0x04, 0x53, 0x50, 0x45, 0x43, 0x49, 0x41, +0x4c, 0x2c, 0x20, 0x45, 0x58, 0x45, 0x4d, 0x50, 0x4c, 0x41, 0x52, 0x59, +0x2c, 0x57, 0x00, 0xff, 0x05, 0x53, 0x45, 0x51, 0x55, 0x45, 0x4e, 0x54, +0x49, 0x41, 0x4c, 0x20, 0x44, 0x41, 0x4d, 0x41, 0x47, 0x45, 0x53, 0x20, +0x28, 0x1e, 0x01, 0x0f, 0x80, 0x50, 0x52, 0x4f, 0x43, 0x55, 0x52, 0x45, +0x4d, 0xbc, 0x00, 0xf1, 0x03, 0x4f, 0x46, 0x20, 0x53, 0x55, 0x42, 0x53, +0x54, 0x49, 0x54, 0x55, 0x54, 0x45, 0x20, 0x47, 0x4f, 0x4f, 0x44, 0x77, +0x01, 0xd1, 0x53, 0x45, 0x52, 0x56, 0x49, 0x43, 0x45, 0x53, 0x3b, 0x20, +0x4c, 0x4f, 0x53, 0x39, 0x01, 0x31, 0x55, 0x53, 0x45, 0x8d, 0x00, 0x41, +0x44, 0x41, 0x54, 0x41, 0x7f, 0x00, 0x80, 0x50, 0x52, 0x4f, 0x46, 0x49, +0x54, 0x53, 0x3b, 0x0c, 0x00, 0x41, 0x42, 0x55, 0x53, 0x49, 0x43, 0x01, +0xf1, 0x0d, 0x49, 0x4e, 0x54, 0x45, 0x52, 0x52, 0x55, 0x50, 0x54, 0x49, +0x4f, 0x4e, 0x29, 0x20, 0x48, 0x4f, 0x57, 0x45, 0x56, 0x45, 0x52, 0x20, +0x43, 0x41, 0x55, 0x53, 0x45, 0x44, 0x6c, 0x01, 0x20, 0x4f, 0x4e, 0xf4, +0x00, 0x02, 0x3c, 0x02, 0x40, 0x45, 0x4f, 0x52, 0x59, 0x5b, 0x00, 0x23, +0x4c, 0x49, 0x8e, 0x01, 0x90, 0x2c, 0x20, 0x57, 0x48, 0x45, 0x54, 0x48, +0x45, 0x52, 0x5f, 0x01, 0x01, 0x36, 0x01, 0x10, 0x41, 0x0f, 0x01, 0x68, +0x53, 0x54, 0x52, 0x49, 0x43, 0x54, 0x27, 0x00, 0x61, 0x4f, 0x52, 0x20, +0x54, 0x4f, 0x52, 0xd9, 0x00, 0x06, 0xf0, 0x00, 0xb0, 0x20, 0x4e, 0x45, +0x47, 0x4c, 0x49, 0x47, 0x45, 0x4e, 0x43, 0x45, 0x21, 0x00, 0x10, 0x4f, +0x49, 0x00, 0xa0, 0x57, 0x49, 0x53, 0x45, 0x29, 0x20, 0x41, 0x52, 0x49, +0x53, 0x21, 0x00, 0x11, 0x49, 0x7d, 0x00, 0x71, 0x20, 0x57, 0x41, 0x59, +0x20, 0x4f, 0x55, 0xfc, 0x00, 0x00, 0xb5, 0x01, 0x31, 0x55, 0x53, 0x45, +0xaf, 0x01, 0x1a, 0x46, 0xcf, 0x02, 0x11, 0x2c, 0xde, 0x01, 0x80, 0x20, +0x49, 0x46, 0x20, 0x41, 0x44, 0x56, 0x49, 0xc0, 0x00, 0x03, 0x30, 0x00, +0x53, 0x50, 0x4f, 0x53, 0x53, 0x49, 0x3f, 0x02, 0x01, 0x3f, 0x01, 0x23, +0x43, 0x48, 0x7e, 0x01, 0x02, 0x15, 0x03, 0x70, 0x59, 0x6f, 0x75, 0x20, +0x63, 0x61, 0x6e, 0x9b, 0x03, 0x32, 0x74, 0x61, 0x63, 0xb5, 0x04, 0xb0, +0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x20, 0x61, 0x74, 0x20, 0x3a, 0x23, +0x00, 0x11, 0x2d, 0xe8, 0x05, 0x03, 0x8c, 0x04, 0xd0, 0x72, 0x65, 0x70, +0x6f, 0x73, 0x69, 0x74, 0x6f, 0x72, 0x79, 0x20, 0x3a, 0x20, 0x8a, 0x05, +0xf6, 0x0c, 0x73, 0x3a, 0x2f, 0x2f, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, +0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x43, 0x79, 0x61, 0x6e, 0x34, 0x39, 0x37, +0x33, 0x2f, 0x6c, 0x7a, 0x34, 0x3d, 0x00, 0x60, 0x70, 0x75, 0x62, 0x6c, +0x69, 0x63, 0x40, 0x04, 0x28, 0x75, 0x6d, 0x38, 0x00, 0xc1, 0x72, 0x6f, +0x75, 0x70, 0x73, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x3f, 0x00, +0x01, 0x22, 0x00, 0x32, 0x2f, 0x23, 0x21, 0x08, 0x00, 0xf0, 0x1b, 0x6c, +0x7a, 0x34, 0x63, 0x0a, 0x2a, 0x2f, 0x0a, 0x23, 0x70, 0x72, 0x61, 0x67, +0x6d, 0x61, 0x20, 0x6f, 0x6e, 0x63, 0x65, 0x0a, 0x0a, 0x23, 0x69, 0x66, +0x20, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x64, 0x20, 0x28, 0x5f, 0x5f, +0x63, 0x70, 0x6c, 0x75, 0x73, 0x04, 0x00, 0xf0, 0x08, 0x29, 0x0a, 0x65, +0x78, 0x74, 0x65, 0x72, 0x6e, 0x20, 0x22, 0x43, 0x22, 0x20, 0x7b, 0x0a, +0x23, 0x65, 0x6e, 0x64, 0x69, 0x66, 0x0a, 0x0a, 0xab, 0x06, 0x74, 0x2a, +0x20, 0x6c, 0x7a, 0x34, 0x2e, 0x68, 0x2a, 0x04, 0x79, 0x73, 0x20, 0x62, +0x6c, 0x6f, 0x63, 0x6b, 0xb2, 0x06, 0x41, 0x66, 0x75, 0x6e, 0x63, 0x9b, +0x04, 0x11, 0x2c, 0x9c, 0x04, 0xf1, 0x02, 0x67, 0x69, 0x76, 0x65, 0x73, +0x20, 0x66, 0x75, 0x6c, 0x6c, 0x20, 0x62, 0x75, 0x66, 0x66, 0x65, 0x72, +0x22, 0x01, 0x60, 0x72, 0x6f, 0x6c, 0x20, 0x74, 0x6f, 0x47, 0x00, 0x42, +0x67, 0x72, 0x61, 0x6d, 0x37, 0x05, 0xb0, 0x2a, 0x20, 0x49, 0x66, 0x20, +0x79, 0x6f, 0x75, 0x20, 0x6e, 0x65, 0xfa, 0x05, 0x90, 0x6f, 0x20, 0x67, +0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x5a, 0x06, 0xc5, 0x74, 0x65, 0x72, +0x2d, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x6e, 0x00, 0xf0, +0x01, 0x65, 0x64, 0x20, 0x64, 0x61, 0x74, 0x61, 0x20, 0x28, 0x72, 0x65, +0x73, 0x70, 0x65, 0x63, 0x74, 0xfd, 0x04, 0x00, 0x25, 0x01, 0x60, 0x66, +0x72, 0x61, 0x6d, 0x65, 0x20, 0x13, 0x00, 0x05, 0x61, 0x06, 0x20, 0x29, +0x2c, 0x60, 0x00, 0x00, 0x90, 0x00, 0x00, 0xa4, 0x01, 0x22, 0x6c, 0x65, +0xa0, 0x01, 0x40, 0x6c, 0x69, 0x62, 0x72, 0x8f, 0x05, 0xf1, 0x0e, 0x68, +0x61, 0x6e, 0x64, 0x6c, 0x65, 0x20, 0x69, 0x74, 0x73, 0x20, 0x6f, 0x77, +0x6e, 0x20, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x2c, 0x20, 0x70, 0x6c, +0x65, 0x61, 0x73, 0x65, 0xdc, 0x06, 0x31, 0x6c, 0x7a, 0x34, 0x56, 0x00, +0xb0, 0x2e, 0x68, 0x20, 0x69, 0x6e, 0x73, 0x74, 0x65, 0x61, 0x64, 0x2e, +0x50, 0x01, 0x3f, 0x0a, 0x2f, 0x2a, 0x01, 0x00, 0x12, 0x70, 0x0a, 0x2a, +0x20, 0x20, 0x56, 0x65, 0x72, 0x20, 0x01, 0x1f, 0x0a, 0x32, 0x00, 0x13, +0x32, 0x2f, 0x0a, 0x23, 0x9b, 0x01, 0x00, 0xd2, 0x00, 0xe0, 0x5f, 0x56, +0x45, 0x52, 0x53, 0x49, 0x4f, 0x4e, 0x5f, 0x4d, 0x41, 0x4a, 0x4f, 0x52, +0x5d, 0x06, 0x10, 0x31, 0x05, 0x00, 0x20, 0x2f, 0x2a, 0x09, 0x02, 0x60, +0x20, 0x62, 0x72, 0x65, 0x61, 0x6b, 0xfc, 0x00, 0x01, 0x27, 0x01, 0x20, +0x66, 0x61, 0xe9, 0x06, 0x8f, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x73, 0x20, +0x20, 0x48, 0x00, 0x05, 0x22, 0x49, 0x4e, 0x48, 0x00, 0x17, 0x37, 0x48, +0x00, 0x94, 0x6e, 0x65, 0x77, 0x20, 0x28, 0x6e, 0x6f, 0x6e, 0x2d, 0x51, +0x00, 0x18, 0x29, 0x52, 0x00, 0xbf, 0x61, 0x70, 0x61, 0x62, 0x69, 0x6c, +0x69, 0x74, 0x69, 0x65, 0x73, 0x56, 0x00, 0x05, 0x7a, 0x52, 0x45, 0x4c, +0x45, 0x41, 0x53, 0x45, 0x9e, 0x00, 0xf0, 0x03, 0x74, 0x77, 0x65, 0x61, +0x6b, 0x73, 0x2c, 0x20, 0x62, 0x75, 0x67, 0x2d, 0x66, 0x69, 0x78, 0x65, +0x73, 0x2c, 0x08, 0x08, 0x70, 0x64, 0x65, 0x76, 0x65, 0x6c, 0x6f, 0x70, +0x92, 0x06, 0x0f, 0x4e, 0x00, 0x05, 0x8e, 0x4e, 0x55, 0x4d, 0x42, 0x45, +0x52, 0x20, 0x28, 0x00, 0x01, 0x40, 0x2a, 0x31, 0x30, 0x30, 0x04, 0x00, +0x2f, 0x20, 0x2b, 0xd5, 0x00, 0x00, 0x0e, 0x19, 0x00, 0x04, 0x98, 0x00, +0x51, 0x29, 0x0a, 0x69, 0x6e, 0x74, 0x19, 0x00, 0x12, 0x76, 0x8b, 0x01, +0xef, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x20, 0x28, 0x76, 0x6f, 0x69, +0x64, 0x29, 0x3b, 0xcd, 0x01, 0x1a, 0x30, 0x54, 0x75, 0x6e, 0x72, 0x01, +0x20, 0x70, 0x61, 0x15, 0x02, 0x3f, 0x74, 0x65, 0x72, 0xd6, 0x01, 0x16, +0x02, 0x45, 0x03, 0x00, 0x85, 0x00, 0xc0, 0x4d, 0x45, 0x4d, 0x4f, 0x52, +0x59, 0x5f, 0x55, 0x53, 0x41, 0x47, 0x45, 0x20, 0x04, 0x31, 0x2a, 0x20, +0x4d, 0x78, 0x02, 0x61, 0x20, 0x75, 0x73, 0x61, 0x67, 0x65, 0x23, 0x08, +0xf0, 0x1d, 0x75, 0x6c, 0x61, 0x20, 0x3a, 0x20, 0x4e, 0x2d, 0x3e, 0x32, +0x5e, 0x4e, 0x20, 0x42, 0x79, 0x74, 0x65, 0x73, 0x20, 0x28, 0x65, 0x78, +0x61, 0x6d, 0x70, 0x6c, 0x65, 0x73, 0x20, 0x3a, 0x20, 0x31, 0x30, 0x20, +0x2d, 0x3e, 0x20, 0x31, 0x4b, 0x42, 0x3b, 0x20, 0x31, 0x32, 0x0b, 0x00, +0x80, 0x34, 0x4b, 0x42, 0x20, 0x3b, 0x20, 0x31, 0x36, 0x0c, 0x00, 0x20, +0x36, 0x34, 0x18, 0x00, 0x12, 0x32, 0x23, 0x00, 0x91, 0x4d, 0x42, 0x3b, +0x20, 0x65, 0x74, 0x63, 0x2e, 0x29, 0x66, 0x03, 0x60, 0x6e, 0x63, 0x72, +0x65, 0x61, 0x73, 0xc0, 0x00, 0x18, 0x6d, 0x72, 0x00, 0x20, 0x69, 0x6d, +0xd6, 0x03, 0x29, 0x65, 0x73, 0xce, 0x03, 0x10, 0x72, 0x3f, 0x03, 0x12, +0x0a, 0xcd, 0x08, 0x4a, 0x75, 0x63, 0x65, 0x64, 0x33, 0x00, 0x00, 0x4d, +0x03, 0x03, 0x37, 0x00, 0x00, 0x70, 0x03, 0x70, 0x65, 0x64, 0x2c, 0x20, +0x64, 0x75, 0x65, 0xbc, 0x03, 0xc0, 0x63, 0x61, 0x63, 0x68, 0x65, 0x20, +0x65, 0x66, 0x66, 0x65, 0x63, 0x74, 0x3f, 0x00, 0xf1, 0x05, 0x44, 0x65, +0x66, 0x61, 0x75, 0x6c, 0x74, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x20, +0x69, 0x73, 0x20, 0x31, 0x34, 0x2c, 0x20, 0x02, 0xf0, 0x05, 0x31, 0x36, +0x4b, 0x42, 0x2c, 0x20, 0x77, 0x68, 0x69, 0x63, 0x68, 0x20, 0x6e, 0x69, +0x63, 0x65, 0x6c, 0x79, 0x20, 0x66, 0x89, 0x03, 0xf2, 0x02, 0x69, 0x6e, +0x74, 0x6f, 0x20, 0x49, 0x6e, 0x74, 0x65, 0x6c, 0x20, 0x78, 0x38, 0x36, +0x20, 0x4c, 0x31, 0x53, 0x00, 0x1c, 0x0a, 0x2f, 0x02, 0x09, 0x47, 0x01, +0x3f, 0x31, 0x34, 0x0a, 0xc7, 0x01, 0x1a, 0x20, 0x53, 0x69, 0x4c, 0x01, +0x24, 0x20, 0x46, 0xb3, 0x04, 0x0f, 0xc7, 0x01, 0x16, 0x05, 0x4b, 0x02, +0x04, 0x2c, 0x01, 0x22, 0x5f, 0x64, 0xe1, 0x00, 0x60, 0x28, 0x63, 0x6f, +0x6e, 0x73, 0x74, 0x81, 0x03, 0x23, 0x72, 0x2a, 0xeb, 0x05, 0x13, 0x2c, +0x0e, 0x00, 0x50, 0x64, 0x65, 0x73, 0x74, 0x2c, 0xd8, 0x00, 0x03, 0x18, +0x00, 0x42, 0x53, 0x69, 0x7a, 0x65, 0x10, 0x00, 0x70, 0x6d, 0x61, 0x78, +0x44, 0x65, 0x73, 0x74, 0x11, 0x00, 0x25, 0x29, 0x3b, 0x5b, 0x00, 0x25, +0x64, 0x65, 0x5d, 0x00, 0x5f, 0x73, 0x61, 0x66, 0x65, 0x20, 0x5b, 0x00, +0x12, 0x06, 0x1c, 0x05, 0x0b, 0x5f, 0x00, 0x0a, 0x19, 0x00, 0x02, 0xef, +0x02, 0x1f, 0x0a, 0xc2, 0x00, 0x02, 0x12, 0x29, 0xae, 0x06, 0x24, 0x20, +0x43, 0x32, 0x00, 0x36, 0x73, 0x20, 0x27, 0xb2, 0x00, 0x31, 0x27, 0x20, +0x62, 0x89, 0x02, 0x44, 0x66, 0x72, 0x6f, 0x6d, 0xd2, 0x05, 0x03, 0x1f, +0x00, 0x11, 0x27, 0x37, 0x00, 0x01, 0xb9, 0x01, 0xe0, 0x61, 0x6c, 0x72, +0x65, 0x61, 0x64, 0x79, 0x20, 0x61, 0x6c, 0x6c, 0x6f, 0x63, 0x61, 0xd3, +0x0b, 0x10, 0x27, 0xa4, 0x00, 0x14, 0x27, 0x32, 0x00, 0x00, 0x94, 0x0b, +0x57, 0x69, 0x7a, 0x65, 0x20, 0x27, 0xfb, 0x00, 0x29, 0x27, 0x2e, 0x77, +0x00, 0x00, 0x7e, 0x02, 0xa3, 0x69, 0x73, 0x20, 0x67, 0x75, 0x61, 0x72, +0x61, 0x6e, 0x74, 0x13, 0x06, 0x40, 0x73, 0x75, 0x63, 0x63, 0x0b, 0x00, +0x2a, 0x69, 0x66, 0x3b, 0x00, 0x39, 0x20, 0x3e, 0x3d, 0x8f, 0x01, 0x66, +0x42, 0x6f, 0x75, 0x6e, 0x64, 0x28, 0xb6, 0x00, 0x12, 0x29, 0x5c, 0x00, +0xf0, 0x11, 0x49, 0x74, 0x20, 0x61, 0x6c, 0x73, 0x6f, 0x20, 0x72, 0x75, +0x6e, 0x73, 0x20, 0x66, 0x61, 0x73, 0x74, 0x65, 0x72, 0x2c, 0x20, 0x73, +0x6f, 0x20, 0x69, 0x74, 0x27, 0x73, 0x20, 0x61, 0x20, 0x72, 0x26, 0x01, +0x30, 0x6d, 0x65, 0x6e, 0x03, 0x0b, 0x30, 0x73, 0x65, 0x74, 0x51, 0x06, +0x03, 0x38, 0x00, 0x12, 0x66, 0x64, 0x0b, 0x03, 0xdb, 0x06, 0x00, 0xf8, +0x02, 0x26, 0x6e, 0x6f, 0x6d, 0x01, 0x05, 0x01, 0x01, 0x03, 0xfd, 0x00, +0x40, 0x20, 0x6d, 0x6f, 0x72, 0x5e, 0x06, 0x29, 0x6d, 0x69, 0xfa, 0x00, +0x41, 0x64, 0x67, 0x65, 0x74, 0x4e, 0x09, 0x09, 0x62, 0x03, 0xf2, 0x04, +0x73, 0x74, 0x6f, 0x70, 0x73, 0x20, 0x2a, 0x69, 0x6d, 0x6d, 0x65, 0x64, +0x69, 0x61, 0x74, 0x65, 0x6c, 0x79, 0x2a, 0x3a, 0x07, 0x09, 0x72, 0x00, +0x30, 0x72, 0x65, 0x73, 0x3f, 0x03, 0x72, 0x69, 0x73, 0x20, 0x7a, 0x65, +0x72, 0x6f, 0x96, 0x00, 0x10, 0x41, 0xb4, 0x00, 0x00, 0x15, 0x02, 0x50, +0x65, 0x71, 0x75, 0x65, 0x6e, 0x0e, 0x02, 0x03, 0x6b, 0x00, 0x00, 0x62, +0x07, 0x21, 0x65, 0x6e, 0x2e, 0x00, 0x21, 0x6e, 0x6f, 0x74, 0x03, 0x22, +0x69, 0x64, 0x33, 0x00, 0x10, 0x54, 0x46, 0x0c, 0x05, 0x55, 0x00, 0x90, +0x6e, 0x65, 0x76, 0x65, 0x72, 0x20, 0x77, 0x72, 0x69, 0xd1, 0x01, 0x7a, +0x6f, 0x75, 0x74, 0x73, 0x69, 0x64, 0x65, 0xa9, 0x01, 0x60, 0x2c, 0x20, +0x6e, 0x6f, 0x72, 0x20, 0xcc, 0x01, 0x06, 0x20, 0x00, 0x04, 0xec, 0x00, +0x02, 0x22, 0x00, 0x05, 0xf0, 0x0c, 0x07, 0xd6, 0x02, 0xe0, 0x20, 0x20, +0x3a, 0x20, 0x4d, 0x61, 0x78, 0x20, 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, +0x04, 0x01, 0x05, 0xf7, 0x03, 0x01, 0xb3, 0x03, 0xe5, 0x41, 0x58, 0x5f, +0x49, 0x4e, 0x50, 0x55, 0x54, 0x5f, 0x56, 0x41, 0x4c, 0x55, 0x45, 0x41, +0x00, 0x07, 0xd1, 0x01, 0x22, 0x20, 0x3a, 0x33, 0x08, 0x20, 0x6f, 0x72, +0x64, 0x05, 0x42, 0x74, 0x69, 0x61, 0x6c, 0x30, 0x02, 0x25, 0x6f, 0x66, +0x74, 0x02, 0x02, 0xa7, 0x00, 0x12, 0x28, 0x3a, 0x04, 0x01, 0x4c, 0x0d, +0x2e, 0x62, 0x65, 0x78, 0x02, 0x15, 0x29, 0x5e, 0x00, 0x81, 0x72, 0x65, +0x74, 0x75, 0x72, 0x6e, 0x20, 0x3a, 0x58, 0x01, 0x12, 0x6e, 0xfb, 0x05, +0x23, 0x6f, 0x66, 0xce, 0x02, 0x00, 0x04, 0x01, 0x32, 0x74, 0x65, 0x6e, +0xc0, 0x01, 0x0b, 0x62, 0x00, 0xe0, 0x6e, 0x65, 0x63, 0x65, 0x73, 0x73, +0x61, 0x72, 0x69, 0x6c, 0x79, 0x20, 0x3c, 0x3d, 0xa6, 0x00, 0x52, 0x4f, +0x75, 0x74, 0x70, 0x75, 0xaf, 0x03, 0x29, 0x0a, 0x20, 0x01, 0x00, 0x40, +0x6f, 0x72, 0x20, 0x30, 0x9d, 0x02, 0x09, 0x11, 0x09, 0x6f, 0x61, 0x69, +0x6c, 0x73, 0x0a, 0x0a, 0xd3, 0x03, 0x00, 0x05, 0x6b, 0x03, 0x0a, 0x9d, +0x03, 0x20, 0x20, 0x3a, 0x2a, 0x01, 0x00, 0xa7, 0x00, 0x72, 0x70, 0x72, +0x65, 0x63, 0x69, 0x73, 0x65, 0x0c, 0x01, 0x04, 0x01, 0x01, 0x29, 0x74, +0x68, 0x03, 0x09, 0x01, 0x82, 0x09, 0x02, 0x86, 0x01, 0x0e, 0xe9, 0x03, +0x07, 0x4c, 0x00, 0x04, 0x3f, 0x00, 0x00, 0xd6, 0x00, 0x22, 0x69, 0x6e, +0x08, 0x0e, 0x04, 0xe5, 0x01, 0x0f, 0x45, 0x01, 0x0c, 0x2f, 0x2e, 0x0a, +0x41, 0x01, 0x0e, 0x17, 0x64, 0x78, 0x00, 0x02, 0x46, 0x01, 0x0e, 0x68, +0x00, 0x0e, 0x4b, 0x01, 0x0f, 0x99, 0x04, 0x00, 0x0a, 0x51, 0x01, 0x1f, +0x49, 0xb0, 0x00, 0x01, 0x04, 0xd8, 0x02, 0xd1, 0x6c, 0x61, 0x72, 0x67, +0x65, 0x20, 0x65, 0x6e, 0x6f, 0x75, 0x67, 0x68, 0x2c, 0x82, 0x00, 0x10, +0x64, 0xd5, 0x06, 0x41, 0x77, 0x69, 0x6c, 0x6c, 0x56, 0x03, 0x01, 0x46, +0x03, 0x11, 0x6f, 0xac, 0x01, 0x92, 0x20, 0x61, 0x6e, 0x20, 0x65, 0x72, +0x72, 0x6f, 0x72, 0x04, 0x10, 0x5d, 0x28, 0x3c, 0x30, 0x29, 0x2e, 0x6a, +0x00, 0x01, 0x26, 0x01, 0x02, 0x9e, 0x0b, 0x60, 0x73, 0x74, 0x72, 0x65, +0x61, 0x6d, 0x69, 0x00, 0x50, 0x64, 0x65, 0x74, 0x65, 0x63, 0xc3, 0x02, +0x30, 0x6d, 0x61, 0x6c, 0x94, 0x07, 0x00, 0xe4, 0x06, 0x09, 0x9a, 0x03, +0x06, 0x6f, 0x00, 0x05, 0x82, 0x00, 0x00, 0x78, 0x00, 0x03, 0x2e, 0x01, +0xa3, 0x61, 0x20, 0x6e, 0x65, 0x67, 0x61, 0x74, 0x69, 0x76, 0x65, 0xc3, +0x03, 0x0b, 0x77, 0x00, 0x0a, 0x91, 0x03, 0x11, 0x69, 0x84, 0x0f, 0x03, +0x71, 0x00, 0x30, 0x61, 0x67, 0x61, 0x6c, 0x0a, 0x05, 0x33, 0x05, 0xf0, +0x01, 0x76, 0x65, 0x72, 0x66, 0x6c, 0x6f, 0x77, 0x20, 0x65, 0x78, 0x70, +0x6c, 0x6f, 0x69, 0x74, 0x73, 0xdd, 0x05, 0x31, 0x63, 0x6c, 0x75, 0x72, +0x00, 0x92, 0x6d, 0x61, 0x6c, 0x69, 0x63, 0x69, 0x6f, 0x75, 0x73, 0x12, +0x0b, 0x7c, 0x70, 0x61, 0x63, 0x6b, 0x65, 0x74, 0x73, 0xe3, 0x00, 0x1f, +0x74, 0xf2, 0x03, 0x03, 0x03, 0x23, 0x01, 0x0c, 0xf2, 0x03, 0x06, 0x21, +0x00, 0x26, 0x69, 0x6e, 0x20, 0x00, 0x02, 0xf8, 0x0a, 0x0f, 0x65, 0x07, +0x19, 0x50, 0x41, 0x64, 0x76, 0x61, 0x6e, 0x3b, 0x08, 0x0e, 0x67, 0x07, +0x0f, 0x04, 0x0b, 0x19, 0x06, 0x36, 0x04, 0x44, 0x53, 0x49, 0x5a, 0x45, +0xd4, 0x00, 0x51, 0x30, 0x78, 0x37, 0x45, 0x30, 0x01, 0x00, 0x02, 0x73, +0x0a, 0xd3, 0x32, 0x20, 0x31, 0x31, 0x33, 0x20, 0x39, 0x32, 0x39, 0x20, +0x32, 0x31, 0x36, 0x9c, 0x02, 0x0b, 0xaf, 0x0a, 0x31, 0x43, 0x4f, 0x4d, +0x69, 0x10, 0x70, 0x42, 0x4f, 0x55, 0x4e, 0x44, 0x28, 0x69, 0x18, 0x03, +0xe4, 0x29, 0x20, 0x20, 0x28, 0x28, 0x75, 0x6e, 0x73, 0x69, 0x67, 0x6e, +0x65, 0x64, 0x29, 0x14, 0x00, 0x26, 0x3e, 0x20, 0x14, 0x00, 0x0f, 0x82, +0x00, 0x00, 0x64, 0x3f, 0x20, 0x30, 0x20, 0x3a, 0x20, 0x2d, 0x00, 0x33, +0x2b, 0x20, 0x28, 0x0b, 0x00, 0x40, 0x2f, 0x32, 0x35, 0x35, 0x10, 0x00, +0x3d, 0x31, 0x36, 0x29, 0x65, 0x07, 0x02, 0x98, 0x06, 0x04, 0xf7, 0x03, +0x14, 0x50, 0x46, 0x0d, 0x00, 0x51, 0x02, 0x72, 0x6d, 0x61, 0x78, 0x69, +0x6d, 0x75, 0x6d, 0xa8, 0x03, 0x01, 0xf8, 0x12, 0x00, 0xcc, 0x0c, 0x08, +0x49, 0x04, 0x34, 0x6d, 0x61, 0x79, 0xac, 0x01, 0x10, 0x69, 0x5a, 0x02, +0x40, 0x22, 0x77, 0x6f, 0x72, 0x11, 0x08, 0xf2, 0x00, 0x61, 0x73, 0x65, +0x22, 0x20, 0x73, 0x63, 0x65, 0x6e, 0x61, 0x72, 0x69, 0x6f, 0x20, 0x28, +0xae, 0x01, 0x01, 0x08, 0x02, 0x08, 0xa5, 0x06, 0x33, 0x69, 0x62, 0x6c, +0x5e, 0x03, 0x0f, 0x74, 0x02, 0x00, 0x22, 0x69, 0x6d, 0x95, 0x03, 0x61, +0x75, 0x73, 0x65, 0x66, 0x75, 0x6c, 0x99, 0x09, 0x03, 0xe9, 0x09, 0x03, +0x05, 0x04, 0x00, 0x2a, 0x00, 0x50, 0x70, 0x75, 0x72, 0x70, 0x6f, 0x0f, +0x08, 0x1f, 0x28, 0x94, 0x03, 0x00, 0x16, 0x73, 0x66, 0x07, 0x5f, 0x4d, +0x61, 0x63, 0x72, 0x6f, 0x6b, 0x01, 0x00, 0x10, 0x29, 0x6c, 0x00, 0x01, +0x80, 0x07, 0x05, 0x69, 0x12, 0x11, 0x66, 0x92, 0x03, 0x41, 0x6d, 0x70, +0x69, 0x6c, 0x4d, 0x00, 0x70, 0x2d, 0x74, 0x69, 0x6d, 0x65, 0x20, 0x65, +0x2e, 0x06, 0x02, 0x5d, 0x00, 0x6f, 0x28, 0x73, 0x74, 0x61, 0x63, 0x6b, +0x8c, 0x00, 0x00, 0x00, 0x39, 0x00, 0x03, 0x0b, 0x0b, 0x03, 0x76, 0x00, +0x36, 0x4e, 0x6f, 0x74, 0x38, 0x01, 0x0f, 0xd6, 0x08, 0x01, 0x05, 0xae, +0x07, 0x02, 0xf9, 0x07, 0x51, 0x20, 0x77, 0x68, 0x65, 0x6e, 0x5e, 0x04, +0x08, 0xc3, 0x00, 0x00, 0xa3, 0x00, 0x0f, 0x4c, 0x08, 0x03, 0x2a, 0x72, +0x63, 0xa0, 0x04, 0x01, 0x67, 0x01, 0x04, 0xee, 0x06, 0x1f, 0x6d, 0xee, +0x06, 0x11, 0x00, 0x36, 0x02, 0x0e, 0x8f, 0x06, 0x04, 0xf8, 0x01, 0x03, +0xda, 0x01, 0x02, 0x85, 0x00, 0x0f, 0xdf, 0x01, 0x06, 0x0f, 0x70, 0x06, +0x00, 0x10, 0x2c, 0x71, 0x06, 0x26, 0x69, 0x6e, 0x3d, 0x00, 0x53, 0x73, +0x20, 0x74, 0x6f, 0x6f, 0x1e, 0x05, 0x3f, 0x28, 0x20, 0x3e, 0x86, 0x00, +0x00, 0x10, 0x29, 0xc5, 0x03, 0x0c, 0xc3, 0x0a, 0x02, 0xe8, 0x00, 0x00, +0x16, 0x00, 0x05, 0xdb, 0x00, 0x0f, 0x27, 0x0a, 0x01, 0x00, 0x3e, 0x01, +0x05, 0xc2, 0x02, 0x10, 0x53, 0x6a, 0x0f, 0x2f, 0x61, 0x73, 0x73, 0x01, +0x04, 0x00, 0xf6, 0x0d, 0x11, 0x74, 0xb6, 0x01, 0x21, 0x77, 0x73, 0xbe, +0x09, 0x41, 0x65, 0x6c, 0x65, 0x63, 0x8c, 0x05, 0x81, 0x22, 0x61, 0x63, +0x63, 0x65, 0x6c, 0x65, 0x72, 0xcd, 0x01, 0x84, 0x22, 0x20, 0x66, 0x61, +0x63, 0x74, 0x6f, 0x72, 0xa3, 0x08, 0x12, 0x65, 0xbc, 0x00, 0x12, 0x72, +0x44, 0x11, 0x07, 0x29, 0x00, 0x02, 0x59, 0x01, 0x03, 0x80, 0x05, 0x02, +0xc5, 0x01, 0x01, 0x23, 0x00, 0x04, 0x24, 0x17, 0x04, 0x70, 0x00, 0x22, +0x73, 0x6f, 0xdf, 0x0f, 0x00, 0x56, 0x06, 0x19, 0x72, 0x30, 0x07, 0x01, +0xc4, 0x14, 0x02, 0x0a, 0x0a, 0x01, 0xf2, 0x09, 0xa0, 0x74, 0x72, 0x61, +0x64, 0x65, 0x2d, 0x6f, 0x66, 0x66, 0x2e, 0x1e, 0x05, 0x00, 0xcf, 0x0c, +0x31, 0x62, 0x65, 0x20, 0x2a, 0x04, 0x53, 0x74, 0x75, 0x6e, 0x65, 0x64, +0xb9, 0x16, 0x42, 0x65, 0x61, 0x63, 0x68, 0x7b, 0x0a, 0x20, 0x73, 0x73, +0xca, 0x05, 0x02, 0xe0, 0x01, 0x02, 0xc5, 0x02, 0x00, 0x7e, 0x05, 0x10, +0x72, 0x82, 0x06, 0x71, 0x6c, 0x79, 0x20, 0x2b, 0x7e, 0x33, 0x25, 0xe8, +0x00, 0x00, 0x0b, 0x0d, 0x03, 0xa4, 0x09, 0x1f, 0x6e, 0xc2, 0x00, 0x00, +0x00, 0x37, 0x07, 0x35, 0x22, 0x31, 0x22, 0x9a, 0x07, 0x03, 0x45, 0x01, +0x7f, 0x72, 0x65, 0x67, 0x75, 0x6c, 0x61, 0x72, 0x4d, 0x01, 0x04, 0x01, +0x4f, 0x00, 0x10, 0x56, 0x3f, 0x00, 0x10, 0x73, 0x3c, 0x07, 0x12, 0x30, +0x79, 0x06, 0x11, 0x62, 0x4a, 0x12, 0x20, 0x6c, 0x61, 0x60, 0x05, 0xb0, +0x62, 0x79, 0x20, 0x41, 0x43, 0x43, 0x45, 0x4c, 0x45, 0x52, 0x41, 0x8a, +0x13, 0xc1, 0x5f, 0x44, 0x45, 0x46, 0x41, 0x55, 0x4c, 0x54, 0x20, 0x28, +0x73, 0x65, 0xc2, 0x10, 0x34, 0x2e, 0x63, 0x29, 0xeb, 0x07, 0x00, 0x81, +0x0d, 0x1f, 0x2e, 0x05, 0x02, 0x01, 0x01, 0xdf, 0x01, 0x1f, 0x20, 0xc6, +0x0c, 0x2d, 0x02, 0x11, 0x00, 0x08, 0xf9, 0x00, 0x00, 0x4a, 0x02, 0x0f, +0x4b, 0x02, 0x02, 0x9a, 0x5f, 0x65, 0x78, 0x74, 0x53, 0x74, 0x61, 0x74, +0x65, 0x54, 0x02, 0x0f, 0x52, 0x12, 0x01, 0x30, 0x2c, 0x20, 0x6a, 0xa2, +0x08, 0x22, 0x75, 0x73, 0x64, 0x07, 0x12, 0x20, 0xa6, 0x12, 0x38, 0x61, +0x6c, 0x6c, 0x68, 0x0c, 0x03, 0x2b, 0x04, 0x41, 0x73, 0x70, 0x61, 0x63, +0x89, 0x0e, 0x20, 0x73, 0x74, 0x8c, 0x0b, 0x0a, 0x71, 0x0b, 0x32, 0x61, +0x74, 0x65, 0x9e, 0x01, 0x22, 0x55, 0x73, 0x13, 0x06, 0x00, 0x38, 0x03, +0x24, 0x6f, 0x66, 0x87, 0x00, 0xf4, 0x01, 0x74, 0x6f, 0x20, 0x6b, 0x6e, +0x6f, 0x77, 0x20, 0x68, 0x6f, 0x77, 0x20, 0x6d, 0x75, 0x63, 0x68, 0x54, +0x00, 0x06, 0x20, 0x09, 0x03, 0x6d, 0x00, 0x02, 0xcd, 0x0b, 0x00, 0xee, +0x07, 0x04, 0x13, 0x00, 0x92, 0x20, 0x69, 0x74, 0x20, 0x6f, 0x6e, 0x20, +0x38, 0x2d, 0x7a, 0x06, 0x10, 0x62, 0x53, 0x03, 0x20, 0x61, 0x72, 0x34, +0x11, 0x33, 0x28, 0x75, 0x73, 0xa9, 0x07, 0x30, 0x6c, 0x6f, 0x63, 0x65, +0x00, 0x40, 0x79, 0x70, 0x69, 0x63, 0xbc, 0x00, 0x15, 0x29, 0xf7, 0x02, +0x24, 0x6e, 0x2c, 0x19, 0x05, 0x00, 0x47, 0x00, 0x40, 0x61, 0x73, 0x20, +0x27, 0x9a, 0x10, 0x12, 0x2a, 0xb1, 0x00, 0x11, 0x27, 0x56, 0x0f, 0x0f, +0x16, 0x01, 0x00, 0x09, 0xc7, 0x01, 0x08, 0xc9, 0x00, 0x03, 0xd7, 0x10, +0x04, 0x4f, 0x0e, 0x0f, 0x76, 0x01, 0x03, 0x27, 0x20, 0x28, 0x64, 0x00, +0x2f, 0x2c, 0x20, 0xf8, 0x01, 0x11, 0x05, 0x1e, 0x04, 0x0f, 0xf7, 0x01, +0x25, 0x13, 0x64, 0x2f, 0x00, 0x05, 0xf2, 0x01, 0x10, 0x52, 0x96, 0x08, +0x12, 0x73, 0x03, 0x19, 0x60, 0x6c, 0x6f, 0x67, 0x69, 0x63, 0x2c, 0xcc, +0x02, 0x05, 0xed, 0x00, 0x00, 0xee, 0x01, 0x12, 0x73, 0x8a, 0x01, 0x01, +0xd6, 0x06, 0x52, 0x61, 0x73, 0x20, 0x70, 0x6f, 0xd1, 0x06, 0x02, 0x87, +0x0e, 0x0b, 0x93, 0x0c, 0x0f, 0x87, 0x0e, 0x09, 0x0a, 0xdc, 0x0b, 0x05, +0x87, 0x0e, 0x10, 0x74, 0x71, 0x04, 0x1b, 0x74, 0x8a, 0x0e, 0x0a, 0x2d, +0x0d, 0x21, 0x65, 0x69, 0x2e, 0x19, 0x16, 0x63, 0x16, 0x0f, 0x00, 0xaf, +0x00, 0x57, 0x65, 0x6e, 0x74, 0x69, 0x72, 0x15, 0x0d, 0x05, 0x7b, 0x0d, +0x00, 0x7f, 0x00, 0x03, 0x66, 0x00, 0x22, 0x69, 0x66, 0x61, 0x0e, 0x09, +0xb0, 0x0a, 0x13, 0x0a, 0xbf, 0x05, 0x10, 0x66, 0xc6, 0x03, 0x0a, 0x1d, +0x0f, 0x00, 0x63, 0x00, 0x20, 0x6c, 0x65, 0x0a, 0x0e, 0x02, 0x7f, 0x04, +0x0f, 0xfd, 0x00, 0x13, 0x06, 0xed, 0x09, 0x16, 0x2a, 0x9a, 0x03, 0x55, +0x50, 0x74, 0x72, 0x20, 0x3a, 0x2a, 0x04, 0x02, 0x73, 0x1b, 0x02, 0x4a, +0x0f, 0x41, 0x69, 0x6e, 0x64, 0x69, 0xb2, 0x02, 0x01, 0xe6, 0x02, 0x34, +0x61, 0x6e, 0x79, 0x0a, 0x0d, 0x42, 0x68, 0x65, 0x72, 0x65, 0xf2, 0x0d, +0x0a, 0x5c, 0x01, 0x28, 0x74, 0x6f, 0xac, 0x00, 0x0b, 0x5b, 0x0a, 0x08, +0x01, 0x00, 0x36, 0x4e, 0x65, 0x77, 0x02, 0x07, 0x0b, 0xf2, 0x0b, 0x23, +0x6f, 0x6c, 0x1e, 0x07, 0x1e, 0x2e, 0x09, 0x07, 0x2f, 0x4e, 0x62, 0x8d, +0x0d, 0x01, 0x0f, 0x86, 0x0d, 0x04, 0x0a, 0xb1, 0x01, 0x0f, 0x87, 0x0d, +0x17, 0x0e, 0xf3, 0x04, 0x06, 0x90, 0x02, 0x0f, 0xf7, 0x04, 0x12, 0x29, +0x2a, 0x20, 0x5e, 0x01, 0x02, 0xf3, 0x02, 0x0b, 0x8e, 0x00, 0x07, 0xf5, +0x02, 0x2f, 0x64, 0x65, 0x39, 0x07, 0x03, 0x8a, 0x6f, 0x72, 0x69, 0x67, +0x69, 0x6e, 0x61, 0x6c, 0xa4, 0x0d, 0x04, 0x16, 0x00, 0x04, 0x00, 0x10, +0x30, 0x72, 0x65, 0x66, 0xbe, 0x04, 0x27, 0x75, 0x6e, 0x5d, 0x0d, 0x00, +0xb1, 0x02, 0x0f, 0x90, 0x0d, 0x0f, 0x06, 0xc1, 0x01, 0x07, 0xd6, 0x0c, +0x04, 0x87, 0x0d, 0x23, 0x69, 0x6e, 0xfb, 0x1b, 0x6c, 0x77, 0x6f, 0x72, +0x64, 0x73, 0x2c, 0x52, 0x0e, 0x01, 0xcb, 0x09, 0x0f, 0x1e, 0x0d, 0x72, +0x1e, 0x44, 0x68, 0x0a, 0x0f, 0xa5, 0x0e, 0x07, 0x42, 0x20, 0x49, 0x74, +0x73, 0xcf, 0x03, 0x05, 0x24, 0x00, 0x42, 0x20, 0x6d, 0x69, 0x6e, 0x5d, +0x09, 0x38, 0x66, 0x20, 0x27, 0x73, 0x01, 0x03, 0xc6, 0x12, 0x02, 0x6f, +0x00, 0x10, 0x6e, 0x3a, 0x0a, 0x1b, 0x3a, 0xef, 0x03, 0x00, 0x73, 0x0f, +0x23, 0x79, 0x20, 0x5a, 0x18, 0x04, 0x02, 0x06, 0x07, 0xd0, 0x05, 0x00, +0x81, 0x0a, 0x20, 0x70, 0x72, 0x94, 0x18, 0x12, 0x6c, 0xd0, 0x1d, 0x2c, +0x65, 0x64, 0x99, 0x18, 0x2a, 0x2e, 0x0a, 0x7d, 0x0d, 0x00, 0xfe, 0x0a, +0x46, 0x20, 0x62, 0x69, 0x74, 0xbc, 0x08, 0x3f, 0x61, 0x6e, 0x20, 0x17, +0x10, 0x02, 0x09, 0x3a, 0x00, 0x30, 0x48, 0x6f, 0x77, 0x20, 0x05, 0x10, +0x2c, 0x15, 0x06, 0x32, 0x64, 0x6f, 0x65, 0xfc, 0x0e, 0x04, 0x29, 0x06, +0x00, 0xb9, 0x03, 0x03, 0x33, 0x0e, 0x01, 0xd9, 0x1d, 0x03, 0x34, 0x0e, +0x11, 0x69, 0x86, 0x04, 0x22, 0x69, 0x6f, 0x1e, 0x07, 0x05, 0xf8, 0x03, +0x01, 0x42, 0x04, 0x03, 0xbe, 0x01, 0x16, 0x28, 0x34, 0x0e, 0x01, 0xd2, +0x05, 0x0a, 0x75, 0x00, 0x00, 0x1a, 0x07, 0x1a, 0x74, 0x28, 0x0c, 0x60, +0x6e, 0x20, 0x74, 0x72, 0x75, 0x73, 0xed, 0x01, 0x71, 0x65, 0x6e, 0x76, +0x69, 0x72, 0x6f, 0x6e, 0xbe, 0x17, 0x61, 0x6f, 0x6e, 0x6c, 0x79, 0x20, +0x28, 0x59, 0x00, 0x22, 0x74, 0x6f, 0xe5, 0x01, 0x01, 0x4d, 0x02, 0x04, +0x23, 0x14, 0x15, 0x61, 0x36, 0x00, 0x02, 0x3d, 0x02, 0x19, 0x29, 0xb0, +0x06, 0x2f, 0x64, 0x65, 0x79, 0x08, 0x20, 0x08, 0xc9, 0x01, 0x2f, 0x29, +0x3b, 0x6b, 0x03, 0x01, 0x00, 0x46, 0x01, 0x13, 0x5f, 0x39, 0x12, 0x05, +0x73, 0x03, 0x0a, 0xcf, 0x05, 0x06, 0x2e, 0x00, 0x2d, 0x20, 0x61, 0x4f, +0x11, 0x06, 0x19, 0x06, 0x0a, 0x9e, 0x10, 0x10, 0x27, 0xcc, 0x1b, 0x01, +0xb8, 0x1b, 0x00, 0x43, 0x00, 0x0e, 0xf7, 0x14, 0x0e, 0xf4, 0x10, 0x0d, +0x6a, 0x06, 0x0f, 0xf4, 0x10, 0x00, 0x05, 0x6f, 0x06, 0x07, 0x38, 0x03, +0x11, 0x74, 0x65, 0x02, 0x26, 0x74, 0x6f, 0x3c, 0x03, 0x06, 0x0d, 0x07, +0x24, 0x6f, 0x70, 0x4e, 0x0a, 0x52, 0x61, 0x73, 0x20, 0x73, 0x6f, 0x08, +0x00, 0x03, 0xc3, 0x06, 0x06, 0x9b, 0x12, 0x90, 0x27, 0x20, 0x68, 0x61, +0x73, 0x20, 0x62, 0x65, 0x65, 0x3d, 0x14, 0x00, 0x3b, 0x17, 0x03, 0xaf, +0x08, 0x10, 0x72, 0xc9, 0x17, 0x01, 0x28, 0x20, 0x18, 0x65, 0x1f, 0x05, +0x00, 0x7a, 0x0d, 0x0f, 0xe8, 0x11, 0x14, 0x00, 0xb9, 0x0d, 0x04, 0x57, +0x20, 0x0f, 0xe5, 0x11, 0x2b, 0x12, 0x4e, 0x7a, 0x03, 0x01, 0x69, 0x02, +0x03, 0x6a, 0x00, 0x03, 0x84, 0x0b, 0x1f, 0x3c, 0xd1, 0x00, 0x01, 0x6f, +0x73, 0x68, 0x6f, 0x75, 0x6c, 0x64, 0x01, 0x13, 0x02, 0x07, 0x7d, 0x02, +0x40, 0x62, 0x65, 0x20, 0x73, 0x67, 0x09, 0x2b, 0x65, 0x72, 0x4e, 0x04, +0x65, 0x41, 0x6c, 0x77, 0x61, 0x79, 0x73, 0x80, 0x1c, 0x0c, 0xf9, 0x06, +0x00, 0xf8, 0x06, 0x03, 0xdf, 0x00, 0x0f, 0x1c, 0x12, 0x81, 0x0f, 0xbb, +0x11, 0x03, 0x1c, 0x66, 0xbe, 0x11, 0x00, 0x60, 0x00, 0x02, 0x2b, 0x00, +0x0a, 0xc4, 0x11, 0x2a, 0x6f, 0x66, 0xc7, 0x11, 0x03, 0x91, 0x04, 0x06, +0x65, 0x06, 0x0e, 0x79, 0x12, 0x0f, 0x55, 0x12, 0x03, 0x0e, 0xbf, 0x03, +0x0d, 0x73, 0x03, 0x0f, 0xab, 0x18, 0x27, 0x0c, 0xf4, 0x01, 0x0f, 0xc1, +0x18, 0x0a, 0x0e, 0x85, 0x12, 0x0f, 0xf3, 0x19, 0x11, 0x01, 0xbe, 0x01, +0x00, 0x8a, 0x01, 0x08, 0x69, 0x18, 0x0f, 0x9b, 0x12, 0x00, 0x0f, 0xa4, +0x12, 0x21, 0x60, 0x53, 0x54, 0x52, 0x45, 0x41, 0x4d, 0x62, 0x0f, 0xdc, +0x5f, 0x55, 0x36, 0x34, 0x20, 0x28, 0x28, 0x31, 0x20, 0x3c, 0x3c, 0x20, +0x28, 0xa8, 0x1a, 0x30, 0x2d, 0x33, 0x29, 0x21, 0x12, 0x2f, 0x34, 0x29, +0x3d, 0x00, 0x04, 0x01, 0xfe, 0x01, 0x1f, 0x28, 0x51, 0x00, 0x00, 0x22, +0x2a, 0x20, 0xe1, 0x0b, 0x60, 0x28, 0x6c, 0x6f, 0x6e, 0x67, 0x20, 0x05, +0x00, 0x27, 0x29, 0x29, 0x53, 0x1c, 0x02, 0x9a, 0x02, 0x11, 0x5f, 0x71, +0x1b, 0x20, 0x69, 0x6e, 0x92, 0x02, 0x02, 0x9a, 0x03, 0x81, 0x73, 0x74, +0x72, 0x75, 0x63, 0x74, 0x75, 0x72, 0x11, 0x0d, 0x20, 0x74, 0x72, 0x52, +0x11, 0x02, 0x7a, 0x06, 0x03, 0xcc, 0x02, 0x01, 0x7d, 0x1f, 0x20, 0x69, +0x6d, 0xbe, 0x10, 0x30, 0x61, 0x6e, 0x74, 0x8f, 0x08, 0x32, 0x6e, 0x69, +0x74, 0x96, 0x03, 0x06, 0x3b, 0x00, 0x04, 0xda, 0x0a, 0x12, 0x62, 0x2f, +0x02, 0x31, 0x66, 0x69, 0x72, 0x8c, 0x0d, 0x30, 0x65, 0x20, 0x21, 0x3e, +0x00, 0x03, 0x44, 0x07, 0x29, 0x6f, 0x6e, 0x8d, 0x0d, 0x82, 0x64, 0x69, +0x72, 0x65, 0x63, 0x74, 0x6c, 0x79, 0x3f, 0x03, 0x05, 0x4b, 0x00, 0x12, +0x69, 0xe8, 0x1f, 0x00, 0xf4, 0x25, 0x00, 0x78, 0x0c, 0x02, 0x08, 0x0d, +0x53, 0x20, 0x6c, 0x69, 0x6e, 0x6b, 0xc3, 0x1f, 0x00, 0x52, 0x00, 0x06, +0x7c, 0x03, 0x04, 0x2c, 0x00, 0x02, 0x42, 0x0d, 0x60, 0x6c, 0x69, 0x62, +0x6c, 0x7a, 0x34, 0xf3, 0x04, 0x59, 0x61, 0x20, 0x44, 0x4c, 0x4c, 0xa7, +0x1f, 0x20, 0x62, 0x65, 0x21, 0x15, 0x01, 0x7d, 0x02, 0x00, 0x6c, 0x00, +0x01, 0x35, 0x13, 0x66, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x73, 0xb7, 0x1f, +0x00, 0x0f, 0x14, 0x73, 0x74, 0x79, 0x70, 0x65, 0x64, 0x65, 0x66, 0x93, +0x00, 0x35, 0x20, 0x7b, 0x20, 0x50, 0x01, 0x20, 0x20, 0x74, 0x63, 0x20, +0x1e, 0x5b, 0x7c, 0x01, 0x49, 0x5d, 0x3b, 0x20, 0x7d, 0x65, 0x01, 0x27, +0x3b, 0x0a, 0x7a, 0x01, 0x52, 0x72, 0x65, 0x73, 0x65, 0x74, 0x5b, 0x02, +0x00, 0x13, 0x00, 0x0e, 0x3e, 0x07, 0x22, 0x74, 0x6f, 0x55, 0x01, 0x27, +0x61, 0x6e, 0x1f, 0x01, 0x08, 0x4f, 0x00, 0x06, 0x1f, 0x01, 0x01, 0xa2, +0x00, 0x00, 0x96, 0x0d, 0x0c, 0x5a, 0x00, 0x28, 0x20, 0x28, 0x31, 0x00, +0x13, 0x2a, 0xbd, 0x01, 0x49, 0x50, 0x74, 0x72, 0x29, 0x8c, 0x00, 0x00, +0xde, 0x1d, 0x23, 0x74, 0x65, 0x33, 0x00, 0x01, 0x82, 0x04, 0x05, 0x9e, +0x0e, 0x00, 0x1d, 0x04, 0x00, 0x87, 0x00, 0x30, 0x69, 0x61, 0x6c, 0x8d, +0x06, 0x2f, 0x61, 0x6e, 0x83, 0x00, 0x07, 0x01, 0x1a, 0x00, 0x34, 0x66, +0x72, 0x65, 0x49, 0x00, 0x21, 0x72, 0x65, 0x67, 0x01, 0x11, 0x73, 0x26, +0x21, 0x02, 0x0f, 0x09, 0x02, 0xb4, 0x21, 0x02, 0x09, 0x06, 0x01, 0x1e, +0x02, 0x11, 0x78, 0x9d, 0x26, 0x01, 0x97, 0x01, 0x22, 0x20, 0x28, 0xa8, +0x01, 0x19, 0x29, 0xa0, 0x01, 0x55, 0x74, 0x68, 0x65, 0x73, 0x65, 0x93, +0x01, 0x44, 0x72, 0x61, 0x74, 0x68, 0x07, 0x09, 0x24, 0x74, 0x68, 0x0c, +0x02, 0x03, 0x86, 0x00, 0x01, 0x5d, 0x00, 0x41, 0x54, 0x68, 0x65, 0x79, +0xfb, 0x01, 0x01, 0x51, 0x1b, 0x42, 0x66, 0x75, 0x74, 0x75, 0xa9, 0x04, +0x20, 0x6f, 0x66, 0x19, 0x04, 0x01, 0x1b, 0x13, 0x02, 0x72, 0x00, 0x02, +0xf1, 0x20, 0x00, 0x0c, 0x00, 0x0a, 0xd1, 0x00, 0x32, 0x69, 0x7a, 0x65, +0xf2, 0x01, 0x0a, 0x3a, 0x01, 0x0c, 0x27, 0x01, 0x08, 0x2c, 0x0f, 0x06, +0x01, 0x00, 0x0b, 0x02, 0x01, 0x0f, 0x7e, 0x01, 0x13, 0x8f, 0x6c, 0x6f, +0x61, 0x64, 0x44, 0x69, 0x63, 0x74, 0x07, 0x02, 0x06, 0x00, 0x21, 0x00, +0x24, 0x20, 0x61, 0xed, 0x00, 0x21, 0x64, 0x69, 0x19, 0x00, 0x00, 0x86, +0x22, 0x01, 0x42, 0x08, 0x06, 0x64, 0x00, 0x01, 0x95, 0x03, 0x11, 0x41, +0xdf, 0x09, 0x26, 0x65, 0x76, 0x86, 0x05, 0x04, 0xcc, 0x0d, 0x50, 0x66, +0x6f, 0x72, 0x67, 0x6f, 0x27, 0x0d, 0x12, 0x2c, 0x75, 0x03, 0x16, 0x27, +0x4a, 0x00, 0x12, 0x27, 0x25, 0x00, 0x30, 0x72, 0x65, 0x6d, 0xe4, 0x28, +0x28, 0x69, 0x6e, 0xaf, 0x01, 0x32, 0x4c, 0x6f, 0x61, 0x87, 0x06, 0x05, +0x10, 0x1a, 0x12, 0x30, 0x96, 0x15, 0x31, 0x6c, 0x6f, 0x77, 0xf8, 0x06, +0x00, 0xea, 0x1f, 0x03, 0x00, 0x08, 0x07, 0x9c, 0x00, 0x13, 0x73, 0x8c, +0x05, 0x03, 0x2c, 0x07, 0x0c, 0xe4, 0x07, 0x50, 0x36, 0x34, 0x20, 0x4b, +0x42, 0x5d, 0x20, 0x06, 0x1b, 0x06, 0x04, 0x08, 0x01, 0x0f, 0x37, 0x01, +0x06, 0x0a, 0x6d, 0x10, 0x06, 0x6c, 0x00, 0x02, 0xf3, 0x05, 0x00, 0x10, +0x00, 0x07, 0xe0, 0x09, 0x2f, 0x20, 0x2a, 0xc4, 0x10, 0x00, 0x00, 0x74, +0x02, 0x31, 0x69, 0x6e, 0x75, 0xae, 0x02, 0x04, 0xcd, 0x05, 0x08, 0x65, +0x24, 0x00, 0xae, 0x04, 0x63, 0x27, 0x73, 0x72, 0x63, 0x27, 0x2c, 0x3b, +0x04, 0x01, 0x41, 0x01, 0x01, 0x96, 0x0a, 0x04, 0x54, 0x01, 0x2d, 0x6c, +0x79, 0x4a, 0x08, 0x10, 0x73, 0x5b, 0x04, 0x07, 0xfb, 0x00, 0x25, 0x74, +0x6f, 0xe3, 0x20, 0x0d, 0x19, 0x21, 0x02, 0x02, 0x03, 0x07, 0x39, 0x05, +0x19, 0x50, 0xac, 0x01, 0x04, 0x50, 0x00, 0x10, 0x72, 0xdf, 0x13, 0x33, +0x73, 0x75, 0x6d, 0xc4, 0x1e, 0x13, 0x74, 0xc3, 0x01, 0x00, 0x4c, 0x00, +0x00, 0xa4, 0x00, 0x01, 0x41, 0x2b, 0x15, 0x6e, 0xa5, 0x0b, 0x01, 0x50, +0x05, 0x27, 0x27, 0x64, 0x11, 0x10, 0x0f, 0x99, 0x1b, 0x09, 0x01, 0x36, +0x25, 0x00, 0x21, 0x07, 0x03, 0xc4, 0x0e, 0x0f, 0xbd, 0x16, 0x0a, 0x00, +0x74, 0x01, 0x0f, 0x5e, 0x1f, 0x0f, 0x02, 0x45, 0x08, 0x07, 0x24, 0x1f, +0x04, 0x67, 0x00, 0x32, 0x6e, 0x6f, 0x74, 0x1c, 0x00, 0x2d, 0x69, 0x66, +0x85, 0x25, 0x03, 0x13, 0x1f, 0x25, 0x66, 0x69, 0xfc, 0x10, 0x07, 0xc1, +0x00, 0x02, 0x3f, 0x02, 0x0d, 0xf6, 0x1e, 0x02, 0x4d, 0x00, 0x07, 0xe4, +0x1e, 0x00, 0x79, 0x02, 0x00, 0xd8, 0x05, 0x03, 0xe4, 0x1e, 0x07, 0x4f, +0x02, 0x0f, 0xfa, 0x01, 0x03, 0x0f, 0x5d, 0x02, 0x14, 0x35, 0x73, 0x72, +0x63, 0x7f, 0x08, 0x05, 0xbe, 0x14, 0x2a, 0x72, 0x63, 0x61, 0x08, 0x0f, +0xc3, 0x12, 0x09, 0x07, 0x63, 0x07, 0x34, 0x61, 0x76, 0x65, 0xdf, 0x03, +0x2f, 0x49, 0x66, 0x48, 0x02, 0x04, 0x06, 0xfd, 0x01, 0x04, 0xab, 0x1c, +0x0a, 0x68, 0x01, 0x03, 0x9a, 0x03, 0x51, 0x61, 0x76, 0x61, 0x69, 0x6c, +0xd2, 0x26, 0x27, 0x61, 0x74, 0x57, 0x05, 0x14, 0x20, 0xe5, 0x18, 0x00, +0x64, 0x00, 0x00, 0x70, 0x00, 0x14, 0x20, 0x54, 0x01, 0x20, 0x61, 0x20, +0x66, 0x09, 0x21, 0x72, 0x20, 0xf0, 0x15, 0x23, 0x20, 0x28, 0xdd, 0x00, +0x41, 0x61, 0x66, 0x65, 0x42, 0x67, 0x01, 0x01, 0xde, 0x23, 0x03, 0x53, +0x0b, 0x00, 0x34, 0x07, 0x55, 0x64, 0x6f, 0x6e, 0x27, 0x74, 0x4e, 0x27, +0x00, 0x65, 0x07, 0x09, 0x9a, 0x03, 0xa0, 0x28, 0x29, 0x20, 0x61, 0x66, +0x74, 0x65, 0x72, 0x77, 0x61, 0x05, 0x10, 0x07, 0x73, 0x07, 0x08, 0x94, +0x04, 0x27, 0x73, 0x20, 0x99, 0x20, 0x00, 0xf6, 0x23, 0x63, 0x62, 0x6c, +0x65, 0x2c, 0x20, 0x79, 0xed, 0x28, 0x06, 0x3e, 0x0a, 0x05, 0x5e, 0x00, +0x0f, 0xa9, 0x01, 0x03, 0x29, 0x28, 0x29, 0x5a, 0x04, 0x00, 0xd6, 0x00, +0x1c, 0x64, 0x60, 0x04, 0x0f, 0x5f, 0x04, 0x07, 0x05, 0x0d, 0x04, 0x15, +0x2c, 0xda, 0x11, 0x01, 0xcd, 0x1d, 0x09, 0x22, 0x02, 0x04, 0x9a, 0x01, +0x0f, 0x71, 0x04, 0x09, 0x0b, 0x31, 0x01, 0x0e, 0x6b, 0x04, 0x0e, 0x53, +0x0a, 0x0f, 0x54, 0x0a, 0x1b, 0x06, 0xa7, 0x0a, 0x0f, 0x56, 0x0a, 0x2a, +0x00, 0x63, 0x1d, 0x0e, 0x1b, 0x0a, 0x65, 0x44, 0x45, 0x43, 0x4f, 0x44, +0x45, 0x0d, 0x0a, 0x2f, 0x20, 0x34, 0x24, 0x00, 0x0a, 0x0c, 0x45, 0x0a, +0x0b, 0x3e, 0x00, 0x05, 0x4b, 0x0a, 0x04, 0xe3, 0x1c, 0x18, 0x20, 0x54, +0x0a, 0x0d, 0x21, 0x09, 0x0e, 0x26, 0x00, 0x0d, 0x2a, 0x09, 0x0a, 0x61, +0x00, 0x0b, 0x30, 0x09, 0x11, 0x44, 0x59, 0x0d, 0x00, 0x36, 0x09, 0x0c, +0xaf, 0x0a, 0x04, 0x1a, 0x00, 0x0f, 0xb5, 0x0a, 0x23, 0x0f, 0xa9, 0x0a, +0x08, 0x23, 0x75, 0x73, 0x4e, 0x0a, 0x15, 0x5f, 0x42, 0x09, 0x02, 0x6c, +0x00, 0x12, 0x20, 0xde, 0x1c, 0x20, 0x73, 0x65, 0x03, 0x03, 0x0f, 0xcf, +0x0a, 0x02, 0x0f, 0xd9, 0x08, 0x11, 0x04, 0xd8, 0x08, 0x30, 0x70, 0x72, +0x65, 0x94, 0x03, 0x02, 0x11, 0x27, 0x2f, 0x6f, 0x66, 0x7e, 0x0a, 0x03, +0x01, 0x99, 0x0a, 0x0f, 0xd3, 0x08, 0x2f, 0x04, 0x2c, 0x01, 0x05, 0x30, +0x03, 0x24, 0x74, 0x68, 0x44, 0x00, 0x1f, 0x2e, 0xff, 0x09, 0x01, 0x03, +0xf0, 0x00, 0x0f, 0x05, 0x0a, 0x17, 0x06, 0x61, 0x00, 0x0f, 0x0b, 0x0a, +0x07, 0x03, 0x55, 0x00, 0x0f, 0x11, 0x0a, 0x04, 0x2e, 0x2f, 0x0a, 0x4e, +0x00, 0x0f, 0x99, 0x00, 0x05, 0x0e, 0x77, 0x09, 0x0f, 0x7d, 0x09, 0x05, +0x03, 0x74, 0x00, 0x1f, 0x28, 0x5c, 0x00, 0x05, 0x02, 0x14, 0x00, 0x0b, +0xab, 0x05, 0x0a, 0xf6, 0x01, 0x0f, 0x98, 0x0b, 0x08, 0x03, 0xe6, 0x02, +0x02, 0xfb, 0x16, 0x01, 0xe8, 0x16, 0x03, 0x7f, 0x25, 0x06, 0xa2, 0x04, +0x01, 0x5f, 0x01, 0x12, 0x53, 0x14, 0x26, 0x0f, 0x3d, 0x09, 0x04, 0x21, +0x20, 0x28, 0xc9, 0x1b, 0x02, 0xf4, 0x28, 0x02, 0xd0, 0x1b, 0x4a, 0x73, +0x65, 0x74, 0x29, 0x54, 0x09, 0x10, 0x31, 0xbd, 0x04, 0x3f, 0x4f, 0x4b, +0x2c, 0xc6, 0x04, 0x06, 0x2f, 0x65, 0x74, 0xf2, 0x00, 0x19, 0x02, 0x14, +0x00, 0x0f, 0x4b, 0x09, 0x1a, 0x17, 0x2a, 0x95, 0x05, 0x05, 0x1a, 0x13, +0x00, 0x97, 0x0b, 0x05, 0xa3, 0x10, 0x05, 0xc2, 0x2d, 0x02, 0xda, 0x00, +0x0b, 0x29, 0x12, 0x80, 0x6f, 0x66, 0x20, 0x6d, 0x75, 0x6c, 0x74, 0x69, +0x39, 0x29, 0x03, 0xe1, 0x08, 0x54, 0x69, 0x6e, 0x20, 0x22, 0x73, 0x04, +0x05, 0x10, 0x22, 0x6f, 0x14, 0x03, 0x4b, 0x12, 0x16, 0x50, 0x1f, 0x07, +0x04, 0x39, 0x12, 0x03, 0x64, 0x09, 0x10, 0x2a, 0xd4, 0x08, 0x1f, 0x2a, +0x0a, 0x07, 0x02, 0x01, 0x0d, 0x21, 0x02, 0x0a, 0x07, 0x05, 0x6b, 0x13, +0x03, 0x9b, 0x01, 0x00, 0x3c, 0x03, 0x08, 0xa8, 0x11, 0x40, 0x20, 0x28, +0x75, 0x70, 0xb1, 0x01, 0x04, 0x80, 0x0a, 0x25, 0x20, 0x20, 0xb7, 0x03, +0x05, 0x48, 0x03, 0x10, 0x72, 0xd3, 0x00, 0x02, 0x88, 0x08, 0x17, 0x73, +0x26, 0x24, 0x0b, 0x5b, 0x09, 0x03, 0xde, 0x19, 0x02, 0x10, 0x01, 0x51, +0x2d, 0x20, 0x45, 0x78, 0x61, 0xb8, 0x0e, 0x01, 0xd2, 0x01, 0x01, 0x3a, +0x25, 0x59, 0x61, 0x73, 0x20, 0x65, 0x6e, 0x3c, 0x00, 0x03, 0x1d, 0x1e, +0x01, 0x23, 0x00, 0x30, 0x75, 0x70, 0x64, 0x5b, 0x03, 0x62, 0x72, 0x75, +0x6c, 0x65, 0x20, 0x28, 0xfa, 0x07, 0x07, 0x2c, 0x16, 0x22, 0x61, 0x74, +0x26, 0x00, 0x04, 0xcf, 0x00, 0x14, 0x73, 0x01, 0x13, 0x23, 0x49, 0x6e, +0x90, 0x1d, 0x00, 0xaf, 0x00, 0x02, 0x3c, 0x12, 0x05, 0x86, 0x01, 0x16, +0x26, 0x70, 0x00, 0x07, 0xc3, 0x00, 0x01, 0x77, 0x07, 0x32, 0x68, 0x61, +0x76, 0xfa, 0x15, 0x04, 0x97, 0x0b, 0x04, 0x07, 0x24, 0x42, 0x76, 0x65, +0x72, 0x79, 0xfd, 0x12, 0x30, 0x20, 0x6f, 0x6e, 0x49, 0x07, 0x23, 0x20, +0x3c, 0x1c, 0x01, 0x13, 0x2e, 0xd9, 0x00, 0x14, 0x4c, 0x5a, 0x1f, 0x2e, +0x61, 0x6e, 0xd0, 0x00, 0x2a, 0x62, 0x79, 0x33, 0x17, 0x40, 0x6d, 0x61, +0x78, 0x42, 0xcc, 0x00, 0x01, 0x59, 0x0a, 0x01, 0xb0, 0x04, 0x07, 0x36, +0x17, 0x1a, 0x20, 0x1f, 0x00, 0x01, 0x2a, 0x08, 0x36, 0x70, 0x6c, 0x65, +0x65, 0x34, 0x30, 0x64, 0x65, 0x70, 0x4b, 0x29, 0x32, 0x6e, 0x74, 0x2e, +0x6e, 0x1f, 0x0d, 0xe5, 0x22, 0x00, 0x46, 0x08, 0x01, 0xa9, 0x16, 0x18, +0x64, 0xdc, 0x1c, 0x05, 0xeb, 0x08, 0x34, 0x69, 0x6e, 0x67, 0x63, 0x02, +0x1f, 0x2e, 0x30, 0x01, 0x03, 0x27, 0x65, 0x6e, 0x55, 0x13, 0x0b, 0xda, +0x01, 0x41, 0x73, 0x20, 0x64, 0x6f, 0x7b, 0x09, 0x04, 0x00, 0x09, 0x00, +0x17, 0x14, 0x94, 0x79, 0x6e, 0x63, 0x68, 0x72, 0x6f, 0x6e, 0x69, 0x7a, +0x0d, 0x15, 0x02, 0xbe, 0x1d, 0x0f, 0x69, 0x01, 0x1f, 0x0f, 0x64, 0x01, +0x0a, 0x40, 0x5f, 0x41, 0x74, 0x20, 0x1c, 0x05, 0x22, 0x74, 0x5f, 0x19, +0x00, 0x43, 0x20, 0x2b, 0x20, 0x38, 0xda, 0x08, 0x19, 0x2b, 0x35, 0x01, +0x0f, 0xd7, 0x00, 0x7e, 0x17, 0x6c, 0x1e, 0x02, 0x0b, 0x79, 0x00, 0x02, +0xac, 0x00, 0x32, 0x57, 0x68, 0x65, 0x5d, 0x14, 0x02, 0xca, 0x0f, 0x0a, +0x8c, 0x37, 0x02, 0x99, 0x18, 0x03, 0x9d, 0x1c, 0x12, 0x2c, 0xbb, 0x0a, +0x01, 0xd3, 0x1d, 0x00, 0xda, 0x17, 0x00, 0x90, 0x2e, 0x02, 0x7f, 0x28, +0x02, 0xba, 0x03, 0x01, 0x24, 0x0b, 0x07, 0xd6, 0x0a, 0x04, 0x85, 0x02, +0x05, 0x53, 0x1f, 0x05, 0xa1, 0x1c, 0x02, 0xfc, 0x03, 0x11, 0x69, 0xaf, +0x14, 0x02, 0x39, 0x0a, 0x0f, 0xda, 0x07, 0x06, 0x2f, 0x28, 0x29, 0x9e, +0x14, 0x09, 0x0e, 0x36, 0x0c, 0x0f, 0x55, 0x05, 0x0b, 0x0f, 0x70, 0x2d, +0x3b, 0x0f, 0xf3, 0x18, 0x04, 0x0f, 0x96, 0x00, 0x42, 0x0c, 0x22, 0x19, +0x00, 0xf8, 0x05, 0x05, 0x87, 0x27, 0x0f, 0xe8, 0x05, 0x00, 0x41, 0x3a, +0x0a, 0x2a, 0x5f, 0x55, 0x01, 0x03, 0x18, 0x0c, 0x0f, 0x17, 0x06, 0x0c, +0x48, 0x77, 0x6f, 0x72, 0x6b, 0xba, 0x22, 0x02, 0xb4, 0x01, 0x00, 0x0c, +0x01, 0x14, 0x62, 0x0d, 0x18, 0x2f, 0x6f, 0x66, 0xa0, 0x01, 0x03, 0x03, +0xa8, 0x38, 0x02, 0xae, 0x22, 0x0b, 0x0f, 0x01, 0x19, 0x78, 0x2f, 0x0c, +0x26, 0x20, 0x20, 0x2c, 0x09, 0xc2, 0x73, 0x74, 0x61, 0x6e, 0x64, 0x2d, +0x61, 0x6c, 0x6f, 0x6e, 0x65, 0x2e, 0x16, 0x00, 0x07, 0xdc, 0x0c, 0x00, +0xb0, 0x28, 0x03, 0x80, 0x05, 0x0f, 0xcc, 0x08, 0x0c, 0x1f, 0x2e, 0x1e, +0x02, 0x09, 0x05, 0x00, 0x01, 0x0f, 0x69, 0x2f, 0x3a, 0x0e, 0x9b, 0x07, +0x5d, 0x53, 0x74, 0x61, 0x72, 0x74, 0x9a, 0x07, 0x0f, 0x1e, 0x02, 0x05, +0x0e, 0x96, 0x00, 0x0f, 0x1b, 0x1b, 0x12, 0x0f, 0x7b, 0x00, 0x19, 0x0f, +0xce, 0x29, 0x1b, 0x40, 0x4f, 0x62, 0x73, 0x6f, 0x9d, 0x20, 0x0f, 0xce, +0x29, 0x20, 0x10, 0x2f, 0x07, 0x32, 0x00, 0xd3, 0x2c, 0x00, 0xab, 0x01, +0x30, 0x57, 0x61, 0x72, 0x43, 0x33, 0x22, 0x73, 0x20, 0x19, 0x00, 0x15, +0x53, 0xdb, 0x19, 0x44, 0x73, 0x65, 0x20, 0x77, 0x1c, 0x00, 0x10, 0x6d, +0x06, 0x0e, 0x00, 0xc9, 0x34, 0x01, 0xcd, 0x1d, 0x71, 0x70, 0x72, 0x6f, +0x62, 0x6c, 0x65, 0x6d, 0x23, 0x04, 0x02, 0x0f, 0x04, 0x02, 0x22, 0x36, +0x00, 0x3d, 0x16, 0x05, 0x14, 0x21, 0x00, 0x08, 0x1a, 0x11, 0x69, 0xa7, +0x0e, 0x00, 0x4d, 0x00, 0x02, 0x2d, 0x00, 0x01, 0xa8, 0x07, 0x64, 0x2d, +0x57, 0x6e, 0x6f, 0x2d, 0x64, 0x80, 0x00, 0x72, 0x64, 0x2d, 0x64, 0x65, +0x63, 0x6c, 0x61, 0xe3, 0x0f, 0x02, 0xce, 0x1d, 0x42, 0x67, 0x63, 0x63, +0x0a, 0x3c, 0x20, 0x70, 0x5f, 0x43, 0x52, 0x54, 0x5f, 0x53, 0x45, 0x2f, +0x39, 0xc0, 0x5f, 0x4e, 0x4f, 0x5f, 0x57, 0x41, 0x52, 0x4e, 0x49, 0x4e, +0x47, 0x53, 0xe8, 0x08, 0x68, 0x56, 0x69, 0x73, 0x75, 0x61, 0x6c, 0x7f, +0x28, 0x18, 0x2e, 0xfe, 0x37, 0x01, 0x7c, 0x26, 0x07, 0x95, 0x0d, 0x94, +0x44, 0x45, 0x50, 0x52, 0x45, 0x43, 0x41, 0x54, 0x45, 0x45, 0x00, 0x00, +0x95, 0x25, 0x61, 0x42, 0x4c, 0x4f, 0x43, 0x4b, 0x2e, 0x97, 0x2a, 0x30, +0x69, 0x66, 0x6e, 0x67, 0x0d, 0x0f, 0x2b, 0x00, 0x0b, 0x3e, 0x0a, 0x23, +0x20, 0x54, 0x00, 0x0f, 0x29, 0x00, 0x10, 0x34, 0x47, 0x43, 0x43, 0x04, +0x35, 0x00, 0xe0, 0x37, 0x92, 0x47, 0x4e, 0x55, 0x43, 0x5f, 0x5f, 0x20, +0x2a, 0x20, 0x22, 0x35, 0x03, 0x11, 0x00, 0x01, 0x36, 0x35, 0x30, 0x5f, +0x5f, 0x29, 0x3c, 0x00, 0x4c, 0x69, 0x66, 0x20, 0x28, 0x39, 0x00, 0xa4, +0x3e, 0x3d, 0x20, 0x34, 0x30, 0x35, 0x29, 0x20, 0x7c, 0x7c, 0x2c, 0x38, +0x00, 0x2b, 0x38, 0x43, 0x6c, 0x61, 0x6e, 0x67, 0x35, 0x00, 0x0f, 0x9c, +0x00, 0x03, 0x23, 0x44, 0x28, 0xbc, 0x01, 0x62, 0x29, 0x20, 0x5f, 0x5f, +0x61, 0x74, 0x42, 0x3c, 0x56, 0x65, 0x5f, 0x5f, 0x28, 0x28, 0x83, 0x01, +0x05, 0x23, 0x00, 0x11, 0x29, 0x49, 0x00, 0x2f, 0x65, 0x6c, 0x80, 0x00, +0x04, 0x3f, 0x33, 0x30, 0x31, 0x6a, 0x00, 0x2c, 0x07, 0x61, 0x00, 0x05, +0xc5, 0x00, 0x21, 0x4d, 0x53, 0x65, 0x00, 0x0f, 0x5a, 0x00, 0x15, 0x00, +0x2f, 0x02, 0x00, 0x0c, 0x20, 0x0f, 0xc0, 0x00, 0x02, 0x02, 0x5e, 0x00, +0x22, 0x73, 0x65, 0x4c, 0x00, 0x03, 0x65, 0x39, 0x03, 0x1e, 0x00, 0x23, +0x28, 0x22, 0xa7, 0x01, 0x37, 0x3a, 0x20, 0x59, 0xdd, 0x38, 0x05, 0x2d, +0x09, 0x0b, 0x74, 0x00, 0x02, 0x35, 0x37, 0x00, 0xa4, 0x0c, 0x02, 0x18, +0x2b, 0x3f, 0x65, 0x72, 0x22, 0xa3, 0x00, 0x12, 0x01, 0x83, 0x00, 0x01, +0xa9, 0x39, 0x02, 0xb0, 0x39, 0x00, 0x0d, 0x2d, 0x0f, 0x2e, 0x02, 0x0b, +0x12, 0x20, 0xc1, 0x38, 0x06, 0xd2, 0x03, 0x0f, 0xc6, 0x39, 0x02, 0x03, +0xa0, 0x03, 0x02, 0x0c, 0x06, 0x07, 0x1a, 0x0c, 0x00, 0xb6, 0x0e, 0x44, +0x6c, 0x61, 0x6e, 0x6e, 0xd4, 0x14, 0x36, 0x61, 0x72, 0x74, 0xb1, 0x39, +0x05, 0xc1, 0x03, 0xf2, 0x01, 0x62, 0x79, 0x20, 0x72, 0x31, 0x33, 0x31, +0x20, 0x61, 0x70, 0x70, 0x72, 0x6f, 0x78, 0x69, 0x6d, 0x47, 0x12, 0x0f, +0xd8, 0x13, 0x00, 0x0b, 0xfe, 0x0d, 0x0f, 0x81, 0x28, 0x1c, 0x0f, 0xe7, +0x26, 0x01, 0x03, 0x7f, 0x33, 0x02, 0x4c, 0x1c, 0x0f, 0xd2, 0x28, 0x26, +0x07, 0xeb, 0x31, 0x0f, 0x64, 0x00, 0x00, 0x00, 0x59, 0x04, 0x02, 0x47, +0x27, 0x0b, 0xbf, 0x00, 0x0f, 0x55, 0x27, 0x27, 0x0f, 0xcb, 0x00, 0x0e, +0x07, 0x75, 0x00, 0x0f, 0xbc, 0x27, 0x31, 0x0f, 0xe1, 0x00, 0x0b, 0x05, +0x9d, 0x08, 0x0c, 0xe1, 0x00, 0x0e, 0x50, 0x19, 0x0e, 0x7c, 0x15, 0x0f, +0xf1, 0x00, 0x35, 0x06, 0x85, 0x00, 0x0f, 0x77, 0x00, 0x38, 0x0f, 0x01, +0x01, 0x03, 0x09, 0x10, 0x03, 0x2f, 0x64, 0x65, 0x12, 0x03, 0x17, 0x30, +0x20, 0x6e, 0x61, 0xf3, 0x22, 0x13, 0x61, 0x6c, 0x2a, 0x03, 0xbf, 0x27, +0x06, 0x2c, 0x04, 0x01, 0xd3, 0x0a, 0x01, 0x6d, 0x0e, 0x21, 0x6e, 0x6f, +0x3f, 0x13, 0x41, 0x65, 0x72, 0x20, 0x62, 0x15, 0x1b, 0x02, 0x6d, 0x20, +0x05, 0xeb, 0x08, 0x01, 0xcd, 0x19, 0x05, 0x20, 0x2f, 0x01, 0xfb, 0x0a, +0x04, 0x25, 0x2f, 0x31, 0x61, 0x74, 0x69, 0x83, 0x3b, 0x03, 0x17, 0x28, +0x20, 0x6f, 0x6c, 0x0d, 0x44, 0x03, 0x43, 0x3d, 0x15, 0x73, 0xe1, 0x0d, +0x36, 0x5a, 0x34, 0x5f, 0x30, 0x26, 0x0c, 0x63, 0x2c, 0x0f, 0x63, 0x08, +0x00, 0x0f, 0x38, 0x00, 0x02, 0x30, 0x5f, 0x75, 0x6e, 0x03, 0x2b, 0x16, +0x6e, 0x1d, 0x01, 0x0f, 0x4a, 0x00, 0x0c, 0x00, 0x43, 0x09, 0x03, 0xc8, +0x00, 0x08, 0x16, 0x01, 0x00, 0x55, 0x20, 0x10, 0x6f, 0x4d, 0x14, 0x04, +0x21, 0x0c, 0x14, 0x77, 0x9e, 0x07, 0x22, 0x64, 0x3b, 0xd7, 0x26, 0x01, +0x03, 0x05, 0x00, 0xaa, 0x07, 0x02, 0xfa, 0x00, 0x03, 0x1b, 0x1e, 0x21, +0x72, 0x65, 0xd6, 0x07, 0x02, 0x2d, 0x05, 0x20, 0x68, 0x65, 0xed, 0x13, +0x04, 0x43, 0x25, 0x21, 0x68, 0x69, 0x6c, 0x2d, 0x08, 0xac, 0x37, 0x04, +0x27, 0x23, 0x02, 0x18, 0x0c, 0x02, 0x44, 0x08, 0x08, 0x7a, 0x00, 0x00, +0x7b, 0x01, 0x21, 0x69, 0x67, 0x9a, 0x04, 0x30, 0x74, 0x6f, 0x20, 0x72, +0x10, 0x21, 0x74, 0x61, 0xf6, 0x3e, 0x01, 0xc1, 0x0d, 0x02, 0xcf, 0x01, +0x04, 0x84, 0x02, 0x07, 0x3c, 0x01, 0x0f, 0x72, 0x09, 0x13, 0x07, 0x3f, +0x02, 0x0e, 0x4b, 0x00, 0x0f, 0x4f, 0x01, 0x01, 0x0f, 0x6c, 0x28, 0x17, +0x3f, 0x20, 0x69, 0x73, 0xaa, 0x02, 0x05, 0x0d, 0xbd, 0x05, 0x05, 0x80, +0x11, 0x06, 0xa8, 0x0b, 0x11, 0x3b, 0xd0, 0x14, 0x00, 0xd7, 0x3d, 0x06, +0x1d, 0x00, 0x06, 0x24, 0x3e, 0x14, 0x77, 0xcb, 0x0d, 0x05, 0x3b, 0x09, +0x03, 0xbc, 0x13, 0x07, 0x5d, 0x06, 0x11, 0x22, 0x30, 0x46, 0x0c, 0x2d, +0x1d, 0x14, 0x29, 0x4d, 0x1f, 0x32, 0x22, 0x29, 0x20, 0x82, 0x04, 0x06, +0xdf, 0x13, 0x04, 0x96, 0x18, 0x01, 0x68, 0x03, 0x03, 0x97, 0x18, 0x1f, +0x3b, 0x57, 0x00, 0x1f, 0x02, 0x12, 0x14, 0x08, 0xd2, 0x2c, 0x00, 0x23, +0x00, 0x09, 0xd8, 0x2c, 0x0f, 0x54, 0x00, 0x05, 0x07, 0x31, 0x1f, 0x09, +0x53, 0x00, 0x07, 0x54, 0x00, 0x07, 0x23, 0x00, 0x06, 0x53, 0x00, 0x06, +0x48, 0x05, 0x0f, 0xc1, 0x00, 0x18, 0x04, 0x75, 0x18, 0x0a, 0x6a, 0x00, +0x23, 0x20, 0x20, 0x45, 0x00, 0x01, 0x23, 0x00, 0x56, 0x6c, 0x69, 0x64, +0x65, 0x49, 0x4e, 0x00, 0x09, 0xb6, 0x05, 0x2f, 0x29, 0x3b, 0xc6, 0x01, +0x05, 0x0f, 0x77, 0x0d, 0x00, 0x0f, 0xa0, 0x01, 0x03, 0x0f, 0xcd, 0x0c, +0x0b, 0x0d, 0x56, 0x01, 0x0f, 0xfb, 0x0c, 0x01, 0x00, 0x4f, 0x04, 0xbf, +0x50, 0x72, 0x65, 0x66, 0x69, 0x78, 0x36, 0x34, 0x6b, 0x20, 0x28, 0x3b, +0x1b, 0x0d, 0x0f, 0xfb, 0x0c, 0x05, 0x05, 0xfe, 0x2a, 0x0f, 0xa6, 0x00, +0x10, 0x0a, 0xdd, 0x0c, 0x0f, 0xa6, 0x00, 0x0d, 0x01, 0x2e, 0x00, 0x0f, +0xa6, 0x00, 0x1c, 0x0d, 0x04, 0x0f, 0x0f, 0xef, 0x42, 0x07, 0x90, 0x7d, +0x0a, 0x23, 0x65, 0x6e, 0x64, 0x69, 0x66, 0x0a, +}; + +static unsigned char buf[18830]; + +int main() { + + unsigned long cksum = adler32(0, NULL, 0); + + decompress_lz4(compressed, buf, 18830); + cksum = adler32(cksum, buf, 18830); + + return cksum == 0xf748269d ? 0 : 1; +} diff --git a/test/val/postincdec.c b/test/val/postincdec.c new file mode 100644 index 000000000..6d3e9593c --- /dev/null +++ b/test/val/postincdec.c @@ -0,0 +1,23 @@ +/* + !!DESCRIPTION!! char-sized post-increment and -decrement + !!ORIGIN!! cc65 regression tests + !!LICENCE!! Public Domain + !!AUTHOR!! Lauri Kasanen +*/ + + +static unsigned char val, array[2]; + +int main() { + + val = 0; + array[0] = array[1] = 10; + + array[val++] = 2; + array[val++] = 2; + --val; + array[val--] = 0; + array[val--] = 0; + + return (array[0] == array[1] && array[0] == 0 && val == 0xff) ? 0 : 1; +} diff --git a/test/val/static-fwd-decl.c b/test/val/static-fwd-decl.c new file mode 100644 index 000000000..420640d97 --- /dev/null +++ b/test/val/static-fwd-decl.c @@ -0,0 +1,35 @@ +/* + !!DESCRIPTION!! static forward declarations + !!ORIGIN!! cc65 regression tests + !!LICENCE!! Public Domain + !!AUTHOR!! Bob Andrews +*/ + +/* + see: https://github.com/cc65/cc65/issues/204 +*/ + +#pragma warn(error, on) + +typedef struct _DIRMENU +{ + const char *name; + struct _DIRMENU *dest; +} DIRMENU; + +static DIRMENU rmenu; + +static DIRMENU lmenu = { + "left", + &rmenu +}; + +static DIRMENU rmenu = { + "right", + &lmenu +}; + +int main(void) +{ + return lmenu.dest == &rmenu && rmenu.dest == &lmenu ? 0 : 1; +} diff --git a/test/val/trampoline-params.c b/test/val/trampoline-params.c new file mode 100644 index 000000000..890e43e5f --- /dev/null +++ b/test/val/trampoline-params.c @@ -0,0 +1,32 @@ +/* + !!DESCRIPTION!! wrapped-call pragma w/ many params + !!ORIGIN!! cc65 regression tests + !!LICENCE!! Public Domain + !!AUTHOR!! Lauri Kasanen +*/ + +#include <stdarg.h> + +static unsigned char flag; + +static void trampoline_set() { + asm("ldy tmp4"); + asm("sty %v", flag); + asm("jsr callptr4"); +} + +#pragma wrapped-call(push, trampoline_set, 4) +long adder(long in); +#pragma wrapped-call(pop) + +long adder(long in) { + + return in + 7; +} + +int main() { + + flag = 0; + + return adder(70436) == 70436 + 7 && flag == 4 ? 0 : 1; +} diff --git a/test/val/trampoline-varargs.c b/test/val/trampoline-varargs.c new file mode 100644 index 000000000..d154a3da0 --- /dev/null +++ b/test/val/trampoline-varargs.c @@ -0,0 +1,48 @@ +/* + !!DESCRIPTION!! wrapped-call pragma w/ variadic function + !!ORIGIN!! cc65 regression tests + !!LICENCE!! Public Domain + !!AUTHOR!! Lauri Kasanen +*/ + +#include <stdarg.h> + +static unsigned char flag; + +static void trampoline_set() { + // The Y register is used for variadics - save and restore + asm("sty tmp3"); + + asm("ldy tmp4"); + asm("sty %v", flag); + + asm("ldy tmp3"); + asm("jsr callptr4"); +} + +#pragma wrapped-call(push, trampoline_set, 4) +unsigned adder(unsigned char num, ...); +#pragma wrapped-call(pop) + +unsigned adder(unsigned char num, ...) { + + unsigned char i; + unsigned sum = 0; + va_list ap; + va_start(ap, num); + + for (i = 0; i < num; i++) { + sum += va_arg(ap, unsigned); + } + + va_end(ap); + + return sum; +} + +int main() { + + flag = 0; + + return adder(3, 0, 5, 500) == 505 && flag == 4 ? 0 : 1; +} diff --git a/test/val/trampoline.c b/test/val/trampoline.c new file mode 100644 index 000000000..63741b590 --- /dev/null +++ b/test/val/trampoline.c @@ -0,0 +1,49 @@ +/* + !!DESCRIPTION!! wrapped-call pragma used for trampolines + !!ORIGIN!! cc65 regression tests + !!LICENCE!! Public Domain + !!AUTHOR!! Lauri Kasanen +*/ + +static unsigned char flag; + +static void trampoline_set() { + asm("ldy tmp4"); + asm("sty %v", flag); + asm("jsr callptr4"); +} + +void trampoline_inc() { + asm("inc %v", flag); + asm("jsr callptr4"); +} + +void func3() { + +} + +#pragma wrapped-call(push, trampoline_inc, 0) + +void func2() { + func3(); +} + +#pragma wrapped-call(push, trampoline_set, 4) + +void func1(void); + +#pragma wrapped-call(pop) +#pragma wrapped-call(pop) + +void func1() { + func2(); +} + +int main(void) +{ + flag = 0; + + func1(); + + return flag == 5 ? 0 : 1; +} diff --git a/test/val/unittest.h b/test/val/unittest.h new file mode 100644 index 000000000..bd355bb0c --- /dev/null +++ b/test/val/unittest.h @@ -0,0 +1,89 @@ +/*****************************************************************************/ +/* */ +/* unittest.h */ +/* */ +/* Unit test helper macros */ +/* */ +/* */ +/* */ +/* (C) 2017 Christian Krueger */ +/* */ +/* This software is provided 'as-is', without any expressed or implied */ +/* warranty. In no event will the authors be held liable for any damages */ +/* arising from the use of this software. */ +/* */ +/* Permission is granted to anyone to use this software for any purpose, */ +/* including commercial applications, and to alter it and redistribute it */ +/* freely, subject to the following restrictions: */ +/* */ +/* 1. The origin of this software must not be misrepresented; you must not */ +/* claim that you wrote the original software. If you use this software */ +/* in a product, an acknowledgment in the product documentation would be */ +/* appreciated but is not required. */ +/* 2. Altered source versions must be plainly marked as such, and must not */ +/* be misrepresented as being the original software. */ +/* 3. This notice may not be removed or altered from any source */ +/* distribution. */ +/* */ +/*****************************************************************************/ + +#ifndef _UNITTEST_H +#define _UNITTEST_H + +#include <stdio.h> +#include <stdlib.h> + +#ifndef COMMA +#define COMMA , +#endif + +#define TEST int main(void) \ + {\ + printf("%s: ",__FILE__); + +#define ENDTEST printf("Passed\n"); \ + return EXIT_SUCCESS; \ + } + +#define ASSERT_IsTrue(a,b) if (!(a)) \ + {\ + printf("Fail at line %d:\n",__LINE__);\ + printf(b);\ + printf("\n");\ + printf("Expected status should be true but wasn't!\n");\ + exit(EXIT_FAILURE);\ + } + +#define ASSERT_IsFalse(a,b) if ((a)) \ + {\ + printf("Fail at line %d:\n",__LINE__);\ + printf(b);\ + printf("\n");\ + printf("Expected status should be false but wasn't!\n");\ + exit(EXIT_FAILURE);\ + } + +#define ASSERT_AreEqual(a,b,c,d) if ((a) != (b)) \ + {\ + printf("Fail at line %d:\n",__LINE__);\ + printf(d);\ + printf("\n");\ + printf("Expected value: "c", but is "c"!\n", (a), (b));\ + exit(EXIT_FAILURE);\ + } + +#define ASSERT_AreNotEqual(a,b,c,d) if ((a) == (b)) \ + {\ + printf("Fail at line %d:\n",__LINE__);\ + printf(d);\ + printf("\n");\ + printf("Expected value not: "c", but is "c"!\n", (a), (b));\ + exit(EXIT_FAILURE);\ + } + +/* End of unittest.h */ +#endif + + + + diff --git a/test/val/void-size1.c b/test/val/void-size1.c new file mode 100644 index 000000000..0c2dccaa7 --- /dev/null +++ b/test/val/void-size1.c @@ -0,0 +1,56 @@ +/* + !!DESCRIPTION!! Getting the size of a void-type variable (cc65 extension) + !!ORIGIN!! cc65 regression tests + !!LICENCE!! Public Domain + !!AUTHOR!! Greg King +*/ + +static const void list1 = { + (char)1, + (char)2, + (char)3, + (char)4, + (char)5, + (char)6, + (char)7, + (char)8, + (char)9, + (char)0 +}; + +static void list2 = { + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 0 +}; + +void list3 = { + (char)1, + (char)2, + (char)3, + (char)4, + &list1, + (char)6, + (char)7, + (char)8, + (char)9, + &list2 +}; + +/* We know that the expression is constant; don't tell us. */ + +#pragma warn (const-comparison, off) + +int main (void) +{ + return sizeof list1 != 10 + || sizeof list2 != 20 + || sizeof list3 != 12; +} diff --git a/test/val/while.c b/test/val/while.c index cf2147052..b86b1fba5 100644 --- a/test/val/while.c +++ b/test/val/while.c @@ -1,53 +1,107 @@ /* - !!DESCRIPTION!! + !!DESCRIPTION!! while-condition tests !!ORIGIN!! SDCC regression tests !!LICENCE!! GPL, read COPYING.GPL */ #include <stdio.h> -#include <limits.h> -unsigned char success = 0; -unsigned char failures = 0; -unsigned char dummy = 0; +static unsigned char failures = 0x00; +static unsigned char achar0 = 0; -#ifdef SUPPORT_BIT_TYPES -bit bit0 = 0; -#endif -unsigned int aint0 = 0; -unsigned int aint1 = 0; -unsigned char achar0 = 0; -unsigned char achar1 = 0; - -void -done () -{ - dummy++; -} - -void +static void while1 (void) { unsigned char i = 10; - do - { - achar0++; - } - while (--i); + do { + ++achar0; + } while (--i); - if (achar0 != 10) - failures++; + if (achar0 != 10) { + failures |= 0x01; + } +} + +static void +while2 (void) +{ + unsigned char i = 10; + + achar0 = 0; + while (--i) { + ++achar0; + } + + if (achar0 != 10 - 1) { + failures |= 0x02; + } +} + +static void +while3 (void) +{ + achar0 = 0; + do { + if (++achar0 == (unsigned char)0) { + return; + } + } while (1); + + failures |= 0x04; +} + +static void +while4 (void) +{ + achar0 = 0; + while (1) { + if (++achar0 == (unsigned char)0) { + return; + } + } + + failures |= 0x08; +} + +static void +while5 (void) +{ + achar0 = 0; + do { + ++achar0; + } while (0); + + if (achar0 != 1) { + failures |= 0x10; + } +} + +static void +while6 (void) +{ + achar0 = 0; + while (0) { + ++achar0; + } + + if (achar0 != 1 - 1) { + failures |= 0x20; + } } int main (void) { while1 (); + while2 (); + while3 (); + while4 (); + while5 (); + while6 (); - success = failures; - done (); - printf("failures: %d\n",failures); - + if (failures) { + printf("failures: 0x%02X\n", failures); + } return failures; } diff --git a/testcode/lib/atari/displaylist.c b/testcode/lib/atari/displaylist.c index 04c599878..ae1931e64 100644 --- a/testcode/lib/atari/displaylist.c +++ b/testcode/lib/atari/displaylist.c @@ -1,59 +1,55 @@ /* -** testprogram for ANTIC instructions as defined in "_antic.h" +** test program for ANTIC instructions as defined in "_antic.h" ** ** 23-Feb-2017, Christian Krueger */ #include <conio.h> #include <atari.h> -#include <peekpoke.h> -#include <string.h> -// code is only for testing purposes, as screen and display list are not aligned +// code is only for testing purposes, as screen and display list are not aligned, // and jumps not set! unsigned char DummyScreen[400]; void DisplayList = { - DL_BLK1, - DL_BLK2, - DL_BLK3, - DL_BLK4, - DL_BLK5, - DL_BLK6, - DL_BLK7, - DL_DLI(DL_BLK8), - DL_LMS(DL_CHR40x8x1), - DummyScreen, - DL_HSCROL(DL_CHR40x10x1), - DL_VSCROL(DL_CHR40x8x4), - DL_CHR40x16x4, - DL_LMS(DL_HSCROL(DL_VSCROL(DL_DLI(DL_CHR20x8x2)))), - DummyScreen+120, - DL_CHR20x16x2, - DL_MAP40x8x4, - DL_MAP80x4x2, - DL_MAP80x4x4, - DL_MAP160x2x2, - DL_MAP160x1x2, - DL_MAP160x2x4, - DL_MAP160x1x4, - DL_MAP320x1x1, - DL_JVB, - DL_JMP + DL_BLK1, + DL_BLK2, + DL_BLK3, + DL_BLK4, + DL_BLK5, + DL_BLK6, + DL_BLK7, + DL_DLI(DL_BLK8), + DL_LMS(DL_CHR40x8x1), + DummyScreen, + DL_HSCROL(DL_CHR40x10x1), + DL_VSCROL(DL_CHR40x8x4), + DL_CHR40x16x4, + DL_LMS(DL_HSCROL(DL_VSCROL(DL_DLI(DL_CHR20x8x2)))), + DummyScreen+120, + DL_CHR20x16x2, + DL_MAP40x8x4, + DL_MAP80x4x2, + DL_MAP80x4x4, + DL_MAP160x2x2, + DL_MAP160x1x2, + DL_MAP160x2x4, + DL_MAP160x1x4, + DL_MAP320x1x1, + DL_JVB, + DL_JMP }; -unsigned char dlend = 0; +/* We know that the sizeof expression is constant; don't tell us. */ + +#pragma warn (const-comparison, off) int main(void) { - // unfortunately "sizeof()" doesn't work with void data - // (Error: Size of data type is unknown) - // so we trick with the addresses at front and end... - - int returnValue = (((unsigned int)&dlend-(unsigned int)&DisplayList) != 28); // assure only one byte per instruction! + int returnValue = (sizeof DisplayList != 28); // assure only one byte per instruction! clrscr(); if (returnValue) @@ -66,4 +62,3 @@ main(void) return returnValue; } - diff --git a/testcode/lib/conio.c b/testcode/lib/conio.c index fe977ec08..13188d1cd 100644 --- a/testcode/lib/conio.c +++ b/testcode/lib/conio.c @@ -117,8 +117,8 @@ void main(void) gotoxy(7 + inpos,1); #if defined(__NES__) || defined(__PCE__) || defined(__GAMATE__) - /* not all targets have waitvblank */ - waitvblank(); + /* not all targets have waitvsync */ + waitvsync(); /* for targets that do not have a keyboard, read the first joystick */ joy = joy_read(JOY_1); diff --git a/testcode/lib/gamate/ctest.c b/testcode/lib/gamate/ctest.c index dfebd9bef..793770cee 100644 --- a/testcode/lib/gamate/ctest.c +++ b/testcode/lib/gamate/ctest.c @@ -41,7 +41,7 @@ int main(int argc, char *argv[]) break; } - waitvblank(); + waitvsync(); (*((unsigned char*)LCD_XPOS)) = x; (*((unsigned char*)LCD_YPOS)) = y; diff --git a/testcode/lib/joy-test.c b/testcode/lib/joy-test.c index fc751ebdc..fdd83bb4e 100644 --- a/testcode/lib/joy-test.c +++ b/testcode/lib/joy-test.c @@ -58,21 +58,19 @@ int main (void) #if defined(__ATARI5200__) || defined(__CREATIVISION__) cprintf ("%1d:%-3s%-3s%-3s%-3s%-3s%-3s", i, - (j & joy_masks[JOY_UP])? " U " : " ", - (j & joy_masks[JOY_DOWN])? " D " : " ", - (j & joy_masks[JOY_LEFT])? " L " : " ", - (j & joy_masks[JOY_RIGHT])? " R " : " ", - (j & joy_masks[JOY_FIRE])? " 1 " : " ", - (j & joy_masks[JOY_FIRE2])? " 2 " : " "); + JOY_UP(j)? " U " : " - ", + JOY_DOWN(j)? " D " : " - ", + JOY_LEFT(j)? " L " : " - ", + JOY_RIGHT(j)? " R " : " - ", + JOY_BTN_1(j)? " 1 " : " - "); #else cprintf ("%2d: %-6s%-6s%-6s%-6s%-6s%-6s", i, - (j & joy_masks[JOY_UP])? " up " : " ---- ", - (j & joy_masks[JOY_DOWN])? " down " : " ---- ", - (j & joy_masks[JOY_LEFT])? " left " : " ---- ", - (j & joy_masks[JOY_RIGHT])? "right " : " ---- ", - (j & joy_masks[JOY_FIRE])? " fire " : " ---- ", - (j & joy_masks[JOY_FIRE2])? "fire2 " : " ---- "); + JOY_UP(j)? " up " : " ---- ", + JOY_DOWN(j)? " down " : " ---- ", + JOY_LEFT(j)? " left " : " ---- ", + JOY_RIGHT(j)? "right " : " ---- ", + JOY_BTN_1(j)? "button" : " ---- "); #endif } } diff --git a/testcode/lib/mul-test.c b/testcode/lib/mul-test.c index 2daf5aa06..f9db3f641 100644 --- a/testcode/lib/mul-test.c +++ b/testcode/lib/mul-test.c @@ -1,170 +1,170 @@ -/* mul-test.c -- Test the multiplication operator. */ - -#include <time.h> -#include <conio.h> -#include <ctype.h> - - -/* Number of elements in the progress bar. Use a power of 2, to avoid the -** multiplication (which is about to be tested). -*/ -#define BAR_ELEMENTS 32U - -#if defined(__CBM__) -static const unsigned char revers_bar[8] = { - 0, 0, 0, 0, 0, 1, 1, 1 -}; -static const unsigned char small_bar[8] = { - ' ', 0xa5, 0xb4, 0xb5, 0xa1, 0xb6, 0xaa, 0xa7 -}; - -#elif defined(__ATARI__) -#endif - -/* Screen co-ordinates for the progress meter */ -static unsigned char Width, Height; -static unsigned char X, Y; - -static void ProgressMeter (unsigned Val) -/* Print the progress bar. */ -{ - gotoxy (X, Y); - cprintf (" %5lu/65536\r\n", (unsigned long) Val); - revers (1); - cclear (Val / (unsigned)(65536U / BAR_ELEMENTS)); - -/* Commodore and Atari computers can show eight times greater precision. */ -#if defined(__CBM__) - Val = (Val / (unsigned)(65536U / BAR_ELEMENTS / 8)) % 8; - revers (revers_bar[Val]); - cputc (small_bar[Val]); - -#elif defined(__ATARI__) -#endif - - revers (0); -} - - - -int main(void) -{ - char C; - - /* Clock variables */ - clock_t Ticks; - clock_t Wait; - unsigned Days; - unsigned Hours; - unsigned Minu; - unsigned Sec; - unsigned Milli; - - /* Actual test variables */ - register unsigned lhs = 0; - register unsigned rhs = 0; - register unsigned res; - - /* Clear the screen, and output an informational message. */ - clrscr (); - screensize (&Width, &Height); - cprintf ("This program does an exhaustive test of\r\n" - "the multiplication routine. It runs for\r\n" - "several days; so, please wait very\r\n" - "patiently (or, speed up your emulator).\r\n" - "\n" - "Progress: "); - - /* Remember the current position for the progress bar */ - X = wherex (); - Y = wherey (); - - /* Mark the maximum limit of the bar. */ - revers (1); - cputcxy (BAR_ELEMENTS, Y, ' '); - cputcxy (BAR_ELEMENTS, Y + 1, ' '); - revers (0); - -/* [Targets that have clock() will define CLOCKS_PER_SEC.] */ -#ifdef CLOCKS_PER_SEC - - /* Start timing the test. */ - Ticks = clock(); -#endif - - do { - - /* Update the progress bar */ - ProgressMeter (lhs); - -/* Enable this to test the progress-meter code. -** (And, run emulators at their maximun speed.) -*/ -#if 0 - continue; -#endif - - /* Do one row of tests */ - res = 0; - do { - if (lhs * rhs != res) { -#ifdef CLOCKS_PER_SEC - Wait = clock (); -#endif - gotoxy (0, Y+3); - cprintf ("Error on %u * %u: %u != %u\r\n", lhs, rhs, lhs * rhs, res); - cprintf ("Press a key -- 'Q' to quit. "); - cursor (1); - C = toupper (cgetc ()); - cclearxy (0, Y+3, Width); - cclearxy (0, Y+4, Width); - -#ifdef CLOCKS_PER_SEC - - /* Don't time the user's interaction. */ - Ticks += clock () - Wait; -#endif - - if (C == 'Q') { - goto Done; - } - } - - if (kbhit () && toupper (cgetc ()) == 'Q') { - goto Done; - } - - res += lhs; - } while (++rhs != 0); - - } while (++lhs != 0); - -Done: -#ifdef CLOCKS_PER_SEC - - /* Calculate the time used */ - Ticks = clock() - Ticks; - Milli = ((Ticks % CLOCKS_PER_SEC) * 1000) / CLOCKS_PER_SEC; - Sec = (unsigned) (Ticks / CLOCKS_PER_SEC); - Minu = Sec / 60; - Hours = Minu / 60; - Days = Hours / 24; - Hours %= 24; - Minu %= 60; - Sec %= 60; - - /* Print the time used */ - gotoxy (0, Y+3); - cprintf ("Time used:\r\n" - " %u days,\r\n" - " %u hours,\r\n" - " %u minutes,\r\n" - " %u.%03u seconds.\n", Days, Hours, Minu, Sec, Milli); -#endif - - cprintf ("\rTap a key, to exit. "); - cgetc(); - return 0; -} - - +/* mul-test.c -- Test the multiplication operator. */ + +#include <time.h> +#include <conio.h> +#include <ctype.h> + + +/* Number of elements in the progress bar. Use a power of 2, to avoid the +** multiplication (which is about to be tested). +*/ +#define BAR_ELEMENTS 32U + +#if defined(__CBM__) +static const unsigned char revers_bar[8] = { + 0, 0, 0, 0, 0, 1, 1, 1 +}; +static const unsigned char small_bar[8] = { + ' ', 0xa5, 0xb4, 0xb5, 0xa1, 0xb6, 0xaa, 0xa7 +}; + +#elif defined(__ATARI__) +#endif + +/* Screen co-ordinates for the progress meter */ +static unsigned char Width, Height; +static unsigned char X, Y; + +static void ProgressMeter (unsigned Val) +/* Print the progress bar. */ +{ + gotoxy (X, Y); + cprintf (" %5lu/65536\r\n", (unsigned long) Val); + revers (1); + cclear (Val / (unsigned)(65536U / BAR_ELEMENTS)); + +/* Commodore and Atari computers can show eight times greater precision. */ +#if defined(__CBM__) + Val = (Val / (unsigned)(65536U / BAR_ELEMENTS / 8)) % 8; + revers (revers_bar[Val]); + cputc (small_bar[Val]); + +#elif defined(__ATARI__) +#endif + + revers (0); +} + + + +int main(void) +{ + char C; + + /* Clock variables */ + clock_t Ticks; + clock_t Wait; + unsigned Days; + unsigned Hours; + unsigned Minu; + unsigned Sec; + unsigned Milli; + + /* Actual test variables */ + register unsigned lhs = 0; + register unsigned rhs = 0; + register unsigned res; + + /* Clear the screen, and output an informational message. */ + clrscr (); + screensize (&Width, &Height); + cprintf ("This program does an exhaustive test of\r\n" + "the multiplication routine. It runs for\r\n" + "several days; so, please wait very\r\n" + "patiently (or, speed up your emulator).\r\n" + "\n" + "Progress: "); + + /* Remember the current position for the progress bar */ + X = wherex (); + Y = wherey (); + + /* Mark the maximum limit of the bar. */ + revers (1); + cputcxy (BAR_ELEMENTS, Y, ' '); + cputcxy (BAR_ELEMENTS, Y + 1, ' '); + revers (0); + +/* [Targets that have clock() will define CLOCKS_PER_SEC.] */ +#ifdef CLOCKS_PER_SEC + + /* Start timing the test. */ + Ticks = clock(); +#endif + + do { + + /* Update the progress bar */ + ProgressMeter (lhs); + +/* Enable this to test the progress-meter code. +** (And, run emulators at their maximun speed.) +*/ +#if 0 + continue; +#endif + + /* Do one row of tests */ + res = 0; + do { + if (lhs * rhs != res) { +#ifdef CLOCKS_PER_SEC + Wait = clock (); +#endif + gotoxy (0, Y+3); + cprintf ("Error on %u * %u: %u != %u\r\n", lhs, rhs, lhs * rhs, res); + cprintf ("Press a key -- 'Q' to quit. "); + cursor (1); + C = toupper (cgetc ()); + cclearxy (0, Y+3, Width); + cclearxy (0, Y+4, Width); + +#ifdef CLOCKS_PER_SEC + + /* Don't time the user's interaction. */ + Ticks += clock () - Wait; +#endif + + if (C == 'Q') { + goto Done; + } + } + + if (kbhit () && toupper (cgetc ()) == 'Q') { + goto Done; + } + + res += lhs; + } while (++rhs != 0); + + } while (++lhs != 0); + +Done: +#ifdef CLOCKS_PER_SEC + + /* Calculate the time used */ + Ticks = clock() - Ticks; + Milli = ((Ticks % CLOCKS_PER_SEC) * 1000) / CLOCKS_PER_SEC; + Sec = (unsigned) (Ticks / CLOCKS_PER_SEC); + Minu = Sec / 60; + Hours = Minu / 60; + Days = Hours / 24; + Hours %= 24; + Minu %= 60; + Sec %= 60; + + /* Print the time used */ + gotoxy (0, Y+3); + cprintf ("Time used:\r\n" + " %u days,\r\n" + " %u hours,\r\n" + " %u minutes,\r\n" + " %u.%03u seconds.\n", Days, Hours, Minu, Sec, Milli); +#endif + + cprintf ("\rTap a key, to exit. "); + cgetc(); + return 0; +} + + diff --git a/testcode/lib/pce/conio.c b/testcode/lib/pce/conio.c index a4bd63b15..ed3f86240 100644 --- a/testcode/lib/pce/conio.c +++ b/testcode/lib/pce/conio.c @@ -1,3 +1,4 @@ +#include <pce.h> #include <conio.h> #include <time.h> #include <joystick.h> @@ -97,14 +98,14 @@ void main(void) j = joy_read (i); cprintf ("pad %d: %02x %-6s%-6s%-6s%-6s%-6s%-6s%-6s%-6s", i, j, - (j & joy_masks[JOY_UP])? " up " : " ---- ", - (j & joy_masks[JOY_DOWN])? " down " : " ---- ", - (j & joy_masks[JOY_LEFT])? " left " : " ---- ", - (j & joy_masks[JOY_RIGHT])? "right " : " ---- ", - (j & joy_masks[JOY_FIRE])? " fire " : " ---- ", - (j & joy_masks[JOY_FIRE2])? "fire2 " : " ---- ", - (j & joy_masks[JOY_SELECT])? "select" : " ---- ", - (j & joy_masks[JOY_RUN])? " run " : " ---- "); + JOY_UP(j)? " up " : " ---- ", + JOY_DOWN(j)? " down " : " ---- ", + JOY_LEFT(j)? " left " : " ---- ", + JOY_RIGHT(j)? "right " : " ---- ", + JOY_BTN_I(j)? "btn I " : " ---- ", + JOY_BTN_II(j)? "btn II" : " ---- ", + JOY_SELECT(j)? "select" : " ---- ", + JOY_RUN(j)? " run " : " ---- "); } gotoxy(xsize - 10, 3); @@ -123,7 +124,7 @@ void main(void) p[8],p[9],p[10],p[11],p[12],p[13],p[14],p[15]); } - waitvblank(); + waitvsync(); ++n; } }