diff --git a/.gitignore b/.gitignore index 5fdfc0df..8066747b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,6 @@ temp.s temp.map -packed_messages.s ophis.bin build/* diff --git a/Makefile b/Makefile index e69e5731..b7b0637e 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,10 @@ SRC_KERNAL_GENERIC = $(SRC_KERNAL_COMMON) $(wildcard c64/kernal/,platform_gen SRC_KERNAL_MEGA65 = $(SRC_KERNAL_COMMON) $(wildcard c64/kernal/,platform_mega65/*.s) SRC_KERNAL_ULTIMATE64 = $(SRC_KERNAL_COMMON) $(wildcard c64/kernal/,platform_ultimate64/*.s) +# List of tools + +TOOLS_LIST = build/collect_data build/compress_text build/preprocess build/similarity + # Rules - maintainance all: build/chargen build/newkern_generic build/newbasic_generic build/newc65 build/newkern_ultimate64 build/newbasic_ultimate64 @@ -21,10 +25,7 @@ clean: @rm -rf build @rm -f temp.s @rm -f temp.map - @rm -f c64/basic/packed_messages.s - -.PHONY: prep -prep: Ophis build/collect_data build/compress_text build/preprocess build/similarity + @rm -f ophis.bin Ophis: git submodule init @@ -59,15 +60,22 @@ build/chargen: build/pngprepare assets/8x8font.png # Rules - platform 'generic' -build/basic_generic/OUT.BIN: build/preprocess $(SRC_BASIC_GENERIC) c64/basic/packed_messages.s +build/basic_generic/OUT.BIN: $(TOOLS_LIST) $(SRC_BASIC_GENERIC) build/basic/packed_messages.s + @echo + @echo ### Building BASIC for generic systems + @echo @mkdir -p build/basic_generic @rm -f build/basic_generic/* @for SRC in $(SRC_BASIC_GENERIC); do \ ln -s ../../$$SRC build/basic_generic/$$(basename $$SRC); \ done + @ln -s ../../build/basic/packed_messages.s build/basic_generic/packed_messages.s build/preprocess -d build/basic_generic -l a000 -h e4d2 -build/kernal_generic/OUT.BIN: build/preprocess $(SRC_KERNAL_GENERIC) +build/kernal_generic/OUT.BIN: $(TOOLS_LIST) $(SRC_KERNAL_GENERIC) + @echo + @echo ### Building KERNAL for generic systems + @echo @mkdir -p build/kernal_generic @rm -f build/kernal_generic/* @for SRC in $(SRC_KERNAL_GENERIC); do \ @@ -86,15 +94,22 @@ build/newbasic_generic: build/newrom_generic Makefile # Rules - platform 'Mega 65' -build/basic_mega65/OUT.BIN: build/preprocess $(SRC_BASIC_MEGA65) c64/basic/packed_messages.s +build/basic_mega65/OUT.BIN: $(TOOLS_LIST) $(SRC_BASIC_MEGA65) build/basic/packed_messages.s + @echo + @echo ### Building BASIC for Mega65 + @echo @mkdir -p build/basic_mega65 @rm -f build/basic_mega65/* @for SRC in $(SRC_BASIC_MEGA65); do \ ln -s ../../$$SRC build/basic_mega65/$$(basename $$SRC); \ done + @ln -s ../../build/basic/packed_messages.s build/basic_mega65/packed_messages.s build/preprocess -d build/basic_mega65 -l a000 -h e4d2 -build/kernal_mega65/OUT.BIN: build/preprocess $(SRC_KERNAL_MEGA65) +build/kernal_mega65/OUT.BIN: $(TOOLS_LIST) $(SRC_KERNAL_MEGA65) + @echo + @echo ### Building KERNAL for Mega65 + @echo @mkdir -p build/kernal_mega65 @rm -f build/kernal_mega65/* @for SRC in $(SRC_KERNAL_MEGA65); do \ @@ -119,15 +134,22 @@ build/newc65: build/newkern_mega65 build/newbasic_mega65 build/chargen Makefile # Rules - platform 'Ultimate 64' -build/basic_ultimate64/OUT.BIN: build/preprocess $(SRC_BASIC_ULTIMATE64) c64/basic/packed_messages.s +build/basic_ultimate64/OUT.BIN: $(TOOLS_LIST) $(SRC_BASIC_ULTIMATE64) build/basic/packed_messages.s + @echo + @echo ### Building BASIC for Ultimate 64 + @echo @mkdir -p build/basic_ultimate64 @rm -f build/basic_ultimate64/* @for SRC in $(SRC_BASIC_ULTIMATE64); do \ ln -s ../../$$SRC build/basic_ultimate64/$$(basename $$SRC); \ done + @ln -s ../../build/basic/packed_messages.s build/basic_ultimate64/packed_messages.s build/preprocess -d build/basic_ultimate64 -l a000 -h e4d2 -build/kernal_ultimate64/OUT.BIN: build/preprocess $(SRC_KERNAL_ULTIMATE64) +build/kernal_ultimate64/OUT.BIN: $(TOOLS_LIST) $(SRC_KERNAL_ULTIMATE64) + @echo + @echo ### Building KERNAL for Ultimate 64 + @echo @mkdir -p build/kernal_ultimate64 @rm -f build/kernal_ultimate64/* @for SRC in $(SRC_KERNAL_ULTIMATE64); do \ @@ -146,8 +168,9 @@ build/newbasic_ultimate64: build/newrom_ultimate64 Makefile # Rules - misc -c64/basic/packed_messages.s: Makefile build/compress_text - build/compress_text > c64/basic/packed_messages.s +build/basic/packed_messages.s: Makefile build/compress_text + @mkdir -p build/basic + build/compress_text > build/basic/packed_messages.s # Rules - tests diff --git a/c64/aliases/,aliases_error_codes.s b/c64/aliases/,aliases_error_codes.s new file mode 100644 index 00000000..e27f5373 --- /dev/null +++ b/c64/aliases/,aliases_error_codes.s @@ -0,0 +1,63 @@ + + ;; Kernal error codes - returned in the A register + ;; Described in 'Commodore 64 Programmer's Reference Guide', page 306 + + .alias K_ERR_ROUTINE_TERMINATED $00 + .alias K_ERR_TOO_MANY_OPEN_FILES $01 + .alias K_ERR_FILE_ALREADY_OPEN $02 + .alias K_ERR_FILE_NOT_OPEN $03 + .alias K_ERR_FILE_NOT_FOUND $04 + .alias K_ERR_DEVICE_NOT_FOUND $05 + .alias K_ERR_FILE_NOT_INPUT $06 + .alias K_ERR_FILE_NOT_OUTPUT $07 + .alias K_ERR_FILE_NAME_MISSING $08 + .alias K_ERR_ILLEGAL_DEVICE_NUMBER $09 + .alias K_ERR_TOP_MEM_RS232 $F0 + + ;; Kernal status codes for READST routine (IOSTATUS) + ;; Described in 'Commodore 64 Programmer's Reference Guide', page 292 + + ;; For IEC devices + .alias K_STS_TIMEOUT_WRITE $01 + .alias K_STS_TIMEOUT_READ $02 + .alias K_STS_EOI $40 + .alias K_STS_DEVICE_NOT_FOUND $80 + ;; For tape deck + .alias K_STS_SHORT_BLOCK $04 + .alias K_STS_LONG_BLOCK $08 + .alias K_STS_READ_ERROR $10 + .alias K_STS_CHECKSUM_ERROR $20 + .alias K_STS_END_OF_FILE $40 + .alias K_STS_END_OF_TAPE $80 + + ;; BASIC error codes, taken from http://sta.c64.org/cbm64baserr.html + .alias B_ERR_TOO_MANY_FILES $01 + .alias B_ERR_FILE_OPEN $02 + .alias B_ERR_FILE_NOT_OPEN $03 + .alias B_ERR_FILE_NOT_FOUND $04 + .alias B_ERR_DEVICE_NOT_PRESENT $05 + .alias B_ERR_NOT_INPUT_FILE $06 + .alias B_ERR_NOT_OUTPUT_FILE $07 + .alias B_ERR_MISSING_FILENAME $08 + .alias B_ERR_ILLEGAL_DEVICE_NUMBER $09 + .alias B_ERR_NEXT_WITHOUT_FOR $0A + .alias B_ERR_SYNTAX $0B + .alias B_ERR_RETURN_WITHOUT_GOSUB $0C + .alias B_ERR_OUT_OF_DATA $0D + .alias B_ERR_ILLEGAL_QUANTITY $0E + .alias B_ERR_OVERFLOW $0F + .alias B_ERR_OUT_OF_MEMORY $10 + .alias B_ERR_UNDEFD_STATEMENT $11 + .alias B_ERR_BAD_SUBSCRIPT $12 + .alias B_ERR_REDIMD_ARRAY $13 + .alias B_ERR_DIVISION_BY_ZERO $14 + .alias B_ERR_ILLEGAL_DIRECT $15 + .alias B_ERR_TYPE_MISMATCH $16 + .alias B_ERR_STRING_TOO_LONG $17 + .alias B_ERR_FILE_DATA $18 + .alias B_ERR_FORMULA_TOO_COMPLEX $19 + .alias B_ERR_CANT_CONTINUE $1A + .alias B_ERR_UNDEFD_FUNCTION $1B + .alias B_ERR_VERIFY $1C + .alias B_ERR_LOAD $1D + .alias B_ERR_BREAK $1E diff --git a/c64/aliases/,aliases_hardware.s b/c64/aliases/,aliases_hardware.s new file mode 100644 index 00000000..ee6ceddb --- /dev/null +++ b/c64/aliases/,aliases_hardware.s @@ -0,0 +1,154 @@ + +;; +;; Names of hardware registers - slightly modified names from C64 Programmer's Reference Guide +;; + + ;; CPU memory registers + + .alias CPU_D6510 $0000 + .alias CPU_R6510 $0001 + + ;; VIC-II registers + + .alias VIC_SP0X $D000 + .alias VIC_SP0Y $D001 + .alias VIC_SP1X $D002 + .alias VIC_SP1Y $D003 + .alias VIC_SP2X $D004 + .alias VIC_SP2Y $D005 + .alias VIC_SP3X $D006 + .alias VIC_SP3Y $D007 + .alias VIC_SP4X $D008 + .alias VIC_SP4Y $D009 + .alias VIC_SP5X $D00A + .alias VIC_SP5Y $D00B + .alias VIC_SP6X $D00C + .alias VIC_SP6Y $D00D + .alias VIC_SP7X $D00E + .alias VIC_SP7Y $D00F + + .alias VIC_MSIGX $D010 + .alias VIC_SCROLLY $D011 + .alias VIC_RASTER $D012 + .alias VIC_LPENX $D013 + .alias VIC_LPENY $D014 + .alias VIC_SPENA $D015 + .alias VIC_SCROLX $D016 + .alias VIC_YXPAND $D017 + .alias VIC_YMCSB $D018 + .alias VIC_IRQ $D019 + .alias VIC_IRQMSK $D01A + .alias VIC_SPBGPR $D01B + .alias VIC_SPMC $D01C + .alias VIC_XXPAND $D01D + .alias VIC_SPSPCL $D01E + .alias VIC_SPBGCL $D01F + + .alias VIC_EXTCOL $D020 + .alias VIC_BGCOL0 $D021 + .alias VIC_BGCOL1 $D022 + .alias VIC_BGCOL2 $D023 + .alias VIC_BGCOL3 $D024 + .alias VIC_SPMC0 $D025 + .alias VIC_SPMC1 $D026 + .alias VIC_SP0COL $D027 + .alias VIC_SP1COL $D028 + .alias VIC_SP2COL $D029 + .alias VIC_SP3COL $D02A + .alias VIC_SP4COL $D02B + .alias VIC_SP5COL $D02C + .alias VIC_SP6COL $D02D + .alias VIC_SP7COL $D02E + + ;; SID #1 registers + + .alias SID1_FRELO1 $D400 + .alias SID1_FREHI1 $D401 + .alias SID1_PWLO1 $D402 + .alias SID1_PWHI1 $D403 + .alias SID1_VCREG1 $D404 + .alias SID1_ATDCY1 $D405 + .alias SID1_SUREL1 $D406 + + .alias SID1_FRELO2 $D407 + .alias SID1_FREHI2 $D408 + .alias SID1_PWLO2 $D409 + .alias SID1_PWHI2 $D40A + .alias SID1_VCREG2 $D40B + .alias SID1_ATDCY2 $D40C + .alias SID1_SUREL2 $D40D + + .alias SID1_FRELO3 $D40E + .alias SID1_FREHI3 $D40F + .alias SID1_PWLO3 $D410 + .alias SID1_PWHI3 $D411 + .alias SID1_VCREG3 $D412 + .alias SID1_ATDCY3 $D413 + .alias SID1_SUREL3 $D414 + + .alias SID1_CUTLO $D415 + .alias SID1_CUTHI $D416 + .alias SID1_RESON $D417 + .alias SID1_SIGVOL $D418 + .alias SID1_POTX $D419 + .alias SID1_POTY $D41A + .alias SID1_RANDOM $D41B + .alias SID1_ENV3 $D41C + + ;; SID #2, #3, #4 registers + + .alias SID2_SIGVOL $D438 + .alias SID3_SIGVOL $D458 + .alias SID4_SIGVOL $D478 + + ;; CIA #1 registers + + .alias CIA1_PRA $DC00 + .alias CIA1_PRB $DC01 + .alias CIA1_DDRA $DC02 + .alias CIA1_DDRB $DC03 + + .alias CIA1_TIMALO $DC04 + .alias CIA1_TIMAHI $DC05 + .alias CIA1_TIMBLO $DC06 + .alias CIA1_TIMBHI $DC07 + + .alias CIA1_TODTEN $DC08 + .alias CIA1_TODSEC $DC09 + .alias CIA1_TODMIN $DC0A + .alias CIA1_TODHRS $DC0B + + .alias CIA1_SDR $DC0C + .alias CIA1_ICR $DC0D + .alias CIA1_CRA $DC0E + .alias CIA1_CRB $DC0F + + ;; CIA #2 registers + + .alias CIA2_PRA $DD00 ; VIC bank switching and IEC port + .alias CIA2_PRB $DD01 + .alias CIA2_DDRA $DD02 + .alias CIA2_DDRB $DD03 + + .alias CIA2_TIMALO $DD04 + .alias CIA2_TIMAHI $DD05 + .alias CIA2_TIMBLO $DD06 + .alias CIA2_TIMBHI $DD07 + + .alias CIA2_TODTEN $DD08 + .alias CIA2_TODSEC $DD09 + .alias CIA2_TODMIN $DD0A + .alias CIA2_TODHRS $DD0B + + .alias CIA2_SDR $DD0C + .alias CIA2_ICR $DD0D + .alias CIA2_CRA $DD0E + .alias CIA2_CRB $DD0F + + ;; CIA #2 helper bits - IEC bus + + .alias BIT_CIA2_PRA_ATN_OUT $08 ; 1 - low (pulled), 0 - high (released) + .alias BIT_CIA2_PRA_CLK_OUT $10 ; 1 - low (pulled), 0 - high (released) + .alias BIT_CIA2_PRA_DAT_OUT $20 ; 1 - low (pulled), 0 - high (released) + .alias BIT_CIA2_PRA_CLK_IN $40 ; 0 - low (pulled), 1 - high (released) + .alias BIT_CIA2_PRA_DAT_IN $80 ; 0 - low (pulled), 1 - high (released) diff --git a/c64/aliases/,aliases_ram_lowmem.s b/c64/aliases/,aliases_ram_lowmem.s new file mode 100644 index 00000000..a024d66f --- /dev/null +++ b/c64/aliases/,aliases_ram_lowmem.s @@ -0,0 +1,33 @@ +;; +;; Names of ZP and low memory locations (only the implemented ones) +;; (https://www.c64-wiki.com/wiki/Zeropage) +;; + + ;; $000-$001 - 6502 CPU registers + + ;; Registers for SYS call + .alias sys_reg_a $30c + .alias sys_reg_x $30d + .alias sys_reg_y $30e + .alias sys_reg_p $30f + .alias sys_jmp $310 + + ;; Kernal vectors - interrupts + .alias CINV $0314 + .alias CBINV $0316 + .alias NMINV $0318 + + ;; Kernal vectors - routines + .alias IOPEN $031A + .alias ICLOSE $031C + .alias ICHKIN $031E + .alias ICKOUT $0320 + .alias ICLRCH $0322 + .alias IBASIN $0324 + .alias IBASOUT $0326 + .alias ISTOP $0328 + .alias IGETIN $032A + .alias ICLALL $032C + .alias USRCMD $032E + .alias ILOAD $0330 + .alias ISAVE $0331 diff --git a/c64/aliases/.dummy b/c64/aliases/,aliases_rom_basic.s similarity index 100% rename from c64/aliases/.dummy rename to c64/aliases/,aliases_rom_basic.s diff --git a/c64/aliases/,aliases_rom_kernal.s b/c64/aliases/,aliases_rom_kernal.s new file mode 100644 index 00000000..bb2bd4e4 --- /dev/null +++ b/c64/aliases/,aliases_rom_kernal.s @@ -0,0 +1,41 @@ + + ;; Kernal jump table + .alias JCINT $FF81 + .alias JIOINIT $FF84 + .alias JRAMTAS $FF87 + .alias JRESTOR $FF8A + .alias JVECTOR $FF8D + .alias JSETMSG $FF90 + .alias JSECOND $FF93 + .alias JTKSA $FF96 + .alias JMEMTOP $FF99 + .alias JMEMBOT $FF9C + .alias JSCNKEY $FF9F + .alias JSETTMO $FFA2 + .alias JACPTR $FFA5 + .alias JCIOUT $FFA8 + .alias JUNTLK $FFAB + .alias JUNLSN $FFAE + .alias JLISTEN $FFB1 + .alias JTALK $FFB4 + .alias JREADST $FFB7 + .alias JSETFLS $FFBA + .alias JSETNAM $FFBD + .alias JOPEN $FFC0 + .alias JCLOSE $FFC3 + .alias JCHKIN $FFC6 + .alias JCHKOUT $FFC9 + .alias JCLRCHN $FFCC + .alias JCHRIN $FFCF + .alias JCHROUT $FFD2 + .alias JLOAD $FFD5 + .alias JSAVE $FFD8 + .alias JSETTIM $FFDB + .alias JRDTIM $FFDE + .alias JSTOP $FFE1 + .alias JGETIN $FFE4 + .alias JCLALL $FFE7 + .alias JUDTIM $FFEA + .alias JSCREEN $FFED + .alias JPLOT $FFF0 + .alias JIOBASE $FFF3 diff --git a/c64/basic/,aliases.s b/c64/basic/,aliases.s index bbee542e..d3b76eab 100644 --- a/c64/basic/,aliases.s +++ b/c64/basic/,aliases.s @@ -143,135 +143,6 @@ .alias RSSTAT $0297 ; RS-232 status .alias pal_or_ntsc $02A6 - ;; Registers for SYS call - .alias sys_reg_a $30c - .alias sys_reg_x $30d - .alias sys_reg_y $30e - .alias sys_reg_p $30f - .alias sys_jmp $310 - - ;; Kernal vectors - interrupts - .alias CINV $0314 - .alias CBINV $0316 - .alias NMINV $0318 - - ;; Kernal vectors - routines - .alias IOPEN $031A - .alias ICLOSE $031C - .alias ICHKIN $031E - .alias ICKOUT $0320 - .alias ICLRCH $0322 - .alias IBASIN $0324 - .alias IBASOUT $0326 - .alias ISTOP $0328 - .alias IGETIN $032A - .alias ICLALL $032C - .alias USRCMD $032E - .alias ILOAD $0330 - .alias ISAVE $0331 - - ;; Kernal jump table - .alias JCINT $FF81 - .alias JIOINIT $FF84 - .alias JRAMTAS $FF87 - .alias JRESTOR $FF8A - .alias JVECTOR $FF8D - .alias JSETMSG $FF90 - .alias JSECOND $FF93 - .alias JTKSA $FF96 - .alias JMEMTOP $FF99 - .alias JMEMBOT $FF9C - .alias JSCNKEY $FF9F - .alias JSETTMO $FFA2 - .alias JACPTR $FFA5 - .alias JCIOUT $FFA8 - .alias JUNTLK $FFAB - .alias JUNLSN $FFAE - .alias JLISTEN $FFB1 - .alias JTALK $FFB4 - .alias JREADST $FFB7 - .alias JSETFLS $FFBA - .alias JSETNAM $FFBD - .alias JOPEN $FFC0 - .alias JCLOSE $FFC3 - .alias JCHKIN $FFC6 - .alias JCHKOUT $FFC9 - .alias JCLRCHN $FFCC - .alias JCHRIN $FFCF - .alias JCHROUT $FFD2 - .alias JLOAD $FFD5 - .alias JSAVE $FFD8 - .alias JSETTIM $FFDB - .alias JRDTIM $FFDE - .alias JSTOP $FFE1 - .alias JGETIN $FFE4 - .alias JCLALL $FFE7 - .alias JUDTIM $FFEA - .alias JSCREEN $FFED - .alias JPLOT $FFF0 - .alias JIOBASE $FFF3 - - ;; Kernal error codes - returned in the A register - ;; Described in 'Commodore 64 Programmer's Reference Guide', page 306 - .alias K_ERR_ROUTINE_TERMINATED $00 - .alias K_ERR_TOO_MANY_OPEN_FILES $01 - .alias K_ERR_FILE_ALREADY_OPEN $02 - .alias K_ERR_FILE_NOT_OPEN $03 - .alias K_ERR_FILE_NOT_FOUND $04 - .alias K_ERR_DEVICE_NOT_FOUND $05 - .alias K_ERR_FILE_NOT_INPUT $06 - .alias K_ERR_FILE_NOT_OUTPUT $07 - .alias K_ERR_FILE_NAME_MISSING $08 - .alias K_ERR_ILLEGAL_DEVICE_NUMBER $09 - .alias K_ERR_TOP_MEM_RS232 $F0 - - ;; Kernal status codes for READST routine (IOSTATUS) - ;; Described in 'Commodore 64 Programmer's Reference Guide', page 292 - ;; For IEC devices - .alias K_STS_TIMEOUT_WRITE $01 - .alias K_STS_TIMEOUT_READ $02 - .alias K_STS_EOI $40 - .alias K_STS_DEVICE_NOT_FOUND $80 - ;; For tape deck - .alias K_STS_SHORT_BLOCK $04 - .alias K_STS_LONG_BLOCK $08 - .alias K_STS_READ_ERROR $10 - .alias K_STS_CHECKSUM_ERROR $20 - .alias K_STS_END_OF_FILE $40 - .alias K_STS_END_OF_TAPE $80 - - ;; BASIC error codes, taken from http://sta.c64.org/cbm64baserr.html - .alias B_ERR_TOO_MANY_FILES $01 - .alias B_ERR_FILE_OPEN $02 - .alias B_ERR_FILE_NOT_OPEN $03 - .alias B_ERR_FILE_NOT_FOUND $04 - .alias B_ERR_DEVICE_NOT_PRESENT $05 - .alias B_ERR_NOT_INPUT_FILE $06 - .alias B_ERR_NOT_OUTPUT_FILE $07 - .alias B_ERR_MISSING_FILENAME $08 - .alias B_ERR_ILLEGAL_DEVICE_NUMBER $09 - .alias B_ERR_NEXT_WITHOUT_FOR $0A - .alias B_ERR_SYNTAX $0B - .alias B_ERR_RETURN_WITHOUT_GOSUB $0C - .alias B_ERR_OUT_OF_DATA $0D - .alias B_ERR_ILLEGAL_QUANTITY $0E - .alias B_ERR_OVERFLOW $0F - .alias B_ERR_OUT_OF_MEMORY $10 - .alias B_ERR_UNDEFD_STATEMENT $11 - .alias B_ERR_BAD_SUBSCRIPT $12 - .alias B_ERR_REDIMD_ARRAY $13 - .alias B_ERR_DIVISION_BY_ZERO $14 - .alias B_ERR_ILLEGAL_DIRECT $15 - .alias B_ERR_TYPE_MISMATCH $16 - .alias B_ERR_STRING_TOO_LONG $17 - .alias B_ERR_FILE_DATA $18 - .alias B_ERR_FORMULA_TOO_COMPLEX $19 - .alias B_ERR_CANT_CONTINUE $1A - .alias B_ERR_UNDEFD_FUNCTION $1B - .alias B_ERR_VERIFY $1C - .alias B_ERR_LOAD $1D - .alias B_ERR_BREAK $1E - ;; BASIC uses some extra bytes for memory access under ROMs located at $2A7 onwards ;; IRQs are disabled when doing such accesses, and a default NMI handler only increments ;; a counter, so that if an NMI occurs, it doesn't crash the machine, but can be captured. @@ -283,4 +154,3 @@ .alias poke_under_roms tiny_nmi_handler+poke_under_roms_routine-tiny_nmi_handler_routine .alias memmap_allram tiny_nmi_handler+memmap_allram_routine-tiny_nmi_handler_routine .alias memmap_normal tiny_nmi_handler+memmap_normal_routine-tiny_nmi_handler_routine - diff --git a/c64/kernal/,aliases.s b/c64/kernal/,aliases.s index b76ce732..0c30eca1 100644 --- a/c64/kernal/,aliases.s +++ b/c64/kernal/,aliases.s @@ -90,128 +90,6 @@ .alias RSSTAT $0297 ; RS-232 status .alias pal_or_ntsc $02A6 - ;; Kernal vectors - interrupts - .alias CINV $0314 - .alias CBINV $0316 - .alias NMINV $0318 - - ;; Kernal vectors - routines - .alias IOPEN $031A - .alias ICLOSE $031C - .alias ICHKIN $031E - .alias ICKOUT $0320 - .alias ICLRCH $0322 - .alias IBASIN $0324 - .alias IBASOUT $0326 - .alias ISTOP $0328 - .alias IGETIN $032A - .alias ICLALL $032C - .alias USRCMD $032E - .alias ILOAD $0330 - .alias ISAVE $0331 - - ;; Kernal jump table - .alias JCINT $FF81 - .alias JIOINIT $FF84 - .alias JRAMTAS $FF87 - .alias JRESTOR $FF8A - .alias JVECTOR $FF8D - .alias JSETMSG $FF90 - .alias JSECOND $FF93 - .alias JTKSA $FF96 - .alias JMEMTOP $FF99 - .alias JMEMBOT $FF9C - .alias JSCNKEY $FF9F - .alias JSETTMO $FFA2 - .alias JACPTR $FFA5 - .alias JCIOUT $FFA8 - .alias JUNTLK $FFAB - .alias JUNLSN $FFAE - .alias JLISTEN $FFB1 - .alias JTALK $FFB4 - .alias JREADST $FFB7 - .alias JSETFLS $FFBA - .alias JSETNAM $FFBD - .alias JOPEN $FFC0 - .alias JCLOSE $FFC3 - .alias JCHKIN $FFC6 - .alias JCHKOUT $FFC9 - .alias JCLRCHN $FFCC - .alias JCHRIN $FFCF - .alias JCHROUT $FFD2 - .alias JLOAD $FFD5 - .alias JSAVE $FFD8 - .alias JSETTIM $FFDB - .alias JRDTIM $FFDE - .alias JSTOP $FFE1 - .alias JGETIN $FFE4 - .alias JCLALL $FFE7 - .alias JUDTIM $FFEA - .alias JSCREEN $FFED - .alias JPLOT $FFF0 - .alias JIOBASE $FFF3 - - ;; Kernal error codes - returned in the A register - ;; Described in 'Commodore 64 Programmer's Reference Guide', page 306 - .alias K_ERR_ROUTINE_TERMINATED $00 - .alias K_ERR_TOO_MANY_OPEN_FILES $01 - .alias K_ERR_FILE_ALREADY_OPEN $02 - .alias K_ERR_FILE_NOT_OPEN $03 - .alias K_ERR_FILE_NOT_FOUND $04 - .alias K_ERR_DEVICE_NOT_FOUND $05 - .alias K_ERR_FILE_NOT_INPUT $06 - .alias K_ERR_FILE_NOT_OUTPUT $07 - .alias K_ERR_FILE_NAME_MISSING $08 - .alias K_ERR_ILLEGAL_DEVICE_NUMBER $09 - .alias K_ERR_TOP_MEM_RS232 $F0 - - ;; Kernal status codes for READST routine (IOSTATUS) - ;; Described in 'Commodore 64 Programmer's Reference Guide', page 292 - ;; For IEC devices - .alias K_STS_TIMEOUT_WRITE $01 - .alias K_STS_TIMEOUT_READ $02 - .alias K_STS_EOI $40 - .alias K_STS_DEVICE_NOT_FOUND $80 - ;; For tape deck - .alias K_STS_SHORT_BLOCK $04 - .alias K_STS_LONG_BLOCK $08 - .alias K_STS_READ_ERROR $10 - .alias K_STS_CHECKSUM_ERROR $20 - .alias K_STS_END_OF_FILE $40 - .alias K_STS_END_OF_TAPE $80 - - ;; BASIC error codes, taken from http://sta.c64.org/cbm64baserr.html - .alias B_ERR_TOO_MANY_FILES $01 - .alias B_ERR_FILE_OPEN $02 - .alias B_ERR_FILE_NOT_OPEN $03 - .alias B_ERR_FILE_NOT_FOUND $04 - .alias B_ERR_DEVICE_NOT_PRESENT $05 - .alias B_ERR_NOT_INPUT_FILE $06 - .alias B_ERR_NOT_OUTPUT_FILE $07 - .alias B_ERR_MISSING_FILENAME $08 - .alias B_ERR_ILLEGAL_DEVICE_NUMBER $09 - .alias B_ERR_NEXT_WITHOUT_FOR $0A - .alias B_ERR_SYNTAX $0B - .alias B_ERR_RETURN_WITHOUT_GOSUB $0C - .alias B_ERR_OUT_OF_DATA $0D - .alias B_ERR_ILLEGAL_QUANTITY $0E - .alias B_ERR_OVERFLOW $0F - .alias B_ERR_OUT_OF_MEMORY $10 - .alias B_ERR_UNDEFD_STATEMENT $11 - .alias B_ERR_BAD_SUBSCRIPT $12 - .alias B_ERR_REDIMD_ARRAY $13 - .alias B_ERR_DIVISION_BY_ZERO $14 - .alias B_ERR_ILLEGAL_DIRECT $15 - .alias B_ERR_TYPE_MISMATCH $16 - .alias B_ERR_STRING_TOO_LONG $17 - .alias B_ERR_FILE_DATA $18 - .alias B_ERR_FORMULA_TOO_COMPLEX $19 - .alias B_ERR_CANT_CONTINUE $1A - .alias B_ERR_UNDEFD_FUNCTION $1B - .alias B_ERR_VERIFY $1C - .alias B_ERR_LOAD $1D - .alias B_ERR_BREAK $1E - ;; Under-ROM routines ;; (BASIC also includes them. XXX - We should de-duplicate them in a safe manner) .alias missed_nmi_flag $2A7 @@ -221,12 +99,3 @@ .alias memmap_allram tiny_nmi_handler+memmap_allram_routine-tiny_nmi_handler_routine .alias memmap_normal tiny_nmi_handler+memmap_normal_routine-tiny_nmi_handler_routine - ;; CIA#2 - https://www.c64-wiki.com/wiki/CIA#CIA_2 - - .alias CI2PRA $DD00 ; VIC bank switching and IEC port - - .alias BIT_CI2PRA_ATN_OUT $08 ; 1 - low (pulled), 0 - high (released) - .alias BIT_CI2PRA_CLK_OUT $10 ; 1 - low (pulled), 0 - high (released) - .alias BIT_CI2PRA_DAT_OUT $20 ; 1 - low (pulled), 0 - high (released) - .alias BIT_CI2PRA_CLK_IN $40 ; 0 - low (pulled), 1 - high (released) - .alias BIT_CI2PRA_DAT_IN $80 ; 0 - low (pulled), 1 - high (released) diff --git a/c64/kernal/iec_pull_atn_clk_release_data.s b/c64/kernal/iec_pull_atn_clk_release_data.s index 7e11d311..7d00da80 100644 --- a/c64/kernal/iec_pull_atn_clk_release_data.s +++ b/c64/kernal/iec_pull_atn_clk_release_data.s @@ -5,11 +5,11 @@ iec_pull_atn_clk_release_data: ;; hardware give some lines few more cycles to stabilize; see page 10 of ;; http://www.zimmers.net/anonftp/pub/cbm/programming/serial-bus.pdf - lda CI2PRA - ora #BIT_CI2PRA_ATN_OUT ; pull - sta CI2PRA - ora #BIT_CI2PRA_CLK_OUT ; pull - sta CI2PRA - and #$FF - BIT_CI2PRA_DAT_OUT ; release - sta CI2PRA + lda CIA2_PRA + ora #BIT_CIA2_PRA_ATN_OUT ; pull + sta CIA2_PRA + ora #BIT_CIA2_PRA_CLK_OUT ; pull + sta CIA2_PRA + and #$FF - BIT_CIA2_PRA_DAT_OUT ; release + sta CIA2_PRA rts diff --git a/c64/kernal/iec_pull_clk_release_data.s b/c64/kernal/iec_pull_clk_release_data.s index 613aa4ef..38be0f89 100644 --- a/c64/kernal/iec_pull_clk_release_data.s +++ b/c64/kernal/iec_pull_clk_release_data.s @@ -5,9 +5,9 @@ iec_pull_clk_release_data: ;; hardware give some lines few more cycles to stabilize; see page 10 of ;; http://www.zimmers.net/anonftp/pub/cbm/programming/serial-bus.pdf - lda CI2PRA - ora #BIT_CI2PRA_CLK_OUT ; pull - sta CI2PRA - and #$FF - BIT_CI2PRA_DAT_OUT ; release - sta CI2PRA + lda CIA2_PRA + ora #BIT_CIA2_PRA_CLK_OUT ; pull + sta CIA2_PRA + and #$FF - BIT_CIA2_PRA_DAT_OUT ; release + sta CIA2_PRA rts diff --git a/c64/kernal/iec_pull_data_release_atn_clk.s b/c64/kernal/iec_pull_data_release_atn_clk.s index 7b2a18d0..14e0e236 100644 --- a/c64/kernal/iec_pull_data_release_atn_clk.s +++ b/c64/kernal/iec_pull_data_release_atn_clk.s @@ -5,11 +5,11 @@ iec_pull_data_release_atn_clk: ;; hardware give some lines few more cycles to stabilize; see page 10 of ;; http://www.zimmers.net/anonftp/pub/cbm/programming/serial-bus.pdf - lda CI2PRA - ora #BIT_CI2PRA_DAT_OUT ; pull - sta CI2PRA - and #$FF - BIT_CI2PRA_CLK_OUT ; release - sta CI2PRA - and #$FF - BIT_CI2PRA_ATN_OUT ; release - sta CI2PRA + lda CIA2_PRA + ora #BIT_CIA2_PRA_DAT_OUT ; pull + sta CIA2_PRA + and #$FF - BIT_CIA2_PRA_CLK_OUT ; release + sta CIA2_PRA + and #$FF - BIT_CIA2_PRA_ATN_OUT ; release + sta CIA2_PRA rts diff --git a/c64/kernal/iec_release_atn.s b/c64/kernal/iec_release_atn.s index 194f3856..2aef8984 100644 --- a/c64/kernal/iec_release_atn.s +++ b/c64/kernal/iec_release_atn.s @@ -1,8 +1,8 @@ iec_release_atn: - lda CI2PRA - and #$FF - BIT_CI2PRA_ATN_OUT ; release - sta CI2PRA + lda CIA2_PRA + and #$FF - BIT_CIA2_PRA_ATN_OUT ; release + sta CIA2_PRA rts diff --git a/c64/kernal/iec_release_atn_clk_data.s b/c64/kernal/iec_release_atn_clk_data.s index 3fccfbcb..904ee13f 100644 --- a/c64/kernal/iec_release_atn_clk_data.s +++ b/c64/kernal/iec_release_atn_clk_data.s @@ -5,12 +5,12 @@ iec_release_atn_clk_data: ;; hardware give some lines few more cycles to stabilize; see page 10 of ;; http://www.zimmers.net/anonftp/pub/cbm/programming/serial-bus.pdf - lda CI2PRA - and #$FF - BIT_CI2PRA_ATN_OUT ; release - sta CI2PRA - and #$FF - BIT_CI2PRA_DAT_OUT ; release - sta CI2PRA - and #$FF - BIT_CI2PRA_CLK_OUT ; release - sta CI2PRA + lda CIA2_PRA + and #$FF - BIT_CIA2_PRA_ATN_OUT ; release + sta CIA2_PRA + and #$FF - BIT_CIA2_PRA_DAT_OUT ; release + sta CIA2_PRA + and #$FF - BIT_CIA2_PRA_CLK_OUT ; release + sta CIA2_PRA rts diff --git a/c64/kernal/iec_release_clk_data.s b/c64/kernal/iec_release_clk_data.s index e74ff7e4..f48daa6c 100644 --- a/c64/kernal/iec_release_clk_data.s +++ b/c64/kernal/iec_release_clk_data.s @@ -5,9 +5,9 @@ iec_release_clk_data: ;; hardware give some lines few more cycles to stabilize; see page 10 of ;; http://www.zimmers.net/anonftp/pub/cbm/programming/serial-bus.pdf - lda CI2PRA - and #$FF - BIT_CI2PRA_DAT_OUT ; release - sta CI2PRA - and #$FF - BIT_CI2PRA_CLK_OUT ; release - sta CI2PRA + lda CIA2_PRA + and #$FF - BIT_CIA2_PRA_DAT_OUT ; release + sta CIA2_PRA + and #$FF - BIT_CIA2_PRA_CLK_OUT ; release + sta CIA2_PRA rts diff --git a/c64/kernal/iec_release_clk_pull_data.s b/c64/kernal/iec_release_clk_pull_data.s index 1c167a04..9f252ed3 100644 --- a/c64/kernal/iec_release_clk_pull_data.s +++ b/c64/kernal/iec_release_clk_pull_data.s @@ -5,9 +5,9 @@ iec_release_clk_pull_data: ;; hardware give some lines few more cycles to stabilize; see page 10 of ;; http://www.zimmers.net/anonftp/pub/cbm/programming/serial-bus.pdf - lda CI2PRA - ora #BIT_CI2PRA_DAT_OUT ; pull - sta CI2PRA - and #$FF - BIT_CI2PRA_CLK_OUT ; release - sta CI2PRA + lda CIA2_PRA + ora #BIT_CIA2_PRA_DAT_OUT ; pull + sta CIA2_PRA + and #$FF - BIT_CIA2_PRA_CLK_OUT ; release + sta CIA2_PRA rts diff --git a/c64/kernal/iec_rx_byte.s b/c64/kernal/iec_rx_byte.s index 4a7eb996..9819636c 100644 --- a/c64/kernal/iec_rx_byte.s +++ b/c64/kernal/iec_rx_byte.s @@ -24,8 +24,8 @@ iec_rx_byte: ldx #$11 ; 2 cycles iec_rx_clk_wait1: - lda CI2PRA ; 4 cycles - rol ; 2 cycles, to put BIT_CI2PRA_CLK_IN as the last bit + lda CIA2_PRA ; 4 cycles + rol ; 2 cycles, to put CLK in as the last bit bpl iec_rx_not_eoi ; 2 cycles if not jumped dex ; 2 cycles bne iec_rx_clk_wait1 ; 3 cycles if jumped @@ -77,7 +77,7 @@ iec_rx_bit_loop: ;; Move data bit into C flag, and loop until bit 6 clears ;; i.e., the clock has been released. -* lda CI2PRA +* lda CIA2_PRA rol bpl - @@ -90,8 +90,8 @@ iec_rx_bit_loop: ;; consider this a timeout ldy #$19 ; 2 cycles iec_rx_clk_wait2: - lda CI2PRA ; 4 cycles - rol ; 2 cycles, to put BIT_CI2PRA_CLK_IN as the last bit + lda CIA2_PRA ; 4 cycles + rol ; 2 cycles, to put CLK in as the last bit bpl + ; 2 cycles if not jumped dey ; 2 cycles bne iec_rx_clk_wait2 ; 3 cycles if jumped diff --git a/c64/kernal/iec_set_idle.s b/c64/kernal/iec_set_idle.s index dd936926..1604306d 100644 --- a/c64/kernal/iec_set_idle.s +++ b/c64/kernal/iec_set_idle.s @@ -1,7 +1,7 @@ iec_set_idle: - lda CI2PRA - ora #BIT_CI2PRA_CLK_OUT ; pull - and #$FF - BIT_CI2PRA_DAT_OUT - BIT_CI2PRA_ATN_OUT ; release - sta CI2PRA + lda CIA2_PRA + ora #BIT_CIA2_PRA_CLK_OUT ; pull + and #$FF - BIT_CIA2_PRA_DAT_OUT - BIT_CIA2_PRA_ATN_OUT ; release + sta CIA2_PRA rts diff --git a/c64/kernal/iec_turnaround_to_listen.s b/c64/kernal/iec_turnaround_to_listen.s index b1d0f576..1033b720 100644 --- a/c64/kernal/iec_turnaround_to_listen.s +++ b/c64/kernal/iec_turnaround_to_listen.s @@ -14,8 +14,8 @@ iec_turnaround_to_listen: ;; Wait for clock line to be pulled by the drive ldx #$FF ; XXX should we really use that high number? * - lda CI2PRA - rol ; to put BIT_CI2PRA_CLK_IN as the last (sign) bit + lda CIA2_PRA + rol ; to put BIT_CIA2_PRA_CLK_IN as the last (sign) bit bpl + dex bne - diff --git a/c64/kernal/iec_tx_byte.s b/c64/kernal/iec_tx_byte.s index 946c248d..b827d8c2 100644 --- a/c64/kernal/iec_tx_byte.s +++ b/c64/kernal/iec_tx_byte.s @@ -21,8 +21,8 @@ iec_tx_byte: ;; All done - give device time to tell if they are busy by pulling DATA ;; They should do it within 1ms ldx #$FF -* lda CI2PRA - ;; BPL here is checking that bit 7 of $DD00 clears, +* lda CIA2_PRA + ;; BPL here is checking that bit 7 clears, ;; i.e, that the DATA line is pulled by drive bpl + dex diff --git a/c64/kernal/iec_tx_command.s b/c64/kernal/iec_tx_command.s index 7cde1dce..0e92e2db 100644 --- a/c64/kernal/iec_tx_command.s +++ b/c64/kernal/iec_tx_command.s @@ -14,8 +14,8 @@ iec_tx_command: jsr wait1ms ;; Did at least one device respond by pulling DATA? - lda CI2PRA - and #BIT_CI2PRA_DAT_IN ; XXX try to optimize this, move to separate routine + lda CIA2_PRA + and #BIT_CIA2_PRA_DAT_IN ; XXX try to optimize this, move to separate routine beq + ;; No devices present on the bus, so we can immediately return with device not found @@ -42,8 +42,8 @@ iec_tx_command: ;; flow here, but http://www.zimmers.net/anonftp/pub/cbm/programming/serial-bus.pdf (page 6) ;; advices to just wait 1ms and check the DATA status jsr wait1ms - lda CI2PRA - and #BIT_CI2PRA_DAT_IN ; XXX try to optimize this, move to separate routine + lda CIA2_PRA + and #BIT_CIA2_PRA_DAT_IN ; XXX try to optimize this, move to separate routine beq + ;; XXX possible optimization of the flow above: for many commands it is enough diff --git a/c64/kernal/iec_wait_for_clk_release.s b/c64/kernal/iec_wait_for_clk_release.s index 6139dd1d..22edfdfa 100644 --- a/c64/kernal/iec_wait_for_clk_release.s +++ b/c64/kernal/iec_wait_for_clk_release.s @@ -1,6 +1,7 @@ iec_wait_for_clk_release: - lda CI2PRA - and #BIT_CI2PRA_CLK_IN + + lda CIA2_PRA + and #BIT_CIA2_PRA_CLK_IN beq iec_wait_for_clk_release rts diff --git a/c64/kernal/iec_wait_for_data_pull.s b/c64/kernal/iec_wait_for_data_pull.s index d83b57d4..93bbabe9 100644 --- a/c64/kernal/iec_wait_for_data_pull.s +++ b/c64/kernal/iec_wait_for_data_pull.s @@ -1,6 +1,7 @@ iec_wait_for_data_pull: - lda CI2PRA + + lda CIA2_PRA ;; Check the highest bit, which is DATA IN, ;; (highest bit set = negative value) bmi iec_wait_for_data_pull diff --git a/c64/kernal/iec_wait_for_data_release.s b/c64/kernal/iec_wait_for_data_release.s index e54df9de..dc89638a 100644 --- a/c64/kernal/iec_wait_for_data_release.s +++ b/c64/kernal/iec_wait_for_data_release.s @@ -1,6 +1,7 @@ iec_wait_for_data_release: - lda CI2PRA + + lda CIA2_PRA ;; Check the highest bit, which is DATA IN, ;; (highest bit set = negative value) bpl iec_wait_for_data_release diff --git a/c64/kernal/ramtas.s b/c64/kernal/ramtas.s index e54f7bd2..81f4dfde 100644 --- a/c64/kernal/ramtas.s +++ b/c64/kernal/ramtas.s @@ -12,12 +12,12 @@ ramtas: ; C64 Programmer's Reference guide p291: ; Clear $0000-$0101, $0200-$03ff ; PGS: $0000, $0001 are CPU IO ports, so shouldn't get written to - LDY #$02 - LDA #$00 + ldy #$02 + lda #$00 ramtas_l1: - STA $00,Y - INY - BNE ramtas_l1 + sta $00,Y + iny + bne ramtas_l1 ramtas_l2: ;; How many ways are there to efficiently erase these two pages ;; of RAM? We would like to avoid any unnecessary byte similarity @@ -25,41 +25,41 @@ ramtas_l2: ;; with the longer sequence of identicale bytes we see no basis for ;; it being copyrightable. Again, we just want to redue the attack ;; surface for any misguided suit. - STA $0300,Y - STA $0200,Y - INY - BNE ramtas_l2 + sta $0300,Y + sta $0200,Y + iny + bne ramtas_l2 ; allocate cassette buffer ;; "Mapping the C128", p61 lda #<$033C - STA cassette_buffer_ptr+0 + sta cassette_buffer_ptr+0 lda #>$033C - STA cassette_buffer_ptr+1 + sta cassette_buffer_ptr+1 ; set screen address to $0400 ; https://www.c64-wiki.com/wiki/Screen_RAM ; Since we are setting $D018, we also make sure we are using the ; ROM character set (C64 Programmer's Reference Guide p322) - LDA #$14 - STA $D018 + lda #$14 + sta VIC_YMCSB ; Make sure we have the correct VIC-II memory bank for the screen to really be at $0400 ; and not $4400, $8400 or $C400 ; https://www.c64-wiki.com/wiki/VIC_bank#Selecting_VIC_banks - LDA $DD02 - ORA #$03 - STA $DD02 - LDA $DD00 - ORA #$03 - STA $DD00 + lda CIA2_DDRA + ora #$03 + sta CIA2_DDRA + lda CIA2_PRA + ora #$03 + sta CIA2_PRA ;; Set screen address pointer ("Compute's Mapping the 64" p238) ;; This is obvious boiler plate containing no creative input, but to avoid ;; unnecessarily similarity to the C64 KERNAL, we use X instead of A to do this, ;; and several following - LDX #>$0400 - STX HIBASE + ldx #>$0400 + stx HIBASE ;; Work out RAM size and put in MEMSTR and MEMSIZ ;; "Compute's Mapping the 64", p54